genosdb 0.35.0 → 0.35.2

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.
@@ -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 m_=Object.create;var{getPrototypeOf:f_,defineProperty:AA,getOwnPropertyNames:p_}=Object;var c_=Object.prototype.hasOwnProperty;function l_(W){return this[W]}var d_,o_,b1=(W,X,G)=>{var Y=W!=null&&typeof W==="object";if(Y){var J=X?d_??=new WeakMap:o_??=new WeakMap,Z=J.get(W);if(Z)return Z}G=W!=null?m_(f_(W)):{};let V=X||!W||!W.__esModule?AA(G,"default",{value:W,enumerable:!0}):G;for(let U of p_(W))if(!c_.call(V,U))AA(V,U,{get:l_.bind(W,U),enumerable:!0});if(Y)J.set(W,V);return V};var V1=(W,X)=>()=>(X||W((X={exports:{}}).exports,X),X.exports);var n_=(W)=>W;function i_(W,X){this[W]=n_.bind(null,X)}var zA=(W,X)=>{for(var G in X)AA(W,G,{get:X[G],enumerable:!0,configurable:!0,set:i_.bind(X,G)})};var _8=import.meta.require;var VM=V1((se,ZM)=>{var zG=1000,IG=zG*60,wG=IG*60,$W=wG*24,nh=$W*7,ih=$W*365.25;ZM.exports=function(W,X){X=X||{};var G=typeof W;if(G==="string"&&W.length>0)return rh(W);else if(G==="number"&&isFinite(W))return X.long?sh(W):ah(W);throw Error("val is not a non-empty string or a valid number. val="+JSON.stringify(W))};function rh(W){if(W=String(W),W.length>100)return;var X=/^(-?(?:\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(!X)return;var G=parseFloat(X[1]),Y=(X[2]||"ms").toLowerCase();switch(Y){case"years":case"year":case"yrs":case"yr":case"y":return G*ih;case"weeks":case"week":case"w":return G*nh;case"days":case"day":case"d":return G*$W;case"hours":case"hour":case"hrs":case"hr":case"h":return G*wG;case"minutes":case"minute":case"mins":case"min":case"m":return G*IG;case"seconds":case"second":case"secs":case"sec":case"s":return G*zG;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return G;default:return}}function ah(W){var X=Math.abs(W);if(X>=$W)return Math.round(W/$W)+"d";if(X>=wG)return Math.round(W/wG)+"h";if(X>=IG)return Math.round(W/IG)+"m";if(X>=zG)return Math.round(W/zG)+"s";return W+"ms"}function sh(W){var X=Math.abs(W);if(X>=$W)return EQ(W,X,$W,"day");if(X>=wG)return EQ(W,X,wG,"hour");if(X>=IG)return EQ(W,X,IG,"minute");if(X>=zG)return EQ(W,X,zG,"second");return W+" ms"}function EQ(W,X,G,Y){var J=X>=G*1.5;return Math.round(W/G)+" "+Y+(J?"s":"")}});var Ez=V1((te,UM)=>{function th(W){G.debug=G,G.default=G,G.coerce=Q,G.disable=V,G.enable=J,G.enabled=U,G.humanize=VM(),G.destroy=N,Object.keys(W).forEach((q)=>{G[q]=W[q]}),G.names=[],G.skips=[],G.formatters={};function X(q){let A=0;for(let H=0;H<q.length;H++)A=(A<<5)-A+q.charCodeAt(H),A|=0;return G.colors[Math.abs(A)%G.colors.length]}G.selectColor=X;function G(q){let A,H=null,I,w;function O(...T){if(!O.enabled)return;let x=O,h=Number(new Date),$=h-(A||h);if(x.diff=$,x.prev=A,x.curr=h,A=h,T[0]=G.coerce(T[0]),typeof T[0]!=="string")T.unshift("%O");let F=0;T[0]=T[0].replace(/%([a-zA-Z%])/g,(l,p)=>{if(l==="%%")return"%";F++;let s=G.formatters[p];if(typeof s==="function"){let y=T[F];l=s.call(x,y),T.splice(F,1),F--}return l}),G.formatArgs.call(x,T),(x.log||G.log).apply(x,T)}if(O.namespace=q,O.useColors=G.useColors(),O.color=G.selectColor(q),O.extend=Y,O.destroy=G.destroy,Object.defineProperty(O,"enabled",{enumerable:!0,configurable:!1,get:()=>{if(H!==null)return H;if(I!==G.namespaces)I=G.namespaces,w=G.enabled(q);return w},set:(T)=>{H=T}}),typeof G.init==="function")G.init(O);return O}function Y(q,A){let H=G(this.namespace+(typeof A>"u"?":":A)+q);return H.log=this.log,H}function J(q){G.save(q),G.namespaces=q,G.names=[],G.skips=[];let A=(typeof q==="string"?q:"").trim().replace(" ",",").split(",").filter(Boolean);for(let H of A)if(H[0]==="-")G.skips.push(H.slice(1));else G.names.push(H)}function Z(q,A){let H=0,I=0,w=-1,O=0;while(H<q.length)if(I<A.length&&(A[I]===q[H]||A[I]==="*"))if(A[I]==="*")w=I,O=H,I++;else H++,I++;else if(w!==-1)I=w+1,O++,H=O;else return!1;while(I<A.length&&A[I]==="*")I++;return I===A.length}function V(){let q=[...G.names,...G.skips.map((A)=>"-"+A)].join(",");return G.enable(""),q}function U(q){for(let A of G.skips)if(Z(q,A))return!1;for(let A of G.names)if(Z(q,A))return!0;return!1}function Q(q){if(q instanceof Error)return q.stack||q.message;return q}function N(){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}UM.exports=th});var NM=V1((QM,FQ)=>{QM.formatArgs=Wb;QM.save=Xb;QM.load=Gb;QM.useColors=eh;QM.storage=Yb();QM.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`.")}})();QM.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 eh(){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 Wb(W){if(W[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+W[0]+(this.useColors?"%c ":" ")+"+"+FQ.exports.humanize(this.diff),!this.useColors)return;let X="color: "+this.color;W.splice(1,0,X,"color: inherit");let G=0,Y=0;W[0].replace(/%[a-zA-Z%]/g,(J)=>{if(J==="%%")return;if(G++,J==="%c")Y=G}),W.splice(Y,0,X)}QM.log=console.debug||console.log||(()=>{});function Xb(W){try{if(W)QM.storage.setItem("debug",W);else QM.storage.removeItem("debug")}catch(X){}}function Gb(){let W;try{W=QM.storage.getItem("debug")}catch(X){}if(!W&&typeof process<"u"&&"env"in process)W=process.env.DEBUG;return W}function Yb(){try{return localStorage}catch(W){}}FQ.exports=Ez()(QM);var{formatters:Jb}=FQ.exports;Jb.j=function(W){try{return JSON.stringify(W)}catch(X){return"[UnexpectedJSONParseError]: "+X.message}}});var zM=V1((HM,xQ)=>{var Ab=_8("tty"),SQ=_8("util");HM.init=Db;HM.log=jb;HM.formatArgs=Ib;HM.save=Kb;HM.load=Ob;HM.useColors=zb;HM.destroy=SQ.deprecate(()=>{},"Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.");HM.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)HM.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){}HM.inspectOpts=Object.keys(process.env).filter((W)=>{return/^debug_/i.test(W)}).reduce((W,X)=>{let G=X.substring(6).toLowerCase().replace(/_([a-z])/g,(J,Z)=>{return Z.toUpperCase()}),Y=process.env[X];if(/^(yes|on|true|enabled)$/i.test(Y))Y=!0;else if(/^(no|off|false|disabled)$/i.test(Y))Y=!1;else if(Y==="null")Y=null;else Y=Number(Y);return W[G]=Y,W},{});function zb(){return"colors"in HM.inspectOpts?Boolean(HM.inspectOpts.colors):Ab.isatty(process.stderr.fd)}function Ib(W){let{namespace:X,useColors:G}=this;if(G){let Y=this.color,J="\x1B[3"+(Y<8?Y:"8;5;"+Y),Z=` ${J};1m${X} \x1B[0m`;W[0]=Z+W[0].split(`
3
+ var m_=Object.create;var{getPrototypeOf:f_,defineProperty:AA,getOwnPropertyNames:p_}=Object;var c_=Object.prototype.hasOwnProperty;function l_(W){return this[W]}var d_,o_,b1=(W,X,G)=>{var Y=W!=null&&typeof W==="object";if(Y){var J=X?d_??=new WeakMap:o_??=new WeakMap,Z=J.get(W);if(Z)return Z}G=W!=null?m_(f_(W)):{};let V=X||!W||!W.__esModule?AA(G,"default",{value:W,enumerable:!0}):G;for(let U of p_(W))if(!c_.call(V,U))AA(V,U,{get:l_.bind(W,U),enumerable:!0});if(Y)J.set(W,V);return V};var V1=(W,X)=>()=>(X||W((X={exports:{}}).exports,X),X.exports);var n_=(W)=>W;function i_(W,X){this[W]=n_.bind(null,X)}var zA=(W,X)=>{for(var G in X)AA(W,G,{get:X[G],enumerable:!0,configurable:!0,set:i_.bind(X,G)})};var _8=import.meta.require;var VM=V1((se,ZM)=>{var zG=1000,IG=zG*60,wG=IG*60,$W=wG*24,nh=$W*7,ih=$W*365.25;ZM.exports=function(W,X){X=X||{};var G=typeof W;if(G==="string"&&W.length>0)return rh(W);else if(G==="number"&&isFinite(W))return X.long?sh(W):ah(W);throw Error("val is not a non-empty string or a valid number. val="+JSON.stringify(W))};function rh(W){if(W=String(W),W.length>100)return;var X=/^(-?(?:\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(!X)return;var G=parseFloat(X[1]),Y=(X[2]||"ms").toLowerCase();switch(Y){case"years":case"year":case"yrs":case"yr":case"y":return G*ih;case"weeks":case"week":case"w":return G*nh;case"days":case"day":case"d":return G*$W;case"hours":case"hour":case"hrs":case"hr":case"h":return G*wG;case"minutes":case"minute":case"mins":case"min":case"m":return G*IG;case"seconds":case"second":case"secs":case"sec":case"s":return G*zG;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return G;default:return}}function ah(W){var X=Math.abs(W);if(X>=$W)return Math.round(W/$W)+"d";if(X>=wG)return Math.round(W/wG)+"h";if(X>=IG)return Math.round(W/IG)+"m";if(X>=zG)return Math.round(W/zG)+"s";return W+"ms"}function sh(W){var X=Math.abs(W);if(X>=$W)return EQ(W,X,$W,"day");if(X>=wG)return EQ(W,X,wG,"hour");if(X>=IG)return EQ(W,X,IG,"minute");if(X>=zG)return EQ(W,X,zG,"second");return W+" ms"}function EQ(W,X,G,Y){var J=X>=G*1.5;return Math.round(W/G)+" "+Y+(J?"s":"")}});var Ez=V1((te,UM)=>{function th(W){G.debug=G,G.default=G,G.coerce=Q,G.disable=V,G.enable=J,G.enabled=U,G.humanize=VM(),G.destroy=N,Object.keys(W).forEach((q)=>{G[q]=W[q]}),G.names=[],G.skips=[],G.formatters={};function X(q){let A=0;for(let H=0;H<q.length;H++)A=(A<<5)-A+q.charCodeAt(H),A|=0;return G.colors[Math.abs(A)%G.colors.length]}G.selectColor=X;function G(q){let A,H=null,I,w;function O(...T){if(!O.enabled)return;let x=O,h=Number(new Date),$=h-(A||h);if(x.diff=$,x.prev=A,x.curr=h,A=h,T[0]=G.coerce(T[0]),typeof T[0]!=="string")T.unshift("%O");let F=0;T[0]=T[0].replace(/%([a-zA-Z%])/g,(l,f)=>{if(l==="%%")return"%";F++;let s=G.formatters[f];if(typeof s==="function"){let y=T[F];l=s.call(x,y),T.splice(F,1),F--}return l}),G.formatArgs.call(x,T),(x.log||G.log).apply(x,T)}if(O.namespace=q,O.useColors=G.useColors(),O.color=G.selectColor(q),O.extend=Y,O.destroy=G.destroy,Object.defineProperty(O,"enabled",{enumerable:!0,configurable:!1,get:()=>{if(H!==null)return H;if(I!==G.namespaces)I=G.namespaces,w=G.enabled(q);return w},set:(T)=>{H=T}}),typeof G.init==="function")G.init(O);return O}function Y(q,A){let H=G(this.namespace+(typeof A>"u"?":":A)+q);return H.log=this.log,H}function J(q){G.save(q),G.namespaces=q,G.names=[],G.skips=[];let A=(typeof q==="string"?q:"").trim().replace(" ",",").split(",").filter(Boolean);for(let H of A)if(H[0]==="-")G.skips.push(H.slice(1));else G.names.push(H)}function Z(q,A){let H=0,I=0,w=-1,O=0;while(H<q.length)if(I<A.length&&(A[I]===q[H]||A[I]==="*"))if(A[I]==="*")w=I,O=H,I++;else H++,I++;else if(w!==-1)I=w+1,O++,H=O;else return!1;while(I<A.length&&A[I]==="*")I++;return I===A.length}function V(){let q=[...G.names,...G.skips.map((A)=>"-"+A)].join(",");return G.enable(""),q}function U(q){for(let A of G.skips)if(Z(q,A))return!1;for(let A of G.names)if(Z(q,A))return!0;return!1}function Q(q){if(q instanceof Error)return q.stack||q.message;return q}function N(){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}UM.exports=th});var NM=V1((QM,FQ)=>{QM.formatArgs=Wb;QM.save=Xb;QM.load=Gb;QM.useColors=eh;QM.storage=Yb();QM.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`.")}})();QM.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 eh(){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 Wb(W){if(W[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+W[0]+(this.useColors?"%c ":" ")+"+"+FQ.exports.humanize(this.diff),!this.useColors)return;let X="color: "+this.color;W.splice(1,0,X,"color: inherit");let G=0,Y=0;W[0].replace(/%[a-zA-Z%]/g,(J)=>{if(J==="%%")return;if(G++,J==="%c")Y=G}),W.splice(Y,0,X)}QM.log=console.debug||console.log||(()=>{});function Xb(W){try{if(W)QM.storage.setItem("debug",W);else QM.storage.removeItem("debug")}catch(X){}}function Gb(){let W;try{W=QM.storage.getItem("debug")}catch(X){}if(!W&&typeof process<"u"&&"env"in process)W=process.env.DEBUG;return W}function Yb(){try{return localStorage}catch(W){}}FQ.exports=Ez()(QM);var{formatters:Jb}=FQ.exports;Jb.j=function(W){try{return JSON.stringify(W)}catch(X){return"[UnexpectedJSONParseError]: "+X.message}}});var zM=V1((HM,xQ)=>{var Ab=_8("tty"),SQ=_8("util");HM.init=Db;HM.log=jb;HM.formatArgs=Ib;HM.save=Kb;HM.load=Ob;HM.useColors=zb;HM.destroy=SQ.deprecate(()=>{},"Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.");HM.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)HM.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){}HM.inspectOpts=Object.keys(process.env).filter((W)=>{return/^debug_/i.test(W)}).reduce((W,X)=>{let G=X.substring(6).toLowerCase().replace(/_([a-z])/g,(J,Z)=>{return Z.toUpperCase()}),Y=process.env[X];if(/^(yes|on|true|enabled)$/i.test(Y))Y=!0;else if(/^(no|off|false|disabled)$/i.test(Y))Y=!1;else if(Y==="null")Y=null;else Y=Number(Y);return W[G]=Y,W},{});function zb(){return"colors"in HM.inspectOpts?Boolean(HM.inspectOpts.colors):Ab.isatty(process.stderr.fd)}function Ib(W){let{namespace:X,useColors:G}=this;if(G){let Y=this.color,J="\x1B[3"+(Y<8?Y:"8;5;"+Y),Z=` ${J};1m${X} \x1B[0m`;W[0]=Z+W[0].split(`
4
4
  `).join(`
5
5
  `+Z),W.push(J+"m+"+xQ.exports.humanize(this.diff)+"\x1B[0m")}else W[0]=wb()+X+" "+W[0]}function wb(){if(HM.inspectOpts.hideDate)return"";return new Date().toISOString()+" "}function jb(...W){return process.stderr.write(SQ.formatWithOptions(HM.inspectOpts,...W)+`
6
6
  `)}function Kb(W){if(W)process.env.DEBUG=W;else delete process.env.DEBUG}function Ob(){return process.env.DEBUG}function Db(W){W.inspectOpts={};let X=Object.keys(HM.inspectOpts);for(let G=0;G<X.length;G++)W.inspectOpts[X[G]]=HM.inspectOpts[X[G]]}xQ.exports=Ez()(HM);var{formatters:qM}=xQ.exports;qM.o=function(W){return this.inspectOpts.colors=this.useColors,SQ.inspect(W,this.inspectOpts).split(`
7
- `).map((X)=>X.trim()).join(" ")};qM.O=function(W){return this.inspectOpts.colors=this.useColors,SQ.inspect(W,this.inspectOpts)}});var IM=V1((X00,$z)=>{if(typeof process>"u"||process.type==="renderer"||!1||process.__nwjs)$z.exports=NM();else $z.exports=zM()});var kQ=V1((jM)=>{Object.defineProperty(jM,"__esModule",{value:!0});var Eb=_8("net");function $b(W){switch(Eb.isIP(W)){case 4:return Buffer.from(W.split(".").map((J)=>parseInt(J,10)));case 6:let X=W.split(":"),G=Buffer.alloc(16),Y=0;if(X[X.length-1]==="")X[X.length-1]="0";for(let J=0;J<X.length;J++){if(X[J]===""){if(J+1<X.length&&X[J+1]!=="")Y=16-(X.length-J-1)*2;continue}G.writeUInt16BE(parseInt(X[J],16),Y),Y+=2}return G;default:return null}}jM.bytesFromIP=$b;function Fb(W){switch(W.length){case 4:return[W[0],W[1],W[2],W[3]].join(".");case 16:let X=[],G=-1,Y=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(Y++,G===-1)G=X.length;if(Y>Z)Z=Y,J=G}else G=-1,Y=0;X.push(U.toString(16))}if(Z>0){let V="",U=X.slice(J+Z);if(X.length=J,X.length===0)V+=":";if(U.length===0)V+=":";X.push(V,...U)}return X.join(":");default:return""}}jM.bytesToIP=Fb;var I6=Object.create(null),wM=/^[0-9.]+$/;function Sb(W){if(wM.test(W)&&I6[W]!=="")return W;return I6[W]==null?"":I6[W]}jM.getOID=Sb;function xb(W){if(!wM.test(W)&&I6[W]!=="")return W;return I6[W]==null?W:I6[W]}jM.getOIDName=xb;function w0(W,X){I6[W]=X,I6[X]=W}w0("1.2.840.113549.1.1.1","rsaEncryption");w0("1.2.840.113549.1.1.4","md5WithRsaEncryption");w0("1.2.840.113549.1.1.5","sha1WithRsaEncryption");w0("1.2.840.113549.1.1.8","mgf1");w0("1.2.840.113549.1.1.10","RSASSA-PSS");w0("1.2.840.113549.1.1.11","sha256WithRsaEncryption");w0("1.2.840.113549.1.1.12","sha384WithRsaEncryption");w0("1.2.840.113549.1.1.13","sha512WithRsaEncryption");w0("1.2.840.10045.2.1","ecEncryption");w0("1.2.840.10045.4.1","ecdsaWithSha1");w0("1.2.840.10045.4.3.2","ecdsaWithSha256");w0("1.2.840.10045.4.3.3","ecdsaWithSha384");w0("1.2.840.10045.4.3.4","ecdsaWithSha512");w0("1.2.840.10040.4.3","dsaWithSha1");w0("2.16.840.1.101.3.4.3.2","dsaWithSha256");w0("1.3.14.3.2.7","desCBC");w0("1.3.14.3.2.26","sha1");w0("2.16.840.1.101.3.4.2.1","sha256");w0("2.16.840.1.101.3.4.2.2","sha384");w0("2.16.840.1.101.3.4.2.3","sha512");w0("1.2.840.113549.2.5","md5");w0("1.3.101.110","X25519");w0("1.3.101.111","X448");w0("1.3.101.112","Ed25519");w0("1.3.101.113","Ed448");w0("1.2.840.113549.1.7.1","data");w0("1.2.840.113549.1.7.2","signedData");w0("1.2.840.113549.1.7.3","envelopedData");w0("1.2.840.113549.1.7.4","signedAndEnvelopedData");w0("1.2.840.113549.1.7.5","digestedData");w0("1.2.840.113549.1.7.6","encryptedData");w0("1.2.840.113549.1.9.1","emailAddress");w0("1.2.840.113549.1.9.2","unstructuredName");w0("1.2.840.113549.1.9.3","contentType");w0("1.2.840.113549.1.9.4","messageDigest");w0("1.2.840.113549.1.9.5","signingTime");w0("1.2.840.113549.1.9.6","counterSignature");w0("1.2.840.113549.1.9.7","challengePassword");w0("1.2.840.113549.1.9.8","unstructuredAddress");w0("1.2.840.113549.1.9.14","extensionRequest");w0("1.2.840.113549.1.9.20","friendlyName");w0("1.2.840.113549.1.9.21","localKeyId");w0("1.2.840.113549.1.9.22.1","x509Certificate");w0("1.2.840.113549.1.12.10.1.1","keyBag");w0("1.2.840.113549.1.12.10.1.2","pkcs8ShroudedKeyBag");w0("1.2.840.113549.1.12.10.1.3","certBag");w0("1.2.840.113549.1.12.10.1.4","crlBag");w0("1.2.840.113549.1.12.10.1.5","secretBag");w0("1.2.840.113549.1.12.10.1.6","safeContentsBag");w0("1.2.840.113549.1.5.13","pkcs5PBES2");w0("1.2.840.113549.1.5.12","pkcs5PBKDF2");w0("1.2.840.113549.2.7","hmacWithSha1");w0("1.2.840.113549.2.9","hmacWithSha256");w0("1.2.840.113549.2.10","hmacWithSha384");w0("1.2.840.113549.2.11","hmacWithSha512");w0("1.2.840.113549.3.7","3desCBC");w0("2.16.840.1.101.3.4.1.2","aesCBC128");w0("2.16.840.1.101.3.4.1.42","aesCBC256");w0("2.5.4.3","commonName");w0("2.5.4.5","serialName");w0("2.5.4.6","countryName");w0("2.5.4.7","localityName");w0("2.5.4.8","stateOrProvinceName");w0("2.5.4.10","organizationName");w0("2.5.4.11","organizationalUnitName");w0("2.5.4.15","businessCategory");w0("2.16.840.1.113730.1.1","nsCertType");w0("2.5.29.2","keyAttributes");w0("2.5.29.4","keyUsageRestriction");w0("2.5.29.6","subtreesConstraint");w0("2.5.29.9","subjectDirectoryAttributes");w0("2.5.29.14","subjectKeyIdentifier");w0("2.5.29.15","keyUsage");w0("2.5.29.16","privateKeyUsagePeriod");w0("2.5.29.17","subjectAltName");w0("2.5.29.18","issuerAltName");w0("2.5.29.19","basicConstraints");w0("2.5.29.20","cRLNumber");w0("2.5.29.21","cRLReason");w0("2.5.29.22","expirationDate");w0("2.5.29.23","instructionCode");w0("2.5.29.24","invalidityDate");w0("2.5.29.27","deltaCRLIndicator");w0("2.5.29.28","issuingDistributionPoint");w0("2.5.29.29","certificateIssuer");w0("2.5.29.30","nameConstraints");w0("2.5.29.31","cRLDistributionPoints");w0("2.5.29.32","certificatePolicies");w0("2.5.29.33","policyMappings");w0("2.5.29.35","authorityKeyIdentifier");w0("2.5.29.36","policyConstraints");w0("2.5.29.37","extKeyUsage");w0("2.5.29.46","freshestCRL");w0("2.5.29.54","inhibitAnyPolicy");w0("1.3.6.1.4.1.311.60.2.1.2","jurisdictionST");w0("1.3.6.1.4.1.311.60.2.1.3","jurisdictionC");w0("1.3.6.1.4.1.11129.2.4.2","timestampList");w0("1.3.6.1.5.5.7.1.1","authorityInfoAccess");w0("1.3.6.1.5.5.7.3.1","serverAuth");w0("1.3.6.1.5.5.7.3.2","clientAuth");w0("1.3.6.1.5.5.7.3.3","codeSigning");w0("1.3.6.1.5.5.7.3.4","emailProtection");w0("1.3.6.1.5.5.7.3.8","timeStamping");w0("1.3.6.1.5.5.7.48.1","authorityInfoAccessOcsp");w0("1.3.6.1.5.5.7.48.2","authorityInfoAccessIssuers")});var yQ=V1((Y00,_Q)=>{(function(W){var X=function(K){var M,C=new Float64Array(16);if(K)for(M=0;M<K.length;M++)C[M]=K[M];return C},G=function(){throw Error("no PRNG")},Y=new Uint8Array(16),J=new Uint8Array(32);J[0]=9;var Z=X(),V=X([1]),U=X([56129,1]),Q=X([30883,4953,19914,30187,55467,16705,2637,112,59544,30585,16505,36039,65139,11119,27886,20995]),N=X([61785,9906,39828,60374,45398,33411,5274,224,53552,61171,33010,6542,64743,22239,55772,9222]),q=X([54554,36645,11616,51542,42930,38181,51040,26924,56412,64982,57905,49316,21502,52590,14035,8553]),A=X([26200,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214]),H=X([41136,18958,6951,50414,58488,44335,6150,12099,55207,15867,153,11085,57099,20417,9344,11139]);function I(K,M,C,z){K[M]=C>>24&255,K[M+1]=C>>16&255,K[M+2]=C>>8&255,K[M+3]=C&255,K[M+4]=z>>24&255,K[M+5]=z>>16&255,K[M+6]=z>>8&255,K[M+7]=z&255}function w(K,M,C,z,L){var n,e=0;for(n=0;n<L;n++)e|=K[M+n]^C[z+n];return(1&e-1>>>8)-1}function O(K,M,C,z){return w(K,M,C,z,16)}function T(K,M,C,z){return w(K,M,C,z,32)}function x(K,M,C,z){var L=z[0]&255|(z[1]&255)<<8|(z[2]&255)<<16|(z[3]&255)<<24,n=C[0]&255|(C[1]&255)<<8|(C[2]&255)<<16|(C[3]&255)<<24,e=C[4]&255|(C[5]&255)<<8|(C[6]&255)<<16|(C[7]&255)<<24,z0=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=z[4]&255|(z[5]&255)<<8|(z[6]&255)<<16|(z[7]&255)<<24,b0=M[0]&255|(M[1]&255)<<8|(M[2]&255)<<16|(M[3]&255)<<24,n1=M[4]&255|(M[5]&255)<<8|(M[6]&255)<<16|(M[7]&255)<<24,l0=M[8]&255|(M[9]&255)<<8|(M[10]&255)<<16|(M[11]&255)<<24,A1=M[12]&255|(M[13]&255)<<8|(M[14]&255)<<16|(M[15]&255)<<24,I1=z[8]&255|(z[9]&255)<<8|(z[10]&255)<<16|(z[11]&255)<<24,L1=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,w1=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,j1=z[12]&255|(z[13]&255)<<8|(z[14]&255)<<16|(z[15]&255)<<24,n0=L,X1=n,f0=e,r0=z0,s0=R0,v0=t0,Z0=b0,V0=n1,j0=l0,A0=A1,I0=I1,D0=L1,q1=T1,B1=w1,$1=O1,E1=j1,b;for(var _1=0;_1<20;_1+=2)b=n0+q1|0,s0^=b<<7|b>>>25,b=s0+n0|0,j0^=b<<9|b>>>23,b=j0+s0|0,q1^=b<<13|b>>>19,b=q1+j0|0,n0^=b<<18|b>>>14,b=v0+X1|0,A0^=b<<7|b>>>25,b=A0+v0|0,B1^=b<<9|b>>>23,b=B1+A0|0,X1^=b<<13|b>>>19,b=X1+B1|0,v0^=b<<18|b>>>14,b=I0+Z0|0,$1^=b<<7|b>>>25,b=$1+I0|0,f0^=b<<9|b>>>23,b=f0+$1|0,Z0^=b<<13|b>>>19,b=Z0+f0|0,I0^=b<<18|b>>>14,b=E1+D0|0,r0^=b<<7|b>>>25,b=r0+E1|0,V0^=b<<9|b>>>23,b=V0+r0|0,D0^=b<<13|b>>>19,b=D0+V0|0,E1^=b<<18|b>>>14,b=n0+r0|0,X1^=b<<7|b>>>25,b=X1+n0|0,f0^=b<<9|b>>>23,b=f0+X1|0,r0^=b<<13|b>>>19,b=r0+f0|0,n0^=b<<18|b>>>14,b=v0+s0|0,Z0^=b<<7|b>>>25,b=Z0+v0|0,V0^=b<<9|b>>>23,b=V0+Z0|0,s0^=b<<13|b>>>19,b=s0+V0|0,v0^=b<<18|b>>>14,b=I0+A0|0,D0^=b<<7|b>>>25,b=D0+I0|0,j0^=b<<9|b>>>23,b=j0+D0|0,A0^=b<<13|b>>>19,b=A0+j0|0,I0^=b<<18|b>>>14,b=E1+$1|0,q1^=b<<7|b>>>25,b=q1+E1|0,B1^=b<<9|b>>>23,b=B1+q1|0,$1^=b<<13|b>>>19,b=$1+B1|0,E1^=b<<18|b>>>14;n0=n0+L|0,X1=X1+n|0,f0=f0+e|0,r0=r0+z0|0,s0=s0+R0|0,v0=v0+t0|0,Z0=Z0+b0|0,V0=V0+n1|0,j0=j0+l0|0,A0=A0+A1|0,I0=I0+I1|0,D0=D0+L1|0,q1=q1+T1|0,B1=B1+w1|0,$1=$1+O1|0,E1=E1+j1|0,K[0]=n0>>>0&255,K[1]=n0>>>8&255,K[2]=n0>>>16&255,K[3]=n0>>>24&255,K[4]=X1>>>0&255,K[5]=X1>>>8&255,K[6]=X1>>>16&255,K[7]=X1>>>24&255,K[8]=f0>>>0&255,K[9]=f0>>>8&255,K[10]=f0>>>16&255,K[11]=f0>>>24&255,K[12]=r0>>>0&255,K[13]=r0>>>8&255,K[14]=r0>>>16&255,K[15]=r0>>>24&255,K[16]=s0>>>0&255,K[17]=s0>>>8&255,K[18]=s0>>>16&255,K[19]=s0>>>24&255,K[20]=v0>>>0&255,K[21]=v0>>>8&255,K[22]=v0>>>16&255,K[23]=v0>>>24&255,K[24]=Z0>>>0&255,K[25]=Z0>>>8&255,K[26]=Z0>>>16&255,K[27]=Z0>>>24&255,K[28]=V0>>>0&255,K[29]=V0>>>8&255,K[30]=V0>>>16&255,K[31]=V0>>>24&255,K[32]=j0>>>0&255,K[33]=j0>>>8&255,K[34]=j0>>>16&255,K[35]=j0>>>24&255,K[36]=A0>>>0&255,K[37]=A0>>>8&255,K[38]=A0>>>16&255,K[39]=A0>>>24&255,K[40]=I0>>>0&255,K[41]=I0>>>8&255,K[42]=I0>>>16&255,K[43]=I0>>>24&255,K[44]=D0>>>0&255,K[45]=D0>>>8&255,K[46]=D0>>>16&255,K[47]=D0>>>24&255,K[48]=q1>>>0&255,K[49]=q1>>>8&255,K[50]=q1>>>16&255,K[51]=q1>>>24&255,K[52]=B1>>>0&255,K[53]=B1>>>8&255,K[54]=B1>>>16&255,K[55]=B1>>>24&255,K[56]=$1>>>0&255,K[57]=$1>>>8&255,K[58]=$1>>>16&255,K[59]=$1>>>24&255,K[60]=E1>>>0&255,K[61]=E1>>>8&255,K[62]=E1>>>16&255,K[63]=E1>>>24&255}function h(K,M,C,z){var L=z[0]&255|(z[1]&255)<<8|(z[2]&255)<<16|(z[3]&255)<<24,n=C[0]&255|(C[1]&255)<<8|(C[2]&255)<<16|(C[3]&255)<<24,e=C[4]&255|(C[5]&255)<<8|(C[6]&255)<<16|(C[7]&255)<<24,z0=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=z[4]&255|(z[5]&255)<<8|(z[6]&255)<<16|(z[7]&255)<<24,b0=M[0]&255|(M[1]&255)<<8|(M[2]&255)<<16|(M[3]&255)<<24,n1=M[4]&255|(M[5]&255)<<8|(M[6]&255)<<16|(M[7]&255)<<24,l0=M[8]&255|(M[9]&255)<<8|(M[10]&255)<<16|(M[11]&255)<<24,A1=M[12]&255|(M[13]&255)<<8|(M[14]&255)<<16|(M[15]&255)<<24,I1=z[8]&255|(z[9]&255)<<8|(z[10]&255)<<16|(z[11]&255)<<24,L1=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,w1=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,j1=z[12]&255|(z[13]&255)<<8|(z[14]&255)<<16|(z[15]&255)<<24,n0=L,X1=n,f0=e,r0=z0,s0=R0,v0=t0,Z0=b0,V0=n1,j0=l0,A0=A1,I0=I1,D0=L1,q1=T1,B1=w1,$1=O1,E1=j1,b;for(var _1=0;_1<20;_1+=2)b=n0+q1|0,s0^=b<<7|b>>>25,b=s0+n0|0,j0^=b<<9|b>>>23,b=j0+s0|0,q1^=b<<13|b>>>19,b=q1+j0|0,n0^=b<<18|b>>>14,b=v0+X1|0,A0^=b<<7|b>>>25,b=A0+v0|0,B1^=b<<9|b>>>23,b=B1+A0|0,X1^=b<<13|b>>>19,b=X1+B1|0,v0^=b<<18|b>>>14,b=I0+Z0|0,$1^=b<<7|b>>>25,b=$1+I0|0,f0^=b<<9|b>>>23,b=f0+$1|0,Z0^=b<<13|b>>>19,b=Z0+f0|0,I0^=b<<18|b>>>14,b=E1+D0|0,r0^=b<<7|b>>>25,b=r0+E1|0,V0^=b<<9|b>>>23,b=V0+r0|0,D0^=b<<13|b>>>19,b=D0+V0|0,E1^=b<<18|b>>>14,b=n0+r0|0,X1^=b<<7|b>>>25,b=X1+n0|0,f0^=b<<9|b>>>23,b=f0+X1|0,r0^=b<<13|b>>>19,b=r0+f0|0,n0^=b<<18|b>>>14,b=v0+s0|0,Z0^=b<<7|b>>>25,b=Z0+v0|0,V0^=b<<9|b>>>23,b=V0+Z0|0,s0^=b<<13|b>>>19,b=s0+V0|0,v0^=b<<18|b>>>14,b=I0+A0|0,D0^=b<<7|b>>>25,b=D0+I0|0,j0^=b<<9|b>>>23,b=j0+D0|0,A0^=b<<13|b>>>19,b=A0+j0|0,I0^=b<<18|b>>>14,b=E1+$1|0,q1^=b<<7|b>>>25,b=q1+E1|0,B1^=b<<9|b>>>23,b=B1+q1|0,$1^=b<<13|b>>>19,b=$1+B1|0,E1^=b<<18|b>>>14;K[0]=n0>>>0&255,K[1]=n0>>>8&255,K[2]=n0>>>16&255,K[3]=n0>>>24&255,K[4]=v0>>>0&255,K[5]=v0>>>8&255,K[6]=v0>>>16&255,K[7]=v0>>>24&255,K[8]=I0>>>0&255,K[9]=I0>>>8&255,K[10]=I0>>>16&255,K[11]=I0>>>24&255,K[12]=E1>>>0&255,K[13]=E1>>>8&255,K[14]=E1>>>16&255,K[15]=E1>>>24&255,K[16]=Z0>>>0&255,K[17]=Z0>>>8&255,K[18]=Z0>>>16&255,K[19]=Z0>>>24&255,K[20]=V0>>>0&255,K[21]=V0>>>8&255,K[22]=V0>>>16&255,K[23]=V0>>>24&255,K[24]=j0>>>0&255,K[25]=j0>>>8&255,K[26]=j0>>>16&255,K[27]=j0>>>24&255,K[28]=A0>>>0&255,K[29]=A0>>>8&255,K[30]=A0>>>16&255,K[31]=A0>>>24&255}function $(K,M,C,z){x(K,M,C,z)}function F(K,M,C,z){h(K,M,C,z)}var u=new Uint8Array([101,120,112,97,110,100,32,51,50,45,98,121,116,101,32,107]);function l(K,M,C,z,L,n,e){var z0=new Uint8Array(16),R0=new Uint8Array(64),t0,b0;for(b0=0;b0<16;b0++)z0[b0]=0;for(b0=0;b0<8;b0++)z0[b0]=n[b0];while(L>=64){$(R0,z0,e,u);for(b0=0;b0<64;b0++)K[M+b0]=C[z+b0]^R0[b0];t0=1;for(b0=8;b0<16;b0++)t0=t0+(z0[b0]&255)|0,z0[b0]=t0&255,t0>>>=8;L-=64,M+=64,z+=64}if(L>0){$(R0,z0,e,u);for(b0=0;b0<L;b0++)K[M+b0]=C[z+b0]^R0[b0]}return 0}function p(K,M,C,z,L){var n=new Uint8Array(16),e=new Uint8Array(64),z0,R0;for(R0=0;R0<16;R0++)n[R0]=0;for(R0=0;R0<8;R0++)n[R0]=z[R0];while(C>=64){$(e,n,L,u);for(R0=0;R0<64;R0++)K[M+R0]=e[R0];z0=1;for(R0=8;R0<16;R0++)z0=z0+(n[R0]&255)|0,n[R0]=z0&255,z0>>>=8;C-=64,M+=64}if(C>0){$(e,n,L,u);for(R0=0;R0<C;R0++)K[M+R0]=e[R0]}return 0}function s(K,M,C,z,L){var n=new Uint8Array(32);F(n,z,L,u);var e=new Uint8Array(8);for(var z0=0;z0<8;z0++)e[z0]=z[z0+16];return p(K,M,C,e,n)}function y(K,M,C,z,L,n,e){var z0=new Uint8Array(32);F(z0,n,e,u);var R0=new Uint8Array(8);for(var t0=0;t0<8;t0++)R0[t0]=n[t0+16];return l(K,M,C,z,L,R0,z0)}var t=function(K){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 M,C,z,L,n,e,z0,R0;M=K[0]&255|(K[1]&255)<<8,this.r[0]=M&8191,C=K[2]&255|(K[3]&255)<<8,this.r[1]=(M>>>13|C<<3)&8191,z=K[4]&255|(K[5]&255)<<8,this.r[2]=(C>>>10|z<<6)&7939,L=K[6]&255|(K[7]&255)<<8,this.r[3]=(z>>>7|L<<9)&8191,n=K[8]&255|(K[9]&255)<<8,this.r[4]=(L>>>4|n<<12)&255,this.r[5]=n>>>1&8190,e=K[10]&255|(K[11]&255)<<8,this.r[6]=(n>>>14|e<<2)&8191,z0=K[12]&255|(K[13]&255)<<8,this.r[7]=(e>>>11|z0<<5)&8065,R0=K[14]&255|(K[15]&255)<<8,this.r[8]=(z0>>>8|R0<<8)&8191,this.r[9]=R0>>>5&127,this.pad[0]=K[16]&255|(K[17]&255)<<8,this.pad[1]=K[18]&255|(K[19]&255)<<8,this.pad[2]=K[20]&255|(K[21]&255)<<8,this.pad[3]=K[22]&255|(K[23]&255)<<8,this.pad[4]=K[24]&255|(K[25]&255)<<8,this.pad[5]=K[26]&255|(K[27]&255)<<8,this.pad[6]=K[28]&255|(K[29]&255)<<8,this.pad[7]=K[30]&255|(K[31]&255)<<8};t.prototype.blocks=function(K,M,C){var z=this.fin?0:2048,L,n,e,z0,R0,t0,b0,n1,l0,A1,I1,L1,T1,w1,O1,j1,n0,X1,f0,r0=this.h[0],s0=this.h[1],v0=this.h[2],Z0=this.h[3],V0=this.h[4],j0=this.h[5],A0=this.h[6],I0=this.h[7],D0=this.h[8],q1=this.h[9],B1=this.r[0],$1=this.r[1],E1=this.r[2],b=this.r[3],_1=this.r[4],i1=this.r[5],r1=this.r[6],x1=this.r[7],c1=this.r[8],l1=this.r[9];while(C>=16)L=K[M+0]&255|(K[M+1]&255)<<8,r0+=L&8191,n=K[M+2]&255|(K[M+3]&255)<<8,s0+=(L>>>13|n<<3)&8191,e=K[M+4]&255|(K[M+5]&255)<<8,v0+=(n>>>10|e<<6)&8191,z0=K[M+6]&255|(K[M+7]&255)<<8,Z0+=(e>>>7|z0<<9)&8191,R0=K[M+8]&255|(K[M+9]&255)<<8,V0+=(z0>>>4|R0<<12)&8191,j0+=R0>>>1&8191,t0=K[M+10]&255|(K[M+11]&255)<<8,A0+=(R0>>>14|t0<<2)&8191,b0=K[M+12]&255|(K[M+13]&255)<<8,I0+=(t0>>>11|b0<<5)&8191,n1=K[M+14]&255|(K[M+15]&255)<<8,D0+=(b0>>>8|n1<<8)&8191,q1+=n1>>>5|z,l0=0,A1=l0,A1+=r0*B1,A1+=s0*(5*l1),A1+=v0*(5*c1),A1+=Z0*(5*x1),A1+=V0*(5*r1),l0=A1>>>13,A1&=8191,A1+=j0*(5*i1),A1+=A0*(5*_1),A1+=I0*(5*b),A1+=D0*(5*E1),A1+=q1*(5*$1),l0+=A1>>>13,A1&=8191,I1=l0,I1+=r0*$1,I1+=s0*B1,I1+=v0*(5*l1),I1+=Z0*(5*c1),I1+=V0*(5*x1),l0=I1>>>13,I1&=8191,I1+=j0*(5*r1),I1+=A0*(5*i1),I1+=I0*(5*_1),I1+=D0*(5*b),I1+=q1*(5*E1),l0+=I1>>>13,I1&=8191,L1=l0,L1+=r0*E1,L1+=s0*$1,L1+=v0*B1,L1+=Z0*(5*l1),L1+=V0*(5*c1),l0=L1>>>13,L1&=8191,L1+=j0*(5*x1),L1+=A0*(5*r1),L1+=I0*(5*i1),L1+=D0*(5*_1),L1+=q1*(5*b),l0+=L1>>>13,L1&=8191,T1=l0,T1+=r0*b,T1+=s0*E1,T1+=v0*$1,T1+=Z0*B1,T1+=V0*(5*l1),l0=T1>>>13,T1&=8191,T1+=j0*(5*c1),T1+=A0*(5*x1),T1+=I0*(5*r1),T1+=D0*(5*i1),T1+=q1*(5*_1),l0+=T1>>>13,T1&=8191,w1=l0,w1+=r0*_1,w1+=s0*b,w1+=v0*E1,w1+=Z0*$1,w1+=V0*B1,l0=w1>>>13,w1&=8191,w1+=j0*(5*l1),w1+=A0*(5*c1),w1+=I0*(5*x1),w1+=D0*(5*r1),w1+=q1*(5*i1),l0+=w1>>>13,w1&=8191,O1=l0,O1+=r0*i1,O1+=s0*_1,O1+=v0*b,O1+=Z0*E1,O1+=V0*$1,l0=O1>>>13,O1&=8191,O1+=j0*B1,O1+=A0*(5*l1),O1+=I0*(5*c1),O1+=D0*(5*x1),O1+=q1*(5*r1),l0+=O1>>>13,O1&=8191,j1=l0,j1+=r0*r1,j1+=s0*i1,j1+=v0*_1,j1+=Z0*b,j1+=V0*E1,l0=j1>>>13,j1&=8191,j1+=j0*$1,j1+=A0*B1,j1+=I0*(5*l1),j1+=D0*(5*c1),j1+=q1*(5*x1),l0+=j1>>>13,j1&=8191,n0=l0,n0+=r0*x1,n0+=s0*r1,n0+=v0*i1,n0+=Z0*_1,n0+=V0*b,l0=n0>>>13,n0&=8191,n0+=j0*E1,n0+=A0*$1,n0+=I0*B1,n0+=D0*(5*l1),n0+=q1*(5*c1),l0+=n0>>>13,n0&=8191,X1=l0,X1+=r0*c1,X1+=s0*x1,X1+=v0*r1,X1+=Z0*i1,X1+=V0*_1,l0=X1>>>13,X1&=8191,X1+=j0*b,X1+=A0*E1,X1+=I0*$1,X1+=D0*B1,X1+=q1*(5*l1),l0+=X1>>>13,X1&=8191,f0=l0,f0+=r0*l1,f0+=s0*c1,f0+=v0*x1,f0+=Z0*r1,f0+=V0*i1,l0=f0>>>13,f0&=8191,f0+=j0*_1,f0+=A0*b,f0+=I0*E1,f0+=D0*$1,f0+=q1*B1,l0+=f0>>>13,f0&=8191,l0=(l0<<2)+l0|0,l0=l0+A1|0,A1=l0&8191,l0=l0>>>13,I1+=l0,r0=A1,s0=I1,v0=L1,Z0=T1,V0=w1,j0=O1,A0=j1,I0=n0,D0=X1,q1=f0,M+=16,C-=16;this.h[0]=r0,this.h[1]=s0,this.h[2]=v0,this.h[3]=Z0,this.h[4]=V0,this.h[5]=j0,this.h[6]=A0,this.h[7]=I0,this.h[8]=D0,this.h[9]=q1},t.prototype.finish=function(K,M){var C=new Uint16Array(10),z,L,n,e;if(this.leftover){e=this.leftover,this.buffer[e++]=1;for(;e<16;e++)this.buffer[e]=0;this.fin=1,this.blocks(this.buffer,0,16)}z=this.h[1]>>>13,this.h[1]&=8191;for(e=2;e<10;e++)this.h[e]+=z,z=this.h[e]>>>13,this.h[e]&=8191;this.h[0]+=z*5,z=this.h[0]>>>13,this.h[0]&=8191,this.h[1]+=z,z=this.h[1]>>>13,this.h[1]&=8191,this.h[2]+=z,C[0]=this.h[0]+5,z=C[0]>>>13,C[0]&=8191;for(e=1;e<10;e++)C[e]=this.h[e]+z,z=C[e]>>>13,C[e]&=8191;C[9]-=8192,L=(z^1)-1;for(e=0;e<10;e++)C[e]&=L;L=~L;for(e=0;e<10;e++)this.h[e]=this.h[e]&L|C[e];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,n=this.h[0]+this.pad[0],this.h[0]=n&65535;for(e=1;e<8;e++)n=(this.h[e]+this.pad[e]|0)+(n>>>16)|0,this.h[e]=n&65535;K[M+0]=this.h[0]>>>0&255,K[M+1]=this.h[0]>>>8&255,K[M+2]=this.h[1]>>>0&255,K[M+3]=this.h[1]>>>8&255,K[M+4]=this.h[2]>>>0&255,K[M+5]=this.h[2]>>>8&255,K[M+6]=this.h[3]>>>0&255,K[M+7]=this.h[3]>>>8&255,K[M+8]=this.h[4]>>>0&255,K[M+9]=this.h[4]>>>8&255,K[M+10]=this.h[5]>>>0&255,K[M+11]=this.h[5]>>>8&255,K[M+12]=this.h[6]>>>0&255,K[M+13]=this.h[6]>>>8&255,K[M+14]=this.h[7]>>>0&255,K[M+15]=this.h[7]>>>8&255},t.prototype.update=function(K,M,C){var z,L;if(this.leftover){if(L=16-this.leftover,L>C)L=C;for(z=0;z<L;z++)this.buffer[this.leftover+z]=K[M+z];if(C-=L,M+=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(K,M,L),M+=L,C-=L;if(C){for(z=0;z<C;z++)this.buffer[this.leftover+z]=K[M+z];this.leftover+=C}};function H0(K,M,C,z,L,n){var e=new t(n);return e.update(C,z,L),e.finish(K,M),0}function g(K,M,C,z,L,n){var e=new Uint8Array(16);return H0(e,0,C,z,L,n),O(K,M,e,0)}function d(K,M,C,z,L){var n;if(C<32)return-1;y(K,0,M,0,C,z,L),H0(K,16,K,32,C-32,K);for(n=0;n<16;n++)K[n]=0;return 0}function P(K,M,C,z,L){var n,e=new Uint8Array(32);if(C<32)return-1;if(s(e,0,32,z,L),g(M,16,M,32,C-32,e)!==0)return-1;y(K,0,M,0,C,z,L);for(n=0;n<32;n++)K[n]=0;return 0}function E(K,M){var C;for(C=0;C<16;C++)K[C]=M[C]|0}function f(K){var M,C,z=1;for(M=0;M<16;M++)C=K[M]+z+65535,z=Math.floor(C/65536),K[M]=C-z*65536;K[0]+=z-1+37*(z-1)}function r(K,M,C){var z,L=~(C-1);for(var n=0;n<16;n++)z=L&(K[n]^M[n]),K[n]^=z,M[n]^=z}function o(K,M){var C,z,L,n=X(),e=X();for(C=0;C<16;C++)e[C]=M[C];f(e),f(e),f(e);for(z=0;z<2;z++){n[0]=e[0]-65517;for(C=1;C<15;C++)n[C]=e[C]-65535-(n[C-1]>>16&1),n[C-1]&=65535;n[15]=e[15]-32767-(n[14]>>16&1),L=n[15]>>16&1,n[14]&=65535,r(e,n,1-L)}for(C=0;C<16;C++)K[2*C]=e[C]&255,K[2*C+1]=e[C]>>8}function B(K,M){var C=new Uint8Array(32),z=new Uint8Array(32);return o(C,K),o(z,M),T(C,0,z,0)}function S(K){var M=new Uint8Array(32);return o(M,K),M[0]&1}function _(K,M){var C;for(C=0;C<16;C++)K[C]=M[2*C]+(M[2*C+1]<<8);K[15]&=32767}function v(K,M,C){for(var z=0;z<16;z++)K[z]=M[z]+C[z]}function R(K,M,C){for(var z=0;z<16;z++)K[z]=M[z]-C[z]}function m(K,M,C){var z,L,n=0,e=0,z0=0,R0=0,t0=0,b0=0,n1=0,l0=0,A1=0,I1=0,L1=0,T1=0,w1=0,O1=0,j1=0,n0=0,X1=0,f0=0,r0=0,s0=0,v0=0,Z0=0,V0=0,j0=0,A0=0,I0=0,D0=0,q1=0,B1=0,$1=0,E1=0,b=C[0],_1=C[1],i1=C[2],r1=C[3],x1=C[4],c1=C[5],l1=C[6],k8=C[7],Y8=C[8],P8=C[9],R8=C[10],L8=C[11],m8=C[12],H9=C[13],A9=C[14],z9=C[15];z=M[0],n+=z*b,e+=z*_1,z0+=z*i1,R0+=z*r1,t0+=z*x1,b0+=z*c1,n1+=z*l1,l0+=z*k8,A1+=z*Y8,I1+=z*P8,L1+=z*R8,T1+=z*L8,w1+=z*m8,O1+=z*H9,j1+=z*A9,n0+=z*z9,z=M[1],e+=z*b,z0+=z*_1,R0+=z*i1,t0+=z*r1,b0+=z*x1,n1+=z*c1,l0+=z*l1,A1+=z*k8,I1+=z*Y8,L1+=z*P8,T1+=z*R8,w1+=z*L8,O1+=z*m8,j1+=z*H9,n0+=z*A9,X1+=z*z9,z=M[2],z0+=z*b,R0+=z*_1,t0+=z*i1,b0+=z*r1,n1+=z*x1,l0+=z*c1,A1+=z*l1,I1+=z*k8,L1+=z*Y8,T1+=z*P8,w1+=z*R8,O1+=z*L8,j1+=z*m8,n0+=z*H9,X1+=z*A9,f0+=z*z9,z=M[3],R0+=z*b,t0+=z*_1,b0+=z*i1,n1+=z*r1,l0+=z*x1,A1+=z*c1,I1+=z*l1,L1+=z*k8,T1+=z*Y8,w1+=z*P8,O1+=z*R8,j1+=z*L8,n0+=z*m8,X1+=z*H9,f0+=z*A9,r0+=z*z9,z=M[4],t0+=z*b,b0+=z*_1,n1+=z*i1,l0+=z*r1,A1+=z*x1,I1+=z*c1,L1+=z*l1,T1+=z*k8,w1+=z*Y8,O1+=z*P8,j1+=z*R8,n0+=z*L8,X1+=z*m8,f0+=z*H9,r0+=z*A9,s0+=z*z9,z=M[5],b0+=z*b,n1+=z*_1,l0+=z*i1,A1+=z*r1,I1+=z*x1,L1+=z*c1,T1+=z*l1,w1+=z*k8,O1+=z*Y8,j1+=z*P8,n0+=z*R8,X1+=z*L8,f0+=z*m8,r0+=z*H9,s0+=z*A9,v0+=z*z9,z=M[6],n1+=z*b,l0+=z*_1,A1+=z*i1,I1+=z*r1,L1+=z*x1,T1+=z*c1,w1+=z*l1,O1+=z*k8,j1+=z*Y8,n0+=z*P8,X1+=z*R8,f0+=z*L8,r0+=z*m8,s0+=z*H9,v0+=z*A9,Z0+=z*z9,z=M[7],l0+=z*b,A1+=z*_1,I1+=z*i1,L1+=z*r1,T1+=z*x1,w1+=z*c1,O1+=z*l1,j1+=z*k8,n0+=z*Y8,X1+=z*P8,f0+=z*R8,r0+=z*L8,s0+=z*m8,v0+=z*H9,Z0+=z*A9,V0+=z*z9,z=M[8],A1+=z*b,I1+=z*_1,L1+=z*i1,T1+=z*r1,w1+=z*x1,O1+=z*c1,j1+=z*l1,n0+=z*k8,X1+=z*Y8,f0+=z*P8,r0+=z*R8,s0+=z*L8,v0+=z*m8,Z0+=z*H9,V0+=z*A9,j0+=z*z9,z=M[9],I1+=z*b,L1+=z*_1,T1+=z*i1,w1+=z*r1,O1+=z*x1,j1+=z*c1,n0+=z*l1,X1+=z*k8,f0+=z*Y8,r0+=z*P8,s0+=z*R8,v0+=z*L8,Z0+=z*m8,V0+=z*H9,j0+=z*A9,A0+=z*z9,z=M[10],L1+=z*b,T1+=z*_1,w1+=z*i1,O1+=z*r1,j1+=z*x1,n0+=z*c1,X1+=z*l1,f0+=z*k8,r0+=z*Y8,s0+=z*P8,v0+=z*R8,Z0+=z*L8,V0+=z*m8,j0+=z*H9,A0+=z*A9,I0+=z*z9,z=M[11],T1+=z*b,w1+=z*_1,O1+=z*i1,j1+=z*r1,n0+=z*x1,X1+=z*c1,f0+=z*l1,r0+=z*k8,s0+=z*Y8,v0+=z*P8,Z0+=z*R8,V0+=z*L8,j0+=z*m8,A0+=z*H9,I0+=z*A9,D0+=z*z9,z=M[12],w1+=z*b,O1+=z*_1,j1+=z*i1,n0+=z*r1,X1+=z*x1,f0+=z*c1,r0+=z*l1,s0+=z*k8,v0+=z*Y8,Z0+=z*P8,V0+=z*R8,j0+=z*L8,A0+=z*m8,I0+=z*H9,D0+=z*A9,q1+=z*z9,z=M[13],O1+=z*b,j1+=z*_1,n0+=z*i1,X1+=z*r1,f0+=z*x1,r0+=z*c1,s0+=z*l1,v0+=z*k8,Z0+=z*Y8,V0+=z*P8,j0+=z*R8,A0+=z*L8,I0+=z*m8,D0+=z*H9,q1+=z*A9,B1+=z*z9,z=M[14],j1+=z*b,n0+=z*_1,X1+=z*i1,f0+=z*r1,r0+=z*x1,s0+=z*c1,v0+=z*l1,Z0+=z*k8,V0+=z*Y8,j0+=z*P8,A0+=z*R8,I0+=z*L8,D0+=z*m8,q1+=z*H9,B1+=z*A9,$1+=z*z9,z=M[15],n0+=z*b,X1+=z*_1,f0+=z*i1,r0+=z*r1,s0+=z*x1,v0+=z*c1,Z0+=z*l1,V0+=z*k8,j0+=z*Y8,A0+=z*P8,I0+=z*R8,D0+=z*L8,q1+=z*m8,B1+=z*H9,$1+=z*A9,E1+=z*z9,n+=38*X1,e+=38*f0,z0+=38*r0,R0+=38*s0,t0+=38*v0,b0+=38*Z0,n1+=38*V0,l0+=38*j0,A1+=38*A0,I1+=38*I0,L1+=38*D0,T1+=38*q1,w1+=38*B1,O1+=38*$1,j1+=38*E1,L=1,z=n+L+65535,L=Math.floor(z/65536),n=z-L*65536,z=e+L+65535,L=Math.floor(z/65536),e=z-L*65536,z=z0+L+65535,L=Math.floor(z/65536),z0=z-L*65536,z=R0+L+65535,L=Math.floor(z/65536),R0=z-L*65536,z=t0+L+65535,L=Math.floor(z/65536),t0=z-L*65536,z=b0+L+65535,L=Math.floor(z/65536),b0=z-L*65536,z=n1+L+65535,L=Math.floor(z/65536),n1=z-L*65536,z=l0+L+65535,L=Math.floor(z/65536),l0=z-L*65536,z=A1+L+65535,L=Math.floor(z/65536),A1=z-L*65536,z=I1+L+65535,L=Math.floor(z/65536),I1=z-L*65536,z=L1+L+65535,L=Math.floor(z/65536),L1=z-L*65536,z=T1+L+65535,L=Math.floor(z/65536),T1=z-L*65536,z=w1+L+65535,L=Math.floor(z/65536),w1=z-L*65536,z=O1+L+65535,L=Math.floor(z/65536),O1=z-L*65536,z=j1+L+65535,L=Math.floor(z/65536),j1=z-L*65536,z=n0+L+65535,L=Math.floor(z/65536),n0=z-L*65536,n+=L-1+37*(L-1),L=1,z=n+L+65535,L=Math.floor(z/65536),n=z-L*65536,z=e+L+65535,L=Math.floor(z/65536),e=z-L*65536,z=z0+L+65535,L=Math.floor(z/65536),z0=z-L*65536,z=R0+L+65535,L=Math.floor(z/65536),R0=z-L*65536,z=t0+L+65535,L=Math.floor(z/65536),t0=z-L*65536,z=b0+L+65535,L=Math.floor(z/65536),b0=z-L*65536,z=n1+L+65535,L=Math.floor(z/65536),n1=z-L*65536,z=l0+L+65535,L=Math.floor(z/65536),l0=z-L*65536,z=A1+L+65535,L=Math.floor(z/65536),A1=z-L*65536,z=I1+L+65535,L=Math.floor(z/65536),I1=z-L*65536,z=L1+L+65535,L=Math.floor(z/65536),L1=z-L*65536,z=T1+L+65535,L=Math.floor(z/65536),T1=z-L*65536,z=w1+L+65535,L=Math.floor(z/65536),w1=z-L*65536,z=O1+L+65535,L=Math.floor(z/65536),O1=z-L*65536,z=j1+L+65535,L=Math.floor(z/65536),j1=z-L*65536,z=n0+L+65535,L=Math.floor(z/65536),n0=z-L*65536,n+=L-1+37*(L-1),K[0]=n,K[1]=e,K[2]=z0,K[3]=R0,K[4]=t0,K[5]=b0,K[6]=n1,K[7]=l0,K[8]=A1,K[9]=I1,K[10]=L1,K[11]=T1,K[12]=w1,K[13]=O1,K[14]=j1,K[15]=n0}function J0(K,M){m(K,M,M)}function U0(K,M){var C=X(),z;for(z=0;z<16;z++)C[z]=M[z];for(z=253;z>=0;z--)if(J0(C,C),z!==2&&z!==4)m(C,C,M);for(z=0;z<16;z++)K[z]=C[z]}function q0(K,M){var C=X(),z;for(z=0;z<16;z++)C[z]=M[z];for(z=250;z>=0;z--)if(J0(C,C),z!==1)m(C,C,M);for(z=0;z<16;z++)K[z]=C[z]}function $0(K,M,C){var z=new Uint8Array(32),L=new Float64Array(80),n,e,z0=X(),R0=X(),t0=X(),b0=X(),n1=X(),l0=X();for(e=0;e<31;e++)z[e]=M[e];z[31]=M[31]&127|64,z[0]&=248,_(L,C);for(e=0;e<16;e++)R0[e]=L[e],b0[e]=z0[e]=t0[e]=0;z0[0]=b0[0]=1;for(e=254;e>=0;--e)n=z[e>>>3]>>>(e&7)&1,r(z0,R0,n),r(t0,b0,n),v(n1,z0,t0),R(z0,z0,t0),v(t0,R0,b0),R(R0,R0,b0),J0(b0,n1),J0(l0,z0),m(z0,t0,z0),m(t0,R0,n1),v(n1,z0,t0),R(z0,z0,t0),J0(R0,z0),R(t0,b0,l0),m(z0,t0,U),v(z0,z0,b0),m(t0,t0,z0),m(z0,b0,l0),m(b0,R0,L),J0(R0,n1),r(z0,R0,n),r(t0,b0,n);for(e=0;e<16;e++)L[e+16]=z0[e],L[e+32]=t0[e],L[e+48]=R0[e],L[e+64]=b0[e];var A1=L.subarray(32),I1=L.subarray(16);return U0(A1,A1),m(I1,I1,A1),o(K,I1),0}function u0(K,M){return $0(K,M,J)}function H1(K,M){return G(M,32),u0(K,M)}function v1(K,M,C){var z=new Uint8Array(32);return $0(z,C,M),F(K,Y,z,u)}var h0=d,F1=P;function S1(K,M,C,z,L,n){var e=new Uint8Array(32);return v1(e,L,n),h0(K,M,C,z,e)}function N0(K,M,C,z,L,n){var e=new Uint8Array(32);return v1(e,L,n),F1(K,M,C,z,e)}var F0=[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 m0(K,M,C,z){var L=new Int32Array(16),n=new Int32Array(16),e,z0,R0,t0,b0,n1,l0,A1,I1,L1,T1,w1,O1,j1,n0,X1,f0,r0,s0,v0,Z0,V0,j0,A0,I0,D0,q1=K[0],B1=K[1],$1=K[2],E1=K[3],b=K[4],_1=K[5],i1=K[6],r1=K[7],x1=M[0],c1=M[1],l1=M[2],k8=M[3],Y8=M[4],P8=M[5],R8=M[6],L8=M[7],m8=0;while(z>=128){for(s0=0;s0<16;s0++)v0=8*s0+m8,L[s0]=C[v0+0]<<24|C[v0+1]<<16|C[v0+2]<<8|C[v0+3],n[s0]=C[v0+4]<<24|C[v0+5]<<16|C[v0+6]<<8|C[v0+7];for(s0=0;s0<80;s0++)if(e=q1,z0=B1,R0=$1,t0=E1,b0=b,n1=_1,l0=i1,A1=r1,I1=x1,L1=c1,T1=l1,w1=k8,O1=Y8,j1=P8,n0=R8,X1=L8,Z0=r1,V0=L8,j0=V0&65535,A0=V0>>>16,I0=Z0&65535,D0=Z0>>>16,Z0=(b>>>14|Y8<<18)^(b>>>18|Y8<<14)^(Y8>>>9|b<<23),V0=(Y8>>>14|b<<18)^(Y8>>>18|b<<14)^(b>>>9|Y8<<23),j0+=V0&65535,A0+=V0>>>16,I0+=Z0&65535,D0+=Z0>>>16,Z0=b&_1^~b&i1,V0=Y8&P8^~Y8&R8,j0+=V0&65535,A0+=V0>>>16,I0+=Z0&65535,D0+=Z0>>>16,Z0=F0[s0*2],V0=F0[s0*2+1],j0+=V0&65535,A0+=V0>>>16,I0+=Z0&65535,D0+=Z0>>>16,Z0=L[s0%16],V0=n[s0%16],j0+=V0&65535,A0+=V0>>>16,I0+=Z0&65535,D0+=Z0>>>16,A0+=j0>>>16,I0+=A0>>>16,D0+=I0>>>16,f0=I0&65535|D0<<16,r0=j0&65535|A0<<16,Z0=f0,V0=r0,j0=V0&65535,A0=V0>>>16,I0=Z0&65535,D0=Z0>>>16,Z0=(q1>>>28|x1<<4)^(x1>>>2|q1<<30)^(x1>>>7|q1<<25),V0=(x1>>>28|q1<<4)^(q1>>>2|x1<<30)^(q1>>>7|x1<<25),j0+=V0&65535,A0+=V0>>>16,I0+=Z0&65535,D0+=Z0>>>16,Z0=q1&B1^q1&$1^B1&$1,V0=x1&c1^x1&l1^c1&l1,j0+=V0&65535,A0+=V0>>>16,I0+=Z0&65535,D0+=Z0>>>16,A0+=j0>>>16,I0+=A0>>>16,D0+=I0>>>16,A1=I0&65535|D0<<16,X1=j0&65535|A0<<16,Z0=t0,V0=w1,j0=V0&65535,A0=V0>>>16,I0=Z0&65535,D0=Z0>>>16,Z0=f0,V0=r0,j0+=V0&65535,A0+=V0>>>16,I0+=Z0&65535,D0+=Z0>>>16,A0+=j0>>>16,I0+=A0>>>16,D0+=I0>>>16,t0=I0&65535|D0<<16,w1=j0&65535|A0<<16,B1=e,$1=z0,E1=R0,b=t0,_1=b0,i1=n1,r1=l0,q1=A1,c1=I1,l1=L1,k8=T1,Y8=w1,P8=O1,R8=j1,L8=n0,x1=X1,s0%16===15)for(v0=0;v0<16;v0++)Z0=L[v0],V0=n[v0],j0=V0&65535,A0=V0>>>16,I0=Z0&65535,D0=Z0>>>16,Z0=L[(v0+9)%16],V0=n[(v0+9)%16],j0+=V0&65535,A0+=V0>>>16,I0+=Z0&65535,D0+=Z0>>>16,f0=L[(v0+1)%16],r0=n[(v0+1)%16],Z0=(f0>>>1|r0<<31)^(f0>>>8|r0<<24)^f0>>>7,V0=(r0>>>1|f0<<31)^(r0>>>8|f0<<24)^(r0>>>7|f0<<25),j0+=V0&65535,A0+=V0>>>16,I0+=Z0&65535,D0+=Z0>>>16,f0=L[(v0+14)%16],r0=n[(v0+14)%16],Z0=(f0>>>19|r0<<13)^(r0>>>29|f0<<3)^f0>>>6,V0=(r0>>>19|f0<<13)^(f0>>>29|r0<<3)^(r0>>>6|f0<<26),j0+=V0&65535,A0+=V0>>>16,I0+=Z0&65535,D0+=Z0>>>16,A0+=j0>>>16,I0+=A0>>>16,D0+=I0>>>16,L[v0]=I0&65535|D0<<16,n[v0]=j0&65535|A0<<16;Z0=q1,V0=x1,j0=V0&65535,A0=V0>>>16,I0=Z0&65535,D0=Z0>>>16,Z0=K[0],V0=M[0],j0+=V0&65535,A0+=V0>>>16,I0+=Z0&65535,D0+=Z0>>>16,A0+=j0>>>16,I0+=A0>>>16,D0+=I0>>>16,K[0]=q1=I0&65535|D0<<16,M[0]=x1=j0&65535|A0<<16,Z0=B1,V0=c1,j0=V0&65535,A0=V0>>>16,I0=Z0&65535,D0=Z0>>>16,Z0=K[1],V0=M[1],j0+=V0&65535,A0+=V0>>>16,I0+=Z0&65535,D0+=Z0>>>16,A0+=j0>>>16,I0+=A0>>>16,D0+=I0>>>16,K[1]=B1=I0&65535|D0<<16,M[1]=c1=j0&65535|A0<<16,Z0=$1,V0=l1,j0=V0&65535,A0=V0>>>16,I0=Z0&65535,D0=Z0>>>16,Z0=K[2],V0=M[2],j0+=V0&65535,A0+=V0>>>16,I0+=Z0&65535,D0+=Z0>>>16,A0+=j0>>>16,I0+=A0>>>16,D0+=I0>>>16,K[2]=$1=I0&65535|D0<<16,M[2]=l1=j0&65535|A0<<16,Z0=E1,V0=k8,j0=V0&65535,A0=V0>>>16,I0=Z0&65535,D0=Z0>>>16,Z0=K[3],V0=M[3],j0+=V0&65535,A0+=V0>>>16,I0+=Z0&65535,D0+=Z0>>>16,A0+=j0>>>16,I0+=A0>>>16,D0+=I0>>>16,K[3]=E1=I0&65535|D0<<16,M[3]=k8=j0&65535|A0<<16,Z0=b,V0=Y8,j0=V0&65535,A0=V0>>>16,I0=Z0&65535,D0=Z0>>>16,Z0=K[4],V0=M[4],j0+=V0&65535,A0+=V0>>>16,I0+=Z0&65535,D0+=Z0>>>16,A0+=j0>>>16,I0+=A0>>>16,D0+=I0>>>16,K[4]=b=I0&65535|D0<<16,M[4]=Y8=j0&65535|A0<<16,Z0=_1,V0=P8,j0=V0&65535,A0=V0>>>16,I0=Z0&65535,D0=Z0>>>16,Z0=K[5],V0=M[5],j0+=V0&65535,A0+=V0>>>16,I0+=Z0&65535,D0+=Z0>>>16,A0+=j0>>>16,I0+=A0>>>16,D0+=I0>>>16,K[5]=_1=I0&65535|D0<<16,M[5]=P8=j0&65535|A0<<16,Z0=i1,V0=R8,j0=V0&65535,A0=V0>>>16,I0=Z0&65535,D0=Z0>>>16,Z0=K[6],V0=M[6],j0+=V0&65535,A0+=V0>>>16,I0+=Z0&65535,D0+=Z0>>>16,A0+=j0>>>16,I0+=A0>>>16,D0+=I0>>>16,K[6]=i1=I0&65535|D0<<16,M[6]=R8=j0&65535|A0<<16,Z0=r1,V0=L8,j0=V0&65535,A0=V0>>>16,I0=Z0&65535,D0=Z0>>>16,Z0=K[7],V0=M[7],j0+=V0&65535,A0+=V0>>>16,I0+=Z0&65535,D0+=Z0>>>16,A0+=j0>>>16,I0+=A0>>>16,D0+=I0>>>16,K[7]=r1=I0&65535|D0<<16,M[7]=L8=j0&65535|A0<<16,m8+=128,z-=128}return z}function Y0(K,M,C){var z=new Int32Array(8),L=new Int32Array(8),n=new Uint8Array(256),e,z0=C;z[0]=1779033703,z[1]=3144134277,z[2]=1013904242,z[3]=2773480762,z[4]=1359893119,z[5]=2600822924,z[6]=528734635,z[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,m0(z,L,M,C),C%=128;for(e=0;e<C;e++)n[e]=M[z0-C+e];n[C]=128,C=256-128*(C<112?1:0),n[C-9]=0,I(n,C-8,z0/536870912|0,z0<<3),m0(z,L,n,C);for(e=0;e<8;e++)I(K,8*e,z[e],L[e]);return 0}function K0(K,M){var C=X(),z=X(),L=X(),n=X(),e=X(),z0=X(),R0=X(),t0=X(),b0=X();R(C,K[1],K[0]),R(b0,M[1],M[0]),m(C,C,b0),v(z,K[0],K[1]),v(b0,M[0],M[1]),m(z,z,b0),m(L,K[3],M[3]),m(L,L,N),m(n,K[2],M[2]),v(n,n,n),R(e,z,C),R(z0,n,L),v(R0,n,L),v(t0,z,C),m(K[0],e,z0),m(K[1],t0,R0),m(K[2],R0,z0),m(K[3],e,t0)}function P0(K,M,C){var z;for(z=0;z<4;z++)r(K[z],M[z],C)}function k0(K,M){var C=X(),z=X(),L=X();U0(L,M[2]),m(C,M[0],L),m(z,M[1],L),o(K,z),K[31]^=S(C)<<7}function R1(K,M,C){var z,L;E(K[0],Z),E(K[1],V),E(K[2],V),E(K[3],Z);for(L=255;L>=0;--L)z=C[L/8|0]>>(L&7)&1,P0(K,M,z),K0(M,K),K0(K,K),P0(K,M,z)}function Q1(K,M){var C=[X(),X(),X(),X()];E(C[0],q),E(C[1],A),E(C[2],V),m(C[3],q,A),R1(K,C,M)}function X0(K,M,C){var z=new Uint8Array(64),L=[X(),X(),X(),X()],n;if(!C)G(M,32);Y0(z,M,32),z[0]&=248,z[31]&=127,z[31]|=64,Q1(L,z),k0(K,L);for(n=0;n<32;n++)M[n+32]=K[n];return 0}var C0=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 x0(K,M){var C,z,L,n;for(z=63;z>=32;--z){C=0;for(L=z-32,n=z-12;L<n;++L)M[L]+=C-16*M[z]*C0[L-(z-32)],C=Math.floor((M[L]+128)/256),M[L]-=C*256;M[L]+=C,M[z]=0}C=0;for(L=0;L<32;L++)M[L]+=C-(M[31]>>4)*C0[L],C=M[L]>>8,M[L]&=255;for(L=0;L<32;L++)M[L]-=C*C0[L];for(z=0;z<32;z++)M[z+1]+=M[z]>>8,K[z]=M[z]&255}function k1(K){var M=new Float64Array(64),C;for(C=0;C<64;C++)M[C]=K[C];for(C=0;C<64;C++)K[C]=0;x0(K,M)}function W8(K,M,C,z){var L=new Uint8Array(64),n=new Uint8Array(64),e=new Uint8Array(64),z0,R0,t0=new Float64Array(64),b0=[X(),X(),X(),X()];Y0(L,z,32),L[0]&=248,L[31]&=127,L[31]|=64;var n1=C+64;for(z0=0;z0<C;z0++)K[64+z0]=M[z0];for(z0=0;z0<32;z0++)K[32+z0]=L[32+z0];Y0(e,K.subarray(32),C+32),k1(e),Q1(b0,e),k0(K,b0);for(z0=32;z0<64;z0++)K[z0]=z[z0];Y0(n,K,C+64),k1(n);for(z0=0;z0<64;z0++)t0[z0]=0;for(z0=0;z0<32;z0++)t0[z0]=e[z0];for(z0=0;z0<32;z0++)for(R0=0;R0<32;R0++)t0[z0+R0]+=n[z0]*L[R0];return x0(K.subarray(32),t0),n1}function d1(K,M){var C=X(),z=X(),L=X(),n=X(),e=X(),z0=X(),R0=X();if(E(K[2],V),_(K[1],M),J0(L,K[1]),m(n,L,Q),R(L,L,K[2]),v(n,K[2],n),J0(e,n),J0(z0,e),m(R0,z0,e),m(C,R0,L),m(C,C,n),q0(C,C),m(C,C,L),m(C,C,n),m(C,C,n),m(K[0],C,n),J0(z,K[0]),m(z,z,n),B(z,L))m(K[0],K[0],H);if(J0(z,K[0]),m(z,z,n),B(z,L))return-1;if(S(K[0])===M[31]>>7)R(K[0],Z,K[0]);return m(K[3],K[0],K[1]),0}function N1(K,M,C,z){var L,n=new Uint8Array(32),e=new Uint8Array(64),z0=[X(),X(),X(),X()],R0=[X(),X(),X(),X()];if(C<64)return-1;if(d1(R0,z))return-1;for(L=0;L<C;L++)K[L]=M[L];for(L=0;L<32;L++)K[L+32]=z[L];if(Y0(e,K,C),k1(e),R1(z0,R0,e),Q1(R0,M.subarray(32)),K0(z0,R0),k0(n,z0),C-=64,T(M,0,n,0)){for(L=0;L<C;L++)K[L]=0;return-1}for(L=0;L<C;L++)K[L]=M[L+64];return C}var c=32,W0=24,Q0=32,T0=16,e0=32,q8=32,I8=32,C1=32,_0=32,p0=W0,o0=Q0,a0=T0,z1=64,o1=32,Z8=64,S9=32,lX=64;W.lowlevel={crypto_core_hsalsa20:F,crypto_stream_xor:y,crypto_stream:s,crypto_stream_salsa20_xor:l,crypto_stream_salsa20:p,crypto_onetimeauth:H0,crypto_onetimeauth_verify:g,crypto_verify_16:O,crypto_verify_32:T,crypto_secretbox:d,crypto_secretbox_open:P,crypto_scalarmult:$0,crypto_scalarmult_base:u0,crypto_box_beforenm:v1,crypto_box_afternm:h0,crypto_box:S1,crypto_box_open:N0,crypto_box_keypair:H1,crypto_hash:Y0,crypto_sign:W8,crypto_sign_keypair:X0,crypto_sign_open:N1,crypto_secretbox_KEYBYTES:c,crypto_secretbox_NONCEBYTES:W0,crypto_secretbox_ZEROBYTES:Q0,crypto_secretbox_BOXZEROBYTES:T0,crypto_scalarmult_BYTES:e0,crypto_scalarmult_SCALARBYTES:q8,crypto_box_PUBLICKEYBYTES:I8,crypto_box_SECRETKEYBYTES:C1,crypto_box_BEFORENMBYTES:_0,crypto_box_NONCEBYTES:p0,crypto_box_ZEROBYTES:o0,crypto_box_BOXZEROBYTES:a0,crypto_sign_BYTES:z1,crypto_sign_PUBLICKEYBYTES:o1,crypto_sign_SECRETKEYBYTES:Z8,crypto_sign_SEEDBYTES:S9,crypto_hash_BYTES:lX,gf:X,D:Q,L:C0,pack25519:o,unpack25519:_,M:m,A:v,S:J0,Z:R,pow2523:q0,add:K0,set25519:E,modL:x0,scalarmult:R1,scalarbase:Q1};function vU(K,M){if(K.length!==c)throw Error("bad key size");if(M.length!==W0)throw Error("bad nonce size")}function HA(K,M){if(K.length!==I8)throw Error("bad public key size");if(M.length!==C1)throw Error("bad secret key size")}function X5(){for(var K=0;K<arguments.length;K++)if(!(arguments[K]instanceof Uint8Array))throw TypeError("unexpected type, use Uint8Array")}function ID(K){for(var M=0;M<K.length;M++)K[M]=0}W.randomBytes=function(K){var M=new Uint8Array(K);return G(M,K),M},W.secretbox=function(K,M,C){X5(K,M,C),vU(C,M);var z=new Uint8Array(Q0+K.length),L=new Uint8Array(z.length);for(var n=0;n<K.length;n++)z[n+Q0]=K[n];return d(L,z,z.length,M,C),L.subarray(T0)},W.secretbox.open=function(K,M,C){X5(K,M,C),vU(C,M);var z=new Uint8Array(T0+K.length),L=new Uint8Array(z.length);for(var n=0;n<K.length;n++)z[n+T0]=K[n];if(z.length<32)return null;if(P(L,z,z.length,M,C)!==0)return null;return L.subarray(Q0)},W.secretbox.keyLength=c,W.secretbox.nonceLength=W0,W.secretbox.overheadLength=T0,W.scalarMult=function(K,M){if(X5(K,M),K.length!==q8)throw Error("bad n size");if(M.length!==e0)throw Error("bad p size");var C=new Uint8Array(e0);return $0(C,K,M),C},W.scalarMult.base=function(K){if(X5(K),K.length!==q8)throw Error("bad n size");var M=new Uint8Array(e0);return u0(M,K),M},W.scalarMult.scalarLength=q8,W.scalarMult.groupElementLength=e0,W.box=function(K,M,C,z){var L=W.box.before(C,z);return W.secretbox(K,M,L)},W.box.before=function(K,M){X5(K,M),HA(K,M);var C=new Uint8Array(_0);return v1(C,K,M),C},W.box.after=W.secretbox,W.box.open=function(K,M,C,z){var L=W.box.before(C,z);return W.secretbox.open(K,M,L)},W.box.open.after=W.secretbox.open,W.box.keyPair=function(){var K=new Uint8Array(I8),M=new Uint8Array(C1);return H1(K,M),{publicKey:K,secretKey:M}},W.box.keyPair.fromSecretKey=function(K){if(X5(K),K.length!==C1)throw Error("bad secret key size");var M=new Uint8Array(I8);return u0(M,K),{publicKey:M,secretKey:new Uint8Array(K)}},W.box.publicKeyLength=I8,W.box.secretKeyLength=C1,W.box.sharedKeyLength=_0,W.box.nonceLength=p0,W.box.overheadLength=W.secretbox.overheadLength,W.sign=function(K,M){if(X5(K,M),M.length!==Z8)throw Error("bad secret key size");var C=new Uint8Array(z1+K.length);return W8(C,K,K.length,M),C},W.sign.open=function(K,M){if(X5(K,M),M.length!==o1)throw Error("bad public key size");var C=new Uint8Array(K.length),z=N1(C,K,K.length,M);if(z<0)return null;var L=new Uint8Array(z);for(var n=0;n<L.length;n++)L[n]=C[n];return L},W.sign.detached=function(K,M){var C=W.sign(K,M),z=new Uint8Array(z1);for(var L=0;L<z.length;L++)z[L]=C[L];return z},W.sign.detached.verify=function(K,M,C){if(X5(K,M,C),M.length!==z1)throw Error("bad signature size");if(C.length!==o1)throw Error("bad public key size");var z=new Uint8Array(z1+K.length),L=new Uint8Array(z1+K.length),n;for(n=0;n<z1;n++)z[n]=M[n];for(n=0;n<K.length;n++)z[n+z1]=K[n];return N1(L,z,z.length,C)>=0},W.sign.keyPair=function(){var K=new Uint8Array(o1),M=new Uint8Array(Z8);return X0(K,M),{publicKey:K,secretKey:M}},W.sign.keyPair.fromSecretKey=function(K){if(X5(K),K.length!==Z8)throw Error("bad secret key size");var M=new Uint8Array(o1);for(var C=0;C<M.length;C++)M[C]=K[32+C];return{publicKey:M,secretKey:new Uint8Array(K)}},W.sign.keyPair.fromSeed=function(K){if(X5(K),K.length!==S9)throw Error("bad seed size");var M=new Uint8Array(o1),C=new Uint8Array(Z8);for(var z=0;z<32;z++)C[z]=K[z];return X0(M,C,!0),{publicKey:M,secretKey:C}},W.sign.publicKeyLength=o1,W.sign.secretKeyLength=Z8,W.sign.seedLength=S9,W.sign.signatureLength=z1,W.hash=function(K){X5(K);var M=new Uint8Array(lX);return Y0(M,K,K.length),M},W.hash.hashLength=lX,W.verify=function(K,M){if(X5(K,M),K.length===0||M.length===0)return!1;if(K.length!==M.length)return!1;return w(K,0,M,0,K.length)===0?!0:!1},W.setPRNG=function(K){G=K},function(){var K=typeof self<"u"?self.crypto||self.msCrypto:null;if(K&&K.getRandomValues){var M=65536;W.setPRNG(function(C,z){var L,n=new Uint8Array(z);for(L=0;L<z;L+=M)K.getRandomValues(n.subarray(L,L+Math.min(z-L,M)));for(L=0;L<z;L++)C[L]=n[L];ID(n)})}else if(K=_8("crypto"),K&&K.randomBytes)W.setPRNG(function(C,z){var L,n=K.randomBytes(z);for(L=0;L<z;L++)C[L]=n[L];ID(n)})}()})(typeof _Q<"u"&&Y00?Y00:self.nacl=self.nacl||{})});var Fz=V1((OM)=>{Object.defineProperty(OM,"__esModule",{value:!0});class KM{constructor(W,X=0,G=0){this.start=X,this.end=G>X?G:X,this.buf=W}get length(){return this.buf.length}reset(W=0,X=0){if(this.start=W,X>=this.start)this.end=X;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,X="Too few bytes to parse."){let G=this.end+W;if(G>this.buf.length){let Y=Error(X);throw Y.available=this.buf.length,Y.requested=G,Y}return this.walk(0),this}mustWalk(W,X){return this.mustHas(W,X),this.walk(W),this}}OM.BufferVisitor=KM});var MM=V1((TM)=>{Object.defineProperty(TM,"__esModule",{value:!0});var DM=_8("util"),CM=64,xz="-----BEGIN ",kz="-----END ",fJ="-----",Sz="Proc-Type";class _z{static parse(W){let X=[],G=W.toString("utf8").split(`
7
+ `).map((X)=>X.trim()).join(" ")};qM.O=function(W){return this.inspectOpts.colors=this.useColors,SQ.inspect(W,this.inspectOpts)}});var IM=V1((X00,$z)=>{if(typeof process>"u"||process.type==="renderer"||!1||process.__nwjs)$z.exports=NM();else $z.exports=zM()});var kQ=V1((jM)=>{Object.defineProperty(jM,"__esModule",{value:!0});var Eb=_8("net");function $b(W){switch(Eb.isIP(W)){case 4:return Buffer.from(W.split(".").map((J)=>parseInt(J,10)));case 6:let X=W.split(":"),G=Buffer.alloc(16),Y=0;if(X[X.length-1]==="")X[X.length-1]="0";for(let J=0;J<X.length;J++){if(X[J]===""){if(J+1<X.length&&X[J+1]!=="")Y=16-(X.length-J-1)*2;continue}G.writeUInt16BE(parseInt(X[J],16),Y),Y+=2}return G;default:return null}}jM.bytesFromIP=$b;function Fb(W){switch(W.length){case 4:return[W[0],W[1],W[2],W[3]].join(".");case 16:let X=[],G=-1,Y=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(Y++,G===-1)G=X.length;if(Y>Z)Z=Y,J=G}else G=-1,Y=0;X.push(U.toString(16))}if(Z>0){let V="",U=X.slice(J+Z);if(X.length=J,X.length===0)V+=":";if(U.length===0)V+=":";X.push(V,...U)}return X.join(":");default:return""}}jM.bytesToIP=Fb;var I6=Object.create(null),wM=/^[0-9.]+$/;function Sb(W){if(wM.test(W)&&I6[W]!=="")return W;return I6[W]==null?"":I6[W]}jM.getOID=Sb;function xb(W){if(!wM.test(W)&&I6[W]!=="")return W;return I6[W]==null?W:I6[W]}jM.getOIDName=xb;function w0(W,X){I6[W]=X,I6[X]=W}w0("1.2.840.113549.1.1.1","rsaEncryption");w0("1.2.840.113549.1.1.4","md5WithRsaEncryption");w0("1.2.840.113549.1.1.5","sha1WithRsaEncryption");w0("1.2.840.113549.1.1.8","mgf1");w0("1.2.840.113549.1.1.10","RSASSA-PSS");w0("1.2.840.113549.1.1.11","sha256WithRsaEncryption");w0("1.2.840.113549.1.1.12","sha384WithRsaEncryption");w0("1.2.840.113549.1.1.13","sha512WithRsaEncryption");w0("1.2.840.10045.2.1","ecEncryption");w0("1.2.840.10045.4.1","ecdsaWithSha1");w0("1.2.840.10045.4.3.2","ecdsaWithSha256");w0("1.2.840.10045.4.3.3","ecdsaWithSha384");w0("1.2.840.10045.4.3.4","ecdsaWithSha512");w0("1.2.840.10040.4.3","dsaWithSha1");w0("2.16.840.1.101.3.4.3.2","dsaWithSha256");w0("1.3.14.3.2.7","desCBC");w0("1.3.14.3.2.26","sha1");w0("2.16.840.1.101.3.4.2.1","sha256");w0("2.16.840.1.101.3.4.2.2","sha384");w0("2.16.840.1.101.3.4.2.3","sha512");w0("1.2.840.113549.2.5","md5");w0("1.3.101.110","X25519");w0("1.3.101.111","X448");w0("1.3.101.112","Ed25519");w0("1.3.101.113","Ed448");w0("1.2.840.113549.1.7.1","data");w0("1.2.840.113549.1.7.2","signedData");w0("1.2.840.113549.1.7.3","envelopedData");w0("1.2.840.113549.1.7.4","signedAndEnvelopedData");w0("1.2.840.113549.1.7.5","digestedData");w0("1.2.840.113549.1.7.6","encryptedData");w0("1.2.840.113549.1.9.1","emailAddress");w0("1.2.840.113549.1.9.2","unstructuredName");w0("1.2.840.113549.1.9.3","contentType");w0("1.2.840.113549.1.9.4","messageDigest");w0("1.2.840.113549.1.9.5","signingTime");w0("1.2.840.113549.1.9.6","counterSignature");w0("1.2.840.113549.1.9.7","challengePassword");w0("1.2.840.113549.1.9.8","unstructuredAddress");w0("1.2.840.113549.1.9.14","extensionRequest");w0("1.2.840.113549.1.9.20","friendlyName");w0("1.2.840.113549.1.9.21","localKeyId");w0("1.2.840.113549.1.9.22.1","x509Certificate");w0("1.2.840.113549.1.12.10.1.1","keyBag");w0("1.2.840.113549.1.12.10.1.2","pkcs8ShroudedKeyBag");w0("1.2.840.113549.1.12.10.1.3","certBag");w0("1.2.840.113549.1.12.10.1.4","crlBag");w0("1.2.840.113549.1.12.10.1.5","secretBag");w0("1.2.840.113549.1.12.10.1.6","safeContentsBag");w0("1.2.840.113549.1.5.13","pkcs5PBES2");w0("1.2.840.113549.1.5.12","pkcs5PBKDF2");w0("1.2.840.113549.2.7","hmacWithSha1");w0("1.2.840.113549.2.9","hmacWithSha256");w0("1.2.840.113549.2.10","hmacWithSha384");w0("1.2.840.113549.2.11","hmacWithSha512");w0("1.2.840.113549.3.7","3desCBC");w0("2.16.840.1.101.3.4.1.2","aesCBC128");w0("2.16.840.1.101.3.4.1.42","aesCBC256");w0("2.5.4.3","commonName");w0("2.5.4.5","serialName");w0("2.5.4.6","countryName");w0("2.5.4.7","localityName");w0("2.5.4.8","stateOrProvinceName");w0("2.5.4.10","organizationName");w0("2.5.4.11","organizationalUnitName");w0("2.5.4.15","businessCategory");w0("2.16.840.1.113730.1.1","nsCertType");w0("2.5.29.2","keyAttributes");w0("2.5.29.4","keyUsageRestriction");w0("2.5.29.6","subtreesConstraint");w0("2.5.29.9","subjectDirectoryAttributes");w0("2.5.29.14","subjectKeyIdentifier");w0("2.5.29.15","keyUsage");w0("2.5.29.16","privateKeyUsagePeriod");w0("2.5.29.17","subjectAltName");w0("2.5.29.18","issuerAltName");w0("2.5.29.19","basicConstraints");w0("2.5.29.20","cRLNumber");w0("2.5.29.21","cRLReason");w0("2.5.29.22","expirationDate");w0("2.5.29.23","instructionCode");w0("2.5.29.24","invalidityDate");w0("2.5.29.27","deltaCRLIndicator");w0("2.5.29.28","issuingDistributionPoint");w0("2.5.29.29","certificateIssuer");w0("2.5.29.30","nameConstraints");w0("2.5.29.31","cRLDistributionPoints");w0("2.5.29.32","certificatePolicies");w0("2.5.29.33","policyMappings");w0("2.5.29.35","authorityKeyIdentifier");w0("2.5.29.36","policyConstraints");w0("2.5.29.37","extKeyUsage");w0("2.5.29.46","freshestCRL");w0("2.5.29.54","inhibitAnyPolicy");w0("1.3.6.1.4.1.311.60.2.1.2","jurisdictionST");w0("1.3.6.1.4.1.311.60.2.1.3","jurisdictionC");w0("1.3.6.1.4.1.11129.2.4.2","timestampList");w0("1.3.6.1.5.5.7.1.1","authorityInfoAccess");w0("1.3.6.1.5.5.7.3.1","serverAuth");w0("1.3.6.1.5.5.7.3.2","clientAuth");w0("1.3.6.1.5.5.7.3.3","codeSigning");w0("1.3.6.1.5.5.7.3.4","emailProtection");w0("1.3.6.1.5.5.7.3.8","timeStamping");w0("1.3.6.1.5.5.7.48.1","authorityInfoAccessOcsp");w0("1.3.6.1.5.5.7.48.2","authorityInfoAccessIssuers")});var yQ=V1((Y00,_Q)=>{(function(W){var X=function(K){var M,C=new Float64Array(16);if(K)for(M=0;M<K.length;M++)C[M]=K[M];return C},G=function(){throw Error("no PRNG")},Y=new Uint8Array(16),J=new Uint8Array(32);J[0]=9;var Z=X(),V=X([1]),U=X([56129,1]),Q=X([30883,4953,19914,30187,55467,16705,2637,112,59544,30585,16505,36039,65139,11119,27886,20995]),N=X([61785,9906,39828,60374,45398,33411,5274,224,53552,61171,33010,6542,64743,22239,55772,9222]),q=X([54554,36645,11616,51542,42930,38181,51040,26924,56412,64982,57905,49316,21502,52590,14035,8553]),A=X([26200,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214]),H=X([41136,18958,6951,50414,58488,44335,6150,12099,55207,15867,153,11085,57099,20417,9344,11139]);function I(K,M,C,z){K[M]=C>>24&255,K[M+1]=C>>16&255,K[M+2]=C>>8&255,K[M+3]=C&255,K[M+4]=z>>24&255,K[M+5]=z>>16&255,K[M+6]=z>>8&255,K[M+7]=z&255}function w(K,M,C,z,L){var n,e=0;for(n=0;n<L;n++)e|=K[M+n]^C[z+n];return(1&e-1>>>8)-1}function O(K,M,C,z){return w(K,M,C,z,16)}function T(K,M,C,z){return w(K,M,C,z,32)}function x(K,M,C,z){var L=z[0]&255|(z[1]&255)<<8|(z[2]&255)<<16|(z[3]&255)<<24,n=C[0]&255|(C[1]&255)<<8|(C[2]&255)<<16|(C[3]&255)<<24,e=C[4]&255|(C[5]&255)<<8|(C[6]&255)<<16|(C[7]&255)<<24,z0=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=z[4]&255|(z[5]&255)<<8|(z[6]&255)<<16|(z[7]&255)<<24,b0=M[0]&255|(M[1]&255)<<8|(M[2]&255)<<16|(M[3]&255)<<24,n1=M[4]&255|(M[5]&255)<<8|(M[6]&255)<<16|(M[7]&255)<<24,l0=M[8]&255|(M[9]&255)<<8|(M[10]&255)<<16|(M[11]&255)<<24,A1=M[12]&255|(M[13]&255)<<8|(M[14]&255)<<16|(M[15]&255)<<24,I1=z[8]&255|(z[9]&255)<<8|(z[10]&255)<<16|(z[11]&255)<<24,L1=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,w1=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,j1=z[12]&255|(z[13]&255)<<8|(z[14]&255)<<16|(z[15]&255)<<24,n0=L,X1=n,f0=e,r0=z0,s0=R0,v0=t0,Z0=b0,V0=n1,j0=l0,A0=A1,I0=I1,D0=L1,q1=T1,B1=w1,$1=O1,E1=j1,b;for(var _1=0;_1<20;_1+=2)b=n0+q1|0,s0^=b<<7|b>>>25,b=s0+n0|0,j0^=b<<9|b>>>23,b=j0+s0|0,q1^=b<<13|b>>>19,b=q1+j0|0,n0^=b<<18|b>>>14,b=v0+X1|0,A0^=b<<7|b>>>25,b=A0+v0|0,B1^=b<<9|b>>>23,b=B1+A0|0,X1^=b<<13|b>>>19,b=X1+B1|0,v0^=b<<18|b>>>14,b=I0+Z0|0,$1^=b<<7|b>>>25,b=$1+I0|0,f0^=b<<9|b>>>23,b=f0+$1|0,Z0^=b<<13|b>>>19,b=Z0+f0|0,I0^=b<<18|b>>>14,b=E1+D0|0,r0^=b<<7|b>>>25,b=r0+E1|0,V0^=b<<9|b>>>23,b=V0+r0|0,D0^=b<<13|b>>>19,b=D0+V0|0,E1^=b<<18|b>>>14,b=n0+r0|0,X1^=b<<7|b>>>25,b=X1+n0|0,f0^=b<<9|b>>>23,b=f0+X1|0,r0^=b<<13|b>>>19,b=r0+f0|0,n0^=b<<18|b>>>14,b=v0+s0|0,Z0^=b<<7|b>>>25,b=Z0+v0|0,V0^=b<<9|b>>>23,b=V0+Z0|0,s0^=b<<13|b>>>19,b=s0+V0|0,v0^=b<<18|b>>>14,b=I0+A0|0,D0^=b<<7|b>>>25,b=D0+I0|0,j0^=b<<9|b>>>23,b=j0+D0|0,A0^=b<<13|b>>>19,b=A0+j0|0,I0^=b<<18|b>>>14,b=E1+$1|0,q1^=b<<7|b>>>25,b=q1+E1|0,B1^=b<<9|b>>>23,b=B1+q1|0,$1^=b<<13|b>>>19,b=$1+B1|0,E1^=b<<18|b>>>14;n0=n0+L|0,X1=X1+n|0,f0=f0+e|0,r0=r0+z0|0,s0=s0+R0|0,v0=v0+t0|0,Z0=Z0+b0|0,V0=V0+n1|0,j0=j0+l0|0,A0=A0+A1|0,I0=I0+I1|0,D0=D0+L1|0,q1=q1+T1|0,B1=B1+w1|0,$1=$1+O1|0,E1=E1+j1|0,K[0]=n0>>>0&255,K[1]=n0>>>8&255,K[2]=n0>>>16&255,K[3]=n0>>>24&255,K[4]=X1>>>0&255,K[5]=X1>>>8&255,K[6]=X1>>>16&255,K[7]=X1>>>24&255,K[8]=f0>>>0&255,K[9]=f0>>>8&255,K[10]=f0>>>16&255,K[11]=f0>>>24&255,K[12]=r0>>>0&255,K[13]=r0>>>8&255,K[14]=r0>>>16&255,K[15]=r0>>>24&255,K[16]=s0>>>0&255,K[17]=s0>>>8&255,K[18]=s0>>>16&255,K[19]=s0>>>24&255,K[20]=v0>>>0&255,K[21]=v0>>>8&255,K[22]=v0>>>16&255,K[23]=v0>>>24&255,K[24]=Z0>>>0&255,K[25]=Z0>>>8&255,K[26]=Z0>>>16&255,K[27]=Z0>>>24&255,K[28]=V0>>>0&255,K[29]=V0>>>8&255,K[30]=V0>>>16&255,K[31]=V0>>>24&255,K[32]=j0>>>0&255,K[33]=j0>>>8&255,K[34]=j0>>>16&255,K[35]=j0>>>24&255,K[36]=A0>>>0&255,K[37]=A0>>>8&255,K[38]=A0>>>16&255,K[39]=A0>>>24&255,K[40]=I0>>>0&255,K[41]=I0>>>8&255,K[42]=I0>>>16&255,K[43]=I0>>>24&255,K[44]=D0>>>0&255,K[45]=D0>>>8&255,K[46]=D0>>>16&255,K[47]=D0>>>24&255,K[48]=q1>>>0&255,K[49]=q1>>>8&255,K[50]=q1>>>16&255,K[51]=q1>>>24&255,K[52]=B1>>>0&255,K[53]=B1>>>8&255,K[54]=B1>>>16&255,K[55]=B1>>>24&255,K[56]=$1>>>0&255,K[57]=$1>>>8&255,K[58]=$1>>>16&255,K[59]=$1>>>24&255,K[60]=E1>>>0&255,K[61]=E1>>>8&255,K[62]=E1>>>16&255,K[63]=E1>>>24&255}function h(K,M,C,z){var L=z[0]&255|(z[1]&255)<<8|(z[2]&255)<<16|(z[3]&255)<<24,n=C[0]&255|(C[1]&255)<<8|(C[2]&255)<<16|(C[3]&255)<<24,e=C[4]&255|(C[5]&255)<<8|(C[6]&255)<<16|(C[7]&255)<<24,z0=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=z[4]&255|(z[5]&255)<<8|(z[6]&255)<<16|(z[7]&255)<<24,b0=M[0]&255|(M[1]&255)<<8|(M[2]&255)<<16|(M[3]&255)<<24,n1=M[4]&255|(M[5]&255)<<8|(M[6]&255)<<16|(M[7]&255)<<24,l0=M[8]&255|(M[9]&255)<<8|(M[10]&255)<<16|(M[11]&255)<<24,A1=M[12]&255|(M[13]&255)<<8|(M[14]&255)<<16|(M[15]&255)<<24,I1=z[8]&255|(z[9]&255)<<8|(z[10]&255)<<16|(z[11]&255)<<24,L1=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,w1=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,j1=z[12]&255|(z[13]&255)<<8|(z[14]&255)<<16|(z[15]&255)<<24,n0=L,X1=n,f0=e,r0=z0,s0=R0,v0=t0,Z0=b0,V0=n1,j0=l0,A0=A1,I0=I1,D0=L1,q1=T1,B1=w1,$1=O1,E1=j1,b;for(var _1=0;_1<20;_1+=2)b=n0+q1|0,s0^=b<<7|b>>>25,b=s0+n0|0,j0^=b<<9|b>>>23,b=j0+s0|0,q1^=b<<13|b>>>19,b=q1+j0|0,n0^=b<<18|b>>>14,b=v0+X1|0,A0^=b<<7|b>>>25,b=A0+v0|0,B1^=b<<9|b>>>23,b=B1+A0|0,X1^=b<<13|b>>>19,b=X1+B1|0,v0^=b<<18|b>>>14,b=I0+Z0|0,$1^=b<<7|b>>>25,b=$1+I0|0,f0^=b<<9|b>>>23,b=f0+$1|0,Z0^=b<<13|b>>>19,b=Z0+f0|0,I0^=b<<18|b>>>14,b=E1+D0|0,r0^=b<<7|b>>>25,b=r0+E1|0,V0^=b<<9|b>>>23,b=V0+r0|0,D0^=b<<13|b>>>19,b=D0+V0|0,E1^=b<<18|b>>>14,b=n0+r0|0,X1^=b<<7|b>>>25,b=X1+n0|0,f0^=b<<9|b>>>23,b=f0+X1|0,r0^=b<<13|b>>>19,b=r0+f0|0,n0^=b<<18|b>>>14,b=v0+s0|0,Z0^=b<<7|b>>>25,b=Z0+v0|0,V0^=b<<9|b>>>23,b=V0+Z0|0,s0^=b<<13|b>>>19,b=s0+V0|0,v0^=b<<18|b>>>14,b=I0+A0|0,D0^=b<<7|b>>>25,b=D0+I0|0,j0^=b<<9|b>>>23,b=j0+D0|0,A0^=b<<13|b>>>19,b=A0+j0|0,I0^=b<<18|b>>>14,b=E1+$1|0,q1^=b<<7|b>>>25,b=q1+E1|0,B1^=b<<9|b>>>23,b=B1+q1|0,$1^=b<<13|b>>>19,b=$1+B1|0,E1^=b<<18|b>>>14;K[0]=n0>>>0&255,K[1]=n0>>>8&255,K[2]=n0>>>16&255,K[3]=n0>>>24&255,K[4]=v0>>>0&255,K[5]=v0>>>8&255,K[6]=v0>>>16&255,K[7]=v0>>>24&255,K[8]=I0>>>0&255,K[9]=I0>>>8&255,K[10]=I0>>>16&255,K[11]=I0>>>24&255,K[12]=E1>>>0&255,K[13]=E1>>>8&255,K[14]=E1>>>16&255,K[15]=E1>>>24&255,K[16]=Z0>>>0&255,K[17]=Z0>>>8&255,K[18]=Z0>>>16&255,K[19]=Z0>>>24&255,K[20]=V0>>>0&255,K[21]=V0>>>8&255,K[22]=V0>>>16&255,K[23]=V0>>>24&255,K[24]=j0>>>0&255,K[25]=j0>>>8&255,K[26]=j0>>>16&255,K[27]=j0>>>24&255,K[28]=A0>>>0&255,K[29]=A0>>>8&255,K[30]=A0>>>16&255,K[31]=A0>>>24&255}function $(K,M,C,z){x(K,M,C,z)}function F(K,M,C,z){h(K,M,C,z)}var u=new Uint8Array([101,120,112,97,110,100,32,51,50,45,98,121,116,101,32,107]);function l(K,M,C,z,L,n,e){var z0=new Uint8Array(16),R0=new Uint8Array(64),t0,b0;for(b0=0;b0<16;b0++)z0[b0]=0;for(b0=0;b0<8;b0++)z0[b0]=n[b0];while(L>=64){$(R0,z0,e,u);for(b0=0;b0<64;b0++)K[M+b0]=C[z+b0]^R0[b0];t0=1;for(b0=8;b0<16;b0++)t0=t0+(z0[b0]&255)|0,z0[b0]=t0&255,t0>>>=8;L-=64,M+=64,z+=64}if(L>0){$(R0,z0,e,u);for(b0=0;b0<L;b0++)K[M+b0]=C[z+b0]^R0[b0]}return 0}function f(K,M,C,z,L){var n=new Uint8Array(16),e=new Uint8Array(64),z0,R0;for(R0=0;R0<16;R0++)n[R0]=0;for(R0=0;R0<8;R0++)n[R0]=z[R0];while(C>=64){$(e,n,L,u);for(R0=0;R0<64;R0++)K[M+R0]=e[R0];z0=1;for(R0=8;R0<16;R0++)z0=z0+(n[R0]&255)|0,n[R0]=z0&255,z0>>>=8;C-=64,M+=64}if(C>0){$(e,n,L,u);for(R0=0;R0<C;R0++)K[M+R0]=e[R0]}return 0}function s(K,M,C,z,L){var n=new Uint8Array(32);F(n,z,L,u);var e=new Uint8Array(8);for(var z0=0;z0<8;z0++)e[z0]=z[z0+16];return f(K,M,C,e,n)}function y(K,M,C,z,L,n,e){var z0=new Uint8Array(32);F(z0,n,e,u);var R0=new Uint8Array(8);for(var t0=0;t0<8;t0++)R0[t0]=n[t0+16];return l(K,M,C,z,L,R0,z0)}var t=function(K){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 M,C,z,L,n,e,z0,R0;M=K[0]&255|(K[1]&255)<<8,this.r[0]=M&8191,C=K[2]&255|(K[3]&255)<<8,this.r[1]=(M>>>13|C<<3)&8191,z=K[4]&255|(K[5]&255)<<8,this.r[2]=(C>>>10|z<<6)&7939,L=K[6]&255|(K[7]&255)<<8,this.r[3]=(z>>>7|L<<9)&8191,n=K[8]&255|(K[9]&255)<<8,this.r[4]=(L>>>4|n<<12)&255,this.r[5]=n>>>1&8190,e=K[10]&255|(K[11]&255)<<8,this.r[6]=(n>>>14|e<<2)&8191,z0=K[12]&255|(K[13]&255)<<8,this.r[7]=(e>>>11|z0<<5)&8065,R0=K[14]&255|(K[15]&255)<<8,this.r[8]=(z0>>>8|R0<<8)&8191,this.r[9]=R0>>>5&127,this.pad[0]=K[16]&255|(K[17]&255)<<8,this.pad[1]=K[18]&255|(K[19]&255)<<8,this.pad[2]=K[20]&255|(K[21]&255)<<8,this.pad[3]=K[22]&255|(K[23]&255)<<8,this.pad[4]=K[24]&255|(K[25]&255)<<8,this.pad[5]=K[26]&255|(K[27]&255)<<8,this.pad[6]=K[28]&255|(K[29]&255)<<8,this.pad[7]=K[30]&255|(K[31]&255)<<8};t.prototype.blocks=function(K,M,C){var z=this.fin?0:2048,L,n,e,z0,R0,t0,b0,n1,l0,A1,I1,L1,T1,w1,O1,j1,n0,X1,f0,r0=this.h[0],s0=this.h[1],v0=this.h[2],Z0=this.h[3],V0=this.h[4],j0=this.h[5],A0=this.h[6],I0=this.h[7],D0=this.h[8],q1=this.h[9],B1=this.r[0],$1=this.r[1],E1=this.r[2],b=this.r[3],_1=this.r[4],i1=this.r[5],r1=this.r[6],x1=this.r[7],c1=this.r[8],l1=this.r[9];while(C>=16)L=K[M+0]&255|(K[M+1]&255)<<8,r0+=L&8191,n=K[M+2]&255|(K[M+3]&255)<<8,s0+=(L>>>13|n<<3)&8191,e=K[M+4]&255|(K[M+5]&255)<<8,v0+=(n>>>10|e<<6)&8191,z0=K[M+6]&255|(K[M+7]&255)<<8,Z0+=(e>>>7|z0<<9)&8191,R0=K[M+8]&255|(K[M+9]&255)<<8,V0+=(z0>>>4|R0<<12)&8191,j0+=R0>>>1&8191,t0=K[M+10]&255|(K[M+11]&255)<<8,A0+=(R0>>>14|t0<<2)&8191,b0=K[M+12]&255|(K[M+13]&255)<<8,I0+=(t0>>>11|b0<<5)&8191,n1=K[M+14]&255|(K[M+15]&255)<<8,D0+=(b0>>>8|n1<<8)&8191,q1+=n1>>>5|z,l0=0,A1=l0,A1+=r0*B1,A1+=s0*(5*l1),A1+=v0*(5*c1),A1+=Z0*(5*x1),A1+=V0*(5*r1),l0=A1>>>13,A1&=8191,A1+=j0*(5*i1),A1+=A0*(5*_1),A1+=I0*(5*b),A1+=D0*(5*E1),A1+=q1*(5*$1),l0+=A1>>>13,A1&=8191,I1=l0,I1+=r0*$1,I1+=s0*B1,I1+=v0*(5*l1),I1+=Z0*(5*c1),I1+=V0*(5*x1),l0=I1>>>13,I1&=8191,I1+=j0*(5*r1),I1+=A0*(5*i1),I1+=I0*(5*_1),I1+=D0*(5*b),I1+=q1*(5*E1),l0+=I1>>>13,I1&=8191,L1=l0,L1+=r0*E1,L1+=s0*$1,L1+=v0*B1,L1+=Z0*(5*l1),L1+=V0*(5*c1),l0=L1>>>13,L1&=8191,L1+=j0*(5*x1),L1+=A0*(5*r1),L1+=I0*(5*i1),L1+=D0*(5*_1),L1+=q1*(5*b),l0+=L1>>>13,L1&=8191,T1=l0,T1+=r0*b,T1+=s0*E1,T1+=v0*$1,T1+=Z0*B1,T1+=V0*(5*l1),l0=T1>>>13,T1&=8191,T1+=j0*(5*c1),T1+=A0*(5*x1),T1+=I0*(5*r1),T1+=D0*(5*i1),T1+=q1*(5*_1),l0+=T1>>>13,T1&=8191,w1=l0,w1+=r0*_1,w1+=s0*b,w1+=v0*E1,w1+=Z0*$1,w1+=V0*B1,l0=w1>>>13,w1&=8191,w1+=j0*(5*l1),w1+=A0*(5*c1),w1+=I0*(5*x1),w1+=D0*(5*r1),w1+=q1*(5*i1),l0+=w1>>>13,w1&=8191,O1=l0,O1+=r0*i1,O1+=s0*_1,O1+=v0*b,O1+=Z0*E1,O1+=V0*$1,l0=O1>>>13,O1&=8191,O1+=j0*B1,O1+=A0*(5*l1),O1+=I0*(5*c1),O1+=D0*(5*x1),O1+=q1*(5*r1),l0+=O1>>>13,O1&=8191,j1=l0,j1+=r0*r1,j1+=s0*i1,j1+=v0*_1,j1+=Z0*b,j1+=V0*E1,l0=j1>>>13,j1&=8191,j1+=j0*$1,j1+=A0*B1,j1+=I0*(5*l1),j1+=D0*(5*c1),j1+=q1*(5*x1),l0+=j1>>>13,j1&=8191,n0=l0,n0+=r0*x1,n0+=s0*r1,n0+=v0*i1,n0+=Z0*_1,n0+=V0*b,l0=n0>>>13,n0&=8191,n0+=j0*E1,n0+=A0*$1,n0+=I0*B1,n0+=D0*(5*l1),n0+=q1*(5*c1),l0+=n0>>>13,n0&=8191,X1=l0,X1+=r0*c1,X1+=s0*x1,X1+=v0*r1,X1+=Z0*i1,X1+=V0*_1,l0=X1>>>13,X1&=8191,X1+=j0*b,X1+=A0*E1,X1+=I0*$1,X1+=D0*B1,X1+=q1*(5*l1),l0+=X1>>>13,X1&=8191,f0=l0,f0+=r0*l1,f0+=s0*c1,f0+=v0*x1,f0+=Z0*r1,f0+=V0*i1,l0=f0>>>13,f0&=8191,f0+=j0*_1,f0+=A0*b,f0+=I0*E1,f0+=D0*$1,f0+=q1*B1,l0+=f0>>>13,f0&=8191,l0=(l0<<2)+l0|0,l0=l0+A1|0,A1=l0&8191,l0=l0>>>13,I1+=l0,r0=A1,s0=I1,v0=L1,Z0=T1,V0=w1,j0=O1,A0=j1,I0=n0,D0=X1,q1=f0,M+=16,C-=16;this.h[0]=r0,this.h[1]=s0,this.h[2]=v0,this.h[3]=Z0,this.h[4]=V0,this.h[5]=j0,this.h[6]=A0,this.h[7]=I0,this.h[8]=D0,this.h[9]=q1},t.prototype.finish=function(K,M){var C=new Uint16Array(10),z,L,n,e;if(this.leftover){e=this.leftover,this.buffer[e++]=1;for(;e<16;e++)this.buffer[e]=0;this.fin=1,this.blocks(this.buffer,0,16)}z=this.h[1]>>>13,this.h[1]&=8191;for(e=2;e<10;e++)this.h[e]+=z,z=this.h[e]>>>13,this.h[e]&=8191;this.h[0]+=z*5,z=this.h[0]>>>13,this.h[0]&=8191,this.h[1]+=z,z=this.h[1]>>>13,this.h[1]&=8191,this.h[2]+=z,C[0]=this.h[0]+5,z=C[0]>>>13,C[0]&=8191;for(e=1;e<10;e++)C[e]=this.h[e]+z,z=C[e]>>>13,C[e]&=8191;C[9]-=8192,L=(z^1)-1;for(e=0;e<10;e++)C[e]&=L;L=~L;for(e=0;e<10;e++)this.h[e]=this.h[e]&L|C[e];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,n=this.h[0]+this.pad[0],this.h[0]=n&65535;for(e=1;e<8;e++)n=(this.h[e]+this.pad[e]|0)+(n>>>16)|0,this.h[e]=n&65535;K[M+0]=this.h[0]>>>0&255,K[M+1]=this.h[0]>>>8&255,K[M+2]=this.h[1]>>>0&255,K[M+3]=this.h[1]>>>8&255,K[M+4]=this.h[2]>>>0&255,K[M+5]=this.h[2]>>>8&255,K[M+6]=this.h[3]>>>0&255,K[M+7]=this.h[3]>>>8&255,K[M+8]=this.h[4]>>>0&255,K[M+9]=this.h[4]>>>8&255,K[M+10]=this.h[5]>>>0&255,K[M+11]=this.h[5]>>>8&255,K[M+12]=this.h[6]>>>0&255,K[M+13]=this.h[6]>>>8&255,K[M+14]=this.h[7]>>>0&255,K[M+15]=this.h[7]>>>8&255},t.prototype.update=function(K,M,C){var z,L;if(this.leftover){if(L=16-this.leftover,L>C)L=C;for(z=0;z<L;z++)this.buffer[this.leftover+z]=K[M+z];if(C-=L,M+=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(K,M,L),M+=L,C-=L;if(C){for(z=0;z<C;z++)this.buffer[this.leftover+z]=K[M+z];this.leftover+=C}};function H0(K,M,C,z,L,n){var e=new t(n);return e.update(C,z,L),e.finish(K,M),0}function g(K,M,C,z,L,n){var e=new Uint8Array(16);return H0(e,0,C,z,L,n),O(K,M,e,0)}function d(K,M,C,z,L){var n;if(C<32)return-1;y(K,0,M,0,C,z,L),H0(K,16,K,32,C-32,K);for(n=0;n<16;n++)K[n]=0;return 0}function P(K,M,C,z,L){var n,e=new Uint8Array(32);if(C<32)return-1;if(s(e,0,32,z,L),g(M,16,M,32,C-32,e)!==0)return-1;y(K,0,M,0,C,z,L);for(n=0;n<32;n++)K[n]=0;return 0}function E(K,M){var C;for(C=0;C<16;C++)K[C]=M[C]|0}function p(K){var M,C,z=1;for(M=0;M<16;M++)C=K[M]+z+65535,z=Math.floor(C/65536),K[M]=C-z*65536;K[0]+=z-1+37*(z-1)}function r(K,M,C){var z,L=~(C-1);for(var n=0;n<16;n++)z=L&(K[n]^M[n]),K[n]^=z,M[n]^=z}function o(K,M){var C,z,L,n=X(),e=X();for(C=0;C<16;C++)e[C]=M[C];p(e),p(e),p(e);for(z=0;z<2;z++){n[0]=e[0]-65517;for(C=1;C<15;C++)n[C]=e[C]-65535-(n[C-1]>>16&1),n[C-1]&=65535;n[15]=e[15]-32767-(n[14]>>16&1),L=n[15]>>16&1,n[14]&=65535,r(e,n,1-L)}for(C=0;C<16;C++)K[2*C]=e[C]&255,K[2*C+1]=e[C]>>8}function B(K,M){var C=new Uint8Array(32),z=new Uint8Array(32);return o(C,K),o(z,M),T(C,0,z,0)}function S(K){var M=new Uint8Array(32);return o(M,K),M[0]&1}function _(K,M){var C;for(C=0;C<16;C++)K[C]=M[2*C]+(M[2*C+1]<<8);K[15]&=32767}function v(K,M,C){for(var z=0;z<16;z++)K[z]=M[z]+C[z]}function R(K,M,C){for(var z=0;z<16;z++)K[z]=M[z]-C[z]}function m(K,M,C){var z,L,n=0,e=0,z0=0,R0=0,t0=0,b0=0,n1=0,l0=0,A1=0,I1=0,L1=0,T1=0,w1=0,O1=0,j1=0,n0=0,X1=0,f0=0,r0=0,s0=0,v0=0,Z0=0,V0=0,j0=0,A0=0,I0=0,D0=0,q1=0,B1=0,$1=0,E1=0,b=C[0],_1=C[1],i1=C[2],r1=C[3],x1=C[4],c1=C[5],l1=C[6],k8=C[7],Y8=C[8],P8=C[9],R8=C[10],L8=C[11],m8=C[12],H9=C[13],A9=C[14],z9=C[15];z=M[0],n+=z*b,e+=z*_1,z0+=z*i1,R0+=z*r1,t0+=z*x1,b0+=z*c1,n1+=z*l1,l0+=z*k8,A1+=z*Y8,I1+=z*P8,L1+=z*R8,T1+=z*L8,w1+=z*m8,O1+=z*H9,j1+=z*A9,n0+=z*z9,z=M[1],e+=z*b,z0+=z*_1,R0+=z*i1,t0+=z*r1,b0+=z*x1,n1+=z*c1,l0+=z*l1,A1+=z*k8,I1+=z*Y8,L1+=z*P8,T1+=z*R8,w1+=z*L8,O1+=z*m8,j1+=z*H9,n0+=z*A9,X1+=z*z9,z=M[2],z0+=z*b,R0+=z*_1,t0+=z*i1,b0+=z*r1,n1+=z*x1,l0+=z*c1,A1+=z*l1,I1+=z*k8,L1+=z*Y8,T1+=z*P8,w1+=z*R8,O1+=z*L8,j1+=z*m8,n0+=z*H9,X1+=z*A9,f0+=z*z9,z=M[3],R0+=z*b,t0+=z*_1,b0+=z*i1,n1+=z*r1,l0+=z*x1,A1+=z*c1,I1+=z*l1,L1+=z*k8,T1+=z*Y8,w1+=z*P8,O1+=z*R8,j1+=z*L8,n0+=z*m8,X1+=z*H9,f0+=z*A9,r0+=z*z9,z=M[4],t0+=z*b,b0+=z*_1,n1+=z*i1,l0+=z*r1,A1+=z*x1,I1+=z*c1,L1+=z*l1,T1+=z*k8,w1+=z*Y8,O1+=z*P8,j1+=z*R8,n0+=z*L8,X1+=z*m8,f0+=z*H9,r0+=z*A9,s0+=z*z9,z=M[5],b0+=z*b,n1+=z*_1,l0+=z*i1,A1+=z*r1,I1+=z*x1,L1+=z*c1,T1+=z*l1,w1+=z*k8,O1+=z*Y8,j1+=z*P8,n0+=z*R8,X1+=z*L8,f0+=z*m8,r0+=z*H9,s0+=z*A9,v0+=z*z9,z=M[6],n1+=z*b,l0+=z*_1,A1+=z*i1,I1+=z*r1,L1+=z*x1,T1+=z*c1,w1+=z*l1,O1+=z*k8,j1+=z*Y8,n0+=z*P8,X1+=z*R8,f0+=z*L8,r0+=z*m8,s0+=z*H9,v0+=z*A9,Z0+=z*z9,z=M[7],l0+=z*b,A1+=z*_1,I1+=z*i1,L1+=z*r1,T1+=z*x1,w1+=z*c1,O1+=z*l1,j1+=z*k8,n0+=z*Y8,X1+=z*P8,f0+=z*R8,r0+=z*L8,s0+=z*m8,v0+=z*H9,Z0+=z*A9,V0+=z*z9,z=M[8],A1+=z*b,I1+=z*_1,L1+=z*i1,T1+=z*r1,w1+=z*x1,O1+=z*c1,j1+=z*l1,n0+=z*k8,X1+=z*Y8,f0+=z*P8,r0+=z*R8,s0+=z*L8,v0+=z*m8,Z0+=z*H9,V0+=z*A9,j0+=z*z9,z=M[9],I1+=z*b,L1+=z*_1,T1+=z*i1,w1+=z*r1,O1+=z*x1,j1+=z*c1,n0+=z*l1,X1+=z*k8,f0+=z*Y8,r0+=z*P8,s0+=z*R8,v0+=z*L8,Z0+=z*m8,V0+=z*H9,j0+=z*A9,A0+=z*z9,z=M[10],L1+=z*b,T1+=z*_1,w1+=z*i1,O1+=z*r1,j1+=z*x1,n0+=z*c1,X1+=z*l1,f0+=z*k8,r0+=z*Y8,s0+=z*P8,v0+=z*R8,Z0+=z*L8,V0+=z*m8,j0+=z*H9,A0+=z*A9,I0+=z*z9,z=M[11],T1+=z*b,w1+=z*_1,O1+=z*i1,j1+=z*r1,n0+=z*x1,X1+=z*c1,f0+=z*l1,r0+=z*k8,s0+=z*Y8,v0+=z*P8,Z0+=z*R8,V0+=z*L8,j0+=z*m8,A0+=z*H9,I0+=z*A9,D0+=z*z9,z=M[12],w1+=z*b,O1+=z*_1,j1+=z*i1,n0+=z*r1,X1+=z*x1,f0+=z*c1,r0+=z*l1,s0+=z*k8,v0+=z*Y8,Z0+=z*P8,V0+=z*R8,j0+=z*L8,A0+=z*m8,I0+=z*H9,D0+=z*A9,q1+=z*z9,z=M[13],O1+=z*b,j1+=z*_1,n0+=z*i1,X1+=z*r1,f0+=z*x1,r0+=z*c1,s0+=z*l1,v0+=z*k8,Z0+=z*Y8,V0+=z*P8,j0+=z*R8,A0+=z*L8,I0+=z*m8,D0+=z*H9,q1+=z*A9,B1+=z*z9,z=M[14],j1+=z*b,n0+=z*_1,X1+=z*i1,f0+=z*r1,r0+=z*x1,s0+=z*c1,v0+=z*l1,Z0+=z*k8,V0+=z*Y8,j0+=z*P8,A0+=z*R8,I0+=z*L8,D0+=z*m8,q1+=z*H9,B1+=z*A9,$1+=z*z9,z=M[15],n0+=z*b,X1+=z*_1,f0+=z*i1,r0+=z*r1,s0+=z*x1,v0+=z*c1,Z0+=z*l1,V0+=z*k8,j0+=z*Y8,A0+=z*P8,I0+=z*R8,D0+=z*L8,q1+=z*m8,B1+=z*H9,$1+=z*A9,E1+=z*z9,n+=38*X1,e+=38*f0,z0+=38*r0,R0+=38*s0,t0+=38*v0,b0+=38*Z0,n1+=38*V0,l0+=38*j0,A1+=38*A0,I1+=38*I0,L1+=38*D0,T1+=38*q1,w1+=38*B1,O1+=38*$1,j1+=38*E1,L=1,z=n+L+65535,L=Math.floor(z/65536),n=z-L*65536,z=e+L+65535,L=Math.floor(z/65536),e=z-L*65536,z=z0+L+65535,L=Math.floor(z/65536),z0=z-L*65536,z=R0+L+65535,L=Math.floor(z/65536),R0=z-L*65536,z=t0+L+65535,L=Math.floor(z/65536),t0=z-L*65536,z=b0+L+65535,L=Math.floor(z/65536),b0=z-L*65536,z=n1+L+65535,L=Math.floor(z/65536),n1=z-L*65536,z=l0+L+65535,L=Math.floor(z/65536),l0=z-L*65536,z=A1+L+65535,L=Math.floor(z/65536),A1=z-L*65536,z=I1+L+65535,L=Math.floor(z/65536),I1=z-L*65536,z=L1+L+65535,L=Math.floor(z/65536),L1=z-L*65536,z=T1+L+65535,L=Math.floor(z/65536),T1=z-L*65536,z=w1+L+65535,L=Math.floor(z/65536),w1=z-L*65536,z=O1+L+65535,L=Math.floor(z/65536),O1=z-L*65536,z=j1+L+65535,L=Math.floor(z/65536),j1=z-L*65536,z=n0+L+65535,L=Math.floor(z/65536),n0=z-L*65536,n+=L-1+37*(L-1),L=1,z=n+L+65535,L=Math.floor(z/65536),n=z-L*65536,z=e+L+65535,L=Math.floor(z/65536),e=z-L*65536,z=z0+L+65535,L=Math.floor(z/65536),z0=z-L*65536,z=R0+L+65535,L=Math.floor(z/65536),R0=z-L*65536,z=t0+L+65535,L=Math.floor(z/65536),t0=z-L*65536,z=b0+L+65535,L=Math.floor(z/65536),b0=z-L*65536,z=n1+L+65535,L=Math.floor(z/65536),n1=z-L*65536,z=l0+L+65535,L=Math.floor(z/65536),l0=z-L*65536,z=A1+L+65535,L=Math.floor(z/65536),A1=z-L*65536,z=I1+L+65535,L=Math.floor(z/65536),I1=z-L*65536,z=L1+L+65535,L=Math.floor(z/65536),L1=z-L*65536,z=T1+L+65535,L=Math.floor(z/65536),T1=z-L*65536,z=w1+L+65535,L=Math.floor(z/65536),w1=z-L*65536,z=O1+L+65535,L=Math.floor(z/65536),O1=z-L*65536,z=j1+L+65535,L=Math.floor(z/65536),j1=z-L*65536,z=n0+L+65535,L=Math.floor(z/65536),n0=z-L*65536,n+=L-1+37*(L-1),K[0]=n,K[1]=e,K[2]=z0,K[3]=R0,K[4]=t0,K[5]=b0,K[6]=n1,K[7]=l0,K[8]=A1,K[9]=I1,K[10]=L1,K[11]=T1,K[12]=w1,K[13]=O1,K[14]=j1,K[15]=n0}function J0(K,M){m(K,M,M)}function U0(K,M){var C=X(),z;for(z=0;z<16;z++)C[z]=M[z];for(z=253;z>=0;z--)if(J0(C,C),z!==2&&z!==4)m(C,C,M);for(z=0;z<16;z++)K[z]=C[z]}function q0(K,M){var C=X(),z;for(z=0;z<16;z++)C[z]=M[z];for(z=250;z>=0;z--)if(J0(C,C),z!==1)m(C,C,M);for(z=0;z<16;z++)K[z]=C[z]}function $0(K,M,C){var z=new Uint8Array(32),L=new Float64Array(80),n,e,z0=X(),R0=X(),t0=X(),b0=X(),n1=X(),l0=X();for(e=0;e<31;e++)z[e]=M[e];z[31]=M[31]&127|64,z[0]&=248,_(L,C);for(e=0;e<16;e++)R0[e]=L[e],b0[e]=z0[e]=t0[e]=0;z0[0]=b0[0]=1;for(e=254;e>=0;--e)n=z[e>>>3]>>>(e&7)&1,r(z0,R0,n),r(t0,b0,n),v(n1,z0,t0),R(z0,z0,t0),v(t0,R0,b0),R(R0,R0,b0),J0(b0,n1),J0(l0,z0),m(z0,t0,z0),m(t0,R0,n1),v(n1,z0,t0),R(z0,z0,t0),J0(R0,z0),R(t0,b0,l0),m(z0,t0,U),v(z0,z0,b0),m(t0,t0,z0),m(z0,b0,l0),m(b0,R0,L),J0(R0,n1),r(z0,R0,n),r(t0,b0,n);for(e=0;e<16;e++)L[e+16]=z0[e],L[e+32]=t0[e],L[e+48]=R0[e],L[e+64]=b0[e];var A1=L.subarray(32),I1=L.subarray(16);return U0(A1,A1),m(I1,I1,A1),o(K,I1),0}function u0(K,M){return $0(K,M,J)}function H1(K,M){return G(M,32),u0(K,M)}function v1(K,M,C){var z=new Uint8Array(32);return $0(z,C,M),F(K,Y,z,u)}var h0=d,F1=P;function S1(K,M,C,z,L,n){var e=new Uint8Array(32);return v1(e,L,n),h0(K,M,C,z,e)}function N0(K,M,C,z,L,n){var e=new Uint8Array(32);return v1(e,L,n),F1(K,M,C,z,e)}var F0=[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 m0(K,M,C,z){var L=new Int32Array(16),n=new Int32Array(16),e,z0,R0,t0,b0,n1,l0,A1,I1,L1,T1,w1,O1,j1,n0,X1,f0,r0,s0,v0,Z0,V0,j0,A0,I0,D0,q1=K[0],B1=K[1],$1=K[2],E1=K[3],b=K[4],_1=K[5],i1=K[6],r1=K[7],x1=M[0],c1=M[1],l1=M[2],k8=M[3],Y8=M[4],P8=M[5],R8=M[6],L8=M[7],m8=0;while(z>=128){for(s0=0;s0<16;s0++)v0=8*s0+m8,L[s0]=C[v0+0]<<24|C[v0+1]<<16|C[v0+2]<<8|C[v0+3],n[s0]=C[v0+4]<<24|C[v0+5]<<16|C[v0+6]<<8|C[v0+7];for(s0=0;s0<80;s0++)if(e=q1,z0=B1,R0=$1,t0=E1,b0=b,n1=_1,l0=i1,A1=r1,I1=x1,L1=c1,T1=l1,w1=k8,O1=Y8,j1=P8,n0=R8,X1=L8,Z0=r1,V0=L8,j0=V0&65535,A0=V0>>>16,I0=Z0&65535,D0=Z0>>>16,Z0=(b>>>14|Y8<<18)^(b>>>18|Y8<<14)^(Y8>>>9|b<<23),V0=(Y8>>>14|b<<18)^(Y8>>>18|b<<14)^(b>>>9|Y8<<23),j0+=V0&65535,A0+=V0>>>16,I0+=Z0&65535,D0+=Z0>>>16,Z0=b&_1^~b&i1,V0=Y8&P8^~Y8&R8,j0+=V0&65535,A0+=V0>>>16,I0+=Z0&65535,D0+=Z0>>>16,Z0=F0[s0*2],V0=F0[s0*2+1],j0+=V0&65535,A0+=V0>>>16,I0+=Z0&65535,D0+=Z0>>>16,Z0=L[s0%16],V0=n[s0%16],j0+=V0&65535,A0+=V0>>>16,I0+=Z0&65535,D0+=Z0>>>16,A0+=j0>>>16,I0+=A0>>>16,D0+=I0>>>16,f0=I0&65535|D0<<16,r0=j0&65535|A0<<16,Z0=f0,V0=r0,j0=V0&65535,A0=V0>>>16,I0=Z0&65535,D0=Z0>>>16,Z0=(q1>>>28|x1<<4)^(x1>>>2|q1<<30)^(x1>>>7|q1<<25),V0=(x1>>>28|q1<<4)^(q1>>>2|x1<<30)^(q1>>>7|x1<<25),j0+=V0&65535,A0+=V0>>>16,I0+=Z0&65535,D0+=Z0>>>16,Z0=q1&B1^q1&$1^B1&$1,V0=x1&c1^x1&l1^c1&l1,j0+=V0&65535,A0+=V0>>>16,I0+=Z0&65535,D0+=Z0>>>16,A0+=j0>>>16,I0+=A0>>>16,D0+=I0>>>16,A1=I0&65535|D0<<16,X1=j0&65535|A0<<16,Z0=t0,V0=w1,j0=V0&65535,A0=V0>>>16,I0=Z0&65535,D0=Z0>>>16,Z0=f0,V0=r0,j0+=V0&65535,A0+=V0>>>16,I0+=Z0&65535,D0+=Z0>>>16,A0+=j0>>>16,I0+=A0>>>16,D0+=I0>>>16,t0=I0&65535|D0<<16,w1=j0&65535|A0<<16,B1=e,$1=z0,E1=R0,b=t0,_1=b0,i1=n1,r1=l0,q1=A1,c1=I1,l1=L1,k8=T1,Y8=w1,P8=O1,R8=j1,L8=n0,x1=X1,s0%16===15)for(v0=0;v0<16;v0++)Z0=L[v0],V0=n[v0],j0=V0&65535,A0=V0>>>16,I0=Z0&65535,D0=Z0>>>16,Z0=L[(v0+9)%16],V0=n[(v0+9)%16],j0+=V0&65535,A0+=V0>>>16,I0+=Z0&65535,D0+=Z0>>>16,f0=L[(v0+1)%16],r0=n[(v0+1)%16],Z0=(f0>>>1|r0<<31)^(f0>>>8|r0<<24)^f0>>>7,V0=(r0>>>1|f0<<31)^(r0>>>8|f0<<24)^(r0>>>7|f0<<25),j0+=V0&65535,A0+=V0>>>16,I0+=Z0&65535,D0+=Z0>>>16,f0=L[(v0+14)%16],r0=n[(v0+14)%16],Z0=(f0>>>19|r0<<13)^(r0>>>29|f0<<3)^f0>>>6,V0=(r0>>>19|f0<<13)^(f0>>>29|r0<<3)^(r0>>>6|f0<<26),j0+=V0&65535,A0+=V0>>>16,I0+=Z0&65535,D0+=Z0>>>16,A0+=j0>>>16,I0+=A0>>>16,D0+=I0>>>16,L[v0]=I0&65535|D0<<16,n[v0]=j0&65535|A0<<16;Z0=q1,V0=x1,j0=V0&65535,A0=V0>>>16,I0=Z0&65535,D0=Z0>>>16,Z0=K[0],V0=M[0],j0+=V0&65535,A0+=V0>>>16,I0+=Z0&65535,D0+=Z0>>>16,A0+=j0>>>16,I0+=A0>>>16,D0+=I0>>>16,K[0]=q1=I0&65535|D0<<16,M[0]=x1=j0&65535|A0<<16,Z0=B1,V0=c1,j0=V0&65535,A0=V0>>>16,I0=Z0&65535,D0=Z0>>>16,Z0=K[1],V0=M[1],j0+=V0&65535,A0+=V0>>>16,I0+=Z0&65535,D0+=Z0>>>16,A0+=j0>>>16,I0+=A0>>>16,D0+=I0>>>16,K[1]=B1=I0&65535|D0<<16,M[1]=c1=j0&65535|A0<<16,Z0=$1,V0=l1,j0=V0&65535,A0=V0>>>16,I0=Z0&65535,D0=Z0>>>16,Z0=K[2],V0=M[2],j0+=V0&65535,A0+=V0>>>16,I0+=Z0&65535,D0+=Z0>>>16,A0+=j0>>>16,I0+=A0>>>16,D0+=I0>>>16,K[2]=$1=I0&65535|D0<<16,M[2]=l1=j0&65535|A0<<16,Z0=E1,V0=k8,j0=V0&65535,A0=V0>>>16,I0=Z0&65535,D0=Z0>>>16,Z0=K[3],V0=M[3],j0+=V0&65535,A0+=V0>>>16,I0+=Z0&65535,D0+=Z0>>>16,A0+=j0>>>16,I0+=A0>>>16,D0+=I0>>>16,K[3]=E1=I0&65535|D0<<16,M[3]=k8=j0&65535|A0<<16,Z0=b,V0=Y8,j0=V0&65535,A0=V0>>>16,I0=Z0&65535,D0=Z0>>>16,Z0=K[4],V0=M[4],j0+=V0&65535,A0+=V0>>>16,I0+=Z0&65535,D0+=Z0>>>16,A0+=j0>>>16,I0+=A0>>>16,D0+=I0>>>16,K[4]=b=I0&65535|D0<<16,M[4]=Y8=j0&65535|A0<<16,Z0=_1,V0=P8,j0=V0&65535,A0=V0>>>16,I0=Z0&65535,D0=Z0>>>16,Z0=K[5],V0=M[5],j0+=V0&65535,A0+=V0>>>16,I0+=Z0&65535,D0+=Z0>>>16,A0+=j0>>>16,I0+=A0>>>16,D0+=I0>>>16,K[5]=_1=I0&65535|D0<<16,M[5]=P8=j0&65535|A0<<16,Z0=i1,V0=R8,j0=V0&65535,A0=V0>>>16,I0=Z0&65535,D0=Z0>>>16,Z0=K[6],V0=M[6],j0+=V0&65535,A0+=V0>>>16,I0+=Z0&65535,D0+=Z0>>>16,A0+=j0>>>16,I0+=A0>>>16,D0+=I0>>>16,K[6]=i1=I0&65535|D0<<16,M[6]=R8=j0&65535|A0<<16,Z0=r1,V0=L8,j0=V0&65535,A0=V0>>>16,I0=Z0&65535,D0=Z0>>>16,Z0=K[7],V0=M[7],j0+=V0&65535,A0+=V0>>>16,I0+=Z0&65535,D0+=Z0>>>16,A0+=j0>>>16,I0+=A0>>>16,D0+=I0>>>16,K[7]=r1=I0&65535|D0<<16,M[7]=L8=j0&65535|A0<<16,m8+=128,z-=128}return z}function Y0(K,M,C){var z=new Int32Array(8),L=new Int32Array(8),n=new Uint8Array(256),e,z0=C;z[0]=1779033703,z[1]=3144134277,z[2]=1013904242,z[3]=2773480762,z[4]=1359893119,z[5]=2600822924,z[6]=528734635,z[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,m0(z,L,M,C),C%=128;for(e=0;e<C;e++)n[e]=M[z0-C+e];n[C]=128,C=256-128*(C<112?1:0),n[C-9]=0,I(n,C-8,z0/536870912|0,z0<<3),m0(z,L,n,C);for(e=0;e<8;e++)I(K,8*e,z[e],L[e]);return 0}function K0(K,M){var C=X(),z=X(),L=X(),n=X(),e=X(),z0=X(),R0=X(),t0=X(),b0=X();R(C,K[1],K[0]),R(b0,M[1],M[0]),m(C,C,b0),v(z,K[0],K[1]),v(b0,M[0],M[1]),m(z,z,b0),m(L,K[3],M[3]),m(L,L,N),m(n,K[2],M[2]),v(n,n,n),R(e,z,C),R(z0,n,L),v(R0,n,L),v(t0,z,C),m(K[0],e,z0),m(K[1],t0,R0),m(K[2],R0,z0),m(K[3],e,t0)}function P0(K,M,C){var z;for(z=0;z<4;z++)r(K[z],M[z],C)}function k0(K,M){var C=X(),z=X(),L=X();U0(L,M[2]),m(C,M[0],L),m(z,M[1],L),o(K,z),K[31]^=S(C)<<7}function R1(K,M,C){var z,L;E(K[0],Z),E(K[1],V),E(K[2],V),E(K[3],Z);for(L=255;L>=0;--L)z=C[L/8|0]>>(L&7)&1,P0(K,M,z),K0(M,K),K0(K,K),P0(K,M,z)}function Q1(K,M){var C=[X(),X(),X(),X()];E(C[0],q),E(C[1],A),E(C[2],V),m(C[3],q,A),R1(K,C,M)}function X0(K,M,C){var z=new Uint8Array(64),L=[X(),X(),X(),X()],n;if(!C)G(M,32);Y0(z,M,32),z[0]&=248,z[31]&=127,z[31]|=64,Q1(L,z),k0(K,L);for(n=0;n<32;n++)M[n+32]=K[n];return 0}var C0=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 x0(K,M){var C,z,L,n;for(z=63;z>=32;--z){C=0;for(L=z-32,n=z-12;L<n;++L)M[L]+=C-16*M[z]*C0[L-(z-32)],C=Math.floor((M[L]+128)/256),M[L]-=C*256;M[L]+=C,M[z]=0}C=0;for(L=0;L<32;L++)M[L]+=C-(M[31]>>4)*C0[L],C=M[L]>>8,M[L]&=255;for(L=0;L<32;L++)M[L]-=C*C0[L];for(z=0;z<32;z++)M[z+1]+=M[z]>>8,K[z]=M[z]&255}function k1(K){var M=new Float64Array(64),C;for(C=0;C<64;C++)M[C]=K[C];for(C=0;C<64;C++)K[C]=0;x0(K,M)}function W8(K,M,C,z){var L=new Uint8Array(64),n=new Uint8Array(64),e=new Uint8Array(64),z0,R0,t0=new Float64Array(64),b0=[X(),X(),X(),X()];Y0(L,z,32),L[0]&=248,L[31]&=127,L[31]|=64;var n1=C+64;for(z0=0;z0<C;z0++)K[64+z0]=M[z0];for(z0=0;z0<32;z0++)K[32+z0]=L[32+z0];Y0(e,K.subarray(32),C+32),k1(e),Q1(b0,e),k0(K,b0);for(z0=32;z0<64;z0++)K[z0]=z[z0];Y0(n,K,C+64),k1(n);for(z0=0;z0<64;z0++)t0[z0]=0;for(z0=0;z0<32;z0++)t0[z0]=e[z0];for(z0=0;z0<32;z0++)for(R0=0;R0<32;R0++)t0[z0+R0]+=n[z0]*L[R0];return x0(K.subarray(32),t0),n1}function d1(K,M){var C=X(),z=X(),L=X(),n=X(),e=X(),z0=X(),R0=X();if(E(K[2],V),_(K[1],M),J0(L,K[1]),m(n,L,Q),R(L,L,K[2]),v(n,K[2],n),J0(e,n),J0(z0,e),m(R0,z0,e),m(C,R0,L),m(C,C,n),q0(C,C),m(C,C,L),m(C,C,n),m(C,C,n),m(K[0],C,n),J0(z,K[0]),m(z,z,n),B(z,L))m(K[0],K[0],H);if(J0(z,K[0]),m(z,z,n),B(z,L))return-1;if(S(K[0])===M[31]>>7)R(K[0],Z,K[0]);return m(K[3],K[0],K[1]),0}function N1(K,M,C,z){var L,n=new Uint8Array(32),e=new Uint8Array(64),z0=[X(),X(),X(),X()],R0=[X(),X(),X(),X()];if(C<64)return-1;if(d1(R0,z))return-1;for(L=0;L<C;L++)K[L]=M[L];for(L=0;L<32;L++)K[L+32]=z[L];if(Y0(e,K,C),k1(e),R1(z0,R0,e),Q1(R0,M.subarray(32)),K0(z0,R0),k0(n,z0),C-=64,T(M,0,n,0)){for(L=0;L<C;L++)K[L]=0;return-1}for(L=0;L<C;L++)K[L]=M[L+64];return C}var c=32,W0=24,Q0=32,T0=16,e0=32,q8=32,I8=32,C1=32,_0=32,p0=W0,o0=Q0,a0=T0,z1=64,o1=32,Z8=64,S9=32,lX=64;W.lowlevel={crypto_core_hsalsa20:F,crypto_stream_xor:y,crypto_stream:s,crypto_stream_salsa20_xor:l,crypto_stream_salsa20:f,crypto_onetimeauth:H0,crypto_onetimeauth_verify:g,crypto_verify_16:O,crypto_verify_32:T,crypto_secretbox:d,crypto_secretbox_open:P,crypto_scalarmult:$0,crypto_scalarmult_base:u0,crypto_box_beforenm:v1,crypto_box_afternm:h0,crypto_box:S1,crypto_box_open:N0,crypto_box_keypair:H1,crypto_hash:Y0,crypto_sign:W8,crypto_sign_keypair:X0,crypto_sign_open:N1,crypto_secretbox_KEYBYTES:c,crypto_secretbox_NONCEBYTES:W0,crypto_secretbox_ZEROBYTES:Q0,crypto_secretbox_BOXZEROBYTES:T0,crypto_scalarmult_BYTES:e0,crypto_scalarmult_SCALARBYTES:q8,crypto_box_PUBLICKEYBYTES:I8,crypto_box_SECRETKEYBYTES:C1,crypto_box_BEFORENMBYTES:_0,crypto_box_NONCEBYTES:p0,crypto_box_ZEROBYTES:o0,crypto_box_BOXZEROBYTES:a0,crypto_sign_BYTES:z1,crypto_sign_PUBLICKEYBYTES:o1,crypto_sign_SECRETKEYBYTES:Z8,crypto_sign_SEEDBYTES:S9,crypto_hash_BYTES:lX,gf:X,D:Q,L:C0,pack25519:o,unpack25519:_,M:m,A:v,S:J0,Z:R,pow2523:q0,add:K0,set25519:E,modL:x0,scalarmult:R1,scalarbase:Q1};function vU(K,M){if(K.length!==c)throw Error("bad key size");if(M.length!==W0)throw Error("bad nonce size")}function HA(K,M){if(K.length!==I8)throw Error("bad public key size");if(M.length!==C1)throw Error("bad secret key size")}function X5(){for(var K=0;K<arguments.length;K++)if(!(arguments[K]instanceof Uint8Array))throw TypeError("unexpected type, use Uint8Array")}function ID(K){for(var M=0;M<K.length;M++)K[M]=0}W.randomBytes=function(K){var M=new Uint8Array(K);return G(M,K),M},W.secretbox=function(K,M,C){X5(K,M,C),vU(C,M);var z=new Uint8Array(Q0+K.length),L=new Uint8Array(z.length);for(var n=0;n<K.length;n++)z[n+Q0]=K[n];return d(L,z,z.length,M,C),L.subarray(T0)},W.secretbox.open=function(K,M,C){X5(K,M,C),vU(C,M);var z=new Uint8Array(T0+K.length),L=new Uint8Array(z.length);for(var n=0;n<K.length;n++)z[n+T0]=K[n];if(z.length<32)return null;if(P(L,z,z.length,M,C)!==0)return null;return L.subarray(Q0)},W.secretbox.keyLength=c,W.secretbox.nonceLength=W0,W.secretbox.overheadLength=T0,W.scalarMult=function(K,M){if(X5(K,M),K.length!==q8)throw Error("bad n size");if(M.length!==e0)throw Error("bad p size");var C=new Uint8Array(e0);return $0(C,K,M),C},W.scalarMult.base=function(K){if(X5(K),K.length!==q8)throw Error("bad n size");var M=new Uint8Array(e0);return u0(M,K),M},W.scalarMult.scalarLength=q8,W.scalarMult.groupElementLength=e0,W.box=function(K,M,C,z){var L=W.box.before(C,z);return W.secretbox(K,M,L)},W.box.before=function(K,M){X5(K,M),HA(K,M);var C=new Uint8Array(_0);return v1(C,K,M),C},W.box.after=W.secretbox,W.box.open=function(K,M,C,z){var L=W.box.before(C,z);return W.secretbox.open(K,M,L)},W.box.open.after=W.secretbox.open,W.box.keyPair=function(){var K=new Uint8Array(I8),M=new Uint8Array(C1);return H1(K,M),{publicKey:K,secretKey:M}},W.box.keyPair.fromSecretKey=function(K){if(X5(K),K.length!==C1)throw Error("bad secret key size");var M=new Uint8Array(I8);return u0(M,K),{publicKey:M,secretKey:new Uint8Array(K)}},W.box.publicKeyLength=I8,W.box.secretKeyLength=C1,W.box.sharedKeyLength=_0,W.box.nonceLength=p0,W.box.overheadLength=W.secretbox.overheadLength,W.sign=function(K,M){if(X5(K,M),M.length!==Z8)throw Error("bad secret key size");var C=new Uint8Array(z1+K.length);return W8(C,K,K.length,M),C},W.sign.open=function(K,M){if(X5(K,M),M.length!==o1)throw Error("bad public key size");var C=new Uint8Array(K.length),z=N1(C,K,K.length,M);if(z<0)return null;var L=new Uint8Array(z);for(var n=0;n<L.length;n++)L[n]=C[n];return L},W.sign.detached=function(K,M){var C=W.sign(K,M),z=new Uint8Array(z1);for(var L=0;L<z.length;L++)z[L]=C[L];return z},W.sign.detached.verify=function(K,M,C){if(X5(K,M,C),M.length!==z1)throw Error("bad signature size");if(C.length!==o1)throw Error("bad public key size");var z=new Uint8Array(z1+K.length),L=new Uint8Array(z1+K.length),n;for(n=0;n<z1;n++)z[n]=M[n];for(n=0;n<K.length;n++)z[n+z1]=K[n];return N1(L,z,z.length,C)>=0},W.sign.keyPair=function(){var K=new Uint8Array(o1),M=new Uint8Array(Z8);return X0(K,M),{publicKey:K,secretKey:M}},W.sign.keyPair.fromSecretKey=function(K){if(X5(K),K.length!==Z8)throw Error("bad secret key size");var M=new Uint8Array(o1);for(var C=0;C<M.length;C++)M[C]=K[32+C];return{publicKey:M,secretKey:new Uint8Array(K)}},W.sign.keyPair.fromSeed=function(K){if(X5(K),K.length!==S9)throw Error("bad seed size");var M=new Uint8Array(o1),C=new Uint8Array(Z8);for(var z=0;z<32;z++)C[z]=K[z];return X0(M,C,!0),{publicKey:M,secretKey:C}},W.sign.publicKeyLength=o1,W.sign.secretKeyLength=Z8,W.sign.seedLength=S9,W.sign.signatureLength=z1,W.hash=function(K){X5(K);var M=new Uint8Array(lX);return Y0(M,K,K.length),M},W.hash.hashLength=lX,W.verify=function(K,M){if(X5(K,M),K.length===0||M.length===0)return!1;if(K.length!==M.length)return!1;return w(K,0,M,0,K.length)===0?!0:!1},W.setPRNG=function(K){G=K},function(){var K=typeof self<"u"?self.crypto||self.msCrypto:null;if(K&&K.getRandomValues){var M=65536;W.setPRNG(function(C,z){var L,n=new Uint8Array(z);for(L=0;L<z;L+=M)K.getRandomValues(n.subarray(L,L+Math.min(z-L,M)));for(L=0;L<z;L++)C[L]=n[L];ID(n)})}else if(K=_8("crypto"),K&&K.randomBytes)W.setPRNG(function(C,z){var L,n=K.randomBytes(z);for(L=0;L<z;L++)C[L]=n[L];ID(n)})}()})(typeof _Q<"u"&&Y00?Y00:self.nacl=self.nacl||{})});var Fz=V1((OM)=>{Object.defineProperty(OM,"__esModule",{value:!0});class KM{constructor(W,X=0,G=0){this.start=X,this.end=G>X?G:X,this.buf=W}get length(){return this.buf.length}reset(W=0,X=0){if(this.start=W,X>=this.start)this.end=X;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,X="Too few bytes to parse."){let G=this.end+W;if(G>this.buf.length){let Y=Error(X);throw Y.available=this.buf.length,Y.requested=G,Y}return this.walk(0),this}mustWalk(W,X){return this.mustHas(W,X),this.walk(W),this}}OM.BufferVisitor=KM});var MM=V1((TM)=>{Object.defineProperty(TM,"__esModule",{value:!0});var DM=_8("util"),CM=64,xz="-----BEGIN ",kz="-----END ",fJ="-----",Sz="Proc-Type";class _z{static parse(W){let X=[],G=W.toString("utf8").split(`
8
8
  `).map((Y)=>Y.trim()).filter((Y)=>Y!==""&&!Y.startsWith("#"));while(G.length>0)X.push(ub(G));if(X.length===0)throw Error("PEM: no block");return X}constructor(W,X){this.type=W,this.body=X,this.headers=Object.create(null)}get procType(){return this.getHeader(Sz)}getHeader(W){let X=this.headers[W];return X==null?"":X}setHeader(W,X){if(W.includes(":"))throw Error("pem: cannot encode a header key that contains a colon");if(W===""||X==="")throw Error("pem: invalid header key or value");this.headers[W]=X}toString(){let W=xz+this.type+fJ+`
9
9
  `,X=Object.keys(this.headers);if(X.length>0){let J=this.procType;if(J!=="")W+=`${Sz}: ${J}
10
10
  `;X.sort();for(let Z of X)if(Z!==Sz)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 fM;(function(W){(function(X){var G=typeof globalThis==="object"?globalThis:typeof global==="object"?global:typeof self==="object"?self:typeof this==="object"?this:U(),Y=J(W);if(typeof G.Reflect<"u")Y=J(G.Reflect,Y);if(X(Y,G),typeof G.Reflect>"u")G.Reflect=W;function J(Q,N){return function(q,A){if(Object.defineProperty(Q,q,{configurable:!0,writable:!0,value:A}),N)N(q,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(X,G){var Y=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,N=!U&&!Q,q={create:U?function(){return N1(Object.create(null))}:Q?function(){return N1({__proto__:null})}:function(){return N1({})},has:N?function(c,W0){return Y.call(c,W0)}:function(c,W0){return W0 in c},get:N?function(c,W0){return Y.call(c,W0)?c[W0]:void 0}:function(c,W0){return c[W0]}},A=Object.getPrototypeOf(Function),H=typeof Map==="function"&&typeof Map.prototype.entries==="function"?Map:k1(),I=typeof Set==="function"&&typeof Set.prototype.entries==="function"?Set:W8(),w=typeof WeakMap==="function"?WeakMap:d1(),O=J?Symbol.for("@reflect-metadata:registry"):void 0,T=Q1(),x=X0(T);function h(c,W0,Q0,T0){if(!v(Q0)){if(!v1(c))throw TypeError();if(!J0(W0))throw TypeError();if(!J0(T0)&&!v(T0)&&!R(T0))throw TypeError();if(R(T0))T0=void 0;return Q0=H1(Q0),d(c,W0,Q0,T0)}else{if(!v1(c))throw TypeError();if(!F1(W0))throw TypeError();return g(c,W0)}}X("decorate",h);function $(c,W0){function Q0(T0,e0){if(!J0(T0))throw TypeError();if(!v(e0)&&!S1(e0))throw TypeError();o(c,W0,T0,e0)}return Q0}X("metadata",$);function F(c,W0,Q0,T0){if(!J0(Q0))throw TypeError();if(!v(T0))T0=H1(T0);return o(c,W0,Q0,T0)}X("defineMetadata",F);function u(c,W0,Q0){if(!J0(W0))throw TypeError();if(!v(Q0))Q0=H1(Q0);return P(c,W0,Q0)}X("hasMetadata",u);function l(c,W0,Q0){if(!J0(W0))throw TypeError();if(!v(Q0))Q0=H1(Q0);return E(c,W0,Q0)}X("hasOwnMetadata",l);function p(c,W0,Q0){if(!J0(W0))throw TypeError();if(!v(Q0))Q0=H1(Q0);return f(c,W0,Q0)}X("getMetadata",p);function s(c,W0,Q0){if(!J0(W0))throw TypeError();if(!v(Q0))Q0=H1(Q0);return r(c,W0,Q0)}X("getOwnMetadata",s);function y(c,W0){if(!J0(c))throw TypeError();if(!v(W0))W0=H1(W0);return B(c,W0)}X("getMetadataKeys",y);function t(c,W0){if(!J0(c))throw TypeError();if(!v(W0))W0=H1(W0);return S(c,W0)}X("getOwnMetadataKeys",t);function H0(c,W0,Q0){if(!J0(W0))throw TypeError();if(!v(Q0))Q0=H1(Q0);if(!J0(W0))throw TypeError();if(!v(Q0))Q0=H1(Q0);var T0=x0(W0,Q0,!1);if(v(T0))return!1;return T0.OrdinaryDeleteMetadata(c,W0,Q0)}X("deleteMetadata",H0);function g(c,W0){for(var Q0=c.length-1;Q0>=0;--Q0){var T0=c[Q0],e0=T0(W0);if(!v(e0)&&!R(e0)){if(!F1(e0))throw TypeError();W0=e0}}return W0}function d(c,W0,Q0,T0){for(var e0=c.length-1;e0>=0;--e0){var q8=c[e0],I8=q8(W0,Q0,T0);if(!v(I8)&&!R(I8)){if(!J0(I8))throw TypeError();T0=I8}}return T0}function P(c,W0,Q0){var T0=E(c,W0,Q0);if(T0)return!0;var e0=k0(W0);if(!R(e0))return P(c,e0,Q0);return!1}function E(c,W0,Q0){var T0=x0(W0,Q0,!1);if(v(T0))return!1;return $0(T0.OrdinaryHasOwnMetadata(c,W0,Q0))}function f(c,W0,Q0){var T0=E(c,W0,Q0);if(T0)return r(c,W0,Q0);var e0=k0(W0);if(!R(e0))return f(c,e0,Q0);return}function r(c,W0,Q0){var T0=x0(W0,Q0,!1);if(v(T0))return;return T0.OrdinaryGetOwnMetadata(c,W0,Q0)}function o(c,W0,Q0,T0){var e0=x0(Q0,T0,!0);e0.OrdinaryDefineOwnMetadata(c,W0,Q0,T0)}function B(c,W0){var Q0=S(c,W0),T0=k0(c);if(T0===null)return Q0;var e0=B(T0,W0);if(e0.length<=0)return Q0;if(Q0.length<=0)return e0;var q8=new I,I8=[];for(var C1=0,_0=Q0;C1<_0.length;C1++){var p0=_0[C1],o0=q8.has(p0);if(!o0)q8.add(p0),I8.push(p0)}for(var a0=0,z1=e0;a0<z1.length;a0++){var p0=z1[a0],o0=q8.has(p0);if(!o0)q8.add(p0),I8.push(p0)}return I8}function S(c,W0){var Q0=x0(c,W0,!1);if(!Q0)return[];return Q0.OrdinaryOwnMetadataKeys(c,W0)}function _(c){if(c===null)return 1;switch(typeof c){case"undefined":return 0;case"boolean":return 2;case"string":return 3;case"symbol":return 4;case"number":return 5;case"object":return c===null?1:6;default:return 6}}function v(c){return c===void 0}function R(c){return c===null}function m(c){return typeof c==="symbol"}function J0(c){return typeof c==="object"?c!==null:typeof c==="function"}function U0(c,W0){switch(_(c)){case 0:return c;case 1:return c;case 2:return c;case 3:return c;case 4:return c;case 5:return c}var Q0=W0===3?"string":W0===5?"number":"default",T0=F0(c,Z);if(T0!==void 0){var e0=T0.call(c,Q0);if(J0(e0))throw TypeError();return e0}return q0(c,Q0==="default"?"number":Q0)}function q0(c,W0){if(W0==="string"){var Q0=c.toString;if(h0(Q0)){var T0=Q0.call(c);if(!J0(T0))return T0}var e0=c.valueOf;if(h0(e0)){var T0=e0.call(c);if(!J0(T0))return T0}}else{var e0=c.valueOf;if(h0(e0)){var T0=e0.call(c);if(!J0(T0))return T0}var q8=c.toString;if(h0(q8)){var T0=q8.call(c);if(!J0(T0))return T0}}throw TypeError()}function $0(c){return!!c}function u0(c){return""+c}function H1(c){var W0=U0(c,3);if(m(W0))return W0;return u0(W0)}function v1(c){return Array.isArray?Array.isArray(c):c instanceof Object?c instanceof Array:Object.prototype.toString.call(c)==="[object Array]"}function h0(c){return typeof c==="function"}function F1(c){return typeof c==="function"}function S1(c){switch(_(c)){case 3:return!0;case 4:return!0;default:return!1}}function N0(c,W0){return c===W0||c!==c&&W0!==W0}function F0(c,W0){var Q0=c[W0];if(Q0===void 0||Q0===null)return;if(!h0(Q0))throw TypeError();return Q0}function m0(c){var W0=F0(c,V);if(!h0(W0))throw TypeError();var Q0=W0.call(c);if(!J0(Q0))throw TypeError();return Q0}function Y0(c){return c.value}function K0(c){var W0=c.next();return W0.done?!1:W0}function P0(c){var W0=c.return;if(W0)W0.call(c)}function k0(c){var W0=Object.getPrototypeOf(c);if(typeof c!=="function"||c===A)return W0;if(W0!==A)return W0;var Q0=c.prototype,T0=Q0&&Object.getPrototypeOf(Q0);if(T0==null||T0===Object.prototype)return W0;var e0=T0.constructor;if(typeof e0!=="function")return W0;if(e0===c)return W0;return e0}function R1(){var c;if(!v(O)&&typeof G.Reflect<"u"&&!(O in G.Reflect)&&typeof G.Reflect.defineMetadata==="function")c=C0(G.Reflect);var W0,Q0,T0,e0=new w,q8={registerProvider:I8,getProvider:_0,setProvider:o0};return q8;function I8(a0){if(!Object.isExtensible(q8))throw Error("Cannot add provider to a frozen registry.");switch(!0){case c===a0:break;case v(W0):W0=a0;break;case W0===a0:break;case v(Q0):Q0=a0;break;case Q0===a0:break;default:if(T0===void 0)T0=new I;T0.add(a0);break}}function C1(a0,z1){if(!v(W0)){if(W0.isProviderFor(a0,z1))return W0;if(!v(Q0)){if(Q0.isProviderFor(a0,z1))return W0;if(!v(T0)){var o1=m0(T0);while(!0){var Z8=K0(o1);if(!Z8)return;var S9=Y0(Z8);if(S9.isProviderFor(a0,z1))return P0(o1),S9}}}}if(!v(c)&&c.isProviderFor(a0,z1))return c;return}function _0(a0,z1){var o1=e0.get(a0),Z8;if(!v(o1))Z8=o1.get(z1);if(!v(Z8))return Z8;if(Z8=C1(a0,z1),!v(Z8)){if(v(o1))o1=new H,e0.set(a0,o1);o1.set(z1,Z8)}return Z8}function p0(a0){if(v(a0))throw TypeError();return W0===a0||Q0===a0||!v(T0)&&T0.has(a0)}function o0(a0,z1,o1){if(!p0(o1))throw Error("Metadata provider not registered.");var Z8=_0(a0,z1);if(Z8!==o1){if(!v(Z8))return!1;var S9=e0.get(a0);if(v(S9))S9=new H,e0.set(a0,S9);S9.set(z1,o1)}return!0}}function Q1(){var c;if(!v(O)&&J0(G.Reflect)&&Object.isExtensible(G.Reflect))c=G.Reflect[O];if(v(c))c=R1();if(!v(O)&&J0(G.Reflect)&&Object.isExtensible(G.Reflect))Object.defineProperty(G.Reflect,O,{enumerable:!1,configurable:!1,writable:!1,value:c});return c}function X0(c){var W0=new w,Q0={isProviderFor:function(p0,o0){var a0=W0.get(p0);if(v(a0))return!1;return a0.has(o0)},OrdinaryDefineOwnMetadata:I8,OrdinaryHasOwnMetadata:e0,OrdinaryGetOwnMetadata:q8,OrdinaryOwnMetadataKeys:C1,OrdinaryDeleteMetadata:_0};return T.registerProvider(Q0),Q0;function T0(p0,o0,a0){var z1=W0.get(p0),o1=!1;if(v(z1)){if(!a0)return;z1=new H,W0.set(p0,z1),o1=!0}var Z8=z1.get(o0);if(v(Z8)){if(!a0)return;if(Z8=new H,z1.set(o0,Z8),!c.setProvider(p0,o0,Q0)){if(z1.delete(o0),o1)W0.delete(p0);throw Error("Wrong provider for target.")}}return Z8}function e0(p0,o0,a0){var z1=T0(o0,a0,!1);if(v(z1))return!1;return $0(z1.has(p0))}function q8(p0,o0,a0){var z1=T0(o0,a0,!1);if(v(z1))return;return z1.get(p0)}function I8(p0,o0,a0,z1){var o1=T0(a0,z1,!0);o1.set(p0,o0)}function C1(p0,o0){var a0=[],z1=T0(p0,o0,!1);if(v(z1))return a0;var o1=z1.keys(),Z8=m0(o1),S9=0;while(!0){var lX=K0(Z8);if(!lX)return a0.length=S9,a0;var vU=Y0(lX);try{a0[S9]=vU}catch(HA){try{P0(Z8)}finally{throw HA}}S9++}}function _0(p0,o0,a0){var z1=T0(o0,a0,!1);if(v(z1))return!1;if(!z1.delete(p0))return!1;if(z1.size===0){var o1=W0.get(o0);if(!v(o1)){if(o1.delete(a0),o1.size===0)W0.delete(o1)}}return!0}}function C0(c){var{defineMetadata:W0,hasOwnMetadata:Q0,getOwnMetadata:T0,getOwnMetadataKeys:e0,deleteMetadata:q8}=c,I8=new w,C1={isProviderFor:function(_0,p0){var o0=I8.get(_0);if(!v(o0)&&o0.has(p0))return!0;if(e0(_0,p0).length){if(v(o0))o0=new I,I8.set(_0,o0);return o0.add(p0),!0}return!1},OrdinaryDefineOwnMetadata:W0,OrdinaryHasOwnMetadata:Q0,OrdinaryGetOwnMetadata:T0,OrdinaryOwnMetadataKeys:e0,OrdinaryDeleteMetadata:q8};return C1}function x0(c,W0,Q0){var T0=T.getProvider(c,W0);if(!v(T0))return T0;if(Q0){if(T.setProvider(c,W0,x))return x;throw Error("Illegal state.")}return}function k1(){var c={},W0=[],Q0=function(){function C1(_0,p0,o0){this._index=0,this._keys=_0,this._values=p0,this._selector=o0}return C1.prototype["@@iterator"]=function(){return this},C1.prototype[V]=function(){return this},C1.prototype.next=function(){var _0=this._index;if(_0>=0&&_0<this._keys.length){var p0=this._selector(this._keys[_0],this._values[_0]);if(_0+1>=this._keys.length)this._index=-1,this._keys=W0,this._values=W0;else this._index++;return{value:p0,done:!1}}return{value:void 0,done:!0}},C1.prototype.throw=function(_0){if(this._index>=0)this._index=-1,this._keys=W0,this._values=W0;throw _0},C1.prototype.return=function(_0){if(this._index>=0)this._index=-1,this._keys=W0,this._values=W0;return{value:_0,done:!0}},C1}(),T0=function(){function C1(){this._keys=[],this._values=[],this._cacheKey=c,this._cacheIndex=-2}return Object.defineProperty(C1.prototype,"size",{get:function(){return this._keys.length},enumerable:!0,configurable:!0}),C1.prototype.has=function(_0){return this._find(_0,!1)>=0},C1.prototype.get=function(_0){var p0=this._find(_0,!1);return p0>=0?this._values[p0]:void 0},C1.prototype.set=function(_0,p0){var o0=this._find(_0,!0);return this._values[o0]=p0,this},C1.prototype.delete=function(_0){var p0=this._find(_0,!1);if(p0>=0){var o0=this._keys.length;for(var a0=p0+1;a0<o0;a0++)this._keys[a0-1]=this._keys[a0],this._values[a0-1]=this._values[a0];if(this._keys.length--,this._values.length--,N0(_0,this._cacheKey))this._cacheKey=c,this._cacheIndex=-2;return!0}return!1},C1.prototype.clear=function(){this._keys.length=0,this._values.length=0,this._cacheKey=c,this._cacheIndex=-2},C1.prototype.keys=function(){return new Q0(this._keys,this._values,e0)},C1.prototype.values=function(){return new Q0(this._keys,this._values,q8)},C1.prototype.entries=function(){return new Q0(this._keys,this._values,I8)},C1.prototype["@@iterator"]=function(){return this.entries()},C1.prototype[V]=function(){return this.entries()},C1.prototype._find=function(_0,p0){if(!N0(this._cacheKey,_0)){this._cacheIndex=-1;for(var o0=0;o0<this._keys.length;o0++)if(N0(this._keys[o0],_0)){this._cacheIndex=o0;break}}if(this._cacheIndex<0&&p0)this._cacheIndex=this._keys.length,this._keys.push(_0),this._values.push(void 0);return this._cacheIndex},C1}();return T0;function e0(C1,_0){return C1}function q8(C1,_0){return _0}function I8(C1,_0){return[C1,_0]}}function W8(){var c=function(){function W0(){this._map=new H}return Object.defineProperty(W0.prototype,"size",{get:function(){return this._map.size},enumerable:!0,configurable:!0}),W0.prototype.has=function(Q0){return this._map.has(Q0)},W0.prototype.add=function(Q0){return this._map.set(Q0,Q0),this},W0.prototype.delete=function(Q0){return this._map.delete(Q0)},W0.prototype.clear=function(){this._map.clear()},W0.prototype.keys=function(){return this._map.keys()},W0.prototype.values=function(){return this._map.keys()},W0.prototype.entries=function(){return this._map.entries()},W0.prototype["@@iterator"]=function(){return this.keys()},W0.prototype[V]=function(){return this.keys()},W0}();return c}function d1(){var c=16,W0=q.create(),Q0=T0();return function(){function _0(){this._key=T0()}return _0.prototype.has=function(p0){var o0=e0(p0,!1);return o0!==void 0?q.has(o0,this._key):!1},_0.prototype.get=function(p0){var o0=e0(p0,!1);return o0!==void 0?q.get(o0,this._key):void 0},_0.prototype.set=function(p0,o0){var a0=e0(p0,!0);return a0[this._key]=o0,this},_0.prototype.delete=function(p0){var o0=e0(p0,!1);return o0!==void 0?delete o0[this._key]:!1},_0.prototype.clear=function(){this._key=T0()},_0}();function T0(){var _0;do _0="@@WeakMap@@"+C1();while(q.has(W0,_0));return W0[_0]=!0,_0}function e0(_0,p0){if(!Y.call(_0,Q0)){if(!p0)return;Object.defineProperty(_0,Q0,{value:q.create()})}return _0[Q0]}function q8(_0,p0){for(var o0=0;o0<p0;++o0)_0[o0]=Math.random()*255|0;return _0}function I8(_0){if(typeof Uint8Array==="function"){var p0=new Uint8Array(_0);if(typeof crypto<"u")crypto.getRandomValues(p0);else if(typeof msCrypto<"u")msCrypto.getRandomValues(p0);else q8(p0,_0);return p0}return q8(Array(_0),_0)}function C1(){var _0=I8(c);_0[6]=_0[6]&79|64,_0[8]=_0[8]&191|128;var p0="";for(var o0=0;o0<c;++o0){var a0=_0[o0];if(o0===4||o0===6||o0===8)p0+="-";if(a0<16)p0+="0";p0+=a0.toString(16).toLowerCase()}return p0}}function N1(c){return c.__=void 0,delete c.__,c}})})(fM||(fM={}))});var zR=V1((h10,UN)=>{var bP,mP,fP,pP,cP,lP,dP,oP,nP,iP,rP,aP,sP,ZN,II,tP,eP,WR,kG,XR,GR,YR,JR,ZR,VR,UR,QR,NR,VN,qR,HR,AR;(function(W){var X=typeof global==="object"?global:typeof self==="object"?self:typeof this==="object"?this:{};if(typeof define==="function"&&define.amd)define("tslib",["exports"],function(Y){W(G(X,G(Y)))});else if(typeof UN==="object"&&typeof h10==="object")W(G(X,G(h10)));else W(G(X));function G(Y,J){if(Y!==X)if(typeof Object.create==="function")Object.defineProperty(Y,"__esModule",{value:!0});else Y.__esModule=!0;return function(Z,V){return Y[Z]=J?J(Z,V):V}}})(function(W){var X=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]};bP=function(Z,V){if(typeof V!=="function"&&V!==null)throw TypeError("Class extends value "+String(V)+" is not a constructor or null");X(Z,V);function U(){this.constructor=Z}Z.prototype=V===null?Object.create(V):(U.prototype=V.prototype,new U)},mP=Object.assign||function(Z){for(var V,U=1,Q=arguments.length;U<Q;U++){V=arguments[U];for(var N in V)if(Object.prototype.hasOwnProperty.call(V,N))Z[N]=V[N]}return Z},fP=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 N=0,Q=Object.getOwnPropertySymbols(Z);N<Q.length;N++)if(V.indexOf(Q[N])<0&&Object.prototype.propertyIsEnumerable.call(Z,Q[N]))U[Q[N]]=Z[Q[N]]}return U},pP=function(Z,V,U,Q){var N=arguments.length,q=N<3?V:Q===null?Q=Object.getOwnPropertyDescriptor(V,U):Q,A;if(typeof Reflect==="object"&&typeof Reflect.decorate==="function")q=Reflect.decorate(Z,V,U,Q);else for(var H=Z.length-1;H>=0;H--)if(A=Z[H])q=(N<3?A(q):N>3?A(V,U,q):A(V,U))||q;return N>3&&q&&Object.defineProperty(V,U,q),q},cP=function(Z,V){return function(U,Q){V(U,Q,Z)}},lP=function(Z,V,U,Q,N,q){function A(l){if(l!==void 0&&typeof l!=="function")throw TypeError("Function expected");return l}var H=Q.kind,I=H==="getter"?"get":H==="setter"?"set":"value",w=!V&&Z?Q.static?Z:Z.prototype:null,O=V||(w?Object.getOwnPropertyDescriptor(w,Q.name):{}),T,x=!1;for(var h=U.length-1;h>=0;h--){var $={};for(var F in Q)$[F]=F==="access"?{}:Q[F];for(var F in Q.access)$.access[F]=Q.access[F];$.addInitializer=function(l){if(x)throw TypeError("Cannot add initializers after decoration has completed");q.push(A(l||null))};var u=(0,U[h])(H==="accessor"?{get:O.get,set:O.set}:O[I],$);if(H==="accessor"){if(u===void 0)continue;if(u===null||typeof u!=="object")throw TypeError("Object expected");if(T=A(u.get))O.get=T;if(T=A(u.set))O.set=T;if(T=A(u.init))N.unshift(T)}else if(T=A(u))if(H==="field")N.unshift(T);else O[I]=T}if(w)Object.defineProperty(w,Q.name,O);x=!0},dP=function(Z,V,U){var Q=arguments.length>2;for(var N=0;N<V.length;N++)U=Q?V[N].call(Z,U):V[N].call(Z);return Q?U:void 0},oP=function(Z){return typeof Z==="symbol"?Z:"".concat(Z)},nP=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})},iP=function(Z,V){if(typeof Reflect==="object"&&typeof Reflect.metadata==="function")return Reflect.metadata(Z,V)},rP=function(Z,V,U,Q){function N(q){return q instanceof U?q:new U(function(A){A(q)})}return new(U||(U=Promise))(function(q,A){function H(O){try{w(Q.next(O))}catch(T){A(T)}}function I(O){try{w(Q.throw(O))}catch(T){A(T)}}function w(O){O.done?q(O.value):N(O.value).then(H,I)}w((Q=Q.apply(Z,V||[])).next())})},aP=function(Z,V){var U={label:0,sent:function(){if(q[0]&1)throw q[1];return q[1]},trys:[],ops:[]},Q,N,q,A=Object.create((typeof Iterator==="function"?Iterator:Object).prototype);return A.next=H(0),A.throw=H(1),A.return=H(2),typeof Symbol==="function"&&(A[Symbol.iterator]=function(){return this}),A;function H(w){return function(O){return I([w,O])}}function I(w){if(Q)throw TypeError("Generator is already executing.");while(A&&(A=0,w[0]&&(U=0)),U)try{if(Q=1,N&&(q=w[0]&2?N.return:w[0]?N.throw||((q=N.return)&&q.call(N),0):N.next)&&!(q=q.call(N,w[1])).done)return q;if(N=0,q)w=[w[0]&2,q.value];switch(w[0]){case 0:case 1:q=w;break;case 4:return U.label++,{value:w[1],done:!1};case 5:U.label++,N=w[1],w=[0];continue;case 7:w=U.ops.pop(),U.trys.pop();continue;default:if((q=U.trys,!(q=q.length>0&&q[q.length-1]))&&(w[0]===6||w[0]===2)){U=0;continue}if(w[0]===3&&(!q||w[1]>q[0]&&w[1]<q[3])){U.label=w[1];break}if(w[0]===6&&U.label<q[1]){U.label=q[1],q=w;break}if(q&&U.label<q[2]){U.label=q[2],U.ops.push(w);break}if(q[2])U.ops.pop();U.trys.pop();continue}w=V.call(Z,U)}catch(O){w=[6,O],N=0}finally{Q=q=0}if(w[0]&5)throw w[1];return{value:w[0]?w[1]:void 0,done:!0}}},sP=function(Z,V){for(var U in Z)if(U!=="default"&&!Object.prototype.hasOwnProperty.call(V,U))VN(V,Z,U)},VN=Object.create?function(Z,V,U,Q){if(Q===void 0)Q=U;var N=Object.getOwnPropertyDescriptor(V,U);if(!N||("get"in N?!V.__esModule:N.writable||N.configurable))N={enumerable:!0,get:function(){return V[U]}};Object.defineProperty(Z,Q,N)}:function(Z,V,U,Q){if(Q===void 0)Q=U;Z[Q]=V[U]},ZN=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.")},II=function(Z,V){var U=typeof Symbol==="function"&&Z[Symbol.iterator];if(!U)return Z;var Q=U.call(Z),N,q=[],A;try{while((V===void 0||V-- >0)&&!(N=Q.next()).done)q.push(N.value)}catch(H){A={error:H}}finally{try{if(N&&!N.done&&(U=Q.return))U.call(Q)}finally{if(A)throw A.error}}return q},tP=function(){for(var Z=[],V=0;V<arguments.length;V++)Z=Z.concat(II(arguments[V]));return Z},eP=function(){for(var Z=0,V=0,U=arguments.length;V<U;V++)Z+=arguments[V].length;for(var Q=Array(Z),N=0,V=0;V<U;V++)for(var q=arguments[V],A=0,H=q.length;A<H;A++,N++)Q[N]=q[A];return Q},WR=function(Z,V,U){if(U||arguments.length===2){for(var Q=0,N=V.length,q;Q<N;Q++)if(q||!(Q in V)){if(!q)q=Array.prototype.slice.call(V,0,Q);q[Q]=V[Q]}}return Z.concat(q||Array.prototype.slice.call(V))},kG=function(Z){return this instanceof kG?(this.v=Z,this):new kG(Z)},XR=function(Z,V,U){if(!Symbol.asyncIterator)throw TypeError("Symbol.asyncIterator is not defined.");var Q=U.apply(Z,V||[]),N,q=[];return N=Object.create((typeof AsyncIterator==="function"?AsyncIterator:Object).prototype),H("next"),H("throw"),H("return",A),N[Symbol.asyncIterator]=function(){return this},N;function A(h){return function($){return Promise.resolve($).then(h,T)}}function H(h,$){if(Q[h]){if(N[h]=function(F){return new Promise(function(u,l){q.push([h,F,u,l])>1||I(h,F)})},$)N[h]=$(N[h])}}function I(h,$){try{w(Q[h]($))}catch(F){x(q[0][3],F)}}function w(h){h.value instanceof kG?Promise.resolve(h.value.v).then(O,T):x(q[0][2],h)}function O(h){I("next",h)}function T(h){I("throw",h)}function x(h,$){if(h($),q.shift(),q.length)I(q[0][0],q[0][1])}},GR=function(Z){var V,U;return V={},Q("next"),Q("throw",function(N){throw N}),Q("return"),V[Symbol.iterator]=function(){return this},V;function Q(N,q){V[N]=Z[N]?function(A){return(U=!U)?{value:kG(Z[N](A)),done:!1}:q?q(A):A}:q}},YR=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 ZN==="function"?ZN(Z):Z[Symbol.iterator](),U={},Q("next"),Q("throw"),Q("return"),U[Symbol.asyncIterator]=function(){return this},U);function Q(q){U[q]=Z[q]&&function(A){return new Promise(function(H,I){A=Z[q](A),N(H,I,A.done,A.value)})}}function N(q,A,H,I){Promise.resolve(I).then(function(w){q({value:w,done:H})},A)}},JR=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},Y=function(Z){return Y=Object.getOwnPropertyNames||function(V){var U=[];for(var Q in V)if(Object.prototype.hasOwnProperty.call(V,Q))U[U.length]=Q;return U},Y(Z)};ZR=function(Z){if(Z&&Z.__esModule)return Z;var V={};if(Z!=null){for(var U=Y(Z),Q=0;Q<U.length;Q++)if(U[Q]!=="default")VN(V,Z,U[Q])}return G(V,Z),V},VR=function(Z){return Z&&Z.__esModule?Z:{default:Z}},UR=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)},QR=function(Z,V,U,Q,N){if(Q==="m")throw TypeError("Private method is not writable");if(Q==="a"&&!N)throw TypeError("Private accessor was defined without a setter");if(typeof V==="function"?Z!==V||!N:!V.has(Z))throw TypeError("Cannot write private member to an object whose class did not declare it");return Q==="a"?N.call(Z,U):N?N.value=U:V.set(Z,U),U},NR=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)},qR=function(Z,V,U){if(V!==null&&V!==void 0){if(typeof V!=="object"&&typeof V!=="function")throw TypeError("Object expected.");var Q,N;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)N=Q}if(typeof Q!=="function")throw TypeError("Object not disposable.");if(N)Q=function(){try{N.call(this)}catch(q){return Promise.reject(q)}};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};HR=function(Z){function V(q){Z.error=Z.hasError?new J(q,Z.error,"An error was suppressed during disposal."):q,Z.hasError=!0}var U,Q=0;function N(){while(U=Z.stack.pop())try{if(!U.async&&Q===1)return Q=0,Z.stack.push(U),Promise.resolve().then(N);if(U.dispose){var q=U.dispose.call(U.value);if(U.async)return Q|=2,Promise.resolve(q).then(N,function(A){return V(A),N()})}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 N()},AR=function(Z,V){if(typeof Z==="string"&&/^\.\.?\//.test(Z))return Z.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i,function(U,Q,N,q,A){return Q?V?".jsx":".js":N&&(!q||!A)?U:N+q+"."+A.toLowerCase()+"js"});return Z},W("__extends",bP),W("__assign",mP),W("__rest",fP),W("__decorate",pP),W("__param",cP),W("__esDecorate",lP),W("__runInitializers",dP),W("__propKey",oP),W("__setFunctionName",nP),W("__metadata",iP),W("__awaiter",rP),W("__generator",aP),W("__exportStar",sP),W("__createBinding",VN),W("__values",ZN),W("__read",II),W("__spread",tP),W("__spreadArrays",eP),W("__spreadArray",WR),W("__await",kG),W("__asyncGenerator",XR),W("__asyncDelegator",GR),W("__asyncValues",YR),W("__makeTemplateObject",JR),W("__importStar",ZR),W("__importDefault",VR),W("__classPrivateFieldGet",UR),W("__classPrivateFieldSet",QR),W("__classPrivateFieldIn",NR),W("__addDisposableResource",qR),W("__disposeResources",HR),W("__rewriteRelativeImportExtension",AR)})});var RL=V1((sJ0,lN)=>{/*! *****************************************************************************
27
+ ***************************************************************************** */var fM;(function(W){(function(X){var G=typeof globalThis==="object"?globalThis:typeof global==="object"?global:typeof self==="object"?self:typeof this==="object"?this:U(),Y=J(W);if(typeof G.Reflect<"u")Y=J(G.Reflect,Y);if(X(Y,G),typeof G.Reflect>"u")G.Reflect=W;function J(Q,N){return function(q,A){if(Object.defineProperty(Q,q,{configurable:!0,writable:!0,value:A}),N)N(q,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(X,G){var Y=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,N=!U&&!Q,q={create:U?function(){return N1(Object.create(null))}:Q?function(){return N1({__proto__:null})}:function(){return N1({})},has:N?function(c,W0){return Y.call(c,W0)}:function(c,W0){return W0 in c},get:N?function(c,W0){return Y.call(c,W0)?c[W0]:void 0}:function(c,W0){return c[W0]}},A=Object.getPrototypeOf(Function),H=typeof Map==="function"&&typeof Map.prototype.entries==="function"?Map:k1(),I=typeof Set==="function"&&typeof Set.prototype.entries==="function"?Set:W8(),w=typeof WeakMap==="function"?WeakMap:d1(),O=J?Symbol.for("@reflect-metadata:registry"):void 0,T=Q1(),x=X0(T);function h(c,W0,Q0,T0){if(!v(Q0)){if(!v1(c))throw TypeError();if(!J0(W0))throw TypeError();if(!J0(T0)&&!v(T0)&&!R(T0))throw TypeError();if(R(T0))T0=void 0;return Q0=H1(Q0),d(c,W0,Q0,T0)}else{if(!v1(c))throw TypeError();if(!F1(W0))throw TypeError();return g(c,W0)}}X("decorate",h);function $(c,W0){function Q0(T0,e0){if(!J0(T0))throw TypeError();if(!v(e0)&&!S1(e0))throw TypeError();o(c,W0,T0,e0)}return Q0}X("metadata",$);function F(c,W0,Q0,T0){if(!J0(Q0))throw TypeError();if(!v(T0))T0=H1(T0);return o(c,W0,Q0,T0)}X("defineMetadata",F);function u(c,W0,Q0){if(!J0(W0))throw TypeError();if(!v(Q0))Q0=H1(Q0);return P(c,W0,Q0)}X("hasMetadata",u);function l(c,W0,Q0){if(!J0(W0))throw TypeError();if(!v(Q0))Q0=H1(Q0);return E(c,W0,Q0)}X("hasOwnMetadata",l);function f(c,W0,Q0){if(!J0(W0))throw TypeError();if(!v(Q0))Q0=H1(Q0);return p(c,W0,Q0)}X("getMetadata",f);function s(c,W0,Q0){if(!J0(W0))throw TypeError();if(!v(Q0))Q0=H1(Q0);return r(c,W0,Q0)}X("getOwnMetadata",s);function y(c,W0){if(!J0(c))throw TypeError();if(!v(W0))W0=H1(W0);return B(c,W0)}X("getMetadataKeys",y);function t(c,W0){if(!J0(c))throw TypeError();if(!v(W0))W0=H1(W0);return S(c,W0)}X("getOwnMetadataKeys",t);function H0(c,W0,Q0){if(!J0(W0))throw TypeError();if(!v(Q0))Q0=H1(Q0);if(!J0(W0))throw TypeError();if(!v(Q0))Q0=H1(Q0);var T0=x0(W0,Q0,!1);if(v(T0))return!1;return T0.OrdinaryDeleteMetadata(c,W0,Q0)}X("deleteMetadata",H0);function g(c,W0){for(var Q0=c.length-1;Q0>=0;--Q0){var T0=c[Q0],e0=T0(W0);if(!v(e0)&&!R(e0)){if(!F1(e0))throw TypeError();W0=e0}}return W0}function d(c,W0,Q0,T0){for(var e0=c.length-1;e0>=0;--e0){var q8=c[e0],I8=q8(W0,Q0,T0);if(!v(I8)&&!R(I8)){if(!J0(I8))throw TypeError();T0=I8}}return T0}function P(c,W0,Q0){var T0=E(c,W0,Q0);if(T0)return!0;var e0=k0(W0);if(!R(e0))return P(c,e0,Q0);return!1}function E(c,W0,Q0){var T0=x0(W0,Q0,!1);if(v(T0))return!1;return $0(T0.OrdinaryHasOwnMetadata(c,W0,Q0))}function p(c,W0,Q0){var T0=E(c,W0,Q0);if(T0)return r(c,W0,Q0);var e0=k0(W0);if(!R(e0))return p(c,e0,Q0);return}function r(c,W0,Q0){var T0=x0(W0,Q0,!1);if(v(T0))return;return T0.OrdinaryGetOwnMetadata(c,W0,Q0)}function o(c,W0,Q0,T0){var e0=x0(Q0,T0,!0);e0.OrdinaryDefineOwnMetadata(c,W0,Q0,T0)}function B(c,W0){var Q0=S(c,W0),T0=k0(c);if(T0===null)return Q0;var e0=B(T0,W0);if(e0.length<=0)return Q0;if(Q0.length<=0)return e0;var q8=new I,I8=[];for(var C1=0,_0=Q0;C1<_0.length;C1++){var p0=_0[C1],o0=q8.has(p0);if(!o0)q8.add(p0),I8.push(p0)}for(var a0=0,z1=e0;a0<z1.length;a0++){var p0=z1[a0],o0=q8.has(p0);if(!o0)q8.add(p0),I8.push(p0)}return I8}function S(c,W0){var Q0=x0(c,W0,!1);if(!Q0)return[];return Q0.OrdinaryOwnMetadataKeys(c,W0)}function _(c){if(c===null)return 1;switch(typeof c){case"undefined":return 0;case"boolean":return 2;case"string":return 3;case"symbol":return 4;case"number":return 5;case"object":return c===null?1:6;default:return 6}}function v(c){return c===void 0}function R(c){return c===null}function m(c){return typeof c==="symbol"}function J0(c){return typeof c==="object"?c!==null:typeof c==="function"}function U0(c,W0){switch(_(c)){case 0:return c;case 1:return c;case 2:return c;case 3:return c;case 4:return c;case 5:return c}var Q0=W0===3?"string":W0===5?"number":"default",T0=F0(c,Z);if(T0!==void 0){var e0=T0.call(c,Q0);if(J0(e0))throw TypeError();return e0}return q0(c,Q0==="default"?"number":Q0)}function q0(c,W0){if(W0==="string"){var Q0=c.toString;if(h0(Q0)){var T0=Q0.call(c);if(!J0(T0))return T0}var e0=c.valueOf;if(h0(e0)){var T0=e0.call(c);if(!J0(T0))return T0}}else{var e0=c.valueOf;if(h0(e0)){var T0=e0.call(c);if(!J0(T0))return T0}var q8=c.toString;if(h0(q8)){var T0=q8.call(c);if(!J0(T0))return T0}}throw TypeError()}function $0(c){return!!c}function u0(c){return""+c}function H1(c){var W0=U0(c,3);if(m(W0))return W0;return u0(W0)}function v1(c){return Array.isArray?Array.isArray(c):c instanceof Object?c instanceof Array:Object.prototype.toString.call(c)==="[object Array]"}function h0(c){return typeof c==="function"}function F1(c){return typeof c==="function"}function S1(c){switch(_(c)){case 3:return!0;case 4:return!0;default:return!1}}function N0(c,W0){return c===W0||c!==c&&W0!==W0}function F0(c,W0){var Q0=c[W0];if(Q0===void 0||Q0===null)return;if(!h0(Q0))throw TypeError();return Q0}function m0(c){var W0=F0(c,V);if(!h0(W0))throw TypeError();var Q0=W0.call(c);if(!J0(Q0))throw TypeError();return Q0}function Y0(c){return c.value}function K0(c){var W0=c.next();return W0.done?!1:W0}function P0(c){var W0=c.return;if(W0)W0.call(c)}function k0(c){var W0=Object.getPrototypeOf(c);if(typeof c!=="function"||c===A)return W0;if(W0!==A)return W0;var Q0=c.prototype,T0=Q0&&Object.getPrototypeOf(Q0);if(T0==null||T0===Object.prototype)return W0;var e0=T0.constructor;if(typeof e0!=="function")return W0;if(e0===c)return W0;return e0}function R1(){var c;if(!v(O)&&typeof G.Reflect<"u"&&!(O in G.Reflect)&&typeof G.Reflect.defineMetadata==="function")c=C0(G.Reflect);var W0,Q0,T0,e0=new w,q8={registerProvider:I8,getProvider:_0,setProvider:o0};return q8;function I8(a0){if(!Object.isExtensible(q8))throw Error("Cannot add provider to a frozen registry.");switch(!0){case c===a0:break;case v(W0):W0=a0;break;case W0===a0:break;case v(Q0):Q0=a0;break;case Q0===a0:break;default:if(T0===void 0)T0=new I;T0.add(a0);break}}function C1(a0,z1){if(!v(W0)){if(W0.isProviderFor(a0,z1))return W0;if(!v(Q0)){if(Q0.isProviderFor(a0,z1))return W0;if(!v(T0)){var o1=m0(T0);while(!0){var Z8=K0(o1);if(!Z8)return;var S9=Y0(Z8);if(S9.isProviderFor(a0,z1))return P0(o1),S9}}}}if(!v(c)&&c.isProviderFor(a0,z1))return c;return}function _0(a0,z1){var o1=e0.get(a0),Z8;if(!v(o1))Z8=o1.get(z1);if(!v(Z8))return Z8;if(Z8=C1(a0,z1),!v(Z8)){if(v(o1))o1=new H,e0.set(a0,o1);o1.set(z1,Z8)}return Z8}function p0(a0){if(v(a0))throw TypeError();return W0===a0||Q0===a0||!v(T0)&&T0.has(a0)}function o0(a0,z1,o1){if(!p0(o1))throw Error("Metadata provider not registered.");var Z8=_0(a0,z1);if(Z8!==o1){if(!v(Z8))return!1;var S9=e0.get(a0);if(v(S9))S9=new H,e0.set(a0,S9);S9.set(z1,o1)}return!0}}function Q1(){var c;if(!v(O)&&J0(G.Reflect)&&Object.isExtensible(G.Reflect))c=G.Reflect[O];if(v(c))c=R1();if(!v(O)&&J0(G.Reflect)&&Object.isExtensible(G.Reflect))Object.defineProperty(G.Reflect,O,{enumerable:!1,configurable:!1,writable:!1,value:c});return c}function X0(c){var W0=new w,Q0={isProviderFor:function(p0,o0){var a0=W0.get(p0);if(v(a0))return!1;return a0.has(o0)},OrdinaryDefineOwnMetadata:I8,OrdinaryHasOwnMetadata:e0,OrdinaryGetOwnMetadata:q8,OrdinaryOwnMetadataKeys:C1,OrdinaryDeleteMetadata:_0};return T.registerProvider(Q0),Q0;function T0(p0,o0,a0){var z1=W0.get(p0),o1=!1;if(v(z1)){if(!a0)return;z1=new H,W0.set(p0,z1),o1=!0}var Z8=z1.get(o0);if(v(Z8)){if(!a0)return;if(Z8=new H,z1.set(o0,Z8),!c.setProvider(p0,o0,Q0)){if(z1.delete(o0),o1)W0.delete(p0);throw Error("Wrong provider for target.")}}return Z8}function e0(p0,o0,a0){var z1=T0(o0,a0,!1);if(v(z1))return!1;return $0(z1.has(p0))}function q8(p0,o0,a0){var z1=T0(o0,a0,!1);if(v(z1))return;return z1.get(p0)}function I8(p0,o0,a0,z1){var o1=T0(a0,z1,!0);o1.set(p0,o0)}function C1(p0,o0){var a0=[],z1=T0(p0,o0,!1);if(v(z1))return a0;var o1=z1.keys(),Z8=m0(o1),S9=0;while(!0){var lX=K0(Z8);if(!lX)return a0.length=S9,a0;var vU=Y0(lX);try{a0[S9]=vU}catch(HA){try{P0(Z8)}finally{throw HA}}S9++}}function _0(p0,o0,a0){var z1=T0(o0,a0,!1);if(v(z1))return!1;if(!z1.delete(p0))return!1;if(z1.size===0){var o1=W0.get(o0);if(!v(o1)){if(o1.delete(a0),o1.size===0)W0.delete(o1)}}return!0}}function C0(c){var{defineMetadata:W0,hasOwnMetadata:Q0,getOwnMetadata:T0,getOwnMetadataKeys:e0,deleteMetadata:q8}=c,I8=new w,C1={isProviderFor:function(_0,p0){var o0=I8.get(_0);if(!v(o0)&&o0.has(p0))return!0;if(e0(_0,p0).length){if(v(o0))o0=new I,I8.set(_0,o0);return o0.add(p0),!0}return!1},OrdinaryDefineOwnMetadata:W0,OrdinaryHasOwnMetadata:Q0,OrdinaryGetOwnMetadata:T0,OrdinaryOwnMetadataKeys:e0,OrdinaryDeleteMetadata:q8};return C1}function x0(c,W0,Q0){var T0=T.getProvider(c,W0);if(!v(T0))return T0;if(Q0){if(T.setProvider(c,W0,x))return x;throw Error("Illegal state.")}return}function k1(){var c={},W0=[],Q0=function(){function C1(_0,p0,o0){this._index=0,this._keys=_0,this._values=p0,this._selector=o0}return C1.prototype["@@iterator"]=function(){return this},C1.prototype[V]=function(){return this},C1.prototype.next=function(){var _0=this._index;if(_0>=0&&_0<this._keys.length){var p0=this._selector(this._keys[_0],this._values[_0]);if(_0+1>=this._keys.length)this._index=-1,this._keys=W0,this._values=W0;else this._index++;return{value:p0,done:!1}}return{value:void 0,done:!0}},C1.prototype.throw=function(_0){if(this._index>=0)this._index=-1,this._keys=W0,this._values=W0;throw _0},C1.prototype.return=function(_0){if(this._index>=0)this._index=-1,this._keys=W0,this._values=W0;return{value:_0,done:!0}},C1}(),T0=function(){function C1(){this._keys=[],this._values=[],this._cacheKey=c,this._cacheIndex=-2}return Object.defineProperty(C1.prototype,"size",{get:function(){return this._keys.length},enumerable:!0,configurable:!0}),C1.prototype.has=function(_0){return this._find(_0,!1)>=0},C1.prototype.get=function(_0){var p0=this._find(_0,!1);return p0>=0?this._values[p0]:void 0},C1.prototype.set=function(_0,p0){var o0=this._find(_0,!0);return this._values[o0]=p0,this},C1.prototype.delete=function(_0){var p0=this._find(_0,!1);if(p0>=0){var o0=this._keys.length;for(var a0=p0+1;a0<o0;a0++)this._keys[a0-1]=this._keys[a0],this._values[a0-1]=this._values[a0];if(this._keys.length--,this._values.length--,N0(_0,this._cacheKey))this._cacheKey=c,this._cacheIndex=-2;return!0}return!1},C1.prototype.clear=function(){this._keys.length=0,this._values.length=0,this._cacheKey=c,this._cacheIndex=-2},C1.prototype.keys=function(){return new Q0(this._keys,this._values,e0)},C1.prototype.values=function(){return new Q0(this._keys,this._values,q8)},C1.prototype.entries=function(){return new Q0(this._keys,this._values,I8)},C1.prototype["@@iterator"]=function(){return this.entries()},C1.prototype[V]=function(){return this.entries()},C1.prototype._find=function(_0,p0){if(!N0(this._cacheKey,_0)){this._cacheIndex=-1;for(var o0=0;o0<this._keys.length;o0++)if(N0(this._keys[o0],_0)){this._cacheIndex=o0;break}}if(this._cacheIndex<0&&p0)this._cacheIndex=this._keys.length,this._keys.push(_0),this._values.push(void 0);return this._cacheIndex},C1}();return T0;function e0(C1,_0){return C1}function q8(C1,_0){return _0}function I8(C1,_0){return[C1,_0]}}function W8(){var c=function(){function W0(){this._map=new H}return Object.defineProperty(W0.prototype,"size",{get:function(){return this._map.size},enumerable:!0,configurable:!0}),W0.prototype.has=function(Q0){return this._map.has(Q0)},W0.prototype.add=function(Q0){return this._map.set(Q0,Q0),this},W0.prototype.delete=function(Q0){return this._map.delete(Q0)},W0.prototype.clear=function(){this._map.clear()},W0.prototype.keys=function(){return this._map.keys()},W0.prototype.values=function(){return this._map.keys()},W0.prototype.entries=function(){return this._map.entries()},W0.prototype["@@iterator"]=function(){return this.keys()},W0.prototype[V]=function(){return this.keys()},W0}();return c}function d1(){var c=16,W0=q.create(),Q0=T0();return function(){function _0(){this._key=T0()}return _0.prototype.has=function(p0){var o0=e0(p0,!1);return o0!==void 0?q.has(o0,this._key):!1},_0.prototype.get=function(p0){var o0=e0(p0,!1);return o0!==void 0?q.get(o0,this._key):void 0},_0.prototype.set=function(p0,o0){var a0=e0(p0,!0);return a0[this._key]=o0,this},_0.prototype.delete=function(p0){var o0=e0(p0,!1);return o0!==void 0?delete o0[this._key]:!1},_0.prototype.clear=function(){this._key=T0()},_0}();function T0(){var _0;do _0="@@WeakMap@@"+C1();while(q.has(W0,_0));return W0[_0]=!0,_0}function e0(_0,p0){if(!Y.call(_0,Q0)){if(!p0)return;Object.defineProperty(_0,Q0,{value:q.create()})}return _0[Q0]}function q8(_0,p0){for(var o0=0;o0<p0;++o0)_0[o0]=Math.random()*255|0;return _0}function I8(_0){if(typeof Uint8Array==="function"){var p0=new Uint8Array(_0);if(typeof crypto<"u")crypto.getRandomValues(p0);else if(typeof msCrypto<"u")msCrypto.getRandomValues(p0);else q8(p0,_0);return p0}return q8(Array(_0),_0)}function C1(){var _0=I8(c);_0[6]=_0[6]&79|64,_0[8]=_0[8]&191|128;var p0="";for(var o0=0;o0<c;++o0){var a0=_0[o0];if(o0===4||o0===6||o0===8)p0+="-";if(a0<16)p0+="0";p0+=a0.toString(16).toLowerCase()}return p0}}function N1(c){return c.__=void 0,delete c.__,c}})})(fM||(fM={}))});var zR=V1((h10,UN)=>{var bP,mP,fP,pP,cP,lP,dP,oP,nP,iP,rP,aP,sP,ZN,II,tP,eP,WR,kG,XR,GR,YR,JR,ZR,VR,UR,QR,NR,VN,qR,HR,AR;(function(W){var X=typeof global==="object"?global:typeof self==="object"?self:typeof this==="object"?this:{};if(typeof define==="function"&&define.amd)define("tslib",["exports"],function(Y){W(G(X,G(Y)))});else if(typeof UN==="object"&&typeof h10==="object")W(G(X,G(h10)));else W(G(X));function G(Y,J){if(Y!==X)if(typeof Object.create==="function")Object.defineProperty(Y,"__esModule",{value:!0});else Y.__esModule=!0;return function(Z,V){return Y[Z]=J?J(Z,V):V}}})(function(W){var X=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]};bP=function(Z,V){if(typeof V!=="function"&&V!==null)throw TypeError("Class extends value "+String(V)+" is not a constructor or null");X(Z,V);function U(){this.constructor=Z}Z.prototype=V===null?Object.create(V):(U.prototype=V.prototype,new U)},mP=Object.assign||function(Z){for(var V,U=1,Q=arguments.length;U<Q;U++){V=arguments[U];for(var N in V)if(Object.prototype.hasOwnProperty.call(V,N))Z[N]=V[N]}return Z},fP=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 N=0,Q=Object.getOwnPropertySymbols(Z);N<Q.length;N++)if(V.indexOf(Q[N])<0&&Object.prototype.propertyIsEnumerable.call(Z,Q[N]))U[Q[N]]=Z[Q[N]]}return U},pP=function(Z,V,U,Q){var N=arguments.length,q=N<3?V:Q===null?Q=Object.getOwnPropertyDescriptor(V,U):Q,A;if(typeof Reflect==="object"&&typeof Reflect.decorate==="function")q=Reflect.decorate(Z,V,U,Q);else for(var H=Z.length-1;H>=0;H--)if(A=Z[H])q=(N<3?A(q):N>3?A(V,U,q):A(V,U))||q;return N>3&&q&&Object.defineProperty(V,U,q),q},cP=function(Z,V){return function(U,Q){V(U,Q,Z)}},lP=function(Z,V,U,Q,N,q){function A(l){if(l!==void 0&&typeof l!=="function")throw TypeError("Function expected");return l}var H=Q.kind,I=H==="getter"?"get":H==="setter"?"set":"value",w=!V&&Z?Q.static?Z:Z.prototype:null,O=V||(w?Object.getOwnPropertyDescriptor(w,Q.name):{}),T,x=!1;for(var h=U.length-1;h>=0;h--){var $={};for(var F in Q)$[F]=F==="access"?{}:Q[F];for(var F in Q.access)$.access[F]=Q.access[F];$.addInitializer=function(l){if(x)throw TypeError("Cannot add initializers after decoration has completed");q.push(A(l||null))};var u=(0,U[h])(H==="accessor"?{get:O.get,set:O.set}:O[I],$);if(H==="accessor"){if(u===void 0)continue;if(u===null||typeof u!=="object")throw TypeError("Object expected");if(T=A(u.get))O.get=T;if(T=A(u.set))O.set=T;if(T=A(u.init))N.unshift(T)}else if(T=A(u))if(H==="field")N.unshift(T);else O[I]=T}if(w)Object.defineProperty(w,Q.name,O);x=!0},dP=function(Z,V,U){var Q=arguments.length>2;for(var N=0;N<V.length;N++)U=Q?V[N].call(Z,U):V[N].call(Z);return Q?U:void 0},oP=function(Z){return typeof Z==="symbol"?Z:"".concat(Z)},nP=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})},iP=function(Z,V){if(typeof Reflect==="object"&&typeof Reflect.metadata==="function")return Reflect.metadata(Z,V)},rP=function(Z,V,U,Q){function N(q){return q instanceof U?q:new U(function(A){A(q)})}return new(U||(U=Promise))(function(q,A){function H(O){try{w(Q.next(O))}catch(T){A(T)}}function I(O){try{w(Q.throw(O))}catch(T){A(T)}}function w(O){O.done?q(O.value):N(O.value).then(H,I)}w((Q=Q.apply(Z,V||[])).next())})},aP=function(Z,V){var U={label:0,sent:function(){if(q[0]&1)throw q[1];return q[1]},trys:[],ops:[]},Q,N,q,A=Object.create((typeof Iterator==="function"?Iterator:Object).prototype);return A.next=H(0),A.throw=H(1),A.return=H(2),typeof Symbol==="function"&&(A[Symbol.iterator]=function(){return this}),A;function H(w){return function(O){return I([w,O])}}function I(w){if(Q)throw TypeError("Generator is already executing.");while(A&&(A=0,w[0]&&(U=0)),U)try{if(Q=1,N&&(q=w[0]&2?N.return:w[0]?N.throw||((q=N.return)&&q.call(N),0):N.next)&&!(q=q.call(N,w[1])).done)return q;if(N=0,q)w=[w[0]&2,q.value];switch(w[0]){case 0:case 1:q=w;break;case 4:return U.label++,{value:w[1],done:!1};case 5:U.label++,N=w[1],w=[0];continue;case 7:w=U.ops.pop(),U.trys.pop();continue;default:if((q=U.trys,!(q=q.length>0&&q[q.length-1]))&&(w[0]===6||w[0]===2)){U=0;continue}if(w[0]===3&&(!q||w[1]>q[0]&&w[1]<q[3])){U.label=w[1];break}if(w[0]===6&&U.label<q[1]){U.label=q[1],q=w;break}if(q&&U.label<q[2]){U.label=q[2],U.ops.push(w);break}if(q[2])U.ops.pop();U.trys.pop();continue}w=V.call(Z,U)}catch(O){w=[6,O],N=0}finally{Q=q=0}if(w[0]&5)throw w[1];return{value:w[0]?w[1]:void 0,done:!0}}},sP=function(Z,V){for(var U in Z)if(U!=="default"&&!Object.prototype.hasOwnProperty.call(V,U))VN(V,Z,U)},VN=Object.create?function(Z,V,U,Q){if(Q===void 0)Q=U;var N=Object.getOwnPropertyDescriptor(V,U);if(!N||("get"in N?!V.__esModule:N.writable||N.configurable))N={enumerable:!0,get:function(){return V[U]}};Object.defineProperty(Z,Q,N)}:function(Z,V,U,Q){if(Q===void 0)Q=U;Z[Q]=V[U]},ZN=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.")},II=function(Z,V){var U=typeof Symbol==="function"&&Z[Symbol.iterator];if(!U)return Z;var Q=U.call(Z),N,q=[],A;try{while((V===void 0||V-- >0)&&!(N=Q.next()).done)q.push(N.value)}catch(H){A={error:H}}finally{try{if(N&&!N.done&&(U=Q.return))U.call(Q)}finally{if(A)throw A.error}}return q},tP=function(){for(var Z=[],V=0;V<arguments.length;V++)Z=Z.concat(II(arguments[V]));return Z},eP=function(){for(var Z=0,V=0,U=arguments.length;V<U;V++)Z+=arguments[V].length;for(var Q=Array(Z),N=0,V=0;V<U;V++)for(var q=arguments[V],A=0,H=q.length;A<H;A++,N++)Q[N]=q[A];return Q},WR=function(Z,V,U){if(U||arguments.length===2){for(var Q=0,N=V.length,q;Q<N;Q++)if(q||!(Q in V)){if(!q)q=Array.prototype.slice.call(V,0,Q);q[Q]=V[Q]}}return Z.concat(q||Array.prototype.slice.call(V))},kG=function(Z){return this instanceof kG?(this.v=Z,this):new kG(Z)},XR=function(Z,V,U){if(!Symbol.asyncIterator)throw TypeError("Symbol.asyncIterator is not defined.");var Q=U.apply(Z,V||[]),N,q=[];return N=Object.create((typeof AsyncIterator==="function"?AsyncIterator:Object).prototype),H("next"),H("throw"),H("return",A),N[Symbol.asyncIterator]=function(){return this},N;function A(h){return function($){return Promise.resolve($).then(h,T)}}function H(h,$){if(Q[h]){if(N[h]=function(F){return new Promise(function(u,l){q.push([h,F,u,l])>1||I(h,F)})},$)N[h]=$(N[h])}}function I(h,$){try{w(Q[h]($))}catch(F){x(q[0][3],F)}}function w(h){h.value instanceof kG?Promise.resolve(h.value.v).then(O,T):x(q[0][2],h)}function O(h){I("next",h)}function T(h){I("throw",h)}function x(h,$){if(h($),q.shift(),q.length)I(q[0][0],q[0][1])}},GR=function(Z){var V,U;return V={},Q("next"),Q("throw",function(N){throw N}),Q("return"),V[Symbol.iterator]=function(){return this},V;function Q(N,q){V[N]=Z[N]?function(A){return(U=!U)?{value:kG(Z[N](A)),done:!1}:q?q(A):A}:q}},YR=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 ZN==="function"?ZN(Z):Z[Symbol.iterator](),U={},Q("next"),Q("throw"),Q("return"),U[Symbol.asyncIterator]=function(){return this},U);function Q(q){U[q]=Z[q]&&function(A){return new Promise(function(H,I){A=Z[q](A),N(H,I,A.done,A.value)})}}function N(q,A,H,I){Promise.resolve(I).then(function(w){q({value:w,done:H})},A)}},JR=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},Y=function(Z){return Y=Object.getOwnPropertyNames||function(V){var U=[];for(var Q in V)if(Object.prototype.hasOwnProperty.call(V,Q))U[U.length]=Q;return U},Y(Z)};ZR=function(Z){if(Z&&Z.__esModule)return Z;var V={};if(Z!=null){for(var U=Y(Z),Q=0;Q<U.length;Q++)if(U[Q]!=="default")VN(V,Z,U[Q])}return G(V,Z),V},VR=function(Z){return Z&&Z.__esModule?Z:{default:Z}},UR=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)},QR=function(Z,V,U,Q,N){if(Q==="m")throw TypeError("Private method is not writable");if(Q==="a"&&!N)throw TypeError("Private accessor was defined without a setter");if(typeof V==="function"?Z!==V||!N:!V.has(Z))throw TypeError("Cannot write private member to an object whose class did not declare it");return Q==="a"?N.call(Z,U):N?N.value=U:V.set(Z,U),U},NR=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)},qR=function(Z,V,U){if(V!==null&&V!==void 0){if(typeof V!=="object"&&typeof V!=="function")throw TypeError("Object expected.");var Q,N;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)N=Q}if(typeof Q!=="function")throw TypeError("Object not disposable.");if(N)Q=function(){try{N.call(this)}catch(q){return Promise.reject(q)}};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};HR=function(Z){function V(q){Z.error=Z.hasError?new J(q,Z.error,"An error was suppressed during disposal."):q,Z.hasError=!0}var U,Q=0;function N(){while(U=Z.stack.pop())try{if(!U.async&&Q===1)return Q=0,Z.stack.push(U),Promise.resolve().then(N);if(U.dispose){var q=U.dispose.call(U.value);if(U.async)return Q|=2,Promise.resolve(q).then(N,function(A){return V(A),N()})}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 N()},AR=function(Z,V){if(typeof Z==="string"&&/^\.\.?\//.test(Z))return Z.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i,function(U,Q,N,q,A){return Q?V?".jsx":".js":N&&(!q||!A)?U:N+q+"."+A.toLowerCase()+"js"});return Z},W("__extends",bP),W("__assign",mP),W("__rest",fP),W("__decorate",pP),W("__param",cP),W("__esDecorate",lP),W("__runInitializers",dP),W("__propKey",oP),W("__setFunctionName",nP),W("__metadata",iP),W("__awaiter",rP),W("__generator",aP),W("__exportStar",sP),W("__createBinding",VN),W("__values",ZN),W("__read",II),W("__spread",tP),W("__spreadArrays",eP),W("__spreadArray",WR),W("__await",kG),W("__asyncGenerator",XR),W("__asyncDelegator",GR),W("__asyncValues",YR),W("__makeTemplateObject",JR),W("__importStar",ZR),W("__importDefault",VR),W("__classPrivateFieldGet",UR),W("__classPrivateFieldSet",QR),W("__classPrivateFieldIn",NR),W("__addDisposableResource",qR),W("__disposeResources",HR),W("__rewriteRelativeImportExtension",AR)})});var RL=V1((sJ0,lN)=>{/*! *****************************************************************************
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
- `),Qq.prototype[W]=X.toFunction({assertSize:Bj})});IE.exports=Qq;function Bj(W,X){if(W>X)throw new Xl(W,X)}});var D8=V1((Aq0,PE)=>{var Ej=jV(),Gl=nB(),Yl=sB(),Jl=eB(),Zl=XE(),Vl=JE(),jE=VE(),Ul=QE(),Ql=HE(),{encode:DE}=OV(),{decode:CE}=jY(),{encodingLength:Nl}=DV(),ql=wE(),TE=IY(),ME={array:Gl,bool:Jl,buffer:Yl,reserved:Zl,string:Vl,when:Ul,select:Ql};for(let W of Object.keys(jE))ME[W]=jE[W];var Nq=Symbol("schema");function KE(W){let X=new Ej({readableObjectMode:!1,writableObjectMode:!0,transform:Hl});return X[Nq]=W,X}function OE(W){let X=null,G=Buffer.isBuffer(W);if(!G)X=W;let Y=new Ej({transform:Al,readableObjectMode:!0,writableObjectMode:!1});if(Y[Nq]=X,G)Y.append(W);return Y}function Hl(W,X,G){try{DE(W,this[Nq],this);let Y=this.slice();this.consume(Y.length),G(null,Y)}catch(Y){G(Y)}}function Al(W,X,G){this.append(W);try{while(this.length>0){let Y=new ql(this),J=CE(Y,this[Nq]);Y.commit(),this.push(J)}G()}catch(Y){if(Y instanceof TE)G();else G(Y)}}PE.exports={createEncodeStream:KE,createDecodeStream:OE,encode:DE,decode:CE,encodingLength:Nl,createEncode:KE,createDecode:OE,types:ME,BinaryStream:Ej,NotEnoughDataError:TE}});var M$=V1((C$)=>{Object.defineProperty(C$,"__esModule",{value:!0});C$.LEB128=C$.SignedLEB128=C$.UnsignedLEB128=void 0;var PY;(function(W){W[W.LOWER_7=127]="LOWER_7",W[W.UPPER_1=128]="UPPER_1"})(PY||(PY={}));var D$=(W)=>Number.isSafeInteger(W);class RY{static decode(W,X=0){let G=this.$scanForNullBytes(W,X),Y=0,J=0;for(let Z=0;Z<=G-X;Z++){let V=W[X+Z]&PY.LOWER_7;Y|=V<<J,J+=7}return Y}static encode(W){if(this.check(W),W<0)throw Error(`An unsigned number must NOT be negative, ${W} is!`);let X=[],G=W;do{let Y=G&PY.LOWER_7;if(G>>=7,G)Y=Y|PY.UPPER_1;X.push(Y)}while(G);return Uint8Array.from(X)}static check(W){if(!D$(W))throw Error(`${W} is not a safe integer!`)}static $scanForNullBytes(W,X=0){let G=X,Y=0;do{if(G>=W.byteLength)throw Error("This is not a LEB128-encoded Uint8Array, no ending found!");Y=W.slice(G,G+1)[0],G++}while(Y&PY.UPPER_1);return G-1}static getLength(W,X=0){return this.$scanForNullBytes(W,X)-X}}C$.UnsignedLEB128=RY;class Pq{static $ceil7mul(W){let X=W;while(X%7)X++;return X}static check(W){if(!D$(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 X=Math.ceil(Math.log2(-W));return RY.encode((1<<this.$ceil7mul(X))+W)}static decode(W,X=0){let G=RY.decode(W,X);return-((1<<Math.ceil(Math.log2(G)))-G)}}C$.SignedLEB128=Pq;class Rq{}C$.LEB128=Rq;Rq.encode=(W)=>(W>=0?RY:Pq).encode(W);Rq.decode=(W,X=0,G=!1)=>(G?Pq:RY).decode(W,X)});var R$=V1((ij,P$)=>{/*! MIT License. Copyright 2015-2018 Richard Moore <me@ricmoo.com>. See LICENSE.txt. */(function(W){function X(B){return parseInt(B)===B}function G(B){if(!X(B.length))return!1;for(var S=0;S<B.length;S++)if(!X(B[S])||B[S]<0||B[S]>255)return!1;return!0}function Y(B,S){if(B.buffer&&B.name==="Uint8Array"){if(S)if(B.slice)B=B.slice();else B=Array.prototype.slice.call(B);return B}if(Array.isArray(B)){if(!G(B))throw Error("Array contains invalid value: "+B);return new Uint8Array(B)}if(X(B.length)&&G(B))return new Uint8Array(B);throw Error("unsupported array-like object")}function J(B){return new Uint8Array(B)}function Z(B,S,_,v,R){if(v!=null||R!=null)if(B.slice)B=B.slice(v,R);else B=Array.prototype.slice.call(B,v,R);S.set(B,_)}var V=function(){function B(_){var v=[],R=0;_=encodeURI(_);while(R<_.length){var m=_.charCodeAt(R++);if(m===37)v.push(parseInt(_.substr(R,2),16)),R+=2;else v.push(m)}return Y(v)}function S(_){var v=[],R=0;while(R<_.length){var m=_[R];if(m<128)v.push(String.fromCharCode(m)),R++;else if(m>191&&m<224)v.push(String.fromCharCode((m&31)<<6|_[R+1]&63)),R+=2;else v.push(String.fromCharCode((m&15)<<12|(_[R+1]&63)<<6|_[R+2]&63)),R+=3}return v.join("")}return{toBytes:B,fromBytes:S}}(),U=function(){function B(v){var R=[];for(var m=0;m<v.length;m+=2)R.push(parseInt(v.substr(m,2),16));return R}var S="0123456789abcdef";function _(v){var R=[];for(var m=0;m<v.length;m++){var J0=v[m];R.push(S[(J0&240)>>4]+S[J0&15])}return R.join("")}return{toBytes:B,fromBytes:_}}(),Q={16:10,24:12,32:14},N=[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],q=[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],H=[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],I=[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],O=[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],h=[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],$=[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],F=[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],u=[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],l=[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],p=[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 s(B){var S=[];for(var _=0;_<B.length;_+=4)S.push(B[_]<<24|B[_+1]<<16|B[_+2]<<8|B[_+3]);return S}var y=function(B){if(!(this instanceof y))throw Error("AES must be instanitated with `new`");Object.defineProperty(this,"key",{value:Y(B,!0)}),this._prepare()};y.prototype._prepare=function(){var B=Q[this.key.length];if(B==null)throw Error("invalid key size (must be 16, 24 or 32 bytes)");this._Ke=[],this._Kd=[];for(var S=0;S<=B;S++)this._Ke.push([0,0,0,0]),this._Kd.push([0,0,0,0]);var _=(B+1)*4,v=this.key.length/4,R=s(this.key),m;for(var S=0;S<v;S++)m=S>>2,this._Ke[m][S%4]=R[S],this._Kd[B-m][S%4]=R[S];var J0=0,U0=v,q0;while(U0<_){if(q0=R[v-1],R[0]^=q[q0>>16&255]<<24^q[q0>>8&255]<<16^q[q0&255]<<8^q[q0>>24&255]^N[J0]<<24,J0+=1,v!=8)for(var S=1;S<v;S++)R[S]^=R[S-1];else{for(var S=1;S<v/2;S++)R[S]^=R[S-1];q0=R[v/2-1],R[v/2]^=q[q0&255]^q[q0>>8&255]<<8^q[q0>>16&255]<<16^q[q0>>24&255]<<24;for(var S=v/2+1;S<v;S++)R[S]^=R[S-1]}var S=0,$0,u0;while(S<v&&U0<_)$0=U0>>2,u0=U0%4,this._Ke[$0][u0]=R[S],this._Kd[B-$0][u0]=R[S++],U0++}for(var $0=1;$0<B;$0++)for(var u0=0;u0<4;u0++)q0=this._Kd[$0][u0],this._Kd[$0][u0]=F[q0>>24&255]^u[q0>>16&255]^l[q0>>8&255]^p[q0&255]},y.prototype.encrypt=function(B){if(B.length!=16)throw Error("invalid plaintext size (must be 16 bytes)");var S=this._Ke.length-1,_=[0,0,0,0],v=s(B);for(var R=0;R<4;R++)v[R]^=this._Ke[0][R];for(var m=1;m<S;m++){for(var R=0;R<4;R++)_[R]=H[v[R]>>24&255]^I[v[(R+1)%4]>>16&255]^w[v[(R+2)%4]>>8&255]^O[v[(R+3)%4]&255]^this._Ke[m][R];v=_.slice()}var J0=J(16),U0;for(var R=0;R<4;R++)U0=this._Ke[S][R],J0[4*R]=(q[v[R]>>24&255]^U0>>24)&255,J0[4*R+1]=(q[v[(R+1)%4]>>16&255]^U0>>16)&255,J0[4*R+2]=(q[v[(R+2)%4]>>8&255]^U0>>8)&255,J0[4*R+3]=(q[v[(R+3)%4]&255]^U0)&255;return J0},y.prototype.decrypt=function(B){if(B.length!=16)throw Error("invalid ciphertext size (must be 16 bytes)");var S=this._Kd.length-1,_=[0,0,0,0],v=s(B);for(var R=0;R<4;R++)v[R]^=this._Kd[0][R];for(var m=1;m<S;m++){for(var R=0;R<4;R++)_[R]=T[v[R]>>24&255]^x[v[(R+3)%4]>>16&255]^h[v[(R+2)%4]>>8&255]^$[v[(R+1)%4]&255]^this._Kd[m][R];v=_.slice()}var J0=J(16),U0;for(var R=0;R<4;R++)U0=this._Kd[S][R],J0[4*R]=(A[v[R]>>24&255]^U0>>24)&255,J0[4*R+1]=(A[v[(R+3)%4]>>16&255]^U0>>16)&255,J0[4*R+2]=(A[v[(R+2)%4]>>8&255]^U0>>8)&255,J0[4*R+3]=(A[v[(R+1)%4]&255]^U0)&255;return J0};var t=function(B){if(!(this instanceof t))throw Error("AES must be instanitated with `new`");this.description="Electronic Code Block",this.name="ecb",this._aes=new y(B)};t.prototype.encrypt=function(B){if(B=Y(B),B.length%16!==0)throw Error("invalid plaintext size (must be multiple of 16 bytes)");var S=J(B.length),_=J(16);for(var v=0;v<B.length;v+=16)Z(B,_,0,v,v+16),_=this._aes.encrypt(_),Z(_,S,v);return S},t.prototype.decrypt=function(B){if(B=Y(B),B.length%16!==0)throw Error("invalid ciphertext size (must be multiple of 16 bytes)");var S=J(B.length),_=J(16);for(var v=0;v<B.length;v+=16)Z(B,_,0,v,v+16),_=this._aes.decrypt(_),Z(_,S,v);return S};var H0=function(B,S){if(!(this instanceof H0))throw Error("AES must be instanitated with `new`");if(this.description="Cipher Block Chaining",this.name="cbc",!S)S=J(16);else if(S.length!=16)throw Error("invalid initialation vector size (must be 16 bytes)");this._lastCipherblock=Y(S,!0),this._aes=new y(B)};H0.prototype.encrypt=function(B){if(B=Y(B),B.length%16!==0)throw Error("invalid plaintext size (must be multiple of 16 bytes)");var S=J(B.length),_=J(16);for(var v=0;v<B.length;v+=16){Z(B,_,0,v,v+16);for(var R=0;R<16;R++)_[R]^=this._lastCipherblock[R];this._lastCipherblock=this._aes.encrypt(_),Z(this._lastCipherblock,S,v)}return S},H0.prototype.decrypt=function(B){if(B=Y(B),B.length%16!==0)throw Error("invalid ciphertext size (must be multiple of 16 bytes)");var S=J(B.length),_=J(16);for(var v=0;v<B.length;v+=16){Z(B,_,0,v,v+16),_=this._aes.decrypt(_);for(var R=0;R<16;R++)S[v+R]=_[R]^this._lastCipherblock[R];Z(B,this._lastCipherblock,0,v,v+16)}return S};var g=function(B,S,_){if(!(this instanceof g))throw Error("AES must be instanitated with `new`");if(this.description="Cipher Feedback",this.name="cfb",!S)S=J(16);else if(S.length!=16)throw Error("invalid initialation vector size (must be 16 size)");if(!_)_=1;this.segmentSize=_,this._shiftRegister=Y(S,!0),this._aes=new y(B)};g.prototype.encrypt=function(B){if(B.length%this.segmentSize!=0)throw Error("invalid plaintext size (must be segmentSize bytes)");var S=Y(B,!0),_;for(var v=0;v<S.length;v+=this.segmentSize){_=this._aes.encrypt(this._shiftRegister);for(var R=0;R<this.segmentSize;R++)S[v+R]^=_[R];Z(this._shiftRegister,this._shiftRegister,0,this.segmentSize),Z(S,this._shiftRegister,16-this.segmentSize,v,v+this.segmentSize)}return S},g.prototype.decrypt=function(B){if(B.length%this.segmentSize!=0)throw Error("invalid ciphertext size (must be segmentSize bytes)");var S=Y(B,!0),_;for(var v=0;v<S.length;v+=this.segmentSize){_=this._aes.encrypt(this._shiftRegister);for(var R=0;R<this.segmentSize;R++)S[v+R]^=_[R];Z(this._shiftRegister,this._shiftRegister,0,this.segmentSize),Z(B,this._shiftRegister,16-this.segmentSize,v,v+this.segmentSize)}return S};var d=function(B,S){if(!(this instanceof d))throw Error("AES must be instanitated with `new`");if(this.description="Output Feedback",this.name="ofb",!S)S=J(16);else if(S.length!=16)throw Error("invalid initialation vector size (must be 16 bytes)");this._lastPrecipher=Y(S,!0),this._lastPrecipherIndex=16,this._aes=new y(B)};d.prototype.encrypt=function(B){var S=Y(B,!0);for(var _=0;_<S.length;_++){if(this._lastPrecipherIndex===16)this._lastPrecipher=this._aes.encrypt(this._lastPrecipher),this._lastPrecipherIndex=0;S[_]^=this._lastPrecipher[this._lastPrecipherIndex++]}return S},d.prototype.decrypt=d.prototype.encrypt;var P=function(B){if(!(this instanceof P))throw Error("Counter must be instanitated with `new`");if(B!==0&&!B)B=1;if(typeof B==="number")this._counter=J(16),this.setValue(B);else this.setBytes(B)};P.prototype.setValue=function(B){if(typeof B!=="number"||parseInt(B)!=B)throw Error("invalid counter value (must be an integer)");if(B>Number.MAX_SAFE_INTEGER)throw Error("integer value out of safe range");for(var S=15;S>=0;--S)this._counter[S]=B%256,B=parseInt(B/256)},P.prototype.setBytes=function(B){if(B=Y(B,!0),B.length!=16)throw Error("invalid counter bytes size (must be 16 bytes)");this._counter=B},P.prototype.increment=function(){for(var B=15;B>=0;B--)if(this._counter[B]===255)this._counter[B]=0;else{this._counter[B]++;break}};var E=function(B,S){if(!(this instanceof E))throw Error("AES must be instanitated with `new`");if(this.description="Counter",this.name="ctr",!(S instanceof P))S=new P(S);this._counter=S,this._remainingCounter=null,this._remainingCounterIndex=16,this._aes=new y(B)};E.prototype.encrypt=function(B){var S=Y(B,!0);for(var _=0;_<S.length;_++){if(this._remainingCounterIndex===16)this._remainingCounter=this._aes.encrypt(this._counter._counter),this._remainingCounterIndex=0,this._counter.increment();S[_]^=this._remainingCounter[this._remainingCounterIndex++]}return S},E.prototype.decrypt=E.prototype.encrypt;function f(B){B=Y(B,!0);var S=16-B.length%16,_=J(B.length+S);Z(B,_);for(var v=B.length;v<_.length;v++)_[v]=S;return _}function r(B){if(B=Y(B,!0),B.length<16)throw Error("PKCS#7 invalid length");var S=B[B.length-1];if(S>16)throw Error("PKCS#7 padding byte out of range");var _=B.length-S;for(var v=0;v<S;v++)if(B[_+v]!==S)throw Error("PKCS#7 invalid padding byte");var R=J(_);return Z(B,R,0,0,_),R}var o={AES:y,Counter:P,ModeOfOperation:{ecb:t,cbc:H0,cfb:g,ofb:d,ctr:E},utils:{hex:U,utf8:V},padding:{pkcs7:{pad:f,strip:r}},_arrayTest:{coerceArray:Y,createArray:J,copyArray:Z}};if(typeof ij<"u")P$.exports=o;else if(typeof define==="function"&&define.amd)define([],function(){return o});else{if(W.aesjs)o._aesjs=W.aesjs;W.aesjs=o}})(ij)});var tj=V1((S$)=>{var G1=S$,{Buffer:$q}=_8("buffer"),sl=_8("os");G1.toBuffer=function(W,X,G){G=~~G;let Y;if(this.isV4Format(W))Y=X||$q.alloc(G+4),W.split(/\./g).map((J)=>{Y[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)}Y=X||$q.alloc(G+16);for(Z=0;Z<J.length;Z++){let V=parseInt(J[Z],16);Y[G++]=V>>8&255,Y[G++]=V&255}}if(!Y)throw Error(`Invalid ip address: ${W}`);return Y};G1.toString=function(W,X,G){X=~~X,G=G||W.length-X;let Y=[];if(G===4){for(let J=0;J<G;J++)Y.push(W[X+J]);Y=Y.join(".")}else if(G===16){for(let J=0;J<G;J+=2)Y.push(W.readUInt16BE(X+J).toString(16));Y=Y.join(":"),Y=Y.replace(/(^|:)0(:0)*:0(:|$)/,"$1::$3"),Y=Y.replace(/:{3,4}/,"::")}return Y};var tl=/^(\d{1,3}\.){3,3}\d{1,3}$/,el=/^(::)?(((\d{1,3}\.){3}(\d{1,3}){1})?([0-9a-f]){0,4}:{0,2}){1,8}(::)?$/i;G1.isV4Format=function(W){return tl.test(W)};G1.isV6Format=function(W){return el.test(W)};function SV(W){if(W===4)return"ipv4";if(W===6)return"ipv6";return W?W.toLowerCase():"ipv4"}G1.fromPrefixLen=function(W,X){if(W>32)X="ipv6";else X=SV(X);let G=4;if(X==="ipv6")G=16;let Y=$q.alloc(G);for(let J=0,Z=Y.length;J<Z;++J){let V=8;if(W<8)V=W;W-=V,Y[J]=~(255>>V)&255}return G1.toString(Y)};G1.mask=function(W,X){W=G1.toBuffer(W),X=G1.toBuffer(X);let G=$q.alloc(Math.max(W.length,X.length)),Y;if(W.length===X.length)for(Y=0;Y<W.length;Y++)G[Y]=W[Y]&X[Y];else if(X.length===4)for(Y=0;Y<X.length;Y++)G[Y]=W[W.length-4+Y]&X[Y];else{for(Y=0;Y<G.length-6;Y++)G[Y]=0;G[10]=255,G[11]=255;for(Y=0;Y<W.length;Y++)G[Y+12]=W[Y]&X[Y+12];Y+=12}for(;Y<G.length;Y++)G[Y]=0;return G1.toString(G)};G1.cidr=function(W){let X=W.split("/"),G=X[0];if(X.length!==2)throw Error(`invalid CIDR subnet: ${G}`);let Y=G1.fromPrefixLen(parseInt(X[1],10));return G1.mask(G,Y)};G1.subnet=function(W,X){let G=G1.toLong(G1.mask(W,X)),Y=G1.toBuffer(X),J=0;for(let V=0;V<Y.length;V++)if(Y[V]===255)J+=8;else{let U=Y[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:X,subnetMaskLength:J,numHosts:Z<=2?Z:Z-2,length:Z,contains(V){return G===G1.toLong(G1.mask(V,X))}}};G1.cidrSubnet=function(W){let X=W.split("/"),G=X[0];if(X.length!==2)throw Error(`invalid CIDR subnet: ${G}`);let Y=G1.fromPrefixLen(parseInt(X[1],10));return G1.subnet(G,Y)};G1.not=function(W){let X=G1.toBuffer(W);for(let G=0;G<X.length;G++)X[G]=255^X[G];return G1.toString(X)};G1.or=function(W,X){if(W=G1.toBuffer(W),X=G1.toBuffer(X),W.length===X.length){for(let Z=0;Z<W.length;++Z)W[Z]|=X[Z];return G1.toString(W)}let G=W,Y=X;if(X.length>W.length)G=X,Y=W;let J=G.length-Y.length;for(let Z=J;Z<G.length;++Z)G[Z]|=Y[Z-J];return G1.toString(G)};G1.isEqual=function(W,X){if(W=G1.toBuffer(W),X=G1.toBuffer(X),W.length===X.length){for(let Y=0;Y<W.length;Y++)if(W[Y]!==X[Y])return!1;return!0}if(X.length===4){let Y=X;X=W,W=Y}for(let Y=0;Y<10;Y++)if(X[Y]!==0)return!1;let G=X.readUInt16BE(10);if(G!==0&&G!==65535)return!1;for(let Y=0;Y<4;Y++)if(W[Y]!==X[Y+12])return!1;return!0};G1.isPrivate=function(W){if(G1.isLoopback(W))return!0;if(!G1.isV6Format(W)){let X=G1.normalizeToLong(W);if(X<0)throw Error("invalid ipv4 address");W=G1.fromLong(X)}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=SV(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,X){let G=sl.networkInterfaces();if(X=SV(X),W&&W!=="private"&&W!=="public"){let J=G[W].filter((Z)=>{return SV(Z.family)===X});if(J.length===0)return;return J[0].address}let Y=Object.keys(G).map((J)=>{let Z=G[J].filter((V)=>{if(V.family=SV(V.family),V.family!==X||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!Y.length?G1.loopback(X):Y[0]};G1.toLong=function(W){let X=0;return W.split(".").forEach((G)=>{X<<=8,X+=parseInt(G)}),X>>>0};G1.fromLong=function(W){return`${W>>>24}.${W>>16&255}.${W>>8&255}.${W&255}`};G1.normalizeToLong=function(W){let X=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(X.some(isNaN))return-1;let G=0;switch(X.length){case 1:G=X[0];break;case 2:if(X[0]>255||X[1]>16777215)return-1;G=X[0]<<24|X[1]&16777215;break;case 3:if(X[0]>255||X[1]>255||X[2]>65535)return-1;G=X[0]<<24|X[1]<<16|X[2]&65535;break;case 4:if(X.some((J)=>J>255))return-1;G=X[0]<<24|X[1]<<16|X[2]<<8|X[3];break;default:return-1}return G>>>0}});var k$=V1((eq0,x$)=>{x$.exports=function W(X,G){if(X===G)return!0;if(X&&G&&typeof X=="object"&&typeof G=="object"){if(X.constructor!==G.constructor)return!1;var Y,J,Z;if(Array.isArray(X)){if(Y=X.length,Y!=G.length)return!1;for(J=Y;J--!==0;)if(!W(X[J],G[J]))return!1;return!0}if(X.constructor===RegExp)return X.source===G.source&&X.flags===G.flags;if(X.valueOf!==Object.prototype.valueOf)return X.valueOf()===G.valueOf();if(X.toString!==Object.prototype.toString)return X.toString()===G.toString();if(Z=Object.keys(X),Y=Z.length,Y!==Object.keys(G).length)return!1;for(J=Y;J--!==0;)if(!Object.prototype.hasOwnProperty.call(G,Z[J]))return!1;for(J=Y;J--!==0;){var V=Z[J];if(!W(X[V],G[V]))return!1}return!0}return X!==X&&G!==G}});var _$=V1((Wd)=>{Wd.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};Wd.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 y$=V1((Yd)=>{Yd.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};Yd.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 v$=V1((Vd)=>{Vd.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};Vd.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 g$=V1((Nd)=>{Nd.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};Nd.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 u$=V1((Ad)=>{Ad.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}`};Ad.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 X=W.match(/_(\d+)$/);if(X)return parseInt(X[1],10);return-1}});var m$=V1((b$,ej)=>{var h$=function(W){Object.defineProperty(W,"__esModule",{value:!0}),W.decode=A,W.encode=q,W.familyOf=N,W.name=void 0,W.sizeOf=Q,W.v6=W.v4=void 0;let X=/^(\d{1,3}\.){3,3}\d{1,3}$/,G=4,Y=/^(::)?(((\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:(H)=>X.test(H),encode(H,I,w){w=~~w,I=I||new Uint8Array(w+G);let O=H.length,T=0;for(let x=0;x<O;){let h=H.charCodeAt(x++);if(h===46)I[w++]=T,T=0;else T=T*10+(h-48)}return I[w]=T,I},decode(H,I){return I=~~I,`${H[I++]}.${H[I++]}.${H[I++]}.${H[I]}`}};W.v4=Z;let V={name:"v6",size:J,isFormat:(H)=>H.length>0&&Y.test(H),encode(H,I,w){w=~~w;let O=w+J,T=-1,x=0,h=0,$=!0,F=!1;I=I||new Uint8Array(w+J);for(let u=0;u<H.length;u++){let l=H.charCodeAt(u);if(l===58){if($){if(T!==-1){if(w<O)I[w]=0;if(w<O-1)I[w+1]=0;w+=2}else if(w<O)T=w}else{if(F===!0){if(w<O)I[w]=h;w++}else{if(w<O)I[w]=x>>8;if(w<O-1)I[w+1]=x&255;w+=2}x=0,h=0}$=!0,F=!1}else if(l===46){if(w<O)I[w]=h;w++,h=0,x=0,$=!1,F=!0}else{if($=!1,l>=97)l-=87;else if(l>=65)l-=55;else l-=48,h=h*10+l;x=(x<<4)+l}}if($===!1)if(F===!0){if(w<O)I[w]=h;w++}else{if(w<O)I[w]=x>>8;if(w<O-1)I[w+1]=x&255;w+=2}else if(T===0){if(w<O)I[w]=0;if(w<O-1)I[w+1]=0;w+=2}else if(T!==-1){w+=2;for(let u=Math.min(w-1,O-1);u>=T+2;u--)I[u]=I[u-2];I[T]=0,I[T+1]=0,T=w}if(T!==w&&T!==-1){if(w>O-2)w=O-2;while(O>T)I[--O]=w<O&&w>T?I[--w]:0}else while(w<O)I[w++]=0;return I},decode(H,I){I=~~I;let w="";for(let O=0;O<J;O+=2){if(O!==0)w+=":";w+=(H[I+O]<<8|H[I+O+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(H){if(Z.isFormat(H))return Z.size;if(V.isFormat(H))return V.size;throw Error(`Invalid ip address: ${H}`)}function N(H){return Q(H)===Z.size?1:2}function q(H,I,w){w=~~w;let O=Q(H);if(typeof I==="function")I=I(w+O);if(O===Z.size)return Z.encode(H,I,w);return V.encode(H,I,w)}function A(H,I,w){if(I=~~I,w=w||H.length-I,w===Z.size)return Z.decode(H,I,w);if(w===V.size)return V.decode(H,I,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 h$});else if(typeof ej==="object"&&typeof b$==="object")ej.exports=h$});var f$=V1((Dd)=>{var Z1=_8("buffer").Buffer,f4=_$(),wd=y$(),jd=v$(),Sq=g$(),GK=u$(),KX=m$(),g0=Dd.name={};g0.encode=function(W,X,G,{mail:Y=!1}={}){if(!X)X=Z1.alloc(g0.encodingLength(W));if(!G)G=0;let J=G,Z=W.replace(/^\.|\.$/gm,"");if(Z.length){let V=[];if(Y){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=X.write(V[U],G+1);X[G]=Q,G+=Q+1}}return X[G++]=0,g0.encode.bytes=G-J,X};g0.encode.bytes=0;g0.decode=function(W,X,{mail:G=!1}={}){if(!X)X=0;let Y=[],J=X,Z=0,V=0,U=!1;while(!0){if(X>=W.length)throw Error("Cannot decode name (buffer overflow)");let Q=W[X++];if(V+=U?0:1,Q===0)break;else if((Q&192)===0){if(X+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 N=W.toString("utf-8",X,X+Q);if(G)N=N.replace(/\./g,"\\.");Y.push(N),X+=Q,V+=U?0:Q}else if((Q&192)===192){if(X+1>W.length)throw Error("Cannot decode name (buffer overflow)");let N=W.readUInt16BE(X-1)-49152;if(N>=J)throw Error("Cannot decode name (bad pointer)");X=N,J=N,V+=U?0:1,U=!0}else throw Error("Cannot decode name (bad label)")}return g0.decode.bytes=V,Y.length===0?".":Y.join(".")};g0.decode.bytes=0;g0.encodingLength=function(W){if(W==="."||W==="..")return 1;return Z1.byteLength(W.replace(/^\.|\.$/gm,""))+2};var y1={};y1.encode=function(W,X,G){if(!X)X=Z1.alloc(y1.encodingLength(W));if(!G)G=0;let Y=X.write(W,G+1);return X[G]=Y,y1.encode.bytes=Y+1,X};y1.encode.bytes=0;y1.decode=function(W,X){if(!X)X=0;let G=W[X],Y=W.toString("utf-8",X+1,X+1+G);return y1.decode.bytes=G+1,Y};y1.decode.bytes=0;y1.encodingLength=function(W){return Z1.byteLength(W)+1};var W7={};W7.encode=function(W,X,G){if(!X)X=W7.encodingLength(W);if(!G)G=0;let Y=(W.flags||0)&32767,J=W.type==="response"?32768:0;return X.writeUInt16BE(W.id||0,G),X.writeUInt16BE(Y|J,G+2),X.writeUInt16BE(W.questions.length,G+4),X.writeUInt16BE(W.answers.length,G+6),X.writeUInt16BE(W.authorities.length,G+8),X.writeUInt16BE(W.additionals.length,G+10),X};W7.encode.bytes=12;W7.decode=function(W,X){if(!X)X=0;if(W.length<12)throw Error("Header must be 12 bytes");let G=W.readUInt16BE(X+2);return{id:W.readUInt16BE(X),type:G&32768?"response":"query",flags:G&32767,flag_qr:(G>>15&1)===1,opcode:jd.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:wd.toString(G&15),questions:Array(W.readUInt16BE(X+4)),answers:Array(W.readUInt16BE(X+6)),authorities:Array(W.readUInt16BE(X+8)),additionals:Array(W.readUInt16BE(X+10))}};W7.decode.bytes=12;W7.encodingLength=function(){return 12};var k4=Dd.unknown={};k4.encode=function(W,X,G){if(!X)X=Z1.alloc(k4.encodingLength(W));if(!G)G=0;return X.writeUInt16BE(W.length,G),W.copy(X,G+2),k4.encode.bytes=W.length+2,X};k4.encode.bytes=0;k4.decode=function(W,X){if(!X)X=0;let G=W.readUInt16BE(X),Y=W.slice(X+2,X+2+G);return k4.decode.bytes=G+2,Y};k4.decode.bytes=0;k4.encodingLength=function(W){return W.length+2};var _4=Dd.ns={};_4.encode=function(W,X,G){if(!X)X=Z1.alloc(_4.encodingLength(W));if(!G)G=0;return g0.encode(W,X,G+2),X.writeUInt16BE(g0.encode.bytes,G),_4.encode.bytes=g0.encode.bytes+2,X};_4.encode.bytes=0;_4.decode=function(W,X){if(!X)X=0;let G=W.readUInt16BE(X),Y=g0.decode(W,X+2);return _4.decode.bytes=G+2,Y};_4.decode.bytes=0;_4.encodingLength=function(W){return g0.encodingLength(W)+2};var y4=Dd.soa={};y4.encode=function(W,X,G){if(!X)X=Z1.alloc(y4.encodingLength(W));if(!G)G=0;let Y=G;return G+=2,g0.encode(W.mname,X,G),G+=g0.encode.bytes,g0.encode(W.rname,X,G,{mail:!0}),G+=g0.encode.bytes,X.writeUInt32BE(W.serial||0,G),G+=4,X.writeUInt32BE(W.refresh||0,G),G+=4,X.writeUInt32BE(W.retry||0,G),G+=4,X.writeUInt32BE(W.expire||0,G),G+=4,X.writeUInt32BE(W.minimum||0,G),G+=4,X.writeUInt16BE(G-Y-2,Y),y4.encode.bytes=G-Y,X};y4.encode.bytes=0;y4.decode=function(W,X){if(!X)X=0;let G=X,Y={};return X+=2,Y.mname=g0.decode(W,X),X+=g0.decode.bytes,Y.rname=g0.decode(W,X,{mail:!0}),X+=g0.decode.bytes,Y.serial=W.readUInt32BE(X),X+=4,Y.refresh=W.readUInt32BE(X),X+=4,Y.retry=W.readUInt32BE(X),X+=4,Y.expire=W.readUInt32BE(X),X+=4,Y.minimum=W.readUInt32BE(X),X+=4,y4.decode.bytes=X-G,Y};y4.decode.bytes=0;y4.encodingLength=function(W){return 22+g0.encodingLength(W.mname)+g0.encodingLength(W.rname)};var v4=Dd.txt={};v4.encode=function(W,X,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(!X)X=Z1.alloc(v4.encodingLength(W));if(!G)G=0;let Y=G;return G+=2,W.forEach(function(J){X[G++]=J.length,J.copy(X,G,0,J.length),G+=J.length}),X.writeUInt16BE(G-Y-2,Y),v4.encode.bytes=G-Y,X};v4.encode.bytes=0;v4.decode=function(W,X){if(!X)X=0;let G=X,Y=W.readUInt16BE(X);X+=2;let J=[];while(Y>0){let Z=W[X++];if(--Y,Y<Z)throw Error("Buffer overflow");J.push(W.slice(X,X+Z)),X+=Z,Y-=Z}return v4.decode.bytes=X-G,J};v4.decode.bytes=0;v4.encodingLength=function(W){if(!Array.isArray(W))W=[W];let X=2;return W.forEach(function(G){if(typeof G==="string")X+=Z1.byteLength(G)+1;else X+=G.length+1}),X};var g4=Dd.null={};g4.encode=function(W,X,G){if(!X)X=Z1.alloc(g4.encodingLength(W));if(!G)G=0;if(typeof W==="string")W=Z1.from(W);if(!W)W=Z1.alloc(0);let Y=G;G+=2;let J=W.length;return W.copy(X,G,0,J),G+=J,X.writeUInt16BE(G-Y-2,Y),g4.encode.bytes=G-Y,X};g4.encode.bytes=0;g4.decode=function(W,X){if(!X)X=0;let G=X,Y=W.readUInt16BE(X);X+=2;let J=W.slice(X,X+Y);return X+=Y,g4.decode.bytes=X-G,J};g4.decode.bytes=0;g4.encodingLength=function(W){if(!W)return 2;return(Z1.isBuffer(W)?W.length:Z1.byteLength(W))+2};var u4=Dd.hinfo={};u4.encode=function(W,X,G){if(!X)X=Z1.alloc(u4.encodingLength(W));if(!G)G=0;let Y=G;return G+=2,y1.encode(W.cpu,X,G),G+=y1.encode.bytes,y1.encode(W.os,X,G),G+=y1.encode.bytes,X.writeUInt16BE(G-Y-2,Y),u4.encode.bytes=G-Y,X};u4.encode.bytes=0;u4.decode=function(W,X){if(!X)X=0;let G=X,Y={};return X+=2,Y.cpu=y1.decode(W,X),X+=y1.decode.bytes,Y.os=y1.decode(W,X),X+=y1.decode.bytes,u4.decode.bytes=X-G,Y};u4.decode.bytes=0;u4.encodingLength=function(W){return y1.encodingLength(W.cpu)+y1.encodingLength(W.os)+2};var t5=Dd.ptr={},Kd=Dd.cname=t5,Od=Dd.dname=t5;t5.encode=function(W,X,G){if(!X)X=Z1.alloc(t5.encodingLength(W));if(!G)G=0;return g0.encode(W,X,G+2),X.writeUInt16BE(g0.encode.bytes,G),t5.encode.bytes=g0.encode.bytes+2,X};t5.encode.bytes=0;t5.decode=function(W,X){if(!X)X=0;let G=g0.decode(W,X+2);return t5.decode.bytes=g0.decode.bytes+2,G};t5.decode.bytes=0;t5.encodingLength=function(W){return g0.encodingLength(W)+2};var h4=Dd.srv={};h4.encode=function(W,X,G){if(!X)X=Z1.alloc(h4.encodingLength(W));if(!G)G=0;X.writeUInt16BE(W.priority||0,G+2),X.writeUInt16BE(W.weight||0,G+4),X.writeUInt16BE(W.port||0,G+6),g0.encode(W.target,X,G+8);let Y=g0.encode.bytes+6;return X.writeUInt16BE(Y,G),h4.encode.bytes=Y+2,X};h4.encode.bytes=0;h4.decode=function(W,X){if(!X)X=0;let G=W.readUInt16BE(X),Y={};return Y.priority=W.readUInt16BE(X+2),Y.weight=W.readUInt16BE(X+4),Y.port=W.readUInt16BE(X+6),Y.target=g0.decode(W,X+8),h4.decode.bytes=G+2,Y};h4.decode.bytes=0;h4.encodingLength=function(W){return 8+g0.encodingLength(W.target)};var H5=Dd.caa={};H5.ISSUER_CRITICAL=128;H5.encode=function(W,X,G){let Y=H5.encodingLength(W);if(!X)X=Z1.alloc(H5.encodingLength(W));if(!G)G=0;if(W.issuerCritical)W.flags=H5.ISSUER_CRITICAL;return X.writeUInt16BE(Y-2,G),G+=2,X.writeUInt8(W.flags||0,G),G+=1,y1.encode(W.tag,X,G),G+=y1.encode.bytes,X.write(W.value,G),G+=Z1.byteLength(W.value),H5.encode.bytes=Y,X};H5.encode.bytes=0;H5.decode=function(W,X){if(!X)X=0;let G=W.readUInt16BE(X);X+=2;let Y=X,J={};return J.flags=W.readUInt8(X),X+=1,J.tag=y1.decode(W,X),X+=y1.decode.bytes,J.value=W.toString("utf-8",X,Y+G),J.issuerCritical=!!(J.flags&H5.ISSUER_CRITICAL),H5.decode.bytes=G+2,J};H5.decode.bytes=0;H5.encodingLength=function(W){return y1.encodingLength(W.tag)+y1.encodingLength(W.value)+2};var i6=Dd.mx={};i6.encode=function(W,X,G){if(!X)X=Z1.alloc(i6.encodingLength(W));if(!G)G=0;let Y=G;return G+=2,X.writeUInt16BE(W.preference||0,G),G+=2,g0.encode(W.exchange,X,G),G+=g0.encode.bytes,X.writeUInt16BE(G-Y-2,Y),i6.encode.bytes=G-Y,X};i6.encode.bytes=0;i6.decode=function(W,X){if(!X)X=0;let G=X,Y={};return X+=2,Y.preference=W.readUInt16BE(X),X+=2,Y.exchange=g0.decode(W,X),X+=g0.decode.bytes,i6.decode.bytes=X-G,Y};i6.encodingLength=function(W){return 4+g0.encodingLength(W.exchange)};var b4=Dd.a={};b4.encode=function(W,X,G){if(!X)X=Z1.alloc(b4.encodingLength(W));if(!G)G=0;return X.writeUInt16BE(4,G),G+=2,KX.v4.encode(W,X,G),b4.encode.bytes=6,X};b4.encode.bytes=0;b4.decode=function(W,X){if(!X)X=0;X+=2;let G=KX.v4.decode(W,X);return b4.decode.bytes=6,G};b4.decode.bytes=0;b4.encodingLength=function(){return 6};var m4=Dd.aaaa={};m4.encode=function(W,X,G){if(!X)X=Z1.alloc(m4.encodingLength(W));if(!G)G=0;return X.writeUInt16BE(16,G),G+=2,KX.v6.encode(W,X,G),m4.encode.bytes=18,X};m4.encode.bytes=0;m4.decode=function(W,X){if(!X)X=0;X+=2;let G=KX.v6.decode(W,X);return m4.decode.bytes=18,G};m4.decode.bytes=0;m4.encodingLength=function(){return 18};var s9=Dd.option={};s9.encode=function(W,X,G){if(!X)X=Z1.alloc(s9.encodingLength(W));if(!G)G=0;let Y=G,J=GK.toCode(W.code);if(X.writeUInt16BE(J,G),G+=2,W.data)X.writeUInt16BE(W.data.length,G),G+=2,W.data.copy(X,G),G+=W.data.length;else switch(J){case 8:let Z=W.sourcePrefixLength||0,V=W.family||KX.familyOf(W.ip),U=KX.encode(W.ip,Z1.alloc),Q=Math.ceil(Z/8);X.writeUInt16BE(Q+4,G),G+=2,X.writeUInt16BE(V,G),G+=2,X.writeUInt8(Z,G++),X.writeUInt8(W.scopePrefixLength||0,G++),U.copy(X,G,0,Q),G+=Q;break;case 11:if(W.timeout)X.writeUInt16BE(2,G),G+=2,X.writeUInt16BE(W.timeout,G),G+=2;else X.writeUInt16BE(0,G),G+=2;break;case 12:let N=W.length||0;X.writeUInt16BE(N,G),G+=2,X.fill(0,G,G+N),G+=N;break;case 14:let q=W.tags.length*2;X.writeUInt16BE(q,G),G+=2;for(let A of W.tags)X.writeUInt16BE(A,G),G+=2;break;default:throw Error(`Unknown roption code: ${W.code}`)}return s9.encode.bytes=G-Y,X};s9.encode.bytes=0;s9.decode=function(W,X){if(!X)X=0;let G={};G.code=W.readUInt16BE(X),G.type=GK.toString(G.code),X+=2;let Y=W.readUInt16BE(X);switch(X+=2,G.data=W.slice(X,X+Y),G.code){case 8:G.family=W.readUInt16BE(X),X+=2,G.sourcePrefixLength=W.readUInt8(X++),G.scopePrefixLength=W.readUInt8(X++);let J=Z1.alloc(G.family===1?4:16);W.copy(J,0,X,X+Y-4),G.ip=KX.decode(J);break;case 11:if(Y>0)G.timeout=W.readUInt16BE(X),X+=2;break;case 14:G.tags=[];for(let Z=0;Z<Y;Z+=2)G.tags.push(W.readUInt16BE(X)),X+=2}return s9.decode.bytes=Y+4,G};s9.decode.bytes=0;s9.encodingLength=function(W){if(W.data)return W.data.length+4;switch(GK.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 z5=Dd.opt={};z5.encode=function(W,X,G){if(!X)X=Z1.alloc(z5.encodingLength(W));if(!G)G=0;let Y=G,J=FY(W,s9);return X.writeUInt16BE(J,G),G=xV(W,s9,X,G+2),z5.encode.bytes=G-Y,X};z5.encode.bytes=0;z5.decode=function(W,X){if(!X)X=0;let G=X,Y=[],J=W.readUInt16BE(X);X+=2;let Z=0;while(J>0)Y[Z++]=s9.decode(W,X),X+=s9.decode.bytes,J-=s9.decode.bytes;return z5.decode.bytes=X-G,Y};z5.decode.bytes=0;z5.encodingLength=function(W){return 2+FY(W||[],s9)};var h9=Dd.dnskey={};h9.PROTOCOL_DNSSEC=3;h9.ZONE_KEY=128;h9.SECURE_ENTRYPOINT=32768;h9.encode=function(W,X,G){if(!X)X=Z1.alloc(h9.encodingLength(W));if(!G)G=0;let Y=G,J=W.key;if(!Z1.isBuffer(J))throw Error("Key must be a Buffer");return G+=2,X.writeUInt16BE(W.flags,G),G+=2,X.writeUInt8(h9.PROTOCOL_DNSSEC,G),G+=1,X.writeUInt8(W.algorithm,G),G+=1,J.copy(X,G,0,J.length),G+=J.length,h9.encode.bytes=G-Y,X.writeUInt16BE(h9.encode.bytes-2,Y),X};h9.encode.bytes=0;h9.decode=function(W,X){if(!X)X=0;let G=X;var Y={},J=W.readUInt16BE(X);if(X+=2,Y.flags=W.readUInt16BE(X),X+=2,W.readUInt8(X)!==h9.PROTOCOL_DNSSEC)throw Error("Protocol must be 3");return X+=1,Y.algorithm=W.readUInt8(X),X+=1,Y.key=W.slice(X,G+J+2),X+=Y.key.length,h9.decode.bytes=X-G,Y};h9.decode.bytes=0;h9.encodingLength=function(W){return 6+Z1.byteLength(W.key)};var v7=Dd.rrsig={};v7.encode=function(W,X,G){if(!X)X=Z1.alloc(v7.encodingLength(W));if(!G)G=0;let Y=G,J=W.signature;if(!Z1.isBuffer(J))throw Error("Signature must be a Buffer");return G+=2,X.writeUInt16BE(f4.toType(W.typeCovered),G),G+=2,X.writeUInt8(W.algorithm,G),G+=1,X.writeUInt8(W.labels,G),G+=1,X.writeUInt32BE(W.originalTTL,G),G+=4,X.writeUInt32BE(W.expiration,G),G+=4,X.writeUInt32BE(W.inception,G),G+=4,X.writeUInt16BE(W.keyTag,G),G+=2,g0.encode(W.signersName,X,G),G+=g0.encode.bytes,J.copy(X,G,0,J.length),G+=J.length,v7.encode.bytes=G-Y,X.writeUInt16BE(v7.encode.bytes-2,Y),X};v7.encode.bytes=0;v7.decode=function(W,X){if(!X)X=0;let G=X;var Y={},J=W.readUInt16BE(X);return X+=2,Y.typeCovered=f4.toString(W.readUInt16BE(X)),X+=2,Y.algorithm=W.readUInt8(X),X+=1,Y.labels=W.readUInt8(X),X+=1,Y.originalTTL=W.readUInt32BE(X),X+=4,Y.expiration=W.readUInt32BE(X),X+=4,Y.inception=W.readUInt32BE(X),X+=4,Y.keyTag=W.readUInt16BE(X),X+=2,Y.signersName=g0.decode(W,X),X+=g0.decode.bytes,Y.signature=W.slice(X,G+J+2),X+=Y.signature.length,v7.decode.bytes=X-G,Y};v7.decode.bytes=0;v7.encodingLength=function(W){return 20+g0.encodingLength(W.signersName)+Z1.byteLength(W.signature)};var g7=Dd.rp={};g7.encode=function(W,X,G){if(!X)X=Z1.alloc(g7.encodingLength(W));if(!G)G=0;let Y=G;return G+=2,g0.encode(W.mbox||".",X,G,{mail:!0}),G+=g0.encode.bytes,g0.encode(W.txt||".",X,G),G+=g0.encode.bytes,g7.encode.bytes=G-Y,X.writeUInt16BE(g7.encode.bytes-2,Y),X};g7.encode.bytes=0;g7.decode=function(W,X){if(!X)X=0;let G=X,Y={};return X+=2,Y.mbox=g0.decode(W,X,{mail:!0})||".",X+=g0.decode.bytes,Y.txt=g0.decode(W,X)||".",X+=g0.decode.bytes,g7.decode.bytes=X-G,Y};g7.decode.bytes=0;g7.encodingLength=function(W){return 2+g0.encodingLength(W.mbox||".")+g0.encodingLength(W.txt||".")};var a8={};a8.encode=function(W,X,G){if(!X)X=Z1.alloc(a8.encodingLength(W));if(!G)G=0;let Y=G;var J=[];for(var Z=0;Z<W.length;Z++){var V=f4.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]);X.writeUInt8(Z,G),G+=1,X.writeUInt8(U.length,G),G+=1,U.copy(X,G),G+=U.length}return a8.encode.bytes=G-Y,X};a8.encode.bytes=0;a8.decode=function(W,X,G){if(!X)X=0;let Y=X;var J=[];while(X-Y<G){var Z=W.readUInt8(X);X+=1;var V=W.readUInt8(X);X+=1;for(var U=0;U<V;U++){var Q=W.readUInt8(X+U);for(var N=0;N<8;N++)if(Q&1<<7-N){var q=f4.toString(Z<<8|U<<3|N);J.push(q)}}X+=V}return a8.decode.bytes=X-Y,J};a8.decode.bytes=0;a8.encodingLength=function(W){var X=[];for(var G=0;G<W.length;G++){var Y=f4.toType(W[G]);X[Y>>8]=Math.max(X[Y>>8]||0,Y&255)}var J=0;for(G=0;G<X.length;G++)if(X[G]!==void 0)J+=2+Math.ceil((X[G]+1)/8);return J};var u7=Dd.nsec={};u7.encode=function(W,X,G){if(!X)X=Z1.alloc(u7.encodingLength(W));if(!G)G=0;let Y=G;return G+=2,g0.encode(W.nextDomain,X,G),G+=g0.encode.bytes,a8.encode(W.rrtypes,X,G),G+=a8.encode.bytes,u7.encode.bytes=G-Y,X.writeUInt16BE(u7.encode.bytes-2,Y),X};u7.encode.bytes=0;u7.decode=function(W,X){if(!X)X=0;let G=X;var Y={},J=W.readUInt16BE(X);return X+=2,Y.nextDomain=g0.decode(W,X),X+=g0.decode.bytes,Y.rrtypes=a8.decode(W,X,J-(X-G)),X+=a8.decode.bytes,u7.decode.bytes=X-G,Y};u7.decode.bytes=0;u7.encodingLength=function(W){return 2+g0.encodingLength(W.nextDomain)+a8.encodingLength(W.rrtypes)};var h7=Dd.nsec3={};h7.encode=function(W,X,G){if(!X)X=Z1.alloc(h7.encodingLength(W));if(!G)G=0;let Y=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,X.writeUInt8(W.algorithm,G),G+=1,X.writeUInt8(W.flags,G),G+=1,X.writeUInt16BE(W.iterations,G),G+=2,X.writeUInt8(J.length,G),G+=1,J.copy(X,G,0,J.length),G+=J.length,X.writeUInt8(Z.length,G),G+=1,Z.copy(X,G,0,Z.length),G+=Z.length,a8.encode(W.rrtypes,X,G),G+=a8.encode.bytes,h7.encode.bytes=G-Y,X.writeUInt16BE(h7.encode.bytes-2,Y),X};h7.encode.bytes=0;h7.decode=function(W,X){if(!X)X=0;let G=X;var Y={},J=W.readUInt16BE(X);X+=2,Y.algorithm=W.readUInt8(X),X+=1,Y.flags=W.readUInt8(X),X+=1,Y.iterations=W.readUInt16BE(X),X+=2;let Z=W.readUInt8(X);X+=1,Y.salt=W.slice(X,X+Z),X+=Z;let V=W.readUInt8(X);return X+=1,Y.nextDomain=W.slice(X,X+V),X+=V,Y.rrtypes=a8.decode(W,X,J-(X-G)),X+=a8.decode.bytes,h7.decode.bytes=X-G,Y};h7.decode.bytes=0;h7.encodingLength=function(W){return 8+W.salt.length+W.nextDomain.length+a8.encodingLength(W.rrtypes)};var b7=Dd.ds={};b7.encode=function(W,X,G){if(!X)X=Z1.alloc(b7.encodingLength(W));if(!G)G=0;let Y=G,J=W.digest;if(!Z1.isBuffer(J))throw Error("Digest must be a Buffer");return G+=2,X.writeUInt16BE(W.keyTag,G),G+=2,X.writeUInt8(W.algorithm,G),G+=1,X.writeUInt8(W.digestType,G),G+=1,J.copy(X,G,0,J.length),G+=J.length,b7.encode.bytes=G-Y,X.writeUInt16BE(b7.encode.bytes-2,Y),X};b7.encode.bytes=0;b7.decode=function(W,X){if(!X)X=0;let G=X;var Y={},J=W.readUInt16BE(X);return X+=2,Y.keyTag=W.readUInt16BE(X),X+=2,Y.algorithm=W.readUInt8(X),X+=1,Y.digestType=W.readUInt8(X),X+=1,Y.digest=W.slice(X,G+J+2),X+=Y.digest.length,b7.decode.bytes=X-G,Y};b7.decode.bytes=0;b7.encodingLength=function(W){return 6+Z1.byteLength(W.digest)};var A5=Dd.sshfp={};A5.getFingerprintLengthForHashType=function(X){switch(X){case 1:return 20;case 2:return 32}};A5.encode=function(X,G,Y){if(!G)G=Z1.alloc(A5.encodingLength(X));if(!Y)Y=0;let J=Y;Y+=2,G[Y]=X.algorithm,Y+=1,G[Y]=X.hash,Y+=1;let Z=Z1.from(X.fingerprint.toUpperCase(),"hex");if(Z.length!==A5.getFingerprintLengthForHashType(X.hash))throw Error("Invalid fingerprint length");return Z.copy(G,Y),Y+=Z.byteLength,A5.encode.bytes=Y-J,G.writeUInt16BE(A5.encode.bytes-2,J),G};A5.encode.bytes=0;A5.decode=function(X,G){if(!G)G=0;let Y=G,J={};G+=2,J.algorithm=X[G],G+=1,J.hash=X[G],G+=1;let Z=A5.getFingerprintLengthForHashType(J.hash);return J.fingerprint=X.slice(G,G+Z).toString("hex").toUpperCase(),G+=Z,A5.decode.bytes=G-Y,J};A5.decode.bytes=0;A5.encodingLength=function(W){return 4+Z1.from(W.fingerprint,"hex").byteLength};var m7=Dd.naptr={};m7.encode=function(W,X,G){if(!X)X=Z1.alloc(m7.encodingLength(W));if(!G)G=0;let Y=G;return G+=2,X.writeUInt16BE(W.order||0,G),G+=2,X.writeUInt16BE(W.preference||0,G),G+=2,y1.encode(W.flags,X,G),G+=y1.encode.bytes,y1.encode(W.services,X,G),G+=y1.encode.bytes,y1.encode(W.regexp,X,G),G+=y1.encode.bytes,g0.encode(W.replacement,X,G),G+=g0.encode.bytes,m7.encode.bytes=G-Y,X.writeUInt16BE(m7.encode.bytes-2,Y),X};m7.encode.bytes=0;m7.decode=function(W,X){if(!X)X=0;let G=X,Y={};return X+=2,Y.order=W.readUInt16BE(X),X+=2,Y.preference=W.readUInt16BE(X),X+=2,Y.flags=y1.decode(W,X),X+=y1.decode.bytes,Y.services=y1.decode(W,X),X+=y1.decode.bytes,Y.regexp=y1.decode(W,X),X+=y1.decode.bytes,Y.replacement=g0.decode(W,X),X+=g0.decode.bytes,m7.decode.bytes=X-G,Y};m7.decode.bytes=0;m7.encodingLength=function(W){return y1.encodingLength(W.flags)+y1.encodingLength(W.services)+y1.encodingLength(W.regexp)+g0.encodingLength(W.replacement)+6};var f7=Dd.tlsa={};f7.encode=function(W,X,G){if(!X)X=Z1.alloc(f7.encodingLength(W));if(!G)G=0;let Y=G,J=W.certificate;if(!Z1.isBuffer(J))throw Error("Certificate must be a Buffer");return G+=2,X.writeUInt8(W.usage,G),G+=1,X.writeUInt8(W.selector,G),G+=1,X.writeUInt8(W.matchingType,G),G+=1,J.copy(X,G,0,J.length),G+=J.length,f7.encode.bytes=G-Y,X.writeUInt16BE(f7.encode.bytes-2,Y),X};f7.encode.bytes=0;f7.decode=function(W,X){if(!X)X=0;let G=X,Y={},J=W.readUInt16BE(X);return X+=2,Y.usage=W.readUInt8(X),X+=1,Y.selector=W.readUInt8(X),X+=1,Y.matchingType=W.readUInt8(X),X+=1,Y.certificate=W.slice(X,G+J+2),X+=Y.certificate.length,f7.decode.bytes=X-G,Y};f7.decode.bytes=0;f7.encodingLength=function(W){return 5+Z1.byteLength(W.certificate)};var YK=Dd.record=function(W){switch(W.toUpperCase()){case"A":return b4;case"PTR":return t5;case"CNAME":return Kd;case"DNAME":return Od;case"TXT":return v4;case"NULL":return g4;case"AAAA":return m4;case"SRV":return h4;case"HINFO":return u4;case"CAA":return H5;case"NS":return _4;case"SOA":return y4;case"MX":return i6;case"OPT":return z5;case"DNSKEY":return h9;case"RRSIG":return v7;case"RP":return g7;case"NSEC":return u7;case"NSEC3":return h7;case"SSHFP":return A5;case"DS":return b7;case"NAPTR":return m7;case"TLSA":return f7}return k4},V9=Dd.answer={};V9.encode=function(W,X,G){if(!X)X=Z1.alloc(V9.encodingLength(W));if(!G)G=0;let Y=G;if(g0.encode(W.name,X,G),G+=g0.encode.bytes,X.writeUInt16BE(f4.toType(W.type),G),W.type.toUpperCase()==="OPT"){if(W.name!==".")throw Error("OPT name must be root.");X.writeUInt16BE(W.udpPayloadSize||4096,G+2),X.writeUInt8(W.extendedRcode||0,G+4),X.writeUInt8(W.ednsVersion||0,G+5),X.writeUInt16BE(W.flags||0,G+6),G+=8,z5.encode(W.options||[],X,G),G+=z5.encode.bytes}else{let J=Sq.toClass(W.class===void 0?"IN":W.class);if(W.flush)J|=32768;X.writeUInt16BE(J,G+2),X.writeUInt32BE(W.ttl||0,G+4),G+=8;let Z=YK(W.type);Z.encode(W.data,X,G),G+=Z.encode.bytes}return V9.encode.bytes=G-Y,X};V9.encode.bytes=0;V9.decode=function(W,X){if(!X)X=0;let G={},Y=X;if(G.name=g0.decode(W,X),X+=g0.decode.bytes,G.type=f4.toString(W.readUInt16BE(X)),G.type==="OPT")G.udpPayloadSize=W.readUInt16BE(X+2),G.extendedRcode=W.readUInt8(X+4),G.ednsVersion=W.readUInt8(X+5),G.flags=W.readUInt16BE(X+6),G.flag_do=(G.flags>>15&1)===1,G.options=z5.decode(W,X+8),X+=8+z5.decode.bytes;else{let J=W.readUInt16BE(X+2);G.ttl=W.readUInt32BE(X+4),G.class=Sq.toString(J&-32769),G.flush=!!(J&32768);let Z=YK(G.type);G.data=Z.decode(W,X+8),X+=8+Z.decode.bytes}return V9.decode.bytes=X-Y,G};V9.decode.bytes=0;V9.encodingLength=function(W){let X=W.data!==null&&W.data!==void 0?W.data:W.options;return g0.encodingLength(W.name)+8+YK(W.type).encodingLength(X)};var e5=Dd.question={};e5.encode=function(W,X,G){if(!X)X=Z1.alloc(e5.encodingLength(W));if(!G)G=0;let Y=G;return g0.encode(W.name,X,G),G+=g0.encode.bytes,X.writeUInt16BE(f4.toType(W.type),G),G+=2,X.writeUInt16BE(Sq.toClass(W.class===void 0?"IN":W.class),G),G+=2,e5.encode.bytes=G-Y,W};e5.encode.bytes=0;e5.decode=function(W,X){if(!X)X=0;let G=X,Y={};if(Y.name=g0.decode(W,X),X+=g0.decode.bytes,Y.type=f4.toString(W.readUInt16BE(X)),X+=2,Y.class=Sq.toString(W.readUInt16BE(X)),X+=2,!!(Y.class&32768))Y.class&=-32769;return e5.decode.bytes=X-G,Y};e5.decode.bytes=0;e5.encodingLength=function(W){return g0.encodingLength(W.name)+4};Dd.AUTHORITATIVE_ANSWER=1024;Dd.TRUNCATED_RESPONSE=512;Dd.RECURSION_DESIRED=256;Dd.RECURSION_AVAILABLE=128;Dd.AUTHENTIC_DATA=32;Dd.CHECKING_DISABLED=16;Dd.DNSSEC_OK=32768;Dd.encode=function(W,X,G){let Y=!X;if(Y)X=Z1.alloc(Dd.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(W7.encode(W,X,G),G+=W7.encode.bytes,G=xV(W.questions,e5,X,G),G=xV(W.answers,V9,X,G),G=xV(W.authorities,V9,X,G),G=xV(W.additionals,V9,X,G),Dd.encode.bytes=G-J,Y&&Dd.encode.bytes!==X.length)return X.slice(0,Dd.encode.bytes);return X};Dd.encode.bytes=0;Dd.decode=function(W,X){if(!X)X=0;let G=X,Y=W7.decode(W,X);return X+=W7.decode.bytes,X=Fq(Y.questions,e5,W,X),X=Fq(Y.answers,V9,W,X),X=Fq(Y.authorities,V9,W,X),X=Fq(Y.additionals,V9,W,X),Dd.decode.bytes=X-G,Y};Dd.decode.bytes=0;Dd.encodingLength=function(W){return W7.encodingLength(W)+FY(W.questions||[],e5)+FY(W.answers||[],V9)+FY(W.authorities||[],V9)+FY(W.additionals||[],V9)};Dd.streamEncode=function(W){let X=Dd.encode(W),G=Z1.alloc(2);G.writeUInt16BE(X.byteLength);let Y=Z1.concat([G,X]);return Dd.streamEncode.bytes=Y.byteLength,Y};Dd.streamEncode.bytes=0;Dd.streamDecode=function(W){let X=W.readUInt16BE(0);if(W.byteLength<X+2)return null;let G=Dd.decode(W.slice(2));return Dd.streamDecode.bytes=Dd.decode.bytes,G};Dd.streamDecode.bytes=0;function FY(W,X){let G=0;for(let Y=0;Y<W.length;Y++)G+=X.encodingLength(W[Y]);return G}function xV(W,X,G,Y){for(let J=0;J<W.length;J++)X.encode(W[J],G,Y),Y+=X.encode.bytes;return Y}function Fq(W,X,G,Y){for(let J=0;J<W.length;J++)W[J]=X.decode(G,Y),Y+=X.decode.bytes;return Y}});var l$=V1((vH0,c$)=>{var p$=_d;process.nextTick(kd,42);c$.exports=$d;function $d(W){var X=Y;return G;function G(J){X(J||Sd)}function Y(J){var Z=[J];X=V,W(U);function V(Q){Z.push(Q)}function U(Q){var N=arguments;X=Fd(Q)?Y:q;while(Z.length)q(Z.shift());function q(A){p$(xd,A,N)}}}}function Fd(W){return Object.prototype.toString.call(W)==="[object Error]"}function Sd(){}function xd(W,X){W.apply(null,X)}function kd(W){if(W===42)p$=process.nextTick}function _d(W,X,G){process.nextTick(function(){W(X,G)})}});var n$=V1((gH0,o$)=>{var JK=f$(),yd=_8("dgram"),vd=l$(),gd=_8("events"),VK=_8("os"),ZK=function(){};o$.exports=function(W){if(!W)W={};var X=new gd.EventEmitter,G=typeof W.port==="number"?W.port:5353,Y=W.type||"udp4",J=W.ip||W.host||(Y==="udp4"?"224.0.0.251":null),Z={address:J,port:G},V={},U=!1,Q=null;if(Y==="udp6"&&(!J||!W.interface))throw Error("For IPv6 multicast you must specify `ip` and `interface`");var N=W.socket||yd.createSocket({type:Y,reuseAddr:W.reuseAddr!==!1,toString:function(){return Y}});N.on("error",function(A){if(A.code==="EACCES"||A.code==="EADDRINUSE")X.emit("error",A);else X.emit("warning",A)}),N.on("message",function(A,H){try{A=JK.decode(A)}catch(I){X.emit("warning",I);return}if(X.emit("packet",A,H),A.type==="query")X.emit("query",A,H);if(A.type==="response")X.emit("response",A,H)}),N.on("listening",function(){if(!G)G=Z.port=N.address().port;if(W.multicast!==!1)X.update(),Q=setInterval(X.update,5000),N.setMulticastTTL(W.ttl||255),N.setMulticastLoopback(W.loopback!==!1)});var q=vd(function(A){if(!G||W.bind===!1)return A(null);N.once("error",A),N.bind(G,W.bind||W.interface,function(){N.removeListener("error",A),A(null)})});return q(function(A){if(A)return X.emit("error",A);X.emit("ready")}),X.send=function(A,H,I){if(typeof H==="function")return X.send(A,null,H);if(!I)I=ZK;if(!H)H=Z;else if(!H.host&&!H.address)H.address=Z.address;q(w);function w(O){if(U)return I();if(O)return I(O);var T=JK.encode(A);N.send(T,0,T.length,H.port,H.address||H.host,I)}},X.response=X.respond=function(A,H,I){if(Array.isArray(A))A={answers:A};A.type="response",A.flags=(A.flags||0)|JK.AUTHORITATIVE_ANSWER,X.send(A,H,I)},X.query=function(A,H,I,w){if(typeof H==="function")return X.query(A,null,null,H);if(typeof H==="object"&&H&&H.port)return X.query(A,null,H,I);if(typeof I==="function")return X.query(A,H,null,I);if(!w)w=ZK;if(typeof A==="string")A=[{name:A,type:H||"ANY"}];if(Array.isArray(A))A={type:"query",questions:A};A.type="query",X.send(A,I,w)},X.destroy=function(A){if(!A)A=ZK;if(U)return process.nextTick(A);U=!0,clearInterval(Q);for(var H in V)try{N.dropMembership(J,H)}catch(I){}V={},N.close(A)},X.update=function(){var A=W.interface?[].concat(W.interface):hd(),H=!1;for(var I=0;I<A.length;I++){var w=A[I];if(V[w])continue;try{N.addMembership(J,w),V[w]=!0,H=!0}catch(O){X.emit("warning",O)}}if(H){if(N.setMulticastInterface)try{N.setMulticastInterface(W.interface||ud())}catch(O){X.emit("warning",O)}X.emit("networkInterface")}},X};function ud(){var W=VK.networkInterfaces(),X=Object.keys(W);for(var G=0;G<X.length;G++){var Y=W[X[G]];for(var J=0;J<Y.length;J++){var Z=Y[J];if(d$(Z.family)&&!Z.internal){if(VK.platform()==="darwin"&&X[G]==="en0")return Z.address;return"0.0.0.0"}}}return"127.0.0.1"}function hd(){var W=VK.networkInterfaces(),X=Object.keys(W),G=[];for(var Y=0;Y<X.length;Y++){var J=W[X[Y]];for(var Z=0;Z<J.length;Z++){var V=J[Z];if(d$(V.family)){G.push(V.address);break}}}return G}function d$(W){return W===4||W==="IPv4"}});import{Database as kt}from"bun:sqlite";import{mkdirSync as _t}from"fs";import{dirname as yt}from"path";function wD(W){let X=W.length,G=0,Y=0;while(Y<X){let J=W.charCodeAt(Y++);if((J&4294967168)===0){G++;continue}else if((J&4294965248)===0)G+=2;else{if(J>=55296&&J<=56319){if(Y<X){let Z=W.charCodeAt(Y);if((Z&64512)===56320)++Y,J=((J&1023)<<10)+(Z&1023)+65536}}if((J&4294901760)===0)G+=3;else G+=4}}return G}function r_(W,X,G){let Y=W.length,J=G,Z=0;while(Z<Y){let V=W.charCodeAt(Z++);if((V&4294967168)===0){X[J++]=V;continue}else if((V&4294965248)===0)X[J++]=V>>6&31|192;else{if(V>=55296&&V<=56319){if(Z<Y){let U=W.charCodeAt(Z);if((U&64512)===56320)++Z,V=((V&1023)<<10)+(U&1023)+65536}}if((V&4294901760)===0)X[J++]=V>>12&15|224,X[J++]=V>>6&63|128;else X[J++]=V>>18&7|240,X[J++]=V>>12&63|128,X[J++]=V>>6&63|128}X[J++]=V&63|128}}var a_=new TextEncoder,s_=50;function t_(W,X,G){a_.encodeInto(W,X.subarray(G))}function jD(W,X,G){if(W.length>s_)t_(W,X,G);else r_(W,X,G)}var e_=4096;function IA(W,X,G){let Y=X,J=Y+G,Z=[],V="";while(Y<J){let U=W[Y++];if((U&128)===0)Z.push(U);else if((U&224)===192){let Q=W[Y++]&63;Z.push((U&31)<<6|Q)}else if((U&240)===224){let Q=W[Y++]&63,N=W[Y++]&63;Z.push((U&31)<<12|Q<<6|N)}else if((U&248)===240){let Q=W[Y++]&63,N=W[Y++]&63,q=W[Y++]&63,A=(U&7)<<18|Q<<12|N<<6|q;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>=e_)V+=String.fromCharCode(...Z),Z.length=0}if(Z.length>0)V+=String.fromCharCode(...Z);return V}var Wy=new TextDecoder,Xy=200;function Gy(W,X,G){let Y=W.subarray(X,X+G);return Wy.decode(Y)}function KD(W,X,G){if(G>Xy)return Gy(W,X,G);else return IA(W,X,G)}class dX{type;data;constructor(W,X){this.type=W,this.data=X}}class x9 extends Error{constructor(W){super(W);let X=Object.create(x9.prototype);Object.setPrototypeOf(this,X),Object.defineProperty(this,"name",{configurable:!0,enumerable:!1,value:x9.name})}}var oX=4294967295;function OD(W,X,G){let Y=G/4294967296,J=G;W.setUint32(X,Y),W.setUint32(X+4,J)}function gU(W,X,G){let Y=Math.floor(G/4294967296),J=G;W.setUint32(X,Y),W.setUint32(X+4,J)}function uU(W,X){let G=W.getInt32(X),Y=W.getUint32(X+4);return G*4294967296+Y}function DD(W,X){let G=W.getUint32(X),Y=W.getUint32(X+4);return G*4294967296+Y}var Yy=-1,Jy=4294967295,Zy=17179869183;function Vy({sec:W,nsec:X}){if(W>=0&&X>=0&&W<=Zy)if(X===0&&W<=Jy){let G=new Uint8Array(4);return new DataView(G.buffer).setUint32(0,W),G}else{let G=W/4294967296,Y=W&4294967295,J=new Uint8Array(8),Z=new DataView(J.buffer);return Z.setUint32(0,X<<2|G&3),Z.setUint32(4,Y),J}else{let G=new Uint8Array(12),Y=new DataView(G.buffer);return Y.setUint32(0,X),gU(Y,4,W),G}}function Uy(W){let X=W.getTime(),G=Math.floor(X/1000),Y=(X-G*1000)*1e6,J=Math.floor(Y/1e9);return{sec:G+J,nsec:Y-J*1e9}}function Qy(W){if(W instanceof Date){let X=Uy(W);return Vy(X)}else return null}function Ny(W){let X=new DataView(W.buffer,W.byteOffset,W.byteLength);switch(W.byteLength){case 4:{let G=X.getUint32(0),Y=0;return{sec:G,nsec:0}}case 8:{let G=X.getUint32(0),Y=X.getUint32(4),J=(G&3)*4294967296+Y,Z=G>>>2;return{sec:J,nsec:Z}}case 12:{let G=uU(X,4),Y=X.getUint32(0);return{sec:G,nsec:Y}}default:throw new x9(`Unrecognized data size for timestamp (expected 4, 8, or 12): ${W.length}`)}}function qy(W){let X=Ny(W);return new Date(X.sec*1000+X.nsec/1e6)}var CD={type:Yy,encode:Qy,decode:qy};class nX{static defaultCodec=new nX;__brand;builtInEncoders=[];builtInDecoders=[];encoders=[];decoders=[];constructor(){this.register(CD)}register({type:W,encode:X,decode:G}){if(W>=0)this.encoders[W]=X,this.decoders[W]=G;else{let Y=-1-W;this.builtInEncoders[Y]=X,this.builtInDecoders[Y]=G}}tryToEncode(W,X){for(let G=0;G<this.builtInEncoders.length;G++){let Y=this.builtInEncoders[G];if(Y!=null){let J=Y(W,X);if(J!=null){let Z=-1-G;return new dX(Z,J)}}}for(let G=0;G<this.encoders.length;G++){let Y=this.encoders[G];if(Y!=null){let J=Y(W,X);if(J!=null)return new dX(G,J)}}if(W instanceof dX)return W;return null}decode(W,X,G){let Y=X<0?this.builtInDecoders[-1-X]:this.decoders[X];if(Y)return Y(W,X,G);else return new dX(X,W)}}function Hy(W){return W instanceof ArrayBuffer||typeof SharedArrayBuffer<"u"&&W instanceof SharedArrayBuffer}function NJ(W){if(W instanceof Uint8Array)return W;else if(ArrayBuffer.isView(W))return new Uint8Array(W.buffer,W.byteOffset,W.byteLength);else if(Hy(W))return new Uint8Array(W);else return Uint8Array.from(W)}var Ay=100,zy=2048;class hU{extensionCodec;context;useBigInt64;maxDepth;initialBufferSize;sortKeys;forceFloat32;ignoreUndefined;forceIntegerToFloat;pos;view;bytes;entered=!1;constructor(W){this.extensionCodec=W?.extensionCodec??nX.defaultCodec,this.context=W?.context,this.useBigInt64=W?.useBigInt64??!1,this.maxDepth=W?.maxDepth??Ay,this.initialBufferSize=W?.initialBufferSize??zy,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 hU({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,X){if(X>this.maxDepth)throw Error(`Too deep objects in depth ${X}`);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,X)}ensureBufferSizeToWrite(W){let X=this.pos+W;if(this.view.byteLength<X)this.resizeBuffer(X*2)}resizeBuffer(W){let X=new ArrayBuffer(W),G=new Uint8Array(X),Y=new DataView(X);G.set(this.bytes),this.view=Y,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=wD(W);this.ensureBufferSizeToWrite(5+G),this.writeStringHeader(G),jD(W,this.bytes,this.pos),this.pos+=G}encodeObject(W,X){let G=this.extensionCodec.tryToEncode(W,this.context);if(G!=null)this.encodeExtension(G);else if(Array.isArray(W))this.encodeArray(W,X);else if(ArrayBuffer.isView(W))this.encodeBinary(W);else if(typeof W==="object")this.encodeMap(W,X);else throw Error(`Unrecognized object: ${Object.prototype.toString.apply(W)}`)}encodeBinary(W){let X=W.byteLength;if(X<256)this.writeU8(196),this.writeU8(X);else if(X<65536)this.writeU8(197),this.writeU16(X);else if(X<4294967296)this.writeU8(198),this.writeU32(X);else throw Error(`Too large binary: ${X}`);let G=NJ(W);this.writeU8a(G)}encodeArray(W,X){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 Y of W)this.doEncode(Y,X+1)}countWithoutUndefined(W,X){let G=0;for(let Y of X)if(W[Y]!==void 0)G++;return G}encodeMap(W,X){let G=Object.keys(W);if(this.sortKeys)G.sort();let Y=this.ignoreUndefined?this.countWithoutUndefined(W,G):G.length;if(Y<16)this.writeU8(128+Y);else if(Y<65536)this.writeU8(222),this.writeU16(Y);else if(Y<4294967296)this.writeU8(223),this.writeU32(Y);else throw Error(`Too large map object: ${Y}`);for(let J of G){let Z=W[J];if(!(this.ignoreUndefined&&Z===void 0))this.encodeString(J),this.doEncode(Z,X+1)}}encodeExtension(W){if(typeof W.data==="function"){let G=W.data(this.pos+6),Y=G.length;if(Y>=4294967296)throw Error(`Too large extension object: ${Y}`);this.writeU8(201),this.writeU32(Y),this.writeI8(W.type),this.writeU8a(G);return}let X=W.data.length;if(X===1)this.writeU8(212);else if(X===2)this.writeU8(213);else if(X===4)this.writeU8(214);else if(X===8)this.writeU8(215);else if(X===16)this.writeU8(216);else if(X<256)this.writeU8(199),this.writeU8(X);else if(X<65536)this.writeU8(200),this.writeU16(X);else if(X<4294967296)this.writeU8(201),this.writeU32(X);else throw Error(`Too large extension object: ${X}`);this.writeI8(W.type),this.writeU8a(W.data)}writeU8(W){this.ensureBufferSizeToWrite(1),this.view.setUint8(this.pos,W),this.pos++}writeU8a(W){let X=W.length;this.ensureBufferSizeToWrite(X),this.bytes.set(W,this.pos),this.pos+=X}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),OD(this.view,this.pos,W),this.pos+=8}writeI64(W){this.ensureBufferSizeToWrite(8),gU(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 bU(W,X){return new hU(X).encodeSharedRef(W)}function mU(W){return`${W<0?"-":""}0x${Math.abs(W).toString(16).padStart(2,"0")}`}var Iy=16,wy=16;class wA{hit=0;miss=0;caches;maxKeyLength;maxLengthPerKey;constructor(W=Iy,X=wy){this.maxKeyLength=W,this.maxLengthPerKey=X,this.caches=[];for(let G=0;G<this.maxKeyLength;G++)this.caches.push([])}canBeCached(W){return W>0&&W<=this.maxKeyLength}find(W,X,G){let Y=this.caches[G-1];W:for(let J of Y){let Z=J.bytes;for(let V=0;V<G;V++)if(Z[V]!==W[X+V])continue W;return J.str}return null}store(W,X){let G=this.caches[W.length-1],Y={bytes:W,str:X};if(G.length>=this.maxLengthPerKey)G[Math.random()*G.length|0]=Y;else G.push(Y)}decode(W,X,G){let Y=this.find(W,X,G);if(Y!=null)return this.hit++,Y;this.miss++;let J=IA(W,X,G),Z=Uint8Array.prototype.slice.call(W,X,X+G);return this.store(Z,J),J}}var jA="array",HJ="map_key",MD="map_value",jy=(W)=>{if(typeof W==="string"||typeof W==="number")return W;throw new x9("The type of key must be string or number but "+typeof W)};class PD{stack=[];stackHeadPosition=-1;get length(){return this.stackHeadPosition+1}top(){return this.stack[this.stackHeadPosition]}pushArrayState(W){let X=this.getUninitializedStateFromPool();X.type=jA,X.position=0,X.size=W,X.array=Array(W)}pushMapState(W){let X=this.getUninitializedStateFromPool();X.type=HJ,X.readCount=0,X.size=W,X.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===jA){let G=W;G.size=0,G.array=void 0,G.position=0,G.type=void 0}if(W.type===HJ||W.type===MD){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,KA=new DataView(new ArrayBuffer(0)),Ky=new Uint8Array(KA.buffer);try{KA.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 TD=RangeError("Insufficient data"),Oy=new wA;class fU{extensionCodec;context;useBigInt64;rawStrings;maxStrLength;maxBinLength;maxArrayLength;maxMapLength;maxExtLength;keyDecoder;mapKeyConverter;totalPos=0;pos=0;view=KA;bytes=Ky;headByte=qJ;stack=new PD;entered=!1;constructor(W){this.extensionCodec=W?.extensionCodec??nX.defaultCodec,this.context=W?.context,this.useBigInt64=W?.useBigInt64??!1,this.rawStrings=W?.rawStrings??!1,this.maxStrLength=W?.maxStrLength??oX,this.maxBinLength=W?.maxBinLength??oX,this.maxArrayLength=W?.maxArrayLength??oX,this.maxMapLength=W?.maxMapLength??oX,this.maxExtLength=W?.maxExtLength??oX,this.keyDecoder=W?.keyDecoder!==void 0?W.keyDecoder:Oy,this.mapKeyConverter=W?.mapKeyConverter??jy}clone(){return new fU({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 X=NJ(W);this.bytes=X,this.view=new DataView(X.buffer,X.byteOffset,X.byteLength),this.pos=0}appendBuffer(W){if(this.headByte===qJ&&!this.hasRemaining(1))this.setBuffer(W);else{let X=this.bytes.subarray(this.pos),G=NJ(W),Y=new Uint8Array(X.length+G.length);Y.set(X),Y.set(G,X.length),this.setBuffer(Y)}}hasRemaining(W){return this.view.byteLength-this.pos>=W}createExtraByteError(W){let{view:X,pos:G}=this;return RangeError(`Extra ${X.byteLength-G} of ${X.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 X=this.doDecodeSync();if(this.hasRemaining(1))throw this.createExtraByteError(this.pos);return X}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 X=!1,G;for await(let V of W){if(X)throw this.entered=!1,this.createExtraByteError(this.totalPos);this.appendBuffer(V);try{G=this.doDecodeSync(),X=!0}catch(U){if(!(U instanceof RangeError))throw U}this.totalPos+=this.pos}if(X){if(this.hasRemaining(1))throw this.createExtraByteError(this.totalPos);return G}let{headByte:Y,pos:J,totalPos:Z}=this;throw RangeError(`Insufficient data in parsing ${mU(Y)} 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,X){if(this.entered){yield*this.clone().decodeMultiAsync(W,X);return}try{this.entered=!0;let G=X,Y=-1;for await(let J of W){if(X&&Y===0)throw this.createExtraByteError(this.totalPos);if(this.appendBuffer(J),G)Y=this.readArraySize(),G=!1,this.complete();try{while(!0)if(yield this.doDecodeSync(),--Y===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(),X;if(W>=224)X=W-256;else if(W<192)if(W<128)X=W;else if(W<144){let Y=W-128;if(Y!==0){this.pushMapState(Y),this.complete();continue W}else X={}}else if(W<160){let Y=W-144;if(Y!==0){this.pushArrayState(Y),this.complete();continue W}else X=[]}else{let Y=W-160;X=this.decodeString(Y,0)}else if(W===192)X=null;else if(W===194)X=!1;else if(W===195)X=!0;else if(W===202)X=this.readF32();else if(W===203)X=this.readF64();else if(W===204)X=this.readU8();else if(W===205)X=this.readU16();else if(W===206)X=this.readU32();else if(W===207)if(this.useBigInt64)X=this.readU64AsBigInt();else X=this.readU64();else if(W===208)X=this.readI8();else if(W===209)X=this.readI16();else if(W===210)X=this.readI32();else if(W===211)if(this.useBigInt64)X=this.readI64AsBigInt();else X=this.readI64();else if(W===217){let Y=this.lookU8();X=this.decodeString(Y,1)}else if(W===218){let Y=this.lookU16();X=this.decodeString(Y,2)}else if(W===219){let Y=this.lookU32();X=this.decodeString(Y,4)}else if(W===220){let Y=this.readU16();if(Y!==0){this.pushArrayState(Y),this.complete();continue W}else X=[]}else if(W===221){let Y=this.readU32();if(Y!==0){this.pushArrayState(Y),this.complete();continue W}else X=[]}else if(W===222){let Y=this.readU16();if(Y!==0){this.pushMapState(Y),this.complete();continue W}else X={}}else if(W===223){let Y=this.readU32();if(Y!==0){this.pushMapState(Y),this.complete();continue W}else X={}}else if(W===196){let Y=this.lookU8();X=this.decodeBinary(Y,1)}else if(W===197){let Y=this.lookU16();X=this.decodeBinary(Y,2)}else if(W===198){let Y=this.lookU32();X=this.decodeBinary(Y,4)}else if(W===212)X=this.decodeExtension(1,0);else if(W===213)X=this.decodeExtension(2,0);else if(W===214)X=this.decodeExtension(4,0);else if(W===215)X=this.decodeExtension(8,0);else if(W===216)X=this.decodeExtension(16,0);else if(W===199){let Y=this.lookU8();X=this.decodeExtension(Y,1)}else if(W===200){let Y=this.lookU16();X=this.decodeExtension(Y,2)}else if(W===201){let Y=this.lookU32();X=this.decodeExtension(Y,4)}else throw new x9(`Unrecognized type byte: ${mU(W)}`);this.complete();let G=this.stack;while(G.length>0){let Y=G.top();if(Y.type===jA)if(Y.array[Y.position]=X,Y.position++,Y.position===Y.size)X=Y.array,G.release(Y);else continue W;else if(Y.type===HJ){if(X==="__proto__")throw new x9("The key __proto__ is not allowed");Y.key=this.mapKeyConverter(X),Y.type=MD;continue W}else if(Y.map[Y.key]=X,Y.readCount++,Y.readCount===Y.size)X=Y.map,G.release(Y);else{Y.key=null,Y.type=HJ;continue W}}return X}}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 x9(`Unrecognized array type byte: ${mU(W)}`)}}pushMapState(W){if(W>this.maxMapLength)throw new x9(`Max length exceeded: map length (${W}) > maxMapLengthLength (${this.maxMapLength})`);this.stack.pushMapState(W)}pushArrayState(W){if(W>this.maxArrayLength)throw new x9(`Max length exceeded: array length (${W}) > maxArrayLength (${this.maxArrayLength})`);this.stack.pushArrayState(W)}decodeString(W,X){if(!this.rawStrings||this.stateIsMapKey())return this.decodeUtf8String(W,X);return this.decodeBinary(W,X)}decodeUtf8String(W,X){if(W>this.maxStrLength)throw new x9(`Max length exceeded: UTF-8 byte length (${W}) > maxStrLength (${this.maxStrLength})`);if(this.bytes.byteLength<this.pos+X+W)throw TD;let G=this.pos+X,Y;if(this.stateIsMapKey()&&this.keyDecoder?.canBeCached(W))Y=this.keyDecoder.decode(this.bytes,G,W);else Y=KD(this.bytes,G,W);return this.pos+=X+W,Y}stateIsMapKey(){if(this.stack.length>0)return this.stack.top().type===HJ;return!1}decodeBinary(W,X){if(W>this.maxBinLength)throw new x9(`Max length exceeded: bin length (${W}) > maxBinLength (${this.maxBinLength})`);if(!this.hasRemaining(W+X))throw TD;let G=this.pos+X,Y=this.bytes.subarray(G,G+W);return this.pos+=X+W,Y}decodeExtension(W,X){if(W>this.maxExtLength)throw new x9(`Max length exceeded: ext length (${W}) > maxExtLength (${this.maxExtLength})`);let G=this.view.getInt8(this.pos+X),Y=this.decodeBinary(W,X+1);return this.extensionCodec.decode(Y,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=DD(this.view,this.pos);return this.pos+=8,W}readI64(){let W=uU(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 zW(W,X){return new fU(X).decode(W)}/*! pako 2.1.0 https://github.com/nodeca/pako @license (MIT AND Zlib) */function eX(W){let X=W.length;while(--X>=0)W[X]=0}var Dy=0,QC=1,Cy=2,Ty=3,My=258,fA=29,BJ=256,OJ=BJ+1+fA,aX=30,pA=19,NC=2*OJ+1,IW=15,OA=16,Py=7,cA=256,qC=16,HC=17,AC=18,kA=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]),nU=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]),Ry=new Uint8Array([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7]),zC=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),Ly=512,W4=Array((OJ+2)*2);eX(W4);var wJ=Array(aX*2);eX(wJ);var DJ=Array(Ly);eX(DJ);var CJ=Array(My-Ty+1);eX(CJ);var lA=Array(fA);eX(lA);var iU=Array(aX);eX(iU);function DA(W,X,G,Y,J){this.static_tree=W,this.extra_bits=X,this.extra_base=G,this.elems=Y,this.max_length=J,this.has_stree=W&&W.length}var IC,wC,jC;function CA(W,X){this.dyn_tree=W,this.max_code=0,this.stat_desc=X}var KC=(W)=>{return W<256?DJ[W]:DJ[256+(W>>>7)]},TJ=(W,X)=>{W.pending_buf[W.pending++]=X&255,W.pending_buf[W.pending++]=X>>>8&255},m9=(W,X,G)=>{if(W.bi_valid>OA-G)W.bi_buf|=X<<W.bi_valid&65535,TJ(W,W.bi_buf),W.bi_buf=X>>OA-W.bi_valid,W.bi_valid+=G-OA;else W.bi_buf|=X<<W.bi_valid&65535,W.bi_valid+=G},A7=(W,X,G)=>{m9(W,G[X*2],G[X*2+1])},OC=(W,X)=>{let G=0;do G|=W&1,W>>>=1,G<<=1;while(--X>0);return G>>>1},By=(W)=>{if(W.bi_valid===16)TJ(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},Ey=(W,X)=>{let{dyn_tree:G,max_code:Y}=X,J=X.stat_desc.static_tree,Z=X.stat_desc.has_stree,V=X.stat_desc.extra_bits,U=X.stat_desc.extra_base,Q=X.stat_desc.max_length,N,q,A,H,I,w,O=0;for(H=0;H<=IW;H++)W.bl_count[H]=0;G[W.heap[W.heap_max]*2+1]=0;for(N=W.heap_max+1;N<NC;N++){if(q=W.heap[N],H=G[G[q*2+1]*2+1]+1,H>Q)H=Q,O++;if(G[q*2+1]=H,q>Y)continue;if(W.bl_count[H]++,I=0,q>=U)I=V[q-U];if(w=G[q*2],W.opt_len+=w*(H+I),Z)W.static_len+=w*(J[q*2+1]+I)}if(O===0)return;do{H=Q-1;while(W.bl_count[H]===0)H--;W.bl_count[H]--,W.bl_count[H+1]+=2,W.bl_count[Q]--,O-=2}while(O>0);for(H=Q;H!==0;H--){q=W.bl_count[H];while(q!==0){if(A=W.heap[--N],A>Y)continue;if(G[A*2+1]!==H)W.opt_len+=(H-G[A*2+1])*G[A*2],G[A*2+1]=H;q--}}},DC=(W,X,G)=>{let Y=Array(IW+1),J=0,Z,V;for(Z=1;Z<=IW;Z++)J=J+G[Z-1]<<1,Y[Z]=J;for(V=0;V<=X;V++){let U=W[V*2+1];if(U===0)continue;W[V*2]=OC(Y[U]++,U)}},$y=()=>{let W,X,G,Y,J,Z=Array(IW+1);G=0;for(Y=0;Y<fA-1;Y++){lA[Y]=G;for(W=0;W<1<<kA[Y];W++)CJ[G++]=Y}CJ[G-1]=Y,J=0;for(Y=0;Y<16;Y++){iU[Y]=J;for(W=0;W<1<<nU[Y];W++)DJ[J++]=Y}J>>=7;for(;Y<aX;Y++){iU[Y]=J<<7;for(W=0;W<1<<nU[Y]-7;W++)DJ[256+J++]=Y}for(X=0;X<=IW;X++)Z[X]=0;W=0;while(W<=143)W4[W*2+1]=8,W++,Z[8]++;while(W<=255)W4[W*2+1]=9,W++,Z[9]++;while(W<=279)W4[W*2+1]=7,W++,Z[7]++;while(W<=287)W4[W*2+1]=8,W++,Z[8]++;DC(W4,OJ+1,Z);for(W=0;W<aX;W++)wJ[W*2+1]=5,wJ[W*2]=OC(W,5);IC=new DA(W4,kA,BJ+1,OJ,IW),wC=new DA(wJ,nU,0,aX,IW),jC=new DA([],Ry,0,pA,Py)},CC=(W)=>{let X;for(X=0;X<OJ;X++)W.dyn_ltree[X*2]=0;for(X=0;X<aX;X++)W.dyn_dtree[X*2]=0;for(X=0;X<pA;X++)W.bl_tree[X*2]=0;W.dyn_ltree[cA*2]=1,W.opt_len=W.static_len=0,W.sym_next=W.matches=0},TC=(W)=>{if(W.bi_valid>8)TJ(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},RD=(W,X,G,Y)=>{let J=X*2,Z=G*2;return W[J]<W[Z]||W[J]===W[Z]&&Y[X]<=Y[G]},TA=(W,X,G)=>{let Y=W.heap[G],J=G<<1;while(J<=W.heap_len){if(J<W.heap_len&&RD(X,W.heap[J+1],W.heap[J],W.depth))J++;if(RD(X,Y,W.heap[J],W.depth))break;W.heap[G]=W.heap[J],G=J,J<<=1}W.heap[G]=Y},LD=(W,X,G)=>{let Y,J,Z=0,V,U;if(W.sym_next!==0)do if(Y=W.pending_buf[W.sym_buf+Z++]&255,Y+=(W.pending_buf[W.sym_buf+Z++]&255)<<8,J=W.pending_buf[W.sym_buf+Z++],Y===0)A7(W,J,X);else{if(V=CJ[J],A7(W,V+BJ+1,X),U=kA[V],U!==0)J-=lA[V],m9(W,J,U);if(Y--,V=KC(Y),A7(W,V,G),U=nU[V],U!==0)Y-=iU[V],m9(W,Y,U)}while(Z<W.sym_next);A7(W,cA,X)},_A=(W,X)=>{let G=X.dyn_tree,Y=X.stat_desc.static_tree,J=X.stat_desc.has_stree,Z=X.stat_desc.elems,V,U,Q=-1,N;W.heap_len=0,W.heap_max=NC;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(N=W.heap[++W.heap_len]=Q<2?++Q:0,G[N*2]=1,W.depth[N]=0,W.opt_len--,J)W.static_len-=Y[N*2+1];X.max_code=Q;for(V=W.heap_len>>1;V>=1;V--)TA(W,G,V);N=Z;do V=W.heap[1],W.heap[1]=W.heap[W.heap_len--],TA(W,G,1),U=W.heap[1],W.heap[--W.heap_max]=V,W.heap[--W.heap_max]=U,G[N*2]=G[V*2]+G[U*2],W.depth[N]=(W.depth[V]>=W.depth[U]?W.depth[V]:W.depth[U])+1,G[V*2+1]=G[U*2+1]=N,W.heap[1]=N++,TA(W,G,1);while(W.heap_len>=2);W.heap[--W.heap_max]=W.heap[1],Ey(W,X),DC(G,Q,W.bl_count)},BD=(W,X,G)=>{let Y,J=-1,Z,V=X[1],U=0,Q=7,N=4;if(V===0)Q=138,N=3;X[(G+1)*2+1]=65535;for(Y=0;Y<=G;Y++){if(Z=V,V=X[(Y+1)*2+1],++U<Q&&Z===V)continue;else if(U<N)W.bl_tree[Z*2]+=U;else if(Z!==0){if(Z!==J)W.bl_tree[Z*2]++;W.bl_tree[qC*2]++}else if(U<=10)W.bl_tree[HC*2]++;else W.bl_tree[AC*2]++;if(U=0,J=Z,V===0)Q=138,N=3;else if(Z===V)Q=6,N=3;else Q=7,N=4}},ED=(W,X,G)=>{let Y,J=-1,Z,V=X[1],U=0,Q=7,N=4;if(V===0)Q=138,N=3;for(Y=0;Y<=G;Y++){if(Z=V,V=X[(Y+1)*2+1],++U<Q&&Z===V)continue;else if(U<N)do A7(W,Z,W.bl_tree);while(--U!==0);else if(Z!==0){if(Z!==J)A7(W,Z,W.bl_tree),U--;A7(W,qC,W.bl_tree),m9(W,U-3,2)}else if(U<=10)A7(W,HC,W.bl_tree),m9(W,U-3,3);else A7(W,AC,W.bl_tree),m9(W,U-11,7);if(U=0,J=Z,V===0)Q=138,N=3;else if(Z===V)Q=6,N=3;else Q=7,N=4}},Fy=(W)=>{let X;BD(W,W.dyn_ltree,W.l_desc.max_code),BD(W,W.dyn_dtree,W.d_desc.max_code),_A(W,W.bl_desc);for(X=pA-1;X>=3;X--)if(W.bl_tree[zC[X]*2+1]!==0)break;return W.opt_len+=3*(X+1)+5+5+4,X},Sy=(W,X,G,Y)=>{let J;m9(W,X-257,5),m9(W,G-1,5),m9(W,Y-4,4);for(J=0;J<Y;J++)m9(W,W.bl_tree[zC[J]*2+1],3);ED(W,W.dyn_ltree,X-1),ED(W,W.dyn_dtree,G-1)},xy=(W)=>{let X=4093624447,G;for(G=0;G<=31;G++,X>>>=1)if(X&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<BJ;G++)if(W.dyn_ltree[G*2]!==0)return 1;return 0},$D=!1,ky=(W)=>{if(!$D)$y(),$D=!0;W.l_desc=new CA(W.dyn_ltree,IC),W.d_desc=new CA(W.dyn_dtree,wC),W.bl_desc=new CA(W.bl_tree,jC),W.bi_buf=0,W.bi_valid=0,CC(W)},MC=(W,X,G,Y)=>{if(m9(W,(Dy<<1)+(Y?1:0),3),TC(W),TJ(W,G),TJ(W,~G),G)W.pending_buf.set(W.window.subarray(X,X+G),W.pending);W.pending+=G},_y=(W)=>{m9(W,QC<<1,3),A7(W,cA,W4),By(W)},yy=(W,X,G,Y)=>{let J,Z,V=0;if(W.level>0){if(W.strm.data_type===2)W.strm.data_type=xy(W);if(_A(W,W.l_desc),_A(W,W.d_desc),V=Fy(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&&X!==-1)MC(W,X,G,Y);else if(W.strategy===4||Z===J)m9(W,(QC<<1)+(Y?1:0),3),LD(W,W4,wJ);else m9(W,(Cy<<1)+(Y?1:0),3),Sy(W,W.l_desc.max_code+1,W.d_desc.max_code+1,V+1),LD(W,W.dyn_ltree,W.dyn_dtree);if(CC(W),Y)TC(W)},vy=(W,X,G)=>{if(W.pending_buf[W.sym_buf+W.sym_next++]=X,W.pending_buf[W.sym_buf+W.sym_next++]=X>>8,W.pending_buf[W.sym_buf+W.sym_next++]=G,X===0)W.dyn_ltree[G*2]++;else W.matches++,X--,W.dyn_ltree[(CJ[G]+BJ+1)*2]++,W.dyn_dtree[KC(X)*2]++;return W.sym_next===W.sym_end},gy=ky,uy=MC,hy=yy,by=vy,my=_y,fy={_tr_init:gy,_tr_stored_block:uy,_tr_flush_block:hy,_tr_tally:by,_tr_align:my},py=(W,X,G,Y)=>{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+X[Y++]|0,Z=Z+J|0;while(--V);J%=65521,Z%=65521}return J|Z<<16|0},MJ=py,cy=()=>{let W,X=[];for(var G=0;G<256;G++){W=G;for(var Y=0;Y<8;Y++)W=W&1?3988292384^W>>>1:W>>>1;X[G]=W}return X},ly=new Uint32Array(cy()),dy=(W,X,G,Y)=>{let J=ly,Z=Y+G;W^=-1;for(let V=Y;V<Z;V++)W=W>>>8^J[(W^X[V])&255];return W^-1},r8=dy,KW={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"},CW={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:oy,_tr_stored_block:yA,_tr_flush_block:ny,_tr_tally:Q6,_tr_align:iy}=fy,{Z_NO_FLUSH:N6,Z_PARTIAL_FLUSH:ry,Z_FULL_FLUSH:ay,Z_FINISH:K5,Z_BLOCK:FD,Z_OK:W9,Z_STREAM_END:SD,Z_STREAM_ERROR:z7,Z_DATA_ERROR:sy,Z_BUF_ERROR:MA,Z_DEFAULT_COMPRESSION:ty,Z_FILTERED:ey,Z_HUFFMAN_ONLY:pU,Z_RLE:Wv,Z_FIXED:Xv,Z_DEFAULT_STRATEGY:Gv,Z_UNKNOWN:Yv,Z_DEFLATED:sU}=CW,Jv=9,Zv=15,Vv=8,Uv=29,Qv=256,vA=Qv+1+Uv,Nv=30,qv=19,Hv=2*vA+1,Av=15,m1=3,U6=258,I7=U6+m1+1,zv=32,sX=42,dA=57,gA=69,uA=73,hA=91,bA=103,wW=113,zJ=666,k9=1,WG=2,OW=3,XG=4,Iv=3,jW=(W,X)=>{return W.msg=KW[X],X},xD=(W)=>{return W*2-(W>4?9:0)},V6=(W)=>{let X=W.length;while(--X>=0)W[X]=0},wv=(W)=>{let X,G,Y,J=W.w_size;X=W.hash_size,Y=X;do G=W.head[--Y],W.head[Y]=G>=J?G-J:0;while(--X);X=J,Y=X;do G=W.prev[--Y],W.prev[Y]=G>=J?G-J:0;while(--X)},jv=(W,X,G)=>(X<<W.hash_shift^G)&W.hash_mask,q6=jv,G5=(W)=>{let X=W.state,G=X.pending;if(G>W.avail_out)G=W.avail_out;if(G===0)return;if(W.output.set(X.pending_buf.subarray(X.pending_out,X.pending_out+G),W.next_out),W.next_out+=G,X.pending_out+=G,W.total_out+=G,W.avail_out-=G,X.pending-=G,X.pending===0)X.pending_out=0},Y5=(W,X)=>{ny(W,W.block_start>=0?W.block_start:-1,W.strstart-W.block_start,X),W.block_start=W.strstart,G5(W.strm)},t1=(W,X)=>{W.pending_buf[W.pending++]=X},AJ=(W,X)=>{W.pending_buf[W.pending++]=X>>>8&255,W.pending_buf[W.pending++]=X&255},mA=(W,X,G,Y)=>{let J=W.avail_in;if(J>Y)J=Y;if(J===0)return 0;if(W.avail_in-=J,X.set(W.input.subarray(W.next_in,W.next_in+J),G),W.state.wrap===1)W.adler=MJ(W.adler,X,J,G);else if(W.state.wrap===2)W.adler=r8(W.adler,X,J,G);return W.next_in+=J,W.total_in+=J,J},PC=(W,X)=>{let{max_chain_length:G,strstart:Y}=W,J,Z,V=W.prev_length,U=W.nice_match,Q=W.strstart>W.w_size-I7?W.strstart-(W.w_size-I7):0,N=W.window,q=W.w_mask,A=W.prev,H=W.strstart+U6,I=N[Y+V-1],w=N[Y+V];if(W.prev_length>=W.good_match)G>>=2;if(U>W.lookahead)U=W.lookahead;do{if(J=X,N[J+V]!==w||N[J+V-1]!==I||N[J]!==N[Y]||N[++J]!==N[Y+1])continue;Y+=2,J++;do;while(N[++Y]===N[++J]&&N[++Y]===N[++J]&&N[++Y]===N[++J]&&N[++Y]===N[++J]&&N[++Y]===N[++J]&&N[++Y]===N[++J]&&N[++Y]===N[++J]&&N[++Y]===N[++J]&&Y<H);if(Z=U6-(H-Y),Y=H-U6,Z>V){if(W.match_start=X,V=Z,Z>=U)break;I=N[Y+V-1],w=N[Y+V]}}while((X=A[X&q])>Q&&--G!==0);if(V<=W.lookahead)return V;return W.lookahead},tX=(W)=>{let X=W.w_size,G,Y,J;do{if(Y=W.window_size-W.lookahead-W.strstart,W.strstart>=X+(X-I7)){if(W.window.set(W.window.subarray(X,X+X-Y),0),W.match_start-=X,W.strstart-=X,W.block_start-=X,W.insert>W.strstart)W.insert=W.strstart;wv(W),Y+=X}if(W.strm.avail_in===0)break;if(G=mA(W.strm,W.window,W.strstart+W.lookahead,Y),W.lookahead+=G,W.lookahead+W.insert>=m1){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+m1-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<m1)break}}while(W.lookahead<I7&&W.strm.avail_in!==0)},RC=(W,X)=>{let G=W.pending_buf_size-5>W.w_size?W.w_size:W.pending_buf_size-5,Y,J,Z,V=0,U=W.strm.avail_in;do{if(Y=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,Y>J+W.strm.avail_in)Y=J+W.strm.avail_in;if(Y>Z)Y=Z;if(Y<G&&(Y===0&&X!==K5||X===N6||Y!==J+W.strm.avail_in))break;if(V=X===K5&&Y===J+W.strm.avail_in?1:0,yA(W,0,0,V),W.pending_buf[W.pending-4]=Y,W.pending_buf[W.pending-3]=Y>>8,W.pending_buf[W.pending-2]=~Y,W.pending_buf[W.pending-1]=~Y>>8,G5(W.strm),J){if(J>Y)J=Y;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,Y-=J}if(Y)mA(W.strm,W.strm.output,W.strm.next_out,Y),W.strm.next_out+=Y,W.strm.avail_out-=Y,W.strm.total_out+=Y}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 XG;if(X!==N6&&X!==K5&&W.strm.avail_in===0&&W.strstart===W.block_start)return WG;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)mA(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||X===K5)&&X!==N6&&W.strm.avail_in===0&&J<=Z)Y=J>Z?Z:J,V=X===K5&&W.strm.avail_in===0&&Y===J?1:0,yA(W,W.block_start,Y,V),W.block_start+=Y,G5(W.strm);return V?OW:k9},PA=(W,X)=>{let G,Y;for(;;){if(W.lookahead<I7){if(tX(W),W.lookahead<I7&&X===N6)return k9;if(W.lookahead===0)break}if(G=0,W.lookahead>=m1)W.ins_h=q6(W,W.ins_h,W.window[W.strstart+m1-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-I7)W.match_length=PC(W,G);if(W.match_length>=m1)if(Y=Q6(W,W.strstart-W.match_start,W.match_length-m1),W.lookahead-=W.match_length,W.match_length<=W.max_lazy_match&&W.lookahead>=m1){W.match_length--;do W.strstart++,W.ins_h=q6(W,W.ins_h,W.window[W.strstart+m1-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 Y=Q6(W,0,W.window[W.strstart]),W.lookahead--,W.strstart++;if(Y){if(Y5(W,!1),W.strm.avail_out===0)return k9}}if(W.insert=W.strstart<m1-1?W.strstart:m1-1,X===K5){if(Y5(W,!0),W.strm.avail_out===0)return OW;return XG}if(W.sym_next){if(Y5(W,!1),W.strm.avail_out===0)return k9}return WG},iX=(W,X)=>{let G,Y,J;for(;;){if(W.lookahead<I7){if(tX(W),W.lookahead<I7&&X===N6)return k9;if(W.lookahead===0)break}if(G=0,W.lookahead>=m1)W.ins_h=q6(W,W.ins_h,W.window[W.strstart+m1-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=m1-1,G!==0&&W.prev_length<W.max_lazy_match&&W.strstart-G<=W.w_size-I7){if(W.match_length=PC(W,G),W.match_length<=5&&(W.strategy===ey||W.match_length===m1&&W.strstart-W.match_start>4096))W.match_length=m1-1}if(W.prev_length>=m1&&W.match_length<=W.prev_length){J=W.strstart+W.lookahead-m1,Y=Q6(W,W.strstart-1-W.prev_match,W.prev_length-m1),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+m1-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=m1-1,W.strstart++,Y){if(Y5(W,!1),W.strm.avail_out===0)return k9}}else if(W.match_available){if(Y=Q6(W,0,W.window[W.strstart-1]),Y)Y5(W,!1);if(W.strstart++,W.lookahead--,W.strm.avail_out===0)return k9}else W.match_available=1,W.strstart++,W.lookahead--}if(W.match_available)Y=Q6(W,0,W.window[W.strstart-1]),W.match_available=0;if(W.insert=W.strstart<m1-1?W.strstart:m1-1,X===K5){if(Y5(W,!0),W.strm.avail_out===0)return OW;return XG}if(W.sym_next){if(Y5(W,!1),W.strm.avail_out===0)return k9}return WG},Kv=(W,X)=>{let G,Y,J,Z,V=W.window;for(;;){if(W.lookahead<=U6){if(tX(W),W.lookahead<=U6&&X===N6)return k9;if(W.lookahead===0)break}if(W.match_length=0,W.lookahead>=m1&&W.strstart>0){if(J=W.strstart-1,Y=V[J],Y===V[++J]&&Y===V[++J]&&Y===V[++J]){Z=W.strstart+U6;do;while(Y===V[++J]&&Y===V[++J]&&Y===V[++J]&&Y===V[++J]&&Y===V[++J]&&Y===V[++J]&&Y===V[++J]&&Y===V[++J]&&J<Z);if(W.match_length=U6-(Z-J),W.match_length>W.lookahead)W.match_length=W.lookahead}}if(W.match_length>=m1)G=Q6(W,1,W.match_length-m1),W.lookahead-=W.match_length,W.strstart+=W.match_length,W.match_length=0;else G=Q6(W,0,W.window[W.strstart]),W.lookahead--,W.strstart++;if(G){if(Y5(W,!1),W.strm.avail_out===0)return k9}}if(W.insert=0,X===K5){if(Y5(W,!0),W.strm.avail_out===0)return OW;return XG}if(W.sym_next){if(Y5(W,!1),W.strm.avail_out===0)return k9}return WG},Ov=(W,X)=>{let G;for(;;){if(W.lookahead===0){if(tX(W),W.lookahead===0){if(X===N6)return k9;break}}if(W.match_length=0,G=Q6(W,0,W.window[W.strstart]),W.lookahead--,W.strstart++,G){if(Y5(W,!1),W.strm.avail_out===0)return k9}}if(W.insert=0,X===K5){if(Y5(W,!0),W.strm.avail_out===0)return OW;return XG}if(W.sym_next){if(Y5(W,!1),W.strm.avail_out===0)return k9}return WG};function H7(W,X,G,Y,J){this.good_length=W,this.max_lazy=X,this.nice_length=G,this.max_chain=Y,this.func=J}var IJ=[new H7(0,0,0,0,RC),new H7(4,4,8,4,PA),new H7(4,5,16,8,PA),new H7(4,6,32,32,PA),new H7(4,4,16,16,iX),new H7(8,16,32,32,iX),new H7(8,16,128,128,iX),new H7(8,32,128,256,iX),new H7(32,128,258,1024,iX),new H7(32,258,258,4096,iX)],Dv=(W)=>{W.window_size=2*W.w_size,V6(W.head),W.max_lazy_match=IJ[W.level].max_lazy,W.good_match=IJ[W.level].good_length,W.nice_match=IJ[W.level].nice_length,W.max_chain_length=IJ[W.level].max_chain,W.strstart=0,W.block_start=0,W.lookahead=0,W.insert=0,W.match_length=W.prev_length=m1-1,W.match_available=0,W.ins_h=0};function Cv(){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=sU,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(Hv*2),this.dyn_dtree=new Uint16Array((2*Nv+1)*2),this.bl_tree=new Uint16Array((2*qv+1)*2),V6(this.dyn_ltree),V6(this.dyn_dtree),V6(this.bl_tree),this.l_desc=null,this.d_desc=null,this.bl_desc=null,this.bl_count=new Uint16Array(Av+1),this.heap=new Uint16Array(2*vA+1),V6(this.heap),this.heap_len=0,this.heap_max=0,this.depth=new Uint16Array(2*vA+1),V6(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 EJ=(W)=>{if(!W)return 1;let X=W.state;if(!X||X.strm!==W||X.status!==sX&&X.status!==dA&&X.status!==gA&&X.status!==uA&&X.status!==hA&&X.status!==bA&&X.status!==wW&&X.status!==zJ)return 1;return 0},LC=(W)=>{if(EJ(W))return jW(W,z7);W.total_in=W.total_out=0,W.data_type=Yv;let X=W.state;if(X.pending=0,X.pending_out=0,X.wrap<0)X.wrap=-X.wrap;return X.status=X.wrap===2?dA:X.wrap?sX:wW,W.adler=X.wrap===2?0:1,X.last_flush=-2,oy(X),W9},BC=(W)=>{let X=LC(W);if(X===W9)Dv(W.state);return X},Tv=(W,X)=>{if(EJ(W)||W.state.wrap!==2)return z7;return W.state.gzhead=X,W9},EC=(W,X,G,Y,J,Z)=>{if(!W)return z7;let V=1;if(X===ty)X=6;if(Y<0)V=0,Y=-Y;else if(Y>15)V=2,Y-=16;if(J<1||J>Jv||G!==sU||Y<8||Y>15||X<0||X>9||Z<0||Z>Xv||Y===8&&V!==1)return jW(W,z7);if(Y===8)Y=9;let U=new Cv;return W.state=U,U.strm=W,U.status=sX,U.wrap=V,U.gzhead=null,U.w_bits=Y,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+m1-1)/m1),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=X,U.strategy=Z,U.method=G,BC(W)},Mv=(W,X)=>{return EC(W,X,sU,Zv,Vv,Gv)},Pv=(W,X)=>{if(EJ(W)||X>FD||X<0)return W?jW(W,z7):z7;let G=W.state;if(!W.output||W.avail_in!==0&&!W.input||G.status===zJ&&X!==K5)return jW(W,W.avail_out===0?MA:z7);let Y=G.last_flush;if(G.last_flush=X,G.pending!==0){if(G5(W),W.avail_out===0)return G.last_flush=-1,W9}else if(W.avail_in===0&&xD(X)<=xD(Y)&&X!==K5)return jW(W,MA);if(G.status===zJ&&W.avail_in!==0)return jW(W,MA);if(G.status===sX&&G.wrap===0)G.status=wW;if(G.status===sX){let J=sU+(G.w_bits-8<<4)<<8,Z=-1;if(G.strategy>=pU||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|=zv;if(J+=31-J%31,AJ(G,J),G.strstart!==0)AJ(G,W.adler>>>16),AJ(G,W.adler&65535);if(W.adler=1,G.status=wW,G5(W),G.pending!==0)return G.last_flush=-1,W9}if(G.status===dA)if(W.adler=0,t1(G,31),t1(G,139),t1(G,8),!G.gzhead){if(t1(G,0),t1(G,0),t1(G,0),t1(G,0),t1(G,0),t1(G,G.level===9?2:G.strategy>=pU||G.level<2?4:0),t1(G,Iv),G.status=wW,G5(W),G.pending!==0)return G.last_flush=-1,W9}else{if(t1(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)),t1(G,G.gzhead.time&255),t1(G,G.gzhead.time>>8&255),t1(G,G.gzhead.time>>16&255),t1(G,G.gzhead.time>>24&255),t1(G,G.level===9?2:G.strategy>=pU||G.level<2?4:0),t1(G,G.gzhead.os&255),G.gzhead.extra&&G.gzhead.extra.length)t1(G,G.gzhead.extra.length&255),t1(G,G.gzhead.extra.length>>8&255);if(G.gzhead.hcrc)W.adler=r8(W.adler,G.pending_buf,G.pending,0);G.gzindex=0,G.status=gA}if(G.status===gA){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=r8(W.adler,G.pending_buf,G.pending-J,J);if(G.gzindex+=U,G5(W),G.pending!==0)return G.last_flush=-1,W9;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=r8(W.adler,G.pending_buf,G.pending-J,J);G.gzindex=0}G.status=uA}if(G.status===uA){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=r8(W.adler,G.pending_buf,G.pending-J,J);if(G5(W),G.pending!==0)return G.last_flush=-1,W9;J=0}if(G.gzindex<G.gzhead.name.length)Z=G.gzhead.name.charCodeAt(G.gzindex++)&255;else Z=0;t1(G,Z)}while(Z!==0);if(G.gzhead.hcrc&&G.pending>J)W.adler=r8(W.adler,G.pending_buf,G.pending-J,J);G.gzindex=0}G.status=hA}if(G.status===hA){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=r8(W.adler,G.pending_buf,G.pending-J,J);if(G5(W),G.pending!==0)return G.last_flush=-1,W9;J=0}if(G.gzindex<G.gzhead.comment.length)Z=G.gzhead.comment.charCodeAt(G.gzindex++)&255;else Z=0;t1(G,Z)}while(Z!==0);if(G.gzhead.hcrc&&G.pending>J)W.adler=r8(W.adler,G.pending_buf,G.pending-J,J)}G.status=bA}if(G.status===bA){if(G.gzhead.hcrc){if(G.pending+2>G.pending_buf_size){if(G5(W),G.pending!==0)return G.last_flush=-1,W9}t1(G,W.adler&255),t1(G,W.adler>>8&255),W.adler=0}if(G.status=wW,G5(W),G.pending!==0)return G.last_flush=-1,W9}if(W.avail_in!==0||G.lookahead!==0||X!==N6&&G.status!==zJ){let J=G.level===0?RC(G,X):G.strategy===pU?Ov(G,X):G.strategy===Wv?Kv(G,X):IJ[G.level].func(G,X);if(J===OW||J===XG)G.status=zJ;if(J===k9||J===OW){if(W.avail_out===0)G.last_flush=-1;return W9}if(J===WG){if(X===ry)iy(G);else if(X!==FD){if(yA(G,0,0,!1),X===ay){if(V6(G.head),G.lookahead===0)G.strstart=0,G.block_start=0,G.insert=0}}if(G5(W),W.avail_out===0)return G.last_flush=-1,W9}}if(X!==K5)return W9;if(G.wrap<=0)return SD;if(G.wrap===2)t1(G,W.adler&255),t1(G,W.adler>>8&255),t1(G,W.adler>>16&255),t1(G,W.adler>>24&255),t1(G,W.total_in&255),t1(G,W.total_in>>8&255),t1(G,W.total_in>>16&255),t1(G,W.total_in>>24&255);else AJ(G,W.adler>>>16),AJ(G,W.adler&65535);if(G5(W),G.wrap>0)G.wrap=-G.wrap;return G.pending!==0?W9:SD},Rv=(W)=>{if(EJ(W))return z7;let X=W.state.status;return W.state=null,X===wW?jW(W,sy):W9},Lv=(W,X)=>{let G=X.length;if(EJ(W))return z7;let Y=W.state,J=Y.wrap;if(J===2||J===1&&Y.status!==sX||Y.lookahead)return z7;if(J===1)W.adler=MJ(W.adler,X,G,0);if(Y.wrap=0,G>=Y.w_size){if(J===0)V6(Y.head),Y.strstart=0,Y.block_start=0,Y.insert=0;let Q=new Uint8Array(Y.w_size);Q.set(X.subarray(G-Y.w_size,G),0),X=Q,G=Y.w_size}let{avail_in:Z,next_in:V,input:U}=W;W.avail_in=G,W.next_in=0,W.input=X,tX(Y);while(Y.lookahead>=m1){let Q=Y.strstart,N=Y.lookahead-(m1-1);do Y.ins_h=q6(Y,Y.ins_h,Y.window[Q+m1-1]),Y.prev[Q&Y.w_mask]=Y.head[Y.ins_h],Y.head[Y.ins_h]=Q,Q++;while(--N);Y.strstart=Q,Y.lookahead=m1-1,tX(Y)}return Y.strstart+=Y.lookahead,Y.block_start=Y.strstart,Y.insert=Y.lookahead,Y.lookahead=0,Y.match_length=Y.prev_length=m1-1,Y.match_available=0,W.next_in=V,W.input=U,W.avail_in=Z,Y.wrap=J,W9},Bv=Mv,Ev=EC,$v=BC,Fv=LC,Sv=Tv,xv=Pv,kv=Rv,_v=Lv,yv="pako deflate (from Nodeca project)",jJ={deflateInit:Bv,deflateInit2:Ev,deflateReset:$v,deflateResetKeep:Fv,deflateSetHeader:Sv,deflate:xv,deflateEnd:kv,deflateSetDictionary:_v,deflateInfo:yv},vv=(W,X)=>{return Object.prototype.hasOwnProperty.call(W,X)},gv=function(W){let X=Array.prototype.slice.call(arguments,1);while(X.length){let G=X.shift();if(!G)continue;if(typeof G!=="object")throw TypeError(G+"must be non-object");for(let Y in G)if(vv(G,Y))W[Y]=G[Y]}return W},uv=(W)=>{let X=0;for(let Y=0,J=W.length;Y<J;Y++)X+=W[Y].length;let G=new Uint8Array(X);for(let Y=0,J=0,Z=W.length;Y<Z;Y++){let V=W[Y];G.set(V,J),J+=V.length}return G},tU={assign:gv,flattenChunks:uv},$C=!0;try{String.fromCharCode.apply(null,new Uint8Array(1))}catch(W){$C=!1}var PJ=new Uint8Array(256);for(let W=0;W<256;W++)PJ[W]=W>=252?6:W>=248?5:W>=240?4:W>=224?3:W>=192?2:1;PJ[254]=PJ[254]=1;var hv=(W)=>{if(typeof TextEncoder==="function"&&TextEncoder.prototype.encode)return new TextEncoder().encode(W);let X,G,Y,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(Y=W.charCodeAt(J+1),(Y&64512)===56320)G=65536+(G-55296<<10)+(Y-56320),J++}U+=G<128?1:G<2048?2:G<65536?3:4}X=new Uint8Array(U);for(Z=0,J=0;Z<U;J++){if(G=W.charCodeAt(J),(G&64512)===55296&&J+1<V){if(Y=W.charCodeAt(J+1),(Y&64512)===56320)G=65536+(G-55296<<10)+(Y-56320),J++}if(G<128)X[Z++]=G;else if(G<2048)X[Z++]=192|G>>>6,X[Z++]=128|G&63;else if(G<65536)X[Z++]=224|G>>>12,X[Z++]=128|G>>>6&63,X[Z++]=128|G&63;else X[Z++]=240|G>>>18,X[Z++]=128|G>>>12&63,X[Z++]=128|G>>>6&63,X[Z++]=128|G&63}return X},bv=(W,X)=>{if(X<65534){if(W.subarray&&$C)return String.fromCharCode.apply(null,W.length===X?W:W.subarray(0,X))}let G="";for(let Y=0;Y<X;Y++)G+=String.fromCharCode(W[Y]);return G},mv=(W,X)=>{let G=X||W.length;if(typeof TextDecoder==="function"&&TextDecoder.prototype.decode)return new TextDecoder().decode(W.subarray(0,X));let Y,J,Z=Array(G*2);for(J=0,Y=0;Y<G;){let V=W[Y++];if(V<128){Z[J++]=V;continue}let U=PJ[V];if(U>4){Z[J++]=65533,Y+=U-1;continue}V&=U===2?31:U===3?15:7;while(U>1&&Y<G)V=V<<6|W[Y++]&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 bv(Z,J)},fv=(W,X)=>{if(X=X||W.length,X>W.length)X=W.length;let G=X-1;while(G>=0&&(W[G]&192)===128)G--;if(G<0)return X;if(G===0)return X;return G+PJ[W[G]]>X?G:X},RJ={string2buf:hv,buf2string:mv,utf8border:fv};function pv(){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 FC=pv,SC=Object.prototype.toString,{Z_NO_FLUSH:cv,Z_SYNC_FLUSH:lv,Z_FULL_FLUSH:dv,Z_FINISH:ov,Z_OK:rU,Z_STREAM_END:nv,Z_DEFAULT_COMPRESSION:iv,Z_DEFAULT_STRATEGY:rv,Z_DEFLATED:av}=CW;function $J(W){this.options=tU.assign({level:iv,method:av,chunkSize:16384,windowBits:15,memLevel:8,strategy:rv},W||{});let X=this.options;if(X.raw&&X.windowBits>0)X.windowBits=-X.windowBits;else if(X.gzip&&X.windowBits>0&&X.windowBits<16)X.windowBits+=16;this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new FC,this.strm.avail_out=0;let G=jJ.deflateInit2(this.strm,X.level,X.method,X.windowBits,X.memLevel,X.strategy);if(G!==rU)throw Error(KW[G]);if(X.header)jJ.deflateSetHeader(this.strm,X.header);if(X.dictionary){let Y;if(typeof X.dictionary==="string")Y=RJ.string2buf(X.dictionary);else if(SC.call(X.dictionary)==="[object ArrayBuffer]")Y=new Uint8Array(X.dictionary);else Y=X.dictionary;if(G=jJ.deflateSetDictionary(this.strm,Y),G!==rU)throw Error(KW[G]);this._dict_set=!0}}$J.prototype.push=function(W,X){let G=this.strm,Y=this.options.chunkSize,J,Z;if(this.ended)return!1;if(X===~~X)Z=X;else Z=X===!0?ov:cv;if(typeof W==="string")G.input=RJ.string2buf(W);else if(SC.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(Y),G.next_out=0,G.avail_out=Y;if((Z===lv||Z===dv)&&G.avail_out<=6){this.onData(G.output.subarray(0,G.next_out)),G.avail_out=0;continue}if(J=jJ.deflate(G,Z),J===nv){if(G.next_out>0)this.onData(G.output.subarray(0,G.next_out));return J=jJ.deflateEnd(this.strm),this.onEnd(J),this.ended=!0,J===rU}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};$J.prototype.onData=function(W){this.chunks.push(W)};$J.prototype.onEnd=function(W){if(W===rU)this.result=tU.flattenChunks(this.chunks);this.chunks=[],this.err=W,this.msg=this.strm.msg};function oA(W,X){let G=new $J(X);if(G.push(W,!0),G.err)throw G.msg||KW[G.err];return G.result}function sv(W,X){return X=X||{},X.raw=!0,oA(W,X)}function tv(W,X){return X=X||{},X.gzip=!0,oA(W,X)}var ev=$J,Wg=oA,Xg=sv,Gg=tv,Yg=CW,Jg={Deflate:ev,deflate:Wg,deflateRaw:Xg,gzip:Gg,constants:Yg},cU=16209,Zg=16191,Vg=function(X,G){let Y,J,Z,V,U,Q,N,q,A,H,I,w,O,T,x,h,$,F,u,l,p,s,y,t,H0=X.state;Y=X.next_in,y=X.input,J=Y+(X.avail_in-5),Z=X.next_out,t=X.output,V=Z-(G-X.avail_out),U=Z+(X.avail_out-257),Q=H0.dmax,N=H0.wsize,q=H0.whave,A=H0.wnext,H=H0.window,I=H0.hold,w=H0.bits,O=H0.lencode,T=H0.distcode,x=(1<<H0.lenbits)-1,h=(1<<H0.distbits)-1;W:do{if(w<15)I+=y[Y++]<<w,w+=8,I+=y[Y++]<<w,w+=8;$=O[I&x];X:for(;;){if(F=$>>>24,I>>>=F,w-=F,F=$>>>16&255,F===0)t[Z++]=$&65535;else if(F&16){if(u=$&65535,F&=15,F){if(w<F)I+=y[Y++]<<w,w+=8;u+=I&(1<<F)-1,I>>>=F,w-=F}if(w<15)I+=y[Y++]<<w,w+=8,I+=y[Y++]<<w,w+=8;$=T[I&h];G:for(;;){if(F=$>>>24,I>>>=F,w-=F,F=$>>>16&255,F&16){if(l=$&65535,F&=15,w<F){if(I+=y[Y++]<<w,w+=8,w<F)I+=y[Y++]<<w,w+=8}if(l+=I&(1<<F)-1,l>Q){X.msg="invalid distance too far back",H0.mode=cU;break W}if(I>>>=F,w-=F,F=Z-V,l>F){if(F=l-F,F>q){if(H0.sane){X.msg="invalid distance too far back",H0.mode=cU;break W}}if(p=0,s=H,A===0){if(p+=N-F,F<u){u-=F;do t[Z++]=H[p++];while(--F);p=Z-l,s=t}}else if(A<F){if(p+=N+A-F,F-=A,F<u){u-=F;do t[Z++]=H[p++];while(--F);if(p=0,A<u){F=A,u-=F;do t[Z++]=H[p++];while(--F);p=Z-l,s=t}}}else if(p+=A-F,F<u){u-=F;do t[Z++]=H[p++];while(--F);p=Z-l,s=t}while(u>2)t[Z++]=s[p++],t[Z++]=s[p++],t[Z++]=s[p++],u-=3;if(u){if(t[Z++]=s[p++],u>1)t[Z++]=s[p++]}}else{p=Z-l;do t[Z++]=t[p++],t[Z++]=t[p++],t[Z++]=t[p++],u-=3;while(u>2);if(u){if(t[Z++]=t[p++],u>1)t[Z++]=t[p++]}}}else if((F&64)===0){$=T[($&65535)+(I&(1<<F)-1)];continue G}else{X.msg="invalid distance code",H0.mode=cU;break W}break}}else if((F&64)===0){$=O[($&65535)+(I&(1<<F)-1)];continue X}else if(F&32){H0.mode=Zg;break W}else{X.msg="invalid literal/length code",H0.mode=cU;break W}break}}while(Y<J&&Z<U);u=w>>3,Y-=u,w-=u<<3,I&=(1<<w)-1,X.next_in=Y,X.next_out=Z,X.avail_in=Y<J?5+(J-Y):5-(Y-J),X.avail_out=Z<U?257+(U-Z):257-(Z-U),H0.hold=I,H0.bits=w;return},rX=15,kD=852,_D=592,yD=0,RA=1,vD=2,Ug=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]),Qg=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]),Ng=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]),qg=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]),Hg=(W,X,G,Y,J,Z,V,U)=>{let Q=U.bits,N=0,q=0,A=0,H=0,I=0,w=0,O=0,T=0,x=0,h=0,$,F,u,l,p,s=null,y,t=new Uint16Array(rX+1),H0=new Uint16Array(rX+1),g=null,d,P,E;for(N=0;N<=rX;N++)t[N]=0;for(q=0;q<Y;q++)t[X[G+q]]++;I=Q;for(H=rX;H>=1;H--)if(t[H]!==0)break;if(I>H)I=H;if(H===0)return J[Z++]=20971520,J[Z++]=20971520,U.bits=1,0;for(A=1;A<H;A++)if(t[A]!==0)break;if(I<A)I=A;T=1;for(N=1;N<=rX;N++)if(T<<=1,T-=t[N],T<0)return-1;if(T>0&&(W===yD||H!==1))return-1;H0[1]=0;for(N=1;N<rX;N++)H0[N+1]=H0[N]+t[N];for(q=0;q<Y;q++)if(X[G+q]!==0)V[H0[X[G+q]]++]=q;if(W===yD)s=g=V,y=20;else if(W===RA)s=Ug,g=Qg,y=257;else s=Ng,g=qg,y=0;if(h=0,q=0,N=A,p=Z,w=I,O=0,u=-1,x=1<<I,l=x-1,W===RA&&x>kD||W===vD&&x>_D)return 1;for(;;){if(d=N-O,V[q]+1<y)P=0,E=V[q];else if(V[q]>=y)P=g[V[q]-y],E=s[V[q]-y];else P=96,E=0;$=1<<N-O,F=1<<w,A=F;do F-=$,J[p+(h>>O)+F]=d<<24|P<<16|E|0;while(F!==0);$=1<<N-1;while(h&$)$>>=1;if($!==0)h&=$-1,h+=$;else h=0;if(q++,--t[N]===0){if(N===H)break;N=X[G+V[q]]}if(N>I&&(h&l)!==u){if(O===0)O=I;p+=A,w=N-O,T=1<<w;while(w+O<H){if(T-=t[w+O],T<=0)break;w++,T<<=1}if(x+=1<<w,W===RA&&x>kD||W===vD&&x>_D)return 1;u=h&l,J[u]=I<<24|w<<16|p-Z|0}}if(h!==0)J[p+h]=N-O<<24|4194304|0;return U.bits=I,0},KJ=Hg,Ag=0,xC=1,kC=2,{Z_FINISH:gD,Z_BLOCK:zg,Z_TREES:lU,Z_OK:DW,Z_STREAM_END:Ig,Z_NEED_DICT:wg,Z_STREAM_ERROR:O5,Z_DATA_ERROR:_C,Z_MEM_ERROR:yC,Z_BUF_ERROR:jg,Z_DEFLATED:uD}=CW,eU=16180,hD=16181,bD=16182,mD=16183,fD=16184,pD=16185,cD=16186,lD=16187,dD=16188,oD=16189,aU=16190,e7=16191,LA=16192,nD=16193,BA=16194,iD=16195,rD=16196,aD=16197,sD=16198,dU=16199,oU=16200,tD=16201,eD=16202,WC=16203,XC=16204,GC=16205,EA=16206,YC=16207,JC=16208,O8=16209,vC=16210,gC=16211,Kg=852,Og=592,Dg=15,Cg=Dg,ZC=(W)=>{return(W>>>24&255)+(W>>>8&65280)+((W&65280)<<8)+((W&255)<<24)};function Tg(){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 TW=(W)=>{if(!W)return 1;let X=W.state;if(!X||X.strm!==W||X.mode<eU||X.mode>gC)return 1;return 0},uC=(W)=>{if(TW(W))return O5;let X=W.state;if(W.total_in=W.total_out=X.total=0,W.msg="",X.wrap)W.adler=X.wrap&1;return X.mode=eU,X.last=0,X.havedict=0,X.flags=-1,X.dmax=32768,X.head=null,X.hold=0,X.bits=0,X.lencode=X.lendyn=new Int32Array(Kg),X.distcode=X.distdyn=new Int32Array(Og),X.sane=1,X.back=-1,DW},hC=(W)=>{if(TW(W))return O5;let X=W.state;return X.wsize=0,X.whave=0,X.wnext=0,uC(W)},bC=(W,X)=>{let G;if(TW(W))return O5;let Y=W.state;if(X<0)G=0,X=-X;else if(G=(X>>4)+5,X<48)X&=15;if(X&&(X<8||X>15))return O5;if(Y.window!==null&&Y.wbits!==X)Y.window=null;return Y.wrap=G,Y.wbits=X,hC(W)},mC=(W,X)=>{if(!W)return O5;let G=new Tg;W.state=G,G.strm=W,G.window=null,G.mode=eU;let Y=bC(W,X);if(Y!==DW)W.state=null;return Y},Mg=(W)=>{return mC(W,Cg)},VC=!0,$A,FA,Pg=(W)=>{if(VC){$A=new Int32Array(512),FA=new Int32Array(32);let X=0;while(X<144)W.lens[X++]=8;while(X<256)W.lens[X++]=9;while(X<280)W.lens[X++]=7;while(X<288)W.lens[X++]=8;KJ(xC,W.lens,0,288,$A,0,W.work,{bits:9}),X=0;while(X<32)W.lens[X++]=5;KJ(kC,W.lens,0,32,FA,0,W.work,{bits:5}),VC=!1}W.lencode=$A,W.lenbits=9,W.distcode=FA,W.distbits=5},fC=(W,X,G,Y)=>{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(Y>=Z.wsize)Z.window.set(X.subarray(G-Z.wsize,G),0),Z.wnext=0,Z.whave=Z.wsize;else{if(J=Z.wsize-Z.wnext,J>Y)J=Y;if(Z.window.set(X.subarray(G-Y,G-Y+J),Z.wnext),Y-=J,Y)Z.window.set(X.subarray(G-Y,G),0),Z.wnext=Y,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},Rg=(W,X)=>{let G,Y,J,Z,V,U,Q,N,q,A,H,I,w,O,T=0,x,h,$,F,u,l,p,s,y=new Uint8Array(4),t,H0,g=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]);if(TW(W)||!W.output||!W.input&&W.avail_in!==0)return O5;if(G=W.state,G.mode===e7)G.mode=LA;V=W.next_out,J=W.output,Q=W.avail_out,Z=W.next_in,Y=W.input,U=W.avail_in,N=G.hold,q=G.bits,A=U,H=Q,s=DW;W:for(;;)switch(G.mode){case eU:if(G.wrap===0){G.mode=LA;break}while(q<16){if(U===0)break W;U--,N+=Y[Z++]<<q,q+=8}if(G.wrap&2&&N===35615){if(G.wbits===0)G.wbits=15;G.check=0,y[0]=N&255,y[1]=N>>>8&255,G.check=r8(G.check,y,2,0),N=0,q=0,G.mode=hD;break}if(G.head)G.head.done=!1;if(!(G.wrap&1)||(((N&255)<<8)+(N>>8))%31){W.msg="incorrect header check",G.mode=O8;break}if((N&15)!==uD){W.msg="unknown compression method",G.mode=O8;break}if(N>>>=4,q-=4,p=(N&15)+8,G.wbits===0)G.wbits=p;if(p>15||p>G.wbits){W.msg="invalid window size",G.mode=O8;break}G.dmax=1<<G.wbits,G.flags=0,W.adler=G.check=1,G.mode=N&512?oD:e7,N=0,q=0;break;case hD:while(q<16){if(U===0)break W;U--,N+=Y[Z++]<<q,q+=8}if(G.flags=N,(G.flags&255)!==uD){W.msg="unknown compression method",G.mode=O8;break}if(G.flags&57344){W.msg="unknown header flags set",G.mode=O8;break}if(G.head)G.head.text=N>>8&1;if(G.flags&512&&G.wrap&4)y[0]=N&255,y[1]=N>>>8&255,G.check=r8(G.check,y,2,0);N=0,q=0,G.mode=bD;case bD:while(q<32){if(U===0)break W;U--,N+=Y[Z++]<<q,q+=8}if(G.head)G.head.time=N;if(G.flags&512&&G.wrap&4)y[0]=N&255,y[1]=N>>>8&255,y[2]=N>>>16&255,y[3]=N>>>24&255,G.check=r8(G.check,y,4,0);N=0,q=0,G.mode=mD;case mD:while(q<16){if(U===0)break W;U--,N+=Y[Z++]<<q,q+=8}if(G.head)G.head.xflags=N&255,G.head.os=N>>8;if(G.flags&512&&G.wrap&4)y[0]=N&255,y[1]=N>>>8&255,G.check=r8(G.check,y,2,0);N=0,q=0,G.mode=fD;case fD:if(G.flags&1024){while(q<16){if(U===0)break W;U--,N+=Y[Z++]<<q,q+=8}if(G.length=N,G.head)G.head.extra_len=N;if(G.flags&512&&G.wrap&4)y[0]=N&255,y[1]=N>>>8&255,G.check=r8(G.check,y,2,0);N=0,q=0}else if(G.head)G.head.extra=null;G.mode=pD;case pD:if(G.flags&1024){if(I=G.length,I>U)I=U;if(I){if(G.head){if(p=G.head.extra_len-G.length,!G.head.extra)G.head.extra=new Uint8Array(G.head.extra_len);G.head.extra.set(Y.subarray(Z,Z+I),p)}if(G.flags&512&&G.wrap&4)G.check=r8(G.check,Y,I,Z);U-=I,Z+=I,G.length-=I}if(G.length)break W}G.length=0,G.mode=cD;case cD:if(G.flags&2048){if(U===0)break W;I=0;do if(p=Y[Z+I++],G.head&&p&&G.length<65536)G.head.name+=String.fromCharCode(p);while(p&&I<U);if(G.flags&512&&G.wrap&4)G.check=r8(G.check,Y,I,Z);if(U-=I,Z+=I,p)break W}else if(G.head)G.head.name=null;G.length=0,G.mode=lD;case lD:if(G.flags&4096){if(U===0)break W;I=0;do if(p=Y[Z+I++],G.head&&p&&G.length<65536)G.head.comment+=String.fromCharCode(p);while(p&&I<U);if(G.flags&512&&G.wrap&4)G.check=r8(G.check,Y,I,Z);if(U-=I,Z+=I,p)break W}else if(G.head)G.head.comment=null;G.mode=dD;case dD:if(G.flags&512){while(q<16){if(U===0)break W;U--,N+=Y[Z++]<<q,q+=8}if(G.wrap&4&&N!==(G.check&65535)){W.msg="header crc mismatch",G.mode=O8;break}N=0,q=0}if(G.head)G.head.hcrc=G.flags>>9&1,G.head.done=!0;W.adler=G.check=0,G.mode=e7;break;case oD:while(q<32){if(U===0)break W;U--,N+=Y[Z++]<<q,q+=8}W.adler=G.check=ZC(N),N=0,q=0,G.mode=aU;case aU:if(G.havedict===0)return W.next_out=V,W.avail_out=Q,W.next_in=Z,W.avail_in=U,G.hold=N,G.bits=q,wg;W.adler=G.check=1,G.mode=e7;case e7:if(X===zg||X===lU)break W;case LA:if(G.last){N>>>=q&7,q-=q&7,G.mode=EA;break}while(q<3){if(U===0)break W;U--,N+=Y[Z++]<<q,q+=8}switch(G.last=N&1,N>>>=1,q-=1,N&3){case 0:G.mode=nD;break;case 1:if(Pg(G),G.mode=dU,X===lU){N>>>=2,q-=2;break W}break;case 2:G.mode=rD;break;case 3:W.msg="invalid block type",G.mode=O8}N>>>=2,q-=2;break;case nD:N>>>=q&7,q-=q&7;while(q<32){if(U===0)break W;U--,N+=Y[Z++]<<q,q+=8}if((N&65535)!==(N>>>16^65535)){W.msg="invalid stored block lengths",G.mode=O8;break}if(G.length=N&65535,N=0,q=0,G.mode=BA,X===lU)break W;case BA:G.mode=iD;case iD:if(I=G.length,I){if(I>U)I=U;if(I>Q)I=Q;if(I===0)break W;J.set(Y.subarray(Z,Z+I),V),U-=I,Z+=I,Q-=I,V+=I,G.length-=I;break}G.mode=e7;break;case rD:while(q<14){if(U===0)break W;U--,N+=Y[Z++]<<q,q+=8}if(G.nlen=(N&31)+257,N>>>=5,q-=5,G.ndist=(N&31)+1,N>>>=5,q-=5,G.ncode=(N&15)+4,N>>>=4,q-=4,G.nlen>286||G.ndist>30){W.msg="too many length or distance symbols",G.mode=O8;break}G.have=0,G.mode=aD;case aD:while(G.have<G.ncode){while(q<3){if(U===0)break W;U--,N+=Y[Z++]<<q,q+=8}G.lens[g[G.have++]]=N&7,N>>>=3,q-=3}while(G.have<19)G.lens[g[G.have++]]=0;if(G.lencode=G.lendyn,G.lenbits=7,t={bits:G.lenbits},s=KJ(Ag,G.lens,0,19,G.lencode,0,G.work,t),G.lenbits=t.bits,s){W.msg="invalid code lengths set",G.mode=O8;break}G.have=0,G.mode=sD;case sD:while(G.have<G.nlen+G.ndist){for(;;){if(T=G.lencode[N&(1<<G.lenbits)-1],x=T>>>24,h=T>>>16&255,$=T&65535,x<=q)break;if(U===0)break W;U--,N+=Y[Z++]<<q,q+=8}if($<16)N>>>=x,q-=x,G.lens[G.have++]=$;else{if($===16){H0=x+2;while(q<H0){if(U===0)break W;U--,N+=Y[Z++]<<q,q+=8}if(N>>>=x,q-=x,G.have===0){W.msg="invalid bit length repeat",G.mode=O8;break}p=G.lens[G.have-1],I=3+(N&3),N>>>=2,q-=2}else if($===17){H0=x+3;while(q<H0){if(U===0)break W;U--,N+=Y[Z++]<<q,q+=8}N>>>=x,q-=x,p=0,I=3+(N&7),N>>>=3,q-=3}else{H0=x+7;while(q<H0){if(U===0)break W;U--,N+=Y[Z++]<<q,q+=8}N>>>=x,q-=x,p=0,I=11+(N&127),N>>>=7,q-=7}if(G.have+I>G.nlen+G.ndist){W.msg="invalid bit length repeat",G.mode=O8;break}while(I--)G.lens[G.have++]=p}}if(G.mode===O8)break;if(G.lens[256]===0){W.msg="invalid code -- missing end-of-block",G.mode=O8;break}if(G.lenbits=9,t={bits:G.lenbits},s=KJ(xC,G.lens,0,G.nlen,G.lencode,0,G.work,t),G.lenbits=t.bits,s){W.msg="invalid literal/lengths set",G.mode=O8;break}if(G.distbits=6,G.distcode=G.distdyn,t={bits:G.distbits},s=KJ(kC,G.lens,G.nlen,G.ndist,G.distcode,0,G.work,t),G.distbits=t.bits,s){W.msg="invalid distances set",G.mode=O8;break}if(G.mode=dU,X===lU)break W;case dU:G.mode=oU;case oU:if(U>=6&&Q>=258){if(W.next_out=V,W.avail_out=Q,W.next_in=Z,W.avail_in=U,G.hold=N,G.bits=q,Vg(W,H),V=W.next_out,J=W.output,Q=W.avail_out,Z=W.next_in,Y=W.input,U=W.avail_in,N=G.hold,q=G.bits,G.mode===e7)G.back=-1;break}G.back=0;for(;;){if(T=G.lencode[N&(1<<G.lenbits)-1],x=T>>>24,h=T>>>16&255,$=T&65535,x<=q)break;if(U===0)break W;U--,N+=Y[Z++]<<q,q+=8}if(h&&(h&240)===0){F=x,u=h,l=$;for(;;){if(T=G.lencode[l+((N&(1<<F+u)-1)>>F)],x=T>>>24,h=T>>>16&255,$=T&65535,F+x<=q)break;if(U===0)break W;U--,N+=Y[Z++]<<q,q+=8}N>>>=F,q-=F,G.back+=F}if(N>>>=x,q-=x,G.back+=x,G.length=$,h===0){G.mode=GC;break}if(h&32){G.back=-1,G.mode=e7;break}if(h&64){W.msg="invalid literal/length code",G.mode=O8;break}G.extra=h&15,G.mode=tD;case tD:if(G.extra){H0=G.extra;while(q<H0){if(U===0)break W;U--,N+=Y[Z++]<<q,q+=8}G.length+=N&(1<<G.extra)-1,N>>>=G.extra,q-=G.extra,G.back+=G.extra}G.was=G.length,G.mode=eD;case eD:for(;;){if(T=G.distcode[N&(1<<G.distbits)-1],x=T>>>24,h=T>>>16&255,$=T&65535,x<=q)break;if(U===0)break W;U--,N+=Y[Z++]<<q,q+=8}if((h&240)===0){F=x,u=h,l=$;for(;;){if(T=G.distcode[l+((N&(1<<F+u)-1)>>F)],x=T>>>24,h=T>>>16&255,$=T&65535,F+x<=q)break;if(U===0)break W;U--,N+=Y[Z++]<<q,q+=8}N>>>=F,q-=F,G.back+=F}if(N>>>=x,q-=x,G.back+=x,h&64){W.msg="invalid distance code",G.mode=O8;break}G.offset=$,G.extra=h&15,G.mode=WC;case WC:if(G.extra){H0=G.extra;while(q<H0){if(U===0)break W;U--,N+=Y[Z++]<<q,q+=8}G.offset+=N&(1<<G.extra)-1,N>>>=G.extra,q-=G.extra,G.back+=G.extra}if(G.offset>G.dmax){W.msg="invalid distance too far back",G.mode=O8;break}G.mode=XC;case XC:if(Q===0)break W;if(I=H-Q,G.offset>I){if(I=G.offset-I,I>G.whave){if(G.sane){W.msg="invalid distance too far back",G.mode=O8;break}}if(I>G.wnext)I-=G.wnext,w=G.wsize-I;else w=G.wnext-I;if(I>G.length)I=G.length;O=G.window}else O=J,w=V-G.offset,I=G.length;if(I>Q)I=Q;Q-=I,G.length-=I;do J[V++]=O[w++];while(--I);if(G.length===0)G.mode=oU;break;case GC:if(Q===0)break W;J[V++]=G.length,Q--,G.mode=oU;break;case EA:if(G.wrap){while(q<32){if(U===0)break W;U--,N|=Y[Z++]<<q,q+=8}if(H-=Q,W.total_out+=H,G.total+=H,G.wrap&4&&H)W.adler=G.check=G.flags?r8(G.check,J,H,V-H):MJ(G.check,J,H,V-H);if(H=Q,G.wrap&4&&(G.flags?N:ZC(N))!==G.check){W.msg="incorrect data check",G.mode=O8;break}N=0,q=0}G.mode=YC;case YC:if(G.wrap&&G.flags){while(q<32){if(U===0)break W;U--,N+=Y[Z++]<<q,q+=8}if(G.wrap&4&&N!==(G.total&4294967295)){W.msg="incorrect length check",G.mode=O8;break}N=0,q=0}G.mode=JC;case JC:s=Ig;break W;case O8:s=_C;break W;case vC:return yC;case gC:default:return O5}if(W.next_out=V,W.avail_out=Q,W.next_in=Z,W.avail_in=U,G.hold=N,G.bits=q,G.wsize||H!==W.avail_out&&G.mode<O8&&(G.mode<EA||X!==gD)){if(fC(W,W.output,W.next_out,H-W.avail_out));}if(A-=W.avail_in,H-=W.avail_out,W.total_in+=A,W.total_out+=H,G.total+=H,G.wrap&4&&H)W.adler=G.check=G.flags?r8(G.check,J,H,W.next_out-H):MJ(G.check,J,H,W.next_out-H);if(W.data_type=G.bits+(G.last?64:0)+(G.mode===e7?128:0)+(G.mode===dU||G.mode===BA?256:0),(A===0&&H===0||X===gD)&&s===DW)s=jg;return s},Lg=(W)=>{if(TW(W))return O5;let X=W.state;if(X.window)X.window=null;return W.state=null,DW},Bg=(W,X)=>{if(TW(W))return O5;let G=W.state;if((G.wrap&2)===0)return O5;return G.head=X,X.done=!1,DW},Eg=(W,X)=>{let G=X.length,Y,J,Z;if(TW(W))return O5;if(Y=W.state,Y.wrap!==0&&Y.mode!==aU)return O5;if(Y.mode===aU){if(J=1,J=MJ(J,X,G,0),J!==Y.check)return _C}if(Z=fC(W,X,G,G),Z)return Y.mode=vC,yC;return Y.havedict=1,DW},$g=hC,Fg=bC,Sg=uC,xg=Mg,kg=mC,_g=Rg,yg=Lg,vg=Bg,gg=Eg,ug="pako inflate (from Nodeca project)",X4={inflateReset:$g,inflateReset2:Fg,inflateResetKeep:Sg,inflateInit:xg,inflateInit2:kg,inflate:_g,inflateEnd:yg,inflateGetHeader:vg,inflateSetDictionary:gg,inflateInfo:ug};function hg(){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 bg=hg,pC=Object.prototype.toString,{Z_NO_FLUSH:mg,Z_FINISH:fg,Z_OK:LJ,Z_STREAM_END:SA,Z_NEED_DICT:xA,Z_STREAM_ERROR:pg,Z_DATA_ERROR:UC,Z_MEM_ERROR:cg}=CW;function FJ(W){this.options=tU.assign({chunkSize:65536,windowBits:15,to:""},W||{});let X=this.options;if(X.raw&&X.windowBits>=0&&X.windowBits<16){if(X.windowBits=-X.windowBits,X.windowBits===0)X.windowBits=-15}if(X.windowBits>=0&&X.windowBits<16&&!(W&&W.windowBits))X.windowBits+=32;if(X.windowBits>15&&X.windowBits<48){if((X.windowBits&15)===0)X.windowBits|=15}this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new FC,this.strm.avail_out=0;let G=X4.inflateInit2(this.strm,X.windowBits);if(G!==LJ)throw Error(KW[G]);if(this.header=new bg,X4.inflateGetHeader(this.strm,this.header),X.dictionary){if(typeof X.dictionary==="string")X.dictionary=RJ.string2buf(X.dictionary);else if(pC.call(X.dictionary)==="[object ArrayBuffer]")X.dictionary=new Uint8Array(X.dictionary);if(X.raw){if(G=X4.inflateSetDictionary(this.strm,X.dictionary),G!==LJ)throw Error(KW[G])}}}FJ.prototype.push=function(W,X){let G=this.strm,Y=this.options.chunkSize,J=this.options.dictionary,Z,V,U;if(this.ended)return!1;if(X===~~X)V=X;else V=X===!0?fg:mg;if(pC.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(Y),G.next_out=0,G.avail_out=Y;if(Z=X4.inflate(G,V),Z===xA&&J){if(Z=X4.inflateSetDictionary(G,J),Z===LJ)Z=X4.inflate(G,V);else if(Z===UC)Z=xA}while(G.avail_in>0&&Z===SA&&G.state.wrap>0&&W[G.next_in]!==0)X4.inflateReset(G),Z=X4.inflate(G,V);switch(Z){case pg:case UC:case xA:case cg:return this.onEnd(Z),this.ended=!0,!1}if(U=G.avail_out,G.next_out){if(G.avail_out===0||Z===SA)if(this.options.to==="string"){let Q=RJ.utf8border(G.output,G.next_out),N=G.next_out-Q,q=RJ.buf2string(G.output,Q);if(G.next_out=N,G.avail_out=Y-N,N)G.output.set(G.output.subarray(Q,Q+N),0);this.onData(q)}else this.onData(G.output.length===G.next_out?G.output:G.output.subarray(0,G.next_out))}if(Z===LJ&&U===0)continue;if(Z===SA)return Z=X4.inflateEnd(this.strm),this.onEnd(Z),this.ended=!0,!0;if(G.avail_in===0)break}return!0};FJ.prototype.onData=function(W){this.chunks.push(W)};FJ.prototype.onEnd=function(W){if(W===LJ)if(this.options.to==="string")this.result=this.chunks.join("");else this.result=tU.flattenChunks(this.chunks);this.chunks=[],this.err=W,this.msg=this.strm.msg};function nA(W,X){let G=new FJ(X);if(G.push(W),G.err)throw G.msg||KW[G.err];return G.result}function lg(W,X){return X=X||{},X.raw=!0,nA(W,X)}var dg=FJ,og=nA,ng=lg,ig=nA,rg=CW,ag={Inflate:dg,inflate:og,inflateRaw:ng,ungzip:ig,constants:rg},{Deflate:sg,deflate:tg,deflateRaw:eg,gzip:Wu}=Jg,{Inflate:Xu,inflate:Gu,inflateRaw:Yu,ungzip:Ju}=ag,Zu=sg,Vu=tg,Uu=eg,Qu=Wu,Nu=Xu,qu=Gu,Hu=Yu,Au=Ju,zu=CW,GG={Deflate:Zu,deflate:Vu,deflateRaw:Uu,gzip:Qu,Inflate:Nu,inflate:qu,inflateRaw:Hu,ungzip:Au,constants:zu};function cC(){let W=Date.now(),X=0;return{now(){return W=Math.max(W,Date.now()),X++,{physical:W,logical:X}},update(G){if(!G||typeof G.physical!=="number"||typeof G.logical!=="number")return;W=Math.max(W,G.physical),X=Math.max(X,G.logical)+1},compare(G,Y){if(!G&&!Y)return 0;if(!G)return-1;if(!Y)return 1;if(G.physical!==Y.physical)return G.physical>Y.physical?1:-1;if(G.logical!==Y.logical)return G.logical>Y.logical?1:-1;return 0}}}var MW=(W)=>W?.physical>Date.now()+7200000;function lC(W,X,G){let Y=X.timestamp;if(MW(Y))return{resolved:!1};if(X?.value?.priority===!0&&typeof X.id==="string"&&X.id.startsWith("user:")&&"role"in X.value){let{priority:Z,...V}=X.value;return{resolved:!0,value:V,timestamp:Y}}if(X?.value?.priority!==void 0){let{priority:Z,...V}=X.value;X={...X,value:V}}if(!W?.timestamp)return{resolved:!0,value:X.value,timestamp:Y};let J=G.compare(Y,W.timestamp);if(J<0)return{resolved:!1};if(J===0&&JSON.stringify(X.value)<=JSON.stringify(W.value))return{resolved:!1};return{resolved:!0,value:X.value,timestamp:Y}}var iA=Math.PI/180,dC=(W)=>Math.sin(W*iA/2)**2,Iu=new Intl.Collator().compare,SJ={$eq:(W,X)=>W===X,$ne:(W,X)=>W!==X,$gt:(W,X)=>W>X,$gte:(W,X)=>W>=X,$lt:(W,X)=>W<X,$lte:(W,X)=>W<=X,$in:(W,X)=>Array.isArray(X)&&(Array.isArray(W)?W.some((G)=>X.includes(G)):X.includes(W)),$between:(W,[X,G])=>W>=X&&W<=G,$near:(W,{latitude:X,longitude:G,radius:Y})=>{let J=W?.value??W,Z=J?.latitude??J?.location?.latitude,V=J?.longitude??J?.location?.longitude;return[Z,V,X,G,Y].every(Number.isFinite)&&dC(Z-X)+Math.cos(X*iA)*Math.cos(Z*iA)*dC(V-G)<=Math.sin(Math.min(Y/12742,Math.PI/2))**2},$exists:(W,X)=>X?W!==void 0:W===void 0,$startsWith:(W,X)=>typeof W==="string"&&W.startsWith(X),$endsWith:(W,X)=>typeof W==="string"&&W.endsWith(X),$contains:(W,X)=>typeof W==="string"&&W.includes(X),$text:{global:(W,X)=>{let G=(J)=>String(J).normalize("NFD").replace(/[\u0300-\u036f]/g,"").toLowerCase().replace(/[^\w\s]/g,""),Y=G(X);return Object.values(W).some((J)=>typeof J==="object"?null.fieldSearch(J,Y):G(J).includes(Y))},field:(W,X)=>{let G=(J)=>String(J).normalize("NFD").replace(/[\u0300-\u036f]/g,"").toLowerCase().replace(/[^\w\s]/g,""),Y=G(X);return Array.isArray(W)?W.some((J)=>G(J).includes(Y)):G(W).includes(Y)}},$like:(W,X)=>typeof W==="string"&&typeof X==="string"&&new RegExp(`^${X.replace(/%/g,".*").replace(/_/g,".")}$`,"i").test(W),$regex:(W,X)=>typeof W==="string"&&new RegExp(X.$regex||X,"i").test(W),$and:(W,X,G)=>X.every((Y)=>G.createFilter(Y,G.allNodes)(W)),$or:(W,X,G)=>X.some((Y)=>G.createFilter(Y,G.allNodes)(W)),$not:(W,X,G)=>!G.createFilter(X,G.allNodes)(W),$edge:(W,X,G)=>{if(!W.edges?.length||typeof X!=="object"||X===null)return!1;let Y=G.createFilter(X,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(Y(Q))V.push(Q);Q.edges?.forEach((N)=>!Z.has(N)&&Z.add(N)&&J.push(N))}if(V.length)W._edgeResult=V;return V.length>0}},rA=(W,X)=>X.split(".").reduce((G,Y)=>G&&typeof G==="object"&&(Y in G)?G[Y]:void 0,W),WQ=(W,X)=>{if(Object.keys(W).length===0)return()=>!0;return(G)=>Object.entries(W).every(([Y,J])=>{if(Y.startsWith("$"))return SJ[Y](G,J,{createFilter:WQ,allNodes:X});let Z=rA(G.value,Y);if(Z===void 0)Z=rA(G,Y);if(J instanceof RegExp)return J.test(String(Z));if(typeof J!=="object"||J===null)return SJ.$eq(Z,J);return Object.entries(J).every(([V,U])=>{if(V==="$text")return SJ.$text.field(Z,U);if(V==="$between"&&U.every((Q)=>Q instanceof Date))return SJ.$between(new Date(Z),U);return SJ[V]?.(Z,U,{createFilter:WQ,allNodes:X})??!1})})},aA=(W,X)=>{let{$edge:G,...Y}=X.query||{},J=WQ(Y,W),Z=Object.values(W).filter(J),U=[...G?(()=>{let Q=WQ({$edge:G},W);Z.forEach((q)=>Q(q));let N=new Map;return Z.forEach((q)=>{if(q._edgeResult)q._edgeResult.forEach((A)=>N.set(A.id,A)),delete q._edgeResult}),Array.from(N.values())})():Z];if(X.field){let Q=X.order==="asc"?1:-1,N=U.map((q)=>[rA(q.value,X.field),q]);N.sort(([q,A],[H,I])=>((typeof q==="string"&&typeof H==="string"?Iu(q,H):(q??0)-(H??0))||(A.id<I.id?-1:1))*Q),U=N.map(([,q])=>q)}if(X.$after){let Q=U.findIndex((N)=>N.id===X.$after);U=Q>=0?U.slice(Q+1):[]}if(X.$before){let Q=U.findIndex((N)=>N.id===X.$before);U=Q>=0?U.slice(0,Q):[]}if(X.$limit)U=U.slice(0,X.$limit);return U.map((Q)=>({...Q,edges:(Q.edges??[]).filter((N)=>Object.hasOwn(W,N))}))};var _9=(()=>{let W=()=>{};return new Proxy(console,{get:(X,G)=>globalThis.__gdbDebug?X[G].bind(X):W})})(),YG=typeof globalThis==="object"&&"crypto"in globalThis?globalThis.crypto:void 0;/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */function PQ(W){return W instanceof Uint8Array||ArrayBuffer.isView(W)&&W.constructor.name==="Uint8Array"}function Qz(W){if(!Number.isSafeInteger(W)||W<0)throw Error("positive integer expected, got "+W)}function EW(W,...X){if(!PQ(W))throw Error("Uint8Array expected");if(X.length>0&&!X.includes(W.length))throw Error("Uint8Array expected of length "+X+", got length="+W.length)}function AT(W){if(typeof W!=="function"||typeof W.create!=="function")throw Error("Hash should be wrapped by utils.createHasher");Qz(W.outputLen),Qz(W.blockLen)}function AQ(W,X=!0){if(W.destroyed)throw Error("Hash instance has been destroyed");if(X&&W.finished)throw Error("Hash#digest() has already been called")}function wu(W,X){EW(W);let G=X.outputLen;if(W.length<G)throw Error("digestInto() expects output buffer of length at least "+G)}function zQ(...W){for(let X=0;X<W.length;X++)W[X].fill(0)}function sA(W){return new DataView(W.buffer,W.byteOffset,W.byteLength)}function w7(W,X){return W<<32-X|W>>>X}var zT=(()=>typeof Uint8Array.from([]).toHex==="function"&&typeof Uint8Array.fromHex==="function")(),ju=Array.from({length:256},(W,X)=>X.toString(16).padStart(2,"0"));function VG(W){if(EW(W),zT)return W.toHex();let X="";for(let G=0;G<W.length;G++)X+=ju[W[G]];return X}var G4={_0:48,_9:57,A:65,F:70,a:97,f:102};function oC(W){if(W>=G4._0&&W<=G4._9)return W-G4._0;if(W>=G4.A&&W<=G4.F)return W-(G4.A-10);if(W>=G4.a&&W<=G4.f)return W-(G4.a-10);return}function IQ(W){if(typeof W!=="string")throw Error("hex string expected, got "+typeof W);if(zT)return Uint8Array.fromHex(W);let X=W.length,G=X/2;if(X%2)throw Error("hex string expected, got unpadded hex of length "+X);let Y=new Uint8Array(G);for(let J=0,Z=0;J<G;J++,Z+=2){let V=oC(W.charCodeAt(Z)),U=oC(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)}Y[J]=V*16+U}return Y}function IT(W){if(typeof W!=="string")throw Error("string expected");return new Uint8Array(new TextEncoder().encode(W))}function jz(W){if(typeof W==="string")W=IT(W);return EW(W),W}function j7(...W){let X=0;for(let Y=0;Y<W.length;Y++){let J=W[Y];EW(J),X+=J.length}let G=new Uint8Array(X);for(let Y=0,J=0;Y<W.length;Y++){let Z=W[Y];G.set(Z,J),J+=Z.length}return G}class Kz{}function Ku(W){let X=(Y)=>W().update(jz(Y)).digest(),G=W();return X.outputLen=G.outputLen,X.blockLen=G.blockLen,X.create=()=>W(),X}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 Ou(W,X,G,Y){if(typeof W.setBigUint64==="function")return W.setBigUint64(X,G,Y);let J=BigInt(32),Z=BigInt(4294967295),V=Number(G>>J&Z),U=Number(G&Z),Q=Y?4:0,N=Y?0:4;W.setUint32(X+Q,V,Y),W.setUint32(X+N,U,Y)}function Du(W,X,G){return W&X^~W&G}function Cu(W,X,G){return W&X^W&G^X&G}class wT extends Kz{constructor(W,X,G,Y){super();this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=W,this.outputLen=X,this.padOffset=G,this.isLE=Y,this.buffer=new Uint8Array(W),this.view=sA(this.buffer)}update(W){AQ(this),W=jz(W),EW(W);let{view:X,buffer:G,blockLen:Y}=this,J=W.length;for(let Z=0;Z<J;){let V=Math.min(Y-this.pos,J-Z);if(V===Y){let U=sA(W);for(;Y<=J-Z;Z+=Y)this.process(U,Z);continue}if(G.set(W.subarray(Z,Z+V),this.pos),this.pos+=V,Z+=V,this.pos===Y)this.process(X,0),this.pos=0}return this.length+=W.length,this.roundClean(),this}digestInto(W){AQ(this),wu(W,this),this.finished=!0;let{buffer:X,view:G,blockLen:Y,isLE:J}=this,{pos:Z}=this;if(X[Z++]=128,zQ(this.buffer.subarray(Z)),this.padOffset>Y-Z)this.process(G,0),Z=0;for(let q=Z;q<Y;q++)X[q]=0;Ou(G,Y-8,BigInt(this.length*8),J),this.process(G,0);let V=sA(W),U=this.outputLen;if(U%4)throw Error("_sha2: outputLen should be aligned to 32bit");let Q=U/4,N=this.get();if(Q>N.length)throw Error("_sha2: outputLen bigger than state");for(let q=0;q<Q;q++)V.setUint32(4*q,N[q],J)}digest(){let{buffer:W,outputLen:X}=this;this.digestInto(W);let G=W.slice(0,X);return this.destroy(),G}_cloneInto(W){W||(W=new this.constructor),W.set(...this.get());let{blockLen:X,buffer:G,length:Y,finished:J,destroyed:Z,pos:V}=this;if(W.destroyed=Z,W.finished=J,W.length=Y,W.pos=V,Y%X)W.buffer.set(G);return W}clone(){return this._cloneInto()}}var H6=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Tu=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]),A6=new Uint32Array(64);class jT extends wT{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:X,C:G,D:Y,E:J,F:Z,G:V,H:U}=this;return[W,X,G,Y,J,Z,V,U]}set(W,X,G,Y,J,Z,V,U){this.A=W|0,this.B=X|0,this.C=G|0,this.D=Y|0,this.E=J|0,this.F=Z|0,this.G=V|0,this.H=U|0}process(W,X){for(let q=0;q<16;q++,X+=4)A6[q]=W.getUint32(X,!1);for(let q=16;q<64;q++){let A=A6[q-15],H=A6[q-2],I=w7(A,7)^w7(A,18)^A>>>3,w=w7(H,17)^w7(H,19)^H>>>10;A6[q]=w+A6[q-7]+I+A6[q-16]|0}let{A:G,B:Y,C:J,D:Z,E:V,F:U,G:Q,H:N}=this;for(let q=0;q<64;q++){let A=w7(V,6)^w7(V,11)^w7(V,25),H=N+A+Du(V,U,Q)+Tu[q]+A6[q]|0,I=(w7(G,2)^w7(G,13)^w7(G,22))+Cu(G,Y,J)|0;N=Q,Q=U,U=V,V=Z+H|0,Z=J,J=Y,Y=G,G=H+I|0}G=G+this.A|0,Y=Y+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,N=N+this.H|0,this.set(G,Y,J,Z,V,U,Q,N)}roundClean(){zQ(A6)}destroy(){this.set(0,0,0,0,0,0,0,0),zQ(this.buffer)}}var Nz=Ku(()=>new jT);class Oz extends Kz{constructor(W,X){super();this.finished=!1,this.destroyed=!1,AT(W);let G=jz(X);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 Y=this.blockLen,J=new Uint8Array(Y);J.set(G.length>Y?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),zQ(J)}update(W){return AQ(this),this.iHash.update(W),this}digestInto(W){AQ(this),EW(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:X,iHash:G,finished:Y,destroyed:J,blockLen:Z,outputLen:V}=this;return W=W,W.finished=Y,W.destroyed=J,W.blockLen=Z,W.outputLen=V,W.oHash=X._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 KT=(W,X,G)=>new Oz(W,X).update(G).digest();KT.create=(W,X)=>new Oz(W,X);/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */var Dz=BigInt(0),qz=BigInt(1);function wQ(W,X=""){if(typeof W!=="boolean"){let G=X&&`"${X}"`;throw Error(G+"expected boolean, got type="+typeof W)}return W}function PW(W,X,G=""){let Y=PQ(W),J=W?.length,Z=X!==void 0;if(!Y||Z&&J!==X){let V=G&&`"${G}" `,U=Z?` of length ${X}`:"",Q=Y?`length=${J}`:`type=${typeof W}`;throw Error(V+"expected Uint8Array"+U+", got "+Q)}return W}function XQ(W){let X=W.toString(16);return X.length&1?"0"+X:X}function OT(W){if(typeof W!=="string")throw Error("hex string expected, got "+typeof W);return W===""?Dz:BigInt("0x"+W)}function HG(W){return OT(VG(W))}function DT(W){return EW(W),OT(VG(Uint8Array.from(W).reverse()))}function LQ(W,X){return IQ(W.toString(16).padStart(X*2,"0"))}function CT(W,X){return LQ(W,X).reverse()}function f8(W,X,G){let Y;if(typeof X==="string")try{Y=IQ(X)}catch(Z){throw Error(W+" must be hex string or Uint8Array, cause: "+Z)}else if(PQ(X))Y=Uint8Array.from(X);else throw Error(W+" must be hex string or Uint8Array");let J=Y.length;if(typeof G==="number"&&J!==G)throw Error(W+" of length "+G+" expected, got "+J);return Y}var tA=(W)=>typeof W==="bigint"&&Dz<=W;function Hz(W,X,G){return tA(W)&&tA(X)&&tA(G)&&X<=W&&W<G}function Mu(W,X,G,Y){if(!Hz(X,G,Y))throw Error("expected valid "+W+": "+G+" <= n < "+Y+", got "+X)}function TT(W){let X;for(X=0;W>Dz;W>>=qz,X+=1);return X}var bJ=(W)=>(qz<<BigInt(W))-qz;function Pu(W,X,G){if(typeof W!=="number"||W<2)throw Error("hashLen must be a number");if(typeof X!=="number"||X<2)throw Error("qByteLen must be a number");if(typeof G!=="function")throw Error("hmacFn must be a function");let Y=(H)=>new Uint8Array(H),J=(H)=>Uint8Array.of(H),Z=Y(W),V=Y(W),U=0,Q=()=>{Z.fill(1),V.fill(0),U=0},N=(...H)=>G(V,Z,...H),q=(H=Y(0))=>{if(V=N(J(0),H),Z=N(),H.length===0)return;V=N(J(1),H),Z=N()},A=()=>{if(U++>=1000)throw Error("drbg: tried 1000 values");let H=0,I=[];while(H<X){Z=N();let w=Z.slice();I.push(w),H+=Z.length}return j7(...I)};return(H,I)=>{Q(),q(H);let w=void 0;while(!(w=I(A())))q();return Q(),w}}function Cz(W,X,G={}){if(!W||typeof W!=="object")throw Error("expected valid options object");function Y(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(X).forEach(([J,Z])=>Y(J,Z,!1)),Object.entries(G).forEach(([J,Z])=>Y(J,Z,!0))}function nC(W){let X=new WeakMap;return(G,...Y)=>{let J=X.get(G);if(J!==void 0)return J;let Z=W(G,...Y);return X.set(G,Z),Z}}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */var y9=BigInt(0),I9=BigInt(1),RW=BigInt(2),MT=BigInt(3),PT=BigInt(4),RT=BigInt(5),Ru=BigInt(7),LT=BigInt(8),Lu=BigInt(9),BT=BigInt(16);function T5(W,X){let G=W%X;return G>=y9?G:X+G}function D5(W,X,G){let Y=W;while(X-- >y9)Y*=Y,Y%=G;return Y}function iC(W,X){if(W===y9)throw Error("invert: expected non-zero number");if(X<=y9)throw Error("invert: expected positive modulus, got "+X);let G=T5(W,X),Y=X,J=y9,Z=I9,V=I9,U=y9;while(G!==y9){let Q=Y/G,N=Y%G,q=J-V*Q,A=Z-U*Q;Y=G,G=N,J=V,Z=U,V=q,U=A}if(Y!==I9)throw Error("invert: does not exist");return T5(J,X)}function Tz(W,X,G){if(!W.eql(W.sqr(X),G))throw Error("Cannot find square root")}function ET(W,X){let G=(W.ORDER+I9)/PT,Y=W.pow(X,G);return Tz(W,Y,X),Y}function Bu(W,X){let G=(W.ORDER-RT)/LT,Y=W.mul(X,RW),J=W.pow(Y,G),Z=W.mul(X,J),V=W.mul(W.mul(Z,RW),J),U=W.mul(Z,W.sub(V,W.ONE));return Tz(W,U,X),U}function Eu(W){let X=mJ(W),G=$T(W),Y=G(X,X.neg(X.ONE)),J=G(X,Y),Z=G(X,X.neg(Y)),V=(W+Ru)/BT;return(U,Q)=>{let N=U.pow(Q,V),q=U.mul(N,Y),A=U.mul(N,J),H=U.mul(N,Z),I=U.eql(U.sqr(q),Q),w=U.eql(U.sqr(A),Q);N=U.cmov(N,q,I),q=U.cmov(H,A,w);let O=U.eql(U.sqr(q),Q),T=U.cmov(N,q,O);return Tz(U,T,Q),T}}function $T(W){if(W<MT)throw Error("sqrt is not defined for small field");let X=W-I9,G=0;while(X%RW===y9)X/=RW,G++;let Y=RW,J=mJ(W);while(rC(J,Y)===1)if(Y++>1000)throw Error("Cannot find square root: probably non-prime P");if(G===1)return ET;let Z=J.pow(Y,X),V=(X+I9)/RW;return function(U,Q){if(U.is0(Q))return Q;if(rC(U,Q)!==1)throw Error("Cannot find square root");let N=G,q=U.mul(U.ONE,Z),A=U.pow(Q,X),H=U.pow(Q,V);while(!U.eql(A,U.ONE)){if(U.is0(A))return U.ZERO;let I=1,w=U.sqr(A);while(!U.eql(w,U.ONE))if(I++,w=U.sqr(w),I===N)throw Error("Cannot find square root");let O=I9<<BigInt(N-I-1),T=U.pow(q,O);N=I,q=U.sqr(T),A=U.mul(A,q),H=U.mul(H,T)}return H}}function $u(W){if(W%PT===MT)return ET;if(W%LT===RT)return Bu;if(W%BT===Lu)return Eu(W);return $T(W)}var Fu=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Su(W){let X={ORDER:"bigint",MASK:"bigint",BYTES:"number",BITS:"number"},G=Fu.reduce((Y,J)=>{return Y[J]="function",Y},X);return Cz(W,G),W}function xu(W,X,G){if(G<y9)throw Error("invalid exponent, negatives unsupported");if(G===y9)return W.ONE;if(G===I9)return X;let Y=W.ONE,J=X;while(G>y9){if(G&I9)Y=W.mul(Y,J);J=W.sqr(J),G>>=I9}return Y}function FT(W,X,G=!1){let Y=Array(X.length).fill(G?W.ZERO:void 0),J=X.reduce((V,U,Q)=>{if(W.is0(U))return V;return Y[Q]=V,W.mul(V,U)},W.ONE),Z=W.inv(J);return X.reduceRight((V,U,Q)=>{if(W.is0(U))return V;return Y[Q]=W.mul(V,Y[Q]),W.mul(V,U)},Z),Y}function rC(W,X){let G=(W.ORDER-I9)/RW,Y=W.pow(X,G),J=W.eql(Y,W.ONE),Z=W.eql(Y,W.ZERO),V=W.eql(Y,W.neg(W.ONE));if(!J&&!Z&&!V)throw Error("invalid Legendre symbol result");return J?1:Z?0:-1}function ST(W,X){if(X!==void 0)Qz(X);let G=X!==void 0?X:W.toString(2).length,Y=Math.ceil(G/8);return{nBitLength:G,nByteLength:Y}}function mJ(W,X,G=!1,Y={}){if(W<=y9)throw Error("invalid field: expected ORDER > 0, got "+W);let J=void 0,Z=void 0,V=!1,U=void 0;if(typeof X==="object"&&X!=null){if(Y.sqrt||G)throw Error("cannot specify opts in two arguments");let H=X;if(H.BITS)J=H.BITS;if(H.sqrt)Z=H.sqrt;if(typeof H.isLE==="boolean")G=H.isLE;if(typeof H.modFromBytes==="boolean")V=H.modFromBytes;U=H.allowedLengths}else{if(typeof X==="number")J=X;if(Y.sqrt)Z=Y.sqrt}let{nBitLength:Q,nByteLength:N}=ST(W,J);if(N>2048)throw Error("invalid field: expected ORDER of <= 2048 bytes");let q,A=Object.freeze({ORDER:W,isLE:G,BITS:Q,BYTES:N,MASK:bJ(Q),ZERO:y9,ONE:I9,allowedLengths:U,create:(H)=>T5(H,W),isValid:(H)=>{if(typeof H!=="bigint")throw Error("invalid field element: expected bigint, got "+typeof H);return y9<=H&&H<W},is0:(H)=>H===y9,isValidNot0:(H)=>!A.is0(H)&&A.isValid(H),isOdd:(H)=>(H&I9)===I9,neg:(H)=>T5(-H,W),eql:(H,I)=>H===I,sqr:(H)=>T5(H*H,W),add:(H,I)=>T5(H+I,W),sub:(H,I)=>T5(H-I,W),mul:(H,I)=>T5(H*I,W),pow:(H,I)=>xu(A,H,I),div:(H,I)=>T5(H*iC(I,W),W),sqrN:(H)=>H*H,addN:(H,I)=>H+I,subN:(H,I)=>H-I,mulN:(H,I)=>H*I,inv:(H)=>iC(H,W),sqrt:Z||((H)=>{if(!q)q=$u(W);return q(A,H)}),toBytes:(H)=>G?CT(H,N):LQ(H,N),fromBytes:(H,I=!0)=>{if(U){if(!U.includes(H.length)||H.length>N)throw Error("Field.fromBytes: expected "+U+" bytes, got "+H.length);let O=new Uint8Array(N);O.set(H,G?0:O.length-H.length),H=O}if(H.length!==N)throw Error("Field.fromBytes: expected "+N+" bytes, got "+H.length);let w=G?DT(H):HG(H);if(V)w=T5(w,W);if(!I){if(!A.isValid(w))throw Error("invalid field element: outside of range 0..ORDER")}return w},invertBatch:(H)=>FT(A,H),cmov:(H,I,w)=>w?I:H});return Object.freeze(A)}function xT(W){if(typeof W!=="bigint")throw Error("field order must be bigint");let X=W.toString(2).length;return Math.ceil(X/8)}function kT(W){let X=xT(W);return X+Math.ceil(X/2)}function _T(W,X,G=!1){let Y=W.length,J=xT(X),Z=kT(X);if(Y<16||Y<Z||Y>1024)throw Error("expected "+Z+"-1024 bytes of input, got "+Y);let V=G?DT(W):HG(W),U=T5(V,X-I9)+I9;return G?CT(U,J):LQ(U,J)}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */var NG=BigInt(0),LW=BigInt(1);function jQ(W,X){let G=X.negate();return W?G:X}function eA(W,X){let G=FT(W.Fp,X.map((Y)=>Y.Z));return X.map((Y,J)=>W.fromAffine(Y.toAffine(G[J])))}function yT(W,X){if(!Number.isSafeInteger(W)||W<=0||W>X)throw Error("invalid window size, expected [1.."+X+"], got W="+W)}function Wz(W,X){yT(W,X);let G=Math.ceil(X/W)+1,Y=2**(W-1),J=2**W,Z=bJ(W),V=BigInt(W);return{windows:G,windowSize:Y,mask:Z,maxNumber:J,shiftBy:V}}function aC(W,X,G){let{windowSize:Y,mask:J,maxNumber:Z,shiftBy:V}=G,U=Number(W&J),Q=W>>V;if(U>Y)U-=Z,Q+=LW;let N=X*Y,q=N+Math.abs(U)-1,A=U===0,H=U<0,I=X%2!==0;return{nextN:Q,offset:q,isZero:A,isNeg:H,isNegF:I,offsetF:N}}function ku(W,X){if(!Array.isArray(W))throw Error("array expected");W.forEach((G,Y)=>{if(!(G instanceof X))throw Error("invalid point at index "+Y)})}function _u(W,X){if(!Array.isArray(W))throw Error("array of scalars expected");W.forEach((G,Y)=>{if(!X.isValid(G))throw Error("invalid scalar at index "+Y)})}var Xz=new WeakMap,vT=new WeakMap;function Gz(W){return vT.get(W)||1}function sC(W){if(W!==NG)throw Error("invalid wNAF")}class gT{constructor(W,X){this.BASE=W.BASE,this.ZERO=W.ZERO,this.Fn=W.Fn,this.bits=X}_unsafeLadder(W,X,G=this.ZERO){let Y=W;while(X>NG){if(X&LW)G=G.add(Y);Y=Y.double(),X>>=LW}return G}precomputeWindow(W,X){let{windows:G,windowSize:Y}=Wz(X,this.bits),J=[],Z=W,V=Z;for(let U=0;U<G;U++){V=Z,J.push(V);for(let Q=1;Q<Y;Q++)V=V.add(Z),J.push(V);Z=V.double()}return J}wNAF(W,X,G){if(!this.Fn.isValid(G))throw Error("invalid scalar");let Y=this.ZERO,J=this.BASE,Z=Wz(W,this.bits);for(let V=0;V<Z.windows;V++){let{nextN:U,offset:Q,isZero:N,isNeg:q,isNegF:A,offsetF:H}=aC(G,V,Z);if(G=U,N)J=J.add(jQ(A,X[H]));else Y=Y.add(jQ(q,X[Q]))}return sC(G),{p:Y,f:J}}wNAFUnsafe(W,X,G,Y=this.ZERO){let J=Wz(W,this.bits);for(let Z=0;Z<J.windows;Z++){if(G===NG)break;let{nextN:V,offset:U,isZero:Q,isNeg:N}=aC(G,Z,J);if(G=V,Q)continue;else{let q=X[U];Y=Y.add(N?q.negate():q)}}return sC(G),Y}getPrecomputes(W,X,G){let Y=Xz.get(X);if(!Y){if(Y=this.precomputeWindow(X,W),W!==1){if(typeof G==="function")Y=G(Y);Xz.set(X,Y)}}return Y}cached(W,X,G){let Y=Gz(W);return this.wNAF(Y,this.getPrecomputes(Y,W,G),X)}unsafe(W,X,G,Y){let J=Gz(W);if(J===1)return this._unsafeLadder(W,X,Y);return this.wNAFUnsafe(J,this.getPrecomputes(J,W,G),X,Y)}createCache(W,X){yT(X,this.bits),vT.set(W,X),Xz.delete(W)}hasCache(W){return Gz(W)!==1}}function yu(W,X,G,Y){let J=X,Z=W.ZERO,V=W.ZERO;while(G>NG||Y>NG){if(G&LW)Z=Z.add(J);if(Y&LW)V=V.add(J);J=J.double(),G>>=LW,Y>>=LW}return{p1:Z,p2:V}}function vu(W,X,G,Y){ku(G,W),_u(Y,X);let J=G.length,Z=Y.length;if(J!==Z)throw Error("arrays of points and scalars must have equal length");let V=W.ZERO,U=TT(BigInt(J)),Q=1;if(U>12)Q=U-3;else if(U>4)Q=U-2;else if(U>0)Q=2;let N=bJ(Q),q=Array(Number(N)+1).fill(V),A=Math.floor((X.BITS-1)/Q)*Q,H=V;for(let I=A;I>=0;I-=Q){q.fill(V);for(let O=0;O<Z;O++){let T=Y[O],x=Number(T>>BigInt(I)&N);q[x]=q[x].add(G[O])}let w=V;for(let O=q.length-1,T=V;O>0;O--)T=T.add(q[O]),w=w.add(T);if(H=H.add(w),I!==0)for(let O=0;O<Q;O++)H=H.double()}return H}function tC(W,X,G){if(X){if(X.ORDER!==W)throw Error("Field.ORDER must match order: Fp == p, Fn == n");return Su(X),X}else return mJ(W,{isLE:G})}function gu(W,X,G={},Y){if(Y===void 0)Y=W==="edwards";if(!X||typeof X!=="object")throw Error(`expected valid ${W} CURVE object`);for(let U of["p","n","h"]){let Q=X[U];if(!(typeof Q==="bigint"&&Q>NG))throw Error(`CURVE.${U} must be positive bigint`)}let J=tC(X.p,G.Fp,Y),Z=tC(X.n,G.Fn,Y),V=["Gx","Gy","a",W==="weierstrass"?"b":"d"];for(let U of V)if(!J.isValid(X[U]))throw Error(`CURVE.${U} must be valid field element of CURVE.Fp`);return X=Object.freeze(Object.assign({},X)),{CURVE:X,Fp:J,Fn:Z}}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */var eC=(W,X)=>(W+(W>=0?X:-X)/hT)/X;function uu(W,X,G){let[[Y,J],[Z,V]]=X,U=eC(V*W,G),Q=eC(-J*W,G),N=W-U*Y-Q*Z,q=-U*J-Q*V,A=N<J4,H=q<J4;if(A)N=-N;if(H)q=-q;let I=bJ(Math.ceil(TT(G)/2))+UG;if(N<J4||N>=I||q<J4||q>=I)throw Error("splitScalar (endomorphism): failed, k="+W);return{k1neg:A,k1:N,k2neg:H,k2:q}}function Az(W){if(!["compact","recovered","der"].includes(W))throw Error('Signature format must be "compact", "recovered", or "der"');return W}function Yz(W,X){let G={};for(let Y of Object.keys(X))G[Y]=W[Y]===void 0?X[Y]:W[Y];if(wQ(G.lowS,"lowS"),wQ(G.prehash,"prehash"),G.format!==void 0)Az(G.format);return G}class uT extends Error{constructor(W=""){super(W)}}var Y4={Err:uT,_tlv:{encode:(W,X)=>{let{Err:G}=Y4;if(W<0||W>256)throw new G("tlv.encode: wrong tag");if(X.length&1)throw new G("tlv.encode: unpadded data");let Y=X.length/2,J=XQ(Y);if(J.length/2&128)throw new G("tlv.encode: long form length too big");let Z=Y>127?XQ(J.length/2|128):"";return XQ(W)+Z+J+X},decode(W,X){let{Err:G}=Y4,Y=0;if(W<0||W>256)throw new G("tlv.encode: wrong tag");if(X.length<2||X[Y++]!==W)throw new G("tlv.decode: wrong tlv");let J=X[Y++],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 N=X.subarray(Y,Y+Q);if(N.length!==Q)throw new G("tlv.decode: length bytes not complete");if(N[0]===0)throw new G("tlv.decode(long): zero leftmost byte");for(let q of N)V=V<<8|q;if(Y+=Q,V<128)throw new G("tlv.decode(long): not minimal encoding")}let U=X.subarray(Y,Y+V);if(U.length!==V)throw new G("tlv.decode: wrong value length");return{v:U,l:X.subarray(Y+V)}}},_int:{encode(W){let{Err:X}=Y4;if(W<J4)throw new X("integer: negative integers are not allowed");let G=XQ(W);if(Number.parseInt(G[0],16)&8)G="00"+G;if(G.length&1)throw new X("unexpected DER parsing assertion: unpadded hex");return G},decode(W){let{Err:X}=Y4;if(W[0]&128)throw new X("invalid signature integer: negative");if(W[0]===0&&!(W[1]&128))throw new X("invalid signature integer: unnecessary leading zero");return HG(W)}},toSig(W){let{Err:X,_int:G,_tlv:Y}=Y4,J=f8("signature",W),{v:Z,l:V}=Y.decode(48,J);if(V.length)throw new X("invalid signature: left bytes after parsing");let{v:U,l:Q}=Y.decode(2,Z),{v:N,l:q}=Y.decode(2,Q);if(q.length)throw new X("invalid signature: left bytes after parsing");return{r:G.decode(U),s:G.decode(N)}},hexFromSig(W){let{_tlv:X,_int:G}=Y4,Y=X.encode(2,G.encode(W.r)),J=X.encode(2,G.encode(W.s)),Z=Y+J;return X.encode(48,Z)}},J4=BigInt(0),UG=BigInt(1),hT=BigInt(2),GQ=BigInt(3),hu=BigInt(4);function BW(W,X){let{BYTES:G}=W,Y;if(typeof X==="bigint")Y=X;else{let J=f8("private key",X);try{Y=W.fromBytes(J)}catch(Z){throw Error(`invalid private key: expected ui8a of size ${G}, got ${typeof X}`)}}if(!W.isValidNot0(Y))throw Error("invalid private key: out of range [1..N-1]");return Y}function bu(W,X={}){let G=gu("weierstrass",W,X),{Fp:Y,Fn:J}=G,Z=G.CURVE,{h:V,n:U}=Z;Cz(X,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",wrapPrivateKey:"boolean"});let{endo:Q}=X;if(Q){if(!Y.is0(Z.a)||typeof Q.beta!=="bigint"||!Array.isArray(Q.basises))throw Error('invalid endo: expected "beta": bigint and "basises": array')}let N=mT(Y,J);function q(){if(!Y.isOdd)throw Error("compression is not supported: Field does not have .isOdd()")}function A(g,d,P){let{x:E,y:f}=d.toAffine(),r=Y.toBytes(E);if(wQ(P,"isCompressed"),P){q();let o=!Y.isOdd(f);return j7(bT(o),r)}else return j7(Uint8Array.of(4),r,Y.toBytes(f))}function H(g){PW(g,void 0,"Point");let{publicKey:d,publicKeyUncompressed:P}=N,E=g.length,f=g[0],r=g.subarray(1);if(E===d&&(f===2||f===3)){let o=Y.fromBytes(r);if(!Y.isValid(o))throw Error("bad point: is not on curve, wrong x");let B=O(o),S;try{S=Y.sqrt(B)}catch(v){let R=v instanceof Error?": "+v.message:"";throw Error("bad point: is not on curve, sqrt error"+R)}q();let _=Y.isOdd(S);if((f&1)===1!==_)S=Y.neg(S);return{x:o,y:S}}else if(E===P&&f===4){let o=Y.BYTES,B=Y.fromBytes(r.subarray(0,o)),S=Y.fromBytes(r.subarray(o,o*2));if(!T(B,S))throw Error("bad point: is not on curve");return{x:B,y:S}}else throw Error(`bad point: got length ${E}, expected compressed=${d} or uncompressed=${P}`)}let I=X.toBytes||A,w=X.fromBytes||H;function O(g){let d=Y.sqr(g),P=Y.mul(d,g);return Y.add(Y.add(P,Y.mul(g,Z.a)),Z.b)}function T(g,d){let P=Y.sqr(d),E=O(g);return Y.eql(P,E)}if(!T(Z.Gx,Z.Gy))throw Error("bad curve params: generator point");let x=Y.mul(Y.pow(Z.a,GQ),hu),h=Y.mul(Y.sqr(Z.b),BigInt(27));if(Y.is0(Y.add(x,h)))throw Error("bad curve params: a or b");function $(g,d,P=!1){if(!Y.isValid(d)||P&&Y.is0(d))throw Error(`bad point coordinate ${g}`);return d}function F(g){if(!(g instanceof y))throw Error("ProjectivePoint expected")}function u(g){if(!Q||!Q.basises)throw Error("no endo");return uu(g,Q.basises,J.ORDER)}let l=nC((g,d)=>{let{X:P,Y:E,Z:f}=g;if(Y.eql(f,Y.ONE))return{x:P,y:E};let r=g.is0();if(d==null)d=r?Y.ONE:Y.inv(f);let o=Y.mul(P,d),B=Y.mul(E,d),S=Y.mul(f,d);if(r)return{x:Y.ZERO,y:Y.ZERO};if(!Y.eql(S,Y.ONE))throw Error("invZ was invalid");return{x:o,y:B}}),p=nC((g)=>{if(g.is0()){if(X.allowInfinityPoint&&!Y.is0(g.Y))return;throw Error("bad point: ZERO")}let{x:d,y:P}=g.toAffine();if(!Y.isValid(d)||!Y.isValid(P))throw Error("bad point: x or y not field elements");if(!T(d,P))throw Error("bad point: equation left != right");if(!g.isTorsionFree())throw Error("bad point: not in prime-order subgroup");return!0});function s(g,d,P,E,f){return P=new y(Y.mul(P.X,g),P.Y,P.Z),d=jQ(E,d),P=jQ(f,P),d.add(P)}class y{constructor(g,d,P){this.X=$("x",g),this.Y=$("y",d,!0),this.Z=$("z",P),Object.freeze(this)}static CURVE(){return Z}static fromAffine(g){let{x:d,y:P}=g||{};if(!g||!Y.isValid(d)||!Y.isValid(P))throw Error("invalid affine point");if(g instanceof y)throw Error("projective point not allowed");if(Y.is0(d)&&Y.is0(P))return y.ZERO;return new y(d,P,Y.ONE)}static fromBytes(g){let d=y.fromAffine(w(PW(g,void 0,"point")));return d.assertValidity(),d}static fromHex(g){return y.fromBytes(f8("pointHex",g))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(g=8,d=!0){if(H0.createCache(this,g),!d)this.multiply(GQ);return this}assertValidity(){p(this)}hasEvenY(){let{y:g}=this.toAffine();if(!Y.isOdd)throw Error("Field doesn't support isOdd");return!Y.isOdd(g)}equals(g){F(g);let{X:d,Y:P,Z:E}=this,{X:f,Y:r,Z:o}=g,B=Y.eql(Y.mul(d,o),Y.mul(f,E)),S=Y.eql(Y.mul(P,o),Y.mul(r,E));return B&&S}negate(){return new y(this.X,Y.neg(this.Y),this.Z)}double(){let{a:g,b:d}=Z,P=Y.mul(d,GQ),{X:E,Y:f,Z:r}=this,o=Y.ZERO,B=Y.ZERO,S=Y.ZERO,_=Y.mul(E,E),v=Y.mul(f,f),R=Y.mul(r,r),m=Y.mul(E,f);return m=Y.add(m,m),S=Y.mul(E,r),S=Y.add(S,S),o=Y.mul(g,S),B=Y.mul(P,R),B=Y.add(o,B),o=Y.sub(v,B),B=Y.add(v,B),B=Y.mul(o,B),o=Y.mul(m,o),S=Y.mul(P,S),R=Y.mul(g,R),m=Y.sub(_,R),m=Y.mul(g,m),m=Y.add(m,S),S=Y.add(_,_),_=Y.add(S,_),_=Y.add(_,R),_=Y.mul(_,m),B=Y.add(B,_),R=Y.mul(f,r),R=Y.add(R,R),_=Y.mul(R,m),o=Y.sub(o,_),S=Y.mul(R,v),S=Y.add(S,S),S=Y.add(S,S),new y(o,B,S)}add(g){F(g);let{X:d,Y:P,Z:E}=this,{X:f,Y:r,Z:o}=g,B=Y.ZERO,S=Y.ZERO,_=Y.ZERO,v=Z.a,R=Y.mul(Z.b,GQ),m=Y.mul(d,f),J0=Y.mul(P,r),U0=Y.mul(E,o),q0=Y.add(d,P),$0=Y.add(f,r);q0=Y.mul(q0,$0),$0=Y.add(m,J0),q0=Y.sub(q0,$0),$0=Y.add(d,E);let u0=Y.add(f,o);return $0=Y.mul($0,u0),u0=Y.add(m,U0),$0=Y.sub($0,u0),u0=Y.add(P,E),B=Y.add(r,o),u0=Y.mul(u0,B),B=Y.add(J0,U0),u0=Y.sub(u0,B),_=Y.mul(v,$0),B=Y.mul(R,U0),_=Y.add(B,_),B=Y.sub(J0,_),_=Y.add(J0,_),S=Y.mul(B,_),J0=Y.add(m,m),J0=Y.add(J0,m),U0=Y.mul(v,U0),$0=Y.mul(R,$0),J0=Y.add(J0,U0),U0=Y.sub(m,U0),U0=Y.mul(v,U0),$0=Y.add($0,U0),m=Y.mul(J0,$0),S=Y.add(S,m),m=Y.mul(u0,$0),B=Y.mul(q0,B),B=Y.sub(B,m),m=Y.mul(q0,J0),_=Y.mul(u0,_),_=Y.add(_,m),new y(B,S,_)}subtract(g){return this.add(g.negate())}is0(){return this.equals(y.ZERO)}multiply(g){let{endo:d}=X;if(!J.isValidNot0(g))throw Error("invalid scalar: out of range");let P,E,f=(r)=>H0.cached(this,r,(o)=>eA(y,o));if(d){let{k1neg:r,k1:o,k2neg:B,k2:S}=u(g),{p:_,f:v}=f(o),{p:R,f:m}=f(S);E=v.add(m),P=s(d.beta,_,R,r,B)}else{let{p:r,f:o}=f(g);P=r,E=o}return eA(y,[P,E])[0]}multiplyUnsafe(g){let{endo:d}=X,P=this;if(!J.isValid(g))throw Error("invalid scalar: out of range");if(g===J4||P.is0())return y.ZERO;if(g===UG)return P;if(H0.hasCache(this))return this.multiply(g);if(d){let{k1neg:E,k1:f,k2neg:r,k2:o}=u(g),{p1:B,p2:S}=yu(y,P,f,o);return s(d.beta,B,S,E,r)}else return H0.unsafe(P,g)}multiplyAndAddUnsafe(g,d,P){let E=this.multiplyUnsafe(d).add(g.multiplyUnsafe(P));return E.is0()?void 0:E}toAffine(g){return l(this,g)}isTorsionFree(){let{isTorsionFree:g}=X;if(V===UG)return!0;if(g)return g(y,this);return H0.unsafe(this,U).is0()}clearCofactor(){let{clearCofactor:g}=X;if(V===UG)return this;if(g)return g(y,this);return this.multiplyUnsafe(V)}isSmallOrder(){return this.multiplyUnsafe(V).is0()}toBytes(g=!0){return wQ(g,"isCompressed"),this.assertValidity(),I(y,this,g)}toHex(g=!0){return VG(this.toBytes(g))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}get px(){return this.X}get py(){return this.X}get pz(){return this.Z}toRawBytes(g=!0){return this.toBytes(g)}_setWindowSize(g){this.precompute(g)}static normalizeZ(g){return eA(y,g)}static msm(g,d){return vu(y,J,g,d)}static fromPrivateKey(g){return y.BASE.multiply(BW(J,g))}}y.BASE=new y(Z.Gx,Z.Gy,Y.ONE),y.ZERO=new y(Y.ZERO,Y.ONE,Y.ZERO),y.Fp=Y,y.Fn=J;let t=J.BITS,H0=new gT(y,X.endo?Math.ceil(t/2):t);return y.BASE.precompute(8),y}function bT(W){return Uint8Array.of(W?2:3)}function mT(W,X){return{secretKey:X.BYTES,publicKey:1+W.BYTES,publicKeyUncompressed:1+2*W.BYTES,publicKeyHasPrefix:!0,signature:2*X.BYTES}}function mu(W,X={}){let{Fn:G}=W,Y=X.randomBytes||RQ,J=Object.assign(mT(W.Fp,G),{seed:kT(G.ORDER)});function Z(H){try{return!!BW(G,H)}catch(I){return!1}}function V(H,I){let{publicKey:w,publicKeyUncompressed:O}=J;try{let T=H.length;if(I===!0&&T!==w)return!1;if(I===!1&&T!==O)return!1;return!!W.fromBytes(H)}catch(T){return!1}}function U(H=Y(J.seed)){return _T(PW(H,J.seed,"seed"),G.ORDER)}function Q(H,I=!0){return W.BASE.multiply(BW(G,H)).toBytes(I)}function N(H){let I=U(H);return{secretKey:I,publicKey:Q(I)}}function q(H){if(typeof H==="bigint")return!1;if(H instanceof W)return!0;let{secretKey:I,publicKey:w,publicKeyUncompressed:O}=J;if(G.allowedLengths||I===w)return;let T=f8("key",H).length;return T===w||T===O}function A(H,I,w=!0){if(q(H)===!0)throw Error("first arg must be private key");if(q(I)===!1)throw Error("second arg must be public key");let O=BW(G,H);return W.fromHex(I).multiply(O).toBytes(w)}return Object.freeze({getPublicKey:Q,getSharedSecret:A,keygen:N,Point:W,utils:{isValidSecretKey:Z,isValidPublicKey:V,randomSecretKey:U,isValidPrivateKey:Z,randomPrivateKey:U,normPrivateKeyToScalar:(H)=>BW(G,H),precompute(H=8,I=W.BASE){return I.precompute(H,!1)}},lengths:J})}function fu(W,X,G={}){AT(X),Cz(G,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});let Y=G.randomBytes||RQ,J=G.hmac||((P,...E)=>KT(X,P,j7(...E))),{Fp:Z,Fn:V}=W,{ORDER:U,BITS:Q}=V,{keygen:N,getPublicKey:q,getSharedSecret:A,utils:H,lengths:I}=mu(W,G),w={prehash:!1,lowS:typeof G.lowS==="boolean"?G.lowS:!1,format:void 0,extraEntropy:!1},O="compact";function T(P){let E=U>>UG;return P>E}function x(P,E){if(!V.isValidNot0(E))throw Error(`invalid signature ${P}: out of range 1..Point.Fn.ORDER`);return E}function h(P,E){Az(E);let f=I.signature,r=E==="compact"?f:E==="recovered"?f+1:void 0;return PW(P,r,`${E} signature`)}class ${constructor(P,E,f){if(this.r=x("r",P),this.s=x("s",E),f!=null)this.recovery=f;Object.freeze(this)}static fromBytes(P,E=O){h(P,E);let f;if(E==="der"){let{r:S,s:_}=Y4.toSig(PW(P));return new $(S,_)}if(E==="recovered")f=P[0],E="compact",P=P.subarray(1);let r=V.BYTES,o=P.subarray(0,r),B=P.subarray(r,r*2);return new $(V.fromBytes(o),V.fromBytes(B),f)}static fromHex(P,E){return this.fromBytes(IQ(P),E)}addRecoveryBit(P){return new $(this.r,this.s,P)}recoverPublicKey(P){let E=Z.ORDER,{r:f,s:r,recovery:o}=this;if(o==null||![0,1,2,3].includes(o))throw Error("recovery id invalid");if(U*hT<E&&o>1)throw Error("recovery id is ambiguous for h>1 curve");let B=o===2||o===3?f+U:f;if(!Z.isValid(B))throw Error("recovery id 2 or 3 invalid");let S=Z.toBytes(B),_=W.fromBytes(j7(bT((o&1)===0),S)),v=V.inv(B),R=u(f8("msgHash",P)),m=V.create(-R*v),J0=V.create(r*v),U0=W.BASE.multiplyUnsafe(m).add(_.multiplyUnsafe(J0));if(U0.is0())throw Error("point at infinify");return U0.assertValidity(),U0}hasHighS(){return T(this.s)}toBytes(P=O){if(Az(P),P==="der")return IQ(Y4.hexFromSig(this));let E=V.toBytes(this.r),f=V.toBytes(this.s);if(P==="recovered"){if(this.recovery==null)throw Error("recovery bit must be present");return j7(Uint8Array.of(this.recovery),E,f)}return j7(E,f)}toHex(P){return VG(this.toBytes(P))}assertValidity(){}static fromCompact(P){return $.fromBytes(f8("sig",P),"compact")}static fromDER(P){return $.fromBytes(f8("sig",P),"der")}normalizeS(){return this.hasHighS()?new $(this.r,V.neg(this.s),this.recovery):this}toDERRawBytes(){return this.toBytes("der")}toDERHex(){return VG(this.toBytes("der"))}toCompactRawBytes(){return this.toBytes("compact")}toCompactHex(){return VG(this.toBytes("compact"))}}let F=G.bits2int||function(P){if(P.length>8192)throw Error("input is too large");let E=HG(P),f=P.length*8-Q;return f>0?E>>BigInt(f):E},u=G.bits2int_modN||function(P){return V.create(F(P))},l=bJ(Q);function p(P){return Mu("num < 2^"+Q,P,J4,l),V.toBytes(P)}function s(P,E){return PW(P,void 0,"message"),E?PW(X(P),void 0,"prehashed message"):P}function y(P,E,f){if(["recovered","canonical"].some((U0)=>(U0 in f)))throw Error("sign() legacy options not supported");let{lowS:r,prehash:o,extraEntropy:B}=Yz(f,w);P=s(P,o);let S=u(P),_=BW(V,E),v=[p(_),p(S)];if(B!=null&&B!==!1){let U0=B===!0?Y(I.secretKey):B;v.push(f8("extraEntropy",U0))}let R=j7(...v),m=S;function J0(U0){let q0=F(U0);if(!V.isValidNot0(q0))return;let $0=V.inv(q0),u0=W.BASE.multiply(q0).toAffine(),H1=V.create(u0.x);if(H1===J4)return;let v1=V.create($0*V.create(m+H1*_));if(v1===J4)return;let h0=(u0.x===H1?0:2)|Number(u0.y&UG),F1=v1;if(r&&T(v1))F1=V.neg(v1),h0^=1;return new $(H1,F1,h0)}return{seed:R,k2sig:J0}}function t(P,E,f={}){P=f8("message",P);let{seed:r,k2sig:o}=y(P,E,f);return Pu(X.outputLen,V.BYTES,J)(r,o)}function H0(P){let E=void 0,f=typeof P==="string"||PQ(P),r=!f&&P!==null&&typeof P==="object"&&typeof P.r==="bigint"&&typeof P.s==="bigint";if(!f&&!r)throw Error("invalid signature, expected Uint8Array, hex string or Signature instance");if(r)E=new $(P.r,P.s);else if(f){try{E=$.fromBytes(f8("sig",P),"der")}catch(o){if(!(o instanceof Y4.Err))throw o}if(!E)try{E=$.fromBytes(f8("sig",P),"compact")}catch(o){return!1}}if(!E)return!1;return E}function g(P,E,f,r={}){let{lowS:o,prehash:B,format:S}=Yz(r,w);if(f=f8("publicKey",f),E=s(f8("message",E),B),"strict"in r)throw Error("options.strict was renamed to lowS");let _=S===void 0?H0(P):$.fromBytes(f8("sig",P),S);if(_===!1)return!1;try{let v=W.fromBytes(f);if(o&&_.hasHighS())return!1;let{r:R,s:m}=_,J0=u(E),U0=V.inv(m),q0=V.create(J0*U0),$0=V.create(R*U0),u0=W.BASE.multiplyUnsafe(q0).add(v.multiplyUnsafe($0));if(u0.is0())return!1;return V.create(u0.x)===R}catch(v){return!1}}function d(P,E,f={}){let{prehash:r}=Yz(f,w);return E=s(E,r),$.fromBytes(P,"recovered").recoverPublicKey(E).toBytes()}return Object.freeze({keygen:N,getPublicKey:q,getSharedSecret:A,utils:H,lengths:I,Point:W,sign:t,verify:g,recoverPublicKey:d,Signature:$,hash:X})}function pu(W){let X={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,Y=W.allowedPrivateKeyLengths?Array.from(new Set(W.allowedPrivateKeyLengths.map((V)=>Math.ceil(V/2)))):void 0,J=mJ(X.n,{BITS:W.nBitLength,allowedLengths:Y,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:X,curveOpts:Z}}function cu(W){let{CURVE:X,curveOpts:G}=pu(W),Y={hmac:W.hmac,randomBytes:W.randomBytes,lowS:W.lowS,bits2int:W.bits2int,bits2int_modN:W.bits2int_modN};return{CURVE:X,curveOpts:G,hash:W.hash,ecdsaOpts:Y}}function lu(W,X){let G=X.Point;return Object.assign({},X,{ProjectivePoint:G,CURVE:Object.assign({},W,ST(G.Fn.ORDER,G.Fn.BITS))})}function du(W){let{CURVE:X,curveOpts:G,hash:Y,ecdsaOpts:J}=cu(W),Z=bu(X,G),V=fu(Z,Y,J);return lu(W,V)}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */function ou(W,X){let G=(Y)=>du({...W,hash:Y});return{...G(X),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")},nu={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]},iu=BigInt(0),WT=BigInt(1),zz=BigInt(2);function ru(W){let X=qG.p,G=BigInt(3),Y=BigInt(6),J=BigInt(11),Z=BigInt(22),V=BigInt(23),U=BigInt(44),Q=BigInt(88),N=W*W*W%X,q=N*N*W%X,A=D5(q,G,X)*q%X,H=D5(A,G,X)*q%X,I=D5(H,zz,X)*N%X,w=D5(I,J,X)*I%X,O=D5(w,Z,X)*w%X,T=D5(O,U,X)*O%X,x=D5(T,Q,X)*T%X,h=D5(x,U,X)*O%X,$=D5(h,G,X)*q%X,F=D5($,V,X)*w%X,u=D5(F,Y,X)*N%X,l=D5(u,zz,X);if(!KQ.eql(KQ.sqr(l),W))throw Error("Cannot find square root");return l}var KQ=mJ(qG.p,{sqrt:ru}),fT=ou({...qG,Fp:KQ,lowS:!0,endo:nu},Nz),XT={};function OQ(W,...X){let G=XT[W];if(G===void 0){let Y=Nz(IT(W));G=j7(Y,Y),XT[W]=G}return Nz(j7(G,...X))}var Mz=(W)=>W.toBytes(!0).slice(1),AG=(()=>fT.Point)(),Pz=(W)=>W%zz===iu;function Iz(W){let{Fn:X,BASE:G}=AG,Y=BW(X,W),J=G.multiply(Y);return{scalar:Pz(J.y)?Y:X.neg(Y),bytes:Mz(J)}}function pT(W){let X=KQ;if(!X.isValidNot0(W))throw Error("invalid x: Fail if x \u2265 p");let G=X.create(W*W),Y=X.create(G*W+BigInt(7)),J=X.sqrt(Y);if(!Pz(J))J=X.neg(J);let Z=AG.fromAffine({x:W,y:J});return Z.assertValidity(),Z}var uJ=HG;function cT(...W){return AG.Fn.create(uJ(OQ("BIP0340/challenge",...W)))}function GT(W){return Iz(W).bytes}function au(W,X,G=RQ(32)){let{Fn:Y}=AG,J=f8("message",W),{bytes:Z,scalar:V}=Iz(X),U=f8("auxRand",G,32),Q=Y.toBytes(V^uJ(OQ("BIP0340/aux",U))),N=OQ("BIP0340/nonce",Q,Z,J),{bytes:q,scalar:A}=Iz(N),H=cT(q,Z,J),I=new Uint8Array(64);if(I.set(q,0),I.set(Y.toBytes(Y.create(A+H*V)),32),!lT(I,J,Z))throw Error("sign: Invalid signature produced");return I}function lT(W,X,G){let{Fn:Y,BASE:J}=AG,Z=f8("signature",W,64),V=f8("message",X),U=f8("publicKey",G,32);try{let Q=pT(uJ(U)),N=uJ(Z.subarray(0,32));if(!Hz(N,WT,qG.p))return!1;let q=uJ(Z.subarray(32,64));if(!Hz(q,WT,qG.n))return!1;let A=cT(Y.toBytes(N),Mz(Q),V),H=J.multiplyUnsafe(q).add(Q.multiplyUnsafe(Y.neg(A))),{x:I,y:w}=H.toAffine();if(H.is0()||!Pz(w)||I!==N)return!1;return!0}catch(Q){return!1}}var Rz=(()=>{let W=(G=RQ(48))=>{return _T(G,qG.n)};fT.utils.randomSecretKey;function X(G){let Y=W(G);return{secretKey:Y,publicKey:GT(Y)}}return{keygen:X,getPublicKey:GT,sign:au,verify:lT,Point:AG,utils:{randomSecretKey:W,randomPrivateKey:W,taggedHash:OQ,lift_x:pT,pointToBytes:Mz,numberToBytesBE:LQ,bytesToNumberBE:HG,mod:T5},lengths:{secretKey:32,publicKey:32,publicKeyHasPrefix:!1,signature:64,seed:48}}})(),su=new TextEncoder,tu=new TextDecoder,Z4=(W)=>su.encode(W),_J=(W)=>tu.decode(W),wz=(W)=>Array.from(W,(X)=>X.toString(16).padStart(2,"0")).join(""),K7=JSON.stringify,DQ=JSON.parse,eu=(W,X=Number.MAX_SAFE_INTEGER)=>W.split("").reduce((G,Y)=>G+Y.charCodeAt(0),0)%X,CQ="AES-GCM",Wh={},dT="$",oT=",",Xh=(W)=>{let X=new Uint8Array(W),G=32768,Y="";for(let J=0;J<X.length;J+=32768)Y+=String.fromCharCode(...X.subarray(J,J+32768));return btoa(Y)},Gh=(W)=>Uint8Array.from(atob(W),(X)=>X.charCodeAt(0)).buffer,YQ=(W)=>Wh[W]??=crypto.subtle.digest("SHA-1",Z4(W)).then((X)=>{let G=new Uint8Array(X),Y="";for(let J of G)Y+=J.toString(36);return Y}),Yh=async(W,X,G)=>{if(!W){let J=await crypto.subtle.digest("SHA-256",Z4(`:${X}:${G}`));return crypto.subtle.importKey("raw",J,{name:CQ},!1,["encrypt","decrypt"])}let Y=await crypto.subtle.importKey("raw",Z4(W),"PBKDF2",!1,["deriveKey"]);return crypto.subtle.deriveKey({name:"PBKDF2",salt:Z4(`${X}:${G}`),iterations:1e5,hash:"SHA-256"},Y,{name:CQ,length:256},!1,["encrypt","decrypt"])},Jh=async(W,X)=>{let G=crypto.getRandomValues(new Uint8Array(12)),Y=await W,J=await crypto.subtle.encrypt({name:CQ,iv:G},Y,Z4(X));return`${G.join(oT)}${dT}${Xh(J)}`},Zh=async(W,X)=>{let[G,Y]=X.split(dT);if(!G||!Y)throw Error("Invalid encrypted payload format");let J=Uint8Array.from(G.split(oT),Number),Z=await W,V=await crypto.subtle.decrypt({name:CQ,iv:J},Z,Gh(Y));return _J(V)},C5="GenosRTC",BQ=(W,X)=>Array.from({length:W},X),TQ=(W)=>Array.from(crypto.getRandomValues(new Uint8Array(W)),(X)=>"0123456789AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz"[X%62]).join(""),w8=typeof sessionStorage<"u"?sessionStorage.__genosrtcId??=TQ(20):TQ(20),ZG=Promise.all.bind(Promise),Vh=typeof window<"u",{entries:Uh,fromEntries:nT,keys:ne}=Object,YT=()=>{},h5=(W)=>Error(`GenosRTC: ${W}`),JQ=(...W)=>W.join("@"),Qh=5000,JT="icegatheringstatechange",ZT="offer",Nh="answer",qh=[...BQ(3,(W,X)=>`stun:stun${X||""}.l.google.com:19302`),"stun:stun.cloudflare.com:3478"].map((W)=>({urls:W})),VT=(W,{rtcConfig:X,rtcPolyfill:G,turnConfig:Y})=>{let J=new(G||RTCPeerConnection)({iceServers:[...qh,...Y||[]],...X}),Z={},V=!1,U=!1,Q,N=(H)=>Object.assign(H,{binaryType:"arraybuffer",bufferedAmountLowThreshold:65535,onmessage:(I)=>Z.data?.(I.data),onopen:()=>Z.connect?.(),onclose:()=>Z.close?.(),onerror:(I)=>!I?.error?.message?.includes("User-Initiated Abort")&&Z.error?.(I)}),q=()=>Promise.race([new Promise((H)=>{let I=()=>{if(J.iceGatheringState==="complete")J.removeEventListener(JT,I),H()};J.addEventListener(JT,I),I()}),new Promise((H)=>setTimeout(H,Qh))]).then(()=>({type:J.localDescription.type,sdp:J.localDescription.sdp.replace(/a=ice-options:trickle\s\n/g,"")}));if(W?N(Q=J.createDataChannel("data")):J.ondatachannel=({channel:H})=>N(Q=H),J.onnegotiationneeded=async()=>{try{V=!0,await J.setLocalDescription(),Z.signal?.(await q())}catch(H){Z.error?.(H)}finally{V=!1}},J.onconnectionstatechange=()=>{if(["disconnected","failed","closed"].includes(J.connectionState))Z.close?.()},J.ontrack=(H)=>{Z.track?.(H.track,H.streams[0]),Z.stream?.(H.streams[0])},J.onremovestream=(H)=>Z.stream?.(H.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(H){if(Q?.readyState==="open"&&!H.sdp?.includes("a=rtpmap"))return;try{if(H.type===ZT){if(V||J.signalingState!=="stable"&&!U){if(W)return;await ZG([J.setLocalDescription({type:"rollback"}),J.setRemoteDescription(H)])}else await J.setRemoteDescription(H);await J.setLocalDescription();let I=await q();return Z.signal?.(I),I}if(H.type===Nh){U=!0;try{await J.setRemoteDescription(H)}finally{U=!1}}}catch(I){Z.error?.(I)}},sendData:(H)=>{if(Q?.readyState!=="open")return!1;return Q.send(H),!0},destroy:()=>{Q?.close(),J.close(),V=U=!1},setHandlers:(H)=>Object.assign(Z,H),offerPromise:W?new Promise((H)=>Z.signal=(I)=>I.type===ZT&&H(I)):Promise.resolve(),addStream:(H)=>H.getTracks().forEach((I)=>J.addTrack(I,H)),removeStream:(H)=>A().filter((I)=>H.getTracks().includes(I.track)).forEach((I)=>J.removeTrack(I)),addTrack:(H,I)=>J.addTrack(H,I),removeTrack:(H)=>{let I=A().find((w)=>w.track===H);if(I)J.removeTrack(I)},replaceTrack:(H,I)=>A().find((w)=>w.track===H)?.replaceTrack(I)}},Hh=Object.getPrototypeOf(Uint8Array),QQ=12,iT=0,NQ=iT+QQ,qQ=NQ+1,yJ=qQ+1,vJ=yJ+1,xJ=16384-vJ,ZQ=255,Jz="bufferedamountlow",JG=(W)=>`@_${W}`,UT=JG("ping"),Zz=100,Ah=3,zh=200,Ih=512,wh=33554432,QT=async(W,X,G=1/0)=>{let Y=new Blob([W]).stream().pipeThrough(new X("deflate")).getReader(),J=[],Z=0;for(let Q=await Y.read();!Q.done;Q=await Y.read()){if((Z+=Q.value.byteLength)>G)throw Y.cancel(),h5(`inflated payload exceeds ${G} bytes`);J.push(Q.value)}let V=new Uint8Array(Z),U=0;for(let Q of J)V.set(Q,U),U+=Q.byteLength;return V},jh=(W,X,G,Y,J)=>{let Z=new Map,V=new Map,U=new Map,Q={},N={},q={},A={},H=new Map,I=new Map,w=Promise.resolve(),O=(R,m)=>{if(!H.has(R))H.set(R,new Set);H.get(R).add(m)},T=(R,m)=>H.get(R)?.delete(m),x=(R,...m)=>H.get(R)?.forEach((J0)=>J0(...m)),h=(R,m)=>{let J0=R?Array.isArray(R)?R:[R]:Z.keys();return Array.from(J0,(U0)=>{let q0=Z.get(U0);if(!q0)return _9.warn(`${C5}: no peer with id ${U0}`),null;return m(U0,q0)}).filter(Boolean)},$=(R)=>{if(!Z.has(R))return;Z.delete(R),I.delete(R),_.delete(R),delete Q[R],delete N[R],delete q[R],delete A[R],x("peer:leave",R),X(R)},F=(R)=>new Promise((m,J0)=>{let U0=setTimeout(()=>{R.removeEventListener(Jz,q0),J0(Error(`${C5}: bufferLow timeout`))},5000);function q0(){clearTimeout(U0),R.removeEventListener(Jz,q0),m()}R.addEventListener(Jz,q0)}),u=(R)=>{if(U.has(R))return U.get(R);if(!R)throw h5("action type is required");let m=Z4(R);if(m.byteLength>QQ)throw h5(`\u274C "${R}" exceeds ${QQ} bytes. Use a shorter name.`);let J0=new Uint8Array(QQ).map((h0,F1)=>m[F1]||0),U0=0,q0=new Map([["message",new Set],["progress",new Set]]),$0=(h0,F1)=>q0.get(h0)?.add(F1),u0=(h0,F1)=>q0.get(h0)?.delete(F1),H1=async(h0,F1,S1,N0)=>{if(S1&&typeof S1!=="object")throw h5("meta must be object");if(h0===void 0)throw h5("data cannot be undefined");let F0=h0 instanceof Blob,m0=F0||h0 instanceof ArrayBuffer||h0 instanceof Hh,Y0=typeof h0!=="string";if(S1&&!m0)throw h5("meta only allowed with binary");let K0=m0?new Uint8Array(F0?await h0.arrayBuffer():h0):Z4(Y0?K7(h0):h0),P0=0;if(!m0&&K0.byteLength>=Ih){let X0=await QT(K0,CompressionStream);if(X0.byteLength<K0.byteLength)K0=X0,P0=1}let k0=S1?Z4(K7(S1)):null,R1=Math.ceil(K0.byteLength/xJ)+(S1?1:0)||1;if(R1>Zz)throw h5(`Message too large, exceeds max chunks ${Zz}`);let Q1=BQ(R1,(X0,C0)=>{let x0=C0===R1-1,k1=S1&&C0===0,W8=k1?k0:K0.subarray(S1?(C0-1)*xJ:C0*xJ,S1?C0*xJ:(C0+1)*xJ),d1=new Uint8Array(vJ+W8.byteLength);return d1.set(J0),d1.set([U0],NQ),d1.set([x0|k1<<1|m0<<2|Y0<<3|P0<<4],qQ),d1.set([Math.round((C0+1)/R1*ZQ)],yJ),d1.set(W8,vJ),d1});return U0=U0+1&ZQ,ZG(h(F1,async(X0,C0)=>{let{channel:x0}=C0;for(let k1=0;k1<R1;k1++){let W8=0;while(x0.bufferedAmount>x0.bufferedAmountLowThreshold){if(W8++>Ah)throw h5(`${C5}: send buffer full, max retries reached for peer ${X0}`);try{await F(x0)}catch(d1){_9.warn(d1.message),await new Promise((N1)=>setTimeout(N1,zh))}}if(!Z.has(X0))break;if(!C0.sendData(Q1[k1]))throw h5(`channel not open for peer ${X0}`);N0?.(Q1[k1][yJ]/ZQ,X0,S1)}}))};V.set(R,{listeners:q0,send:H1});let v1={send:H1,on:$0,off:u0};return U.set(R,v1),v1},l=(R,m)=>{try{I.set(R,Date.now()),_.delete(R);let J0=new Uint8Array(m),U0=_J(J0.subarray(iT,NQ)).replace(/\x00/g,"");if(!V.has(U0))return _9.warn(`${C5}: unregistered type (${U0})`);if(U0===UT){y("",R).catch(()=>{});return}let[q0]=J0.subarray(NQ,qQ),[$0]=J0.subarray(qQ,yJ),[u0]=J0.subarray(yJ,vJ),H1=J0.subarray(vJ),v1=Boolean($0&1),h0=Boolean($0&2),F1=Boolean($0&4),S1=Boolean($0&8),N0=Boolean($0&16),F0=V.get(U0),m0=(Q[R]||={})[U0]||={};if(m0[q0]?.chunks?.length>Zz){_9.warn(`${C5}: peer ${R} sent too many chunks for nonce ${q0}, ignoring.`);return}let Y0=m0[q0]||={chunks:[]};if(h0)try{Y0.meta=DQ(_J(H1))}catch{_9.warn(`${C5}: failed to parse meta from peer ${R} for type ${U0}`);return}else Y0.chunks.push(H1);if(F0.listeners.get("progress").forEach((P0)=>{try{P0(u0/ZQ,R,Y0.meta)}catch(k0){console.error(k0)}}),!v1)return;let K0=new Uint8Array(Y0.chunks.reduce((P0,k0)=>P0+k0.byteLength,0));Y0.chunks.reduce((P0,k0)=>(K0.set(k0,P0),P0+k0.byteLength),0),delete m0[q0],w=w.then(async()=>{let P0=N0?await QT(K0,DecompressionStream,wh):K0,k0;if(F1)k0=P0;else if(S1)try{k0=DQ(_J(P0))}catch{_9.warn(`${C5}: failed to parse JSON message data from peer ${R} for type ${U0}`);return}else k0=_J(P0);F0.listeners.get("message").forEach((R1)=>{try{R1(k0,R,Y0.meta)}catch(Q1){console.error(Q1)}})}).catch((P0)=>console.error(`${C5}: dispatch error from peer ${R}:`,P0))}catch(J0){_9.error(`${C5}: error handling data from peer ${R}:`,J0)}},p=async()=>{try{await r(""),await new Promise((R)=>setTimeout(R,99))}catch(R){_9.warn(`${C5}: error sending leave`,R)}for(let[R,m]of Z){try{m.destroy()}catch{}Z.delete(R)}clearInterval(v),G()},{send:s}=u(UT),{send:y,on:t}=u(JG("pong")),{send:H0,on:g}=u(JG("signal")),{send:d,on:P}=u(JG("stream")),{send:E,on:f}=u(JG("track")),{send:r,on:o}=u(JG("leave"));W((R,m)=>{let J0=Z.get(m);if(J0===R)return;if(J0){let U0=()=>{};J0.setHandlers({data:U0,stream:U0,track:U0,signal:U0,close:U0,error:U0})}Z.set(m,R),I.set(m,Date.now()),_.delete(m),R.setHandlers({data:(U0)=>l(m,U0),stream:(U0)=>{x("stream:add",U0,m,q[m]),delete q[m]},track:(U0,q0)=>{x("track:add",U0,q0,m,A[m]),delete A[m]},signal:(U0)=>H0(U0,m),close:()=>$(m),error:(U0)=>{_9.error(`${C5}: peer error for ${m}`,U0),$(m)}}),x("peer:join",m,Y?.(m))}),J?.((R,m,J0)=>x(J0?"peer:seen":"peer:lost",R,m)),t("message",(R,m)=>{N[m]?.(),delete N[m]}),g("message",(R,m)=>Z.get(m)?.signal(R)),P("message",(R,m)=>q[m]=R),f("message",(R,m)=>A[m]=R),o("message",(R,m)=>$(m));let B=1e4,S=20000,_=new Map,v=setInterval(()=>{let R=Date.now();for(let[m,J0]of Z){if(R-(I.get(m)??R)<=B)continue;let U0=_.get(m);if(U0===void 0)_.set(m,R),s("",m).catch(()=>{});else if(R-U0>S){_.delete(m);try{J0.destroy()}catch{}$(m)}}},5000);if(Vh)addEventListener("beforeunload",p);return{on:O,off:T,channel:u,leave:p,ping:async(R)=>{if(!R)throw h5("ping() requires target peer ID");let m=Date.now();return s("",R),await new Promise((J0)=>N[R]=J0),Date.now()-m},getPeers:()=>nT(Array.from(Z,([R,m])=>[R,m.connection])),addStream:(R,m,J0)=>h(m,async(U0,q0)=>{if(J0)await d(J0,U0);q0.addStream(R)}),removeStream:(R,m)=>h(m,(J0,U0)=>U0.removeStream(R)),addTrack:(R,m,J0,U0)=>h(J0,async(q0,$0)=>{if(U0)await E(U0,q0);$0.addTrack(R,m)}),removeTrack:(R,m)=>h(m,(J0,U0)=>U0.removeTrack(R)),replaceTrack:(R,m,J0,U0)=>h(J0,async(q0,$0)=>{if(U0)await E(U0,q0);$0.replaceTrack(R,m)})}},Kh=5,Oh=10,Dh=2500,VQ=57333,Ch=({init:W,subscribe:X,announce:G,bye:Y})=>{let J={},Z=!1,V,U;return(Q,N,q)=>{let{appId:A}=Q;if(J[A]?.[N])return J[A][N];if(!Q||!N||!A&&!Q.firebaseApp)throw h5(!Q?"config required":!N?"roomId required":"appId missing");let H=YT,I=YT;if(!Z){let _=W(Q);U=BQ(Kh,()=>{try{return VT(!0,Q)}catch{return null}}).filter(Boolean),V=Array.isArray(_)?_:[_];let v=setInterval(()=>{U=U.filter((R)=>{let m=Date.now()-R.created<VQ;if(!m)R.destroy();return m})},VQ);J.offerCleanupTimer||=v,Z=!0}let w={},O={},T=new Map,x=new Map,h=new Map,$={},F=JQ(C5,A,N),u=YQ(F),l=YQ(JQ(F,w8)),p=Yh(Q.password||"",A,N),s=(_)=>async(v)=>({type:v.type,sdp:await _(p,v.sdp)}),y=s(Zh),t=s(Jh),H0=(_)=>{return setTimeout(()=>{if(!_.isDead&&!Object.values(O).includes(_))_.destroy()},VQ),_},g=(_)=>{try{return H0(VT(_,Q))}catch{return null}},d=(_,v)=>{if(O[v]===_)return;_.connectedAt=Date.now(),O[v]?.destroy(),O[v]=_,H(_,v),w[v]?.forEach((R)=>R!==_&&R.destroy()),delete w[v]},P=(_,v)=>{if(O[v]===_)delete O[v]},E=(_)=>async(v,R,m)=>{let[J0,U0]=await ZG([u,l]);if(v!==J0&&v!==U0)return;let{peerId:q0,offer:$0,answer:u0,type:H1,bye:v1}=typeof R==="string"?DQ(R):R;if(v1){if(q0&&q0!==w8)x.delete(q0),I(q0,null,!1),h.set(q0,Date.now()),delete $[q0];return}if(q0&&q0!==w8)I(q0,H1,!0),x.set(q0,Date.now()),h.delete(q0);if(H1&&q0)$[q0]=H1;if(q0===w8)return;if(O[q0]){let h0=O[q0].channel?.readyState==="open";if(!$0||h0||Date.now()-O[q0].connectedAt<2000)return;O[q0].destroy(),delete O[q0]}if(Q.admit&&!Q.admit(q0))return;if($0){if(w[q0]?.[_]&&w8>q0)return;let h0=g(!1);if(!h0)return;h0.setHandlers({connect:()=>d(h0,q0),close:()=>P(h0,q0)});try{let F1=await y($0);if(h0.isDead)return;let[S1,N0]=await ZG([YQ(JQ(F,q0)),h0.signal(F1).then(t)]);m(S1,K7({peerId:w8,answer:N0,...Q.type&&{type:Q.type}}))}catch{q?.({error:"decryption failed (offer)",appId:A,peerId:q0,roomId:N})}}else if(u0){let h0=w[q0]?.[_];if(!h0||h0.isDead)return;h0.setHandlers({connect:()=>d(h0,q0),close:()=>P(h0,q0)});try{h0.signal(await y(u0))}catch{q?.({error:"decryption failed (answer)",appId:A,peerId:q0,roomId:N})}}else{let h0=w[q0]||=[];if(h0.forEach((N0,F0)=>{if(N0&&(N0.isDead||Date.now()-(N0.dialedAt??N0.created)>VQ)){if(N0.isDead)T.set(q0,Date.now()+30000);N0.destroy(),delete h0[F0]}}),h0[_]||h0.filter(Boolean).length>=2||T.get(q0)>Date.now())return;if(Object.values(w).reduce((N0,F0)=>N0+F0.filter((m0)=>m0&&!m0.isDead).length,0)>=Oh)return;let F1=U.pop(),S1=F1?H0(F1):g(!0);if(!S1){T.set(q0,Date.now()+30000);return}S1.dialedAt=Date.now(),h0[_]=S1;try{let[N0,{offer:F0}]=await ZG([YQ(JQ(F,q0)),S1.offerPromise.then(t).then((m0)=>({offer:m0}))]);S1.setHandlers({connect:()=>d(S1,q0),close:()=>P(S1,q0)}),m(N0,K7({peerId:w8,offer:F0,...Q.type&&{type:Q.type}}))}catch{if(h0[_]===S1)delete h0[_];S1.destroy()}}},f=[],r=[],o=[],B=()=>o.forEach(({relay:_,rootTopic:v})=>Y?.(_,v));V.forEach(async(_,v)=>{let R=await _;if(!R)return;let[m,J0]=await ZG([u,l]);r[v]=X(R,m,J0,E(v)),o.push({relay:R,rootTopic:m});let U0=async()=>{let q0=await G(R,m,J0);f[v]=setTimeout(U0,typeof q0==="number"?q0:Dh)};U0()}),J[A]||={};let S=jh((_)=>H=_,(_)=>delete O[_],()=>S.onCleanup?.(),(_)=>$[_],(_)=>I=_);if(typeof window<"u")window.addEventListener("pagehide",B);return S.onCleanup=()=>{if(B(),typeof window<"u")window.removeEventListener("pagehide",B);if(delete J[A][N],f.forEach(clearTimeout),r.forEach((_)=>_?.()),Object.keys(J).length===0)clearInterval(J.offerCleanupTimer),delete J.offerCleanupTimer},S._census=()=>{for(let v of Object.keys(O))x.set(v,Date.now());let _=Date.now()-120000;for(let[v,R]of x)if(R<_)x.delete(v);return[...x.keys()]},S._gone=()=>{let _=Date.now()-60000;for(let[v,R]of h)if(R<_)h.delete(v);return[...h.keys()]},J[A][N]=S}},NT=3333,Th=30000,kJ={},rT={},Mh=(W,X)=>{let G={},Y=null;G.reopenHandlers=new Set;let J=()=>{if(Y)clearTimeout(Y),Y=null;if(G.socket)G.socket.onclose=null,G.socket.close();let Z=new WebSocket(W);Z.onclose=()=>{kJ[W]??=NT,Y=setTimeout(J,kJ[W]),kJ[W]=Math.min(kJ[W]*2,Th)},Z.onmessage=(V)=>X(V.data),G.socket=Z,G.url=Z.url,G.ready=new Promise((V)=>{Z.onopen=()=>{kJ[W]=NT,V(G),G.reopenHandlers.forEach((U)=>U())}}),G.send=(V)=>{if(Z.readyState===1)Z.send(V)}};return G.forceReconnect=J,J(),rT[W]=G,G};if(typeof window<"u"){let W=(X)=>{_9.info("\u26A1 [GenosRTC] Network event detected. Forcing reconnection\u2026"),Object.values(rT).forEach((G)=>{if(G.socket&&G.socket.readyState!==WebSocket.OPEN&&(X||G.socket.readyState!==WebSocket.CONNECTING))G.forceReconnect()})};window.addEventListener("online",()=>{_9.info("\u2705 Reconnected to the network."),W(!0)}),window.addEventListener("offline",async()=>{_9.info("\u274C Disconnected from the network.")}),document.addEventListener("visibilitychange",()=>{if(document.visibilityState==="visible")W()})}var Ph=(W)=>()=>nT(Uh(W).map(([X,G])=>[X,G.socket])),QG={},Rh=10,aT="x",sT="EVENT",Lh=/pow:\s*(\d+)\s*bits needed\.?/i,HQ=new Set,tT=Rz.utils.randomSecretKey(),Bh=wz(Rz.getPublicKey(tT)),Lz={},gJ={},Eh={},eT=()=>Math.floor(Date.now()/1000),WM=(W)=>Eh[W]??=eu(W,1e4)+20000,hJ=(W)=>W.replace(/\/$/,""),$h="https://cdn.jsdelivr.net/gh/estebanrfp/gdb@main/relays.json",XM=(W)=>Array.isArray(W)?[...new Set(W.filter((X)=>X?.startsWith?.("wss://")))]:[],GM="genosrtc_relays",Fh=()=>{try{return XM(JSON.parse(globalThis.localStorage?.getItem(GM)))}catch{return[]}},Sh=()=>fetch(`${$h}?r=${Math.random().toString(36).slice(2)}`,{signal:AbortSignal.timeout(5000)}).then((W)=>W.json()).then(XM).then((W)=>(W.length&&globalThis.localStorage?.setItem(GM,JSON.stringify(W)),W)).catch(()=>[]).then((W)=>(W=W.length?W:Fh(),W.length||_9.warn("\u26A0\uFE0F [GenosRTC] Relay list unreachable - Pass rtc.relayUrls to override."),W)),xh=(W,X)=>{let[G,Y,J,Z]=DQ(X);if(G===sT)return gJ[Y]?.(Lz[Y],J.content);if(G==="NOTICE"||G==="OK"&&!J){if(+((G==="NOTICE"?Y:Z).match(Lh)?.[1]??0)>0){let V=hJ(W);HQ.add(V),QG[V]?.close?.(),delete QG[V]}}},kh=(W)=>{let X=hJ(W);if(QG[X])return QG[X];let G=Mh(X,(Y)=>xh(X,Y));return QG[X]=G},Vz=async(W,X)=>{let G={kind:WM(W),content:X,pubkey:Bh,created_at:eT(),tags:[[aT,W]]},Y=Z4(K7([0,G.pubkey,G.created_at,G.kind,G.tags,G.content])),J=new Uint8Array(await crypto.subtle.digest("SHA-256",Y)),Z=Rz.sign(J,tT);return K7([sT,{...G,id:wz(J),sig:wz(Z)}])},qT=(W,X)=>{return Lz[W]=X,K7(["REQ",W,{kinds:[WM(X)],since:eT(),["#"+aT]:[X]}])},HT=(W)=>{return delete Lz[W],K7(["CLOSE",W])},YM=Ch({init:(W)=>{let X=W?.relayUrls?.length?W.relayUrls:null,G=X?Promise.resolve(X):Sh(),Y=X?.length??W.relayRedundancy??Rh;return BQ(Y,(J,Z)=>G.then((V)=>{let U=V[Z]&&kh(V[Z]);return U?U.ready.then(()=>U).catch(()=>null):null}))},subscribe:(W,X,G,Y)=>{let J=TQ(64),Z=TQ(64);gJ[J]=gJ[Z]=(U,Q)=>Y(U,Q,async(N,q)=>{if(HQ.has(hJ(W.url)))return;W.send(await Vz(N,q))});let V=()=>{W.send(qT(J,X)),W.send(qT(Z,G))};return V(),W.reopenHandlers.add(V),()=>{W.reopenHandlers.delete(V),W.send(HT(J)),W.send(HT(Z)),delete gJ[J],delete gJ[Z]}},announce:async(W,X)=>{if(HQ.has(hJ(W.url)))return;W.send(await Vz(X,K7({peerId:w8})))},bye:async(W,X)=>{if(HQ.has(hJ(W.url)))return;W.send(await Vz(X,K7({peerId:w8,bye:1})))}}),ie=Ph(QG),_h={cellSize:10},yh=5000,vh=3000,gh=2000,uh=2000,hh=1e4,bh=30000,mh=5000,fh=30000,MQ=(W)=>{let X=String(W||"").match(/cell-(\d+)/);return X?Number(X[1]):null},Uz=(W,X)=>{let G=MQ(W);if(G==null)return[];let Y=[];for(let J=1;J<X;J*=2){if(G-J>=0)Y.push(`cell-${G-J}`);if(G+J<X)Y.push(`cell-${G+J}`)}return Y},UQ=(W)=>`c${(MQ(W)||0).toString(36)}`,ph=10,ch=(W,X)=>{let G=+X.cellSize>=2?X.cellSize|0:ph;return Math.max(1,Math.ceil(W/G))},JM=(W)=>{let X=0;for(let G=0;G<W.length;G++)X=Math.imul(X^W.charCodeAt(G),2654435761);return X>>>0},z6=(W,X)=>{let G=0,Y=-1;for(let J=0;J<X;J++){let Z=JM(`${W}:${J}`);if(Z>Y)Y=Z,G=J}return G};function lh(W,X={},G={}){let Y={..._h,...X},J=1,Z={epoch:0,roster:[w8],set:new Set([w8]),key:w8,C:1,cellId:null,isBridge:!1,bridges:[],edgeBridges:[]},V={cellId:null},U=0,Q=0,N="",q=0,A=0,H=0,I=null,w=null,O=null,T=new Map,x=new Set,h=new Map,$=new Set,F=0,u=new Set,l=new Map,p=()=>Math.min(150,Math.ceil(Math.log2(Z.C+1))*2+3),s=(N0)=>Uz(N0,Z.C),y=W.on?.bind(W),t=W.off?.bind(W);if(y)W.on=(N0,F0)=>String(N0).startsWith("mesh:")?d(N0,F0):y(N0,F0);if(t)W.off=(N0,F0)=>String(N0).startsWith("mesh:")?h.get(N0)?.delete(F0):t(N0,F0);let H0=(N0)=>(x.add(N0),()=>x.delete(N0)),g=(N0,F0)=>{for(let m0 of x)try{m0(N0,F0)}catch(Y0){_9.error("\uD83D\uDD78\uFE0F [Cells] Error in deliver handler:",Y0)}},d=(N0,F0)=>{if(!h.has(N0))h.set(N0,new Set);return h.get(N0).add(F0),()=>h.get(N0)?.delete(F0)},P=(N0,...F0)=>{let m0=h.get(N0);if(m0)for(let Y0 of m0)try{Y0(...F0)}catch{}},E=(N0)=>{try{return typeof N0==="string"?JSON.parse(N0):N0}catch{return null}},f=()=>`${w8}:${Date.now().toString(36)}:${(F++&65535).toString(36)}`,r=()=>{if($.size>yh)$.delete($.values().next().value)},o=()=>[...new Set([...W._census(),w8])].sort(),B=(N0,F0,m0)=>F0.filter((Y0)=>z6(Y0,m0)===N0),S=(N0,F0,m0)=>{if(N0==null)return null;let Y0=(k0)=>JM(`${k0}@${N0}`),K0=null,P0=-1;for(let k0 of B(N0,F0,m0)){let R1=Y0(k0);if(R1>P0)P0=R1,K0=k0}return K0},_=(N0)=>{let F0=Z.audience?.get(N0);if(!F0)return[];return Object.keys(W.getPeers?.()||{}).filter((m0)=>F0.has(m0))},v=(N0,F0)=>{if(N0!==w&&!(Z.isBridge&&Z.bridges.some((x0)=>UQ(x0)===N0)))return;let m0=E(F0);if(!m0?.id||!m0?.t)return;if($.has(m0.id))return;$.add(m0.id),r();let{t:Y0,id:K0,ttl:P0,data:k0,origin:R1,originCell:Q1}=m0,X0=Z.cellId;if(Y0==="ping"&&k0?.pingId&&k0.target===w8&&R1!==w8){let x0={t:"pong",id:f(),ttl:p(),data:{pingId:k0.pingId,receivedAt:Date.now()},origin:w8,originCell:X0},k1=W.getPeers?.()?.[R1]?[R1]:_(X0);I?.send(JSON.stringify(x0),k1)}if(Y0==="pong"&&k0?.pingId){let x0=l.get(k0.pingId);if(x0)clearTimeout(x0.timeout),x0.resolve(Date.now()-x0.start),l.delete(k0.pingId)}if(Y0==="msg"&&R1!==w8)g(k0,R1);if(!Z.isBridge)return;if((P0??0)<=0)return;let C0=(x0,k1,W8=null)=>{if(!x0||!k1.length)return;let d1={t:Y0,id:K0,ttl:W8??(P0??p())-1,data:k0,origin:R1||w8,originCell:Q1||X0};x0.send(JSON.stringify(d1),k1)};if(N0===w){for(let x0 of s(X0))C0(R(x0),_(x0));return}C0(I,_(X0));for(let x0 of s(X0))if(UQ(x0)!==N0)C0(R(x0),_(x0))},R=(N0)=>{let F0=UQ(N0),m0=W.channel(F0);if(!u.has(F0))u.add(F0),m0.on("message",(Y0)=>v(F0,Y0));return m0},m=()=>{if(!Z.cellId)return;if(w=UQ(Z.cellId),I=W.channel(w),!u.has(w))u.add(w),I.on("message",(N0)=>v(w,N0));if(Z.isBridge)for(let N0 of s(Z.cellId))R(N0)},J0=(N0,F0)=>{if(!N0.cellId||!N0.set.has(F0))return!1;let m0=`cell-${z6(F0,N0.C)}`;return m0===N0.cellId||N0.bridges.includes(m0)||Uz(m0,N0.C).includes(N0.cellId)&&S(z6(F0,N0.C),N0.roster,N0.C)===F0},U0=(N0)=>Z.set.size<2&&(V.set?.size??0)<2||J0(Z,N0)||Date.now()<U&&J0(V,N0),q0=()=>{let N0=W.getPeers?.()||{};for(let F0 of Object.keys(N0))if(!U0(F0))N0[F0].close?.()};G.admit=U0;let $0=()=>({epoch:Z.epoch,cellId:Z.cellId,isBridge:Z.isBridge,bridges:Z.bridges,roster:[...Z.roster],cellSize:J,dynamicTTL:p(),totalCells:Z.C}),u0=()=>{A=Date.now();for(let[N0,F0]of T){if(N0===w8)continue;P("mesh:peer-state",{id:N0,cell:F0.cell,bridges:F0.bridges,timestamp:A})}},H1=(N0)=>{let F0=ch(N0.length,Y);J=Math.ceil(N0.length/F0);let m0=`cell-${z6(w8,F0)}`,Y0=new Map,K0=new Set,P0=new Map,k0=(x0)=>P0.get(x0)??P0.set(x0,new Set).get(x0);for(let x0 of N0)k0(`cell-${z6(x0,F0)}`).add(x0);let R1=new Map,Q1=(x0)=>R1.has(x0)?R1.get(x0):R1.set(x0,S(x0,N0,F0)).get(x0);for(let x0 of new Set(N0.map((k1)=>z6(k1,F0)))){let k1=`cell-${x0}`;for(let W8 of Uz(k1,F0)){if(MQ(W8)<x0)continue;for(let d1 of[Q1(x0),Q1(MQ(W8))]){if(!d1)continue;let N1=`cell-${z6(d1,F0)}`===k1?W8:k1,c=Y0.get(d1)??[];if(!c.includes(N1))c.push(N1);if(Y0.set(d1,c),k0(k1).add(d1),k0(W8).add(d1),k1===m0||W8===m0)K0.add(d1)}}}let X0=Y0.get(w8)??[],C0=Z.cellId!==m0||String(Z.bridges)!==String(X0);V=Z,Z={epoch:Z.epoch+1,roster:N0,set:new Set(N0),key:N0.join("|"),C:F0,cellId:m0,isBridge:X0.length>0,bridges:X0,edgeBridges:[...K0],audience:P0},H=Date.now(),T.clear();for(let x0 of N0){let k1=Y0.get(x0)??[];T.set(x0,{cell:`cell-${z6(x0,F0)}`,isBridge:k1.length>0,bridges:k1})}if(U=Date.now()+mh,C0)m();_9.info("\uD83D\uDD78\uFE0F [Cells] seal",{epoch:Z.epoch,myCell:m0,bridges:X0,C:F0,roster:N0.length}),u0(),P("mesh:state",$0())},v1=()=>{let N0=o(),F0=N0.join("|");if(F0===Z.key)Q=0;else{let m0=Date.now();if(Q||=m0,F0!==N)N=F0,q=m0;if(N0.some((Y0)=>!Z.set.has(Y0))||Z.edgeBridges.some((Y0)=>!N0.includes(Y0))||(W._gone?.()??[]).some((Y0)=>Z.set.has(Y0))?m0-q>=uh||m0-Q>=hh:m0-Q>=bh)Q=0,H1(N0)}if(U&&Date.now()>=U)U=0,q0()},h0=()=>{if(O)return;O=setInterval(()=>{if(v1(),Date.now()-A>=fh)u0()},gh)},F1=()=>{if(O)clearInterval(O),O=null},S1=(N0)=>{return new Promise((F0,m0)=>{let Y0=`${Date.now()}-${Math.random().toString(36).slice(2,8)}`,K0=Date.now(),P0=setTimeout(()=>{l.delete(Y0),m0(Error("Ping timeout"))},vh);l.set(Y0,{start:K0,resolve:F0,reject:m0,timeout:P0,peerId:N0});let k0={t:"ping",id:f(),ttl:p(),data:{pingId:Y0,target:N0},origin:w8,originCell:Z.cellId};I?.send(JSON.stringify(k0),_(Z.cellId))})};return W.on?.("peer:join",()=>v1()),W.on?.("peer:leave",()=>v1()),H1(o()),h0(),{send:(N0)=>{let F0={t:"msg",id:f(),ttl:p(),data:N0,origin:w8,originCell:Z.cellId},m0=JSON.stringify(F0);return I.send(m0,_(Z.cellId)),v(w,m0),Promise.resolve()},on:(N0,F0)=>N0==="message"?H0(F0):void 0,ping:S1,getState:()=>({...$0(),knownCells:new Set([...T.values()].map((N0)=>N0.cell)).size}),getPeerInfo:()=>new Map(T),getStableRoster:()=>[...Z.roster],getKnownCells:()=>{let N0=new Map;for(let[F0,{cell:m0}]of T)if(!N0.has(m0))N0.set(m0,{lastSeen:H,peerId:F0});return N0},getCellSize:()=>J,destroy:()=>{F1(),l.forEach((N0)=>clearTimeout(N0.timeout)),l.clear()}}}function dh(W,X,G){let Y={},J=YM({...W,admit:(Q)=>Y.admit?.(Q)??!0},X,G),Z=W.overlay||{},V=lh(J,Z,Y),U=new Map;return{on:(Q,N)=>J.on(Q,N),off:(Q,N)=>J.off?.(Q,N),channel:(Q)=>{if(U.has(Q))return U.get(Q);let N=J.channel(Q),q={send:(A,H)=>{if(H){let I=[].concat(H),w=J.getPeers?.()||{};if(I.every((O)=>w[O]))return N.send(A,H)}return V.send({_ch:Q,_d:A,_t:H})},on:(A,H)=>{if(A==="message")V.on("message",(I,w)=>{if(I?._ch!==Q)return;if(I._t&&![].concat(I._t).includes(w8))return;H(I._d,w)}),N.on(A,H);else N.on(A,H)},off:(A,H)=>N.off?.(A,H),_original:N};return U.set(Q,q),q},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 Bz=(W,X,G)=>W?.cells||W?.overlay?dh(W,X,G):YM(W,X,G);import{randomBytes as P2}from"crypto";function oh(){var W,X=!1,G=this;G._DeArray=function(Y,J,Z){return[Y.slice(J,J+Z)]},G._EnArray=function(Y,J,Z,V){for(var U=0;U<Z;Y[J+U]=V[U]?V[U]:0,U++);},G._DeChar=function(Y,J){return String.fromCharCode(Y[J])},G._EnChar=function(Y,J,Z){Y[J]=Z.charCodeAt(0)},G._DeInt=function(Y,J){var Z=X?W.len-1:0,V=X?-1:1,U=Z+V*W.len,Q,N,q;for(Q=0,N=Z,q=1;N!=U;Q+=Y[J+N]*q,N+=V,q*=256);if(W.bSigned&&Q&Math.pow(2,W.len*8-1))Q-=Math.pow(2,W.len*8);return Q},G._EnInt=function(Y,J,Z){var V=X?W.len-1:0,U=X?-1:1,Q=V+U*W.len,N;Z=Z<W.min?W.min:Z>W.max?W.max:Z;for(N=V;N!=Q;Y[J+N]=Z&255,N+=U,Z>>=8);},G._DeString=function(Y,J,Z){for(var V=Array(Z),U=0;U<Z;V[U]=String.fromCharCode(Y[J+U]),U++);return V.join("")},G._EnString=function(Y,J,Z,V){for(var U,Q=0;Q<Z;Y[J+Q]=(U=V.charCodeAt(Q))?U:0,Q++);},G._De754=function(Y,J){var Z,V,U,Q,N,q,A,H,I,w;A=W.mLen,H=W.len*8-W.mLen-1,w=(1<<H)-1,I=w>>1,Q=X?0:W.len-1,N=X?1:-1,Z=Y[J+Q],Q+=N,q=-7;for(V=Z&(1<<-q)-1,Z>>=-q,q+=H;q>0;V=V*256+Y[J+Q],Q+=N,q-=8);for(U=V&(1<<-q)-1,V>>=-q,q+=A;q>0;U=U*256+Y[J+Q],Q+=N,q-=8);switch(V){case 0:V=1-I;break;case w:return U?NaN:(Z?-1:1)*(1/0);default:U=U+Math.pow(2,A),V=V-I;break}return(Z?-1:1)*U*Math.pow(2,V-A)},G._En754=function(Y,J,Z){var V,U,Q,N,q,A,H,I,w,O;if(H=W.mLen,I=W.len*8-W.mLen-1,O=(1<<I)-1,w=O>>1,V=Z<0?1:0,Z=Math.abs(Z),isNaN(Z)||Z==1/0)Q=isNaN(Z)?1:0,U=O;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>=O)Q=0,U=O;else if(U+w>=1)Q=(Z*A-1)*Math.pow(2,H),U=U+w;else Q=Z*Math.pow(2,w-1)*Math.pow(2,H),U=0}for(N=X?W.len-1:0,q=X?-1:1;H>=8;Y[J+N]=Q&255,N+=q,Q/=256,H-=8);for(U=U<<H|Q,I+=H;I>0;Y[J+N]=U&255,N+=q,U/=256,I-=8);Y[J+N-q]|=V*128},G._DeInt64=function(Y,J){var Z=X?0:7,V=X?1:-1,U=Z+V*8,Q=[0,0,!W.bSigned],N,q,A;for(N=Z,A=1,q=0;N!=U;Q[A]=(Q[A]<<8>>>0)+Y[J+N],N+=V,q++,A=q<4?1:0);return Q},G._EnInt64=function(Y,J,Z){var V=X?0:7,U=X?1:-1,Q=V+U*8,N,q,A,H;for(N=V,A=1,q=0,H=24;N!=Q;Y[J+N]=Z[A]>>H&255,N+=U,q++,A=q<4?1:0,H=24-8*(q%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(Y,J,Z,V){for(var U=W.de,Q=[],N=0;N<Y;Q.push(U(Z,V+N*J)),N++);return Q},G._PackSeries=function(Y,J,Z,V,U,Q){for(var N=W.en,q=0;q<Y;N(Z,V+q*J,U[Q+q]),q++);},G.Unpack=function(Y,J,Z){X=Y.charAt(0)!="<",Z=Z?Z:0;var V=new RegExp(this._sPattern,"g"),U,Q,N,q=[];while(U=V.exec(Y)){if(Q=U[1]==null||U[1]==""?1:parseInt(U[1]),N=this._lenLut[U[2]],Z+Q*N>J.length)return;switch(U[2]){case"A":case"s":q.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]],q.push(this._UnpackSeries(Q,N,J,Z));break}Z+=Q*N}return Array.prototype.concat.apply([],q)},G.PackTo=function(Y,J,Z,V){X=Y.charAt(0)!="<";var U=new RegExp(this._sPattern,"g"),Q,N,q,A,H=0;while(Q=U.exec(Y)){if(N=Q[1]==null||Q[1]==""?1:parseInt(Q[1]),q=this._lenLut[Q[2]],Z+N*q>J.length)return!1;switch(Q[2]){case"A":case"s":if(H+1>V.length)return!1;this._elLut[Q[2]].en(J,Z,N,V[H]),H+=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]],H+N>V.length)return!1;this._PackSeries(N,q,J,Z,V,H),H+=N;break;case"x":for(A=0;A<N;A++)J[Z+A]=0;break}Z+=N*q}return J},G.Pack=function(Y,J){return this.PackTo(Y,Array(this.CalcLength(Y)),0,J)},G.CalcLength=function(Y){var J=new RegExp(this._sPattern,"g"),Z=0,V;while(V=J.exec(Y))Z+=(V[1]==null||V[1]==""?1:parseInt(V[1]))*this._lenLut[V[2]];return Z}}var X8=new oh;var y2=b1(IM(),1),AH=b1(bz(),1);import{createSocket as od}from"dgram";import{createSocket as rd}from"dgram";import*as v2 from"net";import{connect as ad}from"net";import{createSign as td,randomBytes as ed,webcrypto as Wo}from"crypto";var _N0=b1(pM(),1);var L7={};zA(L7,{verifySchema:()=>Jf,fromBER:()=>q4,compareSchema:()=>V4,VisibleString:()=>xW,ViewWriter:()=>oJ,VideotexString:()=>LG,ValueBlock:()=>X9,Utf8String:()=>m5,UniversalString:()=>TG,UTCTime:()=>kW,TimeOfDay:()=>eQ,TeletexString:()=>RG,TIME:()=>GN,Set:()=>c9,Sequence:()=>v9,Repeated:()=>jG,RelativeObjectIdentifier:()=>sQ,RawData:()=>_P,PrintableString:()=>PG,Primitive:()=>D6,OctetString:()=>P7,ObjectIdentifier:()=>DG,NumericString:()=>MG,Null:()=>M7,Integer:()=>C6,IA5String:()=>BG,HexBlock:()=>T7,GraphicString:()=>EG,GeneralizedTime:()=>SG,GeneralString:()=>$G,Enumerated:()=>OG,EndOfContent:()=>rQ,Duration:()=>XN,DateTime:()=>WN,DEFAULT_MAX_NODES:()=>XP,DEFAULT_MAX_DEPTH:()=>WP,DEFAULT_MAX_CONTENT_LENGTH:()=>GP,DATE:()=>tQ,Constructed:()=>l8,Choice:()=>iJ,CharacterString:()=>FG,Boolean:()=>KG,BmpString:()=>CG,BitString:()=>R7,BaseStringBlock:()=>nQ,BaseBlock:()=>y8,Any:()=>Q4});/*!
147
+ `),Qq.prototype[W]=X.toFunction({assertSize:Bj})});IE.exports=Qq;function Bj(W,X){if(W>X)throw new Xl(W,X)}});var D8=V1((Aq0,PE)=>{var Ej=jV(),Gl=nB(),Yl=sB(),Jl=eB(),Zl=XE(),Vl=JE(),jE=VE(),Ul=QE(),Ql=HE(),{encode:DE}=OV(),{decode:CE}=jY(),{encodingLength:Nl}=DV(),ql=wE(),TE=IY(),ME={array:Gl,bool:Jl,buffer:Yl,reserved:Zl,string:Vl,when:Ul,select:Ql};for(let W of Object.keys(jE))ME[W]=jE[W];var Nq=Symbol("schema");function KE(W){let X=new Ej({readableObjectMode:!1,writableObjectMode:!0,transform:Hl});return X[Nq]=W,X}function OE(W){let X=null,G=Buffer.isBuffer(W);if(!G)X=W;let Y=new Ej({transform:Al,readableObjectMode:!0,writableObjectMode:!1});if(Y[Nq]=X,G)Y.append(W);return Y}function Hl(W,X,G){try{DE(W,this[Nq],this);let Y=this.slice();this.consume(Y.length),G(null,Y)}catch(Y){G(Y)}}function Al(W,X,G){this.append(W);try{while(this.length>0){let Y=new ql(this),J=CE(Y,this[Nq]);Y.commit(),this.push(J)}G()}catch(Y){if(Y instanceof TE)G();else G(Y)}}PE.exports={createEncodeStream:KE,createDecodeStream:OE,encode:DE,decode:CE,encodingLength:Nl,createEncode:KE,createDecode:OE,types:ME,BinaryStream:Ej,NotEnoughDataError:TE}});var M$=V1((C$)=>{Object.defineProperty(C$,"__esModule",{value:!0});C$.LEB128=C$.SignedLEB128=C$.UnsignedLEB128=void 0;var PY;(function(W){W[W.LOWER_7=127]="LOWER_7",W[W.UPPER_1=128]="UPPER_1"})(PY||(PY={}));var D$=(W)=>Number.isSafeInteger(W);class RY{static decode(W,X=0){let G=this.$scanForNullBytes(W,X),Y=0,J=0;for(let Z=0;Z<=G-X;Z++){let V=W[X+Z]&PY.LOWER_7;Y|=V<<J,J+=7}return Y}static encode(W){if(this.check(W),W<0)throw Error(`An unsigned number must NOT be negative, ${W} is!`);let X=[],G=W;do{let Y=G&PY.LOWER_7;if(G>>=7,G)Y=Y|PY.UPPER_1;X.push(Y)}while(G);return Uint8Array.from(X)}static check(W){if(!D$(W))throw Error(`${W} is not a safe integer!`)}static $scanForNullBytes(W,X=0){let G=X,Y=0;do{if(G>=W.byteLength)throw Error("This is not a LEB128-encoded Uint8Array, no ending found!");Y=W.slice(G,G+1)[0],G++}while(Y&PY.UPPER_1);return G-1}static getLength(W,X=0){return this.$scanForNullBytes(W,X)-X}}C$.UnsignedLEB128=RY;class Pq{static $ceil7mul(W){let X=W;while(X%7)X++;return X}static check(W){if(!D$(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 X=Math.ceil(Math.log2(-W));return RY.encode((1<<this.$ceil7mul(X))+W)}static decode(W,X=0){let G=RY.decode(W,X);return-((1<<Math.ceil(Math.log2(G)))-G)}}C$.SignedLEB128=Pq;class Rq{}C$.LEB128=Rq;Rq.encode=(W)=>(W>=0?RY:Pq).encode(W);Rq.decode=(W,X=0,G=!1)=>(G?Pq:RY).decode(W,X)});var R$=V1((ij,P$)=>{/*! MIT License. Copyright 2015-2018 Richard Moore <me@ricmoo.com>. See LICENSE.txt. */(function(W){function X(B){return parseInt(B)===B}function G(B){if(!X(B.length))return!1;for(var S=0;S<B.length;S++)if(!X(B[S])||B[S]<0||B[S]>255)return!1;return!0}function Y(B,S){if(B.buffer&&B.name==="Uint8Array"){if(S)if(B.slice)B=B.slice();else B=Array.prototype.slice.call(B);return B}if(Array.isArray(B)){if(!G(B))throw Error("Array contains invalid value: "+B);return new Uint8Array(B)}if(X(B.length)&&G(B))return new Uint8Array(B);throw Error("unsupported array-like object")}function J(B){return new Uint8Array(B)}function Z(B,S,_,v,R){if(v!=null||R!=null)if(B.slice)B=B.slice(v,R);else B=Array.prototype.slice.call(B,v,R);S.set(B,_)}var V=function(){function B(_){var v=[],R=0;_=encodeURI(_);while(R<_.length){var m=_.charCodeAt(R++);if(m===37)v.push(parseInt(_.substr(R,2),16)),R+=2;else v.push(m)}return Y(v)}function S(_){var v=[],R=0;while(R<_.length){var m=_[R];if(m<128)v.push(String.fromCharCode(m)),R++;else if(m>191&&m<224)v.push(String.fromCharCode((m&31)<<6|_[R+1]&63)),R+=2;else v.push(String.fromCharCode((m&15)<<12|(_[R+1]&63)<<6|_[R+2]&63)),R+=3}return v.join("")}return{toBytes:B,fromBytes:S}}(),U=function(){function B(v){var R=[];for(var m=0;m<v.length;m+=2)R.push(parseInt(v.substr(m,2),16));return R}var S="0123456789abcdef";function _(v){var R=[];for(var m=0;m<v.length;m++){var J0=v[m];R.push(S[(J0&240)>>4]+S[J0&15])}return R.join("")}return{toBytes:B,fromBytes:_}}(),Q={16:10,24:12,32:14},N=[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],q=[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],H=[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],I=[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],O=[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],h=[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],$=[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],F=[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],u=[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],l=[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],f=[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 s(B){var S=[];for(var _=0;_<B.length;_+=4)S.push(B[_]<<24|B[_+1]<<16|B[_+2]<<8|B[_+3]);return S}var y=function(B){if(!(this instanceof y))throw Error("AES must be instanitated with `new`");Object.defineProperty(this,"key",{value:Y(B,!0)}),this._prepare()};y.prototype._prepare=function(){var B=Q[this.key.length];if(B==null)throw Error("invalid key size (must be 16, 24 or 32 bytes)");this._Ke=[],this._Kd=[];for(var S=0;S<=B;S++)this._Ke.push([0,0,0,0]),this._Kd.push([0,0,0,0]);var _=(B+1)*4,v=this.key.length/4,R=s(this.key),m;for(var S=0;S<v;S++)m=S>>2,this._Ke[m][S%4]=R[S],this._Kd[B-m][S%4]=R[S];var J0=0,U0=v,q0;while(U0<_){if(q0=R[v-1],R[0]^=q[q0>>16&255]<<24^q[q0>>8&255]<<16^q[q0&255]<<8^q[q0>>24&255]^N[J0]<<24,J0+=1,v!=8)for(var S=1;S<v;S++)R[S]^=R[S-1];else{for(var S=1;S<v/2;S++)R[S]^=R[S-1];q0=R[v/2-1],R[v/2]^=q[q0&255]^q[q0>>8&255]<<8^q[q0>>16&255]<<16^q[q0>>24&255]<<24;for(var S=v/2+1;S<v;S++)R[S]^=R[S-1]}var S=0,$0,u0;while(S<v&&U0<_)$0=U0>>2,u0=U0%4,this._Ke[$0][u0]=R[S],this._Kd[B-$0][u0]=R[S++],U0++}for(var $0=1;$0<B;$0++)for(var u0=0;u0<4;u0++)q0=this._Kd[$0][u0],this._Kd[$0][u0]=F[q0>>24&255]^u[q0>>16&255]^l[q0>>8&255]^f[q0&255]},y.prototype.encrypt=function(B){if(B.length!=16)throw Error("invalid plaintext size (must be 16 bytes)");var S=this._Ke.length-1,_=[0,0,0,0],v=s(B);for(var R=0;R<4;R++)v[R]^=this._Ke[0][R];for(var m=1;m<S;m++){for(var R=0;R<4;R++)_[R]=H[v[R]>>24&255]^I[v[(R+1)%4]>>16&255]^w[v[(R+2)%4]>>8&255]^O[v[(R+3)%4]&255]^this._Ke[m][R];v=_.slice()}var J0=J(16),U0;for(var R=0;R<4;R++)U0=this._Ke[S][R],J0[4*R]=(q[v[R]>>24&255]^U0>>24)&255,J0[4*R+1]=(q[v[(R+1)%4]>>16&255]^U0>>16)&255,J0[4*R+2]=(q[v[(R+2)%4]>>8&255]^U0>>8)&255,J0[4*R+3]=(q[v[(R+3)%4]&255]^U0)&255;return J0},y.prototype.decrypt=function(B){if(B.length!=16)throw Error("invalid ciphertext size (must be 16 bytes)");var S=this._Kd.length-1,_=[0,0,0,0],v=s(B);for(var R=0;R<4;R++)v[R]^=this._Kd[0][R];for(var m=1;m<S;m++){for(var R=0;R<4;R++)_[R]=T[v[R]>>24&255]^x[v[(R+3)%4]>>16&255]^h[v[(R+2)%4]>>8&255]^$[v[(R+1)%4]&255]^this._Kd[m][R];v=_.slice()}var J0=J(16),U0;for(var R=0;R<4;R++)U0=this._Kd[S][R],J0[4*R]=(A[v[R]>>24&255]^U0>>24)&255,J0[4*R+1]=(A[v[(R+3)%4]>>16&255]^U0>>16)&255,J0[4*R+2]=(A[v[(R+2)%4]>>8&255]^U0>>8)&255,J0[4*R+3]=(A[v[(R+1)%4]&255]^U0)&255;return J0};var t=function(B){if(!(this instanceof t))throw Error("AES must be instanitated with `new`");this.description="Electronic Code Block",this.name="ecb",this._aes=new y(B)};t.prototype.encrypt=function(B){if(B=Y(B),B.length%16!==0)throw Error("invalid plaintext size (must be multiple of 16 bytes)");var S=J(B.length),_=J(16);for(var v=0;v<B.length;v+=16)Z(B,_,0,v,v+16),_=this._aes.encrypt(_),Z(_,S,v);return S},t.prototype.decrypt=function(B){if(B=Y(B),B.length%16!==0)throw Error("invalid ciphertext size (must be multiple of 16 bytes)");var S=J(B.length),_=J(16);for(var v=0;v<B.length;v+=16)Z(B,_,0,v,v+16),_=this._aes.decrypt(_),Z(_,S,v);return S};var H0=function(B,S){if(!(this instanceof H0))throw Error("AES must be instanitated with `new`");if(this.description="Cipher Block Chaining",this.name="cbc",!S)S=J(16);else if(S.length!=16)throw Error("invalid initialation vector size (must be 16 bytes)");this._lastCipherblock=Y(S,!0),this._aes=new y(B)};H0.prototype.encrypt=function(B){if(B=Y(B),B.length%16!==0)throw Error("invalid plaintext size (must be multiple of 16 bytes)");var S=J(B.length),_=J(16);for(var v=0;v<B.length;v+=16){Z(B,_,0,v,v+16);for(var R=0;R<16;R++)_[R]^=this._lastCipherblock[R];this._lastCipherblock=this._aes.encrypt(_),Z(this._lastCipherblock,S,v)}return S},H0.prototype.decrypt=function(B){if(B=Y(B),B.length%16!==0)throw Error("invalid ciphertext size (must be multiple of 16 bytes)");var S=J(B.length),_=J(16);for(var v=0;v<B.length;v+=16){Z(B,_,0,v,v+16),_=this._aes.decrypt(_);for(var R=0;R<16;R++)S[v+R]=_[R]^this._lastCipherblock[R];Z(B,this._lastCipherblock,0,v,v+16)}return S};var g=function(B,S,_){if(!(this instanceof g))throw Error("AES must be instanitated with `new`");if(this.description="Cipher Feedback",this.name="cfb",!S)S=J(16);else if(S.length!=16)throw Error("invalid initialation vector size (must be 16 size)");if(!_)_=1;this.segmentSize=_,this._shiftRegister=Y(S,!0),this._aes=new y(B)};g.prototype.encrypt=function(B){if(B.length%this.segmentSize!=0)throw Error("invalid plaintext size (must be segmentSize bytes)");var S=Y(B,!0),_;for(var v=0;v<S.length;v+=this.segmentSize){_=this._aes.encrypt(this._shiftRegister);for(var R=0;R<this.segmentSize;R++)S[v+R]^=_[R];Z(this._shiftRegister,this._shiftRegister,0,this.segmentSize),Z(S,this._shiftRegister,16-this.segmentSize,v,v+this.segmentSize)}return S},g.prototype.decrypt=function(B){if(B.length%this.segmentSize!=0)throw Error("invalid ciphertext size (must be segmentSize bytes)");var S=Y(B,!0),_;for(var v=0;v<S.length;v+=this.segmentSize){_=this._aes.encrypt(this._shiftRegister);for(var R=0;R<this.segmentSize;R++)S[v+R]^=_[R];Z(this._shiftRegister,this._shiftRegister,0,this.segmentSize),Z(B,this._shiftRegister,16-this.segmentSize,v,v+this.segmentSize)}return S};var d=function(B,S){if(!(this instanceof d))throw Error("AES must be instanitated with `new`");if(this.description="Output Feedback",this.name="ofb",!S)S=J(16);else if(S.length!=16)throw Error("invalid initialation vector size (must be 16 bytes)");this._lastPrecipher=Y(S,!0),this._lastPrecipherIndex=16,this._aes=new y(B)};d.prototype.encrypt=function(B){var S=Y(B,!0);for(var _=0;_<S.length;_++){if(this._lastPrecipherIndex===16)this._lastPrecipher=this._aes.encrypt(this._lastPrecipher),this._lastPrecipherIndex=0;S[_]^=this._lastPrecipher[this._lastPrecipherIndex++]}return S},d.prototype.decrypt=d.prototype.encrypt;var P=function(B){if(!(this instanceof P))throw Error("Counter must be instanitated with `new`");if(B!==0&&!B)B=1;if(typeof B==="number")this._counter=J(16),this.setValue(B);else this.setBytes(B)};P.prototype.setValue=function(B){if(typeof B!=="number"||parseInt(B)!=B)throw Error("invalid counter value (must be an integer)");if(B>Number.MAX_SAFE_INTEGER)throw Error("integer value out of safe range");for(var S=15;S>=0;--S)this._counter[S]=B%256,B=parseInt(B/256)},P.prototype.setBytes=function(B){if(B=Y(B,!0),B.length!=16)throw Error("invalid counter bytes size (must be 16 bytes)");this._counter=B},P.prototype.increment=function(){for(var B=15;B>=0;B--)if(this._counter[B]===255)this._counter[B]=0;else{this._counter[B]++;break}};var E=function(B,S){if(!(this instanceof E))throw Error("AES must be instanitated with `new`");if(this.description="Counter",this.name="ctr",!(S instanceof P))S=new P(S);this._counter=S,this._remainingCounter=null,this._remainingCounterIndex=16,this._aes=new y(B)};E.prototype.encrypt=function(B){var S=Y(B,!0);for(var _=0;_<S.length;_++){if(this._remainingCounterIndex===16)this._remainingCounter=this._aes.encrypt(this._counter._counter),this._remainingCounterIndex=0,this._counter.increment();S[_]^=this._remainingCounter[this._remainingCounterIndex++]}return S},E.prototype.decrypt=E.prototype.encrypt;function p(B){B=Y(B,!0);var S=16-B.length%16,_=J(B.length+S);Z(B,_);for(var v=B.length;v<_.length;v++)_[v]=S;return _}function r(B){if(B=Y(B,!0),B.length<16)throw Error("PKCS#7 invalid length");var S=B[B.length-1];if(S>16)throw Error("PKCS#7 padding byte out of range");var _=B.length-S;for(var v=0;v<S;v++)if(B[_+v]!==S)throw Error("PKCS#7 invalid padding byte");var R=J(_);return Z(B,R,0,0,_),R}var o={AES:y,Counter:P,ModeOfOperation:{ecb:t,cbc:H0,cfb:g,ofb:d,ctr:E},utils:{hex:U,utf8:V},padding:{pkcs7:{pad:p,strip:r}},_arrayTest:{coerceArray:Y,createArray:J,copyArray:Z}};if(typeof ij<"u")P$.exports=o;else if(typeof define==="function"&&define.amd)define([],function(){return o});else{if(W.aesjs)o._aesjs=W.aesjs;W.aesjs=o}})(ij)});var tj=V1((S$)=>{var G1=S$,{Buffer:$q}=_8("buffer"),sl=_8("os");G1.toBuffer=function(W,X,G){G=~~G;let Y;if(this.isV4Format(W))Y=X||$q.alloc(G+4),W.split(/\./g).map((J)=>{Y[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)}Y=X||$q.alloc(G+16);for(Z=0;Z<J.length;Z++){let V=parseInt(J[Z],16);Y[G++]=V>>8&255,Y[G++]=V&255}}if(!Y)throw Error(`Invalid ip address: ${W}`);return Y};G1.toString=function(W,X,G){X=~~X,G=G||W.length-X;let Y=[];if(G===4){for(let J=0;J<G;J++)Y.push(W[X+J]);Y=Y.join(".")}else if(G===16){for(let J=0;J<G;J+=2)Y.push(W.readUInt16BE(X+J).toString(16));Y=Y.join(":"),Y=Y.replace(/(^|:)0(:0)*:0(:|$)/,"$1::$3"),Y=Y.replace(/:{3,4}/,"::")}return Y};var tl=/^(\d{1,3}\.){3,3}\d{1,3}$/,el=/^(::)?(((\d{1,3}\.){3}(\d{1,3}){1})?([0-9a-f]){0,4}:{0,2}){1,8}(::)?$/i;G1.isV4Format=function(W){return tl.test(W)};G1.isV6Format=function(W){return el.test(W)};function SV(W){if(W===4)return"ipv4";if(W===6)return"ipv6";return W?W.toLowerCase():"ipv4"}G1.fromPrefixLen=function(W,X){if(W>32)X="ipv6";else X=SV(X);let G=4;if(X==="ipv6")G=16;let Y=$q.alloc(G);for(let J=0,Z=Y.length;J<Z;++J){let V=8;if(W<8)V=W;W-=V,Y[J]=~(255>>V)&255}return G1.toString(Y)};G1.mask=function(W,X){W=G1.toBuffer(W),X=G1.toBuffer(X);let G=$q.alloc(Math.max(W.length,X.length)),Y;if(W.length===X.length)for(Y=0;Y<W.length;Y++)G[Y]=W[Y]&X[Y];else if(X.length===4)for(Y=0;Y<X.length;Y++)G[Y]=W[W.length-4+Y]&X[Y];else{for(Y=0;Y<G.length-6;Y++)G[Y]=0;G[10]=255,G[11]=255;for(Y=0;Y<W.length;Y++)G[Y+12]=W[Y]&X[Y+12];Y+=12}for(;Y<G.length;Y++)G[Y]=0;return G1.toString(G)};G1.cidr=function(W){let X=W.split("/"),G=X[0];if(X.length!==2)throw Error(`invalid CIDR subnet: ${G}`);let Y=G1.fromPrefixLen(parseInt(X[1],10));return G1.mask(G,Y)};G1.subnet=function(W,X){let G=G1.toLong(G1.mask(W,X)),Y=G1.toBuffer(X),J=0;for(let V=0;V<Y.length;V++)if(Y[V]===255)J+=8;else{let U=Y[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:X,subnetMaskLength:J,numHosts:Z<=2?Z:Z-2,length:Z,contains(V){return G===G1.toLong(G1.mask(V,X))}}};G1.cidrSubnet=function(W){let X=W.split("/"),G=X[0];if(X.length!==2)throw Error(`invalid CIDR subnet: ${G}`);let Y=G1.fromPrefixLen(parseInt(X[1],10));return G1.subnet(G,Y)};G1.not=function(W){let X=G1.toBuffer(W);for(let G=0;G<X.length;G++)X[G]=255^X[G];return G1.toString(X)};G1.or=function(W,X){if(W=G1.toBuffer(W),X=G1.toBuffer(X),W.length===X.length){for(let Z=0;Z<W.length;++Z)W[Z]|=X[Z];return G1.toString(W)}let G=W,Y=X;if(X.length>W.length)G=X,Y=W;let J=G.length-Y.length;for(let Z=J;Z<G.length;++Z)G[Z]|=Y[Z-J];return G1.toString(G)};G1.isEqual=function(W,X){if(W=G1.toBuffer(W),X=G1.toBuffer(X),W.length===X.length){for(let Y=0;Y<W.length;Y++)if(W[Y]!==X[Y])return!1;return!0}if(X.length===4){let Y=X;X=W,W=Y}for(let Y=0;Y<10;Y++)if(X[Y]!==0)return!1;let G=X.readUInt16BE(10);if(G!==0&&G!==65535)return!1;for(let Y=0;Y<4;Y++)if(W[Y]!==X[Y+12])return!1;return!0};G1.isPrivate=function(W){if(G1.isLoopback(W))return!0;if(!G1.isV6Format(W)){let X=G1.normalizeToLong(W);if(X<0)throw Error("invalid ipv4 address");W=G1.fromLong(X)}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=SV(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,X){let G=sl.networkInterfaces();if(X=SV(X),W&&W!=="private"&&W!=="public"){let J=G[W].filter((Z)=>{return SV(Z.family)===X});if(J.length===0)return;return J[0].address}let Y=Object.keys(G).map((J)=>{let Z=G[J].filter((V)=>{if(V.family=SV(V.family),V.family!==X||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!Y.length?G1.loopback(X):Y[0]};G1.toLong=function(W){let X=0;return W.split(".").forEach((G)=>{X<<=8,X+=parseInt(G)}),X>>>0};G1.fromLong=function(W){return`${W>>>24}.${W>>16&255}.${W>>8&255}.${W&255}`};G1.normalizeToLong=function(W){let X=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(X.some(isNaN))return-1;let G=0;switch(X.length){case 1:G=X[0];break;case 2:if(X[0]>255||X[1]>16777215)return-1;G=X[0]<<24|X[1]&16777215;break;case 3:if(X[0]>255||X[1]>255||X[2]>65535)return-1;G=X[0]<<24|X[1]<<16|X[2]&65535;break;case 4:if(X.some((J)=>J>255))return-1;G=X[0]<<24|X[1]<<16|X[2]<<8|X[3];break;default:return-1}return G>>>0}});var k$=V1((eq0,x$)=>{x$.exports=function W(X,G){if(X===G)return!0;if(X&&G&&typeof X=="object"&&typeof G=="object"){if(X.constructor!==G.constructor)return!1;var Y,J,Z;if(Array.isArray(X)){if(Y=X.length,Y!=G.length)return!1;for(J=Y;J--!==0;)if(!W(X[J],G[J]))return!1;return!0}if(X.constructor===RegExp)return X.source===G.source&&X.flags===G.flags;if(X.valueOf!==Object.prototype.valueOf)return X.valueOf()===G.valueOf();if(X.toString!==Object.prototype.toString)return X.toString()===G.toString();if(Z=Object.keys(X),Y=Z.length,Y!==Object.keys(G).length)return!1;for(J=Y;J--!==0;)if(!Object.prototype.hasOwnProperty.call(G,Z[J]))return!1;for(J=Y;J--!==0;){var V=Z[J];if(!W(X[V],G[V]))return!1}return!0}return X!==X&&G!==G}});var _$=V1((Wd)=>{Wd.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};Wd.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 y$=V1((Yd)=>{Yd.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};Yd.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 v$=V1((Vd)=>{Vd.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};Vd.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 g$=V1((Nd)=>{Nd.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};Nd.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 u$=V1((Ad)=>{Ad.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}`};Ad.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 X=W.match(/_(\d+)$/);if(X)return parseInt(X[1],10);return-1}});var m$=V1((b$,ej)=>{var h$=function(W){Object.defineProperty(W,"__esModule",{value:!0}),W.decode=A,W.encode=q,W.familyOf=N,W.name=void 0,W.sizeOf=Q,W.v6=W.v4=void 0;let X=/^(\d{1,3}\.){3,3}\d{1,3}$/,G=4,Y=/^(::)?(((\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:(H)=>X.test(H),encode(H,I,w){w=~~w,I=I||new Uint8Array(w+G);let O=H.length,T=0;for(let x=0;x<O;){let h=H.charCodeAt(x++);if(h===46)I[w++]=T,T=0;else T=T*10+(h-48)}return I[w]=T,I},decode(H,I){return I=~~I,`${H[I++]}.${H[I++]}.${H[I++]}.${H[I]}`}};W.v4=Z;let V={name:"v6",size:J,isFormat:(H)=>H.length>0&&Y.test(H),encode(H,I,w){w=~~w;let O=w+J,T=-1,x=0,h=0,$=!0,F=!1;I=I||new Uint8Array(w+J);for(let u=0;u<H.length;u++){let l=H.charCodeAt(u);if(l===58){if($){if(T!==-1){if(w<O)I[w]=0;if(w<O-1)I[w+1]=0;w+=2}else if(w<O)T=w}else{if(F===!0){if(w<O)I[w]=h;w++}else{if(w<O)I[w]=x>>8;if(w<O-1)I[w+1]=x&255;w+=2}x=0,h=0}$=!0,F=!1}else if(l===46){if(w<O)I[w]=h;w++,h=0,x=0,$=!1,F=!0}else{if($=!1,l>=97)l-=87;else if(l>=65)l-=55;else l-=48,h=h*10+l;x=(x<<4)+l}}if($===!1)if(F===!0){if(w<O)I[w]=h;w++}else{if(w<O)I[w]=x>>8;if(w<O-1)I[w+1]=x&255;w+=2}else if(T===0){if(w<O)I[w]=0;if(w<O-1)I[w+1]=0;w+=2}else if(T!==-1){w+=2;for(let u=Math.min(w-1,O-1);u>=T+2;u--)I[u]=I[u-2];I[T]=0,I[T+1]=0,T=w}if(T!==w&&T!==-1){if(w>O-2)w=O-2;while(O>T)I[--O]=w<O&&w>T?I[--w]:0}else while(w<O)I[w++]=0;return I},decode(H,I){I=~~I;let w="";for(let O=0;O<J;O+=2){if(O!==0)w+=":";w+=(H[I+O]<<8|H[I+O+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(H){if(Z.isFormat(H))return Z.size;if(V.isFormat(H))return V.size;throw Error(`Invalid ip address: ${H}`)}function N(H){return Q(H)===Z.size?1:2}function q(H,I,w){w=~~w;let O=Q(H);if(typeof I==="function")I=I(w+O);if(O===Z.size)return Z.encode(H,I,w);return V.encode(H,I,w)}function A(H,I,w){if(I=~~I,w=w||H.length-I,w===Z.size)return Z.decode(H,I,w);if(w===V.size)return V.decode(H,I,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 h$});else if(typeof ej==="object"&&typeof b$==="object")ej.exports=h$});var f$=V1((Dd)=>{var Z1=_8("buffer").Buffer,f4=_$(),wd=y$(),jd=v$(),Sq=g$(),GK=u$(),KX=m$(),g0=Dd.name={};g0.encode=function(W,X,G,{mail:Y=!1}={}){if(!X)X=Z1.alloc(g0.encodingLength(W));if(!G)G=0;let J=G,Z=W.replace(/^\.|\.$/gm,"");if(Z.length){let V=[];if(Y){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=X.write(V[U],G+1);X[G]=Q,G+=Q+1}}return X[G++]=0,g0.encode.bytes=G-J,X};g0.encode.bytes=0;g0.decode=function(W,X,{mail:G=!1}={}){if(!X)X=0;let Y=[],J=X,Z=0,V=0,U=!1;while(!0){if(X>=W.length)throw Error("Cannot decode name (buffer overflow)");let Q=W[X++];if(V+=U?0:1,Q===0)break;else if((Q&192)===0){if(X+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 N=W.toString("utf-8",X,X+Q);if(G)N=N.replace(/\./g,"\\.");Y.push(N),X+=Q,V+=U?0:Q}else if((Q&192)===192){if(X+1>W.length)throw Error("Cannot decode name (buffer overflow)");let N=W.readUInt16BE(X-1)-49152;if(N>=J)throw Error("Cannot decode name (bad pointer)");X=N,J=N,V+=U?0:1,U=!0}else throw Error("Cannot decode name (bad label)")}return g0.decode.bytes=V,Y.length===0?".":Y.join(".")};g0.decode.bytes=0;g0.encodingLength=function(W){if(W==="."||W==="..")return 1;return Z1.byteLength(W.replace(/^\.|\.$/gm,""))+2};var y1={};y1.encode=function(W,X,G){if(!X)X=Z1.alloc(y1.encodingLength(W));if(!G)G=0;let Y=X.write(W,G+1);return X[G]=Y,y1.encode.bytes=Y+1,X};y1.encode.bytes=0;y1.decode=function(W,X){if(!X)X=0;let G=W[X],Y=W.toString("utf-8",X+1,X+1+G);return y1.decode.bytes=G+1,Y};y1.decode.bytes=0;y1.encodingLength=function(W){return Z1.byteLength(W)+1};var W7={};W7.encode=function(W,X,G){if(!X)X=W7.encodingLength(W);if(!G)G=0;let Y=(W.flags||0)&32767,J=W.type==="response"?32768:0;return X.writeUInt16BE(W.id||0,G),X.writeUInt16BE(Y|J,G+2),X.writeUInt16BE(W.questions.length,G+4),X.writeUInt16BE(W.answers.length,G+6),X.writeUInt16BE(W.authorities.length,G+8),X.writeUInt16BE(W.additionals.length,G+10),X};W7.encode.bytes=12;W7.decode=function(W,X){if(!X)X=0;if(W.length<12)throw Error("Header must be 12 bytes");let G=W.readUInt16BE(X+2);return{id:W.readUInt16BE(X),type:G&32768?"response":"query",flags:G&32767,flag_qr:(G>>15&1)===1,opcode:jd.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:wd.toString(G&15),questions:Array(W.readUInt16BE(X+4)),answers:Array(W.readUInt16BE(X+6)),authorities:Array(W.readUInt16BE(X+8)),additionals:Array(W.readUInt16BE(X+10))}};W7.decode.bytes=12;W7.encodingLength=function(){return 12};var k4=Dd.unknown={};k4.encode=function(W,X,G){if(!X)X=Z1.alloc(k4.encodingLength(W));if(!G)G=0;return X.writeUInt16BE(W.length,G),W.copy(X,G+2),k4.encode.bytes=W.length+2,X};k4.encode.bytes=0;k4.decode=function(W,X){if(!X)X=0;let G=W.readUInt16BE(X),Y=W.slice(X+2,X+2+G);return k4.decode.bytes=G+2,Y};k4.decode.bytes=0;k4.encodingLength=function(W){return W.length+2};var _4=Dd.ns={};_4.encode=function(W,X,G){if(!X)X=Z1.alloc(_4.encodingLength(W));if(!G)G=0;return g0.encode(W,X,G+2),X.writeUInt16BE(g0.encode.bytes,G),_4.encode.bytes=g0.encode.bytes+2,X};_4.encode.bytes=0;_4.decode=function(W,X){if(!X)X=0;let G=W.readUInt16BE(X),Y=g0.decode(W,X+2);return _4.decode.bytes=G+2,Y};_4.decode.bytes=0;_4.encodingLength=function(W){return g0.encodingLength(W)+2};var y4=Dd.soa={};y4.encode=function(W,X,G){if(!X)X=Z1.alloc(y4.encodingLength(W));if(!G)G=0;let Y=G;return G+=2,g0.encode(W.mname,X,G),G+=g0.encode.bytes,g0.encode(W.rname,X,G,{mail:!0}),G+=g0.encode.bytes,X.writeUInt32BE(W.serial||0,G),G+=4,X.writeUInt32BE(W.refresh||0,G),G+=4,X.writeUInt32BE(W.retry||0,G),G+=4,X.writeUInt32BE(W.expire||0,G),G+=4,X.writeUInt32BE(W.minimum||0,G),G+=4,X.writeUInt16BE(G-Y-2,Y),y4.encode.bytes=G-Y,X};y4.encode.bytes=0;y4.decode=function(W,X){if(!X)X=0;let G=X,Y={};return X+=2,Y.mname=g0.decode(W,X),X+=g0.decode.bytes,Y.rname=g0.decode(W,X,{mail:!0}),X+=g0.decode.bytes,Y.serial=W.readUInt32BE(X),X+=4,Y.refresh=W.readUInt32BE(X),X+=4,Y.retry=W.readUInt32BE(X),X+=4,Y.expire=W.readUInt32BE(X),X+=4,Y.minimum=W.readUInt32BE(X),X+=4,y4.decode.bytes=X-G,Y};y4.decode.bytes=0;y4.encodingLength=function(W){return 22+g0.encodingLength(W.mname)+g0.encodingLength(W.rname)};var v4=Dd.txt={};v4.encode=function(W,X,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(!X)X=Z1.alloc(v4.encodingLength(W));if(!G)G=0;let Y=G;return G+=2,W.forEach(function(J){X[G++]=J.length,J.copy(X,G,0,J.length),G+=J.length}),X.writeUInt16BE(G-Y-2,Y),v4.encode.bytes=G-Y,X};v4.encode.bytes=0;v4.decode=function(W,X){if(!X)X=0;let G=X,Y=W.readUInt16BE(X);X+=2;let J=[];while(Y>0){let Z=W[X++];if(--Y,Y<Z)throw Error("Buffer overflow");J.push(W.slice(X,X+Z)),X+=Z,Y-=Z}return v4.decode.bytes=X-G,J};v4.decode.bytes=0;v4.encodingLength=function(W){if(!Array.isArray(W))W=[W];let X=2;return W.forEach(function(G){if(typeof G==="string")X+=Z1.byteLength(G)+1;else X+=G.length+1}),X};var g4=Dd.null={};g4.encode=function(W,X,G){if(!X)X=Z1.alloc(g4.encodingLength(W));if(!G)G=0;if(typeof W==="string")W=Z1.from(W);if(!W)W=Z1.alloc(0);let Y=G;G+=2;let J=W.length;return W.copy(X,G,0,J),G+=J,X.writeUInt16BE(G-Y-2,Y),g4.encode.bytes=G-Y,X};g4.encode.bytes=0;g4.decode=function(W,X){if(!X)X=0;let G=X,Y=W.readUInt16BE(X);X+=2;let J=W.slice(X,X+Y);return X+=Y,g4.decode.bytes=X-G,J};g4.decode.bytes=0;g4.encodingLength=function(W){if(!W)return 2;return(Z1.isBuffer(W)?W.length:Z1.byteLength(W))+2};var u4=Dd.hinfo={};u4.encode=function(W,X,G){if(!X)X=Z1.alloc(u4.encodingLength(W));if(!G)G=0;let Y=G;return G+=2,y1.encode(W.cpu,X,G),G+=y1.encode.bytes,y1.encode(W.os,X,G),G+=y1.encode.bytes,X.writeUInt16BE(G-Y-2,Y),u4.encode.bytes=G-Y,X};u4.encode.bytes=0;u4.decode=function(W,X){if(!X)X=0;let G=X,Y={};return X+=2,Y.cpu=y1.decode(W,X),X+=y1.decode.bytes,Y.os=y1.decode(W,X),X+=y1.decode.bytes,u4.decode.bytes=X-G,Y};u4.decode.bytes=0;u4.encodingLength=function(W){return y1.encodingLength(W.cpu)+y1.encodingLength(W.os)+2};var t5=Dd.ptr={},Kd=Dd.cname=t5,Od=Dd.dname=t5;t5.encode=function(W,X,G){if(!X)X=Z1.alloc(t5.encodingLength(W));if(!G)G=0;return g0.encode(W,X,G+2),X.writeUInt16BE(g0.encode.bytes,G),t5.encode.bytes=g0.encode.bytes+2,X};t5.encode.bytes=0;t5.decode=function(W,X){if(!X)X=0;let G=g0.decode(W,X+2);return t5.decode.bytes=g0.decode.bytes+2,G};t5.decode.bytes=0;t5.encodingLength=function(W){return g0.encodingLength(W)+2};var h4=Dd.srv={};h4.encode=function(W,X,G){if(!X)X=Z1.alloc(h4.encodingLength(W));if(!G)G=0;X.writeUInt16BE(W.priority||0,G+2),X.writeUInt16BE(W.weight||0,G+4),X.writeUInt16BE(W.port||0,G+6),g0.encode(W.target,X,G+8);let Y=g0.encode.bytes+6;return X.writeUInt16BE(Y,G),h4.encode.bytes=Y+2,X};h4.encode.bytes=0;h4.decode=function(W,X){if(!X)X=0;let G=W.readUInt16BE(X),Y={};return Y.priority=W.readUInt16BE(X+2),Y.weight=W.readUInt16BE(X+4),Y.port=W.readUInt16BE(X+6),Y.target=g0.decode(W,X+8),h4.decode.bytes=G+2,Y};h4.decode.bytes=0;h4.encodingLength=function(W){return 8+g0.encodingLength(W.target)};var H5=Dd.caa={};H5.ISSUER_CRITICAL=128;H5.encode=function(W,X,G){let Y=H5.encodingLength(W);if(!X)X=Z1.alloc(H5.encodingLength(W));if(!G)G=0;if(W.issuerCritical)W.flags=H5.ISSUER_CRITICAL;return X.writeUInt16BE(Y-2,G),G+=2,X.writeUInt8(W.flags||0,G),G+=1,y1.encode(W.tag,X,G),G+=y1.encode.bytes,X.write(W.value,G),G+=Z1.byteLength(W.value),H5.encode.bytes=Y,X};H5.encode.bytes=0;H5.decode=function(W,X){if(!X)X=0;let G=W.readUInt16BE(X);X+=2;let Y=X,J={};return J.flags=W.readUInt8(X),X+=1,J.tag=y1.decode(W,X),X+=y1.decode.bytes,J.value=W.toString("utf-8",X,Y+G),J.issuerCritical=!!(J.flags&H5.ISSUER_CRITICAL),H5.decode.bytes=G+2,J};H5.decode.bytes=0;H5.encodingLength=function(W){return y1.encodingLength(W.tag)+y1.encodingLength(W.value)+2};var i6=Dd.mx={};i6.encode=function(W,X,G){if(!X)X=Z1.alloc(i6.encodingLength(W));if(!G)G=0;let Y=G;return G+=2,X.writeUInt16BE(W.preference||0,G),G+=2,g0.encode(W.exchange,X,G),G+=g0.encode.bytes,X.writeUInt16BE(G-Y-2,Y),i6.encode.bytes=G-Y,X};i6.encode.bytes=0;i6.decode=function(W,X){if(!X)X=0;let G=X,Y={};return X+=2,Y.preference=W.readUInt16BE(X),X+=2,Y.exchange=g0.decode(W,X),X+=g0.decode.bytes,i6.decode.bytes=X-G,Y};i6.encodingLength=function(W){return 4+g0.encodingLength(W.exchange)};var b4=Dd.a={};b4.encode=function(W,X,G){if(!X)X=Z1.alloc(b4.encodingLength(W));if(!G)G=0;return X.writeUInt16BE(4,G),G+=2,KX.v4.encode(W,X,G),b4.encode.bytes=6,X};b4.encode.bytes=0;b4.decode=function(W,X){if(!X)X=0;X+=2;let G=KX.v4.decode(W,X);return b4.decode.bytes=6,G};b4.decode.bytes=0;b4.encodingLength=function(){return 6};var m4=Dd.aaaa={};m4.encode=function(W,X,G){if(!X)X=Z1.alloc(m4.encodingLength(W));if(!G)G=0;return X.writeUInt16BE(16,G),G+=2,KX.v6.encode(W,X,G),m4.encode.bytes=18,X};m4.encode.bytes=0;m4.decode=function(W,X){if(!X)X=0;X+=2;let G=KX.v6.decode(W,X);return m4.decode.bytes=18,G};m4.decode.bytes=0;m4.encodingLength=function(){return 18};var s9=Dd.option={};s9.encode=function(W,X,G){if(!X)X=Z1.alloc(s9.encodingLength(W));if(!G)G=0;let Y=G,J=GK.toCode(W.code);if(X.writeUInt16BE(J,G),G+=2,W.data)X.writeUInt16BE(W.data.length,G),G+=2,W.data.copy(X,G),G+=W.data.length;else switch(J){case 8:let Z=W.sourcePrefixLength||0,V=W.family||KX.familyOf(W.ip),U=KX.encode(W.ip,Z1.alloc),Q=Math.ceil(Z/8);X.writeUInt16BE(Q+4,G),G+=2,X.writeUInt16BE(V,G),G+=2,X.writeUInt8(Z,G++),X.writeUInt8(W.scopePrefixLength||0,G++),U.copy(X,G,0,Q),G+=Q;break;case 11:if(W.timeout)X.writeUInt16BE(2,G),G+=2,X.writeUInt16BE(W.timeout,G),G+=2;else X.writeUInt16BE(0,G),G+=2;break;case 12:let N=W.length||0;X.writeUInt16BE(N,G),G+=2,X.fill(0,G,G+N),G+=N;break;case 14:let q=W.tags.length*2;X.writeUInt16BE(q,G),G+=2;for(let A of W.tags)X.writeUInt16BE(A,G),G+=2;break;default:throw Error(`Unknown roption code: ${W.code}`)}return s9.encode.bytes=G-Y,X};s9.encode.bytes=0;s9.decode=function(W,X){if(!X)X=0;let G={};G.code=W.readUInt16BE(X),G.type=GK.toString(G.code),X+=2;let Y=W.readUInt16BE(X);switch(X+=2,G.data=W.slice(X,X+Y),G.code){case 8:G.family=W.readUInt16BE(X),X+=2,G.sourcePrefixLength=W.readUInt8(X++),G.scopePrefixLength=W.readUInt8(X++);let J=Z1.alloc(G.family===1?4:16);W.copy(J,0,X,X+Y-4),G.ip=KX.decode(J);break;case 11:if(Y>0)G.timeout=W.readUInt16BE(X),X+=2;break;case 14:G.tags=[];for(let Z=0;Z<Y;Z+=2)G.tags.push(W.readUInt16BE(X)),X+=2}return s9.decode.bytes=Y+4,G};s9.decode.bytes=0;s9.encodingLength=function(W){if(W.data)return W.data.length+4;switch(GK.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 z5=Dd.opt={};z5.encode=function(W,X,G){if(!X)X=Z1.alloc(z5.encodingLength(W));if(!G)G=0;let Y=G,J=FY(W,s9);return X.writeUInt16BE(J,G),G=xV(W,s9,X,G+2),z5.encode.bytes=G-Y,X};z5.encode.bytes=0;z5.decode=function(W,X){if(!X)X=0;let G=X,Y=[],J=W.readUInt16BE(X);X+=2;let Z=0;while(J>0)Y[Z++]=s9.decode(W,X),X+=s9.decode.bytes,J-=s9.decode.bytes;return z5.decode.bytes=X-G,Y};z5.decode.bytes=0;z5.encodingLength=function(W){return 2+FY(W||[],s9)};var h9=Dd.dnskey={};h9.PROTOCOL_DNSSEC=3;h9.ZONE_KEY=128;h9.SECURE_ENTRYPOINT=32768;h9.encode=function(W,X,G){if(!X)X=Z1.alloc(h9.encodingLength(W));if(!G)G=0;let Y=G,J=W.key;if(!Z1.isBuffer(J))throw Error("Key must be a Buffer");return G+=2,X.writeUInt16BE(W.flags,G),G+=2,X.writeUInt8(h9.PROTOCOL_DNSSEC,G),G+=1,X.writeUInt8(W.algorithm,G),G+=1,J.copy(X,G,0,J.length),G+=J.length,h9.encode.bytes=G-Y,X.writeUInt16BE(h9.encode.bytes-2,Y),X};h9.encode.bytes=0;h9.decode=function(W,X){if(!X)X=0;let G=X;var Y={},J=W.readUInt16BE(X);if(X+=2,Y.flags=W.readUInt16BE(X),X+=2,W.readUInt8(X)!==h9.PROTOCOL_DNSSEC)throw Error("Protocol must be 3");return X+=1,Y.algorithm=W.readUInt8(X),X+=1,Y.key=W.slice(X,G+J+2),X+=Y.key.length,h9.decode.bytes=X-G,Y};h9.decode.bytes=0;h9.encodingLength=function(W){return 6+Z1.byteLength(W.key)};var v7=Dd.rrsig={};v7.encode=function(W,X,G){if(!X)X=Z1.alloc(v7.encodingLength(W));if(!G)G=0;let Y=G,J=W.signature;if(!Z1.isBuffer(J))throw Error("Signature must be a Buffer");return G+=2,X.writeUInt16BE(f4.toType(W.typeCovered),G),G+=2,X.writeUInt8(W.algorithm,G),G+=1,X.writeUInt8(W.labels,G),G+=1,X.writeUInt32BE(W.originalTTL,G),G+=4,X.writeUInt32BE(W.expiration,G),G+=4,X.writeUInt32BE(W.inception,G),G+=4,X.writeUInt16BE(W.keyTag,G),G+=2,g0.encode(W.signersName,X,G),G+=g0.encode.bytes,J.copy(X,G,0,J.length),G+=J.length,v7.encode.bytes=G-Y,X.writeUInt16BE(v7.encode.bytes-2,Y),X};v7.encode.bytes=0;v7.decode=function(W,X){if(!X)X=0;let G=X;var Y={},J=W.readUInt16BE(X);return X+=2,Y.typeCovered=f4.toString(W.readUInt16BE(X)),X+=2,Y.algorithm=W.readUInt8(X),X+=1,Y.labels=W.readUInt8(X),X+=1,Y.originalTTL=W.readUInt32BE(X),X+=4,Y.expiration=W.readUInt32BE(X),X+=4,Y.inception=W.readUInt32BE(X),X+=4,Y.keyTag=W.readUInt16BE(X),X+=2,Y.signersName=g0.decode(W,X),X+=g0.decode.bytes,Y.signature=W.slice(X,G+J+2),X+=Y.signature.length,v7.decode.bytes=X-G,Y};v7.decode.bytes=0;v7.encodingLength=function(W){return 20+g0.encodingLength(W.signersName)+Z1.byteLength(W.signature)};var g7=Dd.rp={};g7.encode=function(W,X,G){if(!X)X=Z1.alloc(g7.encodingLength(W));if(!G)G=0;let Y=G;return G+=2,g0.encode(W.mbox||".",X,G,{mail:!0}),G+=g0.encode.bytes,g0.encode(W.txt||".",X,G),G+=g0.encode.bytes,g7.encode.bytes=G-Y,X.writeUInt16BE(g7.encode.bytes-2,Y),X};g7.encode.bytes=0;g7.decode=function(W,X){if(!X)X=0;let G=X,Y={};return X+=2,Y.mbox=g0.decode(W,X,{mail:!0})||".",X+=g0.decode.bytes,Y.txt=g0.decode(W,X)||".",X+=g0.decode.bytes,g7.decode.bytes=X-G,Y};g7.decode.bytes=0;g7.encodingLength=function(W){return 2+g0.encodingLength(W.mbox||".")+g0.encodingLength(W.txt||".")};var a8={};a8.encode=function(W,X,G){if(!X)X=Z1.alloc(a8.encodingLength(W));if(!G)G=0;let Y=G;var J=[];for(var Z=0;Z<W.length;Z++){var V=f4.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]);X.writeUInt8(Z,G),G+=1,X.writeUInt8(U.length,G),G+=1,U.copy(X,G),G+=U.length}return a8.encode.bytes=G-Y,X};a8.encode.bytes=0;a8.decode=function(W,X,G){if(!X)X=0;let Y=X;var J=[];while(X-Y<G){var Z=W.readUInt8(X);X+=1;var V=W.readUInt8(X);X+=1;for(var U=0;U<V;U++){var Q=W.readUInt8(X+U);for(var N=0;N<8;N++)if(Q&1<<7-N){var q=f4.toString(Z<<8|U<<3|N);J.push(q)}}X+=V}return a8.decode.bytes=X-Y,J};a8.decode.bytes=0;a8.encodingLength=function(W){var X=[];for(var G=0;G<W.length;G++){var Y=f4.toType(W[G]);X[Y>>8]=Math.max(X[Y>>8]||0,Y&255)}var J=0;for(G=0;G<X.length;G++)if(X[G]!==void 0)J+=2+Math.ceil((X[G]+1)/8);return J};var u7=Dd.nsec={};u7.encode=function(W,X,G){if(!X)X=Z1.alloc(u7.encodingLength(W));if(!G)G=0;let Y=G;return G+=2,g0.encode(W.nextDomain,X,G),G+=g0.encode.bytes,a8.encode(W.rrtypes,X,G),G+=a8.encode.bytes,u7.encode.bytes=G-Y,X.writeUInt16BE(u7.encode.bytes-2,Y),X};u7.encode.bytes=0;u7.decode=function(W,X){if(!X)X=0;let G=X;var Y={},J=W.readUInt16BE(X);return X+=2,Y.nextDomain=g0.decode(W,X),X+=g0.decode.bytes,Y.rrtypes=a8.decode(W,X,J-(X-G)),X+=a8.decode.bytes,u7.decode.bytes=X-G,Y};u7.decode.bytes=0;u7.encodingLength=function(W){return 2+g0.encodingLength(W.nextDomain)+a8.encodingLength(W.rrtypes)};var h7=Dd.nsec3={};h7.encode=function(W,X,G){if(!X)X=Z1.alloc(h7.encodingLength(W));if(!G)G=0;let Y=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,X.writeUInt8(W.algorithm,G),G+=1,X.writeUInt8(W.flags,G),G+=1,X.writeUInt16BE(W.iterations,G),G+=2,X.writeUInt8(J.length,G),G+=1,J.copy(X,G,0,J.length),G+=J.length,X.writeUInt8(Z.length,G),G+=1,Z.copy(X,G,0,Z.length),G+=Z.length,a8.encode(W.rrtypes,X,G),G+=a8.encode.bytes,h7.encode.bytes=G-Y,X.writeUInt16BE(h7.encode.bytes-2,Y),X};h7.encode.bytes=0;h7.decode=function(W,X){if(!X)X=0;let G=X;var Y={},J=W.readUInt16BE(X);X+=2,Y.algorithm=W.readUInt8(X),X+=1,Y.flags=W.readUInt8(X),X+=1,Y.iterations=W.readUInt16BE(X),X+=2;let Z=W.readUInt8(X);X+=1,Y.salt=W.slice(X,X+Z),X+=Z;let V=W.readUInt8(X);return X+=1,Y.nextDomain=W.slice(X,X+V),X+=V,Y.rrtypes=a8.decode(W,X,J-(X-G)),X+=a8.decode.bytes,h7.decode.bytes=X-G,Y};h7.decode.bytes=0;h7.encodingLength=function(W){return 8+W.salt.length+W.nextDomain.length+a8.encodingLength(W.rrtypes)};var b7=Dd.ds={};b7.encode=function(W,X,G){if(!X)X=Z1.alloc(b7.encodingLength(W));if(!G)G=0;let Y=G,J=W.digest;if(!Z1.isBuffer(J))throw Error("Digest must be a Buffer");return G+=2,X.writeUInt16BE(W.keyTag,G),G+=2,X.writeUInt8(W.algorithm,G),G+=1,X.writeUInt8(W.digestType,G),G+=1,J.copy(X,G,0,J.length),G+=J.length,b7.encode.bytes=G-Y,X.writeUInt16BE(b7.encode.bytes-2,Y),X};b7.encode.bytes=0;b7.decode=function(W,X){if(!X)X=0;let G=X;var Y={},J=W.readUInt16BE(X);return X+=2,Y.keyTag=W.readUInt16BE(X),X+=2,Y.algorithm=W.readUInt8(X),X+=1,Y.digestType=W.readUInt8(X),X+=1,Y.digest=W.slice(X,G+J+2),X+=Y.digest.length,b7.decode.bytes=X-G,Y};b7.decode.bytes=0;b7.encodingLength=function(W){return 6+Z1.byteLength(W.digest)};var A5=Dd.sshfp={};A5.getFingerprintLengthForHashType=function(X){switch(X){case 1:return 20;case 2:return 32}};A5.encode=function(X,G,Y){if(!G)G=Z1.alloc(A5.encodingLength(X));if(!Y)Y=0;let J=Y;Y+=2,G[Y]=X.algorithm,Y+=1,G[Y]=X.hash,Y+=1;let Z=Z1.from(X.fingerprint.toUpperCase(),"hex");if(Z.length!==A5.getFingerprintLengthForHashType(X.hash))throw Error("Invalid fingerprint length");return Z.copy(G,Y),Y+=Z.byteLength,A5.encode.bytes=Y-J,G.writeUInt16BE(A5.encode.bytes-2,J),G};A5.encode.bytes=0;A5.decode=function(X,G){if(!G)G=0;let Y=G,J={};G+=2,J.algorithm=X[G],G+=1,J.hash=X[G],G+=1;let Z=A5.getFingerprintLengthForHashType(J.hash);return J.fingerprint=X.slice(G,G+Z).toString("hex").toUpperCase(),G+=Z,A5.decode.bytes=G-Y,J};A5.decode.bytes=0;A5.encodingLength=function(W){return 4+Z1.from(W.fingerprint,"hex").byteLength};var m7=Dd.naptr={};m7.encode=function(W,X,G){if(!X)X=Z1.alloc(m7.encodingLength(W));if(!G)G=0;let Y=G;return G+=2,X.writeUInt16BE(W.order||0,G),G+=2,X.writeUInt16BE(W.preference||0,G),G+=2,y1.encode(W.flags,X,G),G+=y1.encode.bytes,y1.encode(W.services,X,G),G+=y1.encode.bytes,y1.encode(W.regexp,X,G),G+=y1.encode.bytes,g0.encode(W.replacement,X,G),G+=g0.encode.bytes,m7.encode.bytes=G-Y,X.writeUInt16BE(m7.encode.bytes-2,Y),X};m7.encode.bytes=0;m7.decode=function(W,X){if(!X)X=0;let G=X,Y={};return X+=2,Y.order=W.readUInt16BE(X),X+=2,Y.preference=W.readUInt16BE(X),X+=2,Y.flags=y1.decode(W,X),X+=y1.decode.bytes,Y.services=y1.decode(W,X),X+=y1.decode.bytes,Y.regexp=y1.decode(W,X),X+=y1.decode.bytes,Y.replacement=g0.decode(W,X),X+=g0.decode.bytes,m7.decode.bytes=X-G,Y};m7.decode.bytes=0;m7.encodingLength=function(W){return y1.encodingLength(W.flags)+y1.encodingLength(W.services)+y1.encodingLength(W.regexp)+g0.encodingLength(W.replacement)+6};var f7=Dd.tlsa={};f7.encode=function(W,X,G){if(!X)X=Z1.alloc(f7.encodingLength(W));if(!G)G=0;let Y=G,J=W.certificate;if(!Z1.isBuffer(J))throw Error("Certificate must be a Buffer");return G+=2,X.writeUInt8(W.usage,G),G+=1,X.writeUInt8(W.selector,G),G+=1,X.writeUInt8(W.matchingType,G),G+=1,J.copy(X,G,0,J.length),G+=J.length,f7.encode.bytes=G-Y,X.writeUInt16BE(f7.encode.bytes-2,Y),X};f7.encode.bytes=0;f7.decode=function(W,X){if(!X)X=0;let G=X,Y={},J=W.readUInt16BE(X);return X+=2,Y.usage=W.readUInt8(X),X+=1,Y.selector=W.readUInt8(X),X+=1,Y.matchingType=W.readUInt8(X),X+=1,Y.certificate=W.slice(X,G+J+2),X+=Y.certificate.length,f7.decode.bytes=X-G,Y};f7.decode.bytes=0;f7.encodingLength=function(W){return 5+Z1.byteLength(W.certificate)};var YK=Dd.record=function(W){switch(W.toUpperCase()){case"A":return b4;case"PTR":return t5;case"CNAME":return Kd;case"DNAME":return Od;case"TXT":return v4;case"NULL":return g4;case"AAAA":return m4;case"SRV":return h4;case"HINFO":return u4;case"CAA":return H5;case"NS":return _4;case"SOA":return y4;case"MX":return i6;case"OPT":return z5;case"DNSKEY":return h9;case"RRSIG":return v7;case"RP":return g7;case"NSEC":return u7;case"NSEC3":return h7;case"SSHFP":return A5;case"DS":return b7;case"NAPTR":return m7;case"TLSA":return f7}return k4},V9=Dd.answer={};V9.encode=function(W,X,G){if(!X)X=Z1.alloc(V9.encodingLength(W));if(!G)G=0;let Y=G;if(g0.encode(W.name,X,G),G+=g0.encode.bytes,X.writeUInt16BE(f4.toType(W.type),G),W.type.toUpperCase()==="OPT"){if(W.name!==".")throw Error("OPT name must be root.");X.writeUInt16BE(W.udpPayloadSize||4096,G+2),X.writeUInt8(W.extendedRcode||0,G+4),X.writeUInt8(W.ednsVersion||0,G+5),X.writeUInt16BE(W.flags||0,G+6),G+=8,z5.encode(W.options||[],X,G),G+=z5.encode.bytes}else{let J=Sq.toClass(W.class===void 0?"IN":W.class);if(W.flush)J|=32768;X.writeUInt16BE(J,G+2),X.writeUInt32BE(W.ttl||0,G+4),G+=8;let Z=YK(W.type);Z.encode(W.data,X,G),G+=Z.encode.bytes}return V9.encode.bytes=G-Y,X};V9.encode.bytes=0;V9.decode=function(W,X){if(!X)X=0;let G={},Y=X;if(G.name=g0.decode(W,X),X+=g0.decode.bytes,G.type=f4.toString(W.readUInt16BE(X)),G.type==="OPT")G.udpPayloadSize=W.readUInt16BE(X+2),G.extendedRcode=W.readUInt8(X+4),G.ednsVersion=W.readUInt8(X+5),G.flags=W.readUInt16BE(X+6),G.flag_do=(G.flags>>15&1)===1,G.options=z5.decode(W,X+8),X+=8+z5.decode.bytes;else{let J=W.readUInt16BE(X+2);G.ttl=W.readUInt32BE(X+4),G.class=Sq.toString(J&-32769),G.flush=!!(J&32768);let Z=YK(G.type);G.data=Z.decode(W,X+8),X+=8+Z.decode.bytes}return V9.decode.bytes=X-Y,G};V9.decode.bytes=0;V9.encodingLength=function(W){let X=W.data!==null&&W.data!==void 0?W.data:W.options;return g0.encodingLength(W.name)+8+YK(W.type).encodingLength(X)};var e5=Dd.question={};e5.encode=function(W,X,G){if(!X)X=Z1.alloc(e5.encodingLength(W));if(!G)G=0;let Y=G;return g0.encode(W.name,X,G),G+=g0.encode.bytes,X.writeUInt16BE(f4.toType(W.type),G),G+=2,X.writeUInt16BE(Sq.toClass(W.class===void 0?"IN":W.class),G),G+=2,e5.encode.bytes=G-Y,W};e5.encode.bytes=0;e5.decode=function(W,X){if(!X)X=0;let G=X,Y={};if(Y.name=g0.decode(W,X),X+=g0.decode.bytes,Y.type=f4.toString(W.readUInt16BE(X)),X+=2,Y.class=Sq.toString(W.readUInt16BE(X)),X+=2,!!(Y.class&32768))Y.class&=-32769;return e5.decode.bytes=X-G,Y};e5.decode.bytes=0;e5.encodingLength=function(W){return g0.encodingLength(W.name)+4};Dd.AUTHORITATIVE_ANSWER=1024;Dd.TRUNCATED_RESPONSE=512;Dd.RECURSION_DESIRED=256;Dd.RECURSION_AVAILABLE=128;Dd.AUTHENTIC_DATA=32;Dd.CHECKING_DISABLED=16;Dd.DNSSEC_OK=32768;Dd.encode=function(W,X,G){let Y=!X;if(Y)X=Z1.alloc(Dd.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(W7.encode(W,X,G),G+=W7.encode.bytes,G=xV(W.questions,e5,X,G),G=xV(W.answers,V9,X,G),G=xV(W.authorities,V9,X,G),G=xV(W.additionals,V9,X,G),Dd.encode.bytes=G-J,Y&&Dd.encode.bytes!==X.length)return X.slice(0,Dd.encode.bytes);return X};Dd.encode.bytes=0;Dd.decode=function(W,X){if(!X)X=0;let G=X,Y=W7.decode(W,X);return X+=W7.decode.bytes,X=Fq(Y.questions,e5,W,X),X=Fq(Y.answers,V9,W,X),X=Fq(Y.authorities,V9,W,X),X=Fq(Y.additionals,V9,W,X),Dd.decode.bytes=X-G,Y};Dd.decode.bytes=0;Dd.encodingLength=function(W){return W7.encodingLength(W)+FY(W.questions||[],e5)+FY(W.answers||[],V9)+FY(W.authorities||[],V9)+FY(W.additionals||[],V9)};Dd.streamEncode=function(W){let X=Dd.encode(W),G=Z1.alloc(2);G.writeUInt16BE(X.byteLength);let Y=Z1.concat([G,X]);return Dd.streamEncode.bytes=Y.byteLength,Y};Dd.streamEncode.bytes=0;Dd.streamDecode=function(W){let X=W.readUInt16BE(0);if(W.byteLength<X+2)return null;let G=Dd.decode(W.slice(2));return Dd.streamDecode.bytes=Dd.decode.bytes,G};Dd.streamDecode.bytes=0;function FY(W,X){let G=0;for(let Y=0;Y<W.length;Y++)G+=X.encodingLength(W[Y]);return G}function xV(W,X,G,Y){for(let J=0;J<W.length;J++)X.encode(W[J],G,Y),Y+=X.encode.bytes;return Y}function Fq(W,X,G,Y){for(let J=0;J<W.length;J++)W[J]=X.decode(G,Y),Y+=X.decode.bytes;return Y}});var l$=V1((vH0,c$)=>{var p$=_d;process.nextTick(kd,42);c$.exports=$d;function $d(W){var X=Y;return G;function G(J){X(J||Sd)}function Y(J){var Z=[J];X=V,W(U);function V(Q){Z.push(Q)}function U(Q){var N=arguments;X=Fd(Q)?Y:q;while(Z.length)q(Z.shift());function q(A){p$(xd,A,N)}}}}function Fd(W){return Object.prototype.toString.call(W)==="[object Error]"}function Sd(){}function xd(W,X){W.apply(null,X)}function kd(W){if(W===42)p$=process.nextTick}function _d(W,X,G){process.nextTick(function(){W(X,G)})}});var n$=V1((gH0,o$)=>{var JK=f$(),yd=_8("dgram"),vd=l$(),gd=_8("events"),VK=_8("os"),ZK=function(){};o$.exports=function(W){if(!W)W={};var X=new gd.EventEmitter,G=typeof W.port==="number"?W.port:5353,Y=W.type||"udp4",J=W.ip||W.host||(Y==="udp4"?"224.0.0.251":null),Z={address:J,port:G},V={},U=!1,Q=null;if(Y==="udp6"&&(!J||!W.interface))throw Error("For IPv6 multicast you must specify `ip` and `interface`");var N=W.socket||yd.createSocket({type:Y,reuseAddr:W.reuseAddr!==!1,toString:function(){return Y}});N.on("error",function(A){if(A.code==="EACCES"||A.code==="EADDRINUSE")X.emit("error",A);else X.emit("warning",A)}),N.on("message",function(A,H){try{A=JK.decode(A)}catch(I){X.emit("warning",I);return}if(X.emit("packet",A,H),A.type==="query")X.emit("query",A,H);if(A.type==="response")X.emit("response",A,H)}),N.on("listening",function(){if(!G)G=Z.port=N.address().port;if(W.multicast!==!1)X.update(),Q=setInterval(X.update,5000),N.setMulticastTTL(W.ttl||255),N.setMulticastLoopback(W.loopback!==!1)});var q=vd(function(A){if(!G||W.bind===!1)return A(null);N.once("error",A),N.bind(G,W.bind||W.interface,function(){N.removeListener("error",A),A(null)})});return q(function(A){if(A)return X.emit("error",A);X.emit("ready")}),X.send=function(A,H,I){if(typeof H==="function")return X.send(A,null,H);if(!I)I=ZK;if(!H)H=Z;else if(!H.host&&!H.address)H.address=Z.address;q(w);function w(O){if(U)return I();if(O)return I(O);var T=JK.encode(A);N.send(T,0,T.length,H.port,H.address||H.host,I)}},X.response=X.respond=function(A,H,I){if(Array.isArray(A))A={answers:A};A.type="response",A.flags=(A.flags||0)|JK.AUTHORITATIVE_ANSWER,X.send(A,H,I)},X.query=function(A,H,I,w){if(typeof H==="function")return X.query(A,null,null,H);if(typeof H==="object"&&H&&H.port)return X.query(A,null,H,I);if(typeof I==="function")return X.query(A,H,null,I);if(!w)w=ZK;if(typeof A==="string")A=[{name:A,type:H||"ANY"}];if(Array.isArray(A))A={type:"query",questions:A};A.type="query",X.send(A,I,w)},X.destroy=function(A){if(!A)A=ZK;if(U)return process.nextTick(A);U=!0,clearInterval(Q);for(var H in V)try{N.dropMembership(J,H)}catch(I){}V={},N.close(A)},X.update=function(){var A=W.interface?[].concat(W.interface):hd(),H=!1;for(var I=0;I<A.length;I++){var w=A[I];if(V[w])continue;try{N.addMembership(J,w),V[w]=!0,H=!0}catch(O){X.emit("warning",O)}}if(H){if(N.setMulticastInterface)try{N.setMulticastInterface(W.interface||ud())}catch(O){X.emit("warning",O)}X.emit("networkInterface")}},X};function ud(){var W=VK.networkInterfaces(),X=Object.keys(W);for(var G=0;G<X.length;G++){var Y=W[X[G]];for(var J=0;J<Y.length;J++){var Z=Y[J];if(d$(Z.family)&&!Z.internal){if(VK.platform()==="darwin"&&X[G]==="en0")return Z.address;return"0.0.0.0"}}}return"127.0.0.1"}function hd(){var W=VK.networkInterfaces(),X=Object.keys(W),G=[];for(var Y=0;Y<X.length;Y++){var J=W[X[Y]];for(var Z=0;Z<J.length;Z++){var V=J[Z];if(d$(V.family)){G.push(V.address);break}}}return G}function d$(W){return W===4||W==="IPv4"}});import{Database as kt}from"bun:sqlite";import{mkdirSync as _t}from"fs";import{dirname as yt}from"path";function wD(W){let X=W.length,G=0,Y=0;while(Y<X){let J=W.charCodeAt(Y++);if((J&4294967168)===0){G++;continue}else if((J&4294965248)===0)G+=2;else{if(J>=55296&&J<=56319){if(Y<X){let Z=W.charCodeAt(Y);if((Z&64512)===56320)++Y,J=((J&1023)<<10)+(Z&1023)+65536}}if((J&4294901760)===0)G+=3;else G+=4}}return G}function r_(W,X,G){let Y=W.length,J=G,Z=0;while(Z<Y){let V=W.charCodeAt(Z++);if((V&4294967168)===0){X[J++]=V;continue}else if((V&4294965248)===0)X[J++]=V>>6&31|192;else{if(V>=55296&&V<=56319){if(Z<Y){let U=W.charCodeAt(Z);if((U&64512)===56320)++Z,V=((V&1023)<<10)+(U&1023)+65536}}if((V&4294901760)===0)X[J++]=V>>12&15|224,X[J++]=V>>6&63|128;else X[J++]=V>>18&7|240,X[J++]=V>>12&63|128,X[J++]=V>>6&63|128}X[J++]=V&63|128}}var a_=new TextEncoder,s_=50;function t_(W,X,G){a_.encodeInto(W,X.subarray(G))}function jD(W,X,G){if(W.length>s_)t_(W,X,G);else r_(W,X,G)}var e_=4096;function IA(W,X,G){let Y=X,J=Y+G,Z=[],V="";while(Y<J){let U=W[Y++];if((U&128)===0)Z.push(U);else if((U&224)===192){let Q=W[Y++]&63;Z.push((U&31)<<6|Q)}else if((U&240)===224){let Q=W[Y++]&63,N=W[Y++]&63;Z.push((U&31)<<12|Q<<6|N)}else if((U&248)===240){let Q=W[Y++]&63,N=W[Y++]&63,q=W[Y++]&63,A=(U&7)<<18|Q<<12|N<<6|q;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>=e_)V+=String.fromCharCode(...Z),Z.length=0}if(Z.length>0)V+=String.fromCharCode(...Z);return V}var Wy=new TextDecoder,Xy=200;function Gy(W,X,G){let Y=W.subarray(X,X+G);return Wy.decode(Y)}function KD(W,X,G){if(G>Xy)return Gy(W,X,G);else return IA(W,X,G)}class dX{type;data;constructor(W,X){this.type=W,this.data=X}}class x9 extends Error{constructor(W){super(W);let X=Object.create(x9.prototype);Object.setPrototypeOf(this,X),Object.defineProperty(this,"name",{configurable:!0,enumerable:!1,value:x9.name})}}var oX=4294967295;function OD(W,X,G){let Y=G/4294967296,J=G;W.setUint32(X,Y),W.setUint32(X+4,J)}function gU(W,X,G){let Y=Math.floor(G/4294967296),J=G;W.setUint32(X,Y),W.setUint32(X+4,J)}function uU(W,X){let G=W.getInt32(X),Y=W.getUint32(X+4);return G*4294967296+Y}function DD(W,X){let G=W.getUint32(X),Y=W.getUint32(X+4);return G*4294967296+Y}var Yy=-1,Jy=4294967295,Zy=17179869183;function Vy({sec:W,nsec:X}){if(W>=0&&X>=0&&W<=Zy)if(X===0&&W<=Jy){let G=new Uint8Array(4);return new DataView(G.buffer).setUint32(0,W),G}else{let G=W/4294967296,Y=W&4294967295,J=new Uint8Array(8),Z=new DataView(J.buffer);return Z.setUint32(0,X<<2|G&3),Z.setUint32(4,Y),J}else{let G=new Uint8Array(12),Y=new DataView(G.buffer);return Y.setUint32(0,X),gU(Y,4,W),G}}function Uy(W){let X=W.getTime(),G=Math.floor(X/1000),Y=(X-G*1000)*1e6,J=Math.floor(Y/1e9);return{sec:G+J,nsec:Y-J*1e9}}function Qy(W){if(W instanceof Date){let X=Uy(W);return Vy(X)}else return null}function Ny(W){let X=new DataView(W.buffer,W.byteOffset,W.byteLength);switch(W.byteLength){case 4:{let G=X.getUint32(0),Y=0;return{sec:G,nsec:0}}case 8:{let G=X.getUint32(0),Y=X.getUint32(4),J=(G&3)*4294967296+Y,Z=G>>>2;return{sec:J,nsec:Z}}case 12:{let G=uU(X,4),Y=X.getUint32(0);return{sec:G,nsec:Y}}default:throw new x9(`Unrecognized data size for timestamp (expected 4, 8, or 12): ${W.length}`)}}function qy(W){let X=Ny(W);return new Date(X.sec*1000+X.nsec/1e6)}var CD={type:Yy,encode:Qy,decode:qy};class nX{static defaultCodec=new nX;__brand;builtInEncoders=[];builtInDecoders=[];encoders=[];decoders=[];constructor(){this.register(CD)}register({type:W,encode:X,decode:G}){if(W>=0)this.encoders[W]=X,this.decoders[W]=G;else{let Y=-1-W;this.builtInEncoders[Y]=X,this.builtInDecoders[Y]=G}}tryToEncode(W,X){for(let G=0;G<this.builtInEncoders.length;G++){let Y=this.builtInEncoders[G];if(Y!=null){let J=Y(W,X);if(J!=null){let Z=-1-G;return new dX(Z,J)}}}for(let G=0;G<this.encoders.length;G++){let Y=this.encoders[G];if(Y!=null){let J=Y(W,X);if(J!=null)return new dX(G,J)}}if(W instanceof dX)return W;return null}decode(W,X,G){let Y=X<0?this.builtInDecoders[-1-X]:this.decoders[X];if(Y)return Y(W,X,G);else return new dX(X,W)}}function Hy(W){return W instanceof ArrayBuffer||typeof SharedArrayBuffer<"u"&&W instanceof SharedArrayBuffer}function NJ(W){if(W instanceof Uint8Array)return W;else if(ArrayBuffer.isView(W))return new Uint8Array(W.buffer,W.byteOffset,W.byteLength);else if(Hy(W))return new Uint8Array(W);else return Uint8Array.from(W)}var Ay=100,zy=2048;class hU{extensionCodec;context;useBigInt64;maxDepth;initialBufferSize;sortKeys;forceFloat32;ignoreUndefined;forceIntegerToFloat;pos;view;bytes;entered=!1;constructor(W){this.extensionCodec=W?.extensionCodec??nX.defaultCodec,this.context=W?.context,this.useBigInt64=W?.useBigInt64??!1,this.maxDepth=W?.maxDepth??Ay,this.initialBufferSize=W?.initialBufferSize??zy,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 hU({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,X){if(X>this.maxDepth)throw Error(`Too deep objects in depth ${X}`);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,X)}ensureBufferSizeToWrite(W){let X=this.pos+W;if(this.view.byteLength<X)this.resizeBuffer(X*2)}resizeBuffer(W){let X=new ArrayBuffer(W),G=new Uint8Array(X),Y=new DataView(X);G.set(this.bytes),this.view=Y,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=wD(W);this.ensureBufferSizeToWrite(5+G),this.writeStringHeader(G),jD(W,this.bytes,this.pos),this.pos+=G}encodeObject(W,X){let G=this.extensionCodec.tryToEncode(W,this.context);if(G!=null)this.encodeExtension(G);else if(Array.isArray(W))this.encodeArray(W,X);else if(ArrayBuffer.isView(W))this.encodeBinary(W);else if(typeof W==="object")this.encodeMap(W,X);else throw Error(`Unrecognized object: ${Object.prototype.toString.apply(W)}`)}encodeBinary(W){let X=W.byteLength;if(X<256)this.writeU8(196),this.writeU8(X);else if(X<65536)this.writeU8(197),this.writeU16(X);else if(X<4294967296)this.writeU8(198),this.writeU32(X);else throw Error(`Too large binary: ${X}`);let G=NJ(W);this.writeU8a(G)}encodeArray(W,X){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 Y of W)this.doEncode(Y,X+1)}countWithoutUndefined(W,X){let G=0;for(let Y of X)if(W[Y]!==void 0)G++;return G}encodeMap(W,X){let G=Object.keys(W);if(this.sortKeys)G.sort();let Y=this.ignoreUndefined?this.countWithoutUndefined(W,G):G.length;if(Y<16)this.writeU8(128+Y);else if(Y<65536)this.writeU8(222),this.writeU16(Y);else if(Y<4294967296)this.writeU8(223),this.writeU32(Y);else throw Error(`Too large map object: ${Y}`);for(let J of G){let Z=W[J];if(!(this.ignoreUndefined&&Z===void 0))this.encodeString(J),this.doEncode(Z,X+1)}}encodeExtension(W){if(typeof W.data==="function"){let G=W.data(this.pos+6),Y=G.length;if(Y>=4294967296)throw Error(`Too large extension object: ${Y}`);this.writeU8(201),this.writeU32(Y),this.writeI8(W.type),this.writeU8a(G);return}let X=W.data.length;if(X===1)this.writeU8(212);else if(X===2)this.writeU8(213);else if(X===4)this.writeU8(214);else if(X===8)this.writeU8(215);else if(X===16)this.writeU8(216);else if(X<256)this.writeU8(199),this.writeU8(X);else if(X<65536)this.writeU8(200),this.writeU16(X);else if(X<4294967296)this.writeU8(201),this.writeU32(X);else throw Error(`Too large extension object: ${X}`);this.writeI8(W.type),this.writeU8a(W.data)}writeU8(W){this.ensureBufferSizeToWrite(1),this.view.setUint8(this.pos,W),this.pos++}writeU8a(W){let X=W.length;this.ensureBufferSizeToWrite(X),this.bytes.set(W,this.pos),this.pos+=X}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),OD(this.view,this.pos,W),this.pos+=8}writeI64(W){this.ensureBufferSizeToWrite(8),gU(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 bU(W,X){return new hU(X).encodeSharedRef(W)}function mU(W){return`${W<0?"-":""}0x${Math.abs(W).toString(16).padStart(2,"0")}`}var Iy=16,wy=16;class wA{hit=0;miss=0;caches;maxKeyLength;maxLengthPerKey;constructor(W=Iy,X=wy){this.maxKeyLength=W,this.maxLengthPerKey=X,this.caches=[];for(let G=0;G<this.maxKeyLength;G++)this.caches.push([])}canBeCached(W){return W>0&&W<=this.maxKeyLength}find(W,X,G){let Y=this.caches[G-1];W:for(let J of Y){let Z=J.bytes;for(let V=0;V<G;V++)if(Z[V]!==W[X+V])continue W;return J.str}return null}store(W,X){let G=this.caches[W.length-1],Y={bytes:W,str:X};if(G.length>=this.maxLengthPerKey)G[Math.random()*G.length|0]=Y;else G.push(Y)}decode(W,X,G){let Y=this.find(W,X,G);if(Y!=null)return this.hit++,Y;this.miss++;let J=IA(W,X,G),Z=Uint8Array.prototype.slice.call(W,X,X+G);return this.store(Z,J),J}}var jA="array",HJ="map_key",MD="map_value",jy=(W)=>{if(typeof W==="string"||typeof W==="number")return W;throw new x9("The type of key must be string or number but "+typeof W)};class PD{stack=[];stackHeadPosition=-1;get length(){return this.stackHeadPosition+1}top(){return this.stack[this.stackHeadPosition]}pushArrayState(W){let X=this.getUninitializedStateFromPool();X.type=jA,X.position=0,X.size=W,X.array=Array(W)}pushMapState(W){let X=this.getUninitializedStateFromPool();X.type=HJ,X.readCount=0,X.size=W,X.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===jA){let G=W;G.size=0,G.array=void 0,G.position=0,G.type=void 0}if(W.type===HJ||W.type===MD){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,KA=new DataView(new ArrayBuffer(0)),Ky=new Uint8Array(KA.buffer);try{KA.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 TD=RangeError("Insufficient data"),Oy=new wA;class fU{extensionCodec;context;useBigInt64;rawStrings;maxStrLength;maxBinLength;maxArrayLength;maxMapLength;maxExtLength;keyDecoder;mapKeyConverter;totalPos=0;pos=0;view=KA;bytes=Ky;headByte=qJ;stack=new PD;entered=!1;constructor(W){this.extensionCodec=W?.extensionCodec??nX.defaultCodec,this.context=W?.context,this.useBigInt64=W?.useBigInt64??!1,this.rawStrings=W?.rawStrings??!1,this.maxStrLength=W?.maxStrLength??oX,this.maxBinLength=W?.maxBinLength??oX,this.maxArrayLength=W?.maxArrayLength??oX,this.maxMapLength=W?.maxMapLength??oX,this.maxExtLength=W?.maxExtLength??oX,this.keyDecoder=W?.keyDecoder!==void 0?W.keyDecoder:Oy,this.mapKeyConverter=W?.mapKeyConverter??jy}clone(){return new fU({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 X=NJ(W);this.bytes=X,this.view=new DataView(X.buffer,X.byteOffset,X.byteLength),this.pos=0}appendBuffer(W){if(this.headByte===qJ&&!this.hasRemaining(1))this.setBuffer(W);else{let X=this.bytes.subarray(this.pos),G=NJ(W),Y=new Uint8Array(X.length+G.length);Y.set(X),Y.set(G,X.length),this.setBuffer(Y)}}hasRemaining(W){return this.view.byteLength-this.pos>=W}createExtraByteError(W){let{view:X,pos:G}=this;return RangeError(`Extra ${X.byteLength-G} of ${X.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 X=this.doDecodeSync();if(this.hasRemaining(1))throw this.createExtraByteError(this.pos);return X}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 X=!1,G;for await(let V of W){if(X)throw this.entered=!1,this.createExtraByteError(this.totalPos);this.appendBuffer(V);try{G=this.doDecodeSync(),X=!0}catch(U){if(!(U instanceof RangeError))throw U}this.totalPos+=this.pos}if(X){if(this.hasRemaining(1))throw this.createExtraByteError(this.totalPos);return G}let{headByte:Y,pos:J,totalPos:Z}=this;throw RangeError(`Insufficient data in parsing ${mU(Y)} 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,X){if(this.entered){yield*this.clone().decodeMultiAsync(W,X);return}try{this.entered=!0;let G=X,Y=-1;for await(let J of W){if(X&&Y===0)throw this.createExtraByteError(this.totalPos);if(this.appendBuffer(J),G)Y=this.readArraySize(),G=!1,this.complete();try{while(!0)if(yield this.doDecodeSync(),--Y===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(),X;if(W>=224)X=W-256;else if(W<192)if(W<128)X=W;else if(W<144){let Y=W-128;if(Y!==0){this.pushMapState(Y),this.complete();continue W}else X={}}else if(W<160){let Y=W-144;if(Y!==0){this.pushArrayState(Y),this.complete();continue W}else X=[]}else{let Y=W-160;X=this.decodeString(Y,0)}else if(W===192)X=null;else if(W===194)X=!1;else if(W===195)X=!0;else if(W===202)X=this.readF32();else if(W===203)X=this.readF64();else if(W===204)X=this.readU8();else if(W===205)X=this.readU16();else if(W===206)X=this.readU32();else if(W===207)if(this.useBigInt64)X=this.readU64AsBigInt();else X=this.readU64();else if(W===208)X=this.readI8();else if(W===209)X=this.readI16();else if(W===210)X=this.readI32();else if(W===211)if(this.useBigInt64)X=this.readI64AsBigInt();else X=this.readI64();else if(W===217){let Y=this.lookU8();X=this.decodeString(Y,1)}else if(W===218){let Y=this.lookU16();X=this.decodeString(Y,2)}else if(W===219){let Y=this.lookU32();X=this.decodeString(Y,4)}else if(W===220){let Y=this.readU16();if(Y!==0){this.pushArrayState(Y),this.complete();continue W}else X=[]}else if(W===221){let Y=this.readU32();if(Y!==0){this.pushArrayState(Y),this.complete();continue W}else X=[]}else if(W===222){let Y=this.readU16();if(Y!==0){this.pushMapState(Y),this.complete();continue W}else X={}}else if(W===223){let Y=this.readU32();if(Y!==0){this.pushMapState(Y),this.complete();continue W}else X={}}else if(W===196){let Y=this.lookU8();X=this.decodeBinary(Y,1)}else if(W===197){let Y=this.lookU16();X=this.decodeBinary(Y,2)}else if(W===198){let Y=this.lookU32();X=this.decodeBinary(Y,4)}else if(W===212)X=this.decodeExtension(1,0);else if(W===213)X=this.decodeExtension(2,0);else if(W===214)X=this.decodeExtension(4,0);else if(W===215)X=this.decodeExtension(8,0);else if(W===216)X=this.decodeExtension(16,0);else if(W===199){let Y=this.lookU8();X=this.decodeExtension(Y,1)}else if(W===200){let Y=this.lookU16();X=this.decodeExtension(Y,2)}else if(W===201){let Y=this.lookU32();X=this.decodeExtension(Y,4)}else throw new x9(`Unrecognized type byte: ${mU(W)}`);this.complete();let G=this.stack;while(G.length>0){let Y=G.top();if(Y.type===jA)if(Y.array[Y.position]=X,Y.position++,Y.position===Y.size)X=Y.array,G.release(Y);else continue W;else if(Y.type===HJ){if(X==="__proto__")throw new x9("The key __proto__ is not allowed");Y.key=this.mapKeyConverter(X),Y.type=MD;continue W}else if(Y.map[Y.key]=X,Y.readCount++,Y.readCount===Y.size)X=Y.map,G.release(Y);else{Y.key=null,Y.type=HJ;continue W}}return X}}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 x9(`Unrecognized array type byte: ${mU(W)}`)}}pushMapState(W){if(W>this.maxMapLength)throw new x9(`Max length exceeded: map length (${W}) > maxMapLengthLength (${this.maxMapLength})`);this.stack.pushMapState(W)}pushArrayState(W){if(W>this.maxArrayLength)throw new x9(`Max length exceeded: array length (${W}) > maxArrayLength (${this.maxArrayLength})`);this.stack.pushArrayState(W)}decodeString(W,X){if(!this.rawStrings||this.stateIsMapKey())return this.decodeUtf8String(W,X);return this.decodeBinary(W,X)}decodeUtf8String(W,X){if(W>this.maxStrLength)throw new x9(`Max length exceeded: UTF-8 byte length (${W}) > maxStrLength (${this.maxStrLength})`);if(this.bytes.byteLength<this.pos+X+W)throw TD;let G=this.pos+X,Y;if(this.stateIsMapKey()&&this.keyDecoder?.canBeCached(W))Y=this.keyDecoder.decode(this.bytes,G,W);else Y=KD(this.bytes,G,W);return this.pos+=X+W,Y}stateIsMapKey(){if(this.stack.length>0)return this.stack.top().type===HJ;return!1}decodeBinary(W,X){if(W>this.maxBinLength)throw new x9(`Max length exceeded: bin length (${W}) > maxBinLength (${this.maxBinLength})`);if(!this.hasRemaining(W+X))throw TD;let G=this.pos+X,Y=this.bytes.subarray(G,G+W);return this.pos+=X+W,Y}decodeExtension(W,X){if(W>this.maxExtLength)throw new x9(`Max length exceeded: ext length (${W}) > maxExtLength (${this.maxExtLength})`);let G=this.view.getInt8(this.pos+X),Y=this.decodeBinary(W,X+1);return this.extensionCodec.decode(Y,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=DD(this.view,this.pos);return this.pos+=8,W}readI64(){let W=uU(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 zW(W,X){return new fU(X).decode(W)}/*! pako 2.1.0 https://github.com/nodeca/pako @license (MIT AND Zlib) */function eX(W){let X=W.length;while(--X>=0)W[X]=0}var Dy=0,QC=1,Cy=2,Ty=3,My=258,fA=29,BJ=256,OJ=BJ+1+fA,aX=30,pA=19,NC=2*OJ+1,IW=15,OA=16,Py=7,cA=256,qC=16,HC=17,AC=18,kA=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]),nU=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]),Ry=new Uint8Array([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7]),zC=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),Ly=512,W4=Array((OJ+2)*2);eX(W4);var wJ=Array(aX*2);eX(wJ);var DJ=Array(Ly);eX(DJ);var CJ=Array(My-Ty+1);eX(CJ);var lA=Array(fA);eX(lA);var iU=Array(aX);eX(iU);function DA(W,X,G,Y,J){this.static_tree=W,this.extra_bits=X,this.extra_base=G,this.elems=Y,this.max_length=J,this.has_stree=W&&W.length}var IC,wC,jC;function CA(W,X){this.dyn_tree=W,this.max_code=0,this.stat_desc=X}var KC=(W)=>{return W<256?DJ[W]:DJ[256+(W>>>7)]},TJ=(W,X)=>{W.pending_buf[W.pending++]=X&255,W.pending_buf[W.pending++]=X>>>8&255},m9=(W,X,G)=>{if(W.bi_valid>OA-G)W.bi_buf|=X<<W.bi_valid&65535,TJ(W,W.bi_buf),W.bi_buf=X>>OA-W.bi_valid,W.bi_valid+=G-OA;else W.bi_buf|=X<<W.bi_valid&65535,W.bi_valid+=G},A7=(W,X,G)=>{m9(W,G[X*2],G[X*2+1])},OC=(W,X)=>{let G=0;do G|=W&1,W>>>=1,G<<=1;while(--X>0);return G>>>1},By=(W)=>{if(W.bi_valid===16)TJ(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},Ey=(W,X)=>{let{dyn_tree:G,max_code:Y}=X,J=X.stat_desc.static_tree,Z=X.stat_desc.has_stree,V=X.stat_desc.extra_bits,U=X.stat_desc.extra_base,Q=X.stat_desc.max_length,N,q,A,H,I,w,O=0;for(H=0;H<=IW;H++)W.bl_count[H]=0;G[W.heap[W.heap_max]*2+1]=0;for(N=W.heap_max+1;N<NC;N++){if(q=W.heap[N],H=G[G[q*2+1]*2+1]+1,H>Q)H=Q,O++;if(G[q*2+1]=H,q>Y)continue;if(W.bl_count[H]++,I=0,q>=U)I=V[q-U];if(w=G[q*2],W.opt_len+=w*(H+I),Z)W.static_len+=w*(J[q*2+1]+I)}if(O===0)return;do{H=Q-1;while(W.bl_count[H]===0)H--;W.bl_count[H]--,W.bl_count[H+1]+=2,W.bl_count[Q]--,O-=2}while(O>0);for(H=Q;H!==0;H--){q=W.bl_count[H];while(q!==0){if(A=W.heap[--N],A>Y)continue;if(G[A*2+1]!==H)W.opt_len+=(H-G[A*2+1])*G[A*2],G[A*2+1]=H;q--}}},DC=(W,X,G)=>{let Y=Array(IW+1),J=0,Z,V;for(Z=1;Z<=IW;Z++)J=J+G[Z-1]<<1,Y[Z]=J;for(V=0;V<=X;V++){let U=W[V*2+1];if(U===0)continue;W[V*2]=OC(Y[U]++,U)}},$y=()=>{let W,X,G,Y,J,Z=Array(IW+1);G=0;for(Y=0;Y<fA-1;Y++){lA[Y]=G;for(W=0;W<1<<kA[Y];W++)CJ[G++]=Y}CJ[G-1]=Y,J=0;for(Y=0;Y<16;Y++){iU[Y]=J;for(W=0;W<1<<nU[Y];W++)DJ[J++]=Y}J>>=7;for(;Y<aX;Y++){iU[Y]=J<<7;for(W=0;W<1<<nU[Y]-7;W++)DJ[256+J++]=Y}for(X=0;X<=IW;X++)Z[X]=0;W=0;while(W<=143)W4[W*2+1]=8,W++,Z[8]++;while(W<=255)W4[W*2+1]=9,W++,Z[9]++;while(W<=279)W4[W*2+1]=7,W++,Z[7]++;while(W<=287)W4[W*2+1]=8,W++,Z[8]++;DC(W4,OJ+1,Z);for(W=0;W<aX;W++)wJ[W*2+1]=5,wJ[W*2]=OC(W,5);IC=new DA(W4,kA,BJ+1,OJ,IW),wC=new DA(wJ,nU,0,aX,IW),jC=new DA([],Ry,0,pA,Py)},CC=(W)=>{let X;for(X=0;X<OJ;X++)W.dyn_ltree[X*2]=0;for(X=0;X<aX;X++)W.dyn_dtree[X*2]=0;for(X=0;X<pA;X++)W.bl_tree[X*2]=0;W.dyn_ltree[cA*2]=1,W.opt_len=W.static_len=0,W.sym_next=W.matches=0},TC=(W)=>{if(W.bi_valid>8)TJ(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},RD=(W,X,G,Y)=>{let J=X*2,Z=G*2;return W[J]<W[Z]||W[J]===W[Z]&&Y[X]<=Y[G]},TA=(W,X,G)=>{let Y=W.heap[G],J=G<<1;while(J<=W.heap_len){if(J<W.heap_len&&RD(X,W.heap[J+1],W.heap[J],W.depth))J++;if(RD(X,Y,W.heap[J],W.depth))break;W.heap[G]=W.heap[J],G=J,J<<=1}W.heap[G]=Y},LD=(W,X,G)=>{let Y,J,Z=0,V,U;if(W.sym_next!==0)do if(Y=W.pending_buf[W.sym_buf+Z++]&255,Y+=(W.pending_buf[W.sym_buf+Z++]&255)<<8,J=W.pending_buf[W.sym_buf+Z++],Y===0)A7(W,J,X);else{if(V=CJ[J],A7(W,V+BJ+1,X),U=kA[V],U!==0)J-=lA[V],m9(W,J,U);if(Y--,V=KC(Y),A7(W,V,G),U=nU[V],U!==0)Y-=iU[V],m9(W,Y,U)}while(Z<W.sym_next);A7(W,cA,X)},_A=(W,X)=>{let G=X.dyn_tree,Y=X.stat_desc.static_tree,J=X.stat_desc.has_stree,Z=X.stat_desc.elems,V,U,Q=-1,N;W.heap_len=0,W.heap_max=NC;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(N=W.heap[++W.heap_len]=Q<2?++Q:0,G[N*2]=1,W.depth[N]=0,W.opt_len--,J)W.static_len-=Y[N*2+1];X.max_code=Q;for(V=W.heap_len>>1;V>=1;V--)TA(W,G,V);N=Z;do V=W.heap[1],W.heap[1]=W.heap[W.heap_len--],TA(W,G,1),U=W.heap[1],W.heap[--W.heap_max]=V,W.heap[--W.heap_max]=U,G[N*2]=G[V*2]+G[U*2],W.depth[N]=(W.depth[V]>=W.depth[U]?W.depth[V]:W.depth[U])+1,G[V*2+1]=G[U*2+1]=N,W.heap[1]=N++,TA(W,G,1);while(W.heap_len>=2);W.heap[--W.heap_max]=W.heap[1],Ey(W,X),DC(G,Q,W.bl_count)},BD=(W,X,G)=>{let Y,J=-1,Z,V=X[1],U=0,Q=7,N=4;if(V===0)Q=138,N=3;X[(G+1)*2+1]=65535;for(Y=0;Y<=G;Y++){if(Z=V,V=X[(Y+1)*2+1],++U<Q&&Z===V)continue;else if(U<N)W.bl_tree[Z*2]+=U;else if(Z!==0){if(Z!==J)W.bl_tree[Z*2]++;W.bl_tree[qC*2]++}else if(U<=10)W.bl_tree[HC*2]++;else W.bl_tree[AC*2]++;if(U=0,J=Z,V===0)Q=138,N=3;else if(Z===V)Q=6,N=3;else Q=7,N=4}},ED=(W,X,G)=>{let Y,J=-1,Z,V=X[1],U=0,Q=7,N=4;if(V===0)Q=138,N=3;for(Y=0;Y<=G;Y++){if(Z=V,V=X[(Y+1)*2+1],++U<Q&&Z===V)continue;else if(U<N)do A7(W,Z,W.bl_tree);while(--U!==0);else if(Z!==0){if(Z!==J)A7(W,Z,W.bl_tree),U--;A7(W,qC,W.bl_tree),m9(W,U-3,2)}else if(U<=10)A7(W,HC,W.bl_tree),m9(W,U-3,3);else A7(W,AC,W.bl_tree),m9(W,U-11,7);if(U=0,J=Z,V===0)Q=138,N=3;else if(Z===V)Q=6,N=3;else Q=7,N=4}},Fy=(W)=>{let X;BD(W,W.dyn_ltree,W.l_desc.max_code),BD(W,W.dyn_dtree,W.d_desc.max_code),_A(W,W.bl_desc);for(X=pA-1;X>=3;X--)if(W.bl_tree[zC[X]*2+1]!==0)break;return W.opt_len+=3*(X+1)+5+5+4,X},Sy=(W,X,G,Y)=>{let J;m9(W,X-257,5),m9(W,G-1,5),m9(W,Y-4,4);for(J=0;J<Y;J++)m9(W,W.bl_tree[zC[J]*2+1],3);ED(W,W.dyn_ltree,X-1),ED(W,W.dyn_dtree,G-1)},xy=(W)=>{let X=4093624447,G;for(G=0;G<=31;G++,X>>>=1)if(X&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<BJ;G++)if(W.dyn_ltree[G*2]!==0)return 1;return 0},$D=!1,ky=(W)=>{if(!$D)$y(),$D=!0;W.l_desc=new CA(W.dyn_ltree,IC),W.d_desc=new CA(W.dyn_dtree,wC),W.bl_desc=new CA(W.bl_tree,jC),W.bi_buf=0,W.bi_valid=0,CC(W)},MC=(W,X,G,Y)=>{if(m9(W,(Dy<<1)+(Y?1:0),3),TC(W),TJ(W,G),TJ(W,~G),G)W.pending_buf.set(W.window.subarray(X,X+G),W.pending);W.pending+=G},_y=(W)=>{m9(W,QC<<1,3),A7(W,cA,W4),By(W)},yy=(W,X,G,Y)=>{let J,Z,V=0;if(W.level>0){if(W.strm.data_type===2)W.strm.data_type=xy(W);if(_A(W,W.l_desc),_A(W,W.d_desc),V=Fy(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&&X!==-1)MC(W,X,G,Y);else if(W.strategy===4||Z===J)m9(W,(QC<<1)+(Y?1:0),3),LD(W,W4,wJ);else m9(W,(Cy<<1)+(Y?1:0),3),Sy(W,W.l_desc.max_code+1,W.d_desc.max_code+1,V+1),LD(W,W.dyn_ltree,W.dyn_dtree);if(CC(W),Y)TC(W)},vy=(W,X,G)=>{if(W.pending_buf[W.sym_buf+W.sym_next++]=X,W.pending_buf[W.sym_buf+W.sym_next++]=X>>8,W.pending_buf[W.sym_buf+W.sym_next++]=G,X===0)W.dyn_ltree[G*2]++;else W.matches++,X--,W.dyn_ltree[(CJ[G]+BJ+1)*2]++,W.dyn_dtree[KC(X)*2]++;return W.sym_next===W.sym_end},gy=ky,uy=MC,hy=yy,by=vy,my=_y,fy={_tr_init:gy,_tr_stored_block:uy,_tr_flush_block:hy,_tr_tally:by,_tr_align:my},py=(W,X,G,Y)=>{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+X[Y++]|0,Z=Z+J|0;while(--V);J%=65521,Z%=65521}return J|Z<<16|0},MJ=py,cy=()=>{let W,X=[];for(var G=0;G<256;G++){W=G;for(var Y=0;Y<8;Y++)W=W&1?3988292384^W>>>1:W>>>1;X[G]=W}return X},ly=new Uint32Array(cy()),dy=(W,X,G,Y)=>{let J=ly,Z=Y+G;W^=-1;for(let V=Y;V<Z;V++)W=W>>>8^J[(W^X[V])&255];return W^-1},r8=dy,KW={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"},CW={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:oy,_tr_stored_block:yA,_tr_flush_block:ny,_tr_tally:Q6,_tr_align:iy}=fy,{Z_NO_FLUSH:N6,Z_PARTIAL_FLUSH:ry,Z_FULL_FLUSH:ay,Z_FINISH:K5,Z_BLOCK:FD,Z_OK:W9,Z_STREAM_END:SD,Z_STREAM_ERROR:z7,Z_DATA_ERROR:sy,Z_BUF_ERROR:MA,Z_DEFAULT_COMPRESSION:ty,Z_FILTERED:ey,Z_HUFFMAN_ONLY:pU,Z_RLE:Wv,Z_FIXED:Xv,Z_DEFAULT_STRATEGY:Gv,Z_UNKNOWN:Yv,Z_DEFLATED:sU}=CW,Jv=9,Zv=15,Vv=8,Uv=29,Qv=256,vA=Qv+1+Uv,Nv=30,qv=19,Hv=2*vA+1,Av=15,m1=3,U6=258,I7=U6+m1+1,zv=32,sX=42,dA=57,gA=69,uA=73,hA=91,bA=103,wW=113,zJ=666,k9=1,WG=2,OW=3,XG=4,Iv=3,jW=(W,X)=>{return W.msg=KW[X],X},xD=(W)=>{return W*2-(W>4?9:0)},V6=(W)=>{let X=W.length;while(--X>=0)W[X]=0},wv=(W)=>{let X,G,Y,J=W.w_size;X=W.hash_size,Y=X;do G=W.head[--Y],W.head[Y]=G>=J?G-J:0;while(--X);X=J,Y=X;do G=W.prev[--Y],W.prev[Y]=G>=J?G-J:0;while(--X)},jv=(W,X,G)=>(X<<W.hash_shift^G)&W.hash_mask,q6=jv,G5=(W)=>{let X=W.state,G=X.pending;if(G>W.avail_out)G=W.avail_out;if(G===0)return;if(W.output.set(X.pending_buf.subarray(X.pending_out,X.pending_out+G),W.next_out),W.next_out+=G,X.pending_out+=G,W.total_out+=G,W.avail_out-=G,X.pending-=G,X.pending===0)X.pending_out=0},Y5=(W,X)=>{ny(W,W.block_start>=0?W.block_start:-1,W.strstart-W.block_start,X),W.block_start=W.strstart,G5(W.strm)},t1=(W,X)=>{W.pending_buf[W.pending++]=X},AJ=(W,X)=>{W.pending_buf[W.pending++]=X>>>8&255,W.pending_buf[W.pending++]=X&255},mA=(W,X,G,Y)=>{let J=W.avail_in;if(J>Y)J=Y;if(J===0)return 0;if(W.avail_in-=J,X.set(W.input.subarray(W.next_in,W.next_in+J),G),W.state.wrap===1)W.adler=MJ(W.adler,X,J,G);else if(W.state.wrap===2)W.adler=r8(W.adler,X,J,G);return W.next_in+=J,W.total_in+=J,J},PC=(W,X)=>{let{max_chain_length:G,strstart:Y}=W,J,Z,V=W.prev_length,U=W.nice_match,Q=W.strstart>W.w_size-I7?W.strstart-(W.w_size-I7):0,N=W.window,q=W.w_mask,A=W.prev,H=W.strstart+U6,I=N[Y+V-1],w=N[Y+V];if(W.prev_length>=W.good_match)G>>=2;if(U>W.lookahead)U=W.lookahead;do{if(J=X,N[J+V]!==w||N[J+V-1]!==I||N[J]!==N[Y]||N[++J]!==N[Y+1])continue;Y+=2,J++;do;while(N[++Y]===N[++J]&&N[++Y]===N[++J]&&N[++Y]===N[++J]&&N[++Y]===N[++J]&&N[++Y]===N[++J]&&N[++Y]===N[++J]&&N[++Y]===N[++J]&&N[++Y]===N[++J]&&Y<H);if(Z=U6-(H-Y),Y=H-U6,Z>V){if(W.match_start=X,V=Z,Z>=U)break;I=N[Y+V-1],w=N[Y+V]}}while((X=A[X&q])>Q&&--G!==0);if(V<=W.lookahead)return V;return W.lookahead},tX=(W)=>{let X=W.w_size,G,Y,J;do{if(Y=W.window_size-W.lookahead-W.strstart,W.strstart>=X+(X-I7)){if(W.window.set(W.window.subarray(X,X+X-Y),0),W.match_start-=X,W.strstart-=X,W.block_start-=X,W.insert>W.strstart)W.insert=W.strstart;wv(W),Y+=X}if(W.strm.avail_in===0)break;if(G=mA(W.strm,W.window,W.strstart+W.lookahead,Y),W.lookahead+=G,W.lookahead+W.insert>=m1){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+m1-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<m1)break}}while(W.lookahead<I7&&W.strm.avail_in!==0)},RC=(W,X)=>{let G=W.pending_buf_size-5>W.w_size?W.w_size:W.pending_buf_size-5,Y,J,Z,V=0,U=W.strm.avail_in;do{if(Y=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,Y>J+W.strm.avail_in)Y=J+W.strm.avail_in;if(Y>Z)Y=Z;if(Y<G&&(Y===0&&X!==K5||X===N6||Y!==J+W.strm.avail_in))break;if(V=X===K5&&Y===J+W.strm.avail_in?1:0,yA(W,0,0,V),W.pending_buf[W.pending-4]=Y,W.pending_buf[W.pending-3]=Y>>8,W.pending_buf[W.pending-2]=~Y,W.pending_buf[W.pending-1]=~Y>>8,G5(W.strm),J){if(J>Y)J=Y;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,Y-=J}if(Y)mA(W.strm,W.strm.output,W.strm.next_out,Y),W.strm.next_out+=Y,W.strm.avail_out-=Y,W.strm.total_out+=Y}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 XG;if(X!==N6&&X!==K5&&W.strm.avail_in===0&&W.strstart===W.block_start)return WG;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)mA(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||X===K5)&&X!==N6&&W.strm.avail_in===0&&J<=Z)Y=J>Z?Z:J,V=X===K5&&W.strm.avail_in===0&&Y===J?1:0,yA(W,W.block_start,Y,V),W.block_start+=Y,G5(W.strm);return V?OW:k9},PA=(W,X)=>{let G,Y;for(;;){if(W.lookahead<I7){if(tX(W),W.lookahead<I7&&X===N6)return k9;if(W.lookahead===0)break}if(G=0,W.lookahead>=m1)W.ins_h=q6(W,W.ins_h,W.window[W.strstart+m1-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-I7)W.match_length=PC(W,G);if(W.match_length>=m1)if(Y=Q6(W,W.strstart-W.match_start,W.match_length-m1),W.lookahead-=W.match_length,W.match_length<=W.max_lazy_match&&W.lookahead>=m1){W.match_length--;do W.strstart++,W.ins_h=q6(W,W.ins_h,W.window[W.strstart+m1-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 Y=Q6(W,0,W.window[W.strstart]),W.lookahead--,W.strstart++;if(Y){if(Y5(W,!1),W.strm.avail_out===0)return k9}}if(W.insert=W.strstart<m1-1?W.strstart:m1-1,X===K5){if(Y5(W,!0),W.strm.avail_out===0)return OW;return XG}if(W.sym_next){if(Y5(W,!1),W.strm.avail_out===0)return k9}return WG},iX=(W,X)=>{let G,Y,J;for(;;){if(W.lookahead<I7){if(tX(W),W.lookahead<I7&&X===N6)return k9;if(W.lookahead===0)break}if(G=0,W.lookahead>=m1)W.ins_h=q6(W,W.ins_h,W.window[W.strstart+m1-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=m1-1,G!==0&&W.prev_length<W.max_lazy_match&&W.strstart-G<=W.w_size-I7){if(W.match_length=PC(W,G),W.match_length<=5&&(W.strategy===ey||W.match_length===m1&&W.strstart-W.match_start>4096))W.match_length=m1-1}if(W.prev_length>=m1&&W.match_length<=W.prev_length){J=W.strstart+W.lookahead-m1,Y=Q6(W,W.strstart-1-W.prev_match,W.prev_length-m1),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+m1-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=m1-1,W.strstart++,Y){if(Y5(W,!1),W.strm.avail_out===0)return k9}}else if(W.match_available){if(Y=Q6(W,0,W.window[W.strstart-1]),Y)Y5(W,!1);if(W.strstart++,W.lookahead--,W.strm.avail_out===0)return k9}else W.match_available=1,W.strstart++,W.lookahead--}if(W.match_available)Y=Q6(W,0,W.window[W.strstart-1]),W.match_available=0;if(W.insert=W.strstart<m1-1?W.strstart:m1-1,X===K5){if(Y5(W,!0),W.strm.avail_out===0)return OW;return XG}if(W.sym_next){if(Y5(W,!1),W.strm.avail_out===0)return k9}return WG},Kv=(W,X)=>{let G,Y,J,Z,V=W.window;for(;;){if(W.lookahead<=U6){if(tX(W),W.lookahead<=U6&&X===N6)return k9;if(W.lookahead===0)break}if(W.match_length=0,W.lookahead>=m1&&W.strstart>0){if(J=W.strstart-1,Y=V[J],Y===V[++J]&&Y===V[++J]&&Y===V[++J]){Z=W.strstart+U6;do;while(Y===V[++J]&&Y===V[++J]&&Y===V[++J]&&Y===V[++J]&&Y===V[++J]&&Y===V[++J]&&Y===V[++J]&&Y===V[++J]&&J<Z);if(W.match_length=U6-(Z-J),W.match_length>W.lookahead)W.match_length=W.lookahead}}if(W.match_length>=m1)G=Q6(W,1,W.match_length-m1),W.lookahead-=W.match_length,W.strstart+=W.match_length,W.match_length=0;else G=Q6(W,0,W.window[W.strstart]),W.lookahead--,W.strstart++;if(G){if(Y5(W,!1),W.strm.avail_out===0)return k9}}if(W.insert=0,X===K5){if(Y5(W,!0),W.strm.avail_out===0)return OW;return XG}if(W.sym_next){if(Y5(W,!1),W.strm.avail_out===0)return k9}return WG},Ov=(W,X)=>{let G;for(;;){if(W.lookahead===0){if(tX(W),W.lookahead===0){if(X===N6)return k9;break}}if(W.match_length=0,G=Q6(W,0,W.window[W.strstart]),W.lookahead--,W.strstart++,G){if(Y5(W,!1),W.strm.avail_out===0)return k9}}if(W.insert=0,X===K5){if(Y5(W,!0),W.strm.avail_out===0)return OW;return XG}if(W.sym_next){if(Y5(W,!1),W.strm.avail_out===0)return k9}return WG};function H7(W,X,G,Y,J){this.good_length=W,this.max_lazy=X,this.nice_length=G,this.max_chain=Y,this.func=J}var IJ=[new H7(0,0,0,0,RC),new H7(4,4,8,4,PA),new H7(4,5,16,8,PA),new H7(4,6,32,32,PA),new H7(4,4,16,16,iX),new H7(8,16,32,32,iX),new H7(8,16,128,128,iX),new H7(8,32,128,256,iX),new H7(32,128,258,1024,iX),new H7(32,258,258,4096,iX)],Dv=(W)=>{W.window_size=2*W.w_size,V6(W.head),W.max_lazy_match=IJ[W.level].max_lazy,W.good_match=IJ[W.level].good_length,W.nice_match=IJ[W.level].nice_length,W.max_chain_length=IJ[W.level].max_chain,W.strstart=0,W.block_start=0,W.lookahead=0,W.insert=0,W.match_length=W.prev_length=m1-1,W.match_available=0,W.ins_h=0};function Cv(){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=sU,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(Hv*2),this.dyn_dtree=new Uint16Array((2*Nv+1)*2),this.bl_tree=new Uint16Array((2*qv+1)*2),V6(this.dyn_ltree),V6(this.dyn_dtree),V6(this.bl_tree),this.l_desc=null,this.d_desc=null,this.bl_desc=null,this.bl_count=new Uint16Array(Av+1),this.heap=new Uint16Array(2*vA+1),V6(this.heap),this.heap_len=0,this.heap_max=0,this.depth=new Uint16Array(2*vA+1),V6(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 EJ=(W)=>{if(!W)return 1;let X=W.state;if(!X||X.strm!==W||X.status!==sX&&X.status!==dA&&X.status!==gA&&X.status!==uA&&X.status!==hA&&X.status!==bA&&X.status!==wW&&X.status!==zJ)return 1;return 0},LC=(W)=>{if(EJ(W))return jW(W,z7);W.total_in=W.total_out=0,W.data_type=Yv;let X=W.state;if(X.pending=0,X.pending_out=0,X.wrap<0)X.wrap=-X.wrap;return X.status=X.wrap===2?dA:X.wrap?sX:wW,W.adler=X.wrap===2?0:1,X.last_flush=-2,oy(X),W9},BC=(W)=>{let X=LC(W);if(X===W9)Dv(W.state);return X},Tv=(W,X)=>{if(EJ(W)||W.state.wrap!==2)return z7;return W.state.gzhead=X,W9},EC=(W,X,G,Y,J,Z)=>{if(!W)return z7;let V=1;if(X===ty)X=6;if(Y<0)V=0,Y=-Y;else if(Y>15)V=2,Y-=16;if(J<1||J>Jv||G!==sU||Y<8||Y>15||X<0||X>9||Z<0||Z>Xv||Y===8&&V!==1)return jW(W,z7);if(Y===8)Y=9;let U=new Cv;return W.state=U,U.strm=W,U.status=sX,U.wrap=V,U.gzhead=null,U.w_bits=Y,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+m1-1)/m1),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=X,U.strategy=Z,U.method=G,BC(W)},Mv=(W,X)=>{return EC(W,X,sU,Zv,Vv,Gv)},Pv=(W,X)=>{if(EJ(W)||X>FD||X<0)return W?jW(W,z7):z7;let G=W.state;if(!W.output||W.avail_in!==0&&!W.input||G.status===zJ&&X!==K5)return jW(W,W.avail_out===0?MA:z7);let Y=G.last_flush;if(G.last_flush=X,G.pending!==0){if(G5(W),W.avail_out===0)return G.last_flush=-1,W9}else if(W.avail_in===0&&xD(X)<=xD(Y)&&X!==K5)return jW(W,MA);if(G.status===zJ&&W.avail_in!==0)return jW(W,MA);if(G.status===sX&&G.wrap===0)G.status=wW;if(G.status===sX){let J=sU+(G.w_bits-8<<4)<<8,Z=-1;if(G.strategy>=pU||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|=zv;if(J+=31-J%31,AJ(G,J),G.strstart!==0)AJ(G,W.adler>>>16),AJ(G,W.adler&65535);if(W.adler=1,G.status=wW,G5(W),G.pending!==0)return G.last_flush=-1,W9}if(G.status===dA)if(W.adler=0,t1(G,31),t1(G,139),t1(G,8),!G.gzhead){if(t1(G,0),t1(G,0),t1(G,0),t1(G,0),t1(G,0),t1(G,G.level===9?2:G.strategy>=pU||G.level<2?4:0),t1(G,Iv),G.status=wW,G5(W),G.pending!==0)return G.last_flush=-1,W9}else{if(t1(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)),t1(G,G.gzhead.time&255),t1(G,G.gzhead.time>>8&255),t1(G,G.gzhead.time>>16&255),t1(G,G.gzhead.time>>24&255),t1(G,G.level===9?2:G.strategy>=pU||G.level<2?4:0),t1(G,G.gzhead.os&255),G.gzhead.extra&&G.gzhead.extra.length)t1(G,G.gzhead.extra.length&255),t1(G,G.gzhead.extra.length>>8&255);if(G.gzhead.hcrc)W.adler=r8(W.adler,G.pending_buf,G.pending,0);G.gzindex=0,G.status=gA}if(G.status===gA){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=r8(W.adler,G.pending_buf,G.pending-J,J);if(G.gzindex+=U,G5(W),G.pending!==0)return G.last_flush=-1,W9;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=r8(W.adler,G.pending_buf,G.pending-J,J);G.gzindex=0}G.status=uA}if(G.status===uA){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=r8(W.adler,G.pending_buf,G.pending-J,J);if(G5(W),G.pending!==0)return G.last_flush=-1,W9;J=0}if(G.gzindex<G.gzhead.name.length)Z=G.gzhead.name.charCodeAt(G.gzindex++)&255;else Z=0;t1(G,Z)}while(Z!==0);if(G.gzhead.hcrc&&G.pending>J)W.adler=r8(W.adler,G.pending_buf,G.pending-J,J);G.gzindex=0}G.status=hA}if(G.status===hA){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=r8(W.adler,G.pending_buf,G.pending-J,J);if(G5(W),G.pending!==0)return G.last_flush=-1,W9;J=0}if(G.gzindex<G.gzhead.comment.length)Z=G.gzhead.comment.charCodeAt(G.gzindex++)&255;else Z=0;t1(G,Z)}while(Z!==0);if(G.gzhead.hcrc&&G.pending>J)W.adler=r8(W.adler,G.pending_buf,G.pending-J,J)}G.status=bA}if(G.status===bA){if(G.gzhead.hcrc){if(G.pending+2>G.pending_buf_size){if(G5(W),G.pending!==0)return G.last_flush=-1,W9}t1(G,W.adler&255),t1(G,W.adler>>8&255),W.adler=0}if(G.status=wW,G5(W),G.pending!==0)return G.last_flush=-1,W9}if(W.avail_in!==0||G.lookahead!==0||X!==N6&&G.status!==zJ){let J=G.level===0?RC(G,X):G.strategy===pU?Ov(G,X):G.strategy===Wv?Kv(G,X):IJ[G.level].func(G,X);if(J===OW||J===XG)G.status=zJ;if(J===k9||J===OW){if(W.avail_out===0)G.last_flush=-1;return W9}if(J===WG){if(X===ry)iy(G);else if(X!==FD){if(yA(G,0,0,!1),X===ay){if(V6(G.head),G.lookahead===0)G.strstart=0,G.block_start=0,G.insert=0}}if(G5(W),W.avail_out===0)return G.last_flush=-1,W9}}if(X!==K5)return W9;if(G.wrap<=0)return SD;if(G.wrap===2)t1(G,W.adler&255),t1(G,W.adler>>8&255),t1(G,W.adler>>16&255),t1(G,W.adler>>24&255),t1(G,W.total_in&255),t1(G,W.total_in>>8&255),t1(G,W.total_in>>16&255),t1(G,W.total_in>>24&255);else AJ(G,W.adler>>>16),AJ(G,W.adler&65535);if(G5(W),G.wrap>0)G.wrap=-G.wrap;return G.pending!==0?W9:SD},Rv=(W)=>{if(EJ(W))return z7;let X=W.state.status;return W.state=null,X===wW?jW(W,sy):W9},Lv=(W,X)=>{let G=X.length;if(EJ(W))return z7;let Y=W.state,J=Y.wrap;if(J===2||J===1&&Y.status!==sX||Y.lookahead)return z7;if(J===1)W.adler=MJ(W.adler,X,G,0);if(Y.wrap=0,G>=Y.w_size){if(J===0)V6(Y.head),Y.strstart=0,Y.block_start=0,Y.insert=0;let Q=new Uint8Array(Y.w_size);Q.set(X.subarray(G-Y.w_size,G),0),X=Q,G=Y.w_size}let{avail_in:Z,next_in:V,input:U}=W;W.avail_in=G,W.next_in=0,W.input=X,tX(Y);while(Y.lookahead>=m1){let Q=Y.strstart,N=Y.lookahead-(m1-1);do Y.ins_h=q6(Y,Y.ins_h,Y.window[Q+m1-1]),Y.prev[Q&Y.w_mask]=Y.head[Y.ins_h],Y.head[Y.ins_h]=Q,Q++;while(--N);Y.strstart=Q,Y.lookahead=m1-1,tX(Y)}return Y.strstart+=Y.lookahead,Y.block_start=Y.strstart,Y.insert=Y.lookahead,Y.lookahead=0,Y.match_length=Y.prev_length=m1-1,Y.match_available=0,W.next_in=V,W.input=U,W.avail_in=Z,Y.wrap=J,W9},Bv=Mv,Ev=EC,$v=BC,Fv=LC,Sv=Tv,xv=Pv,kv=Rv,_v=Lv,yv="pako deflate (from Nodeca project)",jJ={deflateInit:Bv,deflateInit2:Ev,deflateReset:$v,deflateResetKeep:Fv,deflateSetHeader:Sv,deflate:xv,deflateEnd:kv,deflateSetDictionary:_v,deflateInfo:yv},vv=(W,X)=>{return Object.prototype.hasOwnProperty.call(W,X)},gv=function(W){let X=Array.prototype.slice.call(arguments,1);while(X.length){let G=X.shift();if(!G)continue;if(typeof G!=="object")throw TypeError(G+"must be non-object");for(let Y in G)if(vv(G,Y))W[Y]=G[Y]}return W},uv=(W)=>{let X=0;for(let Y=0,J=W.length;Y<J;Y++)X+=W[Y].length;let G=new Uint8Array(X);for(let Y=0,J=0,Z=W.length;Y<Z;Y++){let V=W[Y];G.set(V,J),J+=V.length}return G},tU={assign:gv,flattenChunks:uv},$C=!0;try{String.fromCharCode.apply(null,new Uint8Array(1))}catch(W){$C=!1}var PJ=new Uint8Array(256);for(let W=0;W<256;W++)PJ[W]=W>=252?6:W>=248?5:W>=240?4:W>=224?3:W>=192?2:1;PJ[254]=PJ[254]=1;var hv=(W)=>{if(typeof TextEncoder==="function"&&TextEncoder.prototype.encode)return new TextEncoder().encode(W);let X,G,Y,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(Y=W.charCodeAt(J+1),(Y&64512)===56320)G=65536+(G-55296<<10)+(Y-56320),J++}U+=G<128?1:G<2048?2:G<65536?3:4}X=new Uint8Array(U);for(Z=0,J=0;Z<U;J++){if(G=W.charCodeAt(J),(G&64512)===55296&&J+1<V){if(Y=W.charCodeAt(J+1),(Y&64512)===56320)G=65536+(G-55296<<10)+(Y-56320),J++}if(G<128)X[Z++]=G;else if(G<2048)X[Z++]=192|G>>>6,X[Z++]=128|G&63;else if(G<65536)X[Z++]=224|G>>>12,X[Z++]=128|G>>>6&63,X[Z++]=128|G&63;else X[Z++]=240|G>>>18,X[Z++]=128|G>>>12&63,X[Z++]=128|G>>>6&63,X[Z++]=128|G&63}return X},bv=(W,X)=>{if(X<65534){if(W.subarray&&$C)return String.fromCharCode.apply(null,W.length===X?W:W.subarray(0,X))}let G="";for(let Y=0;Y<X;Y++)G+=String.fromCharCode(W[Y]);return G},mv=(W,X)=>{let G=X||W.length;if(typeof TextDecoder==="function"&&TextDecoder.prototype.decode)return new TextDecoder().decode(W.subarray(0,X));let Y,J,Z=Array(G*2);for(J=0,Y=0;Y<G;){let V=W[Y++];if(V<128){Z[J++]=V;continue}let U=PJ[V];if(U>4){Z[J++]=65533,Y+=U-1;continue}V&=U===2?31:U===3?15:7;while(U>1&&Y<G)V=V<<6|W[Y++]&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 bv(Z,J)},fv=(W,X)=>{if(X=X||W.length,X>W.length)X=W.length;let G=X-1;while(G>=0&&(W[G]&192)===128)G--;if(G<0)return X;if(G===0)return X;return G+PJ[W[G]]>X?G:X},RJ={string2buf:hv,buf2string:mv,utf8border:fv};function pv(){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 FC=pv,SC=Object.prototype.toString,{Z_NO_FLUSH:cv,Z_SYNC_FLUSH:lv,Z_FULL_FLUSH:dv,Z_FINISH:ov,Z_OK:rU,Z_STREAM_END:nv,Z_DEFAULT_COMPRESSION:iv,Z_DEFAULT_STRATEGY:rv,Z_DEFLATED:av}=CW;function $J(W){this.options=tU.assign({level:iv,method:av,chunkSize:16384,windowBits:15,memLevel:8,strategy:rv},W||{});let X=this.options;if(X.raw&&X.windowBits>0)X.windowBits=-X.windowBits;else if(X.gzip&&X.windowBits>0&&X.windowBits<16)X.windowBits+=16;this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new FC,this.strm.avail_out=0;let G=jJ.deflateInit2(this.strm,X.level,X.method,X.windowBits,X.memLevel,X.strategy);if(G!==rU)throw Error(KW[G]);if(X.header)jJ.deflateSetHeader(this.strm,X.header);if(X.dictionary){let Y;if(typeof X.dictionary==="string")Y=RJ.string2buf(X.dictionary);else if(SC.call(X.dictionary)==="[object ArrayBuffer]")Y=new Uint8Array(X.dictionary);else Y=X.dictionary;if(G=jJ.deflateSetDictionary(this.strm,Y),G!==rU)throw Error(KW[G]);this._dict_set=!0}}$J.prototype.push=function(W,X){let G=this.strm,Y=this.options.chunkSize,J,Z;if(this.ended)return!1;if(X===~~X)Z=X;else Z=X===!0?ov:cv;if(typeof W==="string")G.input=RJ.string2buf(W);else if(SC.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(Y),G.next_out=0,G.avail_out=Y;if((Z===lv||Z===dv)&&G.avail_out<=6){this.onData(G.output.subarray(0,G.next_out)),G.avail_out=0;continue}if(J=jJ.deflate(G,Z),J===nv){if(G.next_out>0)this.onData(G.output.subarray(0,G.next_out));return J=jJ.deflateEnd(this.strm),this.onEnd(J),this.ended=!0,J===rU}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};$J.prototype.onData=function(W){this.chunks.push(W)};$J.prototype.onEnd=function(W){if(W===rU)this.result=tU.flattenChunks(this.chunks);this.chunks=[],this.err=W,this.msg=this.strm.msg};function oA(W,X){let G=new $J(X);if(G.push(W,!0),G.err)throw G.msg||KW[G.err];return G.result}function sv(W,X){return X=X||{},X.raw=!0,oA(W,X)}function tv(W,X){return X=X||{},X.gzip=!0,oA(W,X)}var ev=$J,Wg=oA,Xg=sv,Gg=tv,Yg=CW,Jg={Deflate:ev,deflate:Wg,deflateRaw:Xg,gzip:Gg,constants:Yg},cU=16209,Zg=16191,Vg=function(X,G){let Y,J,Z,V,U,Q,N,q,A,H,I,w,O,T,x,h,$,F,u,l,f,s,y,t,H0=X.state;Y=X.next_in,y=X.input,J=Y+(X.avail_in-5),Z=X.next_out,t=X.output,V=Z-(G-X.avail_out),U=Z+(X.avail_out-257),Q=H0.dmax,N=H0.wsize,q=H0.whave,A=H0.wnext,H=H0.window,I=H0.hold,w=H0.bits,O=H0.lencode,T=H0.distcode,x=(1<<H0.lenbits)-1,h=(1<<H0.distbits)-1;W:do{if(w<15)I+=y[Y++]<<w,w+=8,I+=y[Y++]<<w,w+=8;$=O[I&x];X:for(;;){if(F=$>>>24,I>>>=F,w-=F,F=$>>>16&255,F===0)t[Z++]=$&65535;else if(F&16){if(u=$&65535,F&=15,F){if(w<F)I+=y[Y++]<<w,w+=8;u+=I&(1<<F)-1,I>>>=F,w-=F}if(w<15)I+=y[Y++]<<w,w+=8,I+=y[Y++]<<w,w+=8;$=T[I&h];G:for(;;){if(F=$>>>24,I>>>=F,w-=F,F=$>>>16&255,F&16){if(l=$&65535,F&=15,w<F){if(I+=y[Y++]<<w,w+=8,w<F)I+=y[Y++]<<w,w+=8}if(l+=I&(1<<F)-1,l>Q){X.msg="invalid distance too far back",H0.mode=cU;break W}if(I>>>=F,w-=F,F=Z-V,l>F){if(F=l-F,F>q){if(H0.sane){X.msg="invalid distance too far back",H0.mode=cU;break W}}if(f=0,s=H,A===0){if(f+=N-F,F<u){u-=F;do t[Z++]=H[f++];while(--F);f=Z-l,s=t}}else if(A<F){if(f+=N+A-F,F-=A,F<u){u-=F;do t[Z++]=H[f++];while(--F);if(f=0,A<u){F=A,u-=F;do t[Z++]=H[f++];while(--F);f=Z-l,s=t}}}else if(f+=A-F,F<u){u-=F;do t[Z++]=H[f++];while(--F);f=Z-l,s=t}while(u>2)t[Z++]=s[f++],t[Z++]=s[f++],t[Z++]=s[f++],u-=3;if(u){if(t[Z++]=s[f++],u>1)t[Z++]=s[f++]}}else{f=Z-l;do t[Z++]=t[f++],t[Z++]=t[f++],t[Z++]=t[f++],u-=3;while(u>2);if(u){if(t[Z++]=t[f++],u>1)t[Z++]=t[f++]}}}else if((F&64)===0){$=T[($&65535)+(I&(1<<F)-1)];continue G}else{X.msg="invalid distance code",H0.mode=cU;break W}break}}else if((F&64)===0){$=O[($&65535)+(I&(1<<F)-1)];continue X}else if(F&32){H0.mode=Zg;break W}else{X.msg="invalid literal/length code",H0.mode=cU;break W}break}}while(Y<J&&Z<U);u=w>>3,Y-=u,w-=u<<3,I&=(1<<w)-1,X.next_in=Y,X.next_out=Z,X.avail_in=Y<J?5+(J-Y):5-(Y-J),X.avail_out=Z<U?257+(U-Z):257-(Z-U),H0.hold=I,H0.bits=w;return},rX=15,kD=852,_D=592,yD=0,RA=1,vD=2,Ug=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]),Qg=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]),Ng=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]),qg=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]),Hg=(W,X,G,Y,J,Z,V,U)=>{let Q=U.bits,N=0,q=0,A=0,H=0,I=0,w=0,O=0,T=0,x=0,h=0,$,F,u,l,f,s=null,y,t=new Uint16Array(rX+1),H0=new Uint16Array(rX+1),g=null,d,P,E;for(N=0;N<=rX;N++)t[N]=0;for(q=0;q<Y;q++)t[X[G+q]]++;I=Q;for(H=rX;H>=1;H--)if(t[H]!==0)break;if(I>H)I=H;if(H===0)return J[Z++]=20971520,J[Z++]=20971520,U.bits=1,0;for(A=1;A<H;A++)if(t[A]!==0)break;if(I<A)I=A;T=1;for(N=1;N<=rX;N++)if(T<<=1,T-=t[N],T<0)return-1;if(T>0&&(W===yD||H!==1))return-1;H0[1]=0;for(N=1;N<rX;N++)H0[N+1]=H0[N]+t[N];for(q=0;q<Y;q++)if(X[G+q]!==0)V[H0[X[G+q]]++]=q;if(W===yD)s=g=V,y=20;else if(W===RA)s=Ug,g=Qg,y=257;else s=Ng,g=qg,y=0;if(h=0,q=0,N=A,f=Z,w=I,O=0,u=-1,x=1<<I,l=x-1,W===RA&&x>kD||W===vD&&x>_D)return 1;for(;;){if(d=N-O,V[q]+1<y)P=0,E=V[q];else if(V[q]>=y)P=g[V[q]-y],E=s[V[q]-y];else P=96,E=0;$=1<<N-O,F=1<<w,A=F;do F-=$,J[f+(h>>O)+F]=d<<24|P<<16|E|0;while(F!==0);$=1<<N-1;while(h&$)$>>=1;if($!==0)h&=$-1,h+=$;else h=0;if(q++,--t[N]===0){if(N===H)break;N=X[G+V[q]]}if(N>I&&(h&l)!==u){if(O===0)O=I;f+=A,w=N-O,T=1<<w;while(w+O<H){if(T-=t[w+O],T<=0)break;w++,T<<=1}if(x+=1<<w,W===RA&&x>kD||W===vD&&x>_D)return 1;u=h&l,J[u]=I<<24|w<<16|f-Z|0}}if(h!==0)J[f+h]=N-O<<24|4194304|0;return U.bits=I,0},KJ=Hg,Ag=0,xC=1,kC=2,{Z_FINISH:gD,Z_BLOCK:zg,Z_TREES:lU,Z_OK:DW,Z_STREAM_END:Ig,Z_NEED_DICT:wg,Z_STREAM_ERROR:O5,Z_DATA_ERROR:_C,Z_MEM_ERROR:yC,Z_BUF_ERROR:jg,Z_DEFLATED:uD}=CW,eU=16180,hD=16181,bD=16182,mD=16183,fD=16184,pD=16185,cD=16186,lD=16187,dD=16188,oD=16189,aU=16190,e7=16191,LA=16192,nD=16193,BA=16194,iD=16195,rD=16196,aD=16197,sD=16198,dU=16199,oU=16200,tD=16201,eD=16202,WC=16203,XC=16204,GC=16205,EA=16206,YC=16207,JC=16208,O8=16209,vC=16210,gC=16211,Kg=852,Og=592,Dg=15,Cg=Dg,ZC=(W)=>{return(W>>>24&255)+(W>>>8&65280)+((W&65280)<<8)+((W&255)<<24)};function Tg(){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 TW=(W)=>{if(!W)return 1;let X=W.state;if(!X||X.strm!==W||X.mode<eU||X.mode>gC)return 1;return 0},uC=(W)=>{if(TW(W))return O5;let X=W.state;if(W.total_in=W.total_out=X.total=0,W.msg="",X.wrap)W.adler=X.wrap&1;return X.mode=eU,X.last=0,X.havedict=0,X.flags=-1,X.dmax=32768,X.head=null,X.hold=0,X.bits=0,X.lencode=X.lendyn=new Int32Array(Kg),X.distcode=X.distdyn=new Int32Array(Og),X.sane=1,X.back=-1,DW},hC=(W)=>{if(TW(W))return O5;let X=W.state;return X.wsize=0,X.whave=0,X.wnext=0,uC(W)},bC=(W,X)=>{let G;if(TW(W))return O5;let Y=W.state;if(X<0)G=0,X=-X;else if(G=(X>>4)+5,X<48)X&=15;if(X&&(X<8||X>15))return O5;if(Y.window!==null&&Y.wbits!==X)Y.window=null;return Y.wrap=G,Y.wbits=X,hC(W)},mC=(W,X)=>{if(!W)return O5;let G=new Tg;W.state=G,G.strm=W,G.window=null,G.mode=eU;let Y=bC(W,X);if(Y!==DW)W.state=null;return Y},Mg=(W)=>{return mC(W,Cg)},VC=!0,$A,FA,Pg=(W)=>{if(VC){$A=new Int32Array(512),FA=new Int32Array(32);let X=0;while(X<144)W.lens[X++]=8;while(X<256)W.lens[X++]=9;while(X<280)W.lens[X++]=7;while(X<288)W.lens[X++]=8;KJ(xC,W.lens,0,288,$A,0,W.work,{bits:9}),X=0;while(X<32)W.lens[X++]=5;KJ(kC,W.lens,0,32,FA,0,W.work,{bits:5}),VC=!1}W.lencode=$A,W.lenbits=9,W.distcode=FA,W.distbits=5},fC=(W,X,G,Y)=>{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(Y>=Z.wsize)Z.window.set(X.subarray(G-Z.wsize,G),0),Z.wnext=0,Z.whave=Z.wsize;else{if(J=Z.wsize-Z.wnext,J>Y)J=Y;if(Z.window.set(X.subarray(G-Y,G-Y+J),Z.wnext),Y-=J,Y)Z.window.set(X.subarray(G-Y,G),0),Z.wnext=Y,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},Rg=(W,X)=>{let G,Y,J,Z,V,U,Q,N,q,A,H,I,w,O,T=0,x,h,$,F,u,l,f,s,y=new Uint8Array(4),t,H0,g=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]);if(TW(W)||!W.output||!W.input&&W.avail_in!==0)return O5;if(G=W.state,G.mode===e7)G.mode=LA;V=W.next_out,J=W.output,Q=W.avail_out,Z=W.next_in,Y=W.input,U=W.avail_in,N=G.hold,q=G.bits,A=U,H=Q,s=DW;W:for(;;)switch(G.mode){case eU:if(G.wrap===0){G.mode=LA;break}while(q<16){if(U===0)break W;U--,N+=Y[Z++]<<q,q+=8}if(G.wrap&2&&N===35615){if(G.wbits===0)G.wbits=15;G.check=0,y[0]=N&255,y[1]=N>>>8&255,G.check=r8(G.check,y,2,0),N=0,q=0,G.mode=hD;break}if(G.head)G.head.done=!1;if(!(G.wrap&1)||(((N&255)<<8)+(N>>8))%31){W.msg="incorrect header check",G.mode=O8;break}if((N&15)!==uD){W.msg="unknown compression method",G.mode=O8;break}if(N>>>=4,q-=4,f=(N&15)+8,G.wbits===0)G.wbits=f;if(f>15||f>G.wbits){W.msg="invalid window size",G.mode=O8;break}G.dmax=1<<G.wbits,G.flags=0,W.adler=G.check=1,G.mode=N&512?oD:e7,N=0,q=0;break;case hD:while(q<16){if(U===0)break W;U--,N+=Y[Z++]<<q,q+=8}if(G.flags=N,(G.flags&255)!==uD){W.msg="unknown compression method",G.mode=O8;break}if(G.flags&57344){W.msg="unknown header flags set",G.mode=O8;break}if(G.head)G.head.text=N>>8&1;if(G.flags&512&&G.wrap&4)y[0]=N&255,y[1]=N>>>8&255,G.check=r8(G.check,y,2,0);N=0,q=0,G.mode=bD;case bD:while(q<32){if(U===0)break W;U--,N+=Y[Z++]<<q,q+=8}if(G.head)G.head.time=N;if(G.flags&512&&G.wrap&4)y[0]=N&255,y[1]=N>>>8&255,y[2]=N>>>16&255,y[3]=N>>>24&255,G.check=r8(G.check,y,4,0);N=0,q=0,G.mode=mD;case mD:while(q<16){if(U===0)break W;U--,N+=Y[Z++]<<q,q+=8}if(G.head)G.head.xflags=N&255,G.head.os=N>>8;if(G.flags&512&&G.wrap&4)y[0]=N&255,y[1]=N>>>8&255,G.check=r8(G.check,y,2,0);N=0,q=0,G.mode=fD;case fD:if(G.flags&1024){while(q<16){if(U===0)break W;U--,N+=Y[Z++]<<q,q+=8}if(G.length=N,G.head)G.head.extra_len=N;if(G.flags&512&&G.wrap&4)y[0]=N&255,y[1]=N>>>8&255,G.check=r8(G.check,y,2,0);N=0,q=0}else if(G.head)G.head.extra=null;G.mode=pD;case pD:if(G.flags&1024){if(I=G.length,I>U)I=U;if(I){if(G.head){if(f=G.head.extra_len-G.length,!G.head.extra)G.head.extra=new Uint8Array(G.head.extra_len);G.head.extra.set(Y.subarray(Z,Z+I),f)}if(G.flags&512&&G.wrap&4)G.check=r8(G.check,Y,I,Z);U-=I,Z+=I,G.length-=I}if(G.length)break W}G.length=0,G.mode=cD;case cD:if(G.flags&2048){if(U===0)break W;I=0;do if(f=Y[Z+I++],G.head&&f&&G.length<65536)G.head.name+=String.fromCharCode(f);while(f&&I<U);if(G.flags&512&&G.wrap&4)G.check=r8(G.check,Y,I,Z);if(U-=I,Z+=I,f)break W}else if(G.head)G.head.name=null;G.length=0,G.mode=lD;case lD:if(G.flags&4096){if(U===0)break W;I=0;do if(f=Y[Z+I++],G.head&&f&&G.length<65536)G.head.comment+=String.fromCharCode(f);while(f&&I<U);if(G.flags&512&&G.wrap&4)G.check=r8(G.check,Y,I,Z);if(U-=I,Z+=I,f)break W}else if(G.head)G.head.comment=null;G.mode=dD;case dD:if(G.flags&512){while(q<16){if(U===0)break W;U--,N+=Y[Z++]<<q,q+=8}if(G.wrap&4&&N!==(G.check&65535)){W.msg="header crc mismatch",G.mode=O8;break}N=0,q=0}if(G.head)G.head.hcrc=G.flags>>9&1,G.head.done=!0;W.adler=G.check=0,G.mode=e7;break;case oD:while(q<32){if(U===0)break W;U--,N+=Y[Z++]<<q,q+=8}W.adler=G.check=ZC(N),N=0,q=0,G.mode=aU;case aU:if(G.havedict===0)return W.next_out=V,W.avail_out=Q,W.next_in=Z,W.avail_in=U,G.hold=N,G.bits=q,wg;W.adler=G.check=1,G.mode=e7;case e7:if(X===zg||X===lU)break W;case LA:if(G.last){N>>>=q&7,q-=q&7,G.mode=EA;break}while(q<3){if(U===0)break W;U--,N+=Y[Z++]<<q,q+=8}switch(G.last=N&1,N>>>=1,q-=1,N&3){case 0:G.mode=nD;break;case 1:if(Pg(G),G.mode=dU,X===lU){N>>>=2,q-=2;break W}break;case 2:G.mode=rD;break;case 3:W.msg="invalid block type",G.mode=O8}N>>>=2,q-=2;break;case nD:N>>>=q&7,q-=q&7;while(q<32){if(U===0)break W;U--,N+=Y[Z++]<<q,q+=8}if((N&65535)!==(N>>>16^65535)){W.msg="invalid stored block lengths",G.mode=O8;break}if(G.length=N&65535,N=0,q=0,G.mode=BA,X===lU)break W;case BA:G.mode=iD;case iD:if(I=G.length,I){if(I>U)I=U;if(I>Q)I=Q;if(I===0)break W;J.set(Y.subarray(Z,Z+I),V),U-=I,Z+=I,Q-=I,V+=I,G.length-=I;break}G.mode=e7;break;case rD:while(q<14){if(U===0)break W;U--,N+=Y[Z++]<<q,q+=8}if(G.nlen=(N&31)+257,N>>>=5,q-=5,G.ndist=(N&31)+1,N>>>=5,q-=5,G.ncode=(N&15)+4,N>>>=4,q-=4,G.nlen>286||G.ndist>30){W.msg="too many length or distance symbols",G.mode=O8;break}G.have=0,G.mode=aD;case aD:while(G.have<G.ncode){while(q<3){if(U===0)break W;U--,N+=Y[Z++]<<q,q+=8}G.lens[g[G.have++]]=N&7,N>>>=3,q-=3}while(G.have<19)G.lens[g[G.have++]]=0;if(G.lencode=G.lendyn,G.lenbits=7,t={bits:G.lenbits},s=KJ(Ag,G.lens,0,19,G.lencode,0,G.work,t),G.lenbits=t.bits,s){W.msg="invalid code lengths set",G.mode=O8;break}G.have=0,G.mode=sD;case sD:while(G.have<G.nlen+G.ndist){for(;;){if(T=G.lencode[N&(1<<G.lenbits)-1],x=T>>>24,h=T>>>16&255,$=T&65535,x<=q)break;if(U===0)break W;U--,N+=Y[Z++]<<q,q+=8}if($<16)N>>>=x,q-=x,G.lens[G.have++]=$;else{if($===16){H0=x+2;while(q<H0){if(U===0)break W;U--,N+=Y[Z++]<<q,q+=8}if(N>>>=x,q-=x,G.have===0){W.msg="invalid bit length repeat",G.mode=O8;break}f=G.lens[G.have-1],I=3+(N&3),N>>>=2,q-=2}else if($===17){H0=x+3;while(q<H0){if(U===0)break W;U--,N+=Y[Z++]<<q,q+=8}N>>>=x,q-=x,f=0,I=3+(N&7),N>>>=3,q-=3}else{H0=x+7;while(q<H0){if(U===0)break W;U--,N+=Y[Z++]<<q,q+=8}N>>>=x,q-=x,f=0,I=11+(N&127),N>>>=7,q-=7}if(G.have+I>G.nlen+G.ndist){W.msg="invalid bit length repeat",G.mode=O8;break}while(I--)G.lens[G.have++]=f}}if(G.mode===O8)break;if(G.lens[256]===0){W.msg="invalid code -- missing end-of-block",G.mode=O8;break}if(G.lenbits=9,t={bits:G.lenbits},s=KJ(xC,G.lens,0,G.nlen,G.lencode,0,G.work,t),G.lenbits=t.bits,s){W.msg="invalid literal/lengths set",G.mode=O8;break}if(G.distbits=6,G.distcode=G.distdyn,t={bits:G.distbits},s=KJ(kC,G.lens,G.nlen,G.ndist,G.distcode,0,G.work,t),G.distbits=t.bits,s){W.msg="invalid distances set",G.mode=O8;break}if(G.mode=dU,X===lU)break W;case dU:G.mode=oU;case oU:if(U>=6&&Q>=258){if(W.next_out=V,W.avail_out=Q,W.next_in=Z,W.avail_in=U,G.hold=N,G.bits=q,Vg(W,H),V=W.next_out,J=W.output,Q=W.avail_out,Z=W.next_in,Y=W.input,U=W.avail_in,N=G.hold,q=G.bits,G.mode===e7)G.back=-1;break}G.back=0;for(;;){if(T=G.lencode[N&(1<<G.lenbits)-1],x=T>>>24,h=T>>>16&255,$=T&65535,x<=q)break;if(U===0)break W;U--,N+=Y[Z++]<<q,q+=8}if(h&&(h&240)===0){F=x,u=h,l=$;for(;;){if(T=G.lencode[l+((N&(1<<F+u)-1)>>F)],x=T>>>24,h=T>>>16&255,$=T&65535,F+x<=q)break;if(U===0)break W;U--,N+=Y[Z++]<<q,q+=8}N>>>=F,q-=F,G.back+=F}if(N>>>=x,q-=x,G.back+=x,G.length=$,h===0){G.mode=GC;break}if(h&32){G.back=-1,G.mode=e7;break}if(h&64){W.msg="invalid literal/length code",G.mode=O8;break}G.extra=h&15,G.mode=tD;case tD:if(G.extra){H0=G.extra;while(q<H0){if(U===0)break W;U--,N+=Y[Z++]<<q,q+=8}G.length+=N&(1<<G.extra)-1,N>>>=G.extra,q-=G.extra,G.back+=G.extra}G.was=G.length,G.mode=eD;case eD:for(;;){if(T=G.distcode[N&(1<<G.distbits)-1],x=T>>>24,h=T>>>16&255,$=T&65535,x<=q)break;if(U===0)break W;U--,N+=Y[Z++]<<q,q+=8}if((h&240)===0){F=x,u=h,l=$;for(;;){if(T=G.distcode[l+((N&(1<<F+u)-1)>>F)],x=T>>>24,h=T>>>16&255,$=T&65535,F+x<=q)break;if(U===0)break W;U--,N+=Y[Z++]<<q,q+=8}N>>>=F,q-=F,G.back+=F}if(N>>>=x,q-=x,G.back+=x,h&64){W.msg="invalid distance code",G.mode=O8;break}G.offset=$,G.extra=h&15,G.mode=WC;case WC:if(G.extra){H0=G.extra;while(q<H0){if(U===0)break W;U--,N+=Y[Z++]<<q,q+=8}G.offset+=N&(1<<G.extra)-1,N>>>=G.extra,q-=G.extra,G.back+=G.extra}if(G.offset>G.dmax){W.msg="invalid distance too far back",G.mode=O8;break}G.mode=XC;case XC:if(Q===0)break W;if(I=H-Q,G.offset>I){if(I=G.offset-I,I>G.whave){if(G.sane){W.msg="invalid distance too far back",G.mode=O8;break}}if(I>G.wnext)I-=G.wnext,w=G.wsize-I;else w=G.wnext-I;if(I>G.length)I=G.length;O=G.window}else O=J,w=V-G.offset,I=G.length;if(I>Q)I=Q;Q-=I,G.length-=I;do J[V++]=O[w++];while(--I);if(G.length===0)G.mode=oU;break;case GC:if(Q===0)break W;J[V++]=G.length,Q--,G.mode=oU;break;case EA:if(G.wrap){while(q<32){if(U===0)break W;U--,N|=Y[Z++]<<q,q+=8}if(H-=Q,W.total_out+=H,G.total+=H,G.wrap&4&&H)W.adler=G.check=G.flags?r8(G.check,J,H,V-H):MJ(G.check,J,H,V-H);if(H=Q,G.wrap&4&&(G.flags?N:ZC(N))!==G.check){W.msg="incorrect data check",G.mode=O8;break}N=0,q=0}G.mode=YC;case YC:if(G.wrap&&G.flags){while(q<32){if(U===0)break W;U--,N+=Y[Z++]<<q,q+=8}if(G.wrap&4&&N!==(G.total&4294967295)){W.msg="incorrect length check",G.mode=O8;break}N=0,q=0}G.mode=JC;case JC:s=Ig;break W;case O8:s=_C;break W;case vC:return yC;case gC:default:return O5}if(W.next_out=V,W.avail_out=Q,W.next_in=Z,W.avail_in=U,G.hold=N,G.bits=q,G.wsize||H!==W.avail_out&&G.mode<O8&&(G.mode<EA||X!==gD)){if(fC(W,W.output,W.next_out,H-W.avail_out));}if(A-=W.avail_in,H-=W.avail_out,W.total_in+=A,W.total_out+=H,G.total+=H,G.wrap&4&&H)W.adler=G.check=G.flags?r8(G.check,J,H,W.next_out-H):MJ(G.check,J,H,W.next_out-H);if(W.data_type=G.bits+(G.last?64:0)+(G.mode===e7?128:0)+(G.mode===dU||G.mode===BA?256:0),(A===0&&H===0||X===gD)&&s===DW)s=jg;return s},Lg=(W)=>{if(TW(W))return O5;let X=W.state;if(X.window)X.window=null;return W.state=null,DW},Bg=(W,X)=>{if(TW(W))return O5;let G=W.state;if((G.wrap&2)===0)return O5;return G.head=X,X.done=!1,DW},Eg=(W,X)=>{let G=X.length,Y,J,Z;if(TW(W))return O5;if(Y=W.state,Y.wrap!==0&&Y.mode!==aU)return O5;if(Y.mode===aU){if(J=1,J=MJ(J,X,G,0),J!==Y.check)return _C}if(Z=fC(W,X,G,G),Z)return Y.mode=vC,yC;return Y.havedict=1,DW},$g=hC,Fg=bC,Sg=uC,xg=Mg,kg=mC,_g=Rg,yg=Lg,vg=Bg,gg=Eg,ug="pako inflate (from Nodeca project)",X4={inflateReset:$g,inflateReset2:Fg,inflateResetKeep:Sg,inflateInit:xg,inflateInit2:kg,inflate:_g,inflateEnd:yg,inflateGetHeader:vg,inflateSetDictionary:gg,inflateInfo:ug};function hg(){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 bg=hg,pC=Object.prototype.toString,{Z_NO_FLUSH:mg,Z_FINISH:fg,Z_OK:LJ,Z_STREAM_END:SA,Z_NEED_DICT:xA,Z_STREAM_ERROR:pg,Z_DATA_ERROR:UC,Z_MEM_ERROR:cg}=CW;function FJ(W){this.options=tU.assign({chunkSize:65536,windowBits:15,to:""},W||{});let X=this.options;if(X.raw&&X.windowBits>=0&&X.windowBits<16){if(X.windowBits=-X.windowBits,X.windowBits===0)X.windowBits=-15}if(X.windowBits>=0&&X.windowBits<16&&!(W&&W.windowBits))X.windowBits+=32;if(X.windowBits>15&&X.windowBits<48){if((X.windowBits&15)===0)X.windowBits|=15}this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new FC,this.strm.avail_out=0;let G=X4.inflateInit2(this.strm,X.windowBits);if(G!==LJ)throw Error(KW[G]);if(this.header=new bg,X4.inflateGetHeader(this.strm,this.header),X.dictionary){if(typeof X.dictionary==="string")X.dictionary=RJ.string2buf(X.dictionary);else if(pC.call(X.dictionary)==="[object ArrayBuffer]")X.dictionary=new Uint8Array(X.dictionary);if(X.raw){if(G=X4.inflateSetDictionary(this.strm,X.dictionary),G!==LJ)throw Error(KW[G])}}}FJ.prototype.push=function(W,X){let G=this.strm,Y=this.options.chunkSize,J=this.options.dictionary,Z,V,U;if(this.ended)return!1;if(X===~~X)V=X;else V=X===!0?fg:mg;if(pC.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(Y),G.next_out=0,G.avail_out=Y;if(Z=X4.inflate(G,V),Z===xA&&J){if(Z=X4.inflateSetDictionary(G,J),Z===LJ)Z=X4.inflate(G,V);else if(Z===UC)Z=xA}while(G.avail_in>0&&Z===SA&&G.state.wrap>0&&W[G.next_in]!==0)X4.inflateReset(G),Z=X4.inflate(G,V);switch(Z){case pg:case UC:case xA:case cg:return this.onEnd(Z),this.ended=!0,!1}if(U=G.avail_out,G.next_out){if(G.avail_out===0||Z===SA)if(this.options.to==="string"){let Q=RJ.utf8border(G.output,G.next_out),N=G.next_out-Q,q=RJ.buf2string(G.output,Q);if(G.next_out=N,G.avail_out=Y-N,N)G.output.set(G.output.subarray(Q,Q+N),0);this.onData(q)}else this.onData(G.output.length===G.next_out?G.output:G.output.subarray(0,G.next_out))}if(Z===LJ&&U===0)continue;if(Z===SA)return Z=X4.inflateEnd(this.strm),this.onEnd(Z),this.ended=!0,!0;if(G.avail_in===0)break}return!0};FJ.prototype.onData=function(W){this.chunks.push(W)};FJ.prototype.onEnd=function(W){if(W===LJ)if(this.options.to==="string")this.result=this.chunks.join("");else this.result=tU.flattenChunks(this.chunks);this.chunks=[],this.err=W,this.msg=this.strm.msg};function nA(W,X){let G=new FJ(X);if(G.push(W),G.err)throw G.msg||KW[G.err];return G.result}function lg(W,X){return X=X||{},X.raw=!0,nA(W,X)}var dg=FJ,og=nA,ng=lg,ig=nA,rg=CW,ag={Inflate:dg,inflate:og,inflateRaw:ng,ungzip:ig,constants:rg},{Deflate:sg,deflate:tg,deflateRaw:eg,gzip:Wu}=Jg,{Inflate:Xu,inflate:Gu,inflateRaw:Yu,ungzip:Ju}=ag,Zu=sg,Vu=tg,Uu=eg,Qu=Wu,Nu=Xu,qu=Gu,Hu=Yu,Au=Ju,zu=CW,GG={Deflate:Zu,deflate:Vu,deflateRaw:Uu,gzip:Qu,Inflate:Nu,inflate:qu,inflateRaw:Hu,ungzip:Au,constants:zu};function cC(){let W=Date.now(),X=0;return{now(){return W=Math.max(W,Date.now()),X++,{physical:W,logical:X}},update(G){if(!G||typeof G.physical!=="number"||typeof G.logical!=="number")return;W=Math.max(W,G.physical),X=Math.max(X,G.logical)+1},compare(G,Y){if(!G&&!Y)return 0;if(!G)return-1;if(!Y)return 1;if(G.physical!==Y.physical)return G.physical>Y.physical?1:-1;if(G.logical!==Y.logical)return G.logical>Y.logical?1:-1;return 0}}}var MW=(W)=>W?.physical>Date.now()+7200000;function lC(W,X,G){let Y=X.timestamp;if(MW(Y))return{resolved:!1};if(X?.value?.priority===!0&&typeof X.id==="string"&&X.id.startsWith("user:")&&"role"in X.value){let{priority:Z,...V}=X.value;if(W?.timestamp&&G.compare(Y,W.timestamp)===0&&JSON.stringify(V)===JSON.stringify(W.value))return{resolved:!1};return{resolved:!0,value:V,timestamp:Y}}if(X?.value?.priority!==void 0){let{priority:Z,...V}=X.value;X={...X,value:V}}if(!W?.timestamp)return{resolved:!0,value:X.value,timestamp:Y};let J=G.compare(Y,W.timestamp);if(J<0)return{resolved:!1};if(J===0&&JSON.stringify(X.value)<=JSON.stringify(W.value))return{resolved:!1};return{resolved:!0,value:X.value,timestamp:Y}}var iA=Math.PI/180,dC=(W)=>Math.sin(W*iA/2)**2,Iu=new Intl.Collator().compare,SJ={$eq:(W,X)=>W===X,$ne:(W,X)=>W!==X,$gt:(W,X)=>W>X,$gte:(W,X)=>W>=X,$lt:(W,X)=>W<X,$lte:(W,X)=>W<=X,$in:(W,X)=>Array.isArray(X)&&(Array.isArray(W)?W.some((G)=>X.includes(G)):X.includes(W)),$between:(W,[X,G])=>W>=X&&W<=G,$near:(W,{latitude:X,longitude:G,radius:Y})=>{let J=W?.value??W,Z=J?.latitude??J?.location?.latitude,V=J?.longitude??J?.location?.longitude;return[Z,V,X,G,Y].every(Number.isFinite)&&dC(Z-X)+Math.cos(X*iA)*Math.cos(Z*iA)*dC(V-G)<=Math.sin(Math.min(Y/12742,Math.PI/2))**2},$exists:(W,X)=>X?W!==void 0:W===void 0,$startsWith:(W,X)=>typeof W==="string"&&W.startsWith(X),$endsWith:(W,X)=>typeof W==="string"&&W.endsWith(X),$contains:(W,X)=>typeof W==="string"&&W.includes(X),$text:{global:(W,X)=>{let G=(J)=>String(J).normalize("NFD").replace(/[\u0300-\u036f]/g,"").toLowerCase().replace(/[^\w\s]/g,""),Y=G(X);return Object.values(W).some((J)=>typeof J==="object"?null.fieldSearch(J,Y):G(J).includes(Y))},field:(W,X)=>{let G=(J)=>String(J).normalize("NFD").replace(/[\u0300-\u036f]/g,"").toLowerCase().replace(/[^\w\s]/g,""),Y=G(X);return Array.isArray(W)?W.some((J)=>G(J).includes(Y)):G(W).includes(Y)}},$like:(W,X)=>typeof W==="string"&&typeof X==="string"&&new RegExp(`^${X.replace(/%/g,".*").replace(/_/g,".")}$`,"i").test(W),$regex:(W,X)=>typeof W==="string"&&new RegExp(X.$regex||X,"i").test(W),$and:(W,X,G)=>X.every((Y)=>G.createFilter(Y,G.allNodes)(W)),$or:(W,X,G)=>X.some((Y)=>G.createFilter(Y,G.allNodes)(W)),$not:(W,X,G)=>!G.createFilter(X,G.allNodes)(W),$edge:(W,X,G)=>{if(!W.edges?.length||typeof X!=="object"||X===null)return!1;let Y=G.createFilter(X,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(Y(Q))V.push(Q);Q.edges?.forEach((N)=>!Z.has(N)&&Z.add(N)&&J.push(N))}if(V.length)W._edgeResult=V;return V.length>0}},rA=(W,X)=>X.split(".").reduce((G,Y)=>G&&typeof G==="object"&&(Y in G)?G[Y]:void 0,W),WQ=(W,X)=>{if(Object.keys(W).length===0)return()=>!0;return(G)=>Object.entries(W).every(([Y,J])=>{if(Y.startsWith("$"))return SJ[Y](G,J,{createFilter:WQ,allNodes:X});let Z=rA(G.value,Y);if(Z===void 0)Z=rA(G,Y);if(J instanceof RegExp)return J.test(String(Z));if(typeof J!=="object"||J===null)return SJ.$eq(Z,J);return Object.entries(J).every(([V,U])=>{if(V==="$text")return SJ.$text.field(Z,U);if(V==="$between"&&U.every((Q)=>Q instanceof Date))return SJ.$between(new Date(Z),U);return SJ[V]?.(Z,U,{createFilter:WQ,allNodes:X})??!1})})},aA=(W,X)=>{let{$edge:G,...Y}=X.query||{},J=WQ(Y,W),Z=Object.values(W).filter(J),U=[...G?(()=>{let Q=WQ({$edge:G},W);Z.forEach((q)=>Q(q));let N=new Map;return Z.forEach((q)=>{if(q._edgeResult)q._edgeResult.forEach((A)=>N.set(A.id,A)),delete q._edgeResult}),Array.from(N.values())})():Z];if(X.field){let Q=X.order==="asc"?1:-1,N=U.map((q)=>[rA(q.value,X.field),q]);N.sort(([q,A],[H,I])=>((typeof q==="string"&&typeof H==="string"?Iu(q,H):(q??0)-(H??0))||(A.id<I.id?-1:1))*Q),U=N.map(([,q])=>q)}if(X.$after){let Q=U.findIndex((N)=>N.id===X.$after);U=Q>=0?U.slice(Q+1):[]}if(X.$before){let Q=U.findIndex((N)=>N.id===X.$before);U=Q>=0?U.slice(0,Q):[]}if(X.$limit)U=U.slice(0,X.$limit);return U.map((Q)=>({...Q,edges:(Q.edges??[]).filter((N)=>Object.hasOwn(W,N))}))};var _9=(()=>{let W=()=>{};return new Proxy(console,{get:(X,G)=>globalThis.__gdbDebug?X[G].bind(X):W})})(),YG=typeof globalThis==="object"&&"crypto"in globalThis?globalThis.crypto:void 0;/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */function PQ(W){return W instanceof Uint8Array||ArrayBuffer.isView(W)&&W.constructor.name==="Uint8Array"}function Qz(W){if(!Number.isSafeInteger(W)||W<0)throw Error("positive integer expected, got "+W)}function EW(W,...X){if(!PQ(W))throw Error("Uint8Array expected");if(X.length>0&&!X.includes(W.length))throw Error("Uint8Array expected of length "+X+", got length="+W.length)}function AT(W){if(typeof W!=="function"||typeof W.create!=="function")throw Error("Hash should be wrapped by utils.createHasher");Qz(W.outputLen),Qz(W.blockLen)}function AQ(W,X=!0){if(W.destroyed)throw Error("Hash instance has been destroyed");if(X&&W.finished)throw Error("Hash#digest() has already been called")}function wu(W,X){EW(W);let G=X.outputLen;if(W.length<G)throw Error("digestInto() expects output buffer of length at least "+G)}function zQ(...W){for(let X=0;X<W.length;X++)W[X].fill(0)}function sA(W){return new DataView(W.buffer,W.byteOffset,W.byteLength)}function w7(W,X){return W<<32-X|W>>>X}var zT=(()=>typeof Uint8Array.from([]).toHex==="function"&&typeof Uint8Array.fromHex==="function")(),ju=Array.from({length:256},(W,X)=>X.toString(16).padStart(2,"0"));function VG(W){if(EW(W),zT)return W.toHex();let X="";for(let G=0;G<W.length;G++)X+=ju[W[G]];return X}var G4={_0:48,_9:57,A:65,F:70,a:97,f:102};function oC(W){if(W>=G4._0&&W<=G4._9)return W-G4._0;if(W>=G4.A&&W<=G4.F)return W-(G4.A-10);if(W>=G4.a&&W<=G4.f)return W-(G4.a-10);return}function IQ(W){if(typeof W!=="string")throw Error("hex string expected, got "+typeof W);if(zT)return Uint8Array.fromHex(W);let X=W.length,G=X/2;if(X%2)throw Error("hex string expected, got unpadded hex of length "+X);let Y=new Uint8Array(G);for(let J=0,Z=0;J<G;J++,Z+=2){let V=oC(W.charCodeAt(Z)),U=oC(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)}Y[J]=V*16+U}return Y}function IT(W){if(typeof W!=="string")throw Error("string expected");return new Uint8Array(new TextEncoder().encode(W))}function jz(W){if(typeof W==="string")W=IT(W);return EW(W),W}function j7(...W){let X=0;for(let Y=0;Y<W.length;Y++){let J=W[Y];EW(J),X+=J.length}let G=new Uint8Array(X);for(let Y=0,J=0;Y<W.length;Y++){let Z=W[Y];G.set(Z,J),J+=Z.length}return G}class Kz{}function Ku(W){let X=(Y)=>W().update(jz(Y)).digest(),G=W();return X.outputLen=G.outputLen,X.blockLen=G.blockLen,X.create=()=>W(),X}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 Ou(W,X,G,Y){if(typeof W.setBigUint64==="function")return W.setBigUint64(X,G,Y);let J=BigInt(32),Z=BigInt(4294967295),V=Number(G>>J&Z),U=Number(G&Z),Q=Y?4:0,N=Y?0:4;W.setUint32(X+Q,V,Y),W.setUint32(X+N,U,Y)}function Du(W,X,G){return W&X^~W&G}function Cu(W,X,G){return W&X^W&G^X&G}class wT extends Kz{constructor(W,X,G,Y){super();this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=W,this.outputLen=X,this.padOffset=G,this.isLE=Y,this.buffer=new Uint8Array(W),this.view=sA(this.buffer)}update(W){AQ(this),W=jz(W),EW(W);let{view:X,buffer:G,blockLen:Y}=this,J=W.length;for(let Z=0;Z<J;){let V=Math.min(Y-this.pos,J-Z);if(V===Y){let U=sA(W);for(;Y<=J-Z;Z+=Y)this.process(U,Z);continue}if(G.set(W.subarray(Z,Z+V),this.pos),this.pos+=V,Z+=V,this.pos===Y)this.process(X,0),this.pos=0}return this.length+=W.length,this.roundClean(),this}digestInto(W){AQ(this),wu(W,this),this.finished=!0;let{buffer:X,view:G,blockLen:Y,isLE:J}=this,{pos:Z}=this;if(X[Z++]=128,zQ(this.buffer.subarray(Z)),this.padOffset>Y-Z)this.process(G,0),Z=0;for(let q=Z;q<Y;q++)X[q]=0;Ou(G,Y-8,BigInt(this.length*8),J),this.process(G,0);let V=sA(W),U=this.outputLen;if(U%4)throw Error("_sha2: outputLen should be aligned to 32bit");let Q=U/4,N=this.get();if(Q>N.length)throw Error("_sha2: outputLen bigger than state");for(let q=0;q<Q;q++)V.setUint32(4*q,N[q],J)}digest(){let{buffer:W,outputLen:X}=this;this.digestInto(W);let G=W.slice(0,X);return this.destroy(),G}_cloneInto(W){W||(W=new this.constructor),W.set(...this.get());let{blockLen:X,buffer:G,length:Y,finished:J,destroyed:Z,pos:V}=this;if(W.destroyed=Z,W.finished=J,W.length=Y,W.pos=V,Y%X)W.buffer.set(G);return W}clone(){return this._cloneInto()}}var H6=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Tu=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]),A6=new Uint32Array(64);class jT extends wT{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:X,C:G,D:Y,E:J,F:Z,G:V,H:U}=this;return[W,X,G,Y,J,Z,V,U]}set(W,X,G,Y,J,Z,V,U){this.A=W|0,this.B=X|0,this.C=G|0,this.D=Y|0,this.E=J|0,this.F=Z|0,this.G=V|0,this.H=U|0}process(W,X){for(let q=0;q<16;q++,X+=4)A6[q]=W.getUint32(X,!1);for(let q=16;q<64;q++){let A=A6[q-15],H=A6[q-2],I=w7(A,7)^w7(A,18)^A>>>3,w=w7(H,17)^w7(H,19)^H>>>10;A6[q]=w+A6[q-7]+I+A6[q-16]|0}let{A:G,B:Y,C:J,D:Z,E:V,F:U,G:Q,H:N}=this;for(let q=0;q<64;q++){let A=w7(V,6)^w7(V,11)^w7(V,25),H=N+A+Du(V,U,Q)+Tu[q]+A6[q]|0,I=(w7(G,2)^w7(G,13)^w7(G,22))+Cu(G,Y,J)|0;N=Q,Q=U,U=V,V=Z+H|0,Z=J,J=Y,Y=G,G=H+I|0}G=G+this.A|0,Y=Y+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,N=N+this.H|0,this.set(G,Y,J,Z,V,U,Q,N)}roundClean(){zQ(A6)}destroy(){this.set(0,0,0,0,0,0,0,0),zQ(this.buffer)}}var Nz=Ku(()=>new jT);class Oz extends Kz{constructor(W,X){super();this.finished=!1,this.destroyed=!1,AT(W);let G=jz(X);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 Y=this.blockLen,J=new Uint8Array(Y);J.set(G.length>Y?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),zQ(J)}update(W){return AQ(this),this.iHash.update(W),this}digestInto(W){AQ(this),EW(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:X,iHash:G,finished:Y,destroyed:J,blockLen:Z,outputLen:V}=this;return W=W,W.finished=Y,W.destroyed=J,W.blockLen=Z,W.outputLen=V,W.oHash=X._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 KT=(W,X,G)=>new Oz(W,X).update(G).digest();KT.create=(W,X)=>new Oz(W,X);/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */var Dz=BigInt(0),qz=BigInt(1);function wQ(W,X=""){if(typeof W!=="boolean"){let G=X&&`"${X}"`;throw Error(G+"expected boolean, got type="+typeof W)}return W}function PW(W,X,G=""){let Y=PQ(W),J=W?.length,Z=X!==void 0;if(!Y||Z&&J!==X){let V=G&&`"${G}" `,U=Z?` of length ${X}`:"",Q=Y?`length=${J}`:`type=${typeof W}`;throw Error(V+"expected Uint8Array"+U+", got "+Q)}return W}function XQ(W){let X=W.toString(16);return X.length&1?"0"+X:X}function OT(W){if(typeof W!=="string")throw Error("hex string expected, got "+typeof W);return W===""?Dz:BigInt("0x"+W)}function HG(W){return OT(VG(W))}function DT(W){return EW(W),OT(VG(Uint8Array.from(W).reverse()))}function LQ(W,X){return IQ(W.toString(16).padStart(X*2,"0"))}function CT(W,X){return LQ(W,X).reverse()}function f8(W,X,G){let Y;if(typeof X==="string")try{Y=IQ(X)}catch(Z){throw Error(W+" must be hex string or Uint8Array, cause: "+Z)}else if(PQ(X))Y=Uint8Array.from(X);else throw Error(W+" must be hex string or Uint8Array");let J=Y.length;if(typeof G==="number"&&J!==G)throw Error(W+" of length "+G+" expected, got "+J);return Y}var tA=(W)=>typeof W==="bigint"&&Dz<=W;function Hz(W,X,G){return tA(W)&&tA(X)&&tA(G)&&X<=W&&W<G}function Mu(W,X,G,Y){if(!Hz(X,G,Y))throw Error("expected valid "+W+": "+G+" <= n < "+Y+", got "+X)}function TT(W){let X;for(X=0;W>Dz;W>>=qz,X+=1);return X}var bJ=(W)=>(qz<<BigInt(W))-qz;function Pu(W,X,G){if(typeof W!=="number"||W<2)throw Error("hashLen must be a number");if(typeof X!=="number"||X<2)throw Error("qByteLen must be a number");if(typeof G!=="function")throw Error("hmacFn must be a function");let Y=(H)=>new Uint8Array(H),J=(H)=>Uint8Array.of(H),Z=Y(W),V=Y(W),U=0,Q=()=>{Z.fill(1),V.fill(0),U=0},N=(...H)=>G(V,Z,...H),q=(H=Y(0))=>{if(V=N(J(0),H),Z=N(),H.length===0)return;V=N(J(1),H),Z=N()},A=()=>{if(U++>=1000)throw Error("drbg: tried 1000 values");let H=0,I=[];while(H<X){Z=N();let w=Z.slice();I.push(w),H+=Z.length}return j7(...I)};return(H,I)=>{Q(),q(H);let w=void 0;while(!(w=I(A())))q();return Q(),w}}function Cz(W,X,G={}){if(!W||typeof W!=="object")throw Error("expected valid options object");function Y(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(X).forEach(([J,Z])=>Y(J,Z,!1)),Object.entries(G).forEach(([J,Z])=>Y(J,Z,!0))}function nC(W){let X=new WeakMap;return(G,...Y)=>{let J=X.get(G);if(J!==void 0)return J;let Z=W(G,...Y);return X.set(G,Z),Z}}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */var y9=BigInt(0),I9=BigInt(1),RW=BigInt(2),MT=BigInt(3),PT=BigInt(4),RT=BigInt(5),Ru=BigInt(7),LT=BigInt(8),Lu=BigInt(9),BT=BigInt(16);function T5(W,X){let G=W%X;return G>=y9?G:X+G}function D5(W,X,G){let Y=W;while(X-- >y9)Y*=Y,Y%=G;return Y}function iC(W,X){if(W===y9)throw Error("invert: expected non-zero number");if(X<=y9)throw Error("invert: expected positive modulus, got "+X);let G=T5(W,X),Y=X,J=y9,Z=I9,V=I9,U=y9;while(G!==y9){let Q=Y/G,N=Y%G,q=J-V*Q,A=Z-U*Q;Y=G,G=N,J=V,Z=U,V=q,U=A}if(Y!==I9)throw Error("invert: does not exist");return T5(J,X)}function Tz(W,X,G){if(!W.eql(W.sqr(X),G))throw Error("Cannot find square root")}function ET(W,X){let G=(W.ORDER+I9)/PT,Y=W.pow(X,G);return Tz(W,Y,X),Y}function Bu(W,X){let G=(W.ORDER-RT)/LT,Y=W.mul(X,RW),J=W.pow(Y,G),Z=W.mul(X,J),V=W.mul(W.mul(Z,RW),J),U=W.mul(Z,W.sub(V,W.ONE));return Tz(W,U,X),U}function Eu(W){let X=mJ(W),G=$T(W),Y=G(X,X.neg(X.ONE)),J=G(X,Y),Z=G(X,X.neg(Y)),V=(W+Ru)/BT;return(U,Q)=>{let N=U.pow(Q,V),q=U.mul(N,Y),A=U.mul(N,J),H=U.mul(N,Z),I=U.eql(U.sqr(q),Q),w=U.eql(U.sqr(A),Q);N=U.cmov(N,q,I),q=U.cmov(H,A,w);let O=U.eql(U.sqr(q),Q),T=U.cmov(N,q,O);return Tz(U,T,Q),T}}function $T(W){if(W<MT)throw Error("sqrt is not defined for small field");let X=W-I9,G=0;while(X%RW===y9)X/=RW,G++;let Y=RW,J=mJ(W);while(rC(J,Y)===1)if(Y++>1000)throw Error("Cannot find square root: probably non-prime P");if(G===1)return ET;let Z=J.pow(Y,X),V=(X+I9)/RW;return function(U,Q){if(U.is0(Q))return Q;if(rC(U,Q)!==1)throw Error("Cannot find square root");let N=G,q=U.mul(U.ONE,Z),A=U.pow(Q,X),H=U.pow(Q,V);while(!U.eql(A,U.ONE)){if(U.is0(A))return U.ZERO;let I=1,w=U.sqr(A);while(!U.eql(w,U.ONE))if(I++,w=U.sqr(w),I===N)throw Error("Cannot find square root");let O=I9<<BigInt(N-I-1),T=U.pow(q,O);N=I,q=U.sqr(T),A=U.mul(A,q),H=U.mul(H,T)}return H}}function $u(W){if(W%PT===MT)return ET;if(W%LT===RT)return Bu;if(W%BT===Lu)return Eu(W);return $T(W)}var Fu=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Su(W){let X={ORDER:"bigint",MASK:"bigint",BYTES:"number",BITS:"number"},G=Fu.reduce((Y,J)=>{return Y[J]="function",Y},X);return Cz(W,G),W}function xu(W,X,G){if(G<y9)throw Error("invalid exponent, negatives unsupported");if(G===y9)return W.ONE;if(G===I9)return X;let Y=W.ONE,J=X;while(G>y9){if(G&I9)Y=W.mul(Y,J);J=W.sqr(J),G>>=I9}return Y}function FT(W,X,G=!1){let Y=Array(X.length).fill(G?W.ZERO:void 0),J=X.reduce((V,U,Q)=>{if(W.is0(U))return V;return Y[Q]=V,W.mul(V,U)},W.ONE),Z=W.inv(J);return X.reduceRight((V,U,Q)=>{if(W.is0(U))return V;return Y[Q]=W.mul(V,Y[Q]),W.mul(V,U)},Z),Y}function rC(W,X){let G=(W.ORDER-I9)/RW,Y=W.pow(X,G),J=W.eql(Y,W.ONE),Z=W.eql(Y,W.ZERO),V=W.eql(Y,W.neg(W.ONE));if(!J&&!Z&&!V)throw Error("invalid Legendre symbol result");return J?1:Z?0:-1}function ST(W,X){if(X!==void 0)Qz(X);let G=X!==void 0?X:W.toString(2).length,Y=Math.ceil(G/8);return{nBitLength:G,nByteLength:Y}}function mJ(W,X,G=!1,Y={}){if(W<=y9)throw Error("invalid field: expected ORDER > 0, got "+W);let J=void 0,Z=void 0,V=!1,U=void 0;if(typeof X==="object"&&X!=null){if(Y.sqrt||G)throw Error("cannot specify opts in two arguments");let H=X;if(H.BITS)J=H.BITS;if(H.sqrt)Z=H.sqrt;if(typeof H.isLE==="boolean")G=H.isLE;if(typeof H.modFromBytes==="boolean")V=H.modFromBytes;U=H.allowedLengths}else{if(typeof X==="number")J=X;if(Y.sqrt)Z=Y.sqrt}let{nBitLength:Q,nByteLength:N}=ST(W,J);if(N>2048)throw Error("invalid field: expected ORDER of <= 2048 bytes");let q,A=Object.freeze({ORDER:W,isLE:G,BITS:Q,BYTES:N,MASK:bJ(Q),ZERO:y9,ONE:I9,allowedLengths:U,create:(H)=>T5(H,W),isValid:(H)=>{if(typeof H!=="bigint")throw Error("invalid field element: expected bigint, got "+typeof H);return y9<=H&&H<W},is0:(H)=>H===y9,isValidNot0:(H)=>!A.is0(H)&&A.isValid(H),isOdd:(H)=>(H&I9)===I9,neg:(H)=>T5(-H,W),eql:(H,I)=>H===I,sqr:(H)=>T5(H*H,W),add:(H,I)=>T5(H+I,W),sub:(H,I)=>T5(H-I,W),mul:(H,I)=>T5(H*I,W),pow:(H,I)=>xu(A,H,I),div:(H,I)=>T5(H*iC(I,W),W),sqrN:(H)=>H*H,addN:(H,I)=>H+I,subN:(H,I)=>H-I,mulN:(H,I)=>H*I,inv:(H)=>iC(H,W),sqrt:Z||((H)=>{if(!q)q=$u(W);return q(A,H)}),toBytes:(H)=>G?CT(H,N):LQ(H,N),fromBytes:(H,I=!0)=>{if(U){if(!U.includes(H.length)||H.length>N)throw Error("Field.fromBytes: expected "+U+" bytes, got "+H.length);let O=new Uint8Array(N);O.set(H,G?0:O.length-H.length),H=O}if(H.length!==N)throw Error("Field.fromBytes: expected "+N+" bytes, got "+H.length);let w=G?DT(H):HG(H);if(V)w=T5(w,W);if(!I){if(!A.isValid(w))throw Error("invalid field element: outside of range 0..ORDER")}return w},invertBatch:(H)=>FT(A,H),cmov:(H,I,w)=>w?I:H});return Object.freeze(A)}function xT(W){if(typeof W!=="bigint")throw Error("field order must be bigint");let X=W.toString(2).length;return Math.ceil(X/8)}function kT(W){let X=xT(W);return X+Math.ceil(X/2)}function _T(W,X,G=!1){let Y=W.length,J=xT(X),Z=kT(X);if(Y<16||Y<Z||Y>1024)throw Error("expected "+Z+"-1024 bytes of input, got "+Y);let V=G?DT(W):HG(W),U=T5(V,X-I9)+I9;return G?CT(U,J):LQ(U,J)}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */var NG=BigInt(0),LW=BigInt(1);function jQ(W,X){let G=X.negate();return W?G:X}function eA(W,X){let G=FT(W.Fp,X.map((Y)=>Y.Z));return X.map((Y,J)=>W.fromAffine(Y.toAffine(G[J])))}function yT(W,X){if(!Number.isSafeInteger(W)||W<=0||W>X)throw Error("invalid window size, expected [1.."+X+"], got W="+W)}function Wz(W,X){yT(W,X);let G=Math.ceil(X/W)+1,Y=2**(W-1),J=2**W,Z=bJ(W),V=BigInt(W);return{windows:G,windowSize:Y,mask:Z,maxNumber:J,shiftBy:V}}function aC(W,X,G){let{windowSize:Y,mask:J,maxNumber:Z,shiftBy:V}=G,U=Number(W&J),Q=W>>V;if(U>Y)U-=Z,Q+=LW;let N=X*Y,q=N+Math.abs(U)-1,A=U===0,H=U<0,I=X%2!==0;return{nextN:Q,offset:q,isZero:A,isNeg:H,isNegF:I,offsetF:N}}function ku(W,X){if(!Array.isArray(W))throw Error("array expected");W.forEach((G,Y)=>{if(!(G instanceof X))throw Error("invalid point at index "+Y)})}function _u(W,X){if(!Array.isArray(W))throw Error("array of scalars expected");W.forEach((G,Y)=>{if(!X.isValid(G))throw Error("invalid scalar at index "+Y)})}var Xz=new WeakMap,vT=new WeakMap;function Gz(W){return vT.get(W)||1}function sC(W){if(W!==NG)throw Error("invalid wNAF")}class gT{constructor(W,X){this.BASE=W.BASE,this.ZERO=W.ZERO,this.Fn=W.Fn,this.bits=X}_unsafeLadder(W,X,G=this.ZERO){let Y=W;while(X>NG){if(X&LW)G=G.add(Y);Y=Y.double(),X>>=LW}return G}precomputeWindow(W,X){let{windows:G,windowSize:Y}=Wz(X,this.bits),J=[],Z=W,V=Z;for(let U=0;U<G;U++){V=Z,J.push(V);for(let Q=1;Q<Y;Q++)V=V.add(Z),J.push(V);Z=V.double()}return J}wNAF(W,X,G){if(!this.Fn.isValid(G))throw Error("invalid scalar");let Y=this.ZERO,J=this.BASE,Z=Wz(W,this.bits);for(let V=0;V<Z.windows;V++){let{nextN:U,offset:Q,isZero:N,isNeg:q,isNegF:A,offsetF:H}=aC(G,V,Z);if(G=U,N)J=J.add(jQ(A,X[H]));else Y=Y.add(jQ(q,X[Q]))}return sC(G),{p:Y,f:J}}wNAFUnsafe(W,X,G,Y=this.ZERO){let J=Wz(W,this.bits);for(let Z=0;Z<J.windows;Z++){if(G===NG)break;let{nextN:V,offset:U,isZero:Q,isNeg:N}=aC(G,Z,J);if(G=V,Q)continue;else{let q=X[U];Y=Y.add(N?q.negate():q)}}return sC(G),Y}getPrecomputes(W,X,G){let Y=Xz.get(X);if(!Y){if(Y=this.precomputeWindow(X,W),W!==1){if(typeof G==="function")Y=G(Y);Xz.set(X,Y)}}return Y}cached(W,X,G){let Y=Gz(W);return this.wNAF(Y,this.getPrecomputes(Y,W,G),X)}unsafe(W,X,G,Y){let J=Gz(W);if(J===1)return this._unsafeLadder(W,X,Y);return this.wNAFUnsafe(J,this.getPrecomputes(J,W,G),X,Y)}createCache(W,X){yT(X,this.bits),vT.set(W,X),Xz.delete(W)}hasCache(W){return Gz(W)!==1}}function yu(W,X,G,Y){let J=X,Z=W.ZERO,V=W.ZERO;while(G>NG||Y>NG){if(G&LW)Z=Z.add(J);if(Y&LW)V=V.add(J);J=J.double(),G>>=LW,Y>>=LW}return{p1:Z,p2:V}}function vu(W,X,G,Y){ku(G,W),_u(Y,X);let J=G.length,Z=Y.length;if(J!==Z)throw Error("arrays of points and scalars must have equal length");let V=W.ZERO,U=TT(BigInt(J)),Q=1;if(U>12)Q=U-3;else if(U>4)Q=U-2;else if(U>0)Q=2;let N=bJ(Q),q=Array(Number(N)+1).fill(V),A=Math.floor((X.BITS-1)/Q)*Q,H=V;for(let I=A;I>=0;I-=Q){q.fill(V);for(let O=0;O<Z;O++){let T=Y[O],x=Number(T>>BigInt(I)&N);q[x]=q[x].add(G[O])}let w=V;for(let O=q.length-1,T=V;O>0;O--)T=T.add(q[O]),w=w.add(T);if(H=H.add(w),I!==0)for(let O=0;O<Q;O++)H=H.double()}return H}function tC(W,X,G){if(X){if(X.ORDER!==W)throw Error("Field.ORDER must match order: Fp == p, Fn == n");return Su(X),X}else return mJ(W,{isLE:G})}function gu(W,X,G={},Y){if(Y===void 0)Y=W==="edwards";if(!X||typeof X!=="object")throw Error(`expected valid ${W} CURVE object`);for(let U of["p","n","h"]){let Q=X[U];if(!(typeof Q==="bigint"&&Q>NG))throw Error(`CURVE.${U} must be positive bigint`)}let J=tC(X.p,G.Fp,Y),Z=tC(X.n,G.Fn,Y),V=["Gx","Gy","a",W==="weierstrass"?"b":"d"];for(let U of V)if(!J.isValid(X[U]))throw Error(`CURVE.${U} must be valid field element of CURVE.Fp`);return X=Object.freeze(Object.assign({},X)),{CURVE:X,Fp:J,Fn:Z}}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */var eC=(W,X)=>(W+(W>=0?X:-X)/hT)/X;function uu(W,X,G){let[[Y,J],[Z,V]]=X,U=eC(V*W,G),Q=eC(-J*W,G),N=W-U*Y-Q*Z,q=-U*J-Q*V,A=N<J4,H=q<J4;if(A)N=-N;if(H)q=-q;let I=bJ(Math.ceil(TT(G)/2))+UG;if(N<J4||N>=I||q<J4||q>=I)throw Error("splitScalar (endomorphism): failed, k="+W);return{k1neg:A,k1:N,k2neg:H,k2:q}}function Az(W){if(!["compact","recovered","der"].includes(W))throw Error('Signature format must be "compact", "recovered", or "der"');return W}function Yz(W,X){let G={};for(let Y of Object.keys(X))G[Y]=W[Y]===void 0?X[Y]:W[Y];if(wQ(G.lowS,"lowS"),wQ(G.prehash,"prehash"),G.format!==void 0)Az(G.format);return G}class uT extends Error{constructor(W=""){super(W)}}var Y4={Err:uT,_tlv:{encode:(W,X)=>{let{Err:G}=Y4;if(W<0||W>256)throw new G("tlv.encode: wrong tag");if(X.length&1)throw new G("tlv.encode: unpadded data");let Y=X.length/2,J=XQ(Y);if(J.length/2&128)throw new G("tlv.encode: long form length too big");let Z=Y>127?XQ(J.length/2|128):"";return XQ(W)+Z+J+X},decode(W,X){let{Err:G}=Y4,Y=0;if(W<0||W>256)throw new G("tlv.encode: wrong tag");if(X.length<2||X[Y++]!==W)throw new G("tlv.decode: wrong tlv");let J=X[Y++],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 N=X.subarray(Y,Y+Q);if(N.length!==Q)throw new G("tlv.decode: length bytes not complete");if(N[0]===0)throw new G("tlv.decode(long): zero leftmost byte");for(let q of N)V=V<<8|q;if(Y+=Q,V<128)throw new G("tlv.decode(long): not minimal encoding")}let U=X.subarray(Y,Y+V);if(U.length!==V)throw new G("tlv.decode: wrong value length");return{v:U,l:X.subarray(Y+V)}}},_int:{encode(W){let{Err:X}=Y4;if(W<J4)throw new X("integer: negative integers are not allowed");let G=XQ(W);if(Number.parseInt(G[0],16)&8)G="00"+G;if(G.length&1)throw new X("unexpected DER parsing assertion: unpadded hex");return G},decode(W){let{Err:X}=Y4;if(W[0]&128)throw new X("invalid signature integer: negative");if(W[0]===0&&!(W[1]&128))throw new X("invalid signature integer: unnecessary leading zero");return HG(W)}},toSig(W){let{Err:X,_int:G,_tlv:Y}=Y4,J=f8("signature",W),{v:Z,l:V}=Y.decode(48,J);if(V.length)throw new X("invalid signature: left bytes after parsing");let{v:U,l:Q}=Y.decode(2,Z),{v:N,l:q}=Y.decode(2,Q);if(q.length)throw new X("invalid signature: left bytes after parsing");return{r:G.decode(U),s:G.decode(N)}},hexFromSig(W){let{_tlv:X,_int:G}=Y4,Y=X.encode(2,G.encode(W.r)),J=X.encode(2,G.encode(W.s)),Z=Y+J;return X.encode(48,Z)}},J4=BigInt(0),UG=BigInt(1),hT=BigInt(2),GQ=BigInt(3),hu=BigInt(4);function BW(W,X){let{BYTES:G}=W,Y;if(typeof X==="bigint")Y=X;else{let J=f8("private key",X);try{Y=W.fromBytes(J)}catch(Z){throw Error(`invalid private key: expected ui8a of size ${G}, got ${typeof X}`)}}if(!W.isValidNot0(Y))throw Error("invalid private key: out of range [1..N-1]");return Y}function bu(W,X={}){let G=gu("weierstrass",W,X),{Fp:Y,Fn:J}=G,Z=G.CURVE,{h:V,n:U}=Z;Cz(X,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",wrapPrivateKey:"boolean"});let{endo:Q}=X;if(Q){if(!Y.is0(Z.a)||typeof Q.beta!=="bigint"||!Array.isArray(Q.basises))throw Error('invalid endo: expected "beta": bigint and "basises": array')}let N=mT(Y,J);function q(){if(!Y.isOdd)throw Error("compression is not supported: Field does not have .isOdd()")}function A(g,d,P){let{x:E,y:p}=d.toAffine(),r=Y.toBytes(E);if(wQ(P,"isCompressed"),P){q();let o=!Y.isOdd(p);return j7(bT(o),r)}else return j7(Uint8Array.of(4),r,Y.toBytes(p))}function H(g){PW(g,void 0,"Point");let{publicKey:d,publicKeyUncompressed:P}=N,E=g.length,p=g[0],r=g.subarray(1);if(E===d&&(p===2||p===3)){let o=Y.fromBytes(r);if(!Y.isValid(o))throw Error("bad point: is not on curve, wrong x");let B=O(o),S;try{S=Y.sqrt(B)}catch(v){let R=v instanceof Error?": "+v.message:"";throw Error("bad point: is not on curve, sqrt error"+R)}q();let _=Y.isOdd(S);if((p&1)===1!==_)S=Y.neg(S);return{x:o,y:S}}else if(E===P&&p===4){let o=Y.BYTES,B=Y.fromBytes(r.subarray(0,o)),S=Y.fromBytes(r.subarray(o,o*2));if(!T(B,S))throw Error("bad point: is not on curve");return{x:B,y:S}}else throw Error(`bad point: got length ${E}, expected compressed=${d} or uncompressed=${P}`)}let I=X.toBytes||A,w=X.fromBytes||H;function O(g){let d=Y.sqr(g),P=Y.mul(d,g);return Y.add(Y.add(P,Y.mul(g,Z.a)),Z.b)}function T(g,d){let P=Y.sqr(d),E=O(g);return Y.eql(P,E)}if(!T(Z.Gx,Z.Gy))throw Error("bad curve params: generator point");let x=Y.mul(Y.pow(Z.a,GQ),hu),h=Y.mul(Y.sqr(Z.b),BigInt(27));if(Y.is0(Y.add(x,h)))throw Error("bad curve params: a or b");function $(g,d,P=!1){if(!Y.isValid(d)||P&&Y.is0(d))throw Error(`bad point coordinate ${g}`);return d}function F(g){if(!(g instanceof y))throw Error("ProjectivePoint expected")}function u(g){if(!Q||!Q.basises)throw Error("no endo");return uu(g,Q.basises,J.ORDER)}let l=nC((g,d)=>{let{X:P,Y:E,Z:p}=g;if(Y.eql(p,Y.ONE))return{x:P,y:E};let r=g.is0();if(d==null)d=r?Y.ONE:Y.inv(p);let o=Y.mul(P,d),B=Y.mul(E,d),S=Y.mul(p,d);if(r)return{x:Y.ZERO,y:Y.ZERO};if(!Y.eql(S,Y.ONE))throw Error("invZ was invalid");return{x:o,y:B}}),f=nC((g)=>{if(g.is0()){if(X.allowInfinityPoint&&!Y.is0(g.Y))return;throw Error("bad point: ZERO")}let{x:d,y:P}=g.toAffine();if(!Y.isValid(d)||!Y.isValid(P))throw Error("bad point: x or y not field elements");if(!T(d,P))throw Error("bad point: equation left != right");if(!g.isTorsionFree())throw Error("bad point: not in prime-order subgroup");return!0});function s(g,d,P,E,p){return P=new y(Y.mul(P.X,g),P.Y,P.Z),d=jQ(E,d),P=jQ(p,P),d.add(P)}class y{constructor(g,d,P){this.X=$("x",g),this.Y=$("y",d,!0),this.Z=$("z",P),Object.freeze(this)}static CURVE(){return Z}static fromAffine(g){let{x:d,y:P}=g||{};if(!g||!Y.isValid(d)||!Y.isValid(P))throw Error("invalid affine point");if(g instanceof y)throw Error("projective point not allowed");if(Y.is0(d)&&Y.is0(P))return y.ZERO;return new y(d,P,Y.ONE)}static fromBytes(g){let d=y.fromAffine(w(PW(g,void 0,"point")));return d.assertValidity(),d}static fromHex(g){return y.fromBytes(f8("pointHex",g))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(g=8,d=!0){if(H0.createCache(this,g),!d)this.multiply(GQ);return this}assertValidity(){f(this)}hasEvenY(){let{y:g}=this.toAffine();if(!Y.isOdd)throw Error("Field doesn't support isOdd");return!Y.isOdd(g)}equals(g){F(g);let{X:d,Y:P,Z:E}=this,{X:p,Y:r,Z:o}=g,B=Y.eql(Y.mul(d,o),Y.mul(p,E)),S=Y.eql(Y.mul(P,o),Y.mul(r,E));return B&&S}negate(){return new y(this.X,Y.neg(this.Y),this.Z)}double(){let{a:g,b:d}=Z,P=Y.mul(d,GQ),{X:E,Y:p,Z:r}=this,o=Y.ZERO,B=Y.ZERO,S=Y.ZERO,_=Y.mul(E,E),v=Y.mul(p,p),R=Y.mul(r,r),m=Y.mul(E,p);return m=Y.add(m,m),S=Y.mul(E,r),S=Y.add(S,S),o=Y.mul(g,S),B=Y.mul(P,R),B=Y.add(o,B),o=Y.sub(v,B),B=Y.add(v,B),B=Y.mul(o,B),o=Y.mul(m,o),S=Y.mul(P,S),R=Y.mul(g,R),m=Y.sub(_,R),m=Y.mul(g,m),m=Y.add(m,S),S=Y.add(_,_),_=Y.add(S,_),_=Y.add(_,R),_=Y.mul(_,m),B=Y.add(B,_),R=Y.mul(p,r),R=Y.add(R,R),_=Y.mul(R,m),o=Y.sub(o,_),S=Y.mul(R,v),S=Y.add(S,S),S=Y.add(S,S),new y(o,B,S)}add(g){F(g);let{X:d,Y:P,Z:E}=this,{X:p,Y:r,Z:o}=g,B=Y.ZERO,S=Y.ZERO,_=Y.ZERO,v=Z.a,R=Y.mul(Z.b,GQ),m=Y.mul(d,p),J0=Y.mul(P,r),U0=Y.mul(E,o),q0=Y.add(d,P),$0=Y.add(p,r);q0=Y.mul(q0,$0),$0=Y.add(m,J0),q0=Y.sub(q0,$0),$0=Y.add(d,E);let u0=Y.add(p,o);return $0=Y.mul($0,u0),u0=Y.add(m,U0),$0=Y.sub($0,u0),u0=Y.add(P,E),B=Y.add(r,o),u0=Y.mul(u0,B),B=Y.add(J0,U0),u0=Y.sub(u0,B),_=Y.mul(v,$0),B=Y.mul(R,U0),_=Y.add(B,_),B=Y.sub(J0,_),_=Y.add(J0,_),S=Y.mul(B,_),J0=Y.add(m,m),J0=Y.add(J0,m),U0=Y.mul(v,U0),$0=Y.mul(R,$0),J0=Y.add(J0,U0),U0=Y.sub(m,U0),U0=Y.mul(v,U0),$0=Y.add($0,U0),m=Y.mul(J0,$0),S=Y.add(S,m),m=Y.mul(u0,$0),B=Y.mul(q0,B),B=Y.sub(B,m),m=Y.mul(q0,J0),_=Y.mul(u0,_),_=Y.add(_,m),new y(B,S,_)}subtract(g){return this.add(g.negate())}is0(){return this.equals(y.ZERO)}multiply(g){let{endo:d}=X;if(!J.isValidNot0(g))throw Error("invalid scalar: out of range");let P,E,p=(r)=>H0.cached(this,r,(o)=>eA(y,o));if(d){let{k1neg:r,k1:o,k2neg:B,k2:S}=u(g),{p:_,f:v}=p(o),{p:R,f:m}=p(S);E=v.add(m),P=s(d.beta,_,R,r,B)}else{let{p:r,f:o}=p(g);P=r,E=o}return eA(y,[P,E])[0]}multiplyUnsafe(g){let{endo:d}=X,P=this;if(!J.isValid(g))throw Error("invalid scalar: out of range");if(g===J4||P.is0())return y.ZERO;if(g===UG)return P;if(H0.hasCache(this))return this.multiply(g);if(d){let{k1neg:E,k1:p,k2neg:r,k2:o}=u(g),{p1:B,p2:S}=yu(y,P,p,o);return s(d.beta,B,S,E,r)}else return H0.unsafe(P,g)}multiplyAndAddUnsafe(g,d,P){let E=this.multiplyUnsafe(d).add(g.multiplyUnsafe(P));return E.is0()?void 0:E}toAffine(g){return l(this,g)}isTorsionFree(){let{isTorsionFree:g}=X;if(V===UG)return!0;if(g)return g(y,this);return H0.unsafe(this,U).is0()}clearCofactor(){let{clearCofactor:g}=X;if(V===UG)return this;if(g)return g(y,this);return this.multiplyUnsafe(V)}isSmallOrder(){return this.multiplyUnsafe(V).is0()}toBytes(g=!0){return wQ(g,"isCompressed"),this.assertValidity(),I(y,this,g)}toHex(g=!0){return VG(this.toBytes(g))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}get px(){return this.X}get py(){return this.X}get pz(){return this.Z}toRawBytes(g=!0){return this.toBytes(g)}_setWindowSize(g){this.precompute(g)}static normalizeZ(g){return eA(y,g)}static msm(g,d){return vu(y,J,g,d)}static fromPrivateKey(g){return y.BASE.multiply(BW(J,g))}}y.BASE=new y(Z.Gx,Z.Gy,Y.ONE),y.ZERO=new y(Y.ZERO,Y.ONE,Y.ZERO),y.Fp=Y,y.Fn=J;let t=J.BITS,H0=new gT(y,X.endo?Math.ceil(t/2):t);return y.BASE.precompute(8),y}function bT(W){return Uint8Array.of(W?2:3)}function mT(W,X){return{secretKey:X.BYTES,publicKey:1+W.BYTES,publicKeyUncompressed:1+2*W.BYTES,publicKeyHasPrefix:!0,signature:2*X.BYTES}}function mu(W,X={}){let{Fn:G}=W,Y=X.randomBytes||RQ,J=Object.assign(mT(W.Fp,G),{seed:kT(G.ORDER)});function Z(H){try{return!!BW(G,H)}catch(I){return!1}}function V(H,I){let{publicKey:w,publicKeyUncompressed:O}=J;try{let T=H.length;if(I===!0&&T!==w)return!1;if(I===!1&&T!==O)return!1;return!!W.fromBytes(H)}catch(T){return!1}}function U(H=Y(J.seed)){return _T(PW(H,J.seed,"seed"),G.ORDER)}function Q(H,I=!0){return W.BASE.multiply(BW(G,H)).toBytes(I)}function N(H){let I=U(H);return{secretKey:I,publicKey:Q(I)}}function q(H){if(typeof H==="bigint")return!1;if(H instanceof W)return!0;let{secretKey:I,publicKey:w,publicKeyUncompressed:O}=J;if(G.allowedLengths||I===w)return;let T=f8("key",H).length;return T===w||T===O}function A(H,I,w=!0){if(q(H)===!0)throw Error("first arg must be private key");if(q(I)===!1)throw Error("second arg must be public key");let O=BW(G,H);return W.fromHex(I).multiply(O).toBytes(w)}return Object.freeze({getPublicKey:Q,getSharedSecret:A,keygen:N,Point:W,utils:{isValidSecretKey:Z,isValidPublicKey:V,randomSecretKey:U,isValidPrivateKey:Z,randomPrivateKey:U,normPrivateKeyToScalar:(H)=>BW(G,H),precompute(H=8,I=W.BASE){return I.precompute(H,!1)}},lengths:J})}function fu(W,X,G={}){AT(X),Cz(G,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});let Y=G.randomBytes||RQ,J=G.hmac||((P,...E)=>KT(X,P,j7(...E))),{Fp:Z,Fn:V}=W,{ORDER:U,BITS:Q}=V,{keygen:N,getPublicKey:q,getSharedSecret:A,utils:H,lengths:I}=mu(W,G),w={prehash:!1,lowS:typeof G.lowS==="boolean"?G.lowS:!1,format:void 0,extraEntropy:!1},O="compact";function T(P){let E=U>>UG;return P>E}function x(P,E){if(!V.isValidNot0(E))throw Error(`invalid signature ${P}: out of range 1..Point.Fn.ORDER`);return E}function h(P,E){Az(E);let p=I.signature,r=E==="compact"?p:E==="recovered"?p+1:void 0;return PW(P,r,`${E} signature`)}class ${constructor(P,E,p){if(this.r=x("r",P),this.s=x("s",E),p!=null)this.recovery=p;Object.freeze(this)}static fromBytes(P,E=O){h(P,E);let p;if(E==="der"){let{r:S,s:_}=Y4.toSig(PW(P));return new $(S,_)}if(E==="recovered")p=P[0],E="compact",P=P.subarray(1);let r=V.BYTES,o=P.subarray(0,r),B=P.subarray(r,r*2);return new $(V.fromBytes(o),V.fromBytes(B),p)}static fromHex(P,E){return this.fromBytes(IQ(P),E)}addRecoveryBit(P){return new $(this.r,this.s,P)}recoverPublicKey(P){let E=Z.ORDER,{r:p,s:r,recovery:o}=this;if(o==null||![0,1,2,3].includes(o))throw Error("recovery id invalid");if(U*hT<E&&o>1)throw Error("recovery id is ambiguous for h>1 curve");let B=o===2||o===3?p+U:p;if(!Z.isValid(B))throw Error("recovery id 2 or 3 invalid");let S=Z.toBytes(B),_=W.fromBytes(j7(bT((o&1)===0),S)),v=V.inv(B),R=u(f8("msgHash",P)),m=V.create(-R*v),J0=V.create(r*v),U0=W.BASE.multiplyUnsafe(m).add(_.multiplyUnsafe(J0));if(U0.is0())throw Error("point at infinify");return U0.assertValidity(),U0}hasHighS(){return T(this.s)}toBytes(P=O){if(Az(P),P==="der")return IQ(Y4.hexFromSig(this));let E=V.toBytes(this.r),p=V.toBytes(this.s);if(P==="recovered"){if(this.recovery==null)throw Error("recovery bit must be present");return j7(Uint8Array.of(this.recovery),E,p)}return j7(E,p)}toHex(P){return VG(this.toBytes(P))}assertValidity(){}static fromCompact(P){return $.fromBytes(f8("sig",P),"compact")}static fromDER(P){return $.fromBytes(f8("sig",P),"der")}normalizeS(){return this.hasHighS()?new $(this.r,V.neg(this.s),this.recovery):this}toDERRawBytes(){return this.toBytes("der")}toDERHex(){return VG(this.toBytes("der"))}toCompactRawBytes(){return this.toBytes("compact")}toCompactHex(){return VG(this.toBytes("compact"))}}let F=G.bits2int||function(P){if(P.length>8192)throw Error("input is too large");let E=HG(P),p=P.length*8-Q;return p>0?E>>BigInt(p):E},u=G.bits2int_modN||function(P){return V.create(F(P))},l=bJ(Q);function f(P){return Mu("num < 2^"+Q,P,J4,l),V.toBytes(P)}function s(P,E){return PW(P,void 0,"message"),E?PW(X(P),void 0,"prehashed message"):P}function y(P,E,p){if(["recovered","canonical"].some((U0)=>(U0 in p)))throw Error("sign() legacy options not supported");let{lowS:r,prehash:o,extraEntropy:B}=Yz(p,w);P=s(P,o);let S=u(P),_=BW(V,E),v=[f(_),f(S)];if(B!=null&&B!==!1){let U0=B===!0?Y(I.secretKey):B;v.push(f8("extraEntropy",U0))}let R=j7(...v),m=S;function J0(U0){let q0=F(U0);if(!V.isValidNot0(q0))return;let $0=V.inv(q0),u0=W.BASE.multiply(q0).toAffine(),H1=V.create(u0.x);if(H1===J4)return;let v1=V.create($0*V.create(m+H1*_));if(v1===J4)return;let h0=(u0.x===H1?0:2)|Number(u0.y&UG),F1=v1;if(r&&T(v1))F1=V.neg(v1),h0^=1;return new $(H1,F1,h0)}return{seed:R,k2sig:J0}}function t(P,E,p={}){P=f8("message",P);let{seed:r,k2sig:o}=y(P,E,p);return Pu(X.outputLen,V.BYTES,J)(r,o)}function H0(P){let E=void 0,p=typeof P==="string"||PQ(P),r=!p&&P!==null&&typeof P==="object"&&typeof P.r==="bigint"&&typeof P.s==="bigint";if(!p&&!r)throw Error("invalid signature, expected Uint8Array, hex string or Signature instance");if(r)E=new $(P.r,P.s);else if(p){try{E=$.fromBytes(f8("sig",P),"der")}catch(o){if(!(o instanceof Y4.Err))throw o}if(!E)try{E=$.fromBytes(f8("sig",P),"compact")}catch(o){return!1}}if(!E)return!1;return E}function g(P,E,p,r={}){let{lowS:o,prehash:B,format:S}=Yz(r,w);if(p=f8("publicKey",p),E=s(f8("message",E),B),"strict"in r)throw Error("options.strict was renamed to lowS");let _=S===void 0?H0(P):$.fromBytes(f8("sig",P),S);if(_===!1)return!1;try{let v=W.fromBytes(p);if(o&&_.hasHighS())return!1;let{r:R,s:m}=_,J0=u(E),U0=V.inv(m),q0=V.create(J0*U0),$0=V.create(R*U0),u0=W.BASE.multiplyUnsafe(q0).add(v.multiplyUnsafe($0));if(u0.is0())return!1;return V.create(u0.x)===R}catch(v){return!1}}function d(P,E,p={}){let{prehash:r}=Yz(p,w);return E=s(E,r),$.fromBytes(P,"recovered").recoverPublicKey(E).toBytes()}return Object.freeze({keygen:N,getPublicKey:q,getSharedSecret:A,utils:H,lengths:I,Point:W,sign:t,verify:g,recoverPublicKey:d,Signature:$,hash:X})}function pu(W){let X={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,Y=W.allowedPrivateKeyLengths?Array.from(new Set(W.allowedPrivateKeyLengths.map((V)=>Math.ceil(V/2)))):void 0,J=mJ(X.n,{BITS:W.nBitLength,allowedLengths:Y,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:X,curveOpts:Z}}function cu(W){let{CURVE:X,curveOpts:G}=pu(W),Y={hmac:W.hmac,randomBytes:W.randomBytes,lowS:W.lowS,bits2int:W.bits2int,bits2int_modN:W.bits2int_modN};return{CURVE:X,curveOpts:G,hash:W.hash,ecdsaOpts:Y}}function lu(W,X){let G=X.Point;return Object.assign({},X,{ProjectivePoint:G,CURVE:Object.assign({},W,ST(G.Fn.ORDER,G.Fn.BITS))})}function du(W){let{CURVE:X,curveOpts:G,hash:Y,ecdsaOpts:J}=cu(W),Z=bu(X,G),V=fu(Z,Y,J);return lu(W,V)}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */function ou(W,X){let G=(Y)=>du({...W,hash:Y});return{...G(X),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")},nu={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]},iu=BigInt(0),WT=BigInt(1),zz=BigInt(2);function ru(W){let X=qG.p,G=BigInt(3),Y=BigInt(6),J=BigInt(11),Z=BigInt(22),V=BigInt(23),U=BigInt(44),Q=BigInt(88),N=W*W*W%X,q=N*N*W%X,A=D5(q,G,X)*q%X,H=D5(A,G,X)*q%X,I=D5(H,zz,X)*N%X,w=D5(I,J,X)*I%X,O=D5(w,Z,X)*w%X,T=D5(O,U,X)*O%X,x=D5(T,Q,X)*T%X,h=D5(x,U,X)*O%X,$=D5(h,G,X)*q%X,F=D5($,V,X)*w%X,u=D5(F,Y,X)*N%X,l=D5(u,zz,X);if(!KQ.eql(KQ.sqr(l),W))throw Error("Cannot find square root");return l}var KQ=mJ(qG.p,{sqrt:ru}),fT=ou({...qG,Fp:KQ,lowS:!0,endo:nu},Nz),XT={};function OQ(W,...X){let G=XT[W];if(G===void 0){let Y=Nz(IT(W));G=j7(Y,Y),XT[W]=G}return Nz(j7(G,...X))}var Mz=(W)=>W.toBytes(!0).slice(1),AG=(()=>fT.Point)(),Pz=(W)=>W%zz===iu;function Iz(W){let{Fn:X,BASE:G}=AG,Y=BW(X,W),J=G.multiply(Y);return{scalar:Pz(J.y)?Y:X.neg(Y),bytes:Mz(J)}}function pT(W){let X=KQ;if(!X.isValidNot0(W))throw Error("invalid x: Fail if x \u2265 p");let G=X.create(W*W),Y=X.create(G*W+BigInt(7)),J=X.sqrt(Y);if(!Pz(J))J=X.neg(J);let Z=AG.fromAffine({x:W,y:J});return Z.assertValidity(),Z}var uJ=HG;function cT(...W){return AG.Fn.create(uJ(OQ("BIP0340/challenge",...W)))}function GT(W){return Iz(W).bytes}function au(W,X,G=RQ(32)){let{Fn:Y}=AG,J=f8("message",W),{bytes:Z,scalar:V}=Iz(X),U=f8("auxRand",G,32),Q=Y.toBytes(V^uJ(OQ("BIP0340/aux",U))),N=OQ("BIP0340/nonce",Q,Z,J),{bytes:q,scalar:A}=Iz(N),H=cT(q,Z,J),I=new Uint8Array(64);if(I.set(q,0),I.set(Y.toBytes(Y.create(A+H*V)),32),!lT(I,J,Z))throw Error("sign: Invalid signature produced");return I}function lT(W,X,G){let{Fn:Y,BASE:J}=AG,Z=f8("signature",W,64),V=f8("message",X),U=f8("publicKey",G,32);try{let Q=pT(uJ(U)),N=uJ(Z.subarray(0,32));if(!Hz(N,WT,qG.p))return!1;let q=uJ(Z.subarray(32,64));if(!Hz(q,WT,qG.n))return!1;let A=cT(Y.toBytes(N),Mz(Q),V),H=J.multiplyUnsafe(q).add(Q.multiplyUnsafe(Y.neg(A))),{x:I,y:w}=H.toAffine();if(H.is0()||!Pz(w)||I!==N)return!1;return!0}catch(Q){return!1}}var Rz=(()=>{let W=(G=RQ(48))=>{return _T(G,qG.n)};fT.utils.randomSecretKey;function X(G){let Y=W(G);return{secretKey:Y,publicKey:GT(Y)}}return{keygen:X,getPublicKey:GT,sign:au,verify:lT,Point:AG,utils:{randomSecretKey:W,randomPrivateKey:W,taggedHash:OQ,lift_x:pT,pointToBytes:Mz,numberToBytesBE:LQ,bytesToNumberBE:HG,mod:T5},lengths:{secretKey:32,publicKey:32,publicKeyHasPrefix:!1,signature:64,seed:48}}})(),su=new TextEncoder,tu=new TextDecoder,Z4=(W)=>su.encode(W),_J=(W)=>tu.decode(W),wz=(W)=>Array.from(W,(X)=>X.toString(16).padStart(2,"0")).join(""),K7=JSON.stringify,DQ=JSON.parse,eu=(W,X=Number.MAX_SAFE_INTEGER)=>W.split("").reduce((G,Y)=>G+Y.charCodeAt(0),0)%X,CQ="AES-GCM",Wh={},dT="$",oT=",",Xh=(W)=>{let X=new Uint8Array(W),G=32768,Y="";for(let J=0;J<X.length;J+=32768)Y+=String.fromCharCode(...X.subarray(J,J+32768));return btoa(Y)},Gh=(W)=>Uint8Array.from(atob(W),(X)=>X.charCodeAt(0)).buffer,YQ=(W)=>Wh[W]??=crypto.subtle.digest("SHA-1",Z4(W)).then((X)=>{let G=new Uint8Array(X),Y="";for(let J of G)Y+=J.toString(36);return Y}),Yh=async(W,X,G)=>{if(!W){let J=await crypto.subtle.digest("SHA-256",Z4(`:${X}:${G}`));return crypto.subtle.importKey("raw",J,{name:CQ},!1,["encrypt","decrypt"])}let Y=await crypto.subtle.importKey("raw",Z4(W),"PBKDF2",!1,["deriveKey"]);return crypto.subtle.deriveKey({name:"PBKDF2",salt:Z4(`${X}:${G}`),iterations:1e5,hash:"SHA-256"},Y,{name:CQ,length:256},!1,["encrypt","decrypt"])},Jh=async(W,X)=>{let G=crypto.getRandomValues(new Uint8Array(12)),Y=await W,J=await crypto.subtle.encrypt({name:CQ,iv:G},Y,Z4(X));return`${G.join(oT)}${dT}${Xh(J)}`},Zh=async(W,X)=>{let[G,Y]=X.split(dT);if(!G||!Y)throw Error("Invalid encrypted payload format");let J=Uint8Array.from(G.split(oT),Number),Z=await W,V=await crypto.subtle.decrypt({name:CQ,iv:J},Z,Gh(Y));return _J(V)},C5="GenosRTC",BQ=(W,X)=>Array.from({length:W},X),TQ=(W)=>Array.from(crypto.getRandomValues(new Uint8Array(W)),(X)=>"0123456789AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz"[X%62]).join(""),w8=typeof sessionStorage<"u"?sessionStorage.__genosrtcId??=TQ(20):TQ(20),ZG=Promise.all.bind(Promise),Vh=typeof window<"u",{entries:Uh,fromEntries:nT,keys:ne}=Object,YT=()=>{},h5=(W)=>Error(`GenosRTC: ${W}`),JQ=(...W)=>W.join("@"),Qh=5000,JT="icegatheringstatechange",ZT="offer",Nh="answer",qh=[...BQ(3,(W,X)=>`stun:stun${X||""}.l.google.com:19302`),"stun:stun.cloudflare.com:3478"].map((W)=>({urls:W})),VT=(W,{rtcConfig:X,rtcPolyfill:G,turnConfig:Y})=>{let J=new(G||RTCPeerConnection)({iceServers:[...qh,...Y||[]],...X}),Z={},V=!1,U=!1,Q,N=(H)=>Object.assign(H,{binaryType:"arraybuffer",bufferedAmountLowThreshold:65535,onmessage:(I)=>Z.data?.(I.data),onopen:()=>Z.connect?.(),onclose:()=>Z.close?.(),onerror:(I)=>!I?.error?.message?.includes("User-Initiated Abort")&&Z.error?.(I)}),q=()=>Promise.race([new Promise((H)=>{let I=()=>{if(J.iceGatheringState==="complete")J.removeEventListener(JT,I),H()};J.addEventListener(JT,I),I()}),new Promise((H)=>setTimeout(H,Qh))]).then(()=>({type:J.localDescription.type,sdp:J.localDescription.sdp.replace(/a=ice-options:trickle\s\n/g,"")}));if(W?N(Q=J.createDataChannel("data")):J.ondatachannel=({channel:H})=>N(Q=H),J.onnegotiationneeded=async()=>{try{V=!0,await J.setLocalDescription(),Z.signal?.(await q())}catch(H){Z.error?.(H)}finally{V=!1}},J.onconnectionstatechange=()=>{if(["disconnected","failed","closed"].includes(J.connectionState))Z.close?.()},J.ontrack=(H)=>{Z.track?.(H.track,H.streams[0]),Z.stream?.(H.streams[0])},J.onremovestream=(H)=>Z.stream?.(H.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(H){if(Q?.readyState==="open"&&!H.sdp?.includes("a=rtpmap"))return;try{if(H.type===ZT){if(V||J.signalingState!=="stable"&&!U){if(W)return;await ZG([J.setLocalDescription({type:"rollback"}),J.setRemoteDescription(H)])}else await J.setRemoteDescription(H);await J.setLocalDescription();let I=await q();return Z.signal?.(I),I}if(H.type===Nh){U=!0;try{await J.setRemoteDescription(H)}finally{U=!1}}}catch(I){Z.error?.(I)}},sendData:(H)=>{if(Q?.readyState!=="open")return!1;return Q.send(H),!0},destroy:()=>{Q?.close(),J.close(),V=U=!1},setHandlers:(H)=>Object.assign(Z,H),offerPromise:W?new Promise((H)=>Z.signal=(I)=>I.type===ZT&&H(I)):Promise.resolve(),addStream:(H)=>H.getTracks().forEach((I)=>J.addTrack(I,H)),removeStream:(H)=>A().filter((I)=>H.getTracks().includes(I.track)).forEach((I)=>J.removeTrack(I)),addTrack:(H,I)=>J.addTrack(H,I),removeTrack:(H)=>{let I=A().find((w)=>w.track===H);if(I)J.removeTrack(I)},replaceTrack:(H,I)=>A().find((w)=>w.track===H)?.replaceTrack(I)}},Hh=Object.getPrototypeOf(Uint8Array),QQ=12,iT=0,NQ=iT+QQ,qQ=NQ+1,yJ=qQ+1,vJ=yJ+1,xJ=16384-vJ,ZQ=255,Jz="bufferedamountlow",JG=(W)=>`@_${W}`,UT=JG("ping"),Zz=100,Ah=3,zh=200,Ih=512,wh=33554432,QT=async(W,X,G=1/0)=>{let Y=new Blob([W]).stream().pipeThrough(new X("deflate")).getReader(),J=[],Z=0;for(let Q=await Y.read();!Q.done;Q=await Y.read()){if((Z+=Q.value.byteLength)>G)throw Y.cancel(),h5(`inflated payload exceeds ${G} bytes`);J.push(Q.value)}let V=new Uint8Array(Z),U=0;for(let Q of J)V.set(Q,U),U+=Q.byteLength;return V},jh=(W,X,G,Y,J)=>{let Z=new Map,V=new Map,U=new Map,Q={},N={},q={},A={},H=new Map,I=new Map,w=Promise.resolve(),O=(R,m)=>{if(!H.has(R))H.set(R,new Set);H.get(R).add(m)},T=(R,m)=>H.get(R)?.delete(m),x=(R,...m)=>H.get(R)?.forEach((J0)=>J0(...m)),h=(R,m)=>{let J0=R?Array.isArray(R)?R:[R]:Z.keys();return Array.from(J0,(U0)=>{let q0=Z.get(U0);if(!q0)return _9.warn(`${C5}: no peer with id ${U0}`),null;return m(U0,q0)}).filter(Boolean)},$=(R)=>{if(!Z.has(R))return;Z.delete(R),I.delete(R),_.delete(R),delete Q[R],delete N[R],delete q[R],delete A[R],x("peer:leave",R),X(R)},F=(R)=>new Promise((m,J0)=>{let U0=setTimeout(()=>{R.removeEventListener(Jz,q0),J0(Error(`${C5}: bufferLow timeout`))},5000);function q0(){clearTimeout(U0),R.removeEventListener(Jz,q0),m()}R.addEventListener(Jz,q0)}),u=(R)=>{if(U.has(R))return U.get(R);if(!R)throw h5("action type is required");let m=Z4(R);if(m.byteLength>QQ)throw h5(`\u274C "${R}" exceeds ${QQ} bytes. Use a shorter name.`);let J0=new Uint8Array(QQ).map((h0,F1)=>m[F1]||0),U0=0,q0=new Map([["message",new Set],["progress",new Set]]),$0=(h0,F1)=>q0.get(h0)?.add(F1),u0=(h0,F1)=>q0.get(h0)?.delete(F1),H1=async(h0,F1,S1,N0)=>{if(S1&&typeof S1!=="object")throw h5("meta must be object");if(h0===void 0)throw h5("data cannot be undefined");let F0=h0 instanceof Blob,m0=F0||h0 instanceof ArrayBuffer||h0 instanceof Hh,Y0=typeof h0!=="string";if(S1&&!m0)throw h5("meta only allowed with binary");let K0=m0?new Uint8Array(F0?await h0.arrayBuffer():h0):Z4(Y0?K7(h0):h0),P0=0;if(!m0&&K0.byteLength>=Ih){let X0=await QT(K0,CompressionStream);if(X0.byteLength<K0.byteLength)K0=X0,P0=1}let k0=S1?Z4(K7(S1)):null,R1=Math.ceil(K0.byteLength/xJ)+(S1?1:0)||1;if(R1>Zz)throw h5(`Message too large, exceeds max chunks ${Zz}`);let Q1=BQ(R1,(X0,C0)=>{let x0=C0===R1-1,k1=S1&&C0===0,W8=k1?k0:K0.subarray(S1?(C0-1)*xJ:C0*xJ,S1?C0*xJ:(C0+1)*xJ),d1=new Uint8Array(vJ+W8.byteLength);return d1.set(J0),d1.set([U0],NQ),d1.set([x0|k1<<1|m0<<2|Y0<<3|P0<<4],qQ),d1.set([Math.round((C0+1)/R1*ZQ)],yJ),d1.set(W8,vJ),d1});return U0=U0+1&ZQ,ZG(h(F1,async(X0,C0)=>{let{channel:x0}=C0;for(let k1=0;k1<R1;k1++){let W8=0;while(x0.bufferedAmount>x0.bufferedAmountLowThreshold){if(W8++>Ah)throw h5(`${C5}: send buffer full, max retries reached for peer ${X0}`);try{await F(x0)}catch(d1){_9.warn(d1.message),await new Promise((N1)=>setTimeout(N1,zh))}}if(!Z.has(X0))break;if(!C0.sendData(Q1[k1]))throw h5(`channel not open for peer ${X0}`);N0?.(Q1[k1][yJ]/ZQ,X0,S1)}}))};V.set(R,{listeners:q0,send:H1});let v1={send:H1,on:$0,off:u0};return U.set(R,v1),v1},l=(R,m)=>{try{I.set(R,Date.now()),_.delete(R);let J0=new Uint8Array(m),U0=_J(J0.subarray(iT,NQ)).replace(/\x00/g,"");if(!V.has(U0))return _9.warn(`${C5}: unregistered type (${U0})`);if(U0===UT){y("",R).catch(()=>{});return}let[q0]=J0.subarray(NQ,qQ),[$0]=J0.subarray(qQ,yJ),[u0]=J0.subarray(yJ,vJ),H1=J0.subarray(vJ),v1=Boolean($0&1),h0=Boolean($0&2),F1=Boolean($0&4),S1=Boolean($0&8),N0=Boolean($0&16),F0=V.get(U0),m0=(Q[R]||={})[U0]||={};if(m0[q0]?.chunks?.length>Zz){_9.warn(`${C5}: peer ${R} sent too many chunks for nonce ${q0}, ignoring.`);return}let Y0=m0[q0]||={chunks:[]};if(h0)try{Y0.meta=DQ(_J(H1))}catch{_9.warn(`${C5}: failed to parse meta from peer ${R} for type ${U0}`);return}else Y0.chunks.push(H1);if(F0.listeners.get("progress").forEach((P0)=>{try{P0(u0/ZQ,R,Y0.meta)}catch(k0){console.error(k0)}}),!v1)return;let K0=new Uint8Array(Y0.chunks.reduce((P0,k0)=>P0+k0.byteLength,0));Y0.chunks.reduce((P0,k0)=>(K0.set(k0,P0),P0+k0.byteLength),0),delete m0[q0],w=w.then(async()=>{let P0=N0?await QT(K0,DecompressionStream,wh):K0,k0;if(F1)k0=P0;else if(S1)try{k0=DQ(_J(P0))}catch{_9.warn(`${C5}: failed to parse JSON message data from peer ${R} for type ${U0}`);return}else k0=_J(P0);F0.listeners.get("message").forEach((R1)=>{try{R1(k0,R,Y0.meta)}catch(Q1){console.error(Q1)}})}).catch((P0)=>console.error(`${C5}: dispatch error from peer ${R}:`,P0))}catch(J0){_9.error(`${C5}: error handling data from peer ${R}:`,J0)}},f=async()=>{try{await r(""),await new Promise((R)=>setTimeout(R,99))}catch(R){_9.warn(`${C5}: error sending leave`,R)}for(let[R,m]of Z){try{m.destroy()}catch{}Z.delete(R)}clearInterval(v),G()},{send:s}=u(UT),{send:y,on:t}=u(JG("pong")),{send:H0,on:g}=u(JG("signal")),{send:d,on:P}=u(JG("stream")),{send:E,on:p}=u(JG("track")),{send:r,on:o}=u(JG("leave"));W((R,m)=>{let J0=Z.get(m);if(J0===R)return;if(J0){let U0=()=>{};J0.setHandlers({data:U0,stream:U0,track:U0,signal:U0,close:U0,error:U0})}Z.set(m,R),I.set(m,Date.now()),_.delete(m),R.setHandlers({data:(U0)=>l(m,U0),stream:(U0)=>{x("stream:add",U0,m,q[m]),delete q[m]},track:(U0,q0)=>{x("track:add",U0,q0,m,A[m]),delete A[m]},signal:(U0)=>H0(U0,m),close:()=>$(m),error:(U0)=>{_9.error(`${C5}: peer error for ${m}`,U0),$(m)}}),x("peer:join",m,Y?.(m))}),J?.((R,m,J0)=>x(J0?"peer:seen":"peer:lost",R,m)),t("message",(R,m)=>{N[m]?.(),delete N[m]}),g("message",(R,m)=>Z.get(m)?.signal(R)),P("message",(R,m)=>q[m]=R),p("message",(R,m)=>A[m]=R),o("message",(R,m)=>$(m));let B=1e4,S=20000,_=new Map,v=setInterval(()=>{let R=Date.now();for(let[m,J0]of Z){if(R-(I.get(m)??R)<=B)continue;let U0=_.get(m);if(U0===void 0)_.set(m,R),s("",m).catch(()=>{});else if(R-U0>S){_.delete(m);try{J0.destroy()}catch{}$(m)}}},5000);if(Vh)addEventListener("beforeunload",f);return{on:O,off:T,channel:u,leave:f,ping:async(R)=>{if(!R)throw h5("ping() requires target peer ID");let m=Date.now();return s("",R),await new Promise((J0)=>N[R]=J0),Date.now()-m},getPeers:()=>nT(Array.from(Z,([R,m])=>[R,m.connection])),addStream:(R,m,J0)=>h(m,async(U0,q0)=>{if(J0)await d(J0,U0);q0.addStream(R)}),removeStream:(R,m)=>h(m,(J0,U0)=>U0.removeStream(R)),addTrack:(R,m,J0,U0)=>h(J0,async(q0,$0)=>{if(U0)await E(U0,q0);$0.addTrack(R,m)}),removeTrack:(R,m)=>h(m,(J0,U0)=>U0.removeTrack(R)),replaceTrack:(R,m,J0,U0)=>h(J0,async(q0,$0)=>{if(U0)await E(U0,q0);$0.replaceTrack(R,m)})}},Kh=5,Oh=10,Dh=2500,VQ=57333,Ch=({init:W,subscribe:X,announce:G,bye:Y})=>{let J={},Z=!1,V,U;return(Q,N,q)=>{let{appId:A}=Q;if(J[A]?.[N])return J[A][N];if(!Q||!N||!A&&!Q.firebaseApp)throw h5(!Q?"config required":!N?"roomId required":"appId missing");let H=YT,I=YT;if(!Z){let _=W(Q);U=BQ(Kh,()=>{try{return VT(!0,Q)}catch{return null}}).filter(Boolean),V=Array.isArray(_)?_:[_];let v=setInterval(()=>{U=U.filter((R)=>{let m=Date.now()-R.created<VQ;if(!m)R.destroy();return m})},VQ);J.offerCleanupTimer||=v,Z=!0}let w={},O={},T=new Map,x=new Map,h=new Map,$={},F=JQ(C5,A,N),u=YQ(F),l=YQ(JQ(F,w8)),f=Yh(Q.password||"",A,N),s=(_)=>async(v)=>({type:v.type,sdp:await _(f,v.sdp)}),y=s(Zh),t=s(Jh),H0=(_)=>{return setTimeout(()=>{if(!_.isDead&&!Object.values(O).includes(_))_.destroy()},VQ),_},g=(_)=>{try{return H0(VT(_,Q))}catch{return null}},d=(_,v)=>{if(O[v]===_)return;_.connectedAt=Date.now(),O[v]?.destroy(),O[v]=_,H(_,v),w[v]?.forEach((R)=>R!==_&&R.destroy()),delete w[v]},P=(_,v)=>{if(O[v]===_)delete O[v]},E=(_)=>async(v,R,m)=>{let[J0,U0]=await ZG([u,l]);if(v!==J0&&v!==U0)return;let{peerId:q0,offer:$0,answer:u0,type:H1,bye:v1}=typeof R==="string"?DQ(R):R;if(v1){if(q0&&q0!==w8)x.delete(q0),I(q0,null,!1),h.set(q0,Date.now()),delete $[q0];return}if(q0&&q0!==w8)I(q0,H1,!0),x.set(q0,Date.now()),h.delete(q0);if(H1&&q0)$[q0]=H1;if(q0===w8)return;if(O[q0]){let h0=O[q0].channel?.readyState==="open";if(!$0||h0||Date.now()-O[q0].connectedAt<2000)return;O[q0].destroy(),delete O[q0]}if(Q.admit&&!Q.admit(q0))return;if($0){if(w[q0]?.[_]&&w8>q0)return;let h0=g(!1);if(!h0)return;h0.setHandlers({connect:()=>d(h0,q0),close:()=>P(h0,q0)});try{let F1=await y($0);if(h0.isDead)return;let[S1,N0]=await ZG([YQ(JQ(F,q0)),h0.signal(F1).then(t)]);m(S1,K7({peerId:w8,answer:N0,...Q.type&&{type:Q.type}}))}catch{q?.({error:"decryption failed (offer)",appId:A,peerId:q0,roomId:N})}}else if(u0){let h0=w[q0]?.[_];if(!h0||h0.isDead)return;h0.setHandlers({connect:()=>d(h0,q0),close:()=>P(h0,q0)});try{h0.signal(await y(u0))}catch{q?.({error:"decryption failed (answer)",appId:A,peerId:q0,roomId:N})}}else{let h0=w[q0]||=[];if(h0.forEach((N0,F0)=>{if(N0&&(N0.isDead||Date.now()-(N0.dialedAt??N0.created)>VQ)){if(N0.isDead)T.set(q0,Date.now()+30000);N0.destroy(),delete h0[F0]}}),h0[_]||h0.filter(Boolean).length>=2||T.get(q0)>Date.now())return;if(Object.values(w).reduce((N0,F0)=>N0+F0.filter((m0)=>m0&&!m0.isDead).length,0)>=Oh)return;let F1=U.pop(),S1=F1?H0(F1):g(!0);if(!S1){T.set(q0,Date.now()+30000);return}S1.dialedAt=Date.now(),h0[_]=S1;try{let[N0,{offer:F0}]=await ZG([YQ(JQ(F,q0)),S1.offerPromise.then(t).then((m0)=>({offer:m0}))]);S1.setHandlers({connect:()=>d(S1,q0),close:()=>P(S1,q0)}),m(N0,K7({peerId:w8,offer:F0,...Q.type&&{type:Q.type}}))}catch{if(h0[_]===S1)delete h0[_];S1.destroy()}}},p=[],r=[],o=[],B=()=>o.forEach(({relay:_,rootTopic:v})=>Y?.(_,v));V.forEach(async(_,v)=>{let R=await _;if(!R)return;let[m,J0]=await ZG([u,l]);r[v]=X(R,m,J0,E(v)),o.push({relay:R,rootTopic:m});let U0=async()=>{let q0=await G(R,m,J0);p[v]=setTimeout(U0,typeof q0==="number"?q0:Dh)};U0()}),J[A]||={};let S=jh((_)=>H=_,(_)=>delete O[_],()=>S.onCleanup?.(),(_)=>$[_],(_)=>I=_);if(typeof window<"u")window.addEventListener("pagehide",B);return S.onCleanup=()=>{if(B(),typeof window<"u")window.removeEventListener("pagehide",B);if(delete J[A][N],p.forEach(clearTimeout),r.forEach((_)=>_?.()),Object.keys(J).length===0)clearInterval(J.offerCleanupTimer),delete J.offerCleanupTimer},S._census=()=>{for(let v of Object.keys(O))x.set(v,Date.now());let _=Date.now()-120000;for(let[v,R]of x)if(R<_)x.delete(v);return[...x.keys()]},S._gone=()=>{let _=Date.now()-60000;for(let[v,R]of h)if(R<_)h.delete(v);return[...h.keys()]},J[A][N]=S}},NT=3333,Th=30000,kJ={},rT={},Mh=(W,X)=>{let G={},Y=null;G.reopenHandlers=new Set;let J=()=>{if(Y)clearTimeout(Y),Y=null;if(G.socket)G.socket.onclose=null,G.socket.close();let Z=new WebSocket(W);Z.onclose=()=>{kJ[W]??=NT,Y=setTimeout(J,kJ[W]),kJ[W]=Math.min(kJ[W]*2,Th)},Z.onmessage=(V)=>X(V.data),G.socket=Z,G.url=Z.url,G.ready=new Promise((V)=>{Z.onopen=()=>{kJ[W]=NT,V(G),G.reopenHandlers.forEach((U)=>U())}}),G.send=(V)=>{if(Z.readyState===1)Z.send(V)}};return G.forceReconnect=J,J(),rT[W]=G,G};if(typeof window<"u"){let W=(X)=>{_9.info("\u26A1 [GenosRTC] Network event detected. Forcing reconnection\u2026"),Object.values(rT).forEach((G)=>{if(G.socket&&G.socket.readyState!==WebSocket.OPEN&&(X||G.socket.readyState!==WebSocket.CONNECTING))G.forceReconnect()})};window.addEventListener("online",()=>{_9.info("\u2705 Reconnected to the network."),W(!0)}),window.addEventListener("offline",async()=>{_9.info("\u274C Disconnected from the network.")}),document.addEventListener("visibilitychange",()=>{if(document.visibilityState==="visible")W()})}var Ph=(W)=>()=>nT(Uh(W).map(([X,G])=>[X,G.socket])),QG={},Rh=10,aT="x",sT="EVENT",Lh=/pow:\s*(\d+)\s*bits needed\.?/i,HQ=new Set,tT=Rz.utils.randomSecretKey(),Bh=wz(Rz.getPublicKey(tT)),Lz={},gJ={},Eh={},eT=()=>Math.floor(Date.now()/1000),WM=(W)=>Eh[W]??=eu(W,1e4)+20000,hJ=(W)=>W.replace(/\/$/,""),$h="https://cdn.jsdelivr.net/gh/estebanrfp/gdb@main/relays.json",XM=(W)=>Array.isArray(W)?[...new Set(W.filter((X)=>X?.startsWith?.("wss://")))]:[],GM="genosrtc_relays",Fh=()=>{try{return XM(JSON.parse(globalThis.localStorage?.getItem(GM)))}catch{return[]}},Sh=()=>fetch(`${$h}?r=${Math.random().toString(36).slice(2)}`,{signal:AbortSignal.timeout(5000)}).then((W)=>W.json()).then(XM).then((W)=>(W.length&&globalThis.localStorage?.setItem(GM,JSON.stringify(W)),W)).catch(()=>[]).then((W)=>(W=W.length?W:Fh(),W.length||_9.warn("\u26A0\uFE0F [GenosRTC] Relay list unreachable - Pass rtc.relayUrls to override."),W)),xh=(W,X)=>{let[G,Y,J,Z]=DQ(X);if(G===sT)return gJ[Y]?.(Lz[Y],J.content);if(G==="NOTICE"||G==="OK"&&!J){if(+((G==="NOTICE"?Y:Z).match(Lh)?.[1]??0)>0){let V=hJ(W);HQ.add(V),QG[V]?.close?.(),delete QG[V]}}},kh=(W)=>{let X=hJ(W);if(QG[X])return QG[X];let G=Mh(X,(Y)=>xh(X,Y));return QG[X]=G},Vz=async(W,X)=>{let G={kind:WM(W),content:X,pubkey:Bh,created_at:eT(),tags:[[aT,W]]},Y=Z4(K7([0,G.pubkey,G.created_at,G.kind,G.tags,G.content])),J=new Uint8Array(await crypto.subtle.digest("SHA-256",Y)),Z=Rz.sign(J,tT);return K7([sT,{...G,id:wz(J),sig:wz(Z)}])},qT=(W,X)=>{return Lz[W]=X,K7(["REQ",W,{kinds:[WM(X)],since:eT(),["#"+aT]:[X]}])},HT=(W)=>{return delete Lz[W],K7(["CLOSE",W])},YM=Ch({init:(W)=>{let X=W?.relayUrls?.length?W.relayUrls:null,G=X?Promise.resolve(X):Sh(),Y=X?.length??W.relayRedundancy??Rh;return BQ(Y,(J,Z)=>G.then((V)=>{let U=V[Z]&&kh(V[Z]);return U?U.ready.then(()=>U).catch(()=>null):null}))},subscribe:(W,X,G,Y)=>{let J=TQ(64),Z=TQ(64);gJ[J]=gJ[Z]=(U,Q)=>Y(U,Q,async(N,q)=>{if(HQ.has(hJ(W.url)))return;W.send(await Vz(N,q))});let V=()=>{W.send(qT(J,X)),W.send(qT(Z,G))};return V(),W.reopenHandlers.add(V),()=>{W.reopenHandlers.delete(V),W.send(HT(J)),W.send(HT(Z)),delete gJ[J],delete gJ[Z]}},announce:async(W,X)=>{if(HQ.has(hJ(W.url)))return;W.send(await Vz(X,K7({peerId:w8})))},bye:async(W,X)=>{if(HQ.has(hJ(W.url)))return;W.send(await Vz(X,K7({peerId:w8,bye:1})))}}),ie=Ph(QG),_h={cellSize:10},yh=5000,vh=3000,gh=2000,uh=2000,hh=1e4,bh=30000,mh=5000,fh=30000,MQ=(W)=>{let X=String(W||"").match(/cell-(\d+)/);return X?Number(X[1]):null},Uz=(W,X)=>{let G=MQ(W);if(G==null)return[];let Y=[];for(let J=1;J<X;J*=2){if(G-J>=0)Y.push(`cell-${G-J}`);if(G+J<X)Y.push(`cell-${G+J}`)}return Y},UQ=(W)=>`c${(MQ(W)||0).toString(36)}`,ph=10,ch=(W,X)=>{let G=+X.cellSize>=2?X.cellSize|0:ph;return Math.max(1,Math.ceil(W/G))},JM=(W)=>{let X=0;for(let G=0;G<W.length;G++)X=Math.imul(X^W.charCodeAt(G),2654435761);return X>>>0},z6=(W,X)=>{let G=0,Y=-1;for(let J=0;J<X;J++){let Z=JM(`${W}:${J}`);if(Z>Y)Y=Z,G=J}return G};function lh(W,X={},G={}){let Y={..._h,...X},J=1,Z={epoch:0,roster:[w8],set:new Set([w8]),key:w8,C:1,cellId:null,isBridge:!1,bridges:[],edgeBridges:[]},V={cellId:null},U=0,Q=0,N="",q=0,A=0,H=0,I=null,w=null,O=null,T=new Map,x=new Set,h=new Map,$=new Set,F=0,u=new Set,l=new Map,f=()=>Math.min(150,Math.ceil(Math.log2(Z.C+1))*2+3),s=(N0)=>Uz(N0,Z.C),y=W.on?.bind(W),t=W.off?.bind(W);if(y)W.on=(N0,F0)=>String(N0).startsWith("mesh:")?d(N0,F0):y(N0,F0);if(t)W.off=(N0,F0)=>String(N0).startsWith("mesh:")?h.get(N0)?.delete(F0):t(N0,F0);let H0=(N0)=>(x.add(N0),()=>x.delete(N0)),g=(N0,F0)=>{for(let m0 of x)try{m0(N0,F0)}catch(Y0){_9.error("\uD83D\uDD78\uFE0F [Cells] Error in deliver handler:",Y0)}},d=(N0,F0)=>{if(!h.has(N0))h.set(N0,new Set);return h.get(N0).add(F0),()=>h.get(N0)?.delete(F0)},P=(N0,...F0)=>{let m0=h.get(N0);if(m0)for(let Y0 of m0)try{Y0(...F0)}catch{}},E=(N0)=>{try{return typeof N0==="string"?JSON.parse(N0):N0}catch{return null}},p=()=>`${w8}:${Date.now().toString(36)}:${(F++&65535).toString(36)}`,r=()=>{if($.size>yh)$.delete($.values().next().value)},o=()=>[...new Set([...W._census(),w8])].sort(),B=(N0,F0,m0)=>F0.filter((Y0)=>z6(Y0,m0)===N0),S=(N0,F0,m0)=>{if(N0==null)return null;let Y0=(k0)=>JM(`${k0}@${N0}`),K0=null,P0=-1;for(let k0 of B(N0,F0,m0)){let R1=Y0(k0);if(R1>P0)P0=R1,K0=k0}return K0},_=(N0)=>{let F0=Z.audience?.get(N0);if(!F0)return[];return Object.keys(W.getPeers?.()||{}).filter((m0)=>F0.has(m0))},v=(N0,F0)=>{if(N0!==w&&!(Z.isBridge&&Z.bridges.some((x0)=>UQ(x0)===N0)))return;let m0=E(F0);if(!m0?.id||!m0?.t)return;if($.has(m0.id))return;$.add(m0.id),r();let{t:Y0,id:K0,ttl:P0,data:k0,origin:R1,originCell:Q1}=m0,X0=Z.cellId;if(Y0==="ping"&&k0?.pingId&&k0.target===w8&&R1!==w8){let x0={t:"pong",id:p(),ttl:f(),data:{pingId:k0.pingId,receivedAt:Date.now()},origin:w8,originCell:X0},k1=W.getPeers?.()?.[R1]?[R1]:_(X0);I?.send(JSON.stringify(x0),k1)}if(Y0==="pong"&&k0?.pingId){let x0=l.get(k0.pingId);if(x0)clearTimeout(x0.timeout),x0.resolve(Date.now()-x0.start),l.delete(k0.pingId)}if(Y0==="msg"&&R1!==w8)g(k0,R1);if(!Z.isBridge)return;if((P0??0)<=0)return;let C0=(x0,k1,W8=null)=>{if(!x0||!k1.length)return;let d1={t:Y0,id:K0,ttl:W8??(P0??f())-1,data:k0,origin:R1||w8,originCell:Q1||X0};x0.send(JSON.stringify(d1),k1)};if(N0===w){for(let x0 of s(X0))C0(R(x0),_(x0));return}C0(I,_(X0));for(let x0 of s(X0))if(UQ(x0)!==N0)C0(R(x0),_(x0))},R=(N0)=>{let F0=UQ(N0),m0=W.channel(F0);if(!u.has(F0))u.add(F0),m0.on("message",(Y0)=>v(F0,Y0));return m0},m=()=>{if(!Z.cellId)return;if(w=UQ(Z.cellId),I=W.channel(w),!u.has(w))u.add(w),I.on("message",(N0)=>v(w,N0));if(Z.isBridge)for(let N0 of s(Z.cellId))R(N0)},J0=(N0,F0)=>{if(!N0.cellId||!N0.set.has(F0))return!1;let m0=`cell-${z6(F0,N0.C)}`;return m0===N0.cellId||N0.bridges.includes(m0)||Uz(m0,N0.C).includes(N0.cellId)&&S(z6(F0,N0.C),N0.roster,N0.C)===F0},U0=(N0)=>Z.set.size<2&&(V.set?.size??0)<2||J0(Z,N0)||Date.now()<U&&J0(V,N0),q0=()=>{let N0=W.getPeers?.()||{};for(let F0 of Object.keys(N0))if(!U0(F0))N0[F0].close?.()};G.admit=U0;let $0=()=>({epoch:Z.epoch,cellId:Z.cellId,isBridge:Z.isBridge,bridges:Z.bridges,roster:[...Z.roster],cellSize:J,dynamicTTL:f(),totalCells:Z.C}),u0=()=>{A=Date.now();for(let[N0,F0]of T){if(N0===w8)continue;P("mesh:peer-state",{id:N0,cell:F0.cell,bridges:F0.bridges,timestamp:A})}},H1=(N0)=>{let F0=ch(N0.length,Y);J=Math.ceil(N0.length/F0);let m0=`cell-${z6(w8,F0)}`,Y0=new Map,K0=new Set,P0=new Map,k0=(x0)=>P0.get(x0)??P0.set(x0,new Set).get(x0);for(let x0 of N0)k0(`cell-${z6(x0,F0)}`).add(x0);let R1=new Map,Q1=(x0)=>R1.has(x0)?R1.get(x0):R1.set(x0,S(x0,N0,F0)).get(x0);for(let x0 of new Set(N0.map((k1)=>z6(k1,F0)))){let k1=`cell-${x0}`;for(let W8 of Uz(k1,F0)){if(MQ(W8)<x0)continue;for(let d1 of[Q1(x0),Q1(MQ(W8))]){if(!d1)continue;let N1=`cell-${z6(d1,F0)}`===k1?W8:k1,c=Y0.get(d1)??[];if(!c.includes(N1))c.push(N1);if(Y0.set(d1,c),k0(k1).add(d1),k0(W8).add(d1),k1===m0||W8===m0)K0.add(d1)}}}let X0=Y0.get(w8)??[],C0=Z.cellId!==m0||String(Z.bridges)!==String(X0);V=Z,Z={epoch:Z.epoch+1,roster:N0,set:new Set(N0),key:N0.join("|"),C:F0,cellId:m0,isBridge:X0.length>0,bridges:X0,edgeBridges:[...K0],audience:P0},H=Date.now(),T.clear();for(let x0 of N0){let k1=Y0.get(x0)??[];T.set(x0,{cell:`cell-${z6(x0,F0)}`,isBridge:k1.length>0,bridges:k1})}if(U=Date.now()+mh,C0)m();_9.info("\uD83D\uDD78\uFE0F [Cells] seal",{epoch:Z.epoch,myCell:m0,bridges:X0,C:F0,roster:N0.length}),u0(),P("mesh:state",$0())},v1=()=>{let N0=o(),F0=N0.join("|");if(F0===Z.key)Q=0;else{let m0=Date.now();if(Q||=m0,F0!==N)N=F0,q=m0;if(N0.some((Y0)=>!Z.set.has(Y0))||Z.edgeBridges.some((Y0)=>!N0.includes(Y0))||(W._gone?.()??[]).some((Y0)=>Z.set.has(Y0))?m0-q>=uh||m0-Q>=hh:m0-Q>=bh)Q=0,H1(N0)}if(U&&Date.now()>=U)U=0,q0()},h0=()=>{if(O)return;O=setInterval(()=>{if(v1(),Date.now()-A>=fh)u0()},gh)},F1=()=>{if(O)clearInterval(O),O=null},S1=(N0)=>{return new Promise((F0,m0)=>{let Y0=`${Date.now()}-${Math.random().toString(36).slice(2,8)}`,K0=Date.now(),P0=setTimeout(()=>{l.delete(Y0),m0(Error("Ping timeout"))},vh);l.set(Y0,{start:K0,resolve:F0,reject:m0,timeout:P0,peerId:N0});let k0={t:"ping",id:p(),ttl:f(),data:{pingId:Y0,target:N0},origin:w8,originCell:Z.cellId};I?.send(JSON.stringify(k0),_(Z.cellId))})};return W.on?.("peer:join",()=>v1()),W.on?.("peer:leave",()=>v1()),H1(o()),h0(),{send:(N0)=>{let F0={t:"msg",id:p(),ttl:f(),data:N0,origin:w8,originCell:Z.cellId},m0=JSON.stringify(F0);return I.send(m0,_(Z.cellId)),v(w,m0),Promise.resolve()},on:(N0,F0)=>N0==="message"?H0(F0):void 0,ping:S1,getState:()=>({...$0(),knownCells:new Set([...T.values()].map((N0)=>N0.cell)).size}),getPeerInfo:()=>new Map(T),getStableRoster:()=>[...Z.roster],getKnownCells:()=>{let N0=new Map;for(let[F0,{cell:m0}]of T)if(!N0.has(m0))N0.set(m0,{lastSeen:H,peerId:F0});return N0},getCellSize:()=>J,destroy:()=>{F1(),l.forEach((N0)=>clearTimeout(N0.timeout)),l.clear()}}}function dh(W,X,G){let Y={},J=YM({...W,admit:(Q)=>Y.admit?.(Q)??!0},X,G),Z=W.overlay||{},V=lh(J,Z,Y),U=new Map;return{on:(Q,N)=>J.on(Q,N),off:(Q,N)=>J.off?.(Q,N),channel:(Q)=>{if(U.has(Q))return U.get(Q);let N=J.channel(Q),q={send:(A,H)=>{if(H){let I=[].concat(H),w=J.getPeers?.()||{};if(I.every((O)=>w[O]))return N.send(A,H)}return V.send({_ch:Q,_d:A,_t:H})},on:(A,H)=>{if(A==="message")V.on("message",(I,w)=>{if(I?._ch!==Q)return;if(I._t&&![].concat(I._t).includes(w8))return;H(I._d,w)}),N.on(A,H);else N.on(A,H)},off:(A,H)=>N.off?.(A,H),_original:N};return U.set(Q,q),q},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 Bz=(W,X,G)=>W?.cells||W?.overlay?dh(W,X,G):YM(W,X,G);import{randomBytes as P2}from"crypto";function oh(){var W,X=!1,G=this;G._DeArray=function(Y,J,Z){return[Y.slice(J,J+Z)]},G._EnArray=function(Y,J,Z,V){for(var U=0;U<Z;Y[J+U]=V[U]?V[U]:0,U++);},G._DeChar=function(Y,J){return String.fromCharCode(Y[J])},G._EnChar=function(Y,J,Z){Y[J]=Z.charCodeAt(0)},G._DeInt=function(Y,J){var Z=X?W.len-1:0,V=X?-1:1,U=Z+V*W.len,Q,N,q;for(Q=0,N=Z,q=1;N!=U;Q+=Y[J+N]*q,N+=V,q*=256);if(W.bSigned&&Q&Math.pow(2,W.len*8-1))Q-=Math.pow(2,W.len*8);return Q},G._EnInt=function(Y,J,Z){var V=X?W.len-1:0,U=X?-1:1,Q=V+U*W.len,N;Z=Z<W.min?W.min:Z>W.max?W.max:Z;for(N=V;N!=Q;Y[J+N]=Z&255,N+=U,Z>>=8);},G._DeString=function(Y,J,Z){for(var V=Array(Z),U=0;U<Z;V[U]=String.fromCharCode(Y[J+U]),U++);return V.join("")},G._EnString=function(Y,J,Z,V){for(var U,Q=0;Q<Z;Y[J+Q]=(U=V.charCodeAt(Q))?U:0,Q++);},G._De754=function(Y,J){var Z,V,U,Q,N,q,A,H,I,w;A=W.mLen,H=W.len*8-W.mLen-1,w=(1<<H)-1,I=w>>1,Q=X?0:W.len-1,N=X?1:-1,Z=Y[J+Q],Q+=N,q=-7;for(V=Z&(1<<-q)-1,Z>>=-q,q+=H;q>0;V=V*256+Y[J+Q],Q+=N,q-=8);for(U=V&(1<<-q)-1,V>>=-q,q+=A;q>0;U=U*256+Y[J+Q],Q+=N,q-=8);switch(V){case 0:V=1-I;break;case w:return U?NaN:(Z?-1:1)*(1/0);default:U=U+Math.pow(2,A),V=V-I;break}return(Z?-1:1)*U*Math.pow(2,V-A)},G._En754=function(Y,J,Z){var V,U,Q,N,q,A,H,I,w,O;if(H=W.mLen,I=W.len*8-W.mLen-1,O=(1<<I)-1,w=O>>1,V=Z<0?1:0,Z=Math.abs(Z),isNaN(Z)||Z==1/0)Q=isNaN(Z)?1:0,U=O;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>=O)Q=0,U=O;else if(U+w>=1)Q=(Z*A-1)*Math.pow(2,H),U=U+w;else Q=Z*Math.pow(2,w-1)*Math.pow(2,H),U=0}for(N=X?W.len-1:0,q=X?-1:1;H>=8;Y[J+N]=Q&255,N+=q,Q/=256,H-=8);for(U=U<<H|Q,I+=H;I>0;Y[J+N]=U&255,N+=q,U/=256,I-=8);Y[J+N-q]|=V*128},G._DeInt64=function(Y,J){var Z=X?0:7,V=X?1:-1,U=Z+V*8,Q=[0,0,!W.bSigned],N,q,A;for(N=Z,A=1,q=0;N!=U;Q[A]=(Q[A]<<8>>>0)+Y[J+N],N+=V,q++,A=q<4?1:0);return Q},G._EnInt64=function(Y,J,Z){var V=X?0:7,U=X?1:-1,Q=V+U*8,N,q,A,H;for(N=V,A=1,q=0,H=24;N!=Q;Y[J+N]=Z[A]>>H&255,N+=U,q++,A=q<4?1:0,H=24-8*(q%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(Y,J,Z,V){for(var U=W.de,Q=[],N=0;N<Y;Q.push(U(Z,V+N*J)),N++);return Q},G._PackSeries=function(Y,J,Z,V,U,Q){for(var N=W.en,q=0;q<Y;N(Z,V+q*J,U[Q+q]),q++);},G.Unpack=function(Y,J,Z){X=Y.charAt(0)!="<",Z=Z?Z:0;var V=new RegExp(this._sPattern,"g"),U,Q,N,q=[];while(U=V.exec(Y)){if(Q=U[1]==null||U[1]==""?1:parseInt(U[1]),N=this._lenLut[U[2]],Z+Q*N>J.length)return;switch(U[2]){case"A":case"s":q.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]],q.push(this._UnpackSeries(Q,N,J,Z));break}Z+=Q*N}return Array.prototype.concat.apply([],q)},G.PackTo=function(Y,J,Z,V){X=Y.charAt(0)!="<";var U=new RegExp(this._sPattern,"g"),Q,N,q,A,H=0;while(Q=U.exec(Y)){if(N=Q[1]==null||Q[1]==""?1:parseInt(Q[1]),q=this._lenLut[Q[2]],Z+N*q>J.length)return!1;switch(Q[2]){case"A":case"s":if(H+1>V.length)return!1;this._elLut[Q[2]].en(J,Z,N,V[H]),H+=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]],H+N>V.length)return!1;this._PackSeries(N,q,J,Z,V,H),H+=N;break;case"x":for(A=0;A<N;A++)J[Z+A]=0;break}Z+=N*q}return J},G.Pack=function(Y,J){return this.PackTo(Y,Array(this.CalcLength(Y)),0,J)},G.CalcLength=function(Y){var J=new RegExp(this._sPattern,"g"),Z=0,V;while(V=J.exec(Y))Z+=(V[1]==null||V[1]==""?1:parseInt(V[1]))*this._lenLut[V[2]];return Z}}var X8=new oh;var y2=b1(IM(),1),AH=b1(bz(),1);import{createSocket as od}from"dgram";import{createSocket as rd}from"dgram";import*as v2 from"net";import{connect as ad}from"net";import{createSign as td,randomBytes as ed,webcrypto as Wo}from"crypto";var _N0=b1(pM(),1);var L7={};zA(L7,{verifySchema:()=>Jf,fromBER:()=>q4,compareSchema:()=>V4,VisibleString:()=>xW,ViewWriter:()=>oJ,VideotexString:()=>LG,ValueBlock:()=>X9,Utf8String:()=>m5,UniversalString:()=>TG,UTCTime:()=>kW,TimeOfDay:()=>eQ,TeletexString:()=>RG,TIME:()=>GN,Set:()=>c9,Sequence:()=>v9,Repeated:()=>jG,RelativeObjectIdentifier:()=>sQ,RawData:()=>_P,PrintableString:()=>PG,Primitive:()=>D6,OctetString:()=>P7,ObjectIdentifier:()=>DG,NumericString:()=>MG,Null:()=>M7,Integer:()=>C6,IA5String:()=>BG,HexBlock:()=>T7,GraphicString:()=>EG,GeneralizedTime:()=>SG,GeneralString:()=>$G,Enumerated:()=>OG,EndOfContent:()=>rQ,Duration:()=>XN,DateTime:()=>WN,DEFAULT_MAX_NODES:()=>XP,DEFAULT_MAX_DEPTH:()=>WP,DEFAULT_MAX_CONTENT_LENGTH:()=>GP,DATE:()=>tQ,Constructed:()=>l8,Choice:()=>iJ,CharacterString:()=>FG,Boolean:()=>KG,BmpString:()=>CG,BitString:()=>R7,BaseStringBlock:()=>nQ,BaseBlock:()=>y8,Any:()=>Q4});/*!
148
148
  * MIT License
149
149
  *
150
150
  * Copyright (c) 2017-2024 Peculiar Ventures, LLC
@@ -239,18 +239,18 @@ ${W.join(`
239
239
  `)}static pad(W=0){return"".padStart(2*W," ")}static serializeObj(W,X=0){let G=[],Y=this.pad(X++),J="",Z=W[a1.VALUE];if(Z)J=` ${Z}`;G.push(`${Y}${W[a1.NAME]}:${J}`),Y=this.pad(X);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(`${Y}${Q}${U}`);else if(U instanceof Date)G.push(`${Y}${Q}${U.toUTCString()}`);else if(Array.isArray(U))for(let N of U)N[a1.NAME]=V,G.push(...this.serializeObj(N,X));else if(U instanceof a1)U[a1.NAME]=V,G.push(...this.serializeObj(U,X));else if(y0.isBufferSource(U))if(V)G.push(`${Y}${Q}`),G.push(...this.serializeBufferSource(U,X+1));else G.push(...this.serializeBufferSource(U,X));else if("toTextObject"in U){let N=U.toTextObject();N[a1.NAME]=V,G.push(...this.serializeObj(N,X))}else throw TypeError("Cannot serialize data in text format. Unsupported type.")}return G}static serializeBufferSource(W,X=0){let G=this.pad(X),Y=y0.toUint8Array(W),J=[];for(let Z=0;Z<Y.length;){let V=[];for(let U=0;U<16&&Z<Y.length;U++){if(U===8)V.push("");let Q=Y[Z++].toString(16).padStart(2,"0");V.push(Q)}J.push(`${G}${V.join(" ")}`)}return J}static serializeAlgorithm(W){return this.algorithmSerializer.toTextObject(W)}}y6.oidSerializer=P4;y6.algorithmSerializer=p3;var NY;class g6{get rawData(){if(!M1(this,NY,"f"))j8(this,NY,S0.serialize(this.asn),"f");return M1(this,NY,"f")}constructor(...W){if(NY.set(this,void 0),y0.isBufferSource(W[0]))this.asn=S0.parse(W[0],W[1]),j8(this,NY,y0.toArrayBuffer(W[0]),"f"),this.onInit(this.asn);else this.asn=W[0],this.onInit(this.asn)}equal(W){if(W instanceof g6)return lM(W.rawData,this.rawData);return!1}toString(W="text"){switch(W){case"asn":return S0.toString(this.rawData);case"text":return y6.serialize(this.toTextObject());case"hex":return i0.ToHex(this.rawData);case"base64":return i0.ToBase64(this.rawData);case"base64url":return i0.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 a1(this.getTextName(),{},W)}}NY=new WeakMap;g6.NAME="ASN";class Q5 extends g6{constructor(...W){let X;if(y0.isBufferSource(W[0]))X=y0.toArrayBuffer(W[0]);else X=S0.serialize(new D9({extnID:W[0],critical:W[1],extnValue:new J1(y0.toArrayBuffer(W[2]))}));super(X,D9)}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[a1.NAME]===Q5.NAME)W[a1.NAME]=P4.toString(this.type);return W}}var c3;class _6{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[c3]="CryptoProvider",typeof self<"u"&&typeof crypto<"u")this.set(_6.DEFAULT,crypto);else if(typeof global<"u"&&global.crypto&&global.crypto.subtle)this.set(_6.DEFAULT,global.crypto)}clear(){this.items.clear()}delete(W){return this.items.delete(W)}forEach(W,X){return this.items.forEach(W,X)}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=_6.DEFAULT){let X=this.items.get(W.toLowerCase());if(!X)throw Error(`Cannot get Crypto by name '${W}'`);return X}set(W,X){if(typeof W==="string"){if(!X)throw TypeError("Argument 'value' is required");this.items.set(W.toLowerCase(),X)}else this.items.set(_6.DEFAULT,W);return this}}c3=Symbol.toStringTag;_6.DEFAULT="default";var u8=new _6,zp=/^[0-2](?:\.[1-9][0-9]*)+$/;function Ip(W){return new RegExp(zp).test(W)}class Vj{constructor(W={}){this.items={};for(let X in W)this.register(X,W[X])}get(W){return this.items[W]||null}findId(W){if(!Ip(W))return this.get(W);return W}register(W,X){this.items[W]=X,this.items[X]=W}}var o9=new Vj;o9.register("CN","2.5.4.3");o9.register("L","2.5.4.7");o9.register("ST","2.5.4.8");o9.register("O","2.5.4.10");o9.register("OU","2.5.4.11");o9.register("C","2.5.4.6");o9.register("DC","0.9.2342.19200300.100.1.25");o9.register("E","1.2.840.113549.1.9.1");o9.register("G","2.5.4.42");o9.register("I","2.5.4.43");o9.register("SN","2.5.4.4");o9.register("T","2.5.4.12");function wp(W,X){return`\\${i0.ToHex(i0.FromUtf8String(X)).toUpperCase()}`}function jp(W){return W.replace(/([,+"\\<>;])/g,"\\$1").replace(/^([ #])/,"\\$1").replace(/([ ]$)/,"\\$1").replace(/([\r\n\t])/,wp)}class i5{static isASCII(W){for(let X=0;X<W.length;X++)if(W.charCodeAt(X)>255)return!1;return!0}static isPrintableString(W){return/^[A-Za-z0-9 '()+,-./:=?]*$/g.test(W)}constructor(W,X={}){this.extraNames=new Vj,this.asn=new V8;for(let G in X)if(Object.prototype.hasOwnProperty.call(X,G)){let Y=X[G];this.extraNames.register(G,Y)}if(typeof W==="string")this.asn=this.fromString(W);else if(W instanceof V8)this.asn=W;else if(y0.isBufferSource(W))this.asn=S0.parse(W,V8);else this.asn=this.fromJSON(W)}getField(W){let X=this.extraNames.findId(W)||o9.findId(W),G=[];for(let Y of this.asn)for(let J of Y)if(J.type===X)G.push(J.value.toString());return G}getName(W){return this.extraNames.get(W)||o9.get(W)}toString(){return this.asn.map((W)=>W.map((X)=>{let G=this.getName(X.type)||X.type,Y=X.value.anyValue?`#${i0.ToHex(X.value.anyValue)}`:jp(X.value.toString());return`${G}=${Y}`}).join("+")).join(", ")}toJSON(){var W;let X=[];for(let G of this.asn){let Y={};for(let J of G){let Z=this.getName(J.type)||J.type;(W=Y[Z])!==null&&W!==void 0||(Y[Z]=[]),Y[Z].push(J.value.anyValue?`#${i0.ToHex(J.value.anyValue)}`:J.value.toString())}X.push(Y)}return X}fromString(W){let X=new V8,G=/(\d\.[\d.]*\d|[A-Za-z]+)=((?:"")|(?:".*?[^\\]")|(?:[^,+"\\](?=[,+]|$))|(?:[^,+].*?(?:[^\\][,+]))|(?:))([,+])?/g,Y=null,J=",";while(Y=G.exec(`${W},`)){let[,Z,V]=Y,U=V[V.length-1];if(U===","||U==="+")V=V.slice(0,V.length-1),Y[3]=U;let Q=Y[3];Z=this.getTypeOid(Z);let N=this.createAttribute(Z,V);if(J==="+")X[X.length-1].push(N);else X.push(new M6([N]));J=Q}return X}fromJSON(W){let X=new V8;for(let G of W){let Y=new M6;for(let J in G){let Z=this.getTypeOid(J),V=G[J];for(let U of V){let Q=this.createAttribute(Z,U);Y.push(Q)}}X.push(Y)}return X}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,X){let G=new vG({type:W});if(typeof X==="object")for(let Y in X)switch(Y){case"ia5String":G.value.ia5String=X[Y];break;case"utf8String":G.value.utf8String=X[Y];break;case"universalString":G.value.universalString=X[Y];break;case"bmpString":G.value.bmpString=X[Y];break;case"printableString":G.value.printableString=X[Y];break}else if(X[0]==="#")G.value.anyValue=i0.FromHex(X.slice(1));else{let Y=this.processStringValue(X);if(W===this.getName("E")||W===this.getName("DC"))G.value.ia5String=Y;else if(i5.isPrintableString(Y))G.value.printableString=Y;else G.value.utf8String=Y}return G}processStringValue(W){let X=/"(.*?[^\\])?"/.exec(W);if(X)W=X[1];return W.replace(/\\0a/ig,`
240
240
  `).replace(/\\0d/ig,"\r").replace(/\\0g/ig,"\t").replace(/\\(.)/g,"$1")}toArrayBuffer(){return S0.serialize(this.asn)}async getThumbprint(...W){var X;let G,Y="SHA-1";if(W.length>=1&&!((X=W[0])===null||X===void 0?void 0:X.subtle))Y=W[0]||Y,G=W[1]||u8.get();else G=W[0]||u8.get();return await G.subtle.digest(Y,this.toArrayBuffer())}}var l3="Cannot initialize GeneralName from ASN.1 data.",F3=`${l3} Unsupported string format in use.`,Kp=`${l3} Value doesn't match to GUID regular expression.`,S3=/^([0-9a-f]{8})-?([0-9a-f]{4})-?([0-9a-f]{4})-?([0-9a-f]{4})-?([0-9a-f]{12})$/i,x3="1.3.6.1.4.1.311.25.1",k3="1.3.6.1.4.1.311.20.2.3",iw="dns",rw="dn",aw="email",sw="ip",tw="url",ew="guid",Wj="upn",aN="id";class T4 extends g6{constructor(...W){let X;if(W.length===2)switch(W[0]){case rw:{let G=new i5(W[1]).toArrayBuffer(),Y=S0.parse(G,V8);X=new U1({directoryName:Y});break}case iw:X=new U1({dNSName:W[1]});break;case aw:X=new U1({rfc822Name:W[1]});break;case ew:{let G=new RegExp(S3,"i").exec(W[1]);if(!G)throw Error("Cannot parse GUID value. Value doesn't match to regular expression");let Y=G.slice(1).map((J,Z)=>{if(Z<3)return i0.ToHex(new Uint8Array(i0.FromHex(J)).reverse());return J}).join("");X=new U1({otherName:new yW({typeId:x3,value:S0.serialize(new J1(i0.FromHex(Y)))})});break}case sw:X=new U1({iPAddress:W[1]});break;case aN:X=new U1({registeredID:W[1]});break;case Wj:{X=new U1({otherName:new yW({typeId:k3,value:S0.serialize(qI.toASN(W[1]))})});break}case tw:X=new U1({uniformResourceIdentifier:W[1]});break;default:throw Error("Cannot create GeneralName. Unsupported type of the name")}else if(y0.isBufferSource(W[0]))X=S0.parse(W[0],U1);else X=W[0];super(X)}onInit(W){if(W.dNSName!=null)this.type=iw,this.value=W.dNSName;else if(W.rfc822Name!=null)this.type=aw,this.value=W.rfc822Name;else if(W.iPAddress!=null)this.type=sw,this.value=W.iPAddress;else if(W.uniformResourceIdentifier!=null)this.type=tw,this.value=W.uniformResourceIdentifier;else if(W.registeredID!=null)this.type=aN,this.value=W.registeredID;else if(W.directoryName!=null)this.type=rw,this.value=new i5(W.directoryName).toString();else if(W.otherName!=null)if(W.otherName.typeId===x3){this.type=ew;let X=S0.parse(W.otherName.value,J1),G=new RegExp(S3,"i").exec(i0.ToHex(X));if(!G)throw Error(Kp);this.value=G.slice(1).map((Y,J)=>{if(J<3)return i0.ToHex(new Uint8Array(i0.FromHex(Y)).reverse());return Y}).join("-")}else if(W.otherName.typeId===k3)this.type=Wj,this.value=S0.parse(W.otherName.value,g8).toString();else throw Error(F3);else throw Error(F3)}toJSON(){return{type:this.type,value:this.value}}toTextObject(){let W;switch(this.type){case rw:case iw:case ew:case sw:case aN:case Wj:case tw:W=this.type.toUpperCase();break;case aw:W="Email";break;default:throw Error("Unsupported GeneralName type")}let X=this.value;if(this.type===aN)X=P4.toString(X);return new a1(W,void 0,X)}}class v6 extends g6{constructor(W){let X;if(W instanceof K8)X=W;else if(Array.isArray(W)){let G=[];for(let Y of W)if(Y instanceof U1)G.push(Y);else{let J=S0.parse(new T4(Y.type,Y.value).rawData,U1);G.push(J)}X=new K8(G)}else if(y0.isBufferSource(W))X=S0.parse(W,K8);else throw Error("Cannot initialize GeneralNames. Incorrect incoming arguments");super(X)}onInit(W){let X=[];for(let G of W){let Y=null;try{Y=new T4(G)}catch{continue}X.push(Y)}this.items=X}toJSON(){return this.items.map((W)=>W.toJSON())}toTextObject(){let W=super.toTextObjectEmpty();for(let X of this.items){let G=X.toTextObject(),Y=W[G[a1.NAME]];if(!Array.isArray(Y))Y=[],W[G[a1.NAME]]=Y;Y.push(G)}return W}}v6.NAME="GeneralNames";var UV="-{5}",NV="\\n",Op=`[^${NV}]+`,Dp=`${UV}BEGIN (${Op}(?=${UV}))${UV}`,Cp=`${UV}END \\1${UV}`,AY="\\n",Tp=`[^:${NV}]+`,Mp=`(?:[^${NV}]+${AY}(?: +[^${NV}]+${AY})*)`,Pp="[a-zA-Z0-9=+/]+",Rp=`(?:${Pp}${AY})+`,_3=`${Dp}${AY}(?:((?:${Tp}: ${Mp})+))?${AY}?(${Rp})${Cp}`;class T9{static isPem(W){return typeof W==="string"&&new RegExp(_3,"g").test(W.replace(/\r/g,""))}static decodeWithHeaders(W){W=W.replace(/\r/g,"");let X=new RegExp(_3,"g"),G=[],Y=null;while(Y=X.exec(W)){let J=Y[3].replace(new RegExp(`[${NV}]+`,"g"),""),Z={type:Y[1],headers:[],rawData:i0.FromBase64(J)},V=Y[2];if(V){let U=V.split(new RegExp(AY,"g")),Q=null;for(let N of U){let[q,A]=N.split(/:(.*)/);if(A===void 0){if(!Q)throw Error("Cannot parse PEM string. Incorrect header value");Q.value+=q.trim()}else{if(Q)Z.headers.push(Q);Q={key:q,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 X=this.decode(W);if(!X.length)throw RangeError("PEM string doesn't contain any objects");return X[0]}static encode(W,X){if(Array.isArray(W)){let G=[];if(X)W.forEach((Y)=>{if(!y0.isBufferSource(Y))throw TypeError("Cannot encode array of BufferSource in PEM format. Not all items of the array are BufferSource");G.push(this.encodeStruct({type:X,rawData:y0.toArrayBuffer(Y)}))});else W.forEach((Y)=>{if(!("type"in Y))throw TypeError("Cannot encode array of PemStruct in PEM format. Not all items of the array are PemStrut");G.push(this.encodeStruct(Y))});return G.join(`
241
241
  `)}else{if(!X)throw Error("Required argument 'tag' is missed");return this.encodeStruct({type:X,rawData:y0.toArrayBuffer(W)})}}static encodeStruct(W){var X;let G=W.type.toLocaleUpperCase(),Y=[];if(Y.push(`-----BEGIN ${G}-----`),(X=W.headers)===null||X===void 0?void 0:X.length){for(let Q of W.headers)Y.push(`${Q.key}: ${Q.value}`);Y.push("")}let J=i0.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 Y.push(...U),Y.push(`-----END ${G}-----`),Y.join(`
242
- `)}}T9.CertificateTag="CERTIFICATE";T9.CrlTag="CRL";T9.CertificateRequestTag="CERTIFICATE REQUEST";T9.PublicKeyTag="PUBLIC KEY";T9.PrivateKeyTag="PRIVATE KEY";class M4 extends g6{static isAsnEncoded(W){return y0.isBufferSource(W)||typeof W==="string"}static toArrayBuffer(W){if(typeof W==="string")if(T9.isPem(W))return T9.decode(W)[0];else if(i0.isHex(W))return i0.FromHex(W);else if(i0.isBase64(W))return i0.FromBase64(W);else if(i0.isBase64Url(W))return i0.FromBase64Url(W);else throw TypeError("Unsupported format of 'raw' argument. Must be one of DER, PEM, HEX, Base64, or Base4Url");else{let X=y0.toUint8Array(W);if(X.length>0&&X[0]===48)return y0.toArrayBuffer(W);let G=i0.ToBinary(W);if(T9.isPem(G))return T9.decode(G)[0];else if(i0.isHex(G))return i0.FromHex(G);else if(i0.isBase64(G))return i0.FromBase64(G);else if(i0.isBase64Url(G))return i0.FromBase64Url(G);throw TypeError("Unsupported format of 'raw' argument. Must be one of DER, PEM, HEX, Base64, or Base4Url")}}constructor(...W){if(M4.isAsnEncoded(W[0]))super(M4.toArrayBuffer(W[0]),W[1]);else super(W[0])}toString(W="pem"){switch(W){case"pem":return T9.encode(this.rawData,this.tag);default:return super.toString(W)}}}class r5 extends M4{static async create(W,X=u8.get()){if(W instanceof r5)return W;else if(_6.isCryptoKey(W)){if(W.type!=="public")throw TypeError("Public key is required");let G=await X.subtle.exportKey("spki",W);return new r5(G)}else if(W.publicKey)return W.publicKey;else if(y0.isBufferSource(W))return new r5(W);else throw TypeError("Unsupported PublicKeyType")}constructor(W){if(M4.isAsnEncoded(W))super(W,O9);else super(W);this.tag=T9.PublicKeyTag}async export(...W){let X,G=["verify"],Y={hash:"SHA-256",...this.algorithm};if(W.length>1)Y=W[0]||Y,G=W[1]||G,X=W[2]||u8.get();else X=W[0]||u8.get();let J=this.rawData,Z=S0.parse(this.rawData,O9);if(Z.algorithm.algorithm===F6)J=Lp(Z,J);return X.subtle.importKey("spki",J,Y,!0,G)}onInit(W){let X=H8.resolve(UX),G=this.algorithm=X.toWebAlgorithm(W.algorithm);switch(W.algorithm.algorithm){case x7:{let Y=S0.parse(W.subjectPublicKey,xZ),J=y0.toUint8Array(Y.modulus);G.publicExponent=y0.toUint8Array(Y.publicExponent),G.modulusLength=(!J[0]?J.slice(1):J).byteLength<<3;break}}}async getThumbprint(...W){var X;let G,Y="SHA-1";if(W.length>=1&&!((X=W[0])===null||X===void 0?void 0:X.subtle))Y=W[0]||Y,G=W[1]||u8.get();else G=W[0]||u8.get();return await G.subtle.digest(Y,this.rawData)}async getKeyIdentifier(...W){let X,G="SHA-1";if(W.length===1)if(typeof W[0]==="string")G=W[0],X=u8.get();else X=W[0];else if(W.length===2)G=W[0],X=W[1];else X=u8.get();let Y=S0.parse(this.rawData,O9);return await X.subtle.digest(G,Y.subjectPublicKey)}toTextObject(){let W=this.toTextObjectEmpty(),X=S0.parse(this.rawData,O9);switch(W.Algorithm=y6.serializeAlgorithm(X.algorithm),X.algorithm.algorithm){case rW:W["EC Point"]=X.subjectPublicKey;break;case x7:default:W["Raw Data"]=X.subjectPublicKey}return W}}function Lp(W,X){return W.algorithm=new L0({algorithm:x7,parameters:null}),X=S0.serialize(W),X}class qV extends Q5{static async create(W,X=!1,G=u8.get()){if("name"in W&&"serialNumber"in W)return new qV(W,X);let J=await(await r5.create(W,G)).getKeyIdentifier(G);return new qV(i0.ToHex(J),X)}constructor(...W){if(y0.isBufferSource(W[0]))super(W[0]);else if(typeof W[0]==="string"){let X=new z4({keyIdentifier:new gG(i0.FromHex(W[0]))});super(AN,W[1],S0.serialize(X))}else{let X=W[0],G=X.name instanceof v6?S0.parse(X.name.rawData,K8):X.name,Y=new z4({authorityCertIssuer:G,authorityCertSerialNumber:i0.FromHex(X.serialNumber)});super(AN,W[1],S0.serialize(Y))}}onInit(W){super.onInit(W);let X=S0.parse(W.extnValue,z4);if(X.keyIdentifier)this.keyId=i0.ToHex(X.keyIdentifier);if(X.authorityCertIssuer||X.authorityCertSerialNumber)this.certId={name:X.authorityCertIssuer||[],serialNumber:X.authorityCertSerialNumber?i0.ToHex(X.authorityCertSerialNumber):""}}toTextObject(){let W=this.toTextObjectWithoutValue(),X=S0.parse(this.value,z4);if(X.authorityCertIssuer)W["Authority Issuer"]=new v6(X.authorityCertIssuer).toTextObject();if(X.authorityCertSerialNumber)W["Authority Serial Number"]=X.authorityCertSerialNumber;if(X.keyIdentifier)W[""]=X.keyIdentifier;return W}}qV.NAME="Authority Key Identifier";class Uj extends Q5{constructor(...W){if(y0.isBufferSource(W[0])){super(W[0]);let X=S0.parse(this.value,uG);this.ca=X.cA,this.pathLength=X.pathLenConstraint}else{let X=new uG({cA:W[0],pathLenConstraint:W[1]});super(zN,W[2],S0.serialize(X));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}}Uj.NAME="Basic Constraints";var y3;(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"})(y3||(y3={}));class Qj extends Q5{constructor(...W){if(y0.isBufferSource(W[0])){super(W[0]);let X=S0.parse(this.value,XZ);this.usages=X.map((G)=>G)}else{let X=new XZ(W[0]);super(TN,W[1],S0.serialize(X));this.usages=W[0]}}toTextObject(){let W=this.toTextObjectWithoutValue();return W[""]=this.usages.map((X)=>P4.toString(X)).join(", "),W}}Qj.NAME="Extended Key Usages";var v3;(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"})(v3||(v3={}));class Nj extends Q5{constructor(...W){if(y0.isBufferSource(W[0])){super(W[0]);let X=S0.parse(this.value,YZ);this.usages=X.toNumber()}else{let X=new YZ(W[0]);super(MN,W[1],S0.serialize(X));this.usages=W[0]}}toTextObject(){let W=this.toTextObjectWithoutValue(),X=S0.parse(this.value,YZ);return W[""]=X.toJSON().join(", "),W}}Nj.NAME="Key Usages";class Xq extends Q5{static async create(W,X=!1,G=u8.get()){let J=await(await r5.create(W,G)).getKeyIdentifier(G);return new Xq(i0.ToHex(J),X)}constructor(...W){if(y0.isBufferSource(W[0])){super(W[0]);let X=S0.parse(this.value,J5);this.keyId=i0.ToHex(X)}else{let X=typeof W[0]==="string"?i0.FromHex(W[0]):W[0],G=new J5(X);super(pI,W[1],S0.serialize(G));this.keyId=i0.ToHex(X)}}toTextObject(){let W=this.toTextObjectWithoutValue(),X=S0.parse(this.value,J5);return W[""]=X,W}}Xq.NAME="Subject Key Identifier";class qj extends Q5{constructor(...W){if(y0.isBufferSource(W[0]))super(W[0]);else super(mI,W[1],new v6(W[0]||[]).rawData)}onInit(W){super.onInit(W);let X=S0.parse(W.extnValue,LN);this.names=new v6(X)}toTextObject(){let W=this.toTextObjectWithoutValue(),X=this.names.toTextObject();for(let G in X)W[G]=X[G];return W}}qj.NAME="Subject Alternative Name";class i9{static register(W,X){this.items.set(W,X)}static create(W){let X=new Q5(W),G=this.items.get(X.type);if(G)return new G(W);return X}}i9.items=new Map;class Hj extends Q5{constructor(...W){var X;if(y0.isBufferSource(W[0])){super(W[0]);let G=S0.parse(this.value,sJ);this.policies=G.map((Y)=>Y.policyIdentifier)}else{let G=W[0],Y=(X=W[1])!==null&&X!==void 0?X:!1,J=new sJ(G.map((Z)=>new hG({policyIdentifier:Z})));super(wN,Y,S0.serialize(J));this.policies=G}}toTextObject(){let W=this.toTextObjectWithoutValue();return W.Policy=this.policies.map((X)=>new a1("",{},P4.toString(X))),W}}Hj.NAME="Certificate Policies";i9.register(wN,Hj);class Aj extends Q5{constructor(...W){var X;if(y0.isBufferSource(W[0]))super(W[0]);else if(Array.isArray(W[0])&&typeof W[0][0]==="string"){let Y=W[0].map((Z)=>{return new j4({distributionPoint:new w4({fullName:[new U1({uniformResourceIdentifier:Z})]})})}),J=new L6(Y);super(DN,W[1],S0.serialize(J))}else{let G=new L6(W[0]);super(DN,W[1],S0.serialize(G))}(X=this.distributionPoints)!==null&&X!==void 0||(this.distributionPoints=[])}onInit(W){super.onInit(W);let X=S0.parse(W.extnValue,L6);this.distributionPoints=X}toTextObject(){let W=this.toTextObjectWithoutValue();return W["Distribution Point"]=this.distributionPoints.map((X)=>{var G;let Y={};if(X.distributionPoint)Y[""]=(G=X.distributionPoint.fullName)===null||G===void 0?void 0:G.map((J)=>new T4(J).toString()).join(", ");if(X.reasons)Y.Reasons=X.reasons.toString();if(X.cRLIssuer)Y["CRL Issuer"]=X.cRLIssuer.map((J)=>J.toString()).join(", ");return Y}),W}}Aj.NAME="CRL Distribution Points";class zj extends Q5{constructor(...W){var X,G,Y,J;if(y0.isBufferSource(W[0]))super(W[0]);else if(W[0]instanceof gW){let Z=new gW(W[0]);super(HN,W[1],S0.serialize(Z))}else{let Z=W[0],V=new gW;tN(V,Z,TI,"ocsp"),tN(V,Z,MI,"caIssuers"),tN(V,Z,PI,"timeStamping"),tN(V,Z,RI,"caRepository");super(HN,W[1],S0.serialize(V))}(X=this.ocsp)!==null&&X!==void 0||(this.ocsp=[]),(G=this.caIssuers)!==null&&G!==void 0||(this.caIssuers=[]),(Y=this.timeStamping)!==null&&Y!==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=[],S0.parse(W.extnValue,gW).forEach((G)=>{switch(G.accessMethod){case TI:this.ocsp.push(new T4(G.accessLocation));break;case MI:this.caIssuers.push(new T4(G.accessLocation));break;case PI:this.timeStamping.push(new T4(G.accessLocation));break;case RI:this.caRepository.push(new T4(G.accessLocation));break}})}toTextObject(){let W=this.toTextObjectWithoutValue();if(this.ocsp.length)sN(W,"OCSP",this.ocsp);if(this.caIssuers.length)sN(W,"CA Issuers",this.caIssuers);if(this.timeStamping.length)sN(W,"Time Stamping",this.timeStamping);if(this.caRepository.length)sN(W,"CA Repository",this.caRepository);return W}}zj.NAME="Authority Info Access";function sN(W,X,G){if(G.length===1)W[X]=G[0].toTextObject();else{let Y=new a1("");G.forEach((J,Z)=>{let V=J.toTextObject(),U=`${V[a1.NAME]} ${Z+1}`,Q=Y[U];if(!Array.isArray(Q))Q=[],Y[U]=Q;Q.push(V)}),W[X]=Y}}function tN(W,X,G,Y){let J=X[Y];if(J)(Array.isArray(J)?J:[J]).forEach((V)=>{if(typeof V==="string")V=new T4("url",V);W.push(new R6({accessMethod:G,accessLocation:S0.parse(V.rawData,U1)}))})}class Ij extends Q5{constructor(...W){if(y0.isBufferSource(W[0]))super(W[0]);else super(yI,W[1],new v6(W[0]||[]).rawData)}onInit(W){super.onInit(W);let X=S0.parse(W.extnValue,K8);this.names=new v6(X)}toTextObject(){let W=this.toTextObjectWithoutValue(),X=this.names.toTextObject();for(let G in X)W[G]=X[G];return W}}Ij.NAME="Issuer Alternative Name";class zY extends g6{constructor(...W){let X;if(y0.isBufferSource(W[0]))X=y0.toArrayBuffer(W[0]);else{let G=W[0],Y=Array.isArray(W[1])?W[1].map((J)=>y0.toArrayBuffer(J)):[];X=S0.serialize(new K9({type:G,values:Y}))}super(X,K9)}onInit(W){this.type=W.type,this.values=W.values}toTextObject(){let W=this.toTextObjectWithoutValue();return W.Value=this.values.map((X)=>new a1("",{"":X})),W}toTextObjectWithoutValue(){let W=this.toTextObjectEmpty();if(W[a1.NAME]===zY.NAME)W[a1.NAME]=P4.toString(this.type);return W}}zY.NAME="Attribute";class wj extends zY{constructor(...W){var X;if(y0.isBufferSource(W[0]))super(W[0]);else{let G=new hZ({printableString:W[0]});super(ow,[S0.serialize(G)])}(X=this.password)!==null&&X!==void 0||(this.password="")}onInit(W){if(super.onInit(W),this.values[0]){let X=S0.parse(this.values[0],hZ);this.password=X.toString()}}toTextObject(){let W=this.toTextObjectWithoutValue();return W[a1.VALUE]=this.password,W}}wj.NAME="Challenge Password";class Gq extends zY{constructor(...W){var X;if(y0.isBufferSource(W[0]))super(W[0]);else{let G=W[0],Y=new Z5;for(let J of G)Y.push(S0.parse(J.rawData,D9));super(mZ,[S0.serialize(Y)])}(X=this.items)!==null&&X!==void 0||(this.items=[])}onInit(W){if(super.onInit(W),this.values[0]){let X=S0.parse(this.values[0],Z5);this.items=X.map((G)=>i9.create(S0.serialize(G)))}}toTextObject(){let W=this.toTextObjectWithoutValue(),X=this.items.map((G)=>G.toTextObject());for(let G of X)W[G[a1.NAME]]=G;return W}}Gq.NAME="Extensions";class AV{static register(W,X){this.items.set(W,X)}static create(W){let X=new zY(W),G=this.items.get(X.type);if(G)return new G(W);return X}}AV.items=new Map;var zV="crypto.signatureFormatter";class d3{toAsnSignature(W,X){return y0.toArrayBuffer(X)}toWebSignature(W,X){return y0.toArrayBuffer(X)}}var Wq,Yj=Wq=class{static createPssParams(X,G){let Y=Wq.getHashAlgorithm(X);if(!Y)return null;return new D4({hashAlgorithm:Y,maskGenAlgorithm:new L0({algorithm:S6,parameters:S0.serialize(Y)}),saltLength:G})}static getHashAlgorithm(X){let G=H8.resolve(UX);if(typeof X==="string")return G.toAsnAlgorithm({name:X});if(typeof X==="object"&&X&&"name"in X)return G.toAsnAlgorithm(X);return null}toAsnAlgorithm(X){switch(X.name.toLowerCase()){case"rsassa-pkcs1-v1_5":if("hash"in X){let G;if(typeof X.hash==="string")G=X.hash;else if(X.hash&&typeof X.hash==="object"&&"name"in X.hash&&typeof X.hash.name==="string")G=X.hash.name.toUpperCase();else throw Error("Cannot get hash algorithm name");switch(G.toLowerCase()){case"sha-1":return new L0({algorithm:WY,parameters:null});case"sha-256":return new L0({algorithm:bN,parameters:null});case"sha-384":return new L0({algorithm:XY,parameters:null});case"sha-512":return new L0({algorithm:GY,parameters:null})}}else return new L0({algorithm:x7,parameters:null});break;case"rsa-pss":if("hash"in X){if(!(("saltLength"in X)&&typeof X.saltLength==="number"))throw Error("Cannot get 'saltLength' from 'alg' argument");let G=Wq.createPssParams(X.hash,X.saltLength);if(!G)throw Error("Cannot create PSS parameters");return new L0({algorithm:F6,parameters:S0.serialize(G)})}else return new L0({algorithm:F6,parameters:null})}return null}toWebAlgorithm(X){switch(X.algorithm){case x7:return{name:"RSASSA-PKCS1-v1_5"};case WY:return{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-1"}};case bN:return{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}};case XY:return{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-384"}};case GY:return{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-512"}};case F6:if(X.parameters){let G=S0.parse(X.parameters,D4);return{name:"RSA-PSS",hash:H8.resolve(UX).toWebAlgorithm(G.hashAlgorithm),saltLength:G.saltLength}}else return{name:"RSA-PSS"}}return null}};Yj=Wq=j([k6()],Yj);H8.registerSingleton(HV,Yj);var Jj=class{toAsnAlgorithm(X){switch(X.name.toLowerCase()){case"sha-1":return new L0({algorithm:aW});case"sha-256":return new L0({algorithm:sW});case"sha-384":return new L0({algorithm:tW});case"sha-512":return new L0({algorithm:eW})}return null}toWebAlgorithm(X){switch(X.algorithm){case aW:return{name:"SHA-1"};case sW:return{name:"SHA-256"};case tW:return{name:"SHA-384"};case eW:return{name:"SHA-512"}}return null}};Jj=j([k6()],Jj);H8.registerSingleton(HV,Jj);class B5{addPadding(W,X){let G=y0.toUint8Array(X),Y=new Uint8Array(W);return Y.set(G,W-G.length),Y.buffer}removePadding(W,X=!1){let G=y0.toUint8Array(W);for(let Y=0;Y<G.length;Y++){if(!G[Y])continue;G=G.slice(Y);break}if(X&&G[0]>127){let Y=new Uint8Array(G.length+1);return Y.set(G,1),Y.buffer}return G.buffer}toAsnSignature(W,X){if(W.name==="ECDSA"){let G=W.namedCurve,Y=B5.namedCurveSize.get(G)||B5.defaultNamedCurveSize,J=new eG,Z=y0.toUint8Array(X);return J.r=this.removePadding(Z.slice(0,Y),!0),J.s=this.removePadding(Z.slice(Y,Y+Y),!0),S0.serialize(J)}return null}toWebSignature(W,X){if(W.name==="ECDSA"){let G=S0.parse(X,eG),Y=W.namedCurve,J=B5.namedCurveSize.get(Y)||B5.defaultNamedCurveSize,Z=this.addPadding(J,this.removePadding(G.r)),V=this.addPadding(J,this.removePadding(G.s));return cM(Z,V)}return null}}B5.namedCurveSize=new Map;B5.defaultNamedCurveSize=32;var Xj="1.3.101.110",g3="1.3.101.111",Gj="1.3.101.112",u3="1.3.101.113",Zj=class{toAsnAlgorithm(X){let G=null;switch(X.name.toLowerCase()){case"ed25519":G=Gj;break;case"x25519":G=Xj;break;case"eddsa":switch(X.namedCurve.toLowerCase()){case"ed25519":G=Gj;break;case"ed448":G=u3;break}break;case"ecdh-es":switch(X.namedCurve.toLowerCase()){case"x25519":G=Xj;break;case"x448":G=g3;break}}if(G)return new L0({algorithm:G});return null}toWebAlgorithm(X){switch(X.algorithm){case Gj:return{name:"Ed25519"};case u3:return{name:"EdDSA",namedCurve:"Ed448"};case Xj:return{name:"X25519"};case g3:return{name:"ECDH-ES",namedCurve:"X448"}}return null}};Zj=j([k6()],Zj);H8.registerSingleton(HV,Zj);var cZ,lZ,dZ,oZ,nZ,iZ,rZ,qY;class o3 extends M4{get subjectName(){if(!M1(this,lZ,"f"))j8(this,lZ,new i5(this.asn.certificationRequestInfo.subject),"f");return M1(this,lZ,"f")}get subject(){if(!M1(this,dZ,"f"))j8(this,dZ,this.subjectName.toString(),"f");return M1(this,dZ,"f")}get signatureAlgorithm(){if(!M1(this,oZ,"f")){let W=H8.resolve(UX);j8(this,oZ,W.toWebAlgorithm(this.asn.signatureAlgorithm),"f")}return M1(this,oZ,"f")}get signature(){if(!M1(this,nZ,"f"))j8(this,nZ,this.asn.signature,"f");return M1(this,nZ,"f")}get publicKey(){if(!M1(this,iZ,"f"))j8(this,iZ,new r5(this.asn.certificationRequestInfo.subjectPKInfo),"f");return M1(this,iZ,"f")}get attributes(){if(!M1(this,rZ,"f"))j8(this,rZ,this.asn.certificationRequestInfo.attributes.map((W)=>AV.create(S0.serialize(W))),"f");return M1(this,rZ,"f")}get extensions(){if(!M1(this,qY,"f")){j8(this,qY,[],"f");let W=this.getAttribute(mZ);if(W instanceof Gq)j8(this,qY,W.items,"f")}return M1(this,qY,"f")}get tbs(){if(!M1(this,cZ,"f"))j8(this,cZ,this.asn.certificationRequestInfoRaw||S0.serialize(this.asn.certificationRequestInfo),"f");return M1(this,cZ,"f")}constructor(W){let X=M4.isAsnEncoded(W)?[W,VX]:[W];super(X[0],X[1]);cZ.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),rZ.set(this,void 0),qY.set(this,void 0),this.tag=T9.CertificateRequestTag}onInit(W){}getAttribute(W){for(let X of this.attributes)if(X.type===W)return X;return null}getAttributes(W){return this.attributes.filter((X)=>X.type===W)}getExtension(W){for(let X of this.extensions)if(X.type===W)return X;return null}getExtensions(W){return this.extensions.filter((X)=>X.type===W)}async verify(W=u8.get()){let X={...this.publicKey.algorithm,...this.signatureAlgorithm},G=await this.publicKey.export(X,["verify"],W),Y=H8.resolveAll(zV).reverse(),J=null;for(let V of Y)if(J=V.toWebSignature(X,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(),X=S0.parse(this.rawData,VX),G=X.certificationRequestInfo,Y=new a1("",{Version:`${B7[G.version]} (${G.version})`,Subject:this.subject,"Subject Public Key Info":this.publicKey});if(this.attributes.length){let J=new a1("");for(let Z of this.attributes){let V=Z.toTextObject();J[V[a1.NAME]]=V}Y.Attributes=J}return W.Data=Y,W.Signature=new a1("",{Algorithm:y6.serializeAlgorithm(X.signatureAlgorithm),"":X.signature}),W}}cZ=new WeakMap,lZ=new WeakMap,dZ=new WeakMap,oZ=new WeakMap,nZ=new WeakMap,iZ=new WeakMap,rZ=new WeakMap,qY=new WeakMap;o3.NAME="PKCS#10 Certificate Request";var aZ,sZ,tZ,eZ,WV,XV,GV,YV,JV,ZV,HY,VV;class jj extends M4{get publicKey(){if(!M1(this,VV,"f"))j8(this,VV,new r5(this.asn.tbsCertificate.subjectPublicKeyInfo),"f");return M1(this,VV,"f")}get serialNumber(){if(!M1(this,sZ,"f")){let W=this.asn.tbsCertificate,X=new Uint8Array(W.serialNumber);if(X.length>1&&X[0]===0&&X[1]>127)X=X.slice(1);j8(this,sZ,i0.ToHex(X),"f")}return M1(this,sZ,"f")}get subjectName(){if(!M1(this,tZ,"f"))j8(this,tZ,new i5(this.asn.tbsCertificate.subject),"f");return M1(this,tZ,"f")}get subject(){if(!M1(this,eZ,"f"))j8(this,eZ,this.subjectName.toString(),"f");return M1(this,eZ,"f")}get issuerName(){if(!M1(this,WV,"f"))j8(this,WV,new i5(this.asn.tbsCertificate.issuer),"f");return M1(this,WV,"f")}get issuer(){if(!M1(this,XV,"f"))j8(this,XV,this.issuerName.toString(),"f");return M1(this,XV,"f")}get notBefore(){if(!M1(this,GV,"f")){let W=this.asn.tbsCertificate.validity.notBefore.utcTime||this.asn.tbsCertificate.validity.notBefore.generalTime;if(!W)throw Error("Cannot get 'notBefore' value");j8(this,GV,W,"f")}return M1(this,GV,"f")}get notAfter(){if(!M1(this,YV,"f")){let W=this.asn.tbsCertificate.validity.notAfter.utcTime||this.asn.tbsCertificate.validity.notAfter.generalTime;if(!W)throw Error("Cannot get 'notAfter' value");j8(this,YV,W,"f")}return M1(this,YV,"f")}get signatureAlgorithm(){if(!M1(this,JV,"f")){let W=H8.resolve(UX);j8(this,JV,W.toWebAlgorithm(this.asn.signatureAlgorithm),"f")}return M1(this,JV,"f")}get signature(){if(!M1(this,ZV,"f"))j8(this,ZV,this.asn.signatureValue,"f");return M1(this,ZV,"f")}get extensions(){if(!M1(this,HY,"f")){if(j8(this,HY,[],"f"),this.asn.tbsCertificate.extensions)j8(this,HY,this.asn.tbsCertificate.extensions.map((W)=>i9.create(S0.serialize(W))),"f")}return M1(this,HY,"f")}get tbs(){if(!M1(this,aZ,"f"))j8(this,aZ,this.asn.tbsCertificateRaw||S0.serialize(this.asn.tbsCertificate),"f");return M1(this,aZ,"f")}constructor(W){let X=M4.isAsnEncoded(W)?[W,c5]:[W];super(X[0],X[1]);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),XV.set(this,void 0),GV.set(this,void 0),YV.set(this,void 0),JV.set(this,void 0),ZV.set(this,void 0),HY.set(this,void 0),VV.set(this,void 0),this.tag=T9.CertificateTag}onInit(W){}getExtension(W){for(let X of this.extensions)if(typeof W==="string"){if(X.type===W)return X}else if(X instanceof W)return X;return null}getExtensions(W){return this.extensions.filter((X)=>{if(typeof W==="string")return X.type===W;else return X instanceof W})}async verify(W={},X=u8.get()){let G,Y,J=W.publicKey;try{if(!J)G={...this.publicKey.algorithm,...this.signatureAlgorithm},Y=await this.publicKey.export(G,["verify"],X);else if("publicKey"in J)G={...J.publicKey.algorithm,...this.signatureAlgorithm},Y=await J.publicKey.export(G,["verify"],X);else if(J instanceof r5)G={...J.algorithm,...this.signatureAlgorithm},Y=await J.export(G,["verify"],X);else if(y0.isBufferSource(J)){let Q=new r5(J);G={...Q.algorithm,...this.signatureAlgorithm},Y=await Q.export(G,["verify"],X)}else G={...J.algorithm,...this.signatureAlgorithm},Y=J}catch{return!1}let Z=H8.resolveAll(zV).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 X.subtle.verify(this.signatureAlgorithm,Y,V,this.tbs);if(W.signatureOnly)return U;else{let N=(W.date||new Date).getTime();return U&&this.notBefore.getTime()<N&&N<this.notAfter.getTime()}}async getThumbprint(...W){let X,G="SHA-1";if(W[0])if(!W[0].subtle)G=W[0]||G,X=W[1];else X=W[0];return X!==null&&X!==void 0||(X=u8.get()),await X.subtle.digest(G,this.rawData)}async isSelfSigned(W=u8.get()){return this.subject===this.issuer&&await this.verify({signatureOnly:!0},W)}toTextObject(){let W=this.toTextObjectEmpty(),X=S0.parse(this.rawData,c5),G=X.tbsCertificate,Y=new a1("",{Version:`${B7[G.version]} (${G.version})`,"Serial Number":G.serialNumber,"Signature Algorithm":y6.serializeAlgorithm(G.signature),Issuer:this.issuer,Validity:new a1("",{"Not Before":G.validity.notBefore.getTime(),"Not After":G.validity.notAfter.getTime()}),Subject:this.subject,"Subject Public Key Info":this.publicKey});if(G.issuerUniqueID)Y["Issuer Unique ID"]=G.issuerUniqueID;if(G.subjectUniqueID)Y["Subject Unique ID"]=G.subjectUniqueID;if(this.extensions.length){let J=new a1("");for(let Z of this.extensions){let V=Z.toTextObject();J[V[a1.NAME]]=V}Y.Extensions=J}return W.Data=Y,W.Signature=new a1("",{Algorithm:y6.serializeAlgorithm(X.signatureAlgorithm),"":X.signatureValue}),W}}aZ=new WeakMap,sZ=new WeakMap,tZ=new WeakMap,eZ=new WeakMap,WV=new WeakMap,XV=new WeakMap,GV=new WeakMap,YV=new WeakMap,JV=new WeakMap,ZV=new WeakMap,HY=new WeakMap,VV=new WeakMap;jj.NAME="Certificate";function Bp(W,X=u8.get()){let G=y0.toUint8Array(i0.FromHex(W||"")),Y=G&&G.length&&G.some((Z)=>Z>0)?new Uint8Array(G):void 0;if(!Y)Y=X.getRandomValues(new Uint8Array(16));let J=0;while(J<Y.length-1&&Y[J]===0)J++;if(Y=Y.slice(J),Y[0]>127){let Z=new Uint8Array(Y.length+1);Z[0]=0,Z.set(Y,1),Y=Z}return Y.buffer}class Kj{static async createSelfSigned(W,X=u8.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},X)}static async create(W,X=u8.get()){var G;let Y;if(W.publicKey instanceof r5)Y=W.publicKey.rawData;else if("publicKey"in W.publicKey)Y=W.publicKey.publicKey.rawData;else if(y0.isBufferSource(W.publicKey))Y=W.publicKey;else Y=await X.subtle.exportKey("spki",W.publicKey);let J=Bp(W.serialNumber,X),Z=W.notBefore||new Date,V=W.notAfter||new Date(Z.getTime()+31536000000),U=new c5({tbsCertificate:new C9({version:B7.v3,serialNumber:J,validity:new B6({notBefore:Z,notAfter:V}),extensions:new Z5(((G=W.extensions)===null||G===void 0?void 0:G.map((O)=>S0.parse(O.rawData,D9)))||[]),subjectPublicKeyInfo:S0.parse(Y,O9)})});if(W.subject){let O=W.subject instanceof i5?W.subject:new i5(W.subject);U.tbsCertificate.subject=S0.parse(O.toArrayBuffer(),V8)}if(W.issuer){let O=W.issuer instanceof i5?W.issuer:new i5(W.issuer);U.tbsCertificate.issuer=S0.parse(O.toArrayBuffer(),V8)}let Q={hash:"SHA-256"},N="signingKey"in W?{...Q,...W.signingAlgorithm,...W.signingKey.algorithm}:{...Q,...W.signingAlgorithm},q=H8.resolve(UX);U.tbsCertificate.signature=U.signatureAlgorithm=q.toAsnAlgorithm(N);let A=S0.serialize(U.tbsCertificate),H="signingKey"in W?await X.subtle.sign(N,W.signingKey,A):W.signature,I=H8.resolveAll(zV).reverse(),w=null;for(let O of I)if(w=O.toAsnSignature(N,H),w)break;if(!w)throw Error("Cannot convert ASN.1 signature value to WebCrypto format");return U.signatureValue=w,new jj(S0.serialize(U))}}var Ep,$p,Fp,Sp,xp,h3;(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"})(h3||(h3={}));Ep=new WeakMap,$p=new WeakMap,Fp=new WeakMap,Sp=new WeakMap,xp=new WeakMap;var kp,_p,yp,vp,gp,up,hp;kp=new WeakMap,_p=new WeakMap,yp=new WeakMap,vp=new WeakMap,gp=new WeakMap,up=new WeakMap,hp=new WeakMap;i9.register(zN,Uj);i9.register(TN,Qj);i9.register(MN,Nj);i9.register(pI,Xq);i9.register(AN,qV);i9.register(mI,qj);i9.register(DN,Aj);i9.register(HN,zj);i9.register(yI,Ij);AV.register(ow,wj);AV.register(mZ,Gq);H8.registerSingleton(zV,d3);H8.registerSingleton(zV,B5);B5.namedCurveSize.set("P-256",32);B5.namedCurveSize.set("K-256",32);B5.namedCurveSize.set("P-384",48);B5.namedCurveSize.set("P-521",66);var hY=b1(D8(),1),b2=b1(D8(),1),m2=b1(yQ(),1);import{createHash as Yo,createHmac as Jo}from"crypto";import*as R4 from"crypto";var NX=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 qX(W){return W instanceof Uint8Array||ArrayBuffer.isView(W)&&W.constructor.name==="Uint8Array"}function CV(W){if(!Number.isSafeInteger(W)||W<0)throw Error("positive integer expected, got "+W)}function a5(W,...X){if(!qX(W))throw Error("Uint8Array expected");if(X.length>0&&!X.includes(W.length))throw Error("Uint8Array expected of length "+X+", got length="+W.length)}function qq(W){if(typeof W!=="function"||typeof W.create!=="function")throw Error("Hash should be wrapped by utils.createHasher");CV(W.outputLen),CV(W.blockLen)}function KY(W,X=!0){if(W.destroyed)throw Error("Hash instance has been destroyed");if(X&&W.finished)throw Error("Hash#digest() has already been called")}function LE(W,X){a5(W);let G=X.outputLen;if(W.length<G)throw Error("digestInto() expects output buffer of length at least "+G)}function B4(...W){for(let X=0;X<W.length;X++)W[X].fill(0)}function Hq(W){return new DataView(W.buffer,W.byteOffset,W.byteLength)}function s5(W,X){return W<<32-X|W>>>X}var BE=(()=>typeof Uint8Array.from([]).toHex==="function"&&typeof Uint8Array.fromHex==="function")(),zl=Array.from({length:256},(W,X)=>X.toString(16).padStart(2,"0"));function E4(W){if(a5(W),BE)return W.toHex();let X="";for(let G=0;G<W.length;G++)X+=zl[W[G]];return X}var L4={_0:48,_9:57,A:65,F:70,a:97,f:102};function RE(W){if(W>=L4._0&&W<=L4._9)return W-L4._0;if(W>=L4.A&&W<=L4.F)return W-(L4.A-10);if(W>=L4.a&&W<=L4.f)return W-(L4.a-10);return}function HX(W){if(typeof W!=="string")throw Error("hex string expected, got "+typeof W);if(BE)return Uint8Array.fromHex(W);let X=W.length,G=X/2;if(X%2)throw Error("hex string expected, got unpadded hex of length "+X);let Y=new Uint8Array(G);for(let J=0,Z=0;J<G;J++,Z+=2){let V=RE(W.charCodeAt(Z)),U=RE(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)}Y[J]=V*16+U}return Y}function Aq(W){if(typeof W!=="string")throw Error("string expected");return new Uint8Array(new TextEncoder().encode(W))}function TV(W){if(typeof W==="string")W=Aq(W);return a5(W),W}function a9(...W){let X=0;for(let Y=0;Y<W.length;Y++){let J=W[Y];a5(J),X+=J.length}let G=new Uint8Array(X);for(let Y=0,J=0;Y<W.length;Y++){let Z=W[Y];G.set(Z,J),J+=Z.length}return G}class MV{}function zq(W){let X=(Y)=>W().update(TV(Y)).digest(),G=W();return X.outputLen=G.outputLen,X.blockLen=G.blockLen,X.create=()=>W(),X}function AX(W=32){if(NX&&typeof NX.getRandomValues==="function")return NX.getRandomValues(new Uint8Array(W));if(NX&&typeof NX.randomBytes==="function")return Uint8Array.from(NX.randomBytes(W));throw Error("crypto.getRandomValues must be defined")}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */var Sj=BigInt(0),Fj=BigInt(1);function PV(W,X=""){if(typeof W!=="boolean"){let G=X&&`"${X}"`;throw Error(G+"expected boolean, got type="+typeof W)}return W}function p6(W,X,G=""){let Y=qX(W),J=W?.length,Z=X!==void 0;if(!Y||Z&&J!==X){let V=G&&`"${G}" `,U=Z?` of length ${X}`:"",Q=Y?`length=${J}`:`type=${typeof W}`;throw Error(V+"expected Uint8Array"+U+", got "+Q)}return W}function RV(W){let X=W.toString(16);return X.length&1?"0"+X:X}function EE(W){if(typeof W!=="string")throw Error("hex string expected, got "+typeof W);return W===""?Sj:BigInt("0x"+W)}function $4(W){return EE(E4(W))}function xj(W){return a5(W),EE(E4(Uint8Array.from(W).reverse()))}function OY(W,X){return HX(W.toString(16).padStart(X*2,"0"))}function kj(W,X){return OY(W,X).reverse()}function F8(W,X,G){let Y;if(typeof X==="string")try{Y=HX(X)}catch(Z){throw Error(W+" must be hex string or Uint8Array, cause: "+Z)}else if(qX(X))Y=Uint8Array.from(X);else throw Error(W+" must be hex string or Uint8Array");let J=Y.length;if(typeof G==="number"&&J!==G)throw Error(W+" of length "+G+" expected, got "+J);return Y}var $j=(W)=>typeof W==="bigint"&&Sj<=W;function LV(W,X,G){return $j(W)&&$j(X)&&$j(G)&&X<=W&&W<G}function $E(W,X,G,Y){if(!LV(X,G,Y))throw Error("expected valid "+W+": "+G+" <= n < "+Y+", got "+X)}function Iq(W){let X;for(X=0;W>Sj;W>>=Fj,X+=1);return X}var c6=(W)=>(Fj<<BigInt(W))-Fj;function FE(W,X,G){if(typeof W!=="number"||W<2)throw Error("hashLen must be a number");if(typeof X!=="number"||X<2)throw Error("qByteLen must be a number");if(typeof G!=="function")throw Error("hmacFn must be a function");let Y=(I)=>new Uint8Array(I),J=(I)=>Uint8Array.of(I),Z=Y(W),V=Y(W),U=0,Q=()=>{Z.fill(1),V.fill(0),U=0},N=(...I)=>G(V,Z,...I),q=(I=Y(0))=>{if(V=N(J(0),I),Z=N(),I.length===0)return;V=N(J(1),I),Z=N()},A=()=>{if(U++>=1000)throw Error("drbg: tried 1000 values");let I=0,w=[];while(I<X){Z=N();let O=Z.slice();w.push(O),I+=Z.length}return a9(...w)};return(I,w)=>{Q(),q(I);let O=void 0;while(!(O=w(A())))q();return Q(),O}}function BV(W,X,G={}){if(!W||typeof W!=="object")throw Error("expected valid options object");function Y(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(X).forEach(([J,Z])=>Y(J,Z,!1)),Object.entries(G).forEach(([J,Z])=>Y(J,Z,!0))}function _j(W){let X=new WeakMap;return(G,...Y)=>{let J=X.get(G);if(J!==void 0)return J;let Z=W(G,...Y);return X.set(G,Z),Z}}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */var u9=BigInt(0),M9=BigInt(1),zX=BigInt(2),kE=BigInt(3),_E=BigInt(4),yE=BigInt(5),Il=BigInt(7),vE=BigInt(8),wl=BigInt(9),gE=BigInt(16);function N5(W,X){let G=W%X;return G>=u9?G:X+G}function q5(W,X,G){let Y=W;while(X-- >u9)Y*=Y,Y%=G;return Y}function SE(W,X){if(W===u9)throw Error("invert: expected non-zero number");if(X<=u9)throw Error("invert: expected positive modulus, got "+X);let G=N5(W,X),Y=X,J=u9,Z=M9,V=M9,U=u9;while(G!==u9){let N=Y/G,q=Y%G,A=J-V*N,H=Z-U*N;Y=G,G=q,J=V,Z=U,V=A,U=H}if(Y!==M9)throw Error("invert: does not exist");return N5(J,X)}function yj(W,X,G){if(!W.eql(W.sqr(X),G))throw Error("Cannot find square root")}function uE(W,X){let G=(W.ORDER+M9)/_E,Y=W.pow(X,G);return yj(W,Y,X),Y}function jl(W,X){let G=(W.ORDER-yE)/vE,Y=W.mul(X,zX),J=W.pow(Y,G),Z=W.mul(X,J),V=W.mul(W.mul(Z,zX),J),U=W.mul(Z,W.sub(V,W.ONE));return yj(W,U,X),U}function Kl(W){let X=$5(W),G=hE(W),Y=G(X,X.neg(X.ONE)),J=G(X,Y),Z=G(X,X.neg(Y)),V=(W+Il)/gE;return(U,Q)=>{let N=U.pow(Q,V),q=U.mul(N,Y),A=U.mul(N,J),H=U.mul(N,Z),I=U.eql(U.sqr(q),Q),w=U.eql(U.sqr(A),Q);N=U.cmov(N,q,I),q=U.cmov(H,A,w);let O=U.eql(U.sqr(q),Q),T=U.cmov(N,q,O);return yj(U,T,Q),T}}function hE(W){if(W<kE)throw Error("sqrt is not defined for small field");let X=W-M9,G=0;while(X%zX===u9)X/=zX,G++;let Y=zX,J=$5(W);while(xE(J,Y)===1)if(Y++>1000)throw Error("Cannot find square root: probably non-prime P");if(G===1)return uE;let Z=J.pow(Y,X),V=(X+M9)/zX;return function(Q,N){if(Q.is0(N))return N;if(xE(Q,N)!==1)throw Error("Cannot find square root");let q=G,A=Q.mul(Q.ONE,Z),H=Q.pow(N,X),I=Q.pow(N,V);while(!Q.eql(H,Q.ONE)){if(Q.is0(H))return Q.ZERO;let w=1,O=Q.sqr(H);while(!Q.eql(O,Q.ONE))if(w++,O=Q.sqr(O),w===q)throw Error("Cannot find square root");let T=M9<<BigInt(q-w-1),x=Q.pow(A,T);q=w,A=Q.sqr(x),H=Q.mul(H,A),I=Q.mul(I,x)}return I}}function Ol(W){if(W%_E===kE)return uE;if(W%vE===yE)return jl;if(W%gE===wl)return Kl(W);return hE(W)}var Dl=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function vj(W){let X={ORDER:"bigint",MASK:"bigint",BYTES:"number",BITS:"number"},G=Dl.reduce((Y,J)=>{return Y[J]="function",Y},X);return BV(W,G),W}function Cl(W,X,G){if(G<u9)throw Error("invalid exponent, negatives unsupported");if(G===u9)return W.ONE;if(G===M9)return X;let Y=W.ONE,J=X;while(G>u9){if(G&M9)Y=W.mul(Y,J);J=W.sqr(J),G>>=M9}return Y}function wq(W,X,G=!1){let Y=Array(X.length).fill(G?W.ZERO:void 0),J=X.reduce((V,U,Q)=>{if(W.is0(U))return V;return Y[Q]=V,W.mul(V,U)},W.ONE),Z=W.inv(J);return X.reduceRight((V,U,Q)=>{if(W.is0(U))return V;return Y[Q]=W.mul(V,Y[Q]),W.mul(V,U)},Z),Y}function xE(W,X){let G=(W.ORDER-M9)/zX,Y=W.pow(X,G),J=W.eql(Y,W.ONE),Z=W.eql(Y,W.ZERO),V=W.eql(Y,W.neg(W.ONE));if(!J&&!Z&&!V)throw Error("invalid Legendre symbol result");return J?1:Z?0:-1}function jq(W,X){if(X!==void 0)CV(X);let G=X!==void 0?X:W.toString(2).length,Y=Math.ceil(G/8);return{nBitLength:G,nByteLength:Y}}function $5(W,X,G=!1,Y={}){if(W<=u9)throw Error("invalid field: expected ORDER > 0, got "+W);let J=void 0,Z=void 0,V=!1,U=void 0;if(typeof X==="object"&&X!=null){if(Y.sqrt||G)throw Error("cannot specify opts in two arguments");let H=X;if(H.BITS)J=H.BITS;if(H.sqrt)Z=H.sqrt;if(typeof H.isLE==="boolean")G=H.isLE;if(typeof H.modFromBytes==="boolean")V=H.modFromBytes;U=H.allowedLengths}else{if(typeof X==="number")J=X;if(Y.sqrt)Z=Y.sqrt}let{nBitLength:Q,nByteLength:N}=jq(W,J);if(N>2048)throw Error("invalid field: expected ORDER of <= 2048 bytes");let q,A=Object.freeze({ORDER:W,isLE:G,BITS:Q,BYTES:N,MASK:c6(Q),ZERO:u9,ONE:M9,allowedLengths:U,create:(H)=>N5(H,W),isValid:(H)=>{if(typeof H!=="bigint")throw Error("invalid field element: expected bigint, got "+typeof H);return u9<=H&&H<W},is0:(H)=>H===u9,isValidNot0:(H)=>!A.is0(H)&&A.isValid(H),isOdd:(H)=>(H&M9)===M9,neg:(H)=>N5(-H,W),eql:(H,I)=>H===I,sqr:(H)=>N5(H*H,W),add:(H,I)=>N5(H+I,W),sub:(H,I)=>N5(H-I,W),mul:(H,I)=>N5(H*I,W),pow:(H,I)=>Cl(A,H,I),div:(H,I)=>N5(H*SE(I,W),W),sqrN:(H)=>H*H,addN:(H,I)=>H+I,subN:(H,I)=>H-I,mulN:(H,I)=>H*I,inv:(H)=>SE(H,W),sqrt:Z||((H)=>{if(!q)q=Ol(W);return q(A,H)}),toBytes:(H)=>G?kj(H,N):OY(H,N),fromBytes:(H,I=!0)=>{if(U){if(!U.includes(H.length)||H.length>N)throw Error("Field.fromBytes: expected "+U+" bytes, got "+H.length);let O=new Uint8Array(N);O.set(H,G?0:O.length-H.length),H=O}if(H.length!==N)throw Error("Field.fromBytes: expected "+N+" bytes, got "+H.length);let w=G?xj(H):$4(H);if(V)w=N5(w,W);if(!I){if(!A.isValid(w))throw Error("invalid field element: outside of range 0..ORDER")}return w},invertBatch:(H)=>wq(A,H),cmov:(H,I,w)=>w?I:H});return Object.freeze(A)}function bE(W){if(typeof W!=="bigint")throw Error("field order must be bigint");let X=W.toString(2).length;return Math.ceil(X/8)}function gj(W){let X=bE(W);return X+Math.ceil(X/2)}function Kq(W,X,G=!1){let Y=W.length,J=bE(X),Z=gj(X);if(Y<16||Y<Z||Y>1024)throw Error("expected "+Z+"-1024 bytes of input, got "+Y);let V=G?xj(W):$4(W),U=N5(V,X-M9)+M9;return G?kj(U,J):OY(U,J)}function Tl(W,X,G,Y){if(typeof W.setBigUint64==="function")return W.setBigUint64(X,G,Y);let J=BigInt(32),Z=BigInt(4294967295),V=Number(G>>J&Z),U=Number(G&Z),Q=Y?4:0,N=Y?0:4;W.setUint32(X+Q,V,Y),W.setUint32(X+N,U,Y)}function mE(W,X,G){return W&X^~W&G}function fE(W,X,G){return W&X^W&G^X&G}class Oq extends MV{constructor(W,X,G,Y){super();this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=W,this.outputLen=X,this.padOffset=G,this.isLE=Y,this.buffer=new Uint8Array(W),this.view=Hq(this.buffer)}update(W){KY(this),W=TV(W),a5(W);let{view:X,buffer:G,blockLen:Y}=this,J=W.length;for(let Z=0;Z<J;){let V=Math.min(Y-this.pos,J-Z);if(V===Y){let U=Hq(W);for(;Y<=J-Z;Z+=Y)this.process(U,Z);continue}if(G.set(W.subarray(Z,Z+V),this.pos),this.pos+=V,Z+=V,this.pos===Y)this.process(X,0),this.pos=0}return this.length+=W.length,this.roundClean(),this}digestInto(W){KY(this),LE(W,this),this.finished=!0;let{buffer:X,view:G,blockLen:Y,isLE:J}=this,{pos:Z}=this;if(X[Z++]=128,B4(this.buffer.subarray(Z)),this.padOffset>Y-Z)this.process(G,0),Z=0;for(let q=Z;q<Y;q++)X[q]=0;Tl(G,Y-8,BigInt(this.length*8),J),this.process(G,0);let V=Hq(W),U=this.outputLen;if(U%4)throw Error("_sha2: outputLen should be aligned to 32bit");let Q=U/4,N=this.get();if(Q>N.length)throw Error("_sha2: outputLen bigger than state");for(let q=0;q<Q;q++)V.setUint32(4*q,N[q],J)}digest(){let{buffer:W,outputLen:X}=this;this.digestInto(W);let G=W.slice(0,X);return this.destroy(),G}_cloneInto(W){W||(W=new this.constructor),W.set(...this.get());let{blockLen:X,buffer:G,length:Y,finished:J,destroyed:Z,pos:V}=this;if(W.destroyed=Z,W.finished=J,W.length=Y,W.pos=V,Y%X)W.buffer.set(G);return W}clone(){return this._cloneInto()}}var F4=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var J9=Uint32Array.from([3418070365,3238371032,1654270250,914150663,2438529370,812702999,355462360,4144912697,1731405415,4290775857,2394180231,1750603025,3675008525,1694076839,1203062813,3204075428]),Z9=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var Dq=BigInt(4294967295),pE=BigInt(32);function Ml(W,X=!1){if(X)return{h:Number(W&Dq),l:Number(W>>pE&Dq)};return{h:Number(W>>pE&Dq)|0,l:Number(W&Dq)|0}}function cE(W,X=!1){let G=W.length,Y=new Uint32Array(G),J=new Uint32Array(G);for(let Z=0;Z<G;Z++){let{h:V,l:U}=Ml(W[Z],X);[Y[Z],J[Z]]=[V,U]}return[Y,J]}var uj=(W,X,G)=>W>>>G,hj=(W,X,G)=>W<<32-G|X>>>G,IX=(W,X,G)=>W>>>G|X<<32-G,wX=(W,X,G)=>W<<32-G|X>>>G,EV=(W,X,G)=>W<<64-G|X>>>G-32,$V=(W,X,G)=>W>>>G-32|X<<64-G;function y7(W,X,G,Y){let J=(X>>>0)+(Y>>>0);return{h:W+G+(J/4294967296|0)|0,l:J|0}}var lE=(W,X,G)=>(W>>>0)+(X>>>0)+(G>>>0),dE=(W,X,G,Y)=>X+G+Y+(W/4294967296|0)|0,oE=(W,X,G,Y)=>(W>>>0)+(X>>>0)+(G>>>0)+(Y>>>0),nE=(W,X,G,Y,J)=>X+G+Y+J+(W/4294967296|0)|0,iE=(W,X,G,Y,J)=>(W>>>0)+(X>>>0)+(G>>>0)+(Y>>>0)+(J>>>0),rE=(W,X,G,Y,J,Z)=>X+G+Y+J+Z+(W/4294967296|0)|0;var Rl=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]),l6=new Uint32Array(64);class aE extends Oq{constructor(W=32){super(64,W,8,!1);this.A=F4[0]|0,this.B=F4[1]|0,this.C=F4[2]|0,this.D=F4[3]|0,this.E=F4[4]|0,this.F=F4[5]|0,this.G=F4[6]|0,this.H=F4[7]|0}get(){let{A:W,B:X,C:G,D:Y,E:J,F:Z,G:V,H:U}=this;return[W,X,G,Y,J,Z,V,U]}set(W,X,G,Y,J,Z,V,U){this.A=W|0,this.B=X|0,this.C=G|0,this.D=Y|0,this.E=J|0,this.F=Z|0,this.G=V|0,this.H=U|0}process(W,X){for(let q=0;q<16;q++,X+=4)l6[q]=W.getUint32(X,!1);for(let q=16;q<64;q++){let A=l6[q-15],H=l6[q-2],I=s5(A,7)^s5(A,18)^A>>>3,w=s5(H,17)^s5(H,19)^H>>>10;l6[q]=w+l6[q-7]+I+l6[q-16]|0}let{A:G,B:Y,C:J,D:Z,E:V,F:U,G:Q,H:N}=this;for(let q=0;q<64;q++){let A=s5(V,6)^s5(V,11)^s5(V,25),H=N+A+mE(V,U,Q)+Rl[q]+l6[q]|0,w=(s5(G,2)^s5(G,13)^s5(G,22))+fE(G,Y,J)|0;N=Q,Q=U,U=V,V=Z+H|0,Z=J,J=Y,Y=G,G=H+w|0}G=G+this.A|0,Y=Y+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,N=N+this.H|0,this.set(G,Y,J,Z,V,U,Q,N)}roundClean(){B4(l6)}destroy(){this.set(0,0,0,0,0,0,0,0),B4(this.buffer)}}var sE=(()=>cE(["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))))(),Ll=(()=>sE[0])(),Bl=(()=>sE[1])(),d6=new Uint32Array(80),o6=new Uint32Array(80);class bj extends Oq{constructor(W=64){super(128,W,16,!1);this.Ah=Z9[0]|0,this.Al=Z9[1]|0,this.Bh=Z9[2]|0,this.Bl=Z9[3]|0,this.Ch=Z9[4]|0,this.Cl=Z9[5]|0,this.Dh=Z9[6]|0,this.Dl=Z9[7]|0,this.Eh=Z9[8]|0,this.El=Z9[9]|0,this.Fh=Z9[10]|0,this.Fl=Z9[11]|0,this.Gh=Z9[12]|0,this.Gl=Z9[13]|0,this.Hh=Z9[14]|0,this.Hl=Z9[15]|0}get(){let{Ah:W,Al:X,Bh:G,Bl:Y,Ch:J,Cl:Z,Dh:V,Dl:U,Eh:Q,El:N,Fh:q,Fl:A,Gh:H,Gl:I,Hh:w,Hl:O}=this;return[W,X,G,Y,J,Z,V,U,Q,N,q,A,H,I,w,O]}set(W,X,G,Y,J,Z,V,U,Q,N,q,A,H,I,w,O){this.Ah=W|0,this.Al=X|0,this.Bh=G|0,this.Bl=Y|0,this.Ch=J|0,this.Cl=Z|0,this.Dh=V|0,this.Dl=U|0,this.Eh=Q|0,this.El=N|0,this.Fh=q|0,this.Fl=A|0,this.Gh=H|0,this.Gl=I|0,this.Hh=w|0,this.Hl=O|0}process(W,X){for(let h=0;h<16;h++,X+=4)d6[h]=W.getUint32(X),o6[h]=W.getUint32(X+=4);for(let h=16;h<80;h++){let $=d6[h-15]|0,F=o6[h-15]|0,u=IX($,F,1)^IX($,F,8)^uj($,F,7),l=wX($,F,1)^wX($,F,8)^hj($,F,7),p=d6[h-2]|0,s=o6[h-2]|0,y=IX(p,s,19)^EV(p,s,61)^uj(p,s,6),t=wX(p,s,19)^$V(p,s,61)^hj(p,s,6),H0=oE(l,t,o6[h-7],o6[h-16]),g=nE(H0,u,y,d6[h-7],d6[h-16]);d6[h]=g|0,o6[h]=H0|0}let{Ah:G,Al:Y,Bh:J,Bl:Z,Ch:V,Cl:U,Dh:Q,Dl:N,Eh:q,El:A,Fh:H,Fl:I,Gh:w,Gl:O,Hh:T,Hl:x}=this;for(let h=0;h<80;h++){let $=IX(q,A,14)^IX(q,A,18)^EV(q,A,41),F=wX(q,A,14)^wX(q,A,18)^$V(q,A,41),u=q&H^~q&w,l=A&I^~A&O,p=iE(x,F,l,Bl[h],o6[h]),s=rE(p,T,$,u,Ll[h],d6[h]),y=p|0,t=IX(G,Y,28)^EV(G,Y,34)^EV(G,Y,39),H0=wX(G,Y,28)^$V(G,Y,34)^$V(G,Y,39),g=G&J^G&V^J&V,d=Y&Z^Y&U^Z&U;T=w|0,x=O|0,w=H|0,O=I|0,H=q|0,I=A|0,{h:q,l:A}=y7(Q|0,N|0,s|0,y|0),Q=V|0,N=U|0,V=J|0,U=Z|0,J=G|0,Z=Y|0;let P=lE(y,H0,d);G=dE(P,s,t,g),Y=P|0}({h:G,l:Y}=y7(this.Ah|0,this.Al|0,G|0,Y|0)),{h:J,l:Z}=y7(this.Bh|0,this.Bl|0,J|0,Z|0),{h:V,l:U}=y7(this.Ch|0,this.Cl|0,V|0,U|0),{h:Q,l:N}=y7(this.Dh|0,this.Dl|0,Q|0,N|0),{h:q,l:A}=y7(this.Eh|0,this.El|0,q|0,A|0),{h:H,l:I}=y7(this.Fh|0,this.Fl|0,H|0,I|0),{h:w,l:O}=y7(this.Gh|0,this.Gl|0,w|0,O|0),{h:T,l:x}=y7(this.Hh|0,this.Hl|0,T|0,x|0),this.set(G,Y,J,Z,V,U,Q,N,q,A,H,I,w,O,T,x)}roundClean(){B4(d6,o6)}destroy(){B4(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}}class tE extends bj{constructor(){super(48);this.Ah=J9[0]|0,this.Al=J9[1]|0,this.Bh=J9[2]|0,this.Bl=J9[3]|0,this.Ch=J9[4]|0,this.Cl=J9[5]|0,this.Dh=J9[6]|0,this.Dl=J9[7]|0,this.Eh=J9[8]|0,this.El=J9[9]|0,this.Fh=J9[10]|0,this.Fl=J9[11]|0,this.Gh=J9[12]|0,this.Gl=J9[13]|0,this.Hh=J9[14]|0,this.Hl=J9[15]|0}}var DY=zq(()=>new aE);var eE=zq(()=>new bj),W$=zq(()=>new tE);class mj extends MV{constructor(W,X){super();this.finished=!1,this.destroyed=!1,qq(W);let G=TV(X);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 Y=this.blockLen,J=new Uint8Array(Y);J.set(G.length>Y?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),B4(J)}update(W){return KY(this),this.iHash.update(W),this}digestInto(W){KY(this),a5(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:X,iHash:G,finished:Y,destroyed:J,blockLen:Z,outputLen:V}=this;return W=W,W.finished=Y,W.destroyed=J,W.blockLen=Z,W.outputLen=V,W.oHash=X._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 fj=(W,X,G)=>new mj(W,X).update(G).digest();fj.create=(W,X)=>new mj(W,X);/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */var CY=BigInt(0),jX=BigInt(1);function FV(W,X){let G=X.negate();return W?G:X}function Cq(W,X){let G=wq(W.Fp,X.map((Y)=>Y.Z));return X.map((Y,J)=>W.fromAffine(Y.toAffine(G[J])))}function J$(W,X){if(!Number.isSafeInteger(W)||W<=0||W>X)throw Error("invalid window size, expected [1.."+X+"], got W="+W)}function pj(W,X){J$(W,X);let G=Math.ceil(X/W)+1,Y=2**(W-1),J=2**W,Z=c6(W),V=BigInt(W);return{windows:G,windowSize:Y,mask:Z,maxNumber:J,shiftBy:V}}function X$(W,X,G){let{windowSize:Y,mask:J,maxNumber:Z,shiftBy:V}=G,U=Number(W&J),Q=W>>V;if(U>Y)U-=Z,Q+=jX;let N=X*Y,q=N+Math.abs(U)-1,A=U===0,H=U<0,I=X%2!==0;return{nextN:Q,offset:q,isZero:A,isNeg:H,isNegF:I,offsetF:N}}function El(W,X){if(!Array.isArray(W))throw Error("array expected");W.forEach((G,Y)=>{if(!(G instanceof X))throw Error("invalid point at index "+Y)})}function $l(W,X){if(!Array.isArray(W))throw Error("array of scalars expected");W.forEach((G,Y)=>{if(!X.isValid(G))throw Error("invalid scalar at index "+Y)})}var cj=new WeakMap,Z$=new WeakMap;function lj(W){return Z$.get(W)||1}function G$(W){if(W!==CY)throw Error("invalid wNAF")}class dj{constructor(W,X){this.BASE=W.BASE,this.ZERO=W.ZERO,this.Fn=W.Fn,this.bits=X}_unsafeLadder(W,X,G=this.ZERO){let Y=W;while(X>CY){if(X&jX)G=G.add(Y);Y=Y.double(),X>>=jX}return G}precomputeWindow(W,X){let{windows:G,windowSize:Y}=pj(X,this.bits),J=[],Z=W,V=Z;for(let U=0;U<G;U++){V=Z,J.push(V);for(let Q=1;Q<Y;Q++)V=V.add(Z),J.push(V);Z=V.double()}return J}wNAF(W,X,G){if(!this.Fn.isValid(G))throw Error("invalid scalar");let Y=this.ZERO,J=this.BASE,Z=pj(W,this.bits);for(let V=0;V<Z.windows;V++){let{nextN:U,offset:Q,isZero:N,isNeg:q,isNegF:A,offsetF:H}=X$(G,V,Z);if(G=U,N)J=J.add(FV(A,X[H]));else Y=Y.add(FV(q,X[Q]))}return G$(G),{p:Y,f:J}}wNAFUnsafe(W,X,G,Y=this.ZERO){let J=pj(W,this.bits);for(let Z=0;Z<J.windows;Z++){if(G===CY)break;let{nextN:V,offset:U,isZero:Q,isNeg:N}=X$(G,Z,J);if(G=V,Q)continue;else{let q=X[U];Y=Y.add(N?q.negate():q)}}return G$(G),Y}getPrecomputes(W,X,G){let Y=cj.get(X);if(!Y){if(Y=this.precomputeWindow(X,W),W!==1){if(typeof G==="function")Y=G(Y);cj.set(X,Y)}}return Y}cached(W,X,G){let Y=lj(W);return this.wNAF(Y,this.getPrecomputes(Y,W,G),X)}unsafe(W,X,G,Y){let J=lj(W);if(J===1)return this._unsafeLadder(W,X,Y);return this.wNAFUnsafe(J,this.getPrecomputes(J,W,G),X,Y)}createCache(W,X){J$(X,this.bits),Z$.set(W,X),cj.delete(W)}hasCache(W){return lj(W)!==1}}function V$(W,X,G,Y){let J=X,Z=W.ZERO,V=W.ZERO;while(G>CY||Y>CY){if(G&jX)Z=Z.add(J);if(Y&jX)V=V.add(J);J=J.double(),G>>=jX,Y>>=jX}return{p1:Z,p2:V}}function U$(W,X,G,Y){El(G,W),$l(Y,X);let J=G.length,Z=Y.length;if(J!==Z)throw Error("arrays of points and scalars must have equal length");let V=W.ZERO,U=Iq(BigInt(J)),Q=1;if(U>12)Q=U-3;else if(U>4)Q=U-2;else if(U>0)Q=2;let N=c6(Q),q=Array(Number(N)+1).fill(V),A=Math.floor((X.BITS-1)/Q)*Q,H=V;for(let I=A;I>=0;I-=Q){q.fill(V);for(let O=0;O<Z;O++){let T=Y[O],x=Number(T>>BigInt(I)&N);q[x]=q[x].add(G[O])}let w=V;for(let O=q.length-1,T=V;O>0;O--)T=T.add(q[O]),w=w.add(T);if(H=H.add(w),I!==0)for(let O=0;O<Q;O++)H=H.double()}return H}function Y$(W,X,G){if(X){if(X.ORDER!==W)throw Error("Field.ORDER must match order: Fp == p, Fn == n");return vj(X),X}else return $5(W,{isLE:G})}function Q$(W,X,G={},Y){if(Y===void 0)Y=W==="edwards";if(!X||typeof X!=="object")throw Error(`expected valid ${W} CURVE object`);for(let Q of["p","n","h"]){let N=X[Q];if(!(typeof N==="bigint"&&N>CY))throw Error(`CURVE.${Q} must be positive bigint`)}let J=Y$(X.p,G.Fp,Y),Z=Y$(X.n,G.Fn,Y),U=["Gx","Gy","a",W==="weierstrass"?"b":"d"];for(let Q of U)if(!J.isValid(X[Q]))throw Error(`CURVE.${Q} must be valid field element of CURVE.Fp`);return X=Object.freeze(Object.assign({},X)),{CURVE:X,Fp:J,Fn:Z}}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */var N$=(W,X)=>(W+(W>=0?X:-X)/H$)/X;function Fl(W,X,G){let[[Y,J],[Z,V]]=X,U=N$(V*W,G),Q=N$(-J*W,G),N=W-U*Y-Q*Z,q=-U*J-Q*V,A=N<x4,H=q<x4;if(A)N=-N;if(H)q=-q;let I=c6(Math.ceil(Iq(G)/2))+TY;if(N<x4||N>=I||q<x4||q>=I)throw Error("splitScalar (endomorphism): failed, k="+W);return{k1neg:A,k1:N,k2neg:H,k2:q}}function nj(W){if(!["compact","recovered","der"].includes(W))throw Error('Signature format must be "compact", "recovered", or "der"');return W}function oj(W,X){let G={};for(let Y of Object.keys(X))G[Y]=W[Y]===void 0?X[Y]:W[Y];if(PV(G.lowS,"lowS"),PV(G.prehash,"prehash"),G.format!==void 0)nj(G.format);return G}class q$ extends Error{constructor(W=""){super(W)}}var S4={Err:q$,_tlv:{encode:(W,X)=>{let{Err:G}=S4;if(W<0||W>256)throw new G("tlv.encode: wrong tag");if(X.length&1)throw new G("tlv.encode: unpadded data");let Y=X.length/2,J=RV(Y);if(J.length/2&128)throw new G("tlv.encode: long form length too big");let Z=Y>127?RV(J.length/2|128):"";return RV(W)+Z+J+X},decode(W,X){let{Err:G}=S4,Y=0;if(W<0||W>256)throw new G("tlv.encode: wrong tag");if(X.length<2||X[Y++]!==W)throw new G("tlv.decode: wrong tlv");let J=X[Y++],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 N=X.subarray(Y,Y+Q);if(N.length!==Q)throw new G("tlv.decode: length bytes not complete");if(N[0]===0)throw new G("tlv.decode(long): zero leftmost byte");for(let q of N)V=V<<8|q;if(Y+=Q,V<128)throw new G("tlv.decode(long): not minimal encoding")}let U=X.subarray(Y,Y+V);if(U.length!==V)throw new G("tlv.decode: wrong value length");return{v:U,l:X.subarray(Y+V)}}},_int:{encode(W){let{Err:X}=S4;if(W<x4)throw new X("integer: negative integers are not allowed");let G=RV(W);if(Number.parseInt(G[0],16)&8)G="00"+G;if(G.length&1)throw new X("unexpected DER parsing assertion: unpadded hex");return G},decode(W){let{Err:X}=S4;if(W[0]&128)throw new X("invalid signature integer: negative");if(W[0]===0&&!(W[1]&128))throw new X("invalid signature integer: unnecessary leading zero");return $4(W)}},toSig(W){let{Err:X,_int:G,_tlv:Y}=S4,J=F8("signature",W),{v:Z,l:V}=Y.decode(48,J);if(V.length)throw new X("invalid signature: left bytes after parsing");let{v:U,l:Q}=Y.decode(2,Z),{v:N,l:q}=Y.decode(2,Q);if(q.length)throw new X("invalid signature: left bytes after parsing");return{r:G.decode(U),s:G.decode(N)}},hexFromSig(W){let{_tlv:X,_int:G}=S4,Y=X.encode(2,G.encode(W.r)),J=X.encode(2,G.encode(W.s)),Z=Y+J;return X.encode(48,Z)}},x4=BigInt(0),TY=BigInt(1),H$=BigInt(2),Tq=BigInt(3),Sl=BigInt(4);function n6(W,X){let{BYTES:G}=W,Y;if(typeof X==="bigint")Y=X;else{let J=F8("private key",X);try{Y=W.fromBytes(J)}catch(Z){throw Error(`invalid private key: expected ui8a of size ${G}, got ${typeof X}`)}}if(!W.isValidNot0(Y))throw Error("invalid private key: out of range [1..N-1]");return Y}function xl(W,X={}){let G=Q$("weierstrass",W,X),{Fp:Y,Fn:J}=G,Z=G.CURVE,{h:V,n:U}=Z;BV(X,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",wrapPrivateKey:"boolean"});let{endo:Q}=X;if(Q){if(!Y.is0(Z.a)||typeof Q.beta!=="bigint"||!Array.isArray(Q.basises))throw Error('invalid endo: expected "beta": bigint and "basises": array')}let N=z$(Y,J);function q(){if(!Y.isOdd)throw Error("compression is not supported: Field does not have .isOdd()")}function A(g,d,P){let{x:E,y:f}=d.toAffine(),r=Y.toBytes(E);if(PV(P,"isCompressed"),P){q();let o=!Y.isOdd(f);return a9(A$(o),r)}else return a9(Uint8Array.of(4),r,Y.toBytes(f))}function H(g){p6(g,void 0,"Point");let{publicKey:d,publicKeyUncompressed:P}=N,E=g.length,f=g[0],r=g.subarray(1);if(E===d&&(f===2||f===3)){let o=Y.fromBytes(r);if(!Y.isValid(o))throw Error("bad point: is not on curve, wrong x");let B=O(o),S;try{S=Y.sqrt(B)}catch(R){let m=R instanceof Error?": "+R.message:"";throw Error("bad point: is not on curve, sqrt error"+m)}q();let _=Y.isOdd(S);if((f&1)===1!==_)S=Y.neg(S);return{x:o,y:S}}else if(E===P&&f===4){let o=Y.BYTES,B=Y.fromBytes(r.subarray(0,o)),S=Y.fromBytes(r.subarray(o,o*2));if(!T(B,S))throw Error("bad point: is not on curve");return{x:B,y:S}}else throw Error(`bad point: got length ${E}, expected compressed=${d} or uncompressed=${P}`)}let I=X.toBytes||A,w=X.fromBytes||H;function O(g){let d=Y.sqr(g),P=Y.mul(d,g);return Y.add(Y.add(P,Y.mul(g,Z.a)),Z.b)}function T(g,d){let P=Y.sqr(d),E=O(g);return Y.eql(P,E)}if(!T(Z.Gx,Z.Gy))throw Error("bad curve params: generator point");let x=Y.mul(Y.pow(Z.a,Tq),Sl),h=Y.mul(Y.sqr(Z.b),BigInt(27));if(Y.is0(Y.add(x,h)))throw Error("bad curve params: a or b");function $(g,d,P=!1){if(!Y.isValid(d)||P&&Y.is0(d))throw Error(`bad point coordinate ${g}`);return d}function F(g){if(!(g instanceof y))throw Error("ProjectivePoint expected")}function u(g){if(!Q||!Q.basises)throw Error("no endo");return Fl(g,Q.basises,J.ORDER)}let l=_j((g,d)=>{let{X:P,Y:E,Z:f}=g;if(Y.eql(f,Y.ONE))return{x:P,y:E};let r=g.is0();if(d==null)d=r?Y.ONE:Y.inv(f);let o=Y.mul(P,d),B=Y.mul(E,d),S=Y.mul(f,d);if(r)return{x:Y.ZERO,y:Y.ZERO};if(!Y.eql(S,Y.ONE))throw Error("invZ was invalid");return{x:o,y:B}}),p=_j((g)=>{if(g.is0()){if(X.allowInfinityPoint&&!Y.is0(g.Y))return;throw Error("bad point: ZERO")}let{x:d,y:P}=g.toAffine();if(!Y.isValid(d)||!Y.isValid(P))throw Error("bad point: x or y not field elements");if(!T(d,P))throw Error("bad point: equation left != right");if(!g.isTorsionFree())throw Error("bad point: not in prime-order subgroup");return!0});function s(g,d,P,E,f){return P=new y(Y.mul(P.X,g),P.Y,P.Z),d=FV(E,d),P=FV(f,P),d.add(P)}class y{constructor(g,d,P){this.X=$("x",g),this.Y=$("y",d,!0),this.Z=$("z",P),Object.freeze(this)}static CURVE(){return Z}static fromAffine(g){let{x:d,y:P}=g||{};if(!g||!Y.isValid(d)||!Y.isValid(P))throw Error("invalid affine point");if(g instanceof y)throw Error("projective point not allowed");if(Y.is0(d)&&Y.is0(P))return y.ZERO;return new y(d,P,Y.ONE)}static fromBytes(g){let d=y.fromAffine(w(p6(g,void 0,"point")));return d.assertValidity(),d}static fromHex(g){return y.fromBytes(F8("pointHex",g))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(g=8,d=!0){if(H0.createCache(this,g),!d)this.multiply(Tq);return this}assertValidity(){p(this)}hasEvenY(){let{y:g}=this.toAffine();if(!Y.isOdd)throw Error("Field doesn't support isOdd");return!Y.isOdd(g)}equals(g){F(g);let{X:d,Y:P,Z:E}=this,{X:f,Y:r,Z:o}=g,B=Y.eql(Y.mul(d,o),Y.mul(f,E)),S=Y.eql(Y.mul(P,o),Y.mul(r,E));return B&&S}negate(){return new y(this.X,Y.neg(this.Y),this.Z)}double(){let{a:g,b:d}=Z,P=Y.mul(d,Tq),{X:E,Y:f,Z:r}=this,o=Y.ZERO,B=Y.ZERO,S=Y.ZERO,_=Y.mul(E,E),v=Y.mul(f,f),R=Y.mul(r,r),m=Y.mul(E,f);return m=Y.add(m,m),S=Y.mul(E,r),S=Y.add(S,S),o=Y.mul(g,S),B=Y.mul(P,R),B=Y.add(o,B),o=Y.sub(v,B),B=Y.add(v,B),B=Y.mul(o,B),o=Y.mul(m,o),S=Y.mul(P,S),R=Y.mul(g,R),m=Y.sub(_,R),m=Y.mul(g,m),m=Y.add(m,S),S=Y.add(_,_),_=Y.add(S,_),_=Y.add(_,R),_=Y.mul(_,m),B=Y.add(B,_),R=Y.mul(f,r),R=Y.add(R,R),_=Y.mul(R,m),o=Y.sub(o,_),S=Y.mul(R,v),S=Y.add(S,S),S=Y.add(S,S),new y(o,B,S)}add(g){F(g);let{X:d,Y:P,Z:E}=this,{X:f,Y:r,Z:o}=g,B=Y.ZERO,S=Y.ZERO,_=Y.ZERO,v=Z.a,R=Y.mul(Z.b,Tq),m=Y.mul(d,f),J0=Y.mul(P,r),U0=Y.mul(E,o),q0=Y.add(d,P),$0=Y.add(f,r);q0=Y.mul(q0,$0),$0=Y.add(m,J0),q0=Y.sub(q0,$0),$0=Y.add(d,E);let u0=Y.add(f,o);return $0=Y.mul($0,u0),u0=Y.add(m,U0),$0=Y.sub($0,u0),u0=Y.add(P,E),B=Y.add(r,o),u0=Y.mul(u0,B),B=Y.add(J0,U0),u0=Y.sub(u0,B),_=Y.mul(v,$0),B=Y.mul(R,U0),_=Y.add(B,_),B=Y.sub(J0,_),_=Y.add(J0,_),S=Y.mul(B,_),J0=Y.add(m,m),J0=Y.add(J0,m),U0=Y.mul(v,U0),$0=Y.mul(R,$0),J0=Y.add(J0,U0),U0=Y.sub(m,U0),U0=Y.mul(v,U0),$0=Y.add($0,U0),m=Y.mul(J0,$0),S=Y.add(S,m),m=Y.mul(u0,$0),B=Y.mul(q0,B),B=Y.sub(B,m),m=Y.mul(q0,J0),_=Y.mul(u0,_),_=Y.add(_,m),new y(B,S,_)}subtract(g){return this.add(g.negate())}is0(){return this.equals(y.ZERO)}multiply(g){let{endo:d}=X;if(!J.isValidNot0(g))throw Error("invalid scalar: out of range");let P,E,f=(r)=>H0.cached(this,r,(o)=>Cq(y,o));if(d){let{k1neg:r,k1:o,k2neg:B,k2:S}=u(g),{p:_,f:v}=f(o),{p:R,f:m}=f(S);E=v.add(m),P=s(d.beta,_,R,r,B)}else{let{p:r,f:o}=f(g);P=r,E=o}return Cq(y,[P,E])[0]}multiplyUnsafe(g){let{endo:d}=X,P=this;if(!J.isValid(g))throw Error("invalid scalar: out of range");if(g===x4||P.is0())return y.ZERO;if(g===TY)return P;if(H0.hasCache(this))return this.multiply(g);if(d){let{k1neg:E,k1:f,k2neg:r,k2:o}=u(g),{p1:B,p2:S}=V$(y,P,f,o);return s(d.beta,B,S,E,r)}else return H0.unsafe(P,g)}multiplyAndAddUnsafe(g,d,P){let E=this.multiplyUnsafe(d).add(g.multiplyUnsafe(P));return E.is0()?void 0:E}toAffine(g){return l(this,g)}isTorsionFree(){let{isTorsionFree:g}=X;if(V===TY)return!0;if(g)return g(y,this);return H0.unsafe(this,U).is0()}clearCofactor(){let{clearCofactor:g}=X;if(V===TY)return this;if(g)return g(y,this);return this.multiplyUnsafe(V)}isSmallOrder(){return this.multiplyUnsafe(V).is0()}toBytes(g=!0){return PV(g,"isCompressed"),this.assertValidity(),I(y,this,g)}toHex(g=!0){return E4(this.toBytes(g))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}get px(){return this.X}get py(){return this.X}get pz(){return this.Z}toRawBytes(g=!0){return this.toBytes(g)}_setWindowSize(g){this.precompute(g)}static normalizeZ(g){return Cq(y,g)}static msm(g,d){return U$(y,J,g,d)}static fromPrivateKey(g){return y.BASE.multiply(n6(J,g))}}y.BASE=new y(Z.Gx,Z.Gy,Y.ONE),y.ZERO=new y(Y.ZERO,Y.ONE,Y.ZERO),y.Fp=Y,y.Fn=J;let t=J.BITS,H0=new dj(y,X.endo?Math.ceil(t/2):t);return y.BASE.precompute(8),y}function A$(W){return Uint8Array.of(W?2:3)}function z$(W,X){return{secretKey:X.BYTES,publicKey:1+W.BYTES,publicKeyUncompressed:1+2*W.BYTES,publicKeyHasPrefix:!0,signature:2*X.BYTES}}function kl(W,X={}){let{Fn:G}=W,Y=X.randomBytes||AX,J=Object.assign(z$(W.Fp,G),{seed:gj(G.ORDER)});function Z(I){try{return!!n6(G,I)}catch(w){return!1}}function V(I,w){let{publicKey:O,publicKeyUncompressed:T}=J;try{let x=I.length;if(w===!0&&x!==O)return!1;if(w===!1&&x!==T)return!1;return!!W.fromBytes(I)}catch(x){return!1}}function U(I=Y(J.seed)){return Kq(p6(I,J.seed,"seed"),G.ORDER)}function Q(I,w=!0){return W.BASE.multiply(n6(G,I)).toBytes(w)}function N(I){let w=U(I);return{secretKey:w,publicKey:Q(w)}}function q(I){if(typeof I==="bigint")return!1;if(I instanceof W)return!0;let{secretKey:w,publicKey:O,publicKeyUncompressed:T}=J;if(G.allowedLengths||w===O)return;let x=F8("key",I).length;return x===O||x===T}function A(I,w,O=!0){if(q(I)===!0)throw Error("first arg must be private key");if(q(w)===!1)throw Error("second arg must be public key");let T=n6(G,I);return W.fromHex(w).multiply(T).toBytes(O)}return Object.freeze({getPublicKey:Q,getSharedSecret:A,keygen:N,Point:W,utils:{isValidSecretKey:Z,isValidPublicKey:V,randomSecretKey:U,isValidPrivateKey:Z,randomPrivateKey:U,normPrivateKeyToScalar:(I)=>n6(G,I),precompute(I=8,w=W.BASE){return w.precompute(I,!1)}},lengths:J})}function _l(W,X,G={}){qq(X),BV(G,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});let Y=G.randomBytes||AX,J=G.hmac||((P,...E)=>fj(X,P,a9(...E))),{Fp:Z,Fn:V}=W,{ORDER:U,BITS:Q}=V,{keygen:N,getPublicKey:q,getSharedSecret:A,utils:H,lengths:I}=kl(W,G),w={prehash:!1,lowS:typeof G.lowS==="boolean"?G.lowS:!1,format:void 0,extraEntropy:!1},O="compact";function T(P){let E=U>>TY;return P>E}function x(P,E){if(!V.isValidNot0(E))throw Error(`invalid signature ${P}: out of range 1..Point.Fn.ORDER`);return E}function h(P,E){nj(E);let f=I.signature,r=E==="compact"?f:E==="recovered"?f+1:void 0;return p6(P,r,`${E} signature`)}class ${constructor(P,E,f){if(this.r=x("r",P),this.s=x("s",E),f!=null)this.recovery=f;Object.freeze(this)}static fromBytes(P,E=O){h(P,E);let f;if(E==="der"){let{r:S,s:_}=S4.toSig(p6(P));return new $(S,_)}if(E==="recovered")f=P[0],E="compact",P=P.subarray(1);let r=V.BYTES,o=P.subarray(0,r),B=P.subarray(r,r*2);return new $(V.fromBytes(o),V.fromBytes(B),f)}static fromHex(P,E){return this.fromBytes(HX(P),E)}addRecoveryBit(P){return new $(this.r,this.s,P)}recoverPublicKey(P){let E=Z.ORDER,{r:f,s:r,recovery:o}=this;if(o==null||![0,1,2,3].includes(o))throw Error("recovery id invalid");if(U*H$<E&&o>1)throw Error("recovery id is ambiguous for h>1 curve");let S=o===2||o===3?f+U:f;if(!Z.isValid(S))throw Error("recovery id 2 or 3 invalid");let _=Z.toBytes(S),v=W.fromBytes(a9(A$((o&1)===0),_)),R=V.inv(S),m=u(F8("msgHash",P)),J0=V.create(-m*R),U0=V.create(r*R),q0=W.BASE.multiplyUnsafe(J0).add(v.multiplyUnsafe(U0));if(q0.is0())throw Error("point at infinify");return q0.assertValidity(),q0}hasHighS(){return T(this.s)}toBytes(P=O){if(nj(P),P==="der")return HX(S4.hexFromSig(this));let E=V.toBytes(this.r),f=V.toBytes(this.s);if(P==="recovered"){if(this.recovery==null)throw Error("recovery bit must be present");return a9(Uint8Array.of(this.recovery),E,f)}return a9(E,f)}toHex(P){return E4(this.toBytes(P))}assertValidity(){}static fromCompact(P){return $.fromBytes(F8("sig",P),"compact")}static fromDER(P){return $.fromBytes(F8("sig",P),"der")}normalizeS(){return this.hasHighS()?new $(this.r,V.neg(this.s),this.recovery):this}toDERRawBytes(){return this.toBytes("der")}toDERHex(){return E4(this.toBytes("der"))}toCompactRawBytes(){return this.toBytes("compact")}toCompactHex(){return E4(this.toBytes("compact"))}}let F=G.bits2int||function(E){if(E.length>8192)throw Error("input is too large");let f=$4(E),r=E.length*8-Q;return r>0?f>>BigInt(r):f},u=G.bits2int_modN||function(E){return V.create(F(E))},l=c6(Q);function p(P){return $E("num < 2^"+Q,P,x4,l),V.toBytes(P)}function s(P,E){return p6(P,void 0,"message"),E?p6(X(P),void 0,"prehashed message"):P}function y(P,E,f){if(["recovered","canonical"].some((U0)=>(U0 in f)))throw Error("sign() legacy options not supported");let{lowS:r,prehash:o,extraEntropy:B}=oj(f,w);P=s(P,o);let S=u(P),_=n6(V,E),v=[p(_),p(S)];if(B!=null&&B!==!1){let U0=B===!0?Y(I.secretKey):B;v.push(F8("extraEntropy",U0))}let R=a9(...v),m=S;function J0(U0){let q0=F(U0);if(!V.isValidNot0(q0))return;let $0=V.inv(q0),u0=W.BASE.multiply(q0).toAffine(),H1=V.create(u0.x);if(H1===x4)return;let v1=V.create($0*V.create(m+H1*_));if(v1===x4)return;let h0=(u0.x===H1?0:2)|Number(u0.y&TY),F1=v1;if(r&&T(v1))F1=V.neg(v1),h0^=1;return new $(H1,F1,h0)}return{seed:R,k2sig:J0}}function t(P,E,f={}){P=F8("message",P);let{seed:r,k2sig:o}=y(P,E,f);return FE(X.outputLen,V.BYTES,J)(r,o)}function H0(P){let E=void 0,f=typeof P==="string"||qX(P),r=!f&&P!==null&&typeof P==="object"&&typeof P.r==="bigint"&&typeof P.s==="bigint";if(!f&&!r)throw Error("invalid signature, expected Uint8Array, hex string or Signature instance");if(r)E=new $(P.r,P.s);else if(f){try{E=$.fromBytes(F8("sig",P),"der")}catch(o){if(!(o instanceof S4.Err))throw o}if(!E)try{E=$.fromBytes(F8("sig",P),"compact")}catch(o){return!1}}if(!E)return!1;return E}function g(P,E,f,r={}){let{lowS:o,prehash:B,format:S}=oj(r,w);if(f=F8("publicKey",f),E=s(F8("message",E),B),"strict"in r)throw Error("options.strict was renamed to lowS");let _=S===void 0?H0(P):$.fromBytes(F8("sig",P),S);if(_===!1)return!1;try{let v=W.fromBytes(f);if(o&&_.hasHighS())return!1;let{r:R,s:m}=_,J0=u(E),U0=V.inv(m),q0=V.create(J0*U0),$0=V.create(R*U0),u0=W.BASE.multiplyUnsafe(q0).add(v.multiplyUnsafe($0));if(u0.is0())return!1;return V.create(u0.x)===R}catch(v){return!1}}function d(P,E,f={}){let{prehash:r}=oj(f,w);return E=s(E,r),$.fromBytes(P,"recovered").recoverPublicKey(E).toBytes()}return Object.freeze({keygen:N,getPublicKey:q,getSharedSecret:A,utils:H,lengths:I,Point:W,sign:t,verify:g,recoverPublicKey:d,Signature:$,hash:X})}function yl(W){let X={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,Y=W.allowedPrivateKeyLengths?Array.from(new Set(W.allowedPrivateKeyLengths.map((V)=>Math.ceil(V/2)))):void 0,J=$5(X.n,{BITS:W.nBitLength,allowedLengths:Y,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:X,curveOpts:Z}}function vl(W){let{CURVE:X,curveOpts:G}=yl(W),Y={hmac:W.hmac,randomBytes:W.randomBytes,lowS:W.lowS,bits2int:W.bits2int,bits2int_modN:W.bits2int_modN};return{CURVE:X,curveOpts:G,hash:W.hash,ecdsaOpts:Y}}function gl(W,X){let G=X.Point;return Object.assign({},X,{ProjectivePoint:G,CURVE:Object.assign({},W,jq(G.Fn.ORDER,G.Fn.BITS))})}function I$(W){let{CURVE:X,curveOpts:G,hash:Y,ecdsaOpts:J}=vl(W),Z=xl(X,G),V=_l(Z,Y,J);return gl(W,V)}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */function MY(W,X){let G=(Y)=>I$({...W,hash:Y});return{...G(X),create:G}}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */var w$={p:BigInt("0xffffffff00000001000000000000000000000000ffffffffffffffffffffffff"),n:BigInt("0xffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551"),h:BigInt(1),a:BigInt("0xffffffff00000001000000000000000000000000fffffffffffffffffffffffc"),b:BigInt("0x5ac635d8aa3a93e7b3ebbd55769886bc651d06b0cc53b0f63bce3c3e27d2604b"),Gx:BigInt("0x6b17d1f2e12c4247f8bce6e563a440f277037d812deb33a0f4a13945d898c296"),Gy:BigInt("0x4fe342e2fe1a7f9b8ee7eb4a7c0f9e162bce33576b315ececbb6406837bf51f5")},j$={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffeffffffff0000000000000000ffffffff"),n:BigInt("0xffffffffffffffffffffffffffffffffffffffffffffffffc7634d81f4372ddf581a0db248b0a77aecec196accc52973"),h:BigInt(1),a:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffeffffffff0000000000000000fffffffc"),b:BigInt("0xb3312fa7e23ee7e4988e056be3f82d19181d9c6efe8141120314088f5013875ac656398d8a2ed19d2a85c8edd3ec2aef"),Gx:BigInt("0xaa87ca22be8b05378eb1c71ef320ad746e1d3b628ba79b9859f741e082542a385502f25dbf55296c3a545e3872760ab7"),Gy:BigInt("0x3617de4a96262c6f5d9e98bf9292dc29f8f41dbd289a147ce9da3113b5f0b8c00a60b1ce1d7e819d7a431d7c90ea0e5f")},K$={p:BigInt("0x1ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),n:BigInt("0x01fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffa51868783bf2f966b7fcc0148f709a5d03bb5c9b8899c47aebb6fb71e91386409"),h:BigInt(1),a:BigInt("0x1fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc"),b:BigInt("0x0051953eb9618e1c9a1f929a21a0b68540eea2da725b99b315f3b8b489918ef109e156193951ec7e937b1652c0bd3bb1bf073573df883d2c34f1ef451fd46b503f00"),Gx:BigInt("0x00c6858e06b70404e9cd9e3ecb662395b4429c648139053fb521f828af606b4d3dbaa14b5e77efe75928fe1dc127a2ffa8de3348b3c1856a429bf97e7e31c2e5bd66"),Gy:BigInt("0x011839296a789a3bc0045c8a5fb42c7d1bd998f54449579b446817afbd17273e662c97ee72995ef42640c550b9013fad0761353c7086a272c24088be94769fd16650")},ul=$5(w$.p),hl=$5(j$.p),bl=$5(K$.p);var O$=MY({...w$,Fp:ul,lowS:!1},DY);var dq0=MY({...j$,Fp:hl,lowS:!1},W$);var oq0=MY({...K$,Fp:bl,lowS:!1,allowedPrivateKeyLengths:[130,131,132]},eE);/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */var Mq=O$;var U9=b1(D8(),1),Z7=b1(D8(),1),n2=b1(D8(),1),MX=b1(D8(),1),l4=b1(D8(),1),e2=b1(yQ(),1),RX=b1(D8(),1),a6=b1(D8(),1),LX=b1(D8(),1),lY=b1(D8(),1),s6=b1(D8(),1),BX=b1(D8(),1),V7=b1(D8(),1),U7=b1(D8(),1),jH=b1(D8(),1),J7=b1(D8(),1),US=b1(D8(),1),bo=b1(M$(),1);import{randomBytes as Co}from"crypto";import{setTimeout as To}from"timers/promises";import{createCipheriv as ko,createDecipheriv as _o}from"crypto";var hq=b1(R$(),1),EX=b1(D8(),1),CX=b1(D8(),1),o7=b1(D8(),1),l7=b1(D8(),1),$X=b1(D8(),1);import{createHmac as QK}from"crypto";import{createCipheriv as HF,createDecipheriv as AF,createHmac as zF,timingSafeEqual as wn}from"crypto";import{createCipheriv as KF,createDecipheriv as OF}from"crypto";import{setTimeout as Ln}from"timers/promises";import{randomBytes as Sn}from"crypto";import{createHmac as ES}from"crypto";import{randomBytes as $S}from"crypto";var Bq="undefined",EY=Bq!==typeof Buffer&&Buffer,BY=Bq!==typeof Uint8Array&&Uint8Array,Lq=Bq!==typeof ArrayBuffer&&ArrayBuffer,L$=[0,0,0,0,0,0,0,0],pl=Array.isArray||al,LY=4294967296,cl=16777216,$Y,Eq=E$("Uint64BE",!0,!0),aj=E$("Int64BE",!0,!1);function E$(W,X,G){var Y=X?0:4,J=X?4:0,Z=X?0:3,V=X?1:2,U=X?2:1,Q=X?3:0,N=X?ol:il,q=X?nl:rl,A=w.prototype,H="is"+W,I="_"+H;if(A.buffer=void 0,A.offset=0,A[I]=!0,A.toNumber=h,A.toString=$,A.toJSON=h,A.toArray=ll,EY)A.toBuffer=dl;if(BY)A.toArrayBuffer=$$;return w[H]=O,w;function w(l,p,s,y){if(!(this instanceof w))return new w(l,p,s,y);return T(this,l,p,s,y)}function O(l){return!!(l&&l[I])}function T(l,p,s,y,t){if(BY&&Lq){if(p instanceof Lq)p=new BY(p);if(y instanceof Lq)y=new BY(y)}if(!p&&!s&&!y&&!$Y){l.buffer=F$(L$,0);return}if(!B$(p,s)){var H0=$Y||Array;t=s,y=p,s=0,p=$Y===EY?EY.alloc(8):new H0(8)}if(l.buffer=p,l.offset=s|=0,Bq===typeof y)return;if(typeof y==="string")x(p,s,y,t||10);else if(B$(y,t))rj(p,s,y,t);else if(typeof t==="number")F(p,s+Y,y),F(p,s+J,t);else if(y>0)N(p,s,y);else if(y<0)q(p,s,y);else rj(p,s,L$,0)}function x(l,p,s,y){var t=0,H0=s.length,g=0,d=0;if(s[0]==="-")t++;var P=t;while(t<H0){var E=parseInt(s[t++],y);if(!(E>=0))break;d=d*y+E,g=g*y+Math.floor(d/LY),d%=LY}if(P)if(g=~g,d)d=LY-d;else g++;F(l,p+Y,g),F(l,p+J,d)}function h(){var l=this.buffer,p=this.offset,s=u(l,p+Y),y=u(l,p+J);if(!G)s|=0;return s?s*LY+y:y}function $(l){var p=this.buffer,s=this.offset,y=u(p,s+Y),t=u(p,s+J),H0="",g=!G&&y&2147483648;if(g)y=~y,t=LY-t;l=l||10;while(!0){var d=y%l*LY+t;if(y=Math.floor(y/l),t=Math.floor(d/l),H0=(d%l).toString(l)+H0,!y&&!t)break}if(g)H0="-"+H0;return H0}function F(l,p,s){l[p+Q]=s&255,s=s>>8,l[p+U]=s&255,s=s>>8,l[p+V]=s&255,s=s>>8,l[p+Z]=s&255}function u(l,p){return l[p+Z]*cl+(l[p+V]<<16)+(l[p+U]<<8)+l[p+Q]}}function ll(W){var X=this.buffer,G=this.offset;if($Y=null,W!==!1&&pl(X))return X.length===8?X:X.slice(G,G+8);return F$(X,G)}function dl(W){var X=this.buffer,G=this.offset;if($Y=EY,W!==!1&&EY.isBuffer(X))return X.length===8?X:X.slice(G,G+8);return EY.from($$.call(this,W))}function $$(W){var X=this.buffer,G=this.offset,Y=X.buffer;if($Y=BY,W!==!1&&!X.offset&&Y instanceof Lq)return Y.byteLength===8?Y:Y.slice(G,G+8);var J=new BY(8);return rj(J,0,X,G),J.buffer}function B$(W,X){var G=W&&W.length;return X|=0,G&&X+8<=G&&typeof W[X]!=="string"}function rj(W,X,G,Y){X|=0,Y|=0;for(var J=0;J<8;J++)W[X++]=G[Y++]&255}function F$(W,X){return Array.prototype.slice.call(W,X,X+8)}function ol(W,X,G){var Y=X+8;while(Y>X)W[--Y]=G&255,G/=256}function nl(W,X,G){var Y=X+8;G++;while(Y>X)W[--Y]=-G&255^255,G/=256}function il(W,X,G){var Y=X+8;while(X<Y)W[X++]=G&255,G/=256}function rl(W,X,G){var Y=X+8;G++;while(X<Y)W[X++]=-G&255^255,G/=256}function al(W){return!!W&&Object.prototype.toString.call(W)=="[object Array]"}var tV=b1(tj(),1);import{createHash as rn}from"crypto";import{setTimeout as an}from"timers/promises";import{createHash as Ji}from"crypto";import{isIPv4 as hF}from"net";import{randomBytes as Zi}from"crypto";import{isIPv4 as bF}from"net";var pq=b1(k$(),1),gS=b1(n$(),1),hS=b1(tj(),1);import*as uK from"timers/promises";import{randomUUID as Ui}from"crypto";import*as uS from"os";import{EventEmitter as Oi}from"events";import{randomUUID as Fi}from"crypto";import{setTimeout as KK}from"timers/promises";import{createHash as Si}from"crypto";import{performance as kq}from"perf_hooks";import{randomUUID as xi}from"crypto";import{randomUUID as aS}from"crypto";import{setTimeout as ei}from"timers/promises";import{randomBytes as Yr}from"crypto";import{isIPv4 as Jr}from"net";var eV=b1(bz(),1);import{randomUUID as Zr}from"crypto";import{setTimeout as Vr}from"timers/promises";import{randomUUID as Hr}from"crypto";import{randomUUID as jr}from"crypto";import{createHmac as Z2,randomBytes as Kr}from"crypto";import{randomBytes as K2}from"crypto";import{randomUUID as O2}from"crypto";import{setTimeout as D2}from"timers/promises";import{randomUUID as dr}from"crypto";function R2(){return X8.Unpack("!H",P2(2))[0]}function PK(){return X8.Unpack("!L",P2(4))[0]}var aq=class{constructor(W){this.bitLength=W}value=0;set(W,X,G){return G&=(1<<W)-1,this.value|=G<<this.bitLength-W-X,this}get buffer(){let W=Math.ceil(this.bitLength/8),X=Buffer.alloc(W);return X.writeUIntBE(this.value,0,W),X}},L2=class{constructor(W){if(this.bitLength=W,W>32)throw Error()}_value=0n;offset=0n;set(W,X=1){let G=BigInt(W),Y=BigInt(X);return G&=(1n<<Y)-1n,this._value|=G<<BigInt(this.bitLength)-Y-this.offset,this.offset+=Y,this}get value(){return Number(this._value)}get buffer(){let W=Math.ceil(this.bitLength/8),X=Buffer.alloc(W);return X.writeUIntBE(this.value,0,W),X}};function b8(W,X,G=1){let Y=W.toString(2).split("");Y=[...Array(8-Y.length).fill("0"),...Y];let J=Y.slice(X,X+G).join("");return Number.parseInt(J,2)}function S8(W,X){return gq(W)(X)}function gq(W,X){let G=W.reduce((J,Z)=>J+Z,0),Y=X?Buffer.alloc(G):void 0;return(J)=>{let Z=Y||Buffer.alloc(G),V=0;return J.forEach((U,Q)=>{let N=W[Q];if(N===8)Z.writeBigUInt64BE(U,V);else Z.writeUIntBE(U,V,N);V+=N}),Z}}function e9(W,X){let G=0;return X.map((Y)=>{let J;if(Y===8)J=W.readBigUInt64BE(G);else J=W.readUIntBE(G,Y);return G+=Y,J})}var lV=class{constructor(W){this.uint8Array=W}position=0;bitsPending=0;writeBits(W,X){if(W==0)return this;X&=4294967295>>>32-W;let G;if(this.bitsPending>0)if(this.bitsPending>W)this.uint8Array[this.position-1]|=X<<this.bitsPending-W,G=W,this.bitsPending-=W;else if(this.bitsPending==W)this.uint8Array[this.position-1]|=X,G=W,this.bitsPending=0;else this.uint8Array[this.position-1]|=X>>W-this.bitsPending,G=this.bitsPending,this.bitsPending=0;else G=Math.min(8,W),this.bitsPending=8-G,this.uint8Array[this.position++]=X>>W-G<<this.bitsPending;if(W-=G,W>0)this.writeBits(W,X);return this}readBits(W){return this._readBits(W)}_readBits(W,X){if(typeof X>"u")X=0;if(W==0)return X;let G,Y;if(this.bitsPending>0){let J=this.uint8Array[this.position-1]&255>>8-this.bitsPending;Y=Math.min(this.bitsPending,W),this.bitsPending-=Y,G=J>>this.bitsPending}else Y=Math.min(8,W),this.bitsPending=8-Y,G=this.uint8Array[this.position++]>>this.bitsPending;return W-=Y,X=X<<Y|G,W>0?this._readBits(W,X):X}seekTo(W){if(this.position=W/8|0,this.bitsPending=W%8,this.bitsPending>0)this.bitsPending=8-this.bitsPending,this.position++}},bd=3988292384,md=2197175160;function B2(W){return typeof W!=="string"}function E2(W){let X=Array(256),G=0;for(let Y=0;Y<256;++Y)G=Y,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,X[Y]=G;return new Int32Array(X)}function $2(W){let X=new Int32Array(4096),G=0,Y=0,J=0;for(J=0;J<256;++J)X[J]=W[J];for(J=0;J<256;++J){Y=W[J];for(G=256+J;G<4096;G+=256)Y=X[G]=Y>>>8^W[Y&255]}let Z=[];for(J=1;J<16;++J)Z[J-1]=X.subarray(J*256,J*256+256);return Z}function F2(W,X,G){let Y=X^-1,J=0,Z=W.length,V=0,U=0;while(J<Z)if(V=W.charCodeAt(J++),V<128)Y=Y>>>8^G[(Y^V)&255];else if(V<2048)Y=Y>>>8^G[(Y^(192|V>>6&31))&255],Y=Y>>>8^G[(Y^(128|V&63))&255];else if(V>=55296&&V<57344)V=(V&1023)+64,U=W.charCodeAt(J++)&1023,Y=Y>>>8^G[(Y^(240|V>>8&7))&255],Y=Y>>>8^G[(Y^(128|V>>2&63))&255],Y=Y>>>8^G[(Y^(128|U>>6&15|(V&3)<<4))&255],Y=Y>>>8^G[(Y^(128|U&63))&255];else Y=Y>>>8^G[(Y^(224|V>>12&15))&255],Y=Y>>>8^G[(Y^(128|V>>6&63))&255],Y=Y>>>8^G[(Y^(128|V&63))&255];return~Y>>>0}function S2(W,X,G,Y){let[J,Z,V,U,Q,N,q,A,H,I,w,O,T,x,h]=Y,$=X^-1,F=0,u=W.length-15;while(F<u)$=h[W[F++]^$&255]^x[W[F++]^$>>>8&255]^T[W[F++]^$>>>16&255]^O[W[F++]^$>>>24]^w[W[F++]]^I[W[F++]]^H[W[F++]]^A[W[F++]]^q[W[F++]]^N[W[F++]]^Q[W[F++]]^U[W[F++]]^V[W[F++]]^Z[W[F++]]^J[W[F++]]^G[W[F++]];for(u+=15;F<u;)$=$>>>8^G[($^W[F++])&255];return~$>>>0}var RK=E2(bd),fd=$2(RK),LK=E2(md),pd=$2(LK);function cd(W,X=0){if(B2(W))return S2(W,X,RK,fd);return F2(W,X,RK)}function x2(W,X=0){if(B2(W))return S2(W,X,LK,pd);return F2(W,X,LK)}function ld(W,X){return W+X&255}function R9(W,X){return W+X&65535}function uY(W,X){return Number(BigInt(W)+BigInt(X)&0xffffffffn)}function dd(W){return W&16777215}function k2(W,X){return W<X&&X-W>32768||W>X&&W-X<32768}function c4(W,X){return W<X&&X-W>2147483648||W>X&&W-X<2147483648}function fV(W,X){return W===X||c4(W,X)}var dV=(W)=>Number.parseInt(W,10);var _2=(W,X)=>X?X[W]:void 0;async function nd(W,X,G="udp4",Y){let J;for(let Z=W;Z<=X;Z++){let V=od(G);if(setImmediate(()=>V.bind({port:Z,address:_2(G,Y)})),await new Promise((Q)=>{V.once("error",(N)=>Q(N)),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<=X)break}if(!J)throw Error("port not found");return J}function sq(W){if(W==="IPv4")return 4;if(W==="IPv6")return 6;return W}var P1=y2.default.debug,d0=class{event={stack:[],promiseStack:[],eventId:0};ended=!1;onended;onerror=(W)=>{};execute=(...W)=>{if(this.ended)return;for(let X of this.event.stack)X.execute(...W);(async()=>{for(let X of this.event.promiseStack)await X.execute(...W)})().catch((X)=>{this.onerror(X)})};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 X of this.event.stack)if(X.error)X.error(W);this.allUnsubscribe()};allUnsubscribe=()=>{if(this.ended)throw Error("event completed");this.event={stack:[],promiseStack:[],eventId:0}};subscribe=(W,X,G)=>{let Y=this.event.eventId;this.event.stack.push({execute:W,id:Y,complete:X,error:G}),this.event.eventId++;let J=()=>{this.event.stack=this.event.stack.filter((V)=>V.id!==Y&&V)};return{unSubscribe:J,disposer:(V)=>{V.push(J)}}};pipe(W){this.subscribe((...X)=>{W.execute(...X)})}queuingSubscribe=(W,X,G)=>{if(this.ended)throw Error("event completed");let Y=this.event.eventId;this.event.promiseStack.push({execute:W,id:Y,complete:X,error:G}),this.event.eventId++;let J=()=>{this.event.stack=this.event.stack.filter((V)=>V.id!==Y&&V)};return{unSubscribe:J,disposer:(V)=>{V.push(J)}}};once=(W,X,G)=>{let Y=this.subscribe((...J)=>{Y.unSubscribe(),W(...J)},X,G)};watch=(W,X)=>new Promise((G,Y)=>{let J=X&&setTimeout(()=>{Y("Event watch timeout")},X),{unSubscribe:Z}=this.subscribe((...V)=>{if(W(...V)){if(J)clearTimeout(J);Z(),G(V)}})});asPromise=(W)=>new Promise((X,G)=>{let Y=W&&setTimeout(()=>{G("Event asPromise timeout")},W);this.once((...J)=>{if(Y)clearTimeout(Y);X(J)},()=>{if(Y)clearTimeout(Y);X([])},(J)=>{if(Y)clearTimeout(Y);G(J)})});get returnTrigger(){let{execute:W,error:X,complete:G}=this;return{execute:W,error:X,complete:G}}get returnListener(){let{subscribe:W,once:X,asPromise:G}=this;return{subscribe:W,once:X,asPromise:G}}get length(){return this.event.stack.length}},id=class{_disposer=[];push(W){this._disposer.push(W)}dispose(){this._disposer.forEach((W)=>W()),this._disposer=[]}},i$=P1("werift-ice:packages/ice/src/transport.ts"),BK=class W{constructor(X,G={}){this.socketType=X,this.options=G,this.socket=rd(X),this.socket.on("message",(Y,J)=>{if(sq(J.family)===6)[J.address]=J.address.split("%");this.rinfo=J;try{this.onData(Y,[J.address,J.port])}catch(Z){i$("onData error",Z)}})}type="udp";socket;rinfo;onData=()=>{};closed=!1;static async init(X,G={}){let Y=new W(X,G);return await Y.init(),Y}async init(){let X=_2(this.socketType,this.options.interfaceAddresses);if(this.options.port)this.socket.bind({port:this.options.port,address:X});else if(this.options.portRange){let G=await nd(this.options.portRange[0],this.options.portRange[1],this.socketType,this.options.interfaceAddresses);this.socket.bind({port:G,address:X})}else this.socket.bind({address:X});await new Promise((G)=>this.socket.once("listening",G))}send=async(X,G)=>{if(G&&!v2.isIP(G[0]))return new Promise((Y,J)=>{this.socket.send(X,G[1],G[0],(Z)=>{if(Z)i$("send error",G,X),J(Z);else Y()})});else G=G??[this.rinfo?.address,this.rinfo?.port],this.socket.send(X,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((X)=>{this.closed=!0,this.socket.once("close",X);try{this.socket.close()}catch(G){X()}})},sd=class W{constructor(X){this.addr=X,this.connect()}type="tcp";connecting;client;onData=()=>{};closed=!1;connect(){if(this.closed)return;if(this.client)this.client.destroy();this.connecting=new Promise((X,G)=>{try{this.client=ad({port:this.addr[1],host:this.addr[0]},X)}catch(Y){G(Y)}}),this.client.on("data",(X)=>{let G=[this.client.remoteAddress,this.client.remotePort];this.onData(X,G)}),this.client.on("end",()=>{this.connect()}),this.client.on("error",(X)=>{console.log("error",X)})}async init(){await this.connecting}static async init(X){let G=new W(X);return await G.init(),G}get address(){return{}}send=async(X,G)=>{await this.connecting,this.client.write(X,(Y)=>{if(Y)console.log("err",Y)})};close=async()=>{this.closed=!0,this.client.destroy()}},o4={rsa_1:1,ecdsa_3:3},tq={sha256_4:4},EK={TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256_49195:49195,TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256_49199:49199},Xo=Object.values(EK),t6={x25519_29:29,secp256r1_23:23},g2=Object.values(t6),u2={named_curve_3:3},r$={rsa_pkcs1_sha256:1025,ecdsa_secp256r1_sha256:1027},Go=[1,64],h2=[{hash:tq.sha256_4,signature:o4.rsa_1},{hash:tq.sha256_4,signature:o4.ecdsa_3}],Zo=()=>{let W=Mq.utils.randomPrivateKey(),X=Mq.getPublicKey(W,!1),G=Buffer.from(W),Y=Buffer.from(X);return{privateKey:G,publicKey:Y}},Vo=({publicKey:W,privateKey:X})=>{let G=Mq.getSharedSecret(X,W);return Buffer.from(G).subarray(1)};function f2(W,X,G){switch(G){case t6.secp256r1_23:return Vo({publicKey:W,privateKey:X});case t6.x25519_29:return Buffer.from(m2.default.scalarMult(X,W));default:throw Error()}}function a$(W,X,G){let Y=Jo(W,X);return Y.update(G),Y.digest()}function XU(W,X,G,Y="sha256"){let J=G,Z=[],V=X;do{V=a$(Y,W,V);let U=a$(Y,W,Buffer.concat([V,X]));Z.push(U),G-=U.length}while(G>0);return Buffer.concat(Z,J)}function p2(W,X,G){let Y=Buffer.concat([Buffer.from("master secret"),X,G]);return XU(W,Y,48)}function c2(W,X){let G=l2("sha256",X),Y="extended master secret";return XU(W,Buffer.concat([Buffer.from("extended master secret"),G]),48)}function Uo(W,X,G,Y,J,Z){let V=Z?Y:J,U=Z?J:Y,Q=Buffer.concat([Buffer.from(W),V,U]);return XU(G,Q,X)}function l2(W,X){return Yo(W).update(X).digest()}function d2(W,X,G,Y=12){let J=l2("sha256",X);return XU(W,Buffer.concat([Buffer.from(G),J]),Y)}function Qo(W,X){return d2(W,X,"client finished")}function No(W,X){return d2(W,X,"server finished")}function qo(W,X,G,Y,J,Z,V="sha256"){let U=Y*2+J*2,Q=W,N=Buffer.concat([G,X]),q=XU(Q,Buffer.concat([Buffer.from("key expansion"),N]),U,V),A=b2.createDecode(q),H=A.readBuffer(Y),I=A.readBuffer(Y),w=A.readBuffer(J),O=A.readBuffer(J),T=Buffer.alloc(Z,0),x=Buffer.alloc(Z,0);return w.copy(T,0),O.copy(x,0),{clientWriteKey:H,serverWriteKey:I,clientNonce:T,serverNonce:x}}var d4={CLIENT:1,SERVER:2},Ho=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}},$K=Wo;u8.set($K);var eq=class{constructor(W,X,G,Y){if(this.sessionType=W,this.certPem=X,this.keyPem=G,X&&G&&Y)this.parseX509(X,G,Y)}localRandom;remoteRandom;cipherSuite;remoteCertificate;remoteKeyPair;localKeyPair;masterSecret;cipher;namedCurve;signatureHashAlgorithm;localCert;localPrivateKey;static createSelfSignedCertificateWithKey=async(W,X)=>{let G=(()=>{switch(W.signature){case o4.rsa_1:return"RSASSA-PKCS1-v1_5";case o4.ecdsa_3:return"ECDSA"}})(),Y=(()=>{switch(W.hash){case tq.sha256_4:return"SHA-256"}})(),J=(()=>{switch(X){case t6.secp256r1_23:return"P-256";case t6.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:Y,namedCurve:J};case"RSASSA-PKCS1-v1_5":return{name:G,hash:Y,publicExponent:new Uint8Array([1,0,1]),modulusLength:2048}}})(),V=await $K.subtle.generateKey(Z,!0,["sign","verify"]),Q=(await Kj.createSelfSigned({serialNumber:ed(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"),N=T9.encode(await $K.subtle.exportKey("pkcs8",V.privateKey),"private key");return{certPem:Q,keyPem:N,signatureHash:W}};encryptPacket(W){let X=W.recordLayerHeader,G=X.protocolVersion.major<<8|X.protocolVersion.minor,Y=this.cipher.encrypt(this.sessionType,W.fragment,{type:X.contentType,version:G,epoch:X.epoch,sequenceNumber:X.sequenceNumber});return W.fragment=Y,W.recordLayerHeader.contentLen=Y.length,W}decryptPacket(W){let X=W.recordLayerHeader,G=X.protocolVersion.major<<8|X.protocolVersion.minor;return this.cipher.decrypt(this.sessionType,W.fragment,{type:X.contentType,version:G,epoch:X.epoch,sequenceNumber:X.sequenceNumber})}verifyData(W){if(this.sessionType===d4.CLIENT)return Qo(this.masterSecret,W);else return No(this.masterSecret,W)}signatureData(W,X){let G=td(X).update(W),Y=this.localPrivateKey.toPEM().toString();return G.sign(Y)}generateKeySignature(W){let X=this.sessionType===d4.CLIENT?this.localRandom:this.remoteRandom,G=this.sessionType===d4.SERVER?this.localRandom:this.remoteRandom,Y=this.valueKeySignature(X.serialize(),G.serialize(),this.localKeyPair.publicKey,this.namedCurve);return this.localPrivateKey.sign(Y,W)}parseX509(W,X,G){let Y=AH.Certificate.fromPEM(Buffer.from(W)),J=AH.PrivateKey.fromPEM(Buffer.from(X));this.localCert=Y.raw,this.localPrivateKey=J,this.signatureHashAlgorithm=G}valueKeySignature(W,X,G,Y){let J=Buffer.from(hY.encode({type:u2.named_curve_3,curve:Y,len:G.length},{type:hY.types.uint8,curve:hY.types.uint16be,len:hY.types.uint8}).slice());return Buffer.concat([W,X,J,G])}},WH=class{srtpProfile;static findMatchingSRTPProfile(W,X){for(let G of X)if(W.includes(G))return G}},GO=(W)=>"0x"+W.toString("hex").replace(/(.)(.)/g,"$1$2 ").split(" ").filter((X)=>X!=null&&X.length>0).join(",0x"),o2=(W)=>Object.entries({...W}).reduce((X,[G,Y])=>{if(typeof Y==="number"||typeof Y==="string")X[G]=Y;if(Buffer.isBuffer(Y))X[G]=GO(Y);return X},{}),F5=class W{constructor(X,G,Y,J,Z,V){this.msg_type=X,this.length=G,this.message_seq=Y,this.fragment_offset=J,this.fragment_length=Z,this.fragment=V}static spec={msg_type:Z7.types.uint8,length:Z7.types.uint24be,message_seq:Z7.types.uint16be,fragment_offset:Z7.types.uint24be,fragment_length:Z7.types.uint24be,fragment:Z7.types.buffer((X)=>X.current.fragment_length)};get summary(){return o2(this)}static createEmpty(){return new W(void 0,void 0,void 0,void 0,void 0,void 0)}static deSerialize(X){return new W(...Object.values(Z7.decode(X,W.spec)))}serialize(){let X=Z7.encode(this,W.spec).slice();return Buffer.from(X)}chunk(X){let G=0,Y=this.fragment.length;if(Y===0)return[new W(this.msg_type,Y,this.message_seq,G,0,this.fragment)];let J=[];if(!X)X=1240;while(G<Y){let Z=Math.min(X,Y-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,Y,this.message_seq,G,V.length,V)),G+=V.length}return J}static assemble(X){if(!X?.length)throw Error("cannot reassemble handshake from empty array");X=X.sort((Y,J)=>Y.fragment_offset-J.fragment_offset);let G=Buffer.alloc(X[0].length);for(let Y of X)Y.fragment.copy(G,Y.fragment_offset);return new W(X[0].msg_type,X[0].length,X[0].message_seq,0,G.length,G)}static findAllFragments(X,G){let Y=X.find((J)=>J.msg_type===G);if(!Y)return[];if(!X?.length)return[];return X.filter((J)=>{return J.msg_type===Y.msg_type&&J.message_seq===Y.message_seq&&J.length===Y.length})}},{uint16be:XH,uint24be:Ao,buffer:i2,array:zo,uint8:iV,string:Io}=n2.types,wo={type:XH,data:i2(XH)},FK=zo(wo,XH,"bytes"),jo=i2(Ao),Ko=iV,Oo=Io(XH),Do={hash:iV,signature:iV},YO={major:iV,minor:iV},PX=class W{constructor(X=Math.floor(Date.now()/1000),G=Co(28)){this.gmt_unix_time=X,this.random_bytes=G}static spec={gmt_unix_time:MX.types.uint32be,random_bytes:MX.types.buffer(28)};static deSerialize(X){return new W(...Object.values(MX.decode(X,W.spec)))}static from(X){return new W(...Object.values(X))}serialize(){let X=MX.encode(this,W.spec).slice();return Buffer.from(X)}},r2=class W{constructor(X,G,Y,J,Z,V,U){this.clientVersion=X,this.random=G,this.sessionId=Y,this.cookie=J,this.cipherSuites=Z,this.compressionMethods=V,this.extensions=U}msgType=1;messageSeq=0;static spec={clientVersion:{major:U9.types.uint8,minor:U9.types.uint8},random:PX.spec,sessionId:U9.types.buffer(U9.types.uint8),cookie:U9.types.buffer(U9.types.uint8),cipherSuites:U9.types.array(U9.types.uint16be,U9.types.uint16be,"bytes"),compressionMethods:U9.types.array(U9.types.uint8,U9.types.uint8,"bytes"),extensions:FK};static createEmpty(){return new W(void 0,void 0,void 0,void 0,void 0,void 0,void 0)}static deSerialize(X){return new W(...Object.values(U9.decode(X,W.spec)))}serialize(){let X=U9.encode(this,W.spec).slice();return Buffer.from(X)}toFragment(){let X=this.serialize();return new F5(this.msgType,X.length,this.messageSeq,0,X.length,X)}},Mo=class W{constructor(X,G,Y,J,Z){this.epoch=X,this.sequenceNumber=G,this.contentType=Y,this.protocolVersion=J,this.contentLen=Z}static spec={epoch:l4.types.uint16be,sequenceNumber:l4.types.uint48be,contentType:l4.types.uint8,protocolVersion:YO,contentLen:l4.types.uint16be};static createEmpty(){return new W(void 0,void 0,void 0,void 0,void 0)}static deSerialize(X){return new W(...Object.values(l4.decode(X,W.spec)))}serialize(){let X=l4.encode(this,W.spec).slice();return Buffer.from(X)}},a2=class W{constructor(X,G){this.recordLayerHeader=X,this.fragment=G}get summary(){return{header:this.recordLayerHeader,fragment:GO(this.fragment)}}static createEmpty(){return new W(void 0,void 0)}static deSerialize(X){if(X.length<13)throw Error("Invalid DTLS record: buffer is too short");let G=X.readUInt8(0),Y=X.readUInt8(1),J=X.readUInt8(2),Z=X.readUInt16BE(3),V=X.slice(5,11).readUIntBE(0,6),U=X.readUInt16BE(11);if(X.length<13+U)throw Error("Invalid DTLS record: fragment length exceeds buffer");let Q=X.slice(13,13+U);return new W({contentType:G,protocolVersion:{major:Y,minor:J},epoch:Z,sequenceNumber:V,contentLen:U},Q)}serialize(){let X=this.fragment.length,G=13+X,Y=Buffer.alloc(G);return Y.writeUInt8(this.recordLayerHeader.contentType,0),Y.writeUInt8(this.recordLayerHeader.protocolVersion.major,1),Y.writeUInt8(this.recordLayerHeader.protocolVersion.minor,2),Y.writeUInt16BE(this.recordLayerHeader.epoch,3),Y.writeUIntBE(this.recordLayerHeader.sequenceNumber,5,6),Y.writeUInt16BE(X,11),this.fragment.copy(Y,13),Y}computeMACHeader(){return new Mo(this.recordLayerHeader.epoch,this.recordLayerHeader.sequenceNumber,this.recordLayerHeader.contentType,this.recordLayerHeader.protocolVersion,this.recordLayerHeader.contentLen).serialize()}},s2=(W)=>(X)=>{return W.lastFlight=X,X.flatMap((G)=>{return G.messageSeq=W.sequenceNumber++,G.toFragment().chunk()})},GU=(W)=>(X,G)=>{return X.map((Y)=>{return new a2({contentType:Y.type,protocolVersion:W.version,epoch:W.epoch,sequenceNumber:G,contentLen:Y.fragment.length},Y.fragment)})},SK=((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})(SK||{}),Po=P1("werift-dtls : packages/dtls/src/flight/flight.ts : warn"),UK=P1("werift-dtls : packages/dtls/src/flight/flight.ts : err"),YU=class W{constructor(X,G,Y,J){this.transport=X,this.dtls=G,this.flight=Y,this.nextFlight=J}state="PREPARING";static RetransmitCount=10;createPacket(X){let G=s2(this.dtls)(X);return this.dtls.bufferHandshakeCache(G,!0,this.flight),GU(this.dtls)(G.map((J)=>({type:22,fragment:J.serialize()})),++this.dtls.recordSequenceNumber)}async transmit(X){let G=0;for(;G<=W.RetransmitCount;G++){if(this.setState("SENDING"),this.send(X).catch((Y)=>{UK("fail to send",UK)}),this.setState("WAITING"),this.nextFlight===void 0){this.setState("FINISHED");break}if(await To(1000*((G+1)/2)),this.dtls.flight>=this.nextFlight){this.setState("FINISHED");break}else Po(this.dtls.sessionId,"retransmit",G,this.dtls.flight)}if(G>W.RetransmitCount)throw UK(this.dtls.sessionId,"retransmit failed",G),Error(`over retransmitCount : ${this.flight} ${this.nextFlight}`)}send=(X)=>Promise.all(X.map((G)=>this.transport.send(G)));setState(X){this.state=X}},Ro=class extends YU{constructor(W,X,G){super(W,X,1,3);this.cipher=G}async exec(W){if(this.dtls.flight===1)throw Error();this.dtls.flight=1;let X=new r2({major:254,minor:253},new PX,Buffer.from([]),Buffer.from([]),Xo,[0],W);this.dtls.version=X.clientVersion,this.cipher.localRandom=PX.from(X.random);let G=this.createPacket([X]),Y=Buffer.concat(G.map((J)=>J.serialize()));await this.transmit([Y])}},Lo=P1("werift-dtls : packages/dtls/src/flight/client/flight3.ts : log"),Bo=class extends YU{constructor(W,X){super(W,X,3,5)}async exec(W){if(this.dtls.flight===3)throw Error();this.dtls.flight=3,this.dtls.handshakeCache=[];let[X]=this.dtls.lastFlight;Lo("dtls version",X.clientVersion),X.cookie=W.cookie,this.dtls.cookie=W.cookie;let G=this.createPacket([X]),Y=Buffer.concat(G.map((J)=>J.serialize()));await this.transmit([Y])}},zH={NULL:0,ECDHE:1},JU={NULL:0,RSA:1,ECDSA:2,PSK:3},ZU={NULL:0,RSA:1,ECDHE_RSA:2,ECDHE_ECDSA:3,PSK:4,ECDHE_PSK:5},VU=class{id=0;name;signType;keyType;toString(){return this.name}};function Eo(){let W=new VU;return W.id=ZU.RSA,W.name="RSA",W.keyType=JU.RSA,W}function $o(){let W=new VU;return W.id=ZU.ECDHE_RSA,W.name="ECDHE_RSA",W.signType=zH.ECDHE,W.keyType=JU.RSA,W}function Fo(){let W=new VU;return W.id=ZU.ECDHE_ECDSA,W.name="ECDHE_ECDSA",W.signType=zH.ECDHE,W.keyType=JU.ECDSA,W}function So(){let W=new VU;return W.id=ZU.PSK,W.name="PSK",W.signType=zH.NULL,W.keyType=JU.PSK,W}function xo(){let W=new VU;return W.id=ZU.ECDHE_PSK,W.name="ECDHE_PSK",W.signType=zH.ECDHE,W.keyType=JU.PSK,W}var yo=P1("werift-dtls : packages/dtls/src/cipher/suites/aead.ts : err"),vo=class extends Ho{keyLength=0;nonceLength=0;ivLength=0;authTagLength=0;nonceImplicitLength=0;nonceExplicitLength=0;clientWriteKey;serverWriteKey;clientNonce;serverNonce;constructor(){super()}get summary(){return o2(this)}init(W,X,G){let Y=qo(W,G,X,this.keyLength,this.ivLength,this.nonceLength,this.hashAlgorithm);this.clientWriteKey=Y.clientWriteKey,this.serverWriteKey=Y.serverWriteKey,this.clientNonce=Y.clientNonce,this.serverNonce=Y.serverNonce}encrypt(W,X,G){let Y=W===d4.CLIENT,J=Y?this.clientNonce:this.serverNonce,Z=Y?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,X.length),Q=ko(this.blockAlgorithm,Z,J,{authTagLength:this.authTagLength});Q.setAAD(U,{plaintextLength:X.length});let N=Q.update(X),q=Q.final(),A=Q.getAuthTag();return Buffer.concat([V,N,q,A])}encodeAdditionalBuffer(W,X){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(X,11),G}decrypt(W,X,G){let Y=W===d4.CLIENT,J=Y?this.serverNonce:this.clientNonce,Z=Y?this.serverWriteKey:this.clientWriteKey;if(!J||!Z)throw Error();X.subarray(0,this.nonceExplicitLength).copy(J,this.nonceImplicitLength);let U=X.subarray(this.nonceExplicitLength,X.length-this.authTagLength),Q=X.subarray(X.length-this.authTagLength),N=this.encodeAdditionalBuffer(G,U.length),q=_o(this.blockAlgorithm,Z,J,{authTagLength:this.authTagLength});q.setAuthTag(Q),q.setAAD(N,{plaintextLength:U.length});let A=q.update(U);try{let H=q.final();return H.length>0?Buffer.concat([A,H]):A}catch(H){throw yo("decrypt failed",H,W,GO(X),G,this.summary),H}}},h8={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},_V={K_LEN:16,N_MIN:12,N_MAX:12,P_MAX:68719476705,A_MAX:9007199254740991,C_MAX:68719476721},yV={K_LEN:32,N_MIN:12,N_MAX:12,P_MAX:68719476705,A_MAX:9007199254740991,C_MAX:68719476721},s$=Eo(),t$=$o(),e$=Fo(),WF=So(),XF=xo();function t2(W){switch(W){case h8.TLS_RSA_WITH_AES_128_GCM_SHA256:return p7(h8.TLS_RSA_WITH_AES_128_GCM_SHA256,"TLS_RSA_WITH_AES_128_GCM_SHA256","aes-128-gcm",s$,_V);case h8.TLS_RSA_WITH_AES_256_GCM_SHA384:return p7(h8.TLS_RSA_WITH_AES_256_GCM_SHA384,"TLS_RSA_WITH_AES_256_GCM_SHA384","aes-256-gcm",s$,yV,"sha384");case h8.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256:return p7(h8.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,"TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256","aes-128-gcm",t$,_V);case h8.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384:return p7(h8.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,"TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384","aes-256-gcm",t$,yV,"sha384");case h8.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256:return p7(h8.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,"TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256","aes-128-gcm",e$,_V);case h8.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384:return p7(h8.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,"TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384","aes-256-gcm",e$,yV,"sha384");case h8.TLS_PSK_WITH_AES_128_GCM_SHA256:return p7(h8.TLS_PSK_WITH_AES_128_GCM_SHA256,"TLS_PSK_WITH_AES_128_GCM_SHA256","aes-128-gcm",WF,_V,"sha256");case h8.TLS_PSK_WITH_AES_256_GCM_SHA384:return p7(h8.TLS_PSK_WITH_AES_256_GCM_SHA384,"TLS_PSK_WITH_AES_256_GCM_SHA384","aes-256-gcm",WF,yV,"sha384");case h8.TLS_ECDHE_PSK_WITH_AES_128_GCM_SHA256:return p7(h8.TLS_ECDHE_PSK_WITH_AES_128_GCM_SHA256,"TLS_ECDHE_PSK_WITH_AES_128_GCM_SHA256","aes-128-gcm",XF,_V,"sha256");case h8.TLS_ECDHE_PSK_WITH_AES_256_GCM_SHA384:return p7(h8.TLS_ECDHE_PSK_WITH_AES_256_GCM_SHA384,"TLS_ECDHE_PSK_WITH_AES_256_GCM_SHA384","aes-256-gcm",XF,yV,"sha384");default:break}return null}function p7(W,X,G,Y,J,Z="sha256"){let V=new vo;return V.id=W,V.name=X,V.blockAlgorithm=G,V.kx=Y,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 WS(W){switch(W){case t6.secp256r1_23:{let{privateKey:X,publicKey:G}=Zo();return{curve:W,privateKey:X,publicKey:G}}case t6.x25519_29:{let X=e2.default.box.keyPair();return{curve:W,privateKey:Buffer.from(X.secretKey.buffer),publicKey:Buffer.from(X.publicKey.buffer)}}default:throw Error()}}var IH=class{static type=23},wH=class W{static type=65281;static spec={type:RX.types.uint16be,data:RX.types.uint8};type=W.type;data=0;constructor(X={}){Object.assign(this,X)}static createEmpty(){return new W}static deSerialize(X){return new W(RX.decode(X,W.spec))}serialize(){let X=RX.encode(this,W.spec).slice();return Buffer.from(X)}get extension(){return{type:this.type,data:this.serialize().slice(2)}}},bY=class W{static type=14;static spec={type:a6.types.uint16be,data:a6.types.buffer(a6.types.uint16be)};type=W.type;data=Buffer.from([]);profiles=[];mki=Buffer.from([0]);constructor(X={}){Object.assign(this,X)}static create(X,G){return new W({profiles:X,mki:G})}static deSerialize(X){let G=new W(a6.decode(X,W.spec)),Y=G.data.readUInt16BE(),J=Array(Y/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(Y+2),G}serialize(){let X=Buffer.alloc(2);X.writeUInt16BE(this.profiles.length*2);let G=Buffer.concat([X,...this.profiles.map((J)=>{let Z=Buffer.alloc(2);return Z.writeUInt16BE(J),Z}),this.mki]);this.data=G;let Y=a6.encode(this,W.spec).slice();return Buffer.from(Y)}static fromData(X){let G=Buffer.alloc(4);return G.writeUInt16BE(W.type),G.writeUInt16BE(X.length,2),W.deSerialize(Buffer.concat([G,X]))}get extension(){return{type:this.type,data:this.serialize().slice(4)}}},GH=class W{constructor(X){this.certificateList=X}msgType=11;messageSeq;static spec={certificateList:LX.types.array(jo,LX.types.uint24be,"bytes")};static createEmpty(){return new W(void 0)}static deSerialize(X){return new W(...Object.values(LX.decode(X,W.spec)))}serialize(){let X=LX.encode(this,W.spec).slice();return Buffer.from(X)}toFragment(){let X=this.serialize();return new F5(this.msgType,X.length,this.messageSeq,0,X.length,X)}},XS=class W{constructor(X=1){this.type=X}static spec={type:lY.types.uint8};static createEmpty(){return new W}static deSerialize(X){return new W(...Object.values(lY.decode(X,W.spec)))}serialize(){let X=lY.encode(this,W.spec).slice();return Buffer.from(X)}},GS=class W{constructor(X,G){this.algorithm=X,this.signature=G}msgType=15;messageSeq;static spec={algorithm:s6.types.uint16be,signature:s6.types.buffer(s6.types.uint16be)};static createEmpty(){return new W(void 0,void 0)}static deSerialize(X){let G=s6.decode(X,W.spec);return new W(...Object.values(G))}serialize(){let X=s6.encode(this,W.spec).slice();return Buffer.from(X)}toFragment(){let X=this.serialize();return new F5(this.msgType,X.length,this.messageSeq,0,X.length,X)}},YS=class W{constructor(X){this.publicKey=X}msgType=16;messageSeq;static spec={publicKey:BX.types.buffer(BX.types.uint8)};static createEmpty(){return new W(void 0)}static deSerialize(X){let G=BX.decode(X,W.spec);return new W(...Object.values(G))}serialize(){let X=BX.encode(this,W.spec).slice();return Buffer.from(X)}toFragment(){let X=this.serialize();return new F5(this.msgType,X.length,this.messageSeq,0,X.length,X)}},xK=class W{constructor(X){this.verifyData=X}msgType=20;messageSeq;static createEmpty(){return new W(void 0)}static deSerialize(X){return new W(X)}serialize(){return this.verifyData}toFragment(){let X=this.serialize();return new F5(this.msgType,X.length,this.messageSeq,0,X.length,X)}},JS=class W{constructor(X,G,Y){this.certificateTypes=X,this.signatures=G,this.authorities=Y}msgType=13;messageSeq;static spec={certificateTypes:V7.types.array(Ko,V7.types.uint8,"bytes"),signatures:V7.types.array(Do,V7.types.uint16be,"bytes"),authorities:V7.types.array(Oo,V7.types.uint16be,"bytes")};static createEmpty(){return new W(void 0,void 0,void 0)}static deSerialize(X){return new W(...Object.values(V7.decode(X,W.spec)))}serialize(){let X=V7.encode(this,W.spec).slice();return Buffer.from(X)}toFragment(){let X=this.serialize();return new F5(this.msgType,X.length,this.messageSeq,0,X.length,X)}},ZS=class W{constructor(X,G,Y,J,Z,V){this.serverVersion=X,this.random=G,this.sessionId=Y,this.cipherSuite=J,this.compressionMethod=Z,this.extensions=V}msgType=2;messageSeq;static spec={serverVersion:YO,random:PX.spec,sessionId:U7.types.buffer(U7.types.uint8),cipherSuite:U7.types.uint16be,compressionMethod:U7.types.uint8};static createEmpty(){return new W(void 0,void 0,void 0,void 0,void 0,void 0)}static deSerialize(X){let G=U7.decode(X,W.spec),Y=new W(...Object.values(G));if(Y.serialize().length<X.length)return new W(...Object.values(U7.decode(X,{...W.spec,extensions:FK})));return Y}serialize(){let X=this.extensions===void 0?U7.encode(this,W.spec).slice():U7.encode(this,{...W.spec,extensions:FK}).slice();return Buffer.from(X)}toFragment(){let X=this.serialize();return new F5(this.msgType,X.length,this.messageSeq,0,X.length,X)}},VS=class W{msgType=14;messageSeq;static spec={};static createEmpty(){return new W}static deSerialize(X){return new W(...Object.values(jH.decode(X,W.spec)))}serialize(){let X=jH.encode(this,W.spec).slice();return Buffer.from(X)}toFragment(){let X=this.serialize();return new F5(this.msgType,X.length,this.messageSeq,0,X.length,X)}};function go(W,X){return Buffer.from(US.encode(W,X).slice())}var QS=class W{constructor(X,G,Y,J,Z,V,U,Q){this.ellipticCurveType=X,this.namedCurve=G,this.publicKeyLength=Y,this.publicKey=J,this.hashAlgorithm=Z,this.signatureAlgorithm=V,this.signatureLength=U,this.signature=Q}msgType=12;messageSeq;static spec={ellipticCurveType:J7.types.uint8,namedCurve:J7.types.uint16be,publicKeyLength:J7.types.uint8,publicKey:J7.types.buffer((X)=>X.current.publicKeyLength),hashAlgorithm:J7.types.uint8,signatureAlgorithm:J7.types.uint8,signatureLength:J7.types.uint16be,signature:J7.types.buffer((X)=>X.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(X){let G=J7.decode(X,W.spec);return new W(...Object.values(G))}serialize(){return go(this,W.spec)}toFragment(){let X=this.serialize();return new F5(this.msgType,X.length,this.messageSeq,0,X.length,X)}},KH=1,UU=7;var uo=(W)=>{switch(W){case KH:case UU:return 16}},ho=(W)=>{switch(W){case KH:return 14;case UU:return 12}},iH0=P1("werift-rtp : packages/rtp/src/codec/av1.ts");var mo={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"},rH0=Object.entries(mo).reduce((W,[X,G])=>{return W[G]=Number(X),W},{});var aH0=Buffer.from([0,0,0,1]);function GF(W,X){let G=Buffer.alloc(X);return W.copy(G),G}function YH(W){return Number.parseInt(W.toString(),10)}function fo(W){let X=W[0];return X>127&&X<192}var kK=4,XW=class W{version=2;padding=!1;count=0;type=0;length=0;constructor(X={}){Object.assign(this,X)}static serialize(X,G,Y,J){let V=new W({type:X,count:G,version:2,length:J}).serialize();return Buffer.concat([V,Y])}serialize(){let X=new aq(8);if(X.set(2,0,this.version),this.padding)X.set(1,2,1);return X.set(5,3,this.count),S8([1,1,2],[X.value,this.type,this.length])}static deSerialize(X){let[G,Y,J]=e9(X,[1,1,2]),Z=b8(G,0,2),V=b8(G,2,1)>0,U=b8(G,3,5);return new W({version:Z,padding:V,count:U,type:Y,length:J})}},YF=class W{static count=4;count=W.count;senderSsrc;mediaSsrc;fir=[];constructor(X={}){Object.assign(this,X)}get length(){return Math.floor(this.serialize().length/4-1)}static deSerialize(X){let[G,Y]=e9(X,[4,4]),J=[];for(let Z=8;Z<X.length;Z+=8)J.push({ssrc:X.readUInt32BE(Z),sequenceNumber:X[Z+4]});return new W({senderSsrc:G,mediaSsrc:Y,fir:J})}serialize(){let X=S8([4,4],[this.senderSsrc,this.mediaSsrc]),G=Buffer.alloc(this.fir.length*8);return this.fir.forEach(({ssrc:Y,sequenceNumber:J},Z)=>{G.writeUInt32BE(Y,Z*8),G[Z*8+4]=J}),Buffer.concat([X,G])}},JH=class W{static count=1;count=W.count;length=2;senderSsrc;mediaSsrc;constructor(X={}){Object.assign(this,X)}static deSerialize(X){let[G,Y]=e9(X,[4,4]);return new W({senderSsrc:G,mediaSsrc:Y})}serialize(){return S8([4,4],[this.senderSsrc,this.mediaSsrc])}},ZH=class W{static count=15;length;count=W.count;senderSsrc;mediaSsrc;uniqueID="REMB";ssrcNum=0;brExp;brMantissa;bitrate;ssrcFeedbacks=[];constructor(X={}){Object.assign(this,X)}static deSerialize(X){let[G,Y,J,Z,V]=e9(X,[4,4,4,1,1]),U=b8(V,0,6),Q=(b8(V,6,2)<<16)+(X[14]<<8)+X[15],N=U>46?18446744073709551615n:BigInt(Q)<<BigInt(U),q=[];for(let A=16;A<X.length;A+=4){let H=X.slice(A).readUIntBE(0,4);q.push(H)}return new W({senderSsrc:G,mediaSsrc:Y,uniqueID:S8([4],[J]).toString(),ssrcNum:Z,brExp:U,brMantissa:Q,ssrcFeedbacks:q,bitrate:N})}serialize(){let X=Buffer.concat([S8([4,4],[this.senderSsrc,this.mediaSsrc]),Buffer.from(this.uniqueID),S8([1],[this.ssrcNum])]),G=new aq(24);G.set(6,0,this.brExp).set(18,6,this.brMantissa);let Y=Buffer.concat(this.ssrcFeedbacks.map((Z)=>S8([4],[Z]))),J=Buffer.concat([X,S8([3],[G.value]),Y]);return this.length=J.length/4,J}},po=P1("werift-rtp: /rtcp/psfb/index"),rV=class W{static type=206;type=W.type;feedback;constructor(X={}){Object.assign(this,X)}serialize(){let X=this.feedback.serialize();return XW.serialize(this.type,this.feedback.count,X,this.feedback.length)}static deSerialize(X,G){let Y;switch(G.count){case YF.count:Y=YF.deSerialize(X);break;case JH.count:Y=JH.deSerialize(X);break;case ZH.count:Y=ZH.deSerialize(X);break;default:po("unknown psfb packet",G.count);break}return new W({feedback:Y})}},aV=class W{ssrc=0;reports=[];static type=201;type=W.type;constructor(X={}){Object.assign(this,X)}serialize(){let X=S8([4],[this.ssrc]);return X=Buffer.concat([X,...this.reports.map((G)=>G.serialize())]),XW.serialize(W.type,this.reports.length,X,Math.floor(X.length/4))}static deSerialize(X,G){let[Y]=e9(X,[4]),J=4,Z=[];for(let V=0;V<G;V++)Z.push(JO.deSerialize(X.slice(J,J+24))),J+=24;return new W({ssrc:Y,reports:Z})}},JO=class W{ssrc;fractionLost;packetsLost;highestSequence;jitter;lsr;dlsr;constructor(X={}){Object.assign(this,X)}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 S8([4,1,3,4,4,4,4],[this.ssrc,this.fractionLost,this.packetsLost,this.highestSequence,this.jitter,this.lsr,this.dlsr])}static deSerialize(X){let[G,Y,J,Z,V,U,Q]=e9(X,[4,1,3,4,4,4,4]);return new W({ssrc:G,fractionLost:Y,packetsLost:J,highestSequence:Z,jitter:V,lsr:U,dlsr:Q})}},NS=205,VH=class W{static count=1;count=W.count;header;senderSsrc;mediaSourceSsrc;lost=[];toJSON(){return{lost:this.lost,senderSsrc:this.senderSsrc,mediaSourceSsrc:this.mediaSourceSsrc}}constructor(X={}){if(Object.assign(this,X),!this.header)this.header=new XW({type:NS,count:this.count,version:2})}static deSerialize(X,G){let[Y,J]=e9(X,[4,4]),Z=[];for(let V=8;V<X.length;V+=4){let[U,Q]=e9(X.subarray(V),[2,2]);Z.push(U);for(let N=0;N<16;N++)if(Q>>N&1)Z.push(U+N+1)}return new W({header:G,senderSsrc:Y,mediaSourceSsrc:J,lost:Z})}serialize(){let X=S8([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(S8([2,2],[J,Z])),J=V,Z=0}),G.push(S8([2,2],[J,Z]))}let Y=Buffer.concat([X,Buffer.concat(G)]);return this.header.length=Y.length/4,Buffer.concat([this.header.serialize(),Y])}},co=P1("werift/rtp/rtcp/rtpfb/twcc"),UH=class W{static count=15;count=W.count;length=2;senderSsrc;mediaSourceSsrc;baseSequenceNumber;packetStatusCount;referenceTime;fbPktCount;packetChunks=[];recvDeltas=[];header;constructor(X={}){if(Object.assign(this,X),!this.header)this.header=new XW({type:205,count:this.count,version:2})}static deSerialize(X,G){let[Y,J,Z,V,U,Q]=e9(X,[4,4,2,2,3,1]),N=[],q=[],A=16;for(let I=0;I<V;){let w=b8(X.slice(A,A+1)[0],0,1),O;switch(w){case 0:{let T=oV.deSerialize(X.slice(A,A+2));O=T;let x=Math.min(V-I,T.runLength);if(T.packetStatus===1||T.packetStatus===2)for(let h=0;h<x;h++)q.push(new uq({type:T.packetStatus}));I+=x}break;case 1:{let T=lo.deSerialize(X.slice(A,A+2));if(O=T,T.symbolSize===0)T.symbolList.forEach((x)=>{if(x===1)q.push(new uq({type:1}))});if(T.symbolSize===1)T.symbolList.forEach((x)=>{if(x===1||x===2)q.push(new uq({type:x}))});I+=T.symbolList.length}break}if(!O)throw Error();A+=2,N.push(O)}let H=A;return q.forEach((I)=>{if(I.type===1)I.deSerialize(X.slice(H,H+1)),H++;if(I.type===2)I.deSerialize(X.slice(H,H+2)),H+=2}),new W({senderSsrc:Y,mediaSourceSsrc:J,baseSequenceNumber:Z,packetStatusCount:V,referenceTime:U,fbPktCount:Q,recvDeltas:q,packetChunks:N,header:G})}serialize(){let X=S8([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())),Y=Buffer.concat(this.recvDeltas.map((Z)=>{try{return Z.serialize()}catch(V){co(V?.message);return}}).filter((Z)=>Z)),J=Buffer.concat([X,G,Y]);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 X=this.baseSequenceNumber-1,G=this.packetChunks.filter((V)=>V instanceof oV).flatMap((V)=>V.results(X)),Y=0,Z=BigInt(this.referenceTime)*64n;for(let V of G){let U=this.recvDeltas[Y];if(!V.received||!U)continue;Z+=BigInt(U.delta)/1000n,V.delta=U.delta,V.receivedAtMs=Number(Z),Y++}return G}},oV=class W{type;packetStatus;runLength;constructor(X={}){Object.assign(this,X),this.type=0}static deSerialize(X){let G=b8(X[0],1,2),Y=(b8(X[0],3,5)<<8)+X[1];return new W({type:0,packetStatus:G,runLength:Y})}serialize(){return new L2(16).set(0).set(this.packetStatus,2).set(this.runLength,13).buffer}results(X){let G=this.packetStatus===1||this.packetStatus===2,Y=[];for(let J=0;J<=this.runLength;++J)Y.push(new oo({sequenceNumber:++X,received:G}));return Y}},lo=class W{type;symbolSize;symbolList=[];constructor(X={}){Object.assign(this,X)}static deSerialize(X){let Y=b8(X[0],1,1),J=[];function Z(V,U){for(let Q=0;Q<V;Q++)U(Q)}switch(Y){case 0:Z(6,(V)=>J.push(b8(X[0],2+V,1))),Z(8,(V)=>J.push(b8(X[1],V,1)));break;case 1:Z(3,(V)=>J.push(b8(X[0],2+V*2,2))),Z(4,(V)=>J.push(b8(X[1],V*2,2)));break;default:Y=(b8(X[0],2,6)<<8)+X[1]}return new W({type:1,symbolSize:Y,symbolList:J})}serialize(){let X=Buffer.alloc(2),G=new L2(16).set(1).set(this.symbolSize),Y=this.symbolSize===0?1:2;return this.symbolList.forEach((J)=>{G.set(J,Y)}),X.writeUInt16BE(G.value),X}},uq=class W{type;delta;constructor(X={}){Object.assign(this,X)}static deSerialize(X){let G,Y;if(X.length===1)G=1,Y=250*X[0];else if(X.length===2)G=2,Y=250*X.readInt16BE();if(G===void 0||Y===void 0)throw Error();return new W({type:G,delta:Y})}deSerialize(X){let G=W.deSerialize(X);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 X=Buffer.alloc(1);return X.writeUInt8(this.delta),X}else if(this.type===2){let X=Buffer.alloc(2);return X.writeInt16BE(this.delta),X}throw Error("errDeltaExceedLimit "+this.delta+" "+this.type)}};var oo=class{sequenceNumber=0;delta=0;received=!1;receivedAtMs=0;constructor(W){Object.assign(this,W)}},no=P1("werift-rtp:packages/rtp/rtcp/rtpfb/index"),mY=class W{static type=NS;type=W.type;feedback;header;constructor(X={}){Object.assign(this,X)}serialize(){return this.feedback.serialize()}static deSerialize(X,G){let Y;switch(G.count){case VH.count:Y=VH.deSerialize(X,G);break;case UH.count:Y=UH.deSerialize(X,G);break;default:no("unknown rtpfb packet",G.count);break}return new W({feedback:Y,header:G})}},QH=class W{static type=202;type=W.type;chunks=[];constructor(X){Object.assign(this,X)}get length(){let X=0;return this.chunks.forEach((G)=>X+=G.length),X}serialize(){let X=Buffer.concat(this.chunks.map((G)=>G.serialize()));while(X.length%4)X=Buffer.concat([X,Buffer.from([0])]);return XW.serialize(this.type,this.chunks.length,X,X.length/4)}static deSerialize(X,G){let Y=[];for(let J=0;J<X.length;){let Z=qS.deSerialize(X.slice(J));Y.push(Z),J+=Z.length}return new W({chunks:Y})}},qS=class W{source;items=[];constructor(X={}){Object.assign(this,X)}get length(){let X=4;return this.items.forEach((G)=>X+=G.length),X+=1,X+=JF(X),X}serialize(){let X=Buffer.concat([S8([4],[this.source]),Buffer.concat(this.items.map((Y)=>Y.serialize()))]);return Buffer.concat([X,Buffer.alloc(JF(X.length))])}static deSerialize(X){let G=X.readUInt32BE(),Y=[];for(let J=4;J<X.length;){if(X[J]===0)break;let V=HS.deSerialize(X.slice(J));Y.push(V),J+=V.length}return new W({source:G,items:Y})}},HS=class W{type;text;constructor(X){Object.assign(this,X)}get length(){return 2+Buffer.from(this.text).length}serialize(){let X=Buffer.from(this.text);return Buffer.concat([S8([1,1],[this.type,X.length]),X])}static deSerialize(X){let G=X[0],Y=X[1],J=X.slice(2,2+Y).toString();return new W({type:G,text:J})}};function JF(W){if(W%4==0)return 0;return 4-W%4}var fY=class W{ssrc=0;senderInfo;reports=[];static type=200;type=W.type;constructor(X){Object.assign(this,X)}toJSON(){return{ssrc:this.ssrc,senderInfo:this.senderInfo.toJSON(),reports:this.reports.map((X)=>X.toJSON())}}serialize(){let X=Buffer.alloc(4);return X.writeUInt32BE(this.ssrc),X=Buffer.concat([X,this.senderInfo.serialize()]),X=Buffer.concat([X,...this.reports.map((G)=>G.serialize())]),XW.serialize(W.type,this.reports.length,X,Math.floor(X.length/4))}static deSerialize(X,G){let Y=X.readUInt32BE(),J=AS.deSerialize(X.subarray(4,24)),Z=24,V=[];for(let Q=0;Q<G;Q++)V.push(JO.deSerialize(X.subarray(Z,Z+24))),Z+=24;return new W({ssrc:Y,senderInfo:J,reports:V})}},AS=class W{ntpTimestamp;rtpTimestamp;packetCount;octetCount;constructor(X={}){Object.assign(this,X)}toJSON(){return{ntpTimestamp:io(this.ntpTimestamp),rtpTimestamp:this.rtpTimestamp}}serialize(){return S8([8,4,4,4],[this.ntpTimestamp,this.rtpTimestamp,this.packetCount,this.octetCount])}static deSerialize(X){let[G,Y,J,Z]=e9(X,[8,4,4,4]);return new W({ntpTimestamp:G,rtpTimestamp:Y,packetCount:J,octetCount:Z})}},io=(W)=>{let[X,G]=e9(S8([8],[W]),[4,4]);return Number(`${X}.${G}`)},ro=P1("werift-rtp:packages/rtp/src/rtcp/rtcp.ts"),ao=class{static deSerialize(W){let X=0,G=[];while(X<W.length){let Y=XW.deSerialize(W.subarray(X,X+kK));X+=kK;let J=W.subarray(X);if(X+=Y.length*4,Y.padding)J=J.subarray(0,J.length-J.subarray(-1)[0]);try{switch(Y.type){case fY.type:G.push(fY.deSerialize(J,Y.count));break;case aV.type:G.push(aV.deSerialize(J,Y.count));break;case QH.type:G.push(QH.deSerialize(J,Y));break;case mY.type:G.push(mY.deSerialize(J,Y));break;case rV.type:G.push(rV.deSerialize(J,Y));break;default:break}}catch(Z){ro("deSerialize RTCP",Z)}}return G}};function so(W){return W.length>=2&&W[1]>=192&&W[1]<=208}var P9={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 to(W,X){return W.map((G)=>{let Y=X[G.id];if(!Y)return{uri:"unknown",value:G.payload};switch(Y){case P9.sdesMid:case P9.sdesRTPStreamID:case P9.repairedRtpStreamId:return{uri:Y,value:Jn(G.payload)};case P9.transportWideCC:return{uri:Y,value:Zn(G.payload)};case P9.absSendTime:return{uri:Y,value:Vn(G.payload)};case P9.audioLevelIndication:return{uri:Y,value:Un(G.payload)};case P9.videoOrientation:return{uri:Y,value:Qn(G.payload)};default:return{uri:Y,value:G.payload}}}).reduce((G,Y)=>{if(Y)G[Y.uri]=Y.value;return G},{})}function eo(W){return Buffer.from(W)}function Wn(W){return Buffer.from(W)}function Xn(W){return Buffer.from(W)}function Gn(W){return S8([2],[W])}function Yn(W){let X=Buffer.alloc(3),G=W>>14n&0x00ffffffn;return X.writeUIntBE(Number(G),0,3),X}function Jn(W){return W.toString()}function Zn(W){return W.readUInt16BE()}function Vn(W){return e9(W,[3])[0]}function Un(W){let X=new lV(W);return{v:X.readBits(1)===1,level:X.readBits(7)}}function Qn(W){let X=new lV(W);return X.readBits(4),{c:X.readBits(1),f:X.readBits(1),r1:X.readBits(1),r0:X.readBits(1)}}var Nn=P1("packages/rtp/src/rtp/red/packet.ts"),zS=class W{header;blocks=[];static deSerialize(X){let G=X instanceof ArrayBuffer?Buffer.from(X):X,Y=new W,J=0;return[Y.header,J]=ZF.deSerialize(G),Y.header.fields.forEach(({blockLength:Z,timestampOffset:V,blockPT:U})=>{if(Z&&V){let Q=G.subarray(J,J+Z);Y.blocks.push({block:Q,blockPT:U,timestampOffset:V}),J+=Z}else{let Q=G.subarray(J);Y.blocks.push({block:Q,blockPT:U})}}),Y}serialize(){this.header=new ZF;for(let{timestampOffset:G,blockPT:Y,block:J}of this.blocks)if(G)this.header.fields.push({fBit:1,blockPT:Y,blockLength:J.length,timestampOffset:G});else this.header.fields.push({fBit:0,blockPT:Y});let X=this.header.serialize();for(let{block:G}of this.blocks)X=Buffer.concat([X,G]);return X}},ZF=class W{fields=[];static deSerialize(X){let G=0,Y=new W;for(;;){let J={};Y.fields.push(J);let Z=new lV(X.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[Y,G]}serialize(){let X=Buffer.alloc(0);for(let G of this.fields)try{if(G.timestampOffset&&G.blockLength){let Y=new lV(Buffer.alloc(4)).writeBits(1,G.fBit).writeBits(7,G.blockPT).writeBits(14,G.timestampOffset).writeBits(10,G.blockLength);X=Buffer.concat([X,Y.uint8Array])}else{let Y=new lV(Buffer.alloc(1)).writeBits(1,0).writeBits(7,G.blockPT);X=Buffer.concat([X,Y.uint8Array])}}catch(Y){Nn(Y?.message)}return X}},qn=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 zS,X=this.cache.slice(-(this.distance+1)),G=X.pop();if(!G)return W;return X.forEach((Y)=>{let J=uY(G.timestamp,-Y.timestamp);if(J>Hn)return;W.blocks.push({block:Y.block,blockPT:Y.blockPT,timestampOffset:J})}),W.blocks.push({block:G.block,blockPT:G.blockPT}),W}},Hn=16383,An=class{size=150;sequenceNumbers=[];push(W,X){let G=[];return W.blocks.forEach(({blockPT:J,timestampOffset:Z,block:V},U)=>{let Q=R9(X.header.sequenceNumber,-(W.blocks.length-(U+1)));if(Z)G.push(new WW(new e6({timestamp:uY(X.header.timestamp,-Z),payloadType:J,ssrc:X.header.ssrc,sequenceNumber:Q,marker:!0}),V));else G.push(new WW(new e6({timestamp:X.header.timestamp,payloadType:J,ssrc:X.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}})}},OX={OneByte:48862,TwoByte:4096},VF=2,UF=4,QF=8,NF=12,qF=4,e6=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=OX.OneByte;extensionLength;extensions=[];constructor(X={}){Object.assign(this,X)}static deSerialize(X){let G=new W,Y=0,J=X[Y++];G.version=b8(J,0,2),G.padding=b8(J,2)>0,G.extension=b8(J,3)>0,G.csrcLength=b8(J,4,4),G.csrc=[...Array(G.csrcLength)].map(()=>{let V=X.readUInt32BE(Y);return Y+=4,V}),Y+=NF-1;let Z=X[1];G.marker=b8(Z,0)>0,G.payloadType=b8(Z,1,7),G.sequenceNumber=X.readUInt16BE(VF),G.timestamp=X.readUInt32BE(UF),G.ssrc=X.readUInt32BE(QF);for(let V=0;V<G.csrc.length;V++){let U=NF+V*qF;G.csrc[V]=X.subarray(U).readUInt32BE()}if(G.extension){G.extensionProfile=X.subarray(Y).readUInt16BE(),Y+=2;let V=X.subarray(Y).readUInt16BE()*4;switch(G.extensionLength=V,Y+=2,G.extensionProfile){case OX.OneByte:{let U=Y+V;while(Y<U){if(X[Y]===0){Y++;continue}let Q=X[Y]>>4,N=(X[Y]&(X[Y]^240))+1;if(Y++,Q===15)break;let q={id:Q,payload:X.subarray(Y,Y+N)};G.extensions=[...G.extensions,q],Y+=N}}break;case OX.TwoByte:{let U=Y+V;while(Y<U){if(X[Y]===0){Y++;continue}let Q=X[Y];Y++;let N=X[Y];Y++;let q={id:Q,payload:X.subarray(Y,Y+N)};G.extensions=[...G.extensions,q],Y+=N}}break;default:{let U={id:0,payload:X.subarray(Y,Y+V)};G.extensions=[...G.extensions,U],Y+=G.extensions[0].payload.length}break}}if(G.payloadOffset=Y,G.padding)G.paddingSize=X[X.length-1];return G}get serializeSize(){let{csrc:X,extensionProfile:G,extensions:Y}=this,J=12+X.length*qF;if(Y.length>0||this.extension===!0){let Z=4;switch(G){case OX.OneByte:for(let V of Y)Z+=1+V.payload.length;break;case OX.TwoByte:for(let V of Y)Z+=2+V.payload.length;break;default:Z+=Y[0].payload.length}J+=Math.floor((Z+3)/4)*4}return J}serialize(X){let G=Buffer.alloc(X),Y=0,J=new aq(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,Y++);let Z=new aq(8);if(this.marker)Z.set(1,0,1);Z.set(7,1,this.payloadType),G.writeUInt8(Z.value,Y++),G.writeUInt16BE(this.sequenceNumber,VF),Y+=2,G.writeUInt32BE(this.timestamp,UF),Y+=4,G.writeUInt32BE(this.ssrc,QF),Y+=4;for(let V of this.csrc)G.writeUInt32BE(V,Y),Y+=4;if(this.extension){let V=Y;G.writeUInt16BE(this.extensionProfile,Y),Y+=4;let U=Y;switch(this.extensionProfile){case OX.OneByte:for(let q of this.extensions)G.writeUInt8(q.id<<4|q.payload.length-1,Y++),q.payload.copy(G,Y),Y+=q.payload.length;break;case OX.TwoByte:for(let q of this.extensions)G.writeUInt8(q.id,Y++),G.writeUInt8(q.payload.length,Y++),q.payload.copy(G,Y),Y+=q.payload.length;break;default:{let q=this.extensions[0].payload.length;if(q%4!=0)throw Error();this.extensions[0].payload.copy(G,Y),Y+=q}}let Q=Y-U,N=Math.trunc((Q+3)/4)*4;G.writeUInt16BE(Math.trunc(N/4),V+2);for(let q=0;q<N-Q;q++)G.writeUInt8(0,Y),Y++}return this.payloadOffset=Y,G}},WW=class W{constructor(X,G){this.header=X,this.payload=G}get serializeSize(){return this.header.serializeSize+this.payload.length}clone(){return new W(new e6({...this.header}),this.payload)}serialize(){let X=this.header.serialize(this.header.serializeSize+this.payload.length),{payloadOffset:G}=this.header;if(this.payload.copy(X,G),this.header.padding){let Y=Buffer.alloc(this.header.paddingSize);Y.writeUInt8(this.header.paddingSize,this.header.paddingSize-1),X=Buffer.concat([X,Y])}return X}static deSerialize(X){let G=e6.deSerialize(X);return new W(G,X.subarray(G.payloadOffset,X.length-G.paddingSize))}clear(){this.payload=null}};function zn(W,X,G){return new WW(new e6({payloadType:X,marker:W.header.marker,sequenceNumber:X8.Unpack("!H",W.payload.subarray(0,2))[0],timestamp:W.header.timestamp,ssrc:G}),W.payload.subarray(2))}function In(W,X,G,Y){return new WW(new e6({payloadType:X,marker:W.header.marker,sequenceNumber:G,timestamp:W.header.timestamp,ssrc:Y,csrc:W.header.csrc,extensions:W.header.extensions}),Buffer.concat([Buffer.from(X8.Pack("!H",[W.header.sequenceNumber])),W.payload]))}var IS=class{constructor(W,X,G,Y){this.srtpSessionKey=W,this.srtpSessionSalt=X,this.srtcpSessionKey=G,this.srtcpSessionSalt=Y}encryptRtp(W,X,G){return Buffer.from([])}decryptRtp(W,X,G){return[]}encryptRTCP(W,X){return Buffer.from([])}decryptRTCP(W){return[]}},pY=class extends Error{constructor(W){super(W);this.name="SrtpAuthenticationError"}},IF=12,jn=8;function ZO(W,X,G="Failed to authenticate SRTP packet"){let Y=W.length-X;sV(W.length>=IF+X,G);let J=jS(()=>e6.deSerialize(W.subarray(0,Y)),G);return J.paddingSize=0,sV(J.payloadOffset>=IF&&J.payloadOffset<=Y,G),J}function wS(W,X,G,Y="Failed to authenticate SRTCP packet"){return sV(W.length>=jn+X+G,Y),jS(()=>XW.deSerialize(W.subarray(0,kK)),Y)}function sV(W,X){if(!W)throw new pY(X)}function jS(W,X){try{return W()}catch{throw new pY(X)}}function KS(W,X,G="Failed to authenticate SRTP packet"){if(!W.padding)return W.paddingSize=0,W;sV(X.length>W.payloadOffset,G);let Y=X[X.length-1];return sV(Y>0&&Y<=X.length-W.payloadOffset,G),W.paddingSize=Y,W}var Kn=class extends IS{constructor(W,X,G,Y,J,Z){super(W,X,G,Y);this.srtpSessionAuthTag=J,this.srtcpSessionAuthTag=Z}authTagLength=10;encryptRtp(W,X,G){let Y=W.serialize(W.serializeSize),J=this.generateCounter(W.sequenceNumber,G,W.ssrc,this.srtpSessionSalt),V=HF("aes-128-ctr",this.srtpSessionKey,J).update(X),U=this.generateSrtpAuthTag(G,Y,V);return Buffer.concat([Y,V,U])}decryptRtp(W,X,G=ZO(W,this.authTagLength)){let Y=W.length-this.authTagLength,J=W.subarray(0,Y),Z=W.subarray(Y),V=this.generateSrtpAuthTag(X,J.subarray(0,G.payloadOffset),J.subarray(G.payloadOffset));jF(Z,V,"Failed to authenticate SRTP packet");let U=this.generateCounter(G.sequenceNumber,X,G.ssrc,this.srtpSessionSalt),Q=AF("aes-128-ctr",this.srtpSessionKey,U),N=J.subarray(G.payloadOffset),q=Q.update(N),A=Buffer.concat([J.subarray(0,G.payloadOffset),q]);return[A,KS(G,A,"Failed to authenticate SRTP packet")]}encryptRTCP(W,X){let G=Buffer.from(W),Y=G.readUInt32BE(4),J=this.generateCounter(X&65535,X>>16,Y,this.srtcpSessionSalt);HF("aes-128-ctr",this.srtcpSessionKey,J).update(G.slice(8)).copy(G,8),G=Buffer.concat([G,Buffer.alloc(4)]),G.writeUInt32BE(X,G.length-4),G[G.length-4]|=128;let U=this.generateSrtcpAuthTag(G);return G=Buffer.concat([G,U]),G}decryptRTCP(W){let X=wS(W,this.authTagLength,wF),G=W.length-(this.authTagLength+wF),Y=W.subarray(0,W.length-this.authTagLength),J=W.subarray(W.length-this.authTagLength),Z=this.generateSrtcpAuthTag(Y);jF(J,Z,"Failed to authenticate SRTCP packet");let V=Buffer.from(W).slice(0,G);if(W[G]>>>7===0)return[V,X];let Q=W.readUInt32BE(G);Q&=2147483647;let N=W.readUInt32BE(4),q=this.generateCounter(Q&65535,Q>>16,N,this.srtcpSessionSalt);return AF("aes-128-ctr",this.srtcpSessionKey,q).update(V.subarray(8)).copy(V,8),[V,X]}generateSrtcpAuthTag(W){return zF("sha1",this.srtcpSessionAuthTag).update(W).digest().slice(0,10)}generateCounter(W,X,G,Y){let J=Buffer.alloc(16);J.writeUInt32BE(G,4),J.writeUInt32BE(X,8),J.writeUInt32BE(Number(BigInt(W)<<16n),12);for(let Z=0;Z<Y.length;Z++)J[Z]^=Y[Z];return J}generateSrtpAuthTag(W,...X){let G=zF("sha1",this.srtpSessionAuthTag),Y=Buffer.alloc(4);Y.writeUInt32BE(W);for(let J of X)G.update(J);return G.update(Y).digest().subarray(0,10)}},wF=4;function jF(W,X,G){if(W.length!==X.length||!wn(W,X))throw new pY(G)}var On=class extends IS{aeadAuthTagLen=16;rtpIvWriter=gq([2,4,4,2],!0);rtcpIvWriter=gq([2,4,2,4],!0);aadWriter=gq([4],!0);constructor(W,X,G,Y){super(W,X,G,Y)}encryptRtp(W,X,G){let Y=W.serialize(W.serializeSize),J=this.rtpInitializationVector(W,G),Z=KF("aes-128-gcm",this.srtpSessionKey,J);Z.setAAD(Y);let V=Z.update(X);Z.final();let U=Z.getAuthTag();return Buffer.concat([Y,V,U])}decryptRtp(W,X,G=ZO(W,this.aeadAuthTagLen)){let Y=W.subarray(0,G.payloadOffset),J=W.length-this.aeadAuthTagLen,Z=W.subarray(J),V=Buffer.from([]);V=GF(V,W.length-this.aeadAuthTagLen),Y.copy(V);let U=this.rtpInitializationVector(G,X),Q=W.slice(G.payloadOffset,J),N=OF("aes-128-gcm",this.srtpSessionKey,U);N.setAAD(Y),N.setAuthTag(Z);let q=N.update(Q);return CF(N,"SRTP"),q.copy(V,G.payloadOffset),[V,KS(G,V,"Failed to authenticate SRTP packet")]}encryptRTCP(W,X){let G=W.readUInt32BE(4),Y=W.length+this.aeadAuthTagLen,J=Buffer.from([]);J=GF(J,Y+NK),W.slice(0,8).copy(J);let Z=this.rtcpInitializationVector(G,X),V=this.rtcpAdditionalAuthenticatedData(W,X),U=KF("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,Y),J}decryptRTCP(W){let X=wS(W,this.aeadAuthTagLen,NK),G=W.length-NK,Y=G-this.aeadAuthTagLen,J=W.readUInt32BE(4),Z=W.readUInt32BE(G),V=Z>>>31===1,U=Z&~(DF<<24),Q=this.rtcpInitializationVector(J,U),N=V?Buffer.concat([W.subarray(0,8),W.subarray(G)]):Buffer.concat([W.subarray(0,Y),W.subarray(G)]),q=V?W.slice(8,Y):Buffer.alloc(0),A=V?Buffer.alloc(Y):Buffer.from(W.subarray(0,Y));if(V)W.slice(0,8).copy(A);let H=OF("aes-128-gcm",this.srtcpSessionKey,Q);H.setAAD(N),H.setAuthTag(W.subarray(Y,G));let I=H.update(q);if(CF(H,"SRTCP"),V)I.copy(A,8);return[A,X]}rtpInitializationVector(W,X){let G=this.rtpIvWriter([0,W.ssrc,X,W.sequenceNumber]);for(let Y=0;Y<G.length;Y++)G[Y]^=this.srtpSessionSalt[Y];return G}rtcpInitializationVector(W,X){let G=this.rtcpIvWriter([0,W,0,X]);for(let Y=0;Y<G.length;Y++)G[Y]^=this.srtcpSessionSalt[Y];return G}rtcpAdditionalAuthenticatedData(W,X){let G=Buffer.concat([W.subarray(0,8),this.aadWriter([X])]);return G[8]|=DF,G}},NK=4,DF=128;function CF(W,X){try{W.final()}catch{throw new pY(`Failed to authenticate ${X} packet`)}}var OS=class{constructor(W,X,G){this.masterKey=W,this.masterSalt=X,this.profile=G;{let Y=14-X.length;if(Y>0)this.masterSalt=Buffer.concat([X,Buffer.alloc(Y)])}switch(this.srtpSessionKey=this.generateSessionKey(0),this.srtpSessionSalt=this.generateSessionSalt(2),this.srtpSessionAuthTag=this.generateSessionAuthTag(1),this.srtpSessionAuth=QK("sha1",this.srtpSessionAuthTag),this.srtcpSessionKey=this.generateSessionKey(3),this.srtcpSessionSalt=this.generateSessionSalt(5),this.srtcpSessionAuthTag=this.generateSessionAuthTag(4),this.srtcpSessionAuth=QK("sha1",this.srtcpSessionAuthTag),G){case KH:this.cipher=new Kn(this.srtpSessionKey,this.srtpSessionSalt,this.srtcpSessionKey,this.srtcpSessionSalt,this.srtpSessionAuthTag,this.srtcpSessionAuthTag);break;case UU:this.cipher=new On(this.srtpSessionKey,this.srtpSessionSalt,this.srtcpSessionKey,this.srtcpSessionSalt);break}}srtpSSRCStates={};srtpSessionKey;srtpSessionSalt;srtpSessionAuthTag;srtpSessionAuth;srtcpSSRCStates={};srtcpSessionKey;srtcpSessionSalt;srtcpSessionAuthTag;srtcpSessionAuth;cipher;generateSessionKey(W){let X=Buffer.from(this.masterSalt),G=Buffer.from([W,0,0,0,0,0,0]);for(let J=G.length-1,Z=X.length-1;J>=0;J--,Z--)X[Z]=X[Z]^G[J];X=Buffer.concat([X,Buffer.from([0,0])]);let Y=new hq.default.AES(this.masterKey);return Buffer.from(Y.encrypt(X))}generateSessionSalt(W){let X=Buffer.from(this.masterSalt),G=Buffer.from([W,0,0,0,0,0,0]);for(let J=G.length-1,Z=X.length-1;J>=0;J--,Z--)X[Z]=X[Z]^G[J];X=Buffer.concat([X,Buffer.from([0,0])]);let Y=new hq.default.AES(this.masterKey);return X=Buffer.from(Y.encrypt(X)),X.subarray(0,14)}generateSessionAuthTag(W){let X=Buffer.from(this.masterSalt),G=Buffer.from([W,0,0,0,0,0,0]);for(let V=G.length-1,U=X.length-1;V>=0;V--,U--)X[U]=X[U]^G[V];let Y=Buffer.concat([X,Buffer.from([0,0])]),J=Buffer.concat([X,Buffer.from([0,1])]),Z=new hq.default.AES(this.masterKey);return Y=Buffer.from(Z.encrypt(Y)),J=Buffer.from(Z.encrypt(J)),Buffer.concat([Y,J.subarray(0,4)])}getSrtpSsrcState(W){let X=this.srtpSSRCStates[W];if(X)return X;return X={ssrc:W,rolloverCounter:0,lastSequenceNumber:0},this.srtpSSRCStates[W]=X,X}getSrtcpSsrcState(W){let X=this.srtcpSSRCStates[W];if(X)return X;return X={srtcpIndex:0,ssrc:W},this.srtcpSSRCStates[W]=X,X}updateRolloverCount(W,X){if(!X.rolloverHasProcessed)X.rolloverHasProcessed=!0;else if(W===0){if(X.lastSequenceNumber>vV)X.rolloverCounter++}else if(X.lastSequenceNumber<vV&&W>TF-vV){if(X.rolloverCounter>0)X.rolloverCounter--}else if(W<vV&&X.lastSequenceNumber>TF-vV)X.rolloverCounter++;X.lastSequenceNumber=W}generateSrtpAuthTag(W,X){this.srtpSessionAuth=QK("sha1",this.srtpSessionAuthTag);let G=Buffer.alloc(4);return G.writeUInt32BE(X),this.srtpSessionAuth.update(W).update(G).digest().slice(0,10)}index(W){let X=this.srtcpSSRCStates[W];if(!X)return 0;return X.srtcpIndex}setIndex(W,X){let G=this.getSrtcpSsrcState(W);G.srtcpIndex=X%2147483647}},vV=100,TF=65535,Dn=class extends OS{constructor(W,X,G){super(W,X,G)}encryptRTCP(W){let X=W.readUInt32BE(4),G=this.getSrtcpSsrcState(X);if(G.srtcpIndex++,G.srtcpIndex>>Cn)G.srtcpIndex=0;return this.cipher.encryptRTCP(W,G.srtcpIndex)}decryptRTCP(W){return this.cipher.decryptRTCP(W)}},Cn=2147483647,DS=class{constructor(W){this.ContextCls=W}localContext;remoteContext;onData;start(W,X,G,Y,J){this.localContext=new this.ContextCls(W,X,J),this.remoteContext=new this.ContextCls(G,Y,J)}},Tn=class extends DS{constructor(W){super(Dn);this.config=W,this.start(W.keys.localMasterKey,W.keys.localMasterSalt,W.keys.remoteMasterKey,W.keys.remoteMasterSalt,W.profile)}decrypt=(W)=>{let[X]=this.remoteContext.decryptRTCP(W);return X};encrypt(W){return this.localContext.encryptRTCP(W)}},Mn=class extends OS{constructor(W,X,G){super(W,X,G)}encryptRtp(W,X){let G=this.getSrtpSsrcState(X.ssrc);return this.updateRolloverCount(X.sequenceNumber,G),this.cipher.encryptRtp(X,W,G.rolloverCounter)}decryptRtp(W){let X=ZO(W,this.rtpAuthTagLength),G=this.srtpSSRCStates[X.ssrc],Y=G?{...G}:{ssrc:X.ssrc,rolloverCounter:0,lastSequenceNumber:0};this.updateRolloverCount(X.sequenceNumber,Y);let J=this.cipher.decryptRtp(W,Y.rolloverCounter,X);if(G)Object.assign(G,Y);else this.srtpSSRCStates[X.ssrc]=Y;return J}get rtpAuthTagLength(){return this.profile===UU?16:10}},Pn=class extends DS{constructor(W){super(Mn);this.config=W,this.start(W.keys.localMasterKey,W.keys.localMasterSalt,W.keys.remoteMasterKey,W.keys.remoteMasterSalt,W.profile)}decrypt=(W)=>{let[X]=this.remoteContext.decryptRtp(W);return X};encrypt(W,X){return this.localContext.encryptRtp(W,X)}},XA0=class{constructor(W){this.props=W}sequenceNumber=R2();timestamp=PK();create(W){this.sequenceNumber=R9(this.sequenceNumber,1);let X=this.props.between*this.props.clockRate/1000;this.timestamp=uY(this.timestamp,X);let G=new e6({sequenceNumber:this.sequenceNumber,timestamp:Number(this.timestamp),payloadType:96,extension:!0,marker:!1,padding:!1});return new WW(G,W)}},b9=P1("werift-dtls : packages/dtls/src/flight/client/flight5.ts : log"),Rn=class extends YU{constructor(W,X,G,Y){super(W,X,5,7);this.cipher=G,this.srtp=Y}handleHandshake(W){this.dtls.bufferHandshakeCache([W],!1,4);let X=(()=>{switch(W.msg_type){case 2:return ZS.deSerialize(W.fragment);case 11:return GH.deSerialize(W.fragment);case 12:return QS.deSerialize(W.fragment);case 13:return JS.deSerialize(W.fragment);case 14:return VS.deSerialize(W.fragment)}})();if(X)dY[X.msgType]({dtls:this.dtls,cipher:this.cipher,srtp:this.srtp})(X)}async exec(){if(this.dtls.flight===5){b9(this.dtls.sessionId,"flight5 twice"),this.send(this.dtls.lastMessage);return}this.dtls.flight=5;let W=this.dtls.requestedCertificateTypes.length>0;b9(this.dtls.sessionId,"send flight5",W);let X=[W&&this.sendCertificate(),this.sendClientKeyExchange(),W&&this.sendCertificateVerify(),this.sendChangeCipherSpec(),this.sendFinished()].filter((G)=>G);this.dtls.lastMessage=X,await this.transmit(X)}sendCertificate(){let W=new GH([Buffer.from(this.cipher.localCert)]),X=this.createPacket([W]);return Buffer.concat(X.map((Y)=>Y.serialize()))}sendClientKeyExchange(){if(!this.cipher.localKeyPair)throw Error();let W=new YS(this.cipher.localKeyPair.publicKey),X=this.createPacket([W]),G=Buffer.concat(X.map((U)=>U.serialize())),Y=this.cipher.localKeyPair,J=this.cipher.remoteKeyPair;if(!J.publicKey)throw Error("not exist");let Z=f2(J.publicKey,Y.privateKey,Y.curve);b9(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?c2(Z,V):p2(Z,this.cipher.localRandom.serialize(),this.cipher.remoteRandom.serialize()),this.cipher.cipher=t2(this.cipher.cipherSuite),this.cipher.cipher.init(this.cipher.masterSecret,this.cipher.remoteRandom.serialize(),this.cipher.localRandom.serialize()),b9(this.dtls.sessionId,"cipher",this.cipher.cipher.summary),G}sendCertificateVerify(){let W=Buffer.concat(this.dtls.sortedHandshakeCache.map((V)=>V.serialize())),X=this.cipher.signatureData(W,"sha256"),G=(()=>{switch(this.cipher.signatureHashAlgorithm?.signature){case o4.ecdsa_3:return r$.ecdsa_secp256r1_sha256;case o4.rsa_1:return r$.rsa_pkcs1_sha256}})();if(!G)throw Error();b9(this.dtls.sessionId,"signatureScheme",this.cipher.signatureHashAlgorithm?.signature,G);let Y=new GS(G,X),J=this.createPacket([Y]);return Buffer.concat(J.map((V)=>V.serialize()))}sendChangeCipherSpec(){let W=XS.createEmpty().serialize(),X=GU(this.dtls)([{type:20,fragment:W}],++this.dtls.recordSequenceNumber);return Buffer.concat(X.map((Y)=>Y.serialize()))}sendFinished(){let W=Buffer.concat(this.dtls.sortedHandshakeCache.map((Z)=>Z.serialize())),X=this.cipher.verifyData(W),G=new xK(X);this.dtls.epoch=1;let[Y]=this.createPacket([G]);this.dtls.recordSequenceNumber=0;let J=this.cipher.encryptPacket(Y).serialize();return b9(this.dtls.sessionId,"finished",this.cipher.cipher.summary),J}},dY={};dY[2]=({cipher:W,srtp:X,dtls:G})=>(Y)=>{if(b9(G.sessionId,"serverHello",Y.cipherSuite),W.remoteRandom=PX.from(Y.random),W.cipherSuite=Y.cipherSuite,b9(G.sessionId,"selected cipherSuite",W.cipherSuite),Y.extensions)Y.extensions.forEach((J)=>{switch(J.type){case bY.type:{let Z=bY.fromData(J.data),V=WH.findMatchingSRTPProfile(Z.profiles,G.options.srtpProfiles||[]);if(b9(G.sessionId,"selected srtp profile",V),V==null)return;X.srtpProfile=V}break;case IH.type:G.remoteExtendedMasterSecret=!0;break;case wH.type:b9(G.sessionId,"RenegotiationIndication");break}})};dY[11]=({cipher:W,dtls:X})=>(G)=>{b9(X.sessionId,"handshake certificate",G),W.remoteCertificate=G.certificateList[0]};dY[12]=({cipher:W,dtls:X})=>(G)=>{if(!W.localRandom||!W.remoteRandom)throw Error();b9(X.sessionId,"ServerKeyExchange",G),b9(X.sessionId,"selected curve",G.namedCurve),W.remoteKeyPair={curve:G.namedCurve,publicKey:G.publicKey},W.localKeyPair=WS(G.namedCurve)};dY[13]=({dtls:W})=>(X)=>{b9(W.sessionId,"certificate_request",X),W.requestedCertificateTypes=X.certificateTypes,W.requestedSignatureAlgorithms=X.signatures};dY[14]=({dtls:W})=>(X)=>{b9(W.sessionId,"server_hello_done",X)};var CS=class W{constructor(X,G){this.serverVersion=X,this.cookie=G}msgType=3;messageSeq;static spec={serverVersion:YO,cookie:EX.types.buffer(EX.types.uint8)};static createEmpty(){return new W(void 0,void 0)}static deSerialize(X){return new W(...Object.values(EX.decode(X,W.spec)))}serialize(){let X=EX.encode(this,W.spec).slice();return Buffer.from(X)}get version(){return{major:255-this.serverVersion.major,minor:255-this.serverVersion.minor}}toFragment(){let X=this.serialize();return new F5(this.msgType,X.length,this.messageSeq,0,X.length,X)}},Bn=P1("werift-dtls : packages/dtls/src/context/dtls.ts : log"),MF=class{constructor(W,X){this.options=W,this.sessionType=X}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],[X])=>Number(W)-Number(X)).flatMap(([,{data:W}])=>W.sort((X,G)=>X.message_seq-G.message_seq))}checkHandshakesExist=(W)=>!W.find((X)=>this.sortedHandshakeCache.find((G)=>G.msg_type===X)==null);bufferHandshakeCache(W,X,G){if(!this.handshakeCache[G])this.handshakeCache[G]={data:[],isLocal:X,flight:G};let Y=W.filter((J)=>{let Z=this.handshakeCache[G].data.find((V)=>V.msg_type===J.msg_type);if(Z)return Bn(this.sessionId,"exist",Z.summary,X,G),!1;return!0});this.handshakeCache[G].data=[...this.handshakeCache[G].data,...Y]}},En=class{constructor(W){this.socket=W}send=(W)=>{return this.socket.send(W)}},_K=class W{static type=10;static spec={type:o7.types.uint16be,data:o7.types.array(o7.types.uint16be,o7.types.uint16be,"bytes")};type=W.type;data=[];constructor(X={}){Object.assign(this,X)}static createEmpty(){return new W}static fromData(X){return new W({type:W.type,data:o7.decode(X,W.spec.data)})}static deSerialize(X){return new W(o7.decode(X,W.spec))}serialize(){return Buffer.from(o7.encode(this,W.spec).slice())}get extension(){return{type:this.type,data:this.serialize().slice(2)}}},yK=class W{static type=13;static spec={type:l7.types.uint16be,data:l7.types.array({hash:l7.types.uint8,signature:l7.types.uint8},l7.types.uint16be,"bytes")};type=W.type;data=[];constructor(X={}){Object.assign(this,X)}static createEmpty(){return new W}static deSerialize(X){return new W(l7.decode(X,W.spec))}serialize(){let X=l7.encode(this,W.spec).slice();return Buffer.from(X)}static fromData(X){let G=Buffer.alloc(2);return G.writeUInt16BE(W.type),W.deSerialize(Buffer.concat([G,X]))}get extension(){return{type:this.type,data:this.serialize().slice(2)}}},PF=class W{constructor(X,G){this.level=X,this.description=G}static spec={level:$X.types.uint8,description:$X.types.uint8};static deSerialize(X){return new W(...Object.values($X.decode(X,W.spec)))}serialize(){let X=$X.encode(this,W.spec).slice();return Buffer.from(X)}},RF=P1("werift-dtls : packages/dtls/record/receive.ts : log"),qK=P1("werift-dtls : packages/dtls/record/receive.ts : err"),$n=(W)=>{let X=0,G=[];while(W.length>X){let Y=W.readUInt16BE(X+11);if(W.length<X+(12+Y))break;let J=a2.deSerialize(W.subarray(X));G.push(J),X+=13+Y}return G},Fn=(W,X)=>(G)=>{switch(G.recordLayerHeader.contentType){case 20:return RF(W.sessionId,"change cipher spec"),[{type:20,data:void 0}];case 22:{let J=G.fragment;try{if(G.recordLayerHeader.epoch>0)RF(W.sessionId,"decrypt handshake"),J=X.decryptPacket(G)}catch(Z){throw qK(W.sessionId,"decrypt failed",Z),Z}try{let Z=0,V=[];while(J.length>Z){let U=F5.deSerialize(J.subarray(Z));V.push({type:22,data:U}),Z+=U.fragment_length+12}return V}catch(Z){throw qK(W.sessionId,"decSerialize failed",Z,J),Z}}case 23:return[{type:23,data:X.decryptPacket(G)}];case 21:{let J=PF.deSerialize(G.fragment);if(SK[J.description]==null){let Z=X.decryptPacket(G);J=PF.deSerialize(Z)}if(qK(W.sessionId,"ContentType.alert",J,SK[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}]}},LF=P1("werift-dtls : packages/dtls/src/socket.ts : log"),BF=P1("werift-dtls : packages/dtls/src/socket.ts : err"),TS=class{constructor(W,X){this.options=W,this.sessionType=X,this.dtls=new MF(this.options,this.sessionType),this.cipher=new eq(this.sessionType,this.options.cert,this.options.key,this.options.signatureHash),this.transport=new En(this.options.transport),this.setupExtensions(),this.transport.socket.onData=this.udpOnMessage}onConnect=new d0;onData=new d0;onError=new d0;onClose=new d0;transport;cipher;dtls;srtp=new WH;connected=!1;extensions=[];onHandleHandshakes;bufferFragmentedHandshakes=[];renegotiation(){LF("renegotiation",this.sessionType),this.connected=!1,this.cipher=new eq(this.sessionType,this.options.cert,this.options.key,this.options.signatureHash),this.dtls=new MF(this.options,this.sessionType),this.srtp=new WH,this.extensions=[],this.bufferFragmentedHandshakes=[]}udpOnMessage=(W)=>{let X=$n(W);for(let G of X)try{let Y=Fn(this.dtls,this.cipher)(G);for(let J of Y)switch(J.type){case 22:{let Z=J.data,V=this.handleFragmentHandshake([Z]),U=Object.values(V.reduce((Q,N)=>{if(!Q[N.msg_type])Q[N.msg_type]=[];return Q[N.msg_type].push(N),Q},{})).map((Q)=>F5.assemble(Q)).sort((Q,N)=>Q.msg_type-N.msg_type);this.onHandleHandshakes(U).catch((Q)=>{BF(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(Y){BF(this.dtls.sessionId,"catch udpOnMessage error",Y)}};setupExtensions(){if(LF(this.dtls.sessionId,"support srtpProfiles",this.options.srtpProfiles),this.options.srtpProfiles&&this.options.srtpProfiles.length>0){let W=bY.create(this.options.srtpProfiles,Buffer.from([0]));this.extensions.push(W.extension)}{let W=_K.createEmpty();W.data=g2,this.extensions.push(W.extension)}{let W=yK.createEmpty();W.data=h2,this.extensions.push(W.extension)}if(this.options.extendedMasterSecret)this.extensions.push({type:IH.type,data:Buffer.alloc(0)});{let W=wH.createEmpty();this.extensions.push(W.extension)}}waitForReady=(W)=>new Promise(async(X,G)=>{for(let Y=0;Y<10;Y++)if(W()){X();break}else await Ln(100*Y);G("waitForReady timeout")});handleFragmentHandshake(W){let X=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)X=[...this.bufferFragmentedHandshakes,...X],this.bufferFragmentedHandshakes=[]}return X}send=async(W)=>{let X=GU(this.dtls)([{type:23,fragment:W}],++this.dtls.recordSequenceNumber)[0];await this.transport.send(this.cipher.encryptPacket(X).serialize())};close(){this.transport.socket.close()}extractSessionKeys(W,X){let G=this.exportKeyingMaterial("EXTRACTOR-dtls_srtp",W*2+X*2),{clientKey:Y,serverKey:J,clientSalt:Z,serverSalt:V}=CX.decode(G,{clientKey:CX.types.buffer(W),serverKey:CX.types.buffer(W),clientSalt:CX.types.buffer(X),serverSalt:CX.types.buffer(X)});if(this.sessionType===d4.CLIENT)return{localKey:Y,localSalt:Z,remoteKey:J,remoteSalt:V};else return{localKey:J,localSalt:V,remoteKey:Y,remoteSalt:Z}}exportKeyingMaterial(W,X){return Uo(W,X,this.cipher.masterSecret,this.cipher.localRandom.serialize(),this.cipher.remoteRandom.serialize(),this.sessionType===d4.CLIENT)}get remoteCertificate(){return this.cipher.remoteCertificate}},HK=P1("werift-dtls : packages/dtls/src/client.ts : log"),EF=class extends TS{constructor(W){super(W,d4.CLIENT);this.onHandleHandshakes=this.handleHandshakes,HK(this.dtls.sessionId,"start client")}async connect(){await new Ro(this.transport,this.dtls,this.cipher).exec(this.extensions)}flight5;handleHandshakes=async(W)=>{HK(this.dtls.sessionId,"handleHandshakes",W.map((X)=>X.msg_type));for(let X of W)switch(X.msg_type){case 3:{let G=CS.deSerialize(X.fragment);await new Bo(this.transport,this.dtls).exec(G)}break;case 2:{if(this.connected)return;this.flight5=new Rn(this.transport,this.dtls,this.cipher,this.srtp),this.flight5.handleHandshake(X)}break;case 11:case 12:case 13:await this.waitForReady(()=>!!this.flight5),this.flight5?.handleHandshake(X);break;case 14:{await this.waitForReady(()=>!!this.flight5),this.flight5?.handleHandshake(X);let G=[11,12,this.options.certificateRequest&&13].filter((Y)=>typeof Y==="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(),HK(this.dtls.sessionId,"dtls connected");break}}},c7=P1("werift-dtls : packages/dtls/flight/server/flight2.ts : log"),xn=(W,X,G,Y)=>(J)=>{c7("dtls version",J.clientVersion),X.flight=2,X.recordSequenceNumber=0,X.sequenceNumber=0,J.extensions.forEach((A)=>{switch(A.type){case _K.type:{let H=_K.fromData(A.data).data;c7(X.sessionId,"curves",H);let I=H.filter((w)=>g2.includes(w))[0];G.namedCurve=I,c7(X.sessionId,"curve selected",G.namedCurve)}break;case yK.type:{if(!G.signatureHashAlgorithm)throw Error("need to set certificate");let H=yK.fromData(A.data).data;c7(X.sessionId,"hash,signature",H);let I=H.find((O)=>O.signature===G.signatureHashAlgorithm?.signature)?.signature,w=H.find((O)=>O.hash===G.signatureHashAlgorithm?.hash)?.hash;if(I==null||w==null)throw Error("invalid signatureHash")}break;case bY.type:{if(!X.options?.srtpProfiles)return;if(X.options.srtpProfiles.length===0)return;let H=bY.fromData(A.data);c7(X.sessionId,"srtp profiles",H.profiles);let I=WH.findMatchingSRTPProfile(H.profiles,X.options?.srtpProfiles);if(!I)throw Error();Y.srtpProfile=I,c7(X.sessionId,"srtp profile selected",Y.srtpProfile)}break;case IH.type:X.remoteExtendedMasterSecret=!0;break;case wH.type:c7(X.sessionId,"RenegotiationIndication",A.data);break;case 43:{let I=[...A.data.subarray(1)].map((w)=>w.toString(10));c7("dtls supported version",I)}break}}),G.localRandom=new PX,G.remoteRandom=PX.from(J.random);let Z=J.cipherSuites;c7(X.sessionId,"cipher suites",Z);let V=(()=>{switch(G.signatureHashAlgorithm?.signature){case o4.ecdsa_3:return EK.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256_49195;case o4.rsa_1:return EK.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,c7(X.sessionId,"selected cipherSuite",G.cipherSuite),G.localKeyPair=WS(G.namedCurve),X.cookie||=Sn(20);let U=new CS({major:254,minor:253},X.cookie),Q=s2(X)([U]),q=GU(X)(Q.map((A)=>({type:22,fragment:A.serialize()})),++X.recordSequenceNumber).map((A)=>A.serialize());for(let A of q)W.send(A)},$F=P1("werift-dtls : packages/dtls/flight/server/flight4.ts : log"),kn=class extends YU{constructor(W,X,G,Y){super(W,X,4,6);this.cipher=G,this.srtp=Y}async exec(W,X=!1){if(this.dtls.flight===4){$F(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(),X&&this.sendCertificateRequest(),this.sendServerHelloDone()].filter((Y)=>Y);this.dtls.lastMessage=G,await this.transmit(G)}sendServerHello(){let W=[];if(this.srtp.srtpProfile)W.push(bY.create([this.srtp.srtpProfile],Buffer.from([0])).extension);if(this.dtls.options.extendedMasterSecret)W.push({type:IH.type,data:Buffer.alloc(0)});let X=wH.createEmpty();W.push(X.extension);let G=new ZS(this.dtls.version,this.cipher.localRandom,Buffer.from([0]),this.cipher.cipherSuite,0,W),Y=this.createPacket([G]);return Buffer.concat(Y.map((J)=>J.serialize()))}sendCertificate(){let W=new GH([Buffer.from(this.cipher.localCert)]),X=this.createPacket([W]);return Buffer.concat(X.map((G)=>G.serialize()))}sendServerKeyExchange(){let W=this.cipher.generateKeySignature("sha256");if(!this.cipher.signatureHashAlgorithm)throw Error("not exist");let X=new QS(u2.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([X]);return Buffer.concat(G.map((Y)=>Y.serialize()))}sendCertificateRequest(){let W=new JS(Go,h2,[]);$F(this.dtls.sessionId,"sendCertificateRequest",W);let X=this.createPacket([W]);return Buffer.concat(X.map((G)=>G.serialize()))}sendServerHelloDone(){let W=new VS,X=this.createPacket([W]);return Buffer.concat(X.map((G)=>G.serialize()))}},cY=P1("werift-dtls : packages/dtls/flight/server/flight6.ts"),_n=class extends YU{constructor(W,X,G){super(W,X,6);this.cipher=G}handleHandshake(W){this.dtls.bufferHandshakeCache([W],!1,5);let X=(()=>{switch(W.msg_type){case 11:return GH.deSerialize(W.fragment);case 15:return GS.deSerialize(W.fragment);case 16:return YS.deSerialize(W.fragment);case 20:return xK.deSerialize(W.fragment)}})();if(X){let G=QU[X.msgType];if(!G)return;G({dtls:this.dtls,cipher:this.cipher})(X)}}async exec(){if(this.dtls.flight===6){cY(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=XS.createEmpty().serialize(),X=GU(this.dtls)([{type:20,fragment:W}],++this.dtls.recordSequenceNumber);return Buffer.concat(X.map((Y)=>Y.serialize()))}sendFinished(){let W=Buffer.concat(this.dtls.sortedHandshakeCache.map((Z)=>Z.serialize())),X=this.cipher.verifyData(W),G=new xK(X);this.dtls.epoch=1;let[Y]=this.createPacket([G]);return this.dtls.recordSequenceNumber=0,this.cipher.encryptPacket(Y).serialize()}},QU={};QU[16]=({cipher:W,dtls:X})=>(G)=>{if(W.remoteKeyPair={curve:W.namedCurve,publicKey:G.publicKey},!W.remoteKeyPair.publicKey||!W.localKeyPair||!W.remoteRandom||!W.localRandom)throw Error("not exist");let Y=f2(W.remoteKeyPair.publicKey,W.localKeyPair.privateKey,W.localKeyPair.curve);cY(X.sessionId,"extendedMasterSecret",X.options.extendedMasterSecret,X.remoteExtendedMasterSecret);let J=Buffer.concat(X.sortedHandshakeCache.map((Z)=>Z.serialize()));W.masterSecret=X.options.extendedMasterSecret&&X.remoteExtendedMasterSecret?c2(Y,J):p2(Y,W.remoteRandom.serialize(),W.localRandom.serialize()),W.cipher=t2(W.cipherSuite),W.cipher.init(W.masterSecret,W.localRandom.serialize(),W.remoteRandom.serialize()),cY(X.sessionId,"setup cipher",W.cipher.summary)};QU[11]=({cipher:W,dtls:X})=>(G)=>{cY(X.sessionId,"handshake certificate",G),W.remoteCertificate=G.certificateList[0]};QU[15]=({cipher:W,dtls:X})=>(G)=>{if(!W.remoteCertificate)throw Error("client certificate missing before certificate verify");cY(X.sessionId,"certificate_verify",G.algorithm)};QU[20]=({dtls:W})=>(X)=>{cY(W.sessionId,"finished",X)};var xY=P1("werift-dtls : packages/dtls/src/server.ts : log"),yn=class extends TS{constructor(W){super(W,d4.SERVER);this.onHandleHandshakes=this.handleHandshakes,xY(this.dtls.sessionId,"start server")}flight6;handleHandshakes=async(W)=>{xY(this.dtls.sessionId,"handleHandshakes",W.map((X)=>X.msg_type));for(let X of W)switch(X.msg_type){case 1:{if(this.connected)this.renegotiation();let G=r2.deSerialize(X.fragment);if(G.cookie.length===0)xY(this.dtls.sessionId,"send flight2"),xn(this.transport,this.dtls,this.cipher,this.srtp)(G);else if(this.dtls.cookie&&G.cookie.equals(this.dtls.cookie))xY(this.dtls.sessionId,"send flight4"),await new kn(this.transport,this.dtls,this.cipher,this.srtp).exec(X,this.options.certificateRequest);else xY("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 _n(this.transport,this.dtls,this.cipher),this.flight6.handleHandshake(X)}break;case 20:{await this.waitForReady(()=>!!this.flight6),this.flight6?.handleHandshake(X);let G=[16,this.options.certificateRequest&&11,this.options.certificateRequest&&15].filter((Y)=>typeof Y==="number");await this.waitForReady(()=>this.dtls.checkHandshakesExist(G)),await this.flight6?.exec(),this.connected=!0,this.onConnect.execute(),xY(this.dtls.sessionId,"dtls connected")}break}}},VO=554869826,vn=8,gn=1398035790,r6=20,MS=24,PS=1,RS=2,un=6,hn=50;var LS=((W)=>{return W[W.REQUEST=0]="REQUEST",W[W.INDICATION=16]="INDICATION",W[W.RESPONSE=256]="RESPONSE",W[W.ERROR=272]="ERROR",W})(LS||{}),BS=((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})(BS||{});function gV(W){return $S(W).toString("hex").substring(0,W)}function FS(){return $S(12)}var FF=class{queue=[];wait=new d0;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((X)=>{this.wait.subscribe((G)=>{this.queue.shift(),X(G)})});return W}},vK=(W)=>{let X,G,Y=new Promise((Z,V)=>{X=Z,G=V});Y.then(()=>{J.execute(void 0),J.complete()}).catch((Z)=>{J.execute(Z??Error()),J.complete()});let J=new d0;return W(X,G,J).catch(()=>{}),{awaitable:Y,resolve:X,reject:G}};function yY(W){let[X]=W,G=tV.default.isV4Format(X)?PS:RS,Y=Buffer.alloc(4);return Y.writeUInt8(0,0),Y.writeUInt8(G,1),Y.writeUInt16BE(W[1],2),Buffer.concat([Y,tV.default.toBuffer(X)])}function bn(W){if(W.length<4)throw Error("STUN error code is less than 4 bytes");let X=W.readUInt8(2),G=W.readUInt8(3),Y=W.slice(4).toString("utf8");return[X*100+G,Y]}function vY(W){if(W.length<4)throw Error("STUN address length is less than 4 bytes");let X=W.readUInt8(1),G=W.readUInt16BE(2),Y=W.slice(4);switch(X){case PS:if(Y.length!=4)throw Error("STUN address has invalid length for IPv4");return[tV.default.toString(Y),G];case RS:if(Y.length!=16)throw Error("STUN address has invalid length for IPv6");return[tV.default.toString(Y),G];default:throw Error("STUN address has unknown protocol")}}var UO=Buffer.alloc(6);UO.writeUInt16BE(VO>>16,0);UO.writeUInt32BE(VO,2);function SS(W,X){let G=[...UO,...X],Y=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),Y=Buffer.concat([Y,V])}return Y}function bq(W,X){return vY(SS(W,X))}function mn(W){let X=Buffer.alloc(4);X.writeUInt16BE(0,0),X.writeUInt8(Math.floor(W[0]/100),2),X.writeUInt8(W[0]%100,3);let G=Buffer.from(W[1],"utf8");return Buffer.concat([X,G])}function mq(W,X){return SS(yY(W),X)}var uV=(W)=>{let X=Buffer.alloc(4);return X.writeUInt32BE(W,0),X},hV=(W)=>W.readUInt32BE(0),fn=(W)=>{let X=Buffer.alloc(4);return X.writeUInt16BE(W,0),X},pn=(W)=>W.readUInt16BE(0),SF=(W)=>{return new aj(W.toString()).toBuffer()},xF=(W)=>{let X=new aj(W);return BigInt(X.toString())},AK=(W)=>Buffer.from(W,"utf8"),zK=(W)=>W.toString("utf8"),IK=(W)=>W,wK=(W)=>W,cn=(W)=>Buffer.from([]),ln=(W)=>null,xS=[[1,"MAPPED-ADDRESS",yY,vY],[3,"CHANGE-REQUEST",uV,hV],[4,"SOURCE-ADDRESS",yY,vY],[5,"CHANGED-ADDRESS",yY,vY],[6,"USERNAME",AK,zK],[8,"MESSAGE-INTEGRITY",IK,wK],[9,"ERROR-CODE",mn,bn],[12,"CHANNEL-NUMBER",fn,pn],[13,"LIFETIME",uV,hV],[18,"XOR-PEER-ADDRESS",mq,bq],[19,"DATA",IK,wK],[20,"REALM",AK,zK],[21,"NONCE",IK,wK],[22,"XOR-RELAYED-ADDRESS",mq,bq],[25,"REQUESTED-TRANSPORT",uV,hV],[32,"XOR-MAPPED-ADDRESS",mq,bq],[36,"PRIORITY",uV,hV],[37,"USE-CANDIDATE",cn,ln],[32802,"SOFTWARE",AK,zK],[32808,"FINGERPRINT",uV,hV],[32809,"ICE-CONTROLLED",SF,xF],[32810,"ICE-CONTROLLING",SF,xF],[32811,"RESPONSE-ORIGIN",yY,vY],[32812,"OTHER-ADDRESS",yY,vY]],kS=class{constructor(W=[]){this.attributes=W}getAttributes(){return this.attributes}setAttribute(W,X){let G=this.attributes.find((Y)=>Y[0]===W);if(G)G[1]=X;else this.attributes.push([W,X]);return this}getAttributeValue(W){let X=this.attributes.find((G)=>G[0]===W);if(!X)return;return X[1]}get attributesKeys(){return this.attributes.map((W)=>W[0])}clear(){this.attributes=[]}},kF=xS.reduce((W,X)=>{return W[X[0]]=X,W},{}),dn=xS.reduce((W,X)=>{return W[X[1]]=X,W},{});function QO(W,X){if(W.length<r6)return;let G=W.readUint16BE(2);if(W.length!==r6+G)return;let Y=W.readUint16BE(0),J=Buffer.from(W.slice(r6-12,r6)),Z=new kS;for(let U=r6;U<=W.length-4;){let Q=W.readUInt16BE(U),N=W.readUInt16BE(U+2),q=W.slice(U+4,U+4+N),A=4*Math.floor((N+3)/4)-N;if(Object.keys(kF).includes(Q.toString())){let[,I,,w]=kF[Q];if(w.name===bq.name)Z.setAttribute(I,w(q,J));else Z.setAttribute(I,w(q));if(I==="FINGERPRINT"){let O=_S(W.slice(0,U));if(Z.getAttributeValue("FINGERPRINT")!==O)return}else if(I==="MESSAGE-INTEGRITY"){if(X){let O=on(W.slice(0,U),X),T=Z.getAttributeValue("MESSAGE-INTEGRITY");if(!O.equals(T))return}}}U+=4+N+A}let V=Z.getAttributes();return Z.clear(),new d7(Y&16111,Y&272,J,V)}var d7=class extends kS{constructor(W,X,G=FS(),Y=[]){super(Y);this.messageMethod=W,this.messageClass=X,this.transactionId=G}toJSON(){return this.json}get json(){return{messageMethod:BS[this.messageMethod],messageClass:LS[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 Y=this.getAttributeValue(G),[J,,Z]=dn[G],V=Z.name===mq.name?Z(Y,this.transactionId):Z(Y),U=V.length,Q=4*Math.floor((U+3)/4)-U,N=Buffer.alloc(4);N.writeUInt16BE(J,0),N.writeUInt16BE(U,2),W=Buffer.concat([W,N,V,Buffer.alloc(Q,0)])}let X=Buffer.alloc(8);return X.writeUInt16BE(this.messageMethod|this.messageClass,0),X.writeUInt16BE(W.length,2),X.writeUInt32BE(VO,4),Buffer.concat([X,this.transactionId,W])}addMessageIntegrity(W){return this.setAttribute("MESSAGE-INTEGRITY",this.messageIntegrity(W)),this}messageIntegrity(W){let X=NO(this.bytes,this.bytes.length-r6+MS);return Buffer.from(ES("sha1",W).update(X).digest("hex"),"hex")}addFingerprint(){this.setAttribute("FINGERPRINT",_S(this.bytes))}},NO=(W,X)=>{let G=Buffer.alloc(W.length);return W.copy(G,0,0,2),G.writeUInt16BE(X,2),W.copy(G,4,4),G};function _S(W){let X=NO(W,W.length-r6+vn);return(cd(X)^gn)>>>0}function on(W,X){let G=NO(W,W.length-r6+MS);return Buffer.from(ES("sha1",X).update(G).digest("hex"),"hex")}function _F(W){let X=W%4;if(X===0)return 0;else return 4-X}var yS=class extends Error{response;addr},vS=class extends yS{constructor(W,X){super();this.response=W,this.addr=X}get str(){let W="STUN transaction failed",X=this.response.getAttributeValue("ERROR-CODE");if(X){let[G,Y]=X;W+=` (${G} - ${Y})`}return W}},nn=class extends yS{get str(){return"STUN transaction timed out"}},jK=P1("werift-ice:packages/ice/src/stun/transaction.ts"),qO=class{constructor(W,X,G,Y){this.request=W,this.addr=X,this.protocol=G,this.retransmissions=Y,this.triesMax=1+(this.retransmissions?this.retransmissions:un)}timeoutDelay=hn;ended=!1;tries=0;triesMax;onResponse=new d0;responseReceived=(W,X)=>{if(this.onResponse.length>0)if(W.messageClass===256)this.onResponse.execute(W,X),this.onResponse.complete();else this.onResponse.error(new vS(W,X))};run=async()=>{try{return this.retry().catch((X)=>{jK("retry failed",X)}),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)=>{jK("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)jK(`retry failed times:${this.tries} maxLimit:${this.triesMax}`),this.onResponse.error(new nn)};cancel(){this.ended=!0}},yF=P1("werift-ice : packages/ice/src/stun/protocol.ts"),vF=class W{static type="stun";type=W.type;transport;transactions={};get transactionsKeys(){return Object.keys(this.transactions)}localCandidate;sentMessage;localIp;onRequestReceived=new d0;onDataReceived=new d0;constructor(){}connectionMade=async(X,G,Y)=>{if(X)this.transport=await BK.init("udp4",{portRange:G,interfaceAddresses:Y});else this.transport=await BK.init("udp6",{portRange:G,interfaceAddresses:Y});this.transport.onData=(J,Z)=>{this.datagramReceived(J,Z)}};datagramReceived(X,G){try{let Y=QO(X);if(!Y){if(this.localCandidate)this.onDataReceived.execute(X);return}if((Y.messageClass===256||Y.messageClass===272)&&this.transactionsKeys.includes(Y.transactionIdHex))this.transactions[Y.transactionIdHex].responseReceived(Y,G);else if(Y.messageClass===0)this.onRequestReceived.execute(Y,G,X)}catch(Y){yF("datagramReceived error",Y)}}getExtraInfo(){let{address:X,port:G}=this.transport.address;return[X,G]}async sendStun(X,G){if(this.transport.closed)return;let Y=X.bytes;await this.transport.send(Y,G).catch(()=>{yF("sendStun failed",G,X)})}async sendData(X,G){if(this.transport.closed)return;await this.transport.send(X,G)}async request(X,G,Y,J){if(this.transactionsKeys.includes(X.transactionIdHex))throw Error("already request ed");if(Y)X.addMessageIntegrity(Y),X.addFingerprint();let Z=new qO(X,G,this,J);this.transactions[X.transactionIdHex]=Z;try{return await Z.run()}catch(V){throw V}finally{delete this.transactions[X.transactionIdHex]}}async close(){Object.values(this.transactions).forEach((X)=>{X.cancel()}),await this.transport.close(),this.onRequestReceived.complete(),this.onDataReceived.complete()}},t9=P1("werift-ice:packages/ice/src/turn/protocol.ts"),sn=500,tn=600,en=285212672,Wi=class W{constructor(X){this.turn=X,X.onData.subscribe((G,Y)=>{this.handleStunMessage(G,Y)}).disposer(this.disposer)}static type="turn";type=W.type;localCandidate;disposer=new id;onRequestReceived=new d0;onDataReceived=new d0;handleStunMessage=(X,G)=>{try{let Y=QO(X);if(!Y){this.onDataReceived.execute(X);return}if(Y.messageClass===256||Y.messageClass===272){let J=this.turn.transactions[Y.transactionIdHex];if(J)J.responseReceived(Y,G)}else if(Y.messageClass===0)this.onRequestReceived.execute(Y,G,X)}catch(Y){t9("datagramReceived error",Y)}};async request(X,G,Y){if(this.turn.transactions[X.transactionIdHex])throw Error("exist");if(Y)X.addMessageIntegrity(Y),X.addFingerprint();let J=new qO(X,G,this);this.turn.transactions[X.transactionIdHex]=J;try{return await J.run()}catch(Z){throw Z}finally{delete this.turn.transactions[X.transactionIdHex]}}async connectionMade(){}async sendData(X,G){await this.turn.sendData(X,G)}async sendStun(X,G){await this.turn.sendData(X.bytes,G)}async close(){return this.disposer.dispose(),this.turn.close()}},Xi=class W{constructor(X,G,Y,J,Z,V={}){this.server=X,this.username=G,this.password=Y,this.lifetime=J,this.transport=Z,this.options=V,this.channelRefreshTime=this.options.channelRefreshTime??sn}static type="turn";type=W.type;onData=new d0;onRequestReceived=new d0;onDataReceived=new d0;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 X=new d7(3,0);X.setAttribute("LIFETIME",this.lifetime).setAttribute("REQUESTED-TRANSPORT",en);let[G]=await this.requestWithRetry(X,this.server).catch((J)=>{throw t9("connect error",J),J});this.relayedAddress=G.getAttributeValue("XOR-RELAYED-ADDRESS"),this.mappedAddress=G.getAttributeValue("XOR-MAPPED-ADDRESS");let Y=G.getAttributeValue("LIFETIME");t9("connect",this.relayedAddress,this.mappedAddress,{exp:Y}),this.refresh(Y)}handleChannelData(X){let[G,Y]=X8.Unpack("!HH",X.slice(0,4)),J=this.addrByChannel[G];if(J){let Z=X.subarray(4,4+Y);this.onData.execute(Z,J)}}handleSTUNMessage(X,G){try{let Y=QO(X);if(!Y)throw Error("not stun message");if(Y.messageClass===256||Y.messageClass===272){let J=this.transactions[Y.transactionIdHex];if(J)J.responseReceived(Y,G)}else if(Y.messageClass===0)this.onData.execute(X,G);if(Y.getAttributeValue("DATA")){let J=Y.getAttributeValue("DATA");this.onData.execute(J,G)}}catch(Y){t9("parse error",X.toString())}}dataReceived(X,G){let Y=(J,Z)=>{if(J.length>=4&&uF(J))this.handleChannelData(J);else this.handleSTUNMessage(J,Z)};if(this.transport.type==="tcp"){this.tcpBuffer=Buffer.concat([this.tcpBuffer,X]);while(this.tcpBuffer.length>=4){let[,J]=e9(this.tcpBuffer.subarray(0,4),[2,2]);J+=_F(J);let Z=uF(this.tcpBuffer)?4+J:20+J;if(this.tcpBuffer.length<Z)break;Y(this.tcpBuffer.subarray(0,Z),G),this.tcpBuffer=this.tcpBuffer.subarray(Z)}}else Y(X,G)}async send(X,G){if(this.transport.closed)return;if(this.transport.type==="tcp"){let Y=_F(X.length);await this.transport.send(Y>0?Buffer.concat([X,Buffer.alloc(Y)]):X,G)}else await this.transport.send(X,G)}async createPermission(X){let G=new d7(8,0);G.setAttribute("XOR-PEER-ADDRESS",X).setAttribute("USERNAME",this.username).setAttribute("REALM",this.realm).setAttribute("NONCE",this.nonce),await this.request(G,this.server).catch((Y)=>{throw Y})}refresh=(X)=>{this.refreshHandle=vK(async(G,Y,J)=>{let Z=!0;J.once(()=>{Z=!1});while(Z){let V=0.8333333333333334*X*1000;t9("refresh delay",V,{exp:X}),await an(V);let U=new d7(4,0);U.setAttribute("LIFETIME",X);try{let[Q]=await this.requestWithRetry(U,this.server);X=Q.getAttributeValue("LIFETIME"),t9("refresh",{exp:X})}catch(Q){t9("refresh error",Q)}}})};async request(X,G){if(this.transactions[X.transactionIdHex])throw Error("exist");if(this.integrityKey)X.setAttribute("USERNAME",this.username).setAttribute("REALM",this.realm).setAttribute("NONCE",this.nonce).addMessageIntegrity(this.integrityKey).addFingerprint();let Y=new qO(X,G,this);this.transactions[X.transactionIdHex]=Y;try{return await Y.run()}catch(J){throw J}finally{delete this.transactions[X.transactionIdHex]}}async requestWithRetry(X,G){let Y,J;try{[Y,J]=await this.request(X,G)}catch(Z){if(Z instanceof vS==!1)throw t9("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(t9("retry with nonce",V),this.nonce=U,V===401)this.realm=Q;this.integrityKey=Yi(this.username,this.realm,this.password),X.transactionId=FS(),[Y,J]=await this.request(X,this.server)}else throw Z}return[Y,J]}async sendData(X,G){let Y=await this.getChannel(G).catch((Z)=>{return Error("channelBind error")});if(Y instanceof Error){await this.getPermission(G);let Z=new d7(6,16).setAttribute("DATA",X).setAttribute("XOR-PEER-ADDRESS",G);await this.sendStun(Z,this.server);return}let J=X8.Pack("!HH",[Y.number,X.length]);await this.send(Buffer.concat([Buffer.from(J),X]),this.server)}async getPermission(X){if(await this.creatingPermission,!this.permissionByAddr[X.join(":")])this.creatingPermission=this.createPermission(X),this.permissionByAddr[X.join(":")]=!0,await this.creatingPermission.catch((Y)=>{throw t9("createPermission error",Y),Y})}async getChannel(X){if(this.channelBinding)await this.channelBinding;let G=this.channelByAddr[X.join(":")];if(!G)this.channelByAddr[X.join(":")]={number:this.channelNumber++,address:X},G=this.channelByAddr[X.join(":")],this.addrByChannel[G.number]=X,this.channelBinding=this.channelBind(G.number,X),await this.channelBinding.catch((Y)=>{throw t9("channelBind error",Y),Y}),this.channelRefreshAt=dV(Date.now()/1000)+this.channelRefreshTime,this.channelBinding=void 0,t9("channelBind",G);else if(this.channelRefreshAt<dV(Date.now()/1000))this.channelBinding=this.channelBind(G.number,X),this.channelRefreshAt=dV(Date.now()/1000)+this.channelRefreshTime,await this.channelBinding.catch((Y)=>{throw t9("channelBind error",Y),Y}),this.channelBinding=void 0,t9("channelBind refresh",G);return G}async channelBind(X,G){let Y=new d7(9,0);Y.setAttribute("CHANNEL-NUMBER",X).setAttribute("XOR-PEER-ADDRESS",G);let[J]=await this.requestWithRetry(Y,this.server);if(J.messageMethod!==9)throw Error("should be CHANNEL_BIND")}async sendStun(X,G){await this.send(X.bytes,G)}async close(){this.refreshHandle?.resolve?.(),await this.transport.close()}};async function Gi({address:W,username:X,password:G},{lifetime:Y,portRange:J,interfaceAddresses:Z,transport:V}={}){Y??=tn,V??="udp";let U=V==="udp"?await BK.init("udp4",{portRange:J,interfaceAddresses:Z}):await sd.init(W),Q=new Xi(W,X,G,Y,U);return await Q.connectionMade(),Q}async function gF({address:W,username:X,password:G},{lifetime:Y,portRange:J,interfaceAddresses:Z,transport:V}={}){let U=await Gi({address:W,username:X,password:G},{lifetime:Y,portRange:J,interfaceAddresses:Z,transport:V});return new Wi(U)}function Yi(W,X,G){return rn("md5").update(Buffer.from([W,X,G].join(":"))).digest()}function uF(W){return(W[0]&192)==64}var TX=class W{constructor(X,G,Y,J,Z,V,U,Q,N,q,A,H){this.foundation=X,this.component=G,this.transport=Y,this.priority=J,this.host=Z,this.port=V,this.type=U,this.relatedAddress=Q,this.relatedPort=N,this.tcptype=q,this.generation=A,this.ufrag=H}static fromSdp(X){let G=X.split(" ");if(G.length<8)throw Error("SDP does not have enough properties");let Y={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,H=G.length-1;A<H;A+=2)if(G[A]==="raddr")Y.related_address=G[A+1];else if(G[A]==="rport")Y.related_port=Number(G[A+1]);else if(G[A]==="tcptype")Y.tcptype=G[A+1];else if(G[A]==="generation")Y.generation=Number(G[A+1]);else if(G[A]==="ufrag")Y.ufrag=G[A+1];let{foundation:J,component:Z,transport:V,priority:U,host:Q,port:N,type:q}=Y;return new W(J,Z,V,U,Q,N,q,Y.related_address,Y.related_port,Y.tcptype,Y.generation,Y.ufrag)}canPairWith(X){let G=hF(this.host),Y=hF(X.host);return this.component===X.component&&this.transport.toLowerCase()===X.transport.toLowerCase()&&G===Y}toSdp(){let X=`${this.foundation} ${this.component} ${this.transport} ${this.priority} ${this.host} ${this.port} typ ${this.type}`;if(this.relatedAddress)X+=` raddr ${this.relatedAddress}`;if(this.relatedPort!=null)X+=` rport ${this.relatedPort}`;if(this.tcptype)X+=` tcptype ${this.tcptype}`;if(this.generation!=null)X+=` generation ${this.generation}`;if(this.ufrag!=null)X+=` ufrag ${this.ufrag}`;return X}};function gK(W,X,G){let Y=`${W}|${X}|${G}`;return Ji("md5").update(Y,"ascii").digest("hex").slice(7)}function fq(W,X=65535){let Y=0;if(W==="host")Y=126;else if(W==="prflx")Y=110;else if(W==="srflx")Y=100;else Y=0;return 16777216*Y+256*X+255}var Vi=class{cache=new Map;mdnsInstance=gS.default();constructor(){this.mdnsInstance.setMaxListeners(50)}lookup(W){return new Promise((X,G)=>{let Y=()=>{this.mdnsInstance.removeListener("response",Z),clearTimeout(J)},J=setTimeout(()=>{Y(),G(Error("No mDNS response"))},1e4),Z=(V)=>{let U=V.answers?.[0];if(U?.type!=="A")return;if(U.name!==W)return;Y(),X(U.data)};this.mdnsInstance.on("response",Z),this.mdnsInstance.query(W,"A")})}close(){this.mdnsInstance.destroy()}},Qi=P1("werift-ice : packages/ice/src/ice.ts : log"),mF=class{constructor(W,X,G){this.protocol=W,this.remoteCandidate=X,this.iceControlling=G}id=Ui().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 hK(this.localCandidate,this.remoteCandidate,this.iceControlling)}get foundation(){return this.localCandidate.foundation}},fF=1,xq=2,Ni=5,pF=6;var qi={useIpv4:!0,useIpv6:!0};function cF(W){if(!["host","relay","srflx"].includes(W.type))throw Error(`Unexpected candidate type "${W.type}"`);return W}function Hi(W,X){return W.sort((G,Y)=>hK(G.localCandidate,G.remoteCandidate,X)-hK(Y.localCandidate,Y.remoteCandidate,X)).reverse()}function hK(W,X,G){let Y=G&&W.priority||X.priority,J=G&&X.priority||W.priority;return 1*Math.min(Y,J)+2*Math.max(Y,J)+(Y>J?1:0)}async function Ai(W,X){let G=new d7(1,0);try{let[Y]=await W.request(G,X),J=W.localCandidate;if(!J)throw Error("not exist");return new TX(gK("srflx","udp",J.host),J.component,J.transport,fq("srflx"),Y.getAttributeValue("XOR-MAPPED-ADDRESS")[0],Y.getAttributeValue("XOR-MAPPED-ADDRESS")[1],"srflx",J.host,J.port)}catch(Y){Qi("error serverReflexiveCandidate",Y)}}function lF(W){if(W&&Number.isNaN(W[1]))return[W[0],443];return W}var zi=P1("werift-ice : packages/ice/src/utils.ts");function Ii(W){return sq(W.family)===4&&W.address?.startsWith("169.254.")||sq(W.family)===6&&W.address?.startsWith("fe80::")}function dF(W,{useLinkLocalAddress:X}={}){let G=["ipsec","tun","utun","tap"],Y=["vmnet","veth"],J=uS.networkInterfaces();zi(J);let Z=Object.keys(J).map((V)=>{for(let Q of[...G,...Y])if(V.startsWith(Q))return{nic:V,addresses:[]};let U=J[V].filter((Q)=>sq(Q.family)===W&&!hS.default.isLoopback(Q.address)&&(X?!0:!Ii(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 wi(W,X,G={}){let Y=[];if(W)Y.push(...dF(4,G));if(X)Y.push(...dF(6,G));return Y}var J8=P1("werift-ice : packages/ice/src/ice.ts : log"),ji=class{constructor(W,X){this._iceControlling=W,this.options={...qi,...X};let{stunServer:G,turnServer:Y}=this.options;this.stunServer=lF(G)??["stun.l.google.com",19302],this.turnServer=lF(Y),this.restart(),J8("new Connection",this.options)}localUsername=gV(4);localPassword=gV(22);remoteIsLite=!1;remotePassword="";remoteUsername="";checkList=[];localCandidates=[];stunServer;turnServer;options;remoteCandidatesEnd=!1;localCandidatesEnd=!1;generation=-1;userHistory={};tieBreaker=BigInt(new Eq(Zi(64)).toString());state="new";lookup;_remoteCandidates=[];nominated;nominating=!1;checkListDone=!1;checkListState=new FF;earlyChecks=[];earlyChecksDone=!1;localCandidatesStart=!1;protocols=[];queryConsentHandle;onData=new d0;stateChanged=new d0;onIceCandidate=new d0;get iceControlling(){return this._iceControlling}set iceControlling(W){if(this.generation>0||this.nominated)return;this._iceControlling=W;for(let X of this.checkList)X.iceControlling=W}async restart(){if(this.generation++,this.localUsername=gV(4),this.localPassword=gV(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 FF,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(){J8("resetNominatedPair"),this.nominated=void 0,this.nominating=!1}setRemoteParams({iceLite:W,usernameFragment:X,password:G}){J8("setRemoteParams",{iceLite:W,usernameFragment:X,password:G}),this.remoteIsLite=W,this.remoteUsername=X,this.remotePassword=G}async gatherCandidates(){if(!this.localCandidatesStart){this.localCandidatesStart=!0;let W=wi(this.options.useIpv4,this.options.useIpv6,{useLinkLocalAddress:this.options.useLinkLocalAddress}),{interfaceAddresses:X}=this.options;if(X){let Y=W.filter((J)=>Object.values(X).includes(J));if(Y.length)W=Y}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((X,G,Y)=>{if(X.messageMethod!==1){this.respondError(X,G,W,[400,"Bad Request"]);return}let J=X.getAttributeValue("USERNAME"),{remoteUsername:Z}=oF(J),V=this.userHistory[Z]??this.localPassword,{iceControlling:U}=this;if(U&&X.attributesKeys.includes("ICE-CONTROLLING"))if(this.tieBreaker>=X.getAttributeValue("ICE-CONTROLLING")){this.respondError(X,G,W,[487,"Role Conflict"]);return}else this.switchRole(!1);else if(!U&&X.attributesKeys.includes("ICE-CONTROLLED"))if(this.tieBreaker<X.getAttributeValue("ICE-CONTROLLED"))this.respondError(X,G,W,[487,"Role Conflict"]);else{this.switchRole(!0);return}if(this.options.filterStunResponse&&!this.options.filterStunResponse(X,G,W))return;let Q=new d7(1,256,X.transactionId);if(Q.setAttribute("XOR-MAPPED-ADDRESS",G).addMessageIntegrity(Buffer.from(V,"utf8")).addFingerprint(),W.sendStun(Q,G).catch((N)=>{J8("sendStun error",N)}),this.checkList.length===0&&!this.earlyChecksDone)this.earlyChecks.push([X,G,W]);else this.checkIncoming(X,G,W)}),W.onDataReceived.subscribe((X)=>{try{let G=this.nominated;if(G&&G.protocol===W)G.packetsReceived++,G.bytesReceived+=X.length;this.onData.execute(X)}catch(G){J8("dataReceived",G)}})}getCandidatePromises(W,X=5){let G=[];W=W.filter((Q)=>{if(this.protocols.find((N)=>N.localIp===Q))return!1;return!0});let Y=W.map(async(Q)=>{let N=new vF;this.ensureProtocol(N);try{await N.connectionMade(bF(Q),this.options.portRange,this.options.interfaceAddresses),N.localIp=Q,this.protocols.push(N),J8("protocol",N.localIp);let q=[Q,N.getExtraInfo()[1]];return N.localCandidate=new TX(gK("host","udp",q[0]),1,"udp",fq("host"),q[0],q[1],"host",void 0,void 0,void 0,this.generation,this.localUsername),this.pairLocalProtocol(N),this.appendLocalCandidate(N.localCandidate),N}catch(q){J8("error protocol STUN",q)}});G.push(...Y.map((Q)=>Q.then((N)=>N?.localCandidate)));let{stunServer:J,turnServer:Z}=this;if(J){let Q=Y.map(async(N)=>{let q=await N;if(!q)return;return new Promise(async(H,I)=>{let w=setTimeout(I,X*1000);if(q.localCandidate?.host&&bF(q.localCandidate?.host)){let O=await Ai(q,J).catch((T)=>{J8("error",T)});if(O)this.appendLocalCandidate(O);clearTimeout(w),H(O)}else clearTimeout(w),H()}).catch((H)=>{J8("query STUN server",H)})});G.push(...Q)}let{turnUsername:V,turnPassword:U}=this.options;if(Z&&V&&U){let Q=(async()=>{let N=await gF({address:Z,username:V,password:U},{portRange:this.options.portRange,interfaceAddresses:this.options.interfaceAddresses,transport:this.options.turnTransport==="tcp"?"tcp":"udp"}).catch(async(H)=>{if(this.options.turnTransport!=="tcp")return await gF({address:Z,username:V,password:U},{portRange:this.options.portRange,interfaceAddresses:this.options.interfaceAddresses,transport:"tcp"});else throw H});this.ensureProtocol(N),this.protocols.push(N);let q=N.turn.relayedAddress,A=N.turn.mappedAddress;return J8("turn candidateAddress",q),N.localCandidate=new TX(gK("relay","udp",q[0]),1,"udp",fq("relay"),q[0],q[1],"relay",A[0],A[1],void 0,this.generation,this.localUsername),this.appendLocalCandidate(N.localCandidate),N.localCandidate})().catch((N)=>{J8("query TURN server",N)});if(this.options.forceTurn)G=[];G.push(Q)}return G}async connect(){if(J8("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 X of this.remoteCandidates)this.pairRemoteCandidate(X);this.sortCheckList(),this.unfreezeInitial(),J8("earlyChecks",this.localPassword,this.earlyChecks.length);for(let X of this.earlyChecks)this.checkIncoming(...X);this.earlyChecks=[],this.earlyChecksDone=!0;for(;;){if(this.state==="closed")break;if(!this.schedulingChecks())break;await uK.setTimeout(20)}let W=xq;while(this.checkList.length>0&&W===xq)W=await this.checkListState.get(),J8("checkListState",W);for(let X of this.checkList)X.handle?.resolve?.();if(W!==fF)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 X=new Set(W.localCandidate.foundation);for(let G of this.checkList)if(G.component===W.component&&!X.has(G.localCandidate.foundation)&&G.state===0)G.updateState(1),X.add(G.localCandidate.foundation)}schedulingChecks(){{let W=this.checkList.filter((X)=>{if(this.options.forceTurn&&X.protocol.type===vF.type)return!1;return!0}).find((X)=>X.state===1);if(W)return W.handle=this.checkStart(W),!0}{let W=this.checkList.find((X)=>X.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=vK(async(W,X,G)=>{let Y=0,J=!1,Z=new AbortController;G.once(()=>{J=!0,Y+=pF,Z.abort(),this.queryConsentHandle=void 0});let{localUsername:V,remoteUsername:U,iceControlling:Q}=this;try{while(this.state!=="closed"&&!J){await uK.setTimeout(Ni*(0.8+0.4*Math.random())*1000,void 0,{signal:Z.signal});let N=this.nominated;if(!N||J)break;let q=this.buildRequest({nominate:!1,localUsername:V,remoteUsername:U,iceControlling:Q});try{if(await N.protocol.request(q,N.remoteAddr,Buffer.from(this.remotePassword,"utf8"),0),Y=0,this.state==="disconnected")this.setState("connected")}catch(A){if(N.id===this.nominated?.id){J8("no stun response"),Y++,this.setState("disconnected");break}}if(Y>=pF){J8("Consent to send expired"),this.queryConsentHandle=void 0,this.setState("closed");break}}}catch(N){}})};async close(){if(this.setState("closed"),this.queryConsentHandle?.resolve?.(),this.checkList&&!this.checkListDone)this.checkListState.put(new Promise((W)=>{W(xq)}));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 Vi;let X=await this.lookup.lookup(W.host);W.host=X}catch(X){return}try{cF(W)}catch(X){return}J8("addRemoteCandidate",W),this._remoteCandidates.push(W),this.pairRemoteCandidate(W),this.sortCheckList()}send=async(W)=>{let X=this.nominated;if(X)await X.protocol.sendData(W,X.remoteAddr),X.packetsSent++,X.bytesSent+=W.length;else return};getDefaultCandidate(){let W=this.localCandidates.sort((G,Y)=>G.priority-Y.priority),[X]=W;return X}set remoteCandidates(W){if(this.remoteCandidatesEnd)throw Error("Cannot set remote candidates after end-of-candidates.");this._remoteCandidates=[];for(let X of W){try{cF(X)}catch(G){continue}this._remoteCandidates.push(X)}this.remoteCandidatesEnd=!0}get remoteCandidates(){return this._remoteCandidates}get candidatePairs(){return this.checkList}sortCheckList(){Hi(this.checkList,this.iceControlling)}findPair(W,X){return this.checkList.find((Y)=>pq.default(Y.protocol,W)&&pq.default(Y.remoteCandidate,X))}switchRole(W){J8("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){J8("nominated",W.toJSON()),this.nominated=W,this.nominating=!1;for(let X of this.checkList)if(X.component===W.component&&[1,0].includes(X.state))X.updateState(4)}if(this.nominated){if(!this.checkListDone)J8("ICE completed"),this.checkListState.put(new Promise((X)=>X(fF))),this.checkListDone=!0;return}J8("not completed",W.toJSON());for(let X of this.checkList)if(X.localCandidate.foundation===W.localCandidate.foundation&&X.state===0)X.updateState(1)}{let X=[3,4];if(this.checkList.find(({state:G})=>!X.includes(G)))return}if(!this.iceControlling){if(this.checkList.find(({state:G})=>G===3))return}if(!this.checkListDone)J8("ICE failed"),this.checkListState.put(new Promise((X)=>{X(xq)}))}checkStart=(W)=>vK(async(X)=>{J8("check start",W.toJSON()),W.updateState(2);let G={},{remotePassword:Y,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}),N=performance.now();try{let[q,A]=await W.protocol.request(Q,W.remoteAddr,Buffer.from(Y,"utf8"),4),I=(performance.now()-N)/1000;W.rtt=I,W.totalRoundTripTime+=I,W.roundTripTimeMeasurements++,J8("response received",Q.toJSON(),q.toJSON(),A,{localUsername:V,remoteUsername:J,remotePassword:Y,generation:Z,rtt:I}),G.response=q,G.addr=A}catch(q){let A=q;if(J8("failure case",Q.toJSON(),A.response?JSON.stringify(A.response.toJSON(),null,2):q,{localUsername:V,remoteUsername:J,remotePassword:Y,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,X();return}if(A.response?.getAttributeValue("ERROR-CODE")[0]===401){J8("retry 401",W.toJSON()),await this.checkStart(W).awaitable,X();return}else{J8("checkStart CandidatePairState.FAILED",W.toJSON()),W.updateState(4),this.checkComplete(W),X();return}}if(!pq.default(G.addr,W.remoteAddr)){W.updateState(4),this.checkComplete(W),X();return}if(U||W.remoteNominated)W.nominated=!0;else if(this.iceControlling&&!this.nominating){this.nominating=!0;let q=this.buildRequest({nominate:!0,localUsername:V,remoteUsername:J,iceControlling:this.iceControlling});try{await W.protocol.request(q,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),X()});addPair(W){this.checkList.push(W),this.sortCheckList()}checkIncoming(W,X,G){let Y=W.getAttributeValue("USERNAME"),{remoteUsername:J}=oF(Y),Z,[V,U]=X;for(let N of this.remoteCandidates)if(N.host===V&&N.port===U){Z=N;break}if(!Z)Z=new TX(gV(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 mF(G,Z,this.iceControlling),Q.updateState(1),this.addPair(Q);if(Q.localCandidate.ufrag=J,J8("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,X){if(W.localCandidate?.canPairWith(X)&&!this.findPair(W,X)){let G=new mF(W,X,this.iceControlling);if(this.options.filterCandidatePair&&!this.options.filterCandidatePair(G))return;G.updateState(1),this.addPair(G)}}pairLocalProtocol(W){for(let X of this.remoteCandidates)this.tryPair(W,X)}pairRemoteCandidate=(W)=>{for(let X of this.protocols)this.tryPair(X,W)};buildRequest({nominate:W,remoteUsername:X,localUsername:G,iceControlling:Y}){let J=Ki({remoteUsername:X,localUsername:G}),Z=new d7(1,0);if(Z.setAttribute("USERNAME",J).setAttribute("PRIORITY",fq("prflx")),Y){if(Z.setAttribute("ICE-CONTROLLING",this.tieBreaker),W)Z.setAttribute("USE-CANDIDATE",null)}else Z.setAttribute("ICE-CONTROLLED",this.tieBreaker);return Z}respondError(W,X,G,Y){let J=new d7(W.messageMethod,272,W.transactionId);J.setAttribute("ERROR-CODE",Y).addMessageIntegrity(Buffer.from(this.localPassword,"utf8")).addFingerprint(),G.sendStun(J,X).catch((Z)=>{J8("sendStun error",Z)})}},Ki=({remoteUsername:W,localUsername:X})=>{return`${W}:${X}`},oF=(W)=>{let[X,G]=W.split(":");return{remoteUsername:X,localUsername:G}};function nF(W){return W.map((X,G)=>[G,X])}function p4(W,X){let G=W.split(X);return[G[0],G.slice(1).join(X)]}var HO=class extends Oi{addEventListener=(W,X)=>{this.addListener(W,X)};removeEventListener=(W,X)=>{this.removeListener(W,X)}},Di=P1("werift:packages/webrtc/src/dataChannel.ts");function Ci(W){return Buffer.isBuffer(W)?W.length:Buffer.byteLength(W)}var bS=class extends HO{constructor(W,X,G=!0){super();if(this.sctp=W,this.parameters=X,this.sendOpen=G,this.id=this.parameters.id,X.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 d0;stateChanged=new d0;onMessage=new d0;error=new d0;bufferedAmountLow=new d0;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}Di("change state",W)}}addBufferedAmount(W){let X=this.bufferedAmount>this.bufferedAmountLowThreshold&&this.bufferedAmount+W<=this.bufferedAmountLowThreshold;if(this.bufferedAmount+=W,X)this.bufferedAmountLow.execute(),this.emit("bufferedamountlow")}send(W){let X=this.sctp.datachannelSend(this,W);this.messagesSent++,this.bytesSent+=X}close(){this.sctp.dataChannelClose(this)}},mS=class{label="";maxPacketLifeTime;maxRetransmits;ordered=!0;protocol="";negotiated=!1;id;constructor(W={}){Object.assign(this,W)}};var OH=()=>({type:"nack"}),NU=()=>({type:"nack",parameter:"pli"}),DH=()=>({type:"goog-remb"}),Ti=()=>({type:"transport-cc"}),FX=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}},Mi=class{id;uri;constructor(W){Object.assign(this,W)}};var Pi=class{type;parameter;constructor(W={}){Object.assign(this,W)}},Ri=class{ssrc;constructor(W={}){Object.assign(this,W)}},Li=class{ssrc;payloadType;rtx;constructor(W){Object.assign(this,W)}},fS=class{rid;direction;constructor(W){Object.assign(this,W)}},Bi=(W={})=>new FX({mimeType:"video/h264",clockRate:90000,rtcpFeedback:[OH(),NU(),DH()],parameters:"profile-level-id=42e01f;packetization-mode=1;level-asymmetry-allowed=1",...W}),pS=(W={})=>new FX({mimeType:"video/VP8",clockRate:90000,rtcpFeedback:[OH(),NU(),DH()],...W}),Ei=(W={})=>new FX({mimeType:"video/VP9",clockRate:90000,rtcpFeedback:[OH(),NU(),DH()],...W}),$i=(W={})=>new FX({mimeType:"video/AV1X",clockRate:90000,rtcpFeedback:[OH(),NU(),DH()],...W}),cS=(W={})=>new FX({mimeType:"audio/OPUS",clockRate:48000,channels:2,...W}),lS=(W={})=>new FX({mimeType:"audio/PCMU",clockRate:8000,channels:1,payloadType:0,...W}),dS=[$i(),Ei(),pS(),Bi(),cS(),lS()].map((W)=>W.mimeType),wA0=dS.filter((W)=>W.toLowerCase().startsWith("video/")),jA0=dS.filter((W)=>W.toLowerCase().startsWith("audio/"));var iF=2,rF=3,ki=0,_q=50,aF=51,sF=53,_i=56,yi=57,vi="0.0.0.0",tF=9,bK={auto:"actpass",client:"active",server:"passive"},eF=Object.keys(bK).reduce((W,X)=>{let G=bK[X];return W[G]=X,W},{}),gi=["apt","max-fr","max-fs","maxplaybackrate","minptime","stereo","useinbandfec"],oS=["cname","msid","mslabel","label"],W2={SRTP_AES128_CM_HMAC_SHA1_80:KH,SRTP_AEAD_AES_128_GCM:UU},cq=["sendonly","sendrecv"],ui=["sendrecv","recvonly"],hi=class extends Map{constructor(W){super();if(W)for(let X of W)this.set(X.id,X)}};function N8(W,...X){let G=X.filter((Y)=>Y!==void 0);return`${W}_${G.join("_")}`}function SX(){return performance.now()}var bi=class{constructor(W,X,G,Y,J){if(this.kind=W,this.receiver=G,this.sender=Y,this._direction=J,X)this.setDtlsTransport(X)}id=xi().toString();onTrack=new d0;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,cq.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((X)=>X.mimeType.toLowerCase().includes(W.toLowerCase()))?.payloadType}getCodecStats(){let W=SX(),X=[];if(!this.dtlsTransport)return X;let G=N8("transport",this.dtlsTransport.id);for(let Y of this.codecs){let J={type:"codec",id:N8("codec",Y.payloadType,G),timestamp:W,payloadType:Y.payloadType,transportId:G,mimeType:Y.mimeType,clockRate:Y.clockRate,channels:Y.channels,sdpFmtpLine:Y.parameters};X.push(J)}return X}},mi="inactive",nS="sendonly",iS="recvonly",rS="sendrecv",OK=[mi,nS,iS,rS],mK=class extends HO{uuid=aS().toString();streamId;remote=!1;label;kind;id;ssrc;rid;header;codec;enabled=!0;onReceiveRtp=new d0;onReceiveRtcp=new d0;onSourceChanged=new d0;stopped=!1;muted=!0;constructor(W){super();Object.assign(this,W),this.onReceiveRtp.subscribe((X)=>{this.muted=!1,this.header=X.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 X=Buffer.isBuffer(W)?WW.deSerialize(W):W;X.header.payloadType=this.codec?.payloadType??X.header.payloadType,this.onReceiveRtp.execute(X)}},fi=class{id;tracks=[];constructor(W){if(Array.isArray(W))this.tracks=W;else Object.assign(this,W);this.id??=aS().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")}},pi=P1("werift:packages/webrtc/src/utils.ts");function sS(W,X){let G=(Z)=>Z.toUpperCase(),Y=(Z)=>Z.match(/(.{2})/g).join(":"),J=Si(X).update(W).digest("hex");return Y(G(J))}var ci={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 tS(W){return ci[W.trim().toLowerCase()]}function fK(W){return W.replace(/[^0-9a-f]/gi,"").toLowerCase()}function li(W){let X=W[0];return X>19&&X<64}var eS=(W,X)=>OK[OK.indexOf(W)&OK.indexOf(X)];function di(W){if(W==="sendonly")return"recvonly";if(W==="recvonly")return"sendonly";return W}var Wx=Date.now,oi=BigInt(Date.now())*1000n-process.hrtime.bigint()/1000n,ni=()=>{return oi+process.hrtime.bigint()/1000n},NH=()=>Date.now()/1000,ii=()=>{let X=(kq.timeOrigin+kq.now()-Date.UTC(1900,0,1))/1000,[G,Y]=X.toString().split(".").map(Number);return S8([4,4],[G,Y]).readBigUInt64BE()},Xx=(W)=>{let X=S8([8],[W]),[,G,Y]=e9(X,[2,2,2,2]);return S8([2,2],[G,Y]).readUInt32BE()};function ri(W){let X=(U)=>{if(!U)return;let[Q,N]=U.split(":");return[Q,Number.parseInt(N)]},G=X(W.find(({urls:U})=>U.includes("stun:"))?.urls.slice(5)),Y=X(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:Y,turnUsername:Z,turnPassword:J};return pi("iceOptions",V),V}var PA0=eq.createSelfSignedCertificateWithKey;var ai=(W,X)=>{if(!W||typeof W!=="object")if(X!==null&&typeof X==="object")return X;else return W;if(!X||typeof X!=="object"){if(X==null)return W;return X}for(let G in X)if(Object.prototype.hasOwnProperty.call(X,G)){let Y=X[G];if(Y!=null)W[G]=Y}return W},si=P1("werift:packages/webrtc/src/media/receiver/nack.ts"),X2=150,ti=class{constructor(W){this.receiver=W}newEstSeqNum=0;_lost={};nackLoop;onPacketLost=new d0;mediaSourceSsrc;retryCount=10;closed=!1;get lostSeqNumbers(){return Object.keys(this._lost).map(Number).sort()}getLost(W){return this._lost[W]}setLost(W,X){if(this._lost[W]=X,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){si("failed to send nack",G)}},5)}removeLost(W){delete this._lost[W]}addPacket(W){let{sequenceNumber:X,ssrc:G}=W.header;if(this.mediaSourceSsrc=G,this.newEstSeqNum===0){this.newEstSeqNum=X;return}if(this.getLost(X)){this.removeLost(X);return}if(X===R9(this.newEstSeqNum,1))this.newEstSeqNum=X;else if(X>R9(this.newEstSeqNum,1)){for(let Y=R9(this.newEstSeqNum,1);Y<X;Y=R9(Y,1))this.setLost(Y,1);this.newEstSeqNum=X,this.pruneLost()}}pruneLost(){if(this.lostSeqNumbers.length>X2)this._lost=Object.entries(this._lost).slice(-X2).reduce((W,[X,G])=>{return W[X]=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,X)=>{if(this.lostSeqNumbers.length>0&&this.mediaSourceSsrc){let G=new VH({senderSsrc:this.receiver.rtcpSsrc,mediaSourceSsrc:this.mediaSourceSsrc,lost:this.lostSeqNumbers}),Y=new mY({feedback:G});this.receiver.dtlsTransport.sendRtcp([Y]).then(W).catch(X),this.updateRetryCount(),this.onPacketLost.execute(G)}})},Wr=P1("werift:packages/webrtc/media/receiver/receiverTwcc"),Xr=class{constructor(W,X,G){this.dtlsTransport=W,this.rtcpSsrc=X,this.mediaSourceSsrc=G,this.runTWCC()}extensionInfo={};twccRunning=!1;fbPktCount=0;lastTimestamp;handleTWCC(W){if(this.extensionInfo[W]={tsn:W,timestamp:ni()},Object.keys(this.extensionInfo).length>10)this.sendTWCC()}async runTWCC(){while(this.twccRunning)this.sendTWCC(),await ei(100)}sendTWCC(){if(Object.keys(this.extensionInfo).length===0)return;let W=Object.values(this.extensionInfo).sort((q,A)=>q.tsn-A.tsn),X=W[0].tsn,G=W.slice(-1)[0].tsn,Y=[],J=W[0].tsn,Z=R9(G-X,1),V,U,Q=[];for(let q=X;q<=G;q++){let A=this.extensionInfo[q]?.timestamp;if(A){if(!this.lastTimestamp)this.lastTimestamp=A;if(!V)V=this.lastTimestamp;let H=A-this.lastTimestamp;this.lastTimestamp=A;let I=new uq({delta:Number(H)});if(I.parseDelta(),Q.push(I),U!=null&&U.status!==I.type)Y.push(new oV({packetStatus:U.status,runLength:q-U.minTSN})),U={minTSN:q,status:I.type};if(q===G)if(U!=null)Y.push(new oV({packetStatus:U.status,runLength:q-U.minTSN+1}));else Y.push(new oV({packetStatus:I.type,runLength:1}));if(U==null)U={minTSN:q,status:I.type}}}if(!V)return;let N=new mY({feedback:new UH({senderSsrc:this.rtcpSsrc,mediaSourceSsrc:this.mediaSourceSsrc,baseSequenceNumber:J,packetStatusCount:Z,referenceTime:dd(Math.floor(Number(V/1000n/64n))),fbPktCount:this.fbPktCount,recvDeltas:Q,packetChunks:Y})});this.dtlsTransport.sendRtcp([N]).catch((q)=>{Wr(q)}),this.extensionInfo={},this.fbPktCount=ld(this.fbPktCount,1)}},Gr=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,X=Date.now()/1000){let G=this.max_seq==null||k2(W.header.sequenceNumber,this.max_seq);if(this.packets_received++,this.base_seq==null)this.base_seq=W.header.sequenceNumber;if(G){let Y=dV(X*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(Y-(this.last_arrival??0)-(W.header.timestamp-(this.last_timestamp??0)));this.jitter_q4+=J-(this.jitter_q4+8>>4)}this.last_arrival=Y,this.last_timestamp=W.header.timestamp}}get fraction_lost(){let W=this.packets_expected-this.expected_prior;this.expected_prior=this.packets_expected;let X=this.packets_received-this.received_prior;this.received_prior=this.packets_received;let G=W-X;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}},X7=P1("werift:packages/webrtc/src/transport/dtls.ts"),G2=class W{constructor(X,G,Y,J=[]){this.config=X,this.iceTransport=G,this.localCertificate=Y,this.srtpProfiles=J,this.localCertificate??=W.localCertificate}id=Zr().toString();state="new";role="auto";srtpStarted=!1;transportSequenceNumber=0;bytesSent=0;bytesReceived=0;packetsSent=0;packetsReceived=0;dataReceiver=()=>{};dtls;srtp;srtcp;onStateChange=new d0;onRtcp=new d0;onRtp=new d0;static localCertificate;static localCertificatePromise;remoteParameters;get localParameters(){return new cK(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:X,keyPem:G,signatureHash:Y}=await eq.createSelfSignedCertificateWithKey({signature:o4.ecdsa_3,hash:tq.sha256_4},t6.secp256r1_23);return this.localCertificate=new Gx(G,X,Y),this.localCertificate})(),this.localCertificatePromise}setRemoteParams(X){let G=Ur([...this.remoteParameters?.fingerprints??[],...X.fingerprints]),Y=X.role==="auto"&&this.remoteParameters?.role?this.remoteParameters.role:X.role;this.remoteParameters=new cK(G,Y)}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(X,G)=>{if(this.role==="server")this.dtls=new yn({cert:this.localCertificate?.certPem,key:this.localCertificate?.privateKey,signatureHash:this.localCertificate?.signatureHash,transport:Y2(this.iceTransport.connection),srtpProfiles:this.srtpProfiles,extendedMasterSecret:!0,certificateRequest:!0});else this.dtls=new EF({cert:this.localCertificate?.certPem,key:this.localCertificate?.privateKey,signatureHash:this.localCertificate?.signatureHash,transport:Y2(this.iceTransport.connection),srtpProfiles:this.srtpProfiles,extendedMasterSecret:!0});if(this.dtls.onData.subscribe((Y)=>{if(this.config.debug.inboundPacketLoss&&this.config.debug.inboundPacketLoss/100<Math.random())return;this.dataReceiver(Y)}),this.dtls.onClose.subscribe(()=>{if(this.state!=="failed")this.setState("closed")}),this.dtls.onConnect.once(X),this.dtls.onError.once((Y)=>{this.setState("failed"),X7("dtls failed",Y),G(Y)}),this.dtls instanceof EF)await Vr(100),this.dtls.connect().catch((Y)=>{this.setState("failed"),X7("dtls connect failed",Y),G(Y)})});try{this.verifyRemoteCertificateFingerprint()}catch(X){throw this.setState("failed"),this.dtls?.close(),X}if(this.srtpProfiles.length>0)this.startSrtp();this.setState("connected"),X7("dtls connected")}verifyRemoteCertificateFingerprint(){if(!this.remoteParameters||this.remoteParameters.fingerprints.length===0)throw Error("remote fingerprint not exist");let X=this.dtls?.remoteCertificate;if(!X)throw Error("remote certificate not available");let G=this.remoteParameters.fingerprints.flatMap(({algorithm:U,value:Q})=>{let N=tS(U);if(!N)return[];let q=fK(Q);if(!q)throw Error("remote fingerprint value is empty");return[{normalizedAlgorithm:N,normalizedValue:q}]});if(G.length===0)throw Error("no supported remote fingerprint algorithms");let Y=Nr(G),J=G.filter(({normalizedAlgorithm:U})=>U===Y),Z=J.reduce((U,{normalizedAlgorithm:Q})=>{if(!U.has(Q))U.set(Q,fK(sS(X,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 X=this.dtls.srtp.srtpProfile;if(!X)throw Error("need srtpProfile");X7("selected SRTP Profile",X);let{localKey:G,localSalt:Y,remoteKey:J,remoteSalt:Z}=this.dtls.extractSessionKeys(uo(X),ho(X)),V={keys:{localMasterKey:G,localMasterSalt:Y,remoteMasterKey:J,remoteMasterSalt:Z},profile:X};this.srtp=new Pn(V),this.srtcp=new Tn(V)}startSrtp(){if(this.srtpStarted)return;this.srtpStarted=!0,this.updateSrtpSession(),this.iceTransport.connection.onData.subscribe((X)=>{if(this.config.debug.inboundPacketLoss&&this.config.debug.inboundPacketLoss/100<Math.random())return;if(!fo(X))return;if(this.bytesReceived+=X.length,this.packetsReceived++,so(X)){let G;try{G=this.srtcp.decrypt(X)}catch(J){if(J instanceof pY){X7("dropping invalid SRTCP packet",J);return}throw J}let Y;try{Y=ao.deSerialize(G)}catch(J){X7("dropping malformed SRTCP packet",J);return}for(let J of Y)try{this.onRtcp.execute(J)}catch(Z){X7("RTCP error",Z)}}else{let G;try{G=this.srtp.decrypt(X)}catch(J){if(J instanceof pY){X7("dropping invalid SRTP packet",J);return}throw J}let Y;try{Y=WW.deSerialize(G)}catch(J){X7("dropping malformed SRTP packet",J);return}try{this.onRtp.execute(Y)}catch(J){X7("RTP error",J)}}})}sendData=async(X)=>{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(X)};async sendRtp(X,G){try{let Y=this.srtp.encrypt(X,G);if(this.config.debug.outboundPacketLoss&&this.config.debug.outboundPacketLoss/100<Math.random())return Y.length;return this.bytesSent+=Y.length,this.packetsSent++,await this.iceTransport.connection.send(Y).catch(()=>{}),Y.length}catch(Y){return X7("failed to send",Y),0}}async sendRtcp(X){let G=Buffer.concat(X.map((J)=>J.serialize())),Y=this.srtcp.encrypt(G);if(this.config.debug.outboundPacketLoss&&this.config.debug.outboundPacketLoss/100<Math.random())return Y.length;this.bytesSent+=Y.length,this.packetsSent++,await this.iceTransport.connection.send(Y).catch(()=>{})}setState(X){if(X!=this.state)this.state=X,this.onStateChange.execute(X)}async stop(){this.setState("closed"),await this.iceTransport.stop()}async getStats(){let X=SX(),G=[],J={type:"transport",id:N8("transport",this.id),timestamp:X,bytesSent:this.bytesSent,bytesReceived:this.bytesReceived,packetsSent:this.packetsSent,packetsReceived:this.packetsReceived,dtlsState:this.state,iceState:this.iceTransport.state,selectedCandidatePairId:this.iceTransport.connection.nominated?N8("candidate-pair",this.iceTransport.connection.nominated.localCandidate.foundation,this.iceTransport.connection.nominated.remoteCandidate.foundation):void 0,localCertificateId:this.localCertificate?N8("certificate","local"):void 0,remoteCertificateId:this.remoteParameters?N8("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:N8("certificate","local"),timestamp:X,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:N8("certificate","remote"),timestamp:X,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 Gx=class{constructor(W,X,G){this.certPem=X,this.signatureHash=G;let Y=eV.Certificate.fromPEM(Buffer.from(X));this.publicKey=Y.publicKey.toPEM(),this.privateKey=eV.PrivateKey.fromPEM(Buffer.from(W)).toPEM()}publicKey;privateKey;getFingerprints(){return[new pK("sha-256",sS(eV.Certificate.fromPEM(Buffer.from(this.certPem)).raw,"sha256"))]}},pK=class{constructor(W,X){this.algorithm=W,this.value=X}},cK=class{constructor(W=[],X){this.fingerprints=W,this.role=X}},Ur=(W)=>{let X=new Set;return W.filter(({algorithm:G,value:Y})=>{let J=`${tS(G)??G.trim().toLowerCase()}:${fK(Y)}`;if(X.has(J))return!1;return X.add(J),!0})},Qr=["sha512","sha384","sha256","sha224","sha1"],Nr=(W)=>{return Qr.find((X)=>W.some(({normalizedAlgorithm:G})=>G===X))??W[0].normalizedAlgorithm},qr=class{constructor(W){this.ice=W,W.onData.subscribe((X)=>{if(li(X)){if(this.onData)this.onData(X)}})}closed=!1;onData=()=>{};get address(){return{}}type="ice";send=(W)=>{return this.ice.send(W)};async close(){this.closed=!0,this.ice.close()}},Y2=(W)=>new qr(W),J2=P1("werift:packages/webrtc/src/transport/ice.ts"),Ar=class{constructor(W){this.iceGather=W,this.connection=this.iceGather.connection,this.connection.stateChanged.subscribe((X)=>{this.setState(X)}),this.iceGather.onIceCandidate=(X)=>{this.onIceCandidate.execute(X)}}id=Hr().toString();connection;state="new";waitStart;renominating=!1;onStateChange=new d0;onIceCandidate=new d0;onNegotiationNeeded=new d0;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(Ir(W))};setRemoteParams(W,X=!1){if(X)this.renominating=!0;if(this.connection.remoteUsername&&this.connection.remotePassword&&(this.connection.remoteUsername!==W.usernameFragment||this.connection.remotePassword!==W.password))if(this.renominating)J2("renomination",W),this.connection.resetNominatedPair(),this.renominating=!1;else J2("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 d0,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=SX(),X=[];for(let Y of this.localCandidates){let J={type:"local-candidate",id:N8("local-candidate",Y.foundation),timestamp:W,transportId:N8("transport",this.id),address:Y.ip,port:Y.port,protocol:Y.protocol,candidateType:Y.type,priority:Y.priority,foundation:Y.foundation};X.push(J)}for(let Y of this.connection.remoteCandidates){let J=WU(Y),Z={type:"remote-candidate",id:N8("remote-candidate",J.foundation),timestamp:W,transportId:N8("transport",this.id),address:J.ip,port:J.port,protocol:J.protocol,candidateType:J.type,priority:J.priority,foundation:J.foundation};X.push(Z)}let G=this.connection?.candidatePairs?[...this.connection.candidatePairs.filter((Y)=>Y.nominated),...this.connection.candidatePairs.filter((Y)=>!Y.nominated)]:[];for(let Y of G){let J={type:"candidate-pair",id:N8("candidate-pair",Y.foundation),timestamp:W,transportId:N8("transport",this.id),localCandidateId:N8("local-candidate",Y.localCandidate.foundation),remoteCandidateId:N8("remote-candidate",Y.remoteCandidate.foundation),state:Y.state,nominated:Y.nominated,packetsSent:Y.packetsSent,packetsReceived:Y.packetsReceived,bytesSent:Y.bytesSent,bytesReceived:Y.bytesReceived,currentRoundTripTime:Y.rtt};X.push(J)}return X}};var zr=class{constructor(W={}){this.options=W,this.connection=new ji(!1,this.options),this.connection.onIceCandidate.subscribe((X)=>{this.onIceCandidate(WU(X))})}onIceCandidate=()=>{};gatheringState="new";connection;onGatheringStateChange=new d0;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(WU)}get localParameters(){return new Jx({usernameFragment:this.connection.localUsername,password:this.connection.localPassword})}setState(W){if(W!==this.gatheringState)this.gatheringState=W,this.onGatheringStateChange.execute(W)}};function WU(W){let X=new Yx(W.component,W.foundation,W.host,W.port,W.priority,W.transport,W.type,W.generation,W.ufrag);return X.relatedAddress=W.relatedAddress,X.relatedPort=W.relatedPort,X.tcpType=W.tcptype,X}function Ir(W){return new TX(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 wr=class{candidate;sdpMid;sdpMLineIndex;usernameFragment;constructor(W){Object.assign(this,W)}static fromSdp(W){let X=TX.fromSdp(W);return WU(X).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}}},Yx=class{constructor(W,X,G,Y,J,Z,V,U,Q){this.component=W,this.foundation=X,this.ip=G,this.port=Y,this.priority=J,this.protocol=Z,this.type=V,this.generation=U,this.ufrag=Q}relatedAddress;relatedPort;sdpMid;sdpMLineIndex;tcpType;toJSON(){return new wr({candidate:Ix(this),sdpMLineIndex:this.sdpMLineIndex,sdpMid:this.sdpMid,usernameFragment:this.ufrag})}static fromJSON(W){try{if(!W.candidate)throw Error("candidate is required");let X=wx(W.candidate);return X.sdpMLineIndex=W.sdpMLineIndex??void 0,X.sdpMid=W.sdpMid??void 0,X}catch(X){}}},Jx=class{iceLite=!1;usernameFragment;password;constructor(W={}){Object.assign(this,W)}},n7=class W{constructor(X=0,G=Buffer.from("")){this.flags=X,this._body=G}get body(){return this._body}set body(X){this._body=X}static type=-1;get type(){return W.type}get bytes(){if(!this.body)throw Error();let X=Buffer.alloc(4);return X.writeUInt8(this.type,0),X.writeUInt8(this.flags,1),X.writeUInt16BE(this.body.length+4,2),Buffer.concat([X,this.body,...[...Array(HU(this.body.length))].map(()=>Buffer.from("\x00"))])}},AO=class extends n7{constructor(W=0,X){super(W,X);if(this.flags=W,X)this.initiateTag=X.readUInt32BE(0),this.advertisedRwnd=X.readUInt32BE(4),this.outboundStreams=X.readUInt16BE(8),this.inboundStreams=X.readUInt16BE(10),this.initialTsn=X.readUInt32BE(12),this.params=qx(X.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,Nx(this.params)])}},lq=class W extends AO{static type=1;get type(){return W.type}},lK=class W extends AO{static type=2;get type(){return W.type}},Or=class W extends AO{static type=130;get type(){return W.type}},dq=class W extends n7{constructor(X=0,G){super(X,G);if(this.flags=X,G){this.cumulativeTsn=G.readUInt32BE(0);let Y=4;while(Y<G.length)this.streams.push([G.readUInt16BE(Y),G.readUInt16BE(Y+2)]),Y+=4}else this.cumulativeTsn=0}static type=192;streams=[];cumulativeTsn;get type(){return W.type}set body(X){}get body(){let X=Buffer.alloc(4);return X.writeUInt32BE(this.cumulativeTsn,0),Buffer.concat([X,...this.streams.map(([G,Y])=>{let J=Buffer.alloc(4);return J.writeUInt16BE(G,0),J.writeUInt16BE(Y,2),J})])}},oq=class W extends n7{constructor(X=0,G){super(X,G);if(this.flags=X,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 X=16+this.userData.length,G=Buffer.alloc(16);G.writeUInt8(this.type,0),G.writeUInt8(this.flags,1),G.writeUInt16BE(X,2),G.writeUInt32BE(this.tsn,4),G.writeUInt16BE(this.streamId,8),G.writeUInt16BE(this.streamSeqNum,10),G.writeUInt32BE(this.protocol,12);let Y=Buffer.concat([G,this.userData]);if(X%4)Y=Buffer.concat([Y,...[...Array(HU(X))].map(()=>Buffer.from("\x00"))]);return Y}},dK=class W extends n7{static type=10;get type(){return W.type}},oK=class W extends n7{static type=11;get type(){return W.type}},qU=class extends n7{constructor(W=0,X=void 0){super(W,X);if(this.flags=W,X)this.params=qx(X)}params=[];get body(){return Nx(this.params)}},nK=class W extends qU{static type=6;get type(){return W.type}},nq=class W extends qU{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(([X,G])=>{return{name:(Object.entries(W.CODE).find(([,J])=>J===X)||[])[0],body:G}})}},iK=class W extends qU{static type=4;get type(){return W.type}},Zx=class W extends qU{static type=5;get type(){return W.type}},rK=class W extends qU{static type=130;get type(){return W.type}},aK=class W extends n7{constructor(X=0,G){super(X,G);if(this.flags=X,G){this.cumulativeTsn=G.readUInt32BE(0),this.advertisedRwnd=G.readUInt32BE(4);let Y=G.readUInt16BE(8),J=G.readUInt16BE(10),Z=12;[...Array(Y)].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 X=16+4*(this.gaps.length+this.duplicates.length),G=Buffer.alloc(16);G.writeUInt8(this.type,0),G.writeUInt8(this.flags,1),G.writeUInt16BE(X,2),G.writeUInt32BE(this.cumulativeTsn,4),G.writeUInt32BE(this.advertisedRwnd,8),G.writeUInt16BE(this.gaps.length,12),G.writeUInt16BE(this.duplicates.length,14);let Y=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 Y=Buffer.concat([Y,...this.duplicates.map((J)=>{let Z=Buffer.alloc(4);return Z.writeUInt32BE(J,0),Z})]),Y}},Vx=class W extends n7{constructor(X=0,G){super(X,G);if(this.flags=X,G)this.cumulativeTsn=G.readUInt32BE(0)}static type=7;get type(){return W.type}cumulativeTsn=0;get body(){let X=Buffer.alloc(4);return X.writeUInt32BE(this.cumulativeTsn,0),X}},Ux=class W extends n7{static type=8;get type(){return W.type}},Qx=class W extends n7{static type=14;get type(){return W.type}},Dr=[oq,lq,lK,aK,iK,Zx,nK,Vx,Ux,nq,dK,oK,Qx,rK,dq],Cr=Dr.reduce((W,X)=>{return W[X.type]=X,W},{});function HU(W){let X=W%4;return X?4-X:0}function Nx(W){let X=Buffer.from(""),G=Buffer.from("");return W.forEach(([Y,J])=>{let Z=J.length+4,V=Buffer.alloc(4);V.writeUInt16BE(Y,0),V.writeUInt16BE(Z,2),X=Buffer.concat([X,G,V,J]),G=Buffer.concat([...Array(HU(Z))].map(()=>Buffer.from("\x00")))}),X}function qx(W){let X=[],G=0;while(G<=W.length-4){let Y=W.readUInt16BE(G),J=W.readUInt16BE(G+2);X.push([Y,W.slice(G+4,G+J)]),G+=J+HU(J)}return X}function Tr(W){if(W.length<12)throw Error("SCTP packet length is less than 12 bytes");let X=W.readUInt16BE(0),G=W.readUInt16BE(2),Y=W.readUInt32BE(4),J=W.readUInt32LE(8),Z=x2(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),N=W.readUInt8(U+1),q=W.readUInt16BE(U+2),A=W.slice(U+4,U+q),H=Cr[Q.toString()];if(H)V.push(new H(N,A));else throw Error("unknown");U+=q+HU(q)}return[X,G,Y,V]}function Mr(W,X,G,Y){let J=Buffer.alloc(8);J.writeUInt16BE(W,0),J.writeUInt16BE(X,2),J.writeUInt32BE(G,4);let Z=Y.bytes,V=x2(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 Pr(W){return W.map((X,G)=>[G,X])}function Rr(W){return W.reduce((X,G)=>{return X[G]=new d0,X},{})}var sK=class W{constructor(X,G,Y,J){this.requestSequence=X,this.responseSequence=G,this.lastTsn=Y,this.streams=J}static type=13;get type(){return W.type}get bytes(){let X=Buffer.from(X8.Pack("!LLL",[this.requestSequence,this.responseSequence,this.lastTsn]));return Buffer.concat([X,...this.streams.map((G)=>Buffer.from(X8.Pack("!H",[G])))])}static parse(X){let[G,Y,J]=X8.Unpack("!LLL",X),Z=[];for(let V=12;V<X.length;V+=2)Z.push(X8.Unpack("!H",X.slice(V))[0]);return new W(G,Y,J,Z)}},Hx=class W{constructor(X,G){this.requestSequence=X,this.newStreams=G}static type=17;get type(){return W.type}get bytes(){return Buffer.from(X8.Pack("!LHH",[this.requestSequence,this.newStreams,0]))}static parse(X){let[G,Y]=X8.Unpack("!LHH",X);return new W(G,Y)}},yq={ReconfigResultSuccessPerformed:1,BadSequenceNumber:5},iq=class W{constructor(X,G){this.responseSequence=X,this.result=G}static type=16;get type(){return W.type}get bytes(){return Buffer.from(X8.Pack("!LL",[this.responseSequence,this.result]))}static parse(X){let[G,Y]=X8.Unpack("!LL",X);return new W(G,Y)}},V2={13:sK,16:iq,17:Hx},e1=P1("werift/sctp/sctp"),Lr=24,Br=60,U2=65535,G7=1200,pV=1,Ax=2,tK=4,Q2=10,Er=8,N2=0.125,q2=0.25,H2=3,$r=1,Fr=60,qH=4294967296,Sr=200,xr=30,A2=135,z2=7,I2=32776,w2=49152,kr=["new","closed","connected","connecting"],_r=class W{constructor(X,G=5000){this.transport=X,this.port=G,this.localPort=this.port,this.transport.onData=(Y)=>{this.handleData(Y)}}flush=new d0;stateChanged=Rr(kr);onReconfigStreams=new d0;onReceive=new d0;onSackReceived=async()=>{};associationState=1;started=!1;state="new";isServer=!0;isStopping=!1;isClosed=!1;hmacKey=Kr(16);localPartialReliability=!0;localPort;localVerificationTag=PK();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=U2;lastReceivedTsn;sackDuplicates=[];sackMisOrdered=new Set;sackNeeded=!1;sackPacketCount=0;sackHasNewDataInPacket=!1;sackImmediate=!1;sackTimeout;cwnd=3*G7;fastRecoveryExit;fastRecoveryTransmit=!1;forwardTsnChunk;flightSize=0;outboundQueue=[];outboundStreamSeq={};_outboundStreamsCount=U2;localTsn=Number(PK());lastSackedTsn=DX(this.localTsn);advancedPeerAckTsn=DX(this.localTsn);partialBytesAcked=0;sentQueue=[];transmitting=!1;transmitRequested=!1;reconfigRequestSeq=this.localTsn;reconfigResponseSeq=0;reconfigRequest;reconfigQueue=[];srtt;rttvar;rto=H2;timer1Handle;timer1Chunk;timer1Failures=0;timer2Handle;timer2Chunk;timer2Failures=0;timer3Handle;timerReconfigHandle;timerReconfigFailures=0;timerHeartbeatHandle;heartbeatInterval=xr;ssthresh;get isStopped(){return this.isStopping||this.isClosed}get maxChannels(){if(this._inboundStreamsCount>0)return Math.min(this._inboundStreamsCount,this._outboundStreamsCount);return}static client(X,G=5000){let Y=new W(X,G);return Y.isServer=!1,Y}static server(X,G=5000){let Y=new W(X,G);return Y.isServer=!0,Y}async handleData(X){if(this.isStopped)return;let G,[,,Y,J]=Tr(X);if(J.filter((V)=>V.type===lq.type).length>0){if(J.length!=1)throw Error();G=0}else G=this.localVerificationTag;if(Y!==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((X)=>{e1("send delayed sack failed",X.message)})},Sr)}async sendSack(){if(this.isStopped)return;if(!this.sackNeeded)return;let X=[],G;[...this.sackMisOrdered].sort().forEach((J)=>{let Z=(J-this.lastReceivedTsn)%qH;if(J===G)X[X.length-1][1]=Z;else X.push([Z,Z]);G=gY(J)});let Y=new aK(0,void 0);Y.cumulativeTsn=this.lastReceivedTsn,Y.advertisedRwnd=Math.max(0,this.advertisedRwnd),Y.duplicates=[...this.sackDuplicates],Y.gaps=X,await this.sendChunk(Y).catch((J)=>{e1("send sack failed",J.message)}),this.sackDuplicates=[],this.sackNeeded=!1,this.sackPacketCount=0,this.sackImmediate=!1}async receiveChunk(X){switch(X.type){case oq.type:this.receiveDataChunk(X);break;case lq.type:{if(!this.isServer)return;let G=X;e1("receive init",G),this.lastReceivedTsn=DX(G.initialTsn),this.reconfigResponseSeq=DX(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 Y=new lK;Y.initiateTag=this.localVerificationTag,Y.advertisedRwnd=this.advertisedRwnd,Y.outboundStreams=this._outboundStreamsCount,Y.inboundStreams=this._inboundStreamsCount,Y.initialTsn=this.localTsn,this.setExtensions(Y.params);let J=Date.now()/1000,Z=Buffer.from(X8.Pack("!L",[J]));Z=Buffer.concat([Z,Z2("sha1",this.hmacKey).update(Z).digest()]),Y.params.push([z2,Z]),e1("send initAck",Y),await this.sendChunk(Y).catch((V)=>{e1("send initAck failed",V.message)})}break;case lK.type:{if(this.associationState!=2)return;let G=X;this.timer1Cancel(),this.lastReceivedTsn=DX(G.initialTsn),this.reconfigResponseSeq=DX(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 Y=new dK;for(let[J,Z]of G.params)if(J===z2){Y.body=Z;break}await this.sendChunk(Y).catch((J)=>{e1("send echo failed",J.message)}),this.timer1Start(Y),this.setState(3)}break;case aK.type:await this.receiveSackChunk(X);break;case iK.type:{let G=new Zx;G.params=X.params,await this.sendChunk(G).catch((Y)=>{e1("send heartbeat ack failed",Y.message)})}break;case nK.type:this.setState(1);break;case Vx.type:{this.timer2Cancel(),this.setState(7);let G=new Ux;await this.sendChunk(G).catch((Y)=>{e1("send shutdown ack failed",Y.message)}),this.t2Start(G),this.setState(6)}break;case nq.type:e1("ErrorChunk",X.descriptions);break;case dK.type:{if(!this.isServer)return;let Y=X.body,J=Z2("sha1",this.hmacKey).update(Y.slice(0,4)).digest();if(Y?.length!=Lr||!Y.slice(4).equals(J)){e1("x State cookie is invalid");return}let Z=Date.now()/1000,V=X8.Unpack("!L",Y)[0];if(V<Z-Br||V>Z){let Q=new nq(0,void 0);Q.params.push([nq.CODE.StaleCookieError,Buffer.concat([...Array(8)].map(()=>Buffer.from("\x00")))]),await this.sendChunk(Q).catch((N)=>{e1("send errorChunk failed",N.message)});return}let U=new oK;await this.sendChunk(U).catch((Q)=>{e1("send cookieAck failed",Q.message)}),this.setState(4)}break;case oK.type:{if(this.associationState!=3)return;this.timer1Cancel(),this.setState(4)}break;case Qx.type:{if(this.associationState!=8)return;this.timer2Cancel(),this.setState(1)}break;case rK.type:{if(this.associationState!=4)return;let G=X;for(let[Y,J]of G.params){let Z=V2[Y];if(Z)await this.receiveReconfigParam(Z.parse(J))}}break;case dq.type:this.receiveForwardTsnChunk(X);break}}getExtensions(X){for(let[G,Y]of X)if(G===w2)this.remotePartialReliability=!0;else if(G===I2)this.remoteExtensions=[...Y]}async receiveReconfigParam(X){switch(e1("receiveReconfigParam",V2[X.type]),X.type){case sK.type:{let G=X,Y=new iq(G.requestSequence,yq.ReconfigResultSuccessPerformed);this.reconfigResponseSeq=G.requestSequence,await this.sendReconfigParam(Y),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 iq.type:{let G=X;if(G.result!==yq.ReconfigResultSuccessPerformed)e1("OutgoingSSNResetRequestParam failed",Object.keys(yq).find((Y)=>yq[Y]===G.result));else if(G.responseSequence===this.reconfigRequest?.requestSequence){let Y=this.reconfigRequest.streams.map((J)=>{return delete this.outboundStreamSeq[J],J});if(this.onReconfigStreams.execute(Y),this.reconfigRequest=void 0,this.timerReconfigCancel(),this.rto=H2,this.timerReconfigFailures=0,this.reconfigQueue.length>0)await this.transmitReconfigRequest()}}break;case Hx.type:{let G=X;this._inboundStreamsCount+=G.newStreams;let Y=new iq(G.requestSequence,1);this.reconfigResponseSeq=G.requestSequence,await this.sendReconfigParam(Y)}break}}receiveDataChunk(X){if(this.sackNeeded=!0,this.markReceived(X.tsn)){this.sackImmediate=!0;return}if(this.sackHasNewDataInPacket=!0,this.sackImmediate=!0,(X.flags&pV)===0)this.sackImmediate=!0;if(this.sackMisOrdered.size>0)this.sackImmediate=!0;let G=this.getInboundStream(X.streamId);G.addChunk(X),this.advertisedRwnd-=X.userData.length;for(let Y of G.popMessages())this.advertisedRwnd+=Y[2].length,this.receive(...Y)}async receiveSackChunk(X){if(c4(this.lastSackedTsn,X.cumulativeTsn))return;let G=Date.now()/1000;this.lastSackedTsn=X.cumulativeTsn;let Y=this.flightSize>=this.cwnd,J=0,Z=0;while(this.sentQueue.length>0&&fV(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(X.gaps.length>0){let U=new Set,Q;X.gaps.forEach((q)=>{for(let A=q[0];A<q[1]+1;A++)Q=(X.cumulativeTsn+A)%qH,U.add(Q)});let N=X.cumulativeTsn;for(let q of this.sentQueue){if(c4(q.tsn,Q))break;if(U.has(q.tsn)&&!q.acked)Z+=q.bookSize,q.acked=!0,this.flightSizeDecrease(q),N=q.tsn}for(let q of this.sentQueue){if(c4(q.tsn,N))break;if(!U.has(q.tsn)){if(q.misses++,q.misses===3){if(q.misses=0,!this.maybeAbandon(q))q.retransmit=!0;q.acked=!1,this.flightSizeDecrease(q),V=!0}}}}if(this.fastRecoveryExit===void 0){if(J&&Y){if(this.cwnd<=this.ssthresh)this.cwnd+=Math.min(Z,G7);else if(this.partialBytesAcked+=Z,this.partialBytesAcked>=this.cwnd)this.partialBytesAcked-=this.cwnd,this.cwnd+=G7}if(V)this.ssthresh=Math.max(Math.floor(this.cwnd/2),4*G7),this.cwnd=this.ssthresh,this.partialBytesAcked=0,this.fastRecoveryExit=this.sentQueue[this.sentQueue.length-1].tsn,this.fastRecoveryTransmit=!0}else if(fV(X.cumulativeTsn,this.fastRecoveryExit))this.fastRecoveryExit=void 0;if(this.sentQueue.length===0)this.timer3Cancel();else if(J>0)this.timer3Restart();this.peerAdvertisedRwnd=X.advertisedRwnd,this.updateAdvancedPeerAckPoint(),await this.onSackReceived(),await this.transmit()}receiveForwardTsnChunk(X){if(this.sackNeeded=!0,this.sackImmediate=!0,fV(this.lastReceivedTsn,X.cumulativeTsn))return;let G=(Y)=>c4(Y,this.lastReceivedTsn);this.lastReceivedTsn=X.cumulativeTsn,this.sackMisOrdered=new Set([...this.sackMisOrdered].filter(G));for(let Y of[...this.sackMisOrdered].sort())if(Y===gY(this.lastReceivedTsn))this.lastReceivedTsn=Y;else break;this.sackDuplicates=this.sackDuplicates.filter(G),this.sackMisOrdered=new Set([...this.sackMisOrdered].filter(G));for(let[Y,J]of X.streams){let Z=this.getInboundStream(Y);Z.streamSequenceNumber=R9(J,1);for(let V of Z.popMessages())this.advertisedRwnd+=V[2].length,this.receive(...V)}Object.values(this.inboundStreams).forEach((Y)=>{this.advertisedRwnd+=Y.pruneChunks(this.lastReceivedTsn)})}updateRto(X){if(!this.srtt)this.rttvar=X/2,this.srtt=X;else this.rttvar=(1-q2)*this.rttvar+q2*Math.abs(this.srtt-X),this.srtt=(1-N2)*this.srtt+N2*X;this.rto=Math.max($r,Math.min(this.srtt+4*this.rttvar,Fr))}receive(X,G,Y){this.onReceive.execute(X,G,Y)}getInboundStream(X){if(!this.inboundStreams[X])this.inboundStreams[X]=new yr;return this.inboundStreams[X]}markReceived(X){if(fV(this.lastReceivedTsn,X)||this.sackMisOrdered.has(X))return this.sackDuplicates.push(X),!0;this.sackMisOrdered.add(X);for(let Y of[...this.sackMisOrdered].sort())if(Y===gY(this.lastReceivedTsn))this.lastReceivedTsn=Y;else break;let G=(Y)=>c4(Y,this.lastReceivedTsn);return this.sackDuplicates=this.sackDuplicates.filter(G),this.sackMisOrdered=new Set([...this.sackMisOrdered].filter(G)),!1}send=async(X,G,Y,{expiry:J,maxRetransmits:Z,ordered:V}={expiry:void 0,maxRetransmits:void 0,ordered:!0})=>{let U=V?this.outboundStreamSeq[X]||0:0,Q=Math.ceil(Y.length/G7),N=0,q=[];for(let A=0;A<Q;A++){let H=new oq(0,void 0);if(H.flags=0,!V)H.flags=tK;if(A===0)H.flags|=Ax;if(A===Q-1)H.flags|=pV;H.tsn=this.localTsn,H.streamId=X,H.streamSeqNum=U,H.protocol=G,H.userData=Y.slice(N,N+G7),H.bookSize=H.userData.length,H.expiry=J,H.maxRetransmits=Z,N+=G7,this.localTsn=gY(this.localTsn),q.push(H)}if(q.forEach((A)=>{this.outboundQueue.push(A)}),V)this.outboundStreamSeq[X]=R9(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)=>{e1("send forwardTsn failed",J.message)}),this.forwardTsnChunk=void 0,!this.timer3Handle)this.timer3Start()}let X=this.fastRecoveryExit!=null?2*G7:4*G7,G=Math.min(this.flightSize+X,this.cwnd),Y=!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)=>{e1("send data failed",Z.message)}),Y)this.timer3Restart()}Y=!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)=>{e1("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 X=[...new Set(this.reconfigQueue)],G=X.slice(0,A2);this.reconfigQueue=X.slice(A2);let Y=new sK(this.reconfigRequestSeq,this.reconfigResponseSeq,DX(this.localTsn),G);this.reconfigRequestSeq=gY(this.reconfigRequestSeq),this.reconfigRequest=Y,await this.sendReconfigParam(Y),this.timerReconfigHandleStart()}}async sendReconfigParam(X){e1("sendReconfigParam",X);let G=new rK;G.params.push([X.type,X.bytes]),await this.sendChunk(G).catch((Y)=>{e1("send reconfig failed",Y.message)})}async sendResetRequest(X){e1("sendResetRequest",X);let G=new oq(0,void 0);if(G.streamId=X,this.outboundQueue.push(G),!this.timer3Handle)await this.transmit()}flightSizeIncrease(X){this.flightSize+=X.bookSize}flightSizeDecrease(X){this.flightSize=Math.max(0,this.flightSize-X.bookSize)}timer1Start(X){if(this.timer1Handle)throw Error();this.timer1Chunk=X,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>Er)this.setState(1);else{if(setImmediate(()=>{if(this.isStopped)return;this.sendChunk(this.timer1Chunk).catch((X)=>{e1("send timer1 chunk failed",X.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(X){if(this.timer2Handle)throw Error();this.timer2Chunk=X,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>Q2)this.setState(1);else{if(setImmediate(()=>{if(this.isStopped)return;this.sendChunk(this.timer2Chunk).catch((X)=>{e1("send timer2Chunk failed",X.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((X)=>{if(!this.maybeAbandon(X))X.retransmit=!0}),this.updateAdvancedPeerAckPoint(),this.fastRecoveryExit=void 0,this.flightSize=0,this.partialBytesAcked=0,this.ssthresh=Math.max(Math.floor(this.cwnd/2),4*G7),this.cwnd=G7,this.transmit()};timer3Cancel(){if(this.timer3Handle)clearTimeout(this.timer3Handle),this.timer3Handle=void 0}timerReconfigHandleStart(){if(this.isStopped)return;if(this.timerReconfigHandle)return;e1("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>Q2)e1("timerReconfigFailures",this.timerReconfigFailures),this.setState(1),this.timerReconfigHandle=void 0;else if(this.reconfigRequest){if(e1("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)e1("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 X=new iK;X.params.push([1,Buffer.from(X8.Pack("!L",[Math.floor(Date.now()/1000)]))]),await this.sendChunk(X).catch((G)=>{e1("send heartbeat failed",G.message)})}this.heartbeatStart()};setHeartbeatInterval(X){if(X<=0)throw Error("heartbeat interval must be > 0");this.heartbeatInterval=X,this.heartbeatRestart()}updateAdvancedPeerAckPoint(){if(c4(this.lastSackedTsn,this.advancedPeerAckTsn))this.advancedPeerAckTsn=this.lastSackedTsn;let X=0,G={};while(this.sentQueue.length>0&&this.sentQueue[0].abandoned){let Y=this.sentQueue.shift();if(this.advancedPeerAckTsn=Y.tsn,X++,!(Y.flags&tK))G[Y.streamId]=Y.streamSeqNum}if(!this.sentQueue.length)this.sentQueue=[];if(X)this.forwardTsnChunk=new dq(0,void 0),this.forwardTsnChunk.cumulativeTsn=this.advancedPeerAckTsn,this.forwardTsnChunk.streams=Object.entries(G).map(([Y,J])=>[Number(Y),J])}maybeAbandon(X){if(X.abandoned)return!0;if(!(!!X.maxRetransmits&&X.maxRetransmits<X.sentCount||!!X.expiry&&X.expiry<Date.now()/1000))return!1;let Y=this.sentQueue.findIndex((J)=>J.type===X.type);for(let J=Y;J>=0;J--){let Z=this.sentQueue[J];if(Z.abandoned=!0,Z.retransmit=!1,Z.flags&pV)break}for(let J=Y;J<this.sentQueue.length;J++){let Z=this.sentQueue[J];if(Z.abandoned=!0,Z.retransmit=!1,Z.flags&pV)break}return!0}static getCapabilities(){return new vr(65536)}setRemotePort(X){this.remotePort=X}async start(X){if(!this.started){if(this.started=!0,this.setConnectionState("connecting"),X)this.setRemotePort(X);if(!this.isServer)await this.init()}}async init(){let X=new lq;X.initiateTag=this.localVerificationTag,X.advertisedRwnd=this.advertisedRwnd,X.outboundStreams=this._outboundStreamsCount,X.inboundStreams=this._inboundStreamsMax,X.initialTsn=this.localTsn,this.setExtensions(X.params),e1("send init",X);try{await this.sendChunk(X),this.timer1Start(X),this.setState(2)}catch(G){e1("send init failed",G.message)}}setExtensions(X){let G=[];if(this.localPartialReliability)X.push([w2,Buffer.from("")]),G.push(dq.type);G.push(Or.type),X.push([I2,Buffer.from(G)])}async sendChunk(X){if(this.state==="closed")return;if(this.remotePort===void 0)throw Error("invalid remote port");let G=Mr(this.localPort,this.remotePort,this.remoteVerificationTag,X);await this.transport.send(G)}setState(X){if(X!=this.associationState)this.associationState=X;if(X===4)this.isStopping=!1,this.isClosed=!1,this.setConnectionState("connected"),this.heartbeatStart();else if(X===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(X){this.state=X,e1("setConnectionState",X),this.stateChanged[X].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 X=new nK;await this.sendChunk(X).catch((G)=>{e1("send abort failed",G.message)})}removeAllListeners(){Object.values(this.stateChanged).forEach((X)=>X.allUnsubscribe())}},yr=class{reassembly=[];streamSequenceNumber=0;constructor(){}addChunk(W){if(this.reassembly.length===0||c4(W.tsn,this.reassembly[this.reassembly.length-1].tsn)){this.reassembly.push(W);return}for(let[X,G]of Pr(this.reassembly)){if(G.tsn===W.tsn)throw Error("duplicate chunk in reassembly");if(c4(G.tsn,W.tsn)){this.reassembly.splice(X,0,W);break}}}*popMessages(){let W=0,X,G,Y;while(W<this.reassembly.length){let J=this.reassembly[W];if(X===void 0){if(Y=!(J.flags&tK),!(J.flags&Ax))if(Y)break;else{W++;continue}if(Y&&k2(J.streamSeqNum,this.streamSequenceNumber))break;G=J.tsn,X=W}else if(J.tsn!==G)if(Y)break;else{X=void 0,W++;continue}if(J.flags&pV){let Z=this.reassembly.slice(X,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,X),...this.reassembly.slice(W+1)],Y&&J.streamSeqNum===this.streamSequenceNumber)this.streamSequenceNumber=R9(this.streamSequenceNumber,1);W=X,yield[J.streamId,J.protocol,V]}else W++;G=gY(G)}}pruneChunks(W){let X=-1,G=0;for(let[Y,J]of this.reassembly.entries())if(fV(W,J.tsn))X=Y,G+=J.userData.length;else break;return this.reassembly=this.reassembly.slice(X+1),G}},vr=class{constructor(W){this.maxMessageSize=W}};function DX(W){return(W-1)%qH}function gY(W){return(W+1)%qH}var kY=P1("werift:packages/webrtc/src/transport/sctp.ts"),cV=65536,gr=class W{constructor(X=5000,G=cV){this.port=X,this.maxMessageSize=G}dtlsTransport;sctp;onDataChannel=new d0;id=jr().toString();mid;mLineIndex;bundled=!1;dataChannels={};remoteMaxMessageSize=cV;dataChannelQueue=[];dataChannelId;eventDisposer=[];setDtlsTransport(X){if(this.dtlsTransport&&this.dtlsTransport.id===X.id)return;this.eventDisposer.forEach((G)=>G()),this.dtlsTransport=X,this.sctp=new _r(new ur(this.dtlsTransport),this.port),this.eventDisposer=[...[this.sctp.onReceive.subscribe(this.datachannelReceive),this.sctp.onReconfigStreams.subscribe((G)=>{G.forEach((Y)=>{let J=this.dataChannels[Y];if(!J)return;J.setReadyState("closing"),J.setReadyState("closed"),delete this.dataChannels[Y]})}),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(X){return Object.values(this.dataChannels).find((G)=>G.label===X)}datachannelReceive=async(X,G,Y)=>{if(G===_q&&Y.length>0)switch(kY("DCEP",X,G,Y),Y[0]){case rF:{if(Y.length<12){kY("DATA_CHANNEL_OPEN data.length not enough");return}if(!Object.keys(this.dataChannels).includes(X.toString())){let[,Z,,V,U,Q]=X8.Unpack("!BBHLHH",Y),N=12,q=Y.slice(N,N+U).toString("utf8");N+=U;let A=Y.slice(N,N+Q).toString("utf8");kY("DATA_CHANNEL_OPEN",{channelType:Z,reliability:V,streamId:X,label:q,protocol:A});let H=(Z&3)===1?V:void 0,I=(Z&3)===2?V:void 0,w=new mS({label:q,ordered:(Z&128)===0,maxPacketLifeTime:I,maxRetransmits:H,protocol:A,id:X}),O=new bS(this,w,!1);O.isCreatedByRemote=!0,this.dataChannels[X]=O,this.onDataChannel.execute(O),O.setReadyState("open")}else kY("datachannel already opened","retransmit ack");let J=this.dataChannels[X];this.dataChannelQueue.push([J,_q,Buffer.from(X8.Pack("!B",[iF]))]),await this.dataChannelFlush()}break;case iF:{kY("DATA_CHANNEL_ACK",X,G);let J=this.dataChannels[X];if(!J)throw Error("channel not found");J.setReadyState("open")}break}else{let J=this.dataChannels[X];if(J){let Z=(()=>{switch(G){case aF:return Y.toString("utf8");case _i:return"";case sF:return Y;case yi:return Buffer.from([]);default:throw Error()}})();if(J.messagesReceived++,J.bytesReceived+=Y.length,J.onMessage.execute(Z),J.emit("message",{data:Z}),J.onmessage)J.onmessage({data:Z})}}};dataChannelAddNegotiated(X){if(X.id==null)throw Error();if(this.dataChannels[X.id])throw Error();if(this.dataChannels[X.id]=X,this.sctp.associationState===4)X.setReadyState("open")}dataChannelOpen(X){if(X.id){if(this.dataChannels[X.id])throw Error(`Data channel with ID ${X.id} already registered`);this.dataChannels[X.id]=X}let G=ki,Y=0,J=0;if(!X.ordered)G=128;if(X.maxRetransmits)G=1,J=X.maxRetransmits;else if(X.maxPacketLifeTime)G=2,J=X.maxPacketLifeTime;let Z=X8.Pack("!BBHLHH",[rF,G,Y,J,X.label.length,X.protocol.length]),V=Buffer.concat([Buffer.from(Z),Buffer.from(X.label,"utf8"),Buffer.from(X.protocol,"utf8")]);this.dataChannelQueue.push([X,_q,V]),this.dataChannelFlush()}async dataChannelFlush(){if(this.sctp.associationState!=4)return;while(this.dataChannelQueue.length>0){let[X,G,Y]=this.dataChannelQueue.shift(),J=X.id;if(J===void 0){J=this.dataChannelId;while(Object.keys(this.dataChannels).includes(J.toString()))J+=2;this.dataChannels[J]=X,X.setId(J)}if(G===_q)await this.sctp.send(J,G,Y,{ordered:!0});else{let Z=X.maxPacketLifeTime?Date.now()+X.maxPacketLifeTime/1000:void 0;await this.sctp.send(J,G,Y,{expiry:Z,maxRetransmits:X.maxRetransmits,ordered:X.ordered}),X.addBufferedAmount(-Y.length)}}this.dataChannelQueue=[]}assertSendableMessageSize(X){if(this.remoteMaxMessageSize!==0&&X>this.remoteMaxMessageSize)throw Error(`max-message-size exceeded: ${X} > ${this.remoteMaxMessageSize}`)}datachannelSend=(X,G)=>{let Y=Buffer.isBuffer(G)?G:Buffer.from(G),J=Ci(G);if(this.assertSendableMessageSize(J),X.addBufferedAmount(J),this.dataChannelQueue.push(typeof G==="string"?[X,aF,Y]:[X,sF,Y]),this.sctp.associationState!==4)kY("sctp not established",this.sctp.associationState);return this.dataChannelFlush(),J};getCapabilities(){return W.getCapabilities(this.maxMessageSize)}static getCapabilities(X=cV){return new zx(X)}setRemoteMaxMessageSize(X){this.remoteMaxMessageSize=X??cV}setRemotePort(X){this.sctp.setRemotePort(X)}async start(X){if(this.isServer)this.dataChannelId=0;else this.dataChannelId=1;this.sctp.isServer=this.isServer,await this.sctp.start(X)}async stop(){this.dtlsTransport.dataReceiver=()=>{},await this.sctp.stop()}dataChannelClose(X){if(!["closing","closed"].includes(X.readyState))if(X.setReadyState("closing"),this.sctp.associationState===4){if(!this.sctp.reconfigQueue.includes(X.id))this.sctp.reconfigQueue.push(X.id);if(this.sctp.reconfigQueue.length===1)this.sctp.transmitReconfigRequest()}else{if(this.dataChannelQueue=this.dataChannelQueue.filter((G)=>G[0].id!==X.id),this.sctp.reconfigQueue=this.sctp.reconfigQueue.filter((G)=>G!==X.id),X.id)delete this.dataChannels[X.id];X.setReadyState("closed")}}},zx=class{constructor(W){this.maxMessageSize=W}},ur=class{constructor(W){this.dtls=W}set onData(W){this.dtls.dataReceiver=W}send=(W)=>{return this.dtls.sendData(W)};close(){}},rq=class W{version=0;origin;name="-";time="0 0";host;group=[];extMapAllowMixed=!0;msidSemantic=[];media=[];type;dtlsRole;iceOptions;iceLite;icePassword;iceUsernameFragment;dtlsFingerprints=[];static parse(X){let[G,Y]=hr(X),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=DK(V.slice(2));else if(V.startsWith("t="))J.time=V.slice(2);else if(V.startsWith("a=")){let[U,Q]=CK(V);switch(U){case"fingerprint":{let[N,q]=Q?.split(" ")||[];J.dtlsFingerprints.push(new pK(N,q))}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":TK(J.group,Q);break;case"msid-semantic":TK(J.msidSemantic,Q);break;case"setup":J.dtlsRole=eF[Q];break;case"extmap-allow-mixed":J.extMapAllowMixed=!0;break}}});let Z=J.group.find((V)=>V.semantic==="BUNDLE");return Y.forEach((V)=>{let Q=V[0].match(/^m=([^ ]+) ([0-9]+) ([A-Z/]+) (.+)/);if(!Q)throw Error("m line not found");let N=Q[1],q=Q[4].split(" "),A=["audio","video"].includes(N)?q.map((w)=>Number(w)):void 0,H=new eK(N,Number.parseInt(Q[2]),Q[3],A||q);if(H.dtlsParams=new cK([...J.dtlsFingerprints],J.dtlsRole),H.iceParams=new Jx({iceLite:J.iceLite,usernameFragment:J.iceUsernameFragment,password:J.icePassword}),H.iceOptions=J.iceOptions,J.media.push(H),V.slice(1).forEach((w)=>{if(w.startsWith("c="))H.host=DK(w.slice(2));else if(w.startsWith("a=")){let[O,T]=CK(w);switch(O){case"candidate":if(!T)throw Error();H.iceCandidates.push(wx(T));break;case"end-of-candidates":H.iceCandidatesComplete=!0;break;case"extmap":{let[x,h]=T.split(" ");if(x.includes("/"))[x]=x.split("/");H.rtp.headerExtensions.push(new Mi({id:Number.parseInt(x),uri:h}))}break;case"fingerprint":{if(!T)throw Error();let[x,h]=T.split(" ");H.dtlsParams?.fingerprints.push(new pK(x,h))}break;case"ice-options":H.iceOptions=T;break;case"ice-pwd":H.iceParams.password=T;break;case"ice-ufrag":H.iceParams.usernameFragment=T;break;case"ice-lite":H.iceParams.iceLite=!0;break;case"max-message-size":H.sctpCapabilities=new zx(Number.parseInt(T,10));break;case"mid":H.rtp.muxId=T;break;case"msid":H.msid=T;break;case"rtcp":{let[x,h]=p4(T," ");H.rtcpPort=Number.parseInt(x),H.rtcpHost=DK(h)}break;case"rtcp-mux":H.rtcpMux=!0;break;case"setup":H.dtlsParams.role=eF[T];break;case"recvonly":case"sendonly":case"sendrecv":case"inactive":H.direction=O;break;case"rtpmap":{let[x,h]=p4(T," "),[$,F,u]=h.split("/"),l;if(H.kind==="audio")l=u?Number.parseInt(u):1;let p=new FX({mimeType:H.kind+"/"+$,channels:l,clockRate:Number.parseInt(F),payloadType:Number.parseInt(x)});H.rtp.codecs.push(p)}break;case"sctpmap":{if(!T)throw Error();let[x,h]=p4(T," ");H.sctpMap[Number.parseInt(x)]=h,H.sctpPort=Number.parseInt(x)}break;case"sctp-port":if(!T)throw Error();H.sctpPort=Number.parseInt(T);break;case"ssrc":{let[x,h]=p4(T," "),$=Number.parseInt(x),[F,u]=p4(h,":"),l=H.ssrc.find((p)=>p.ssrc===$);if(!l)l=new XO({ssrc:$}),H.ssrc.push(l);if(oS.includes(F))l[F]=u}break;case"ssrc-group":TK(H.ssrcGroup,T);break;case"rid":{let[x,h]=p4(T," ");H.simulcastParameters.push(new fS({rid:x,direction:h}))}break}}}),!H.iceParams.usernameFragment||!H.iceParams.password){if(H.rtp.muxId&&Z&&Z.items.includes(H.rtp.muxId))for(let w=0;w<Z.items.length;w++){if(!Z.items.includes(w.toString()))continue;let O=J.media[w];if(O.iceParams?.usernameFragment&&O.iceParams.password){H.iceParams={...O.iceParams};break}}}if(!H.dtlsParams.role)H.dtlsParams=void 0;let I=(w)=>H.rtp.codecs.find((O)=>O.payloadType===w);V.slice(1).forEach((w)=>{if(w.startsWith("a=")){let[O,T]=CK(w);if(O==="fmtp"){let[x,h]=p4(T," "),$=I(Number(x));$.parameters=h}else if(O==="rtcp-fb"){let[x,h,$]=T.split(" ");H.rtp.codecs.forEach((F)=>{if(["*",F.payloadType.toString()].includes(x))F.rtcpFeedback.push(new Pi({type:h,parameter:$}))})}}})}),J}webrtcTrackId(X){if(X.msid?.includes(" ")){let G=X.msid.split(" ");for(let Y of this.msidSemantic)if(Y.semantic==="WMS"&&(Y.items.includes(G[0])||Y.items.includes("*")))return G[1]}return}get string(){let X=[`v=${this.version}`,`o=${this.origin}`,`s=${this.name}`];if(this.host)X.push(`c=${WO(this.host)}`);if(X.push(`t=${this.time}`),this.group.forEach((J)=>X.push(`a=group:${J.str}`)),this.extMapAllowMixed)X.push("a=extmap-allow-mixed");this.msidSemantic.forEach((J)=>X.push(`a=msid-semantic:${J.str}`));let G=this.media.map((J)=>J.toString()).join("");return X.join(`\r
242
+ `)}}T9.CertificateTag="CERTIFICATE";T9.CrlTag="CRL";T9.CertificateRequestTag="CERTIFICATE REQUEST";T9.PublicKeyTag="PUBLIC KEY";T9.PrivateKeyTag="PRIVATE KEY";class M4 extends g6{static isAsnEncoded(W){return y0.isBufferSource(W)||typeof W==="string"}static toArrayBuffer(W){if(typeof W==="string")if(T9.isPem(W))return T9.decode(W)[0];else if(i0.isHex(W))return i0.FromHex(W);else if(i0.isBase64(W))return i0.FromBase64(W);else if(i0.isBase64Url(W))return i0.FromBase64Url(W);else throw TypeError("Unsupported format of 'raw' argument. Must be one of DER, PEM, HEX, Base64, or Base4Url");else{let X=y0.toUint8Array(W);if(X.length>0&&X[0]===48)return y0.toArrayBuffer(W);let G=i0.ToBinary(W);if(T9.isPem(G))return T9.decode(G)[0];else if(i0.isHex(G))return i0.FromHex(G);else if(i0.isBase64(G))return i0.FromBase64(G);else if(i0.isBase64Url(G))return i0.FromBase64Url(G);throw TypeError("Unsupported format of 'raw' argument. Must be one of DER, PEM, HEX, Base64, or Base4Url")}}constructor(...W){if(M4.isAsnEncoded(W[0]))super(M4.toArrayBuffer(W[0]),W[1]);else super(W[0])}toString(W="pem"){switch(W){case"pem":return T9.encode(this.rawData,this.tag);default:return super.toString(W)}}}class r5 extends M4{static async create(W,X=u8.get()){if(W instanceof r5)return W;else if(_6.isCryptoKey(W)){if(W.type!=="public")throw TypeError("Public key is required");let G=await X.subtle.exportKey("spki",W);return new r5(G)}else if(W.publicKey)return W.publicKey;else if(y0.isBufferSource(W))return new r5(W);else throw TypeError("Unsupported PublicKeyType")}constructor(W){if(M4.isAsnEncoded(W))super(W,O9);else super(W);this.tag=T9.PublicKeyTag}async export(...W){let X,G=["verify"],Y={hash:"SHA-256",...this.algorithm};if(W.length>1)Y=W[0]||Y,G=W[1]||G,X=W[2]||u8.get();else X=W[0]||u8.get();let J=this.rawData,Z=S0.parse(this.rawData,O9);if(Z.algorithm.algorithm===F6)J=Lp(Z,J);return X.subtle.importKey("spki",J,Y,!0,G)}onInit(W){let X=H8.resolve(UX),G=this.algorithm=X.toWebAlgorithm(W.algorithm);switch(W.algorithm.algorithm){case x7:{let Y=S0.parse(W.subjectPublicKey,xZ),J=y0.toUint8Array(Y.modulus);G.publicExponent=y0.toUint8Array(Y.publicExponent),G.modulusLength=(!J[0]?J.slice(1):J).byteLength<<3;break}}}async getThumbprint(...W){var X;let G,Y="SHA-1";if(W.length>=1&&!((X=W[0])===null||X===void 0?void 0:X.subtle))Y=W[0]||Y,G=W[1]||u8.get();else G=W[0]||u8.get();return await G.subtle.digest(Y,this.rawData)}async getKeyIdentifier(...W){let X,G="SHA-1";if(W.length===1)if(typeof W[0]==="string")G=W[0],X=u8.get();else X=W[0];else if(W.length===2)G=W[0],X=W[1];else X=u8.get();let Y=S0.parse(this.rawData,O9);return await X.subtle.digest(G,Y.subjectPublicKey)}toTextObject(){let W=this.toTextObjectEmpty(),X=S0.parse(this.rawData,O9);switch(W.Algorithm=y6.serializeAlgorithm(X.algorithm),X.algorithm.algorithm){case rW:W["EC Point"]=X.subjectPublicKey;break;case x7:default:W["Raw Data"]=X.subjectPublicKey}return W}}function Lp(W,X){return W.algorithm=new L0({algorithm:x7,parameters:null}),X=S0.serialize(W),X}class qV extends Q5{static async create(W,X=!1,G=u8.get()){if("name"in W&&"serialNumber"in W)return new qV(W,X);let J=await(await r5.create(W,G)).getKeyIdentifier(G);return new qV(i0.ToHex(J),X)}constructor(...W){if(y0.isBufferSource(W[0]))super(W[0]);else if(typeof W[0]==="string"){let X=new z4({keyIdentifier:new gG(i0.FromHex(W[0]))});super(AN,W[1],S0.serialize(X))}else{let X=W[0],G=X.name instanceof v6?S0.parse(X.name.rawData,K8):X.name,Y=new z4({authorityCertIssuer:G,authorityCertSerialNumber:i0.FromHex(X.serialNumber)});super(AN,W[1],S0.serialize(Y))}}onInit(W){super.onInit(W);let X=S0.parse(W.extnValue,z4);if(X.keyIdentifier)this.keyId=i0.ToHex(X.keyIdentifier);if(X.authorityCertIssuer||X.authorityCertSerialNumber)this.certId={name:X.authorityCertIssuer||[],serialNumber:X.authorityCertSerialNumber?i0.ToHex(X.authorityCertSerialNumber):""}}toTextObject(){let W=this.toTextObjectWithoutValue(),X=S0.parse(this.value,z4);if(X.authorityCertIssuer)W["Authority Issuer"]=new v6(X.authorityCertIssuer).toTextObject();if(X.authorityCertSerialNumber)W["Authority Serial Number"]=X.authorityCertSerialNumber;if(X.keyIdentifier)W[""]=X.keyIdentifier;return W}}qV.NAME="Authority Key Identifier";class Uj extends Q5{constructor(...W){if(y0.isBufferSource(W[0])){super(W[0]);let X=S0.parse(this.value,uG);this.ca=X.cA,this.pathLength=X.pathLenConstraint}else{let X=new uG({cA:W[0],pathLenConstraint:W[1]});super(zN,W[2],S0.serialize(X));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}}Uj.NAME="Basic Constraints";var y3;(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"})(y3||(y3={}));class Qj extends Q5{constructor(...W){if(y0.isBufferSource(W[0])){super(W[0]);let X=S0.parse(this.value,XZ);this.usages=X.map((G)=>G)}else{let X=new XZ(W[0]);super(TN,W[1],S0.serialize(X));this.usages=W[0]}}toTextObject(){let W=this.toTextObjectWithoutValue();return W[""]=this.usages.map((X)=>P4.toString(X)).join(", "),W}}Qj.NAME="Extended Key Usages";var v3;(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"})(v3||(v3={}));class Nj extends Q5{constructor(...W){if(y0.isBufferSource(W[0])){super(W[0]);let X=S0.parse(this.value,YZ);this.usages=X.toNumber()}else{let X=new YZ(W[0]);super(MN,W[1],S0.serialize(X));this.usages=W[0]}}toTextObject(){let W=this.toTextObjectWithoutValue(),X=S0.parse(this.value,YZ);return W[""]=X.toJSON().join(", "),W}}Nj.NAME="Key Usages";class Xq extends Q5{static async create(W,X=!1,G=u8.get()){let J=await(await r5.create(W,G)).getKeyIdentifier(G);return new Xq(i0.ToHex(J),X)}constructor(...W){if(y0.isBufferSource(W[0])){super(W[0]);let X=S0.parse(this.value,J5);this.keyId=i0.ToHex(X)}else{let X=typeof W[0]==="string"?i0.FromHex(W[0]):W[0],G=new J5(X);super(pI,W[1],S0.serialize(G));this.keyId=i0.ToHex(X)}}toTextObject(){let W=this.toTextObjectWithoutValue(),X=S0.parse(this.value,J5);return W[""]=X,W}}Xq.NAME="Subject Key Identifier";class qj extends Q5{constructor(...W){if(y0.isBufferSource(W[0]))super(W[0]);else super(mI,W[1],new v6(W[0]||[]).rawData)}onInit(W){super.onInit(W);let X=S0.parse(W.extnValue,LN);this.names=new v6(X)}toTextObject(){let W=this.toTextObjectWithoutValue(),X=this.names.toTextObject();for(let G in X)W[G]=X[G];return W}}qj.NAME="Subject Alternative Name";class i9{static register(W,X){this.items.set(W,X)}static create(W){let X=new Q5(W),G=this.items.get(X.type);if(G)return new G(W);return X}}i9.items=new Map;class Hj extends Q5{constructor(...W){var X;if(y0.isBufferSource(W[0])){super(W[0]);let G=S0.parse(this.value,sJ);this.policies=G.map((Y)=>Y.policyIdentifier)}else{let G=W[0],Y=(X=W[1])!==null&&X!==void 0?X:!1,J=new sJ(G.map((Z)=>new hG({policyIdentifier:Z})));super(wN,Y,S0.serialize(J));this.policies=G}}toTextObject(){let W=this.toTextObjectWithoutValue();return W.Policy=this.policies.map((X)=>new a1("",{},P4.toString(X))),W}}Hj.NAME="Certificate Policies";i9.register(wN,Hj);class Aj extends Q5{constructor(...W){var X;if(y0.isBufferSource(W[0]))super(W[0]);else if(Array.isArray(W[0])&&typeof W[0][0]==="string"){let Y=W[0].map((Z)=>{return new j4({distributionPoint:new w4({fullName:[new U1({uniformResourceIdentifier:Z})]})})}),J=new L6(Y);super(DN,W[1],S0.serialize(J))}else{let G=new L6(W[0]);super(DN,W[1],S0.serialize(G))}(X=this.distributionPoints)!==null&&X!==void 0||(this.distributionPoints=[])}onInit(W){super.onInit(W);let X=S0.parse(W.extnValue,L6);this.distributionPoints=X}toTextObject(){let W=this.toTextObjectWithoutValue();return W["Distribution Point"]=this.distributionPoints.map((X)=>{var G;let Y={};if(X.distributionPoint)Y[""]=(G=X.distributionPoint.fullName)===null||G===void 0?void 0:G.map((J)=>new T4(J).toString()).join(", ");if(X.reasons)Y.Reasons=X.reasons.toString();if(X.cRLIssuer)Y["CRL Issuer"]=X.cRLIssuer.map((J)=>J.toString()).join(", ");return Y}),W}}Aj.NAME="CRL Distribution Points";class zj extends Q5{constructor(...W){var X,G,Y,J;if(y0.isBufferSource(W[0]))super(W[0]);else if(W[0]instanceof gW){let Z=new gW(W[0]);super(HN,W[1],S0.serialize(Z))}else{let Z=W[0],V=new gW;tN(V,Z,TI,"ocsp"),tN(V,Z,MI,"caIssuers"),tN(V,Z,PI,"timeStamping"),tN(V,Z,RI,"caRepository");super(HN,W[1],S0.serialize(V))}(X=this.ocsp)!==null&&X!==void 0||(this.ocsp=[]),(G=this.caIssuers)!==null&&G!==void 0||(this.caIssuers=[]),(Y=this.timeStamping)!==null&&Y!==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=[],S0.parse(W.extnValue,gW).forEach((G)=>{switch(G.accessMethod){case TI:this.ocsp.push(new T4(G.accessLocation));break;case MI:this.caIssuers.push(new T4(G.accessLocation));break;case PI:this.timeStamping.push(new T4(G.accessLocation));break;case RI:this.caRepository.push(new T4(G.accessLocation));break}})}toTextObject(){let W=this.toTextObjectWithoutValue();if(this.ocsp.length)sN(W,"OCSP",this.ocsp);if(this.caIssuers.length)sN(W,"CA Issuers",this.caIssuers);if(this.timeStamping.length)sN(W,"Time Stamping",this.timeStamping);if(this.caRepository.length)sN(W,"CA Repository",this.caRepository);return W}}zj.NAME="Authority Info Access";function sN(W,X,G){if(G.length===1)W[X]=G[0].toTextObject();else{let Y=new a1("");G.forEach((J,Z)=>{let V=J.toTextObject(),U=`${V[a1.NAME]} ${Z+1}`,Q=Y[U];if(!Array.isArray(Q))Q=[],Y[U]=Q;Q.push(V)}),W[X]=Y}}function tN(W,X,G,Y){let J=X[Y];if(J)(Array.isArray(J)?J:[J]).forEach((V)=>{if(typeof V==="string")V=new T4("url",V);W.push(new R6({accessMethod:G,accessLocation:S0.parse(V.rawData,U1)}))})}class Ij extends Q5{constructor(...W){if(y0.isBufferSource(W[0]))super(W[0]);else super(yI,W[1],new v6(W[0]||[]).rawData)}onInit(W){super.onInit(W);let X=S0.parse(W.extnValue,K8);this.names=new v6(X)}toTextObject(){let W=this.toTextObjectWithoutValue(),X=this.names.toTextObject();for(let G in X)W[G]=X[G];return W}}Ij.NAME="Issuer Alternative Name";class zY extends g6{constructor(...W){let X;if(y0.isBufferSource(W[0]))X=y0.toArrayBuffer(W[0]);else{let G=W[0],Y=Array.isArray(W[1])?W[1].map((J)=>y0.toArrayBuffer(J)):[];X=S0.serialize(new K9({type:G,values:Y}))}super(X,K9)}onInit(W){this.type=W.type,this.values=W.values}toTextObject(){let W=this.toTextObjectWithoutValue();return W.Value=this.values.map((X)=>new a1("",{"":X})),W}toTextObjectWithoutValue(){let W=this.toTextObjectEmpty();if(W[a1.NAME]===zY.NAME)W[a1.NAME]=P4.toString(this.type);return W}}zY.NAME="Attribute";class wj extends zY{constructor(...W){var X;if(y0.isBufferSource(W[0]))super(W[0]);else{let G=new hZ({printableString:W[0]});super(ow,[S0.serialize(G)])}(X=this.password)!==null&&X!==void 0||(this.password="")}onInit(W){if(super.onInit(W),this.values[0]){let X=S0.parse(this.values[0],hZ);this.password=X.toString()}}toTextObject(){let W=this.toTextObjectWithoutValue();return W[a1.VALUE]=this.password,W}}wj.NAME="Challenge Password";class Gq extends zY{constructor(...W){var X;if(y0.isBufferSource(W[0]))super(W[0]);else{let G=W[0],Y=new Z5;for(let J of G)Y.push(S0.parse(J.rawData,D9));super(mZ,[S0.serialize(Y)])}(X=this.items)!==null&&X!==void 0||(this.items=[])}onInit(W){if(super.onInit(W),this.values[0]){let X=S0.parse(this.values[0],Z5);this.items=X.map((G)=>i9.create(S0.serialize(G)))}}toTextObject(){let W=this.toTextObjectWithoutValue(),X=this.items.map((G)=>G.toTextObject());for(let G of X)W[G[a1.NAME]]=G;return W}}Gq.NAME="Extensions";class AV{static register(W,X){this.items.set(W,X)}static create(W){let X=new zY(W),G=this.items.get(X.type);if(G)return new G(W);return X}}AV.items=new Map;var zV="crypto.signatureFormatter";class d3{toAsnSignature(W,X){return y0.toArrayBuffer(X)}toWebSignature(W,X){return y0.toArrayBuffer(X)}}var Wq,Yj=Wq=class{static createPssParams(X,G){let Y=Wq.getHashAlgorithm(X);if(!Y)return null;return new D4({hashAlgorithm:Y,maskGenAlgorithm:new L0({algorithm:S6,parameters:S0.serialize(Y)}),saltLength:G})}static getHashAlgorithm(X){let G=H8.resolve(UX);if(typeof X==="string")return G.toAsnAlgorithm({name:X});if(typeof X==="object"&&X&&"name"in X)return G.toAsnAlgorithm(X);return null}toAsnAlgorithm(X){switch(X.name.toLowerCase()){case"rsassa-pkcs1-v1_5":if("hash"in X){let G;if(typeof X.hash==="string")G=X.hash;else if(X.hash&&typeof X.hash==="object"&&"name"in X.hash&&typeof X.hash.name==="string")G=X.hash.name.toUpperCase();else throw Error("Cannot get hash algorithm name");switch(G.toLowerCase()){case"sha-1":return new L0({algorithm:WY,parameters:null});case"sha-256":return new L0({algorithm:bN,parameters:null});case"sha-384":return new L0({algorithm:XY,parameters:null});case"sha-512":return new L0({algorithm:GY,parameters:null})}}else return new L0({algorithm:x7,parameters:null});break;case"rsa-pss":if("hash"in X){if(!(("saltLength"in X)&&typeof X.saltLength==="number"))throw Error("Cannot get 'saltLength' from 'alg' argument");let G=Wq.createPssParams(X.hash,X.saltLength);if(!G)throw Error("Cannot create PSS parameters");return new L0({algorithm:F6,parameters:S0.serialize(G)})}else return new L0({algorithm:F6,parameters:null})}return null}toWebAlgorithm(X){switch(X.algorithm){case x7:return{name:"RSASSA-PKCS1-v1_5"};case WY:return{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-1"}};case bN:return{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}};case XY:return{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-384"}};case GY:return{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-512"}};case F6:if(X.parameters){let G=S0.parse(X.parameters,D4);return{name:"RSA-PSS",hash:H8.resolve(UX).toWebAlgorithm(G.hashAlgorithm),saltLength:G.saltLength}}else return{name:"RSA-PSS"}}return null}};Yj=Wq=j([k6()],Yj);H8.registerSingleton(HV,Yj);var Jj=class{toAsnAlgorithm(X){switch(X.name.toLowerCase()){case"sha-1":return new L0({algorithm:aW});case"sha-256":return new L0({algorithm:sW});case"sha-384":return new L0({algorithm:tW});case"sha-512":return new L0({algorithm:eW})}return null}toWebAlgorithm(X){switch(X.algorithm){case aW:return{name:"SHA-1"};case sW:return{name:"SHA-256"};case tW:return{name:"SHA-384"};case eW:return{name:"SHA-512"}}return null}};Jj=j([k6()],Jj);H8.registerSingleton(HV,Jj);class B5{addPadding(W,X){let G=y0.toUint8Array(X),Y=new Uint8Array(W);return Y.set(G,W-G.length),Y.buffer}removePadding(W,X=!1){let G=y0.toUint8Array(W);for(let Y=0;Y<G.length;Y++){if(!G[Y])continue;G=G.slice(Y);break}if(X&&G[0]>127){let Y=new Uint8Array(G.length+1);return Y.set(G,1),Y.buffer}return G.buffer}toAsnSignature(W,X){if(W.name==="ECDSA"){let G=W.namedCurve,Y=B5.namedCurveSize.get(G)||B5.defaultNamedCurveSize,J=new eG,Z=y0.toUint8Array(X);return J.r=this.removePadding(Z.slice(0,Y),!0),J.s=this.removePadding(Z.slice(Y,Y+Y),!0),S0.serialize(J)}return null}toWebSignature(W,X){if(W.name==="ECDSA"){let G=S0.parse(X,eG),Y=W.namedCurve,J=B5.namedCurveSize.get(Y)||B5.defaultNamedCurveSize,Z=this.addPadding(J,this.removePadding(G.r)),V=this.addPadding(J,this.removePadding(G.s));return cM(Z,V)}return null}}B5.namedCurveSize=new Map;B5.defaultNamedCurveSize=32;var Xj="1.3.101.110",g3="1.3.101.111",Gj="1.3.101.112",u3="1.3.101.113",Zj=class{toAsnAlgorithm(X){let G=null;switch(X.name.toLowerCase()){case"ed25519":G=Gj;break;case"x25519":G=Xj;break;case"eddsa":switch(X.namedCurve.toLowerCase()){case"ed25519":G=Gj;break;case"ed448":G=u3;break}break;case"ecdh-es":switch(X.namedCurve.toLowerCase()){case"x25519":G=Xj;break;case"x448":G=g3;break}}if(G)return new L0({algorithm:G});return null}toWebAlgorithm(X){switch(X.algorithm){case Gj:return{name:"Ed25519"};case u3:return{name:"EdDSA",namedCurve:"Ed448"};case Xj:return{name:"X25519"};case g3:return{name:"ECDH-ES",namedCurve:"X448"}}return null}};Zj=j([k6()],Zj);H8.registerSingleton(HV,Zj);var cZ,lZ,dZ,oZ,nZ,iZ,rZ,qY;class o3 extends M4{get subjectName(){if(!M1(this,lZ,"f"))j8(this,lZ,new i5(this.asn.certificationRequestInfo.subject),"f");return M1(this,lZ,"f")}get subject(){if(!M1(this,dZ,"f"))j8(this,dZ,this.subjectName.toString(),"f");return M1(this,dZ,"f")}get signatureAlgorithm(){if(!M1(this,oZ,"f")){let W=H8.resolve(UX);j8(this,oZ,W.toWebAlgorithm(this.asn.signatureAlgorithm),"f")}return M1(this,oZ,"f")}get signature(){if(!M1(this,nZ,"f"))j8(this,nZ,this.asn.signature,"f");return M1(this,nZ,"f")}get publicKey(){if(!M1(this,iZ,"f"))j8(this,iZ,new r5(this.asn.certificationRequestInfo.subjectPKInfo),"f");return M1(this,iZ,"f")}get attributes(){if(!M1(this,rZ,"f"))j8(this,rZ,this.asn.certificationRequestInfo.attributes.map((W)=>AV.create(S0.serialize(W))),"f");return M1(this,rZ,"f")}get extensions(){if(!M1(this,qY,"f")){j8(this,qY,[],"f");let W=this.getAttribute(mZ);if(W instanceof Gq)j8(this,qY,W.items,"f")}return M1(this,qY,"f")}get tbs(){if(!M1(this,cZ,"f"))j8(this,cZ,this.asn.certificationRequestInfoRaw||S0.serialize(this.asn.certificationRequestInfo),"f");return M1(this,cZ,"f")}constructor(W){let X=M4.isAsnEncoded(W)?[W,VX]:[W];super(X[0],X[1]);cZ.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),rZ.set(this,void 0),qY.set(this,void 0),this.tag=T9.CertificateRequestTag}onInit(W){}getAttribute(W){for(let X of this.attributes)if(X.type===W)return X;return null}getAttributes(W){return this.attributes.filter((X)=>X.type===W)}getExtension(W){for(let X of this.extensions)if(X.type===W)return X;return null}getExtensions(W){return this.extensions.filter((X)=>X.type===W)}async verify(W=u8.get()){let X={...this.publicKey.algorithm,...this.signatureAlgorithm},G=await this.publicKey.export(X,["verify"],W),Y=H8.resolveAll(zV).reverse(),J=null;for(let V of Y)if(J=V.toWebSignature(X,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(),X=S0.parse(this.rawData,VX),G=X.certificationRequestInfo,Y=new a1("",{Version:`${B7[G.version]} (${G.version})`,Subject:this.subject,"Subject Public Key Info":this.publicKey});if(this.attributes.length){let J=new a1("");for(let Z of this.attributes){let V=Z.toTextObject();J[V[a1.NAME]]=V}Y.Attributes=J}return W.Data=Y,W.Signature=new a1("",{Algorithm:y6.serializeAlgorithm(X.signatureAlgorithm),"":X.signature}),W}}cZ=new WeakMap,lZ=new WeakMap,dZ=new WeakMap,oZ=new WeakMap,nZ=new WeakMap,iZ=new WeakMap,rZ=new WeakMap,qY=new WeakMap;o3.NAME="PKCS#10 Certificate Request";var aZ,sZ,tZ,eZ,WV,XV,GV,YV,JV,ZV,HY,VV;class jj extends M4{get publicKey(){if(!M1(this,VV,"f"))j8(this,VV,new r5(this.asn.tbsCertificate.subjectPublicKeyInfo),"f");return M1(this,VV,"f")}get serialNumber(){if(!M1(this,sZ,"f")){let W=this.asn.tbsCertificate,X=new Uint8Array(W.serialNumber);if(X.length>1&&X[0]===0&&X[1]>127)X=X.slice(1);j8(this,sZ,i0.ToHex(X),"f")}return M1(this,sZ,"f")}get subjectName(){if(!M1(this,tZ,"f"))j8(this,tZ,new i5(this.asn.tbsCertificate.subject),"f");return M1(this,tZ,"f")}get subject(){if(!M1(this,eZ,"f"))j8(this,eZ,this.subjectName.toString(),"f");return M1(this,eZ,"f")}get issuerName(){if(!M1(this,WV,"f"))j8(this,WV,new i5(this.asn.tbsCertificate.issuer),"f");return M1(this,WV,"f")}get issuer(){if(!M1(this,XV,"f"))j8(this,XV,this.issuerName.toString(),"f");return M1(this,XV,"f")}get notBefore(){if(!M1(this,GV,"f")){let W=this.asn.tbsCertificate.validity.notBefore.utcTime||this.asn.tbsCertificate.validity.notBefore.generalTime;if(!W)throw Error("Cannot get 'notBefore' value");j8(this,GV,W,"f")}return M1(this,GV,"f")}get notAfter(){if(!M1(this,YV,"f")){let W=this.asn.tbsCertificate.validity.notAfter.utcTime||this.asn.tbsCertificate.validity.notAfter.generalTime;if(!W)throw Error("Cannot get 'notAfter' value");j8(this,YV,W,"f")}return M1(this,YV,"f")}get signatureAlgorithm(){if(!M1(this,JV,"f")){let W=H8.resolve(UX);j8(this,JV,W.toWebAlgorithm(this.asn.signatureAlgorithm),"f")}return M1(this,JV,"f")}get signature(){if(!M1(this,ZV,"f"))j8(this,ZV,this.asn.signatureValue,"f");return M1(this,ZV,"f")}get extensions(){if(!M1(this,HY,"f")){if(j8(this,HY,[],"f"),this.asn.tbsCertificate.extensions)j8(this,HY,this.asn.tbsCertificate.extensions.map((W)=>i9.create(S0.serialize(W))),"f")}return M1(this,HY,"f")}get tbs(){if(!M1(this,aZ,"f"))j8(this,aZ,this.asn.tbsCertificateRaw||S0.serialize(this.asn.tbsCertificate),"f");return M1(this,aZ,"f")}constructor(W){let X=M4.isAsnEncoded(W)?[W,c5]:[W];super(X[0],X[1]);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),XV.set(this,void 0),GV.set(this,void 0),YV.set(this,void 0),JV.set(this,void 0),ZV.set(this,void 0),HY.set(this,void 0),VV.set(this,void 0),this.tag=T9.CertificateTag}onInit(W){}getExtension(W){for(let X of this.extensions)if(typeof W==="string"){if(X.type===W)return X}else if(X instanceof W)return X;return null}getExtensions(W){return this.extensions.filter((X)=>{if(typeof W==="string")return X.type===W;else return X instanceof W})}async verify(W={},X=u8.get()){let G,Y,J=W.publicKey;try{if(!J)G={...this.publicKey.algorithm,...this.signatureAlgorithm},Y=await this.publicKey.export(G,["verify"],X);else if("publicKey"in J)G={...J.publicKey.algorithm,...this.signatureAlgorithm},Y=await J.publicKey.export(G,["verify"],X);else if(J instanceof r5)G={...J.algorithm,...this.signatureAlgorithm},Y=await J.export(G,["verify"],X);else if(y0.isBufferSource(J)){let Q=new r5(J);G={...Q.algorithm,...this.signatureAlgorithm},Y=await Q.export(G,["verify"],X)}else G={...J.algorithm,...this.signatureAlgorithm},Y=J}catch{return!1}let Z=H8.resolveAll(zV).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 X.subtle.verify(this.signatureAlgorithm,Y,V,this.tbs);if(W.signatureOnly)return U;else{let N=(W.date||new Date).getTime();return U&&this.notBefore.getTime()<N&&N<this.notAfter.getTime()}}async getThumbprint(...W){let X,G="SHA-1";if(W[0])if(!W[0].subtle)G=W[0]||G,X=W[1];else X=W[0];return X!==null&&X!==void 0||(X=u8.get()),await X.subtle.digest(G,this.rawData)}async isSelfSigned(W=u8.get()){return this.subject===this.issuer&&await this.verify({signatureOnly:!0},W)}toTextObject(){let W=this.toTextObjectEmpty(),X=S0.parse(this.rawData,c5),G=X.tbsCertificate,Y=new a1("",{Version:`${B7[G.version]} (${G.version})`,"Serial Number":G.serialNumber,"Signature Algorithm":y6.serializeAlgorithm(G.signature),Issuer:this.issuer,Validity:new a1("",{"Not Before":G.validity.notBefore.getTime(),"Not After":G.validity.notAfter.getTime()}),Subject:this.subject,"Subject Public Key Info":this.publicKey});if(G.issuerUniqueID)Y["Issuer Unique ID"]=G.issuerUniqueID;if(G.subjectUniqueID)Y["Subject Unique ID"]=G.subjectUniqueID;if(this.extensions.length){let J=new a1("");for(let Z of this.extensions){let V=Z.toTextObject();J[V[a1.NAME]]=V}Y.Extensions=J}return W.Data=Y,W.Signature=new a1("",{Algorithm:y6.serializeAlgorithm(X.signatureAlgorithm),"":X.signatureValue}),W}}aZ=new WeakMap,sZ=new WeakMap,tZ=new WeakMap,eZ=new WeakMap,WV=new WeakMap,XV=new WeakMap,GV=new WeakMap,YV=new WeakMap,JV=new WeakMap,ZV=new WeakMap,HY=new WeakMap,VV=new WeakMap;jj.NAME="Certificate";function Bp(W,X=u8.get()){let G=y0.toUint8Array(i0.FromHex(W||"")),Y=G&&G.length&&G.some((Z)=>Z>0)?new Uint8Array(G):void 0;if(!Y)Y=X.getRandomValues(new Uint8Array(16));let J=0;while(J<Y.length-1&&Y[J]===0)J++;if(Y=Y.slice(J),Y[0]>127){let Z=new Uint8Array(Y.length+1);Z[0]=0,Z.set(Y,1),Y=Z}return Y.buffer}class Kj{static async createSelfSigned(W,X=u8.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},X)}static async create(W,X=u8.get()){var G;let Y;if(W.publicKey instanceof r5)Y=W.publicKey.rawData;else if("publicKey"in W.publicKey)Y=W.publicKey.publicKey.rawData;else if(y0.isBufferSource(W.publicKey))Y=W.publicKey;else Y=await X.subtle.exportKey("spki",W.publicKey);let J=Bp(W.serialNumber,X),Z=W.notBefore||new Date,V=W.notAfter||new Date(Z.getTime()+31536000000),U=new c5({tbsCertificate:new C9({version:B7.v3,serialNumber:J,validity:new B6({notBefore:Z,notAfter:V}),extensions:new Z5(((G=W.extensions)===null||G===void 0?void 0:G.map((O)=>S0.parse(O.rawData,D9)))||[]),subjectPublicKeyInfo:S0.parse(Y,O9)})});if(W.subject){let O=W.subject instanceof i5?W.subject:new i5(W.subject);U.tbsCertificate.subject=S0.parse(O.toArrayBuffer(),V8)}if(W.issuer){let O=W.issuer instanceof i5?W.issuer:new i5(W.issuer);U.tbsCertificate.issuer=S0.parse(O.toArrayBuffer(),V8)}let Q={hash:"SHA-256"},N="signingKey"in W?{...Q,...W.signingAlgorithm,...W.signingKey.algorithm}:{...Q,...W.signingAlgorithm},q=H8.resolve(UX);U.tbsCertificate.signature=U.signatureAlgorithm=q.toAsnAlgorithm(N);let A=S0.serialize(U.tbsCertificate),H="signingKey"in W?await X.subtle.sign(N,W.signingKey,A):W.signature,I=H8.resolveAll(zV).reverse(),w=null;for(let O of I)if(w=O.toAsnSignature(N,H),w)break;if(!w)throw Error("Cannot convert ASN.1 signature value to WebCrypto format");return U.signatureValue=w,new jj(S0.serialize(U))}}var Ep,$p,Fp,Sp,xp,h3;(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"})(h3||(h3={}));Ep=new WeakMap,$p=new WeakMap,Fp=new WeakMap,Sp=new WeakMap,xp=new WeakMap;var kp,_p,yp,vp,gp,up,hp;kp=new WeakMap,_p=new WeakMap,yp=new WeakMap,vp=new WeakMap,gp=new WeakMap,up=new WeakMap,hp=new WeakMap;i9.register(zN,Uj);i9.register(TN,Qj);i9.register(MN,Nj);i9.register(pI,Xq);i9.register(AN,qV);i9.register(mI,qj);i9.register(DN,Aj);i9.register(HN,zj);i9.register(yI,Ij);AV.register(ow,wj);AV.register(mZ,Gq);H8.registerSingleton(zV,d3);H8.registerSingleton(zV,B5);B5.namedCurveSize.set("P-256",32);B5.namedCurveSize.set("K-256",32);B5.namedCurveSize.set("P-384",48);B5.namedCurveSize.set("P-521",66);var hY=b1(D8(),1),b2=b1(D8(),1),m2=b1(yQ(),1);import{createHash as Yo,createHmac as Jo}from"crypto";import*as R4 from"crypto";var NX=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 qX(W){return W instanceof Uint8Array||ArrayBuffer.isView(W)&&W.constructor.name==="Uint8Array"}function CV(W){if(!Number.isSafeInteger(W)||W<0)throw Error("positive integer expected, got "+W)}function a5(W,...X){if(!qX(W))throw Error("Uint8Array expected");if(X.length>0&&!X.includes(W.length))throw Error("Uint8Array expected of length "+X+", got length="+W.length)}function qq(W){if(typeof W!=="function"||typeof W.create!=="function")throw Error("Hash should be wrapped by utils.createHasher");CV(W.outputLen),CV(W.blockLen)}function KY(W,X=!0){if(W.destroyed)throw Error("Hash instance has been destroyed");if(X&&W.finished)throw Error("Hash#digest() has already been called")}function LE(W,X){a5(W);let G=X.outputLen;if(W.length<G)throw Error("digestInto() expects output buffer of length at least "+G)}function B4(...W){for(let X=0;X<W.length;X++)W[X].fill(0)}function Hq(W){return new DataView(W.buffer,W.byteOffset,W.byteLength)}function s5(W,X){return W<<32-X|W>>>X}var BE=(()=>typeof Uint8Array.from([]).toHex==="function"&&typeof Uint8Array.fromHex==="function")(),zl=Array.from({length:256},(W,X)=>X.toString(16).padStart(2,"0"));function E4(W){if(a5(W),BE)return W.toHex();let X="";for(let G=0;G<W.length;G++)X+=zl[W[G]];return X}var L4={_0:48,_9:57,A:65,F:70,a:97,f:102};function RE(W){if(W>=L4._0&&W<=L4._9)return W-L4._0;if(W>=L4.A&&W<=L4.F)return W-(L4.A-10);if(W>=L4.a&&W<=L4.f)return W-(L4.a-10);return}function HX(W){if(typeof W!=="string")throw Error("hex string expected, got "+typeof W);if(BE)return Uint8Array.fromHex(W);let X=W.length,G=X/2;if(X%2)throw Error("hex string expected, got unpadded hex of length "+X);let Y=new Uint8Array(G);for(let J=0,Z=0;J<G;J++,Z+=2){let V=RE(W.charCodeAt(Z)),U=RE(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)}Y[J]=V*16+U}return Y}function Aq(W){if(typeof W!=="string")throw Error("string expected");return new Uint8Array(new TextEncoder().encode(W))}function TV(W){if(typeof W==="string")W=Aq(W);return a5(W),W}function a9(...W){let X=0;for(let Y=0;Y<W.length;Y++){let J=W[Y];a5(J),X+=J.length}let G=new Uint8Array(X);for(let Y=0,J=0;Y<W.length;Y++){let Z=W[Y];G.set(Z,J),J+=Z.length}return G}class MV{}function zq(W){let X=(Y)=>W().update(TV(Y)).digest(),G=W();return X.outputLen=G.outputLen,X.blockLen=G.blockLen,X.create=()=>W(),X}function AX(W=32){if(NX&&typeof NX.getRandomValues==="function")return NX.getRandomValues(new Uint8Array(W));if(NX&&typeof NX.randomBytes==="function")return Uint8Array.from(NX.randomBytes(W));throw Error("crypto.getRandomValues must be defined")}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */var Sj=BigInt(0),Fj=BigInt(1);function PV(W,X=""){if(typeof W!=="boolean"){let G=X&&`"${X}"`;throw Error(G+"expected boolean, got type="+typeof W)}return W}function p6(W,X,G=""){let Y=qX(W),J=W?.length,Z=X!==void 0;if(!Y||Z&&J!==X){let V=G&&`"${G}" `,U=Z?` of length ${X}`:"",Q=Y?`length=${J}`:`type=${typeof W}`;throw Error(V+"expected Uint8Array"+U+", got "+Q)}return W}function RV(W){let X=W.toString(16);return X.length&1?"0"+X:X}function EE(W){if(typeof W!=="string")throw Error("hex string expected, got "+typeof W);return W===""?Sj:BigInt("0x"+W)}function $4(W){return EE(E4(W))}function xj(W){return a5(W),EE(E4(Uint8Array.from(W).reverse()))}function OY(W,X){return HX(W.toString(16).padStart(X*2,"0"))}function kj(W,X){return OY(W,X).reverse()}function F8(W,X,G){let Y;if(typeof X==="string")try{Y=HX(X)}catch(Z){throw Error(W+" must be hex string or Uint8Array, cause: "+Z)}else if(qX(X))Y=Uint8Array.from(X);else throw Error(W+" must be hex string or Uint8Array");let J=Y.length;if(typeof G==="number"&&J!==G)throw Error(W+" of length "+G+" expected, got "+J);return Y}var $j=(W)=>typeof W==="bigint"&&Sj<=W;function LV(W,X,G){return $j(W)&&$j(X)&&$j(G)&&X<=W&&W<G}function $E(W,X,G,Y){if(!LV(X,G,Y))throw Error("expected valid "+W+": "+G+" <= n < "+Y+", got "+X)}function Iq(W){let X;for(X=0;W>Sj;W>>=Fj,X+=1);return X}var c6=(W)=>(Fj<<BigInt(W))-Fj;function FE(W,X,G){if(typeof W!=="number"||W<2)throw Error("hashLen must be a number");if(typeof X!=="number"||X<2)throw Error("qByteLen must be a number");if(typeof G!=="function")throw Error("hmacFn must be a function");let Y=(I)=>new Uint8Array(I),J=(I)=>Uint8Array.of(I),Z=Y(W),V=Y(W),U=0,Q=()=>{Z.fill(1),V.fill(0),U=0},N=(...I)=>G(V,Z,...I),q=(I=Y(0))=>{if(V=N(J(0),I),Z=N(),I.length===0)return;V=N(J(1),I),Z=N()},A=()=>{if(U++>=1000)throw Error("drbg: tried 1000 values");let I=0,w=[];while(I<X){Z=N();let O=Z.slice();w.push(O),I+=Z.length}return a9(...w)};return(I,w)=>{Q(),q(I);let O=void 0;while(!(O=w(A())))q();return Q(),O}}function BV(W,X,G={}){if(!W||typeof W!=="object")throw Error("expected valid options object");function Y(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(X).forEach(([J,Z])=>Y(J,Z,!1)),Object.entries(G).forEach(([J,Z])=>Y(J,Z,!0))}function _j(W){let X=new WeakMap;return(G,...Y)=>{let J=X.get(G);if(J!==void 0)return J;let Z=W(G,...Y);return X.set(G,Z),Z}}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */var u9=BigInt(0),M9=BigInt(1),zX=BigInt(2),kE=BigInt(3),_E=BigInt(4),yE=BigInt(5),Il=BigInt(7),vE=BigInt(8),wl=BigInt(9),gE=BigInt(16);function N5(W,X){let G=W%X;return G>=u9?G:X+G}function q5(W,X,G){let Y=W;while(X-- >u9)Y*=Y,Y%=G;return Y}function SE(W,X){if(W===u9)throw Error("invert: expected non-zero number");if(X<=u9)throw Error("invert: expected positive modulus, got "+X);let G=N5(W,X),Y=X,J=u9,Z=M9,V=M9,U=u9;while(G!==u9){let N=Y/G,q=Y%G,A=J-V*N,H=Z-U*N;Y=G,G=q,J=V,Z=U,V=A,U=H}if(Y!==M9)throw Error("invert: does not exist");return N5(J,X)}function yj(W,X,G){if(!W.eql(W.sqr(X),G))throw Error("Cannot find square root")}function uE(W,X){let G=(W.ORDER+M9)/_E,Y=W.pow(X,G);return yj(W,Y,X),Y}function jl(W,X){let G=(W.ORDER-yE)/vE,Y=W.mul(X,zX),J=W.pow(Y,G),Z=W.mul(X,J),V=W.mul(W.mul(Z,zX),J),U=W.mul(Z,W.sub(V,W.ONE));return yj(W,U,X),U}function Kl(W){let X=$5(W),G=hE(W),Y=G(X,X.neg(X.ONE)),J=G(X,Y),Z=G(X,X.neg(Y)),V=(W+Il)/gE;return(U,Q)=>{let N=U.pow(Q,V),q=U.mul(N,Y),A=U.mul(N,J),H=U.mul(N,Z),I=U.eql(U.sqr(q),Q),w=U.eql(U.sqr(A),Q);N=U.cmov(N,q,I),q=U.cmov(H,A,w);let O=U.eql(U.sqr(q),Q),T=U.cmov(N,q,O);return yj(U,T,Q),T}}function hE(W){if(W<kE)throw Error("sqrt is not defined for small field");let X=W-M9,G=0;while(X%zX===u9)X/=zX,G++;let Y=zX,J=$5(W);while(xE(J,Y)===1)if(Y++>1000)throw Error("Cannot find square root: probably non-prime P");if(G===1)return uE;let Z=J.pow(Y,X),V=(X+M9)/zX;return function(Q,N){if(Q.is0(N))return N;if(xE(Q,N)!==1)throw Error("Cannot find square root");let q=G,A=Q.mul(Q.ONE,Z),H=Q.pow(N,X),I=Q.pow(N,V);while(!Q.eql(H,Q.ONE)){if(Q.is0(H))return Q.ZERO;let w=1,O=Q.sqr(H);while(!Q.eql(O,Q.ONE))if(w++,O=Q.sqr(O),w===q)throw Error("Cannot find square root");let T=M9<<BigInt(q-w-1),x=Q.pow(A,T);q=w,A=Q.sqr(x),H=Q.mul(H,A),I=Q.mul(I,x)}return I}}function Ol(W){if(W%_E===kE)return uE;if(W%vE===yE)return jl;if(W%gE===wl)return Kl(W);return hE(W)}var Dl=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function vj(W){let X={ORDER:"bigint",MASK:"bigint",BYTES:"number",BITS:"number"},G=Dl.reduce((Y,J)=>{return Y[J]="function",Y},X);return BV(W,G),W}function Cl(W,X,G){if(G<u9)throw Error("invalid exponent, negatives unsupported");if(G===u9)return W.ONE;if(G===M9)return X;let Y=W.ONE,J=X;while(G>u9){if(G&M9)Y=W.mul(Y,J);J=W.sqr(J),G>>=M9}return Y}function wq(W,X,G=!1){let Y=Array(X.length).fill(G?W.ZERO:void 0),J=X.reduce((V,U,Q)=>{if(W.is0(U))return V;return Y[Q]=V,W.mul(V,U)},W.ONE),Z=W.inv(J);return X.reduceRight((V,U,Q)=>{if(W.is0(U))return V;return Y[Q]=W.mul(V,Y[Q]),W.mul(V,U)},Z),Y}function xE(W,X){let G=(W.ORDER-M9)/zX,Y=W.pow(X,G),J=W.eql(Y,W.ONE),Z=W.eql(Y,W.ZERO),V=W.eql(Y,W.neg(W.ONE));if(!J&&!Z&&!V)throw Error("invalid Legendre symbol result");return J?1:Z?0:-1}function jq(W,X){if(X!==void 0)CV(X);let G=X!==void 0?X:W.toString(2).length,Y=Math.ceil(G/8);return{nBitLength:G,nByteLength:Y}}function $5(W,X,G=!1,Y={}){if(W<=u9)throw Error("invalid field: expected ORDER > 0, got "+W);let J=void 0,Z=void 0,V=!1,U=void 0;if(typeof X==="object"&&X!=null){if(Y.sqrt||G)throw Error("cannot specify opts in two arguments");let H=X;if(H.BITS)J=H.BITS;if(H.sqrt)Z=H.sqrt;if(typeof H.isLE==="boolean")G=H.isLE;if(typeof H.modFromBytes==="boolean")V=H.modFromBytes;U=H.allowedLengths}else{if(typeof X==="number")J=X;if(Y.sqrt)Z=Y.sqrt}let{nBitLength:Q,nByteLength:N}=jq(W,J);if(N>2048)throw Error("invalid field: expected ORDER of <= 2048 bytes");let q,A=Object.freeze({ORDER:W,isLE:G,BITS:Q,BYTES:N,MASK:c6(Q),ZERO:u9,ONE:M9,allowedLengths:U,create:(H)=>N5(H,W),isValid:(H)=>{if(typeof H!=="bigint")throw Error("invalid field element: expected bigint, got "+typeof H);return u9<=H&&H<W},is0:(H)=>H===u9,isValidNot0:(H)=>!A.is0(H)&&A.isValid(H),isOdd:(H)=>(H&M9)===M9,neg:(H)=>N5(-H,W),eql:(H,I)=>H===I,sqr:(H)=>N5(H*H,W),add:(H,I)=>N5(H+I,W),sub:(H,I)=>N5(H-I,W),mul:(H,I)=>N5(H*I,W),pow:(H,I)=>Cl(A,H,I),div:(H,I)=>N5(H*SE(I,W),W),sqrN:(H)=>H*H,addN:(H,I)=>H+I,subN:(H,I)=>H-I,mulN:(H,I)=>H*I,inv:(H)=>SE(H,W),sqrt:Z||((H)=>{if(!q)q=Ol(W);return q(A,H)}),toBytes:(H)=>G?kj(H,N):OY(H,N),fromBytes:(H,I=!0)=>{if(U){if(!U.includes(H.length)||H.length>N)throw Error("Field.fromBytes: expected "+U+" bytes, got "+H.length);let O=new Uint8Array(N);O.set(H,G?0:O.length-H.length),H=O}if(H.length!==N)throw Error("Field.fromBytes: expected "+N+" bytes, got "+H.length);let w=G?xj(H):$4(H);if(V)w=N5(w,W);if(!I){if(!A.isValid(w))throw Error("invalid field element: outside of range 0..ORDER")}return w},invertBatch:(H)=>wq(A,H),cmov:(H,I,w)=>w?I:H});return Object.freeze(A)}function bE(W){if(typeof W!=="bigint")throw Error("field order must be bigint");let X=W.toString(2).length;return Math.ceil(X/8)}function gj(W){let X=bE(W);return X+Math.ceil(X/2)}function Kq(W,X,G=!1){let Y=W.length,J=bE(X),Z=gj(X);if(Y<16||Y<Z||Y>1024)throw Error("expected "+Z+"-1024 bytes of input, got "+Y);let V=G?xj(W):$4(W),U=N5(V,X-M9)+M9;return G?kj(U,J):OY(U,J)}function Tl(W,X,G,Y){if(typeof W.setBigUint64==="function")return W.setBigUint64(X,G,Y);let J=BigInt(32),Z=BigInt(4294967295),V=Number(G>>J&Z),U=Number(G&Z),Q=Y?4:0,N=Y?0:4;W.setUint32(X+Q,V,Y),W.setUint32(X+N,U,Y)}function mE(W,X,G){return W&X^~W&G}function fE(W,X,G){return W&X^W&G^X&G}class Oq extends MV{constructor(W,X,G,Y){super();this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=W,this.outputLen=X,this.padOffset=G,this.isLE=Y,this.buffer=new Uint8Array(W),this.view=Hq(this.buffer)}update(W){KY(this),W=TV(W),a5(W);let{view:X,buffer:G,blockLen:Y}=this,J=W.length;for(let Z=0;Z<J;){let V=Math.min(Y-this.pos,J-Z);if(V===Y){let U=Hq(W);for(;Y<=J-Z;Z+=Y)this.process(U,Z);continue}if(G.set(W.subarray(Z,Z+V),this.pos),this.pos+=V,Z+=V,this.pos===Y)this.process(X,0),this.pos=0}return this.length+=W.length,this.roundClean(),this}digestInto(W){KY(this),LE(W,this),this.finished=!0;let{buffer:X,view:G,blockLen:Y,isLE:J}=this,{pos:Z}=this;if(X[Z++]=128,B4(this.buffer.subarray(Z)),this.padOffset>Y-Z)this.process(G,0),Z=0;for(let q=Z;q<Y;q++)X[q]=0;Tl(G,Y-8,BigInt(this.length*8),J),this.process(G,0);let V=Hq(W),U=this.outputLen;if(U%4)throw Error("_sha2: outputLen should be aligned to 32bit");let Q=U/4,N=this.get();if(Q>N.length)throw Error("_sha2: outputLen bigger than state");for(let q=0;q<Q;q++)V.setUint32(4*q,N[q],J)}digest(){let{buffer:W,outputLen:X}=this;this.digestInto(W);let G=W.slice(0,X);return this.destroy(),G}_cloneInto(W){W||(W=new this.constructor),W.set(...this.get());let{blockLen:X,buffer:G,length:Y,finished:J,destroyed:Z,pos:V}=this;if(W.destroyed=Z,W.finished=J,W.length=Y,W.pos=V,Y%X)W.buffer.set(G);return W}clone(){return this._cloneInto()}}var F4=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var J9=Uint32Array.from([3418070365,3238371032,1654270250,914150663,2438529370,812702999,355462360,4144912697,1731405415,4290775857,2394180231,1750603025,3675008525,1694076839,1203062813,3204075428]),Z9=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var Dq=BigInt(4294967295),pE=BigInt(32);function Ml(W,X=!1){if(X)return{h:Number(W&Dq),l:Number(W>>pE&Dq)};return{h:Number(W>>pE&Dq)|0,l:Number(W&Dq)|0}}function cE(W,X=!1){let G=W.length,Y=new Uint32Array(G),J=new Uint32Array(G);for(let Z=0;Z<G;Z++){let{h:V,l:U}=Ml(W[Z],X);[Y[Z],J[Z]]=[V,U]}return[Y,J]}var uj=(W,X,G)=>W>>>G,hj=(W,X,G)=>W<<32-G|X>>>G,IX=(W,X,G)=>W>>>G|X<<32-G,wX=(W,X,G)=>W<<32-G|X>>>G,EV=(W,X,G)=>W<<64-G|X>>>G-32,$V=(W,X,G)=>W>>>G-32|X<<64-G;function y7(W,X,G,Y){let J=(X>>>0)+(Y>>>0);return{h:W+G+(J/4294967296|0)|0,l:J|0}}var lE=(W,X,G)=>(W>>>0)+(X>>>0)+(G>>>0),dE=(W,X,G,Y)=>X+G+Y+(W/4294967296|0)|0,oE=(W,X,G,Y)=>(W>>>0)+(X>>>0)+(G>>>0)+(Y>>>0),nE=(W,X,G,Y,J)=>X+G+Y+J+(W/4294967296|0)|0,iE=(W,X,G,Y,J)=>(W>>>0)+(X>>>0)+(G>>>0)+(Y>>>0)+(J>>>0),rE=(W,X,G,Y,J,Z)=>X+G+Y+J+Z+(W/4294967296|0)|0;var Rl=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]),l6=new Uint32Array(64);class aE extends Oq{constructor(W=32){super(64,W,8,!1);this.A=F4[0]|0,this.B=F4[1]|0,this.C=F4[2]|0,this.D=F4[3]|0,this.E=F4[4]|0,this.F=F4[5]|0,this.G=F4[6]|0,this.H=F4[7]|0}get(){let{A:W,B:X,C:G,D:Y,E:J,F:Z,G:V,H:U}=this;return[W,X,G,Y,J,Z,V,U]}set(W,X,G,Y,J,Z,V,U){this.A=W|0,this.B=X|0,this.C=G|0,this.D=Y|0,this.E=J|0,this.F=Z|0,this.G=V|0,this.H=U|0}process(W,X){for(let q=0;q<16;q++,X+=4)l6[q]=W.getUint32(X,!1);for(let q=16;q<64;q++){let A=l6[q-15],H=l6[q-2],I=s5(A,7)^s5(A,18)^A>>>3,w=s5(H,17)^s5(H,19)^H>>>10;l6[q]=w+l6[q-7]+I+l6[q-16]|0}let{A:G,B:Y,C:J,D:Z,E:V,F:U,G:Q,H:N}=this;for(let q=0;q<64;q++){let A=s5(V,6)^s5(V,11)^s5(V,25),H=N+A+mE(V,U,Q)+Rl[q]+l6[q]|0,w=(s5(G,2)^s5(G,13)^s5(G,22))+fE(G,Y,J)|0;N=Q,Q=U,U=V,V=Z+H|0,Z=J,J=Y,Y=G,G=H+w|0}G=G+this.A|0,Y=Y+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,N=N+this.H|0,this.set(G,Y,J,Z,V,U,Q,N)}roundClean(){B4(l6)}destroy(){this.set(0,0,0,0,0,0,0,0),B4(this.buffer)}}var sE=(()=>cE(["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))))(),Ll=(()=>sE[0])(),Bl=(()=>sE[1])(),d6=new Uint32Array(80),o6=new Uint32Array(80);class bj extends Oq{constructor(W=64){super(128,W,16,!1);this.Ah=Z9[0]|0,this.Al=Z9[1]|0,this.Bh=Z9[2]|0,this.Bl=Z9[3]|0,this.Ch=Z9[4]|0,this.Cl=Z9[5]|0,this.Dh=Z9[6]|0,this.Dl=Z9[7]|0,this.Eh=Z9[8]|0,this.El=Z9[9]|0,this.Fh=Z9[10]|0,this.Fl=Z9[11]|0,this.Gh=Z9[12]|0,this.Gl=Z9[13]|0,this.Hh=Z9[14]|0,this.Hl=Z9[15]|0}get(){let{Ah:W,Al:X,Bh:G,Bl:Y,Ch:J,Cl:Z,Dh:V,Dl:U,Eh:Q,El:N,Fh:q,Fl:A,Gh:H,Gl:I,Hh:w,Hl:O}=this;return[W,X,G,Y,J,Z,V,U,Q,N,q,A,H,I,w,O]}set(W,X,G,Y,J,Z,V,U,Q,N,q,A,H,I,w,O){this.Ah=W|0,this.Al=X|0,this.Bh=G|0,this.Bl=Y|0,this.Ch=J|0,this.Cl=Z|0,this.Dh=V|0,this.Dl=U|0,this.Eh=Q|0,this.El=N|0,this.Fh=q|0,this.Fl=A|0,this.Gh=H|0,this.Gl=I|0,this.Hh=w|0,this.Hl=O|0}process(W,X){for(let h=0;h<16;h++,X+=4)d6[h]=W.getUint32(X),o6[h]=W.getUint32(X+=4);for(let h=16;h<80;h++){let $=d6[h-15]|0,F=o6[h-15]|0,u=IX($,F,1)^IX($,F,8)^uj($,F,7),l=wX($,F,1)^wX($,F,8)^hj($,F,7),f=d6[h-2]|0,s=o6[h-2]|0,y=IX(f,s,19)^EV(f,s,61)^uj(f,s,6),t=wX(f,s,19)^$V(f,s,61)^hj(f,s,6),H0=oE(l,t,o6[h-7],o6[h-16]),g=nE(H0,u,y,d6[h-7],d6[h-16]);d6[h]=g|0,o6[h]=H0|0}let{Ah:G,Al:Y,Bh:J,Bl:Z,Ch:V,Cl:U,Dh:Q,Dl:N,Eh:q,El:A,Fh:H,Fl:I,Gh:w,Gl:O,Hh:T,Hl:x}=this;for(let h=0;h<80;h++){let $=IX(q,A,14)^IX(q,A,18)^EV(q,A,41),F=wX(q,A,14)^wX(q,A,18)^$V(q,A,41),u=q&H^~q&w,l=A&I^~A&O,f=iE(x,F,l,Bl[h],o6[h]),s=rE(f,T,$,u,Ll[h],d6[h]),y=f|0,t=IX(G,Y,28)^EV(G,Y,34)^EV(G,Y,39),H0=wX(G,Y,28)^$V(G,Y,34)^$V(G,Y,39),g=G&J^G&V^J&V,d=Y&Z^Y&U^Z&U;T=w|0,x=O|0,w=H|0,O=I|0,H=q|0,I=A|0,{h:q,l:A}=y7(Q|0,N|0,s|0,y|0),Q=V|0,N=U|0,V=J|0,U=Z|0,J=G|0,Z=Y|0;let P=lE(y,H0,d);G=dE(P,s,t,g),Y=P|0}({h:G,l:Y}=y7(this.Ah|0,this.Al|0,G|0,Y|0)),{h:J,l:Z}=y7(this.Bh|0,this.Bl|0,J|0,Z|0),{h:V,l:U}=y7(this.Ch|0,this.Cl|0,V|0,U|0),{h:Q,l:N}=y7(this.Dh|0,this.Dl|0,Q|0,N|0),{h:q,l:A}=y7(this.Eh|0,this.El|0,q|0,A|0),{h:H,l:I}=y7(this.Fh|0,this.Fl|0,H|0,I|0),{h:w,l:O}=y7(this.Gh|0,this.Gl|0,w|0,O|0),{h:T,l:x}=y7(this.Hh|0,this.Hl|0,T|0,x|0),this.set(G,Y,J,Z,V,U,Q,N,q,A,H,I,w,O,T,x)}roundClean(){B4(d6,o6)}destroy(){B4(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}}class tE extends bj{constructor(){super(48);this.Ah=J9[0]|0,this.Al=J9[1]|0,this.Bh=J9[2]|0,this.Bl=J9[3]|0,this.Ch=J9[4]|0,this.Cl=J9[5]|0,this.Dh=J9[6]|0,this.Dl=J9[7]|0,this.Eh=J9[8]|0,this.El=J9[9]|0,this.Fh=J9[10]|0,this.Fl=J9[11]|0,this.Gh=J9[12]|0,this.Gl=J9[13]|0,this.Hh=J9[14]|0,this.Hl=J9[15]|0}}var DY=zq(()=>new aE);var eE=zq(()=>new bj),W$=zq(()=>new tE);class mj extends MV{constructor(W,X){super();this.finished=!1,this.destroyed=!1,qq(W);let G=TV(X);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 Y=this.blockLen,J=new Uint8Array(Y);J.set(G.length>Y?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),B4(J)}update(W){return KY(this),this.iHash.update(W),this}digestInto(W){KY(this),a5(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:X,iHash:G,finished:Y,destroyed:J,blockLen:Z,outputLen:V}=this;return W=W,W.finished=Y,W.destroyed=J,W.blockLen=Z,W.outputLen=V,W.oHash=X._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 fj=(W,X,G)=>new mj(W,X).update(G).digest();fj.create=(W,X)=>new mj(W,X);/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */var CY=BigInt(0),jX=BigInt(1);function FV(W,X){let G=X.negate();return W?G:X}function Cq(W,X){let G=wq(W.Fp,X.map((Y)=>Y.Z));return X.map((Y,J)=>W.fromAffine(Y.toAffine(G[J])))}function J$(W,X){if(!Number.isSafeInteger(W)||W<=0||W>X)throw Error("invalid window size, expected [1.."+X+"], got W="+W)}function pj(W,X){J$(W,X);let G=Math.ceil(X/W)+1,Y=2**(W-1),J=2**W,Z=c6(W),V=BigInt(W);return{windows:G,windowSize:Y,mask:Z,maxNumber:J,shiftBy:V}}function X$(W,X,G){let{windowSize:Y,mask:J,maxNumber:Z,shiftBy:V}=G,U=Number(W&J),Q=W>>V;if(U>Y)U-=Z,Q+=jX;let N=X*Y,q=N+Math.abs(U)-1,A=U===0,H=U<0,I=X%2!==0;return{nextN:Q,offset:q,isZero:A,isNeg:H,isNegF:I,offsetF:N}}function El(W,X){if(!Array.isArray(W))throw Error("array expected");W.forEach((G,Y)=>{if(!(G instanceof X))throw Error("invalid point at index "+Y)})}function $l(W,X){if(!Array.isArray(W))throw Error("array of scalars expected");W.forEach((G,Y)=>{if(!X.isValid(G))throw Error("invalid scalar at index "+Y)})}var cj=new WeakMap,Z$=new WeakMap;function lj(W){return Z$.get(W)||1}function G$(W){if(W!==CY)throw Error("invalid wNAF")}class dj{constructor(W,X){this.BASE=W.BASE,this.ZERO=W.ZERO,this.Fn=W.Fn,this.bits=X}_unsafeLadder(W,X,G=this.ZERO){let Y=W;while(X>CY){if(X&jX)G=G.add(Y);Y=Y.double(),X>>=jX}return G}precomputeWindow(W,X){let{windows:G,windowSize:Y}=pj(X,this.bits),J=[],Z=W,V=Z;for(let U=0;U<G;U++){V=Z,J.push(V);for(let Q=1;Q<Y;Q++)V=V.add(Z),J.push(V);Z=V.double()}return J}wNAF(W,X,G){if(!this.Fn.isValid(G))throw Error("invalid scalar");let Y=this.ZERO,J=this.BASE,Z=pj(W,this.bits);for(let V=0;V<Z.windows;V++){let{nextN:U,offset:Q,isZero:N,isNeg:q,isNegF:A,offsetF:H}=X$(G,V,Z);if(G=U,N)J=J.add(FV(A,X[H]));else Y=Y.add(FV(q,X[Q]))}return G$(G),{p:Y,f:J}}wNAFUnsafe(W,X,G,Y=this.ZERO){let J=pj(W,this.bits);for(let Z=0;Z<J.windows;Z++){if(G===CY)break;let{nextN:V,offset:U,isZero:Q,isNeg:N}=X$(G,Z,J);if(G=V,Q)continue;else{let q=X[U];Y=Y.add(N?q.negate():q)}}return G$(G),Y}getPrecomputes(W,X,G){let Y=cj.get(X);if(!Y){if(Y=this.precomputeWindow(X,W),W!==1){if(typeof G==="function")Y=G(Y);cj.set(X,Y)}}return Y}cached(W,X,G){let Y=lj(W);return this.wNAF(Y,this.getPrecomputes(Y,W,G),X)}unsafe(W,X,G,Y){let J=lj(W);if(J===1)return this._unsafeLadder(W,X,Y);return this.wNAFUnsafe(J,this.getPrecomputes(J,W,G),X,Y)}createCache(W,X){J$(X,this.bits),Z$.set(W,X),cj.delete(W)}hasCache(W){return lj(W)!==1}}function V$(W,X,G,Y){let J=X,Z=W.ZERO,V=W.ZERO;while(G>CY||Y>CY){if(G&jX)Z=Z.add(J);if(Y&jX)V=V.add(J);J=J.double(),G>>=jX,Y>>=jX}return{p1:Z,p2:V}}function U$(W,X,G,Y){El(G,W),$l(Y,X);let J=G.length,Z=Y.length;if(J!==Z)throw Error("arrays of points and scalars must have equal length");let V=W.ZERO,U=Iq(BigInt(J)),Q=1;if(U>12)Q=U-3;else if(U>4)Q=U-2;else if(U>0)Q=2;let N=c6(Q),q=Array(Number(N)+1).fill(V),A=Math.floor((X.BITS-1)/Q)*Q,H=V;for(let I=A;I>=0;I-=Q){q.fill(V);for(let O=0;O<Z;O++){let T=Y[O],x=Number(T>>BigInt(I)&N);q[x]=q[x].add(G[O])}let w=V;for(let O=q.length-1,T=V;O>0;O--)T=T.add(q[O]),w=w.add(T);if(H=H.add(w),I!==0)for(let O=0;O<Q;O++)H=H.double()}return H}function Y$(W,X,G){if(X){if(X.ORDER!==W)throw Error("Field.ORDER must match order: Fp == p, Fn == n");return vj(X),X}else return $5(W,{isLE:G})}function Q$(W,X,G={},Y){if(Y===void 0)Y=W==="edwards";if(!X||typeof X!=="object")throw Error(`expected valid ${W} CURVE object`);for(let Q of["p","n","h"]){let N=X[Q];if(!(typeof N==="bigint"&&N>CY))throw Error(`CURVE.${Q} must be positive bigint`)}let J=Y$(X.p,G.Fp,Y),Z=Y$(X.n,G.Fn,Y),U=["Gx","Gy","a",W==="weierstrass"?"b":"d"];for(let Q of U)if(!J.isValid(X[Q]))throw Error(`CURVE.${Q} must be valid field element of CURVE.Fp`);return X=Object.freeze(Object.assign({},X)),{CURVE:X,Fp:J,Fn:Z}}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */var N$=(W,X)=>(W+(W>=0?X:-X)/H$)/X;function Fl(W,X,G){let[[Y,J],[Z,V]]=X,U=N$(V*W,G),Q=N$(-J*W,G),N=W-U*Y-Q*Z,q=-U*J-Q*V,A=N<x4,H=q<x4;if(A)N=-N;if(H)q=-q;let I=c6(Math.ceil(Iq(G)/2))+TY;if(N<x4||N>=I||q<x4||q>=I)throw Error("splitScalar (endomorphism): failed, k="+W);return{k1neg:A,k1:N,k2neg:H,k2:q}}function nj(W){if(!["compact","recovered","der"].includes(W))throw Error('Signature format must be "compact", "recovered", or "der"');return W}function oj(W,X){let G={};for(let Y of Object.keys(X))G[Y]=W[Y]===void 0?X[Y]:W[Y];if(PV(G.lowS,"lowS"),PV(G.prehash,"prehash"),G.format!==void 0)nj(G.format);return G}class q$ extends Error{constructor(W=""){super(W)}}var S4={Err:q$,_tlv:{encode:(W,X)=>{let{Err:G}=S4;if(W<0||W>256)throw new G("tlv.encode: wrong tag");if(X.length&1)throw new G("tlv.encode: unpadded data");let Y=X.length/2,J=RV(Y);if(J.length/2&128)throw new G("tlv.encode: long form length too big");let Z=Y>127?RV(J.length/2|128):"";return RV(W)+Z+J+X},decode(W,X){let{Err:G}=S4,Y=0;if(W<0||W>256)throw new G("tlv.encode: wrong tag");if(X.length<2||X[Y++]!==W)throw new G("tlv.decode: wrong tlv");let J=X[Y++],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 N=X.subarray(Y,Y+Q);if(N.length!==Q)throw new G("tlv.decode: length bytes not complete");if(N[0]===0)throw new G("tlv.decode(long): zero leftmost byte");for(let q of N)V=V<<8|q;if(Y+=Q,V<128)throw new G("tlv.decode(long): not minimal encoding")}let U=X.subarray(Y,Y+V);if(U.length!==V)throw new G("tlv.decode: wrong value length");return{v:U,l:X.subarray(Y+V)}}},_int:{encode(W){let{Err:X}=S4;if(W<x4)throw new X("integer: negative integers are not allowed");let G=RV(W);if(Number.parseInt(G[0],16)&8)G="00"+G;if(G.length&1)throw new X("unexpected DER parsing assertion: unpadded hex");return G},decode(W){let{Err:X}=S4;if(W[0]&128)throw new X("invalid signature integer: negative");if(W[0]===0&&!(W[1]&128))throw new X("invalid signature integer: unnecessary leading zero");return $4(W)}},toSig(W){let{Err:X,_int:G,_tlv:Y}=S4,J=F8("signature",W),{v:Z,l:V}=Y.decode(48,J);if(V.length)throw new X("invalid signature: left bytes after parsing");let{v:U,l:Q}=Y.decode(2,Z),{v:N,l:q}=Y.decode(2,Q);if(q.length)throw new X("invalid signature: left bytes after parsing");return{r:G.decode(U),s:G.decode(N)}},hexFromSig(W){let{_tlv:X,_int:G}=S4,Y=X.encode(2,G.encode(W.r)),J=X.encode(2,G.encode(W.s)),Z=Y+J;return X.encode(48,Z)}},x4=BigInt(0),TY=BigInt(1),H$=BigInt(2),Tq=BigInt(3),Sl=BigInt(4);function n6(W,X){let{BYTES:G}=W,Y;if(typeof X==="bigint")Y=X;else{let J=F8("private key",X);try{Y=W.fromBytes(J)}catch(Z){throw Error(`invalid private key: expected ui8a of size ${G}, got ${typeof X}`)}}if(!W.isValidNot0(Y))throw Error("invalid private key: out of range [1..N-1]");return Y}function xl(W,X={}){let G=Q$("weierstrass",W,X),{Fp:Y,Fn:J}=G,Z=G.CURVE,{h:V,n:U}=Z;BV(X,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",wrapPrivateKey:"boolean"});let{endo:Q}=X;if(Q){if(!Y.is0(Z.a)||typeof Q.beta!=="bigint"||!Array.isArray(Q.basises))throw Error('invalid endo: expected "beta": bigint and "basises": array')}let N=z$(Y,J);function q(){if(!Y.isOdd)throw Error("compression is not supported: Field does not have .isOdd()")}function A(g,d,P){let{x:E,y:p}=d.toAffine(),r=Y.toBytes(E);if(PV(P,"isCompressed"),P){q();let o=!Y.isOdd(p);return a9(A$(o),r)}else return a9(Uint8Array.of(4),r,Y.toBytes(p))}function H(g){p6(g,void 0,"Point");let{publicKey:d,publicKeyUncompressed:P}=N,E=g.length,p=g[0],r=g.subarray(1);if(E===d&&(p===2||p===3)){let o=Y.fromBytes(r);if(!Y.isValid(o))throw Error("bad point: is not on curve, wrong x");let B=O(o),S;try{S=Y.sqrt(B)}catch(R){let m=R instanceof Error?": "+R.message:"";throw Error("bad point: is not on curve, sqrt error"+m)}q();let _=Y.isOdd(S);if((p&1)===1!==_)S=Y.neg(S);return{x:o,y:S}}else if(E===P&&p===4){let o=Y.BYTES,B=Y.fromBytes(r.subarray(0,o)),S=Y.fromBytes(r.subarray(o,o*2));if(!T(B,S))throw Error("bad point: is not on curve");return{x:B,y:S}}else throw Error(`bad point: got length ${E}, expected compressed=${d} or uncompressed=${P}`)}let I=X.toBytes||A,w=X.fromBytes||H;function O(g){let d=Y.sqr(g),P=Y.mul(d,g);return Y.add(Y.add(P,Y.mul(g,Z.a)),Z.b)}function T(g,d){let P=Y.sqr(d),E=O(g);return Y.eql(P,E)}if(!T(Z.Gx,Z.Gy))throw Error("bad curve params: generator point");let x=Y.mul(Y.pow(Z.a,Tq),Sl),h=Y.mul(Y.sqr(Z.b),BigInt(27));if(Y.is0(Y.add(x,h)))throw Error("bad curve params: a or b");function $(g,d,P=!1){if(!Y.isValid(d)||P&&Y.is0(d))throw Error(`bad point coordinate ${g}`);return d}function F(g){if(!(g instanceof y))throw Error("ProjectivePoint expected")}function u(g){if(!Q||!Q.basises)throw Error("no endo");return Fl(g,Q.basises,J.ORDER)}let l=_j((g,d)=>{let{X:P,Y:E,Z:p}=g;if(Y.eql(p,Y.ONE))return{x:P,y:E};let r=g.is0();if(d==null)d=r?Y.ONE:Y.inv(p);let o=Y.mul(P,d),B=Y.mul(E,d),S=Y.mul(p,d);if(r)return{x:Y.ZERO,y:Y.ZERO};if(!Y.eql(S,Y.ONE))throw Error("invZ was invalid");return{x:o,y:B}}),f=_j((g)=>{if(g.is0()){if(X.allowInfinityPoint&&!Y.is0(g.Y))return;throw Error("bad point: ZERO")}let{x:d,y:P}=g.toAffine();if(!Y.isValid(d)||!Y.isValid(P))throw Error("bad point: x or y not field elements");if(!T(d,P))throw Error("bad point: equation left != right");if(!g.isTorsionFree())throw Error("bad point: not in prime-order subgroup");return!0});function s(g,d,P,E,p){return P=new y(Y.mul(P.X,g),P.Y,P.Z),d=FV(E,d),P=FV(p,P),d.add(P)}class y{constructor(g,d,P){this.X=$("x",g),this.Y=$("y",d,!0),this.Z=$("z",P),Object.freeze(this)}static CURVE(){return Z}static fromAffine(g){let{x:d,y:P}=g||{};if(!g||!Y.isValid(d)||!Y.isValid(P))throw Error("invalid affine point");if(g instanceof y)throw Error("projective point not allowed");if(Y.is0(d)&&Y.is0(P))return y.ZERO;return new y(d,P,Y.ONE)}static fromBytes(g){let d=y.fromAffine(w(p6(g,void 0,"point")));return d.assertValidity(),d}static fromHex(g){return y.fromBytes(F8("pointHex",g))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(g=8,d=!0){if(H0.createCache(this,g),!d)this.multiply(Tq);return this}assertValidity(){f(this)}hasEvenY(){let{y:g}=this.toAffine();if(!Y.isOdd)throw Error("Field doesn't support isOdd");return!Y.isOdd(g)}equals(g){F(g);let{X:d,Y:P,Z:E}=this,{X:p,Y:r,Z:o}=g,B=Y.eql(Y.mul(d,o),Y.mul(p,E)),S=Y.eql(Y.mul(P,o),Y.mul(r,E));return B&&S}negate(){return new y(this.X,Y.neg(this.Y),this.Z)}double(){let{a:g,b:d}=Z,P=Y.mul(d,Tq),{X:E,Y:p,Z:r}=this,o=Y.ZERO,B=Y.ZERO,S=Y.ZERO,_=Y.mul(E,E),v=Y.mul(p,p),R=Y.mul(r,r),m=Y.mul(E,p);return m=Y.add(m,m),S=Y.mul(E,r),S=Y.add(S,S),o=Y.mul(g,S),B=Y.mul(P,R),B=Y.add(o,B),o=Y.sub(v,B),B=Y.add(v,B),B=Y.mul(o,B),o=Y.mul(m,o),S=Y.mul(P,S),R=Y.mul(g,R),m=Y.sub(_,R),m=Y.mul(g,m),m=Y.add(m,S),S=Y.add(_,_),_=Y.add(S,_),_=Y.add(_,R),_=Y.mul(_,m),B=Y.add(B,_),R=Y.mul(p,r),R=Y.add(R,R),_=Y.mul(R,m),o=Y.sub(o,_),S=Y.mul(R,v),S=Y.add(S,S),S=Y.add(S,S),new y(o,B,S)}add(g){F(g);let{X:d,Y:P,Z:E}=this,{X:p,Y:r,Z:o}=g,B=Y.ZERO,S=Y.ZERO,_=Y.ZERO,v=Z.a,R=Y.mul(Z.b,Tq),m=Y.mul(d,p),J0=Y.mul(P,r),U0=Y.mul(E,o),q0=Y.add(d,P),$0=Y.add(p,r);q0=Y.mul(q0,$0),$0=Y.add(m,J0),q0=Y.sub(q0,$0),$0=Y.add(d,E);let u0=Y.add(p,o);return $0=Y.mul($0,u0),u0=Y.add(m,U0),$0=Y.sub($0,u0),u0=Y.add(P,E),B=Y.add(r,o),u0=Y.mul(u0,B),B=Y.add(J0,U0),u0=Y.sub(u0,B),_=Y.mul(v,$0),B=Y.mul(R,U0),_=Y.add(B,_),B=Y.sub(J0,_),_=Y.add(J0,_),S=Y.mul(B,_),J0=Y.add(m,m),J0=Y.add(J0,m),U0=Y.mul(v,U0),$0=Y.mul(R,$0),J0=Y.add(J0,U0),U0=Y.sub(m,U0),U0=Y.mul(v,U0),$0=Y.add($0,U0),m=Y.mul(J0,$0),S=Y.add(S,m),m=Y.mul(u0,$0),B=Y.mul(q0,B),B=Y.sub(B,m),m=Y.mul(q0,J0),_=Y.mul(u0,_),_=Y.add(_,m),new y(B,S,_)}subtract(g){return this.add(g.negate())}is0(){return this.equals(y.ZERO)}multiply(g){let{endo:d}=X;if(!J.isValidNot0(g))throw Error("invalid scalar: out of range");let P,E,p=(r)=>H0.cached(this,r,(o)=>Cq(y,o));if(d){let{k1neg:r,k1:o,k2neg:B,k2:S}=u(g),{p:_,f:v}=p(o),{p:R,f:m}=p(S);E=v.add(m),P=s(d.beta,_,R,r,B)}else{let{p:r,f:o}=p(g);P=r,E=o}return Cq(y,[P,E])[0]}multiplyUnsafe(g){let{endo:d}=X,P=this;if(!J.isValid(g))throw Error("invalid scalar: out of range");if(g===x4||P.is0())return y.ZERO;if(g===TY)return P;if(H0.hasCache(this))return this.multiply(g);if(d){let{k1neg:E,k1:p,k2neg:r,k2:o}=u(g),{p1:B,p2:S}=V$(y,P,p,o);return s(d.beta,B,S,E,r)}else return H0.unsafe(P,g)}multiplyAndAddUnsafe(g,d,P){let E=this.multiplyUnsafe(d).add(g.multiplyUnsafe(P));return E.is0()?void 0:E}toAffine(g){return l(this,g)}isTorsionFree(){let{isTorsionFree:g}=X;if(V===TY)return!0;if(g)return g(y,this);return H0.unsafe(this,U).is0()}clearCofactor(){let{clearCofactor:g}=X;if(V===TY)return this;if(g)return g(y,this);return this.multiplyUnsafe(V)}isSmallOrder(){return this.multiplyUnsafe(V).is0()}toBytes(g=!0){return PV(g,"isCompressed"),this.assertValidity(),I(y,this,g)}toHex(g=!0){return E4(this.toBytes(g))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}get px(){return this.X}get py(){return this.X}get pz(){return this.Z}toRawBytes(g=!0){return this.toBytes(g)}_setWindowSize(g){this.precompute(g)}static normalizeZ(g){return Cq(y,g)}static msm(g,d){return U$(y,J,g,d)}static fromPrivateKey(g){return y.BASE.multiply(n6(J,g))}}y.BASE=new y(Z.Gx,Z.Gy,Y.ONE),y.ZERO=new y(Y.ZERO,Y.ONE,Y.ZERO),y.Fp=Y,y.Fn=J;let t=J.BITS,H0=new dj(y,X.endo?Math.ceil(t/2):t);return y.BASE.precompute(8),y}function A$(W){return Uint8Array.of(W?2:3)}function z$(W,X){return{secretKey:X.BYTES,publicKey:1+W.BYTES,publicKeyUncompressed:1+2*W.BYTES,publicKeyHasPrefix:!0,signature:2*X.BYTES}}function kl(W,X={}){let{Fn:G}=W,Y=X.randomBytes||AX,J=Object.assign(z$(W.Fp,G),{seed:gj(G.ORDER)});function Z(I){try{return!!n6(G,I)}catch(w){return!1}}function V(I,w){let{publicKey:O,publicKeyUncompressed:T}=J;try{let x=I.length;if(w===!0&&x!==O)return!1;if(w===!1&&x!==T)return!1;return!!W.fromBytes(I)}catch(x){return!1}}function U(I=Y(J.seed)){return Kq(p6(I,J.seed,"seed"),G.ORDER)}function Q(I,w=!0){return W.BASE.multiply(n6(G,I)).toBytes(w)}function N(I){let w=U(I);return{secretKey:w,publicKey:Q(w)}}function q(I){if(typeof I==="bigint")return!1;if(I instanceof W)return!0;let{secretKey:w,publicKey:O,publicKeyUncompressed:T}=J;if(G.allowedLengths||w===O)return;let x=F8("key",I).length;return x===O||x===T}function A(I,w,O=!0){if(q(I)===!0)throw Error("first arg must be private key");if(q(w)===!1)throw Error("second arg must be public key");let T=n6(G,I);return W.fromHex(w).multiply(T).toBytes(O)}return Object.freeze({getPublicKey:Q,getSharedSecret:A,keygen:N,Point:W,utils:{isValidSecretKey:Z,isValidPublicKey:V,randomSecretKey:U,isValidPrivateKey:Z,randomPrivateKey:U,normPrivateKeyToScalar:(I)=>n6(G,I),precompute(I=8,w=W.BASE){return w.precompute(I,!1)}},lengths:J})}function _l(W,X,G={}){qq(X),BV(G,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});let Y=G.randomBytes||AX,J=G.hmac||((P,...E)=>fj(X,P,a9(...E))),{Fp:Z,Fn:V}=W,{ORDER:U,BITS:Q}=V,{keygen:N,getPublicKey:q,getSharedSecret:A,utils:H,lengths:I}=kl(W,G),w={prehash:!1,lowS:typeof G.lowS==="boolean"?G.lowS:!1,format:void 0,extraEntropy:!1},O="compact";function T(P){let E=U>>TY;return P>E}function x(P,E){if(!V.isValidNot0(E))throw Error(`invalid signature ${P}: out of range 1..Point.Fn.ORDER`);return E}function h(P,E){nj(E);let p=I.signature,r=E==="compact"?p:E==="recovered"?p+1:void 0;return p6(P,r,`${E} signature`)}class ${constructor(P,E,p){if(this.r=x("r",P),this.s=x("s",E),p!=null)this.recovery=p;Object.freeze(this)}static fromBytes(P,E=O){h(P,E);let p;if(E==="der"){let{r:S,s:_}=S4.toSig(p6(P));return new $(S,_)}if(E==="recovered")p=P[0],E="compact",P=P.subarray(1);let r=V.BYTES,o=P.subarray(0,r),B=P.subarray(r,r*2);return new $(V.fromBytes(o),V.fromBytes(B),p)}static fromHex(P,E){return this.fromBytes(HX(P),E)}addRecoveryBit(P){return new $(this.r,this.s,P)}recoverPublicKey(P){let E=Z.ORDER,{r:p,s:r,recovery:o}=this;if(o==null||![0,1,2,3].includes(o))throw Error("recovery id invalid");if(U*H$<E&&o>1)throw Error("recovery id is ambiguous for h>1 curve");let S=o===2||o===3?p+U:p;if(!Z.isValid(S))throw Error("recovery id 2 or 3 invalid");let _=Z.toBytes(S),v=W.fromBytes(a9(A$((o&1)===0),_)),R=V.inv(S),m=u(F8("msgHash",P)),J0=V.create(-m*R),U0=V.create(r*R),q0=W.BASE.multiplyUnsafe(J0).add(v.multiplyUnsafe(U0));if(q0.is0())throw Error("point at infinify");return q0.assertValidity(),q0}hasHighS(){return T(this.s)}toBytes(P=O){if(nj(P),P==="der")return HX(S4.hexFromSig(this));let E=V.toBytes(this.r),p=V.toBytes(this.s);if(P==="recovered"){if(this.recovery==null)throw Error("recovery bit must be present");return a9(Uint8Array.of(this.recovery),E,p)}return a9(E,p)}toHex(P){return E4(this.toBytes(P))}assertValidity(){}static fromCompact(P){return $.fromBytes(F8("sig",P),"compact")}static fromDER(P){return $.fromBytes(F8("sig",P),"der")}normalizeS(){return this.hasHighS()?new $(this.r,V.neg(this.s),this.recovery):this}toDERRawBytes(){return this.toBytes("der")}toDERHex(){return E4(this.toBytes("der"))}toCompactRawBytes(){return this.toBytes("compact")}toCompactHex(){return E4(this.toBytes("compact"))}}let F=G.bits2int||function(E){if(E.length>8192)throw Error("input is too large");let p=$4(E),r=E.length*8-Q;return r>0?p>>BigInt(r):p},u=G.bits2int_modN||function(E){return V.create(F(E))},l=c6(Q);function f(P){return $E("num < 2^"+Q,P,x4,l),V.toBytes(P)}function s(P,E){return p6(P,void 0,"message"),E?p6(X(P),void 0,"prehashed message"):P}function y(P,E,p){if(["recovered","canonical"].some((U0)=>(U0 in p)))throw Error("sign() legacy options not supported");let{lowS:r,prehash:o,extraEntropy:B}=oj(p,w);P=s(P,o);let S=u(P),_=n6(V,E),v=[f(_),f(S)];if(B!=null&&B!==!1){let U0=B===!0?Y(I.secretKey):B;v.push(F8("extraEntropy",U0))}let R=a9(...v),m=S;function J0(U0){let q0=F(U0);if(!V.isValidNot0(q0))return;let $0=V.inv(q0),u0=W.BASE.multiply(q0).toAffine(),H1=V.create(u0.x);if(H1===x4)return;let v1=V.create($0*V.create(m+H1*_));if(v1===x4)return;let h0=(u0.x===H1?0:2)|Number(u0.y&TY),F1=v1;if(r&&T(v1))F1=V.neg(v1),h0^=1;return new $(H1,F1,h0)}return{seed:R,k2sig:J0}}function t(P,E,p={}){P=F8("message",P);let{seed:r,k2sig:o}=y(P,E,p);return FE(X.outputLen,V.BYTES,J)(r,o)}function H0(P){let E=void 0,p=typeof P==="string"||qX(P),r=!p&&P!==null&&typeof P==="object"&&typeof P.r==="bigint"&&typeof P.s==="bigint";if(!p&&!r)throw Error("invalid signature, expected Uint8Array, hex string or Signature instance");if(r)E=new $(P.r,P.s);else if(p){try{E=$.fromBytes(F8("sig",P),"der")}catch(o){if(!(o instanceof S4.Err))throw o}if(!E)try{E=$.fromBytes(F8("sig",P),"compact")}catch(o){return!1}}if(!E)return!1;return E}function g(P,E,p,r={}){let{lowS:o,prehash:B,format:S}=oj(r,w);if(p=F8("publicKey",p),E=s(F8("message",E),B),"strict"in r)throw Error("options.strict was renamed to lowS");let _=S===void 0?H0(P):$.fromBytes(F8("sig",P),S);if(_===!1)return!1;try{let v=W.fromBytes(p);if(o&&_.hasHighS())return!1;let{r:R,s:m}=_,J0=u(E),U0=V.inv(m),q0=V.create(J0*U0),$0=V.create(R*U0),u0=W.BASE.multiplyUnsafe(q0).add(v.multiplyUnsafe($0));if(u0.is0())return!1;return V.create(u0.x)===R}catch(v){return!1}}function d(P,E,p={}){let{prehash:r}=oj(p,w);return E=s(E,r),$.fromBytes(P,"recovered").recoverPublicKey(E).toBytes()}return Object.freeze({keygen:N,getPublicKey:q,getSharedSecret:A,utils:H,lengths:I,Point:W,sign:t,verify:g,recoverPublicKey:d,Signature:$,hash:X})}function yl(W){let X={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,Y=W.allowedPrivateKeyLengths?Array.from(new Set(W.allowedPrivateKeyLengths.map((V)=>Math.ceil(V/2)))):void 0,J=$5(X.n,{BITS:W.nBitLength,allowedLengths:Y,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:X,curveOpts:Z}}function vl(W){let{CURVE:X,curveOpts:G}=yl(W),Y={hmac:W.hmac,randomBytes:W.randomBytes,lowS:W.lowS,bits2int:W.bits2int,bits2int_modN:W.bits2int_modN};return{CURVE:X,curveOpts:G,hash:W.hash,ecdsaOpts:Y}}function gl(W,X){let G=X.Point;return Object.assign({},X,{ProjectivePoint:G,CURVE:Object.assign({},W,jq(G.Fn.ORDER,G.Fn.BITS))})}function I$(W){let{CURVE:X,curveOpts:G,hash:Y,ecdsaOpts:J}=vl(W),Z=xl(X,G),V=_l(Z,Y,J);return gl(W,V)}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */function MY(W,X){let G=(Y)=>I$({...W,hash:Y});return{...G(X),create:G}}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */var w$={p:BigInt("0xffffffff00000001000000000000000000000000ffffffffffffffffffffffff"),n:BigInt("0xffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551"),h:BigInt(1),a:BigInt("0xffffffff00000001000000000000000000000000fffffffffffffffffffffffc"),b:BigInt("0x5ac635d8aa3a93e7b3ebbd55769886bc651d06b0cc53b0f63bce3c3e27d2604b"),Gx:BigInt("0x6b17d1f2e12c4247f8bce6e563a440f277037d812deb33a0f4a13945d898c296"),Gy:BigInt("0x4fe342e2fe1a7f9b8ee7eb4a7c0f9e162bce33576b315ececbb6406837bf51f5")},j$={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffeffffffff0000000000000000ffffffff"),n:BigInt("0xffffffffffffffffffffffffffffffffffffffffffffffffc7634d81f4372ddf581a0db248b0a77aecec196accc52973"),h:BigInt(1),a:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffeffffffff0000000000000000fffffffc"),b:BigInt("0xb3312fa7e23ee7e4988e056be3f82d19181d9c6efe8141120314088f5013875ac656398d8a2ed19d2a85c8edd3ec2aef"),Gx:BigInt("0xaa87ca22be8b05378eb1c71ef320ad746e1d3b628ba79b9859f741e082542a385502f25dbf55296c3a545e3872760ab7"),Gy:BigInt("0x3617de4a96262c6f5d9e98bf9292dc29f8f41dbd289a147ce9da3113b5f0b8c00a60b1ce1d7e819d7a431d7c90ea0e5f")},K$={p:BigInt("0x1ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),n:BigInt("0x01fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffa51868783bf2f966b7fcc0148f709a5d03bb5c9b8899c47aebb6fb71e91386409"),h:BigInt(1),a:BigInt("0x1fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc"),b:BigInt("0x0051953eb9618e1c9a1f929a21a0b68540eea2da725b99b315f3b8b489918ef109e156193951ec7e937b1652c0bd3bb1bf073573df883d2c34f1ef451fd46b503f00"),Gx:BigInt("0x00c6858e06b70404e9cd9e3ecb662395b4429c648139053fb521f828af606b4d3dbaa14b5e77efe75928fe1dc127a2ffa8de3348b3c1856a429bf97e7e31c2e5bd66"),Gy:BigInt("0x011839296a789a3bc0045c8a5fb42c7d1bd998f54449579b446817afbd17273e662c97ee72995ef42640c550b9013fad0761353c7086a272c24088be94769fd16650")},ul=$5(w$.p),hl=$5(j$.p),bl=$5(K$.p);var O$=MY({...w$,Fp:ul,lowS:!1},DY);var dq0=MY({...j$,Fp:hl,lowS:!1},W$);var oq0=MY({...K$,Fp:bl,lowS:!1,allowedPrivateKeyLengths:[130,131,132]},eE);/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */var Mq=O$;var U9=b1(D8(),1),Z7=b1(D8(),1),n2=b1(D8(),1),MX=b1(D8(),1),l4=b1(D8(),1),e2=b1(yQ(),1),RX=b1(D8(),1),a6=b1(D8(),1),LX=b1(D8(),1),lY=b1(D8(),1),s6=b1(D8(),1),BX=b1(D8(),1),V7=b1(D8(),1),U7=b1(D8(),1),jH=b1(D8(),1),J7=b1(D8(),1),US=b1(D8(),1),bo=b1(M$(),1);import{randomBytes as Co}from"crypto";import{setTimeout as To}from"timers/promises";import{createCipheriv as ko,createDecipheriv as _o}from"crypto";var hq=b1(R$(),1),EX=b1(D8(),1),CX=b1(D8(),1),o7=b1(D8(),1),l7=b1(D8(),1),$X=b1(D8(),1);import{createHmac as QK}from"crypto";import{createCipheriv as HF,createDecipheriv as AF,createHmac as zF,timingSafeEqual as wn}from"crypto";import{createCipheriv as KF,createDecipheriv as OF}from"crypto";import{setTimeout as Ln}from"timers/promises";import{randomBytes as Sn}from"crypto";import{createHmac as ES}from"crypto";import{randomBytes as $S}from"crypto";var Bq="undefined",EY=Bq!==typeof Buffer&&Buffer,BY=Bq!==typeof Uint8Array&&Uint8Array,Lq=Bq!==typeof ArrayBuffer&&ArrayBuffer,L$=[0,0,0,0,0,0,0,0],pl=Array.isArray||al,LY=4294967296,cl=16777216,$Y,Eq=E$("Uint64BE",!0,!0),aj=E$("Int64BE",!0,!1);function E$(W,X,G){var Y=X?0:4,J=X?4:0,Z=X?0:3,V=X?1:2,U=X?2:1,Q=X?3:0,N=X?ol:il,q=X?nl:rl,A=w.prototype,H="is"+W,I="_"+H;if(A.buffer=void 0,A.offset=0,A[I]=!0,A.toNumber=h,A.toString=$,A.toJSON=h,A.toArray=ll,EY)A.toBuffer=dl;if(BY)A.toArrayBuffer=$$;return w[H]=O,w;function w(l,f,s,y){if(!(this instanceof w))return new w(l,f,s,y);return T(this,l,f,s,y)}function O(l){return!!(l&&l[I])}function T(l,f,s,y,t){if(BY&&Lq){if(f instanceof Lq)f=new BY(f);if(y instanceof Lq)y=new BY(y)}if(!f&&!s&&!y&&!$Y){l.buffer=F$(L$,0);return}if(!B$(f,s)){var H0=$Y||Array;t=s,y=f,s=0,f=$Y===EY?EY.alloc(8):new H0(8)}if(l.buffer=f,l.offset=s|=0,Bq===typeof y)return;if(typeof y==="string")x(f,s,y,t||10);else if(B$(y,t))rj(f,s,y,t);else if(typeof t==="number")F(f,s+Y,y),F(f,s+J,t);else if(y>0)N(f,s,y);else if(y<0)q(f,s,y);else rj(f,s,L$,0)}function x(l,f,s,y){var t=0,H0=s.length,g=0,d=0;if(s[0]==="-")t++;var P=t;while(t<H0){var E=parseInt(s[t++],y);if(!(E>=0))break;d=d*y+E,g=g*y+Math.floor(d/LY),d%=LY}if(P)if(g=~g,d)d=LY-d;else g++;F(l,f+Y,g),F(l,f+J,d)}function h(){var l=this.buffer,f=this.offset,s=u(l,f+Y),y=u(l,f+J);if(!G)s|=0;return s?s*LY+y:y}function $(l){var f=this.buffer,s=this.offset,y=u(f,s+Y),t=u(f,s+J),H0="",g=!G&&y&2147483648;if(g)y=~y,t=LY-t;l=l||10;while(!0){var d=y%l*LY+t;if(y=Math.floor(y/l),t=Math.floor(d/l),H0=(d%l).toString(l)+H0,!y&&!t)break}if(g)H0="-"+H0;return H0}function F(l,f,s){l[f+Q]=s&255,s=s>>8,l[f+U]=s&255,s=s>>8,l[f+V]=s&255,s=s>>8,l[f+Z]=s&255}function u(l,f){return l[f+Z]*cl+(l[f+V]<<16)+(l[f+U]<<8)+l[f+Q]}}function ll(W){var X=this.buffer,G=this.offset;if($Y=null,W!==!1&&pl(X))return X.length===8?X:X.slice(G,G+8);return F$(X,G)}function dl(W){var X=this.buffer,G=this.offset;if($Y=EY,W!==!1&&EY.isBuffer(X))return X.length===8?X:X.slice(G,G+8);return EY.from($$.call(this,W))}function $$(W){var X=this.buffer,G=this.offset,Y=X.buffer;if($Y=BY,W!==!1&&!X.offset&&Y instanceof Lq)return Y.byteLength===8?Y:Y.slice(G,G+8);var J=new BY(8);return rj(J,0,X,G),J.buffer}function B$(W,X){var G=W&&W.length;return X|=0,G&&X+8<=G&&typeof W[X]!=="string"}function rj(W,X,G,Y){X|=0,Y|=0;for(var J=0;J<8;J++)W[X++]=G[Y++]&255}function F$(W,X){return Array.prototype.slice.call(W,X,X+8)}function ol(W,X,G){var Y=X+8;while(Y>X)W[--Y]=G&255,G/=256}function nl(W,X,G){var Y=X+8;G++;while(Y>X)W[--Y]=-G&255^255,G/=256}function il(W,X,G){var Y=X+8;while(X<Y)W[X++]=G&255,G/=256}function rl(W,X,G){var Y=X+8;G++;while(X<Y)W[X++]=-G&255^255,G/=256}function al(W){return!!W&&Object.prototype.toString.call(W)=="[object Array]"}var tV=b1(tj(),1);import{createHash as rn}from"crypto";import{setTimeout as an}from"timers/promises";import{createHash as Ji}from"crypto";import{isIPv4 as hF}from"net";import{randomBytes as Zi}from"crypto";import{isIPv4 as bF}from"net";var pq=b1(k$(),1),gS=b1(n$(),1),hS=b1(tj(),1);import*as uK from"timers/promises";import{randomUUID as Ui}from"crypto";import*as uS from"os";import{EventEmitter as Oi}from"events";import{randomUUID as Fi}from"crypto";import{setTimeout as KK}from"timers/promises";import{createHash as Si}from"crypto";import{performance as kq}from"perf_hooks";import{randomUUID as xi}from"crypto";import{randomUUID as aS}from"crypto";import{setTimeout as ei}from"timers/promises";import{randomBytes as Yr}from"crypto";import{isIPv4 as Jr}from"net";var eV=b1(bz(),1);import{randomUUID as Zr}from"crypto";import{setTimeout as Vr}from"timers/promises";import{randomUUID as Hr}from"crypto";import{randomUUID as jr}from"crypto";import{createHmac as Z2,randomBytes as Kr}from"crypto";import{randomBytes as K2}from"crypto";import{randomUUID as O2}from"crypto";import{setTimeout as D2}from"timers/promises";import{randomUUID as dr}from"crypto";function R2(){return X8.Unpack("!H",P2(2))[0]}function PK(){return X8.Unpack("!L",P2(4))[0]}var aq=class{constructor(W){this.bitLength=W}value=0;set(W,X,G){return G&=(1<<W)-1,this.value|=G<<this.bitLength-W-X,this}get buffer(){let W=Math.ceil(this.bitLength/8),X=Buffer.alloc(W);return X.writeUIntBE(this.value,0,W),X}},L2=class{constructor(W){if(this.bitLength=W,W>32)throw Error()}_value=0n;offset=0n;set(W,X=1){let G=BigInt(W),Y=BigInt(X);return G&=(1n<<Y)-1n,this._value|=G<<BigInt(this.bitLength)-Y-this.offset,this.offset+=Y,this}get value(){return Number(this._value)}get buffer(){let W=Math.ceil(this.bitLength/8),X=Buffer.alloc(W);return X.writeUIntBE(this.value,0,W),X}};function b8(W,X,G=1){let Y=W.toString(2).split("");Y=[...Array(8-Y.length).fill("0"),...Y];let J=Y.slice(X,X+G).join("");return Number.parseInt(J,2)}function S8(W,X){return gq(W)(X)}function gq(W,X){let G=W.reduce((J,Z)=>J+Z,0),Y=X?Buffer.alloc(G):void 0;return(J)=>{let Z=Y||Buffer.alloc(G),V=0;return J.forEach((U,Q)=>{let N=W[Q];if(N===8)Z.writeBigUInt64BE(U,V);else Z.writeUIntBE(U,V,N);V+=N}),Z}}function e9(W,X){let G=0;return X.map((Y)=>{let J;if(Y===8)J=W.readBigUInt64BE(G);else J=W.readUIntBE(G,Y);return G+=Y,J})}var lV=class{constructor(W){this.uint8Array=W}position=0;bitsPending=0;writeBits(W,X){if(W==0)return this;X&=4294967295>>>32-W;let G;if(this.bitsPending>0)if(this.bitsPending>W)this.uint8Array[this.position-1]|=X<<this.bitsPending-W,G=W,this.bitsPending-=W;else if(this.bitsPending==W)this.uint8Array[this.position-1]|=X,G=W,this.bitsPending=0;else this.uint8Array[this.position-1]|=X>>W-this.bitsPending,G=this.bitsPending,this.bitsPending=0;else G=Math.min(8,W),this.bitsPending=8-G,this.uint8Array[this.position++]=X>>W-G<<this.bitsPending;if(W-=G,W>0)this.writeBits(W,X);return this}readBits(W){return this._readBits(W)}_readBits(W,X){if(typeof X>"u")X=0;if(W==0)return X;let G,Y;if(this.bitsPending>0){let J=this.uint8Array[this.position-1]&255>>8-this.bitsPending;Y=Math.min(this.bitsPending,W),this.bitsPending-=Y,G=J>>this.bitsPending}else Y=Math.min(8,W),this.bitsPending=8-Y,G=this.uint8Array[this.position++]>>this.bitsPending;return W-=Y,X=X<<Y|G,W>0?this._readBits(W,X):X}seekTo(W){if(this.position=W/8|0,this.bitsPending=W%8,this.bitsPending>0)this.bitsPending=8-this.bitsPending,this.position++}},bd=3988292384,md=2197175160;function B2(W){return typeof W!=="string"}function E2(W){let X=Array(256),G=0;for(let Y=0;Y<256;++Y)G=Y,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,X[Y]=G;return new Int32Array(X)}function $2(W){let X=new Int32Array(4096),G=0,Y=0,J=0;for(J=0;J<256;++J)X[J]=W[J];for(J=0;J<256;++J){Y=W[J];for(G=256+J;G<4096;G+=256)Y=X[G]=Y>>>8^W[Y&255]}let Z=[];for(J=1;J<16;++J)Z[J-1]=X.subarray(J*256,J*256+256);return Z}function F2(W,X,G){let Y=X^-1,J=0,Z=W.length,V=0,U=0;while(J<Z)if(V=W.charCodeAt(J++),V<128)Y=Y>>>8^G[(Y^V)&255];else if(V<2048)Y=Y>>>8^G[(Y^(192|V>>6&31))&255],Y=Y>>>8^G[(Y^(128|V&63))&255];else if(V>=55296&&V<57344)V=(V&1023)+64,U=W.charCodeAt(J++)&1023,Y=Y>>>8^G[(Y^(240|V>>8&7))&255],Y=Y>>>8^G[(Y^(128|V>>2&63))&255],Y=Y>>>8^G[(Y^(128|U>>6&15|(V&3)<<4))&255],Y=Y>>>8^G[(Y^(128|U&63))&255];else Y=Y>>>8^G[(Y^(224|V>>12&15))&255],Y=Y>>>8^G[(Y^(128|V>>6&63))&255],Y=Y>>>8^G[(Y^(128|V&63))&255];return~Y>>>0}function S2(W,X,G,Y){let[J,Z,V,U,Q,N,q,A,H,I,w,O,T,x,h]=Y,$=X^-1,F=0,u=W.length-15;while(F<u)$=h[W[F++]^$&255]^x[W[F++]^$>>>8&255]^T[W[F++]^$>>>16&255]^O[W[F++]^$>>>24]^w[W[F++]]^I[W[F++]]^H[W[F++]]^A[W[F++]]^q[W[F++]]^N[W[F++]]^Q[W[F++]]^U[W[F++]]^V[W[F++]]^Z[W[F++]]^J[W[F++]]^G[W[F++]];for(u+=15;F<u;)$=$>>>8^G[($^W[F++])&255];return~$>>>0}var RK=E2(bd),fd=$2(RK),LK=E2(md),pd=$2(LK);function cd(W,X=0){if(B2(W))return S2(W,X,RK,fd);return F2(W,X,RK)}function x2(W,X=0){if(B2(W))return S2(W,X,LK,pd);return F2(W,X,LK)}function ld(W,X){return W+X&255}function R9(W,X){return W+X&65535}function uY(W,X){return Number(BigInt(W)+BigInt(X)&0xffffffffn)}function dd(W){return W&16777215}function k2(W,X){return W<X&&X-W>32768||W>X&&W-X<32768}function c4(W,X){return W<X&&X-W>2147483648||W>X&&W-X<2147483648}function fV(W,X){return W===X||c4(W,X)}var dV=(W)=>Number.parseInt(W,10);var _2=(W,X)=>X?X[W]:void 0;async function nd(W,X,G="udp4",Y){let J;for(let Z=W;Z<=X;Z++){let V=od(G);if(setImmediate(()=>V.bind({port:Z,address:_2(G,Y)})),await new Promise((Q)=>{V.once("error",(N)=>Q(N)),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<=X)break}if(!J)throw Error("port not found");return J}function sq(W){if(W==="IPv4")return 4;if(W==="IPv6")return 6;return W}var P1=y2.default.debug,d0=class{event={stack:[],promiseStack:[],eventId:0};ended=!1;onended;onerror=(W)=>{};execute=(...W)=>{if(this.ended)return;for(let X of this.event.stack)X.execute(...W);(async()=>{for(let X of this.event.promiseStack)await X.execute(...W)})().catch((X)=>{this.onerror(X)})};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 X of this.event.stack)if(X.error)X.error(W);this.allUnsubscribe()};allUnsubscribe=()=>{if(this.ended)throw Error("event completed");this.event={stack:[],promiseStack:[],eventId:0}};subscribe=(W,X,G)=>{let Y=this.event.eventId;this.event.stack.push({execute:W,id:Y,complete:X,error:G}),this.event.eventId++;let J=()=>{this.event.stack=this.event.stack.filter((V)=>V.id!==Y&&V)};return{unSubscribe:J,disposer:(V)=>{V.push(J)}}};pipe(W){this.subscribe((...X)=>{W.execute(...X)})}queuingSubscribe=(W,X,G)=>{if(this.ended)throw Error("event completed");let Y=this.event.eventId;this.event.promiseStack.push({execute:W,id:Y,complete:X,error:G}),this.event.eventId++;let J=()=>{this.event.stack=this.event.stack.filter((V)=>V.id!==Y&&V)};return{unSubscribe:J,disposer:(V)=>{V.push(J)}}};once=(W,X,G)=>{let Y=this.subscribe((...J)=>{Y.unSubscribe(),W(...J)},X,G)};watch=(W,X)=>new Promise((G,Y)=>{let J=X&&setTimeout(()=>{Y("Event watch timeout")},X),{unSubscribe:Z}=this.subscribe((...V)=>{if(W(...V)){if(J)clearTimeout(J);Z(),G(V)}})});asPromise=(W)=>new Promise((X,G)=>{let Y=W&&setTimeout(()=>{G("Event asPromise timeout")},W);this.once((...J)=>{if(Y)clearTimeout(Y);X(J)},()=>{if(Y)clearTimeout(Y);X([])},(J)=>{if(Y)clearTimeout(Y);G(J)})});get returnTrigger(){let{execute:W,error:X,complete:G}=this;return{execute:W,error:X,complete:G}}get returnListener(){let{subscribe:W,once:X,asPromise:G}=this;return{subscribe:W,once:X,asPromise:G}}get length(){return this.event.stack.length}},id=class{_disposer=[];push(W){this._disposer.push(W)}dispose(){this._disposer.forEach((W)=>W()),this._disposer=[]}},i$=P1("werift-ice:packages/ice/src/transport.ts"),BK=class W{constructor(X,G={}){this.socketType=X,this.options=G,this.socket=rd(X),this.socket.on("message",(Y,J)=>{if(sq(J.family)===6)[J.address]=J.address.split("%");this.rinfo=J;try{this.onData(Y,[J.address,J.port])}catch(Z){i$("onData error",Z)}})}type="udp";socket;rinfo;onData=()=>{};closed=!1;static async init(X,G={}){let Y=new W(X,G);return await Y.init(),Y}async init(){let X=_2(this.socketType,this.options.interfaceAddresses);if(this.options.port)this.socket.bind({port:this.options.port,address:X});else if(this.options.portRange){let G=await nd(this.options.portRange[0],this.options.portRange[1],this.socketType,this.options.interfaceAddresses);this.socket.bind({port:G,address:X})}else this.socket.bind({address:X});await new Promise((G)=>this.socket.once("listening",G))}send=async(X,G)=>{if(G&&!v2.isIP(G[0]))return new Promise((Y,J)=>{this.socket.send(X,G[1],G[0],(Z)=>{if(Z)i$("send error",G,X),J(Z);else Y()})});else G=G??[this.rinfo?.address,this.rinfo?.port],this.socket.send(X,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((X)=>{this.closed=!0,this.socket.once("close",X);try{this.socket.close()}catch(G){X()}})},sd=class W{constructor(X){this.addr=X,this.connect()}type="tcp";connecting;client;onData=()=>{};closed=!1;connect(){if(this.closed)return;if(this.client)this.client.destroy();this.connecting=new Promise((X,G)=>{try{this.client=ad({port:this.addr[1],host:this.addr[0]},X)}catch(Y){G(Y)}}),this.client.on("data",(X)=>{let G=[this.client.remoteAddress,this.client.remotePort];this.onData(X,G)}),this.client.on("end",()=>{this.connect()}),this.client.on("error",(X)=>{console.log("error",X)})}async init(){await this.connecting}static async init(X){let G=new W(X);return await G.init(),G}get address(){return{}}send=async(X,G)=>{await this.connecting,this.client.write(X,(Y)=>{if(Y)console.log("err",Y)})};close=async()=>{this.closed=!0,this.client.destroy()}},o4={rsa_1:1,ecdsa_3:3},tq={sha256_4:4},EK={TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256_49195:49195,TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256_49199:49199},Xo=Object.values(EK),t6={x25519_29:29,secp256r1_23:23},g2=Object.values(t6),u2={named_curve_3:3},r$={rsa_pkcs1_sha256:1025,ecdsa_secp256r1_sha256:1027},Go=[1,64],h2=[{hash:tq.sha256_4,signature:o4.rsa_1},{hash:tq.sha256_4,signature:o4.ecdsa_3}],Zo=()=>{let W=Mq.utils.randomPrivateKey(),X=Mq.getPublicKey(W,!1),G=Buffer.from(W),Y=Buffer.from(X);return{privateKey:G,publicKey:Y}},Vo=({publicKey:W,privateKey:X})=>{let G=Mq.getSharedSecret(X,W);return Buffer.from(G).subarray(1)};function f2(W,X,G){switch(G){case t6.secp256r1_23:return Vo({publicKey:W,privateKey:X});case t6.x25519_29:return Buffer.from(m2.default.scalarMult(X,W));default:throw Error()}}function a$(W,X,G){let Y=Jo(W,X);return Y.update(G),Y.digest()}function XU(W,X,G,Y="sha256"){let J=G,Z=[],V=X;do{V=a$(Y,W,V);let U=a$(Y,W,Buffer.concat([V,X]));Z.push(U),G-=U.length}while(G>0);return Buffer.concat(Z,J)}function p2(W,X,G){let Y=Buffer.concat([Buffer.from("master secret"),X,G]);return XU(W,Y,48)}function c2(W,X){let G=l2("sha256",X),Y="extended master secret";return XU(W,Buffer.concat([Buffer.from("extended master secret"),G]),48)}function Uo(W,X,G,Y,J,Z){let V=Z?Y:J,U=Z?J:Y,Q=Buffer.concat([Buffer.from(W),V,U]);return XU(G,Q,X)}function l2(W,X){return Yo(W).update(X).digest()}function d2(W,X,G,Y=12){let J=l2("sha256",X);return XU(W,Buffer.concat([Buffer.from(G),J]),Y)}function Qo(W,X){return d2(W,X,"client finished")}function No(W,X){return d2(W,X,"server finished")}function qo(W,X,G,Y,J,Z,V="sha256"){let U=Y*2+J*2,Q=W,N=Buffer.concat([G,X]),q=XU(Q,Buffer.concat([Buffer.from("key expansion"),N]),U,V),A=b2.createDecode(q),H=A.readBuffer(Y),I=A.readBuffer(Y),w=A.readBuffer(J),O=A.readBuffer(J),T=Buffer.alloc(Z,0),x=Buffer.alloc(Z,0);return w.copy(T,0),O.copy(x,0),{clientWriteKey:H,serverWriteKey:I,clientNonce:T,serverNonce:x}}var d4={CLIENT:1,SERVER:2},Ho=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}},$K=Wo;u8.set($K);var eq=class{constructor(W,X,G,Y){if(this.sessionType=W,this.certPem=X,this.keyPem=G,X&&G&&Y)this.parseX509(X,G,Y)}localRandom;remoteRandom;cipherSuite;remoteCertificate;remoteKeyPair;localKeyPair;masterSecret;cipher;namedCurve;signatureHashAlgorithm;localCert;localPrivateKey;static createSelfSignedCertificateWithKey=async(W,X)=>{let G=(()=>{switch(W.signature){case o4.rsa_1:return"RSASSA-PKCS1-v1_5";case o4.ecdsa_3:return"ECDSA"}})(),Y=(()=>{switch(W.hash){case tq.sha256_4:return"SHA-256"}})(),J=(()=>{switch(X){case t6.secp256r1_23:return"P-256";case t6.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:Y,namedCurve:J};case"RSASSA-PKCS1-v1_5":return{name:G,hash:Y,publicExponent:new Uint8Array([1,0,1]),modulusLength:2048}}})(),V=await $K.subtle.generateKey(Z,!0,["sign","verify"]),Q=(await Kj.createSelfSigned({serialNumber:ed(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"),N=T9.encode(await $K.subtle.exportKey("pkcs8",V.privateKey),"private key");return{certPem:Q,keyPem:N,signatureHash:W}};encryptPacket(W){let X=W.recordLayerHeader,G=X.protocolVersion.major<<8|X.protocolVersion.minor,Y=this.cipher.encrypt(this.sessionType,W.fragment,{type:X.contentType,version:G,epoch:X.epoch,sequenceNumber:X.sequenceNumber});return W.fragment=Y,W.recordLayerHeader.contentLen=Y.length,W}decryptPacket(W){let X=W.recordLayerHeader,G=X.protocolVersion.major<<8|X.protocolVersion.minor;return this.cipher.decrypt(this.sessionType,W.fragment,{type:X.contentType,version:G,epoch:X.epoch,sequenceNumber:X.sequenceNumber})}verifyData(W){if(this.sessionType===d4.CLIENT)return Qo(this.masterSecret,W);else return No(this.masterSecret,W)}signatureData(W,X){let G=td(X).update(W),Y=this.localPrivateKey.toPEM().toString();return G.sign(Y)}generateKeySignature(W){let X=this.sessionType===d4.CLIENT?this.localRandom:this.remoteRandom,G=this.sessionType===d4.SERVER?this.localRandom:this.remoteRandom,Y=this.valueKeySignature(X.serialize(),G.serialize(),this.localKeyPair.publicKey,this.namedCurve);return this.localPrivateKey.sign(Y,W)}parseX509(W,X,G){let Y=AH.Certificate.fromPEM(Buffer.from(W)),J=AH.PrivateKey.fromPEM(Buffer.from(X));this.localCert=Y.raw,this.localPrivateKey=J,this.signatureHashAlgorithm=G}valueKeySignature(W,X,G,Y){let J=Buffer.from(hY.encode({type:u2.named_curve_3,curve:Y,len:G.length},{type:hY.types.uint8,curve:hY.types.uint16be,len:hY.types.uint8}).slice());return Buffer.concat([W,X,J,G])}},WH=class{srtpProfile;static findMatchingSRTPProfile(W,X){for(let G of X)if(W.includes(G))return G}},GO=(W)=>"0x"+W.toString("hex").replace(/(.)(.)/g,"$1$2 ").split(" ").filter((X)=>X!=null&&X.length>0).join(",0x"),o2=(W)=>Object.entries({...W}).reduce((X,[G,Y])=>{if(typeof Y==="number"||typeof Y==="string")X[G]=Y;if(Buffer.isBuffer(Y))X[G]=GO(Y);return X},{}),F5=class W{constructor(X,G,Y,J,Z,V){this.msg_type=X,this.length=G,this.message_seq=Y,this.fragment_offset=J,this.fragment_length=Z,this.fragment=V}static spec={msg_type:Z7.types.uint8,length:Z7.types.uint24be,message_seq:Z7.types.uint16be,fragment_offset:Z7.types.uint24be,fragment_length:Z7.types.uint24be,fragment:Z7.types.buffer((X)=>X.current.fragment_length)};get summary(){return o2(this)}static createEmpty(){return new W(void 0,void 0,void 0,void 0,void 0,void 0)}static deSerialize(X){return new W(...Object.values(Z7.decode(X,W.spec)))}serialize(){let X=Z7.encode(this,W.spec).slice();return Buffer.from(X)}chunk(X){let G=0,Y=this.fragment.length;if(Y===0)return[new W(this.msg_type,Y,this.message_seq,G,0,this.fragment)];let J=[];if(!X)X=1240;while(G<Y){let Z=Math.min(X,Y-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,Y,this.message_seq,G,V.length,V)),G+=V.length}return J}static assemble(X){if(!X?.length)throw Error("cannot reassemble handshake from empty array");X=X.sort((Y,J)=>Y.fragment_offset-J.fragment_offset);let G=Buffer.alloc(X[0].length);for(let Y of X)Y.fragment.copy(G,Y.fragment_offset);return new W(X[0].msg_type,X[0].length,X[0].message_seq,0,G.length,G)}static findAllFragments(X,G){let Y=X.find((J)=>J.msg_type===G);if(!Y)return[];if(!X?.length)return[];return X.filter((J)=>{return J.msg_type===Y.msg_type&&J.message_seq===Y.message_seq&&J.length===Y.length})}},{uint16be:XH,uint24be:Ao,buffer:i2,array:zo,uint8:iV,string:Io}=n2.types,wo={type:XH,data:i2(XH)},FK=zo(wo,XH,"bytes"),jo=i2(Ao),Ko=iV,Oo=Io(XH),Do={hash:iV,signature:iV},YO={major:iV,minor:iV},PX=class W{constructor(X=Math.floor(Date.now()/1000),G=Co(28)){this.gmt_unix_time=X,this.random_bytes=G}static spec={gmt_unix_time:MX.types.uint32be,random_bytes:MX.types.buffer(28)};static deSerialize(X){return new W(...Object.values(MX.decode(X,W.spec)))}static from(X){return new W(...Object.values(X))}serialize(){let X=MX.encode(this,W.spec).slice();return Buffer.from(X)}},r2=class W{constructor(X,G,Y,J,Z,V,U){this.clientVersion=X,this.random=G,this.sessionId=Y,this.cookie=J,this.cipherSuites=Z,this.compressionMethods=V,this.extensions=U}msgType=1;messageSeq=0;static spec={clientVersion:{major:U9.types.uint8,minor:U9.types.uint8},random:PX.spec,sessionId:U9.types.buffer(U9.types.uint8),cookie:U9.types.buffer(U9.types.uint8),cipherSuites:U9.types.array(U9.types.uint16be,U9.types.uint16be,"bytes"),compressionMethods:U9.types.array(U9.types.uint8,U9.types.uint8,"bytes"),extensions:FK};static createEmpty(){return new W(void 0,void 0,void 0,void 0,void 0,void 0,void 0)}static deSerialize(X){return new W(...Object.values(U9.decode(X,W.spec)))}serialize(){let X=U9.encode(this,W.spec).slice();return Buffer.from(X)}toFragment(){let X=this.serialize();return new F5(this.msgType,X.length,this.messageSeq,0,X.length,X)}},Mo=class W{constructor(X,G,Y,J,Z){this.epoch=X,this.sequenceNumber=G,this.contentType=Y,this.protocolVersion=J,this.contentLen=Z}static spec={epoch:l4.types.uint16be,sequenceNumber:l4.types.uint48be,contentType:l4.types.uint8,protocolVersion:YO,contentLen:l4.types.uint16be};static createEmpty(){return new W(void 0,void 0,void 0,void 0,void 0)}static deSerialize(X){return new W(...Object.values(l4.decode(X,W.spec)))}serialize(){let X=l4.encode(this,W.spec).slice();return Buffer.from(X)}},a2=class W{constructor(X,G){this.recordLayerHeader=X,this.fragment=G}get summary(){return{header:this.recordLayerHeader,fragment:GO(this.fragment)}}static createEmpty(){return new W(void 0,void 0)}static deSerialize(X){if(X.length<13)throw Error("Invalid DTLS record: buffer is too short");let G=X.readUInt8(0),Y=X.readUInt8(1),J=X.readUInt8(2),Z=X.readUInt16BE(3),V=X.slice(5,11).readUIntBE(0,6),U=X.readUInt16BE(11);if(X.length<13+U)throw Error("Invalid DTLS record: fragment length exceeds buffer");let Q=X.slice(13,13+U);return new W({contentType:G,protocolVersion:{major:Y,minor:J},epoch:Z,sequenceNumber:V,contentLen:U},Q)}serialize(){let X=this.fragment.length,G=13+X,Y=Buffer.alloc(G);return Y.writeUInt8(this.recordLayerHeader.contentType,0),Y.writeUInt8(this.recordLayerHeader.protocolVersion.major,1),Y.writeUInt8(this.recordLayerHeader.protocolVersion.minor,2),Y.writeUInt16BE(this.recordLayerHeader.epoch,3),Y.writeUIntBE(this.recordLayerHeader.sequenceNumber,5,6),Y.writeUInt16BE(X,11),this.fragment.copy(Y,13),Y}computeMACHeader(){return new Mo(this.recordLayerHeader.epoch,this.recordLayerHeader.sequenceNumber,this.recordLayerHeader.contentType,this.recordLayerHeader.protocolVersion,this.recordLayerHeader.contentLen).serialize()}},s2=(W)=>(X)=>{return W.lastFlight=X,X.flatMap((G)=>{return G.messageSeq=W.sequenceNumber++,G.toFragment().chunk()})},GU=(W)=>(X,G)=>{return X.map((Y)=>{return new a2({contentType:Y.type,protocolVersion:W.version,epoch:W.epoch,sequenceNumber:G,contentLen:Y.fragment.length},Y.fragment)})},SK=((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})(SK||{}),Po=P1("werift-dtls : packages/dtls/src/flight/flight.ts : warn"),UK=P1("werift-dtls : packages/dtls/src/flight/flight.ts : err"),YU=class W{constructor(X,G,Y,J){this.transport=X,this.dtls=G,this.flight=Y,this.nextFlight=J}state="PREPARING";static RetransmitCount=10;createPacket(X){let G=s2(this.dtls)(X);return this.dtls.bufferHandshakeCache(G,!0,this.flight),GU(this.dtls)(G.map((J)=>({type:22,fragment:J.serialize()})),++this.dtls.recordSequenceNumber)}async transmit(X){let G=0;for(;G<=W.RetransmitCount;G++){if(this.setState("SENDING"),this.send(X).catch((Y)=>{UK("fail to send",UK)}),this.setState("WAITING"),this.nextFlight===void 0){this.setState("FINISHED");break}if(await To(1000*((G+1)/2)),this.dtls.flight>=this.nextFlight){this.setState("FINISHED");break}else Po(this.dtls.sessionId,"retransmit",G,this.dtls.flight)}if(G>W.RetransmitCount)throw UK(this.dtls.sessionId,"retransmit failed",G),Error(`over retransmitCount : ${this.flight} ${this.nextFlight}`)}send=(X)=>Promise.all(X.map((G)=>this.transport.send(G)));setState(X){this.state=X}},Ro=class extends YU{constructor(W,X,G){super(W,X,1,3);this.cipher=G}async exec(W){if(this.dtls.flight===1)throw Error();this.dtls.flight=1;let X=new r2({major:254,minor:253},new PX,Buffer.from([]),Buffer.from([]),Xo,[0],W);this.dtls.version=X.clientVersion,this.cipher.localRandom=PX.from(X.random);let G=this.createPacket([X]),Y=Buffer.concat(G.map((J)=>J.serialize()));await this.transmit([Y])}},Lo=P1("werift-dtls : packages/dtls/src/flight/client/flight3.ts : log"),Bo=class extends YU{constructor(W,X){super(W,X,3,5)}async exec(W){if(this.dtls.flight===3)throw Error();this.dtls.flight=3,this.dtls.handshakeCache=[];let[X]=this.dtls.lastFlight;Lo("dtls version",X.clientVersion),X.cookie=W.cookie,this.dtls.cookie=W.cookie;let G=this.createPacket([X]),Y=Buffer.concat(G.map((J)=>J.serialize()));await this.transmit([Y])}},zH={NULL:0,ECDHE:1},JU={NULL:0,RSA:1,ECDSA:2,PSK:3},ZU={NULL:0,RSA:1,ECDHE_RSA:2,ECDHE_ECDSA:3,PSK:4,ECDHE_PSK:5},VU=class{id=0;name;signType;keyType;toString(){return this.name}};function Eo(){let W=new VU;return W.id=ZU.RSA,W.name="RSA",W.keyType=JU.RSA,W}function $o(){let W=new VU;return W.id=ZU.ECDHE_RSA,W.name="ECDHE_RSA",W.signType=zH.ECDHE,W.keyType=JU.RSA,W}function Fo(){let W=new VU;return W.id=ZU.ECDHE_ECDSA,W.name="ECDHE_ECDSA",W.signType=zH.ECDHE,W.keyType=JU.ECDSA,W}function So(){let W=new VU;return W.id=ZU.PSK,W.name="PSK",W.signType=zH.NULL,W.keyType=JU.PSK,W}function xo(){let W=new VU;return W.id=ZU.ECDHE_PSK,W.name="ECDHE_PSK",W.signType=zH.ECDHE,W.keyType=JU.PSK,W}var yo=P1("werift-dtls : packages/dtls/src/cipher/suites/aead.ts : err"),vo=class extends Ho{keyLength=0;nonceLength=0;ivLength=0;authTagLength=0;nonceImplicitLength=0;nonceExplicitLength=0;clientWriteKey;serverWriteKey;clientNonce;serverNonce;constructor(){super()}get summary(){return o2(this)}init(W,X,G){let Y=qo(W,G,X,this.keyLength,this.ivLength,this.nonceLength,this.hashAlgorithm);this.clientWriteKey=Y.clientWriteKey,this.serverWriteKey=Y.serverWriteKey,this.clientNonce=Y.clientNonce,this.serverNonce=Y.serverNonce}encrypt(W,X,G){let Y=W===d4.CLIENT,J=Y?this.clientNonce:this.serverNonce,Z=Y?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,X.length),Q=ko(this.blockAlgorithm,Z,J,{authTagLength:this.authTagLength});Q.setAAD(U,{plaintextLength:X.length});let N=Q.update(X),q=Q.final(),A=Q.getAuthTag();return Buffer.concat([V,N,q,A])}encodeAdditionalBuffer(W,X){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(X,11),G}decrypt(W,X,G){let Y=W===d4.CLIENT,J=Y?this.serverNonce:this.clientNonce,Z=Y?this.serverWriteKey:this.clientWriteKey;if(!J||!Z)throw Error();X.subarray(0,this.nonceExplicitLength).copy(J,this.nonceImplicitLength);let U=X.subarray(this.nonceExplicitLength,X.length-this.authTagLength),Q=X.subarray(X.length-this.authTagLength),N=this.encodeAdditionalBuffer(G,U.length),q=_o(this.blockAlgorithm,Z,J,{authTagLength:this.authTagLength});q.setAuthTag(Q),q.setAAD(N,{plaintextLength:U.length});let A=q.update(U);try{let H=q.final();return H.length>0?Buffer.concat([A,H]):A}catch(H){throw yo("decrypt failed",H,W,GO(X),G,this.summary),H}}},h8={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},_V={K_LEN:16,N_MIN:12,N_MAX:12,P_MAX:68719476705,A_MAX:9007199254740991,C_MAX:68719476721},yV={K_LEN:32,N_MIN:12,N_MAX:12,P_MAX:68719476705,A_MAX:9007199254740991,C_MAX:68719476721},s$=Eo(),t$=$o(),e$=Fo(),WF=So(),XF=xo();function t2(W){switch(W){case h8.TLS_RSA_WITH_AES_128_GCM_SHA256:return p7(h8.TLS_RSA_WITH_AES_128_GCM_SHA256,"TLS_RSA_WITH_AES_128_GCM_SHA256","aes-128-gcm",s$,_V);case h8.TLS_RSA_WITH_AES_256_GCM_SHA384:return p7(h8.TLS_RSA_WITH_AES_256_GCM_SHA384,"TLS_RSA_WITH_AES_256_GCM_SHA384","aes-256-gcm",s$,yV,"sha384");case h8.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256:return p7(h8.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,"TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256","aes-128-gcm",t$,_V);case h8.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384:return p7(h8.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,"TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384","aes-256-gcm",t$,yV,"sha384");case h8.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256:return p7(h8.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,"TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256","aes-128-gcm",e$,_V);case h8.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384:return p7(h8.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,"TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384","aes-256-gcm",e$,yV,"sha384");case h8.TLS_PSK_WITH_AES_128_GCM_SHA256:return p7(h8.TLS_PSK_WITH_AES_128_GCM_SHA256,"TLS_PSK_WITH_AES_128_GCM_SHA256","aes-128-gcm",WF,_V,"sha256");case h8.TLS_PSK_WITH_AES_256_GCM_SHA384:return p7(h8.TLS_PSK_WITH_AES_256_GCM_SHA384,"TLS_PSK_WITH_AES_256_GCM_SHA384","aes-256-gcm",WF,yV,"sha384");case h8.TLS_ECDHE_PSK_WITH_AES_128_GCM_SHA256:return p7(h8.TLS_ECDHE_PSK_WITH_AES_128_GCM_SHA256,"TLS_ECDHE_PSK_WITH_AES_128_GCM_SHA256","aes-128-gcm",XF,_V,"sha256");case h8.TLS_ECDHE_PSK_WITH_AES_256_GCM_SHA384:return p7(h8.TLS_ECDHE_PSK_WITH_AES_256_GCM_SHA384,"TLS_ECDHE_PSK_WITH_AES_256_GCM_SHA384","aes-256-gcm",XF,yV,"sha384");default:break}return null}function p7(W,X,G,Y,J,Z="sha256"){let V=new vo;return V.id=W,V.name=X,V.blockAlgorithm=G,V.kx=Y,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 WS(W){switch(W){case t6.secp256r1_23:{let{privateKey:X,publicKey:G}=Zo();return{curve:W,privateKey:X,publicKey:G}}case t6.x25519_29:{let X=e2.default.box.keyPair();return{curve:W,privateKey:Buffer.from(X.secretKey.buffer),publicKey:Buffer.from(X.publicKey.buffer)}}default:throw Error()}}var IH=class{static type=23},wH=class W{static type=65281;static spec={type:RX.types.uint16be,data:RX.types.uint8};type=W.type;data=0;constructor(X={}){Object.assign(this,X)}static createEmpty(){return new W}static deSerialize(X){return new W(RX.decode(X,W.spec))}serialize(){let X=RX.encode(this,W.spec).slice();return Buffer.from(X)}get extension(){return{type:this.type,data:this.serialize().slice(2)}}},bY=class W{static type=14;static spec={type:a6.types.uint16be,data:a6.types.buffer(a6.types.uint16be)};type=W.type;data=Buffer.from([]);profiles=[];mki=Buffer.from([0]);constructor(X={}){Object.assign(this,X)}static create(X,G){return new W({profiles:X,mki:G})}static deSerialize(X){let G=new W(a6.decode(X,W.spec)),Y=G.data.readUInt16BE(),J=Array(Y/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(Y+2),G}serialize(){let X=Buffer.alloc(2);X.writeUInt16BE(this.profiles.length*2);let G=Buffer.concat([X,...this.profiles.map((J)=>{let Z=Buffer.alloc(2);return Z.writeUInt16BE(J),Z}),this.mki]);this.data=G;let Y=a6.encode(this,W.spec).slice();return Buffer.from(Y)}static fromData(X){let G=Buffer.alloc(4);return G.writeUInt16BE(W.type),G.writeUInt16BE(X.length,2),W.deSerialize(Buffer.concat([G,X]))}get extension(){return{type:this.type,data:this.serialize().slice(4)}}},GH=class W{constructor(X){this.certificateList=X}msgType=11;messageSeq;static spec={certificateList:LX.types.array(jo,LX.types.uint24be,"bytes")};static createEmpty(){return new W(void 0)}static deSerialize(X){return new W(...Object.values(LX.decode(X,W.spec)))}serialize(){let X=LX.encode(this,W.spec).slice();return Buffer.from(X)}toFragment(){let X=this.serialize();return new F5(this.msgType,X.length,this.messageSeq,0,X.length,X)}},XS=class W{constructor(X=1){this.type=X}static spec={type:lY.types.uint8};static createEmpty(){return new W}static deSerialize(X){return new W(...Object.values(lY.decode(X,W.spec)))}serialize(){let X=lY.encode(this,W.spec).slice();return Buffer.from(X)}},GS=class W{constructor(X,G){this.algorithm=X,this.signature=G}msgType=15;messageSeq;static spec={algorithm:s6.types.uint16be,signature:s6.types.buffer(s6.types.uint16be)};static createEmpty(){return new W(void 0,void 0)}static deSerialize(X){let G=s6.decode(X,W.spec);return new W(...Object.values(G))}serialize(){let X=s6.encode(this,W.spec).slice();return Buffer.from(X)}toFragment(){let X=this.serialize();return new F5(this.msgType,X.length,this.messageSeq,0,X.length,X)}},YS=class W{constructor(X){this.publicKey=X}msgType=16;messageSeq;static spec={publicKey:BX.types.buffer(BX.types.uint8)};static createEmpty(){return new W(void 0)}static deSerialize(X){let G=BX.decode(X,W.spec);return new W(...Object.values(G))}serialize(){let X=BX.encode(this,W.spec).slice();return Buffer.from(X)}toFragment(){let X=this.serialize();return new F5(this.msgType,X.length,this.messageSeq,0,X.length,X)}},xK=class W{constructor(X){this.verifyData=X}msgType=20;messageSeq;static createEmpty(){return new W(void 0)}static deSerialize(X){return new W(X)}serialize(){return this.verifyData}toFragment(){let X=this.serialize();return new F5(this.msgType,X.length,this.messageSeq,0,X.length,X)}},JS=class W{constructor(X,G,Y){this.certificateTypes=X,this.signatures=G,this.authorities=Y}msgType=13;messageSeq;static spec={certificateTypes:V7.types.array(Ko,V7.types.uint8,"bytes"),signatures:V7.types.array(Do,V7.types.uint16be,"bytes"),authorities:V7.types.array(Oo,V7.types.uint16be,"bytes")};static createEmpty(){return new W(void 0,void 0,void 0)}static deSerialize(X){return new W(...Object.values(V7.decode(X,W.spec)))}serialize(){let X=V7.encode(this,W.spec).slice();return Buffer.from(X)}toFragment(){let X=this.serialize();return new F5(this.msgType,X.length,this.messageSeq,0,X.length,X)}},ZS=class W{constructor(X,G,Y,J,Z,V){this.serverVersion=X,this.random=G,this.sessionId=Y,this.cipherSuite=J,this.compressionMethod=Z,this.extensions=V}msgType=2;messageSeq;static spec={serverVersion:YO,random:PX.spec,sessionId:U7.types.buffer(U7.types.uint8),cipherSuite:U7.types.uint16be,compressionMethod:U7.types.uint8};static createEmpty(){return new W(void 0,void 0,void 0,void 0,void 0,void 0)}static deSerialize(X){let G=U7.decode(X,W.spec),Y=new W(...Object.values(G));if(Y.serialize().length<X.length)return new W(...Object.values(U7.decode(X,{...W.spec,extensions:FK})));return Y}serialize(){let X=this.extensions===void 0?U7.encode(this,W.spec).slice():U7.encode(this,{...W.spec,extensions:FK}).slice();return Buffer.from(X)}toFragment(){let X=this.serialize();return new F5(this.msgType,X.length,this.messageSeq,0,X.length,X)}},VS=class W{msgType=14;messageSeq;static spec={};static createEmpty(){return new W}static deSerialize(X){return new W(...Object.values(jH.decode(X,W.spec)))}serialize(){let X=jH.encode(this,W.spec).slice();return Buffer.from(X)}toFragment(){let X=this.serialize();return new F5(this.msgType,X.length,this.messageSeq,0,X.length,X)}};function go(W,X){return Buffer.from(US.encode(W,X).slice())}var QS=class W{constructor(X,G,Y,J,Z,V,U,Q){this.ellipticCurveType=X,this.namedCurve=G,this.publicKeyLength=Y,this.publicKey=J,this.hashAlgorithm=Z,this.signatureAlgorithm=V,this.signatureLength=U,this.signature=Q}msgType=12;messageSeq;static spec={ellipticCurveType:J7.types.uint8,namedCurve:J7.types.uint16be,publicKeyLength:J7.types.uint8,publicKey:J7.types.buffer((X)=>X.current.publicKeyLength),hashAlgorithm:J7.types.uint8,signatureAlgorithm:J7.types.uint8,signatureLength:J7.types.uint16be,signature:J7.types.buffer((X)=>X.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(X){let G=J7.decode(X,W.spec);return new W(...Object.values(G))}serialize(){return go(this,W.spec)}toFragment(){let X=this.serialize();return new F5(this.msgType,X.length,this.messageSeq,0,X.length,X)}},KH=1,UU=7;var uo=(W)=>{switch(W){case KH:case UU:return 16}},ho=(W)=>{switch(W){case KH:return 14;case UU:return 12}},iH0=P1("werift-rtp : packages/rtp/src/codec/av1.ts");var mo={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"},rH0=Object.entries(mo).reduce((W,[X,G])=>{return W[G]=Number(X),W},{});var aH0=Buffer.from([0,0,0,1]);function GF(W,X){let G=Buffer.alloc(X);return W.copy(G),G}function YH(W){return Number.parseInt(W.toString(),10)}function fo(W){let X=W[0];return X>127&&X<192}var kK=4,XW=class W{version=2;padding=!1;count=0;type=0;length=0;constructor(X={}){Object.assign(this,X)}static serialize(X,G,Y,J){let V=new W({type:X,count:G,version:2,length:J}).serialize();return Buffer.concat([V,Y])}serialize(){let X=new aq(8);if(X.set(2,0,this.version),this.padding)X.set(1,2,1);return X.set(5,3,this.count),S8([1,1,2],[X.value,this.type,this.length])}static deSerialize(X){let[G,Y,J]=e9(X,[1,1,2]),Z=b8(G,0,2),V=b8(G,2,1)>0,U=b8(G,3,5);return new W({version:Z,padding:V,count:U,type:Y,length:J})}},YF=class W{static count=4;count=W.count;senderSsrc;mediaSsrc;fir=[];constructor(X={}){Object.assign(this,X)}get length(){return Math.floor(this.serialize().length/4-1)}static deSerialize(X){let[G,Y]=e9(X,[4,4]),J=[];for(let Z=8;Z<X.length;Z+=8)J.push({ssrc:X.readUInt32BE(Z),sequenceNumber:X[Z+4]});return new W({senderSsrc:G,mediaSsrc:Y,fir:J})}serialize(){let X=S8([4,4],[this.senderSsrc,this.mediaSsrc]),G=Buffer.alloc(this.fir.length*8);return this.fir.forEach(({ssrc:Y,sequenceNumber:J},Z)=>{G.writeUInt32BE(Y,Z*8),G[Z*8+4]=J}),Buffer.concat([X,G])}},JH=class W{static count=1;count=W.count;length=2;senderSsrc;mediaSsrc;constructor(X={}){Object.assign(this,X)}static deSerialize(X){let[G,Y]=e9(X,[4,4]);return new W({senderSsrc:G,mediaSsrc:Y})}serialize(){return S8([4,4],[this.senderSsrc,this.mediaSsrc])}},ZH=class W{static count=15;length;count=W.count;senderSsrc;mediaSsrc;uniqueID="REMB";ssrcNum=0;brExp;brMantissa;bitrate;ssrcFeedbacks=[];constructor(X={}){Object.assign(this,X)}static deSerialize(X){let[G,Y,J,Z,V]=e9(X,[4,4,4,1,1]),U=b8(V,0,6),Q=(b8(V,6,2)<<16)+(X[14]<<8)+X[15],N=U>46?18446744073709551615n:BigInt(Q)<<BigInt(U),q=[];for(let A=16;A<X.length;A+=4){let H=X.slice(A).readUIntBE(0,4);q.push(H)}return new W({senderSsrc:G,mediaSsrc:Y,uniqueID:S8([4],[J]).toString(),ssrcNum:Z,brExp:U,brMantissa:Q,ssrcFeedbacks:q,bitrate:N})}serialize(){let X=Buffer.concat([S8([4,4],[this.senderSsrc,this.mediaSsrc]),Buffer.from(this.uniqueID),S8([1],[this.ssrcNum])]),G=new aq(24);G.set(6,0,this.brExp).set(18,6,this.brMantissa);let Y=Buffer.concat(this.ssrcFeedbacks.map((Z)=>S8([4],[Z]))),J=Buffer.concat([X,S8([3],[G.value]),Y]);return this.length=J.length/4,J}},po=P1("werift-rtp: /rtcp/psfb/index"),rV=class W{static type=206;type=W.type;feedback;constructor(X={}){Object.assign(this,X)}serialize(){let X=this.feedback.serialize();return XW.serialize(this.type,this.feedback.count,X,this.feedback.length)}static deSerialize(X,G){let Y;switch(G.count){case YF.count:Y=YF.deSerialize(X);break;case JH.count:Y=JH.deSerialize(X);break;case ZH.count:Y=ZH.deSerialize(X);break;default:po("unknown psfb packet",G.count);break}return new W({feedback:Y})}},aV=class W{ssrc=0;reports=[];static type=201;type=W.type;constructor(X={}){Object.assign(this,X)}serialize(){let X=S8([4],[this.ssrc]);return X=Buffer.concat([X,...this.reports.map((G)=>G.serialize())]),XW.serialize(W.type,this.reports.length,X,Math.floor(X.length/4))}static deSerialize(X,G){let[Y]=e9(X,[4]),J=4,Z=[];for(let V=0;V<G;V++)Z.push(JO.deSerialize(X.slice(J,J+24))),J+=24;return new W({ssrc:Y,reports:Z})}},JO=class W{ssrc;fractionLost;packetsLost;highestSequence;jitter;lsr;dlsr;constructor(X={}){Object.assign(this,X)}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 S8([4,1,3,4,4,4,4],[this.ssrc,this.fractionLost,this.packetsLost,this.highestSequence,this.jitter,this.lsr,this.dlsr])}static deSerialize(X){let[G,Y,J,Z,V,U,Q]=e9(X,[4,1,3,4,4,4,4]);return new W({ssrc:G,fractionLost:Y,packetsLost:J,highestSequence:Z,jitter:V,lsr:U,dlsr:Q})}},NS=205,VH=class W{static count=1;count=W.count;header;senderSsrc;mediaSourceSsrc;lost=[];toJSON(){return{lost:this.lost,senderSsrc:this.senderSsrc,mediaSourceSsrc:this.mediaSourceSsrc}}constructor(X={}){if(Object.assign(this,X),!this.header)this.header=new XW({type:NS,count:this.count,version:2})}static deSerialize(X,G){let[Y,J]=e9(X,[4,4]),Z=[];for(let V=8;V<X.length;V+=4){let[U,Q]=e9(X.subarray(V),[2,2]);Z.push(U);for(let N=0;N<16;N++)if(Q>>N&1)Z.push(U+N+1)}return new W({header:G,senderSsrc:Y,mediaSourceSsrc:J,lost:Z})}serialize(){let X=S8([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(S8([2,2],[J,Z])),J=V,Z=0}),G.push(S8([2,2],[J,Z]))}let Y=Buffer.concat([X,Buffer.concat(G)]);return this.header.length=Y.length/4,Buffer.concat([this.header.serialize(),Y])}},co=P1("werift/rtp/rtcp/rtpfb/twcc"),UH=class W{static count=15;count=W.count;length=2;senderSsrc;mediaSourceSsrc;baseSequenceNumber;packetStatusCount;referenceTime;fbPktCount;packetChunks=[];recvDeltas=[];header;constructor(X={}){if(Object.assign(this,X),!this.header)this.header=new XW({type:205,count:this.count,version:2})}static deSerialize(X,G){let[Y,J,Z,V,U,Q]=e9(X,[4,4,2,2,3,1]),N=[],q=[],A=16;for(let I=0;I<V;){let w=b8(X.slice(A,A+1)[0],0,1),O;switch(w){case 0:{let T=oV.deSerialize(X.slice(A,A+2));O=T;let x=Math.min(V-I,T.runLength);if(T.packetStatus===1||T.packetStatus===2)for(let h=0;h<x;h++)q.push(new uq({type:T.packetStatus}));I+=x}break;case 1:{let T=lo.deSerialize(X.slice(A,A+2));if(O=T,T.symbolSize===0)T.symbolList.forEach((x)=>{if(x===1)q.push(new uq({type:1}))});if(T.symbolSize===1)T.symbolList.forEach((x)=>{if(x===1||x===2)q.push(new uq({type:x}))});I+=T.symbolList.length}break}if(!O)throw Error();A+=2,N.push(O)}let H=A;return q.forEach((I)=>{if(I.type===1)I.deSerialize(X.slice(H,H+1)),H++;if(I.type===2)I.deSerialize(X.slice(H,H+2)),H+=2}),new W({senderSsrc:Y,mediaSourceSsrc:J,baseSequenceNumber:Z,packetStatusCount:V,referenceTime:U,fbPktCount:Q,recvDeltas:q,packetChunks:N,header:G})}serialize(){let X=S8([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())),Y=Buffer.concat(this.recvDeltas.map((Z)=>{try{return Z.serialize()}catch(V){co(V?.message);return}}).filter((Z)=>Z)),J=Buffer.concat([X,G,Y]);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 X=this.baseSequenceNumber-1,G=this.packetChunks.filter((V)=>V instanceof oV).flatMap((V)=>V.results(X)),Y=0,Z=BigInt(this.referenceTime)*64n;for(let V of G){let U=this.recvDeltas[Y];if(!V.received||!U)continue;Z+=BigInt(U.delta)/1000n,V.delta=U.delta,V.receivedAtMs=Number(Z),Y++}return G}},oV=class W{type;packetStatus;runLength;constructor(X={}){Object.assign(this,X),this.type=0}static deSerialize(X){let G=b8(X[0],1,2),Y=(b8(X[0],3,5)<<8)+X[1];return new W({type:0,packetStatus:G,runLength:Y})}serialize(){return new L2(16).set(0).set(this.packetStatus,2).set(this.runLength,13).buffer}results(X){let G=this.packetStatus===1||this.packetStatus===2,Y=[];for(let J=0;J<=this.runLength;++J)Y.push(new oo({sequenceNumber:++X,received:G}));return Y}},lo=class W{type;symbolSize;symbolList=[];constructor(X={}){Object.assign(this,X)}static deSerialize(X){let Y=b8(X[0],1,1),J=[];function Z(V,U){for(let Q=0;Q<V;Q++)U(Q)}switch(Y){case 0:Z(6,(V)=>J.push(b8(X[0],2+V,1))),Z(8,(V)=>J.push(b8(X[1],V,1)));break;case 1:Z(3,(V)=>J.push(b8(X[0],2+V*2,2))),Z(4,(V)=>J.push(b8(X[1],V*2,2)));break;default:Y=(b8(X[0],2,6)<<8)+X[1]}return new W({type:1,symbolSize:Y,symbolList:J})}serialize(){let X=Buffer.alloc(2),G=new L2(16).set(1).set(this.symbolSize),Y=this.symbolSize===0?1:2;return this.symbolList.forEach((J)=>{G.set(J,Y)}),X.writeUInt16BE(G.value),X}},uq=class W{type;delta;constructor(X={}){Object.assign(this,X)}static deSerialize(X){let G,Y;if(X.length===1)G=1,Y=250*X[0];else if(X.length===2)G=2,Y=250*X.readInt16BE();if(G===void 0||Y===void 0)throw Error();return new W({type:G,delta:Y})}deSerialize(X){let G=W.deSerialize(X);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 X=Buffer.alloc(1);return X.writeUInt8(this.delta),X}else if(this.type===2){let X=Buffer.alloc(2);return X.writeInt16BE(this.delta),X}throw Error("errDeltaExceedLimit "+this.delta+" "+this.type)}};var oo=class{sequenceNumber=0;delta=0;received=!1;receivedAtMs=0;constructor(W){Object.assign(this,W)}},no=P1("werift-rtp:packages/rtp/rtcp/rtpfb/index"),mY=class W{static type=NS;type=W.type;feedback;header;constructor(X={}){Object.assign(this,X)}serialize(){return this.feedback.serialize()}static deSerialize(X,G){let Y;switch(G.count){case VH.count:Y=VH.deSerialize(X,G);break;case UH.count:Y=UH.deSerialize(X,G);break;default:no("unknown rtpfb packet",G.count);break}return new W({feedback:Y,header:G})}},QH=class W{static type=202;type=W.type;chunks=[];constructor(X){Object.assign(this,X)}get length(){let X=0;return this.chunks.forEach((G)=>X+=G.length),X}serialize(){let X=Buffer.concat(this.chunks.map((G)=>G.serialize()));while(X.length%4)X=Buffer.concat([X,Buffer.from([0])]);return XW.serialize(this.type,this.chunks.length,X,X.length/4)}static deSerialize(X,G){let Y=[];for(let J=0;J<X.length;){let Z=qS.deSerialize(X.slice(J));Y.push(Z),J+=Z.length}return new W({chunks:Y})}},qS=class W{source;items=[];constructor(X={}){Object.assign(this,X)}get length(){let X=4;return this.items.forEach((G)=>X+=G.length),X+=1,X+=JF(X),X}serialize(){let X=Buffer.concat([S8([4],[this.source]),Buffer.concat(this.items.map((Y)=>Y.serialize()))]);return Buffer.concat([X,Buffer.alloc(JF(X.length))])}static deSerialize(X){let G=X.readUInt32BE(),Y=[];for(let J=4;J<X.length;){if(X[J]===0)break;let V=HS.deSerialize(X.slice(J));Y.push(V),J+=V.length}return new W({source:G,items:Y})}},HS=class W{type;text;constructor(X){Object.assign(this,X)}get length(){return 2+Buffer.from(this.text).length}serialize(){let X=Buffer.from(this.text);return Buffer.concat([S8([1,1],[this.type,X.length]),X])}static deSerialize(X){let G=X[0],Y=X[1],J=X.slice(2,2+Y).toString();return new W({type:G,text:J})}};function JF(W){if(W%4==0)return 0;return 4-W%4}var fY=class W{ssrc=0;senderInfo;reports=[];static type=200;type=W.type;constructor(X){Object.assign(this,X)}toJSON(){return{ssrc:this.ssrc,senderInfo:this.senderInfo.toJSON(),reports:this.reports.map((X)=>X.toJSON())}}serialize(){let X=Buffer.alloc(4);return X.writeUInt32BE(this.ssrc),X=Buffer.concat([X,this.senderInfo.serialize()]),X=Buffer.concat([X,...this.reports.map((G)=>G.serialize())]),XW.serialize(W.type,this.reports.length,X,Math.floor(X.length/4))}static deSerialize(X,G){let Y=X.readUInt32BE(),J=AS.deSerialize(X.subarray(4,24)),Z=24,V=[];for(let Q=0;Q<G;Q++)V.push(JO.deSerialize(X.subarray(Z,Z+24))),Z+=24;return new W({ssrc:Y,senderInfo:J,reports:V})}},AS=class W{ntpTimestamp;rtpTimestamp;packetCount;octetCount;constructor(X={}){Object.assign(this,X)}toJSON(){return{ntpTimestamp:io(this.ntpTimestamp),rtpTimestamp:this.rtpTimestamp}}serialize(){return S8([8,4,4,4],[this.ntpTimestamp,this.rtpTimestamp,this.packetCount,this.octetCount])}static deSerialize(X){let[G,Y,J,Z]=e9(X,[8,4,4,4]);return new W({ntpTimestamp:G,rtpTimestamp:Y,packetCount:J,octetCount:Z})}},io=(W)=>{let[X,G]=e9(S8([8],[W]),[4,4]);return Number(`${X}.${G}`)},ro=P1("werift-rtp:packages/rtp/src/rtcp/rtcp.ts"),ao=class{static deSerialize(W){let X=0,G=[];while(X<W.length){let Y=XW.deSerialize(W.subarray(X,X+kK));X+=kK;let J=W.subarray(X);if(X+=Y.length*4,Y.padding)J=J.subarray(0,J.length-J.subarray(-1)[0]);try{switch(Y.type){case fY.type:G.push(fY.deSerialize(J,Y.count));break;case aV.type:G.push(aV.deSerialize(J,Y.count));break;case QH.type:G.push(QH.deSerialize(J,Y));break;case mY.type:G.push(mY.deSerialize(J,Y));break;case rV.type:G.push(rV.deSerialize(J,Y));break;default:break}}catch(Z){ro("deSerialize RTCP",Z)}}return G}};function so(W){return W.length>=2&&W[1]>=192&&W[1]<=208}var P9={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 to(W,X){return W.map((G)=>{let Y=X[G.id];if(!Y)return{uri:"unknown",value:G.payload};switch(Y){case P9.sdesMid:case P9.sdesRTPStreamID:case P9.repairedRtpStreamId:return{uri:Y,value:Jn(G.payload)};case P9.transportWideCC:return{uri:Y,value:Zn(G.payload)};case P9.absSendTime:return{uri:Y,value:Vn(G.payload)};case P9.audioLevelIndication:return{uri:Y,value:Un(G.payload)};case P9.videoOrientation:return{uri:Y,value:Qn(G.payload)};default:return{uri:Y,value:G.payload}}}).reduce((G,Y)=>{if(Y)G[Y.uri]=Y.value;return G},{})}function eo(W){return Buffer.from(W)}function Wn(W){return Buffer.from(W)}function Xn(W){return Buffer.from(W)}function Gn(W){return S8([2],[W])}function Yn(W){let X=Buffer.alloc(3),G=W>>14n&0x00ffffffn;return X.writeUIntBE(Number(G),0,3),X}function Jn(W){return W.toString()}function Zn(W){return W.readUInt16BE()}function Vn(W){return e9(W,[3])[0]}function Un(W){let X=new lV(W);return{v:X.readBits(1)===1,level:X.readBits(7)}}function Qn(W){let X=new lV(W);return X.readBits(4),{c:X.readBits(1),f:X.readBits(1),r1:X.readBits(1),r0:X.readBits(1)}}var Nn=P1("packages/rtp/src/rtp/red/packet.ts"),zS=class W{header;blocks=[];static deSerialize(X){let G=X instanceof ArrayBuffer?Buffer.from(X):X,Y=new W,J=0;return[Y.header,J]=ZF.deSerialize(G),Y.header.fields.forEach(({blockLength:Z,timestampOffset:V,blockPT:U})=>{if(Z&&V){let Q=G.subarray(J,J+Z);Y.blocks.push({block:Q,blockPT:U,timestampOffset:V}),J+=Z}else{let Q=G.subarray(J);Y.blocks.push({block:Q,blockPT:U})}}),Y}serialize(){this.header=new ZF;for(let{timestampOffset:G,blockPT:Y,block:J}of this.blocks)if(G)this.header.fields.push({fBit:1,blockPT:Y,blockLength:J.length,timestampOffset:G});else this.header.fields.push({fBit:0,blockPT:Y});let X=this.header.serialize();for(let{block:G}of this.blocks)X=Buffer.concat([X,G]);return X}},ZF=class W{fields=[];static deSerialize(X){let G=0,Y=new W;for(;;){let J={};Y.fields.push(J);let Z=new lV(X.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[Y,G]}serialize(){let X=Buffer.alloc(0);for(let G of this.fields)try{if(G.timestampOffset&&G.blockLength){let Y=new lV(Buffer.alloc(4)).writeBits(1,G.fBit).writeBits(7,G.blockPT).writeBits(14,G.timestampOffset).writeBits(10,G.blockLength);X=Buffer.concat([X,Y.uint8Array])}else{let Y=new lV(Buffer.alloc(1)).writeBits(1,0).writeBits(7,G.blockPT);X=Buffer.concat([X,Y.uint8Array])}}catch(Y){Nn(Y?.message)}return X}},qn=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 zS,X=this.cache.slice(-(this.distance+1)),G=X.pop();if(!G)return W;return X.forEach((Y)=>{let J=uY(G.timestamp,-Y.timestamp);if(J>Hn)return;W.blocks.push({block:Y.block,blockPT:Y.blockPT,timestampOffset:J})}),W.blocks.push({block:G.block,blockPT:G.blockPT}),W}},Hn=16383,An=class{size=150;sequenceNumbers=[];push(W,X){let G=[];return W.blocks.forEach(({blockPT:J,timestampOffset:Z,block:V},U)=>{let Q=R9(X.header.sequenceNumber,-(W.blocks.length-(U+1)));if(Z)G.push(new WW(new e6({timestamp:uY(X.header.timestamp,-Z),payloadType:J,ssrc:X.header.ssrc,sequenceNumber:Q,marker:!0}),V));else G.push(new WW(new e6({timestamp:X.header.timestamp,payloadType:J,ssrc:X.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}})}},OX={OneByte:48862,TwoByte:4096},VF=2,UF=4,QF=8,NF=12,qF=4,e6=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=OX.OneByte;extensionLength;extensions=[];constructor(X={}){Object.assign(this,X)}static deSerialize(X){let G=new W,Y=0,J=X[Y++];G.version=b8(J,0,2),G.padding=b8(J,2)>0,G.extension=b8(J,3)>0,G.csrcLength=b8(J,4,4),G.csrc=[...Array(G.csrcLength)].map(()=>{let V=X.readUInt32BE(Y);return Y+=4,V}),Y+=NF-1;let Z=X[1];G.marker=b8(Z,0)>0,G.payloadType=b8(Z,1,7),G.sequenceNumber=X.readUInt16BE(VF),G.timestamp=X.readUInt32BE(UF),G.ssrc=X.readUInt32BE(QF);for(let V=0;V<G.csrc.length;V++){let U=NF+V*qF;G.csrc[V]=X.subarray(U).readUInt32BE()}if(G.extension){G.extensionProfile=X.subarray(Y).readUInt16BE(),Y+=2;let V=X.subarray(Y).readUInt16BE()*4;switch(G.extensionLength=V,Y+=2,G.extensionProfile){case OX.OneByte:{let U=Y+V;while(Y<U){if(X[Y]===0){Y++;continue}let Q=X[Y]>>4,N=(X[Y]&(X[Y]^240))+1;if(Y++,Q===15)break;let q={id:Q,payload:X.subarray(Y,Y+N)};G.extensions=[...G.extensions,q],Y+=N}}break;case OX.TwoByte:{let U=Y+V;while(Y<U){if(X[Y]===0){Y++;continue}let Q=X[Y];Y++;let N=X[Y];Y++;let q={id:Q,payload:X.subarray(Y,Y+N)};G.extensions=[...G.extensions,q],Y+=N}}break;default:{let U={id:0,payload:X.subarray(Y,Y+V)};G.extensions=[...G.extensions,U],Y+=G.extensions[0].payload.length}break}}if(G.payloadOffset=Y,G.padding)G.paddingSize=X[X.length-1];return G}get serializeSize(){let{csrc:X,extensionProfile:G,extensions:Y}=this,J=12+X.length*qF;if(Y.length>0||this.extension===!0){let Z=4;switch(G){case OX.OneByte:for(let V of Y)Z+=1+V.payload.length;break;case OX.TwoByte:for(let V of Y)Z+=2+V.payload.length;break;default:Z+=Y[0].payload.length}J+=Math.floor((Z+3)/4)*4}return J}serialize(X){let G=Buffer.alloc(X),Y=0,J=new aq(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,Y++);let Z=new aq(8);if(this.marker)Z.set(1,0,1);Z.set(7,1,this.payloadType),G.writeUInt8(Z.value,Y++),G.writeUInt16BE(this.sequenceNumber,VF),Y+=2,G.writeUInt32BE(this.timestamp,UF),Y+=4,G.writeUInt32BE(this.ssrc,QF),Y+=4;for(let V of this.csrc)G.writeUInt32BE(V,Y),Y+=4;if(this.extension){let V=Y;G.writeUInt16BE(this.extensionProfile,Y),Y+=4;let U=Y;switch(this.extensionProfile){case OX.OneByte:for(let q of this.extensions)G.writeUInt8(q.id<<4|q.payload.length-1,Y++),q.payload.copy(G,Y),Y+=q.payload.length;break;case OX.TwoByte:for(let q of this.extensions)G.writeUInt8(q.id,Y++),G.writeUInt8(q.payload.length,Y++),q.payload.copy(G,Y),Y+=q.payload.length;break;default:{let q=this.extensions[0].payload.length;if(q%4!=0)throw Error();this.extensions[0].payload.copy(G,Y),Y+=q}}let Q=Y-U,N=Math.trunc((Q+3)/4)*4;G.writeUInt16BE(Math.trunc(N/4),V+2);for(let q=0;q<N-Q;q++)G.writeUInt8(0,Y),Y++}return this.payloadOffset=Y,G}},WW=class W{constructor(X,G){this.header=X,this.payload=G}get serializeSize(){return this.header.serializeSize+this.payload.length}clone(){return new W(new e6({...this.header}),this.payload)}serialize(){let X=this.header.serialize(this.header.serializeSize+this.payload.length),{payloadOffset:G}=this.header;if(this.payload.copy(X,G),this.header.padding){let Y=Buffer.alloc(this.header.paddingSize);Y.writeUInt8(this.header.paddingSize,this.header.paddingSize-1),X=Buffer.concat([X,Y])}return X}static deSerialize(X){let G=e6.deSerialize(X);return new W(G,X.subarray(G.payloadOffset,X.length-G.paddingSize))}clear(){this.payload=null}};function zn(W,X,G){return new WW(new e6({payloadType:X,marker:W.header.marker,sequenceNumber:X8.Unpack("!H",W.payload.subarray(0,2))[0],timestamp:W.header.timestamp,ssrc:G}),W.payload.subarray(2))}function In(W,X,G,Y){return new WW(new e6({payloadType:X,marker:W.header.marker,sequenceNumber:G,timestamp:W.header.timestamp,ssrc:Y,csrc:W.header.csrc,extensions:W.header.extensions}),Buffer.concat([Buffer.from(X8.Pack("!H",[W.header.sequenceNumber])),W.payload]))}var IS=class{constructor(W,X,G,Y){this.srtpSessionKey=W,this.srtpSessionSalt=X,this.srtcpSessionKey=G,this.srtcpSessionSalt=Y}encryptRtp(W,X,G){return Buffer.from([])}decryptRtp(W,X,G){return[]}encryptRTCP(W,X){return Buffer.from([])}decryptRTCP(W){return[]}},pY=class extends Error{constructor(W){super(W);this.name="SrtpAuthenticationError"}},IF=12,jn=8;function ZO(W,X,G="Failed to authenticate SRTP packet"){let Y=W.length-X;sV(W.length>=IF+X,G);let J=jS(()=>e6.deSerialize(W.subarray(0,Y)),G);return J.paddingSize=0,sV(J.payloadOffset>=IF&&J.payloadOffset<=Y,G),J}function wS(W,X,G,Y="Failed to authenticate SRTCP packet"){return sV(W.length>=jn+X+G,Y),jS(()=>XW.deSerialize(W.subarray(0,kK)),Y)}function sV(W,X){if(!W)throw new pY(X)}function jS(W,X){try{return W()}catch{throw new pY(X)}}function KS(W,X,G="Failed to authenticate SRTP packet"){if(!W.padding)return W.paddingSize=0,W;sV(X.length>W.payloadOffset,G);let Y=X[X.length-1];return sV(Y>0&&Y<=X.length-W.payloadOffset,G),W.paddingSize=Y,W}var Kn=class extends IS{constructor(W,X,G,Y,J,Z){super(W,X,G,Y);this.srtpSessionAuthTag=J,this.srtcpSessionAuthTag=Z}authTagLength=10;encryptRtp(W,X,G){let Y=W.serialize(W.serializeSize),J=this.generateCounter(W.sequenceNumber,G,W.ssrc,this.srtpSessionSalt),V=HF("aes-128-ctr",this.srtpSessionKey,J).update(X),U=this.generateSrtpAuthTag(G,Y,V);return Buffer.concat([Y,V,U])}decryptRtp(W,X,G=ZO(W,this.authTagLength)){let Y=W.length-this.authTagLength,J=W.subarray(0,Y),Z=W.subarray(Y),V=this.generateSrtpAuthTag(X,J.subarray(0,G.payloadOffset),J.subarray(G.payloadOffset));jF(Z,V,"Failed to authenticate SRTP packet");let U=this.generateCounter(G.sequenceNumber,X,G.ssrc,this.srtpSessionSalt),Q=AF("aes-128-ctr",this.srtpSessionKey,U),N=J.subarray(G.payloadOffset),q=Q.update(N),A=Buffer.concat([J.subarray(0,G.payloadOffset),q]);return[A,KS(G,A,"Failed to authenticate SRTP packet")]}encryptRTCP(W,X){let G=Buffer.from(W),Y=G.readUInt32BE(4),J=this.generateCounter(X&65535,X>>16,Y,this.srtcpSessionSalt);HF("aes-128-ctr",this.srtcpSessionKey,J).update(G.slice(8)).copy(G,8),G=Buffer.concat([G,Buffer.alloc(4)]),G.writeUInt32BE(X,G.length-4),G[G.length-4]|=128;let U=this.generateSrtcpAuthTag(G);return G=Buffer.concat([G,U]),G}decryptRTCP(W){let X=wS(W,this.authTagLength,wF),G=W.length-(this.authTagLength+wF),Y=W.subarray(0,W.length-this.authTagLength),J=W.subarray(W.length-this.authTagLength),Z=this.generateSrtcpAuthTag(Y);jF(J,Z,"Failed to authenticate SRTCP packet");let V=Buffer.from(W).slice(0,G);if(W[G]>>>7===0)return[V,X];let Q=W.readUInt32BE(G);Q&=2147483647;let N=W.readUInt32BE(4),q=this.generateCounter(Q&65535,Q>>16,N,this.srtcpSessionSalt);return AF("aes-128-ctr",this.srtcpSessionKey,q).update(V.subarray(8)).copy(V,8),[V,X]}generateSrtcpAuthTag(W){return zF("sha1",this.srtcpSessionAuthTag).update(W).digest().slice(0,10)}generateCounter(W,X,G,Y){let J=Buffer.alloc(16);J.writeUInt32BE(G,4),J.writeUInt32BE(X,8),J.writeUInt32BE(Number(BigInt(W)<<16n),12);for(let Z=0;Z<Y.length;Z++)J[Z]^=Y[Z];return J}generateSrtpAuthTag(W,...X){let G=zF("sha1",this.srtpSessionAuthTag),Y=Buffer.alloc(4);Y.writeUInt32BE(W);for(let J of X)G.update(J);return G.update(Y).digest().subarray(0,10)}},wF=4;function jF(W,X,G){if(W.length!==X.length||!wn(W,X))throw new pY(G)}var On=class extends IS{aeadAuthTagLen=16;rtpIvWriter=gq([2,4,4,2],!0);rtcpIvWriter=gq([2,4,2,4],!0);aadWriter=gq([4],!0);constructor(W,X,G,Y){super(W,X,G,Y)}encryptRtp(W,X,G){let Y=W.serialize(W.serializeSize),J=this.rtpInitializationVector(W,G),Z=KF("aes-128-gcm",this.srtpSessionKey,J);Z.setAAD(Y);let V=Z.update(X);Z.final();let U=Z.getAuthTag();return Buffer.concat([Y,V,U])}decryptRtp(W,X,G=ZO(W,this.aeadAuthTagLen)){let Y=W.subarray(0,G.payloadOffset),J=W.length-this.aeadAuthTagLen,Z=W.subarray(J),V=Buffer.from([]);V=GF(V,W.length-this.aeadAuthTagLen),Y.copy(V);let U=this.rtpInitializationVector(G,X),Q=W.slice(G.payloadOffset,J),N=OF("aes-128-gcm",this.srtpSessionKey,U);N.setAAD(Y),N.setAuthTag(Z);let q=N.update(Q);return CF(N,"SRTP"),q.copy(V,G.payloadOffset),[V,KS(G,V,"Failed to authenticate SRTP packet")]}encryptRTCP(W,X){let G=W.readUInt32BE(4),Y=W.length+this.aeadAuthTagLen,J=Buffer.from([]);J=GF(J,Y+NK),W.slice(0,8).copy(J);let Z=this.rtcpInitializationVector(G,X),V=this.rtcpAdditionalAuthenticatedData(W,X),U=KF("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,Y),J}decryptRTCP(W){let X=wS(W,this.aeadAuthTagLen,NK),G=W.length-NK,Y=G-this.aeadAuthTagLen,J=W.readUInt32BE(4),Z=W.readUInt32BE(G),V=Z>>>31===1,U=Z&~(DF<<24),Q=this.rtcpInitializationVector(J,U),N=V?Buffer.concat([W.subarray(0,8),W.subarray(G)]):Buffer.concat([W.subarray(0,Y),W.subarray(G)]),q=V?W.slice(8,Y):Buffer.alloc(0),A=V?Buffer.alloc(Y):Buffer.from(W.subarray(0,Y));if(V)W.slice(0,8).copy(A);let H=OF("aes-128-gcm",this.srtcpSessionKey,Q);H.setAAD(N),H.setAuthTag(W.subarray(Y,G));let I=H.update(q);if(CF(H,"SRTCP"),V)I.copy(A,8);return[A,X]}rtpInitializationVector(W,X){let G=this.rtpIvWriter([0,W.ssrc,X,W.sequenceNumber]);for(let Y=0;Y<G.length;Y++)G[Y]^=this.srtpSessionSalt[Y];return G}rtcpInitializationVector(W,X){let G=this.rtcpIvWriter([0,W,0,X]);for(let Y=0;Y<G.length;Y++)G[Y]^=this.srtcpSessionSalt[Y];return G}rtcpAdditionalAuthenticatedData(W,X){let G=Buffer.concat([W.subarray(0,8),this.aadWriter([X])]);return G[8]|=DF,G}},NK=4,DF=128;function CF(W,X){try{W.final()}catch{throw new pY(`Failed to authenticate ${X} packet`)}}var OS=class{constructor(W,X,G){this.masterKey=W,this.masterSalt=X,this.profile=G;{let Y=14-X.length;if(Y>0)this.masterSalt=Buffer.concat([X,Buffer.alloc(Y)])}switch(this.srtpSessionKey=this.generateSessionKey(0),this.srtpSessionSalt=this.generateSessionSalt(2),this.srtpSessionAuthTag=this.generateSessionAuthTag(1),this.srtpSessionAuth=QK("sha1",this.srtpSessionAuthTag),this.srtcpSessionKey=this.generateSessionKey(3),this.srtcpSessionSalt=this.generateSessionSalt(5),this.srtcpSessionAuthTag=this.generateSessionAuthTag(4),this.srtcpSessionAuth=QK("sha1",this.srtcpSessionAuthTag),G){case KH:this.cipher=new Kn(this.srtpSessionKey,this.srtpSessionSalt,this.srtcpSessionKey,this.srtcpSessionSalt,this.srtpSessionAuthTag,this.srtcpSessionAuthTag);break;case UU:this.cipher=new On(this.srtpSessionKey,this.srtpSessionSalt,this.srtcpSessionKey,this.srtcpSessionSalt);break}}srtpSSRCStates={};srtpSessionKey;srtpSessionSalt;srtpSessionAuthTag;srtpSessionAuth;srtcpSSRCStates={};srtcpSessionKey;srtcpSessionSalt;srtcpSessionAuthTag;srtcpSessionAuth;cipher;generateSessionKey(W){let X=Buffer.from(this.masterSalt),G=Buffer.from([W,0,0,0,0,0,0]);for(let J=G.length-1,Z=X.length-1;J>=0;J--,Z--)X[Z]=X[Z]^G[J];X=Buffer.concat([X,Buffer.from([0,0])]);let Y=new hq.default.AES(this.masterKey);return Buffer.from(Y.encrypt(X))}generateSessionSalt(W){let X=Buffer.from(this.masterSalt),G=Buffer.from([W,0,0,0,0,0,0]);for(let J=G.length-1,Z=X.length-1;J>=0;J--,Z--)X[Z]=X[Z]^G[J];X=Buffer.concat([X,Buffer.from([0,0])]);let Y=new hq.default.AES(this.masterKey);return X=Buffer.from(Y.encrypt(X)),X.subarray(0,14)}generateSessionAuthTag(W){let X=Buffer.from(this.masterSalt),G=Buffer.from([W,0,0,0,0,0,0]);for(let V=G.length-1,U=X.length-1;V>=0;V--,U--)X[U]=X[U]^G[V];let Y=Buffer.concat([X,Buffer.from([0,0])]),J=Buffer.concat([X,Buffer.from([0,1])]),Z=new hq.default.AES(this.masterKey);return Y=Buffer.from(Z.encrypt(Y)),J=Buffer.from(Z.encrypt(J)),Buffer.concat([Y,J.subarray(0,4)])}getSrtpSsrcState(W){let X=this.srtpSSRCStates[W];if(X)return X;return X={ssrc:W,rolloverCounter:0,lastSequenceNumber:0},this.srtpSSRCStates[W]=X,X}getSrtcpSsrcState(W){let X=this.srtcpSSRCStates[W];if(X)return X;return X={srtcpIndex:0,ssrc:W},this.srtcpSSRCStates[W]=X,X}updateRolloverCount(W,X){if(!X.rolloverHasProcessed)X.rolloverHasProcessed=!0;else if(W===0){if(X.lastSequenceNumber>vV)X.rolloverCounter++}else if(X.lastSequenceNumber<vV&&W>TF-vV){if(X.rolloverCounter>0)X.rolloverCounter--}else if(W<vV&&X.lastSequenceNumber>TF-vV)X.rolloverCounter++;X.lastSequenceNumber=W}generateSrtpAuthTag(W,X){this.srtpSessionAuth=QK("sha1",this.srtpSessionAuthTag);let G=Buffer.alloc(4);return G.writeUInt32BE(X),this.srtpSessionAuth.update(W).update(G).digest().slice(0,10)}index(W){let X=this.srtcpSSRCStates[W];if(!X)return 0;return X.srtcpIndex}setIndex(W,X){let G=this.getSrtcpSsrcState(W);G.srtcpIndex=X%2147483647}},vV=100,TF=65535,Dn=class extends OS{constructor(W,X,G){super(W,X,G)}encryptRTCP(W){let X=W.readUInt32BE(4),G=this.getSrtcpSsrcState(X);if(G.srtcpIndex++,G.srtcpIndex>>Cn)G.srtcpIndex=0;return this.cipher.encryptRTCP(W,G.srtcpIndex)}decryptRTCP(W){return this.cipher.decryptRTCP(W)}},Cn=2147483647,DS=class{constructor(W){this.ContextCls=W}localContext;remoteContext;onData;start(W,X,G,Y,J){this.localContext=new this.ContextCls(W,X,J),this.remoteContext=new this.ContextCls(G,Y,J)}},Tn=class extends DS{constructor(W){super(Dn);this.config=W,this.start(W.keys.localMasterKey,W.keys.localMasterSalt,W.keys.remoteMasterKey,W.keys.remoteMasterSalt,W.profile)}decrypt=(W)=>{let[X]=this.remoteContext.decryptRTCP(W);return X};encrypt(W){return this.localContext.encryptRTCP(W)}},Mn=class extends OS{constructor(W,X,G){super(W,X,G)}encryptRtp(W,X){let G=this.getSrtpSsrcState(X.ssrc);return this.updateRolloverCount(X.sequenceNumber,G),this.cipher.encryptRtp(X,W,G.rolloverCounter)}decryptRtp(W){let X=ZO(W,this.rtpAuthTagLength),G=this.srtpSSRCStates[X.ssrc],Y=G?{...G}:{ssrc:X.ssrc,rolloverCounter:0,lastSequenceNumber:0};this.updateRolloverCount(X.sequenceNumber,Y);let J=this.cipher.decryptRtp(W,Y.rolloverCounter,X);if(G)Object.assign(G,Y);else this.srtpSSRCStates[X.ssrc]=Y;return J}get rtpAuthTagLength(){return this.profile===UU?16:10}},Pn=class extends DS{constructor(W){super(Mn);this.config=W,this.start(W.keys.localMasterKey,W.keys.localMasterSalt,W.keys.remoteMasterKey,W.keys.remoteMasterSalt,W.profile)}decrypt=(W)=>{let[X]=this.remoteContext.decryptRtp(W);return X};encrypt(W,X){return this.localContext.encryptRtp(W,X)}},XA0=class{constructor(W){this.props=W}sequenceNumber=R2();timestamp=PK();create(W){this.sequenceNumber=R9(this.sequenceNumber,1);let X=this.props.between*this.props.clockRate/1000;this.timestamp=uY(this.timestamp,X);let G=new e6({sequenceNumber:this.sequenceNumber,timestamp:Number(this.timestamp),payloadType:96,extension:!0,marker:!1,padding:!1});return new WW(G,W)}},b9=P1("werift-dtls : packages/dtls/src/flight/client/flight5.ts : log"),Rn=class extends YU{constructor(W,X,G,Y){super(W,X,5,7);this.cipher=G,this.srtp=Y}handleHandshake(W){this.dtls.bufferHandshakeCache([W],!1,4);let X=(()=>{switch(W.msg_type){case 2:return ZS.deSerialize(W.fragment);case 11:return GH.deSerialize(W.fragment);case 12:return QS.deSerialize(W.fragment);case 13:return JS.deSerialize(W.fragment);case 14:return VS.deSerialize(W.fragment)}})();if(X)dY[X.msgType]({dtls:this.dtls,cipher:this.cipher,srtp:this.srtp})(X)}async exec(){if(this.dtls.flight===5){b9(this.dtls.sessionId,"flight5 twice"),this.send(this.dtls.lastMessage);return}this.dtls.flight=5;let W=this.dtls.requestedCertificateTypes.length>0;b9(this.dtls.sessionId,"send flight5",W);let X=[W&&this.sendCertificate(),this.sendClientKeyExchange(),W&&this.sendCertificateVerify(),this.sendChangeCipherSpec(),this.sendFinished()].filter((G)=>G);this.dtls.lastMessage=X,await this.transmit(X)}sendCertificate(){let W=new GH([Buffer.from(this.cipher.localCert)]),X=this.createPacket([W]);return Buffer.concat(X.map((Y)=>Y.serialize()))}sendClientKeyExchange(){if(!this.cipher.localKeyPair)throw Error();let W=new YS(this.cipher.localKeyPair.publicKey),X=this.createPacket([W]),G=Buffer.concat(X.map((U)=>U.serialize())),Y=this.cipher.localKeyPair,J=this.cipher.remoteKeyPair;if(!J.publicKey)throw Error("not exist");let Z=f2(J.publicKey,Y.privateKey,Y.curve);b9(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?c2(Z,V):p2(Z,this.cipher.localRandom.serialize(),this.cipher.remoteRandom.serialize()),this.cipher.cipher=t2(this.cipher.cipherSuite),this.cipher.cipher.init(this.cipher.masterSecret,this.cipher.remoteRandom.serialize(),this.cipher.localRandom.serialize()),b9(this.dtls.sessionId,"cipher",this.cipher.cipher.summary),G}sendCertificateVerify(){let W=Buffer.concat(this.dtls.sortedHandshakeCache.map((V)=>V.serialize())),X=this.cipher.signatureData(W,"sha256"),G=(()=>{switch(this.cipher.signatureHashAlgorithm?.signature){case o4.ecdsa_3:return r$.ecdsa_secp256r1_sha256;case o4.rsa_1:return r$.rsa_pkcs1_sha256}})();if(!G)throw Error();b9(this.dtls.sessionId,"signatureScheme",this.cipher.signatureHashAlgorithm?.signature,G);let Y=new GS(G,X),J=this.createPacket([Y]);return Buffer.concat(J.map((V)=>V.serialize()))}sendChangeCipherSpec(){let W=XS.createEmpty().serialize(),X=GU(this.dtls)([{type:20,fragment:W}],++this.dtls.recordSequenceNumber);return Buffer.concat(X.map((Y)=>Y.serialize()))}sendFinished(){let W=Buffer.concat(this.dtls.sortedHandshakeCache.map((Z)=>Z.serialize())),X=this.cipher.verifyData(W),G=new xK(X);this.dtls.epoch=1;let[Y]=this.createPacket([G]);this.dtls.recordSequenceNumber=0;let J=this.cipher.encryptPacket(Y).serialize();return b9(this.dtls.sessionId,"finished",this.cipher.cipher.summary),J}},dY={};dY[2]=({cipher:W,srtp:X,dtls:G})=>(Y)=>{if(b9(G.sessionId,"serverHello",Y.cipherSuite),W.remoteRandom=PX.from(Y.random),W.cipherSuite=Y.cipherSuite,b9(G.sessionId,"selected cipherSuite",W.cipherSuite),Y.extensions)Y.extensions.forEach((J)=>{switch(J.type){case bY.type:{let Z=bY.fromData(J.data),V=WH.findMatchingSRTPProfile(Z.profiles,G.options.srtpProfiles||[]);if(b9(G.sessionId,"selected srtp profile",V),V==null)return;X.srtpProfile=V}break;case IH.type:G.remoteExtendedMasterSecret=!0;break;case wH.type:b9(G.sessionId,"RenegotiationIndication");break}})};dY[11]=({cipher:W,dtls:X})=>(G)=>{b9(X.sessionId,"handshake certificate",G),W.remoteCertificate=G.certificateList[0]};dY[12]=({cipher:W,dtls:X})=>(G)=>{if(!W.localRandom||!W.remoteRandom)throw Error();b9(X.sessionId,"ServerKeyExchange",G),b9(X.sessionId,"selected curve",G.namedCurve),W.remoteKeyPair={curve:G.namedCurve,publicKey:G.publicKey},W.localKeyPair=WS(G.namedCurve)};dY[13]=({dtls:W})=>(X)=>{b9(W.sessionId,"certificate_request",X),W.requestedCertificateTypes=X.certificateTypes,W.requestedSignatureAlgorithms=X.signatures};dY[14]=({dtls:W})=>(X)=>{b9(W.sessionId,"server_hello_done",X)};var CS=class W{constructor(X,G){this.serverVersion=X,this.cookie=G}msgType=3;messageSeq;static spec={serverVersion:YO,cookie:EX.types.buffer(EX.types.uint8)};static createEmpty(){return new W(void 0,void 0)}static deSerialize(X){return new W(...Object.values(EX.decode(X,W.spec)))}serialize(){let X=EX.encode(this,W.spec).slice();return Buffer.from(X)}get version(){return{major:255-this.serverVersion.major,minor:255-this.serverVersion.minor}}toFragment(){let X=this.serialize();return new F5(this.msgType,X.length,this.messageSeq,0,X.length,X)}},Bn=P1("werift-dtls : packages/dtls/src/context/dtls.ts : log"),MF=class{constructor(W,X){this.options=W,this.sessionType=X}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],[X])=>Number(W)-Number(X)).flatMap(([,{data:W}])=>W.sort((X,G)=>X.message_seq-G.message_seq))}checkHandshakesExist=(W)=>!W.find((X)=>this.sortedHandshakeCache.find((G)=>G.msg_type===X)==null);bufferHandshakeCache(W,X,G){if(!this.handshakeCache[G])this.handshakeCache[G]={data:[],isLocal:X,flight:G};let Y=W.filter((J)=>{let Z=this.handshakeCache[G].data.find((V)=>V.msg_type===J.msg_type);if(Z)return Bn(this.sessionId,"exist",Z.summary,X,G),!1;return!0});this.handshakeCache[G].data=[...this.handshakeCache[G].data,...Y]}},En=class{constructor(W){this.socket=W}send=(W)=>{return this.socket.send(W)}},_K=class W{static type=10;static spec={type:o7.types.uint16be,data:o7.types.array(o7.types.uint16be,o7.types.uint16be,"bytes")};type=W.type;data=[];constructor(X={}){Object.assign(this,X)}static createEmpty(){return new W}static fromData(X){return new W({type:W.type,data:o7.decode(X,W.spec.data)})}static deSerialize(X){return new W(o7.decode(X,W.spec))}serialize(){return Buffer.from(o7.encode(this,W.spec).slice())}get extension(){return{type:this.type,data:this.serialize().slice(2)}}},yK=class W{static type=13;static spec={type:l7.types.uint16be,data:l7.types.array({hash:l7.types.uint8,signature:l7.types.uint8},l7.types.uint16be,"bytes")};type=W.type;data=[];constructor(X={}){Object.assign(this,X)}static createEmpty(){return new W}static deSerialize(X){return new W(l7.decode(X,W.spec))}serialize(){let X=l7.encode(this,W.spec).slice();return Buffer.from(X)}static fromData(X){let G=Buffer.alloc(2);return G.writeUInt16BE(W.type),W.deSerialize(Buffer.concat([G,X]))}get extension(){return{type:this.type,data:this.serialize().slice(2)}}},PF=class W{constructor(X,G){this.level=X,this.description=G}static spec={level:$X.types.uint8,description:$X.types.uint8};static deSerialize(X){return new W(...Object.values($X.decode(X,W.spec)))}serialize(){let X=$X.encode(this,W.spec).slice();return Buffer.from(X)}},RF=P1("werift-dtls : packages/dtls/record/receive.ts : log"),qK=P1("werift-dtls : packages/dtls/record/receive.ts : err"),$n=(W)=>{let X=0,G=[];while(W.length>X){let Y=W.readUInt16BE(X+11);if(W.length<X+(12+Y))break;let J=a2.deSerialize(W.subarray(X));G.push(J),X+=13+Y}return G},Fn=(W,X)=>(G)=>{switch(G.recordLayerHeader.contentType){case 20:return RF(W.sessionId,"change cipher spec"),[{type:20,data:void 0}];case 22:{let J=G.fragment;try{if(G.recordLayerHeader.epoch>0)RF(W.sessionId,"decrypt handshake"),J=X.decryptPacket(G)}catch(Z){throw qK(W.sessionId,"decrypt failed",Z),Z}try{let Z=0,V=[];while(J.length>Z){let U=F5.deSerialize(J.subarray(Z));V.push({type:22,data:U}),Z+=U.fragment_length+12}return V}catch(Z){throw qK(W.sessionId,"decSerialize failed",Z,J),Z}}case 23:return[{type:23,data:X.decryptPacket(G)}];case 21:{let J=PF.deSerialize(G.fragment);if(SK[J.description]==null){let Z=X.decryptPacket(G);J=PF.deSerialize(Z)}if(qK(W.sessionId,"ContentType.alert",J,SK[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}]}},LF=P1("werift-dtls : packages/dtls/src/socket.ts : log"),BF=P1("werift-dtls : packages/dtls/src/socket.ts : err"),TS=class{constructor(W,X){this.options=W,this.sessionType=X,this.dtls=new MF(this.options,this.sessionType),this.cipher=new eq(this.sessionType,this.options.cert,this.options.key,this.options.signatureHash),this.transport=new En(this.options.transport),this.setupExtensions(),this.transport.socket.onData=this.udpOnMessage}onConnect=new d0;onData=new d0;onError=new d0;onClose=new d0;transport;cipher;dtls;srtp=new WH;connected=!1;extensions=[];onHandleHandshakes;bufferFragmentedHandshakes=[];renegotiation(){LF("renegotiation",this.sessionType),this.connected=!1,this.cipher=new eq(this.sessionType,this.options.cert,this.options.key,this.options.signatureHash),this.dtls=new MF(this.options,this.sessionType),this.srtp=new WH,this.extensions=[],this.bufferFragmentedHandshakes=[]}udpOnMessage=(W)=>{let X=$n(W);for(let G of X)try{let Y=Fn(this.dtls,this.cipher)(G);for(let J of Y)switch(J.type){case 22:{let Z=J.data,V=this.handleFragmentHandshake([Z]),U=Object.values(V.reduce((Q,N)=>{if(!Q[N.msg_type])Q[N.msg_type]=[];return Q[N.msg_type].push(N),Q},{})).map((Q)=>F5.assemble(Q)).sort((Q,N)=>Q.msg_type-N.msg_type);this.onHandleHandshakes(U).catch((Q)=>{BF(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(Y){BF(this.dtls.sessionId,"catch udpOnMessage error",Y)}};setupExtensions(){if(LF(this.dtls.sessionId,"support srtpProfiles",this.options.srtpProfiles),this.options.srtpProfiles&&this.options.srtpProfiles.length>0){let W=bY.create(this.options.srtpProfiles,Buffer.from([0]));this.extensions.push(W.extension)}{let W=_K.createEmpty();W.data=g2,this.extensions.push(W.extension)}{let W=yK.createEmpty();W.data=h2,this.extensions.push(W.extension)}if(this.options.extendedMasterSecret)this.extensions.push({type:IH.type,data:Buffer.alloc(0)});{let W=wH.createEmpty();this.extensions.push(W.extension)}}waitForReady=(W)=>new Promise(async(X,G)=>{for(let Y=0;Y<10;Y++)if(W()){X();break}else await Ln(100*Y);G("waitForReady timeout")});handleFragmentHandshake(W){let X=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)X=[...this.bufferFragmentedHandshakes,...X],this.bufferFragmentedHandshakes=[]}return X}send=async(W)=>{let X=GU(this.dtls)([{type:23,fragment:W}],++this.dtls.recordSequenceNumber)[0];await this.transport.send(this.cipher.encryptPacket(X).serialize())};close(){this.transport.socket.close()}extractSessionKeys(W,X){let G=this.exportKeyingMaterial("EXTRACTOR-dtls_srtp",W*2+X*2),{clientKey:Y,serverKey:J,clientSalt:Z,serverSalt:V}=CX.decode(G,{clientKey:CX.types.buffer(W),serverKey:CX.types.buffer(W),clientSalt:CX.types.buffer(X),serverSalt:CX.types.buffer(X)});if(this.sessionType===d4.CLIENT)return{localKey:Y,localSalt:Z,remoteKey:J,remoteSalt:V};else return{localKey:J,localSalt:V,remoteKey:Y,remoteSalt:Z}}exportKeyingMaterial(W,X){return Uo(W,X,this.cipher.masterSecret,this.cipher.localRandom.serialize(),this.cipher.remoteRandom.serialize(),this.sessionType===d4.CLIENT)}get remoteCertificate(){return this.cipher.remoteCertificate}},HK=P1("werift-dtls : packages/dtls/src/client.ts : log"),EF=class extends TS{constructor(W){super(W,d4.CLIENT);this.onHandleHandshakes=this.handleHandshakes,HK(this.dtls.sessionId,"start client")}async connect(){await new Ro(this.transport,this.dtls,this.cipher).exec(this.extensions)}flight5;handleHandshakes=async(W)=>{HK(this.dtls.sessionId,"handleHandshakes",W.map((X)=>X.msg_type));for(let X of W)switch(X.msg_type){case 3:{let G=CS.deSerialize(X.fragment);await new Bo(this.transport,this.dtls).exec(G)}break;case 2:{if(this.connected)return;this.flight5=new Rn(this.transport,this.dtls,this.cipher,this.srtp),this.flight5.handleHandshake(X)}break;case 11:case 12:case 13:await this.waitForReady(()=>!!this.flight5),this.flight5?.handleHandshake(X);break;case 14:{await this.waitForReady(()=>!!this.flight5),this.flight5?.handleHandshake(X);let G=[11,12,this.options.certificateRequest&&13].filter((Y)=>typeof Y==="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(),HK(this.dtls.sessionId,"dtls connected");break}}},c7=P1("werift-dtls : packages/dtls/flight/server/flight2.ts : log"),xn=(W,X,G,Y)=>(J)=>{c7("dtls version",J.clientVersion),X.flight=2,X.recordSequenceNumber=0,X.sequenceNumber=0,J.extensions.forEach((A)=>{switch(A.type){case _K.type:{let H=_K.fromData(A.data).data;c7(X.sessionId,"curves",H);let I=H.filter((w)=>g2.includes(w))[0];G.namedCurve=I,c7(X.sessionId,"curve selected",G.namedCurve)}break;case yK.type:{if(!G.signatureHashAlgorithm)throw Error("need to set certificate");let H=yK.fromData(A.data).data;c7(X.sessionId,"hash,signature",H);let I=H.find((O)=>O.signature===G.signatureHashAlgorithm?.signature)?.signature,w=H.find((O)=>O.hash===G.signatureHashAlgorithm?.hash)?.hash;if(I==null||w==null)throw Error("invalid signatureHash")}break;case bY.type:{if(!X.options?.srtpProfiles)return;if(X.options.srtpProfiles.length===0)return;let H=bY.fromData(A.data);c7(X.sessionId,"srtp profiles",H.profiles);let I=WH.findMatchingSRTPProfile(H.profiles,X.options?.srtpProfiles);if(!I)throw Error();Y.srtpProfile=I,c7(X.sessionId,"srtp profile selected",Y.srtpProfile)}break;case IH.type:X.remoteExtendedMasterSecret=!0;break;case wH.type:c7(X.sessionId,"RenegotiationIndication",A.data);break;case 43:{let I=[...A.data.subarray(1)].map((w)=>w.toString(10));c7("dtls supported version",I)}break}}),G.localRandom=new PX,G.remoteRandom=PX.from(J.random);let Z=J.cipherSuites;c7(X.sessionId,"cipher suites",Z);let V=(()=>{switch(G.signatureHashAlgorithm?.signature){case o4.ecdsa_3:return EK.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256_49195;case o4.rsa_1:return EK.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,c7(X.sessionId,"selected cipherSuite",G.cipherSuite),G.localKeyPair=WS(G.namedCurve),X.cookie||=Sn(20);let U=new CS({major:254,minor:253},X.cookie),Q=s2(X)([U]),q=GU(X)(Q.map((A)=>({type:22,fragment:A.serialize()})),++X.recordSequenceNumber).map((A)=>A.serialize());for(let A of q)W.send(A)},$F=P1("werift-dtls : packages/dtls/flight/server/flight4.ts : log"),kn=class extends YU{constructor(W,X,G,Y){super(W,X,4,6);this.cipher=G,this.srtp=Y}async exec(W,X=!1){if(this.dtls.flight===4){$F(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(),X&&this.sendCertificateRequest(),this.sendServerHelloDone()].filter((Y)=>Y);this.dtls.lastMessage=G,await this.transmit(G)}sendServerHello(){let W=[];if(this.srtp.srtpProfile)W.push(bY.create([this.srtp.srtpProfile],Buffer.from([0])).extension);if(this.dtls.options.extendedMasterSecret)W.push({type:IH.type,data:Buffer.alloc(0)});let X=wH.createEmpty();W.push(X.extension);let G=new ZS(this.dtls.version,this.cipher.localRandom,Buffer.from([0]),this.cipher.cipherSuite,0,W),Y=this.createPacket([G]);return Buffer.concat(Y.map((J)=>J.serialize()))}sendCertificate(){let W=new GH([Buffer.from(this.cipher.localCert)]),X=this.createPacket([W]);return Buffer.concat(X.map((G)=>G.serialize()))}sendServerKeyExchange(){let W=this.cipher.generateKeySignature("sha256");if(!this.cipher.signatureHashAlgorithm)throw Error("not exist");let X=new QS(u2.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([X]);return Buffer.concat(G.map((Y)=>Y.serialize()))}sendCertificateRequest(){let W=new JS(Go,h2,[]);$F(this.dtls.sessionId,"sendCertificateRequest",W);let X=this.createPacket([W]);return Buffer.concat(X.map((G)=>G.serialize()))}sendServerHelloDone(){let W=new VS,X=this.createPacket([W]);return Buffer.concat(X.map((G)=>G.serialize()))}},cY=P1("werift-dtls : packages/dtls/flight/server/flight6.ts"),_n=class extends YU{constructor(W,X,G){super(W,X,6);this.cipher=G}handleHandshake(W){this.dtls.bufferHandshakeCache([W],!1,5);let X=(()=>{switch(W.msg_type){case 11:return GH.deSerialize(W.fragment);case 15:return GS.deSerialize(W.fragment);case 16:return YS.deSerialize(W.fragment);case 20:return xK.deSerialize(W.fragment)}})();if(X){let G=QU[X.msgType];if(!G)return;G({dtls:this.dtls,cipher:this.cipher})(X)}}async exec(){if(this.dtls.flight===6){cY(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=XS.createEmpty().serialize(),X=GU(this.dtls)([{type:20,fragment:W}],++this.dtls.recordSequenceNumber);return Buffer.concat(X.map((Y)=>Y.serialize()))}sendFinished(){let W=Buffer.concat(this.dtls.sortedHandshakeCache.map((Z)=>Z.serialize())),X=this.cipher.verifyData(W),G=new xK(X);this.dtls.epoch=1;let[Y]=this.createPacket([G]);return this.dtls.recordSequenceNumber=0,this.cipher.encryptPacket(Y).serialize()}},QU={};QU[16]=({cipher:W,dtls:X})=>(G)=>{if(W.remoteKeyPair={curve:W.namedCurve,publicKey:G.publicKey},!W.remoteKeyPair.publicKey||!W.localKeyPair||!W.remoteRandom||!W.localRandom)throw Error("not exist");let Y=f2(W.remoteKeyPair.publicKey,W.localKeyPair.privateKey,W.localKeyPair.curve);cY(X.sessionId,"extendedMasterSecret",X.options.extendedMasterSecret,X.remoteExtendedMasterSecret);let J=Buffer.concat(X.sortedHandshakeCache.map((Z)=>Z.serialize()));W.masterSecret=X.options.extendedMasterSecret&&X.remoteExtendedMasterSecret?c2(Y,J):p2(Y,W.remoteRandom.serialize(),W.localRandom.serialize()),W.cipher=t2(W.cipherSuite),W.cipher.init(W.masterSecret,W.localRandom.serialize(),W.remoteRandom.serialize()),cY(X.sessionId,"setup cipher",W.cipher.summary)};QU[11]=({cipher:W,dtls:X})=>(G)=>{cY(X.sessionId,"handshake certificate",G),W.remoteCertificate=G.certificateList[0]};QU[15]=({cipher:W,dtls:X})=>(G)=>{if(!W.remoteCertificate)throw Error("client certificate missing before certificate verify");cY(X.sessionId,"certificate_verify",G.algorithm)};QU[20]=({dtls:W})=>(X)=>{cY(W.sessionId,"finished",X)};var xY=P1("werift-dtls : packages/dtls/src/server.ts : log"),yn=class extends TS{constructor(W){super(W,d4.SERVER);this.onHandleHandshakes=this.handleHandshakes,xY(this.dtls.sessionId,"start server")}flight6;handleHandshakes=async(W)=>{xY(this.dtls.sessionId,"handleHandshakes",W.map((X)=>X.msg_type));for(let X of W)switch(X.msg_type){case 1:{if(this.connected)this.renegotiation();let G=r2.deSerialize(X.fragment);if(G.cookie.length===0)xY(this.dtls.sessionId,"send flight2"),xn(this.transport,this.dtls,this.cipher,this.srtp)(G);else if(this.dtls.cookie&&G.cookie.equals(this.dtls.cookie))xY(this.dtls.sessionId,"send flight4"),await new kn(this.transport,this.dtls,this.cipher,this.srtp).exec(X,this.options.certificateRequest);else xY("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 _n(this.transport,this.dtls,this.cipher),this.flight6.handleHandshake(X)}break;case 20:{await this.waitForReady(()=>!!this.flight6),this.flight6?.handleHandshake(X);let G=[16,this.options.certificateRequest&&11,this.options.certificateRequest&&15].filter((Y)=>typeof Y==="number");await this.waitForReady(()=>this.dtls.checkHandshakesExist(G)),await this.flight6?.exec(),this.connected=!0,this.onConnect.execute(),xY(this.dtls.sessionId,"dtls connected")}break}}},VO=554869826,vn=8,gn=1398035790,r6=20,MS=24,PS=1,RS=2,un=6,hn=50;var LS=((W)=>{return W[W.REQUEST=0]="REQUEST",W[W.INDICATION=16]="INDICATION",W[W.RESPONSE=256]="RESPONSE",W[W.ERROR=272]="ERROR",W})(LS||{}),BS=((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})(BS||{});function gV(W){return $S(W).toString("hex").substring(0,W)}function FS(){return $S(12)}var FF=class{queue=[];wait=new d0;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((X)=>{this.wait.subscribe((G)=>{this.queue.shift(),X(G)})});return W}},vK=(W)=>{let X,G,Y=new Promise((Z,V)=>{X=Z,G=V});Y.then(()=>{J.execute(void 0),J.complete()}).catch((Z)=>{J.execute(Z??Error()),J.complete()});let J=new d0;return W(X,G,J).catch(()=>{}),{awaitable:Y,resolve:X,reject:G}};function yY(W){let[X]=W,G=tV.default.isV4Format(X)?PS:RS,Y=Buffer.alloc(4);return Y.writeUInt8(0,0),Y.writeUInt8(G,1),Y.writeUInt16BE(W[1],2),Buffer.concat([Y,tV.default.toBuffer(X)])}function bn(W){if(W.length<4)throw Error("STUN error code is less than 4 bytes");let X=W.readUInt8(2),G=W.readUInt8(3),Y=W.slice(4).toString("utf8");return[X*100+G,Y]}function vY(W){if(W.length<4)throw Error("STUN address length is less than 4 bytes");let X=W.readUInt8(1),G=W.readUInt16BE(2),Y=W.slice(4);switch(X){case PS:if(Y.length!=4)throw Error("STUN address has invalid length for IPv4");return[tV.default.toString(Y),G];case RS:if(Y.length!=16)throw Error("STUN address has invalid length for IPv6");return[tV.default.toString(Y),G];default:throw Error("STUN address has unknown protocol")}}var UO=Buffer.alloc(6);UO.writeUInt16BE(VO>>16,0);UO.writeUInt32BE(VO,2);function SS(W,X){let G=[...UO,...X],Y=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),Y=Buffer.concat([Y,V])}return Y}function bq(W,X){return vY(SS(W,X))}function mn(W){let X=Buffer.alloc(4);X.writeUInt16BE(0,0),X.writeUInt8(Math.floor(W[0]/100),2),X.writeUInt8(W[0]%100,3);let G=Buffer.from(W[1],"utf8");return Buffer.concat([X,G])}function mq(W,X){return SS(yY(W),X)}var uV=(W)=>{let X=Buffer.alloc(4);return X.writeUInt32BE(W,0),X},hV=(W)=>W.readUInt32BE(0),fn=(W)=>{let X=Buffer.alloc(4);return X.writeUInt16BE(W,0),X},pn=(W)=>W.readUInt16BE(0),SF=(W)=>{return new aj(W.toString()).toBuffer()},xF=(W)=>{let X=new aj(W);return BigInt(X.toString())},AK=(W)=>Buffer.from(W,"utf8"),zK=(W)=>W.toString("utf8"),IK=(W)=>W,wK=(W)=>W,cn=(W)=>Buffer.from([]),ln=(W)=>null,xS=[[1,"MAPPED-ADDRESS",yY,vY],[3,"CHANGE-REQUEST",uV,hV],[4,"SOURCE-ADDRESS",yY,vY],[5,"CHANGED-ADDRESS",yY,vY],[6,"USERNAME",AK,zK],[8,"MESSAGE-INTEGRITY",IK,wK],[9,"ERROR-CODE",mn,bn],[12,"CHANNEL-NUMBER",fn,pn],[13,"LIFETIME",uV,hV],[18,"XOR-PEER-ADDRESS",mq,bq],[19,"DATA",IK,wK],[20,"REALM",AK,zK],[21,"NONCE",IK,wK],[22,"XOR-RELAYED-ADDRESS",mq,bq],[25,"REQUESTED-TRANSPORT",uV,hV],[32,"XOR-MAPPED-ADDRESS",mq,bq],[36,"PRIORITY",uV,hV],[37,"USE-CANDIDATE",cn,ln],[32802,"SOFTWARE",AK,zK],[32808,"FINGERPRINT",uV,hV],[32809,"ICE-CONTROLLED",SF,xF],[32810,"ICE-CONTROLLING",SF,xF],[32811,"RESPONSE-ORIGIN",yY,vY],[32812,"OTHER-ADDRESS",yY,vY]],kS=class{constructor(W=[]){this.attributes=W}getAttributes(){return this.attributes}setAttribute(W,X){let G=this.attributes.find((Y)=>Y[0]===W);if(G)G[1]=X;else this.attributes.push([W,X]);return this}getAttributeValue(W){let X=this.attributes.find((G)=>G[0]===W);if(!X)return;return X[1]}get attributesKeys(){return this.attributes.map((W)=>W[0])}clear(){this.attributes=[]}},kF=xS.reduce((W,X)=>{return W[X[0]]=X,W},{}),dn=xS.reduce((W,X)=>{return W[X[1]]=X,W},{});function QO(W,X){if(W.length<r6)return;let G=W.readUint16BE(2);if(W.length!==r6+G)return;let Y=W.readUint16BE(0),J=Buffer.from(W.slice(r6-12,r6)),Z=new kS;for(let U=r6;U<=W.length-4;){let Q=W.readUInt16BE(U),N=W.readUInt16BE(U+2),q=W.slice(U+4,U+4+N),A=4*Math.floor((N+3)/4)-N;if(Object.keys(kF).includes(Q.toString())){let[,I,,w]=kF[Q];if(w.name===bq.name)Z.setAttribute(I,w(q,J));else Z.setAttribute(I,w(q));if(I==="FINGERPRINT"){let O=_S(W.slice(0,U));if(Z.getAttributeValue("FINGERPRINT")!==O)return}else if(I==="MESSAGE-INTEGRITY"){if(X){let O=on(W.slice(0,U),X),T=Z.getAttributeValue("MESSAGE-INTEGRITY");if(!O.equals(T))return}}}U+=4+N+A}let V=Z.getAttributes();return Z.clear(),new d7(Y&16111,Y&272,J,V)}var d7=class extends kS{constructor(W,X,G=FS(),Y=[]){super(Y);this.messageMethod=W,this.messageClass=X,this.transactionId=G}toJSON(){return this.json}get json(){return{messageMethod:BS[this.messageMethod],messageClass:LS[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 Y=this.getAttributeValue(G),[J,,Z]=dn[G],V=Z.name===mq.name?Z(Y,this.transactionId):Z(Y),U=V.length,Q=4*Math.floor((U+3)/4)-U,N=Buffer.alloc(4);N.writeUInt16BE(J,0),N.writeUInt16BE(U,2),W=Buffer.concat([W,N,V,Buffer.alloc(Q,0)])}let X=Buffer.alloc(8);return X.writeUInt16BE(this.messageMethod|this.messageClass,0),X.writeUInt16BE(W.length,2),X.writeUInt32BE(VO,4),Buffer.concat([X,this.transactionId,W])}addMessageIntegrity(W){return this.setAttribute("MESSAGE-INTEGRITY",this.messageIntegrity(W)),this}messageIntegrity(W){let X=NO(this.bytes,this.bytes.length-r6+MS);return Buffer.from(ES("sha1",W).update(X).digest("hex"),"hex")}addFingerprint(){this.setAttribute("FINGERPRINT",_S(this.bytes))}},NO=(W,X)=>{let G=Buffer.alloc(W.length);return W.copy(G,0,0,2),G.writeUInt16BE(X,2),W.copy(G,4,4),G};function _S(W){let X=NO(W,W.length-r6+vn);return(cd(X)^gn)>>>0}function on(W,X){let G=NO(W,W.length-r6+MS);return Buffer.from(ES("sha1",X).update(G).digest("hex"),"hex")}function _F(W){let X=W%4;if(X===0)return 0;else return 4-X}var yS=class extends Error{response;addr},vS=class extends yS{constructor(W,X){super();this.response=W,this.addr=X}get str(){let W="STUN transaction failed",X=this.response.getAttributeValue("ERROR-CODE");if(X){let[G,Y]=X;W+=` (${G} - ${Y})`}return W}},nn=class extends yS{get str(){return"STUN transaction timed out"}},jK=P1("werift-ice:packages/ice/src/stun/transaction.ts"),qO=class{constructor(W,X,G,Y){this.request=W,this.addr=X,this.protocol=G,this.retransmissions=Y,this.triesMax=1+(this.retransmissions?this.retransmissions:un)}timeoutDelay=hn;ended=!1;tries=0;triesMax;onResponse=new d0;responseReceived=(W,X)=>{if(this.onResponse.length>0)if(W.messageClass===256)this.onResponse.execute(W,X),this.onResponse.complete();else this.onResponse.error(new vS(W,X))};run=async()=>{try{return this.retry().catch((X)=>{jK("retry failed",X)}),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)=>{jK("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)jK(`retry failed times:${this.tries} maxLimit:${this.triesMax}`),this.onResponse.error(new nn)};cancel(){this.ended=!0}},yF=P1("werift-ice : packages/ice/src/stun/protocol.ts"),vF=class W{static type="stun";type=W.type;transport;transactions={};get transactionsKeys(){return Object.keys(this.transactions)}localCandidate;sentMessage;localIp;onRequestReceived=new d0;onDataReceived=new d0;constructor(){}connectionMade=async(X,G,Y)=>{if(X)this.transport=await BK.init("udp4",{portRange:G,interfaceAddresses:Y});else this.transport=await BK.init("udp6",{portRange:G,interfaceAddresses:Y});this.transport.onData=(J,Z)=>{this.datagramReceived(J,Z)}};datagramReceived(X,G){try{let Y=QO(X);if(!Y){if(this.localCandidate)this.onDataReceived.execute(X);return}if((Y.messageClass===256||Y.messageClass===272)&&this.transactionsKeys.includes(Y.transactionIdHex))this.transactions[Y.transactionIdHex].responseReceived(Y,G);else if(Y.messageClass===0)this.onRequestReceived.execute(Y,G,X)}catch(Y){yF("datagramReceived error",Y)}}getExtraInfo(){let{address:X,port:G}=this.transport.address;return[X,G]}async sendStun(X,G){if(this.transport.closed)return;let Y=X.bytes;await this.transport.send(Y,G).catch(()=>{yF("sendStun failed",G,X)})}async sendData(X,G){if(this.transport.closed)return;await this.transport.send(X,G)}async request(X,G,Y,J){if(this.transactionsKeys.includes(X.transactionIdHex))throw Error("already request ed");if(Y)X.addMessageIntegrity(Y),X.addFingerprint();let Z=new qO(X,G,this,J);this.transactions[X.transactionIdHex]=Z;try{return await Z.run()}catch(V){throw V}finally{delete this.transactions[X.transactionIdHex]}}async close(){Object.values(this.transactions).forEach((X)=>{X.cancel()}),await this.transport.close(),this.onRequestReceived.complete(),this.onDataReceived.complete()}},t9=P1("werift-ice:packages/ice/src/turn/protocol.ts"),sn=500,tn=600,en=285212672,Wi=class W{constructor(X){this.turn=X,X.onData.subscribe((G,Y)=>{this.handleStunMessage(G,Y)}).disposer(this.disposer)}static type="turn";type=W.type;localCandidate;disposer=new id;onRequestReceived=new d0;onDataReceived=new d0;handleStunMessage=(X,G)=>{try{let Y=QO(X);if(!Y){this.onDataReceived.execute(X);return}if(Y.messageClass===256||Y.messageClass===272){let J=this.turn.transactions[Y.transactionIdHex];if(J)J.responseReceived(Y,G)}else if(Y.messageClass===0)this.onRequestReceived.execute(Y,G,X)}catch(Y){t9("datagramReceived error",Y)}};async request(X,G,Y){if(this.turn.transactions[X.transactionIdHex])throw Error("exist");if(Y)X.addMessageIntegrity(Y),X.addFingerprint();let J=new qO(X,G,this);this.turn.transactions[X.transactionIdHex]=J;try{return await J.run()}catch(Z){throw Z}finally{delete this.turn.transactions[X.transactionIdHex]}}async connectionMade(){}async sendData(X,G){await this.turn.sendData(X,G)}async sendStun(X,G){await this.turn.sendData(X.bytes,G)}async close(){return this.disposer.dispose(),this.turn.close()}},Xi=class W{constructor(X,G,Y,J,Z,V={}){this.server=X,this.username=G,this.password=Y,this.lifetime=J,this.transport=Z,this.options=V,this.channelRefreshTime=this.options.channelRefreshTime??sn}static type="turn";type=W.type;onData=new d0;onRequestReceived=new d0;onDataReceived=new d0;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 X=new d7(3,0);X.setAttribute("LIFETIME",this.lifetime).setAttribute("REQUESTED-TRANSPORT",en);let[G]=await this.requestWithRetry(X,this.server).catch((J)=>{throw t9("connect error",J),J});this.relayedAddress=G.getAttributeValue("XOR-RELAYED-ADDRESS"),this.mappedAddress=G.getAttributeValue("XOR-MAPPED-ADDRESS");let Y=G.getAttributeValue("LIFETIME");t9("connect",this.relayedAddress,this.mappedAddress,{exp:Y}),this.refresh(Y)}handleChannelData(X){let[G,Y]=X8.Unpack("!HH",X.slice(0,4)),J=this.addrByChannel[G];if(J){let Z=X.subarray(4,4+Y);this.onData.execute(Z,J)}}handleSTUNMessage(X,G){try{let Y=QO(X);if(!Y)throw Error("not stun message");if(Y.messageClass===256||Y.messageClass===272){let J=this.transactions[Y.transactionIdHex];if(J)J.responseReceived(Y,G)}else if(Y.messageClass===0)this.onData.execute(X,G);if(Y.getAttributeValue("DATA")){let J=Y.getAttributeValue("DATA");this.onData.execute(J,G)}}catch(Y){t9("parse error",X.toString())}}dataReceived(X,G){let Y=(J,Z)=>{if(J.length>=4&&uF(J))this.handleChannelData(J);else this.handleSTUNMessage(J,Z)};if(this.transport.type==="tcp"){this.tcpBuffer=Buffer.concat([this.tcpBuffer,X]);while(this.tcpBuffer.length>=4){let[,J]=e9(this.tcpBuffer.subarray(0,4),[2,2]);J+=_F(J);let Z=uF(this.tcpBuffer)?4+J:20+J;if(this.tcpBuffer.length<Z)break;Y(this.tcpBuffer.subarray(0,Z),G),this.tcpBuffer=this.tcpBuffer.subarray(Z)}}else Y(X,G)}async send(X,G){if(this.transport.closed)return;if(this.transport.type==="tcp"){let Y=_F(X.length);await this.transport.send(Y>0?Buffer.concat([X,Buffer.alloc(Y)]):X,G)}else await this.transport.send(X,G)}async createPermission(X){let G=new d7(8,0);G.setAttribute("XOR-PEER-ADDRESS",X).setAttribute("USERNAME",this.username).setAttribute("REALM",this.realm).setAttribute("NONCE",this.nonce),await this.request(G,this.server).catch((Y)=>{throw Y})}refresh=(X)=>{this.refreshHandle=vK(async(G,Y,J)=>{let Z=!0;J.once(()=>{Z=!1});while(Z){let V=0.8333333333333334*X*1000;t9("refresh delay",V,{exp:X}),await an(V);let U=new d7(4,0);U.setAttribute("LIFETIME",X);try{let[Q]=await this.requestWithRetry(U,this.server);X=Q.getAttributeValue("LIFETIME"),t9("refresh",{exp:X})}catch(Q){t9("refresh error",Q)}}})};async request(X,G){if(this.transactions[X.transactionIdHex])throw Error("exist");if(this.integrityKey)X.setAttribute("USERNAME",this.username).setAttribute("REALM",this.realm).setAttribute("NONCE",this.nonce).addMessageIntegrity(this.integrityKey).addFingerprint();let Y=new qO(X,G,this);this.transactions[X.transactionIdHex]=Y;try{return await Y.run()}catch(J){throw J}finally{delete this.transactions[X.transactionIdHex]}}async requestWithRetry(X,G){let Y,J;try{[Y,J]=await this.request(X,G)}catch(Z){if(Z instanceof vS==!1)throw t9("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(t9("retry with nonce",V),this.nonce=U,V===401)this.realm=Q;this.integrityKey=Yi(this.username,this.realm,this.password),X.transactionId=FS(),[Y,J]=await this.request(X,this.server)}else throw Z}return[Y,J]}async sendData(X,G){let Y=await this.getChannel(G).catch((Z)=>{return Error("channelBind error")});if(Y instanceof Error){await this.getPermission(G);let Z=new d7(6,16).setAttribute("DATA",X).setAttribute("XOR-PEER-ADDRESS",G);await this.sendStun(Z,this.server);return}let J=X8.Pack("!HH",[Y.number,X.length]);await this.send(Buffer.concat([Buffer.from(J),X]),this.server)}async getPermission(X){if(await this.creatingPermission,!this.permissionByAddr[X.join(":")])this.creatingPermission=this.createPermission(X),this.permissionByAddr[X.join(":")]=!0,await this.creatingPermission.catch((Y)=>{throw t9("createPermission error",Y),Y})}async getChannel(X){if(this.channelBinding)await this.channelBinding;let G=this.channelByAddr[X.join(":")];if(!G)this.channelByAddr[X.join(":")]={number:this.channelNumber++,address:X},G=this.channelByAddr[X.join(":")],this.addrByChannel[G.number]=X,this.channelBinding=this.channelBind(G.number,X),await this.channelBinding.catch((Y)=>{throw t9("channelBind error",Y),Y}),this.channelRefreshAt=dV(Date.now()/1000)+this.channelRefreshTime,this.channelBinding=void 0,t9("channelBind",G);else if(this.channelRefreshAt<dV(Date.now()/1000))this.channelBinding=this.channelBind(G.number,X),this.channelRefreshAt=dV(Date.now()/1000)+this.channelRefreshTime,await this.channelBinding.catch((Y)=>{throw t9("channelBind error",Y),Y}),this.channelBinding=void 0,t9("channelBind refresh",G);return G}async channelBind(X,G){let Y=new d7(9,0);Y.setAttribute("CHANNEL-NUMBER",X).setAttribute("XOR-PEER-ADDRESS",G);let[J]=await this.requestWithRetry(Y,this.server);if(J.messageMethod!==9)throw Error("should be CHANNEL_BIND")}async sendStun(X,G){await this.send(X.bytes,G)}async close(){this.refreshHandle?.resolve?.(),await this.transport.close()}};async function Gi({address:W,username:X,password:G},{lifetime:Y,portRange:J,interfaceAddresses:Z,transport:V}={}){Y??=tn,V??="udp";let U=V==="udp"?await BK.init("udp4",{portRange:J,interfaceAddresses:Z}):await sd.init(W),Q=new Xi(W,X,G,Y,U);return await Q.connectionMade(),Q}async function gF({address:W,username:X,password:G},{lifetime:Y,portRange:J,interfaceAddresses:Z,transport:V}={}){let U=await Gi({address:W,username:X,password:G},{lifetime:Y,portRange:J,interfaceAddresses:Z,transport:V});return new Wi(U)}function Yi(W,X,G){return rn("md5").update(Buffer.from([W,X,G].join(":"))).digest()}function uF(W){return(W[0]&192)==64}var TX=class W{constructor(X,G,Y,J,Z,V,U,Q,N,q,A,H){this.foundation=X,this.component=G,this.transport=Y,this.priority=J,this.host=Z,this.port=V,this.type=U,this.relatedAddress=Q,this.relatedPort=N,this.tcptype=q,this.generation=A,this.ufrag=H}static fromSdp(X){let G=X.split(" ");if(G.length<8)throw Error("SDP does not have enough properties");let Y={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,H=G.length-1;A<H;A+=2)if(G[A]==="raddr")Y.related_address=G[A+1];else if(G[A]==="rport")Y.related_port=Number(G[A+1]);else if(G[A]==="tcptype")Y.tcptype=G[A+1];else if(G[A]==="generation")Y.generation=Number(G[A+1]);else if(G[A]==="ufrag")Y.ufrag=G[A+1];let{foundation:J,component:Z,transport:V,priority:U,host:Q,port:N,type:q}=Y;return new W(J,Z,V,U,Q,N,q,Y.related_address,Y.related_port,Y.tcptype,Y.generation,Y.ufrag)}canPairWith(X){let G=hF(this.host),Y=hF(X.host);return this.component===X.component&&this.transport.toLowerCase()===X.transport.toLowerCase()&&G===Y}toSdp(){let X=`${this.foundation} ${this.component} ${this.transport} ${this.priority} ${this.host} ${this.port} typ ${this.type}`;if(this.relatedAddress)X+=` raddr ${this.relatedAddress}`;if(this.relatedPort!=null)X+=` rport ${this.relatedPort}`;if(this.tcptype)X+=` tcptype ${this.tcptype}`;if(this.generation!=null)X+=` generation ${this.generation}`;if(this.ufrag!=null)X+=` ufrag ${this.ufrag}`;return X}};function gK(W,X,G){let Y=`${W}|${X}|${G}`;return Ji("md5").update(Y,"ascii").digest("hex").slice(7)}function fq(W,X=65535){let Y=0;if(W==="host")Y=126;else if(W==="prflx")Y=110;else if(W==="srflx")Y=100;else Y=0;return 16777216*Y+256*X+255}var Vi=class{cache=new Map;mdnsInstance=gS.default();constructor(){this.mdnsInstance.setMaxListeners(50)}lookup(W){return new Promise((X,G)=>{let Y=()=>{this.mdnsInstance.removeListener("response",Z),clearTimeout(J)},J=setTimeout(()=>{Y(),G(Error("No mDNS response"))},1e4),Z=(V)=>{let U=V.answers?.[0];if(U?.type!=="A")return;if(U.name!==W)return;Y(),X(U.data)};this.mdnsInstance.on("response",Z),this.mdnsInstance.query(W,"A")})}close(){this.mdnsInstance.destroy()}},Qi=P1("werift-ice : packages/ice/src/ice.ts : log"),mF=class{constructor(W,X,G){this.protocol=W,this.remoteCandidate=X,this.iceControlling=G}id=Ui().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 hK(this.localCandidate,this.remoteCandidate,this.iceControlling)}get foundation(){return this.localCandidate.foundation}},fF=1,xq=2,Ni=5,pF=6;var qi={useIpv4:!0,useIpv6:!0};function cF(W){if(!["host","relay","srflx"].includes(W.type))throw Error(`Unexpected candidate type "${W.type}"`);return W}function Hi(W,X){return W.sort((G,Y)=>hK(G.localCandidate,G.remoteCandidate,X)-hK(Y.localCandidate,Y.remoteCandidate,X)).reverse()}function hK(W,X,G){let Y=G&&W.priority||X.priority,J=G&&X.priority||W.priority;return 1*Math.min(Y,J)+2*Math.max(Y,J)+(Y>J?1:0)}async function Ai(W,X){let G=new d7(1,0);try{let[Y]=await W.request(G,X),J=W.localCandidate;if(!J)throw Error("not exist");return new TX(gK("srflx","udp",J.host),J.component,J.transport,fq("srflx"),Y.getAttributeValue("XOR-MAPPED-ADDRESS")[0],Y.getAttributeValue("XOR-MAPPED-ADDRESS")[1],"srflx",J.host,J.port)}catch(Y){Qi("error serverReflexiveCandidate",Y)}}function lF(W){if(W&&Number.isNaN(W[1]))return[W[0],443];return W}var zi=P1("werift-ice : packages/ice/src/utils.ts");function Ii(W){return sq(W.family)===4&&W.address?.startsWith("169.254.")||sq(W.family)===6&&W.address?.startsWith("fe80::")}function dF(W,{useLinkLocalAddress:X}={}){let G=["ipsec","tun","utun","tap"],Y=["vmnet","veth"],J=uS.networkInterfaces();zi(J);let Z=Object.keys(J).map((V)=>{for(let Q of[...G,...Y])if(V.startsWith(Q))return{nic:V,addresses:[]};let U=J[V].filter((Q)=>sq(Q.family)===W&&!hS.default.isLoopback(Q.address)&&(X?!0:!Ii(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 wi(W,X,G={}){let Y=[];if(W)Y.push(...dF(4,G));if(X)Y.push(...dF(6,G));return Y}var J8=P1("werift-ice : packages/ice/src/ice.ts : log"),ji=class{constructor(W,X){this._iceControlling=W,this.options={...qi,...X};let{stunServer:G,turnServer:Y}=this.options;this.stunServer=lF(G)??["stun.l.google.com",19302],this.turnServer=lF(Y),this.restart(),J8("new Connection",this.options)}localUsername=gV(4);localPassword=gV(22);remoteIsLite=!1;remotePassword="";remoteUsername="";checkList=[];localCandidates=[];stunServer;turnServer;options;remoteCandidatesEnd=!1;localCandidatesEnd=!1;generation=-1;userHistory={};tieBreaker=BigInt(new Eq(Zi(64)).toString());state="new";lookup;_remoteCandidates=[];nominated;nominating=!1;checkListDone=!1;checkListState=new FF;earlyChecks=[];earlyChecksDone=!1;localCandidatesStart=!1;protocols=[];queryConsentHandle;onData=new d0;stateChanged=new d0;onIceCandidate=new d0;get iceControlling(){return this._iceControlling}set iceControlling(W){if(this.generation>0||this.nominated)return;this._iceControlling=W;for(let X of this.checkList)X.iceControlling=W}async restart(){if(this.generation++,this.localUsername=gV(4),this.localPassword=gV(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 FF,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(){J8("resetNominatedPair"),this.nominated=void 0,this.nominating=!1}setRemoteParams({iceLite:W,usernameFragment:X,password:G}){J8("setRemoteParams",{iceLite:W,usernameFragment:X,password:G}),this.remoteIsLite=W,this.remoteUsername=X,this.remotePassword=G}async gatherCandidates(){if(!this.localCandidatesStart){this.localCandidatesStart=!0;let W=wi(this.options.useIpv4,this.options.useIpv6,{useLinkLocalAddress:this.options.useLinkLocalAddress}),{interfaceAddresses:X}=this.options;if(X){let Y=W.filter((J)=>Object.values(X).includes(J));if(Y.length)W=Y}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((X,G,Y)=>{if(X.messageMethod!==1){this.respondError(X,G,W,[400,"Bad Request"]);return}let J=X.getAttributeValue("USERNAME"),{remoteUsername:Z}=oF(J),V=this.userHistory[Z]??this.localPassword,{iceControlling:U}=this;if(U&&X.attributesKeys.includes("ICE-CONTROLLING"))if(this.tieBreaker>=X.getAttributeValue("ICE-CONTROLLING")){this.respondError(X,G,W,[487,"Role Conflict"]);return}else this.switchRole(!1);else if(!U&&X.attributesKeys.includes("ICE-CONTROLLED"))if(this.tieBreaker<X.getAttributeValue("ICE-CONTROLLED"))this.respondError(X,G,W,[487,"Role Conflict"]);else{this.switchRole(!0);return}if(this.options.filterStunResponse&&!this.options.filterStunResponse(X,G,W))return;let Q=new d7(1,256,X.transactionId);if(Q.setAttribute("XOR-MAPPED-ADDRESS",G).addMessageIntegrity(Buffer.from(V,"utf8")).addFingerprint(),W.sendStun(Q,G).catch((N)=>{J8("sendStun error",N)}),this.checkList.length===0&&!this.earlyChecksDone)this.earlyChecks.push([X,G,W]);else this.checkIncoming(X,G,W)}),W.onDataReceived.subscribe((X)=>{try{let G=this.nominated;if(G&&G.protocol===W)G.packetsReceived++,G.bytesReceived+=X.length;this.onData.execute(X)}catch(G){J8("dataReceived",G)}})}getCandidatePromises(W,X=5){let G=[];W=W.filter((Q)=>{if(this.protocols.find((N)=>N.localIp===Q))return!1;return!0});let Y=W.map(async(Q)=>{let N=new vF;this.ensureProtocol(N);try{await N.connectionMade(bF(Q),this.options.portRange,this.options.interfaceAddresses),N.localIp=Q,this.protocols.push(N),J8("protocol",N.localIp);let q=[Q,N.getExtraInfo()[1]];return N.localCandidate=new TX(gK("host","udp",q[0]),1,"udp",fq("host"),q[0],q[1],"host",void 0,void 0,void 0,this.generation,this.localUsername),this.pairLocalProtocol(N),this.appendLocalCandidate(N.localCandidate),N}catch(q){J8("error protocol STUN",q)}});G.push(...Y.map((Q)=>Q.then((N)=>N?.localCandidate)));let{stunServer:J,turnServer:Z}=this;if(J){let Q=Y.map(async(N)=>{let q=await N;if(!q)return;return new Promise(async(H,I)=>{let w=setTimeout(I,X*1000);if(q.localCandidate?.host&&bF(q.localCandidate?.host)){let O=await Ai(q,J).catch((T)=>{J8("error",T)});if(O)this.appendLocalCandidate(O);clearTimeout(w),H(O)}else clearTimeout(w),H()}).catch((H)=>{J8("query STUN server",H)})});G.push(...Q)}let{turnUsername:V,turnPassword:U}=this.options;if(Z&&V&&U){let Q=(async()=>{let N=await gF({address:Z,username:V,password:U},{portRange:this.options.portRange,interfaceAddresses:this.options.interfaceAddresses,transport:this.options.turnTransport==="tcp"?"tcp":"udp"}).catch(async(H)=>{if(this.options.turnTransport!=="tcp")return await gF({address:Z,username:V,password:U},{portRange:this.options.portRange,interfaceAddresses:this.options.interfaceAddresses,transport:"tcp"});else throw H});this.ensureProtocol(N),this.protocols.push(N);let q=N.turn.relayedAddress,A=N.turn.mappedAddress;return J8("turn candidateAddress",q),N.localCandidate=new TX(gK("relay","udp",q[0]),1,"udp",fq("relay"),q[0],q[1],"relay",A[0],A[1],void 0,this.generation,this.localUsername),this.appendLocalCandidate(N.localCandidate),N.localCandidate})().catch((N)=>{J8("query TURN server",N)});if(this.options.forceTurn)G=[];G.push(Q)}return G}async connect(){if(J8("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 X of this.remoteCandidates)this.pairRemoteCandidate(X);this.sortCheckList(),this.unfreezeInitial(),J8("earlyChecks",this.localPassword,this.earlyChecks.length);for(let X of this.earlyChecks)this.checkIncoming(...X);this.earlyChecks=[],this.earlyChecksDone=!0;for(;;){if(this.state==="closed")break;if(!this.schedulingChecks())break;await uK.setTimeout(20)}let W=xq;while(this.checkList.length>0&&W===xq)W=await this.checkListState.get(),J8("checkListState",W);for(let X of this.checkList)X.handle?.resolve?.();if(W!==fF)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 X=new Set(W.localCandidate.foundation);for(let G of this.checkList)if(G.component===W.component&&!X.has(G.localCandidate.foundation)&&G.state===0)G.updateState(1),X.add(G.localCandidate.foundation)}schedulingChecks(){{let W=this.checkList.filter((X)=>{if(this.options.forceTurn&&X.protocol.type===vF.type)return!1;return!0}).find((X)=>X.state===1);if(W)return W.handle=this.checkStart(W),!0}{let W=this.checkList.find((X)=>X.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=vK(async(W,X,G)=>{let Y=0,J=!1,Z=new AbortController;G.once(()=>{J=!0,Y+=pF,Z.abort(),this.queryConsentHandle=void 0});let{localUsername:V,remoteUsername:U,iceControlling:Q}=this;try{while(this.state!=="closed"&&!J){await uK.setTimeout(Ni*(0.8+0.4*Math.random())*1000,void 0,{signal:Z.signal});let N=this.nominated;if(!N||J)break;let q=this.buildRequest({nominate:!1,localUsername:V,remoteUsername:U,iceControlling:Q});try{if(await N.protocol.request(q,N.remoteAddr,Buffer.from(this.remotePassword,"utf8"),0),Y=0,this.state==="disconnected")this.setState("connected")}catch(A){if(N.id===this.nominated?.id){J8("no stun response"),Y++,this.setState("disconnected");break}}if(Y>=pF){J8("Consent to send expired"),this.queryConsentHandle=void 0,this.setState("closed");break}}}catch(N){}})};async close(){if(this.setState("closed"),this.queryConsentHandle?.resolve?.(),this.checkList&&!this.checkListDone)this.checkListState.put(new Promise((W)=>{W(xq)}));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 Vi;let X=await this.lookup.lookup(W.host);W.host=X}catch(X){return}try{cF(W)}catch(X){return}J8("addRemoteCandidate",W),this._remoteCandidates.push(W),this.pairRemoteCandidate(W),this.sortCheckList()}send=async(W)=>{let X=this.nominated;if(X)await X.protocol.sendData(W,X.remoteAddr),X.packetsSent++,X.bytesSent+=W.length;else return};getDefaultCandidate(){let W=this.localCandidates.sort((G,Y)=>G.priority-Y.priority),[X]=W;return X}set remoteCandidates(W){if(this.remoteCandidatesEnd)throw Error("Cannot set remote candidates after end-of-candidates.");this._remoteCandidates=[];for(let X of W){try{cF(X)}catch(G){continue}this._remoteCandidates.push(X)}this.remoteCandidatesEnd=!0}get remoteCandidates(){return this._remoteCandidates}get candidatePairs(){return this.checkList}sortCheckList(){Hi(this.checkList,this.iceControlling)}findPair(W,X){return this.checkList.find((Y)=>pq.default(Y.protocol,W)&&pq.default(Y.remoteCandidate,X))}switchRole(W){J8("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){J8("nominated",W.toJSON()),this.nominated=W,this.nominating=!1;for(let X of this.checkList)if(X.component===W.component&&[1,0].includes(X.state))X.updateState(4)}if(this.nominated){if(!this.checkListDone)J8("ICE completed"),this.checkListState.put(new Promise((X)=>X(fF))),this.checkListDone=!0;return}J8("not completed",W.toJSON());for(let X of this.checkList)if(X.localCandidate.foundation===W.localCandidate.foundation&&X.state===0)X.updateState(1)}{let X=[3,4];if(this.checkList.find(({state:G})=>!X.includes(G)))return}if(!this.iceControlling){if(this.checkList.find(({state:G})=>G===3))return}if(!this.checkListDone)J8("ICE failed"),this.checkListState.put(new Promise((X)=>{X(xq)}))}checkStart=(W)=>vK(async(X)=>{J8("check start",W.toJSON()),W.updateState(2);let G={},{remotePassword:Y,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}),N=performance.now();try{let[q,A]=await W.protocol.request(Q,W.remoteAddr,Buffer.from(Y,"utf8"),4),I=(performance.now()-N)/1000;W.rtt=I,W.totalRoundTripTime+=I,W.roundTripTimeMeasurements++,J8("response received",Q.toJSON(),q.toJSON(),A,{localUsername:V,remoteUsername:J,remotePassword:Y,generation:Z,rtt:I}),G.response=q,G.addr=A}catch(q){let A=q;if(J8("failure case",Q.toJSON(),A.response?JSON.stringify(A.response.toJSON(),null,2):q,{localUsername:V,remoteUsername:J,remotePassword:Y,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,X();return}if(A.response?.getAttributeValue("ERROR-CODE")[0]===401){J8("retry 401",W.toJSON()),await this.checkStart(W).awaitable,X();return}else{J8("checkStart CandidatePairState.FAILED",W.toJSON()),W.updateState(4),this.checkComplete(W),X();return}}if(!pq.default(G.addr,W.remoteAddr)){W.updateState(4),this.checkComplete(W),X();return}if(U||W.remoteNominated)W.nominated=!0;else if(this.iceControlling&&!this.nominating){this.nominating=!0;let q=this.buildRequest({nominate:!0,localUsername:V,remoteUsername:J,iceControlling:this.iceControlling});try{await W.protocol.request(q,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),X()});addPair(W){this.checkList.push(W),this.sortCheckList()}checkIncoming(W,X,G){let Y=W.getAttributeValue("USERNAME"),{remoteUsername:J}=oF(Y),Z,[V,U]=X;for(let N of this.remoteCandidates)if(N.host===V&&N.port===U){Z=N;break}if(!Z)Z=new TX(gV(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 mF(G,Z,this.iceControlling),Q.updateState(1),this.addPair(Q);if(Q.localCandidate.ufrag=J,J8("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,X){if(W.localCandidate?.canPairWith(X)&&!this.findPair(W,X)){let G=new mF(W,X,this.iceControlling);if(this.options.filterCandidatePair&&!this.options.filterCandidatePair(G))return;G.updateState(1),this.addPair(G)}}pairLocalProtocol(W){for(let X of this.remoteCandidates)this.tryPair(W,X)}pairRemoteCandidate=(W)=>{for(let X of this.protocols)this.tryPair(X,W)};buildRequest({nominate:W,remoteUsername:X,localUsername:G,iceControlling:Y}){let J=Ki({remoteUsername:X,localUsername:G}),Z=new d7(1,0);if(Z.setAttribute("USERNAME",J).setAttribute("PRIORITY",fq("prflx")),Y){if(Z.setAttribute("ICE-CONTROLLING",this.tieBreaker),W)Z.setAttribute("USE-CANDIDATE",null)}else Z.setAttribute("ICE-CONTROLLED",this.tieBreaker);return Z}respondError(W,X,G,Y){let J=new d7(W.messageMethod,272,W.transactionId);J.setAttribute("ERROR-CODE",Y).addMessageIntegrity(Buffer.from(this.localPassword,"utf8")).addFingerprint(),G.sendStun(J,X).catch((Z)=>{J8("sendStun error",Z)})}},Ki=({remoteUsername:W,localUsername:X})=>{return`${W}:${X}`},oF=(W)=>{let[X,G]=W.split(":");return{remoteUsername:X,localUsername:G}};function nF(W){return W.map((X,G)=>[G,X])}function p4(W,X){let G=W.split(X);return[G[0],G.slice(1).join(X)]}var HO=class extends Oi{addEventListener=(W,X)=>{this.addListener(W,X)};removeEventListener=(W,X)=>{this.removeListener(W,X)}},Di=P1("werift:packages/webrtc/src/dataChannel.ts");function Ci(W){return Buffer.isBuffer(W)?W.length:Buffer.byteLength(W)}var bS=class extends HO{constructor(W,X,G=!0){super();if(this.sctp=W,this.parameters=X,this.sendOpen=G,this.id=this.parameters.id,X.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 d0;stateChanged=new d0;onMessage=new d0;error=new d0;bufferedAmountLow=new d0;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}Di("change state",W)}}addBufferedAmount(W){let X=this.bufferedAmount>this.bufferedAmountLowThreshold&&this.bufferedAmount+W<=this.bufferedAmountLowThreshold;if(this.bufferedAmount+=W,X)this.bufferedAmountLow.execute(),this.emit("bufferedamountlow")}send(W){let X=this.sctp.datachannelSend(this,W);this.messagesSent++,this.bytesSent+=X}close(){this.sctp.dataChannelClose(this)}},mS=class{label="";maxPacketLifeTime;maxRetransmits;ordered=!0;protocol="";negotiated=!1;id;constructor(W={}){Object.assign(this,W)}};var OH=()=>({type:"nack"}),NU=()=>({type:"nack",parameter:"pli"}),DH=()=>({type:"goog-remb"}),Ti=()=>({type:"transport-cc"}),FX=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}},Mi=class{id;uri;constructor(W){Object.assign(this,W)}};var Pi=class{type;parameter;constructor(W={}){Object.assign(this,W)}},Ri=class{ssrc;constructor(W={}){Object.assign(this,W)}},Li=class{ssrc;payloadType;rtx;constructor(W){Object.assign(this,W)}},fS=class{rid;direction;constructor(W){Object.assign(this,W)}},Bi=(W={})=>new FX({mimeType:"video/h264",clockRate:90000,rtcpFeedback:[OH(),NU(),DH()],parameters:"profile-level-id=42e01f;packetization-mode=1;level-asymmetry-allowed=1",...W}),pS=(W={})=>new FX({mimeType:"video/VP8",clockRate:90000,rtcpFeedback:[OH(),NU(),DH()],...W}),Ei=(W={})=>new FX({mimeType:"video/VP9",clockRate:90000,rtcpFeedback:[OH(),NU(),DH()],...W}),$i=(W={})=>new FX({mimeType:"video/AV1X",clockRate:90000,rtcpFeedback:[OH(),NU(),DH()],...W}),cS=(W={})=>new FX({mimeType:"audio/OPUS",clockRate:48000,channels:2,...W}),lS=(W={})=>new FX({mimeType:"audio/PCMU",clockRate:8000,channels:1,payloadType:0,...W}),dS=[$i(),Ei(),pS(),Bi(),cS(),lS()].map((W)=>W.mimeType),wA0=dS.filter((W)=>W.toLowerCase().startsWith("video/")),jA0=dS.filter((W)=>W.toLowerCase().startsWith("audio/"));var iF=2,rF=3,ki=0,_q=50,aF=51,sF=53,_i=56,yi=57,vi="0.0.0.0",tF=9,bK={auto:"actpass",client:"active",server:"passive"},eF=Object.keys(bK).reduce((W,X)=>{let G=bK[X];return W[G]=X,W},{}),gi=["apt","max-fr","max-fs","maxplaybackrate","minptime","stereo","useinbandfec"],oS=["cname","msid","mslabel","label"],W2={SRTP_AES128_CM_HMAC_SHA1_80:KH,SRTP_AEAD_AES_128_GCM:UU},cq=["sendonly","sendrecv"],ui=["sendrecv","recvonly"],hi=class extends Map{constructor(W){super();if(W)for(let X of W)this.set(X.id,X)}};function N8(W,...X){let G=X.filter((Y)=>Y!==void 0);return`${W}_${G.join("_")}`}function SX(){return performance.now()}var bi=class{constructor(W,X,G,Y,J){if(this.kind=W,this.receiver=G,this.sender=Y,this._direction=J,X)this.setDtlsTransport(X)}id=xi().toString();onTrack=new d0;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,cq.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((X)=>X.mimeType.toLowerCase().includes(W.toLowerCase()))?.payloadType}getCodecStats(){let W=SX(),X=[];if(!this.dtlsTransport)return X;let G=N8("transport",this.dtlsTransport.id);for(let Y of this.codecs){let J={type:"codec",id:N8("codec",Y.payloadType,G),timestamp:W,payloadType:Y.payloadType,transportId:G,mimeType:Y.mimeType,clockRate:Y.clockRate,channels:Y.channels,sdpFmtpLine:Y.parameters};X.push(J)}return X}},mi="inactive",nS="sendonly",iS="recvonly",rS="sendrecv",OK=[mi,nS,iS,rS],mK=class extends HO{uuid=aS().toString();streamId;remote=!1;label;kind;id;ssrc;rid;header;codec;enabled=!0;onReceiveRtp=new d0;onReceiveRtcp=new d0;onSourceChanged=new d0;stopped=!1;muted=!0;constructor(W){super();Object.assign(this,W),this.onReceiveRtp.subscribe((X)=>{this.muted=!1,this.header=X.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 X=Buffer.isBuffer(W)?WW.deSerialize(W):W;X.header.payloadType=this.codec?.payloadType??X.header.payloadType,this.onReceiveRtp.execute(X)}},fi=class{id;tracks=[];constructor(W){if(Array.isArray(W))this.tracks=W;else Object.assign(this,W);this.id??=aS().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")}},pi=P1("werift:packages/webrtc/src/utils.ts");function sS(W,X){let G=(Z)=>Z.toUpperCase(),Y=(Z)=>Z.match(/(.{2})/g).join(":"),J=Si(X).update(W).digest("hex");return Y(G(J))}var ci={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 tS(W){return ci[W.trim().toLowerCase()]}function fK(W){return W.replace(/[^0-9a-f]/gi,"").toLowerCase()}function li(W){let X=W[0];return X>19&&X<64}var eS=(W,X)=>OK[OK.indexOf(W)&OK.indexOf(X)];function di(W){if(W==="sendonly")return"recvonly";if(W==="recvonly")return"sendonly";return W}var Wx=Date.now,oi=BigInt(Date.now())*1000n-process.hrtime.bigint()/1000n,ni=()=>{return oi+process.hrtime.bigint()/1000n},NH=()=>Date.now()/1000,ii=()=>{let X=(kq.timeOrigin+kq.now()-Date.UTC(1900,0,1))/1000,[G,Y]=X.toString().split(".").map(Number);return S8([4,4],[G,Y]).readBigUInt64BE()},Xx=(W)=>{let X=S8([8],[W]),[,G,Y]=e9(X,[2,2,2,2]);return S8([2,2],[G,Y]).readUInt32BE()};function ri(W){let X=(U)=>{if(!U)return;let[Q,N]=U.split(":");return[Q,Number.parseInt(N)]},G=X(W.find(({urls:U})=>U.includes("stun:"))?.urls.slice(5)),Y=X(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:Y,turnUsername:Z,turnPassword:J};return pi("iceOptions",V),V}var PA0=eq.createSelfSignedCertificateWithKey;var ai=(W,X)=>{if(!W||typeof W!=="object")if(X!==null&&typeof X==="object")return X;else return W;if(!X||typeof X!=="object"){if(X==null)return W;return X}for(let G in X)if(Object.prototype.hasOwnProperty.call(X,G)){let Y=X[G];if(Y!=null)W[G]=Y}return W},si=P1("werift:packages/webrtc/src/media/receiver/nack.ts"),X2=150,ti=class{constructor(W){this.receiver=W}newEstSeqNum=0;_lost={};nackLoop;onPacketLost=new d0;mediaSourceSsrc;retryCount=10;closed=!1;get lostSeqNumbers(){return Object.keys(this._lost).map(Number).sort()}getLost(W){return this._lost[W]}setLost(W,X){if(this._lost[W]=X,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){si("failed to send nack",G)}},5)}removeLost(W){delete this._lost[W]}addPacket(W){let{sequenceNumber:X,ssrc:G}=W.header;if(this.mediaSourceSsrc=G,this.newEstSeqNum===0){this.newEstSeqNum=X;return}if(this.getLost(X)){this.removeLost(X);return}if(X===R9(this.newEstSeqNum,1))this.newEstSeqNum=X;else if(X>R9(this.newEstSeqNum,1)){for(let Y=R9(this.newEstSeqNum,1);Y<X;Y=R9(Y,1))this.setLost(Y,1);this.newEstSeqNum=X,this.pruneLost()}}pruneLost(){if(this.lostSeqNumbers.length>X2)this._lost=Object.entries(this._lost).slice(-X2).reduce((W,[X,G])=>{return W[X]=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,X)=>{if(this.lostSeqNumbers.length>0&&this.mediaSourceSsrc){let G=new VH({senderSsrc:this.receiver.rtcpSsrc,mediaSourceSsrc:this.mediaSourceSsrc,lost:this.lostSeqNumbers}),Y=new mY({feedback:G});this.receiver.dtlsTransport.sendRtcp([Y]).then(W).catch(X),this.updateRetryCount(),this.onPacketLost.execute(G)}})},Wr=P1("werift:packages/webrtc/media/receiver/receiverTwcc"),Xr=class{constructor(W,X,G){this.dtlsTransport=W,this.rtcpSsrc=X,this.mediaSourceSsrc=G,this.runTWCC()}extensionInfo={};twccRunning=!1;fbPktCount=0;lastTimestamp;handleTWCC(W){if(this.extensionInfo[W]={tsn:W,timestamp:ni()},Object.keys(this.extensionInfo).length>10)this.sendTWCC()}async runTWCC(){while(this.twccRunning)this.sendTWCC(),await ei(100)}sendTWCC(){if(Object.keys(this.extensionInfo).length===0)return;let W=Object.values(this.extensionInfo).sort((q,A)=>q.tsn-A.tsn),X=W[0].tsn,G=W.slice(-1)[0].tsn,Y=[],J=W[0].tsn,Z=R9(G-X,1),V,U,Q=[];for(let q=X;q<=G;q++){let A=this.extensionInfo[q]?.timestamp;if(A){if(!this.lastTimestamp)this.lastTimestamp=A;if(!V)V=this.lastTimestamp;let H=A-this.lastTimestamp;this.lastTimestamp=A;let I=new uq({delta:Number(H)});if(I.parseDelta(),Q.push(I),U!=null&&U.status!==I.type)Y.push(new oV({packetStatus:U.status,runLength:q-U.minTSN})),U={minTSN:q,status:I.type};if(q===G)if(U!=null)Y.push(new oV({packetStatus:U.status,runLength:q-U.minTSN+1}));else Y.push(new oV({packetStatus:I.type,runLength:1}));if(U==null)U={minTSN:q,status:I.type}}}if(!V)return;let N=new mY({feedback:new UH({senderSsrc:this.rtcpSsrc,mediaSourceSsrc:this.mediaSourceSsrc,baseSequenceNumber:J,packetStatusCount:Z,referenceTime:dd(Math.floor(Number(V/1000n/64n))),fbPktCount:this.fbPktCount,recvDeltas:Q,packetChunks:Y})});this.dtlsTransport.sendRtcp([N]).catch((q)=>{Wr(q)}),this.extensionInfo={},this.fbPktCount=ld(this.fbPktCount,1)}},Gr=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,X=Date.now()/1000){let G=this.max_seq==null||k2(W.header.sequenceNumber,this.max_seq);if(this.packets_received++,this.base_seq==null)this.base_seq=W.header.sequenceNumber;if(G){let Y=dV(X*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(Y-(this.last_arrival??0)-(W.header.timestamp-(this.last_timestamp??0)));this.jitter_q4+=J-(this.jitter_q4+8>>4)}this.last_arrival=Y,this.last_timestamp=W.header.timestamp}}get fraction_lost(){let W=this.packets_expected-this.expected_prior;this.expected_prior=this.packets_expected;let X=this.packets_received-this.received_prior;this.received_prior=this.packets_received;let G=W-X;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}},X7=P1("werift:packages/webrtc/src/transport/dtls.ts"),G2=class W{constructor(X,G,Y,J=[]){this.config=X,this.iceTransport=G,this.localCertificate=Y,this.srtpProfiles=J,this.localCertificate??=W.localCertificate}id=Zr().toString();state="new";role="auto";srtpStarted=!1;transportSequenceNumber=0;bytesSent=0;bytesReceived=0;packetsSent=0;packetsReceived=0;dataReceiver=()=>{};dtls;srtp;srtcp;onStateChange=new d0;onRtcp=new d0;onRtp=new d0;static localCertificate;static localCertificatePromise;remoteParameters;get localParameters(){return new cK(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:X,keyPem:G,signatureHash:Y}=await eq.createSelfSignedCertificateWithKey({signature:o4.ecdsa_3,hash:tq.sha256_4},t6.secp256r1_23);return this.localCertificate=new Gx(G,X,Y),this.localCertificate})(),this.localCertificatePromise}setRemoteParams(X){let G=Ur([...this.remoteParameters?.fingerprints??[],...X.fingerprints]),Y=X.role==="auto"&&this.remoteParameters?.role?this.remoteParameters.role:X.role;this.remoteParameters=new cK(G,Y)}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(X,G)=>{if(this.role==="server")this.dtls=new yn({cert:this.localCertificate?.certPem,key:this.localCertificate?.privateKey,signatureHash:this.localCertificate?.signatureHash,transport:Y2(this.iceTransport.connection),srtpProfiles:this.srtpProfiles,extendedMasterSecret:!0,certificateRequest:!0});else this.dtls=new EF({cert:this.localCertificate?.certPem,key:this.localCertificate?.privateKey,signatureHash:this.localCertificate?.signatureHash,transport:Y2(this.iceTransport.connection),srtpProfiles:this.srtpProfiles,extendedMasterSecret:!0});if(this.dtls.onData.subscribe((Y)=>{if(this.config.debug.inboundPacketLoss&&this.config.debug.inboundPacketLoss/100<Math.random())return;this.dataReceiver(Y)}),this.dtls.onClose.subscribe(()=>{if(this.state!=="failed")this.setState("closed")}),this.dtls.onConnect.once(X),this.dtls.onError.once((Y)=>{this.setState("failed"),X7("dtls failed",Y),G(Y)}),this.dtls instanceof EF)await Vr(100),this.dtls.connect().catch((Y)=>{this.setState("failed"),X7("dtls connect failed",Y),G(Y)})});try{this.verifyRemoteCertificateFingerprint()}catch(X){throw this.setState("failed"),this.dtls?.close(),X}if(this.srtpProfiles.length>0)this.startSrtp();this.setState("connected"),X7("dtls connected")}verifyRemoteCertificateFingerprint(){if(!this.remoteParameters||this.remoteParameters.fingerprints.length===0)throw Error("remote fingerprint not exist");let X=this.dtls?.remoteCertificate;if(!X)throw Error("remote certificate not available");let G=this.remoteParameters.fingerprints.flatMap(({algorithm:U,value:Q})=>{let N=tS(U);if(!N)return[];let q=fK(Q);if(!q)throw Error("remote fingerprint value is empty");return[{normalizedAlgorithm:N,normalizedValue:q}]});if(G.length===0)throw Error("no supported remote fingerprint algorithms");let Y=Nr(G),J=G.filter(({normalizedAlgorithm:U})=>U===Y),Z=J.reduce((U,{normalizedAlgorithm:Q})=>{if(!U.has(Q))U.set(Q,fK(sS(X,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 X=this.dtls.srtp.srtpProfile;if(!X)throw Error("need srtpProfile");X7("selected SRTP Profile",X);let{localKey:G,localSalt:Y,remoteKey:J,remoteSalt:Z}=this.dtls.extractSessionKeys(uo(X),ho(X)),V={keys:{localMasterKey:G,localMasterSalt:Y,remoteMasterKey:J,remoteMasterSalt:Z},profile:X};this.srtp=new Pn(V),this.srtcp=new Tn(V)}startSrtp(){if(this.srtpStarted)return;this.srtpStarted=!0,this.updateSrtpSession(),this.iceTransport.connection.onData.subscribe((X)=>{if(this.config.debug.inboundPacketLoss&&this.config.debug.inboundPacketLoss/100<Math.random())return;if(!fo(X))return;if(this.bytesReceived+=X.length,this.packetsReceived++,so(X)){let G;try{G=this.srtcp.decrypt(X)}catch(J){if(J instanceof pY){X7("dropping invalid SRTCP packet",J);return}throw J}let Y;try{Y=ao.deSerialize(G)}catch(J){X7("dropping malformed SRTCP packet",J);return}for(let J of Y)try{this.onRtcp.execute(J)}catch(Z){X7("RTCP error",Z)}}else{let G;try{G=this.srtp.decrypt(X)}catch(J){if(J instanceof pY){X7("dropping invalid SRTP packet",J);return}throw J}let Y;try{Y=WW.deSerialize(G)}catch(J){X7("dropping malformed SRTP packet",J);return}try{this.onRtp.execute(Y)}catch(J){X7("RTP error",J)}}})}sendData=async(X)=>{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(X)};async sendRtp(X,G){try{let Y=this.srtp.encrypt(X,G);if(this.config.debug.outboundPacketLoss&&this.config.debug.outboundPacketLoss/100<Math.random())return Y.length;return this.bytesSent+=Y.length,this.packetsSent++,await this.iceTransport.connection.send(Y).catch(()=>{}),Y.length}catch(Y){return X7("failed to send",Y),0}}async sendRtcp(X){let G=Buffer.concat(X.map((J)=>J.serialize())),Y=this.srtcp.encrypt(G);if(this.config.debug.outboundPacketLoss&&this.config.debug.outboundPacketLoss/100<Math.random())return Y.length;this.bytesSent+=Y.length,this.packetsSent++,await this.iceTransport.connection.send(Y).catch(()=>{})}setState(X){if(X!=this.state)this.state=X,this.onStateChange.execute(X)}async stop(){this.setState("closed"),await this.iceTransport.stop()}async getStats(){let X=SX(),G=[],J={type:"transport",id:N8("transport",this.id),timestamp:X,bytesSent:this.bytesSent,bytesReceived:this.bytesReceived,packetsSent:this.packetsSent,packetsReceived:this.packetsReceived,dtlsState:this.state,iceState:this.iceTransport.state,selectedCandidatePairId:this.iceTransport.connection.nominated?N8("candidate-pair",this.iceTransport.connection.nominated.localCandidate.foundation,this.iceTransport.connection.nominated.remoteCandidate.foundation):void 0,localCertificateId:this.localCertificate?N8("certificate","local"):void 0,remoteCertificateId:this.remoteParameters?N8("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:N8("certificate","local"),timestamp:X,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:N8("certificate","remote"),timestamp:X,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 Gx=class{constructor(W,X,G){this.certPem=X,this.signatureHash=G;let Y=eV.Certificate.fromPEM(Buffer.from(X));this.publicKey=Y.publicKey.toPEM(),this.privateKey=eV.PrivateKey.fromPEM(Buffer.from(W)).toPEM()}publicKey;privateKey;getFingerprints(){return[new pK("sha-256",sS(eV.Certificate.fromPEM(Buffer.from(this.certPem)).raw,"sha256"))]}},pK=class{constructor(W,X){this.algorithm=W,this.value=X}},cK=class{constructor(W=[],X){this.fingerprints=W,this.role=X}},Ur=(W)=>{let X=new Set;return W.filter(({algorithm:G,value:Y})=>{let J=`${tS(G)??G.trim().toLowerCase()}:${fK(Y)}`;if(X.has(J))return!1;return X.add(J),!0})},Qr=["sha512","sha384","sha256","sha224","sha1"],Nr=(W)=>{return Qr.find((X)=>W.some(({normalizedAlgorithm:G})=>G===X))??W[0].normalizedAlgorithm},qr=class{constructor(W){this.ice=W,W.onData.subscribe((X)=>{if(li(X)){if(this.onData)this.onData(X)}})}closed=!1;onData=()=>{};get address(){return{}}type="ice";send=(W)=>{return this.ice.send(W)};async close(){this.closed=!0,this.ice.close()}},Y2=(W)=>new qr(W),J2=P1("werift:packages/webrtc/src/transport/ice.ts"),Ar=class{constructor(W){this.iceGather=W,this.connection=this.iceGather.connection,this.connection.stateChanged.subscribe((X)=>{this.setState(X)}),this.iceGather.onIceCandidate=(X)=>{this.onIceCandidate.execute(X)}}id=Hr().toString();connection;state="new";waitStart;renominating=!1;onStateChange=new d0;onIceCandidate=new d0;onNegotiationNeeded=new d0;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(Ir(W))};setRemoteParams(W,X=!1){if(X)this.renominating=!0;if(this.connection.remoteUsername&&this.connection.remotePassword&&(this.connection.remoteUsername!==W.usernameFragment||this.connection.remotePassword!==W.password))if(this.renominating)J2("renomination",W),this.connection.resetNominatedPair(),this.renominating=!1;else J2("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 d0,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=SX(),X=[];for(let Y of this.localCandidates){let J={type:"local-candidate",id:N8("local-candidate",Y.foundation),timestamp:W,transportId:N8("transport",this.id),address:Y.ip,port:Y.port,protocol:Y.protocol,candidateType:Y.type,priority:Y.priority,foundation:Y.foundation};X.push(J)}for(let Y of this.connection.remoteCandidates){let J=WU(Y),Z={type:"remote-candidate",id:N8("remote-candidate",J.foundation),timestamp:W,transportId:N8("transport",this.id),address:J.ip,port:J.port,protocol:J.protocol,candidateType:J.type,priority:J.priority,foundation:J.foundation};X.push(Z)}let G=this.connection?.candidatePairs?[...this.connection.candidatePairs.filter((Y)=>Y.nominated),...this.connection.candidatePairs.filter((Y)=>!Y.nominated)]:[];for(let Y of G){let J={type:"candidate-pair",id:N8("candidate-pair",Y.foundation),timestamp:W,transportId:N8("transport",this.id),localCandidateId:N8("local-candidate",Y.localCandidate.foundation),remoteCandidateId:N8("remote-candidate",Y.remoteCandidate.foundation),state:Y.state,nominated:Y.nominated,packetsSent:Y.packetsSent,packetsReceived:Y.packetsReceived,bytesSent:Y.bytesSent,bytesReceived:Y.bytesReceived,currentRoundTripTime:Y.rtt};X.push(J)}return X}};var zr=class{constructor(W={}){this.options=W,this.connection=new ji(!1,this.options),this.connection.onIceCandidate.subscribe((X)=>{this.onIceCandidate(WU(X))})}onIceCandidate=()=>{};gatheringState="new";connection;onGatheringStateChange=new d0;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(WU)}get localParameters(){return new Jx({usernameFragment:this.connection.localUsername,password:this.connection.localPassword})}setState(W){if(W!==this.gatheringState)this.gatheringState=W,this.onGatheringStateChange.execute(W)}};function WU(W){let X=new Yx(W.component,W.foundation,W.host,W.port,W.priority,W.transport,W.type,W.generation,W.ufrag);return X.relatedAddress=W.relatedAddress,X.relatedPort=W.relatedPort,X.tcpType=W.tcptype,X}function Ir(W){return new TX(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 wr=class{candidate;sdpMid;sdpMLineIndex;usernameFragment;constructor(W){Object.assign(this,W)}static fromSdp(W){let X=TX.fromSdp(W);return WU(X).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}}},Yx=class{constructor(W,X,G,Y,J,Z,V,U,Q){this.component=W,this.foundation=X,this.ip=G,this.port=Y,this.priority=J,this.protocol=Z,this.type=V,this.generation=U,this.ufrag=Q}relatedAddress;relatedPort;sdpMid;sdpMLineIndex;tcpType;toJSON(){return new wr({candidate:Ix(this),sdpMLineIndex:this.sdpMLineIndex,sdpMid:this.sdpMid,usernameFragment:this.ufrag})}static fromJSON(W){try{if(!W.candidate)throw Error("candidate is required");let X=wx(W.candidate);return X.sdpMLineIndex=W.sdpMLineIndex??void 0,X.sdpMid=W.sdpMid??void 0,X}catch(X){}}},Jx=class{iceLite=!1;usernameFragment;password;constructor(W={}){Object.assign(this,W)}},n7=class W{constructor(X=0,G=Buffer.from("")){this.flags=X,this._body=G}get body(){return this._body}set body(X){this._body=X}static type=-1;get type(){return W.type}get bytes(){if(!this.body)throw Error();let X=Buffer.alloc(4);return X.writeUInt8(this.type,0),X.writeUInt8(this.flags,1),X.writeUInt16BE(this.body.length+4,2),Buffer.concat([X,this.body,...[...Array(HU(this.body.length))].map(()=>Buffer.from("\x00"))])}},AO=class extends n7{constructor(W=0,X){super(W,X);if(this.flags=W,X)this.initiateTag=X.readUInt32BE(0),this.advertisedRwnd=X.readUInt32BE(4),this.outboundStreams=X.readUInt16BE(8),this.inboundStreams=X.readUInt16BE(10),this.initialTsn=X.readUInt32BE(12),this.params=qx(X.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,Nx(this.params)])}},lq=class W extends AO{static type=1;get type(){return W.type}},lK=class W extends AO{static type=2;get type(){return W.type}},Or=class W extends AO{static type=130;get type(){return W.type}},dq=class W extends n7{constructor(X=0,G){super(X,G);if(this.flags=X,G){this.cumulativeTsn=G.readUInt32BE(0);let Y=4;while(Y<G.length)this.streams.push([G.readUInt16BE(Y),G.readUInt16BE(Y+2)]),Y+=4}else this.cumulativeTsn=0}static type=192;streams=[];cumulativeTsn;get type(){return W.type}set body(X){}get body(){let X=Buffer.alloc(4);return X.writeUInt32BE(this.cumulativeTsn,0),Buffer.concat([X,...this.streams.map(([G,Y])=>{let J=Buffer.alloc(4);return J.writeUInt16BE(G,0),J.writeUInt16BE(Y,2),J})])}},oq=class W extends n7{constructor(X=0,G){super(X,G);if(this.flags=X,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 X=16+this.userData.length,G=Buffer.alloc(16);G.writeUInt8(this.type,0),G.writeUInt8(this.flags,1),G.writeUInt16BE(X,2),G.writeUInt32BE(this.tsn,4),G.writeUInt16BE(this.streamId,8),G.writeUInt16BE(this.streamSeqNum,10),G.writeUInt32BE(this.protocol,12);let Y=Buffer.concat([G,this.userData]);if(X%4)Y=Buffer.concat([Y,...[...Array(HU(X))].map(()=>Buffer.from("\x00"))]);return Y}},dK=class W extends n7{static type=10;get type(){return W.type}},oK=class W extends n7{static type=11;get type(){return W.type}},qU=class extends n7{constructor(W=0,X=void 0){super(W,X);if(this.flags=W,X)this.params=qx(X)}params=[];get body(){return Nx(this.params)}},nK=class W extends qU{static type=6;get type(){return W.type}},nq=class W extends qU{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(([X,G])=>{return{name:(Object.entries(W.CODE).find(([,J])=>J===X)||[])[0],body:G}})}},iK=class W extends qU{static type=4;get type(){return W.type}},Zx=class W extends qU{static type=5;get type(){return W.type}},rK=class W extends qU{static type=130;get type(){return W.type}},aK=class W extends n7{constructor(X=0,G){super(X,G);if(this.flags=X,G){this.cumulativeTsn=G.readUInt32BE(0),this.advertisedRwnd=G.readUInt32BE(4);let Y=G.readUInt16BE(8),J=G.readUInt16BE(10),Z=12;[...Array(Y)].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 X=16+4*(this.gaps.length+this.duplicates.length),G=Buffer.alloc(16);G.writeUInt8(this.type,0),G.writeUInt8(this.flags,1),G.writeUInt16BE(X,2),G.writeUInt32BE(this.cumulativeTsn,4),G.writeUInt32BE(this.advertisedRwnd,8),G.writeUInt16BE(this.gaps.length,12),G.writeUInt16BE(this.duplicates.length,14);let Y=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 Y=Buffer.concat([Y,...this.duplicates.map((J)=>{let Z=Buffer.alloc(4);return Z.writeUInt32BE(J,0),Z})]),Y}},Vx=class W extends n7{constructor(X=0,G){super(X,G);if(this.flags=X,G)this.cumulativeTsn=G.readUInt32BE(0)}static type=7;get type(){return W.type}cumulativeTsn=0;get body(){let X=Buffer.alloc(4);return X.writeUInt32BE(this.cumulativeTsn,0),X}},Ux=class W extends n7{static type=8;get type(){return W.type}},Qx=class W extends n7{static type=14;get type(){return W.type}},Dr=[oq,lq,lK,aK,iK,Zx,nK,Vx,Ux,nq,dK,oK,Qx,rK,dq],Cr=Dr.reduce((W,X)=>{return W[X.type]=X,W},{});function HU(W){let X=W%4;return X?4-X:0}function Nx(W){let X=Buffer.from(""),G=Buffer.from("");return W.forEach(([Y,J])=>{let Z=J.length+4,V=Buffer.alloc(4);V.writeUInt16BE(Y,0),V.writeUInt16BE(Z,2),X=Buffer.concat([X,G,V,J]),G=Buffer.concat([...Array(HU(Z))].map(()=>Buffer.from("\x00")))}),X}function qx(W){let X=[],G=0;while(G<=W.length-4){let Y=W.readUInt16BE(G),J=W.readUInt16BE(G+2);X.push([Y,W.slice(G+4,G+J)]),G+=J+HU(J)}return X}function Tr(W){if(W.length<12)throw Error("SCTP packet length is less than 12 bytes");let X=W.readUInt16BE(0),G=W.readUInt16BE(2),Y=W.readUInt32BE(4),J=W.readUInt32LE(8),Z=x2(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),N=W.readUInt8(U+1),q=W.readUInt16BE(U+2),A=W.slice(U+4,U+q),H=Cr[Q.toString()];if(H)V.push(new H(N,A));else throw Error("unknown");U+=q+HU(q)}return[X,G,Y,V]}function Mr(W,X,G,Y){let J=Buffer.alloc(8);J.writeUInt16BE(W,0),J.writeUInt16BE(X,2),J.writeUInt32BE(G,4);let Z=Y.bytes,V=x2(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 Pr(W){return W.map((X,G)=>[G,X])}function Rr(W){return W.reduce((X,G)=>{return X[G]=new d0,X},{})}var sK=class W{constructor(X,G,Y,J){this.requestSequence=X,this.responseSequence=G,this.lastTsn=Y,this.streams=J}static type=13;get type(){return W.type}get bytes(){let X=Buffer.from(X8.Pack("!LLL",[this.requestSequence,this.responseSequence,this.lastTsn]));return Buffer.concat([X,...this.streams.map((G)=>Buffer.from(X8.Pack("!H",[G])))])}static parse(X){let[G,Y,J]=X8.Unpack("!LLL",X),Z=[];for(let V=12;V<X.length;V+=2)Z.push(X8.Unpack("!H",X.slice(V))[0]);return new W(G,Y,J,Z)}},Hx=class W{constructor(X,G){this.requestSequence=X,this.newStreams=G}static type=17;get type(){return W.type}get bytes(){return Buffer.from(X8.Pack("!LHH",[this.requestSequence,this.newStreams,0]))}static parse(X){let[G,Y]=X8.Unpack("!LHH",X);return new W(G,Y)}},yq={ReconfigResultSuccessPerformed:1,BadSequenceNumber:5},iq=class W{constructor(X,G){this.responseSequence=X,this.result=G}static type=16;get type(){return W.type}get bytes(){return Buffer.from(X8.Pack("!LL",[this.responseSequence,this.result]))}static parse(X){let[G,Y]=X8.Unpack("!LL",X);return new W(G,Y)}},V2={13:sK,16:iq,17:Hx},e1=P1("werift/sctp/sctp"),Lr=24,Br=60,U2=65535,G7=1200,pV=1,Ax=2,tK=4,Q2=10,Er=8,N2=0.125,q2=0.25,H2=3,$r=1,Fr=60,qH=4294967296,Sr=200,xr=30,A2=135,z2=7,I2=32776,w2=49152,kr=["new","closed","connected","connecting"],_r=class W{constructor(X,G=5000){this.transport=X,this.port=G,this.localPort=this.port,this.transport.onData=(Y)=>{this.handleData(Y)}}flush=new d0;stateChanged=Rr(kr);onReconfigStreams=new d0;onReceive=new d0;onSackReceived=async()=>{};associationState=1;started=!1;state="new";isServer=!0;isStopping=!1;isClosed=!1;hmacKey=Kr(16);localPartialReliability=!0;localPort;localVerificationTag=PK();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=U2;lastReceivedTsn;sackDuplicates=[];sackMisOrdered=new Set;sackNeeded=!1;sackPacketCount=0;sackHasNewDataInPacket=!1;sackImmediate=!1;sackTimeout;cwnd=3*G7;fastRecoveryExit;fastRecoveryTransmit=!1;forwardTsnChunk;flightSize=0;outboundQueue=[];outboundStreamSeq={};_outboundStreamsCount=U2;localTsn=Number(PK());lastSackedTsn=DX(this.localTsn);advancedPeerAckTsn=DX(this.localTsn);partialBytesAcked=0;sentQueue=[];transmitting=!1;transmitRequested=!1;reconfigRequestSeq=this.localTsn;reconfigResponseSeq=0;reconfigRequest;reconfigQueue=[];srtt;rttvar;rto=H2;timer1Handle;timer1Chunk;timer1Failures=0;timer2Handle;timer2Chunk;timer2Failures=0;timer3Handle;timerReconfigHandle;timerReconfigFailures=0;timerHeartbeatHandle;heartbeatInterval=xr;ssthresh;get isStopped(){return this.isStopping||this.isClosed}get maxChannels(){if(this._inboundStreamsCount>0)return Math.min(this._inboundStreamsCount,this._outboundStreamsCount);return}static client(X,G=5000){let Y=new W(X,G);return Y.isServer=!1,Y}static server(X,G=5000){let Y=new W(X,G);return Y.isServer=!0,Y}async handleData(X){if(this.isStopped)return;let G,[,,Y,J]=Tr(X);if(J.filter((V)=>V.type===lq.type).length>0){if(J.length!=1)throw Error();G=0}else G=this.localVerificationTag;if(Y!==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((X)=>{e1("send delayed sack failed",X.message)})},Sr)}async sendSack(){if(this.isStopped)return;if(!this.sackNeeded)return;let X=[],G;[...this.sackMisOrdered].sort().forEach((J)=>{let Z=(J-this.lastReceivedTsn)%qH;if(J===G)X[X.length-1][1]=Z;else X.push([Z,Z]);G=gY(J)});let Y=new aK(0,void 0);Y.cumulativeTsn=this.lastReceivedTsn,Y.advertisedRwnd=Math.max(0,this.advertisedRwnd),Y.duplicates=[...this.sackDuplicates],Y.gaps=X,await this.sendChunk(Y).catch((J)=>{e1("send sack failed",J.message)}),this.sackDuplicates=[],this.sackNeeded=!1,this.sackPacketCount=0,this.sackImmediate=!1}async receiveChunk(X){switch(X.type){case oq.type:this.receiveDataChunk(X);break;case lq.type:{if(!this.isServer)return;let G=X;e1("receive init",G),this.lastReceivedTsn=DX(G.initialTsn),this.reconfigResponseSeq=DX(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 Y=new lK;Y.initiateTag=this.localVerificationTag,Y.advertisedRwnd=this.advertisedRwnd,Y.outboundStreams=this._outboundStreamsCount,Y.inboundStreams=this._inboundStreamsCount,Y.initialTsn=this.localTsn,this.setExtensions(Y.params);let J=Date.now()/1000,Z=Buffer.from(X8.Pack("!L",[J]));Z=Buffer.concat([Z,Z2("sha1",this.hmacKey).update(Z).digest()]),Y.params.push([z2,Z]),e1("send initAck",Y),await this.sendChunk(Y).catch((V)=>{e1("send initAck failed",V.message)})}break;case lK.type:{if(this.associationState!=2)return;let G=X;this.timer1Cancel(),this.lastReceivedTsn=DX(G.initialTsn),this.reconfigResponseSeq=DX(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 Y=new dK;for(let[J,Z]of G.params)if(J===z2){Y.body=Z;break}await this.sendChunk(Y).catch((J)=>{e1("send echo failed",J.message)}),this.timer1Start(Y),this.setState(3)}break;case aK.type:await this.receiveSackChunk(X);break;case iK.type:{let G=new Zx;G.params=X.params,await this.sendChunk(G).catch((Y)=>{e1("send heartbeat ack failed",Y.message)})}break;case nK.type:this.setState(1);break;case Vx.type:{this.timer2Cancel(),this.setState(7);let G=new Ux;await this.sendChunk(G).catch((Y)=>{e1("send shutdown ack failed",Y.message)}),this.t2Start(G),this.setState(6)}break;case nq.type:e1("ErrorChunk",X.descriptions);break;case dK.type:{if(!this.isServer)return;let Y=X.body,J=Z2("sha1",this.hmacKey).update(Y.slice(0,4)).digest();if(Y?.length!=Lr||!Y.slice(4).equals(J)){e1("x State cookie is invalid");return}let Z=Date.now()/1000,V=X8.Unpack("!L",Y)[0];if(V<Z-Br||V>Z){let Q=new nq(0,void 0);Q.params.push([nq.CODE.StaleCookieError,Buffer.concat([...Array(8)].map(()=>Buffer.from("\x00")))]),await this.sendChunk(Q).catch((N)=>{e1("send errorChunk failed",N.message)});return}let U=new oK;await this.sendChunk(U).catch((Q)=>{e1("send cookieAck failed",Q.message)}),this.setState(4)}break;case oK.type:{if(this.associationState!=3)return;this.timer1Cancel(),this.setState(4)}break;case Qx.type:{if(this.associationState!=8)return;this.timer2Cancel(),this.setState(1)}break;case rK.type:{if(this.associationState!=4)return;let G=X;for(let[Y,J]of G.params){let Z=V2[Y];if(Z)await this.receiveReconfigParam(Z.parse(J))}}break;case dq.type:this.receiveForwardTsnChunk(X);break}}getExtensions(X){for(let[G,Y]of X)if(G===w2)this.remotePartialReliability=!0;else if(G===I2)this.remoteExtensions=[...Y]}async receiveReconfigParam(X){switch(e1("receiveReconfigParam",V2[X.type]),X.type){case sK.type:{let G=X,Y=new iq(G.requestSequence,yq.ReconfigResultSuccessPerformed);this.reconfigResponseSeq=G.requestSequence,await this.sendReconfigParam(Y),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 iq.type:{let G=X;if(G.result!==yq.ReconfigResultSuccessPerformed)e1("OutgoingSSNResetRequestParam failed",Object.keys(yq).find((Y)=>yq[Y]===G.result));else if(G.responseSequence===this.reconfigRequest?.requestSequence){let Y=this.reconfigRequest.streams.map((J)=>{return delete this.outboundStreamSeq[J],J});if(this.onReconfigStreams.execute(Y),this.reconfigRequest=void 0,this.timerReconfigCancel(),this.rto=H2,this.timerReconfigFailures=0,this.reconfigQueue.length>0)await this.transmitReconfigRequest()}}break;case Hx.type:{let G=X;this._inboundStreamsCount+=G.newStreams;let Y=new iq(G.requestSequence,1);this.reconfigResponseSeq=G.requestSequence,await this.sendReconfigParam(Y)}break}}receiveDataChunk(X){if(this.sackNeeded=!0,this.markReceived(X.tsn)){this.sackImmediate=!0;return}if(this.sackHasNewDataInPacket=!0,this.sackImmediate=!0,(X.flags&pV)===0)this.sackImmediate=!0;if(this.sackMisOrdered.size>0)this.sackImmediate=!0;let G=this.getInboundStream(X.streamId);G.addChunk(X),this.advertisedRwnd-=X.userData.length;for(let Y of G.popMessages())this.advertisedRwnd+=Y[2].length,this.receive(...Y)}async receiveSackChunk(X){if(c4(this.lastSackedTsn,X.cumulativeTsn))return;let G=Date.now()/1000;this.lastSackedTsn=X.cumulativeTsn;let Y=this.flightSize>=this.cwnd,J=0,Z=0;while(this.sentQueue.length>0&&fV(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(X.gaps.length>0){let U=new Set,Q;X.gaps.forEach((q)=>{for(let A=q[0];A<q[1]+1;A++)Q=(X.cumulativeTsn+A)%qH,U.add(Q)});let N=X.cumulativeTsn;for(let q of this.sentQueue){if(c4(q.tsn,Q))break;if(U.has(q.tsn)&&!q.acked)Z+=q.bookSize,q.acked=!0,this.flightSizeDecrease(q),N=q.tsn}for(let q of this.sentQueue){if(c4(q.tsn,N))break;if(!U.has(q.tsn)){if(q.misses++,q.misses===3){if(q.misses=0,!this.maybeAbandon(q))q.retransmit=!0;q.acked=!1,this.flightSizeDecrease(q),V=!0}}}}if(this.fastRecoveryExit===void 0){if(J&&Y){if(this.cwnd<=this.ssthresh)this.cwnd+=Math.min(Z,G7);else if(this.partialBytesAcked+=Z,this.partialBytesAcked>=this.cwnd)this.partialBytesAcked-=this.cwnd,this.cwnd+=G7}if(V)this.ssthresh=Math.max(Math.floor(this.cwnd/2),4*G7),this.cwnd=this.ssthresh,this.partialBytesAcked=0,this.fastRecoveryExit=this.sentQueue[this.sentQueue.length-1].tsn,this.fastRecoveryTransmit=!0}else if(fV(X.cumulativeTsn,this.fastRecoveryExit))this.fastRecoveryExit=void 0;if(this.sentQueue.length===0)this.timer3Cancel();else if(J>0)this.timer3Restart();this.peerAdvertisedRwnd=X.advertisedRwnd,this.updateAdvancedPeerAckPoint(),await this.onSackReceived(),await this.transmit()}receiveForwardTsnChunk(X){if(this.sackNeeded=!0,this.sackImmediate=!0,fV(this.lastReceivedTsn,X.cumulativeTsn))return;let G=(Y)=>c4(Y,this.lastReceivedTsn);this.lastReceivedTsn=X.cumulativeTsn,this.sackMisOrdered=new Set([...this.sackMisOrdered].filter(G));for(let Y of[...this.sackMisOrdered].sort())if(Y===gY(this.lastReceivedTsn))this.lastReceivedTsn=Y;else break;this.sackDuplicates=this.sackDuplicates.filter(G),this.sackMisOrdered=new Set([...this.sackMisOrdered].filter(G));for(let[Y,J]of X.streams){let Z=this.getInboundStream(Y);Z.streamSequenceNumber=R9(J,1);for(let V of Z.popMessages())this.advertisedRwnd+=V[2].length,this.receive(...V)}Object.values(this.inboundStreams).forEach((Y)=>{this.advertisedRwnd+=Y.pruneChunks(this.lastReceivedTsn)})}updateRto(X){if(!this.srtt)this.rttvar=X/2,this.srtt=X;else this.rttvar=(1-q2)*this.rttvar+q2*Math.abs(this.srtt-X),this.srtt=(1-N2)*this.srtt+N2*X;this.rto=Math.max($r,Math.min(this.srtt+4*this.rttvar,Fr))}receive(X,G,Y){this.onReceive.execute(X,G,Y)}getInboundStream(X){if(!this.inboundStreams[X])this.inboundStreams[X]=new yr;return this.inboundStreams[X]}markReceived(X){if(fV(this.lastReceivedTsn,X)||this.sackMisOrdered.has(X))return this.sackDuplicates.push(X),!0;this.sackMisOrdered.add(X);for(let Y of[...this.sackMisOrdered].sort())if(Y===gY(this.lastReceivedTsn))this.lastReceivedTsn=Y;else break;let G=(Y)=>c4(Y,this.lastReceivedTsn);return this.sackDuplicates=this.sackDuplicates.filter(G),this.sackMisOrdered=new Set([...this.sackMisOrdered].filter(G)),!1}send=async(X,G,Y,{expiry:J,maxRetransmits:Z,ordered:V}={expiry:void 0,maxRetransmits:void 0,ordered:!0})=>{let U=V?this.outboundStreamSeq[X]||0:0,Q=Math.ceil(Y.length/G7),N=0,q=[];for(let A=0;A<Q;A++){let H=new oq(0,void 0);if(H.flags=0,!V)H.flags=tK;if(A===0)H.flags|=Ax;if(A===Q-1)H.flags|=pV;H.tsn=this.localTsn,H.streamId=X,H.streamSeqNum=U,H.protocol=G,H.userData=Y.slice(N,N+G7),H.bookSize=H.userData.length,H.expiry=J,H.maxRetransmits=Z,N+=G7,this.localTsn=gY(this.localTsn),q.push(H)}if(q.forEach((A)=>{this.outboundQueue.push(A)}),V)this.outboundStreamSeq[X]=R9(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)=>{e1("send forwardTsn failed",J.message)}),this.forwardTsnChunk=void 0,!this.timer3Handle)this.timer3Start()}let X=this.fastRecoveryExit!=null?2*G7:4*G7,G=Math.min(this.flightSize+X,this.cwnd),Y=!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)=>{e1("send data failed",Z.message)}),Y)this.timer3Restart()}Y=!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)=>{e1("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 X=[...new Set(this.reconfigQueue)],G=X.slice(0,A2);this.reconfigQueue=X.slice(A2);let Y=new sK(this.reconfigRequestSeq,this.reconfigResponseSeq,DX(this.localTsn),G);this.reconfigRequestSeq=gY(this.reconfigRequestSeq),this.reconfigRequest=Y,await this.sendReconfigParam(Y),this.timerReconfigHandleStart()}}async sendReconfigParam(X){e1("sendReconfigParam",X);let G=new rK;G.params.push([X.type,X.bytes]),await this.sendChunk(G).catch((Y)=>{e1("send reconfig failed",Y.message)})}async sendResetRequest(X){e1("sendResetRequest",X);let G=new oq(0,void 0);if(G.streamId=X,this.outboundQueue.push(G),!this.timer3Handle)await this.transmit()}flightSizeIncrease(X){this.flightSize+=X.bookSize}flightSizeDecrease(X){this.flightSize=Math.max(0,this.flightSize-X.bookSize)}timer1Start(X){if(this.timer1Handle)throw Error();this.timer1Chunk=X,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>Er)this.setState(1);else{if(setImmediate(()=>{if(this.isStopped)return;this.sendChunk(this.timer1Chunk).catch((X)=>{e1("send timer1 chunk failed",X.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(X){if(this.timer2Handle)throw Error();this.timer2Chunk=X,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>Q2)this.setState(1);else{if(setImmediate(()=>{if(this.isStopped)return;this.sendChunk(this.timer2Chunk).catch((X)=>{e1("send timer2Chunk failed",X.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((X)=>{if(!this.maybeAbandon(X))X.retransmit=!0}),this.updateAdvancedPeerAckPoint(),this.fastRecoveryExit=void 0,this.flightSize=0,this.partialBytesAcked=0,this.ssthresh=Math.max(Math.floor(this.cwnd/2),4*G7),this.cwnd=G7,this.transmit()};timer3Cancel(){if(this.timer3Handle)clearTimeout(this.timer3Handle),this.timer3Handle=void 0}timerReconfigHandleStart(){if(this.isStopped)return;if(this.timerReconfigHandle)return;e1("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>Q2)e1("timerReconfigFailures",this.timerReconfigFailures),this.setState(1),this.timerReconfigHandle=void 0;else if(this.reconfigRequest){if(e1("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)e1("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 X=new iK;X.params.push([1,Buffer.from(X8.Pack("!L",[Math.floor(Date.now()/1000)]))]),await this.sendChunk(X).catch((G)=>{e1("send heartbeat failed",G.message)})}this.heartbeatStart()};setHeartbeatInterval(X){if(X<=0)throw Error("heartbeat interval must be > 0");this.heartbeatInterval=X,this.heartbeatRestart()}updateAdvancedPeerAckPoint(){if(c4(this.lastSackedTsn,this.advancedPeerAckTsn))this.advancedPeerAckTsn=this.lastSackedTsn;let X=0,G={};while(this.sentQueue.length>0&&this.sentQueue[0].abandoned){let Y=this.sentQueue.shift();if(this.advancedPeerAckTsn=Y.tsn,X++,!(Y.flags&tK))G[Y.streamId]=Y.streamSeqNum}if(!this.sentQueue.length)this.sentQueue=[];if(X)this.forwardTsnChunk=new dq(0,void 0),this.forwardTsnChunk.cumulativeTsn=this.advancedPeerAckTsn,this.forwardTsnChunk.streams=Object.entries(G).map(([Y,J])=>[Number(Y),J])}maybeAbandon(X){if(X.abandoned)return!0;if(!(!!X.maxRetransmits&&X.maxRetransmits<X.sentCount||!!X.expiry&&X.expiry<Date.now()/1000))return!1;let Y=this.sentQueue.findIndex((J)=>J.type===X.type);for(let J=Y;J>=0;J--){let Z=this.sentQueue[J];if(Z.abandoned=!0,Z.retransmit=!1,Z.flags&pV)break}for(let J=Y;J<this.sentQueue.length;J++){let Z=this.sentQueue[J];if(Z.abandoned=!0,Z.retransmit=!1,Z.flags&pV)break}return!0}static getCapabilities(){return new vr(65536)}setRemotePort(X){this.remotePort=X}async start(X){if(!this.started){if(this.started=!0,this.setConnectionState("connecting"),X)this.setRemotePort(X);if(!this.isServer)await this.init()}}async init(){let X=new lq;X.initiateTag=this.localVerificationTag,X.advertisedRwnd=this.advertisedRwnd,X.outboundStreams=this._outboundStreamsCount,X.inboundStreams=this._inboundStreamsMax,X.initialTsn=this.localTsn,this.setExtensions(X.params),e1("send init",X);try{await this.sendChunk(X),this.timer1Start(X),this.setState(2)}catch(G){e1("send init failed",G.message)}}setExtensions(X){let G=[];if(this.localPartialReliability)X.push([w2,Buffer.from("")]),G.push(dq.type);G.push(Or.type),X.push([I2,Buffer.from(G)])}async sendChunk(X){if(this.state==="closed")return;if(this.remotePort===void 0)throw Error("invalid remote port");let G=Mr(this.localPort,this.remotePort,this.remoteVerificationTag,X);await this.transport.send(G)}setState(X){if(X!=this.associationState)this.associationState=X;if(X===4)this.isStopping=!1,this.isClosed=!1,this.setConnectionState("connected"),this.heartbeatStart();else if(X===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(X){this.state=X,e1("setConnectionState",X),this.stateChanged[X].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 X=new nK;await this.sendChunk(X).catch((G)=>{e1("send abort failed",G.message)})}removeAllListeners(){Object.values(this.stateChanged).forEach((X)=>X.allUnsubscribe())}},yr=class{reassembly=[];streamSequenceNumber=0;constructor(){}addChunk(W){if(this.reassembly.length===0||c4(W.tsn,this.reassembly[this.reassembly.length-1].tsn)){this.reassembly.push(W);return}for(let[X,G]of Pr(this.reassembly)){if(G.tsn===W.tsn)throw Error("duplicate chunk in reassembly");if(c4(G.tsn,W.tsn)){this.reassembly.splice(X,0,W);break}}}*popMessages(){let W=0,X,G,Y;while(W<this.reassembly.length){let J=this.reassembly[W];if(X===void 0){if(Y=!(J.flags&tK),!(J.flags&Ax))if(Y)break;else{W++;continue}if(Y&&k2(J.streamSeqNum,this.streamSequenceNumber))break;G=J.tsn,X=W}else if(J.tsn!==G)if(Y)break;else{X=void 0,W++;continue}if(J.flags&pV){let Z=this.reassembly.slice(X,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,X),...this.reassembly.slice(W+1)],Y&&J.streamSeqNum===this.streamSequenceNumber)this.streamSequenceNumber=R9(this.streamSequenceNumber,1);W=X,yield[J.streamId,J.protocol,V]}else W++;G=gY(G)}}pruneChunks(W){let X=-1,G=0;for(let[Y,J]of this.reassembly.entries())if(fV(W,J.tsn))X=Y,G+=J.userData.length;else break;return this.reassembly=this.reassembly.slice(X+1),G}},vr=class{constructor(W){this.maxMessageSize=W}};function DX(W){return(W-1)%qH}function gY(W){return(W+1)%qH}var kY=P1("werift:packages/webrtc/src/transport/sctp.ts"),cV=65536,gr=class W{constructor(X=5000,G=cV){this.port=X,this.maxMessageSize=G}dtlsTransport;sctp;onDataChannel=new d0;id=jr().toString();mid;mLineIndex;bundled=!1;dataChannels={};remoteMaxMessageSize=cV;dataChannelQueue=[];dataChannelId;eventDisposer=[];setDtlsTransport(X){if(this.dtlsTransport&&this.dtlsTransport.id===X.id)return;this.eventDisposer.forEach((G)=>G()),this.dtlsTransport=X,this.sctp=new _r(new ur(this.dtlsTransport),this.port),this.eventDisposer=[...[this.sctp.onReceive.subscribe(this.datachannelReceive),this.sctp.onReconfigStreams.subscribe((G)=>{G.forEach((Y)=>{let J=this.dataChannels[Y];if(!J)return;J.setReadyState("closing"),J.setReadyState("closed"),delete this.dataChannels[Y]})}),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(X){return Object.values(this.dataChannels).find((G)=>G.label===X)}datachannelReceive=async(X,G,Y)=>{if(G===_q&&Y.length>0)switch(kY("DCEP",X,G,Y),Y[0]){case rF:{if(Y.length<12){kY("DATA_CHANNEL_OPEN data.length not enough");return}if(!Object.keys(this.dataChannels).includes(X.toString())){let[,Z,,V,U,Q]=X8.Unpack("!BBHLHH",Y),N=12,q=Y.slice(N,N+U).toString("utf8");N+=U;let A=Y.slice(N,N+Q).toString("utf8");kY("DATA_CHANNEL_OPEN",{channelType:Z,reliability:V,streamId:X,label:q,protocol:A});let H=(Z&3)===1?V:void 0,I=(Z&3)===2?V:void 0,w=new mS({label:q,ordered:(Z&128)===0,maxPacketLifeTime:I,maxRetransmits:H,protocol:A,id:X}),O=new bS(this,w,!1);O.isCreatedByRemote=!0,this.dataChannels[X]=O,this.onDataChannel.execute(O),O.setReadyState("open")}else kY("datachannel already opened","retransmit ack");let J=this.dataChannels[X];this.dataChannelQueue.push([J,_q,Buffer.from(X8.Pack("!B",[iF]))]),await this.dataChannelFlush()}break;case iF:{kY("DATA_CHANNEL_ACK",X,G);let J=this.dataChannels[X];if(!J)throw Error("channel not found");J.setReadyState("open")}break}else{let J=this.dataChannels[X];if(J){let Z=(()=>{switch(G){case aF:return Y.toString("utf8");case _i:return"";case sF:return Y;case yi:return Buffer.from([]);default:throw Error()}})();if(J.messagesReceived++,J.bytesReceived+=Y.length,J.onMessage.execute(Z),J.emit("message",{data:Z}),J.onmessage)J.onmessage({data:Z})}}};dataChannelAddNegotiated(X){if(X.id==null)throw Error();if(this.dataChannels[X.id])throw Error();if(this.dataChannels[X.id]=X,this.sctp.associationState===4)X.setReadyState("open")}dataChannelOpen(X){if(X.id){if(this.dataChannels[X.id])throw Error(`Data channel with ID ${X.id} already registered`);this.dataChannels[X.id]=X}let G=ki,Y=0,J=0;if(!X.ordered)G=128;if(X.maxRetransmits)G=1,J=X.maxRetransmits;else if(X.maxPacketLifeTime)G=2,J=X.maxPacketLifeTime;let Z=X8.Pack("!BBHLHH",[rF,G,Y,J,X.label.length,X.protocol.length]),V=Buffer.concat([Buffer.from(Z),Buffer.from(X.label,"utf8"),Buffer.from(X.protocol,"utf8")]);this.dataChannelQueue.push([X,_q,V]),this.dataChannelFlush()}async dataChannelFlush(){if(this.sctp.associationState!=4)return;while(this.dataChannelQueue.length>0){let[X,G,Y]=this.dataChannelQueue.shift(),J=X.id;if(J===void 0){J=this.dataChannelId;while(Object.keys(this.dataChannels).includes(J.toString()))J+=2;this.dataChannels[J]=X,X.setId(J)}if(G===_q)await this.sctp.send(J,G,Y,{ordered:!0});else{let Z=X.maxPacketLifeTime?Date.now()+X.maxPacketLifeTime/1000:void 0;await this.sctp.send(J,G,Y,{expiry:Z,maxRetransmits:X.maxRetransmits,ordered:X.ordered}),X.addBufferedAmount(-Y.length)}}this.dataChannelQueue=[]}assertSendableMessageSize(X){if(this.remoteMaxMessageSize!==0&&X>this.remoteMaxMessageSize)throw Error(`max-message-size exceeded: ${X} > ${this.remoteMaxMessageSize}`)}datachannelSend=(X,G)=>{let Y=Buffer.isBuffer(G)?G:Buffer.from(G),J=Ci(G);if(this.assertSendableMessageSize(J),X.addBufferedAmount(J),this.dataChannelQueue.push(typeof G==="string"?[X,aF,Y]:[X,sF,Y]),this.sctp.associationState!==4)kY("sctp not established",this.sctp.associationState);return this.dataChannelFlush(),J};getCapabilities(){return W.getCapabilities(this.maxMessageSize)}static getCapabilities(X=cV){return new zx(X)}setRemoteMaxMessageSize(X){this.remoteMaxMessageSize=X??cV}setRemotePort(X){this.sctp.setRemotePort(X)}async start(X){if(this.isServer)this.dataChannelId=0;else this.dataChannelId=1;this.sctp.isServer=this.isServer,await this.sctp.start(X)}async stop(){this.dtlsTransport.dataReceiver=()=>{},await this.sctp.stop()}dataChannelClose(X){if(!["closing","closed"].includes(X.readyState))if(X.setReadyState("closing"),this.sctp.associationState===4){if(!this.sctp.reconfigQueue.includes(X.id))this.sctp.reconfigQueue.push(X.id);if(this.sctp.reconfigQueue.length===1)this.sctp.transmitReconfigRequest()}else{if(this.dataChannelQueue=this.dataChannelQueue.filter((G)=>G[0].id!==X.id),this.sctp.reconfigQueue=this.sctp.reconfigQueue.filter((G)=>G!==X.id),X.id)delete this.dataChannels[X.id];X.setReadyState("closed")}}},zx=class{constructor(W){this.maxMessageSize=W}},ur=class{constructor(W){this.dtls=W}set onData(W){this.dtls.dataReceiver=W}send=(W)=>{return this.dtls.sendData(W)};close(){}},rq=class W{version=0;origin;name="-";time="0 0";host;group=[];extMapAllowMixed=!0;msidSemantic=[];media=[];type;dtlsRole;iceOptions;iceLite;icePassword;iceUsernameFragment;dtlsFingerprints=[];static parse(X){let[G,Y]=hr(X),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=DK(V.slice(2));else if(V.startsWith("t="))J.time=V.slice(2);else if(V.startsWith("a=")){let[U,Q]=CK(V);switch(U){case"fingerprint":{let[N,q]=Q?.split(" ")||[];J.dtlsFingerprints.push(new pK(N,q))}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":TK(J.group,Q);break;case"msid-semantic":TK(J.msidSemantic,Q);break;case"setup":J.dtlsRole=eF[Q];break;case"extmap-allow-mixed":J.extMapAllowMixed=!0;break}}});let Z=J.group.find((V)=>V.semantic==="BUNDLE");return Y.forEach((V)=>{let Q=V[0].match(/^m=([^ ]+) ([0-9]+) ([A-Z/]+) (.+)/);if(!Q)throw Error("m line not found");let N=Q[1],q=Q[4].split(" "),A=["audio","video"].includes(N)?q.map((w)=>Number(w)):void 0,H=new eK(N,Number.parseInt(Q[2]),Q[3],A||q);if(H.dtlsParams=new cK([...J.dtlsFingerprints],J.dtlsRole),H.iceParams=new Jx({iceLite:J.iceLite,usernameFragment:J.iceUsernameFragment,password:J.icePassword}),H.iceOptions=J.iceOptions,J.media.push(H),V.slice(1).forEach((w)=>{if(w.startsWith("c="))H.host=DK(w.slice(2));else if(w.startsWith("a=")){let[O,T]=CK(w);switch(O){case"candidate":if(!T)throw Error();H.iceCandidates.push(wx(T));break;case"end-of-candidates":H.iceCandidatesComplete=!0;break;case"extmap":{let[x,h]=T.split(" ");if(x.includes("/"))[x]=x.split("/");H.rtp.headerExtensions.push(new Mi({id:Number.parseInt(x),uri:h}))}break;case"fingerprint":{if(!T)throw Error();let[x,h]=T.split(" ");H.dtlsParams?.fingerprints.push(new pK(x,h))}break;case"ice-options":H.iceOptions=T;break;case"ice-pwd":H.iceParams.password=T;break;case"ice-ufrag":H.iceParams.usernameFragment=T;break;case"ice-lite":H.iceParams.iceLite=!0;break;case"max-message-size":H.sctpCapabilities=new zx(Number.parseInt(T,10));break;case"mid":H.rtp.muxId=T;break;case"msid":H.msid=T;break;case"rtcp":{let[x,h]=p4(T," ");H.rtcpPort=Number.parseInt(x),H.rtcpHost=DK(h)}break;case"rtcp-mux":H.rtcpMux=!0;break;case"setup":H.dtlsParams.role=eF[T];break;case"recvonly":case"sendonly":case"sendrecv":case"inactive":H.direction=O;break;case"rtpmap":{let[x,h]=p4(T," "),[$,F,u]=h.split("/"),l;if(H.kind==="audio")l=u?Number.parseInt(u):1;let f=new FX({mimeType:H.kind+"/"+$,channels:l,clockRate:Number.parseInt(F),payloadType:Number.parseInt(x)});H.rtp.codecs.push(f)}break;case"sctpmap":{if(!T)throw Error();let[x,h]=p4(T," ");H.sctpMap[Number.parseInt(x)]=h,H.sctpPort=Number.parseInt(x)}break;case"sctp-port":if(!T)throw Error();H.sctpPort=Number.parseInt(T);break;case"ssrc":{let[x,h]=p4(T," "),$=Number.parseInt(x),[F,u]=p4(h,":"),l=H.ssrc.find((f)=>f.ssrc===$);if(!l)l=new XO({ssrc:$}),H.ssrc.push(l);if(oS.includes(F))l[F]=u}break;case"ssrc-group":TK(H.ssrcGroup,T);break;case"rid":{let[x,h]=p4(T," ");H.simulcastParameters.push(new fS({rid:x,direction:h}))}break}}}),!H.iceParams.usernameFragment||!H.iceParams.password){if(H.rtp.muxId&&Z&&Z.items.includes(H.rtp.muxId))for(let w=0;w<Z.items.length;w++){if(!Z.items.includes(w.toString()))continue;let O=J.media[w];if(O.iceParams?.usernameFragment&&O.iceParams.password){H.iceParams={...O.iceParams};break}}}if(!H.dtlsParams.role)H.dtlsParams=void 0;let I=(w)=>H.rtp.codecs.find((O)=>O.payloadType===w);V.slice(1).forEach((w)=>{if(w.startsWith("a=")){let[O,T]=CK(w);if(O==="fmtp"){let[x,h]=p4(T," "),$=I(Number(x));$.parameters=h}else if(O==="rtcp-fb"){let[x,h,$]=T.split(" ");H.rtp.codecs.forEach((F)=>{if(["*",F.payloadType.toString()].includes(x))F.rtcpFeedback.push(new Pi({type:h,parameter:$}))})}}})}),J}webrtcTrackId(X){if(X.msid?.includes(" ")){let G=X.msid.split(" ");for(let Y of this.msidSemantic)if(Y.semantic==="WMS"&&(Y.items.includes(G[0])||Y.items.includes("*")))return G[1]}return}get string(){let X=[`v=${this.version}`,`o=${this.origin}`,`s=${this.name}`];if(this.host)X.push(`c=${WO(this.host)}`);if(X.push(`t=${this.time}`),this.group.forEach((J)=>X.push(`a=group:${J.str}`)),this.extMapAllowMixed)X.push("a=extmap-allow-mixed");this.msidSemantic.forEach((J)=>X.push(`a=msid-semantic:${J.str}`));let G=this.media.map((J)=>J.toString()).join("");return X.join(`\r
243
243
  `)+`\r
244
244
  `+G}toJSON(){return new br(this.string,this.type)}toSdp(){return{type:this.type,sdp:this.string}}},eK=class{constructor(W,X,G,Y){this.kind=W,this.port=X,this.profile=G,this.fmt=Y}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((X)=>X.toString()).join(" ")}`),this.host)W.push(`c=${WO(this.host)}`);if(this.iceCandidates.forEach((X)=>{W.push(`a=candidate:${Ix(X)}`)}),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((X)=>{W.push(`a=fingerprint:${X.algorithm} ${X.value}`)}),W.push(`a=setup:${bK[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} ${WO(this.rtcpHost)}`),this.rtcpMux)W.push("a=rtcp-mux")}if(this.ssrcGroup.forEach((X)=>{W.push(`a=ssrc-group:${X.str}`)}),this.ssrc.forEach((X)=>{oS.forEach((G)=>{let Y=X[G];if(Y!==void 0)W.push(`a=ssrc:${X.ssrc} ${G}:${Y}`)})}),this.rtp.codecs.forEach((X)=>{if(W.push(`a=rtpmap:${X.payloadType} ${X.str}`),X.rtcpFeedback.forEach((G)=>{let Y=G.type;if(G.parameter)Y+=` ${G.parameter}`;W.push(`a=rtcp-fb:${X.payloadType} ${Y}`)}),X.parameters)W.push(`a=fmtp:${X.payloadType} ${X.parameters}`)}),Object.keys(this.sctpMap).forEach((X)=>{let G=this.sctpMap[Number(X)];W.push(`a=sctpmap:${X} ${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((X)=>W.push(`a=extmap:${X.id} ${X.uri}`)),this.simulcastParameters.length){this.simulcastParameters.forEach((J)=>{W.push(`a=rid:${J.rid} ${J.direction}`)});let X="a=simulcast:",G=this.simulcastParameters.filter((J)=>J.direction==="recv");if(G.length)X+=`recv ${G.map((J)=>J.rid).join(";")} `;let Y=this.simulcastParameters.filter((J)=>J.direction==="send");if(Y.length)X+=`send ${Y.map((J)=>J.rid).join(";")}`;W.push(X)}return W.join(`\r
245
245
  `)+`\r
246
246
  `}},nV=class{constructor(W,X){this.semantic=W,this.items=X}get str(){return`${this.semantic} ${this.items.join(" ")}`}};function DK(W){let X=W.match(/^IN (IP4|IP6) ([^ ]+)$/);if(!X)throw Error("exception");return X[2]}function WO(W){return`IN IP${Jr(W)?4:6} ${W}`}function Ix(W){let X=`${W.foundation} ${W.component} ${W.protocol} ${W.priority} ${W.ip} ${W.port} typ ${W.type}`;if(W.relatedAddress!=null)X+=` raddr ${W.relatedAddress}`;if(W.relatedPort!=null)X+=` rport ${W.relatedPort}`;if(W.tcpType!=null)X+=` tcptype ${W.tcpType}`;if(W.generation!=null)X+=` generation ${W.generation}`;if(W.ufrag!=null)X+=` ufrag ${W.ufrag}`;return X}function hr(W){let X=[],G=[],Y=W.split(`\r
247
247
  `);if(Y.length===1)Y=W.split(`
248
- `);return Y.forEach((J)=>{if(J.startsWith("m="))G.push([J]);else if(G.length>0)G[G.length-1].push(J);else X.push(J)}),[X,G]}function CK(W){if(W.includes(":")){let X=p4(W.slice(2),":");return[X[0],X[1]]}else return[W.slice(2),void 0]}function TK(W,X,G=(Y)=>Y.toString()){let Y=X.split(" ");if(Y.length>0)W.push(new nV(Y[0],Y.slice(1).map(G)))}function wx(W){let X=TX.fromSdp(W);return WU(X)}var br=class{constructor(W,X){this.sdp=W,this.type=X}static isThis(W){if(typeof W?.sdp==="string")return!0}toSdp(){return{sdp:this.sdp,type:this.type}}};function j2(W,X){let Y=new Eq(Yr(64)).toString().slice(0,8),J=0;X.origin=`- ${Y} 0 IN IP4 0.0.0.0`,X.msidSemantic.push(new nV("WMS",["*"])),X.type=W}function HH(W){let X={};return W.split(";").forEach((G)=>{if(G.includes("=")){let[Y,J]=p4(G,"=");if(gi.includes(Y))X[Y]=Number(J);else X[Y]=J}else if(G.includes(":")){let[Y,J]=G.split(":");X[Y]=Number.isNaN(Number(J))?J:Number(J)}else X[G]=void 0}),X}var XO=class{ssrc;cname;msid;msLabel;label;constructor(W){Object.assign(this,W)}},vq=P1("werift:packages/webrtc/src/media/rtpReceiver.ts"),jx=class{constructor(W,X,G){this.config=W,this.kind=X,this.rtcpSsrc=G}codecs={};get codecArray(){return Object.values(this.codecs).sort((W,X)=>W.payloadType-X.payloadType)}ssrcByRtx={};nack=new ti(this);audioRedHandler=new An;type="receiver";uuid=Fi().toString();tracks=[];trackBySSRC={};trackByRID={};lastSRtimestamp={};receiveLastSRTimestamp={};onPacketLost=this.nack.onPacketLost;onRtcp=new d0;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 mK({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===Ti().type)}get pliEnabled(){return this.codecArray[0]?.rtcpFeedback.find((W)=>W.type===NU().type)}prepareReceive(W){W.codecs.forEach((X)=>{this.codecs[X.payloadType]=X}),W.encodings.forEach((X)=>{if(X.rtx)this.ssrcByRtx[X.rtx.ssrc]=X.ssrc})}setupTWCC(W){if(this.twccEnabled&&!this.receiverTWCC)this.receiverTWCC=new Xr(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 KK(500+Math.random()*1000,void 0,{signal:this.rtcpCancel.signal});let W=Object.entries(this.remoteStreams).map(([G,Y])=>{let J=0,Z=0;if(this.lastSRtimestamp[G]){J=this.lastSRtimestamp[G];let V=NH()-this.receiveLastSRTimestamp[G];if(V>0&&V<65536)Z=dV(V*65536)}return new JO({ssrc:Number(G),fractionLost:Y.fraction_lost,packetsLost:Y.packets_lost,highestSequence:Y.max_seq,jitter:Y.jitter,lsr:J,dlsr:Z})}),X=new aV({ssrc:this.rtcpSsrc,reports:W});try{if(this.config.debug.receiverReportDelay)await KK(this.config.debug.receiverReportDelay);await this.dtlsTransport.sendRtcp([X])}catch(G){vq("sendRtcp failed",G),await KK(500+Math.random()*1000)}}}catch(W){}}async getStats(){let W=SX(),X=[];if(!this.dtlsTransport)return X;let G=N8("transport",this.dtlsTransport.id);for(let Y of this.tracks){if(!Y.ssrc)continue;let J=this.remoteStreams[Y.ssrc];if(!J)continue;let Z={type:"inbound-rtp",id:N8("inbound-rtp",Y.ssrc),timestamp:W,ssrc:Y.ssrc,kind:this.kind,transportId:G,codecId:this.codecs[0]?N8("codec",this.codecs[0].payloadType,G):void 0,mid:this.sdesMid,trackIdentifier:Y.id,packetsReceived:J.packets_received,packetsLost:J.packets_lost,jitter:J.jitter};if(X.push(Z),this.lastSRtimestamp[Y.ssrc]){let V={type:"remote-outbound-rtp",id:N8("remote-outbound-rtp",Y.ssrc),timestamp:W,ssrc:Y.ssrc,kind:this.kind,transportId:G,codecId:Z.codecId,localId:Z.id,remoteTimestamp:this.receiveLastSRTimestamp[Y.ssrc]*1000};X.push(V)}}return X}async sendRtcpPLI(W){if(!this.pliEnabled){vq("pli not supported",{mediaSsrc:W});return}if(this.stopped)return;vq("sendRtcpPLI",{mediaSsrc:W});let X=new rV({feedback:new JH({senderSsrc:this.rtcpSsrc,mediaSsrc:W})});try{await this.dtlsTransport.sendRtcp([X])}catch(G){vq(G)}}handleRtcpPacket(W){switch(W.type){case fY.type:{let X=W;this.lastSRtimestamp[X.ssrc]=Xx(X.senderInfo.ntpTimestamp),this.receiveLastSRTimestamp[X.ssrc]=NH();let G=this.trackBySSRC[W.ssrc];if(G)G.onReceiveRtcp.execute(W)}break}this.onRtcp.execute(W)}handleRtpBySsrc=(W,X)=>{let G=this.trackBySSRC[W.header.ssrc];this.handleRTP(W,X,G)};handleRtpByRid=(W,X,G)=>{let Y=this.trackByRID[X];if(!this.trackBySSRC[W.header.ssrc])this.trackBySSRC[W.header.ssrc]=Y;this.handleRTP(W,G,Y)};handleRTP(W,X,G){if(this.stopped)return;let Y=this.codecs[W.header.payloadType];if(!Y)return;if(this.remoteStreams[W.header.ssrc]=this.remoteStreams[W.header.ssrc]??new Gr(Y.clockRate),this.remoteStreams[W.header.ssrc].add(W),this.receiverTWCC){let Z=X[P9.transportWideCC];if(!Z==null)throw Error("undefined");this.receiverTWCC.handleTWCC(Z)}else if(this.twccEnabled)this.setupTWCC(W.header.ssrc);if(Y.name.toLowerCase()==="rtx"){let Z=this.ssrcByRtx[W.header.ssrc],V=HH(Y.parameters??""),U=this.codecs[V.apt];if(W.payload.length<2)return;W=zn(W,U.payloadType,Z),G=this.trackBySSRC[Z]}let J;if(Y.name.toLowerCase()==="red"){if(J=zS.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(),X)}}else G.onReceiveRtp.execute(W.clone(),X);this.runRtcp()}},bV=P1("werift:packages/webrtc/src/media/router.ts"),mr=class{ssrcTable={};ridTable={};extIdUriMap={};constructor(){}registerRtpSender(W){this.ssrcTable[W.ssrc]=W}registerRtpReceiver(W,X){bV("registerRtpReceiver",X),this.ssrcTable[X]=W}registerRtpReceiverBySsrc(W,X){bV("registerRtpReceiverBySsrc",X),X.encodings.filter((G)=>G.ssrc!=null).forEach((G,Y)=>{if(this.registerRtpReceiver(W.receiver,G.ssrc),W.addTrack(new mK({ssrc:G.ssrc,kind:W.kind,id:W.sender.trackId,remote:!0,codec:X.codecs[Y]})),G.rtx)this.registerRtpReceiver(W.receiver,G.rtx.ssrc)}),X.headerExtensions.forEach((G)=>{this.extIdUriMap[G.id]=G.uri})}registerRtpReceiverByRid(W,X,G){let[Y]=G.codecs;bV("registerRtpReceiverByRid",X),W.addTrack(new mK({rid:X.rid,kind:W.kind,id:W.sender.trackId,remote:!0,codec:Y})),this.ridTable[X.rid]=W.receiver}routeRtp=(W)=>{let X=to(W.header.extensions,this.extIdUriMap),G=this.ssrcTable[W.header.ssrc],Y=X[P9.sdesRTPStreamID];if(typeof Y==="string")G=this.ridTable[Y],G.latestRid=Y,G.handleRtpByRid(W,Y,X);else if(G)G.handleRtpBySsrc(W,X);else if(G=Object.values(this.ridTable).filter((V)=>V instanceof jx).find((V)=>V.trackBySSRC[W.header.ssrc]),G)bV("simulcast register receiver by ssrc",W.header.ssrc),this.registerRtpReceiver(G,W.header.ssrc),G.handleRtpBySsrc(W,X);if(!G){bV("ssrcReceiver not found");return}let J=X[P9.sdesMid];if(typeof J==="string")G.sdesMid=J;let Z=X[P9.repairedRtpStreamId];if(typeof Z==="string")G.latestRepairedRid=Z};routeRtcp=(W)=>{let X=[];switch(W.type){case fY.type:W=W,X.push(this.ssrcTable[W.ssrc]);break;case aV.type:W=W,W.reports.forEach((G)=>{X.push(this.ssrcTable[G.ssrc])});break;case QH.type:{let G=W}break;case mY.type:{let G=W;if(G.feedback)X.push(this.ssrcTable[G.feedback.mediaSourceSsrc])}break;case rV.type:{let G=W;switch(G.feedback.count){case ZH.count:{let Y=G.feedback;X.push(this.ssrcTable[Y.ssrcFeedbacks[0]])}break;default:X.push(this.ssrcTable[G.feedback.senderSsrc]||this.ssrcTable[G.feedback.mediaSsrc])}}break}X.filter((G)=>G).forEach((G)=>G.handleRtcpPacket(W))}},fr=class{numPackets=0;totalSize=0;firstPacketSentAtMs=0;lastPacketSentAtMs=0;firstPacketReceivedAtMs=0;lastPacketReceivedAtMs=0;addPacket(W,X,G){if(this.numPackets===0)this.firstPacketSentAtMs=X,this.firstPacketReceivedAtMs=G,this.lastPacketSentAtMs=X,this.lastPacketReceivedAtMs=G;else{if(X<this.firstPacketSentAtMs)this.firstPacketSentAtMs=X;if(G<this.firstPacketReceivedAtMs)this.firstPacketReceivedAtMs=G;if(X>this.lastPacketSentAtMs)this.lastPacketSentAtMs=X;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,X=this.totalSize/W*8*1000;return YH(X)}get sendBitrate(){let W=this.lastPacketSentAtMs-this.firstPacketSentAtMs,X=this.totalSize/W*8*1000;return YH(X)}},_Y=20,pr=10,cr=class{congestion=!1;onAvailableBitrate=new d0;onCongestion=new d0;onCongestionScore=new d0;congestionCounter=0;cumulativeResult=new fr;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=Wx()-this.cumulativeResult.firstPacketSentAtMs;if(G>1000){if(this.cumulativeResult.reset(),this.congestionCounter<_Y)this.congestionCounter++;else if(this.congestionScore<pr)this.congestionScore++;if(this.congestionCounter>=_Y&&!this.congestion)this.congestion=!0,this.onCongestion.execute(this.congestion)}for(let Y of W.packetResults){if(!Y.received)continue;let J=Y.sequenceNumber,Z=this.sentInfos[J];if(!Z)continue;if(!Y.receivedAtMs)continue;this.cumulativeResult.addPacket(Z.size,Z.sendingAtMs,Y.receivedAtMs)}if(G>=100&&this.cumulativeResult.numPackets>=20){if(this.availableBitrate=Math.min(this.cumulativeResult.sendBitrate,this.cumulativeResult.receiveBitrate),this.cumulativeResult.reset(),this.congestionCounter>-_Y){let Y=YH(_Y/2)+1,J=YH(_Y/4)+1,Z=Y-(Y-J)/10*this.congestionScore;this.congestionCounter=this.congestionCounter-Z}if(this.congestionCounter<=-_Y){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((X)=>Number(X)).sort().filter((X)=>X<W.wideSeq).forEach((X)=>{delete this.sentInfos[X]}),this.sentInfos[W.wideSeq]=W}},MK=P1("werift:packages/webrtc/src/media/rtpSender.ts"),C2=128,T2=0.85,lr=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=X8.Unpack("!L",K2(4))[0];rtxSsrc=X8.Unpack("!L",K2(4))[0];streamId=O2().toString();trackId=O2().toString();onReady=new d0;onRtcp=new d0;onPictureLossIndication=new d0;onGenericNack=new d0;senderBWE=new cr;cname;mid;rtpStreamId;repairedRtpStreamId;rtxPayloadType;rtxSequenceNumber=R2();redRedundantPayloadType;_redDistance=2;redEncoder=new qn(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((X)=>X());this.dtlsTransport=W,this.dtlsDisposer=[this.dtlsTransport.onStateChange.subscribe((X)=>{if(X==="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((X)=>{let G=HH(X.parameters??"");if(X.name.toLowerCase()==="rtx"&&G.apt===this.codec?.payloadType)this.rtxPayloadType=X.payloadType;if(X.name.toLowerCase()==="red")this.redRedundantPayloadType=Number((X.parameters??"").split("/")[0])})}registerTrack(W){if(W.stopped)throw Error("track is ended");if(this.disposeTrack)this.disposeTrack();W.id=this.trackId;let{unSubscribe:X}=W.onReceiveRtp.subscribe(async(G)=>{await this.sendRtp(G)});if(this.track=W,this.disposeTrack=X,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 X=W.header||(await W.onReceiveRtp.asPromise())[0].header;this.replaceRTP(X)}this.registerTrack(W),MK("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 D2(500+Math.random()*1000,void 0,{signal:this.rtcpCancel.signal});let W=[new fY({ssrc:this.ssrc,senderInfo:new AS({ntpTimestamp:this.ntpTimestamp,rtpTimestamp:this.rtpTimestamp,packetCount:this.packetCount,octetCount:this.octetCount})})];if(this.lastSRtimestamp=Xx(this.ntpTimestamp),this.lastSentSRTimestamp=NH(),this.cname)W.push(new QH({chunks:[new qS({source:this.ssrc,items:[new HS({type:1,text:this.cname})]})]}));try{await this.dtlsTransport.sendRtcp(W)}catch(X){MK("sendRtcp failed",X),await D2(500+Math.random()*1000)}}}catch(W){}}replaceRTP({sequenceNumber:W,timestamp:X},G=!1){if(this.sequenceNumber!=null){if(this.seqOffset=R9(this.sequenceNumber,-W),G)this.seqOffset=R9(this.seqOffset,2)}if(this.timestamp!=null){if(this.timestampOffset=uY(this.timestamp,-X),G)this.timestampOffset=R9(this.timestampOffset,1)}this.rtpCache=[],MK("replaceRTP",this.sequenceNumber,W,this.seqOffset)}async sendRtp(W){if(this.dtlsTransport.state!=="connected"||!this.codec)return;W=Buffer.isBuffer(W)?WW.deSerialize(W):W;let{header:X,payload:G}=W;X.ssrc=this.ssrc,X.payloadType=this.codec.payloadType,X.timestamp=uY(X.timestamp,this.timestampOffset),X.sequenceNumber=R9(X.sequenceNumber,this.seqOffset),this.timestamp=X.timestamp,this.sequenceNumber=X.sequenceNumber;let Y=ii(),J=[...X.extensions];X.extensions=this.headerExtensions.map((N)=>{let q=(()=>{switch(N.uri){case P9.sdesMid:if(this.mid)return eo(this.mid);return;case P9.sdesRTPStreamID:if(this.rtpStreamId)return Wn(this.rtpStreamId);return;case P9.repairedRtpStreamId:if(this.repairedRtpStreamId)return Xn(this.repairedRtpStreamId);return;case P9.transportWideCC:return this.dtlsTransport.transportSequenceNumber=R9(this.dtlsTransport.transportSequenceNumber,1),Gn(this.dtlsTransport.transportSequenceNumber);case P9.absSendTime:return Yn(Y)}})();if(q)return{id:N.id,payload:q}}).filter((N)=>N);for(let N of J){let q=X.extensions.find((A)=>A.id===N.id);if(q)q.payload=N.payload;else X.extensions.push(N)}X.extensions=X.extensions.sort((N,q)=>N.id-q.id),this.ntpTimestamp=Y,this.rtpTimestamp=X.timestamp,this.octetCount+=G.length,this.packetCount=uY(this.packetCount,1),this.rtpCache[X.sequenceNumber%C2]=W;let Z=G;if(this.redRedundantPayloadType)this.redEncoder.push({block:Z,timestamp:X.timestamp,blockPT:this.redRedundantPayloadType}),Z=this.redEncoder.build().serialize();let V=await this.dtlsTransport.sendRtp(Z,X);this.runRtcp();let U=Wx(),Q={wideSeq:this.dtlsTransport.transportSequenceNumber,size:V,sendingAtMs:U,sentAtMs:U};this.senderBWE.rtpPacketSent(Q)}handleRtcpPacket(W){switch(W.type){case fY.type:case aV.type:W.reports.filter((G)=>G.ssrc===this.ssrc).forEach((G)=>{if(this.lastSRtimestamp===G.lsr&&G.dlsr){if(this.lastSentSRTimestamp){let Y=NH()-this.lastSentSRTimestamp-G.dlsr/65536;if(this.rtt===void 0)this.rtt=Y;else this.rtt=T2*this.rtt+(1-T2)*Y}}});break;case mY.type:{let X=W;switch(X.feedback.count){case UH.count:{let G=X.feedback;this.senderBWE.receiveTWCC(G)}break;case VH.count:{let G=X.feedback;G.lost.forEach(async(Y)=>{let J=this.rtpCache[Y%C2];if(J&&J.header.sequenceNumber!==Y)J=void 0;if(J){if(this.rtxPayloadType!=null)J=In(J,this.rtxPayloadType,this.rtxSequenceNumber,this.rtxSsrc),this.rtxSequenceNumber=R9(this.rtxSequenceNumber,1);await this.dtlsTransport.sendRtp(J.payload,J.header)}}),this.onGenericNack.execute(G)}break}}break;case rV.type:{let X=W;switch(X.feedback.count){case ZH.count:{let G=X.feedback;this.receiverEstimatedMaxBitrate=G.bitrate}break;case JH.count:this.onPictureLossIndication.execute();break}}break}this.onRtcp.execute(W)}getParameters(){return{encodings:[]}}setParameters(W){}async getStats(){let W=SX(),X=[];if(!this.dtlsTransport)return X;let G=N8("transport",this.dtlsTransport.id),Y={type:"outbound-rtp",id:N8("outbound-rtp",this.ssrc),timestamp:W,ssrc:this.ssrc,kind:this.kind,transportId:G,codecId:this.codec?N8("codec",this.codec.payloadType,G):void 0,mid:this.mid,packetsSent:this.packetCount,bytesSent:this.octetCount,rtxSsrc:this.rtxPayloadType?this.rtxSsrc:void 0};if(X.push(Y),this.track){let J={type:"media-source",id:N8("media-source",this.trackId),timestamp:W,trackIdentifier:this.trackId,kind:this.kind};X.push(J)}if(this.rtt!==void 0){let J={type:"remote-inbound-rtp",id:N8("remote-inbound-rtp",this.ssrc),timestamp:W,ssrc:this.ssrc,kind:this.kind,transportId:G,codecId:Y.codecId,localId:Y.id,roundTripTime:this.rtt};X.push(J)}return X}},or=P1("werift:packages/webrtc/src/transport/sctpManager.ts"),nr=class{sctpTransport;sctpRemotePort;dataChannelsOpened=0;dataChannelsClosed=0;dataChannels=[];onDataChannel=new d0;constructor(){}createSctpTransport(W){let X=new gr(5000,W);return X.mid=void 0,X.onDataChannel.subscribe((G)=>{this.dataChannelsOpened++,this.dataChannels.push(G),this.onDataChannel.execute(G)}),this.sctpTransport=X,X}createDataChannel(W,X={}){let Y={...{protocol:"",ordered:!0,negotiated:!1},...X};if(Y.maxPacketLifeTime&&Y.maxRetransmits)throw Error("can not select both");if(!this.sctpTransport)this.sctpTransport=this.createSctpTransport();let J=new mS({id:Y.id,label:W,maxPacketLifeTime:Y.maxPacketLifeTime,maxRetransmits:Y.maxRetransmits,negotiated:Y.negotiated,ordered:Y.ordered,protocol:Y.protocol}),Z=new bS(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(),or("sctp connected")}setRemoteSCTP(W,X){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=X,!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=SX(),X=[];for(let G of this.dataChannels){let Y={type:"data-channel",id:N8("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};X.push(Y)}return X}},ir=class{currentLocalDescription;currentRemoteDescription;pendingLocalDescription;pendingRemoteDescription;cname;midSuffix;bundlePolicy;seenMid=new Set;constructor({cname:W,midSuffix:X,bundlePolicy:G}){this.cname=W,this.midSuffix=X??!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,X){let G=new eK(W.kind,9,"UDP/TLS/RTP/SAVPF",W.codecs.map((Y)=>Y.payloadType));if(G.direction=X,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 XO({ssrc:W.sender.ssrc,cname:this.cname})],W.options.simulcast)G.simulcastParameters=W.options.simulcast.map((Y)=>new fS(Y));if(G.rtp.codecs.find((Y)=>Y.name.toLowerCase()==="rtx"))G.ssrc.push(new XO({ssrc:W.sender.rtxSsrc,cname:this.cname})),G.ssrcGroup=[new nV("FID",[W.sender.ssrc.toString(),W.sender.rtxSsrc.toString()])];return this.addTransportDescription(G,W.dtlsTransport),G}createMediaDescriptionForSctp(W){let X=new eK("application",tF,"UDP/DTLS/SCTP",["webrtc-datachannel"]);return X.sctpPort=W.port,X.rtp.muxId=W.mid,X.sctpCapabilities=W.getCapabilities(),this.addTransportDescription(X,W.dtlsTransport),X}addTransportDescription(W,X){let G=X.iceTransport;if(W.iceCandidates=G.localCandidates,W.iceCandidatesComplete=G.gatheringState==="complete",W.iceParams=G.localParameters,W.iceOptions="trickle",W.host=vi,W.port=tF,W.direction==="inactive")W.port=0,W.msid=void 0;if(!W.dtlsParams){if(W.dtlsParams=X.localParameters,!W.dtlsParams.fingerprints)W.dtlsParams.fingerprints=X.localParameters.fingerprints}}allocateMid(W=""){let X="";for(let G=0;;)if(X=(G++).toString()+W,!this.seenMid.has(X))break;return this.seenMid.add(X),X}parseSdp({sdp:W,isLocal:X,signalingState:G,type:Y}){let J=rq.parse(W);return this.validateDescription({description:J,isLocal:X,signalingState:G}),J.type=Y,J}validateDescription({description:W,isLocal:X,signalingState:G}){if(X){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,X){let G=new rq;j2("offer",G),(this.currentLocalDescription?.media??[]).forEach((J,Z)=>{let V=J.rtp.muxId;if(!V)return;if(J.kind==="application"){if(!X)throw Error("sctpTransport not found");X.mLineIndex=Z,G.media.push(this.createMediaDescriptionForSctp(X))}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(X&&!G.media.find((J)=>J.kind==="application")){if(X.mLineIndex=G.media.length,X.mid==null)X.mid=this.allocateMid(this.midSuffix?"dc":"");G.media.push(this.createMediaDescriptionForSctp(X))}if(this.bundlePolicy!=="disable"){let J=G.media.map((Z)=>Z.rtp.muxId).filter((Z)=>Z);if(J.length){let Z=new nV("BUNDLE",J);G.group.push(Z)}}return G}buildAnswerSdp({transceivers:W,sctpTransport:X,signalingState:G}){if(!["have-remote-offer","have-local-pranswer"].includes(G))throw Error("createAnswer failed");if(!this._remoteDescription)throw Error("wrong state");let Y=new rq;j2("answer",Y);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,eS(U.direction,U.offerDirection)),Z=U.dtlsTransport}else if(J.kind==="application"){if(!X||!X.mid)throw Error("sctpTransport not found");V=this.createMediaDescriptionForSctp(X),Z=X.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"}));Y.media.push(V)}if(this.bundlePolicy!=="disable"){let J=new nV("BUNDLE",[]);for(let Z of Y.media)if(Z.rtp.muxId)J.items.push(Z.rtp.muxId);Y.group.push(J)}return Y}setLocalDescription(W){if(this.currentLocalDescription=W,W.type==="answer")this.pendingLocalDescription=void 0;else this.pendingLocalDescription=W}setRemoteDescription(W,X){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:X,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,X,G){let Y=new Map(X.map((V)=>[V?.mLineIndex,V])),J=X.find((V)=>V?.dtlsTransport)?.dtlsTransport??G?.dtlsTransport;W.media.filter((V)=>["audio","video"].includes(V.kind)).forEach((V,U)=>{let N=(Y.get(U)??X[U])?.dtlsTransport??J;if(!N)throw Error(`dtls transport not found for media index ${U}`);this.addTransportDescription(V,N)});let Z=W.media.find((V)=>V.kind==="application");if(G&&Z)this.addTransportDescription(Z,G.dtlsTransport);this.setLocalDescription(W)}},mV=P1("werift:packages/webrtc/src/transport/secureTransportManager.ts"),rr=class{connectionState="new";iceConnectionState="new";iceGatheringState="new";certificate;iceGatheringStateChange=new d0;iceConnectionStateChange=new d0;onIceCandidate=new d0;connectionStateChange=new d0;config;transceiverManager;sctpManager;constructor({config:W,transceiverManager:X,sctpManager:G}){if(this.config=W,this.transceiverManager=X,this.sctpManager=G,this.config.dtls){let{keys:Y}=this.config.dtls;if(Y)this.setupCertificate(Y)}}get dtlsTransports(){return[...this.transceiverManager.getTransceivers().map((X)=>X?.dtlsTransport),this.sctpManager.sctpTransport?.dtlsTransport].filter((X)=>X!=null).reduce((X,G)=>{if(!X.map((Y)=>Y.id).includes(G.id))X.push(G);return X},[])}get iceTransports(){return this.dtlsTransports.map((W)=>W.iceTransport)}setupCertificate(W){this.certificate=new Gx(W.keyPem,W.certPem,W.signatureHash)}createTransport(){let W=this.iceTransports.find((J)=>J.state!=="closed"),X=new zr({...ri(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)X.connection.localUsername=W.connection.localUsername,X.connection.localPassword=W.connection.localPassword;X.onGatheringStateChange.subscribe(()=>{this.updateIceGatheringState()}),this.updateIceGatheringState();let G=new Ar(X);return G.onStateChange.subscribe(()=>{this.updateIceConnectionState()}),new G2(this.config,G,this.certificate,ar)}handleNewIceCandidate({candidate:W,media:X,remoteIsBundled:G,transceiver:Y,sctpTransport:J,bundlePolicy:Z}){if(Z==="max-bundle"||G){if(W.sdpMLineIndex=0,X)W.sdpMid=X.rtp.muxId}else{if(Y)W.sdpMLineIndex=Y.mLineIndex,W.sdpMid=Y.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,X){let G=Yx.fromJSON(X);if(!G)return;let Y;if(typeof G.sdpMid==="number")Y=this.getTransportByMid(G.sdpMid);if(!Y&&typeof G.sdpMLineIndex==="number")Y=this.getTransportByMLineIndex(W,G.sdpMLineIndex);if(!Y)Y=this.iceTransports[0];if(Y)await Y.addRemoteCandidate(G);else mV("iceTransport not found for candidate",G)}getTransportByMid(W){let X,G=this.transceiverManager.getTransceivers().find((Y)=>Y.mid===W);if(G)X=G.dtlsTransport.iceTransport;else if(!X&&this.sctpManager.sctpTransport?.mid===W)X=this.sctpManager.sctpTransport.dtlsTransport.iceTransport;return X}getTransportByMLineIndex(W,X){let G=W.media[X];if(!G)return;return this.getTransportByMid(G.rtp.muxId)}restartIce(){for(let W of this.iceTransports)W.restart()}setLocalRole({type:W,role:X}){for(let G of this.dtlsTransports){let Y=G.iceTransport;if(W==="offer")Y.connection.iceControlling=!0;else Y.connection.iceControlling=!1;if(Y.connection.remoteIsLite)Y.connection.iceControlling=!0;if(W==="answer"){if(X)G.role=X}}}updateIceGatheringState(){let W=this.iceTransports;function X(...Y){return W.filter((J)=>Y.includes(J.gatheringState)).length===W.length}let G;if(W.length&&X("complete"))G="complete";else if(!W.length||X("new","complete"))G="new";else if(W.map((Y)=>Y.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,X;function G(...J){return W.filter((Z)=>J.includes(Z.state)).length===W.length}function Y(...J){return W.some((Z)=>J.includes(Z.state))}if(this.connectionState==="closed")X="closed";else if(Y("failed"))X="failed";else if(Y("disconnected"))X="disconnected";else if(G("new","closed"))X="new";else if(Y("new","checking"))X="checking";else if(G("completed","closed"))X="completed";else if(G("connected","completed","closed"))X="connected";else X="new";if(this.iceConnectionState===X)return;mV("iceConnectionStateChange",X),this.iceConnectionState=X,this.iceConnectionStateChange.execute(X)}async gatherCandidates(W){let X=this.iceTransports.find((G)=>G.state==="connected"||G.state==="completed");if(W&&X)mV("skipping ICE gathering for bundled connection");else await Promise.allSettled(this.iceTransports.map((G)=>G.gather())).catch((G)=>{mV("gatherCandidates failed",G)})}setConnectionState(W){mV("connectionStateChange",W),this.connectionState=W,this.connectionStateChange.execute(W)}async getStats(){let W=[];for(let X of this.dtlsTransports){let G=await X.getStats();if(G)W.push(...G)}return W}async ensureCerts(){if(!this.certificate)this.certificate=await G2.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()}},ar=[W2.SRTP_AEAD_AES_128_GCM,W2.SRTP_AES128_CM_HMAC_SHA1_80],Y7=P1("werift:packages/webrtc/src/peerConnection.ts"),Kx=class extends HO{cname=dr().toString();config=Ox();signalingState="stable";negotiationneeded=!1;needRestart=!1;router=new mr;sdpManager;transceiverManager;sctpManager;secureManager;isClosed=!1;shouldNegotiationneeded=!1;remoteBundleNegotiated=!1;iceGatheringStateChange=new d0;iceConnectionStateChange=new d0;signalingStateChange=new d0;connectionStateChange=new d0;onDataChannel=new d0;onRemoteTransceiverAdded=new d0;onTransceiverAdded=new d0;onIceCandidate=new d0;onNegotiationneeded=new d0;onTrack=new d0;ondatachannel;onicecandidate;onicecandidateerror;onicegatheringstatechange;onnegotiationneeded;onsignalingstatechange;ontrack;onconnectionstatechange;oniceconnectionstatechange;constructor(W={}){super();this.setConfiguration(W),this.sdpManager=new ir({cname:this.cname,bundlePolicy:this.config.bundlePolicy}),this.transceiverManager=new tr(this.cname,this.config,this.router),this.transceiverManager.onTransceiverAdded.pipe(this.onTransceiverAdded),this.transceiverManager.onRemoteTransceiverAdded.pipe(this.onRemoteTransceiverAdded),this.transceiverManager.onTrack.subscribe(({track:X,stream:G,transceiver:Y})=>{let J={track:X,streams:[G],transceiver:Y,receiver:Y.receiver};if(this.onTrack.execute(X),this.emit("track",J),this.ontrack)this.ontrack(J)}),this.transceiverManager.onNegotiationNeeded.subscribe(()=>this.needNegotiation()),this.sctpManager=new nr,this.sctpManager.onDataChannel.subscribe((X)=>{this.onDataChannel.execute(X);let G={channel:X};this.ondatachannel?.(G),this.emit("datachannel",G)}),this.secureManager=new rr({config:this.config,sctpManager:this.sctpManager,transceiverManager:this.transceiverManager}),this.secureManager.iceGatheringStateChange.pipe(this.iceGatheringStateChange),this.secureManager.iceConnectionStateChange.subscribe((X)=>{if(X==="closed")this.close();this.iceConnectionStateChange.execute(X)}),this.secureManager.connectionStateChange.subscribe((X)=>{this.connectionStateChange.execute(X),this.onconnectionstatechange?.(),this.emit("connectionstatechange")}),this.secureManager.onIceCandidate.subscribe((X)=>{let G=X?X.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(ai(this.config,W),this.config.icePortRange){let[X,G]=this.config.icePortRange;if(X===G)throw Error("should not be same value");if(X>=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[X,G]of nF([...this.config.codecs.audio||[],...this.config.codecs.video||[]])){if(G.payloadType!=null)continue;switch(G.payloadType=96+X,G.name.toLowerCase()){case"rtx":G.parameters=`apt=${G.payloadType-1}`;break;case"red":if(G.contentType==="audio"){let Y=G.payloadType+1;G.parameters=`${Y}/${Y}`,G.payloadType=63}break}}[...this.config.headerExtensions.audio||[],...this.config.headerExtensions.video||[]].forEach((X,G)=>{X.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),X=this.findOrCreateTransport();return W.setDtlsTransport(X),W}createDataChannel(W,X={}){if(!this.sctpTransport)this.createSctpTransport(),this.needNegotiation();let G=this.sctpManager.createDataChannel(W,X);if(!G.sctp.dtlsTransport){let Y=this.findOrCreateTransport();G.sctp.setDtlsTransport(Y)}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"),X=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 Y=G.iceTransport;return Y.onNegotiationNeeded.subscribe(()=>{this.needNegotiation()}),Y.onIceCandidate.subscribe((J)=>{if(!this.localDescription){Y7("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){Y7("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===Y.id),sctpTransport:this.sctpTransport?.dtlsTransport.iceTransport.id===Y.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 nF(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 Y=G.media.find((J)=>J.dtlsParams)?.dtlsParams?.role;if(this.secureManager.setLocalRole({type:G.type,role:Y}),["answer","pranswer"].includes(G.type))for(let J of this.transceiverManager.getTransceivers()){let Z=eS(J.direction,J.offerDirection);J.setCurrentDirection(Z)}if(this.sdpManager.setLocal(G,this.transceiverManager.getTransceivers(),this.sctpTransport),await this.gatherCandidates().catch((J)=>{Y7("gatherCandidates failed",J)}),G.type==="answer")this.connect().catch((J)=>{Y7("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 X=this.sdpManager.buildOfferSdp(this.transceiverManager.getTransceivers(),this.sctpTransport);await this.secureManager.addIceCandidate(X,W)}async connect(){if(Y7("start connect"),(await Promise.allSettled(this.dtlsTransports.map(async(X)=>{let{iceTransport:G}=X;if(G.state==="connected")return;let Y=()=>X.state==="connected";if(Y())return;if(this.secureManager.setConnectionState("connecting"),await G.start().catch((J)=>{throw Y7("iceTransport.start failed",J),J}),Y())return;if(await X.start().catch((J)=>{throw Y7("dtlsTransport.start failed",J),J}),this.sctpTransport&&this.sctpTransport.dtlsTransport.id===X.id)await this.sctpManager.connectSctp()}))).find((X)=>X.status==="rejected"))this.secureManager.setConnectionState("failed");else this.secureManager.setConnectionState("connected")}restartIce(){this.needRestart=!0,this.needNegotiation()}async setRemoteDescription(W){if(W instanceof rq)W=W.toSdp();let X=this.sdpManager.setRemoteDescription(W,this.signalingState);if(X.group.some((V)=>V.semantic==="BUNDLE"&&V.items.length>0))this.remoteBundleNegotiated=!0;let G,Y=(V,U)=>V.kind===U.kind&&[void 0,U.rtp.muxId].includes(V.mid),J=X.media.map((V,U)=>{let Q;if(["audio","video"].includes(V.kind)){let q=this.transceiverManager.getTransceivers().find((A)=>Y(A,V));if(!q)q=this.addTransceiver(V.kind,{direction:"recvonly"}),q.mid=V.rtp.muxId,this.onRemoteTransceiverAdded.execute(q);else if(q.direction==="inactive"&&q.stopping){if(q.stopped=!0,W.type==="answer")q.setCurrentDirection("inactive");return}if(this.sdpManager.remoteIsBundled)if(!G)G=q.dtlsTransport;else q.setDtlsTransport(G);Q=q.dtlsTransport,this.transceiverManager.setRemoteRTP(q,V,X.type,U)}else if(V.kind==="application"){let q=this.sctpTransport;if(!q)q=this.createSctpTransport(),q.mid=V.rtp.muxId;if(this.sdpManager.remoteIsBundled)if(!G)G=q.dtlsTransport;else q.setDtlsTransport(G);Q=q.dtlsTransport,this.sctpManager.setRemoteSCTP(V,U)}else throw Error("invalid media kind");let N=Q.iceTransport;if(V.iceParams){let q=!!this.sdpManager.inactiveRemoteMedia;if(N.setRemoteParams(V.iceParams,q),V.iceParams?.iceLite)N.connection.iceControlling=!0}if(V.dtlsParams)Q.setRemoteParams(V.dtlsParams);if(V.iceCandidates.forEach(N.addRemoteCandidate),V.iceCandidatesComplete)N.addRemoteCandidate(void 0);if(X.type==="answer"&&V.dtlsParams?.role)Q.role=V.dtlsParams.role==="client"?"server":"client";return N});J=J.filter((V)=>!!V);let Z=this.transceiverManager.getTransceivers().filter((V)=>X.media.find((U)=>Y(V,U))==null);if(W.type==="answer")for(let V of Z)V.stop(),V.stopped=!0;if(X.type==="offer")this.setSignalingState("have-remote-offer");else if(X.type==="answer")this.setSignalingState("stable");if(X.type==="answer")Y7("caller start connect"),this.connect().catch((V)=>{Y7("connect failed",V),this.secureManager.setConnectionState("failed")});if(this.negotiationneeded=!1,this.shouldNegotiationneeded)this.needNegotiation()}addTransceiver(W,X={}){let G=this.findOrCreateTransport(),Y=this.transceiverManager.addTransceiver(W,G,X);return this.secureManager.updateIceConnectionState(),this.needNegotiation(),Y}addTrack(W,X){if(this.isClosed)throw Error("is closed");let G=this.transceiverManager.addTrack(W,X);if(!G.dtlsTransport){let Y=this.findOrCreateTransport();G.setDtlsTransport(Y)}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(Y7("signalingStateChange",W),this.signalingState=W,this.signalingStateChange.execute(W),this.onsignalingstatechange)this.onsignalingstatechange({})}createPeerConnectionStats(){let W=SX();return{type:"peer-connection",id:N8("peer-connection"),timestamp:W,dataChannelsOpened:this.sctpManager.dataChannelsOpened,dataChannelsClosed:this.sctpManager.dataChannelsClosed}}async getStats(W){let X=[];X.push(this.createPeerConnectionStats());let G=await this.transceiverManager.getStats(W);X.push(...G);let Y=await this.secureManager.getStats();if(X.push(...Y),this.sctpTransport){let J=await this.sctpManager.getStats();if(J)X.push(...J)}return new hi(X)}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(),Y7("peerConnection closed")}},M2=(W,X)=>W.find((G)=>G.mimeType.toLowerCase()===X.mimeType.toLowerCase())?X:void 0;function Ox(){return{codecs:{audio:[cS(),lS()],video:[pS()]},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 mA0=Ox(),sr=P1("werift:packages/webrtc/src/media/rtpTransceiverManager.ts"),tr=class{constructor(W,X,G){this.cname=W,this.config=X,this.router=G}transceivers=[];onTransceiverAdded=new d0;onRemoteTransceiverAdded=new d0;onTrack=new d0;onNegotiationNeeded=new d0;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((X)=>X.mLineIndex===W)}pushTransceiver(W){this.transceivers.push(W)}replaceTransceiver(W,X){this.transceivers[X]=W}addTransceiver(W,X,G={}){let Y=typeof W==="string"?W:W.kind,J=G.direction||"sendrecv",Z=new lr(W),V=new jx(this.config,Y,Z.ssrc),U=new bi(Y,X,V,Z,J);U.options=G,this.router.registerRtpSender(U.sender);let Q=this.transceivers.findIndex((q)=>q.currentDirection==="inactive"&&!q.usedForSender),N=this.transceivers.find((q)=>q.currentDirection==="inactive"&&!q.usedForSender);if(Q>-1&&N)this.replaceTransceiver(U,Q),U.mLineIndex=N.mLineIndex,U.mid=N.mid,N.setCurrentDirection(void 0);else this.pushTransceiver(U);return this.onTransceiverAdded.execute(U),U}addTrack(W,X){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&&cq.includes(J.direction)===!0);if(G)return G.sender.registerTrack(W),G;let Y=this.transceivers.find((J)=>J.sender.track==null&&J.kind===W.kind&&cq.includes(J.direction)===!1&&!J.usedForSender);if(Y){switch(Y.sender.registerTrack(W),Y.direction){case"recvonly":Y.setDirection("sendrecv");break;case"inactive":Y.setDirection("sendonly");break}return Y}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 X=this.transceivers.find(({sender:{ssrc:G}})=>W.ssrc===G);if(!X)throw Error("No matching transceiver found");if(W.stop(),X.currentDirection==="recvonly"){this.onNegotiationNeeded.execute();return}if(X.stopping||X.stopped)X.setDirection("inactive");else if(X.direction==="sendrecv")X.setDirection("recvonly");else if(X.direction==="sendonly"||X.direction==="recvonly")X.setDirection("inactive")}assignTransceiverCodecs(W){let X=this.config.codecs[W.kind].filter((G)=>{switch(G.direction){case"recvonly":{if(ui.includes(W.direction))return!0;return!1}case"sendonly":{if(cq.includes(W.direction))return!0;return!1}case"sendrecv":{if([rS,iS,nS].includes(W.direction))return!0;return!1}case"all":return!0;default:return!1}});W.codecs=X}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,X){return{muxId:W.rtp.muxId,rtcp:W.rtp.rtcp,codecs:X.codecs,headerExtensions:X.headerExtensions,encodings:Object.values(X.codecs.reduce((Y,J)=>{if(J.name.toLowerCase()==="rtx"){let Z=HH(J.parameters??""),V=Y[Z.apt];if(V&&W.ssrc.length===2)V.rtx=new Ri({ssrc:W.ssrc[1].ssrc});return Y}return Y[J.payloadType]=new Li({ssrc:W.ssrc[0]?.ssrc,payloadType:J.payloadType}),Y},{}))}}setRemoteRTP(W,X,G,Y){if(!W.mid)W.mid=X.rtp.muxId;if(W.mLineIndex=Y,W.codecs=X.rtp.codecs.filter((U)=>{let Q=this.config.codecs[X.kind]||[],N=M2(Q,U);if(!N)return!1;if(N?.name.toLowerCase()==="rtx"){let A=HH(N.parameters??"").apt,H=X.rtp.codecs.find((I)=>I.payloadType===A);if(!H)return!1;return!!M2(Q,H)}return!0}),sr("negotiated codecs",W.codecs),W.codecs.length===0)throw Error("negotiate codecs failed.");W.headerExtensions=X.rtp.headerExtensions.filter((U)=>(this.config.headerExtensions[X.kind]||[]).find((Q)=>Q.uri===U.uri));let J=X.direction??"inactive",Z=di(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(X,W);for(let Q of X.simulcastParameters)this.router.registerRtpReceiverByRid(W,Q,U);W.receiver.prepareReceive(U),this.router.registerRtpReceiverBySsrc(W,U)}if(["sendonly","sendrecv"].includes(J)){if(X.msid){let[U,Q]=X.msid.split(" ");W.receiver.remoteStreamId=U,W.receiver.remoteTrackId=Q}this.onTrack.execute({track:W.receiver.track,transceiver:W,stream:new fi({id:W.receiver.remoteStreamId,tracks:[W.receiver.track]})})}if(X.ssrc[0]?.ssrc)W.receiver.setupTWCC(X.ssrc[0].ssrc)}async getStats(W){let X=[];for(let G of this.transceivers){let Y=!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(Y)X.push(Z)}else X.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(Y)X.push(Z)}else X.push(Z)}if(Y){let J=G.getCodecStats();if(J)X.push(...J)}}return X}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 zO extends Kx{toJSON(){return{}}createDataChannel(...W){let X=super.createDataChannel(...W);try{X.toJSON=()=>({})}catch{}return X}}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */var oY={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},er={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]},Wa=BigInt(0),Dx=BigInt(1),IO=BigInt(2);function Xa(W){let X=oY.p,G=BigInt(3),Y=BigInt(6),J=BigInt(11),Z=BigInt(22),V=BigInt(23),U=BigInt(44),Q=BigInt(88),N=W*W*W%X,q=N*N*W%X,A=q5(q,G,X)*q%X,H=q5(A,G,X)*q%X,I=q5(H,IO,X)*N%X,w=q5(I,J,X)*I%X,O=q5(w,Z,X)*w%X,T=q5(O,U,X)*O%X,x=q5(T,Q,X)*T%X,h=q5(x,U,X)*O%X,$=q5(h,G,X)*q%X,F=q5($,V,X)*w%X,u=q5(F,Y,X)*N%X,l=q5(u,IO,X);if(!CH.eql(CH.sqr(l),W))throw Error("Cannot find square root");return l}var CH=$5(oY.p,{sqrt:Xa}),Mx=MY({...oY,Fp:CH,lowS:!0,endo:er},DY),Cx={};function TH(W,...X){let G=Cx[W];if(G===void 0){let Y=DY(Aq(W));G=a9(Y,Y),Cx[W]=G}return DY(a9(G,...X))}var jO=(W)=>W.toBytes(!0).slice(1),nY=(()=>Mx.Point)(),KO=(W)=>W%IO===Wa;function wO(W){let{Fn:X,BASE:G}=nY,Y=n6(X,W),J=G.multiply(Y);return{scalar:KO(J.y)?Y:X.neg(Y),bytes:jO(J)}}function Px(W){let X=CH;if(!X.isValidNot0(W))throw Error("invalid x: Fail if x \u2265 p");let G=X.create(W*W),Y=X.create(G*W+BigInt(7)),J=X.sqrt(Y);if(!KO(J))J=X.neg(J);let Z=nY.fromAffine({x:W,y:J});return Z.assertValidity(),Z}var AU=$4;function Rx(...W){return nY.Fn.create(AU(TH("BIP0340/challenge",...W)))}function Tx(W){return wO(W).bytes}function Ga(W,X,G=AX(32)){let{Fn:Y}=nY,J=F8("message",W),{bytes:Z,scalar:V}=wO(X),U=F8("auxRand",G,32),Q=Y.toBytes(V^AU(TH("BIP0340/aux",U))),N=TH("BIP0340/nonce",Q,Z,J),{bytes:q,scalar:A}=wO(N),H=Rx(q,Z,J),I=new Uint8Array(64);if(I.set(q,0),I.set(Y.toBytes(Y.create(A+H*V)),32),!Lx(I,J,Z))throw Error("sign: Invalid signature produced");return I}function Lx(W,X,G){let{Fn:Y,BASE:J}=nY,Z=F8("signature",W,64),V=F8("message",X),U=F8("publicKey",G,32);try{let Q=Px(AU(U)),N=AU(Z.subarray(0,32));if(!LV(N,Dx,oY.p))return!1;let q=AU(Z.subarray(32,64));if(!LV(q,Dx,oY.n))return!1;let A=Rx(Y.toBytes(N),jO(Q),V),H=J.multiplyUnsafe(q).add(Q.multiplyUnsafe(Y.neg(A))),{x:I,y:w}=H.toAffine();if(H.is0()||!KO(w)||I!==N)return!1;return!0}catch(Q){return!1}}var Bx=(()=>{let G=(J=AX(48))=>{return Kq(J,oY.n)};Mx.utils.randomSecretKey;function Y(J){let Z=G(J);return{secretKey:Z,publicKey:Tx(Z)}}return{keygen:Y,getPublicKey:Tx,sign:Ga,verify:Lx,Point:nY,utils:{randomSecretKey:G,randomPrivateKey:G,taggedHash:TH,lift_x:Px,pointToBytes:jO,numberToBytesBE:OY,bytesToNumberBE:$4,mod:N5},lengths:{secretKey:32,publicKey:32,publicKeyHasPrefix:!1,signature:64,seed:48}}})();var Ex=(W)=>Uint8Array.from(W.match(/.{2}/g).map((X)=>parseInt(X,16))),Ya=(W)=>[...W].map((X)=>X.toString(16).padStart(2,"0")).join(""),Ja=async(W)=>{try{if(typeof W.pubkey!=="string"||typeof W.sig!=="string"||typeof W.id!=="string")return!1;let X=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",X));if(Ya(G)!==W.id)return!1;return Bx.verify(Ex(W.sig),G,Ex(W.pubkey))}catch{return!1}},Za=(W,X)=>{if(W.kinds&&!W.kinds.includes(X.kind))return!1;if(W.since&&X.created_at<W.since-60)return!1;if(W["#x"]){let G=(X.tags??[]).filter((Y)=>Y?.[0]==="x").map((Y)=>Y[1]);if(!W["#x"].some((Y)=>G.includes(Y)))return!1}return!0};function $x({port:W=Number(process.env.PORT)||8080}={}){let X=new Map,G=0,Y=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:X.size,events:G,dropped:Y})},websocket:{open(Z){X.set(Z,new Map)},close(Z){X.delete(Z)},async message(Z,V){let U;try{U=JSON.parse(String(V))}catch{return}if(!Array.isArray(U))return;let[Q,N,q]=U;if(Q==="REQ"&&typeof N==="string"&&q&&typeof q==="object"){X.get(Z)?.set(N,q),Z.send(JSON.stringify(["EOSE",N]));return}if(Q==="CLOSE"&&typeof N==="string"){X.get(Z)?.delete(N);return}if(Q==="EVENT"&&N&&typeof N==="object"){if(!await Ja(N)){Y++,Z.send(JSON.stringify(["OK",N.id??"",!1,"invalid: bad signature"]));return}G++,Z.send(JSON.stringify(["OK",N.id,!0,""]));for(let[A,H]of X)for(let[I,w]of H)if(Za(w,N)){try{A.send(JSON.stringify(["EVENT",I,N]))}catch{}break}}}}});return console.info(`\uD83D\uDCE1 Relay listening on :${J.port} (ephemeral, schnorr-verified)`),{port:J.port,stats:()=>({connections:X.size,events:G,dropped:Y}),stop:()=>J.stop(!0)}}var MH="6.15.0";function Va(W,X,G){let Y=X.split("|").map((Z)=>Z.trim());for(let Z=0;Z<Y.length;Z++)switch(X){case"any":return;case"bigint":case"boolean":case"number":case"string":if(typeof W===X)return}let J=Error(`invalid value for type ${X}`);throw J.code="INVALID_ARGUMENT",J.argument=`value.${G}`,J.value=W,J}async function i7(W){let X=Object.keys(W);return(await Promise.all(X.map((Y)=>Promise.resolve(W[Y])))).reduce((Y,J,Z)=>{return Y[X[Z]]=J,Y},{})}function A8(W,X,G){for(let Y in X){let J=X[Y],Z=G?G[Y]:null;if(Z)Va(J,Z,Y);Object.defineProperty(W,Y,{enumerable:!0,value:J,writable:!1})}}function iY(W,X){if(W==null)return"null";if(X==null)X=new Set;if(typeof W==="object"){if(X.has(W))return"[Circular]";X.add(W)}if(Array.isArray(W))return"[ "+W.map((G)=>iY(G,X)).join(", ")+" ]";if(W instanceof Uint8Array){let Y="0x";for(let J=0;J<W.length;J++)Y+="0123456789abcdef"[W[J]>>4],Y+="0123456789abcdef"[W[J]&15];return Y}if(typeof W==="object"&&typeof W.toJSON==="function")return iY(W.toJSON(),X);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((Y)=>`${iY(Y,X)}: ${iY(W[Y],X)}`).join(", ")+" }"}}return"[ COULD NOT SERIALIZE ]"}function PH(W,X){return W&&W.code===X}function zU(W,X,G){let Y=W;{let Z=[];if(G){if("message"in G||"code"in G||"name"in G)throw Error(`value will overwrite populated values: ${iY(G)}`);for(let V in G){if(V==="shortMessage")continue;let U=G[V];Z.push(V+"="+iY(U))}}if(Z.push(`code=${X}`),Z.push(`version=${MH}`),Z.length)W+=" ("+Z.join(", ")+")"}let J;switch(X){case"INVALID_ARGUMENT":J=TypeError(W);break;case"NUMERIC_FAULT":case"BUFFER_OVERRUN":J=RangeError(W);break;default:J=Error(W)}if(A8(J,{code:X}),G)Object.assign(J,G);if(J.shortMessage==null)A8(J,{shortMessage:Y});return J}function Y1(W,X,G,Y){if(!W)throw zU(X,G,Y)}function a(W,X,G,Y){Y1(W,X,"INVALID_ARGUMENT",{argument:G,value:Y})}var Ua=["NFD","NFC","NFKD","NFKC"].reduce((W,X)=>{try{if("test".normalize(X)!=="test")throw Error("bad");if(X==="NFD"){let G=String.fromCharCode(233).normalize("NFD"),Y=String.fromCharCode(101,769);if(G!==Y)throw Error("broken")}W.push(X)}catch(G){}return W},[]);function rY(W){Y1(Ua.indexOf(W)>=0,"platform missing String.prototype.normalize","UNSUPPORTED_OPERATION",{operation:"String.prototype.normalize",info:{form:W}})}function n4(W,X,G){if(G==null)G="";if(W!==X){let Y=G,J="new";if(G)Y+=".",J+=" "+G;Y1(!1,`private constructor; use ${Y}from* methods`,"UNSUPPORTED_OPERATION",{operation:J})}}function Sx(W,X,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 Y=new Uint8Array((W.length-2)/2),J=2;for(let Z=0;Z<Y.length;Z++)Y[Z]=parseInt(W.substring(J,J+2),16),J+=2;return Y}a(!1,"invalid BytesLike value",X||"value",W)}function E0(W,X){return Sx(W,X,!1)}function Q7(W,X){return Sx(W,X,!0)}function L9(W,X){if(typeof W!=="string"||!W.match(/^0x[0-9A-Fa-f]*$/))return!1;if(typeof X==="number"&&W.length!==2+2*X)return!1;if(X===!0&&W.length%2!==0)return!1;return!0}function r7(W){return L9(W,!0)||W instanceof Uint8Array}var Fx="0123456789abcdef";function M0(W){let X=E0(W),G="0x";for(let Y=0;Y<X.length;Y++){let J=X[Y];G+=Fx[(J&240)>>4]+Fx[J&15]}return G}function G8(W){return"0x"+W.map((X)=>M0(X).substring(2)).join("")}function i4(W){if(L9(W,!0))return(W.length-2)/2;return E0(W).length}function aY(W,X,G){let Y=E0(W);if(G!=null&&G>Y.length)Y1(!1,"cannot slice beyond data bounds","BUFFER_OVERRUN",{buffer:Y,length:Y.length,offset:G});return M0(Y.slice(X==null?0:X,G==null?Y.length:G))}function Qa(W,X,G){let Y=E0(W);Y1(X>=Y.length,"padding exceeds data length","BUFFER_OVERRUN",{buffer:new Uint8Array(Y),length:X,offset:X+1});let J=new Uint8Array(X);if(J.fill(0),G)J.set(Y,X-Y.length);else J.set(Y,0);return M0(J)}function I5(W,X){return Qa(W,X,!0)}var OO=BigInt(0),xX=BigInt(1),sY=9007199254740991;function RH(W,X){let G=f1(W,"value"),Y=BigInt(s8(X,"width")),J=xX<<Y-xX;if(G<OO){G=-G,Y1(G<=J,"too low","NUMERIC_FAULT",{operation:"toTwos",fault:"overflow",value:W});let Z=(xX<<Y)-xX;return(~G&Z)+xX}else Y1(G<J,"too high","NUMERIC_FAULT",{operation:"toTwos",fault:"overflow",value:W});return G}function LH(W,X){let G=IU(W,"value"),Y=BigInt(s8(X,"bits"));return G&(xX<<Y)-xX}function f1(W,X){switch(typeof W){case"bigint":return W;case"number":return a(Number.isInteger(W),"underflow",X||"value",W),a(W>=-sY&&W<=sY,"overflow",X||"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){a(!1,`invalid BigNumberish string: ${G.message}`,X||"value",W)}}a(!1,"invalid BigNumberish value",X||"value",W)}function IU(W,X){let G=f1(W,X);return Y1(G>=OO,"unsigned value cannot be negative","NUMERIC_FAULT",{fault:"overflow",operation:"getUint",value:W}),G}var xx="0123456789abcdef";function tY(W){if(W instanceof Uint8Array){let X="0x0";for(let G of W)X+=xx[G>>4],X+=xx[G&15];return BigInt(X)}return f1(W)}function s8(W,X){switch(typeof W){case"bigint":return a(W>=-sY&&W<=sY,"overflow",X||"value",W),Number(W);case"number":return a(Number.isInteger(W),"underflow",X||"value",W),a(W>=-sY&&W<=sY,"overflow",X||"value",W),W;case"string":try{if(W==="")throw Error("empty string");return s8(BigInt(W),X)}catch(G){a(!1,`invalid numeric string: ${G.message}`,X||"value",W)}}a(!1,"invalid numeric value",X||"value",W)}function N7(W,X){let Y=IU(W,"value").toString(16);if(X==null){if(Y.length%2)Y="0"+Y}else{let J=s8(X,"width");Y1(J*2>=Y.length,`value exceeds width (${J} bytes)`,"NUMERIC_FAULT",{operation:"toBeHex",fault:"overflow",value:W});while(Y.length<J*2)Y="0"+Y}return"0x"+Y}function z8(W){let X=IU(W,"value");if(X===OO)return new Uint8Array([]);let G=X.toString(16);if(G.length%2)G="0"+G;let Y=new Uint8Array(G.length/2);for(let J=0;J<Y.length;J++){let Z=J*2;Y[J]=parseInt(G.substring(Z,Z+2),16)}return Y}function BH(W){let X=M0(r7(W)?W:z8(W)).substring(2);while(X.startsWith("0"))X=X.substring(1);if(X==="")X="0";return"0x"+X}var $H="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",EH=null;function Na(W){if(EH==null){EH={};for(let G=0;G<$H.length;G++)EH[$H[G]]=BigInt(G)}let X=EH[W];return a(X!=null,"invalid base58 value","letter",W),X}var qa=BigInt(0),DO=BigInt(58);function FH(W){let X=E0(W),G=tY(X),Y="";while(G)Y=$H[Number(G%DO)]+Y,G/=DO;for(let J=0;J<X.length;J++){if(X[J])break;Y=$H[0]+Y}return Y}function SH(W){let X=qa;for(let G=0;G<W.length;G++)X*=DO,X+=Na(W[G]);return X}function Ha(W,X,G,Y,J){a(!1,`invalid codepoint at offset ${X}; ${W}`,"bytes",G)}function kx(W,X,G,Y,J){if(W==="BAD_PREFIX"||W==="UNEXPECTED_CONTINUE"){let Z=0;for(let V=X+1;V<G.length;V++){if(G[V]>>6!==2)break;Z++}return Z}if(W==="OVERRUN")return G.length-X-1;return 0}function Aa(W,X,G,Y,J){if(W==="OVERLONG")return a(typeof J==="number","invalid bad code point for replacement","badCodepoint",J),Y.push(J),0;return Y.push(65533),kx(W,X,G,Y,J)}var _x=Object.freeze({error:Ha,ignore:kx,replace:Aa});function Q9(W,X){if(a(typeof W==="string","invalid string value","str",W),X!=null)rY(X),W=W.normalize(X);let G=[];for(let Y=0;Y<W.length;Y++){let J=W.charCodeAt(Y);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){Y++;let Z=W.charCodeAt(Y);a(Y<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 za(W){let X=W.toString(16);while(X.length<2)X="0"+X;return"0x"+X}function yx(W,X,G){let Y=0;for(let J=0;J<G;J++)Y=Y*256+W[X+J];return Y}function vx(W,X,G,Y){let J=[];while(G<X+1+Y){let Z=gx(W,G);J.push(Z.result),G+=Z.consumed,Y1(G<=X+1+Y,"child data too short","BUFFER_OVERRUN",{buffer:W,length:Y,offset:X})}return{consumed:1+Y,result:J}}function gx(W,X){Y1(W.length!==0,"data too short","BUFFER_OVERRUN",{buffer:W,length:0,offset:1});let G=(Y)=>{Y1(Y<=W.length,"data short segment too short","BUFFER_OVERRUN",{buffer:W,length:W.length,offset:Y})};if(W[X]>=248){let Y=W[X]-247;G(X+1+Y);let J=yx(W,X+1,Y);return G(X+1+Y+J),vx(W,X,X+1+Y,Y+J)}else if(W[X]>=192){let Y=W[X]-192;return G(X+1+Y),vx(W,X,X+1,Y)}else if(W[X]>=184){let Y=W[X]-183;G(X+1+Y);let J=yx(W,X+1,Y);G(X+1+Y+J);let Z=M0(W.slice(X+1+Y,X+1+Y+J));return{consumed:1+Y+J,result:Z}}else if(W[X]>=128){let Y=W[X]-128;G(X+1+Y);let J=M0(W.slice(X+1,X+1+Y));return{consumed:1+Y,result:J}}return{consumed:1,result:za(W[X])}}function GW(W){let X=E0(W,"data"),G=gx(X,0);return a(G.consumed===X.length,"unexpected junk after rlp payload","data",W),G.result}function ux(W){let X=[];while(W)X.unshift(W&255),W>>=8;return X}function bx(W){if(Array.isArray(W)){let Y=[];if(W.forEach(function(Z){Y=Y.concat(bx(Z))}),Y.length<=55)return Y.unshift(192+Y.length),Y;let J=ux(Y.length);return J.unshift(247+J.length),J.concat(Y)}let X=Array.prototype.slice.call(E0(W,"object"));if(X.length===1&&X[0]<=127)return X;else if(X.length<=55)return X.unshift(128+X.length),X;let G=ux(X.length);return G.unshift(183+G.length),G.concat(X)}var hx="0123456789abcdef";function S5(W){let X="0x";for(let G of bx(W))X+=hx[G>>4],X+=hx[G&15];return X}function xH(W){let X=E0(W,"randomBytes");X[6]=X[6]&15|64,X[8]=X[8]&63|128;let G=M0(X);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 CO,createHmac as mx,pbkdf2Sync as fx,randomBytes as px}from"crypto";var cx=!1,lx=function(W,X,G){return mx(W,X).update(G).digest()},dx=lx;function YW(W,X,G){let Y=E0(X,"key"),J=E0(G,"data");return M0(dx(W,Y,J))}YW._=lx;YW.lock=function(){cx=!0};YW.register=function(W){if(cx)throw Error("computeHmac is locked");dx=W};Object.freeze(YW);function B9(W){if(!Number.isSafeInteger(W)||W<0)throw Error(`Wrong positive integer: ${W}`)}function wU(W,...X){if(!(W instanceof Uint8Array))throw Error("Expected Uint8Array");if(X.length>0&&!X.includes(W.length))throw Error(`Expected Uint8Array of length ${X}, not of length=${W.length}`)}function kH(W){if(typeof W!=="function"||typeof W.create!=="function")throw Error("Hash should be wrapped by utils.wrapConstructor");B9(W.outputLen),B9(W.blockLen)}function r4(W,X=!0){if(W.destroyed)throw Error("Hash instance has been destroyed");if(X&&W.finished)throw Error("Hash#digest() has already been called")}function _H(W,X){wU(W);let G=X.outputLen;if(W.length<G)throw Error(`digestInto() expects output buffer of length at least ${G}`)}var yH=BigInt(4294967295),ox=BigInt(32);function Ma(W,X=!1){if(X)return{h:Number(W&yH),l:Number(W>>ox&yH)};return{h:Number(W>>ox&yH)|0,l:Number(W&yH)|0}}function nx(W,X=!1){let G=new Uint32Array(W.length),Y=new Uint32Array(W.length);for(let J=0;J<W.length;J++){let{h:Z,l:V}=Ma(W[J],X);[G[J],Y[J]]=[Z,V]}return[G,Y]}var ix=(W,X,G)=>W<<G|X>>>32-G,rx=(W,X,G)=>X<<G|W>>>32-G,ax=(W,X,G)=>X<<G-32|W>>>64-G,sx=(W,X,G)=>W<<G-32|X>>>64-G;import*as jU from"crypto";var vH=jU&&typeof jU==="object"&&"webcrypto"in jU?jU.webcrypto:void 0;/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */var tx=(W)=>W instanceof Uint8Array;var eY=(W)=>new Uint32Array(W.buffer,W.byteOffset,Math.floor(W.byteLength/4)),WJ=(W)=>new DataView(W.buffer,W.byteOffset,W.byteLength),q7=(W,X)=>W<<32-X|W>>>X,Pa=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;if(!Pa)throw Error("Non little-endian hardware is not supported");var Ra=async()=>{};async function gH(W,X,G){let Y=Date.now();for(let J=0;J<W;J++){G(J);let Z=Date.now()-Y;if(Z>=0&&Z<X)continue;await Ra(),Y+=Z}}function La(W){if(typeof W!=="string")throw Error(`utf8ToBytes expected string, got ${typeof W}`);return new Uint8Array(new TextEncoder().encode(W))}function a7(W){if(typeof W==="string")W=La(W);if(!tx(W))throw Error(`expected Uint8Array, got ${typeof W}`);return W}function ex(...W){let X=new Uint8Array(W.reduce((Y,J)=>Y+J.length,0)),G=0;return W.forEach((Y)=>{if(!tx(Y))throw Error("Uint8Array expected");X.set(Y,G),G+=Y.length}),X}class kX{clone(){return this._cloneInto()}}var Ba={}.toString;function uH(W,X){if(X!==void 0&&Ba.call(X)!=="[object Object]")throw Error("Options should be object or undefined");return Object.assign(W,X)}function XJ(W){let X=(Y)=>W().update(a7(Y)).digest(),G=W();return X.outputLen=G.outputLen,X.blockLen=G.blockLen,X.create=()=>W(),X}function Wk(W=32){if(vH&&typeof vH.getRandomValues==="function")return vH.getRandomValues(new Uint8Array(W));throw Error("crypto.getRandomValues must be defined")}var[Yk,Jk,Zk]=[[],[],[]],Ea=BigInt(0),KU=BigInt(1),$a=BigInt(2),Fa=BigInt(7),Sa=BigInt(256),xa=BigInt(113);for(let W=0,X=KU,G=1,Y=0;W<24;W++){[G,Y]=[Y,(2*G+3*Y)%5],Yk.push(2*(5*Y+G)),Jk.push((W+1)*(W+2)/2%64);let J=Ea;for(let Z=0;Z<7;Z++)if(X=(X<<KU^(X>>Fa)*xa)%Sa,X&$a)J^=KU<<(KU<<BigInt(Z))-KU;Zk.push(J)}var[ka,_a]=nx(Zk,!0),Xk=(W,X,G)=>G>32?ax(W,X,G):ix(W,X,G),Gk=(W,X,G)=>G>32?sx(W,X,G):rx(W,X,G);function ya(W,X=24){let G=new Uint32Array(10);for(let Y=24-X;Y<24;Y++){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,N=G[Q],q=G[Q+1],A=Xk(N,q,1)^G[U],H=Gk(N,q,1)^G[U+1];for(let I=0;I<50;I+=10)W[V+I]^=A,W[V+I+1]^=H}let J=W[2],Z=W[3];for(let V=0;V<24;V++){let U=Jk[V],Q=Xk(J,Z,U),N=Gk(J,Z,U),q=Yk[V];J=W[q],Z=W[q+1],W[q]=Q,W[q+1]=N}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[Y],W[1]^=_a[Y]}G.fill(0)}class TO extends kX{constructor(W,X,G,Y=!1,J=24){super();if(this.blockLen=W,this.suffix=X,this.outputLen=G,this.enableXOF=Y,this.rounds=J,this.pos=0,this.posOut=0,this.finished=!1,this.destroyed=!1,B9(G),0>=this.blockLen||this.blockLen>=200)throw Error("Sha3 supports only keccak-f1600 function");this.state=new Uint8Array(200),this.state32=eY(this.state)}keccak(){ya(this.state32,this.rounds),this.posOut=0,this.pos=0}update(W){r4(this);let{blockLen:X,state:G}=this;W=a7(W);let Y=W.length;for(let J=0;J<Y;){let Z=Math.min(X-this.pos,Y-J);for(let V=0;V<Z;V++)G[this.pos++]^=W[J++];if(this.pos===X)this.keccak()}return this}finish(){if(this.finished)return;this.finished=!0;let{state:W,suffix:X,pos:G,blockLen:Y}=this;if(W[G]^=X,(X&128)!==0&&G===Y-1)this.keccak();W[Y-1]^=128,this.keccak()}writeInto(W){r4(this,!1),wU(W),this.finish();let X=this.state,{blockLen:G}=this;for(let Y=0,J=W.length;Y<J;){if(this.posOut>=G)this.keccak();let Z=Math.min(G-this.posOut,J-Y);W.set(X.subarray(this.posOut,this.posOut+Z),Y),this.posOut+=Z,Y+=Z}return W}xofInto(W){if(!this.enableXOF)throw Error("XOF is not possible for this instance");return this.writeInto(W)}xof(W){return B9(W),this.xofInto(new Uint8Array(W))}digestInto(W){if(_H(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:X,suffix:G,outputLen:Y,rounds:J,enableXOF:Z}=this;return W||(W=new TO(X,G,Y,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=Y,W.enableXOF=Z,W.destroyed=this.destroyed,W}}var va=(W,X,G)=>XJ(()=>new TO(X,W,G));var Vk=va(1,136,32);var Uk=!1,Qk=function(W){return Vk(W)},Nk=Qk;function U8(W){let X=E0(W,"data");return M0(Nk(X))}U8._=Qk;U8.lock=function(){Uk=!0};U8.register=function(W){if(Uk)throw TypeError("keccak256 is locked");Nk=W};Object.freeze(U8);function ga(W,X,G,Y){if(typeof W.setBigUint64==="function")return W.setBigUint64(X,G,Y);let J=BigInt(32),Z=BigInt(4294967295),V=Number(G>>J&Z),U=Number(G&Z),Q=Y?4:0,N=Y?0:4;W.setUint32(X+Q,V,Y),W.setUint32(X+N,U,Y)}class OU extends kX{constructor(W,X,G,Y){super();this.blockLen=W,this.outputLen=X,this.padOffset=G,this.isLE=Y,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(W),this.view=WJ(this.buffer)}update(W){r4(this);let{view:X,buffer:G,blockLen:Y}=this;W=a7(W);let J=W.length;for(let Z=0;Z<J;){let V=Math.min(Y-this.pos,J-Z);if(V===Y){let U=WJ(W);for(;Y<=J-Z;Z+=Y)this.process(U,Z);continue}if(G.set(W.subarray(Z,Z+V),this.pos),this.pos+=V,Z+=V,this.pos===Y)this.process(X,0),this.pos=0}return this.length+=W.length,this.roundClean(),this}digestInto(W){r4(this),_H(W,this),this.finished=!0;let{buffer:X,view:G,blockLen:Y,isLE:J}=this,{pos:Z}=this;if(X[Z++]=128,this.buffer.subarray(Z).fill(0),this.padOffset>Y-Z)this.process(G,0),Z=0;for(let q=Z;q<Y;q++)X[q]=0;ga(G,Y-8,BigInt(this.length*8),J),this.process(G,0);let V=WJ(W),U=this.outputLen;if(U%4)throw Error("_sha2: outputLen should be aligned to 32bit");let Q=U/4,N=this.get();if(Q>N.length)throw Error("_sha2: outputLen bigger than state");for(let q=0;q<Q;q++)V.setUint32(4*q,N[q],J)}digest(){let{buffer:W,outputLen:X}=this;this.digestInto(W);let G=W.slice(0,X);return this.destroy(),G}_cloneInto(W){W||(W=new this.constructor),W.set(...this.get());let{blockLen:X,buffer:G,length:Y,finished:J,destroyed:Z,pos:V}=this;if(W.length=Y,W.pos=V,W.finished=J,W.destroyed=Z,Y%X)W.buffer.set(G);return W}}var ua=new Uint8Array([7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8]),Hk=Uint8Array.from({length:16},(W,X)=>X),ha=Hk.map((W)=>(9*W+5)%16),MO=[Hk],PO=[ha];for(let W=0;W<4;W++)for(let X of[MO,PO])X.push(X[W].map((G)=>ua[G]));var Ak=[[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)),ba=MO.map((W,X)=>W.map((G)=>Ak[X][G])),ma=PO.map((W,X)=>W.map((G)=>Ak[X][G])),fa=new Uint32Array([0,1518500249,1859775393,2400959708,2840853838]),pa=new Uint32Array([1352829926,1548603684,1836072691,2053994217,0]),hH=(W,X)=>W<<X|W>>>32-X;function qk(W,X,G,Y){if(W===0)return X^G^Y;else if(W===1)return X&G|~X&Y;else if(W===2)return(X|~G)^Y;else if(W===3)return X&Y|G&~Y;else return X^(G|~Y)}var bH=new Uint32Array(16);class zk 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:X,h2:G,h3:Y,h4:J}=this;return[W,X,G,Y,J]}set(W,X,G,Y,J){this.h0=W|0,this.h1=X|0,this.h2=G|0,this.h3=Y|0,this.h4=J|0}process(W,X){for(let H=0;H<16;H++,X+=4)bH[H]=W.getUint32(X,!0);let G=this.h0|0,Y=G,J=this.h1|0,Z=J,V=this.h2|0,U=V,Q=this.h3|0,N=Q,q=this.h4|0,A=q;for(let H=0;H<5;H++){let I=4-H,w=fa[H],O=pa[H],T=MO[H],x=PO[H],h=ba[H],$=ma[H];for(let F=0;F<16;F++){let u=hH(G+qk(H,J,V,Q)+bH[T[F]]+w,h[F])+q|0;G=q,q=Q,Q=hH(V,10)|0,V=J,J=u}for(let F=0;F<16;F++){let u=hH(Y+qk(I,Z,U,N)+bH[x[F]]+O,$[F])+A|0;Y=A,A=N,N=hH(U,10)|0,U=Z,Z=u}}this.set(this.h1+V+N|0,this.h2+Q+A|0,this.h3+q+Y|0,this.h4+G+Z|0,this.h0+J+U|0)}roundClean(){bH.fill(0)}destroy(){this.destroyed=!0,this.buffer.fill(0),this.set(0,0,0,0,0)}}var Ik=XJ(()=>new zk);var wk=!1,jk=function(W){return Ik(W)},Kk=jk;function JW(W){let X=E0(W,"data");return M0(Kk(X))}JW._=jk;JW.lock=function(){wk=!0};JW.register=function(W){if(wk)throw TypeError("ripemd160 is locked");Kk=W};Object.freeze(JW);var Ok=!1,Dk=function(W,X,G,Y,J){return fx(W,X,G,Y,J)},Ck=Dk;function x5(W,X,G,Y,J){let Z=E0(W,"password"),V=E0(X,"salt");return M0(Ck(Z,V,G,Y,J))}x5._=Dk;x5.lock=function(){Ok=!0};x5.register=function(W){if(Ok)throw Error("pbkdf2 is locked");Ck=W};Object.freeze(x5);var Tk=!1,Mk=function(W){return new Uint8Array(px(W))},Pk=Mk;function k5(W){return Pk(W)}k5._=Mk;k5.lock=function(){Tk=!0};k5.register=function(W){if(Tk)throw Error("randomBytes is locked");Pk=W};Object.freeze(k5);var ca=(W,X,G)=>W&X^~W&G,la=(W,X,G)=>W&X^W&G^X&G,da=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]),ZW=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),VW=new Uint32Array(64);class Rk extends OU{constructor(){super(64,32,8,!1);this.A=ZW[0]|0,this.B=ZW[1]|0,this.C=ZW[2]|0,this.D=ZW[3]|0,this.E=ZW[4]|0,this.F=ZW[5]|0,this.G=ZW[6]|0,this.H=ZW[7]|0}get(){let{A:W,B:X,C:G,D:Y,E:J,F:Z,G:V,H:U}=this;return[W,X,G,Y,J,Z,V,U]}set(W,X,G,Y,J,Z,V,U){this.A=W|0,this.B=X|0,this.C=G|0,this.D=Y|0,this.E=J|0,this.F=Z|0,this.G=V|0,this.H=U|0}process(W,X){for(let q=0;q<16;q++,X+=4)VW[q]=W.getUint32(X,!1);for(let q=16;q<64;q++){let A=VW[q-15],H=VW[q-2],I=q7(A,7)^q7(A,18)^A>>>3,w=q7(H,17)^q7(H,19)^H>>>10;VW[q]=w+VW[q-7]+I+VW[q-16]|0}let{A:G,B:Y,C:J,D:Z,E:V,F:U,G:Q,H:N}=this;for(let q=0;q<64;q++){let A=q7(V,6)^q7(V,11)^q7(V,25),H=N+A+ca(V,U,Q)+da[q]+VW[q]|0,w=(q7(G,2)^q7(G,13)^q7(G,22))+la(G,Y,J)|0;N=Q,Q=U,U=V,V=Z+H|0,Z=J,J=Y,Y=G,G=H+w|0}G=G+this.A|0,Y=Y+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,N=N+this.H|0,this.set(G,Y,J,Z,V,U,Q,N)}roundClean(){VW.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}}var DU=XJ(()=>new Rk);class RO extends kX{constructor(W,X){super();this.finished=!1,this.destroyed=!1,kH(W);let G=a7(X);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 Y=this.blockLen,J=new Uint8Array(Y);J.set(G.length>Y?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 r4(this),this.iHash.update(W),this}digestInto(W){r4(this),wU(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:X,iHash:G,finished:Y,destroyed:J,blockLen:Z,outputLen:V}=this;return W=W,W.finished=Y,W.destroyed=J,W.blockLen=Z,W.outputLen=V,W.oHash=X._cloneInto(W.oHash),W.iHash=G._cloneInto(W.iHash),W}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}}var CU=(W,X,G)=>new RO(W,X).update(G).digest();CU.create=(W,X)=>new RO(W,X);function oa(W,X,G,Y){kH(W);let J=uH({dkLen:32,asyncTick:10},Y),{c:Z,dkLen:V,asyncTick:U}=J;if(B9(Z),B9(V),B9(U),Z<1)throw Error("PBKDF2: iterations (c) should be >= 1");let Q=a7(X),N=a7(G),q=new Uint8Array(V),A=CU.create(W,Q),H=A._cloneInto().update(N);return{c:Z,dkLen:V,asyncTick:U,DK:q,PRF:A,PRFSalt:H}}function na(W,X,G,Y,J){if(W.destroy(),X.destroy(),Y)Y.destroy();return J.fill(0),G}function LO(W,X,G,Y){let{c:J,dkLen:Z,DK:V,PRF:U,PRFSalt:Q}=oa(W,X,G,Y),N,q=new Uint8Array(4),A=WJ(q),H=new Uint8Array(U.outputLen);for(let I=1,w=0;w<Z;I++,w+=U.outputLen){let O=V.subarray(w,w+U.outputLen);A.setInt32(0,I,!1),(N=Q._cloneInto(N)).update(q).digestInto(H),O.set(H.subarray(0,O.length));for(let T=1;T<J;T++){U._cloneInto(N).update(H).digestInto(H);for(let x=0;x<O.length;x++)O[x]^=H[x]}}return na(U,Q,V,N,H)}var s1=(W,X)=>W<<X|W>>>32-X;function Lk(W,X,G,Y,J,Z){let V=W[X++]^G[Y++],U=W[X++]^G[Y++],Q=W[X++]^G[Y++],N=W[X++]^G[Y++],q=W[X++]^G[Y++],A=W[X++]^G[Y++],H=W[X++]^G[Y++],I=W[X++]^G[Y++],w=W[X++]^G[Y++],O=W[X++]^G[Y++],T=W[X++]^G[Y++],x=W[X++]^G[Y++],h=W[X++]^G[Y++],$=W[X++]^G[Y++],F=W[X++]^G[Y++],u=W[X++]^G[Y++],l=V,p=U,s=Q,y=N,t=q,H0=A,g=H,d=I,P=w,E=O,f=T,r=x,o=h,B=$,S=F,_=u;for(let v=0;v<8;v+=2)t^=s1(l+o|0,7),P^=s1(t+l|0,9),o^=s1(P+t|0,13),l^=s1(o+P|0,18),E^=s1(H0+p|0,7),B^=s1(E+H0|0,9),p^=s1(B+E|0,13),H0^=s1(p+B|0,18),S^=s1(f+g|0,7),s^=s1(S+f|0,9),g^=s1(s+S|0,13),f^=s1(g+s|0,18),y^=s1(_+r|0,7),d^=s1(y+_|0,9),r^=s1(d+y|0,13),_^=s1(r+d|0,18),p^=s1(l+y|0,7),s^=s1(p+l|0,9),y^=s1(s+p|0,13),l^=s1(y+s|0,18),g^=s1(H0+t|0,7),d^=s1(g+H0|0,9),t^=s1(d+g|0,13),H0^=s1(t+d|0,18),r^=s1(f+E|0,7),P^=s1(r+f|0,9),E^=s1(P+r|0,13),f^=s1(E+P|0,18),o^=s1(_+S|0,7),B^=s1(o+_|0,9),S^=s1(B+o|0,13),_^=s1(S+B|0,18);J[Z++]=V+l|0,J[Z++]=U+p|0,J[Z++]=Q+s|0,J[Z++]=N+y|0,J[Z++]=q+t|0,J[Z++]=A+H0|0,J[Z++]=H+g|0,J[Z++]=I+d|0,J[Z++]=w+P|0,J[Z++]=O+E|0,J[Z++]=T+f|0,J[Z++]=x+r|0,J[Z++]=h+o|0,J[Z++]=$+B|0,J[Z++]=F+S|0,J[Z++]=u+_|0}function GJ(W,X,G,Y,J){let Z=Y+0,V=Y+16*J;for(let U=0;U<16;U++)G[V+U]=W[X+(2*J-1)*16+U];for(let U=0;U<J;U++,Z+=16,X+=16){if(Lk(G,V,W,X,G,Z),U>0)V+=16;Lk(G,Z,W,X+=16,G,V)}}function Bk(W,X,G){let Y=uH({dkLen:32,asyncTick:10,maxmem:1073742848},G),{N:J,r:Z,p:V,dkLen:U,asyncTick:Q,maxmem:N,onProgress:q}=Y;if(B9(J),B9(Z),B9(V),B9(U),B9(Q),B9(N),q!==void 0&&typeof q!=="function")throw Error("progressCb should be function");let A=128*Z,H=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 I=A*(J+V);if(I>N)throw Error(`Scrypt: parameters too large, ${I} (128 * r * (N + p)) > ${N} (maxmem)`);let w=LO(DU,W,X,{c:1,dkLen:A*V}),O=eY(w),T=eY(new Uint8Array(A*J)),x=eY(new Uint8Array(A)),h=()=>{};if(q){let $=2*J*V,F=Math.max(Math.floor($/1e4),1),u=0;h=()=>{if(u++,q&&(!(u%F)||u===$))q(u/$)}}return{N:J,r:Z,p:V,dkLen:U,blockSize32:H,V:T,B32:O,B:w,tmp:x,blockMixCb:h,asyncTick:Q}}function Ek(W,X,G,Y,J){let Z=LO(DU,W,G,{c:1,dkLen:X});return G.fill(0),Y.fill(0),J.fill(0),Z}function $k(W,X,G){let{N:Y,r:J,p:Z,dkLen:V,blockSize32:U,V:Q,B32:N,B:q,tmp:A,blockMixCb:H}=Bk(W,X,G);for(let I=0;I<Z;I++){let w=U*I;for(let O=0;O<U;O++)Q[O]=N[w+O];for(let O=0,T=0;O<Y-1;O++)GJ(Q,T,Q,T+=U,J),H();GJ(Q,(Y-1)*U,N,w,J),H();for(let O=0;O<Y;O++){let T=N[w+U-16]%Y;for(let x=0;x<U;x++)A[x]=N[w+x]^Q[T*U+x];GJ(A,0,N,w,J),H()}}return Ek(W,V,q,Q,A)}async function Fk(W,X,G){let{N:Y,r:J,p:Z,dkLen:V,blockSize32:U,V:Q,B32:N,B:q,tmp:A,blockMixCb:H,asyncTick:I}=Bk(W,X,G);for(let w=0;w<Z;w++){let O=U*w;for(let x=0;x<U;x++)Q[x]=N[O+x];let T=0;await gH(Y-1,I,()=>{GJ(Q,T,Q,T+=U,J),H()}),GJ(Q,(Y-1)*U,N,O,J),H(),await gH(Y,I,()=>{let x=N[O+U-16]%Y;for(let h=0;h<U;h++)A[h]=N[O+h]^Q[x*U+h];GJ(A,0,N,O,J),H()})}return Ek(W,V,q,Q,A)}var Sk=!1,xk=!1,kk=async function(W,X,G,Y,J,Z,V){return await Fk(W,X,{N:G,r:Y,p:J,dkLen:Z,onProgress:V})},_k=function(W,X,G,Y,J,Z){return $k(W,X,{N:G,r:Y,p:J,dkLen:Z})},yk=kk,vk=_k;async function UW(W,X,G,Y,J,Z,V){let U=E0(W,"passwd"),Q=E0(X,"salt");return M0(await yk(U,Q,G,Y,J,Z,V))}UW._=kk;UW.lock=function(){xk=!0};UW.register=function(W){if(xk)throw Error("scrypt is locked");yk=W};Object.freeze(UW);function QW(W,X,G,Y,J,Z){let V=E0(W,"passwd"),U=E0(X,"salt");return M0(vk(V,U,G,Y,J,Z))}QW._=_k;QW.lock=function(){Sk=!0};QW.register=function(W){if(Sk)throw Error("scryptSync is locked");vk=W};Object.freeze(QW);var gk=function(W){return CO("sha256").update(W).digest()},uk=function(W){return CO("sha512").update(W).digest()},hk=gk,bk=uk,mk=!1,fk=!1;function E9(W){let X=E0(W,"data");return M0(hk(X))}E9._=gk;E9.lock=function(){mk=!0};E9.register=function(W){if(mk)throw Error("sha256 is locked");hk=W};Object.freeze(E9);function mH(W){let X=E0(W,"data");return M0(bk(X))}mH._=uk;mH.lock=function(){fk=!0};mH.register=function(W){if(fk)throw Error("sha512 is locked");bk=W};Object.freeze(E9);var FO={};zA(FO,{validateObject:()=>qW,utf8ToBytes:()=>ta,numberToVarBytesBE:()=>aa,numberToHexUnpadded:()=>lk,numberToBytesLE:()=>lH,numberToBytesBE:()=>NW,hexToNumber:()=>EO,hexToBytes:()=>yX,equalBytes:()=>sa,ensureBytes:()=>w5,createHmacDrbg:()=>$O,concatBytes:()=>YJ,bytesToNumberLE:()=>cH,bytesToNumberBE:()=>a4,bytesToHex:()=>_X,bitSet:()=>Xs,bitMask:()=>TU,bitLen:()=>ea,bitGet:()=>Ws});/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */var ck=BigInt(0),fH=BigInt(1),ia=BigInt(2),pH=(W)=>W instanceof Uint8Array,ra=Array.from({length:256},(W,X)=>X.toString(16).padStart(2,"0"));function _X(W){if(!pH(W))throw Error("Uint8Array expected");let X="";for(let G=0;G<W.length;G++)X+=ra[W[G]];return X}function lk(W){let X=W.toString(16);return X.length&1?`0${X}`:X}function EO(W){if(typeof W!=="string")throw Error("hex string expected, got "+typeof W);return BigInt(W===""?"0":`0x${W}`)}function yX(W){if(typeof W!=="string")throw Error("hex string expected, got "+typeof W);let X=W.length;if(X%2)throw Error("padded hex string expected, got unpadded hex of length "+X);let G=new Uint8Array(X/2);for(let Y=0;Y<G.length;Y++){let J=Y*2,Z=W.slice(J,J+2),V=Number.parseInt(Z,16);if(Number.isNaN(V)||V<0)throw Error("Invalid byte sequence");G[Y]=V}return G}function a4(W){return EO(_X(W))}function cH(W){if(!pH(W))throw Error("Uint8Array expected");return EO(_X(Uint8Array.from(W).reverse()))}function NW(W,X){return yX(W.toString(16).padStart(X*2,"0"))}function lH(W,X){return NW(W,X).reverse()}function aa(W){return yX(lk(W))}function w5(W,X,G){let Y;if(typeof X==="string")try{Y=yX(X)}catch(Z){throw Error(`${W} must be valid hex string, got "${X}". Cause: ${Z}`)}else if(pH(X))Y=Uint8Array.from(X);else throw Error(`${W} must be hex string or Uint8Array`);let J=Y.length;if(typeof G==="number"&&J!==G)throw Error(`${W} expected ${G} bytes, got ${J}`);return Y}function YJ(...W){let X=new Uint8Array(W.reduce((Y,J)=>Y+J.length,0)),G=0;return W.forEach((Y)=>{if(!pH(Y))throw Error("Uint8Array expected");X.set(Y,G),G+=Y.length}),X}function sa(W,X){if(W.length!==X.length)return!1;for(let G=0;G<W.length;G++)if(W[G]!==X[G])return!1;return!0}function ta(W){if(typeof W!=="string")throw Error(`utf8ToBytes expected string, got ${typeof W}`);return new Uint8Array(new TextEncoder().encode(W))}function ea(W){let X;for(X=0;W>ck;W>>=fH,X+=1);return X}function Ws(W,X){return W>>BigInt(X)&fH}var Xs=(W,X,G)=>{return W|(G?fH:ck)<<BigInt(X)},TU=(W)=>(ia<<BigInt(W-1))-fH,BO=(W)=>new Uint8Array(W),pk=(W)=>Uint8Array.from(W);function $O(W,X,G){if(typeof W!=="number"||W<2)throw Error("hashLen must be a number");if(typeof X!=="number"||X<2)throw Error("qByteLen must be a number");if(typeof G!=="function")throw Error("hmacFn must be a function");let Y=BO(W),J=BO(W),Z=0,V=()=>{Y.fill(1),J.fill(0),Z=0},U=(...A)=>G(J,Y,...A),Q=(A=BO())=>{if(J=U(pk([0]),A),Y=U(),A.length===0)return;J=U(pk([1]),A),Y=U()},N=()=>{if(Z++>=1000)throw Error("drbg: tried 1000 values");let A=0,H=[];while(A<X){Y=U();let I=Y.slice();H.push(I),A+=Y.length}return YJ(...H)};return(A,H)=>{V(),Q(A);let I=void 0;while(!(I=H(N())))Q();return V(),I}}var Gs={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,X)=>X.Fp.isValid(W),hash:(W)=>typeof W==="function"&&Number.isSafeInteger(W.outputLen)};function qW(W,X,G={}){let Y=(J,Z,V)=>{let U=Gs[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(X))Y(J,Z,!1);for(let[J,Z]of Object.entries(G))Y(J,Z,!0);return W}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */var n8=BigInt(0),x8=BigInt(1),vX=BigInt(2),Ys=BigInt(3),SO=BigInt(4),dk=BigInt(5),ok=BigInt(8),Js=BigInt(9),Zs=BigInt(16);function $9(W,X){let G=W%X;return G>=n8?G:X+G}function Vs(W,X,G){if(G<=n8||X<n8)throw Error("Expected power/modulo > 0");if(G===x8)return n8;let Y=x8;while(X>n8){if(X&x8)Y=Y*W%G;W=W*W%G,X>>=x8}return Y}function j5(W,X,G){let Y=W;while(X-- >n8)Y*=Y,Y%=G;return Y}function dH(W,X){if(W===n8||X<=n8)throw Error(`invert: expected positive integers, got n=${W} mod=${X}`);let G=$9(W,X),Y=X,J=n8,Z=x8,V=x8,U=n8;while(G!==n8){let N=Y/G,q=Y%G,A=J-V*N,H=Z-U*N;Y=G,G=q,J=V,Z=U,V=A,U=H}if(Y!==x8)throw Error("invert: does not exist");return $9(J,X)}function Us(W){let X=(W-x8)/vX,G,Y,J;for(G=W-x8,Y=0;G%vX===n8;G/=vX,Y++);for(J=vX;J<W&&Vs(J,X,W)!==W-x8;J++);if(Y===1){let V=(W+x8)/SO;return function(Q,N){let q=Q.pow(N,V);if(!Q.eql(Q.sqr(q),N))throw Error("Cannot find square root");return q}}let Z=(G+x8)/vX;return function(U,Q){if(U.pow(Q,X)===U.neg(U.ONE))throw Error("Cannot find square root");let N=Y,q=U.pow(U.mul(U.ONE,J),G),A=U.pow(Q,Z),H=U.pow(Q,G);while(!U.eql(H,U.ONE)){if(U.eql(H,U.ZERO))return U.ZERO;let I=1;for(let O=U.sqr(H);I<N;I++){if(U.eql(O,U.ONE))break;O=U.sqr(O)}let w=U.pow(q,x8<<BigInt(N-I-1));q=U.sqr(w),A=U.mul(A,w),H=U.mul(H,q),N=I}return A}}function Qs(W){if(W%SO===Ys){let X=(W+x8)/SO;return function(Y,J){let Z=Y.pow(J,X);if(!Y.eql(Y.sqr(Z),J))throw Error("Cannot find square root");return Z}}if(W%ok===dk){let X=(W-dk)/ok;return function(Y,J){let Z=Y.mul(J,vX),V=Y.pow(Z,X),U=Y.mul(J,V),Q=Y.mul(Y.mul(U,vX),V),N=Y.mul(U,Y.sub(Q,Y.ONE));if(!Y.eql(Y.sqr(N),J))throw Error("Cannot find square root");return N}}if(W%Zs===Js);return Us(W)}var Ns=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function xO(W){let X={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},G=Ns.reduce((Y,J)=>{return Y[J]="function",Y},X);return qW(W,G)}function qs(W,X,G){if(G<n8)throw Error("Expected power > 0");if(G===n8)return W.ONE;if(G===x8)return X;let Y=W.ONE,J=X;while(G>n8){if(G&x8)Y=W.mul(Y,J);J=W.sqr(J),G>>=x8}return Y}function Hs(W,X){let G=Array(X.length),Y=X.reduce((Z,V,U)=>{if(W.is0(V))return Z;return G[U]=Z,W.mul(Z,V)},W.ONE),J=W.inv(Y);return X.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 kO(W,X){let G=X!==void 0?X:W.toString(2).length,Y=Math.ceil(G/8);return{nBitLength:G,nByteLength:Y}}function nk(W,X,G=!1,Y={}){if(W<=n8)throw Error(`Expected Field ORDER > 0, got ${W}`);let{nBitLength:J,nByteLength:Z}=kO(W,X);if(Z>2048)throw Error("Field lengths over 2048 bytes are not supported");let V=Qs(W),U=Object.freeze({ORDER:W,BITS:J,BYTES:Z,MASK:TU(J),ZERO:n8,ONE:x8,create:(Q)=>$9(Q,W),isValid:(Q)=>{if(typeof Q!=="bigint")throw Error(`Invalid field element: expected bigint, got ${typeof Q}`);return n8<=Q&&Q<W},is0:(Q)=>Q===n8,isOdd:(Q)=>(Q&x8)===x8,neg:(Q)=>$9(-Q,W),eql:(Q,N)=>Q===N,sqr:(Q)=>$9(Q*Q,W),add:(Q,N)=>$9(Q+N,W),sub:(Q,N)=>$9(Q-N,W),mul:(Q,N)=>$9(Q*N,W),pow:(Q,N)=>qs(U,Q,N),div:(Q,N)=>$9(Q*dH(N,W),W),sqrN:(Q)=>Q*Q,addN:(Q,N)=>Q+N,subN:(Q,N)=>Q-N,mulN:(Q,N)=>Q*N,inv:(Q)=>dH(Q,W),sqrt:Y.sqrt||((Q)=>V(U,Q)),invertBatch:(Q)=>Hs(U,Q),cmov:(Q,N,q)=>q?N:Q,toBytes:(Q)=>G?lH(Q,Z):NW(Q,Z),fromBytes:(Q)=>{if(Q.length!==Z)throw Error(`Fp.fromBytes: expected ${Z}, got ${Q.length}`);return G?cH(Q):a4(Q)}});return Object.freeze(U)}function ik(W){if(typeof W!=="bigint")throw Error("field order must be bigint");let X=W.toString(2).length;return Math.ceil(X/8)}function _O(W){let X=ik(W);return X+Math.ceil(X/2)}function rk(W,X,G=!1){let Y=W.length,J=ik(X),Z=_O(X);if(Y<16||Y<Z||Y>1024)throw Error(`expected ${Z}-1024 bytes of input, got ${Y}`);let V=G?a4(W):cH(W),U=$9(V,X-x8)+x8;return G?lH(U,J):NW(U,J)}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */var zs=BigInt(0),yO=BigInt(1);function ak(W,X){let G=(J,Z)=>{let V=Z.negate();return J?V:Z},Y=(J)=>{let Z=Math.ceil(X/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>zs){if(Z&yO)V=V.add(U);U=U.double(),Z>>=yO}return V},precomputeWindow(J,Z){let{windows:V,windowSize:U}=Y(Z),Q=[],N=J,q=N;for(let A=0;A<V;A++){q=N,Q.push(q);for(let H=1;H<U;H++)q=q.add(N),Q.push(q);N=q.double()}return Q},wNAF(J,Z,V){let{windows:U,windowSize:Q}=Y(J),N=W.ZERO,q=W.BASE,A=BigInt(2**J-1),H=2**J,I=BigInt(J);for(let w=0;w<U;w++){let O=w*Q,T=Number(V&A);if(V>>=I,T>Q)T-=H,V+=yO;let x=O,h=O+Math.abs(T)-1,$=w%2!==0,F=T<0;if(T===0)q=q.add(G($,Z[x]));else N=N.add(G(F,Z[h]))}return{p:N,f:q}},wNAFCached(J,Z,V,U){let Q=J._WINDOW_SIZE||1,N=Z.get(J);if(!N){if(N=this.precomputeWindow(J,Q),Q!==1)Z.set(J,U(N))}return this.wNAF(Q,N,V)}}}function vO(W){return xO(W.Fp),qW(W,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...kO(W.n,W.nBitLength),...W,...{p:W.Fp.ORDER}})}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */function Is(W){let X=vO(W);qW(X,{a:"field",b:"field"},{allowedPrivateKeyLengths:"array",wrapPrivateKey:"boolean",isTorsionFree:"function",clearCofactor:"function",allowInfinityPoint:"boolean",fromBytes:"function",toBytes:"function"});let{endo:G,Fp:Y,a:J}=X;if(G){if(!Y.eql(J,Y.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({...X})}var{bytesToNumberBE:ws,hexToBytes:js}=FO,gX={Err:class extends Error{constructor(X=""){super(X)}},_parseInt(W){let{Err:X}=gX;if(W.length<2||W[0]!==2)throw new X("Invalid signature integer tag");let G=W[1],Y=W.subarray(2,G+2);if(!G||Y.length!==G)throw new X("Invalid signature integer: wrong length");if(Y[0]&128)throw new X("Invalid signature integer: negative");if(Y[0]===0&&!(Y[1]&128))throw new X("Invalid signature integer: unnecessary leading zero");return{d:ws(Y),l:W.subarray(G+2)}},toSig(W){let{Err:X}=gX,G=typeof W==="string"?js(W):W;if(!(G instanceof Uint8Array))throw Error("ui8a expected");let Y=G.length;if(Y<2||G[0]!=48)throw new X("Invalid signature tag");if(G[1]!==Y-2)throw new X("Invalid signature: incorrect length");let{d:J,l:Z}=gX._parseInt(G.subarray(2)),{d:V,l:U}=gX._parseInt(Z);if(U.length)throw new X("Invalid signature: left bytes after parsing");return{r:J,s:V}},hexFromSig(W){let X=(N)=>Number.parseInt(N[0],16)&8?"00"+N:N,G=(N)=>{let q=N.toString(16);return q.length&1?`0${q}`:q},Y=X(G(W.s)),J=X(G(W.r)),Z=Y.length/2,V=J.length/2,U=G(Z),Q=G(V);return`30${G(V+Z+4)}02${Q}${J}02${U}${Y}`}},s4=BigInt(0),_5=BigInt(1),Mj0=BigInt(2),sk=BigInt(3),Pj0=BigInt(4);function Ks(W){let X=Is(W),{Fp:G}=X,Y=X.toBytes||((w,O,T)=>{let x=O.toAffine();return YJ(Uint8Array.from([4]),G.toBytes(x.x),G.toBytes(x.y))}),J=X.fromBytes||((w)=>{let O=w.subarray(1),T=G.fromBytes(O.subarray(0,G.BYTES)),x=G.fromBytes(O.subarray(G.BYTES,2*G.BYTES));return{x:T,y:x}});function Z(w){let{a:O,b:T}=X,x=G.sqr(w),h=G.mul(x,w);return G.add(G.add(h,G.mul(w,O)),T)}if(!G.eql(G.sqr(X.Gy),Z(X.Gx)))throw Error("bad generator point: equation left != right");function V(w){return typeof w==="bigint"&&s4<w&&w<X.n}function U(w){if(!V(w))throw Error("Expected valid bigint: 0 < bigint < curve.n")}function Q(w){let{allowedPrivateKeyLengths:O,nByteLength:T,wrapPrivateKey:x,n:h}=X;if(O&&typeof w!=="bigint"){if(w instanceof Uint8Array)w=_X(w);if(typeof w!=="string"||!O.includes(w.length))throw Error("Invalid key");w=w.padStart(T*2,"0")}let $;try{$=typeof w==="bigint"?w:a4(w5("private key",w,T))}catch(F){throw Error(`private key must be ${T} bytes, hex or bigint, not ${typeof w}`)}if(x)$=$9($,h);return U($),$}let N=new Map;function q(w){if(!(w instanceof A))throw Error("ProjectivePoint expected")}class A{constructor(w,O,T){if(this.px=w,this.py=O,this.pz=T,w==null||!G.isValid(w))throw Error("x required");if(O==null||!G.isValid(O))throw Error("y required");if(T==null||!G.isValid(T))throw Error("z required")}static fromAffine(w){let{x:O,y:T}=w||{};if(!w||!G.isValid(O)||!G.isValid(T))throw Error("invalid affine point");if(w instanceof A)throw Error("projective point not allowed");let x=(h)=>G.eql(h,G.ZERO);if(x(O)&&x(T))return A.ZERO;return new A(O,T,G.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(w){let O=G.invertBatch(w.map((T)=>T.pz));return w.map((T,x)=>T.toAffine(O[x])).map(A.fromAffine)}static fromHex(w){let O=A.fromAffine(J(w5("pointHex",w)));return O.assertValidity(),O}static fromPrivateKey(w){return A.BASE.multiply(Q(w))}_setWindowSize(w){this._WINDOW_SIZE=w,N.delete(this)}assertValidity(){if(this.is0()){if(X.allowInfinityPoint&&!G.is0(this.py))return;throw Error("bad point: ZERO")}let{x:w,y:O}=this.toAffine();if(!G.isValid(w)||!G.isValid(O))throw Error("bad point: x or y not FE");let T=G.sqr(O),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){q(w);let{px:O,py:T,pz:x}=this,{px:h,py:$,pz:F}=w,u=G.eql(G.mul(O,F),G.mul(h,x)),l=G.eql(G.mul(T,F),G.mul($,x));return u&&l}negate(){return new A(this.px,G.neg(this.py),this.pz)}double(){let{a:w,b:O}=X,T=G.mul(O,sk),{px:x,py:h,pz:$}=this,F=G.ZERO,u=G.ZERO,l=G.ZERO,p=G.mul(x,x),s=G.mul(h,h),y=G.mul($,$),t=G.mul(x,h);return t=G.add(t,t),l=G.mul(x,$),l=G.add(l,l),F=G.mul(w,l),u=G.mul(T,y),u=G.add(F,u),F=G.sub(s,u),u=G.add(s,u),u=G.mul(F,u),F=G.mul(t,F),l=G.mul(T,l),y=G.mul(w,y),t=G.sub(p,y),t=G.mul(w,t),t=G.add(t,l),l=G.add(p,p),p=G.add(l,p),p=G.add(p,y),p=G.mul(p,t),u=G.add(u,p),y=G.mul(h,$),y=G.add(y,y),p=G.mul(y,t),F=G.sub(F,p),l=G.mul(y,s),l=G.add(l,l),l=G.add(l,l),new A(F,u,l)}add(w){q(w);let{px:O,py:T,pz:x}=this,{px:h,py:$,pz:F}=w,u=G.ZERO,l=G.ZERO,p=G.ZERO,s=X.a,y=G.mul(X.b,sk),t=G.mul(O,h),H0=G.mul(T,$),g=G.mul(x,F),d=G.add(O,T),P=G.add(h,$);d=G.mul(d,P),P=G.add(t,H0),d=G.sub(d,P),P=G.add(O,x);let E=G.add(h,F);return P=G.mul(P,E),E=G.add(t,g),P=G.sub(P,E),E=G.add(T,x),u=G.add($,F),E=G.mul(E,u),u=G.add(H0,g),E=G.sub(E,u),p=G.mul(s,P),u=G.mul(y,g),p=G.add(u,p),u=G.sub(H0,p),p=G.add(H0,p),l=G.mul(u,p),H0=G.add(t,t),H0=G.add(H0,t),g=G.mul(s,g),P=G.mul(y,P),H0=G.add(H0,g),g=G.sub(t,g),g=G.mul(s,g),P=G.add(P,g),t=G.mul(H0,P),l=G.add(l,t),t=G.mul(E,P),u=G.mul(d,u),u=G.sub(u,t),t=G.mul(d,H0),p=G.mul(E,p),p=G.add(p,t),new A(u,l,p)}subtract(w){return this.add(w.negate())}is0(){return this.equals(A.ZERO)}wNAF(w){return I.wNAFCached(this,N,w,(O)=>{let T=G.invertBatch(O.map((x)=>x.pz));return O.map((x,h)=>x.toAffine(T[h])).map(A.fromAffine)})}multiplyUnsafe(w){let O=A.ZERO;if(w===s4)return O;if(U(w),w===_5)return this;let{endo:T}=X;if(!T)return I.unsafeLadder(this,w);let{k1neg:x,k1:h,k2neg:$,k2:F}=T.splitScalar(w),u=O,l=O,p=this;while(h>s4||F>s4){if(h&_5)u=u.add(p);if(F&_5)l=l.add(p);p=p.double(),h>>=_5,F>>=_5}if(x)u=u.negate();if($)l=l.negate();return l=new A(G.mul(l.px,T.beta),l.py,l.pz),u.add(l)}multiply(w){U(w);let O=w,T,x,{endo:h}=X;if(h){let{k1neg:$,k1:F,k2neg:u,k2:l}=h.splitScalar(O),{p,f:s}=this.wNAF(F),{p:y,f:t}=this.wNAF(l);p=I.constTimeNegate($,p),y=I.constTimeNegate(u,y),y=new A(G.mul(y.px,h.beta),y.py,y.pz),T=p.add(y),x=s.add(t)}else{let{p:$,f:F}=this.wNAF(O);T=$,x=F}return A.normalizeZ([T,x])[0]}multiplyAndAddUnsafe(w,O,T){let x=A.BASE,h=(F,u)=>u===s4||u===_5||!F.equals(x)?F.multiplyUnsafe(u):F.multiply(u),$=h(this,O).add(h(w,T));return $.is0()?void 0:$}toAffine(w){let{px:O,py:T,pz:x}=this,h=this.is0();if(w==null)w=h?G.ONE:G.inv(x);let $=G.mul(O,w),F=G.mul(T,w),u=G.mul(x,w);if(h)return{x:G.ZERO,y:G.ZERO};if(!G.eql(u,G.ONE))throw Error("invZ was invalid");return{x:$,y:F}}isTorsionFree(){let{h:w,isTorsionFree:O}=X;if(w===_5)return!0;if(O)return O(A,this);throw Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){let{h:w,clearCofactor:O}=X;if(w===_5)return this;if(O)return O(A,this);return this.multiplyUnsafe(X.h)}toRawBytes(w=!0){return this.assertValidity(),Y(A,this,w)}toHex(w=!0){return _X(this.toRawBytes(w))}}A.BASE=new A(X.Gx,X.Gy,G.ONE),A.ZERO=new A(G.ZERO,G.ONE,G.ZERO);let H=X.nBitLength,I=ak(A,X.endo?Math.ceil(H/2):H);return{CURVE:X,ProjectivePoint:A,normPrivateKeyToScalar:Q,weierstrassEquation:Z,isWithinCurveOrder:V}}function Os(W){let X=vO(W);return qW(X,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...X})}function tk(W){let X=Os(W),{Fp:G,n:Y}=X,J=G.BYTES+1,Z=2*G.BYTES+1;function V(E){return s4<E&&E<G.ORDER}function U(E){return $9(E,Y)}function Q(E){return dH(E,Y)}let{ProjectivePoint:N,normPrivateKeyToScalar:q,weierstrassEquation:A,isWithinCurveOrder:H}=Ks({...X,toBytes(E,f,r){let o=f.toAffine(),B=G.toBytes(o.x),S=YJ;if(r)return S(Uint8Array.from([f.hasEvenY()?2:3]),B);else return S(Uint8Array.from([4]),B,G.toBytes(o.y))},fromBytes(E){let f=E.length,r=E[0],o=E.subarray(1);if(f===J&&(r===2||r===3)){let B=a4(o);if(!V(B))throw Error("Point is not on curve");let S=A(B),_=G.sqrt(S),v=(_&_5)===_5;if((r&1)===1!==v)_=G.neg(_);return{x:B,y:_}}else if(f===Z&&r===4){let B=G.fromBytes(o.subarray(0,G.BYTES)),S=G.fromBytes(o.subarray(G.BYTES,2*G.BYTES));return{x:B,y:S}}else throw Error(`Point of length ${f} was invalid. Expected ${J} compressed bytes or ${Z} uncompressed bytes`)}}),I=(E)=>_X(NW(E,X.nByteLength));function w(E){let f=Y>>_5;return E>f}function O(E){return w(E)?U(-E):E}let T=(E,f,r)=>a4(E.slice(f,r));class x{constructor(E,f,r){this.r=E,this.s=f,this.recovery=r,this.assertValidity()}static fromCompact(E){let f=X.nByteLength;return E=w5("compactSignature",E,f*2),new x(T(E,0,f),T(E,f,2*f))}static fromDER(E){let{r:f,s:r}=gX.toSig(w5("DER",E));return new x(f,r)}assertValidity(){if(!H(this.r))throw Error("r must be 0 < r < CURVE.n");if(!H(this.s))throw Error("s must be 0 < s < CURVE.n")}addRecoveryBit(E){return new x(this.r,this.s,E)}recoverPublicKey(E){let{r:f,s:r,recovery:o}=this,B=p(w5("msgHash",E));if(o==null||![0,1,2,3].includes(o))throw Error("recovery id invalid");let S=o===2||o===3?f+X.n:f;if(S>=G.ORDER)throw Error("recovery id 2 or 3 invalid");let _=(o&1)===0?"02":"03",v=N.fromHex(_+I(S)),R=Q(S),m=U(-B*R),J0=U(r*R),U0=N.BASE.multiplyAndAddUnsafe(v,m,J0);if(!U0)throw Error("point at infinify");return U0.assertValidity(),U0}hasHighS(){return w(this.s)}normalizeS(){return this.hasHighS()?new x(this.r,U(-this.s),this.recovery):this}toDERRawBytes(){return yX(this.toDERHex())}toDERHex(){return gX.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return yX(this.toCompactHex())}toCompactHex(){return I(this.r)+I(this.s)}}let h={isValidPrivateKey(E){try{return q(E),!0}catch(f){return!1}},normPrivateKeyToScalar:q,randomPrivateKey:()=>{let E=_O(X.n);return rk(X.randomBytes(E),X.n)},precompute(E=8,f=N.BASE){return f._setWindowSize(E),f.multiply(BigInt(3)),f}};function $(E,f=!0){return N.fromPrivateKey(E).toRawBytes(f)}function F(E){let f=E instanceof Uint8Array,r=typeof E==="string",o=(f||r)&&E.length;if(f)return o===J||o===Z;if(r)return o===2*J||o===2*Z;if(E instanceof N)return!0;return!1}function u(E,f,r=!0){if(F(E))throw Error("first arg must be private key");if(!F(f))throw Error("second arg must be public key");return N.fromHex(f).multiply(q(E)).toRawBytes(r)}let l=X.bits2int||function(E){let f=a4(E),r=E.length*8-X.nBitLength;return r>0?f>>BigInt(r):f},p=X.bits2int_modN||function(E){return U(l(E))},s=TU(X.nBitLength);function y(E){if(typeof E!=="bigint")throw Error("bigint expected");if(!(s4<=E&&E<s))throw Error(`bigint expected < 2^${X.nBitLength}`);return NW(E,X.nByteLength)}function t(E,f,r=H0){if(["recovered","canonical"].some((u0)=>(u0 in r)))throw Error("sign() legacy options not supported");let{hash:o,randomBytes:B}=X,{lowS:S,prehash:_,extraEntropy:v}=r;if(S==null)S=!0;if(E=w5("msgHash",E),_)E=w5("prehashed msgHash",o(E));let R=p(E),m=q(f),J0=[y(m),y(R)];if(v!=null){let u0=v===!0?B(G.BYTES):v;J0.push(w5("extraEntropy",u0))}let U0=YJ(...J0),q0=R;function $0(u0){let H1=l(u0);if(!H(H1))return;let v1=Q(H1),h0=N.BASE.multiply(H1).toAffine(),F1=U(h0.x);if(F1===s4)return;let S1=U(v1*U(q0+F1*m));if(S1===s4)return;let N0=(h0.x===F1?0:2)|Number(h0.y&_5),F0=S1;if(S&&w(S1))F0=O(S1),N0^=1;return new x(F1,F0,N0)}return{seed:U0,k2sig:$0}}let H0={lowS:X.lowS,prehash:!1},g={lowS:X.lowS,prehash:!1};function d(E,f,r=H0){let{seed:o,k2sig:B}=t(E,f,r),S=X;return $O(S.hash.outputLen,S.nByteLength,S.hmac)(o,B)}N.BASE._setWindowSize(8);function P(E,f,r,o=g){let B=E;if(f=w5("msgHash",f),r=w5("publicKey",r),"strict"in o)throw Error("options.strict was renamed to lowS");let{lowS:S,prehash:_}=o,v=void 0,R;try{if(typeof B==="string"||B instanceof Uint8Array)try{v=x.fromDER(B)}catch(h0){if(!(h0 instanceof gX.Err))throw h0;v=x.fromCompact(B)}else if(typeof B==="object"&&typeof B.r==="bigint"&&typeof B.s==="bigint"){let{r:h0,s:F1}=B;v=new x(h0,F1)}else throw Error("PARSE");R=N.fromHex(r)}catch(h0){if(h0.message==="PARSE")throw Error("signature must be Signature instance, Uint8Array or hex string");return!1}if(S&&v.hasHighS())return!1;if(_)f=X.hash(f);let{r:m,s:J0}=v,U0=p(f),q0=Q(J0),$0=U(U0*q0),u0=U(m*q0),H1=N.BASE.multiplyAndAddUnsafe(R,$0,u0)?.toAffine();if(!H1)return!1;return U(H1.x)===m}return{CURVE:X,getPublicKey:$,getSharedSecret:u,sign:d,verify:P,ProjectivePoint:N,Signature:x,utils:h}}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */function Ds(W){return{hash:W,hmac:(X,...G)=>CU(W,X,ex(...G)),randomBytes:Wk}}function ek(W,X){let G=(Y)=>tk({...W,...Ds(Y)});return Object.freeze({...G(X),create:G})}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */var G_=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),W_=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),Cs=BigInt(1),gO=BigInt(2),X_=(W,X)=>(W+X/gO)/X;function Ts(W){let X=G_,G=BigInt(3),Y=BigInt(6),J=BigInt(11),Z=BigInt(22),V=BigInt(23),U=BigInt(44),Q=BigInt(88),N=W*W*W%X,q=N*N*W%X,A=j5(q,G,X)*q%X,H=j5(A,G,X)*q%X,I=j5(H,gO,X)*N%X,w=j5(I,J,X)*I%X,O=j5(w,Z,X)*w%X,T=j5(O,U,X)*O%X,x=j5(T,Q,X)*T%X,h=j5(x,U,X)*O%X,$=j5(h,G,X)*q%X,F=j5($,V,X)*w%X,u=j5(F,Y,X)*N%X,l=j5(u,gO,X);if(!uO.eql(uO.sqr(l),W))throw Error("Cannot find square root");return l}var uO=nk(G_,void 0,void 0,{sqrt:Ts}),t4=ek({a:BigInt(0),b:BigInt(7),Fp:uO,n:W_,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:(W)=>{let X=W_,G=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),Y=-Cs*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),J=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),Z=G,V=BigInt("0x100000000000000000000000000000000"),U=X_(Z*W,X),Q=X_(-Y*W,X),N=$9(W-U*G-Q*J,X),q=$9(-U*Y-Q*Z,X),A=N>V,H=q>V;if(A)N=X-N;if(H)q=X-q;if(N>V||q>V)throw Error("splitScalar: Endomorphism failed, k="+W);return{k1neg:A,k1:N,k2neg:H,k2:q}}}},DU),kj0=BigInt(0);var _j0=t4.ProjectivePoint;var hO="0x0000000000000000000000000000000000000000";var oH="0x0000000000000000000000000000000000000000000000000000000000000000";var bO=`\x19Ethereum Signed Message:
248
+ `);return Y.forEach((J)=>{if(J.startsWith("m="))G.push([J]);else if(G.length>0)G[G.length-1].push(J);else X.push(J)}),[X,G]}function CK(W){if(W.includes(":")){let X=p4(W.slice(2),":");return[X[0],X[1]]}else return[W.slice(2),void 0]}function TK(W,X,G=(Y)=>Y.toString()){let Y=X.split(" ");if(Y.length>0)W.push(new nV(Y[0],Y.slice(1).map(G)))}function wx(W){let X=TX.fromSdp(W);return WU(X)}var br=class{constructor(W,X){this.sdp=W,this.type=X}static isThis(W){if(typeof W?.sdp==="string")return!0}toSdp(){return{sdp:this.sdp,type:this.type}}};function j2(W,X){let Y=new Eq(Yr(64)).toString().slice(0,8),J=0;X.origin=`- ${Y} 0 IN IP4 0.0.0.0`,X.msidSemantic.push(new nV("WMS",["*"])),X.type=W}function HH(W){let X={};return W.split(";").forEach((G)=>{if(G.includes("=")){let[Y,J]=p4(G,"=");if(gi.includes(Y))X[Y]=Number(J);else X[Y]=J}else if(G.includes(":")){let[Y,J]=G.split(":");X[Y]=Number.isNaN(Number(J))?J:Number(J)}else X[G]=void 0}),X}var XO=class{ssrc;cname;msid;msLabel;label;constructor(W){Object.assign(this,W)}},vq=P1("werift:packages/webrtc/src/media/rtpReceiver.ts"),jx=class{constructor(W,X,G){this.config=W,this.kind=X,this.rtcpSsrc=G}codecs={};get codecArray(){return Object.values(this.codecs).sort((W,X)=>W.payloadType-X.payloadType)}ssrcByRtx={};nack=new ti(this);audioRedHandler=new An;type="receiver";uuid=Fi().toString();tracks=[];trackBySSRC={};trackByRID={};lastSRtimestamp={};receiveLastSRTimestamp={};onPacketLost=this.nack.onPacketLost;onRtcp=new d0;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 mK({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===Ti().type)}get pliEnabled(){return this.codecArray[0]?.rtcpFeedback.find((W)=>W.type===NU().type)}prepareReceive(W){W.codecs.forEach((X)=>{this.codecs[X.payloadType]=X}),W.encodings.forEach((X)=>{if(X.rtx)this.ssrcByRtx[X.rtx.ssrc]=X.ssrc})}setupTWCC(W){if(this.twccEnabled&&!this.receiverTWCC)this.receiverTWCC=new Xr(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 KK(500+Math.random()*1000,void 0,{signal:this.rtcpCancel.signal});let W=Object.entries(this.remoteStreams).map(([G,Y])=>{let J=0,Z=0;if(this.lastSRtimestamp[G]){J=this.lastSRtimestamp[G];let V=NH()-this.receiveLastSRTimestamp[G];if(V>0&&V<65536)Z=dV(V*65536)}return new JO({ssrc:Number(G),fractionLost:Y.fraction_lost,packetsLost:Y.packets_lost,highestSequence:Y.max_seq,jitter:Y.jitter,lsr:J,dlsr:Z})}),X=new aV({ssrc:this.rtcpSsrc,reports:W});try{if(this.config.debug.receiverReportDelay)await KK(this.config.debug.receiverReportDelay);await this.dtlsTransport.sendRtcp([X])}catch(G){vq("sendRtcp failed",G),await KK(500+Math.random()*1000)}}}catch(W){}}async getStats(){let W=SX(),X=[];if(!this.dtlsTransport)return X;let G=N8("transport",this.dtlsTransport.id);for(let Y of this.tracks){if(!Y.ssrc)continue;let J=this.remoteStreams[Y.ssrc];if(!J)continue;let Z={type:"inbound-rtp",id:N8("inbound-rtp",Y.ssrc),timestamp:W,ssrc:Y.ssrc,kind:this.kind,transportId:G,codecId:this.codecs[0]?N8("codec",this.codecs[0].payloadType,G):void 0,mid:this.sdesMid,trackIdentifier:Y.id,packetsReceived:J.packets_received,packetsLost:J.packets_lost,jitter:J.jitter};if(X.push(Z),this.lastSRtimestamp[Y.ssrc]){let V={type:"remote-outbound-rtp",id:N8("remote-outbound-rtp",Y.ssrc),timestamp:W,ssrc:Y.ssrc,kind:this.kind,transportId:G,codecId:Z.codecId,localId:Z.id,remoteTimestamp:this.receiveLastSRTimestamp[Y.ssrc]*1000};X.push(V)}}return X}async sendRtcpPLI(W){if(!this.pliEnabled){vq("pli not supported",{mediaSsrc:W});return}if(this.stopped)return;vq("sendRtcpPLI",{mediaSsrc:W});let X=new rV({feedback:new JH({senderSsrc:this.rtcpSsrc,mediaSsrc:W})});try{await this.dtlsTransport.sendRtcp([X])}catch(G){vq(G)}}handleRtcpPacket(W){switch(W.type){case fY.type:{let X=W;this.lastSRtimestamp[X.ssrc]=Xx(X.senderInfo.ntpTimestamp),this.receiveLastSRTimestamp[X.ssrc]=NH();let G=this.trackBySSRC[W.ssrc];if(G)G.onReceiveRtcp.execute(W)}break}this.onRtcp.execute(W)}handleRtpBySsrc=(W,X)=>{let G=this.trackBySSRC[W.header.ssrc];this.handleRTP(W,X,G)};handleRtpByRid=(W,X,G)=>{let Y=this.trackByRID[X];if(!this.trackBySSRC[W.header.ssrc])this.trackBySSRC[W.header.ssrc]=Y;this.handleRTP(W,G,Y)};handleRTP(W,X,G){if(this.stopped)return;let Y=this.codecs[W.header.payloadType];if(!Y)return;if(this.remoteStreams[W.header.ssrc]=this.remoteStreams[W.header.ssrc]??new Gr(Y.clockRate),this.remoteStreams[W.header.ssrc].add(W),this.receiverTWCC){let Z=X[P9.transportWideCC];if(!Z==null)throw Error("undefined");this.receiverTWCC.handleTWCC(Z)}else if(this.twccEnabled)this.setupTWCC(W.header.ssrc);if(Y.name.toLowerCase()==="rtx"){let Z=this.ssrcByRtx[W.header.ssrc],V=HH(Y.parameters??""),U=this.codecs[V.apt];if(W.payload.length<2)return;W=zn(W,U.payloadType,Z),G=this.trackBySSRC[Z]}let J;if(Y.name.toLowerCase()==="red"){if(J=zS.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(),X)}}else G.onReceiveRtp.execute(W.clone(),X);this.runRtcp()}},bV=P1("werift:packages/webrtc/src/media/router.ts"),mr=class{ssrcTable={};ridTable={};extIdUriMap={};constructor(){}registerRtpSender(W){this.ssrcTable[W.ssrc]=W}registerRtpReceiver(W,X){bV("registerRtpReceiver",X),this.ssrcTable[X]=W}registerRtpReceiverBySsrc(W,X){bV("registerRtpReceiverBySsrc",X),X.encodings.filter((G)=>G.ssrc!=null).forEach((G,Y)=>{if(this.registerRtpReceiver(W.receiver,G.ssrc),W.addTrack(new mK({ssrc:G.ssrc,kind:W.kind,id:W.sender.trackId,remote:!0,codec:X.codecs[Y]})),G.rtx)this.registerRtpReceiver(W.receiver,G.rtx.ssrc)}),X.headerExtensions.forEach((G)=>{this.extIdUriMap[G.id]=G.uri})}registerRtpReceiverByRid(W,X,G){let[Y]=G.codecs;bV("registerRtpReceiverByRid",X),W.addTrack(new mK({rid:X.rid,kind:W.kind,id:W.sender.trackId,remote:!0,codec:Y})),this.ridTable[X.rid]=W.receiver}routeRtp=(W)=>{let X=to(W.header.extensions,this.extIdUriMap),G=this.ssrcTable[W.header.ssrc],Y=X[P9.sdesRTPStreamID];if(typeof Y==="string")G=this.ridTable[Y],G.latestRid=Y,G.handleRtpByRid(W,Y,X);else if(G)G.handleRtpBySsrc(W,X);else if(G=Object.values(this.ridTable).filter((V)=>V instanceof jx).find((V)=>V.trackBySSRC[W.header.ssrc]),G)bV("simulcast register receiver by ssrc",W.header.ssrc),this.registerRtpReceiver(G,W.header.ssrc),G.handleRtpBySsrc(W,X);if(!G){bV("ssrcReceiver not found");return}let J=X[P9.sdesMid];if(typeof J==="string")G.sdesMid=J;let Z=X[P9.repairedRtpStreamId];if(typeof Z==="string")G.latestRepairedRid=Z};routeRtcp=(W)=>{let X=[];switch(W.type){case fY.type:W=W,X.push(this.ssrcTable[W.ssrc]);break;case aV.type:W=W,W.reports.forEach((G)=>{X.push(this.ssrcTable[G.ssrc])});break;case QH.type:{let G=W}break;case mY.type:{let G=W;if(G.feedback)X.push(this.ssrcTable[G.feedback.mediaSourceSsrc])}break;case rV.type:{let G=W;switch(G.feedback.count){case ZH.count:{let Y=G.feedback;X.push(this.ssrcTable[Y.ssrcFeedbacks[0]])}break;default:X.push(this.ssrcTable[G.feedback.senderSsrc]||this.ssrcTable[G.feedback.mediaSsrc])}}break}X.filter((G)=>G).forEach((G)=>G.handleRtcpPacket(W))}},fr=class{numPackets=0;totalSize=0;firstPacketSentAtMs=0;lastPacketSentAtMs=0;firstPacketReceivedAtMs=0;lastPacketReceivedAtMs=0;addPacket(W,X,G){if(this.numPackets===0)this.firstPacketSentAtMs=X,this.firstPacketReceivedAtMs=G,this.lastPacketSentAtMs=X,this.lastPacketReceivedAtMs=G;else{if(X<this.firstPacketSentAtMs)this.firstPacketSentAtMs=X;if(G<this.firstPacketReceivedAtMs)this.firstPacketReceivedAtMs=G;if(X>this.lastPacketSentAtMs)this.lastPacketSentAtMs=X;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,X=this.totalSize/W*8*1000;return YH(X)}get sendBitrate(){let W=this.lastPacketSentAtMs-this.firstPacketSentAtMs,X=this.totalSize/W*8*1000;return YH(X)}},_Y=20,pr=10,cr=class{congestion=!1;onAvailableBitrate=new d0;onCongestion=new d0;onCongestionScore=new d0;congestionCounter=0;cumulativeResult=new fr;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=Wx()-this.cumulativeResult.firstPacketSentAtMs;if(G>1000){if(this.cumulativeResult.reset(),this.congestionCounter<_Y)this.congestionCounter++;else if(this.congestionScore<pr)this.congestionScore++;if(this.congestionCounter>=_Y&&!this.congestion)this.congestion=!0,this.onCongestion.execute(this.congestion)}for(let Y of W.packetResults){if(!Y.received)continue;let J=Y.sequenceNumber,Z=this.sentInfos[J];if(!Z)continue;if(!Y.receivedAtMs)continue;this.cumulativeResult.addPacket(Z.size,Z.sendingAtMs,Y.receivedAtMs)}if(G>=100&&this.cumulativeResult.numPackets>=20){if(this.availableBitrate=Math.min(this.cumulativeResult.sendBitrate,this.cumulativeResult.receiveBitrate),this.cumulativeResult.reset(),this.congestionCounter>-_Y){let Y=YH(_Y/2)+1,J=YH(_Y/4)+1,Z=Y-(Y-J)/10*this.congestionScore;this.congestionCounter=this.congestionCounter-Z}if(this.congestionCounter<=-_Y){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((X)=>Number(X)).sort().filter((X)=>X<W.wideSeq).forEach((X)=>{delete this.sentInfos[X]}),this.sentInfos[W.wideSeq]=W}},MK=P1("werift:packages/webrtc/src/media/rtpSender.ts"),C2=128,T2=0.85,lr=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=X8.Unpack("!L",K2(4))[0];rtxSsrc=X8.Unpack("!L",K2(4))[0];streamId=O2().toString();trackId=O2().toString();onReady=new d0;onRtcp=new d0;onPictureLossIndication=new d0;onGenericNack=new d0;senderBWE=new cr;cname;mid;rtpStreamId;repairedRtpStreamId;rtxPayloadType;rtxSequenceNumber=R2();redRedundantPayloadType;_redDistance=2;redEncoder=new qn(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((X)=>X());this.dtlsTransport=W,this.dtlsDisposer=[this.dtlsTransport.onStateChange.subscribe((X)=>{if(X==="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((X)=>{let G=HH(X.parameters??"");if(X.name.toLowerCase()==="rtx"&&G.apt===this.codec?.payloadType)this.rtxPayloadType=X.payloadType;if(X.name.toLowerCase()==="red")this.redRedundantPayloadType=Number((X.parameters??"").split("/")[0])})}registerTrack(W){if(W.stopped)throw Error("track is ended");if(this.disposeTrack)this.disposeTrack();W.id=this.trackId;let{unSubscribe:X}=W.onReceiveRtp.subscribe(async(G)=>{await this.sendRtp(G)});if(this.track=W,this.disposeTrack=X,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 X=W.header||(await W.onReceiveRtp.asPromise())[0].header;this.replaceRTP(X)}this.registerTrack(W),MK("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 D2(500+Math.random()*1000,void 0,{signal:this.rtcpCancel.signal});let W=[new fY({ssrc:this.ssrc,senderInfo:new AS({ntpTimestamp:this.ntpTimestamp,rtpTimestamp:this.rtpTimestamp,packetCount:this.packetCount,octetCount:this.octetCount})})];if(this.lastSRtimestamp=Xx(this.ntpTimestamp),this.lastSentSRTimestamp=NH(),this.cname)W.push(new QH({chunks:[new qS({source:this.ssrc,items:[new HS({type:1,text:this.cname})]})]}));try{await this.dtlsTransport.sendRtcp(W)}catch(X){MK("sendRtcp failed",X),await D2(500+Math.random()*1000)}}}catch(W){}}replaceRTP({sequenceNumber:W,timestamp:X},G=!1){if(this.sequenceNumber!=null){if(this.seqOffset=R9(this.sequenceNumber,-W),G)this.seqOffset=R9(this.seqOffset,2)}if(this.timestamp!=null){if(this.timestampOffset=uY(this.timestamp,-X),G)this.timestampOffset=R9(this.timestampOffset,1)}this.rtpCache=[],MK("replaceRTP",this.sequenceNumber,W,this.seqOffset)}async sendRtp(W){if(this.dtlsTransport.state!=="connected"||!this.codec)return;W=Buffer.isBuffer(W)?WW.deSerialize(W):W;let{header:X,payload:G}=W;X.ssrc=this.ssrc,X.payloadType=this.codec.payloadType,X.timestamp=uY(X.timestamp,this.timestampOffset),X.sequenceNumber=R9(X.sequenceNumber,this.seqOffset),this.timestamp=X.timestamp,this.sequenceNumber=X.sequenceNumber;let Y=ii(),J=[...X.extensions];X.extensions=this.headerExtensions.map((N)=>{let q=(()=>{switch(N.uri){case P9.sdesMid:if(this.mid)return eo(this.mid);return;case P9.sdesRTPStreamID:if(this.rtpStreamId)return Wn(this.rtpStreamId);return;case P9.repairedRtpStreamId:if(this.repairedRtpStreamId)return Xn(this.repairedRtpStreamId);return;case P9.transportWideCC:return this.dtlsTransport.transportSequenceNumber=R9(this.dtlsTransport.transportSequenceNumber,1),Gn(this.dtlsTransport.transportSequenceNumber);case P9.absSendTime:return Yn(Y)}})();if(q)return{id:N.id,payload:q}}).filter((N)=>N);for(let N of J){let q=X.extensions.find((A)=>A.id===N.id);if(q)q.payload=N.payload;else X.extensions.push(N)}X.extensions=X.extensions.sort((N,q)=>N.id-q.id),this.ntpTimestamp=Y,this.rtpTimestamp=X.timestamp,this.octetCount+=G.length,this.packetCount=uY(this.packetCount,1),this.rtpCache[X.sequenceNumber%C2]=W;let Z=G;if(this.redRedundantPayloadType)this.redEncoder.push({block:Z,timestamp:X.timestamp,blockPT:this.redRedundantPayloadType}),Z=this.redEncoder.build().serialize();let V=await this.dtlsTransport.sendRtp(Z,X);this.runRtcp();let U=Wx(),Q={wideSeq:this.dtlsTransport.transportSequenceNumber,size:V,sendingAtMs:U,sentAtMs:U};this.senderBWE.rtpPacketSent(Q)}handleRtcpPacket(W){switch(W.type){case fY.type:case aV.type:W.reports.filter((G)=>G.ssrc===this.ssrc).forEach((G)=>{if(this.lastSRtimestamp===G.lsr&&G.dlsr){if(this.lastSentSRTimestamp){let Y=NH()-this.lastSentSRTimestamp-G.dlsr/65536;if(this.rtt===void 0)this.rtt=Y;else this.rtt=T2*this.rtt+(1-T2)*Y}}});break;case mY.type:{let X=W;switch(X.feedback.count){case UH.count:{let G=X.feedback;this.senderBWE.receiveTWCC(G)}break;case VH.count:{let G=X.feedback;G.lost.forEach(async(Y)=>{let J=this.rtpCache[Y%C2];if(J&&J.header.sequenceNumber!==Y)J=void 0;if(J){if(this.rtxPayloadType!=null)J=In(J,this.rtxPayloadType,this.rtxSequenceNumber,this.rtxSsrc),this.rtxSequenceNumber=R9(this.rtxSequenceNumber,1);await this.dtlsTransport.sendRtp(J.payload,J.header)}}),this.onGenericNack.execute(G)}break}}break;case rV.type:{let X=W;switch(X.feedback.count){case ZH.count:{let G=X.feedback;this.receiverEstimatedMaxBitrate=G.bitrate}break;case JH.count:this.onPictureLossIndication.execute();break}}break}this.onRtcp.execute(W)}getParameters(){return{encodings:[]}}setParameters(W){}async getStats(){let W=SX(),X=[];if(!this.dtlsTransport)return X;let G=N8("transport",this.dtlsTransport.id),Y={type:"outbound-rtp",id:N8("outbound-rtp",this.ssrc),timestamp:W,ssrc:this.ssrc,kind:this.kind,transportId:G,codecId:this.codec?N8("codec",this.codec.payloadType,G):void 0,mid:this.mid,packetsSent:this.packetCount,bytesSent:this.octetCount,rtxSsrc:this.rtxPayloadType?this.rtxSsrc:void 0};if(X.push(Y),this.track){let J={type:"media-source",id:N8("media-source",this.trackId),timestamp:W,trackIdentifier:this.trackId,kind:this.kind};X.push(J)}if(this.rtt!==void 0){let J={type:"remote-inbound-rtp",id:N8("remote-inbound-rtp",this.ssrc),timestamp:W,ssrc:this.ssrc,kind:this.kind,transportId:G,codecId:Y.codecId,localId:Y.id,roundTripTime:this.rtt};X.push(J)}return X}},or=P1("werift:packages/webrtc/src/transport/sctpManager.ts"),nr=class{sctpTransport;sctpRemotePort;dataChannelsOpened=0;dataChannelsClosed=0;dataChannels=[];onDataChannel=new d0;constructor(){}createSctpTransport(W){let X=new gr(5000,W);return X.mid=void 0,X.onDataChannel.subscribe((G)=>{this.dataChannelsOpened++,this.dataChannels.push(G),this.onDataChannel.execute(G)}),this.sctpTransport=X,X}createDataChannel(W,X={}){let Y={...{protocol:"",ordered:!0,negotiated:!1},...X};if(Y.maxPacketLifeTime&&Y.maxRetransmits)throw Error("can not select both");if(!this.sctpTransport)this.sctpTransport=this.createSctpTransport();let J=new mS({id:Y.id,label:W,maxPacketLifeTime:Y.maxPacketLifeTime,maxRetransmits:Y.maxRetransmits,negotiated:Y.negotiated,ordered:Y.ordered,protocol:Y.protocol}),Z=new bS(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(),or("sctp connected")}setRemoteSCTP(W,X){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=X,!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=SX(),X=[];for(let G of this.dataChannels){let Y={type:"data-channel",id:N8("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};X.push(Y)}return X}},ir=class{currentLocalDescription;currentRemoteDescription;pendingLocalDescription;pendingRemoteDescription;cname;midSuffix;bundlePolicy;seenMid=new Set;constructor({cname:W,midSuffix:X,bundlePolicy:G}){this.cname=W,this.midSuffix=X??!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,X){let G=new eK(W.kind,9,"UDP/TLS/RTP/SAVPF",W.codecs.map((Y)=>Y.payloadType));if(G.direction=X,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 XO({ssrc:W.sender.ssrc,cname:this.cname})],W.options.simulcast)G.simulcastParameters=W.options.simulcast.map((Y)=>new fS(Y));if(G.rtp.codecs.find((Y)=>Y.name.toLowerCase()==="rtx"))G.ssrc.push(new XO({ssrc:W.sender.rtxSsrc,cname:this.cname})),G.ssrcGroup=[new nV("FID",[W.sender.ssrc.toString(),W.sender.rtxSsrc.toString()])];return this.addTransportDescription(G,W.dtlsTransport),G}createMediaDescriptionForSctp(W){let X=new eK("application",tF,"UDP/DTLS/SCTP",["webrtc-datachannel"]);return X.sctpPort=W.port,X.rtp.muxId=W.mid,X.sctpCapabilities=W.getCapabilities(),this.addTransportDescription(X,W.dtlsTransport),X}addTransportDescription(W,X){let G=X.iceTransport;if(W.iceCandidates=G.localCandidates,W.iceCandidatesComplete=G.gatheringState==="complete",W.iceParams=G.localParameters,W.iceOptions="trickle",W.host=vi,W.port=tF,W.direction==="inactive")W.port=0,W.msid=void 0;if(!W.dtlsParams){if(W.dtlsParams=X.localParameters,!W.dtlsParams.fingerprints)W.dtlsParams.fingerprints=X.localParameters.fingerprints}}allocateMid(W=""){let X="";for(let G=0;;)if(X=(G++).toString()+W,!this.seenMid.has(X))break;return this.seenMid.add(X),X}parseSdp({sdp:W,isLocal:X,signalingState:G,type:Y}){let J=rq.parse(W);return this.validateDescription({description:J,isLocal:X,signalingState:G}),J.type=Y,J}validateDescription({description:W,isLocal:X,signalingState:G}){if(X){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,X){let G=new rq;j2("offer",G),(this.currentLocalDescription?.media??[]).forEach((J,Z)=>{let V=J.rtp.muxId;if(!V)return;if(J.kind==="application"){if(!X)throw Error("sctpTransport not found");X.mLineIndex=Z,G.media.push(this.createMediaDescriptionForSctp(X))}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(X&&!G.media.find((J)=>J.kind==="application")){if(X.mLineIndex=G.media.length,X.mid==null)X.mid=this.allocateMid(this.midSuffix?"dc":"");G.media.push(this.createMediaDescriptionForSctp(X))}if(this.bundlePolicy!=="disable"){let J=G.media.map((Z)=>Z.rtp.muxId).filter((Z)=>Z);if(J.length){let Z=new nV("BUNDLE",J);G.group.push(Z)}}return G}buildAnswerSdp({transceivers:W,sctpTransport:X,signalingState:G}){if(!["have-remote-offer","have-local-pranswer"].includes(G))throw Error("createAnswer failed");if(!this._remoteDescription)throw Error("wrong state");let Y=new rq;j2("answer",Y);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,eS(U.direction,U.offerDirection)),Z=U.dtlsTransport}else if(J.kind==="application"){if(!X||!X.mid)throw Error("sctpTransport not found");V=this.createMediaDescriptionForSctp(X),Z=X.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"}));Y.media.push(V)}if(this.bundlePolicy!=="disable"){let J=new nV("BUNDLE",[]);for(let Z of Y.media)if(Z.rtp.muxId)J.items.push(Z.rtp.muxId);Y.group.push(J)}return Y}setLocalDescription(W){if(this.currentLocalDescription=W,W.type==="answer")this.pendingLocalDescription=void 0;else this.pendingLocalDescription=W}setRemoteDescription(W,X){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:X,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,X,G){let Y=new Map(X.map((V)=>[V?.mLineIndex,V])),J=X.find((V)=>V?.dtlsTransport)?.dtlsTransport??G?.dtlsTransport;W.media.filter((V)=>["audio","video"].includes(V.kind)).forEach((V,U)=>{let N=(Y.get(U)??X[U])?.dtlsTransport??J;if(!N)throw Error(`dtls transport not found for media index ${U}`);this.addTransportDescription(V,N)});let Z=W.media.find((V)=>V.kind==="application");if(G&&Z)this.addTransportDescription(Z,G.dtlsTransport);this.setLocalDescription(W)}},mV=P1("werift:packages/webrtc/src/transport/secureTransportManager.ts"),rr=class{connectionState="new";iceConnectionState="new";iceGatheringState="new";certificate;iceGatheringStateChange=new d0;iceConnectionStateChange=new d0;onIceCandidate=new d0;connectionStateChange=new d0;config;transceiverManager;sctpManager;constructor({config:W,transceiverManager:X,sctpManager:G}){if(this.config=W,this.transceiverManager=X,this.sctpManager=G,this.config.dtls){let{keys:Y}=this.config.dtls;if(Y)this.setupCertificate(Y)}}get dtlsTransports(){return[...this.transceiverManager.getTransceivers().map((X)=>X?.dtlsTransport),this.sctpManager.sctpTransport?.dtlsTransport].filter((X)=>X!=null).reduce((X,G)=>{if(!X.map((Y)=>Y.id).includes(G.id))X.push(G);return X},[])}get iceTransports(){return this.dtlsTransports.map((W)=>W.iceTransport)}setupCertificate(W){this.certificate=new Gx(W.keyPem,W.certPem,W.signatureHash)}createTransport(){let W=this.iceTransports.find((J)=>J.state!=="closed"),X=new zr({...ri(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)X.connection.localUsername=W.connection.localUsername,X.connection.localPassword=W.connection.localPassword;X.onGatheringStateChange.subscribe(()=>{this.updateIceGatheringState()}),this.updateIceGatheringState();let G=new Ar(X);return G.onStateChange.subscribe(()=>{this.updateIceConnectionState()}),new G2(this.config,G,this.certificate,ar)}handleNewIceCandidate({candidate:W,media:X,remoteIsBundled:G,transceiver:Y,sctpTransport:J,bundlePolicy:Z}){if(Z==="max-bundle"||G){if(W.sdpMLineIndex=0,X)W.sdpMid=X.rtp.muxId}else{if(Y)W.sdpMLineIndex=Y.mLineIndex,W.sdpMid=Y.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,X){let G=Yx.fromJSON(X);if(!G)return;let Y;if(typeof G.sdpMid==="number")Y=this.getTransportByMid(G.sdpMid);if(!Y&&typeof G.sdpMLineIndex==="number")Y=this.getTransportByMLineIndex(W,G.sdpMLineIndex);if(!Y)Y=this.iceTransports[0];if(Y)await Y.addRemoteCandidate(G);else mV("iceTransport not found for candidate",G)}getTransportByMid(W){let X,G=this.transceiverManager.getTransceivers().find((Y)=>Y.mid===W);if(G)X=G.dtlsTransport.iceTransport;else if(!X&&this.sctpManager.sctpTransport?.mid===W)X=this.sctpManager.sctpTransport.dtlsTransport.iceTransport;return X}getTransportByMLineIndex(W,X){let G=W.media[X];if(!G)return;return this.getTransportByMid(G.rtp.muxId)}restartIce(){for(let W of this.iceTransports)W.restart()}setLocalRole({type:W,role:X}){for(let G of this.dtlsTransports){let Y=G.iceTransport;if(W==="offer")Y.connection.iceControlling=!0;else Y.connection.iceControlling=!1;if(Y.connection.remoteIsLite)Y.connection.iceControlling=!0;if(W==="answer"){if(X)G.role=X}}}updateIceGatheringState(){let W=this.iceTransports;function X(...Y){return W.filter((J)=>Y.includes(J.gatheringState)).length===W.length}let G;if(W.length&&X("complete"))G="complete";else if(!W.length||X("new","complete"))G="new";else if(W.map((Y)=>Y.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,X;function G(...J){return W.filter((Z)=>J.includes(Z.state)).length===W.length}function Y(...J){return W.some((Z)=>J.includes(Z.state))}if(this.connectionState==="closed")X="closed";else if(Y("failed"))X="failed";else if(Y("disconnected"))X="disconnected";else if(G("new","closed"))X="new";else if(Y("new","checking"))X="checking";else if(G("completed","closed"))X="completed";else if(G("connected","completed","closed"))X="connected";else X="new";if(this.iceConnectionState===X)return;mV("iceConnectionStateChange",X),this.iceConnectionState=X,this.iceConnectionStateChange.execute(X)}async gatherCandidates(W){let X=this.iceTransports.find((G)=>G.state==="connected"||G.state==="completed");if(W&&X)mV("skipping ICE gathering for bundled connection");else await Promise.allSettled(this.iceTransports.map((G)=>G.gather())).catch((G)=>{mV("gatherCandidates failed",G)})}setConnectionState(W){mV("connectionStateChange",W),this.connectionState=W,this.connectionStateChange.execute(W)}async getStats(){let W=[];for(let X of this.dtlsTransports){let G=await X.getStats();if(G)W.push(...G)}return W}async ensureCerts(){if(!this.certificate)this.certificate=await G2.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()}},ar=[W2.SRTP_AEAD_AES_128_GCM,W2.SRTP_AES128_CM_HMAC_SHA1_80],Y7=P1("werift:packages/webrtc/src/peerConnection.ts"),Kx=class extends HO{cname=dr().toString();config=Ox();signalingState="stable";negotiationneeded=!1;needRestart=!1;router=new mr;sdpManager;transceiverManager;sctpManager;secureManager;isClosed=!1;shouldNegotiationneeded=!1;remoteBundleNegotiated=!1;iceGatheringStateChange=new d0;iceConnectionStateChange=new d0;signalingStateChange=new d0;connectionStateChange=new d0;onDataChannel=new d0;onRemoteTransceiverAdded=new d0;onTransceiverAdded=new d0;onIceCandidate=new d0;onNegotiationneeded=new d0;onTrack=new d0;ondatachannel;onicecandidate;onicecandidateerror;onicegatheringstatechange;onnegotiationneeded;onsignalingstatechange;ontrack;onconnectionstatechange;oniceconnectionstatechange;constructor(W={}){super();this.setConfiguration(W),this.sdpManager=new ir({cname:this.cname,bundlePolicy:this.config.bundlePolicy}),this.transceiverManager=new tr(this.cname,this.config,this.router),this.transceiverManager.onTransceiverAdded.pipe(this.onTransceiverAdded),this.transceiverManager.onRemoteTransceiverAdded.pipe(this.onRemoteTransceiverAdded),this.transceiverManager.onTrack.subscribe(({track:X,stream:G,transceiver:Y})=>{let J={track:X,streams:[G],transceiver:Y,receiver:Y.receiver};if(this.onTrack.execute(X),this.emit("track",J),this.ontrack)this.ontrack(J)}),this.transceiverManager.onNegotiationNeeded.subscribe(()=>this.needNegotiation()),this.sctpManager=new nr,this.sctpManager.onDataChannel.subscribe((X)=>{this.onDataChannel.execute(X);let G={channel:X};this.ondatachannel?.(G),this.emit("datachannel",G)}),this.secureManager=new rr({config:this.config,sctpManager:this.sctpManager,transceiverManager:this.transceiverManager}),this.secureManager.iceGatheringStateChange.pipe(this.iceGatheringStateChange),this.secureManager.iceConnectionStateChange.subscribe((X)=>{if(X==="closed")this.close();this.iceConnectionStateChange.execute(X)}),this.secureManager.connectionStateChange.subscribe((X)=>{this.connectionStateChange.execute(X),this.onconnectionstatechange?.(),this.emit("connectionstatechange")}),this.secureManager.onIceCandidate.subscribe((X)=>{let G=X?X.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(ai(this.config,W),this.config.icePortRange){let[X,G]=this.config.icePortRange;if(X===G)throw Error("should not be same value");if(X>=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[X,G]of nF([...this.config.codecs.audio||[],...this.config.codecs.video||[]])){if(G.payloadType!=null)continue;switch(G.payloadType=96+X,G.name.toLowerCase()){case"rtx":G.parameters=`apt=${G.payloadType-1}`;break;case"red":if(G.contentType==="audio"){let Y=G.payloadType+1;G.parameters=`${Y}/${Y}`,G.payloadType=63}break}}[...this.config.headerExtensions.audio||[],...this.config.headerExtensions.video||[]].forEach((X,G)=>{X.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),X=this.findOrCreateTransport();return W.setDtlsTransport(X),W}createDataChannel(W,X={}){if(!this.sctpTransport)this.createSctpTransport(),this.needNegotiation();let G=this.sctpManager.createDataChannel(W,X);if(!G.sctp.dtlsTransport){let Y=this.findOrCreateTransport();G.sctp.setDtlsTransport(Y)}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"),X=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 Y=G.iceTransport;return Y.onNegotiationNeeded.subscribe(()=>{this.needNegotiation()}),Y.onIceCandidate.subscribe((J)=>{if(!this.localDescription){Y7("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){Y7("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===Y.id),sctpTransport:this.sctpTransport?.dtlsTransport.iceTransport.id===Y.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 nF(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 Y=G.media.find((J)=>J.dtlsParams)?.dtlsParams?.role;if(this.secureManager.setLocalRole({type:G.type,role:Y}),["answer","pranswer"].includes(G.type))for(let J of this.transceiverManager.getTransceivers()){let Z=eS(J.direction,J.offerDirection);J.setCurrentDirection(Z)}if(this.sdpManager.setLocal(G,this.transceiverManager.getTransceivers(),this.sctpTransport),await this.gatherCandidates().catch((J)=>{Y7("gatherCandidates failed",J)}),G.type==="answer")this.connect().catch((J)=>{Y7("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 X=this.sdpManager.buildOfferSdp(this.transceiverManager.getTransceivers(),this.sctpTransport);await this.secureManager.addIceCandidate(X,W)}async connect(){if(Y7("start connect"),(await Promise.allSettled(this.dtlsTransports.map(async(X)=>{let{iceTransport:G}=X;if(G.state==="connected")return;let Y=()=>X.state==="connected";if(Y())return;if(this.secureManager.setConnectionState("connecting"),await G.start().catch((J)=>{throw Y7("iceTransport.start failed",J),J}),Y())return;if(await X.start().catch((J)=>{throw Y7("dtlsTransport.start failed",J),J}),this.sctpTransport&&this.sctpTransport.dtlsTransport.id===X.id)await this.sctpManager.connectSctp()}))).find((X)=>X.status==="rejected"))this.secureManager.setConnectionState("failed");else this.secureManager.setConnectionState("connected")}restartIce(){this.needRestart=!0,this.needNegotiation()}async setRemoteDescription(W){if(W instanceof rq)W=W.toSdp();let X=this.sdpManager.setRemoteDescription(W,this.signalingState);if(X.group.some((V)=>V.semantic==="BUNDLE"&&V.items.length>0))this.remoteBundleNegotiated=!0;let G,Y=(V,U)=>V.kind===U.kind&&[void 0,U.rtp.muxId].includes(V.mid),J=X.media.map((V,U)=>{let Q;if(["audio","video"].includes(V.kind)){let q=this.transceiverManager.getTransceivers().find((A)=>Y(A,V));if(!q)q=this.addTransceiver(V.kind,{direction:"recvonly"}),q.mid=V.rtp.muxId,this.onRemoteTransceiverAdded.execute(q);else if(q.direction==="inactive"&&q.stopping){if(q.stopped=!0,W.type==="answer")q.setCurrentDirection("inactive");return}if(this.sdpManager.remoteIsBundled)if(!G)G=q.dtlsTransport;else q.setDtlsTransport(G);Q=q.dtlsTransport,this.transceiverManager.setRemoteRTP(q,V,X.type,U)}else if(V.kind==="application"){let q=this.sctpTransport;if(!q)q=this.createSctpTransport(),q.mid=V.rtp.muxId;if(this.sdpManager.remoteIsBundled)if(!G)G=q.dtlsTransport;else q.setDtlsTransport(G);Q=q.dtlsTransport,this.sctpManager.setRemoteSCTP(V,U)}else throw Error("invalid media kind");let N=Q.iceTransport;if(V.iceParams){let q=!!this.sdpManager.inactiveRemoteMedia;if(N.setRemoteParams(V.iceParams,q),V.iceParams?.iceLite)N.connection.iceControlling=!0}if(V.dtlsParams)Q.setRemoteParams(V.dtlsParams);if(V.iceCandidates.forEach(N.addRemoteCandidate),V.iceCandidatesComplete)N.addRemoteCandidate(void 0);if(X.type==="answer"&&V.dtlsParams?.role)Q.role=V.dtlsParams.role==="client"?"server":"client";return N});J=J.filter((V)=>!!V);let Z=this.transceiverManager.getTransceivers().filter((V)=>X.media.find((U)=>Y(V,U))==null);if(W.type==="answer")for(let V of Z)V.stop(),V.stopped=!0;if(X.type==="offer")this.setSignalingState("have-remote-offer");else if(X.type==="answer")this.setSignalingState("stable");if(X.type==="answer")Y7("caller start connect"),this.connect().catch((V)=>{Y7("connect failed",V),this.secureManager.setConnectionState("failed")});if(this.negotiationneeded=!1,this.shouldNegotiationneeded)this.needNegotiation()}addTransceiver(W,X={}){let G=this.findOrCreateTransport(),Y=this.transceiverManager.addTransceiver(W,G,X);return this.secureManager.updateIceConnectionState(),this.needNegotiation(),Y}addTrack(W,X){if(this.isClosed)throw Error("is closed");let G=this.transceiverManager.addTrack(W,X);if(!G.dtlsTransport){let Y=this.findOrCreateTransport();G.setDtlsTransport(Y)}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(Y7("signalingStateChange",W),this.signalingState=W,this.signalingStateChange.execute(W),this.onsignalingstatechange)this.onsignalingstatechange({})}createPeerConnectionStats(){let W=SX();return{type:"peer-connection",id:N8("peer-connection"),timestamp:W,dataChannelsOpened:this.sctpManager.dataChannelsOpened,dataChannelsClosed:this.sctpManager.dataChannelsClosed}}async getStats(W){let X=[];X.push(this.createPeerConnectionStats());let G=await this.transceiverManager.getStats(W);X.push(...G);let Y=await this.secureManager.getStats();if(X.push(...Y),this.sctpTransport){let J=await this.sctpManager.getStats();if(J)X.push(...J)}return new hi(X)}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(),Y7("peerConnection closed")}},M2=(W,X)=>W.find((G)=>G.mimeType.toLowerCase()===X.mimeType.toLowerCase())?X:void 0;function Ox(){return{codecs:{audio:[cS(),lS()],video:[pS()]},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 mA0=Ox(),sr=P1("werift:packages/webrtc/src/media/rtpTransceiverManager.ts"),tr=class{constructor(W,X,G){this.cname=W,this.config=X,this.router=G}transceivers=[];onTransceiverAdded=new d0;onRemoteTransceiverAdded=new d0;onTrack=new d0;onNegotiationNeeded=new d0;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((X)=>X.mLineIndex===W)}pushTransceiver(W){this.transceivers.push(W)}replaceTransceiver(W,X){this.transceivers[X]=W}addTransceiver(W,X,G={}){let Y=typeof W==="string"?W:W.kind,J=G.direction||"sendrecv",Z=new lr(W),V=new jx(this.config,Y,Z.ssrc),U=new bi(Y,X,V,Z,J);U.options=G,this.router.registerRtpSender(U.sender);let Q=this.transceivers.findIndex((q)=>q.currentDirection==="inactive"&&!q.usedForSender),N=this.transceivers.find((q)=>q.currentDirection==="inactive"&&!q.usedForSender);if(Q>-1&&N)this.replaceTransceiver(U,Q),U.mLineIndex=N.mLineIndex,U.mid=N.mid,N.setCurrentDirection(void 0);else this.pushTransceiver(U);return this.onTransceiverAdded.execute(U),U}addTrack(W,X){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&&cq.includes(J.direction)===!0);if(G)return G.sender.registerTrack(W),G;let Y=this.transceivers.find((J)=>J.sender.track==null&&J.kind===W.kind&&cq.includes(J.direction)===!1&&!J.usedForSender);if(Y){switch(Y.sender.registerTrack(W),Y.direction){case"recvonly":Y.setDirection("sendrecv");break;case"inactive":Y.setDirection("sendonly");break}return Y}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 X=this.transceivers.find(({sender:{ssrc:G}})=>W.ssrc===G);if(!X)throw Error("No matching transceiver found");if(W.stop(),X.currentDirection==="recvonly"){this.onNegotiationNeeded.execute();return}if(X.stopping||X.stopped)X.setDirection("inactive");else if(X.direction==="sendrecv")X.setDirection("recvonly");else if(X.direction==="sendonly"||X.direction==="recvonly")X.setDirection("inactive")}assignTransceiverCodecs(W){let X=this.config.codecs[W.kind].filter((G)=>{switch(G.direction){case"recvonly":{if(ui.includes(W.direction))return!0;return!1}case"sendonly":{if(cq.includes(W.direction))return!0;return!1}case"sendrecv":{if([rS,iS,nS].includes(W.direction))return!0;return!1}case"all":return!0;default:return!1}});W.codecs=X}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,X){return{muxId:W.rtp.muxId,rtcp:W.rtp.rtcp,codecs:X.codecs,headerExtensions:X.headerExtensions,encodings:Object.values(X.codecs.reduce((Y,J)=>{if(J.name.toLowerCase()==="rtx"){let Z=HH(J.parameters??""),V=Y[Z.apt];if(V&&W.ssrc.length===2)V.rtx=new Ri({ssrc:W.ssrc[1].ssrc});return Y}return Y[J.payloadType]=new Li({ssrc:W.ssrc[0]?.ssrc,payloadType:J.payloadType}),Y},{}))}}setRemoteRTP(W,X,G,Y){if(!W.mid)W.mid=X.rtp.muxId;if(W.mLineIndex=Y,W.codecs=X.rtp.codecs.filter((U)=>{let Q=this.config.codecs[X.kind]||[],N=M2(Q,U);if(!N)return!1;if(N?.name.toLowerCase()==="rtx"){let A=HH(N.parameters??"").apt,H=X.rtp.codecs.find((I)=>I.payloadType===A);if(!H)return!1;return!!M2(Q,H)}return!0}),sr("negotiated codecs",W.codecs),W.codecs.length===0)throw Error("negotiate codecs failed.");W.headerExtensions=X.rtp.headerExtensions.filter((U)=>(this.config.headerExtensions[X.kind]||[]).find((Q)=>Q.uri===U.uri));let J=X.direction??"inactive",Z=di(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(X,W);for(let Q of X.simulcastParameters)this.router.registerRtpReceiverByRid(W,Q,U);W.receiver.prepareReceive(U),this.router.registerRtpReceiverBySsrc(W,U)}if(["sendonly","sendrecv"].includes(J)){if(X.msid){let[U,Q]=X.msid.split(" ");W.receiver.remoteStreamId=U,W.receiver.remoteTrackId=Q}this.onTrack.execute({track:W.receiver.track,transceiver:W,stream:new fi({id:W.receiver.remoteStreamId,tracks:[W.receiver.track]})})}if(X.ssrc[0]?.ssrc)W.receiver.setupTWCC(X.ssrc[0].ssrc)}async getStats(W){let X=[];for(let G of this.transceivers){let Y=!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(Y)X.push(Z)}else X.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(Y)X.push(Z)}else X.push(Z)}if(Y){let J=G.getCodecStats();if(J)X.push(...J)}}return X}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 zO extends Kx{toJSON(){return{}}createDataChannel(...W){let X=super.createDataChannel(...W);try{X.toJSON=()=>({})}catch{}return X}}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */var oY={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},er={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]},Wa=BigInt(0),Dx=BigInt(1),IO=BigInt(2);function Xa(W){let X=oY.p,G=BigInt(3),Y=BigInt(6),J=BigInt(11),Z=BigInt(22),V=BigInt(23),U=BigInt(44),Q=BigInt(88),N=W*W*W%X,q=N*N*W%X,A=q5(q,G,X)*q%X,H=q5(A,G,X)*q%X,I=q5(H,IO,X)*N%X,w=q5(I,J,X)*I%X,O=q5(w,Z,X)*w%X,T=q5(O,U,X)*O%X,x=q5(T,Q,X)*T%X,h=q5(x,U,X)*O%X,$=q5(h,G,X)*q%X,F=q5($,V,X)*w%X,u=q5(F,Y,X)*N%X,l=q5(u,IO,X);if(!CH.eql(CH.sqr(l),W))throw Error("Cannot find square root");return l}var CH=$5(oY.p,{sqrt:Xa}),Mx=MY({...oY,Fp:CH,lowS:!0,endo:er},DY),Cx={};function TH(W,...X){let G=Cx[W];if(G===void 0){let Y=DY(Aq(W));G=a9(Y,Y),Cx[W]=G}return DY(a9(G,...X))}var jO=(W)=>W.toBytes(!0).slice(1),nY=(()=>Mx.Point)(),KO=(W)=>W%IO===Wa;function wO(W){let{Fn:X,BASE:G}=nY,Y=n6(X,W),J=G.multiply(Y);return{scalar:KO(J.y)?Y:X.neg(Y),bytes:jO(J)}}function Px(W){let X=CH;if(!X.isValidNot0(W))throw Error("invalid x: Fail if x \u2265 p");let G=X.create(W*W),Y=X.create(G*W+BigInt(7)),J=X.sqrt(Y);if(!KO(J))J=X.neg(J);let Z=nY.fromAffine({x:W,y:J});return Z.assertValidity(),Z}var AU=$4;function Rx(...W){return nY.Fn.create(AU(TH("BIP0340/challenge",...W)))}function Tx(W){return wO(W).bytes}function Ga(W,X,G=AX(32)){let{Fn:Y}=nY,J=F8("message",W),{bytes:Z,scalar:V}=wO(X),U=F8("auxRand",G,32),Q=Y.toBytes(V^AU(TH("BIP0340/aux",U))),N=TH("BIP0340/nonce",Q,Z,J),{bytes:q,scalar:A}=wO(N),H=Rx(q,Z,J),I=new Uint8Array(64);if(I.set(q,0),I.set(Y.toBytes(Y.create(A+H*V)),32),!Lx(I,J,Z))throw Error("sign: Invalid signature produced");return I}function Lx(W,X,G){let{Fn:Y,BASE:J}=nY,Z=F8("signature",W,64),V=F8("message",X),U=F8("publicKey",G,32);try{let Q=Px(AU(U)),N=AU(Z.subarray(0,32));if(!LV(N,Dx,oY.p))return!1;let q=AU(Z.subarray(32,64));if(!LV(q,Dx,oY.n))return!1;let A=Rx(Y.toBytes(N),jO(Q),V),H=J.multiplyUnsafe(q).add(Q.multiplyUnsafe(Y.neg(A))),{x:I,y:w}=H.toAffine();if(H.is0()||!KO(w)||I!==N)return!1;return!0}catch(Q){return!1}}var Bx=(()=>{let G=(J=AX(48))=>{return Kq(J,oY.n)};Mx.utils.randomSecretKey;function Y(J){let Z=G(J);return{secretKey:Z,publicKey:Tx(Z)}}return{keygen:Y,getPublicKey:Tx,sign:Ga,verify:Lx,Point:nY,utils:{randomSecretKey:G,randomPrivateKey:G,taggedHash:TH,lift_x:Px,pointToBytes:jO,numberToBytesBE:OY,bytesToNumberBE:$4,mod:N5},lengths:{secretKey:32,publicKey:32,publicKeyHasPrefix:!1,signature:64,seed:48}}})();var Ex=(W)=>Uint8Array.from(W.match(/.{2}/g).map((X)=>parseInt(X,16))),Ya=(W)=>[...W].map((X)=>X.toString(16).padStart(2,"0")).join(""),Ja=async(W)=>{try{if(typeof W.pubkey!=="string"||typeof W.sig!=="string"||typeof W.id!=="string")return!1;let X=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",X));if(Ya(G)!==W.id)return!1;return Bx.verify(Ex(W.sig),G,Ex(W.pubkey))}catch{return!1}},Za=(W,X)=>{if(W.kinds&&!W.kinds.includes(X.kind))return!1;if(W.since&&X.created_at<W.since-60)return!1;if(W["#x"]){let G=(X.tags??[]).filter((Y)=>Y?.[0]==="x").map((Y)=>Y[1]);if(!W["#x"].some((Y)=>G.includes(Y)))return!1}return!0};function $x({port:W=Number(process.env.PORT)||8080}={}){let X=new Map,G=0,Y=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:X.size,events:G,dropped:Y})},websocket:{open(Z){X.set(Z,new Map)},close(Z){X.delete(Z)},async message(Z,V){let U;try{U=JSON.parse(String(V))}catch{return}if(!Array.isArray(U))return;let[Q,N,q]=U;if(Q==="REQ"&&typeof N==="string"&&q&&typeof q==="object"){X.get(Z)?.set(N,q),Z.send(JSON.stringify(["EOSE",N]));return}if(Q==="CLOSE"&&typeof N==="string"){X.get(Z)?.delete(N);return}if(Q==="EVENT"&&N&&typeof N==="object"){if(!await Ja(N)){Y++,Z.send(JSON.stringify(["OK",N.id??"",!1,"invalid: bad signature"]));return}G++,Z.send(JSON.stringify(["OK",N.id,!0,""]));for(let[A,H]of X)for(let[I,w]of H)if(Za(w,N)){try{A.send(JSON.stringify(["EVENT",I,N]))}catch{}break}}}}});return console.info(`\uD83D\uDCE1 Relay listening on :${J.port} (ephemeral, schnorr-verified)`),{port:J.port,stats:()=>({connections:X.size,events:G,dropped:Y}),stop:()=>J.stop(!0)}}var MH="6.15.0";function Va(W,X,G){let Y=X.split("|").map((Z)=>Z.trim());for(let Z=0;Z<Y.length;Z++)switch(X){case"any":return;case"bigint":case"boolean":case"number":case"string":if(typeof W===X)return}let J=Error(`invalid value for type ${X}`);throw J.code="INVALID_ARGUMENT",J.argument=`value.${G}`,J.value=W,J}async function i7(W){let X=Object.keys(W);return(await Promise.all(X.map((Y)=>Promise.resolve(W[Y])))).reduce((Y,J,Z)=>{return Y[X[Z]]=J,Y},{})}function A8(W,X,G){for(let Y in X){let J=X[Y],Z=G?G[Y]:null;if(Z)Va(J,Z,Y);Object.defineProperty(W,Y,{enumerable:!0,value:J,writable:!1})}}function iY(W,X){if(W==null)return"null";if(X==null)X=new Set;if(typeof W==="object"){if(X.has(W))return"[Circular]";X.add(W)}if(Array.isArray(W))return"[ "+W.map((G)=>iY(G,X)).join(", ")+" ]";if(W instanceof Uint8Array){let Y="0x";for(let J=0;J<W.length;J++)Y+="0123456789abcdef"[W[J]>>4],Y+="0123456789abcdef"[W[J]&15];return Y}if(typeof W==="object"&&typeof W.toJSON==="function")return iY(W.toJSON(),X);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((Y)=>`${iY(Y,X)}: ${iY(W[Y],X)}`).join(", ")+" }"}}return"[ COULD NOT SERIALIZE ]"}function PH(W,X){return W&&W.code===X}function zU(W,X,G){let Y=W;{let Z=[];if(G){if("message"in G||"code"in G||"name"in G)throw Error(`value will overwrite populated values: ${iY(G)}`);for(let V in G){if(V==="shortMessage")continue;let U=G[V];Z.push(V+"="+iY(U))}}if(Z.push(`code=${X}`),Z.push(`version=${MH}`),Z.length)W+=" ("+Z.join(", ")+")"}let J;switch(X){case"INVALID_ARGUMENT":J=TypeError(W);break;case"NUMERIC_FAULT":case"BUFFER_OVERRUN":J=RangeError(W);break;default:J=Error(W)}if(A8(J,{code:X}),G)Object.assign(J,G);if(J.shortMessage==null)A8(J,{shortMessage:Y});return J}function Y1(W,X,G,Y){if(!W)throw zU(X,G,Y)}function a(W,X,G,Y){Y1(W,X,"INVALID_ARGUMENT",{argument:G,value:Y})}var Ua=["NFD","NFC","NFKD","NFKC"].reduce((W,X)=>{try{if("test".normalize(X)!=="test")throw Error("bad");if(X==="NFD"){let G=String.fromCharCode(233).normalize("NFD"),Y=String.fromCharCode(101,769);if(G!==Y)throw Error("broken")}W.push(X)}catch(G){}return W},[]);function rY(W){Y1(Ua.indexOf(W)>=0,"platform missing String.prototype.normalize","UNSUPPORTED_OPERATION",{operation:"String.prototype.normalize",info:{form:W}})}function n4(W,X,G){if(G==null)G="";if(W!==X){let Y=G,J="new";if(G)Y+=".",J+=" "+G;Y1(!1,`private constructor; use ${Y}from* methods`,"UNSUPPORTED_OPERATION",{operation:J})}}function Sx(W,X,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 Y=new Uint8Array((W.length-2)/2),J=2;for(let Z=0;Z<Y.length;Z++)Y[Z]=parseInt(W.substring(J,J+2),16),J+=2;return Y}a(!1,"invalid BytesLike value",X||"value",W)}function E0(W,X){return Sx(W,X,!1)}function Q7(W,X){return Sx(W,X,!0)}function L9(W,X){if(typeof W!=="string"||!W.match(/^0x[0-9A-Fa-f]*$/))return!1;if(typeof X==="number"&&W.length!==2+2*X)return!1;if(X===!0&&W.length%2!==0)return!1;return!0}function r7(W){return L9(W,!0)||W instanceof Uint8Array}var Fx="0123456789abcdef";function M0(W){let X=E0(W),G="0x";for(let Y=0;Y<X.length;Y++){let J=X[Y];G+=Fx[(J&240)>>4]+Fx[J&15]}return G}function G8(W){return"0x"+W.map((X)=>M0(X).substring(2)).join("")}function i4(W){if(L9(W,!0))return(W.length-2)/2;return E0(W).length}function aY(W,X,G){let Y=E0(W);if(G!=null&&G>Y.length)Y1(!1,"cannot slice beyond data bounds","BUFFER_OVERRUN",{buffer:Y,length:Y.length,offset:G});return M0(Y.slice(X==null?0:X,G==null?Y.length:G))}function Qa(W,X,G){let Y=E0(W);Y1(X>=Y.length,"padding exceeds data length","BUFFER_OVERRUN",{buffer:new Uint8Array(Y),length:X,offset:X+1});let J=new Uint8Array(X);if(J.fill(0),G)J.set(Y,X-Y.length);else J.set(Y,0);return M0(J)}function I5(W,X){return Qa(W,X,!0)}var OO=BigInt(0),xX=BigInt(1),sY=9007199254740991;function RH(W,X){let G=f1(W,"value"),Y=BigInt(s8(X,"width")),J=xX<<Y-xX;if(G<OO){G=-G,Y1(G<=J,"too low","NUMERIC_FAULT",{operation:"toTwos",fault:"overflow",value:W});let Z=(xX<<Y)-xX;return(~G&Z)+xX}else Y1(G<J,"too high","NUMERIC_FAULT",{operation:"toTwos",fault:"overflow",value:W});return G}function LH(W,X){let G=IU(W,"value"),Y=BigInt(s8(X,"bits"));return G&(xX<<Y)-xX}function f1(W,X){switch(typeof W){case"bigint":return W;case"number":return a(Number.isInteger(W),"underflow",X||"value",W),a(W>=-sY&&W<=sY,"overflow",X||"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){a(!1,`invalid BigNumberish string: ${G.message}`,X||"value",W)}}a(!1,"invalid BigNumberish value",X||"value",W)}function IU(W,X){let G=f1(W,X);return Y1(G>=OO,"unsigned value cannot be negative","NUMERIC_FAULT",{fault:"overflow",operation:"getUint",value:W}),G}var xx="0123456789abcdef";function tY(W){if(W instanceof Uint8Array){let X="0x0";for(let G of W)X+=xx[G>>4],X+=xx[G&15];return BigInt(X)}return f1(W)}function s8(W,X){switch(typeof W){case"bigint":return a(W>=-sY&&W<=sY,"overflow",X||"value",W),Number(W);case"number":return a(Number.isInteger(W),"underflow",X||"value",W),a(W>=-sY&&W<=sY,"overflow",X||"value",W),W;case"string":try{if(W==="")throw Error("empty string");return s8(BigInt(W),X)}catch(G){a(!1,`invalid numeric string: ${G.message}`,X||"value",W)}}a(!1,"invalid numeric value",X||"value",W)}function N7(W,X){let Y=IU(W,"value").toString(16);if(X==null){if(Y.length%2)Y="0"+Y}else{let J=s8(X,"width");Y1(J*2>=Y.length,`value exceeds width (${J} bytes)`,"NUMERIC_FAULT",{operation:"toBeHex",fault:"overflow",value:W});while(Y.length<J*2)Y="0"+Y}return"0x"+Y}function z8(W){let X=IU(W,"value");if(X===OO)return new Uint8Array([]);let G=X.toString(16);if(G.length%2)G="0"+G;let Y=new Uint8Array(G.length/2);for(let J=0;J<Y.length;J++){let Z=J*2;Y[J]=parseInt(G.substring(Z,Z+2),16)}return Y}function BH(W){let X=M0(r7(W)?W:z8(W)).substring(2);while(X.startsWith("0"))X=X.substring(1);if(X==="")X="0";return"0x"+X}var $H="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",EH=null;function Na(W){if(EH==null){EH={};for(let G=0;G<$H.length;G++)EH[$H[G]]=BigInt(G)}let X=EH[W];return a(X!=null,"invalid base58 value","letter",W),X}var qa=BigInt(0),DO=BigInt(58);function FH(W){let X=E0(W),G=tY(X),Y="";while(G)Y=$H[Number(G%DO)]+Y,G/=DO;for(let J=0;J<X.length;J++){if(X[J])break;Y=$H[0]+Y}return Y}function SH(W){let X=qa;for(let G=0;G<W.length;G++)X*=DO,X+=Na(W[G]);return X}function Ha(W,X,G,Y,J){a(!1,`invalid codepoint at offset ${X}; ${W}`,"bytes",G)}function kx(W,X,G,Y,J){if(W==="BAD_PREFIX"||W==="UNEXPECTED_CONTINUE"){let Z=0;for(let V=X+1;V<G.length;V++){if(G[V]>>6!==2)break;Z++}return Z}if(W==="OVERRUN")return G.length-X-1;return 0}function Aa(W,X,G,Y,J){if(W==="OVERLONG")return a(typeof J==="number","invalid bad code point for replacement","badCodepoint",J),Y.push(J),0;return Y.push(65533),kx(W,X,G,Y,J)}var _x=Object.freeze({error:Ha,ignore:kx,replace:Aa});function Q9(W,X){if(a(typeof W==="string","invalid string value","str",W),X!=null)rY(X),W=W.normalize(X);let G=[];for(let Y=0;Y<W.length;Y++){let J=W.charCodeAt(Y);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){Y++;let Z=W.charCodeAt(Y);a(Y<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 za(W){let X=W.toString(16);while(X.length<2)X="0"+X;return"0x"+X}function yx(W,X,G){let Y=0;for(let J=0;J<G;J++)Y=Y*256+W[X+J];return Y}function vx(W,X,G,Y){let J=[];while(G<X+1+Y){let Z=gx(W,G);J.push(Z.result),G+=Z.consumed,Y1(G<=X+1+Y,"child data too short","BUFFER_OVERRUN",{buffer:W,length:Y,offset:X})}return{consumed:1+Y,result:J}}function gx(W,X){Y1(W.length!==0,"data too short","BUFFER_OVERRUN",{buffer:W,length:0,offset:1});let G=(Y)=>{Y1(Y<=W.length,"data short segment too short","BUFFER_OVERRUN",{buffer:W,length:W.length,offset:Y})};if(W[X]>=248){let Y=W[X]-247;G(X+1+Y);let J=yx(W,X+1,Y);return G(X+1+Y+J),vx(W,X,X+1+Y,Y+J)}else if(W[X]>=192){let Y=W[X]-192;return G(X+1+Y),vx(W,X,X+1,Y)}else if(W[X]>=184){let Y=W[X]-183;G(X+1+Y);let J=yx(W,X+1,Y);G(X+1+Y+J);let Z=M0(W.slice(X+1+Y,X+1+Y+J));return{consumed:1+Y+J,result:Z}}else if(W[X]>=128){let Y=W[X]-128;G(X+1+Y);let J=M0(W.slice(X+1,X+1+Y));return{consumed:1+Y,result:J}}return{consumed:1,result:za(W[X])}}function GW(W){let X=E0(W,"data"),G=gx(X,0);return a(G.consumed===X.length,"unexpected junk after rlp payload","data",W),G.result}function ux(W){let X=[];while(W)X.unshift(W&255),W>>=8;return X}function bx(W){if(Array.isArray(W)){let Y=[];if(W.forEach(function(Z){Y=Y.concat(bx(Z))}),Y.length<=55)return Y.unshift(192+Y.length),Y;let J=ux(Y.length);return J.unshift(247+J.length),J.concat(Y)}let X=Array.prototype.slice.call(E0(W,"object"));if(X.length===1&&X[0]<=127)return X;else if(X.length<=55)return X.unshift(128+X.length),X;let G=ux(X.length);return G.unshift(183+G.length),G.concat(X)}var hx="0123456789abcdef";function S5(W){let X="0x";for(let G of bx(W))X+=hx[G>>4],X+=hx[G&15];return X}function xH(W){let X=E0(W,"randomBytes");X[6]=X[6]&15|64,X[8]=X[8]&63|128;let G=M0(X);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 CO,createHmac as mx,pbkdf2Sync as fx,randomBytes as px}from"crypto";var cx=!1,lx=function(W,X,G){return mx(W,X).update(G).digest()},dx=lx;function YW(W,X,G){let Y=E0(X,"key"),J=E0(G,"data");return M0(dx(W,Y,J))}YW._=lx;YW.lock=function(){cx=!0};YW.register=function(W){if(cx)throw Error("computeHmac is locked");dx=W};Object.freeze(YW);function B9(W){if(!Number.isSafeInteger(W)||W<0)throw Error(`Wrong positive integer: ${W}`)}function wU(W,...X){if(!(W instanceof Uint8Array))throw Error("Expected Uint8Array");if(X.length>0&&!X.includes(W.length))throw Error(`Expected Uint8Array of length ${X}, not of length=${W.length}`)}function kH(W){if(typeof W!=="function"||typeof W.create!=="function")throw Error("Hash should be wrapped by utils.wrapConstructor");B9(W.outputLen),B9(W.blockLen)}function r4(W,X=!0){if(W.destroyed)throw Error("Hash instance has been destroyed");if(X&&W.finished)throw Error("Hash#digest() has already been called")}function _H(W,X){wU(W);let G=X.outputLen;if(W.length<G)throw Error(`digestInto() expects output buffer of length at least ${G}`)}var yH=BigInt(4294967295),ox=BigInt(32);function Ma(W,X=!1){if(X)return{h:Number(W&yH),l:Number(W>>ox&yH)};return{h:Number(W>>ox&yH)|0,l:Number(W&yH)|0}}function nx(W,X=!1){let G=new Uint32Array(W.length),Y=new Uint32Array(W.length);for(let J=0;J<W.length;J++){let{h:Z,l:V}=Ma(W[J],X);[G[J],Y[J]]=[Z,V]}return[G,Y]}var ix=(W,X,G)=>W<<G|X>>>32-G,rx=(W,X,G)=>X<<G|W>>>32-G,ax=(W,X,G)=>X<<G-32|W>>>64-G,sx=(W,X,G)=>W<<G-32|X>>>64-G;import*as jU from"crypto";var vH=jU&&typeof jU==="object"&&"webcrypto"in jU?jU.webcrypto:void 0;/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */var tx=(W)=>W instanceof Uint8Array;var eY=(W)=>new Uint32Array(W.buffer,W.byteOffset,Math.floor(W.byteLength/4)),WJ=(W)=>new DataView(W.buffer,W.byteOffset,W.byteLength),q7=(W,X)=>W<<32-X|W>>>X,Pa=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;if(!Pa)throw Error("Non little-endian hardware is not supported");var Ra=async()=>{};async function gH(W,X,G){let Y=Date.now();for(let J=0;J<W;J++){G(J);let Z=Date.now()-Y;if(Z>=0&&Z<X)continue;await Ra(),Y+=Z}}function La(W){if(typeof W!=="string")throw Error(`utf8ToBytes expected string, got ${typeof W}`);return new Uint8Array(new TextEncoder().encode(W))}function a7(W){if(typeof W==="string")W=La(W);if(!tx(W))throw Error(`expected Uint8Array, got ${typeof W}`);return W}function ex(...W){let X=new Uint8Array(W.reduce((Y,J)=>Y+J.length,0)),G=0;return W.forEach((Y)=>{if(!tx(Y))throw Error("Uint8Array expected");X.set(Y,G),G+=Y.length}),X}class kX{clone(){return this._cloneInto()}}var Ba={}.toString;function uH(W,X){if(X!==void 0&&Ba.call(X)!=="[object Object]")throw Error("Options should be object or undefined");return Object.assign(W,X)}function XJ(W){let X=(Y)=>W().update(a7(Y)).digest(),G=W();return X.outputLen=G.outputLen,X.blockLen=G.blockLen,X.create=()=>W(),X}function Wk(W=32){if(vH&&typeof vH.getRandomValues==="function")return vH.getRandomValues(new Uint8Array(W));throw Error("crypto.getRandomValues must be defined")}var[Yk,Jk,Zk]=[[],[],[]],Ea=BigInt(0),KU=BigInt(1),$a=BigInt(2),Fa=BigInt(7),Sa=BigInt(256),xa=BigInt(113);for(let W=0,X=KU,G=1,Y=0;W<24;W++){[G,Y]=[Y,(2*G+3*Y)%5],Yk.push(2*(5*Y+G)),Jk.push((W+1)*(W+2)/2%64);let J=Ea;for(let Z=0;Z<7;Z++)if(X=(X<<KU^(X>>Fa)*xa)%Sa,X&$a)J^=KU<<(KU<<BigInt(Z))-KU;Zk.push(J)}var[ka,_a]=nx(Zk,!0),Xk=(W,X,G)=>G>32?ax(W,X,G):ix(W,X,G),Gk=(W,X,G)=>G>32?sx(W,X,G):rx(W,X,G);function ya(W,X=24){let G=new Uint32Array(10);for(let Y=24-X;Y<24;Y++){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,N=G[Q],q=G[Q+1],A=Xk(N,q,1)^G[U],H=Gk(N,q,1)^G[U+1];for(let I=0;I<50;I+=10)W[V+I]^=A,W[V+I+1]^=H}let J=W[2],Z=W[3];for(let V=0;V<24;V++){let U=Jk[V],Q=Xk(J,Z,U),N=Gk(J,Z,U),q=Yk[V];J=W[q],Z=W[q+1],W[q]=Q,W[q+1]=N}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[Y],W[1]^=_a[Y]}G.fill(0)}class TO extends kX{constructor(W,X,G,Y=!1,J=24){super();if(this.blockLen=W,this.suffix=X,this.outputLen=G,this.enableXOF=Y,this.rounds=J,this.pos=0,this.posOut=0,this.finished=!1,this.destroyed=!1,B9(G),0>=this.blockLen||this.blockLen>=200)throw Error("Sha3 supports only keccak-f1600 function");this.state=new Uint8Array(200),this.state32=eY(this.state)}keccak(){ya(this.state32,this.rounds),this.posOut=0,this.pos=0}update(W){r4(this);let{blockLen:X,state:G}=this;W=a7(W);let Y=W.length;for(let J=0;J<Y;){let Z=Math.min(X-this.pos,Y-J);for(let V=0;V<Z;V++)G[this.pos++]^=W[J++];if(this.pos===X)this.keccak()}return this}finish(){if(this.finished)return;this.finished=!0;let{state:W,suffix:X,pos:G,blockLen:Y}=this;if(W[G]^=X,(X&128)!==0&&G===Y-1)this.keccak();W[Y-1]^=128,this.keccak()}writeInto(W){r4(this,!1),wU(W),this.finish();let X=this.state,{blockLen:G}=this;for(let Y=0,J=W.length;Y<J;){if(this.posOut>=G)this.keccak();let Z=Math.min(G-this.posOut,J-Y);W.set(X.subarray(this.posOut,this.posOut+Z),Y),this.posOut+=Z,Y+=Z}return W}xofInto(W){if(!this.enableXOF)throw Error("XOF is not possible for this instance");return this.writeInto(W)}xof(W){return B9(W),this.xofInto(new Uint8Array(W))}digestInto(W){if(_H(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:X,suffix:G,outputLen:Y,rounds:J,enableXOF:Z}=this;return W||(W=new TO(X,G,Y,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=Y,W.enableXOF=Z,W.destroyed=this.destroyed,W}}var va=(W,X,G)=>XJ(()=>new TO(X,W,G));var Vk=va(1,136,32);var Uk=!1,Qk=function(W){return Vk(W)},Nk=Qk;function U8(W){let X=E0(W,"data");return M0(Nk(X))}U8._=Qk;U8.lock=function(){Uk=!0};U8.register=function(W){if(Uk)throw TypeError("keccak256 is locked");Nk=W};Object.freeze(U8);function ga(W,X,G,Y){if(typeof W.setBigUint64==="function")return W.setBigUint64(X,G,Y);let J=BigInt(32),Z=BigInt(4294967295),V=Number(G>>J&Z),U=Number(G&Z),Q=Y?4:0,N=Y?0:4;W.setUint32(X+Q,V,Y),W.setUint32(X+N,U,Y)}class OU extends kX{constructor(W,X,G,Y){super();this.blockLen=W,this.outputLen=X,this.padOffset=G,this.isLE=Y,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(W),this.view=WJ(this.buffer)}update(W){r4(this);let{view:X,buffer:G,blockLen:Y}=this;W=a7(W);let J=W.length;for(let Z=0;Z<J;){let V=Math.min(Y-this.pos,J-Z);if(V===Y){let U=WJ(W);for(;Y<=J-Z;Z+=Y)this.process(U,Z);continue}if(G.set(W.subarray(Z,Z+V),this.pos),this.pos+=V,Z+=V,this.pos===Y)this.process(X,0),this.pos=0}return this.length+=W.length,this.roundClean(),this}digestInto(W){r4(this),_H(W,this),this.finished=!0;let{buffer:X,view:G,blockLen:Y,isLE:J}=this,{pos:Z}=this;if(X[Z++]=128,this.buffer.subarray(Z).fill(0),this.padOffset>Y-Z)this.process(G,0),Z=0;for(let q=Z;q<Y;q++)X[q]=0;ga(G,Y-8,BigInt(this.length*8),J),this.process(G,0);let V=WJ(W),U=this.outputLen;if(U%4)throw Error("_sha2: outputLen should be aligned to 32bit");let Q=U/4,N=this.get();if(Q>N.length)throw Error("_sha2: outputLen bigger than state");for(let q=0;q<Q;q++)V.setUint32(4*q,N[q],J)}digest(){let{buffer:W,outputLen:X}=this;this.digestInto(W);let G=W.slice(0,X);return this.destroy(),G}_cloneInto(W){W||(W=new this.constructor),W.set(...this.get());let{blockLen:X,buffer:G,length:Y,finished:J,destroyed:Z,pos:V}=this;if(W.length=Y,W.pos=V,W.finished=J,W.destroyed=Z,Y%X)W.buffer.set(G);return W}}var ua=new Uint8Array([7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8]),Hk=Uint8Array.from({length:16},(W,X)=>X),ha=Hk.map((W)=>(9*W+5)%16),MO=[Hk],PO=[ha];for(let W=0;W<4;W++)for(let X of[MO,PO])X.push(X[W].map((G)=>ua[G]));var Ak=[[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)),ba=MO.map((W,X)=>W.map((G)=>Ak[X][G])),ma=PO.map((W,X)=>W.map((G)=>Ak[X][G])),fa=new Uint32Array([0,1518500249,1859775393,2400959708,2840853838]),pa=new Uint32Array([1352829926,1548603684,1836072691,2053994217,0]),hH=(W,X)=>W<<X|W>>>32-X;function qk(W,X,G,Y){if(W===0)return X^G^Y;else if(W===1)return X&G|~X&Y;else if(W===2)return(X|~G)^Y;else if(W===3)return X&Y|G&~Y;else return X^(G|~Y)}var bH=new Uint32Array(16);class zk 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:X,h2:G,h3:Y,h4:J}=this;return[W,X,G,Y,J]}set(W,X,G,Y,J){this.h0=W|0,this.h1=X|0,this.h2=G|0,this.h3=Y|0,this.h4=J|0}process(W,X){for(let H=0;H<16;H++,X+=4)bH[H]=W.getUint32(X,!0);let G=this.h0|0,Y=G,J=this.h1|0,Z=J,V=this.h2|0,U=V,Q=this.h3|0,N=Q,q=this.h4|0,A=q;for(let H=0;H<5;H++){let I=4-H,w=fa[H],O=pa[H],T=MO[H],x=PO[H],h=ba[H],$=ma[H];for(let F=0;F<16;F++){let u=hH(G+qk(H,J,V,Q)+bH[T[F]]+w,h[F])+q|0;G=q,q=Q,Q=hH(V,10)|0,V=J,J=u}for(let F=0;F<16;F++){let u=hH(Y+qk(I,Z,U,N)+bH[x[F]]+O,$[F])+A|0;Y=A,A=N,N=hH(U,10)|0,U=Z,Z=u}}this.set(this.h1+V+N|0,this.h2+Q+A|0,this.h3+q+Y|0,this.h4+G+Z|0,this.h0+J+U|0)}roundClean(){bH.fill(0)}destroy(){this.destroyed=!0,this.buffer.fill(0),this.set(0,0,0,0,0)}}var Ik=XJ(()=>new zk);var wk=!1,jk=function(W){return Ik(W)},Kk=jk;function JW(W){let X=E0(W,"data");return M0(Kk(X))}JW._=jk;JW.lock=function(){wk=!0};JW.register=function(W){if(wk)throw TypeError("ripemd160 is locked");Kk=W};Object.freeze(JW);var Ok=!1,Dk=function(W,X,G,Y,J){return fx(W,X,G,Y,J)},Ck=Dk;function x5(W,X,G,Y,J){let Z=E0(W,"password"),V=E0(X,"salt");return M0(Ck(Z,V,G,Y,J))}x5._=Dk;x5.lock=function(){Ok=!0};x5.register=function(W){if(Ok)throw Error("pbkdf2 is locked");Ck=W};Object.freeze(x5);var Tk=!1,Mk=function(W){return new Uint8Array(px(W))},Pk=Mk;function k5(W){return Pk(W)}k5._=Mk;k5.lock=function(){Tk=!0};k5.register=function(W){if(Tk)throw Error("randomBytes is locked");Pk=W};Object.freeze(k5);var ca=(W,X,G)=>W&X^~W&G,la=(W,X,G)=>W&X^W&G^X&G,da=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]),ZW=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),VW=new Uint32Array(64);class Rk extends OU{constructor(){super(64,32,8,!1);this.A=ZW[0]|0,this.B=ZW[1]|0,this.C=ZW[2]|0,this.D=ZW[3]|0,this.E=ZW[4]|0,this.F=ZW[5]|0,this.G=ZW[6]|0,this.H=ZW[7]|0}get(){let{A:W,B:X,C:G,D:Y,E:J,F:Z,G:V,H:U}=this;return[W,X,G,Y,J,Z,V,U]}set(W,X,G,Y,J,Z,V,U){this.A=W|0,this.B=X|0,this.C=G|0,this.D=Y|0,this.E=J|0,this.F=Z|0,this.G=V|0,this.H=U|0}process(W,X){for(let q=0;q<16;q++,X+=4)VW[q]=W.getUint32(X,!1);for(let q=16;q<64;q++){let A=VW[q-15],H=VW[q-2],I=q7(A,7)^q7(A,18)^A>>>3,w=q7(H,17)^q7(H,19)^H>>>10;VW[q]=w+VW[q-7]+I+VW[q-16]|0}let{A:G,B:Y,C:J,D:Z,E:V,F:U,G:Q,H:N}=this;for(let q=0;q<64;q++){let A=q7(V,6)^q7(V,11)^q7(V,25),H=N+A+ca(V,U,Q)+da[q]+VW[q]|0,w=(q7(G,2)^q7(G,13)^q7(G,22))+la(G,Y,J)|0;N=Q,Q=U,U=V,V=Z+H|0,Z=J,J=Y,Y=G,G=H+w|0}G=G+this.A|0,Y=Y+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,N=N+this.H|0,this.set(G,Y,J,Z,V,U,Q,N)}roundClean(){VW.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}}var DU=XJ(()=>new Rk);class RO extends kX{constructor(W,X){super();this.finished=!1,this.destroyed=!1,kH(W);let G=a7(X);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 Y=this.blockLen,J=new Uint8Array(Y);J.set(G.length>Y?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 r4(this),this.iHash.update(W),this}digestInto(W){r4(this),wU(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:X,iHash:G,finished:Y,destroyed:J,blockLen:Z,outputLen:V}=this;return W=W,W.finished=Y,W.destroyed=J,W.blockLen=Z,W.outputLen=V,W.oHash=X._cloneInto(W.oHash),W.iHash=G._cloneInto(W.iHash),W}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}}var CU=(W,X,G)=>new RO(W,X).update(G).digest();CU.create=(W,X)=>new RO(W,X);function oa(W,X,G,Y){kH(W);let J=uH({dkLen:32,asyncTick:10},Y),{c:Z,dkLen:V,asyncTick:U}=J;if(B9(Z),B9(V),B9(U),Z<1)throw Error("PBKDF2: iterations (c) should be >= 1");let Q=a7(X),N=a7(G),q=new Uint8Array(V),A=CU.create(W,Q),H=A._cloneInto().update(N);return{c:Z,dkLen:V,asyncTick:U,DK:q,PRF:A,PRFSalt:H}}function na(W,X,G,Y,J){if(W.destroy(),X.destroy(),Y)Y.destroy();return J.fill(0),G}function LO(W,X,G,Y){let{c:J,dkLen:Z,DK:V,PRF:U,PRFSalt:Q}=oa(W,X,G,Y),N,q=new Uint8Array(4),A=WJ(q),H=new Uint8Array(U.outputLen);for(let I=1,w=0;w<Z;I++,w+=U.outputLen){let O=V.subarray(w,w+U.outputLen);A.setInt32(0,I,!1),(N=Q._cloneInto(N)).update(q).digestInto(H),O.set(H.subarray(0,O.length));for(let T=1;T<J;T++){U._cloneInto(N).update(H).digestInto(H);for(let x=0;x<O.length;x++)O[x]^=H[x]}}return na(U,Q,V,N,H)}var s1=(W,X)=>W<<X|W>>>32-X;function Lk(W,X,G,Y,J,Z){let V=W[X++]^G[Y++],U=W[X++]^G[Y++],Q=W[X++]^G[Y++],N=W[X++]^G[Y++],q=W[X++]^G[Y++],A=W[X++]^G[Y++],H=W[X++]^G[Y++],I=W[X++]^G[Y++],w=W[X++]^G[Y++],O=W[X++]^G[Y++],T=W[X++]^G[Y++],x=W[X++]^G[Y++],h=W[X++]^G[Y++],$=W[X++]^G[Y++],F=W[X++]^G[Y++],u=W[X++]^G[Y++],l=V,f=U,s=Q,y=N,t=q,H0=A,g=H,d=I,P=w,E=O,p=T,r=x,o=h,B=$,S=F,_=u;for(let v=0;v<8;v+=2)t^=s1(l+o|0,7),P^=s1(t+l|0,9),o^=s1(P+t|0,13),l^=s1(o+P|0,18),E^=s1(H0+f|0,7),B^=s1(E+H0|0,9),f^=s1(B+E|0,13),H0^=s1(f+B|0,18),S^=s1(p+g|0,7),s^=s1(S+p|0,9),g^=s1(s+S|0,13),p^=s1(g+s|0,18),y^=s1(_+r|0,7),d^=s1(y+_|0,9),r^=s1(d+y|0,13),_^=s1(r+d|0,18),f^=s1(l+y|0,7),s^=s1(f+l|0,9),y^=s1(s+f|0,13),l^=s1(y+s|0,18),g^=s1(H0+t|0,7),d^=s1(g+H0|0,9),t^=s1(d+g|0,13),H0^=s1(t+d|0,18),r^=s1(p+E|0,7),P^=s1(r+p|0,9),E^=s1(P+r|0,13),p^=s1(E+P|0,18),o^=s1(_+S|0,7),B^=s1(o+_|0,9),S^=s1(B+o|0,13),_^=s1(S+B|0,18);J[Z++]=V+l|0,J[Z++]=U+f|0,J[Z++]=Q+s|0,J[Z++]=N+y|0,J[Z++]=q+t|0,J[Z++]=A+H0|0,J[Z++]=H+g|0,J[Z++]=I+d|0,J[Z++]=w+P|0,J[Z++]=O+E|0,J[Z++]=T+p|0,J[Z++]=x+r|0,J[Z++]=h+o|0,J[Z++]=$+B|0,J[Z++]=F+S|0,J[Z++]=u+_|0}function GJ(W,X,G,Y,J){let Z=Y+0,V=Y+16*J;for(let U=0;U<16;U++)G[V+U]=W[X+(2*J-1)*16+U];for(let U=0;U<J;U++,Z+=16,X+=16){if(Lk(G,V,W,X,G,Z),U>0)V+=16;Lk(G,Z,W,X+=16,G,V)}}function Bk(W,X,G){let Y=uH({dkLen:32,asyncTick:10,maxmem:1073742848},G),{N:J,r:Z,p:V,dkLen:U,asyncTick:Q,maxmem:N,onProgress:q}=Y;if(B9(J),B9(Z),B9(V),B9(U),B9(Q),B9(N),q!==void 0&&typeof q!=="function")throw Error("progressCb should be function");let A=128*Z,H=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 I=A*(J+V);if(I>N)throw Error(`Scrypt: parameters too large, ${I} (128 * r * (N + p)) > ${N} (maxmem)`);let w=LO(DU,W,X,{c:1,dkLen:A*V}),O=eY(w),T=eY(new Uint8Array(A*J)),x=eY(new Uint8Array(A)),h=()=>{};if(q){let $=2*J*V,F=Math.max(Math.floor($/1e4),1),u=0;h=()=>{if(u++,q&&(!(u%F)||u===$))q(u/$)}}return{N:J,r:Z,p:V,dkLen:U,blockSize32:H,V:T,B32:O,B:w,tmp:x,blockMixCb:h,asyncTick:Q}}function Ek(W,X,G,Y,J){let Z=LO(DU,W,G,{c:1,dkLen:X});return G.fill(0),Y.fill(0),J.fill(0),Z}function $k(W,X,G){let{N:Y,r:J,p:Z,dkLen:V,blockSize32:U,V:Q,B32:N,B:q,tmp:A,blockMixCb:H}=Bk(W,X,G);for(let I=0;I<Z;I++){let w=U*I;for(let O=0;O<U;O++)Q[O]=N[w+O];for(let O=0,T=0;O<Y-1;O++)GJ(Q,T,Q,T+=U,J),H();GJ(Q,(Y-1)*U,N,w,J),H();for(let O=0;O<Y;O++){let T=N[w+U-16]%Y;for(let x=0;x<U;x++)A[x]=N[w+x]^Q[T*U+x];GJ(A,0,N,w,J),H()}}return Ek(W,V,q,Q,A)}async function Fk(W,X,G){let{N:Y,r:J,p:Z,dkLen:V,blockSize32:U,V:Q,B32:N,B:q,tmp:A,blockMixCb:H,asyncTick:I}=Bk(W,X,G);for(let w=0;w<Z;w++){let O=U*w;for(let x=0;x<U;x++)Q[x]=N[O+x];let T=0;await gH(Y-1,I,()=>{GJ(Q,T,Q,T+=U,J),H()}),GJ(Q,(Y-1)*U,N,O,J),H(),await gH(Y,I,()=>{let x=N[O+U-16]%Y;for(let h=0;h<U;h++)A[h]=N[O+h]^Q[x*U+h];GJ(A,0,N,O,J),H()})}return Ek(W,V,q,Q,A)}var Sk=!1,xk=!1,kk=async function(W,X,G,Y,J,Z,V){return await Fk(W,X,{N:G,r:Y,p:J,dkLen:Z,onProgress:V})},_k=function(W,X,G,Y,J,Z){return $k(W,X,{N:G,r:Y,p:J,dkLen:Z})},yk=kk,vk=_k;async function UW(W,X,G,Y,J,Z,V){let U=E0(W,"passwd"),Q=E0(X,"salt");return M0(await yk(U,Q,G,Y,J,Z,V))}UW._=kk;UW.lock=function(){xk=!0};UW.register=function(W){if(xk)throw Error("scrypt is locked");yk=W};Object.freeze(UW);function QW(W,X,G,Y,J,Z){let V=E0(W,"passwd"),U=E0(X,"salt");return M0(vk(V,U,G,Y,J,Z))}QW._=_k;QW.lock=function(){Sk=!0};QW.register=function(W){if(Sk)throw Error("scryptSync is locked");vk=W};Object.freeze(QW);var gk=function(W){return CO("sha256").update(W).digest()},uk=function(W){return CO("sha512").update(W).digest()},hk=gk,bk=uk,mk=!1,fk=!1;function E9(W){let X=E0(W,"data");return M0(hk(X))}E9._=gk;E9.lock=function(){mk=!0};E9.register=function(W){if(mk)throw Error("sha256 is locked");hk=W};Object.freeze(E9);function mH(W){let X=E0(W,"data");return M0(bk(X))}mH._=uk;mH.lock=function(){fk=!0};mH.register=function(W){if(fk)throw Error("sha512 is locked");bk=W};Object.freeze(E9);var FO={};zA(FO,{validateObject:()=>qW,utf8ToBytes:()=>ta,numberToVarBytesBE:()=>aa,numberToHexUnpadded:()=>lk,numberToBytesLE:()=>lH,numberToBytesBE:()=>NW,hexToNumber:()=>EO,hexToBytes:()=>yX,equalBytes:()=>sa,ensureBytes:()=>w5,createHmacDrbg:()=>$O,concatBytes:()=>YJ,bytesToNumberLE:()=>cH,bytesToNumberBE:()=>a4,bytesToHex:()=>_X,bitSet:()=>Xs,bitMask:()=>TU,bitLen:()=>ea,bitGet:()=>Ws});/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */var ck=BigInt(0),fH=BigInt(1),ia=BigInt(2),pH=(W)=>W instanceof Uint8Array,ra=Array.from({length:256},(W,X)=>X.toString(16).padStart(2,"0"));function _X(W){if(!pH(W))throw Error("Uint8Array expected");let X="";for(let G=0;G<W.length;G++)X+=ra[W[G]];return X}function lk(W){let X=W.toString(16);return X.length&1?`0${X}`:X}function EO(W){if(typeof W!=="string")throw Error("hex string expected, got "+typeof W);return BigInt(W===""?"0":`0x${W}`)}function yX(W){if(typeof W!=="string")throw Error("hex string expected, got "+typeof W);let X=W.length;if(X%2)throw Error("padded hex string expected, got unpadded hex of length "+X);let G=new Uint8Array(X/2);for(let Y=0;Y<G.length;Y++){let J=Y*2,Z=W.slice(J,J+2),V=Number.parseInt(Z,16);if(Number.isNaN(V)||V<0)throw Error("Invalid byte sequence");G[Y]=V}return G}function a4(W){return EO(_X(W))}function cH(W){if(!pH(W))throw Error("Uint8Array expected");return EO(_X(Uint8Array.from(W).reverse()))}function NW(W,X){return yX(W.toString(16).padStart(X*2,"0"))}function lH(W,X){return NW(W,X).reverse()}function aa(W){return yX(lk(W))}function w5(W,X,G){let Y;if(typeof X==="string")try{Y=yX(X)}catch(Z){throw Error(`${W} must be valid hex string, got "${X}". Cause: ${Z}`)}else if(pH(X))Y=Uint8Array.from(X);else throw Error(`${W} must be hex string or Uint8Array`);let J=Y.length;if(typeof G==="number"&&J!==G)throw Error(`${W} expected ${G} bytes, got ${J}`);return Y}function YJ(...W){let X=new Uint8Array(W.reduce((Y,J)=>Y+J.length,0)),G=0;return W.forEach((Y)=>{if(!pH(Y))throw Error("Uint8Array expected");X.set(Y,G),G+=Y.length}),X}function sa(W,X){if(W.length!==X.length)return!1;for(let G=0;G<W.length;G++)if(W[G]!==X[G])return!1;return!0}function ta(W){if(typeof W!=="string")throw Error(`utf8ToBytes expected string, got ${typeof W}`);return new Uint8Array(new TextEncoder().encode(W))}function ea(W){let X;for(X=0;W>ck;W>>=fH,X+=1);return X}function Ws(W,X){return W>>BigInt(X)&fH}var Xs=(W,X,G)=>{return W|(G?fH:ck)<<BigInt(X)},TU=(W)=>(ia<<BigInt(W-1))-fH,BO=(W)=>new Uint8Array(W),pk=(W)=>Uint8Array.from(W);function $O(W,X,G){if(typeof W!=="number"||W<2)throw Error("hashLen must be a number");if(typeof X!=="number"||X<2)throw Error("qByteLen must be a number");if(typeof G!=="function")throw Error("hmacFn must be a function");let Y=BO(W),J=BO(W),Z=0,V=()=>{Y.fill(1),J.fill(0),Z=0},U=(...A)=>G(J,Y,...A),Q=(A=BO())=>{if(J=U(pk([0]),A),Y=U(),A.length===0)return;J=U(pk([1]),A),Y=U()},N=()=>{if(Z++>=1000)throw Error("drbg: tried 1000 values");let A=0,H=[];while(A<X){Y=U();let I=Y.slice();H.push(I),A+=Y.length}return YJ(...H)};return(A,H)=>{V(),Q(A);let I=void 0;while(!(I=H(N())))Q();return V(),I}}var Gs={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,X)=>X.Fp.isValid(W),hash:(W)=>typeof W==="function"&&Number.isSafeInteger(W.outputLen)};function qW(W,X,G={}){let Y=(J,Z,V)=>{let U=Gs[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(X))Y(J,Z,!1);for(let[J,Z]of Object.entries(G))Y(J,Z,!0);return W}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */var n8=BigInt(0),x8=BigInt(1),vX=BigInt(2),Ys=BigInt(3),SO=BigInt(4),dk=BigInt(5),ok=BigInt(8),Js=BigInt(9),Zs=BigInt(16);function $9(W,X){let G=W%X;return G>=n8?G:X+G}function Vs(W,X,G){if(G<=n8||X<n8)throw Error("Expected power/modulo > 0");if(G===x8)return n8;let Y=x8;while(X>n8){if(X&x8)Y=Y*W%G;W=W*W%G,X>>=x8}return Y}function j5(W,X,G){let Y=W;while(X-- >n8)Y*=Y,Y%=G;return Y}function dH(W,X){if(W===n8||X<=n8)throw Error(`invert: expected positive integers, got n=${W} mod=${X}`);let G=$9(W,X),Y=X,J=n8,Z=x8,V=x8,U=n8;while(G!==n8){let N=Y/G,q=Y%G,A=J-V*N,H=Z-U*N;Y=G,G=q,J=V,Z=U,V=A,U=H}if(Y!==x8)throw Error("invert: does not exist");return $9(J,X)}function Us(W){let X=(W-x8)/vX,G,Y,J;for(G=W-x8,Y=0;G%vX===n8;G/=vX,Y++);for(J=vX;J<W&&Vs(J,X,W)!==W-x8;J++);if(Y===1){let V=(W+x8)/SO;return function(Q,N){let q=Q.pow(N,V);if(!Q.eql(Q.sqr(q),N))throw Error("Cannot find square root");return q}}let Z=(G+x8)/vX;return function(U,Q){if(U.pow(Q,X)===U.neg(U.ONE))throw Error("Cannot find square root");let N=Y,q=U.pow(U.mul(U.ONE,J),G),A=U.pow(Q,Z),H=U.pow(Q,G);while(!U.eql(H,U.ONE)){if(U.eql(H,U.ZERO))return U.ZERO;let I=1;for(let O=U.sqr(H);I<N;I++){if(U.eql(O,U.ONE))break;O=U.sqr(O)}let w=U.pow(q,x8<<BigInt(N-I-1));q=U.sqr(w),A=U.mul(A,w),H=U.mul(H,q),N=I}return A}}function Qs(W){if(W%SO===Ys){let X=(W+x8)/SO;return function(Y,J){let Z=Y.pow(J,X);if(!Y.eql(Y.sqr(Z),J))throw Error("Cannot find square root");return Z}}if(W%ok===dk){let X=(W-dk)/ok;return function(Y,J){let Z=Y.mul(J,vX),V=Y.pow(Z,X),U=Y.mul(J,V),Q=Y.mul(Y.mul(U,vX),V),N=Y.mul(U,Y.sub(Q,Y.ONE));if(!Y.eql(Y.sqr(N),J))throw Error("Cannot find square root");return N}}if(W%Zs===Js);return Us(W)}var Ns=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function xO(W){let X={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},G=Ns.reduce((Y,J)=>{return Y[J]="function",Y},X);return qW(W,G)}function qs(W,X,G){if(G<n8)throw Error("Expected power > 0");if(G===n8)return W.ONE;if(G===x8)return X;let Y=W.ONE,J=X;while(G>n8){if(G&x8)Y=W.mul(Y,J);J=W.sqr(J),G>>=x8}return Y}function Hs(W,X){let G=Array(X.length),Y=X.reduce((Z,V,U)=>{if(W.is0(V))return Z;return G[U]=Z,W.mul(Z,V)},W.ONE),J=W.inv(Y);return X.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 kO(W,X){let G=X!==void 0?X:W.toString(2).length,Y=Math.ceil(G/8);return{nBitLength:G,nByteLength:Y}}function nk(W,X,G=!1,Y={}){if(W<=n8)throw Error(`Expected Field ORDER > 0, got ${W}`);let{nBitLength:J,nByteLength:Z}=kO(W,X);if(Z>2048)throw Error("Field lengths over 2048 bytes are not supported");let V=Qs(W),U=Object.freeze({ORDER:W,BITS:J,BYTES:Z,MASK:TU(J),ZERO:n8,ONE:x8,create:(Q)=>$9(Q,W),isValid:(Q)=>{if(typeof Q!=="bigint")throw Error(`Invalid field element: expected bigint, got ${typeof Q}`);return n8<=Q&&Q<W},is0:(Q)=>Q===n8,isOdd:(Q)=>(Q&x8)===x8,neg:(Q)=>$9(-Q,W),eql:(Q,N)=>Q===N,sqr:(Q)=>$9(Q*Q,W),add:(Q,N)=>$9(Q+N,W),sub:(Q,N)=>$9(Q-N,W),mul:(Q,N)=>$9(Q*N,W),pow:(Q,N)=>qs(U,Q,N),div:(Q,N)=>$9(Q*dH(N,W),W),sqrN:(Q)=>Q*Q,addN:(Q,N)=>Q+N,subN:(Q,N)=>Q-N,mulN:(Q,N)=>Q*N,inv:(Q)=>dH(Q,W),sqrt:Y.sqrt||((Q)=>V(U,Q)),invertBatch:(Q)=>Hs(U,Q),cmov:(Q,N,q)=>q?N:Q,toBytes:(Q)=>G?lH(Q,Z):NW(Q,Z),fromBytes:(Q)=>{if(Q.length!==Z)throw Error(`Fp.fromBytes: expected ${Z}, got ${Q.length}`);return G?cH(Q):a4(Q)}});return Object.freeze(U)}function ik(W){if(typeof W!=="bigint")throw Error("field order must be bigint");let X=W.toString(2).length;return Math.ceil(X/8)}function _O(W){let X=ik(W);return X+Math.ceil(X/2)}function rk(W,X,G=!1){let Y=W.length,J=ik(X),Z=_O(X);if(Y<16||Y<Z||Y>1024)throw Error(`expected ${Z}-1024 bytes of input, got ${Y}`);let V=G?a4(W):cH(W),U=$9(V,X-x8)+x8;return G?lH(U,J):NW(U,J)}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */var zs=BigInt(0),yO=BigInt(1);function ak(W,X){let G=(J,Z)=>{let V=Z.negate();return J?V:Z},Y=(J)=>{let Z=Math.ceil(X/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>zs){if(Z&yO)V=V.add(U);U=U.double(),Z>>=yO}return V},precomputeWindow(J,Z){let{windows:V,windowSize:U}=Y(Z),Q=[],N=J,q=N;for(let A=0;A<V;A++){q=N,Q.push(q);for(let H=1;H<U;H++)q=q.add(N),Q.push(q);N=q.double()}return Q},wNAF(J,Z,V){let{windows:U,windowSize:Q}=Y(J),N=W.ZERO,q=W.BASE,A=BigInt(2**J-1),H=2**J,I=BigInt(J);for(let w=0;w<U;w++){let O=w*Q,T=Number(V&A);if(V>>=I,T>Q)T-=H,V+=yO;let x=O,h=O+Math.abs(T)-1,$=w%2!==0,F=T<0;if(T===0)q=q.add(G($,Z[x]));else N=N.add(G(F,Z[h]))}return{p:N,f:q}},wNAFCached(J,Z,V,U){let Q=J._WINDOW_SIZE||1,N=Z.get(J);if(!N){if(N=this.precomputeWindow(J,Q),Q!==1)Z.set(J,U(N))}return this.wNAF(Q,N,V)}}}function vO(W){return xO(W.Fp),qW(W,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...kO(W.n,W.nBitLength),...W,...{p:W.Fp.ORDER}})}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */function Is(W){let X=vO(W);qW(X,{a:"field",b:"field"},{allowedPrivateKeyLengths:"array",wrapPrivateKey:"boolean",isTorsionFree:"function",clearCofactor:"function",allowInfinityPoint:"boolean",fromBytes:"function",toBytes:"function"});let{endo:G,Fp:Y,a:J}=X;if(G){if(!Y.eql(J,Y.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({...X})}var{bytesToNumberBE:ws,hexToBytes:js}=FO,gX={Err:class extends Error{constructor(X=""){super(X)}},_parseInt(W){let{Err:X}=gX;if(W.length<2||W[0]!==2)throw new X("Invalid signature integer tag");let G=W[1],Y=W.subarray(2,G+2);if(!G||Y.length!==G)throw new X("Invalid signature integer: wrong length");if(Y[0]&128)throw new X("Invalid signature integer: negative");if(Y[0]===0&&!(Y[1]&128))throw new X("Invalid signature integer: unnecessary leading zero");return{d:ws(Y),l:W.subarray(G+2)}},toSig(W){let{Err:X}=gX,G=typeof W==="string"?js(W):W;if(!(G instanceof Uint8Array))throw Error("ui8a expected");let Y=G.length;if(Y<2||G[0]!=48)throw new X("Invalid signature tag");if(G[1]!==Y-2)throw new X("Invalid signature: incorrect length");let{d:J,l:Z}=gX._parseInt(G.subarray(2)),{d:V,l:U}=gX._parseInt(Z);if(U.length)throw new X("Invalid signature: left bytes after parsing");return{r:J,s:V}},hexFromSig(W){let X=(N)=>Number.parseInt(N[0],16)&8?"00"+N:N,G=(N)=>{let q=N.toString(16);return q.length&1?`0${q}`:q},Y=X(G(W.s)),J=X(G(W.r)),Z=Y.length/2,V=J.length/2,U=G(Z),Q=G(V);return`30${G(V+Z+4)}02${Q}${J}02${U}${Y}`}},s4=BigInt(0),_5=BigInt(1),Mj0=BigInt(2),sk=BigInt(3),Pj0=BigInt(4);function Ks(W){let X=Is(W),{Fp:G}=X,Y=X.toBytes||((w,O,T)=>{let x=O.toAffine();return YJ(Uint8Array.from([4]),G.toBytes(x.x),G.toBytes(x.y))}),J=X.fromBytes||((w)=>{let O=w.subarray(1),T=G.fromBytes(O.subarray(0,G.BYTES)),x=G.fromBytes(O.subarray(G.BYTES,2*G.BYTES));return{x:T,y:x}});function Z(w){let{a:O,b:T}=X,x=G.sqr(w),h=G.mul(x,w);return G.add(G.add(h,G.mul(w,O)),T)}if(!G.eql(G.sqr(X.Gy),Z(X.Gx)))throw Error("bad generator point: equation left != right");function V(w){return typeof w==="bigint"&&s4<w&&w<X.n}function U(w){if(!V(w))throw Error("Expected valid bigint: 0 < bigint < curve.n")}function Q(w){let{allowedPrivateKeyLengths:O,nByteLength:T,wrapPrivateKey:x,n:h}=X;if(O&&typeof w!=="bigint"){if(w instanceof Uint8Array)w=_X(w);if(typeof w!=="string"||!O.includes(w.length))throw Error("Invalid key");w=w.padStart(T*2,"0")}let $;try{$=typeof w==="bigint"?w:a4(w5("private key",w,T))}catch(F){throw Error(`private key must be ${T} bytes, hex or bigint, not ${typeof w}`)}if(x)$=$9($,h);return U($),$}let N=new Map;function q(w){if(!(w instanceof A))throw Error("ProjectivePoint expected")}class A{constructor(w,O,T){if(this.px=w,this.py=O,this.pz=T,w==null||!G.isValid(w))throw Error("x required");if(O==null||!G.isValid(O))throw Error("y required");if(T==null||!G.isValid(T))throw Error("z required")}static fromAffine(w){let{x:O,y:T}=w||{};if(!w||!G.isValid(O)||!G.isValid(T))throw Error("invalid affine point");if(w instanceof A)throw Error("projective point not allowed");let x=(h)=>G.eql(h,G.ZERO);if(x(O)&&x(T))return A.ZERO;return new A(O,T,G.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(w){let O=G.invertBatch(w.map((T)=>T.pz));return w.map((T,x)=>T.toAffine(O[x])).map(A.fromAffine)}static fromHex(w){let O=A.fromAffine(J(w5("pointHex",w)));return O.assertValidity(),O}static fromPrivateKey(w){return A.BASE.multiply(Q(w))}_setWindowSize(w){this._WINDOW_SIZE=w,N.delete(this)}assertValidity(){if(this.is0()){if(X.allowInfinityPoint&&!G.is0(this.py))return;throw Error("bad point: ZERO")}let{x:w,y:O}=this.toAffine();if(!G.isValid(w)||!G.isValid(O))throw Error("bad point: x or y not FE");let T=G.sqr(O),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){q(w);let{px:O,py:T,pz:x}=this,{px:h,py:$,pz:F}=w,u=G.eql(G.mul(O,F),G.mul(h,x)),l=G.eql(G.mul(T,F),G.mul($,x));return u&&l}negate(){return new A(this.px,G.neg(this.py),this.pz)}double(){let{a:w,b:O}=X,T=G.mul(O,sk),{px:x,py:h,pz:$}=this,F=G.ZERO,u=G.ZERO,l=G.ZERO,f=G.mul(x,x),s=G.mul(h,h),y=G.mul($,$),t=G.mul(x,h);return t=G.add(t,t),l=G.mul(x,$),l=G.add(l,l),F=G.mul(w,l),u=G.mul(T,y),u=G.add(F,u),F=G.sub(s,u),u=G.add(s,u),u=G.mul(F,u),F=G.mul(t,F),l=G.mul(T,l),y=G.mul(w,y),t=G.sub(f,y),t=G.mul(w,t),t=G.add(t,l),l=G.add(f,f),f=G.add(l,f),f=G.add(f,y),f=G.mul(f,t),u=G.add(u,f),y=G.mul(h,$),y=G.add(y,y),f=G.mul(y,t),F=G.sub(F,f),l=G.mul(y,s),l=G.add(l,l),l=G.add(l,l),new A(F,u,l)}add(w){q(w);let{px:O,py:T,pz:x}=this,{px:h,py:$,pz:F}=w,u=G.ZERO,l=G.ZERO,f=G.ZERO,s=X.a,y=G.mul(X.b,sk),t=G.mul(O,h),H0=G.mul(T,$),g=G.mul(x,F),d=G.add(O,T),P=G.add(h,$);d=G.mul(d,P),P=G.add(t,H0),d=G.sub(d,P),P=G.add(O,x);let E=G.add(h,F);return P=G.mul(P,E),E=G.add(t,g),P=G.sub(P,E),E=G.add(T,x),u=G.add($,F),E=G.mul(E,u),u=G.add(H0,g),E=G.sub(E,u),f=G.mul(s,P),u=G.mul(y,g),f=G.add(u,f),u=G.sub(H0,f),f=G.add(H0,f),l=G.mul(u,f),H0=G.add(t,t),H0=G.add(H0,t),g=G.mul(s,g),P=G.mul(y,P),H0=G.add(H0,g),g=G.sub(t,g),g=G.mul(s,g),P=G.add(P,g),t=G.mul(H0,P),l=G.add(l,t),t=G.mul(E,P),u=G.mul(d,u),u=G.sub(u,t),t=G.mul(d,H0),f=G.mul(E,f),f=G.add(f,t),new A(u,l,f)}subtract(w){return this.add(w.negate())}is0(){return this.equals(A.ZERO)}wNAF(w){return I.wNAFCached(this,N,w,(O)=>{let T=G.invertBatch(O.map((x)=>x.pz));return O.map((x,h)=>x.toAffine(T[h])).map(A.fromAffine)})}multiplyUnsafe(w){let O=A.ZERO;if(w===s4)return O;if(U(w),w===_5)return this;let{endo:T}=X;if(!T)return I.unsafeLadder(this,w);let{k1neg:x,k1:h,k2neg:$,k2:F}=T.splitScalar(w),u=O,l=O,f=this;while(h>s4||F>s4){if(h&_5)u=u.add(f);if(F&_5)l=l.add(f);f=f.double(),h>>=_5,F>>=_5}if(x)u=u.negate();if($)l=l.negate();return l=new A(G.mul(l.px,T.beta),l.py,l.pz),u.add(l)}multiply(w){U(w);let O=w,T,x,{endo:h}=X;if(h){let{k1neg:$,k1:F,k2neg:u,k2:l}=h.splitScalar(O),{p:f,f:s}=this.wNAF(F),{p:y,f:t}=this.wNAF(l);f=I.constTimeNegate($,f),y=I.constTimeNegate(u,y),y=new A(G.mul(y.px,h.beta),y.py,y.pz),T=f.add(y),x=s.add(t)}else{let{p:$,f:F}=this.wNAF(O);T=$,x=F}return A.normalizeZ([T,x])[0]}multiplyAndAddUnsafe(w,O,T){let x=A.BASE,h=(F,u)=>u===s4||u===_5||!F.equals(x)?F.multiplyUnsafe(u):F.multiply(u),$=h(this,O).add(h(w,T));return $.is0()?void 0:$}toAffine(w){let{px:O,py:T,pz:x}=this,h=this.is0();if(w==null)w=h?G.ONE:G.inv(x);let $=G.mul(O,w),F=G.mul(T,w),u=G.mul(x,w);if(h)return{x:G.ZERO,y:G.ZERO};if(!G.eql(u,G.ONE))throw Error("invZ was invalid");return{x:$,y:F}}isTorsionFree(){let{h:w,isTorsionFree:O}=X;if(w===_5)return!0;if(O)return O(A,this);throw Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){let{h:w,clearCofactor:O}=X;if(w===_5)return this;if(O)return O(A,this);return this.multiplyUnsafe(X.h)}toRawBytes(w=!0){return this.assertValidity(),Y(A,this,w)}toHex(w=!0){return _X(this.toRawBytes(w))}}A.BASE=new A(X.Gx,X.Gy,G.ONE),A.ZERO=new A(G.ZERO,G.ONE,G.ZERO);let H=X.nBitLength,I=ak(A,X.endo?Math.ceil(H/2):H);return{CURVE:X,ProjectivePoint:A,normPrivateKeyToScalar:Q,weierstrassEquation:Z,isWithinCurveOrder:V}}function Os(W){let X=vO(W);return qW(X,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...X})}function tk(W){let X=Os(W),{Fp:G,n:Y}=X,J=G.BYTES+1,Z=2*G.BYTES+1;function V(E){return s4<E&&E<G.ORDER}function U(E){return $9(E,Y)}function Q(E){return dH(E,Y)}let{ProjectivePoint:N,normPrivateKeyToScalar:q,weierstrassEquation:A,isWithinCurveOrder:H}=Ks({...X,toBytes(E,p,r){let o=p.toAffine(),B=G.toBytes(o.x),S=YJ;if(r)return S(Uint8Array.from([p.hasEvenY()?2:3]),B);else return S(Uint8Array.from([4]),B,G.toBytes(o.y))},fromBytes(E){let p=E.length,r=E[0],o=E.subarray(1);if(p===J&&(r===2||r===3)){let B=a4(o);if(!V(B))throw Error("Point is not on curve");let S=A(B),_=G.sqrt(S),v=(_&_5)===_5;if((r&1)===1!==v)_=G.neg(_);return{x:B,y:_}}else if(p===Z&&r===4){let B=G.fromBytes(o.subarray(0,G.BYTES)),S=G.fromBytes(o.subarray(G.BYTES,2*G.BYTES));return{x:B,y:S}}else throw Error(`Point of length ${p} was invalid. Expected ${J} compressed bytes or ${Z} uncompressed bytes`)}}),I=(E)=>_X(NW(E,X.nByteLength));function w(E){let p=Y>>_5;return E>p}function O(E){return w(E)?U(-E):E}let T=(E,p,r)=>a4(E.slice(p,r));class x{constructor(E,p,r){this.r=E,this.s=p,this.recovery=r,this.assertValidity()}static fromCompact(E){let p=X.nByteLength;return E=w5("compactSignature",E,p*2),new x(T(E,0,p),T(E,p,2*p))}static fromDER(E){let{r:p,s:r}=gX.toSig(w5("DER",E));return new x(p,r)}assertValidity(){if(!H(this.r))throw Error("r must be 0 < r < CURVE.n");if(!H(this.s))throw Error("s must be 0 < s < CURVE.n")}addRecoveryBit(E){return new x(this.r,this.s,E)}recoverPublicKey(E){let{r:p,s:r,recovery:o}=this,B=f(w5("msgHash",E));if(o==null||![0,1,2,3].includes(o))throw Error("recovery id invalid");let S=o===2||o===3?p+X.n:p;if(S>=G.ORDER)throw Error("recovery id 2 or 3 invalid");let _=(o&1)===0?"02":"03",v=N.fromHex(_+I(S)),R=Q(S),m=U(-B*R),J0=U(r*R),U0=N.BASE.multiplyAndAddUnsafe(v,m,J0);if(!U0)throw Error("point at infinify");return U0.assertValidity(),U0}hasHighS(){return w(this.s)}normalizeS(){return this.hasHighS()?new x(this.r,U(-this.s),this.recovery):this}toDERRawBytes(){return yX(this.toDERHex())}toDERHex(){return gX.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return yX(this.toCompactHex())}toCompactHex(){return I(this.r)+I(this.s)}}let h={isValidPrivateKey(E){try{return q(E),!0}catch(p){return!1}},normPrivateKeyToScalar:q,randomPrivateKey:()=>{let E=_O(X.n);return rk(X.randomBytes(E),X.n)},precompute(E=8,p=N.BASE){return p._setWindowSize(E),p.multiply(BigInt(3)),p}};function $(E,p=!0){return N.fromPrivateKey(E).toRawBytes(p)}function F(E){let p=E instanceof Uint8Array,r=typeof E==="string",o=(p||r)&&E.length;if(p)return o===J||o===Z;if(r)return o===2*J||o===2*Z;if(E instanceof N)return!0;return!1}function u(E,p,r=!0){if(F(E))throw Error("first arg must be private key");if(!F(p))throw Error("second arg must be public key");return N.fromHex(p).multiply(q(E)).toRawBytes(r)}let l=X.bits2int||function(E){let p=a4(E),r=E.length*8-X.nBitLength;return r>0?p>>BigInt(r):p},f=X.bits2int_modN||function(E){return U(l(E))},s=TU(X.nBitLength);function y(E){if(typeof E!=="bigint")throw Error("bigint expected");if(!(s4<=E&&E<s))throw Error(`bigint expected < 2^${X.nBitLength}`);return NW(E,X.nByteLength)}function t(E,p,r=H0){if(["recovered","canonical"].some((u0)=>(u0 in r)))throw Error("sign() legacy options not supported");let{hash:o,randomBytes:B}=X,{lowS:S,prehash:_,extraEntropy:v}=r;if(S==null)S=!0;if(E=w5("msgHash",E),_)E=w5("prehashed msgHash",o(E));let R=f(E),m=q(p),J0=[y(m),y(R)];if(v!=null){let u0=v===!0?B(G.BYTES):v;J0.push(w5("extraEntropy",u0))}let U0=YJ(...J0),q0=R;function $0(u0){let H1=l(u0);if(!H(H1))return;let v1=Q(H1),h0=N.BASE.multiply(H1).toAffine(),F1=U(h0.x);if(F1===s4)return;let S1=U(v1*U(q0+F1*m));if(S1===s4)return;let N0=(h0.x===F1?0:2)|Number(h0.y&_5),F0=S1;if(S&&w(S1))F0=O(S1),N0^=1;return new x(F1,F0,N0)}return{seed:U0,k2sig:$0}}let H0={lowS:X.lowS,prehash:!1},g={lowS:X.lowS,prehash:!1};function d(E,p,r=H0){let{seed:o,k2sig:B}=t(E,p,r),S=X;return $O(S.hash.outputLen,S.nByteLength,S.hmac)(o,B)}N.BASE._setWindowSize(8);function P(E,p,r,o=g){let B=E;if(p=w5("msgHash",p),r=w5("publicKey",r),"strict"in o)throw Error("options.strict was renamed to lowS");let{lowS:S,prehash:_}=o,v=void 0,R;try{if(typeof B==="string"||B instanceof Uint8Array)try{v=x.fromDER(B)}catch(h0){if(!(h0 instanceof gX.Err))throw h0;v=x.fromCompact(B)}else if(typeof B==="object"&&typeof B.r==="bigint"&&typeof B.s==="bigint"){let{r:h0,s:F1}=B;v=new x(h0,F1)}else throw Error("PARSE");R=N.fromHex(r)}catch(h0){if(h0.message==="PARSE")throw Error("signature must be Signature instance, Uint8Array or hex string");return!1}if(S&&v.hasHighS())return!1;if(_)p=X.hash(p);let{r:m,s:J0}=v,U0=f(p),q0=Q(J0),$0=U(U0*q0),u0=U(m*q0),H1=N.BASE.multiplyAndAddUnsafe(R,$0,u0)?.toAffine();if(!H1)return!1;return U(H1.x)===m}return{CURVE:X,getPublicKey:$,getSharedSecret:u,sign:d,verify:P,ProjectivePoint:N,Signature:x,utils:h}}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */function Ds(W){return{hash:W,hmac:(X,...G)=>CU(W,X,ex(...G)),randomBytes:Wk}}function ek(W,X){let G=(Y)=>tk({...W,...Ds(Y)});return Object.freeze({...G(X),create:G})}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */var G_=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),W_=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),Cs=BigInt(1),gO=BigInt(2),X_=(W,X)=>(W+X/gO)/X;function Ts(W){let X=G_,G=BigInt(3),Y=BigInt(6),J=BigInt(11),Z=BigInt(22),V=BigInt(23),U=BigInt(44),Q=BigInt(88),N=W*W*W%X,q=N*N*W%X,A=j5(q,G,X)*q%X,H=j5(A,G,X)*q%X,I=j5(H,gO,X)*N%X,w=j5(I,J,X)*I%X,O=j5(w,Z,X)*w%X,T=j5(O,U,X)*O%X,x=j5(T,Q,X)*T%X,h=j5(x,U,X)*O%X,$=j5(h,G,X)*q%X,F=j5($,V,X)*w%X,u=j5(F,Y,X)*N%X,l=j5(u,gO,X);if(!uO.eql(uO.sqr(l),W))throw Error("Cannot find square root");return l}var uO=nk(G_,void 0,void 0,{sqrt:Ts}),t4=ek({a:BigInt(0),b:BigInt(7),Fp:uO,n:W_,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:(W)=>{let X=W_,G=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),Y=-Cs*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),J=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),Z=G,V=BigInt("0x100000000000000000000000000000000"),U=X_(Z*W,X),Q=X_(-Y*W,X),N=$9(W-U*G-Q*J,X),q=$9(-U*Y-Q*Z,X),A=N>V,H=q>V;if(A)N=X-N;if(H)q=X-q;if(N>V||q>V)throw Error("splitScalar: Endomorphism failed, k="+W);return{k1neg:A,k1:N,k2neg:H,k2:q}}}},DU),kj0=BigInt(0);var _j0=t4.ProjectivePoint;var hO="0x0000000000000000000000000000000000000000";var oH="0x0000000000000000000000000000000000000000000000000000000000000000";var bO=`\x19Ethereum Signed Message:
249
249
  `;var Y_=BigInt(0),J_=BigInt(1),Z_=BigInt(2),V_=BigInt(27),U_=BigInt(28),nH=BigInt(35),JJ={};function Q_(W){return I5(z8(W),32)}class T8{#W;#X;#G;#Y;get r(){return this.#W}set r(W){a(i4(W)===32,"invalid r","value",W),this.#W=M0(W)}get s(){return a(parseInt(this.#X.substring(0,3))<8,"non-canonical s; use ._s","s",this.#X),this.#X}set s(W){a(i4(W)===32,"invalid s","value",W),this.#X=M0(W)}get _s(){return this.#X}isValid(){return parseInt(this.#X.substring(0,3))<8}get v(){return this.#G}set v(W){let X=s8(W,"value");a(X===27||X===28,"invalid v","v",W),this.#G=X}get networkV(){return this.#Y}get legacyChainId(){let W=this.networkV;if(W==null)return null;return T8.getChainId(W)}get yParity(){return this.v===27?0:1}get yParityAndS(){let W=E0(this.s);if(this.yParity)W[0]|=128;return M0(W)}get compactSerialized(){return G8([this.r,this.yParityAndS])}get serialized(){return G8([this.r,this.s,this.yParity?"0x1c":"0x1b"])}constructor(W,X,G,Y){n4(W,JJ,"Signature"),this.#W=X,this.#X=G,this.#G=Y,this.#Y=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 T8(JJ,this.r,this._s,this.v);if(this.networkV)W.#Y=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 X=f1(W,"v");if(X==V_||X==U_)return Y_;return a(X>=nH,"invalid EIP-155 v","v",W),(X-nH)/Z_}static getChainIdV(W,X){return f1(W)*Z_+BigInt(35+X-27)}static getNormalizedV(W){let X=f1(W);if(X===Y_||X===V_)return 27;if(X===J_||X===U_)return 28;return a(X>=nH,"invalid v","v",W),X&J_?27:28}static from(W){function X(Q,N){a(Q,N,"signature",W)}if(W==null)return new T8(JJ,oH,oH,27);if(typeof W==="string"){let Q=E0(W,"signature");if(Q.length===64){let N=M0(Q.slice(0,32)),q=Q.slice(32,64),A=q[0]&128?28:27;return q[0]&=127,new T8(JJ,N,M0(q),A)}if(Q.length===65){let N=M0(Q.slice(0,32)),q=M0(Q.slice(32,64)),A=T8.getNormalizedV(Q[64]);return new T8(JJ,N,q,A)}X(!1,"invalid raw signature length")}if(W instanceof T8)return W.clone();let G=W.r;X(G!=null,"missing r");let Y=Q_(G),J=function(Q,N){if(Q!=null)return Q_(Q);if(N!=null){X(L9(N,32),"invalid yParityAndS");let q=E0(N);return q[0]&=127,M0(q)}X(!1,"missing s")}(W.s,W.yParityAndS),{networkV:Z,v:V}=function(Q,N,q){if(Q!=null){let A=f1(Q);return{networkV:A>=nH?A:void 0,v:T8.getNormalizedV(A)}}if(N!=null)return X(L9(N,32),"invalid yParityAndS"),{v:E0(N)[0]&128?28:27};if(q!=null){switch(s8(q,"sig.yParity")){case 0:return{v:27};case 1:return{v:28}}X(!1,"invalid yParity")}X(!1,"missing v")}(W.v,W.yParityAndS,W.yParity),U=new T8(JJ,Y,J,V);if(Z)U.#Y=Z;return X(W.yParity==null||s8(W.yParity,"sig.yParity")===U.yParity,"yParity mismatch"),X(W.yParityAndS==null||W.yParityAndS===U.yParityAndS,"yParityAndS mismatch"),U}}class i8{#W;constructor(W){a(i4(W)===32,"invalid private key","privateKey","[REDACTED]"),this.#W=M0(W)}get privateKey(){return this.#W}get publicKey(){return i8.computePublicKey(this.#W)}get compressedPublicKey(){return i8.computePublicKey(this.#W,!0)}sign(W){a(i4(W)===32,"invalid digest length","digest",W);let X=t4.sign(Q7(W),Q7(this.#W),{lowS:!0});return T8.from({r:N7(X.r,32),s:N7(X.s,32),v:X.recovery?28:27})}computeSharedSecret(W){let X=i8.computePublicKey(W);return M0(t4.getSharedSecret(Q7(this.#W),E0(X),!1))}static computePublicKey(W,X){let G=E0(W,"key");if(G.length===32){let J=t4.getPublicKey(G,!!X);return M0(J)}if(G.length===64){let J=new Uint8Array(65);J[0]=4,J.set(G,1),G=J}let Y=t4.ProjectivePoint.fromHex(G);return M0(Y.toRawBytes(X))}static recoverPublicKey(W,X){a(i4(W)===32,"invalid digest length","digest",W);let G=T8.from(X),Y=t4.Signature.fromCompact(Q7(G8([G.r,G.s])));Y=Y.addRecoveryBit(G.yParity);let J=Y.recoverPublicKey(Q7(W));return a(J!=null,"invalid signature for digest","signature",X),"0x"+J.toHex(!1)}static addPoints(W,X,G){let Y=t4.ProjectivePoint.fromHex(i8.computePublicKey(W).substring(2)),J=t4.ProjectivePoint.fromHex(i8.computePublicKey(X).substring(2));return"0x"+Y.add(J).toHex(!!G)}}var Ms=BigInt(0),Ps=BigInt(36);function N_(W){W=W.toLowerCase();let X=W.substring(2).split(""),G=new Uint8Array(40);for(let J=0;J<40;J++)G[J]=X[J].charCodeAt(0);let Y=E0(U8(G));for(let J=0;J<40;J+=2){if(Y[J>>1]>>4>=8)X[J]=X[J].toUpperCase();if((Y[J>>1]&15)>=8)X[J+1]=X[J+1].toUpperCase()}return"0x"+X.join("")}var mO={};for(let W=0;W<10;W++)mO[String(W)]=String(W);for(let W=0;W<26;W++)mO[String.fromCharCode(65+W)]=String(10+W);var q_=15;function Rs(W){W=W.toUpperCase(),W=W.substring(4)+W.substring(0,2)+"00";let X=W.split("").map((Y)=>{return mO[Y]}).join("");while(X.length>=q_){let Y=X.substring(0,q_);X=parseInt(Y,10)%97+X.substring(Y.length)}let G=String(98-parseInt(X,10)%97);while(G.length<2)G="0"+G;return G}var Ls=function(){let W={};for(let X=0;X<36;X++){let G="0123456789abcdefghijklmnopqrstuvwxyz"[X];W[G]=BigInt(X)}return W}();function Bs(W){W=W.toLowerCase();let X=Ms;for(let G=0;G<W.length;G++)X=X*Ps+Ls[W[G]];return X}function h1(W){if(a(typeof W==="string","invalid address","address",W),W.match(/^(0x)?[0-9a-fA-F]{40}$/)){if(!W.startsWith("0x"))W="0x"+W;let X=N_(W);return a(!W.match(/([A-F].*[a-f])|([a-f].*[A-F])/)||X===W,"bad address checksum","address",W),X}if(W.match(/^XE[0-9]{2}[0-9A-Za-z]{30,31}$/)){a(W.substring(2,4)===Rs(W),"bad icap checksum","address",W);let X=Bs(W.substring(4)).toString(16);while(X.length<40)X="0"+X;return N_("0x"+X)}a(!1,"invalid address","address",W)}function pO(W){return W&&typeof W.getAddress==="function"}async function fO(W,X){let G=await X;if(G==null||G==="0x0000000000000000000000000000000000000000")Y1(typeof W!=="string","unconfigured name","UNCONFIGURED_NAME",{value:W}),a(!1,"invalid AddressLike value; did not resolve to a value address","target",W);return h1(G)}function e4(W,X){if(typeof W==="string"){if(W.match(/^0x[0-9a-f]{40}$/i))return h1(W);return Y1(X!=null,"ENS resolution requires a provider","UNSUPPORTED_OPERATION",{operation:"resolveName"}),fO(W,X.resolveName(W))}else if(pO(W))return fO(W,W.getAddress());else if(W&&typeof W.then==="function")return fO(W,W);a(!1,"unsupported addressable value","target",W)}function cO(W,X){return{address:h1(W),storageKeys:X.map((G,Y)=>{return a(L9(G,32),"invalid slot",`storageKeys[${Y}]`,G),G.toLowerCase()})}}function uX(W){if(Array.isArray(W))return W.map((G,Y)=>{if(Array.isArray(G))return a(G.length===2,"invalid slot set",`value[${Y}]`,G),cO(G[0],G[1]);return a(G!=null&&typeof G==="object","invalid address-slot set","value",W),cO(G.address,G.storageKeys)});a(W!=null&&typeof W==="object","invalid access list","value",W);let X=Object.keys(W).map((G)=>{let Y=W[G].reduce((J,Z)=>{return J[Z]=!0,J},{});return cO(G,Object.keys(Y).sort())});return X.sort((G,Y)=>G.address.localeCompare(Y.address)),X}function H_(W){return{address:h1(W.address),nonce:f1(W.nonce!=null?W.nonce:0),chainId:f1(W.chainId!=null?W.chainId:0),signature:T8.from(W.signature)}}function W6(W){let X;if(typeof W==="string")X=i8.computePublicKey(W,!1);else X=W.publicKey;return h1(U8("0x"+X.substring(4)).substring(26))}function MU(W,X){return W6(i8.recoverPublicKey(W,X))}var t8=BigInt(0),Fs=BigInt(2),Ss=BigInt(27),xs=BigInt(28),ks=BigInt(35),_s=BigInt("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),lO=131072;function ys(W){return{blobToKzgCommitment:(Y)=>{if("computeBlobProof"in W){if("blobToKzgCommitment"in W&&typeof W.blobToKzgCommitment==="function")return E0(W.blobToKzgCommitment(M0(Y)))}else if("blobToKzgCommitment"in W&&typeof W.blobToKzgCommitment==="function")return E0(W.blobToKzgCommitment(Y));if("blobToKZGCommitment"in W&&typeof W.blobToKZGCommitment==="function")return E0(W.blobToKZGCommitment(M0(Y)));a(!1,"unsupported KZG library","kzg",W)},computeBlobKzgProof:(Y,J)=>{if("computeBlobProof"in W&&typeof W.computeBlobProof==="function")return E0(W.computeBlobProof(M0(Y),M0(J)));if("computeBlobKzgProof"in W&&typeof W.computeBlobKzgProof==="function")return W.computeBlobKzgProof(Y,J);if("computeBlobKZGProof"in W&&typeof W.computeBlobKZGProof==="function")return E0(W.computeBlobKZGProof(M0(Y),M0(J)));a(!1,"unsupported KZG library","kzg",W)}}}function A_(W,X){let G=W.toString(16);while(G.length<2)G="0"+G;return G+=E9(X).substring(4),"0x"+G}function ZJ(W){if(W==="0x")return null;return h1(W)}function iH(W,X){try{return uX(W)}catch(G){a(!1,G.message,X,W)}}function vs(W,X){try{if(!Array.isArray(W))throw Error("authorizationList: invalid array");let G=[];for(let Y=0;Y<W.length;Y++){let J=W[Y];if(!Array.isArray(J))throw Error(`authorization[${Y}]: invalid array`);if(J.length!==6)throw Error(`authorization[${Y}]: wrong length`);if(!J[1])throw Error(`authorization[${Y}]: null address`);G.push({address:ZJ(J[1]),nonce:Q8(J[2],"nonce"),chainId:Q8(J[0],"chainId"),signature:T8.from({yParity:hX(J[3],"yParity"),r:I5(J[4],32),s:I5(J[5],32)})})}return G}catch(G){a(!1,G.message,X,W)}}function hX(W,X){if(W==="0x")return 0;return s8(W,X)}function Q8(W,X){if(W==="0x")return t8;let G=f1(W,X);return a(G<=_s,"value exceeds uint size",X,G),G}function p1(W,X){let G=f1(W,"value"),Y=z8(G);return a(Y.length<=32,"value too large",`tx.${X}`,G),Y}function rH(W){return uX(W).map((X)=>[X.address,X.storageKeys])}function gs(W){return W.map((X)=>{return[p1(X.chainId,"chainId"),X.address,p1(X.nonce,"nonce"),p1(X.signature.yParity,"yParity"),z8(X.signature.r),z8(X.signature.s)]})}function us(W,X){a(Array.isArray(W),`invalid ${X}`,"value",W);for(let G=0;G<W.length;G++)a(L9(W[G],32),"invalid ${ param } hash",`value[${G}]`,W[G]);return W}function hs(W){let X=GW(W);a(Array.isArray(X)&&(X.length===9||X.length===6),"invalid field count for legacy transaction","data",W);let G={type:0,nonce:hX(X[0],"nonce"),gasPrice:Q8(X[1],"gasPrice"),gasLimit:Q8(X[2],"gasLimit"),to:ZJ(X[3]),value:Q8(X[4],"value"),data:M0(X[5]),chainId:t8};if(X.length===6)return G;let Y=Q8(X[6],"v"),J=Q8(X[7],"r"),Z=Q8(X[8],"s");if(J===t8&&Z===t8)G.chainId=Y;else{let V=(Y-ks)/Fs;if(V<t8)V=t8;G.chainId=V,a(V!==t8||(Y===Ss||Y===xs),"non-canonical legacy v","v",X[6]),G.signature=T8.from({r:I5(X[7],32),s:I5(X[8],32),v:Y})}return G}function bs(W,X){let G=[p1(W.nonce,"nonce"),p1(W.gasPrice||0,"gasPrice"),p1(W.gasLimit,"gasLimit"),W.to||"0x",p1(W.value,"value"),W.data],Y=t8;if(W.chainId!=t8)Y=f1(W.chainId,"tx.chainId"),a(!X||X.networkV==null||X.legacyChainId===Y,"tx.chainId/sig.v mismatch","sig",X);else if(W.signature){let Z=W.signature.legacyChainId;if(Z!=null)Y=Z}if(!X){if(Y!==t8)G.push(z8(Y)),G.push("0x"),G.push("0x");return S5(G)}let J=BigInt(27+X.yParity);if(Y!==t8)J=T8.getChainIdV(Y,X.v);else if(BigInt(X.v)!==J)a(!1,"tx.chainId/sig.v mismatch","sig",X);return G.push(z8(J)),G.push(z8(X.r)),G.push(z8(X.s)),S5(G)}function aH(W,X){let G;try{if(G=hX(X[0],"yParity"),G!==0&&G!==1)throw Error("bad yParity")}catch(V){a(!1,"invalid yParity","yParity",X[0])}let Y=I5(X[1],32),J=I5(X[2],32),Z=T8.from({r:Y,s:J,yParity:G});W.signature=Z}function ms(W){let X=GW(E0(W).slice(1));a(Array.isArray(X)&&(X.length===9||X.length===12),"invalid field count for transaction type: 2","data",M0(W));let G={type:2,chainId:Q8(X[0],"chainId"),nonce:hX(X[1],"nonce"),maxPriorityFeePerGas:Q8(X[2],"maxPriorityFeePerGas"),maxFeePerGas:Q8(X[3],"maxFeePerGas"),gasPrice:null,gasLimit:Q8(X[4],"gasLimit"),to:ZJ(X[5]),value:Q8(X[6],"value"),data:M0(X[7]),accessList:iH(X[8],"accessList")};if(X.length===9)return G;return aH(G,X.slice(9)),G}function fs(W,X){let G=[p1(W.chainId,"chainId"),p1(W.nonce,"nonce"),p1(W.maxPriorityFeePerGas||0,"maxPriorityFeePerGas"),p1(W.maxFeePerGas||0,"maxFeePerGas"),p1(W.gasLimit,"gasLimit"),W.to||"0x",p1(W.value,"value"),W.data,rH(W.accessList||[])];if(X)G.push(p1(X.yParity,"yParity")),G.push(z8(X.r)),G.push(z8(X.s));return G8(["0x02",S5(G)])}function ps(W){let X=GW(E0(W).slice(1));a(Array.isArray(X)&&(X.length===8||X.length===11),"invalid field count for transaction type: 1","data",M0(W));let G={type:1,chainId:Q8(X[0],"chainId"),nonce:hX(X[1],"nonce"),gasPrice:Q8(X[2],"gasPrice"),gasLimit:Q8(X[3],"gasLimit"),to:ZJ(X[4]),value:Q8(X[5],"value"),data:M0(X[6]),accessList:iH(X[7],"accessList")};if(X.length===8)return G;return aH(G,X.slice(8)),G}function cs(W,X){let G=[p1(W.chainId,"chainId"),p1(W.nonce,"nonce"),p1(W.gasPrice||0,"gasPrice"),p1(W.gasLimit,"gasLimit"),W.to||"0x",p1(W.value,"value"),W.data,rH(W.accessList||[])];if(X)G.push(p1(X.yParity,"recoveryParam")),G.push(z8(X.r)),G.push(z8(X.s));return G8(["0x01",S5(G)])}function ls(W){let X=GW(E0(W).slice(1)),G="3",Y=null;if(X.length===4&&Array.isArray(X[0])){G="3 (network format)";let Z=X[1],V=X[2],U=X[3];a(Array.isArray(Z),"invalid network format: blobs not an array","fields[1]",Z),a(Array.isArray(V),"invalid network format: commitments not an array","fields[2]",V),a(Array.isArray(U),"invalid network format: proofs not an array","fields[3]",U),a(Z.length===V.length,"invalid network format: blobs/commitments length mismatch","fields",X),a(Z.length===U.length,"invalid network format: blobs/proofs length mismatch","fields",X),Y=[];for(let Q=0;Q<X[1].length;Q++)Y.push({data:Z[Q],commitment:V[Q],proof:U[Q]});X=X[0]}a(Array.isArray(X)&&(X.length===11||X.length===14),`invalid field count for transaction type: ${G}`,"data",M0(W));let J={type:3,chainId:Q8(X[0],"chainId"),nonce:hX(X[1],"nonce"),maxPriorityFeePerGas:Q8(X[2],"maxPriorityFeePerGas"),maxFeePerGas:Q8(X[3],"maxFeePerGas"),gasPrice:null,gasLimit:Q8(X[4],"gasLimit"),to:ZJ(X[5]),value:Q8(X[6],"value"),data:M0(X[7]),accessList:iH(X[8],"accessList"),maxFeePerBlobGas:Q8(X[9],"maxFeePerBlobGas"),blobVersionedHashes:X[10]};if(Y)J.blobs=Y;a(J.to!=null,`invalid address for transaction type: ${G}`,"data",W),a(Array.isArray(J.blobVersionedHashes),"invalid blobVersionedHashes: must be an array","data",W);for(let Z=0;Z<J.blobVersionedHashes.length;Z++)a(L9(J.blobVersionedHashes[Z],32),`invalid blobVersionedHash at index ${Z}: must be length 32`,"data",W);if(X.length===11)return J;return aH(J,X.slice(11)),J}function ds(W,X,G){let Y=[p1(W.chainId,"chainId"),p1(W.nonce,"nonce"),p1(W.maxPriorityFeePerGas||0,"maxPriorityFeePerGas"),p1(W.maxFeePerGas||0,"maxFeePerGas"),p1(W.gasLimit,"gasLimit"),W.to||hO,p1(W.value,"value"),W.data,rH(W.accessList||[]),p1(W.maxFeePerBlobGas||0,"maxFeePerBlobGas"),us(W.blobVersionedHashes||[],"blobVersionedHashes")];if(X){if(Y.push(p1(X.yParity,"yParity")),Y.push(z8(X.r)),Y.push(z8(X.s)),G)return G8(["0x03",S5([Y,G.map((J)=>J.data),G.map((J)=>J.commitment),G.map((J)=>J.proof)])])}return G8(["0x03",S5(Y)])}function os(W){let X=GW(E0(W).slice(1));a(Array.isArray(X)&&(X.length===10||X.length===13),"invalid field count for transaction type: 4","data",M0(W));let G={type:4,chainId:Q8(X[0],"chainId"),nonce:hX(X[1],"nonce"),maxPriorityFeePerGas:Q8(X[2],"maxPriorityFeePerGas"),maxFeePerGas:Q8(X[3],"maxFeePerGas"),gasPrice:null,gasLimit:Q8(X[4],"gasLimit"),to:ZJ(X[5]),value:Q8(X[6],"value"),data:M0(X[7]),accessList:iH(X[8],"accessList"),authorizationList:vs(X[9],"authorizationList")};if(X.length===10)return G;return aH(G,X.slice(10)),G}function ns(W,X){let G=[p1(W.chainId,"chainId"),p1(W.nonce,"nonce"),p1(W.maxPriorityFeePerGas||0,"maxPriorityFeePerGas"),p1(W.maxFeePerGas||0,"maxFeePerGas"),p1(W.gasLimit,"gasLimit"),W.to||"0x",p1(W.value,"value"),W.data,rH(W.accessList||[]),gs(W.authorizationList||[])];if(X)G.push(p1(X.yParity,"yParity")),G.push(z8(X.r)),G.push(z8(X.s));return G8(["0x04",S5(G)])}class W5{#W;#X;#G;#Y;#Q;#N;#q;#H;#A;#z;#I;#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:a(!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.#X;if(W==null&&this.type===3)return hO;return W}set to(W){this.#X=W==null?null:h1(W)}get nonce(){return this.#Y}set nonce(W){this.#Y=s8(W,"value")}get gasLimit(){return this.#Q}set gasLimit(W){this.#Q=f1(W)}get gasPrice(){let W=this.#N;if(W==null&&(this.type===0||this.type===1))return t8;return W}set gasPrice(W){this.#N=W==null?null:f1(W,"gasPrice")}get maxPriorityFeePerGas(){let W=this.#q;if(W==null){if(this.type===2||this.type===3)return t8;return null}return W}set maxPriorityFeePerGas(W){this.#q=W==null?null:f1(W,"maxPriorityFeePerGas")}get maxFeePerGas(){let W=this.#H;if(W==null){if(this.type===2||this.type===3)return t8;return null}return W}set maxFeePerGas(W){this.#H=W==null?null:f1(W,"maxFeePerGas")}get data(){return this.#G}set data(W){this.#G=M0(W)}get value(){return this.#A}set value(W){this.#A=f1(W,"value")}get chainId(){return this.#z}set chainId(W){this.#z=f1(W)}get signature(){return this.#I||null}set signature(W){this.#I=W==null?null:T8.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:uX(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((X)=>H_(X))}get maxFeePerBlobGas(){let W=this.#U;if(W==null&&this.type===3)return t8;return W}set maxFeePerBlobGas(W){this.#U=W==null?null:f1(W,"maxFeePerBlobGas")}get blobVersionedHashes(){let W=this.#Z;if(W==null&&this.type===3)return[];return W}set blobVersionedHashes(W){if(W!=null){a(Array.isArray(W),"blobVersionedHashes must be an Array","value",W),W=W.slice();for(let X=0;X<W.length;X++)a(L9(W[X],32),"invalid blobVersionedHash",`value[${X}]`,W[X])}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 X=[],G=[];for(let Y=0;Y<W.length;Y++){let J=W[Y];if(r7(J)){Y1(this.#J,"adding a raw blob requires a KZG library","UNSUPPORTED_OPERATION",{operation:"set blobs()"});let Z=E0(J);if(a(Z.length<=lO,"blob is too large",`blobs[${Y}]`,J),Z.length!==lO){let Q=new Uint8Array(lO);Q.set(Z),Z=Q}let V=this.#J.blobToKzgCommitment(Z),U=M0(this.#J.computeBlobKzgProof(Z,V));X.push({data:M0(Z),commitment:M0(V),proof:U}),G.push(A_(1,V))}else{let Z=M0(J.commitment);X.push({data:M0(J.data),commitment:Z,proof:M0(J.proof)}),G.push(A_(1,Z))}}this.#V=X,this.#Z=G}get kzg(){return this.#J}set kzg(W){if(W==null)this.#J=null;else this.#J=ys(W)}constructor(){this.#W=null,this.#X=null,this.#Y=0,this.#Q=t8,this.#N=null,this.#q=null,this.#H=null,this.#G="0x",this.#A=t8,this.#z=t8,this.#I=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 U8(this.#K(!0,!1))}get unsignedHash(){return U8(this.unsignedSerialized)}get from(){if(this.signature==null)return null;return MU(this.unsignedHash,this.signature)}get fromPublicKey(){if(this.signature==null)return null;return i8.recoverPublicKey(this.unsignedHash,this.signature)}isSigned(){return this.signature!=null}#K(W,X){Y1(!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 bs(this,G);case 1:return cs(this,G);case 2:return fs(this,G);case 3:return ds(this,G,X?this.blobs:null);case 4:return ns(this,G)}Y1(!1,"unsupported transaction type","UNSUPPORTED_OPERATION",{operation:".serialized"})}get serialized(){return this.#K(!0,!0)}get unsignedSerialized(){return this.#K(!1,!1)}inferType(){let W=this.inferTypes();if(W.indexOf(2)>=0)return 2;return W.pop()}inferTypes(){let W=this.gasPrice!=null,X=this.maxFeePerGas!=null||this.maxPriorityFeePerGas!=null,G=this.accessList!=null,Y=this.#U!=null||this.#Z;if(this.maxFeePerGas!=null&&this.maxPriorityFeePerGas!=null)Y1(this.maxFeePerGas>=this.maxPriorityFeePerGas,"priorityFee cannot be more than maxFee","BAD_DATA",{value:this});Y1(!X||this.type!==0&&this.type!==1,"transaction type cannot have maxFeePerGas or maxPriorityFeePerGas","BAD_DATA",{value:this}),Y1(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(X)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(Y&&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 W5.from(this)}toJSON(){let W=(X)=>{if(X==null)return null;return X.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 W5;if(typeof W==="string"){let G=E0(W);if(G[0]>=127)return W5.from(hs(G));switch(G[0]){case 1:return W5.from(ps(G));case 2:return W5.from(ms(G));case 3:return W5.from(ls(G));case 4:return W5.from(os(G))}Y1(!1,"unsupported transaction type","UNSUPPORTED_OPERATION",{operation:"from"})}let X=new W5;if(W.type!=null)X.type=W.type;if(W.to!=null)X.to=W.to;if(W.nonce!=null)X.nonce=W.nonce;if(W.gasLimit!=null)X.gasLimit=W.gasLimit;if(W.gasPrice!=null)X.gasPrice=W.gasPrice;if(W.maxPriorityFeePerGas!=null)X.maxPriorityFeePerGas=W.maxPriorityFeePerGas;if(W.maxFeePerGas!=null)X.maxFeePerGas=W.maxFeePerGas;if(W.maxFeePerBlobGas!=null)X.maxFeePerBlobGas=W.maxFeePerBlobGas;if(W.data!=null)X.data=W.data;if(W.value!=null)X.value=W.value;if(W.chainId!=null)X.chainId=W.chainId;if(W.signature!=null)X.signature=T8.from(W.signature);if(W.accessList!=null)X.accessList=W.accessList;if(W.authorizationList!=null)X.authorizationList=W.authorizationList;if(W.blobVersionedHashes!=null)X.blobVersionedHashes=W.blobVersionedHashes;if(W.kzg!=null)X.kzg=W.kzg;if(W.blobs!=null)X.blobs=W.blobs;if(W.hash!=null)a(X.isSigned(),"unsigned transaction cannot define '.hash'","tx",W),a(X.hash===W.hash,"hash mismatch","tx",W);if(W.from!=null)a(X.isSigned(),"unsigned transaction cannot define '.from'","tx",W),a(X.from.toLowerCase()===(W.from||"").toLowerCase(),"from mismatch","tx",W);return X}}function sH(W){return a(typeof W.address==="string","invalid address for hashAuthorization","auth.address",W),U8(G8(["0x05",S5([W.chainId!=null?z8(W.chainId):"0x",h1(W.address),W.nonce!=null?z8(W.nonce):"0x"])]))}function X6(W){return U8(Q9(W))}function PU(W){if(typeof W==="string")W=Q9(W);return U8(G8([Q9(bO),Q9(String(W.length)),W]))}function RU(W,X){let G=PU(W);return MU(G,X)}var j_=new Uint8Array(32);j_.fill(0);var is=BigInt(-1),K_=BigInt(0),O_=BigInt(1),rs=BigInt("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");function as(W){let X=E0(W),G=X.length%32;if(G)return G8([X,j_.slice(G)]);return M0(X)}var ss=N7(O_,32),ts=N7(K_,32),z_={name:"string",version:"string",chainId:"uint256",verifyingContract:"address",salt:"bytes32"},dO=["name","version","chainId","verifyingContract","salt"];function I_(W){return function(X){return a(typeof X==="string",`invalid domain value for ${JSON.stringify(W)}`,`domain.${W}`,X),X}}var es={name:I_("name"),version:I_("version"),chainId:function(W){let X=f1(W,"domain.chainId");if(a(X>=0,"invalid chain ID","domain.chainId",W),Number.isSafeInteger(X))return Number(X);return BH(X)},verifyingContract:function(W){try{return h1(W).toLowerCase()}catch(X){}a(!1,'invalid domain value "verifyingContract"',"domain.verifyingContract",W)},salt:function(W){let X=E0(W,"domain.salt");return a(X.length===32,'invalid domain value "salt"',"domain.salt",W),M0(X)}};function oO(W){{let X=W.match(/^(u?)int(\d+)$/);if(X){let G=X[1]==="",Y=parseInt(X[2]);a(Y%8===0&&Y!==0&&Y<=256&&X[2]===String(Y),"invalid numeric width","type",W);let J=LH(rs,G?Y-1:Y),Z=G?(J+O_)*is:K_;return function(V){let U=f1(V,"value");return a(U>=Z&&U<=J,`value out-of-bounds for ${W}`,"value",U),N7(G?RH(U,256):U,32)}}}{let X=W.match(/^bytes(\d+)$/);if(X){let G=parseInt(X[1]);return a(G!==0&&G<=32&&X[1]===String(G),"invalid bytes width","type",W),function(Y){let J=E0(Y);return a(J.length===G,`invalid length for ${W}`,"value",Y),as(Y)}}}switch(W){case"address":return function(X){return I5(h1(X),32)};case"bool":return function(X){return!X?ts:ss};case"bytes":return function(X){return U8(X)};case"string":return function(X){return X6(X)}}return null}function w_(W,X){return`${W}(${X.map(({name:G,type:Y})=>Y+" "+G).join(",")})`}function tH(W){let X=W.match(/^([^\x5b]*)((\x5b\d*\x5d)*)(\x5b(\d*)\x5d)$/);if(X)return{base:X[1],index:X[2]+X[4],array:{base:X[1],prefix:X[1]+X[2],count:X[5]?parseInt(X[5]):-1}};return{base:W}}class F9{primaryType;#W;get types(){return JSON.parse(this.#W)}#X;#G;constructor(W){this.#X=new Map,this.#G=new Map;let X=new Map,G=new Map,Y=new Map,J={};Object.keys(W).forEach((U)=>{J[U]=W[U].map(({name:Q,type:N})=>{let{base:q,index:A}=tH(N);if(q==="int"&&!W.int)q="int256";if(q==="uint"&&!W.uint)q="uint256";return{name:Q,type:q+(A||"")}}),X.set(U,new Set),G.set(U,[]),Y.set(U,new Set)}),this.#W=JSON.stringify(J);for(let U in J){let Q=new Set;for(let N of J[U]){a(!Q.has(N.name),`duplicate variable name ${JSON.stringify(N.name)} in ${JSON.stringify(U)}`,"types",W),Q.add(N.name);let q=tH(N.type).base;if(a(q!==U,`circular type reference to ${JSON.stringify(q)}`,"types",W),oO(q))continue;a(G.has(q),`unknown type ${JSON.stringify(q)}`,"types",W),G.get(q).push(U),X.get(U).add(q)}}let Z=Array.from(G.keys()).filter((U)=>G.get(U).length===0);a(Z.length!==0,"missing primary type","types",W),a(Z.length===1,`ambiguous primary types or unused types: ${Z.map((U)=>JSON.stringify(U)).join(", ")}`,"types",W),A8(this,{primaryType:Z[0]});function V(U,Q){a(!Q.has(U),`circular type reference to ${JSON.stringify(U)}`,"types",W),Q.add(U);for(let N of X.get(U)){if(!G.has(N))continue;V(N,Q);for(let q of Q)Y.get(q).add(N)}Q.delete(U)}V(this.primaryType,new Set);for(let[U,Q]of Y){let N=Array.from(Q);N.sort(),this.#X.set(U,w_(U,J[U])+N.map((q)=>w_(q,J[q])).join(""))}}getEncoder(W){let X=this.#G.get(W);if(!X)X=this.#Y(W),this.#G.set(W,X);return X}#Y(W){{let Y=oO(W);if(Y)return Y}let X=tH(W).array;if(X){let Y=X.prefix,J=this.getEncoder(Y);return(Z)=>{a(X.count===-1||X.count===Z.length,`array length mismatch; expected length ${X.count}`,"value",Z);let V=Z.map(J);if(this.#X.has(Y))V=V.map(U8);return U8(G8(V))}}let G=this.types[W];if(G){let Y=X6(this.#X.get(W));return(J)=>{let Z=G.map(({name:V,type:U})=>{let Q=this.getEncoder(U)(J[V]);if(this.#X.has(U))return U8(Q);return Q});return Z.unshift(Y),G8(Z)}}a(!1,`unknown type: ${W}`,"type",W)}encodeType(W){let X=this.#X.get(W);return a(X,`unknown type: ${JSON.stringify(W)}`,"name",W),X}encodeData(W,X){return this.getEncoder(W)(X)}hashStruct(W,X){return U8(this.encodeData(W,X))}encode(W){return this.encodeData(this.primaryType,W)}hash(W){return this.hashStruct(this.primaryType,W)}_visit(W,X,G){if(oO(W))return G(W,X);let Y=tH(W).array;if(Y)return a(Y.count===-1||Y.count===X.length,`array length mismatch; expected length ${Y.count}`,"value",X),X.map((Z)=>this._visit(Y.prefix,Z,G));let J=this.types[W];if(J)return J.reduce((Z,{name:V,type:U})=>{return Z[V]=this._visit(U,X[V],G),Z},{});a(!1,`unknown type: ${W}`,"type",W)}visit(W,X){return this._visit(this.primaryType,W,X)}static from(W){return new F9(W)}static getPrimaryType(W){return F9.from(W).primaryType}static hashStruct(W,X,G){return F9.from(X).hashStruct(W,G)}static hashDomain(W){let X=[];for(let G in W){if(W[G]==null)continue;let Y=z_[G];a(Y,`invalid typed-data domain key: ${JSON.stringify(G)}`,"domain",W),X.push({name:G,type:Y})}return X.sort((G,Y)=>{return dO.indexOf(G.name)-dO.indexOf(Y.name)}),F9.hashStruct("EIP712Domain",{EIP712Domain:X},W)}static encode(W,X,G){return G8(["0x1901",F9.hashDomain(W),F9.from(X).hash(G)])}static hash(W,X,G){return U8(F9.encode(W,X,G))}static async resolveNames(W,X,G,Y){W=Object.assign({},W);for(let V in W)if(W[V]==null)delete W[V];let J={};if(W.verifyingContract&&!L9(W.verifyingContract,20))J[W.verifyingContract]="0x";let Z=F9.from(X);Z.visit(G,(V,U)=>{if(V==="address"&&!L9(U,20))J[U]="0x";return U});for(let V in J)J[V]=await Y(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,X,G){F9.hashDomain(W);let Y={},J=[];dO.forEach((U)=>{let Q=W[U];if(Q==null)return;Y[U]=es[U](Q),J.push({name:U,type:z_[U]})});let Z=F9.from(X);X=Z.types;let V=Object.assign({},X);return a(V.EIP712Domain==null,"types must not contain EIP712Domain type","types.EIP712Domain",X),V.EIP712Domain=J,Z.encode(G),{types:V,domain:Y,primaryType:Z.primaryType,message:Z.visit(G,(U,Q)=>{if(U.match(/^bytes(\d*)/))return M0(E0(Q));if(U.match(/^u?int/))return f1(Q).toString();switch(U){case"address":return Q.toLowerCase();case"bool":return!!Q;case"string":return a(typeof Q==="string","invalid string","value",Q),Q}a(!1,"unsupported type","type",U)})}}}var D_=BigInt(0);function nO(W){if(W==null)return null;return W}function e8(W){if(W==null)return null;return W.toString()}function LU(W){let X={};if(W.to)X.to=W.to;if(W.from)X.from=W.from;if(W.data)X.data=M0(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;X[J]=f1(W[J],`request.${J}`)}let Y="type,nonce".split(/,/);for(let J of Y){if(!(J in W)||W[J]==null)continue;X[J]=s8(W[J],`request.${J}`)}if(W.accessList)X.accessList=uX(W.accessList);if(W.authorizationList)X.authorizationList=W.authorizationList.slice();if("blockTag"in W)X.blockTag=W.blockTag;if("enableCcipRead"in W)X.enableCcipRead=!!W.enableCcipRead;if("customData"in W)X.customData=W.customData;if("blobVersionedHashes"in W&&W.blobVersionedHashes)X.blobVersionedHashes=W.blobVersionedHashes.slice();if("kzg"in W)X.kzg=W.kzg;if("blobs"in W&&W.blobs)X.blobs=W.blobs.map((J)=>{if(r7(J))return M0(J);return Object.assign({},J)});return X}class C_{provider;number;hash;timestamp;parentHash;parentBeaconBlockRoot;nonce;difficulty;gasLimit;gasUsed;stateRoot;receiptsRoot;blobGasUsed;excessBlobGas;miner;prevRandao;extraData;baseFeePerGas;#W;constructor(W,X){this.#W=W.transactions.map((G)=>{if(typeof G!=="string")return new eH(G,X);return G}),A8(this,{provider:X,hash:nO(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:nO(W.prevRandao),extraData:W.extraData,baseFeePerGas:nO(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 Y1(typeof W[0]==="object","transactions were not prefetched with block request","UNSUPPORTED_OPERATION",{operation:"transactionResponses()"}),W}toJSON(){let{baseFeePerGas:W,difficulty:X,extraData:G,gasLimit:Y,gasUsed:J,hash:Z,miner:V,prevRandao:U,nonce:Q,number:N,parentHash:q,parentBeaconBlockRoot:A,stateRoot:H,receiptsRoot:I,timestamp:w,transactions:O}=this;return{_type:"Block",baseFeePerGas:e8(W),difficulty:e8(X),extraData:G,gasLimit:e8(Y),gasUsed:e8(J),blobGasUsed:e8(this.blobGasUsed),excessBlobGas:e8(this.excessBlobGas),hash:Z,miner:V,prevRandao:U,nonce:Q,number:N,parentHash:q,timestamp:w,parentBeaconBlockRoot:A,stateRoot:H,receiptsRoot:I,transactions:O}}[Symbol.iterator](){let W=0,X=this.transactions;return{next:()=>{if(W<this.length)return{value:X[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 X=void 0;if(typeof W==="number")X=this.#W[W];else{let G=W.toLowerCase();for(let Y of this.#W)if(typeof Y==="string"){if(Y!==G)continue;X=Y;break}else{if(Y.hash!==G)continue;X=Y;break}}if(X==null)throw Error("no such tx");if(typeof X==="string")return await this.provider.getTransaction(X);else return X}getPrefetchedTransaction(W){let X=this.prefetchedTransactions;if(typeof W==="number")return X[W];W=W.toLowerCase();for(let G of X)if(G.hash===W)return G;a(!1,"no matching transaction","indexOrHash",W)}isMined(){return!!this.hash}isLondon(){return!!this.baseFeePerGas}orphanedEvent(){if(!this.isMined())throw Error("");return Gt(this)}}class iO{provider;transactionHash;blockHash;blockNumber;removed;address;data;topics;index;transactionIndex;constructor(W,X){this.provider=X;let G=Object.freeze(W.topics.slice());A8(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:X,blockNumber:G,data:Y,index:J,removed:Z,topics:V,transactionHash:U,transactionIndex:Q}=this;return{_type:"log",address:W,blockHash:X,blockNumber:G,data:Y,index:J,removed:Z,topics:V,transactionHash:U,transactionIndex:Q}}async getBlock(){let W=await this.provider.getBlock(this.blockHash);return Y1(!!W,"failed to find transaction","UNKNOWN_ERROR",{}),W}async getTransaction(){let W=await this.provider.getTransaction(this.transactionHash);return Y1(!!W,"failed to find transaction","UNKNOWN_ERROR",{}),W}async getTransactionReceipt(){let W=await this.provider.getTransactionReceipt(this.transactionHash);return Y1(!!W,"failed to find transaction receipt","UNKNOWN_ERROR",{}),W}removedEvent(){return Yt(this)}}class T_{provider;to;from;contractAddress;hash;index;blockHash;blockNumber;logsBloom;gasUsed;blobGasUsed;cumulativeGasUsed;gasPrice;blobGasPrice;type;status;root;#W;constructor(W,X){this.#W=Object.freeze(W.logs.map((Y)=>{return new iO(Y,X)}));let G=D_;if(W.effectiveGasPrice!=null)G=W.effectiveGasPrice;else if(W.gasPrice!=null)G=W.gasPrice;A8(this,{provider:X,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:X,contractAddress:G,hash:Y,index:J,blockHash:Z,blockNumber:V,logsBloom:U,logs:Q,status:N,root:q}=this;return{_type:"TransactionReceipt",blockHash:Z,blockNumber:V,contractAddress:G,cumulativeGasUsed:e8(this.cumulativeGasUsed),from:X,gasPrice:e8(this.gasPrice),blobGasUsed:e8(this.blobGasUsed),blobGasPrice:e8(this.blobGasPrice),gasUsed:e8(this.gasUsed),hash:Y,index:J,logs:Q,logsBloom:U,root:q,status:N,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 P_(this)}reorderedEvent(W){return Y1(!W||W.isMined(),"unmined 'other' transction cannot be orphaned","UNSUPPORTED_OPERATION",{operation:"reorderedEvent(other)"}),M_(this,W)}}class eH{provider;blockNumber;blockHash;index;hash;type;to;from;nonce;gasLimit;gasPrice;maxPriorityFeePerGas;maxFeePerGas;maxFeePerBlobGas;data;value;chainId;signature;accessList;blobVersionedHashes;authorizationList;#W;constructor(W,X){this.provider=X,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:X,index:G,hash:Y,type:J,to:Z,from:V,nonce:U,data:Q,signature:N,accessList:q,blobVersionedHashes:A}=this;return{_type:"TransactionResponse",accessList:q,blockNumber:W,blockHash:X,blobVersionedHashes:A,chainId:e8(this.chainId),data:Q,from:V,gasLimit:e8(this.gasLimit),gasPrice:e8(this.gasPrice),hash:Y,maxFeePerGas:e8(this.maxFeePerGas),maxPriorityFeePerGas:e8(this.maxPriorityFeePerGas),maxFeePerBlobGas:e8(this.maxFeePerBlobGas),nonce:U,signature:N,to:Z,index:G,type:J,value:e8(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 X=this.provider.getBlock(W);if(X==null)throw Error("TODO");return X}async getTransaction(){return this.provider.getTransaction(this.hash)}async confirmations(){if(this.blockNumber==null){let{tx:X,blockNumber:G}=await i7({tx:this.getTransaction(),blockNumber:this.provider.getBlockNumber()});if(X==null||X.blockNumber==null)return 0;return G-X.blockNumber+1}return await this.provider.getBlockNumber()-this.blockNumber+1}async wait(W,X){let G=W==null?1:W,Y=X==null?0:X,J=this.#W,Z=-1,V=J===-1?!0:!1,U=async()=>{if(V)return null;let{blockNumber:A,nonce:H}=await i7({blockNumber:this.provider.getBlockNumber(),nonce:this.provider.getTransactionCount(this.from)});if(H<this.nonce){J=A;return}if(V)return null;let I=await this.getTransaction();if(I&&I.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 O of w)if(O===this.hash)return;for(let O=0;O<w.length;O++){let T=await w.getTransaction(O);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 h="replaced";if(T.data===this.data&&T.to===this.to&&T.value===this.value)h="repriced";else if(T.data==="0x"&&T.from===T.to&&T.value===D_)h="cancelled";Y1(!1,"transaction was replaced","TRANSACTION_REPLACED",{cancelled:h==="replaced"||h==="cancelled",reason:h,replacement:T.replaceableTransaction(J),hash:T.hash,receipt:x})}}Z++}return},Q=(A)=>{if(A==null||A.status!==0)return A;Y1(!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})},N=await this.provider.getTransactionReceipt(this.hash);if(G===0)return Q(N);if(N){if(G===1||await N.confirmations()>=G)return Q(N)}else if(await U(),G===0)return null;return await new Promise((A,H)=>{let I=[],w=()=>{I.forEach((T)=>T())};if(I.push(()=>{V=!0}),Y>0){let T=setTimeout(()=>{w(),H(zU("wait for transaction timeout","TIMEOUT"))},Y);I.push(()=>{clearTimeout(T)})}let O=async(T)=>{if(await T.confirmations()>=G){w();try{A(Q(T))}catch(x){H(x)}}};if(I.push(()=>{this.provider.off(this.hash,O)}),this.provider.on(this.hash,O),J>=0){let T=async()=>{try{await U()}catch(x){if(PH(x,"TRANSACTION_REPLACED")){w(),H(x);return}}if(!V)this.provider.once("block",T)};I.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 Y1(this.isMined(),"unmined transaction canot be orphaned","UNSUPPORTED_OPERATION",{operation:"removeEvent()"}),P_(this)}reorderedEvent(W){return Y1(this.isMined(),"unmined transaction canot be orphaned","UNSUPPORTED_OPERATION",{operation:"removeEvent()"}),Y1(!W||W.isMined(),"unmined 'other' transaction canot be orphaned","UNSUPPORTED_OPERATION",{operation:"removeEvent()"}),M_(this,W)}replaceableTransaction(W){a(Number.isInteger(W)&&W>=0,"invalid startBlock","startBlock",W);let X=new eH(this,this.provider);return X.#W=W,X}}function Gt(W){return{orphan:"drop-block",hash:W.hash,number:W.number}}function M_(W,X){return{orphan:"reorder-transaction",tx:W,other:X}}function P_(W){return{orphan:"drop-transaction",tx:W}}function Yt(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 bX(W,X){if(W.provider)return W.provider;Y1(!1,"missing provider","UNSUPPORTED_OPERATION",{operation:X})}async function R_(W,X){let G=LU(X);if(G.to!=null)G.to=e4(G.to,W);if(G.from!=null){let Y=G.from;G.from=Promise.all([W.getAddress(),e4(Y,W)]).then(([J,Z])=>{return a(J.toLowerCase()===Z.toLowerCase(),"transaction from mismatch","tx.from",Z),J})}else G.from=W.getAddress();return await i7(G)}class BU{provider;constructor(W){A8(this,{provider:W||null})}async getNonce(W){return bX(this,"getTransactionCount").getTransactionCount(await this.getAddress(),W)}async populateCall(W){return await R_(this,W)}async populateTransaction(W){let X=bX(this,"populateTransaction"),G=await R_(this,W);if(G.nonce==null)G.nonce=await this.getNonce("pending");if(G.gasLimit==null)G.gasLimit=await this.estimateGas(G);let Y=await this.provider.getNetwork();if(G.chainId!=null){let Z=f1(G.chainId);a(Z===Y.chainId,"transaction chainId mismatch","tx.chainId",W.chainId)}else G.chainId=Y.chainId;let J=G.maxFeePerGas!=null||G.maxPriorityFeePerGas!=null;if(G.gasPrice!=null&&(G.type===2||J))a(!1,"eip-1559 transaction do not support gasPrice","tx",W);else if((G.type===0||G.type===1)&&J)a(!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 X.getFeeData();if(Y1(Z.gasPrice!=null,"network does not support gasPrice","UNSUPPORTED_OPERATION",{operation:"getGasPrice"}),G.gasPrice==null)G.gasPrice=Z.gasPrice}else{let Z=await X.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(Y1(!J,"network does not support EIP-1559","UNSUPPORTED_OPERATION",{operation:"populateTransaction"}),G.gasPrice==null)G.gasPrice=Z.gasPrice;G.type=0}else Y1(!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 i7(G)}async populateAuthorization(W){let X=Object.assign({},W);if(X.chainId==null)X.chainId=(await bX(this,"getNetwork").getNetwork()).chainId;if(X.nonce==null)X.nonce=await this.getNonce();return X}async estimateGas(W){return bX(this,"estimateGas").estimateGas(await this.populateCall(W))}async call(W){return bX(this,"call").call(await this.populateCall(W))}async resolveName(W){return await bX(this,"resolveName").resolveName(W)}async sendTransaction(W){let X=bX(this,"sendTransaction"),G=await this.populateTransaction(W);delete G.from;let Y=W5.from(G);return await X.broadcastTransaction(await this.signTransaction(Y))}authorize(W){Y1(!1,"authorization not implemented for this signer","UNSUPPORTED_OPERATION",{operation:"authorize"})}}class EU extends BU{address;constructor(W,X){super(X);A8(this,{address:W})}async getAddress(){return this.address}connect(W){return new EU(this.address,W)}#W(W,X){Y1(!1,`VoidSigner cannot sign ${W}`,"UNSUPPORTED_OPERATION",{operation:X})}async signTransaction(W){this.#W("transactions","signTransaction")}async signMessage(W){this.#W("messages","signMessage")}async signTypedData(W,X,G){this.#W("typed-data","signTypedData")}}class mX extends BU{address;#W;constructor(W,X){super(X);a(W&&typeof W.sign==="function","invalid private key","privateKey","[ REDACTED ]"),this.#W=W;let G=W6(this.signingKey.publicKey);A8(this,{address:G})}get signingKey(){return this.#W}get privateKey(){return this.signingKey.privateKey}async getAddress(){return this.address}connect(W){return new mX(this.#W,W)}async signTransaction(W){W=LU(W);let{to:X,from:G}=await i7({to:W.to?e4(W.to,this):void 0,from:W.from?e4(W.from,this):void 0});if(X!=null)W.to=X;if(G!=null)W.from=G;if(W.from!=null)a(h1(W.from)===this.address,"transaction from address mismatch","tx.from",W.from),delete W.from;let Y=W5.from(W);return Y.signature=this.signingKey.sign(Y.unsignedHash),Y.serialized}async signMessage(W){return this.signMessageSync(W)}signMessageSync(W){return this.signingKey.sign(PU(W)).serialized}authorizeSync(W){a(typeof W.address==="string","invalid address for authorizeSync","auth.address",W);let X=this.signingKey.sign(sH(W));return Object.assign({},{address:h1(W.address),nonce:f1(W.nonce||0),chainId:f1(W.chainId||0)},{signature:X})}async authorize(W){return W=Object.assign({},W,{address:await e4(W.address,this)}),this.authorizeSync(await this.populateAuthorization(W))}async signTypedData(W,X,G){let Y=await F9.resolveNames(W,X,G,async(J)=>{Y1(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 Y1(Z!=null,"unconfigured ENS name","UNCONFIGURED_NAME",{value:J}),Z});return this.signingKey.sign(F9.hash(Y.domain,X,Y.value)).serialized}}var WA=" !#$%&'()*+,-./<=>?@[]^_`{|}~",Jt=/^[a-z]*$/i;function L_(W,X){let G=97;return W.reduce((Y,J)=>{if(J===X)G++;else if(J.match(Jt))Y.push(String.fromCharCode(G)+J);else G=97,Y.push(J);return Y},[])}function Zt(W,X){for(let J=WA.length-1;J>=0;J--)W=W.split(WA[J]).join(X.substring(2*J,2*J+2));let G=[],Y=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(Y)throw Error(`leftovers: ${JSON.stringify(Y)}`);return L_(L_(G,";"),":")}function B_(W){return a(W[0]==="0","unsupported auwl data","data",W),Zt(W.substring(1+2*WA.length),W.substring(1,1+2*WA.length))}class rO{locale;constructor(W){A8(this,{locale:W})}split(W){return W.toLowerCase().split(/\s+/g)}join(W){return W.join(" ")}}class aO extends rO{#W;#X;constructor(W,X,G){super(W);this.#W=X,this.#X=G,this.#G=null}get _data(){return this.#W}_decodeWords(){return B_(this.#W)}#G;#Y(){if(this.#G==null){let W=this._decodeWords();if(X6(W.join(`
250
250
  `)+`
251
- `)!==this.#X)throw Error(`BIP39 Wordlist for ${this.locale} FAILED`);this.#G=W}return this.#G}getWord(W){let X=this.#Y();return a(W>=0&&W<X.length,`invalid word index: ${W}`,"index",W),X[W]}getWordIndex(W){return this.#Y().indexOf(W)}}var Vt="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",Ut="0x3c8acc1e7b08d8e76f9fda015ef48dc8c710a73cb7e0f77b2c18a9b5a7adde60",sO=null;class G6 extends aO{constructor(){super("en",Vt,Ut)}static wordlist(){if(sO==null)sO=new G6;return sO}}function E_(W){return(1<<W)-1<<8-W&255}function Qt(W){return(1<<W)-1&255}function tO(W,X){if(rY("NFKD"),X==null)X=G6.wordlist();let G=X.split(W);a(G.length%3===0&&G.length>=12&&G.length<=24,"invalid mnemonic length","mnemonic","[ REDACTED ]");let Y=new Uint8Array(Math.ceil(11*G.length/8)),J=0;for(let N=0;N<G.length;N++){let q=X.getWordIndex(G[N].normalize("NFKD"));a(q>=0,`invalid mnemonic word at index ${N}`,"mnemonic","[ REDACTED ]");for(let A=0;A<11;A++){if(q&1<<10-A)Y[J>>3]|=1<<7-J%8;J++}}let Z=32*G.length/3,V=G.length/3,U=E_(V),Q=E0(E9(Y.slice(0,Z/8)))[0]&U;return a(Q===(Y[Y.length-1]&U),"invalid mnemonic checksum","mnemonic","[ REDACTED ]"),M0(Y.slice(0,Z/8))}function eO(W,X){if(a(W.length%4===0&&W.length>=16&&W.length<=32,"invalid entropy size","entropy","[ REDACTED ]"),X==null)X=G6.wordlist();let G=[0],Y=11;for(let V=0;V<W.length;V++)if(Y>8)G[G.length-1]<<=8,G[G.length-1]|=W[V],Y-=8;else G[G.length-1]<<=Y,G[G.length-1]|=W[V]>>8-Y,G.push(W[V]&Qt(8-Y)),Y+=3;let J=W.length/4,Z=parseInt(E9(W).substring(2,4),16)&E_(J);return G[G.length-1]<<=J,G[G.length-1]|=Z>>8-J,X.join(G.map((V)=>X.getWord(V)))}var WD={};class Y6{phrase;password;wordlist;entropy;constructor(W,X,G,Y,J){if(Y==null)Y="";if(J==null)J=G6.wordlist();n4(W,WD,"Mnemonic"),A8(this,{phrase:G,password:Y,wordlist:J,entropy:X})}computeSeed(){let W=Q9("mnemonic"+this.password,"NFKD");return x5(Q9(this.phrase,"NFKD"),W,2048,64,"sha512")}static fromPhrase(W,X,G){let Y=tO(W,G);return W=eO(E0(Y),G),new Y6(WD,Y,W,X,G)}static fromEntropy(W,X,G){let Y=E0(W,"entropy"),J=eO(Y,G);return new Y6(WD,M0(Y),J,X,G)}static entropyToPhrase(W,X){let G=E0(W,"entropy");return eO(G,X)}static phraseToEntropy(W,X){return tO(W,X)}static isValidMnemonic(W,X){try{return tO(W,X),!0}catch(G){}return!1}}/*! MIT License. Copyright 2015-2022 Richard Moore <me@ricmoo.com>. See LICENSE.txt. */var N9=function(W,X,G,Y){if(G==="a"&&!Y)throw TypeError("Private accessor was defined without a getter");if(typeof X==="function"?W!==X||!Y:!X.has(W))throw TypeError("Cannot read private member from an object whose class did not declare it");return G==="m"?Y:G==="a"?Y.call(W):Y?Y.value:X.get(W)},XD=function(W,X,G,Y,J){if(Y==="m")throw TypeError("Private method is not writable");if(Y==="a"&&!J)throw TypeError("Private accessor was defined without a setter");if(typeof X==="function"?W!==X||!J:!X.has(W))throw TypeError("Cannot write private member to an object whose class did not declare it");return Y==="a"?J.call(W,G):J?J.value=G:X.set(W,G),G},GA,v5,s7,Nt={16:10,24:12,32:14},qt=[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],y5=[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],XA=[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],Ht=[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],At=[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],zt=[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],It=[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],wt=[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],jt=[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],Kt=[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],Ot=[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],Dt=[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],Ct=[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],Tt=[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],Mt=[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 GD(W){let X=[];for(let G=0;G<W.length;G+=4)X.push(W[G]<<24|W[G+1]<<16|W[G+2]<<8|W[G+3]);return X}class YA{get key(){return N9(this,GA,"f").slice()}constructor(W){if(GA.set(this,void 0),v5.set(this,void 0),s7.set(this,void 0),!(this instanceof YA))throw Error("AES must be instanitated with `new`");XD(this,GA,new Uint8Array(W),"f");let X=Nt[this.key.length];if(X==null)throw TypeError("invalid key size (must be 16, 24 or 32 bytes)");XD(this,s7,[],"f"),XD(this,v5,[],"f");for(let N=0;N<=X;N++)N9(this,s7,"f").push([0,0,0,0]),N9(this,v5,"f").push([0,0,0,0]);let G=(X+1)*4,Y=this.key.length/4,J=GD(this.key),Z;for(let N=0;N<Y;N++)Z=N>>2,N9(this,s7,"f")[Z][N%4]=J[N],N9(this,v5,"f")[X-Z][N%4]=J[N];let V=0,U=Y,Q;while(U<G){if(Q=J[Y-1],J[0]^=y5[Q>>16&255]<<24^y5[Q>>8&255]<<16^y5[Q&255]<<8^y5[Q>>24&255]^qt[V]<<24,V+=1,Y!=8)for(let H=1;H<Y;H++)J[H]^=J[H-1];else{for(let H=1;H<Y/2;H++)J[H]^=J[H-1];Q=J[Y/2-1],J[Y/2]^=y5[Q&255]^y5[Q>>8&255]<<8^y5[Q>>16&255]<<16^y5[Q>>24&255]<<24;for(let H=Y/2+1;H<Y;H++)J[H]^=J[H-1]}let N=0,q,A;while(N<Y&&U<G)q=U>>2,A=U%4,N9(this,s7,"f")[q][A]=J[N],N9(this,v5,"f")[X-q][A]=J[N++],U++}for(let N=1;N<X;N++)for(let q=0;q<4;q++)Q=N9(this,v5,"f")[N][q],N9(this,v5,"f")[N][q]=Dt[Q>>24&255]^Ct[Q>>16&255]^Tt[Q>>8&255]^Mt[Q&255]}encrypt(W){if(W.length!=16)throw TypeError("invalid plaintext size (must be 16 bytes)");let X=N9(this,s7,"f").length-1,G=[0,0,0,0],Y=GD(W);for(let V=0;V<4;V++)Y[V]^=N9(this,s7,"f")[0][V];for(let V=1;V<X;V++){for(let U=0;U<4;U++)G[U]=Ht[Y[U]>>24&255]^At[Y[(U+1)%4]>>16&255]^zt[Y[(U+2)%4]>>8&255]^It[Y[(U+3)%4]&255]^N9(this,s7,"f")[V][U];Y=G.slice()}let J=new Uint8Array(16),Z=0;for(let V=0;V<4;V++)Z=N9(this,s7,"f")[X][V],J[4*V]=(y5[Y[V]>>24&255]^Z>>24)&255,J[4*V+1]=(y5[Y[(V+1)%4]>>16&255]^Z>>16)&255,J[4*V+2]=(y5[Y[(V+2)%4]>>8&255]^Z>>8)&255,J[4*V+3]=(y5[Y[(V+3)%4]&255]^Z)&255;return J}decrypt(W){if(W.length!=16)throw TypeError("invalid ciphertext size (must be 16 bytes)");let X=N9(this,v5,"f").length-1,G=[0,0,0,0],Y=GD(W);for(let V=0;V<4;V++)Y[V]^=N9(this,v5,"f")[0][V];for(let V=1;V<X;V++){for(let U=0;U<4;U++)G[U]=wt[Y[U]>>24&255]^jt[Y[(U+3)%4]>>16&255]^Kt[Y[(U+2)%4]>>8&255]^Ot[Y[(U+1)%4]&255]^N9(this,v5,"f")[V][U];Y=G.slice()}let J=new Uint8Array(16),Z=0;for(let V=0;V<4;V++)Z=N9(this,v5,"f")[X][V],J[4*V]=(XA[Y[V]>>24&255]^Z>>24)&255,J[4*V+1]=(XA[Y[(V+3)%4]>>16&255]^Z>>16)&255,J[4*V+2]=(XA[Y[(V+2)%4]>>8&255]^Z>>8)&255,J[4*V+3]=(XA[Y[(V+1)%4]&255]^Z)&255;return J}}GA=new WeakMap,v5=new WeakMap,s7=new WeakMap;class $U{constructor(W,X,G){if(G&&!(this instanceof G))throw Error(`${W} must be instantiated with "new"`);Object.defineProperties(this,{aes:{enumerable:!0,value:new YA(X)},name:{enumerable:!0,value:W}})}}var JA=function(W,X,G,Y,J){if(Y==="m")throw TypeError("Private method is not writable");if(Y==="a"&&!J)throw TypeError("Private accessor was defined without a setter");if(typeof X==="function"?W!==X||!J:!X.has(W))throw TypeError("Cannot write private member to an object whose class did not declare it");return Y==="a"?J.call(W,G):J?J.value=G:X.set(W,G),G},VJ=function(W,X,G,Y){if(G==="a"&&!Y)throw TypeError("Private accessor was defined without a getter");if(typeof X==="function"?W!==X||!Y:!X.has(W))throw TypeError("Cannot read private member from an object whose class did not declare it");return G==="m"?Y:G==="a"?Y.call(W):Y?Y.value:X.get(W)},FU,J6;class SU extends $U{constructor(W,X){super("ECC",W,SU);if(FU.set(this,void 0),J6.set(this,void 0),X){if(X.length%16)throw TypeError("invalid iv size (must be 16 bytes)");JA(this,FU,new Uint8Array(X),"f")}else JA(this,FU,new Uint8Array(16),"f");JA(this,J6,this.iv,"f")}get iv(){return new Uint8Array(VJ(this,FU,"f"))}encrypt(W){if(W.length%16)throw TypeError("invalid plaintext size (must be multiple of 16 bytes)");let X=new Uint8Array(W.length);for(let G=0;G<W.length;G+=16){for(let Y=0;Y<16;Y++)VJ(this,J6,"f")[Y]^=W[G+Y];JA(this,J6,this.aes.encrypt(VJ(this,J6,"f")),"f"),X.set(VJ(this,J6,"f"),G)}return X}decrypt(W){if(W.length%16)throw TypeError("invalid ciphertext size (must be multiple of 16 bytes)");let X=new Uint8Array(W.length);for(let G=0;G<W.length;G+=16){let Y=this.aes.decrypt(W.subarray(G,G+16));for(let J=0;J<16;J++)X[G+J]=Y[J]^VJ(this,J6,"f")[J],VJ(this,J6,"f")[J]=W[G+J]}return X}}FU=new WeakMap,J6=new WeakMap;var UJ=function(W,X,G,Y,J){if(Y==="m")throw TypeError("Private method is not writable");if(Y==="a"&&!J)throw TypeError("Private accessor was defined without a setter");if(typeof X==="function"?W!==X||!J:!X.has(W))throw TypeError("Cannot write private member to an object whose class did not declare it");return Y==="a"?J.call(W,G):J?J.value=G:X.set(W,G),G},g5=function(W,X,G,Y){if(G==="a"&&!Y)throw TypeError("Private accessor was defined without a getter");if(typeof X==="function"?W!==X||!Y:!X.has(W))throw TypeError("Cannot read private member from an object whose class did not declare it");return G==="m"?Y:G==="a"?Y.call(W):Y?Y.value:X.get(W)},xU,fX,u5;class HW extends $U{constructor(W,X){super("CTR",W,HW);if(xU.set(this,void 0),fX.set(this,void 0),u5.set(this,void 0),UJ(this,u5,new Uint8Array(16),"f"),g5(this,u5,"f").fill(0),UJ(this,xU,g5(this,u5,"f"),"f"),UJ(this,fX,16,"f"),X==null)X=1;if(typeof X==="number")this.setCounterValue(X);else this.setCounterBytes(X)}get counter(){return new Uint8Array(g5(this,u5,"f"))}setCounterValue(W){if(!Number.isInteger(W)||W<0||W>Number.MAX_SAFE_INTEGER)throw TypeError("invalid counter initial integer value");for(let X=15;X>=0;--X)g5(this,u5,"f")[X]=W%256,W=Math.floor(W/256)}setCounterBytes(W){if(W.length!==16)throw TypeError("invalid counter initial Uint8Array value length");g5(this,u5,"f").set(W)}increment(){for(let W=15;W>=0;W--)if(g5(this,u5,"f")[W]===255)g5(this,u5,"f")[W]=0;else{g5(this,u5,"f")[W]++;break}}encrypt(W){var X,G;let Y=new Uint8Array(W);for(let J=0;J<Y.length;J++){if(g5(this,fX,"f")===16)UJ(this,xU,this.aes.encrypt(g5(this,u5,"f")),"f"),UJ(this,fX,0,"f"),this.increment();Y[J]^=g5(this,xU,"f")[UJ(this,fX,(G=g5(this,fX,"f"),X=G++,G),"f"),X]}return Y}decrypt(W){return this.encrypt(W)}}xU=new WeakMap,fX=new WeakMap,u5=new WeakMap;function YD(W){if(W.length<16)throw TypeError("PKCS#7 invalid length");let X=W[W.length-1];if(X>16)throw TypeError("PKCS#7 padding byte out of range");let G=W.length-X;for(let Y=0;Y<X;Y++)if(W[G+Y]!==X)throw TypeError("PKCS#7 invalid padding byte");return new Uint8Array(W.subarray(0,G))}function JD(W){if(typeof W==="string"&&!W.startsWith("0x"))W="0x"+W;return Q7(W)}function QJ(W,X){W=String(W);while(W.length<X)W="0"+W;return W}function pX(W){if(typeof W==="string")return Q9(W,"NFKC");return Q7(W)}function M8(W,X){let G=X.match(/^([a-z0-9$_.-]*)(:([a-z]+))?(!)?$/i);a(G!=null,"invalid path","path",X);let Y=G[1],J=G[3],Z=G[4]==="!",V=W;for(let U of Y.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 N in V)if(N.toLowerCase()===U){Q=V[N];break}V=Q}else V=null;if(V==null)break}if(a(!Z||V!=null,"missing required value","path",Y),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 JD(V)}if(J==="array"&&Array.isArray(V))return V;if(J===typeof V)return V;a(!1,`wrong type found for ${J} `,"path",Y)}return V}var F_="m/44'/60'/0'/0/0";function VA(W){try{let X=JSON.parse(W);if((X.version!=null?parseInt(X.version):0)===3)return!0}catch(X){}return!1}function Pt(W,X,G){if(M8(W,"crypto.cipher:string")==="aes-128-ctr"){let J=M8(W,"crypto.cipherparams.iv:data!"),Z=new HW(X,J);return M0(Z.decrypt(G))}Y1(!1,"unsupported cipher","UNSUPPORTED_OPERATION",{operation:"decrypt"})}function ZA(W,X){let G=E0(X),Y=M8(W,"crypto.ciphertext:data!"),J=M0(U8(G8([G.slice(16,32),Y]))).substring(2);a(J===M8(W,"crypto.mac:string!").toLowerCase(),"incorrect password","password","[ REDACTED ]");let Z=Pt(W,G.slice(0,16),Y),V=W6(Z);if(W.address){let N=W.address.toLowerCase();if(!N.startsWith("0x"))N="0x"+N;a(h1(N)===V,"keystore address/privateKey mismatch","address",W.address)}let U={address:V,privateKey:Z};if(M8(W,"x-ethers.version:string")==="0.1"){let N=G.slice(32,64),q=M8(W,"x-ethers.mnemonicCiphertext:data!"),A=M8(W,"x-ethers.mnemonicCounter:data!"),H=new HW(N,A);U.mnemonic={path:M8(W,"x-ethers.path:string")||F_,locale:M8(W,"x-ethers.locale:string")||"en",entropy:M0(E0(H.decrypt(q)))}}return U}function S_(W){let X=M8(W,"crypto.kdf:string");if(X&&typeof X==="string"){if(X.toLowerCase()==="scrypt"){let G=M8(W,"crypto.kdfparams.salt:data!"),Y=M8(W,"crypto.kdfparams.n:int!"),J=M8(W,"crypto.kdfparams.r:int!"),Z=M8(W,"crypto.kdfparams.p:int!");a(Y>0&&(Y&Y-1)===0,"invalid kdf.N","kdf.N",Y),a(J>0&&Z>0,"invalid kdf","kdf",X);let V=M8(W,"crypto.kdfparams.dklen:int!");return a(V===32,"invalid kdf.dklen","kdf.dflen",V),{name:"scrypt",salt:G,N:Y,r:J,p:Z,dkLen:64}}else if(X.toLowerCase()==="pbkdf2"){let G=M8(W,"crypto.kdfparams.salt:data!"),Y=M8(W,"crypto.kdfparams.prf:string!"),J=Y.split("-").pop();a(J==="sha256"||J==="sha512","invalid kdf.pdf","kdf.pdf",Y);let Z=M8(W,"crypto.kdfparams.c:int!"),V=M8(W,"crypto.kdfparams.dklen:int!");return a(V===32,"invalid kdf.dklen","kdf.dklen",V),{name:"pbkdf2",salt:G,count:Z,dkLen:V,algorithm:J}}}a(!1,"unsupported key-derivation function","kdf",X)}function ZD(W,X){let G=JSON.parse(W),Y=pX(X),J=S_(G);if(J.name==="pbkdf2"){let{salt:A,count:H,dkLen:I,algorithm:w}=J,O=x5(Y,A,H,I,w);return ZA(G,O)}Y1(J.name==="scrypt","cannot be reached","UNKNOWN_ERROR",{params:J});let{salt:Z,N:V,r:U,p:Q,dkLen:N}=J,q=QW(Y,Z,V,U,Q,N);return ZA(G,q)}function $_(W){return new Promise((X)=>{setTimeout(()=>{X()},W)})}async function VD(W,X,G){let Y=JSON.parse(W),J=pX(X),Z=S_(Y);if(Z.name==="pbkdf2"){if(G)G(0),await $_(0);let{salt:H,count:I,dkLen:w,algorithm:O}=Z,T=x5(J,H,I,w,O);if(G)G(1),await $_(0);return ZA(Y,T)}Y1(Z.name==="scrypt","cannot be reached","UNKNOWN_ERROR",{params:Z});let{salt:V,N:U,r:Q,p:N,dkLen:q}=Z,A=await UW(J,V,U,Q,N,q,G);return ZA(Y,A)}function x_(W){let X=W.salt!=null?E0(W.salt,"options.salt"):k5(32),G=131072,Y=8,J=1;if(W.scrypt){if(W.scrypt.N)G=W.scrypt.N;if(W.scrypt.r)Y=W.scrypt.r;if(W.scrypt.p)J=W.scrypt.p}return a(typeof G==="number"&&G>0&&Number.isSafeInteger(G)&&(BigInt(G)&BigInt(G-1))===BigInt(0),"invalid scrypt N parameter","options.N",G),a(typeof Y==="number"&&Y>0&&Number.isSafeInteger(Y),"invalid scrypt r parameter","options.r",Y),a(typeof J==="number"&&J>0&&Number.isSafeInteger(J),"invalid scrypt p parameter","options.p",J),{name:"scrypt",dkLen:32,salt:X,N:G,r:Y,p:J}}function k_(W,X,G,Y){let J=E0(G.privateKey,"privateKey"),Z=Y.iv!=null?E0(Y.iv,"options.iv"):k5(16);a(Z.length===16,"invalid options.iv length","options.iv",Y.iv);let V=Y.uuid!=null?E0(Y.uuid,"options.uuid"):k5(16);a(V.length===16,"invalid options.uuid length","options.uuid",Y.iv);let U=W.slice(0,16),Q=W.slice(16,32),N=new HW(U,Z),q=E0(N.encrypt(J)),A=U8(G8([Q,q])),H={address:G.address.substring(2).toLowerCase(),id:xH(V),version:3,Crypto:{cipher:"aes-128-ctr",cipherparams:{iv:M0(Z).substring(2)},ciphertext:M0(q).substring(2),kdf:"scrypt",kdfparams:{salt:M0(X.salt).substring(2),n:X.N,dklen:32,p:X.p,r:X.r},mac:A.substring(2)}};if(G.mnemonic){let I=Y.client!=null?Y.client:`ethers/${MH}`,w=G.mnemonic.path||F_,O=G.mnemonic.locale||"en",T=W.slice(32,64),x=E0(G.mnemonic.entropy,"account.mnemonic.entropy"),h=k5(16),$=new HW(T,h),F=E0($.encrypt(x)),u=new Date,p="UTC--"+(u.getUTCFullYear()+"-"+QJ(u.getUTCMonth()+1,2)+"-"+QJ(u.getUTCDate(),2)+"T"+QJ(u.getUTCHours(),2)+"-"+QJ(u.getUTCMinutes(),2)+"-"+QJ(u.getUTCSeconds(),2)+".0Z")+"--"+H.address;H["x-ethers"]={client:I,gethFilename:p,path:w,locale:O,mnemonicCounter:M0(h).substring(2),mnemonicCiphertext:M0(F).substring(2),version:"0.1"}}return JSON.stringify(H)}function kU(W,X,G){if(G==null)G={};let Y=pX(X),J=x_(G),Z=QW(Y,J.salt,J.N,J.r,J.p,64);return k_(E0(Z),J,W,G)}async function _U(W,X,G){if(G==null)G={};let Y=pX(X),J=x_(G),Z=await UW(Y,J.salt,J.N,J.r,J.p,64,G.progressCallback);return k_(E0(Z),J,W,G)}var yU="m/44'/60'/0'/0/0",Rt=new Uint8Array([66,105,116,99,111,105,110,32,115,101,101,100]),AW=2147483648,Lt=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),Bt="0123456789abcdef";function UA(W,X){let G="";while(W)G=Bt[W%16]+G,W=Math.trunc(W/16);while(G.length<X*2)G="0"+G;return"0x"+G}function UD(W){let X=E0(W),G=aY(E9(E9(X)),0,4),Y=G8([X,G]);return FH(Y)}var t7={};function __(W,X,G,Y){let J=new Uint8Array(37);if(W&AW)Y1(Y!=null,"cannot derive child of neutered node","UNSUPPORTED_OPERATION",{operation:"deriveChild"}),J.set(E0(Y),1);else J.set(E0(G));for(let V=24;V>=0;V-=8)J[33+(V>>3)]=W>>24-V&255;let Z=E0(YW("sha512",X,J));return{IL:Z.slice(0,32),IR:Z.slice(32)}}function y_(W,X){let G=X.split("/");if(a(G.length>0,"invalid path","path",X),G[0]==="m")a(W.depth===0,`cannot derive root path (i.e. path starting with "m/") for a node at non-zero depth ${W.depth}`,"path",X),G.shift();let Y=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));a(V<AW,"invalid path index",`path[${J}]`,Z),Y=Y.deriveChild(AW+V)}else if(Z.match(/^[0-9]+$/)){let V=parseInt(Z);a(V<AW,"invalid path index",`path[${J}]`,Z),Y=Y.deriveChild(V)}else a(!1,"invalid path component",`path[${J}]`,Z)}return Y}class q9 extends mX{publicKey;fingerprint;parentFingerprint;mnemonic;chainCode;path;index;depth;constructor(W,X,G,Y,J,Z,V,U,Q){super(X,Q);n4(W,t7,"HDNodeWallet"),A8(this,{publicKey:X.compressedPublicKey});let N=aY(JW(E9(this.publicKey)),0,4);A8(this,{parentFingerprint:G,fingerprint:N,chainCode:Y,path:J,index:Z,depth:V}),A8(this,{mnemonic:U})}connect(W){return new q9(t7,this.signingKey,this.parentFingerprint,this.chainCode,this.path,this.index,this.depth,this.mnemonic,W)}#W(){let W={address:this.address,privateKey:this.privateKey},X=this.mnemonic;if(this.path&&X&&X.wordlist.locale==="en"&&X.password==="")W.mnemonic={path:this.path,locale:"en",entropy:X.entropy};return W}async encrypt(W,X){return await _U(this.#W(),W,{progressCallback:X})}encryptSync(W){return kU(this.#W(),W)}get extendedKey(){return Y1(this.depth<256,"Depth too deep","UNSUPPORTED_OPERATION",{operation:"extendedKey"}),UD(G8(["0x0488ADE4",UA(this.depth,1),this.parentFingerprint,UA(this.index,4),this.chainCode,G8(["0x00",this.privateKey])]))}hasPath(){return this.path!=null}neuter(){return new cX(t7,this.address,this.publicKey,this.parentFingerprint,this.chainCode,this.path,this.index,this.depth,this.provider)}deriveChild(W){let X=s8(W,"index");a(X<=4294967295,"invalid index","index",X);let G=this.path;if(G){if(G+="/"+(X&~AW),X&AW)G+="'"}let{IR:Y,IL:J}=__(X,this.chainCode,this.publicKey,this.privateKey),Z=new i8(N7((tY(J)+BigInt(this.privateKey))%Lt,32));return new q9(t7,Z,this.fingerprint,M0(Y),G,X,this.depth+1,this.mnemonic,this.provider)}derivePath(W){return y_(this,W)}static#X(W,X){a(r7(W),"invalid seed","seed","[REDACTED]");let G=E0(W,"seed");a(G.length>=16&&G.length<=64,"invalid seed","seed","[REDACTED]");let Y=E0(YW("sha512",Rt,G)),J=new i8(M0(Y.slice(0,32)));return new q9(t7,J,"0x00000000",M0(Y.slice(32)),"m",0,0,X,null)}static fromExtendedKey(W){let X=z8(SH(W));a(X.length===82||UD(X.slice(0,78))===W,"invalid extended key","extendedKey","[ REDACTED ]");let G=X[4],Y=M0(X.slice(5,9)),J=parseInt(M0(X.slice(9,13)).substring(2),16),Z=M0(X.slice(13,45)),V=X.slice(45,78);switch(M0(X.slice(0,4))){case"0x0488b21e":case"0x043587cf":{let U=M0(V);return new cX(t7,W6(U),U,Y,Z,null,J,G,null)}case"0x0488ade4":case"0x04358394 ":if(V[0]!==0)break;return new q9(t7,new i8(V.slice(1)),Y,Z,null,J,G,null,null)}a(!1,"invalid extended key prefix","extendedKey","[ REDACTED ]")}static createRandom(W,X,G){if(W==null)W="";if(X==null)X=yU;if(G==null)G=G6.wordlist();let Y=Y6.fromEntropy(k5(16),W,G);return q9.#X(Y.computeSeed(),Y).derivePath(X)}static fromMnemonic(W,X){if(!X)X=yU;return q9.#X(W.computeSeed(),W).derivePath(X)}static fromPhrase(W,X,G,Y){if(X==null)X="";if(G==null)G=yU;if(Y==null)Y=G6.wordlist();let J=Y6.fromPhrase(W,X,Y);return q9.#X(J.computeSeed(),J).derivePath(G)}static fromSeed(W){return q9.#X(W,null)}}class cX extends EU{publicKey;fingerprint;parentFingerprint;chainCode;path;index;depth;constructor(W,X,G,Y,J,Z,V,U,Q){super(X,Q);n4(W,t7,"HDNodeVoidWallet"),A8(this,{publicKey:G});let N=aY(JW(E9(G)),0,4);A8(this,{publicKey:G,fingerprint:N,parentFingerprint:Y,chainCode:J,path:Z,index:V,depth:U})}connect(W){return new cX(t7,this.address,this.publicKey,this.parentFingerprint,this.chainCode,this.path,this.index,this.depth,W)}get extendedKey(){return Y1(this.depth<256,"Depth too deep","UNSUPPORTED_OPERATION",{operation:"extendedKey"}),UD(G8(["0x0488B21E",UA(this.depth,1),this.parentFingerprint,UA(this.index,4),this.chainCode,this.publicKey]))}hasPath(){return this.path!=null}deriveChild(W){let X=s8(W,"index");a(X<=4294967295,"invalid index","index",X);let G=this.path;if(G){if(G+="/"+(X&~AW),X&AW)G+="'"}let{IR:Y,IL:J}=__(X,this.chainCode,this.publicKey,null),Z=i8.addPoints(J,this.publicKey,!0),V=W6(Z);return new cX(t7,V,Z,this.fingerprint,M0(Y),G,X,this.depth+1,this.provider)}derivePath(W){return y_(this,W)}}function QA(W){try{if(JSON.parse(W).encseed)return!0}catch(X){}return!1}function NA(W,X){let G=JSON.parse(W),Y=pX(X),J=h1(M8(G,"ethaddr:string!")),Z=JD(M8(G,"encseed:string!"));a(Z&&Z.length%16===0,"invalid encseed","json",W);let V=E0(x5(Y,Y,2000,32,"sha256")).slice(0,16),U=Z.slice(0,16),Q=Z.slice(16),N=new SU(V,U),q=YD(E0(N.decrypt(Q))),A="";for(let H=0;H<q.length;H++)A+=String.fromCharCode(q[H]);return{address:J,privateKey:X6(A)}}function v_(W){return new Promise((X)=>{setTimeout(()=>{X()},W)})}class Z6 extends mX{constructor(W,X){if(typeof W==="string"&&!W.startsWith("0x"))W="0x"+W;let G=typeof W==="string"?new i8(W):W;super(G,X)}connect(W){return new Z6(this.signingKey,W)}async encrypt(W,X){let G={address:this.address,privateKey:this.privateKey};return await _U(G,W,{progressCallback:X})}encryptSync(W){let X={address:this.address,privateKey:this.privateKey};return kU(X,W)}static#W(W){if(a(W,"invalid JSON wallet","json","[ REDACTED ]"),"mnemonic"in W&&W.mnemonic&&W.mnemonic.locale==="en"){let G=Y6.fromEntropy(W.mnemonic.entropy),Y=q9.fromMnemonic(G,W.mnemonic.path);if(Y.address===W.address&&Y.privateKey===W.privateKey)return Y;console.log("WARNING: JSON mismatch address/privateKey != mnemonic; fallback onto private key")}let X=new Z6(W.privateKey);return a(X.address===W.address,"address/privateKey mismatch","json","[ REDACTED ]"),X}static async fromEncryptedJson(W,X,G){let Y=null;if(VA(W))Y=await VD(W,X,G);else if(QA(W)){if(G)G(0),await v_(0);if(Y=NA(W,X),G)G(1),await v_(0)}return Z6.#W(Y)}static fromEncryptedJsonSync(W,X){let G=null;if(VA(W))G=ZD(W,X);else if(QA(W))G=NA(W,X);else a(!1,"invalid JSON wallet","json","[ REDACTED ]");return Z6.#W(G)}static createRandom(W){let X=q9.createRandom();if(W)return X.connect(W);return X}static fromPhrase(W,X){let G=q9.fromPhrase(W);if(X)return G.connect(X);return G}}var qA=(W)=>{let X=(G)=>G&&typeof G==="object"&&!Array.isArray(G)?Object.keys(G).sort().reduce((Y,J)=>(Y[J]=X(G[J]),Y),{}):Array.isArray(G)?G.map(X):G;return JSON.stringify(X(W))},Ft=(W,X)=>{try{return h1(RU(Q9(qA(W)),X))}catch{return null}},ND=(W)=>{if(!W?.signature||!W?.originEthAddress||!W?.originUser)return{ok:!1,reason:"missing-fields"};let X;try{if(X=h1(W.originEthAddress),h1(W.originUser)!==X)return{ok:!1,reason:"address-mismatch"}}catch{return{ok:!1,reason:"invalid-address"}}let{signature:G,originEthAddress:Y,base:J,...Z}=W;try{let V=RU(Q9(qA(Z)),G);if(h1(V)!==X)return{ok:!1,reason:"invalid-signature"};let{originUser:U,...Q}=Z;return{ok:!0,normalizedOriginEthAddress:X,payload:J===void 0?Q:{...Q,base:J}}}catch(V){return{ok:!1,reason:"verify-error",error:V}}},g_=({constitution:W=[],customRoles:X=null,getNode:G})=>{let Y=W.map(($)=>{try{return h1($)}catch{return null}}).filter(Boolean),J=X??qD,Z=($,F)=>HD(J,$,F),V=new Map,U=($,F)=>{if(V.size>4096)V.clear();let u=F+JSON.stringify($);if(!V.has(u))V.set(u,Ft($,F));return V.get(u)},Q=($)=>$?.owner??$?._meta?.owner,N=($)=>/^(?:SM_ID_PREFIX_)?(0x[0-9a-fA-F]{40}):/.exec($)?.[1],q=($)=>typeof $==="string"&&$.startsWith("user:"),A=($,F,u)=>$===F||["write","delete"].includes(u?.[$]),H=($,F,u)=>$===F||u?.[$]==="delete",I=($,F)=>$.physical-F.physical||$.logical-F.logical,w=({type:$,id:F,sourceId:u,targetId:l,edges:p,value:s,timestamp:y,originUser:t})=>u?{type:$,sourceId:u,targetId:l,edges:p,timestamp:y,originUser:t}:{type:$,id:F,value:s,timestamp:y,originUser:t},O=($)=>{if(Y.includes($))return"superadmin";let F=G(`user:${$}`)?.value;if(!F?.role)return"guest";return F.expiresAt&&new Date(F.expiresAt).getTime()<Date.now()?"guest":F.role},T=($,F)=>!!$?.sig&&Y.includes($.author)&&U({type:"upsert",id:F,value:$.value,timestamp:$.ts,originUser:$.author},$.sig)===$.author,x=($)=>$?.meta?.role??($?.meta&&{...$.meta,ts:$.meta.ts??$.timestamp}),h=($,F,u)=>[$,x(F)].filter((l)=>T(l,u)).sort((l,p)=>I(p.ts,l.ts))[0];return{op($,F){if(!$?.signature)return!1;let u=U(w($),$.signature);if(!u||u!==$.originUser)return!1;let l=$.sourceId??$.id,p=$.type==="remove"?"delete":$.sourceId?"link":"write";if(q(l)){if(Y.includes(u))return!0;if(p!=="write"||u!==l.slice(5))return!1;if(F&&!Z(O(u),"write"))return!1;let{role:t="guest",expiresAt:H0=null}=h($.receipt,F,l)?.value??{},g=$.value??{};return g.role===t&&(g.expiresAt??null)===H0}if(!Z(O(u),p))return!1;let s=Q(F?.value)??N(l);if(s)return(p==="delete"?H:A)(u,s,F?.value?.collaborators);let y=Q($.value);return!y||u===y},opOf($,F){let u=F.meta??{};return{type:"upsert",id:$,value:u.value??F.value,timestamp:u.ts??F.timestamp,originUser:u.author,originEthAddress:u.author,signature:u.sig,...u.role&&{receipt:u.role}}},edgeOf($,F){let u=F.meta?.edges;return u?{type:u.type,sourceId:$,targetId:u.targetId,edges:F.edges??[],timestamp:u.ts,originUser:u.author,originEthAddress:u.author,signature:u.sig}:null},edgeReceipt($){if(!$?.signature||!Array.isArray($.edges))return null;return{author:U(w($),$.signature),sig:$.signature,ts:$.timestamp,type:$.type,targetId:$.targetId}},edges($,F,u){let l=F.meta?.edges,p=u.meta?.edges;if(!l||p&&I(p.ts,l.ts)>=0)return null;let s=this.edgeOf($,F);return this.op(s,u)?s:null},describe($,F){let u=$?.signature&&U(w($),$.signature);if(!u)return"unsigned or invalid signature";return`${u} as ${O(u)}, owner ${Q(F?.value)??N($.sourceId??$.id)??"none"}`},receipt($,F,u){if(!$?.signature)return null;let l=U(w($),$.signature),p={author:l,sig:$.signature,ts:$.timestamp};if(u.meta?.edges)p.edges=u.meta.edges;if(q($.id)){if(p.value=$.value,!Y.includes(l)){let s=h($.receipt,F,$.id);if(s)p.role=s}}return p}}};function u_(W,X=[]){let G=String(W??"").trim();if(!G)throw Error("sm-server: signing key required (GDB_SM_KEY)");let Y=G.includes(" ")?q9.fromPhrase(G):new Z6(G),J=h1(Y.address),Z=new Set([...X,J].map((Q)=>{try{return h1(Q)}catch{return null}}).filter(Boolean));return{address:J,superAdmins:Z,canonicalize:qA,signOps:async(Q)=>{let N=[];for(let q of Q){if(q?.signature&&q?.originEthAddress&&q?.originUser){N.push(q);continue}let A={...q,originUser:J},H=await Y.signMessage(Q9(qA(A)));N.push({...q,originUser:J,originEthAddress:J,signature:H})}return N},verifyOp:ND,isSuperAdmin:(Q)=>{try{return Z.has(h1(Q))}catch{return!1}}}}var qD={superadmin:{can:["assignRole","deleteAny"],inherits:["admin"]},admin:{can:["delete"],inherits:["manager"]},manager:{can:["publish"],inherits:["user"]},user:{can:["write","link","sync"],inherits:["guest"]},guest:{can:["read","sync"]}},St=Object.keys(qD),HD=(W,X,G,Y=new Set)=>{if(!X||!W[X]||Y.has(X))return!1;if(Y.add(X),W[X].can?.includes(G))return!0;return(W[X].inherits??[]).some((J)=>HD(W,J,G,new Set(Y)))},xt=(W)=>W==="upsert"?"write":W==="remove"?"delete":W==="link"||W==="unlink"?"link":W==="sync"||W==="deltaSync"?"sync":"unknown",QD=(W)=>`${W.slice(0,6)}...${W.slice(-4)}`,h_=({constitution:W=[],customRoles:X=null,getNode:G})=>{let Y=W.map((U)=>{try{return h1(U)}catch{return null}}).filter(Boolean),J=X??qD,Z=(U)=>{let Q=G(`user:${U}`)?.value;if(!Q?.role)return"guest";if(Q.expiresAt&&new Date(Q.expiresAt).getTime()<Date.now())return"guest";return Q.role},V=(U)=>{try{return Y.includes(h1(U??""))}catch{return!1}};return async(U)=>{let Q=[];for(let N of U){if(N?.type==="sync"){Q.push(N);continue}if(N?.type==="fullStateSync"||N?.type==="deltaSync"){if(!(N.signature&&N.originEthAddress&&N.originUser)){Q.push(N);continue}let h=ND(N);if(h.ok)Q.push(h.payload);else console.warn(`\u26A0\uFE0F SM: ${N.type} rejected: ${h.reason}`);continue}let q=ND(N);if(!q.ok){console.warn(`\u26A0\uFE0F SM: invalid signed operation: ${q.reason}`);continue}let{normalizedOriginEthAddress:A,payload:H}=q,I=Y.includes(A)?"superadmin":Z(A),w={...H,signer:A,originUser:N.originUser,originEthAddress:N.originEthAddress,signature:N.signature};if(H.type==="upsert"&&H.id===`user:${A}`&&!G(H.id)){Q.push(w);continue}let{role:O,ethAddress:T}=H.value??{};if(O==="superadmin"&&!V(T)){console.warn(`\u26A0\uFE0F SM: [POLICY] ${QD(A)} tried to assign superadmin to ${QD(String(T??""))}. Blocked.`);continue}let x=xt(H.type);if(HD(J,I,x))Q.push(w);else console.warn(`\u26A0\uFE0F SM: ${QD(A)} (role: ${I}) DENIED ${x}`)}return Q}};function b_(W,X,G,{intervalMs:Y=4000,settleMs:J=15000,customRoles:Z=null}={}){let V=new Set([...St,...Object.keys(Z??{})]),U=async(A,H,I=null)=>{let w=h1(A);if(!V.has(H))throw Error(`Role '${H}' is not a defined role.`);let O=`user:${w}`,T=(await W.get(O)).result?.value||{};await W.put({...T,ethAddress:w,role:H,assignedByEthAddress:X.address,expiresAt:I?new Date(I).toISOString():null,priority:!0},O)},Q=async()=>{let A=new Map;for(let H of G){let I=H.then?.assignRole;if(!I)continue;let w=[];try{({results:w=[]}=W.map({query:H.if}))}catch(O){console.error("\u274C GOVERNANCE: rule evaluation failed:",O.message);continue}for(let O of w){if(!O.id.startsWith("user:"))continue;if(X.isSuperAdmin(O.id.slice(5)))continue;if(H.offsetTimestamp&&(O.timestamp?.physical??0)>Date.now()-H.offsetTimestamp)continue;A.set(O.id,{role:I,current:O.value?.role})}}for(let[H,{role:I,current:w}]of A){if(w===I)continue;try{await U(H.slice(5),I),console.info(`\uD83D\uDCDC GOVERNANCE: ${H.slice(5)} '${w}' -> '${I}'`)}catch(O){console.error("\u274C GOVERNANCE: assignRole failed:",O.message)}}},N=null,q=setTimeout(()=>{N=setInterval(Q,Y),console.info(`\uD83D\uDCDC GOVERNANCE ENGINE: active \u2014 ${G.length} rule(s), every ${Y} ms.`)},J);return{assignRole:U,stop:()=>{if(clearTimeout(q),N)clearInterval(N)}}}var zD=(W)=>W&&typeof W==="object"?structuredClone(W):W,AD=(W,X=16)=>{let G=null,Y=null;return(...J)=>{if(Y??=Promise.withResolvers(),G!==null)clearTimeout(G);return G=setTimeout(async()=>{G=null;try{Y.resolve(await W(...J))}catch(Z){Y.reject(Z)}finally{Y=null}},X),Y.promise}},vt=(W)=>{let X=!1;return()=>{if(X)return;X=!0,setImmediate(()=>{X=!1,W()})}};function gt(W=1000){let X=[];return{add(G){if(G?.timestamp){if(X.push(G),X.length>W)X.splice(0,X.length-W)}},getOldest:()=>X[0]??null,getDelta:(G,Y)=>G?X.filter((J)=>Y(J.timestamp,G)>0):[...X],sign({type:G,id:Y,sourceId:J,timestamp:Z,originUser:V,originEthAddress:U,signature:Q}){let N=X.find((q)=>q.type===G&&(q.id??q.sourceId)===(Y??J)&&q.timestamp?.physical===Z?.physical&&q.timestamp?.logical===Z?.logical);if(N&&Q)Object.assign(N,{originUser:V,originEthAddress:U,signature:Q})},clear(){X=[]},entries:()=>[...X],setEntries(G=[]){if(X=Array.isArray(G)?[...G]:[],X.length>W)X.splice(0,X.length-W)}}}function ut(){let W={nodes:{}};return{get nodes(){return W.nodes},set nodes(X){W.nodes=X??{}},upsert(X,G,Y){let J=W.nodes[X];W.nodes[X]={id:X,value:zD(G),edges:J?.edges?[...J.edges]:[],timestamp:Y,...J?.meta&&{meta:J.meta}}},get:(X)=>W.nodes[X]??null,link(X,G,Y){let J=W.nodes[X],Z=W.nodes[G];if(J&&Z&&!J.edges.includes(G))W.nodes[X]={...J,edges:[...J.edges,G],timestamp:Y}},unlink(X,G,Y){let J=W.nodes[X];if(J?.edges.includes(G))W.nodes[X]={...J,edges:J.edges.filter((Z)=>Z!==G),timestamp:Y}},getAllNodes:()=>Object.values(W.nodes),serialize:()=>GG.deflate(bU(W.nodes)),deserialize(X){let G=X instanceof Uint8Array?X:new Uint8Array(X);W.nodes=zW(GG.inflate(G))}}}function ht(W,X){let G=yt(W);if(G&&G!==".")_t(G,{recursive:!0});let Y=new kt(W);Y.exec("PRAGMA journal_mode = WAL"),Y.exec("PRAGMA synchronous = NORMAL"),Y.exec(`
251
+ `)!==this.#X)throw Error(`BIP39 Wordlist for ${this.locale} FAILED`);this.#G=W}return this.#G}getWord(W){let X=this.#Y();return a(W>=0&&W<X.length,`invalid word index: ${W}`,"index",W),X[W]}getWordIndex(W){return this.#Y().indexOf(W)}}var Vt="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",Ut="0x3c8acc1e7b08d8e76f9fda015ef48dc8c710a73cb7e0f77b2c18a9b5a7adde60",sO=null;class G6 extends aO{constructor(){super("en",Vt,Ut)}static wordlist(){if(sO==null)sO=new G6;return sO}}function E_(W){return(1<<W)-1<<8-W&255}function Qt(W){return(1<<W)-1&255}function tO(W,X){if(rY("NFKD"),X==null)X=G6.wordlist();let G=X.split(W);a(G.length%3===0&&G.length>=12&&G.length<=24,"invalid mnemonic length","mnemonic","[ REDACTED ]");let Y=new Uint8Array(Math.ceil(11*G.length/8)),J=0;for(let N=0;N<G.length;N++){let q=X.getWordIndex(G[N].normalize("NFKD"));a(q>=0,`invalid mnemonic word at index ${N}`,"mnemonic","[ REDACTED ]");for(let A=0;A<11;A++){if(q&1<<10-A)Y[J>>3]|=1<<7-J%8;J++}}let Z=32*G.length/3,V=G.length/3,U=E_(V),Q=E0(E9(Y.slice(0,Z/8)))[0]&U;return a(Q===(Y[Y.length-1]&U),"invalid mnemonic checksum","mnemonic","[ REDACTED ]"),M0(Y.slice(0,Z/8))}function eO(W,X){if(a(W.length%4===0&&W.length>=16&&W.length<=32,"invalid entropy size","entropy","[ REDACTED ]"),X==null)X=G6.wordlist();let G=[0],Y=11;for(let V=0;V<W.length;V++)if(Y>8)G[G.length-1]<<=8,G[G.length-1]|=W[V],Y-=8;else G[G.length-1]<<=Y,G[G.length-1]|=W[V]>>8-Y,G.push(W[V]&Qt(8-Y)),Y+=3;let J=W.length/4,Z=parseInt(E9(W).substring(2,4),16)&E_(J);return G[G.length-1]<<=J,G[G.length-1]|=Z>>8-J,X.join(G.map((V)=>X.getWord(V)))}var WD={};class Y6{phrase;password;wordlist;entropy;constructor(W,X,G,Y,J){if(Y==null)Y="";if(J==null)J=G6.wordlist();n4(W,WD,"Mnemonic"),A8(this,{phrase:G,password:Y,wordlist:J,entropy:X})}computeSeed(){let W=Q9("mnemonic"+this.password,"NFKD");return x5(Q9(this.phrase,"NFKD"),W,2048,64,"sha512")}static fromPhrase(W,X,G){let Y=tO(W,G);return W=eO(E0(Y),G),new Y6(WD,Y,W,X,G)}static fromEntropy(W,X,G){let Y=E0(W,"entropy"),J=eO(Y,G);return new Y6(WD,M0(Y),J,X,G)}static entropyToPhrase(W,X){let G=E0(W,"entropy");return eO(G,X)}static phraseToEntropy(W,X){return tO(W,X)}static isValidMnemonic(W,X){try{return tO(W,X),!0}catch(G){}return!1}}/*! MIT License. Copyright 2015-2022 Richard Moore <me@ricmoo.com>. See LICENSE.txt. */var N9=function(W,X,G,Y){if(G==="a"&&!Y)throw TypeError("Private accessor was defined without a getter");if(typeof X==="function"?W!==X||!Y:!X.has(W))throw TypeError("Cannot read private member from an object whose class did not declare it");return G==="m"?Y:G==="a"?Y.call(W):Y?Y.value:X.get(W)},XD=function(W,X,G,Y,J){if(Y==="m")throw TypeError("Private method is not writable");if(Y==="a"&&!J)throw TypeError("Private accessor was defined without a setter");if(typeof X==="function"?W!==X||!J:!X.has(W))throw TypeError("Cannot write private member to an object whose class did not declare it");return Y==="a"?J.call(W,G):J?J.value=G:X.set(W,G),G},GA,v5,s7,Nt={16:10,24:12,32:14},qt=[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],y5=[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],XA=[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],Ht=[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],At=[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],zt=[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],It=[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],wt=[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],jt=[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],Kt=[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],Ot=[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],Dt=[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],Ct=[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],Tt=[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],Mt=[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 GD(W){let X=[];for(let G=0;G<W.length;G+=4)X.push(W[G]<<24|W[G+1]<<16|W[G+2]<<8|W[G+3]);return X}class YA{get key(){return N9(this,GA,"f").slice()}constructor(W){if(GA.set(this,void 0),v5.set(this,void 0),s7.set(this,void 0),!(this instanceof YA))throw Error("AES must be instanitated with `new`");XD(this,GA,new Uint8Array(W),"f");let X=Nt[this.key.length];if(X==null)throw TypeError("invalid key size (must be 16, 24 or 32 bytes)");XD(this,s7,[],"f"),XD(this,v5,[],"f");for(let N=0;N<=X;N++)N9(this,s7,"f").push([0,0,0,0]),N9(this,v5,"f").push([0,0,0,0]);let G=(X+1)*4,Y=this.key.length/4,J=GD(this.key),Z;for(let N=0;N<Y;N++)Z=N>>2,N9(this,s7,"f")[Z][N%4]=J[N],N9(this,v5,"f")[X-Z][N%4]=J[N];let V=0,U=Y,Q;while(U<G){if(Q=J[Y-1],J[0]^=y5[Q>>16&255]<<24^y5[Q>>8&255]<<16^y5[Q&255]<<8^y5[Q>>24&255]^qt[V]<<24,V+=1,Y!=8)for(let H=1;H<Y;H++)J[H]^=J[H-1];else{for(let H=1;H<Y/2;H++)J[H]^=J[H-1];Q=J[Y/2-1],J[Y/2]^=y5[Q&255]^y5[Q>>8&255]<<8^y5[Q>>16&255]<<16^y5[Q>>24&255]<<24;for(let H=Y/2+1;H<Y;H++)J[H]^=J[H-1]}let N=0,q,A;while(N<Y&&U<G)q=U>>2,A=U%4,N9(this,s7,"f")[q][A]=J[N],N9(this,v5,"f")[X-q][A]=J[N++],U++}for(let N=1;N<X;N++)for(let q=0;q<4;q++)Q=N9(this,v5,"f")[N][q],N9(this,v5,"f")[N][q]=Dt[Q>>24&255]^Ct[Q>>16&255]^Tt[Q>>8&255]^Mt[Q&255]}encrypt(W){if(W.length!=16)throw TypeError("invalid plaintext size (must be 16 bytes)");let X=N9(this,s7,"f").length-1,G=[0,0,0,0],Y=GD(W);for(let V=0;V<4;V++)Y[V]^=N9(this,s7,"f")[0][V];for(let V=1;V<X;V++){for(let U=0;U<4;U++)G[U]=Ht[Y[U]>>24&255]^At[Y[(U+1)%4]>>16&255]^zt[Y[(U+2)%4]>>8&255]^It[Y[(U+3)%4]&255]^N9(this,s7,"f")[V][U];Y=G.slice()}let J=new Uint8Array(16),Z=0;for(let V=0;V<4;V++)Z=N9(this,s7,"f")[X][V],J[4*V]=(y5[Y[V]>>24&255]^Z>>24)&255,J[4*V+1]=(y5[Y[(V+1)%4]>>16&255]^Z>>16)&255,J[4*V+2]=(y5[Y[(V+2)%4]>>8&255]^Z>>8)&255,J[4*V+3]=(y5[Y[(V+3)%4]&255]^Z)&255;return J}decrypt(W){if(W.length!=16)throw TypeError("invalid ciphertext size (must be 16 bytes)");let X=N9(this,v5,"f").length-1,G=[0,0,0,0],Y=GD(W);for(let V=0;V<4;V++)Y[V]^=N9(this,v5,"f")[0][V];for(let V=1;V<X;V++){for(let U=0;U<4;U++)G[U]=wt[Y[U]>>24&255]^jt[Y[(U+3)%4]>>16&255]^Kt[Y[(U+2)%4]>>8&255]^Ot[Y[(U+1)%4]&255]^N9(this,v5,"f")[V][U];Y=G.slice()}let J=new Uint8Array(16),Z=0;for(let V=0;V<4;V++)Z=N9(this,v5,"f")[X][V],J[4*V]=(XA[Y[V]>>24&255]^Z>>24)&255,J[4*V+1]=(XA[Y[(V+3)%4]>>16&255]^Z>>16)&255,J[4*V+2]=(XA[Y[(V+2)%4]>>8&255]^Z>>8)&255,J[4*V+3]=(XA[Y[(V+1)%4]&255]^Z)&255;return J}}GA=new WeakMap,v5=new WeakMap,s7=new WeakMap;class $U{constructor(W,X,G){if(G&&!(this instanceof G))throw Error(`${W} must be instantiated with "new"`);Object.defineProperties(this,{aes:{enumerable:!0,value:new YA(X)},name:{enumerable:!0,value:W}})}}var JA=function(W,X,G,Y,J){if(Y==="m")throw TypeError("Private method is not writable");if(Y==="a"&&!J)throw TypeError("Private accessor was defined without a setter");if(typeof X==="function"?W!==X||!J:!X.has(W))throw TypeError("Cannot write private member to an object whose class did not declare it");return Y==="a"?J.call(W,G):J?J.value=G:X.set(W,G),G},VJ=function(W,X,G,Y){if(G==="a"&&!Y)throw TypeError("Private accessor was defined without a getter");if(typeof X==="function"?W!==X||!Y:!X.has(W))throw TypeError("Cannot read private member from an object whose class did not declare it");return G==="m"?Y:G==="a"?Y.call(W):Y?Y.value:X.get(W)},FU,J6;class SU extends $U{constructor(W,X){super("ECC",W,SU);if(FU.set(this,void 0),J6.set(this,void 0),X){if(X.length%16)throw TypeError("invalid iv size (must be 16 bytes)");JA(this,FU,new Uint8Array(X),"f")}else JA(this,FU,new Uint8Array(16),"f");JA(this,J6,this.iv,"f")}get iv(){return new Uint8Array(VJ(this,FU,"f"))}encrypt(W){if(W.length%16)throw TypeError("invalid plaintext size (must be multiple of 16 bytes)");let X=new Uint8Array(W.length);for(let G=0;G<W.length;G+=16){for(let Y=0;Y<16;Y++)VJ(this,J6,"f")[Y]^=W[G+Y];JA(this,J6,this.aes.encrypt(VJ(this,J6,"f")),"f"),X.set(VJ(this,J6,"f"),G)}return X}decrypt(W){if(W.length%16)throw TypeError("invalid ciphertext size (must be multiple of 16 bytes)");let X=new Uint8Array(W.length);for(let G=0;G<W.length;G+=16){let Y=this.aes.decrypt(W.subarray(G,G+16));for(let J=0;J<16;J++)X[G+J]=Y[J]^VJ(this,J6,"f")[J],VJ(this,J6,"f")[J]=W[G+J]}return X}}FU=new WeakMap,J6=new WeakMap;var UJ=function(W,X,G,Y,J){if(Y==="m")throw TypeError("Private method is not writable");if(Y==="a"&&!J)throw TypeError("Private accessor was defined without a setter");if(typeof X==="function"?W!==X||!J:!X.has(W))throw TypeError("Cannot write private member to an object whose class did not declare it");return Y==="a"?J.call(W,G):J?J.value=G:X.set(W,G),G},g5=function(W,X,G,Y){if(G==="a"&&!Y)throw TypeError("Private accessor was defined without a getter");if(typeof X==="function"?W!==X||!Y:!X.has(W))throw TypeError("Cannot read private member from an object whose class did not declare it");return G==="m"?Y:G==="a"?Y.call(W):Y?Y.value:X.get(W)},xU,fX,u5;class HW extends $U{constructor(W,X){super("CTR",W,HW);if(xU.set(this,void 0),fX.set(this,void 0),u5.set(this,void 0),UJ(this,u5,new Uint8Array(16),"f"),g5(this,u5,"f").fill(0),UJ(this,xU,g5(this,u5,"f"),"f"),UJ(this,fX,16,"f"),X==null)X=1;if(typeof X==="number")this.setCounterValue(X);else this.setCounterBytes(X)}get counter(){return new Uint8Array(g5(this,u5,"f"))}setCounterValue(W){if(!Number.isInteger(W)||W<0||W>Number.MAX_SAFE_INTEGER)throw TypeError("invalid counter initial integer value");for(let X=15;X>=0;--X)g5(this,u5,"f")[X]=W%256,W=Math.floor(W/256)}setCounterBytes(W){if(W.length!==16)throw TypeError("invalid counter initial Uint8Array value length");g5(this,u5,"f").set(W)}increment(){for(let W=15;W>=0;W--)if(g5(this,u5,"f")[W]===255)g5(this,u5,"f")[W]=0;else{g5(this,u5,"f")[W]++;break}}encrypt(W){var X,G;let Y=new Uint8Array(W);for(let J=0;J<Y.length;J++){if(g5(this,fX,"f")===16)UJ(this,xU,this.aes.encrypt(g5(this,u5,"f")),"f"),UJ(this,fX,0,"f"),this.increment();Y[J]^=g5(this,xU,"f")[UJ(this,fX,(G=g5(this,fX,"f"),X=G++,G),"f"),X]}return Y}decrypt(W){return this.encrypt(W)}}xU=new WeakMap,fX=new WeakMap,u5=new WeakMap;function YD(W){if(W.length<16)throw TypeError("PKCS#7 invalid length");let X=W[W.length-1];if(X>16)throw TypeError("PKCS#7 padding byte out of range");let G=W.length-X;for(let Y=0;Y<X;Y++)if(W[G+Y]!==X)throw TypeError("PKCS#7 invalid padding byte");return new Uint8Array(W.subarray(0,G))}function JD(W){if(typeof W==="string"&&!W.startsWith("0x"))W="0x"+W;return Q7(W)}function QJ(W,X){W=String(W);while(W.length<X)W="0"+W;return W}function pX(W){if(typeof W==="string")return Q9(W,"NFKC");return Q7(W)}function M8(W,X){let G=X.match(/^([a-z0-9$_.-]*)(:([a-z]+))?(!)?$/i);a(G!=null,"invalid path","path",X);let Y=G[1],J=G[3],Z=G[4]==="!",V=W;for(let U of Y.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 N in V)if(N.toLowerCase()===U){Q=V[N];break}V=Q}else V=null;if(V==null)break}if(a(!Z||V!=null,"missing required value","path",Y),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 JD(V)}if(J==="array"&&Array.isArray(V))return V;if(J===typeof V)return V;a(!1,`wrong type found for ${J} `,"path",Y)}return V}var F_="m/44'/60'/0'/0/0";function VA(W){try{let X=JSON.parse(W);if((X.version!=null?parseInt(X.version):0)===3)return!0}catch(X){}return!1}function Pt(W,X,G){if(M8(W,"crypto.cipher:string")==="aes-128-ctr"){let J=M8(W,"crypto.cipherparams.iv:data!"),Z=new HW(X,J);return M0(Z.decrypt(G))}Y1(!1,"unsupported cipher","UNSUPPORTED_OPERATION",{operation:"decrypt"})}function ZA(W,X){let G=E0(X),Y=M8(W,"crypto.ciphertext:data!"),J=M0(U8(G8([G.slice(16,32),Y]))).substring(2);a(J===M8(W,"crypto.mac:string!").toLowerCase(),"incorrect password","password","[ REDACTED ]");let Z=Pt(W,G.slice(0,16),Y),V=W6(Z);if(W.address){let N=W.address.toLowerCase();if(!N.startsWith("0x"))N="0x"+N;a(h1(N)===V,"keystore address/privateKey mismatch","address",W.address)}let U={address:V,privateKey:Z};if(M8(W,"x-ethers.version:string")==="0.1"){let N=G.slice(32,64),q=M8(W,"x-ethers.mnemonicCiphertext:data!"),A=M8(W,"x-ethers.mnemonicCounter:data!"),H=new HW(N,A);U.mnemonic={path:M8(W,"x-ethers.path:string")||F_,locale:M8(W,"x-ethers.locale:string")||"en",entropy:M0(E0(H.decrypt(q)))}}return U}function S_(W){let X=M8(W,"crypto.kdf:string");if(X&&typeof X==="string"){if(X.toLowerCase()==="scrypt"){let G=M8(W,"crypto.kdfparams.salt:data!"),Y=M8(W,"crypto.kdfparams.n:int!"),J=M8(W,"crypto.kdfparams.r:int!"),Z=M8(W,"crypto.kdfparams.p:int!");a(Y>0&&(Y&Y-1)===0,"invalid kdf.N","kdf.N",Y),a(J>0&&Z>0,"invalid kdf","kdf",X);let V=M8(W,"crypto.kdfparams.dklen:int!");return a(V===32,"invalid kdf.dklen","kdf.dflen",V),{name:"scrypt",salt:G,N:Y,r:J,p:Z,dkLen:64}}else if(X.toLowerCase()==="pbkdf2"){let G=M8(W,"crypto.kdfparams.salt:data!"),Y=M8(W,"crypto.kdfparams.prf:string!"),J=Y.split("-").pop();a(J==="sha256"||J==="sha512","invalid kdf.pdf","kdf.pdf",Y);let Z=M8(W,"crypto.kdfparams.c:int!"),V=M8(W,"crypto.kdfparams.dklen:int!");return a(V===32,"invalid kdf.dklen","kdf.dklen",V),{name:"pbkdf2",salt:G,count:Z,dkLen:V,algorithm:J}}}a(!1,"unsupported key-derivation function","kdf",X)}function ZD(W,X){let G=JSON.parse(W),Y=pX(X),J=S_(G);if(J.name==="pbkdf2"){let{salt:A,count:H,dkLen:I,algorithm:w}=J,O=x5(Y,A,H,I,w);return ZA(G,O)}Y1(J.name==="scrypt","cannot be reached","UNKNOWN_ERROR",{params:J});let{salt:Z,N:V,r:U,p:Q,dkLen:N}=J,q=QW(Y,Z,V,U,Q,N);return ZA(G,q)}function $_(W){return new Promise((X)=>{setTimeout(()=>{X()},W)})}async function VD(W,X,G){let Y=JSON.parse(W),J=pX(X),Z=S_(Y);if(Z.name==="pbkdf2"){if(G)G(0),await $_(0);let{salt:H,count:I,dkLen:w,algorithm:O}=Z,T=x5(J,H,I,w,O);if(G)G(1),await $_(0);return ZA(Y,T)}Y1(Z.name==="scrypt","cannot be reached","UNKNOWN_ERROR",{params:Z});let{salt:V,N:U,r:Q,p:N,dkLen:q}=Z,A=await UW(J,V,U,Q,N,q,G);return ZA(Y,A)}function x_(W){let X=W.salt!=null?E0(W.salt,"options.salt"):k5(32),G=131072,Y=8,J=1;if(W.scrypt){if(W.scrypt.N)G=W.scrypt.N;if(W.scrypt.r)Y=W.scrypt.r;if(W.scrypt.p)J=W.scrypt.p}return a(typeof G==="number"&&G>0&&Number.isSafeInteger(G)&&(BigInt(G)&BigInt(G-1))===BigInt(0),"invalid scrypt N parameter","options.N",G),a(typeof Y==="number"&&Y>0&&Number.isSafeInteger(Y),"invalid scrypt r parameter","options.r",Y),a(typeof J==="number"&&J>0&&Number.isSafeInteger(J),"invalid scrypt p parameter","options.p",J),{name:"scrypt",dkLen:32,salt:X,N:G,r:Y,p:J}}function k_(W,X,G,Y){let J=E0(G.privateKey,"privateKey"),Z=Y.iv!=null?E0(Y.iv,"options.iv"):k5(16);a(Z.length===16,"invalid options.iv length","options.iv",Y.iv);let V=Y.uuid!=null?E0(Y.uuid,"options.uuid"):k5(16);a(V.length===16,"invalid options.uuid length","options.uuid",Y.iv);let U=W.slice(0,16),Q=W.slice(16,32),N=new HW(U,Z),q=E0(N.encrypt(J)),A=U8(G8([Q,q])),H={address:G.address.substring(2).toLowerCase(),id:xH(V),version:3,Crypto:{cipher:"aes-128-ctr",cipherparams:{iv:M0(Z).substring(2)},ciphertext:M0(q).substring(2),kdf:"scrypt",kdfparams:{salt:M0(X.salt).substring(2),n:X.N,dklen:32,p:X.p,r:X.r},mac:A.substring(2)}};if(G.mnemonic){let I=Y.client!=null?Y.client:`ethers/${MH}`,w=G.mnemonic.path||F_,O=G.mnemonic.locale||"en",T=W.slice(32,64),x=E0(G.mnemonic.entropy,"account.mnemonic.entropy"),h=k5(16),$=new HW(T,h),F=E0($.encrypt(x)),u=new Date,f="UTC--"+(u.getUTCFullYear()+"-"+QJ(u.getUTCMonth()+1,2)+"-"+QJ(u.getUTCDate(),2)+"T"+QJ(u.getUTCHours(),2)+"-"+QJ(u.getUTCMinutes(),2)+"-"+QJ(u.getUTCSeconds(),2)+".0Z")+"--"+H.address;H["x-ethers"]={client:I,gethFilename:f,path:w,locale:O,mnemonicCounter:M0(h).substring(2),mnemonicCiphertext:M0(F).substring(2),version:"0.1"}}return JSON.stringify(H)}function kU(W,X,G){if(G==null)G={};let Y=pX(X),J=x_(G),Z=QW(Y,J.salt,J.N,J.r,J.p,64);return k_(E0(Z),J,W,G)}async function _U(W,X,G){if(G==null)G={};let Y=pX(X),J=x_(G),Z=await UW(Y,J.salt,J.N,J.r,J.p,64,G.progressCallback);return k_(E0(Z),J,W,G)}var yU="m/44'/60'/0'/0/0",Rt=new Uint8Array([66,105,116,99,111,105,110,32,115,101,101,100]),AW=2147483648,Lt=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),Bt="0123456789abcdef";function UA(W,X){let G="";while(W)G=Bt[W%16]+G,W=Math.trunc(W/16);while(G.length<X*2)G="0"+G;return"0x"+G}function UD(W){let X=E0(W),G=aY(E9(E9(X)),0,4),Y=G8([X,G]);return FH(Y)}var t7={};function __(W,X,G,Y){let J=new Uint8Array(37);if(W&AW)Y1(Y!=null,"cannot derive child of neutered node","UNSUPPORTED_OPERATION",{operation:"deriveChild"}),J.set(E0(Y),1);else J.set(E0(G));for(let V=24;V>=0;V-=8)J[33+(V>>3)]=W>>24-V&255;let Z=E0(YW("sha512",X,J));return{IL:Z.slice(0,32),IR:Z.slice(32)}}function y_(W,X){let G=X.split("/");if(a(G.length>0,"invalid path","path",X),G[0]==="m")a(W.depth===0,`cannot derive root path (i.e. path starting with "m/") for a node at non-zero depth ${W.depth}`,"path",X),G.shift();let Y=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));a(V<AW,"invalid path index",`path[${J}]`,Z),Y=Y.deriveChild(AW+V)}else if(Z.match(/^[0-9]+$/)){let V=parseInt(Z);a(V<AW,"invalid path index",`path[${J}]`,Z),Y=Y.deriveChild(V)}else a(!1,"invalid path component",`path[${J}]`,Z)}return Y}class q9 extends mX{publicKey;fingerprint;parentFingerprint;mnemonic;chainCode;path;index;depth;constructor(W,X,G,Y,J,Z,V,U,Q){super(X,Q);n4(W,t7,"HDNodeWallet"),A8(this,{publicKey:X.compressedPublicKey});let N=aY(JW(E9(this.publicKey)),0,4);A8(this,{parentFingerprint:G,fingerprint:N,chainCode:Y,path:J,index:Z,depth:V}),A8(this,{mnemonic:U})}connect(W){return new q9(t7,this.signingKey,this.parentFingerprint,this.chainCode,this.path,this.index,this.depth,this.mnemonic,W)}#W(){let W={address:this.address,privateKey:this.privateKey},X=this.mnemonic;if(this.path&&X&&X.wordlist.locale==="en"&&X.password==="")W.mnemonic={path:this.path,locale:"en",entropy:X.entropy};return W}async encrypt(W,X){return await _U(this.#W(),W,{progressCallback:X})}encryptSync(W){return kU(this.#W(),W)}get extendedKey(){return Y1(this.depth<256,"Depth too deep","UNSUPPORTED_OPERATION",{operation:"extendedKey"}),UD(G8(["0x0488ADE4",UA(this.depth,1),this.parentFingerprint,UA(this.index,4),this.chainCode,G8(["0x00",this.privateKey])]))}hasPath(){return this.path!=null}neuter(){return new cX(t7,this.address,this.publicKey,this.parentFingerprint,this.chainCode,this.path,this.index,this.depth,this.provider)}deriveChild(W){let X=s8(W,"index");a(X<=4294967295,"invalid index","index",X);let G=this.path;if(G){if(G+="/"+(X&~AW),X&AW)G+="'"}let{IR:Y,IL:J}=__(X,this.chainCode,this.publicKey,this.privateKey),Z=new i8(N7((tY(J)+BigInt(this.privateKey))%Lt,32));return new q9(t7,Z,this.fingerprint,M0(Y),G,X,this.depth+1,this.mnemonic,this.provider)}derivePath(W){return y_(this,W)}static#X(W,X){a(r7(W),"invalid seed","seed","[REDACTED]");let G=E0(W,"seed");a(G.length>=16&&G.length<=64,"invalid seed","seed","[REDACTED]");let Y=E0(YW("sha512",Rt,G)),J=new i8(M0(Y.slice(0,32)));return new q9(t7,J,"0x00000000",M0(Y.slice(32)),"m",0,0,X,null)}static fromExtendedKey(W){let X=z8(SH(W));a(X.length===82||UD(X.slice(0,78))===W,"invalid extended key","extendedKey","[ REDACTED ]");let G=X[4],Y=M0(X.slice(5,9)),J=parseInt(M0(X.slice(9,13)).substring(2),16),Z=M0(X.slice(13,45)),V=X.slice(45,78);switch(M0(X.slice(0,4))){case"0x0488b21e":case"0x043587cf":{let U=M0(V);return new cX(t7,W6(U),U,Y,Z,null,J,G,null)}case"0x0488ade4":case"0x04358394 ":if(V[0]!==0)break;return new q9(t7,new i8(V.slice(1)),Y,Z,null,J,G,null,null)}a(!1,"invalid extended key prefix","extendedKey","[ REDACTED ]")}static createRandom(W,X,G){if(W==null)W="";if(X==null)X=yU;if(G==null)G=G6.wordlist();let Y=Y6.fromEntropy(k5(16),W,G);return q9.#X(Y.computeSeed(),Y).derivePath(X)}static fromMnemonic(W,X){if(!X)X=yU;return q9.#X(W.computeSeed(),W).derivePath(X)}static fromPhrase(W,X,G,Y){if(X==null)X="";if(G==null)G=yU;if(Y==null)Y=G6.wordlist();let J=Y6.fromPhrase(W,X,Y);return q9.#X(J.computeSeed(),J).derivePath(G)}static fromSeed(W){return q9.#X(W,null)}}class cX extends EU{publicKey;fingerprint;parentFingerprint;chainCode;path;index;depth;constructor(W,X,G,Y,J,Z,V,U,Q){super(X,Q);n4(W,t7,"HDNodeVoidWallet"),A8(this,{publicKey:G});let N=aY(JW(E9(G)),0,4);A8(this,{publicKey:G,fingerprint:N,parentFingerprint:Y,chainCode:J,path:Z,index:V,depth:U})}connect(W){return new cX(t7,this.address,this.publicKey,this.parentFingerprint,this.chainCode,this.path,this.index,this.depth,W)}get extendedKey(){return Y1(this.depth<256,"Depth too deep","UNSUPPORTED_OPERATION",{operation:"extendedKey"}),UD(G8(["0x0488B21E",UA(this.depth,1),this.parentFingerprint,UA(this.index,4),this.chainCode,this.publicKey]))}hasPath(){return this.path!=null}deriveChild(W){let X=s8(W,"index");a(X<=4294967295,"invalid index","index",X);let G=this.path;if(G){if(G+="/"+(X&~AW),X&AW)G+="'"}let{IR:Y,IL:J}=__(X,this.chainCode,this.publicKey,null),Z=i8.addPoints(J,this.publicKey,!0),V=W6(Z);return new cX(t7,V,Z,this.fingerprint,M0(Y),G,X,this.depth+1,this.provider)}derivePath(W){return y_(this,W)}}function QA(W){try{if(JSON.parse(W).encseed)return!0}catch(X){}return!1}function NA(W,X){let G=JSON.parse(W),Y=pX(X),J=h1(M8(G,"ethaddr:string!")),Z=JD(M8(G,"encseed:string!"));a(Z&&Z.length%16===0,"invalid encseed","json",W);let V=E0(x5(Y,Y,2000,32,"sha256")).slice(0,16),U=Z.slice(0,16),Q=Z.slice(16),N=new SU(V,U),q=YD(E0(N.decrypt(Q))),A="";for(let H=0;H<q.length;H++)A+=String.fromCharCode(q[H]);return{address:J,privateKey:X6(A)}}function v_(W){return new Promise((X)=>{setTimeout(()=>{X()},W)})}class Z6 extends mX{constructor(W,X){if(typeof W==="string"&&!W.startsWith("0x"))W="0x"+W;let G=typeof W==="string"?new i8(W):W;super(G,X)}connect(W){return new Z6(this.signingKey,W)}async encrypt(W,X){let G={address:this.address,privateKey:this.privateKey};return await _U(G,W,{progressCallback:X})}encryptSync(W){let X={address:this.address,privateKey:this.privateKey};return kU(X,W)}static#W(W){if(a(W,"invalid JSON wallet","json","[ REDACTED ]"),"mnemonic"in W&&W.mnemonic&&W.mnemonic.locale==="en"){let G=Y6.fromEntropy(W.mnemonic.entropy),Y=q9.fromMnemonic(G,W.mnemonic.path);if(Y.address===W.address&&Y.privateKey===W.privateKey)return Y;console.log("WARNING: JSON mismatch address/privateKey != mnemonic; fallback onto private key")}let X=new Z6(W.privateKey);return a(X.address===W.address,"address/privateKey mismatch","json","[ REDACTED ]"),X}static async fromEncryptedJson(W,X,G){let Y=null;if(VA(W))Y=await VD(W,X,G);else if(QA(W)){if(G)G(0),await v_(0);if(Y=NA(W,X),G)G(1),await v_(0)}return Z6.#W(Y)}static fromEncryptedJsonSync(W,X){let G=null;if(VA(W))G=ZD(W,X);else if(QA(W))G=NA(W,X);else a(!1,"invalid JSON wallet","json","[ REDACTED ]");return Z6.#W(G)}static createRandom(W){let X=q9.createRandom();if(W)return X.connect(W);return X}static fromPhrase(W,X){let G=q9.fromPhrase(W);if(X)return G.connect(X);return G}}var qA=(W)=>{let X=(G)=>G&&typeof G==="object"&&!Array.isArray(G)?Object.keys(G).sort().reduce((Y,J)=>(Y[J]=X(G[J]),Y),{}):Array.isArray(G)?G.map(X):G;return JSON.stringify(X(W))},Ft=(W,X)=>{try{return h1(RU(Q9(qA(W)),X))}catch{return null}},ND=(W)=>{if(!W?.signature||!W?.originEthAddress||!W?.originUser)return{ok:!1,reason:"missing-fields"};let X;try{if(X=h1(W.originEthAddress),h1(W.originUser)!==X)return{ok:!1,reason:"address-mismatch"}}catch{return{ok:!1,reason:"invalid-address"}}let{signature:G,originEthAddress:Y,base:J,...Z}=W;try{let V=RU(Q9(qA(Z)),G);if(h1(V)!==X)return{ok:!1,reason:"invalid-signature"};let{originUser:U,...Q}=Z;return{ok:!0,normalizedOriginEthAddress:X,payload:J===void 0?Q:{...Q,base:J}}}catch(V){return{ok:!1,reason:"verify-error",error:V}}},g_=({constitution:W=[],customRoles:X=null,getNode:G})=>{let Y=W.map(($)=>{try{return h1($)}catch{return null}}).filter(Boolean),J=X??qD,Z=($,F)=>HD(J,$,F),V=new Map,U=($,F)=>{if(V.size>4096)V.clear();let u=F+JSON.stringify($);if(!V.has(u))V.set(u,Ft($,F));return V.get(u)},Q=($)=>$?.owner??$?._meta?.owner,N=($)=>/^(?:SM_ID_PREFIX_)?(0x[0-9a-fA-F]{40}):/.exec($)?.[1],q=($)=>typeof $==="string"&&$.startsWith("user:"),A=($,F,u)=>$===F||["write","delete"].includes(u?.[$]),H=($,F,u)=>$===F||u?.[$]==="delete",I=($,F)=>$.physical-F.physical||$.logical-F.logical,w=({type:$,id:F,sourceId:u,targetId:l,edges:f,value:s,timestamp:y,originUser:t})=>u?{type:$,sourceId:u,targetId:l,edges:f,timestamp:y,originUser:t}:{type:$,id:F,value:s,timestamp:y,originUser:t},O=($)=>{if(Y.includes($))return"superadmin";let F=G(`user:${$}`)?.value;if(!F?.role)return"guest";return F.expiresAt&&new Date(F.expiresAt).getTime()<Date.now()?"guest":F.role},T=($,F)=>!!$?.sig&&Y.includes($.author)&&U({type:"upsert",id:F,value:$.value,timestamp:$.ts,originUser:$.author},$.sig)===$.author,x=($)=>$?.meta?.role??($?.meta&&{...$.meta,ts:$.meta.ts??$.timestamp}),h=($,F)=>{let u=x($);return T(u,F)?u:void 0};return{op($,F){if(!$?.signature)return!1;let u=U(w($),$.signature);if(!u||u!==$.originUser)return!1;let l=$.sourceId??$.id,f=$.type==="remove"?"delete":$.sourceId?"link":"write";if(q(l)){let t=h(F,l);if(Y.includes(u))return!t||I($.timestamp,t.ts)>0;if(f!=="write"||u!==l.slice(5))return!1;if(F&&!Z(O(u),"write"))return!1;let{role:H0="guest",expiresAt:g=null}=t?.value??{},d=$.value??{};return d.role===H0&&(d.expiresAt??null)===g}if(!Z(O(u),f))return!1;let s=Q(F?.value)??N(l);if(s)return(f==="delete"?H:A)(u,s,F?.value?.collaborators);let y=Q($.value);return!y||u===y},opOf($,F){let u=F.meta??{},l=(f)=>({type:"upsert",id:$,value:f.value??F.value,timestamp:f.ts??F.timestamp,originUser:f.author,originEthAddress:f.author,signature:f.sig});return u.role?[l(u.role),l(u)]:[l(u)]},edgeOf($,F){let u=F.meta?.edges;return u?{type:u.type,sourceId:$,targetId:u.targetId,edges:F.edges??[],timestamp:u.ts,originUser:u.author,originEthAddress:u.author,signature:u.sig}:null},edgeReceipt($){if(!$?.signature||!Array.isArray($.edges))return null;return{author:U(w($),$.signature),sig:$.signature,ts:$.timestamp,type:$.type,targetId:$.targetId}},edges($,F,u){let l=F.meta?.edges,f=u.meta?.edges;if(!l||f&&I(f.ts,l.ts)>=0)return null;let s=this.edgeOf($,F);return this.op(s,u)?s:null},describe($,F){let u=$?.signature&&U(w($),$.signature);if(!u)return"unsigned or invalid signature";return`${u} as ${O(u)}, owner ${Q(F?.value)??N($.sourceId??$.id)??"none"}`},receipt($,F,u){if(!$?.signature)return null;let l=U(w($),$.signature),f={author:l,sig:$.signature,ts:$.timestamp};if(u.meta?.edges)f.edges=u.meta.edges;if(q($.id)){if(f.value=$.value,!Y.includes(l)){let s=h(F,$.id);if(s)f.role=s}}return f}}};function u_(W,X=[]){let G=String(W??"").trim();if(!G)throw Error("sm-server: signing key required (GDB_SM_KEY)");let Y=G.includes(" ")?q9.fromPhrase(G):new Z6(G),J=h1(Y.address),Z=new Set([...X,J].map((Q)=>{try{return h1(Q)}catch{return null}}).filter(Boolean));return{address:J,superAdmins:Z,canonicalize:qA,signOps:async(Q)=>{let N=[];for(let q of Q){if(q?.signature&&q?.originEthAddress&&q?.originUser){N.push(q);continue}let A={...q,originUser:J},H=await Y.signMessage(Q9(qA(A)));N.push({...q,originUser:J,originEthAddress:J,signature:H})}return N},verifyOp:ND,isSuperAdmin:(Q)=>{try{return Z.has(h1(Q))}catch{return!1}}}}var qD={superadmin:{can:["assignRole","deleteAny"],inherits:["admin"]},admin:{can:["delete"],inherits:["manager"]},manager:{can:["publish"],inherits:["user"]},user:{can:["write","link","sync"],inherits:["guest"]},guest:{can:["read","sync"]}},St=Object.keys(qD),HD=(W,X,G,Y=new Set)=>{if(!X||!W[X]||Y.has(X))return!1;if(Y.add(X),W[X].can?.includes(G))return!0;return(W[X].inherits??[]).some((J)=>HD(W,J,G,new Set(Y)))},xt=(W)=>W==="upsert"?"write":W==="remove"?"delete":W==="link"||W==="unlink"?"link":W==="sync"||W==="deltaSync"?"sync":"unknown",QD=(W)=>`${W.slice(0,6)}...${W.slice(-4)}`,h_=({constitution:W=[],customRoles:X=null,getNode:G})=>{let Y=W.map((U)=>{try{return h1(U)}catch{return null}}).filter(Boolean),J=X??qD,Z=(U)=>{let Q=G(`user:${U}`)?.value;if(!Q?.role)return"guest";if(Q.expiresAt&&new Date(Q.expiresAt).getTime()<Date.now())return"guest";return Q.role},V=(U)=>{try{return Y.includes(h1(U??""))}catch{return!1}};return async(U)=>{let Q=[];for(let N of U){if(N?.type==="sync"){Q.push(N);continue}if(N?.type==="fullStateSync"||N?.type==="deltaSync"){if(!(N.signature&&N.originEthAddress&&N.originUser)){Q.push(N);continue}let h=ND(N);if(h.ok)Q.push(h.payload);else console.warn(`\u26A0\uFE0F SM: ${N.type} rejected: ${h.reason}`);continue}let q=ND(N);if(!q.ok){console.warn(`\u26A0\uFE0F SM: invalid signed operation: ${q.reason}`);continue}let{normalizedOriginEthAddress:A,payload:H}=q,I=Y.includes(A)?"superadmin":Z(A),w={...H,signer:A,originUser:N.originUser,originEthAddress:N.originEthAddress,signature:N.signature};if(H.type==="upsert"&&H.id===`user:${A}`&&!G(H.id)){Q.push(w);continue}let{role:O,ethAddress:T}=H.value??{};if(O==="superadmin"&&!V(T)){console.warn(`\u26A0\uFE0F SM: [POLICY] ${QD(A)} tried to assign superadmin to ${QD(String(T??""))}. Blocked.`);continue}let x=xt(H.type);if(HD(J,I,x))Q.push(w);else console.warn(`\u26A0\uFE0F SM: ${QD(A)} (role: ${I}) DENIED ${x}`)}return Q}};function b_(W,X,G,{intervalMs:Y=4000,settleMs:J=15000,customRoles:Z=null}={}){let V=new Set([...St,...Object.keys(Z??{})]),U=async(A,H,I=null)=>{let w=h1(A);if(!V.has(H))throw Error(`Role '${H}' is not a defined role.`);let O=`user:${w}`,T=(await W.get(O)).result?.value||{};await W.put({...T,ethAddress:w,role:H,assignedByEthAddress:X.address,expiresAt:I?new Date(I).toISOString():null,priority:!0},O)},Q=async()=>{let A=new Map;for(let H of G){let I=H.then?.assignRole;if(!I)continue;let w=[];try{({results:w=[]}=W.map({query:H.if}))}catch(O){console.error("\u274C GOVERNANCE: rule evaluation failed:",O.message);continue}for(let O of w){if(!O.id.startsWith("user:"))continue;if(X.isSuperAdmin(O.id.slice(5)))continue;if(H.offsetTimestamp&&(O.timestamp?.physical??0)>Date.now()-H.offsetTimestamp)continue;A.set(O.id,{role:I,current:O.value?.role})}}for(let[H,{role:I,current:w}]of A){if(w===I)continue;try{await U(H.slice(5),I),console.info(`\uD83D\uDCDC GOVERNANCE: ${H.slice(5)} '${w}' -> '${I}'`)}catch(O){console.error("\u274C GOVERNANCE: assignRole failed:",O.message)}}},N=null,q=setTimeout(()=>{N=setInterval(Q,Y),console.info(`\uD83D\uDCDC GOVERNANCE ENGINE: active \u2014 ${G.length} rule(s), every ${Y} ms.`)},J);return{assignRole:U,stop:()=>{if(clearTimeout(q),N)clearInterval(N)}}}var zD=(W)=>W&&typeof W==="object"?structuredClone(W):W,AD=(W,X=16)=>{let G=null,Y=null;return(...J)=>{if(Y??=Promise.withResolvers(),G!==null)clearTimeout(G);return G=setTimeout(async()=>{G=null;try{Y.resolve(await W(...J))}catch(Z){Y.reject(Z)}finally{Y=null}},X),Y.promise}},vt=(W)=>{let X=!1;return()=>{if(X)return;X=!0,setImmediate(()=>{X=!1,W()})}};function gt(W=1000){let X=[];return{add(G){if(G?.timestamp){if(X.push(G),X.length>W)X.splice(0,X.length-W)}},getOldest:()=>X[0]??null,getDelta:(G,Y)=>G?X.filter((J)=>Y(J.timestamp,G)>0):[...X],sign({type:G,id:Y,sourceId:J,timestamp:Z,originUser:V,originEthAddress:U,signature:Q}){let N=X.find((q)=>q.type===G&&(q.id??q.sourceId)===(Y??J)&&q.timestamp?.physical===Z?.physical&&q.timestamp?.logical===Z?.logical);if(N&&Q)Object.assign(N,{originUser:V,originEthAddress:U,signature:Q})},clear(){X=[]},entries:()=>[...X],setEntries(G=[]){if(X=Array.isArray(G)?[...G]:[],X.length>W)X.splice(0,X.length-W)}}}function ut(){let W={nodes:{}};return{get nodes(){return W.nodes},set nodes(X){W.nodes=X??{}},upsert(X,G,Y){let J=W.nodes[X];W.nodes[X]={id:X,value:zD(G),edges:J?.edges?[...J.edges]:[],timestamp:Y,...J?.meta&&{meta:J.meta}}},get:(X)=>W.nodes[X]??null,link(X,G,Y){let J=W.nodes[X],Z=W.nodes[G];if(J&&Z&&!J.edges.includes(G))W.nodes[X]={...J,edges:[...J.edges,G],timestamp:Y}},unlink(X,G,Y){let J=W.nodes[X];if(J?.edges.includes(G))W.nodes[X]={...J,edges:J.edges.filter((Z)=>Z!==G),timestamp:Y}},getAllNodes:()=>Object.values(W.nodes),serialize:()=>GG.deflate(bU(W.nodes)),deserialize(X){let G=X instanceof Uint8Array?X:new Uint8Array(X);W.nodes=zW(GG.inflate(G))}}}function ht(W,X){let G=yt(W);if(G&&G!==".")_t(G,{recursive:!0});let Y=new kt(W);Y.exec("PRAGMA journal_mode = WAL"),Y.exec("PRAGMA synchronous = NORMAL"),Y.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=Y.prepare("SELECT value FROM kv WHERE key = ?"),Z=Y.prepare("INSERT OR REPLACE INTO kv (key, value) VALUES (?, ?)"),V=Y.prepare("DELETE FROM kv WHERE key = ?"),U=X;return{getBlob(Q){let N=J.get(`${U}:${Q}`);return N?new Uint8Array(N.value):null},getText(Q){let N=J.get(`${U}:${Q}`);return N?Buffer.from(N.value).toString("utf8"):null},putBlob(Q,N){Z.run(`${U}:${Q}`,Buffer.from(N))},putText(Q,N){Z.run(`${U}:${Q}`,Buffer.from(N,"utf8"))},del(Q){V.run(`${U}:${Q}`)},close(){Y.close()}}}async function bt(W=process.env.GDB_ROOM||process.argv.slice(2).find((Y)=>!Y.startsWith("--"))||"default",X={},G=process.env.GDB_DB_PATH||"./data.sqlite"){console.info(`\u26A1 GDBServer [${W}] initializing (bun:sqlite)`);let{password:Y,saveDelay:J=200,oplogSize:Z=1000,rtcPolyfill:V=null,rtc:U=!0,room:Q=null,sm:N=null,relay:q=null}=X,A=U?.constructor===Object?U:{},{turnConfig:H=null}=A,I=A.relayUrls??((process.env.GDB_RELAY_URLS??"").split(",").map((Y0)=>Y0.trim()).filter(Boolean).length?process.env.GDB_RELAY_URLS.split(",").map((Y0)=>Y0.trim()).filter(Boolean):null),w=q??(process.argv.includes("--relay")||["1","true"].includes(process.env.GDB_RELAY??"")),O=null;if(w)O=$x(q?.constructor===Object?q:{}),I=[...I??[],`ws://127.0.0.1:${O.port}`];let T=A.cells??(process.argv.includes("--cells")||["1","true"].includes(process.env.GDB_CELLS??"")),x=Q??process.argv.includes("--room"),h=N?.constructor===Object?N:null,$=h?.key??process.env.GDB_SM_KEY??null,F=h?.superAdmins??(process.env.GDB_SUPERADMINS??"").split(",").map((Y0)=>Y0.trim()).filter(Boolean),u=null;if($)u=u_($,F),console.info(`\uD83D\uDEE1\uFE0F SM: signing as ${u.address}`);else if(h)console.warn("\u26A0\uFE0F SM: sm configured but no signing key (GDB_SM_KEY) \u2014 running unsigned, memory-only role.");let l=Boolean(u||h||F.length);if(l&&!u&&!F.length)console.warn("\u26A0\uFE0F SM: superAdmins is empty \u2014 only a superadmin's signed write sets a role, so no identity can be promoted; open the base role in customRoles if guests should write.");let p=u?[...u.superAdmins]:F;if(l&&!p.length)console.warn("\u26A0\uFE0F SM: no superAdmins (GDB_SUPERADMINS) \u2014 role nodes cannot be verified and will not be relayed.");let s=l?g_({constitution:p,customRoles:h?.customRoles??null,getNode:(Y0)=>y.get(Y0)}):null,y=ut(),t=cC(),H0=(Y0)=>{let K0=y.get(Y0.sourceId);if(!K0)return;if(Array.isArray(Y0.edges))K0.edges=[...Y0.edges];let P0=s?.edgeReceipt(Y0);if(P0)K0.meta={...K0.meta,edges:P0}},g=(Y0,K0)=>JSON.stringify(Y0)===JSON.stringify(K0),d=gt(Z),P=ht(G,W),E=[],f=[],r=[],o=null,B=null,S=null,_={},v=()=>{let Y0=P.getBlob("graph");if(Y0?.byteLength)y.deserialize(Y0),console.info(`\u2705 Graph loaded: ${y.getAllNodes().length} nodes`)},R=()=>{P.putBlob("graph",y.serialize())},m=()=>{let Y0=P.getText("timestamp");if(Y0){let K0=JSON.parse(Y0);if(K0?.physical&&K0?.logical)o=K0,t.update(o)}},J0=()=>{P.putText("timestamp",JSON.stringify(o??null))},U0=()=>{let Y0=P.getBlob("oplog");if(Y0?.byteLength){let K0=zW(GG.inflate(Y0));if(Array.isArray(K0))d.setEntries(K0),console.info(`\u2705 Oplog loaded: ${K0.length} ops`)}},q0=()=>{P.putBlob("oplog",GG.deflate(bU(d.entries())))},$0=(Y0)=>{if(!Y0)return;if(!o||t.compare(Y0,o)>0)o=Y0,J0()},u0=()=>{let Y0=0,K0=0;for(let[P0,k0]of Object.entries(y.nodes)){let R1=`${P0}\x00${k0.timestamp.physical}\x00${k0.timestamp.logical}`,Q1=2166136261,X0=3386659096;for(let C0=0;C0<R1.length;C0++)Q1=Math.imul(Q1^R1.charCodeAt(C0),16777619),X0=Math.imul(X0^R1.charCodeAt(C0),16777619);Y0^=Q1,K0^=X0}return`${Y0>>>0}.${K0>>>0}`},H1=AD(()=>R(),J),v1=AD(()=>q0(),J),h0=()=>{let Y0={...y.nodes};E.forEach((K0)=>K0(Y0))},F1=vt(()=>h0()),S1=async(Y0)=>{if(!Y0?.length||!B)return!1;try{return await B.send(Y0),!0}catch(K0){return console.error("\u274C safeSend failed:",K0?.message),!1}},N0=async(Y0)=>{let K0=await S1(Y0);return setTimeout(()=>S1(Y0),2500),K0},F0=async(Y0)=>{let K0=!1,P0=null,k0=(X0)=>{if(X0&&(!P0||t.compare(X0,P0)>0))P0=X0},R1=(X0)=>{try{if(X0 instanceof Uint8Array||X0 instanceof ArrayBuffer){let C0=zW(X0);return Array.isArray(C0)?C0:[C0]}if(Array.isArray(X0))return X0;if(X0&&typeof X0==="object")return zW(GG.inflate(new Uint8Array(Object.values(X0))))}catch(C0){console.error("\u274C decode failed",C0)}return null},Q1={upsert(X0){let C0=y.get(X0.id);if(!C0){for(let N1 of d.getDelta(null))if(N1.type==="remove"&&N1.id===X0.id&&t.compare(N1.timestamp,X0.timestamp)>=0)return!1}let{resolved:x0,value:k1,timestamp:W8}=lC(C0,X0,t);if(!x0)return!1;if(s&&!s.op(X0,C0))return console.warn(`\u26A0\uFE0F [SYNC-AUTH] upsert denied: ${X0.id} (${s.describe(X0,C0)})`),!1;y.upsert(X0.id,k1,W8);let d1=s?.receipt(X0,C0,y.get(X0.id));if(d1)y.get(X0.id).meta=d1;return t.update(W8),d.add({type:"upsert",id:X0.id,timestamp:W8}),K0=!0,k0(W8),!0},remove(X0){if(MW(X0.timestamp))return;let C0=y.get(X0.id);if(!C0||t.compare(C0.timestamp,X0.timestamp)>=0)return;if(s&&!s.op(X0,C0))return console.warn(`\u26A0\uFE0F [SYNC-AUTH] remove denied: ${X0.id} (${s.describe(X0,C0)})`);delete y.nodes[X0.id],t.update(X0.timestamp),d.add({type:"remove",id:X0.id,value:X0.value,timestamp:X0.timestamp,originUser:X0.originUser,originEthAddress:X0.originEthAddress,signature:X0.signature}),K0=!0,k0(X0.timestamp)},link(X0){if(MW(X0.timestamp))return;let C0=y.get(X0.sourceId),x0=y.get(X0.targetId);if(!C0||!x0||t.compare(C0.timestamp,X0.timestamp)>=0)return;if(C0.meta?.edges&&t.compare(C0.meta.edges.ts,X0.timestamp)>=0)return;if(s&&!s.op(X0,C0))return console.warn(`\u26A0\uFE0F [SYNC-AUTH] link denied: ${X0.sourceId} (${s.describe(X0,C0)})`);y.link(X0.sourceId,X0.targetId,X0.timestamp),H0(X0),t.update(X0.timestamp),d.add({type:"link",sourceId:X0.sourceId,targetId:X0.targetId,edges:X0.edges,timestamp:X0.timestamp,originUser:X0.originUser,originEthAddress:X0.originEthAddress,signature:X0.signature}),K0=!0,k0(X0.timestamp)},unlink(X0){if(MW(X0.timestamp))return;let C0=y.get(X0.sourceId);if(!C0||t.compare(C0.timestamp,X0.timestamp)>=0)return;if(C0.meta?.edges&&t.compare(C0.meta.edges.ts,X0.timestamp)>=0)return;if(s&&!s.op(X0,C0))return console.warn(`\u26A0\uFE0F [SYNC-AUTH] unlink denied: ${X0.sourceId} (${s.describe(X0,C0)})`);y.unlink(X0.sourceId,X0.targetId,X0.timestamp),H0(X0),t.update(X0.timestamp),d.add({type:"unlink",sourceId:X0.sourceId,targetId:X0.targetId,edges:X0.edges,timestamp:X0.timestamp,originUser:X0.originUser,originEthAddress:X0.originEthAddress,signature:X0.signature}),K0=!0,k0(X0.timestamp)},async sync({timestamp:X0,digest:C0}){if(C0&&C0===u0())return console.info("\uD83D\uDFF0 State digests match \u2014 nothing to send.");let x0=d.getOldest();if(X0==null||x0&&t.compare(X0,x0.timestamp)<0){console.info("\uD83D\uDCA5 Sending FULL state sync:",y.getAllNodes().length,"nodes"),await N0([{type:"fullStateSync",graphData:y.nodes,removals:d.getDelta(null).filter((N1)=>N1.type==="remove"),timestamp:o}]);return}let W8=d.getDelta(null);if(!W8.length)return;let d1=W8.flatMap((N1)=>{if(N1.type!=="upsert")return[N1];let c=y.get(N1.id);if(!c)return[];return[s?.opOf(N1.id,c)??{...N1,value:c.value}]});console.info("\uD83D\uDE80 Sending DELTA sync:",d1.length,"ops"),await N0([{type:"deltaSync",operations:d1,timestamp:o}])},deltaSync({operations:X0}){let C0=R1(X0);if(!Array.isArray(C0))return;console.info("\uD83D\uDCE5 deltaSync:",C0.length,"ops");for(let x0 of C0)if(x0&&Q1[x0.type])Q1[x0.type](x0)},async fullStateSync({graphData:X0,removals:C0,timestamp:x0,reciprocal:k1}){if(!X0||typeof X0!=="object")return;let W8=Object.entries(X0).sort(([N1],[c])=>c.startsWith("user:")-N1.startsWith("user:"));for(let[N1,c]of W8){let W0=Q1.upsert(s?.opOf(N1,c)??{type:"upsert",id:N1,value:c.value,timestamp:c.timestamp}),Q0=y.nodes[N1];if(!Q0)continue;if(s){let T0=s.edges(N1,c,Q0);if(T0&&!MW(T0.timestamp))H0(T0)}else if(W0)Q0.edges=[...c.edges??[]]}for(let N1 of C0??[])Q1.remove(N1);let d1=new Set(Object.keys(X0));if(!k1&&Object.keys(y.nodes).some((N1)=>!d1.has(N1)))await N0([{type:"fullStateSync",graphData:y.nodes,removals:d.getDelta(null).filter((N1)=>N1.type==="remove"),timestamp:o,reciprocal:!0}]);if(K0=!0,console.info("\u2705 fullStateSync merged:",y.getAllNodes().length,"nodes"),x0&&!MW(x0))k0(x0),t.update(x0)}};for(let X0 of Y0)if(Q1[X0.type])await Q1[X0.type](X0);if(P0&&(!o||t.compare(P0,o)>0))$0(P0);if(K0)await Promise.all([H1(),v1()]),F1()},m0=AD(async()=>{let Y0=r.splice(0);if(!Y0.length)return!1;let K0=await S1(Y0);if(!K0)r.unshift(...Y0),setTimeout(()=>m0().catch(()=>{}),1000);return K0},16);if(Object.assign(_,{use(Y0){if(typeof Y0==="function")f.push(Y0)},async put(Y0,K0){let P0=t.now();$0(P0);let k0=Y0?.owner??Y0?._meta?.owner;K0??=k0?`${k0}:${crypto.randomUUID()}`:crypto.randomUUID(),y.upsert(K0,Y0,P0),d.add({type:"upsert",id:K0,timestamp:P0}),H1(),v1();try{r.push({type:"upsert",id:K0,value:Y0,timestamp:P0}),m0().catch(()=>{})}finally{F1()}return K0},async get(Y0){if(typeof Y0!=="string")return{result:null};let K0=y.get(Y0);if(!K0)return{result:null};return{result:{...K0,value:zD(K0.value),edges:K0.edges.filter((P0)=>Object.hasOwn(y.nodes,P0))}}},map(...Y0){let P0={...{realtime:!1,query:{},field:null,order:"asc",$limit:null,$after:null,$before:null}},k0=null,R1=!1;Y0.forEach((C0)=>typeof C0==="function"?k0=C0:C0&&typeof C0==="object"&&(R1=R1||("realtime"in C0),Object.assign(P0,C0))),k0&&!R1&&(P0.realtime=!0);let Q1=aA(y.nodes,P0),X0=null;if(k0){if(Q1.forEach((C0)=>k0({id:C0.id,value:C0.value,edges:C0.edges,timestamp:C0.timestamp,action:"initial"})),P0.realtime){let C0=(x0)=>`${x0.id}:${x0.timestamp?.physical??0}:${x0.timestamp?.logical??0}:${(x0.edges??[]).join(",")}`;X0=(x0)=>{let k1=aA(x0,P0),W8=new Map(Q1.map((N1)=>[N1.id,N1])),d1=new Map(k1.map((N1)=>[N1.id,N1]));if(k1.length!==Q1.length||!k1.map(C0).every((N1,c)=>N1===Q1.map(C0)[c])){for(let[N1,c]of d1){let W0=W8.get(N1);if(!W0)k0({id:N1,value:c.value,edges:c.edges,timestamp:c.timestamp,action:"added"});else if(C0(c)!==C0(W0))k0({id:N1,value:c.value,edges:c.edges,timestamp:c.timestamp,action:"updated"})}for(let[N1,c]of W8)if(!d1.has(N1))k0({id:N1,value:null,edges:c.edges,timestamp:c.timestamp,action:"removed"});Q1=k1}},E.push(X0)}}return{results:Q1,...P0.realtime&&k0&&X0&&{unsubscribe:()=>{let C0=E.indexOf(X0);if(C0>=0)E.splice(C0,1)}}}},async link(Y0,K0){if(!y.nodes[Y0]||!y.nodes[K0])return;let P0=t.now();y.link(Y0,K0,P0);let k0=[...y.nodes[Y0].edges];d.add({type:"link",sourceId:Y0,targetId:K0,edges:k0,timestamp:P0}),H1(),v1(),$0(P0);try{r.push({type:"link",sourceId:Y0,targetId:K0,edges:k0,timestamp:P0}),m0().catch(()=>{})}finally{F1()}},async unlink(Y0,K0){if(!y.nodes[Y0]?.edges.includes(K0))return;let P0=t.now();y.unlink(Y0,K0,P0);let k0=[...y.nodes[Y0].edges];d.add({type:"unlink",sourceId:Y0,targetId:K0,edges:k0,timestamp:P0}),H1(),v1(),$0(P0);try{r.push({type:"unlink",sourceId:Y0,targetId:K0,edges:k0,timestamp:P0}),m0().catch(()=>{})}finally{F1()}},async remove(Y0){let K0=y.get(Y0);if(!K0)return;let P0=t.now();delete y.nodes[Y0],d.add({type:"remove",id:Y0,value:K0.value,timestamp:P0}),H1(),v1(),$0(P0);try{r.push({type:"remove",id:Y0,value:K0.value,timestamp:P0}),m0().catch(()=>{})}finally{F1()}},async clear(){y.nodes={},d.clear(),P.del("graph"),P.del("oplog"),h0()},on(Y0){return E.push(Y0),()=>{let K0=E.indexOf(Y0);if(K0>=0)E.splice(K0,1)}},close(){P.close()}}),l)_.use(h_({constitution:p,customRoles:h?.customRoles??null,getNode:(Y0)=>y.get(Y0)})),console.info("\uD83D\uDEE1\uFE0F SM: verifying incoming operations");try{let Y0=`graph-sync-room-${W}`,K0={appId:"1234",type:"superpeer",...Y&&{password:Y},...I&&{relayUrls:I},...H&&{turnConfig:H},...T&&{cells:!0},...T&&T!==!0&&{overlay:T},rtcPolyfill:V??zO};if(S=Bz(K0,Y0),B=S.channel("syncGraph"),console.info(`\u26A1 Transport: ${T?"cellular mesh":"full mesh"}`),u){let P0=B.send;B={...B,send:async(k0)=>{let R1=await u.signOps(k0),Q1=!1;for(let X0 of R1??[]){if(!X0?.signature)continue;if(X0.type!=="upsert"){if(d.sign(X0),Q1=!0,Array.isArray(X0.edges)&&g(y.get(X0.sourceId)?.edges,X0.edges))H0(X0);continue}let C0=y.get(X0.id);if(!C0||!g(C0.value,X0.value))continue;let x0=s.receipt(X0,C0,C0);if(x0)C0.meta=x0,Q1=!0}if(Q1)H1(),v1();return P0(R1)}},_.sm=u}if(!T){let P0=!1;S.channel("c0").on("message",()=>{if(P0)return;P0=!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)_.room=Bz(K0,`app-sync-${W}`),console.info("\u26A1 db.room joined \u2014 visible to monitors/presence");S.on("peer:join",(P0)=>{console.info("\u26A1 Peer connected:",P0);for(let k0 of[0,1500,4000,9000])setTimeout(()=>S1([{type:"sync",timestamp:o,digest:u0()}]),k0)}),S.on("peer:leave",(P0)=>console.info("\u26A1 Peer disconnected:",P0)),B.on("message",async(P0)=>{let k0;try{k0=P0 instanceof Uint8Array||P0 instanceof ArrayBuffer?(()=>{let Q1=zW(P0);return Array.isArray(Q1)?Q1:[Q1]})():Array.isArray(P0)?P0:[P0]}catch(Q1){return console.error("\u274C decode failed:",Q1)}let R1=new Map([...new Set(k0.flatMap((Q1)=>["id","sourceId","targetId"].map((X0)=>Q1?.[X0]).filter(Boolean)))].map((Q1)=>y.get(Q1)?[Q1,zD(y.get(Q1))]:null).filter(Boolean));for(let Q1 of f)try{if(k0=await Q1(k0,R1),!k0?.length)return}catch(X0){console.error("\u274C Middleware error:",X0);return}await F0(k0)}),console.info("\u2705 GenosRTC sync enabled")}catch(Y0){console.warn("\u26A0\uFE0F GenosRTC not available:",Y0.message)}if(v(),m(),U0(),u){let Y0=h?.governanceRules??null;if(!Y0&&process.env.GDB_SM_RULES){let K0=process.env.GDB_SM_RULES.trim();try{if(K0.startsWith("["))Y0=JSON.parse(K0);else if(K0.startsWith("{"))Y0=[JSON.parse(K0)];else Y0=(await import(new URL(K0,`file://${process.cwd()}/`).href)).default}catch(P0){console.error("\u274C GOVERNANCE: could not load GDB_SM_RULES:",P0.message)}}if(Array.isArray(Y0)&&Y0.length)_.governance=b_(_,u,Y0,{customRoles:h?.customRoles??null})}if(O)_.relay=O;return Object.defineProperties(_,{syncChannel:{get:()=>B},hybridClock:{get:()=>t},graph:{get:()=>({getAllNodes:()=>y.getAllNodes(),get:(Y0)=>y.get(Y0)})}}),console.info(`\u2705 GDBServer [${W}] ready (bun:sqlite)`),_}if(import.meta.main){let W=new Set(["ECONNREFUSED","ECONNRESET","EHOSTUNREACH","ENETUNREACH","EADDRNOTAVAIL","ETIMEDOUT","EPIPE"]),X=(Z)=>W.has(Z?.code)||W.has(Z?.errno),G=new Map,Y=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);Y??=setTimeout(()=>{Y=null;let U=[...G].filter(([,Q])=>Q>1).map(([Q,N])=>`${Q} \xD7${N}`).join(", ");if(U)console.warn("\u26A0\uFE0F Transient network errors (ignored, last 60s):",U);G.clear()},60000)};process.on("uncaughtException",(Z)=>{if(X(Z))return J(Z?.code??Z?.errno);console.error("\u274C Fatal:",Z?.message??Z),process.exit(1)}),process.on("unhandledRejection",(Z)=>{if(X(Z))return J(Z?.code??Z?.errno);console.error("\u274C Fatal (rejection):",Z?.message??Z),process.exit(1)}),bt().catch((Z)=>{console.error("\u274C Fatal:",Z.message),process.exit(1)})}export{bt as gdbServer};
256
+ `);let J=Y.prepare("SELECT value FROM kv WHERE key = ?"),Z=Y.prepare("INSERT OR REPLACE INTO kv (key, value) VALUES (?, ?)"),V=Y.prepare("DELETE FROM kv WHERE key = ?"),U=X;return{getBlob(Q){let N=J.get(`${U}:${Q}`);return N?new Uint8Array(N.value):null},getText(Q){let N=J.get(`${U}:${Q}`);return N?Buffer.from(N.value).toString("utf8"):null},putBlob(Q,N){Z.run(`${U}:${Q}`,Buffer.from(N))},putText(Q,N){Z.run(`${U}:${Q}`,Buffer.from(N,"utf8"))},del(Q){V.run(`${U}:${Q}`)},close(){Y.close()}}}async function bt(W=process.env.GDB_ROOM||process.argv.slice(2).find((Y)=>!Y.startsWith("--"))||"default",X={},G=process.env.GDB_DB_PATH||"./data.sqlite"){console.info(`\u26A1 GDBServer [${W}] initializing (bun:sqlite)`);let{password:Y,saveDelay:J=200,oplogSize:Z=1000,rtcPolyfill:V=null,rtc:U=!0,room:Q=null,sm:N=null,relay:q=null}=X,A=U?.constructor===Object?U:{},{turnConfig:H=null}=A,I=A.relayUrls??((process.env.GDB_RELAY_URLS??"").split(",").map((Y0)=>Y0.trim()).filter(Boolean).length?process.env.GDB_RELAY_URLS.split(",").map((Y0)=>Y0.trim()).filter(Boolean):null),w=q??(process.argv.includes("--relay")||["1","true"].includes(process.env.GDB_RELAY??"")),O=null;if(w)O=$x(q?.constructor===Object?q:{}),I=[...I??[],`ws://127.0.0.1:${O.port}`];let T=A.cells??(process.argv.includes("--cells")||["1","true"].includes(process.env.GDB_CELLS??"")),x=Q??process.argv.includes("--room"),h=N?.constructor===Object?N:null,$=h?.key??process.env.GDB_SM_KEY??null,F=h?.superAdmins??(process.env.GDB_SUPERADMINS??"").split(",").map((Y0)=>Y0.trim()).filter(Boolean),u=null;if($)u=u_($,F),console.info(`\uD83D\uDEE1\uFE0F SM: signing as ${u.address}`);else if(h)console.warn("\u26A0\uFE0F SM: sm configured but no signing key (GDB_SM_KEY) \u2014 running unsigned, memory-only role.");let l=Boolean(u||h||F.length);if(l&&!u&&!F.length)console.warn("\u26A0\uFE0F SM: superAdmins is empty \u2014 only a superadmin's signed write sets a role, so no identity can be promoted; open the base role in customRoles if guests should write.");let f=u?[...u.superAdmins]:F;if(l&&!f.length)console.warn("\u26A0\uFE0F SM: no superAdmins (GDB_SUPERADMINS) \u2014 role nodes cannot be verified and will not be relayed.");let s=l?g_({constitution:f,customRoles:h?.customRoles??null,getNode:(Y0)=>y.get(Y0)}):null,y=ut(),t=cC(),H0=(Y0)=>{let K0=y.get(Y0.sourceId);if(!K0)return;if(Array.isArray(Y0.edges))K0.edges=[...Y0.edges];let P0=s?.edgeReceipt(Y0);if(P0)K0.meta={...K0.meta,edges:P0}},g=(Y0,K0)=>JSON.stringify(Y0)===JSON.stringify(K0),d=gt(Z),P=ht(G,W),E=[],p=[],r=[],o=null,B=null,S=null,_={},v=()=>{let Y0=P.getBlob("graph");if(Y0?.byteLength)y.deserialize(Y0),console.info(`\u2705 Graph loaded: ${y.getAllNodes().length} nodes`)},R=()=>{P.putBlob("graph",y.serialize())},m=()=>{let Y0=P.getText("timestamp");if(Y0){let K0=JSON.parse(Y0);if(K0?.physical&&K0?.logical)o=K0,t.update(o)}},J0=()=>{P.putText("timestamp",JSON.stringify(o??null))},U0=()=>{let Y0=P.getBlob("oplog");if(Y0?.byteLength){let K0=zW(GG.inflate(Y0));if(Array.isArray(K0))d.setEntries(K0),console.info(`\u2705 Oplog loaded: ${K0.length} ops`)}},q0=()=>{P.putBlob("oplog",GG.deflate(bU(d.entries())))},$0=(Y0)=>{if(!Y0)return;if(!o||t.compare(Y0,o)>0)o=Y0,J0()},u0=()=>{let Y0=0,K0=0;for(let[P0,k0]of Object.entries(y.nodes)){let R1=`${P0}\x00${k0.timestamp.physical}\x00${k0.timestamp.logical}`,Q1=2166136261,X0=3386659096;for(let C0=0;C0<R1.length;C0++)Q1=Math.imul(Q1^R1.charCodeAt(C0),16777619),X0=Math.imul(X0^R1.charCodeAt(C0),16777619);Y0^=Q1,K0^=X0}return`${Y0>>>0}.${K0>>>0}`},H1=AD(()=>R(),J),v1=AD(()=>q0(),J),h0=()=>{let Y0={...y.nodes};E.forEach((K0)=>K0(Y0))},F1=vt(()=>h0()),S1=async(Y0)=>{if(!Y0?.length||!B)return!1;try{return await B.send(Y0),!0}catch(K0){return console.error("\u274C safeSend failed:",K0?.message),!1}},N0=async(Y0)=>{let K0=await S1(Y0);return setTimeout(()=>S1(Y0),2500),K0},F0=async(Y0)=>{let K0=!1,P0=null,k0=(X0)=>{if(X0&&(!P0||t.compare(X0,P0)>0))P0=X0},R1=(X0)=>{try{if(X0 instanceof Uint8Array||X0 instanceof ArrayBuffer){let C0=zW(X0);return Array.isArray(C0)?C0:[C0]}if(Array.isArray(X0))return X0;if(X0&&typeof X0==="object")return zW(GG.inflate(new Uint8Array(Object.values(X0))))}catch(C0){console.error("\u274C decode failed",C0)}return null},Q1={upsert(X0){let C0=y.get(X0.id);if(!C0){for(let N1 of d.getDelta(null))if(N1.type==="remove"&&N1.id===X0.id&&t.compare(N1.timestamp,X0.timestamp)>=0)return!1}let{resolved:x0,value:k1,timestamp:W8}=lC(C0,X0,t);if(!x0)return!1;if(s&&!s.op(X0,C0))return console.warn(`\u26A0\uFE0F [SYNC-AUTH] upsert denied: ${X0.id} (${s.describe(X0,C0)})`),!1;y.upsert(X0.id,k1,W8);let d1=s?.receipt(X0,C0,y.get(X0.id));if(d1)y.get(X0.id).meta=d1;return t.update(W8),d.add({type:"upsert",id:X0.id,timestamp:W8}),K0=!0,k0(W8),!0},remove(X0){if(MW(X0.timestamp))return;let C0=y.get(X0.id);if(!C0||t.compare(C0.timestamp,X0.timestamp)>=0)return;if(s&&!s.op(X0,C0))return console.warn(`\u26A0\uFE0F [SYNC-AUTH] remove denied: ${X0.id} (${s.describe(X0,C0)})`);delete y.nodes[X0.id],t.update(X0.timestamp),d.add({type:"remove",id:X0.id,value:X0.value,timestamp:X0.timestamp,originUser:X0.originUser,originEthAddress:X0.originEthAddress,signature:X0.signature}),K0=!0,k0(X0.timestamp)},link(X0){if(MW(X0.timestamp))return;let C0=y.get(X0.sourceId),x0=y.get(X0.targetId);if(!C0||!x0||t.compare(C0.timestamp,X0.timestamp)>=0)return;if(C0.meta?.edges&&t.compare(C0.meta.edges.ts,X0.timestamp)>=0)return;if(s&&!s.op(X0,C0))return console.warn(`\u26A0\uFE0F [SYNC-AUTH] link denied: ${X0.sourceId} (${s.describe(X0,C0)})`);y.link(X0.sourceId,X0.targetId,X0.timestamp),H0(X0),t.update(X0.timestamp),d.add({type:"link",sourceId:X0.sourceId,targetId:X0.targetId,edges:X0.edges,timestamp:X0.timestamp,originUser:X0.originUser,originEthAddress:X0.originEthAddress,signature:X0.signature}),K0=!0,k0(X0.timestamp)},unlink(X0){if(MW(X0.timestamp))return;let C0=y.get(X0.sourceId);if(!C0||t.compare(C0.timestamp,X0.timestamp)>=0)return;if(C0.meta?.edges&&t.compare(C0.meta.edges.ts,X0.timestamp)>=0)return;if(s&&!s.op(X0,C0))return console.warn(`\u26A0\uFE0F [SYNC-AUTH] unlink denied: ${X0.sourceId} (${s.describe(X0,C0)})`);y.unlink(X0.sourceId,X0.targetId,X0.timestamp),H0(X0),t.update(X0.timestamp),d.add({type:"unlink",sourceId:X0.sourceId,targetId:X0.targetId,edges:X0.edges,timestamp:X0.timestamp,originUser:X0.originUser,originEthAddress:X0.originEthAddress,signature:X0.signature}),K0=!0,k0(X0.timestamp)},async sync({timestamp:X0,digest:C0}){if(C0&&C0===u0())return console.info("\uD83D\uDFF0 State digests match \u2014 nothing to send.");let x0=d.getOldest();if(X0==null||x0&&t.compare(X0,x0.timestamp)<0){console.info("\uD83D\uDCA5 Sending FULL state sync:",y.getAllNodes().length,"nodes"),await N0([{type:"fullStateSync",graphData:y.nodes,removals:d.getDelta(null).filter((N1)=>N1.type==="remove"),timestamp:o}]);return}let W8=d.getDelta(null);if(!W8.length)return;let d1=W8.flatMap((N1)=>{if(N1.type!=="upsert")return[N1];let c=y.get(N1.id);if(!c)return[];return s?.opOf(N1.id,c)??[{...N1,value:c.value}]});console.info("\uD83D\uDE80 Sending DELTA sync:",d1.length,"ops"),await N0([{type:"deltaSync",operations:d1,timestamp:o}])},deltaSync({operations:X0}){let C0=R1(X0);if(!Array.isArray(C0))return;console.info("\uD83D\uDCE5 deltaSync:",C0.length,"ops");for(let x0 of C0)if(x0&&Q1[x0.type])Q1[x0.type](x0)},async fullStateSync({graphData:X0,removals:C0,timestamp:x0,reciprocal:k1}){if(!X0||typeof X0!=="object")return;let W8=Object.entries(X0).sort(([N1],[c])=>c.startsWith("user:")-N1.startsWith("user:"));for(let[N1,c]of W8){let W0=(s?.opOf(N1,c)??[{type:"upsert",id:N1,value:c.value,timestamp:c.timestamp}]).map(Q1.upsert).includes(!0),Q0=y.nodes[N1];if(!Q0)continue;if(s){let T0=s.edges(N1,c,Q0);if(T0&&!MW(T0.timestamp))H0(T0)}else if(W0)Q0.edges=[...c.edges??[]]}for(let N1 of C0??[])Q1.remove(N1);let d1=new Set(Object.keys(X0));if(!k1&&Object.keys(y.nodes).some((N1)=>!d1.has(N1)))await N0([{type:"fullStateSync",graphData:y.nodes,removals:d.getDelta(null).filter((N1)=>N1.type==="remove"),timestamp:o,reciprocal:!0}]);if(K0=!0,console.info("\u2705 fullStateSync merged:",y.getAllNodes().length,"nodes"),x0&&!MW(x0))k0(x0),t.update(x0)}};for(let X0 of Y0)if(Q1[X0.type])await Q1[X0.type](X0);if(P0&&(!o||t.compare(P0,o)>0))$0(P0);if(K0)H1(),v1(),F1()},m0=AD(async()=>{let Y0=r.splice(0);if(!Y0.length)return!1;let K0=await S1(Y0);if(!K0)r.unshift(...Y0),setTimeout(()=>m0().catch(()=>{}),1000);return K0},16);if(Object.assign(_,{use(Y0){if(typeof Y0==="function")p.push(Y0)},async put(Y0,K0){let P0=t.now();$0(P0);let k0=Y0?.owner??Y0?._meta?.owner;K0??=k0?`${k0}:${crypto.randomUUID()}`:crypto.randomUUID(),y.upsert(K0,Y0,P0),d.add({type:"upsert",id:K0,timestamp:P0}),H1(),v1();try{r.push({type:"upsert",id:K0,value:Y0,timestamp:P0}),m0().catch(()=>{})}finally{F1()}return K0},async get(Y0){if(typeof Y0!=="string")return{result:null};let K0=y.get(Y0);if(!K0)return{result:null};return{result:{...K0,value:zD(K0.value),edges:K0.edges.filter((P0)=>Object.hasOwn(y.nodes,P0))}}},map(...Y0){let P0={...{realtime:!1,query:{},field:null,order:"asc",$limit:null,$after:null,$before:null}},k0=null,R1=!1;Y0.forEach((C0)=>typeof C0==="function"?k0=C0:C0&&typeof C0==="object"&&(R1=R1||("realtime"in C0),Object.assign(P0,C0))),k0&&!R1&&(P0.realtime=!0);let Q1=aA(y.nodes,P0),X0=null;if(k0){if(Q1.forEach((C0)=>k0({id:C0.id,value:C0.value,edges:C0.edges,timestamp:C0.timestamp,action:"initial"})),P0.realtime){let C0=(x0)=>`${x0.id}:${x0.timestamp?.physical??0}:${x0.timestamp?.logical??0}:${(x0.edges??[]).join(",")}`;X0=(x0)=>{let k1=aA(x0,P0),W8=new Map(Q1.map((N1)=>[N1.id,N1])),d1=new Map(k1.map((N1)=>[N1.id,N1]));if(k1.length!==Q1.length||!k1.map(C0).every((N1,c)=>N1===Q1.map(C0)[c])){for(let[N1,c]of d1){let W0=W8.get(N1);if(!W0)k0({id:N1,value:c.value,edges:c.edges,timestamp:c.timestamp,action:"added"});else if(C0(c)!==C0(W0))k0({id:N1,value:c.value,edges:c.edges,timestamp:c.timestamp,action:"updated"})}for(let[N1,c]of W8)if(!d1.has(N1))k0({id:N1,value:null,edges:c.edges,timestamp:c.timestamp,action:"removed"});Q1=k1}},E.push(X0)}}return{results:Q1,...P0.realtime&&k0&&X0&&{unsubscribe:()=>{let C0=E.indexOf(X0);if(C0>=0)E.splice(C0,1)}}}},async link(Y0,K0){if(!y.nodes[Y0]||!y.nodes[K0])return;let P0=t.now();y.link(Y0,K0,P0);let k0=[...y.nodes[Y0].edges];d.add({type:"link",sourceId:Y0,targetId:K0,edges:k0,timestamp:P0}),H1(),v1(),$0(P0);try{r.push({type:"link",sourceId:Y0,targetId:K0,edges:k0,timestamp:P0}),m0().catch(()=>{})}finally{F1()}},async unlink(Y0,K0){if(!y.nodes[Y0]?.edges.includes(K0))return;let P0=t.now();y.unlink(Y0,K0,P0);let k0=[...y.nodes[Y0].edges];d.add({type:"unlink",sourceId:Y0,targetId:K0,edges:k0,timestamp:P0}),H1(),v1(),$0(P0);try{r.push({type:"unlink",sourceId:Y0,targetId:K0,edges:k0,timestamp:P0}),m0().catch(()=>{})}finally{F1()}},async remove(Y0){let K0=y.get(Y0);if(!K0)return;let P0=t.now();delete y.nodes[Y0],d.add({type:"remove",id:Y0,value:K0.value,timestamp:P0}),H1(),v1(),$0(P0);try{r.push({type:"remove",id:Y0,value:K0.value,timestamp:P0}),m0().catch(()=>{})}finally{F1()}},async clear(){y.nodes={},d.clear(),P.del("graph"),P.del("oplog"),h0()},on(Y0){return E.push(Y0),()=>{let K0=E.indexOf(Y0);if(K0>=0)E.splice(K0,1)}},close(){P.close()}}),l)_.use(h_({constitution:f,customRoles:h?.customRoles??null,getNode:(Y0)=>y.get(Y0)})),console.info("\uD83D\uDEE1\uFE0F SM: verifying incoming operations");try{let Y0=`graph-sync-room-${W}`,K0={appId:"1234",type:"superpeer",...Y&&{password:Y},...I&&{relayUrls:I},...H&&{turnConfig:H},...T&&{cells:!0},...T&&T!==!0&&{overlay:T},rtcPolyfill:V??zO};if(S=Bz(K0,Y0),B=S.channel("syncGraph"),console.info(`\u26A1 Transport: ${T?"cellular mesh":"full mesh"}`),u){let P0=B.send;B={...B,send:async(k0)=>{let R1=await u.signOps(k0),Q1=!1;for(let X0 of R1??[]){if(!X0?.signature)continue;if(X0.type!=="upsert"){if(d.sign(X0),Q1=!0,Array.isArray(X0.edges)&&g(y.get(X0.sourceId)?.edges,X0.edges))H0(X0);continue}let C0=y.get(X0.id);if(!C0||!g(C0.value,X0.value))continue;let x0=s.receipt(X0,C0,C0);if(x0)C0.meta=x0,Q1=!0}if(Q1)H1(),v1();return P0(R1)}},_.sm=u}if(!T){let P0=!1;S.channel("c0").on("message",()=>{if(P0)return;P0=!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)_.room=Bz(K0,`app-sync-${W}`),console.info("\u26A1 db.room joined \u2014 visible to monitors/presence");S.on("peer:join",(P0)=>{console.info("\u26A1 Peer connected:",P0);for(let k0 of[0,1500,4000,9000])setTimeout(()=>S1([{type:"sync",timestamp:o,digest:u0()}]),k0)}),S.on("peer:leave",(P0)=>console.info("\u26A1 Peer disconnected:",P0)),B.on("message",async(P0)=>{let k0;try{k0=P0 instanceof Uint8Array||P0 instanceof ArrayBuffer?(()=>{let Q1=zW(P0);return Array.isArray(Q1)?Q1:[Q1]})():Array.isArray(P0)?P0:[P0]}catch(Q1){return console.error("\u274C decode failed:",Q1)}let R1=new Map([...new Set(k0.flatMap((Q1)=>["id","sourceId","targetId"].map((X0)=>Q1?.[X0]).filter(Boolean)))].map((Q1)=>y.get(Q1)?[Q1,zD(y.get(Q1))]:null).filter(Boolean));for(let Q1 of p)try{if(k0=await Q1(k0,R1),!k0?.length)return}catch(X0){console.error("\u274C Middleware error:",X0);return}await F0(k0)}),console.info("\u2705 GenosRTC sync enabled")}catch(Y0){console.warn("\u26A0\uFE0F GenosRTC not available:",Y0.message)}if(v(),m(),U0(),u){let Y0=h?.governanceRules??null;if(!Y0&&process.env.GDB_SM_RULES){let K0=process.env.GDB_SM_RULES.trim();try{if(K0.startsWith("["))Y0=JSON.parse(K0);else if(K0.startsWith("{"))Y0=[JSON.parse(K0)];else Y0=(await import(new URL(K0,`file://${process.cwd()}/`).href)).default}catch(P0){console.error("\u274C GOVERNANCE: could not load GDB_SM_RULES:",P0.message)}}if(Array.isArray(Y0)&&Y0.length)_.governance=b_(_,u,Y0,{customRoles:h?.customRoles??null})}if(O)_.relay=O;return Object.defineProperties(_,{syncChannel:{get:()=>B},hybridClock:{get:()=>t},graph:{get:()=>({getAllNodes:()=>y.getAllNodes(),get:(Y0)=>y.get(Y0)})}}),console.info(`\u2705 GDBServer [${W}] ready (bun:sqlite)`),_}if(import.meta.main){let W=new Set(["ECONNREFUSED","ECONNRESET","EHOSTUNREACH","ENETUNREACH","EADDRNOTAVAIL","ETIMEDOUT","EPIPE"]),X=(Z)=>W.has(Z?.code)||W.has(Z?.errno),G=new Map,Y=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);Y??=setTimeout(()=>{Y=null;let U=[...G].filter(([,Q])=>Q>1).map(([Q,N])=>`${Q} \xD7${N}`).join(", ");if(U)console.warn("\u26A0\uFE0F Transient network errors (ignored, last 60s):",U);G.clear()},60000)};process.on("uncaughtException",(Z)=>{if(X(Z))return J(Z?.code??Z?.errno);console.error("\u274C Fatal:",Z?.message??Z),process.exit(1)}),process.on("unhandledRejection",(Z)=>{if(X(Z))return J(Z?.code??Z?.errno);console.error("\u274C Fatal (rejection):",Z?.message??Z),process.exit(1)}),bt().catch((Z)=>{console.error("\u274C Fatal:",Z.message),process.exit(1)})}export{bt as gdbServer};