@urun-sh/core 0.1.38 → 0.1.41

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.
@@ -0,0 +1,130 @@
1
+ import{a as Gt,b as Ve,c as iy,d as it,e as K5,f as $5,g as W5,h as G5}from"./chunk-FNR7JDXN.mjs";var hi=Ve(oy=>{"use strict";function X5(){var t,e=!1,r=this;r._DeArray=function(n,s,i){return[n.slice(s,s+i)]},r._EnArray=function(n,s,i,o){for(var a=0;a<i;n[s+a]=o[a]?o[a]:0,a++);},r._DeChar=function(n,s){return String.fromCharCode(n[s])},r._EnChar=function(n,s,i){n[s]=i.charCodeAt(0)},r._DeInt=function(n,s){var i=e?t.len-1:0,o=e?-1:1,a=i+o*t.len,c,f,l;for(c=0,f=i,l=1;f!=a;c+=n[s+f]*l,f+=o,l*=256);return t.bSigned&&c&Math.pow(2,t.len*8-1)&&(c-=Math.pow(2,t.len*8)),c},r._EnInt=function(n,s,i){var o=e?t.len-1:0,a=e?-1:1,c=o+a*t.len,f;for(i=i<t.min?t.min:i>t.max?t.max:i,f=o;f!=c;n[s+f]=i&255,f+=a,i>>=8);},r._DeString=function(n,s,i){for(var o=new Array(i),a=0;a<i;o[a]=String.fromCharCode(n[s+a]),a++);return o.join("")},r._EnString=function(n,s,i,o){for(var a,c=0;c<i;n[s+c]=(a=o.charCodeAt(c))?a:0,c++);},r._De754=function(n,s){var i,o,a,c,f,l,p,x,v,S;for(p=t.mLen,x=t.len*8-t.mLen-1,S=(1<<x)-1,v=S>>1,c=e?0:t.len-1,f=e?1:-1,i=n[s+c],c+=f,l=-7,o=i&(1<<-l)-1,i>>=-l,l+=x;l>0;o=o*256+n[s+c],c+=f,l-=8);for(a=o&(1<<-l)-1,o>>=-l,l+=p;l>0;a=a*256+n[s+c],c+=f,l-=8);switch(o){case 0:o=1-v;break;case S:return a?NaN:(i?-1:1)*(1/0);default:a=a+Math.pow(2,p),o=o-v;break}return(i?-1:1)*a*Math.pow(2,o-p)},r._En754=function(n,s,i){var o,a,c,f,l,p,x,v,S,I;for(x=t.mLen,v=t.len*8-t.mLen-1,I=(1<<v)-1,S=I>>1,o=i<0?1:0,i=Math.abs(i),isNaN(i)||i==1/0?(c=isNaN(i)?1:0,a=I):(a=Math.floor(Math.log(i)/Math.LN2),i*(p=Math.pow(2,-a))<1&&(a--,p*=2),a+S>=1?i+=t.rt/p:i+=t.rt*Math.pow(2,1-S),i*p>=2&&(a++,p/=2),a+S>=I?(c=0,a=I):a+S>=1?(c=(i*p-1)*Math.pow(2,x),a=a+S):(c=i*Math.pow(2,S-1)*Math.pow(2,x),a=0)),f=e?t.len-1:0,l=e?-1:1;x>=8;n[s+f]=c&255,f+=l,c/=256,x-=8);for(a=a<<x|c,v+=x;v>0;n[s+f]=a&255,f+=l,a/=256,v-=8);n[s+f-l]|=o*128},r._DeInt64=function(n,s){var i=e?0:7,o=e?1:-1,a=i+o*8,c=[0,0,!t.bSigned],f,l,p;for(f=i,p=1,l=0;f!=a;c[p]=(c[p]<<8>>>0)+n[s+f],f+=o,l++,p=l<4?1:0);return c},r._EnInt64=function(n,s,i){var o=e?0:7,a=e?1:-1,c=o+a*8,f,l,p,x;for(f=o,p=1,l=0,x=24;f!=c;n[s+f]=i[p]>>x&255,f+=a,l++,p=l<4?1:0,x=24-8*(l%4));},r._sPattern="(\\d + )?([AxcbBhHsfdiIlLqQ])",r._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},r._elLut={A:{en:r._EnArray,de:r._DeArray},s:{en:r._EnString,de:r._DeString},c:{en:r._EnChar,de:r._DeChar},b:{en:r._EnInt,de:r._DeInt,len:1,bSigned:!0,min:-Math.pow(2,7),max:Math.pow(2,7)-1},B:{en:r._EnInt,de:r._DeInt,len:1,bSigned:!1,min:0,max:Math.pow(2,8)-1},h:{en:r._EnInt,de:r._DeInt,len:2,bSigned:!0,min:-Math.pow(2,15),max:Math.pow(2,15)-1},H:{en:r._EnInt,de:r._DeInt,len:2,bSigned:!1,min:0,max:Math.pow(2,16)-1},i:{en:r._EnInt,de:r._DeInt,len:4,bSigned:!0,min:-Math.pow(2,31),max:Math.pow(2,31)-1},I:{en:r._EnInt,de:r._DeInt,len:4,bSigned:!1,min:0,max:Math.pow(2,32)-1},l:{en:r._EnInt,de:r._DeInt,len:4,bSigned:!0,min:-Math.pow(2,31),max:Math.pow(2,31)-1},L:{en:r._EnInt,de:r._DeInt,len:4,bSigned:!1,min:0,max:Math.pow(2,32)-1},f:{en:r._En754,de:r._De754,len:4,mLen:23,rt:Math.pow(2,-24)-Math.pow(2,-77)},d:{en:r._En754,de:r._De754,len:8,mLen:52,rt:0},q:{en:r._EnInt64,de:r._DeInt64,bSigned:!0},Q:{en:r._EnInt64,de:r._DeInt64,bSigned:!1}},r._UnpackSeries=function(n,s,i,o){for(var a=t.de,c=[],f=0;f<n;c.push(a(i,o+f*s)),f++);return c},r._PackSeries=function(n,s,i,o,a,c){for(var f=t.en,l=0;l<n;f(i,o+l*s,a[c+l]),l++);},r.Unpack=function(n,s,i){e=n.charAt(0)!="<",i=i||0;for(var o=new RegExp(this._sPattern,"g"),a,c,f,l=[];a=o.exec(n);){if(c=a[1]==null||a[1]==""?1:parseInt(a[1]),f=this._lenLut[a[2]],i+c*f>s.length)return;switch(a[2]){case"A":case"s":l.push(this._elLut[a[2]].de(s,i,c));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":t=this._elLut[a[2]],l.push(this._UnpackSeries(c,f,s,i));break}i+=c*f}return Array.prototype.concat.apply([],l)},r.PackTo=function(n,s,i,o){e=n.charAt(0)!="<";for(var a=new RegExp(this._sPattern,"g"),c,f,l,p,x=0;c=a.exec(n);){if(f=c[1]==null||c[1]==""?1:parseInt(c[1]),l=this._lenLut[c[2]],i+f*l>s.length)return!1;switch(c[2]){case"A":case"s":if(x+1>o.length)return!1;this._elLut[c[2]].en(s,i,f,o[x]),x+=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(t=this._elLut[c[2]],x+f>o.length)return!1;this._PackSeries(f,l,s,i,o,x),x+=f;break;case"x":for(p=0;p<f;p++)s[i+p]=0;break}i+=f*l}return s},r.Pack=function(n,s){return this.PackTo(n,new Array(this.CalcLength(n)),0,s)},r.CalcLength=function(n){for(var s=new RegExp(this._sPattern,"g"),i=0,o;o=s.exec(n);)i+=(o[1]==null||o[1]==""?1:parseInt(o[1]))*this._lenLut[o[2]];return i}}oy.jspack=new X5});var vp=Ve((Zk,ay)=>{"use strict";function Y5(t){r.debug=r,r.default=r,r.coerce=c,r.disable=o,r.enable=s,r.enabled=a,r.humanize=$5(),r.destroy=f,Object.keys(t).forEach(l=>{r[l]=t[l]}),r.names=[],r.skips=[],r.formatters={};function e(l){let p=0;for(let x=0;x<l.length;x++)p=(p<<5)-p+l.charCodeAt(x),p|=0;return r.colors[Math.abs(p)%r.colors.length]}r.selectColor=e;function r(l){let p,x=null,v,S;function I(...L){if(!I.enabled)return;let ee=I,Pe=Number(new Date),ie=Pe-(p||Pe);ee.diff=ie,ee.prev=p,ee.curr=Pe,p=Pe,L[0]=r.coerce(L[0]),typeof L[0]!="string"&&L.unshift("%O");let ve=0;L[0]=L[0].replace(/%([a-zA-Z%])/g,(he,Ne)=>{if(he==="%%")return"%";ve++;let we=r.formatters[Ne];if(typeof we=="function"){let X=L[ve];he=we.call(ee,X),L.splice(ve,1),ve--}return he}),r.formatArgs.call(ee,L),(ee.log||r.log).apply(ee,L)}return I.namespace=l,I.useColors=r.useColors(),I.color=r.selectColor(l),I.extend=n,I.destroy=r.destroy,Object.defineProperty(I,"enabled",{enumerable:!0,configurable:!1,get:()=>x!==null?x:(v!==r.namespaces&&(v=r.namespaces,S=r.enabled(l)),S),set:L=>{x=L}}),typeof r.init=="function"&&r.init(I),I}function n(l,p){let x=r(this.namespace+(typeof p>"u"?":":p)+l);return x.log=this.log,x}function s(l){r.save(l),r.namespaces=l,r.names=[],r.skips=[];let p=(typeof l=="string"?l:"").trim().replace(" ",",").split(",").filter(Boolean);for(let x of p)x[0]==="-"?r.skips.push(x.slice(1)):r.names.push(x)}function i(l,p){let x=0,v=0,S=-1,I=0;for(;x<l.length;)if(v<p.length&&(p[v]===l[x]||p[v]==="*"))p[v]==="*"?(S=v,I=x,v++):(x++,v++);else if(S!==-1)v=S+1,I++,x=I;else return!1;for(;v<p.length&&p[v]==="*";)v++;return v===p.length}function o(){let l=[...r.names,...r.skips.map(p=>"-"+p)].join(",");return r.enable(""),l}function a(l){for(let p of r.skips)if(i(l,p))return!1;for(let p of r.names)if(i(l,p))return!0;return!1}function c(l){return l instanceof Error?l.stack||l.message:l}function f(){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 r.enable(r.load()),r}ay.exports=Y5});var cy=Ve((Xr,ul)=>{"use strict";Xr.formatArgs=J5;Xr.save=Q5;Xr.load=eE;Xr.useColors=Z5;Xr.storage=tE();Xr.destroy=(()=>{let t=!1;return()=>{t||(t=!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`."))}})();Xr.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 Z5(){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 t;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&&(t=navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/))&&parseInt(t[1],10)>=31||typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)}function J5(t){if(t[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+t[0]+(this.useColors?"%c ":" ")+"+"+ul.exports.humanize(this.diff),!this.useColors)return;let e="color: "+this.color;t.splice(1,0,e,"color: inherit");let r=0,n=0;t[0].replace(/%[a-zA-Z%]/g,s=>{s!=="%%"&&(r++,s==="%c"&&(n=r))}),t.splice(n,0,e)}Xr.log=console.debug||console.log||(()=>{});function Q5(t){try{t?Xr.storage.setItem("debug",t):Xr.storage.removeItem("debug")}catch{}}function eE(){let t;try{t=Xr.storage.getItem("debug")}catch{}return!t&&typeof process<"u"&&"env"in process&&(t=process.env.DEBUG),t}function tE(){try{return localStorage}catch{}}ul.exports=vp()(Xr);var{formatters:rE}=ul.exports;rE.j=function(t){try{return JSON.stringify(t)}catch(e){return"[UnexpectedJSONParseError]: "+e.message}}});var fy=Ve((ir,dl)=>{"use strict";var nE=Gt("tty"),fl=Gt("util");ir.init=fE;ir.log=aE;ir.formatArgs=iE;ir.save=cE;ir.load=uE;ir.useColors=sE;ir.destroy=fl.deprecate(()=>{},"Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.");ir.colors=[6,2,3,4,5,1];try{let t=(G5(),K5(W5));t&&(t.stderr||t).level>=2&&(ir.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{}ir.inspectOpts=Object.keys(process.env).filter(t=>/^debug_/i.test(t)).reduce((t,e)=>{let r=e.substring(6).toLowerCase().replace(/_([a-z])/g,(s,i)=>i.toUpperCase()),n=process.env[e];return/^(yes|on|true|enabled)$/i.test(n)?n=!0:/^(no|off|false|disabled)$/i.test(n)?n=!1:n==="null"?n=null:n=Number(n),t[r]=n,t},{});function sE(){return"colors"in ir.inspectOpts?!!ir.inspectOpts.colors:nE.isatty(process.stderr.fd)}function iE(t){let{namespace:e,useColors:r}=this;if(r){let n=this.color,s="\x1B[3"+(n<8?n:"8;5;"+n),i=` ${s};1m${e} \x1B[0m`;t[0]=i+t[0].split(`
2
+ `).join(`
3
+ `+i),t.push(s+"m+"+dl.exports.humanize(this.diff)+"\x1B[0m")}else t[0]=oE()+e+" "+t[0]}function oE(){return ir.inspectOpts.hideDate?"":new Date().toISOString()+" "}function aE(...t){return process.stderr.write(fl.formatWithOptions(ir.inspectOpts,...t)+`
4
+ `)}function cE(t){t?process.env.DEBUG=t:delete process.env.DEBUG}function uE(){return process.env.DEBUG}function fE(t){t.inspectOpts={};let e=Object.keys(ir.inspectOpts);for(let r=0;r<e.length;r++)t.inspectOpts[e[r]]=ir.inspectOpts[e[r]]}dl.exports=vp()(ir);var{formatters:uy}=dl.exports;uy.o=function(t){return this.inspectOpts.colors=this.useColors,fl.inspect(t,this.inspectOpts).split(`
5
+ `).map(e=>e.trim()).join(" ")};uy.O=function(t){return this.inspectOpts.colors=this.useColors,fl.inspect(t,this.inspectOpts)}});var dy=Ve((Jk,wp)=>{"use strict";typeof process>"u"||process.type==="renderer"||process.browser===!0||process.__nwjs?wp.exports=cy():wp.exports=fy()});var ll=Ve(za=>{"use strict";Object.defineProperty(za,"__esModule",{value:!0});var dE=Gt("net");function lE(t){switch(dE.isIP(t)){case 4:return Buffer.from(t.split(".").map(s=>parseInt(s,10)));case 6:let e=t.split(":"),r=Buffer.alloc(16),n=0;e[e.length-1]===""&&(e[e.length-1]="0");for(let s=0;s<e.length;s++){if(e[s]===""){s+1<e.length&&e[s+1]!==""&&(n=16-(e.length-s-1)*2);continue}r.writeUInt16BE(parseInt(e[s],16),n),n+=2}return r;default:return null}}za.bytesFromIP=lE;function hE(t){switch(t.length){case 4:return[t[0],t[1],t[2],t[3]].join(".");case 16:let e=[],r=-1,n=0,s=-1,i=0;for(let o=0;o<t.length;o+=2){let a=t[o]<<8|t[o+1];a===0?(n++,r===-1&&(r=e.length),n>i&&(i=n,s=r)):(r=-1,n=0),e.push(a.toString(16))}if(i>0){let o="",a=e.slice(s+i);e.length=s,e.length===0&&(o+=":"),a.length===0&&(o+=":"),e.push(o,...a)}return e.join(":");default:return""}}za.bytesToIP=hE;var pi=Object.create(null),ly=/^[0-9.]+$/;function pE(t){return ly.test(t)&&pi[t]!==""?t:pi[t]==null?"":pi[t]}za.getOID=pE;function xE(t){return!ly.test(t)&&pi[t]!==""||pi[t]==null?t:pi[t]}za.getOIDName=xE;function $(t,e){pi[t]=e,pi[e]=t}$("1.2.840.113549.1.1.1","rsaEncryption");$("1.2.840.113549.1.1.4","md5WithRsaEncryption");$("1.2.840.113549.1.1.5","sha1WithRsaEncryption");$("1.2.840.113549.1.1.8","mgf1");$("1.2.840.113549.1.1.10","RSASSA-PSS");$("1.2.840.113549.1.1.11","sha256WithRsaEncryption");$("1.2.840.113549.1.1.12","sha384WithRsaEncryption");$("1.2.840.113549.1.1.13","sha512WithRsaEncryption");$("1.2.840.10045.2.1","ecEncryption");$("1.2.840.10045.4.1","ecdsaWithSha1");$("1.2.840.10045.4.3.2","ecdsaWithSha256");$("1.2.840.10045.4.3.3","ecdsaWithSha384");$("1.2.840.10045.4.3.4","ecdsaWithSha512");$("1.2.840.10040.4.3","dsaWithSha1");$("2.16.840.1.101.3.4.3.2","dsaWithSha256");$("1.3.14.3.2.7","desCBC");$("1.3.14.3.2.26","sha1");$("2.16.840.1.101.3.4.2.1","sha256");$("2.16.840.1.101.3.4.2.2","sha384");$("2.16.840.1.101.3.4.2.3","sha512");$("1.2.840.113549.2.5","md5");$("1.3.101.110","X25519");$("1.3.101.111","X448");$("1.3.101.112","Ed25519");$("1.3.101.113","Ed448");$("1.2.840.113549.1.7.1","data");$("1.2.840.113549.1.7.2","signedData");$("1.2.840.113549.1.7.3","envelopedData");$("1.2.840.113549.1.7.4","signedAndEnvelopedData");$("1.2.840.113549.1.7.5","digestedData");$("1.2.840.113549.1.7.6","encryptedData");$("1.2.840.113549.1.9.1","emailAddress");$("1.2.840.113549.1.9.2","unstructuredName");$("1.2.840.113549.1.9.3","contentType");$("1.2.840.113549.1.9.4","messageDigest");$("1.2.840.113549.1.9.5","signingTime");$("1.2.840.113549.1.9.6","counterSignature");$("1.2.840.113549.1.9.7","challengePassword");$("1.2.840.113549.1.9.8","unstructuredAddress");$("1.2.840.113549.1.9.14","extensionRequest");$("1.2.840.113549.1.9.20","friendlyName");$("1.2.840.113549.1.9.21","localKeyId");$("1.2.840.113549.1.9.22.1","x509Certificate");$("1.2.840.113549.1.12.10.1.1","keyBag");$("1.2.840.113549.1.12.10.1.2","pkcs8ShroudedKeyBag");$("1.2.840.113549.1.12.10.1.3","certBag");$("1.2.840.113549.1.12.10.1.4","crlBag");$("1.2.840.113549.1.12.10.1.5","secretBag");$("1.2.840.113549.1.12.10.1.6","safeContentsBag");$("1.2.840.113549.1.5.13","pkcs5PBES2");$("1.2.840.113549.1.5.12","pkcs5PBKDF2");$("1.2.840.113549.2.7","hmacWithSha1");$("1.2.840.113549.2.9","hmacWithSha256");$("1.2.840.113549.2.10","hmacWithSha384");$("1.2.840.113549.2.11","hmacWithSha512");$("1.2.840.113549.3.7","3desCBC");$("2.16.840.1.101.3.4.1.2","aesCBC128");$("2.16.840.1.101.3.4.1.42","aesCBC256");$("2.5.4.3","commonName");$("2.5.4.5","serialName");$("2.5.4.6","countryName");$("2.5.4.7","localityName");$("2.5.4.8","stateOrProvinceName");$("2.5.4.10","organizationName");$("2.5.4.11","organizationalUnitName");$("2.5.4.15","businessCategory");$("2.16.840.1.113730.1.1","nsCertType");$("2.5.29.2","keyAttributes");$("2.5.29.4","keyUsageRestriction");$("2.5.29.6","subtreesConstraint");$("2.5.29.9","subjectDirectoryAttributes");$("2.5.29.14","subjectKeyIdentifier");$("2.5.29.15","keyUsage");$("2.5.29.16","privateKeyUsagePeriod");$("2.5.29.17","subjectAltName");$("2.5.29.18","issuerAltName");$("2.5.29.19","basicConstraints");$("2.5.29.20","cRLNumber");$("2.5.29.21","cRLReason");$("2.5.29.22","expirationDate");$("2.5.29.23","instructionCode");$("2.5.29.24","invalidityDate");$("2.5.29.27","deltaCRLIndicator");$("2.5.29.28","issuingDistributionPoint");$("2.5.29.29","certificateIssuer");$("2.5.29.30","nameConstraints");$("2.5.29.31","cRLDistributionPoints");$("2.5.29.32","certificatePolicies");$("2.5.29.33","policyMappings");$("2.5.29.35","authorityKeyIdentifier");$("2.5.29.36","policyConstraints");$("2.5.29.37","extKeyUsage");$("2.5.29.46","freshestCRL");$("2.5.29.54","inhibitAnyPolicy");$("1.3.6.1.4.1.311.60.2.1.2","jurisdictionST");$("1.3.6.1.4.1.311.60.2.1.3","jurisdictionC");$("1.3.6.1.4.1.11129.2.4.2","timestampList");$("1.3.6.1.5.5.7.1.1","authorityInfoAccess");$("1.3.6.1.5.5.7.3.1","serverAuth");$("1.3.6.1.5.5.7.3.2","clientAuth");$("1.3.6.1.5.5.7.3.3","codeSigning");$("1.3.6.1.5.5.7.3.4","emailProtection");$("1.3.6.1.5.5.7.3.8","timeStamping");$("1.3.6.1.5.5.7.48.1","authorityInfoAccessOcsp");$("1.3.6.1.5.5.7.48.2","authorityInfoAccessIssuers")});var pl=Ve((eR,hl)=>{"use strict";(function(t){"use strict";var e=function(h){var y,g=new Float64Array(16);if(h)for(y=0;y<h.length;y++)g[y]=h[y];return g},r=function(){throw new Error("no PRNG")},n=new Uint8Array(16),s=new Uint8Array(32);s[0]=9;var i=e(),o=e([1]),a=e([56129,1]),c=e([30883,4953,19914,30187,55467,16705,2637,112,59544,30585,16505,36039,65139,11119,27886,20995]),f=e([61785,9906,39828,60374,45398,33411,5274,224,53552,61171,33010,6542,64743,22239,55772,9222]),l=e([54554,36645,11616,51542,42930,38181,51040,26924,56412,64982,57905,49316,21502,52590,14035,8553]),p=e([26200,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214]),x=e([41136,18958,6951,50414,58488,44335,6150,12099,55207,15867,153,11085,57099,20417,9344,11139]);function v(h,y,g,u){h[y]=g>>24&255,h[y+1]=g>>16&255,h[y+2]=g>>8&255,h[y+3]=g&255,h[y+4]=u>>24&255,h[y+5]=u>>16&255,h[y+6]=u>>8&255,h[y+7]=u&255}function S(h,y,g,u,b){var _,R=0;for(_=0;_<b;_++)R|=h[y+_]^g[u+_];return(1&R-1>>>8)-1}function I(h,y,g,u){return S(h,y,g,u,16)}function L(h,y,g,u){return S(h,y,g,u,32)}function ee(h,y,g,u){for(var b=u[0]&255|(u[1]&255)<<8|(u[2]&255)<<16|(u[3]&255)<<24,_=g[0]&255|(g[1]&255)<<8|(g[2]&255)<<16|(g[3]&255)<<24,R=g[4]&255|(g[5]&255)<<8|(g[6]&255)<<16|(g[7]&255)<<24,F=g[8]&255|(g[9]&255)<<8|(g[10]&255)<<16|(g[11]&255)<<24,Q=g[12]&255|(g[13]&255)<<8|(g[14]&255)<<16|(g[15]&255)<<24,_e=u[4]&255|(u[5]&255)<<8|(u[6]&255)<<16|(u[7]&255)<<24,le=y[0]&255|(y[1]&255)<<8|(y[2]&255)<<16|(y[3]&255)<<24,bt=y[4]&255|(y[5]&255)<<8|(y[6]&255)<<16|(y[7]&255)<<24,ye=y[8]&255|(y[9]&255)<<8|(y[10]&255)<<16|(y[11]&255)<<24,Fe=y[12]&255|(y[13]&255)<<8|(y[14]&255)<<16|(y[15]&255)<<24,$e=u[8]&255|(u[9]&255)<<8|(u[10]&255)<<16|(u[11]&255)<<24,rt=g[16]&255|(g[17]&255)<<8|(g[18]&255)<<16|(g[19]&255)<<24,Qe=g[20]&255|(g[21]&255)<<8|(g[22]&255)<<16|(g[23]&255)<<24,We=g[24]&255|(g[25]&255)<<8|(g[26]&255)<<16|(g[27]&255)<<24,Ze=g[28]&255|(g[29]&255)<<8|(g[30]&255)<<16|(g[31]&255)<<24,Ge=u[12]&255|(u[13]&255)<<8|(u[14]&255)<<16|(u[15]&255)<<24,Ee=b,Oe=_,pe=R,Ae=F,Ie=Q,fe=_e,U=le,D=bt,W=ye,z=Fe,K=$e,Y=rt,qe=Qe,nt=We,ot=Ze,st=Ge,E,ft=0;ft<20;ft+=2)E=Ee+qe|0,Ie^=E<<7|E>>>25,E=Ie+Ee|0,W^=E<<9|E>>>23,E=W+Ie|0,qe^=E<<13|E>>>19,E=qe+W|0,Ee^=E<<18|E>>>14,E=fe+Oe|0,z^=E<<7|E>>>25,E=z+fe|0,nt^=E<<9|E>>>23,E=nt+z|0,Oe^=E<<13|E>>>19,E=Oe+nt|0,fe^=E<<18|E>>>14,E=K+U|0,ot^=E<<7|E>>>25,E=ot+K|0,pe^=E<<9|E>>>23,E=pe+ot|0,U^=E<<13|E>>>19,E=U+pe|0,K^=E<<18|E>>>14,E=st+Y|0,Ae^=E<<7|E>>>25,E=Ae+st|0,D^=E<<9|E>>>23,E=D+Ae|0,Y^=E<<13|E>>>19,E=Y+D|0,st^=E<<18|E>>>14,E=Ee+Ae|0,Oe^=E<<7|E>>>25,E=Oe+Ee|0,pe^=E<<9|E>>>23,E=pe+Oe|0,Ae^=E<<13|E>>>19,E=Ae+pe|0,Ee^=E<<18|E>>>14,E=fe+Ie|0,U^=E<<7|E>>>25,E=U+fe|0,D^=E<<9|E>>>23,E=D+U|0,Ie^=E<<13|E>>>19,E=Ie+D|0,fe^=E<<18|E>>>14,E=K+z|0,Y^=E<<7|E>>>25,E=Y+K|0,W^=E<<9|E>>>23,E=W+Y|0,z^=E<<13|E>>>19,E=z+W|0,K^=E<<18|E>>>14,E=st+ot|0,qe^=E<<7|E>>>25,E=qe+st|0,nt^=E<<9|E>>>23,E=nt+qe|0,ot^=E<<13|E>>>19,E=ot+nt|0,st^=E<<18|E>>>14;Ee=Ee+b|0,Oe=Oe+_|0,pe=pe+R|0,Ae=Ae+F|0,Ie=Ie+Q|0,fe=fe+_e|0,U=U+le|0,D=D+bt|0,W=W+ye|0,z=z+Fe|0,K=K+$e|0,Y=Y+rt|0,qe=qe+Qe|0,nt=nt+We|0,ot=ot+Ze|0,st=st+Ge|0,h[0]=Ee>>>0&255,h[1]=Ee>>>8&255,h[2]=Ee>>>16&255,h[3]=Ee>>>24&255,h[4]=Oe>>>0&255,h[5]=Oe>>>8&255,h[6]=Oe>>>16&255,h[7]=Oe>>>24&255,h[8]=pe>>>0&255,h[9]=pe>>>8&255,h[10]=pe>>>16&255,h[11]=pe>>>24&255,h[12]=Ae>>>0&255,h[13]=Ae>>>8&255,h[14]=Ae>>>16&255,h[15]=Ae>>>24&255,h[16]=Ie>>>0&255,h[17]=Ie>>>8&255,h[18]=Ie>>>16&255,h[19]=Ie>>>24&255,h[20]=fe>>>0&255,h[21]=fe>>>8&255,h[22]=fe>>>16&255,h[23]=fe>>>24&255,h[24]=U>>>0&255,h[25]=U>>>8&255,h[26]=U>>>16&255,h[27]=U>>>24&255,h[28]=D>>>0&255,h[29]=D>>>8&255,h[30]=D>>>16&255,h[31]=D>>>24&255,h[32]=W>>>0&255,h[33]=W>>>8&255,h[34]=W>>>16&255,h[35]=W>>>24&255,h[36]=z>>>0&255,h[37]=z>>>8&255,h[38]=z>>>16&255,h[39]=z>>>24&255,h[40]=K>>>0&255,h[41]=K>>>8&255,h[42]=K>>>16&255,h[43]=K>>>24&255,h[44]=Y>>>0&255,h[45]=Y>>>8&255,h[46]=Y>>>16&255,h[47]=Y>>>24&255,h[48]=qe>>>0&255,h[49]=qe>>>8&255,h[50]=qe>>>16&255,h[51]=qe>>>24&255,h[52]=nt>>>0&255,h[53]=nt>>>8&255,h[54]=nt>>>16&255,h[55]=nt>>>24&255,h[56]=ot>>>0&255,h[57]=ot>>>8&255,h[58]=ot>>>16&255,h[59]=ot>>>24&255,h[60]=st>>>0&255,h[61]=st>>>8&255,h[62]=st>>>16&255,h[63]=st>>>24&255}function Pe(h,y,g,u){for(var b=u[0]&255|(u[1]&255)<<8|(u[2]&255)<<16|(u[3]&255)<<24,_=g[0]&255|(g[1]&255)<<8|(g[2]&255)<<16|(g[3]&255)<<24,R=g[4]&255|(g[5]&255)<<8|(g[6]&255)<<16|(g[7]&255)<<24,F=g[8]&255|(g[9]&255)<<8|(g[10]&255)<<16|(g[11]&255)<<24,Q=g[12]&255|(g[13]&255)<<8|(g[14]&255)<<16|(g[15]&255)<<24,_e=u[4]&255|(u[5]&255)<<8|(u[6]&255)<<16|(u[7]&255)<<24,le=y[0]&255|(y[1]&255)<<8|(y[2]&255)<<16|(y[3]&255)<<24,bt=y[4]&255|(y[5]&255)<<8|(y[6]&255)<<16|(y[7]&255)<<24,ye=y[8]&255|(y[9]&255)<<8|(y[10]&255)<<16|(y[11]&255)<<24,Fe=y[12]&255|(y[13]&255)<<8|(y[14]&255)<<16|(y[15]&255)<<24,$e=u[8]&255|(u[9]&255)<<8|(u[10]&255)<<16|(u[11]&255)<<24,rt=g[16]&255|(g[17]&255)<<8|(g[18]&255)<<16|(g[19]&255)<<24,Qe=g[20]&255|(g[21]&255)<<8|(g[22]&255)<<16|(g[23]&255)<<24,We=g[24]&255|(g[25]&255)<<8|(g[26]&255)<<16|(g[27]&255)<<24,Ze=g[28]&255|(g[29]&255)<<8|(g[30]&255)<<16|(g[31]&255)<<24,Ge=u[12]&255|(u[13]&255)<<8|(u[14]&255)<<16|(u[15]&255)<<24,Ee=b,Oe=_,pe=R,Ae=F,Ie=Q,fe=_e,U=le,D=bt,W=ye,z=Fe,K=$e,Y=rt,qe=Qe,nt=We,ot=Ze,st=Ge,E,ft=0;ft<20;ft+=2)E=Ee+qe|0,Ie^=E<<7|E>>>25,E=Ie+Ee|0,W^=E<<9|E>>>23,E=W+Ie|0,qe^=E<<13|E>>>19,E=qe+W|0,Ee^=E<<18|E>>>14,E=fe+Oe|0,z^=E<<7|E>>>25,E=z+fe|0,nt^=E<<9|E>>>23,E=nt+z|0,Oe^=E<<13|E>>>19,E=Oe+nt|0,fe^=E<<18|E>>>14,E=K+U|0,ot^=E<<7|E>>>25,E=ot+K|0,pe^=E<<9|E>>>23,E=pe+ot|0,U^=E<<13|E>>>19,E=U+pe|0,K^=E<<18|E>>>14,E=st+Y|0,Ae^=E<<7|E>>>25,E=Ae+st|0,D^=E<<9|E>>>23,E=D+Ae|0,Y^=E<<13|E>>>19,E=Y+D|0,st^=E<<18|E>>>14,E=Ee+Ae|0,Oe^=E<<7|E>>>25,E=Oe+Ee|0,pe^=E<<9|E>>>23,E=pe+Oe|0,Ae^=E<<13|E>>>19,E=Ae+pe|0,Ee^=E<<18|E>>>14,E=fe+Ie|0,U^=E<<7|E>>>25,E=U+fe|0,D^=E<<9|E>>>23,E=D+U|0,Ie^=E<<13|E>>>19,E=Ie+D|0,fe^=E<<18|E>>>14,E=K+z|0,Y^=E<<7|E>>>25,E=Y+K|0,W^=E<<9|E>>>23,E=W+Y|0,z^=E<<13|E>>>19,E=z+W|0,K^=E<<18|E>>>14,E=st+ot|0,qe^=E<<7|E>>>25,E=qe+st|0,nt^=E<<9|E>>>23,E=nt+qe|0,ot^=E<<13|E>>>19,E=ot+nt|0,st^=E<<18|E>>>14;h[0]=Ee>>>0&255,h[1]=Ee>>>8&255,h[2]=Ee>>>16&255,h[3]=Ee>>>24&255,h[4]=fe>>>0&255,h[5]=fe>>>8&255,h[6]=fe>>>16&255,h[7]=fe>>>24&255,h[8]=K>>>0&255,h[9]=K>>>8&255,h[10]=K>>>16&255,h[11]=K>>>24&255,h[12]=st>>>0&255,h[13]=st>>>8&255,h[14]=st>>>16&255,h[15]=st>>>24&255,h[16]=U>>>0&255,h[17]=U>>>8&255,h[18]=U>>>16&255,h[19]=U>>>24&255,h[20]=D>>>0&255,h[21]=D>>>8&255,h[22]=D>>>16&255,h[23]=D>>>24&255,h[24]=W>>>0&255,h[25]=W>>>8&255,h[26]=W>>>16&255,h[27]=W>>>24&255,h[28]=z>>>0&255,h[29]=z>>>8&255,h[30]=z>>>16&255,h[31]=z>>>24&255}function ie(h,y,g,u){ee(h,y,g,u)}function ve(h,y,g,u){Pe(h,y,g,u)}var ze=new Uint8Array([101,120,112,97,110,100,32,51,50,45,98,121,116,101,32,107]);function he(h,y,g,u,b,_,R){var F=new Uint8Array(16),Q=new Uint8Array(64),_e,le;for(le=0;le<16;le++)F[le]=0;for(le=0;le<8;le++)F[le]=_[le];for(;b>=64;){for(ie(Q,F,R,ze),le=0;le<64;le++)h[y+le]=g[u+le]^Q[le];for(_e=1,le=8;le<16;le++)_e=_e+(F[le]&255)|0,F[le]=_e&255,_e>>>=8;b-=64,y+=64,u+=64}if(b>0)for(ie(Q,F,R,ze),le=0;le<b;le++)h[y+le]=g[u+le]^Q[le];return 0}function Ne(h,y,g,u,b){var _=new Uint8Array(16),R=new Uint8Array(64),F,Q;for(Q=0;Q<16;Q++)_[Q]=0;for(Q=0;Q<8;Q++)_[Q]=u[Q];for(;g>=64;){for(ie(R,_,b,ze),Q=0;Q<64;Q++)h[y+Q]=R[Q];for(F=1,Q=8;Q<16;Q++)F=F+(_[Q]&255)|0,_[Q]=F&255,F>>>=8;g-=64,y+=64}if(g>0)for(ie(R,_,b,ze),Q=0;Q<g;Q++)h[y+Q]=R[Q];return 0}function we(h,y,g,u,b){var _=new Uint8Array(32);ve(_,u,b,ze);for(var R=new Uint8Array(8),F=0;F<8;F++)R[F]=u[F+16];return Ne(h,y,g,R,_)}function X(h,y,g,u,b,_,R){var F=new Uint8Array(32);ve(F,_,R,ze);for(var Q=new Uint8Array(8),_e=0;_e<8;_e++)Q[_e]=_[_e+16];return he(h,y,g,u,b,Q,F)}var ut=function(h){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 y,g,u,b,_,R,F,Q;y=h[0]&255|(h[1]&255)<<8,this.r[0]=y&8191,g=h[2]&255|(h[3]&255)<<8,this.r[1]=(y>>>13|g<<3)&8191,u=h[4]&255|(h[5]&255)<<8,this.r[2]=(g>>>10|u<<6)&7939,b=h[6]&255|(h[7]&255)<<8,this.r[3]=(u>>>7|b<<9)&8191,_=h[8]&255|(h[9]&255)<<8,this.r[4]=(b>>>4|_<<12)&255,this.r[5]=_>>>1&8190,R=h[10]&255|(h[11]&255)<<8,this.r[6]=(_>>>14|R<<2)&8191,F=h[12]&255|(h[13]&255)<<8,this.r[7]=(R>>>11|F<<5)&8065,Q=h[14]&255|(h[15]&255)<<8,this.r[8]=(F>>>8|Q<<8)&8191,this.r[9]=Q>>>5&127,this.pad[0]=h[16]&255|(h[17]&255)<<8,this.pad[1]=h[18]&255|(h[19]&255)<<8,this.pad[2]=h[20]&255|(h[21]&255)<<8,this.pad[3]=h[22]&255|(h[23]&255)<<8,this.pad[4]=h[24]&255|(h[25]&255)<<8,this.pad[5]=h[26]&255|(h[27]&255)<<8,this.pad[6]=h[28]&255|(h[29]&255)<<8,this.pad[7]=h[30]&255|(h[31]&255)<<8};ut.prototype.blocks=function(h,y,g){for(var u=this.fin?0:2048,b,_,R,F,Q,_e,le,bt,ye,Fe,$e,rt,Qe,We,Ze,Ge,Ee,Oe,pe,Ae=this.h[0],Ie=this.h[1],fe=this.h[2],U=this.h[3],D=this.h[4],W=this.h[5],z=this.h[6],K=this.h[7],Y=this.h[8],qe=this.h[9],nt=this.r[0],ot=this.r[1],st=this.r[2],E=this.r[3],ft=this.r[4],vt=this.r[5],wt=this.r[6],ct=this.r[7],xt=this.r[8],mt=this.r[9];g>=16;)b=h[y+0]&255|(h[y+1]&255)<<8,Ae+=b&8191,_=h[y+2]&255|(h[y+3]&255)<<8,Ie+=(b>>>13|_<<3)&8191,R=h[y+4]&255|(h[y+5]&255)<<8,fe+=(_>>>10|R<<6)&8191,F=h[y+6]&255|(h[y+7]&255)<<8,U+=(R>>>7|F<<9)&8191,Q=h[y+8]&255|(h[y+9]&255)<<8,D+=(F>>>4|Q<<12)&8191,W+=Q>>>1&8191,_e=h[y+10]&255|(h[y+11]&255)<<8,z+=(Q>>>14|_e<<2)&8191,le=h[y+12]&255|(h[y+13]&255)<<8,K+=(_e>>>11|le<<5)&8191,bt=h[y+14]&255|(h[y+15]&255)<<8,Y+=(le>>>8|bt<<8)&8191,qe+=bt>>>5|u,ye=0,Fe=ye,Fe+=Ae*nt,Fe+=Ie*(5*mt),Fe+=fe*(5*xt),Fe+=U*(5*ct),Fe+=D*(5*wt),ye=Fe>>>13,Fe&=8191,Fe+=W*(5*vt),Fe+=z*(5*ft),Fe+=K*(5*E),Fe+=Y*(5*st),Fe+=qe*(5*ot),ye+=Fe>>>13,Fe&=8191,$e=ye,$e+=Ae*ot,$e+=Ie*nt,$e+=fe*(5*mt),$e+=U*(5*xt),$e+=D*(5*ct),ye=$e>>>13,$e&=8191,$e+=W*(5*wt),$e+=z*(5*vt),$e+=K*(5*ft),$e+=Y*(5*E),$e+=qe*(5*st),ye+=$e>>>13,$e&=8191,rt=ye,rt+=Ae*st,rt+=Ie*ot,rt+=fe*nt,rt+=U*(5*mt),rt+=D*(5*xt),ye=rt>>>13,rt&=8191,rt+=W*(5*ct),rt+=z*(5*wt),rt+=K*(5*vt),rt+=Y*(5*ft),rt+=qe*(5*E),ye+=rt>>>13,rt&=8191,Qe=ye,Qe+=Ae*E,Qe+=Ie*st,Qe+=fe*ot,Qe+=U*nt,Qe+=D*(5*mt),ye=Qe>>>13,Qe&=8191,Qe+=W*(5*xt),Qe+=z*(5*ct),Qe+=K*(5*wt),Qe+=Y*(5*vt),Qe+=qe*(5*ft),ye+=Qe>>>13,Qe&=8191,We=ye,We+=Ae*ft,We+=Ie*E,We+=fe*st,We+=U*ot,We+=D*nt,ye=We>>>13,We&=8191,We+=W*(5*mt),We+=z*(5*xt),We+=K*(5*ct),We+=Y*(5*wt),We+=qe*(5*vt),ye+=We>>>13,We&=8191,Ze=ye,Ze+=Ae*vt,Ze+=Ie*ft,Ze+=fe*E,Ze+=U*st,Ze+=D*ot,ye=Ze>>>13,Ze&=8191,Ze+=W*nt,Ze+=z*(5*mt),Ze+=K*(5*xt),Ze+=Y*(5*ct),Ze+=qe*(5*wt),ye+=Ze>>>13,Ze&=8191,Ge=ye,Ge+=Ae*wt,Ge+=Ie*vt,Ge+=fe*ft,Ge+=U*E,Ge+=D*st,ye=Ge>>>13,Ge&=8191,Ge+=W*ot,Ge+=z*nt,Ge+=K*(5*mt),Ge+=Y*(5*xt),Ge+=qe*(5*ct),ye+=Ge>>>13,Ge&=8191,Ee=ye,Ee+=Ae*ct,Ee+=Ie*wt,Ee+=fe*vt,Ee+=U*ft,Ee+=D*E,ye=Ee>>>13,Ee&=8191,Ee+=W*st,Ee+=z*ot,Ee+=K*nt,Ee+=Y*(5*mt),Ee+=qe*(5*xt),ye+=Ee>>>13,Ee&=8191,Oe=ye,Oe+=Ae*xt,Oe+=Ie*ct,Oe+=fe*wt,Oe+=U*vt,Oe+=D*ft,ye=Oe>>>13,Oe&=8191,Oe+=W*E,Oe+=z*st,Oe+=K*ot,Oe+=Y*nt,Oe+=qe*(5*mt),ye+=Oe>>>13,Oe&=8191,pe=ye,pe+=Ae*mt,pe+=Ie*xt,pe+=fe*ct,pe+=U*wt,pe+=D*vt,ye=pe>>>13,pe&=8191,pe+=W*ft,pe+=z*E,pe+=K*st,pe+=Y*ot,pe+=qe*nt,ye+=pe>>>13,pe&=8191,ye=(ye<<2)+ye|0,ye=ye+Fe|0,Fe=ye&8191,ye=ye>>>13,$e+=ye,Ae=Fe,Ie=$e,fe=rt,U=Qe,D=We,W=Ze,z=Ge,K=Ee,Y=Oe,qe=pe,y+=16,g-=16;this.h[0]=Ae,this.h[1]=Ie,this.h[2]=fe,this.h[3]=U,this.h[4]=D,this.h[5]=W,this.h[6]=z,this.h[7]=K,this.h[8]=Y,this.h[9]=qe},ut.prototype.finish=function(h,y){var g=new Uint16Array(10),u,b,_,R;if(this.leftover){for(R=this.leftover,this.buffer[R++]=1;R<16;R++)this.buffer[R]=0;this.fin=1,this.blocks(this.buffer,0,16)}for(u=this.h[1]>>>13,this.h[1]&=8191,R=2;R<10;R++)this.h[R]+=u,u=this.h[R]>>>13,this.h[R]&=8191;for(this.h[0]+=u*5,u=this.h[0]>>>13,this.h[0]&=8191,this.h[1]+=u,u=this.h[1]>>>13,this.h[1]&=8191,this.h[2]+=u,g[0]=this.h[0]+5,u=g[0]>>>13,g[0]&=8191,R=1;R<10;R++)g[R]=this.h[R]+u,u=g[R]>>>13,g[R]&=8191;for(g[9]-=8192,b=(u^1)-1,R=0;R<10;R++)g[R]&=b;for(b=~b,R=0;R<10;R++)this.h[R]=this.h[R]&b|g[R];for(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,_=this.h[0]+this.pad[0],this.h[0]=_&65535,R=1;R<8;R++)_=(this.h[R]+this.pad[R]|0)+(_>>>16)|0,this.h[R]=_&65535;h[y+0]=this.h[0]>>>0&255,h[y+1]=this.h[0]>>>8&255,h[y+2]=this.h[1]>>>0&255,h[y+3]=this.h[1]>>>8&255,h[y+4]=this.h[2]>>>0&255,h[y+5]=this.h[2]>>>8&255,h[y+6]=this.h[3]>>>0&255,h[y+7]=this.h[3]>>>8&255,h[y+8]=this.h[4]>>>0&255,h[y+9]=this.h[4]>>>8&255,h[y+10]=this.h[5]>>>0&255,h[y+11]=this.h[5]>>>8&255,h[y+12]=this.h[6]>>>0&255,h[y+13]=this.h[6]>>>8&255,h[y+14]=this.h[7]>>>0&255,h[y+15]=this.h[7]>>>8&255},ut.prototype.update=function(h,y,g){var u,b;if(this.leftover){for(b=16-this.leftover,b>g&&(b=g),u=0;u<b;u++)this.buffer[this.leftover+u]=h[y+u];if(g-=b,y+=b,this.leftover+=b,this.leftover<16)return;this.blocks(this.buffer,0,16),this.leftover=0}if(g>=16&&(b=g-g%16,this.blocks(h,y,b),y+=b,g-=b),g){for(u=0;u<g;u++)this.buffer[this.leftover+u]=h[y+u];this.leftover+=g}};function St(h,y,g,u,b,_){var R=new ut(_);return R.update(g,u,b),R.finish(h,y),0}function He(h,y,g,u,b,_){var R=new Uint8Array(16);return St(R,0,g,u,b,_),I(h,y,R,0)}function q(h,y,g,u,b){var _;if(g<32)return-1;for(X(h,0,y,0,g,u,b),St(h,16,h,32,g-32,h),_=0;_<16;_++)h[_]=0;return 0}function V(h,y,g,u,b){var _,R=new Uint8Array(32);if(g<32||(we(R,0,32,u,b),He(y,16,y,32,g-32,R)!==0))return-1;for(X(h,0,y,0,g,u,b),_=0;_<32;_++)h[_]=0;return 0}function M(h,y){var g;for(g=0;g<16;g++)h[g]=y[g]|0}function oe(h){var y,g,u=1;for(y=0;y<16;y++)g=h[y]+u+65535,u=Math.floor(g/65536),h[y]=g-u*65536;h[0]+=u-1+37*(u-1)}function ge(h,y,g){for(var u,b=~(g-1),_=0;_<16;_++)u=b&(h[_]^y[_]),h[_]^=u,y[_]^=u}function Te(h,y){var g,u,b,_=e(),R=e();for(g=0;g<16;g++)R[g]=y[g];for(oe(R),oe(R),oe(R),u=0;u<2;u++){for(_[0]=R[0]-65517,g=1;g<15;g++)_[g]=R[g]-65535-(_[g-1]>>16&1),_[g-1]&=65535;_[15]=R[15]-32767-(_[14]>>16&1),b=_[15]>>16&1,_[14]&=65535,ge(R,_,1-b)}for(g=0;g<16;g++)h[2*g]=R[g]&255,h[2*g+1]=R[g]>>8}function A(h,y){var g=new Uint8Array(32),u=new Uint8Array(32);return Te(g,h),Te(u,y),L(g,0,u,0)}function T(h){var y=new Uint8Array(32);return Te(y,h),y[0]&1}function H(h,y){var g;for(g=0;g<16;g++)h[g]=y[2*g]+(y[2*g+1]<<8);h[15]&=32767}function C(h,y,g){for(var u=0;u<16;u++)h[u]=y[u]+g[u]}function N(h,y,g){for(var u=0;u<16;u++)h[u]=y[u]-g[u]}function Z(h,y,g){var u,b,_=0,R=0,F=0,Q=0,_e=0,le=0,bt=0,ye=0,Fe=0,$e=0,rt=0,Qe=0,We=0,Ze=0,Ge=0,Ee=0,Oe=0,pe=0,Ae=0,Ie=0,fe=0,U=0,D=0,W=0,z=0,K=0,Y=0,qe=0,nt=0,ot=0,st=0,E=g[0],ft=g[1],vt=g[2],wt=g[3],ct=g[4],xt=g[5],mt=g[6],$t=g[7],It=g[8],jt=g[9],qt=g[10],Vt=g[11],er=g[12],yr=g[13],br=g[14],vr=g[15];u=y[0],_+=u*E,R+=u*ft,F+=u*vt,Q+=u*wt,_e+=u*ct,le+=u*xt,bt+=u*mt,ye+=u*$t,Fe+=u*It,$e+=u*jt,rt+=u*qt,Qe+=u*Vt,We+=u*er,Ze+=u*yr,Ge+=u*br,Ee+=u*vr,u=y[1],R+=u*E,F+=u*ft,Q+=u*vt,_e+=u*wt,le+=u*ct,bt+=u*xt,ye+=u*mt,Fe+=u*$t,$e+=u*It,rt+=u*jt,Qe+=u*qt,We+=u*Vt,Ze+=u*er,Ge+=u*yr,Ee+=u*br,Oe+=u*vr,u=y[2],F+=u*E,Q+=u*ft,_e+=u*vt,le+=u*wt,bt+=u*ct,ye+=u*xt,Fe+=u*mt,$e+=u*$t,rt+=u*It,Qe+=u*jt,We+=u*qt,Ze+=u*Vt,Ge+=u*er,Ee+=u*yr,Oe+=u*br,pe+=u*vr,u=y[3],Q+=u*E,_e+=u*ft,le+=u*vt,bt+=u*wt,ye+=u*ct,Fe+=u*xt,$e+=u*mt,rt+=u*$t,Qe+=u*It,We+=u*jt,Ze+=u*qt,Ge+=u*Vt,Ee+=u*er,Oe+=u*yr,pe+=u*br,Ae+=u*vr,u=y[4],_e+=u*E,le+=u*ft,bt+=u*vt,ye+=u*wt,Fe+=u*ct,$e+=u*xt,rt+=u*mt,Qe+=u*$t,We+=u*It,Ze+=u*jt,Ge+=u*qt,Ee+=u*Vt,Oe+=u*er,pe+=u*yr,Ae+=u*br,Ie+=u*vr,u=y[5],le+=u*E,bt+=u*ft,ye+=u*vt,Fe+=u*wt,$e+=u*ct,rt+=u*xt,Qe+=u*mt,We+=u*$t,Ze+=u*It,Ge+=u*jt,Ee+=u*qt,Oe+=u*Vt,pe+=u*er,Ae+=u*yr,Ie+=u*br,fe+=u*vr,u=y[6],bt+=u*E,ye+=u*ft,Fe+=u*vt,$e+=u*wt,rt+=u*ct,Qe+=u*xt,We+=u*mt,Ze+=u*$t,Ge+=u*It,Ee+=u*jt,Oe+=u*qt,pe+=u*Vt,Ae+=u*er,Ie+=u*yr,fe+=u*br,U+=u*vr,u=y[7],ye+=u*E,Fe+=u*ft,$e+=u*vt,rt+=u*wt,Qe+=u*ct,We+=u*xt,Ze+=u*mt,Ge+=u*$t,Ee+=u*It,Oe+=u*jt,pe+=u*qt,Ae+=u*Vt,Ie+=u*er,fe+=u*yr,U+=u*br,D+=u*vr,u=y[8],Fe+=u*E,$e+=u*ft,rt+=u*vt,Qe+=u*wt,We+=u*ct,Ze+=u*xt,Ge+=u*mt,Ee+=u*$t,Oe+=u*It,pe+=u*jt,Ae+=u*qt,Ie+=u*Vt,fe+=u*er,U+=u*yr,D+=u*br,W+=u*vr,u=y[9],$e+=u*E,rt+=u*ft,Qe+=u*vt,We+=u*wt,Ze+=u*ct,Ge+=u*xt,Ee+=u*mt,Oe+=u*$t,pe+=u*It,Ae+=u*jt,Ie+=u*qt,fe+=u*Vt,U+=u*er,D+=u*yr,W+=u*br,z+=u*vr,u=y[10],rt+=u*E,Qe+=u*ft,We+=u*vt,Ze+=u*wt,Ge+=u*ct,Ee+=u*xt,Oe+=u*mt,pe+=u*$t,Ae+=u*It,Ie+=u*jt,fe+=u*qt,U+=u*Vt,D+=u*er,W+=u*yr,z+=u*br,K+=u*vr,u=y[11],Qe+=u*E,We+=u*ft,Ze+=u*vt,Ge+=u*wt,Ee+=u*ct,Oe+=u*xt,pe+=u*mt,Ae+=u*$t,Ie+=u*It,fe+=u*jt,U+=u*qt,D+=u*Vt,W+=u*er,z+=u*yr,K+=u*br,Y+=u*vr,u=y[12],We+=u*E,Ze+=u*ft,Ge+=u*vt,Ee+=u*wt,Oe+=u*ct,pe+=u*xt,Ae+=u*mt,Ie+=u*$t,fe+=u*It,U+=u*jt,D+=u*qt,W+=u*Vt,z+=u*er,K+=u*yr,Y+=u*br,qe+=u*vr,u=y[13],Ze+=u*E,Ge+=u*ft,Ee+=u*vt,Oe+=u*wt,pe+=u*ct,Ae+=u*xt,Ie+=u*mt,fe+=u*$t,U+=u*It,D+=u*jt,W+=u*qt,z+=u*Vt,K+=u*er,Y+=u*yr,qe+=u*br,nt+=u*vr,u=y[14],Ge+=u*E,Ee+=u*ft,Oe+=u*vt,pe+=u*wt,Ae+=u*ct,Ie+=u*xt,fe+=u*mt,U+=u*$t,D+=u*It,W+=u*jt,z+=u*qt,K+=u*Vt,Y+=u*er,qe+=u*yr,nt+=u*br,ot+=u*vr,u=y[15],Ee+=u*E,Oe+=u*ft,pe+=u*vt,Ae+=u*wt,Ie+=u*ct,fe+=u*xt,U+=u*mt,D+=u*$t,W+=u*It,z+=u*jt,K+=u*qt,Y+=u*Vt,qe+=u*er,nt+=u*yr,ot+=u*br,st+=u*vr,_+=38*Oe,R+=38*pe,F+=38*Ae,Q+=38*Ie,_e+=38*fe,le+=38*U,bt+=38*D,ye+=38*W,Fe+=38*z,$e+=38*K,rt+=38*Y,Qe+=38*qe,We+=38*nt,Ze+=38*ot,Ge+=38*st,b=1,u=_+b+65535,b=Math.floor(u/65536),_=u-b*65536,u=R+b+65535,b=Math.floor(u/65536),R=u-b*65536,u=F+b+65535,b=Math.floor(u/65536),F=u-b*65536,u=Q+b+65535,b=Math.floor(u/65536),Q=u-b*65536,u=_e+b+65535,b=Math.floor(u/65536),_e=u-b*65536,u=le+b+65535,b=Math.floor(u/65536),le=u-b*65536,u=bt+b+65535,b=Math.floor(u/65536),bt=u-b*65536,u=ye+b+65535,b=Math.floor(u/65536),ye=u-b*65536,u=Fe+b+65535,b=Math.floor(u/65536),Fe=u-b*65536,u=$e+b+65535,b=Math.floor(u/65536),$e=u-b*65536,u=rt+b+65535,b=Math.floor(u/65536),rt=u-b*65536,u=Qe+b+65535,b=Math.floor(u/65536),Qe=u-b*65536,u=We+b+65535,b=Math.floor(u/65536),We=u-b*65536,u=Ze+b+65535,b=Math.floor(u/65536),Ze=u-b*65536,u=Ge+b+65535,b=Math.floor(u/65536),Ge=u-b*65536,u=Ee+b+65535,b=Math.floor(u/65536),Ee=u-b*65536,_+=b-1+37*(b-1),b=1,u=_+b+65535,b=Math.floor(u/65536),_=u-b*65536,u=R+b+65535,b=Math.floor(u/65536),R=u-b*65536,u=F+b+65535,b=Math.floor(u/65536),F=u-b*65536,u=Q+b+65535,b=Math.floor(u/65536),Q=u-b*65536,u=_e+b+65535,b=Math.floor(u/65536),_e=u-b*65536,u=le+b+65535,b=Math.floor(u/65536),le=u-b*65536,u=bt+b+65535,b=Math.floor(u/65536),bt=u-b*65536,u=ye+b+65535,b=Math.floor(u/65536),ye=u-b*65536,u=Fe+b+65535,b=Math.floor(u/65536),Fe=u-b*65536,u=$e+b+65535,b=Math.floor(u/65536),$e=u-b*65536,u=rt+b+65535,b=Math.floor(u/65536),rt=u-b*65536,u=Qe+b+65535,b=Math.floor(u/65536),Qe=u-b*65536,u=We+b+65535,b=Math.floor(u/65536),We=u-b*65536,u=Ze+b+65535,b=Math.floor(u/65536),Ze=u-b*65536,u=Ge+b+65535,b=Math.floor(u/65536),Ge=u-b*65536,u=Ee+b+65535,b=Math.floor(u/65536),Ee=u-b*65536,_+=b-1+37*(b-1),h[0]=_,h[1]=R,h[2]=F,h[3]=Q,h[4]=_e,h[5]=le,h[6]=bt,h[7]=ye,h[8]=Fe,h[9]=$e,h[10]=rt,h[11]=Qe,h[12]=We,h[13]=Ze,h[14]=Ge,h[15]=Ee}function ne(h,y){Z(h,y,y)}function Ye(h,y){var g=e(),u;for(u=0;u<16;u++)g[u]=y[u];for(u=253;u>=0;u--)ne(g,g),u!==2&&u!==4&&Z(g,g,y);for(u=0;u<16;u++)h[u]=g[u]}function at(h,y){var g=e(),u;for(u=0;u<16;u++)g[u]=y[u];for(u=250;u>=0;u--)ne(g,g),u!==1&&Z(g,g,y);for(u=0;u<16;u++)h[u]=g[u]}function Et(h,y,g){var u=new Uint8Array(32),b=new Float64Array(80),_,R,F=e(),Q=e(),_e=e(),le=e(),bt=e(),ye=e();for(R=0;R<31;R++)u[R]=y[R];for(u[31]=y[31]&127|64,u[0]&=248,H(b,g),R=0;R<16;R++)Q[R]=b[R],le[R]=F[R]=_e[R]=0;for(F[0]=le[0]=1,R=254;R>=0;--R)_=u[R>>>3]>>>(R&7)&1,ge(F,Q,_),ge(_e,le,_),C(bt,F,_e),N(F,F,_e),C(_e,Q,le),N(Q,Q,le),ne(le,bt),ne(ye,F),Z(F,_e,F),Z(_e,Q,bt),C(bt,F,_e),N(F,F,_e),ne(Q,F),N(_e,le,ye),Z(F,_e,a),C(F,F,le),Z(_e,_e,F),Z(F,le,ye),Z(le,Q,b),ne(Q,bt),ge(F,Q,_),ge(_e,le,_);for(R=0;R<16;R++)b[R+16]=F[R],b[R+32]=_e[R],b[R+48]=Q[R],b[R+64]=le[R];var Fe=b.subarray(32),$e=b.subarray(16);return Ye(Fe,Fe),Z($e,$e,Fe),Te(h,$e),0}function lt(h,y){return Et(h,y,s)}function Ct(h,y){return r(y,32),lt(h,y)}function rn(h,y,g){var u=new Uint8Array(32);return Et(u,g,y),ve(h,n,u,ze)}var nn=q,xo=V;function gp(h,y,g,u,b,_){var R=new Uint8Array(32);return rn(R,b,_),nn(h,y,g,u,R)}function au(h,y,g,u,b,_){var R=new Uint8Array(32);return rn(R,b,_),xo(h,y,g,u,R)}var cu=[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 uu(h,y,g,u){for(var b=new Int32Array(16),_=new Int32Array(16),R,F,Q,_e,le,bt,ye,Fe,$e,rt,Qe,We,Ze,Ge,Ee,Oe,pe,Ae,Ie,fe,U,D,W,z,K,Y,qe=h[0],nt=h[1],ot=h[2],st=h[3],E=h[4],ft=h[5],vt=h[6],wt=h[7],ct=y[0],xt=y[1],mt=y[2],$t=y[3],It=y[4],jt=y[5],qt=y[6],Vt=y[7],er=0;u>=128;){for(Ie=0;Ie<16;Ie++)fe=8*Ie+er,b[Ie]=g[fe+0]<<24|g[fe+1]<<16|g[fe+2]<<8|g[fe+3],_[Ie]=g[fe+4]<<24|g[fe+5]<<16|g[fe+6]<<8|g[fe+7];for(Ie=0;Ie<80;Ie++)if(R=qe,F=nt,Q=ot,_e=st,le=E,bt=ft,ye=vt,Fe=wt,$e=ct,rt=xt,Qe=mt,We=$t,Ze=It,Ge=jt,Ee=qt,Oe=Vt,U=wt,D=Vt,W=D&65535,z=D>>>16,K=U&65535,Y=U>>>16,U=(E>>>14|It<<18)^(E>>>18|It<<14)^(It>>>9|E<<23),D=(It>>>14|E<<18)^(It>>>18|E<<14)^(E>>>9|It<<23),W+=D&65535,z+=D>>>16,K+=U&65535,Y+=U>>>16,U=E&ft^~E&vt,D=It&jt^~It&qt,W+=D&65535,z+=D>>>16,K+=U&65535,Y+=U>>>16,U=cu[Ie*2],D=cu[Ie*2+1],W+=D&65535,z+=D>>>16,K+=U&65535,Y+=U>>>16,U=b[Ie%16],D=_[Ie%16],W+=D&65535,z+=D>>>16,K+=U&65535,Y+=U>>>16,z+=W>>>16,K+=z>>>16,Y+=K>>>16,pe=K&65535|Y<<16,Ae=W&65535|z<<16,U=pe,D=Ae,W=D&65535,z=D>>>16,K=U&65535,Y=U>>>16,U=(qe>>>28|ct<<4)^(ct>>>2|qe<<30)^(ct>>>7|qe<<25),D=(ct>>>28|qe<<4)^(qe>>>2|ct<<30)^(qe>>>7|ct<<25),W+=D&65535,z+=D>>>16,K+=U&65535,Y+=U>>>16,U=qe&nt^qe&ot^nt&ot,D=ct&xt^ct&mt^xt&mt,W+=D&65535,z+=D>>>16,K+=U&65535,Y+=U>>>16,z+=W>>>16,K+=z>>>16,Y+=K>>>16,Fe=K&65535|Y<<16,Oe=W&65535|z<<16,U=_e,D=We,W=D&65535,z=D>>>16,K=U&65535,Y=U>>>16,U=pe,D=Ae,W+=D&65535,z+=D>>>16,K+=U&65535,Y+=U>>>16,z+=W>>>16,K+=z>>>16,Y+=K>>>16,_e=K&65535|Y<<16,We=W&65535|z<<16,nt=R,ot=F,st=Q,E=_e,ft=le,vt=bt,wt=ye,qe=Fe,xt=$e,mt=rt,$t=Qe,It=We,jt=Ze,qt=Ge,Vt=Ee,ct=Oe,Ie%16===15)for(fe=0;fe<16;fe++)U=b[fe],D=_[fe],W=D&65535,z=D>>>16,K=U&65535,Y=U>>>16,U=b[(fe+9)%16],D=_[(fe+9)%16],W+=D&65535,z+=D>>>16,K+=U&65535,Y+=U>>>16,pe=b[(fe+1)%16],Ae=_[(fe+1)%16],U=(pe>>>1|Ae<<31)^(pe>>>8|Ae<<24)^pe>>>7,D=(Ae>>>1|pe<<31)^(Ae>>>8|pe<<24)^(Ae>>>7|pe<<25),W+=D&65535,z+=D>>>16,K+=U&65535,Y+=U>>>16,pe=b[(fe+14)%16],Ae=_[(fe+14)%16],U=(pe>>>19|Ae<<13)^(Ae>>>29|pe<<3)^pe>>>6,D=(Ae>>>19|pe<<13)^(pe>>>29|Ae<<3)^(Ae>>>6|pe<<26),W+=D&65535,z+=D>>>16,K+=U&65535,Y+=U>>>16,z+=W>>>16,K+=z>>>16,Y+=K>>>16,b[fe]=K&65535|Y<<16,_[fe]=W&65535|z<<16;U=qe,D=ct,W=D&65535,z=D>>>16,K=U&65535,Y=U>>>16,U=h[0],D=y[0],W+=D&65535,z+=D>>>16,K+=U&65535,Y+=U>>>16,z+=W>>>16,K+=z>>>16,Y+=K>>>16,h[0]=qe=K&65535|Y<<16,y[0]=ct=W&65535|z<<16,U=nt,D=xt,W=D&65535,z=D>>>16,K=U&65535,Y=U>>>16,U=h[1],D=y[1],W+=D&65535,z+=D>>>16,K+=U&65535,Y+=U>>>16,z+=W>>>16,K+=z>>>16,Y+=K>>>16,h[1]=nt=K&65535|Y<<16,y[1]=xt=W&65535|z<<16,U=ot,D=mt,W=D&65535,z=D>>>16,K=U&65535,Y=U>>>16,U=h[2],D=y[2],W+=D&65535,z+=D>>>16,K+=U&65535,Y+=U>>>16,z+=W>>>16,K+=z>>>16,Y+=K>>>16,h[2]=ot=K&65535|Y<<16,y[2]=mt=W&65535|z<<16,U=st,D=$t,W=D&65535,z=D>>>16,K=U&65535,Y=U>>>16,U=h[3],D=y[3],W+=D&65535,z+=D>>>16,K+=U&65535,Y+=U>>>16,z+=W>>>16,K+=z>>>16,Y+=K>>>16,h[3]=st=K&65535|Y<<16,y[3]=$t=W&65535|z<<16,U=E,D=It,W=D&65535,z=D>>>16,K=U&65535,Y=U>>>16,U=h[4],D=y[4],W+=D&65535,z+=D>>>16,K+=U&65535,Y+=U>>>16,z+=W>>>16,K+=z>>>16,Y+=K>>>16,h[4]=E=K&65535|Y<<16,y[4]=It=W&65535|z<<16,U=ft,D=jt,W=D&65535,z=D>>>16,K=U&65535,Y=U>>>16,U=h[5],D=y[5],W+=D&65535,z+=D>>>16,K+=U&65535,Y+=U>>>16,z+=W>>>16,K+=z>>>16,Y+=K>>>16,h[5]=ft=K&65535|Y<<16,y[5]=jt=W&65535|z<<16,U=vt,D=qt,W=D&65535,z=D>>>16,K=U&65535,Y=U>>>16,U=h[6],D=y[6],W+=D&65535,z+=D>>>16,K+=U&65535,Y+=U>>>16,z+=W>>>16,K+=z>>>16,Y+=K>>>16,h[6]=vt=K&65535|Y<<16,y[6]=qt=W&65535|z<<16,U=wt,D=Vt,W=D&65535,z=D>>>16,K=U&65535,Y=U>>>16,U=h[7],D=y[7],W+=D&65535,z+=D>>>16,K+=U&65535,Y+=U>>>16,z+=W>>>16,K+=z>>>16,Y+=K>>>16,h[7]=wt=K&65535|Y<<16,y[7]=Vt=W&65535|z<<16,er+=128,u-=128}return u}function Vn(h,y,g){var u=new Int32Array(8),b=new Int32Array(8),_=new Uint8Array(256),R,F=g;for(u[0]=1779033703,u[1]=3144134277,u[2]=1013904242,u[3]=2773480762,u[4]=1359893119,u[5]=2600822924,u[6]=528734635,u[7]=1541459225,b[0]=4089235720,b[1]=2227873595,b[2]=4271175723,b[3]=1595750129,b[4]=2917565137,b[5]=725511199,b[6]=4215389547,b[7]=327033209,uu(u,b,y,g),g%=128,R=0;R<g;R++)_[R]=y[F-g+R];for(_[g]=128,g=256-128*(g<112?1:0),_[g-9]=0,v(_,g-8,F/536870912|0,F<<3),uu(u,b,_,g),R=0;R<8;R++)v(h,8*R,u[R],b[R]);return 0}function mo(h,y){var g=e(),u=e(),b=e(),_=e(),R=e(),F=e(),Q=e(),_e=e(),le=e();N(g,h[1],h[0]),N(le,y[1],y[0]),Z(g,g,le),C(u,h[0],h[1]),C(le,y[0],y[1]),Z(u,u,le),Z(b,h[3],y[3]),Z(b,b,f),Z(_,h[2],y[2]),C(_,_,_),N(R,u,g),N(F,_,b),C(Q,_,b),C(_e,u,g),Z(h[0],R,F),Z(h[1],_e,Q),Z(h[2],Q,F),Z(h[3],R,_e)}function fu(h,y,g){var u;for(u=0;u<4;u++)ge(h[u],y[u],g)}function go(h,y){var g=e(),u=e(),b=e();Ye(b,y[2]),Z(g,y[0],b),Z(u,y[1],b),Te(h,u),h[31]^=T(g)<<7}function du(h,y,g){var u,b;for(M(h[0],i),M(h[1],o),M(h[2],o),M(h[3],i),b=255;b>=0;--b)u=g[b/8|0]>>(b&7)&1,fu(h,y,u),mo(y,h),mo(h,h),fu(h,y,u)}function ja(h,y){var g=[e(),e(),e(),e()];M(g[0],l),M(g[1],p),M(g[2],o),Z(g[3],l,p),du(h,g,y)}function lu(h,y,g){var u=new Uint8Array(64),b=[e(),e(),e(),e()],_;for(g||r(y,32),Vn(u,y,32),u[0]&=248,u[31]&=127,u[31]|=64,ja(b,u),go(h,b),_=0;_<32;_++)y[_+32]=h[_];return 0}var qa=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 Ss(h,y){var g,u,b,_;for(u=63;u>=32;--u){for(g=0,b=u-32,_=u-12;b<_;++b)y[b]+=g-16*y[u]*qa[b-(u-32)],g=Math.floor((y[b]+128)/256),y[b]-=g*256;y[b]+=g,y[u]=0}for(g=0,b=0;b<32;b++)y[b]+=g-(y[31]>>4)*qa[b],g=y[b]>>8,y[b]&=255;for(b=0;b<32;b++)y[b]-=g*qa[b];for(u=0;u<32;u++)y[u+1]+=y[u]>>8,h[u]=y[u]&255}function hu(h){var y=new Float64Array(64),g;for(g=0;g<64;g++)y[g]=h[g];for(g=0;g<64;g++)h[g]=0;Ss(h,y)}function al(h,y,g,u){var b=new Uint8Array(64),_=new Uint8Array(64),R=new Uint8Array(64),F,Q,_e=new Float64Array(64),le=[e(),e(),e(),e()];Vn(b,u,32),b[0]&=248,b[31]&=127,b[31]|=64;var bt=g+64;for(F=0;F<g;F++)h[64+F]=y[F];for(F=0;F<32;F++)h[32+F]=b[32+F];for(Vn(R,h.subarray(32),g+32),hu(R),ja(le,R),go(h,le),F=32;F<64;F++)h[F]=u[F];for(Vn(_,h,g+64),hu(_),F=0;F<64;F++)_e[F]=0;for(F=0;F<32;F++)_e[F]=R[F];for(F=0;F<32;F++)for(Q=0;Q<32;Q++)_e[F+Q]+=_[F]*b[Q];return Ss(h.subarray(32),_e),bt}function yp(h,y){var g=e(),u=e(),b=e(),_=e(),R=e(),F=e(),Q=e();return M(h[2],o),H(h[1],y),ne(b,h[1]),Z(_,b,c),N(b,b,h[2]),C(_,h[2],_),ne(R,_),ne(F,R),Z(Q,F,R),Z(g,Q,b),Z(g,g,_),at(g,g),Z(g,g,b),Z(g,g,_),Z(g,g,_),Z(h[0],g,_),ne(u,h[0]),Z(u,u,_),A(u,b)&&Z(h[0],h[0],x),ne(u,h[0]),Z(u,u,_),A(u,b)?-1:(T(h[0])===y[31]>>7&&N(h[0],i,h[0]),Z(h[3],h[0],h[1]),0)}function yo(h,y,g,u){var b,_=new Uint8Array(32),R=new Uint8Array(64),F=[e(),e(),e(),e()],Q=[e(),e(),e(),e()];if(g<64||yp(Q,u))return-1;for(b=0;b<g;b++)h[b]=y[b];for(b=0;b<32;b++)h[b+32]=u[b];if(Vn(R,h,g),hu(R),du(F,Q,R),ja(Q,y.subarray(32)),mo(F,Q),go(_,F),g-=64,L(y,0,_,0)){for(b=0;b<g;b++)h[b]=0;return-1}for(b=0;b<g;b++)h[b]=y[b+64];return g}var B=32,P=24,j=32,J=16,Be=32,Rt=32,Pt=32,Je=32,ae=32,xe=P,Se=j,Ce=J,Ke=64,yt=32,_t=64,_r=32,Va=64;t.lowlevel={crypto_core_hsalsa20:ve,crypto_stream_xor:X,crypto_stream:we,crypto_stream_salsa20_xor:he,crypto_stream_salsa20:Ne,crypto_onetimeauth:St,crypto_onetimeauth_verify:He,crypto_verify_16:I,crypto_verify_32:L,crypto_secretbox:q,crypto_secretbox_open:V,crypto_scalarmult:Et,crypto_scalarmult_base:lt,crypto_box_beforenm:rn,crypto_box_afternm:nn,crypto_box:gp,crypto_box_open:au,crypto_box_keypair:Ct,crypto_hash:Vn,crypto_sign:al,crypto_sign_keypair:lu,crypto_sign_open:yo,crypto_secretbox_KEYBYTES:B,crypto_secretbox_NONCEBYTES:P,crypto_secretbox_ZEROBYTES:j,crypto_secretbox_BOXZEROBYTES:J,crypto_scalarmult_BYTES:Be,crypto_scalarmult_SCALARBYTES:Rt,crypto_box_PUBLICKEYBYTES:Pt,crypto_box_SECRETKEYBYTES:Je,crypto_box_BEFORENMBYTES:ae,crypto_box_NONCEBYTES:xe,crypto_box_ZEROBYTES:Se,crypto_box_BOXZEROBYTES:Ce,crypto_sign_BYTES:Ke,crypto_sign_PUBLICKEYBYTES:yt,crypto_sign_SECRETKEYBYTES:_t,crypto_sign_SEEDBYTES:_r,crypto_hash_BYTES:Va,gf:e,D:c,L:qa,pack25519:Te,unpack25519:H,M:Z,A:C,S:ne,Z:N,pow2523:at,add:mo,set25519:M,modL:Ss,scalarmult:du,scalarbase:ja};function cl(h,y){if(h.length!==B)throw new Error("bad key size");if(y.length!==P)throw new Error("bad nonce size")}function bp(h,y){if(h.length!==Pt)throw new Error("bad public key size");if(y.length!==Je)throw new Error("bad secret key size")}function Gr(){for(var h=0;h<arguments.length;h++)if(!(arguments[h]instanceof Uint8Array))throw new TypeError("unexpected type, use Uint8Array")}function sy(h){for(var y=0;y<h.length;y++)h[y]=0}t.randomBytes=function(h){var y=new Uint8Array(h);return r(y,h),y},t.secretbox=function(h,y,g){Gr(h,y,g),cl(g,y);for(var u=new Uint8Array(j+h.length),b=new Uint8Array(u.length),_=0;_<h.length;_++)u[_+j]=h[_];return q(b,u,u.length,y,g),b.subarray(J)},t.secretbox.open=function(h,y,g){Gr(h,y,g),cl(g,y);for(var u=new Uint8Array(J+h.length),b=new Uint8Array(u.length),_=0;_<h.length;_++)u[_+J]=h[_];return u.length<32||V(b,u,u.length,y,g)!==0?null:b.subarray(j)},t.secretbox.keyLength=B,t.secretbox.nonceLength=P,t.secretbox.overheadLength=J,t.scalarMult=function(h,y){if(Gr(h,y),h.length!==Rt)throw new Error("bad n size");if(y.length!==Be)throw new Error("bad p size");var g=new Uint8Array(Be);return Et(g,h,y),g},t.scalarMult.base=function(h){if(Gr(h),h.length!==Rt)throw new Error("bad n size");var y=new Uint8Array(Be);return lt(y,h),y},t.scalarMult.scalarLength=Rt,t.scalarMult.groupElementLength=Be,t.box=function(h,y,g,u){var b=t.box.before(g,u);return t.secretbox(h,y,b)},t.box.before=function(h,y){Gr(h,y),bp(h,y);var g=new Uint8Array(ae);return rn(g,h,y),g},t.box.after=t.secretbox,t.box.open=function(h,y,g,u){var b=t.box.before(g,u);return t.secretbox.open(h,y,b)},t.box.open.after=t.secretbox.open,t.box.keyPair=function(){var h=new Uint8Array(Pt),y=new Uint8Array(Je);return Ct(h,y),{publicKey:h,secretKey:y}},t.box.keyPair.fromSecretKey=function(h){if(Gr(h),h.length!==Je)throw new Error("bad secret key size");var y=new Uint8Array(Pt);return lt(y,h),{publicKey:y,secretKey:new Uint8Array(h)}},t.box.publicKeyLength=Pt,t.box.secretKeyLength=Je,t.box.sharedKeyLength=ae,t.box.nonceLength=xe,t.box.overheadLength=t.secretbox.overheadLength,t.sign=function(h,y){if(Gr(h,y),y.length!==_t)throw new Error("bad secret key size");var g=new Uint8Array(Ke+h.length);return al(g,h,h.length,y),g},t.sign.open=function(h,y){if(Gr(h,y),y.length!==yt)throw new Error("bad public key size");var g=new Uint8Array(h.length),u=yo(g,h,h.length,y);if(u<0)return null;for(var b=new Uint8Array(u),_=0;_<b.length;_++)b[_]=g[_];return b},t.sign.detached=function(h,y){for(var g=t.sign(h,y),u=new Uint8Array(Ke),b=0;b<u.length;b++)u[b]=g[b];return u},t.sign.detached.verify=function(h,y,g){if(Gr(h,y,g),y.length!==Ke)throw new Error("bad signature size");if(g.length!==yt)throw new Error("bad public key size");var u=new Uint8Array(Ke+h.length),b=new Uint8Array(Ke+h.length),_;for(_=0;_<Ke;_++)u[_]=y[_];for(_=0;_<h.length;_++)u[_+Ke]=h[_];return yo(b,u,u.length,g)>=0},t.sign.keyPair=function(){var h=new Uint8Array(yt),y=new Uint8Array(_t);return lu(h,y),{publicKey:h,secretKey:y}},t.sign.keyPair.fromSecretKey=function(h){if(Gr(h),h.length!==_t)throw new Error("bad secret key size");for(var y=new Uint8Array(yt),g=0;g<y.length;g++)y[g]=h[32+g];return{publicKey:y,secretKey:new Uint8Array(h)}},t.sign.keyPair.fromSeed=function(h){if(Gr(h),h.length!==_r)throw new Error("bad seed size");for(var y=new Uint8Array(yt),g=new Uint8Array(_t),u=0;u<32;u++)g[u]=h[u];return lu(y,g,!0),{publicKey:y,secretKey:g}},t.sign.publicKeyLength=yt,t.sign.secretKeyLength=_t,t.sign.seedLength=_r,t.sign.signatureLength=Ke,t.hash=function(h){Gr(h);var y=new Uint8Array(Va);return Vn(y,h,h.length),y},t.hash.hashLength=Va,t.verify=function(h,y){return Gr(h,y),h.length===0||y.length===0||h.length!==y.length?!1:S(h,0,y,0,h.length)===0},t.setPRNG=function(h){r=h},(function(){var h=typeof self<"u"?self.crypto||self.msCrypto:null;if(h&&h.getRandomValues){var y=65536;t.setPRNG(function(g,u){var b,_=new Uint8Array(u);for(b=0;b<u;b+=y)h.getRandomValues(_.subarray(b,b+Math.min(u-b,y)));for(b=0;b<u;b++)g[b]=_[b];sy(_)})}else typeof Gt<"u"&&(h=Gt("crypto"),h&&h.randomBytes&&t.setPRNG(function(g,u){var b,_=h.randomBytes(u);for(b=0;b<u;b++)g[b]=_[b];sy(_)}))})()})(typeof hl<"u"&&hl.exports?hl.exports:self.nacl=self.nacl||{})});var Ap=Ve(Ep=>{"use strict";Object.defineProperty(Ep,"__esModule",{value:!0});var Sp=class{constructor(e,r=0,n=0){this.start=r,this.end=n>r?n:r,this.buf=e}get length(){return this.buf.length}reset(e=0,r=0){return this.start=e,r>=this.start?this.end=r:this.end<this.start&&(this.end=this.start),this}walk(e){return this.start=this.end,this.end+=e,this}mustHas(e,r="Too few bytes to parse."){let n=this.end+e;if(n>this.buf.length){let s=new Error(r);throw s.available=this.buf.length,s.requested=n,s}return this.walk(0),this}mustWalk(e,r){return this.mustHas(e,r),this.walk(e),this}};Ep.BufferVisitor=Sp});var xy=Ve(_p=>{"use strict";Object.defineProperty(_p,"__esModule",{value:!0});var hy=Gt("util"),py=64,Ip="-----BEGIN ",Tp="-----END ",pu="-----",Cp="Proc-Type",xl=class{static parse(e){let r=[],n=e.toString("utf8").split(`
6
+ `).map(s=>s.trim()).filter(s=>s!==""&&!s.startsWith("#"));for(;n.length>0;)r.push(mE(n));if(r.length===0)throw new Error("PEM: no block");return r}constructor(e,r){this.type=e,this.body=r,this.headers=Object.create(null)}get procType(){return this.getHeader(Cp)}getHeader(e){let r=this.headers[e];return r??""}setHeader(e,r){if(e.includes(":"))throw new Error("pem: cannot encode a header key that contains a colon");if(e===""||r==="")throw new Error("pem: invalid header key or value");this.headers[e]=r}toString(){let e=Ip+this.type+pu+`
7
+ `,r=Object.keys(this.headers);if(r.length>0){let i=this.procType;i!==""&&(e+=`${Cp}: ${i}
8
+ `),r.sort();for(let o of r)o!==Cp&&(e+=`${o}: ${this.headers[o]}
9
+ `);e+=`
10
+ `}let n=this.body.toString("base64"),s=0;for(;s<n.length;)e+=n.slice(s,s+py)+`
11
+ `,s+=py;return e+=Tp+this.type+pu+`
12
+ `,e}toBuffer(){return Buffer.from(this.toString(),"utf8")}valueOf(){return this.body}toJSON(){return{type:this.type,body:this.body,headers:this.headers}}[hy.inspect.custom](e,r){return`<${this.constructor.name} ${hy.inspect(this.toJSON(),r)}>`}};_p.PEM=xl;function mE(t){let e=t.shift();if(e==null||!e.startsWith(Ip)||!e.endsWith(pu))throw new Error("pem: invalid BEGIN line");let r=e.slice(Ip.length,e.length-pu.length);if(r==="")throw new Error("pem: invalid type");let n=[];for(e=t.shift();e!=null&&e.includes(": ");){let o=e.split(": ");if(o.length!==2||o[0]===""||o[1]==="")throw new Error("pem: invalid Header line");n.push(o),e=t.shift()}let s="";for(;e!=null&&!e.startsWith(Tp);)s+=e,e=t.shift();if(e==null||e!==`${Tp}${r}${pu}`)throw new Error("pem: invalid END line");let i=new xl(r,Buffer.from(s,"base64"));if(s===""||i.body.toString("base64")!==s)throw new Error("pem: invalid base64 body");for(let o of n)i.setHeader(o[0],o[1]);return i}});var by=Ve(xi=>{"use strict";Object.defineProperty(xi,"__esModule",{value:!0});var my=Gt("util"),ml=Ap(),zt;(function(t){t[t.UNIVERSAL=0]="UNIVERSAL",t[t.APPLICATION=64]="APPLICATION",t[t.CONTEXT_SPECIFIC=128]="CONTEXT_SPECIFIC",t[t.PRIVATE=192]="PRIVATE"})(zt=xi.Class||(xi.Class={}));var ht;(function(t){t[t.NONE=0]="NONE",t[t.BOOLEAN=1]="BOOLEAN",t[t.INTEGER=2]="INTEGER",t[t.BITSTRING=3]="BITSTRING",t[t.OCTETSTRING=4]="OCTETSTRING",t[t.NULL=5]="NULL",t[t.OID=6]="OID",t[t.ENUMERATED=10]="ENUMERATED",t[t.UTF8=12]="UTF8",t[t.SEQUENCE=16]="SEQUENCE",t[t.SET=17]="SET",t[t.NUMERICSTRING=18]="NUMERICSTRING",t[t.PRINTABLESTRING=19]="PRINTABLESTRING",t[t.T61STRING=20]="T61STRING",t[t.IA5STRING=22]="IA5STRING",t[t.UTCTIME=23]="UTCTIME",t[t.GENERALIZEDTIME=24]="GENERALIZEDTIME",t[t.GENERALSTRING=27]="GENERALSTRING"})(ht=xi.Tag||(xi.Tag={}));var xu=class{constructor(e,r){this.buf=e,this.bitLen=r}at(e){if(e<0||e>=this.bitLen||!Number.isInteger(e))return 0;let r=Math.floor(e/8),n=7-e%8;return this.buf[r]>>n&1}rightAlign(){let e=8-this.bitLen%8;if(e===8||this.buf.length===0)return this.buf;let r=Buffer.alloc(this.buf.length);r[0]=this.buf[0]>>e;for(let n=1;n<this.buf.length;n++)r[n]=this.buf[n-1]<<8-e,r[n]|=this.buf[n]>>e;return r}};xi.BitString=xu;var Bp=class t{static Bool(e){let r=new t(zt.UNIVERSAL,ht.BOOLEAN,Buffer.from([e?255:0]));return r._value=e,r}static parseBool(e){if(!(e instanceof Buffer)||e.length!==1)throw new Error("ASN1 syntax error: invalid boolean");switch(e[0]){case 0:return!1;case 255:return!0;default:throw new Error("ASN1 syntax error: invalid boolean")}}static Integer(e){if(e instanceof Buffer){let s=new t(zt.UNIVERSAL,ht.INTEGER,e);return s._value=e.toString("hex"),s}if(!Number.isSafeInteger(e))throw new Error("ASN1 syntax error: invalid integer");let r;if(e>=-128&&e<128)r=Buffer.alloc(1),r.writeInt8(e,0);else if(e>=-32768&&e<32768)r=Buffer.alloc(2),r.writeIntBE(e,0,2);else if(e>=-8388608&&e<8388608)r=Buffer.alloc(3),r.writeIntBE(e,0,3);else if(e>=-2147483648&&e<2147483648)r=Buffer.alloc(4),r.writeIntBE(e,0,4);else if(e>=-549755813888&&e<549755813888)r=Buffer.alloc(5),r.writeIntBE(e,0,5);else if(e>=-0x800000000000&&e<0x800000000000)r=Buffer.alloc(6),r.writeIntBE(e,0,6);else throw new Error("ASN1 syntax error: invalid Integer");let n=new t(zt.UNIVERSAL,ht.INTEGER,r);return n._value=e,n}static parseInteger(e){if(!(e instanceof Buffer)||e.length===0)throw new Error("ASN1 syntax error: invalid Integer");return e.length>6?e.toString("hex"):e.readIntBE(0,e.length)}static parseIntegerNum(e){let r=t.parseInteger(e);if(typeof r!="number")throw new Error("ASN1 syntax error: invalid Integer number");return r}static parseIntegerStr(e){let r=t.parseInteger(e);return typeof r=="number"?r.toString(16):r}static BitString(e){e instanceof Buffer&&(e=new xu(e,e.length*8));let r=e.buf.length*8-e.bitLen,n=Buffer.alloc(e.buf.length+1);return n.writeInt8(r,0),e.buf.copy(n,1),new t(zt.UNIVERSAL,ht.BITSTRING,n)}static parseBitString(e){if(!(e instanceof Buffer)||e.length===0)throw new Error("ASN1 syntax error: invalid BitString");let r=e[0];if(r>7||e.length===1&&r>0||(e[e.length-1]&(1<<e[0])-1)!==0)throw new Error("ASN1 syntax error: invalid padding bits in BIT STRING");return new xu(e.slice(1),(e.length-1)*8-r)}static Null(){let e=new t(zt.UNIVERSAL,ht.NULL,Buffer.alloc(0));return e._value=null,e}static parseNull(e){if(!(e instanceof Buffer)||e.length!==0)throw new Error("ASN1 syntax error: invalid null");return null}static OID(e){let r=e.split(".");if(r.length===0)throw new Error("ASN1 syntax error: invalid Object Identifier");let n=[];n.push(40*tr(r[0])+tr(r[1]));let s=[];for(let o=2;o<r.length;++o){let a=tr(r[o]);for(s.length=0,s.push(a&127);a>127;)a=a>>>7,s.unshift(a&127|128);n.push(...s)}let i=new t(zt.UNIVERSAL,ht.OID,Buffer.from(n));return i._value=e,i}static parseOID(e){if(!(e instanceof Buffer)||e.length===0)throw new Error("ASN1 syntax error: invalid OID");let r=Math.floor(e[0]/40)+"."+e[0]%40,n=0;for(let s=1;s<e.length;s++)e[s]>=128?(n+=e[s]&127,n=n<<7):(r+="."+(n+e[s]),n=0);return r}static UTF8(e){let r=new t(zt.UNIVERSAL,ht.UTF8,Buffer.from(e,"utf8"));return r._value=e,r}static parseUTF8(e){if(!(e instanceof Buffer))throw new Error("parse ASN1 error: invalid Buffer");return e.toString("utf8")}static NumericString(e){if(!gy(e))throw new Error("ASN1 syntax error: invalid NumericString");let r=new t(zt.UNIVERSAL,ht.NUMERICSTRING,Buffer.from(e,"utf8"));return r._value=e,r}static parseNumericString(e){if(!(e instanceof Buffer))throw new Error("parse ASN1 error: invalid Buffer");let r=e.toString("utf8");if(!gy(r))throw new Error("ASN1 syntax error: invalid NumericString");return r}static PrintableString(e){let r=new t(zt.UNIVERSAL,ht.PRINTABLESTRING,Buffer.from(e,"utf8"));return r._value=e,r}static parsePrintableString(e){if(!(e instanceof Buffer))throw new Error("parse ASN1 error: invalid Buffer");return e.toString("utf8")}static IA5String(e){if(!yy(e))throw new Error("ASN1 syntax error: invalid IA5String");let r=new t(zt.UNIVERSAL,ht.IA5STRING,Buffer.from(e,"utf8"));return r._value=e,r}static parseIA5String(e){if(!(e instanceof Buffer))throw new Error("parse ASN1 error: invalid Buffer");let r=e.toString("utf8");if(!yy(r))throw new Error("ASN1 syntax error: invalid IA5String");return r}static T61String(e){let r=new t(zt.UNIVERSAL,ht.T61STRING,Buffer.from(e,"utf8"));return r._value=e,r}static parseT61String(e){if(!(e instanceof Buffer))throw new Error("parse ASN1 error: invalid Buffer");return e.toString("utf8")}static GeneralString(e){let r=new t(zt.UNIVERSAL,ht.GENERALSTRING,Buffer.from(e,"utf8"));return r._value=e,r}static parseGeneralString(e){if(!(e instanceof Buffer))throw new Error("parse ASN1 error: invalid Buffer");return e.toString("utf8")}static UTCTime(e){let r="",n=[];n.push((""+e.getUTCFullYear()).substr(2)),n.push(""+(e.getUTCMonth()+1)),n.push(""+e.getUTCDate()),n.push(""+e.getUTCHours()),n.push(""+e.getUTCMinutes()),n.push(""+e.getUTCSeconds());for(let i of n)i.length<2&&(r+="0"),r+=i;r+="Z";let s=new t(zt.UNIVERSAL,ht.UTCTIME,Buffer.from(r,"utf8"));return s._value=e,s}static parseUTCTime(e){if(!(e instanceof Buffer)||e.length===0)throw new Error("ASN1 syntax error: invalid UTC Time");let r=e.toString("utf8"),n=new Date,s=tr(r.substr(0,2));s=s>=50?1900+s:2e3+s;let i=tr(r.substr(2,2))-1,o=tr(r.substr(4,2)),a=tr(r.substr(6,2)),c=tr(r.substr(8,2)),f=0,l=0,p="";if(r.length>11&&(l=10,p=r.charAt(l),p!=="+"&&p!=="-"&&(f=tr(r.substr(10,2)),l+=2)),n.setUTCFullYear(s,i,o),n.setUTCHours(a,c,f,0),l>0&&(p=r.charAt(l),p==="+"||p==="-")){let x=tr(r.substr(l+1,2)),v=tr(r.substr(l+4,2)),S=x*60+v;S*=6e4,p==="+"?n.setTime(+n-S):n.setTime(+n+S)}return n}static GeneralizedTime(e){let r="",n=[];n.push(""+e.getUTCFullYear()),n.push(""+(e.getUTCMonth()+1)),n.push(""+e.getUTCDate()),n.push(""+e.getUTCHours()),n.push(""+e.getUTCMinutes()),n.push(""+e.getUTCSeconds());for(let i of n)i.length<2&&(r+="0"),r+=i;r+="Z";let s=new t(zt.UNIVERSAL,ht.GENERALIZEDTIME,Buffer.from(r,"utf8"));return s._value=e,s}static parseGeneralizedTime(e){if(!(e instanceof Buffer)||e.length===0)throw new Error("ASN1 syntax error: invalid Generalized Time");let r=e.toString("utf8"),n=new Date,s=tr(r.substr(0,4)),i=tr(r.substr(4,2))-1,o=tr(r.substr(6,2)),a=tr(r.substr(8,2)),c=tr(r.substr(10,2)),f=tr(r.substr(12,2)),l=0,p=0,x=!1;r.charAt(r.length-1)==="Z"&&(x=!0);let v=r.length-5,S=r.charAt(v);if(S==="+"||S==="-"){let I=tr(r.substr(v+1,2)),L=tr(r.substr(v+4,2));p=I*60+L,p*=6e4,S==="+"&&(p*=-1),x=!0}return r.charAt(14)==="."&&(l=parseFloat(r.substr(14))*1e3),x?(n.setUTCFullYear(s,i,o),n.setUTCHours(a,c,f,l),n.setTime(+n+p)):(n.setFullYear(s,i,o),n.setHours(a,c,f,l)),n}static parseTime(e,r){switch(e){case ht.UTCTIME:return t.parseUTCTime(r);case ht.GENERALIZEDTIME:return t.parseGeneralizedTime(r);default:throw new Error("Invalid ASN1 time tag")}}static Set(e){let r=new t(zt.UNIVERSAL,ht.SET,Buffer.concat(e.map(n=>n.toDER())));return r._value=e,r}static Seq(e){let r=new t(zt.UNIVERSAL,ht.SEQUENCE,Buffer.concat(e.map(n=>n.toDER())));return r._value=e,r}static Spec(e,r,n=!0){let s=Array.isArray(r)?Buffer.concat(r.map(o=>o.toDER())):r.toDER();Array.isArray(r)&&(n=!0);let i=new t(zt.CONTEXT_SPECIFIC,e,s,n);return i._value=r,i}static fromDER(e,r=!1){return t._fromDER(new ml.BufferVisitor(e),r)}static parseDER(e,r,n){let s=t._fromDER(new ml.BufferVisitor(e),!1);if(s.class!==r&&s.tag!==n)throw new Error(`invalid ASN.1 DER for class ${r} and tag ${n}`);return s}static parseDERWithTemplate(e,r){let n=t._fromDER(new ml.BufferVisitor(e),!0),s={},i=n.validate(r,s);if(i!=null)throw i.data=n,i;return s}static _parseCompound(e,r){let n=[],s=e.length,i=new ml.BufferVisitor(e),o=0;for(;o<s;){let a=i.end;n.push(t._fromDER(i,r)),o+=i.end-a}return n}static _fromDER(e,r){if(!(e.buf instanceof Buffer)||e.length===0)throw new Error("ASN1 syntax error: invalid Generalized Time");e.mustWalk(1,"Too few bytes to read ASN.1 tag.");let n=e.start,s=e.buf[n],i=s&192,o=s&31,a=gE(e);if(e.mustHas(a),a!==0&&o===ht.NULL)throw new Error("invalid value length or NULL tag.");e.mustWalk(a);let c=(s&32)===32,f=new t(i,o,e.buf.slice(e.start,e.end),c);return c&&r&&(f._value=t._parseCompound(f.bytes,r)),f._der=e.buf.slice(n,e.end),f}constructor(e,r,n,s=!1){this.class=e,this.tag=r,this.bytes=n,this.isCompound=s||r===ht.SEQUENCE||r===ht.SET,this._value=void 0,this._der=null}get value(){return this._value===void 0&&(this._value=this.valueOf()),this._value}get DER(){return this._der==null&&(this._der=this.toDER()),this._der}mustCompound(e="asn1 object value is not compound"){if(!this.isCompound||!Array.isArray(this.value)){let r=new Error(e);throw r.data=this.toJSON(),r}return this.value}equals(e){return!(!(e instanceof t)||this.class!==e.class||this.tag!==e.tag||this.isCompound!==e.isCompound||!this.bytes.equals(e.bytes))}toDER(){let e=this.class|this.tag;this.isCompound&&(e|=32);let r=yE(this.bytes.length),n=Buffer.allocUnsafe(2+r+this.bytes.length);return n.writeInt8(e,0),r===0?(n.writeUInt8(this.bytes.length,1),this.bytes.copy(n,2)):(n.writeUInt8(r|128,1),n.writeUIntBE(this.bytes.length,2,r),this.bytes.copy(n,2+r)),n}valueOf(){if(this.isCompound)return t._parseCompound(this.bytes,!1);if(this.class!==zt.UNIVERSAL)return this.bytes;switch(this.tag){case ht.BOOLEAN:return t.parseBool(this.bytes);case ht.INTEGER:return t.parseInteger(this.bytes);case ht.BITSTRING:return t.parseBitString(this.bytes);case ht.NULL:return t.parseNull(this.bytes);case ht.OID:return t.parseOID(this.bytes);case ht.UTF8:return t.parseUTF8(this.bytes);case ht.NUMERICSTRING:return t.parseNumericString(this.bytes);case ht.PRINTABLESTRING:return t.parsePrintableString(this.bytes);case ht.T61STRING:return t.parseT61String(this.bytes);case ht.IA5STRING:return t.parseIA5String(this.bytes);case ht.GENERALSTRING:return t.parseGeneralString(this.bytes);case ht.UTCTIME:return t.parseUTCTime(this.bytes);case ht.GENERALIZEDTIME:return t.parseGeneralizedTime(this.bytes);default:return this.bytes}}validate(e,r={}){if(this.class!==e.class)return new Error(`ASN.1 object validate failure for ${e.name} : error class ${zt[this.class]}`);if(!(Array.isArray(e.tag)?e.tag:[e.tag]).includes(this.tag))return new Error(`ASN.1 object validate failure for ${e.name}: error tag ${ht[this.tag]}`);if(e.capture!=null&&(r[e.capture]=this),Array.isArray(e.value)){let s=this.mustCompound(`${e.name} need compound ASN1 value`);for(let i=0,o=0;i<e.value.length;i++)if(s[o]!=null){let a=s[o].validate(e.value[i],r);if(a==null)o++;else if(e.value[i].optional!==!0)return a}else if(e.value[i].optional!==!0)return new Error(`ASN.1 object validate failure for ${e.value[i].name}: not exists`)}else if(e.value!=null){let s=this.tag===ht.BITSTRING?this.bytes.slice(1):this.bytes;return t.fromDER(s).validate(e.value,r)}return null}toJSON(){let e=this.value;return Array.isArray(e)&&(e=e.map(r=>r.toJSON())),{class:zt[this.class],tag:this.class===zt.UNIVERSAL?ht[this.tag]:this.tag,value:e}}[my.inspect.custom](e,r){return r.depth<=2&&(r.depth=10),`<${this.constructor.name} ${my.inspect(this.toJSON(),r)}>`}};xi.ASN1=Bp;function gE(t){t.mustWalk(1,"Too few bytes to read ASN.1 value length.");let e=t.buf[t.start];if((e&128)===0)return e;let r=e&127;return t.mustWalk(r,"Too few bytes to read ASN.1 value length."),t.buf.readUIntBE(t.start,r)}function yE(t){if(t<=127)return 0;if(t<=255)return 1;if(t<=65535)return 2;if(t<=16777215)return 3;if(t<=4294967295)return 4;if(t<=0xffffffffff)return 5;if(t<=0xffffffffffff)return 6;throw new Error("invalid value length")}function gy(t){for(let e of t){let r=e.charCodeAt(0);if(r!==32&&(r<48||r>57))return!1}return!0}function yy(t){for(let e of t)if(e.charCodeAt(0)>=128)return!1;return!0}function tr(t,e=10){let r=parseInt(t,e);if(Number.isNaN(r))throw new Error(`Invalid numeric string "${t}" in radix ${e}.`);return r}});var kp=Ve(mi=>{"use strict";Object.defineProperty(mi,"__esModule",{value:!0});var bE=Ap();mi.BufferVisitor=bE.BufferVisitor;var vE=xy();mi.PEM=vE.PEM;var gl=by();mi.ASN1=gl.ASN1;mi.Class=gl.Class;mi.Tag=gl.Tag;mi.BitString=gl.BitString});var Op=Ve(zn=>{"use strict";Object.defineProperty(zn,"__esModule",{value:!0});var yi=Gt("util"),mu=Gt("crypto"),Pp=pl(),re=kp(),wr=ll();zn.publicKeyValidator={name:"PublicKeyInfo",class:re.Class.UNIVERSAL,tag:re.Tag.SEQUENCE,capture:"publicKeyInfo",value:[{name:"PublicKeyInfo.AlgorithmIdentifier",class:re.Class.UNIVERSAL,tag:re.Tag.SEQUENCE,value:[{name:"PublicKeyAlgorithmIdentifier.algorithm",class:re.Class.UNIVERSAL,tag:re.Tag.OID,capture:"publicKeyOID"}]},{name:"PublicKeyInfo.PublicKey",class:re.Class.UNIVERSAL,tag:re.Tag.BITSTRING,capture:"publicKey"}]};zn.privateKeyValidator={name:"PrivateKeyInfo",class:re.Class.UNIVERSAL,tag:re.Tag.SEQUENCE,capture:"privateKeyInfo",value:[{name:"PrivateKeyInfo.Version",class:re.Class.UNIVERSAL,tag:re.Tag.INTEGER,capture:"privateKeyVersion"},{name:"PrivateKeyInfo.AlgorithmIdentifier",class:re.Class.UNIVERSAL,tag:re.Tag.SEQUENCE,value:[{name:"PrivateKeyAlgorithmIdentifier.algorithm",class:re.Class.UNIVERSAL,tag:re.Tag.OID,capture:"privateKeyOID"}]},{name:"PrivateKeyInfo.PrivateKey",class:re.Class.UNIVERSAL,tag:re.Tag.OCTETSTRING,capture:"privateKey"}]};var wE={name:"RSAPublicKey",class:re.Class.UNIVERSAL,tag:re.Tag.SEQUENCE,value:[{name:"RSAPublicKey.modulus",class:re.Class.UNIVERSAL,tag:re.Tag.INTEGER,capture:"publicKeyModulus"},{name:"RSAPublicKey.exponent",class:re.Class.UNIVERSAL,tag:re.Tag.INTEGER,capture:"publicKeyExponent"}]},SE={name:"RSAPrivateKey",class:re.Class.UNIVERSAL,tag:re.Tag.SEQUENCE,value:[{name:"RSAPrivateKey.version",class:re.Class.UNIVERSAL,tag:re.Tag.INTEGER,capture:"privateKeyVersion"},{name:"RSAPrivateKey.modulus",class:re.Class.UNIVERSAL,tag:re.Tag.INTEGER,capture:"privateKeyModulus"},{name:"RSAPrivateKey.publicExponent",class:re.Class.UNIVERSAL,tag:re.Tag.INTEGER,capture:"privateKeyPublicExponent"},{name:"RSAPrivateKey.privateExponent",class:re.Class.UNIVERSAL,tag:re.Tag.INTEGER,capture:"privateKeyPrivateExponent"},{name:"RSAPrivateKey.prime1",class:re.Class.UNIVERSAL,tag:re.Tag.INTEGER,capture:"privateKeyPrime1"},{name:"RSAPrivateKey.prime2",class:re.Class.UNIVERSAL,tag:re.Tag.INTEGER,capture:"privateKeyPrime2"},{name:"RSAPrivateKey.exponent1",class:re.Class.UNIVERSAL,tag:re.Tag.INTEGER,capture:"privateKeyExponent1"},{name:"RSAPrivateKey.exponent2",class:re.Class.UNIVERSAL,tag:re.Tag.INTEGER,capture:"privateKeyExponent2"},{name:"RSAPrivateKey.coefficient",class:re.Class.UNIVERSAL,tag:re.Tag.INTEGER,capture:"privateKeyCoefficient"}]},EE=[wr.getOID("X25519"),wr.getOID("X448"),wr.getOID("Ed25519"),wr.getOID("Ed448")],Fa=class t{constructor(e){let r={},n=e.validate(zn.publicKeyValidator,r);if(n!=null)throw new Error("Cannot read X.509 public key: "+n.message);this.oid=re.ASN1.parseOID(r.publicKeyOID.bytes),this.algo=wr.getOIDName(this.oid),this._pkcs8=e,this._keyRaw=re.ASN1.parseBitString(r.publicKey.bytes).buf,this._finalKey=this._keyRaw,this._finalPEM=""}static fromPEM(e){let r=re.PEM.parse(e)[0];if(r.procType.includes("ENCRYPTED"))throw new Error("Could not convert public key from PEM, PEM is encrypted.");let n=re.ASN1.fromDER(r.body,!0);switch(r.type){case"PUBLIC KEY":return new t(n);case"RSA PUBLIC KEY":let s=re.ASN1.Seq([re.ASN1.Seq([re.ASN1.OID(wr.getOID("rsaEncryption")),re.ASN1.Null()]),re.ASN1.BitString(n.DER)]);return new t(s);default:throw new Error("Could not convert public key from PEM, recommend PKCS#8 PEM")}}static addVerifier(e,r){if(e=wr.getOID(e),e==="")throw new Error(`Invalid object identifier: ${e}`);if(t._verifiers[e]!=null)throw new Error(`Verifier ${e} exists`);t._verifiers[e]=r}get keyRaw(){return this._finalKey}verify(e,r,n){let s=t._verifiers[this.oid];if(s!=null){let o=mu.createHash(n).update(e).digest();return s.call(this,o,r)}let i=mu.createVerify(n);return i.update(e),i.verify(this.toPEM(),r)}getFingerprint(e,r="PublicKey"){let n;switch(r){case"PublicKeyInfo":n=this._pkcs8.DER;break;case"PublicKey":n=this._keyRaw;break;default:throw new Error(`Unknown fingerprint type "${r}".`)}let s=mu.createHash(e);return s.update(n),s.digest()}toASN1(){return this._pkcs8}toDER(){return this._pkcs8.DER}toPEM(){return this._finalPEM===""&&(this._finalPEM=new re.PEM("PUBLIC KEY",this._pkcs8.DER).toString()),this._finalPEM}toJSON(){return{oid:this.oid,algo:this.algo,publicKey:this._keyRaw}}[yi.inspect.custom](e,r){return`<${this.constructor.name} ${yi.inspect(this.toJSON(),r)}>`}};Fa._verifiers=Object.create(null);zn.PublicKey=Fa;var Ka=class t{constructor(e){let r=Object.create(null),n=e.validate(zn.privateKeyValidator,r);if(n!=null)throw new Error("Cannot read X.509 private key: "+n.message);if(this.version=re.ASN1.parseIntegerNum(r.privateKeyVersion.bytes)+1,this.oid=re.ASN1.parseOID(r.privateKeyOID.bytes),this.algo=wr.getOIDName(this.oid),this._pkcs8=e,this._keyRaw=r.privateKey.bytes,this._publicKeyRaw=null,this._finalKey=this._keyRaw,this._finalPEM="",EE.includes(this.oid)){if(this._finalKey=this._keyRaw=re.ASN1.parseDER(this._keyRaw,re.Class.UNIVERSAL,re.Tag.OCTETSTRING).bytes,this.oid==="1.3.101.112"){let s=Pp.sign.keyPair.fromSeed(this._keyRaw);this._publicKeyRaw=Buffer.from(s.publicKey),this._finalKey=Buffer.from(s.secretKey)}else if(this.version===2)for(let s of e.mustCompound())s.class===re.Class.CONTEXT_SPECIFIC&&s.tag===1&&(this._publicKeyRaw=re.ASN1.parseBitString(s.bytes).buf,this._finalKey=Buffer.concat([this._keyRaw,this._publicKeyRaw]))}}static fromPEM(e){let r=re.PEM.parse(e)[0];if(r.procType.includes("ENCRYPTED"))throw new Error("Could not convert private key from PEM, PEM is encrypted.");let n=re.ASN1.fromDER(r.body,!0);switch(r.type){case"PRIVATE KEY":return new t(n);case"RSA PRIVATE KEY":return n=re.ASN1.Seq([n.value[0],re.ASN1.Seq([re.ASN1.OID(wr.getOID("rsaEncryption")),re.ASN1.Null()]),new re.ASN1(re.Class.UNIVERSAL,re.Tag.OCTETSTRING,n.DER)]),new t(n);default:throw new Error("Could not convert private key from PEM, recommend PKCS#8 PEM")}}static addSigner(e,r){if(e=wr.getOID(e),e==="")throw new Error(`Invalid object identifier: ${e}`);if(t._signers[e]!=null)throw new Error(`Signer ${e} exists`);t._signers[e]=r}get keyRaw(){return this._finalKey}get publicKeyRaw(){return this._publicKeyRaw}sign(e,r){let n=t._signers[this.oid];if(n!=null){let i=mu.createHash(r).update(e).digest();return n.call(this,i)}let s=mu.createSign(r);return s.update(e),s.sign(this.toPEM())}toASN1(){return this._pkcs8}toDER(){return this._pkcs8.DER}toPEM(){return this._finalPEM===""&&(this._finalPEM=new re.PEM("PRIVATE KEY",this._pkcs8.DER).toString()),this._finalPEM}toJSON(){return{version:this.version,oid:this.oid,algo:this.algo,privateKey:this._keyRaw,publicKey:this._publicKeyRaw}}[yi.inspect.custom](e,r){return`<${this.constructor.name} ${yi.inspect(this.toJSON(),r)}>`}};Ka._signers=Object.create(null);zn.PrivateKey=Ka;var Rp=class t extends Fa{static fromPublicKey(e){return new t(e.toASN1())}constructor(e){if(super(e),wr.getOID(this.oid)!==wr.getOID("rsaEncryption"))throw new Error(`Invalid RSA public key, unknown OID: ${this.oid}`);let r=Object.create(null);this._pkcs1=re.ASN1.fromDER(this._keyRaw,!0);let n=this._pkcs1.validate(wE,r);if(n!=null)throw new Error("Cannot read RSA public key: "+n.message);this.modulus=re.ASN1.parseIntegerStr(r.publicKeyModulus.bytes),this.exponent=re.ASN1.parseIntegerNum(r.publicKeyExponent.bytes)}toASN1(){return this._pkcs1}toDER(){return this._keyRaw}toPEM(){return this._finalPEM===""&&(this._finalPEM=new re.PEM("RSA PUBLIC KEY",this._keyRaw).toString()),this._finalPEM}toPublicKeyPEM(){return new re.PEM("PUBLIC KEY",this._pkcs8.DER).toString()}toJSON(){return{oid:this.oid,algo:this.algo,modulus:gi(this.modulus),exponent:this.exponent}}[yi.inspect.custom](e,r){return`<${this.constructor.name} ${yi.inspect(this.toJSON(),r)}>`}};zn.RSAPublicKey=Rp;var Np=class t extends Ka{static fromPrivateKey(e){return new t(e.toASN1())}constructor(e){if(super(e),wr.getOID(this.oid)!==wr.getOID("rsaEncryption"))throw new Error(`Invalid RSA private key, unknown OID: ${this.oid}`);let r=Object.create(null);this._pkcs1=re.ASN1.fromDER(this._keyRaw,!0);let n=this._pkcs1.validate(SE,r);if(n!=null)throw new Error("Cannot read RSA private key: "+n.message);this.publicExponent=re.ASN1.parseIntegerNum(r.privateKeyPublicExponent.bytes),this.privateExponent=re.ASN1.parseIntegerStr(r.privateKeyPrivateExponent.bytes),this.modulus=re.ASN1.parseIntegerStr(r.privateKeyModulus.bytes),this.prime1=re.ASN1.parseIntegerStr(r.privateKeyPrime1.bytes),this.prime2=re.ASN1.parseIntegerStr(r.privateKeyPrime2.bytes),this.exponent1=re.ASN1.parseIntegerStr(r.privateKeyExponent1.bytes),this.exponent2=re.ASN1.parseIntegerStr(r.privateKeyExponent2.bytes),this.coefficient=re.ASN1.parseIntegerStr(r.privateKeyCoefficient.bytes)}toASN1(){return this._pkcs1}toDER(){return this._keyRaw}toPEM(){return this._finalPEM===""&&(this._finalPEM=new re.PEM("RSA PRIVATE KEY",this._keyRaw).toString()),this._finalPEM}toPrivateKeyPEM(){return new re.PEM("PRIVATE KEY",this._pkcs8.DER).toString()}toJSON(){return{version:this.version,oid:this.oid,algo:this.algo,publicExponent:this.publicExponent,privateExponent:gi(this.privateExponent),modulus:gi(this.modulus),prime1:gi(this.prime1),prime2:gi(this.prime2),exponent1:gi(this.exponent1),exponent2:gi(this.exponent2),coefficient:gi(this.coefficient)}}[yi.inspect.custom](e,r){return`<${this.constructor.name} ${yi.inspect(this.toJSON(),r)}>`}};zn.RSAPrivateKey=Np;function gi(t){return t.length%8!==0&&t.startsWith("00")?t.slice(2):t}Fa.addVerifier(wr.getOID("Ed25519"),function(t,e){return Pp.sign.detached.verify(t,e,this.keyRaw)});Ka.addSigner(wr.getOID("Ed25519"),function(t){let e=this.keyRaw;if(e.length!==64)throw new Error("Invalid signing key.");return Buffer.from(Pp.sign.detached(t,e))})});var Cy=Ve(yl=>{"use strict";Object.defineProperty(yl,"__esModule",{value:!0});var vy=Gt("util"),AE=Gt("crypto"),G=kp(),Sr=ll(),Ay=Op(),rr=Object.create(null);rr.CN=Sr.getOID("commonName");rr.commonName="CN";rr.C=Sr.getOID("countryName");rr.countryName="C";rr.L=Sr.getOID("localityName");rr.localityName="L";rr.ST=Sr.getOID("stateOrProvinceName");rr.stateOrProvinceName="ST";rr.O=Sr.getOID("organizationName");rr.organizationName="O";rr.OU=Sr.getOID("organizationalUnitName");rr.organizationalUnitName="OU";rr.E=Sr.getOID("emailAddress");rr.emailAddress="E";function CE(t){return rr[t]==null?"":rr[t]}var IE={name:"Certificate",class:G.Class.UNIVERSAL,tag:G.Tag.SEQUENCE,value:[{name:"Certificate.TBSCertificate",class:G.Class.UNIVERSAL,tag:G.Tag.SEQUENCE,capture:"tbsCertificate",value:[{name:"Certificate.TBSCertificate.version",class:G.Class.CONTEXT_SPECIFIC,tag:G.Tag.NONE,optional:!0,value:[{name:"Certificate.TBSCertificate.version.integer",class:G.Class.UNIVERSAL,tag:G.Tag.INTEGER,capture:"certVersion"}]},{name:"Certificate.TBSCertificate.serialNumber",class:G.Class.UNIVERSAL,tag:G.Tag.INTEGER,capture:"certSerialNumber"},{name:"Certificate.TBSCertificate.signature",class:G.Class.UNIVERSAL,tag:G.Tag.SEQUENCE,value:[{name:"Certificate.TBSCertificate.signature.algorithm",class:G.Class.UNIVERSAL,tag:G.Tag.OID,capture:"certinfoSignatureOID"},{name:"Certificate.TBSCertificate.signature.parameters",class:G.Class.UNIVERSAL,tag:G.Tag.OCTETSTRING,optional:!0,capture:"certinfoSignatureParams"}]},{name:"Certificate.TBSCertificate.issuer",class:G.Class.UNIVERSAL,tag:G.Tag.SEQUENCE,capture:"certIssuer"},{name:"Certificate.TBSCertificate.validity",class:G.Class.UNIVERSAL,tag:G.Tag.SEQUENCE,value:[{name:"Certificate.TBSCertificate.validity.notBefore",class:G.Class.UNIVERSAL,tag:[G.Tag.UTCTIME,G.Tag.GENERALIZEDTIME],capture:"certValidityNotBefore"},{name:"Certificate.TBSCertificate.validity.notAfter",class:G.Class.UNIVERSAL,tag:[G.Tag.UTCTIME,G.Tag.GENERALIZEDTIME],capture:"certValidityNotAfter"}]},{name:"Certificate.TBSCertificate.subject",class:G.Class.UNIVERSAL,tag:G.Tag.SEQUENCE,capture:"certSubject"},Ay.publicKeyValidator,{name:"Certificate.TBSCertificate.issuerUniqueID",class:G.Class.CONTEXT_SPECIFIC,tag:G.Tag.BOOLEAN,optional:!0,value:[{name:"Certificate.TBSCertificate.issuerUniqueID.id",class:G.Class.UNIVERSAL,tag:G.Tag.BITSTRING,capture:"certIssuerUniqueId"}]},{name:"Certificate.TBSCertificate.subjectUniqueID",class:G.Class.CONTEXT_SPECIFIC,tag:G.Tag.INTEGER,optional:!0,value:[{name:"Certificate.TBSCertificate.subjectUniqueID.id",class:G.Class.UNIVERSAL,tag:G.Tag.BITSTRING,capture:"certSubjectUniqueId"}]},{name:"Certificate.TBSCertificate.extensions",class:G.Class.CONTEXT_SPECIFIC,tag:G.Tag.BITSTRING,capture:"certExtensions",optional:!0}]},{name:"Certificate.signatureAlgorithm",class:G.Class.UNIVERSAL,tag:G.Tag.SEQUENCE,value:[{name:"Certificate.signatureAlgorithm.algorithm",class:G.Class.UNIVERSAL,tag:G.Tag.OID,capture:"certSignatureOID"},{name:"Certificate.TBSCertificate.signature.parameters",class:G.Class.UNIVERSAL,tag:G.Tag.OCTETSTRING,optional:!0,capture:"certSignatureParams"}]},{name:"Certificate.signatureValue",class:G.Class.UNIVERSAL,tag:G.Tag.BITSTRING,capture:"certSignature"}]},gu=class{constructor(){this.attributes=[],this.uniqueId=null}get commonName(){return this.getFieldValue("commonName")}get organizationName(){return this.getFieldValue("organizationName")}get organizationalUnitName(){return this.getFieldValue("organizationalUnitName")}get countryName(){return this.getFieldValue("countryName")}get localityName(){return this.getFieldValue("localityName")}get serialName(){return this.getFieldValue("serialName")}getHash(){let e=AE.createHash("sha1");for(let r of this.attributes)e.update(r.oid),e.update(r.value);return e.digest()}getField(e){for(let r of this.attributes)if(e===r.oid||e===r.name||e===r.shortName)return r;return null}addField(e){Sy([e]),this.attributes.push(e)}setAttrs(e){Sy(e),this.attributes=e}toJSON(){let e={};for(let r of this.attributes){let n=r.shortName;typeof n=="string"&&n!==""&&(e[n]=r.value)}return e.uniqueId=this.uniqueId,e.attributes=this.attributes,e}getFieldValue(e){let r=this.getField(e);return r!=null?r.value:""}};yl.DistinguishedName=gu;var Lp=class t{static fromPEMs(e){let r=[],n=G.PEM.parse(e);for(let s of n){if(s.type!=="CERTIFICATE"&&s.type!=="X509 CERTIFICATE"&&s.type!=="TRUSTED CERTIFICATE")throw new Error("Could not convert certificate from PEM: invalid type");if(s.procType.includes("ENCRYPTED"))throw new Error("Could not convert certificate from PEM: PEM is encrypted.");let i=G.ASN1.fromDER(s.body);r.push(new t(i))}if(r.length===0)throw new Error("No Certificate");return r}static fromPEM(e){return t.fromPEMs(e)[0]}constructor(e){let r=Object.create(null),n=e.validate(IE,r);if(n!=null)throw new Error("Cannot read X.509 certificate: "+n.message);if(this.raw=e.DER,this.version=r.certVersion==null?0:G.ASN1.parseIntegerNum(r.certVersion.bytes)+1,this.serialNumber=G.ASN1.parseIntegerStr(r.certSerialNumber.bytes),this.signatureOID=G.ASN1.parseOID(r.certSignatureOID.bytes),this.signatureAlgorithm=Sr.getOIDName(this.signatureOID),this.infoSignatureOID=G.ASN1.parseOID(r.certinfoSignatureOID.bytes),this.signature=G.ASN1.parseBitString(r.certSignature.bytes).buf,this.validFrom=G.ASN1.parseTime(r.certValidityNotBefore.tag,r.certValidityNotBefore.bytes),this.validTo=G.ASN1.parseTime(r.certValidityNotAfter.tag,r.certValidityNotAfter.bytes),this.issuer=new gu,this.issuer.setAttrs(Ey(r.certIssuer)),r.certIssuerUniqueId!=null&&(this.issuer.uniqueId=G.ASN1.parseBitString(r.certIssuerUniqueId.bytes)),this.subject=new gu,this.subject.setAttrs(Ey(r.certSubject)),r.certSubjectUniqueId!=null&&(this.subject.uniqueId=G.ASN1.parseBitString(r.certSubjectUniqueId.bytes)),this.extensions=[],this.subjectKeyIdentifier="",this.authorityKeyIdentifier="",this.ocspServer="",this.issuingCertificateURL="",this.isCA=!1,this.maxPathLen=-1,this.basicConstraintsValid=!1,this.keyUsage=0,this.dnsNames=[],this.emailAddresses=[],this.ipAddresses=[],this.uris=[],r.certExtensions!=null){this.extensions=TE(r.certExtensions);for(let s of this.extensions)if(typeof s.subjectKeyIdentifier=="string"&&(this.subjectKeyIdentifier=s.subjectKeyIdentifier),typeof s.authorityKeyIdentifier=="string"&&(this.authorityKeyIdentifier=s.authorityKeyIdentifier),typeof s.authorityInfoAccessOcsp=="string"&&(this.ocspServer=s.authorityInfoAccessOcsp),typeof s.authorityInfoAccessIssuers=="string"&&(this.issuingCertificateURL=s.authorityInfoAccessIssuers),typeof s.basicConstraintsValid=="boolean"&&(this.isCA=s.isCA,this.maxPathLen=s.maxPathLen,this.basicConstraintsValid=s.basicConstraintsValid),typeof s.keyUsage=="number"&&(this.keyUsage=s.keyUsage),Array.isArray(s.altNames))for(let i of s.altNames)i.dnsName!=null&&this.dnsNames.push(i.dnsName),i.email!=null&&this.emailAddresses.push(i.email),i.ip!=null&&this.ipAddresses.push(i.ip),i.uri!=null&&this.uris.push(i.uri)}this.publicKey=new Ay.PublicKey(r.publicKeyInfo),this.publicKeyRaw=this.publicKey.toDER(),this.tbsCertificate=r.tbsCertificate}getExtension(e,r=""){for(let n of this.extensions)if(e===n.oid||e===n.name)return r===""?n:n[r];return null}checkSignature(e){if(this.version===3&&!this.basicConstraintsValid||this.basicConstraintsValid&&!this.isCA)return new Error("The parent constraint violation error");if(this.getExtension("keyUsage","keyCertSign")!==!0)return new Error("The parent constraint violation error");if(!e.isIssuer(this))return new Error("The parent certificate did not issue the given child certificate");let r=HE(e.signatureOID);return r===""?new Error("Unknown child signature OID."):this.publicKey.verify(e.tbsCertificate.DER,e.signature,r)===!1?new Error("Child signature not matched"):null}isIssuer(e){return this.issuer.getHash().equals(e.subject.getHash())}verifySubjectKeyIdentifier(){return this.publicKey.getFingerprint("sha1","PublicKey").toString("hex")===this.subjectKeyIdentifier}toJSON(){let e={};for(let r of Object.keys(this))e[r]=jE(this[r]);return delete e.tbsCertificate,e}[vy.inspect.custom](e,r){return r.depth<=2&&(r.depth=10),`<${this.constructor.name} ${vy.inspect(this.toJSON(),r)}>`}};yl.Certificate=Lp;function TE(t){let e=[];for(let r of t.mustCompound())for(let n of r.mustCompound())e.push(_E(n));return e}function _E(t){let e={};switch(e.oid=G.ASN1.parseOID(t.value[0].bytes),e.critical=!1,t.value[1].tag===G.Tag.BOOLEAN?(e.critical=G.ASN1.parseBool(t.value[1].bytes),e.value=t.value[2].bytes):e.value=t.value[1].bytes,e.name=Sr.getOIDName(e.oid),e.name){case"keyUsage":BE(e);break;case"basicConstraints":kE(e);break;case"extKeyUsage":RE(e);break;case"nsCertType":NE(e);break;case"subjectAltName":wy(e);break;case"issuerAltName":wy(e);break;case"subjectKeyIdentifier":OE(e);break;case"authorityKeyIdentifier":UE(e);break;case"authorityInfoAccess":ME(e);break}return e}function BE(t){let e=G.ASN1.parseBitString(G.ASN1.fromDER(t.value).bytes),r=0,n=0;t.keyUsage=0;for(let s=0;s<9;s++)e.at(s)!==0&&(t.keyUsage|=1<<s);e.buf.length>0&&(r=e.buf[0],n=e.buf.length>1?e.buf[1]:0),t.digitalSignature=(r&128)===128,t.nonRepudiation=(r&64)===64,t.keyEncipherment=(r&32)===32,t.dataEncipherment=(r&16)===16,t.keyAgreement=(r&8)===8,t.keyCertSign=(r&4)===4,t.cRLSign=(r&2)===2,t.encipherOnly=(r&1)===1,t.decipherOnly=(n&128)===128}function kE(t){let r=G.ASN1.fromDER(t.value).mustCompound();r.length>0&&r[0].tag===G.Tag.BOOLEAN?t.isCA=G.ASN1.parseBool(r[0].bytes):t.isCA=!1;let n=null;r.length>0&&r[0].tag===G.Tag.INTEGER?n=r[0].bytes:r.length>1&&(n=r[1].bytes),n!==null?t.maxPathLen=G.ASN1.parseInteger(n):t.maxPathLen=-1,t.basicConstraintsValid=!0}function RE(t){let r=G.ASN1.fromDER(t.value).mustCompound();for(let n of r)t[Sr.getOIDName(G.ASN1.parseOID(n.bytes))]=!0}function NE(t){let e=G.ASN1.parseBitString(G.ASN1.fromDER(t.value).bytes),r=0;e.buf.length>0&&(r=e.buf[0]),t.client=(r&128)===128,t.server=(r&64)===64,t.email=(r&32)===32,t.objsign=(r&16)===16,t.reserved=(r&8)===8,t.sslCA=(r&4)===4,t.emailCA=(r&2)===2,t.objCA=(r&1)===1}function wy(t){t.altNames=[];let r=G.ASN1.fromDER(t.value).mustCompound();for(let n of r){let s={tag:n.tag,value:n.bytes};switch(t.altNames.push(s),n.tag){case 1:s.email=n.bytes.toString();break;case 2:s.dnsName=n.bytes.toString();break;case 6:s.uri=n.bytes.toString();break;case 7:s.ip=Sr.bytesToIP(n.bytes);break;case 8:s.oid=G.ASN1.parseOID(n.bytes);break;default:}}}var PE={name:"subjectKeyIdentifier",class:G.Class.UNIVERSAL,tag:G.Tag.OCTETSTRING,capture:"subjectKeyIdentifier"};function OE(t){let e=G.ASN1.parseDERWithTemplate(t.value,PE);t.subjectKeyIdentifier=e.subjectKeyIdentifier.bytes.toString("hex")}var LE={name:"authorityKeyIdentifier",class:G.Class.UNIVERSAL,tag:G.Tag.SEQUENCE,value:[{name:"authorityKeyIdentifier.value",class:G.Class.CONTEXT_SPECIFIC,tag:G.Tag.NONE,capture:"authorityKeyIdentifier"}]};function UE(t){let e=G.ASN1.parseDERWithTemplate(t.value,LE);t.authorityKeyIdentifier=e.authorityKeyIdentifier.bytes.toString("hex")}var DE={name:"authorityInfoAccess",class:G.Class.UNIVERSAL,tag:G.Tag.SEQUENCE,value:[{name:"authorityInfoAccess.authorityInfoAccessOcsp",class:G.Class.UNIVERSAL,tag:G.Tag.SEQUENCE,optional:!0,value:[{name:"authorityInfoAccess.authorityInfoAccessOcsp.oid",class:G.Class.UNIVERSAL,tag:G.Tag.OID},{name:"authorityInfoAccess.authorityInfoAccessOcsp.value",class:G.Class.CONTEXT_SPECIFIC,tag:G.Tag.OID,capture:"authorityInfoAccessOcsp"}]},{name:"authorityInfoAccess.authorityInfoAccessIssuers",class:G.Class.UNIVERSAL,tag:G.Tag.SEQUENCE,optional:!0,value:[{name:"authorityInfoAccess.authorityInfoAccessIssuers.oid",class:G.Class.UNIVERSAL,tag:G.Tag.OID},{name:"authorityInfoAccess.authorityInfoAccessIssuers.value",class:G.Class.CONTEXT_SPECIFIC,tag:G.Tag.OID,capture:"authorityInfoAccessIssuers"}]}]};function ME(t){let e=G.ASN1.parseDERWithTemplate(t.value,DE);e.authorityInfoAccessOcsp!=null&&(t.authorityInfoAccessOcsp=e.authorityInfoAccessOcsp.bytes.toString()),e.authorityInfoAccessIssuers!=null&&(t.authorityInfoAccessIssuers=e.authorityInfoAccessIssuers.bytes.toString())}function Sy(t){for(let e of t){if((e.name==null||e.name==="")&&(e.oid!=null&&(e.name=Sr.getOIDName(e.oid)),e.name===""&&e.shortName!=null&&(e.name=Sr.getOIDName(rr[e.shortName]))),e.oid==null||e.oid==="")if(e.name!=="")e.oid=Sr.getOID(e.name);else throw new Error("Attribute oid not specified.");if((e.shortName==null||e.shortName==="")&&(e.shortName=rr[e.name]==null?"":rr[e.name]),e.value==null)throw new Error("Attribute value not specified.")}}function HE(t){switch(Sr.getOIDName(t)){case"sha1WithRsaEncryption":return"sha1";case"md5WithRsaEncryption":return"md5";case"sha256WithRsaEncryption":return"sha256";case"sha384WithRsaEncryption":return"sha384";case"sha512WithRsaEncryption":return"sha512";case"RSASSA-PSS":return"sha256";case"ecdsaWithSha1":return"sha1";case"ecdsaWithSha256":return"sha256";case"ecdsaWithSha384":return"sha384";case"ecdsaWithSha512":return"sha512";case"dsaWithSha1":return"sha1";case"dsaWithSha256":return"sha256";default:return""}}function Ey(t){let e=[];for(let r of t.mustCompound())for(let n of r.mustCompound()){let s=n.mustCompound(),i={};i.oid=G.ASN1.parseOID(s[0].bytes),i.value=s[1].value,i.valueTag=s[1].tag,i.name=Sr.getOIDName(i.oid),i.shortName=CE(i.name),e.push(i)}return e}function jE(t){return t!=null&&!(t instanceof Buffer)&&typeof t.toJSON=="function"?t.toJSON():t}});var Up=Ve(sn=>{"use strict";Object.defineProperty(sn,"__esModule",{value:!0});var bl=ll();sn.bytesFromIP=bl.bytesFromIP;sn.bytesToIP=bl.bytesToIP;sn.getOID=bl.getOID;sn.getOIDName=bl.getOIDName;var vl=Op();sn.PublicKey=vl.PublicKey;sn.PrivateKey=vl.PrivateKey;sn.RSAPublicKey=vl.RSAPublicKey;sn.RSAPrivateKey=vl.RSAPrivateKey;var Iy=Cy();sn.Certificate=Iy.Certificate;sn.DistinguishedName=Iy.DistinguishedName});var _y=Ve(()=>{"use strict";var Ty;(function(t){(function(e){var r=typeof globalThis=="object"?globalThis:typeof global=="object"?global:typeof self=="object"?self:typeof this=="object"?this:a(),n=s(t);typeof r.Reflect<"u"&&(n=s(r.Reflect,n)),e(n,r),typeof r.Reflect>"u"&&(r.Reflect=t);function s(c,f){return function(l,p){Object.defineProperty(c,l,{configurable:!0,writable:!0,value:p}),f&&f(l,p)}}function i(){try{return Function("return this;")()}catch{}}function o(){try{return(0,eval)("(function() { return this; })()")}catch{}}function a(){return i()||o()}})(function(e,r){var n=Object.prototype.hasOwnProperty,s=typeof Symbol=="function",i=s&&typeof Symbol.toPrimitive<"u"?Symbol.toPrimitive:"@@toPrimitive",o=s&&typeof Symbol.iterator<"u"?Symbol.iterator:"@@iterator",a=typeof Object.create=="function",c={__proto__:[]}instanceof Array,f=!a&&!c,l={create:a?function(){return yo(Object.create(null))}:c?function(){return yo({__proto__:null})}:function(){return yo({})},has:f?function(B,P){return n.call(B,P)}:function(B,P){return P in B},get:f?function(B,P){return n.call(B,P)?B[P]:void 0}:function(B,P){return B[P]}},p=Object.getPrototypeOf(Function),x=typeof Map=="function"&&typeof Map.prototype.entries=="function"?Map:hu(),v=typeof Set=="function"&&typeof Set.prototype.entries=="function"?Set:al(),S=typeof WeakMap=="function"?WeakMap:yp(),I=s?Symbol.for("@reflect-metadata:registry"):void 0,L=ja(),ee=lu(L);function Pe(B,P,j,J){if(C(j)){if(!rn(B))throw new TypeError;if(!xo(P))throw new TypeError;return He(B,P)}else{if(!rn(B))throw new TypeError;if(!ne(P))throw new TypeError;if(!ne(J)&&!C(J)&&!N(J))throw new TypeError;return N(J)&&(J=void 0),j=Ct(j),q(B,P,j,J)}}e("decorate",Pe);function ie(B,P){function j(J,Be){if(!ne(J))throw new TypeError;if(!C(Be)&&!gp(Be))throw new TypeError;Te(B,P,J,Be)}return j}e("metadata",ie);function ve(B,P,j,J){if(!ne(j))throw new TypeError;return C(J)||(J=Ct(J)),Te(B,P,j,J)}e("defineMetadata",ve);function ze(B,P,j){if(!ne(P))throw new TypeError;return C(j)||(j=Ct(j)),V(B,P,j)}e("hasMetadata",ze);function he(B,P,j){if(!ne(P))throw new TypeError;return C(j)||(j=Ct(j)),M(B,P,j)}e("hasOwnMetadata",he);function Ne(B,P,j){if(!ne(P))throw new TypeError;return C(j)||(j=Ct(j)),oe(B,P,j)}e("getMetadata",Ne);function we(B,P,j){if(!ne(P))throw new TypeError;return C(j)||(j=Ct(j)),ge(B,P,j)}e("getOwnMetadata",we);function X(B,P){if(!ne(B))throw new TypeError;return C(P)||(P=Ct(P)),A(B,P)}e("getMetadataKeys",X);function ut(B,P){if(!ne(B))throw new TypeError;return C(P)||(P=Ct(P)),T(B,P)}e("getOwnMetadataKeys",ut);function St(B,P,j){if(!ne(P))throw new TypeError;if(C(j)||(j=Ct(j)),!ne(P))throw new TypeError;C(j)||(j=Ct(j));var J=Ss(P,j,!1);return C(J)?!1:J.OrdinaryDeleteMetadata(B,P,j)}e("deleteMetadata",St);function He(B,P){for(var j=B.length-1;j>=0;--j){var J=B[j],Be=J(P);if(!C(Be)&&!N(Be)){if(!xo(Be))throw new TypeError;P=Be}}return P}function q(B,P,j,J){for(var Be=B.length-1;Be>=0;--Be){var Rt=B[Be],Pt=Rt(P,j,J);if(!C(Pt)&&!N(Pt)){if(!ne(Pt))throw new TypeError;J=Pt}}return J}function V(B,P,j){var J=M(B,P,j);if(J)return!0;var Be=go(P);return N(Be)?!1:V(B,Be,j)}function M(B,P,j){var J=Ss(P,j,!1);return C(J)?!1:Et(J.OrdinaryHasOwnMetadata(B,P,j))}function oe(B,P,j){var J=M(B,P,j);if(J)return ge(B,P,j);var Be=go(P);if(!N(Be))return oe(B,Be,j)}function ge(B,P,j){var J=Ss(P,j,!1);if(!C(J))return J.OrdinaryGetOwnMetadata(B,P,j)}function Te(B,P,j,J){var Be=Ss(j,J,!0);Be.OrdinaryDefineOwnMetadata(B,P,j,J)}function A(B,P){var j=T(B,P),J=go(B);if(J===null)return j;var Be=A(J,P);if(Be.length<=0)return j;if(j.length<=0)return Be;for(var Rt=new v,Pt=[],Je=0,ae=j;Je<ae.length;Je++){var xe=ae[Je],Se=Rt.has(xe);Se||(Rt.add(xe),Pt.push(xe))}for(var Ce=0,Ke=Be;Ce<Ke.length;Ce++){var xe=Ke[Ce],Se=Rt.has(xe);Se||(Rt.add(xe),Pt.push(xe))}return Pt}function T(B,P){var j=Ss(B,P,!1);return j?j.OrdinaryOwnMetadataKeys(B,P):[]}function H(B){if(B===null)return 1;switch(typeof B){case"undefined":return 0;case"boolean":return 2;case"string":return 3;case"symbol":return 4;case"number":return 5;case"object":return B===null?1:6;default:return 6}}function C(B){return B===void 0}function N(B){return B===null}function Z(B){return typeof B=="symbol"}function ne(B){return typeof B=="object"?B!==null:typeof B=="function"}function Ye(B,P){switch(H(B)){case 0:return B;case 1:return B;case 2:return B;case 3:return B;case 4:return B;case 5:return B}var j=P===3?"string":P===5?"number":"default",J=cu(B,i);if(J!==void 0){var Be=J.call(B,j);if(ne(Be))throw new TypeError;return Be}return at(B,j==="default"?"number":j)}function at(B,P){if(P==="string"){var j=B.toString;if(nn(j)){var J=j.call(B);if(!ne(J))return J}var Be=B.valueOf;if(nn(Be)){var J=Be.call(B);if(!ne(J))return J}}else{var Be=B.valueOf;if(nn(Be)){var J=Be.call(B);if(!ne(J))return J}var Rt=B.toString;if(nn(Rt)){var J=Rt.call(B);if(!ne(J))return J}}throw new TypeError}function Et(B){return!!B}function lt(B){return""+B}function Ct(B){var P=Ye(B,3);return Z(P)?P:lt(P)}function rn(B){return Array.isArray?Array.isArray(B):B instanceof Object?B instanceof Array:Object.prototype.toString.call(B)==="[object Array]"}function nn(B){return typeof B=="function"}function xo(B){return typeof B=="function"}function gp(B){switch(H(B)){case 3:return!0;case 4:return!0;default:return!1}}function au(B,P){return B===P||B!==B&&P!==P}function cu(B,P){var j=B[P];if(j!=null){if(!nn(j))throw new TypeError;return j}}function uu(B){var P=cu(B,o);if(!nn(P))throw new TypeError;var j=P.call(B);if(!ne(j))throw new TypeError;return j}function Vn(B){return B.value}function mo(B){var P=B.next();return P.done?!1:P}function fu(B){var P=B.return;P&&P.call(B)}function go(B){var P=Object.getPrototypeOf(B);if(typeof B!="function"||B===p||P!==p)return P;var j=B.prototype,J=j&&Object.getPrototypeOf(j);if(J==null||J===Object.prototype)return P;var Be=J.constructor;return typeof Be!="function"||Be===B?P:Be}function du(){var B;!C(I)&&typeof r.Reflect<"u"&&!(I in r.Reflect)&&typeof r.Reflect.defineMetadata=="function"&&(B=qa(r.Reflect));var P,j,J,Be=new S,Rt={registerProvider:Pt,getProvider:ae,setProvider:Se};return Rt;function Pt(Ce){if(!Object.isExtensible(Rt))throw new Error("Cannot add provider to a frozen registry.");switch(!0){case B===Ce:break;case C(P):P=Ce;break;case P===Ce:break;case C(j):j=Ce;break;case j===Ce:break;default:J===void 0&&(J=new v),J.add(Ce);break}}function Je(Ce,Ke){if(!C(P)){if(P.isProviderFor(Ce,Ke))return P;if(!C(j)){if(j.isProviderFor(Ce,Ke))return P;if(!C(J))for(var yt=uu(J);;){var _t=mo(yt);if(!_t)return;var _r=Vn(_t);if(_r.isProviderFor(Ce,Ke))return fu(yt),_r}}}if(!C(B)&&B.isProviderFor(Ce,Ke))return B}function ae(Ce,Ke){var yt=Be.get(Ce),_t;return C(yt)||(_t=yt.get(Ke)),C(_t)&&(_t=Je(Ce,Ke),C(_t)||(C(yt)&&(yt=new x,Be.set(Ce,yt)),yt.set(Ke,_t))),_t}function xe(Ce){if(C(Ce))throw new TypeError;return P===Ce||j===Ce||!C(J)&&J.has(Ce)}function Se(Ce,Ke,yt){if(!xe(yt))throw new Error("Metadata provider not registered.");var _t=ae(Ce,Ke);if(_t!==yt){if(!C(_t))return!1;var _r=Be.get(Ce);C(_r)&&(_r=new x,Be.set(Ce,_r)),_r.set(Ke,yt)}return!0}}function ja(){var B;return!C(I)&&ne(r.Reflect)&&Object.isExtensible(r.Reflect)&&(B=r.Reflect[I]),C(B)&&(B=du()),!C(I)&&ne(r.Reflect)&&Object.isExtensible(r.Reflect)&&Object.defineProperty(r.Reflect,I,{enumerable:!1,configurable:!1,writable:!1,value:B}),B}function lu(B){var P=new S,j={isProviderFor:function(xe,Se){var Ce=P.get(xe);return C(Ce)?!1:Ce.has(Se)},OrdinaryDefineOwnMetadata:Pt,OrdinaryHasOwnMetadata:Be,OrdinaryGetOwnMetadata:Rt,OrdinaryOwnMetadataKeys:Je,OrdinaryDeleteMetadata:ae};return L.registerProvider(j),j;function J(xe,Se,Ce){var Ke=P.get(xe),yt=!1;if(C(Ke)){if(!Ce)return;Ke=new x,P.set(xe,Ke),yt=!0}var _t=Ke.get(Se);if(C(_t)){if(!Ce)return;if(_t=new x,Ke.set(Se,_t),!B.setProvider(xe,Se,j))throw Ke.delete(Se),yt&&P.delete(xe),new Error("Wrong provider for target.")}return _t}function Be(xe,Se,Ce){var Ke=J(Se,Ce,!1);return C(Ke)?!1:Et(Ke.has(xe))}function Rt(xe,Se,Ce){var Ke=J(Se,Ce,!1);if(!C(Ke))return Ke.get(xe)}function Pt(xe,Se,Ce,Ke){var yt=J(Ce,Ke,!0);yt.set(xe,Se)}function Je(xe,Se){var Ce=[],Ke=J(xe,Se,!1);if(C(Ke))return Ce;for(var yt=Ke.keys(),_t=uu(yt),_r=0;;){var Va=mo(_t);if(!Va)return Ce.length=_r,Ce;var cl=Vn(Va);try{Ce[_r]=cl}catch(bp){try{fu(_t)}finally{throw bp}}_r++}}function ae(xe,Se,Ce){var Ke=J(Se,Ce,!1);if(C(Ke)||!Ke.delete(xe))return!1;if(Ke.size===0){var yt=P.get(Se);C(yt)||(yt.delete(Ce),yt.size===0&&P.delete(yt))}return!0}}function qa(B){var P=B.defineMetadata,j=B.hasOwnMetadata,J=B.getOwnMetadata,Be=B.getOwnMetadataKeys,Rt=B.deleteMetadata,Pt=new S,Je={isProviderFor:function(ae,xe){var Se=Pt.get(ae);return!C(Se)&&Se.has(xe)?!0:Be(ae,xe).length?(C(Se)&&(Se=new v,Pt.set(ae,Se)),Se.add(xe),!0):!1},OrdinaryDefineOwnMetadata:P,OrdinaryHasOwnMetadata:j,OrdinaryGetOwnMetadata:J,OrdinaryOwnMetadataKeys:Be,OrdinaryDeleteMetadata:Rt};return Je}function Ss(B,P,j){var J=L.getProvider(B,P);if(!C(J))return J;if(j){if(L.setProvider(B,P,ee))return ee;throw new Error("Illegal state.")}}function hu(){var B={},P=[],j=(function(){function Je(ae,xe,Se){this._index=0,this._keys=ae,this._values=xe,this._selector=Se}return Je.prototype["@@iterator"]=function(){return this},Je.prototype[o]=function(){return this},Je.prototype.next=function(){var ae=this._index;if(ae>=0&&ae<this._keys.length){var xe=this._selector(this._keys[ae],this._values[ae]);return ae+1>=this._keys.length?(this._index=-1,this._keys=P,this._values=P):this._index++,{value:xe,done:!1}}return{value:void 0,done:!0}},Je.prototype.throw=function(ae){throw this._index>=0&&(this._index=-1,this._keys=P,this._values=P),ae},Je.prototype.return=function(ae){return this._index>=0&&(this._index=-1,this._keys=P,this._values=P),{value:ae,done:!0}},Je})(),J=(function(){function Je(){this._keys=[],this._values=[],this._cacheKey=B,this._cacheIndex=-2}return Object.defineProperty(Je.prototype,"size",{get:function(){return this._keys.length},enumerable:!0,configurable:!0}),Je.prototype.has=function(ae){return this._find(ae,!1)>=0},Je.prototype.get=function(ae){var xe=this._find(ae,!1);return xe>=0?this._values[xe]:void 0},Je.prototype.set=function(ae,xe){var Se=this._find(ae,!0);return this._values[Se]=xe,this},Je.prototype.delete=function(ae){var xe=this._find(ae,!1);if(xe>=0){for(var Se=this._keys.length,Ce=xe+1;Ce<Se;Ce++)this._keys[Ce-1]=this._keys[Ce],this._values[Ce-1]=this._values[Ce];return this._keys.length--,this._values.length--,au(ae,this._cacheKey)&&(this._cacheKey=B,this._cacheIndex=-2),!0}return!1},Je.prototype.clear=function(){this._keys.length=0,this._values.length=0,this._cacheKey=B,this._cacheIndex=-2},Je.prototype.keys=function(){return new j(this._keys,this._values,Be)},Je.prototype.values=function(){return new j(this._keys,this._values,Rt)},Je.prototype.entries=function(){return new j(this._keys,this._values,Pt)},Je.prototype["@@iterator"]=function(){return this.entries()},Je.prototype[o]=function(){return this.entries()},Je.prototype._find=function(ae,xe){if(!au(this._cacheKey,ae)){this._cacheIndex=-1;for(var Se=0;Se<this._keys.length;Se++)if(au(this._keys[Se],ae)){this._cacheIndex=Se;break}}return this._cacheIndex<0&&xe&&(this._cacheIndex=this._keys.length,this._keys.push(ae),this._values.push(void 0)),this._cacheIndex},Je})();return J;function Be(Je,ae){return Je}function Rt(Je,ae){return ae}function Pt(Je,ae){return[Je,ae]}}function al(){var B=(function(){function P(){this._map=new x}return Object.defineProperty(P.prototype,"size",{get:function(){return this._map.size},enumerable:!0,configurable:!0}),P.prototype.has=function(j){return this._map.has(j)},P.prototype.add=function(j){return this._map.set(j,j),this},P.prototype.delete=function(j){return this._map.delete(j)},P.prototype.clear=function(){this._map.clear()},P.prototype.keys=function(){return this._map.keys()},P.prototype.values=function(){return this._map.keys()},P.prototype.entries=function(){return this._map.entries()},P.prototype["@@iterator"]=function(){return this.keys()},P.prototype[o]=function(){return this.keys()},P})();return B}function yp(){var B=16,P=l.create(),j=J();return(function(){function ae(){this._key=J()}return ae.prototype.has=function(xe){var Se=Be(xe,!1);return Se!==void 0?l.has(Se,this._key):!1},ae.prototype.get=function(xe){var Se=Be(xe,!1);return Se!==void 0?l.get(Se,this._key):void 0},ae.prototype.set=function(xe,Se){var Ce=Be(xe,!0);return Ce[this._key]=Se,this},ae.prototype.delete=function(xe){var Se=Be(xe,!1);return Se!==void 0?delete Se[this._key]:!1},ae.prototype.clear=function(){this._key=J()},ae})();function J(){var ae;do ae="@@WeakMap@@"+Je();while(l.has(P,ae));return P[ae]=!0,ae}function Be(ae,xe){if(!n.call(ae,j)){if(!xe)return;Object.defineProperty(ae,j,{value:l.create()})}return ae[j]}function Rt(ae,xe){for(var Se=0;Se<xe;++Se)ae[Se]=Math.random()*255|0;return ae}function Pt(ae){if(typeof Uint8Array=="function"){var xe=new Uint8Array(ae);return typeof crypto<"u"?crypto.getRandomValues(xe):typeof msCrypto<"u"?msCrypto.getRandomValues(xe):Rt(xe,ae),xe}return Rt(new Array(ae),ae)}function Je(){var ae=Pt(B);ae[6]=ae[6]&79|64,ae[8]=ae[8]&191|128;for(var xe="",Se=0;Se<B;++Se){var Ce=ae[Se];(Se===4||Se===6||Se===8)&&(xe+="-"),Ce<16&&(xe+="0"),xe+=Ce.toString(16).toLowerCase()}return xe}}function yo(B){return B.__=void 0,delete B.__,B}})})(Ty||(Ty={}))});var Nv=Ve((KX,Rv)=>{"use strict";function YC(t){return/^[$A-Z\_a-z\xaa\xb5\xba\xc0-\xd6\xd8-\xf6\xf8-\u02c1\u02c6-\u02d1\u02e0-\u02e4\u02ec\u02ee\u0370-\u0374\u0376\u0377\u037a-\u037d\u0386\u0388-\u038a\u038c\u038e-\u03a1\u03a3-\u03f5\u03f7-\u0481\u048a-\u0527\u0531-\u0556\u0559\u0561-\u0587\u05d0-\u05ea\u05f0-\u05f2\u0620-\u064a\u066e\u066f\u0671-\u06d3\u06d5\u06e5\u06e6\u06ee\u06ef\u06fa-\u06fc\u06ff\u0710\u0712-\u072f\u074d-\u07a5\u07b1\u07ca-\u07ea\u07f4\u07f5\u07fa\u0800-\u0815\u081a\u0824\u0828\u0840-\u0858\u08a0\u08a2-\u08ac\u0904-\u0939\u093d\u0950\u0958-\u0961\u0971-\u0977\u0979-\u097f\u0985-\u098c\u098f\u0990\u0993-\u09a8\u09aa-\u09b0\u09b2\u09b6-\u09b9\u09bd\u09ce\u09dc\u09dd\u09df-\u09e1\u09f0\u09f1\u0a05-\u0a0a\u0a0f\u0a10\u0a13-\u0a28\u0a2a-\u0a30\u0a32\u0a33\u0a35\u0a36\u0a38\u0a39\u0a59-\u0a5c\u0a5e\u0a72-\u0a74\u0a85-\u0a8d\u0a8f-\u0a91\u0a93-\u0aa8\u0aaa-\u0ab0\u0ab2\u0ab3\u0ab5-\u0ab9\u0abd\u0ad0\u0ae0\u0ae1\u0b05-\u0b0c\u0b0f\u0b10\u0b13-\u0b28\u0b2a-\u0b30\u0b32\u0b33\u0b35-\u0b39\u0b3d\u0b5c\u0b5d\u0b5f-\u0b61\u0b71\u0b83\u0b85-\u0b8a\u0b8e-\u0b90\u0b92-\u0b95\u0b99\u0b9a\u0b9c\u0b9e\u0b9f\u0ba3\u0ba4\u0ba8-\u0baa\u0bae-\u0bb9\u0bd0\u0c05-\u0c0c\u0c0e-\u0c10\u0c12-\u0c28\u0c2a-\u0c33\u0c35-\u0c39\u0c3d\u0c58\u0c59\u0c60\u0c61\u0c85-\u0c8c\u0c8e-\u0c90\u0c92-\u0ca8\u0caa-\u0cb3\u0cb5-\u0cb9\u0cbd\u0cde\u0ce0\u0ce1\u0cf1\u0cf2\u0d05-\u0d0c\u0d0e-\u0d10\u0d12-\u0d3a\u0d3d\u0d4e\u0d60\u0d61\u0d7a-\u0d7f\u0d85-\u0d96\u0d9a-\u0db1\u0db3-\u0dbb\u0dbd\u0dc0-\u0dc6\u0e01-\u0e30\u0e32\u0e33\u0e40-\u0e46\u0e81\u0e82\u0e84\u0e87\u0e88\u0e8a\u0e8d\u0e94-\u0e97\u0e99-\u0e9f\u0ea1-\u0ea3\u0ea5\u0ea7\u0eaa\u0eab\u0ead-\u0eb0\u0eb2\u0eb3\u0ebd\u0ec0-\u0ec4\u0ec6\u0edc-\u0edf\u0f00\u0f40-\u0f47\u0f49-\u0f6c\u0f88-\u0f8c\u1000-\u102a\u103f\u1050-\u1055\u105a-\u105d\u1061\u1065\u1066\u106e-\u1070\u1075-\u1081\u108e\u10a0-\u10c5\u10c7\u10cd\u10d0-\u10fa\u10fc-\u1248\u124a-\u124d\u1250-\u1256\u1258\u125a-\u125d\u1260-\u1288\u128a-\u128d\u1290-\u12b0\u12b2-\u12b5\u12b8-\u12be\u12c0\u12c2-\u12c5\u12c8-\u12d6\u12d8-\u1310\u1312-\u1315\u1318-\u135a\u1380-\u138f\u13a0-\u13f4\u1401-\u166c\u166f-\u167f\u1681-\u169a\u16a0-\u16ea\u16ee-\u16f0\u1700-\u170c\u170e-\u1711\u1720-\u1731\u1740-\u1751\u1760-\u176c\u176e-\u1770\u1780-\u17b3\u17d7\u17dc\u1820-\u1877\u1880-\u18a8\u18aa\u18b0-\u18f5\u1900-\u191c\u1950-\u196d\u1970-\u1974\u1980-\u19ab\u19c1-\u19c7\u1a00-\u1a16\u1a20-\u1a54\u1aa7\u1b05-\u1b33\u1b45-\u1b4b\u1b83-\u1ba0\u1bae\u1baf\u1bba-\u1be5\u1c00-\u1c23\u1c4d-\u1c4f\u1c5a-\u1c7d\u1ce9-\u1cec\u1cee-\u1cf1\u1cf5\u1cf6\u1d00-\u1dbf\u1e00-\u1f15\u1f18-\u1f1d\u1f20-\u1f45\u1f48-\u1f4d\u1f50-\u1f57\u1f59\u1f5b\u1f5d\u1f5f-\u1f7d\u1f80-\u1fb4\u1fb6-\u1fbc\u1fbe\u1fc2-\u1fc4\u1fc6-\u1fcc\u1fd0-\u1fd3\u1fd6-\u1fdb\u1fe0-\u1fec\u1ff2-\u1ff4\u1ff6-\u1ffc\u2071\u207f\u2090-\u209c\u2102\u2107\u210a-\u2113\u2115\u2119-\u211d\u2124\u2126\u2128\u212a-\u212d\u212f-\u2139\u213c-\u213f\u2145-\u2149\u214e\u2160-\u2188\u2c00-\u2c2e\u2c30-\u2c5e\u2c60-\u2ce4\u2ceb-\u2cee\u2cf2\u2cf3\u2d00-\u2d25\u2d27\u2d2d\u2d30-\u2d67\u2d6f\u2d80-\u2d96\u2da0-\u2da6\u2da8-\u2dae\u2db0-\u2db6\u2db8-\u2dbe\u2dc0-\u2dc6\u2dc8-\u2dce\u2dd0-\u2dd6\u2dd8-\u2dde\u2e2f\u3005-\u3007\u3021-\u3029\u3031-\u3035\u3038-\u303c\u3041-\u3096\u309d-\u309f\u30a1-\u30fa\u30fc-\u30ff\u3105-\u312d\u3131-\u318e\u31a0-\u31ba\u31f0-\u31ff\u3400-\u4db5\u4e00-\u9fcc\ua000-\ua48c\ua4d0-\ua4fd\ua500-\ua60c\ua610-\ua61f\ua62a\ua62b\ua640-\ua66e\ua67f-\ua697\ua6a0-\ua6ef\ua717-\ua71f\ua722-\ua788\ua78b-\ua78e\ua790-\ua793\ua7a0-\ua7aa\ua7f8-\ua801\ua803-\ua805\ua807-\ua80a\ua80c-\ua822\ua840-\ua873\ua882-\ua8b3\ua8f2-\ua8f7\ua8fb\ua90a-\ua925\ua930-\ua946\ua960-\ua97c\ua984-\ua9b2\ua9cf\uaa00-\uaa28\uaa40-\uaa42\uaa44-\uaa4b\uaa60-\uaa76\uaa7a\uaa80-\uaaaf\uaab1\uaab5\uaab6\uaab9-\uaabd\uaac0\uaac2\uaadb-\uaadd\uaae0-\uaaea\uaaf2-\uaaf4\uab01-\uab06\uab09-\uab0e\uab11-\uab16\uab20-\uab26\uab28-\uab2e\uabc0-\uabe2\uac00-\ud7a3\ud7b0-\ud7c6\ud7cb-\ud7fb\uf900-\ufa6d\ufa70-\ufad9\ufb00-\ufb06\ufb13-\ufb17\ufb1d\ufb1f-\ufb28\ufb2a-\ufb36\ufb38-\ufb3c\ufb3e\ufb40\ufb41\ufb43\ufb44\ufb46-\ufbb1\ufbd3-\ufd3d\ufd50-\ufd8f\ufd92-\ufdc7\ufdf0-\ufdfb\ufe70-\ufe74\ufe76-\ufefc\uff21-\uff3a\uff41-\uff5a\uff66-\uffbe\uffc2-\uffc7\uffca-\uffcf\uffd2-\uffd7\uffda-\uffdc][$A-Z\_a-z\xaa\xb5\xba\xc0-\xd6\xd8-\xf6\xf8-\u02c1\u02c6-\u02d1\u02e0-\u02e4\u02ec\u02ee\u0370-\u0374\u0376\u0377\u037a-\u037d\u0386\u0388-\u038a\u038c\u038e-\u03a1\u03a3-\u03f5\u03f7-\u0481\u048a-\u0527\u0531-\u0556\u0559\u0561-\u0587\u05d0-\u05ea\u05f0-\u05f2\u0620-\u064a\u066e\u066f\u0671-\u06d3\u06d5\u06e5\u06e6\u06ee\u06ef\u06fa-\u06fc\u06ff\u0710\u0712-\u072f\u074d-\u07a5\u07b1\u07ca-\u07ea\u07f4\u07f5\u07fa\u0800-\u0815\u081a\u0824\u0828\u0840-\u0858\u08a0\u08a2-\u08ac\u0904-\u0939\u093d\u0950\u0958-\u0961\u0971-\u0977\u0979-\u097f\u0985-\u098c\u098f\u0990\u0993-\u09a8\u09aa-\u09b0\u09b2\u09b6-\u09b9\u09bd\u09ce\u09dc\u09dd\u09df-\u09e1\u09f0\u09f1\u0a05-\u0a0a\u0a0f\u0a10\u0a13-\u0a28\u0a2a-\u0a30\u0a32\u0a33\u0a35\u0a36\u0a38\u0a39\u0a59-\u0a5c\u0a5e\u0a72-\u0a74\u0a85-\u0a8d\u0a8f-\u0a91\u0a93-\u0aa8\u0aaa-\u0ab0\u0ab2\u0ab3\u0ab5-\u0ab9\u0abd\u0ad0\u0ae0\u0ae1\u0b05-\u0b0c\u0b0f\u0b10\u0b13-\u0b28\u0b2a-\u0b30\u0b32\u0b33\u0b35-\u0b39\u0b3d\u0b5c\u0b5d\u0b5f-\u0b61\u0b71\u0b83\u0b85-\u0b8a\u0b8e-\u0b90\u0b92-\u0b95\u0b99\u0b9a\u0b9c\u0b9e\u0b9f\u0ba3\u0ba4\u0ba8-\u0baa\u0bae-\u0bb9\u0bd0\u0c05-\u0c0c\u0c0e-\u0c10\u0c12-\u0c28\u0c2a-\u0c33\u0c35-\u0c39\u0c3d\u0c58\u0c59\u0c60\u0c61\u0c85-\u0c8c\u0c8e-\u0c90\u0c92-\u0ca8\u0caa-\u0cb3\u0cb5-\u0cb9\u0cbd\u0cde\u0ce0\u0ce1\u0cf1\u0cf2\u0d05-\u0d0c\u0d0e-\u0d10\u0d12-\u0d3a\u0d3d\u0d4e\u0d60\u0d61\u0d7a-\u0d7f\u0d85-\u0d96\u0d9a-\u0db1\u0db3-\u0dbb\u0dbd\u0dc0-\u0dc6\u0e01-\u0e30\u0e32\u0e33\u0e40-\u0e46\u0e81\u0e82\u0e84\u0e87\u0e88\u0e8a\u0e8d\u0e94-\u0e97\u0e99-\u0e9f\u0ea1-\u0ea3\u0ea5\u0ea7\u0eaa\u0eab\u0ead-\u0eb0\u0eb2\u0eb3\u0ebd\u0ec0-\u0ec4\u0ec6\u0edc-\u0edf\u0f00\u0f40-\u0f47\u0f49-\u0f6c\u0f88-\u0f8c\u1000-\u102a\u103f\u1050-\u1055\u105a-\u105d\u1061\u1065\u1066\u106e-\u1070\u1075-\u1081\u108e\u10a0-\u10c5\u10c7\u10cd\u10d0-\u10fa\u10fc-\u1248\u124a-\u124d\u1250-\u1256\u1258\u125a-\u125d\u1260-\u1288\u128a-\u128d\u1290-\u12b0\u12b2-\u12b5\u12b8-\u12be\u12c0\u12c2-\u12c5\u12c8-\u12d6\u12d8-\u1310\u1312-\u1315\u1318-\u135a\u1380-\u138f\u13a0-\u13f4\u1401-\u166c\u166f-\u167f\u1681-\u169a\u16a0-\u16ea\u16ee-\u16f0\u1700-\u170c\u170e-\u1711\u1720-\u1731\u1740-\u1751\u1760-\u176c\u176e-\u1770\u1780-\u17b3\u17d7\u17dc\u1820-\u1877\u1880-\u18a8\u18aa\u18b0-\u18f5\u1900-\u191c\u1950-\u196d\u1970-\u1974\u1980-\u19ab\u19c1-\u19c7\u1a00-\u1a16\u1a20-\u1a54\u1aa7\u1b05-\u1b33\u1b45-\u1b4b\u1b83-\u1ba0\u1bae\u1baf\u1bba-\u1be5\u1c00-\u1c23\u1c4d-\u1c4f\u1c5a-\u1c7d\u1ce9-\u1cec\u1cee-\u1cf1\u1cf5\u1cf6\u1d00-\u1dbf\u1e00-\u1f15\u1f18-\u1f1d\u1f20-\u1f45\u1f48-\u1f4d\u1f50-\u1f57\u1f59\u1f5b\u1f5d\u1f5f-\u1f7d\u1f80-\u1fb4\u1fb6-\u1fbc\u1fbe\u1fc2-\u1fc4\u1fc6-\u1fcc\u1fd0-\u1fd3\u1fd6-\u1fdb\u1fe0-\u1fec\u1ff2-\u1ff4\u1ff6-\u1ffc\u2071\u207f\u2090-\u209c\u2102\u2107\u210a-\u2113\u2115\u2119-\u211d\u2124\u2126\u2128\u212a-\u212d\u212f-\u2139\u213c-\u213f\u2145-\u2149\u214e\u2160-\u2188\u2c00-\u2c2e\u2c30-\u2c5e\u2c60-\u2ce4\u2ceb-\u2cee\u2cf2\u2cf3\u2d00-\u2d25\u2d27\u2d2d\u2d30-\u2d67\u2d6f\u2d80-\u2d96\u2da0-\u2da6\u2da8-\u2dae\u2db0-\u2db6\u2db8-\u2dbe\u2dc0-\u2dc6\u2dc8-\u2dce\u2dd0-\u2dd6\u2dd8-\u2dde\u2e2f\u3005-\u3007\u3021-\u3029\u3031-\u3035\u3038-\u303c\u3041-\u3096\u309d-\u309f\u30a1-\u30fa\u30fc-\u30ff\u3105-\u312d\u3131-\u318e\u31a0-\u31ba\u31f0-\u31ff\u3400-\u4db5\u4e00-\u9fcc\ua000-\ua48c\ua4d0-\ua4fd\ua500-\ua60c\ua610-\ua61f\ua62a\ua62b\ua640-\ua66e\ua67f-\ua697\ua6a0-\ua6ef\ua717-\ua71f\ua722-\ua788\ua78b-\ua78e\ua790-\ua793\ua7a0-\ua7aa\ua7f8-\ua801\ua803-\ua805\ua807-\ua80a\ua80c-\ua822\ua840-\ua873\ua882-\ua8b3\ua8f2-\ua8f7\ua8fb\ua90a-\ua925\ua930-\ua946\ua960-\ua97c\ua984-\ua9b2\ua9cf\uaa00-\uaa28\uaa40-\uaa42\uaa44-\uaa4b\uaa60-\uaa76\uaa7a\uaa80-\uaaaf\uaab1\uaab5\uaab6\uaab9-\uaabd\uaac0\uaac2\uaadb-\uaadd\uaae0-\uaaea\uaaf2-\uaaf4\uab01-\uab06\uab09-\uab0e\uab11-\uab16\uab20-\uab26\uab28-\uab2e\uabc0-\uabe2\uac00-\ud7a3\ud7b0-\ud7c6\ud7cb-\ud7fb\uf900-\ufa6d\ufa70-\ufad9\ufb00-\ufb06\ufb13-\ufb17\ufb1d\ufb1f-\ufb28\ufb2a-\ufb36\ufb38-\ufb3c\ufb3e\ufb40\ufb41\ufb43\ufb44\ufb46-\ufbb1\ufbd3-\ufd3d\ufd50-\ufd8f\ufd92-\ufdc7\ufdf0-\ufdfb\ufe70-\ufe74\ufe76-\ufefc\uff21-\uff3a\uff41-\uff5a\uff66-\uffbe\uffc2-\uffc7\uffca-\uffcf\uffd2-\uffd7\uffda-\uffdc0-9\u0300-\u036f\u0483-\u0487\u0591-\u05bd\u05bf\u05c1\u05c2\u05c4\u05c5\u05c7\u0610-\u061a\u064b-\u0669\u0670\u06d6-\u06dc\u06df-\u06e4\u06e7\u06e8\u06ea-\u06ed\u06f0-\u06f9\u0711\u0730-\u074a\u07a6-\u07b0\u07c0-\u07c9\u07eb-\u07f3\u0816-\u0819\u081b-\u0823\u0825-\u0827\u0829-\u082d\u0859-\u085b\u08e4-\u08fe\u0900-\u0903\u093a-\u093c\u093e-\u094f\u0951-\u0957\u0962\u0963\u0966-\u096f\u0981-\u0983\u09bc\u09be-\u09c4\u09c7\u09c8\u09cb-\u09cd\u09d7\u09e2\u09e3\u09e6-\u09ef\u0a01-\u0a03\u0a3c\u0a3e-\u0a42\u0a47\u0a48\u0a4b-\u0a4d\u0a51\u0a66-\u0a71\u0a75\u0a81-\u0a83\u0abc\u0abe-\u0ac5\u0ac7-\u0ac9\u0acb-\u0acd\u0ae2\u0ae3\u0ae6-\u0aef\u0b01-\u0b03\u0b3c\u0b3e-\u0b44\u0b47\u0b48\u0b4b-\u0b4d\u0b56\u0b57\u0b62\u0b63\u0b66-\u0b6f\u0b82\u0bbe-\u0bc2\u0bc6-\u0bc8\u0bca-\u0bcd\u0bd7\u0be6-\u0bef\u0c01-\u0c03\u0c3e-\u0c44\u0c46-\u0c48\u0c4a-\u0c4d\u0c55\u0c56\u0c62\u0c63\u0c66-\u0c6f\u0c82\u0c83\u0cbc\u0cbe-\u0cc4\u0cc6-\u0cc8\u0cca-\u0ccd\u0cd5\u0cd6\u0ce2\u0ce3\u0ce6-\u0cef\u0d02\u0d03\u0d3e-\u0d44\u0d46-\u0d48\u0d4a-\u0d4d\u0d57\u0d62\u0d63\u0d66-\u0d6f\u0d82\u0d83\u0dca\u0dcf-\u0dd4\u0dd6\u0dd8-\u0ddf\u0df2\u0df3\u0e31\u0e34-\u0e3a\u0e47-\u0e4e\u0e50-\u0e59\u0eb1\u0eb4-\u0eb9\u0ebb\u0ebc\u0ec8-\u0ecd\u0ed0-\u0ed9\u0f18\u0f19\u0f20-\u0f29\u0f35\u0f37\u0f39\u0f3e\u0f3f\u0f71-\u0f84\u0f86\u0f87\u0f8d-\u0f97\u0f99-\u0fbc\u0fc6\u102b-\u103e\u1040-\u1049\u1056-\u1059\u105e-\u1060\u1062-\u1064\u1067-\u106d\u1071-\u1074\u1082-\u108d\u108f-\u109d\u135d-\u135f\u1712-\u1714\u1732-\u1734\u1752\u1753\u1772\u1773\u17b4-\u17d3\u17dd\u17e0-\u17e9\u180b-\u180d\u1810-\u1819\u18a9\u1920-\u192b\u1930-\u193b\u1946-\u194f\u19b0-\u19c0\u19c8\u19c9\u19d0-\u19d9\u1a17-\u1a1b\u1a55-\u1a5e\u1a60-\u1a7c\u1a7f-\u1a89\u1a90-\u1a99\u1b00-\u1b04\u1b34-\u1b44\u1b50-\u1b59\u1b6b-\u1b73\u1b80-\u1b82\u1ba1-\u1bad\u1bb0-\u1bb9\u1be6-\u1bf3\u1c24-\u1c37\u1c40-\u1c49\u1c50-\u1c59\u1cd0-\u1cd2\u1cd4-\u1ce8\u1ced\u1cf2-\u1cf4\u1dc0-\u1de6\u1dfc-\u1dff\u200c\u200d\u203f\u2040\u2054\u20d0-\u20dc\u20e1\u20e5-\u20f0\u2cef-\u2cf1\u2d7f\u2de0-\u2dff\u302a-\u302f\u3099\u309a\ua620-\ua629\ua66f\ua674-\ua67d\ua69f\ua6f0\ua6f1\ua802\ua806\ua80b\ua823-\ua827\ua880\ua881\ua8b4-\ua8c4\ua8d0-\ua8d9\ua8e0-\ua8f1\ua900-\ua909\ua926-\ua92d\ua947-\ua953\ua980-\ua983\ua9b3-\ua9c0\ua9d0-\ua9d9\uaa29-\uaa36\uaa43\uaa4c\uaa4d\uaa50-\uaa59\uaa7b\uaab0\uaab2-\uaab4\uaab7\uaab8\uaabe\uaabf\uaac1\uaaeb-\uaaef\uaaf5\uaaf6\uabe3-\uabea\uabec\uabed\uabf0-\uabf9\ufb1e\ufe00-\ufe0f\ufe20-\ufe26\ufe33\ufe34\ufe4d-\ufe4f\uff10-\uff19\uff3f]*$/.test(t)}Rv.exports=YC});var Qf=Ve(($X,qv)=>{"use strict";var Pv=Gt("util"),Dv=Nv(),Ov=/[\{\[]/,Lv=/[\}\]]/,Uv=["do","if","in","for","let","new","try","var","case","else","enum","eval","null","this","true","void","with","await","break","catch","class","const","false","super","throw","while","yield","delete","export","import","public","return","static","switch","typeof","default","extends","finally","package","private","continue","debugger","function","arguments","interface","protected","implements","instanceof","NaN","undefined"],Mv={};for(K0=0;K0<Uv.length;K0++)Mv[Uv[K0]]=!0;var K0,ZC=function(t){return Dv(t)&&!Mv.hasOwnProperty(t)},Hv={s:function(t){return""+t},d:function(t){return""+Number(t)},o:function(t){return JSON.stringify(t)}},jv=function(){var t=[],e=0,r={},n=function(o){for(var a="";a.length<e*2;)a+=" ";t.push(a+o)},s=function(o){if(Lv.test(o.trim()[0])&&Ov.test(o[o.length-1])){e--,n(o),e++;return}if(Ov.test(o[o.length-1])){n(o),e++;return}if(Lv.test(o.trim()[0])){e--,n(o);return}n(o)},i=function(o){if(!o)return i;if(arguments.length===1&&o.indexOf(`
13
+ `)>-1)for(var a=o.trim().split(`
14
+ `),c=0;c<a.length;c++)s(a[c].trim());else s(Pv.format.apply(Pv,arguments));return i};return i.scope={},i.formats=Hv,i.sym=function(o){return(!o||!ZC(o))&&(o="tmp"),r[o]||(r[o]=0),o+(r[o]++||"")},i.property=function(o,a){return arguments.length===1&&(a=o,o=""),a=a+"",Dv(a)?o?o+"."+a:a:o?o+"["+JSON.stringify(a)+"]":JSON.stringify(a)},i.toString=function(){return t.join(`
15
+ `)},i.toFunction=function(o){o||(o={});var a="return ("+i.toString()+")";Object.keys(i.scope).forEach(function(l){o[l]||(o[l]=i.scope[l])});var c=Object.keys(o).map(function(l){return l}),f=c.map(function(l){return o[l]});return Function.apply(null,c.concat(a)).apply(null,f)},arguments.length&&i.apply(null,arguments),i};jv.formats=Hv;qv.exports=jv});var zv=Ve((WX,Vv)=>{"use strict";var W0=class{constructor(){this.next=null,this.buffer=null}};Vv.exports=class $0{constructor(){this.head=null,this.tail=null,this.length=0,this.count=0}push(e){let r=new W0;r.buffer=e,this.length>0?this.tail.next=r:this.head=r,this.tail=r,this.length+=e.length,this.count+=1}unshift(e){let r=new W0;r.buffer=e,r.next=this.head,this.isEmpty()&&(this.tail=r),this.head=r,this.length+=e.length,this.count+=1}shift(){if(this.isEmpty())return null;let e=this.head.buffer;return this.head===this.tail?(this.head=null,this.tail=null):this.head=this.head.next,this.length-=e.length,this.length=Math.max(this.length,0),this.count-=1,e}get first(){return this.isEmpty()?null:this.head.buffer}get last(){return this.isEmpty()?null:this.tail.buffer}isEmpty(){return this.length===0}clear(){this.head=null,this.tail=null,this.length=0,this.count=0}slice(e,r){if(e<0||e>=this.length)return new $0;if(r<0||r>this.length||r<e)return new $0;let n=new $0,s=this.head,i=e,o=r;for(;s;){if(s.buffer.length>i){i===0&&s.buffer.length<=o?n.push(s.buffer):s.buffer.length>=o?n.push(s.buffer.slice(i,o)):n.push(s.buffer.slice(i));break}i-=s.buffer.length,o-=s.buffer.length,s=s.next}if(s.buffer.length<o)for(;s;){if(s.buffer.length===o){n.push(s.buffer);break}else if(s.buffer.length>o){n.push(s.buffer.slice(0,o));break}else i<0&&s.buffer.length<o&&n.push(s.buffer);i-=s.buffer.length,o-=s.buffer.length,s=s.next}return n}}});var Wv=Ve((GX,$v)=>{"use strict";var G0=Qf(),JC=zv(),pa=class t{constructor(){this.queue=new JC,this.offset=0}get length(){return this.queue.length-this.offset}append(e){if(Buffer.isBuffer(e)){if(this.offset>0){let r=this.queue.shift();this.queue.unshift(r.slice(this.offset)),this.offset=0}this.queue.push(e)}else if(Array.isArray(e))for(let r=0;r<e.length;r+=1)this.append(e[r]);else if(e instanceof t){if(this.offset>0){let n=this.queue.shift();this.queue.unshift(n.slice(this.offset)),this.offset=0}if(e.offset>0){let n=e.queue.shift();e.queue.unshift(n.slice(e.offset)),e.offset=0}let r=e.queue.head;for(;r;)this.queue.push(r.buffer),r=r.next}}get(e){let r=e;for(;r>=this.length;)r-=this.length;for(;r<0;)r+=this.length;let n=this.queue.head,{offset:s}=this;for(;n;){if(n.buffer.length-s>r)return n.buffer[r+s];r-=n.buffer.length-s,s=0,n=n.next}}slice(e,r){for(typeof e!="number"&&(e=0),typeof r!="number"&&(r=this.length);e<0;)e+=this.length;for(;r<0;)r+=this.length;if(r=Math.min(r,this.length),e>=this.length||r===0)return Buffer.alloc(0);let n=e;e=Math.min(n,r),r=Math.max(n,r);let s=this.queue.slice(e+this.offset,r+this.offset);if(s.count===1)return s.first;let i=s.head,o=Buffer.allocUnsafe(s.length),a=0;for(let c=0;c<s.count;c+=1)o.set(i.buffer,a),a+=i.buffer.length,i=i.next;return o}toString(e,r,n){return this.slice(r,n).toString(e)}consume(e){let r=e;for(;this.length>0;){let n=this.queue.first.length-this.offset;if(r>=n)this.queue.shift(),r-=n,this.offset=0;else{this.offset+=r;break}}}indexOf(e,r=0){if(!Number.isInteger(e))throw new TypeError("Invalid argument 1");if(e<0||e>255)throw new Error("Invalid argument 1");for(Number.isInteger(r)||(r=0);r>=this.length;)r-=this.length;for(;r<0;)r+=this.length;let n=this.queue.head,s=0,i=()=>{s+=n.buffer.length,n=n.next};for(;n;){let o=0;if(n===this.queue.head&&(o+=this.offset),r>=n.buffer.length-o){r-=n.buffer.length-o,i();continue}r<n.buffer.length&&(o+=r);let a=n.buffer.indexOf(e,o);if(a>-1)return a+s-this.offset;i(),o>this.offset&&(r=0)}return-1}},Fv={readDoubleBE:8,readDoubleLE:8,readFloatBE:4,readFloatLE:4,readInt32BE:4,readInt32LE:4,readUInt32BE:4,readUInt32LE:4,readInt16BE:2,readInt16LE:2,readUInt16BE:2,readUInt16LE:2,readInt8:1,readUInt8:1};Object.keys(Fv).forEach(t=>{let e=G0();e(`
16
+ function bufferlist_${t}(offset = 0) {
17
+ const start = offset + this.offset;
18
+ const head = this.queue.first;
19
+ const size = ${e.formats.d(Fv[t])};
20
+ const isFirtsChunkEnough = head.length - start >= size;
21
+
22
+ return isFirtsChunkEnough
23
+ ? head.${t}(start)
24
+ : this.slice(offset, offset + size).${t}(0)
25
+ }
26
+ `),pa.prototype[t]=e.toFunction()});var QC=["readIntBE","readIntLE","readUIntBE","readUIntLE"];QC.forEach(t=>{let e=G0();e(`
27
+ function bufferlist_${t}(size, offset = 0) {
28
+ const start = offset + this.offset;
29
+ const head = this.queue.first;
30
+ const isFirtsChunkEnough = head.length - start >= size;
31
+
32
+ return isFirtsChunkEnough
33
+ ? head.${t}(start, size)
34
+ : this.slice(offset, offset + size).${t}(0, size)
35
+ }
36
+ `),pa.prototype[t]=e.toFunction()});var Kv={writeDoubleBE:8,writeDoubleLE:8,writeFloatBE:4,writeFloatLE:4,writeInt32BE:4,writeInt32LE:4,writeUInt32BE:4,writeUInt32LE:4,writeInt16BE:2,writeInt16LE:2,writeUInt16BE:2,writeUInt16LE:2,writeInt8:1,writeUInt8:1};Object.keys(Kv).forEach(t=>{let e=G0();e(`
37
+ function bufferlist_${t}(value) {
38
+ const size = ${e.formats.d(Kv[t])};
39
+ const buf = Buffer.allocUnsafe(size);
40
+ buf.${t}(value, 0);
41
+ this.append(buf);
42
+ }
43
+ `),pa.prototype[t]=e.toFunction()});var e9=["writeIntBE","writeIntLE","writeUIntBE","writeUIntLE"];e9.forEach(t=>{let e=G0();e(`
44
+ function bufferlist_${t}(value, size) {
45
+ const buf = Buffer.allocUnsafe(size);
46
+ buf.${t}(value, 0, size);
47
+ this.append(buf);
48
+ }
49
+ `),pa.prototype[t]=e.toFunction()});$v.exports=pa});var kc=Ve((YX,Gv)=>{"use strict";Gv.exports=class extends Error{constructor(e,r){let n=`requested ${e} bytes but only ${r} available`;super(n),this.name="NotEnoughDataError"}}});var ed=Ve((ZX,Zv)=>{"use strict";var{Transform:t9}=Gt("stream"),X0=Qf(),r9=Wv(),n9=kc(),Xv=Symbol("buffer"),xa=class extends t9{constructor(e={}){super(e),this[Xv]=new r9}get buffer(){return this[Xv]}get length(){return this.buffer.length}append(e){this.buffer.append(e)}get(e){return this.buffer.get(e)}slice(e,r){return this.buffer.slice(e,r)}consume(e){this.buffer.consume(e)}toString(e,r,n){return this.buffer.toString(e,r,n)}indexOf(e,r=0){return this.buffer.indexOf(e,r)}readBuffer(e){Om(e,this.length);let r=this.slice(0,e);return this.consume(e),r}writeBuffer(e){this.append(e)}},Yv={readDoubleBE:8,readDoubleLE:8,readFloatBE:4,readFloatLE:4,readInt32BE:4,readInt32LE:4,readUInt32BE:4,readUInt32LE:4,readInt16BE:2,readInt16LE:2,readUInt16BE:2,readUInt16LE:2,readInt8:1,readUInt8:1},s9=["readIntBE","readIntLE","readUIntBE","readUIntLE"];Object.keys(Yv).forEach(t=>{let e=X0();e(`
50
+ function binary_${t}() {
51
+ const bytes = ${e.formats.d(Yv[t])};
52
+ assertSize(bytes, this.length);
53
+
54
+ const res = this.buffer.${t}(0);
55
+ this.consume(bytes);
56
+
57
+ return res;
58
+ }
59
+ `),xa.prototype[t]=e.toFunction({assertSize:Om})});s9.forEach(t=>{let e=X0();e(`
60
+ function binary_${t}(size) {
61
+ assertSize(size, this.length);
62
+
63
+ const res = this.buffer.${t}(size, 0);
64
+ this.consume(size);
65
+ return res;
66
+ }
67
+ `),xa.prototype[t]=e.toFunction({assertSize:Om})});var i9=["writeDoubleBE","writeDoubleLE","writeFloatBE","writeFloatLE","writeInt32BE","writeInt32LE","writeUInt32BE","writeUInt32LE","writeInt16BE","writeInt16LE","writeUInt16BE","writeUInt16LE","writeInt8","writeUInt8"];i9.forEach(t=>{let e=X0();e(`
68
+ function binary_${t}(value) {
69
+ this.buffer.${t}(value);
70
+ }
71
+ `),xa.prototype[t]=e.toFunction()});var o9=["writeIntBE","writeIntLE","writeUIntBE","writeUIntLE"];o9.forEach(t=>{let e=X0();e(`
72
+ function binary_${t}(value, size) {
73
+ this.buffer.${t}(value, size);
74
+ }
75
+ `),xa.prototype[t]=e.toFunction()});function Om(t,e){if(t>e)throw new n9(t,e)}Zv.exports=xa});var Qv=Ve((JX,Jv)=>{"use strict";Jv.exports=function(e){return e!=null&&typeof e=="object"&&Array.isArray(e)===!1}});var rw=Ve((QX,tw)=>{"use strict";var a9=Qv();function ew(t){return a9(t)===!0&&Object.prototype.toString.call(t)==="[object Object]"}tw.exports=function(e){var r,n;return!(ew(e)===!1||(r=e.constructor,typeof r!="function")||(n=r.prototype,ew(n)===!1)||n.hasOwnProperty("isPrototypeOf")===!1)}});var as=Ve((eY,nw)=>{"use strict";var c9=rw();nw.exports={isType:u9,isUserType:c9,isFunction:td,isDecodeType:f9,isEncodeType:d9};function u9(t){return Lm(t)&&td(t.encode)&&td(t.decode)}function td(t){return typeof t=="function"}function Lm(t){return typeof t=="object"&&t!==null}function f9(t){return Lm(t)&&td(t.decode)}function d9(t){return Lm(t)&&td(t.encode)}});var Ki=Ve((tY,sw)=>{"use strict";var l9=Symbol("skip"),h9=Symbol("bytes");sw.exports={skip:l9,bytes:h9}});var $i=Ve((rY,ow)=>{"use strict";var iw=Ki();ow.exports=class Y0{constructor(){this[iw.bytes]=0,this.node=void 0,this.current=void 0}get bytes(){return this[iw.bytes]}static clone(e){let r=new Y0;return e instanceof Y0&&(r.node=e.node,r.current=e.current),r}static clean(e){e instanceof Y0&&(e.node=void 0,e.current=void 0)}}});var Rc=Ve((nY,dw)=>{"use strict";var{isType:p9,isUserType:x9,isDecodeType:m9}=as(),g9=ed(),Um=Ki(),aw=$i();dw.exports={decode:cw,decodeCommon:uw};function cw(t,e){let r=t;Buffer.isBuffer(t)&&(r=new g9,r.append(t));let n=new aw,s=uw(r,e,n);return cw.bytes=n.bytes,aw.clean(n),s}function uw(t,e,r){if(p9(e)){let n=e.decode.call(r,t);return r[Um.bytes]+=e.decode.bytes,n}return fw(t,e,r)}function fw(t,e,r){y9(e);let n=Object.create(null);r.node===void 0&&(r.node=n),r.current=n;let s=Object.keys(e);for(let i=0;i<s.length;i+=1){let o=s[i],a=e[o];if(!m9(a)){n[o]=fw(t,a,r),r.current=n;continue}let c=a.decode.call(r,t);r[Um.bytes]+=a.decode.bytes,a[Um.skip]!==!0&&(n[o]=c)}return n}function y9(t){if(!x9(t))throw new TypeError("Argument #2 should be a plain object.")}});var rd=Ve((sY,gw)=>{"use strict";var{isUserType:b9,isEncodeType:v9,isType:w9}=as(),hw=Ki(),lw=$i(),Dm=ed();gw.exports={encode:pw,encodeCommon:xw};function pw(t,e,r){let n=new lw;if(e instanceof Dm){let s=r;r=e,e=s}return r instanceof Dm||(r=new Dm),xw(t,r,e,n),pw.bytes=n.bytes,lw.clean(n),r}function xw(t,e,r,n){w9(r)?(r.encode.call(n,t,e),n[hw.bytes]+=r.encode.bytes):mw(t,e,r,n)}function mw(t,e,r,n){S9(r),n.node===void 0&&(n.node=t),n.current=t;let s=Object.keys(r);for(let i=0;i<s.length;i+=1){let o=s[i],a=r[o],c=t[o];if(!v9(a)){mw(c,e,a,n),n.current=t;continue}a.encode.call(n,c,e),n[hw.bytes]+=a.encode.bytes}}function S9(t){if(!b9(t))throw new TypeError("Argument `schema` should be a plain object.")}});var nd=Ve((iY,Ew)=>{"use strict";var{isUserType:E9,isType:bw}=as(),yw=$i(),vw=Ki();Ew.exports={encodingLength:A9,encodingLengthCommon:ww};function A9(t,e){let r=new yw;return ww(t,e,r),yw.clean(r),r.bytes}function ww(t,e,r){bw(e)?r[vw.bytes]+=e.encodingLength.call(r,t):Sw(t,e,r)}function Sw(t,e,r){if(!E9(e))throw new TypeError("Argument `schema` should be a plain object.");r.node===void 0&&(r.node=t),r.current=t;let n=Object.keys(e);for(let s=0;s<n.length;s+=1){let i=n[s],o=e[i],a=t[i];if(!bw(o)){Sw(a,o,r),r.current=t;continue}r[vw.bytes]+=o.encodingLength.call(r,a)}}});var Rw=Ve((oY,kw)=>{"use strict";var{decodeCommon:Bw}=Rc(),{encodeCommon:C9}=rd(),{encodingLengthCommon:Aw}=nd(),{isType:Cw,isUserType:I9,isFunction:T9}=as(),Wi=$i();kw.exports=_9;function _9(t,e,r="count"){if(!Cw(t)&&!I9(t))throw new TypeError("Argument #1 should be a valid type.");let n=r==="bytes",s=typeof e=="number",i=Cw(e),o=T9(e);if(!s&&!i&&!o)throw new TypeError("Unknown type of argument #1.");return{encode:a,decode:c,encodingLength:f};function a(l,p){Iw(l);let x=Wi.clone(this);a.bytes=0;let v=0;if(i?v=l.length:s?v=e:o&&(v=e(x),Tw(v)),n||_w(v,l.length),n){let S=Wi.clone(x);for(let I of l)Aw(I,t,S);i&&(v=S.bytes),_w(S.bytes,v),Wi.clean(S)}i&&(e.encode.call(x,v,p),a.bytes+=e.encode.bytes),l.forEach(S=>{C9(S,p,t,x)}),a.bytes+=x.bytes,Wi.clean(x)}function c(l){let p=0;c.bytes=0;let x=Wi.clone(this);s?p=e:i?(p=e.decode.call(x,l),c.bytes+=e.decode.bytes):o&&(p=e(x)),Tw(p);let v;return n?v=B9(t,p,l,x):v=k9(t,p,l,x),c.bytes+=x.bytes,Wi.clean(x),v}function f(l){Iw(l);let p=Wi.clone(this),x=0;if(s&&n)return e;i&&!n&&(x=e.encodingLength(l.length));for(let v of l)Aw(v,t,p);return Wi.clean(p),x+=p.bytes,i&&n&&(x+=e.encodingLength(x)),x}}function Iw(t){if(!Array.isArray(t))throw new TypeError("Argument #1 should be an Array.")}function Tw(t){if(typeof t!="number")throw new TypeError("Length of an array should be a number.")}function _w(t,e){if(t!==e)throw new Error(`Argument #1 required length ${t} instead of ${e}`)}function B9(t,e,r,n){let s=[],i=n.bytes,o=0;for(;o<e;)s.push(Bw(r,t,n)),o=n.bytes-i;if(o>e)throw new Error("Incorrect length of an array.");return s}function k9(t,e,r,n){let s=new Array(e);for(let i=0;i<e;i+=1)s[i]=Bw(r,t,n);return s}});var Lw=Ve((aY,Ow)=>{"use strict";var{isType:R9,isFunction:N9}=as(),P9=kc(),O9=ed();Ow.exports=L9;function L9(t){let e=typeof t=="number",r=R9(t),n=N9(t),s=t===null;if(!e&&!r&&!n&&!s)throw new TypeError("Unknown type of argument #1.");return{encode:i,decode:o,encodingLength:a};function i(c,f){Nw(c),i.bytes=0;let l=this;if(e&&Pw(t,c.length),r&&(t.encode.call(l,c.length,f),i.bytes+=t.encode.bytes),n){let p=t(l);Mm(p),Pw(p,c.length)}f.writeBuffer(Buffer.isBuffer(c)?c:c.buffer),i.bytes+=c.length,s&&(f.writeUInt8(0),i.bytes+=1)}function o(c){let f=0;o.bytes=0;let l=this;if(e)f=t;else if(r)f=t.decode.call(l,c),o.bytes+=t.decode.bytes,Mm(f);else if(n)f=t(l),Mm(f);else if(s&&(f=c.indexOf(0),f===-1))throw new P9(c.length+1,c.length);let p=c.readBuffer(f);return o.bytes+=f,s&&(o.bytes+=1,c.consume(1)),p}function a(c){Nw(c);let f=0;return e?t:(s?f=1:r&&(f=t.encodingLength(c.length)),f+c.length)}}function Nw(t){if(!Buffer.isBuffer(t)&&!(t instanceof O9))throw new TypeError("Argument 1 should be a Buffer or a BinaryStream.")}function Pw(t,e){if(t!==e)throw new Error(`Buffer required length ${t} instead of ${e}`)}function Mm(t){if(typeof t!="number")throw new TypeError("Length of a buffer should be a number.")}});var Dw=Ve((cY,Uw)=>{"use strict";var{isType:U9}=as();Uw.exports=D9;function D9(t){if(!U9(t))throw new TypeError("Argument #1 should be valid type.");function e(n){let s=this,i=t.decode.call(s,n);return e.bytes=t.decode.bytes,!!i}function r(n,s){let i=this;t.encode.call(i,n?1:0,s),r.bytes=t.encode.bytes}return{encode:r,decode:e,encodingLength:t.encodingLength}}});var Hw=Ve((uY,Mw)=>{"use strict";var{decodeCommon:M9}=Rc(),{encodeCommon:H9}=rd(),{encodingLengthCommon:j9}=nd(),{isType:q9,isFunction:Z0}=as(),V9=Ki(),Gi=$i();Mw.exports=z9;function z9(t,e=1){if(!q9(t))throw new TypeError("Invalid data type.");if(!Number.isInteger(e)&&!Z0(e))throw new TypeError("Argument #2 should be a valid integer or function.");return{[V9.skip]:!0,encodingLength:r,decode:n,encode:s};function r(i){let o=Gi.clone(this),a=Z0(e)?e(o):e;return j9(i,t,o),Gi.clean(o),o.bytes*a}function n(i){let o=Gi.clone(this);n.bytes=0;let a=Z0(e)?e(o):e;if(a===0){Gi.clean(o);return}for(let c=a;c>0;c-=1)M9(i,t,o);n.bytes=o.bytes,Gi.clean(o)}function s(i,o){s.bytes=0;let a=Gi.clone(this),c=Z0(e)?e(a):e;if(c===0){Gi.clean(a);return}for(let f=c;f>0;f-=1)H9(0,o,t,a);s.bytes=a.bytes,Gi.clean(a)}}});var Vw=Ve((fY,qw)=>{"use strict";var{isType:F9}=as(),K9=kc();qw.exports=$9;function $9(t,e="ascii"){if(!Buffer.isEncoding(e))throw new Error("Argument #2 should be an encoding name.");if(typeof t=="number")return{encode:X9(t,e),decode:Y9(t,e),encodingLength:()=>t};if(F9(t))return{encode:Z9(t,e),decode:J9(t,e),encodingLength:Q9(t,e)};if(t===null)return{encode:W9(e),decode:G9(e),encodingLength(r){return Buffer.byteLength(r,e)+1}};if(typeof t=="function")return{encode:eI(t,e),decode:tI(t,e),encodingLength(r){return Buffer.byteLength(r,e)}};throw new TypeError("Unknown type of argument #1.")}function W9(t){return function e(r,n){let s=Buffer.from(r.toString(),t);n.writeBuffer(s),n.writeInt8(0),e.bytes=s.length+1}}function G9(t){return function e(r){let n=r.indexOf(0);if(n===-1)throw new K9(r.length+1,r.length);let s=n+1,i=r.readBuffer(s);return e.bytes=s,i.toString(t,0,n)}}function X9(t,e){return function r(n,s){if(n=n.toString(),Buffer.byteLength(n,e)!==t)throw new Error(`Size of string should be ${t} in bytes.`);let i=Buffer.from(n,e);s.writeBuffer(i),r.bytes=i.length}}function Y9(t,e){return function r(n){let s=n.readBuffer(t);return r.bytes=t,s.toString(e)}}function Z9(t,e){return function r(n,s){n=n.toString();let i=this;t.encode.call(i,Buffer.byteLength(n,e),s),r.bytes=t.encode.bytes;let o=Buffer.from(n,e);s.writeBuffer(o),r.bytes+=o.length}}function J9(t,e){return function r(n){let s=t.decode.call(this,n);if(typeof s!="number")throw new TypeError("Size of a string should be a number.");let i=n.readBuffer(s);return r.bytes=t.decode.bytes+i.length,i.toString(e)}}function Q9(t,e){return function(n){let s=Buffer.byteLength(n,e);return t.encodingLength(s)+s}}function eI(t,e){return function r(n,s){r.bytes=0;let o=t(this),a=Buffer.from(n.toString(),e);jw(o),rI(o,a.length),s.writeBuffer(a),r.bytes+=a.length}}function tI(t,e){return function r(n){let s=t(this);jw(s);let i=n.readBuffer(s);return r.bytes=s,i.toString(e)}}function jw(t){if(typeof t!="number")throw new TypeError("Length of a buffer should be a number.")}function rI(t,e){if(t!==e)throw new Error(`Buffer required length ${t} instead of ${e}`)}});var Fw=Ve((dY,zw)=>{"use strict";var J0=Qf();zw.exports={doublebe:zr(8,"writeDoubleBE","readDoubleBE"),doublele:zr(8,"writeDoubleLE","readDoubleLE"),floatbe:zr(4,"writeFloatBE","readFloatBE"),floatle:zr(4,"writeFloatLE","readFloatLE"),int8:zr(1,"writeInt8","readInt8"),uint8:zr(1,"writeUInt8","readUInt8"),int16be:zr(2,"writeInt16BE","readInt16BE"),uint16be:zr(2,"writeUInt16BE","readUInt16BE"),int16le:zr(2,"writeInt16LE","readInt16LE"),uint16le:zr(2,"writeUInt16LE","readUInt16LE"),int32be:zr(4,"writeInt32BE","readInt32BE"),uint32be:zr(4,"writeUInt32BE","readUInt32BE"),int32le:zr(4,"writeInt32LE","readInt32LE"),uint32le:zr(4,"writeUInt32LE","readUInt32LE"),int24be:gn(3,"writeIntBE","readIntBE"),uint24be:gn(3,"writeUIntBE","readUIntBE"),int24le:gn(3,"writeIntLE","readIntLE"),uint24le:gn(3,"writeUIntLE","readUIntLE"),int40be:gn(5,"writeIntBE","readIntBE"),uint40be:gn(5,"writeUIntBE","readUIntBE"),int40le:gn(5,"writeIntLE","readIntLE"),uint40le:gn(5,"writeUIntLE","readUIntLE"),int48be:gn(6,"writeIntBE","readIntBE"),uint48be:gn(6,"writeUIntBE","readUIntBE"),int48le:gn(6,"writeIntLE","readIntLE"),uint48le:gn(6,"writeUIntLE","readUIntLE")};function zr(t,e,r){let n=J0(),s=J0();return n(`
76
+ function decode_${r}(rstream) {
77
+ decode_${r}.bytes = ${n.formats.d(t)};
78
+ return rstream.${r}()
79
+ }
80
+ `),s(`
81
+ function encode_${e}(value, wstream) {
82
+ wstream.${e}(value);
83
+ encode_${e}.bytes = ${n.formats.d(t)};
84
+ }
85
+ `),{encodingLength:()=>t,encode:s.toFunction(),decode:n.toFunction()}}function gn(t,e,r){let n=J0(),s=J0();return n(`
86
+ function decode_${r}(rstream) {
87
+ decode_${r}.bytes = ${n.formats.d(t)};
88
+ return rstream.${r}(${n.formats.d(t)})
89
+ }
90
+ `),s(`
91
+ function encode_${e}(value, wstream) {
92
+ wstream.${e}(value, ${n.formats.d(t)});
93
+ encode_${e}.bytes = ${n.formats.d(t)};
94
+ }
95
+ `),{encodingLength:()=>t,encode:s.toFunction(),decode:n.toFunction()}}});var $w=Ve((lY,Kw)=>{"use strict";var{isType:nI,isFunction:Hm,isUserType:sI}=as(),jm=Ki(),{decodeCommon:iI}=Rc(),{encodeCommon:oI}=rd(),{encodingLengthCommon:aI}=nd(),Xi=$i();Kw.exports=cI;function cI(t,e){if(!nI(e)&&!sI(e))throw new TypeError("Argument #2 should be a valid type.");let r={encode:n,decode:s,encodingLength:i,[jm.skip]:!1};return r;function n(o,a){let c=Xi.clone(this);n.bytes=0;let f=Hm(t)?!!t(c):!!t;if(r[jm.skip]=!f,!f){Xi.clean(c);return}oI(o,a,e,c),n.bytes=c.bytes,Xi.clean(c)}function s(o){let a=Xi.clone(this);s.bytes=0;let c=Hm(t)?!!t(a):!!t;if(r[jm.skip]=!c,!c){Xi.clean(a);return}let f=iI(o,e,a);return s.bytes=a.bytes,Xi.clean(a),f}function i(o){let a=Xi.clone(this);return(Hm(t)?t(a):t)&&aI(o,e,a),Xi.clean(a),a.bytes}}});var Xw=Ve((hY,Gw)=>{"use strict";var Q0=Ki(),{decodeCommon:uI}=Rc(),Ww=$i();Gw.exports=fI;function fI(...t){if(t.length===0)throw new TypeError("You should set at least one condition type.");let e={decode:r,encode:()=>{},[Q0.skip]:!0};return e;function r(n){r.bytes=0;let s=Ww.clone(this);for(let i of t){let o=uI(n,i,s);if(i[Q0.skip]!==!0)return r.bytes=s.bytes,Ww.clean(s),e[Q0.skip]=!1,o}e[Q0.skip]=!0}}});var Qw=Ve((pY,Jw)=>{"use strict";var Zw=Qf(),dI=kc(),sd=class{constructor(e){this.stream=e,this.index=0}append(e){this.stream.append(e)}commit(){this.stream.consume(this.index)}get(e=0){return this.stream.get(this.index+e)}get length(){return this.stream.length}slice(e,r){return this.stream.slice(e,r)}toString(e,r,n){return this.stream.toString(e,r,n)}readBuffer(e){qm(this.index+e,this.length);let r=this.stream.slice(this.index,this.index+e);return this.index+=e,r}indexOf(e,r=0){return this.stream.indexOf(e,this.index+r)-this.index}},Yw={readDoubleBE:8,readDoubleLE:8,readFloatBE:4,readFloatLE:4,readInt32BE:4,readInt32LE:4,readUInt32BE:4,readUInt32LE:4,readInt16BE:2,readInt16LE:2,readUInt16BE:2,readUInt16LE:2,readInt8:1,readUInt8:1};Object.keys(Yw).forEach(t=>{let e=Zw(),r=Yw[t];e(`
96
+ function transaction_${t}() {
97
+ assertSize(this.index + ${e.formats.d(r)}, this.length);
98
+ const value = this.stream.buffer.${t}(this.index);
99
+ this.index += ${e.formats.d(r)};
100
+ return value;
101
+ }
102
+ `),sd.prototype[t]=e.toFunction({assertSize:qm})});["readIntBE","readIntLE","readUIntBE","readUIntLE"].forEach(t=>{let e=Zw();e(`
103
+ function transaction_${t}(bytes) {
104
+ assertSize(this.index + bytes, this.length);
105
+ const value = this.stream.buffer.${t}(bytes, this.index);
106
+ this.index += bytes;
107
+ return value;
108
+ }
109
+ `),sd.prototype[t]=e.toFunction({assertSize:qm})});Jw.exports=sd;function qm(t,e){if(t>e)throw new dI(t,e)}});var Ut=Ve((xY,aS)=>{"use strict";var Vm=ed(),lI=Rw(),hI=Lw(),pI=Dw(),xI=Hw(),mI=Vw(),eS=Fw(),gI=$w(),yI=Xw(),{encode:nS}=rd(),{decode:sS}=Rc(),{encodingLength:bI}=nd(),vI=Qw(),iS=kc(),oS={array:lI,bool:pI,buffer:hI,reserved:xI,string:mI,when:gI,select:yI};for(let t of Object.keys(eS))oS[t]=eS[t];var eh=Symbol("schema");function tS(t){let e=new Vm({readableObjectMode:!1,writableObjectMode:!0,transform:wI});return e[eh]=t,e}function rS(t){let e=null,r=Buffer.isBuffer(t);r||(e=t);let n=new Vm({transform:SI,readableObjectMode:!0,writableObjectMode:!1});return n[eh]=e,r&&n.append(t),n}function wI(t,e,r){try{nS(t,this[eh],this);let n=this.slice();this.consume(n.length),r(null,n)}catch(n){r(n)}}function SI(t,e,r){this.append(t);try{for(;this.length>0;){let n=new vI(this),s=sS(n,this[eh]);n.commit(),this.push(s)}r()}catch(n){n instanceof iS?r():r(n)}}aS.exports={createEncodeStream:tS,createDecodeStream:rS,encode:nS,decode:sS,encodingLength:bI,createEncode:tS,createDecode:rS,types:oS,BinaryStream:Vm,NotEnoughDataError:iS}});var i6=Ve(to=>{"use strict";Object.defineProperty(to,"__esModule",{value:!0});to.LEB128=to.SignedLEB128=to.UnsignedLEB128=void 0;var Mc;(function(t){t[t.LOWER_7=127]="LOWER_7",t[t.UPPER_1=128]="UPPER_1"})(Mc||(Mc={}));var s6=t=>Number.isSafeInteger(t),Ea=class{static decode(e,r=0){let n=this.$scanForNullBytes(e,r),s=0,i=0;for(let o=0;o<=n-r;o++){let a=e[r+o]&Mc.LOWER_7;s|=a<<i,i+=7}return s}static encode(e){if(this.check(e),e<0)throw new Error(`An unsigned number must NOT be negative, ${e} is!`);let r=[],n=e;do{let s=n&Mc.LOWER_7;n>>=7,n&&(s=s|Mc.UPPER_1),r.push(s)}while(n);return Uint8Array.from(r)}static check(e){if(!s6(e))throw new Error(`${e} is not a safe integer!`)}static $scanForNullBytes(e,r=0){let n=r,s=0;do{if(n>=e.byteLength)throw new Error("This is not a LEB128-encoded Uint8Array, no ending found!");s=e.slice(n,n+1)[0],n++}while(s&Mc.UPPER_1);return n-1}static getLength(e,r=0){return this.$scanForNullBytes(e,r)-r}};to.UnsignedLEB128=Ea;var pd=class{static $ceil7mul(e){let r=e;for(;r%7;)r++;return r}static check(e){if(!s6(e))throw new Error(`${e} is not a safe integer!`)}static encode(e){if(this.check(e),e>=0)throw new Error(`A signed number must be negative, ${e} isn't!`);let r=Math.ceil(Math.log2(-e));return Ea.encode((1<<this.$ceil7mul(r))+e)}static decode(e,r=0){let n=Ea.decode(e,r);return-((1<<Math.ceil(Math.log2(n)))-n)}};to.SignedLEB128=pd;var xd=class{};to.LEB128=xd;xd.encode=t=>(t>=0?Ea:pd).encode(t);xd.decode=(t,e=0,r=!1)=>(r?pd:Ea).decode(t,e)});var a6=Ve((u1,o6)=>{"use strict";(function(t){"use strict";function e(A){return parseInt(A)===A}function r(A){if(!e(A.length))return!1;for(var T=0;T<A.length;T++)if(!e(A[T])||A[T]<0||A[T]>255)return!1;return!0}function n(A,T){if(A.buffer&&A.name==="Uint8Array")return T&&(A.slice?A=A.slice():A=Array.prototype.slice.call(A)),A;if(Array.isArray(A)){if(!r(A))throw new Error("Array contains invalid value: "+A);return new Uint8Array(A)}if(e(A.length)&&r(A))return new Uint8Array(A);throw new Error("unsupported array-like object")}function s(A){return new Uint8Array(A)}function i(A,T,H,C,N){(C!=null||N!=null)&&(A.slice?A=A.slice(C,N):A=Array.prototype.slice.call(A,C,N)),T.set(A,H)}var o=(function(){function A(H){var C=[],N=0;for(H=encodeURI(H);N<H.length;){var Z=H.charCodeAt(N++);Z===37?(C.push(parseInt(H.substr(N,2),16)),N+=2):C.push(Z)}return n(C)}function T(H){for(var C=[],N=0;N<H.length;){var Z=H[N];Z<128?(C.push(String.fromCharCode(Z)),N++):Z>191&&Z<224?(C.push(String.fromCharCode((Z&31)<<6|H[N+1]&63)),N+=2):(C.push(String.fromCharCode((Z&15)<<12|(H[N+1]&63)<<6|H[N+2]&63)),N+=3)}return C.join("")}return{toBytes:A,fromBytes:T}})(),a=(function(){function A(C){for(var N=[],Z=0;Z<C.length;Z+=2)N.push(parseInt(C.substr(Z,2),16));return N}var T="0123456789abcdef";function H(C){for(var N=[],Z=0;Z<C.length;Z++){var ne=C[Z];N.push(T[(ne&240)>>4]+T[ne&15])}return N.join("")}return{toBytes:A,fromBytes:H}})(),c={16:10,24:12,32:14},f=[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],l=[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],p=[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],x=[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],v=[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],S=[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],I=[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],L=[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],ee=[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],Pe=[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,1047239e3,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],ie=[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,679998e3,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],ve=[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],ze=[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],he=[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,1047239e3,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],Ne=[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,679998e3,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 we(A){for(var T=[],H=0;H<A.length;H+=4)T.push(A[H]<<24|A[H+1]<<16|A[H+2]<<8|A[H+3]);return T}var X=function(A){if(!(this instanceof X))throw Error("AES must be instanitated with `new`");Object.defineProperty(this,"key",{value:n(A,!0)}),this._prepare()};X.prototype._prepare=function(){var A=c[this.key.length];if(A==null)throw new Error("invalid key size (must be 16, 24 or 32 bytes)");this._Ke=[],this._Kd=[];for(var T=0;T<=A;T++)this._Ke.push([0,0,0,0]),this._Kd.push([0,0,0,0]);for(var H=(A+1)*4,C=this.key.length/4,N=we(this.key),Z,T=0;T<C;T++)Z=T>>2,this._Ke[Z][T%4]=N[T],this._Kd[A-Z][T%4]=N[T];for(var ne=0,Ye=C,at;Ye<H;){if(at=N[C-1],N[0]^=l[at>>16&255]<<24^l[at>>8&255]<<16^l[at&255]<<8^l[at>>24&255]^f[ne]<<24,ne+=1,C!=8)for(var T=1;T<C;T++)N[T]^=N[T-1];else{for(var T=1;T<C/2;T++)N[T]^=N[T-1];at=N[C/2-1],N[C/2]^=l[at&255]^l[at>>8&255]<<8^l[at>>16&255]<<16^l[at>>24&255]<<24;for(var T=C/2+1;T<C;T++)N[T]^=N[T-1]}for(var T=0,Et,lt;T<C&&Ye<H;)Et=Ye>>2,lt=Ye%4,this._Ke[Et][lt]=N[T],this._Kd[A-Et][lt]=N[T++],Ye++}for(var Et=1;Et<A;Et++)for(var lt=0;lt<4;lt++)at=this._Kd[Et][lt],this._Kd[Et][lt]=ve[at>>24&255]^ze[at>>16&255]^he[at>>8&255]^Ne[at&255]},X.prototype.encrypt=function(A){if(A.length!=16)throw new Error("invalid plaintext size (must be 16 bytes)");for(var T=this._Ke.length-1,H=[0,0,0,0],C=we(A),N=0;N<4;N++)C[N]^=this._Ke[0][N];for(var Z=1;Z<T;Z++){for(var N=0;N<4;N++)H[N]=x[C[N]>>24&255]^v[C[(N+1)%4]>>16&255]^S[C[(N+2)%4]>>8&255]^I[C[(N+3)%4]&255]^this._Ke[Z][N];C=H.slice()}for(var ne=s(16),Ye,N=0;N<4;N++)Ye=this._Ke[T][N],ne[4*N]=(l[C[N]>>24&255]^Ye>>24)&255,ne[4*N+1]=(l[C[(N+1)%4]>>16&255]^Ye>>16)&255,ne[4*N+2]=(l[C[(N+2)%4]>>8&255]^Ye>>8)&255,ne[4*N+3]=(l[C[(N+3)%4]&255]^Ye)&255;return ne},X.prototype.decrypt=function(A){if(A.length!=16)throw new Error("invalid ciphertext size (must be 16 bytes)");for(var T=this._Kd.length-1,H=[0,0,0,0],C=we(A),N=0;N<4;N++)C[N]^=this._Kd[0][N];for(var Z=1;Z<T;Z++){for(var N=0;N<4;N++)H[N]=L[C[N]>>24&255]^ee[C[(N+3)%4]>>16&255]^Pe[C[(N+2)%4]>>8&255]^ie[C[(N+1)%4]&255]^this._Kd[Z][N];C=H.slice()}for(var ne=s(16),Ye,N=0;N<4;N++)Ye=this._Kd[T][N],ne[4*N]=(p[C[N]>>24&255]^Ye>>24)&255,ne[4*N+1]=(p[C[(N+3)%4]>>16&255]^Ye>>16)&255,ne[4*N+2]=(p[C[(N+2)%4]>>8&255]^Ye>>8)&255,ne[4*N+3]=(p[C[(N+1)%4]&255]^Ye)&255;return ne};var ut=function(A){if(!(this instanceof ut))throw Error("AES must be instanitated with `new`");this.description="Electronic Code Block",this.name="ecb",this._aes=new X(A)};ut.prototype.encrypt=function(A){if(A=n(A),A.length%16!==0)throw new Error("invalid plaintext size (must be multiple of 16 bytes)");for(var T=s(A.length),H=s(16),C=0;C<A.length;C+=16)i(A,H,0,C,C+16),H=this._aes.encrypt(H),i(H,T,C);return T},ut.prototype.decrypt=function(A){if(A=n(A),A.length%16!==0)throw new Error("invalid ciphertext size (must be multiple of 16 bytes)");for(var T=s(A.length),H=s(16),C=0;C<A.length;C+=16)i(A,H,0,C,C+16),H=this._aes.decrypt(H),i(H,T,C);return T};var St=function(A,T){if(!(this instanceof St))throw Error("AES must be instanitated with `new`");if(this.description="Cipher Block Chaining",this.name="cbc",!T)T=s(16);else if(T.length!=16)throw new Error("invalid initialation vector size (must be 16 bytes)");this._lastCipherblock=n(T,!0),this._aes=new X(A)};St.prototype.encrypt=function(A){if(A=n(A),A.length%16!==0)throw new Error("invalid plaintext size (must be multiple of 16 bytes)");for(var T=s(A.length),H=s(16),C=0;C<A.length;C+=16){i(A,H,0,C,C+16);for(var N=0;N<16;N++)H[N]^=this._lastCipherblock[N];this._lastCipherblock=this._aes.encrypt(H),i(this._lastCipherblock,T,C)}return T},St.prototype.decrypt=function(A){if(A=n(A),A.length%16!==0)throw new Error("invalid ciphertext size (must be multiple of 16 bytes)");for(var T=s(A.length),H=s(16),C=0;C<A.length;C+=16){i(A,H,0,C,C+16),H=this._aes.decrypt(H);for(var N=0;N<16;N++)T[C+N]=H[N]^this._lastCipherblock[N];i(A,this._lastCipherblock,0,C,C+16)}return T};var He=function(A,T,H){if(!(this instanceof He))throw Error("AES must be instanitated with `new`");if(this.description="Cipher Feedback",this.name="cfb",!T)T=s(16);else if(T.length!=16)throw new Error("invalid initialation vector size (must be 16 size)");H||(H=1),this.segmentSize=H,this._shiftRegister=n(T,!0),this._aes=new X(A)};He.prototype.encrypt=function(A){if(A.length%this.segmentSize!=0)throw new Error("invalid plaintext size (must be segmentSize bytes)");for(var T=n(A,!0),H,C=0;C<T.length;C+=this.segmentSize){H=this._aes.encrypt(this._shiftRegister);for(var N=0;N<this.segmentSize;N++)T[C+N]^=H[N];i(this._shiftRegister,this._shiftRegister,0,this.segmentSize),i(T,this._shiftRegister,16-this.segmentSize,C,C+this.segmentSize)}return T},He.prototype.decrypt=function(A){if(A.length%this.segmentSize!=0)throw new Error("invalid ciphertext size (must be segmentSize bytes)");for(var T=n(A,!0),H,C=0;C<T.length;C+=this.segmentSize){H=this._aes.encrypt(this._shiftRegister);for(var N=0;N<this.segmentSize;N++)T[C+N]^=H[N];i(this._shiftRegister,this._shiftRegister,0,this.segmentSize),i(A,this._shiftRegister,16-this.segmentSize,C,C+this.segmentSize)}return T};var q=function(A,T){if(!(this instanceof q))throw Error("AES must be instanitated with `new`");if(this.description="Output Feedback",this.name="ofb",!T)T=s(16);else if(T.length!=16)throw new Error("invalid initialation vector size (must be 16 bytes)");this._lastPrecipher=n(T,!0),this._lastPrecipherIndex=16,this._aes=new X(A)};q.prototype.encrypt=function(A){for(var T=n(A,!0),H=0;H<T.length;H++)this._lastPrecipherIndex===16&&(this._lastPrecipher=this._aes.encrypt(this._lastPrecipher),this._lastPrecipherIndex=0),T[H]^=this._lastPrecipher[this._lastPrecipherIndex++];return T},q.prototype.decrypt=q.prototype.encrypt;var V=function(A){if(!(this instanceof V))throw Error("Counter must be instanitated with `new`");A!==0&&!A&&(A=1),typeof A=="number"?(this._counter=s(16),this.setValue(A)):this.setBytes(A)};V.prototype.setValue=function(A){if(typeof A!="number"||parseInt(A)!=A)throw new Error("invalid counter value (must be an integer)");if(A>Number.MAX_SAFE_INTEGER)throw new Error("integer value out of safe range");for(var T=15;T>=0;--T)this._counter[T]=A%256,A=parseInt(A/256)},V.prototype.setBytes=function(A){if(A=n(A,!0),A.length!=16)throw new Error("invalid counter bytes size (must be 16 bytes)");this._counter=A},V.prototype.increment=function(){for(var A=15;A>=0;A--)if(this._counter[A]===255)this._counter[A]=0;else{this._counter[A]++;break}};var M=function(A,T){if(!(this instanceof M))throw Error("AES must be instanitated with `new`");this.description="Counter",this.name="ctr",T instanceof V||(T=new V(T)),this._counter=T,this._remainingCounter=null,this._remainingCounterIndex=16,this._aes=new X(A)};M.prototype.encrypt=function(A){for(var T=n(A,!0),H=0;H<T.length;H++)this._remainingCounterIndex===16&&(this._remainingCounter=this._aes.encrypt(this._counter._counter),this._remainingCounterIndex=0,this._counter.increment()),T[H]^=this._remainingCounter[this._remainingCounterIndex++];return T},M.prototype.decrypt=M.prototype.encrypt;function oe(A){A=n(A,!0);var T=16-A.length%16,H=s(A.length+T);i(A,H);for(var C=A.length;C<H.length;C++)H[C]=T;return H}function ge(A){if(A=n(A,!0),A.length<16)throw new Error("PKCS#7 invalid length");var T=A[A.length-1];if(T>16)throw new Error("PKCS#7 padding byte out of range");for(var H=A.length-T,C=0;C<T;C++)if(A[H+C]!==T)throw new Error("PKCS#7 invalid padding byte");var N=s(H);return i(A,N,0,0,H),N}var Te={AES:X,Counter:V,ModeOfOperation:{ecb:ut,cbc:St,cfb:He,ofb:q,ctr:M},utils:{hex:a,utf8:o},padding:{pkcs7:{pad:oe,strip:ge}},_arrayTest:{coerceArray:n,createArray:s,copyArray:i}};typeof u1<"u"?o6.exports=Te:typeof define=="function"&&define.amd?define([],function(){return Te}):(t.aesjs&&(Te._aesjs=t.aesjs),t.aesjs=Te)})(u1)});var h1=Ve(h6=>{"use strict";var Ue=h6,{Buffer:vh}=Gt("buffer"),iT=Gt("os");Ue.toBuffer=function(t,e,r){r=~~r;let n;if(this.isV4Format(t))n=e||vh.alloc(r+4),t.split(/\./g).map(s=>{n[r++]=parseInt(s,10)&255});else if(this.isV6Format(t)){let s=t.split(":",8),i;for(i=0;i<s.length;i++){let o=this.isV4Format(s[i]),a;o&&(a=this.toBuffer(s[i]),s[i]=a.slice(0,2).toString("hex")),a&&++i<8&&s.splice(i,0,a.slice(2,4).toString("hex"))}if(s[0]==="")for(;s.length<8;)s.unshift("0");else if(s[s.length-1]==="")for(;s.length<8;)s.push("0");else if(s.length<8){for(i=0;i<s.length&&s[i]!=="";i++);let o=[i,1];for(i=9-s.length;i>0;i--)o.push("0");s.splice(...o)}for(n=e||vh.alloc(r+16),i=0;i<s.length;i++){let o=parseInt(s[i],16);n[r++]=o>>8&255,n[r++]=o&255}}if(!n)throw Error(`Invalid ip address: ${t}`);return n};Ue.toString=function(t,e,r){e=~~e,r=r||t.length-e;let n=[];if(r===4){for(let s=0;s<r;s++)n.push(t[e+s]);n=n.join(".")}else if(r===16){for(let s=0;s<r;s+=2)n.push(t.readUInt16BE(e+s).toString(16));n=n.join(":"),n=n.replace(/(^|:)0(:0)*:0(:|$)/,"$1::$3"),n=n.replace(/:{3,4}/,"::")}return n};var oT=/^(\d{1,3}\.){3,3}\d{1,3}$/,aT=/^(::)?(((\d{1,3}\.){3}(\d{1,3}){1})?([0-9a-f]){0,4}:{0,2}){1,8}(::)?$/i;Ue.isV4Format=function(t){return oT.test(t)};Ue.isV6Format=function(t){return aT.test(t)};function md(t){return t===4?"ipv4":t===6?"ipv6":t?t.toLowerCase():"ipv4"}Ue.fromPrefixLen=function(t,e){t>32?e="ipv6":e=md(e);let r=4;e==="ipv6"&&(r=16);let n=vh.alloc(r);for(let s=0,i=n.length;s<i;++s){let o=8;t<8&&(o=t),t-=o,n[s]=~(255>>o)&255}return Ue.toString(n)};Ue.mask=function(t,e){t=Ue.toBuffer(t),e=Ue.toBuffer(e);let r=vh.alloc(Math.max(t.length,e.length)),n;if(t.length===e.length)for(n=0;n<t.length;n++)r[n]=t[n]&e[n];else if(e.length===4)for(n=0;n<e.length;n++)r[n]=t[t.length-4+n]&e[n];else{for(n=0;n<r.length-6;n++)r[n]=0;for(r[10]=255,r[11]=255,n=0;n<t.length;n++)r[n+12]=t[n]&e[n+12];n+=12}for(;n<r.length;n++)r[n]=0;return Ue.toString(r)};Ue.cidr=function(t){let e=t.split("/"),r=e[0];if(e.length!==2)throw new Error(`invalid CIDR subnet: ${r}`);let n=Ue.fromPrefixLen(parseInt(e[1],10));return Ue.mask(r,n)};Ue.subnet=function(t,e){let r=Ue.toLong(Ue.mask(t,e)),n=Ue.toBuffer(e),s=0;for(let o=0;o<n.length;o++)if(n[o]===255)s+=8;else{let a=n[o]&255;for(;a;)a=a<<1&255,s++}let i=2**(32-s);return{networkAddress:Ue.fromLong(r),firstAddress:i<=2?Ue.fromLong(r):Ue.fromLong(r+1),lastAddress:i<=2?Ue.fromLong(r+i-1):Ue.fromLong(r+i-2),broadcastAddress:Ue.fromLong(r+i-1),subnetMask:e,subnetMaskLength:s,numHosts:i<=2?i:i-2,length:i,contains(o){return r===Ue.toLong(Ue.mask(o,e))}}};Ue.cidrSubnet=function(t){let e=t.split("/"),r=e[0];if(e.length!==2)throw new Error(`invalid CIDR subnet: ${r}`);let n=Ue.fromPrefixLen(parseInt(e[1],10));return Ue.subnet(r,n)};Ue.not=function(t){let e=Ue.toBuffer(t);for(let r=0;r<e.length;r++)e[r]=255^e[r];return Ue.toString(e)};Ue.or=function(t,e){if(t=Ue.toBuffer(t),e=Ue.toBuffer(e),t.length===e.length){for(let i=0;i<t.length;++i)t[i]|=e[i];return Ue.toString(t)}let r=t,n=e;e.length>t.length&&(r=e,n=t);let s=r.length-n.length;for(let i=s;i<r.length;++i)r[i]|=n[i-s];return Ue.toString(r)};Ue.isEqual=function(t,e){if(t=Ue.toBuffer(t),e=Ue.toBuffer(e),t.length===e.length){for(let n=0;n<t.length;n++)if(t[n]!==e[n])return!1;return!0}if(e.length===4){let n=e;e=t,t=n}for(let n=0;n<10;n++)if(e[n]!==0)return!1;let r=e.readUInt16BE(10);if(r!==0&&r!==65535)return!1;for(let n=0;n<4;n++)if(t[n]!==e[n+12])return!1;return!0};Ue.isPrivate=function(t){if(Ue.isLoopback(t))return!0;if(!Ue.isV6Format(t)){let e=Ue.normalizeToLong(t);if(e<0)throw new Error("invalid ipv4 address");t=Ue.fromLong(e)}return/^(::f{4}:)?10\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/i.test(t)||/^(::f{4}:)?192\.168\.([0-9]{1,3})\.([0-9]{1,3})$/i.test(t)||/^(::f{4}:)?172\.(1[6-9]|2\d|30|31)\.([0-9]{1,3})\.([0-9]{1,3})$/i.test(t)||/^(::f{4}:)?169\.254\.([0-9]{1,3})\.([0-9]{1,3})$/i.test(t)||/^f[cd][0-9a-f]{2}:/i.test(t)||/^fe80:/i.test(t)||/^::1$/.test(t)||/^::$/.test(t)};Ue.isPublic=function(t){return!Ue.isPrivate(t)};Ue.isLoopback=function(t){return!/\./.test(t)&&!/:/.test(t)&&(t=Ue.fromLong(Number(t))),/^(::f{4}:)?127\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})/.test(t)||/^0177\./.test(t)||/^0x7f\./i.test(t)||/^fe80::1$/i.test(t)||/^::1$/.test(t)||/^::$/.test(t)};Ue.loopback=function(t){if(t=md(t),t!=="ipv4"&&t!=="ipv6")throw new Error("family must be ipv4 or ipv6");return t==="ipv4"?"127.0.0.1":"fe80::1"};Ue.address=function(t,e){let r=iT.networkInterfaces();if(e=md(e),t&&t!=="private"&&t!=="public"){let s=r[t].filter(i=>md(i.family)===e);return s.length===0?void 0:s[0].address}let n=Object.keys(r).map(s=>{let i=r[s].filter(o=>(o.family=md(o.family),o.family!==e||Ue.isLoopback(o.address)?!1:t?t==="public"?Ue.isPrivate(o.address):Ue.isPublic(o.address):!0));return i.length?i[0].address:void 0}).filter(Boolean);return n.length?n[0]:Ue.loopback(e)};Ue.toLong=function(t){let e=0;return t.split(".").forEach(r=>{e<<=8,e+=parseInt(r)}),e>>>0};Ue.fromLong=function(t){return`${t>>>24}.${t>>16&255}.${t>>8&255}.${t&255}`};Ue.normalizeToLong=function(t){let e=t.split(".").map(s=>s.startsWith("0x")||s.startsWith("0X")?parseInt(s,16):s.startsWith("0")&&s!=="0"&&/^[0-7]+$/.test(s)?parseInt(s,8):/^[1-9]\d*$/.test(s)||s==="0"?parseInt(s,10):NaN);if(e.some(isNaN))return-1;let r=0;switch(e.length){case 1:r=e[0];break;case 2:if(e[0]>255||e[1]>16777215)return-1;r=e[0]<<24|e[1]&16777215;break;case 3:if(e[0]>255||e[1]>255||e[2]>65535)return-1;r=e[0]<<24|e[1]<<16|e[2]&65535;break;case 4:if(e.some(s=>s>255))return-1;r=e[0]<<24|e[1]<<16|e[2]<<8|e[3];break;default:return-1}return r>>>0}});var x6=Ve((rZ,p6)=>{"use strict";p6.exports=function t(e,r){if(e===r)return!0;if(e&&r&&typeof e=="object"&&typeof r=="object"){if(e.constructor!==r.constructor)return!1;var n,s,i;if(Array.isArray(e)){if(n=e.length,n!=r.length)return!1;for(s=n;s--!==0;)if(!t(e[s],r[s]))return!1;return!0}if(e.constructor===RegExp)return e.source===r.source&&e.flags===r.flags;if(e.valueOf!==Object.prototype.valueOf)return e.valueOf()===r.valueOf();if(e.toString!==Object.prototype.toString)return e.toString()===r.toString();if(i=Object.keys(e),n=i.length,n!==Object.keys(r).length)return!1;for(s=n;s--!==0;)if(!Object.prototype.hasOwnProperty.call(r,i[s]))return!1;for(s=n;s--!==0;){var o=i[s];if(!t(e[o],r[o]))return!1}return!0}return e!==e&&r!==r}});var m6=Ve(p1=>{"use strict";p1.toString=function(t){switch(t){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_"+t};p1.toType=function(t){switch(t.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}return t.toUpperCase().startsWith("UNKNOWN_")?parseInt(t.slice(8)):0}});var g6=Ve(x1=>{"use strict";x1.toString=function(t){switch(t){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_"+t};x1.toRcode=function(t){switch(t.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 y6=Ve(m1=>{"use strict";m1.toString=function(t){switch(t){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_"+t};m1.toOpcode=function(t){switch(t.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 b6=Ve(g1=>{"use strict";g1.toString=function(t){switch(t){case 1:return"IN";case 2:return"CS";case 3:return"CH";case 4:return"HS";case 255:return"ANY"}return"UNKNOWN_"+t};g1.toClass=function(t){switch(t.toUpperCase()){case"IN":return 1;case"CS":return 2;case"CH":return 3;case"HS":return 4;case"ANY":return 255}return 0}});var v6=Ve(y1=>{"use strict";y1.toString=function(t){switch(t){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"}return t<0?null:`OPTION_${t}`};y1.toCode=function(t){if(typeof t=="number")return t;if(!t)return-1;switch(t.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 e=t.match(/_(\d+)$/);return e?parseInt(e[1],10):-1}});var E6=Ve((S6,b1)=>{"use strict";var w6=(function(t){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.decode=p,t.encode=l,t.familyOf=f,t.name=void 0,t.sizeOf=c,t.v6=t.v4=void 0;let e=/^(\d{1,3}\.){3,3}\d{1,3}$/,r=4,n=/^(::)?(((\d{1,3}\.){3}(\d{1,3}){1})?([0-9a-f]){0,4}:{0,2}){1,8}(::)?$/i,s=16,i={name:"v4",size:r,isFormat:x=>e.test(x),encode(x,v,S){S=~~S,v=v||new Uint8Array(S+r);let I=x.length,L=0;for(let ee=0;ee<I;){let Pe=x.charCodeAt(ee++);Pe===46?(v[S++]=L,L=0):L=L*10+(Pe-48)}return v[S]=L,v},decode(x,v){return v=~~v,`${x[v++]}.${x[v++]}.${x[v++]}.${x[v]}`}};t.v4=i;let o={name:"v6",size:s,isFormat:x=>x.length>0&&n.test(x),encode(x,v,S){S=~~S;let I=S+s,L=-1,ee=0,Pe=0,ie=!0,ve=!1;v=v||new Uint8Array(S+s);for(let ze=0;ze<x.length;ze++){let he=x.charCodeAt(ze);he===58?(ie?L!==-1?(S<I&&(v[S]=0),S<I-1&&(v[S+1]=0),S+=2):S<I&&(L=S):(ve===!0?(S<I&&(v[S]=Pe),S++):(S<I&&(v[S]=ee>>8),S<I-1&&(v[S+1]=ee&255),S+=2),ee=0,Pe=0),ie=!0,ve=!1):he===46?(S<I&&(v[S]=Pe),S++,Pe=0,ee=0,ie=!1,ve=!0):(ie=!1,he>=97?he-=87:he>=65?he-=55:(he-=48,Pe=Pe*10+he),ee=(ee<<4)+he)}if(ie===!1)ve===!0?(S<I&&(v[S]=Pe),S++):(S<I&&(v[S]=ee>>8),S<I-1&&(v[S+1]=ee&255),S+=2);else if(L===0)S<I&&(v[S]=0),S<I-1&&(v[S+1]=0),S+=2;else if(L!==-1){S+=2;for(let ze=Math.min(S-1,I-1);ze>=L+2;ze--)v[ze]=v[ze-2];v[L]=0,v[L+1]=0,L=S}if(L!==S&&L!==-1)for(S>I-2&&(S=I-2);I>L;)v[--I]=S<I&&S>L?v[--S]:0;else for(;S<I;)v[S++]=0;return v},decode(x,v){v=~~v;let S="";for(let I=0;I<s;I+=2)I!==0&&(S+=":"),S+=(x[v+I]<<8|x[v+I+1]).toString(16);return S.replace(/(^|:)0(:0)*:0(:|$)/,"$1::$3").replace(/:{3,4}/,"::")}};t.v6=o;let a="ip";t.name=a;function c(x){if(i.isFormat(x))return i.size;if(o.isFormat(x))return o.size;throw Error(`Invalid ip address: ${x}`)}function f(x){return c(x)===i.size?1:2}function l(x,v,S){S=~~S;let I=c(x);return typeof v=="function"&&(v=v(S+I)),I===i.size?i.encode(x,v,S):o.encode(x,v,S)}function p(x,v,S){if(v=~~v,S=S||x.length-v,S===i.size)return i.decode(x,v,S);if(S===o.size)return o.decode(x,v,S);throw Error(`Invalid buffer size needs to be ${i.size} for v4 or ${o.size} for v6.`)}return"default"in t?t.default:t})({});typeof define=="function"&&define.amd?define([],function(){return w6}):typeof b1=="object"&&typeof S6=="object"&&(b1.exports=w6)});var I6=Ve(De=>{"use strict";var Me=Gt("buffer").Buffer,si=m6(),cT=g6(),uT=y6(),Sh=b6(),v1=v6(),Aa=E6(),fT=0,A6=32768,w1=32768,dT=~w1,C6=32768,lT=~C6,de=De.name={};de.encode=function(t,e,r,{mail:n=!1}={}){e||(e=Me.alloc(de.encodingLength(t))),r||(r=0);let s=r,i=t.replace(/^\.|\.$/gm,"");if(i.length){let o=[];if(n){let a="";i.split(".").forEach(c=>{c.endsWith("\\")?a+=(a.length?".":"")+c.slice(0,-1):o.length===0&&a.length?o.push(a+"."+c):o.push(c)})}else o=i.split(".");for(let a=0;a<o.length;a++){let c=e.write(o[a],r+1);e[r]=c,r+=c+1}}return e[r++]=0,de.encode.bytes=r-s,e};de.encode.bytes=0;de.decode=function(t,e,{mail:r=!1}={}){e||(e=0);let n=[],s=e,i=0,o=0,a=!1;for(;;){if(e>=t.length)throw new Error("Cannot decode name (buffer overflow)");let c=t[e++];if(o+=a?0:1,c===0)break;if((c&192)===0){if(e+c>t.length)throw new Error("Cannot decode name (buffer overflow)");if(i+=c+1,i>254)throw new Error("Cannot decode name (name too long)");let f=t.toString("utf-8",e,e+c);r&&(f=f.replace(/\./g,"\\.")),n.push(f),e+=c,o+=a?0:c}else if((c&192)===192){if(e+1>t.length)throw new Error("Cannot decode name (buffer overflow)");let f=t.readUInt16BE(e-1)-49152;if(f>=s)throw new Error("Cannot decode name (bad pointer)");e=f,s=f,o+=a?0:1,a=!0}else throw new Error("Cannot decode name (bad label)")}return de.decode.bytes=o,n.length===0?".":n.join(".")};de.decode.bytes=0;de.encodingLength=function(t){return t==="."||t===".."?1:Me.byteLength(t.replace(/^\.|\.$/gm,""))+2};var dt={};dt.encode=function(t,e,r){e||(e=Me.alloc(dt.encodingLength(t))),r||(r=0);let n=e.write(t,r+1);return e[r]=n,dt.encode.bytes=n+1,e};dt.encode.bytes=0;dt.decode=function(t,e){e||(e=0);let r=t[e],n=t.toString("utf-8",e+1,e+1+r);return dt.decode.bytes=r+1,n};dt.decode.bytes=0;dt.encodingLength=function(t){return Me.byteLength(t)+1};var Pn={};Pn.encode=function(t,e,r){e||(e=Pn.encodingLength(t)),r||(r=0);let n=(t.flags||0)&32767,s=t.type==="response"?A6:fT;return e.writeUInt16BE(t.id||0,r),e.writeUInt16BE(n|s,r+2),e.writeUInt16BE(t.questions.length,r+4),e.writeUInt16BE(t.answers.length,r+6),e.writeUInt16BE(t.authorities.length,r+8),e.writeUInt16BE(t.additionals.length,r+10),e};Pn.encode.bytes=12;Pn.decode=function(t,e){if(e||(e=0),t.length<12)throw new Error("Header must be 12 bytes");let r=t.readUInt16BE(e+2);return{id:t.readUInt16BE(e),type:r&A6?"response":"query",flags:r&32767,flag_qr:(r>>15&1)===1,opcode:uT.toString(r>>11&15),flag_aa:(r>>10&1)===1,flag_tc:(r>>9&1)===1,flag_rd:(r>>8&1)===1,flag_ra:(r>>7&1)===1,flag_z:(r>>6&1)===1,flag_ad:(r>>5&1)===1,flag_cd:(r>>4&1)===1,rcode:cT.toString(r&15),questions:new Array(t.readUInt16BE(e+4)),answers:new Array(t.readUInt16BE(e+6)),authorities:new Array(t.readUInt16BE(e+8)),additionals:new Array(t.readUInt16BE(e+10))}};Pn.decode.bytes=12;Pn.encodingLength=function(){return 12};var Xs=De.unknown={};Xs.encode=function(t,e,r){return e||(e=Me.alloc(Xs.encodingLength(t))),r||(r=0),e.writeUInt16BE(t.length,r),t.copy(e,r+2),Xs.encode.bytes=t.length+2,e};Xs.encode.bytes=0;Xs.decode=function(t,e){e||(e=0);let r=t.readUInt16BE(e),n=t.slice(e+2,e+2+r);return Xs.decode.bytes=r+2,n};Xs.decode.bytes=0;Xs.encodingLength=function(t){return t.length+2};var Ys=De.ns={};Ys.encode=function(t,e,r){return e||(e=Me.alloc(Ys.encodingLength(t))),r||(r=0),de.encode(t,e,r+2),e.writeUInt16BE(de.encode.bytes,r),Ys.encode.bytes=de.encode.bytes+2,e};Ys.encode.bytes=0;Ys.decode=function(t,e){e||(e=0);let r=t.readUInt16BE(e),n=de.decode(t,e+2);return Ys.decode.bytes=r+2,n};Ys.decode.bytes=0;Ys.encodingLength=function(t){return de.encodingLength(t)+2};var Zs=De.soa={};Zs.encode=function(t,e,r){e||(e=Me.alloc(Zs.encodingLength(t))),r||(r=0);let n=r;return r+=2,de.encode(t.mname,e,r),r+=de.encode.bytes,de.encode(t.rname,e,r,{mail:!0}),r+=de.encode.bytes,e.writeUInt32BE(t.serial||0,r),r+=4,e.writeUInt32BE(t.refresh||0,r),r+=4,e.writeUInt32BE(t.retry||0,r),r+=4,e.writeUInt32BE(t.expire||0,r),r+=4,e.writeUInt32BE(t.minimum||0,r),r+=4,e.writeUInt16BE(r-n-2,n),Zs.encode.bytes=r-n,e};Zs.encode.bytes=0;Zs.decode=function(t,e){e||(e=0);let r=e,n={};return e+=2,n.mname=de.decode(t,e),e+=de.decode.bytes,n.rname=de.decode(t,e,{mail:!0}),e+=de.decode.bytes,n.serial=t.readUInt32BE(e),e+=4,n.refresh=t.readUInt32BE(e),e+=4,n.retry=t.readUInt32BE(e),e+=4,n.expire=t.readUInt32BE(e),e+=4,n.minimum=t.readUInt32BE(e),e+=4,Zs.decode.bytes=e-r,n};Zs.decode.bytes=0;Zs.encodingLength=function(t){return 22+de.encodingLength(t.mname)+de.encodingLength(t.rname)};var Js=De.txt={};Js.encode=function(t,e,r){Array.isArray(t)||(t=[t]);for(let s=0;s<t.length;s++)if(typeof t[s]=="string"&&(t[s]=Me.from(t[s])),!Me.isBuffer(t[s]))throw new Error("Must be a Buffer");e||(e=Me.alloc(Js.encodingLength(t))),r||(r=0);let n=r;return r+=2,t.forEach(function(s){e[r++]=s.length,s.copy(e,r,0,s.length),r+=s.length}),e.writeUInt16BE(r-n-2,n),Js.encode.bytes=r-n,e};Js.encode.bytes=0;Js.decode=function(t,e){e||(e=0);let r=e,n=t.readUInt16BE(e);e+=2;let s=[];for(;n>0;){let i=t[e++];if(--n,n<i)throw new Error("Buffer overflow");s.push(t.slice(e,e+i)),e+=i,n-=i}return Js.decode.bytes=e-r,s};Js.decode.bytes=0;Js.encodingLength=function(t){Array.isArray(t)||(t=[t]);let e=2;return t.forEach(function(r){typeof r=="string"?e+=Me.byteLength(r)+1:e+=r.length+1}),e};var Qs=De.null={};Qs.encode=function(t,e,r){e||(e=Me.alloc(Qs.encodingLength(t))),r||(r=0),typeof t=="string"&&(t=Me.from(t)),t||(t=Me.alloc(0));let n=r;r+=2;let s=t.length;return t.copy(e,r,0,s),r+=s,e.writeUInt16BE(r-n-2,n),Qs.encode.bytes=r-n,e};Qs.encode.bytes=0;Qs.decode=function(t,e){e||(e=0);let r=e,n=t.readUInt16BE(e);e+=2;let s=t.slice(e,e+n);return e+=n,Qs.decode.bytes=e-r,s};Qs.decode.bytes=0;Qs.encodingLength=function(t){return t?(Me.isBuffer(t)?t.length:Me.byteLength(t))+2:2};var ei=De.hinfo={};ei.encode=function(t,e,r){e||(e=Me.alloc(ei.encodingLength(t))),r||(r=0);let n=r;return r+=2,dt.encode(t.cpu,e,r),r+=dt.encode.bytes,dt.encode(t.os,e,r),r+=dt.encode.bytes,e.writeUInt16BE(r-n-2,n),ei.encode.bytes=r-n,e};ei.encode.bytes=0;ei.decode=function(t,e){e||(e=0);let r=e,n={};return e+=2,n.cpu=dt.decode(t,e),e+=dt.decode.bytes,n.os=dt.decode(t,e),e+=dt.decode.bytes,ei.decode.bytes=e-r,n};ei.decode.bytes=0;ei.encodingLength=function(t){return dt.encodingLength(t.cpu)+dt.encodingLength(t.os)+2};var Rn=De.ptr={},hT=De.cname=Rn,pT=De.dname=Rn;Rn.encode=function(t,e,r){return e||(e=Me.alloc(Rn.encodingLength(t))),r||(r=0),de.encode(t,e,r+2),e.writeUInt16BE(de.encode.bytes,r),Rn.encode.bytes=de.encode.bytes+2,e};Rn.encode.bytes=0;Rn.decode=function(t,e){e||(e=0);let r=de.decode(t,e+2);return Rn.decode.bytes=de.decode.bytes+2,r};Rn.decode.bytes=0;Rn.encodingLength=function(t){return de.encodingLength(t)+2};var ti=De.srv={};ti.encode=function(t,e,r){e||(e=Me.alloc(ti.encodingLength(t))),r||(r=0),e.writeUInt16BE(t.priority||0,r+2),e.writeUInt16BE(t.weight||0,r+4),e.writeUInt16BE(t.port||0,r+6),de.encode(t.target,e,r+8);let n=de.encode.bytes+6;return e.writeUInt16BE(n,r),ti.encode.bytes=n+2,e};ti.encode.bytes=0;ti.decode=function(t,e){e||(e=0);let r=t.readUInt16BE(e),n={};return n.priority=t.readUInt16BE(e+2),n.weight=t.readUInt16BE(e+4),n.port=t.readUInt16BE(e+6),n.target=de.decode(t,e+8),ti.decode.bytes=r+2,n};ti.decode.bytes=0;ti.encodingLength=function(t){return 8+de.encodingLength(t.target)};var Qr=De.caa={};Qr.ISSUER_CRITICAL=128;Qr.encode=function(t,e,r){let n=Qr.encodingLength(t);return e||(e=Me.alloc(Qr.encodingLength(t))),r||(r=0),t.issuerCritical&&(t.flags=Qr.ISSUER_CRITICAL),e.writeUInt16BE(n-2,r),r+=2,e.writeUInt8(t.flags||0,r),r+=1,dt.encode(t.tag,e,r),r+=dt.encode.bytes,e.write(t.value,r),r+=Me.byteLength(t.value),Qr.encode.bytes=n,e};Qr.encode.bytes=0;Qr.decode=function(t,e){e||(e=0);let r=t.readUInt16BE(e);e+=2;let n=e,s={};return s.flags=t.readUInt8(e),e+=1,s.tag=dt.decode(t,e),e+=dt.decode.bytes,s.value=t.toString("utf-8",e,n+r),s.issuerCritical=!!(s.flags&Qr.ISSUER_CRITICAL),Qr.decode.bytes=r+2,s};Qr.decode.bytes=0;Qr.encodingLength=function(t){return dt.encodingLength(t.tag)+dt.encodingLength(t.value)+2};var ro=De.mx={};ro.encode=function(t,e,r){e||(e=Me.alloc(ro.encodingLength(t))),r||(r=0);let n=r;return r+=2,e.writeUInt16BE(t.preference||0,r),r+=2,de.encode(t.exchange,e,r),r+=de.encode.bytes,e.writeUInt16BE(r-n-2,n),ro.encode.bytes=r-n,e};ro.encode.bytes=0;ro.decode=function(t,e){e||(e=0);let r=e,n={};return e+=2,n.preference=t.readUInt16BE(e),e+=2,n.exchange=de.decode(t,e),e+=de.decode.bytes,ro.decode.bytes=e-r,n};ro.encodingLength=function(t){return 4+de.encodingLength(t.exchange)};var ri=De.a={};ri.encode=function(t,e,r){return e||(e=Me.alloc(ri.encodingLength(t))),r||(r=0),e.writeUInt16BE(4,r),r+=2,Aa.v4.encode(t,e,r),ri.encode.bytes=6,e};ri.encode.bytes=0;ri.decode=function(t,e){e||(e=0),e+=2;let r=Aa.v4.decode(t,e);return ri.decode.bytes=6,r};ri.decode.bytes=0;ri.encodingLength=function(){return 6};var ni=De.aaaa={};ni.encode=function(t,e,r){return e||(e=Me.alloc(ni.encodingLength(t))),r||(r=0),e.writeUInt16BE(16,r),r+=2,Aa.v6.encode(t,e,r),ni.encode.bytes=18,e};ni.encode.bytes=0;ni.decode=function(t,e){e||(e=0),e+=2;let r=Aa.v6.decode(t,e);return ni.decode.bytes=18,r};ni.decode.bytes=0;ni.encodingLength=function(){return 18};var Kr=De.option={};Kr.encode=function(t,e,r){e||(e=Me.alloc(Kr.encodingLength(t))),r||(r=0);let n=r,s=v1.toCode(t.code);if(e.writeUInt16BE(s,r),r+=2,t.data)e.writeUInt16BE(t.data.length,r),r+=2,t.data.copy(e,r),r+=t.data.length;else switch(s){case 8:let i=t.sourcePrefixLength||0,o=t.family||Aa.familyOf(t.ip),a=Aa.encode(t.ip,Me.alloc),c=Math.ceil(i/8);e.writeUInt16BE(c+4,r),r+=2,e.writeUInt16BE(o,r),r+=2,e.writeUInt8(i,r++),e.writeUInt8(t.scopePrefixLength||0,r++),a.copy(e,r,0,c),r+=c;break;case 11:t.timeout?(e.writeUInt16BE(2,r),r+=2,e.writeUInt16BE(t.timeout,r),r+=2):(e.writeUInt16BE(0,r),r+=2);break;case 12:let f=t.length||0;e.writeUInt16BE(f,r),r+=2,e.fill(0,r,r+f),r+=f;break;case 14:let l=t.tags.length*2;e.writeUInt16BE(l,r),r+=2;for(let p of t.tags)e.writeUInt16BE(p,r),r+=2;break;default:throw new Error(`Unknown roption code: ${t.code}`)}return Kr.encode.bytes=r-n,e};Kr.encode.bytes=0;Kr.decode=function(t,e){e||(e=0);let r={};r.code=t.readUInt16BE(e),r.type=v1.toString(r.code),e+=2;let n=t.readUInt16BE(e);switch(e+=2,r.data=t.slice(e,e+n),r.code){case 8:r.family=t.readUInt16BE(e),e+=2,r.sourcePrefixLength=t.readUInt8(e++),r.scopePrefixLength=t.readUInt8(e++);let s=Me.alloc(r.family===1?4:16);t.copy(s,0,e,e+n-4),r.ip=Aa.decode(s);break;case 11:n>0&&(r.timeout=t.readUInt16BE(e),e+=2);break;case 14:r.tags=[];for(let i=0;i<n;i+=2)r.tags.push(t.readUInt16BE(e)),e+=2}return Kr.decode.bytes=n+4,r};Kr.decode.bytes=0;Kr.encodingLength=function(t){if(t.data)return t.data.length+4;switch(v1.toCode(t.code)){case 8:let r=t.sourcePrefixLength||0;return Math.ceil(r/8)+8;case 11:return typeof t.timeout=="number"?6:4;case 12:return t.length+4;case 14:return 4+t.tags.length*2}throw new Error(`Unknown roption code: ${t.code}`)};var tn=De.opt={};tn.encode=function(t,e,r){e||(e=Me.alloc(tn.encodingLength(t))),r||(r=0);let n=r,s=zc(t,Kr);return e.writeUInt16BE(s,r),r=gd(t,Kr,e,r+2),tn.encode.bytes=r-n,e};tn.encode.bytes=0;tn.decode=function(t,e){e||(e=0);let r=e,n=[],s=t.readUInt16BE(e);e+=2;let i=0;for(;s>0;)n[i++]=Kr.decode(t,e),e+=Kr.decode.bytes,s-=Kr.decode.bytes;return tn.decode.bytes=e-r,n};tn.decode.bytes=0;tn.encodingLength=function(t){return 2+zc(t||[],Kr)};var Nr=De.dnskey={};Nr.PROTOCOL_DNSSEC=3;Nr.ZONE_KEY=128;Nr.SECURE_ENTRYPOINT=32768;Nr.encode=function(t,e,r){e||(e=Me.alloc(Nr.encodingLength(t))),r||(r=0);let n=r,s=t.key;if(!Me.isBuffer(s))throw new Error("Key must be a Buffer");return r+=2,e.writeUInt16BE(t.flags,r),r+=2,e.writeUInt8(Nr.PROTOCOL_DNSSEC,r),r+=1,e.writeUInt8(t.algorithm,r),r+=1,s.copy(e,r,0,s.length),r+=s.length,Nr.encode.bytes=r-n,e.writeUInt16BE(Nr.encode.bytes-2,n),e};Nr.encode.bytes=0;Nr.decode=function(t,e){e||(e=0);let r=e;var n={},s=t.readUInt16BE(e);if(e+=2,n.flags=t.readUInt16BE(e),e+=2,t.readUInt8(e)!==Nr.PROTOCOL_DNSSEC)throw new Error("Protocol must be 3");return e+=1,n.algorithm=t.readUInt8(e),e+=1,n.key=t.slice(e,r+s+2),e+=n.key.length,Nr.decode.bytes=e-r,n};Nr.decode.bytes=0;Nr.encodingLength=function(t){return 6+Me.byteLength(t.key)};var fs=De.rrsig={};fs.encode=function(t,e,r){e||(e=Me.alloc(fs.encodingLength(t))),r||(r=0);let n=r,s=t.signature;if(!Me.isBuffer(s))throw new Error("Signature must be a Buffer");return r+=2,e.writeUInt16BE(si.toType(t.typeCovered),r),r+=2,e.writeUInt8(t.algorithm,r),r+=1,e.writeUInt8(t.labels,r),r+=1,e.writeUInt32BE(t.originalTTL,r),r+=4,e.writeUInt32BE(t.expiration,r),r+=4,e.writeUInt32BE(t.inception,r),r+=4,e.writeUInt16BE(t.keyTag,r),r+=2,de.encode(t.signersName,e,r),r+=de.encode.bytes,s.copy(e,r,0,s.length),r+=s.length,fs.encode.bytes=r-n,e.writeUInt16BE(fs.encode.bytes-2,n),e};fs.encode.bytes=0;fs.decode=function(t,e){e||(e=0);let r=e;var n={},s=t.readUInt16BE(e);return e+=2,n.typeCovered=si.toString(t.readUInt16BE(e)),e+=2,n.algorithm=t.readUInt8(e),e+=1,n.labels=t.readUInt8(e),e+=1,n.originalTTL=t.readUInt32BE(e),e+=4,n.expiration=t.readUInt32BE(e),e+=4,n.inception=t.readUInt32BE(e),e+=4,n.keyTag=t.readUInt16BE(e),e+=2,n.signersName=de.decode(t,e),e+=de.decode.bytes,n.signature=t.slice(e,r+s+2),e+=n.signature.length,fs.decode.bytes=e-r,n};fs.decode.bytes=0;fs.encodingLength=function(t){return 20+de.encodingLength(t.signersName)+Me.byteLength(t.signature)};var ds=De.rp={};ds.encode=function(t,e,r){e||(e=Me.alloc(ds.encodingLength(t))),r||(r=0);let n=r;return r+=2,de.encode(t.mbox||".",e,r,{mail:!0}),r+=de.encode.bytes,de.encode(t.txt||".",e,r),r+=de.encode.bytes,ds.encode.bytes=r-n,e.writeUInt16BE(ds.encode.bytes-2,n),e};ds.encode.bytes=0;ds.decode=function(t,e){e||(e=0);let r=e,n={};return e+=2,n.mbox=de.decode(t,e,{mail:!0})||".",e+=de.decode.bytes,n.txt=de.decode(t,e)||".",e+=de.decode.bytes,ds.decode.bytes=e-r,n};ds.decode.bytes=0;ds.encodingLength=function(t){return 2+de.encodingLength(t.mbox||".")+de.encodingLength(t.txt||".")};var ar={};ar.encode=function(t,e,r){e||(e=Me.alloc(ar.encodingLength(t))),r||(r=0);let n=r;for(var s=[],i=0;i<t.length;i++){var o=si.toType(t[i]);s[o>>8]===void 0&&(s[o>>8]=[]),s[o>>8][o>>3&31]|=1<<7-(o&7)}for(i=0;i<s.length;i++)if(s[i]!==void 0){var a=Me.from(s[i]);e.writeUInt8(i,r),r+=1,e.writeUInt8(a.length,r),r+=1,a.copy(e,r),r+=a.length}return ar.encode.bytes=r-n,e};ar.encode.bytes=0;ar.decode=function(t,e,r){e||(e=0);let n=e;for(var s=[];e-n<r;){var i=t.readUInt8(e);e+=1;var o=t.readUInt8(e);e+=1;for(var a=0;a<o;a++)for(var c=t.readUInt8(e+a),f=0;f<8;f++)if(c&1<<7-f){var l=si.toString(i<<8|a<<3|f);s.push(l)}e+=o}return ar.decode.bytes=e-n,s};ar.decode.bytes=0;ar.encodingLength=function(t){for(var e=[],r=0;r<t.length;r++){var n=si.toType(t[r]);e[n>>8]=Math.max(e[n>>8]||0,n&255)}var s=0;for(r=0;r<e.length;r++)e[r]!==void 0&&(s+=2+Math.ceil((e[r]+1)/8));return s};var ls=De.nsec={};ls.encode=function(t,e,r){e||(e=Me.alloc(ls.encodingLength(t))),r||(r=0);let n=r;return r+=2,de.encode(t.nextDomain,e,r),r+=de.encode.bytes,ar.encode(t.rrtypes,e,r),r+=ar.encode.bytes,ls.encode.bytes=r-n,e.writeUInt16BE(ls.encode.bytes-2,n),e};ls.encode.bytes=0;ls.decode=function(t,e){e||(e=0);let r=e;var n={},s=t.readUInt16BE(e);return e+=2,n.nextDomain=de.decode(t,e),e+=de.decode.bytes,n.rrtypes=ar.decode(t,e,s-(e-r)),e+=ar.decode.bytes,ls.decode.bytes=e-r,n};ls.decode.bytes=0;ls.encodingLength=function(t){return 2+de.encodingLength(t.nextDomain)+ar.encodingLength(t.rrtypes)};var hs=De.nsec3={};hs.encode=function(t,e,r){e||(e=Me.alloc(hs.encodingLength(t))),r||(r=0);let n=r,s=t.salt;if(!Me.isBuffer(s))throw new Error("salt must be a Buffer");let i=t.nextDomain;if(!Me.isBuffer(i))throw new Error("nextDomain must be a Buffer");return r+=2,e.writeUInt8(t.algorithm,r),r+=1,e.writeUInt8(t.flags,r),r+=1,e.writeUInt16BE(t.iterations,r),r+=2,e.writeUInt8(s.length,r),r+=1,s.copy(e,r,0,s.length),r+=s.length,e.writeUInt8(i.length,r),r+=1,i.copy(e,r,0,i.length),r+=i.length,ar.encode(t.rrtypes,e,r),r+=ar.encode.bytes,hs.encode.bytes=r-n,e.writeUInt16BE(hs.encode.bytes-2,n),e};hs.encode.bytes=0;hs.decode=function(t,e){e||(e=0);let r=e;var n={},s=t.readUInt16BE(e);e+=2,n.algorithm=t.readUInt8(e),e+=1,n.flags=t.readUInt8(e),e+=1,n.iterations=t.readUInt16BE(e),e+=2;let i=t.readUInt8(e);e+=1,n.salt=t.slice(e,e+i),e+=i;let o=t.readUInt8(e);return e+=1,n.nextDomain=t.slice(e,e+o),e+=o,n.rrtypes=ar.decode(t,e,s-(e-r)),e+=ar.decode.bytes,hs.decode.bytes=e-r,n};hs.decode.bytes=0;hs.encodingLength=function(t){return 8+t.salt.length+t.nextDomain.length+ar.encodingLength(t.rrtypes)};var ps=De.ds={};ps.encode=function(t,e,r){e||(e=Me.alloc(ps.encodingLength(t))),r||(r=0);let n=r,s=t.digest;if(!Me.isBuffer(s))throw new Error("Digest must be a Buffer");return r+=2,e.writeUInt16BE(t.keyTag,r),r+=2,e.writeUInt8(t.algorithm,r),r+=1,e.writeUInt8(t.digestType,r),r+=1,s.copy(e,r,0,s.length),r+=s.length,ps.encode.bytes=r-n,e.writeUInt16BE(ps.encode.bytes-2,n),e};ps.encode.bytes=0;ps.decode=function(t,e){e||(e=0);let r=e;var n={},s=t.readUInt16BE(e);return e+=2,n.keyTag=t.readUInt16BE(e),e+=2,n.algorithm=t.readUInt8(e),e+=1,n.digestType=t.readUInt8(e),e+=1,n.digest=t.slice(e,r+s+2),e+=n.digest.length,ps.decode.bytes=e-r,n};ps.decode.bytes=0;ps.encodingLength=function(t){return 6+Me.byteLength(t.digest)};var en=De.sshfp={};en.getFingerprintLengthForHashType=function(e){switch(e){case 1:return 20;case 2:return 32}};en.encode=function(e,r,n){r||(r=Me.alloc(en.encodingLength(e))),n||(n=0);let s=n;n+=2,r[n]=e.algorithm,n+=1,r[n]=e.hash,n+=1;let i=Me.from(e.fingerprint.toUpperCase(),"hex");if(i.length!==en.getFingerprintLengthForHashType(e.hash))throw new Error("Invalid fingerprint length");return i.copy(r,n),n+=i.byteLength,en.encode.bytes=n-s,r.writeUInt16BE(en.encode.bytes-2,s),r};en.encode.bytes=0;en.decode=function(e,r){r||(r=0);let n=r,s={};r+=2,s.algorithm=e[r],r+=1,s.hash=e[r],r+=1;let i=en.getFingerprintLengthForHashType(s.hash);return s.fingerprint=e.slice(r,r+i).toString("hex").toUpperCase(),r+=i,en.decode.bytes=r-n,s};en.decode.bytes=0;en.encodingLength=function(t){return 4+Me.from(t.fingerprint,"hex").byteLength};var xs=De.naptr={};xs.encode=function(t,e,r){e||(e=Me.alloc(xs.encodingLength(t))),r||(r=0);let n=r;return r+=2,e.writeUInt16BE(t.order||0,r),r+=2,e.writeUInt16BE(t.preference||0,r),r+=2,dt.encode(t.flags,e,r),r+=dt.encode.bytes,dt.encode(t.services,e,r),r+=dt.encode.bytes,dt.encode(t.regexp,e,r),r+=dt.encode.bytes,de.encode(t.replacement,e,r),r+=de.encode.bytes,xs.encode.bytes=r-n,e.writeUInt16BE(xs.encode.bytes-2,n),e};xs.encode.bytes=0;xs.decode=function(t,e){e||(e=0);let r=e,n={};return e+=2,n.order=t.readUInt16BE(e),e+=2,n.preference=t.readUInt16BE(e),e+=2,n.flags=dt.decode(t,e),e+=dt.decode.bytes,n.services=dt.decode(t,e),e+=dt.decode.bytes,n.regexp=dt.decode(t,e),e+=dt.decode.bytes,n.replacement=de.decode(t,e),e+=de.decode.bytes,xs.decode.bytes=e-r,n};xs.decode.bytes=0;xs.encodingLength=function(t){return dt.encodingLength(t.flags)+dt.encodingLength(t.services)+dt.encodingLength(t.regexp)+de.encodingLength(t.replacement)+6};var ms=De.tlsa={};ms.encode=function(t,e,r){e||(e=Me.alloc(ms.encodingLength(t))),r||(r=0);let n=r,s=t.certificate;if(!Me.isBuffer(s))throw new Error("Certificate must be a Buffer");return r+=2,e.writeUInt8(t.usage,r),r+=1,e.writeUInt8(t.selector,r),r+=1,e.writeUInt8(t.matchingType,r),r+=1,s.copy(e,r,0,s.length),r+=s.length,ms.encode.bytes=r-n,e.writeUInt16BE(ms.encode.bytes-2,n),e};ms.encode.bytes=0;ms.decode=function(t,e){e||(e=0);let r=e,n={},s=t.readUInt16BE(e);return e+=2,n.usage=t.readUInt8(e),e+=1,n.selector=t.readUInt8(e),e+=1,n.matchingType=t.readUInt8(e),e+=1,n.certificate=t.slice(e,r+s+2),e+=n.certificate.length,ms.decode.bytes=e-r,n};ms.decode.bytes=0;ms.encodingLength=function(t){return 5+Me.byteLength(t.certificate)};var S1=De.record=function(t){switch(t.toUpperCase()){case"A":return ri;case"PTR":return Rn;case"CNAME":return hT;case"DNAME":return pT;case"TXT":return Js;case"NULL":return Qs;case"AAAA":return ni;case"SRV":return ti;case"HINFO":return ei;case"CAA":return Qr;case"NS":return Ys;case"SOA":return Zs;case"MX":return ro;case"OPT":return tn;case"DNSKEY":return Nr;case"RRSIG":return fs;case"RP":return ds;case"NSEC":return ls;case"NSEC3":return hs;case"SSHFP":return en;case"DS":return ps;case"NAPTR":return xs;case"TLSA":return ms}return Xs},mr=De.answer={};mr.encode=function(t,e,r){e||(e=Me.alloc(mr.encodingLength(t))),r||(r=0);let n=r;if(de.encode(t.name,e,r),r+=de.encode.bytes,e.writeUInt16BE(si.toType(t.type),r),t.type.toUpperCase()==="OPT"){if(t.name!==".")throw new Error("OPT name must be root.");e.writeUInt16BE(t.udpPayloadSize||4096,r+2),e.writeUInt8(t.extendedRcode||0,r+4),e.writeUInt8(t.ednsVersion||0,r+5),e.writeUInt16BE(t.flags||0,r+6),r+=8,tn.encode(t.options||[],e,r),r+=tn.encode.bytes}else{let s=Sh.toClass(t.class===void 0?"IN":t.class);t.flush&&(s|=w1),e.writeUInt16BE(s,r+2),e.writeUInt32BE(t.ttl||0,r+4),r+=8;let i=S1(t.type);i.encode(t.data,e,r),r+=i.encode.bytes}return mr.encode.bytes=r-n,e};mr.encode.bytes=0;mr.decode=function(t,e){e||(e=0);let r={},n=e;if(r.name=de.decode(t,e),e+=de.decode.bytes,r.type=si.toString(t.readUInt16BE(e)),r.type==="OPT")r.udpPayloadSize=t.readUInt16BE(e+2),r.extendedRcode=t.readUInt8(e+4),r.ednsVersion=t.readUInt8(e+5),r.flags=t.readUInt16BE(e+6),r.flag_do=(r.flags>>15&1)===1,r.options=tn.decode(t,e+8),e+=8+tn.decode.bytes;else{let s=t.readUInt16BE(e+2);r.ttl=t.readUInt32BE(e+4),r.class=Sh.toString(s&dT),r.flush=!!(s&w1);let i=S1(r.type);r.data=i.decode(t,e+8),e+=8+i.decode.bytes}return mr.decode.bytes=e-n,r};mr.decode.bytes=0;mr.encodingLength=function(t){let e=t.data!==null&&t.data!==void 0?t.data:t.options;return de.encodingLength(t.name)+8+S1(t.type).encodingLength(e)};var Nn=De.question={};Nn.encode=function(t,e,r){e||(e=Me.alloc(Nn.encodingLength(t))),r||(r=0);let n=r;return de.encode(t.name,e,r),r+=de.encode.bytes,e.writeUInt16BE(si.toType(t.type),r),r+=2,e.writeUInt16BE(Sh.toClass(t.class===void 0?"IN":t.class),r),r+=2,Nn.encode.bytes=r-n,t};Nn.encode.bytes=0;Nn.decode=function(t,e){e||(e=0);let r=e,n={};return n.name=de.decode(t,e),e+=de.decode.bytes,n.type=si.toString(t.readUInt16BE(e)),e+=2,n.class=Sh.toString(t.readUInt16BE(e)),e+=2,n.class&C6&&(n.class&=lT),Nn.decode.bytes=e-r,n};Nn.decode.bytes=0;Nn.encodingLength=function(t){return de.encodingLength(t.name)+4};De.AUTHORITATIVE_ANSWER=1024;De.TRUNCATED_RESPONSE=512;De.RECURSION_DESIRED=256;De.RECURSION_AVAILABLE=128;De.AUTHENTIC_DATA=32;De.CHECKING_DISABLED=16;De.DNSSEC_OK=32768;De.encode=function(t,e,r){let n=!e;n&&(e=Me.alloc(De.encodingLength(t))),r||(r=0);let s=r;return t.questions||(t.questions=[]),t.answers||(t.answers=[]),t.authorities||(t.authorities=[]),t.additionals||(t.additionals=[]),Pn.encode(t,e,r),r+=Pn.encode.bytes,r=gd(t.questions,Nn,e,r),r=gd(t.answers,mr,e,r),r=gd(t.authorities,mr,e,r),r=gd(t.additionals,mr,e,r),De.encode.bytes=r-s,n&&De.encode.bytes!==e.length?e.slice(0,De.encode.bytes):e};De.encode.bytes=0;De.decode=function(t,e){e||(e=0);let r=e,n=Pn.decode(t,e);return e+=Pn.decode.bytes,e=wh(n.questions,Nn,t,e),e=wh(n.answers,mr,t,e),e=wh(n.authorities,mr,t,e),e=wh(n.additionals,mr,t,e),De.decode.bytes=e-r,n};De.decode.bytes=0;De.encodingLength=function(t){return Pn.encodingLength(t)+zc(t.questions||[],Nn)+zc(t.answers||[],mr)+zc(t.authorities||[],mr)+zc(t.additionals||[],mr)};De.streamEncode=function(t){let e=De.encode(t),r=Me.alloc(2);r.writeUInt16BE(e.byteLength);let n=Me.concat([r,e]);return De.streamEncode.bytes=n.byteLength,n};De.streamEncode.bytes=0;De.streamDecode=function(t){let e=t.readUInt16BE(0);if(t.byteLength<e+2)return null;let r=De.decode(t.slice(2));return De.streamDecode.bytes=De.decode.bytes,r};De.streamDecode.bytes=0;function zc(t,e){let r=0;for(let n=0;n<t.length;n++)r+=e.encodingLength(t[n]);return r}function gd(t,e,r,n){for(let s=0;s<t.length;s++)e.encode(t[s],r,n),n+=e.encode.bytes;return n}function wh(t,e,r,n){for(let s=0;s<t.length;s++)t[s]=e.decode(r,n),n+=e.decode.bytes;return n}});var B6=Ve((uZ,_6)=>{"use strict";var T6=vT;process.nextTick(bT,42);_6.exports=xT;function xT(t){var e=n;return r;function r(s){e(s||gT)}function n(s){var i=[s];e=o,t(a);function o(c){i.push(c)}function a(c){var f=arguments;for(e=mT(c)?n:l;i.length;)l(i.shift());function l(p){T6(yT,p,f)}}}}function mT(t){return Object.prototype.toString.call(t)==="[object Error]"}function gT(){}function yT(t,e){t.apply(null,e)}function bT(t){t===42&&(T6=process.nextTick)}function vT(t,e,r){process.nextTick(function(){t(e,r)})}});var N6=Ve((fZ,R6)=>{"use strict";var E1=I6(),wT=Gt("dgram"),ST=B6(),ET=Gt("events"),C1=Gt("os"),A1=function(){};R6.exports=function(t){t||(t={});var e=new ET.EventEmitter,r=typeof t.port=="number"?t.port:5353,n=t.type||"udp4",s=t.ip||t.host||(n==="udp4"?"224.0.0.251":null),i={address:s,port:r},o={},a=!1,c=null;if(n==="udp6"&&(!s||!t.interface))throw new Error("For IPv6 multicast you must specify `ip` and `interface`");var f=t.socket||wT.createSocket({type:n,reuseAddr:t.reuseAddr!==!1,toString:function(){return n}});f.on("error",function(p){p.code==="EACCES"||p.code==="EADDRINUSE"?e.emit("error",p):e.emit("warning",p)}),f.on("message",function(p,x){try{p=E1.decode(p)}catch(v){e.emit("warning",v);return}e.emit("packet",p,x),p.type==="query"&&e.emit("query",p,x),p.type==="response"&&e.emit("response",p,x)}),f.on("listening",function(){r||(r=i.port=f.address().port),t.multicast!==!1&&(e.update(),c=setInterval(e.update,5e3),f.setMulticastTTL(t.ttl||255),f.setMulticastLoopback(t.loopback!==!1))});var l=ST(function(p){if(!r||t.bind===!1)return p(null);f.once("error",p),f.bind(r,t.bind||t.interface,function(){f.removeListener("error",p),p(null)})});return l(function(p){if(p)return e.emit("error",p);e.emit("ready")}),e.send=function(p,x,v){if(typeof x=="function")return e.send(p,null,x);v||(v=A1),x?!x.host&&!x.address&&(x.address=i.address):x=i,l(S);function S(I){if(a)return v();if(I)return v(I);var L=E1.encode(p);f.send(L,0,L.length,x.port,x.address||x.host,v)}},e.response=e.respond=function(p,x,v){Array.isArray(p)&&(p={answers:p}),p.type="response",p.flags=(p.flags||0)|E1.AUTHORITATIVE_ANSWER,e.send(p,x,v)},e.query=function(p,x,v,S){if(typeof x=="function")return e.query(p,null,null,x);if(typeof x=="object"&&x&&x.port)return e.query(p,null,x,v);if(typeof v=="function")return e.query(p,x,null,v);S||(S=A1),typeof p=="string"&&(p=[{name:p,type:x||"ANY"}]),Array.isArray(p)&&(p={type:"query",questions:p}),p.type="query",e.send(p,v,S)},e.destroy=function(p){if(p||(p=A1),a)return process.nextTick(p);a=!0,clearInterval(c);for(var x in o)try{f.dropMembership(s,x)}catch{}o={},f.close(p)},e.update=function(){for(var p=t.interface?[].concat(t.interface):CT(),x=!1,v=0;v<p.length;v++){var S=p[v];if(!o[S])try{f.addMembership(s,S),o[S]=!0,x=!0}catch(I){e.emit("warning",I)}}if(x){if(f.setMulticastInterface)try{f.setMulticastInterface(t.interface||AT())}catch(I){e.emit("warning",I)}e.emit("networkInterface")}},e};function AT(){for(var t=C1.networkInterfaces(),e=Object.keys(t),r=0;r<e.length;r++)for(var n=t[e[r]],s=0;s<n.length;s++){var i=n[s];if(k6(i.family)&&!i.internal)return C1.platform()==="darwin"&&e[r]==="en0"?i.address:"0.0.0.0"}return"127.0.0.1"}function CT(){for(var t=C1.networkInterfaces(),e=Object.keys(t),r=[],n=0;n<e.length;n++)for(var s=t[e[n]],i=0;i<s.length;i++){var o=s[i];if(k6(o.family)){r.push(o.address);break}}return r}function k6(t){return t===4||t==="IPv4"}});var Vg=it(hi(),1),b8=it(dy(),1),fp=it(Up(),1);import{randomBytes as u8}from"crypto";import{createSocket as g8}from"dgram";import{createSocket as UT}from"dgram";import*as v8 from"net";import{connect as DT}from"net";import{createSign as HT,randomBytes as jT,webcrypto as qT}from"crypto";var RX=it(_y());var Gn={};iy(Gn,{Any:()=>Kn,BaseBlock:()=>Wt,BaseStringBlock:()=>wu,BitString:()=>wn,BmpString:()=>Eo,Boolean:()=>vo,CharacterString:()=>No,Choice:()=>Wa,Constructed:()=>Xt,DATE:()=>Tu,DEFAULT_MAX_CONTENT_LENGTH:()=>Vy,DEFAULT_MAX_DEPTH:()=>jy,DEFAULT_MAX_NODES:()=>qy,DateTime:()=>Bu,Duration:()=>ku,EndOfContent:()=>Su,Enumerated:()=>wo,GeneralString:()=>Ro,GeneralizedTime:()=>Po,GraphicString:()=>ko,HexBlock:()=>Wn,IA5String:()=>Bo,Integer:()=>Is,Null:()=>bn,NumericString:()=>Co,ObjectIdentifier:()=>So,OctetString:()=>vn,Primitive:()=>Cs,PrintableString:()=>Io,RawData:()=>jp,RelativeObjectIdentifier:()=>Iu,Repeated:()=>Oo,Sequence:()=>Er,Set:()=>Br,TIME:()=>Ru,TeletexString:()=>To,TimeOfDay:()=>_u,UTCTime:()=>wi,UniversalString:()=>Ao,Utf8String:()=>an,ValueBlock:()=>or,VideotexString:()=>_o,ViewWriter:()=>$a,VisibleString:()=>vi,compareSchema:()=>Es,fromBER:()=>_s,verifySchema:()=>dA});var qE="[object ArrayBuffer]",ce=class t{static isArrayBuffer(e){return Object.prototype.toString.call(e)===qE}static toArrayBuffer(e){return this.isArrayBuffer(e)?e:e.byteLength===e.buffer.byteLength||e.byteOffset===0&&e.byteLength===e.buffer.byteLength?e.buffer:this.toUint8Array(e.buffer).slice(e.byteOffset,e.byteOffset+e.byteLength).buffer}static toUint8Array(e){return this.toView(e,Uint8Array)}static toView(e,r){if(e.constructor===r)return e;if(this.isArrayBuffer(e))return new r(e);if(this.isArrayBufferView(e))return new r(e.buffer,e.byteOffset,e.byteLength);throw new TypeError("The provided value is not of type '(ArrayBuffer or ArrayBufferView)'")}static isBufferSource(e){return this.isArrayBufferView(e)||this.isArrayBuffer(e)}static isArrayBufferView(e){return ArrayBuffer.isView(e)||e&&this.isArrayBuffer(e.buffer)}static isEqual(e,r){let n=t.toUint8Array(e),s=t.toUint8Array(r);if(n.length!==s.byteLength)return!1;for(let i=0;i<n.length;i++)if(n[i]!==s[i])return!1;return!0}static concat(...e){let r;Array.isArray(e[0])&&!(e[1]instanceof Function)||Array.isArray(e[0])&&e[1]instanceof Function?r=e[0]:e[e.length-1]instanceof Function?r=e.slice(0,e.length-1):r=e;let n=0;for(let o of r)n+=o.byteLength;let s=new Uint8Array(n),i=0;for(let o of r){let a=this.toUint8Array(o);s.set(a,i),i+=a.length}return e[e.length-1]instanceof Function?this.toView(s,e[e.length-1]):s.buffer}},Dp="string",VE=/^[0-9a-f\s]+$/i,zE=/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/,FE=/^[a-zA-Z0-9-_]+$/,wl=class{static fromString(e){let r=unescape(encodeURIComponent(e)),n=new Uint8Array(r.length);for(let s=0;s<r.length;s++)n[s]=r.charCodeAt(s);return n.buffer}static toString(e){let r=ce.toUint8Array(e),n="";for(let i=0;i<r.length;i++)n+=String.fromCharCode(r[i]);return decodeURIComponent(escape(n))}},on=class{static toString(e,r=!1){let n=ce.toArrayBuffer(e),s=new DataView(n),i="";for(let o=0;o<n.byteLength;o+=2){let a=s.getUint16(o,r);i+=String.fromCharCode(a)}return i}static fromString(e,r=!1){let n=new ArrayBuffer(e.length*2),s=new DataView(n);for(let i=0;i<e.length;i++)s.setUint16(i*2,e.charCodeAt(i),r);return n}},ke=class t{static isHex(e){return typeof e===Dp&&VE.test(e)}static isBase64(e){return typeof e===Dp&&zE.test(e)}static isBase64Url(e){return typeof e===Dp&&FE.test(e)}static ToString(e,r="utf8"){let n=ce.toUint8Array(e);switch(r.toLowerCase()){case"utf8":return this.ToUtf8String(n);case"binary":return this.ToBinary(n);case"hex":return this.ToHex(n);case"base64":return this.ToBase64(n);case"base64url":return this.ToBase64Url(n);case"utf16le":return on.toString(n,!0);case"utf16":case"utf16be":return on.toString(n);default:throw new Error(`Unknown type of encoding '${r}'`)}}static FromString(e,r="utf8"){if(!e)return new ArrayBuffer(0);switch(r.toLowerCase()){case"utf8":return this.FromUtf8String(e);case"binary":return this.FromBinary(e);case"hex":return this.FromHex(e);case"base64":return this.FromBase64(e);case"base64url":return this.FromBase64Url(e);case"utf16le":return on.fromString(e,!0);case"utf16":case"utf16be":return on.fromString(e);default:throw new Error(`Unknown type of encoding '${r}'`)}}static ToBase64(e){let r=ce.toUint8Array(e);if(typeof btoa<"u"){let n=this.ToString(r,"binary");return btoa(n)}else return Buffer.from(r).toString("base64")}static FromBase64(e){let r=this.formatString(e);if(!r)return new ArrayBuffer(0);if(!t.isBase64(r))throw new TypeError("Argument 'base64Text' is not Base64 encoded");return typeof atob<"u"?this.FromBinary(atob(r)):new Uint8Array(Buffer.from(r,"base64")).buffer}static FromBase64Url(e){let r=this.formatString(e);if(!r)return new ArrayBuffer(0);if(!t.isBase64Url(r))throw new TypeError("Argument 'base64url' is not Base64Url encoded");return this.FromBase64(this.Base64Padding(r.replace(/\-/g,"+").replace(/\_/g,"/")))}static ToBase64Url(e){return this.ToBase64(e).replace(/\+/g,"-").replace(/\//g,"_").replace(/\=/g,"")}static FromUtf8String(e,r=t.DEFAULT_UTF8_ENCODING){switch(r){case"ascii":return this.FromBinary(e);case"utf8":return wl.fromString(e);case"utf16":case"utf16be":return on.fromString(e);case"utf16le":case"usc2":return on.fromString(e,!0);default:throw new Error(`Unknown type of encoding '${r}'`)}}static ToUtf8String(e,r=t.DEFAULT_UTF8_ENCODING){switch(r){case"ascii":return this.ToBinary(e);case"utf8":return wl.toString(e);case"utf16":case"utf16be":return on.toString(e);case"utf16le":case"usc2":return on.toString(e,!0);default:throw new Error(`Unknown type of encoding '${r}'`)}}static FromBinary(e){let r=e.length,n=new Uint8Array(r);for(let s=0;s<r;s++)n[s]=e.charCodeAt(s);return n.buffer}static ToBinary(e){let r=ce.toUint8Array(e),n="";for(let s=0;s<r.length;s++)n+=String.fromCharCode(r[s]);return n}static ToHex(e){let r=ce.toUint8Array(e),n="",s=r.length;for(let i=0;i<s;i++){let o=r[i];o<16&&(n+="0"),n+=o.toString(16)}return n}static FromHex(e){let r=this.formatString(e);if(!r)return new ArrayBuffer(0);if(!t.isHex(r))throw new TypeError("Argument 'hexString' is not HEX encoded");r.length%2&&(r=`0${r}`);let n=new Uint8Array(r.length/2);for(let s=0;s<r.length;s=s+2){let i=r.slice(s,s+2);n[s/2]=parseInt(i,16)}return n.buffer}static ToUtf16String(e,r=!1){return on.toString(e,r)}static FromUtf16String(e,r=!1){return on.fromString(e,r)}static Base64Padding(e){let r=4-e.length%4;if(r<4)for(let n=0;n<r;n++)e+="=";return e}static formatString(e){return e?.replace(/[\n\r\t ]/g,"")||""}};ke.DEFAULT_UTF8_ENCODING="utf8";function By(...t){let e=t.map(s=>s.byteLength).reduce((s,i)=>s+i),r=new Uint8Array(e),n=0;return t.map(s=>new Uint8Array(s)).forEach(s=>{for(let i of s)r[n++]=i}),r.buffer}function ky(t,e){if(!(t&&e)||t.byteLength!==e.byteLength)return!1;let r=new Uint8Array(t),n=new Uint8Array(e);for(let s=0;s<t.byteLength;s++)if(r[s]!==n[s])return!1;return!0}function bo(t,e){let r=0;if(t.length===1)return t[0];for(let n=t.length-1;n>=0;n--)r+=t[t.length-1-n]*Math.pow(2,e*n);return r}function bi(t,e,r=-1){let n=r,s=t,i=0,o=Math.pow(2,e);for(let a=1;a<8;a++){if(t<o){let c;if(n<0)c=new ArrayBuffer(a),i=a;else{if(n<a)return new ArrayBuffer(0);c=new ArrayBuffer(n),i=n}let f=new Uint8Array(c);for(let l=a-1;l>=0;l--){let p=Math.pow(2,l*e);f[i-l-1]=Math.floor(s/p),s-=f[i-l-1]*p}return c}o*=Math.pow(2,e)}return new ArrayBuffer(0)}function Sl(...t){let e=0,r=0;for(let i of t)e+=i.length;let n=new ArrayBuffer(e),s=new Uint8Array(n);for(let i of t)s.set(i,r),r+=i.length;return s}function Mp(){let t=new Uint8Array(this.valueHex);if(this.valueHex.byteLength>=2){let a=t[0]===255&&t[1]&128,c=t[0]===0&&(t[1]&128)===0;(a||c)&&this.warnings.push("Needlessly long format")}let e=new ArrayBuffer(this.valueHex.byteLength),r=new Uint8Array(e);for(let a=0;a<this.valueHex.byteLength;a++)r[a]=0;r[0]=t[0]&128;let n=bo(r,8),s=new ArrayBuffer(this.valueHex.byteLength),i=new Uint8Array(s);for(let a=0;a<this.valueHex.byteLength;a++)i[a]=t[a];return i[0]&=127,bo(i,8)-n}function Ry(t){let e=t<0?t*-1:t,r=128;for(let n=1;n<8;n++){if(e<=r){if(t<0){let o=r-e,a=bi(o,8,n),c=new Uint8Array(a);return c[0]|=128,a}let s=bi(e,8,n),i=new Uint8Array(s);if(i[0]&128){let o=s.slice(0),a=new Uint8Array(o);s=new ArrayBuffer(s.byteLength+1),i=new Uint8Array(s);for(let c=0;c<o.byteLength;c++)i[c+1]=a[c];i[0]=0}return s}r*=Math.pow(2,8)}return new ArrayBuffer(0)}function Ny(t,e){if(t.byteLength!==e.byteLength)return!1;let r=new Uint8Array(t),n=new Uint8Array(e);for(let s=0;s<r.length;s++)if(r[s]!==n[s])return!1;return!0}function Or(t,e){let r=t.toString(10);if(e<r.length)return"";let n=e-r.length,s=new Array(n);for(let o=0;o<n;o++)s[o]="0";return s.join("").concat(r)}var dR=Math.log(2);function El(){if(typeof BigInt>"u")throw new Error("BigInt is not defined. Your environment doesn't implement BigInt.")}function qp(t){let e=0,r=0;for(let s=0;s<t.length;s++){let i=t[s];e+=i.byteLength}let n=new Uint8Array(e);for(let s=0;s<t.length;s++){let i=t[s];n.set(new Uint8Array(i),r),r+=i.byteLength}return n.buffer}function Ts(t,e,r,n){return e instanceof Uint8Array?e.byteLength?r<0?(t.error="Wrong parameter: inputOffset less than zero",!1):n<0?(t.error="Wrong parameter: inputLength less than zero",!1):e.byteLength-r-n<0?(t.error="End of input reached before message was fully decoded (inconsistent offset and length values)",!1):!0:(t.error="Wrong parameter: inputBuffer has zero length",!1):(t.error="Wrong parameter: inputBuffer must be 'Uint8Array'",!1)}var $a=class{constructor(){this.items=[]}write(e){this.items.push(e)}final(){return qp(this.items)}},yu=[new Uint8Array([1])],Py="0123456789",Hp="name",Oy="valueHexView",WE="isHexOnly",GE="idBlock",XE="tagClass",YE="tagNumber",ZE="isConstructed",JE="fromBER",QE="toBER",eA="local",Lr="",$n=new ArrayBuffer(0),Ml=new Uint8Array(0),vu="EndOfContent",Uy="OCTET STRING",Dy="BIT STRING";function Wn(t){var e;return e=class extends t{get valueHex(){return this.valueHexView.slice().buffer}set valueHex(n){this.valueHexView=new Uint8Array(n)}constructor(...n){var s;super(...n);let i=n[0]||{};this.isHexOnly=(s=i.isHexOnly)!==null&&s!==void 0?s:!1,this.valueHexView=i.valueHex?ce.toUint8Array(i.valueHex):Ml}fromBER(n,s,i,o){let a=n instanceof ArrayBuffer?new Uint8Array(n):n;if(!Ts(this,a,s,i))return-1;let c=s+i;return this.valueHexView=a.subarray(s,c),this.valueHexView.length?(this.blockLength=i,c):(this.warnings.push("Zero buffer length"),s)}toBER(n=!1){return this.isHexOnly?n?new ArrayBuffer(this.valueHexView.byteLength):this.valueHexView.byteLength===this.valueHexView.buffer.byteLength?this.valueHexView.buffer:this.valueHexView.slice().buffer:(this.error="Flag 'isHexOnly' is not set, abort",$n)}toJSON(){return{...super.toJSON(),isHexOnly:this.isHexOnly,valueHex:ke.ToHex(this.valueHexView)}}},e.NAME="hexBlock",e}var As=class{static blockName(){return this.NAME}get valueBeforeDecode(){return this.valueBeforeDecodeView.slice().buffer}set valueBeforeDecode(e){this.valueBeforeDecodeView=new Uint8Array(e)}constructor({blockLength:e=0,error:r=Lr,warnings:n=[],valueBeforeDecode:s=Ml}={}){this.blockLength=e,this.error=r,this.warnings=n,this.valueBeforeDecodeView=ce.toUint8Array(s)}toJSON(){return{blockName:this.constructor.NAME,blockLength:this.blockLength,error:this.error,warnings:this.warnings,valueBeforeDecode:ke.ToHex(this.valueBeforeDecodeView)}}};As.NAME="baseBlock";var or=class extends As{fromBER(e,r,n,s){throw TypeError("User need to make a specific function in a class which extends 'ValueBlock'")}toBER(e,r){throw TypeError("User need to make a specific function in a class which extends 'ValueBlock'")}};or.NAME="valueBlock";var Al=class extends Wn(As){constructor({idBlock:e={}}={}){var r,n,s,i;super(),e?(this.isHexOnly=(r=e.isHexOnly)!==null&&r!==void 0?r:!1,this.valueHexView=e.valueHex?ce.toUint8Array(e.valueHex):Ml,this.tagClass=(n=e.tagClass)!==null&&n!==void 0?n:-1,this.tagNumber=(s=e.tagNumber)!==null&&s!==void 0?s:-1,this.isConstructed=(i=e.isConstructed)!==null&&i!==void 0?i:!1):(this.tagClass=-1,this.tagNumber=-1,this.isConstructed=!1)}toBER(e=!1){let r=0;switch(this.tagClass){case 1:r|=0;break;case 2:r|=64;break;case 3:r|=128;break;case 4:r|=192;break;default:return this.error="Unknown tag class",$n}if(this.isConstructed&&(r|=32),this.tagNumber<31&&!this.isHexOnly){let s=new Uint8Array(1);if(!e){let i=this.tagNumber;i&=31,r|=i,s[0]=r}return s.buffer}if(!this.isHexOnly){let s=bi(this.tagNumber,7),i=new Uint8Array(s),o=s.byteLength,a=new Uint8Array(o+1);if(a[0]=r|31,!e){for(let c=0;c<o-1;c++)a[c+1]=i[c]|128;a[o]=i[o-1]}return a.buffer}let n=new Uint8Array(this.valueHexView.byteLength+1);if(n[0]=r|31,!e){let s=this.valueHexView;for(let i=0;i<s.length-1;i++)n[i+1]=s[i]|128;n[this.valueHexView.byteLength]=s[s.length-1]}return n.buffer}fromBER(e,r,n){let s=ce.toUint8Array(e);if(!Ts(this,s,r,n))return-1;let i=s.subarray(r,r+n);if(i.length===0)return this.error="Zero buffer length",-1;switch(i[0]&192){case 0:this.tagClass=1;break;case 64:this.tagClass=2;break;case 128:this.tagClass=3;break;case 192:this.tagClass=4;break;default:return this.error="Unknown tag class",-1}this.isConstructed=(i[0]&32)===32,this.isHexOnly=!1;let a=i[0]&31;if(a!==31)this.tagNumber=a,this.blockLength=1;else{let c=0;for(;;){let l=c+1;if(l>=i.length)return this.error="End of input reached before message was fully decoded",-1;if(c++,(i[l]&128)===0)break}this.blockLength=c+1;let f=this.valueHexView=new Uint8Array(c);for(let l=0;l<c;l++)f[l]=i[l+1]&127;this.blockLength<=9?this.tagNumber=bo(f,7):(this.isHexOnly=!0,this.warnings.push("Tag too long, represented as hex-coded"))}if(this.tagClass===1&&this.isConstructed)switch(this.tagNumber){case 1:case 2:case 5:case 6:case 9:case 13:case 14:case 23:case 24:case 31:case 32:case 33:case 34:return this.error="Constructed encoding used for primitive type",-1}return r+this.blockLength}toJSON(){return{...super.toJSON(),tagClass:this.tagClass,tagNumber:this.tagNumber,isConstructed:this.isConstructed}}};Al.NAME="identificationBlock";var Cl=class extends As{constructor({lenBlock:e={}}={}){var r,n,s;super(),this.isIndefiniteForm=(r=e.isIndefiniteForm)!==null&&r!==void 0?r:!1,this.longFormUsed=(n=e.longFormUsed)!==null&&n!==void 0?n:!1,this.length=(s=e.length)!==null&&s!==void 0?s:0}fromBER(e,r,n){let s=ce.toUint8Array(e);if(!Ts(this,s,r,n))return-1;let i=s.subarray(r,r+n);if(i.length===0)return this.error="Zero buffer length",-1;if(i[0]===255)return this.error="Length block 0xFF is reserved by standard",-1;if(this.isIndefiniteForm=i[0]===128,this.isIndefiniteForm)return this.blockLength=1,r+this.blockLength;if(this.longFormUsed=!!(i[0]&128),this.longFormUsed===!1)return this.length=i[0],this.blockLength=1,r+this.blockLength;let o=i[0]&127;if(o>8)return this.error="Too big integer",-1;if(o+1>i.length)return this.error="End of input reached before message was fully decoded",-1;let a=r+1,c=s.subarray(a,a+o);return c[o-1]===0&&this.warnings.push("Needlessly long encoded length"),this.length=bo(c,8),this.longFormUsed&&this.length<=127&&this.warnings.push("Unnecessary usage of long length form"),this.blockLength=o+1,r+this.blockLength}toBER(e=!1){let r,n;if(this.length>127&&(this.longFormUsed=!0),this.isIndefiniteForm)return r=new ArrayBuffer(1),e===!1&&(n=new Uint8Array(r),n[0]=128),r;if(this.longFormUsed){let s=bi(this.length,8);if(s.byteLength>127)return this.error="Too big length",$n;if(r=new ArrayBuffer(s.byteLength+1),e)return r;let i=new Uint8Array(s);n=new Uint8Array(r),n[0]=s.byteLength|128;for(let o=0;o<s.byteLength;o++)n[o+1]=i[o];return r}return r=new ArrayBuffer(1),e===!1&&(n=new Uint8Array(r),n[0]=this.length),r}toJSON(){return{...super.toJSON(),isIndefiniteForm:this.isIndefiniteForm,longFormUsed:this.longFormUsed,length:this.length}}};Cl.NAME="lengthBlock";var me={},Wt=class extends As{constructor({name:e=Lr,optional:r=!1,primitiveSchema:n,...s}={},i){super(s),this.name=e,this.optional=r,n&&(this.primitiveSchema=n),this.idBlock=new Al(s),this.lenBlock=new Cl(s),this.valueBlock=i?new i(s):new or(s)}fromBER(e,r,n,s){let i=this.valueBlock.fromBER(e,r,this.lenBlock.isIndefiniteForm?n:this.lenBlock.length,s);return i===-1?(this.error=this.valueBlock.error,i):(this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.valueBlock.error.length||(this.blockLength+=this.valueBlock.blockLength),i)}toBER(e,r){let n=r||new $a;r||My(this);let s=this.idBlock.toBER(e);if(n.write(s),this.lenBlock.isIndefiniteForm)n.write(new Uint8Array([128]).buffer),this.valueBlock.toBER(e,n),n.write(new ArrayBuffer(2));else{let i=this.valueBlock.toBER(e);this.lenBlock.length=i.byteLength;let o=this.lenBlock.toBER(e);n.write(o),n.write(i)}return r?$n:n.final()}toJSON(){let e={...super.toJSON(),idBlock:this.idBlock.toJSON(),lenBlock:this.lenBlock.toJSON(),valueBlock:this.valueBlock.toJSON(),name:this.name,optional:this.optional};return this.primitiveSchema&&(e.primitiveSchema=this.primitiveSchema.toJSON()),e}toString(e="ascii"){return e==="ascii"?this.onAsciiEncoding():ke.ToHex(this.toBER())}onAsciiEncoding(){let e=this.constructor.NAME,r=ke.ToHex(this.valueBlock.valueBeforeDecodeView);return`${e} : ${r}`}isEqual(e){if(this===e)return!0;if(!(e instanceof this.constructor))return!1;let r=this.toBER(),n=e.toBER();return Ny(r,n)}};Wt.NAME="BaseBlock";function My(t){var e;if(t instanceof me.Constructed)for(let r of t.valueBlock.value)My(r)&&(t.lenBlock.isIndefiniteForm=!0);return!!(!((e=t.lenBlock)===null||e===void 0)&&e.isIndefiniteForm)}var wu=class extends Wt{getValue(){return this.valueBlock.value}setValue(e){this.valueBlock.value=e}constructor({value:e=Lr,...r}={},n){super(r,n),e&&this.fromString(e)}fromBER(e,r,n){let s=this.valueBlock.fromBER(e,r,this.lenBlock.isIndefiniteForm?n:this.lenBlock.length);return s===-1?(this.error=this.valueBlock.error,s):(this.fromBuffer(this.valueBlock.valueHexView),this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.valueBlock.error.length||(this.blockLength+=this.valueBlock.blockLength),s)}onAsciiEncoding(){return`${this.constructor.NAME} : '${this.valueBlock.value}'`}};wu.NAME="BaseStringBlock";var Il=class extends Wn(or){constructor({isHexOnly:e=!0,...r}={}){super(r),this.isHexOnly=e}};Il.NAME="PrimitiveValueBlock";var Hy,Cs=class extends Wt{constructor(e={}){super(e,Il),this.idBlock.isConstructed=!1}};Hy=Cs;me.Primitive=Hy;Cs.NAME="PRIMITIVE";var jy=100,qy=1e4,Vy=16*1024*1024,tA="Maximum ASN.1 nesting depth exceeded",rA="Maximum ASN.1 node count exceeded",nA="Maximum ASN.1 content length exceeded";function Nu(t={}){var e,r,n;return{depth:0,maxDepth:(e=t.maxDepth)!==null&&e!==void 0?e:jy,nodesCount:0,maxNodes:(r=t.maxNodes)!==null&&r!==void 0?r:qy,maxContentLength:(n=t.maxContentLength)!==null&&n!==void 0?n:Vy}}function sA(t){let e=new Wt({},or);return e.error=t,{offset:-1,result:e}}function iA(t){if(t.nodesCount+=1,t.nodesCount>t.maxNodes)return rA}function oA(t,e){if(t>e.maxContentLength)return nA}function Vp(t,e,r,n){let s=n.depth+1;if(s>n.maxDepth)return sA(tA);n.depth=s;try{return Hl(t,e,r,n)}finally{n.depth-=1}}function aA(t,e){if(t instanceof e)return t;let r=new e;return r.idBlock=t.idBlock,r.lenBlock=t.lenBlock,r.warnings=t.warnings,r.valueBeforeDecodeView=t.valueBeforeDecodeView,r}function Hl(t,e=0,r=t.length,n=Nu()){let s=e,i=new Wt({},or),o=new As;if(!Ts(o,t,e,r))return i.error=o.error,{offset:-1,result:i};if(!t.subarray(e,e+r).length)return i.error="Zero buffer length",{offset:-1,result:i};let c=iA(n);if(c)return i.error=c,{offset:-1,result:i};let f=i.idBlock.fromBER(t,e,r);if(i.idBlock.warnings.length&&i.warnings.concat(i.idBlock.warnings),f===-1)return i.error=i.idBlock.error,{offset:-1,result:i};if(e=f,r-=i.idBlock.blockLength,f=i.lenBlock.fromBER(t,e,r),i.lenBlock.warnings.length&&i.warnings.concat(i.lenBlock.warnings),f===-1)return i.error=i.lenBlock.error,{offset:-1,result:i};e=f,r-=i.lenBlock.blockLength;let l=i.lenBlock.isIndefiniteForm?r:i.lenBlock.length,p=oA(l,n);if(p)return i.error=p,{offset:-1,result:i};if(!i.idBlock.isConstructed&&i.lenBlock.isIndefiniteForm)return i.error="Indefinite length form used for primitive encoding form",{offset:-1,result:i};let x=Wt;switch(i.idBlock.tagClass){case 1:if(i.idBlock.tagNumber>=37&&i.idBlock.isHexOnly===!1)return i.error="UNIVERSAL 37 and upper tags are reserved by ASN.1 standard",{offset:-1,result:i};switch(i.idBlock.tagNumber){case 0:if(i.idBlock.isConstructed&&i.lenBlock.length>0)return i.error="Type [UNIVERSAL 0] is reserved",{offset:-1,result:i};x=me.EndOfContent;break;case 1:x=me.Boolean;break;case 2:x=me.Integer;break;case 3:x=me.BitString;break;case 4:x=me.OctetString;break;case 5:x=me.Null;break;case 6:x=me.ObjectIdentifier;break;case 10:x=me.Enumerated;break;case 12:x=me.Utf8String;break;case 13:x=me.RelativeObjectIdentifier;break;case 14:x=me.TIME;break;case 15:return i.error="[UNIVERSAL 15] is reserved by ASN.1 standard",{offset:-1,result:i};case 16:x=me.Sequence;break;case 17:x=me.Set;break;case 18:x=me.NumericString;break;case 19:x=me.PrintableString;break;case 20:x=me.TeletexString;break;case 21:x=me.VideotexString;break;case 22:x=me.IA5String;break;case 23:x=me.UTCTime;break;case 24:x=me.GeneralizedTime;break;case 25:x=me.GraphicString;break;case 26:x=me.VisibleString;break;case 27:x=me.GeneralString;break;case 28:x=me.UniversalString;break;case 29:x=me.CharacterString;break;case 30:x=me.BmpString;break;case 31:x=me.DATE;break;case 32:x=me.TimeOfDay;break;case 33:x=me.DateTime;break;case 34:x=me.Duration;break;default:{let v=i.idBlock.isConstructed?new me.Constructed:new me.Primitive;v.idBlock=i.idBlock,v.lenBlock=i.lenBlock,v.warnings=i.warnings,i=v}}break;default:x=i.idBlock.isConstructed?me.Constructed:me.Primitive}return i=aA(i,x),f=i.fromBER(t,e,l,n),i.valueBeforeDecodeView=t.subarray(s,s+i.blockLength),{offset:f,result:i}}function _s(t,e={}){if(!t.byteLength){let r=new Wt({},or);return r.error="Input buffer has zero length",{offset:-1,result:r}}return Hl(ce.toUint8Array(t).slice(),0,t.byteLength,Nu(e))}function cA(t,e){return t?1:e}var Fn=class extends or{constructor({value:e=[],isIndefiniteForm:r=!1,...n}={}){super(n),this.value=e,this.isIndefiniteForm=r}fromBER(e,r,n,s){let i=ce.toUint8Array(e),o=s??Nu();if(!Ts(this,i,r,n))return-1;if(this.valueBeforeDecodeView=i.subarray(r,r+n),this.valueBeforeDecodeView.length===0)return this.warnings.push("Zero buffer length"),r;let a=r;for(;cA(this.isIndefiniteForm,n)>0;){let c=Vp(i,a,n,o);if(c.offset===-1)return this.error=c.result.error,this.warnings.concat(c.result.warnings),-1;if(a=c.offset,this.blockLength+=c.result.blockLength,n-=c.result.blockLength,this.value.push(c.result),this.isIndefiniteForm&&c.result.constructor.NAME===vu)break}return this.isIndefiniteForm&&(this.value[this.value.length-1].constructor.NAME===vu?this.value.pop():this.warnings.push("No EndOfContent block encoded")),a}toBER(e,r){let n=r||new $a;for(let s=0;s<this.value.length;s++)this.value[s].toBER(e,n);return r?$n:n.final()}toJSON(){let e={...super.toJSON(),isIndefiniteForm:this.isIndefiniteForm,value:[]};for(let r of this.value)e.value.push(r.toJSON());return e}};Fn.NAME="ConstructedValueBlock";var zy,Xt=class extends Wt{constructor(e={}){super(e,Fn),this.idBlock.isConstructed=!0}fromBER(e,r,n,s){this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm;let i=this.valueBlock.fromBER(e,r,this.lenBlock.isIndefiniteForm?n:this.lenBlock.length,s);return i===-1?(this.error=this.valueBlock.error,i):(this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.valueBlock.error.length||(this.blockLength+=this.valueBlock.blockLength),i)}onAsciiEncoding(){let e=[];for(let n of this.valueBlock.value)e.push(n.toString("ascii").split(`
110
+ `).map(s=>` ${s}`).join(`
111
+ `));let r=this.idBlock.tagClass===3?`[${this.idBlock.tagNumber}]`:this.constructor.NAME;return e.length?`${r} :
112
+ ${e.join(`
113
+ `)}`:`${r} :`}};zy=Xt;me.Constructed=zy;Xt.NAME="CONSTRUCTED";var Tl=class extends or{fromBER(e,r,n){return r}toBER(e){return $n}};Tl.override="EndOfContentValueBlock";var Fy,Su=class extends Wt{constructor(e={}){super(e,Tl),this.idBlock.tagClass=1,this.idBlock.tagNumber=0}};Fy=Su;me.EndOfContent=Fy;Su.NAME=vu;var Ky,bn=class extends Wt{constructor(e={}){super(e,or),this.idBlock.tagClass=1,this.idBlock.tagNumber=5}fromBER(e,r,n){return this.lenBlock.length>0&&this.warnings.push("Non-zero length of value block for Null type"),this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.blockLength+=n,r+n>e.byteLength?(this.error="End of input reached before message was fully decoded (inconsistent offset and length values)",-1):r+n}toBER(e,r){let n=new ArrayBuffer(2);if(!e){let s=new Uint8Array(n);s[0]=5,s[1]=0}return r&&r.write(n),n}onAsciiEncoding(){return`${this.constructor.NAME}`}};Ky=bn;me.Null=Ky;bn.NAME="NULL";var _l=class extends Wn(or){get value(){for(let e of this.valueHexView)if(e>0)return!0;return!1}set value(e){this.valueHexView[0]=e?255:0}constructor({value:e,...r}={}){super(r),r.valueHex?this.valueHexView=ce.toUint8Array(r.valueHex):this.valueHexView=new Uint8Array(1),e&&(this.value=e)}fromBER(e,r,n){let s=ce.toUint8Array(e);return Ts(this,s,r,n)?(this.valueHexView=s.subarray(r,r+n),n>1&&this.warnings.push("Boolean value encoded in more then 1 octet"),this.isHexOnly=!0,Mp.call(this),this.blockLength=n,r+n):-1}toBER(){return this.valueHexView.slice()}toJSON(){return{...super.toJSON(),value:this.value}}};_l.NAME="BooleanValueBlock";var $y,vo=class extends Wt{getValue(){return this.valueBlock.value}setValue(e){this.valueBlock.value=e}constructor(e={}){super(e,_l),this.idBlock.tagClass=1,this.idBlock.tagNumber=1}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.getValue}`}};$y=vo;me.Boolean=$y;vo.NAME="BOOLEAN";var Bl=class extends Wn(Fn){constructor({isConstructed:e=!1,...r}={}){super(r),this.isConstructed=e}fromBER(e,r,n,s){let i=0;if(this.isConstructed){if(this.isHexOnly=!1,i=Fn.prototype.fromBER.call(this,e,r,n,s),i===-1)return i;for(let o=0;o<this.value.length;o++){let a=this.value[o].constructor.NAME;if(a===vu){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, OCTET STRING may consists of OCTET STRINGs only",-1}if(a!==Uy)return this.error="OCTET STRING may consists of OCTET STRINGs only",-1}}else this.isHexOnly=!0,i=super.fromBER(e,r,n),this.blockLength=n;return i}toBER(e,r){return this.isConstructed?Fn.prototype.toBER.call(this,e,r):e?new ArrayBuffer(this.valueHexView.byteLength):this.valueHexView.slice().buffer}toJSON(){return{...super.toJSON(),isConstructed:this.isConstructed}}};Bl.NAME="OctetStringValueBlock";var zp,vn=class extends Wt{constructor({idBlock:e={},lenBlock:r={},...n}={}){var s,i;(s=n.isConstructed)!==null&&s!==void 0||(n.isConstructed=!!(!((i=n.value)===null||i===void 0)&&i.length)),super({idBlock:{isConstructed:n.isConstructed,...e},lenBlock:{...r,isIndefiniteForm:!!n.isIndefiniteForm},...n},Bl),this.idBlock.tagClass=1,this.idBlock.tagNumber=4}fromBER(e,r,n,s){if(this.valueBlock.isConstructed=this.idBlock.isConstructed,this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm,n===0)return this.idBlock.error.length===0&&(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length===0&&(this.blockLength+=this.lenBlock.blockLength),r;if(!this.valueBlock.isConstructed){let o=(e instanceof ArrayBuffer?new Uint8Array(e):e).subarray(r,r+n);try{if(o.byteLength){let a=s??Nu(),c=Vp(o,0,o.byteLength,a);c.offset!==-1&&c.offset===n&&(this.valueBlock.value=[c.result])}}catch{}}return super.fromBER(e,r,n,s)}onAsciiEncoding(){if(this.valueBlock.isConstructed||this.valueBlock.value&&this.valueBlock.value.length)return Xt.prototype.onAsciiEncoding.call(this);let e=this.constructor.NAME,r=ke.ToHex(this.valueBlock.valueHexView);return`${e} : ${r}`}getValue(){if(!this.idBlock.isConstructed)return this.valueBlock.valueHexView.slice().buffer;let e=[];for(let r of this.valueBlock.value)r instanceof zp&&e.push(r.valueBlock.valueHexView);return ce.concat(e)}};zp=vn;me.OctetString=zp;vn.NAME=Uy;var kl=class extends Wn(Fn){constructor({unusedBits:e=0,isConstructed:r=!1,...n}={}){super(n),this.unusedBits=e,this.isConstructed=r,this.blockLength=this.valueHexView.byteLength}fromBER(e,r,n,s){if(!n)return r;let i=-1;if(this.isConstructed){if(i=Fn.prototype.fromBER.call(this,e,r,n,s),i===-1)return i;for(let c of this.value){let f=c.constructor.NAME;if(f===vu){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, BIT STRING may consists of BIT STRINGs only",-1}if(f!==Dy)return this.error="BIT STRING may consists of BIT STRINGs only",-1;let l=c.valueBlock;if(this.unusedBits>0&&l.unusedBits>0)return this.error='Using of "unused bits" inside constructive BIT STRING allowed for least one only',-1;this.unusedBits=l.unusedBits}return i}let o=ce.toUint8Array(e);if(!Ts(this,o,r,n))return-1;let a=o.subarray(r,r+n);if(this.unusedBits=a[0],this.unusedBits>7)return this.error="Unused bits for BitString must be in range 0-7",-1;if(!this.unusedBits){let c=a.subarray(1);try{if(c.byteLength){let f=s??Nu(),l=Vp(c,0,c.byteLength,f);l.offset!==-1&&l.offset===n-1&&(this.value=[l.result])}}catch{}}return this.valueHexView=a.subarray(1),this.blockLength=a.length,r+n}toBER(e,r){if(this.isConstructed)return Fn.prototype.toBER.call(this,e,r);if(e)return new ArrayBuffer(this.valueHexView.byteLength+1);if(!this.valueHexView.byteLength){let s=new Uint8Array(1);return s[0]=0,s.buffer}let n=new Uint8Array(this.valueHexView.length+1);return n[0]=this.unusedBits,n.set(this.valueHexView,1),n.buffer}toJSON(){return{...super.toJSON(),unusedBits:this.unusedBits,isConstructed:this.isConstructed}}};kl.NAME="BitStringValueBlock";var Wy,wn=class extends Wt{constructor({idBlock:e={},lenBlock:r={},...n}={}){var s,i;(s=n.isConstructed)!==null&&s!==void 0||(n.isConstructed=!!(!((i=n.value)===null||i===void 0)&&i.length)),super({idBlock:{isConstructed:n.isConstructed,...e},lenBlock:{...r,isIndefiniteForm:!!n.isIndefiniteForm},...n},kl),this.idBlock.tagClass=1,this.idBlock.tagNumber=3}fromBER(e,r,n,s){return this.valueBlock.isConstructed=this.idBlock.isConstructed,this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm,super.fromBER(e,r,n,s)}onAsciiEncoding(){if(this.valueBlock.isConstructed||this.valueBlock.value&&this.valueBlock.value.length)return Xt.prototype.onAsciiEncoding.call(this);{let e=[],r=this.valueBlock.valueHexView;for(let o of r)e.push(o.toString(2).padStart(8,"0"));let n=e.join(""),s=this.constructor.NAME,i=n.substring(0,n.length-this.valueBlock.unusedBits);return`${s} : ${i}`}}};Wy=wn;me.BitString=Wy;wn.NAME=Dy;var Gy;function uA(t,e){let r=new Uint8Array([0]),n=new Uint8Array(t),s=new Uint8Array(e),i=n.slice(0),o=i.length-1,a=s.slice(0),c=a.length-1,f=0,l=c<o?o:c,p=0;for(let x=l;x>=0;x--,p++)!0===p<a.length?f=i[o-p]+a[c-p]+r[0]:f=i[o-p]+r[0],r[0]=f/10,!0===p>=i.length?i=Sl(new Uint8Array([f%10]),i):i[o-p]=f%10;return r[0]>0&&(i=Sl(r,i)),i}function Ly(t){if(t>=yu.length)for(let e=yu.length;e<=t;e++){let r=new Uint8Array([0]),n=yu[e-1].slice(0);for(let s=n.length-1;s>=0;s--){let i=new Uint8Array([(n[s]<<1)+r[0]]);r[0]=i[0]/10,n[s]=i[0]%10}r[0]>0&&(n=Sl(r,n)),yu.push(n)}return yu[t]}function fA(t,e){let r=0,n=new Uint8Array(t),s=new Uint8Array(e),i=n.slice(0),o=i.length-1,a=s.slice(0),c=a.length-1,f,l=0;for(let p=c;p>=0;p--,l++)f=i[o-l]-a[c-l]-r,!0===f<0?(r=1,i[o-l]=f+10):(r=0,i[o-l]=f);if(r>0)for(let p=o-c+1;p>=0;p--,l++)if(f=i[o-l]-r,f<0)r=1,i[o-l]=f+10;else{r=0,i[o-l]=f;break}return i.slice()}var Eu=class extends Wn(or){setValueHex(){this.valueHexView.length>=4?(this.warnings.push("Too big Integer for decoding, hex only"),this.isHexOnly=!0,this._valueDec=0):(this.isHexOnly=!1,this.valueHexView.length>0&&(this._valueDec=Mp.call(this)))}constructor({value:e,...r}={}){super(r),this._valueDec=0,r.valueHex&&this.setValueHex(),e!==void 0&&(this.valueDec=e)}set valueDec(e){this._valueDec=e,this.isHexOnly=!1,this.valueHexView=new Uint8Array(Ry(e))}get valueDec(){return this._valueDec}fromDER(e,r,n,s=0){let i=this.fromBER(e,r,n);if(i===-1)return i;let o=this.valueHexView;return o[0]===0&&(o[1]&128)!==0?this.valueHexView=o.subarray(1):s!==0&&o.length<s&&(s-o.length>1&&(s=o.length+1),this.valueHexView=o.subarray(s-o.length)),i}toDER(e=!1){let r=this.valueHexView;switch(!0){case(r[0]&128)!==0:{let n=new Uint8Array(this.valueHexView.length+1);n[0]=0,n.set(r,1),this.valueHexView=n}break;case(r[0]===0&&(r[1]&128)===0):this.valueHexView=this.valueHexView.subarray(1);break}return this.toBER(e)}fromBER(e,r,n){let s=super.fromBER(e,r,n);return s===-1||this.setValueHex(),s}toBER(e){return e?new ArrayBuffer(this.valueHexView.length):this.valueHexView.slice().buffer}toJSON(){return{...super.toJSON(),valueDec:this.valueDec}}toString(){let e=this.valueHexView.length*8-1,r=new Uint8Array(this.valueHexView.length*8/3),n=0,s,i=this.valueHexView,o="",a=!1;for(let c=i.byteLength-1;c>=0;c--){s=i[c];for(let f=0;f<8;f++)(s&1)===1&&(n===e?(r=fA(Ly(n),r),o="-"):r=uA(r,Ly(n))),n++,s>>=1}for(let c=0;c<r.length;c++)r[c]&&(a=!0),a&&(o+=Py.charAt(r[c]));return a===!1&&(o+=Py.charAt(0)),o}};Gy=Eu;Eu.NAME="IntegerValueBlock";Object.defineProperty(Gy.prototype,"valueHex",{set:function(t){this.valueHexView=new Uint8Array(t),this.setValueHex()},get:function(){return this.valueHexView.slice().buffer}});var bu,Is=class extends Wt{constructor(e={}){super(e,Eu),this.idBlock.tagClass=1,this.idBlock.tagNumber=2}toBigInt(){return El(),BigInt(this.valueBlock.toString())}static fromBigInt(e){El();let r=BigInt(e),n=new $a,s=r.toString(16).replace(/^-/,""),i=new Uint8Array(ke.FromHex(s));if(r<0){let a=new Uint8Array(i.length+(i[0]&128?1:0));a[0]|=128;let f=BigInt(`0x${ke.ToHex(a)}`)+r,l=ce.toUint8Array(ke.FromHex(f.toString(16)));l[0]|=128,n.write(l)}else i[0]&128&&n.write(new Uint8Array([0])),n.write(i);return new bu({valueHex:n.final()})}convertToDER(){let e=new bu({valueHex:this.valueBlock.valueHexView});return e.valueBlock.toDER(),e}convertFromDER(){return new bu({valueHex:this.valueBlock.valueHexView[0]===0?this.valueBlock.valueHexView.subarray(1):this.valueBlock.valueHexView})}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()}`}};bu=Is;me.Integer=bu;Is.NAME="INTEGER";var Xy,wo=class extends Is{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=10}};Xy=wo;me.Enumerated=Xy;wo.NAME="ENUMERATED";var Au=class extends Wn(or){constructor({valueDec:e=-1,isFirstSid:r=!1,...n}={}){super(n),this.valueDec=e,this.isFirstSid=r}fromBER(e,r,n){if(!n)return r;let s=ce.toUint8Array(e);if(!Ts(this,s,r,n))return-1;let i=s.subarray(r,r+n);this.valueHexView=new Uint8Array(n);for(let a=0;a<n&&(this.valueHexView[a]=i[a]&127,this.blockLength++,(i[a]&128)!==0);a++);let o=new Uint8Array(this.blockLength);for(let a=0;a<this.blockLength;a++)o[a]=this.valueHexView[a];return this.valueHexView=o,(i[this.blockLength-1]&128)!==0?(this.error="End of input reached before message was fully decoded",-1):(this.valueHexView[0]===0&&this.warnings.push("Needlessly long format of SID encoding"),this.blockLength<=8?this.valueDec=bo(this.valueHexView,7):(this.isHexOnly=!0,this.warnings.push("Too big SID for decoding, hex only")),r+this.blockLength)}set valueBigInt(e){El();let r=BigInt(e).toString(2);for(;r.length%7;)r="0"+r;let n=new Uint8Array(r.length/7);for(let s=0;s<n.length;s++)n[s]=parseInt(r.slice(s*7,s*7+7),2)+(s+1<n.length?128:0);this.fromBER(n.buffer,0,n.length)}toBER(e){if(this.isHexOnly){if(e)return new ArrayBuffer(this.valueHexView.byteLength);let s=this.valueHexView,i=new Uint8Array(this.blockLength);for(let o=0;o<this.blockLength-1;o++)i[o]=s[o]|128;return i[this.blockLength-1]=s[this.blockLength-1],i.buffer}let r=bi(this.valueDec,7);if(r.byteLength===0)return this.error="Error during encoding SID value",$n;let n=new Uint8Array(r.byteLength);if(!e){let s=new Uint8Array(r),i=r.byteLength-1;for(let o=0;o<i;o++)n[o]=s[o]|128;n[i]=s[i]}return n}toString(){let e="";if(this.isHexOnly)e=ke.ToHex(this.valueHexView);else if(this.isFirstSid){let r=this.valueDec;this.valueDec<=39?e="0.":this.valueDec<=79?(e="1.",r-=40):(e="2.",r-=80),e+=r.toString()}else e=this.valueDec.toString();return e}toJSON(){return{...super.toJSON(),valueDec:this.valueDec,isFirstSid:this.isFirstSid}}};Au.NAME="sidBlock";var Rl=class extends or{constructor({value:e=Lr,...r}={}){super(r),this.value=[],e&&this.fromString(e)}fromBER(e,r,n){let s=r;for(;n>0;){let i=new Au;if(s=i.fromBER(e,s,n),s===-1)return this.blockLength=0,this.error=i.error,s;this.value.length===0&&(i.isFirstSid=!0),this.blockLength+=i.blockLength,n-=i.blockLength,this.value.push(i)}return s}toBER(e){let r=[];for(let n=0;n<this.value.length;n++){let s=this.value[n].toBER(e);if(s.byteLength===0)return this.error=this.value[n].error,$n;r.push(s)}return qp(r)}fromString(e){this.value=[];let r=0,n=0,s="",i=!1;do if(n=e.indexOf(".",r),n===-1?s=e.substring(r):s=e.substring(r,n),r=n+1,i){let o=this.value[0],a=0;switch(o.valueDec){case 0:break;case 1:a=40;break;case 2:a=80;break;default:this.value=[];return}let c=parseInt(s,10);if(isNaN(c))return;o.valueDec=c+a,i=!1}else{let o=new Au;if(s>Number.MAX_SAFE_INTEGER){El();let a=BigInt(s);o.valueBigInt=a}else if(o.valueDec=parseInt(s,10),isNaN(o.valueDec))return;this.value.length||(o.isFirstSid=!0,i=!0),this.value.push(o)}while(n!==-1)}toString(){let e="",r=!1;for(let n=0;n<this.value.length;n++){r=this.value[n].isHexOnly;let s=this.value[n].toString();n!==0&&(e=`${e}.`),r?(s=`{${s}}`,this.value[n].isFirstSid?e=`2.{${s} - 80}`:e+=s):e+=s}return e}toJSON(){let e={...super.toJSON(),value:this.toString(),sidArray:[]};for(let r=0;r<this.value.length;r++)e.sidArray.push(this.value[r].toJSON());return e}};Rl.NAME="ObjectIdentifierValueBlock";var Yy,So=class extends Wt{getValue(){return this.valueBlock.toString()}setValue(e){this.valueBlock.fromString(e)}constructor(e={}){super(e,Rl),this.idBlock.tagClass=1,this.idBlock.tagNumber=6}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()||"empty"}`}toJSON(){return{...super.toJSON(),value:this.getValue()}}};Yy=So;me.ObjectIdentifier=Yy;So.NAME="OBJECT IDENTIFIER";var Cu=class extends Wn(As){constructor({valueDec:e=0,...r}={}){super(r),this.valueDec=e}fromBER(e,r,n){if(n===0)return r;let s=ce.toUint8Array(e);if(!Ts(this,s,r,n))return-1;let i=s.subarray(r,r+n);this.valueHexView=new Uint8Array(n);for(let a=0;a<n&&(this.valueHexView[a]=i[a]&127,this.blockLength++,(i[a]&128)!==0);a++);let o=new Uint8Array(this.blockLength);for(let a=0;a<this.blockLength;a++)o[a]=this.valueHexView[a];return this.valueHexView=o,(i[this.blockLength-1]&128)!==0?(this.error="End of input reached before message was fully decoded",-1):(this.valueHexView[0]===0&&this.warnings.push("Needlessly long format of SID encoding"),this.blockLength<=8?this.valueDec=bo(this.valueHexView,7):(this.isHexOnly=!0,this.warnings.push("Too big SID for decoding, hex only")),r+this.blockLength)}toBER(e){if(this.isHexOnly){if(e)return new ArrayBuffer(this.valueHexView.byteLength);let s=this.valueHexView,i=new Uint8Array(this.blockLength);for(let o=0;o<this.blockLength-1;o++)i[o]=s[o]|128;return i[this.blockLength-1]=s[this.blockLength-1],i.buffer}let r=bi(this.valueDec,7);if(r.byteLength===0)return this.error="Error during encoding SID value",$n;let n=new Uint8Array(r.byteLength);if(!e){let s=new Uint8Array(r),i=r.byteLength-1;for(let o=0;o<i;o++)n[o]=s[o]|128;n[i]=s[i]}return n.buffer}toString(){let e="";return this.isHexOnly?e=ke.ToHex(this.valueHexView):e=this.valueDec.toString(),e}toJSON(){return{...super.toJSON(),valueDec:this.valueDec}}};Cu.NAME="relativeSidBlock";var Nl=class extends or{constructor({value:e=Lr,...r}={}){super(r),this.value=[],e&&this.fromString(e)}fromBER(e,r,n){let s=r;for(;n>0;){let i=new Cu;if(s=i.fromBER(e,s,n),s===-1)return this.blockLength=0,this.error=i.error,s;this.blockLength+=i.blockLength,n-=i.blockLength,this.value.push(i)}return s}toBER(e,r){let n=[];for(let s=0;s<this.value.length;s++){let i=this.value[s].toBER(e);if(i.byteLength===0)return this.error=this.value[s].error,$n;n.push(i)}return qp(n)}fromString(e){this.value=[];let r=0,n=0,s="";do{n=e.indexOf(".",r),n===-1?s=e.substring(r):s=e.substring(r,n),r=n+1;let i=new Cu;if(i.valueDec=parseInt(s,10),isNaN(i.valueDec))return!0;this.value.push(i)}while(n!==-1);return!0}toString(){let e="",r=!1;for(let n=0;n<this.value.length;n++){r=this.value[n].isHexOnly;let s=this.value[n].toString();n!==0&&(e=`${e}.`),r&&(s=`{${s}}`),e+=s}return e}toJSON(){let e={...super.toJSON(),value:this.toString(),sidArray:[]};for(let r=0;r<this.value.length;r++)e.sidArray.push(this.value[r].toJSON());return e}};Nl.NAME="RelativeObjectIdentifierValueBlock";var Zy,Iu=class extends Wt{getValue(){return this.valueBlock.toString()}setValue(e){this.valueBlock.fromString(e)}constructor(e={}){super(e,Nl),this.idBlock.tagClass=1,this.idBlock.tagNumber=13}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()||"empty"}`}toJSON(){return{...super.toJSON(),value:this.getValue()}}};Zy=Iu;me.RelativeObjectIdentifier=Zy;Iu.NAME="RelativeObjectIdentifier";var Jy,Er=class extends Xt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=16}};Jy=Er;me.Sequence=Jy;Er.NAME="SEQUENCE";var Qy,Br=class extends Xt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=17}};Qy=Br;me.Set=Qy;Br.NAME="SET";var Pl=class extends Wn(or){constructor({...e}={}){super(e),this.isHexOnly=!0,this.value=Lr}toJSON(){return{...super.toJSON(),value:this.value}}};Pl.NAME="StringValueBlock";var Ol=class extends Pl{};Ol.NAME="SimpleStringValueBlock";var kr=class extends wu{constructor({...e}={}){super(e,Ol)}fromBuffer(e){this.valueBlock.value=String.fromCharCode.apply(null,ce.toUint8Array(e))}fromString(e){let r=e.length,n=this.valueBlock.valueHexView=new Uint8Array(r);for(let s=0;s<r;s++)n[s]=e.charCodeAt(s);this.valueBlock.value=e}};kr.NAME="SIMPLE STRING";var Ll=class extends kr{fromBuffer(e){this.valueBlock.valueHexView=ce.toUint8Array(e);try{this.valueBlock.value=ke.ToUtf8String(e)}catch(r){this.warnings.push(`Error during "decodeURIComponent": ${r}, using raw string`),this.valueBlock.value=ke.ToBinary(e)}}fromString(e){this.valueBlock.valueHexView=new Uint8Array(ke.FromUtf8String(e)),this.valueBlock.value=e}};Ll.NAME="Utf8StringValueBlock";var eb,an=class extends Ll{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=12}};eb=an;me.Utf8String=eb;an.NAME="UTF8String";var Ul=class extends kr{fromBuffer(e){this.valueBlock.value=ke.ToUtf16String(e),this.valueBlock.valueHexView=ce.toUint8Array(e)}fromString(e){this.valueBlock.value=e,this.valueBlock.valueHexView=new Uint8Array(ke.FromUtf16String(e))}};Ul.NAME="BmpStringValueBlock";var tb,Eo=class extends Ul{constructor({...e}={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=30}};tb=Eo;me.BmpString=tb;Eo.NAME="BMPString";var Dl=class extends kr{fromBuffer(e){let r=ArrayBuffer.isView(e)?e.slice().buffer:e.slice(0),n=new Uint8Array(r);for(let s=0;s<n.length;s+=4)n[s]=n[s+3],n[s+1]=n[s+2],n[s+2]=0,n[s+3]=0;this.valueBlock.value=String.fromCharCode.apply(null,new Uint32Array(r))}fromString(e){let r=e.length,n=this.valueBlock.valueHexView=new Uint8Array(r*4);for(let s=0;s<r;s++){let i=bi(e.charCodeAt(s),8),o=new Uint8Array(i);if(o.length>4)continue;let a=4-o.length;for(let c=o.length-1;c>=0;c--)n[s*4+c+a]=o[c]}this.valueBlock.value=e}};Dl.NAME="UniversalStringValueBlock";var rb,Ao=class extends Dl{constructor({...e}={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=28}};rb=Ao;me.UniversalString=rb;Ao.NAME="UniversalString";var nb,Co=class extends kr{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=18}};nb=Co;me.NumericString=nb;Co.NAME="NumericString";var sb,Io=class extends kr{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=19}};sb=Io;me.PrintableString=sb;Io.NAME="PrintableString";var ib,To=class extends kr{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=20}};ib=To;me.TeletexString=ib;To.NAME="TeletexString";var ob,_o=class extends kr{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=21}};ob=_o;me.VideotexString=ob;_o.NAME="VideotexString";var ab,Bo=class extends kr{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=22}};ab=Bo;me.IA5String=ab;Bo.NAME="IA5String";var cb,ko=class extends kr{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=25}};cb=ko;me.GraphicString=cb;ko.NAME="GraphicString";var ub,vi=class extends kr{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=26}};ub=vi;me.VisibleString=ub;vi.NAME="VisibleString";var fb,Ro=class extends kr{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=27}};fb=Ro;me.GeneralString=fb;Ro.NAME="GeneralString";var db,No=class extends kr{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=29}};db=No;me.CharacterString=db;No.NAME="CharacterString";var lb,wi=class extends vi{constructor({value:e,valueDate:r,...n}={}){if(super(n),this.year=0,this.month=0,this.day=0,this.hour=0,this.minute=0,this.second=0,e){this.fromString(e),this.valueBlock.valueHexView=new Uint8Array(e.length);for(let s=0;s<e.length;s++)this.valueBlock.valueHexView[s]=e.charCodeAt(s)}r&&(this.fromDate(r),this.valueBlock.valueHexView=new Uint8Array(this.toBuffer())),this.idBlock.tagClass=1,this.idBlock.tagNumber=23}fromBuffer(e){this.fromString(String.fromCharCode.apply(null,ce.toUint8Array(e)))}toBuffer(){let e=this.toString(),r=new ArrayBuffer(e.length),n=new Uint8Array(r);for(let s=0;s<e.length;s++)n[s]=e.charCodeAt(s);return r}fromDate(e){this.year=e.getUTCFullYear(),this.month=e.getUTCMonth()+1,this.day=e.getUTCDate(),this.hour=e.getUTCHours(),this.minute=e.getUTCMinutes(),this.second=e.getUTCSeconds()}toDate(){return new Date(Date.UTC(this.year,this.month-1,this.day,this.hour,this.minute,this.second))}fromString(e){let n=/(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})Z/ig.exec(e);if(n===null){this.error="Wrong input string for conversion";return}let s=parseInt(n[1],10);s>=50?this.year=1900+s:this.year=2e3+s,this.month=parseInt(n[2],10),this.day=parseInt(n[3],10),this.hour=parseInt(n[4],10),this.minute=parseInt(n[5],10),this.second=parseInt(n[6],10)}toString(e="iso"){if(e==="iso"){let r=new Array(7);return r[0]=Or(this.year<2e3?this.year-1900:this.year-2e3,2),r[1]=Or(this.month,2),r[2]=Or(this.day,2),r[3]=Or(this.hour,2),r[4]=Or(this.minute,2),r[5]=Or(this.second,2),r[6]="Z",r.join("")}return super.toString(e)}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.toDate().toISOString()}`}toJSON(){return{...super.toJSON(),year:this.year,month:this.month,day:this.day,hour:this.hour,minute:this.minute,second:this.second}}};lb=wi;me.UTCTime=lb;wi.NAME="UTCTime";var hb,Po=class extends wi{constructor(e={}){var r;super(e),(r=this.millisecond)!==null&&r!==void 0||(this.millisecond=0),this.idBlock.tagClass=1,this.idBlock.tagNumber=24}fromDate(e){super.fromDate(e),this.millisecond=e.getUTCMilliseconds()}toDate(){let e=Date.UTC(this.year,this.month-1,this.day,this.hour,this.minute,this.second,this.millisecond);return new Date(e)}fromString(e){let r=!1,n="",s="",i=0,o,a=0,c=0;if(e[e.length-1]==="Z")n=e.substring(0,e.length-1),r=!0;else{let p=new Number(e[e.length-1]);if(isNaN(p.valueOf()))throw new Error("Wrong input string for conversion");n=e}if(r){if(n.indexOf("+")!==-1)throw new Error("Wrong input string for conversion");if(n.indexOf("-")!==-1)throw new Error("Wrong input string for conversion")}else{let p=1,x=n.indexOf("+"),v="";if(x===-1&&(x=n.indexOf("-"),p=-1),x!==-1){if(v=n.substring(x+1),n=n.substring(0,x),v.length!==2&&v.length!==4)throw new Error("Wrong input string for conversion");let S=parseInt(v.substring(0,2),10);if(isNaN(S.valueOf()))throw new Error("Wrong input string for conversion");if(a=p*S,v.length===4){if(S=parseInt(v.substring(2,4),10),isNaN(S.valueOf()))throw new Error("Wrong input string for conversion");c=p*S}}}let f=n.indexOf(".");if(f===-1&&(f=n.indexOf(",")),f!==-1){let p=new Number(`0${n.substring(f)}`);if(isNaN(p.valueOf()))throw new Error("Wrong input string for conversion");i=p.valueOf(),s=n.substring(0,f)}else s=n;switch(!0){case s.length===8:if(o=/(\d{4})(\d{2})(\d{2})/ig,f!==-1)throw new Error("Wrong input string for conversion");break;case s.length===10:if(o=/(\d{4})(\d{2})(\d{2})(\d{2})/ig,f!==-1){let p=60*i;this.minute=Math.floor(p),p=60*(p-this.minute),this.second=Math.floor(p),p=1e3*(p-this.second),this.millisecond=Math.floor(p)}break;case s.length===12:if(o=/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})/ig,f!==-1){let p=60*i;this.second=Math.floor(p),p=1e3*(p-this.second),this.millisecond=Math.floor(p)}break;case s.length===14:if(o=/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/ig,f!==-1){let p=1e3*i;this.millisecond=Math.floor(p)}break;default:throw new Error("Wrong input string for conversion")}let l=o.exec(s);if(l===null)throw new Error("Wrong input string for conversion");for(let p=1;p<l.length;p++)switch(p){case 1:this.year=parseInt(l[p],10);break;case 2:this.month=parseInt(l[p],10);break;case 3:this.day=parseInt(l[p],10);break;case 4:this.hour=parseInt(l[p],10)+a;break;case 5:this.minute=parseInt(l[p],10)+c;break;case 6:this.second=parseInt(l[p],10);break;default:throw new Error("Wrong input string for conversion")}if(r===!1){let p=new Date(this.year,this.month,this.day,this.hour,this.minute,this.second,this.millisecond);this.year=p.getUTCFullYear(),this.month=p.getUTCMonth(),this.day=p.getUTCDay(),this.hour=p.getUTCHours(),this.minute=p.getUTCMinutes(),this.second=p.getUTCSeconds(),this.millisecond=p.getUTCMilliseconds()}}toString(e="iso"){if(e==="iso"){let r=[];return r.push(Or(this.year,4)),r.push(Or(this.month,2)),r.push(Or(this.day,2)),r.push(Or(this.hour,2)),r.push(Or(this.minute,2)),r.push(Or(this.second,2)),this.millisecond!==0&&(r.push("."),r.push(Or(this.millisecond,3))),r.push("Z"),r.join("")}return super.toString(e)}toJSON(){return{...super.toJSON(),millisecond:this.millisecond}}};hb=Po;me.GeneralizedTime=hb;Po.NAME="GeneralizedTime";var pb,Tu=class extends an{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=31}};pb=Tu;me.DATE=pb;Tu.NAME="DATE";var xb,_u=class extends an{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=32}};xb=_u;me.TimeOfDay=xb;_u.NAME="TimeOfDay";var mb,Bu=class extends an{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=33}};mb=Bu;me.DateTime=mb;Bu.NAME="DateTime";var gb,ku=class extends an{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=34}};gb=ku;me.Duration=gb;ku.NAME="Duration";var yb,Ru=class extends an{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=14}};yb=Ru;me.TIME=yb;Ru.NAME="TIME";var Kn=class{constructor({name:e=Lr,optional:r=!1}={}){this.name=e,this.optional=r}},Wa=class extends Kn{constructor({value:e=[],...r}={}){super(r),this.value=e}},Oo=class extends Kn{constructor({value:e=new Kn,local:r=!1,...n}={}){super(n),this.value=e,this.local=r}},jp=class{get data(){return this.dataView.slice().buffer}set data(e){this.dataView=ce.toUint8Array(e)}constructor({data:e=Ml}={}){this.dataView=ce.toUint8Array(e)}fromBER(e,r,n){let s=r+n;return this.dataView=ce.toUint8Array(e).subarray(r,s),s}toBER(e){return this.dataView.slice().buffer}};function Es(t,e,r){if(r instanceof Wa){for(let i of r.value)if(Es(t,e,i).verified)return{verified:!0,result:t};{let i={verified:!1,result:{error:"Wrong values for Choice type"}};return r.hasOwnProperty(Hp)&&(i.name=r.name),i}}if(r instanceof Kn)return r.hasOwnProperty(Hp)&&(t[r.name]=e),{verified:!0,result:t};if(!(t instanceof Object))return{verified:!1,result:{error:"Wrong root object"}};if(!(e instanceof Object))return{verified:!1,result:{error:"Wrong ASN.1 data"}};if(!(r instanceof Object))return{verified:!1,result:{error:"Wrong ASN.1 schema"}};if(!(GE in r))return{verified:!1,result:{error:"Wrong ASN.1 schema"}};if(!(JE in r.idBlock))return{verified:!1,result:{error:"Wrong ASN.1 schema"}};if(!(QE in r.idBlock))return{verified:!1,result:{error:"Wrong ASN.1 schema"}};let n=r.idBlock.toBER(!1);if(n.byteLength===0)return{verified:!1,result:{error:"Error encoding idBlock for ASN.1 schema"}};if(r.idBlock.fromBER(n,0,n.byteLength)===-1)return{verified:!1,result:{error:"Error decoding idBlock for ASN.1 schema"}};if(r.idBlock.hasOwnProperty(XE)===!1)return{verified:!1,result:{error:"Wrong ASN.1 schema"}};if(r.idBlock.tagClass!==e.idBlock.tagClass)return{verified:!1,result:t};if(r.idBlock.hasOwnProperty(YE)===!1)return{verified:!1,result:{error:"Wrong ASN.1 schema"}};if(r.idBlock.tagNumber!==e.idBlock.tagNumber)return{verified:!1,result:t};if(r.idBlock.hasOwnProperty(ZE)===!1)return{verified:!1,result:{error:"Wrong ASN.1 schema"}};if(r.idBlock.isConstructed!==e.idBlock.isConstructed)return{verified:!1,result:t};if(!(WE in r.idBlock))return{verified:!1,result:{error:"Wrong ASN.1 schema"}};if(r.idBlock.isHexOnly!==e.idBlock.isHexOnly)return{verified:!1,result:t};if(r.idBlock.isHexOnly){if(!(Oy in r.idBlock))return{verified:!1,result:{error:"Wrong ASN.1 schema"}};let i=r.idBlock.valueHexView,o=e.idBlock.valueHexView;if(i.length!==o.length)return{verified:!1,result:t};for(let a=0;a<i.length;a++)if(i[a]!==o[1])return{verified:!1,result:t}}if(r.name&&(r.name=r.name.replace(/^\s+|\s+$/g,Lr),r.name&&(t[r.name]=e)),r instanceof me.Constructed){let i=0,o={verified:!1,result:{error:"Unknown error"}},a=r.valueBlock.value.length;if(a>0&&r.valueBlock.value[0]instanceof Oo&&(a=e.valueBlock.value.length),a===0)return{verified:!0,result:t};if(e.valueBlock.value.length===0&&r.valueBlock.value.length!==0){let c=!0;for(let f=0;f<r.valueBlock.value.length;f++)c=c&&(r.valueBlock.value[f].optional||!1);return c?{verified:!0,result:t}:(r.name&&(r.name=r.name.replace(/^\s+|\s+$/g,Lr),r.name&&delete t[r.name]),t.error="Inconsistent object length",{verified:!1,result:t})}for(let c=0;c<a;c++)if(c-i>=e.valueBlock.value.length){if(r.valueBlock.value[c].optional===!1){let f={verified:!1,result:t};return t.error="Inconsistent length between ASN.1 data and schema",r.name&&(r.name=r.name.replace(/^\s+|\s+$/g,Lr),r.name&&(delete t[r.name],f.name=r.name)),f}}else if(r.valueBlock.value[0]instanceof Oo){if(o=Es(t,e.valueBlock.value[c],r.valueBlock.value[0].value),o.verified===!1)if(r.valueBlock.value[0].optional)i++;else return r.name&&(r.name=r.name.replace(/^\s+|\s+$/g,Lr),r.name&&delete t[r.name]),o;if(Hp in r.valueBlock.value[0]&&r.valueBlock.value[0].name.length>0){let f={};eA in r.valueBlock.value[0]&&r.valueBlock.value[0].local?f=e:f=t,typeof f[r.valueBlock.value[0].name]>"u"&&(f[r.valueBlock.value[0].name]=[]),f[r.valueBlock.value[0].name].push(e.valueBlock.value[c])}}else if(o=Es(t,e.valueBlock.value[c-i],r.valueBlock.value[c]),o.verified===!1)if(r.valueBlock.value[c].optional)i++;else return r.name&&(r.name=r.name.replace(/^\s+|\s+$/g,Lr),r.name&&delete t[r.name]),o;if(o.verified===!1){let c={verified:!1,result:t};return r.name&&(r.name=r.name.replace(/^\s+|\s+$/g,Lr),r.name&&(delete t[r.name],c.name=r.name)),c}return{verified:!0,result:t}}if(r.primitiveSchema&&Oy in e.valueBlock){let i=Hl(e.valueBlock.valueHexView);if(i.offset===-1){let o={verified:!1,result:i.result};return r.name&&(r.name=r.name.replace(/^\s+|\s+$/g,Lr),r.name&&(delete t[r.name],o.name=r.name)),o}return Es(t,i.result,r.primitiveSchema)}return{verified:!0,result:t}}function dA(t,e){if(!(e instanceof Object))return{verified:!1,result:{error:"Wrong ASN.1 schema type"}};let r=Hl(ce.toUint8Array(t));return r.offset===-1?{verified:!1,result:r.result}:Es(r.result,r.result,e)}var lA="[object ArrayBuffer]",hA="[object SharedArrayBuffer]";function bb(t){return Object.prototype.toString.call(t)}function pA(t){if(ArrayBuffer.isView(t))return!0;if(!t||typeof t!="object")return!1;let e=t;return typeof e.byteOffset=="number"&&typeof e.byteLength=="number"&&jl(e.buffer)}function Fp(t){return bb(t)===lA}function vb(t){return typeof SharedArrayBuffer<"u"&&bb(t)===hA}function jl(t){return Fp(t)||vb(t)}function wb(t){return pA(t)}function Bs(t){return jl(t)||wb(t)}function Kp(t){if(!Bs(t))throw new TypeError("Expected ArrayBuffer, SharedArrayBuffer, or ArrayBufferView")}function cn(t){return Kp(t),jl(t)?new Uint8Array(t):new Uint8Array(t.buffer,t.byteOffset,t.byteLength)}function nr(t){if(Kp(t),Fp(t))return t;let e=new ArrayBuffer(t.byteLength);return new Uint8Array(e).set(cn(t)),e}function $p(t,e,r={}){let n=cn(t),s=cn(e);if(!r.constantTime&&n.byteLength!==s.byteLength)return!1;let i=Math.max(n.byteLength,s.byteLength),o=n.byteLength^s.byteLength;for(let a=0;a<i;a++)o|=(n[a]??0)^(s[a]??0);return o===0}var k;(function(t){t[t.Sequence=0]="Sequence",t[t.Set=1]="Set",t[t.Choice=2]="Choice"})(k||(k={}));var w;(function(t){t[t.Any=1]="Any",t[t.Boolean=2]="Boolean",t[t.OctetString=3]="OctetString",t[t.BitString=4]="BitString",t[t.Integer=5]="Integer",t[t.Enumerated=6]="Enumerated",t[t.ObjectIdentifier=7]="ObjectIdentifier",t[t.Utf8String=8]="Utf8String",t[t.BmpString=9]="BmpString",t[t.UniversalString=10]="UniversalString",t[t.NumericString=11]="NumericString",t[t.PrintableString=12]="PrintableString",t[t.TeletexString=13]="TeletexString",t[t.VideotexString=14]="VideotexString",t[t.IA5String=15]="IA5String",t[t.GraphicString=16]="GraphicString",t[t.VisibleString=17]="VisibleString",t[t.GeneralString=18]="GeneralString",t[t.CharacterString=19]="CharacterString",t[t.UTCTime=20]="UTCTime",t[t.GeneralizedTime=21]="GeneralizedTime",t[t.DATE=22]="DATE",t[t.TimeOfDay=23]="TimeOfDay",t[t.DateTime=24]="DateTime",t[t.Duration=25]="Duration",t[t.TIME=26]="TIME",t[t.Null=27]="Null"})(w||(w={}));var Xn=class{unusedBits=0;value=new ArrayBuffer(0);constructor(e,r=0){if(e)if(typeof e=="number")this.fromNumber(e);else if(Bs(e))this.unusedBits=r,this.value=nr(e);else throw TypeError("Unsupported type of 'params' argument for BitString")}fromASN(e){if(!(e instanceof wn))throw new TypeError("Argument 'asn' is not instance of ASN.1 BitString");return this.unusedBits=e.valueBlock.unusedBits,this.value=nr(e.valueBlock.valueHex),this}toASN(){return new wn({unusedBits:this.unusedBits,valueHex:this.value})}toSchema(e){return new wn({name:e})}toNumber(){let e="",r=new Uint8Array(this.value);for(let n of r)e+=n.toString(2).padStart(8,"0");return e=e.split("").reverse().join(""),this.unusedBits&&(e=e.slice(this.unusedBits).padStart(this.unusedBits,"0")),parseInt(e,2)}fromNumber(e){let r=e.toString(2),n=r.length+7>>3;this.unusedBits=(n<<3)-r.length;let s=new Uint8Array(n);r=r.padStart(n<<3,"0").split("").reverse().join("");let i=0;for(;i<n;)s[i]=parseInt(r.slice(i<<3,(i<<3)+8),2),i++;this.value=s.buffer}};var Le=class{buffer;get byteLength(){return this.buffer.byteLength}get byteOffset(){return 0}constructor(e){typeof e=="number"?this.buffer=new ArrayBuffer(e):Bs(e)?this.buffer=nr(e):Array.isArray(e)?this.buffer=new Uint8Array(e).buffer:this.buffer=new ArrayBuffer(0)}fromASN(e){if(!(e instanceof vn))throw new TypeError("Argument 'asn' is not instance of ASN.1 OctetString");return this.buffer=nr(e.valueBlock.valueHex),this}toASN(){return new vn({valueHex:this.buffer})}toSchema(e){return new vn({name:e})}};var gA={fromASN:t=>t instanceof bn?null:nr(t.valueBeforeDecodeView),toASN:t=>{if(t===null)return new bn;let e=_s(t);if(e.result.error)throw new Error(e.result.error);return e.result}},yA={fromASN:t=>t.valueBlock.valueHexView.byteLength>=4?t.valueBlock.toString():t.valueBlock.valueDec,toASN:t=>new Is({value:+t})},bA={fromASN:t=>t.valueBlock.valueDec,toASN:t=>new wo({value:t})},pt={fromASN:t=>nr(t.valueBlock.valueHexView),toASN:t=>new Is({valueHex:t})};var vA={fromASN:t=>nr(t.valueBlock.valueHexView),toASN:t=>new wn({valueHex:t})},wA={fromASN:t=>t.valueBlock.toString(),toASN:t=>new So({value:t})},SA={fromASN:t=>t.valueBlock.value,toASN:t=>new vo({value:t})},Ga={fromASN:t=>nr(t.valueBlock.valueHexView),toASN:t=>new vn({valueHex:t})},Sb={fromASN:t=>new Le(t.getValue()),toASN:t=>t.toASN()};function un(t){return{fromASN:e=>e.valueBlock.value,toASN:e=>new t({value:e})}}var Wp=un(an),EA=un(Eo),AA=un(Ao),CA=un(Co),IA=un(Io),TA=un(To),_A=un(_o),BA=un(Bo),kA=un(ko),RA=un(vi),NA=un(Ro),PA=un(No),OA={fromASN:t=>t.toDate(),toASN:t=>new wi({valueDate:t})},LA={fromASN:t=>t.toDate(),toASN:t=>new Po({valueDate:t})},UA={fromASN:()=>null,toASN:()=>new bn};function Si(t){switch(t){case w.Any:return gA;case w.BitString:return vA;case w.BmpString:return EA;case w.Boolean:return SA;case w.CharacterString:return PA;case w.Enumerated:return bA;case w.GeneralString:return NA;case w.GeneralizedTime:return LA;case w.GraphicString:return kA;case w.IA5String:return BA;case w.Integer:return yA;case w.Null:return UA;case w.NumericString:return CA;case w.ObjectIdentifier:return wA;case w.OctetString:return Ga;case w.PrintableString:return IA;case w.TeletexString:return TA;case w.UTCTime:return OA;case w.UniversalString:return AA;case w.Utf8String:return Wp;case w.VideotexString:return _A;case w.VisibleString:return RA;default:return null}}function fn(t){return typeof t=="function"&&t.prototype?t.prototype.toASN&&t.prototype.fromASN?!0:fn(t.prototype):!!(t&&typeof t=="object"&&"toASN"in t&&"fromASN"in t)}function Xp(t){if(t){let e=Object.getPrototypeOf(t);return e?.prototype?.constructor===Array?!0:Xp(e)}return!1}function Eb(t,e){if(!(t&&e)||t.byteLength!==e.byteLength)return!1;let r=new Uint8Array(t),n=new Uint8Array(e);for(let s=0;s<t.byteLength;s++)if(r[s]!==n[s])return!1;return!0}var ql=class{items=new WeakMap;has(e){return this.items.has(e)}get(e,r=!1){let n=this.items.get(e);if(!n)throw new Error(`Cannot get schema for '${e.prototype.constructor.name}' target`);if(r&&!n.schema)throw new Error(`Schema '${e.prototype.constructor.name}' doesn't contain ASN.1 schema. Call 'AsnSchemaStorage.cache'.`);return n}cache(e){let r=this.get(e);r.schema||(r.schema=this.create(e,!0))}createDefault(e){let r={type:k.Sequence,items:{}},n=this.findParentSchema(e);return n&&(Object.assign(r,n),r.items=Object.assign({},r.items,n.items)),r}create(e,r){let n=this.items.get(e)||this.createDefault(e),s=[];for(let i in n.items){let o=n.items[i],a=r?i:"",c;if(typeof o.type=="number"){let l=w[o.type],p=Gn[l];if(!p)throw new Error(`Cannot get ASN1 class by name '${l}'`);c=new p({name:a})}else fn(o.type)?c=new o.type().toSchema(a):o.optional?this.get(o.type).type===k.Choice?c=new Kn({name:a}):(c=this.create(o.type,!1),c.name=a):c=new Kn({name:a});let f=!!o.optional||o.defaultValue!==void 0;if(o.repeated){c.name="";let l=o.repeated==="set"?Br:Er;c=new l({name:"",value:[new Oo({name:a,value:c})]})}if(o.context!==null&&o.context!==void 0)if(o.implicit)if(typeof o.type=="number"||fn(o.type)){let l=o.repeated?Xt:Cs;s.push(new l({name:a,optional:f,idBlock:{tagClass:3,tagNumber:o.context}}))}else{this.cache(o.type);let l=!!o.repeated,p=l?c:this.get(o.type,!0).schema;p="valueBlock"in p?p.valueBlock.value:p.value,s.push(new Xt({name:l?"":a,optional:f,idBlock:{tagClass:3,tagNumber:o.context},value:p}))}else s.push(new Xt({optional:f,idBlock:{tagClass:3,tagNumber:o.context},value:[c]}));else c.optional=f,s.push(c)}switch(n.type){case k.Sequence:return new Er({value:s,name:""});case k.Set:return new Br({value:s,name:""});case k.Choice:return new Wa({value:s,name:""});default:throw new Error("Unsupported ASN1 type in use")}}set(e,r){return this.items.set(e,r),this}findParentSchema(e){let r=Object.getPrototypeOf(e);return r?this.items.get(r)||this.findParentSchema(r):null}};var Yt=new ql;var O=t=>e=>{let r;Yt.has(e)?r=Yt.get(e):(r=Yt.createDefault(e),Yt.set(e,r)),Object.assign(r,t)};var m=t=>(e,r)=>{let n;Yt.has(e.constructor)?n=Yt.get(e.constructor):(n=Yt.createDefault(e.constructor),Yt.set(e.constructor,n));let s=Object.assign({},t);if(typeof s.type=="number"&&!s.converter){let i=Si(t.type);if(!i)throw new Error(`Cannot get default converter for property '${r}' of ${e.constructor.name}`);s.converter=i}s.raw=t.raw,n.items[r]=s};var Ei=class extends Error{schemas=[]};var Pu=class{static parse(e,r,n){let s=_s(nr(e),n?.berOptions);if(s.result.error)throw new Error(s.result.error);return this.fromASN(s.result,r,n)}static fromASN(e,r,n){try{if(fn(r))return new r().fromASN(e);let s=Yt.get(r);Yt.cache(r);let i=s.schema,o=this.handleChoiceTypes(e,s,r,i,n);if(o?.result)return o.result;o?.targetSchema&&(i=o.targetSchema);let a=this.handleSequenceTypes(e,s,r,i),c=new r;return Xp(r)?this.handleArrayTypes(e,s,r,n):(this.processSchemaItems(s,a,c,n),c)}catch(s){throw s instanceof Ei&&s.schemas.push(r.name),s}}static handleChoiceTypes(e,r,n,s,i){if(e.constructor===Xt&&r.type===k.Choice&&e.idBlock.tagClass===3)for(let o in r.items){let a=r.items[o];if(a.context===e.idBlock.tagNumber&&a.implicit&&typeof a.type=="function"&&Yt.has(a.type)){let c=Yt.get(a.type);if(c&&c.type===k.Sequence){let f=new Er;if("value"in e.valueBlock&&Array.isArray(e.valueBlock.value)&&"value"in f.valueBlock){f.valueBlock.value=e.valueBlock.value;let l=this.fromASN(f,a.type,i),p=new n;return p[o]=l,{result:p}}}}}else if(e.constructor===Xt&&r.type!==k.Choice){let o=new Xt({idBlock:{tagClass:3,tagNumber:e.idBlock.tagNumber},value:r.schema.valueBlock.value});for(let a in r.items)delete e[a];return{targetSchema:o}}return null}static handleSequenceTypes(e,r,n,s){if(r.type===k.Sequence){let i=Es({},e,s);if(!i.verified)throw new Ei(`Data does not match to ${n.name} ASN1 schema.${i.result.error?` ${i.result.error}`:""}`);return i}else{let i=Es({},e,s);if(!i.verified)throw new Ei(`Data does not match to ${n.name} ASN1 schema.${i.result.error?` ${i.result.error}`:""}`);return i}}static processRepeatedField(e,r,n){let s=e.slice(r);if(s.length===1&&s[0].constructor.name==="Sequence"){let i=s[0];i.valueBlock&&i.valueBlock.value&&Array.isArray(i.valueBlock.value)&&(s=i.valueBlock.value)}if(typeof n.type=="number"){let i=Si(n.type);if(!i)throw new Error(`No converter for ASN.1 type ${n.type}`);return s.filter(o=>o&&o.valueBlock).map(o=>{try{return i.fromASN(o)}catch{return}}).filter(o=>o!==void 0)}else return s.filter(i=>i&&i.valueBlock).map(i=>{try{return this.fromASN(i,n.type)}catch{return}}).filter(i=>i!==void 0)}static processPrimitiveField(e,r){let n=Si(r.type);if(!n)throw new Error(`No converter for ASN.1 type ${r.type}`);return n.fromASN(e)}static isOptionalChoiceField(e){return e.optional&&typeof e.type=="function"&&Yt.has(e.type)&&Yt.get(e.type).type===k.Choice}static processOptionalChoiceField(e,r){try{return{processed:!0,value:this.fromASN(e,r.type)}}catch(n){if(n instanceof Ei&&/Wrong values for Choice type/.test(n.message))return{processed:!1};throw n}}static handleArrayTypes(e,r,n,s){if(!("value"in e.valueBlock&&Array.isArray(e.valueBlock.value)))throw new Error("Cannot get items from the ASN.1 parsed value. ASN.1 object is not constructed.");let i=r.itemType;if(typeof i=="number"){let o=Si(i);if(!o)throw new Error(`Cannot get default converter for array item of ${n.name} ASN1 schema`);return n.from(e.valueBlock.value,a=>o.fromASN(a))}else return n.from(e.valueBlock.value,o=>this.fromASN(o,i,s))}static processSchemaItems(e,r,n,s){for(let i in e.items){let o=r.result[i];if(!o)continue;let a=e.items[i],c=a.type,f;typeof c=="number"||fn(c)?f=this.processPrimitiveSchemaItem(o,a,c,s):f=this.processComplexSchemaItem(o,a,c,s),f&&typeof f=="object"&&"value"in f&&"raw"in f?(n[i]=f.value,n[`${i}Raw`]=f.raw):n[i]=f}}static processPrimitiveSchemaItem(e,r,n,s){let i=r.converter??(fn(n)?new n:null);if(!i)throw new Error("Converter is empty");return r.repeated?this.processRepeatedPrimitiveItem(e,r,i,s):this.processSinglePrimitiveItem(e,r,n,i,s)}static processRepeatedPrimitiveItem(e,r,n,s){if(r.implicit){let i=r.repeated==="sequence"?Er:Br,o=new i;o.valueBlock=e.valueBlock;let a=_s(o.toBER(!1),s?.berOptions);if(a.offset===-1)throw new Error(`Cannot parse the child item. ${a.result.error}`);if(!("value"in a.result.valueBlock&&Array.isArray(a.result.valueBlock.value)))throw new Error("Cannot get items from the ASN.1 parsed value. ASN.1 object is not constructed.");let c=a.result.valueBlock.value;return Array.from(c,f=>n.fromASN(f))}else return Array.from(e,i=>n.fromASN(i))}static processSinglePrimitiveItem(e,r,n,s,i){let o=e;if(r.implicit){let a;if(fn(n))a=new n().toSchema("");else{let c=w[n],f=Gn[c];if(!f)throw new Error(`Cannot get '${c}' class from asn1js module`);a=new f}a.valueBlock=o.valueBlock,o=_s(a.toBER(!1),i?.berOptions).result}return s.fromASN(o)}static processComplexSchemaItem(e,r,n,s){if(r.repeated){if(!Array.isArray(e))throw new Error("Cannot get list of items from the ASN.1 parsed value. ASN.1 value should be iterable.");return Array.from(e,i=>this.fromASN(i,n,s))}else{let i=this.handleImplicitTagging(e,r,n);if(this.isOptionalChoiceField(r))try{return this.fromASN(i,n,s)}catch(o){if(o instanceof Ei&&/Wrong values for Choice type/.test(o.message))return;throw o}else{let o=this.fromASN(i,n,s);return r.raw?{value:o,raw:e.valueBeforeDecodeView}:o}}}static handleImplicitTagging(e,r,n){if(r.implicit&&typeof r.context=="number"){let s=Yt.get(n);if(s.type===k.Sequence){let i=new Er;if("value"in e.valueBlock&&Array.isArray(e.valueBlock.value)&&"value"in i.valueBlock)return i.valueBlock.value=e.valueBlock.value,i}else if(s.type===k.Set){let i=new Br;if("value"in e.valueBlock&&Array.isArray(e.valueBlock.value)&&"value"in i.valueBlock)return i.valueBlock.value=e.valueBlock.value,i}}return e}};var Ou=class t{static serialize(e){return e instanceof Wt?e.toBER(!1):this.toASN(e).toBER(!1)}static toASN(e){if(e&&typeof e=="object"&&fn(e))return e.toASN();if(!(e&&typeof e=="object"))throw new TypeError("Parameter 1 should be type of Object.");let r=e.constructor,n=Yt.get(r);Yt.cache(r);let s=[];if(n.itemType){if(!Array.isArray(e))throw new TypeError("Parameter 1 should be type of Array.");if(typeof n.itemType=="number"){let o=Si(n.itemType);if(!o)throw new Error(`Cannot get default converter for array item of ${r.name} ASN1 schema`);s=e.map(a=>o.toASN(a))}else s=e.map(o=>this.toAsnItem({type:n.itemType},"[]",r,o))}else for(let o in n.items){let a=n.items[o],c=e[o];if(c===void 0||a.defaultValue===c||typeof a.defaultValue=="object"&&typeof c=="object"&&Eb(this.serialize(a.defaultValue),this.serialize(c)))continue;let f=t.toAsnItem(a,o,r,c);if(typeof a.context=="number")if(a.implicit)if(!a.repeated&&(typeof a.type=="number"||fn(a.type))){let l={};l.valueHex=f instanceof bn?nr(f.valueBeforeDecodeView):f.valueBlock.toBER(),s.push(new Cs({optional:a.optional,idBlock:{tagClass:3,tagNumber:a.context},...l}))}else s.push(new Xt({optional:a.optional,idBlock:{tagClass:3,tagNumber:a.context},value:f.valueBlock.value}));else s.push(new Xt({optional:a.optional,idBlock:{tagClass:3,tagNumber:a.context},value:[f]}));else a.repeated?s=s.concat(f):s.push(f)}let i;switch(n.type){case k.Sequence:i=new Er({value:s});break;case k.Set:i=new Br({value:s});break;case k.Choice:if(!s[0])throw new Error(`Schema '${r.name}' has wrong data. Choice cannot be empty.`);i=s[0];break}return i}static toAsnItem(e,r,n,s){let i;if(typeof e.type=="number"){let o=e.converter;if(!o)throw new Error(`Property '${r}' doesn't have converter for type ${w[e.type]} in schema '${n.name}'`);if(e.repeated){if(!Array.isArray(s))throw new TypeError("Parameter 'objProp' should be type of Array.");let a=Array.from(s,f=>o.toASN(f)),c=e.repeated==="sequence"?Er:Br;i=new c({value:a})}else i=o.toASN(s)}else if(e.repeated){if(!Array.isArray(s))throw new TypeError("Parameter 'objProp' should be type of Array.");let o=Array.from(s,c=>this.toASN(c)),a=e.repeated==="sequence"?Er:Br;i=new a({value:o})}else i=this.toASN(s);return i}};var Re=class extends Array{constructor(e=[]){if(typeof e=="number")super(e);else{super();for(let r of e)this.push(r)}}};var se=class t{static serialize(e){return Ou.serialize(e)}static parse(e,r,n){return Pu.parse(e,r,n)}static toString(e,r){let n=Bs(e)?nr(e):t.serialize(e),s=_s(n,r?.berOptions);if(s.offset===-1)throw new Error(`Cannot decode ASN.1 data. ${s.result.error}`);return s.result.toString()}};function d(t,e,r,n){var s=arguments.length,i=s<3?e:n===null?n=Object.getOwnPropertyDescriptor(e,r):n,o;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")i=Reflect.decorate(t,e,r,n);else for(var a=t.length-1;a>=0;a--)(o=t[a])&&(i=(s<3?o(i):s>3?o(e,r,i):o(e,r))||i);return s>3&&i&&Object.defineProperty(e,r,i),i}function et(t,e,r,n){if(r==="a"&&!n)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?t!==e||!n:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return r==="m"?n:r==="a"?n.call(t):n?n.value:e.get(t)}function Ot(t,e,r,n,s){if(n==="m")throw new TypeError("Private method is not writable");if(n==="a"&&!s)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?t!==e||!s:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return n==="a"?s.call(t,r):s?s.value=r:e.set(t,r),r}var Xa={};iy(Xa,{decode:()=>Zp,encode:()=>Yp,format:()=>_b,formats:()=>Bb,hex:()=>GA,is:()=>Ib,normalize:()=>Lu,parse:()=>Tb});var MA=/^[0-9a-f]$/i,HA=[" "," ",`
114
+ `,"\r",":","-","."];function jA(t){return t.separators==="none"?[]:!t.separators||t.separators==="common"?HA:t.separators}function qA(t){if(!t)throw new TypeError("Hex separators must be non-empty strings")}function VA(t,e,r){for(let n of r)if(t.startsWith(n,e))return n}function zA(t){let e=/[A-F]/.test(t),r=/[a-f]/.test(t);return e&&!r?"upper":"lower"}function FA(t){let e=/\r\n|\n/.exec(t);if(e)return e[0]===`\r
115
+ `?`\r
116
+ `:`
117
+ `}function Ab(t){return t.replace(/[^0-9a-f]/gi,"")}function KA(t){let e=t.match(/[0-9A-Fa-f]+|[^0-9A-Fa-f]+/g)??[];if(e.length<3)return;let r=e.filter((o,a)=>a%2===0),n=e.filter((o,a)=>a%2===1),s=n[0];if(!s||n.some(o=>o!==s)||r.some(o=>o.length===0||o.length%2!==0))return;let i=r[0]?.length??0;if(i&&!r.slice(0,-1).some(o=>o.length!==i)&&!((r[r.length-1]?.length??0)>i))return{size:i/2,separator:s}}function $A(t){let e=t.trim(),r=/^0x/i.test(e)?"0x":"",n=r?e.slice(2):e,s=FA(n),i=n.split(/\r\n|\n/).filter(f=>f.length>0),o=i[0]?.trim()??"",a=KA(o),c={case:zA(e),prefix:r};if(a&&(c.group=a),s&&i.length>1){let f=Ab(i[0]??"").length/2;f>0&&i.slice(0,-1).every(l=>Ab(l).length/2===f)&&(c.line={bytesPerLine:f,separator:s})}return c}function WA(t,e){let r=e.allowPrefix??!0,n=[...jA(e)].sort((a,c)=>c.length-a.length);for(let a of n)qA(a);let s=t.trim();if(/^0x/i.test(s)){if(!r)throw new TypeError("Hexadecimal text must not include a 0x prefix");s=s.slice(2)}let i="",o=!1;for(let a=0;a<s.length;){let c=s[a]??"";if(MA.test(c)){i+=c,o=!1,a+=1;continue}let f=VA(s,a,n);if(!f)throw new TypeError("Input is not valid hexadecimal text");if(e.strict&&(o||i.length===0))throw new TypeError("Hexadecimal text contains misplaced separators");o=!0,a+=f.length}if(e.strict&&o&&i.length>0)throw new TypeError("Hexadecimal text must not end with a separator");if(i.length%2!==0){if(!e.allowOddLength)throw new TypeError("Hexadecimal text must contain an even number of characters");i=`0${i}`}return i.toLowerCase()}function Cb(t,e){if(!e)return t.join("");if(!Number.isInteger(e.size)||e.size<1)throw new RangeError("Hex group size must be a positive integer");let r=[];for(let n=0;n<t.length;n+=e.size)r.push(t.slice(n,n+e.size).join(""));return r.join(e.separator)}function Lu(t,e={}){return WA(t,e)}function Ib(t,e={}){if(typeof t!="string")return!1;try{return Lu(t,e),!0}catch{return!1}}function Yp(t,e={}){let r=cn(t),n=e.case??"lower",s=Array.from(r,o=>{let a=o.toString(16).padStart(2,"0");return n==="upper"?a.toUpperCase():a}),i="";if(e.line){let o=e.line.bytesPerLine;if(!Number.isInteger(o)||o<1)throw new RangeError("Hex bytesPerLine must be a positive integer");let a=e.line.separator??`
118
+ `,c=[];for(let f=0;f<s.length;f+=o)c.push(Cb(s.slice(f,f+o),e.group));i=c.join(a)}else i=Cb(s,e.group);return`${e.prefix??""}${i}`}function Zp(t,e={}){let r=Lu(t,e),n=new Uint8Array(r.length/2);for(let s=0;s<r.length;s+=2)n[s/2]=Number.parseInt(r.slice(s,s+2),16);return n}function Tb(t,e={}){let r=Lu(t,e);return{bytes:Zp(r),format:$A(t),normalized:r}}function _b(t,e){return Yp(t,e)}var Bb={compact:Object.freeze({}),upper:Object.freeze({case:"upper"}),colon:Object.freeze({group:{size:1,separator:":"}}),colonUpper:Object.freeze({case:"upper",group:{size:1,separator:":"}}),groupsOf4:Object.freeze({group:{size:4,separator:" "}}),prefixed:Object.freeze({prefix:"0x"})},GA={encode:Yp,decode:Zp,format:_b,formats:Bb,is:Ib,normalize:Lu,parse:Tb};var Uu=class{static isIPv4(e){return/^(\d{1,3}\.){3}\d{1,3}$/.test(e)}static parseIPv4(e){let r=e.split(".");if(r.length!==4)throw new Error("Invalid IPv4 address");return r.map(n=>{let s=parseInt(n,10);if(isNaN(s)||s<0||s>255)throw new Error("Invalid IPv4 address part");return s})}static parseIPv6(e){let n=this.expandIPv6(e).split(":");if(n.length!==8)throw new Error("Invalid IPv6 address");return n.reduce((s,i)=>{let o=parseInt(i,16);if(isNaN(o)||o<0||o>65535)throw new Error("Invalid IPv6 address part");return s.push(o>>8&255),s.push(o&255),s},[])}static expandIPv6(e){if(!e.includes("::"))return e;let r=e.split("::");if(r.length>2)throw new Error("Invalid IPv6 address");let n=r[0]?r[0].split(":"):[],s=r[1]?r[1].split(":"):[],i=8-(n.length+s.length);if(i<0)throw new Error("Invalid IPv6 address");return[...n,...Array(i).fill("0"),...s].join(":")}static formatIPv6(e){let r=[];for(let n=0;n<16;n+=2)r.push((e[n]<<8|e[n+1]).toString(16));return this.compressIPv6(r.join(":"))}static compressIPv6(e){let r=e.split(":"),n=-1,s=0,i=-1,o=0;for(let a=0;a<r.length;a++)r[a]==="0"?(i===-1&&(i=a),o++):(o>s&&(n=i,s=o),i=-1,o=0);if(o>s&&(n=i,s=o),s>1){let a=r.slice(0,n).join(":"),c=r.slice(n+s).join(":");return`${a}::${c}`}return e}static parseCIDR(e){let[r,n]=e.split("/"),s=parseInt(n,10);if(this.isIPv4(r)){if(s<0||s>32)throw new Error("Invalid IPv4 prefix length");return[this.parseIPv4(r),s]}else{if(s<0||s>128)throw new Error("Invalid IPv6 prefix length");return[this.parseIPv6(r),s]}}static decodeIP(e){if(e.length===64&&parseInt(e,16)===0)return"::/0";if(e.length!==16)return e;let r=parseInt(e.slice(8),16).toString(2).split("").reduce((s,i)=>s+ +i,0),n=e.slice(0,8).replace(/(.{2})/g,s=>`${parseInt(s,16)}.`);return n=n.slice(0,-1),`${n}/${r}`}static toString(e){let r=new Uint8Array(e);if(r.length===4)return Array.from(r).join(".");if(r.length===16)return this.formatIPv6(r);if(r.length===8||r.length===32){let n=r.length/2,s=r.slice(0,n),i=r.slice(n);if(r.every(c=>c===0))return r.length===8?"0.0.0.0/0":"::/0";let a=i.reduce((c,f)=>c+(f.toString(2).match(/1/g)||[]).length,0);return r.length===8?`${Array.from(s).join(".")}/${a}`:`${this.formatIPv6(s)}/${a}`}return this.decodeIP(Xa.encode(e))}static fromString(e){if(e.includes("/")){let[n,s]=this.parseCIDR(e),i=new Uint8Array(n.length),o=s;for(let c=0;c<i.length;c++)o>=8?(i[c]=255,o-=8):o>0&&(i[c]=255<<8-o,o=0);let a=new Uint8Array(n.length*2);return a.set(n,0),a.set(i,n.length),a.buffer}let r=this.isIPv4(e)?this.parseIPv4(e):this.parseIPv6(e);return new Uint8Array(r).buffer}};var Jp,Qp,ex,Zt=class{teletexString;printableString;universalString;utf8String;bmpString;constructor(e={}){Object.assign(this,e)}toString(){return this.bmpString||this.printableString||this.teletexString||this.universalString||this.utf8String||""}};d([m({type:w.TeletexString})],Zt.prototype,"teletexString",void 0);d([m({type:w.PrintableString})],Zt.prototype,"printableString",void 0);d([m({type:w.UniversalString})],Zt.prototype,"universalString",void 0);d([m({type:w.Utf8String})],Zt.prototype,"utf8String",void 0);d([m({type:w.BmpString})],Zt.prototype,"bmpString",void 0);Zt=d([O({type:k.Choice})],Zt);var Ya=class extends Zt{ia5String;anyValue;constructor(e={}){super(e),Object.assign(this,e)}toString(){return this.ia5String||(this.anyValue?Xa.encode(this.anyValue):super.toString())}};d([m({type:w.IA5String})],Ya.prototype,"ia5String",void 0);d([m({type:w.Any})],Ya.prototype,"anyValue",void 0);Ya=d([O({type:k.Choice})],Ya);var Lo=class{type="";value=new Ya;constructor(e={}){Object.assign(this,e)}};d([m({type:w.ObjectIdentifier})],Lo.prototype,"type",void 0);d([m({type:Ya})],Lo.prototype,"value",void 0);var Ai=Jp=class extends Re{constructor(e){super(e),Object.setPrototypeOf(this,Jp.prototype)}};Ai=Jp=d([O({type:k.Set,itemType:Lo})],Ai);var tx=Qp=class extends Re{constructor(e){super(e),Object.setPrototypeOf(this,Qp.prototype)}};tx=Qp=d([O({type:k.Sequence,itemType:Ai})],tx);var Bt=ex=class extends tx{constructor(e){super(e),Object.setPrototypeOf(this,ex.prototype)}};Bt=ex=d([O({type:k.Sequence})],Bt);var QA={fromASN:t=>Uu.toString(Ga.fromASN(t)),toASN:t=>Ga.toASN(Uu.fromString(t))},Ci=class{typeId="";value=new ArrayBuffer(0);constructor(e={}){Object.assign(this,e)}};d([m({type:w.ObjectIdentifier})],Ci.prototype,"typeId",void 0);d([m({type:w.Any,context:0})],Ci.prototype,"value",void 0);var Du=class{nameAssigner;partyName=new Zt;constructor(e={}){Object.assign(this,e)}};d([m({type:Zt,optional:!0,context:0,implicit:!0})],Du.prototype,"nameAssigner",void 0);d([m({type:Zt,context:1,implicit:!0})],Du.prototype,"partyName",void 0);var je=class{otherName;rfc822Name;dNSName;x400Address;directoryName;ediPartyName;uniformResourceIdentifier;iPAddress;registeredID;constructor(e={}){Object.assign(this,e)}};d([m({type:Ci,context:0,implicit:!0})],je.prototype,"otherName",void 0);d([m({type:w.IA5String,context:1,implicit:!0})],je.prototype,"rfc822Name",void 0);d([m({type:w.IA5String,context:2,implicit:!0})],je.prototype,"dNSName",void 0);d([m({type:w.Any,context:3,implicit:!0})],je.prototype,"x400Address",void 0);d([m({type:Bt,context:4,implicit:!1})],je.prototype,"directoryName",void 0);d([m({type:Du,context:5})],je.prototype,"ediPartyName",void 0);d([m({type:w.IA5String,context:6,implicit:!0})],je.prototype,"uniformResourceIdentifier",void 0);d([m({type:w.OctetString,context:7,implicit:!0,converter:QA})],je.prototype,"iPAddress",void 0);d([m({type:w.ObjectIdentifier,context:8,implicit:!0})],je.prototype,"registeredID",void 0);je=d([O({type:k.Choice})],je);var Ii="1.3.6.1.5.5.7",Ti=`${Ii}.1`,kb=`${Ii}.2`,Uo=`${Ii}.3`,Vl=`${Ii}.48`,dP=`${kb}.1`,lP=`${kb}.2`,rx=`${Vl}.1`,nx=`${Vl}.2`,sx=`${Vl}.3`,ix=`${Vl}.5`,Xe="2.5.29";var ox,zl=`${Ti}.1`,ks=class{accessMethod="";accessLocation=new je;constructor(e={}){Object.assign(this,e)}};d([m({type:w.ObjectIdentifier})],ks.prototype,"accessMethod",void 0);d([m({type:je})],ks.prototype,"accessLocation",void 0);var Do=ox=class extends Re{constructor(e){super(e),Object.setPrototypeOf(this,ox.prototype)}};Do=ox=d([O({type:k.Sequence,itemType:ks})],Do);var Fl=`${Xe}.35`,Mo=class extends Le{},Yn=class{keyIdentifier;authorityCertIssuer;authorityCertSerialNumber;constructor(e={}){e&&Object.assign(this,e)}};d([m({type:Mo,context:0,optional:!0,implicit:!0})],Yn.prototype,"keyIdentifier",void 0);d([m({type:je,context:1,optional:!0,implicit:!0,repeated:"sequence"})],Yn.prototype,"authorityCertIssuer",void 0);d([m({type:w.Integer,context:2,optional:!0,implicit:!0,converter:pt})],Yn.prototype,"authorityCertSerialNumber",void 0);var Kl=`${Xe}.19`,Ho=class{cA=!1;pathLenConstraint;constructor(e={}){Object.assign(this,e)}};d([m({type:w.Boolean,defaultValue:!1})],Ho.prototype,"cA",void 0);d([m({type:w.Integer,optional:!0})],Ho.prototype,"pathLenConstraint",void 0);var ax,Lt=ax=class extends Re{constructor(e){super(e),Object.setPrototypeOf(this,ax.prototype)}};Lt=ax=d([O({type:k.Sequence,itemType:je})],Lt);var cx,eC=`${Xe}.29`,Rb=cx=class extends Lt{constructor(e){super(e),Object.setPrototypeOf(this,cx.prototype)}};Rb=cx=d([O({type:k.Sequence})],Rb);var ux,Wl=`${Xe}.32`,zP=`${Wl}.0`,Rs=class{ia5String;visibleString;bmpString;utf8String;constructor(e={}){Object.assign(this,e)}toString(){return this.ia5String||this.visibleString||this.bmpString||this.utf8String||""}};d([m({type:w.IA5String})],Rs.prototype,"ia5String",void 0);d([m({type:w.VisibleString})],Rs.prototype,"visibleString",void 0);d([m({type:w.BmpString})],Rs.prototype,"bmpString",void 0);d([m({type:w.Utf8String})],Rs.prototype,"utf8String",void 0);Rs=d([O({type:k.Choice})],Rs);var Mu=class{organization=new Rs;noticeNumbers=[];constructor(e={}){Object.assign(this,e)}};d([m({type:Rs})],Mu.prototype,"organization",void 0);d([m({type:w.Integer,repeated:"sequence"})],Mu.prototype,"noticeNumbers",void 0);var Hu=class{noticeRef;explicitText;constructor(e={}){Object.assign(this,e)}};d([m({type:Mu,optional:!0})],Hu.prototype,"noticeRef",void 0);d([m({type:Rs,optional:!0})],Hu.prototype,"explicitText",void 0);var $l=class{cPSuri;userNotice;constructor(e={}){Object.assign(this,e)}};d([m({type:w.IA5String})],$l.prototype,"cPSuri",void 0);d([m({type:Hu})],$l.prototype,"userNotice",void 0);$l=d([O({type:k.Choice})],$l);var ju=class{policyQualifierId="";qualifier=new ArrayBuffer(0);constructor(e={}){Object.assign(this,e)}};d([m({type:w.ObjectIdentifier})],ju.prototype,"policyQualifierId",void 0);d([m({type:w.Any})],ju.prototype,"qualifier",void 0);var jo=class{policyIdentifier="";policyQualifiers;constructor(e={}){Object.assign(this,e)}};d([m({type:w.ObjectIdentifier})],jo.prototype,"policyIdentifier",void 0);d([m({type:ju,repeated:"sequence",optional:!0})],jo.prototype,"policyQualifiers",void 0);var qu=ux=class extends Re{constructor(e){super(e),Object.setPrototypeOf(this,ux.prototype)}};qu=ux=d([O({type:k.Sequence,itemType:jo})],qu);var ZP=`${Xe}.20`,Vu=class{value;constructor(e=0){this.value=e}};d([m({type:w.Integer})],Vu.prototype,"value",void 0);Vu=d([O({type:k.Choice})],Vu);var sO=`${Xe}.27`,Nb=class extends Vu{};Nb=d([O({type:k.Choice})],Nb);var fx,Gl=`${Xe}.31`,Sn;(function(t){t[t.unused=1]="unused",t[t.keyCompromise=2]="keyCompromise",t[t.cACompromise=4]="cACompromise",t[t.affiliationChanged=8]="affiliationChanged",t[t.superseded=16]="superseded",t[t.cessationOfOperation=32]="cessationOfOperation",t[t.certificateHold=64]="certificateHold",t[t.privilegeWithdrawn=128]="privilegeWithdrawn",t[t.aACompromise=256]="aACompromise"})(Sn||(Sn={}));var zu=class extends Xn{toJSON(){let e=[],r=this.toNumber();return r&Sn.aACompromise&&e.push("aACompromise"),r&Sn.affiliationChanged&&e.push("affiliationChanged"),r&Sn.cACompromise&&e.push("cACompromise"),r&Sn.certificateHold&&e.push("certificateHold"),r&Sn.cessationOfOperation&&e.push("cessationOfOperation"),r&Sn.keyCompromise&&e.push("keyCompromise"),r&Sn.privilegeWithdrawn&&e.push("privilegeWithdrawn"),r&Sn.superseded&&e.push("superseded"),r&Sn.unused&&e.push("unused"),e}toString(){return`[${this.toJSON().join(", ")}]`}},Ns=class{fullName;nameRelativeToCRLIssuer;constructor(e={}){Object.assign(this,e)}};d([m({type:je,context:0,repeated:"sequence",implicit:!0})],Ns.prototype,"fullName",void 0);d([m({type:Ai,context:1,implicit:!0})],Ns.prototype,"nameRelativeToCRLIssuer",void 0);Ns=d([O({type:k.Choice})],Ns);var Zn=class{distributionPoint;reasons;cRLIssuer;constructor(e={}){Object.assign(this,e)}};d([m({type:Ns,context:0,optional:!0})],Zn.prototype,"distributionPoint",void 0);d([m({type:zu,context:1,optional:!0,implicit:!0})],Zn.prototype,"reasons",void 0);d([m({type:je,context:2,optional:!0,repeated:"sequence",implicit:!0})],Zn.prototype,"cRLIssuer",void 0);var _i=fx=class extends Re{constructor(e){super(e),Object.setPrototypeOf(this,fx.prototype)}};_i=fx=d([O({type:k.Sequence,itemType:Zn})],_i);var dx,bO=`${Xe}.46`,Pb=dx=class extends _i{constructor(e){super(e),Object.setPrototypeOf(this,dx.prototype)}};Pb=dx=d([O({type:k.Sequence,itemType:Zn})],Pb);var IO=`${Xe}.28`,dn=class t{static ONLY=!1;distributionPoint;onlyContainsUserCerts=t.ONLY;onlyContainsCACerts=t.ONLY;onlySomeReasons;indirectCRL=t.ONLY;onlyContainsAttributeCerts=t.ONLY;constructor(e={}){Object.assign(this,e)}};d([m({type:Ns,context:0,optional:!0})],dn.prototype,"distributionPoint",void 0);d([m({type:w.Boolean,context:1,defaultValue:dn.ONLY,implicit:!0})],dn.prototype,"onlyContainsUserCerts",void 0);d([m({type:w.Boolean,context:2,defaultValue:dn.ONLY,implicit:!0})],dn.prototype,"onlyContainsCACerts",void 0);d([m({type:zu,context:3,optional:!0,implicit:!0})],dn.prototype,"onlySomeReasons",void 0);d([m({type:w.Boolean,context:4,defaultValue:dn.ONLY,implicit:!0})],dn.prototype,"indirectCRL",void 0);d([m({type:w.Boolean,context:5,defaultValue:dn.ONLY,implicit:!0})],dn.prototype,"onlyContainsAttributeCerts",void 0);var Ob=`${Xe}.21`,Fu;(function(t){t[t.unspecified=0]="unspecified",t[t.keyCompromise=1]="keyCompromise",t[t.cACompromise=2]="cACompromise",t[t.affiliationChanged=3]="affiliationChanged",t[t.superseded=4]="superseded",t[t.cessationOfOperation=5]="cessationOfOperation",t[t.certificateHold=6]="certificateHold",t[t.removeFromCRL=8]="removeFromCRL",t[t.privilegeWithdrawn=9]="privilegeWithdrawn",t[t.aACompromise=10]="aACompromise"})(Fu||(Fu={}));var Ku=class{reason=Fu.unspecified;constructor(e=Fu.unspecified){this.reason=e}toJSON(){return Fu[this.reason]}toString(){return this.toJSON()}};d([m({type:w.Enumerated})],Ku.prototype,"reason",void 0);Ku=d([O({type:k.Choice})],Ku);var lx,Xl=`${Xe}.37`,$u=lx=class extends Re{constructor(e){super(e),Object.setPrototypeOf(this,lx.prototype)}};$u=lx=d([O({type:k.Sequence,itemType:w.ObjectIdentifier})],$u);var DO=`${Xl}.0`,Lb=`${Uo}.1`,Ub=`${Uo}.2`,Db=`${Uo}.3`,Mb=`${Uo}.4`,Hb=`${Uo}.8`,jb=`${Uo}.9`;var VO=`${Xe}.54`,hx=class{value;constructor(e=new ArrayBuffer(0)){this.value=e}};d([m({type:w.Integer,converter:pt})],hx.prototype,"value",void 0);hx=d([O({type:k.Choice})],hx);var qb=`${Xe}.24`,Wu=class{value=new Date;constructor(e){e&&(this.value=e)}};d([m({type:w.GeneralizedTime})],Wu.prototype,"value",void 0);Wu=d([O({type:k.Choice})],Wu);var px,xx=`${Xe}.18`,Vb=px=class extends Lt{constructor(e){super(e),Object.setPrototypeOf(this,px.prototype)}};Vb=px=d([O({type:k.Sequence})],Vb);var Yl=`${Xe}.15`,En;(function(t){t[t.digitalSignature=1]="digitalSignature",t[t.nonRepudiation=2]="nonRepudiation",t[t.keyEncipherment=4]="keyEncipherment",t[t.dataEncipherment=8]="dataEncipherment",t[t.keyAgreement=16]="keyAgreement",t[t.keyCertSign=32]="keyCertSign",t[t.cRLSign=64]="cRLSign",t[t.encipherOnly=128]="encipherOnly",t[t.decipherOnly=256]="decipherOnly"})(En||(En={}));var Za=class extends Xn{toJSON(){let e=this.toNumber(),r=[];return e&En.cRLSign&&r.push("crlSign"),e&En.dataEncipherment&&r.push("dataEncipherment"),e&En.decipherOnly&&r.push("decipherOnly"),e&En.digitalSignature&&r.push("digitalSignature"),e&En.encipherOnly&&r.push("encipherOnly"),e&En.keyAgreement&&r.push("keyAgreement"),e&En.keyCertSign&&r.push("keyCertSign"),e&En.keyEncipherment&&r.push("keyEncipherment"),e&En.nonRepudiation&&r.push("nonRepudiation"),r}toString(){return`[${this.toJSON().join(", ")}]`}};var mx,uL=`${Xe}.30`,Ja=class{base=new je;minimum=0;maximum;constructor(e={}){Object.assign(this,e)}};d([m({type:je})],Ja.prototype,"base",void 0);d([m({type:w.Integer,context:0,defaultValue:0,implicit:!0})],Ja.prototype,"minimum",void 0);d([m({type:w.Integer,context:1,optional:!0,implicit:!0})],Ja.prototype,"maximum",void 0);var Zl=mx=class extends Re{constructor(e){super(e),Object.setPrototypeOf(this,mx.prototype)}};Zl=mx=d([O({type:k.Sequence,itemType:Ja})],Zl);var Jl=class{permittedSubtrees;excludedSubtrees;constructor(e={}){Object.assign(this,e)}};d([m({type:Zl,context:0,optional:!0,implicit:!0})],Jl.prototype,"permittedSubtrees",void 0);d([m({type:Zl,context:1,optional:!0,implicit:!0})],Jl.prototype,"excludedSubtrees",void 0);var xL=`${Xe}.36`,Ql=class{requireExplicitPolicy;inhibitPolicyMapping;constructor(e={}){Object.assign(this,e)}};d([m({type:w.Integer,context:0,implicit:!0,optional:!0,converter:pt})],Ql.prototype,"requireExplicitPolicy",void 0);d([m({type:w.Integer,context:1,implicit:!0,optional:!0,converter:pt})],Ql.prototype,"inhibitPolicyMapping",void 0);var gx,vL=`${Xe}.33`,Gu=class{issuerDomainPolicy="";subjectDomainPolicy="";constructor(e={}){Object.assign(this,e)}};d([m({type:w.ObjectIdentifier})],Gu.prototype,"issuerDomainPolicy",void 0);d([m({type:w.ObjectIdentifier})],Gu.prototype,"subjectDomainPolicy",void 0);var zb=gx=class extends Re{constructor(e){super(e),Object.setPrototypeOf(this,gx.prototype)}};zb=gx=d([O({type:k.Sequence,itemType:Gu})],zb);var yx,bx=`${Xe}.17`,e0=yx=class extends Lt{constructor(e){super(e),Object.setPrototypeOf(this,yx.prototype)}};e0=yx=d([O({type:k.Sequence})],e0);var cr=class{type="";values=[];constructor(e={}){Object.assign(this,e)}};d([m({type:w.ObjectIdentifier})],cr.prototype,"type",void 0);d([m({type:w.Any,repeated:"set"})],cr.prototype,"values",void 0);var vx,UL=`${Xe}.9`,Fb=vx=class extends Re{constructor(e){super(e),Object.setPrototypeOf(this,vx.prototype)}};Fb=vx=d([O({type:k.Sequence,itemType:cr})],Fb);var wx=`${Xe}.14`,Ur=class extends Mo{};var KL=`${Xe}.16`,t0=class{notBefore;notAfter;constructor(e={}){Object.assign(this,e)}};d([m({type:w.GeneralizedTime,context:0,implicit:!0,optional:!0})],t0.prototype,"notBefore",void 0);d([m({type:w.GeneralizedTime,context:1,implicit:!0,optional:!0})],t0.prototype,"notAfter",void 0);var Xu;(function(t){t[t.keyUpdateAllowed=1]="keyUpdateAllowed",t[t.newExtensions=2]="newExtensions",t[t.pKIXCertificate=4]="pKIXCertificate"})(Xu||(Xu={}));var r0=class extends Xn{toJSON(){let e=[],r=this.toNumber();return r&Xu.pKIXCertificate&&e.push("pKIXCertificate"),r&Xu.newExtensions&&e.push("newExtensions"),r&Xu.keyUpdateAllowed&&e.push("keyUpdateAllowed"),e}toString(){return`[${this.toJSON().join(", ")}]`}},n0=class{entrustVers="";entrustInfoFlags=new r0;constructor(e={}){Object.assign(this,e)}};d([m({type:w.GeneralString})],n0.prototype,"entrustVers",void 0);d([m({type:r0})],n0.prototype,"entrustInfoFlags",void 0);var Sx,eU=`${Ti}.11`,Kb=Sx=class extends Re{constructor(e){super(e),Object.setPrototypeOf(this,Sx.prototype)}};Kb=Sx=d([O({type:k.Sequence,itemType:ks})],Kb);var te=class t{algorithm="";parameters;constructor(e={}){Object.assign(this,e)}isEqual(e){return e instanceof t&&e.algorithm==this.algorithm&&(e.parameters&&this.parameters&&$p(e.parameters,this.parameters)||e.parameters===this.parameters)}};d([m({type:w.ObjectIdentifier})],te.prototype,"algorithm",void 0);d([m({type:w.Any,optional:!0})],te.prototype,"parameters",void 0);var ur=class{algorithm=new te;subjectPublicKey=new ArrayBuffer(0);constructor(e={}){Object.assign(this,e)}};d([m({type:te})],ur.prototype,"algorithm",void 0);d([m({type:w.BitString})],ur.prototype,"subjectPublicKey",void 0);var Ft=class{utcTime;generalTime;constructor(e){if(e)if(typeof e=="string"||typeof e=="number"||e instanceof Date){let r=new Date(e);r.setMilliseconds(0),r.getUTCFullYear()>2049?this.generalTime=r:this.utcTime=r}else Object.assign(this,e)}getTime(){let e=this.utcTime||this.generalTime;if(!e)throw new Error("Cannot get time from CHOICE object");return e}};d([m({type:w.UTCTime})],Ft.prototype,"utcTime",void 0);d([m({type:w.GeneralizedTime})],Ft.prototype,"generalTime",void 0);Ft=d([O({type:k.Choice})],Ft);var Ps=class{notBefore=new Ft(new Date);notAfter=new Ft(new Date);constructor(e){e&&(this.notBefore=new Ft(e.notBefore),this.notAfter=new Ft(e.notAfter))}};d([m({type:Ft})],Ps.prototype,"notBefore",void 0);d([m({type:Ft})],Ps.prototype,"notAfter",void 0);var Ex,Ar=class t{static CRITICAL=!1;extnID="";critical=t.CRITICAL;extnValue=new Le;constructor(e={}){Object.assign(this,e)}};d([m({type:w.ObjectIdentifier})],Ar.prototype,"extnID",void 0);d([m({type:w.Boolean,defaultValue:Ar.CRITICAL})],Ar.prototype,"critical",void 0);d([m({type:Le})],Ar.prototype,"extnValue",void 0);var Yr=Ex=class extends Re{constructor(e){super(e),Object.setPrototypeOf(this,Ex.prototype)}};Yr=Ex=d([O({type:k.Sequence,itemType:Ar})],Yr);var Jn;(function(t){t[t.v1=0]="v1",t[t.v2=1]="v2",t[t.v3=2]="v3"})(Jn||(Jn={}));var fr=class{version=Jn.v1;serialNumber=new ArrayBuffer(0);signature=new te;issuer=new Bt;validity=new Ps;subject=new Bt;subjectPublicKeyInfo=new ur;issuerUniqueID;subjectUniqueID;extensions;constructor(e={}){Object.assign(this,e)}};d([m({type:w.Integer,context:0,defaultValue:Jn.v1})],fr.prototype,"version",void 0);d([m({type:w.Integer,converter:pt})],fr.prototype,"serialNumber",void 0);d([m({type:te})],fr.prototype,"signature",void 0);d([m({type:Bt})],fr.prototype,"issuer",void 0);d([m({type:Ps})],fr.prototype,"validity",void 0);d([m({type:Bt})],fr.prototype,"subject",void 0);d([m({type:ur})],fr.prototype,"subjectPublicKeyInfo",void 0);d([m({type:w.BitString,context:1,implicit:!0,optional:!0})],fr.prototype,"issuerUniqueID",void 0);d([m({type:w.BitString,context:2,implicit:!0,optional:!0})],fr.prototype,"subjectUniqueID",void 0);d([m({type:Yr,context:3,optional:!0})],fr.prototype,"extensions",void 0);var ln=class{tbsCertificate=new fr;tbsCertificateRaw;signatureAlgorithm=new te;signatureValue=new ArrayBuffer(0);constructor(e={}){Object.assign(this,e)}};d([m({type:fr,raw:!0})],ln.prototype,"tbsCertificate",void 0);d([m({type:te})],ln.prototype,"signatureAlgorithm",void 0);d([m({type:w.BitString})],ln.prototype,"signatureValue",void 0);var qo=class{userCertificate=new ArrayBuffer(0);revocationDate=new Ft;crlEntryExtensions;constructor(e={}){Object.assign(this,e)}};d([m({type:w.Integer,converter:pt})],qo.prototype,"userCertificate",void 0);d([m({type:Ft})],qo.prototype,"revocationDate",void 0);d([m({type:Ar,optional:!0,repeated:"sequence"})],qo.prototype,"crlEntryExtensions",void 0);var Zr=class{version;signature=new te;issuer=new Bt;thisUpdate=new Ft;nextUpdate;revokedCertificates;crlExtensions;constructor(e={}){Object.assign(this,e)}};d([m({type:w.Integer,optional:!0})],Zr.prototype,"version",void 0);d([m({type:te})],Zr.prototype,"signature",void 0);d([m({type:Bt})],Zr.prototype,"issuer",void 0);d([m({type:Ft})],Zr.prototype,"thisUpdate",void 0);d([m({type:Ft,optional:!0})],Zr.prototype,"nextUpdate",void 0);d([m({type:qo,repeated:"sequence",optional:!0})],Zr.prototype,"revokedCertificates",void 0);d([m({type:Ar,optional:!0,context:0,repeated:"sequence"})],Zr.prototype,"crlExtensions",void 0);var Vo=class{tbsCertList=new Zr;tbsCertListRaw;signatureAlgorithm=new te;signature=new ArrayBuffer(0);constructor(e={}){Object.assign(this,e)}};d([m({type:Zr,raw:!0})],Vo.prototype,"tbsCertList",void 0);d([m({type:te})],Vo.prototype,"signatureAlgorithm",void 0);d([m({type:w.BitString})],Vo.prototype,"signature",void 0);var An=class{issuer=new Bt;serialNumber=new ArrayBuffer(0);constructor(e={}){Object.assign(this,e)}};d([m({type:Bt})],An.prototype,"issuer",void 0);d([m({type:w.Integer,converter:pt})],An.prototype,"serialNumber",void 0);var zo=class{subjectKeyIdentifier;issuerAndSerialNumber;constructor(e={}){Object.assign(this,e)}};d([m({type:Ur,context:0,implicit:!0})],zo.prototype,"subjectKeyIdentifier",void 0);d([m({type:An})],zo.prototype,"issuerAndSerialNumber",void 0);zo=d([O({type:k.Choice})],zo);var dr;(function(t){t[t.v0=0]="v0",t[t.v1=1]="v1",t[t.v2=2]="v2",t[t.v3=3]="v3",t[t.v4=4]="v4",t[t.v5=5]="v5"})(dr||(dr={}));var Fo=class extends te{};Fo=d([O({type:k.Sequence})],Fo);var Yu=class extends te{};Yu=d([O({type:k.Sequence})],Yu);var Dr=class extends te{};Dr=d([O({type:k.Sequence})],Dr);var Zu=class extends te{};Zu=d([O({type:k.Sequence})],Zu);var Wb=class extends te{};Wb=d([O({type:k.Sequence})],Wb);var s0=class extends te{};s0=d([O({type:k.Sequence})],s0);var Cn=class{attrType="";attrValues=[];constructor(e={}){Object.assign(this,e)}};d([m({type:w.ObjectIdentifier})],Cn.prototype,"attrType",void 0);d([m({type:w.Any,repeated:"set"})],Cn.prototype,"attrValues",void 0);var Ax,Mr=class{version=dr.v0;sid=new zo;digestAlgorithm=new Fo;signedAttrs;signedAttrsRaw;signatureAlgorithm=new Yu;signature=new Le;unsignedAttrs;constructor(e={}){Object.assign(this,e)}};d([m({type:w.Integer})],Mr.prototype,"version",void 0);d([m({type:zo})],Mr.prototype,"sid",void 0);d([m({type:Fo})],Mr.prototype,"digestAlgorithm",void 0);d([m({type:Cn,repeated:"set",context:0,implicit:!0,optional:!0,raw:!0})],Mr.prototype,"signedAttrs",void 0);d([m({type:Yu})],Mr.prototype,"signatureAlgorithm",void 0);d([m({type:Le})],Mr.prototype,"signature",void 0);d([m({type:Cn,repeated:"set",context:1,implicit:!0,optional:!0})],Mr.prototype,"unsignedAttrs",void 0);var Ju=Ax=class extends Re{constructor(e){super(e),Object.setPrototypeOf(this,Ax.prototype)}};Ju=Ax=d([O({type:k.Set,itemType:Mr})],Ju);var Gb=class extends Mr{};Gb=d([O({type:k.Sequence})],Gb);var Xb=class extends Ft{};Xb=d([O({type:k.Choice})],Xb);var Qu=class{acIssuer=new je;acSerial=0;attrs=[];constructor(e={}){Object.assign(this,e)}};d([m({type:je})],Qu.prototype,"acIssuer",void 0);d([m({type:w.Integer})],Qu.prototype,"acSerial",void 0);d([m({type:cr,repeated:"sequence"})],Qu.prototype,"attrs",void 0);var Cx,ef=Cx=class extends Re{constructor(e){super(e),Object.setPrototypeOf(this,Cx.prototype)}};ef=Cx=d([O({type:k.Sequence,itemType:w.ObjectIdentifier})],ef);var Qa=class{pathLenConstraint;permittedAttrs;excludedAttrs;permitUnSpecified=!0;constructor(e={}){Object.assign(this,e)}};d([m({type:w.Integer,optional:!0})],Qa.prototype,"pathLenConstraint",void 0);d([m({type:ef,implicit:!0,context:0,optional:!0})],Qa.prototype,"permittedAttrs",void 0);d([m({type:ef,implicit:!0,context:1,optional:!0})],Qa.prototype,"excludedAttrs",void 0);d([m({type:w.Boolean,defaultValue:!0})],Qa.prototype,"permitUnSpecified",void 0);var hn=class{issuer=new Lt;serial=new ArrayBuffer(0);issuerUID=new ArrayBuffer(0);constructor(e={}){Object.assign(this,e)}};d([m({type:Lt})],hn.prototype,"issuer",void 0);d([m({type:w.Integer,converter:pt})],hn.prototype,"serial",void 0);d([m({type:w.BitString,optional:!0})],hn.prototype,"issuerUID",void 0);var Ix;(function(t){t[t.publicKey=0]="publicKey",t[t.publicKeyCert=1]="publicKeyCert",t[t.otherObjectTypes=2]="otherObjectTypes"})(Ix||(Ix={}));var pn=class{digestedObjectType=Ix.publicKey;otherObjectTypeID;digestAlgorithm=new te;objectDigest=new ArrayBuffer(0);constructor(e={}){Object.assign(this,e)}};d([m({type:w.Enumerated})],pn.prototype,"digestedObjectType",void 0);d([m({type:w.ObjectIdentifier,optional:!0})],pn.prototype,"otherObjectTypeID",void 0);d([m({type:te})],pn.prototype,"digestAlgorithm",void 0);d([m({type:w.BitString})],pn.prototype,"objectDigest",void 0);var Ko=class{issuerName;baseCertificateID;objectDigestInfo;constructor(e={}){Object.assign(this,e)}};d([m({type:Lt,optional:!0})],Ko.prototype,"issuerName",void 0);d([m({type:hn,context:0,implicit:!0,optional:!0})],Ko.prototype,"baseCertificateID",void 0);d([m({type:pn,context:1,implicit:!0,optional:!0})],Ko.prototype,"objectDigestInfo",void 0);var $o=class{v1Form;v2Form;constructor(e={}){Object.assign(this,e)}};d([m({type:je,repeated:"sequence"})],$o.prototype,"v1Form",void 0);d([m({type:Ko,context:0,implicit:!0})],$o.prototype,"v2Form",void 0);$o=d([O({type:k.Choice})],$o);var Wo=class{notBeforeTime=new Date;notAfterTime=new Date;constructor(e={}){Object.assign(this,e)}};d([m({type:w.GeneralizedTime})],Wo.prototype,"notBeforeTime",void 0);d([m({type:w.GeneralizedTime})],Wo.prototype,"notAfterTime",void 0);var Bi=class{baseCertificateID;entityName;objectDigestInfo;constructor(e={}){Object.assign(this,e)}};d([m({type:hn,implicit:!0,context:0,optional:!0})],Bi.prototype,"baseCertificateID",void 0);d([m({type:Lt,implicit:!0,context:1,optional:!0})],Bi.prototype,"entityName",void 0);d([m({type:pn,implicit:!0,context:2,optional:!0})],Bi.prototype,"objectDigestInfo",void 0);var Tx;(function(t){t[t.v2=1]="v2"})(Tx||(Tx={}));var Hr=class{version=Tx.v2;holder=new Bi;issuer=new $o;signature=new te;serialNumber=new ArrayBuffer(0);attrCertValidityPeriod=new Wo;attributes=[];issuerUniqueID;extensions;constructor(e={}){Object.assign(this,e)}};d([m({type:w.Integer})],Hr.prototype,"version",void 0);d([m({type:Bi})],Hr.prototype,"holder",void 0);d([m({type:$o})],Hr.prototype,"issuer",void 0);d([m({type:te})],Hr.prototype,"signature",void 0);d([m({type:w.Integer,converter:pt})],Hr.prototype,"serialNumber",void 0);d([m({type:Wo})],Hr.prototype,"attrCertValidityPeriod",void 0);d([m({type:cr,repeated:"sequence"})],Hr.prototype,"attributes",void 0);d([m({type:w.BitString,optional:!0})],Hr.prototype,"issuerUniqueID",void 0);d([m({type:Yr,optional:!0})],Hr.prototype,"extensions",void 0);var Go=class{acinfo=new Hr;signatureAlgorithm=new te;signatureValue=new ArrayBuffer(0);constructor(e={}){Object.assign(this,e)}};d([m({type:Hr})],Go.prototype,"acinfo",void 0);d([m({type:te})],Go.prototype,"signatureAlgorithm",void 0);d([m({type:w.BitString})],Go.prototype,"signatureValue",void 0);var tf;(function(t){t[t.unmarked=1]="unmarked",t[t.unclassified=2]="unclassified",t[t.restricted=4]="restricted",t[t.confidential=8]="confidential",t[t.secret=16]="secret",t[t.topSecret=32]="topSecret"})(tf||(tf={}));var ec=class extends Xn{};var tc=class{type="";value=new ArrayBuffer(0);constructor(e={}){Object.assign(this,e)}};d([m({type:w.ObjectIdentifier,implicit:!0,context:0})],tc.prototype,"type",void 0);d([m({type:w.Any,implicit:!0,context:1})],tc.prototype,"value",void 0);var rf=class{policyId="";classList=new ec(tf.unclassified);securityCategories;constructor(e={}){Object.assign(this,e)}};d([m({type:w.ObjectIdentifier})],rf.prototype,"policyId",void 0);d([m({type:ec,defaultValue:new ec(tf.unclassified)})],rf.prototype,"classList",void 0);d([m({type:tc,repeated:"set"})],rf.prototype,"securityCategories",void 0);var rc=class{cotets;oid;string;constructor(e={}){Object.assign(this,e)}};d([m({type:Le})],rc.prototype,"cotets",void 0);d([m({type:w.ObjectIdentifier})],rc.prototype,"oid",void 0);d([m({type:w.Utf8String})],rc.prototype,"string",void 0);var i0=class{policyAuthority;values=[];constructor(e={}){Object.assign(this,e)}};d([m({type:Lt,implicit:!0,context:0,optional:!0})],i0.prototype,"policyAuthority",void 0);d([m({type:rc,repeated:"sequence"})],i0.prototype,"values",void 0);var FH=`${Ti}.4`,KH=`${Ti}.6`,$H=`${Ti}.10`,WH=`${Xe}.55`,nf=`${Ii}.10`,GH=`${nf}.1`,XH=`${nf}.2`,YH=`${nf}.3`,ZH=`${nf}.4`,JH=`${nf}.6`,_x="2.5.4",QH=`${_x}.72`;var Bx,nc=class{targetCertificate=new hn;targetName;certDigestInfo;constructor(e={}){Object.assign(this,e)}};d([m({type:hn})],nc.prototype,"targetCertificate",void 0);d([m({type:je,optional:!0})],nc.prototype,"targetName",void 0);d([m({type:pn,optional:!0})],nc.prototype,"certDigestInfo",void 0);var sc=class{targetName;targetGroup;targetCert;constructor(e={}){Object.assign(this,e)}};d([m({type:je,context:0,implicit:!0})],sc.prototype,"targetName",void 0);d([m({type:je,context:1,implicit:!0})],sc.prototype,"targetGroup",void 0);d([m({type:nc,context:2,implicit:!0})],sc.prototype,"targetCert",void 0);sc=d([O({type:k.Choice})],sc);var o0=Bx=class extends Re{constructor(e){super(e),Object.setPrototypeOf(this,Bx.prototype)}};o0=Bx=d([O({type:k.Sequence,itemType:sc})],o0);var kx,Yb=kx=class extends Re{constructor(e){super(e),Object.setPrototypeOf(this,kx.prototype)}};Yb=kx=d([O({type:k.Sequence,itemType:o0})],Yb);var a0=class{roleAuthority;roleName;constructor(e={}){Object.assign(this,e)}};d([m({type:Lt,implicit:!0,context:0,optional:!0})],a0.prototype,"roleAuthority",void 0);d([m({type:je,implicit:!0,context:1})],a0.prototype,"roleName",void 0);var sf=class{service=new je;ident=new je;authInfo;constructor(e={}){Object.assign(this,e)}};d([m({type:je})],sf.prototype,"service",void 0);d([m({type:je})],sf.prototype,"ident",void 0);d([m({type:Le,optional:!0})],sf.prototype,"authInfo",void 0);var Rx,of=class{otherCertFormat="";otherCert=new ArrayBuffer(0);constructor(e={}){Object.assign(this,e)}};d([m({type:w.ObjectIdentifier})],of.prototype,"otherCertFormat",void 0);d([m({type:w.Any})],of.prototype,"otherCert",void 0);var Xo=class{certificate;v2AttrCert;other;constructor(e={}){Object.assign(this,e)}};d([m({type:ln})],Xo.prototype,"certificate",void 0);d([m({type:Go,context:2,implicit:!0})],Xo.prototype,"v2AttrCert",void 0);d([m({type:of,context:3,implicit:!0})],Xo.prototype,"other",void 0);Xo=d([O({type:k.Choice})],Xo);var Yo=Rx=class extends Re{constructor(e){super(e),Object.setPrototypeOf(this,Rx.prototype)}};Yo=Rx=d([O({type:k.Set,itemType:Xo})],Yo);var xn=class{contentType="";content=new ArrayBuffer(0);constructor(e={}){Object.assign(this,e)}};d([m({type:w.ObjectIdentifier})],xn.prototype,"contentType",void 0);d([m({type:w.Any,context:0})],xn.prototype,"content",void 0);var ic=class{single;any;constructor(e={}){Object.assign(this,e)}};d([m({type:Le})],ic.prototype,"single",void 0);d([m({type:w.Any})],ic.prototype,"any",void 0);ic=d([O({type:k.Choice})],ic);var Zo=class{eContentType="";eContent;constructor(e={}){Object.assign(this,e)}};d([m({type:w.ObjectIdentifier})],Zo.prototype,"eContentType",void 0);d([m({type:ic,context:0,optional:!0})],Zo.prototype,"eContent",void 0);var af=class{value;constructedValue;constructor(e={}){Object.assign(this,e)}};d([m({type:Le,context:0,implicit:!0,optional:!0})],af.prototype,"value",void 0);d([m({type:Le,converter:Sb,context:0,implicit:!0,optional:!0,repeated:"sequence"})],af.prototype,"constructedValue",void 0);af=d([O({type:k.Choice})],af);var ki=class{contentType="";contentEncryptionAlgorithm=new Zu;encryptedContent;constructor(e={}){Object.assign(this,e)}};d([m({type:w.ObjectIdentifier})],ki.prototype,"contentType",void 0);d([m({type:Zu})],ki.prototype,"contentEncryptionAlgorithm",void 0);d([m({type:af,optional:!0})],ki.prototype,"encryptedContent",void 0);var Ri=class{keyAttrId="";keyAttr;constructor(e={}){Object.assign(this,e)}};d([m({type:w.ObjectIdentifier})],Ri.prototype,"keyAttrId",void 0);d([m({type:w.Any,optional:!0})],Ri.prototype,"keyAttr",void 0);var Nx,oc=class{subjectKeyIdentifier=new Ur;date;other;constructor(e={}){Object.assign(this,e)}};d([m({type:Ur})],oc.prototype,"subjectKeyIdentifier",void 0);d([m({type:w.GeneralizedTime,optional:!0})],oc.prototype,"date",void 0);d([m({type:Ri,optional:!0})],oc.prototype,"other",void 0);var ac=class{rKeyId;issuerAndSerialNumber;constructor(e={}){Object.assign(this,e)}};d([m({type:oc,context:0,implicit:!0,optional:!0})],ac.prototype,"rKeyId",void 0);d([m({type:An,optional:!0})],ac.prototype,"issuerAndSerialNumber",void 0);ac=d([O({type:k.Choice})],ac);var cf=class{rid=new ac;encryptedKey=new Le;constructor(e={}){Object.assign(this,e)}};d([m({type:ac})],cf.prototype,"rid",void 0);d([m({type:Le})],cf.prototype,"encryptedKey",void 0);var c0=Nx=class extends Re{constructor(e){super(e),Object.setPrototypeOf(this,Nx.prototype)}};c0=Nx=d([O({type:k.Sequence,itemType:cf})],c0);var uf=class{algorithm=new te;publicKey=new ArrayBuffer(0);constructor(e={}){Object.assign(this,e)}};d([m({type:te})],uf.prototype,"algorithm",void 0);d([m({type:w.BitString})],uf.prototype,"publicKey",void 0);var Jo=class{subjectKeyIdentifier;originatorKey;issuerAndSerialNumber;constructor(e={}){Object.assign(this,e)}};d([m({type:Ur,context:0,implicit:!0,optional:!0})],Jo.prototype,"subjectKeyIdentifier",void 0);d([m({type:uf,context:1,implicit:!0,optional:!0})],Jo.prototype,"originatorKey",void 0);d([m({type:An,optional:!0})],Jo.prototype,"issuerAndSerialNumber",void 0);Jo=d([O({type:k.Choice})],Jo);var Os=class{version=dr.v3;originator=new Jo;ukm;keyEncryptionAlgorithm=new Dr;recipientEncryptedKeys=new c0;constructor(e={}){Object.assign(this,e)}};d([m({type:w.Integer})],Os.prototype,"version",void 0);d([m({type:Jo,context:0})],Os.prototype,"originator",void 0);d([m({type:Le,context:1,optional:!0})],Os.prototype,"ukm",void 0);d([m({type:Dr})],Os.prototype,"keyEncryptionAlgorithm",void 0);d([m({type:c0})],Os.prototype,"recipientEncryptedKeys",void 0);var cc=class{subjectKeyIdentifier;issuerAndSerialNumber;constructor(e={}){Object.assign(this,e)}};d([m({type:Ur,context:0,implicit:!0})],cc.prototype,"subjectKeyIdentifier",void 0);d([m({type:An})],cc.prototype,"issuerAndSerialNumber",void 0);cc=d([O({type:k.Choice})],cc);var Ni=class{version=dr.v0;rid=new cc;keyEncryptionAlgorithm=new Dr;encryptedKey=new Le;constructor(e={}){Object.assign(this,e)}};d([m({type:w.Integer})],Ni.prototype,"version",void 0);d([m({type:cc})],Ni.prototype,"rid",void 0);d([m({type:Dr})],Ni.prototype,"keyEncryptionAlgorithm",void 0);d([m({type:Le})],Ni.prototype,"encryptedKey",void 0);var Qo=class{keyIdentifier=new Le;date;other;constructor(e={}){Object.assign(this,e)}};d([m({type:Le})],Qo.prototype,"keyIdentifier",void 0);d([m({type:w.GeneralizedTime,optional:!0})],Qo.prototype,"date",void 0);d([m({type:Ri,optional:!0})],Qo.prototype,"other",void 0);var Pi=class{version=dr.v4;kekid=new Qo;keyEncryptionAlgorithm=new Dr;encryptedKey=new Le;constructor(e={}){Object.assign(this,e)}};d([m({type:w.Integer})],Pi.prototype,"version",void 0);d([m({type:Qo})],Pi.prototype,"kekid",void 0);d([m({type:Dr})],Pi.prototype,"keyEncryptionAlgorithm",void 0);d([m({type:Le})],Pi.prototype,"encryptedKey",void 0);var Oi=class{version=dr.v0;keyDerivationAlgorithm;keyEncryptionAlgorithm=new Dr;encryptedKey=new Le;constructor(e={}){Object.assign(this,e)}};d([m({type:w.Integer})],Oi.prototype,"version",void 0);d([m({type:s0,context:0,optional:!0})],Oi.prototype,"keyDerivationAlgorithm",void 0);d([m({type:Dr})],Oi.prototype,"keyEncryptionAlgorithm",void 0);d([m({type:Le})],Oi.prototype,"encryptedKey",void 0);var ff=class{oriType="";oriValue=new ArrayBuffer(0);constructor(e={}){Object.assign(this,e)}};d([m({type:w.ObjectIdentifier})],ff.prototype,"oriType",void 0);d([m({type:w.Any})],ff.prototype,"oriValue",void 0);var Ls=class{ktri;kari;kekri;pwri;ori;constructor(e={}){Object.assign(this,e)}};d([m({type:Ni,optional:!0})],Ls.prototype,"ktri",void 0);d([m({type:Os,context:1,implicit:!0,optional:!0})],Ls.prototype,"kari",void 0);d([m({type:Pi,context:2,implicit:!0,optional:!0})],Ls.prototype,"kekri",void 0);d([m({type:Oi,context:3,implicit:!0,optional:!0})],Ls.prototype,"pwri",void 0);d([m({type:ff,context:4,implicit:!0,optional:!0})],Ls.prototype,"ori",void 0);Ls=d([O({type:k.Choice})],Ls);var Px,df=Px=class extends Re{constructor(e){super(e),Object.setPrototypeOf(this,Px.prototype)}};df=Px=d([O({type:k.Set,itemType:Ls})],df);var Ox,Zb=`${Ii}.16`,Jq=`${Zb}.2`,Qq=`${Zb}.4`,uc=class{otherRevInfoFormat="";otherRevInfo=new ArrayBuffer(0);constructor(e={}){Object.assign(this,e)}};d([m({type:w.ObjectIdentifier})],uc.prototype,"otherRevInfoFormat",void 0);d([m({type:w.Any})],uc.prototype,"otherRevInfo",void 0);var u0=class{other=new uc;constructor(e={}){Object.assign(this,e)}};d([m({type:uc,context:1,implicit:!0})],u0.prototype,"other",void 0);u0=d([O({type:k.Choice})],u0);var fc=Ox=class extends Re{constructor(e){super(e),Object.setPrototypeOf(this,Ox.prototype)}};fc=Ox=d([O({type:k.Set,itemType:u0})],fc);var dc=class{certs;crls;constructor(e={}){Object.assign(this,e)}};d([m({type:Yo,context:0,implicit:!0,optional:!0})],dc.prototype,"certs",void 0);d([m({type:fc,context:1,implicit:!0,optional:!0})],dc.prototype,"crls",void 0);var Lx,Ux=Lx=class extends Re{constructor(e){super(e),Object.setPrototypeOf(this,Lx.prototype)}};Ux=Lx=d([O({type:k.Set,itemType:Cn})],Ux);var ea=class{version=dr.v0;originatorInfo;recipientInfos=new df;encryptedContentInfo=new ki;unprotectedAttrs;constructor(e={}){Object.assign(this,e)}};d([m({type:w.Integer})],ea.prototype,"version",void 0);d([m({type:dc,context:0,implicit:!0,optional:!0})],ea.prototype,"originatorInfo",void 0);d([m({type:df})],ea.prototype,"recipientInfos",void 0);d([m({type:ki})],ea.prototype,"encryptedContentInfo",void 0);d([m({type:Ux,context:1,implicit:!0,optional:!0})],ea.prototype,"unprotectedAttrs",void 0);var Jb="1.2.840.113549.1.7.2";var Dx,f0=Dx=class extends Re{constructor(e){super(e),Object.setPrototypeOf(this,Dx.prototype)}};f0=Dx=d([O({type:k.Set,itemType:Fo})],f0);var Us=class{version=dr.v0;digestAlgorithms=new f0;encapContentInfo=new Zo;certificates;crls;signerInfos=new Ju;constructor(e={}){Object.assign(this,e)}};d([m({type:w.Integer})],Us.prototype,"version",void 0);d([m({type:f0})],Us.prototype,"digestAlgorithms",void 0);d([m({type:Zo})],Us.prototype,"encapContentInfo",void 0);d([m({type:Yo,context:0,implicit:!0,optional:!0})],Us.prototype,"certificates",void 0);d([m({type:fc,context:1,implicit:!0,optional:!0})],Us.prototype,"crls",void 0);d([m({type:Ju})],Us.prototype,"signerInfos",void 0);var ta="1.2.840.10045.2.1";var lf="1.2.840.10045.4.1",d0="1.2.840.10045.4.3.1",hf="1.2.840.10045.4.3.2",pf="1.2.840.10045.4.3.3",xf="1.2.840.10045.4.3.4";var Mx="1.2.840.10045.3.1.7";var Hx="1.3.132.0.34";var jx="1.3.132.0.35";function mf(t){return new te({algorithm:t})}var e2=mf(lf),XV=mf(d0),t2=mf(hf),r2=mf(pf),n2=mf(xf);var gf=class{fieldType;parameters;constructor(e={}){Object.assign(this,e)}};d([m({type:w.ObjectIdentifier})],gf.prototype,"fieldType",void 0);d([m({type:w.Any})],gf.prototype,"parameters",void 0);gf=d([O({type:k.Sequence})],gf);var qx=class extends Le{};var lc=class{a;b;seed;constructor(e={}){Object.assign(this,e)}};d([m({type:w.OctetString})],lc.prototype,"a",void 0);d([m({type:w.OctetString})],lc.prototype,"b",void 0);d([m({type:w.BitString,optional:!0})],lc.prototype,"seed",void 0);lc=d([O({type:k.Sequence})],lc);var Vx;(function(t){t[t.ecpVer1=1]="ecpVer1"})(Vx||(Vx={}));var Qn=class{version=Vx.ecpVer1;fieldID;curve;base;order;cofactor;constructor(e={}){Object.assign(this,e)}};d([m({type:w.Integer})],Qn.prototype,"version",void 0);d([m({type:gf})],Qn.prototype,"fieldID",void 0);d([m({type:lc})],Qn.prototype,"curve",void 0);d([m({type:qx})],Qn.prototype,"base",void 0);d([m({type:w.Integer,converter:pt})],Qn.prototype,"order",void 0);d([m({type:w.Integer,optional:!0})],Qn.prototype,"cofactor",void 0);Qn=d([O({type:k.Sequence})],Qn);var es=class{namedCurve;implicitCurve;specifiedCurve;constructor(e={}){Object.assign(this,e)}};d([m({type:w.ObjectIdentifier})],es.prototype,"namedCurve",void 0);d([m({type:w.Null})],es.prototype,"implicitCurve",void 0);d([m({type:Qn})],es.prototype,"specifiedCurve",void 0);es=d([O({type:k.Choice})],es);var hc=class{version=1;privateKey=new Le;parameters;publicKey;constructor(e={}){Object.assign(this,e)}};d([m({type:w.Integer})],hc.prototype,"version",void 0);d([m({type:Le})],hc.prototype,"privateKey",void 0);d([m({type:es,context:0,optional:!0})],hc.prototype,"parameters",void 0);d([m({type:w.BitString,context:1,optional:!0})],hc.prototype,"publicKey",void 0);var ra=class{r=new ArrayBuffer(0);s=new ArrayBuffer(0);constructor(e={}){Object.assign(this,e)}};d([m({type:w.Integer,converter:pt})],ra.prototype,"r",void 0);d([m({type:w.Integer,converter:pt})],ra.prototype,"s",void 0);var jr="1.2.840.113549.1.1",ts=`${jr}.1`,s2=`${jr}.7`,i2=`${jr}.9`,Li=`${jr}.10`,o2=`${jr}.2`,a2=`${jr}.4`,pc=`${jr}.5`,c2=`${jr}.14`;var l0=`${jr}.11`,xc=`${jr}.12`,mc=`${jr}.13`,zx=`${jr}.15`,Fx=`${jr}.16`,na="1.3.14.3.2.26",h0="2.16.840.1.101.3.4.2.4",sa="2.16.840.1.101.3.4.2.1",ia="2.16.840.1.101.3.4.2.2",oa="2.16.840.1.101.3.4.2.3",u2="2.16.840.1.101.3.4.2.5",f2="2.16.840.1.101.3.4.2.6",d2="1.2.840.113549.2.2",l2="1.2.840.113549.2.5",Ui=`${jr}.8`;function sr(t){return new te({algorithm:t,parameters:null})}var Ez=sr(d2),Az=sr(l2),Ds=sr(na),Cz=sr(h0),Iz=sr(sa),Tz=sr(ia),_z=sr(oa),Bz=sr(u2),kz=sr(f2),p0=new te({algorithm:Ui,parameters:se.serialize(Ds)}),Kx=new te({algorithm:i2,parameters:se.serialize(Ga.toASN(new Uint8Array([218,57,163,238,94,107,75,13,50,85,191,239,149,96,24,144,175,216,7,9]).buffer))}),Rz=sr(ts),Nz=sr(o2),Pz=sr(a2),Oz=sr(pc),Lz=sr(zx),Uz=sr(Fx),Dz=sr(xc),Mz=sr(mc),Hz=sr(zx),jz=sr(Fx);var gc=class{hashAlgorithm=new te(Ds);maskGenAlgorithm=new te({algorithm:Ui,parameters:se.serialize(Ds)});pSourceAlgorithm=new te(Kx);constructor(e={}){Object.assign(this,e)}};d([m({type:te,context:0,defaultValue:Ds})],gc.prototype,"hashAlgorithm",void 0);d([m({type:te,context:1,defaultValue:p0})],gc.prototype,"maskGenAlgorithm",void 0);d([m({type:te,context:2,defaultValue:Kx})],gc.prototype,"pSourceAlgorithm",void 0);var Wz=new te({algorithm:s2,parameters:se.serialize(new gc)});var rs=class{hashAlgorithm=new te(Ds);maskGenAlgorithm=new te({algorithm:Ui,parameters:se.serialize(Ds)});saltLength=20;trailerField=1;constructor(e={}){Object.assign(this,e)}};d([m({type:te,context:0,defaultValue:Ds})],rs.prototype,"hashAlgorithm",void 0);d([m({type:te,context:1,defaultValue:p0})],rs.prototype,"maskGenAlgorithm",void 0);d([m({type:w.Integer,context:2,defaultValue:20})],rs.prototype,"saltLength",void 0);d([m({type:w.Integer,context:3,defaultValue:1})],rs.prototype,"trailerField",void 0);var eF=new te({algorithm:Li,parameters:se.serialize(new rs)});var aa=class{digestAlgorithm=new te;digest=new Le;constructor(e={}){Object.assign(this,e)}};d([m({type:te})],aa.prototype,"digestAlgorithm",void 0);d([m({type:Le})],aa.prototype,"digest",void 0);var $x,yc=class{prime=new ArrayBuffer(0);exponent=new ArrayBuffer(0);coefficient=new ArrayBuffer(0);constructor(e={}){Object.assign(this,e)}};d([m({type:w.Integer,converter:pt})],yc.prototype,"prime",void 0);d([m({type:w.Integer,converter:pt})],yc.prototype,"exponent",void 0);d([m({type:w.Integer,converter:pt})],yc.prototype,"coefficient",void 0);var x0=$x=class extends Re{constructor(e){super(e),Object.setPrototypeOf(this,$x.prototype)}};x0=$x=d([O({type:k.Sequence,itemType:yc})],x0);var mn=class{version=0;modulus=new ArrayBuffer(0);publicExponent=new ArrayBuffer(0);privateExponent=new ArrayBuffer(0);prime1=new ArrayBuffer(0);prime2=new ArrayBuffer(0);exponent1=new ArrayBuffer(0);exponent2=new ArrayBuffer(0);coefficient=new ArrayBuffer(0);otherPrimeInfos;constructor(e={}){Object.assign(this,e)}};d([m({type:w.Integer})],mn.prototype,"version",void 0);d([m({type:w.Integer,converter:pt})],mn.prototype,"modulus",void 0);d([m({type:w.Integer,converter:pt})],mn.prototype,"publicExponent",void 0);d([m({type:w.Integer,converter:pt})],mn.prototype,"privateExponent",void 0);d([m({type:w.Integer,converter:pt})],mn.prototype,"prime1",void 0);d([m({type:w.Integer,converter:pt})],mn.prototype,"prime2",void 0);d([m({type:w.Integer,converter:pt})],mn.prototype,"exponent1",void 0);d([m({type:w.Integer,converter:pt})],mn.prototype,"exponent2",void 0);d([m({type:w.Integer,converter:pt})],mn.prototype,"coefficient",void 0);d([m({type:x0,optional:!0})],mn.prototype,"otherPrimeInfos",void 0);var bc=class{modulus=new ArrayBuffer(0);publicExponent=new ArrayBuffer(0);constructor(e={}){Object.assign(this,e)}};d([m({type:w.Integer,converter:pt})],bc.prototype,"modulus",void 0);d([m({type:w.Integer,converter:pt})],bc.prototype,"publicExponent",void 0);var Wx;(function(t){t[t.Transient=0]="Transient",t[t.Singleton=1]="Singleton",t[t.ResolutionScoped=2]="ResolutionScoped",t[t.ContainerScoped=3]="ContainerScoped"})(Wx||(Wx={}));var lr=Wx;var Gx=function(t,e){return Gx=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(r,n){r.__proto__=n}||function(r,n){for(var s in n)n.hasOwnProperty(s)&&(r[s]=n[s])},Gx(t,e)};function yf(t,e){Gx(t,e);function r(){this.constructor=t}t.prototype=e===null?Object.create(e):(r.prototype=e.prototype,new r)}function h2(t,e,r,n){function s(i){return i instanceof r?i:new r(function(o){o(i)})}return new(r||(r=Promise))(function(i,o){function a(l){try{f(n.next(l))}catch(p){o(p)}}function c(l){try{f(n.throw(l))}catch(p){o(p)}}function f(l){l.done?i(l.value):s(l.value).then(a,c)}f((n=n.apply(t,e||[])).next())})}function p2(t,e){var r={label:0,sent:function(){if(i[0]&1)throw i[1];return i[1]},trys:[],ops:[]},n,s,i,o;return o={next:a(0),throw:a(1),return:a(2)},typeof Symbol=="function"&&(o[Symbol.iterator]=function(){return this}),o;function a(f){return function(l){return c([f,l])}}function c(f){if(n)throw new TypeError("Generator is already executing.");for(;r;)try{if(n=1,s&&(i=f[0]&2?s.return:f[0]?s.throw||((i=s.return)&&i.call(s),0):s.next)&&!(i=i.call(s,f[1])).done)return i;switch(s=0,i&&(f=[f[0]&2,i.value]),f[0]){case 0:case 1:i=f;break;case 4:return r.label++,{value:f[1],done:!1};case 5:r.label++,s=f[1],f=[0];continue;case 7:f=r.ops.pop(),r.trys.pop();continue;default:if(i=r.trys,!(i=i.length>0&&i[i.length-1])&&(f[0]===6||f[0]===2)){r=0;continue}if(f[0]===3&&(!i||f[1]>i[0]&&f[1]<i[3])){r.label=f[1];break}if(f[0]===6&&r.label<i[1]){r.label=i[1],i=f;break}if(i&&r.label<i[2]){r.label=i[2],r.ops.push(f);break}i[2]&&r.ops.pop(),r.trys.pop();continue}f=e.call(t,r)}catch(l){f=[6,l],s=0}finally{n=i=0}if(f[0]&5)throw f[1];return{value:f[0]?f[1]:void 0,done:!0}}}function bf(t){var e=typeof Symbol=="function"&&Symbol.iterator,r=e&&t[e],n=0;if(r)return r.call(t);if(t&&typeof t.length=="number")return{next:function(){return t&&n>=t.length&&(t=void 0),{value:t&&t[n++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}function vc(t,e){var r=typeof Symbol=="function"&&t[Symbol.iterator];if(!r)return t;var n=r.call(t),s,i=[],o;try{for(;(e===void 0||e-- >0)&&!(s=n.next()).done;)i.push(s.value)}catch(a){o={error:a}}finally{try{s&&!s.done&&(r=n.return)&&r.call(n)}finally{if(o)throw o.error}}return i}function ns(){for(var t=[],e=0;e<arguments.length;e++)t=t.concat(vc(arguments[e]));return t}var oC="injectionTokens";function Xx(t){var e=Reflect.getMetadata("design:paramtypes",t)||[],r=Reflect.getOwnMetadata(oC,t)||{};return Object.keys(r).forEach(function(n){e[+n]=r[n]}),e}function vf(t){return!!t.useClass}function wc(t){return!!t.useFactory}var m0=(function(){function t(e){this.wrap=e,this.reflectMethods=["get","getPrototypeOf","setPrototypeOf","getOwnPropertyDescriptor","defineProperty","has","set","deleteProperty","apply","construct","ownKeys"]}return t.prototype.createProxy=function(e){var r=this,n={},s=!1,i,o=function(){return s||(i=e(r.wrap()),s=!0),i};return new Proxy(n,this.createHandler(o))},t.prototype.createHandler=function(e){var r={},n=function(s){r[s]=function(){for(var i=[],o=0;o<arguments.length;o++)i[o]=arguments[o];i[0]=e();var a=Reflect[s];return a.apply(void 0,ns(i))}};return this.reflectMethods.forEach(n),r},t})();function Di(t){return typeof t=="string"||typeof t=="symbol"}function Yx(t){return typeof t=="object"&&"token"in t&&"multiple"in t}function g0(t){return typeof t=="object"&&"token"in t&&"transform"in t}function x2(t){return typeof t=="function"||t instanceof m0}function ca(t){return!!t.useToken}function ua(t){return t.useValue!=null}function m2(t){return vf(t)||ua(t)||ca(t)||wc(t)}var aC=(function(){function t(){this._registryMap=new Map}return t.prototype.entries=function(){return this._registryMap.entries()},t.prototype.getAll=function(e){return this.ensure(e),this._registryMap.get(e)},t.prototype.get=function(e){this.ensure(e);var r=this._registryMap.get(e);return r[r.length-1]||null},t.prototype.set=function(e,r){this.ensure(e),this._registryMap.get(e).push(r)},t.prototype.setAll=function(e,r){this._registryMap.set(e,r)},t.prototype.has=function(e){return this.ensure(e),this._registryMap.get(e).length>0},t.prototype.clear=function(){this._registryMap.clear()},t.prototype.ensure=function(e){this._registryMap.has(e)||this._registryMap.set(e,[])},t})(),wf=aC;var cC=(function(t){yf(e,t);function e(){return t!==null&&t.apply(this,arguments)||this}return e})(wf),g2=cC;var uC=(function(){function t(){this.scopedResolutions=new Map}return t})(),Sf=uC;function fC(t,e){if(t===null)return"at position #"+e;var r=t.split(",")[e].trim();return'"'+r+'" at position #'+e}function dC(t,e,r){return r===void 0&&(r=" "),ns([t],e.message.split(`
119
+ `).map(function(n){return r+n})).join(`
120
+ `)}function Zx(t,e,r){var n=vc(t.toString().match(/constructor\(([\w, ]+)\)/)||[],2),s=n[1],i=s===void 0?null:s,o=fC(i,e);return dC("Cannot inject the dependency "+o+' of "'+t.name+'" constructor. Reason:',r)}function y2(t){if(typeof t.dispose!="function")return!1;var e=t.dispose;return!(e.length>0)}var lC=(function(t){yf(e,t);function e(){return t!==null&&t.apply(this,arguments)||this}return e})(wf);var hC=(function(t){yf(e,t);function e(){return t!==null&&t.apply(this,arguments)||this}return e})(wf);var pC=(function(){function t(){this.preResolution=new lC,this.postResolution=new hC}return t})(),b2=pC;var Jx=new Map,xC=(function(){function t(e){this.parent=e,this._registry=new g2,this.interceptors=new b2,this.disposed=!1,this.disposables=new Set}return t.prototype.register=function(e,r,n){n===void 0&&(n={lifecycle:lr.Transient}),this.ensureNotDisposed();var s;if(m2(r)?s=r:s={useClass:r},ca(s))for(var i=[e],o=s;o!=null;){var a=o.useToken;if(i.includes(a))throw new Error("Token registration cycle detected! "+ns(i,[a]).join(" -> "));i.push(a);var c=this._registry.get(a);c&&ca(c.provider)?o=c.provider:o=null}if((n.lifecycle===lr.Singleton||n.lifecycle==lr.ContainerScoped||n.lifecycle==lr.ResolutionScoped)&&(ua(s)||wc(s)))throw new Error('Cannot use lifecycle "'+lr[n.lifecycle]+'" with ValueProviders or FactoryProviders');return this._registry.set(e,{provider:s,options:n}),this},t.prototype.registerType=function(e,r){return this.ensureNotDisposed(),Di(r)?this.register(e,{useToken:r}):this.register(e,{useClass:r})},t.prototype.registerInstance=function(e,r){return this.ensureNotDisposed(),this.register(e,{useValue:r})},t.prototype.registerSingleton=function(e,r){if(this.ensureNotDisposed(),Di(e)){if(Di(r))return this.register(e,{useToken:r},{lifecycle:lr.Singleton});if(r)return this.register(e,{useClass:r},{lifecycle:lr.Singleton});throw new Error('Cannot register a type name as a singleton without a "to" token')}var n=e;return r&&!Di(r)&&(n=r),this.register(e,{useClass:n},{lifecycle:lr.Singleton})},t.prototype.resolve=function(e,r,n){r===void 0&&(r=new Sf),n===void 0&&(n=!1),this.ensureNotDisposed();var s=this.getRegistration(e);if(!s&&Di(e)){if(n)return;throw new Error('Attempted to resolve unregistered dependency token: "'+e.toString()+'"')}if(this.executePreResolutionInterceptor(e,"Single"),s){var i=this.resolveRegistration(s,r);return this.executePostResolutionInterceptor(e,i,"Single"),i}if(x2(e)){var i=this.construct(e,r);return this.executePostResolutionInterceptor(e,i,"Single"),i}throw new Error("Attempted to construct an undefined constructor. Could mean a circular dependency problem. Try using `delay` function.")},t.prototype.executePreResolutionInterceptor=function(e,r){var n,s;if(this.interceptors.preResolution.has(e)){var i=[];try{for(var o=bf(this.interceptors.preResolution.getAll(e)),a=o.next();!a.done;a=o.next()){var c=a.value;c.options.frequency!="Once"&&i.push(c),c.callback(e,r)}}catch(f){n={error:f}}finally{try{a&&!a.done&&(s=o.return)&&s.call(o)}finally{if(n)throw n.error}}this.interceptors.preResolution.setAll(e,i)}},t.prototype.executePostResolutionInterceptor=function(e,r,n){var s,i;if(this.interceptors.postResolution.has(e)){var o=[];try{for(var a=bf(this.interceptors.postResolution.getAll(e)),c=a.next();!c.done;c=a.next()){var f=c.value;f.options.frequency!="Once"&&o.push(f),f.callback(e,r,n)}}catch(l){s={error:l}}finally{try{c&&!c.done&&(i=a.return)&&i.call(a)}finally{if(s)throw s.error}}this.interceptors.postResolution.setAll(e,o)}},t.prototype.resolveRegistration=function(e,r){if(this.ensureNotDisposed(),e.options.lifecycle===lr.ResolutionScoped&&r.scopedResolutions.has(e))return r.scopedResolutions.get(e);var n=e.options.lifecycle===lr.Singleton,s=e.options.lifecycle===lr.ContainerScoped,i=n||s,o;return ua(e.provider)?o=e.provider.useValue:ca(e.provider)?o=i?e.instance||(e.instance=this.resolve(e.provider.useToken,r)):this.resolve(e.provider.useToken,r):vf(e.provider)?o=i?e.instance||(e.instance=this.construct(e.provider.useClass,r)):this.construct(e.provider.useClass,r):wc(e.provider)?o=e.provider.useFactory(this):o=this.construct(e.provider,r),e.options.lifecycle===lr.ResolutionScoped&&r.scopedResolutions.set(e,o),o},t.prototype.resolveAll=function(e,r,n){var s=this;r===void 0&&(r=new Sf),n===void 0&&(n=!1),this.ensureNotDisposed();var i=this.getAllRegistrations(e);if(!i&&Di(e)){if(n)return[];throw new Error('Attempted to resolve unregistered dependency token: "'+e.toString()+'"')}if(this.executePreResolutionInterceptor(e,"All"),i){var o=i.map(function(c){return s.resolveRegistration(c,r)});return this.executePostResolutionInterceptor(e,o,"All"),o}var a=[this.construct(e,r)];return this.executePostResolutionInterceptor(e,a,"All"),a},t.prototype.isRegistered=function(e,r){return r===void 0&&(r=!1),this.ensureNotDisposed(),this._registry.has(e)||r&&(this.parent||!1)&&this.parent.isRegistered(e,!0)},t.prototype.reset=function(){this.ensureNotDisposed(),this._registry.clear(),this.interceptors.preResolution.clear(),this.interceptors.postResolution.clear()},t.prototype.clearInstances=function(){var e,r;this.ensureNotDisposed();try{for(var n=bf(this._registry.entries()),s=n.next();!s.done;s=n.next()){var i=vc(s.value,2),o=i[0],a=i[1];this._registry.setAll(o,a.filter(function(c){return!ua(c.provider)}).map(function(c){return c.instance=void 0,c}))}}catch(c){e={error:c}}finally{try{s&&!s.done&&(r=n.return)&&r.call(n)}finally{if(e)throw e.error}}},t.prototype.createChildContainer=function(){var e,r;this.ensureNotDisposed();var n=new t(this);try{for(var s=bf(this._registry.entries()),i=s.next();!i.done;i=s.next()){var o=vc(i.value,2),a=o[0],c=o[1];c.some(function(f){var l=f.options;return l.lifecycle===lr.ContainerScoped})&&n._registry.setAll(a,c.map(function(f){return f.options.lifecycle===lr.ContainerScoped?{provider:f.provider,options:f.options}:f}))}}catch(f){e={error:f}}finally{try{i&&!i.done&&(r=s.return)&&r.call(s)}finally{if(e)throw e.error}}return n},t.prototype.beforeResolution=function(e,r,n){n===void 0&&(n={frequency:"Always"}),this.interceptors.preResolution.set(e,{callback:r,options:n})},t.prototype.afterResolution=function(e,r,n){n===void 0&&(n={frequency:"Always"}),this.interceptors.postResolution.set(e,{callback:r,options:n})},t.prototype.dispose=function(){return h2(this,void 0,void 0,function(){var e;return p2(this,function(r){switch(r.label){case 0:return this.disposed=!0,e=[],this.disposables.forEach(function(n){var s=n.dispose();s&&e.push(s)}),[4,Promise.all(e)];case 1:return r.sent(),[2]}})})},t.prototype.getRegistration=function(e){return this.isRegistered(e)?this._registry.get(e):this.parent?this.parent.getRegistration(e):null},t.prototype.getAllRegistrations=function(e){return this.isRegistered(e)?this._registry.getAll(e):this.parent?this.parent.getAllRegistrations(e):null},t.prototype.construct=function(e,r){var n=this;if(e instanceof m0)return e.createProxy(function(i){return n.resolve(i,r)});var s=(function(){var i=Jx.get(e);if(!i||i.length===0){if(e.length===0)return new e;throw new Error('TypeInfo not known for "'+e.name+'"')}var o=i.map(n.resolveParams(r,e));return new(e.bind.apply(e,ns([void 0],o)))})();return y2(s)&&this.disposables.add(s),s},t.prototype.resolveParams=function(e,r){var n=this;return function(s,i){var o,a,c;try{return Yx(s)?g0(s)?s.multiple?(o=n.resolve(s.transform)).transform.apply(o,ns([n.resolveAll(s.token,new Sf,s.isOptional)],s.transformArgs)):(a=n.resolve(s.transform)).transform.apply(a,ns([n.resolve(s.token,e,s.isOptional)],s.transformArgs)):s.multiple?n.resolveAll(s.token,new Sf,s.isOptional):n.resolve(s.token,e,s.isOptional):g0(s)?(c=n.resolve(s.transform,e)).transform.apply(c,ns([n.resolve(s.token,e)],s.transformArgs)):n.resolve(s,e)}catch(f){throw new Error(Zx(r,i,f))}}},t.prototype.ensureNotDisposed=function(){if(this.disposed)throw new Error("This container has been disposed, you cannot interact with a disposed container")},t})(),Nt=new xC;function mC(t){return function(e){Jx.set(e,Xx(e)),t&&t.token&&(Array.isArray(t.token)?t.token.forEach(function(r){Nt.register(r,e)}):Nt.register(t.token,e))}}var Mi=mC;if(typeof Reflect>"u"||!Reflect.getMetadata)throw new Error(`tsyringe requires a reflect polyfill. Please add 'import "reflect-metadata"' to the top of your entry point.`);var em,fa=class{attrId="";attrValues=[];constructor(e={}){Object.assign(e)}};d([m({type:w.ObjectIdentifier})],fa.prototype,"attrId",void 0);d([m({type:w.Any,repeated:"set"})],fa.prototype,"attrValues",void 0);var v2=em=class extends Re{constructor(e){super(e),Object.setPrototypeOf(this,em.prototype)}};v2=em=d([O({type:k.Sequence,itemType:fa})],v2);var tm,w2=tm=class extends Re{constructor(e){super(e),Object.setPrototypeOf(this,tm.prototype)}};w2=tm=d([O({type:k.Sequence,itemType:xn})],w2);var gC="1.2.840.113549",yC=`${gC}.1`,S2=`${yC}.12`,Sc=`${S2}.1`,D$=`${Sc}.1`,M$=`${Sc}.2`,H$=`${Sc}.3`,j$=`${Sc}.4`,q$=`${Sc}.5`,V$=`${Sc}.6`,da=`${S2}.10.1`;var K$=`${da}.1`,$$=`${da}.2`,W$=`${da}.3`,G$=`${da}.4`,X$=`${da}.5`,Y$=`${da}.6`,y0="1.2.840.113549.1.9";var b0=class{certId="";certValue=new ArrayBuffer(0);constructor(e={}){Object.assign(this,e)}};d([m({type:w.ObjectIdentifier})],b0.prototype,"certId",void 0);d([m({type:w.Any,context:0})],b0.prototype,"certValue",void 0);var E2=`${y0}.22`,tW=`${E2}.1`,rW=`${E2}.2`;var v0=class{crlId="";crltValue=new ArrayBuffer(0);constructor(e={}){Object.assign(this,e)}};d([m({type:w.ObjectIdentifier})],v0.prototype,"crlId",void 0);d([m({type:w.Any,context:0})],v0.prototype,"crltValue",void 0);var bC=`${y0}.23`,aW=`${bC}.1`;var w0=class extends Le{},Hi=class{encryptionAlgorithm=new te;encryptedData=new w0;constructor(e={}){Object.assign(this,e)}};d([m({type:te})],Hi.prototype,"encryptionAlgorithm",void 0);d([m({type:w0})],Hi.prototype,"encryptedData",void 0);var rm,nm;(function(t){t[t.v1=0]="v1"})(nm||(nm={}));var S0=class extends Le{},sm=rm=class extends Re{constructor(e){super(e),Object.setPrototypeOf(this,rm.prototype)}};sm=rm=d([O({type:k.Sequence,itemType:cr})],sm);var ji=class{version=nm.v1;privateKeyAlgorithm=new te;privateKey=new S0;attributes;constructor(e={}){Object.assign(this,e)}};d([m({type:w.Integer})],ji.prototype,"version",void 0);d([m({type:te})],ji.prototype,"privateKeyAlgorithm",void 0);d([m({type:S0})],ji.prototype,"privateKey",void 0);d([m({type:sm,implicit:!0,context:0,optional:!0})],ji.prototype,"attributes",void 0);var A2=class extends ji{};A2=d([O({type:k.Sequence})],A2);var C2=class extends Hi{};C2=d([O({type:k.Sequence})],C2);var E0=class{secretTypeId="";secretValue=new ArrayBuffer(0);constructor(e={}){Object.assign(this,e)}};d([m({type:w.ObjectIdentifier})],E0.prototype,"secretTypeId",void 0);d([m({type:w.Any,context:0})],E0.prototype,"secretValue",void 0);var qi=class{mac=new aa;macSalt=new Le;iterations=1;constructor(e={}){Object.assign(this,e)}};d([m({type:aa})],qi.prototype,"mac",void 0);d([m({type:Le})],qi.prototype,"macSalt",void 0);d([m({type:w.Integer,defaultValue:1})],qi.prototype,"iterations",void 0);var la=class{version=3;authSafe=new xn;macData=new qi;constructor(e={}){Object.assign(this,e)}};d([m({type:w.Integer})],la.prototype,"version",void 0);d([m({type:xn})],la.prototype,"authSafe",void 0);d([m({type:qi,optional:!0})],la.prototype,"macData",void 0);var im,Ec=class{bagId="";bagValue=new ArrayBuffer(0);bagAttributes;constructor(e={}){Object.assign(this,e)}};d([m({type:w.ObjectIdentifier})],Ec.prototype,"bagId",void 0);d([m({type:w.Any,context:0})],Ec.prototype,"bagValue",void 0);d([m({type:fa,repeated:"set",optional:!0})],Ec.prototype,"bagAttributes",void 0);var I2=im=class extends Re{constructor(e){super(e),Object.setPrototypeOf(this,im.prototype)}};I2=im=d([O({type:k.Sequence,itemType:Ec})],I2);var om,am,cm,Kt="1.2.840.113549.1.9",uG=`${Kt}.0`,j2=`${Kt}.24`,Af=`${Kt}.25`,q2=`${Kt}.26`,V2=`${Kt}.27`,fG=`${j2}.1`,dG=`${j2}.2`,lG=`${Kt}.1`,hG=`${Kt}.2`,pG=`${Kt}.3`,xG=`${Kt}.4`,mG=`${Kt}.5`,gG=`${Kt}.6`,mm=`${Kt}.7`,yG=`${Kt}.8`,bG=`${Kt}.9`,vG=`${Kt}.13`,Cf=`${Kt}.14`,wG=`${Kt}.15`,SG=`${Kt}.20`,EG=`${Kt}.21`;var AG=`${Af}.1`,CG=`${Af}.2`,IG=`${Af}.3`,TG=`${Af}.4`,_G=`${Af}.5`,If="1.3.6.1.5.5.7.9",BG=`${If}.1`,kG=`${If}.2`,RG=`${If}.3`,NG=`${If}.4`,PG=`${If}.5`,OG=`${q2}.1`,LG=`${q2}.2`,UG=`${V2}.1`,DG=`${V2}.2`,MG=`${Kt}.16`,HG=`${Kt}.22`,jG=`${Kt}.23`,qG=`${_x}.65`,A0=class extends Zt{ia5String;constructor(e={}){super(e)}toString(){return{}.toString(),this.ia5String||super.toString()}};d([m({type:w.IA5String})],A0.prototype,"ia5String",void 0);A0=d([O({type:k.Choice})],A0);var T2=class extends xn{};T2=d([O({type:k.Sequence})],T2);var _2=class extends la{};_2=d([O({type:k.Sequence})],_2);var B2=class extends Hi{};B2=d([O({type:k.Sequence})],B2);var um=class{value;constructor(e=""){this.value=e}toString(){return this.value}};d([m({type:w.IA5String})],um.prototype,"value",void 0);um=d([O({type:k.Choice})],um);var k2=class extends A0{};k2=d([O({type:k.Choice})],k2);var R2=class extends Zt{};R2=d([O({type:k.Choice})],R2);var fm=class{value;constructor(e=new Date){this.value=e}};d([m({type:w.GeneralizedTime})],fm.prototype,"value",void 0);fm=d([O({type:k.Choice})],fm);var N2=class extends Zt{};N2=d([O({type:k.Choice})],N2);var dm=class{value;constructor(e="M"){this.value=e}toString(){return this.value}};d([m({type:w.PrintableString})],dm.prototype,"value",void 0);dm=d([O({type:k.Choice})],dm);var C0=class{value;constructor(e=""){this.value=e}toString(){return this.value}};d([m({type:w.PrintableString})],C0.prototype,"value",void 0);C0=d([O({type:k.Choice})],C0);var P2=class extends C0{};P2=d([O({type:k.Choice})],P2);var O2=class extends Zt{};O2=d([O({type:k.Choice})],O2);var lm=class{value;constructor(e=""){this.value=e}toString(){return this.value}};d([m({type:w.ObjectIdentifier})],lm.prototype,"value",void 0);lm=d([O({type:k.Choice})],lm);var L2=class extends Ft{};L2=d([O({type:k.Choice})],L2);var hm=class{value;constructor(e=0){this.value=e}toString(){return this.value.toString()}};d([m({type:w.Integer})],hm.prototype,"value",void 0);hm=d([O({type:k.Choice})],hm);var U2=class extends Mr{};U2=d([O({type:k.Sequence})],U2);var Ef=class extends Zt{};Ef=d([O({type:k.Choice})],Ef);var D2=om=class extends Yr{constructor(e){super(e),Object.setPrototypeOf(this,om.prototype)}};D2=om=d([O({type:k.Sequence})],D2);var M2=am=class extends Re{constructor(e){super(e),Object.setPrototypeOf(this,am.prototype)}};M2=am=d([O({type:k.Set,itemType:Cn})],M2);var pm=class{value;constructor(e=""){this.value=e}toString(){return this.value}};d([m({type:w.BmpString})],pm.prototype,"value",void 0);pm=d([O({type:k.Choice})],pm);var xm=class extends te{};xm=d([O({type:k.Sequence})],xm);var H2=cm=class extends Re{constructor(e){super(e),Object.setPrototypeOf(this,cm.prototype)}};H2=cm=d([O({type:k.Sequence,itemType:xm})],H2);var gm,Tf=gm=class extends Re{constructor(e){super(e),Object.setPrototypeOf(this,gm.prototype)}};Tf=gm=d([O({type:k.Sequence,itemType:cr})],Tf);var ss=class{version=0;subject=new Bt;subjectPKInfo=new ur;attributes=new Tf;constructor(e={}){Object.assign(this,e)}};d([m({type:w.Integer})],ss.prototype,"version",void 0);d([m({type:Bt})],ss.prototype,"subject",void 0);d([m({type:ur})],ss.prototype,"subjectPKInfo",void 0);d([m({type:Tf,implicit:!0,context:0,optional:!0})],ss.prototype,"attributes",void 0);var Vi=class{certificationRequestInfo=new ss;certificationRequestInfoRaw;signatureAlgorithm=new te;signature=new ArrayBuffer(0);constructor(e={}){Object.assign(this,e)}};d([m({type:ss,raw:!0})],Vi.prototype,"certificationRequestInfo",void 0);d([m({type:te})],Vi.prototype,"signatureAlgorithm",void 0);d([m({type:w.BitString})],Vi.prototype,"signature",void 0);var Zf="crypto.algorithm",Tm=class{getAlgorithms(){return Nt.resolveAll(Zf)}toAsnAlgorithm(e){({...e});for(let r of this.getAlgorithms()){let n=r.toAsnAlgorithm(e);if(n)return n}if(/^[0-9.]+$/.test(e.name)){let r=new te({algorithm:e.name});if("parameters"in e){let n=e;r.parameters=n.parameters}return r}throw new Error("Cannot convert WebCrypto algorithm to ASN.1 algorithm")}toWebAlgorithm(e){for(let n of this.getAlgorithms()){let s=n.toWebAlgorithm(e);if(s)return s}return{name:e.algorithm,parameters:e.parameters}}},ha="crypto.algorithmProvider";Nt.registerSingleton(ha,Tm);var B0,Vr="1.3.36.3.3.2.8.1.1",z2=`${Vr}.1`,F2=`${Vr}.2`,K2=`${Vr}.3`,$2=`${Vr}.4`,W2=`${Vr}.5`,G2=`${Vr}.6`,X2=`${Vr}.7`,Y2=`${Vr}.8`,Z2=`${Vr}.9`,J2=`${Vr}.10`,Q2=`${Vr}.11`,ev=`${Vr}.12`,tv=`${Vr}.13`,rv=`${Vr}.14`,nv="brainpoolP160r1",sv="brainpoolP160t1",iv="brainpoolP192r1",ov="brainpoolP192t1",av="brainpoolP224r1",cv="brainpoolP224t1",uv="brainpoolP256r1",fv="brainpoolP256t1",dv="brainpoolP320r1",lv="brainpoolP320t1",hv="brainpoolP384r1",pv="brainpoolP384t1",xv="brainpoolP512r1",mv="brainpoolP512t1",Mt="ECDSA",Wf=B0=class{toAsnAlgorithm(e){switch(e.name.toLowerCase()){case Mt.toLowerCase():if("hash"in e)switch((typeof e.hash=="string"?e.hash:e.hash.name).toLowerCase()){case"sha-1":return e2;case"sha-256":return t2;case"sha-384":return r2;case"sha-512":return n2}else if("namedCurve"in e){let r="";switch(e.namedCurve){case"P-256":r=Mx;break;case"K-256":r=B0.SECP256K1;break;case"P-384":r=Hx;break;case"P-521":r=jx;break;case nv:r=z2;break;case sv:r=F2;break;case iv:r=K2;break;case ov:r=$2;break;case av:r=W2;break;case cv:r=G2;break;case uv:r=X2;break;case fv:r=Y2;break;case dv:r=Z2;break;case lv:r=J2;break;case hv:r=Q2;break;case pv:r=ev;break;case xv:r=tv;break;case mv:r=rv;break}if(r)return new te({algorithm:ta,parameters:se.serialize(new es({namedCurve:r}))})}}return null}toWebAlgorithm(e){switch(e.algorithm){case lf:return{name:Mt,hash:{name:"SHA-1"}};case hf:return{name:Mt,hash:{name:"SHA-256"}};case pf:return{name:Mt,hash:{name:"SHA-384"}};case xf:return{name:Mt,hash:{name:"SHA-512"}};case ta:{if(!e.parameters)throw new TypeError("Cannot get required parameters from EC algorithm");switch(se.parse(e.parameters,es).namedCurve){case Mx:return{name:Mt,namedCurve:"P-256"};case B0.SECP256K1:return{name:Mt,namedCurve:"K-256"};case Hx:return{name:Mt,namedCurve:"P-384"};case jx:return{name:Mt,namedCurve:"P-521"};case z2:return{name:Mt,namedCurve:nv};case F2:return{name:Mt,namedCurve:sv};case K2:return{name:Mt,namedCurve:iv};case $2:return{name:Mt,namedCurve:ov};case W2:return{name:Mt,namedCurve:av};case G2:return{name:Mt,namedCurve:cv};case X2:return{name:Mt,namedCurve:uv};case Y2:return{name:Mt,namedCurve:fv};case Z2:return{name:Mt,namedCurve:dv};case J2:return{name:Mt,namedCurve:lv};case Q2:return{name:Mt,namedCurve:hv};case ev:return{name:Mt,namedCurve:pv};case tv:return{name:Mt,namedCurve:xv};case rv:return{name:Mt,namedCurve:mv}}}}return null}};Wf.SECP256K1="1.3.132.0.10";Wf=B0=d([Mi()],Wf);Nt.registerSingleton(Zf,Wf);var Tv=Symbol("name"),_v=Symbol("value"),gt=class{constructor(e,r={},n=""){this[Tv]=e,this[_v]=n;for(let s in r)this[s]=r[s]}};gt.NAME=Tv;gt.VALUE=_v;var _m=class{static toTextObject(e){let r=new gt("Algorithm Identifier",{},os.toString(e.algorithm));if(e.parameters)if(e.algorithm===ta){let n=new Wf().toWebAlgorithm(e);n&&"namedCurve"in n?r["Named Curve"]=n.namedCurve:r.Parameters=e.parameters}else r.Parameters=e.parameters;return r}},os=class{static toString(e){let r=this.items[e];return r||e}};os.items={[na]:"sha1",[h0]:"sha224",[sa]:"sha256",[ia]:"sha384",[oa]:"sha512",[ts]:"rsaEncryption",[pc]:"sha1WithRSAEncryption",[c2]:"sha224WithRSAEncryption",[l0]:"sha256WithRSAEncryption",[xc]:"sha384WithRSAEncryption",[mc]:"sha512WithRSAEncryption",[ta]:"ecPublicKey",[lf]:"ecdsaWithSHA1",[d0]:"ecdsaWithSHA224",[hf]:"ecdsaWithSHA256",[pf]:"ecdsaWithSHA384",[xf]:"ecdsaWithSHA512",[Lb]:"TLS WWW server authentication",[Ub]:"TLS WWW client authentication",[Db]:"Code Signing",[Mb]:"E-mail Protection",[Hb]:"Time Stamping",[jb]:"OCSP Signing",[Jb]:"Signed Data"};var Hs=class{static serialize(e){return this.serializeObj(e).join(`
121
+ `)}static pad(e=0){return"".padStart(2*e," ")}static serializeObj(e,r=0){let n=[],s=this.pad(r++),i="",o=e[gt.VALUE];o&&(i=` ${o}`),n.push(`${s}${e[gt.NAME]}:${i}`),s=this.pad(r);for(let a in e){if(typeof a=="symbol")continue;let c=e[a],f=a?`${a}: `:"";if(typeof c=="string"||typeof c=="number"||typeof c=="boolean")n.push(`${s}${f}${c}`);else if(c instanceof Date)n.push(`${s}${f}${c.toUTCString()}`);else if(Array.isArray(c))for(let l of c)l[gt.NAME]=a,n.push(...this.serializeObj(l,r));else if(c instanceof gt)c[gt.NAME]=a,n.push(...this.serializeObj(c,r));else if(ce.isBufferSource(c))a?(n.push(`${s}${f}`),n.push(...this.serializeBufferSource(c,r+1))):n.push(...this.serializeBufferSource(c,r));else if("toTextObject"in c){let l=c.toTextObject();l[gt.NAME]=a,n.push(...this.serializeObj(l,r))}else throw new TypeError("Cannot serialize data in text format. Unsupported type.")}return n}static serializeBufferSource(e,r=0){let n=this.pad(r),s=ce.toUint8Array(e),i=[];for(let o=0;o<s.length;){let a=[];for(let c=0;c<16&&o<s.length;c++){c===8&&a.push("");let f=s[o++].toString(16).padStart(2,"0");a.push(f)}i.push(`${n}${a.join(" ")}`)}return i}static serializeAlgorithm(e){return this.algorithmSerializer.toTextObject(e)}};Hs.oidSerializer=os;Hs.algorithmSerializer=_m;var Ac,zi=class t{get rawData(){return et(this,Ac,"f")||Ot(this,Ac,se.serialize(this.asn),"f"),et(this,Ac,"f")}constructor(...e){Ac.set(this,void 0),ce.isBufferSource(e[0])?(this.asn=se.parse(e[0],e[1]),Ot(this,Ac,ce.toArrayBuffer(e[0]),"f"),this.onInit(this.asn)):(this.asn=e[0],this.onInit(this.asn))}equal(e){return e instanceof t?ky(e.rawData,this.rawData):!1}toString(e="text"){switch(e){case"asn":return se.toString(this.rawData);case"text":return Hs.serialize(this.toTextObject());case"hex":return ke.ToHex(this.rawData);case"base64":return ke.ToBase64(this.rawData);case"base64url":return ke.ToBase64Url(this.rawData);default:throw TypeError("Argument 'format' is unsupported value")}}getTextName(){return this.constructor.NAME}toTextObject(){let e=this.toTextObjectEmpty();return e[""]=this.rawData,e}toTextObjectEmpty(e){return new gt(this.getTextName(),{},e)}};Ac=new WeakMap;zi.NAME="ASN";var Jr=class t extends zi{constructor(...e){let r;ce.isBufferSource(e[0])?r=ce.toArrayBuffer(e[0]):r=se.serialize(new Ar({extnID:e[0],critical:e[1],extnValue:new Le(ce.toArrayBuffer(e[2]))})),super(r,Ar)}onInit(e){this.type=e.extnID,this.critical=e.critical,this.value=e.extnValue.buffer}toTextObject(){let e=this.toTextObjectWithoutValue();return e[""]=this.value,e}toTextObjectWithoutValue(){let e=this.toTextObjectEmpty(this.critical?"critical":void 0);return e[gt.NAME]===t.NAME&&(e[gt.NAME]=os.toString(this.type)),e}},Bv,Gf=class t{static isCryptoKeyPair(e){return e&&e.privateKey&&e.publicKey}static isCryptoKey(e){return e&&e.usages&&e.type&&e.algorithm&&e.extractable!==void 0}constructor(){this.items=new Map,this[Bv]="CryptoProvider",typeof self<"u"&&typeof crypto<"u"?this.set(t.DEFAULT,crypto):typeof global<"u"&&global.crypto&&global.crypto.subtle&&this.set(t.DEFAULT,global.crypto)}clear(){this.items.clear()}delete(e){return this.items.delete(e)}forEach(e,r){return this.items.forEach(e,r)}has(e){return this.items.has(e)}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(e=t.DEFAULT){let r=this.items.get(e.toLowerCase());if(!r)throw new Error(`Cannot get Crypto by name '${e}'`);return r}set(e,r){if(typeof e=="string"){if(!r)throw new TypeError("Argument 'value' is required");this.items.set(e.toLowerCase(),r)}else this.items.set(t.DEFAULT,e);return this}};Bv=Symbol.toStringTag;Gf.DEFAULT="default";var Jt=new Gf,EC=/^[0-2](?:\.[1-9][0-9]*)+$/;function AC(t){return new RegExp(EC).test(t)}var R0=class{constructor(e={}){this.items={};for(let r in e)this.register(r,e[r])}get(e){return this.items[e]||null}findId(e){return AC(e)?e:this.get(e)}register(e,r){this.items[e]=r,this.items[r]=e}},qr=new R0;qr.register("CN","2.5.4.3");qr.register("L","2.5.4.7");qr.register("ST","2.5.4.8");qr.register("O","2.5.4.10");qr.register("OU","2.5.4.11");qr.register("C","2.5.4.6");qr.register("DC","0.9.2342.19200300.100.1.25");qr.register("E","1.2.840.113549.1.9.1");qr.register("G","2.5.4.42");qr.register("I","2.5.4.43");qr.register("SN","2.5.4.4");qr.register("T","2.5.4.12");function CC(t,e){return`\\${ke.ToHex(ke.FromUtf8String(e)).toUpperCase()}`}function IC(t){return t.replace(/([,+"\\<>;])/g,"\\$1").replace(/^([ #])/,"\\$1").replace(/([ ]$)/,"\\$1").replace(/([\r\n\t])/,CC)}var In=class t{static isASCII(e){for(let r=0;r<e.length;r++)if(e.charCodeAt(r)>255)return!1;return!0}static isPrintableString(e){return/^[A-Za-z0-9 '()+,-./:=?]*$/g.test(e)}constructor(e,r={}){this.extraNames=new R0,this.asn=new Bt;for(let n in r)if(Object.prototype.hasOwnProperty.call(r,n)){let s=r[n];this.extraNames.register(n,s)}typeof e=="string"?this.asn=this.fromString(e):e instanceof Bt?this.asn=e:ce.isBufferSource(e)?this.asn=se.parse(e,Bt):this.asn=this.fromJSON(e)}getField(e){let r=this.extraNames.findId(e)||qr.findId(e),n=[];for(let s of this.asn)for(let i of s)i.type===r&&n.push(i.value.toString());return n}getName(e){return this.extraNames.get(e)||qr.get(e)}toString(){return this.asn.map(e=>e.map(r=>{let n=this.getName(r.type)||r.type,s=r.value.anyValue?`#${ke.ToHex(r.value.anyValue)}`:IC(r.value.toString());return`${n}=${s}`}).join("+")).join(", ")}toJSON(){var e;let r=[];for(let n of this.asn){let s={};for(let i of n){let o=this.getName(i.type)||i.type;(e=s[o])!==null&&e!==void 0||(s[o]=[]),s[o].push(i.value.anyValue?`#${ke.ToHex(i.value.anyValue)}`:i.value.toString())}r.push(s)}return r}fromString(e){let r=new Bt,n=/(\d\.[\d.]*\d|[A-Za-z]+)=((?:"")|(?:".*?[^\\]")|(?:[^,+"\\](?=[,+]|$))|(?:[^,+].*?(?:[^\\][,+]))|(?:))([,+])?/g,s=null,i=",";for(;s=n.exec(`${e},`);){let[,o,a]=s,c=a[a.length-1];(c===","||c==="+")&&(a=a.slice(0,a.length-1),s[3]=c);let f=s[3];o=this.getTypeOid(o);let l=this.createAttribute(o,a);i==="+"?r[r.length-1].push(l):r.push(new Ai([l])),i=f}return r}fromJSON(e){let r=new Bt;for(let n of e){let s=new Ai;for(let i in n){let o=this.getTypeOid(i),a=n[i];for(let c of a){let f=this.createAttribute(o,c);s.push(f)}}r.push(s)}return r}getTypeOid(e){if(/[\d.]+/.test(e)||(e=this.getName(e)||""),!e)throw new Error(`Cannot get OID for name type '${e}'`);return e}createAttribute(e,r){let n=new Lo({type:e});if(typeof r=="object")for(let s in r)switch(s){case"ia5String":n.value.ia5String=r[s];break;case"utf8String":n.value.utf8String=r[s];break;case"universalString":n.value.universalString=r[s];break;case"bmpString":n.value.bmpString=r[s];break;case"printableString":n.value.printableString=r[s];break}else if(r[0]==="#")n.value.anyValue=ke.FromHex(r.slice(1));else{let s=this.processStringValue(r);e===this.getName("E")||e===this.getName("DC")?n.value.ia5String=s:t.isPrintableString(s)?n.value.printableString=s:n.value.utf8String=s}return n}processStringValue(e){let r=/"(.*?[^\\])?"/.exec(e);return r&&(e=r[1]),e.replace(/\\0a/ig,`
122
+ `).replace(/\\0d/ig,"\r").replace(/\\0g/ig," ").replace(/\\(.)/g,"$1")}toArrayBuffer(){return se.serialize(this.asn)}async getThumbprint(...e){var r;let n,s="SHA-1";return e.length>=1&&!(!((r=e[0])===null||r===void 0)&&r.subtle)?(s=e[0]||s,n=e[1]||Jt.get()):n=e[0]||Jt.get(),await n.subtle.digest(s,this.toArrayBuffer())}},kv="Cannot initialize GeneralName from ASN.1 data.",gv=`${kv} Unsupported string format in use.`,TC=`${kv} Value doesn't match to GUID regular expression.`,yv=/^([0-9a-f]{8})-?([0-9a-f]{4})-?([0-9a-f]{4})-?([0-9a-f]{4})-?([0-9a-f]{12})$/i,bv="1.3.6.1.4.1.311.25.1",vv="1.3.6.1.4.1.311.20.2.3",ym="dns",bm="dn",vm="email",wm="ip",Sm="url",Em="guid",Am="upn",I0="id",is=class extends zi{constructor(...e){let r;if(e.length===2)switch(e[0]){case bm:{let n=new In(e[1]).toArrayBuffer(),s=se.parse(n,Bt);r=new je({directoryName:s});break}case ym:r=new je({dNSName:e[1]});break;case vm:r=new je({rfc822Name:e[1]});break;case Em:{let n=new RegExp(yv,"i").exec(e[1]);if(!n)throw new Error("Cannot parse GUID value. Value doesn't match to regular expression");let s=n.slice(1).map((i,o)=>o<3?ke.ToHex(new Uint8Array(ke.FromHex(i)).reverse()):i).join("");r=new je({otherName:new Ci({typeId:bv,value:se.serialize(new Le(ke.FromHex(s)))})});break}case wm:r=new je({iPAddress:e[1]});break;case I0:r=new je({registeredID:e[1]});break;case Am:{r=new je({otherName:new Ci({typeId:vv,value:se.serialize(Wp.toASN(e[1]))})});break}case Sm:r=new je({uniformResourceIdentifier:e[1]});break;default:throw new Error("Cannot create GeneralName. Unsupported type of the name")}else ce.isBufferSource(e[0])?r=se.parse(e[0],je):r=e[0];super(r)}onInit(e){if(e.dNSName!=null)this.type=ym,this.value=e.dNSName;else if(e.rfc822Name!=null)this.type=vm,this.value=e.rfc822Name;else if(e.iPAddress!=null)this.type=wm,this.value=e.iPAddress;else if(e.uniformResourceIdentifier!=null)this.type=Sm,this.value=e.uniformResourceIdentifier;else if(e.registeredID!=null)this.type=I0,this.value=e.registeredID;else if(e.directoryName!=null)this.type=bm,this.value=new In(e.directoryName).toString();else if(e.otherName!=null)if(e.otherName.typeId===bv){this.type=Em;let r=se.parse(e.otherName.value,Le),n=new RegExp(yv,"i").exec(ke.ToHex(r));if(!n)throw new Error(TC);this.value=n.slice(1).map((s,i)=>i<3?ke.ToHex(new Uint8Array(ke.FromHex(s)).reverse()):s).join("-")}else if(e.otherName.typeId===vv)this.type=Am,this.value=se.parse(e.otherName.value,Zt).toString();else throw new Error(gv);else throw new Error(gv)}toJSON(){return{type:this.type,value:this.value}}toTextObject(){let e;switch(this.type){case bm:case ym:case Em:case wm:case I0:case Am:case Sm:e=this.type.toUpperCase();break;case vm:e="Email";break;default:throw new Error("Unsupported GeneralName type")}let r=this.value;return this.type===I0&&(r=os.toString(r)),new gt(e,void 0,r)}},js=class extends zi{constructor(e){let r;if(e instanceof Lt)r=e;else if(Array.isArray(e)){let n=[];for(let s of e)if(s instanceof je)n.push(s);else{let i=se.parse(new is(s.type,s.value).rawData,je);n.push(i)}r=new Lt(n)}else if(ce.isBufferSource(e))r=se.parse(e,Lt);else throw new Error("Cannot initialize GeneralNames. Incorrect incoming arguments");super(r)}onInit(e){let r=[];for(let n of e){let s=null;try{s=new is(n)}catch{continue}r.push(s)}this.items=r}toJSON(){return this.items.map(e=>e.toJSON())}toTextObject(){let e=super.toTextObjectEmpty();for(let r of this.items){let n=r.toTextObject(),s=e[n[gt.NAME]];Array.isArray(s)||(s=[],e[n[gt.NAME]]=s),s.push(n)}return e}};js.NAME="GeneralNames";var $f="-{5}",Xf="\\n",_C=`[^${Xf}]+`,BC=`${$f}BEGIN (${_C}(?=${$f}))${$f}`,kC=`${$f}END \\1${$f}`,Tc="\\n",RC=`[^:${Xf}]+`,NC=`(?:[^${Xf}]+${Tc}(?: +[^${Xf}]+${Tc})*)`,PC="[a-zA-Z0-9=+/]+",OC=`(?:${PC}${Tc})+`,wv=`${BC}${Tc}(?:((?:${RC}: ${NC})+))?${Tc}?(${OC})${kC}`,hr=class{static isPem(e){return typeof e=="string"&&new RegExp(wv,"g").test(e.replace(/\r/g,""))}static decodeWithHeaders(e){e=e.replace(/\r/g,"");let r=new RegExp(wv,"g"),n=[],s=null;for(;s=r.exec(e);){let i=s[3].replace(new RegExp(`[${Xf}]+`,"g"),""),o={type:s[1],headers:[],rawData:ke.FromBase64(i)},a=s[2];if(a){let c=a.split(new RegExp(Tc,"g")),f=null;for(let l of c){let[p,x]=l.split(/:(.*)/);if(x===void 0){if(!f)throw new Error("Cannot parse PEM string. Incorrect header value");f.value+=p.trim()}else f&&o.headers.push(f),f={key:p,value:x.trim()}}f&&o.headers.push(f)}n.push(o)}return n}static decode(e){return this.decodeWithHeaders(e).map(n=>n.rawData)}static decodeFirst(e){let r=this.decode(e);if(!r.length)throw new RangeError("PEM string doesn't contain any objects");return r[0]}static encode(e,r){if(Array.isArray(e)){let n=new Array;return r?e.forEach(s=>{if(!ce.isBufferSource(s))throw new TypeError("Cannot encode array of BufferSource in PEM format. Not all items of the array are BufferSource");n.push(this.encodeStruct({type:r,rawData:ce.toArrayBuffer(s)}))}):e.forEach(s=>{if(!("type"in s))throw new TypeError("Cannot encode array of PemStruct in PEM format. Not all items of the array are PemStrut");n.push(this.encodeStruct(s))}),n.join(`
123
+ `)}else{if(!r)throw new Error("Required argument 'tag' is missed");return this.encodeStruct({type:r,rawData:ce.toArrayBuffer(e)})}}static encodeStruct(e){var r;let n=e.type.toLocaleUpperCase(),s=[];if(s.push(`-----BEGIN ${n}-----`),!((r=e.headers)===null||r===void 0)&&r.length){for(let f of e.headers)s.push(`${f.key}: ${f.value}`);s.push("")}let i=ke.ToBase64(e.rawData),o,a=0,c=Array();for(;a<i.length&&(i.length-a<64?o=i.substring(a):(o=i.substring(a,a+64),a+=64),o.length!==0);)if(c.push(o),o.length<64)break;return s.push(...c),s.push(`-----END ${n}-----`),s.join(`
124
+ `)}};hr.CertificateTag="CERTIFICATE";hr.CrlTag="CRL";hr.CertificateRequestTag="CERTIFICATE REQUEST";hr.PublicKeyTag="PUBLIC KEY";hr.PrivateKeyTag="PRIVATE KEY";var Fi=class t extends zi{static isAsnEncoded(e){return ce.isBufferSource(e)||typeof e=="string"}static toArrayBuffer(e){if(typeof e=="string"){if(hr.isPem(e))return hr.decode(e)[0];if(ke.isHex(e))return ke.FromHex(e);if(ke.isBase64(e))return ke.FromBase64(e);if(ke.isBase64Url(e))return ke.FromBase64Url(e);throw new TypeError("Unsupported format of 'raw' argument. Must be one of DER, PEM, HEX, Base64, or Base4Url")}else{let r=ce.toUint8Array(e);if(r.length>0&&r[0]===48)return ce.toArrayBuffer(e);let n=ke.ToBinary(e);if(hr.isPem(n))return hr.decode(n)[0];if(ke.isHex(n))return ke.FromHex(n);if(ke.isBase64(n))return ke.FromBase64(n);if(ke.isBase64Url(n))return ke.FromBase64Url(n);throw new TypeError("Unsupported format of 'raw' argument. Must be one of DER, PEM, HEX, Base64, or Base4Url")}}constructor(...e){t.isAsnEncoded(e[0])?super(t.toArrayBuffer(e[0]),e[1]):super(e[0])}toString(e="pem"){return e==="pem"?hr.encode(this.rawData,this.tag):super.toString(e)}},Ms=class t extends Fi{static async create(e,r=Jt.get()){if(e instanceof t)return e;if(Gf.isCryptoKey(e)){if(e.type!=="public")throw new TypeError("Public key is required");let n=await r.subtle.exportKey("spki",e);return new t(n)}else{if(e.publicKey)return e.publicKey;if(ce.isBufferSource(e))return new t(e);throw new TypeError("Unsupported PublicKeyType")}}constructor(e){Fi.isAsnEncoded(e)?super(e,ur):super(e),this.tag=hr.PublicKeyTag}async export(...e){let r,n=["verify"],s={hash:"SHA-256",...this.algorithm};e.length>1?(s=e[0]||s,n=e[1]||n,r=e[2]||Jt.get()):r=e[0]||Jt.get();let i=this.rawData,o=se.parse(this.rawData,ur);return o.algorithm.algorithm===Li&&(i=LC(o,i)),r.subtle.importKey("spki",i,s,!0,n)}onInit(e){let r=Nt.resolve(ha),n=this.algorithm=r.toWebAlgorithm(e.algorithm);if(e.algorithm.algorithm===ts){let s=se.parse(e.subjectPublicKey,bc),i=ce.toUint8Array(s.modulus);n.publicExponent=ce.toUint8Array(s.publicExponent),n.modulusLength=(i[0]?i:i.slice(1)).byteLength<<3}}async getThumbprint(...e){var r;let n,s="SHA-1";return e.length>=1&&!(!((r=e[0])===null||r===void 0)&&r.subtle)?(s=e[0]||s,n=e[1]||Jt.get()):n=e[0]||Jt.get(),await n.subtle.digest(s,this.rawData)}async getKeyIdentifier(...e){let r,n="SHA-1";e.length===1?typeof e[0]=="string"?(n=e[0],r=Jt.get()):r=e[0]:e.length===2?(n=e[0],r=e[1]):r=Jt.get();let s=se.parse(this.rawData,ur);return await r.subtle.digest(n,s.subjectPublicKey)}toTextObject(){let e=this.toTextObjectEmpty(),r=se.parse(this.rawData,ur);switch(e.Algorithm=Hs.serializeAlgorithm(r.algorithm),r.algorithm.algorithm){case ta:e["EC Point"]=r.subjectPublicKey;break;case ts:default:e["Raw Data"]=r.subjectPublicKey}return e}};function LC(t,e){return t.algorithm=new te({algorithm:ts,parameters:null}),e=se.serialize(t),e}var N0=class t extends Jr{static async create(e,r=!1,n=Jt.get()){if("name"in e&&"serialNumber"in e)return new t(e,r);let i=await(await Ms.create(e,n)).getKeyIdentifier(n);return new t(ke.ToHex(i),r)}constructor(...e){if(ce.isBufferSource(e[0]))super(e[0]);else if(typeof e[0]=="string"){let r=new Yn({keyIdentifier:new Mo(ke.FromHex(e[0]))});super(Fl,e[1],se.serialize(r))}else{let r=e[0],n=r.name instanceof js?se.parse(r.name.rawData,Lt):r.name,s=new Yn({authorityCertIssuer:n,authorityCertSerialNumber:ke.FromHex(r.serialNumber)});super(Fl,e[1],se.serialize(s))}}onInit(e){super.onInit(e);let r=se.parse(e.extnValue,Yn);r.keyIdentifier&&(this.keyId=ke.ToHex(r.keyIdentifier)),(r.authorityCertIssuer||r.authorityCertSerialNumber)&&(this.certId={name:r.authorityCertIssuer||[],serialNumber:r.authorityCertSerialNumber?ke.ToHex(r.authorityCertSerialNumber):""})}toTextObject(){let e=this.toTextObjectWithoutValue(),r=se.parse(this.value,Yn);return r.authorityCertIssuer&&(e["Authority Issuer"]=new js(r.authorityCertIssuer).toTextObject()),r.authorityCertSerialNumber&&(e["Authority Serial Number"]=r.authorityCertSerialNumber),r.keyIdentifier&&(e[""]=r.keyIdentifier),e}};N0.NAME="Authority Key Identifier";var P0=class extends Jr{constructor(...e){if(ce.isBufferSource(e[0])){super(e[0]);let r=se.parse(this.value,Ho);this.ca=r.cA,this.pathLength=r.pathLenConstraint}else{let r=new Ho({cA:e[0],pathLenConstraint:e[1]});super(Kl,e[2],se.serialize(r)),this.ca=e[0],this.pathLength=e[1]}}toTextObject(){let e=this.toTextObjectWithoutValue();return this.ca&&(e.CA=this.ca),this.pathLength!==void 0&&(e["Path Length"]=this.pathLength),e}};P0.NAME="Basic Constraints";var Sv;(function(t){t.serverAuth="1.3.6.1.5.5.7.3.1",t.clientAuth="1.3.6.1.5.5.7.3.2",t.codeSigning="1.3.6.1.5.5.7.3.3",t.emailProtection="1.3.6.1.5.5.7.3.4",t.timeStamping="1.3.6.1.5.5.7.3.8",t.ocspSigning="1.3.6.1.5.5.7.3.9"})(Sv||(Sv={}));var O0=class extends Jr{constructor(...e){if(ce.isBufferSource(e[0])){super(e[0]);let r=se.parse(this.value,$u);this.usages=r.map(n=>n)}else{let r=new $u(e[0]);super(Xl,e[1],se.serialize(r)),this.usages=e[0]}}toTextObject(){let e=this.toTextObjectWithoutValue();return e[""]=this.usages.map(r=>os.toString(r)).join(", "),e}};O0.NAME="Extended Key Usages";var Ev;(function(t){t[t.digitalSignature=1]="digitalSignature",t[t.nonRepudiation=2]="nonRepudiation",t[t.keyEncipherment=4]="keyEncipherment",t[t.dataEncipherment=8]="dataEncipherment",t[t.keyAgreement=16]="keyAgreement",t[t.keyCertSign=32]="keyCertSign",t[t.cRLSign=64]="cRLSign",t[t.encipherOnly=128]="encipherOnly",t[t.decipherOnly=256]="decipherOnly"})(Ev||(Ev={}));var L0=class extends Jr{constructor(...e){if(ce.isBufferSource(e[0])){super(e[0]);let r=se.parse(this.value,Za);this.usages=r.toNumber()}else{let r=new Za(e[0]);super(Yl,e[1],se.serialize(r)),this.usages=e[0]}}toTextObject(){let e=this.toTextObjectWithoutValue(),r=se.parse(this.value,Za);return e[""]=r.toJSON().join(", "),e}};L0.NAME="Key Usages";var U0=class t extends Jr{static async create(e,r=!1,n=Jt.get()){let i=await(await Ms.create(e,n)).getKeyIdentifier(n);return new t(ke.ToHex(i),r)}constructor(...e){if(ce.isBufferSource(e[0])){super(e[0]);let r=se.parse(this.value,Ur);this.keyId=ke.ToHex(r)}else{let r=typeof e[0]=="string"?ke.FromHex(e[0]):e[0],n=new Ur(r);super(wx,e[1],se.serialize(n)),this.keyId=ke.ToHex(r)}}toTextObject(){let e=this.toTextObjectWithoutValue(),r=se.parse(this.value,Ur);return e[""]=r,e}};U0.NAME="Subject Key Identifier";var D0=class extends Jr{constructor(...e){ce.isBufferSource(e[0])?super(e[0]):super(bx,e[1],new js(e[0]||[]).rawData)}onInit(e){super.onInit(e);let r=se.parse(e.extnValue,e0);this.names=new js(r)}toTextObject(){let e=this.toTextObjectWithoutValue(),r=this.names.toTextObject();for(let n in r)e[n]=r[n];return e}};D0.NAME="Subject Alternative Name";var Rr=class{static register(e,r){this.items.set(e,r)}static create(e){let r=new Jr(e),n=this.items.get(r.type);return n?new n(e):r}};Rr.items=new Map;var M0=class extends Jr{constructor(...e){var r;if(ce.isBufferSource(e[0])){super(e[0]);let n=se.parse(this.value,qu);this.policies=n.map(s=>s.policyIdentifier)}else{let n=e[0],s=(r=e[1])!==null&&r!==void 0?r:!1,i=new qu(n.map(o=>new jo({policyIdentifier:o})));super(Wl,s,se.serialize(i)),this.policies=n}}toTextObject(){let e=this.toTextObjectWithoutValue();return e.Policy=this.policies.map(r=>new gt("",{},os.toString(r))),e}};M0.NAME="Certificate Policies";Rr.register(Wl,M0);var H0=class extends Jr{constructor(...e){var r;if(ce.isBufferSource(e[0]))super(e[0]);else if(Array.isArray(e[0])&&typeof e[0][0]=="string"){let s=e[0].map(o=>new Zn({distributionPoint:new Ns({fullName:[new je({uniformResourceIdentifier:o})]})})),i=new _i(s);super(Gl,e[1],se.serialize(i))}else{let n=new _i(e[0]);super(Gl,e[1],se.serialize(n))}(r=this.distributionPoints)!==null&&r!==void 0||(this.distributionPoints=[])}onInit(e){super.onInit(e);let r=se.parse(e.extnValue,_i);this.distributionPoints=r}toTextObject(){let e=this.toTextObjectWithoutValue();return e["Distribution Point"]=this.distributionPoints.map(r=>{var n;let s={};return r.distributionPoint&&(s[""]=(n=r.distributionPoint.fullName)===null||n===void 0?void 0:n.map(i=>new is(i).toString()).join(", ")),r.reasons&&(s.Reasons=r.reasons.toString()),r.cRLIssuer&&(s["CRL Issuer"]=r.cRLIssuer.map(i=>i.toString()).join(", ")),s}),e}};H0.NAME="CRL Distribution Points";var j0=class extends Jr{constructor(...e){var r,n,s,i;if(ce.isBufferSource(e[0]))super(e[0]);else if(e[0]instanceof Do){let o=new Do(e[0]);super(zl,e[1],se.serialize(o))}else{let o=e[0],a=new Do;_0(a,o,rx,"ocsp"),_0(a,o,nx,"caIssuers"),_0(a,o,sx,"timeStamping"),_0(a,o,ix,"caRepository"),super(zl,e[1],se.serialize(a))}(r=this.ocsp)!==null&&r!==void 0||(this.ocsp=[]),(n=this.caIssuers)!==null&&n!==void 0||(this.caIssuers=[]),(s=this.timeStamping)!==null&&s!==void 0||(this.timeStamping=[]),(i=this.caRepository)!==null&&i!==void 0||(this.caRepository=[])}onInit(e){super.onInit(e),this.ocsp=[],this.caIssuers=[],this.timeStamping=[],this.caRepository=[],se.parse(e.extnValue,Do).forEach(n=>{switch(n.accessMethod){case rx:this.ocsp.push(new is(n.accessLocation));break;case nx:this.caIssuers.push(new is(n.accessLocation));break;case sx:this.timeStamping.push(new is(n.accessLocation));break;case ix:this.caRepository.push(new is(n.accessLocation));break}})}toTextObject(){let e=this.toTextObjectWithoutValue();return this.ocsp.length&&T0(e,"OCSP",this.ocsp),this.caIssuers.length&&T0(e,"CA Issuers",this.caIssuers),this.timeStamping.length&&T0(e,"Time Stamping",this.timeStamping),this.caRepository.length&&T0(e,"CA Repository",this.caRepository),e}};j0.NAME="Authority Info Access";function T0(t,e,r){if(r.length===1)t[e]=r[0].toTextObject();else{let n=new gt("");r.forEach((s,i)=>{let o=s.toTextObject(),a=`${o[gt.NAME]} ${i+1}`,c=n[a];Array.isArray(c)||(c=[],n[a]=c),c.push(o)}),t[e]=n}}function _0(t,e,r,n){let s=e[n];s&&(Array.isArray(s)?s:[s]).forEach(o=>{typeof o=="string"&&(o=new is("url",o)),t.push(new ks({accessMethod:r,accessLocation:se.parse(o.rawData,je)}))})}var q0=class extends Jr{constructor(...e){ce.isBufferSource(e[0])?super(e[0]):super(xx,e[1],new js(e[0]||[]).rawData)}onInit(e){super.onInit(e);let r=se.parse(e.extnValue,Lt);this.names=new js(r)}toTextObject(){let e=this.toTextObjectWithoutValue(),r=this.names.toTextObject();for(let n in r)e[n]=r[n];return e}};q0.NAME="Issuer Alternative Name";var _c=class t extends zi{constructor(...e){let r;if(ce.isBufferSource(e[0]))r=ce.toArrayBuffer(e[0]);else{let n=e[0],s=Array.isArray(e[1])?e[1].map(i=>ce.toArrayBuffer(i)):[];r=se.serialize(new cr({type:n,values:s}))}super(r,cr)}onInit(e){this.type=e.type,this.values=e.values}toTextObject(){let e=this.toTextObjectWithoutValue();return e.Value=this.values.map(r=>new gt("",{"":r})),e}toTextObjectWithoutValue(){let e=this.toTextObjectEmpty();return e[gt.NAME]===t.NAME&&(e[gt.NAME]=os.toString(this.type)),e}};_c.NAME="Attribute";var V0=class extends _c{constructor(...e){var r;if(ce.isBufferSource(e[0]))super(e[0]);else{let n=new Ef({printableString:e[0]});super(mm,[se.serialize(n)])}(r=this.password)!==null&&r!==void 0||(this.password="")}onInit(e){if(super.onInit(e),this.values[0]){let r=se.parse(this.values[0],Ef);this.password=r.toString()}}toTextObject(){let e=this.toTextObjectWithoutValue();return e[gt.VALUE]=this.password,e}};V0.NAME="Challenge Password";var Yf=class extends _c{constructor(...e){var r;if(ce.isBufferSource(e[0]))super(e[0]);else{let n=e[0],s=new Yr;for(let i of n)s.push(se.parse(i.rawData,Ar));super(Cf,[se.serialize(s)])}(r=this.items)!==null&&r!==void 0||(this.items=[])}onInit(e){if(super.onInit(e),this.values[0]){let r=se.parse(this.values[0],Yr);this.items=r.map(n=>Rr.create(se.serialize(n)))}}toTextObject(){let e=this.toTextObjectWithoutValue(),r=this.items.map(n=>n.toTextObject());for(let n of r)e[n[gt.NAME]]=n;return e}};Yf.NAME="Extensions";var Bc=class{static register(e,r){this.items.set(e,r)}static create(e){let r=new _c(e),n=this.items.get(r.type);return n?new n(e):r}};Bc.items=new Map;var Jf="crypto.signatureFormatter",Bm=class{toAsnSignature(e,r){return ce.toArrayBuffer(r)}toWebSignature(e,r){return ce.toArrayBuffer(r)}},k0,km=k0=class{static createPssParams(e,r){let n=k0.getHashAlgorithm(e);return n?new rs({hashAlgorithm:n,maskGenAlgorithm:new te({algorithm:Ui,parameters:se.serialize(n)}),saltLength:r}):null}static getHashAlgorithm(e){let r=Nt.resolve(ha);return typeof e=="string"?r.toAsnAlgorithm({name:e}):typeof e=="object"&&e&&"name"in e?r.toAsnAlgorithm(e):null}toAsnAlgorithm(e){switch(e.name.toLowerCase()){case"rsassa-pkcs1-v1_5":if("hash"in e){let r;if(typeof e.hash=="string")r=e.hash;else if(e.hash&&typeof e.hash=="object"&&"name"in e.hash&&typeof e.hash.name=="string")r=e.hash.name.toUpperCase();else throw new Error("Cannot get hash algorithm name");switch(r.toLowerCase()){case"sha-1":return new te({algorithm:pc,parameters:null});case"sha-256":return new te({algorithm:l0,parameters:null});case"sha-384":return new te({algorithm:xc,parameters:null});case"sha-512":return new te({algorithm:mc,parameters:null})}}else return new te({algorithm:ts,parameters:null});break;case"rsa-pss":if("hash"in e){if(!("saltLength"in e&&typeof e.saltLength=="number"))throw new Error("Cannot get 'saltLength' from 'alg' argument");let r=k0.createPssParams(e.hash,e.saltLength);if(!r)throw new Error("Cannot create PSS parameters");return new te({algorithm:Li,parameters:se.serialize(r)})}else return new te({algorithm:Li,parameters:null})}return null}toWebAlgorithm(e){switch(e.algorithm){case ts:return{name:"RSASSA-PKCS1-v1_5"};case pc:return{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-1"}};case l0:return{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}};case xc:return{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-384"}};case mc:return{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-512"}};case Li:if(e.parameters){let r=se.parse(e.parameters,rs);return{name:"RSA-PSS",hash:Nt.resolve(ha).toWebAlgorithm(r.hashAlgorithm),saltLength:r.saltLength}}else return{name:"RSA-PSS"}}return null}};km=k0=d([Mi()],km);Nt.registerSingleton(Zf,km);var Rm=class{toAsnAlgorithm(e){switch(e.name.toLowerCase()){case"sha-1":return new te({algorithm:na});case"sha-256":return new te({algorithm:sa});case"sha-384":return new te({algorithm:ia});case"sha-512":return new te({algorithm:oa})}return null}toWebAlgorithm(e){switch(e.algorithm){case na:return{name:"SHA-1"};case sa:return{name:"SHA-256"};case ia:return{name:"SHA-384"};case oa:return{name:"SHA-512"}}return null}};Rm=d([Mi()],Rm);Nt.registerSingleton(Zf,Rm);var qs=class t{addPadding(e,r){let n=ce.toUint8Array(r),s=new Uint8Array(e);return s.set(n,e-n.length),s.buffer}removePadding(e,r=!1){let n=ce.toUint8Array(e);for(let s=0;s<n.length;s++)if(n[s]){n=n.slice(s);break}if(r&&n[0]>127){let s=new Uint8Array(n.length+1);return s.set(n,1),s.buffer}return n.buffer}toAsnSignature(e,r){if(e.name==="ECDSA"){let n=e.namedCurve,s=t.namedCurveSize.get(n)||t.defaultNamedCurveSize,i=new ra,o=ce.toUint8Array(r);return i.r=this.removePadding(o.slice(0,s),!0),i.s=this.removePadding(o.slice(s,s+s),!0),se.serialize(i)}return null}toWebSignature(e,r){if(e.name==="ECDSA"){let n=se.parse(r,ra),s=e.namedCurve,i=t.namedCurveSize.get(s)||t.defaultNamedCurveSize,o=this.addPadding(i,this.removePadding(n.r)),a=this.addPadding(i,this.removePadding(n.s));return By(o,a)}return null}};qs.namedCurveSize=new Map;qs.defaultNamedCurveSize=32;var Cm="1.3.101.110",Av="1.3.101.111",Im="1.3.101.112",Cv="1.3.101.113",Nm=class{toAsnAlgorithm(e){let r=null;switch(e.name.toLowerCase()){case"ed25519":r=Im;break;case"x25519":r=Cm;break;case"eddsa":switch(e.namedCurve.toLowerCase()){case"ed25519":r=Im;break;case"ed448":r=Cv;break}break;case"ecdh-es":switch(e.namedCurve.toLowerCase()){case"x25519":r=Cm;break;case"x448":r=Av;break}}return r?new te({algorithm:r}):null}toWebAlgorithm(e){switch(e.algorithm){case Im:return{name:"Ed25519"};case Cv:return{name:"EdDSA",namedCurve:"Ed448"};case Cm:return{name:"X25519"};case Av:return{name:"ECDH-ES",namedCurve:"X448"}}return null}};Nm=d([Mi()],Nm);Nt.registerSingleton(Zf,Nm);var _f,Bf,kf,Rf,Nf,Pf,Of,Cc,Pm=class extends Fi{get subjectName(){return et(this,Bf,"f")||Ot(this,Bf,new In(this.asn.certificationRequestInfo.subject),"f"),et(this,Bf,"f")}get subject(){return et(this,kf,"f")||Ot(this,kf,this.subjectName.toString(),"f"),et(this,kf,"f")}get signatureAlgorithm(){if(!et(this,Rf,"f")){let e=Nt.resolve(ha);Ot(this,Rf,e.toWebAlgorithm(this.asn.signatureAlgorithm),"f")}return et(this,Rf,"f")}get signature(){return et(this,Nf,"f")||Ot(this,Nf,this.asn.signature,"f"),et(this,Nf,"f")}get publicKey(){return et(this,Pf,"f")||Ot(this,Pf,new Ms(this.asn.certificationRequestInfo.subjectPKInfo),"f"),et(this,Pf,"f")}get attributes(){return et(this,Of,"f")||Ot(this,Of,this.asn.certificationRequestInfo.attributes.map(e=>Bc.create(se.serialize(e))),"f"),et(this,Of,"f")}get extensions(){if(!et(this,Cc,"f")){Ot(this,Cc,[],"f");let e=this.getAttribute(Cf);e instanceof Yf&&Ot(this,Cc,e.items,"f")}return et(this,Cc,"f")}get tbs(){return et(this,_f,"f")||Ot(this,_f,this.asn.certificationRequestInfoRaw||se.serialize(this.asn.certificationRequestInfo),"f"),et(this,_f,"f")}constructor(e){let r=Fi.isAsnEncoded(e)?[e,Vi]:[e];super(r[0],r[1]),_f.set(this,void 0),Bf.set(this,void 0),kf.set(this,void 0),Rf.set(this,void 0),Nf.set(this,void 0),Pf.set(this,void 0),Of.set(this,void 0),Cc.set(this,void 0),this.tag=hr.CertificateRequestTag}onInit(e){}getAttribute(e){for(let r of this.attributes)if(r.type===e)return r;return null}getAttributes(e){return this.attributes.filter(r=>r.type===e)}getExtension(e){for(let r of this.extensions)if(r.type===e)return r;return null}getExtensions(e){return this.extensions.filter(r=>r.type===e)}async verify(e=Jt.get()){let r={...this.publicKey.algorithm,...this.signatureAlgorithm},n=await this.publicKey.export(r,["verify"],e),s=Nt.resolveAll(Jf).reverse(),i=null;for(let a of s)if(i=a.toWebSignature(r,this.signature),i)break;if(!i)throw Error("Cannot convert WebCrypto signature value to ASN.1 format");return await e.subtle.verify(this.signatureAlgorithm,n,i,this.tbs)}toTextObject(){let e=this.toTextObjectEmpty(),r=se.parse(this.rawData,Vi),n=r.certificationRequestInfo,s=new gt("",{Version:`${Jn[n.version]} (${n.version})`,Subject:this.subject,"Subject Public Key Info":this.publicKey});if(this.attributes.length){let i=new gt("");for(let o of this.attributes){let a=o.toTextObject();i[a[gt.NAME]]=a}s.Attributes=i}return e.Data=s,e.Signature=new gt("",{Algorithm:Hs.serializeAlgorithm(r.signatureAlgorithm),"":r.signature}),e}};_f=new WeakMap,Bf=new WeakMap,kf=new WeakMap,Rf=new WeakMap,Nf=new WeakMap,Pf=new WeakMap,Of=new WeakMap,Cc=new WeakMap;Pm.NAME="PKCS#10 Certificate Request";var Lf,Uf,Df,Mf,Hf,jf,qf,Vf,zf,Ff,Ic,Kf,z0=class extends Fi{get publicKey(){return et(this,Kf,"f")||Ot(this,Kf,new Ms(this.asn.tbsCertificate.subjectPublicKeyInfo),"f"),et(this,Kf,"f")}get serialNumber(){if(!et(this,Uf,"f")){let e=this.asn.tbsCertificate,r=new Uint8Array(e.serialNumber);r.length>1&&r[0]===0&&r[1]>127&&(r=r.slice(1)),Ot(this,Uf,ke.ToHex(r),"f")}return et(this,Uf,"f")}get subjectName(){return et(this,Df,"f")||Ot(this,Df,new In(this.asn.tbsCertificate.subject),"f"),et(this,Df,"f")}get subject(){return et(this,Mf,"f")||Ot(this,Mf,this.subjectName.toString(),"f"),et(this,Mf,"f")}get issuerName(){return et(this,Hf,"f")||Ot(this,Hf,new In(this.asn.tbsCertificate.issuer),"f"),et(this,Hf,"f")}get issuer(){return et(this,jf,"f")||Ot(this,jf,this.issuerName.toString(),"f"),et(this,jf,"f")}get notBefore(){if(!et(this,qf,"f")){let e=this.asn.tbsCertificate.validity.notBefore.utcTime||this.asn.tbsCertificate.validity.notBefore.generalTime;if(!e)throw new Error("Cannot get 'notBefore' value");Ot(this,qf,e,"f")}return et(this,qf,"f")}get notAfter(){if(!et(this,Vf,"f")){let e=this.asn.tbsCertificate.validity.notAfter.utcTime||this.asn.tbsCertificate.validity.notAfter.generalTime;if(!e)throw new Error("Cannot get 'notAfter' value");Ot(this,Vf,e,"f")}return et(this,Vf,"f")}get signatureAlgorithm(){if(!et(this,zf,"f")){let e=Nt.resolve(ha);Ot(this,zf,e.toWebAlgorithm(this.asn.signatureAlgorithm),"f")}return et(this,zf,"f")}get signature(){return et(this,Ff,"f")||Ot(this,Ff,this.asn.signatureValue,"f"),et(this,Ff,"f")}get extensions(){return et(this,Ic,"f")||(Ot(this,Ic,[],"f"),this.asn.tbsCertificate.extensions&&Ot(this,Ic,this.asn.tbsCertificate.extensions.map(e=>Rr.create(se.serialize(e))),"f")),et(this,Ic,"f")}get tbs(){return et(this,Lf,"f")||Ot(this,Lf,this.asn.tbsCertificateRaw||se.serialize(this.asn.tbsCertificate),"f"),et(this,Lf,"f")}constructor(e){let r=Fi.isAsnEncoded(e)?[e,ln]:[e];super(r[0],r[1]),Lf.set(this,void 0),Uf.set(this,void 0),Df.set(this,void 0),Mf.set(this,void 0),Hf.set(this,void 0),jf.set(this,void 0),qf.set(this,void 0),Vf.set(this,void 0),zf.set(this,void 0),Ff.set(this,void 0),Ic.set(this,void 0),Kf.set(this,void 0),this.tag=hr.CertificateTag}onInit(e){}getExtension(e){for(let r of this.extensions)if(typeof e=="string"){if(r.type===e)return r}else if(r instanceof e)return r;return null}getExtensions(e){return this.extensions.filter(r=>typeof e=="string"?r.type===e:r instanceof e)}async verify(e={},r=Jt.get()){let n,s,i=e.publicKey;try{if(!i)n={...this.publicKey.algorithm,...this.signatureAlgorithm},s=await this.publicKey.export(n,["verify"],r);else if("publicKey"in i)n={...i.publicKey.algorithm,...this.signatureAlgorithm},s=await i.publicKey.export(n,["verify"],r);else if(i instanceof Ms)n={...i.algorithm,...this.signatureAlgorithm},s=await i.export(n,["verify"],r);else if(ce.isBufferSource(i)){let f=new Ms(i);n={...f.algorithm,...this.signatureAlgorithm},s=await f.export(n,["verify"],r)}else n={...i.algorithm,...this.signatureAlgorithm},s=i}catch{return!1}let o=Nt.resolveAll(Jf).reverse(),a=null;for(let f of o)if(a=f.toWebSignature(n,this.signature),a)break;if(!a)throw Error("Cannot convert ASN.1 signature value to WebCrypto format");let c=await r.subtle.verify(this.signatureAlgorithm,s,a,this.tbs);if(e.signatureOnly)return c;{let l=(e.date||new Date).getTime();return c&&this.notBefore.getTime()<l&&l<this.notAfter.getTime()}}async getThumbprint(...e){let r,n="SHA-1";return e[0]&&(e[0].subtle?r=e[0]:(n=e[0]||n,r=e[1])),r??(r=Jt.get()),await r.subtle.digest(n,this.rawData)}async isSelfSigned(e=Jt.get()){return this.subject===this.issuer&&await this.verify({signatureOnly:!0},e)}toTextObject(){let e=this.toTextObjectEmpty(),r=se.parse(this.rawData,ln),n=r.tbsCertificate,s=new gt("",{Version:`${Jn[n.version]} (${n.version})`,"Serial Number":n.serialNumber,"Signature Algorithm":Hs.serializeAlgorithm(n.signature),Issuer:this.issuer,Validity:new gt("",{"Not Before":n.validity.notBefore.getTime(),"Not After":n.validity.notAfter.getTime()}),Subject:this.subject,"Subject Public Key Info":this.publicKey});if(n.issuerUniqueID&&(s["Issuer Unique ID"]=n.issuerUniqueID),n.subjectUniqueID&&(s["Subject Unique ID"]=n.subjectUniqueID),this.extensions.length){let i=new gt("");for(let o of this.extensions){let a=o.toTextObject();i[a[gt.NAME]]=a}s.Extensions=i}return e.Data=s,e.Signature=new gt("",{Algorithm:Hs.serializeAlgorithm(r.signatureAlgorithm),"":r.signatureValue}),e}};Lf=new WeakMap,Uf=new WeakMap,Df=new WeakMap,Mf=new WeakMap,Hf=new WeakMap,jf=new WeakMap,qf=new WeakMap,Vf=new WeakMap,zf=new WeakMap,Ff=new WeakMap,Ic=new WeakMap,Kf=new WeakMap;z0.NAME="Certificate";function UC(t,e=Jt.get()){let r=ce.toUint8Array(ke.FromHex(t||"")),n=r&&r.length&&r.some(i=>i>0)?new Uint8Array(r):void 0;n||(n=e.getRandomValues(new Uint8Array(16)));let s=0;for(;s<n.length-1&&n[s]===0;)s++;if(n=n.slice(s),n[0]>127){let i=new Uint8Array(n.length+1);i[0]=0,i.set(n,1),n=i}return n.buffer}var F0=class{static async createSelfSigned(e,r=Jt.get()){if(!e.keys.privateKey)throw new Error("Bad field 'keys' in 'params' argument. 'privateKey' is empty");if(!e.keys.publicKey)throw new Error("Bad field 'keys' in 'params' argument. 'publicKey' is empty");return this.create({serialNumber:e.serialNumber,subject:e.name,issuer:e.name,notBefore:e.notBefore,notAfter:e.notAfter,publicKey:e.keys.publicKey,signingKey:e.keys.privateKey,signingAlgorithm:e.signingAlgorithm,extensions:e.extensions},r)}static async create(e,r=Jt.get()){var n;let s;e.publicKey instanceof Ms?s=e.publicKey.rawData:"publicKey"in e.publicKey?s=e.publicKey.publicKey.rawData:ce.isBufferSource(e.publicKey)?s=e.publicKey:s=await r.subtle.exportKey("spki",e.publicKey);let i=UC(e.serialNumber,r),o=e.notBefore||new Date,a=e.notAfter||new Date(o.getTime()+31536e6),c=new ln({tbsCertificate:new fr({version:Jn.v3,serialNumber:i,validity:new Ps({notBefore:o,notAfter:a}),extensions:new Yr(((n=e.extensions)===null||n===void 0?void 0:n.map(L=>se.parse(L.rawData,Ar)))||[]),subjectPublicKeyInfo:se.parse(s,ur)})});if(e.subject){let L=e.subject instanceof In?e.subject:new In(e.subject);c.tbsCertificate.subject=se.parse(L.toArrayBuffer(),Bt)}if(e.issuer){let L=e.issuer instanceof In?e.issuer:new In(e.issuer);c.tbsCertificate.issuer=se.parse(L.toArrayBuffer(),Bt)}let f={hash:"SHA-256"},l="signingKey"in e?{...f,...e.signingAlgorithm,...e.signingKey.algorithm}:{...f,...e.signingAlgorithm},p=Nt.resolve(ha);c.tbsCertificate.signature=c.signatureAlgorithm=p.toAsnAlgorithm(l);let x=se.serialize(c.tbsCertificate),v="signingKey"in e?await r.subtle.sign(l,e.signingKey,x):e.signature,S=Nt.resolveAll(Jf).reverse(),I=null;for(let L of S)if(I=L.toAsnSignature(l,v),I)break;if(!I)throw Error("Cannot convert ASN.1 signature value to WebCrypto format");return c.signatureValue=I,new z0(se.serialize(c))}},DC,MC,HC,jC,qC,Iv;(function(t){t[t.unspecified=0]="unspecified",t[t.keyCompromise=1]="keyCompromise",t[t.cACompromise=2]="cACompromise",t[t.affiliationChanged=3]="affiliationChanged",t[t.superseded=4]="superseded",t[t.cessationOfOperation=5]="cessationOfOperation",t[t.certificateHold=6]="certificateHold",t[t.removeFromCRL=8]="removeFromCRL",t[t.privilegeWithdrawn=9]="privilegeWithdrawn",t[t.aACompromise=10]="aACompromise"})(Iv||(Iv={}));DC=new WeakMap,MC=new WeakMap,HC=new WeakMap,jC=new WeakMap,qC=new WeakMap;var VC,zC,FC,KC,$C,WC,GC;VC=new WeakMap,zC=new WeakMap,FC=new WeakMap,KC=new WeakMap,$C=new WeakMap,WC=new WeakMap,GC=new WeakMap;Rr.register(Kl,P0);Rr.register(Xl,O0);Rr.register(Yl,L0);Rr.register(wx,U0);Rr.register(Fl,N0);Rr.register(bx,D0);Rr.register(Gl,H0);Rr.register(zl,j0);Rr.register(xx,q0);Bc.register(mm,V0);Bc.register(Cf,Yf);Nt.registerSingleton(Jf,Bm);Nt.registerSingleton(Jf,qs);qs.namedCurveSize.set("P-256",32);qs.namedCurveSize.set("K-256",32);qs.namedCurveSize.set("P-384",48);qs.namedCurveSize.set("P-521",66);var Jc=it(Ut(),1),I8=it(Ut(),1),T8=it(pl(),1);import{createHash as FT,createHmac as KT}from"crypto";import*as Vs from"crypto";var ma=Vs&&typeof Vs=="object"&&"webcrypto"in Vs?Vs.webcrypto:Vs&&typeof Vs=="object"&&"randomBytes"in Vs?Vs:void 0;function ga(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"}function id(t){if(!Number.isSafeInteger(t)||t<0)throw new Error("positive integer expected, got "+t)}function Tn(t,...e){if(!ga(t))throw new Error("Uint8Array expected");if(e.length>0&&!e.includes(t.length))throw new Error("Uint8Array expected of length "+e+", got length="+t.length)}function th(t){if(typeof t!="function"||typeof t.create!="function")throw new Error("Hash should be wrapped by utils.createHasher");id(t.outputLen),id(t.blockLen)}function Pc(t,e=!0){if(t.destroyed)throw new Error("Hash instance has been destroyed");if(e&&t.finished)throw new Error("Hash#digest() has already been called")}function uS(t,e){Tn(t);let r=e.outputLen;if(t.length<r)throw new Error("digestInto() expects output buffer of length at least "+r)}function Fs(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function rh(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}function _n(t,e){return t<<32-e|t>>>e}var fS=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",EI=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function Ks(t){if(Tn(t),fS)return t.toHex();let e="";for(let r=0;r<t.length;r++)e+=EI[t[r]];return e}var zs={_0:48,_9:57,A:65,F:70,a:97,f:102};function cS(t){if(t>=zs._0&&t<=zs._9)return t-zs._0;if(t>=zs.A&&t<=zs.F)return t-(zs.A-10);if(t>=zs.a&&t<=zs.f)return t-(zs.a-10)}function ya(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);if(fS)return Uint8Array.fromHex(t);let e=t.length,r=e/2;if(e%2)throw new Error("hex string expected, got unpadded hex of length "+e);let n=new Uint8Array(r);for(let s=0,i=0;s<r;s++,i+=2){let o=cS(t.charCodeAt(i)),a=cS(t.charCodeAt(i+1));if(o===void 0||a===void 0){let c=t[i]+t[i+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+i)}n[s]=o*16+a}return n}function dS(t){if(typeof t!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(t))}function od(t){return typeof t=="string"&&(t=dS(t)),Tn(t),t}function Bn(...t){let e=0;for(let n=0;n<t.length;n++){let s=t[n];Tn(s),e+=s.length}let r=new Uint8Array(e);for(let n=0,s=0;n<t.length;n++){let i=t[n];r.set(i,s),s+=i.length}return r}var Nc=class{};function nh(t){let e=n=>t().update(od(n)).digest(),r=t();return e.outputLen=r.outputLen,e.blockLen=r.blockLen,e.create=()=>t(),e}function sh(t=32){if(ma&&typeof ma.getRandomValues=="function")return ma.getRandomValues(new Uint8Array(t));if(ma&&typeof ma.randomBytes=="function")return Uint8Array.from(ma.randomBytes(t));throw new Error("crypto.getRandomValues must be defined")}var Km=BigInt(0),Fm=BigInt(1);function ad(t,e=""){if(typeof t!="boolean"){let r=e&&`"${e}"`;throw new Error(r+"expected boolean, got type="+typeof t)}return t}function Yi(t,e,r=""){let n=ga(t),s=t?.length,i=e!==void 0;if(!n||i&&s!==e){let o=r&&`"${r}" `,a=i?` of length ${e}`:"",c=n?`length=${s}`:`type=${typeof t}`;throw new Error(o+"expected Uint8Array"+a+", got "+c)}return t}function cd(t){let e=t.toString(16);return e.length&1?"0"+e:e}function lS(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);return t===""?Km:BigInt("0x"+t)}function Oc(t){return lS(Ks(t))}function $m(t){return Tn(t),lS(Ks(Uint8Array.from(t).reverse()))}function ih(t,e){return ya(t.toString(16).padStart(e*2,"0"))}function Wm(t,e){return ih(t,e).reverse()}function Cr(t,e,r){let n;if(typeof e=="string")try{n=ya(e)}catch(i){throw new Error(t+" must be hex string or Uint8Array, cause: "+i)}else if(ga(e))n=Uint8Array.from(e);else throw new Error(t+" must be hex string or Uint8Array");let s=n.length;if(typeof r=="number"&&s!==r)throw new Error(t+" of length "+r+" expected, got "+s);return n}var zm=t=>typeof t=="bigint"&&Km<=t;function hS(t,e,r){return zm(t)&&zm(e)&&zm(r)&&e<=t&&t<r}function pS(t,e,r,n){if(!hS(e,r,n))throw new Error("expected valid "+t+": "+r+" <= n < "+n+", got "+e)}function oh(t){let e;for(e=0;t>Km;t>>=Fm,e+=1);return e}var Zi=t=>(Fm<<BigInt(t))-Fm;function xS(t,e,r){if(typeof t!="number"||t<2)throw new Error("hashLen must be a number");if(typeof e!="number"||e<2)throw new Error("qByteLen must be a number");if(typeof r!="function")throw new Error("hmacFn must be a function");let n=v=>new Uint8Array(v),s=v=>Uint8Array.of(v),i=n(t),o=n(t),a=0,c=()=>{i.fill(1),o.fill(0),a=0},f=(...v)=>r(o,i,...v),l=(v=n(0))=>{o=f(s(0),v),i=f(),v.length!==0&&(o=f(s(1),v),i=f())},p=()=>{if(a++>=1e3)throw new Error("drbg: tried 1000 values");let v=0,S=[];for(;v<e;){i=f();let I=i.slice();S.push(I),v+=i.length}return Bn(...S)};return(v,S)=>{c(),l(v);let I;for(;!(I=S(p()));)l();return c(),I}}function ud(t,e,r={}){if(!t||typeof t!="object")throw new Error("expected valid options object");function n(s,i,o){let a=t[s];if(o&&a===void 0)return;let c=typeof a;if(c!==i||a===null)throw new Error(`param "${s}" is invalid: expected ${i}, got ${c}`)}Object.entries(e).forEach(([s,i])=>n(s,i,!1)),Object.entries(r).forEach(([s,i])=>n(s,i,!0))}function Gm(t){let e=new WeakMap;return(r,...n)=>{let s=e.get(r);if(s!==void 0)return s;let i=t(r,...n);return e.set(r,i),i}}var Fr=BigInt(0),Ir=BigInt(1),ba=BigInt(2),yS=BigInt(3),bS=BigInt(4),vS=BigInt(5),AI=BigInt(7),wS=BigInt(8),CI=BigInt(9),SS=BigInt(16);function kn(t,e){let r=t%e;return r>=Fr?r:e+r}function mS(t,e){if(t===Fr)throw new Error("invert: expected non-zero number");if(e<=Fr)throw new Error("invert: expected positive modulus, got "+e);let r=kn(t,e),n=e,s=Fr,i=Ir,o=Ir,a=Fr;for(;r!==Fr;){let f=n/r,l=n%r,p=s-o*f,x=i-a*f;n=r,r=l,s=o,i=a,o=p,a=x}if(n!==Ir)throw new Error("invert: does not exist");return kn(s,e)}function Xm(t,e,r){if(!t.eql(t.sqr(e),r))throw new Error("Cannot find square root")}function ES(t,e){let r=(t.ORDER+Ir)/bS,n=t.pow(e,r);return Xm(t,n,e),n}function II(t,e){let r=(t.ORDER-vS)/wS,n=t.mul(e,ba),s=t.pow(n,r),i=t.mul(e,s),o=t.mul(t.mul(i,ba),s),a=t.mul(i,t.sub(o,t.ONE));return Xm(t,a,e),a}function TI(t){let e=cs(t),r=AS(t),n=r(e,e.neg(e.ONE)),s=r(e,n),i=r(e,e.neg(n)),o=(t+AI)/SS;return(a,c)=>{let f=a.pow(c,o),l=a.mul(f,n),p=a.mul(f,s),x=a.mul(f,i),v=a.eql(a.sqr(l),c),S=a.eql(a.sqr(p),c);f=a.cmov(f,l,v),l=a.cmov(x,p,S);let I=a.eql(a.sqr(l),c),L=a.cmov(f,l,I);return Xm(a,L,c),L}}function AS(t){if(t<yS)throw new Error("sqrt is not defined for small field");let e=t-Ir,r=0;for(;e%ba===Fr;)e/=ba,r++;let n=ba,s=cs(t);for(;gS(s,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return ES;let i=s.pow(n,e),o=(e+Ir)/ba;return function(c,f){if(c.is0(f))return f;if(gS(c,f)!==1)throw new Error("Cannot find square root");let l=r,p=c.mul(c.ONE,i),x=c.pow(f,e),v=c.pow(f,o);for(;!c.eql(x,c.ONE);){if(c.is0(x))return c.ZERO;let S=1,I=c.sqr(x);for(;!c.eql(I,c.ONE);)if(S++,I=c.sqr(I),S===l)throw new Error("Cannot find square root");let L=Ir<<BigInt(l-S-1),ee=c.pow(p,L);l=S,p=c.sqr(ee),x=c.mul(x,p),v=c.mul(v,ee)}return v}}function _I(t){return t%bS===yS?ES:t%wS===vS?II:t%SS===CI?TI(t):AS(t)}var BI=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Ym(t){let e={ORDER:"bigint",MASK:"bigint",BYTES:"number",BITS:"number"},r=BI.reduce((n,s)=>(n[s]="function",n),e);return ud(t,r),t}function kI(t,e,r){if(r<Fr)throw new Error("invalid exponent, negatives unsupported");if(r===Fr)return t.ONE;if(r===Ir)return e;let n=t.ONE,s=e;for(;r>Fr;)r&Ir&&(n=t.mul(n,s)),s=t.sqr(s),r>>=Ir;return n}function ah(t,e,r=!1){let n=new Array(e.length).fill(r?t.ZERO:void 0),s=e.reduce((o,a,c)=>t.is0(a)?o:(n[c]=o,t.mul(o,a)),t.ONE),i=t.inv(s);return e.reduceRight((o,a,c)=>t.is0(a)?o:(n[c]=t.mul(o,n[c]),t.mul(o,a)),i),n}function gS(t,e){let r=(t.ORDER-Ir)/ba,n=t.pow(e,r),s=t.eql(n,t.ONE),i=t.eql(n,t.ZERO),o=t.eql(n,t.neg(t.ONE));if(!s&&!i&&!o)throw new Error("invalid Legendre symbol result");return s?1:i?0:-1}function ch(t,e){e!==void 0&&id(e);let r=e!==void 0?e:t.toString(2).length,n=Math.ceil(r/8);return{nBitLength:r,nByteLength:n}}function cs(t,e,r=!1,n={}){if(t<=Fr)throw new Error("invalid field: expected ORDER > 0, got "+t);let s,i,o=!1,a;if(typeof e=="object"&&e!=null){if(n.sqrt||r)throw new Error("cannot specify opts in two arguments");let x=e;x.BITS&&(s=x.BITS),x.sqrt&&(i=x.sqrt),typeof x.isLE=="boolean"&&(r=x.isLE),typeof x.modFromBytes=="boolean"&&(o=x.modFromBytes),a=x.allowedLengths}else typeof e=="number"&&(s=e),n.sqrt&&(i=n.sqrt);let{nBitLength:c,nByteLength:f}=ch(t,s);if(f>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let l,p=Object.freeze({ORDER:t,isLE:r,BITS:c,BYTES:f,MASK:Zi(c),ZERO:Fr,ONE:Ir,allowedLengths:a,create:x=>kn(x,t),isValid:x=>{if(typeof x!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof x);return Fr<=x&&x<t},is0:x=>x===Fr,isValidNot0:x=>!p.is0(x)&&p.isValid(x),isOdd:x=>(x&Ir)===Ir,neg:x=>kn(-x,t),eql:(x,v)=>x===v,sqr:x=>kn(x*x,t),add:(x,v)=>kn(x+v,t),sub:(x,v)=>kn(x-v,t),mul:(x,v)=>kn(x*v,t),pow:(x,v)=>kI(p,x,v),div:(x,v)=>kn(x*mS(v,t),t),sqrN:x=>x*x,addN:(x,v)=>x+v,subN:(x,v)=>x-v,mulN:(x,v)=>x*v,inv:x=>mS(x,t),sqrt:i||(x=>(l||(l=_I(t)),l(p,x))),toBytes:x=>r?Wm(x,f):ih(x,f),fromBytes:(x,v=!0)=>{if(a){if(!a.includes(x.length)||x.length>f)throw new Error("Field.fromBytes: expected "+a+" bytes, got "+x.length);let I=new Uint8Array(f);I.set(x,r?0:I.length-x.length),x=I}if(x.length!==f)throw new Error("Field.fromBytes: expected "+f+" bytes, got "+x.length);let S=r?$m(x):Oc(x);if(o&&(S=kn(S,t)),!v&&!p.isValid(S))throw new Error("invalid field element: outside of range 0..ORDER");return S},invertBatch:x=>ah(p,x),cmov:(x,v,S)=>S?v:x});return Object.freeze(p)}function CS(t){if(typeof t!="bigint")throw new Error("field order must be bigint");let e=t.toString(2).length;return Math.ceil(e/8)}function Zm(t){let e=CS(t);return e+Math.ceil(e/2)}function IS(t,e,r=!1){let n=t.length,s=CS(e),i=Zm(e);if(n<16||n<i||n>1024)throw new Error("expected "+i+"-1024 bytes of input, got "+n);let o=r?$m(t):Oc(t),a=kn(o,e-Ir)+Ir;return r?Wm(a,s):ih(a,s)}function RI(t,e,r,n){if(typeof t.setBigUint64=="function")return t.setBigUint64(e,r,n);let s=BigInt(32),i=BigInt(4294967295),o=Number(r>>s&i),a=Number(r&i),c=n?4:0,f=n?0:4;t.setUint32(e+c,o,n),t.setUint32(e+f,a,n)}function TS(t,e,r){return t&e^~t&r}function _S(t,e,r){return t&e^t&r^e&r}var fd=class extends Nc{constructor(e,r,n,s){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=e,this.outputLen=r,this.padOffset=n,this.isLE=s,this.buffer=new Uint8Array(e),this.view=rh(this.buffer)}update(e){Pc(this),e=od(e),Tn(e);let{view:r,buffer:n,blockLen:s}=this,i=e.length;for(let o=0;o<i;){let a=Math.min(s-this.pos,i-o);if(a===s){let c=rh(e);for(;s<=i-o;o+=s)this.process(c,o);continue}n.set(e.subarray(o,o+a),this.pos),this.pos+=a,o+=a,this.pos===s&&(this.process(r,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){Pc(this),uS(e,this),this.finished=!0;let{buffer:r,view:n,blockLen:s,isLE:i}=this,{pos:o}=this;r[o++]=128,Fs(this.buffer.subarray(o)),this.padOffset>s-o&&(this.process(n,0),o=0);for(let p=o;p<s;p++)r[p]=0;RI(n,s-8,BigInt(this.length*8),i),this.process(n,0);let a=rh(e),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let f=c/4,l=this.get();if(f>l.length)throw new Error("_sha2: outputLen bigger than state");for(let p=0;p<f;p++)a.setUint32(4*p,l[p],i)}digest(){let{buffer:e,outputLen:r}=this;this.digestInto(e);let n=e.slice(0,r);return this.destroy(),n}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());let{blockLen:r,buffer:n,length:s,finished:i,destroyed:o,pos:a}=this;return e.destroyed=o,e.finished=i,e.length=s,e.pos=a,s%r&&e.buffer.set(n),e}clone(){return this._cloneInto()}},$s=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var pr=Uint32Array.from([3418070365,3238371032,1654270250,914150663,2438529370,812702999,355462360,4144912697,1731405415,4290775857,2394180231,1750603025,3675008525,1694076839,1203062813,3204075428]),xr=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var uh=BigInt(4294967295),BS=BigInt(32);function NI(t,e=!1){return e?{h:Number(t&uh),l:Number(t>>BS&uh)}:{h:Number(t>>BS&uh)|0,l:Number(t&uh)|0}}function kS(t,e=!1){let r=t.length,n=new Uint32Array(r),s=new Uint32Array(r);for(let i=0;i<r;i++){let{h:o,l:a}=NI(t[i],e);[n[i],s[i]]=[o,a]}return[n,s]}var Jm=(t,e,r)=>t>>>r,Qm=(t,e,r)=>t<<32-r|e>>>r,va=(t,e,r)=>t>>>r|e<<32-r,wa=(t,e,r)=>t<<32-r|e>>>r,dd=(t,e,r)=>t<<64-r|e>>>r-32,ld=(t,e,r)=>t>>>r-32|e<<64-r;function us(t,e,r,n){let s=(e>>>0)+(n>>>0);return{h:t+r+(s/2**32|0)|0,l:s|0}}var RS=(t,e,r)=>(t>>>0)+(e>>>0)+(r>>>0),NS=(t,e,r,n)=>e+r+n+(t/2**32|0)|0,PS=(t,e,r,n)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0),OS=(t,e,r,n,s)=>e+r+n+s+(t/2**32|0)|0,LS=(t,e,r,n,s)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0)+(s>>>0),US=(t,e,r,n,s,i)=>e+r+n+s+i+(t/2**32|0)|0;var OI=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]),Ji=new Uint32Array(64),e1=class extends fd{constructor(e=32){super(64,e,8,!1),this.A=$s[0]|0,this.B=$s[1]|0,this.C=$s[2]|0,this.D=$s[3]|0,this.E=$s[4]|0,this.F=$s[5]|0,this.G=$s[6]|0,this.H=$s[7]|0}get(){let{A:e,B:r,C:n,D:s,E:i,F:o,G:a,H:c}=this;return[e,r,n,s,i,o,a,c]}set(e,r,n,s,i,o,a,c){this.A=e|0,this.B=r|0,this.C=n|0,this.D=s|0,this.E=i|0,this.F=o|0,this.G=a|0,this.H=c|0}process(e,r){for(let p=0;p<16;p++,r+=4)Ji[p]=e.getUint32(r,!1);for(let p=16;p<64;p++){let x=Ji[p-15],v=Ji[p-2],S=_n(x,7)^_n(x,18)^x>>>3,I=_n(v,17)^_n(v,19)^v>>>10;Ji[p]=I+Ji[p-7]+S+Ji[p-16]|0}let{A:n,B:s,C:i,D:o,E:a,F:c,G:f,H:l}=this;for(let p=0;p<64;p++){let x=_n(a,6)^_n(a,11)^_n(a,25),v=l+x+TS(a,c,f)+OI[p]+Ji[p]|0,I=(_n(n,2)^_n(n,13)^_n(n,22))+_S(n,s,i)|0;l=f,f=c,c=a,a=o+v|0,o=i,i=s,s=n,n=v+I|0}n=n+this.A|0,s=s+this.B|0,i=i+this.C|0,o=o+this.D|0,a=a+this.E|0,c=c+this.F|0,f=f+this.G|0,l=l+this.H|0,this.set(n,s,i,o,a,c,f,l)}roundClean(){Fs(Ji)}destroy(){this.set(0,0,0,0,0,0,0,0),Fs(this.buffer)}};var DS=kS(["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(t=>BigInt(t))),LI=DS[0],UI=DS[1],Qi=new Uint32Array(80),eo=new Uint32Array(80),fh=class extends fd{constructor(e=64){super(128,e,16,!1),this.Ah=xr[0]|0,this.Al=xr[1]|0,this.Bh=xr[2]|0,this.Bl=xr[3]|0,this.Ch=xr[4]|0,this.Cl=xr[5]|0,this.Dh=xr[6]|0,this.Dl=xr[7]|0,this.Eh=xr[8]|0,this.El=xr[9]|0,this.Fh=xr[10]|0,this.Fl=xr[11]|0,this.Gh=xr[12]|0,this.Gl=xr[13]|0,this.Hh=xr[14]|0,this.Hl=xr[15]|0}get(){let{Ah:e,Al:r,Bh:n,Bl:s,Ch:i,Cl:o,Dh:a,Dl:c,Eh:f,El:l,Fh:p,Fl:x,Gh:v,Gl:S,Hh:I,Hl:L}=this;return[e,r,n,s,i,o,a,c,f,l,p,x,v,S,I,L]}set(e,r,n,s,i,o,a,c,f,l,p,x,v,S,I,L){this.Ah=e|0,this.Al=r|0,this.Bh=n|0,this.Bl=s|0,this.Ch=i|0,this.Cl=o|0,this.Dh=a|0,this.Dl=c|0,this.Eh=f|0,this.El=l|0,this.Fh=p|0,this.Fl=x|0,this.Gh=v|0,this.Gl=S|0,this.Hh=I|0,this.Hl=L|0}process(e,r){for(let ie=0;ie<16;ie++,r+=4)Qi[ie]=e.getUint32(r),eo[ie]=e.getUint32(r+=4);for(let ie=16;ie<80;ie++){let ve=Qi[ie-15]|0,ze=eo[ie-15]|0,he=va(ve,ze,1)^va(ve,ze,8)^Jm(ve,ze,7),Ne=wa(ve,ze,1)^wa(ve,ze,8)^Qm(ve,ze,7),we=Qi[ie-2]|0,X=eo[ie-2]|0,ut=va(we,X,19)^dd(we,X,61)^Jm(we,X,6),St=wa(we,X,19)^ld(we,X,61)^Qm(we,X,6),He=PS(Ne,St,eo[ie-7],eo[ie-16]),q=OS(He,he,ut,Qi[ie-7],Qi[ie-16]);Qi[ie]=q|0,eo[ie]=He|0}let{Ah:n,Al:s,Bh:i,Bl:o,Ch:a,Cl:c,Dh:f,Dl:l,Eh:p,El:x,Fh:v,Fl:S,Gh:I,Gl:L,Hh:ee,Hl:Pe}=this;for(let ie=0;ie<80;ie++){let ve=va(p,x,14)^va(p,x,18)^dd(p,x,41),ze=wa(p,x,14)^wa(p,x,18)^ld(p,x,41),he=p&v^~p&I,Ne=x&S^~x&L,we=LS(Pe,ze,Ne,UI[ie],eo[ie]),X=US(we,ee,ve,he,LI[ie],Qi[ie]),ut=we|0,St=va(n,s,28)^dd(n,s,34)^dd(n,s,39),He=wa(n,s,28)^ld(n,s,34)^ld(n,s,39),q=n&i^n&a^i&a,V=s&o^s&c^o&c;ee=I|0,Pe=L|0,I=v|0,L=S|0,v=p|0,S=x|0,{h:p,l:x}=us(f|0,l|0,X|0,ut|0),f=a|0,l=c|0,a=i|0,c=o|0,i=n|0,o=s|0;let M=RS(ut,He,V);n=NS(M,X,St,q),s=M|0}({h:n,l:s}=us(this.Ah|0,this.Al|0,n|0,s|0)),{h:i,l:o}=us(this.Bh|0,this.Bl|0,i|0,o|0),{h:a,l:c}=us(this.Ch|0,this.Cl|0,a|0,c|0),{h:f,l}=us(this.Dh|0,this.Dl|0,f|0,l|0),{h:p,l:x}=us(this.Eh|0,this.El|0,p|0,x|0),{h:v,l:S}=us(this.Fh|0,this.Fl|0,v|0,S|0),{h:I,l:L}=us(this.Gh|0,this.Gl|0,I|0,L|0),{h:ee,l:Pe}=us(this.Hh|0,this.Hl|0,ee|0,Pe|0),this.set(n,s,i,o,a,c,f,l,p,x,v,S,I,L,ee,Pe)}roundClean(){Fs(Qi,eo)}destroy(){Fs(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},t1=class extends fh{constructor(){super(48),this.Ah=pr[0]|0,this.Al=pr[1]|0,this.Bh=pr[2]|0,this.Bl=pr[3]|0,this.Ch=pr[4]|0,this.Cl=pr[5]|0,this.Dh=pr[6]|0,this.Dl=pr[7]|0,this.Eh=pr[8]|0,this.El=pr[9]|0,this.Fh=pr[10]|0,this.Fl=pr[11]|0,this.Gh=pr[12]|0,this.Gl=pr[13]|0,this.Hh=pr[14]|0,this.Hl=pr[15]|0}};var MS=nh(()=>new e1);var HS=nh(()=>new fh),jS=nh(()=>new t1);var dh=class extends Nc{constructor(e,r){super(),this.finished=!1,this.destroyed=!1,th(e);let n=od(r);if(this.iHash=e.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let s=this.blockLen,i=new Uint8Array(s);i.set(n.length>s?e.create().update(n).digest():n);for(let o=0;o<i.length;o++)i[o]^=54;this.iHash.update(i),this.oHash=e.create();for(let o=0;o<i.length;o++)i[o]^=106;this.oHash.update(i),Fs(i)}update(e){return Pc(this),this.iHash.update(e),this}digestInto(e){Pc(this),Tn(e,this.outputLen),this.finished=!0,this.iHash.digestInto(e),this.oHash.update(e),this.oHash.digestInto(e),this.destroy()}digest(){let e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||(e=Object.create(Object.getPrototypeOf(this),{}));let{oHash:r,iHash:n,finished:s,destroyed:i,blockLen:o,outputLen:a}=this;return e=e,e.finished=s,e.destroyed=i,e.blockLen=o,e.outputLen=a,e.oHash=r._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},r1=(t,e,r)=>new dh(t,e).update(r).digest();r1.create=(t,e)=>new dh(t,e);var Lc=BigInt(0),Sa=BigInt(1);function hd(t,e){let r=e.negate();return t?r:e}function hh(t,e){let r=ah(t.Fp,e.map(n=>n.Z));return e.map((n,s)=>t.fromAffine(n.toAffine(r[s])))}function FS(t,e){if(!Number.isSafeInteger(t)||t<=0||t>e)throw new Error("invalid window size, expected [1.."+e+"], got W="+t)}function n1(t,e){FS(t,e);let r=Math.ceil(e/t)+1,n=2**(t-1),s=2**t,i=Zi(t),o=BigInt(t);return{windows:r,windowSize:n,mask:i,maxNumber:s,shiftBy:o}}function qS(t,e,r){let{windowSize:n,mask:s,maxNumber:i,shiftBy:o}=r,a=Number(t&s),c=t>>o;a>n&&(a-=i,c+=Sa);let f=e*n,l=f+Math.abs(a)-1,p=a===0,x=a<0,v=e%2!==0;return{nextN:c,offset:l,isZero:p,isNeg:x,isNegF:v,offsetF:f}}function DI(t,e){if(!Array.isArray(t))throw new Error("array expected");t.forEach((r,n)=>{if(!(r instanceof e))throw new Error("invalid point at index "+n)})}function MI(t,e){if(!Array.isArray(t))throw new Error("array of scalars expected");t.forEach((r,n)=>{if(!e.isValid(r))throw new Error("invalid scalar at index "+n)})}var s1=new WeakMap,KS=new WeakMap;function i1(t){return KS.get(t)||1}function VS(t){if(t!==Lc)throw new Error("invalid wNAF")}var lh=class{constructor(e,r){this.BASE=e.BASE,this.ZERO=e.ZERO,this.Fn=e.Fn,this.bits=r}_unsafeLadder(e,r,n=this.ZERO){let s=e;for(;r>Lc;)r&Sa&&(n=n.add(s)),s=s.double(),r>>=Sa;return n}precomputeWindow(e,r){let{windows:n,windowSize:s}=n1(r,this.bits),i=[],o=e,a=o;for(let c=0;c<n;c++){a=o,i.push(a);for(let f=1;f<s;f++)a=a.add(o),i.push(a);o=a.double()}return i}wNAF(e,r,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let s=this.ZERO,i=this.BASE,o=n1(e,this.bits);for(let a=0;a<o.windows;a++){let{nextN:c,offset:f,isZero:l,isNeg:p,isNegF:x,offsetF:v}=qS(n,a,o);n=c,l?i=i.add(hd(x,r[v])):s=s.add(hd(p,r[f]))}return VS(n),{p:s,f:i}}wNAFUnsafe(e,r,n,s=this.ZERO){let i=n1(e,this.bits);for(let o=0;o<i.windows&&n!==Lc;o++){let{nextN:a,offset:c,isZero:f,isNeg:l}=qS(n,o,i);if(n=a,!f){let p=r[c];s=s.add(l?p.negate():p)}}return VS(n),s}getPrecomputes(e,r,n){let s=s1.get(r);return s||(s=this.precomputeWindow(r,e),e!==1&&(typeof n=="function"&&(s=n(s)),s1.set(r,s))),s}cached(e,r,n){let s=i1(e);return this.wNAF(s,this.getPrecomputes(s,e,n),r)}unsafe(e,r,n,s){let i=i1(e);return i===1?this._unsafeLadder(e,r,s):this.wNAFUnsafe(i,this.getPrecomputes(i,e,n),r,s)}createCache(e,r){FS(r,this.bits),KS.set(e,r),s1.delete(e)}hasCache(e){return i1(e)!==1}};function $S(t,e,r,n){let s=e,i=t.ZERO,o=t.ZERO;for(;r>Lc||n>Lc;)r&Sa&&(i=i.add(s)),n&Sa&&(o=o.add(s)),s=s.double(),r>>=Sa,n>>=Sa;return{p1:i,p2:o}}function WS(t,e,r,n){DI(r,t),MI(n,e);let s=r.length,i=n.length;if(s!==i)throw new Error("arrays of points and scalars must have equal length");let o=t.ZERO,a=oh(BigInt(s)),c=1;a>12?c=a-3:a>4?c=a-2:a>0&&(c=2);let f=Zi(c),l=new Array(Number(f)+1).fill(o),p=Math.floor((e.BITS-1)/c)*c,x=o;for(let v=p;v>=0;v-=c){l.fill(o);for(let I=0;I<i;I++){let L=n[I],ee=Number(L>>BigInt(v)&f);l[ee]=l[ee].add(r[I])}let S=o;for(let I=l.length-1,L=o;I>0;I--)L=L.add(l[I]),S=S.add(L);if(x=x.add(S),v!==0)for(let I=0;I<c;I++)x=x.double()}return x}function zS(t,e,r){if(e){if(e.ORDER!==t)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return Ym(e),e}else return cs(t,{isLE:r})}function GS(t,e,r={},n){if(n===void 0&&(n=t==="edwards"),!e||typeof e!="object")throw new Error(`expected valid ${t} CURVE object`);for(let c of["p","n","h"]){let f=e[c];if(!(typeof f=="bigint"&&f>Lc))throw new Error(`CURVE.${c} must be positive bigint`)}let s=zS(e.p,r.Fp,n),i=zS(e.n,r.Fn,n),a=["Gx","Gy","a",t==="weierstrass"?"b":"d"];for(let c of a)if(!s.isValid(e[c]))throw new Error(`CURVE.${c} must be valid field element of CURVE.Fp`);return e=Object.freeze(Object.assign({},e)),{CURVE:e,Fp:s,Fn:i}}var XS=(t,e)=>(t+(t>=0?e:-e)/YS)/e;function HI(t,e,r){let[[n,s],[i,o]]=e,a=XS(o*t,r),c=XS(-s*t,r),f=t-a*n-c*i,l=-a*s-c*o,p=f<Gs,x=l<Gs;p&&(f=-f),x&&(l=-l);let v=Zi(Math.ceil(oh(r)/2))+Dc;if(f<Gs||f>=v||l<Gs||l>=v)throw new Error("splitScalar (endomorphism): failed, k="+t);return{k1neg:p,k1:f,k2neg:x,k2:l}}function a1(t){if(!["compact","recovered","der"].includes(t))throw new Error('Signature format must be "compact", "recovered", or "der"');return t}function o1(t,e){let r={};for(let n of Object.keys(e))r[n]=t[n]===void 0?e[n]:t[n];return ad(r.lowS,"lowS"),ad(r.prehash,"prehash"),r.format!==void 0&&a1(r.format),r}var c1=class extends Error{constructor(e=""){super(e)}},Ws={Err:c1,_tlv:{encode:(t,e)=>{let{Err:r}=Ws;if(t<0||t>256)throw new r("tlv.encode: wrong tag");if(e.length&1)throw new r("tlv.encode: unpadded data");let n=e.length/2,s=cd(n);if(s.length/2&128)throw new r("tlv.encode: long form length too big");let i=n>127?cd(s.length/2|128):"";return cd(t)+i+s+e},decode(t,e){let{Err:r}=Ws,n=0;if(t<0||t>256)throw new r("tlv.encode: wrong tag");if(e.length<2||e[n++]!==t)throw new r("tlv.decode: wrong tlv");let s=e[n++],i=!!(s&128),o=0;if(!i)o=s;else{let c=s&127;if(!c)throw new r("tlv.decode(long): indefinite length not supported");if(c>4)throw new r("tlv.decode(long): byte length is too big");let f=e.subarray(n,n+c);if(f.length!==c)throw new r("tlv.decode: length bytes not complete");if(f[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let l of f)o=o<<8|l;if(n+=c,o<128)throw new r("tlv.decode(long): not minimal encoding")}let a=e.subarray(n,n+o);if(a.length!==o)throw new r("tlv.decode: wrong value length");return{v:a,l:e.subarray(n+o)}}},_int:{encode(t){let{Err:e}=Ws;if(t<Gs)throw new e("integer: negative integers are not allowed");let r=cd(t);if(Number.parseInt(r[0],16)&8&&(r="00"+r),r.length&1)throw new e("unexpected DER parsing assertion: unpadded hex");return r},decode(t){let{Err:e}=Ws;if(t[0]&128)throw new e("invalid signature integer: negative");if(t[0]===0&&!(t[1]&128))throw new e("invalid signature integer: unnecessary leading zero");return Oc(t)}},toSig(t){let{Err:e,_int:r,_tlv:n}=Ws,s=Cr("signature",t),{v:i,l:o}=n.decode(48,s);if(o.length)throw new e("invalid signature: left bytes after parsing");let{v:a,l:c}=n.decode(2,i),{v:f,l}=n.decode(2,c);if(l.length)throw new e("invalid signature: left bytes after parsing");return{r:r.decode(a),s:r.decode(f)}},hexFromSig(t){let{_tlv:e,_int:r}=Ws,n=e.encode(2,r.encode(t.r)),s=e.encode(2,r.encode(t.s)),i=n+s;return e.encode(48,i)}},Gs=BigInt(0),Dc=BigInt(1),YS=BigInt(2),ph=BigInt(3),jI=BigInt(4);function Uc(t,e){let{BYTES:r}=t,n;if(typeof e=="bigint")n=e;else{let s=Cr("private key",e);try{n=t.fromBytes(s)}catch{throw new Error(`invalid private key: expected ui8a of size ${r}, got ${typeof e}`)}}if(!t.isValidNot0(n))throw new Error("invalid private key: out of range [1..N-1]");return n}function qI(t,e={}){let r=GS("weierstrass",t,e),{Fp:n,Fn:s}=r,i=r.CURVE,{h:o,n:a}=i;ud(e,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",wrapPrivateKey:"boolean"});let{endo:c}=e;if(c&&(!n.is0(i.a)||typeof c.beta!="bigint"||!Array.isArray(c.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let f=JS(n,s);function l(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function p(He,q,V){let{x:M,y:oe}=q.toAffine(),ge=n.toBytes(M);if(ad(V,"isCompressed"),V){l();let Te=!n.isOdd(oe);return Bn(ZS(Te),ge)}else return Bn(Uint8Array.of(4),ge,n.toBytes(oe))}function x(He){Yi(He,void 0,"Point");let{publicKey:q,publicKeyUncompressed:V}=f,M=He.length,oe=He[0],ge=He.subarray(1);if(M===q&&(oe===2||oe===3)){let Te=n.fromBytes(ge);if(!n.isValid(Te))throw new Error("bad point: is not on curve, wrong x");let A=I(Te),T;try{T=n.sqrt(A)}catch(N){let Z=N instanceof Error?": "+N.message:"";throw new Error("bad point: is not on curve, sqrt error"+Z)}l();let H=n.isOdd(T);return(oe&1)===1!==H&&(T=n.neg(T)),{x:Te,y:T}}else if(M===V&&oe===4){let Te=n.BYTES,A=n.fromBytes(ge.subarray(0,Te)),T=n.fromBytes(ge.subarray(Te,Te*2));if(!L(A,T))throw new Error("bad point: is not on curve");return{x:A,y:T}}else throw new Error(`bad point: got length ${M}, expected compressed=${q} or uncompressed=${V}`)}let v=e.toBytes||p,S=e.fromBytes||x;function I(He){let q=n.sqr(He),V=n.mul(q,He);return n.add(n.add(V,n.mul(He,i.a)),i.b)}function L(He,q){let V=n.sqr(q),M=I(He);return n.eql(V,M)}if(!L(i.Gx,i.Gy))throw new Error("bad curve params: generator point");let ee=n.mul(n.pow(i.a,ph),jI),Pe=n.mul(n.sqr(i.b),BigInt(27));if(n.is0(n.add(ee,Pe)))throw new Error("bad curve params: a or b");function ie(He,q,V=!1){if(!n.isValid(q)||V&&n.is0(q))throw new Error(`bad point coordinate ${He}`);return q}function ve(He){if(!(He instanceof X))throw new Error("ProjectivePoint expected")}function ze(He){if(!c||!c.basises)throw new Error("no endo");return HI(He,c.basises,s.ORDER)}let he=Gm((He,q)=>{let{X:V,Y:M,Z:oe}=He;if(n.eql(oe,n.ONE))return{x:V,y:M};let ge=He.is0();q==null&&(q=ge?n.ONE:n.inv(oe));let Te=n.mul(V,q),A=n.mul(M,q),T=n.mul(oe,q);if(ge)return{x:n.ZERO,y:n.ZERO};if(!n.eql(T,n.ONE))throw new Error("invZ was invalid");return{x:Te,y:A}}),Ne=Gm(He=>{if(He.is0()){if(e.allowInfinityPoint&&!n.is0(He.Y))return;throw new Error("bad point: ZERO")}let{x:q,y:V}=He.toAffine();if(!n.isValid(q)||!n.isValid(V))throw new Error("bad point: x or y not field elements");if(!L(q,V))throw new Error("bad point: equation left != right");if(!He.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function we(He,q,V,M,oe){return V=new X(n.mul(V.X,He),V.Y,V.Z),q=hd(M,q),V=hd(oe,V),q.add(V)}class X{constructor(q,V,M){this.X=ie("x",q),this.Y=ie("y",V,!0),this.Z=ie("z",M),Object.freeze(this)}static CURVE(){return i}static fromAffine(q){let{x:V,y:M}=q||{};if(!q||!n.isValid(V)||!n.isValid(M))throw new Error("invalid affine point");if(q instanceof X)throw new Error("projective point not allowed");return n.is0(V)&&n.is0(M)?X.ZERO:new X(V,M,n.ONE)}static fromBytes(q){let V=X.fromAffine(S(Yi(q,void 0,"point")));return V.assertValidity(),V}static fromHex(q){return X.fromBytes(Cr("pointHex",q))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(q=8,V=!0){return St.createCache(this,q),V||this.multiply(ph),this}assertValidity(){Ne(this)}hasEvenY(){let{y:q}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(q)}equals(q){ve(q);let{X:V,Y:M,Z:oe}=this,{X:ge,Y:Te,Z:A}=q,T=n.eql(n.mul(V,A),n.mul(ge,oe)),H=n.eql(n.mul(M,A),n.mul(Te,oe));return T&&H}negate(){return new X(this.X,n.neg(this.Y),this.Z)}double(){let{a:q,b:V}=i,M=n.mul(V,ph),{X:oe,Y:ge,Z:Te}=this,A=n.ZERO,T=n.ZERO,H=n.ZERO,C=n.mul(oe,oe),N=n.mul(ge,ge),Z=n.mul(Te,Te),ne=n.mul(oe,ge);return ne=n.add(ne,ne),H=n.mul(oe,Te),H=n.add(H,H),A=n.mul(q,H),T=n.mul(M,Z),T=n.add(A,T),A=n.sub(N,T),T=n.add(N,T),T=n.mul(A,T),A=n.mul(ne,A),H=n.mul(M,H),Z=n.mul(q,Z),ne=n.sub(C,Z),ne=n.mul(q,ne),ne=n.add(ne,H),H=n.add(C,C),C=n.add(H,C),C=n.add(C,Z),C=n.mul(C,ne),T=n.add(T,C),Z=n.mul(ge,Te),Z=n.add(Z,Z),C=n.mul(Z,ne),A=n.sub(A,C),H=n.mul(Z,N),H=n.add(H,H),H=n.add(H,H),new X(A,T,H)}add(q){ve(q);let{X:V,Y:M,Z:oe}=this,{X:ge,Y:Te,Z:A}=q,T=n.ZERO,H=n.ZERO,C=n.ZERO,N=i.a,Z=n.mul(i.b,ph),ne=n.mul(V,ge),Ye=n.mul(M,Te),at=n.mul(oe,A),Et=n.add(V,M),lt=n.add(ge,Te);Et=n.mul(Et,lt),lt=n.add(ne,Ye),Et=n.sub(Et,lt),lt=n.add(V,oe);let Ct=n.add(ge,A);return lt=n.mul(lt,Ct),Ct=n.add(ne,at),lt=n.sub(lt,Ct),Ct=n.add(M,oe),T=n.add(Te,A),Ct=n.mul(Ct,T),T=n.add(Ye,at),Ct=n.sub(Ct,T),C=n.mul(N,lt),T=n.mul(Z,at),C=n.add(T,C),T=n.sub(Ye,C),C=n.add(Ye,C),H=n.mul(T,C),Ye=n.add(ne,ne),Ye=n.add(Ye,ne),at=n.mul(N,at),lt=n.mul(Z,lt),Ye=n.add(Ye,at),at=n.sub(ne,at),at=n.mul(N,at),lt=n.add(lt,at),ne=n.mul(Ye,lt),H=n.add(H,ne),ne=n.mul(Ct,lt),T=n.mul(Et,T),T=n.sub(T,ne),ne=n.mul(Et,Ye),C=n.mul(Ct,C),C=n.add(C,ne),new X(T,H,C)}subtract(q){return this.add(q.negate())}is0(){return this.equals(X.ZERO)}multiply(q){let{endo:V}=e;if(!s.isValidNot0(q))throw new Error("invalid scalar: out of range");let M,oe,ge=Te=>St.cached(this,Te,A=>hh(X,A));if(V){let{k1neg:Te,k1:A,k2neg:T,k2:H}=ze(q),{p:C,f:N}=ge(A),{p:Z,f:ne}=ge(H);oe=N.add(ne),M=we(V.beta,C,Z,Te,T)}else{let{p:Te,f:A}=ge(q);M=Te,oe=A}return hh(X,[M,oe])[0]}multiplyUnsafe(q){let{endo:V}=e,M=this;if(!s.isValid(q))throw new Error("invalid scalar: out of range");if(q===Gs||M.is0())return X.ZERO;if(q===Dc)return M;if(St.hasCache(this))return this.multiply(q);if(V){let{k1neg:oe,k1:ge,k2neg:Te,k2:A}=ze(q),{p1:T,p2:H}=$S(X,M,ge,A);return we(V.beta,T,H,oe,Te)}else return St.unsafe(M,q)}multiplyAndAddUnsafe(q,V,M){let oe=this.multiplyUnsafe(V).add(q.multiplyUnsafe(M));return oe.is0()?void 0:oe}toAffine(q){return he(this,q)}isTorsionFree(){let{isTorsionFree:q}=e;return o===Dc?!0:q?q(X,this):St.unsafe(this,a).is0()}clearCofactor(){let{clearCofactor:q}=e;return o===Dc?this:q?q(X,this):this.multiplyUnsafe(o)}isSmallOrder(){return this.multiplyUnsafe(o).is0()}toBytes(q=!0){return ad(q,"isCompressed"),this.assertValidity(),v(X,this,q)}toHex(q=!0){return Ks(this.toBytes(q))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}get px(){return this.X}get py(){return this.X}get pz(){return this.Z}toRawBytes(q=!0){return this.toBytes(q)}_setWindowSize(q){this.precompute(q)}static normalizeZ(q){return hh(X,q)}static msm(q,V){return WS(X,s,q,V)}static fromPrivateKey(q){return X.BASE.multiply(Uc(s,q))}}X.BASE=new X(i.Gx,i.Gy,n.ONE),X.ZERO=new X(n.ZERO,n.ONE,n.ZERO),X.Fp=n,X.Fn=s;let ut=s.BITS,St=new lh(X,e.endo?Math.ceil(ut/2):ut);return X.BASE.precompute(8),X}function ZS(t){return Uint8Array.of(t?2:3)}function JS(t,e){return{secretKey:e.BYTES,publicKey:1+t.BYTES,publicKeyUncompressed:1+2*t.BYTES,publicKeyHasPrefix:!0,signature:2*e.BYTES}}function VI(t,e={}){let{Fn:r}=t,n=e.randomBytes||sh,s=Object.assign(JS(t.Fp,r),{seed:Zm(r.ORDER)});function i(v){try{return!!Uc(r,v)}catch{return!1}}function o(v,S){let{publicKey:I,publicKeyUncompressed:L}=s;try{let ee=v.length;return S===!0&&ee!==I||S===!1&&ee!==L?!1:!!t.fromBytes(v)}catch{return!1}}function a(v=n(s.seed)){return IS(Yi(v,s.seed,"seed"),r.ORDER)}function c(v,S=!0){return t.BASE.multiply(Uc(r,v)).toBytes(S)}function f(v){let S=a(v);return{secretKey:S,publicKey:c(S)}}function l(v){if(typeof v=="bigint")return!1;if(v instanceof t)return!0;let{secretKey:S,publicKey:I,publicKeyUncompressed:L}=s;if(r.allowedLengths||S===I)return;let ee=Cr("key",v).length;return ee===I||ee===L}function p(v,S,I=!0){if(l(v)===!0)throw new Error("first arg must be private key");if(l(S)===!1)throw new Error("second arg must be public key");let L=Uc(r,v);return t.fromHex(S).multiply(L).toBytes(I)}return Object.freeze({getPublicKey:c,getSharedSecret:p,keygen:f,Point:t,utils:{isValidSecretKey:i,isValidPublicKey:o,randomSecretKey:a,isValidPrivateKey:i,randomPrivateKey:a,normPrivateKeyToScalar:v=>Uc(r,v),precompute(v=8,S=t.BASE){return S.precompute(v,!1)}},lengths:s})}function zI(t,e,r={}){th(e),ud(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});let n=r.randomBytes||sh,s=r.hmac||((V,...M)=>r1(e,V,Bn(...M))),{Fp:i,Fn:o}=t,{ORDER:a,BITS:c}=o,{keygen:f,getPublicKey:l,getSharedSecret:p,utils:x,lengths:v}=VI(t,r),S={prehash:!1,lowS:typeof r.lowS=="boolean"?r.lowS:!1,format:void 0,extraEntropy:!1},I="compact";function L(V){let M=a>>Dc;return V>M}function ee(V,M){if(!o.isValidNot0(M))throw new Error(`invalid signature ${V}: out of range 1..Point.Fn.ORDER`);return M}function Pe(V,M){a1(M);let oe=v.signature,ge=M==="compact"?oe:M==="recovered"?oe+1:void 0;return Yi(V,ge,`${M} signature`)}class ie{constructor(M,oe,ge){this.r=ee("r",M),this.s=ee("s",oe),ge!=null&&(this.recovery=ge),Object.freeze(this)}static fromBytes(M,oe=I){Pe(M,oe);let ge;if(oe==="der"){let{r:H,s:C}=Ws.toSig(Yi(M));return new ie(H,C)}oe==="recovered"&&(ge=M[0],oe="compact",M=M.subarray(1));let Te=o.BYTES,A=M.subarray(0,Te),T=M.subarray(Te,Te*2);return new ie(o.fromBytes(A),o.fromBytes(T),ge)}static fromHex(M,oe){return this.fromBytes(ya(M),oe)}addRecoveryBit(M){return new ie(this.r,this.s,M)}recoverPublicKey(M){let oe=i.ORDER,{r:ge,s:Te,recovery:A}=this;if(A==null||![0,1,2,3].includes(A))throw new Error("recovery id invalid");if(a*YS<oe&&A>1)throw new Error("recovery id is ambiguous for h>1 curve");let H=A===2||A===3?ge+a:ge;if(!i.isValid(H))throw new Error("recovery id 2 or 3 invalid");let C=i.toBytes(H),N=t.fromBytes(Bn(ZS((A&1)===0),C)),Z=o.inv(H),ne=ze(Cr("msgHash",M)),Ye=o.create(-ne*Z),at=o.create(Te*Z),Et=t.BASE.multiplyUnsafe(Ye).add(N.multiplyUnsafe(at));if(Et.is0())throw new Error("point at infinify");return Et.assertValidity(),Et}hasHighS(){return L(this.s)}toBytes(M=I){if(a1(M),M==="der")return ya(Ws.hexFromSig(this));let oe=o.toBytes(this.r),ge=o.toBytes(this.s);if(M==="recovered"){if(this.recovery==null)throw new Error("recovery bit must be present");return Bn(Uint8Array.of(this.recovery),oe,ge)}return Bn(oe,ge)}toHex(M){return Ks(this.toBytes(M))}assertValidity(){}static fromCompact(M){return ie.fromBytes(Cr("sig",M),"compact")}static fromDER(M){return ie.fromBytes(Cr("sig",M),"der")}normalizeS(){return this.hasHighS()?new ie(this.r,o.neg(this.s),this.recovery):this}toDERRawBytes(){return this.toBytes("der")}toDERHex(){return Ks(this.toBytes("der"))}toCompactRawBytes(){return this.toBytes("compact")}toCompactHex(){return Ks(this.toBytes("compact"))}}let ve=r.bits2int||function(M){if(M.length>8192)throw new Error("input is too large");let oe=Oc(M),ge=M.length*8-c;return ge>0?oe>>BigInt(ge):oe},ze=r.bits2int_modN||function(M){return o.create(ve(M))},he=Zi(c);function Ne(V){return pS("num < 2^"+c,V,Gs,he),o.toBytes(V)}function we(V,M){return Yi(V,void 0,"message"),M?Yi(e(V),void 0,"prehashed message"):V}function X(V,M,oe){if(["recovered","canonical"].some(Ye=>Ye in oe))throw new Error("sign() legacy options not supported");let{lowS:ge,prehash:Te,extraEntropy:A}=o1(oe,S);V=we(V,Te);let T=ze(V),H=Uc(o,M),C=[Ne(H),Ne(T)];if(A!=null&&A!==!1){let Ye=A===!0?n(v.secretKey):A;C.push(Cr("extraEntropy",Ye))}let N=Bn(...C),Z=T;function ne(Ye){let at=ve(Ye);if(!o.isValidNot0(at))return;let Et=o.inv(at),lt=t.BASE.multiply(at).toAffine(),Ct=o.create(lt.x);if(Ct===Gs)return;let rn=o.create(Et*o.create(Z+Ct*H));if(rn===Gs)return;let nn=(lt.x===Ct?0:2)|Number(lt.y&Dc),xo=rn;return ge&&L(rn)&&(xo=o.neg(rn),nn^=1),new ie(Ct,xo,nn)}return{seed:N,k2sig:ne}}function ut(V,M,oe={}){V=Cr("message",V);let{seed:ge,k2sig:Te}=X(V,M,oe);return xS(e.outputLen,o.BYTES,s)(ge,Te)}function St(V){let M,oe=typeof V=="string"||ga(V),ge=!oe&&V!==null&&typeof V=="object"&&typeof V.r=="bigint"&&typeof V.s=="bigint";if(!oe&&!ge)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");if(ge)M=new ie(V.r,V.s);else if(oe){try{M=ie.fromBytes(Cr("sig",V),"der")}catch(Te){if(!(Te instanceof Ws.Err))throw Te}if(!M)try{M=ie.fromBytes(Cr("sig",V),"compact")}catch{return!1}}return M||!1}function He(V,M,oe,ge={}){let{lowS:Te,prehash:A,format:T}=o1(ge,S);if(oe=Cr("publicKey",oe),M=we(Cr("message",M),A),"strict"in ge)throw new Error("options.strict was renamed to lowS");let H=T===void 0?St(V):ie.fromBytes(Cr("sig",V),T);if(H===!1)return!1;try{let C=t.fromBytes(oe);if(Te&&H.hasHighS())return!1;let{r:N,s:Z}=H,ne=ze(M),Ye=o.inv(Z),at=o.create(ne*Ye),Et=o.create(N*Ye),lt=t.BASE.multiplyUnsafe(at).add(C.multiplyUnsafe(Et));return lt.is0()?!1:o.create(lt.x)===N}catch{return!1}}function q(V,M,oe={}){let{prehash:ge}=o1(oe,S);return M=we(M,ge),ie.fromBytes(V,"recovered").recoverPublicKey(M).toBytes()}return Object.freeze({keygen:f,getPublicKey:l,getSharedSecret:p,utils:x,lengths:v,Point:t,sign:ut,verify:He,recoverPublicKey:q,Signature:ie,hash:e})}function FI(t){let e={a:t.a,b:t.b,p:t.Fp.ORDER,n:t.n,h:t.h,Gx:t.Gx,Gy:t.Gy},r=t.Fp,n=t.allowedPrivateKeyLengths?Array.from(new Set(t.allowedPrivateKeyLengths.map(o=>Math.ceil(o/2)))):void 0,s=cs(e.n,{BITS:t.nBitLength,allowedLengths:n,modFromBytes:t.wrapPrivateKey}),i={Fp:r,Fn:s,allowInfinityPoint:t.allowInfinityPoint,endo:t.endo,isTorsionFree:t.isTorsionFree,clearCofactor:t.clearCofactor,fromBytes:t.fromBytes,toBytes:t.toBytes};return{CURVE:e,curveOpts:i}}function KI(t){let{CURVE:e,curveOpts:r}=FI(t),n={hmac:t.hmac,randomBytes:t.randomBytes,lowS:t.lowS,bits2int:t.bits2int,bits2int_modN:t.bits2int_modN};return{CURVE:e,curveOpts:r,hash:t.hash,ecdsaOpts:n}}function $I(t,e){let r=e.Point;return Object.assign({},e,{ProjectivePoint:r,CURVE:Object.assign({},t,ch(r.Fn.ORDER,r.Fn.BITS))})}function QS(t){let{CURVE:e,curveOpts:r,hash:n,ecdsaOpts:s}=KI(t),i=qI(e,r),o=zI(i,n,s);return $I(t,o)}function xh(t,e){let r=n=>QS({...t,hash:n});return{...r(e),create:r}}var e6={p:BigInt("0xffffffff00000001000000000000000000000000ffffffffffffffffffffffff"),n:BigInt("0xffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551"),h:BigInt(1),a:BigInt("0xffffffff00000001000000000000000000000000fffffffffffffffffffffffc"),b:BigInt("0x5ac635d8aa3a93e7b3ebbd55769886bc651d06b0cc53b0f63bce3c3e27d2604b"),Gx:BigInt("0x6b17d1f2e12c4247f8bce6e563a440f277037d812deb33a0f4a13945d898c296"),Gy:BigInt("0x4fe342e2fe1a7f9b8ee7eb4a7c0f9e162bce33576b315ececbb6406837bf51f5")},t6={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffeffffffff0000000000000000ffffffff"),n:BigInt("0xffffffffffffffffffffffffffffffffffffffffffffffffc7634d81f4372ddf581a0db248b0a77aecec196accc52973"),h:BigInt(1),a:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffeffffffff0000000000000000fffffffc"),b:BigInt("0xb3312fa7e23ee7e4988e056be3f82d19181d9c6efe8141120314088f5013875ac656398d8a2ed19d2a85c8edd3ec2aef"),Gx:BigInt("0xaa87ca22be8b05378eb1c71ef320ad746e1d3b628ba79b9859f741e082542a385502f25dbf55296c3a545e3872760ab7"),Gy:BigInt("0x3617de4a96262c6f5d9e98bf9292dc29f8f41dbd289a147ce9da3113b5f0b8c00a60b1ce1d7e819d7a431d7c90ea0e5f")},r6={p:BigInt("0x1ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),n:BigInt("0x01fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffa51868783bf2f966b7fcc0148f709a5d03bb5c9b8899c47aebb6fb71e91386409"),h:BigInt(1),a:BigInt("0x1fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc"),b:BigInt("0x0051953eb9618e1c9a1f929a21a0b68540eea2da725b99b315f3b8b489918ef109e156193951ec7e937b1652c0bd3bb1bf073573df883d2c34f1ef451fd46b503f00"),Gx:BigInt("0x00c6858e06b70404e9cd9e3ecb662395b4429c648139053fb521f828af606b4d3dbaa14b5e77efe75928fe1dc127a2ffa8de3348b3c1856a429bf97e7e31c2e5bd66"),Gy:BigInt("0x011839296a789a3bc0045c8a5fb42c7d1bd998f54449579b446817afbd17273e662c97ee72995ef42640c550b9013fad0761353c7086a272c24088be94769fd16650")},WI=cs(e6.p),GI=cs(t6.p),XI=cs(r6.p);var n6=xh({...e6,Fp:WI,lowS:!1},MS);var GY=xh({...t6,Fp:GI,lowS:!1},jS);var XY=xh({...r6,Fp:XI,lowS:!1,allowedPrivateKeyLengths:[130,131,132]},HS);var mh=n6;var gr=it(Ut(),1),Mn=it(Ut(),1),O8=it(Ut(),1),Ra=it(Ut(),1),ci=it(Ut(),1),j8=it(pl(),1),Pa=it(Ut(),1),co=it(Ut(),1),Oa=it(Ut(),1),su=it(Ut(),1),uo=it(Ut(),1),La=it(Ut(),1),Hn=it(Ut(),1),qn=it(Ut(),1),pp=it(Ut(),1),Dn=it(Ut(),1),G8=it(Ut(),1),Y8=it(i6(),1),Xg=it(hi(),1),Rh=it(a6(),1),Ua=it(Ut(),1),_a=it(Ut(),1),vs=it(Ut(),1),bs=it(Ut(),1),Da=it(Ut(),1);import{randomBytes as a_}from"crypto";import{setTimeout as c_}from"timers/promises";import{createCipheriv as b_,createDecipheriv as v_}from"crypto";import{createHmac as T1}from"crypto";import{createCipheriv as Z6,createDecipheriv as J6,createHmac as Q6,timingSafeEqual as l7}from"crypto";import{createCipheriv as n3,createDecipheriv as s3}from"crypto";import{setTimeout as S7}from"timers/promises";import{randomBytes as T7}from"crypto";import{createHmac as R4}from"crypto";import{randomBytes as N4}from"crypto";var yh="undefined",qc=yh!==typeof Buffer&&Buffer,jc=yh!==typeof Uint8Array&&Uint8Array,gh=yh!==typeof ArrayBuffer&&ArrayBuffer,c6=[0,0,0,0,0,0,0,0],YI=Array.isArray||sT,Hc=4294967296,ZI=16777216,Vc,bh=f6("Uint64BE",!0,!0),d1=f6("Int64BE",!0,!1);function f6(t,e,r){var n=e?0:4,s=e?4:0,i=e?0:3,o=e?1:2,a=e?2:1,c=e?3:0,f=e?eT:rT,l=e?tT:nT,p=S.prototype,x="is"+t,v="_"+x;return p.buffer=void 0,p.offset=0,p[v]=!0,p.toNumber=Pe,p.toString=ie,p.toJSON=Pe,p.toArray=JI,qc&&(p.toBuffer=QI),jc&&(p.toArrayBuffer=d6),S[x]=I,S;function S(he,Ne,we,X){return this instanceof S?L(this,he,Ne,we,X):new S(he,Ne,we,X)}function I(he){return!!(he&&he[v])}function L(he,Ne,we,X,ut){if(jc&&gh&&(Ne instanceof gh&&(Ne=new jc(Ne)),X instanceof gh&&(X=new jc(X))),!Ne&&!we&&!X&&!Vc){he.buffer=l6(c6,0);return}if(!u6(Ne,we)){var St=Vc||Array;ut=we,X=Ne,we=0,Ne=Vc===qc?qc.alloc(8):new St(8)}he.buffer=Ne,he.offset=we|=0,yh!==typeof X&&(typeof X=="string"?ee(Ne,we,X,ut||10):u6(X,ut)?f1(Ne,we,X,ut):typeof ut=="number"?(ve(Ne,we+n,X),ve(Ne,we+s,ut)):X>0?f(Ne,we,X):X<0?l(Ne,we,X):f1(Ne,we,c6,0))}function ee(he,Ne,we,X){var ut=0,St=we.length,He=0,q=0;we[0]==="-"&&ut++;for(var V=ut;ut<St;){var M=parseInt(we[ut++],X);if(!(M>=0))break;q=q*X+M,He=He*X+Math.floor(q/Hc),q%=Hc}V&&(He=~He,q?q=Hc-q:He++),ve(he,Ne+n,He),ve(he,Ne+s,q)}function Pe(){var he=this.buffer,Ne=this.offset,we=ze(he,Ne+n),X=ze(he,Ne+s);return r||(we|=0),we?we*Hc+X:X}function ie(he){var Ne=this.buffer,we=this.offset,X=ze(Ne,we+n),ut=ze(Ne,we+s),St="",He=!r&&X&2147483648;for(He&&(X=~X,ut=Hc-ut),he=he||10;;){var q=X%he*Hc+ut;if(X=Math.floor(X/he),ut=Math.floor(q/he),St=(q%he).toString(he)+St,!X&&!ut)break}return He&&(St="-"+St),St}function ve(he,Ne,we){he[Ne+c]=we&255,we=we>>8,he[Ne+a]=we&255,we=we>>8,he[Ne+o]=we&255,we=we>>8,he[Ne+i]=we&255}function ze(he,Ne){return he[Ne+i]*ZI+(he[Ne+o]<<16)+(he[Ne+a]<<8)+he[Ne+c]}}function JI(t){var e=this.buffer,r=this.offset;return Vc=null,t!==!1&&YI(e)?e.length===8?e:e.slice(r,r+8):l6(e,r)}function QI(t){var e=this.buffer,r=this.offset;return Vc=qc,t!==!1&&qc.isBuffer(e)?e.length===8?e:e.slice(r,r+8):qc.from(d6.call(this,t))}function d6(t){var e=this.buffer,r=this.offset,n=e.buffer;if(Vc=jc,t!==!1&&!e.offset&&n instanceof gh)return n.byteLength===8?n:n.slice(r,r+8);var s=new jc(8);return f1(s,0,e,r),s.buffer}function u6(t,e){var r=t&&t.length;return e|=0,r&&e+8<=r&&typeof t[e]!="string"}function f1(t,e,r,n){e|=0,n|=0;for(var s=0;s<8;s++)t[e++]=r[n++]&255}function l6(t,e){return Array.prototype.slice.call(t,e,e+8)}function eT(t,e,r){for(var n=e+8;n>e;)t[--n]=r&255,r/=256}function tT(t,e,r){var n=e+8;for(r++;n>e;)t[--n]=-r&255^255,r/=256}function rT(t,e,r){for(var n=e+8;e<n;)t[e++]=r&255,r/=256}function nT(t,e,r){var n=e+8;for(r++;e<n;)t[e++]=-r&255^255,r/=256}function sT(t){return!!t&&Object.prototype.toString.call(t)=="[object Array]"}var Wd=it(h1(),1),mg=it(hi(),1);import{createHash as K7}from"crypto";import{setTimeout as $7}from"timers/promises";import{createHash as eB}from"crypto";import{isIPv4 as E3}from"net";import{randomBytes as tB}from"crypto";import{isIPv4 as A3}from"net";var Uh=it(x6(),1),F4=it(N6(),1),$4=it(h1(),1);import*as yg from"timers/promises";import{randomUUID as nB}from"crypto";import*as K4 from"os";import{EventEmitter as xB}from"events";import{randomUUID as CB}from"crypto";import{setTimeout as U1}from"timers/promises";import{createHash as IB}from"crypto";import{createSocket as TB}from"dgram";import{performance as P3}from"perf_hooks";import{randomUUID as _B}from"crypto";import{randomUUID as s5}from"crypto";import{setTimeout as YB}from"timers/promises";import{randomBytes as ek}from"crypto";import{isIPv4 as tk}from"net";var Gd=it(Up(),1),Mh=it(hi(),1),Hh=it(hi(),1),ui=it(hi(),1),qg=it(hi(),1);import{randomUUID as rk}from"crypto";import{setTimeout as nk}from"timers/promises";import{randomUUID as ck}from"crypto";import{randomUUID as hk}from"crypto";import{createHmac as K3,randomBytes as pk}from"crypto";import{randomBytes as n8}from"crypto";import{randomUUID as s8}from"crypto";import{setTimeout as i8}from"timers/promises";import{randomUUID as Vk}from"crypto";function f8(){return Vg.jspack.Unpack("!H",u8(2))[0]}function V1(){return Vg.jspack.Unpack("!L",u8(4))[0]}function lZ(t,e){if(t.length!==e.length)throw new TypeError("[webrtc-stun] You can not XOR buffers which length are different");let r=t.length,n=Buffer.allocUnsafe(r);for(let s=0;s<r;s++)n[s]=t[s]^e[s];return n}function hZ(t){let e=[...t].sort((n,s)=>n.length-s.length).reverse()[0].length,r=Buffer.allocUnsafe(e);for(let n=0;n<e;n++)r[n]=0,t.forEach(s=>{r[n]^=s[n]??0});return r}var $h=class{constructor(t){this.bitLength=t}value=0;set(t,e,r){return r&=(1<<t)-1,this.value|=r<<this.bitLength-t-e,this}get buffer(){let t=Math.ceil(this.bitLength/8),e=Buffer.alloc(t);return e.writeUIntBE(this.value,0,t),e}},zg=class{constructor(t){if(this.bitLength=t,t>32)throw new Error}_value=0n;offset=0n;set(t,e=1){let r=BigInt(t),n=BigInt(e);return r&=(1n<<n)-1n,this._value|=r<<BigInt(this.bitLength)-n-this.offset,this.offset+=n,this}get value(){return Number(this._value)}get buffer(){let t=Math.ceil(this.bitLength/8),e=Buffer.alloc(t);return e.writeUIntBE(this.value,0,t),e}};function ue(t,e,r=1){let n=t.toString(2).split("");n=[...Array(8-n.length).fill("0"),...n];let s=n.slice(e,e+r).join("");return Number.parseInt(s,2)}function Wh(t){let e=t.toString(2).split("");return[...[...Array(8-e.length)].map(()=>"0"),...e].join("")}function pZ(t,e){let r=t.toString(2);return[...[...Array(e-r.length)].map(()=>"0"),...r].join("")}function Ht(t,e){return Th(t)(e)}function Th(t,e){let r=t.reduce((s,i)=>s+i,0),n=e?Buffer.alloc(r):void 0;return s=>{let i=n||Buffer.alloc(r),o=0;return s.forEach((a,c)=>{let f=t[c];f===8?i.writeBigUInt64BE(a,o):i.writeUIntBE(a,o,f),o+=f}),i}}function IT(t,e){let r=t.reduce((i,o)=>i+o,0),n=Buffer.alloc(r),s=0;return e.forEach((i,o)=>{let a=t[o];a===8?n.writeBigUInt64LE(i,s):n.writeUIntLE(i,s,a),s+=a}),n}function Wr(t,e){let r=0;return e.map(n=>{let s;return n===8?s=t.readBigUInt64BE(r):s=t.readUIntBE(r,n),r+=n,s})}var xZ=class{buffer;constructor(t){this.buffer=Buffer.alloc(t)}writeInt16BE(t,e){return this.buffer.writeInt16BE(t,e),this}writeUInt8(t,e){return this.buffer.writeUInt8(t,e),this}},mZ=t=>"0x"+t.toString("hex").replace(/(.)(.)/g,"$1$2 ").split(" ").filter(e=>e!=null&&e.length>0).join(",0x");function gZ(t){return t.buffer.slice(t.byteOffset,t.byteOffset+t.byteLength)}var Ba=class{constructor(t){this.uint8Array=t}position=0;bitsPending=0;writeBits(t,e){if(t==0)return this;e&=4294967295>>>32-t;let r;return this.bitsPending>0?this.bitsPending>t?(this.uint8Array[this.position-1]|=e<<this.bitsPending-t,r=t,this.bitsPending-=t):this.bitsPending==t?(this.uint8Array[this.position-1]|=e,r=t,this.bitsPending=0):(this.uint8Array[this.position-1]|=e>>t-this.bitsPending,r=this.bitsPending,this.bitsPending=0):(r=Math.min(8,t),this.bitsPending=8-r,this.uint8Array[this.position++]=e>>t-r<<this.bitsPending),t-=r,t>0&&this.writeBits(t,e),this}readBits(t){return this._readBits(t)}_readBits(t,e){if(typeof e>"u"&&(e=0),t==0)return e;let r,n;if(this.bitsPending>0){let s=this.uint8Array[this.position-1]&255>>8-this.bitsPending;n=Math.min(this.bitsPending,t),this.bitsPending-=n,r=s>>this.bitsPending}else n=Math.min(8,t),this.bitsPending=8-n,r=this.uint8Array[this.position++]>>this.bitsPending;return t-=n,e=e<<n|r,t>0?this._readBits(t,e):e}seekTo(t){this.position=t/8|0,this.bitsPending=t%8,this.bitsPending>0&&(this.bitsPending=8-this.bitsPending,this.position++)}},TT=3988292384,_T=2197175160;function d8(t){return typeof t!="string"}function l8(t){let e=new Array(256),r=0;for(let n=0;n<256;++n)r=n,r=r&1?t^r>>>1:r>>>1,r=r&1?t^r>>>1:r>>>1,r=r&1?t^r>>>1:r>>>1,r=r&1?t^r>>>1:r>>>1,r=r&1?t^r>>>1:r>>>1,r=r&1?t^r>>>1:r>>>1,r=r&1?t^r>>>1:r>>>1,r=r&1?t^r>>>1:r>>>1,e[n]=r;return new Int32Array(e)}function h8(t){let e=new Int32Array(4096),r=0,n=0,s=0;for(s=0;s<256;++s)e[s]=t[s];for(s=0;s<256;++s)for(n=t[s],r=256+s;r<4096;r+=256)n=e[r]=n>>>8^t[n&255];let i=[];for(s=1;s<16;++s)i[s-1]=e.subarray(s*256,s*256+256);return i}function p8(t,e,r){let n=e^-1,s=0,i=t.length,o=0,a=0;for(;s<i;)o=t.charCodeAt(s++),o<128?n=n>>>8^r[(n^o)&255]:o<2048?(n=n>>>8^r[(n^(192|o>>6&31))&255],n=n>>>8^r[(n^(128|o&63))&255]):o>=55296&&o<57344?(o=(o&1023)+64,a=t.charCodeAt(s++)&1023,n=n>>>8^r[(n^(240|o>>8&7))&255],n=n>>>8^r[(n^(128|o>>2&63))&255],n=n>>>8^r[(n^(128|a>>6&15|(o&3)<<4))&255],n=n>>>8^r[(n^(128|a&63))&255]):(n=n>>>8^r[(n^(224|o>>12&15))&255],n=n>>>8^r[(n^(128|o>>6&63))&255],n=n>>>8^r[(n^(128|o&63))&255]);return~n>>>0}function x8(t,e,r,n){let[s,i,o,a,c,f,l,p,x,v,S,I,L,ee,Pe]=n,ie=e^-1,ve=0,ze=t.length-15;for(;ve<ze;)ie=Pe[t[ve++]^ie&255]^ee[t[ve++]^ie>>>8&255]^L[t[ve++]^ie>>>16&255]^I[t[ve++]^ie>>>24]^S[t[ve++]]^v[t[ve++]]^x[t[ve++]]^p[t[ve++]]^l[t[ve++]]^f[t[ve++]]^c[t[ve++]]^a[t[ve++]]^o[t[ve++]]^i[t[ve++]]^s[t[ve++]]^r[t[ve++]];for(ze+=15;ve<ze;)ie=ie>>>8^r[(ie^t[ve++])&255];return~ie>>>0}var z1=l8(TT),BT=h8(z1),F1=l8(_T),kT=h8(F1);function RT(t,e=0){return d8(t)?x8(t,e,z1,BT):p8(t,e,z1)}function m8(t,e=0){return d8(t)?x8(t,e,F1,kT):p8(t,e,F1)}function NT(t,e){return t+e&255}function Tr(t,e){return t+e&65535}function Zc(t,e){return Number(BigInt(t)+BigInt(e)&0xffffffffn)}function PT(t){return t&16777215}function Fg(t,e){return t<e&&e-t>32768||t>e&&t-e<32768}function yZ(t,e){return t===e||Fg(t,e)}function ai(t,e){return t<e&&e-t>2147483648||t>e&&t-e<2147483648}function Id(t,e){return t===e||ai(t,e)}var jd=t=>Number.parseInt(t,10),bZ=class{queue=[];running=!1;push=t=>new Promise((e,r)=>{this.queue.push({promise:t,done:e,failed:r}),this.running||this.run()});async run(){let t=this.queue.shift();if(t){this.running=!0;try{let e=await t.promise();t.done(e)}catch(e){t.failed(e)}this.run()}else this.running=!1}cancel(){this.queue=[]}},Kg=(t,e)=>e?e[t]:void 0;async function y8(t="udp4",e){let r=g8(t);setImmediate(()=>r.bind({port:0,address:Kg(t,e)})),await new Promise(s=>{r.once("error",s),r.once("listening",s)});let n=r.address()?.port;return await new Promise(s=>r.close(()=>s())),n}async function wZ(t,e="udp4",r){return Promise.all([...Array(t)].map(()=>y8(e,r)))}async function OT(t,e,r="udp4",n){let s;for(let i=t;i<=e;i++){let o=g8(r);if(setImmediate(()=>o.bind({port:i,address:Kg(r,n)})),await new Promise(c=>{o.once("error",f=>c(f)),o.once("listening",()=>c())})){await new Promise(c=>o.close(()=>c()));continue}if(s=o.address()?.port,await new Promise(c=>o.close(()=>c())),t<=s&&s<=e)break}if(!s)throw new Error("port not found");return s}function Gh(t){return t==="IPv4"?4:t==="IPv6"?6:t}var SZ=class extends Error{message;payload;path;constructor(t){super(t.message)}toJSON(){return{message:this.message,payload:JSON.parse(JSON.stringify(this.payload)),path:this.path}}},tt=b8.default.debug,be=class{event={stack:[],promiseStack:[],eventId:0};ended=!1;onended;onerror=t=>{};execute=(...t)=>{if(!this.ended){for(let e of this.event.stack)e.execute(...t);(async()=>{for(let e of this.event.promiseStack)await e.execute(...t)})().catch(e=>{this.onerror(e)})}};complete=()=>{if(!this.ended){for(let t of this.event.stack)t.complete&&t.complete();this.allUnsubscribe(),this.ended=!0,this.onended&&(this.onended(),this.onended=void 0)}};error=t=>{if(!this.ended){for(let e of this.event.stack)e.error&&e.error(t);this.allUnsubscribe()}};allUnsubscribe=()=>{if(this.ended)throw new Error("event completed");this.event={stack:[],promiseStack:[],eventId:0}};subscribe=(t,e,r)=>{let n=this.event.eventId;this.event.stack.push({execute:t,id:n,complete:e,error:r}),this.event.eventId++;let s=()=>{this.event.stack=this.event.stack.filter(o=>o.id!==n&&o)};return{unSubscribe:s,disposer:o=>{o.push(s)}}};pipe(t){this.subscribe((...e)=>{t.execute(...e)})}queuingSubscribe=(t,e,r)=>{if(this.ended)throw new Error("event completed");let n=this.event.eventId;this.event.promiseStack.push({execute:t,id:n,complete:e,error:r}),this.event.eventId++;let s=()=>{this.event.stack=this.event.stack.filter(o=>o.id!==n&&o)};return{unSubscribe:s,disposer:o=>{o.push(s)}}};once=(t,e,r)=>{let n=this.subscribe((...s)=>{n.unSubscribe(),t(...s)},e,r)};watch=(t,e)=>new Promise((r,n)=>{let s=e&&setTimeout(()=>{n("Event watch timeout")},e),{unSubscribe:i}=this.subscribe((...o)=>{t(...o)&&(s&&clearTimeout(s),i(),r(o))})});asPromise=t=>new Promise((e,r)=>{let n=t&&setTimeout(()=>{r("Event asPromise timeout")},t);this.once((...s)=>{n&&clearTimeout(n),e(s)},()=>{n&&clearTimeout(n),e([])},s=>{n&&clearTimeout(n),r(s)})});get returnTrigger(){let{execute:t,error:e,complete:r}=this;return{execute:t,error:e,complete:r}}get returnListener(){let{subscribe:t,once:e,asPromise:r}=this;return{subscribe:t,once:e,asPromise:r}}get length(){return this.event.stack.length}},LT=class{_disposer=[];push(t){this._disposer.push(t)}dispose(){this._disposer.forEach(t=>t()),this._disposer=[]}},P6=tt("werift-ice:packages/ice/src/transport.ts"),K1=class w8{constructor(e,r={}){this.socketType=e,this.options=r,this.socket=UT(e),this.socket.on("message",(n,s)=>{Gh(s.family)===6&&([s.address]=s.address.split("%")),this.rinfo=s;try{this.onData(n,[s.address,s.port])}catch(i){P6("onData error",i)}})}type="udp";socket;rinfo;onData=()=>{};closed=!1;static async init(e,r={}){let n=new w8(e,r);return await n.init(),n}async init(){let e=Kg(this.socketType,this.options.interfaceAddresses);if(this.options.port)this.socket.bind({port:this.options.port,address:e});else if(this.options.portRange){let r=await OT(this.options.portRange[0],this.options.portRange[1],this.socketType,this.options.interfaceAddresses);this.socket.bind({port:r,address:e})}else this.socket.bind({address:e});await new Promise(r=>this.socket.once("listening",r))}send=async(e,r)=>{if(r&&!v8.isIP(r[0]))return new Promise((n,s)=>{this.socket.send(e,r[1],r[0],i=>{i?(P6("send error",r,e),s(i)):n()})});r=r??[this.rinfo?.address,this.rinfo?.port],this.socket.send(e,r[1],r[0])};get address(){return this.socket.address()}get host(){return this.socket.address().address}get port(){return this.socket.address().port}close=()=>new Promise(e=>{this.closed=!0,this.socket.once("close",e);try{this.socket.close()}catch{e()}})},MT=class S8{constructor(e){this.addr=e,this.connect()}type="tcp";connecting;client;onData=()=>{};closed=!1;connect(){this.closed||(this.client&&this.client.destroy(),this.connecting=new Promise((e,r)=>{try{this.client=DT({port:this.addr[1],host:this.addr[0]},e)}catch(n){r(n)}}),this.client.on("data",e=>{let r=[this.client.remoteAddress,this.client.remotePort];this.onData(e,r)}),this.client.on("end",()=>{this.connect()}),this.client.on("error",e=>{console.log("error",e)}))}async init(){await this.connecting}static async init(e){let r=new S8(e);return await r.init(),r}get address(){return{}}send=async(e,r)=>{await this.connecting,this.client.write(e,n=>{n&&console.log("err",n)})};close=async()=>{this.closed=!0,this.client.destroy()}},di={rsa_1:1,ecdsa_3:3},Xh={sha256_4:4},$1={TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256_49195:49195,TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256_49199:49199},VT=Object.values($1),fo={x25519_29:29,secp256r1_23:23},E8=Object.values(fo),A8={named_curve_3:3},O6={rsa_pkcs1_sha256:1025,ecdsa_secp256r1_sha256:1027},zT=[1,64],C8=[{hash:Xh.sha256_4,signature:di.rsa_1},{hash:Xh.sha256_4,signature:di.ecdsa_3}],$T=()=>{let t=mh.utils.randomPrivateKey(),e=mh.getPublicKey(t,!1),r=Buffer.from(t),n=Buffer.from(e);return{privateKey:r,publicKey:n}},WT=({publicKey:t,privateKey:e})=>{let r=mh.getSharedSecret(e,t);return Buffer.from(r).subarray(1)};function _8(t,e,r){switch(r){case fo.secp256r1_23:return WT({publicKey:t,privateKey:e});case fo.x25519_29:return Buffer.from(T8.default.scalarMult(e,t));default:throw new Error}}function L6(t,e,r){let n=KT(t,e);return n.update(r),n.digest()}function Yd(t,e,r,n="sha256"){let s=r,i=[],o=e;do{o=L6(n,t,o);let a=L6(n,t,Buffer.concat([o,e]));i.push(a),r-=a.length}while(r>0);return Buffer.concat(i,s)}function B8(t,e,r){let n=Buffer.concat([Buffer.from("master secret"),e,r]);return Yd(t,n,48)}function k8(t,e){let r=R8("sha256",e);return Yd(t,Buffer.concat([Buffer.from("extended master secret"),r]),48)}function GT(t,e,r,n,s,i){let o=i?n:s,a=i?s:n,c=Buffer.concat([Buffer.from(t),o,a]);return Yd(r,c,e)}function R8(t,e){return FT(t).update(e).digest()}function N8(t,e,r,n=12){let s=R8("sha256",e);return Yd(t,Buffer.concat([Buffer.from(r),s]),n)}function XT(t,e){return N8(t,e,"client finished")}function YT(t,e){return N8(t,e,"server finished")}function ZT(t,e,r,n,s,i,o="sha256"){let a=n*2+s*2,c=t,f=Buffer.concat([r,e]),l=Yd(c,Buffer.concat([Buffer.from("key expansion"),f]),a,o),p=(0,I8.createDecode)(l),x=p.readBuffer(n),v=p.readBuffer(n),S=p.readBuffer(s),I=p.readBuffer(s),L=Buffer.alloc(i,0),ee=Buffer.alloc(i,0);return S.copy(L,0),I.copy(ee,0),{clientWriteKey:x,serverWriteKey:v,clientNonce:L,serverNonce:ee}}var fi={CLIENT:1,SERVER:2},JT=class{id=0;name;hashAlgorithm;verifyDataLength=12;blockAlgorithm;kx;init(...t){throw new Error("not implemented")}encrypt(...t){throw new Error("not implemented")}decrypt(...t){throw new Error("not implemented")}toString(){return this.name}},W1=qT;Jt.set(W1);var Yh=class{constructor(t,e,r,n){this.sessionType=t,this.certPem=e,this.keyPem=r,e&&r&&n&&this.parseX509(e,r,n)}localRandom;remoteRandom;cipherSuite;remoteCertificate;remoteKeyPair;localKeyPair;masterSecret;cipher;namedCurve;signatureHashAlgorithm;localCert;localPrivateKey;static createSelfSignedCertificateWithKey=async(t,e)=>{let r=(()=>{switch(t.signature){case di.rsa_1:return"RSASSA-PKCS1-v1_5";case di.ecdsa_3:return"ECDSA"}})(),n=(()=>{if(t.hash===Xh.sha256_4)return"SHA-256"})(),s=(()=>{switch(e){case fo.secp256r1_23:return"P-256";case fo.x25519_29:return r==="ECDSA"?"P-256":"X25519";default:{if(r==="ECDSA")return"P-256";if(r==="RSASSA-PKCS1-v1_5")return"X25519"}}})(),i=(()=>{switch(r){case"ECDSA":return{name:r,hash:n,namedCurve:s};case"RSASSA-PKCS1-v1_5":return{name:r,hash:n,publicExponent:new Uint8Array([1,0,1]),modulusLength:2048}}})(),o=await W1.subtle.generateKey(i,!0,["sign","verify"]),c=(await F0.createSelfSigned({serialNumber:jT(8).toString("hex"),name:"C=AU, ST=Some-State, O=Internet Widgits Pty Ltd",notBefore:new Date,notAfter:new Date(Date.now()+10*365*24*60*60*1e3),signingAlgorithm:i,keys:o})).toString("pem"),f=hr.encode(await W1.subtle.exportKey("pkcs8",o.privateKey),"private key");return{certPem:c,keyPem:f,signatureHash:t}};encryptPacket(t){let e=t.recordLayerHeader,r=e.protocolVersion.major<<8|e.protocolVersion.minor,n=this.cipher.encrypt(this.sessionType,t.fragment,{type:e.contentType,version:r,epoch:e.epoch,sequenceNumber:e.sequenceNumber});return t.fragment=n,t.recordLayerHeader.contentLen=n.length,t}decryptPacket(t){let e=t.recordLayerHeader,r=e.protocolVersion.major<<8|e.protocolVersion.minor;return this.cipher.decrypt(this.sessionType,t.fragment,{type:e.contentType,version:r,epoch:e.epoch,sequenceNumber:e.sequenceNumber})}verifyData(t){return this.sessionType===fi.CLIENT?XT(this.masterSecret,t):YT(this.masterSecret,t)}signatureData(t,e){let r=HT(e).update(t),n=this.localPrivateKey.toPEM().toString();return r.sign(n)}generateKeySignature(t){let e=this.sessionType===fi.CLIENT?this.localRandom:this.remoteRandom,r=this.sessionType===fi.SERVER?this.localRandom:this.remoteRandom,n=this.valueKeySignature(e.serialize(),r.serialize(),this.localKeyPair.publicKey,this.namedCurve);return this.localPrivateKey.sign(n,t)}parseX509(t,e,r){let n=fp.Certificate.fromPEM(Buffer.from(t)),s=fp.PrivateKey.fromPEM(Buffer.from(e));this.localCert=n.raw,this.localPrivateKey=s,this.signatureHashAlgorithm=r}valueKeySignature(t,e,r,n){let s=Buffer.from((0,Jc.encode)({type:A8.named_curve_3,curve:n,len:r.length},{type:Jc.types.uint8,curve:Jc.types.uint16be,len:Jc.types.uint8}).slice());return Buffer.concat([t,e,s,r])}},Zh=class{srtpProfile;static findMatchingSRTPProfile(t,e){for(let r of e)if(t.includes(r))return r}},$g=t=>"0x"+t.toString("hex").replace(/(.)(.)/g,"$1$2 ").split(" ").filter(e=>e!=null&&e.length>0).join(",0x"),P8=t=>Object.entries({...t}).reduce((e,[r,n])=>((typeof n=="number"||typeof n=="string")&&(e[r]=n),Buffer.isBuffer(n)&&(e[r]=$g(n)),e),{}),yn=class no{constructor(e,r,n,s,i,o){this.msg_type=e,this.length=r,this.message_seq=n,this.fragment_offset=s,this.fragment_length=i,this.fragment=o}static spec={msg_type:Mn.types.uint8,length:Mn.types.uint24be,message_seq:Mn.types.uint16be,fragment_offset:Mn.types.uint24be,fragment_length:Mn.types.uint24be,fragment:Mn.types.buffer(e=>e.current.fragment_length)};get summary(){return P8(this)}static createEmpty(){return new no(void 0,void 0,void 0,void 0,void 0,void 0)}static deSerialize(e){return new no(...Object.values((0,Mn.decode)(e,no.spec)))}serialize(){let e=(0,Mn.encode)(this,no.spec).slice();return Buffer.from(e)}chunk(e){let r=0,n=this.fragment.length;if(n===0)return[new no(this.msg_type,n,this.message_seq,r,0,this.fragment)];let s=[];for(e||(e=1240);r<n;){let i=Math.min(e,n-r),o=Buffer.from(this.fragment.slice(r,r+i));if(o.length<=0)throw new Error("Zero or less bytes processed while fragmenting handshake message.");s.push(new no(this.msg_type,n,this.message_seq,r,o.length,o)),r+=o.length}return s}static assemble(e){if(!e?.length)throw new Error("cannot reassemble handshake from empty array");e=e.sort((n,s)=>n.fragment_offset-s.fragment_offset);let r=Buffer.alloc(e[0].length);for(let n of e)n.fragment.copy(r,n.fragment_offset);return new no(e[0].msg_type,e[0].length,e[0].message_seq,0,r.length,r)}static findAllFragments(e,r){let n=e.find(s=>s.msg_type===r);return n?e?.length?e.filter(s=>s.msg_type===n.msg_type&&s.message_seq===n.message_seq&&s.length===n.length):[]:[]}},{uint16be:Jh,uint24be:QT,buffer:L8,array:e_,uint8:zd,string:t_}=O8.types,r_={type:Jh,data:L8(Jh)},G1=e_(r_,Jh,"bytes"),n_=L8(QT),s_=zd,i_=t_(Jh),o_={hash:zd,signature:zd},Wg={major:zd,minor:zd},Na=class Td{constructor(e=Math.floor(Date.now()/1e3),r=a_(28)){this.gmt_unix_time=e,this.random_bytes=r}static spec={gmt_unix_time:Ra.types.uint32be,random_bytes:Ra.types.buffer(28)};static deSerialize(e){return new Td(...Object.values((0,Ra.decode)(e,Td.spec)))}static from(e){return new Td(...Object.values(e))}serialize(){let e=(0,Ra.encode)(this,Td.spec).slice();return Buffer.from(e)}},U8=class _d{constructor(e,r,n,s,i,o,a){this.clientVersion=e,this.random=r,this.sessionId=n,this.cookie=s,this.cipherSuites=i,this.compressionMethods=o,this.extensions=a}msgType=1;messageSeq=0;static spec={clientVersion:{major:gr.types.uint8,minor:gr.types.uint8},random:Na.spec,sessionId:gr.types.buffer(gr.types.uint8),cookie:gr.types.buffer(gr.types.uint8),cipherSuites:gr.types.array(gr.types.uint16be,gr.types.uint16be,"bytes"),compressionMethods:gr.types.array(gr.types.uint8,gr.types.uint8,"bytes"),extensions:G1};static createEmpty(){return new _d(void 0,void 0,void 0,void 0,void 0,void 0,void 0)}static deSerialize(e){return new _d(...Object.values((0,gr.decode)(e,_d.spec)))}serialize(){let e=(0,gr.encode)(this,_d.spec).slice();return Buffer.from(e)}toFragment(){let e=this.serialize();return new yn(this.msgType,e.length,this.messageSeq,0,e.length,e)}},u_=class Bd{constructor(e,r,n,s,i){this.epoch=e,this.sequenceNumber=r,this.contentType=n,this.protocolVersion=s,this.contentLen=i}static spec={epoch:ci.types.uint16be,sequenceNumber:ci.types.uint48be,contentType:ci.types.uint8,protocolVersion:Wg,contentLen:ci.types.uint16be};static createEmpty(){return new Bd(void 0,void 0,void 0,void 0,void 0)}static deSerialize(e){return new Bd(...Object.values((0,ci.decode)(e,Bd.spec)))}serialize(){let e=(0,ci.encode)(this,Bd.spec).slice();return Buffer.from(e)}},D8=class X1{constructor(e,r){this.recordLayerHeader=e,this.fragment=r}get summary(){return{header:this.recordLayerHeader,fragment:$g(this.fragment)}}static createEmpty(){return new X1(void 0,void 0)}static deSerialize(e){if(e.length<13)throw new Error("Invalid DTLS record: buffer is too short");let r=e.readUInt8(0),n=e.readUInt8(1),s=e.readUInt8(2),i=e.readUInt16BE(3),o=e.slice(5,11).readUIntBE(0,6),a=e.readUInt16BE(11);if(e.length<13+a)throw new Error("Invalid DTLS record: fragment length exceeds buffer");let c=e.slice(13,13+a);return new X1({contentType:r,protocolVersion:{major:n,minor:s},epoch:i,sequenceNumber:o,contentLen:a},c)}serialize(){let e=this.fragment.length,r=13+e,n=Buffer.alloc(r);return n.writeUInt8(this.recordLayerHeader.contentType,0),n.writeUInt8(this.recordLayerHeader.protocolVersion.major,1),n.writeUInt8(this.recordLayerHeader.protocolVersion.minor,2),n.writeUInt16BE(this.recordLayerHeader.epoch,3),n.writeUIntBE(this.recordLayerHeader.sequenceNumber,5,6),n.writeUInt16BE(e,11),this.fragment.copy(n,13),n}computeMACHeader(){return new u_(this.recordLayerHeader.epoch,this.recordLayerHeader.sequenceNumber,this.recordLayerHeader.contentType,this.recordLayerHeader.protocolVersion,this.recordLayerHeader.contentLen).serialize()}},M8=t=>e=>(t.lastFlight=e,e.flatMap(r=>(r.messageSeq=t.sequenceNumber++,r.toFragment().chunk()))),Zd=t=>(e,r)=>e.map(n=>new D8({contentType:n.type,protocolVersion:t.version,epoch:t.epoch,sequenceNumber:r,contentLen:n.fragment.length},n.fragment)),Y1=(t=>(t[t.CloseNotify=0]="CloseNotify",t[t.UnexpectedMessage=10]="UnexpectedMessage",t[t.BadRecordMac=20]="BadRecordMac",t[t.DecryptionFailed=21]="DecryptionFailed",t[t.RecordOverflow=22]="RecordOverflow",t[t.DecompressionFailure=30]="DecompressionFailure",t[t.HandshakeFailure=40]="HandshakeFailure",t[t.NoCertificate=41]="NoCertificate",t[t.BadCertificate=42]="BadCertificate",t[t.UnsupportedCertificate=43]="UnsupportedCertificate",t[t.CertificateRevoked=44]="CertificateRevoked",t[t.CertificateExpired=45]="CertificateExpired",t[t.CertificateUnknown=46]="CertificateUnknown",t[t.IllegalParameter=47]="IllegalParameter",t[t.UnknownCa=48]="UnknownCa",t[t.AccessDenied=49]="AccessDenied",t[t.DecodeError=50]="DecodeError",t[t.DecryptError=51]="DecryptError",t[t.ExportRestriction=60]="ExportRestriction",t[t.ProtocolVersion=70]="ProtocolVersion",t[t.InsufficientSecurity=71]="InsufficientSecurity",t[t.InternalError=80]="InternalError",t[t.UserCanceled=90]="UserCanceled",t[t.NoRenegotiation=100]="NoRenegotiation",t[t.UnsupportedExtension=110]="UnsupportedExtension",t))(Y1||{}),f_=tt("werift-dtls : packages/dtls/src/flight/flight.ts : warn"),I1=tt("werift-dtls : packages/dtls/src/flight/flight.ts : err"),Jd=class Z1{constructor(e,r,n,s){this.transport=e,this.dtls=r,this.flight=n,this.nextFlight=s}state="PREPARING";static RetransmitCount=10;createPacket(e){let r=M8(this.dtls)(e);return this.dtls.bufferHandshakeCache(r,!0,this.flight),Zd(this.dtls)(r.map(s=>({type:22,fragment:s.serialize()})),++this.dtls.recordSequenceNumber)}async transmit(e){let r=0;for(;r<=Z1.RetransmitCount;r++){if(this.setState("SENDING"),this.send(e).catch(n=>{I1("fail to send",I1)}),this.setState("WAITING"),this.nextFlight===void 0){this.setState("FINISHED");break}if(await c_(1e3*((r+1)/2)),this.dtls.flight>=this.nextFlight){this.setState("FINISHED");break}else f_(this.dtls.sessionId,"retransmit",r,this.dtls.flight)}if(r>Z1.RetransmitCount)throw I1(this.dtls.sessionId,"retransmit failed",r),new Error(`over retransmitCount : ${this.flight} ${this.nextFlight}`)}send=e=>Promise.all(e.map(r=>this.transport.send(r)));setState(e){this.state=e}},d_=class extends Jd{constructor(t,e,r){super(t,e,1,3),this.cipher=r}async exec(t){if(this.dtls.flight===1)throw new Error;this.dtls.flight=1;let e=new U8({major:254,minor:253},new Na,Buffer.from([]),Buffer.from([]),VT,[0],t);this.dtls.version=e.clientVersion,this.cipher.localRandom=Na.from(e.random);let r=this.createPacket([e]),n=Buffer.concat(r.map(s=>s.serialize()));await this.transmit([n])}},l_=tt("werift-dtls : packages/dtls/src/flight/client/flight3.ts : log"),h_=class extends Jd{constructor(t,e){super(t,e,3,5)}async exec(t){if(this.dtls.flight===3)throw new Error;this.dtls.flight=3,this.dtls.handshakeCache=[];let[e]=this.dtls.lastFlight;l_("dtls version",e.clientVersion),e.cookie=t.cookie,this.dtls.cookie=t.cookie;let r=this.createPacket([e]),n=Buffer.concat(r.map(s=>s.serialize()));await this.transmit([n])}},dp={NULL:0,ECDHE:1},Qd={NULL:0,RSA:1,ECDSA:2,PSK:3},el={NULL:0,RSA:1,ECDHE_RSA:2,ECDHE_ECDSA:3,PSK:4,ECDHE_PSK:5},tl=class{id=0;name;signType;keyType;toString(){return this.name}};function p_(){let t=new tl;return t.id=el.RSA,t.name="RSA",t.keyType=Qd.RSA,t}function x_(){let t=new tl;return t.id=el.ECDHE_RSA,t.name="ECDHE_RSA",t.signType=dp.ECDHE,t.keyType=Qd.RSA,t}function m_(){let t=new tl;return t.id=el.ECDHE_ECDSA,t.name="ECDHE_ECDSA",t.signType=dp.ECDHE,t.keyType=Qd.ECDSA,t}function g_(){let t=new tl;return t.id=el.PSK,t.name="PSK",t.signType=dp.NULL,t.keyType=Qd.PSK,t}function y_(){let t=new tl;return t.id=el.ECDHE_PSK,t.name="ECDHE_PSK",t.signType=dp.ECDHE,t.keyType=Qd.PSK,t}var w_=tt("werift-dtls : packages/dtls/src/cipher/suites/aead.ts : err"),S_=class extends JT{keyLength=0;nonceLength=0;ivLength=0;authTagLength=0;nonceImplicitLength=0;nonceExplicitLength=0;clientWriteKey;serverWriteKey;clientNonce;serverNonce;constructor(){super()}get summary(){return P8(this)}init(t,e,r){let n=ZT(t,r,e,this.keyLength,this.ivLength,this.nonceLength,this.hashAlgorithm);this.clientWriteKey=n.clientWriteKey,this.serverWriteKey=n.serverWriteKey,this.clientNonce=n.clientNonce,this.serverNonce=n.serverNonce}encrypt(t,e,r){let n=t===fi.CLIENT,s=n?this.clientNonce:this.serverNonce,i=n?this.clientWriteKey:this.serverWriteKey;if(!s||!i)throw new Error;s.writeUInt16BE(r.epoch,this.nonceImplicitLength),s.writeUIntBE(r.sequenceNumber,this.nonceImplicitLength+2,6);let o=s.slice(this.nonceImplicitLength),a=this.encodeAdditionalBuffer(r,e.length),c=b_(this.blockAlgorithm,i,s,{authTagLength:this.authTagLength});c.setAAD(a,{plaintextLength:e.length});let f=c.update(e),l=c.final(),p=c.getAuthTag();return Buffer.concat([o,f,l,p])}encodeAdditionalBuffer(t,e){let r=Buffer.alloc(13);return r.writeUInt16BE(t.epoch,0),r.writeUintBE(t.sequenceNumber,2,6),r.writeUInt8(t.type,8),r.writeUInt16BE(t.version,9),r.writeUInt16BE(e,11),r}decrypt(t,e,r){let n=t===fi.CLIENT,s=n?this.serverNonce:this.clientNonce,i=n?this.serverWriteKey:this.clientWriteKey;if(!s||!i)throw new Error;e.subarray(0,this.nonceExplicitLength).copy(s,this.nonceImplicitLength);let a=e.subarray(this.nonceExplicitLength,e.length-this.authTagLength),c=e.subarray(e.length-this.authTagLength),f=this.encodeAdditionalBuffer(r,a.length),l=v_(this.blockAlgorithm,i,s,{authTagLength:this.authTagLength});l.setAuthTag(c),l.setAAD(f,{plaintextLength:a.length});let p=l.update(a);try{let x=l.final();return x.length>0?Buffer.concat([p,x]):p}catch(x){throw w_("decrypt failed",x,t,$g(e),r,this.summary),x}}},Qt={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},yd={K_LEN:16,N_MIN:12,N_MAX:12,P_MAX:2**36-31,A_MAX:2**53-1,C_MAX:2**36-15},bd={K_LEN:32,N_MIN:12,N_MAX:12,P_MAX:2**36-31,A_MAX:2**53-1,C_MAX:2**36-15},U6=p_(),D6=x_(),M6=m_(),H6=g_(),j6=y_();function H8(t){switch(t){case Qt.TLS_RSA_WITH_AES_128_GCM_SHA256:return gs(Qt.TLS_RSA_WITH_AES_128_GCM_SHA256,"TLS_RSA_WITH_AES_128_GCM_SHA256","aes-128-gcm",U6,yd);case Qt.TLS_RSA_WITH_AES_256_GCM_SHA384:return gs(Qt.TLS_RSA_WITH_AES_256_GCM_SHA384,"TLS_RSA_WITH_AES_256_GCM_SHA384","aes-256-gcm",U6,bd,"sha384");case Qt.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256:return gs(Qt.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,"TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256","aes-128-gcm",D6,yd);case Qt.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384:return gs(Qt.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,"TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384","aes-256-gcm",D6,bd,"sha384");case Qt.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256:return gs(Qt.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,"TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256","aes-128-gcm",M6,yd);case Qt.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384:return gs(Qt.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,"TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384","aes-256-gcm",M6,bd,"sha384");case Qt.TLS_PSK_WITH_AES_128_GCM_SHA256:return gs(Qt.TLS_PSK_WITH_AES_128_GCM_SHA256,"TLS_PSK_WITH_AES_128_GCM_SHA256","aes-128-gcm",H6,yd,"sha256");case Qt.TLS_PSK_WITH_AES_256_GCM_SHA384:return gs(Qt.TLS_PSK_WITH_AES_256_GCM_SHA384,"TLS_PSK_WITH_AES_256_GCM_SHA384","aes-256-gcm",H6,bd,"sha384");case Qt.TLS_ECDHE_PSK_WITH_AES_128_GCM_SHA256:return gs(Qt.TLS_ECDHE_PSK_WITH_AES_128_GCM_SHA256,"TLS_ECDHE_PSK_WITH_AES_128_GCM_SHA256","aes-128-gcm",j6,yd,"sha256");case Qt.TLS_ECDHE_PSK_WITH_AES_256_GCM_SHA384:return gs(Qt.TLS_ECDHE_PSK_WITH_AES_256_GCM_SHA384,"TLS_ECDHE_PSK_WITH_AES_256_GCM_SHA384","aes-256-gcm",j6,bd,"sha384");default:break}return null}function gs(t,e,r,n,s,i="sha256"){let o=new S_;return o.id=t,o.name=e,o.blockAlgorithm=r,o.kx=n,o.hashAlgorithm=i,o.keyLength=s.K_LEN,o.nonceLength=s.N_MAX,o.nonceImplicitLength=4,o.nonceExplicitLength=8,o.ivLength=o.nonceImplicitLength,o.authTagLength=16,o}function q8(t){switch(t){case fo.secp256r1_23:{let{privateKey:e,publicKey:r}=$T();return{curve:t,privateKey:e,publicKey:r}}case fo.x25519_29:{let e=j8.default.box.keyPair();return{curve:t,privateKey:Buffer.from(e.secretKey.buffer),publicKey:Buffer.from(e.publicKey.buffer)}}default:throw new Error}}var lp=class{static type=23},hp=class Wc{static type=65281;static spec={type:Pa.types.uint16be,data:Pa.types.uint8};type=Wc.type;data=0;constructor(e={}){Object.assign(this,e)}static createEmpty(){return new Wc}static deSerialize(e){return new Wc((0,Pa.decode)(e,Wc.spec))}serialize(){let e=(0,Pa.encode)(this,Wc.spec).slice();return Buffer.from(e)}get extension(){return{type:this.type,data:this.serialize().slice(2)}}},Qc=class so{static type=14;static spec={type:co.types.uint16be,data:co.types.buffer(co.types.uint16be)};type=so.type;data=Buffer.from([]);profiles=[];mki=Buffer.from([0]);constructor(e={}){Object.assign(this,e)}static create(e,r){return new so({profiles:e,mki:r})}static deSerialize(e){let r=new so((0,co.decode)(e,so.spec)),n=r.data.readUInt16BE(),s=new Array(n/2);for(let i=0;i<s.length;i++)s[i]=r.data.readUInt16BE(i*2+2);return r.profiles=s,r.mki=r.data.slice(n+2),r}serialize(){let e=Buffer.alloc(2);e.writeUInt16BE(this.profiles.length*2);let r=Buffer.concat([e,...this.profiles.map(s=>{let i=Buffer.alloc(2);return i.writeUInt16BE(s),i}),this.mki]);this.data=r;let n=(0,co.encode)(this,so.spec).slice();return Buffer.from(n)}static fromData(e){let r=Buffer.alloc(4);return r.writeUInt16BE(so.type),r.writeUInt16BE(e.length,2),so.deSerialize(Buffer.concat([r,e]))}get extension(){return{type:this.type,data:this.serialize().slice(4)}}},Qh=class kd{constructor(e){this.certificateList=e}msgType=11;messageSeq;static spec={certificateList:Oa.types.array(n_,Oa.types.uint24be,"bytes")};static createEmpty(){return new kd(void 0)}static deSerialize(e){return new kd(...Object.values((0,Oa.decode)(e,kd.spec)))}serialize(){let e=(0,Oa.encode)(this,kd.spec).slice();return Buffer.from(e)}toFragment(){let e=this.serialize();return new yn(this.msgType,e.length,this.messageSeq,0,e.length,e)}},V8=class Rd{constructor(e=1){this.type=e}static spec={type:su.types.uint8};static createEmpty(){return new Rd}static deSerialize(e){return new Rd(...Object.values((0,su.decode)(e,Rd.spec)))}serialize(){let e=(0,su.encode)(this,Rd.spec).slice();return Buffer.from(e)}},z8=class Nd{constructor(e,r){this.algorithm=e,this.signature=r}msgType=15;messageSeq;static spec={algorithm:uo.types.uint16be,signature:uo.types.buffer(uo.types.uint16be)};static createEmpty(){return new Nd(void 0,void 0)}static deSerialize(e){let r=(0,uo.decode)(e,Nd.spec);return new Nd(...Object.values(r))}serialize(){let e=(0,uo.encode)(this,Nd.spec).slice();return Buffer.from(e)}toFragment(){let e=this.serialize();return new yn(this.msgType,e.length,this.messageSeq,0,e.length,e)}},F8=class Pd{constructor(e){this.publicKey=e}msgType=16;messageSeq;static spec={publicKey:La.types.buffer(La.types.uint8)};static createEmpty(){return new Pd(void 0)}static deSerialize(e){let r=(0,La.decode)(e,Pd.spec);return new Pd(...Object.values(r))}serialize(){let e=(0,La.encode)(this,Pd.spec).slice();return Buffer.from(e)}toFragment(){let e=this.serialize();return new yn(this.msgType,e.length,this.messageSeq,0,e.length,e)}},J1=class Q1{constructor(e){this.verifyData=e}msgType=20;messageSeq;static createEmpty(){return new Q1(void 0)}static deSerialize(e){return new Q1(e)}serialize(){return this.verifyData}toFragment(){let e=this.serialize();return new yn(this.msgType,e.length,this.messageSeq,0,e.length,e)}},K8=class Od{constructor(e,r,n){this.certificateTypes=e,this.signatures=r,this.authorities=n}msgType=13;messageSeq;static spec={certificateTypes:Hn.types.array(s_,Hn.types.uint8,"bytes"),signatures:Hn.types.array(o_,Hn.types.uint16be,"bytes"),authorities:Hn.types.array(i_,Hn.types.uint16be,"bytes")};static createEmpty(){return new Od(void 0,void 0,void 0)}static deSerialize(e){return new Od(...Object.values((0,Hn.decode)(e,Od.spec)))}serialize(){let e=(0,Hn.encode)(this,Od.spec).slice();return Buffer.from(e)}toFragment(){let e=this.serialize();return new yn(this.msgType,e.length,this.messageSeq,0,e.length,e)}},$8=class io{constructor(e,r,n,s,i,o){this.serverVersion=e,this.random=r,this.sessionId=n,this.cipherSuite=s,this.compressionMethod=i,this.extensions=o}msgType=2;messageSeq;static spec={serverVersion:Wg,random:Na.spec,sessionId:qn.types.buffer(qn.types.uint8),cipherSuite:qn.types.uint16be,compressionMethod:qn.types.uint8};static createEmpty(){return new io(void 0,void 0,void 0,void 0,void 0,void 0)}static deSerialize(e){let r=(0,qn.decode)(e,io.spec),n=new io(...Object.values(r));return n.serialize().length<e.length?new io(...Object.values((0,qn.decode)(e,{...io.spec,extensions:G1}))):n}serialize(){let e=this.extensions===void 0?(0,qn.encode)(this,io.spec).slice():(0,qn.encode)(this,{...io.spec,extensions:G1}).slice();return Buffer.from(e)}toFragment(){let e=this.serialize();return new yn(this.msgType,e.length,this.messageSeq,0,e.length,e)}},W8=class Ld{msgType=14;messageSeq;static spec={};static createEmpty(){return new Ld}static deSerialize(e){return new Ld(...Object.values((0,pp.decode)(e,Ld.spec)))}serialize(){let e=(0,pp.encode)(this,Ld.spec).slice();return Buffer.from(e)}toFragment(){let e=this.serialize();return new yn(this.msgType,e.length,this.messageSeq,0,e.length,e)}};function E_(t,e){return Buffer.from((0,G8.encode)(t,e).slice())}var X8=class Ud{constructor(e,r,n,s,i,o,a,c){this.ellipticCurveType=e,this.namedCurve=r,this.publicKeyLength=n,this.publicKey=s,this.hashAlgorithm=i,this.signatureAlgorithm=o,this.signatureLength=a,this.signature=c}msgType=12;messageSeq;static spec={ellipticCurveType:Dn.types.uint8,namedCurve:Dn.types.uint16be,publicKeyLength:Dn.types.uint8,publicKey:Dn.types.buffer(e=>e.current.publicKeyLength),hashAlgorithm:Dn.types.uint8,signatureAlgorithm:Dn.types.uint8,signatureLength:Dn.types.uint16be,signature:Dn.types.buffer(e=>e.current.signatureLength)};static createEmpty(){return new Ud(void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0)}static deSerialize(e){let r=(0,Dn.decode)(e,Ud.spec);return new Ud(...Object.values(r))}serialize(){return E_(this,Ud.spec)}toFragment(){let e=this.serialize();return new yn(this.msgType,e.length,this.messageSeq,0,e.length,e)}},rl=1,iu=7,RZ=[rl,iu],A_=t=>{switch(t){case rl:case iu:return 16}},C_=t=>{switch(t){case rl:return 14;case iu:return 12}},I_=tt("werift-rtp : packages/rtp/src/codec/av1.ts"),q6=class Z8{zBit_RtpStartsWithFragment;yBit_RtpEndsWithFragment;w_RtpNumObus;nBit_RtpStartsNewCodedVideoSequence;obu_or_fragment=[];static deSerialize=e=>{let r=new Z8,n=0;if(r.zBit_RtpStartsWithFragment=ue(e[n],0),r.yBit_RtpEndsWithFragment=ue(e[n],1),r.w_RtpNumObus=ue(e[n],2,2),r.nBit_RtpStartsNewCodedVideoSequence=ue(e[n],4),n++,r.nBit_RtpStartsNewCodedVideoSequence&&r.zBit_RtpStartsWithFragment)throw new Error;[...Array(r.w_RtpNumObus-1).keys()].forEach(i=>{let[o,a]=__(e.subarray(n)),c=n+a,f=c+o,l=!1;r.zBit_RtpStartsWithFragment&&i===0&&(l=!0),r.obu_or_fragment.push({data:e.subarray(c,f),isFragment:l}),n+=a+o});let s=!1;return(r.yBit_RtpEndsWithFragment||r.w_RtpNumObus===1&&r.zBit_RtpStartsWithFragment)&&(s=!0),r.obu_or_fragment.push({data:e.subarray(n),isFragment:s}),r};static isDetectedFinalPacketInSequence(e){return e.marker}get isKeyframe(){return this.nBit_RtpStartsNewCodedVideoSequence===1}static getFrame(e){let r=[],n=e.flatMap(a=>a.obu_or_fragment).reduce((a,c,f)=>(a[f]=c,a),{}),s=Object.keys(n).length;for(let a of Object.keys(n).map(Number)){let c=n[a];if(!c)continue;let{data:f,isFragment:l}=c;if(l){let p=[];for(let x=a;x<s;x++){let v=n[x];if(v.isFragment)p.push(v.data),delete n[x];else break}p.length<=1&&(I_("fragment lost, maybe packet lost"),p=[]),r.push(Buffer.concat(p))}else r.push(f)}let i=r.map(a=>T_.deSerialize(a)),o=i.pop();return Buffer.concat([...i.map(a=>(a.obu_has_size_field=1,a.serialize())),o.serialize()])}},T_=class J8{obu_forbidden_bit;obu_type;obu_extension_flag;obu_has_size_field;obu_reserved_1bit;payload;static deSerialize(e){let r=new J8,n=0;return r.obu_forbidden_bit=ue(e[n],0),r.obu_type=Q8[ue(e[n],1,4)],r.obu_extension_flag=ue(e[n],5),r.obu_has_size_field=ue(e[n],6),r.obu_reserved_1bit=ue(e[n],7),n++,r.payload=e.subarray(n),r}serialize(){let e=new zg(8).set(this.obu_forbidden_bit).set(B_[this.obu_type],4).set(this.obu_extension_flag).set(this.obu_has_size_field).set(this.obu_reserved_1bit).buffer,r=Buffer.alloc(0);return this.obu_has_size_field&&(r=Y8.LEB128.encode(this.payload.length)),Buffer.concat([e,r,this.payload])}};function __(t){let e=0,r=0;for(let n=0;n<8;n++){let s=t.readUInt8(n);if(e|=(s&127)<<n*7,r++,!(s&128))break}return[e,r]}var Q8={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"},B_=Object.entries(Q8).reduce((t,[e,r])=>(t[r]=Number(e),t),{}),k_=class e4{f;nri;nalUnitType;s;e;r;nalUnitPayloadType;payload;fragment;static deSerialize(e,r){let n=new e4,s=0,i=e[s];if(n.f=ue(i,0),n.nri=ue(i,1,2),n.nalUnitType=ue(i,3,5),s++,n.s=ue(e[s],0),n.e=ue(e[s],1),n.r=ue(e[s],2),n.nalUnitPayloadType=ue(e[s],3,5),s++,0<n.nalUnitType&&n.nalUnitType<Ca.stap_a)n.payload=this.packaging(e);else if(n.nalUnitType===Ca.stap_a){let o=N_,a=Buffer.alloc(0);for(;o<e.length;){let c=e.readUInt16BE(o);o+=P_,a=Buffer.concat([a,this.packaging(e.subarray(o,o+c))]),o+=c}n.payload=a}else if(n.nalUnitType===Ca.fu_a){r||(r=Buffer.alloc(0));let o=e.subarray(s);if(n.fragment=Buffer.concat([r,o]),n.e){let a=new Ba(Buffer.alloc(1)).writeBits(1,0).writeBits(2,n.nri).writeBits(5,n.nalUnitPayloadType),c=Buffer.concat([a.uint8Array,n.fragment]);n.fragment=void 0,n.payload=this.packaging(c)}}return n}static packaging(e){return Buffer.concat([R_,e])}static isDetectedFinalPacketInSequence(e){return e.marker}get isKeyframe(){return this.nalUnitType===Ca.idrSlice||this.nalUnitPayloadType===Ca.idrSlice}get isPartitionHead(){return this.nalUnitType===Ca.fu_a||this.nalUnitType===Ca.fu_b?this.s!==0:!0}},Ca={idrSlice:5,stap_a:24,stap_b:25,mtap16:26,mtap24:27,fu_a:28,fu_b:29},R_=Buffer.from([0,0,0,1]),N_=1,P_=2,O_=class t4{payload;static deSerialize(e){let r=new t4;return r.payload=e,r}static isDetectedFinalPacketInSequence(e){return!0}get isKeyframe(){return!0}static createCodecPrivate(e=48e3){return Buffer.concat([Buffer.from("OpusHead"),Ht([1,1],[1,2]),IT([2,4,2,1],[312,e,0,0])])}},L_=class r4{xBit;nBit;sBit;pid;iBit;lBit;tBit;kBit;mBit;pictureId;payload;size0=0;hBit;ver;pBit;size1=0;size2=0;static deSerialize(e){let r=new r4,n=0;if(r.xBit=ue(e[n],0),r.nBit=ue(e[n],2),r.sBit=ue(e[n],3),r.pid=ue(e[n],5,3),n++,r.xBit&&(r.iBit=ue(e[n],0),r.lBit=ue(e[n],1),r.tBit=ue(e[n],2),r.kBit=ue(e[n],3),n++),r.iBit)if(r.mBit=ue(e[n],0),r.mBit){let s=Wh(ue(e[n],1,7)),i=Wh(e[n+1]);r.pictureId=Number.parseInt(s+i,2),n+=2}else r.pictureId=ue(e[n],1,7),n++;return r.lBit&&n++,(r.lBit||r.kBit)&&(r.tBit,r.kBit,n++),r.payload=e.subarray(n),r.payloadHeaderExist&&(r.size0=ue(e[n],0,3),r.hBit=ue(e[n],3),r.ver=ue(e[n],4,3),r.pBit=ue(e[n],7),n++,r.size1=e[n],n++,r.size2=e[n]),r}static isDetectedFinalPacketInSequence(e){return e.marker}get isKeyframe(){return this.pBit===0}get isPartitionHead(){return this.sBit===1}get payloadHeaderExist(){return this.sBit===1&&this.pid===0}get size(){return this.payloadHeaderExist?this.size0+8*this.size1+2048*this.size2:0}},U_=class n4{iBit;pBit;lBit;fBit;bBit;eBit;vBit;zBit;m;pictureId;tid;u;sid;d;tl0PicIdx;pDiff=[];n_s;y;g;width=[];height=[];n_g=0;pgT=[];pgU=[];pgP_Diff=[];payload;static deSerialize(e){let{p:r,offset:n}=this.parseRtpPayload(e);return r.payload=e.subarray(n),r}static parseRtpPayload(e){let r=new n4,n=0;if(r.iBit=ue(e[n],0),r.pBit=ue(e[n],1),r.lBit=ue(e[n],2),r.fBit=ue(e[n],3),r.bBit=ue(e[n],4),r.eBit=ue(e[n],5),r.vBit=ue(e[n],6),r.zBit=ue(e[n],7),n++,r.iBit)if(r.m=ue(e[n],0),r.m){let s=Wh(ue(e[n],1,7)),i=Wh(e[n+1]);r.pictureId=Number.parseInt(s+i,2),n+=2}else r.pictureId=ue(e[n],1,7),n++;if(r.lBit&&(r.tid=ue(e[n],0,3),r.u=ue(e[n],3),r.sid=ue(e[n],4,3),r.d=ue(e[n],7),n++,r.fBit===0&&(r.tl0PicIdx=e[n],n++)),r.fBit&&r.pBit)for(;;){r.pDiff=[...r.pDiff,ue(e[n],0,7)];let s=ue(e[n],7);if(n++,s===0)break}return r.vBit&&(r.n_s=ue(e[n],0,3),r.y=ue(e[n],3),r.g=ue(e[n],4),n++,r.y&&[...Array(r.n_s+1)].forEach(()=>{r.width.push(e.readUInt16BE(n)),n+=2,r.height.push(e.readUInt16BE(n)),n+=2}),r.g&&(r.n_g=e[n],n++),r.n_g>0&&[...Array(r.n_g).keys()].forEach(s=>{r.pgT.push(ue(e[n],0,3)),r.pgU.push(ue(e[n],3));let i=ue(e[n],4,2);n++,r.pgP_Diff[s]=[],i>0&&[...Array(i)].forEach(()=>{r.pgP_Diff[s].push(e[n]),n++})})),{offset:n,p:r}}static isDetectedFinalPacketInSequence(e){return e.marker}get isKeyframe(){return!!(!this.pBit&&this.bBit&&(!this.sid||!this.lBit))}get isPartitionHead(){return this.bBit&&(!this.lBit||!this.d)}},NZ=class{payload;fragment;static deSerialize(t,e){return{}}static isDetectedFinalPacketInSequence(t){return!0}get isKeyframe(){return!0}};function PZ(t,e,r){let n=s=>{let i=[];for(let c of e){let f=s.deSerialize(c.payload,r);f.fragment?(r??=Buffer.alloc(0),r=f.fragment):f.payload&&(r=void 0),i.push(f)}let o=!!i.find(c=>c.isKeyframe),a=Buffer.concat(i.map(c=>c.payload).filter(c=>c));return{isKeyframe:o,data:a,sequence:e.at(-1)?.header.sequenceNumber??0,timestamp:e.at(-1)?.header.timestamp??0,frameFragmentBuffer:r}};switch(t.toUpperCase()){case"AV1":{let s=e.map(a=>q6.deSerialize(a.payload)),i=!!s.find(a=>a.isKeyframe),o=q6.getFrame(s);return{isKeyframe:i,data:o,sequence:e.at(-1)?.header.sequenceNumber??0,timestamp:e.at(-1)?.header.timestamp??0}}case"MPEG4/ISO/AVC":return n(k_);case"VP8":return n(L_);case"VP9":return n(U_);case"OPUS":return n(O_);default:throw new Error}}var OZ=["MPEG4/ISO/AVC","VP8","VP9","OPUS","AV1"];function LZ(t){return t.map((e,r)=>[r,e])}function V6(t,e){let r=Buffer.alloc(e);return t.copy(r),r}function ep(t){return Number.parseInt(t.toString(),10)}var UZ={setTimeout:(...t)=>{let e=setTimeout(...t);return()=>clearTimeout(e)},setInterval:(...t)=>{let e=setInterval(()=>{t[0]()},...t.slice(1));return()=>clearInterval(e)}};function D_(t){let e=t[0];return e>127&&e<192}var eg=4,po=class tg{version=2;padding=!1;count=0;type=0;length=0;constructor(e={}){Object.assign(this,e)}static serialize(e,r,n,s){let o=new tg({type:e,count:r,version:2,length:s}).serialize();return Buffer.concat([o,n])}serialize(){let e=new $h(8);return e.set(2,0,this.version),this.padding&&e.set(1,2,1),e.set(5,3,this.count),Ht([1,1,2],[e.value,this.type,this.length])}static deSerialize(e){let[r,n,s]=Wr(e,[1,1,2]),i=ue(r,0,2),o=ue(r,2,1)>0,a=ue(r,3,5);return new tg({version:i,padding:o,count:a,type:n,length:s})}},z6=class rg{static count=4;count=rg.count;senderSsrc;mediaSsrc;fir=[];constructor(e={}){Object.assign(this,e)}get length(){return Math.floor(this.serialize().length/4-1)}static deSerialize(e){let[r,n]=Wr(e,[4,4]),s=[];for(let i=8;i<e.length;i+=8)s.push({ssrc:e.readUInt32BE(i),sequenceNumber:e[i+4]});return new rg({senderSsrc:r,mediaSsrc:n,fir:s})}serialize(){let e=Ht([4,4],[this.senderSsrc,this.mediaSsrc]),r=Buffer.alloc(this.fir.length*8);return this.fir.forEach(({ssrc:n,sequenceNumber:s},i)=>{r.writeUInt32BE(n,i*8),r[i*8+4]=s}),Buffer.concat([e,r])}},tp=class ng{static count=1;count=ng.count;length=2;senderSsrc;mediaSsrc;constructor(e={}){Object.assign(this,e)}static deSerialize(e){let[r,n]=Wr(e,[4,4]);return new ng({senderSsrc:r,mediaSsrc:n})}serialize(){return Ht([4,4],[this.senderSsrc,this.mediaSsrc])}},rp=class sg{static count=15;length;count=sg.count;senderSsrc;mediaSsrc;uniqueID="REMB";ssrcNum=0;brExp;brMantissa;bitrate;ssrcFeedbacks=[];constructor(e={}){Object.assign(this,e)}static deSerialize(e){let[r,n,s,i,o]=Wr(e,[4,4,4,1,1]),a=ue(o,0,6),c=(ue(o,6,2)<<16)+(e[14]<<8)+e[15],f=a>46?18446744073709551615n:BigInt(c)<<BigInt(a),l=[];for(let p=16;p<e.length;p+=4){let x=e.slice(p).readUIntBE(0,4);l.push(x)}return new sg({senderSsrc:r,mediaSsrc:n,uniqueID:Ht([4],[s]).toString(),ssrcNum:i,brExp:a,brMantissa:c,ssrcFeedbacks:l,bitrate:f})}serialize(){let e=Buffer.concat([Ht([4,4],[this.senderSsrc,this.mediaSsrc]),Buffer.from(this.uniqueID),Ht([1],[this.ssrcNum])]),r=new $h(24);r.set(6,0,this.brExp).set(18,6,this.brMantissa);let n=Buffer.concat(this.ssrcFeedbacks.map(i=>Ht([4],[i]))),s=Buffer.concat([e,Ht([3],[r.value]),n]);return this.length=s.length/4,s}},M_=tt("werift-rtp: /rtcp/psfb/index"),Fd=class ig{static type=206;type=ig.type;feedback;constructor(e={}){Object.assign(this,e)}serialize(){let e=this.feedback.serialize();return po.serialize(this.type,this.feedback.count,e,this.feedback.length)}static deSerialize(e,r){let n;switch(r.count){case z6.count:n=z6.deSerialize(e);break;case tp.count:n=tp.deSerialize(e);break;case rp.count:n=rp.deSerialize(e);break;default:M_("unknown psfb packet",r.count);break}return new ig({feedback:n})}},Kd=class _h{ssrc=0;reports=[];static type=201;type=_h.type;constructor(e={}){Object.assign(this,e)}serialize(){let e=Ht([4],[this.ssrc]);return e=Buffer.concat([e,...this.reports.map(r=>r.serialize())]),po.serialize(_h.type,this.reports.length,e,Math.floor(e.length/4))}static deSerialize(e,r){let[n]=Wr(e,[4]),s=4,i=[];for(let o=0;o<r;o++)i.push(Gg.deSerialize(e.slice(s,s+24))),s+=24;return new _h({ssrc:n,reports:i})}},Gg=class s4{ssrc;fractionLost;packetsLost;highestSequence;jitter;lsr;dlsr;constructor(e={}){Object.assign(this,e)}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 Ht([4,1,3,4,4,4,4],[this.ssrc,this.fractionLost,this.packetsLost,this.highestSequence,this.jitter,this.lsr,this.dlsr])}static deSerialize(e){let[r,n,s,i,o,a,c]=Wr(e,[4,1,3,4,4,4,4]);return new s4({ssrc:r,fractionLost:n,packetsLost:s,highestSequence:i,jitter:o,lsr:a,dlsr:c})}},i4=205,np=class og{static count=1;count=og.count;header;senderSsrc;mediaSourceSsrc;lost=[];toJSON(){return{lost:this.lost,senderSsrc:this.senderSsrc,mediaSourceSsrc:this.mediaSourceSsrc}}constructor(e={}){Object.assign(this,e),this.header||(this.header=new po({type:i4,count:this.count,version:2}))}static deSerialize(e,r){let[n,s]=Wr(e,[4,4]),i=[];for(let o=8;o<e.length;o+=4){let[a,c]=Wr(e.subarray(o),[2,2]);i.push(a);for(let f=0;f<16;f++)c>>f&1&&i.push(a+f+1)}return new og({header:r,senderSsrc:n,mediaSourceSsrc:s,lost:i})}serialize(){let e=Ht([4,4],[this.senderSsrc,this.mediaSourceSsrc]),r=[];if(this.lost.length>0){let s=this.lost[0],i=0;this.lost.slice(1).forEach(o=>{let a=o-s-1;a>=0&&a<16?i|=1<<a:(r.push(Ht([2,2],[s,i])),s=o,i=0)}),r.push(Ht([2,2],[s,i]))}let n=Buffer.concat([e,Buffer.concat(r)]);return this.header.length=n.length/4,Buffer.concat([this.header.serialize(),n])}},H_=tt("werift/rtp/rtcp/rtpfb/twcc"),sp=class ag{static count=15;count=ag.count;length=2;senderSsrc;mediaSourceSsrc;baseSequenceNumber;packetStatusCount;referenceTime;fbPktCount;packetChunks=[];recvDeltas=[];header;constructor(e={}){Object.assign(this,e),this.header||(this.header=new po({type:205,count:this.count,version:2}))}static deSerialize(e,r){let[n,s,i,o,a,c]=Wr(e,[4,4,2,2,3,1]),f=[],l=[],p=16;for(let v=0;v<o;){let S=ue(e.slice(p,p+1)[0],0,1),I;switch(S){case 0:{let L=qd.deSerialize(e.slice(p,p+2));I=L;let ee=Math.min(o-v,L.runLength);if(L.packetStatus===1||L.packetStatus===2)for(let Pe=0;Pe<ee;Pe++)l.push(new Bh({type:L.packetStatus}));v+=ee}break;case 1:{let L=j_.deSerialize(e.slice(p,p+2));I=L,L.symbolSize===0&&L.symbolList.forEach(ee=>{ee===1&&l.push(new Bh({type:1}))}),L.symbolSize===1&&L.symbolList.forEach(ee=>{(ee===1||ee===2)&&l.push(new Bh({type:ee}))}),v+=L.symbolList.length}break}if(!I)throw new Error;p+=2,f.push(I)}let x=p;return l.forEach(v=>{v.type===1&&(v.deSerialize(e.slice(x,x+1)),x++),v.type===2&&(v.deSerialize(e.slice(x,x+2)),x+=2)}),new ag({senderSsrc:n,mediaSourceSsrc:s,baseSequenceNumber:i,packetStatusCount:o,referenceTime:a,fbPktCount:c,recvDeltas:l,packetChunks:f,header:r})}serialize(){let e=Ht([4,4,2,2,3,1],[this.senderSsrc,this.mediaSourceSsrc,this.baseSequenceNumber,this.packetStatusCount,this.referenceTime,this.fbPktCount]),r=Buffer.concat(this.packetChunks.map(i=>i.serialize())),n=Buffer.concat(this.recvDeltas.map(i=>{try{return i.serialize()}catch(o){H_(o?.message);return}}).filter(i=>i)),s=Buffer.concat([e,r,n]);if(this.header.padding&&s.length%4!==0){let i=4-s.length%4,o=Buffer.alloc(i);return o[o.length-1]=o.length,this.header.length=Math.floor((s.length+o.length)/4),Buffer.concat([this.header.serialize(),s,o])}return this.header.length=Math.floor(s.length/4),Buffer.concat([this.header.serialize(),s])}get packetResults(){let e=this.baseSequenceNumber-1,r=this.packetChunks.filter(o=>o instanceof qd).flatMap(o=>o.results(e)),n=0,i=BigInt(this.referenceTime)*64n;for(let o of r){let a=this.recvDeltas[n];!o.received||!a||(i+=BigInt(a.delta)/1000n,o.delta=a.delta,o.receivedAtMs=Number(i),n++)}return r}},qd=class o4{type;packetStatus;runLength;constructor(e={}){Object.assign(this,e),this.type=0}static deSerialize(e){let r=ue(e[0],1,2),n=(ue(e[0],3,5)<<8)+e[1];return new o4({type:0,packetStatus:r,runLength:n})}serialize(){return new zg(16).set(0).set(this.packetStatus,2).set(this.runLength,13).buffer}results(e){let r=this.packetStatus===1||this.packetStatus===2,n=[];for(let s=0;s<=this.runLength;++s)n.push(new z_({sequenceNumber:++e,received:r}));return n}},j_=class a4{type;symbolSize;symbolList=[];constructor(e={}){Object.assign(this,e)}static deSerialize(e){let n=ue(e[0],1,1),s=[];function i(o,a){for(let c=0;c<o;c++)a(c)}switch(n){case 0:i(6,o=>s.push(ue(e[0],2+o,1))),i(8,o=>s.push(ue(e[1],o,1)));break;case 1:i(3,o=>s.push(ue(e[0],2+o*2,2))),i(4,o=>s.push(ue(e[1],o*2,2)));break;default:n=(ue(e[0],2,6)<<8)+e[1]}return new a4({type:1,symbolSize:n,symbolList:s})}serialize(){let e=Buffer.alloc(2),r=new zg(16).set(1).set(this.symbolSize),n=this.symbolSize===0?1:2;return this.symbolList.forEach(s=>{r.set(s,n)}),e.writeUInt16BE(r.value),e}},Bh=class cg{type;delta;constructor(e={}){Object.assign(this,e)}static deSerialize(e){let r,n;if(e.length===1?(r=1,n=250*e[0]):e.length===2&&(r=2,n=250*e.readInt16BE()),r===void 0||n===void 0)throw new Error;return new cg({type:r,delta:n})}deSerialize(e){let r=cg.deSerialize(e);this.delta=r.delta}parsed=!1;parseDelta(){this.delta=Math.floor(this.delta/250),this.delta<0||this.delta>255?(this.delta>32767&&(this.delta=32767),this.delta<-32768&&(this.delta=-32768),this.type||(this.type=2)):this.type||(this.type=1),this.parsed=!0}serialize(){if(this.parsed||this.parseDelta(),this.type===1){let e=Buffer.alloc(1);return e.writeUInt8(this.delta),e}else if(this.type===2){let e=Buffer.alloc(2);return e.writeInt16BE(this.delta),e}throw new Error("errDeltaExceedLimit "+this.delta+" "+this.type)}},q_=(t=>(t[t.TypeTCCRunLengthChunk=0]="TypeTCCRunLengthChunk",t[t.TypeTCCStatusVectorChunk=1]="TypeTCCStatusVectorChunk",t[t.packetStatusChunkLength=2]="packetStatusChunkLength",t))(q_||{}),V_=(t=>(t[t.TypeTCCPacketNotReceived=0]="TypeTCCPacketNotReceived",t[t.TypeTCCPacketReceivedSmallDelta=1]="TypeTCCPacketReceivedSmallDelta",t[t.TypeTCCPacketReceivedLargeDelta=2]="TypeTCCPacketReceivedLargeDelta",t[t.TypeTCCPacketReceivedWithoutDelta=3]="TypeTCCPacketReceivedWithoutDelta",t))(V_||{}),z_=class{sequenceNumber=0;delta=0;received=!1;receivedAtMs=0;constructor(t){Object.assign(this,t)}},F_=tt("werift-rtp:packages/rtp/rtcp/rtpfb/index"),eu=class ug{static type=i4;type=ug.type;feedback;header;constructor(e={}){Object.assign(this,e)}serialize(){return this.feedback.serialize()}static deSerialize(e,r){let n;switch(r.count){case np.count:n=np.deSerialize(e,r);break;case sp.count:n=sp.deSerialize(e,r);break;default:F_("unknown rtpfb packet",r.count);break}return new ug({feedback:n,header:r})}},ip=class fg{static type=202;type=fg.type;chunks=[];constructor(e){Object.assign(this,e)}get length(){let e=0;return this.chunks.forEach(r=>e+=r.length),e}serialize(){let e=Buffer.concat(this.chunks.map(r=>r.serialize()));for(;e.length%4;)e=Buffer.concat([e,Buffer.from([0])]);return po.serialize(this.type,this.chunks.length,e,e.length/4)}static deSerialize(e,r){let n=[];for(let s=0;s<e.length;){let i=c4.deSerialize(e.slice(s));n.push(i),s+=i.length}return new fg({chunks:n})}},c4=class u4{source;items=[];constructor(e={}){Object.assign(this,e)}get length(){let e=4;return this.items.forEach(r=>e+=r.length),e+=1,e+=F6(e),e}serialize(){let e=Buffer.concat([Ht([4],[this.source]),Buffer.concat(this.items.map(n=>n.serialize()))]);return Buffer.concat([e,Buffer.alloc(F6(e.length))])}static deSerialize(e){let r=e.readUInt32BE(),n=[];for(let s=4;s<e.length&&e[s]!==0;){let o=f4.deSerialize(e.slice(s));n.push(o),s+=o.length}return new u4({source:r,items:n})}},f4=class d4{type;text;constructor(e){Object.assign(this,e)}get length(){return 2+Buffer.from(this.text).length}serialize(){let e=Buffer.from(this.text);return Buffer.concat([Ht([1,1],[this.type,e.length]),e])}static deSerialize(e){let r=e[0],n=e[1],s=e.slice(2,2+n).toString();return new d4({type:r,text:s})}};function F6(t){return t%4==0?0:4-t%4}var tu=class kh{ssrc=0;senderInfo;reports=[];static type=200;type=kh.type;constructor(e){Object.assign(this,e)}toJSON(){return{ssrc:this.ssrc,senderInfo:this.senderInfo.toJSON(),reports:this.reports.map(e=>e.toJSON())}}serialize(){let e=Buffer.alloc(4);return e.writeUInt32BE(this.ssrc),e=Buffer.concat([e,this.senderInfo.serialize()]),e=Buffer.concat([e,...this.reports.map(r=>r.serialize())]),po.serialize(kh.type,this.reports.length,e,Math.floor(e.length/4))}static deSerialize(e,r){let n=e.readUInt32BE(),s=l4.deSerialize(e.subarray(4,24)),i=24,o=[];for(let c=0;c<r;c++)o.push(Gg.deSerialize(e.subarray(i,i+24))),i+=24;return new kh({ssrc:n,senderInfo:s,reports:o})}},l4=class h4{ntpTimestamp;rtpTimestamp;packetCount;octetCount;constructor(e={}){Object.assign(this,e)}toJSON(){return{ntpTimestamp:K_(this.ntpTimestamp),rtpTimestamp:this.rtpTimestamp}}serialize(){return Ht([8,4,4,4],[this.ntpTimestamp,this.rtpTimestamp,this.packetCount,this.octetCount])}static deSerialize(e){let[r,n,s,i]=Wr(e,[8,4,4,4]);return new h4({ntpTimestamp:r,rtpTimestamp:n,packetCount:s,octetCount:i})}},K_=t=>{let[e,r]=Wr(Ht([8],[t]),[4,4]);return+`${e}.${r}`},$_=tt("werift-rtp:packages/rtp/src/rtcp/rtcp.ts"),W_=class{static deSerialize(t){let e=0,r=[];for(;e<t.length;){let n=po.deSerialize(t.subarray(e,e+eg));e+=eg;let s=t.subarray(e);e+=n.length*4,n.padding&&(s=s.subarray(0,s.length-s.subarray(-1)[0]));try{switch(n.type){case tu.type:r.push(tu.deSerialize(s,n.count));break;case Kd.type:r.push(Kd.deSerialize(s,n.count));break;case ip.type:r.push(ip.deSerialize(s,n));break;case eu.type:r.push(eu.deSerialize(s,n));break;case Fd.type:r.push(Fd.deSerialize(s,n));break;default:break}}catch(i){$_("deSerialize RTCP",i)}}return r}};function G_(t){return t.length>=2&&t[1]>=192&&t[1]<=208}var Dt={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 X_(t,e){return t.map(r=>{let n=e[r.id];if(!n)return{uri:"unknown",value:r.payload};switch(n){case Dt.sdesMid:case Dt.sdesRTPStreamID:case Dt.repairedRtpStreamId:return{uri:n,value:t7(r.payload)};case Dt.transportWideCC:return{uri:n,value:r7(r.payload)};case Dt.absSendTime:return{uri:n,value:n7(r.payload)};case Dt.audioLevelIndication:return{uri:n,value:s7(r.payload)};case Dt.videoOrientation:return{uri:n,value:i7(r.payload)};default:return{uri:n,value:r.payload}}}).reduce((r,n)=>(n&&(r[n.uri]=n.value),r),{})}function Y_(t){return Buffer.from(t)}function Z_(t){return Buffer.from(t)}function J_(t){return Buffer.from(t)}function Q_(t){return Ht([2],[t])}function e7(t){let e=Buffer.alloc(3),r=t>>14n&0x00ffffffn;return e.writeUIntBE(Number(r),0,3),e}function DZ(t){let e=new Ba(Buffer.alloc(1));return e.writeBits(1,1),e.writeBits(7,t),e.uint8Array}function t7(t){return t.toString()}function r7(t){return t.readUInt16BE()}function n7(t){return Wr(t,[3])[0]}function s7(t){let e=new Ba(t);return{v:e.readBits(1)===1,level:e.readBits(7)}}function i7(t){let e=new Ba(t);return e.readBits(4),{c:e.readBits(1),f:e.readBits(1),r1:e.readBits(1),r0:e.readBits(1)}}var o7=tt("packages/rtp/src/rtp/red/packet.ts"),p4=class x4{header;blocks=[];static deSerialize(e){let r=e instanceof ArrayBuffer?Buffer.from(e):e,n=new x4,s=0;return[n.header,s]=K6.deSerialize(r),n.header.fields.forEach(({blockLength:i,timestampOffset:o,blockPT:a})=>{if(i&&o){let c=r.subarray(s,s+i);n.blocks.push({block:c,blockPT:a,timestampOffset:o}),s+=i}else{let c=r.subarray(s);n.blocks.push({block:c,blockPT:a})}}),n}serialize(){this.header=new K6;for(let{timestampOffset:r,blockPT:n,block:s}of this.blocks)r?this.header.fields.push({fBit:1,blockPT:n,blockLength:s.length,timestampOffset:r}):this.header.fields.push({fBit:0,blockPT:n});let e=this.header.serialize();for(let{block:r}of this.blocks)e=Buffer.concat([e,r]);return e}},K6=class m4{fields=[];static deSerialize(e){let r=0,n=new m4;for(;;){let s={};n.fields.push(s);let i=new Ba(e.subarray(r));if(s.fBit=i.readBits(1),s.blockPT=i.readBits(7),r++,s.fBit===0)break;s.timestampOffset=i.readBits(14),s.blockLength=i.readBits(10),r+=3}return[n,r]}serialize(){let e=Buffer.alloc(0);for(let r of this.fields)try{if(r.timestampOffset&&r.blockLength){let n=new Ba(Buffer.alloc(4)).writeBits(1,r.fBit).writeBits(7,r.blockPT).writeBits(14,r.timestampOffset).writeBits(10,r.blockLength);e=Buffer.concat([e,n.uint8Array])}else{let n=new Ba(Buffer.alloc(1)).writeBits(1,0).writeBits(7,r.blockPT);e=Buffer.concat([e,n.uint8Array])}}catch(n){o7(n?.message)}return e}},a7=class{constructor(t=1){this.distance=t}cache=[];cacheSize=10;push(t){this.cache.push(t),this.cache.length>this.cacheSize&&this.cache.shift()}build(){let t=new p4,e=this.cache.slice(-(this.distance+1)),r=e.pop();return r&&(e.forEach(n=>{let s=Zc(r.timestamp,-n.timestamp);s>c7||t.blocks.push({block:n.block,blockPT:n.blockPT,timestampOffset:s})}),t.blocks.push({block:r.block,blockPT:r.blockPT})),t}},c7=16383,u7=class{size=150;sequenceNumbers=[];push(t,e){let r=[];return t.blocks.forEach(({blockPT:s,timestampOffset:i,block:o},a)=>{let c=Tr(e.header.sequenceNumber,-(t.blocks.length-(a+1)));i?r.push(new ho(new lo({timestamp:Zc(e.header.timestamp,-i),payloadType:s,ssrc:e.header.ssrc,sequenceNumber:c,marker:!0}),o)):r.push(new ho(new lo({timestamp:e.header.timestamp,payloadType:s,ssrc:e.header.ssrc,sequenceNumber:c,marker:!0}),o))}),r.filter(s=>this.sequenceNumbers.includes(s.header.sequenceNumber)?!1:(this.sequenceNumbers.length>this.size&&this.sequenceNumbers.shift(),this.sequenceNumbers.push(s.header.sequenceNumber),!0))}},Ia={OneByte:48862,TwoByte:4096},$6=2,W6=4,G6=8,X6=12,Y6=4,lo=class g4{version=2;padding=!1;paddingSize=0;extension=!1;marker=!1;payloadOffset=0;payloadType=0;sequenceNumber=0;timestamp=0;ssrc=0;csrcLength=0;csrc=[];extensionProfile=Ia.OneByte;extensionLength;extensions=[];constructor(e={}){Object.assign(this,e)}static deSerialize(e){let r=new g4,n=0,s=e[n++];r.version=ue(s,0,2),r.padding=ue(s,2)>0,r.extension=ue(s,3)>0,r.csrcLength=ue(s,4,4),r.csrc=[...Array(r.csrcLength)].map(()=>{let o=e.readUInt32BE(n);return n+=4,o}),n+=X6-1;let i=e[1];r.marker=ue(i,0)>0,r.payloadType=ue(i,1,7),r.sequenceNumber=e.readUInt16BE($6),r.timestamp=e.readUInt32BE(W6),r.ssrc=e.readUInt32BE(G6);for(let o=0;o<r.csrc.length;o++){let a=X6+o*Y6;r.csrc[o]=e.subarray(a).readUInt32BE()}if(r.extension){r.extensionProfile=e.subarray(n).readUInt16BE(),n+=2;let o=e.subarray(n).readUInt16BE()*4;switch(r.extensionLength=o,n+=2,r.extensionProfile){case Ia.OneByte:{let a=n+o;for(;n<a;){if(e[n]===0){n++;continue}let c=e[n]>>4,f=(e[n]&(e[n]^240))+1;if(n++,c===15)break;let l={id:c,payload:e.subarray(n,n+f)};r.extensions=[...r.extensions,l],n+=f}}break;case Ia.TwoByte:{let a=n+o;for(;n<a;){if(e[n]===0){n++;continue}let c=e[n];n++;let f=e[n];n++;let l={id:c,payload:e.subarray(n,n+f)};r.extensions=[...r.extensions,l],n+=f}}break;default:{let a={id:0,payload:e.subarray(n,n+o)};r.extensions=[...r.extensions,a],n+=r.extensions[0].payload.length}break}}return r.payloadOffset=n,r.padding&&(r.paddingSize=e[e.length-1]),r}get serializeSize(){let{csrc:e,extensionProfile:r,extensions:n}=this,s=12+e.length*Y6;if(n.length>0||this.extension===!0){let i=4;switch(r){case Ia.OneByte:for(let o of n)i+=1+o.payload.length;break;case Ia.TwoByte:for(let o of n)i+=2+o.payload.length;break;default:i+=n[0].payload.length}s+=Math.floor((i+3)/4)*4}return s}serialize(e){let r=Buffer.alloc(e),n=0,s=new $h(8);s.set(2,0,this.version),this.padding&&s.set(1,2,1),this.extensions.length>0&&(this.extension=!0),this.extension&&s.set(1,3,1),s.set(4,4,this.csrc.length),r.writeUInt8(s.value,n++);let i=new $h(8);this.marker&&i.set(1,0,1),i.set(7,1,this.payloadType),r.writeUInt8(i.value,n++),r.writeUInt16BE(this.sequenceNumber,$6),n+=2,r.writeUInt32BE(this.timestamp,W6),n+=4,r.writeUInt32BE(this.ssrc,G6),n+=4;for(let o of this.csrc)r.writeUInt32BE(o,n),n+=4;if(this.extension){let o=n;r.writeUInt16BE(this.extensionProfile,n),n+=4;let a=n;switch(this.extensionProfile){case Ia.OneByte:for(let l of this.extensions)r.writeUInt8(l.id<<4|l.payload.length-1,n++),l.payload.copy(r,n),n+=l.payload.length;break;case Ia.TwoByte:for(let l of this.extensions)r.writeUInt8(l.id,n++),r.writeUInt8(l.payload.length,n++),l.payload.copy(r,n),n+=l.payload.length;break;default:{let l=this.extensions[0].payload.length;if(l%4!=0)throw new Error;this.extensions[0].payload.copy(r,n),n+=l}}let c=n-a,f=Math.trunc((c+3)/4)*4;r.writeUInt16BE(Math.trunc(f/4),o+2);for(let l=0;l<f-c;l++)r.writeUInt8(0,n),n++}return this.payloadOffset=n,r}},ho=class dg{constructor(e,r){this.header=e,this.payload=r}get serializeSize(){return this.header.serializeSize+this.payload.length}clone(){return new dg(new lo({...this.header}),this.payload)}serialize(){let e=this.header.serialize(this.header.serializeSize+this.payload.length),{payloadOffset:r}=this.header;if(this.payload.copy(e,r),this.header.padding){let n=Buffer.alloc(this.header.paddingSize);n.writeUInt8(this.header.paddingSize,this.header.paddingSize-1),e=Buffer.concat([e,n])}return e}static deSerialize(e){let r=lo.deSerialize(e);return new dg(r,e.subarray(r.payloadOffset,e.length-r.paddingSize))}clear(){this.payload=null}};function f7(t,e,r){return new ho(new lo({payloadType:e,marker:t.header.marker,sequenceNumber:Xg.jspack.Unpack("!H",t.payload.subarray(0,2))[0],timestamp:t.header.timestamp,ssrc:r}),t.payload.subarray(2))}function d7(t,e,r,n){return new ho(new lo({payloadType:e,marker:t.header.marker,sequenceNumber:r,timestamp:t.header.timestamp,ssrc:n,csrc:t.header.csrc,extensions:t.header.extensions}),Buffer.concat([Buffer.from(Xg.jspack.Pack("!H",[t.header.sequenceNumber])),t.payload]))}var y4=class{constructor(t,e,r,n){this.srtpSessionKey=t,this.srtpSessionSalt=e,this.srtcpSessionKey=r,this.srtcpSessionSalt=n}encryptRtp(t,e,r){return Buffer.from([])}decryptRtp(t,e,r){return[]}encryptRTCP(t,e){return Buffer.from([])}decryptRTCP(t){return[]}},ru=class extends Error{constructor(t){super(t),this.name="SrtpAuthenticationError"}},e3=12,h7=8;function Yg(t,e,r="Failed to authenticate SRTP packet"){let n=t.length-e;$d(t.length>=e3+e,r);let s=v4(()=>lo.deSerialize(t.subarray(0,n)),r);return s.paddingSize=0,$d(s.payloadOffset>=e3&&s.payloadOffset<=n,r),s}function b4(t,e,r,n="Failed to authenticate SRTCP packet"){return $d(t.length>=h7+e+r,n),v4(()=>po.deSerialize(t.subarray(0,eg)),n)}function $d(t,e){if(!t)throw new ru(e)}function v4(t,e){try{return t()}catch{throw new ru(e)}}function w4(t,e,r="Failed to authenticate SRTP packet"){if(!t.padding)return t.paddingSize=0,t;$d(e.length>t.payloadOffset,r);let n=e[e.length-1];return $d(n>0&&n<=e.length-t.payloadOffset,r),t.paddingSize=n,t}var p7=class extends y4{constructor(t,e,r,n,s,i){super(t,e,r,n),this.srtpSessionAuthTag=s,this.srtcpSessionAuthTag=i}authTagLength=10;encryptRtp(t,e,r){let n=t.serialize(t.serializeSize),s=this.generateCounter(t.sequenceNumber,r,t.ssrc,this.srtpSessionSalt),o=Z6("aes-128-ctr",this.srtpSessionKey,s).update(e),a=this.generateSrtpAuthTag(r,n,o);return Buffer.concat([n,o,a])}decryptRtp(t,e,r=Yg(t,this.authTagLength)){let n=t.length-this.authTagLength,s=t.subarray(0,n),i=t.subarray(n),o=this.generateSrtpAuthTag(e,s.subarray(0,r.payloadOffset),s.subarray(r.payloadOffset));r3(i,o,"Failed to authenticate SRTP packet");let a=this.generateCounter(r.sequenceNumber,e,r.ssrc,this.srtpSessionSalt),c=J6("aes-128-ctr",this.srtpSessionKey,a),f=s.subarray(r.payloadOffset),l=c.update(f),p=Buffer.concat([s.subarray(0,r.payloadOffset),l]);return[p,w4(r,p,"Failed to authenticate SRTP packet")]}encryptRTCP(t,e){let r=Buffer.from(t),n=r.readUInt32BE(4),s=this.generateCounter(e&65535,e>>16,n,this.srtcpSessionSalt);Z6("aes-128-ctr",this.srtcpSessionKey,s).update(r.slice(8)).copy(r,8),r=Buffer.concat([r,Buffer.alloc(4)]),r.writeUInt32BE(e,r.length-4),r[r.length-4]|=128;let a=this.generateSrtcpAuthTag(r);return r=Buffer.concat([r,a]),r}decryptRTCP(t){let e=b4(t,this.authTagLength,t3),r=t.length-(this.authTagLength+t3),n=t.subarray(0,t.length-this.authTagLength),s=t.subarray(t.length-this.authTagLength),i=this.generateSrtcpAuthTag(n);r3(s,i,"Failed to authenticate SRTCP packet");let o=Buffer.from(t).slice(0,r);if(t[r]>>>7===0)return[o,e];let c=t.readUInt32BE(r);c&=~(1<<31);let f=t.readUInt32BE(4),l=this.generateCounter(c&65535,c>>16,f,this.srtcpSessionSalt);return J6("aes-128-ctr",this.srtcpSessionKey,l).update(o.subarray(8)).copy(o,8),[o,e]}generateSrtcpAuthTag(t){return Q6("sha1",this.srtcpSessionAuthTag).update(t).digest().slice(0,10)}generateCounter(t,e,r,n){let s=Buffer.alloc(16);s.writeUInt32BE(r,4),s.writeUInt32BE(e,8),s.writeUInt32BE(Number(BigInt(t)<<16n),12);for(let i=0;i<n.length;i++)s[i]^=n[i];return s}generateSrtpAuthTag(t,...e){let r=Q6("sha1",this.srtpSessionAuthTag),n=Buffer.alloc(4);n.writeUInt32BE(t);for(let s of e)r.update(s);return r.update(n).digest().subarray(0,10)}},t3=4;function r3(t,e,r){if(t.length!==e.length||!l7(t,e))throw new ru(r)}var x7=class extends y4{aeadAuthTagLen=16;rtpIvWriter=Th([2,4,4,2],!0);rtcpIvWriter=Th([2,4,2,4],!0);aadWriter=Th([4],!0);constructor(t,e,r,n){super(t,e,r,n)}encryptRtp(t,e,r){let n=t.serialize(t.serializeSize),s=this.rtpInitializationVector(t,r),i=n3("aes-128-gcm",this.srtpSessionKey,s);i.setAAD(n);let o=i.update(e);i.final();let a=i.getAuthTag();return Buffer.concat([n,o,a])}decryptRtp(t,e,r=Yg(t,this.aeadAuthTagLen)){let n=t.subarray(0,r.payloadOffset),s=t.length-this.aeadAuthTagLen,i=t.subarray(s),o=Buffer.from([]);o=V6(o,t.length-this.aeadAuthTagLen),n.copy(o);let a=this.rtpInitializationVector(r,e),c=t.slice(r.payloadOffset,s),f=s3("aes-128-gcm",this.srtpSessionKey,a);f.setAAD(n),f.setAuthTag(i);let l=f.update(c);return o3(f,"SRTP"),l.copy(o,r.payloadOffset),[o,w4(r,o,"Failed to authenticate SRTP packet")]}encryptRTCP(t,e){let r=t.readUInt32BE(4),n=t.length+this.aeadAuthTagLen,s=Buffer.from([]);s=V6(s,n+_1),t.slice(0,8).copy(s);let i=this.rtcpInitializationVector(r,e),o=this.rtcpAdditionalAuthenticatedData(t,e),a=n3("aes-128-gcm",this.srtcpSessionKey,i);a.setAAD(o);let c=a.update(t.slice(8));return a.final(),c.copy(s,8),a.getAuthTag().copy(s,8+c.length),o.slice(8,12).copy(s,n),s}decryptRTCP(t){let e=b4(t,this.aeadAuthTagLen,_1),r=t.length-_1,n=r-this.aeadAuthTagLen,s=t.readUInt32BE(4),i=t.readUInt32BE(r),o=i>>>31===1,a=i&~(i3<<24),c=this.rtcpInitializationVector(s,a),f=o?Buffer.concat([t.subarray(0,8),t.subarray(r)]):Buffer.concat([t.subarray(0,n),t.subarray(r)]),l=o?t.slice(8,n):Buffer.alloc(0),p=o?Buffer.alloc(n):Buffer.from(t.subarray(0,n));o&&t.slice(0,8).copy(p);let x=s3("aes-128-gcm",this.srtcpSessionKey,c);x.setAAD(f),x.setAuthTag(t.subarray(n,r));let v=x.update(l);return o3(x,"SRTCP"),o&&v.copy(p,8),[p,e]}rtpInitializationVector(t,e){let r=this.rtpIvWriter([0,t.ssrc,e,t.sequenceNumber]);for(let n=0;n<r.length;n++)r[n]^=this.srtpSessionSalt[n];return r}rtcpInitializationVector(t,e){let r=this.rtcpIvWriter([0,t,0,e]);for(let n=0;n<r.length;n++)r[n]^=this.srtcpSessionSalt[n];return r}rtcpAdditionalAuthenticatedData(t,e){let r=Buffer.concat([t.subarray(0,8),this.aadWriter([e])]);return r[8]|=i3,r}},_1=4,i3=128;function o3(t,e){try{t.final()}catch{throw new ru(`Failed to authenticate ${e} packet`)}}var S4=class{constructor(t,e,r){this.masterKey=t,this.masterSalt=e,this.profile=r;{let n=14-e.length;n>0&&(this.masterSalt=Buffer.concat([e,Buffer.alloc(n)]))}switch(this.srtpSessionKey=this.generateSessionKey(0),this.srtpSessionSalt=this.generateSessionSalt(2),this.srtpSessionAuthTag=this.generateSessionAuthTag(1),this.srtpSessionAuth=T1("sha1",this.srtpSessionAuthTag),this.srtcpSessionKey=this.generateSessionKey(3),this.srtcpSessionSalt=this.generateSessionSalt(5),this.srtcpSessionAuthTag=this.generateSessionAuthTag(4),this.srtcpSessionAuth=T1("sha1",this.srtcpSessionAuthTag),r){case rl:this.cipher=new p7(this.srtpSessionKey,this.srtpSessionSalt,this.srtcpSessionKey,this.srtcpSessionSalt,this.srtpSessionAuthTag,this.srtcpSessionAuthTag);break;case iu:this.cipher=new x7(this.srtpSessionKey,this.srtpSessionSalt,this.srtcpSessionKey,this.srtcpSessionSalt);break}}srtpSSRCStates={};srtpSessionKey;srtpSessionSalt;srtpSessionAuthTag;srtpSessionAuth;srtcpSSRCStates={};srtcpSessionKey;srtcpSessionSalt;srtcpSessionAuthTag;srtcpSessionAuth;cipher;generateSessionKey(t){let e=Buffer.from(this.masterSalt),r=Buffer.from([t,0,0,0,0,0,0]);for(let s=r.length-1,i=e.length-1;s>=0;s--,i--)e[i]=e[i]^r[s];e=Buffer.concat([e,Buffer.from([0,0])]);let n=new Rh.default.AES(this.masterKey);return Buffer.from(n.encrypt(e))}generateSessionSalt(t){let e=Buffer.from(this.masterSalt),r=Buffer.from([t,0,0,0,0,0,0]);for(let s=r.length-1,i=e.length-1;s>=0;s--,i--)e[i]=e[i]^r[s];e=Buffer.concat([e,Buffer.from([0,0])]);let n=new Rh.default.AES(this.masterKey);return e=Buffer.from(n.encrypt(e)),e.subarray(0,14)}generateSessionAuthTag(t){let e=Buffer.from(this.masterSalt),r=Buffer.from([t,0,0,0,0,0,0]);for(let o=r.length-1,a=e.length-1;o>=0;o--,a--)e[a]=e[a]^r[o];let n=Buffer.concat([e,Buffer.from([0,0])]),s=Buffer.concat([e,Buffer.from([0,1])]),i=new Rh.default.AES(this.masterKey);return n=Buffer.from(i.encrypt(n)),s=Buffer.from(i.encrypt(s)),Buffer.concat([n,s.subarray(0,4)])}getSrtpSsrcState(t){let e=this.srtpSSRCStates[t];return e||(e={ssrc:t,rolloverCounter:0,lastSequenceNumber:0},this.srtpSSRCStates[t]=e,e)}getSrtcpSsrcState(t){let e=this.srtcpSSRCStates[t];return e||(e={srtcpIndex:0,ssrc:t},this.srtcpSSRCStates[t]=e,e)}updateRolloverCount(t,e){e.rolloverHasProcessed?t===0?e.lastSequenceNumber>vd&&e.rolloverCounter++:e.lastSequenceNumber<vd&&t>a3-vd?e.rolloverCounter>0&&e.rolloverCounter--:t<vd&&e.lastSequenceNumber>a3-vd&&e.rolloverCounter++:e.rolloverHasProcessed=!0,e.lastSequenceNumber=t}generateSrtpAuthTag(t,e){this.srtpSessionAuth=T1("sha1",this.srtpSessionAuthTag);let r=Buffer.alloc(4);return r.writeUInt32BE(e),this.srtpSessionAuth.update(t).update(r).digest().slice(0,10)}index(t){let e=this.srtcpSSRCStates[t];return e?e.srtcpIndex:0}setIndex(t,e){let r=this.getSrtcpSsrcState(t);r.srtcpIndex=e%2147483647}},vd=100,a3=65535,m7=class extends S4{constructor(t,e,r){super(t,e,r)}encryptRTCP(t){let e=t.readUInt32BE(4),r=this.getSrtcpSsrcState(e);return r.srtcpIndex++,r.srtcpIndex>>g7&&(r.srtcpIndex=0),this.cipher.encryptRTCP(t,r.srtcpIndex)}decryptRTCP(t){return this.cipher.decryptRTCP(t)}},g7=2147483647,E4=class{constructor(t){this.ContextCls=t}localContext;remoteContext;onData;start(t,e,r,n,s){this.localContext=new this.ContextCls(t,e,s),this.remoteContext=new this.ContextCls(r,n,s)}},y7=class extends E4{constructor(t){super(m7),this.config=t,this.start(t.keys.localMasterKey,t.keys.localMasterSalt,t.keys.remoteMasterKey,t.keys.remoteMasterSalt,t.profile)}decrypt=t=>{let[e]=this.remoteContext.decryptRTCP(t);return e};encrypt(t){return this.localContext.encryptRTCP(t)}},b7=class extends S4{constructor(t,e,r){super(t,e,r)}encryptRtp(t,e){let r=this.getSrtpSsrcState(e.ssrc);return this.updateRolloverCount(e.sequenceNumber,r),this.cipher.encryptRtp(e,t,r.rolloverCounter)}decryptRtp(t){let e=Yg(t,this.rtpAuthTagLength),r=this.srtpSSRCStates[e.ssrc],n=r?{...r}:{ssrc:e.ssrc,rolloverCounter:0,lastSequenceNumber:0};this.updateRolloverCount(e.sequenceNumber,n);let s=this.cipher.decryptRtp(t,n.rolloverCounter,e);return r?Object.assign(r,n):this.srtpSSRCStates[e.ssrc]=n,s}get rtpAuthTagLength(){return this.profile===iu?16:10}},v7=class extends E4{constructor(t){super(b7),this.config=t,this.start(t.keys.localMasterKey,t.keys.localMasterSalt,t.keys.remoteMasterKey,t.keys.remoteMasterSalt,t.profile)}decrypt=t=>{let[e]=this.remoteContext.decryptRtp(t);return e};encrypt(t,e){return this.localContext.encryptRtp(t,e)}},qZ=class{constructor(t){this.props=t}sequenceNumber=f8();timestamp=V1();create(t){this.sequenceNumber=Tr(this.sequenceNumber,1);let e=this.props.between*this.props.clockRate/1e3;this.timestamp=Zc(this.timestamp,e);let r=new lo({sequenceNumber:this.sequenceNumber,timestamp:Number(this.timestamp),payloadType:96,extension:!0,marker:!1,padding:!1});return new ho(r,t)}},Pr=tt("werift-dtls : packages/dtls/src/flight/client/flight5.ts : log"),w7=class extends Jd{constructor(t,e,r,n){super(t,e,5,7),this.cipher=r,this.srtp=n}handleHandshake(t){this.dtls.bufferHandshakeCache([t],!1,4);let e=(()=>{switch(t.msg_type){case 2:return $8.deSerialize(t.fragment);case 11:return Qh.deSerialize(t.fragment);case 12:return X8.deSerialize(t.fragment);case 13:return K8.deSerialize(t.fragment);case 14:return W8.deSerialize(t.fragment)}})();e&&ou[e.msgType]({dtls:this.dtls,cipher:this.cipher,srtp:this.srtp})(e)}async exec(){if(this.dtls.flight===5){Pr(this.dtls.sessionId,"flight5 twice"),this.send(this.dtls.lastMessage);return}this.dtls.flight=5;let t=this.dtls.requestedCertificateTypes.length>0;Pr(this.dtls.sessionId,"send flight5",t);let e=[t&&this.sendCertificate(),this.sendClientKeyExchange(),t&&this.sendCertificateVerify(),this.sendChangeCipherSpec(),this.sendFinished()].filter(r=>r);this.dtls.lastMessage=e,await this.transmit(e)}sendCertificate(){let t=new Qh([Buffer.from(this.cipher.localCert)]),e=this.createPacket([t]);return Buffer.concat(e.map(n=>n.serialize()))}sendClientKeyExchange(){if(!this.cipher.localKeyPair)throw new Error;let t=new F8(this.cipher.localKeyPair.publicKey),e=this.createPacket([t]),r=Buffer.concat(e.map(a=>a.serialize())),n=this.cipher.localKeyPair,s=this.cipher.remoteKeyPair;if(!s.publicKey)throw new Error("not exist");let i=_8(s.publicKey,n.privateKey,n.curve);Pr(this.dtls.sessionId,"extendedMasterSecret",this.dtls.options.extendedMasterSecret,this.dtls.remoteExtendedMasterSecret);let o=Buffer.concat(this.dtls.sortedHandshakeCache.map(a=>a.serialize()));return this.cipher.masterSecret=this.dtls.options.extendedMasterSecret&&this.dtls.remoteExtendedMasterSecret?k8(i,o):B8(i,this.cipher.localRandom.serialize(),this.cipher.remoteRandom.serialize()),this.cipher.cipher=H8(this.cipher.cipherSuite),this.cipher.cipher.init(this.cipher.masterSecret,this.cipher.remoteRandom.serialize(),this.cipher.localRandom.serialize()),Pr(this.dtls.sessionId,"cipher",this.cipher.cipher.summary),r}sendCertificateVerify(){let t=Buffer.concat(this.dtls.sortedHandshakeCache.map(o=>o.serialize())),e=this.cipher.signatureData(t,"sha256"),r=(()=>{switch(this.cipher.signatureHashAlgorithm?.signature){case di.ecdsa_3:return O6.ecdsa_secp256r1_sha256;case di.rsa_1:return O6.rsa_pkcs1_sha256}})();if(!r)throw new Error;Pr(this.dtls.sessionId,"signatureScheme",this.cipher.signatureHashAlgorithm?.signature,r);let n=new z8(r,e),s=this.createPacket([n]);return Buffer.concat(s.map(o=>o.serialize()))}sendChangeCipherSpec(){let t=V8.createEmpty().serialize(),e=Zd(this.dtls)([{type:20,fragment:t}],++this.dtls.recordSequenceNumber);return Buffer.concat(e.map(n=>n.serialize()))}sendFinished(){let t=Buffer.concat(this.dtls.sortedHandshakeCache.map(i=>i.serialize())),e=this.cipher.verifyData(t),r=new J1(e);this.dtls.epoch=1;let[n]=this.createPacket([r]);this.dtls.recordSequenceNumber=0;let s=this.cipher.encryptPacket(n).serialize();return Pr(this.dtls.sessionId,"finished",this.cipher.cipher.summary),s}},ou={};ou[2]=({cipher:t,srtp:e,dtls:r})=>n=>{Pr(r.sessionId,"serverHello",n.cipherSuite),t.remoteRandom=Na.from(n.random),t.cipherSuite=n.cipherSuite,Pr(r.sessionId,"selected cipherSuite",t.cipherSuite),n.extensions&&n.extensions.forEach(s=>{switch(s.type){case Qc.type:{let i=Qc.fromData(s.data),o=Zh.findMatchingSRTPProfile(i.profiles,r.options.srtpProfiles||[]);if(Pr(r.sessionId,"selected srtp profile",o),o==null)return;e.srtpProfile=o}break;case lp.type:r.remoteExtendedMasterSecret=!0;break;case hp.type:Pr(r.sessionId,"RenegotiationIndication");break}})};ou[11]=({cipher:t,dtls:e})=>r=>{Pr(e.sessionId,"handshake certificate",r),t.remoteCertificate=r.certificateList[0]};ou[12]=({cipher:t,dtls:e})=>r=>{if(!t.localRandom||!t.remoteRandom)throw new Error;Pr(e.sessionId,"ServerKeyExchange",r),Pr(e.sessionId,"selected curve",r.namedCurve),t.remoteKeyPair={curve:r.namedCurve,publicKey:r.publicKey},t.localKeyPair=q8(r.namedCurve)};ou[13]=({dtls:t})=>e=>{Pr(t.sessionId,"certificate_request",e),t.requestedCertificateTypes=e.certificateTypes,t.requestedSignatureAlgorithms=e.signatures};ou[14]=({dtls:t})=>e=>{Pr(t.sessionId,"server_hello_done",e)};var A4=class Dd{constructor(e,r){this.serverVersion=e,this.cookie=r}msgType=3;messageSeq;static spec={serverVersion:Wg,cookie:Ua.types.buffer(Ua.types.uint8)};static createEmpty(){return new Dd(void 0,void 0)}static deSerialize(e){return new Dd(...Object.values((0,Ua.decode)(e,Dd.spec)))}serialize(){let e=(0,Ua.encode)(this,Dd.spec).slice();return Buffer.from(e)}get version(){return{major:255-this.serverVersion.major,minor:255-this.serverVersion.minor}}toFragment(){let e=this.serialize();return new yn(this.msgType,e.length,this.messageSeq,0,e.length,e)}},E7=tt("werift-dtls : packages/dtls/src/context/dtls.ts : log"),c3=class{constructor(t,e){this.options=t,this.sessionType=e}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(([t],[e])=>Number(t)-Number(e)).flatMap(([,{data:t}])=>t.sort((e,r)=>e.message_seq-r.message_seq))}checkHandshakesExist=t=>!t.find(e=>this.sortedHandshakeCache.find(r=>r.msg_type===e)==null);bufferHandshakeCache(t,e,r){this.handshakeCache[r]||(this.handshakeCache[r]={data:[],isLocal:e,flight:r});let n=t.filter(s=>{let i=this.handshakeCache[r].data.find(o=>o.msg_type===s.msg_type);return i?(E7(this.sessionId,"exist",i.summary,e,r),!1):!0});this.handshakeCache[r].data=[...this.handshakeCache[r].data,...n]}},A7=class{constructor(t){this.socket=t}send=t=>this.socket.send(t)},lg=class ii{static type=10;static spec={type:vs.types.uint16be,data:vs.types.array(vs.types.uint16be,vs.types.uint16be,"bytes")};type=ii.type;data=[];constructor(e={}){Object.assign(this,e)}static createEmpty(){return new ii}static fromData(e){return new ii({type:ii.type,data:(0,vs.decode)(e,ii.spec.data)})}static deSerialize(e){return new ii((0,vs.decode)(e,ii.spec))}serialize(){return Buffer.from((0,vs.encode)(this,ii.spec).slice())}get extension(){return{type:this.type,data:this.serialize().slice(2)}}},hg=class oo{static type=13;static spec={type:bs.types.uint16be,data:bs.types.array({hash:bs.types.uint8,signature:bs.types.uint8},bs.types.uint16be,"bytes")};type=oo.type;data=[];constructor(e={}){Object.assign(this,e)}static createEmpty(){return new oo}static deSerialize(e){return new oo((0,bs.decode)(e,oo.spec))}serialize(){let e=(0,bs.encode)(this,oo.spec).slice();return Buffer.from(e)}static fromData(e){let r=Buffer.alloc(2);return r.writeUInt16BE(oo.type),oo.deSerialize(Buffer.concat([r,e]))}get extension(){return{type:this.type,data:this.serialize().slice(2)}}},u3=class Nh{constructor(e,r){this.level=e,this.description=r}static spec={level:Da.types.uint8,description:Da.types.uint8};static deSerialize(e){return new Nh(...Object.values((0,Da.decode)(e,Nh.spec)))}serialize(){let e=(0,Da.encode)(this,Nh.spec).slice();return Buffer.from(e)}},f3=tt("werift-dtls : packages/dtls/record/receive.ts : log"),B1=tt("werift-dtls : packages/dtls/record/receive.ts : err"),C7=t=>{let e=0,r=[];for(;t.length>e;){let n=t.readUInt16BE(e+11);if(t.length<e+(12+n))break;let s=D8.deSerialize(t.subarray(e));r.push(s),e+=13+n}return r},I7=(t,e)=>r=>{switch(r.recordLayerHeader.contentType){case 20:return f3(t.sessionId,"change cipher spec"),[{type:20,data:void 0}];case 22:{let s=r.fragment;try{r.recordLayerHeader.epoch>0&&(f3(t.sessionId,"decrypt handshake"),s=e.decryptPacket(r))}catch(i){throw B1(t.sessionId,"decrypt failed",i),i}try{let i=0,o=[];for(;s.length>i;){let a=yn.deSerialize(s.subarray(i));o.push({type:22,data:a}),i+=a.fragment_length+12}return o}catch(i){throw B1(t.sessionId,"decSerialize failed",i,s),i}}case 23:return[{type:23,data:e.decryptPacket(r)}];case 21:{let s=u3.deSerialize(r.fragment);if(Y1[s.description]==null){let i=e.decryptPacket(r);s=u3.deSerialize(i)}if(B1(t.sessionId,"ContentType.alert",s,Y1[s.description],"flight",t.flight,"lastFlight",t.lastFlight),s.level>1)throw new Error("alert fatal error");return[{type:21,data:void 0}]}default:return[{type:21,data:void 0}]}},d3=tt("werift-dtls : packages/dtls/src/socket.ts : log"),l3=tt("werift-dtls : packages/dtls/src/socket.ts : err"),C4=class{constructor(t,e){this.options=t,this.sessionType=e,this.dtls=new c3(this.options,this.sessionType),this.cipher=new Yh(this.sessionType,this.options.cert,this.options.key,this.options.signatureHash),this.transport=new A7(this.options.transport),this.setupExtensions(),this.transport.socket.onData=this.udpOnMessage}onConnect=new be;onData=new be;onError=new be;onClose=new be;transport;cipher;dtls;srtp=new Zh;connected=!1;extensions=[];onHandleHandshakes;bufferFragmentedHandshakes=[];renegotiation(){d3("renegotiation",this.sessionType),this.connected=!1,this.cipher=new Yh(this.sessionType,this.options.cert,this.options.key,this.options.signatureHash),this.dtls=new c3(this.options,this.sessionType),this.srtp=new Zh,this.extensions=[],this.bufferFragmentedHandshakes=[]}udpOnMessage=t=>{let e=C7(t);for(let r of e)try{let n=I7(this.dtls,this.cipher)(r);for(let s of n)switch(s.type){case 22:{let i=s.data,o=this.handleFragmentHandshake([i]),a=Object.values(o.reduce((c,f)=>(c[f.msg_type]||(c[f.msg_type]=[]),c[f.msg_type].push(f),c),{})).map(c=>yn.assemble(c)).sort((c,f)=>c.msg_type-f.msg_type);this.onHandleHandshakes(a).catch(c=>{l3(this.dtls.sessionId,"onHandleHandshakes error",c),this.onError.execute(c)})}break;case 23:this.onData.execute(s.data);break;case 21:this.onClose.execute();break}}catch(n){l3(this.dtls.sessionId,"catch udpOnMessage error",n)}};setupExtensions(){if(d3(this.dtls.sessionId,"support srtpProfiles",this.options.srtpProfiles),this.options.srtpProfiles&&this.options.srtpProfiles.length>0){let t=Qc.create(this.options.srtpProfiles,Buffer.from([0]));this.extensions.push(t.extension)}{let t=lg.createEmpty();t.data=E8,this.extensions.push(t.extension)}{let t=hg.createEmpty();t.data=C8,this.extensions.push(t.extension)}this.options.extendedMasterSecret&&this.extensions.push({type:lp.type,data:Buffer.alloc(0)});{let t=hp.createEmpty();this.extensions.push(t.extension)}}waitForReady=t=>new Promise(async(e,r)=>{for(let n=0;n<10;n++)if(t()){e();break}else await S7(100*n);r("waitForReady timeout")});handleFragmentHandshake(t){let e=t.filter(r=>r.fragment_length!==r.length?(this.bufferFragmentedHandshakes.push(r),!1):!0);if(this.bufferFragmentedHandshakes.length>1){let[r]=this.bufferFragmentedHandshakes.slice(-1);r.fragment_offset+r.fragment_length===r.length&&(e=[...this.bufferFragmentedHandshakes,...e],this.bufferFragmentedHandshakes=[])}return e}send=async t=>{let e=Zd(this.dtls)([{type:23,fragment:t}],++this.dtls.recordSequenceNumber)[0];await this.transport.send(this.cipher.encryptPacket(e).serialize())};close(){this.transport.socket.close()}extractSessionKeys(t,e){let r=this.exportKeyingMaterial("EXTRACTOR-dtls_srtp",t*2+e*2),{clientKey:n,serverKey:s,clientSalt:i,serverSalt:o}=(0,_a.decode)(r,{clientKey:_a.types.buffer(t),serverKey:_a.types.buffer(t),clientSalt:_a.types.buffer(e),serverSalt:_a.types.buffer(e)});return this.sessionType===fi.CLIENT?{localKey:n,localSalt:i,remoteKey:s,remoteSalt:o}:{localKey:s,localSalt:o,remoteKey:n,remoteSalt:i}}exportKeyingMaterial(t,e){return GT(t,e,this.cipher.masterSecret,this.cipher.localRandom.serialize(),this.cipher.remoteRandom.serialize(),this.sessionType===fi.CLIENT)}get remoteCertificate(){return this.cipher.remoteCertificate}},k1=tt("werift-dtls : packages/dtls/src/client.ts : log"),h3=class extends C4{constructor(t){super(t,fi.CLIENT),this.onHandleHandshakes=this.handleHandshakes,k1(this.dtls.sessionId,"start client")}async connect(){await new d_(this.transport,this.dtls,this.cipher).exec(this.extensions)}flight5;handleHandshakes=async t=>{k1(this.dtls.sessionId,"handleHandshakes",t.map(e=>e.msg_type));for(let e of t)switch(e.msg_type){case 3:{let r=A4.deSerialize(e.fragment);await new h_(this.transport,this.dtls).exec(r)}break;case 2:{if(this.connected)return;this.flight5=new w7(this.transport,this.dtls,this.cipher,this.srtp),this.flight5.handleHandshake(e)}break;case 11:case 12:case 13:await this.waitForReady(()=>!!this.flight5),this.flight5?.handleHandshake(e);break;case 14:{await this.waitForReady(()=>!!this.flight5),this.flight5?.handleHandshake(e);let r=[11,12,this.options.certificateRequest&&13].filter(n=>typeof n=="number");await this.waitForReady(()=>this.dtls.checkHandshakesExist(r)),await this.flight5?.exec()}break;case 20:this.dtls.flight=7,this.connected=!0,this.onConnect.execute(),k1(this.dtls.sessionId,"dtls connected");break}}},ys=tt("werift-dtls : packages/dtls/flight/server/flight2.ts : log"),_7=(t,e,r,n)=>s=>{ys("dtls version",s.clientVersion),e.flight=2,e.recordSequenceNumber=0,e.sequenceNumber=0,s.extensions.forEach(p=>{switch(p.type){case lg.type:{let x=lg.fromData(p.data).data;ys(e.sessionId,"curves",x);let v=x.filter(S=>E8.includes(S))[0];r.namedCurve=v,ys(e.sessionId,"curve selected",r.namedCurve)}break;case hg.type:{if(!r.signatureHashAlgorithm)throw new Error("need to set certificate");let x=hg.fromData(p.data).data;ys(e.sessionId,"hash,signature",x);let v=x.find(I=>I.signature===r.signatureHashAlgorithm?.signature)?.signature,S=x.find(I=>I.hash===r.signatureHashAlgorithm?.hash)?.hash;if(v==null||S==null)throw new Error("invalid signatureHash")}break;case Qc.type:{if(!e.options?.srtpProfiles||e.options.srtpProfiles.length===0)return;let x=Qc.fromData(p.data);ys(e.sessionId,"srtp profiles",x.profiles);let v=Zh.findMatchingSRTPProfile(x.profiles,e.options?.srtpProfiles);if(!v)throw new Error;n.srtpProfile=v,ys(e.sessionId,"srtp profile selected",n.srtpProfile)}break;case lp.type:e.remoteExtendedMasterSecret=!0;break;case hp.type:ys(e.sessionId,"RenegotiationIndication",p.data);break;case 43:{let v=[...p.data.subarray(1)].map(S=>S.toString(10));ys("dtls supported version",v)}break}}),r.localRandom=new Na,r.remoteRandom=Na.from(s.random);let i=s.cipherSuites;ys(e.sessionId,"cipher suites",i);let o=(()=>{switch(r.signatureHashAlgorithm?.signature){case di.ecdsa_3:return $1.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256_49195;case di.rsa_1:return $1.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256_49199}})();if(o===void 0||!i.includes(o))throw new Error("dtls cipher suite negotiation failed");r.cipherSuite=o,ys(e.sessionId,"selected cipherSuite",r.cipherSuite),r.localKeyPair=q8(r.namedCurve),e.cookie||=T7(20);let a=new A4({major:254,minor:253},e.cookie),c=M8(e)([a]),l=Zd(e)(c.map(p=>({type:22,fragment:p.serialize()})),++e.recordSequenceNumber).map(p=>p.serialize());for(let p of l)t.send(p)},p3=tt("werift-dtls : packages/dtls/flight/server/flight4.ts : log"),B7=class extends Jd{constructor(t,e,r,n){super(t,e,4,6),this.cipher=r,this.srtp=n}async exec(t,e=!1){if(this.dtls.flight===4){p3(this.dtls.sessionId,"flight4 twice"),this.send(this.dtls.lastMessage);return}this.dtls.flight=4,this.dtls.sequenceNumber=1,this.dtls.bufferHandshakeCache([t],!1,4);let r=[this.sendServerHello(),this.sendCertificate(),this.sendServerKeyExchange(),e&&this.sendCertificateRequest(),this.sendServerHelloDone()].filter(n=>n);this.dtls.lastMessage=r,await this.transmit(r)}sendServerHello(){let t=[];this.srtp.srtpProfile&&t.push(Qc.create([this.srtp.srtpProfile],Buffer.from([0])).extension),this.dtls.options.extendedMasterSecret&&t.push({type:lp.type,data:Buffer.alloc(0)});let e=hp.createEmpty();t.push(e.extension);let r=new $8(this.dtls.version,this.cipher.localRandom,Buffer.from([0]),this.cipher.cipherSuite,0,t),n=this.createPacket([r]);return Buffer.concat(n.map(s=>s.serialize()))}sendCertificate(){let t=new Qh([Buffer.from(this.cipher.localCert)]),e=this.createPacket([t]);return Buffer.concat(e.map(r=>r.serialize()))}sendServerKeyExchange(){let t=this.cipher.generateKeySignature("sha256");if(!this.cipher.signatureHashAlgorithm)throw new Error("not exist");let e=new X8(A8.named_curve_3,this.cipher.namedCurve,this.cipher.localKeyPair.publicKey.length,this.cipher.localKeyPair.publicKey,this.cipher.signatureHashAlgorithm.hash,this.cipher.signatureHashAlgorithm.signature,t.length,t),r=this.createPacket([e]);return Buffer.concat(r.map(n=>n.serialize()))}sendCertificateRequest(){let t=new K8(zT,C8,[]);p3(this.dtls.sessionId,"sendCertificateRequest",t);let e=this.createPacket([t]);return Buffer.concat(e.map(r=>r.serialize()))}sendServerHelloDone(){let t=new W8,e=this.createPacket([t]);return Buffer.concat(e.map(r=>r.serialize()))}},nu=tt("werift-dtls : packages/dtls/flight/server/flight6.ts"),k7=class extends Jd{constructor(t,e,r){super(t,e,6),this.cipher=r}handleHandshake(t){this.dtls.bufferHandshakeCache([t],!1,5);let e=(()=>{switch(t.msg_type){case 11:return Qh.deSerialize(t.fragment);case 15:return z8.deSerialize(t.fragment);case 16:return F8.deSerialize(t.fragment);case 20:return J1.deSerialize(t.fragment)}})();if(e){let r=nl[e.msgType];if(!r)return;r({dtls:this.dtls,cipher:this.cipher})(e)}}async exec(){if(this.dtls.flight===6){nu(this.dtls.sessionId,"flight6 twice"),this.send(this.dtls.lastMessage);return}this.dtls.flight=6;let t=[this.sendChangeCipherSpec(),this.sendFinished()];this.dtls.lastMessage=t,await this.transmit(t)}sendChangeCipherSpec(){let t=V8.createEmpty().serialize(),e=Zd(this.dtls)([{type:20,fragment:t}],++this.dtls.recordSequenceNumber);return Buffer.concat(e.map(n=>n.serialize()))}sendFinished(){let t=Buffer.concat(this.dtls.sortedHandshakeCache.map(i=>i.serialize())),e=this.cipher.verifyData(t),r=new J1(e);this.dtls.epoch=1;let[n]=this.createPacket([r]);return this.dtls.recordSequenceNumber=0,this.cipher.encryptPacket(n).serialize()}},nl={};nl[16]=({cipher:t,dtls:e})=>r=>{if(t.remoteKeyPair={curve:t.namedCurve,publicKey:r.publicKey},!t.remoteKeyPair.publicKey||!t.localKeyPair||!t.remoteRandom||!t.localRandom)throw new Error("not exist");let n=_8(t.remoteKeyPair.publicKey,t.localKeyPair.privateKey,t.localKeyPair.curve);nu(e.sessionId,"extendedMasterSecret",e.options.extendedMasterSecret,e.remoteExtendedMasterSecret);let s=Buffer.concat(e.sortedHandshakeCache.map(i=>i.serialize()));t.masterSecret=e.options.extendedMasterSecret&&e.remoteExtendedMasterSecret?k8(n,s):B8(n,t.remoteRandom.serialize(),t.localRandom.serialize()),t.cipher=H8(t.cipherSuite),t.cipher.init(t.masterSecret,t.localRandom.serialize(),t.remoteRandom.serialize()),nu(e.sessionId,"setup cipher",t.cipher.summary)};nl[11]=({cipher:t,dtls:e})=>r=>{nu(e.sessionId,"handshake certificate",r),t.remoteCertificate=r.certificateList[0]};nl[15]=({cipher:t,dtls:e})=>r=>{if(!t.remoteCertificate)throw new Error("client certificate missing before certificate verify");nu(e.sessionId,"certificate_verify",r.algorithm)};nl[20]=({dtls:t})=>e=>{nu(t.sessionId,"finished",e)};var Fc=tt("werift-dtls : packages/dtls/src/server.ts : log"),R7=class extends C4{constructor(t){super(t,fi.SERVER),this.onHandleHandshakes=this.handleHandshakes,Fc(this.dtls.sessionId,"start server")}flight6;handleHandshakes=async t=>{Fc(this.dtls.sessionId,"handleHandshakes",t.map(e=>e.msg_type));for(let e of t)switch(e.msg_type){case 1:{this.connected&&this.renegotiation();let r=U8.deSerialize(e.fragment);r.cookie.length===0?(Fc(this.dtls.sessionId,"send flight2"),_7(this.transport,this.dtls,this.cipher,this.srtp)(r)):this.dtls.cookie&&r.cookie.equals(this.dtls.cookie)?(Fc(this.dtls.sessionId,"send flight4"),await new B7(this.transport,this.dtls,this.cipher,this.srtp).exec(e,this.options.certificateRequest)):Fc("wrong state",{dtlsCookie:this.dtls.cookie?.toString("hex").slice(10),helloCookie:r.cookie.toString("hex").slice(10)})}break;case 11:case 15:case 16:{if(this.connected)return;this.flight6=new k7(this.transport,this.dtls,this.cipher),this.flight6.handleHandshake(e)}break;case 20:{await this.waitForReady(()=>!!this.flight6),this.flight6?.handleHandshake(e);let r=[16,this.options.certificateRequest&&11,this.options.certificateRequest&&15].filter(n=>typeof n=="number");await this.waitForReady(()=>this.dtls.checkHandshakesExist(r)),await this.flight6?.exec(),this.connected=!0,this.onConnect.execute(),Fc(this.dtls.sessionId,"dtls connected")}break}}},Zg=554869826,N7=8,P7=1398035790,ao=20,I4=24,T4=1,_4=2,O7=6,L7=50,FZ=["FINGERPRINT","MESSAGE-INTEGRITY","CHANGE-REQUEST","PRIORITY","USERNAME","ICE-CONTROLLING","SOURCE-ADDRESS","USE-CANDIDATE","ICE-CONTROLLED","ERROR-CODE","XOR-MAPPED-ADDRESS","CHANGED-ADDRESS","LIFETIME","REQUESTED-TRANSPORT","NONCE","REALM","XOR-RELAYED-ADDRESS","CHANNEL-NUMBER","XOR-PEER-ADDRESS","DATA","SOFTWARE","MAPPED-ADDRESS","RESPONSE-ORIGIN","OTHER-ADDRESS"],B4=(t=>(t[t.REQUEST=0]="REQUEST",t[t.INDICATION=16]="INDICATION",t[t.RESPONSE=256]="RESPONSE",t[t.ERROR=272]="ERROR",t))(B4||{}),k4=(t=>(t[t.BINDING=1]="BINDING",t[t.SHARED_SECRET=2]="SHARED_SECRET",t[t.ALLOCATE=3]="ALLOCATE",t[t.REFRESH=4]="REFRESH",t[t.SEND=6]="SEND",t[t.DATA=7]="DATA",t[t.CREATE_PERMISSION=8]="CREATE_PERMISSION",t[t.CHANNEL_BIND=9]="CHANNEL_BIND",t))(k4||{});function wd(t){return N4(t).toString("hex").substring(0,t)}function P4(){return N4(12)}var x3=class{queue=[];wait=new be;put(t){this.queue.push(t),this.queue.length===1&&this.wait.execute(t)}get(){let t=this.queue.shift();return t||new Promise(e=>{this.wait.subscribe(r=>{this.queue.shift(),e(r)})})}},pg=t=>{let e,r,n=new Promise((i,o)=>{e=i,r=o});n.then(()=>{s.execute(void 0),s.complete()}).catch(i=>{s.execute(i??new Error),s.complete()});let s=new be;return t(e,r,s).catch(()=>{}),{awaitable:n,resolve:e,reject:r}};function Gc(t){let[e]=t,r=Wd.default.isV4Format(e)?T4:_4,n=Buffer.alloc(4);return n.writeUInt8(0,0),n.writeUInt8(r,1),n.writeUInt16BE(t[1],2),Buffer.concat([n,Wd.default.toBuffer(e)])}function U7(t){if(t.length<4)throw new Error("STUN error code is less than 4 bytes");let e=t.readUInt8(2),r=t.readUInt8(3),n=t.slice(4).toString("utf8");return[e*100+r,n]}function Xc(t){if(t.length<4)throw new Error("STUN address length is less than 4 bytes");let e=t.readUInt8(1),r=t.readUInt16BE(2),n=t.slice(4);switch(e){case T4:if(n.length!=4)throw new Error("STUN address has invalid length for IPv4");return[Wd.default.toString(n),r];case _4:if(n.length!=16)throw new Error("STUN address has invalid length for IPv6");return[Wd.default.toString(n),r];default:throw new Error("STUN address has unknown protocol")}}var Jg=Buffer.alloc(6);Jg.writeUInt16BE(Zg>>16,0);Jg.writeUInt32BE(Zg,2);function O4(t,e){let r=[...Jg,...e],n=t.slice(0,2);for(let s=2;s<t.length;s++){let i=t[s]^r[s-2],o=Buffer.alloc(1);o.writeUIntBE(i,0,1),n=Buffer.concat([n,o])}return n}function Ph(t,e){return Xc(O4(t,e))}function D7(t){let e=Buffer.alloc(4);e.writeUInt16BE(0,0),e.writeUInt8(Math.floor(t[0]/100),2),e.writeUInt8(t[0]%100,3);let r=Buffer.from(t[1],"utf8");return Buffer.concat([e,r])}function Oh(t,e){return O4(Gc(t),e)}var Sd=t=>{let e=Buffer.alloc(4);return e.writeUInt32BE(t,0),e},Ed=t=>t.readUInt32BE(0),M7=t=>{let e=Buffer.alloc(4);return e.writeUInt16BE(t,0),e},H7=t=>t.readUInt16BE(0),m3=t=>new d1(t.toString()).toBuffer(),g3=t=>{let e=new d1(t);return BigInt(e.toString())},R1=t=>Buffer.from(t,"utf8"),N1=t=>t.toString("utf8"),P1=t=>t,O1=t=>t,j7=t=>Buffer.from([]),q7=t=>null,L4=[[1,"MAPPED-ADDRESS",Gc,Xc],[3,"CHANGE-REQUEST",Sd,Ed],[4,"SOURCE-ADDRESS",Gc,Xc],[5,"CHANGED-ADDRESS",Gc,Xc],[6,"USERNAME",R1,N1],[8,"MESSAGE-INTEGRITY",P1,O1],[9,"ERROR-CODE",D7,U7],[12,"CHANNEL-NUMBER",M7,H7],[13,"LIFETIME",Sd,Ed],[18,"XOR-PEER-ADDRESS",Oh,Ph],[19,"DATA",P1,O1],[20,"REALM",R1,N1],[21,"NONCE",P1,O1],[22,"XOR-RELAYED-ADDRESS",Oh,Ph],[25,"REQUESTED-TRANSPORT",Sd,Ed],[32,"XOR-MAPPED-ADDRESS",Oh,Ph],[36,"PRIORITY",Sd,Ed],[37,"USE-CANDIDATE",j7,q7],[32802,"SOFTWARE",R1,N1],[32808,"FINGERPRINT",Sd,Ed],[32809,"ICE-CONTROLLED",m3,g3],[32810,"ICE-CONTROLLING",m3,g3],[32811,"RESPONSE-ORIGIN",Gc,Xc],[32812,"OTHER-ADDRESS",Gc,Xc]],U4=class{constructor(t=[]){this.attributes=t}getAttributes(){return this.attributes}setAttribute(t,e){let r=this.attributes.find(n=>n[0]===t);return r?r[1]=e:this.attributes.push([t,e]),this}getAttributeValue(t){let e=this.attributes.find(r=>r[0]===t);if(e)return e[1]}get attributesKeys(){return this.attributes.map(t=>t[0])}clear(){this.attributes=[]}},y3=L4.reduce((t,e)=>(t[e[0]]=e,t),{}),V7=L4.reduce((t,e)=>(t[e[1]]=e,t),{});function Qg(t,e){if(t.length<ao)return;let r=t.readUint16BE(2);if(t.length!==ao+r)return;let n=t.readUint16BE(0),s=Buffer.from(t.slice(ao-12,ao)),i=new U4;for(let a=ao;a<=t.length-4;){let c=t.readUInt16BE(a),f=t.readUInt16BE(a+2),l=t.slice(a+4,a+4+f),p=4*Math.floor((f+3)/4)-f;if(Object.keys(y3).includes(c.toString())){let[,v,,S]=y3[c];if(S.name===Ph.name?i.setAttribute(v,S(l,s)):i.setAttribute(v,S(l)),v==="FINGERPRINT"){let I=D4(t.slice(0,a));if(i.getAttributeValue("FINGERPRINT")!==I)return}else if(v==="MESSAGE-INTEGRITY"&&e){let I=z7(t.slice(0,a),e),L=i.getAttributeValue("MESSAGE-INTEGRITY");if(!I.equals(L))return}}a+=4+f+p}let o=i.getAttributes();return i.clear(),new jn(n&16111,n&272,s,o)}var jn=class extends U4{constructor(t,e,r=P4(),n=[]){super(n),this.messageMethod=t,this.messageClass=e,this.transactionId=r}toJSON(){return this.json}get json(){return{messageMethod:k4[this.messageMethod],messageClass:B4[this.messageClass],attributes:this.attributes}}get transactionIdHex(){return this.transactionId.toString("hex")}get bytes(){let t=Buffer.from([]);for(let r of this.attributesKeys){let n=this.getAttributeValue(r),[s,,i]=V7[r],o=i.name===Oh.name?i(n,this.transactionId):i(n),a=o.length,c=4*Math.floor((a+3)/4)-a,f=Buffer.alloc(4);f.writeUInt16BE(s,0),f.writeUInt16BE(a,2),t=Buffer.concat([t,f,o,Buffer.alloc(c,0)])}let e=Buffer.alloc(8);return e.writeUInt16BE(this.messageMethod|this.messageClass,0),e.writeUInt16BE(t.length,2),e.writeUInt32BE(Zg,4),Buffer.concat([e,this.transactionId,t])}addMessageIntegrity(t){return this.setAttribute("MESSAGE-INTEGRITY",this.messageIntegrity(t)),this}messageIntegrity(t){let e=ey(this.bytes,this.bytes.length-ao+I4);return Buffer.from(R4("sha1",t).update(e).digest("hex"),"hex")}addFingerprint(){this.setAttribute("FINGERPRINT",D4(this.bytes))}},ey=(t,e)=>{let r=Buffer.alloc(t.length);return t.copy(r,0,0,2),r.writeUInt16BE(e,2),t.copy(r,4,4),r};function D4(t){let e=ey(t,t.length-ao+N7);return(RT(e)^P7)>>>0}function z7(t,e){let r=ey(t,t.length-ao+I4);return Buffer.from(R4("sha1",e).update(r).digest("hex"),"hex")}function b3(t){let e=t%4;return e===0?0:4-e}var M4=class extends Error{response;addr},H4=class extends M4{constructor(t,e){super(),this.response=t,this.addr=e}get str(){let t="STUN transaction failed",e=this.response.getAttributeValue("ERROR-CODE");if(e){let[r,n]=e;t+=` (${r} - ${n})`}return t}},F7=class extends M4{get str(){return"STUN transaction timed out"}},L1=tt("werift-ice:packages/ice/src/stun/transaction.ts"),ty=class{constructor(t,e,r,n){this.request=t,this.addr=e,this.protocol=r,this.retransmissions=n,this.triesMax=1+(this.retransmissions?this.retransmissions:O7)}timeoutDelay=L7;ended=!1;tries=0;triesMax;onResponse=new be;responseReceived=(t,e)=>{this.onResponse.length>0&&(t.messageClass===256?(this.onResponse.execute(t,e),this.onResponse.complete()):this.onResponse.error(new H4(t,e)))};run=async()=>{try{return this.retry().catch(e=>{L1("retry failed",e)}),await this.onResponse.asPromise()}catch(t){throw t}finally{this.cancel()}};retry=async()=>{for(;this.tries<this.triesMax&&!this.ended&&(this.protocol.sendStun(this.request,this.addr).catch(t=>{L1("send stun failed",t)}),await new Promise(t=>setTimeout(t,this.timeoutDelay)),!this.ended);)this.timeoutDelay*=2,this.tries++;this.tries>=this.triesMax&&(L1(`retry failed times:${this.tries} maxLimit:${this.triesMax}`),this.onResponse.error(new F7))};cancel(){this.ended=!0}},v3=tt("werift-ice : packages/ice/src/stun/protocol.ts"),xg=class j4{static type="stun";type=j4.type;transport;transactions={};get transactionsKeys(){return Object.keys(this.transactions)}localCandidate;sentMessage;localIp;onRequestReceived=new be;onDataReceived=new be;constructor(){}connectionMade=async(e,r,n)=>{e?this.transport=await K1.init("udp4",{portRange:r,interfaceAddresses:n}):this.transport=await K1.init("udp6",{portRange:r,interfaceAddresses:n}),this.transport.onData=(s,i)=>{this.datagramReceived(s,i)}};datagramReceived(e,r){try{let n=Qg(e);if(!n){this.localCandidate&&this.onDataReceived.execute(e);return}(n.messageClass===256||n.messageClass===272)&&this.transactionsKeys.includes(n.transactionIdHex)?this.transactions[n.transactionIdHex].responseReceived(n,r):n.messageClass===0&&this.onRequestReceived.execute(n,r,e)}catch(n){v3("datagramReceived error",n)}}getExtraInfo(){let{address:e,port:r}=this.transport.address;return[e,r]}async sendStun(e,r){if(this.transport.closed)return;let n=e.bytes;await this.transport.send(n,r).catch(()=>{v3("sendStun failed",r,e)})}async sendData(e,r){this.transport.closed||await this.transport.send(e,r)}async request(e,r,n,s){if(this.transactionsKeys.includes(e.transactionIdHex))throw new Error("already request ed");n&&(e.addMessageIntegrity(n),e.addFingerprint());let i=new ty(e,r,this,s);this.transactions[e.transactionIdHex]=i;try{return await i.run()}catch(o){throw o}finally{delete this.transactions[e.transactionIdHex]}}async close(){Object.values(this.transactions).forEach(e=>{e.cancel()}),await this.transport.close(),this.onRequestReceived.complete(),this.onDataReceived.complete()}},$r=tt("werift-ice:packages/ice/src/turn/protocol.ts"),W7=500,G7=600,X7=285212672,Y7=class q4{constructor(e){this.turn=e,e.onData.subscribe((r,n)=>{this.handleStunMessage(r,n)}).disposer(this.disposer)}static type="turn";type=q4.type;localCandidate;disposer=new LT;onRequestReceived=new be;onDataReceived=new be;handleStunMessage=(e,r)=>{try{let n=Qg(e);if(!n){this.onDataReceived.execute(e);return}if(n.messageClass===256||n.messageClass===272){let s=this.turn.transactions[n.transactionIdHex];s&&s.responseReceived(n,r)}else n.messageClass===0&&this.onRequestReceived.execute(n,r,e)}catch(n){$r("datagramReceived error",n)}};async request(e,r,n){if(this.turn.transactions[e.transactionIdHex])throw new Error("exist");n&&(e.addMessageIntegrity(n),e.addFingerprint());let s=new ty(e,r,this);this.turn.transactions[e.transactionIdHex]=s;try{return await s.run()}catch(i){throw i}finally{delete this.turn.transactions[e.transactionIdHex]}}async connectionMade(){}async sendData(e,r){await this.turn.sendData(e,r)}async sendStun(e,r){await this.turn.sendData(e.bytes,r)}async close(){return this.disposer.dispose(),this.turn.close()}},Z7=class V4{constructor(e,r,n,s,i,o={}){this.server=e,this.username=r,this.password=n,this.lifetime=s,this.transport=i,this.options=o,this.channelRefreshTime=this.options.channelRefreshTime??W7}static type="turn";type=V4.type;onData=new be;onRequestReceived=new be;onDataReceived=new be;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=(s,i)=>{this.dataReceived(s,i)};let e=new jn(3,0);e.setAttribute("LIFETIME",this.lifetime).setAttribute("REQUESTED-TRANSPORT",X7);let[r]=await this.requestWithRetry(e,this.server).catch(s=>{throw $r("connect error",s),s});this.relayedAddress=r.getAttributeValue("XOR-RELAYED-ADDRESS"),this.mappedAddress=r.getAttributeValue("XOR-MAPPED-ADDRESS");let n=r.getAttributeValue("LIFETIME");$r("connect",this.relayedAddress,this.mappedAddress,{exp:n}),this.refresh(n)}handleChannelData(e){let[r,n]=mg.jspack.Unpack("!HH",e.slice(0,4)),s=this.addrByChannel[r];if(s){let i=e.subarray(4,4+n);this.onData.execute(i,s)}}handleSTUNMessage(e,r){try{let n=Qg(e);if(!n)throw new Error("not stun message");if(n.messageClass===256||n.messageClass===272){let s=this.transactions[n.transactionIdHex];s&&s.responseReceived(n,r)}else n.messageClass===0&&this.onData.execute(e,r);if(n.getAttributeValue("DATA")){let s=n.getAttributeValue("DATA");this.onData.execute(s,r)}}catch{$r("parse error",e.toString())}}dataReceived(e,r){let n=(s,i)=>{s.length>=4&&S3(s)?this.handleChannelData(s):this.handleSTUNMessage(s,i)};if(this.transport.type==="tcp")for(this.tcpBuffer=Buffer.concat([this.tcpBuffer,e]);this.tcpBuffer.length>=4;){let[,s]=Wr(this.tcpBuffer.subarray(0,4),[2,2]);s+=b3(s);let i=S3(this.tcpBuffer)?4+s:20+s;if(this.tcpBuffer.length<i)break;n(this.tcpBuffer.subarray(0,i),r),this.tcpBuffer=this.tcpBuffer.subarray(i)}else n(e,r)}async send(e,r){if(!this.transport.closed)if(this.transport.type==="tcp"){let n=b3(e.length);await this.transport.send(n>0?Buffer.concat([e,Buffer.alloc(n)]):e,r)}else await this.transport.send(e,r)}async createPermission(e){let r=new jn(8,0);r.setAttribute("XOR-PEER-ADDRESS",e).setAttribute("USERNAME",this.username).setAttribute("REALM",this.realm).setAttribute("NONCE",this.nonce),await this.request(r,this.server).catch(n=>{throw n})}refresh=e=>{this.refreshHandle=pg(async(r,n,s)=>{let i=!0;for(s.once(()=>{i=!1});i;){let o=.8333333333333334*e*1e3;$r("refresh delay",o,{exp:e}),await $7(o);let a=new jn(4,0);a.setAttribute("LIFETIME",e);try{let[c]=await this.requestWithRetry(a,this.server);e=c.getAttributeValue("LIFETIME"),$r("refresh",{exp:e})}catch(c){$r("refresh error",c)}}})};async request(e,r){if(this.transactions[e.transactionIdHex])throw new Error("exist");this.integrityKey&&e.setAttribute("USERNAME",this.username).setAttribute("REALM",this.realm).setAttribute("NONCE",this.nonce).addMessageIntegrity(this.integrityKey).addFingerprint();let n=new ty(e,r,this);this.transactions[e.transactionIdHex]=n;try{return await n.run()}catch(s){throw s}finally{delete this.transactions[e.transactionIdHex]}}async requestWithRetry(e,r){let n,s;try{[n,s]=await this.request(e,r)}catch(i){if(!(i instanceof H4))throw $r("requestWithRetry error",i),i;this.server=i.addr;let[o]=i.response.getAttributeValue("ERROR-CODE"),a=i.response.getAttributeValue("NONCE"),c=i.response.getAttributeValue("REALM");if((o===401&&c||o===438&&this.realm)&&a)$r("retry with nonce",o),this.nonce=a,o===401&&(this.realm=c),this.integrityKey=Q7(this.username,this.realm,this.password),e.transactionId=P4(),[n,s]=await this.request(e,this.server);else throw i}return[n,s]}async sendData(e,r){let n=await this.getChannel(r).catch(i=>new Error("channelBind error"));if(n instanceof Error){await this.getPermission(r);let i=new jn(6,16).setAttribute("DATA",e).setAttribute("XOR-PEER-ADDRESS",r);await this.sendStun(i,this.server);return}let s=mg.jspack.Pack("!HH",[n.number,e.length]);await this.send(Buffer.concat([Buffer.from(s),e]),this.server)}async getPermission(e){await this.creatingPermission,this.permissionByAddr[e.join(":")]||(this.creatingPermission=this.createPermission(e),this.permissionByAddr[e.join(":")]=!0,await this.creatingPermission.catch(n=>{throw $r("createPermission error",n),n}))}async getChannel(e){this.channelBinding&&await this.channelBinding;let r=this.channelByAddr[e.join(":")];return r?this.channelRefreshAt<jd(Date.now()/1e3)&&(this.channelBinding=this.channelBind(r.number,e),this.channelRefreshAt=jd(Date.now()/1e3)+this.channelRefreshTime,await this.channelBinding.catch(n=>{throw $r("channelBind error",n),n}),this.channelBinding=void 0,$r("channelBind refresh",r)):(this.channelByAddr[e.join(":")]={number:this.channelNumber++,address:e},r=this.channelByAddr[e.join(":")],this.addrByChannel[r.number]=e,this.channelBinding=this.channelBind(r.number,e),await this.channelBinding.catch(n=>{throw $r("channelBind error",n),n}),this.channelRefreshAt=jd(Date.now()/1e3)+this.channelRefreshTime,this.channelBinding=void 0,$r("channelBind",r)),r}async channelBind(e,r){let n=new jn(9,0);n.setAttribute("CHANNEL-NUMBER",e).setAttribute("XOR-PEER-ADDRESS",r);let[s]=await this.requestWithRetry(n,this.server);if(s.messageMethod!==9)throw new Error("should be CHANNEL_BIND")}async sendStun(e,r){await this.send(e.bytes,r)}async close(){this.refreshHandle?.resolve?.(),await this.transport.close()}};async function J7({address:t,username:e,password:r},{lifetime:n,portRange:s,interfaceAddresses:i,transport:o}={}){n??=G7,o??="udp";let a=o==="udp"?await K1.init("udp4",{portRange:s,interfaceAddresses:i}):await MT.init(t),c=new Z7(t,e,r,n,a);return await c.connectionMade(),c}async function w3({address:t,username:e,password:r},{lifetime:n,portRange:s,interfaceAddresses:i,transport:o}={}){let a=await J7({address:t,username:e,password:r},{lifetime:n,portRange:s,interfaceAddresses:i,transport:o});return new Y7(a)}function Q7(t,e,r){return K7("md5").update(Buffer.from([t,e,r].join(":"))).digest()}function S3(t){return(t[0]&192)==64}var ka=class z4{constructor(e,r,n,s,i,o,a,c,f,l,p,x){this.foundation=e,this.component=r,this.transport=n,this.priority=s,this.host=i,this.port=o,this.type=a,this.relatedAddress=c,this.relatedPort=f,this.tcptype=l,this.generation=p,this.ufrag=x}static fromSdp(e){let r=e.split(" ");if(r.length<8)throw new Error("SDP does not have enough properties");let n={foundation:r[0],component:Number(r[1]),transport:r[2],priority:Number(r[3]),host:r[4],port:Number(r[5]),type:r[7]};for(let p=8,x=r.length-1;p<x;p+=2)r[p]==="raddr"?n.related_address=r[p+1]:r[p]==="rport"?n.related_port=Number(r[p+1]):r[p]==="tcptype"?n.tcptype=r[p+1]:r[p]==="generation"?n.generation=Number(r[p+1]):r[p]==="ufrag"&&(n.ufrag=r[p+1]);let{foundation:s,component:i,transport:o,priority:a,host:c,port:f,type:l}=n;return new z4(s,i,o,a,c,f,l,n.related_address,n.related_port,n.tcptype,n.generation,n.ufrag)}canPairWith(e){let r=E3(this.host),n=E3(e.host);return this.component===e.component&&this.transport.toLowerCase()===e.transport.toLowerCase()&&r===n}toSdp(){let e=`${this.foundation} ${this.component} ${this.transport} ${this.priority} ${this.host} ${this.port} typ ${this.type}`;return this.relatedAddress&&(e+=` raddr ${this.relatedAddress}`),this.relatedPort!=null&&(e+=` rport ${this.relatedPort}`),this.tcptype&&(e+=` tcptype ${this.tcptype}`),this.generation!=null&&(e+=` generation ${this.generation}`),this.ufrag!=null&&(e+=` ufrag ${this.ufrag}`),e}};function gg(t,e,r){let n=`${t}|${e}|${r}`;return eB("md5").update(n,"ascii").digest("hex").slice(7)}function Lh(t,e=65535){let n=0;return t==="host"?n=126:t==="prflx"?n=110:t==="srflx"?n=100:n=0,(1<<24)*n+256*e+255}var rB=class{cache=new Map;mdnsInstance=(0,F4.default)();constructor(){this.mdnsInstance.setMaxListeners(50)}lookup(t){return new Promise((e,r)=>{let n=()=>{this.mdnsInstance.removeListener("response",i),clearTimeout(s)},s=setTimeout(()=>{n(),r(new Error("No mDNS response"))},1e4),i=o=>{let a=o.answers?.[0];a?.type==="A"&&a.name===t&&(n(),e(a.data))};this.mdnsInstance.on("response",i),this.mdnsInstance.query(t,"A")})}close(){this.mdnsInstance.destroy()}},sB=tt("werift-ice : packages/ice/src/ice.ts : log"),C3=class{constructor(t,e,r){this.protocol=t,this.remoteCandidate=e,this.iceControlling=r}id=nB().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(t){this._state=t}get localCandidate(){if(!this.protocol.localCandidate)throw new 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 bg(this.localCandidate,this.remoteCandidate,this.iceControlling)}get foundation(){return this.localCandidate.foundation}},I3=1,Eh=2,iB=5,T3=6,oB=(t=>(t[t.FROZEN=0]="FROZEN",t[t.WAITING=1]="WAITING",t[t.IN_PROGRESS=2]="IN_PROGRESS",t[t.SUCCEEDED=3]="SUCCEEDED",t[t.FAILED=4]="FAILED",t))(oB||{}),aB={useIpv4:!0,useIpv6:!0};function _3(t){if(!["host","relay","srflx"].includes(t.type))throw new Error(`Unexpected candidate type "${t.type}"`);return t}function cB(t,e){return t.sort((r,n)=>bg(r.localCandidate,r.remoteCandidate,e)-bg(n.localCandidate,n.remoteCandidate,e)).reverse()}function bg(t,e,r){let n=r&&t.priority||e.priority,s=r&&e.priority||t.priority;return 1*Math.min(n,s)+2*Math.max(n,s)+(n>s?1:0)}async function uB(t,e){let r=new jn(1,0);try{let[n]=await t.request(r,e),s=t.localCandidate;if(!s)throw new Error("not exist");return new ka(gg("srflx","udp",s.host),s.component,s.transport,Lh("srflx"),n.getAttributeValue("XOR-MAPPED-ADDRESS")[0],n.getAttributeValue("XOR-MAPPED-ADDRESS")[1],"srflx",s.host,s.port)}catch(n){sB("error serverReflexiveCandidate",n)}}function B3(t){return t&&Number.isNaN(t[1])?[t[0],443]:t}var fB=tt("werift-ice : packages/ice/src/utils.ts");async function eJ(t,e){let r=new xg;await r.connectionMade(!0,void 0,e);let n=new jn(1,0),[s]=await r.request(n,t??["stun.l.google.com",19302]);return await r.close(),s.getAttributeValue("XOR-MAPPED-ADDRESS")[0]}function dB(t){return Gh(t.family)===4&&t.address?.startsWith("169.254.")||Gh(t.family)===6&&t.address?.startsWith("fe80::")}function k3(t,{useLinkLocalAddress:e}={}){let r=["ipsec","tun","utun","tap"],n=["vmnet","veth"],s=K4.networkInterfaces();fB(s);let i=Object.keys(s).map(o=>{for(let c of[...r,...n])if(o.startsWith(c))return{nic:o,addresses:[]};let a=s[o].filter(c=>Gh(c.family)===t&&!$4.default.isLoopback(c.address)&&(e?!0:!dB(c)));return{nic:o,addresses:a.map(c=>c.address)}}).filter(o=>!!o);return i.sort((o,a)=>o.nic.localeCompare(a.nic)),Object.values(i).flatMap(o=>o.addresses)}function lB(t,e,r={}){let n=[];return t&&n.push(...k3(4,r)),e&&n.push(...k3(6,r)),n}var tJ=t=>{if(!t)return;let[e,r]=t.split(":");return[e,Number.parseInt(r)]},Tt=tt("werift-ice : packages/ice/src/ice.ts : log"),hB=class{constructor(t,e){this._iceControlling=t,this.options={...aB,...e};let{stunServer:r,turnServer:n}=this.options;this.stunServer=B3(r)??["stun.l.google.com",19302],this.turnServer=B3(n),this.restart(),Tt("new Connection",this.options)}localUsername=wd(4);localPassword=wd(22);remoteIsLite=!1;remotePassword="";remoteUsername="";checkList=[];localCandidates=[];stunServer;turnServer;options;remoteCandidatesEnd=!1;localCandidatesEnd=!1;generation=-1;userHistory={};tieBreaker=BigInt(new bh(tB(64)).toString());state="new";lookup;_remoteCandidates=[];nominated;nominating=!1;checkListDone=!1;checkListState=new x3;earlyChecks=[];earlyChecksDone=!1;localCandidatesStart=!1;protocols=[];queryConsentHandle;onData=new be;stateChanged=new be;onIceCandidate=new be;get iceControlling(){return this._iceControlling}set iceControlling(t){if(!(this.generation>0||this.nominated)){this._iceControlling=t;for(let e of this.checkList)e.iceControlling=t}}async restart(){this.generation++,this.localUsername=wd(4),this.localPassword=wd(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 x3,this.earlyChecks=[],this.earlyChecksDone=!1,this.localCandidatesStart=!1;for(let t of this.protocols)t.localCandidate&&(t.localCandidate.generation=this.generation,t.localCandidate.ufrag=this.localUsername);this.queryConsentHandle?.resolve?.(),this.queryConsentHandle=void 0}resetNominatedPair(){Tt("resetNominatedPair"),this.nominated=void 0,this.nominating=!1}setRemoteParams({iceLite:t,usernameFragment:e,password:r}){Tt("setRemoteParams",{iceLite:t,usernameFragment:e,password:r}),this.remoteIsLite=t,this.remoteUsername=e,this.remotePassword=r}async gatherCandidates(){if(!this.localCandidatesStart){this.localCandidatesStart=!0;let t=lB(this.options.useIpv4,this.options.useIpv6,{useLinkLocalAddress:this.options.useLinkLocalAddress}),{interfaceAddresses:e}=this.options;if(e){let n=t.filter(s=>Object.values(e).includes(s));n.length&&(t=n)}this.options.additionalHostAddresses&&(t=Array.from(new Set([...this.options.additionalHostAddresses,...t])));let r=this.getCandidatePromises(t,5);await Promise.allSettled(r),this.localCandidatesEnd=!0}this.setState("completed")}appendLocalCandidate(t){this.localCandidates.push(t),this.onIceCandidate.execute(t)}ensureProtocol(t){t.onRequestReceived.subscribe((e,r,n)=>{if(e.messageMethod!==1){this.respondError(e,r,t,[400,"Bad Request"]);return}let s=e.getAttributeValue("USERNAME"),{remoteUsername:i}=R3(s),o=this.userHistory[i]??this.localPassword,{iceControlling:a}=this;if(a&&e.attributesKeys.includes("ICE-CONTROLLING"))if(this.tieBreaker>=e.getAttributeValue("ICE-CONTROLLING")){this.respondError(e,r,t,[487,"Role Conflict"]);return}else this.switchRole(!1);else if(!a&&e.attributesKeys.includes("ICE-CONTROLLED"))if(this.tieBreaker<e.getAttributeValue("ICE-CONTROLLED"))this.respondError(e,r,t,[487,"Role Conflict"]);else{this.switchRole(!0);return}if(this.options.filterStunResponse&&!this.options.filterStunResponse(e,r,t))return;let c=new jn(1,256,e.transactionId);c.setAttribute("XOR-MAPPED-ADDRESS",r).addMessageIntegrity(Buffer.from(o,"utf8")).addFingerprint(),t.sendStun(c,r).catch(f=>{Tt("sendStun error",f)}),this.checkList.length===0&&!this.earlyChecksDone?this.earlyChecks.push([e,r,t]):this.checkIncoming(e,r,t)}),t.onDataReceived.subscribe(e=>{try{let r=this.nominated;r&&r.protocol===t&&(r.packetsReceived++,r.bytesReceived+=e.length),this.onData.execute(e)}catch(r){Tt("dataReceived",r)}})}getCandidatePromises(t,e=5){let r=[];t=t.filter(c=>!this.protocols.find(f=>f.localIp===c));let n=t.map(async c=>{let f=new xg;this.ensureProtocol(f);try{await f.connectionMade(A3(c),this.options.portRange,this.options.interfaceAddresses),f.localIp=c,this.protocols.push(f),Tt("protocol",f.localIp);let l=[c,f.getExtraInfo()[1]];return f.localCandidate=new ka(gg("host","udp",l[0]),1,"udp",Lh("host"),l[0],l[1],"host",void 0,void 0,void 0,this.generation,this.localUsername),this.pairLocalProtocol(f),this.appendLocalCandidate(f.localCandidate),f}catch(l){Tt("error protocol STUN",l)}});r.push(...n.map(c=>c.then(f=>f?.localCandidate)));let{stunServer:s,turnServer:i}=this;if(s){let c=n.map(async f=>{let l=await f;return l?new Promise(async(x,v)=>{let S=setTimeout(v,e*1e3);if(l.localCandidate?.host&&A3(l.localCandidate?.host)){let I=await uB(l,s).catch(L=>{Tt("error",L)});I&&this.appendLocalCandidate(I),clearTimeout(S),x(I)}else clearTimeout(S),x()}).catch(x=>{Tt("query STUN server",x)}):void 0});r.push(...c)}let{turnUsername:o,turnPassword:a}=this.options;if(i&&o&&a){let c=(async()=>{let f=await w3({address:i,username:o,password:a},{portRange:this.options.portRange,interfaceAddresses:this.options.interfaceAddresses,transport:this.options.turnTransport==="tcp"?"tcp":"udp"}).catch(async x=>{if(this.options.turnTransport!=="tcp")return await w3({address:i,username:o,password:a},{portRange:this.options.portRange,interfaceAddresses:this.options.interfaceAddresses,transport:"tcp"});throw x});this.ensureProtocol(f),this.protocols.push(f);let l=f.turn.relayedAddress,p=f.turn.mappedAddress;return Tt("turn candidateAddress",l),f.localCandidate=new ka(gg("relay","udp",l[0]),1,"udp",Lh("relay"),l[0],l[1],"relay",p[0],p[1],void 0,this.generation,this.localUsername),this.appendLocalCandidate(f.localCandidate),f.localCandidate})().catch(f=>{Tt("query TURN server",f)});this.options.forceTurn&&(r=[]),r.push(c)}return r}async connect(){if(Tt("start connect ice"),!this.localCandidatesEnd&&!this.localCandidatesStart)throw new Error("Local candidates gathering was not performed");if(!this.remoteUsername||!this.remotePassword)throw new Error("Remote username or password is missing");for(let e of this.remoteCandidates)this.pairRemoteCandidate(e);this.sortCheckList(),this.unfreezeInitial(),Tt("earlyChecks",this.localPassword,this.earlyChecks.length);for(let e of this.earlyChecks)this.checkIncoming(...e);for(this.earlyChecks=[],this.earlyChecksDone=!0;!(this.state==="closed"||!this.schedulingChecks());)await yg.setTimeout(20);let t=Eh;for(;this.checkList.length>0&&t===Eh;)t=await this.checkListState.get(),Tt("checkListState",t);for(let e of this.checkList)e.handle?.resolve?.();if(t!==I3)throw new Error("ICE negotiation failed");this.queryConsent(),this.setState("connected")}unfreezeInitial(){let[t]=this.checkList;if(!t)return;t.state===0&&t.updateState(1);let e=new Set(t.localCandidate.foundation);for(let r of this.checkList)r.component===t.component&&!e.has(r.localCandidate.foundation)&&r.state===0&&(r.updateState(1),e.add(r.localCandidate.foundation))}schedulingChecks(){{let t=this.checkList.filter(e=>!(this.options.forceTurn&&e.protocol.type===xg.type)).find(e=>e.state===1);if(t)return t.handle=this.checkStart(t),!0}{let t=this.checkList.find(e=>e.state===0);if(t)return t.handle=this.checkStart(t),!0}return this.remoteCandidatesEnd?!1:!this.checkListDone}queryConsent=()=>{this.queryConsentHandle&&this.queryConsentHandle.resolve(),this.queryConsentHandle=pg(async(t,e,r)=>{let n=0,s=!1,i=new AbortController;r.once(()=>{s=!0,n+=T3,i.abort(),this.queryConsentHandle=void 0});let{localUsername:o,remoteUsername:a,iceControlling:c}=this;try{for(;this.state!=="closed"&&!s;){await yg.setTimeout(iB*(.8+.4*Math.random())*1e3,void 0,{signal:i.signal});let f=this.nominated;if(!f||s)break;let l=this.buildRequest({nominate:!1,localUsername:o,remoteUsername:a,iceControlling:c});try{await f.protocol.request(l,f.remoteAddr,Buffer.from(this.remotePassword,"utf8"),0),n=0,this.state==="disconnected"&&this.setState("connected")}catch{if(f.id===this.nominated?.id){Tt("no stun response"),n++,this.setState("disconnected");break}}if(n>=T3){Tt("Consent to send expired"),this.queryConsentHandle=void 0,this.setState("closed");break}}}catch{}})};async close(){this.setState("closed"),this.queryConsentHandle?.resolve?.(),this.checkList&&!this.checkListDone&&this.checkListState.put(new Promise(t=>{t(Eh)})),this.nominated=void 0;for(let t of this.protocols)t.close&&await t.close();this.protocols=[],this.localCandidates=[],this.lookup?.close?.(),this.lookup=void 0}setState(t){this.state=t,this.stateChanged.execute(t)}async addRemoteCandidate(t){if(!t){this.remoteCandidatesEnd=!0;return}if(t.host.includes(".local"))try{this.lookup||(this.lookup=new rB);let e=await this.lookup.lookup(t.host);t.host=e}catch{return}try{_3(t)}catch{return}Tt("addRemoteCandidate",t),this._remoteCandidates.push(t),this.pairRemoteCandidate(t),this.sortCheckList()}send=async t=>{let e=this.nominated;if(e)await e.protocol.sendData(t,e.remoteAddr),e.packetsSent++,e.bytesSent+=t.length;else return};getDefaultCandidate(){let t=this.localCandidates.sort((r,n)=>r.priority-n.priority),[e]=t;return e}set remoteCandidates(t){if(this.remoteCandidatesEnd)throw new Error("Cannot set remote candidates after end-of-candidates.");this._remoteCandidates=[];for(let e of t){try{_3(e)}catch{continue}this._remoteCandidates.push(e)}this.remoteCandidatesEnd=!0}get remoteCandidates(){return this._remoteCandidates}get candidatePairs(){return this.checkList}sortCheckList(){cB(this.checkList,this.iceControlling)}findPair(t,e){return this.checkList.find(n=>(0,Uh.default)(n.protocol,t)&&(0,Uh.default)(n.remoteCandidate,e))}switchRole(t){Tt("switch role",t),this.iceControlling=t,this.sortCheckList()}checkComplete(t){if(t.handle=void 0,t.state===3){if(t.nominated&&(t.remoteCandidate.generation==null||t.remoteCandidate.generation===this.generation)&&this.nominated==null){Tt("nominated",t.toJSON()),this.nominated=t,this.nominating=!1;for(let e of this.checkList)e.component===t.component&&[1,0].includes(e.state)&&e.updateState(4)}if(this.nominated){this.checkListDone||(Tt("ICE completed"),this.checkListState.put(new Promise(e=>e(I3))),this.checkListDone=!0);return}Tt("not completed",t.toJSON());for(let e of this.checkList)e.localCandidate.foundation===t.localCandidate.foundation&&e.state===0&&e.updateState(1)}{let e=[3,4];if(this.checkList.find(({state:r})=>!e.includes(r)))return}!this.iceControlling&&this.checkList.find(({state:r})=>r===3)||this.checkListDone||(Tt("ICE failed"),this.checkListState.put(new Promise(e=>{e(Eh)})))}checkStart=t=>pg(async e=>{Tt("check start",t.toJSON()),t.updateState(2);let r={},{remotePassword:n,remoteUsername:s,generation:i}=this,o=t.localCandidate.ufrag??this.localUsername,a=this.iceControlling&&!this.remoteIsLite,c=this.buildRequest({nominate:a,localUsername:o,remoteUsername:s,iceControlling:this.iceControlling}),f=performance.now();try{let[l,p]=await t.protocol.request(c,t.remoteAddr,Buffer.from(n,"utf8"),4),v=(performance.now()-f)/1e3;t.rtt=v,t.totalRoundTripTime+=v,t.roundTripTimeMeasurements++,Tt("response received",c.toJSON(),l.toJSON(),p,{localUsername:o,remoteUsername:s,remotePassword:n,generation:i,rtt:v}),r.response=l,r.addr=p}catch(l){let p=l;if(Tt("failure case",c.toJSON(),p.response?JSON.stringify(p.response.toJSON(),null,2):l,{localUsername:o,remoteUsername:s,remotePassword:n,generation:i},t.remoteAddr),p.response?.getAttributeValue("ERROR-CODE")[0]===487){c.attributesKeys.includes("ICE-CONTROLLED")?this.switchRole(!0):c.attributesKeys.includes("ICE-CONTROLLING")&&this.switchRole(!1),await this.checkStart(t).awaitable,e();return}if(p.response?.getAttributeValue("ERROR-CODE")[0]===401){Tt("retry 401",t.toJSON()),await this.checkStart(t).awaitable,e();return}else{Tt("checkStart CandidatePairState.FAILED",t.toJSON()),t.updateState(4),this.checkComplete(t),e();return}}if(!(0,Uh.default)(r.addr,t.remoteAddr)){t.updateState(4),this.checkComplete(t),e();return}if(a||t.remoteNominated)t.nominated=!0;else if(this.iceControlling&&!this.nominating){this.nominating=!0;let l=this.buildRequest({nominate:!0,localUsername:o,remoteUsername:s,iceControlling:this.iceControlling});try{await t.protocol.request(l,t.remoteAddr,Buffer.from(this.remotePassword,"utf8"))}catch{t.updateState(4),this.checkComplete(t);return}t.nominated=!0}t.updateState(3),this.checkComplete(t),e()});addPair(t){this.checkList.push(t),this.sortCheckList()}checkIncoming(t,e,r){let n=t.getAttributeValue("USERNAME"),{remoteUsername:s}=R3(n),i,[o,a]=e;for(let f of this.remoteCandidates)if(f.host===o&&f.port===a){i=f;break}i||(i=new ka(wd(10),1,"udp",t.getAttributeValue("PRIORITY"),o,a,"prflx",void 0,void 0,void 0,void 0,void 0),this._remoteCandidates.push(i));let c=this.findPair(r,i);c||(c=new C3(r,i,this.iceControlling),c.updateState(1),this.addPair(c)),c.localCandidate.ufrag=s,Tt("Triggered Checks",t.toJSON(),c.toJSON(),{localUsername:this.localUsername,remoteUsername:this.remoteUsername,localPassword:this.localPassword,remotePassword:this.remotePassword,generation:this.generation}),[1,4].includes(c.state)&&(c.handle=this.checkStart(c)),t.attributesKeys.includes("USE-CANDIDATE")&&!this.iceControlling&&(c.remoteNominated=!0,c.state===3&&(c.nominated=!0,this.checkComplete(c)))}tryPair(t,e){if(t.localCandidate?.canPairWith(e)&&!this.findPair(t,e)){let r=new C3(t,e,this.iceControlling);if(this.options.filterCandidatePair&&!this.options.filterCandidatePair(r))return;r.updateState(1),this.addPair(r)}}pairLocalProtocol(t){for(let e of this.remoteCandidates)this.tryPair(t,e)}pairRemoteCandidate=t=>{for(let e of this.protocols)this.tryPair(e,t)};buildRequest({nominate:t,remoteUsername:e,localUsername:r,iceControlling:n}){let s=pB({remoteUsername:e,localUsername:r}),i=new jn(1,0);return i.setAttribute("USERNAME",s).setAttribute("PRIORITY",Lh("prflx")),n?(i.setAttribute("ICE-CONTROLLING",this.tieBreaker),t&&i.setAttribute("USE-CANDIDATE",null)):i.setAttribute("ICE-CONTROLLED",this.tieBreaker),i}respondError(t,e,r,n){let s=new jn(t.messageMethod,272,t.transactionId);s.setAttribute("ERROR-CODE",n).addMessageIntegrity(Buffer.from(this.localPassword,"utf8")).addFingerprint(),r.sendStun(s,e).catch(i=>{Tt("sendStun error",i)})}},pB=({remoteUsername:t,localUsername:e})=>`${t}:${e}`,R3=t=>{let[e,r]=t.split(":");return{remoteUsername:e,localUsername:r}};function N3(t){return t.map((e,r)=>[r,e])}function oi(t,e){let r=t.split(e);return[r[0],r.slice(1).join(e)]}var ry=class extends xB{addEventListener=(t,e)=>{this.addListener(t,e)};removeEventListener=(t,e)=>{this.removeListener(t,e)}},mB=tt("werift:packages/webrtc/src/dataChannel.ts");function gB(t){return Buffer.isBuffer(t)?t.length:Buffer.byteLength(t)}var W4=class extends ry{constructor(t,e,r=!0){if(super(),this.sctp=t,this.parameters=e,this.sendOpen=r,this.id=this.parameters.id,e.negotiated){if(this.id==null||this.id<0||this.id>65534)throw new Error("ID must be in range 0-65534 if data channel is negotiated out-of-band");this.sctp.dataChannelAddNegotiated(this)}else r&&(this.sendOpen=!1,this.sctp.dataChannelOpen(this))}stateChange=new be;stateChanged=new be;onMessage=new be;error=new be;bufferedAmountLow=new be;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(t){if(t<0||t>4294967295)throw new Error("bufferedAmountLowThreshold must be in range 0 - 4294967295");this._bufferedAmountLowThreshold=t}setId(t){this.id=t}setReadyState(t){if(t!==this.readyState){switch(this.readyState=t,this.stateChange.execute(t),this.stateChanged.execute(t),t){case"open":this.onopen&&this.onopen(),this.emit("open");break;case"closed":this.onclose&&this.onclose(),this.emit("close");break;case"closing":this.onclosing&&this.onclosing();break}mB("change state",t)}}addBufferedAmount(t){let e=this.bufferedAmount>this.bufferedAmountLowThreshold&&this.bufferedAmount+t<=this.bufferedAmountLowThreshold;this.bufferedAmount+=t,e&&(this.bufferedAmountLow.execute(),this.emit("bufferedamountlow"))}send(t){let e=this.sctp.datachannelSend(this,t);this.messagesSent++,this.bytesSent+=e}close(){this.sctp.dataChannelClose(this)}},G4=class{label="";maxPacketLifeTime;maxRetransmits;ordered=!0;protocol="";negotiated=!1;id;constructor(t={}){Object.assign(this,t)}},nJ=()=>({type:"ccm",parameter:"fir"}),xp=()=>({type:"nack"}),sl=()=>({type:"nack",parameter:"pli"}),mp=()=>({type:"goog-remb"}),yB=()=>({type:"transport-cc"}),Ma=class{payloadType;mimeType;clockRate;channels;rtcpFeedback=[];parameters;direction="all";constructor(t){Object.assign(this,t)}get name(){return this.mimeType.split("/")[1]}get contentType(){return this.mimeType.split("/")[0]}get str(){let t=`${this.name}/${this.clockRate}`;return this.channels===2&&(t+="/2"),t}},li=class{id;uri;constructor(t){Object.assign(this,t)}},sJ=class{cname;mux=!1;ssrc;constructor(t={}){Object.assign(this,t)}},bB=class{type;parameter;constructor(t={}){Object.assign(this,t)}},vB=class{ssrc;constructor(t={}){Object.assign(this,t)}},wB=class{ssrc;payloadType;rtx;constructor(t){Object.assign(this,t)}},X4=class{rid;direction;constructor(t){Object.assign(this,t)}},SB=(t={})=>new Ma({mimeType:"video/h264",clockRate:9e4,rtcpFeedback:[xp(),sl(),mp()],parameters:"profile-level-id=42e01f;packetization-mode=1;level-asymmetry-allowed=1",...t}),Y4=(t={})=>new Ma({mimeType:"video/VP8",clockRate:9e4,rtcpFeedback:[xp(),sl(),mp()],...t}),EB=(t={})=>new Ma({mimeType:"video/VP9",clockRate:9e4,rtcpFeedback:[xp(),sl(),mp()],...t}),AB=(t={})=>new Ma({mimeType:"video/AV1X",clockRate:9e4,rtcpFeedback:[xp(),sl(),mp()],...t}),Z4=(t={})=>new Ma({mimeType:"audio/OPUS",clockRate:48e3,channels:2,...t}),J4=(t={})=>new Ma({mimeType:"audio/PCMU",clockRate:8e3,channels:1,payloadType:0,...t}),Q4=[AB(),EB(),Y4(),SB(),Z4(),J4()].map(t=>t.mimeType),iJ=Q4.filter(t=>t.toLowerCase().startsWith("video/")),oJ=Q4.filter(t=>t.toLowerCase().startsWith("audio/"));function aJ(){return new li({uri:Dt.sdesMid})}function cJ(){return new li({uri:Dt.sdesRTPStreamID})}function uJ(){return new li({uri:Dt.repairedRtpStreamId})}function fJ(){return new li({uri:Dt.transportWideCC})}function dJ(){return new li({uri:Dt.absSendTime})}function lJ(){return new li({uri:Dt.dependencyDescriptor})}function hJ(){return new li({uri:Dt.audioLevelIndication})}function pJ(){return new li({uri:Dt.videoOrientation})}var O3=2,L3=3,BB=0,Ah=50,U3=51,D3=53,kB=56,RB=57,NB="0.0.0.0",M3=9,vg={auto:"actpass",client:"active",server:"passive"},H3=Object.keys(vg).reduce((t,e)=>{let r=vg[e];return t[r]=e,t},{}),PB=["apt","max-fr","max-fs","maxplaybackrate","minptime","stereo","useinbandfec"],e5=["cname","msid","mslabel","label"],j3={SRTP_AES128_CM_HMAC_SHA1_80:rl,SRTP_AEAD_AES_128_GCM:iu},Dh=["sendonly","sendrecv"],OB=["sendrecv","recvonly"],LB=class extends Map{constructor(t){if(super(),t)for(let e of t)this.set(e.id,e)}};function kt(t,...e){let r=e.filter(n=>n!==void 0);return`${t}_${r.join("_")}`}function Ha(){return performance.now()}var UB=class{constructor(t,e,r,n,s){this.kind=t,this.receiver=r,this.sender=n,this._direction=s,e&&this.setDtlsTransport(e)}id=_B().toString();onTrack=new be;mid;mLineIndex;usedForSender=!1;_currentDirection;offerDirection;_codecs=[];set codecs(t){this._codecs=t}get codecs(){return this._codecs}headerExtensions=[];options={};stopping=!1;stopped=!1;get dtlsTransport(){return this.receiver.dtlsTransport}get direction(){return this._direction}setDirection(t){this._direction=t,Dh.includes(this._currentDirection??"")&&(this.usedForSender=!0)}get currentDirection(){return this._currentDirection}setCurrentDirection(t){this._currentDirection=t}setDtlsTransport(t){this.receiver.setDtlsTransport(t),this.sender.setDtlsTransport(t)}get msid(){return`${this.sender.streamId} ${this.sender.trackId}`}addTrack(t){this.receiver.addTrack(t)&&this.onTrack.execute(t,this)}stop(){this.stopping||(this.stopping=!0)}getPayloadType(t){return this.codecs.find(e=>e.mimeType.toLowerCase().includes(t.toLowerCase()))?.payloadType}getCodecStats(){let t=Ha(),e=[];if(!this.dtlsTransport)return e;let r=kt("transport",this.dtlsTransport.id);for(let n of this.codecs){let s={type:"codec",id:kt("codec",n.payloadType,r),timestamp:t,payloadType:n.payloadType,transportId:r,mimeType:n.mimeType,clockRate:n.clockRate,channels:n.channels,sdpFmtpLine:n.parameters};e.push(s)}return e}},DB="inactive",t5="sendonly",r5="recvonly",n5="sendrecv",D1=[DB,t5,r5,n5],op=class extends ry{uuid=s5().toString();streamId;remote=!1;label;kind;id;ssrc;rid;header;codec;enabled=!0;onReceiveRtp=new be;onReceiveRtcp=new be;onSourceChanged=new be;stopped=!1;muted=!0;constructor(t){super(),Object.assign(this,t),this.onReceiveRtp.subscribe(e=>{this.muted=!1,this.header=e.header}),this.label=`${this.remote?"remote":"local"} ${this.kind}`}stop=()=>{this.stopped=!0,this.muted=!0,this.onReceiveRtp.complete(),this.emit("ended")};writeRtp=t=>{if(this.remote)throw new Error("this is remoteTrack");if(this.stopped)return;let e=Buffer.isBuffer(t)?ho.deSerialize(t):t;e.header.payloadType=this.codec?.payloadType??e.header.payloadType,this.onReceiveRtp.execute(e)}},MB=class{id;tracks=[];constructor(t){Array.isArray(t)?this.tracks=t:Object.assign(this,t),this.id??=s5().toString()}addTrack(t){t.streamId=this.id,this.tracks.push(t)}getTracks(){return this.tracks}getAudioTracks(){return this.tracks.filter(t=>t.kind==="audio")}getVideoTracks(){return this.tracks.filter(t=>t.kind==="video")}},HB=tt("werift:packages/webrtc/src/utils.ts");function i5(t,e){let r=i=>i.toUpperCase(),n=i=>i.match(/(.{2})/g).join(":"),s=IB(e).update(t).digest("hex");return n(r(s))}var jB={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 o5(t){return jB[t.trim().toLowerCase()]}function wg(t){return t.replace(/[^0-9a-f]/gi,"").toLowerCase()}function qB(t){let e=t[0];return e>19&&e<64}function SJ(t){return t==="recv"?"send":"recv"}var a5=(t,e)=>D1[D1.indexOf(t)&D1.indexOf(e)];function VB(t){return t==="sendonly"?"recvonly":t==="recvonly"?"sendonly":t}var c5=Date.now,zB=BigInt(Date.now())*1000n-process.hrtime.bigint()/1000n,FB=()=>zB+process.hrtime.bigint()/1000n,ap=()=>Date.now()/1e3,KB=()=>{let e=(P3.timeOrigin+P3.now()-Date.UTC(1900,0,1))/1e3,[r,n]=e.toString().split(".").map(Number);return Ht([4,4],[r,n]).readBigUInt64BE()},u5=t=>{let e=Ht([8],[t]),[,r,n]=Wr(e,[2,2,2,2]);return Ht([2,2],[r,n]).readUInt32BE()};function $B(t){let e=a=>{if(!a)return;let[c,f]=a.split(":");return[c,Number.parseInt(f)]},r=e(t.find(({urls:a})=>a.includes("stun:"))?.urls.slice(5)),n=e(t.find(({urls:a})=>a.includes("turn:"))?.urls.slice(5)),{credential:s,username:i}=t.find(({urls:a})=>a.includes("turn:"))||{},o={stunServer:r,turnServer:n,turnUsername:i,turnPassword:s};return HB("iceOptions",o),o}var EJ=Yh.createSelfSignedCertificateWithKey,AJ=class{static async rtpSource({port:t,kind:e,cb:r}){t??=await y8();let n=new op({kind:e}),s=TB("udp4");s.bind(t);let i=a=>{r&&(a=r(a)),n.writeRtp(a)};return s.addListener("message",i),[n,t,()=>{s.removeListener("message",i);try{s.close()}catch{}}]}},WB=(t,e)=>{if(!t||typeof t!="object")return e!==null&&typeof e=="object"?e:t;if(!e||typeof e!="object")return e??t;for(let r in e)if(Object.prototype.hasOwnProperty.call(e,r)){let n=e[r];n!=null&&(t[r]=n)}return t},GB=tt("werift:packages/webrtc/src/media/receiver/nack.ts"),q3=150,XB=class{constructor(t){this.receiver=t}newEstSeqNum=0;_lost={};nackLoop;onPacketLost=new be;mediaSourceSsrc;retryCount=10;closed=!1;get lostSeqNumbers(){return Object.keys(this._lost).map(Number).sort()}getLost(t){return this._lost[t]}setLost(t,e){this._lost[t]=e,!(this.nackLoop||this.closed)&&(this.nackLoop=setInterval(async()=>{try{await this.sendNack(),Object.keys(this._lost).length||(clearInterval(this.nackLoop),this.nackLoop=void 0)}catch(r){GB("failed to send nack",r)}},5))}removeLost(t){delete this._lost[t]}addPacket(t){let{sequenceNumber:e,ssrc:r}=t.header;if(this.mediaSourceSsrc=r,this.newEstSeqNum===0){this.newEstSeqNum=e;return}if(this.getLost(e)){this.removeLost(e);return}if(e===Tr(this.newEstSeqNum,1))this.newEstSeqNum=e;else if(e>Tr(this.newEstSeqNum,1)){for(let n=Tr(this.newEstSeqNum,1);n<e;n=Tr(n,1))this.setLost(n,1);this.newEstSeqNum=e,this.pruneLost()}}pruneLost(){this.lostSeqNumbers.length>q3&&(this._lost=Object.entries(this._lost).slice(-q3).reduce((t,[e,r])=>(t[e]=r,t),{}))}close(){this.closed=!0,clearInterval(this.nackLoop),this._lost={}}updateRetryCount(){this.lostSeqNumbers.forEach(t=>{if(this._lost[t]++>this.retryCount)return this.removeLost(t),t})}sendNack=()=>new Promise((t,e)=>{if(this.lostSeqNumbers.length>0&&this.mediaSourceSsrc){let r=new np({senderSsrc:this.receiver.rtcpSsrc,mediaSourceSsrc:this.mediaSourceSsrc,lost:this.lostSeqNumbers}),n=new eu({feedback:r});this.receiver.dtlsTransport.sendRtcp([n]).then(t).catch(e),this.updateRetryCount(),this.onPacketLost.execute(r)}})},ZB=tt("werift:packages/webrtc/media/receiver/receiverTwcc"),JB=class{constructor(t,e,r){this.dtlsTransport=t,this.rtcpSsrc=e,this.mediaSourceSsrc=r,this.runTWCC()}extensionInfo={};twccRunning=!1;fbPktCount=0;lastTimestamp;handleTWCC(t){this.extensionInfo[t]={tsn:t,timestamp:FB()},Object.keys(this.extensionInfo).length>10&&this.sendTWCC()}async runTWCC(){for(;this.twccRunning;)this.sendTWCC(),await YB(100)}sendTWCC(){if(Object.keys(this.extensionInfo).length===0)return;let t=Object.values(this.extensionInfo).sort((l,p)=>l.tsn-p.tsn),e=t[0].tsn,r=t.slice(-1)[0].tsn,n=[],s=t[0].tsn,i=Tr(r-e,1),o,a,c=[];for(let l=e;l<=r;l++){let p=this.extensionInfo[l]?.timestamp;if(p){this.lastTimestamp||(this.lastTimestamp=p),o||(o=this.lastTimestamp);let x=p-this.lastTimestamp;this.lastTimestamp=p;let v=new Bh({delta:Number(x)});v.parseDelta(),c.push(v),a!=null&&a.status!==v.type&&(n.push(new qd({packetStatus:a.status,runLength:l-a.minTSN})),a={minTSN:l,status:v.type}),l===r&&(a!=null?n.push(new qd({packetStatus:a.status,runLength:l-a.minTSN+1})):n.push(new qd({packetStatus:v.type,runLength:1}))),a==null&&(a={minTSN:l,status:v.type})}}if(!o)return;let f=new eu({feedback:new sp({senderSsrc:this.rtcpSsrc,mediaSourceSsrc:this.mediaSourceSsrc,baseSequenceNumber:s,packetStatusCount:i,referenceTime:PT(Math.floor(Number(o/1000n/64n))),fbPktCount:this.fbPktCount,recvDeltas:c,packetChunks:n})});this.dtlsTransport.sendRtcp([f]).catch(l=>{ZB(l)}),this.extensionInfo={},this.fbPktCount=NT(this.fbPktCount,1)}},QB=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(t){this.clockRate=t}add(t,e=Date.now()/1e3){let r=this.max_seq==null||Fg(t.header.sequenceNumber,this.max_seq);if(this.packets_received++,this.base_seq==null&&(this.base_seq=t.header.sequenceNumber),r){let n=jd(e*this.clockRate);if(this.max_seq!=null&&t.header.sequenceNumber<this.max_seq&&(this.cycles+=65536),this.max_seq=t.header.sequenceNumber,t.header.timestamp!==this.last_timestamp&&this.packets_received>1){let s=Math.abs(n-(this.last_arrival??0)-(t.header.timestamp-(this.last_timestamp??0)));this.jitter_q4+=s-(this.jitter_q4+8>>4)}this.last_arrival=n,this.last_timestamp=t.header.timestamp}}get fraction_lost(){let t=this.packets_expected-this.expected_prior;this.expected_prior=this.packets_expected;let e=this.packets_received-this.received_prior;this.received_prior=this.packets_received;let r=t-e;return t==0||r<=0?0:Math.floor((r<<8)/t)}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 t=this.packets_expected-this.packets_received;return t<0?0:t}},On=tt("werift:packages/webrtc/src/transport/dtls.ts"),V3=class f5{constructor(e,r,n,s=[]){this.config=e,this.iceTransport=r,this.localCertificate=n,this.srtpProfiles=s,this.localCertificate??=f5.localCertificate}id=rk().toString();state="new";role="auto";srtpStarted=!1;transportSequenceNumber=0;bytesSent=0;bytesReceived=0;packetsSent=0;packetsReceived=0;dataReceiver=()=>{};dtls;srtp;srtcp;onStateChange=new be;onRtcp=new be;onRtp=new be;static localCertificate;static localCertificatePromise;remoteParameters;get localParameters(){return new Eg(this.localCertificate?this.localCertificate.getFingerprints():[],this.role)}static async SetupCertificate(){return this.localCertificate?this.localCertificate:this.localCertificatePromise?this.localCertificatePromise:(this.localCertificatePromise=(async()=>{let{certPem:e,keyPem:r,signatureHash:n}=await Yh.createSelfSignedCertificateWithKey({signature:di.ecdsa_3,hash:Xh.sha256_4},fo.secp256r1_23);return this.localCertificate=new d5(r,e,n),this.localCertificate})(),this.localCertificatePromise)}setRemoteParams(e){let r=sk([...this.remoteParameters?.fingerprints??[],...e.fingerprints]),n=e.role==="auto"&&this.remoteParameters?.role?this.remoteParameters.role:e.role;this.remoteParameters=new Eg(r,n)}async start(){if(this.state!=="new")throw new Error("state must be new");if(!this.remoteParameters||this.remoteParameters.fingerprints.length===0)throw new Error("remote fingerprint not exist");this.role==="auto"&&(this.iceTransport.role==="controlling"?this.role="server":this.role="client"),this.setState("connecting"),await new Promise(async(e,r)=>{this.role==="server"?this.dtls=new R7({cert:this.localCertificate?.certPem,key:this.localCertificate?.privateKey,signatureHash:this.localCertificate?.signatureHash,transport:z3(this.iceTransport.connection),srtpProfiles:this.srtpProfiles,extendedMasterSecret:!0,certificateRequest:!0}):this.dtls=new h3({cert:this.localCertificate?.certPem,key:this.localCertificate?.privateKey,signatureHash:this.localCertificate?.signatureHash,transport:z3(this.iceTransport.connection),srtpProfiles:this.srtpProfiles,extendedMasterSecret:!0}),this.dtls.onData.subscribe(n=>{this.config.debug.inboundPacketLoss&&this.config.debug.inboundPacketLoss/100<Math.random()||this.dataReceiver(n)}),this.dtls.onClose.subscribe(()=>{this.state!=="failed"&&this.setState("closed")}),this.dtls.onConnect.once(e),this.dtls.onError.once(n=>{this.setState("failed"),On("dtls failed",n),r(n)}),this.dtls instanceof h3&&(await nk(100),this.dtls.connect().catch(n=>{this.setState("failed"),On("dtls connect failed",n),r(n)}))});try{this.verifyRemoteCertificateFingerprint()}catch(e){throw this.setState("failed"),this.dtls?.close(),e}this.srtpProfiles.length>0&&this.startSrtp(),this.setState("connected"),On("dtls connected")}verifyRemoteCertificateFingerprint(){if(!this.remoteParameters||this.remoteParameters.fingerprints.length===0)throw new Error("remote fingerprint not exist");let e=this.dtls?.remoteCertificate;if(!e)throw new Error("remote certificate not available");let r=this.remoteParameters.fingerprints.flatMap(({algorithm:a,value:c})=>{let f=o5(a);if(!f)return[];let l=wg(c);if(!l)throw new Error("remote fingerprint value is empty");return[{normalizedAlgorithm:f,normalizedValue:l}]});if(r.length===0)throw new Error("no supported remote fingerprint algorithms");let n=ok(r),s=r.filter(({normalizedAlgorithm:a})=>a===n),i=s.reduce((a,{normalizedAlgorithm:c})=>(a.has(c)||a.set(c,wg(i5(e,c))),a),new Map);if(!s.some(({normalizedAlgorithm:a,normalizedValue:c})=>i.get(a)===c))throw new Error("remote certificate fingerprint mismatch")}updateSrtpSession(){if(!this.dtls)throw new Error;let e=this.dtls.srtp.srtpProfile;if(!e)throw new Error("need srtpProfile");On("selected SRTP Profile",e);let{localKey:r,localSalt:n,remoteKey:s,remoteSalt:i}=this.dtls.extractSessionKeys(A_(e),C_(e)),o={keys:{localMasterKey:r,localMasterSalt:n,remoteMasterKey:s,remoteMasterSalt:i},profile:e};this.srtp=new v7(o),this.srtcp=new y7(o)}startSrtp(){this.srtpStarted||(this.srtpStarted=!0,this.updateSrtpSession(),this.iceTransport.connection.onData.subscribe(e=>{if(!(this.config.debug.inboundPacketLoss&&this.config.debug.inboundPacketLoss/100<Math.random())&&D_(e))if(this.bytesReceived+=e.length,this.packetsReceived++,G_(e)){let r;try{r=this.srtcp.decrypt(e)}catch(s){if(s instanceof ru){On("dropping invalid SRTCP packet",s);return}throw s}let n;try{n=W_.deSerialize(r)}catch(s){On("dropping malformed SRTCP packet",s);return}for(let s of n)try{this.onRtcp.execute(s)}catch(i){On("RTCP error",i)}}else{let r;try{r=this.srtp.decrypt(e)}catch(s){if(s instanceof ru){On("dropping invalid SRTP packet",s);return}throw s}let n;try{n=ho.deSerialize(r)}catch(s){On("dropping malformed SRTP packet",s);return}try{this.onRtp.execute(n)}catch(s){On("RTP error",s)}}}))}sendData=async e=>{if(!(this.config.debug.outboundPacketLoss&&this.config.debug.outboundPacketLoss/100<Math.random())){if(!this.dtls)throw new Error("dtls not established");await this.dtls.send(e)}};async sendRtp(e,r){try{let n=this.srtp.encrypt(e,r);return this.config.debug.outboundPacketLoss&&this.config.debug.outboundPacketLoss/100<Math.random()||(this.bytesSent+=n.length,this.packetsSent++,await this.iceTransport.connection.send(n).catch(()=>{})),n.length}catch(n){return On("failed to send",n),0}}async sendRtcp(e){let r=Buffer.concat(e.map(s=>s.serialize())),n=this.srtcp.encrypt(r);if(this.config.debug.outboundPacketLoss&&this.config.debug.outboundPacketLoss/100<Math.random())return n.length;this.bytesSent+=n.length,this.packetsSent++,await this.iceTransport.connection.send(n).catch(()=>{})}setState(e){e!=this.state&&(this.state=e,this.onStateChange.execute(e))}async stop(){this.setState("closed"),await this.iceTransport.stop()}async getStats(){let e=Ha(),r=[],s={type:"transport",id:kt("transport",this.id),timestamp:e,bytesSent:this.bytesSent,bytesReceived:this.bytesReceived,packetsSent:this.packetsSent,packetsReceived:this.packetsReceived,dtlsState:this.state,iceState:this.iceTransport.state,selectedCandidatePairId:this.iceTransport.connection.nominated?kt("candidate-pair",this.iceTransport.connection.nominated.localCandidate.foundation,this.iceTransport.connection.nominated.remoteCandidate.foundation):void 0,localCertificateId:this.localCertificate?kt("certificate","local"):void 0,remoteCertificateId:this.remoteParameters?kt("certificate","remote"):void 0,dtlsRole:this.role==="auto"?void 0:this.role};if(r.push(s),this.localCertificate){let o=this.localCertificate.getFingerprints();if(o.length>0){let a={type:"certificate",id:kt("certificate","local"),timestamp:e,fingerprint:o[0].value,fingerprintAlgorithm:o[0].algorithm,base64Certificate:Buffer.from(this.localCertificate.certPem).toString("base64")};r.push(a)}}if(this.remoteParameters&&this.remoteParameters.fingerprints.length>0){let o={type:"certificate",id:kt("certificate","remote"),timestamp:e,fingerprint:this.remoteParameters.fingerprints[0].value,fingerprintAlgorithm:this.remoteParameters.fingerprints[0].algorithm,base64Certificate:""};r.push(o)}let i=await this.iceTransport.getStats();return r.push(...i),r}},kJ=["new","connecting","connected","closed","failed"],d5=class{constructor(t,e,r){this.certPem=e,this.signatureHash=r;let n=Gd.Certificate.fromPEM(Buffer.from(e));this.publicKey=n.publicKey.toPEM(),this.privateKey=Gd.PrivateKey.fromPEM(Buffer.from(t)).toPEM()}publicKey;privateKey;getFingerprints(){return[new Sg("sha-256",i5(Gd.Certificate.fromPEM(Buffer.from(this.certPem)).raw,"sha256"))]}},Sg=class{constructor(t,e){this.algorithm=t,this.value=e}},Eg=class{constructor(t=[],e){this.fingerprints=t,this.role=e}},sk=t=>{let e=new Set;return t.filter(({algorithm:r,value:n})=>{let s=`${o5(r)??r.trim().toLowerCase()}:${wg(n)}`;return e.has(s)?!1:(e.add(s),!0)})},ik=["sha512","sha384","sha256","sha224","sha1"],ok=t=>ik.find(e=>t.some(({normalizedAlgorithm:r})=>r===e))??t[0].normalizedAlgorithm,ak=class{constructor(t){this.ice=t,t.onData.subscribe(e=>{qB(e)&&this.onData&&this.onData(e)})}closed=!1;onData=()=>{};get address(){return{}}type="ice";send=t=>this.ice.send(t);async close(){this.closed=!0,this.ice.close()}},z3=t=>new ak(t),F3=tt("werift:packages/webrtc/src/transport/ice.ts"),uk=class{constructor(t){this.iceGather=t,this.connection=this.iceGather.connection,this.connection.stateChanged.subscribe(e=>{this.setState(e)}),this.iceGather.onIceCandidate=e=>{this.onIceCandidate.execute(e)}}id=ck().toString();connection;state="new";waitStart;renominating=!1;onStateChange=new be;onIceCandidate=new be;onNegotiationNeeded=new be;get role(){return this.connection.iceControlling?"controlling":"controlled"}get gatheringState(){return this.iceGather.gatheringState}get localCandidates(){return this.iceGather.localCandidates}get localParameters(){return this.iceGather.localParameters}setState(t){t!==this.state&&(this.state=t,this.onStateChange.execute(t))}gather(){return this.iceGather.gather()}addRemoteCandidate=t=>{if(!this.connection.remoteCandidatesEnd)return t?this.connection.addRemoteCandidate(dk(t)):this.connection.addRemoteCandidate(void 0)};setRemoteParams(t,e=!1){e&&(this.renominating=!0),this.connection.remoteUsername&&this.connection.remotePassword&&(this.connection.remoteUsername!==t.usernameFragment||this.connection.remotePassword!==t.password)&&(this.renominating?(F3("renomination",t),this.connection.resetNominatedPair(),this.renominating=!1):(F3("restart",t),this.restart())),this.connection.setRemoteParams(t)}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 new Error("RTCIceTransport is closed");if(!this.connection.remotePassword||!this.connection.remoteUsername)throw new Error("remoteParams missing");this.waitStart&&await this.waitStart.asPromise(),this.waitStart=new be,this.setState("checking");try{await this.connection.connect()}catch(t){throw this.setState("failed"),t}this.waitStart.execute(),this.waitStart.complete(),this.waitStart=void 0}async stop(){this.state!=="closed"&&(this.setState("closed"),await this.connection.close()),this.onStateChange.complete(),this.onIceCandidate.complete(),this.onNegotiationNeeded.complete()}async getStats(){let t=Ha(),e=[];for(let n of this.localCandidates){let s={type:"local-candidate",id:kt("local-candidate",n.foundation),timestamp:t,transportId:kt("transport",this.id),address:n.ip,port:n.port,protocol:n.protocol,candidateType:n.type,priority:n.priority,foundation:n.foundation};e.push(s)}for(let n of this.connection.remoteCandidates){let s=Xd(n),i={type:"remote-candidate",id:kt("remote-candidate",s.foundation),timestamp:t,transportId:kt("transport",this.id),address:s.ip,port:s.port,protocol:s.protocol,candidateType:s.type,priority:s.priority,foundation:s.foundation};e.push(i)}let r=this.connection?.candidatePairs?[...this.connection.candidatePairs.filter(n=>n.nominated),...this.connection.candidatePairs.filter(n=>!n.nominated)]:[];for(let n of r){let s={type:"candidate-pair",id:kt("candidate-pair",n.foundation),timestamp:t,transportId:kt("transport",this.id),localCandidateId:kt("local-candidate",n.localCandidate.foundation),remoteCandidateId:kt("remote-candidate",n.remoteCandidate.foundation),state:n.state,nominated:n.nominated,packetsSent:n.packetsSent,packetsReceived:n.packetsReceived,bytesSent:n.bytesSent,bytesReceived:n.bytesReceived,currentRoundTripTime:n.rtt};e.push(s)}return e}},NJ=["new","checking","connected","completed","disconnected","failed","closed"],PJ=["new","gathering","complete"],fk=class{constructor(t={}){this.options=t,this.connection=new hB(!1,this.options),this.connection.onIceCandidate.subscribe(e=>{this.onIceCandidate(Xd(e))})}onIceCandidate=()=>{};gatheringState="new";connection;onGatheringStateChange=new be;async gather(){this.gatheringState==="new"&&(this.setState("gathering"),await this.connection.gatherCandidates(),this.onIceCandidate(void 0),this.setState("complete"))}get localCandidates(){return this.connection.localCandidates.map(Xd)}get localParameters(){return new h5({usernameFragment:this.connection.localUsername,password:this.connection.localPassword})}setState(t){t!==this.gatheringState&&(this.gatheringState=t,this.onGatheringStateChange.execute(t))}};function Xd(t){let e=new l5(t.component,t.foundation,t.host,t.port,t.priority,t.transport,t.type,t.generation,t.ufrag);return e.relatedAddress=t.relatedAddress,e.relatedPort=t.relatedPort,e.tcpType=t.tcptype,e}function dk(t){return new ka(t.foundation,t.component,t.protocol,t.priority,t.ip,t.port,t.type,t.relatedAddress,t.relatedPort,t.tcpType,t.generation,t.ufrag)}var lk=class{candidate;sdpMid;sdpMLineIndex;usernameFragment;constructor(t){Object.assign(this,t)}static fromSdp(t){let e=ka.fromSdp(t);return Xd(e).toJSON()}static isThis(t){if(typeof t?.candidate=="string")return!0}toJSON(){return{candidate:this.candidate,sdpMid:this.sdpMid,sdpMLineIndex:this.sdpMLineIndex,usernameFragment:this.usernameFragment}}},l5=class{constructor(t,e,r,n,s,i,o,a,c){this.component=t,this.foundation=e,this.ip=r,this.port=n,this.priority=s,this.protocol=i,this.type=o,this.generation=a,this.ufrag=c}relatedAddress;relatedPort;sdpMid;sdpMLineIndex;tcpType;toJSON(){return new lk({candidate:q5(this),sdpMLineIndex:this.sdpMLineIndex,sdpMid:this.sdpMid,usernameFragment:this.ufrag})}static fromJSON(t){try{if(!t.candidate)throw new Error("candidate is required");let e=V5(t.candidate);return e.sdpMLineIndex=t.sdpMLineIndex??void 0,e.sdpMid=t.sdpMid??void 0,e}catch{}}},h5=class{iceLite=!1;usernameFragment;password;constructor(t={}){Object.assign(this,t)}},ws=class p5{constructor(e=0,r=Buffer.from("")){this.flags=e,this._body=r}get body(){return this._body}set body(e){this._body=e}static type=-1;get type(){return p5.type}get bytes(){if(!this.body)throw new Error;let e=Buffer.alloc(4);return e.writeUInt8(this.type,0),e.writeUInt8(this.flags,1),e.writeUInt16BE(this.body.length+4,2),Buffer.concat([e,this.body,...[...Array(ol(this.body.length))].map(()=>Buffer.from("\0"))])}},ny=class extends ws{constructor(t=0,e){super(t,e),this.flags=t,e?(this.initiateTag=e.readUInt32BE(0),this.advertisedRwnd=e.readUInt32BE(4),this.outboundStreams=e.readUInt16BE(8),this.inboundStreams=e.readUInt16BE(10),this.initialTsn=e.readUInt32BE(12),this.params=L5(e.slice(16))):(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 t=Buffer.alloc(16);return t.writeUInt32BE(this.initiateTag,0),t.writeUInt32BE(this.advertisedRwnd,4),t.writeUInt16BE(this.outboundStreams,8),t.writeUInt16BE(this.inboundStreams,10),t.writeUInt32BE(this.initialTsn,12),Buffer.concat([t,O5(this.params)])}},jh=class x5 extends ny{static type=1;get type(){return x5.type}},Ag=class m5 extends ny{static type=2;get type(){return m5.type}},xk=class g5 extends ny{static type=130;get type(){return g5.type}},qh=class y5 extends ws{constructor(e=0,r){if(super(e,r),this.flags=e,r){this.cumulativeTsn=r.readUInt32BE(0);let n=4;for(;n<r.length;)this.streams.push([r.readUInt16BE(n),r.readUInt16BE(n+2)]),n+=4}else this.cumulativeTsn=0}static type=192;streams=[];cumulativeTsn;get type(){return y5.type}set body(e){}get body(){let e=Buffer.alloc(4);return e.writeUInt32BE(this.cumulativeTsn,0),Buffer.concat([e,...this.streams.map(([r,n])=>{let s=Buffer.alloc(4);return s.writeUInt16BE(r,0),s.writeUInt16BE(n,2),s})])}},Vh=class b5 extends ws{constructor(e=0,r){super(e,r),this.flags=e,r&&(this.tsn=r.readUInt32BE(0),this.streamId=r.readUInt16BE(4),this.streamSeqNum=r.readUInt16BE(6),this.protocol=r.readUInt32BE(8),this.userData=r.slice(12))}static type=0;get type(){return b5.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 e=16+this.userData.length,r=Buffer.alloc(16);r.writeUInt8(this.type,0),r.writeUInt8(this.flags,1),r.writeUInt16BE(e,2),r.writeUInt32BE(this.tsn,4),r.writeUInt16BE(this.streamId,8),r.writeUInt16BE(this.streamSeqNum,10),r.writeUInt32BE(this.protocol,12);let n=Buffer.concat([r,this.userData]);return e%4&&(n=Buffer.concat([n,...[...Array(ol(e))].map(()=>Buffer.from("\0"))])),n}},Cg=class v5 extends ws{static type=10;get type(){return v5.type}},Ig=class w5 extends ws{static type=11;get type(){return w5.type}},il=class extends ws{constructor(t=0,e=void 0){super(t,e),this.flags=t,e&&(this.params=L5(e))}params=[];get body(){return O5(this.params)}},Tg=class S5 extends il{static type=6;get type(){return S5.type}},zh=class _g extends il{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 _g.type}get descriptions(){return this.params.map(([e,r])=>({name:(Object.entries(_g.CODE).find(([,s])=>s===e)||[])[0],body:r}))}},Bg=class E5 extends il{static type=4;get type(){return E5.type}},A5=class C5 extends il{static type=5;get type(){return C5.type}},kg=class I5 extends il{static type=130;get type(){return I5.type}},Rg=class T5 extends ws{constructor(e=0,r){if(super(e,r),this.flags=e,r){this.cumulativeTsn=r.readUInt32BE(0),this.advertisedRwnd=r.readUInt32BE(4);let n=r.readUInt16BE(8),s=r.readUInt16BE(10),i=12;[...Array(n)].forEach(()=>{this.gaps.push([r.readUInt16BE(i),r.readUInt16BE(i+2)]),i+=4}),[...Array(s)].forEach(()=>{this.duplicates.push(r.readUInt32BE(i)),i+=4})}}static type=3;get type(){return T5.type}gaps=[];duplicates=[];cumulativeTsn=0;advertisedRwnd=0;get bytes(){let e=16+4*(this.gaps.length+this.duplicates.length),r=Buffer.alloc(16);r.writeUInt8(this.type,0),r.writeUInt8(this.flags,1),r.writeUInt16BE(e,2),r.writeUInt32BE(this.cumulativeTsn,4),r.writeUInt32BE(this.advertisedRwnd,8),r.writeUInt16BE(this.gaps.length,12),r.writeUInt16BE(this.duplicates.length,14);let n=Buffer.concat([r,...this.gaps.map(s=>{let i=Buffer.alloc(4);return i.writeUInt16BE(s[0],0),i.writeUInt16BE(s[1],2),i})]);return n=Buffer.concat([n,...this.duplicates.map(s=>{let i=Buffer.alloc(4);return i.writeUInt32BE(s,0),i})]),n}},_5=class B5 extends ws{constructor(e=0,r){super(e,r),this.flags=e,r&&(this.cumulativeTsn=r.readUInt32BE(0))}static type=7;get type(){return B5.type}cumulativeTsn=0;get body(){let e=Buffer.alloc(4);return e.writeUInt32BE(this.cumulativeTsn,0),e}},k5=class R5 extends ws{static type=8;get type(){return R5.type}},N5=class P5 extends ws{static type=14;get type(){return P5.type}},mk=[Vh,jh,Ag,Rg,Bg,A5,Tg,_5,k5,zh,Cg,Ig,N5,kg,qh],gk=mk.reduce((t,e)=>(t[e.type]=e,t),{});function ol(t){let e=t%4;return e?4-e:0}function O5(t){let e=Buffer.from(""),r=Buffer.from("");return t.forEach(([n,s])=>{let i=s.length+4,o=Buffer.alloc(4);o.writeUInt16BE(n,0),o.writeUInt16BE(i,2),e=Buffer.concat([e,r,o,s]),r=Buffer.concat([...Array(ol(i))].map(()=>Buffer.from("\0")))}),e}function L5(t){let e=[],r=0;for(;r<=t.length-4;){let n=t.readUInt16BE(r),s=t.readUInt16BE(r+2);e.push([n,t.slice(r+4,r+s)]),r+=s+ol(s)}return e}function yk(t){if(t.length<12)throw new Error("SCTP packet length is less than 12 bytes");let e=t.readUInt16BE(0),r=t.readUInt16BE(2),n=t.readUInt32BE(4),s=t.readUInt32LE(8),i=m8(Buffer.concat([t.slice(0,8),Buffer.from("\0\0\0\0"),t.slice(12)]));if(s!==i)throw new Error("SCTP packet has invalid checksum");let o=[],a=12;for(;a+4<=t.length;){let c=t.readUInt8(a),f=t.readUInt8(a+1),l=t.readUInt16BE(a+2),p=t.slice(a+4,a+l),x=gk[c.toString()];if(x)o.push(new x(f,p));else throw new Error("unknown");a+=l+ol(l)}return[e,r,n,o]}function bk(t,e,r,n){let s=Buffer.alloc(8);s.writeUInt16BE(t,0),s.writeUInt16BE(e,2),s.writeUInt32BE(r,4);let i=n.bytes,o=m8(Buffer.concat([s,Buffer.from("\0\0\0\0"),i])),a=Buffer.alloc(4);return a.writeUInt32LE(o,0),Buffer.concat([s,a,i])}function vk(t){return t.map((e,r)=>[r,e])}function wk(t){return t.reduce((e,r)=>(e[r]=new be,e),{})}var Ng=class Pg{constructor(e,r,n,s){this.requestSequence=e,this.responseSequence=r,this.lastTsn=n,this.streams=s}static type=13;get type(){return Pg.type}get bytes(){let e=Buffer.from(ui.jspack.Pack("!LLL",[this.requestSequence,this.responseSequence,this.lastTsn]));return Buffer.concat([e,...this.streams.map(r=>Buffer.from(ui.jspack.Pack("!H",[r])))])}static parse(e){let[r,n,s]=ui.jspack.Unpack("!LLL",e),i=[];for(let o=12;o<e.length;o+=2)i.push(ui.jspack.Unpack("!H",e.slice(o))[0]);return new Pg(r,n,s,i)}},U5=class Og{constructor(e,r){this.requestSequence=e,this.newStreams=r}static type=17;get type(){return Og.type}get bytes(){return Buffer.from(ui.jspack.Pack("!LHH",[this.requestSequence,this.newStreams,0]))}static parse(e){let[r,n]=ui.jspack.Unpack("!LHH",e);return new Og(r,n)}},Ch={ReconfigResultSuccessPerformed:1,BadSequenceNumber:5},Fh=class Lg{constructor(e,r){this.responseSequence=e,this.result=r}static type=16;get type(){return Lg.type}get bytes(){return Buffer.from(ui.jspack.Pack("!LL",[this.responseSequence,this.result]))}static parse(e){let[r,n]=ui.jspack.Unpack("!LL",e);return new Lg(r,n)}},$3={13:Ng,16:Fh,17:U5},At=tt("werift/sctp/sctp"),Sk=24,Ek=60,W3=65535,Ln=1200,Md=1,D5=2,Ug=4,G3=10,Ak=8,X3=1/8,Y3=1/4,Z3=3,Ck=1,Ik=60,cp=2**32,Tk=200,_k=30,J3=135,Q3=7,e8=32776,t8=49152,Bk=["new","closed","connected","connecting"],kk=class Dg{constructor(e,r=5e3){this.transport=e,this.port=r,this.localPort=this.port,this.transport.onData=n=>{this.handleData(n)}}flush=new be;stateChanged=wk(Bk);onReconfigStreams=new be;onReceive=new be;onSackReceived=async()=>{};associationState=1;started=!1;state="new";isServer=!0;isStopping=!1;isClosed=!1;hmacKey=pk(16);localPartialReliability=!0;localPort;localVerificationTag=V1();remoteExtensions=[];remotePartialReliability=!0;remotePort;remoteVerificationTag=0;advertisedRwnd=1024*1024;peerAdvertisedRwnd=this.advertisedRwnd;get peerRwnd(){return Math.max(0,this.peerAdvertisedRwnd-this.flightSize)}inboundStreams={};_inboundStreamsCount=0;_inboundStreamsMax=W3;lastReceivedTsn;sackDuplicates=[];sackMisOrdered=new Set;sackNeeded=!1;sackPacketCount=0;sackHasNewDataInPacket=!1;sackImmediate=!1;sackTimeout;cwnd=3*Ln;fastRecoveryExit;fastRecoveryTransmit=!1;forwardTsnChunk;flightSize=0;outboundQueue=[];outboundStreamSeq={};_outboundStreamsCount=W3;localTsn=Number(V1());lastSackedTsn=Ta(this.localTsn);advancedPeerAckTsn=Ta(this.localTsn);partialBytesAcked=0;sentQueue=[];transmitting=!1;transmitRequested=!1;reconfigRequestSeq=this.localTsn;reconfigResponseSeq=0;reconfigRequest;reconfigQueue=[];srtt;rttvar;rto=Z3;timer1Handle;timer1Chunk;timer1Failures=0;timer2Handle;timer2Chunk;timer2Failures=0;timer3Handle;timerReconfigHandle;timerReconfigFailures=0;timerHeartbeatHandle;heartbeatInterval=_k;ssthresh;get isStopped(){return this.isStopping||this.isClosed}get maxChannels(){if(this._inboundStreamsCount>0)return Math.min(this._inboundStreamsCount,this._outboundStreamsCount)}static client(e,r=5e3){let n=new Dg(e,r);return n.isServer=!1,n}static server(e,r=5e3){let n=new Dg(e,r);return n.isServer=!0,n}async handleData(e){if(this.isStopped)return;let r,[,,n,s]=yk(e);if(s.filter(o=>o.type===jh.type).length>0){if(s.length!=1)throw new Error;r=0}else r=this.localVerificationTag;if(n===r){this.sackHasNewDataInPacket=!1;for(let o of s)await this.receiveChunk(o);this.sackNeeded&&(this.sackHasNewDataInPacket&&this.sackPacketCount++,this.sackPacketCount>=2&&(this.sackImmediate=!0),await this.scheduleSack())}}async scheduleSack(){if(!this.isStopped&&this.sackNeeded){if(this.sackImmediate){this.sackTimeout&&(clearTimeout(this.sackTimeout),this.sackTimeout=void 0),await this.sendSack();return}this.sackTimeout||(this.sackTimeout=setTimeout(()=>{this.sackTimeout=void 0,this.sendSack().catch(e=>{At("send delayed sack failed",e.message)})},Tk))}}async sendSack(){if(this.isStopped||!this.sackNeeded)return;let e=[],r;[...this.sackMisOrdered].sort().forEach(s=>{let i=(s-this.lastReceivedTsn)%cp;s===r?e[e.length-1][1]=i:e.push([i,i]),r=Yc(s)});let n=new Rg(0,void 0);n.cumulativeTsn=this.lastReceivedTsn,n.advertisedRwnd=Math.max(0,this.advertisedRwnd),n.duplicates=[...this.sackDuplicates],n.gaps=e,await this.sendChunk(n).catch(s=>{At("send sack failed",s.message)}),this.sackDuplicates=[],this.sackNeeded=!1,this.sackPacketCount=0,this.sackImmediate=!1}async receiveChunk(e){switch(e.type){case Vh.type:this.receiveDataChunk(e);break;case jh.type:{if(!this.isServer)return;let r=e;At("receive init",r),this.lastReceivedTsn=Ta(r.initialTsn),this.reconfigResponseSeq=Ta(r.initialTsn),this.remoteVerificationTag=r.initiateTag,this.ssthresh=r.advertisedRwnd,this.peerAdvertisedRwnd=r.advertisedRwnd,this.getExtensions(r.params),this._inboundStreamsCount=Math.min(r.outboundStreams,this._inboundStreamsMax),this._outboundStreamsCount=Math.min(this._outboundStreamsCount,r.inboundStreams);let n=new Ag;n.initiateTag=this.localVerificationTag,n.advertisedRwnd=this.advertisedRwnd,n.outboundStreams=this._outboundStreamsCount,n.inboundStreams=this._inboundStreamsCount,n.initialTsn=this.localTsn,this.setExtensions(n.params);let s=Date.now()/1e3,i=Buffer.from(Hh.jspack.Pack("!L",[s]));i=Buffer.concat([i,K3("sha1",this.hmacKey).update(i).digest()]),n.params.push([Q3,i]),At("send initAck",n),await this.sendChunk(n).catch(o=>{At("send initAck failed",o.message)})}break;case Ag.type:{if(this.associationState!=2)return;let r=e;this.timer1Cancel(),this.lastReceivedTsn=Ta(r.initialTsn),this.reconfigResponseSeq=Ta(r.initialTsn),this.remoteVerificationTag=r.initiateTag,this.ssthresh=r.advertisedRwnd,this.peerAdvertisedRwnd=r.advertisedRwnd,this.getExtensions(r.params),this._inboundStreamsCount=Math.min(r.outboundStreams,this._inboundStreamsMax),this._outboundStreamsCount=Math.min(this._outboundStreamsCount,r.inboundStreams);let n=new Cg;for(let[s,i]of r.params)if(s===Q3){n.body=i;break}await this.sendChunk(n).catch(s=>{At("send echo failed",s.message)}),this.timer1Start(n),this.setState(3)}break;case Rg.type:await this.receiveSackChunk(e);break;case Bg.type:{let r=new A5;r.params=e.params,await this.sendChunk(r).catch(n=>{At("send heartbeat ack failed",n.message)})}break;case Tg.type:this.setState(1);break;case _5.type:{this.timer2Cancel(),this.setState(7);let r=new k5;await this.sendChunk(r).catch(n=>{At("send shutdown ack failed",n.message)}),this.t2Start(r),this.setState(6)}break;case zh.type:At("ErrorChunk",e.descriptions);break;case Cg.type:{if(!this.isServer)return;let n=e.body,s=K3("sha1",this.hmacKey).update(n.slice(0,4)).digest();if(n?.length!=Sk||!n.slice(4).equals(s)){At("x State cookie is invalid");return}let i=Date.now()/1e3,o=Hh.jspack.Unpack("!L",n)[0];if(o<i-Ek||o>i){let c=new zh(0,void 0);c.params.push([zh.CODE.StaleCookieError,Buffer.concat([...Array(8)].map(()=>Buffer.from("\0")))]),await this.sendChunk(c).catch(f=>{At("send errorChunk failed",f.message)});return}let a=new Ig;await this.sendChunk(a).catch(c=>{At("send cookieAck failed",c.message)}),this.setState(4)}break;case Ig.type:{if(this.associationState!=3)return;this.timer1Cancel(),this.setState(4)}break;case N5.type:{if(this.associationState!=8)return;this.timer2Cancel(),this.setState(1)}break;case kg.type:{if(this.associationState!=4)return;let r=e;for(let[n,s]of r.params){let i=$3[n];i&&await this.receiveReconfigParam(i.parse(s))}}break;case qh.type:this.receiveForwardTsnChunk(e);break}}getExtensions(e){for(let[r,n]of e)r===t8?this.remotePartialReliability=!0:r===e8&&(this.remoteExtensions=[...n])}async receiveReconfigParam(e){switch(At("receiveReconfigParam",$3[e.type]),e.type){case Ng.type:{let r=e,n=new Fh(r.requestSequence,Ch.ReconfigResultSuccessPerformed);this.reconfigResponseSeq=r.requestSequence,await this.sendReconfigParam(n),await Promise.all(r.streams.map(async s=>{delete this.inboundStreams[s],this.outboundStreamSeq[s]&&(this.reconfigQueue.includes(s)||this.reconfigQueue.push(s))})),await this.transmitReconfigRequest(),this.onReconfigStreams.execute(r.streams)}break;case Fh.type:{let r=e;if(r.result!==Ch.ReconfigResultSuccessPerformed)At("OutgoingSSNResetRequestParam failed",Object.keys(Ch).find(n=>Ch[n]===r.result));else if(r.responseSequence===this.reconfigRequest?.requestSequence){let n=this.reconfigRequest.streams.map(s=>(delete this.outboundStreamSeq[s],s));this.onReconfigStreams.execute(n),this.reconfigRequest=void 0,this.timerReconfigCancel(),this.rto=Z3,this.timerReconfigFailures=0,this.reconfigQueue.length>0&&await this.transmitReconfigRequest()}}break;case U5.type:{let r=e;this._inboundStreamsCount+=r.newStreams;let n=new Fh(r.requestSequence,1);this.reconfigResponseSeq=r.requestSequence,await this.sendReconfigParam(n)}break}}receiveDataChunk(e){if(this.sackNeeded=!0,this.markReceived(e.tsn)){this.sackImmediate=!0;return}this.sackHasNewDataInPacket=!0,this.sackImmediate=!0,(e.flags&Md)===0&&(this.sackImmediate=!0),this.sackMisOrdered.size>0&&(this.sackImmediate=!0);let r=this.getInboundStream(e.streamId);r.addChunk(e),this.advertisedRwnd-=e.userData.length;for(let n of r.popMessages())this.advertisedRwnd+=n[2].length,this.receive(...n)}async receiveSackChunk(e){if(ai(this.lastSackedTsn,e.cumulativeTsn))return;let r=Date.now()/1e3;this.lastSackedTsn=e.cumulativeTsn;let n=this.flightSize>=this.cwnd,s=0,i=0;for(;this.sentQueue.length>0&&Id(this.lastSackedTsn,this.sentQueue[0].tsn);){let a=this.sentQueue.shift();s++,a?.acked||(i+=a.bookSize,this.flightSizeDecrease(a)),s===1&&a.sentCount===1&&this.updateRto(r-a.sentTime)}this.sentQueue.length||(this.sentQueue=[]);let o=!1;if(e.gaps.length>0){let a=new Set,c;e.gaps.forEach(l=>{for(let p=l[0];p<l[1]+1;p++)c=(e.cumulativeTsn+p)%cp,a.add(c)});let f=e.cumulativeTsn;for(let l of this.sentQueue){if(ai(l.tsn,c))break;a.has(l.tsn)&&!l.acked&&(i+=l.bookSize,l.acked=!0,this.flightSizeDecrease(l),f=l.tsn)}for(let l of this.sentQueue){if(ai(l.tsn,f))break;a.has(l.tsn)||(l.misses++,l.misses===3&&(l.misses=0,this.maybeAbandon(l)||(l.retransmit=!0),l.acked=!1,this.flightSizeDecrease(l),o=!0))}}this.fastRecoveryExit===void 0?(s&&n&&(this.cwnd<=this.ssthresh?this.cwnd+=Math.min(i,Ln):(this.partialBytesAcked+=i,this.partialBytesAcked>=this.cwnd&&(this.partialBytesAcked-=this.cwnd,this.cwnd+=Ln))),o&&(this.ssthresh=Math.max(Math.floor(this.cwnd/2),4*Ln),this.cwnd=this.ssthresh,this.partialBytesAcked=0,this.fastRecoveryExit=this.sentQueue[this.sentQueue.length-1].tsn,this.fastRecoveryTransmit=!0)):Id(e.cumulativeTsn,this.fastRecoveryExit)&&(this.fastRecoveryExit=void 0),this.sentQueue.length===0?this.timer3Cancel():s>0&&this.timer3Restart(),this.peerAdvertisedRwnd=e.advertisedRwnd,this.updateAdvancedPeerAckPoint(),await this.onSackReceived(),await this.transmit()}receiveForwardTsnChunk(e){if(this.sackNeeded=!0,this.sackImmediate=!0,Id(this.lastReceivedTsn,e.cumulativeTsn))return;let r=n=>ai(n,this.lastReceivedTsn);this.lastReceivedTsn=e.cumulativeTsn,this.sackMisOrdered=new Set([...this.sackMisOrdered].filter(r));for(let n of[...this.sackMisOrdered].sort())if(n===Yc(this.lastReceivedTsn))this.lastReceivedTsn=n;else break;this.sackDuplicates=this.sackDuplicates.filter(r),this.sackMisOrdered=new Set([...this.sackMisOrdered].filter(r));for(let[n,s]of e.streams){let i=this.getInboundStream(n);i.streamSequenceNumber=Tr(s,1);for(let o of i.popMessages())this.advertisedRwnd+=o[2].length,this.receive(...o)}Object.values(this.inboundStreams).forEach(n=>{this.advertisedRwnd+=n.pruneChunks(this.lastReceivedTsn)})}updateRto(e){this.srtt?(this.rttvar=(1-Y3)*this.rttvar+Y3*Math.abs(this.srtt-e),this.srtt=(1-X3)*this.srtt+X3*e):(this.rttvar=e/2,this.srtt=e),this.rto=Math.max(Ck,Math.min(this.srtt+4*this.rttvar,Ik))}receive(e,r,n){this.onReceive.execute(e,r,n)}getInboundStream(e){return this.inboundStreams[e]||(this.inboundStreams[e]=new Rk),this.inboundStreams[e]}markReceived(e){if(Id(this.lastReceivedTsn,e)||this.sackMisOrdered.has(e))return this.sackDuplicates.push(e),!0;this.sackMisOrdered.add(e);for(let n of[...this.sackMisOrdered].sort())if(n===Yc(this.lastReceivedTsn))this.lastReceivedTsn=n;else break;let r=n=>ai(n,this.lastReceivedTsn);return this.sackDuplicates=this.sackDuplicates.filter(r),this.sackMisOrdered=new Set([...this.sackMisOrdered].filter(r)),!1}send=async(e,r,n,{expiry:s,maxRetransmits:i,ordered:o}={expiry:void 0,maxRetransmits:void 0,ordered:!0})=>{let a=o&&this.outboundStreamSeq[e]||0,c=Math.ceil(n.length/Ln),f=0,l=[];for(let p=0;p<c;p++){let x=new Vh(0,void 0);x.flags=0,o||(x.flags=Ug),p===0&&(x.flags|=D5),p===c-1&&(x.flags|=Md),x.tsn=this.localTsn,x.streamId=e,x.streamSeqNum=a,x.protocol=r,x.userData=n.slice(f,f+Ln),x.bookSize=x.userData.length,x.expiry=s,x.maxRetransmits=i,f+=Ln,this.localTsn=Yc(this.localTsn),l.push(x)}for(l.forEach(p=>{this.outboundQueue.push(p)}),o&&(this.outboundStreamSeq[e]=Tr(a,1)),await this.transmit();this.outboundQueue.length;)await this.flush.asPromise()};async transmit(){if(!this.isStopped){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;this.forwardTsnChunk&&(await this.sendChunk(this.forwardTsnChunk).catch(s=>{At("send forwardTsn failed",s.message)}),this.forwardTsnChunk=void 0,this.timer3Handle||this.timer3Start());let e=this.fastRecoveryExit!=null?2*Ln:4*Ln,r=Math.min(this.flightSize+e,this.cwnd),n=!0;for(let s of this.sentQueue){if(s.retransmit){if(this.fastRecoveryTransmit)this.fastRecoveryTransmit=!1;else if(this.flightSize>=r)break;this.flightSizeIncrease(s),s.misses=0,s.retransmit=!1,s.sentCount++,await this.sendChunk(s).catch(i=>{At("send data failed",i.message)}),n&&this.timer3Restart()}n=!1}for(;this.outboundQueue.length>0&&this.flightSize<r&&this.peerRwnd>0;){let s=this.outboundQueue.shift();if(!s)break;if(s.bookSize>this.peerRwnd&&this.flightSize>0){this.outboundQueue.unshift(s);break}this.sentQueue.push(s),this.flightSizeIncrease(s),s.sentCount++,s.sentTime=Date.now()/1e3,await this.sendChunk(s).catch(i=>{At("send data outboundQueue failed",i.message)}),this.timer3Handle||this.timer3Start()}this.outboundQueue.length||(this.outboundQueue=[]),this.flush.execute()}async transmitReconfigRequest(){if(this.reconfigQueue.length>0&&this.associationState===4&&!this.reconfigRequest){let e=[...new Set(this.reconfigQueue)],r=e.slice(0,J3);this.reconfigQueue=e.slice(J3);let n=new Ng(this.reconfigRequestSeq,this.reconfigResponseSeq,Ta(this.localTsn),r);this.reconfigRequestSeq=Yc(this.reconfigRequestSeq),this.reconfigRequest=n,await this.sendReconfigParam(n),this.timerReconfigHandleStart()}}async sendReconfigParam(e){At("sendReconfigParam",e);let r=new kg;r.params.push([e.type,e.bytes]),await this.sendChunk(r).catch(n=>{At("send reconfig failed",n.message)})}async sendResetRequest(e){At("sendResetRequest",e);let r=new Vh(0,void 0);r.streamId=e,this.outboundQueue.push(r),this.timer3Handle||await this.transmit()}flightSizeIncrease(e){this.flightSize+=e.bookSize}flightSizeDecrease(e){this.flightSize=Math.max(0,this.flightSize-e.bookSize)}timer1Start(e){if(this.timer1Handle)throw new Error;this.timer1Chunk=e,this.timer1Failures=0,this.timer1Handle=setTimeout(this.timer1Expired,this.rto*1e3)}timer1Expired=()=>{if(!this.isStopped)if(this.timer1Failures++,this.timer1Handle=void 0,this.timer1Failures>Ak)this.setState(1);else{if(setImmediate(()=>{this.isStopped||this.sendChunk(this.timer1Chunk).catch(e=>{At("send timer1 chunk failed",e.message)})}),this.isStopped)return;this.timer1Handle=setTimeout(this.timer1Expired,this.rto*1e3)}};timer1Cancel(){this.timer1Handle&&(clearTimeout(this.timer1Handle),this.timer1Handle=void 0,this.timer1Chunk=void 0)}t2Start(e){if(this.timer2Handle)throw new Error;this.timer2Chunk=e,this.timer2Failures=0,this.timer2Handle=setTimeout(this.timer2Expired,this.rto*1e3)}timer2Expired=()=>{if(!this.isStopped)if(this.timer2Failures++,this.timer2Handle=void 0,this.timer2Failures>G3)this.setState(1);else{if(setImmediate(()=>{this.isStopped||this.sendChunk(this.timer2Chunk).catch(e=>{At("send timer2Chunk failed",e.message)})}),this.isStopped)return;this.timer2Handle=setTimeout(this.timer2Expired,this.rto*1e3)}};timer2Cancel(){this.timer2Handle&&(clearTimeout(this.timer2Handle),this.timer2Handle=void 0,this.timer2Chunk=void 0)}timer3Start(){if(!this.isStopped){if(this.timer3Handle)throw new Error;this.timer3Handle=setTimeout(this.timer3Expired,this.rto*1e3)}}timer3Restart(){this.isStopped||(this.timer3Cancel(),this.timer3Handle=setTimeout(this.timer3Expired,this.rto*1e3))}timer3Expired=()=>{this.isStopped||(this.timer3Handle=void 0,this.sentQueue.forEach(e=>{this.maybeAbandon(e)||(e.retransmit=!0)}),this.updateAdvancedPeerAckPoint(),this.fastRecoveryExit=void 0,this.flightSize=0,this.partialBytesAcked=0,this.ssthresh=Math.max(Math.floor(this.cwnd/2),4*Ln),this.cwnd=Ln,this.transmit())};timer3Cancel(){this.timer3Handle&&(clearTimeout(this.timer3Handle),this.timer3Handle=void 0)}timerReconfigHandleStart(){this.isStopped||this.timerReconfigHandle||(At("timerReconfigHandleStart",{rto:this.rto}),this.timerReconfigFailures=0,this.timerReconfigHandle=setTimeout(this.timerReconfigHandleExpired,this.rto*1e3))}timerReconfigHandleExpired=async()=>{if(!this.isStopped){if(this.timerReconfigFailures++,this.rto=Math.ceil(this.rto*1.5),this.timerReconfigFailures>G3)At("timerReconfigFailures",this.timerReconfigFailures),this.setState(1),this.timerReconfigHandle=void 0;else if(this.reconfigRequest){if(At("timerReconfigHandleExpired",this.timerReconfigFailures,this.rto),await this.sendReconfigParam(this.reconfigRequest),this.isStopped)return;this.timerReconfigHandle=setTimeout(this.timerReconfigHandleExpired,this.rto*1e3)}}};timerReconfigCancel(){this.timerReconfigHandle&&(At("timerReconfigCancel"),clearTimeout(this.timerReconfigHandle),this.timerReconfigHandle=void 0,this.timerReconfigFailures=0)}heartbeatStart(){this.timerHeartbeatHandle||this.associationState!==4||(this.timerHeartbeatHandle=setTimeout(this.timerHeartbeatExpired,(this.rto+this.heartbeatInterval)*1e3))}heartbeatRestart(){this.heartbeatCancel(),this.heartbeatStart()}heartbeatCancel(){this.timerHeartbeatHandle&&(clearTimeout(this.timerHeartbeatHandle),this.timerHeartbeatHandle=void 0)}timerHeartbeatExpired=async()=>{if(this.timerHeartbeatHandle=void 0,this.associationState===4){if(this.flightSize===0&&this.outboundQueue.length===0){let e=new Bg;e.params.push([1,Buffer.from(Hh.jspack.Pack("!L",[Math.floor(Date.now()/1e3)]))]),await this.sendChunk(e).catch(r=>{At("send heartbeat failed",r.message)})}this.heartbeatStart()}};setHeartbeatInterval(e){if(e<=0)throw new Error("heartbeat interval must be > 0");this.heartbeatInterval=e,this.heartbeatRestart()}updateAdvancedPeerAckPoint(){ai(this.lastSackedTsn,this.advancedPeerAckTsn)&&(this.advancedPeerAckTsn=this.lastSackedTsn);let e=0,r={};for(;this.sentQueue.length>0&&this.sentQueue[0].abandoned;){let n=this.sentQueue.shift();this.advancedPeerAckTsn=n.tsn,e++,n.flags&Ug||(r[n.streamId]=n.streamSeqNum)}this.sentQueue.length||(this.sentQueue=[]),e&&(this.forwardTsnChunk=new qh(0,void 0),this.forwardTsnChunk.cumulativeTsn=this.advancedPeerAckTsn,this.forwardTsnChunk.streams=Object.entries(r).map(([n,s])=>[Number(n),s]))}maybeAbandon(e){if(e.abandoned)return!0;if(!(!!e.maxRetransmits&&e.maxRetransmits<e.sentCount||!!e.expiry&&e.expiry<Date.now()/1e3))return!1;let n=this.sentQueue.findIndex(s=>s.type===e.type);for(let s=n;s>=0;s--){let i=this.sentQueue[s];if(i.abandoned=!0,i.retransmit=!1,i.flags&Md)break}for(let s=n;s<this.sentQueue.length;s++){let i=this.sentQueue[s];if(i.abandoned=!0,i.retransmit=!1,i.flags&Md)break}return!0}static getCapabilities(){return new Nk(65536)}setRemotePort(e){this.remotePort=e}async start(e){this.started||(this.started=!0,this.setConnectionState("connecting"),e&&this.setRemotePort(e),this.isServer||await this.init())}async init(){let e=new jh;e.initiateTag=this.localVerificationTag,e.advertisedRwnd=this.advertisedRwnd,e.outboundStreams=this._outboundStreamsCount,e.inboundStreams=this._inboundStreamsMax,e.initialTsn=this.localTsn,this.setExtensions(e.params),At("send init",e);try{await this.sendChunk(e),this.timer1Start(e),this.setState(2)}catch(r){At("send init failed",r.message)}}setExtensions(e){let r=[];this.localPartialReliability&&(e.push([t8,Buffer.from("")]),r.push(qh.type)),r.push(xk.type),e.push([e8,Buffer.from(r)])}async sendChunk(e){if(this.state==="closed")return;if(this.remotePort===void 0)throw new Error("invalid remote port");let r=bk(this.localPort,this.remotePort,this.remoteVerificationTag,e);await this.transport.send(r)}setState(e){e!=this.associationState&&(this.associationState=e),e===4?(this.isStopping=!1,this.isClosed=!1,this.setConnectionState("connected"),this.heartbeatStart()):e===1&&(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(e){this.state=e,At("setConnectionState",e),this.stateChanged[e].execute()}async stop(){if(this.isStopped){this.setState(1);return}this.isStopping=!0,this.transport.onData=void 0,this.sackTimeout&&(clearTimeout(this.sackTimeout),this.sackTimeout=void 0),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 e=new Tg;await this.sendChunk(e).catch(r=>{At("send abort failed",r.message)})}removeAllListeners(){Object.values(this.stateChanged).forEach(e=>e.allUnsubscribe())}},Rk=class{reassembly=[];streamSequenceNumber=0;constructor(){}addChunk(t){if(this.reassembly.length===0||ai(t.tsn,this.reassembly[this.reassembly.length-1].tsn)){this.reassembly.push(t);return}for(let[e,r]of vk(this.reassembly)){if(r.tsn===t.tsn)throw new Error("duplicate chunk in reassembly");if(ai(r.tsn,t.tsn)){this.reassembly.splice(e,0,t);break}}}*popMessages(){let t=0,e,r,n;for(;t<this.reassembly.length;){let s=this.reassembly[t];if(e===void 0){if(n=!(s.flags&Ug),!(s.flags&D5)){if(n)break;t++;continue}if(n&&Fg(s.streamSeqNum,this.streamSequenceNumber))break;r=s.tsn,e=t}else if(s.tsn!==r){if(n)break;e=void 0,t++;continue}if(s.flags&Md){let i=this.reassembly.slice(e,t+1).map(a=>a.userData).reduce((a,c)=>(a.push(c),a.push(Buffer.from("")),a),[]);i.pop();let o=Buffer.concat(i);this.reassembly=[...this.reassembly.slice(0,e),...this.reassembly.slice(t+1)],n&&s.streamSeqNum===this.streamSequenceNumber&&(this.streamSequenceNumber=Tr(this.streamSequenceNumber,1)),t=e,yield[s.streamId,s.protocol,o]}else t++;r=Yc(r)}}pruneChunks(t){let e=-1,r=0;for(let[n,s]of this.reassembly.entries())if(Id(t,s.tsn))e=n,r+=s.userData.length;else break;return this.reassembly=this.reassembly.slice(e+1),r}},Nk=class{constructor(t){this.maxMessageSize=t}};function Ta(t){return(t-1)%cp}function Yc(t){return(t+1)%cp}var Kc=tt("werift:packages/webrtc/src/transport/sctp.ts"),Hd=65536,Pk=class M5{constructor(e=5e3,r=Hd){this.port=e,this.maxMessageSize=r}dtlsTransport;sctp;onDataChannel=new be;id=hk().toString();mid;mLineIndex;bundled=!1;dataChannels={};remoteMaxMessageSize=Hd;dataChannelQueue=[];dataChannelId;eventDisposer=[];setDtlsTransport(e){this.dtlsTransport&&this.dtlsTransport.id===e.id||(this.eventDisposer.forEach(r=>r()),this.dtlsTransport=e,this.sctp=new kk(new Ok(this.dtlsTransport),this.port),this.eventDisposer=[...[this.sctp.onReceive.subscribe(this.datachannelReceive),this.sctp.onReconfigStreams.subscribe(r=>{r.forEach(n=>{let s=this.dataChannels[n];s&&(s.setReadyState("closing"),s.setReadyState("closed"),delete this.dataChannels[n])})}),this.sctp.stateChanged.connected.subscribe(()=>{Object.values(this.dataChannels).forEach(r=>{r.negotiated&&r.readyState!=="open"&&r.setReadyState("open")}),this.dataChannelFlush()}),this.sctp.stateChanged.closed.subscribe(()=>{Object.values(this.dataChannels).forEach(r=>{r.setReadyState("closed")}),this.dataChannels={}}),this.dtlsTransport.onStateChange.subscribe(r=>{r==="closed"&&this.sctp.setState(1)})].map(r=>r.unSubscribe),()=>this.sctp.onSackReceived=async()=>{}],this.sctp.onSackReceived=async()=>{await this.dataChannelFlush()})}get isServer(){return this.dtlsTransport.iceTransport.role!=="controlling"}channelByLabel(e){return Object.values(this.dataChannels).find(r=>r.label===e)}datachannelReceive=async(e,r,n)=>{if(r===Ah&&n.length>0)switch(Kc("DCEP",e,r,n),n[0]){case L3:{if(n.length<12){Kc("DATA_CHANNEL_OPEN data.length not enough");return}if(Object.keys(this.dataChannels).includes(e.toString()))Kc("datachannel already opened","retransmit ack");else{let[,i,,o,a,c]=Mh.jspack.Unpack("!BBHLHH",n),f=12,l=n.slice(f,f+a).toString("utf8");f+=a;let p=n.slice(f,f+c).toString("utf8");Kc("DATA_CHANNEL_OPEN",{channelType:i,reliability:o,streamId:e,label:l,protocol:p});let x=(i&3)===1?o:void 0,v=(i&3)===2?o:void 0,S=new G4({label:l,ordered:(i&128)===0,maxPacketLifeTime:v,maxRetransmits:x,protocol:p,id:e}),I=new W4(this,S,!1);I.isCreatedByRemote=!0,this.dataChannels[e]=I,this.onDataChannel.execute(I),I.setReadyState("open")}let s=this.dataChannels[e];this.dataChannelQueue.push([s,Ah,Buffer.from(Mh.jspack.Pack("!B",[O3]))]),await this.dataChannelFlush()}break;case O3:{Kc("DATA_CHANNEL_ACK",e,r);let s=this.dataChannels[e];if(!s)throw new Error("channel not found");s.setReadyState("open")}break}else{let s=this.dataChannels[e];if(s){let i=(()=>{switch(r){case U3:return n.toString("utf8");case kB:return"";case D3:return n;case RB:return Buffer.from([]);default:throw new Error}})();s.messagesReceived++,s.bytesReceived+=n.length,s.onMessage.execute(i),s.emit("message",{data:i}),s.onmessage&&s.onmessage({data:i})}}};dataChannelAddNegotiated(e){if(e.id==null)throw new Error;if(this.dataChannels[e.id])throw new Error;this.dataChannels[e.id]=e,this.sctp.associationState===4&&e.setReadyState("open")}dataChannelOpen(e){if(e.id){if(this.dataChannels[e.id])throw new Error(`Data channel with ID ${e.id} already registered`);this.dataChannels[e.id]=e}let r=BB,n=0,s=0;e.ordered||(r=128),e.maxRetransmits?(r=1,s=e.maxRetransmits):e.maxPacketLifeTime&&(r=2,s=e.maxPacketLifeTime);let i=Mh.jspack.Pack("!BBHLHH",[L3,r,n,s,e.label.length,e.protocol.length]),o=Buffer.concat([Buffer.from(i),Buffer.from(e.label,"utf8"),Buffer.from(e.protocol,"utf8")]);this.dataChannelQueue.push([e,Ah,o]),this.dataChannelFlush()}async dataChannelFlush(){if(this.sctp.associationState==4){for(;this.dataChannelQueue.length>0;){let[e,r,n]=this.dataChannelQueue.shift(),s=e.id;if(s===void 0){for(s=this.dataChannelId;Object.keys(this.dataChannels).includes(s.toString());)s+=2;this.dataChannels[s]=e,e.setId(s)}if(r===Ah)await this.sctp.send(s,r,n,{ordered:!0});else{let i=e.maxPacketLifeTime?Date.now()+e.maxPacketLifeTime/1e3:void 0;await this.sctp.send(s,r,n,{expiry:i,maxRetransmits:e.maxRetransmits,ordered:e.ordered}),e.addBufferedAmount(-n.length)}}this.dataChannelQueue=[]}}assertSendableMessageSize(e){if(this.remoteMaxMessageSize!==0&&e>this.remoteMaxMessageSize)throw new Error(`max-message-size exceeded: ${e} > ${this.remoteMaxMessageSize}`)}datachannelSend=(e,r)=>{let n=Buffer.isBuffer(r)?r:Buffer.from(r),s=gB(r);return this.assertSendableMessageSize(s),e.addBufferedAmount(s),this.dataChannelQueue.push(typeof r=="string"?[e,U3,n]:[e,D3,n]),this.sctp.associationState!==4&&Kc("sctp not established",this.sctp.associationState),this.dataChannelFlush(),s};getCapabilities(){return M5.getCapabilities(this.maxMessageSize)}static getCapabilities(e=Hd){return new H5(e)}setRemoteMaxMessageSize(e){this.remoteMaxMessageSize=e??Hd}setRemotePort(e){this.sctp.setRemotePort(e)}async start(e){this.isServer?this.dataChannelId=0:this.dataChannelId=1,this.sctp.isServer=this.isServer,await this.sctp.start(e)}async stop(){this.dtlsTransport.dataReceiver=()=>{},await this.sctp.stop()}dataChannelClose(e){["closing","closed"].includes(e.readyState)||(e.setReadyState("closing"),this.sctp.associationState===4?(this.sctp.reconfigQueue.includes(e.id)||this.sctp.reconfigQueue.push(e.id),this.sctp.reconfigQueue.length===1&&this.sctp.transmitReconfigRequest()):(this.dataChannelQueue=this.dataChannelQueue.filter(r=>r[0].id!==e.id),this.sctp.reconfigQueue=this.sctp.reconfigQueue.filter(r=>r!==e.id),e.id&&delete this.dataChannels[e.id],e.setReadyState("closed")))}},H5=class{constructor(t){this.maxMessageSize=t}},Ok=class{constructor(t){this.dtls=t}set onData(t){this.dtls.dataReceiver=t}send=t=>this.dtls.sendData(t);close(){}},Kh=class j5{version=0;origin;name="-";time="0 0";host;group=[];extMapAllowMixed=!0;msidSemantic=[];media=[];type;dtlsRole;iceOptions;iceLite;icePassword;iceUsernameFragment;dtlsFingerprints=[];static parse(e){let[r,n]=Lk(e),s=new j5;r.forEach(o=>{if(o.startsWith("v="))s.version=Number.parseInt(o.slice(2),10);else if(o.startsWith("o="))s.origin=o.slice(2);else if(o.startsWith("s="))s.name=o.slice(2);else if(o.startsWith("c="))s.host=M1(o.slice(2));else if(o.startsWith("t="))s.time=o.slice(2);else if(o.startsWith("a=")){let[a,c]=H1(o);switch(a){case"fingerprint":{let[f,l]=c?.split(" ")||[];s.dtlsFingerprints.push(new Sg(f,l))}break;case"ice-lite":s.iceLite=!0;break;case"ice-options":s.iceOptions=c;break;case"ice-pwd":s.icePassword=c;break;case"ice-ufrag":s.iceUsernameFragment=c;break;case"group":j1(s.group,c);break;case"msid-semantic":j1(s.msidSemantic,c);break;case"setup":s.dtlsRole=H3[c];break;case"extmap-allow-mixed":s.extMapAllowMixed=!0;break}}});let i=s.group.find(o=>o.semantic==="BUNDLE");return n.forEach(o=>{let c=o[0].match(/^m=([^ ]+) ([0-9]+) ([A-Z/]+) (.+)/);if(!c)throw new Error("m line not found");let f=c[1],l=c[4].split(" "),p=["audio","video"].includes(f)?l.map(S=>Number(S)):void 0,x=new Mg(f,Number.parseInt(c[2]),c[3],p||l);if(x.dtlsParams=new Eg([...s.dtlsFingerprints],s.dtlsRole),x.iceParams=new h5({iceLite:s.iceLite,usernameFragment:s.iceUsernameFragment,password:s.icePassword}),x.iceOptions=s.iceOptions,s.media.push(x),o.slice(1).forEach(S=>{if(S.startsWith("c="))x.host=M1(S.slice(2));else if(S.startsWith("a=")){let[I,L]=H1(S);switch(I){case"candidate":if(!L)throw new Error;x.iceCandidates.push(V5(L));break;case"end-of-candidates":x.iceCandidatesComplete=!0;break;case"extmap":{let[ee,Pe]=L.split(" ");ee.includes("/")&&([ee]=ee.split("/")),x.rtp.headerExtensions.push(new li({id:Number.parseInt(ee),uri:Pe}))}break;case"fingerprint":{if(!L)throw new Error;let[ee,Pe]=L.split(" ");x.dtlsParams?.fingerprints.push(new Sg(ee,Pe))}break;case"ice-options":x.iceOptions=L;break;case"ice-pwd":x.iceParams.password=L;break;case"ice-ufrag":x.iceParams.usernameFragment=L;break;case"ice-lite":x.iceParams.iceLite=!0;break;case"max-message-size":x.sctpCapabilities=new H5(Number.parseInt(L,10));break;case"mid":x.rtp.muxId=L;break;case"msid":x.msid=L;break;case"rtcp":{let[ee,Pe]=oi(L," ");x.rtcpPort=Number.parseInt(ee),x.rtcpHost=M1(Pe)}break;case"rtcp-mux":x.rtcpMux=!0;break;case"setup":x.dtlsParams.role=H3[L];break;case"recvonly":case"sendonly":case"sendrecv":case"inactive":x.direction=I;break;case"rtpmap":{let[ee,Pe]=oi(L," "),[ie,ve,ze]=Pe.split("/"),he;x.kind==="audio"&&(he=ze?Number.parseInt(ze):1);let Ne=new Ma({mimeType:x.kind+"/"+ie,channels:he,clockRate:Number.parseInt(ve),payloadType:Number.parseInt(ee)});x.rtp.codecs.push(Ne)}break;case"sctpmap":{if(!L)throw new Error;let[ee,Pe]=oi(L," ");x.sctpMap[Number.parseInt(ee)]=Pe,x.sctpPort=Number.parseInt(ee)}break;case"sctp-port":if(!L)throw new Error;x.sctpPort=Number.parseInt(L);break;case"ssrc":{let[ee,Pe]=oi(L," "),ie=Number.parseInt(ee),[ve,ze]=oi(Pe,":"),he=x.ssrc.find(Ne=>Ne.ssrc===ie);he||(he=new jg({ssrc:ie}),x.ssrc.push(he)),e5.includes(ve)&&(he[ve]=ze)}break;case"ssrc-group":j1(x.ssrcGroup,L);break;case"rid":{let[ee,Pe]=oi(L," ");x.simulcastParameters.push(new X4({rid:ee,direction:Pe}))}break}}}),(!x.iceParams.usernameFragment||!x.iceParams.password)&&x.rtp.muxId&&i&&i.items.includes(x.rtp.muxId))for(let S=0;S<i.items.length;S++){if(!i.items.includes(S.toString()))continue;let I=s.media[S];if(I.iceParams?.usernameFragment&&I.iceParams.password){x.iceParams={...I.iceParams};break}}x.dtlsParams.role||(x.dtlsParams=void 0);let v=S=>x.rtp.codecs.find(I=>I.payloadType===S);o.slice(1).forEach(S=>{if(S.startsWith("a=")){let[I,L]=H1(S);if(I==="fmtp"){let[ee,Pe]=oi(L," "),ie=v(Number(ee));ie.parameters=Pe}else if(I==="rtcp-fb"){let[ee,Pe,ie]=L.split(" ");x.rtp.codecs.forEach(ve=>{["*",ve.payloadType.toString()].includes(ee)&&ve.rtcpFeedback.push(new bB({type:Pe,parameter:ie}))})}}})}),s}webrtcTrackId(e){if(e.msid?.includes(" ")){let r=e.msid.split(" ");for(let n of this.msidSemantic)if(n.semantic==="WMS"&&(n.items.includes(r[0])||n.items.includes("*")))return r[1]}}get string(){let e=[`v=${this.version}`,`o=${this.origin}`,`s=${this.name}`];this.host&&e.push(`c=${Hg(this.host)}`),e.push(`t=${this.time}`),this.group.forEach(s=>e.push(`a=group:${s.str}`)),this.extMapAllowMixed&&e.push("a=extmap-allow-mixed"),this.msidSemantic.forEach(s=>e.push(`a=msid-semantic:${s.str}`));let r=this.media.map(s=>s.toString()).join("");return e.join(`\r
125
+ `)+`\r
126
+ `+r}toJSON(){return new Uk(this.string,this.type)}toSdp(){return{type:this.type,sdp:this.string}}},Mg=class{constructor(t,e,r,n){this.kind=t,this.port=e,this.profile=r,this.fmt=n}host;direction;msid;rtcpPort;rtcpHost;rtcpMux=!1;ssrc=[];ssrcGroup=[];rtp={codecs:[],headerExtensions:[]};sctpCapabilities;sctpMap={};sctpPort;dtlsParams;iceParams;iceCandidates=[];iceCandidatesComplete=!1;iceOptions;simulcastParameters=[];toString(){let t=[];if(t.push(`m=${this.kind} ${this.port} ${this.profile} ${this.fmt.map(e=>e.toString()).join(" ")}`),this.host&&t.push(`c=${Hg(this.host)}`),this.iceCandidates.forEach(e=>{t.push(`a=candidate:${q5(e)}`)}),this.iceCandidatesComplete&&t.push("a=end-of-candidates"),this.iceParams?.usernameFragment&&t.push(`a=ice-ufrag:${this.iceParams.usernameFragment}`),this.iceParams?.password&&t.push(`a=ice-pwd:${this.iceParams.password}`),this.iceParams?.iceLite&&t.push("a=ice-lite"),this.iceOptions&&t.push(`a=ice-options:${this.iceOptions}`),this.dtlsParams&&(this.dtlsParams.fingerprints.forEach(e=>{t.push(`a=fingerprint:${e.algorithm} ${e.value}`)}),t.push(`a=setup:${vg[this.dtlsParams.role]}`)),this.direction&&t.push(`a=${this.direction}`),this.rtp.muxId&&t.push(`a=mid:${this.rtp.muxId}`),this.msid&&t.push(`a=msid:${this.msid}`),this.rtcpPort&&this.rtcpHost&&(t.push(`a=rtcp:${this.rtcpPort} ${Hg(this.rtcpHost)}`),this.rtcpMux&&t.push("a=rtcp-mux")),this.ssrcGroup.forEach(e=>{t.push(`a=ssrc-group:${e.str}`)}),this.ssrc.forEach(e=>{e5.forEach(r=>{let n=e[r];n!==void 0&&t.push(`a=ssrc:${e.ssrc} ${r}:${n}`)})}),this.rtp.codecs.forEach(e=>{t.push(`a=rtpmap:${e.payloadType} ${e.str}`),e.rtcpFeedback.forEach(r=>{let n=r.type;r.parameter&&(n+=` ${r.parameter}`),t.push(`a=rtcp-fb:${e.payloadType} ${n}`)}),e.parameters&&t.push(`a=fmtp:${e.payloadType} ${e.parameters}`)}),Object.keys(this.sctpMap).forEach(e=>{let r=this.sctpMap[Number(e)];t.push(`a=sctpmap:${e} ${r}`)}),this.sctpPort&&t.push(`a=sctp-port:${this.sctpPort}`),this.sctpCapabilities&&t.push(`a=max-message-size:${this.sctpCapabilities.maxMessageSize}`),this.rtp.headerExtensions.forEach(e=>t.push(`a=extmap:${e.id} ${e.uri}`)),this.simulcastParameters.length){this.simulcastParameters.forEach(s=>{t.push(`a=rid:${s.rid} ${s.direction}`)});let e="a=simulcast:",r=this.simulcastParameters.filter(s=>s.direction==="recv");r.length&&(e+=`recv ${r.map(s=>s.rid).join(";")} `);let n=this.simulcastParameters.filter(s=>s.direction==="send");n.length&&(e+=`send ${n.map(s=>s.rid).join(";")}`),t.push(e)}return t.join(`\r
127
+ `)+`\r
128
+ `}},Vd=class{constructor(t,e){this.semantic=t,this.items=e}get str(){return`${this.semantic} ${this.items.join(" ")}`}};function M1(t){let e=t.match(/^IN (IP4|IP6) ([^ ]+)$/);if(!e)throw new Error("exception");return e[2]}function Hg(t){return`IN IP${tk(t)?4:6} ${t}`}function q5(t){let e=`${t.foundation} ${t.component} ${t.protocol} ${t.priority} ${t.ip} ${t.port} typ ${t.type}`;return t.relatedAddress!=null&&(e+=` raddr ${t.relatedAddress}`),t.relatedPort!=null&&(e+=` rport ${t.relatedPort}`),t.tcpType!=null&&(e+=` tcptype ${t.tcpType}`),t.generation!=null&&(e+=` generation ${t.generation}`),t.ufrag!=null&&(e+=` ufrag ${t.ufrag}`),e}function Lk(t){let e=[],r=[],n=t.split(`\r
129
+ `);return n.length===1&&(n=t.split(`
130
+ `)),n.forEach(s=>{s.startsWith("m=")?r.push([s]):r.length>0?r[r.length-1].push(s):e.push(s)}),[e,r]}function H1(t){if(t.includes(":")){let e=oi(t.slice(2),":");return[e[0],e[1]]}else return[t.slice(2),void 0]}function j1(t,e,r=n=>n.toString()){let n=e.split(" ");n.length>0&&t.push(new Vd(n[0],n.slice(1).map(r)))}function V5(t){let e=ka.fromSdp(t);return Xd(e)}var Uk=class{constructor(t,e){this.sdp=t,this.type=e}static isThis(t){if(typeof t?.sdp=="string")return!0}toSdp(){return{sdp:this.sdp,type:this.type}}};function r8(t,e){let n=new bh(ek(64)).toString().slice(0,8),s=0;e.origin=`- ${n} ${s} IN IP4 0.0.0.0`,e.msidSemantic.push(new Vd("WMS",["*"])),e.type=t}function up(t){let e={};return t.split(";").forEach(r=>{if(r.includes("=")){let[n,s]=oi(r,"=");PB.includes(n)?e[n]=Number(s):e[n]=s}else if(r.includes(":")){let[n,s]=r.split(":");e[n]=Number.isNaN(Number(s))?s:Number(s)}else e[r]=void 0}),e}function UJ(t,e="="){let r=Object.entries(t).map(([n,s])=>s?`${n}${e}${s}`:n);if(r.length>0)return r.join(";")}var jg=class{ssrc;cname;msid;msLabel;label;constructor(t){Object.assign(this,t)}},Ih=tt("werift:packages/webrtc/src/media/rtpReceiver.ts"),z5=class{constructor(t,e,r){this.config=t,this.kind=e,this.rtcpSsrc=r}codecs={};get codecArray(){return Object.values(this.codecs).sort((t,e)=>t.payloadType-e.payloadType)}ssrcByRtx={};nack=new XB(this);audioRedHandler=new u7;type="receiver";uuid=CB().toString();tracks=[];trackBySSRC={};trackByRID={};lastSRtimestamp={};receiveLastSRTimestamp={};onPacketLost=this.nack.onPacketLost;onRtcp=new be;dtlsTransport;sdesMid;latestRid;latestRepairedRid;receiverTWCC;stopped=!1;remoteStreamId;remoteTrackId;rtcpRunning=!1;rtcpCancel=new AbortController;remoteStreams={};setDtlsTransport(t){this.dtlsTransport=t}get track(){return this.tracks[0]??new op({kind:this.kind})}get nackEnabled(){return this.codecArray[0]?.rtcpFeedback.find(t=>t.type==="nack")}get twccEnabled(){return this.codecArray[0]?.rtcpFeedback.find(t=>t.type===yB().type)}get pliEnabled(){return this.codecArray[0]?.rtcpFeedback.find(t=>t.type===sl().type)}prepareReceive(t){t.codecs.forEach(e=>{this.codecs[e.payloadType]=e}),t.encodings.forEach(e=>{e.rtx&&(this.ssrcByRtx[e.rtx.ssrc]=e.ssrc)})}setupTWCC(t){this.twccEnabled&&!this.receiverTWCC&&(this.receiverTWCC=new JB(this.dtlsTransport,this.rtcpSsrc,t))}addTrack(t){return this.tracks.find(r=>{if(r.rid)return r.rid===t.rid;if(r.ssrc)return r.ssrc===t.ssrc})?!1:(this.tracks.push(t),t.ssrc&&(this.trackBySSRC[t.ssrc]=t),t.rid&&(this.trackByRID[t.rid]=t),!0)}stop(){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)){this.rtcpRunning=!0;try{for(;this.rtcpRunning;){await U1(500+Math.random()*1e3,void 0,{signal:this.rtcpCancel.signal});let t=Object.entries(this.remoteStreams).map(([r,n])=>{let s=0,i=0;if(this.lastSRtimestamp[r]){s=this.lastSRtimestamp[r];let o=ap()-this.receiveLastSRTimestamp[r];o>0&&o<65536&&(i=jd(o*65536))}return new Gg({ssrc:Number(r),fractionLost:n.fraction_lost,packetsLost:n.packets_lost,highestSequence:n.max_seq,jitter:n.jitter,lsr:s,dlsr:i})}),e=new Kd({ssrc:this.rtcpSsrc,reports:t});try{this.config.debug.receiverReportDelay&&await U1(this.config.debug.receiverReportDelay),await this.dtlsTransport.sendRtcp([e])}catch(r){Ih("sendRtcp failed",r),await U1(500+Math.random()*1e3)}}}catch{}}}async getStats(){let t=Ha(),e=[];if(!this.dtlsTransport)return e;let r=kt("transport",this.dtlsTransport.id);for(let n of this.tracks){if(!n.ssrc)continue;let s=this.remoteStreams[n.ssrc];if(!s)continue;let i={type:"inbound-rtp",id:kt("inbound-rtp",n.ssrc),timestamp:t,ssrc:n.ssrc,kind:this.kind,transportId:r,codecId:this.codecs[0]?kt("codec",this.codecs[0].payloadType,r):void 0,mid:this.sdesMid,trackIdentifier:n.id,packetsReceived:s.packets_received,packetsLost:s.packets_lost,jitter:s.jitter};if(e.push(i),this.lastSRtimestamp[n.ssrc]){let o={type:"remote-outbound-rtp",id:kt("remote-outbound-rtp",n.ssrc),timestamp:t,ssrc:n.ssrc,kind:this.kind,transportId:r,codecId:i.codecId,localId:i.id,remoteTimestamp:this.receiveLastSRTimestamp[n.ssrc]*1e3};e.push(o)}}return e}async sendRtcpPLI(t){if(!this.pliEnabled){Ih("pli not supported",{mediaSsrc:t});return}if(this.stopped)return;Ih("sendRtcpPLI",{mediaSsrc:t});let e=new Fd({feedback:new tp({senderSsrc:this.rtcpSsrc,mediaSsrc:t})});try{await this.dtlsTransport.sendRtcp([e])}catch(r){Ih(r)}}handleRtcpPacket(t){switch(t.type){case tu.type:{let e=t;this.lastSRtimestamp[e.ssrc]=u5(e.senderInfo.ntpTimestamp),this.receiveLastSRTimestamp[e.ssrc]=ap();let r=this.trackBySSRC[t.ssrc];r&&r.onReceiveRtcp.execute(t)}break}this.onRtcp.execute(t)}handleRtpBySsrc=(t,e)=>{let r=this.trackBySSRC[t.header.ssrc];this.handleRTP(t,e,r)};handleRtpByRid=(t,e,r)=>{let n=this.trackByRID[e];this.trackBySSRC[t.header.ssrc]||(this.trackBySSRC[t.header.ssrc]=n),this.handleRTP(t,r,n)};handleRTP(t,e,r){if(this.stopped)return;let n=this.codecs[t.header.payloadType];if(!n)return;if(this.remoteStreams[t.header.ssrc]=this.remoteStreams[t.header.ssrc]??new QB(n.clockRate),this.remoteStreams[t.header.ssrc].add(t),this.receiverTWCC){let i=e[Dt.transportWideCC];if(!i==null)throw new Error("undefined");this.receiverTWCC.handleTWCC(i)}else this.twccEnabled&&this.setupTWCC(t.header.ssrc);if(n.name.toLowerCase()==="rtx"){let i=this.ssrcByRtx[t.header.ssrc],o=up(n.parameters??""),a=this.codecs[o.apt];if(t.payload.length<2)return;t=f7(t,a.payloadType,i),r=this.trackBySSRC[i]}let s;if(!(n.name.toLowerCase()==="red"&&(s=p4.deSerialize(t.payload),!Object.keys(this.codecs).includes(s.header.fields[0].blockPT.toString())))){if(r?.kind==="video"&&this.nackEnabled&&this.nack.addPacket(t),r)if(s){if(r.kind==="audio"){let i=this.audioRedHandler.push(s,t);for(let o of i)r.onReceiveRtp.execute(o.clone(),e)}}else r.onReceiveRtp.execute(t.clone(),e);this.runRtcp()}}},Ad=tt("werift:packages/webrtc/src/media/router.ts"),Dk=class{ssrcTable={};ridTable={};extIdUriMap={};constructor(){}registerRtpSender(t){this.ssrcTable[t.ssrc]=t}registerRtpReceiver(t,e){Ad("registerRtpReceiver",e),this.ssrcTable[e]=t}registerRtpReceiverBySsrc(t,e){Ad("registerRtpReceiverBySsrc",e),e.encodings.filter(r=>r.ssrc!=null).forEach((r,n)=>{this.registerRtpReceiver(t.receiver,r.ssrc),t.addTrack(new op({ssrc:r.ssrc,kind:t.kind,id:t.sender.trackId,remote:!0,codec:e.codecs[n]})),r.rtx&&this.registerRtpReceiver(t.receiver,r.rtx.ssrc)}),e.headerExtensions.forEach(r=>{this.extIdUriMap[r.id]=r.uri})}registerRtpReceiverByRid(t,e,r){let[n]=r.codecs;Ad("registerRtpReceiverByRid",e),t.addTrack(new op({rid:e.rid,kind:t.kind,id:t.sender.trackId,remote:!0,codec:n})),this.ridTable[e.rid]=t.receiver}routeRtp=t=>{let e=X_(t.header.extensions,this.extIdUriMap),r=this.ssrcTable[t.header.ssrc],n=e[Dt.sdesRTPStreamID];if(typeof n=="string"?(r=this.ridTable[n],r.latestRid=n,r.handleRtpByRid(t,n,e)):r?r.handleRtpBySsrc(t,e):(r=Object.values(this.ridTable).filter(o=>o instanceof z5).find(o=>o.trackBySSRC[t.header.ssrc]),r&&(Ad("simulcast register receiver by ssrc",t.header.ssrc),this.registerRtpReceiver(r,t.header.ssrc),r.handleRtpBySsrc(t,e))),!r){Ad("ssrcReceiver not found");return}let s=e[Dt.sdesMid];typeof s=="string"&&(r.sdesMid=s);let i=e[Dt.repairedRtpStreamId];typeof i=="string"&&(r.latestRepairedRid=i)};routeRtcp=t=>{let e=[];switch(t.type){case tu.type:t=t,e.push(this.ssrcTable[t.ssrc]);break;case Kd.type:t=t,t.reports.forEach(r=>{e.push(this.ssrcTable[r.ssrc])});break;case ip.type:{let r=t}break;case eu.type:{let r=t;r.feedback&&e.push(this.ssrcTable[r.feedback.mediaSourceSsrc])}break;case Fd.type:{let r=t;switch(r.feedback.count){case rp.count:{let n=r.feedback;e.push(this.ssrcTable[n.ssrcFeedbacks[0]])}break;default:e.push(this.ssrcTable[r.feedback.senderSsrc]||this.ssrcTable[r.feedback.mediaSsrc])}}break}e.filter(r=>r).forEach(r=>r.handleRtcpPacket(t))}},Mk=class{numPackets=0;totalSize=0;firstPacketSentAtMs=0;lastPacketSentAtMs=0;firstPacketReceivedAtMs=0;lastPacketReceivedAtMs=0;addPacket(t,e,r){this.numPackets===0?(this.firstPacketSentAtMs=e,this.firstPacketReceivedAtMs=r,this.lastPacketSentAtMs=e,this.lastPacketReceivedAtMs=r):(e<this.firstPacketSentAtMs&&(this.firstPacketSentAtMs=e),r<this.firstPacketReceivedAtMs&&(this.firstPacketReceivedAtMs=r),e>this.lastPacketSentAtMs&&(this.lastPacketSentAtMs=e),r>this.lastPacketReceivedAtMs&&(this.lastPacketReceivedAtMs=r)),this.numPackets++,this.totalSize+=t}reset(){this.numPackets=0,this.totalSize=0,this.firstPacketSentAtMs=0,this.lastPacketSentAtMs=0,this.firstPacketReceivedAtMs=0,this.lastPacketReceivedAtMs=0}get receiveBitrate(){let t=this.lastPacketReceivedAtMs-this.firstPacketReceivedAtMs,e=this.totalSize/t*8*1e3;return ep(e)}get sendBitrate(){let t=this.lastPacketSentAtMs-this.firstPacketSentAtMs,e=this.totalSize/t*8*1e3;return ep(e)}},$c=20,Hk=10,jk=class{congestion=!1;onAvailableBitrate=new be;onCongestion=new be;onCongestionScore=new be;congestionCounter=0;cumulativeResult=new Mk;sentInfos={};_congestionScore=1;get congestionScore(){return this._congestionScore}set congestionScore(t){this._congestionScore=t,this.onCongestionScore.execute(t)}_availableBitrate=0;get availableBitrate(){return this._availableBitrate}set availableBitrate(t){this._availableBitrate=t,this.onAvailableBitrate.execute(t)}constructor(){}receiveTWCC(t){let r=c5()-this.cumulativeResult.firstPacketSentAtMs;r>1e3&&(this.cumulativeResult.reset(),this.congestionCounter<$c?this.congestionCounter++:this.congestionScore<Hk&&this.congestionScore++,this.congestionCounter>=$c&&!this.congestion&&(this.congestion=!0,this.onCongestion.execute(this.congestion)));for(let n of t.packetResults){if(!n.received)continue;let s=n.sequenceNumber,i=this.sentInfos[s];i&&n.receivedAtMs&&this.cumulativeResult.addPacket(i.size,i.sendingAtMs,n.receivedAtMs)}if(r>=100&&this.cumulativeResult.numPackets>=20){if(this.availableBitrate=Math.min(this.cumulativeResult.sendBitrate,this.cumulativeResult.receiveBitrate),this.cumulativeResult.reset(),this.congestionCounter>-$c){let n=ep($c/2)+1,s=ep($c/4)+1,i=n-(n-s)/10*this.congestionScore;this.congestionCounter=this.congestionCounter-i}this.congestionCounter<=-$c&&(this.congestionScore>1&&(this.congestionScore--,this.onCongestion.execute(!1)),this.congestionCounter=0),this.congestionCounter<=0&&this.congestion&&(this.congestion=!1,this.onCongestion.execute(this.congestion))}}rtpPacketSent(t){Object.keys(t).map(e=>Number(e)).sort().filter(e=>e<t.wideSeq).forEach(e=>{delete this.sentInfos[e]}),this.sentInfos[t.wideSeq]=t}},q1=tt("werift:packages/webrtc/src/media/rtpSender.ts"),o8=128,a8=.85,qk=class{constructor(t){this.trackOrKind=t,this.kind=typeof this.trackOrKind=="string"?this.trackOrKind:this.trackOrKind.kind,typeof t!="string"&&(t.streamId&&(this.streamId=t.streamId),this.registerTrack(t))}type="sender";kind;ssrc=qg.jspack.Unpack("!L",n8(4))[0];rtxSsrc=qg.jspack.Unpack("!L",n8(4))[0];streamId=s8().toString();trackId=s8().toString();onReady=new be;onRtcp=new be;onPictureLossIndication=new be;onGenericNack=new be;senderBWE=new jk;cname;mid;rtpStreamId;repairedRtpStreamId;rtxPayloadType;rtxSequenceNumber=f8();redRedundantPayloadType;_redDistance=2;redEncoder=new a7(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(t){this.dtlsTransport&&this.dtlsDisposer.forEach(e=>e()),this.dtlsTransport=t,this.dtlsDisposer=[this.dtlsTransport.onStateChange.subscribe(e=>{e==="connected"&&this.onReady.execute()}).unSubscribe]}get redDistance(){return this._redDistance}set redDistance(t){this._redDistance=t,this.redEncoder.distance=t}prepareSend(t){this.cname=t.rtcp?.cname,this.mid=t.muxId,this.headerExtensions=t.headerExtensions,this.rtpStreamId=t.rtpStreamId,this.repairedRtpStreamId=t.repairedRtpStreamId,this.codec=t.codecs[0],this.track&&(this.track.codec=this.codec),t.codecs.forEach(e=>{let r=up(e.parameters??"");e.name.toLowerCase()==="rtx"&&r.apt===this.codec?.payloadType&&(this.rtxPayloadType=e.payloadType),e.name.toLowerCase()==="red"&&(this.redRedundantPayloadType=Number((e.parameters??"").split("/")[0]))})}registerTrack(t){if(t.stopped)throw new Error("track is ended");this.disposeTrack&&this.disposeTrack(),t.id=this.trackId;let{unSubscribe:e}=t.onReceiveRtp.subscribe(async r=>{await this.sendRtp(r)});this.track=t,this.disposeTrack=e,this.codec&&(t.codec=this.codec),t.onSourceChanged.subscribe(r=>{this.replaceRTP(r)})}async replaceTrack(t){if(t!==null){if(t.stopped)throw new Error("track is ended");if(this.sequenceNumber!=null){let e=t.header||(await t.onReceiveRtp.asPromise())[0].header;this.replaceRTP(e)}this.registerTrack(t),q1("replaceTrack","ssrc",t.ssrc,"rid",t.rid)}}stop(){this.stopped=!0,this.rtcpRunning=!1,this.rtcpCancel.abort(),this.disposeTrack&&this.disposeTrack(),this.track=void 0}async runRtcp(){if(!(this.rtcpRunning||this.stopped)){this.rtcpRunning=!0;try{for(;this.rtcpRunning;){await i8(500+Math.random()*1e3,void 0,{signal:this.rtcpCancel.signal});let t=[new tu({ssrc:this.ssrc,senderInfo:new l4({ntpTimestamp:this.ntpTimestamp,rtpTimestamp:this.rtpTimestamp,packetCount:this.packetCount,octetCount:this.octetCount})})];this.lastSRtimestamp=u5(this.ntpTimestamp),this.lastSentSRTimestamp=ap(),this.cname&&t.push(new ip({chunks:[new c4({source:this.ssrc,items:[new f4({type:1,text:this.cname})]})]}));try{await this.dtlsTransport.sendRtcp(t)}catch(e){q1("sendRtcp failed",e),await i8(500+Math.random()*1e3)}}}catch{}}}replaceRTP({sequenceNumber:t,timestamp:e},r=!1){this.sequenceNumber!=null&&(this.seqOffset=Tr(this.sequenceNumber,-t),r&&(this.seqOffset=Tr(this.seqOffset,2))),this.timestamp!=null&&(this.timestampOffset=Zc(this.timestamp,-e),r&&(this.timestampOffset=Tr(this.timestampOffset,1))),this.rtpCache=[],q1("replaceRTP",this.sequenceNumber,t,this.seqOffset)}async sendRtp(t){if(this.dtlsTransport.state!=="connected"||!this.codec)return;t=Buffer.isBuffer(t)?ho.deSerialize(t):t;let{header:e,payload:r}=t;e.ssrc=this.ssrc,e.payloadType=this.codec.payloadType,e.timestamp=Zc(e.timestamp,this.timestampOffset),e.sequenceNumber=Tr(e.sequenceNumber,this.seqOffset),this.timestamp=e.timestamp,this.sequenceNumber=e.sequenceNumber;let n=KB(),s=[...e.extensions];e.extensions=this.headerExtensions.map(f=>{let l=(()=>{switch(f.uri){case Dt.sdesMid:return this.mid?Y_(this.mid):void 0;case Dt.sdesRTPStreamID:return this.rtpStreamId?Z_(this.rtpStreamId):void 0;case Dt.repairedRtpStreamId:return this.repairedRtpStreamId?J_(this.repairedRtpStreamId):void 0;case Dt.transportWideCC:return this.dtlsTransport.transportSequenceNumber=Tr(this.dtlsTransport.transportSequenceNumber,1),Q_(this.dtlsTransport.transportSequenceNumber);case Dt.absSendTime:return e7(n)}})();if(l)return{id:f.id,payload:l}}).filter(f=>f);for(let f of s){let l=e.extensions.find(p=>p.id===f.id);l?l.payload=f.payload:e.extensions.push(f)}e.extensions=e.extensions.sort((f,l)=>f.id-l.id),this.ntpTimestamp=n,this.rtpTimestamp=e.timestamp,this.octetCount+=r.length,this.packetCount=Zc(this.packetCount,1),this.rtpCache[e.sequenceNumber%o8]=t;let i=r;this.redRedundantPayloadType&&(this.redEncoder.push({block:i,timestamp:e.timestamp,blockPT:this.redRedundantPayloadType}),i=this.redEncoder.build().serialize());let o=await this.dtlsTransport.sendRtp(i,e);this.runRtcp();let a=c5(),c={wideSeq:this.dtlsTransport.transportSequenceNumber,size:o,sendingAtMs:a,sentAtMs:a};this.senderBWE.rtpPacketSent(c)}handleRtcpPacket(t){switch(t.type){case tu.type:case Kd.type:t.reports.filter(r=>r.ssrc===this.ssrc).forEach(r=>{if(this.lastSRtimestamp===r.lsr&&r.dlsr&&this.lastSentSRTimestamp){let n=ap()-this.lastSentSRTimestamp-r.dlsr/65536;this.rtt===void 0?this.rtt=n:this.rtt=a8*this.rtt+(1-a8)*n}});break;case eu.type:{let e=t;switch(e.feedback.count){case sp.count:{let r=e.feedback;this.senderBWE.receiveTWCC(r)}break;case np.count:{let r=e.feedback;r.lost.forEach(async n=>{let s=this.rtpCache[n%o8];s&&s.header.sequenceNumber!==n&&(s=void 0),s&&(this.rtxPayloadType!=null&&(s=d7(s,this.rtxPayloadType,this.rtxSequenceNumber,this.rtxSsrc),this.rtxSequenceNumber=Tr(this.rtxSequenceNumber,1)),await this.dtlsTransport.sendRtp(s.payload,s.header))}),this.onGenericNack.execute(r)}break}}break;case Fd.type:{let e=t;switch(e.feedback.count){case rp.count:{let r=e.feedback;this.receiverEstimatedMaxBitrate=r.bitrate}break;case tp.count:this.onPictureLossIndication.execute();break}}break}this.onRtcp.execute(t)}getParameters(){return{encodings:[]}}setParameters(t){}async getStats(){let t=Ha(),e=[];if(!this.dtlsTransport)return e;let r=kt("transport",this.dtlsTransport.id),n={type:"outbound-rtp",id:kt("outbound-rtp",this.ssrc),timestamp:t,ssrc:this.ssrc,kind:this.kind,transportId:r,codecId:this.codec?kt("codec",this.codec.payloadType,r):void 0,mid:this.mid,packetsSent:this.packetCount,bytesSent:this.octetCount,rtxSsrc:this.rtxPayloadType?this.rtxSsrc:void 0};if(e.push(n),this.track){let s={type:"media-source",id:kt("media-source",this.trackId),timestamp:t,trackIdentifier:this.trackId,kind:this.kind};e.push(s)}if(this.rtt!==void 0){let s={type:"remote-inbound-rtp",id:kt("remote-inbound-rtp",this.ssrc),timestamp:t,ssrc:this.ssrc,kind:this.kind,transportId:r,codecId:n.codecId,localId:n.id,roundTripTime:this.rtt};e.push(s)}return e}},zk=tt("werift:packages/webrtc/src/transport/sctpManager.ts"),Fk=class{sctpTransport;sctpRemotePort;dataChannelsOpened=0;dataChannelsClosed=0;dataChannels=[];onDataChannel=new be;constructor(){}createSctpTransport(t){let e=new Pk(5e3,t);return e.mid=void 0,e.onDataChannel.subscribe(r=>{this.dataChannelsOpened++,this.dataChannels.push(r),this.onDataChannel.execute(r)}),this.sctpTransport=e,e}createDataChannel(t,e={}){let n={...{protocol:"",ordered:!0,negotiated:!1},...e};if(n.maxPacketLifeTime&&n.maxRetransmits)throw new Error("can not select both");this.sctpTransport||(this.sctpTransport=this.createSctpTransport());let s=new G4({id:n.id,label:t,maxPacketLifeTime:n.maxPacketLifeTime,maxRetransmits:n.maxRetransmits,negotiated:n.negotiated,ordered:n.ordered,protocol:n.protocol}),i=new W4(this.sctpTransport,s);return this.dataChannelsOpened++,this.dataChannels.push(i),i.stateChange.subscribe(o=>{if(o==="closed"){this.dataChannelsClosed++;let a=this.dataChannels.indexOf(i);a!==-1&&this.dataChannels.splice(a,1)}}),i}async connectSctp(){!this.sctpTransport||!this.sctpRemotePort||(await this.sctpTransport.start(this.sctpRemotePort),await this.sctpTransport.sctp.stateChanged.connected.asPromise(),zk("sctp connected"))}setRemoteSCTP(t,e){if(this.sctpTransport){if(this.sctpTransport.setRemoteMaxMessageSize(t.sctpCapabilities?.maxMessageSize),this.sctpRemotePort=t.sctpPort,!this.sctpRemotePort)throw new Error("sctpRemotePort not exist");this.sctpTransport.setRemotePort(this.sctpRemotePort),this.sctpTransport.mLineIndex=e,this.sctpTransport.mid||(this.sctpTransport.mid=t.rtp.muxId)}}async close(){this.sctpTransport&&await this.sctpTransport.stop(),this.onDataChannel.allUnsubscribe()}async getStats(){let t=Ha(),e=[];for(let r of this.dataChannels){let n={type:"data-channel",id:kt("data-channel",r.id),timestamp:t,label:r.label,protocol:r.protocol,dataChannelIdentifier:r.id,state:r.readyState,messagesSent:r.messagesSent||0,bytesSent:r.bytesSent||0,messagesReceived:r.messagesReceived||0,bytesReceived:r.bytesReceived||0};e.push(n)}return e}},Kk=class{currentLocalDescription;currentRemoteDescription;pendingLocalDescription;pendingRemoteDescription;cname;midSuffix;bundlePolicy;seenMid=new Set;constructor({cname:t,midSuffix:e,bundlePolicy:r}){this.cname=t,this.midSuffix=e??!1,this.bundlePolicy=r}get localDescription(){if(this._localDescription)return this._localDescription.toJSON()}get remoteDescription(){if(this._remoteDescription)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?.(t=>t.direction==="inactive")}createMediaDescriptionForTransceiver(t,e){let r=new Mg(t.kind,9,"UDP/TLS/RTP/SAVPF",t.codecs.map(n=>n.payloadType));return r.direction=e,r.msid=t.msid,r.rtp={codecs:t.codecs,headerExtensions:t.headerExtensions,muxId:t.mid},r.rtcpHost="0.0.0.0",r.rtcpPort=9,r.rtcpMux=!0,r.ssrc=[new jg({ssrc:t.sender.ssrc,cname:this.cname})],t.options.simulcast&&(r.simulcastParameters=t.options.simulcast.map(n=>new X4(n))),r.rtp.codecs.find(n=>n.name.toLowerCase()==="rtx")&&(r.ssrc.push(new jg({ssrc:t.sender.rtxSsrc,cname:this.cname})),r.ssrcGroup=[new Vd("FID",[t.sender.ssrc.toString(),t.sender.rtxSsrc.toString()])]),this.addTransportDescription(r,t.dtlsTransport),r}createMediaDescriptionForSctp(t){let e=new Mg("application",M3,"UDP/DTLS/SCTP",["webrtc-datachannel"]);return e.sctpPort=t.port,e.rtp.muxId=t.mid,e.sctpCapabilities=t.getCapabilities(),this.addTransportDescription(e,t.dtlsTransport),e}addTransportDescription(t,e){let r=e.iceTransport;t.iceCandidates=r.localCandidates,t.iceCandidatesComplete=r.gatheringState==="complete",t.iceParams=r.localParameters,t.iceOptions="trickle",t.host=NB,t.port=M3,t.direction==="inactive"&&(t.port=0,t.msid=void 0),t.dtlsParams||(t.dtlsParams=e.localParameters,t.dtlsParams.fingerprints||(t.dtlsParams.fingerprints=e.localParameters.fingerprints))}allocateMid(t=""){let e="";for(let r=0;e=(r++).toString()+t,!!this.seenMid.has(e););return this.seenMid.add(e),e}parseSdp({sdp:t,isLocal:e,signalingState:r,type:n}){let s=Kh.parse(t);return this.validateDescription({description:s,isLocal:e,signalingState:r}),s.type=n,s}validateDescription({description:t,isLocal:e,signalingState:r}){if(e){if(t.type==="offer"){if(!["stable","have-local-offer"].includes(r))throw new Error("Cannot handle offer in signaling state")}else if(t.type==="answer"&&!["have-remote-offer","have-local-pranswer"].includes(r))throw new Error("Cannot handle answer in signaling state")}else if(t.type==="offer"){if(!["stable","have-remote-offer"].includes(r))throw new Error("Cannot handle offer in signaling state")}else if(t.type==="answer"&&!["have-local-offer","have-remote-pranswer"].includes(r))throw new Error("Cannot handle answer in signaling state")}buildOfferSdp(t,e){let r=new Kh;r8("offer",r),(this.currentLocalDescription?.media??[]).forEach((s,i)=>{let o=s.rtp.muxId;if(o)if(s.kind==="application"){if(!e)throw new Error("sctpTransport not found");e.mLineIndex=i,r.media.push(this.createMediaDescriptionForSctp(e))}else{let a=t.find(c=>c.mid===o);if(!a){if(s.direction==="inactive"){r.media.push(s);return}throw new Error("transceiver not found")}a.mLineIndex=i,r.media.push(this.createMediaDescriptionForTransceiver(a,a.direction))}});for(let s of t.filter(i=>!r.media.find(o=>o.rtp.muxId===i.mid))){s.mid==null&&(s.mid=this.allocateMid(this.midSuffix?"av":""));let i=this.createMediaDescriptionForTransceiver(s,s.direction);s.mLineIndex===void 0?(s.mLineIndex=r.media.length,r.media.push(i)):r.media[s.mLineIndex]=i}if(e&&!r.media.find(s=>s.kind==="application")&&(e.mLineIndex=r.media.length,e.mid==null&&(e.mid=this.allocateMid(this.midSuffix?"dc":"")),r.media.push(this.createMediaDescriptionForSctp(e))),this.bundlePolicy!=="disable"){let s=r.media.map(i=>i.rtp.muxId).filter(i=>i);if(s.length){let i=new Vd("BUNDLE",s);r.group.push(i)}}return r}buildAnswerSdp({transceivers:t,sctpTransport:e,signalingState:r}){if(!["have-remote-offer","have-local-pranswer"].includes(r))throw new Error("createAnswer failed");if(!this._remoteDescription)throw new Error("wrong state");let n=new Kh;r8("answer",n);for(let s of this._remoteDescription.media){let i,o;if(["audio","video"].includes(s.kind)){let a=t.find(c=>c.mid===s.rtp.muxId);if(!a)throw new Error(`Transceiver with mid=${s.rtp.muxId} not found`);o=this.createMediaDescriptionForTransceiver(a,a5(a.direction,a.offerDirection)),i=a.dtlsTransport}else if(s.kind==="application"){if(!e||!e.mid)throw new Error("sctpTransport not found");o=this.createMediaDescriptionForSctp(e),i=e.dtlsTransport}else throw new Error("invalid kind");o.dtlsParams&&(i.role==="auto"?o.dtlsParams.role="client":o.dtlsParams.role=i.role),s.simulcastParameters&&s.simulcastParameters.length>0&&(o.simulcastParameters=s.simulcastParameters.map(a=>({...a,direction:a.direction==="send"?"recv":"send"}))),n.media.push(o)}if(this.bundlePolicy!=="disable"){let s=new Vd("BUNDLE",[]);for(let i of n.media)i.rtp.muxId&&s.items.push(i.rtp.muxId);n.group.push(s)}return n}setLocalDescription(t){this.currentLocalDescription=t,t.type==="answer"?this.pendingLocalDescription=void 0:this.pendingLocalDescription=t}setRemoteDescription(t,e){if(!t.sdp||!t.type||t.type==="rollback"||t.type==="pranswer")throw new Error("invalid sessionDescription");let r=this.parseSdp({sdp:t.sdp,isLocal:!1,signalingState:e,type:t.type});return r.type==="answer"?(this.currentRemoteDescription=r,this.pendingRemoteDescription=void 0):this.pendingRemoteDescription=r,r}registerMid(t){this.seenMid.add(t)}get remoteIsBundled(){let t=this._remoteDescription;return t?t.group.find(r=>r.semantic==="BUNDLE"&&this.bundlePolicy!=="disable"):void 0}setLocal(t,e,r){let n=new Map(e.map(o=>[o?.mLineIndex,o])),s=e.find(o=>o?.dtlsTransport)?.dtlsTransport??r?.dtlsTransport;t.media.filter(o=>["audio","video"].includes(o.kind)).forEach((o,a)=>{let f=(n.get(a)??e[a])?.dtlsTransport??s;if(!f)throw new Error(`dtls transport not found for media index ${a}`);this.addTransportDescription(o,f)});let i=t.media.find(o=>o.kind==="application");r&&i&&this.addTransportDescription(i,r.dtlsTransport),this.setLocalDescription(t)}},Cd=tt("werift:packages/webrtc/src/transport/secureTransportManager.ts"),$k=class{connectionState="new";iceConnectionState="new";iceGatheringState="new";certificate;iceGatheringStateChange=new be;iceConnectionStateChange=new be;onIceCandidate=new be;connectionStateChange=new be;config;transceiverManager;sctpManager;constructor({config:t,transceiverManager:e,sctpManager:r}){if(this.config=t,this.transceiverManager=e,this.sctpManager=r,this.config.dtls){let{keys:n}=this.config.dtls;n&&this.setupCertificate(n)}}get dtlsTransports(){return[...this.transceiverManager.getTransceivers().map(e=>e?.dtlsTransport),this.sctpManager.sctpTransport?.dtlsTransport].filter(e=>e!=null).reduce((e,r)=>(e.map(n=>n.id).includes(r.id)||e.push(r),e),[])}get iceTransports(){return this.dtlsTransports.map(t=>t.iceTransport)}setupCertificate(t){this.certificate=new d5(t.keyPem,t.certPem,t.signatureHash)}createTransport(){let t=this.iceTransports.find(s=>s.state!=="closed"),e=new fk({...$B(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});t&&(e.connection.localUsername=t.connection.localUsername,e.connection.localPassword=t.connection.localPassword),e.onGatheringStateChange.subscribe(()=>{this.updateIceGatheringState()}),this.updateIceGatheringState();let r=new uk(e);return r.onStateChange.subscribe(()=>{this.updateIceConnectionState()}),new V3(this.config,r,this.certificate,Wk)}handleNewIceCandidate({candidate:t,media:e,remoteIsBundled:r,transceiver:n,sctpTransport:s,bundlePolicy:i}){return i==="max-bundle"||r?(t.sdpMLineIndex=0,e&&(t.sdpMid=e.rtp.muxId)):(n&&(t.sdpMLineIndex=n.mLineIndex,t.sdpMid=n.mid),s&&(t.sdpMLineIndex=s.mLineIndex,t.sdpMid=s.mid)),t.foundation&&!t.foundation.startsWith("candidate:")&&(t.foundation="candidate:"+t.foundation),this.onIceCandidate.execute(t),t}async addIceCandidate(t,e){let r=l5.fromJSON(e);if(!r)return;let n;typeof r.sdpMid=="number"&&(n=this.getTransportByMid(r.sdpMid)),!n&&typeof r.sdpMLineIndex=="number"&&(n=this.getTransportByMLineIndex(t,r.sdpMLineIndex)),n||(n=this.iceTransports[0]),n?await n.addRemoteCandidate(r):Cd("iceTransport not found for candidate",r)}getTransportByMid(t){let e,r=this.transceiverManager.getTransceivers().find(n=>n.mid===t);return r?e=r.dtlsTransport.iceTransport:!e&&this.sctpManager.sctpTransport?.mid===t&&(e=this.sctpManager.sctpTransport.dtlsTransport.iceTransport),e}getTransportByMLineIndex(t,e){let r=t.media[e];return r?this.getTransportByMid(r.rtp.muxId):void 0}restartIce(){for(let t of this.iceTransports)t.restart()}setLocalRole({type:t,role:e}){for(let r of this.dtlsTransports){let n=r.iceTransport;t==="offer"?n.connection.iceControlling=!0:n.connection.iceControlling=!1,n.connection.remoteIsLite&&(n.connection.iceControlling=!0),t==="answer"&&e&&(r.role=e)}}updateIceGatheringState(){let t=this.iceTransports;function e(...n){return t.filter(s=>n.includes(s.gatheringState)).length===t.length}let r;t.length&&e("complete")?r="complete":!t.length||e("new","complete")?r="new":t.map(n=>n.gatheringState).includes("gathering")?r="gathering":r="new",this.iceGatheringState!==r&&(this.iceGatheringState=r,this.iceGatheringStateChange.execute(r))}updateIceConnectionState(){let t=this.iceTransports,e;function r(...s){return t.filter(i=>s.includes(i.state)).length===t.length}function n(...s){return t.some(i=>s.includes(i.state))}this.connectionState==="closed"?e="closed":n("failed")?e="failed":n("disconnected")?e="disconnected":r("new","closed")?e="new":n("new","checking")?e="checking":r("completed","closed")?e="completed":r("connected","completed","closed")?e="connected":e="new",this.iceConnectionState!==e&&(Cd("iceConnectionStateChange",e),this.iceConnectionState=e,this.iceConnectionStateChange.execute(e))}async gatherCandidates(t){let e=this.iceTransports.find(r=>r.state==="connected"||r.state==="completed");t&&e?Cd("skipping ICE gathering for bundled connection"):await Promise.allSettled(this.iceTransports.map(r=>r.gather())).catch(r=>{Cd("gatherCandidates failed",r)})}setConnectionState(t){Cd("connectionStateChange",t),this.connectionState=t,this.connectionStateChange.execute(t)}async getStats(){let t=[];for(let e of this.dtlsTransports){let r=await e.getStats();r&&t.push(...r)}return t}async ensureCerts(){this.certificate||(this.certificate=await V3.SetupCertificate());for(let t of this.dtlsTransports)t.localCertificate=this.certificate}async close(){this.setConnectionState("closed"),await Promise.allSettled([...this.dtlsTransports.map(t=>t.stop())]),this.iceGatheringStateChange.allUnsubscribe(),this.iceConnectionStateChange.allUnsubscribe(),this.onIceCandidate.allUnsubscribe(),this.connectionStateChange.allUnsubscribe()}},Wk=[j3.SRTP_AEAD_AES_128_GCM,j3.SRTP_AES128_CM_HMAC_SHA1_80],Un=tt("werift:packages/webrtc/src/peerConnection.ts"),qJ=class extends ry{cname=Vk().toString();config=F5();signalingState="stable";negotiationneeded=!1;needRestart=!1;router=new Dk;sdpManager;transceiverManager;sctpManager;secureManager;isClosed=!1;shouldNegotiationneeded=!1;remoteBundleNegotiated=!1;iceGatheringStateChange=new be;iceConnectionStateChange=new be;signalingStateChange=new be;connectionStateChange=new be;onDataChannel=new be;onRemoteTransceiverAdded=new be;onTransceiverAdded=new be;onIceCandidate=new be;onNegotiationneeded=new be;onTrack=new be;ondatachannel;onicecandidate;onicecandidateerror;onicegatheringstatechange;onnegotiationneeded;onsignalingstatechange;ontrack;onconnectionstatechange;oniceconnectionstatechange;constructor(t={}){super(),this.setConfiguration(t),this.sdpManager=new Kk({cname:this.cname,bundlePolicy:this.config.bundlePolicy}),this.transceiverManager=new Xk(this.cname,this.config,this.router),this.transceiverManager.onTransceiverAdded.pipe(this.onTransceiverAdded),this.transceiverManager.onRemoteTransceiverAdded.pipe(this.onRemoteTransceiverAdded),this.transceiverManager.onTrack.subscribe(({track:e,stream:r,transceiver:n})=>{let s={track:e,streams:[r],transceiver:n,receiver:n.receiver};this.onTrack.execute(e),this.emit("track",s),this.ontrack&&this.ontrack(s)}),this.transceiverManager.onNegotiationNeeded.subscribe(()=>this.needNegotiation()),this.sctpManager=new Fk,this.sctpManager.onDataChannel.subscribe(e=>{this.onDataChannel.execute(e);let r={channel:e};this.ondatachannel?.(r),this.emit("datachannel",r)}),this.secureManager=new $k({config:this.config,sctpManager:this.sctpManager,transceiverManager:this.transceiverManager}),this.secureManager.iceGatheringStateChange.pipe(this.iceGatheringStateChange),this.secureManager.iceConnectionStateChange.subscribe(e=>{e==="closed"&&this.close(),this.iceConnectionStateChange.execute(e)}),this.secureManager.connectionStateChange.subscribe(e=>{this.connectionStateChange.execute(e),this.onconnectionstatechange?.(),this.emit("connectionstatechange")}),this.secureManager.onIceCandidate.subscribe(e=>{let r=e?e.toJSON():void 0;this.onIceCandidate.execute(r),this.onicecandidate?.({candidate:r}),this.emit("icecandidate",{candidate:r})})}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(t){if(WB(this.config,t),this.config.icePortRange){let[e,r]=this.config.icePortRange;if(e===r)throw new Error("should not be same value");if(e>=r)throw new Error("The min must be less than max")}if(!Number.isInteger(this.config.maxMessageSize)||this.config.maxMessageSize<0)throw new Error("maxMessageSize must be a non-negative integer");this.sctpManager?.sctpTransport&&(this.sctpManager.sctpTransport.maxMessageSize=this.config.maxMessageSize);for(let[e,r]of N3([...this.config.codecs.audio||[],...this.config.codecs.video||[]]))if(r.payloadType==null)switch(r.payloadType=96+e,r.name.toLowerCase()){case"rtx":r.parameters=`apt=${r.payloadType-1}`;break;case"red":if(r.contentType==="audio"){let n=r.payloadType+1;r.parameters=`${n}/${n}`,r.payloadType=63}break}[...this.config.headerExtensions.audio||[],...this.config.headerExtensions.video||[]].forEach((e,r)=>{e.id=1+r})}getConfiguration(){return this.config}async createOffer({iceRestart:t}={}){(t||this.needRestart)&&(this.needRestart=!1,this.secureManager.restartIce()),await this.secureManager.ensureCerts();for(let r of this.transceiverManager.getTransceivers())r.codecs.length===0&&this.transceiverManager.assignTransceiverCodecs(r),r.headerExtensions.length===0&&(r.headerExtensions=this.config.headerExtensions[r.kind]??[]);return this.sdpManager.buildOfferSdp(this.transceiverManager.getTransceivers(),this.sctpTransport).toJSON()}createSctpTransport(){let t=this.sctpManager.createSctpTransport(this.config.maxMessageSize),e=this.findOrCreateTransport();return t.setDtlsTransport(e),t}createDataChannel(t,e={}){this.sctpTransport||(this.createSctpTransport(),this.needNegotiation());let r=this.sctpManager.createDataChannel(t,e);if(!r.sctp.dtlsTransport){let n=this.findOrCreateTransport();r.sctp.setDtlsTransport(n)}return r}removeTrack(t){if(this.isClosed)throw new Error("peer closed");this.transceiverManager.removeTrack(t),this.needNegotiation()}needNegotiation=async()=>{this.shouldNegotiationneeded=!0,!(this.negotiationneeded||this.signalingState!=="stable")&&(this.shouldNegotiationneeded=!1,setImmediate(()=>{this.negotiationneeded=!0,this.onNegotiationneeded.execute(),this.onnegotiationneeded&&this.onnegotiationneeded({})}))};findOrCreateTransport(){let t=this.dtlsTransports.find(s=>s.state!=="closed"),e=t?.iceTransport;if((this.sdpManager.bundlePolicy==="max-bundle"||this.sdpManager.bundlePolicy!=="disable"&&(this.remoteIsBundled||this.remoteBundleNegotiated))&&t)return t;let r=this.secureManager.createTransport();r.onRtp.subscribe(s=>{this.router.routeRtp(s)}),r.onRtcp.subscribe(s=>{this.router.routeRtcp(s)});let n=r.iceTransport;return n.onNegotiationNeeded.subscribe(()=>{this.needNegotiation()}),n.onIceCandidate.subscribe(s=>{if(!this.localDescription){Un("localDescription not found when ice candidate was gathered");return}if(!s){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){Un("localDescription not found when ice candidate was gathered");return}this.secureManager.handleNewIceCandidate({candidate:s,bundlePolicy:this.sdpManager.bundlePolicy,remoteIsBundled:!!this.sdpManager.remoteIsBundled,media:this._localDescription.media[0],transceiver:this.transceiverManager.getTransceivers().find(i=>i?.dtlsTransport?.iceTransport.id===n.id),sctpTransport:this.sctpTransport?.dtlsTransport.iceTransport.id===n.id?this.sctpTransport:void 0})}),r}async setLocalDescription(t){t=t??(["stable","have-local-offer","have-remote-pranswer"].includes(this.signalingState)?await this.createOffer():await this.createAnswer());let r=this.sdpManager.parseSdp({sdp:t.sdp,isLocal:!0,signalingState:this.signalingState,type:t.type});r.type==="offer"?this.setSignalingState("have-local-offer"):r.type==="answer"&&this.setSignalingState("stable");for(let[s,i]of N3(r.media)){let o=i.rtp.muxId;if(this.sdpManager.registerMid(o),["audio","video"].includes(i.kind)){let a=this.transceiverManager.getTransceiverByMLineIndex(s);a&&(a.mid=o)}i.kind==="application"&&this.sctpTransport&&(this.sctpTransport.mid=o)}let n=r.media.find(s=>s.dtlsParams)?.dtlsParams?.role;if(this.secureManager.setLocalRole({type:r.type,role:n}),["answer","pranswer"].includes(r.type))for(let s of this.transceiverManager.getTransceivers()){let i=a5(s.direction,s.offerDirection);s.setCurrentDirection(i)}return this.sdpManager.setLocal(r,this.transceiverManager.getTransceivers(),this.sctpTransport),await this.gatherCandidates().catch(s=>{Un("gatherCandidates failed",s)}),r.type==="answer"&&this.connect().catch(s=>{Un("connect failed",s),this.secureManager.setConnectionState("failed")}),this.sdpManager.setLocal(r,this.transceiverManager.getTransceivers(),this.sctpTransport),this.shouldNegotiationneeded&&this.needNegotiation(),r}async gatherCandidates(){await this.secureManager.gatherCandidates(!!this.sdpManager.remoteIsBundled)}async addIceCandidate(t){let e=this.sdpManager.buildOfferSdp(this.transceiverManager.getTransceivers(),this.sctpTransport);await this.secureManager.addIceCandidate(e,t)}async connect(){Un("start connect"),(await Promise.allSettled(this.dtlsTransports.map(async e=>{let{iceTransport:r}=e;if(r.state==="connected")return;let n=()=>e.state==="connected";n()||(this.secureManager.setConnectionState("connecting"),await r.start().catch(s=>{throw Un("iceTransport.start failed",s),s}),!n()&&(await e.start().catch(s=>{throw Un("dtlsTransport.start failed",s),s}),this.sctpTransport&&this.sctpTransport.dtlsTransport.id===e.id&&await this.sctpManager.connectSctp()))}))).find(e=>e.status==="rejected")?this.secureManager.setConnectionState("failed"):this.secureManager.setConnectionState("connected")}restartIce(){this.needRestart=!0,this.needNegotiation()}async setRemoteDescription(t){t instanceof Kh&&(t=t.toSdp());let e=this.sdpManager.setRemoteDescription(t,this.signalingState);e.group.some(o=>o.semantic==="BUNDLE"&&o.items.length>0)&&(this.remoteBundleNegotiated=!0);let r,n=(o,a)=>o.kind===a.kind&&[void 0,a.rtp.muxId].includes(o.mid),s=e.media.map((o,a)=>{let c;if(["audio","video"].includes(o.kind)){let l=this.transceiverManager.getTransceivers().find(p=>n(p,o));if(!l)l=this.addTransceiver(o.kind,{direction:"recvonly"}),l.mid=o.rtp.muxId,this.onRemoteTransceiverAdded.execute(l);else if(l.direction==="inactive"&&l.stopping){l.stopped=!0,t.type==="answer"&&l.setCurrentDirection("inactive");return}this.sdpManager.remoteIsBundled&&(r?l.setDtlsTransport(r):r=l.dtlsTransport),c=l.dtlsTransport,this.transceiverManager.setRemoteRTP(l,o,e.type,a)}else if(o.kind==="application"){let l=this.sctpTransport;l||(l=this.createSctpTransport(),l.mid=o.rtp.muxId),this.sdpManager.remoteIsBundled&&(r?l.setDtlsTransport(r):r=l.dtlsTransport),c=l.dtlsTransport,this.sctpManager.setRemoteSCTP(o,a)}else throw new Error("invalid media kind");let f=c.iceTransport;if(o.iceParams){let l=!!this.sdpManager.inactiveRemoteMedia;f.setRemoteParams(o.iceParams,l),o.iceParams?.iceLite&&(f.connection.iceControlling=!0)}return o.dtlsParams&&c.setRemoteParams(o.dtlsParams),o.iceCandidates.forEach(f.addRemoteCandidate),o.iceCandidatesComplete&&f.addRemoteCandidate(void 0),e.type==="answer"&&o.dtlsParams?.role&&(c.role=o.dtlsParams.role==="client"?"server":"client"),f});s=s.filter(o=>!!o);let i=this.transceiverManager.getTransceivers().filter(o=>e.media.find(a=>n(o,a))==null);if(t.type==="answer")for(let o of i)o.stop(),o.stopped=!0;e.type==="offer"?this.setSignalingState("have-remote-offer"):e.type==="answer"&&this.setSignalingState("stable"),e.type==="answer"&&(Un("caller start connect"),this.connect().catch(o=>{Un("connect failed",o),this.secureManager.setConnectionState("failed")})),this.negotiationneeded=!1,this.shouldNegotiationneeded&&this.needNegotiation()}addTransceiver(t,e={}){let r=this.findOrCreateTransport(),n=this.transceiverManager.addTransceiver(t,r,e);return this.secureManager.updateIceConnectionState(),this.needNegotiation(),n}addTrack(t,e){if(this.isClosed)throw new Error("is closed");let r=this.transceiverManager.addTrack(t,e);if(!r.dtlsTransport){let n=this.findOrCreateTransport();r.setDtlsTransport(n)}return this.needNegotiation(),r.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 new Error("RTCPeerConnection is closed")}setSignalingState(t){Un("signalingStateChange",t),this.signalingState=t,this.signalingStateChange.execute(t),this.onsignalingstatechange&&this.onsignalingstatechange({})}createPeerConnectionStats(){let t=Ha();return{type:"peer-connection",id:kt("peer-connection"),timestamp:t,dataChannelsOpened:this.sctpManager.dataChannelsOpened,dataChannelsClosed:this.sctpManager.dataChannelsClosed}}async getStats(t){let e=[];e.push(this.createPeerConnectionStats());let r=await this.transceiverManager.getStats(t);e.push(...r);let n=await this.secureManager.getStats();if(e.push(...n),this.sctpTransport){let s=await this.sctpManager.getStats();s&&e.push(...s)}return new LB(e)}async close(){this.isClosed||(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(),Un("peerConnection closed"))}},c8=(t,e)=>t.find(r=>r.mimeType.toLowerCase()===e.mimeType.toLowerCase())?e:void 0;function F5(){return{codecs:{audio:[Z4(),J4()],video:[Y4()]},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:Hd}}var VJ=F5(),Gk=tt("werift:packages/webrtc/src/media/rtpTransceiverManager.ts"),Xk=class{constructor(t,e,r){this.cname=t,this.config=e,this.router=r}transceivers=[];onTransceiverAdded=new be;onRemoteTransceiverAdded=new be;onTrack=new be;onNegotiationNeeded=new be;getTransceivers(){return this.transceivers}getSenders(){return this.getTransceivers().map(t=>t.sender)}getReceivers(){return this.getTransceivers().map(t=>t.receiver)}getTransceiverByMLineIndex(t){return this.transceivers.find(e=>e.mLineIndex===t)}pushTransceiver(t){this.transceivers.push(t)}replaceTransceiver(t,e){this.transceivers[e]=t}addTransceiver(t,e,r={}){let n=typeof t=="string"?t:t.kind,s=r.direction||"sendrecv",i=new qk(t),o=new z5(this.config,n,i.ssrc),a=new UB(n,e,o,i,s);a.options=r,this.router.registerRtpSender(a.sender);let c=this.transceivers.findIndex(l=>l.currentDirection==="inactive"&&!l.usedForSender),f=this.transceivers.find(l=>l.currentDirection==="inactive"&&!l.usedForSender);return c>-1&&f?(this.replaceTransceiver(a,c),a.mLineIndex=f.mLineIndex,a.mid=f.mid,f.setCurrentDirection(void 0)):this.pushTransceiver(a),this.onTransceiverAdded.execute(a),a}addTrack(t,e){if(this.getSenders().find(s=>s.track?.uuid===t.uuid))throw new Error("Track already added");let r=this.transceivers.find(s=>s.sender.track==null&&s.kind===t.kind&&Dh.includes(s.direction)===!0);if(r)return r.sender.registerTrack(t),r;let n=this.transceivers.find(s=>s.sender.track==null&&s.kind===t.kind&&Dh.includes(s.direction)===!1&&!s.usedForSender);if(n){switch(n.sender.registerTrack(t),n.direction){case"recvonly":n.setDirection("sendrecv");break;case"inactive":n.setDirection("sendonly");break}return n}else return this.addTransceiver(t,void 0,{direction:"sendrecv"})}removeTrack(t){if(!this.getSenders().find(({ssrc:r})=>t.ssrc===r))throw new Error("Sender does not exist");let e=this.transceivers.find(({sender:{ssrc:r}})=>t.ssrc===r);if(!e)throw new Error("No matching transceiver found");if(t.stop(),e.currentDirection==="recvonly"){this.onNegotiationNeeded.execute();return}e.stopping||e.stopped?e.setDirection("inactive"):e.direction==="sendrecv"?e.setDirection("recvonly"):(e.direction==="sendonly"||e.direction==="recvonly")&&e.setDirection("inactive")}assignTransceiverCodecs(t){let e=this.config.codecs[t.kind].filter(r=>{switch(r.direction){case"recvonly":return!!OB.includes(t.direction);case"sendonly":return!!Dh.includes(t.direction);case"sendrecv":return!![n5,r5,t5].includes(t.direction);case"all":return!0;default:return!1}});t.codecs=e}getLocalRtpParams(t){if(t.mid==null)throw new Error("mid not assigned");return{codecs:t.codecs,muxId:t.mid,headerExtensions:t.headerExtensions,rtcp:{cname:this.cname,ssrc:t.sender.ssrc,mux:!0}}}getRemoteRtpParams(t,e){return{muxId:t.rtp.muxId,rtcp:t.rtp.rtcp,codecs:e.codecs,headerExtensions:e.headerExtensions,encodings:Object.values(e.codecs.reduce((n,s)=>{if(s.name.toLowerCase()==="rtx"){let i=up(s.parameters??""),o=n[i.apt];return o&&t.ssrc.length===2&&(o.rtx=new vB({ssrc:t.ssrc[1].ssrc})),n}return n[s.payloadType]=new wB({ssrc:t.ssrc[0]?.ssrc,payloadType:s.payloadType}),n},{}))}}setRemoteRTP(t,e,r,n){if(t.mid||(t.mid=e.rtp.muxId),t.mLineIndex=n,t.codecs=e.rtp.codecs.filter(a=>{let c=this.config.codecs[e.kind]||[],f=c8(c,a);if(!f)return!1;if(f?.name.toLowerCase()==="rtx"){let p=up(f.parameters??"").apt,x=e.rtp.codecs.find(v=>v.payloadType===p);return x?!!c8(c,x):!1}return!0}),Gk("negotiated codecs",t.codecs),t.codecs.length===0)throw new Error("negotiate codecs failed.");t.headerExtensions=e.rtp.headerExtensions.filter(a=>(this.config.headerExtensions[e.kind]||[]).find(c=>c.uri===a.uri));let s=e.direction??"inactive",i=VB(s);["answer","pranswer"].includes(r)?t.setCurrentDirection(i):t.offerDirection=i;let o=this.getLocalRtpParams(t);if(t.sender.prepareSend(o),["recvonly","sendrecv"].includes(t.direction)){let a=this.getRemoteRtpParams(e,t);for(let c of e.simulcastParameters)this.router.registerRtpReceiverByRid(t,c,a);t.receiver.prepareReceive(a),this.router.registerRtpReceiverBySsrc(t,a)}if(["sendonly","sendrecv"].includes(s)){if(e.msid){let[a,c]=e.msid.split(" ");t.receiver.remoteStreamId=a,t.receiver.remoteTrackId=c}this.onTrack.execute({track:t.receiver.track,transceiver:t,stream:new MB({id:t.receiver.remoteStreamId,tracks:[t.receiver.track]})})}e.ssrc[0]?.ssrc&&t.receiver.setupTWCC(e.ssrc[0].ssrc)}async getStats(t){let e=[];for(let r of this.transceivers){let n=!t||r.sender.track===t||r.receiver.track===t;if(r.sender){let s=await r.sender.getStats();if(s)for(let i of s)i.type==="outbound-rtp"||i.type==="media-source"?n&&e.push(i):e.push(i)}if(r.receiver){let s=await r.receiver.getStats();if(s)for(let i of s)i.type==="inbound-rtp"||i.type==="remote-outbound-rtp"?n&&e.push(i):e.push(i)}if(n){let s=r.getCodecStats();s&&e.push(...s)}}return e}close(){for(let t of this.transceivers)t.receiver.stop(),t.sender.stop();this.onTransceiverAdded.allUnsubscribe(),this.onRemoteTransceiverAdded.allUnsubscribe(),this.onTrack.allUnsubscribe(),this.onNegotiationNeeded.allUnsubscribe()}},zJ=["stable","have-local-offer","have-remote-offer","have-local-pranswer","have-remote-pranswer","closed"],FJ=["closed","failed","disconnected","new","connecting","connected"];export{T_ as AV1Obu,q6 as AV1RtpPayload,FZ as AttributeKeys,Ba as BitStream,$h as BitWriter,zg as BitWriter2,xZ as BufferChain,T3 as CONSENT_FAILURES,iB as CONSENT_INTERVAL,Zg as COOKIE,ka as Candidate,C3 as CandidatePair,oB as CandidatePairState,Yh as CipherContext,$1 as CipherSuite,VT as CipherSuiteList,hB as Connection,FJ as ConnectionStates,A8 as CurveType,Hd as DEFAULT_MAX_MESSAGE_SIZE,NZ as DePacketizerBase,D1 as Directions,h3 as DtlsClient,R7 as DtlsServer,C4 as DtlsSocket,kJ as DtlsStates,be as Event,LT as EventDisposer,Ia as ExtensionProfiles,N7 as FINGERPRINT_LENGTH,P7 as FINGERPRINT_XOR,np as GenericNack,Vd as GroupDescription,k_ as H264RtpPayload,ao as HEADER_LENGTH,Xh as HashAlgorithm,I3 as ICE_COMPLETED,Eh as ICE_FAILED,I4 as INTEGRITY_LENGTH,T4 as IPV4_PROTOCOL,_4 as IPV6_PROTOCOL,l5 as IceCandidate,PJ as IceGathererStates,NJ as IceTransportStates,DB as Inactive,ep as Int,Mg as MediaDescription,MB as MediaStream,op as MediaStreamTrack,AJ as MediaStreamTrackFactory,jn as Message,Ca as NalUnitType,fo as NamedCurveAlgorithm,E8 as NamedCurveAlgorithmList,O_ as OpusRtpPayload,q_ as PacketChunk,z_ as PacketResult,V_ as PacketStatus,tp as PictureLossIndication,RZ as Profiles,bZ as PromiseQueue,iu as ProtectionProfileAeadAes128Gcm,rl as ProtectionProfileAes128CmHmacSha1_80,O7 as RETRY_MAX,L7 as RETRY_RTO,d5 as RTCCertificate,W4 as RTCDataChannel,G4 as RTCDataChannelParameters,Sg as RTCDtlsFingerprint,Eg as RTCDtlsParameters,V3 as RTCDtlsTransport,lk as RTCIceCandidate,fk as RTCIceGatherer,h5 as RTCIceParameters,uk as RTCIceTransport,eg as RTCP_HEADER_SIZE,qJ as RTCPeerConnection,bB as RTCRtcpFeedback,sJ as RTCRtcpParameters,Ma as RTCRtpCodecParameters,wB as RTCRtpCodingParameters,li as RTCRtpHeaderExtensionParameters,z5 as RTCRtpReceiver,vB as RTCRtpRtxParameters,qk as RTCRtpSender,X4 as RTCRtpSimulcastParameters,UB as RTCRtpTransceiver,H5 as RTCSctpCapabilities,Pk as RTCSctpTransport,Uk as RTCSessionDescription,LB as RTCStatsReport,Dt as RTP_EXTENSION_URI,rp as ReceiverEstimatedMaxBitrate,Bh as RecvDelta,r5 as Recvonly,p4 as Red,a7 as RedEncoder,u7 as RedHandler,K6 as RedHeader,po as RtcpHeader,W_ as RtcpPacketConverter,Fd as RtcpPayloadSpecificFeedback,Gg as RtcpReceiverInfo,Kd as RtcpRrPacket,l4 as RtcpSenderInfo,ip as RtcpSourceDescriptionPacket,tu as RtcpSrPacket,eu as RtcpTransportLayerFeedback,qZ as RtpBuilder,lo as RtpHeader,ho as RtpPacket,Dk as RtpRouter,qd as RunLengthChunk,Kk as SDPManager,t5 as Sendonly,n5 as Sendrecv,Kh as SessionDescription,zJ as SignalingStates,di as SignatureAlgorithm,O6 as SignatureScheme,c4 as SourceDescriptionChunk,f4 as SourceDescriptionItem,y7 as SrtcpSession,ru as SrtpAuthenticationError,Zh as SrtpContext,v7 as SrtpSession,jg as SsrcDescription,j_ as StatusVectorChunk,Y7 as StunOverTurnProtocol,xg as StunProtocol,MT as TcpTransport,Xk as TransceiverManager,sp as TransportWideCC,Z7 as TurnProtocol,K1 as UdpTransport,L_ as Vp8RtpPayload,U_ as Vp9RtpPayload,SZ as WeriftError,r8 as addSDPHeader,a5 as andDirection,gZ as buffer2ArrayBuffer,hZ as bufferArrayXor,Wr as bufferReader,Ht as bufferWriter,IT as bufferWriterLE,lZ as bufferXor,gg as candidateFoundation,Xd as candidateFromIce,V5 as candidateFromSdp,bg as candidatePairPriority,Lh as candidatePriority,dk as candidateToIce,q5 as candidateToSdp,zT as certificateTypes,B4 as classes,up as codecParametersFromString,UJ as codecParametersToString,u5 as compactNtp,RT as crc32,m8 as crc32c,Th as createBufferWriter,EJ as createSelfSignedCertificate,w3 as createStunOverTurnClient,J7 as createTurnClient,PZ as dePacketizeRtpPackets,tt as debug,WB as deepMerge,aB as defaultOptions,VJ as defaultPeerConfig,OZ as depacketizerCodecs,n7 as deserializeAbsSendTime,s7 as deserializeAudioLevelIndication,t7 as deserializeString,r7 as deserializeUint16BE,i7 as deserializeVideoOrientation,mZ as dumpBuffer,LZ as enumerate,c8 as findCodecByMimeType,OT as findPort,i5 as fingerprint,kt as generateStatsId,ue as getBit,gB as getDataChannelMessageSize,eJ as getGlobalIp,lB as getHostAddresses,Ha as getStatsTimestamp,V6 as growBufferSize,jd as int,Kg as interfaceAddress,qB as isDtls,dB as isLinkLocalAddress,D_ as isMedia,G_ as isRtcp,A_ as keyLength,__ as leb128decode,Q7 as makeIntegrityKey,k4 as methods,FB as microTime,c5 as milliTime,k3 as nodeIpAddress,Gh as normalizeFamilyNodeV18,o5 as normalizeFingerprintAlgorithm,wg as normalizeFingerprintValue,KB as ntpTime,K_ as ntpTime2Sec,pZ as paddingBits,Wh as paddingByte,b3 as paddingLength,j1 as parseGroup,$B as parseIceServers,Qg as parseMessage,f8 as random16,V1 as random32,y8 as randomPort,wZ as randomPorts,VB as reverseDirection,SJ as reverseSimulcastDirection,X_ as rtpHeaderExtensionsParser,C_ as saltLength,e7 as serializeAbsSendTime,DZ as serializeAudioLevelIndication,J_ as serializeRepairedRtpStreamId,Y_ as serializeSdesMid,Z_ as serializeSdesRTPStreamID,Q_ as serializeTransportWideCC,uB as serverReflexiveCandidate,C8 as signatures,cB as sortCandidatePairs,oJ as supportedAudioCodecs,Q4 as supportedCodecs,iJ as supportedVideoCodecs,UZ as timer,ap as timestampSeconds,Tr as uint16Add,Fg as uint16Gt,yZ as uint16Gte,PT as uint24,Zc as uint32Add,ai as uint32Gt,Id as uint32Gte,NT as uint8Add,f7 as unwrapRtx,tJ as url2Address,AB as useAV1X,dJ as useAbsSendTime,hJ as useAudioLevelIndication,lJ as useDependencyDescriptor,nJ as useFIR,SB as useH264,xp as useNACK,Z4 as useOPUS,J4 as usePCMU,sl as usePLI,mp as useREMB,uJ as useRepairedRtpStreamId,aJ as useSdesMid,cJ as useSdesRTPStreamId,yB as useTWCC,fJ as useTransportWideCC,Y4 as useVP8,EB as useVP9,pJ as useVideoOrientation,B3 as validateAddress,_3 as validateRemoteCandidate,d7 as wrapRtx};