@helia/verified-fetch 0.0.0-28d62f7 → 0.0.0-2d965be
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/index.min.js +7 -7
- package/dist/src/utils/responses.d.ts +0 -1
- package/dist/src/utils/responses.d.ts.map +1 -1
- package/dist/src/utils/responses.js +0 -6
- package/dist/src/utils/responses.js.map +1 -1
- package/dist/src/verified-fetch.d.ts.map +1 -1
- package/dist/src/verified-fetch.js +8 -38
- package/dist/src/verified-fetch.js.map +1 -1
- package/package.json +17 -19
- package/src/utils/responses.ts +0 -7
- package/src/verified-fetch.ts +9 -50
package/dist/index.min.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
(function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.HeliaVerifiedFetch = factory()}(typeof self !== 'undefined' ? self : this, function () {
|
|
2
|
-
"use strict";var HeliaVerifiedFetch=(()=>{var $E=Object.create;var ba=Object.defineProperty;var zE=Object.getOwnPropertyDescriptor;var KE=Object.getOwnPropertyNames;var GE=Object.getPrototypeOf,qE=Object.prototype.hasOwnProperty;var le=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),Be=(r,e)=>{for(var t in e)ba(r,t,{get:e[t],enumerable:!0})},vp=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of KE(e))!qE.call(r,i)&&i!==t&&ba(r,i,{get:()=>e[i],enumerable:!(n=zE(e,i))||n.enumerable});return r};var Q=(r,e,t)=>(t=r!=null?$E(GE(r)):{},vp(e||!r||!r.__esModule?ba(t,"default",{value:r,enumerable:!0}):t,r)),YE=r=>vp(ba({},"__esModule",{value:!0}),r);var Uu=le((xB,Vp)=>{var Yi=1e3,Wi=Yi*60,ji=Wi*60,fi=ji*24,Px=fi*7,Fx=fi*365.25;Vp.exports=function(r,e){e=e||{};var t=typeof r;if(t==="string"&&r.length>0)return Vx(r);if(t==="number"&&isFinite(r))return e.long?Hx(r):Mx(r);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(r))};function Vx(r){if(r=String(r),!(r.length>100)){var e=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(r);if(e){var t=parseFloat(e[1]),n=(e[2]||"ms").toLowerCase();switch(n){case"years":case"year":case"yrs":case"yr":case"y":return t*Fx;case"weeks":case"week":case"w":return t*Px;case"days":case"day":case"d":return t*fi;case"hours":case"hour":case"hrs":case"hr":case"h":return t*ji;case"minutes":case"minute":case"mins":case"min":case"m":return t*Wi;case"seconds":case"second":case"secs":case"sec":case"s":return t*Yi;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return t;default:return}}}}function Mx(r){var e=Math.abs(r);return e>=fi?Math.round(r/fi)+"d":e>=ji?Math.round(r/ji)+"h":e>=Wi?Math.round(r/Wi)+"m":e>=Yi?Math.round(r/Yi)+"s":r+"ms"}function Hx(r){var e=Math.abs(r);return e>=fi?Sa(r,e,fi,"day"):e>=ji?Sa(r,e,ji,"hour"):e>=Wi?Sa(r,e,Wi,"minute"):e>=Yi?Sa(r,e,Yi,"second"):r+" ms"}function Sa(r,e,t,n){var i=e>=t*1.5;return Math.round(r/t)+" "+n+(i?"s":"")}});var Hp=le((bB,Mp)=>{function $x(r){t.debug=t,t.default=t,t.coerce=c,t.disable=o,t.enable=i,t.enabled=s,t.humanize=Uu(),t.destroy=u,Object.keys(r).forEach(l=>{t[l]=r[l]}),t.names=[],t.skips=[],t.formatters={};function e(l){let d=0;for(let p=0;p<l.length;p++)d=(d<<5)-d+l.charCodeAt(p),d|=0;return t.colors[Math.abs(d)%t.colors.length]}t.selectColor=e;function t(l){let d,p=null,f,h;function m(...y){if(!m.enabled)return;let g=m,E=Number(new Date),x=E-(d||E);g.diff=x,g.prev=d,g.curr=E,d=E,y[0]=t.coerce(y[0]),typeof y[0]!="string"&&y.unshift("%O");let _=0;y[0]=y[0].replace(/%([a-zA-Z%])/g,(A,v)=>{if(A==="%%")return"%";_++;let b=t.formatters[v];if(typeof b=="function"){let T=y[_];A=b.call(g,T),y.splice(_,1),_--}return A}),t.formatArgs.call(g,y),(g.log||t.log).apply(g,y)}return m.namespace=l,m.useColors=t.useColors(),m.color=t.selectColor(l),m.extend=n,m.destroy=t.destroy,Object.defineProperty(m,"enabled",{enumerable:!0,configurable:!1,get:()=>p!==null?p:(f!==t.namespaces&&(f=t.namespaces,h=t.enabled(l)),h),set:y=>{p=y}}),typeof t.init=="function"&&t.init(m),m}function n(l,d){let p=t(this.namespace+(typeof d>"u"?":":d)+l);return p.log=this.log,p}function i(l){t.save(l),t.namespaces=l,t.names=[],t.skips=[];let d,p=(typeof l=="string"?l:"").split(/[\s,]+/),f=p.length;for(d=0;d<f;d++)p[d]&&(l=p[d].replace(/\*/g,".*?"),l[0]==="-"?t.skips.push(new RegExp("^"+l.slice(1)+"$")):t.names.push(new RegExp("^"+l+"$")))}function o(){let l=[...t.names.map(a),...t.skips.map(a).map(d=>"-"+d)].join(",");return t.enable(""),l}function s(l){if(l[l.length-1]==="*")return!0;let d,p;for(d=0,p=t.skips.length;d<p;d++)if(t.skips[d].test(l))return!1;for(d=0,p=t.names.length;d<p;d++)if(t.names[d].test(l))return!0;return!1}function a(l){return l.toString().substring(2,l.toString().length-2).replace(/\.\*\?$/,"*")}function c(l){return l instanceof Error?l.stack||l.message:l}function u(){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 t.enable(t.load()),t}Mp.exports=$x});var Du=le((_t,Ia)=>{_t.formatArgs=Kx;_t.save=Gx;_t.load=qx;_t.useColors=zx;_t.storage=Yx();_t.destroy=(()=>{let r=!1;return()=>{r||(r=!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`."))}})();_t.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 zx(){return typeof window<"u"&&window.process&&(window.process.type==="renderer"||window.process.__nwjs)?!0:typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)?!1: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&&navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)&&parseInt(RegExp.$1,10)>=31||typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)}function Kx(r){if(r[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+r[0]+(this.useColors?"%c ":" ")+"+"+Ia.exports.humanize(this.diff),!this.useColors)return;let e="color: "+this.color;r.splice(1,0,e,"color: inherit");let t=0,n=0;r[0].replace(/%[a-zA-Z%]/g,i=>{i!=="%%"&&(t++,i==="%c"&&(n=t))}),r.splice(n,0,e)}_t.log=console.debug||console.log||(()=>{});function Gx(r){try{r?_t.storage.setItem("debug",r):_t.storage.removeItem("debug")}catch{}}function qx(){let r;try{r=_t.storage.getItem("debug")}catch{}return!r&&typeof process<"u"&&"env"in process&&(r=process.env.DEBUG),r}function Yx(){try{return localStorage}catch{}}Ia.exports=Hp()(_t);var{formatters:Wx}=Ia.exports;Wx.j=function(r){try{return JSON.stringify(r)}catch(e){return"[UnexpectedJSONParseError]: "+e.message}}});var qp=le((kB,Gp)=>{Gp.exports=Pu;var Kp=128,Jx=127,Qx=~Jx,eb=Math.pow(2,31);function Pu(r,e,t){if(Number.MAX_SAFE_INTEGER&&r>Number.MAX_SAFE_INTEGER)throw Pu.bytes=0,new RangeError("Could not encode varint");e=e||[],t=t||0;for(var n=t;r>=eb;)e[t++]=r&255|Kp,r/=128;for(;r&Qx;)e[t++]=r&255|Kp,r>>>=7;return e[t]=r|0,Pu.bytes=t-n+1,e}});var jp=le((RB,Wp)=>{Wp.exports=Fu;var tb=128,Yp=127;function Fu(r,n){var t=0,n=n||0,i=0,o=n,s,a=r.length;do{if(o>=a||i>49)throw Fu.bytes=0,new RangeError("Could not decode varint");s=r[o++],t+=i<28?(s&Yp)<<i:(s&Yp)*Math.pow(2,i),i+=7}while(s>=tb);return Fu.bytes=o-n,t}});var Zp=le((TB,Xp)=>{var rb=Math.pow(2,7),nb=Math.pow(2,14),ib=Math.pow(2,21),ob=Math.pow(2,28),sb=Math.pow(2,35),ab=Math.pow(2,42),cb=Math.pow(2,49),lb=Math.pow(2,56),ub=Math.pow(2,63);Xp.exports=function(r){return r<rb?1:r<nb?2:r<ib?3:r<ob?4:r<sb?5:r<ab?6:r<cb?7:r<lb?8:r<ub?9:10}});var Ba=le((NB,Jp)=>{Jp.exports={encode:qp(),decode:jp(),encodingLength:Zp()}});var Ce=le((j8,g0)=>{"use strict";function y0(r,e){for(let t in e)Object.defineProperty(r,t,{value:e[t],enumerable:!0,configurable:!0});return r}function Gb(r,e,t){if(!r||typeof r=="string")throw new TypeError("Please pass an Error to err-code");t||(t={}),typeof e=="object"&&(t=e,e=""),e&&(t.code=e);try{return y0(r,t)}catch{t.message=r.message,t.stack=r.stack;let i=function(){};return i.prototype=Object.create(Object.getPrototypeOf(r)),y0(new i,t)}}g0.exports=Gb});var h1=le(yo=>{"use strict";var O6="[object ArrayBuffer]",Wr=class r{static isArrayBuffer(e){return Object.prototype.toString.call(e)===O6}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,t){if(e.constructor===t)return e;if(this.isArrayBuffer(e))return new t(e);if(this.isArrayBufferView(e))return new t(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,t){let n=r.toUint8Array(e),i=r.toUint8Array(t);if(n.length!==i.byteLength)return!1;for(let o=0;o<n.length;o++)if(n[o]!==i[o])return!1;return!0}static concat(...e){let t;Array.isArray(e[0])&&!(e[1]instanceof Function)||Array.isArray(e[0])&&e[1]instanceof Function?t=e[0]:e[e.length-1]instanceof Function?t=e.slice(0,e.length-1):t=e;let n=0;for(let s of t)n+=s.byteLength;let i=new Uint8Array(n),o=0;for(let s of t){let a=this.toUint8Array(s);i.set(a,o),o+=a.length}return e[e.length-1]instanceof Function?this.toView(i,e[e.length-1]):i.buffer}},Yd="string",P6=/^[0-9a-f]+$/i,F6=/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/,V6=/^[a-zA-Z0-9-_]+$/,nc=class{static fromString(e){let t=unescape(encodeURIComponent(e)),n=new Uint8Array(t.length);for(let i=0;i<t.length;i++)n[i]=t.charCodeAt(i);return n.buffer}static toString(e){let t=Wr.toUint8Array(e),n="";for(let o=0;o<t.length;o++)n+=String.fromCharCode(t[o]);return decodeURIComponent(escape(n))}},qt=class{static toString(e,t=!1){let n=Wr.toArrayBuffer(e),i=new DataView(n),o="";for(let s=0;s<n.byteLength;s+=2){let a=i.getUint16(s,t);o+=String.fromCharCode(a)}return o}static fromString(e,t=!1){let n=new ArrayBuffer(e.length*2),i=new DataView(n);for(let o=0;o<e.length;o++)i.setUint16(o*2,e.charCodeAt(o),t);return n}},ic=class r{static isHex(e){return typeof e===Yd&&P6.test(e)}static isBase64(e){return typeof e===Yd&&F6.test(e)}static isBase64Url(e){return typeof e===Yd&&V6.test(e)}static ToString(e,t="utf8"){let n=Wr.toUint8Array(e);switch(t.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 qt.toString(n,!0);case"utf16":case"utf16be":return qt.toString(n);default:throw new Error(`Unknown type of encoding '${t}'`)}}static FromString(e,t="utf8"){if(!e)return new ArrayBuffer(0);switch(t.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 qt.fromString(e,!0);case"utf16":case"utf16be":return qt.fromString(e);default:throw new Error(`Unknown type of encoding '${t}'`)}}static ToBase64(e){let t=Wr.toUint8Array(e);if(typeof btoa<"u"){let n=this.ToString(t,"binary");return btoa(n)}else return Buffer.from(t).toString("base64")}static FromBase64(e){let t=this.formatString(e);if(!t)return new ArrayBuffer(0);if(!r.isBase64(t))throw new TypeError("Argument 'base64Text' is not Base64 encoded");return typeof atob<"u"?this.FromBinary(atob(t)):new Uint8Array(Buffer.from(t,"base64")).buffer}static FromBase64Url(e){let t=this.formatString(e);if(!t)return new ArrayBuffer(0);if(!r.isBase64Url(t))throw new TypeError("Argument 'base64url' is not Base64Url encoded");return this.FromBase64(this.Base64Padding(t.replace(/\-/g,"+").replace(/\_/g,"/")))}static ToBase64Url(e){return this.ToBase64(e).replace(/\+/g,"-").replace(/\//g,"_").replace(/\=/g,"")}static FromUtf8String(e,t=r.DEFAULT_UTF8_ENCODING){switch(t){case"ascii":return this.FromBinary(e);case"utf8":return nc.fromString(e);case"utf16":case"utf16be":return qt.fromString(e);case"utf16le":case"usc2":return qt.fromString(e,!0);default:throw new Error(`Unknown type of encoding '${t}'`)}}static ToUtf8String(e,t=r.DEFAULT_UTF8_ENCODING){switch(t){case"ascii":return this.ToBinary(e);case"utf8":return nc.toString(e);case"utf16":case"utf16be":return qt.toString(e);case"utf16le":case"usc2":return qt.toString(e,!0);default:throw new Error(`Unknown type of encoding '${t}'`)}}static FromBinary(e){let t=e.length,n=new Uint8Array(t);for(let i=0;i<t;i++)n[i]=e.charCodeAt(i);return n.buffer}static ToBinary(e){let t=Wr.toUint8Array(e),n="";for(let i=0;i<t.length;i++)n+=String.fromCharCode(t[i]);return n}static ToHex(e){let t=Wr.toUint8Array(e),n="",i=t.length;for(let o=0;o<i;o++){let s=t[o];s<16&&(n+="0"),n+=s.toString(16)}return n}static FromHex(e){let t=this.formatString(e);if(!t)return new ArrayBuffer(0);if(!r.isHex(t))throw new TypeError("Argument 'hexString' is not HEX encoded");t.length%2&&(t=`0${t}`);let n=new Uint8Array(t.length/2);for(let i=0;i<t.length;i=i+2){let o=t.slice(i,i+2);n[i/2]=parseInt(o,16)}return n.buffer}static ToUtf16String(e,t=!1){return qt.toString(e,t)}static FromUtf16String(e,t=!1){return qt.fromString(e,t)}static Base64Padding(e){let t=4-e.length%4;if(t<4)for(let n=0;n<t;n++)e+="=";return e}static formatString(e){return e?.replace(/[\n\r\t ]/g,"")||""}};ic.DEFAULT_UTF8_ENCODING="utf8";function M6(r,...e){let t=arguments[0];for(let n=1;n<arguments.length;n++){let i=arguments[n];for(let o in i)t[o]=i[o]}return t}function H6(...r){let e=r.map(i=>i.byteLength).reduce((i,o)=>i+o),t=new Uint8Array(e),n=0;return r.map(i=>new Uint8Array(i)).forEach(i=>{for(let o of i)t[n++]=o}),t.buffer}function $6(r,e){if(!(r&&e)||r.byteLength!==e.byteLength)return!1;let t=new Uint8Array(r),n=new Uint8Array(e);for(let i=0;i<r.byteLength;i++)if(t[i]!==n[i])return!1;return!0}yo.BufferSourceConverter=Wr;yo.Convert=ic;yo.assign=M6;yo.combine=H6;yo.isEqual=$6});var Yc=le((fN,lf)=>{var dN=function(){typeof lf<"u"&&(lf.exports=m);var r=86400,e=3200,t=146097*e/400,n=r*t,i=1e3*n,o=864e13,s=4294967296,a=1e6,c="000000000",u=Math.trunc||function(b){var T=b-b%1;return T==0&&(b<0||b===0&&1/b!=1/0)?-0:T},l=m.prototype,d=(m.fromDate=function(b){return new m(+b)},m.fromInt64BE=_(0,1,2,3,0,4),m.fromInt64LE=_(3,2,1,0,4,0),m.fromString=function(N){var T,C=new m,N=(N+="").replace(/^\s*[+\-]?\d+/,function(D){var D=+D,ne=1970+(D-1970)%400;return C.year=D-ne,ne}).replace(/(?:Z|([+\-]\d{2}):?(\d{2}))$/,function($,D,ne){return D<0&&(ne*=-1),T=6e4*(60*+D+ +ne),""}).replace(/\.\d+$/,function($){return C.nano=+($+c).substr(1,9),""}).split(/\D+/);if(1<N.length?N[1]--:N[1]=0,C.time=T=Date.UTC.apply(Date,N)-(T||0),isNaN(T))throw new TypeError("Invalid Date");return y(C)},m.fromTimeT=function(b){return E(b,0)},l.year=0,l.time=0,l.nano=0,l.addNano=function(b){return this.nano+=+b||0,this},l.getNano=function(){var b=y(this);return(b.time%1e3*a+ +b.nano+1e9)%1e9},l.getTimeT=function(){var T=y(this),b=Math.floor(T.time/1e3),T=T.year;return T&&(b+=T*t*r/e),b},l.getYear=function(){return this.toDate().getUTCFullYear()+this.year},l.toDate=function(){return g(y(this).time)},l.toJSON=function(){return this.toString().replace(/0{1,6}Z$/,"Z")},l.toString=function(b){var T=this,C=T.toDate(),N={H:function(){return A(C.getUTCHours())},L:function(){return v(C.getUTCMilliseconds(),3)},M:function(){return A(C.getUTCMinutes())},N:function(){return v(T.getNano(),9)},S:function(){return A(C.getUTCSeconds())},Y:function(){var $=T.getYear();return 999999<$?"+"+$:9999<$?"+"+v($,6):0<=$?v($,4):-999999<=$?"-"+v(-$,6):$},a:function(){return f[C.getUTCDay()]},b:function(){return p[C.getUTCMonth()]},d:function(){return A(C.getUTCDate())},e:function(){return function($){return(9<$?"":" ")+(0|$)}(C.getUTCDate())},m:function(){return A(C.getUTCMonth()+1)}};return function $(D){return D.replace(/%./g,function(ne){var U=ne[1],B=h[U],U=N[U];return B?$(B):U?U():ne})}(b||d)},l.writeInt64BE=x(0,1,2,3,0,4),l.writeInt64LE=x(3,2,1,0,4,0),"%Y-%m-%dT%H:%M:%S.%NZ"),p=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],f=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],h={"%":"%",F:"%Y-%m-%d",n:`
|
|
3
|
-
`,R:"%H:%M",T:"%H:%M:%S",t:" ",X:"%T",Z:"GMT",z:"+0000"};return m;function m(b,T,C){var N=this;if(!(N instanceof m))return new m(b,T,C);N.time=+b||0,N.nano=+T||0,N.year=+C||0,y(N)}function y(b){var T,C,N,$=b.year,D=b.time,ne=b.nano,B=((ne<0||a<=ne)&&(ne-=(C=Math.floor(ne/a))*a,D+=C,C=1),$%e);return(D<-o||o<D||B)&&((T=u(D/i))&&($+=T*e,D-=T*i),(N=g(D)).setUTCFullYear(B+N.getUTCFullYear()),N=(D=+N)+(T=u(($-=B)/e))*i,T&&-o<=N&&N<=o&&($-=T*e,D=N),C=1),C&&(b.year=$,b.time=D,b.nano=ne),b}function g(b){var T=new Date(0);return T.setTime(b),T}function E($,N){$=+$||0;var C=u((N=(N|0)*s)/n)+u($/n),N=N%n+$%n,$=u(N/n);return $&&(C+=$,N-=$*n),new m(1e3*N,0,C*e)}function x(b,T,C,N,$,D){return function(B,U){var L=y(this);B=B||new Array(8),S(B,U|=0);var k=Math.floor(L.time/1e3),L=L.year*(t*r/e),X=u(L/s)+u(k/s),L=L%s+k%s,k=Math.floor(L/s);return k&&(X+=k,L-=k*s),ne(B,U+$,X),ne(B,U+D,L),B};function ne(B,U,X){B[U+b]=X>>24&255,B[U+T]=X>>16&255,B[U+C]=X>>8&255,B[U+N]=255&X}}function _(b,T,C,N,$,D){return function(B,U){S(B,U|=0);var X=ne(B,U+$);return E(ne(B,U+D),X)};function ne(B,U){return 16777216*B[U+b]+(B[U+T]<<16|B[U+C]<<8|B[U+N])}}function S(b,T){if(b=b&&b.length,b==null)throw new TypeError("Invalid Buffer");if(b<T+8)throw new RangeError("Out of range")}function A(b){return(9<b?"":"0")+(0|b)}function v(b,T){return(c+(0|b)).substr(-T)}}()});var Hy=le((jC,Sf)=>{"use strict";var aA=Object.prototype.hasOwnProperty,ft="~";function Ds(){}Object.create&&(Ds.prototype=Object.create(null),new Ds().__proto__||(ft=!1));function cA(r,e,t){this.fn=r,this.context=e,this.once=t||!1}function My(r,e,t,n,i){if(typeof t!="function")throw new TypeError("The listener must be a function");var o=new cA(t,n||r,i),s=ft?ft+e:e;return r._events[s]?r._events[s].fn?r._events[s]=[r._events[s],o]:r._events[s].push(o):(r._events[s]=o,r._eventsCount++),r}function ll(r,e){--r._eventsCount===0?r._events=new Ds:delete r._events[e]}function rt(){this._events=new Ds,this._eventsCount=0}rt.prototype.eventNames=function(){var e=[],t,n;if(this._eventsCount===0)return e;for(n in t=this._events)aA.call(t,n)&&e.push(ft?n.slice(1):n);return Object.getOwnPropertySymbols?e.concat(Object.getOwnPropertySymbols(t)):e};rt.prototype.listeners=function(e){var t=ft?ft+e:e,n=this._events[t];if(!n)return[];if(n.fn)return[n.fn];for(var i=0,o=n.length,s=new Array(o);i<o;i++)s[i]=n[i].fn;return s};rt.prototype.listenerCount=function(e){var t=ft?ft+e:e,n=this._events[t];return n?n.fn?1:n.length:0};rt.prototype.emit=function(e,t,n,i,o,s){var a=ft?ft+e:e;if(!this._events[a])return!1;var c=this._events[a],u=arguments.length,l,d;if(c.fn){switch(c.once&&this.removeListener(e,c.fn,void 0,!0),u){case 1:return c.fn.call(c.context),!0;case 2:return c.fn.call(c.context,t),!0;case 3:return c.fn.call(c.context,t,n),!0;case 4:return c.fn.call(c.context,t,n,i),!0;case 5:return c.fn.call(c.context,t,n,i,o),!0;case 6:return c.fn.call(c.context,t,n,i,o,s),!0}for(d=1,l=new Array(u-1);d<u;d++)l[d-1]=arguments[d];c.fn.apply(c.context,l)}else{var p=c.length,f;for(d=0;d<p;d++)switch(c[d].once&&this.removeListener(e,c[d].fn,void 0,!0),u){case 1:c[d].fn.call(c[d].context);break;case 2:c[d].fn.call(c[d].context,t);break;case 3:c[d].fn.call(c[d].context,t,n);break;case 4:c[d].fn.call(c[d].context,t,n,i);break;default:if(!l)for(f=1,l=new Array(u-1);f<u;f++)l[f-1]=arguments[f];c[d].fn.apply(c[d].context,l)}}return!0};rt.prototype.on=function(e,t,n){return My(this,e,t,n,!1)};rt.prototype.once=function(e,t,n){return My(this,e,t,n,!0)};rt.prototype.removeListener=function(e,t,n,i){var o=ft?ft+e:e;if(!this._events[o])return this;if(!t)return ll(this,o),this;var s=this._events[o];if(s.fn)s.fn===t&&(!i||s.once)&&(!n||s.context===n)&&ll(this,o);else{for(var a=0,c=[],u=s.length;a<u;a++)(s[a].fn!==t||i&&!s[a].once||n&&s[a].context!==n)&&c.push(s[a]);c.length?this._events[o]=c.length===1?c[0]:c:ll(this,o)}return this};rt.prototype.removeAllListeners=function(e){var t;return e?(t=ft?ft+e:e,this._events[t]&&ll(this,t)):(this._events=new Ds,this._eventsCount=0),this};rt.prototype.off=rt.prototype.removeListener;rt.prototype.addListener=rt.prototype.on;rt.prefixed=ft;rt.EventEmitter=rt;typeof Sf<"u"&&(Sf.exports=rt)});var Hg=le((B7,Mg)=>{"use strict";Mg.exports=Vg;var b_=Uu(),Jn=Vg.prototype,v_=new Date%1e9;function A_(){return(Math.random()*1e9>>>0)+v_++}function Vg(r){r=r||{},this.id=r.id||A_(),this.max=r.max||1/0,this.items=r.items||[],this._lookup={},this.size=this.items.length,this.lastModified=new Date(r.lastModified||new Date);for(var e,t,n=this.items.length;n--;)e=this.items[n],t=new Date(e.expires)-new Date,this._lookup[e.key]=e,t>0?this.expire(e.key,t):t<=0&&this.delete(e.key)}Jn.has=function(r){return r in this._lookup};Jn.get=function(r){if(!this.has(r))return null;var e=this._lookup[r];return e.refresh&&this.expire(r,e.refresh),this.items.splice(this.items.indexOf(e),1),this.items.push(e),e.value};Jn.meta=function(r){if(!this.has(r))return null;var e=this._lookup[r];return"meta"in e?e.meta:null};Jn.set=function(r,e,t){var n=this._lookup[r],i=this._lookup[r]={key:r,value:e};return this.lastModified=new Date,n?(clearTimeout(n.timeout),this.items.splice(this.items.indexOf(n),1,i)):(this.size>=this.max&&this.delete(this.items[0].key),this.items.push(i),this.size++),t&&("ttl"in t&&this.expire(r,t.ttl),"meta"in t&&(i.meta=t.meta),t.refresh&&(i.refresh=t.ttl)),this};Jn.delete=function(r){var e=this._lookup[r];return e?(this.lastModified=new Date,this.items.splice(this.items.indexOf(e),1),clearTimeout(e.timeout),delete this._lookup[r],this.size--,this):!1};Jn.expire=function(r,e){var t=e||0,n=this._lookup[r];if(!n)return this;if(typeof t=="string"&&(t=b_(e)),typeof t!="number")throw new TypeError("Expiration time must be a string or number.");return clearTimeout(n.timeout),n.timeout=setTimeout(this.delete.bind(this,n.key),t),n.expires=Number(new Date)+t,this};Jn.clear=function(){for(var r=this.items.length;r--;)this.delete(this.items[r].key);return this};Jn.toJSON=function(){for(var r=new Array(this.items.length),e,t=r.length;t--;)e=this.items[t],r[t]={key:e.key,meta:e.meta,value:e.value,expires:e.expires,refresh:e.refresh};return{id:this.id,max:isFinite(this.max)?this.max:void 0,lastModified:this.lastModified,items:r}}});var mh=le((R7,Kg)=>{Kg.exports=function(r){if(!r)throw Error("hashlru must have a max value, of type number, greater than 0");var e=0,t=Object.create(null),n=Object.create(null);function i(o,s){t[o]=s,e++,e>=r&&(e=0,n=t,t=Object.create(null))}return{has:function(o){return t[o]!==void 0||n[o]!==void 0},remove:function(o){t[o]!==void 0&&(t[o]=void 0),n[o]!==void 0&&(n[o]=void 0)},get:function(o){var s=t[o];if(s!==void 0)return s;if((s=n[o])!==void 0)return i(o,s),s},set:function(o,s){t[o]!==void 0?t[o]=s:i(o,s)},clear:function(){t=Object.create(null),n=Object.create(null)}}}});var iw=le(Dl=>{"use strict";Dl.byteLength=C_;Dl.toByteArray=U_;Dl.fromByteArray=P_;var Ir=[],Xt=[],N_=typeof Uint8Array<"u"?Uint8Array:Array,bh="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(Li=0,rw=bh.length;Li<rw;++Li)Ir[Li]=bh[Li],Xt[bh.charCodeAt(Li)]=Li;var Li,rw;Xt[45]=62;Xt[95]=63;function nw(r){var e=r.length;if(e%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var t=r.indexOf("=");t===-1&&(t=e);var n=t===e?0:4-t%4;return[t,n]}function C_(r){var e=nw(r),t=e[0],n=e[1];return(t+n)*3/4-n}function L_(r,e,t){return(e+t)*3/4-t}function U_(r){var e,t=nw(r),n=t[0],i=t[1],o=new N_(L_(r,n,i)),s=0,a=i>0?n-4:n,c;for(c=0;c<a;c+=4)e=Xt[r.charCodeAt(c)]<<18|Xt[r.charCodeAt(c+1)]<<12|Xt[r.charCodeAt(c+2)]<<6|Xt[r.charCodeAt(c+3)],o[s++]=e>>16&255,o[s++]=e>>8&255,o[s++]=e&255;return i===2&&(e=Xt[r.charCodeAt(c)]<<2|Xt[r.charCodeAt(c+1)]>>4,o[s++]=e&255),i===1&&(e=Xt[r.charCodeAt(c)]<<10|Xt[r.charCodeAt(c+1)]<<4|Xt[r.charCodeAt(c+2)]>>2,o[s++]=e>>8&255,o[s++]=e&255),o}function D_(r){return Ir[r>>18&63]+Ir[r>>12&63]+Ir[r>>6&63]+Ir[r&63]}function O_(r,e,t){for(var n,i=[],o=e;o<t;o+=3)n=(r[o]<<16&16711680)+(r[o+1]<<8&65280)+(r[o+2]&255),i.push(D_(n));return i.join("")}function P_(r){for(var e,t=r.length,n=t%3,i=[],o=16383,s=0,a=t-n;s<a;s+=o)i.push(O_(r,s,s+o>a?a:s+o));return n===1?(e=r[t-1],i.push(Ir[e>>2]+Ir[e<<4&63]+"==")):n===2&&(e=(r[t-2]<<8)+r[t-1],i.push(Ir[e>>10]+Ir[e>>4&63]+Ir[e<<2&63]+"=")),i.join("")}});var ow=le(vh=>{vh.read=function(r,e,t,n,i){var o,s,a=i*8-n-1,c=(1<<a)-1,u=c>>1,l=-7,d=t?i-1:0,p=t?-1:1,f=r[e+d];for(d+=p,o=f&(1<<-l)-1,f>>=-l,l+=a;l>0;o=o*256+r[e+d],d+=p,l-=8);for(s=o&(1<<-l)-1,o>>=-l,l+=n;l>0;s=s*256+r[e+d],d+=p,l-=8);if(o===0)o=1-u;else{if(o===c)return s?NaN:(f?-1:1)*(1/0);s=s+Math.pow(2,n),o=o-u}return(f?-1:1)*s*Math.pow(2,o-n)};vh.write=function(r,e,t,n,i,o){var s,a,c,u=o*8-i-1,l=(1<<u)-1,d=l>>1,p=i===23?Math.pow(2,-24)-Math.pow(2,-77):0,f=n?0:o-1,h=n?1:-1,m=e<0||e===0&&1/e<0?1:0;for(e=Math.abs(e),isNaN(e)||e===1/0?(a=isNaN(e)?1:0,s=l):(s=Math.floor(Math.log(e)/Math.LN2),e*(c=Math.pow(2,-s))<1&&(s--,c*=2),s+d>=1?e+=p/c:e+=p*Math.pow(2,1-d),e*c>=2&&(s++,c/=2),s+d>=l?(a=0,s=l):s+d>=1?(a=(e*c-1)*Math.pow(2,i),s=s+d):(a=e*Math.pow(2,d-1)*Math.pow(2,i),s=0));i>=8;r[t+f]=a&255,f+=h,a/=256,i-=8);for(s=s<<i|a,u+=i;u>0;r[t+f]=s&255,f+=h,s/=256,u-=8);r[t+f-h]|=m*128}});var Nh=le(Oo=>{"use strict";var Ah=iw(),Uo=ow(),sw=typeof Symbol=="function"&&typeof Symbol.for=="function"?Symbol.for("nodejs.util.inspect.custom"):null;Oo.Buffer=I;Oo.SlowBuffer=z_;Oo.INSPECT_MAX_BYTES=50;var Ol=2147483647;Oo.kMaxLength=Ol;I.TYPED_ARRAY_SUPPORT=F_();!I.TYPED_ARRAY_SUPPORT&&typeof console<"u"&&typeof console.error=="function"&&console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support.");function F_(){try{let r=new Uint8Array(1),e={foo:function(){return 42}};return Object.setPrototypeOf(e,Uint8Array.prototype),Object.setPrototypeOf(r,e),r.foo()===42}catch{return!1}}Object.defineProperty(I.prototype,"parent",{enumerable:!0,get:function(){if(I.isBuffer(this))return this.buffer}});Object.defineProperty(I.prototype,"offset",{enumerable:!0,get:function(){if(I.isBuffer(this))return this.byteOffset}});function ln(r){if(r>Ol)throw new RangeError('The value "'+r+'" is invalid for option "size"');let e=new Uint8Array(r);return Object.setPrototypeOf(e,I.prototype),e}function I(r,e,t){if(typeof r=="number"){if(typeof e=="string")throw new TypeError('The "string" argument must be of type string. Received type number');return Bh(r)}return uw(r,e,t)}I.poolSize=8192;function uw(r,e,t){if(typeof r=="string")return M_(r,e);if(ArrayBuffer.isView(r))return H_(r);if(r==null)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof r);if(Br(r,ArrayBuffer)||r&&Br(r.buffer,ArrayBuffer)||typeof SharedArrayBuffer<"u"&&(Br(r,SharedArrayBuffer)||r&&Br(r.buffer,SharedArrayBuffer)))return Sh(r,e,t);if(typeof r=="number")throw new TypeError('The "value" argument must not be of type number. Received type number');let n=r.valueOf&&r.valueOf();if(n!=null&&n!==r)return I.from(n,e,t);let i=$_(r);if(i)return i;if(typeof Symbol<"u"&&Symbol.toPrimitive!=null&&typeof r[Symbol.toPrimitive]=="function")return I.from(r[Symbol.toPrimitive]("string"),e,t);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof r)}I.from=function(r,e,t){return uw(r,e,t)};Object.setPrototypeOf(I.prototype,Uint8Array.prototype);Object.setPrototypeOf(I,Uint8Array);function dw(r){if(typeof r!="number")throw new TypeError('"size" argument must be of type number');if(r<0)throw new RangeError('The value "'+r+'" is invalid for option "size"')}function V_(r,e,t){return dw(r),r<=0?ln(r):e!==void 0?typeof t=="string"?ln(r).fill(e,t):ln(r).fill(e):ln(r)}I.alloc=function(r,e,t){return V_(r,e,t)};function Bh(r){return dw(r),ln(r<0?0:kh(r)|0)}I.allocUnsafe=function(r){return Bh(r)};I.allocUnsafeSlow=function(r){return Bh(r)};function M_(r,e){if((typeof e!="string"||e==="")&&(e="utf8"),!I.isEncoding(e))throw new TypeError("Unknown encoding: "+e);let t=fw(r,e)|0,n=ln(t),i=n.write(r,e);return i!==t&&(n=n.slice(0,i)),n}function _h(r){let e=r.length<0?0:kh(r.length)|0,t=ln(e);for(let n=0;n<e;n+=1)t[n]=r[n]&255;return t}function H_(r){if(Br(r,Uint8Array)){let e=new Uint8Array(r);return Sh(e.buffer,e.byteOffset,e.byteLength)}return _h(r)}function Sh(r,e,t){if(e<0||r.byteLength<e)throw new RangeError('"offset" is outside of buffer bounds');if(r.byteLength<e+(t||0))throw new RangeError('"length" is outside of buffer bounds');let n;return e===void 0&&t===void 0?n=new Uint8Array(r):t===void 0?n=new Uint8Array(r,e):n=new Uint8Array(r,e,t),Object.setPrototypeOf(n,I.prototype),n}function $_(r){if(I.isBuffer(r)){let e=kh(r.length)|0,t=ln(e);return t.length===0||r.copy(t,0,0,e),t}if(r.length!==void 0)return typeof r.length!="number"||Th(r.length)?ln(0):_h(r);if(r.type==="Buffer"&&Array.isArray(r.data))return _h(r.data)}function kh(r){if(r>=Ol)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+Ol.toString(16)+" bytes");return r|0}function z_(r){return+r!=r&&(r=0),I.alloc(+r)}I.isBuffer=function(e){return e!=null&&e._isBuffer===!0&&e!==I.prototype};I.compare=function(e,t){if(Br(e,Uint8Array)&&(e=I.from(e,e.offset,e.byteLength)),Br(t,Uint8Array)&&(t=I.from(t,t.offset,t.byteLength)),!I.isBuffer(e)||!I.isBuffer(t))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(e===t)return 0;let n=e.length,i=t.length;for(let o=0,s=Math.min(n,i);o<s;++o)if(e[o]!==t[o]){n=e[o],i=t[o];break}return n<i?-1:i<n?1:0};I.isEncoding=function(e){switch(String(e).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}};I.concat=function(e,t){if(!Array.isArray(e))throw new TypeError('"list" argument must be an Array of Buffers');if(e.length===0)return I.alloc(0);let n;if(t===void 0)for(t=0,n=0;n<e.length;++n)t+=e[n].length;let i=I.allocUnsafe(t),o=0;for(n=0;n<e.length;++n){let s=e[n];if(Br(s,Uint8Array))o+s.length>i.length?(I.isBuffer(s)||(s=I.from(s)),s.copy(i,o)):Uint8Array.prototype.set.call(i,s,o);else if(I.isBuffer(s))s.copy(i,o);else throw new TypeError('"list" argument must be an Array of Buffers');o+=s.length}return i};function fw(r,e){if(I.isBuffer(r))return r.length;if(ArrayBuffer.isView(r)||Br(r,ArrayBuffer))return r.byteLength;if(typeof r!="string")throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof r);let t=r.length,n=arguments.length>2&&arguments[2]===!0;if(!n&&t===0)return 0;let i=!1;for(;;)switch(e){case"ascii":case"latin1":case"binary":return t;case"utf8":case"utf-8":return Ih(r).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return t*2;case"hex":return t>>>1;case"base64":return bw(r).length;default:if(i)return n?-1:Ih(r).length;e=(""+e).toLowerCase(),i=!0}}I.byteLength=fw;function K_(r,e,t){let n=!1;if((e===void 0||e<0)&&(e=0),e>this.length||((t===void 0||t>this.length)&&(t=this.length),t<=0)||(t>>>=0,e>>>=0,t<=e))return"";for(r||(r="utf8");;)switch(r){case"hex":return eS(this,e,t);case"utf8":case"utf-8":return pw(this,e,t);case"ascii":return J_(this,e,t);case"latin1":case"binary":return Q_(this,e,t);case"base64":return X_(this,e,t);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return tS(this,e,t);default:if(n)throw new TypeError("Unknown encoding: "+r);r=(r+"").toLowerCase(),n=!0}}I.prototype._isBuffer=!0;function Ui(r,e,t){let n=r[e];r[e]=r[t],r[t]=n}I.prototype.swap16=function(){let e=this.length;if(e%2!==0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(let t=0;t<e;t+=2)Ui(this,t,t+1);return this};I.prototype.swap32=function(){let e=this.length;if(e%4!==0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(let t=0;t<e;t+=4)Ui(this,t,t+3),Ui(this,t+1,t+2);return this};I.prototype.swap64=function(){let e=this.length;if(e%8!==0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(let t=0;t<e;t+=8)Ui(this,t,t+7),Ui(this,t+1,t+6),Ui(this,t+2,t+5),Ui(this,t+3,t+4);return this};I.prototype.toString=function(){let e=this.length;return e===0?"":arguments.length===0?pw(this,0,e):K_.apply(this,arguments)};I.prototype.toLocaleString=I.prototype.toString;I.prototype.equals=function(e){if(!I.isBuffer(e))throw new TypeError("Argument must be a Buffer");return this===e?!0:I.compare(this,e)===0};I.prototype.inspect=function(){let e="",t=Oo.INSPECT_MAX_BYTES;return e=this.toString("hex",0,t).replace(/(.{2})/g,"$1 ").trim(),this.length>t&&(e+=" ... "),"<Buffer "+e+">"};sw&&(I.prototype[sw]=I.prototype.inspect);I.prototype.compare=function(e,t,n,i,o){if(Br(e,Uint8Array)&&(e=I.from(e,e.offset,e.byteLength)),!I.isBuffer(e))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof e);if(t===void 0&&(t=0),n===void 0&&(n=e?e.length:0),i===void 0&&(i=0),o===void 0&&(o=this.length),t<0||n>e.length||i<0||o>this.length)throw new RangeError("out of range index");if(i>=o&&t>=n)return 0;if(i>=o)return-1;if(t>=n)return 1;if(t>>>=0,n>>>=0,i>>>=0,o>>>=0,this===e)return 0;let s=o-i,a=n-t,c=Math.min(s,a),u=this.slice(i,o),l=e.slice(t,n);for(let d=0;d<c;++d)if(u[d]!==l[d]){s=u[d],a=l[d];break}return s<a?-1:a<s?1:0};function hw(r,e,t,n,i){if(r.length===0)return-1;if(typeof t=="string"?(n=t,t=0):t>2147483647?t=2147483647:t<-2147483648&&(t=-2147483648),t=+t,Th(t)&&(t=i?0:r.length-1),t<0&&(t=r.length+t),t>=r.length){if(i)return-1;t=r.length-1}else if(t<0)if(i)t=0;else return-1;if(typeof e=="string"&&(e=I.from(e,n)),I.isBuffer(e))return e.length===0?-1:aw(r,e,t,n,i);if(typeof e=="number")return e=e&255,typeof Uint8Array.prototype.indexOf=="function"?i?Uint8Array.prototype.indexOf.call(r,e,t):Uint8Array.prototype.lastIndexOf.call(r,e,t):aw(r,[e],t,n,i);throw new TypeError("val must be string, number or Buffer")}function aw(r,e,t,n,i){let o=1,s=r.length,a=e.length;if(n!==void 0&&(n=String(n).toLowerCase(),n==="ucs2"||n==="ucs-2"||n==="utf16le"||n==="utf-16le")){if(r.length<2||e.length<2)return-1;o=2,s/=2,a/=2,t/=2}function c(l,d){return o===1?l[d]:l.readUInt16BE(d*o)}let u;if(i){let l=-1;for(u=t;u<s;u++)if(c(r,u)===c(e,l===-1?0:u-l)){if(l===-1&&(l=u),u-l+1===a)return l*o}else l!==-1&&(u-=u-l),l=-1}else for(t+a>s&&(t=s-a),u=t;u>=0;u--){let l=!0;for(let d=0;d<a;d++)if(c(r,u+d)!==c(e,d)){l=!1;break}if(l)return u}return-1}I.prototype.includes=function(e,t,n){return this.indexOf(e,t,n)!==-1};I.prototype.indexOf=function(e,t,n){return hw(this,e,t,n,!0)};I.prototype.lastIndexOf=function(e,t,n){return hw(this,e,t,n,!1)};function G_(r,e,t,n){t=Number(t)||0;let i=r.length-t;n?(n=Number(n),n>i&&(n=i)):n=i;let o=e.length;n>o/2&&(n=o/2);let s;for(s=0;s<n;++s){let a=parseInt(e.substr(s*2,2),16);if(Th(a))return s;r[t+s]=a}return s}function q_(r,e,t,n){return Pl(Ih(e,r.length-t),r,t,n)}function Y_(r,e,t,n){return Pl(oS(e),r,t,n)}function W_(r,e,t,n){return Pl(bw(e),r,t,n)}function j_(r,e,t,n){return Pl(sS(e,r.length-t),r,t,n)}I.prototype.write=function(e,t,n,i){if(t===void 0)i="utf8",n=this.length,t=0;else if(n===void 0&&typeof t=="string")i=t,n=this.length,t=0;else if(isFinite(t))t=t>>>0,isFinite(n)?(n=n>>>0,i===void 0&&(i="utf8")):(i=n,n=void 0);else throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");let o=this.length-t;if((n===void 0||n>o)&&(n=o),e.length>0&&(n<0||t<0)||t>this.length)throw new RangeError("Attempt to write outside buffer bounds");i||(i="utf8");let s=!1;for(;;)switch(i){case"hex":return G_(this,e,t,n);case"utf8":case"utf-8":return q_(this,e,t,n);case"ascii":case"latin1":case"binary":return Y_(this,e,t,n);case"base64":return W_(this,e,t,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return j_(this,e,t,n);default:if(s)throw new TypeError("Unknown encoding: "+i);i=(""+i).toLowerCase(),s=!0}};I.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function X_(r,e,t){return e===0&&t===r.length?Ah.fromByteArray(r):Ah.fromByteArray(r.slice(e,t))}function pw(r,e,t){t=Math.min(r.length,t);let n=[],i=e;for(;i<t;){let o=r[i],s=null,a=o>239?4:o>223?3:o>191?2:1;if(i+a<=t){let c,u,l,d;switch(a){case 1:o<128&&(s=o);break;case 2:c=r[i+1],(c&192)===128&&(d=(o&31)<<6|c&63,d>127&&(s=d));break;case 3:c=r[i+1],u=r[i+2],(c&192)===128&&(u&192)===128&&(d=(o&15)<<12|(c&63)<<6|u&63,d>2047&&(d<55296||d>57343)&&(s=d));break;case 4:c=r[i+1],u=r[i+2],l=r[i+3],(c&192)===128&&(u&192)===128&&(l&192)===128&&(d=(o&15)<<18|(c&63)<<12|(u&63)<<6|l&63,d>65535&&d<1114112&&(s=d))}}s===null?(s=65533,a=1):s>65535&&(s-=65536,n.push(s>>>10&1023|55296),s=56320|s&1023),n.push(s),i+=a}return Z_(n)}var cw=4096;function Z_(r){let e=r.length;if(e<=cw)return String.fromCharCode.apply(String,r);let t="",n=0;for(;n<e;)t+=String.fromCharCode.apply(String,r.slice(n,n+=cw));return t}function J_(r,e,t){let n="";t=Math.min(r.length,t);for(let i=e;i<t;++i)n+=String.fromCharCode(r[i]&127);return n}function Q_(r,e,t){let n="";t=Math.min(r.length,t);for(let i=e;i<t;++i)n+=String.fromCharCode(r[i]);return n}function eS(r,e,t){let n=r.length;(!e||e<0)&&(e=0),(!t||t<0||t>n)&&(t=n);let i="";for(let o=e;o<t;++o)i+=aS[r[o]];return i}function tS(r,e,t){let n=r.slice(e,t),i="";for(let o=0;o<n.length-1;o+=2)i+=String.fromCharCode(n[o]+n[o+1]*256);return i}I.prototype.slice=function(e,t){let n=this.length;e=~~e,t=t===void 0?n:~~t,e<0?(e+=n,e<0&&(e=0)):e>n&&(e=n),t<0?(t+=n,t<0&&(t=0)):t>n&&(t=n),t<e&&(t=e);let i=this.subarray(e,t);return Object.setPrototypeOf(i,I.prototype),i};function $e(r,e,t){if(r%1!==0||r<0)throw new RangeError("offset is not uint");if(r+e>t)throw new RangeError("Trying to access beyond buffer length")}I.prototype.readUintLE=I.prototype.readUIntLE=function(e,t,n){e=e>>>0,t=t>>>0,n||$e(e,t,this.length);let i=this[e],o=1,s=0;for(;++s<t&&(o*=256);)i+=this[e+s]*o;return i};I.prototype.readUintBE=I.prototype.readUIntBE=function(e,t,n){e=e>>>0,t=t>>>0,n||$e(e,t,this.length);let i=this[e+--t],o=1;for(;t>0&&(o*=256);)i+=this[e+--t]*o;return i};I.prototype.readUint8=I.prototype.readUInt8=function(e,t){return e=e>>>0,t||$e(e,1,this.length),this[e]};I.prototype.readUint16LE=I.prototype.readUInt16LE=function(e,t){return e=e>>>0,t||$e(e,2,this.length),this[e]|this[e+1]<<8};I.prototype.readUint16BE=I.prototype.readUInt16BE=function(e,t){return e=e>>>0,t||$e(e,2,this.length),this[e]<<8|this[e+1]};I.prototype.readUint32LE=I.prototype.readUInt32LE=function(e,t){return e=e>>>0,t||$e(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+this[e+3]*16777216};I.prototype.readUint32BE=I.prototype.readUInt32BE=function(e,t){return e=e>>>0,t||$e(e,4,this.length),this[e]*16777216+(this[e+1]<<16|this[e+2]<<8|this[e+3])};I.prototype.readBigUInt64LE=ti(function(e){e=e>>>0,Do(e,"offset");let t=this[e],n=this[e+7];(t===void 0||n===void 0)&&ra(e,this.length-8);let i=t+this[++e]*2**8+this[++e]*2**16+this[++e]*2**24,o=this[++e]+this[++e]*2**8+this[++e]*2**16+n*2**24;return BigInt(i)+(BigInt(o)<<BigInt(32))});I.prototype.readBigUInt64BE=ti(function(e){e=e>>>0,Do(e,"offset");let t=this[e],n=this[e+7];(t===void 0||n===void 0)&&ra(e,this.length-8);let i=t*2**24+this[++e]*2**16+this[++e]*2**8+this[++e],o=this[++e]*2**24+this[++e]*2**16+this[++e]*2**8+n;return(BigInt(i)<<BigInt(32))+BigInt(o)});I.prototype.readIntLE=function(e,t,n){e=e>>>0,t=t>>>0,n||$e(e,t,this.length);let i=this[e],o=1,s=0;for(;++s<t&&(o*=256);)i+=this[e+s]*o;return o*=128,i>=o&&(i-=Math.pow(2,8*t)),i};I.prototype.readIntBE=function(e,t,n){e=e>>>0,t=t>>>0,n||$e(e,t,this.length);let i=t,o=1,s=this[e+--i];for(;i>0&&(o*=256);)s+=this[e+--i]*o;return o*=128,s>=o&&(s-=Math.pow(2,8*t)),s};I.prototype.readInt8=function(e,t){return e=e>>>0,t||$e(e,1,this.length),this[e]&128?(255-this[e]+1)*-1:this[e]};I.prototype.readInt16LE=function(e,t){e=e>>>0,t||$e(e,2,this.length);let n=this[e]|this[e+1]<<8;return n&32768?n|4294901760:n};I.prototype.readInt16BE=function(e,t){e=e>>>0,t||$e(e,2,this.length);let n=this[e+1]|this[e]<<8;return n&32768?n|4294901760:n};I.prototype.readInt32LE=function(e,t){return e=e>>>0,t||$e(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24};I.prototype.readInt32BE=function(e,t){return e=e>>>0,t||$e(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]};I.prototype.readBigInt64LE=ti(function(e){e=e>>>0,Do(e,"offset");let t=this[e],n=this[e+7];(t===void 0||n===void 0)&&ra(e,this.length-8);let i=this[e+4]+this[e+5]*2**8+this[e+6]*2**16+(n<<24);return(BigInt(i)<<BigInt(32))+BigInt(t+this[++e]*2**8+this[++e]*2**16+this[++e]*2**24)});I.prototype.readBigInt64BE=ti(function(e){e=e>>>0,Do(e,"offset");let t=this[e],n=this[e+7];(t===void 0||n===void 0)&&ra(e,this.length-8);let i=(t<<24)+this[++e]*2**16+this[++e]*2**8+this[++e];return(BigInt(i)<<BigInt(32))+BigInt(this[++e]*2**24+this[++e]*2**16+this[++e]*2**8+n)});I.prototype.readFloatLE=function(e,t){return e=e>>>0,t||$e(e,4,this.length),Uo.read(this,e,!0,23,4)};I.prototype.readFloatBE=function(e,t){return e=e>>>0,t||$e(e,4,this.length),Uo.read(this,e,!1,23,4)};I.prototype.readDoubleLE=function(e,t){return e=e>>>0,t||$e(e,8,this.length),Uo.read(this,e,!0,52,8)};I.prototype.readDoubleBE=function(e,t){return e=e>>>0,t||$e(e,8,this.length),Uo.read(this,e,!1,52,8)};function vt(r,e,t,n,i,o){if(!I.isBuffer(r))throw new TypeError('"buffer" argument must be a Buffer instance');if(e>i||e<o)throw new RangeError('"value" argument is out of bounds');if(t+n>r.length)throw new RangeError("Index out of range")}I.prototype.writeUintLE=I.prototype.writeUIntLE=function(e,t,n,i){if(e=+e,t=t>>>0,n=n>>>0,!i){let a=Math.pow(2,8*n)-1;vt(this,e,t,n,a,0)}let o=1,s=0;for(this[t]=e&255;++s<n&&(o*=256);)this[t+s]=e/o&255;return t+n};I.prototype.writeUintBE=I.prototype.writeUIntBE=function(e,t,n,i){if(e=+e,t=t>>>0,n=n>>>0,!i){let a=Math.pow(2,8*n)-1;vt(this,e,t,n,a,0)}let o=n-1,s=1;for(this[t+o]=e&255;--o>=0&&(s*=256);)this[t+o]=e/s&255;return t+n};I.prototype.writeUint8=I.prototype.writeUInt8=function(e,t,n){return e=+e,t=t>>>0,n||vt(this,e,t,1,255,0),this[t]=e&255,t+1};I.prototype.writeUint16LE=I.prototype.writeUInt16LE=function(e,t,n){return e=+e,t=t>>>0,n||vt(this,e,t,2,65535,0),this[t]=e&255,this[t+1]=e>>>8,t+2};I.prototype.writeUint16BE=I.prototype.writeUInt16BE=function(e,t,n){return e=+e,t=t>>>0,n||vt(this,e,t,2,65535,0),this[t]=e>>>8,this[t+1]=e&255,t+2};I.prototype.writeUint32LE=I.prototype.writeUInt32LE=function(e,t,n){return e=+e,t=t>>>0,n||vt(this,e,t,4,4294967295,0),this[t+3]=e>>>24,this[t+2]=e>>>16,this[t+1]=e>>>8,this[t]=e&255,t+4};I.prototype.writeUint32BE=I.prototype.writeUInt32BE=function(e,t,n){return e=+e,t=t>>>0,n||vt(this,e,t,4,4294967295,0),this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=e&255,t+4};function mw(r,e,t,n,i){xw(e,n,i,r,t,7);let o=Number(e&BigInt(4294967295));r[t++]=o,o=o>>8,r[t++]=o,o=o>>8,r[t++]=o,o=o>>8,r[t++]=o;let s=Number(e>>BigInt(32)&BigInt(4294967295));return r[t++]=s,s=s>>8,r[t++]=s,s=s>>8,r[t++]=s,s=s>>8,r[t++]=s,t}function yw(r,e,t,n,i){xw(e,n,i,r,t,7);let o=Number(e&BigInt(4294967295));r[t+7]=o,o=o>>8,r[t+6]=o,o=o>>8,r[t+5]=o,o=o>>8,r[t+4]=o;let s=Number(e>>BigInt(32)&BigInt(4294967295));return r[t+3]=s,s=s>>8,r[t+2]=s,s=s>>8,r[t+1]=s,s=s>>8,r[t]=s,t+8}I.prototype.writeBigUInt64LE=ti(function(e,t=0){return mw(this,e,t,BigInt(0),BigInt("0xffffffffffffffff"))});I.prototype.writeBigUInt64BE=ti(function(e,t=0){return yw(this,e,t,BigInt(0),BigInt("0xffffffffffffffff"))});I.prototype.writeIntLE=function(e,t,n,i){if(e=+e,t=t>>>0,!i){let c=Math.pow(2,8*n-1);vt(this,e,t,n,c-1,-c)}let o=0,s=1,a=0;for(this[t]=e&255;++o<n&&(s*=256);)e<0&&a===0&&this[t+o-1]!==0&&(a=1),this[t+o]=(e/s>>0)-a&255;return t+n};I.prototype.writeIntBE=function(e,t,n,i){if(e=+e,t=t>>>0,!i){let c=Math.pow(2,8*n-1);vt(this,e,t,n,c-1,-c)}let o=n-1,s=1,a=0;for(this[t+o]=e&255;--o>=0&&(s*=256);)e<0&&a===0&&this[t+o+1]!==0&&(a=1),this[t+o]=(e/s>>0)-a&255;return t+n};I.prototype.writeInt8=function(e,t,n){return e=+e,t=t>>>0,n||vt(this,e,t,1,127,-128),e<0&&(e=255+e+1),this[t]=e&255,t+1};I.prototype.writeInt16LE=function(e,t,n){return e=+e,t=t>>>0,n||vt(this,e,t,2,32767,-32768),this[t]=e&255,this[t+1]=e>>>8,t+2};I.prototype.writeInt16BE=function(e,t,n){return e=+e,t=t>>>0,n||vt(this,e,t,2,32767,-32768),this[t]=e>>>8,this[t+1]=e&255,t+2};I.prototype.writeInt32LE=function(e,t,n){return e=+e,t=t>>>0,n||vt(this,e,t,4,2147483647,-2147483648),this[t]=e&255,this[t+1]=e>>>8,this[t+2]=e>>>16,this[t+3]=e>>>24,t+4};I.prototype.writeInt32BE=function(e,t,n){return e=+e,t=t>>>0,n||vt(this,e,t,4,2147483647,-2147483648),e<0&&(e=4294967295+e+1),this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=e&255,t+4};I.prototype.writeBigInt64LE=ti(function(e,t=0){return mw(this,e,t,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});I.prototype.writeBigInt64BE=ti(function(e,t=0){return yw(this,e,t,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});function gw(r,e,t,n,i,o){if(t+n>r.length)throw new RangeError("Index out of range");if(t<0)throw new RangeError("Index out of range")}function ww(r,e,t,n,i){return e=+e,t=t>>>0,i||gw(r,e,t,4,34028234663852886e22,-34028234663852886e22),Uo.write(r,e,t,n,23,4),t+4}I.prototype.writeFloatLE=function(e,t,n){return ww(this,e,t,!0,n)};I.prototype.writeFloatBE=function(e,t,n){return ww(this,e,t,!1,n)};function Ew(r,e,t,n,i){return e=+e,t=t>>>0,i||gw(r,e,t,8,17976931348623157e292,-17976931348623157e292),Uo.write(r,e,t,n,52,8),t+8}I.prototype.writeDoubleLE=function(e,t,n){return Ew(this,e,t,!0,n)};I.prototype.writeDoubleBE=function(e,t,n){return Ew(this,e,t,!1,n)};I.prototype.copy=function(e,t,n,i){if(!I.isBuffer(e))throw new TypeError("argument should be a Buffer");if(n||(n=0),!i&&i!==0&&(i=this.length),t>=e.length&&(t=e.length),t||(t=0),i>0&&i<n&&(i=n),i===n||e.length===0||this.length===0)return 0;if(t<0)throw new RangeError("targetStart out of bounds");if(n<0||n>=this.length)throw new RangeError("Index out of range");if(i<0)throw new RangeError("sourceEnd out of bounds");i>this.length&&(i=this.length),e.length-t<i-n&&(i=e.length-t+n);let o=i-n;return this===e&&typeof Uint8Array.prototype.copyWithin=="function"?this.copyWithin(t,n,i):Uint8Array.prototype.set.call(e,this.subarray(n,i),t),o};I.prototype.fill=function(e,t,n,i){if(typeof e=="string"){if(typeof t=="string"?(i=t,t=0,n=this.length):typeof n=="string"&&(i=n,n=this.length),i!==void 0&&typeof i!="string")throw new TypeError("encoding must be a string");if(typeof i=="string"&&!I.isEncoding(i))throw new TypeError("Unknown encoding: "+i);if(e.length===1){let s=e.charCodeAt(0);(i==="utf8"&&s<128||i==="latin1")&&(e=s)}}else typeof e=="number"?e=e&255:typeof e=="boolean"&&(e=Number(e));if(t<0||this.length<t||this.length<n)throw new RangeError("Out of range index");if(n<=t)return this;t=t>>>0,n=n===void 0?this.length:n>>>0,e||(e=0);let o;if(typeof e=="number")for(o=t;o<n;++o)this[o]=e;else{let s=I.isBuffer(e)?e:I.from(e,i),a=s.length;if(a===0)throw new TypeError('The value "'+e+'" is invalid for argument "value"');for(o=0;o<n-t;++o)this[o+t]=s[o%a]}return this};var Lo={};function Rh(r,e,t){Lo[r]=class extends t{constructor(){super(),Object.defineProperty(this,"message",{value:e.apply(this,arguments),writable:!0,configurable:!0}),this.name=`${this.name} [${r}]`,this.stack,delete this.name}get code(){return r}set code(i){Object.defineProperty(this,"code",{configurable:!0,enumerable:!0,value:i,writable:!0})}toString(){return`${this.name} [${r}]: ${this.message}`}}}Rh("ERR_BUFFER_OUT_OF_BOUNDS",function(r){return r?`${r} is outside of buffer bounds`:"Attempt to access memory outside buffer bounds"},RangeError);Rh("ERR_INVALID_ARG_TYPE",function(r,e){return`The "${r}" argument must be of type number. Received type ${typeof e}`},TypeError);Rh("ERR_OUT_OF_RANGE",function(r,e,t){let n=`The value of "${r}" is out of range.`,i=t;return Number.isInteger(t)&&Math.abs(t)>2**32?i=lw(String(t)):typeof t=="bigint"&&(i=String(t),(t>BigInt(2)**BigInt(32)||t<-(BigInt(2)**BigInt(32)))&&(i=lw(i)),i+="n"),n+=` It must be ${e}. Received ${i}`,n},RangeError);function lw(r){let e="",t=r.length,n=r[0]==="-"?1:0;for(;t>=n+4;t-=3)e=`_${r.slice(t-3,t)}${e}`;return`${r.slice(0,t)}${e}`}function rS(r,e,t){Do(e,"offset"),(r[e]===void 0||r[e+t]===void 0)&&ra(e,r.length-(t+1))}function xw(r,e,t,n,i,o){if(r>t||r<e){let s=typeof e=="bigint"?"n":"",a;throw o>3?e===0||e===BigInt(0)?a=`>= 0${s} and < 2${s} ** ${(o+1)*8}${s}`:a=`>= -(2${s} ** ${(o+1)*8-1}${s}) and < 2 ** ${(o+1)*8-1}${s}`:a=`>= ${e}${s} and <= ${t}${s}`,new Lo.ERR_OUT_OF_RANGE("value",a,r)}rS(n,i,o)}function Do(r,e){if(typeof r!="number")throw new Lo.ERR_INVALID_ARG_TYPE(e,"number",r)}function ra(r,e,t){throw Math.floor(r)!==r?(Do(r,t),new Lo.ERR_OUT_OF_RANGE(t||"offset","an integer",r)):e<0?new Lo.ERR_BUFFER_OUT_OF_BOUNDS:new Lo.ERR_OUT_OF_RANGE(t||"offset",`>= ${t?1:0} and <= ${e}`,r)}var nS=/[^+/0-9A-Za-z-_]/g;function iS(r){if(r=r.split("=")[0],r=r.trim().replace(nS,""),r.length<2)return"";for(;r.length%4!==0;)r=r+"=";return r}function Ih(r,e){e=e||1/0;let t,n=r.length,i=null,o=[];for(let s=0;s<n;++s){if(t=r.charCodeAt(s),t>55295&&t<57344){if(!i){if(t>56319){(e-=3)>-1&&o.push(239,191,189);continue}else if(s+1===n){(e-=3)>-1&&o.push(239,191,189);continue}i=t;continue}if(t<56320){(e-=3)>-1&&o.push(239,191,189),i=t;continue}t=(i-55296<<10|t-56320)+65536}else i&&(e-=3)>-1&&o.push(239,191,189);if(i=null,t<128){if((e-=1)<0)break;o.push(t)}else if(t<2048){if((e-=2)<0)break;o.push(t>>6|192,t&63|128)}else if(t<65536){if((e-=3)<0)break;o.push(t>>12|224,t>>6&63|128,t&63|128)}else if(t<1114112){if((e-=4)<0)break;o.push(t>>18|240,t>>12&63|128,t>>6&63|128,t&63|128)}else throw new Error("Invalid code point")}return o}function oS(r){let e=[];for(let t=0;t<r.length;++t)e.push(r.charCodeAt(t)&255);return e}function sS(r,e){let t,n,i,o=[];for(let s=0;s<r.length&&!((e-=2)<0);++s)t=r.charCodeAt(s),n=t>>8,i=t%256,o.push(i),o.push(n);return o}function bw(r){return Ah.toByteArray(iS(r))}function Pl(r,e,t,n){let i;for(i=0;i<n&&!(i+t>=e.length||i>=r.length);++i)e[i+t]=r[i];return i}function Br(r,e){return r instanceof e||r!=null&&r.constructor!=null&&r.constructor.name!=null&&r.constructor.name===e.name}function Th(r){return r!==r}var aS=function(){let r="0123456789abcdef",e=new Array(256);for(let t=0;t<16;++t){let n=t*16;for(let i=0;i<16;++i)e[n+i]=r[t]+r[i]}return e}();function ti(r){return typeof BigInt>"u"?cS:r}function cS(){throw new Error("BigInt not supported")}});var vw=le(Ch=>{"use strict";Ch.toString=function(r){switch(r){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_"+r};Ch.toType=function(r){switch(r.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 r.toUpperCase().startsWith("UNKNOWN_")?parseInt(r.slice(8)):0}});var Aw=le(Lh=>{"use strict";Lh.toString=function(r){switch(r){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_"+r};Lh.toRcode=function(r){switch(r.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 _w=le(Uh=>{"use strict";Uh.toString=function(r){switch(r){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_"+r};Uh.toOpcode=function(r){switch(r.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 Sw=le(Dh=>{"use strict";Dh.toString=function(r){switch(r){case 1:return"IN";case 2:return"CS";case 3:return"CH";case 4:return"HS";case 255:return"ANY"}return"UNKNOWN_"+r};Dh.toClass=function(r){switch(r.toUpperCase()){case"IN":return 1;case"CS":return 2;case"CH":return 3;case"HS":return 4;case"ANY":return 255}return 0}});var Iw=le(Oh=>{"use strict";Oh.toString=function(r){switch(r){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 r<0?null:`OPTION_${r}`};Oh.toCode=function(r){if(typeof r=="number")return r;if(!r)return-1;switch(r.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=r.match(/_(\d+)$/);return e?parseInt(e[1],10):-1}});var Rw=le((kw,Ph)=>{var Bw=function(r){"use strict";Object.defineProperty(r,"__esModule",{value:!0}),r.decode=d,r.encode=l,r.familyOf=u,r.name=void 0,r.sizeOf=c,r.v6=r.v4=void 0;let e=/^(\d{1,3}\.){3,3}\d{1,3}$/,t=4,n=/^(::)?(((\d{1,3}\.){3}(\d{1,3}){1})?([0-9a-f]){0,4}:{0,2}){1,8}(::)?$/i,i=16,o={name:"v4",size:t,isFormat:p=>e.test(p),encode(p,f,h){h=~~h,f=f||new Uint8Array(h+t);let m=p.length,y=0;for(let g=0;g<m;){let E=p.charCodeAt(g++);E===46?(f[h++]=y,y=0):y=y*10+(E-48)}return f[h]=y,f},decode(p,f){return f=~~f,`${p[f++]}.${p[f++]}.${p[f++]}.${p[f]}`}};r.v4=o;let s={name:"v6",size:i,isFormat:p=>p.length>0&&n.test(p),encode(p,f,h){h=~~h;let m=h+i,y=-1,g=0,E=0,x=!0,_=!1;f=f||new Uint8Array(h+i);for(let S=0;S<p.length;S++){let A=p.charCodeAt(S);A===58?(x?y!==-1?(h<m&&(f[h]=0),h<m-1&&(f[h+1]=0),h+=2):h<m&&(y=h):(_===!0?(h<m&&(f[h]=E),h++):(h<m&&(f[h]=g>>8),h<m-1&&(f[h+1]=g&255),h+=2),g=0,E=0),x=!0,_=!1):A===46?(h<m&&(f[h]=E),h++,E=0,g=0,x=!1,_=!0):(x=!1,A>=97?A-=87:A>=65?A-=55:(A-=48,E=E*10+A),g=(g<<4)+A)}if(x===!1)_===!0?(h<m&&(f[h]=E),h++):(h<m&&(f[h]=g>>8),h<m-1&&(f[h+1]=g&255),h+=2);else if(y===0)h<m&&(f[h]=0),h<m-1&&(f[h+1]=0),h+=2;else if(y!==-1){h+=2;for(let S=Math.min(h-1,m-1);S>=y+2;S--)f[S]=f[S-2];f[y]=0,f[y+1]=0,y=h}if(y!==h&&y!==-1)for(h>m-2&&(h=m-2);m>y;)f[--m]=h<m&&h>y?f[--h]:0;else for(;h<m;)f[h++]=0;return f},decode(p,f){f=~~f;let h="";for(let m=0;m<i;m+=2)m!==0&&(h+=":"),h+=(p[f+m]<<8|p[f+m+1]).toString(16);return h.replace(/(^|:)0(:0)*:0(:|$)/,"$1::$3").replace(/:{3,4}/,"::")}};r.v6=s;let a="ip";r.name=a;function c(p){if(o.isFormat(p))return o.size;if(s.isFormat(p))return s.size;throw Error(`Invalid ip address: ${p}`)}function u(p){return c(p)===o.size?1:2}function l(p,f,h){h=~~h;let m=c(p);return typeof f=="function"&&(f=f(h+m)),m===o.size?o.encode(p,f,h):s.encode(p,f,h)}function d(p,f,h){if(f=~~f,h=h||p.length-f,h===o.size)return o.decode(p,f,h);if(h===s.size)return s.decode(p,f,h);throw Error(`Invalid buffer size needs to be ${o.size} for v4 or ${s.size} for v6.`)}return"default"in r?r.default:r}({});typeof define=="function"&&define.amd?define([],function(){return Bw}):typeof Ph=="object"&&typeof kw=="object"&&(Ph.exports=Bw)});var Cw=le(q=>{"use strict";var Y=Nh().Buffer,En=vw(),lS=Aw(),uS=_w(),Vl=Sw(),Fh=Iw(),Di=Rw(),dS=0,Tw=32768,Vh=32768,fS=~Vh,Nw=32768,hS=~Nw,H=q.name={};H.encode=function(r,e,t,{mail:n=!1}={}){e||(e=Y.alloc(H.encodingLength(r))),t||(t=0);let i=t,o=r.replace(/^\.|\.$/gm,"");if(o.length){let s=[];if(n){let a="";o.split(".").forEach(c=>{c.endsWith("\\")?a+=(a.length?".":"")+c.slice(0,-1):s.length===0&&a.length?s.push(a+"."+c):s.push(c)})}else s=o.split(".");for(let a=0;a<s.length;a++){let c=e.write(s[a],t+1);e[t]=c,t+=c+1}}return e[t++]=0,H.encode.bytes=t-i,e};H.encode.bytes=0;H.decode=function(r,e,{mail:t=!1}={}){e||(e=0);let n=[],i=e,o=0,s=0,a=!1;for(;;){if(e>=r.length)throw new Error("Cannot decode name (buffer overflow)");let c=r[e++];if(s+=a?0:1,c===0)break;if(c&192)if((c&192)===192){if(e+1>r.length)throw new Error("Cannot decode name (buffer overflow)");let u=r.readUInt16BE(e-1)-49152;if(u>=i)throw new Error("Cannot decode name (bad pointer)");e=u,i=u,s+=a?0:1,a=!0}else throw new Error("Cannot decode name (bad label)");else{if(e+c>r.length)throw new Error("Cannot decode name (buffer overflow)");if(o+=c+1,o>254)throw new Error("Cannot decode name (name too long)");let u=r.toString("utf-8",e,e+c);t&&(u=u.replace(/\./g,"\\.")),n.push(u),e+=c,s+=a?0:c}}return H.decode.bytes=s,n.length===0?".":n.join(".")};H.decode.bytes=0;H.encodingLength=function(r){return r==="."||r===".."?1:Y.byteLength(r.replace(/^\.|\.$/gm,""))+2};var te={};te.encode=function(r,e,t){e||(e=Y.alloc(te.encodingLength(r))),t||(t=0);let n=e.write(r,t+1);return e[t]=n,te.encode.bytes=n+1,e};te.encode.bytes=0;te.decode=function(r,e){e||(e=0);let t=r[e],n=r.toString("utf-8",e+1,e+1+t);return te.decode.bytes=t+1,n};te.decode.bytes=0;te.encodingLength=function(r){return Y.byteLength(r)+1};var ur={};ur.encode=function(r,e,t){e||(e=ur.encodingLength(r)),t||(t=0);let n=(r.flags||0)&32767,i=r.type==="response"?Tw:dS;return e.writeUInt16BE(r.id||0,t),e.writeUInt16BE(n|i,t+2),e.writeUInt16BE(r.questions.length,t+4),e.writeUInt16BE(r.answers.length,t+6),e.writeUInt16BE(r.authorities.length,t+8),e.writeUInt16BE(r.additionals.length,t+10),e};ur.encode.bytes=12;ur.decode=function(r,e){if(e||(e=0),r.length<12)throw new Error("Header must be 12 bytes");let t=r.readUInt16BE(e+2);return{id:r.readUInt16BE(e),type:t&Tw?"response":"query",flags:t&32767,flag_qr:(t>>15&1)===1,opcode:uS.toString(t>>11&15),flag_aa:(t>>10&1)===1,flag_tc:(t>>9&1)===1,flag_rd:(t>>8&1)===1,flag_ra:(t>>7&1)===1,flag_z:(t>>6&1)===1,flag_ad:(t>>5&1)===1,flag_cd:(t>>4&1)===1,rcode:lS.toString(t&15),questions:new Array(r.readUInt16BE(e+4)),answers:new Array(r.readUInt16BE(e+6)),authorities:new Array(r.readUInt16BE(e+8)),additionals:new Array(r.readUInt16BE(e+10))}};ur.decode.bytes=12;ur.encodingLength=function(){return 12};var un=q.unknown={};un.encode=function(r,e,t){return e||(e=Y.alloc(un.encodingLength(r))),t||(t=0),e.writeUInt16BE(r.length,t),r.copy(e,t+2),un.encode.bytes=r.length+2,e};un.encode.bytes=0;un.decode=function(r,e){e||(e=0);let t=r.readUInt16BE(e),n=r.slice(e+2,e+2+t);return un.decode.bytes=t+2,n};un.decode.bytes=0;un.encodingLength=function(r){return r.length+2};var dn=q.ns={};dn.encode=function(r,e,t){return e||(e=Y.alloc(dn.encodingLength(r))),t||(t=0),H.encode(r,e,t+2),e.writeUInt16BE(H.encode.bytes,t),dn.encode.bytes=H.encode.bytes+2,e};dn.encode.bytes=0;dn.decode=function(r,e){e||(e=0);let t=r.readUInt16BE(e),n=H.decode(r,e+2);return dn.decode.bytes=t+2,n};dn.decode.bytes=0;dn.encodingLength=function(r){return H.encodingLength(r)+2};var fn=q.soa={};fn.encode=function(r,e,t){e||(e=Y.alloc(fn.encodingLength(r))),t||(t=0);let n=t;return t+=2,H.encode(r.mname,e,t),t+=H.encode.bytes,H.encode(r.rname,e,t,{mail:!0}),t+=H.encode.bytes,e.writeUInt32BE(r.serial||0,t),t+=4,e.writeUInt32BE(r.refresh||0,t),t+=4,e.writeUInt32BE(r.retry||0,t),t+=4,e.writeUInt32BE(r.expire||0,t),t+=4,e.writeUInt32BE(r.minimum||0,t),t+=4,e.writeUInt16BE(t-n-2,n),fn.encode.bytes=t-n,e};fn.encode.bytes=0;fn.decode=function(r,e){e||(e=0);let t=e,n={};return e+=2,n.mname=H.decode(r,e),e+=H.decode.bytes,n.rname=H.decode(r,e,{mail:!0}),e+=H.decode.bytes,n.serial=r.readUInt32BE(e),e+=4,n.refresh=r.readUInt32BE(e),e+=4,n.retry=r.readUInt32BE(e),e+=4,n.expire=r.readUInt32BE(e),e+=4,n.minimum=r.readUInt32BE(e),e+=4,fn.decode.bytes=e-t,n};fn.decode.bytes=0;fn.encodingLength=function(r){return 22+H.encodingLength(r.mname)+H.encodingLength(r.rname)};var hn=q.txt={};hn.encode=function(r,e,t){Array.isArray(r)||(r=[r]);for(let i=0;i<r.length;i++)if(typeof r[i]=="string"&&(r[i]=Y.from(r[i])),!Y.isBuffer(r[i]))throw new Error("Must be a Buffer");e||(e=Y.alloc(hn.encodingLength(r))),t||(t=0);let n=t;return t+=2,r.forEach(function(i){e[t++]=i.length,i.copy(e,t,0,i.length),t+=i.length}),e.writeUInt16BE(t-n-2,n),hn.encode.bytes=t-n,e};hn.encode.bytes=0;hn.decode=function(r,e){e||(e=0);let t=e,n=r.readUInt16BE(e);e+=2;let i=[];for(;n>0;){let o=r[e++];if(--n,n<o)throw new Error("Buffer overflow");i.push(r.slice(e,e+o)),e+=o,n-=o}return hn.decode.bytes=e-t,i};hn.decode.bytes=0;hn.encodingLength=function(r){Array.isArray(r)||(r=[r]);let e=2;return r.forEach(function(t){typeof t=="string"?e+=Y.byteLength(t)+1:e+=t.length+1}),e};var pn=q.null={};pn.encode=function(r,e,t){e||(e=Y.alloc(pn.encodingLength(r))),t||(t=0),typeof r=="string"&&(r=Y.from(r)),r||(r=Y.alloc(0));let n=t;t+=2;let i=r.length;return r.copy(e,t,0,i),t+=i,e.writeUInt16BE(t-n-2,n),pn.encode.bytes=t-n,e};pn.encode.bytes=0;pn.decode=function(r,e){e||(e=0);let t=e,n=r.readUInt16BE(e);e+=2;let i=r.slice(e,e+n);return e+=n,pn.decode.bytes=e-t,i};pn.decode.bytes=0;pn.encodingLength=function(r){return r?(Y.isBuffer(r)?r.length:Y.byteLength(r))+2:2};var mn=q.hinfo={};mn.encode=function(r,e,t){e||(e=Y.alloc(mn.encodingLength(r))),t||(t=0);let n=t;return t+=2,te.encode(r.cpu,e,t),t+=te.encode.bytes,te.encode(r.os,e,t),t+=te.encode.bytes,e.writeUInt16BE(t-n-2,n),mn.encode.bytes=t-n,e};mn.encode.bytes=0;mn.decode=function(r,e){e||(e=0);let t=e,n={};return e+=2,n.cpu=te.decode(r,e),e+=te.decode.bytes,n.os=te.decode(r,e),e+=te.decode.bytes,mn.decode.bytes=e-t,n};mn.decode.bytes=0;mn.encodingLength=function(r){return te.encodingLength(r.cpu)+te.encodingLength(r.os)+2};var cr=q.ptr={},pS=q.cname=cr,mS=q.dname=cr;cr.encode=function(r,e,t){return e||(e=Y.alloc(cr.encodingLength(r))),t||(t=0),H.encode(r,e,t+2),e.writeUInt16BE(H.encode.bytes,t),cr.encode.bytes=H.encode.bytes+2,e};cr.encode.bytes=0;cr.decode=function(r,e){e||(e=0);let t=H.decode(r,e+2);return cr.decode.bytes=H.decode.bytes+2,t};cr.decode.bytes=0;cr.encodingLength=function(r){return H.encodingLength(r)+2};var yn=q.srv={};yn.encode=function(r,e,t){e||(e=Y.alloc(yn.encodingLength(r))),t||(t=0),e.writeUInt16BE(r.priority||0,t+2),e.writeUInt16BE(r.weight||0,t+4),e.writeUInt16BE(r.port||0,t+6),H.encode(r.target,e,t+8);let n=H.encode.bytes+6;return e.writeUInt16BE(n,t),yn.encode.bytes=n+2,e};yn.encode.bytes=0;yn.decode=function(r,e){e||(e=0);let t=r.readUInt16BE(e),n={};return n.priority=r.readUInt16BE(e+2),n.weight=r.readUInt16BE(e+4),n.port=r.readUInt16BE(e+6),n.target=H.decode(r,e+8),yn.decode.bytes=t+2,n};yn.decode.bytes=0;yn.encodingLength=function(r){return 8+H.encodingLength(r.target)};var Lt=q.caa={};Lt.ISSUER_CRITICAL=128;Lt.encode=function(r,e,t){let n=Lt.encodingLength(r);return e||(e=Y.alloc(Lt.encodingLength(r))),t||(t=0),r.issuerCritical&&(r.flags=Lt.ISSUER_CRITICAL),e.writeUInt16BE(n-2,t),t+=2,e.writeUInt8(r.flags||0,t),t+=1,te.encode(r.tag,e,t),t+=te.encode.bytes,e.write(r.value,t),t+=Y.byteLength(r.value),Lt.encode.bytes=n,e};Lt.encode.bytes=0;Lt.decode=function(r,e){e||(e=0);let t=r.readUInt16BE(e);e+=2;let n=e,i={};return i.flags=r.readUInt8(e),e+=1,i.tag=te.decode(r,e),e+=te.decode.bytes,i.value=r.toString("utf-8",e,n+t),i.issuerCritical=!!(i.flags&Lt.ISSUER_CRITICAL),Lt.decode.bytes=t+2,i};Lt.decode.bytes=0;Lt.encodingLength=function(r){return te.encodingLength(r.tag)+te.encodingLength(r.value)+2};var ri=q.mx={};ri.encode=function(r,e,t){e||(e=Y.alloc(ri.encodingLength(r))),t||(t=0);let n=t;return t+=2,e.writeUInt16BE(r.preference||0,t),t+=2,H.encode(r.exchange,e,t),t+=H.encode.bytes,e.writeUInt16BE(t-n-2,n),ri.encode.bytes=t-n,e};ri.encode.bytes=0;ri.decode=function(r,e){e||(e=0);let t=e,n={};return e+=2,n.preference=r.readUInt16BE(e),e+=2,n.exchange=H.decode(r,e),e+=H.decode.bytes,ri.decode.bytes=e-t,n};ri.encodingLength=function(r){return 4+H.encodingLength(r.exchange)};var gn=q.a={};gn.encode=function(r,e,t){return e||(e=Y.alloc(gn.encodingLength(r))),t||(t=0),e.writeUInt16BE(4,t),t+=2,Di.v4.encode(r,e,t),gn.encode.bytes=6,e};gn.encode.bytes=0;gn.decode=function(r,e){e||(e=0),e+=2;let t=Di.v4.decode(r,e);return gn.decode.bytes=6,t};gn.decode.bytes=0;gn.encodingLength=function(){return 6};var wn=q.aaaa={};wn.encode=function(r,e,t){return e||(e=Y.alloc(wn.encodingLength(r))),t||(t=0),e.writeUInt16BE(16,t),t+=2,Di.v6.encode(r,e,t),wn.encode.bytes=18,e};wn.encode.bytes=0;wn.decode=function(r,e){e||(e=0),e+=2;let t=Di.v6.decode(r,e);return wn.decode.bytes=18,t};wn.decode.bytes=0;wn.encodingLength=function(){return 18};var At=q.option={};At.encode=function(r,e,t){e||(e=Y.alloc(At.encodingLength(r))),t||(t=0);let n=t,i=Fh.toCode(r.code);if(e.writeUInt16BE(i,t),t+=2,r.data)e.writeUInt16BE(r.data.length,t),t+=2,r.data.copy(e,t),t+=r.data.length;else switch(i){case 8:let o=r.sourcePrefixLength||0,s=r.family||Di.familyOf(r.ip),a=Di.encode(r.ip,Y.alloc),c=Math.ceil(o/8);e.writeUInt16BE(c+4,t),t+=2,e.writeUInt16BE(s,t),t+=2,e.writeUInt8(o,t++),e.writeUInt8(r.scopePrefixLength||0,t++),a.copy(e,t,0,c),t+=c;break;case 11:r.timeout?(e.writeUInt16BE(2,t),t+=2,e.writeUInt16BE(r.timeout,t),t+=2):(e.writeUInt16BE(0,t),t+=2);break;case 12:let u=r.length||0;e.writeUInt16BE(u,t),t+=2,e.fill(0,t,t+u),t+=u;break;case 14:let l=r.tags.length*2;e.writeUInt16BE(l,t),t+=2;for(let d of r.tags)e.writeUInt16BE(d,t),t+=2;break;default:throw new Error(`Unknown roption code: ${r.code}`)}return At.encode.bytes=t-n,e};At.encode.bytes=0;At.decode=function(r,e){e||(e=0);let t={};t.code=r.readUInt16BE(e),t.type=Fh.toString(t.code),e+=2;let n=r.readUInt16BE(e);switch(e+=2,t.data=r.slice(e,e+n),t.code){case 8:t.family=r.readUInt16BE(e),e+=2,t.sourcePrefixLength=r.readUInt8(e++),t.scopePrefixLength=r.readUInt8(e++);let i=Y.alloc(t.family===1?4:16);r.copy(i,0,e,e+n-4),t.ip=Di.decode(i);break;case 11:n>0&&(t.timeout=r.readUInt16BE(e),e+=2);break;case 14:t.tags=[];for(let o=0;o<n;o+=2)t.tags.push(r.readUInt16BE(e)),e+=2}return At.decode.bytes=n+4,t};At.decode.bytes=0;At.encodingLength=function(r){if(r.data)return r.data.length+4;switch(Fh.toCode(r.code)){case 8:let t=r.sourcePrefixLength||0;return Math.ceil(t/8)+8;case 11:return typeof r.timeout=="number"?6:4;case 12:return r.length+4;case 14:return 4+r.tags.length*2}throw new Error(`Unknown roption code: ${r.code}`)};var Dt=q.opt={};Dt.encode=function(r,e,t){e||(e=Y.alloc(Dt.encodingLength(r))),t||(t=0);let n=t,i=Po(r,At);return e.writeUInt16BE(i,t),t=na(r,At,e,t+2),Dt.encode.bytes=t-n,e};Dt.encode.bytes=0;Dt.decode=function(r,e){e||(e=0);let t=e,n=[],i=r.readUInt16BE(e);e+=2;let o=0;for(;i>0;)n[o++]=At.decode(r,e),e+=At.decode.bytes,i-=At.decode.bytes;return Dt.decode.bytes=e-t,n};Dt.decode.bytes=0;Dt.encodingLength=function(r){return 2+Po(r||[],At)};var ht=q.dnskey={};ht.PROTOCOL_DNSSEC=3;ht.ZONE_KEY=128;ht.SECURE_ENTRYPOINT=32768;ht.encode=function(r,e,t){e||(e=Y.alloc(ht.encodingLength(r))),t||(t=0);let n=t,i=r.key;if(!Y.isBuffer(i))throw new Error("Key must be a Buffer");return t+=2,e.writeUInt16BE(r.flags,t),t+=2,e.writeUInt8(ht.PROTOCOL_DNSSEC,t),t+=1,e.writeUInt8(r.algorithm,t),t+=1,i.copy(e,t,0,i.length),t+=i.length,ht.encode.bytes=t-n,e.writeUInt16BE(ht.encode.bytes-2,n),e};ht.encode.bytes=0;ht.decode=function(r,e){e||(e=0);let t=e;var n={},i=r.readUInt16BE(e);if(e+=2,n.flags=r.readUInt16BE(e),e+=2,r.readUInt8(e)!==ht.PROTOCOL_DNSSEC)throw new Error("Protocol must be 3");return e+=1,n.algorithm=r.readUInt8(e),e+=1,n.key=r.slice(e,t+i+2),e+=n.key.length,ht.decode.bytes=e-t,n};ht.decode.bytes=0;ht.encodingLength=function(r){return 6+Y.byteLength(r.key)};var kr=q.rrsig={};kr.encode=function(r,e,t){e||(e=Y.alloc(kr.encodingLength(r))),t||(t=0);let n=t,i=r.signature;if(!Y.isBuffer(i))throw new Error("Signature must be a Buffer");return t+=2,e.writeUInt16BE(En.toType(r.typeCovered),t),t+=2,e.writeUInt8(r.algorithm,t),t+=1,e.writeUInt8(r.labels,t),t+=1,e.writeUInt32BE(r.originalTTL,t),t+=4,e.writeUInt32BE(r.expiration,t),t+=4,e.writeUInt32BE(r.inception,t),t+=4,e.writeUInt16BE(r.keyTag,t),t+=2,H.encode(r.signersName,e,t),t+=H.encode.bytes,i.copy(e,t,0,i.length),t+=i.length,kr.encode.bytes=t-n,e.writeUInt16BE(kr.encode.bytes-2,n),e};kr.encode.bytes=0;kr.decode=function(r,e){e||(e=0);let t=e;var n={},i=r.readUInt16BE(e);return e+=2,n.typeCovered=En.toString(r.readUInt16BE(e)),e+=2,n.algorithm=r.readUInt8(e),e+=1,n.labels=r.readUInt8(e),e+=1,n.originalTTL=r.readUInt32BE(e),e+=4,n.expiration=r.readUInt32BE(e),e+=4,n.inception=r.readUInt32BE(e),e+=4,n.keyTag=r.readUInt16BE(e),e+=2,n.signersName=H.decode(r,e),e+=H.decode.bytes,n.signature=r.slice(e,t+i+2),e+=n.signature.length,kr.decode.bytes=e-t,n};kr.decode.bytes=0;kr.encodingLength=function(r){return 20+H.encodingLength(r.signersName)+Y.byteLength(r.signature)};var Rr=q.rp={};Rr.encode=function(r,e,t){e||(e=Y.alloc(Rr.encodingLength(r))),t||(t=0);let n=t;return t+=2,H.encode(r.mbox||".",e,t,{mail:!0}),t+=H.encode.bytes,H.encode(r.txt||".",e,t),t+=H.encode.bytes,Rr.encode.bytes=t-n,e.writeUInt16BE(Rr.encode.bytes-2,n),e};Rr.encode.bytes=0;Rr.decode=function(r,e){e||(e=0);let t=e,n={};return e+=2,n.mbox=H.decode(r,e,{mail:!0})||".",e+=H.decode.bytes,n.txt=H.decode(r,e)||".",e+=H.decode.bytes,Rr.decode.bytes=e-t,n};Rr.decode.bytes=0;Rr.encodingLength=function(r){return 2+H.encodingLength(r.mbox||".")+H.encodingLength(r.txt||".")};var ze={};ze.encode=function(r,e,t){e||(e=Y.alloc(ze.encodingLength(r))),t||(t=0);let n=t;for(var i=[],o=0;o<r.length;o++){var s=En.toType(r[o]);i[s>>8]===void 0&&(i[s>>8]=[]),i[s>>8][s>>3&31]|=1<<7-(s&7)}for(o=0;o<i.length;o++)if(i[o]!==void 0){var a=Y.from(i[o]);e.writeUInt8(o,t),t+=1,e.writeUInt8(a.length,t),t+=1,a.copy(e,t),t+=a.length}return ze.encode.bytes=t-n,e};ze.encode.bytes=0;ze.decode=function(r,e,t){e||(e=0);let n=e;for(var i=[];e-n<t;){var o=r.readUInt8(e);e+=1;var s=r.readUInt8(e);e+=1;for(var a=0;a<s;a++)for(var c=r.readUInt8(e+a),u=0;u<8;u++)if(c&1<<7-u){var l=En.toString(o<<8|a<<3|u);i.push(l)}e+=s}return ze.decode.bytes=e-n,i};ze.decode.bytes=0;ze.encodingLength=function(r){for(var e=[],t=0;t<r.length;t++){var n=En.toType(r[t]);e[n>>8]=Math.max(e[n>>8]||0,n&255)}var i=0;for(t=0;t<e.length;t++)e[t]!==void 0&&(i+=2+Math.ceil((e[t]+1)/8));return i};var Tr=q.nsec={};Tr.encode=function(r,e,t){e||(e=Y.alloc(Tr.encodingLength(r))),t||(t=0);let n=t;return t+=2,H.encode(r.nextDomain,e,t),t+=H.encode.bytes,ze.encode(r.rrtypes,e,t),t+=ze.encode.bytes,Tr.encode.bytes=t-n,e.writeUInt16BE(Tr.encode.bytes-2,n),e};Tr.encode.bytes=0;Tr.decode=function(r,e){e||(e=0);let t=e;var n={},i=r.readUInt16BE(e);return e+=2,n.nextDomain=H.decode(r,e),e+=H.decode.bytes,n.rrtypes=ze.decode(r,e,i-(e-t)),e+=ze.decode.bytes,Tr.decode.bytes=e-t,n};Tr.decode.bytes=0;Tr.encodingLength=function(r){return 2+H.encodingLength(r.nextDomain)+ze.encodingLength(r.rrtypes)};var Nr=q.nsec3={};Nr.encode=function(r,e,t){e||(e=Y.alloc(Nr.encodingLength(r))),t||(t=0);let n=t,i=r.salt;if(!Y.isBuffer(i))throw new Error("salt must be a Buffer");let o=r.nextDomain;if(!Y.isBuffer(o))throw new Error("nextDomain must be a Buffer");return t+=2,e.writeUInt8(r.algorithm,t),t+=1,e.writeUInt8(r.flags,t),t+=1,e.writeUInt16BE(r.iterations,t),t+=2,e.writeUInt8(i.length,t),t+=1,i.copy(e,t,0,i.length),t+=i.length,e.writeUInt8(o.length,t),t+=1,o.copy(e,t,0,o.length),t+=o.length,ze.encode(r.rrtypes,e,t),t+=ze.encode.bytes,Nr.encode.bytes=t-n,e.writeUInt16BE(Nr.encode.bytes-2,n),e};Nr.encode.bytes=0;Nr.decode=function(r,e){e||(e=0);let t=e;var n={},i=r.readUInt16BE(e);e+=2,n.algorithm=r.readUInt8(e),e+=1,n.flags=r.readUInt8(e),e+=1,n.iterations=r.readUInt16BE(e),e+=2;let o=r.readUInt8(e);e+=1,n.salt=r.slice(e,e+o),e+=o;let s=r.readUInt8(e);return e+=1,n.nextDomain=r.slice(e,e+s),e+=s,n.rrtypes=ze.decode(r,e,i-(e-t)),e+=ze.decode.bytes,Nr.decode.bytes=e-t,n};Nr.decode.bytes=0;Nr.encodingLength=function(r){return 8+r.salt.length+r.nextDomain.length+ze.encodingLength(r.rrtypes)};var Cr=q.ds={};Cr.encode=function(r,e,t){e||(e=Y.alloc(Cr.encodingLength(r))),t||(t=0);let n=t,i=r.digest;if(!Y.isBuffer(i))throw new Error("Digest must be a Buffer");return t+=2,e.writeUInt16BE(r.keyTag,t),t+=2,e.writeUInt8(r.algorithm,t),t+=1,e.writeUInt8(r.digestType,t),t+=1,i.copy(e,t,0,i.length),t+=i.length,Cr.encode.bytes=t-n,e.writeUInt16BE(Cr.encode.bytes-2,n),e};Cr.encode.bytes=0;Cr.decode=function(r,e){e||(e=0);let t=e;var n={},i=r.readUInt16BE(e);return e+=2,n.keyTag=r.readUInt16BE(e),e+=2,n.algorithm=r.readUInt8(e),e+=1,n.digestType=r.readUInt8(e),e+=1,n.digest=r.slice(e,t+i+2),e+=n.digest.length,Cr.decode.bytes=e-t,n};Cr.decode.bytes=0;Cr.encodingLength=function(r){return 6+Y.byteLength(r.digest)};var Ut=q.sshfp={};Ut.getFingerprintLengthForHashType=function(e){switch(e){case 1:return 20;case 2:return 32}};Ut.encode=function(e,t,n){t||(t=Y.alloc(Ut.encodingLength(e))),n||(n=0);let i=n;n+=2,t[n]=e.algorithm,n+=1,t[n]=e.hash,n+=1;let o=Y.from(e.fingerprint.toUpperCase(),"hex");if(o.length!==Ut.getFingerprintLengthForHashType(e.hash))throw new Error("Invalid fingerprint length");return o.copy(t,n),n+=o.byteLength,Ut.encode.bytes=n-i,t.writeUInt16BE(Ut.encode.bytes-2,i),t};Ut.encode.bytes=0;Ut.decode=function(e,t){t||(t=0);let n=t,i={};t+=2,i.algorithm=e[t],t+=1,i.hash=e[t],t+=1;let o=Ut.getFingerprintLengthForHashType(i.hash);return i.fingerprint=e.slice(t,t+o).toString("hex").toUpperCase(),t+=o,Ut.decode.bytes=t-n,i};Ut.decode.bytes=0;Ut.encodingLength=function(r){return 4+Y.from(r.fingerprint,"hex").byteLength};var Lr=q.naptr={};Lr.encode=function(r,e,t){e||(e=Y.alloc(Lr.encodingLength(r))),t||(t=0);let n=t;return t+=2,e.writeUInt16BE(r.order||0,t),t+=2,e.writeUInt16BE(r.preference||0,t),t+=2,te.encode(r.flags,e,t),t+=te.encode.bytes,te.encode(r.services,e,t),t+=te.encode.bytes,te.encode(r.regexp,e,t),t+=te.encode.bytes,H.encode(r.replacement,e,t),t+=H.encode.bytes,Lr.encode.bytes=t-n,e.writeUInt16BE(Lr.encode.bytes-2,n),e};Lr.encode.bytes=0;Lr.decode=function(r,e){e||(e=0);let t=e,n={};return e+=2,n.order=r.readUInt16BE(e),e+=2,n.preference=r.readUInt16BE(e),e+=2,n.flags=te.decode(r,e),e+=te.decode.bytes,n.services=te.decode(r,e),e+=te.decode.bytes,n.regexp=te.decode(r,e),e+=te.decode.bytes,n.replacement=H.decode(r,e),e+=H.decode.bytes,Lr.decode.bytes=e-t,n};Lr.decode.bytes=0;Lr.encodingLength=function(r){return te.encodingLength(r.flags)+te.encodingLength(r.services)+te.encodingLength(r.regexp)+H.encodingLength(r.replacement)+6};var Ur=q.tlsa={};Ur.encode=function(r,e,t){e||(e=Y.alloc(Ur.encodingLength(r))),t||(t=0);let n=t,i=r.certificate;if(!Y.isBuffer(i))throw new Error("Certificate must be a Buffer");return t+=2,e.writeUInt8(r.usage,t),t+=1,e.writeUInt8(r.selector,t),t+=1,e.writeUInt8(r.matchingType,t),t+=1,i.copy(e,t,0,i.length),t+=i.length,Ur.encode.bytes=t-n,e.writeUInt16BE(Ur.encode.bytes-2,n),e};Ur.encode.bytes=0;Ur.decode=function(r,e){e||(e=0);let t=e,n={},i=r.readUInt16BE(e);return e+=2,n.usage=r.readUInt8(e),e+=1,n.selector=r.readUInt8(e),e+=1,n.matchingType=r.readUInt8(e),e+=1,n.certificate=r.slice(e,t+i+2),e+=n.certificate.length,Ur.decode.bytes=e-t,n};Ur.decode.bytes=0;Ur.encodingLength=function(r){return 5+Y.byteLength(r.certificate)};var Mh=q.record=function(r){switch(r.toUpperCase()){case"A":return gn;case"PTR":return cr;case"CNAME":return pS;case"DNAME":return mS;case"TXT":return hn;case"NULL":return pn;case"AAAA":return wn;case"SRV":return yn;case"HINFO":return mn;case"CAA":return Lt;case"NS":return dn;case"SOA":return fn;case"MX":return ri;case"OPT":return Dt;case"DNSKEY":return ht;case"RRSIG":return kr;case"RP":return Rr;case"NSEC":return Tr;case"NSEC3":return Nr;case"SSHFP":return Ut;case"DS":return Cr;case"NAPTR":return Lr;case"TLSA":return Ur}return un},Xe=q.answer={};Xe.encode=function(r,e,t){e||(e=Y.alloc(Xe.encodingLength(r))),t||(t=0);let n=t;if(H.encode(r.name,e,t),t+=H.encode.bytes,e.writeUInt16BE(En.toType(r.type),t),r.type.toUpperCase()==="OPT"){if(r.name!==".")throw new Error("OPT name must be root.");e.writeUInt16BE(r.udpPayloadSize||4096,t+2),e.writeUInt8(r.extendedRcode||0,t+4),e.writeUInt8(r.ednsVersion||0,t+5),e.writeUInt16BE(r.flags||0,t+6),t+=8,Dt.encode(r.options||[],e,t),t+=Dt.encode.bytes}else{let i=Vl.toClass(r.class===void 0?"IN":r.class);r.flush&&(i|=Vh),e.writeUInt16BE(i,t+2),e.writeUInt32BE(r.ttl||0,t+4),t+=8;let o=Mh(r.type);o.encode(r.data,e,t),t+=o.encode.bytes}return Xe.encode.bytes=t-n,e};Xe.encode.bytes=0;Xe.decode=function(r,e){e||(e=0);let t={},n=e;if(t.name=H.decode(r,e),e+=H.decode.bytes,t.type=En.toString(r.readUInt16BE(e)),t.type==="OPT")t.udpPayloadSize=r.readUInt16BE(e+2),t.extendedRcode=r.readUInt8(e+4),t.ednsVersion=r.readUInt8(e+5),t.flags=r.readUInt16BE(e+6),t.flag_do=(t.flags>>15&1)===1,t.options=Dt.decode(r,e+8),e+=8+Dt.decode.bytes;else{let i=r.readUInt16BE(e+2);t.ttl=r.readUInt32BE(e+4),t.class=Vl.toString(i&fS),t.flush=!!(i&Vh);let o=Mh(t.type);t.data=o.decode(r,e+8),e+=8+o.decode.bytes}return Xe.decode.bytes=e-n,t};Xe.decode.bytes=0;Xe.encodingLength=function(r){let e=r.data!==null&&r.data!==void 0?r.data:r.options;return H.encodingLength(r.name)+8+Mh(r.type).encodingLength(e)};var lr=q.question={};lr.encode=function(r,e,t){e||(e=Y.alloc(lr.encodingLength(r))),t||(t=0);let n=t;return H.encode(r.name,e,t),t+=H.encode.bytes,e.writeUInt16BE(En.toType(r.type),t),t+=2,e.writeUInt16BE(Vl.toClass(r.class===void 0?"IN":r.class),t),t+=2,lr.encode.bytes=t-n,r};lr.encode.bytes=0;lr.decode=function(r,e){e||(e=0);let t=e,n={};return n.name=H.decode(r,e),e+=H.decode.bytes,n.type=En.toString(r.readUInt16BE(e)),e+=2,n.class=Vl.toString(r.readUInt16BE(e)),e+=2,!!(n.class&Nw)&&(n.class&=hS),lr.decode.bytes=e-t,n};lr.decode.bytes=0;lr.encodingLength=function(r){return H.encodingLength(r.name)+4};q.AUTHORITATIVE_ANSWER=1024;q.TRUNCATED_RESPONSE=512;q.RECURSION_DESIRED=256;q.RECURSION_AVAILABLE=128;q.AUTHENTIC_DATA=32;q.CHECKING_DISABLED=16;q.DNSSEC_OK=32768;q.encode=function(r,e,t){let n=!e;n&&(e=Y.alloc(q.encodingLength(r))),t||(t=0);let i=t;return r.questions||(r.questions=[]),r.answers||(r.answers=[]),r.authorities||(r.authorities=[]),r.additionals||(r.additionals=[]),ur.encode(r,e,t),t+=ur.encode.bytes,t=na(r.questions,lr,e,t),t=na(r.answers,Xe,e,t),t=na(r.authorities,Xe,e,t),t=na(r.additionals,Xe,e,t),q.encode.bytes=t-i,n&&q.encode.bytes!==e.length?e.slice(0,q.encode.bytes):e};q.encode.bytes=0;q.decode=function(r,e){e||(e=0);let t=e,n=ur.decode(r,e);return e+=ur.decode.bytes,e=Fl(n.questions,lr,r,e),e=Fl(n.answers,Xe,r,e),e=Fl(n.authorities,Xe,r,e),e=Fl(n.additionals,Xe,r,e),q.decode.bytes=e-t,n};q.decode.bytes=0;q.encodingLength=function(r){return ur.encodingLength(r)+Po(r.questions||[],lr)+Po(r.answers||[],Xe)+Po(r.authorities||[],Xe)+Po(r.additionals||[],Xe)};q.streamEncode=function(r){let e=q.encode(r),t=Y.alloc(2);t.writeUInt16BE(e.byteLength);let n=Y.concat([t,e]);return q.streamEncode.bytes=n.byteLength,n};q.streamEncode.bytes=0;q.streamDecode=function(r){let e=r.readUInt16BE(0);if(r.byteLength<e+2)return null;let t=q.decode(r.slice(2));return q.streamDecode.bytes=q.decode.bytes,t};q.streamDecode.bytes=0;function Po(r,e){let t=0;for(let n=0;n<r.length;n++)t+=e.encodingLength(r[n]);return t}function na(r,e,t,n){for(let i=0;i<r.length;i++)e.encode(r[i],t,n),n+=e.encode.bytes;return n}function Fl(r,e,t,n){for(let i=0;i<r.length;i++)r[i]=e.decode(t,n),n+=e.decode.bytes;return n}});var zw=le((ua,$l)=>{(function(r,e){"use strict";var t={version:"3.0.0",x86:{},x64:{},inputValidation:!0};function n(f){if(!Array.isArray(f)&&!ArrayBuffer.isView(f))return!1;for(var h=0;h<f.length;h++)if(!Number.isInteger(f[h])||f[h]<0||f[h]>255)return!1;return!0}function i(f,h){return(f&65535)*h+(((f>>>16)*h&65535)<<16)}function o(f,h){return f<<h|f>>>32-h}function s(f){return f^=f>>>16,f=i(f,2246822507),f^=f>>>13,f=i(f,3266489909),f^=f>>>16,f}function a(f,h){f=[f[0]>>>16,f[0]&65535,f[1]>>>16,f[1]&65535],h=[h[0]>>>16,h[0]&65535,h[1]>>>16,h[1]&65535];var m=[0,0,0,0];return m[3]+=f[3]+h[3],m[2]+=m[3]>>>16,m[3]&=65535,m[2]+=f[2]+h[2],m[1]+=m[2]>>>16,m[2]&=65535,m[1]+=f[1]+h[1],m[0]+=m[1]>>>16,m[1]&=65535,m[0]+=f[0]+h[0],m[0]&=65535,[m[0]<<16|m[1],m[2]<<16|m[3]]}function c(f,h){f=[f[0]>>>16,f[0]&65535,f[1]>>>16,f[1]&65535],h=[h[0]>>>16,h[0]&65535,h[1]>>>16,h[1]&65535];var m=[0,0,0,0];return m[3]+=f[3]*h[3],m[2]+=m[3]>>>16,m[3]&=65535,m[2]+=f[2]*h[3],m[1]+=m[2]>>>16,m[2]&=65535,m[2]+=f[3]*h[2],m[1]+=m[2]>>>16,m[2]&=65535,m[1]+=f[1]*h[3],m[0]+=m[1]>>>16,m[1]&=65535,m[1]+=f[2]*h[2],m[0]+=m[1]>>>16,m[1]&=65535,m[1]+=f[3]*h[1],m[0]+=m[1]>>>16,m[1]&=65535,m[0]+=f[0]*h[3]+f[1]*h[2]+f[2]*h[1]+f[3]*h[0],m[0]&=65535,[m[0]<<16|m[1],m[2]<<16|m[3]]}function u(f,h){return h%=64,h===32?[f[1],f[0]]:h<32?[f[0]<<h|f[1]>>>32-h,f[1]<<h|f[0]>>>32-h]:(h-=32,[f[1]<<h|f[0]>>>32-h,f[0]<<h|f[1]>>>32-h])}function l(f,h){return h%=64,h===0?f:h<32?[f[0]<<h|f[1]>>>32-h,f[1]<<h]:[f[1]<<h-32,0]}function d(f,h){return[f[0]^h[0],f[1]^h[1]]}function p(f){return f=d(f,[0,f[0]>>>1]),f=c(f,[4283543511,3981806797]),f=d(f,[0,f[0]>>>1]),f=c(f,[3301882366,444984403]),f=d(f,[0,f[0]>>>1]),f}t.x86.hash32=function(f,h){if(t.inputValidation&&!n(f))return e;h=h||0;for(var m=f.length%4,y=f.length-m,g=h,E=0,x=3432918353,_=461845907,S=0;S<y;S=S+4)E=f[S]|f[S+1]<<8|f[S+2]<<16|f[S+3]<<24,E=i(E,x),E=o(E,15),E=i(E,_),g^=E,g=o(g,13),g=i(g,5)+3864292196;switch(E=0,m){case 3:E^=f[S+2]<<16;case 2:E^=f[S+1]<<8;case 1:E^=f[S],E=i(E,x),E=o(E,15),E=i(E,_),g^=E}return g^=f.length,g=s(g),g>>>0},t.x86.hash128=function(f,h){if(t.inputValidation&&!n(f))return e;h=h||0;for(var m=f.length%16,y=f.length-m,g=h,E=h,x=h,_=h,S=0,A=0,v=0,b=0,T=597399067,C=2869860233,N=951274213,$=2716044179,D=0;D<y;D=D+16)S=f[D]|f[D+1]<<8|f[D+2]<<16|f[D+3]<<24,A=f[D+4]|f[D+5]<<8|f[D+6]<<16|f[D+7]<<24,v=f[D+8]|f[D+9]<<8|f[D+10]<<16|f[D+11]<<24,b=f[D+12]|f[D+13]<<8|f[D+14]<<16|f[D+15]<<24,S=i(S,T),S=o(S,15),S=i(S,C),g^=S,g=o(g,19),g+=E,g=i(g,5)+1444728091,A=i(A,C),A=o(A,16),A=i(A,N),E^=A,E=o(E,17),E+=x,E=i(E,5)+197830471,v=i(v,N),v=o(v,17),v=i(v,$),x^=v,x=o(x,15),x+=_,x=i(x,5)+2530024501,b=i(b,$),b=o(b,18),b=i(b,T),_^=b,_=o(_,13),_+=g,_=i(_,5)+850148119;switch(S=0,A=0,v=0,b=0,m){case 15:b^=f[D+14]<<16;case 14:b^=f[D+13]<<8;case 13:b^=f[D+12],b=i(b,$),b=o(b,18),b=i(b,T),_^=b;case 12:v^=f[D+11]<<24;case 11:v^=f[D+10]<<16;case 10:v^=f[D+9]<<8;case 9:v^=f[D+8],v=i(v,N),v=o(v,17),v=i(v,$),x^=v;case 8:A^=f[D+7]<<24;case 7:A^=f[D+6]<<16;case 6:A^=f[D+5]<<8;case 5:A^=f[D+4],A=i(A,C),A=o(A,16),A=i(A,N),E^=A;case 4:S^=f[D+3]<<24;case 3:S^=f[D+2]<<16;case 2:S^=f[D+1]<<8;case 1:S^=f[D],S=i(S,T),S=o(S,15),S=i(S,C),g^=S}return g^=f.length,E^=f.length,x^=f.length,_^=f.length,g+=E,g+=x,g+=_,E+=g,x+=g,_+=g,g=s(g),E=s(E),x=s(x),_=s(_),g+=E,g+=x,g+=_,E+=g,x+=g,_+=g,("00000000"+(g>>>0).toString(16)).slice(-8)+("00000000"+(E>>>0).toString(16)).slice(-8)+("00000000"+(x>>>0).toString(16)).slice(-8)+("00000000"+(_>>>0).toString(16)).slice(-8)},t.x64.hash128=function(f,h){if(t.inputValidation&&!n(f))return e;h=h||0;for(var m=f.length%16,y=f.length-m,g=[0,h],E=[0,h],x=[0,0],_=[0,0],S=[2277735313,289559509],A=[1291169091,658871167],v=0;v<y;v=v+16)x=[f[v+4]|f[v+5]<<8|f[v+6]<<16|f[v+7]<<24,f[v]|f[v+1]<<8|f[v+2]<<16|f[v+3]<<24],_=[f[v+12]|f[v+13]<<8|f[v+14]<<16|f[v+15]<<24,f[v+8]|f[v+9]<<8|f[v+10]<<16|f[v+11]<<24],x=c(x,S),x=u(x,31),x=c(x,A),g=d(g,x),g=u(g,27),g=a(g,E),g=a(c(g,[0,5]),[0,1390208809]),_=c(_,A),_=u(_,33),_=c(_,S),E=d(E,_),E=u(E,31),E=a(E,g),E=a(c(E,[0,5]),[0,944331445]);switch(x=[0,0],_=[0,0],m){case 15:_=d(_,l([0,f[v+14]],48));case 14:_=d(_,l([0,f[v+13]],40));case 13:_=d(_,l([0,f[v+12]],32));case 12:_=d(_,l([0,f[v+11]],24));case 11:_=d(_,l([0,f[v+10]],16));case 10:_=d(_,l([0,f[v+9]],8));case 9:_=d(_,[0,f[v+8]]),_=c(_,A),_=u(_,33),_=c(_,S),E=d(E,_);case 8:x=d(x,l([0,f[v+7]],56));case 7:x=d(x,l([0,f[v+6]],48));case 6:x=d(x,l([0,f[v+5]],40));case 5:x=d(x,l([0,f[v+4]],32));case 4:x=d(x,l([0,f[v+3]],24));case 3:x=d(x,l([0,f[v+2]],16));case 2:x=d(x,l([0,f[v+1]],8));case 1:x=d(x,[0,f[v]]),x=c(x,S),x=u(x,31),x=c(x,A),g=d(g,x)}return g=d(g,[0,f.length]),E=d(E,[0,f.length]),g=a(g,E),E=a(E,g),g=p(g),E=p(E),g=a(g,E),E=a(E,g),("00000000"+(g[0]>>>0).toString(16)).slice(-8)+("00000000"+(g[1]>>>0).toString(16)).slice(-8)+("00000000"+(E[0]>>>0).toString(16)).slice(-8)+("00000000"+(E[1]>>>0).toString(16)).slice(-8)},typeof ua<"u"?(typeof $l<"u"&&$l.exports&&(ua=$l.exports=t),ua.murmurHash3=t):typeof define=="function"&&define.amd?define([],function(){return t}):(t._murmurHash3=r.murmurHash3,t.noConflict=function(){return r.murmurHash3=t._murmurHash3,t._murmurHash3=e,t.noConflict=e,t},r.murmurHash3=t)})(ua)});var Gw=le((F9,Kw)=>{Kw.exports=zw()});var Kl=le((G9,Yw)=>{"use strict";Yw.exports=class{constructor(){this._bitArrays=[],this._data=[],this._length=0,this._changedLength=!1,this._changedData=!1}set(e,t){let n=this._internalPositionFor(e,!1);if(t===void 0)n!==-1&&(this._unsetInternalPos(n),this._unsetBit(e),this._changedLength=!0,this._changedData=!0);else{let i=!1;n===-1?(n=this._data.length,this._setBit(e),this._changedData=!0):i=!0,this._setInternalPos(n,e,t,i),this._changedLength=!0}}unset(e){this.set(e,void 0)}get(e){this._sortData();let t=this._internalPositionFor(e,!0);if(t!==-1)return this._data[t][1]}push(e){return this.set(this.length,e),this.length}get length(){if(this._sortData(),this._changedLength){let e=this._data[this._data.length-1];this._length=e?e[0]+1:0,this._changedLength=!1}return this._length}forEach(e){let t=0;for(;t<this.length;)e(this.get(t),t,this),t++}map(e){let t=0,n=new Array(this.length);for(;t<this.length;)n[t]=e(this.get(t),t,this),t++;return n}reduce(e,t){let n=0,i=t;for(;n<this.length;){let o=this.get(n);i=e(i,o,n),n++}return i}find(e){let t=0,n,i;for(;t<this.length&&!n;)i=this.get(t),n=e(i),t++;return n?i:void 0}_internalPositionFor(e,t){let n=this._bytePosFor(e,t);if(n>=this._bitArrays.length)return-1;let i=this._bitArrays[n],o=e-n*7;if(!((i&1<<o)>0))return-1;let a=this._bitArrays.slice(0,n).reduce(NS,0),c=~(4294967295<<o+1),u=qw(i&c);return a+u-1}_bytePosFor(e,t){let n=Math.floor(e/7),i=n+1;for(;!t&&this._bitArrays.length<i;)this._bitArrays.push(0);return n}_setBit(e){let t=this._bytePosFor(e,!1);this._bitArrays[t]|=1<<e-t*7}_unsetBit(e){let t=this._bytePosFor(e,!1);this._bitArrays[t]&=~(1<<e-t*7)}_setInternalPos(e,t,n,i){let o=this._data,s=[t,n];if(i)this._sortData(),o[e]=s;else{if(o.length)if(o[o.length-1][0]>=t)o.push(s);else if(o[0][0]<=t)o.unshift(s);else{let a=Math.round(o.length/2);this._data=o.slice(0,a).concat(s).concat(o.slice(a))}else this._data.push(s);this._changedData=!0,this._changedLength=!0}}_unsetInternalPos(e){this._data.splice(e,1)}_sortData(){this._changedData&&this._data.sort(CS),this._changedData=!1}bitField(){let e=[],t=8,n=0,i=0,o,s=this._bitArrays.slice();for(;s.length||n;){n===0&&(o=s.shift(),n=7);let c=Math.min(n,t),u=~(255<<c),l=o&u;i|=l<<8-t,o=o>>>c,n-=c,t-=c,(!t||!n&&!s.length)&&(e.push(i),i=0,t=8)}for(var a=e.length-1;a>0&&e[a]===0;a--)e.pop();return e}compactArray(){return this._sortData(),this._data.map(LS)}};function NS(r,e){return r+qw(e)}function qw(r){let e=r;return e=e-(e>>1&1431655765),e=(e&858993459)+(e>>2&858993459),(e+(e>>4)&252645135)*16843009>>24}function CS(r,e){return r[0]-e[0]}function LS(r){return r[1]}});var c2=le((IV,a2)=>{var Wh=class{constructor(e,t=12,n=8*1024,i=32*1024,o=64,s){this.bits=t,this.min=n,this.max=i,this.asModule=e,this.rabin=new e.Rabin(t,n,i,o,s),this.polynomial=s}fingerprint(e){let{__retain:t,__release:n,__allocArray:i,__getInt32Array:o,Int32Array_ID:s,Uint8Array_ID:a}=this.asModule,c=new Int32Array(Math.ceil(e.length/this.min)),u=t(i(s,c)),l=t(i(a,e)),d=this.rabin.fingerprint(l,u),p=o(d);n(l),n(u);let f=p.indexOf(0);return f>=0?p.subarray(0,f):p}};a2.exports=Wh});var p2=le(ha=>{"use strict";var qS=typeof BigUint64Array<"u",da=Symbol(),fa=1024;function l2(r,e){let t=new Uint32Array(r),n=new Uint16Array(r);var i=t[e+-4>>>2]>>>1,o=e>>>1;if(i<=fa)return String.fromCharCode.apply(String,n.subarray(o,o+i));let s=[];do{let a=n[o+fa-1],c=a>=55296&&a<56320?fa-1:fa;s.push(String.fromCharCode.apply(String,n.subarray(o,o+=c))),i-=c}while(i>fa);return s.join("")+String.fromCharCode.apply(String,n.subarray(o,o+i))}function jh(r){let e={};function t(i,o){return i?l2(i.buffer,o):"<yet unknown>"}let n=r.env=r.env||{};return n.abort=n.abort||function(o,s,a,c){let u=e.memory||n.memory;throw Error("abort: "+t(u,o)+" at "+t(u,s)+":"+a+":"+c)},n.trace=n.trace||function(o,s){let a=e.memory||n.memory;console.log("trace: "+t(a,o)+(s?" ":"")+Array.prototype.slice.call(arguments,2,2+s).join(", "))},r.Math=r.Math||Math,r.Date=r.Date||Date,e}function Xh(r,e){let t=e.exports,n=t.memory,i=t.table,o=t.__alloc,s=t.__retain,a=t.__rtti_base||-1;function c(A){let v=new Uint32Array(n.buffer),b=v[a>>>2];if((A>>>=0)>=b)throw Error("invalid id: "+A);return v[(a+4>>>2)+A*2]}function u(A){let v=new Uint32Array(n.buffer),b=v[a>>>2];if((A>>>=0)>=b)throw Error("invalid id: "+A);return v[(a+4>>>2)+A*2+1]}function l(A){return 31-Math.clz32(A>>>5&31)}function d(A){return 31-Math.clz32(A>>>14&31)}function p(A){let v=A.length,b=o(v<<1,1),T=new Uint16Array(n.buffer);for(var C=0,N=b>>>1;C<v;++C)T[N+C]=A.charCodeAt(C);return b}r.__allocString=p;function f(A){let v=n.buffer;if(new Uint32Array(v)[A+-8>>>2]!==1)throw Error("not a string: "+A);return l2(v,A)}r.__getString=f;function h(A,v,b){let T=n.buffer;if(b)switch(A){case 2:return new Float32Array(T);case 3:return new Float64Array(T)}else switch(A){case 0:return new(v?Int8Array:Uint8Array)(T);case 1:return new(v?Int16Array:Uint16Array)(T);case 2:return new(v?Int32Array:Uint32Array)(T);case 3:return new(v?BigInt64Array:BigUint64Array)(T)}throw Error("unsupported align: "+A)}function m(A,v){let b=c(A);if(!(b&3))throw Error("not an array: "+A+" @ "+b);let T=l(b),C=v.length,N=o(C<<T,0),$=o(b&2?16:12,A),D=new Uint32Array(n.buffer);D[$+0>>>2]=s(N),D[$+4>>>2]=N,D[$+8>>>2]=C<<T,b&2&&(D[$+12>>>2]=C);let ne=h(T,b&1024,b&2048);if(b&8192)for(let B=0;B<C;++B)ne[(N>>>T)+B]=s(v[B]);else ne.set(v,N>>>T);return $}r.__allocArray=m;function y(A){let v=new Uint32Array(n.buffer),b=v[A+-8>>>2],T=c(b);if(!(T&1))throw Error("not an array: "+b);let C=l(T);var N=v[A+4>>>2];let $=T&2?v[A+12>>>2]:v[N+-4>>>2]>>>C;return h(C,T&1024,T&2048).subarray(N>>>=C,N+$)}r.__getArrayView=y;function g(A){let v=y(A),b=v.length,T=new Array(b);for(let C=0;C<b;C++)T[C]=v[C];return T}r.__getArray=g;function E(A){let v=n.buffer,b=new Uint32Array(v)[A+-4>>>2];return v.slice(A,A+b)}r.__getArrayBuffer=E;function x(A,v,b){return new A(_(A,v,b))}function _(A,v,b){let T=n.buffer,C=new Uint32Array(T),N=C[b+4>>>2];return new A(T,N,C[N+-4>>>2]>>>v)}r.__getInt8Array=x.bind(null,Int8Array,0),r.__getInt8ArrayView=_.bind(null,Int8Array,0),r.__getUint8Array=x.bind(null,Uint8Array,0),r.__getUint8ArrayView=_.bind(null,Uint8Array,0),r.__getUint8ClampedArray=x.bind(null,Uint8ClampedArray,0),r.__getUint8ClampedArrayView=_.bind(null,Uint8ClampedArray,0),r.__getInt16Array=x.bind(null,Int16Array,1),r.__getInt16ArrayView=_.bind(null,Int16Array,1),r.__getUint16Array=x.bind(null,Uint16Array,1),r.__getUint16ArrayView=_.bind(null,Uint16Array,1),r.__getInt32Array=x.bind(null,Int32Array,2),r.__getInt32ArrayView=_.bind(null,Int32Array,2),r.__getUint32Array=x.bind(null,Uint32Array,2),r.__getUint32ArrayView=_.bind(null,Uint32Array,2),qS&&(r.__getInt64Array=x.bind(null,BigInt64Array,3),r.__getInt64ArrayView=_.bind(null,BigInt64Array,3),r.__getUint64Array=x.bind(null,BigUint64Array,3),r.__getUint64ArrayView=_.bind(null,BigUint64Array,3)),r.__getFloat32Array=x.bind(null,Float32Array,2),r.__getFloat32ArrayView=_.bind(null,Float32Array,2),r.__getFloat64Array=x.bind(null,Float64Array,3),r.__getFloat64ArrayView=_.bind(null,Float64Array,3);function S(A,v){let b=new Uint32Array(n.buffer);var T=b[A+-8>>>2];if(T<=b[a>>>2])do if(T==v)return!0;while(T=u(T));return!1}return r.__instanceof=S,r.memory=r.memory||n,r.table=r.table||i,h2(t,r)}function u2(r){return typeof Response<"u"&&r instanceof Response}async function d2(r,e){return u2(r=await r)?f2(r,e):Xh(jh(e||(e={})),await WebAssembly.instantiate(r instanceof WebAssembly.Module?r:await WebAssembly.compile(r),e))}ha.instantiate=d2;function YS(r,e){return Xh(jh(e||(e={})),new WebAssembly.Instance(r instanceof WebAssembly.Module?r:new WebAssembly.Module(r),e))}ha.instantiateSync=YS;async function f2(r,e){return WebAssembly.instantiateStreaming?Xh(jh(e||(e={})),(await WebAssembly.instantiateStreaming(r,e)).instance):d2(u2(r=await r)?r.arrayBuffer():r,e)}ha.instantiateStreaming=f2;function h2(r,e){var t=e?Object.create(e):{},n=r.__argumentsLength?function(i){r.__argumentsLength.value=i}:r.__setArgumentsLength||r.__setargc||function(){};for(let i in r){if(!Object.prototype.hasOwnProperty.call(r,i))continue;let o=r[i],s=i.split("."),a=t;for(;s.length>1;){let l=s.shift();Object.prototype.hasOwnProperty.call(a,l)||(a[l]={}),a=a[l]}let c=s[0],u=c.indexOf("#");if(u>=0){let l=c.substring(0,u),d=a[l];if(typeof d>"u"||!d.prototype){let p=function(...f){return p.wrap(p.prototype.constructor(0,...f))};p.prototype={valueOf:function(){return this[da]}},p.wrap=function(f){return Object.create(p.prototype,{[da]:{value:f,writable:!1}})},d&&Object.getOwnPropertyNames(d).forEach(f=>Object.defineProperty(p,f,Object.getOwnPropertyDescriptor(d,f))),a[l]=p}if(c=c.substring(u+1),a=a[l].prototype,/^(get|set):/.test(c)){if(!Object.prototype.hasOwnProperty.call(a,c=c.substring(4))){let p=r[i.replace("set:","get:")],f=r[i.replace("get:","set:")];Object.defineProperty(a,c,{get:function(){return p(this[da])},set:function(h){f(this[da],h)},enumerable:!0})}}else c==="constructor"?(a[c]=(...p)=>(n(p.length),o(...p))).original=o:(a[c]=function(...p){return n(p.length),o(this[da],...p)}).original=o}else/^(get|set):/.test(c)?Object.prototype.hasOwnProperty.call(a,c=c.substring(4))||Object.defineProperty(a,c,{get:r[i.replace("set:","get:")],set:r[i.replace("get:","set:")],enumerable:!0}):typeof o=="function"&&o!==n?(a[c]=(...l)=>(n(l.length),o(...l))).original=o:a[c]=o}return t}ha.demangle=h2});var y2=le((kV,m2)=>{var{instantiate:WS}=p2();Zh.supported=typeof WebAssembly<"u";function Zh(r={}){if(!Zh.supported)return null;var e=new Uint8Array([0,97,115,109,1,0,0,0,1,78,14,96,2,127,126,0,96,1,127,1,126,96,2,127,127,0,96,1,127,1,127,96,1,127,0,96,2,127,127,1,127,96,3,127,127,127,1,127,96,0,0,96,3,127,127,127,0,96,0,1,127,96,4,127,127,127,127,0,96,5,127,127,127,127,127,1,127,96,1,126,1,127,96,2,126,126,1,126,2,13,1,3,101,110,118,5,97,98,111,114,116,0,10,3,54,53,2,2,8,9,3,5,2,8,6,5,3,4,2,6,9,12,13,2,5,11,3,2,3,2,3,2,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,6,7,7,4,4,5,3,1,0,1,6,47,9,127,1,65,0,11,127,1,65,0,11,127,0,65,3,11,127,0,65,4,11,127,1,65,0,11,127,1,65,0,11,127,1,65,0,11,127,0,65,240,2,11,127,0,65,6,11,7,240,5,41,6,109,101,109,111,114,121,2,0,7,95,95,97,108,108,111,99,0,10,8,95,95,114,101,116,97,105,110,0,11,9,95,95,114,101,108,101,97,115,101,0,12,9,95,95,99,111,108,108,101,99,116,0,51,11,95,95,114,116,116,105,95,98,97,115,101,3,7,13,73,110,116,51,50,65,114,114,97,121,95,73,68,3,2,13,85,105,110,116,56,65,114,114,97,121,95,73,68,3,3,6,100,101,103,114,101,101,0,16,3,109,111,100,0,17,5,82,97,98,105,110,3,8,16,82,97,98,105,110,35,103,101,116,58,119,105,110,100,111,119,0,21,16,82,97,98,105,110,35,115,101,116,58,119,105,110,100,111,119,0,22,21,82,97,98,105,110,35,103,101,116,58,119,105,110,100,111,119,95,115,105,122,101,0,23,21,82,97,98,105,110,35,115,101,116,58,119,105,110,100,111,119,95,115,105,122,101,0,24,14,82,97,98,105,110,35,103,101,116,58,119,112,111,115,0,25,14,82,97,98,105,110,35,115,101,116,58,119,112,111,115,0,26,15,82,97,98,105,110,35,103,101,116,58,99,111,117,110,116,0,27,15,82,97,98,105,110,35,115,101,116,58,99,111,117,110,116,0,28,13,82,97,98,105,110,35,103,101,116,58,112,111,115,0,29,13,82,97,98,105,110,35,115,101,116,58,112,111,115,0,30,15,82,97,98,105,110,35,103,101,116,58,115,116,97,114,116,0,31,15,82,97,98,105,110,35,115,101,116,58,115,116,97,114,116,0,32,16,82,97,98,105,110,35,103,101,116,58,100,105,103,101,115,116,0,33,16,82,97,98,105,110,35,115,101,116,58,100,105,103,101,115,116,0,34,21,82,97,98,105,110,35,103,101,116,58,99,104,117,110,107,95,115,116,97,114,116,0,35,21,82,97,98,105,110,35,115,101,116,58,99,104,117,110,107,95,115,116,97,114,116,0,36,22,82,97,98,105,110,35,103,101,116,58,99,104,117,110,107,95,108,101,110,103,116,104,0,37,22,82,97,98,105,110,35,115,101,116,58,99,104,117,110,107,95,108,101,110,103,116,104,0,38,31,82,97,98,105,110,35,103,101,116,58,99,104,117,110,107,95,99,117,116,95,102,105,110,103,101,114,112,114,105,110,116,0,39,31,82,97,98,105,110,35,115,101,116,58,99,104,117,110,107,95,99,117,116,95,102,105,110,103,101,114,112,114,105,110,116,0,40,20,82,97,98,105,110,35,103,101,116,58,112,111,108,121,110,111,109,105,97,108,0,41,20,82,97,98,105,110,35,115,101,116,58,112,111,108,121,110,111,109,105,97,108,0,42,17,82,97,98,105,110,35,103,101,116,58,109,105,110,115,105,122,101,0,43,17,82,97,98,105,110,35,115,101,116,58,109,105,110,115,105,122,101,0,44,17,82,97,98,105,110,35,103,101,116,58,109,97,120,115,105,122,101,0,45,17,82,97,98,105,110,35,115,101,116,58,109,97,120,115,105,122,101,0,46,14,82,97,98,105,110,35,103,101,116,58,109,97,115,107,0,47,14,82,97,98,105,110,35,115,101,116,58,109,97,115,107,0,48,17,82,97,98,105,110,35,99,111,110,115,116,114,117,99,116,111,114,0,20,17,82,97,98,105,110,35,102,105,110,103,101,114,112,114,105,110,116,0,49,8,1,50,10,165,31,53,199,1,1,4,127,32,1,40,2,0,65,124,113,34,2,65,128,2,73,4,127,32,2,65,4,118,33,4,65,0,5,32,2,65,31,32,2,103,107,34,3,65,4,107,118,65,16,115,33,4,32,3,65,7,107,11,33,3,32,1,40,2,20,33,2,32,1,40,2,16,34,5,4,64,32,5,32,2,54,2,20,11,32,2,4,64,32,2,32,5,54,2,16,11,32,1,32,0,32,4,32,3,65,4,116,106,65,2,116,106,40,2,96,70,4,64,32,0,32,4,32,3,65,4,116,106,65,2,116,106,32,2,54,2,96,32,2,69,4,64,32,0,32,3,65,2,116,106,32,0,32,3,65,2,116,106,40,2,4,65,1,32,4,116,65,127,115,113,34,1,54,2,4,32,1,69,4,64,32,0,32,0,40,2,0,65,1,32,3,116,65,127,115,113,54,2,0,11,11,11,11,226,2,1,6,127,32,1,40,2,0,33,3,32,1,65,16,106,32,1,40,2,0,65,124,113,106,34,4,40,2,0,34,5,65,1,113,4,64,32,3,65,124,113,65,16,106,32,5,65,124,113,106,34,2,65,240,255,255,255,3,73,4,64,32,0,32,4,16,1,32,1,32,2,32,3,65,3,113,114,34,3,54,2,0,32,1,65,16,106,32,1,40,2,0,65,124,113,106,34,4,40,2,0,33,5,11,11,32,3,65,2,113,4,64,32,1,65,4,107,40,2,0,34,2,40,2,0,34,6,65,124,113,65,16,106,32,3,65,124,113,106,34,7,65,240,255,255,255,3,73,4,64,32,0,32,2,16,1,32,2,32,7,32,6,65,3,113,114,34,3,54,2,0,32,2,33,1,11,11,32,4,32,5,65,2,114,54,2,0,32,4,65,4,107,32,1,54,2,0,32,0,32,3,65,124,113,34,2,65,128,2,73,4,127,32,2,65,4,118,33,4,65,0,5,32,2,65,31,32,2,103,107,34,2,65,4,107,118,65,16,115,33,4,32,2,65,7,107,11,34,3,65,4,116,32,4,106,65,2,116,106,40,2,96,33,2,32,1,65,0,54,2,16,32,1,32,2,54,2,20,32,2,4,64,32,2,32,1,54,2,16,11,32,0,32,4,32,3,65,4,116,106,65,2,116,106,32,1,54,2,96,32,0,32,0,40,2,0,65,1,32,3,116,114,54,2,0,32,0,32,3,65,2,116,106,32,0,32,3,65,2,116,106,40,2,4,65,1,32,4,116,114,54,2,4,11,119,1,1,127,32,2,2,127,32,0,40,2,160,12,34,2,4,64,32,2,32,1,65,16,107,70,4,64,32,2,40,2,0,33,3,32,1,65,16,107,33,1,11,11,32,1,11,107,34,2,65,48,73,4,64,15,11,32,1,32,3,65,2,113,32,2,65,32,107,65,1,114,114,54,2,0,32,1,65,0,54,2,16,32,1,65,0,54,2,20,32,1,32,2,106,65,16,107,34,2,65,2,54,2,0,32,0,32,2,54,2,160,12,32,0,32,1,16,2,11,155,1,1,3,127,35,0,34,0,69,4,64,65,1,63,0,34,0,74,4,127,65,1,32,0,107,64,0,65,0,72,5,65,0,11,4,64,0,11,65,176,3,34,0,65,0,54,2,0,65,208,15,65,0,54,2,0,3,64,32,1,65,23,73,4,64,32,1,65,2,116,65,176,3,106,65,0,54,2,4,65,0,33,2,3,64,32,2,65,16,73,4,64,32,1,65,4,116,32,2,106,65,2,116,65,176,3,106,65,0,54,2,96,32,2,65,1,106,33,2,12,1,11,11,32,1,65,1,106,33,1,12,1,11,11,65,176,3,65,224,15,63,0,65,16,116,16,3,65,176,3,36,0,11,32,0,11,45,0,32,0,65,240,255,255,255,3,79,4,64,65,32,65,224,0,65,201,3,65,29,16,0,0,11,32,0,65,15,106,65,112,113,34,0,65,16,32,0,65,16,75,27,11,169,1,1,1,127,32,0,32,1,65,128,2,73,4,127,32,1,65,4,118,33,1,65,0,5,32,1,65,248,255,255,255,1,73,4,64,32,1,65,1,65,27,32,1,103,107,116,106,65,1,107,33,1,11,32,1,65,31,32,1,103,107,34,2,65,4,107,118,65,16,115,33,1,32,2,65,7,107,11,34,2,65,2,116,106,40,2,4,65,127,32,1,116,113,34,1,4,127,32,0,32,1,104,32,2,65,4,116,106,65,2,116,106,40,2,96,5,32,0,40,2,0,65,127,32,2,65,1,106,116,113,34,1,4,127,32,0,32,0,32,1,104,34,0,65,2,116,106,40,2,4,104,32,0,65,4,116,106,65,2,116,106,40,2,96,5,65,0,11,11,11,111,1,1,127,63,0,34,2,32,1,65,248,255,255,255,1,73,4,127,32,1,65,1,65,27,32,1,103,107,116,65,1,107,106,5,32,1,11,65,16,32,0,40,2,160,12,32,2,65,16,116,65,16,107,71,116,106,65,255,255,3,106,65,128,128,124,113,65,16,118,34,1,32,2,32,1,74,27,64,0,65,0,72,4,64,32,1,64,0,65,0,72,4,64,0,11,11,32,0,32,2,65,16,116,63,0,65,16,116,16,3,11,113,1,2,127,32,1,40,2,0,34,3,65,124,113,32,2,107,34,4,65,32,79,4,64,32,1,32,2,32,3,65,2,113,114,54,2,0,32,2,32,1,65,16,106,106,34,1,32,4,65,16,107,65,1,114,54,2,0,32,0,32,1,16,2,5,32,1,32,3,65,126,113,54,2,0,32,1,65,16,106,32,1,40,2,0,65,124,113,106,32,1,65,16,106,32,1,40,2,0,65,124,113,106,40,2,0,65,125,113,54,2,0,11,11,91,1,2,127,32,0,32,1,16,5,34,4,16,6,34,3,69,4,64,65,1,36,1,65,0,36,1,32,0,32,4,16,6,34,3,69,4,64,32,0,32,4,16,7,32,0,32,4,16,6,33,3,11,11,32,3,65,0,54,2,4,32,3,32,2,54,2,8,32,3,32,1,54,2,12,32,0,32,3,16,1,32,0,32,3,32,4,16,8,32,3,11,13,0,16,4,32,0,32,1,16,9,65,16,106,11,33,1,1,127,32,0,65,172,3,75,4,64,32,0,65,16,107,34,1,32,1,40,2,4,65,1,106,54,2,4,11,32,0,11,18,0,32,0,65,172,3,75,4,64,32,0,65,16,107,16,52,11,11,140,3,1,1,127,2,64,32,1,69,13,0,32,0,65,0,58,0,0,32,0,32,1,106,65,1,107,65,0,58,0,0,32,1,65,2,77,13,0,32,0,65,1,106,65,0,58,0,0,32,0,65,2,106,65,0,58,0,0,32,0,32,1,106,34,2,65,2,107,65,0,58,0,0,32,2,65,3,107,65,0,58,0,0,32,1,65,6,77,13,0,32,0,65,3,106,65,0,58,0,0,32,0,32,1,106,65,4,107,65,0,58,0,0,32,1,65,8,77,13,0,32,1,65,0,32,0,107,65,3,113,34,1,107,33,2,32,0,32,1,106,34,0,65,0,54,2,0,32,0,32,2,65,124,113,34,1,106,65,4,107,65,0,54,2,0,32,1,65,8,77,13,0,32,0,65,4,106,65,0,54,2,0,32,0,65,8,106,65,0,54,2,0,32,0,32,1,106,34,2,65,12,107,65,0,54,2,0,32,2,65,8,107,65,0,54,2,0,32,1,65,24,77,13,0,32,0,65,12,106,65,0,54,2,0,32,0,65,16,106,65,0,54,2,0,32,0,65,20,106,65,0,54,2,0,32,0,65,24,106,65,0,54,2,0,32,0,32,1,106,34,2,65,28,107,65,0,54,2,0,32,2,65,24,107,65,0,54,2,0,32,2,65,20,107,65,0,54,2,0,32,2,65,16,107,65,0,54,2,0,32,0,32,0,65,4,113,65,24,106,34,2,106,33,0,32,1,32,2,107,33,1,3,64,32,1,65,32,79,4,64,32,0,66,0,55,3,0,32,0,65,8,106,66,0,55,3,0,32,0,65,16,106,66,0,55,3,0,32,0,65,24,106,66,0,55,3,0,32,1,65,32,107,33,1,32,0,65,32,106,33,0,12,1,11,11,11,11,178,1,1,3,127,32,1,65,240,255,255,255,3,32,2,118,75,4,64,65,144,1,65,192,1,65,23,65,56,16,0,0,11,32,1,32,2,116,34,3,65,0,16,10,34,2,32,3,16,13,32,0,69,4,64,65,12,65,2,16,10,34,0,65,172,3,75,4,64,32,0,65,16,107,34,1,32,1,40,2,4,65,1,106,54,2,4,11,11,32,0,65,0,54,2,0,32,0,65,0,54,2,4,32,0,65,0,54,2,8,32,2,34,1,32,0,40,2,0,34,4,71,4,64,32,1,65,172,3,75,4,64,32,1,65,16,107,34,5,32,5,40,2,4,65,1,106,54,2,4,11,32,4,16,12,11,32,0,32,1,54,2,0,32,0,32,2,54,2,4,32,0,32,3,54,2,8,32,0,11,46,1,2,127,65,12,65,5,16,10,34,0,65,172,3,75,4,64,32,0,65,16,107,34,1,32,1,40,2,4,65,1,106,54,2,4,11,32,0,65,128,2,65,3,16,14,11,9,0,65,63,32,0,121,167,107,11,49,1,2,127,65,63,32,1,121,167,107,33,2,3,64,65,63,32,0,121,167,107,32,2,107,34,3,65,0,78,4,64,32,0,32,1,32,3,172,134,133,33,0,12,1,11,11,32,0,11,40,0,32,1,32,0,40,2,8,79,4,64,65,128,2,65,192,2,65,163,1,65,44,16,0,0,11,32,1,32,0,40,2,4,106,65,0,58,0,0,11,38,0,32,1,32,0,40,2,8,79,4,64,65,128,2,65,192,2,65,152,1,65,44,16,0,0,11,32,1,32,0,40,2,4,106,45,0,0,11,254,5,2,1,127,4,126,32,0,69,4,64,65,232,0,65,6,16,10,34,0,65,172,3,75,4,64,32,0,65,16,107,34,5,32,5,40,2,4,65,1,106,54,2,4,11,11,32,0,65,0,54,2,0,32,0,65,0,54,2,4,32,0,65,0,54,2,8,32,0,66,0,55,3,16,32,0,66,0,55,3,24,32,0,66,0,55,3,32,32,0,66,0,55,3,40,32,0,66,0,55,3,48,32,0,66,0,55,3,56,32,0,66,0,55,3,64,32,0,66,0,55,3,72,32,0,66,0,55,3,80,32,0,66,0,55,3,88,32,0,66,0,55,3,96,32,0,32,2,173,55,3,80,32,0,32,3,173,55,3,88,65,12,65,4,16,10,34,2,65,172,3,75,4,64,32,2,65,16,107,34,3,32,3,40,2,4,65,1,106,54,2,4,11,32,2,32,4,65,0,16,14,33,2,32,0,40,2,0,16,12,32,0,32,2,54,2,0,32,0,32,4,54,2,4,32,0,66,1,32,1,173,134,66,1,125,55,3,96,32,0,66,243,130,183,218,216,230,232,30,55,3,72,35,4,69,4,64,65,0,33,2,3,64,32,2,65,128,2,72,4,64,32,2,65,255,1,113,173,33,6,32,0,41,3,72,34,7,33,8,65,63,32,7,121,167,107,33,1,3,64,65,63,32,6,121,167,107,32,1,107,34,3,65,0,78,4,64,32,6,32,8,32,3,172,134,133,33,6,12,1,11,11,65,0,33,4,3,64,32,4,32,0,40,2,4,65,1,107,72,4,64,32,6,66,8,134,33,6,32,0,41,3,72,34,7,33,8,65,63,32,7,121,167,107,33,1,3,64,65,63,32,6,121,167,107,32,1,107,34,3,65,0,78,4,64,32,6,32,8,32,3,172,134,133,33,6,12,1,11,11,32,4,65,1,106,33,4,12,1,11,11,35,6,40,2,4,32,2,65,3,116,106,32,6,55,3,0,32,2,65,1,106,33,2,12,1,11,11,65,63,32,0,41,3,72,121,167,107,172,33,7,65,0,33,2,3,64,32,2,65,128,2,72,4,64,35,5,33,1,32,2,172,32,7,134,34,8,33,6,65,63,32,0,41,3,72,34,9,121,167,107,33,3,3,64,65,63,32,6,121,167,107,32,3,107,34,4,65,0,78,4,64,32,6,32,9,32,4,172,134,133,33,6,12,1,11,11,32,1,40,2,4,32,2,65,3,116,106,32,6,32,8,132,55,3,0,32,2,65,1,106,33,2,12,1,11,11,65,1,36,4,11,32,0,66,0,55,3,24,32,0,66,0,55,3,32,65,0,33,2,3,64,32,2,32,0,40,2,4,72,4,64,32,0,40,2,0,32,2,16,18,32,2,65,1,106,33,2,12,1,11,11,32,0,66,0,55,3,40,32,0,65,0,54,2,8,32,0,66,0,55,3,16,32,0,66,0,55,3,40,32,0,40,2,0,32,0,40,2,8,16,19,33,1,32,0,40,2,8,32,0,40,2,0,40,2,4,106,65,1,58,0,0,32,0,32,0,41,3,40,35,6,40,2,4,32,1,65,3,116,106,41,3,0,133,55,3,40,32,0,32,0,40,2,8,65,1,106,32,0,40,2,4,111,54,2,8,32,0,35,5,40,2,4,32,0,41,3,40,34,6,66,45,136,167,65,3,116,106,41,3,0,32,6,66,8,134,66,1,132,133,55,3,40,32,0,11,38,1,1,127,32,0,40,2,0,34,0,65,172,3,75,4,64,32,0,65,16,107,34,1,32,1,40,2,4,65,1,106,54,2,4,11,32,0,11,55,1,2,127,32,1,32,0,40,2,0,34,2,71,4,64,32,1,65,172,3,75,4,64,32,1,65,16,107,34,3,32,3,40,2,4,65,1,106,54,2,4,11,32,2,16,12,11,32,0,32,1,54,2,0,11,7,0,32,0,40,2,4,11,9,0,32,0,32,1,54,2,4,11,7,0,32,0,40,2,8,11,9,0,32,0,32,1,54,2,8,11,7,0,32,0,41,3,16,11,9,0,32,0,32,1,55,3,16,11,7,0,32,0,41,3,24,11,9,0,32,0,32,1,55,3,24,11,7,0,32,0,41,3,32,11,9,0,32,0,32,1,55,3,32,11,7,0,32,0,41,3,40,11,9,0,32,0,32,1,55,3,40,11,7,0,32,0,41,3,48,11,9,0,32,0,32,1,55,3,48,11,7,0,32,0,41,3,56,11,9,0,32,0,32,1,55,3,56,11,7,0,32,0,41,3,64,11,9,0,32,0,32,1,55,3,64,11,7,0,32,0,41,3,72,11,9,0,32,0,32,1,55,3,72,11,7,0,32,0,41,3,80,11,9,0,32,0,32,1,55,3,80,11,7,0,32,0,41,3,88,11,9,0,32,0,32,1,55,3,88,11,7,0,32,0,41,3,96,11,9,0,32,0,32,1,55,3,96,11,172,4,2,5,127,1,126,32,2,65,172,3,75,4,64,32,2,65,16,107,34,4,32,4,40,2,4,65,1,106,54,2,4,11,32,2,33,4,65,0,33,2,32,1,40,2,8,33,5,32,1,40,2,4,33,6,3,64,2,127,65,0,33,3,3,64,32,3,32,5,72,4,64,32,3,32,6,106,45,0,0,33,1,32,0,40,2,0,32,0,40,2,8,16,19,33,7,32,0,40,2,8,32,0,40,2,0,40,2,4,106,32,1,58,0,0,32,0,32,0,41,3,40,35,6,40,2,4,32,7,65,3,116,106,41,3,0,133,55,3,40,32,0,32,0,40,2,8,65,1,106,32,0,40,2,4,111,54,2,8,32,0,35,5,40,2,4,32,0,41,3,40,34,8,66,45,136,167,65,3,116,106,41,3,0,32,1,173,32,8,66,8,134,132,133,55,3,40,32,0,32,0,41,3,16,66,1,124,55,3,16,32,0,32,0,41,3,24,66,1,124,55,3,24,32,0,41,3,16,32,0,41,3,80,90,4,127,32,0,41,3,40,32,0,41,3,96,131,80,5,65,0,11,4,127,65,1,5,32,0,41,3,16,32,0,41,3,88,90,11,4,64,32,0,32,0,41,3,32,55,3,48,32,0,32,0,41,3,16,55,3,56,32,0,32,0,41,3,40,55,3,64,65,0,33,1,3,64,32,1,32,0,40,2,4,72,4,64,32,0,40,2,0,32,1,16,18,32,1,65,1,106,33,1,12,1,11,11,32,0,66,0,55,3,40,32,0,65,0,54,2,8,32,0,66,0,55,3,16,32,0,66,0,55,3,40,32,0,40,2,0,32,0,40,2,8,16,19,33,1,32,0,40,2,8,32,0,40,2,0,40,2,4,106,65,1,58,0,0,32,0,32,0,41,3,40,35,6,40,2,4,32,1,65,3,116,106,41,3,0,133,55,3,40,32,0,32,0,40,2,8,65,1,106,32,0,40,2,4,111,54,2,8,32,0,35,5,40,2,4,32,0,41,3,40,34,8,66,45,136,167,65,3,116,106,41,3,0,32,8,66,8,134,66,1,132,133,55,3,40,32,3,65,1,106,12,3,11,32,3,65,1,106,33,3,12,1,11,11,65,127,11,34,1,65,0,78,4,64,32,5,32,1,107,33,5,32,1,32,6,106,33,6,32,2,34,1,65,1,106,33,2,32,4,40,2,4,32,1,65,2,116,106,32,0,41,3,56,62,2,0,12,1,11,11,32,4,11,10,0,16,15,36,5,16,15,36,6,11,3,0,1,11,73,1,2,127,32,0,40,2,4,34,1,65,255,255,255,255,0,113,34,2,65,1,70,4,64,32,0,65,16,106,16,53,32,0,32,0,40,2,0,65,1,114,54,2,0,35,0,32,0,16,2,5,32,0,32,2,65,1,107,32,1,65,128,128,128,128,127,113,114,54,2,4,11,11,58,0,2,64,2,64,2,64,32,0,65,8,107,40,2,0,14,7,0,0,1,1,1,1,1,2,11,15,11,32,0,40,2,0,34,0,4,64,32,0,65,172,3,79,4,64,32,0,65,16,107,16,52,11,11,15,11,0,11,11,137,3,7,0,65,16,11,55,40,0,0,0,1,0,0,0,1,0,0,0,40,0,0,0,97,0,108,0,108,0,111,0,99,0,97,0,116,0,105,0,111,0,110,0,32,0,116,0,111,0,111,0,32,0,108,0,97,0,114,0,103,0,101,0,65,208,0,11,45,30,0,0,0,1,0,0,0,1,0,0,0,30,0,0,0,126,0,108,0,105,0,98,0,47,0,114,0,116,0,47,0,116,0,108,0,115,0,102,0,46,0,116,0,115,0,65,128,1,11,43,28,0,0,0,1,0,0,0,1,0,0,0,28,0,0,0,73,0,110,0,118,0,97,0,108,0,105,0,100,0,32,0,108,0,101,0,110,0,103,0,116,0,104,0,65,176,1,11,53,38,0,0,0,1,0,0,0,1,0,0,0,38,0,0,0,126,0,108,0,105,0,98,0,47,0,97,0,114,0,114,0,97,0,121,0,98,0,117,0,102,0,102,0,101,0,114,0,46,0,116,0,115,0,65,240,1,11,51,36,0,0,0,1,0,0,0,1,0,0,0,36,0,0,0,73,0,110,0,100,0,101,0,120,0,32,0,111,0,117,0,116,0,32,0,111,0,102,0,32,0,114,0,97,0,110,0,103,0,101,0,65,176,2,11,51,36,0,0,0,1,0,0,0,1,0,0,0,36,0,0,0,126,0,108,0,105,0,98,0,47,0,116,0,121,0,112,0,101,0,100,0,97,0,114,0,114,0,97,0,121,0,46,0,116,0,115,0,65,240,2,11,53,7,0,0,0,16,0,0,0,0,0,0,0,16,0,0,0,0,0,0,0,16,0,0,0,0,0,0,0,145,4,0,0,2,0,0,0,49,0,0,0,2,0,0,0,17,1,0,0,2,0,0,0,16,0,34,16,115,111,117,114,99,101,77,97,112,112,105,110,103,85,82,76,16,46,47,114,97,98,105,110,46,119,97,115,109,46,109,97,112]);return WS(new Response(new Blob([e],{type:"application/wasm"})),r)}m2.exports=Zh});var E2=le((RV,w2)=>{var g2=c2(),jS=y2(),XS=async(r,e,t,n,i)=>{let o=await jS();return new g2(o,r,e,t,n,i)};w2.exports={Rabin:g2,create:XS}});var G2=le((JM,K2)=>{"use strict";K2.exports=r=>{if(Object.prototype.toString.call(r)!=="[object Object]")return!1;let e=Object.getPrototypeOf(r);return e===null||e===Object.prototype}});var Z2=le((j2,X2)=>{"use strict";var Xl=G2(),{hasOwnProperty:Y2}=Object.prototype,{propertyIsEnumerable:v4}=Object,$o=(r,e,t)=>Object.defineProperty(r,e,{value:t,writable:!0,enumerable:!0,configurable:!0}),A4=j2,q2={concatArrays:!1,ignoreUndefined:!1},Zl=r=>{let e=[];for(let t in r)Y2.call(r,t)&&e.push(t);if(Object.getOwnPropertySymbols){let t=Object.getOwnPropertySymbols(r);for(let n of t)v4.call(r,n)&&e.push(n)}return e};function zo(r){return Array.isArray(r)?_4(r):Xl(r)?S4(r):r}function _4(r){let e=r.slice(0,0);return Zl(r).forEach(t=>{$o(e,t,zo(r[t]))}),e}function S4(r){let e=Object.getPrototypeOf(r)===null?Object.create(null):{};return Zl(r).forEach(t=>{$o(e,t,zo(r[t]))}),e}var W2=(r,e,t,n)=>(t.forEach(i=>{typeof e[i]>"u"&&n.ignoreUndefined||(i in r&&r[i]!==Object.getPrototypeOf(r)?$o(r,i,ep(r[i],e[i],n)):$o(r,i,zo(e[i])))}),r),I4=(r,e,t)=>{let n=r.slice(0,0),i=0;return[r,e].forEach(o=>{let s=[];for(let a=0;a<o.length;a++)Y2.call(o,a)&&(s.push(String(a)),o===r?$o(n,i++,o[a]):$o(n,i++,zo(o[a])));n=W2(n,o,Zl(o).filter(a=>!s.includes(a)),t)}),n};function ep(r,e,t){return t.concatArrays&&Array.isArray(r)&&Array.isArray(e)?I4(r,e,t):!Xl(e)||!Xl(r)?zo(e):W2(r,e,Zl(e),t)}X2.exports=function(...r){let e=ep(zo(q2),this!==A4&&this||{},q2),t={_:{}};for(let n of r)if(n!==void 0){if(!Xl(n))throw new TypeError("`"+n+"` is not an Option Object");t=ep(t,{_:n},e)}return t._}});var bE=le((pK,xE)=>{"use strict";xE.exports={RTLD_LAZY:1,RTLD_NOW:2,RTLD_GLOBAL:256,RTLD_LOCAL:0,RTLD_DEEPBIND:8,E2BIG:7,EACCES:13,EADDRINUSE:98,EADDRNOTAVAIL:99,EAFNOSUPPORT:97,EAGAIN:11,EALREADY:114,EBADF:9,EBADMSG:74,EBUSY:16,ECANCELED:125,ECHILD:10,ECONNABORTED:103,ECONNREFUSED:111,ECONNRESET:104,EDEADLK:35,EDESTADDRREQ:89,EDOM:33,EDQUOT:122,EEXIST:17,EFAULT:14,EFBIG:27,EHOSTUNREACH:113,EIDRM:43,EILSEQ:84,EINPROGRESS:115,EINTR:4,EINVAL:22,EIO:5,EISCONN:106,EISDIR:21,ELOOP:40,EMFILE:24,EMLINK:31,EMSGSIZE:90,EMULTIHOP:72,ENAMETOOLONG:36,ENETDOWN:100,ENETRESET:102,ENETUNREACH:101,ENFILE:23,ENOBUFS:105,ENODATA:61,ENODEV:19,ENOENT:2,ENOEXEC:8,ENOLCK:37,ENOLINK:67,ENOMEM:12,ENOMSG:42,ENOPROTOOPT:92,ENOSPC:28,ENOSR:63,ENOSTR:60,ENOSYS:38,ENOTCONN:107,ENOTDIR:20,ENOTEMPTY:39,ENOTSOCK:88,ENOTSUP:95,ENOTTY:25,ENXIO:6,EOPNOTSUPP:95,EOVERFLOW:75,EPERM:1,EPIPE:32,EPROTO:71,EPROTONOSUPPORT:93,EPROTOTYPE:91,ERANGE:34,EROFS:30,ESPIPE:29,ESRCH:3,ESTALE:116,ETIME:62,ETIMEDOUT:110,ETXTBSY:26,EWOULDBLOCK:11,EXDEV:18,PRIORITY_LOW:19,PRIORITY_BELOW_NORMAL:10,PRIORITY_NORMAL:0,PRIORITY_ABOVE_NORMAL:-7,PRIORITY_HIGH:-14,PRIORITY_HIGHEST:-20,SIGHUP:1,SIGINT:2,SIGQUIT:3,SIGILL:4,SIGTRAP:5,SIGABRT:6,SIGIOT:6,SIGBUS:7,SIGFPE:8,SIGKILL:9,SIGUSR1:10,SIGSEGV:11,SIGUSR2:12,SIGPIPE:13,SIGALRM:14,SIGTERM:15,SIGCHLD:17,SIGSTKFLT:16,SIGCONT:18,SIGSTOP:19,SIGTSTP:20,SIGTTIN:21,SIGTTOU:22,SIGURG:23,SIGXCPU:24,SIGXFSZ:25,SIGVTALRM:26,SIGPROF:27,SIGWINCH:28,SIGIO:29,SIGPOLL:29,SIGPWR:30,SIGSYS:31,UV_FS_SYMLINK_DIR:1,UV_FS_SYMLINK_JUNCTION:2,O_RDONLY:0,O_WRONLY:1,O_RDWR:2,UV_DIRENT_UNKNOWN:0,UV_DIRENT_FILE:1,UV_DIRENT_DIR:2,UV_DIRENT_LINK:3,UV_DIRENT_FIFO:4,UV_DIRENT_SOCKET:5,UV_DIRENT_CHAR:6,UV_DIRENT_BLOCK:7,EXTENSIONLESS_FORMAT_JAVASCRIPT:0,EXTENSIONLESS_FORMAT_WASM:1,S_IFMT:61440,S_IFREG:32768,S_IFDIR:16384,S_IFCHR:8192,S_IFBLK:24576,S_IFIFO:4096,S_IFLNK:40960,S_IFSOCK:49152,O_CREAT:64,O_EXCL:128,UV_FS_O_FILEMAP:0,O_NOCTTY:256,O_TRUNC:512,O_APPEND:1024,O_DIRECTORY:65536,O_NOATIME:262144,O_NOFOLLOW:131072,O_SYNC:1052672,O_DSYNC:4096,O_DIRECT:16384,O_NONBLOCK:2048,S_IRWXU:448,S_IRUSR:256,S_IWUSR:128,S_IXUSR:64,S_IRWXG:56,S_IRGRP:32,S_IWGRP:16,S_IXGRP:8,S_IRWXO:7,S_IROTH:4,S_IWOTH:2,S_IXOTH:1,F_OK:0,R_OK:4,W_OK:2,X_OK:1,UV_FS_COPYFILE_EXCL:1,COPYFILE_EXCL:1,UV_FS_COPYFILE_FICLONE:2,COPYFILE_FICLONE:2,UV_FS_COPYFILE_FICLONE_FORCE:4,COPYFILE_FICLONE_FORCE:4,OPENSSL_VERSION_NUMBER:805306576,SSL_OP_ALL:2147485776,SSL_OP_ALLOW_NO_DHE_KEX:1024,SSL_OP_ALLOW_UNSAFE_LEGACY_RENEGOTIATION:262144,SSL_OP_CIPHER_SERVER_PREFERENCE:4194304,SSL_OP_CISCO_ANYCONNECT:32768,SSL_OP_COOKIE_EXCHANGE:8192,SSL_OP_CRYPTOPRO_TLSEXT_BUG:2147483648,SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS:2048,SSL_OP_LEGACY_SERVER_CONNECT:4,SSL_OP_NO_COMPRESSION:131072,SSL_OP_NO_ENCRYPT_THEN_MAC:524288,SSL_OP_NO_QUERY_MTU:4096,SSL_OP_NO_RENEGOTIATION:1073741824,SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION:65536,SSL_OP_NO_SSLv2:0,SSL_OP_NO_SSLv3:33554432,SSL_OP_NO_TICKET:16384,SSL_OP_NO_TLSv1:67108864,SSL_OP_NO_TLSv1_1:268435456,SSL_OP_NO_TLSv1_2:134217728,SSL_OP_NO_TLSv1_3:536870912,SSL_OP_PRIORITIZE_CHACHA:2097152,SSL_OP_TLS_ROLLBACK_BUG:8388608,ENGINE_METHOD_RSA:1,ENGINE_METHOD_DSA:2,ENGINE_METHOD_DH:4,ENGINE_METHOD_RAND:8,ENGINE_METHOD_EC:2048,ENGINE_METHOD_CIPHERS:64,ENGINE_METHOD_DIGESTS:128,ENGINE_METHOD_PKEY_METHS:512,ENGINE_METHOD_PKEY_ASN1_METHS:1024,ENGINE_METHOD_ALL:65535,ENGINE_METHOD_NONE:0,DH_CHECK_P_NOT_SAFE_PRIME:2,DH_CHECK_P_NOT_PRIME:1,DH_UNABLE_TO_CHECK_GENERATOR:4,DH_NOT_SUITABLE_GENERATOR:8,RSA_PKCS1_PADDING:1,RSA_NO_PADDING:3,RSA_PKCS1_OAEP_PADDING:4,RSA_X931_PADDING:5,RSA_PKCS1_PSS_PADDING:6,RSA_PSS_SALTLEN_DIGEST:-1,RSA_PSS_SALTLEN_MAX_SIGN:-2,RSA_PSS_SALTLEN_AUTO:-2,defaultCoreCipherList:"TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256:TLS_AES_128_GCM_SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA384:DHE-RSA-AES256-SHA384:ECDHE-RSA-AES256-SHA256:DHE-RSA-AES256-SHA256:HIGH:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!SRP:!CAMELLIA",TLS1_VERSION:769,TLS1_1_VERSION:770,TLS1_2_VERSION:771,TLS1_3_VERSION:772,POINT_CONVERSION_COMPRESSED:2,POINT_CONVERSION_UNCOMPRESSED:4,POINT_CONVERSION_HYBRID:6}});var qI={};Be(qI,{createVerifiedFetch:()=>hp,verifiedFetch:()=>mu});function ui(r){let e=new globalThis.AbortController;function t(){e.abort();for(let o of r)o?.removeEventListener!=null&&o.removeEventListener("abort",t)}for(let o of r){if(o?.aborted===!0){t();break}o?.addEventListener!=null&&o.addEventListener("abort",t)}function n(){for(let o of r)o?.removeEventListener!=null&&o.removeEventListener("abort",t)}let i=e.signal;return i.clear=n,i}function WE(r){let[e,t]=r[Symbol.asyncIterator]!=null?[r[Symbol.asyncIterator](),Symbol.asyncIterator]:[r[Symbol.iterator](),Symbol.iterator],n=[];return{peek:()=>e.next(),push:i=>{n.push(i)},next:()=>n.length>0?{done:!1,value:n.shift()}:e.next(),[t](){return this}}}var Hi=WE;function jE(r){return r[Symbol.asyncIterator]!=null}function Ap(r){return r?.then!=null}function XE(r,e){if(jE(r))return async function*(){for await(let a of r){let c=e(a);Ap(c)&&await c,yield a}}();let t=Hi(r),{value:n,done:i}=t.next();if(i===!0)return function*(){}();if(typeof e(n)?.then=="function")return async function*(){yield n;for await(let a of t){let c=e(a);Ap(c)&&await c,yield a}}();let s=e;return function*(){yield n;for(let a of t)s(a),yield a}()}var gu=XE;var Su={};Be(Su,{base32:()=>qe,base32hex:()=>ax,base32hexpad:()=>lx,base32hexpadupper:()=>ux,base32hexupper:()=>cx,base32pad:()=>ox,base32padupper:()=>sx,base32upper:()=>Bp,base32z:()=>dx});var $i={};Be($i,{coerce:()=>Pt,empty:()=>_p,equals:()=>wu,fromHex:()=>JE,fromString:()=>Eu,isBinary:()=>QE,toHex:()=>ZE,toString:()=>xu});var _p=new Uint8Array(0);function ZE(r){return r.reduce((e,t)=>e+t.toString(16).padStart(2,"0"),"")}function JE(r){let e=r.match(/../g);return e!=null?new Uint8Array(e.map(t=>parseInt(t,16))):_p}function wu(r,e){if(r===e)return!0;if(r.byteLength!==e.byteLength)return!1;for(let t=0;t<r.byteLength;t++)if(r[t]!==e[t])return!1;return!0}function Pt(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return r;if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return new Uint8Array(r.buffer,r.byteOffset,r.byteLength);throw new Error("Unknown type, must be binary type")}function QE(r){return r instanceof ArrayBuffer||ArrayBuffer.isView(r)}function Eu(r){return new TextEncoder().encode(r)}function xu(r){return new TextDecoder().decode(r)}function ex(r,e){if(r.length>=255)throw new TypeError("Alphabet too long");for(var t=new Uint8Array(256),n=0;n<t.length;n++)t[n]=255;for(var i=0;i<r.length;i++){var o=r.charAt(i),s=o.charCodeAt(0);if(t[s]!==255)throw new TypeError(o+" is ambiguous");t[s]=i}var a=r.length,c=r.charAt(0),u=Math.log(a)/Math.log(256),l=Math.log(256)/Math.log(a);function d(h){if(h instanceof Uint8Array||(ArrayBuffer.isView(h)?h=new Uint8Array(h.buffer,h.byteOffset,h.byteLength):Array.isArray(h)&&(h=Uint8Array.from(h))),!(h instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(h.length===0)return"";for(var m=0,y=0,g=0,E=h.length;g!==E&&h[g]===0;)g++,m++;for(var x=(E-g)*l+1>>>0,_=new Uint8Array(x);g!==E;){for(var S=h[g],A=0,v=x-1;(S!==0||A<y)&&v!==-1;v--,A++)S+=256*_[v]>>>0,_[v]=S%a>>>0,S=S/a>>>0;if(S!==0)throw new Error("Non-zero carry");y=A,g++}for(var b=x-y;b!==x&&_[b]===0;)b++;for(var T=c.repeat(m);b<x;++b)T+=r.charAt(_[b]);return T}function p(h){if(typeof h!="string")throw new TypeError("Expected String");if(h.length===0)return new Uint8Array;var m=0;if(h[m]!==" "){for(var y=0,g=0;h[m]===c;)y++,m++;for(var E=(h.length-m)*u+1>>>0,x=new Uint8Array(E);h[m];){var _=t[h.charCodeAt(m)];if(_===255)return;for(var S=0,A=E-1;(_!==0||S<g)&&A!==-1;A--,S++)_+=a*x[A]>>>0,x[A]=_%256>>>0,_=_/256>>>0;if(_!==0)throw new Error("Non-zero carry");g=S,m++}if(h[m]!==" "){for(var v=E-g;v!==E&&x[v]===0;)v++;for(var b=new Uint8Array(y+(E-v)),T=y;v!==E;)b[T++]=x[v++];return b}}}function f(h){var m=p(h);if(m)return m;throw new Error(`Non-${e} character`)}return{encode:d,decodeUnsafe:p,decode:f}}var tx=ex,rx=tx,Sp=rx;var bu=class{name;prefix;baseEncode;constructor(e,t,n){this.name=e,this.prefix=t,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},vu=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,t,n){if(this.name=e,this.prefix=t,t.codePointAt(0)===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=t.codePointAt(0),this.baseDecode=n}decode(e){if(typeof e=="string"){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(e){return Ip(this,e)}},Au=class{decoders;constructor(e){this.decoders=e}or(e){return Ip(this,e)}decode(e){let t=e[0],n=this.decoders[t];if(n!=null)return n.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function Ip(r,e){return new Au({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}var _u=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,t,n,i){this.name=e,this.prefix=t,this.baseEncode=n,this.baseDecode=i,this.encoder=new bu(e,t,n),this.decoder=new vu(e,t,i)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function zi({name:r,prefix:e,encode:t,decode:n}){return new _u(r,e,t,n)}function vn({name:r,prefix:e,alphabet:t}){let{encode:n,decode:i}=Sp(t,r);return zi({prefix:e,name:r,encode:n,decode:o=>Pt(i(o))})}function nx(r,e,t,n){let i={};for(let l=0;l<e.length;++l)i[e[l]]=l;let o=r.length;for(;r[o-1]==="=";)--o;let s=new Uint8Array(o*t/8|0),a=0,c=0,u=0;for(let l=0;l<o;++l){let d=i[r[l]];if(d===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<t|d,a+=t,a>=8&&(a-=8,s[u++]=255&c>>a)}if(a>=t||255&c<<8-a)throw new SyntaxError("Unexpected end of data");return s}function ix(r,e,t){let n=e[e.length-1]==="=",i=(1<<t)-1,o="",s=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],s+=8;s>t;)s-=t,o+=e[i&a>>s];if(s!==0&&(o+=e[i&a<<t-s]),n)for(;o.length*t&7;)o+="=";return o}function ke({name:r,prefix:e,bitsPerChar:t,alphabet:n}){return zi({prefix:e,name:r,encode(i){return ix(i,n,t)},decode(i){return nx(i,n,t,r)}})}var qe=ke({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Bp=ke({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),ox=ke({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),sx=ke({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),ax=ke({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),cx=ke({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),lx=ke({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),ux=ke({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),dx=ke({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Iu={};Be(Iu,{base58btc:()=>Ne,base58flickr:()=>fx});var Ne=vn({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),fx=vn({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var hx=Tp,kp=128,px=127,mx=~px,yx=Math.pow(2,31);function Tp(r,e,t){e=e||[],t=t||0;for(var n=t;r>=yx;)e[t++]=r&255|kp,r/=128;for(;r&mx;)e[t++]=r&255|kp,r>>>=7;return e[t]=r|0,Tp.bytes=t-n+1,e}var gx=Bu,wx=128,Rp=127;function Bu(r,n){var t=0,n=n||0,i=0,o=n,s,a=r.length;do{if(o>=a)throw Bu.bytes=0,new RangeError("Could not decode varint");s=r[o++],t+=i<28?(s&Rp)<<i:(s&Rp)*Math.pow(2,i),i+=7}while(s>=wx);return Bu.bytes=o-n,t}var Ex=Math.pow(2,7),xx=Math.pow(2,14),bx=Math.pow(2,21),vx=Math.pow(2,28),Ax=Math.pow(2,35),_x=Math.pow(2,42),Sx=Math.pow(2,49),Ix=Math.pow(2,56),Bx=Math.pow(2,63),kx=function(r){return r<Ex?1:r<xx?2:r<bx?3:r<vx?4:r<Ax?5:r<_x?6:r<Sx?7:r<Ix?8:r<Bx?9:10},Rx={encode:hx,decode:gx,encodingLength:kx},Tx=Rx,Zo=Tx;function Jo(r,e=0){return[Zo.decode(r,e),Zo.decode.bytes]}function Ki(r,e,t=0){return Zo.encode(r,e,t),e}function Gi(r){return Zo.encodingLength(r)}function mr(r,e){let t=e.byteLength,n=Gi(r),i=n+Gi(t),o=new Uint8Array(i+t);return Ki(r,o,0),Ki(t,o,n),o.set(e,i),new qi(r,t,e,o)}function st(r){let e=Pt(r),[t,n]=Jo(e),[i,o]=Jo(e.subarray(n)),s=e.subarray(n+o);if(s.byteLength!==i)throw new Error("Incorrect length");return new qi(t,i,s,e)}function Np(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&wu(r.bytes,t.bytes)}}var qi=class{code;size;digest;bytes;constructor(e,t,n,i){this.code=e,this.size=t,this.digest=n,this.bytes=i}};function Cp(r,e){let{bytes:t,version:n}=r;switch(n){case 0:return Cx(t,ku(r),e??Ne.encoder);default:return Lx(t,ku(r),e??qe.encoder)}}var Lp=new WeakMap;function ku(r){let e=Lp.get(r);if(e==null){let t=new Map;return Lp.set(r,t),t}return e}var F=class r{code;version;multihash;bytes;"/";constructor(e,t,n,i){this.code=t,this.version=e,this.multihash=n,this.bytes=i,this["/"]=i}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:e,multihash:t}=this;if(e!==Qo)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==Ux)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(t)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:e,digest:t}=this.multihash,n=mr(e,t);return r.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(e){return r.equals(this,e)}static equals(e,t){let n=t;return n!=null&&e.code===n.code&&e.version===n.version&&Np(e.multihash,n.multihash)}toString(e){return Cp(this,e)}toJSON(){return{"/":Cp(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(e){if(e==null)return null;let t=e;if(t instanceof r)return t;if(t["/"]!=null&&t["/"]===t.bytes||t.asCID===t){let{version:n,code:i,multihash:o,bytes:s}=t;return new r(n,i,o,s??Up(n,i,o.bytes))}else if(t[Dx]===!0){let{version:n,multihash:i,code:o}=t,s=st(i);return r.create(n,o,s)}else return null}static create(e,t,n){if(typeof t!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(e){case 0:{if(t!==Qo)throw new Error(`Version 0 CID must use dag-pb (code: ${Qo}) block encoding`);return new r(e,t,n,n.bytes)}case 1:{let i=Up(e,t,n.bytes);return new r(e,t,n,i)}default:throw new Error("Invalid version")}}static createV0(e){return r.create(0,Qo,e)}static createV1(e,t){return r.create(1,e,t)}static decode(e){let[t,n]=r.decodeFirst(e);if(n.length!==0)throw new Error("Incorrect length");return t}static decodeFirst(e){let t=r.inspectBytes(e),n=t.size-t.multihashSize,i=Pt(e.subarray(n,n+t.multihashSize));if(i.byteLength!==t.multihashSize)throw new Error("Incorrect length");let o=i.subarray(t.multihashSize-t.digestSize),s=new qi(t.multihashCode,t.digestSize,o,i);return[t.version===0?r.createV0(s):r.createV1(t.codec,s),e.subarray(t.size)]}static inspectBytes(e){let t=0,n=()=>{let[d,p]=Jo(e.subarray(t));return t+=p,d},i=n(),o=Qo;if(i===18?(i=0,t=0):o=n(),i!==0&&i!==1)throw new RangeError(`Invalid CID version ${i}`);let s=t,a=n(),c=n(),u=t+c,l=u-s;return{version:i,codec:o,multihashCode:a,digestSize:c,multihashSize:l,size:u}}static parse(e,t){let[n,i]=Nx(e,t),o=r.decode(i);if(o.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return ku(o).set(n,e),o}};function Nx(r,e){switch(r[0]){case"Q":{let t=e??Ne;return[Ne.prefix,t.decode(`${Ne.prefix}${r}`)]}case Ne.prefix:{let t=e??Ne;return[Ne.prefix,t.decode(r)]}case qe.prefix:{let t=e??qe;return[qe.prefix,t.decode(r)]}default:{if(e==null)throw Error("To parse non base32 or base58btc encoded CID multibase decoder must be provided");return[r[0],e.decode(r)]}}}function Cx(r,e,t){let{prefix:n}=t;if(n!==Ne.prefix)throw Error(`Cannot string encode V0 in ${t.name} encoding`);let i=e.get(n);if(i==null){let o=t.encode(r).slice(1);return e.set(n,o),o}else return i}function Lx(r,e,t){let{prefix:n}=t,i=e.get(n);if(i==null){let o=t.encode(r);return e.set(n,o),o}else return i}var Qo=112,Ux=18;function Up(r,e,t){let n=Gi(r),i=n+Gi(e),o=new Uint8Array(i+t.byteLength);return Ki(r,o,0),Ki(e,o,n),o.set(t,i),o}var Dx=Symbol.for("@ipld/js-cid/CID");var es=Symbol.for("@libp2p/content-routing");var Ru=Symbol.for("@libp2p/peer-id");function Dp(r){return r!=null&&!!r[Ru]}var ts=Symbol.for("@libp2p/peer-routing");var An=class r extends Error{code;type;constructor(e="The operation was aborted"){super(e),this.code=r.code,this.type=r.type}static code="ABORT_ERR";static type="aborted"},O=class extends Error{code;props;constructor(e,t,n){super(e),this.code=t,this.name=n?.name??"CodeError",this.props=n??{}}};var Aa=class extends EventTarget{#e=new Map;listenerCount(e){let t=this.#e.get(e);return t==null?0:t.length}addEventListener(e,t,n){super.addEventListener(e,t,n);let i=this.#e.get(e);i==null&&(i=[],this.#e.set(e,i)),i.push({callback:t,once:(n!==!0&&n!==!1&&n?.once)??!1})}removeEventListener(e,t,n){super.removeEventListener(e.toString(),t??null,n);let i=this.#e.get(e);i!=null&&(i=i.filter(({callback:o})=>o!==t),this.#e.set(e,i))}dispatchEvent(e){let t=super.dispatchEvent(e),n=this.#e.get(e.type);return n==null||(n=n.filter(({once:i})=>!i),this.#e.set(e.type,n)),t}safeDispatchEvent(e,t={}){return this.dispatchEvent(new Ox(e,t))}},Tu=class extends Event{detail;constructor(e,t){super(e,t),this.detail=t?.detail}},Ox=globalThis.CustomEvent??Tu;var _a=(r,...e)=>{try{[...e]}catch{}};function Op(r){return r!=null&&typeof r.start=="function"&&typeof r.stop=="function"}async function _n(...r){let e=[];for(let t of r)Op(t)&&e.push(t);await Promise.all(e.map(async t=>{t.beforeStart!=null&&await t.beforeStart()})),await Promise.all(e.map(async t=>{await t.start()})),await Promise.all(e.map(async t=>{t.afterStart!=null&&await t.afterStart()}))}async function Sn(...r){let e=[];for(let t of r)Op(t)&&e.push(t);await Promise.all(e.map(async t=>{t.beforeStop!=null&&await t.beforeStop()})),await Promise.all(e.map(async t=>{await t.stop()})),await Promise.all(e.map(async t=>{t.afterStop!=null&&await t.afterStop()}))}var Lu={};Be(Lu,{sha256:()=>fe,sha512:()=>Cu});function di({name:r,code:e,encode:t}){return new Nu(r,e,t)}var Nu=class{name;code;encode;constructor(e,t,n){this.name=e,this.code=t,this.encode=n}digest(e){if(e instanceof Uint8Array){let t=this.encode(e);return t instanceof Uint8Array?mr(this.code,t):t.then(n=>mr(this.code,n))}else throw Error("Unknown type, must be binary type")}};function Fp(r){return async e=>new Uint8Array(await crypto.subtle.digest(r,e))}var fe=di({name:"sha2-256",code:18,encode:Fp("SHA-256")}),Cu=di({name:"sha2-512",code:19,encode:Fp("SHA-512")});var St=Q(Du(),1);var Ou={};Be(Ou,{base64:()=>yr,base64pad:()=>jx,base64url:()=>$p,base64urlpad:()=>Xx});var yr=ke({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),jx=ke({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),$p=ke({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Xx=ke({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});St.default.formatters.b=r=>r==null?"undefined":Ne.baseEncode(r);St.default.formatters.t=r=>r==null?"undefined":qe.baseEncode(r);St.default.formatters.m=r=>r==null?"undefined":yr.baseEncode(r);St.default.formatters.p=r=>r==null?"undefined":r.toString();St.default.formatters.c=r=>r==null?"undefined":r.toString();St.default.formatters.k=r=>r==null?"undefined":r.toString();St.default.formatters.a=r=>r==null?"undefined":r.toString();function Zx(r){let e=()=>{};return e.enabled=!1,e.color="",e.diff=0,e.log=()=>{},e.namespace=r,e.destroy=()=>!0,e.extend=()=>e,e}function zp(){return{forComponent(r){return oe(r)}}}function oe(r){let e=Zx(`${r}:trace`);return St.default.enabled(`${r}:trace`)&&St.default.names.map(t=>t.toString()).find(t=>t.includes(":trace"))!=null&&(e=(0,St.default)(`${r}:trace`)),Object.assign((0,St.default)(r),{error:(0,St.default)(`${r}:error`),trace:e})}function he(r,e){if(r===e)return!0;if(r.byteLength!==e.byteLength)return!1;for(let t=0;t<r.byteLength;t++)if(r[t]!==e[t])return!1;return!0}function In(r){return globalThis.Buffer!=null?new Uint8Array(r.buffer,r.byteOffset,r.byteLength):r}function Mr(r=0){return globalThis.Buffer?.alloc!=null?In(globalThis.Buffer.alloc(r)):new Uint8Array(r)}function mt(r=0){return globalThis.Buffer?.allocUnsafe!=null?In(globalThis.Buffer.allocUnsafe(r)):new Uint8Array(r)}var db=Math.pow(2,7),fb=Math.pow(2,14),hb=Math.pow(2,21),Vu=Math.pow(2,28),Mu=Math.pow(2,35),Hu=Math.pow(2,42),$u=Math.pow(2,49),pe=128,Je=127;function yt(r){if(r<db)return 1;if(r<fb)return 2;if(r<hb)return 3;if(r<Vu)return 4;if(r<Mu)return 5;if(r<Hu)return 6;if(r<$u)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function zu(r,e,t=0){switch(yt(r)){case 8:e[t++]=r&255|pe,r/=128;case 7:e[t++]=r&255|pe,r/=128;case 6:e[t++]=r&255|pe,r/=128;case 5:e[t++]=r&255|pe,r/=128;case 4:e[t++]=r&255|pe,r>>>=7;case 3:e[t++]=r&255|pe,r>>>=7;case 2:e[t++]=r&255|pe,r>>>=7;case 1:{e[t++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return e}function pb(r,e,t=0){switch(yt(r)){case 8:e.set(t++,r&255|pe),r/=128;case 7:e.set(t++,r&255|pe),r/=128;case 6:e.set(t++,r&255|pe),r/=128;case 5:e.set(t++,r&255|pe),r/=128;case 4:e.set(t++,r&255|pe),r>>>=7;case 3:e.set(t++,r&255|pe),r>>>=7;case 2:e.set(t++,r&255|pe),r>>>=7;case 1:{e.set(t++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return e}function Ku(r,e){let t=r[e],n=0;if(n+=t&Je,t<pe||(t=r[e+1],n+=(t&Je)<<7,t<pe)||(t=r[e+2],n+=(t&Je)<<14,t<pe)||(t=r[e+3],n+=(t&Je)<<21,t<pe)||(t=r[e+4],n+=(t&Je)*Vu,t<pe)||(t=r[e+5],n+=(t&Je)*Mu,t<pe)||(t=r[e+6],n+=(t&Je)*Hu,t<pe)||(t=r[e+7],n+=(t&Je)*$u,t<pe))return n;throw new RangeError("Could not decode varint")}function mb(r,e){let t=r.get(e),n=0;if(n+=t&Je,t<pe||(t=r.get(e+1),n+=(t&Je)<<7,t<pe)||(t=r.get(e+2),n+=(t&Je)<<14,t<pe)||(t=r.get(e+3),n+=(t&Je)<<21,t<pe)||(t=r.get(e+4),n+=(t&Je)*Vu,t<pe)||(t=r.get(e+5),n+=(t&Je)*Mu,t<pe)||(t=r.get(e+6),n+=(t&Je)*Hu,t<pe)||(t=r.get(e+7),n+=(t&Je)*$u,t<pe))return n;throw new RangeError("Could not decode varint")}function Xi(r,e,t=0){return e==null&&(e=mt(yt(r))),e instanceof Uint8Array?zu(r,e,t):pb(r,e,t)}function hi(r,e=0){return r instanceof Uint8Array?Ku(r,e):mb(r,e)}var Gu=new Float32Array([-0]),Bn=new Uint8Array(Gu.buffer);function e0(r,e,t){Gu[0]=r,e[t]=Bn[0],e[t+1]=Bn[1],e[t+2]=Bn[2],e[t+3]=Bn[3]}function t0(r,e){return Bn[0]=r[e],Bn[1]=r[e+1],Bn[2]=r[e+2],Bn[3]=r[e+3],Gu[0]}var qu=new Float64Array([-0]),Qe=new Uint8Array(qu.buffer);function r0(r,e,t){qu[0]=r,e[t]=Qe[0],e[t+1]=Qe[1],e[t+2]=Qe[2],e[t+3]=Qe[3],e[t+4]=Qe[4],e[t+5]=Qe[5],e[t+6]=Qe[6],e[t+7]=Qe[7]}function n0(r,e){return Qe[0]=r[e],Qe[1]=r[e+1],Qe[2]=r[e+2],Qe[3]=r[e+3],Qe[4]=r[e+4],Qe[5]=r[e+5],Qe[6]=r[e+6],Qe[7]=r[e+7],qu[0]}var yb=BigInt(Number.MAX_SAFE_INTEGER),gb=BigInt(Number.MIN_SAFE_INTEGER),It=class r{lo;hi;constructor(e,t){this.lo=e|0,this.hi=t|0}toNumber(e=!1){if(!e&&this.hi>>>31>0){let t=~this.lo+1>>>0,n=~this.hi>>>0;return t===0&&(n=n+1>>>0),-(t+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(e=!1){if(e)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let t=~this.lo+1>>>0,n=~this.hi>>>0;return t===0&&(n=n+1>>>0),-(BigInt(t)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(e=!1){return this.toBigInt(e).toString()}zzEncode(){let e=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^e)>>>0,this.lo=(this.lo<<1^e)>>>0,this}zzDecode(){let e=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^e)>>>0,this.hi=(this.hi>>>1^e)>>>0,this}length(){let e=this.lo,t=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?t===0?e<16384?e<128?1:2:e<2097152?3:4:t<16384?t<128?5:6:t<2097152?7:8:n<128?9:10}static fromBigInt(e){if(e===0n)return pi;if(e<yb&&e>gb)return this.fromNumber(Number(e));let t=e<0n;t&&(e=-e);let n=e>>32n,i=e-(n<<32n);return t&&(n=~n|0n,i=~i|0n,++i>i0&&(i=0n,++n>i0&&(n=0n))),new r(Number(i),Number(n))}static fromNumber(e){if(e===0)return pi;let t=e<0;t&&(e=-e);let n=e>>>0,i=(e-n)/4294967296>>>0;return t&&(i=~i>>>0,n=~n>>>0,++n>4294967295&&(n=0,++i>4294967295&&(i=0))),new r(n,i)}static from(e){return typeof e=="number"?r.fromNumber(e):typeof e=="bigint"?r.fromBigInt(e):typeof e=="string"?r.fromBigInt(BigInt(e)):e.low!=null||e.high!=null?new r(e.low>>>0,e.high>>>0):pi}},pi=new It(0,0);pi.toBigInt=function(){return 0n};pi.zzEncode=pi.zzDecode=function(){return this};pi.length=function(){return 1};var i0=4294967296n;function o0(r){let e=0,t=0;for(let n=0;n<r.length;++n)t=r.charCodeAt(n),t<128?e+=1:t<2048?e+=2:(t&64512)===55296&&(r.charCodeAt(n+1)&64512)===56320?(++n,e+=4):e+=3;return e}function s0(r,e,t){if(t-e<1)return"";let i,o=[],s=0,a;for(;e<t;)a=r[e++],a<128?o[s++]=a:a>191&&a<224?o[s++]=(a&31)<<6|r[e++]&63:a>239&&a<365?(a=((a&7)<<18|(r[e++]&63)<<12|(r[e++]&63)<<6|r[e++]&63)-65536,o[s++]=55296+(a>>10),o[s++]=56320+(a&1023)):o[s++]=(a&15)<<12|(r[e++]&63)<<6|r[e++]&63,s>8191&&((i??(i=[])).push(String.fromCharCode.apply(String,o)),s=0);return i!=null?(s>0&&i.push(String.fromCharCode.apply(String,o.slice(0,s))),i.join("")):String.fromCharCode.apply(String,o.slice(0,s))}function Yu(r,e,t){let n=t,i,o;for(let s=0;s<r.length;++s)i=r.charCodeAt(s),i<128?e[t++]=i:i<2048?(e[t++]=i>>6|192,e[t++]=i&63|128):(i&64512)===55296&&((o=r.charCodeAt(s+1))&64512)===56320?(i=65536+((i&1023)<<10)+(o&1023),++s,e[t++]=i>>18|240,e[t++]=i>>12&63|128,e[t++]=i>>6&63|128,e[t++]=i&63|128):(e[t++]=i>>12|224,e[t++]=i>>6&63|128,e[t++]=i&63|128);return t-n}function Zt(r,e){return RangeError(`index out of range: ${r.pos} + ${e??1} > ${r.len}`)}function ka(r,e){return(r[e-4]|r[e-3]<<8|r[e-2]<<16|r[e-1]<<24)>>>0}var Wu=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(e){this.buf=e,this.pos=0,this.len=e.length}uint32(){let e=4294967295;if(e=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(e=(e|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return e;if((this.pos+=5)>this.len)throw this.pos=this.len,Zt(this,10);return e}int32(){return this.uint32()|0}sint32(){let e=this.uint32();return e>>>1^-(e&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw Zt(this,4);return ka(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Zt(this,4);return ka(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Zt(this,4);let e=t0(this.buf,this.pos);return this.pos+=4,e}double(){if(this.pos+8>this.len)throw Zt(this,4);let e=n0(this.buf,this.pos);return this.pos+=8,e}bytes(){let e=this.uint32(),t=this.pos,n=this.pos+e;if(n>this.len)throw Zt(this,e);return this.pos+=e,t===n?new Uint8Array(0):this.buf.subarray(t,n)}string(){let e=this.bytes();return s0(e,0,e.length)}skip(e){if(typeof e=="number"){if(this.pos+e>this.len)throw Zt(this,e);this.pos+=e}else do if(this.pos>=this.len)throw Zt(this);while(this.buf[this.pos++]&128);return this}skipType(e){switch(e){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(e=this.uint32()&7)!==4;)this.skipType(e);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${e} at offset ${this.pos}`)}return this}readLongVarint(){let e=new It(0,0),t=0;if(this.len-this.pos>4){for(;t<4;++t)if(e.lo=(e.lo|(this.buf[this.pos]&127)<<t*7)>>>0,this.buf[this.pos++]<128)return e;if(e.lo=(e.lo|(this.buf[this.pos]&127)<<28)>>>0,e.hi=(e.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return e;t=0}else{for(;t<3;++t){if(this.pos>=this.len)throw Zt(this);if(e.lo=(e.lo|(this.buf[this.pos]&127)<<t*7)>>>0,this.buf[this.pos++]<128)return e}return e.lo=(e.lo|(this.buf[this.pos++]&127)<<t*7)>>>0,e}if(this.len-this.pos>4){for(;t<5;++t)if(e.hi=(e.hi|(this.buf[this.pos]&127)<<t*7+3)>>>0,this.buf[this.pos++]<128)return e}else for(;t<5;++t){if(this.pos>=this.len)throw Zt(this);if(e.hi=(e.hi|(this.buf[this.pos]&127)<<t*7+3)>>>0,this.buf[this.pos++]<128)return e}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw Zt(this,8);let e=ka(this.buf,this.pos+=4),t=ka(this.buf,this.pos+=4);return new It(e,t)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let e=Ku(this.buf,this.pos);return this.pos+=yt(e),e}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function ju(r){return new Wu(r instanceof Uint8Array?r:r.subarray())}function Vt(r,e,t){let n=ju(r);return e.decode(n,void 0,t)}var Xu={};Be(Xu,{base10:()=>wb});var wb=vn({prefix:"9",name:"base10",alphabet:"0123456789"});var Zu={};Be(Zu,{base16:()=>Eb,base16upper:()=>xb});var Eb=ke({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),xb=ke({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Ju={};Be(Ju,{base2:()=>bb});var bb=ke({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Qu={};Be(Qu,{base256emoji:()=>Ib});var c0=Array.from("\u{1F680}\u{1FA90}\u2604\u{1F6F0}\u{1F30C}\u{1F311}\u{1F312}\u{1F313}\u{1F314}\u{1F315}\u{1F316}\u{1F317}\u{1F318}\u{1F30D}\u{1F30F}\u{1F30E}\u{1F409}\u2600\u{1F4BB}\u{1F5A5}\u{1F4BE}\u{1F4BF}\u{1F602}\u2764\u{1F60D}\u{1F923}\u{1F60A}\u{1F64F}\u{1F495}\u{1F62D}\u{1F618}\u{1F44D}\u{1F605}\u{1F44F}\u{1F601}\u{1F525}\u{1F970}\u{1F494}\u{1F496}\u{1F499}\u{1F622}\u{1F914}\u{1F606}\u{1F644}\u{1F4AA}\u{1F609}\u263A\u{1F44C}\u{1F917}\u{1F49C}\u{1F614}\u{1F60E}\u{1F607}\u{1F339}\u{1F926}\u{1F389}\u{1F49E}\u270C\u2728\u{1F937}\u{1F631}\u{1F60C}\u{1F338}\u{1F64C}\u{1F60B}\u{1F497}\u{1F49A}\u{1F60F}\u{1F49B}\u{1F642}\u{1F493}\u{1F929}\u{1F604}\u{1F600}\u{1F5A4}\u{1F603}\u{1F4AF}\u{1F648}\u{1F447}\u{1F3B6}\u{1F612}\u{1F92D}\u2763\u{1F61C}\u{1F48B}\u{1F440}\u{1F62A}\u{1F611}\u{1F4A5}\u{1F64B}\u{1F61E}\u{1F629}\u{1F621}\u{1F92A}\u{1F44A}\u{1F973}\u{1F625}\u{1F924}\u{1F449}\u{1F483}\u{1F633}\u270B\u{1F61A}\u{1F61D}\u{1F634}\u{1F31F}\u{1F62C}\u{1F643}\u{1F340}\u{1F337}\u{1F63B}\u{1F613}\u2B50\u2705\u{1F97A}\u{1F308}\u{1F608}\u{1F918}\u{1F4A6}\u2714\u{1F623}\u{1F3C3}\u{1F490}\u2639\u{1F38A}\u{1F498}\u{1F620}\u261D\u{1F615}\u{1F33A}\u{1F382}\u{1F33B}\u{1F610}\u{1F595}\u{1F49D}\u{1F64A}\u{1F639}\u{1F5E3}\u{1F4AB}\u{1F480}\u{1F451}\u{1F3B5}\u{1F91E}\u{1F61B}\u{1F534}\u{1F624}\u{1F33C}\u{1F62B}\u26BD\u{1F919}\u2615\u{1F3C6}\u{1F92B}\u{1F448}\u{1F62E}\u{1F646}\u{1F37B}\u{1F343}\u{1F436}\u{1F481}\u{1F632}\u{1F33F}\u{1F9E1}\u{1F381}\u26A1\u{1F31E}\u{1F388}\u274C\u270A\u{1F44B}\u{1F630}\u{1F928}\u{1F636}\u{1F91D}\u{1F6B6}\u{1F4B0}\u{1F353}\u{1F4A2}\u{1F91F}\u{1F641}\u{1F6A8}\u{1F4A8}\u{1F92C}\u2708\u{1F380}\u{1F37A}\u{1F913}\u{1F619}\u{1F49F}\u{1F331}\u{1F616}\u{1F476}\u{1F974}\u25B6\u27A1\u2753\u{1F48E}\u{1F4B8}\u2B07\u{1F628}\u{1F31A}\u{1F98B}\u{1F637}\u{1F57A}\u26A0\u{1F645}\u{1F61F}\u{1F635}\u{1F44E}\u{1F932}\u{1F920}\u{1F927}\u{1F4CC}\u{1F535}\u{1F485}\u{1F9D0}\u{1F43E}\u{1F352}\u{1F617}\u{1F911}\u{1F30A}\u{1F92F}\u{1F437}\u260E\u{1F4A7}\u{1F62F}\u{1F486}\u{1F446}\u{1F3A4}\u{1F647}\u{1F351}\u2744\u{1F334}\u{1F4A3}\u{1F438}\u{1F48C}\u{1F4CD}\u{1F940}\u{1F922}\u{1F445}\u{1F4A1}\u{1F4A9}\u{1F450}\u{1F4F8}\u{1F47B}\u{1F910}\u{1F92E}\u{1F3BC}\u{1F975}\u{1F6A9}\u{1F34E}\u{1F34A}\u{1F47C}\u{1F48D}\u{1F4E3}\u{1F942}"),vb=c0.reduce((r,e,t)=>(r[t]=e,r),[]),Ab=c0.reduce((r,e,t)=>(r[e.codePointAt(0)]=t,r),[]);function _b(r){return r.reduce((e,t)=>(e+=vb[t],e),"")}function Sb(r){let e=[];for(let t of r){let n=Ab[t.codePointAt(0)];if(n===void 0)throw new Error(`Non-base256emoji character: ${t}`);e.push(n)}return new Uint8Array(e)}var Ib=zi({prefix:"\u{1F680}",name:"base256emoji",encode:_b,decode:Sb});var ed={};Be(ed,{base36:()=>kn,base36upper:()=>Bb});var kn=vn({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Bb=vn({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var td={};Be(td,{base8:()=>kb});var kb=ke({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var rd={};Be(rd,{identity:()=>Rb});var Rb=zi({prefix:"\0",name:"identity",encode:r=>xu(r),decode:r=>Eu(r)});var JB=new TextEncoder,Tb=new TextDecoder;var Rn=512;function l0(r){return JSON.parse(Tb.decode(r))}var Mt={};Be(Mt,{code:()=>Ae,decode:()=>Lb,encode:()=>Cb,name:()=>Nb});var Nb="raw",Ae=85;function Cb(r){return Pt(r)}function Lb(r){return Pt(r)}var nd={};Be(nd,{identity:()=>et});var u0=0,Ub="identity",d0=Pt;function Db(r){return mr(u0,d0(r))}var et={code:u0,name:Ub,encode:d0,digest:Db};var Tn={...rd,...Ju,...td,...Xu,...Zu,...Su,...ed,...Iu,...Ou,...Qu},u8={...Lu,...nd};function h0(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}var f0=h0("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),id=h0("ascii","a",r=>{let e="a";for(let t=0;t<r.length;t++)e+=String.fromCharCode(r[t]);return e},r=>{r=r.substring(1);let e=mt(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),Ob={utf8:f0,"utf-8":f0,hex:Tn.base16,latin1:id,ascii:id,binary:id,...Tn},Ta=Ob;function V(r,e="utf8"){let t=Ta[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return(e==="utf8"||e==="utf-8")&&globalThis.Buffer!=null&&globalThis.Buffer.from!=null?In(globalThis.Buffer.from(r,"utf-8")):t.decoder.decode(`${t.prefix}${r}`)}function od(r){let e=r??8192,t=e>>>1,n,i=e;return function(s){if(s<1||s>t)return mt(s);i+s>e&&(n=mt(e),i=0);let a=n.subarray(i,i+=s);return i&7&&(i=(i|7)+1),a}}var mi=class{fn;len;next;val;constructor(e,t,n){this.fn=e,this.len=t,this.next=void 0,this.val=n}};function sd(){}var cd=class{head;tail;len;next;constructor(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}},Pb=od();function Fb(r){return globalThis.Buffer!=null?mt(r):Pb(r)}var ns=class{len;head;tail;states;constructor(){this.len=0,this.head=new mi(sd,0,0),this.tail=this.head,this.states=null}_push(e,t,n){return this.tail=this.tail.next=new mi(e,t,n),this.len+=t,this}uint32(e){return this.len+=(this.tail=this.tail.next=new ld((e=e>>>0)<128?1:e<16384?2:e<2097152?3:e<268435456?4:5,e)).len,this}int32(e){return e<0?this._push(Na,10,It.fromNumber(e)):this.uint32(e)}sint32(e){return this.uint32((e<<1^e>>31)>>>0)}uint64(e){let t=It.fromBigInt(e);return this._push(Na,t.length(),t)}uint64Number(e){return this._push(zu,yt(e),e)}uint64String(e){return this.uint64(BigInt(e))}int64(e){return this.uint64(e)}int64Number(e){return this.uint64Number(e)}int64String(e){return this.uint64String(e)}sint64(e){let t=It.fromBigInt(e).zzEncode();return this._push(Na,t.length(),t)}sint64Number(e){let t=It.fromNumber(e).zzEncode();return this._push(Na,t.length(),t)}sint64String(e){return this.sint64(BigInt(e))}bool(e){return this._push(ad,1,e?1:0)}fixed32(e){return this._push(rs,4,e>>>0)}sfixed32(e){return this.fixed32(e)}fixed64(e){let t=It.fromBigInt(e);return this._push(rs,4,t.lo)._push(rs,4,t.hi)}fixed64Number(e){let t=It.fromNumber(e);return this._push(rs,4,t.lo)._push(rs,4,t.hi)}fixed64String(e){return this.fixed64(BigInt(e))}sfixed64(e){return this.fixed64(e)}sfixed64Number(e){return this.fixed64Number(e)}sfixed64String(e){return this.fixed64String(e)}float(e){return this._push(e0,4,e)}double(e){return this._push(r0,8,e)}bytes(e){let t=e.length>>>0;return t===0?this._push(ad,1,0):this.uint32(t)._push(Mb,t,e)}string(e){let t=o0(e);return t!==0?this.uint32(t)._push(Yu,t,e):this._push(ad,1,0)}fork(){return this.states=new cd(this),this.head=this.tail=new mi(sd,0,0),this.len=0,this}reset(){return this.states!=null?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new mi(sd,0,0),this.len=0),this}ldelim(){let e=this.head,t=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=e.next,this.tail=t,this.len+=n),this}finish(){let e=this.head.next,t=Fb(this.len),n=0;for(;e!=null;)e.fn(e.val,t,n),n+=e.len,e=e.next;return t}};function ad(r,e,t){e[t]=r&255}function Vb(r,e,t){for(;r>127;)e[t++]=r&127|128,r>>>=7;e[t]=r}var ld=class extends mi{next;constructor(e,t){super(Vb,e,t),this.next=void 0}};function Na(r,e,t){for(;r.hi!==0;)e[t++]=r.lo&127|128,r.lo=(r.lo>>>7|r.hi<<25)>>>0,r.hi>>>=7;for(;r.lo>127;)e[t++]=r.lo&127|128,r.lo=r.lo>>>7;e[t++]=r.lo}function rs(r,e,t){e[t]=r&255,e[t+1]=r>>>8&255,e[t+2]=r>>>16&255,e[t+3]=r>>>24}function Mb(r,e,t){e.set(r,t)}globalThis.Buffer!=null&&(ns.prototype.bytes=function(r){let e=r.length>>>0;return this.uint32(e),e>0&&this._push(Hb,e,r),this},ns.prototype.string=function(r){let e=globalThis.Buffer.byteLength(r);return this.uint32(e),e>0&&this._push($b,e,r),this});function Hb(r,e,t){e.set(r,t)}function $b(r,e,t){r.length<40?Yu(r,e,t):e.utf8Write!=null?e.utf8Write(r,t):e.set(V(r),t)}function ud(){return new ns}function Ht(r,e){let t=ud();return e.encode(r,t,{lengthDelimited:!1}),t.finish()}var Zi;(function(r){r[r.VARINT=0]="VARINT",r[r.BIT64=1]="BIT64",r[r.LENGTH_DELIMITED=2]="LENGTH_DELIMITED",r[r.START_GROUP=3]="START_GROUP",r[r.END_GROUP=4]="END_GROUP",r[r.BIT32=5]="BIT32"})(Zi||(Zi={}));function Ca(r,e,t,n){return{name:r,type:e,encode:t,decode:n}}function yi(r){function e(i){if(r[i.toString()]==null)throw new Error("Invalid enum value");return r[i]}let t=function(o,s){let a=e(o);s.int32(a)},n=function(o){let s=o.int32();return e(s)};return Ca("enum",Zi.VARINT,t,n)}function $t(r,e){return Ca("message",Zi.LENGTH_DELIMITED,r,e)}function zb(r){return r[Symbol.asyncIterator]!=null}function Kb(r){if(zb(r))return(async()=>{for await(let e of r);})();for(let e of r);}var Jt=Kb;function ye(r,e){if(globalThis.Buffer!=null)return In(globalThis.Buffer.concat(r,e));e==null&&(e=r.reduce((i,o)=>i+o.length,0));let t=mt(e),n=0;for(let i of r)t.set(i,n),n+=i.length;return In(t)}var m0=Symbol.for("@achingbrain/uint8arraylist");function p0(r,e){if(e==null||e<0)throw new RangeError("index is out of bounds");let t=0;for(let n of r){let i=t+n.byteLength;if(e<i)return{buf:n,index:e-t};t=i}throw new RangeError("index is out of bounds")}function gr(r){return!!r?.[m0]}var zt=class r{bufs;length;[m0]=!0;constructor(...e){this.bufs=[],this.length=0,e.length>0&&this.appendAll(e)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...e){this.appendAll(e)}appendAll(e){let t=0;for(let n of e)if(n instanceof Uint8Array)t+=n.byteLength,this.bufs.push(n);else if(gr(n))t+=n.byteLength,this.bufs.push(...n.bufs);else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=t}prepend(...e){this.prependAll(e)}prependAll(e){let t=0;for(let n of e.reverse())if(n instanceof Uint8Array)t+=n.byteLength,this.bufs.unshift(n);else if(gr(n))t+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=t}get(e){let t=p0(this.bufs,e);return t.buf[t.index]}set(e,t){let n=p0(this.bufs,e);n.buf[n.index]=t}write(e,t=0){if(e instanceof Uint8Array)for(let n=0;n<e.length;n++)this.set(t+n,e[n]);else if(gr(e))for(let n=0;n<e.length;n++)this.set(t+n,e.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(e){if(e=Math.trunc(e),!(Number.isNaN(e)||e<=0)){if(e===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(e>=this.bufs[0].byteLength)e-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(e),this.length-=e;break}}}slice(e,t){let{bufs:n,length:i}=this._subList(e,t);return ye(n,i)}subarray(e,t){let{bufs:n,length:i}=this._subList(e,t);return n.length===1?n[0]:ye(n,i)}sublist(e,t){let{bufs:n,length:i}=this._subList(e,t),o=new r;return o.length=i,o.bufs=[...n],o}_subList(e,t){if(e=e??0,t=t??this.length,e<0&&(e=this.length+e),t<0&&(t=this.length+t),e<0||t>this.length)throw new RangeError("index is out of bounds");if(e===t)return{bufs:[],length:0};if(e===0&&t===this.length)return{bufs:this.bufs,length:this.length};let n=[],i=0;for(let o=0;o<this.bufs.length;o++){let s=this.bufs[o],a=i,c=a+s.byteLength;if(i=c,e>=c)continue;let u=e>=a&&e<c,l=t>a&&t<=c;if(u&&l){if(e===a&&t===c){n.push(s);break}let d=e-a;n.push(s.subarray(d,d+(t-e)));break}if(u){if(e===0){n.push(s);continue}n.push(s.subarray(e-a));continue}if(l){if(t===c){n.push(s);break}n.push(s.subarray(0,t-a));break}n.push(s)}return{bufs:n,length:t-e}}indexOf(e,t=0){if(!gr(e)&&!(e instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=e instanceof Uint8Array?e:e.subarray();if(t=Number(t??0),isNaN(t)&&(t=0),t<0&&(t=this.length+t),t<0&&(t=0),e.length===0)return t>this.length?this.length:t;let i=n.byteLength;if(i===0)throw new TypeError("search must be at least 1 byte long");let o=256,s=new Int32Array(o);for(let d=0;d<o;d++)s[d]=-1;for(let d=0;d<i;d++)s[n[d]]=d;let a=s,c=this.byteLength-n.byteLength,u=n.byteLength-1,l;for(let d=t;d<=c;d+=l){l=0;for(let p=u;p>=0;p--){let f=this.get(d+p);if(n[p]!==f){l=Math.max(1,p-a[f]);break}}if(l===0)return d}return-1}getInt8(e){let t=this.subarray(e,e+1);return new DataView(t.buffer,t.byteOffset,t.byteLength).getInt8(0)}setInt8(e,t){let n=mt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,t),this.write(n,e)}getInt16(e,t){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,t)}setInt16(e,t,n){let i=Mr(2);new DataView(i.buffer,i.byteOffset,i.byteLength).setInt16(0,t,n),this.write(i,e)}getInt32(e,t){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,t)}setInt32(e,t,n){let i=Mr(4);new DataView(i.buffer,i.byteOffset,i.byteLength).setInt32(0,t,n),this.write(i,e)}getBigInt64(e,t){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,t)}setBigInt64(e,t,n){let i=Mr(8);new DataView(i.buffer,i.byteOffset,i.byteLength).setBigInt64(0,t,n),this.write(i,e)}getUint8(e){let t=this.subarray(e,e+1);return new DataView(t.buffer,t.byteOffset,t.byteLength).getUint8(0)}setUint8(e,t){let n=mt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,t),this.write(n,e)}getUint16(e,t){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,t)}setUint16(e,t,n){let i=Mr(2);new DataView(i.buffer,i.byteOffset,i.byteLength).setUint16(0,t,n),this.write(i,e)}getUint32(e,t){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,t)}setUint32(e,t,n){let i=Mr(4);new DataView(i.buffer,i.byteOffset,i.byteLength).setUint32(0,t,n),this.write(i,e)}getBigUint64(e,t){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,t)}setBigUint64(e,t,n){let i=Mr(8);new DataView(i.buffer,i.byteOffset,i.byteLength).setBigUint64(0,t,n),this.write(i,e)}getFloat32(e,t){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,t)}setFloat32(e,t,n){let i=Mr(4);new DataView(i.buffer,i.byteOffset,i.byteLength).setFloat32(0,t,n),this.write(i,e)}getFloat64(e,t){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,t)}setFloat64(e,t,n){let i=Mr(8);new DataView(i.buffer,i.byteOffset,i.byteLength).setFloat64(0,t,n),this.write(i,e)}equals(e){if(e==null||!(e instanceof r)||e.bufs.length!==this.bufs.length)return!1;for(let t=0;t<this.bufs.length;t++)if(!he(this.bufs[t],e.bufs[t]))return!1;return!0}static fromUint8Arrays(e,t){let n=new r;return n.bufs=e,t==null&&(t=e.reduce((i,o)=>i+o.byteLength,0)),n.length=t,n}};function qb(r){return r[Symbol.asyncIterator]!=null}function Yb(r,e){if(qb(r))return async function*(){for await(let a of r)yield e(a)}();let t=Hi(r),{value:n,done:i}=t.next();if(i===!0)return function*(){}();let o=e(n);if(typeof o.then=="function")return async function*(){yield await o;for await(let a of t)yield e(a)}();let s=e;return function*(){yield o;for(let a of t)yield s(a)}()}var at=Yb;function _e(){let r={};return r.promise=new Promise((e,t)=>{r.resolve=e,r.reject=t}),r}var La=class{buffer;mask;top;btm;next;constructor(e){if(!(e>0)||e-1&e)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(e),this.mask=e-1,this.top=0,this.btm=0,this.next=null}push(e){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=e,this.top=this.top+1&this.mask,!0)}shift(){let e=this.buffer[this.btm];if(e!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,e}isEmpty(){return this.buffer[this.btm]===void 0}},Ji=class{size;hwm;head;tail;constructor(e={}){this.hwm=e.splitLimit??16,this.head=new La(this.hwm),this.tail=this.head,this.size=0}calculateSize(e){return e?.byteLength!=null?e.byteLength:1}push(e){if(e?.value!=null&&(this.size+=this.calculateSize(e.value)),!this.head.push(e)){let t=this.head;this.head=t.next=new La(2*this.head.buffer.length),this.head.push(e)}}shift(){let e=this.tail.shift();if(e===void 0&&this.tail.next!=null){let t=this.tail.next;this.tail.next=null,this.tail=t,e=this.tail.shift()}return e?.value!=null&&(this.size-=this.calculateSize(e.value)),e}isEmpty(){return this.head.isEmpty()}};var dd=class extends Error{type;code;constructor(e,t){super(e??"The operation was aborted"),this.type="aborted",this.code=t??"ABORT_ERR"}};function Kt(r={}){return Wb(t=>{let n=t.shift();if(n==null)return{done:!0};if(n.error!=null)throw n.error;return{done:n.done===!0,value:n.value}},r)}function Wb(r,e){e=e??{};let t=e.onEnd,n=new Ji,i,o,s,a=_e(),c=async()=>{try{return n.isEmpty()?s?{done:!0}:await new Promise((y,g)=>{o=E=>{o=null,n.push(E);try{y(r(n))}catch(x){g(x)}return i}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=_e()})}},u=y=>o!=null?o(y):(n.push(y),i),l=y=>(n=new Ji,o!=null?o({error:y}):(n.push({error:y}),i)),d=y=>{if(s)return i;if(e?.objectMode!==!0&&y?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return u({done:!1,value:y})},p=y=>s?i:(s=!0,y!=null?l(y):u({done:!0})),f=()=>(n=new Ji,p(),{done:!0}),h=y=>(p(y),{done:!0});if(i={[Symbol.asyncIterator](){return this},next:c,return:f,throw:h,push:d,end:p,get readableLength(){return n.size},onEmpty:async y=>{let g=y?.signal;if(g?.throwIfAborted(),n.isEmpty())return;let E,x;g!=null&&(E=new Promise((_,S)=>{x=()=>{S(new dd)},g.addEventListener("abort",x)}));try{await Promise.race([a.promise,E])}finally{x!=null&&g!=null&&g?.removeEventListener("abort",x)}}},t==null)return i;let m=i;return i={[Symbol.asyncIterator](){return this},next(){return m.next()},throw(y){return m.throw(y),t!=null&&(t(y),t=void 0),{done:!0}},return(){return m.return(),t!=null&&(t(),t=void 0),{done:!0}},push:d,end(y){return m.end(y),t!=null&&(t(y),t=void 0),i},get readableLength(){return m.readableLength},onEmpty:y=>m.onEmpty(y)},i}function jb(r){return r[Symbol.asyncIterator]!=null}function Xb(...r){let e=[];for(let t of r)jb(t)||e.push(t);return e.length===r.length?function*(){for(let t of e)yield*t}():async function*(){let t=Kt({objectMode:!0});Promise.resolve().then(async()=>{try{await Promise.all(r.map(async n=>{for await(let i of n)t.push(i)})),t.end()}catch(n){t.end(n)}}),yield*t}()}var Hr=Xb;function gt(r,...e){if(r==null)throw new Error("Empty pipeline");if(fd(r)){let n=r;r=()=>n.source}else if(E0(r)||w0(r)){let n=r;r=()=>n}let t=[r,...e];if(t.length>1&&fd(t[t.length-1])&&(t[t.length-1]=t[t.length-1].sink),t.length>2)for(let n=1;n<t.length-1;n++)fd(t[n])&&(t[n]=Jb(t[n]));return Zb(...t)}var Zb=(...r)=>{let e;for(;r.length>0;)e=r.shift()(e);return e},w0=r=>r?.[Symbol.asyncIterator]!=null,E0=r=>r?.[Symbol.iterator]!=null,fd=r=>r==null?!1:r.sink!=null&&r.source!=null,Jb=r=>e=>{let t=r.sink(e);if(t?.then!=null){let n=Kt({objectMode:!0});t.then(()=>{n.end()},s=>{n.end(s)});let i,o=r.source;if(w0(o))i=async function*(){yield*o,n.end()};else if(E0(o))i=function*(){yield*o,n.end()};else throw new Error("Unknown duplex source type - must be Iterable or AsyncIterable");return Hr(n,i())}return r.source};function Qb(r){return r[Symbol.asyncIterator]!=null}function e3(r,e){return Qb(r)?async function*(){let t=0;if(!(e<1)){for await(let n of r)if(yield n,t++,t===e)return}}():function*(){let t=0;if(!(e<1)){for(let n of r)if(yield n,t++,t===e)return}}()}var Ua=e3;var M=class extends Event{constructor(e,t){super(e),this.detail=t}};function Z(r,e="utf8"){let t=Ta[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return(e==="utf8"||e==="utf-8")&&globalThis.Buffer!=null&&globalThis.Buffer.from!=null?globalThis.Buffer.from(r.buffer,r.byteOffset,r.byteLength).toString("utf8"):t.encoder.encode(r).substring(1)}var Da=class{url;#e=0;#t=0;#r=0;#s=0;constructor(e){this.url=e instanceof URL?e:new URL(e)}async getRawBlock(e,t){let n=this.url;if(n.pathname=`/ipfs/${e.toString()}`,n.search="?format=raw",t?.aborted===!0)throw new Error(`Signal to fetch raw block for CID ${e} from gateway ${this.url} was aborted prior to fetch`);try{this.#e++;let i=await fetch(n.toString(),{signal:t,headers:{Accept:"application/vnd.ipld.raw"},cache:"force-cache"});if(!i.ok)throw this.#t++,new Error(`unable to fetch raw block for CID ${e} from gateway ${this.url}`);return this.#s++,new Uint8Array(await i.arrayBuffer())}catch{throw t?.aborted===!0?new Error(`fetching raw block for CID ${e} from gateway ${this.url} was aborted`):(this.#t++,new Error(`unable to fetch raw block for CID ${e}`))}}reliability(){return this.#e===0?1:this.#r>0?-1/0:this.#s/(this.#e+this.#t*3)}incrementInvalidBlocks(){this.#r++}};var Oa=class{gateways;log;constructor(e,t={}){this.log=e.logger.forComponent("helia:trustless-gateway-block-broker"),this.gateways=(t.gateways??x0).map(n=>new Da(n))}async retrieve(e,t={}){let n=this.gateways.sort((o,s)=>s.reliability()-o.reliability()),i=[];for(let o of n){this.log("getting block for %c from %s",e,o.url);try{let s=await o.getRawBlock(e,t.signal);this.log.trace("got block for %c from %s",e,o.url);try{await t.validateFn?.(s)}catch(a){throw this.log.error("failed to validate block for %c from %s",e,o.url,a),o.incrementInvalidBlocks(),new Error(`unable to validate block for CID ${e} from gateway ${o.url}`)}return s}catch(s){if(this.log.error("failed to get block for %c from %s",e,o.url,s),s instanceof Error?i.push(s):i.push(new Error(`unable to fetch raw block for CID ${e} from gateway ${o.url}`)),t.signal?.aborted===!0){this.log.trace("request aborted while fetching raw block for CID %c from gateway %s",e,o.url);break}}}throw new AggregateError(i,`unable to fetch raw block for CID ${e} from any gateway`)}};var x0=["https://trustless-gateway.link","https://cloudflare-ipfs.com","https://4everland.io"];function is(r={}){return e=>new Oa(e,r)}var t3=Symbol.for("nodejs.util.inspect.custom"),b0=Object.values(Tn).map(r=>r.decoder).reduce((r,e)=>r.or(e),Tn.identity.decoder),v0=114,hd=36,pd=37,os=class{type;multihash;privateKey;publicKey;string;constructor(e){this.type=e.type,this.multihash=e.multihash,this.privateKey=e.privateKey,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[Ru]=!0;toString(){return this.string==null&&(this.string=Ne.encode(this.multihash.bytes).slice(1)),this.string}toCID(){return F.createV1(v0,this.multihash)}toBytes(){return this.multihash.bytes}toJSON(){return this.toString()}equals(e){if(e==null)return!1;if(e instanceof Uint8Array)return he(this.multihash.bytes,e);if(typeof e=="string")return Bt(e).equals(this);if(e?.multihash?.bytes!=null)return he(this.multihash.bytes,e.multihash.bytes);throw new Error("not valid Id")}[t3](){return`PeerId(${this.toString()})`}},Qi=class extends os{type="RSA";publicKey;constructor(e){super({...e,type:"RSA"}),this.publicKey=e.publicKey}},eo=class extends os{type="Ed25519";publicKey;constructor(e){super({...e,type:"Ed25519"}),this.publicKey=e.multihash.digest}},to=class extends os{type="secp256k1";publicKey;constructor(e){super({...e,type:"secp256k1"}),this.publicKey=e.multihash.digest}};function Bt(r,e){if(e=e??b0,r.charAt(0)==="1"||r.charAt(0)==="Q"){let t=st(Ne.decode(`z${r}`));return r.startsWith("12D")?new eo({multihash:t}):r.startsWith("16U")?new to({multihash:t}):new Qi({multihash:t})}return ss(b0.decode(r))}function ss(r){try{let e=st(r);if(e.code===et.code){if(e.digest.length===hd)return new eo({multihash:e});if(e.digest.length===pd)return new to({multihash:e})}if(e.code===fe.code)return new Qi({multihash:e})}catch{return r3(F.decode(r))}throw new Error("Supplied PeerID CID is invalid")}function r3(r){if(r==null||r.multihash==null||r.version==null||r.version===1&&r.code!==v0)throw new Error("Supplied PeerID CID is invalid");let e=r.multihash;if(e.code===fe.code)return new Qi({multihash:r.multihash});if(e.code===et.code){if(e.digest.length===hd)return new eo({multihash:r.multihash});if(e.digest.length===pd)return new to({multihash:r.multihash})}throw new Error("Supplied PeerID CID is invalid")}async function A0(r,e){return r.length===hd?new eo({multihash:mr(et.code,r),privateKey:e}):r.length===pd?new to({multihash:mr(et.code,r),privateKey:e}):new Qi({multihash:await fe.digest(r),publicKey:r,privateKey:e})}var Pa=class{index=0;input="";new(e){return this.index=0,this.input=e,this}readAtomically(e){let t=this.index,n=e();return n===void 0&&(this.index=t),n}parseWith(e){let t=e();if(this.index===this.input.length)return t}peekChar(){if(!(this.index>=this.input.length))return this.input[this.index]}readChar(){if(!(this.index>=this.input.length))return this.input[this.index++]}readGivenChar(e){return this.readAtomically(()=>{let t=this.readChar();if(t===e)return t})}readSeparator(e,t,n){return this.readAtomically(()=>{if(!(t>0&&this.readGivenChar(e)===void 0))return n()})}readNumber(e,t,n,i){return this.readAtomically(()=>{let o=0,s=0,a=this.peekChar();if(a===void 0)return;let c=a==="0",u=2**(8*i)-1;for(;;){let l=this.readAtomically(()=>{let d=this.readChar();if(d===void 0)return;let p=Number.parseInt(d,e);if(!Number.isNaN(p))return p});if(l===void 0)break;if(o*=e,o+=l,o>u||(s+=1,t!==void 0&&s>t))return}if(s!==0)return!n&&c&&s>1?void 0:o})}readIPv4Addr(){return this.readAtomically(()=>{let e=new Uint8Array(4);for(let t=0;t<e.length;t++){let n=this.readSeparator(".",t,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;e[t]=n}return e})}readIPv6Addr(){let e=t=>{for(let n=0;n<t.length/2;n++){let i=n*2;if(n<t.length-3){let s=this.readSeparator(":",n,()=>this.readIPv4Addr());if(s!==void 0)return t[i]=s[0],t[i+1]=s[1],t[i+2]=s[2],t[i+3]=s[3],[i+4,!0]}let o=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(o===void 0)return[i,!1];t[i]=o>>8,t[i+1]=o&255}return[t.length,!1]};return this.readAtomically(()=>{let t=new Uint8Array(16),[n,i]=e(t);if(n===16)return t;if(i||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let o=new Uint8Array(14),s=16-(n+2),[a]=e(o.subarray(0,s));return t.set(o.subarray(0,a),16-a),t})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var _0=45,n3=15,ro=new Pa;function md(r){if(!(r.length>n3))return ro.new(r).parseWith(()=>ro.readIPv4Addr())}function yd(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>_0))return ro.new(r).parseWith(()=>ro.readIPv6Addr())}function Fa(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>_0))return ro.new(r).parseWith(()=>ro.readIPAddr())}var M5=parseInt("0xFFFF",16),H5=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function B0(r){return!!md(r)}function k0(r){return!!yd(r)}function Va(r){return!!Fa(r)}var R0=B0,c3=k0,gd=function(r){let e=0;if(r=r.toString().trim(),R0(r)){let t=new Uint8Array(e+4);return r.split(/\./g).forEach(n=>{t[e++]=parseInt(n,10)&255}),t}if(c3(r)){let t=r.split(":",8),n;for(n=0;n<t.length;n++){let o=R0(t[n]),s;o&&(s=gd(t[n]),t[n]=Z(s.slice(0,2),"base16")),s!=null&&++n<8&&t.splice(n,0,Z(s.slice(2,4),"base16"))}if(t[0]==="")for(;t.length<8;)t.unshift("0");else if(t[t.length-1]==="")for(;t.length<8;)t.push("0");else if(t.length<8){for(n=0;n<t.length&&t[n]!=="";n++);let o=[n,1];for(n=9-t.length;n>0;n--)o.push("0");t.splice.apply(t,o)}let i=new Uint8Array(e+16);for(n=0;n<t.length;n++){let o=parseInt(t[n],16);i[e++]=o>>8&255,i[e++]=o&255}return i}throw new Error("invalid ip address")},T0=function(r,e=0,t){e=~~e,t=t??r.length-e;let n=new DataView(r.buffer);if(t===4){let i=[];for(let o=0;o<t;o++)i.push(r[e+o]);return i.join(".")}if(t===16){let i=[];for(let o=0;o<t;o+=2)i.push(n.getUint16(e+o).toString(16));return i.join(":").replace(/(^|:)0(:0)*:0(:|$)/,"$1::$3").replace(/:{3,4}/,"::")}return""};var no={},wd={},u3=[[4,32,"ip4"],[6,16,"tcp"],[33,16,"dccp"],[41,128,"ip6"],[42,-1,"ip6zone"],[43,8,"ipcidr"],[53,-1,"dns",!0],[54,-1,"dns4",!0],[55,-1,"dns6",!0],[56,-1,"dnsaddr",!0],[132,16,"sctp"],[273,16,"udp"],[275,0,"p2p-webrtc-star"],[276,0,"p2p-webrtc-direct"],[277,0,"p2p-stardust"],[280,0,"webrtc-direct"],[281,0,"webrtc"],[290,0,"p2p-circuit"],[301,0,"udt"],[302,0,"utp"],[400,-1,"unix",!1,!0],[421,-1,"ipfs"],[421,-1,"p2p"],[443,0,"https"],[444,96,"onion"],[445,296,"onion3"],[446,-1,"garlic64"],[448,0,"tls"],[449,-1,"sni"],[460,0,"quic"],[461,0,"quic-v1"],[465,0,"webtransport"],[466,-1,"certhash"],[477,0,"ws"],[478,0,"wss"],[479,0,"p2p-websocket-star"],[480,0,"http"],[777,-1,"memory"]];u3.forEach(r=>{let e=d3(...r);wd[e.code]=e,no[e.name]=e});function d3(r,e,t,n,i){return{code:r,size:e,name:t,resolvable:!!n,path:!!i}}function we(r){if(typeof r=="number"){if(wd[r]!=null)return wd[r];throw new Error(`no protocol with code: ${r}`)}else if(typeof r=="string"){if(no[r]!=null)return no[r];throw new Error(`no protocol with name: ${r}`)}throw new Error(`invalid protocol id type: ${typeof r}`)}var _k=we("ip4"),Sk=we("ip6"),Ik=we("ipcidr");function xd(r,e){switch(we(r).code){case 4:case 41:return h3(e);case 42:return L0(e);case 6:case 273:case 33:case 132:return D0(e).toString();case 53:case 54:case 55:case 56:case 400:case 449:case 777:return L0(e);case 421:return g3(e);case 444:return U0(e);case 445:return U0(e);case 466:return y3(e);default:return Z(e,"base16")}}function bd(r,e){switch(we(r).code){case 4:return N0(e);case 41:return N0(e);case 42:return C0(e);case 6:case 273:case 33:case 132:return vd(parseInt(e,10));case 53:case 54:case 55:case 56:case 400:case 449:case 777:return C0(e);case 421:return p3(e);case 444:return w3(e);case 445:return E3(e);case 466:return m3(e);default:return V(e,"base16")}}var Ed=Object.values(Tn).map(r=>r.decoder),f3=function(){let r=Ed[0].or(Ed[1]);return Ed.slice(2).forEach(e=>r=r.or(e)),r}();function N0(r){if(!Va(r))throw new Error("invalid ip address");return gd(r)}function h3(r){let e=T0(r,0,r.length);if(e==null)throw new Error("ipBuff is required");if(!Va(e))throw new Error("invalid ip address");return e}function vd(r){let e=new ArrayBuffer(2);return new DataView(e).setUint16(0,r),new Uint8Array(e)}function D0(r){return new DataView(r.buffer).getUint16(r.byteOffset)}function C0(r){let e=V(r),t=Uint8Array.from(Xi(e.length));return ye([t,e],t.length+e.length)}function L0(r){let e=hi(r);if(r=r.slice(yt(e)),r.length!==e)throw new Error("inconsistent lengths");return Z(r)}function p3(r){let e;r[0]==="Q"||r[0]==="1"?e=st(Ne.decode(`z${r}`)).bytes:e=F.parse(r).multihash.bytes;let t=Uint8Array.from(Xi(e.length));return ye([t,e],t.length+e.length)}function m3(r){let e=f3.decode(r),t=Uint8Array.from(Xi(e.length));return ye([t,e],t.length+e.length)}function y3(r){let e=hi(r),t=r.slice(yt(e));if(t.length!==e)throw new Error("inconsistent lengths");return"u"+Z(t,"base64url")}function g3(r){let e=hi(r),t=r.slice(yt(e));if(t.length!==e)throw new Error("inconsistent lengths");return Z(t,"base58btc")}function w3(r){let e=r.split(":");if(e.length!==2)throw new Error(`failed to parse onion addr: ["'${e.join('", "')}'"]' does not contain a port number`);if(e[0].length!==16)throw new Error(`failed to parse onion addr: ${e[0]} not a Tor onion address.`);let t=qe.decode("b"+e[0]),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let i=vd(n);return ye([t,i],t.length+i.length)}function E3(r){let e=r.split(":");if(e.length!==2)throw new Error(`failed to parse onion addr: ["'${e.join('", "')}'"]' does not contain a port number`);if(e[0].length!==56)throw new Error(`failed to parse onion addr: ${e[0]} not a Tor onion3 address.`);let t=qe.decode(`b${e[0]}`),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let i=vd(n);return ye([t,i],t.length+i.length)}function U0(r){let e=r.slice(0,r.length-2),t=r.slice(r.length-2),n=Z(e,"base32"),i=D0(t);return`${n}:${i}`}function O0(r){r=Ad(r);let e=[],t=[],n=null,i=r.split("/").slice(1);if(i.length===1&&i[0]==="")return{bytes:new Uint8Array,string:"/",tuples:[],stringTuples:[],path:null};for(let o=0;o<i.length;o++){let s=i[o],a=we(s);if(a.size===0){e.push([a.code]),t.push([a.code]);continue}if(o++,o>=i.length)throw F0("invalid address: "+r);if(a.path===!0){n=Ad(i.slice(o).join("/")),e.push([a.code,bd(a.code,n)]),t.push([a.code,n]);break}let c=bd(a.code,i[o]);e.push([a.code,c]),t.push([a.code,xd(a.code,c)])}return{string:P0(t),bytes:Sd(e),tuples:e,stringTuples:t,path:n}}function _d(r){let e=[],t=[],n=null,i=0;for(;i<r.length;){let o=hi(r,i),s=yt(o),a=we(o),c=x3(a,r.slice(i+s));if(c===0){e.push([o]),t.push([o]),i+=s;continue}let u=r.slice(i+s,i+s+c);if(i+=c+s,i>r.length)throw F0("Invalid address Uint8Array: "+Z(r,"base16"));e.push([o,u]);let l=xd(o,u);if(t.push([o,l]),a.path===!0){n=l;break}}return{bytes:Uint8Array.from(r),string:P0(t),tuples:e,stringTuples:t,path:n}}function P0(r){let e=[];return r.map(t=>{let n=we(t[0]);return e.push(n.name),t.length>1&&t[1]!=null&&e.push(t[1]),null}),Ad(e.join("/"))}function Sd(r){return ye(r.map(e=>{let t=we(e[0]),n=Uint8Array.from(Xi(t.code));return e.length>1&&e[1]!=null&&(n=ye([n,e[1]])),n}))}function x3(r,e){if(r.size>0)return r.size/8;if(r.size===0)return 0;{let t=hi(e instanceof Uint8Array?e:Uint8Array.from(e));return t+yt(t)}}function Ad(r){return"/"+r.trim().split("/").filter(e=>e).join("/")}function F0(r){return new Error("Error parsing address: "+r)}var b3=Symbol.for("nodejs.util.inspect.custom"),Id=Symbol.for("@multiformats/js-multiaddr/multiaddr"),v3=[we("dns").code,we("dns4").code,we("dns6").code,we("dnsaddr").code],Ma=class r{bytes;#e;#t;#r;#s;[Id]=!0;constructor(e){e==null&&(e="");let t;if(e instanceof Uint8Array)t=_d(e);else if(typeof e=="string"){if(e.length>0&&e.charAt(0)!=="/")throw new Error(`multiaddr "${e}" must start with a "/"`);t=O0(e)}else if(M0(e))t=_d(e.bytes);else throw new Error("addr must be a string, Buffer, or another Multiaddr");this.bytes=t.bytes,this.#e=t.string,this.#t=t.tuples,this.#r=t.stringTuples,this.#s=t.path}toString(){return this.#e}toJSON(){return this.toString()}toOptions(){let e,t,n,i,o="",s=we("tcp"),a=we("udp"),c=we("ip4"),u=we("ip6"),l=we("dns6"),d=we("ip6zone");for(let[f,h]of this.stringTuples())f===d.code&&(o=`%${h??""}`),v3.includes(f)&&(t=s.name,i=443,n=`${h??""}${o}`,e=f===l.code?6:4),(f===s.code||f===a.code)&&(t=we(f).name,i=parseInt(h??"")),(f===c.code||f===u.code)&&(t=we(f).name,n=`${h??""}${o}`,e=f===u.code?6:4);if(e==null||t==null||n==null||i==null)throw new Error('multiaddr must have a valid format: "/{ip4, ip6, dns4, dns6, dnsaddr}/{address}/{tcp, udp}/{port}".');return{family:e,host:n,transport:t,port:i}}protos(){return this.#t.map(([e])=>Object.assign({},we(e)))}protoCodes(){return this.#t.map(([e])=>e)}protoNames(){return this.#t.map(([e])=>we(e).name)}tuples(){return this.#t}stringTuples(){return this.#r}encapsulate(e){return e=new r(e),new r(this.toString()+e.toString())}decapsulate(e){let t=e.toString(),n=this.toString(),i=n.lastIndexOf(t);if(i<0)throw new Error(`Address ${this.toString()} does not contain subaddress: ${e.toString()}`);return new r(n.slice(0,i))}decapsulateCode(e){let t=this.tuples();for(let n=t.length-1;n>=0;n--)if(t[n][0]===e)return new r(Sd(t.slice(0,n)));return this}getPeerId(){try{let e=[];this.stringTuples().forEach(([n,i])=>{n===no.p2p.code&&e.push([n,i]),n===no["p2p-circuit"].code&&(e=[])});let t=e.pop();if(t?.[1]!=null){let n=t[1];return n[0]==="Q"||n[0]==="1"?Z(Ne.decode(`z${n}`),"base58btc"):Z(F.parse(n).multihash.bytes,"base58btc")}return null}catch{return null}}getPath(){return this.#s}equals(e){return he(this.bytes,e.bytes)}async resolve(e){let t=this.protos().find(o=>o.resolvable);if(t==null)return[this];let n=V0.get(t.name);if(n==null)throw new O(`no available resolver for ${t.name}`,"ERR_NO_AVAILABLE_RESOLVER");return(await n(this,e)).map(o=>new r(o))}nodeAddress(){let e=this.toOptions();if(e.transport!=="tcp"&&e.transport!=="udp")throw new Error(`multiaddr must have a valid format - no protocol with name: "${e.transport}". Must have a valid transport protocol: "{tcp, udp}"`);return{family:e.family,address:e.host,port:e.port}}isThinWaistAddress(e){let t=(e??this).protos();return!(t.length!==2||t[0].code!==4&&t[0].code!==41||t[1].code!==6&&t[1].code!==273)}[b3](){return`Multiaddr(${this.#e})`}};var V0=new Map;function M0(r){return!!r?.[Id]}function Bd(r){return new Ma(r)}async function*Ha(r,e={}){let t=r.getReader();try{for(;;){let n=await t.read();if(n.done)return;yield n.value}}finally{e.preventCancel!==!0&&await t.cancel(),t.releaseLock()}}var Gd={};Be(Gd,{Ed25519PrivateKey:()=>xi,Ed25519PublicKey:()=>ls,generateKeyPair:()=>L6,generateKeyPairFromSeed:()=>f1,unmarshalEd25519PrivateKey:()=>N6,unmarshalEd25519PublicKey:()=>C6});function Gt(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}function io(r){if(!Number.isSafeInteger(r)||r<0)throw new Error(`Wrong positive integer: ${r}`)}function A3(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}function kd(r,...e){if(!A3(r))throw new Error("Expected Uint8Array");if(e.length>0&&!e.includes(r.length))throw new Error(`Expected Uint8Array of length ${e}, not of length=${r.length}`)}function $a(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");io(r.outputLen),io(r.blockLen)}function oo(r,e=!0){if(r.destroyed)throw new Error("Hash instance has been destroyed");if(e&&r.finished)throw new Error("Hash#digest() has already been called")}function H0(r,e){kd(r);let t=e.outputLen;if(r.length<t)throw new Error(`digestInto() expects output buffer of length at least ${t}`)}var za=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function $0(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}var ao=r=>new DataView(r.buffer,r.byteOffset,r.byteLength),Qt=(r,e)=>r<<32-e|r>>>e,_3=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;if(!_3)throw new Error("Non little-endian hardware is not supported");var S3=async()=>{};async function z0(r,e,t){let n=Date.now();for(let i=0;i<r;i++){t(i);let o=Date.now()-n;o>=0&&o<e||(await S3(),n+=o)}}function Rd(r){if(typeof r!="string")throw new Error(`utf8ToBytes expected string, got ${typeof r}`);return new Uint8Array(new TextEncoder().encode(r))}function Nn(r){if(typeof r=="string"&&(r=Rd(r)),!$0(r))throw new Error(`expected Uint8Array, got ${typeof r}`);return r}function Ka(...r){let e=0;for(let n=0;n<r.length;n++){let i=r[n];if(!$0(i))throw new Error("Uint8Array expected");e+=i.length}let t=new Uint8Array(e);for(let n=0,i=0;n<r.length;n++){let o=r[n];t.set(o,i),i+=o.length}return t}var so=class{clone(){return this._cloneInto()}},I3={}.toString;function K0(r,e){if(e!==void 0&&I3.call(e)!=="[object Object]")throw new Error("Options should be object or undefined");return Object.assign(r,e)}function Ga(r){let e=n=>r().update(Nn(n)).digest(),t=r();return e.outputLen=t.outputLen,e.blockLen=t.blockLen,e.create=()=>r(),e}function co(r=32){if(za&&typeof za.getRandomValues=="function")return za.getRandomValues(new Uint8Array(r));throw new Error("crypto.getRandomValues must be defined")}function B3(r,e,t,n){if(typeof r.setBigUint64=="function")return r.setBigUint64(e,t,n);let i=BigInt(32),o=BigInt(4294967295),s=Number(t>>i&o),a=Number(t&o),c=n?4:0,u=n?0:4;r.setUint32(e+c,s,n),r.setUint32(e+u,a,n)}var lo=class extends so{constructor(e,t,n,i){super(),this.blockLen=e,this.outputLen=t,this.padOffset=n,this.isLE=i,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(e),this.view=ao(this.buffer)}update(e){oo(this);let{view:t,buffer:n,blockLen:i}=this;e=Nn(e);let o=e.length;for(let s=0;s<o;){let a=Math.min(i-this.pos,o-s);if(a===i){let c=ao(e);for(;i<=o-s;s+=i)this.process(c,s);continue}n.set(e.subarray(s,s+a),this.pos),this.pos+=a,s+=a,this.pos===i&&(this.process(t,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){oo(this),H0(e,this),this.finished=!0;let{buffer:t,view:n,blockLen:i,isLE:o}=this,{pos:s}=this;t[s++]=128,this.buffer.subarray(s).fill(0),this.padOffset>i-s&&(this.process(n,0),s=0);for(let d=s;d<i;d++)t[d]=0;B3(n,i-8,BigInt(this.length*8),o),this.process(n,0);let a=ao(e),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let u=c/4,l=this.get();if(u>l.length)throw new Error("_sha2: outputLen bigger than state");for(let d=0;d<u;d++)a.setUint32(4*d,l[d],o)}digest(){let{buffer:e,outputLen:t}=this;this.digestInto(e);let n=e.slice(0,t);return this.destroy(),n}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());let{blockLen:t,buffer:n,length:i,finished:o,destroyed:s,pos:a}=this;return e.length=i,e.pos=a,e.finished=o,e.destroyed=s,i%t&&e.buffer.set(n),e}};var qa=BigInt(4294967295),Td=BigInt(32);function G0(r,e=!1){return e?{h:Number(r&qa),l:Number(r>>Td&qa)}:{h:Number(r>>Td&qa)|0,l:Number(r&qa)|0}}function k3(r,e=!1){let t=new Uint32Array(r.length),n=new Uint32Array(r.length);for(let i=0;i<r.length;i++){let{h:o,l:s}=G0(r[i],e);[t[i],n[i]]=[o,s]}return[t,n]}var R3=(r,e)=>BigInt(r>>>0)<<Td|BigInt(e>>>0),T3=(r,e,t)=>r>>>t,N3=(r,e,t)=>r<<32-t|e>>>t,C3=(r,e,t)=>r>>>t|e<<32-t,L3=(r,e,t)=>r<<32-t|e>>>t,U3=(r,e,t)=>r<<64-t|e>>>t-32,D3=(r,e,t)=>r>>>t-32|e<<64-t,O3=(r,e)=>e,P3=(r,e)=>r,F3=(r,e,t)=>r<<t|e>>>32-t,V3=(r,e,t)=>e<<t|r>>>32-t,M3=(r,e,t)=>e<<t-32|r>>>64-t,H3=(r,e,t)=>r<<t-32|e>>>64-t;function $3(r,e,t,n){let i=(e>>>0)+(n>>>0);return{h:r+t+(i/2**32|0)|0,l:i|0}}var z3=(r,e,t)=>(r>>>0)+(e>>>0)+(t>>>0),K3=(r,e,t,n)=>e+t+n+(r/2**32|0)|0,G3=(r,e,t,n)=>(r>>>0)+(e>>>0)+(t>>>0)+(n>>>0),q3=(r,e,t,n,i)=>e+t+n+i+(r/2**32|0)|0,Y3=(r,e,t,n,i)=>(r>>>0)+(e>>>0)+(t>>>0)+(n>>>0)+(i>>>0),W3=(r,e,t,n,i,o)=>e+t+n+i+o+(r/2**32|0)|0;var j3={fromBig:G0,split:k3,toBig:R3,shrSH:T3,shrSL:N3,rotrSH:C3,rotrSL:L3,rotrBH:U3,rotrBL:D3,rotr32H:O3,rotr32L:P3,rotlSH:F3,rotlSL:V3,rotlBH:M3,rotlBL:H3,add:$3,add3L:z3,add3H:K3,add4L:G3,add4H:q3,add5H:W3,add5L:Y3},ee=j3;var[X3,Z3]=ee.split(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(r=>BigInt(r))),Cn=new Uint32Array(80),Ln=new Uint32Array(80),Nd=class extends lo{constructor(){super(128,64,16,!1),this.Ah=1779033703,this.Al=-205731576,this.Bh=-1150833019,this.Bl=-2067093701,this.Ch=1013904242,this.Cl=-23791573,this.Dh=-1521486534,this.Dl=1595750129,this.Eh=1359893119,this.El=-1377402159,this.Fh=-1694144372,this.Fl=725511199,this.Gh=528734635,this.Gl=-79577749,this.Hh=1541459225,this.Hl=327033209}get(){let{Ah:e,Al:t,Bh:n,Bl:i,Ch:o,Cl:s,Dh:a,Dl:c,Eh:u,El:l,Fh:d,Fl:p,Gh:f,Gl:h,Hh:m,Hl:y}=this;return[e,t,n,i,o,s,a,c,u,l,d,p,f,h,m,y]}set(e,t,n,i,o,s,a,c,u,l,d,p,f,h,m,y){this.Ah=e|0,this.Al=t|0,this.Bh=n|0,this.Bl=i|0,this.Ch=o|0,this.Cl=s|0,this.Dh=a|0,this.Dl=c|0,this.Eh=u|0,this.El=l|0,this.Fh=d|0,this.Fl=p|0,this.Gh=f|0,this.Gl=h|0,this.Hh=m|0,this.Hl=y|0}process(e,t){for(let x=0;x<16;x++,t+=4)Cn[x]=e.getUint32(t),Ln[x]=e.getUint32(t+=4);for(let x=16;x<80;x++){let _=Cn[x-15]|0,S=Ln[x-15]|0,A=ee.rotrSH(_,S,1)^ee.rotrSH(_,S,8)^ee.shrSH(_,S,7),v=ee.rotrSL(_,S,1)^ee.rotrSL(_,S,8)^ee.shrSL(_,S,7),b=Cn[x-2]|0,T=Ln[x-2]|0,C=ee.rotrSH(b,T,19)^ee.rotrBH(b,T,61)^ee.shrSH(b,T,6),N=ee.rotrSL(b,T,19)^ee.rotrBL(b,T,61)^ee.shrSL(b,T,6),$=ee.add4L(v,N,Ln[x-7],Ln[x-16]),D=ee.add4H($,A,C,Cn[x-7],Cn[x-16]);Cn[x]=D|0,Ln[x]=$|0}let{Ah:n,Al:i,Bh:o,Bl:s,Ch:a,Cl:c,Dh:u,Dl:l,Eh:d,El:p,Fh:f,Fl:h,Gh:m,Gl:y,Hh:g,Hl:E}=this;for(let x=0;x<80;x++){let _=ee.rotrSH(d,p,14)^ee.rotrSH(d,p,18)^ee.rotrBH(d,p,41),S=ee.rotrSL(d,p,14)^ee.rotrSL(d,p,18)^ee.rotrBL(d,p,41),A=d&f^~d&m,v=p&h^~p&y,b=ee.add5L(E,S,v,Z3[x],Ln[x]),T=ee.add5H(b,g,_,A,X3[x],Cn[x]),C=b|0,N=ee.rotrSH(n,i,28)^ee.rotrBH(n,i,34)^ee.rotrBH(n,i,39),$=ee.rotrSL(n,i,28)^ee.rotrBL(n,i,34)^ee.rotrBL(n,i,39),D=n&o^n&a^o&a,ne=i&s^i&c^s&c;g=m|0,E=y|0,m=f|0,y=h|0,f=d|0,h=p|0,{h:d,l:p}=ee.add(u|0,l|0,T|0,C|0),u=a|0,l=c|0,a=o|0,c=s|0,o=n|0,s=i|0;let B=ee.add3L(C,$,ne);n=ee.add3H(B,T,N,D),i=B|0}({h:n,l:i}=ee.add(this.Ah|0,this.Al|0,n|0,i|0)),{h:o,l:s}=ee.add(this.Bh|0,this.Bl|0,o|0,s|0),{h:a,l:c}=ee.add(this.Ch|0,this.Cl|0,a|0,c|0),{h:u,l}=ee.add(this.Dh|0,this.Dl|0,u|0,l|0),{h:d,l:p}=ee.add(this.Eh|0,this.El|0,d|0,p|0),{h:f,l:h}=ee.add(this.Fh|0,this.Fl|0,f|0,h|0),{h:m,l:y}=ee.add(this.Gh|0,this.Gl|0,m|0,y|0),{h:g,l:E}=ee.add(this.Hh|0,this.Hl|0,g|0,E|0),this.set(n,i,o,s,a,c,u,l,d,p,f,h,m,y,g,E)}roundClean(){Cn.fill(0),Ln.fill(0)}destroy(){this.buffer.fill(0),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var uo=Ga(()=>new Nd);var Wa={};Be(Wa,{bitGet:()=>i6,bitLen:()=>n6,bitMask:()=>as,bitSet:()=>o6,bytesToHex:()=>zr,bytesToNumberBE:()=>Kr,bytesToNumberLE:()=>Un,concatBytes:()=>Gr,createHmacDrbg:()=>Ud,ensureBytes:()=>Re,equalBytes:()=>t6,hexToBytes:()=>gi,hexToNumber:()=>Ld,isBytes:()=>er,numberToBytesBE:()=>Dn,numberToBytesLE:()=>wi,numberToHexUnpadded:()=>j0,numberToVarBytesBE:()=>e6,utf8ToBytes:()=>r6,validateObject:()=>wr});var W0=BigInt(0),Ya=BigInt(1),J3=BigInt(2);function er(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}var Q3=Array.from({length:256},(r,e)=>e.toString(16).padStart(2,"0"));function zr(r){if(!er(r))throw new Error("Uint8Array expected");let e="";for(let t=0;t<r.length;t++)e+=Q3[r[t]];return e}function j0(r){let e=r.toString(16);return e.length&1?`0${e}`:e}function Ld(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return BigInt(r===""?"0":`0x${r}`)}var $r={_0:48,_9:57,_A:65,_F:70,_a:97,_f:102};function q0(r){if(r>=$r._0&&r<=$r._9)return r-$r._0;if(r>=$r._A&&r<=$r._F)return r-($r._A-10);if(r>=$r._a&&r<=$r._f)return r-($r._a-10)}function gi(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);let e=r.length,t=e/2;if(e%2)throw new Error("padded hex string expected, got unpadded hex of length "+e);let n=new Uint8Array(t);for(let i=0,o=0;i<t;i++,o+=2){let s=q0(r.charCodeAt(o)),a=q0(r.charCodeAt(o+1));if(s===void 0||a===void 0){let c=r[o]+r[o+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+o)}n[i]=s*16+a}return n}function Kr(r){return Ld(zr(r))}function Un(r){if(!er(r))throw new Error("Uint8Array expected");return Ld(zr(Uint8Array.from(r).reverse()))}function Dn(r,e){return gi(r.toString(16).padStart(e*2,"0"))}function wi(r,e){return Dn(r,e).reverse()}function e6(r){return gi(j0(r))}function Re(r,e,t){let n;if(typeof e=="string")try{n=gi(e)}catch(o){throw new Error(`${r} must be valid hex string, got "${e}". Cause: ${o}`)}else if(er(e))n=Uint8Array.from(e);else throw new Error(`${r} must be hex string or Uint8Array`);let i=n.length;if(typeof t=="number"&&i!==t)throw new Error(`${r} expected ${t} bytes, got ${i}`);return n}function Gr(...r){let e=0;for(let i=0;i<r.length;i++){let o=r[i];if(!er(o))throw new Error("Uint8Array expected");e+=o.length}let t=new Uint8Array(e),n=0;for(let i=0;i<r.length;i++){let o=r[i];t.set(o,n),n+=o.length}return t}function t6(r,e){if(r.length!==e.length)return!1;let t=0;for(let n=0;n<r.length;n++)t|=r[n]^e[n];return t===0}function r6(r){if(typeof r!="string")throw new Error(`utf8ToBytes expected string, got ${typeof r}`);return new Uint8Array(new TextEncoder().encode(r))}function n6(r){let e;for(e=0;r>W0;r>>=Ya,e+=1);return e}function i6(r,e){return r>>BigInt(e)&Ya}var o6=(r,e,t)=>r|(t?Ya:W0)<<BigInt(e),as=r=>(J3<<BigInt(r-1))-Ya,Cd=r=>new Uint8Array(r),Y0=r=>Uint8Array.from(r);function Ud(r,e,t){if(typeof r!="number"||r<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 t!="function")throw new Error("hmacFn must be a function");let n=Cd(r),i=Cd(r),o=0,s=()=>{n.fill(1),i.fill(0),o=0},a=(...d)=>t(i,n,...d),c=(d=Cd())=>{i=a(Y0([0]),d),n=a(),d.length!==0&&(i=a(Y0([1]),d),n=a())},u=()=>{if(o++>=1e3)throw new Error("drbg: tried 1000 values");let d=0,p=[];for(;d<e;){n=a();let f=n.slice();p.push(f),d+=n.length}return Gr(...p)};return(d,p)=>{s(),c(d);let f;for(;!(f=p(u()));)c();return s(),f}}var s6={bigint:r=>typeof r=="bigint",function:r=>typeof r=="function",boolean:r=>typeof r=="boolean",string:r=>typeof r=="string",stringOrUint8Array:r=>typeof r=="string"||er(r),isSafeInteger:r=>Number.isSafeInteger(r),array:r=>Array.isArray(r),field:(r,e)=>e.Fp.isValid(r),hash:r=>typeof r=="function"&&Number.isSafeInteger(r.outputLen)};function wr(r,e,t={}){let n=(i,o,s)=>{let a=s6[o];if(typeof a!="function")throw new Error(`Invalid validator "${o}", expected function`);let c=r[i];if(!(s&&c===void 0)&&!a(c,r))throw new Error(`Invalid param ${String(i)}=${c} (${typeof c}), expected ${o}`)};for(let[i,o]of Object.entries(e))n(i,o,!1);for(let[i,o]of Object.entries(t))n(i,o,!0);return r}var Fe=BigInt(0),Ee=BigInt(1),Ei=BigInt(2),a6=BigInt(3),Dd=BigInt(4),X0=BigInt(5),Z0=BigInt(8),c6=BigInt(9),l6=BigInt(16);function ge(r,e){let t=r%e;return t>=Fe?t:e+t}function u6(r,e,t){if(t<=Fe||e<Fe)throw new Error("Expected power/modulo > 0");if(t===Ee)return Fe;let n=Ee;for(;e>Fe;)e&Ee&&(n=n*r%t),r=r*r%t,e>>=Ee;return n}function xe(r,e,t){let n=r;for(;e-- >Fe;)n*=n,n%=t;return n}function ja(r,e){if(r===Fe||e<=Fe)throw new Error(`invert: expected positive integers, got n=${r} mod=${e}`);let t=ge(r,e),n=e,i=Fe,o=Ee,s=Ee,a=Fe;for(;t!==Fe;){let u=n/t,l=n%t,d=i-s*u,p=o-a*u;n=t,t=l,i=s,o=a,s=d,a=p}if(n!==Ee)throw new Error("invert: does not exist");return ge(i,e)}function d6(r){let e=(r-Ee)/Ei,t,n,i;for(t=r-Ee,n=0;t%Ei===Fe;t/=Ei,n++);for(i=Ei;i<r&&u6(i,e,r)!==r-Ee;i++);if(n===1){let s=(r+Ee)/Dd;return function(c,u){let l=c.pow(u,s);if(!c.eql(c.sqr(l),u))throw new Error("Cannot find square root");return l}}let o=(t+Ee)/Ei;return function(a,c){if(a.pow(c,e)===a.neg(a.ONE))throw new Error("Cannot find square root");let u=n,l=a.pow(a.mul(a.ONE,i),t),d=a.pow(c,o),p=a.pow(c,t);for(;!a.eql(p,a.ONE);){if(a.eql(p,a.ZERO))return a.ZERO;let f=1;for(let m=a.sqr(p);f<u&&!a.eql(m,a.ONE);f++)m=a.sqr(m);let h=a.pow(l,Ee<<BigInt(u-f-1));l=a.sqr(h),d=a.mul(d,h),p=a.mul(p,l),u=f}return d}}function f6(r){if(r%Dd===a6){let e=(r+Ee)/Dd;return function(n,i){let o=n.pow(i,e);if(!n.eql(n.sqr(o),i))throw new Error("Cannot find square root");return o}}if(r%Z0===X0){let e=(r-X0)/Z0;return function(n,i){let o=n.mul(i,Ei),s=n.pow(o,e),a=n.mul(i,s),c=n.mul(n.mul(a,Ei),s),u=n.mul(a,n.sub(c,n.ONE));if(!n.eql(n.sqr(u),i))throw new Error("Cannot find square root");return u}}return r%l6,d6(r)}var J0=(r,e)=>(ge(r,e)&Ee)===Ee,h6=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Od(r){let e={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},t=h6.reduce((n,i)=>(n[i]="function",n),e);return wr(r,t)}function p6(r,e,t){if(t<Fe)throw new Error("Expected power > 0");if(t===Fe)return r.ONE;if(t===Ee)return e;let n=r.ONE,i=e;for(;t>Fe;)t&Ee&&(n=r.mul(n,i)),i=r.sqr(i),t>>=Ee;return n}function m6(r,e){let t=new Array(e.length),n=e.reduce((o,s,a)=>r.is0(s)?o:(t[a]=o,r.mul(o,s)),r.ONE),i=r.inv(n);return e.reduceRight((o,s,a)=>r.is0(s)?o:(t[a]=r.mul(o,t[a]),r.mul(o,s)),i),t}function Pd(r,e){let t=e!==void 0?e:r.toString(2).length,n=Math.ceil(t/8);return{nBitLength:t,nByteLength:n}}function Xa(r,e,t=!1,n={}){if(r<=Fe)throw new Error(`Expected Field ORDER > 0, got ${r}`);let{nBitLength:i,nByteLength:o}=Pd(r,e);if(o>2048)throw new Error("Field lengths over 2048 bytes are not supported");let s=f6(r),a=Object.freeze({ORDER:r,BITS:i,BYTES:o,MASK:as(i),ZERO:Fe,ONE:Ee,create:c=>ge(c,r),isValid:c=>{if(typeof c!="bigint")throw new Error(`Invalid field element: expected bigint, got ${typeof c}`);return Fe<=c&&c<r},is0:c=>c===Fe,isOdd:c=>(c&Ee)===Ee,neg:c=>ge(-c,r),eql:(c,u)=>c===u,sqr:c=>ge(c*c,r),add:(c,u)=>ge(c+u,r),sub:(c,u)=>ge(c-u,r),mul:(c,u)=>ge(c*u,r),pow:(c,u)=>p6(a,c,u),div:(c,u)=>ge(c*ja(u,r),r),sqrN:c=>c*c,addN:(c,u)=>c+u,subN:(c,u)=>c-u,mulN:(c,u)=>c*u,inv:c=>ja(c,r),sqrt:n.sqrt||(c=>s(a,c)),invertBatch:c=>m6(a,c),cmov:(c,u,l)=>l?u:c,toBytes:c=>t?wi(c,o):Dn(c,o),fromBytes:c=>{if(c.length!==o)throw new Error(`Fp.fromBytes: expected ${o}, got ${c.length}`);return t?Un(c):Kr(c)}});return Object.freeze(a)}function Q0(r,e){if(!r.isOdd)throw new Error("Field doesn't have isOdd");let t=r.sqrt(e);return r.isOdd(t)?r.neg(t):t}function e1(r){if(typeof r!="bigint")throw new Error("field order must be bigint");let e=r.toString(2).length;return Math.ceil(e/8)}function Fd(r){let e=e1(r);return e+Math.ceil(e/2)}function t1(r,e,t=!1){let n=r.length,i=e1(e),o=Fd(e);if(n<16||n<o||n>1024)throw new Error(`expected ${o}-1024 bytes of input, got ${n}`);let s=t?Kr(r):Un(r),a=ge(s,e-Ee)+Ee;return t?wi(a,i):Dn(a,i)}var g6=BigInt(0),Vd=BigInt(1);function Za(r,e){let t=(i,o)=>{let s=o.negate();return i?s:o},n=i=>{let o=Math.ceil(e/i)+1,s=2**(i-1);return{windows:o,windowSize:s}};return{constTimeNegate:t,unsafeLadder(i,o){let s=r.ZERO,a=i;for(;o>g6;)o&Vd&&(s=s.add(a)),a=a.double(),o>>=Vd;return s},precomputeWindow(i,o){let{windows:s,windowSize:a}=n(o),c=[],u=i,l=u;for(let d=0;d<s;d++){l=u,c.push(l);for(let p=1;p<a;p++)l=l.add(u),c.push(l);u=l.double()}return c},wNAF(i,o,s){let{windows:a,windowSize:c}=n(i),u=r.ZERO,l=r.BASE,d=BigInt(2**i-1),p=2**i,f=BigInt(i);for(let h=0;h<a;h++){let m=h*c,y=Number(s&d);s>>=f,y>c&&(y-=p,s+=Vd);let g=m,E=m+Math.abs(y)-1,x=h%2!==0,_=y<0;y===0?l=l.add(t(x,o[g])):u=u.add(t(_,o[E]))}return{p:u,f:l}},wNAFCached(i,o,s,a){let c=i._WINDOW_SIZE||1,u=o.get(i);return u||(u=this.precomputeWindow(i,c),c!==1&&o.set(i,a(u))),this.wNAF(c,u,s)}}}function cs(r){return Od(r.Fp),wr(r,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...Pd(r.n,r.nBitLength),...r,p:r.Fp.ORDER})}var tr=BigInt(0),kt=BigInt(1),Ja=BigInt(2),w6=BigInt(8),E6={zip215:!0};function x6(r){let e=cs(r);return wr(r,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...e})}function Qa(r){let e=x6(r),{Fp:t,n,prehash:i,hash:o,randomBytes:s,nByteLength:a,h:c}=e,u=Ja<<BigInt(a*8)-kt,l=t.create,d=e.uvRatio||((L,k)=>{try{return{isValid:!0,value:t.sqrt(L*t.inv(k))}}catch{return{isValid:!1,value:tr}}}),p=e.adjustScalarBytes||(L=>L),f=e.domain||((L,k,K)=>{if(k.length||K)throw new Error("Contexts/pre-hash are not supported");return L}),h=L=>typeof L=="bigint"&&tr<L,m=(L,k)=>h(L)&&h(k)&&L<k,y=L=>L===tr||m(L,u);function g(L,k){if(m(L,k))return L;throw new Error(`Expected valid scalar < ${k}, got ${typeof L} ${L}`)}function E(L){return L===tr?L:g(L,n)}let x=new Map;function _(L){if(!(L instanceof S))throw new Error("ExtendedPoint expected")}class S{constructor(k,K,W,J){if(this.ex=k,this.ey=K,this.ez=W,this.et=J,!y(k))throw new Error("x required");if(!y(K))throw new Error("y required");if(!y(W))throw new Error("z required");if(!y(J))throw new Error("t required")}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(k){if(k instanceof S)throw new Error("extended point not allowed");let{x:K,y:W}=k||{};if(!y(K)||!y(W))throw new Error("invalid affine point");return new S(K,W,kt,l(K*W))}static normalizeZ(k){let K=t.invertBatch(k.map(W=>W.ez));return k.map((W,J)=>W.toAffine(K[J])).map(S.fromAffine)}_setWindowSize(k){this._WINDOW_SIZE=k,x.delete(this)}assertValidity(){let{a:k,d:K}=e;if(this.is0())throw new Error("bad point: ZERO");let{ex:W,ey:J,ez:re,et:ie}=this,me=l(W*W),ae=l(J*J),ue=l(re*re),Ue=l(ue*ue),Ie=l(me*k),Ke=l(ue*l(Ie+ae)),Ge=l(Ue+l(K*l(me*ae)));if(Ke!==Ge)throw new Error("bad point: equation left != right (1)");let Pe=l(W*J),Ze=l(re*ie);if(Pe!==Ze)throw new Error("bad point: equation left != right (2)")}equals(k){_(k);let{ex:K,ey:W,ez:J}=this,{ex:re,ey:ie,ez:me}=k,ae=l(K*me),ue=l(re*J),Ue=l(W*me),Ie=l(ie*J);return ae===ue&&Ue===Ie}is0(){return this.equals(S.ZERO)}negate(){return new S(l(-this.ex),this.ey,this.ez,l(-this.et))}double(){let{a:k}=e,{ex:K,ey:W,ez:J}=this,re=l(K*K),ie=l(W*W),me=l(Ja*l(J*J)),ae=l(k*re),ue=K+W,Ue=l(l(ue*ue)-re-ie),Ie=ae+ie,Ke=Ie-me,Ge=ae-ie,Pe=l(Ue*Ke),Ze=l(Ie*Ge),Vr=l(Ue*Ge),li=l(Ke*Ie);return new S(Pe,Ze,li,Vr)}add(k){_(k);let{a:K,d:W}=e,{ex:J,ey:re,ez:ie,et:me}=this,{ex:ae,ey:ue,ez:Ue,et:Ie}=k;if(K===BigInt(-1)){let mp=l((re-J)*(ue+ae)),yp=l((re+J)*(ue-ae)),yu=l(yp-mp);if(yu===tr)return this.double();let gp=l(ie*Ja*Ie),wp=l(me*Ja*Ue),Ep=wp+gp,xp=yp+mp,bp=wp-gp,FE=l(Ep*yu),VE=l(xp*bp),ME=l(Ep*bp),HE=l(yu*xp);return new S(FE,VE,HE,ME)}let Ke=l(J*ae),Ge=l(re*ue),Pe=l(me*W*Ie),Ze=l(ie*Ue),Vr=l((J+re)*(ae+ue)-Ke-Ge),li=Ze-Pe,Xo=Ze+Pe,pp=l(Ge-K*Ke),UE=l(Vr*li),DE=l(Xo*pp),OE=l(Vr*pp),PE=l(li*Xo);return new S(UE,DE,PE,OE)}subtract(k){return this.add(k.negate())}wNAF(k){return b.wNAFCached(this,x,k,S.normalizeZ)}multiply(k){let{p:K,f:W}=this.wNAF(g(k,n));return S.normalizeZ([K,W])[0]}multiplyUnsafe(k){let K=E(k);return K===tr?v:this.equals(v)||K===kt?this:this.equals(A)?this.wNAF(K).p:b.unsafeLadder(this,K)}isSmallOrder(){return this.multiplyUnsafe(c).is0()}isTorsionFree(){return b.unsafeLadder(this,n).is0()}toAffine(k){let{ex:K,ey:W,ez:J}=this,re=this.is0();k==null&&(k=re?w6:t.inv(J));let ie=l(K*k),me=l(W*k),ae=l(J*k);if(re)return{x:tr,y:kt};if(ae!==kt)throw new Error("invZ was invalid");return{x:ie,y:me}}clearCofactor(){let{h:k}=e;return k===kt?this:this.multiplyUnsafe(k)}static fromHex(k,K=!1){let{d:W,a:J}=e,re=t.BYTES;k=Re("pointHex",k,re);let ie=k.slice(),me=k[re-1];ie[re-1]=me&-129;let ae=Un(ie);ae===tr||(K?g(ae,u):g(ae,t.ORDER));let ue=l(ae*ae),Ue=l(ue-kt),Ie=l(W*ue-J),{isValid:Ke,value:Ge}=d(Ue,Ie);if(!Ke)throw new Error("Point.fromHex: invalid y coordinate");let Pe=(Ge&kt)===kt,Ze=(me&128)!==0;if(!K&&Ge===tr&&Ze)throw new Error("Point.fromHex: x=0 and x_0=1");return Ze!==Pe&&(Ge=l(-Ge)),S.fromAffine({x:Ge,y:ae})}static fromPrivateKey(k){return N(k).point}toRawBytes(){let{x:k,y:K}=this.toAffine(),W=wi(K,t.BYTES);return W[W.length-1]|=k&kt?128:0,W}toHex(){return zr(this.toRawBytes())}}S.BASE=new S(e.Gx,e.Gy,kt,l(e.Gx*e.Gy)),S.ZERO=new S(tr,kt,kt,tr);let{BASE:A,ZERO:v}=S,b=Za(S,a*8);function T(L){return ge(L,n)}function C(L){return T(Un(L))}function N(L){let k=a;L=Re("private key",L,k);let K=Re("hashed private key",o(L),2*k),W=p(K.slice(0,k)),J=K.slice(k,2*k),re=C(W),ie=A.multiply(re),me=ie.toRawBytes();return{head:W,prefix:J,scalar:re,point:ie,pointBytes:me}}function $(L){return N(L).pointBytes}function D(L=new Uint8Array,...k){let K=Gr(...k);return C(o(f(K,Re("context",L),!!i)))}function ne(L,k,K={}){L=Re("message",L),i&&(L=i(L));let{prefix:W,scalar:J,pointBytes:re}=N(k),ie=D(K.context,W,L),me=A.multiply(ie).toRawBytes(),ae=D(K.context,me,re,L),ue=T(ie+ae*J);E(ue);let Ue=Gr(me,wi(ue,t.BYTES));return Re("result",Ue,a*2)}let B=E6;function U(L,k,K,W=B){let{context:J,zip215:re}=W,ie=t.BYTES;L=Re("signature",L,2*ie),k=Re("message",k),i&&(k=i(k));let me=Un(L.slice(ie,2*ie)),ae,ue,Ue;try{ae=S.fromHex(K,re),ue=S.fromHex(L.slice(0,ie),re),Ue=A.multiplyUnsafe(me)}catch{return!1}if(!re&&ae.isSmallOrder())return!1;let Ie=D(J,ue.toRawBytes(),ae.toRawBytes(),k);return ue.add(ae.multiplyUnsafe(Ie)).subtract(Ue).clearCofactor().equals(S.ZERO)}return A._setWindowSize(8),{CURVE:e,getPublicKey:$,sign:ne,verify:U,ExtendedPoint:S,utils:{getExtendedPublicKey:N,randomPrivateKey:()=>s(t.BYTES),precompute(L=8,k=S.BASE){return k._setWindowSize(L),k.multiply(BigInt(3)),k}}}}var Hd=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),r1=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),SR=BigInt(0),b6=BigInt(1),Md=BigInt(2),v6=BigInt(5),n1=BigInt(10),A6=BigInt(20),_6=BigInt(40),i1=BigInt(80);function S6(r){let e=Hd,n=r*r%e*r%e,i=xe(n,Md,e)*n%e,o=xe(i,b6,e)*r%e,s=xe(o,v6,e)*o%e,a=xe(s,n1,e)*s%e,c=xe(a,A6,e)*a%e,u=xe(c,_6,e)*c%e,l=xe(u,i1,e)*u%e,d=xe(l,i1,e)*u%e,p=xe(d,n1,e)*s%e;return{pow_p_5_8:xe(p,Md,e)*r%e,b2:n}}function I6(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}function B6(r,e){let t=Hd,n=ge(e*e*e,t),i=ge(n*n*e,t),o=S6(r*i).pow_p_5_8,s=ge(r*n*o,t),a=ge(e*s*s,t),c=s,u=ge(s*r1,t),l=a===r,d=a===ge(-r,t),p=a===ge(-r*r1,t);return l&&(s=c),(d||p)&&(s=u),J0(s,t)&&(s=ge(-s,t)),{isValid:l||d,value:s}}var qr=Xa(Hd,void 0,!0),$d={a:BigInt(-1),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:qr,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:BigInt(8),Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:uo,randomBytes:co,adjustScalarBytes:I6,uvRatio:B6},fo=Qa($d);function o1(r,e,t){if(e.length>255)throw new Error("Context is too big");return Ka(Rd("SigEd25519 no Ed25519 collisions"),new Uint8Array([t?1:0,e.length]),e,r)}var IR=Qa({...$d,domain:o1}),BR=Qa({...$d,domain:o1,prehash:uo});var k6=(qr.ORDER+BigInt(3))/BigInt(8),kR=qr.pow(Md,k6),RR=qr.sqrt(qr.neg(qr.ONE)),TR=(qr.ORDER-BigInt(5))/BigInt(8),NR=BigInt(486662);var CR=Q0(qr,qr.neg(BigInt(486664)));var LR=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),UR=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),DR=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),OR=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952");var PR=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");var ho=32,Yr=64,ec=32;function s1(){let r=fo.utils.randomPrivateKey(),e=fo.getPublicKey(r);return{privateKey:u1(r,e),publicKey:e}}function a1(r){if(r.length!==ec)throw new TypeError('"seed" must be 32 bytes in length.');if(!(r instanceof Uint8Array))throw new TypeError('"seed" must be a node.js Buffer, or Uint8Array.');let e=r,t=fo.getPublicKey(e);return{privateKey:u1(e,t),publicKey:t}}function c1(r,e){let t=r.subarray(0,ec);return fo.sign(e instanceof Uint8Array?e:e.subarray(),t)}function l1(r,e,t){return fo.verify(e,t instanceof Uint8Array?t:t.subarray(),r)}function u1(r,e){let t=new Uint8Array(Yr);for(let n=0;n<ec;n++)t[n]=r[n],t[ec+n]=e[n];return t}var ct={get(r=globalThis){let e=r.crypto;if(e==null||e.subtle==null)throw Object.assign(new Error("Missing Web Crypto API. The most likely cause of this error is that this page is being accessed from an insecure context (i.e. not HTTPS). For more information and possible resolutions see https://github.com/libp2p/js-libp2p/blob/main/packages/crypto/README.md#web-crypto-api"),{code:"ERR_MISSING_WEB_CRYPTO"});return e}};var zd={alg:"A128GCM",ext:!0,k:"scm9jmO_4BJAgdwWGVulLg",key_ops:["encrypt","decrypt"],kty:"oct"};function d1(r){let e=r?.algorithm??"AES-GCM",t=r?.keyLength??16,n=r?.nonceLength??12,i=r?.digest??"SHA-256",o=r?.saltLength??16,s=r?.iterations??32767,a=ct.get();t*=8;async function c(d,p){let f=a.getRandomValues(new Uint8Array(o)),h=a.getRandomValues(new Uint8Array(n)),m={name:e,iv:h};typeof p=="string"&&(p=V(p));let y;if(p.length===0){y=await a.subtle.importKey("jwk",zd,{name:"AES-GCM"},!0,["encrypt"]);try{let E={name:"PBKDF2",salt:f,iterations:s,hash:{name:i}},x=await a.subtle.importKey("raw",p,{name:"PBKDF2"},!1,["deriveKey"]);y=await a.subtle.deriveKey(E,x,{name:e,length:t},!0,["encrypt"])}catch{y=await a.subtle.importKey("jwk",zd,{name:"AES-GCM"},!0,["encrypt"])}}else{let E={name:"PBKDF2",salt:f,iterations:s,hash:{name:i}},x=await a.subtle.importKey("raw",p,{name:"PBKDF2"},!1,["deriveKey"]);y=await a.subtle.deriveKey(E,x,{name:e,length:t},!0,["encrypt"])}let g=await a.subtle.encrypt(m,y,d);return ye([f,m.iv,new Uint8Array(g)])}async function u(d,p){let f=d.subarray(0,o),h=d.subarray(o,o+n),m=d.subarray(o+n),y={name:e,iv:h};typeof p=="string"&&(p=V(p));let g;if(p.length===0)try{let x={name:"PBKDF2",salt:f,iterations:s,hash:{name:i}},_=await a.subtle.importKey("raw",p,{name:"PBKDF2"},!1,["deriveKey"]);g=await a.subtle.deriveKey(x,_,{name:e,length:t},!0,["decrypt"])}catch{g=await a.subtle.importKey("jwk",zd,{name:"AES-GCM"},!0,["decrypt"])}else{let x={name:"PBKDF2",salt:f,iterations:s,hash:{name:i}},_=await a.subtle.importKey("raw",p,{name:"PBKDF2"},!1,["deriveKey"]);g=await a.subtle.deriveKey(x,_,{name:e,length:t},!0,["decrypt"])}let E=await a.subtle.decrypt(y,g,m);return new Uint8Array(E)}return{encrypt:c,decrypt:u}}async function po(r,e){let n=await d1().encrypt(r,e);return yr.encode(n)}var be;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.Secp256k1="Secp256k1"})(be||(be={}));var Kd;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.Secp256k1=2]="Secp256k1"})(Kd||(Kd={}));(function(r){r.codec=()=>yi(Kd)})(be||(be={}));var Er;(function(r){let e;r.codec=()=>(e==null&&(e=$t((t,n,i={})=>{i.lengthDelimited!==!1&&n.fork(),t.Type!=null&&(n.uint32(8),be.codec().encode(t.Type,n)),t.Data!=null&&(n.uint32(18),n.bytes(t.Data)),i.lengthDelimited!==!1&&n.ldelim()},(t,n)=>{let i={},o=n==null?t.len:t.pos+n;for(;t.pos<o;){let s=t.uint32();switch(s>>>3){case 1:i.Type=be.codec().decode(t);break;case 2:i.Data=t.bytes();break;default:t.skipType(s&7);break}}return i})),e),r.encode=t=>Ht(t,r.codec()),r.decode=t=>Vt(t,r.codec())})(Er||(Er={}));var xr;(function(r){let e;r.codec=()=>(e==null&&(e=$t((t,n,i={})=>{i.lengthDelimited!==!1&&n.fork(),t.Type!=null&&(n.uint32(8),be.codec().encode(t.Type,n)),t.Data!=null&&(n.uint32(18),n.bytes(t.Data)),i.lengthDelimited!==!1&&n.ldelim()},(t,n)=>{let i={},o=n==null?t.len:t.pos+n;for(;t.pos<o;){let s=t.uint32();switch(s>>>3){case 1:i.Type=be.codec().decode(t);break;case 2:i.Data=t.bytes();break;default:t.skipType(s&7);break}}return i})),e),r.encode=t=>Ht(t,r.codec()),r.decode=t=>Vt(t,r.codec())})(xr||(xr={}));var ls=class{_key;constructor(e){this._key=mo(e,ho)}verify(e,t){return l1(this._key,t,e)}marshal(){return this._key}get bytes(){return Er.encode({Type:be.Ed25519,Data:this.marshal()}).subarray()}equals(e){return he(this.bytes,e.bytes)}hash(){let e=fe.digest(this.bytes);return Gt(e)?e.then(({bytes:t})=>t):e.bytes}},xi=class{_key;_publicKey;constructor(e,t){this._key=mo(e,Yr),this._publicKey=mo(t,ho)}sign(e){return c1(this._key,e)}get public(){return new ls(this._publicKey)}marshal(){return this._key}get bytes(){return xr.encode({Type:be.Ed25519,Data:this.marshal()}).subarray()}equals(e){return he(this.bytes,e.bytes)}async hash(){let e=fe.digest(this.bytes),t;return Gt(e)?{bytes:t}=await e:t=e.bytes,t}async id(){let e=et.digest(this.public.bytes);return Ne.encode(e.bytes).substring(1)}async export(e,t="libp2p-key"){if(t==="libp2p-key")return po(this.bytes,e);throw new O(`export format '${t}' is not supported`,"ERR_INVALID_EXPORT_FORMAT")}};function N6(r){if(r.length>Yr){r=mo(r,Yr+ho);let n=r.subarray(0,Yr),i=r.subarray(Yr,r.length);return new xi(n,i)}r=mo(r,Yr);let e=r.subarray(0,Yr),t=r.subarray(ho);return new xi(e,t)}function C6(r){return r=mo(r,ho),new ls(r)}async function L6(){let{privateKey:r,publicKey:e}=s1();return new xi(r,e)}async function f1(r){let{privateKey:e,publicKey:t}=a1(r);return new xi(e,t)}function mo(r,e){if(r=Uint8Array.from(r??[]),r.length!==e)throw new O(`Key must be a Uint8Array of length ${e}, got ${r.length}`,"ERR_INVALID_KEY_TYPE");return r}var tf={};Be(tf,{MAX_RSA_KEY_SIZE:()=>bs,RsaPrivateKey:()=>xo,RsaPublicKey:()=>xs,fromJwk:()=>sv,generateKeyPair:()=>av,unmarshalRsaPrivateKey:()=>Qd,unmarshalRsaPublicKey:()=>ov});function bi(r){if(isNaN(r)||r<=0)throw new O("random bytes length must be a Number bigger than 0","ERR_INVALID_LENGTH");return co(r)}var Vn={};Be(Vn,{exportToPem:()=>ev,importFromPem:()=>tv,jwkToPkcs1:()=>X6,jwkToPkix:()=>J6,pkcs1ToJwk:()=>j6,pkixToJwk:()=>Z6});var rc=class extends so{constructor(e,t){super(),this.finished=!1,this.destroyed=!1,$a(e);let n=Nn(t);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 i=this.blockLen,o=new Uint8Array(i);o.set(n.length>i?e.create().update(n).digest():n);for(let s=0;s<o.length;s++)o[s]^=54;this.iHash.update(o),this.oHash=e.create();for(let s=0;s<o.length;s++)o[s]^=106;this.oHash.update(o),o.fill(0)}update(e){return oo(this),this.iHash.update(e),this}digestInto(e){oo(this),kd(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:t,iHash:n,finished:i,destroyed:o,blockLen:s,outputLen:a}=this;return e=e,e.finished=i,e.destroyed=o,e.blockLen=s,e.outputLen=a,e.oHash=t._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},us=(r,e,t)=>new rc(r,e).update(t).digest();us.create=(r,e)=>new rc(r,e);function U6(r,e,t,n){$a(r);let i=K0({dkLen:32,asyncTick:10},n),{c:o,dkLen:s,asyncTick:a}=i;if(io(o),io(s),io(a),o<1)throw new Error("PBKDF2: iterations (c) should be >= 1");let c=Nn(e),u=Nn(t),l=new Uint8Array(s),d=us.create(r,c),p=d._cloneInto().update(u);return{c:o,dkLen:s,asyncTick:a,DK:l,PRF:d,PRFSalt:p}}function D6(r,e,t,n,i){return r.destroy(),e.destroy(),n&&n.destroy(),i.fill(0),t}async function qd(r,e,t,n){let{c:i,dkLen:o,asyncTick:s,DK:a,PRF:c,PRFSalt:u}=U6(r,e,t,n),l,d=new Uint8Array(4),p=ao(d),f=new Uint8Array(c.outputLen);for(let h=1,m=0;m<o;h++,m+=c.outputLen){let y=a.subarray(m,m+c.outputLen);p.setInt32(0,h,!1),(l=u._cloneInto(l)).update(d).digestInto(f),y.set(f.subarray(0,y.length)),await z0(i-1,s,()=>{c._cloneInto(l).update(f).digestInto(f);for(let g=0;g<y.length;g++)y[g]^=f[g]})}return D6(c,u,a,l,f)}var se=Q(h1());function vi(r,e){let t=0;if(r.length===1)return r[0];for(let n=r.length-1;n>=0;n--)t+=r[r.length-1-n]*Math.pow(2,e*n);return t}function On(r,e,t=-1){let n=t,i=r,o=0,s=Math.pow(2,e);for(let a=1;a<8;a++){if(r<s){let c;if(n<0)c=new ArrayBuffer(a),o=a;else{if(n<a)return new ArrayBuffer(0);c=new ArrayBuffer(n),o=n}let u=new Uint8Array(c);for(let l=a-1;l>=0;l--){let d=Math.pow(2,l*e);u[o-l-1]=Math.floor(i/d),i-=u[o-l-1]*d}return c}s*=Math.pow(2,e)}return new ArrayBuffer(0)}function oc(...r){let e=0,t=0;for(let o of r)e+=o.length;let n=new ArrayBuffer(e),i=new Uint8Array(n);for(let o of r)i.set(o,t),t+=o.length;return i}function Wd(){let r=new Uint8Array(this.valueHex);if(this.valueHex.byteLength>=2){let a=r[0]===255&&r[1]&128,c=r[0]===0&&(r[1]&128)===0;(a||c)&&this.warnings.push("Needlessly long format")}let e=new ArrayBuffer(this.valueHex.byteLength),t=new Uint8Array(e);for(let a=0;a<this.valueHex.byteLength;a++)t[a]=0;t[0]=r[0]&128;let n=vi(t,8),i=new ArrayBuffer(this.valueHex.byteLength),o=new Uint8Array(i);for(let a=0;a<this.valueHex.byteLength;a++)o[a]=r[a];return o[0]&=127,vi(o,8)-n}function p1(r){let e=r<0?r*-1:r,t=128;for(let n=1;n<8;n++){if(e<=t){if(r<0){let s=t-e,a=On(s,8,n),c=new Uint8Array(a);return c[0]|=128,a}let i=On(e,8,n),o=new Uint8Array(i);if(o[0]&128){let s=i.slice(0),a=new Uint8Array(s);i=new ArrayBuffer(i.byteLength+1),o=new Uint8Array(i);for(let c=0;c<s.byteLength;c++)o[c+1]=a[c];o[0]=0}return i}t*=Math.pow(2,8)}return new ArrayBuffer(0)}function m1(r,e){if(r.byteLength!==e.byteLength)return!1;let t=new Uint8Array(r),n=new Uint8Array(e);for(let i=0;i<t.length;i++)if(t[i]!==n[i])return!1;return!0}function wt(r,e){let t=r.toString(10);if(e<t.length)return"";let n=e-t.length,i=new Array(n);for(let s=0;s<n;s++)i[s]="0";return i.join("").concat(t)}var dT=Math.log(2);function sc(){if(typeof BigInt>"u")throw new Error("BigInt is not defined. Your environment doesn't implement BigInt.")}function jd(r){let e=0,t=0;for(let i=0;i<r.length;i++){let o=r[i];e+=o.byteLength}let n=new Uint8Array(e);for(let i=0;i<r.length;i++){let o=r[i];n.set(new Uint8Array(o),t),t+=o.byteLength}return n.buffer}function Jr(r,e,t,n){return e instanceof Uint8Array?e.byteLength?t<0?(r.error="Wrong parameter: inputOffset less than zero",!1):n<0?(r.error="Wrong parameter: inputLength less than zero",!1):e.byteLength-t-n<0?(r.error="End of input reached before message was fully decoded (inconsistent offset and length values)",!1):!0:(r.error="Wrong parameter: inputBuffer has zero length",!1):(r.error="Wrong parameter: inputBuffer must be 'Uint8Array'",!1)}var fs=class{constructor(){this.items=[]}write(e){this.items.push(e)}final(){return jd(this.items)}},ds=[new Uint8Array([1])],y1="0123456789";var wo="",nr=new ArrayBuffer(0),Xd=new Uint8Array(0),hs="EndOfContent",w1="OCTET STRING",E1="BIT STRING";function Qr(r){var e;return e=class extends r{constructor(...n){var i;super(...n);let o=n[0]||{};this.isHexOnly=(i=o.isHexOnly)!==null&&i!==void 0?i:!1,this.valueHexView=o.valueHex?se.BufferSourceConverter.toUint8Array(o.valueHex):Xd}get valueHex(){return this.valueHexView.slice().buffer}set valueHex(n){this.valueHexView=new Uint8Array(n)}fromBER(n,i,o){let s=n instanceof ArrayBuffer?new Uint8Array(n):n;if(!Jr(this,s,i,o))return-1;let a=i+o;return this.valueHexView=s.subarray(i,a),this.valueHexView.length?(this.blockLength=o,a):(this.warnings.push("Zero buffer length"),i)}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",nr)}toJSON(){return{...super.toJSON(),isHexOnly:this.isHexOnly,valueHex:se.Convert.ToHex(this.valueHexView)}}},e.NAME="hexBlock",e}var jr=class{constructor({blockLength:e=0,error:t=wo,warnings:n=[],valueBeforeDecode:i=Xd}={}){this.blockLength=e,this.error=t,this.warnings=n,this.valueBeforeDecodeView=se.BufferSourceConverter.toUint8Array(i)}static blockName(){return this.NAME}get valueBeforeDecode(){return this.valueBeforeDecodeView.slice().buffer}set valueBeforeDecode(e){this.valueBeforeDecodeView=new Uint8Array(e)}toJSON(){return{blockName:this.constructor.NAME,blockLength:this.blockLength,error:this.error,warnings:this.warnings,valueBeforeDecode:se.Convert.ToHex(this.valueBeforeDecodeView)}}};jr.NAME="baseBlock";var tt=class extends jr{fromBER(e,t,n){throw TypeError("User need to make a specific function in a class which extends 'ValueBlock'")}toBER(e,t){throw TypeError("User need to make a specific function in a class which extends 'ValueBlock'")}};tt.NAME="valueBlock";var ac=class extends Qr(jr){constructor({idBlock:e={}}={}){var t,n,i,o;super(),e?(this.isHexOnly=(t=e.isHexOnly)!==null&&t!==void 0?t:!1,this.valueHexView=e.valueHex?se.BufferSourceConverter.toUint8Array(e.valueHex):Xd,this.tagClass=(n=e.tagClass)!==null&&n!==void 0?n:-1,this.tagNumber=(i=e.tagNumber)!==null&&i!==void 0?i:-1,this.isConstructed=(o=e.isConstructed)!==null&&o!==void 0?o:!1):(this.tagClass=-1,this.tagNumber=-1,this.isConstructed=!1)}toBER(e=!1){let t=0;switch(this.tagClass){case 1:t|=0;break;case 2:t|=64;break;case 3:t|=128;break;case 4:t|=192;break;default:return this.error="Unknown tag class",nr}if(this.isConstructed&&(t|=32),this.tagNumber<31&&!this.isHexOnly){let i=new Uint8Array(1);if(!e){let o=this.tagNumber;o&=31,t|=o,i[0]=t}return i.buffer}if(!this.isHexOnly){let i=On(this.tagNumber,7),o=new Uint8Array(i),s=i.byteLength,a=new Uint8Array(s+1);if(a[0]=t|31,!e){for(let c=0;c<s-1;c++)a[c+1]=o[c]|128;a[s]=o[s-1]}return a.buffer}let n=new Uint8Array(this.valueHexView.byteLength+1);if(n[0]=t|31,!e){let i=this.valueHexView;for(let o=0;o<i.length-1;o++)n[o+1]=i[o]|128;n[this.valueHexView.byteLength]=i[i.length-1]}return n.buffer}fromBER(e,t,n){let i=se.BufferSourceConverter.toUint8Array(e);if(!Jr(this,i,t,n))return-1;let o=i.subarray(t,t+n);if(o.length===0)return this.error="Zero buffer length",-1;switch(o[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=(o[0]&32)===32,this.isHexOnly=!1;let a=o[0]&31;if(a!==31)this.tagNumber=a,this.blockLength=1;else{let c=1,u=this.valueHexView=new Uint8Array(255),l=255;for(;o[c]&128;){if(u[c-1]=o[c]&127,c++,c>=o.length)return this.error="End of input reached before message was fully decoded",-1;if(c===l){l+=255;let p=new Uint8Array(l);for(let f=0;f<u.length;f++)p[f]=u[f];u=this.valueHexView=new Uint8Array(l)}}this.blockLength=c+1,u[c-1]=o[c]&127;let d=new Uint8Array(c);for(let p=0;p<c;p++)d[p]=u[p];u=this.valueHexView=new Uint8Array(c),u.set(d),this.blockLength<=9?this.tagNumber=vi(u,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 t+this.blockLength}toJSON(){return{...super.toJSON(),tagClass:this.tagClass,tagNumber:this.tagNumber,isConstructed:this.isConstructed}}};ac.NAME="identificationBlock";var cc=class extends jr{constructor({lenBlock:e={}}={}){var t,n,i;super(),this.isIndefiniteForm=(t=e.isIndefiniteForm)!==null&&t!==void 0?t:!1,this.longFormUsed=(n=e.longFormUsed)!==null&&n!==void 0?n:!1,this.length=(i=e.length)!==null&&i!==void 0?i:0}fromBER(e,t,n){let i=se.BufferSourceConverter.toUint8Array(e);if(!Jr(this,i,t,n))return-1;let o=i.subarray(t,t+n);if(o.length===0)return this.error="Zero buffer length",-1;if(o[0]===255)return this.error="Length block 0xFF is reserved by standard",-1;if(this.isIndefiniteForm=o[0]===128,this.isIndefiniteForm)return this.blockLength=1,t+this.blockLength;if(this.longFormUsed=!!(o[0]&128),this.longFormUsed===!1)return this.length=o[0],this.blockLength=1,t+this.blockLength;let s=o[0]&127;if(s>8)return this.error="Too big integer",-1;if(s+1>o.length)return this.error="End of input reached before message was fully decoded",-1;let a=t+1,c=i.subarray(a,a+s);return c[s-1]===0&&this.warnings.push("Needlessly long encoded length"),this.length=vi(c,8),this.longFormUsed&&this.length<=127&&this.warnings.push("Unnecessary usage of long length form"),this.blockLength=s+1,t+this.blockLength}toBER(e=!1){let t,n;if(this.length>127&&(this.longFormUsed=!0),this.isIndefiniteForm)return t=new ArrayBuffer(1),e===!1&&(n=new Uint8Array(t),n[0]=128),t;if(this.longFormUsed){let i=On(this.length,8);if(i.byteLength>127)return this.error="Too big length",nr;if(t=new ArrayBuffer(i.byteLength+1),e)return t;let o=new Uint8Array(i);n=new Uint8Array(t),n[0]=i.byteLength|128;for(let s=0;s<i.byteLength;s++)n[s+1]=o[s];return t}return t=new ArrayBuffer(1),e===!1&&(n=new Uint8Array(t),n[0]=this.length),t}toJSON(){return{...super.toJSON(),isIndefiniteForm:this.isIndefiniteForm,longFormUsed:this.longFormUsed,length:this.length}}};cc.NAME="lengthBlock";var z={},Ye=class extends jr{constructor({name:e=wo,optional:t=!1,primitiveSchema:n,...i}={},o){super(i),this.name=e,this.optional=t,n&&(this.primitiveSchema=n),this.idBlock=new ac(i),this.lenBlock=new cc(i),this.valueBlock=o?new o(i):new tt(i)}fromBER(e,t,n){let i=this.valueBlock.fromBER(e,t,this.lenBlock.isIndefiniteForm?n:this.lenBlock.length);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,t){let n=t||new fs;t||x1(this);let i=this.idBlock.toBER(e);if(n.write(i),this.lenBlock.isIndefiniteForm)n.write(new Uint8Array([128]).buffer),this.valueBlock.toBER(e,n),n.write(new ArrayBuffer(2));else{let o=this.valueBlock.toBER(e);this.lenBlock.length=o.byteLength;let s=this.lenBlock.toBER(e);n.write(s),n.write(o)}return t?nr: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():se.Convert.ToHex(this.toBER())}onAsciiEncoding(){return`${this.constructor.NAME} : ${se.Convert.ToHex(this.valueBlock.valueBeforeDecodeView)}`}isEqual(e){if(this===e)return!0;if(!(e instanceof this.constructor))return!1;let t=this.toBER(),n=e.toBER();return m1(t,n)}};Ye.NAME="BaseBlock";function x1(r){if(r instanceof z.Constructed)for(let e of r.valueBlock.value)x1(e)&&(r.lenBlock.isIndefiniteForm=!0);return!!r.lenBlock.isIndefiniteForm}var lc=class extends Ye{constructor({value:e=wo,...t}={},n){super(t,n),e&&this.fromString(e)}getValue(){return this.valueBlock.value}setValue(e){this.valueBlock.value=e}fromBER(e,t,n){let i=this.valueBlock.fromBER(e,t,this.lenBlock.isIndefiniteForm?n:this.lenBlock.length);return i===-1?(this.error=this.valueBlock.error,i):(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),i)}onAsciiEncoding(){return`${this.constructor.NAME} : '${this.valueBlock.value}'`}};lc.NAME="BaseStringBlock";var uc=class extends Qr(tt){constructor({isHexOnly:e=!0,...t}={}){super(t),this.isHexOnly=e}};uc.NAME="PrimitiveValueBlock";var b1,dc=class extends Ye{constructor(e={}){super(e,uc),this.idBlock.isConstructed=!1}};b1=dc;z.Primitive=b1;dc.NAME="PRIMITIVE";function K6(r,e){if(r instanceof e)return r;let t=new e;return t.idBlock=r.idBlock,t.lenBlock=r.lenBlock,t.warnings=r.warnings,t.valueBeforeDecodeView=r.valueBeforeDecodeView,t}function Kc(r,e=0,t=r.length){let n=e,i=new Ye({},tt),o=new jr;if(!Jr(o,r,e,t))return i.error=o.error,{offset:-1,result:i};if(!r.subarray(e,e+t).length)return i.error="Zero buffer length",{offset:-1,result:i};let a=i.idBlock.fromBER(r,e,t);if(i.idBlock.warnings.length&&i.warnings.concat(i.idBlock.warnings),a===-1)return i.error=i.idBlock.error,{offset:-1,result:i};if(e=a,t-=i.idBlock.blockLength,a=i.lenBlock.fromBER(r,e,t),i.lenBlock.warnings.length&&i.warnings.concat(i.lenBlock.warnings),a===-1)return i.error=i.lenBlock.error,{offset:-1,result:i};if(e=a,t-=i.lenBlock.blockLength,!i.idBlock.isConstructed&&i.lenBlock.isIndefiniteForm)return i.error="Indefinite length form used for primitive encoding form",{offset:-1,result:i};let c=Ye;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};c=z.EndOfContent;break;case 1:c=z.Boolean;break;case 2:c=z.Integer;break;case 3:c=z.BitString;break;case 4:c=z.OctetString;break;case 5:c=z.Null;break;case 6:c=z.ObjectIdentifier;break;case 10:c=z.Enumerated;break;case 12:c=z.Utf8String;break;case 13:c=z.RelativeObjectIdentifier;break;case 14:c=z.TIME;break;case 15:return i.error="[UNIVERSAL 15] is reserved by ASN.1 standard",{offset:-1,result:i};case 16:c=z.Sequence;break;case 17:c=z.Set;break;case 18:c=z.NumericString;break;case 19:c=z.PrintableString;break;case 20:c=z.TeletexString;break;case 21:c=z.VideotexString;break;case 22:c=z.IA5String;break;case 23:c=z.UTCTime;break;case 24:c=z.GeneralizedTime;break;case 25:c=z.GraphicString;break;case 26:c=z.VisibleString;break;case 27:c=z.GeneralString;break;case 28:c=z.UniversalString;break;case 29:c=z.CharacterString;break;case 30:c=z.BmpString;break;case 31:c=z.DATE;break;case 32:c=z.TimeOfDay;break;case 33:c=z.DateTime;break;case 34:c=z.Duration;break;default:{let u=i.idBlock.isConstructed?new z.Constructed:new z.Primitive;u.idBlock=i.idBlock,u.lenBlock=i.lenBlock,u.warnings=i.warnings,i=u}}break;case 2:case 3:case 4:default:c=i.idBlock.isConstructed?z.Constructed:z.Primitive}return i=K6(i,c),a=i.fromBER(r,e,i.lenBlock.isIndefiniteForm?t:i.lenBlock.length),i.valueBeforeDecodeView=r.subarray(n,n+i.blockLength),{offset:a,result:i}}function Eo(r){if(!r.byteLength){let e=new Ye({},tt);return e.error="Input buffer has zero length",{offset:-1,result:e}}return Kc(se.BufferSourceConverter.toUint8Array(r).slice(),0,r.byteLength)}function G6(r,e){return r?1:e}var br=class extends tt{constructor({value:e=[],isIndefiniteForm:t=!1,...n}={}){super(n),this.value=e,this.isIndefiniteForm=t}fromBER(e,t,n){let i=se.BufferSourceConverter.toUint8Array(e);if(!Jr(this,i,t,n))return-1;if(this.valueBeforeDecodeView=i.subarray(t,t+n),this.valueBeforeDecodeView.length===0)return this.warnings.push("Zero buffer length"),t;let o=t;for(;G6(this.isIndefiniteForm,n)>0;){let s=Kc(i,o,n);if(s.offset===-1)return this.error=s.result.error,this.warnings.concat(s.result.warnings),-1;if(o=s.offset,this.blockLength+=s.result.blockLength,n-=s.result.blockLength,this.value.push(s.result),this.isIndefiniteForm&&s.result.constructor.NAME===hs)break}return this.isIndefiniteForm&&(this.value[this.value.length-1].constructor.NAME===hs?this.value.pop():this.warnings.push("No EndOfContent block encoded")),o}toBER(e,t){let n=t||new fs;for(let i=0;i<this.value.length;i++)this.value[i].toBER(e,n);return t?nr:n.final()}toJSON(){let e={...super.toJSON(),isIndefiniteForm:this.isIndefiniteForm,value:[]};for(let t of this.value)e.value.push(t.toJSON());return e}};br.NAME="ConstructedValueBlock";var v1,Pn=class extends Ye{constructor(e={}){super(e,br),this.idBlock.isConstructed=!0}fromBER(e,t,n){this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm;let i=this.valueBlock.fromBER(e,t,this.lenBlock.isIndefiniteForm?n:this.lenBlock.length);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(`
|
|
2
|
+
"use strict";var HeliaVerifiedFetch=(()=>{var ME=Object.create;var ba=Object.defineProperty;var HE=Object.getOwnPropertyDescriptor;var $E=Object.getOwnPropertyNames;var zE=Object.getPrototypeOf,KE=Object.prototype.hasOwnProperty;var le=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),Be=(r,e)=>{for(var t in e)ba(r,t,{get:e[t],enumerable:!0})},b0=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of $E(e))!KE.call(r,i)&&i!==t&&ba(r,i,{get:()=>e[i],enumerable:!(n=HE(e,i))||n.enumerable});return r};var Q=(r,e,t)=>(t=r!=null?ME(zE(r)):{},b0(e||!r||!r.__esModule?ba(t,"default",{value:r,enumerable:!0}):t,r)),GE=r=>b0(ba({},"__esModule",{value:!0}),r);var Du=le((wB,F0)=>{var qi=1e3,Yi=qi*60,Wi=Yi*60,ui=Wi*24,Dx=ui*7,Ox=ui*365.25;F0.exports=function(r,e){e=e||{};var t=typeof r;if(t==="string"&&r.length>0)return Px(r);if(t==="number"&&isFinite(r))return e.long?Vx(r):Fx(r);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(r))};function Px(r){if(r=String(r),!(r.length>100)){var e=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(r);if(e){var t=parseFloat(e[1]),n=(e[2]||"ms").toLowerCase();switch(n){case"years":case"year":case"yrs":case"yr":case"y":return t*Ox;case"weeks":case"week":case"w":return t*Dx;case"days":case"day":case"d":return t*ui;case"hours":case"hour":case"hrs":case"hr":case"h":return t*Wi;case"minutes":case"minute":case"mins":case"min":case"m":return t*Yi;case"seconds":case"second":case"secs":case"sec":case"s":return t*qi;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return t;default:return}}}}function Fx(r){var e=Math.abs(r);return e>=ui?Math.round(r/ui)+"d":e>=Wi?Math.round(r/Wi)+"h":e>=Yi?Math.round(r/Yi)+"m":e>=qi?Math.round(r/qi)+"s":r+"ms"}function Vx(r){var e=Math.abs(r);return e>=ui?Sa(r,e,ui,"day"):e>=Wi?Sa(r,e,Wi,"hour"):e>=Yi?Sa(r,e,Yi,"minute"):e>=qi?Sa(r,e,qi,"second"):r+" ms"}function Sa(r,e,t,n){var i=e>=t*1.5;return Math.round(r/t)+" "+n+(i?"s":"")}});var M0=le((EB,V0)=>{function Mx(r){t.debug=t,t.default=t,t.coerce=c,t.disable=o,t.enable=i,t.enabled=s,t.humanize=Du(),t.destroy=u,Object.keys(r).forEach(l=>{t[l]=r[l]}),t.names=[],t.skips=[],t.formatters={};function e(l){let d=0;for(let p=0;p<l.length;p++)d=(d<<5)-d+l.charCodeAt(p),d|=0;return t.colors[Math.abs(d)%t.colors.length]}t.selectColor=e;function t(l){let d,p=null,f,h;function m(...y){if(!m.enabled)return;let g=m,E=Number(new Date),x=E-(d||E);g.diff=x,g.prev=d,g.curr=E,d=E,y[0]=t.coerce(y[0]),typeof y[0]!="string"&&y.unshift("%O");let _=0;y[0]=y[0].replace(/%([a-zA-Z%])/g,(A,v)=>{if(A==="%%")return"%";_++;let b=t.formatters[v];if(typeof b=="function"){let T=y[_];A=b.call(g,T),y.splice(_,1),_--}return A}),t.formatArgs.call(g,y),(g.log||t.log).apply(g,y)}return m.namespace=l,m.useColors=t.useColors(),m.color=t.selectColor(l),m.extend=n,m.destroy=t.destroy,Object.defineProperty(m,"enabled",{enumerable:!0,configurable:!1,get:()=>p!==null?p:(f!==t.namespaces&&(f=t.namespaces,h=t.enabled(l)),h),set:y=>{p=y}}),typeof t.init=="function"&&t.init(m),m}function n(l,d){let p=t(this.namespace+(typeof d>"u"?":":d)+l);return p.log=this.log,p}function i(l){t.save(l),t.namespaces=l,t.names=[],t.skips=[];let d,p=(typeof l=="string"?l:"").split(/[\s,]+/),f=p.length;for(d=0;d<f;d++)p[d]&&(l=p[d].replace(/\*/g,".*?"),l[0]==="-"?t.skips.push(new RegExp("^"+l.slice(1)+"$")):t.names.push(new RegExp("^"+l+"$")))}function o(){let l=[...t.names.map(a),...t.skips.map(a).map(d=>"-"+d)].join(",");return t.enable(""),l}function s(l){if(l[l.length-1]==="*")return!0;let d,p;for(d=0,p=t.skips.length;d<p;d++)if(t.skips[d].test(l))return!1;for(d=0,p=t.names.length;d<p;d++)if(t.names[d].test(l))return!0;return!1}function a(l){return l.toString().substring(2,l.toString().length-2).replace(/\.\*\?$/,"*")}function c(l){return l instanceof Error?l.stack||l.message:l}function u(){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 t.enable(t.load()),t}V0.exports=Mx});var Ou=le((_t,Ia)=>{_t.formatArgs=$x;_t.save=zx;_t.load=Kx;_t.useColors=Hx;_t.storage=Gx();_t.destroy=(()=>{let r=!1;return()=>{r||(r=!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`."))}})();_t.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 Hx(){return typeof window<"u"&&window.process&&(window.process.type==="renderer"||window.process.__nwjs)?!0:typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)?!1: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&&navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)&&parseInt(RegExp.$1,10)>=31||typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)}function $x(r){if(r[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+r[0]+(this.useColors?"%c ":" ")+"+"+Ia.exports.humanize(this.diff),!this.useColors)return;let e="color: "+this.color;r.splice(1,0,e,"color: inherit");let t=0,n=0;r[0].replace(/%[a-zA-Z%]/g,i=>{i!=="%%"&&(t++,i==="%c"&&(n=t))}),r.splice(n,0,e)}_t.log=console.debug||console.log||(()=>{});function zx(r){try{r?_t.storage.setItem("debug",r):_t.storage.removeItem("debug")}catch{}}function Kx(){let r;try{r=_t.storage.getItem("debug")}catch{}return!r&&typeof process<"u"&&"env"in process&&(r=process.env.DEBUG),r}function Gx(){try{return localStorage}catch{}}Ia.exports=M0()(_t);var{formatters:qx}=Ia.exports;qx.j=function(r){try{return JSON.stringify(r)}catch(e){return"[UnexpectedJSONParseError]: "+e.message}}});var G0=le((IB,K0)=>{K0.exports=Fu;var z0=128,Xx=127,Zx=~Xx,Jx=Math.pow(2,31);function Fu(r,e,t){if(Number.MAX_SAFE_INTEGER&&r>Number.MAX_SAFE_INTEGER)throw Fu.bytes=0,new RangeError("Could not encode varint");e=e||[],t=t||0;for(var n=t;r>=Jx;)e[t++]=r&255|z0,r/=128;for(;r&Zx;)e[t++]=r&255|z0,r>>>=7;return e[t]=r|0,Fu.bytes=t-n+1,e}});var W0=le((BB,Y0)=>{Y0.exports=Vu;var Qx=128,q0=127;function Vu(r,n){var t=0,n=n||0,i=0,o=n,s,a=r.length;do{if(o>=a||i>49)throw Vu.bytes=0,new RangeError("Could not decode varint");s=r[o++],t+=i<28?(s&q0)<<i:(s&q0)*Math.pow(2,i),i+=7}while(s>=Qx);return Vu.bytes=o-n,t}});var X0=le((kB,j0)=>{var eb=Math.pow(2,7),tb=Math.pow(2,14),rb=Math.pow(2,21),nb=Math.pow(2,28),ib=Math.pow(2,35),ob=Math.pow(2,42),sb=Math.pow(2,49),ab=Math.pow(2,56),cb=Math.pow(2,63);j0.exports=function(r){return r<eb?1:r<tb?2:r<rb?3:r<nb?4:r<ib?5:r<ob?6:r<sb?7:r<ab?8:r<cb?9:10}});var Ba=le((RB,Z0)=>{Z0.exports={encode:G0(),decode:W0(),encodingLength:X0()}});var Ce=le((Y8,yp)=>{"use strict";function mp(r,e){for(let t in e)Object.defineProperty(r,t,{value:e[t],enumerable:!0,configurable:!0});return r}function zb(r,e,t){if(!r||typeof r=="string")throw new TypeError("Please pass an Error to err-code");t||(t={}),typeof e=="object"&&(t=e,e=""),e&&(t.code=e);try{return mp(r,t)}catch{t.message=r.message,t.stack=r.stack;let i=function(){};return i.prototype=Object.create(Object.getPrototypeOf(r)),mp(new i,t)}}yp.exports=zb});var f1=le(mo=>{"use strict";var U6="[object ArrayBuffer]",Wr=class r{static isArrayBuffer(e){return Object.prototype.toString.call(e)===U6}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,t){if(e.constructor===t)return e;if(this.isArrayBuffer(e))return new t(e);if(this.isArrayBufferView(e))return new t(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,t){let n=r.toUint8Array(e),i=r.toUint8Array(t);if(n.length!==i.byteLength)return!1;for(let o=0;o<n.length;o++)if(n[o]!==i[o])return!1;return!0}static concat(...e){let t;Array.isArray(e[0])&&!(e[1]instanceof Function)||Array.isArray(e[0])&&e[1]instanceof Function?t=e[0]:e[e.length-1]instanceof Function?t=e.slice(0,e.length-1):t=e;let n=0;for(let s of t)n+=s.byteLength;let i=new Uint8Array(n),o=0;for(let s of t){let a=this.toUint8Array(s);i.set(a,o),o+=a.length}return e[e.length-1]instanceof Function?this.toView(i,e[e.length-1]):i.buffer}},Wd="string",D6=/^[0-9a-f]+$/i,O6=/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/,P6=/^[a-zA-Z0-9-_]+$/,nc=class{static fromString(e){let t=unescape(encodeURIComponent(e)),n=new Uint8Array(t.length);for(let i=0;i<t.length;i++)n[i]=t.charCodeAt(i);return n.buffer}static toString(e){let t=Wr.toUint8Array(e),n="";for(let o=0;o<t.length;o++)n+=String.fromCharCode(t[o]);return decodeURIComponent(escape(n))}},Gt=class{static toString(e,t=!1){let n=Wr.toArrayBuffer(e),i=new DataView(n),o="";for(let s=0;s<n.byteLength;s+=2){let a=i.getUint16(s,t);o+=String.fromCharCode(a)}return o}static fromString(e,t=!1){let n=new ArrayBuffer(e.length*2),i=new DataView(n);for(let o=0;o<e.length;o++)i.setUint16(o*2,e.charCodeAt(o),t);return n}},ic=class r{static isHex(e){return typeof e===Wd&&D6.test(e)}static isBase64(e){return typeof e===Wd&&O6.test(e)}static isBase64Url(e){return typeof e===Wd&&P6.test(e)}static ToString(e,t="utf8"){let n=Wr.toUint8Array(e);switch(t.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 Gt.toString(n,!0);case"utf16":case"utf16be":return Gt.toString(n);default:throw new Error(`Unknown type of encoding '${t}'`)}}static FromString(e,t="utf8"){if(!e)return new ArrayBuffer(0);switch(t.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 Gt.fromString(e,!0);case"utf16":case"utf16be":return Gt.fromString(e);default:throw new Error(`Unknown type of encoding '${t}'`)}}static ToBase64(e){let t=Wr.toUint8Array(e);if(typeof btoa<"u"){let n=this.ToString(t,"binary");return btoa(n)}else return Buffer.from(t).toString("base64")}static FromBase64(e){let t=this.formatString(e);if(!t)return new ArrayBuffer(0);if(!r.isBase64(t))throw new TypeError("Argument 'base64Text' is not Base64 encoded");return typeof atob<"u"?this.FromBinary(atob(t)):new Uint8Array(Buffer.from(t,"base64")).buffer}static FromBase64Url(e){let t=this.formatString(e);if(!t)return new ArrayBuffer(0);if(!r.isBase64Url(t))throw new TypeError("Argument 'base64url' is not Base64Url encoded");return this.FromBase64(this.Base64Padding(t.replace(/\-/g,"+").replace(/\_/g,"/")))}static ToBase64Url(e){return this.ToBase64(e).replace(/\+/g,"-").replace(/\//g,"_").replace(/\=/g,"")}static FromUtf8String(e,t=r.DEFAULT_UTF8_ENCODING){switch(t){case"ascii":return this.FromBinary(e);case"utf8":return nc.fromString(e);case"utf16":case"utf16be":return Gt.fromString(e);case"utf16le":case"usc2":return Gt.fromString(e,!0);default:throw new Error(`Unknown type of encoding '${t}'`)}}static ToUtf8String(e,t=r.DEFAULT_UTF8_ENCODING){switch(t){case"ascii":return this.ToBinary(e);case"utf8":return nc.toString(e);case"utf16":case"utf16be":return Gt.toString(e);case"utf16le":case"usc2":return Gt.toString(e,!0);default:throw new Error(`Unknown type of encoding '${t}'`)}}static FromBinary(e){let t=e.length,n=new Uint8Array(t);for(let i=0;i<t;i++)n[i]=e.charCodeAt(i);return n.buffer}static ToBinary(e){let t=Wr.toUint8Array(e),n="";for(let i=0;i<t.length;i++)n+=String.fromCharCode(t[i]);return n}static ToHex(e){let t=Wr.toUint8Array(e),n="",i=t.length;for(let o=0;o<i;o++){let s=t[o];s<16&&(n+="0"),n+=s.toString(16)}return n}static FromHex(e){let t=this.formatString(e);if(!t)return new ArrayBuffer(0);if(!r.isHex(t))throw new TypeError("Argument 'hexString' is not HEX encoded");t.length%2&&(t=`0${t}`);let n=new Uint8Array(t.length/2);for(let i=0;i<t.length;i=i+2){let o=t.slice(i,i+2);n[i/2]=parseInt(o,16)}return n.buffer}static ToUtf16String(e,t=!1){return Gt.toString(e,t)}static FromUtf16String(e,t=!1){return Gt.fromString(e,t)}static Base64Padding(e){let t=4-e.length%4;if(t<4)for(let n=0;n<t;n++)e+="=";return e}static formatString(e){return e?.replace(/[\n\r\t ]/g,"")||""}};ic.DEFAULT_UTF8_ENCODING="utf8";function F6(r,...e){let t=arguments[0];for(let n=1;n<arguments.length;n++){let i=arguments[n];for(let o in i)t[o]=i[o]}return t}function V6(...r){let e=r.map(i=>i.byteLength).reduce((i,o)=>i+o),t=new Uint8Array(e),n=0;return r.map(i=>new Uint8Array(i)).forEach(i=>{for(let o of i)t[n++]=o}),t.buffer}function M6(r,e){if(!(r&&e)||r.byteLength!==e.byteLength)return!1;let t=new Uint8Array(r),n=new Uint8Array(e);for(let i=0;i<r.byteLength;i++)if(t[i]!==n[i])return!1;return!0}mo.BufferSourceConverter=Wr;mo.Convert=ic;mo.assign=F6;mo.combine=V6;mo.isEqual=M6});var Yc=le((uN,uf)=>{var lN=function(){typeof uf<"u"&&(uf.exports=m);var r=86400,e=3200,t=146097*e/400,n=r*t,i=1e3*n,o=864e13,s=4294967296,a=1e6,c="000000000",u=Math.trunc||function(b){var T=b-b%1;return T==0&&(b<0||b===0&&1/b!=1/0)?-0:T},l=m.prototype,d=(m.fromDate=function(b){return new m(+b)},m.fromInt64BE=_(0,1,2,3,0,4),m.fromInt64LE=_(3,2,1,0,4,0),m.fromString=function(N){var T,C=new m,N=(N+="").replace(/^\s*[+\-]?\d+/,function(D){var D=+D,ne=1970+(D-1970)%400;return C.year=D-ne,ne}).replace(/(?:Z|([+\-]\d{2}):?(\d{2}))$/,function($,D,ne){return D<0&&(ne*=-1),T=6e4*(60*+D+ +ne),""}).replace(/\.\d+$/,function($){return C.nano=+($+c).substr(1,9),""}).split(/\D+/);if(1<N.length?N[1]--:N[1]=0,C.time=T=Date.UTC.apply(Date,N)-(T||0),isNaN(T))throw new TypeError("Invalid Date");return y(C)},m.fromTimeT=function(b){return E(b,0)},l.year=0,l.time=0,l.nano=0,l.addNano=function(b){return this.nano+=+b||0,this},l.getNano=function(){var b=y(this);return(b.time%1e3*a+ +b.nano+1e9)%1e9},l.getTimeT=function(){var T=y(this),b=Math.floor(T.time/1e3),T=T.year;return T&&(b+=T*t*r/e),b},l.getYear=function(){return this.toDate().getUTCFullYear()+this.year},l.toDate=function(){return g(y(this).time)},l.toJSON=function(){return this.toString().replace(/0{1,6}Z$/,"Z")},l.toString=function(b){var T=this,C=T.toDate(),N={H:function(){return A(C.getUTCHours())},L:function(){return v(C.getUTCMilliseconds(),3)},M:function(){return A(C.getUTCMinutes())},N:function(){return v(T.getNano(),9)},S:function(){return A(C.getUTCSeconds())},Y:function(){var $=T.getYear();return 999999<$?"+"+$:9999<$?"+"+v($,6):0<=$?v($,4):-999999<=$?"-"+v(-$,6):$},a:function(){return f[C.getUTCDay()]},b:function(){return p[C.getUTCMonth()]},d:function(){return A(C.getUTCDate())},e:function(){return function($){return(9<$?"":" ")+(0|$)}(C.getUTCDate())},m:function(){return A(C.getUTCMonth()+1)}};return function $(D){return D.replace(/%./g,function(ne){var U=ne[1],B=h[U],U=N[U];return B?$(B):U?U():ne})}(b||d)},l.writeInt64BE=x(0,1,2,3,0,4),l.writeInt64LE=x(3,2,1,0,4,0),"%Y-%m-%dT%H:%M:%S.%NZ"),p=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],f=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],h={"%":"%",F:"%Y-%m-%d",n:`
|
|
3
|
+
`,R:"%H:%M",T:"%H:%M:%S",t:" ",X:"%T",Z:"GMT",z:"+0000"};return m;function m(b,T,C){var N=this;if(!(N instanceof m))return new m(b,T,C);N.time=+b||0,N.nano=+T||0,N.year=+C||0,y(N)}function y(b){var T,C,N,$=b.year,D=b.time,ne=b.nano,B=((ne<0||a<=ne)&&(ne-=(C=Math.floor(ne/a))*a,D+=C,C=1),$%e);return(D<-o||o<D||B)&&((T=u(D/i))&&($+=T*e,D-=T*i),(N=g(D)).setUTCFullYear(B+N.getUTCFullYear()),N=(D=+N)+(T=u(($-=B)/e))*i,T&&-o<=N&&N<=o&&($-=T*e,D=N),C=1),C&&(b.year=$,b.time=D,b.nano=ne),b}function g(b){var T=new Date(0);return T.setTime(b),T}function E($,N){$=+$||0;var C=u((N=(N|0)*s)/n)+u($/n),N=N%n+$%n,$=u(N/n);return $&&(C+=$,N-=$*n),new m(1e3*N,0,C*e)}function x(b,T,C,N,$,D){return function(B,U){var L=y(this);B=B||new Array(8),S(B,U|=0);var k=Math.floor(L.time/1e3),L=L.year*(t*r/e),X=u(L/s)+u(k/s),L=L%s+k%s,k=Math.floor(L/s);return k&&(X+=k,L-=k*s),ne(B,U+$,X),ne(B,U+D,L),B};function ne(B,U,X){B[U+b]=X>>24&255,B[U+T]=X>>16&255,B[U+C]=X>>8&255,B[U+N]=255&X}}function _(b,T,C,N,$,D){return function(B,U){S(B,U|=0);var X=ne(B,U+$);return E(ne(B,U+D),X)};function ne(B,U){return 16777216*B[U+b]+(B[U+T]<<16|B[U+C]<<8|B[U+N])}}function S(b,T){if(b=b&&b.length,b==null)throw new TypeError("Invalid Buffer");if(b<T+8)throw new RangeError("Out of range")}function A(b){return(9<b?"":"0")+(0|b)}function v(b,T){return(c+(0|b)).substr(-T)}}()});var My=le((YC,If)=>{"use strict";var oA=Object.prototype.hasOwnProperty,ft="~";function Ds(){}Object.create&&(Ds.prototype=Object.create(null),new Ds().__proto__||(ft=!1));function sA(r,e,t){this.fn=r,this.context=e,this.once=t||!1}function Vy(r,e,t,n,i){if(typeof t!="function")throw new TypeError("The listener must be a function");var o=new sA(t,n||r,i),s=ft?ft+e:e;return r._events[s]?r._events[s].fn?r._events[s]=[r._events[s],o]:r._events[s].push(o):(r._events[s]=o,r._eventsCount++),r}function ll(r,e){--r._eventsCount===0?r._events=new Ds:delete r._events[e]}function rt(){this._events=new Ds,this._eventsCount=0}rt.prototype.eventNames=function(){var e=[],t,n;if(this._eventsCount===0)return e;for(n in t=this._events)oA.call(t,n)&&e.push(ft?n.slice(1):n);return Object.getOwnPropertySymbols?e.concat(Object.getOwnPropertySymbols(t)):e};rt.prototype.listeners=function(e){var t=ft?ft+e:e,n=this._events[t];if(!n)return[];if(n.fn)return[n.fn];for(var i=0,o=n.length,s=new Array(o);i<o;i++)s[i]=n[i].fn;return s};rt.prototype.listenerCount=function(e){var t=ft?ft+e:e,n=this._events[t];return n?n.fn?1:n.length:0};rt.prototype.emit=function(e,t,n,i,o,s){var a=ft?ft+e:e;if(!this._events[a])return!1;var c=this._events[a],u=arguments.length,l,d;if(c.fn){switch(c.once&&this.removeListener(e,c.fn,void 0,!0),u){case 1:return c.fn.call(c.context),!0;case 2:return c.fn.call(c.context,t),!0;case 3:return c.fn.call(c.context,t,n),!0;case 4:return c.fn.call(c.context,t,n,i),!0;case 5:return c.fn.call(c.context,t,n,i,o),!0;case 6:return c.fn.call(c.context,t,n,i,o,s),!0}for(d=1,l=new Array(u-1);d<u;d++)l[d-1]=arguments[d];c.fn.apply(c.context,l)}else{var p=c.length,f;for(d=0;d<p;d++)switch(c[d].once&&this.removeListener(e,c[d].fn,void 0,!0),u){case 1:c[d].fn.call(c[d].context);break;case 2:c[d].fn.call(c[d].context,t);break;case 3:c[d].fn.call(c[d].context,t,n);break;case 4:c[d].fn.call(c[d].context,t,n,i);break;default:if(!l)for(f=1,l=new Array(u-1);f<u;f++)l[f-1]=arguments[f];c[d].fn.apply(c[d].context,l)}}return!0};rt.prototype.on=function(e,t,n){return Vy(this,e,t,n,!1)};rt.prototype.once=function(e,t,n){return Vy(this,e,t,n,!0)};rt.prototype.removeListener=function(e,t,n,i){var o=ft?ft+e:e;if(!this._events[o])return this;if(!t)return ll(this,o),this;var s=this._events[o];if(s.fn)s.fn===t&&(!i||s.once)&&(!n||s.context===n)&&ll(this,o);else{for(var a=0,c=[],u=s.length;a<u;a++)(s[a].fn!==t||i&&!s[a].once||n&&s[a].context!==n)&&c.push(s[a]);c.length?this._events[o]=c.length===1?c[0]:c:ll(this,o)}return this};rt.prototype.removeAllListeners=function(e){var t;return e?(t=ft?ft+e:e,this._events[t]&&ll(this,t)):(this._events=new Ds,this._eventsCount=0),this};rt.prototype.off=rt.prototype.removeListener;rt.prototype.addListener=rt.prototype.on;rt.prefixed=ft;rt.EventEmitter=rt;typeof If<"u"&&(If.exports=rt)});var Vg=le((S7,Fg)=>{"use strict";Fg.exports=Pg;var E_=Du(),Jn=Pg.prototype,x_=new Date%1e9;function b_(){return(Math.random()*1e9>>>0)+x_++}function Pg(r){r=r||{},this.id=r.id||b_(),this.max=r.max||1/0,this.items=r.items||[],this._lookup={},this.size=this.items.length,this.lastModified=new Date(r.lastModified||new Date);for(var e,t,n=this.items.length;n--;)e=this.items[n],t=new Date(e.expires)-new Date,this._lookup[e.key]=e,t>0?this.expire(e.key,t):t<=0&&this.delete(e.key)}Jn.has=function(r){return r in this._lookup};Jn.get=function(r){if(!this.has(r))return null;var e=this._lookup[r];return e.refresh&&this.expire(r,e.refresh),this.items.splice(this.items.indexOf(e),1),this.items.push(e),e.value};Jn.meta=function(r){if(!this.has(r))return null;var e=this._lookup[r];return"meta"in e?e.meta:null};Jn.set=function(r,e,t){var n=this._lookup[r],i=this._lookup[r]={key:r,value:e};return this.lastModified=new Date,n?(clearTimeout(n.timeout),this.items.splice(this.items.indexOf(n),1,i)):(this.size>=this.max&&this.delete(this.items[0].key),this.items.push(i),this.size++),t&&("ttl"in t&&this.expire(r,t.ttl),"meta"in t&&(i.meta=t.meta),t.refresh&&(i.refresh=t.ttl)),this};Jn.delete=function(r){var e=this._lookup[r];return e?(this.lastModified=new Date,this.items.splice(this.items.indexOf(e),1),clearTimeout(e.timeout),delete this._lookup[r],this.size--,this):!1};Jn.expire=function(r,e){var t=e||0,n=this._lookup[r];if(!n)return this;if(typeof t=="string"&&(t=E_(e)),typeof t!="number")throw new TypeError("Expiration time must be a string or number.");return clearTimeout(n.timeout),n.timeout=setTimeout(this.delete.bind(this,n.key),t),n.expires=Number(new Date)+t,this};Jn.clear=function(){for(var r=this.items.length;r--;)this.delete(this.items[r].key);return this};Jn.toJSON=function(){for(var r=new Array(this.items.length),e,t=r.length;t--;)e=this.items[t],r[t]={key:e.key,meta:e.meta,value:e.value,expires:e.expires,refresh:e.refresh};return{id:this.id,max:isFinite(this.max)?this.max:void 0,lastModified:this.lastModified,items:r}}});var yh=le((B7,$g)=>{$g.exports=function(r){if(!r)throw Error("hashlru must have a max value, of type number, greater than 0");var e=0,t=Object.create(null),n=Object.create(null);function i(o,s){t[o]=s,e++,e>=r&&(e=0,n=t,t=Object.create(null))}return{has:function(o){return t[o]!==void 0||n[o]!==void 0},remove:function(o){t[o]!==void 0&&(t[o]=void 0),n[o]!==void 0&&(n[o]=void 0)},get:function(o){var s=t[o];if(s!==void 0)return s;if((s=n[o])!==void 0)return i(o,s),s},set:function(o,s){t[o]!==void 0?t[o]=s:i(o,s)},clear:function(){t=Object.create(null),n=Object.create(null)}}}});var rw=le(Dl=>{"use strict";Dl.byteLength=T_;Dl.toByteArray=C_;Dl.fromByteArray=D_;var Ir=[],jt=[],R_=typeof Uint8Array<"u"?Uint8Array:Array,vh="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(Ni=0,ew=vh.length;Ni<ew;++Ni)Ir[Ni]=vh[Ni],jt[vh.charCodeAt(Ni)]=Ni;var Ni,ew;jt[45]=62;jt[95]=63;function tw(r){var e=r.length;if(e%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var t=r.indexOf("=");t===-1&&(t=e);var n=t===e?0:4-t%4;return[t,n]}function T_(r){var e=tw(r),t=e[0],n=e[1];return(t+n)*3/4-n}function N_(r,e,t){return(e+t)*3/4-t}function C_(r){var e,t=tw(r),n=t[0],i=t[1],o=new R_(N_(r,n,i)),s=0,a=i>0?n-4:n,c;for(c=0;c<a;c+=4)e=jt[r.charCodeAt(c)]<<18|jt[r.charCodeAt(c+1)]<<12|jt[r.charCodeAt(c+2)]<<6|jt[r.charCodeAt(c+3)],o[s++]=e>>16&255,o[s++]=e>>8&255,o[s++]=e&255;return i===2&&(e=jt[r.charCodeAt(c)]<<2|jt[r.charCodeAt(c+1)]>>4,o[s++]=e&255),i===1&&(e=jt[r.charCodeAt(c)]<<10|jt[r.charCodeAt(c+1)]<<4|jt[r.charCodeAt(c+2)]>>2,o[s++]=e>>8&255,o[s++]=e&255),o}function L_(r){return Ir[r>>18&63]+Ir[r>>12&63]+Ir[r>>6&63]+Ir[r&63]}function U_(r,e,t){for(var n,i=[],o=e;o<t;o+=3)n=(r[o]<<16&16711680)+(r[o+1]<<8&65280)+(r[o+2]&255),i.push(L_(n));return i.join("")}function D_(r){for(var e,t=r.length,n=t%3,i=[],o=16383,s=0,a=t-n;s<a;s+=o)i.push(U_(r,s,s+o>a?a:s+o));return n===1?(e=r[t-1],i.push(Ir[e>>2]+Ir[e<<4&63]+"==")):n===2&&(e=(r[t-2]<<8)+r[t-1],i.push(Ir[e>>10]+Ir[e>>4&63]+Ir[e<<2&63]+"=")),i.join("")}});var nw=le(Ah=>{Ah.read=function(r,e,t,n,i){var o,s,a=i*8-n-1,c=(1<<a)-1,u=c>>1,l=-7,d=t?i-1:0,p=t?-1:1,f=r[e+d];for(d+=p,o=f&(1<<-l)-1,f>>=-l,l+=a;l>0;o=o*256+r[e+d],d+=p,l-=8);for(s=o&(1<<-l)-1,o>>=-l,l+=n;l>0;s=s*256+r[e+d],d+=p,l-=8);if(o===0)o=1-u;else{if(o===c)return s?NaN:(f?-1:1)*(1/0);s=s+Math.pow(2,n),o=o-u}return(f?-1:1)*s*Math.pow(2,o-n)};Ah.write=function(r,e,t,n,i,o){var s,a,c,u=o*8-i-1,l=(1<<u)-1,d=l>>1,p=i===23?Math.pow(2,-24)-Math.pow(2,-77):0,f=n?0:o-1,h=n?1:-1,m=e<0||e===0&&1/e<0?1:0;for(e=Math.abs(e),isNaN(e)||e===1/0?(a=isNaN(e)?1:0,s=l):(s=Math.floor(Math.log(e)/Math.LN2),e*(c=Math.pow(2,-s))<1&&(s--,c*=2),s+d>=1?e+=p/c:e+=p*Math.pow(2,1-d),e*c>=2&&(s++,c/=2),s+d>=l?(a=0,s=l):s+d>=1?(a=(e*c-1)*Math.pow(2,i),s=s+d):(a=e*Math.pow(2,d-1)*Math.pow(2,i),s=0));i>=8;r[t+f]=a&255,f+=h,a/=256,i-=8);for(s=s<<i|a,u+=i;u>0;r[t+f]=s&255,f+=h,s/=256,u-=8);r[t+f-h]|=m*128}});var Ch=le(Oo=>{"use strict";var _h=rw(),Uo=nw(),iw=typeof Symbol=="function"&&typeof Symbol.for=="function"?Symbol.for("nodejs.util.inspect.custom"):null;Oo.Buffer=I;Oo.SlowBuffer=H_;Oo.INSPECT_MAX_BYTES=50;var Ol=2147483647;Oo.kMaxLength=Ol;I.TYPED_ARRAY_SUPPORT=O_();!I.TYPED_ARRAY_SUPPORT&&typeof console<"u"&&typeof console.error=="function"&&console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support.");function O_(){try{let r=new Uint8Array(1),e={foo:function(){return 42}};return Object.setPrototypeOf(e,Uint8Array.prototype),Object.setPrototypeOf(r,e),r.foo()===42}catch{return!1}}Object.defineProperty(I.prototype,"parent",{enumerable:!0,get:function(){if(I.isBuffer(this))return this.buffer}});Object.defineProperty(I.prototype,"offset",{enumerable:!0,get:function(){if(I.isBuffer(this))return this.byteOffset}});function ln(r){if(r>Ol)throw new RangeError('The value "'+r+'" is invalid for option "size"');let e=new Uint8Array(r);return Object.setPrototypeOf(e,I.prototype),e}function I(r,e,t){if(typeof r=="number"){if(typeof e=="string")throw new TypeError('The "string" argument must be of type string. Received type number');return kh(r)}return cw(r,e,t)}I.poolSize=8192;function cw(r,e,t){if(typeof r=="string")return F_(r,e);if(ArrayBuffer.isView(r))return V_(r);if(r==null)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof r);if(Br(r,ArrayBuffer)||r&&Br(r.buffer,ArrayBuffer)||typeof SharedArrayBuffer<"u"&&(Br(r,SharedArrayBuffer)||r&&Br(r.buffer,SharedArrayBuffer)))return Ih(r,e,t);if(typeof r=="number")throw new TypeError('The "value" argument must not be of type number. Received type number');let n=r.valueOf&&r.valueOf();if(n!=null&&n!==r)return I.from(n,e,t);let i=M_(r);if(i)return i;if(typeof Symbol<"u"&&Symbol.toPrimitive!=null&&typeof r[Symbol.toPrimitive]=="function")return I.from(r[Symbol.toPrimitive]("string"),e,t);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof r)}I.from=function(r,e,t){return cw(r,e,t)};Object.setPrototypeOf(I.prototype,Uint8Array.prototype);Object.setPrototypeOf(I,Uint8Array);function lw(r){if(typeof r!="number")throw new TypeError('"size" argument must be of type number');if(r<0)throw new RangeError('The value "'+r+'" is invalid for option "size"')}function P_(r,e,t){return lw(r),r<=0?ln(r):e!==void 0?typeof t=="string"?ln(r).fill(e,t):ln(r).fill(e):ln(r)}I.alloc=function(r,e,t){return P_(r,e,t)};function kh(r){return lw(r),ln(r<0?0:Rh(r)|0)}I.allocUnsafe=function(r){return kh(r)};I.allocUnsafeSlow=function(r){return kh(r)};function F_(r,e){if((typeof e!="string"||e==="")&&(e="utf8"),!I.isEncoding(e))throw new TypeError("Unknown encoding: "+e);let t=uw(r,e)|0,n=ln(t),i=n.write(r,e);return i!==t&&(n=n.slice(0,i)),n}function Sh(r){let e=r.length<0?0:Rh(r.length)|0,t=ln(e);for(let n=0;n<e;n+=1)t[n]=r[n]&255;return t}function V_(r){if(Br(r,Uint8Array)){let e=new Uint8Array(r);return Ih(e.buffer,e.byteOffset,e.byteLength)}return Sh(r)}function Ih(r,e,t){if(e<0||r.byteLength<e)throw new RangeError('"offset" is outside of buffer bounds');if(r.byteLength<e+(t||0))throw new RangeError('"length" is outside of buffer bounds');let n;return e===void 0&&t===void 0?n=new Uint8Array(r):t===void 0?n=new Uint8Array(r,e):n=new Uint8Array(r,e,t),Object.setPrototypeOf(n,I.prototype),n}function M_(r){if(I.isBuffer(r)){let e=Rh(r.length)|0,t=ln(e);return t.length===0||r.copy(t,0,0,e),t}if(r.length!==void 0)return typeof r.length!="number"||Nh(r.length)?ln(0):Sh(r);if(r.type==="Buffer"&&Array.isArray(r.data))return Sh(r.data)}function Rh(r){if(r>=Ol)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+Ol.toString(16)+" bytes");return r|0}function H_(r){return+r!=r&&(r=0),I.alloc(+r)}I.isBuffer=function(e){return e!=null&&e._isBuffer===!0&&e!==I.prototype};I.compare=function(e,t){if(Br(e,Uint8Array)&&(e=I.from(e,e.offset,e.byteLength)),Br(t,Uint8Array)&&(t=I.from(t,t.offset,t.byteLength)),!I.isBuffer(e)||!I.isBuffer(t))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(e===t)return 0;let n=e.length,i=t.length;for(let o=0,s=Math.min(n,i);o<s;++o)if(e[o]!==t[o]){n=e[o],i=t[o];break}return n<i?-1:i<n?1:0};I.isEncoding=function(e){switch(String(e).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}};I.concat=function(e,t){if(!Array.isArray(e))throw new TypeError('"list" argument must be an Array of Buffers');if(e.length===0)return I.alloc(0);let n;if(t===void 0)for(t=0,n=0;n<e.length;++n)t+=e[n].length;let i=I.allocUnsafe(t),o=0;for(n=0;n<e.length;++n){let s=e[n];if(Br(s,Uint8Array))o+s.length>i.length?(I.isBuffer(s)||(s=I.from(s)),s.copy(i,o)):Uint8Array.prototype.set.call(i,s,o);else if(I.isBuffer(s))s.copy(i,o);else throw new TypeError('"list" argument must be an Array of Buffers');o+=s.length}return i};function uw(r,e){if(I.isBuffer(r))return r.length;if(ArrayBuffer.isView(r)||Br(r,ArrayBuffer))return r.byteLength;if(typeof r!="string")throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof r);let t=r.length,n=arguments.length>2&&arguments[2]===!0;if(!n&&t===0)return 0;let i=!1;for(;;)switch(e){case"ascii":case"latin1":case"binary":return t;case"utf8":case"utf-8":return Bh(r).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return t*2;case"hex":return t>>>1;case"base64":return Ew(r).length;default:if(i)return n?-1:Bh(r).length;e=(""+e).toLowerCase(),i=!0}}I.byteLength=uw;function $_(r,e,t){let n=!1;if((e===void 0||e<0)&&(e=0),e>this.length||((t===void 0||t>this.length)&&(t=this.length),t<=0)||(t>>>=0,e>>>=0,t<=e))return"";for(r||(r="utf8");;)switch(r){case"hex":return J_(this,e,t);case"utf8":case"utf-8":return fw(this,e,t);case"ascii":return X_(this,e,t);case"latin1":case"binary":return Z_(this,e,t);case"base64":return W_(this,e,t);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return Q_(this,e,t);default:if(n)throw new TypeError("Unknown encoding: "+r);r=(r+"").toLowerCase(),n=!0}}I.prototype._isBuffer=!0;function Ci(r,e,t){let n=r[e];r[e]=r[t],r[t]=n}I.prototype.swap16=function(){let e=this.length;if(e%2!==0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(let t=0;t<e;t+=2)Ci(this,t,t+1);return this};I.prototype.swap32=function(){let e=this.length;if(e%4!==0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(let t=0;t<e;t+=4)Ci(this,t,t+3),Ci(this,t+1,t+2);return this};I.prototype.swap64=function(){let e=this.length;if(e%8!==0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(let t=0;t<e;t+=8)Ci(this,t,t+7),Ci(this,t+1,t+6),Ci(this,t+2,t+5),Ci(this,t+3,t+4);return this};I.prototype.toString=function(){let e=this.length;return e===0?"":arguments.length===0?fw(this,0,e):$_.apply(this,arguments)};I.prototype.toLocaleString=I.prototype.toString;I.prototype.equals=function(e){if(!I.isBuffer(e))throw new TypeError("Argument must be a Buffer");return this===e?!0:I.compare(this,e)===0};I.prototype.inspect=function(){let e="",t=Oo.INSPECT_MAX_BYTES;return e=this.toString("hex",0,t).replace(/(.{2})/g,"$1 ").trim(),this.length>t&&(e+=" ... "),"<Buffer "+e+">"};iw&&(I.prototype[iw]=I.prototype.inspect);I.prototype.compare=function(e,t,n,i,o){if(Br(e,Uint8Array)&&(e=I.from(e,e.offset,e.byteLength)),!I.isBuffer(e))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof e);if(t===void 0&&(t=0),n===void 0&&(n=e?e.length:0),i===void 0&&(i=0),o===void 0&&(o=this.length),t<0||n>e.length||i<0||o>this.length)throw new RangeError("out of range index");if(i>=o&&t>=n)return 0;if(i>=o)return-1;if(t>=n)return 1;if(t>>>=0,n>>>=0,i>>>=0,o>>>=0,this===e)return 0;let s=o-i,a=n-t,c=Math.min(s,a),u=this.slice(i,o),l=e.slice(t,n);for(let d=0;d<c;++d)if(u[d]!==l[d]){s=u[d],a=l[d];break}return s<a?-1:a<s?1:0};function dw(r,e,t,n,i){if(r.length===0)return-1;if(typeof t=="string"?(n=t,t=0):t>2147483647?t=2147483647:t<-2147483648&&(t=-2147483648),t=+t,Nh(t)&&(t=i?0:r.length-1),t<0&&(t=r.length+t),t>=r.length){if(i)return-1;t=r.length-1}else if(t<0)if(i)t=0;else return-1;if(typeof e=="string"&&(e=I.from(e,n)),I.isBuffer(e))return e.length===0?-1:ow(r,e,t,n,i);if(typeof e=="number")return e=e&255,typeof Uint8Array.prototype.indexOf=="function"?i?Uint8Array.prototype.indexOf.call(r,e,t):Uint8Array.prototype.lastIndexOf.call(r,e,t):ow(r,[e],t,n,i);throw new TypeError("val must be string, number or Buffer")}function ow(r,e,t,n,i){let o=1,s=r.length,a=e.length;if(n!==void 0&&(n=String(n).toLowerCase(),n==="ucs2"||n==="ucs-2"||n==="utf16le"||n==="utf-16le")){if(r.length<2||e.length<2)return-1;o=2,s/=2,a/=2,t/=2}function c(l,d){return o===1?l[d]:l.readUInt16BE(d*o)}let u;if(i){let l=-1;for(u=t;u<s;u++)if(c(r,u)===c(e,l===-1?0:u-l)){if(l===-1&&(l=u),u-l+1===a)return l*o}else l!==-1&&(u-=u-l),l=-1}else for(t+a>s&&(t=s-a),u=t;u>=0;u--){let l=!0;for(let d=0;d<a;d++)if(c(r,u+d)!==c(e,d)){l=!1;break}if(l)return u}return-1}I.prototype.includes=function(e,t,n){return this.indexOf(e,t,n)!==-1};I.prototype.indexOf=function(e,t,n){return dw(this,e,t,n,!0)};I.prototype.lastIndexOf=function(e,t,n){return dw(this,e,t,n,!1)};function z_(r,e,t,n){t=Number(t)||0;let i=r.length-t;n?(n=Number(n),n>i&&(n=i)):n=i;let o=e.length;n>o/2&&(n=o/2);let s;for(s=0;s<n;++s){let a=parseInt(e.substr(s*2,2),16);if(Nh(a))return s;r[t+s]=a}return s}function K_(r,e,t,n){return Pl(Bh(e,r.length-t),r,t,n)}function G_(r,e,t,n){return Pl(nS(e),r,t,n)}function q_(r,e,t,n){return Pl(Ew(e),r,t,n)}function Y_(r,e,t,n){return Pl(iS(e,r.length-t),r,t,n)}I.prototype.write=function(e,t,n,i){if(t===void 0)i="utf8",n=this.length,t=0;else if(n===void 0&&typeof t=="string")i=t,n=this.length,t=0;else if(isFinite(t))t=t>>>0,isFinite(n)?(n=n>>>0,i===void 0&&(i="utf8")):(i=n,n=void 0);else throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");let o=this.length-t;if((n===void 0||n>o)&&(n=o),e.length>0&&(n<0||t<0)||t>this.length)throw new RangeError("Attempt to write outside buffer bounds");i||(i="utf8");let s=!1;for(;;)switch(i){case"hex":return z_(this,e,t,n);case"utf8":case"utf-8":return K_(this,e,t,n);case"ascii":case"latin1":case"binary":return G_(this,e,t,n);case"base64":return q_(this,e,t,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return Y_(this,e,t,n);default:if(s)throw new TypeError("Unknown encoding: "+i);i=(""+i).toLowerCase(),s=!0}};I.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function W_(r,e,t){return e===0&&t===r.length?_h.fromByteArray(r):_h.fromByteArray(r.slice(e,t))}function fw(r,e,t){t=Math.min(r.length,t);let n=[],i=e;for(;i<t;){let o=r[i],s=null,a=o>239?4:o>223?3:o>191?2:1;if(i+a<=t){let c,u,l,d;switch(a){case 1:o<128&&(s=o);break;case 2:c=r[i+1],(c&192)===128&&(d=(o&31)<<6|c&63,d>127&&(s=d));break;case 3:c=r[i+1],u=r[i+2],(c&192)===128&&(u&192)===128&&(d=(o&15)<<12|(c&63)<<6|u&63,d>2047&&(d<55296||d>57343)&&(s=d));break;case 4:c=r[i+1],u=r[i+2],l=r[i+3],(c&192)===128&&(u&192)===128&&(l&192)===128&&(d=(o&15)<<18|(c&63)<<12|(u&63)<<6|l&63,d>65535&&d<1114112&&(s=d))}}s===null?(s=65533,a=1):s>65535&&(s-=65536,n.push(s>>>10&1023|55296),s=56320|s&1023),n.push(s),i+=a}return j_(n)}var sw=4096;function j_(r){let e=r.length;if(e<=sw)return String.fromCharCode.apply(String,r);let t="",n=0;for(;n<e;)t+=String.fromCharCode.apply(String,r.slice(n,n+=sw));return t}function X_(r,e,t){let n="";t=Math.min(r.length,t);for(let i=e;i<t;++i)n+=String.fromCharCode(r[i]&127);return n}function Z_(r,e,t){let n="";t=Math.min(r.length,t);for(let i=e;i<t;++i)n+=String.fromCharCode(r[i]);return n}function J_(r,e,t){let n=r.length;(!e||e<0)&&(e=0),(!t||t<0||t>n)&&(t=n);let i="";for(let o=e;o<t;++o)i+=oS[r[o]];return i}function Q_(r,e,t){let n=r.slice(e,t),i="";for(let o=0;o<n.length-1;o+=2)i+=String.fromCharCode(n[o]+n[o+1]*256);return i}I.prototype.slice=function(e,t){let n=this.length;e=~~e,t=t===void 0?n:~~t,e<0?(e+=n,e<0&&(e=0)):e>n&&(e=n),t<0?(t+=n,t<0&&(t=0)):t>n&&(t=n),t<e&&(t=e);let i=this.subarray(e,t);return Object.setPrototypeOf(i,I.prototype),i};function $e(r,e,t){if(r%1!==0||r<0)throw new RangeError("offset is not uint");if(r+e>t)throw new RangeError("Trying to access beyond buffer length")}I.prototype.readUintLE=I.prototype.readUIntLE=function(e,t,n){e=e>>>0,t=t>>>0,n||$e(e,t,this.length);let i=this[e],o=1,s=0;for(;++s<t&&(o*=256);)i+=this[e+s]*o;return i};I.prototype.readUintBE=I.prototype.readUIntBE=function(e,t,n){e=e>>>0,t=t>>>0,n||$e(e,t,this.length);let i=this[e+--t],o=1;for(;t>0&&(o*=256);)i+=this[e+--t]*o;return i};I.prototype.readUint8=I.prototype.readUInt8=function(e,t){return e=e>>>0,t||$e(e,1,this.length),this[e]};I.prototype.readUint16LE=I.prototype.readUInt16LE=function(e,t){return e=e>>>0,t||$e(e,2,this.length),this[e]|this[e+1]<<8};I.prototype.readUint16BE=I.prototype.readUInt16BE=function(e,t){return e=e>>>0,t||$e(e,2,this.length),this[e]<<8|this[e+1]};I.prototype.readUint32LE=I.prototype.readUInt32LE=function(e,t){return e=e>>>0,t||$e(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+this[e+3]*16777216};I.prototype.readUint32BE=I.prototype.readUInt32BE=function(e,t){return e=e>>>0,t||$e(e,4,this.length),this[e]*16777216+(this[e+1]<<16|this[e+2]<<8|this[e+3])};I.prototype.readBigUInt64LE=ei(function(e){e=e>>>0,Do(e,"offset");let t=this[e],n=this[e+7];(t===void 0||n===void 0)&&ra(e,this.length-8);let i=t+this[++e]*2**8+this[++e]*2**16+this[++e]*2**24,o=this[++e]+this[++e]*2**8+this[++e]*2**16+n*2**24;return BigInt(i)+(BigInt(o)<<BigInt(32))});I.prototype.readBigUInt64BE=ei(function(e){e=e>>>0,Do(e,"offset");let t=this[e],n=this[e+7];(t===void 0||n===void 0)&&ra(e,this.length-8);let i=t*2**24+this[++e]*2**16+this[++e]*2**8+this[++e],o=this[++e]*2**24+this[++e]*2**16+this[++e]*2**8+n;return(BigInt(i)<<BigInt(32))+BigInt(o)});I.prototype.readIntLE=function(e,t,n){e=e>>>0,t=t>>>0,n||$e(e,t,this.length);let i=this[e],o=1,s=0;for(;++s<t&&(o*=256);)i+=this[e+s]*o;return o*=128,i>=o&&(i-=Math.pow(2,8*t)),i};I.prototype.readIntBE=function(e,t,n){e=e>>>0,t=t>>>0,n||$e(e,t,this.length);let i=t,o=1,s=this[e+--i];for(;i>0&&(o*=256);)s+=this[e+--i]*o;return o*=128,s>=o&&(s-=Math.pow(2,8*t)),s};I.prototype.readInt8=function(e,t){return e=e>>>0,t||$e(e,1,this.length),this[e]&128?(255-this[e]+1)*-1:this[e]};I.prototype.readInt16LE=function(e,t){e=e>>>0,t||$e(e,2,this.length);let n=this[e]|this[e+1]<<8;return n&32768?n|4294901760:n};I.prototype.readInt16BE=function(e,t){e=e>>>0,t||$e(e,2,this.length);let n=this[e+1]|this[e]<<8;return n&32768?n|4294901760:n};I.prototype.readInt32LE=function(e,t){return e=e>>>0,t||$e(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24};I.prototype.readInt32BE=function(e,t){return e=e>>>0,t||$e(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]};I.prototype.readBigInt64LE=ei(function(e){e=e>>>0,Do(e,"offset");let t=this[e],n=this[e+7];(t===void 0||n===void 0)&&ra(e,this.length-8);let i=this[e+4]+this[e+5]*2**8+this[e+6]*2**16+(n<<24);return(BigInt(i)<<BigInt(32))+BigInt(t+this[++e]*2**8+this[++e]*2**16+this[++e]*2**24)});I.prototype.readBigInt64BE=ei(function(e){e=e>>>0,Do(e,"offset");let t=this[e],n=this[e+7];(t===void 0||n===void 0)&&ra(e,this.length-8);let i=(t<<24)+this[++e]*2**16+this[++e]*2**8+this[++e];return(BigInt(i)<<BigInt(32))+BigInt(this[++e]*2**24+this[++e]*2**16+this[++e]*2**8+n)});I.prototype.readFloatLE=function(e,t){return e=e>>>0,t||$e(e,4,this.length),Uo.read(this,e,!0,23,4)};I.prototype.readFloatBE=function(e,t){return e=e>>>0,t||$e(e,4,this.length),Uo.read(this,e,!1,23,4)};I.prototype.readDoubleLE=function(e,t){return e=e>>>0,t||$e(e,8,this.length),Uo.read(this,e,!0,52,8)};I.prototype.readDoubleBE=function(e,t){return e=e>>>0,t||$e(e,8,this.length),Uo.read(this,e,!1,52,8)};function vt(r,e,t,n,i,o){if(!I.isBuffer(r))throw new TypeError('"buffer" argument must be a Buffer instance');if(e>i||e<o)throw new RangeError('"value" argument is out of bounds');if(t+n>r.length)throw new RangeError("Index out of range")}I.prototype.writeUintLE=I.prototype.writeUIntLE=function(e,t,n,i){if(e=+e,t=t>>>0,n=n>>>0,!i){let a=Math.pow(2,8*n)-1;vt(this,e,t,n,a,0)}let o=1,s=0;for(this[t]=e&255;++s<n&&(o*=256);)this[t+s]=e/o&255;return t+n};I.prototype.writeUintBE=I.prototype.writeUIntBE=function(e,t,n,i){if(e=+e,t=t>>>0,n=n>>>0,!i){let a=Math.pow(2,8*n)-1;vt(this,e,t,n,a,0)}let o=n-1,s=1;for(this[t+o]=e&255;--o>=0&&(s*=256);)this[t+o]=e/s&255;return t+n};I.prototype.writeUint8=I.prototype.writeUInt8=function(e,t,n){return e=+e,t=t>>>0,n||vt(this,e,t,1,255,0),this[t]=e&255,t+1};I.prototype.writeUint16LE=I.prototype.writeUInt16LE=function(e,t,n){return e=+e,t=t>>>0,n||vt(this,e,t,2,65535,0),this[t]=e&255,this[t+1]=e>>>8,t+2};I.prototype.writeUint16BE=I.prototype.writeUInt16BE=function(e,t,n){return e=+e,t=t>>>0,n||vt(this,e,t,2,65535,0),this[t]=e>>>8,this[t+1]=e&255,t+2};I.prototype.writeUint32LE=I.prototype.writeUInt32LE=function(e,t,n){return e=+e,t=t>>>0,n||vt(this,e,t,4,4294967295,0),this[t+3]=e>>>24,this[t+2]=e>>>16,this[t+1]=e>>>8,this[t]=e&255,t+4};I.prototype.writeUint32BE=I.prototype.writeUInt32BE=function(e,t,n){return e=+e,t=t>>>0,n||vt(this,e,t,4,4294967295,0),this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=e&255,t+4};function hw(r,e,t,n,i){ww(e,n,i,r,t,7);let o=Number(e&BigInt(4294967295));r[t++]=o,o=o>>8,r[t++]=o,o=o>>8,r[t++]=o,o=o>>8,r[t++]=o;let s=Number(e>>BigInt(32)&BigInt(4294967295));return r[t++]=s,s=s>>8,r[t++]=s,s=s>>8,r[t++]=s,s=s>>8,r[t++]=s,t}function pw(r,e,t,n,i){ww(e,n,i,r,t,7);let o=Number(e&BigInt(4294967295));r[t+7]=o,o=o>>8,r[t+6]=o,o=o>>8,r[t+5]=o,o=o>>8,r[t+4]=o;let s=Number(e>>BigInt(32)&BigInt(4294967295));return r[t+3]=s,s=s>>8,r[t+2]=s,s=s>>8,r[t+1]=s,s=s>>8,r[t]=s,t+8}I.prototype.writeBigUInt64LE=ei(function(e,t=0){return hw(this,e,t,BigInt(0),BigInt("0xffffffffffffffff"))});I.prototype.writeBigUInt64BE=ei(function(e,t=0){return pw(this,e,t,BigInt(0),BigInt("0xffffffffffffffff"))});I.prototype.writeIntLE=function(e,t,n,i){if(e=+e,t=t>>>0,!i){let c=Math.pow(2,8*n-1);vt(this,e,t,n,c-1,-c)}let o=0,s=1,a=0;for(this[t]=e&255;++o<n&&(s*=256);)e<0&&a===0&&this[t+o-1]!==0&&(a=1),this[t+o]=(e/s>>0)-a&255;return t+n};I.prototype.writeIntBE=function(e,t,n,i){if(e=+e,t=t>>>0,!i){let c=Math.pow(2,8*n-1);vt(this,e,t,n,c-1,-c)}let o=n-1,s=1,a=0;for(this[t+o]=e&255;--o>=0&&(s*=256);)e<0&&a===0&&this[t+o+1]!==0&&(a=1),this[t+o]=(e/s>>0)-a&255;return t+n};I.prototype.writeInt8=function(e,t,n){return e=+e,t=t>>>0,n||vt(this,e,t,1,127,-128),e<0&&(e=255+e+1),this[t]=e&255,t+1};I.prototype.writeInt16LE=function(e,t,n){return e=+e,t=t>>>0,n||vt(this,e,t,2,32767,-32768),this[t]=e&255,this[t+1]=e>>>8,t+2};I.prototype.writeInt16BE=function(e,t,n){return e=+e,t=t>>>0,n||vt(this,e,t,2,32767,-32768),this[t]=e>>>8,this[t+1]=e&255,t+2};I.prototype.writeInt32LE=function(e,t,n){return e=+e,t=t>>>0,n||vt(this,e,t,4,2147483647,-2147483648),this[t]=e&255,this[t+1]=e>>>8,this[t+2]=e>>>16,this[t+3]=e>>>24,t+4};I.prototype.writeInt32BE=function(e,t,n){return e=+e,t=t>>>0,n||vt(this,e,t,4,2147483647,-2147483648),e<0&&(e=4294967295+e+1),this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=e&255,t+4};I.prototype.writeBigInt64LE=ei(function(e,t=0){return hw(this,e,t,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});I.prototype.writeBigInt64BE=ei(function(e,t=0){return pw(this,e,t,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});function mw(r,e,t,n,i,o){if(t+n>r.length)throw new RangeError("Index out of range");if(t<0)throw new RangeError("Index out of range")}function yw(r,e,t,n,i){return e=+e,t=t>>>0,i||mw(r,e,t,4,34028234663852886e22,-34028234663852886e22),Uo.write(r,e,t,n,23,4),t+4}I.prototype.writeFloatLE=function(e,t,n){return yw(this,e,t,!0,n)};I.prototype.writeFloatBE=function(e,t,n){return yw(this,e,t,!1,n)};function gw(r,e,t,n,i){return e=+e,t=t>>>0,i||mw(r,e,t,8,17976931348623157e292,-17976931348623157e292),Uo.write(r,e,t,n,52,8),t+8}I.prototype.writeDoubleLE=function(e,t,n){return gw(this,e,t,!0,n)};I.prototype.writeDoubleBE=function(e,t,n){return gw(this,e,t,!1,n)};I.prototype.copy=function(e,t,n,i){if(!I.isBuffer(e))throw new TypeError("argument should be a Buffer");if(n||(n=0),!i&&i!==0&&(i=this.length),t>=e.length&&(t=e.length),t||(t=0),i>0&&i<n&&(i=n),i===n||e.length===0||this.length===0)return 0;if(t<0)throw new RangeError("targetStart out of bounds");if(n<0||n>=this.length)throw new RangeError("Index out of range");if(i<0)throw new RangeError("sourceEnd out of bounds");i>this.length&&(i=this.length),e.length-t<i-n&&(i=e.length-t+n);let o=i-n;return this===e&&typeof Uint8Array.prototype.copyWithin=="function"?this.copyWithin(t,n,i):Uint8Array.prototype.set.call(e,this.subarray(n,i),t),o};I.prototype.fill=function(e,t,n,i){if(typeof e=="string"){if(typeof t=="string"?(i=t,t=0,n=this.length):typeof n=="string"&&(i=n,n=this.length),i!==void 0&&typeof i!="string")throw new TypeError("encoding must be a string");if(typeof i=="string"&&!I.isEncoding(i))throw new TypeError("Unknown encoding: "+i);if(e.length===1){let s=e.charCodeAt(0);(i==="utf8"&&s<128||i==="latin1")&&(e=s)}}else typeof e=="number"?e=e&255:typeof e=="boolean"&&(e=Number(e));if(t<0||this.length<t||this.length<n)throw new RangeError("Out of range index");if(n<=t)return this;t=t>>>0,n=n===void 0?this.length:n>>>0,e||(e=0);let o;if(typeof e=="number")for(o=t;o<n;++o)this[o]=e;else{let s=I.isBuffer(e)?e:I.from(e,i),a=s.length;if(a===0)throw new TypeError('The value "'+e+'" is invalid for argument "value"');for(o=0;o<n-t;++o)this[o+t]=s[o%a]}return this};var Lo={};function Th(r,e,t){Lo[r]=class extends t{constructor(){super(),Object.defineProperty(this,"message",{value:e.apply(this,arguments),writable:!0,configurable:!0}),this.name=`${this.name} [${r}]`,this.stack,delete this.name}get code(){return r}set code(i){Object.defineProperty(this,"code",{configurable:!0,enumerable:!0,value:i,writable:!0})}toString(){return`${this.name} [${r}]: ${this.message}`}}}Th("ERR_BUFFER_OUT_OF_BOUNDS",function(r){return r?`${r} is outside of buffer bounds`:"Attempt to access memory outside buffer bounds"},RangeError);Th("ERR_INVALID_ARG_TYPE",function(r,e){return`The "${r}" argument must be of type number. Received type ${typeof e}`},TypeError);Th("ERR_OUT_OF_RANGE",function(r,e,t){let n=`The value of "${r}" is out of range.`,i=t;return Number.isInteger(t)&&Math.abs(t)>2**32?i=aw(String(t)):typeof t=="bigint"&&(i=String(t),(t>BigInt(2)**BigInt(32)||t<-(BigInt(2)**BigInt(32)))&&(i=aw(i)),i+="n"),n+=` It must be ${e}. Received ${i}`,n},RangeError);function aw(r){let e="",t=r.length,n=r[0]==="-"?1:0;for(;t>=n+4;t-=3)e=`_${r.slice(t-3,t)}${e}`;return`${r.slice(0,t)}${e}`}function eS(r,e,t){Do(e,"offset"),(r[e]===void 0||r[e+t]===void 0)&&ra(e,r.length-(t+1))}function ww(r,e,t,n,i,o){if(r>t||r<e){let s=typeof e=="bigint"?"n":"",a;throw o>3?e===0||e===BigInt(0)?a=`>= 0${s} and < 2${s} ** ${(o+1)*8}${s}`:a=`>= -(2${s} ** ${(o+1)*8-1}${s}) and < 2 ** ${(o+1)*8-1}${s}`:a=`>= ${e}${s} and <= ${t}${s}`,new Lo.ERR_OUT_OF_RANGE("value",a,r)}eS(n,i,o)}function Do(r,e){if(typeof r!="number")throw new Lo.ERR_INVALID_ARG_TYPE(e,"number",r)}function ra(r,e,t){throw Math.floor(r)!==r?(Do(r,t),new Lo.ERR_OUT_OF_RANGE(t||"offset","an integer",r)):e<0?new Lo.ERR_BUFFER_OUT_OF_BOUNDS:new Lo.ERR_OUT_OF_RANGE(t||"offset",`>= ${t?1:0} and <= ${e}`,r)}var tS=/[^+/0-9A-Za-z-_]/g;function rS(r){if(r=r.split("=")[0],r=r.trim().replace(tS,""),r.length<2)return"";for(;r.length%4!==0;)r=r+"=";return r}function Bh(r,e){e=e||1/0;let t,n=r.length,i=null,o=[];for(let s=0;s<n;++s){if(t=r.charCodeAt(s),t>55295&&t<57344){if(!i){if(t>56319){(e-=3)>-1&&o.push(239,191,189);continue}else if(s+1===n){(e-=3)>-1&&o.push(239,191,189);continue}i=t;continue}if(t<56320){(e-=3)>-1&&o.push(239,191,189),i=t;continue}t=(i-55296<<10|t-56320)+65536}else i&&(e-=3)>-1&&o.push(239,191,189);if(i=null,t<128){if((e-=1)<0)break;o.push(t)}else if(t<2048){if((e-=2)<0)break;o.push(t>>6|192,t&63|128)}else if(t<65536){if((e-=3)<0)break;o.push(t>>12|224,t>>6&63|128,t&63|128)}else if(t<1114112){if((e-=4)<0)break;o.push(t>>18|240,t>>12&63|128,t>>6&63|128,t&63|128)}else throw new Error("Invalid code point")}return o}function nS(r){let e=[];for(let t=0;t<r.length;++t)e.push(r.charCodeAt(t)&255);return e}function iS(r,e){let t,n,i,o=[];for(let s=0;s<r.length&&!((e-=2)<0);++s)t=r.charCodeAt(s),n=t>>8,i=t%256,o.push(i),o.push(n);return o}function Ew(r){return _h.toByteArray(rS(r))}function Pl(r,e,t,n){let i;for(i=0;i<n&&!(i+t>=e.length||i>=r.length);++i)e[i+t]=r[i];return i}function Br(r,e){return r instanceof e||r!=null&&r.constructor!=null&&r.constructor.name!=null&&r.constructor.name===e.name}function Nh(r){return r!==r}var oS=function(){let r="0123456789abcdef",e=new Array(256);for(let t=0;t<16;++t){let n=t*16;for(let i=0;i<16;++i)e[n+i]=r[t]+r[i]}return e}();function ei(r){return typeof BigInt>"u"?sS:r}function sS(){throw new Error("BigInt not supported")}});var xw=le(Lh=>{"use strict";Lh.toString=function(r){switch(r){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_"+r};Lh.toType=function(r){switch(r.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 r.toUpperCase().startsWith("UNKNOWN_")?parseInt(r.slice(8)):0}});var bw=le(Uh=>{"use strict";Uh.toString=function(r){switch(r){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_"+r};Uh.toRcode=function(r){switch(r.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 vw=le(Dh=>{"use strict";Dh.toString=function(r){switch(r){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_"+r};Dh.toOpcode=function(r){switch(r.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 Aw=le(Oh=>{"use strict";Oh.toString=function(r){switch(r){case 1:return"IN";case 2:return"CS";case 3:return"CH";case 4:return"HS";case 255:return"ANY"}return"UNKNOWN_"+r};Oh.toClass=function(r){switch(r.toUpperCase()){case"IN":return 1;case"CS":return 2;case"CH":return 3;case"HS":return 4;case"ANY":return 255}return 0}});var _w=le(Ph=>{"use strict";Ph.toString=function(r){switch(r){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 r<0?null:`OPTION_${r}`};Ph.toCode=function(r){if(typeof r=="number")return r;if(!r)return-1;switch(r.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=r.match(/_(\d+)$/);return e?parseInt(e[1],10):-1}});var Bw=le((Iw,Fh)=>{var Sw=function(r){"use strict";Object.defineProperty(r,"__esModule",{value:!0}),r.decode=d,r.encode=l,r.familyOf=u,r.name=void 0,r.sizeOf=c,r.v6=r.v4=void 0;let e=/^(\d{1,3}\.){3,3}\d{1,3}$/,t=4,n=/^(::)?(((\d{1,3}\.){3}(\d{1,3}){1})?([0-9a-f]){0,4}:{0,2}){1,8}(::)?$/i,i=16,o={name:"v4",size:t,isFormat:p=>e.test(p),encode(p,f,h){h=~~h,f=f||new Uint8Array(h+t);let m=p.length,y=0;for(let g=0;g<m;){let E=p.charCodeAt(g++);E===46?(f[h++]=y,y=0):y=y*10+(E-48)}return f[h]=y,f},decode(p,f){return f=~~f,`${p[f++]}.${p[f++]}.${p[f++]}.${p[f]}`}};r.v4=o;let s={name:"v6",size:i,isFormat:p=>p.length>0&&n.test(p),encode(p,f,h){h=~~h;let m=h+i,y=-1,g=0,E=0,x=!0,_=!1;f=f||new Uint8Array(h+i);for(let S=0;S<p.length;S++){let A=p.charCodeAt(S);A===58?(x?y!==-1?(h<m&&(f[h]=0),h<m-1&&(f[h+1]=0),h+=2):h<m&&(y=h):(_===!0?(h<m&&(f[h]=E),h++):(h<m&&(f[h]=g>>8),h<m-1&&(f[h+1]=g&255),h+=2),g=0,E=0),x=!0,_=!1):A===46?(h<m&&(f[h]=E),h++,E=0,g=0,x=!1,_=!0):(x=!1,A>=97?A-=87:A>=65?A-=55:(A-=48,E=E*10+A),g=(g<<4)+A)}if(x===!1)_===!0?(h<m&&(f[h]=E),h++):(h<m&&(f[h]=g>>8),h<m-1&&(f[h+1]=g&255),h+=2);else if(y===0)h<m&&(f[h]=0),h<m-1&&(f[h+1]=0),h+=2;else if(y!==-1){h+=2;for(let S=Math.min(h-1,m-1);S>=y+2;S--)f[S]=f[S-2];f[y]=0,f[y+1]=0,y=h}if(y!==h&&y!==-1)for(h>m-2&&(h=m-2);m>y;)f[--m]=h<m&&h>y?f[--h]:0;else for(;h<m;)f[h++]=0;return f},decode(p,f){f=~~f;let h="";for(let m=0;m<i;m+=2)m!==0&&(h+=":"),h+=(p[f+m]<<8|p[f+m+1]).toString(16);return h.replace(/(^|:)0(:0)*:0(:|$)/,"$1::$3").replace(/:{3,4}/,"::")}};r.v6=s;let a="ip";r.name=a;function c(p){if(o.isFormat(p))return o.size;if(s.isFormat(p))return s.size;throw Error(`Invalid ip address: ${p}`)}function u(p){return c(p)===o.size?1:2}function l(p,f,h){h=~~h;let m=c(p);return typeof f=="function"&&(f=f(h+m)),m===o.size?o.encode(p,f,h):s.encode(p,f,h)}function d(p,f,h){if(f=~~f,h=h||p.length-f,h===o.size)return o.decode(p,f,h);if(h===s.size)return s.decode(p,f,h);throw Error(`Invalid buffer size needs to be ${o.size} for v4 or ${s.size} for v6.`)}return"default"in r?r.default:r}({});typeof define=="function"&&define.amd?define([],function(){return Sw}):typeof Fh=="object"&&typeof Iw=="object"&&(Fh.exports=Sw)});var Tw=le(q=>{"use strict";var Y=Ch().Buffer,En=xw(),aS=bw(),cS=vw(),Vl=Aw(),Vh=_w(),Li=Bw(),lS=0,kw=32768,Mh=32768,uS=~Mh,Rw=32768,dS=~Rw,M=q.name={};M.encode=function(r,e,t,{mail:n=!1}={}){e||(e=Y.alloc(M.encodingLength(r))),t||(t=0);let i=t,o=r.replace(/^\.|\.$/gm,"");if(o.length){let s=[];if(n){let a="";o.split(".").forEach(c=>{c.endsWith("\\")?a+=(a.length?".":"")+c.slice(0,-1):s.length===0&&a.length?s.push(a+"."+c):s.push(c)})}else s=o.split(".");for(let a=0;a<s.length;a++){let c=e.write(s[a],t+1);e[t]=c,t+=c+1}}return e[t++]=0,M.encode.bytes=t-i,e};M.encode.bytes=0;M.decode=function(r,e,{mail:t=!1}={}){e||(e=0);let n=[],i=e,o=0,s=0,a=!1;for(;;){if(e>=r.length)throw new Error("Cannot decode name (buffer overflow)");let c=r[e++];if(s+=a?0:1,c===0)break;if(c&192)if((c&192)===192){if(e+1>r.length)throw new Error("Cannot decode name (buffer overflow)");let u=r.readUInt16BE(e-1)-49152;if(u>=i)throw new Error("Cannot decode name (bad pointer)");e=u,i=u,s+=a?0:1,a=!0}else throw new Error("Cannot decode name (bad label)");else{if(e+c>r.length)throw new Error("Cannot decode name (buffer overflow)");if(o+=c+1,o>254)throw new Error("Cannot decode name (name too long)");let u=r.toString("utf-8",e,e+c);t&&(u=u.replace(/\./g,"\\.")),n.push(u),e+=c,s+=a?0:c}}return M.decode.bytes=s,n.length===0?".":n.join(".")};M.decode.bytes=0;M.encodingLength=function(r){return r==="."||r===".."?1:Y.byteLength(r.replace(/^\.|\.$/gm,""))+2};var te={};te.encode=function(r,e,t){e||(e=Y.alloc(te.encodingLength(r))),t||(t=0);let n=e.write(r,t+1);return e[t]=n,te.encode.bytes=n+1,e};te.encode.bytes=0;te.decode=function(r,e){e||(e=0);let t=r[e],n=r.toString("utf-8",e+1,e+1+t);return te.decode.bytes=t+1,n};te.decode.bytes=0;te.encodingLength=function(r){return Y.byteLength(r)+1};var ur={};ur.encode=function(r,e,t){e||(e=ur.encodingLength(r)),t||(t=0);let n=(r.flags||0)&32767,i=r.type==="response"?kw:lS;return e.writeUInt16BE(r.id||0,t),e.writeUInt16BE(n|i,t+2),e.writeUInt16BE(r.questions.length,t+4),e.writeUInt16BE(r.answers.length,t+6),e.writeUInt16BE(r.authorities.length,t+8),e.writeUInt16BE(r.additionals.length,t+10),e};ur.encode.bytes=12;ur.decode=function(r,e){if(e||(e=0),r.length<12)throw new Error("Header must be 12 bytes");let t=r.readUInt16BE(e+2);return{id:r.readUInt16BE(e),type:t&kw?"response":"query",flags:t&32767,flag_qr:(t>>15&1)===1,opcode:cS.toString(t>>11&15),flag_aa:(t>>10&1)===1,flag_tc:(t>>9&1)===1,flag_rd:(t>>8&1)===1,flag_ra:(t>>7&1)===1,flag_z:(t>>6&1)===1,flag_ad:(t>>5&1)===1,flag_cd:(t>>4&1)===1,rcode:aS.toString(t&15),questions:new Array(r.readUInt16BE(e+4)),answers:new Array(r.readUInt16BE(e+6)),authorities:new Array(r.readUInt16BE(e+8)),additionals:new Array(r.readUInt16BE(e+10))}};ur.decode.bytes=12;ur.encodingLength=function(){return 12};var un=q.unknown={};un.encode=function(r,e,t){return e||(e=Y.alloc(un.encodingLength(r))),t||(t=0),e.writeUInt16BE(r.length,t),r.copy(e,t+2),un.encode.bytes=r.length+2,e};un.encode.bytes=0;un.decode=function(r,e){e||(e=0);let t=r.readUInt16BE(e),n=r.slice(e+2,e+2+t);return un.decode.bytes=t+2,n};un.decode.bytes=0;un.encodingLength=function(r){return r.length+2};var dn=q.ns={};dn.encode=function(r,e,t){return e||(e=Y.alloc(dn.encodingLength(r))),t||(t=0),M.encode(r,e,t+2),e.writeUInt16BE(M.encode.bytes,t),dn.encode.bytes=M.encode.bytes+2,e};dn.encode.bytes=0;dn.decode=function(r,e){e||(e=0);let t=r.readUInt16BE(e),n=M.decode(r,e+2);return dn.decode.bytes=t+2,n};dn.decode.bytes=0;dn.encodingLength=function(r){return M.encodingLength(r)+2};var fn=q.soa={};fn.encode=function(r,e,t){e||(e=Y.alloc(fn.encodingLength(r))),t||(t=0);let n=t;return t+=2,M.encode(r.mname,e,t),t+=M.encode.bytes,M.encode(r.rname,e,t,{mail:!0}),t+=M.encode.bytes,e.writeUInt32BE(r.serial||0,t),t+=4,e.writeUInt32BE(r.refresh||0,t),t+=4,e.writeUInt32BE(r.retry||0,t),t+=4,e.writeUInt32BE(r.expire||0,t),t+=4,e.writeUInt32BE(r.minimum||0,t),t+=4,e.writeUInt16BE(t-n-2,n),fn.encode.bytes=t-n,e};fn.encode.bytes=0;fn.decode=function(r,e){e||(e=0);let t=e,n={};return e+=2,n.mname=M.decode(r,e),e+=M.decode.bytes,n.rname=M.decode(r,e,{mail:!0}),e+=M.decode.bytes,n.serial=r.readUInt32BE(e),e+=4,n.refresh=r.readUInt32BE(e),e+=4,n.retry=r.readUInt32BE(e),e+=4,n.expire=r.readUInt32BE(e),e+=4,n.minimum=r.readUInt32BE(e),e+=4,fn.decode.bytes=e-t,n};fn.decode.bytes=0;fn.encodingLength=function(r){return 22+M.encodingLength(r.mname)+M.encodingLength(r.rname)};var hn=q.txt={};hn.encode=function(r,e,t){Array.isArray(r)||(r=[r]);for(let i=0;i<r.length;i++)if(typeof r[i]=="string"&&(r[i]=Y.from(r[i])),!Y.isBuffer(r[i]))throw new Error("Must be a Buffer");e||(e=Y.alloc(hn.encodingLength(r))),t||(t=0);let n=t;return t+=2,r.forEach(function(i){e[t++]=i.length,i.copy(e,t,0,i.length),t+=i.length}),e.writeUInt16BE(t-n-2,n),hn.encode.bytes=t-n,e};hn.encode.bytes=0;hn.decode=function(r,e){e||(e=0);let t=e,n=r.readUInt16BE(e);e+=2;let i=[];for(;n>0;){let o=r[e++];if(--n,n<o)throw new Error("Buffer overflow");i.push(r.slice(e,e+o)),e+=o,n-=o}return hn.decode.bytes=e-t,i};hn.decode.bytes=0;hn.encodingLength=function(r){Array.isArray(r)||(r=[r]);let e=2;return r.forEach(function(t){typeof t=="string"?e+=Y.byteLength(t)+1:e+=t.length+1}),e};var pn=q.null={};pn.encode=function(r,e,t){e||(e=Y.alloc(pn.encodingLength(r))),t||(t=0),typeof r=="string"&&(r=Y.from(r)),r||(r=Y.alloc(0));let n=t;t+=2;let i=r.length;return r.copy(e,t,0,i),t+=i,e.writeUInt16BE(t-n-2,n),pn.encode.bytes=t-n,e};pn.encode.bytes=0;pn.decode=function(r,e){e||(e=0);let t=e,n=r.readUInt16BE(e);e+=2;let i=r.slice(e,e+n);return e+=n,pn.decode.bytes=e-t,i};pn.decode.bytes=0;pn.encodingLength=function(r){return r?(Y.isBuffer(r)?r.length:Y.byteLength(r))+2:2};var mn=q.hinfo={};mn.encode=function(r,e,t){e||(e=Y.alloc(mn.encodingLength(r))),t||(t=0);let n=t;return t+=2,te.encode(r.cpu,e,t),t+=te.encode.bytes,te.encode(r.os,e,t),t+=te.encode.bytes,e.writeUInt16BE(t-n-2,n),mn.encode.bytes=t-n,e};mn.encode.bytes=0;mn.decode=function(r,e){e||(e=0);let t=e,n={};return e+=2,n.cpu=te.decode(r,e),e+=te.decode.bytes,n.os=te.decode(r,e),e+=te.decode.bytes,mn.decode.bytes=e-t,n};mn.decode.bytes=0;mn.encodingLength=function(r){return te.encodingLength(r.cpu)+te.encodingLength(r.os)+2};var cr=q.ptr={},fS=q.cname=cr,hS=q.dname=cr;cr.encode=function(r,e,t){return e||(e=Y.alloc(cr.encodingLength(r))),t||(t=0),M.encode(r,e,t+2),e.writeUInt16BE(M.encode.bytes,t),cr.encode.bytes=M.encode.bytes+2,e};cr.encode.bytes=0;cr.decode=function(r,e){e||(e=0);let t=M.decode(r,e+2);return cr.decode.bytes=M.decode.bytes+2,t};cr.decode.bytes=0;cr.encodingLength=function(r){return M.encodingLength(r)+2};var yn=q.srv={};yn.encode=function(r,e,t){e||(e=Y.alloc(yn.encodingLength(r))),t||(t=0),e.writeUInt16BE(r.priority||0,t+2),e.writeUInt16BE(r.weight||0,t+4),e.writeUInt16BE(r.port||0,t+6),M.encode(r.target,e,t+8);let n=M.encode.bytes+6;return e.writeUInt16BE(n,t),yn.encode.bytes=n+2,e};yn.encode.bytes=0;yn.decode=function(r,e){e||(e=0);let t=r.readUInt16BE(e),n={};return n.priority=r.readUInt16BE(e+2),n.weight=r.readUInt16BE(e+4),n.port=r.readUInt16BE(e+6),n.target=M.decode(r,e+8),yn.decode.bytes=t+2,n};yn.decode.bytes=0;yn.encodingLength=function(r){return 8+M.encodingLength(r.target)};var Ct=q.caa={};Ct.ISSUER_CRITICAL=128;Ct.encode=function(r,e,t){let n=Ct.encodingLength(r);return e||(e=Y.alloc(Ct.encodingLength(r))),t||(t=0),r.issuerCritical&&(r.flags=Ct.ISSUER_CRITICAL),e.writeUInt16BE(n-2,t),t+=2,e.writeUInt8(r.flags||0,t),t+=1,te.encode(r.tag,e,t),t+=te.encode.bytes,e.write(r.value,t),t+=Y.byteLength(r.value),Ct.encode.bytes=n,e};Ct.encode.bytes=0;Ct.decode=function(r,e){e||(e=0);let t=r.readUInt16BE(e);e+=2;let n=e,i={};return i.flags=r.readUInt8(e),e+=1,i.tag=te.decode(r,e),e+=te.decode.bytes,i.value=r.toString("utf-8",e,n+t),i.issuerCritical=!!(i.flags&Ct.ISSUER_CRITICAL),Ct.decode.bytes=t+2,i};Ct.decode.bytes=0;Ct.encodingLength=function(r){return te.encodingLength(r.tag)+te.encodingLength(r.value)+2};var ti=q.mx={};ti.encode=function(r,e,t){e||(e=Y.alloc(ti.encodingLength(r))),t||(t=0);let n=t;return t+=2,e.writeUInt16BE(r.preference||0,t),t+=2,M.encode(r.exchange,e,t),t+=M.encode.bytes,e.writeUInt16BE(t-n-2,n),ti.encode.bytes=t-n,e};ti.encode.bytes=0;ti.decode=function(r,e){e||(e=0);let t=e,n={};return e+=2,n.preference=r.readUInt16BE(e),e+=2,n.exchange=M.decode(r,e),e+=M.decode.bytes,ti.decode.bytes=e-t,n};ti.encodingLength=function(r){return 4+M.encodingLength(r.exchange)};var gn=q.a={};gn.encode=function(r,e,t){return e||(e=Y.alloc(gn.encodingLength(r))),t||(t=0),e.writeUInt16BE(4,t),t+=2,Li.v4.encode(r,e,t),gn.encode.bytes=6,e};gn.encode.bytes=0;gn.decode=function(r,e){e||(e=0),e+=2;let t=Li.v4.decode(r,e);return gn.decode.bytes=6,t};gn.decode.bytes=0;gn.encodingLength=function(){return 6};var wn=q.aaaa={};wn.encode=function(r,e,t){return e||(e=Y.alloc(wn.encodingLength(r))),t||(t=0),e.writeUInt16BE(16,t),t+=2,Li.v6.encode(r,e,t),wn.encode.bytes=18,e};wn.encode.bytes=0;wn.decode=function(r,e){e||(e=0),e+=2;let t=Li.v6.decode(r,e);return wn.decode.bytes=18,t};wn.decode.bytes=0;wn.encodingLength=function(){return 18};var At=q.option={};At.encode=function(r,e,t){e||(e=Y.alloc(At.encodingLength(r))),t||(t=0);let n=t,i=Vh.toCode(r.code);if(e.writeUInt16BE(i,t),t+=2,r.data)e.writeUInt16BE(r.data.length,t),t+=2,r.data.copy(e,t),t+=r.data.length;else switch(i){case 8:let o=r.sourcePrefixLength||0,s=r.family||Li.familyOf(r.ip),a=Li.encode(r.ip,Y.alloc),c=Math.ceil(o/8);e.writeUInt16BE(c+4,t),t+=2,e.writeUInt16BE(s,t),t+=2,e.writeUInt8(o,t++),e.writeUInt8(r.scopePrefixLength||0,t++),a.copy(e,t,0,c),t+=c;break;case 11:r.timeout?(e.writeUInt16BE(2,t),t+=2,e.writeUInt16BE(r.timeout,t),t+=2):(e.writeUInt16BE(0,t),t+=2);break;case 12:let u=r.length||0;e.writeUInt16BE(u,t),t+=2,e.fill(0,t,t+u),t+=u;break;case 14:let l=r.tags.length*2;e.writeUInt16BE(l,t),t+=2;for(let d of r.tags)e.writeUInt16BE(d,t),t+=2;break;default:throw new Error(`Unknown roption code: ${r.code}`)}return At.encode.bytes=t-n,e};At.encode.bytes=0;At.decode=function(r,e){e||(e=0);let t={};t.code=r.readUInt16BE(e),t.type=Vh.toString(t.code),e+=2;let n=r.readUInt16BE(e);switch(e+=2,t.data=r.slice(e,e+n),t.code){case 8:t.family=r.readUInt16BE(e),e+=2,t.sourcePrefixLength=r.readUInt8(e++),t.scopePrefixLength=r.readUInt8(e++);let i=Y.alloc(t.family===1?4:16);r.copy(i,0,e,e+n-4),t.ip=Li.decode(i);break;case 11:n>0&&(t.timeout=r.readUInt16BE(e),e+=2);break;case 14:t.tags=[];for(let o=0;o<n;o+=2)t.tags.push(r.readUInt16BE(e)),e+=2}return At.decode.bytes=n+4,t};At.decode.bytes=0;At.encodingLength=function(r){if(r.data)return r.data.length+4;switch(Vh.toCode(r.code)){case 8:let t=r.sourcePrefixLength||0;return Math.ceil(t/8)+8;case 11:return typeof r.timeout=="number"?6:4;case 12:return r.length+4;case 14:return 4+r.tags.length*2}throw new Error(`Unknown roption code: ${r.code}`)};var Ut=q.opt={};Ut.encode=function(r,e,t){e||(e=Y.alloc(Ut.encodingLength(r))),t||(t=0);let n=t,i=Po(r,At);return e.writeUInt16BE(i,t),t=na(r,At,e,t+2),Ut.encode.bytes=t-n,e};Ut.encode.bytes=0;Ut.decode=function(r,e){e||(e=0);let t=e,n=[],i=r.readUInt16BE(e);e+=2;let o=0;for(;i>0;)n[o++]=At.decode(r,e),e+=At.decode.bytes,i-=At.decode.bytes;return Ut.decode.bytes=e-t,n};Ut.decode.bytes=0;Ut.encodingLength=function(r){return 2+Po(r||[],At)};var ht=q.dnskey={};ht.PROTOCOL_DNSSEC=3;ht.ZONE_KEY=128;ht.SECURE_ENTRYPOINT=32768;ht.encode=function(r,e,t){e||(e=Y.alloc(ht.encodingLength(r))),t||(t=0);let n=t,i=r.key;if(!Y.isBuffer(i))throw new Error("Key must be a Buffer");return t+=2,e.writeUInt16BE(r.flags,t),t+=2,e.writeUInt8(ht.PROTOCOL_DNSSEC,t),t+=1,e.writeUInt8(r.algorithm,t),t+=1,i.copy(e,t,0,i.length),t+=i.length,ht.encode.bytes=t-n,e.writeUInt16BE(ht.encode.bytes-2,n),e};ht.encode.bytes=0;ht.decode=function(r,e){e||(e=0);let t=e;var n={},i=r.readUInt16BE(e);if(e+=2,n.flags=r.readUInt16BE(e),e+=2,r.readUInt8(e)!==ht.PROTOCOL_DNSSEC)throw new Error("Protocol must be 3");return e+=1,n.algorithm=r.readUInt8(e),e+=1,n.key=r.slice(e,t+i+2),e+=n.key.length,ht.decode.bytes=e-t,n};ht.decode.bytes=0;ht.encodingLength=function(r){return 6+Y.byteLength(r.key)};var kr=q.rrsig={};kr.encode=function(r,e,t){e||(e=Y.alloc(kr.encodingLength(r))),t||(t=0);let n=t,i=r.signature;if(!Y.isBuffer(i))throw new Error("Signature must be a Buffer");return t+=2,e.writeUInt16BE(En.toType(r.typeCovered),t),t+=2,e.writeUInt8(r.algorithm,t),t+=1,e.writeUInt8(r.labels,t),t+=1,e.writeUInt32BE(r.originalTTL,t),t+=4,e.writeUInt32BE(r.expiration,t),t+=4,e.writeUInt32BE(r.inception,t),t+=4,e.writeUInt16BE(r.keyTag,t),t+=2,M.encode(r.signersName,e,t),t+=M.encode.bytes,i.copy(e,t,0,i.length),t+=i.length,kr.encode.bytes=t-n,e.writeUInt16BE(kr.encode.bytes-2,n),e};kr.encode.bytes=0;kr.decode=function(r,e){e||(e=0);let t=e;var n={},i=r.readUInt16BE(e);return e+=2,n.typeCovered=En.toString(r.readUInt16BE(e)),e+=2,n.algorithm=r.readUInt8(e),e+=1,n.labels=r.readUInt8(e),e+=1,n.originalTTL=r.readUInt32BE(e),e+=4,n.expiration=r.readUInt32BE(e),e+=4,n.inception=r.readUInt32BE(e),e+=4,n.keyTag=r.readUInt16BE(e),e+=2,n.signersName=M.decode(r,e),e+=M.decode.bytes,n.signature=r.slice(e,t+i+2),e+=n.signature.length,kr.decode.bytes=e-t,n};kr.decode.bytes=0;kr.encodingLength=function(r){return 20+M.encodingLength(r.signersName)+Y.byteLength(r.signature)};var Rr=q.rp={};Rr.encode=function(r,e,t){e||(e=Y.alloc(Rr.encodingLength(r))),t||(t=0);let n=t;return t+=2,M.encode(r.mbox||".",e,t,{mail:!0}),t+=M.encode.bytes,M.encode(r.txt||".",e,t),t+=M.encode.bytes,Rr.encode.bytes=t-n,e.writeUInt16BE(Rr.encode.bytes-2,n),e};Rr.encode.bytes=0;Rr.decode=function(r,e){e||(e=0);let t=e,n={};return e+=2,n.mbox=M.decode(r,e,{mail:!0})||".",e+=M.decode.bytes,n.txt=M.decode(r,e)||".",e+=M.decode.bytes,Rr.decode.bytes=e-t,n};Rr.decode.bytes=0;Rr.encodingLength=function(r){return 2+M.encodingLength(r.mbox||".")+M.encodingLength(r.txt||".")};var ze={};ze.encode=function(r,e,t){e||(e=Y.alloc(ze.encodingLength(r))),t||(t=0);let n=t;for(var i=[],o=0;o<r.length;o++){var s=En.toType(r[o]);i[s>>8]===void 0&&(i[s>>8]=[]),i[s>>8][s>>3&31]|=1<<7-(s&7)}for(o=0;o<i.length;o++)if(i[o]!==void 0){var a=Y.from(i[o]);e.writeUInt8(o,t),t+=1,e.writeUInt8(a.length,t),t+=1,a.copy(e,t),t+=a.length}return ze.encode.bytes=t-n,e};ze.encode.bytes=0;ze.decode=function(r,e,t){e||(e=0);let n=e;for(var i=[];e-n<t;){var o=r.readUInt8(e);e+=1;var s=r.readUInt8(e);e+=1;for(var a=0;a<s;a++)for(var c=r.readUInt8(e+a),u=0;u<8;u++)if(c&1<<7-u){var l=En.toString(o<<8|a<<3|u);i.push(l)}e+=s}return ze.decode.bytes=e-n,i};ze.decode.bytes=0;ze.encodingLength=function(r){for(var e=[],t=0;t<r.length;t++){var n=En.toType(r[t]);e[n>>8]=Math.max(e[n>>8]||0,n&255)}var i=0;for(t=0;t<e.length;t++)e[t]!==void 0&&(i+=2+Math.ceil((e[t]+1)/8));return i};var Tr=q.nsec={};Tr.encode=function(r,e,t){e||(e=Y.alloc(Tr.encodingLength(r))),t||(t=0);let n=t;return t+=2,M.encode(r.nextDomain,e,t),t+=M.encode.bytes,ze.encode(r.rrtypes,e,t),t+=ze.encode.bytes,Tr.encode.bytes=t-n,e.writeUInt16BE(Tr.encode.bytes-2,n),e};Tr.encode.bytes=0;Tr.decode=function(r,e){e||(e=0);let t=e;var n={},i=r.readUInt16BE(e);return e+=2,n.nextDomain=M.decode(r,e),e+=M.decode.bytes,n.rrtypes=ze.decode(r,e,i-(e-t)),e+=ze.decode.bytes,Tr.decode.bytes=e-t,n};Tr.decode.bytes=0;Tr.encodingLength=function(r){return 2+M.encodingLength(r.nextDomain)+ze.encodingLength(r.rrtypes)};var Nr=q.nsec3={};Nr.encode=function(r,e,t){e||(e=Y.alloc(Nr.encodingLength(r))),t||(t=0);let n=t,i=r.salt;if(!Y.isBuffer(i))throw new Error("salt must be a Buffer");let o=r.nextDomain;if(!Y.isBuffer(o))throw new Error("nextDomain must be a Buffer");return t+=2,e.writeUInt8(r.algorithm,t),t+=1,e.writeUInt8(r.flags,t),t+=1,e.writeUInt16BE(r.iterations,t),t+=2,e.writeUInt8(i.length,t),t+=1,i.copy(e,t,0,i.length),t+=i.length,e.writeUInt8(o.length,t),t+=1,o.copy(e,t,0,o.length),t+=o.length,ze.encode(r.rrtypes,e,t),t+=ze.encode.bytes,Nr.encode.bytes=t-n,e.writeUInt16BE(Nr.encode.bytes-2,n),e};Nr.encode.bytes=0;Nr.decode=function(r,e){e||(e=0);let t=e;var n={},i=r.readUInt16BE(e);e+=2,n.algorithm=r.readUInt8(e),e+=1,n.flags=r.readUInt8(e),e+=1,n.iterations=r.readUInt16BE(e),e+=2;let o=r.readUInt8(e);e+=1,n.salt=r.slice(e,e+o),e+=o;let s=r.readUInt8(e);return e+=1,n.nextDomain=r.slice(e,e+s),e+=s,n.rrtypes=ze.decode(r,e,i-(e-t)),e+=ze.decode.bytes,Nr.decode.bytes=e-t,n};Nr.decode.bytes=0;Nr.encodingLength=function(r){return 8+r.salt.length+r.nextDomain.length+ze.encodingLength(r.rrtypes)};var Cr=q.ds={};Cr.encode=function(r,e,t){e||(e=Y.alloc(Cr.encodingLength(r))),t||(t=0);let n=t,i=r.digest;if(!Y.isBuffer(i))throw new Error("Digest must be a Buffer");return t+=2,e.writeUInt16BE(r.keyTag,t),t+=2,e.writeUInt8(r.algorithm,t),t+=1,e.writeUInt8(r.digestType,t),t+=1,i.copy(e,t,0,i.length),t+=i.length,Cr.encode.bytes=t-n,e.writeUInt16BE(Cr.encode.bytes-2,n),e};Cr.encode.bytes=0;Cr.decode=function(r,e){e||(e=0);let t=e;var n={},i=r.readUInt16BE(e);return e+=2,n.keyTag=r.readUInt16BE(e),e+=2,n.algorithm=r.readUInt8(e),e+=1,n.digestType=r.readUInt8(e),e+=1,n.digest=r.slice(e,t+i+2),e+=n.digest.length,Cr.decode.bytes=e-t,n};Cr.decode.bytes=0;Cr.encodingLength=function(r){return 6+Y.byteLength(r.digest)};var Lt=q.sshfp={};Lt.getFingerprintLengthForHashType=function(e){switch(e){case 1:return 20;case 2:return 32}};Lt.encode=function(e,t,n){t||(t=Y.alloc(Lt.encodingLength(e))),n||(n=0);let i=n;n+=2,t[n]=e.algorithm,n+=1,t[n]=e.hash,n+=1;let o=Y.from(e.fingerprint.toUpperCase(),"hex");if(o.length!==Lt.getFingerprintLengthForHashType(e.hash))throw new Error("Invalid fingerprint length");return o.copy(t,n),n+=o.byteLength,Lt.encode.bytes=n-i,t.writeUInt16BE(Lt.encode.bytes-2,i),t};Lt.encode.bytes=0;Lt.decode=function(e,t){t||(t=0);let n=t,i={};t+=2,i.algorithm=e[t],t+=1,i.hash=e[t],t+=1;let o=Lt.getFingerprintLengthForHashType(i.hash);return i.fingerprint=e.slice(t,t+o).toString("hex").toUpperCase(),t+=o,Lt.decode.bytes=t-n,i};Lt.decode.bytes=0;Lt.encodingLength=function(r){return 4+Y.from(r.fingerprint,"hex").byteLength};var Lr=q.naptr={};Lr.encode=function(r,e,t){e||(e=Y.alloc(Lr.encodingLength(r))),t||(t=0);let n=t;return t+=2,e.writeUInt16BE(r.order||0,t),t+=2,e.writeUInt16BE(r.preference||0,t),t+=2,te.encode(r.flags,e,t),t+=te.encode.bytes,te.encode(r.services,e,t),t+=te.encode.bytes,te.encode(r.regexp,e,t),t+=te.encode.bytes,M.encode(r.replacement,e,t),t+=M.encode.bytes,Lr.encode.bytes=t-n,e.writeUInt16BE(Lr.encode.bytes-2,n),e};Lr.encode.bytes=0;Lr.decode=function(r,e){e||(e=0);let t=e,n={};return e+=2,n.order=r.readUInt16BE(e),e+=2,n.preference=r.readUInt16BE(e),e+=2,n.flags=te.decode(r,e),e+=te.decode.bytes,n.services=te.decode(r,e),e+=te.decode.bytes,n.regexp=te.decode(r,e),e+=te.decode.bytes,n.replacement=M.decode(r,e),e+=M.decode.bytes,Lr.decode.bytes=e-t,n};Lr.decode.bytes=0;Lr.encodingLength=function(r){return te.encodingLength(r.flags)+te.encodingLength(r.services)+te.encodingLength(r.regexp)+M.encodingLength(r.replacement)+6};var Ur=q.tlsa={};Ur.encode=function(r,e,t){e||(e=Y.alloc(Ur.encodingLength(r))),t||(t=0);let n=t,i=r.certificate;if(!Y.isBuffer(i))throw new Error("Certificate must be a Buffer");return t+=2,e.writeUInt8(r.usage,t),t+=1,e.writeUInt8(r.selector,t),t+=1,e.writeUInt8(r.matchingType,t),t+=1,i.copy(e,t,0,i.length),t+=i.length,Ur.encode.bytes=t-n,e.writeUInt16BE(Ur.encode.bytes-2,n),e};Ur.encode.bytes=0;Ur.decode=function(r,e){e||(e=0);let t=e,n={},i=r.readUInt16BE(e);return e+=2,n.usage=r.readUInt8(e),e+=1,n.selector=r.readUInt8(e),e+=1,n.matchingType=r.readUInt8(e),e+=1,n.certificate=r.slice(e,t+i+2),e+=n.certificate.length,Ur.decode.bytes=e-t,n};Ur.decode.bytes=0;Ur.encodingLength=function(r){return 5+Y.byteLength(r.certificate)};var Hh=q.record=function(r){switch(r.toUpperCase()){case"A":return gn;case"PTR":return cr;case"CNAME":return fS;case"DNAME":return hS;case"TXT":return hn;case"NULL":return pn;case"AAAA":return wn;case"SRV":return yn;case"HINFO":return mn;case"CAA":return Ct;case"NS":return dn;case"SOA":return fn;case"MX":return ti;case"OPT":return Ut;case"DNSKEY":return ht;case"RRSIG":return kr;case"RP":return Rr;case"NSEC":return Tr;case"NSEC3":return Nr;case"SSHFP":return Lt;case"DS":return Cr;case"NAPTR":return Lr;case"TLSA":return Ur}return un},Xe=q.answer={};Xe.encode=function(r,e,t){e||(e=Y.alloc(Xe.encodingLength(r))),t||(t=0);let n=t;if(M.encode(r.name,e,t),t+=M.encode.bytes,e.writeUInt16BE(En.toType(r.type),t),r.type.toUpperCase()==="OPT"){if(r.name!==".")throw new Error("OPT name must be root.");e.writeUInt16BE(r.udpPayloadSize||4096,t+2),e.writeUInt8(r.extendedRcode||0,t+4),e.writeUInt8(r.ednsVersion||0,t+5),e.writeUInt16BE(r.flags||0,t+6),t+=8,Ut.encode(r.options||[],e,t),t+=Ut.encode.bytes}else{let i=Vl.toClass(r.class===void 0?"IN":r.class);r.flush&&(i|=Mh),e.writeUInt16BE(i,t+2),e.writeUInt32BE(r.ttl||0,t+4),t+=8;let o=Hh(r.type);o.encode(r.data,e,t),t+=o.encode.bytes}return Xe.encode.bytes=t-n,e};Xe.encode.bytes=0;Xe.decode=function(r,e){e||(e=0);let t={},n=e;if(t.name=M.decode(r,e),e+=M.decode.bytes,t.type=En.toString(r.readUInt16BE(e)),t.type==="OPT")t.udpPayloadSize=r.readUInt16BE(e+2),t.extendedRcode=r.readUInt8(e+4),t.ednsVersion=r.readUInt8(e+5),t.flags=r.readUInt16BE(e+6),t.flag_do=(t.flags>>15&1)===1,t.options=Ut.decode(r,e+8),e+=8+Ut.decode.bytes;else{let i=r.readUInt16BE(e+2);t.ttl=r.readUInt32BE(e+4),t.class=Vl.toString(i&uS),t.flush=!!(i&Mh);let o=Hh(t.type);t.data=o.decode(r,e+8),e+=8+o.decode.bytes}return Xe.decode.bytes=e-n,t};Xe.decode.bytes=0;Xe.encodingLength=function(r){let e=r.data!==null&&r.data!==void 0?r.data:r.options;return M.encodingLength(r.name)+8+Hh(r.type).encodingLength(e)};var lr=q.question={};lr.encode=function(r,e,t){e||(e=Y.alloc(lr.encodingLength(r))),t||(t=0);let n=t;return M.encode(r.name,e,t),t+=M.encode.bytes,e.writeUInt16BE(En.toType(r.type),t),t+=2,e.writeUInt16BE(Vl.toClass(r.class===void 0?"IN":r.class),t),t+=2,lr.encode.bytes=t-n,r};lr.encode.bytes=0;lr.decode=function(r,e){e||(e=0);let t=e,n={};return n.name=M.decode(r,e),e+=M.decode.bytes,n.type=En.toString(r.readUInt16BE(e)),e+=2,n.class=Vl.toString(r.readUInt16BE(e)),e+=2,!!(n.class&Rw)&&(n.class&=dS),lr.decode.bytes=e-t,n};lr.decode.bytes=0;lr.encodingLength=function(r){return M.encodingLength(r.name)+4};q.AUTHORITATIVE_ANSWER=1024;q.TRUNCATED_RESPONSE=512;q.RECURSION_DESIRED=256;q.RECURSION_AVAILABLE=128;q.AUTHENTIC_DATA=32;q.CHECKING_DISABLED=16;q.DNSSEC_OK=32768;q.encode=function(r,e,t){let n=!e;n&&(e=Y.alloc(q.encodingLength(r))),t||(t=0);let i=t;return r.questions||(r.questions=[]),r.answers||(r.answers=[]),r.authorities||(r.authorities=[]),r.additionals||(r.additionals=[]),ur.encode(r,e,t),t+=ur.encode.bytes,t=na(r.questions,lr,e,t),t=na(r.answers,Xe,e,t),t=na(r.authorities,Xe,e,t),t=na(r.additionals,Xe,e,t),q.encode.bytes=t-i,n&&q.encode.bytes!==e.length?e.slice(0,q.encode.bytes):e};q.encode.bytes=0;q.decode=function(r,e){e||(e=0);let t=e,n=ur.decode(r,e);return e+=ur.decode.bytes,e=Fl(n.questions,lr,r,e),e=Fl(n.answers,Xe,r,e),e=Fl(n.authorities,Xe,r,e),e=Fl(n.additionals,Xe,r,e),q.decode.bytes=e-t,n};q.decode.bytes=0;q.encodingLength=function(r){return ur.encodingLength(r)+Po(r.questions||[],lr)+Po(r.answers||[],Xe)+Po(r.authorities||[],Xe)+Po(r.additionals||[],Xe)};q.streamEncode=function(r){let e=q.encode(r),t=Y.alloc(2);t.writeUInt16BE(e.byteLength);let n=Y.concat([t,e]);return q.streamEncode.bytes=n.byteLength,n};q.streamEncode.bytes=0;q.streamDecode=function(r){let e=r.readUInt16BE(0);if(r.byteLength<e+2)return null;let t=q.decode(r.slice(2));return q.streamDecode.bytes=q.decode.bytes,t};q.streamDecode.bytes=0;function Po(r,e){let t=0;for(let n=0;n<r.length;n++)t+=e.encodingLength(r[n]);return t}function na(r,e,t,n){for(let i=0;i<r.length;i++)e.encode(r[i],t,n),n+=e.encode.bytes;return n}function Fl(r,e,t,n){for(let i=0;i<r.length;i++)r[i]=e.decode(t,n),n+=e.decode.bytes;return n}});var Hw=le((ua,$l)=>{(function(r,e){"use strict";var t={version:"3.0.0",x86:{},x64:{},inputValidation:!0};function n(f){if(!Array.isArray(f)&&!ArrayBuffer.isView(f))return!1;for(var h=0;h<f.length;h++)if(!Number.isInteger(f[h])||f[h]<0||f[h]>255)return!1;return!0}function i(f,h){return(f&65535)*h+(((f>>>16)*h&65535)<<16)}function o(f,h){return f<<h|f>>>32-h}function s(f){return f^=f>>>16,f=i(f,2246822507),f^=f>>>13,f=i(f,3266489909),f^=f>>>16,f}function a(f,h){f=[f[0]>>>16,f[0]&65535,f[1]>>>16,f[1]&65535],h=[h[0]>>>16,h[0]&65535,h[1]>>>16,h[1]&65535];var m=[0,0,0,0];return m[3]+=f[3]+h[3],m[2]+=m[3]>>>16,m[3]&=65535,m[2]+=f[2]+h[2],m[1]+=m[2]>>>16,m[2]&=65535,m[1]+=f[1]+h[1],m[0]+=m[1]>>>16,m[1]&=65535,m[0]+=f[0]+h[0],m[0]&=65535,[m[0]<<16|m[1],m[2]<<16|m[3]]}function c(f,h){f=[f[0]>>>16,f[0]&65535,f[1]>>>16,f[1]&65535],h=[h[0]>>>16,h[0]&65535,h[1]>>>16,h[1]&65535];var m=[0,0,0,0];return m[3]+=f[3]*h[3],m[2]+=m[3]>>>16,m[3]&=65535,m[2]+=f[2]*h[3],m[1]+=m[2]>>>16,m[2]&=65535,m[2]+=f[3]*h[2],m[1]+=m[2]>>>16,m[2]&=65535,m[1]+=f[1]*h[3],m[0]+=m[1]>>>16,m[1]&=65535,m[1]+=f[2]*h[2],m[0]+=m[1]>>>16,m[1]&=65535,m[1]+=f[3]*h[1],m[0]+=m[1]>>>16,m[1]&=65535,m[0]+=f[0]*h[3]+f[1]*h[2]+f[2]*h[1]+f[3]*h[0],m[0]&=65535,[m[0]<<16|m[1],m[2]<<16|m[3]]}function u(f,h){return h%=64,h===32?[f[1],f[0]]:h<32?[f[0]<<h|f[1]>>>32-h,f[1]<<h|f[0]>>>32-h]:(h-=32,[f[1]<<h|f[0]>>>32-h,f[0]<<h|f[1]>>>32-h])}function l(f,h){return h%=64,h===0?f:h<32?[f[0]<<h|f[1]>>>32-h,f[1]<<h]:[f[1]<<h-32,0]}function d(f,h){return[f[0]^h[0],f[1]^h[1]]}function p(f){return f=d(f,[0,f[0]>>>1]),f=c(f,[4283543511,3981806797]),f=d(f,[0,f[0]>>>1]),f=c(f,[3301882366,444984403]),f=d(f,[0,f[0]>>>1]),f}t.x86.hash32=function(f,h){if(t.inputValidation&&!n(f))return e;h=h||0;for(var m=f.length%4,y=f.length-m,g=h,E=0,x=3432918353,_=461845907,S=0;S<y;S=S+4)E=f[S]|f[S+1]<<8|f[S+2]<<16|f[S+3]<<24,E=i(E,x),E=o(E,15),E=i(E,_),g^=E,g=o(g,13),g=i(g,5)+3864292196;switch(E=0,m){case 3:E^=f[S+2]<<16;case 2:E^=f[S+1]<<8;case 1:E^=f[S],E=i(E,x),E=o(E,15),E=i(E,_),g^=E}return g^=f.length,g=s(g),g>>>0},t.x86.hash128=function(f,h){if(t.inputValidation&&!n(f))return e;h=h||0;for(var m=f.length%16,y=f.length-m,g=h,E=h,x=h,_=h,S=0,A=0,v=0,b=0,T=597399067,C=2869860233,N=951274213,$=2716044179,D=0;D<y;D=D+16)S=f[D]|f[D+1]<<8|f[D+2]<<16|f[D+3]<<24,A=f[D+4]|f[D+5]<<8|f[D+6]<<16|f[D+7]<<24,v=f[D+8]|f[D+9]<<8|f[D+10]<<16|f[D+11]<<24,b=f[D+12]|f[D+13]<<8|f[D+14]<<16|f[D+15]<<24,S=i(S,T),S=o(S,15),S=i(S,C),g^=S,g=o(g,19),g+=E,g=i(g,5)+1444728091,A=i(A,C),A=o(A,16),A=i(A,N),E^=A,E=o(E,17),E+=x,E=i(E,5)+197830471,v=i(v,N),v=o(v,17),v=i(v,$),x^=v,x=o(x,15),x+=_,x=i(x,5)+2530024501,b=i(b,$),b=o(b,18),b=i(b,T),_^=b,_=o(_,13),_+=g,_=i(_,5)+850148119;switch(S=0,A=0,v=0,b=0,m){case 15:b^=f[D+14]<<16;case 14:b^=f[D+13]<<8;case 13:b^=f[D+12],b=i(b,$),b=o(b,18),b=i(b,T),_^=b;case 12:v^=f[D+11]<<24;case 11:v^=f[D+10]<<16;case 10:v^=f[D+9]<<8;case 9:v^=f[D+8],v=i(v,N),v=o(v,17),v=i(v,$),x^=v;case 8:A^=f[D+7]<<24;case 7:A^=f[D+6]<<16;case 6:A^=f[D+5]<<8;case 5:A^=f[D+4],A=i(A,C),A=o(A,16),A=i(A,N),E^=A;case 4:S^=f[D+3]<<24;case 3:S^=f[D+2]<<16;case 2:S^=f[D+1]<<8;case 1:S^=f[D],S=i(S,T),S=o(S,15),S=i(S,C),g^=S}return g^=f.length,E^=f.length,x^=f.length,_^=f.length,g+=E,g+=x,g+=_,E+=g,x+=g,_+=g,g=s(g),E=s(E),x=s(x),_=s(_),g+=E,g+=x,g+=_,E+=g,x+=g,_+=g,("00000000"+(g>>>0).toString(16)).slice(-8)+("00000000"+(E>>>0).toString(16)).slice(-8)+("00000000"+(x>>>0).toString(16)).slice(-8)+("00000000"+(_>>>0).toString(16)).slice(-8)},t.x64.hash128=function(f,h){if(t.inputValidation&&!n(f))return e;h=h||0;for(var m=f.length%16,y=f.length-m,g=[0,h],E=[0,h],x=[0,0],_=[0,0],S=[2277735313,289559509],A=[1291169091,658871167],v=0;v<y;v=v+16)x=[f[v+4]|f[v+5]<<8|f[v+6]<<16|f[v+7]<<24,f[v]|f[v+1]<<8|f[v+2]<<16|f[v+3]<<24],_=[f[v+12]|f[v+13]<<8|f[v+14]<<16|f[v+15]<<24,f[v+8]|f[v+9]<<8|f[v+10]<<16|f[v+11]<<24],x=c(x,S),x=u(x,31),x=c(x,A),g=d(g,x),g=u(g,27),g=a(g,E),g=a(c(g,[0,5]),[0,1390208809]),_=c(_,A),_=u(_,33),_=c(_,S),E=d(E,_),E=u(E,31),E=a(E,g),E=a(c(E,[0,5]),[0,944331445]);switch(x=[0,0],_=[0,0],m){case 15:_=d(_,l([0,f[v+14]],48));case 14:_=d(_,l([0,f[v+13]],40));case 13:_=d(_,l([0,f[v+12]],32));case 12:_=d(_,l([0,f[v+11]],24));case 11:_=d(_,l([0,f[v+10]],16));case 10:_=d(_,l([0,f[v+9]],8));case 9:_=d(_,[0,f[v+8]]),_=c(_,A),_=u(_,33),_=c(_,S),E=d(E,_);case 8:x=d(x,l([0,f[v+7]],56));case 7:x=d(x,l([0,f[v+6]],48));case 6:x=d(x,l([0,f[v+5]],40));case 5:x=d(x,l([0,f[v+4]],32));case 4:x=d(x,l([0,f[v+3]],24));case 3:x=d(x,l([0,f[v+2]],16));case 2:x=d(x,l([0,f[v+1]],8));case 1:x=d(x,[0,f[v]]),x=c(x,S),x=u(x,31),x=c(x,A),g=d(g,x)}return g=d(g,[0,f.length]),E=d(E,[0,f.length]),g=a(g,E),E=a(E,g),g=p(g),E=p(E),g=a(g,E),E=a(E,g),("00000000"+(g[0]>>>0).toString(16)).slice(-8)+("00000000"+(g[1]>>>0).toString(16)).slice(-8)+("00000000"+(E[0]>>>0).toString(16)).slice(-8)+("00000000"+(E[1]>>>0).toString(16)).slice(-8)},typeof ua<"u"?(typeof $l<"u"&&$l.exports&&(ua=$l.exports=t),ua.murmurHash3=t):typeof define=="function"&&define.amd?define([],function(){return t}):(t._murmurHash3=r.murmurHash3,t.noConflict=function(){return r.murmurHash3=t._murmurHash3,t._murmurHash3=e,t.noConflict=e,t},r.murmurHash3=t)})(ua)});var zw=le((O9,$w)=>{$w.exports=Hw()});var Kl=le((z9,Gw)=>{"use strict";Gw.exports=class{constructor(){this._bitArrays=[],this._data=[],this._length=0,this._changedLength=!1,this._changedData=!1}set(e,t){let n=this._internalPositionFor(e,!1);if(t===void 0)n!==-1&&(this._unsetInternalPos(n),this._unsetBit(e),this._changedLength=!0,this._changedData=!0);else{let i=!1;n===-1?(n=this._data.length,this._setBit(e),this._changedData=!0):i=!0,this._setInternalPos(n,e,t,i),this._changedLength=!0}}unset(e){this.set(e,void 0)}get(e){this._sortData();let t=this._internalPositionFor(e,!0);if(t!==-1)return this._data[t][1]}push(e){return this.set(this.length,e),this.length}get length(){if(this._sortData(),this._changedLength){let e=this._data[this._data.length-1];this._length=e?e[0]+1:0,this._changedLength=!1}return this._length}forEach(e){let t=0;for(;t<this.length;)e(this.get(t),t,this),t++}map(e){let t=0,n=new Array(this.length);for(;t<this.length;)n[t]=e(this.get(t),t,this),t++;return n}reduce(e,t){let n=0,i=t;for(;n<this.length;){let o=this.get(n);i=e(i,o,n),n++}return i}find(e){let t=0,n,i;for(;t<this.length&&!n;)i=this.get(t),n=e(i),t++;return n?i:void 0}_internalPositionFor(e,t){let n=this._bytePosFor(e,t);if(n>=this._bitArrays.length)return-1;let i=this._bitArrays[n],o=e-n*7;if(!((i&1<<o)>0))return-1;let a=this._bitArrays.slice(0,n).reduce(RS,0),c=~(4294967295<<o+1),u=Kw(i&c);return a+u-1}_bytePosFor(e,t){let n=Math.floor(e/7),i=n+1;for(;!t&&this._bitArrays.length<i;)this._bitArrays.push(0);return n}_setBit(e){let t=this._bytePosFor(e,!1);this._bitArrays[t]|=1<<e-t*7}_unsetBit(e){let t=this._bytePosFor(e,!1);this._bitArrays[t]&=~(1<<e-t*7)}_setInternalPos(e,t,n,i){let o=this._data,s=[t,n];if(i)this._sortData(),o[e]=s;else{if(o.length)if(o[o.length-1][0]>=t)o.push(s);else if(o[0][0]<=t)o.unshift(s);else{let a=Math.round(o.length/2);this._data=o.slice(0,a).concat(s).concat(o.slice(a))}else this._data.push(s);this._changedData=!0,this._changedLength=!0}}_unsetInternalPos(e){this._data.splice(e,1)}_sortData(){this._changedData&&this._data.sort(TS),this._changedData=!1}bitField(){let e=[],t=8,n=0,i=0,o,s=this._bitArrays.slice();for(;s.length||n;){n===0&&(o=s.shift(),n=7);let c=Math.min(n,t),u=~(255<<c),l=o&u;i|=l<<8-t,o=o>>>c,n-=c,t-=c,(!t||!n&&!s.length)&&(e.push(i),i=0,t=8)}for(var a=e.length-1;a>0&&e[a]===0;a--)e.pop();return e}compactArray(){return this._sortData(),this._data.map(NS)}};function RS(r,e){return r+Kw(e)}function Kw(r){let e=r;return e=e-(e>>1&1431655765),e=(e&858993459)+(e>>2&858993459),(e+(e>>4)&252645135)*16843009>>24}function TS(r,e){return r[0]-e[0]}function NS(r){return r[1]}});var s2=le((_V,o2)=>{var jh=class{constructor(e,t=12,n=8*1024,i=32*1024,o=64,s){this.bits=t,this.min=n,this.max=i,this.asModule=e,this.rabin=new e.Rabin(t,n,i,o,s),this.polynomial=s}fingerprint(e){let{__retain:t,__release:n,__allocArray:i,__getInt32Array:o,Int32Array_ID:s,Uint8Array_ID:a}=this.asModule,c=new Int32Array(Math.ceil(e.length/this.min)),u=t(i(s,c)),l=t(i(a,e)),d=this.rabin.fingerprint(l,u),p=o(d);n(l),n(u);let f=p.indexOf(0);return f>=0?p.subarray(0,f):p}};o2.exports=jh});var f2=le(ha=>{"use strict";var KS=typeof BigUint64Array<"u",da=Symbol(),fa=1024;function a2(r,e){let t=new Uint32Array(r),n=new Uint16Array(r);var i=t[e+-4>>>2]>>>1,o=e>>>1;if(i<=fa)return String.fromCharCode.apply(String,n.subarray(o,o+i));let s=[];do{let a=n[o+fa-1],c=a>=55296&&a<56320?fa-1:fa;s.push(String.fromCharCode.apply(String,n.subarray(o,o+=c))),i-=c}while(i>fa);return s.join("")+String.fromCharCode.apply(String,n.subarray(o,o+i))}function Xh(r){let e={};function t(i,o){return i?a2(i.buffer,o):"<yet unknown>"}let n=r.env=r.env||{};return n.abort=n.abort||function(o,s,a,c){let u=e.memory||n.memory;throw Error("abort: "+t(u,o)+" at "+t(u,s)+":"+a+":"+c)},n.trace=n.trace||function(o,s){let a=e.memory||n.memory;console.log("trace: "+t(a,o)+(s?" ":"")+Array.prototype.slice.call(arguments,2,2+s).join(", "))},r.Math=r.Math||Math,r.Date=r.Date||Date,e}function Zh(r,e){let t=e.exports,n=t.memory,i=t.table,o=t.__alloc,s=t.__retain,a=t.__rtti_base||-1;function c(A){let v=new Uint32Array(n.buffer),b=v[a>>>2];if((A>>>=0)>=b)throw Error("invalid id: "+A);return v[(a+4>>>2)+A*2]}function u(A){let v=new Uint32Array(n.buffer),b=v[a>>>2];if((A>>>=0)>=b)throw Error("invalid id: "+A);return v[(a+4>>>2)+A*2+1]}function l(A){return 31-Math.clz32(A>>>5&31)}function d(A){return 31-Math.clz32(A>>>14&31)}function p(A){let v=A.length,b=o(v<<1,1),T=new Uint16Array(n.buffer);for(var C=0,N=b>>>1;C<v;++C)T[N+C]=A.charCodeAt(C);return b}r.__allocString=p;function f(A){let v=n.buffer;if(new Uint32Array(v)[A+-8>>>2]!==1)throw Error("not a string: "+A);return a2(v,A)}r.__getString=f;function h(A,v,b){let T=n.buffer;if(b)switch(A){case 2:return new Float32Array(T);case 3:return new Float64Array(T)}else switch(A){case 0:return new(v?Int8Array:Uint8Array)(T);case 1:return new(v?Int16Array:Uint16Array)(T);case 2:return new(v?Int32Array:Uint32Array)(T);case 3:return new(v?BigInt64Array:BigUint64Array)(T)}throw Error("unsupported align: "+A)}function m(A,v){let b=c(A);if(!(b&3))throw Error("not an array: "+A+" @ "+b);let T=l(b),C=v.length,N=o(C<<T,0),$=o(b&2?16:12,A),D=new Uint32Array(n.buffer);D[$+0>>>2]=s(N),D[$+4>>>2]=N,D[$+8>>>2]=C<<T,b&2&&(D[$+12>>>2]=C);let ne=h(T,b&1024,b&2048);if(b&8192)for(let B=0;B<C;++B)ne[(N>>>T)+B]=s(v[B]);else ne.set(v,N>>>T);return $}r.__allocArray=m;function y(A){let v=new Uint32Array(n.buffer),b=v[A+-8>>>2],T=c(b);if(!(T&1))throw Error("not an array: "+b);let C=l(T);var N=v[A+4>>>2];let $=T&2?v[A+12>>>2]:v[N+-4>>>2]>>>C;return h(C,T&1024,T&2048).subarray(N>>>=C,N+$)}r.__getArrayView=y;function g(A){let v=y(A),b=v.length,T=new Array(b);for(let C=0;C<b;C++)T[C]=v[C];return T}r.__getArray=g;function E(A){let v=n.buffer,b=new Uint32Array(v)[A+-4>>>2];return v.slice(A,A+b)}r.__getArrayBuffer=E;function x(A,v,b){return new A(_(A,v,b))}function _(A,v,b){let T=n.buffer,C=new Uint32Array(T),N=C[b+4>>>2];return new A(T,N,C[N+-4>>>2]>>>v)}r.__getInt8Array=x.bind(null,Int8Array,0),r.__getInt8ArrayView=_.bind(null,Int8Array,0),r.__getUint8Array=x.bind(null,Uint8Array,0),r.__getUint8ArrayView=_.bind(null,Uint8Array,0),r.__getUint8ClampedArray=x.bind(null,Uint8ClampedArray,0),r.__getUint8ClampedArrayView=_.bind(null,Uint8ClampedArray,0),r.__getInt16Array=x.bind(null,Int16Array,1),r.__getInt16ArrayView=_.bind(null,Int16Array,1),r.__getUint16Array=x.bind(null,Uint16Array,1),r.__getUint16ArrayView=_.bind(null,Uint16Array,1),r.__getInt32Array=x.bind(null,Int32Array,2),r.__getInt32ArrayView=_.bind(null,Int32Array,2),r.__getUint32Array=x.bind(null,Uint32Array,2),r.__getUint32ArrayView=_.bind(null,Uint32Array,2),KS&&(r.__getInt64Array=x.bind(null,BigInt64Array,3),r.__getInt64ArrayView=_.bind(null,BigInt64Array,3),r.__getUint64Array=x.bind(null,BigUint64Array,3),r.__getUint64ArrayView=_.bind(null,BigUint64Array,3)),r.__getFloat32Array=x.bind(null,Float32Array,2),r.__getFloat32ArrayView=_.bind(null,Float32Array,2),r.__getFloat64Array=x.bind(null,Float64Array,3),r.__getFloat64ArrayView=_.bind(null,Float64Array,3);function S(A,v){let b=new Uint32Array(n.buffer);var T=b[A+-8>>>2];if(T<=b[a>>>2])do if(T==v)return!0;while(T=u(T));return!1}return r.__instanceof=S,r.memory=r.memory||n,r.table=r.table||i,d2(t,r)}function c2(r){return typeof Response<"u"&&r instanceof Response}async function l2(r,e){return c2(r=await r)?u2(r,e):Zh(Xh(e||(e={})),await WebAssembly.instantiate(r instanceof WebAssembly.Module?r:await WebAssembly.compile(r),e))}ha.instantiate=l2;function GS(r,e){return Zh(Xh(e||(e={})),new WebAssembly.Instance(r instanceof WebAssembly.Module?r:new WebAssembly.Module(r),e))}ha.instantiateSync=GS;async function u2(r,e){return WebAssembly.instantiateStreaming?Zh(Xh(e||(e={})),(await WebAssembly.instantiateStreaming(r,e)).instance):l2(c2(r=await r)?r.arrayBuffer():r,e)}ha.instantiateStreaming=u2;function d2(r,e){var t=e?Object.create(e):{},n=r.__argumentsLength?function(i){r.__argumentsLength.value=i}:r.__setArgumentsLength||r.__setargc||function(){};for(let i in r){if(!Object.prototype.hasOwnProperty.call(r,i))continue;let o=r[i],s=i.split("."),a=t;for(;s.length>1;){let l=s.shift();Object.prototype.hasOwnProperty.call(a,l)||(a[l]={}),a=a[l]}let c=s[0],u=c.indexOf("#");if(u>=0){let l=c.substring(0,u),d=a[l];if(typeof d>"u"||!d.prototype){let p=function(...f){return p.wrap(p.prototype.constructor(0,...f))};p.prototype={valueOf:function(){return this[da]}},p.wrap=function(f){return Object.create(p.prototype,{[da]:{value:f,writable:!1}})},d&&Object.getOwnPropertyNames(d).forEach(f=>Object.defineProperty(p,f,Object.getOwnPropertyDescriptor(d,f))),a[l]=p}if(c=c.substring(u+1),a=a[l].prototype,/^(get|set):/.test(c)){if(!Object.prototype.hasOwnProperty.call(a,c=c.substring(4))){let p=r[i.replace("set:","get:")],f=r[i.replace("get:","set:")];Object.defineProperty(a,c,{get:function(){return p(this[da])},set:function(h){f(this[da],h)},enumerable:!0})}}else c==="constructor"?(a[c]=(...p)=>(n(p.length),o(...p))).original=o:(a[c]=function(...p){return n(p.length),o(this[da],...p)}).original=o}else/^(get|set):/.test(c)?Object.prototype.hasOwnProperty.call(a,c=c.substring(4))||Object.defineProperty(a,c,{get:r[i.replace("set:","get:")],set:r[i.replace("get:","set:")],enumerable:!0}):typeof o=="function"&&o!==n?(a[c]=(...l)=>(n(l.length),o(...l))).original=o:a[c]=o}return t}ha.demangle=d2});var p2=le((IV,h2)=>{var{instantiate:qS}=f2();Jh.supported=typeof WebAssembly<"u";function Jh(r={}){if(!Jh.supported)return null;var e=new Uint8Array([0,97,115,109,1,0,0,0,1,78,14,96,2,127,126,0,96,1,127,1,126,96,2,127,127,0,96,1,127,1,127,96,1,127,0,96,2,127,127,1,127,96,3,127,127,127,1,127,96,0,0,96,3,127,127,127,0,96,0,1,127,96,4,127,127,127,127,0,96,5,127,127,127,127,127,1,127,96,1,126,1,127,96,2,126,126,1,126,2,13,1,3,101,110,118,5,97,98,111,114,116,0,10,3,54,53,2,2,8,9,3,5,2,8,6,5,3,4,2,6,9,12,13,2,5,11,3,2,3,2,3,2,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,6,7,7,4,4,5,3,1,0,1,6,47,9,127,1,65,0,11,127,1,65,0,11,127,0,65,3,11,127,0,65,4,11,127,1,65,0,11,127,1,65,0,11,127,1,65,0,11,127,0,65,240,2,11,127,0,65,6,11,7,240,5,41,6,109,101,109,111,114,121,2,0,7,95,95,97,108,108,111,99,0,10,8,95,95,114,101,116,97,105,110,0,11,9,95,95,114,101,108,101,97,115,101,0,12,9,95,95,99,111,108,108,101,99,116,0,51,11,95,95,114,116,116,105,95,98,97,115,101,3,7,13,73,110,116,51,50,65,114,114,97,121,95,73,68,3,2,13,85,105,110,116,56,65,114,114,97,121,95,73,68,3,3,6,100,101,103,114,101,101,0,16,3,109,111,100,0,17,5,82,97,98,105,110,3,8,16,82,97,98,105,110,35,103,101,116,58,119,105,110,100,111,119,0,21,16,82,97,98,105,110,35,115,101,116,58,119,105,110,100,111,119,0,22,21,82,97,98,105,110,35,103,101,116,58,119,105,110,100,111,119,95,115,105,122,101,0,23,21,82,97,98,105,110,35,115,101,116,58,119,105,110,100,111,119,95,115,105,122,101,0,24,14,82,97,98,105,110,35,103,101,116,58,119,112,111,115,0,25,14,82,97,98,105,110,35,115,101,116,58,119,112,111,115,0,26,15,82,97,98,105,110,35,103,101,116,58,99,111,117,110,116,0,27,15,82,97,98,105,110,35,115,101,116,58,99,111,117,110,116,0,28,13,82,97,98,105,110,35,103,101,116,58,112,111,115,0,29,13,82,97,98,105,110,35,115,101,116,58,112,111,115,0,30,15,82,97,98,105,110,35,103,101,116,58,115,116,97,114,116,0,31,15,82,97,98,105,110,35,115,101,116,58,115,116,97,114,116,0,32,16,82,97,98,105,110,35,103,101,116,58,100,105,103,101,115,116,0,33,16,82,97,98,105,110,35,115,101,116,58,100,105,103,101,115,116,0,34,21,82,97,98,105,110,35,103,101,116,58,99,104,117,110,107,95,115,116,97,114,116,0,35,21,82,97,98,105,110,35,115,101,116,58,99,104,117,110,107,95,115,116,97,114,116,0,36,22,82,97,98,105,110,35,103,101,116,58,99,104,117,110,107,95,108,101,110,103,116,104,0,37,22,82,97,98,105,110,35,115,101,116,58,99,104,117,110,107,95,108,101,110,103,116,104,0,38,31,82,97,98,105,110,35,103,101,116,58,99,104,117,110,107,95,99,117,116,95,102,105,110,103,101,114,112,114,105,110,116,0,39,31,82,97,98,105,110,35,115,101,116,58,99,104,117,110,107,95,99,117,116,95,102,105,110,103,101,114,112,114,105,110,116,0,40,20,82,97,98,105,110,35,103,101,116,58,112,111,108,121,110,111,109,105,97,108,0,41,20,82,97,98,105,110,35,115,101,116,58,112,111,108,121,110,111,109,105,97,108,0,42,17,82,97,98,105,110,35,103,101,116,58,109,105,110,115,105,122,101,0,43,17,82,97,98,105,110,35,115,101,116,58,109,105,110,115,105,122,101,0,44,17,82,97,98,105,110,35,103,101,116,58,109,97,120,115,105,122,101,0,45,17,82,97,98,105,110,35,115,101,116,58,109,97,120,115,105,122,101,0,46,14,82,97,98,105,110,35,103,101,116,58,109,97,115,107,0,47,14,82,97,98,105,110,35,115,101,116,58,109,97,115,107,0,48,17,82,97,98,105,110,35,99,111,110,115,116,114,117,99,116,111,114,0,20,17,82,97,98,105,110,35,102,105,110,103,101,114,112,114,105,110,116,0,49,8,1,50,10,165,31,53,199,1,1,4,127,32,1,40,2,0,65,124,113,34,2,65,128,2,73,4,127,32,2,65,4,118,33,4,65,0,5,32,2,65,31,32,2,103,107,34,3,65,4,107,118,65,16,115,33,4,32,3,65,7,107,11,33,3,32,1,40,2,20,33,2,32,1,40,2,16,34,5,4,64,32,5,32,2,54,2,20,11,32,2,4,64,32,2,32,5,54,2,16,11,32,1,32,0,32,4,32,3,65,4,116,106,65,2,116,106,40,2,96,70,4,64,32,0,32,4,32,3,65,4,116,106,65,2,116,106,32,2,54,2,96,32,2,69,4,64,32,0,32,3,65,2,116,106,32,0,32,3,65,2,116,106,40,2,4,65,1,32,4,116,65,127,115,113,34,1,54,2,4,32,1,69,4,64,32,0,32,0,40,2,0,65,1,32,3,116,65,127,115,113,54,2,0,11,11,11,11,226,2,1,6,127,32,1,40,2,0,33,3,32,1,65,16,106,32,1,40,2,0,65,124,113,106,34,4,40,2,0,34,5,65,1,113,4,64,32,3,65,124,113,65,16,106,32,5,65,124,113,106,34,2,65,240,255,255,255,3,73,4,64,32,0,32,4,16,1,32,1,32,2,32,3,65,3,113,114,34,3,54,2,0,32,1,65,16,106,32,1,40,2,0,65,124,113,106,34,4,40,2,0,33,5,11,11,32,3,65,2,113,4,64,32,1,65,4,107,40,2,0,34,2,40,2,0,34,6,65,124,113,65,16,106,32,3,65,124,113,106,34,7,65,240,255,255,255,3,73,4,64,32,0,32,2,16,1,32,2,32,7,32,6,65,3,113,114,34,3,54,2,0,32,2,33,1,11,11,32,4,32,5,65,2,114,54,2,0,32,4,65,4,107,32,1,54,2,0,32,0,32,3,65,124,113,34,2,65,128,2,73,4,127,32,2,65,4,118,33,4,65,0,5,32,2,65,31,32,2,103,107,34,2,65,4,107,118,65,16,115,33,4,32,2,65,7,107,11,34,3,65,4,116,32,4,106,65,2,116,106,40,2,96,33,2,32,1,65,0,54,2,16,32,1,32,2,54,2,20,32,2,4,64,32,2,32,1,54,2,16,11,32,0,32,4,32,3,65,4,116,106,65,2,116,106,32,1,54,2,96,32,0,32,0,40,2,0,65,1,32,3,116,114,54,2,0,32,0,32,3,65,2,116,106,32,0,32,3,65,2,116,106,40,2,4,65,1,32,4,116,114,54,2,4,11,119,1,1,127,32,2,2,127,32,0,40,2,160,12,34,2,4,64,32,2,32,1,65,16,107,70,4,64,32,2,40,2,0,33,3,32,1,65,16,107,33,1,11,11,32,1,11,107,34,2,65,48,73,4,64,15,11,32,1,32,3,65,2,113,32,2,65,32,107,65,1,114,114,54,2,0,32,1,65,0,54,2,16,32,1,65,0,54,2,20,32,1,32,2,106,65,16,107,34,2,65,2,54,2,0,32,0,32,2,54,2,160,12,32,0,32,1,16,2,11,155,1,1,3,127,35,0,34,0,69,4,64,65,1,63,0,34,0,74,4,127,65,1,32,0,107,64,0,65,0,72,5,65,0,11,4,64,0,11,65,176,3,34,0,65,0,54,2,0,65,208,15,65,0,54,2,0,3,64,32,1,65,23,73,4,64,32,1,65,2,116,65,176,3,106,65,0,54,2,4,65,0,33,2,3,64,32,2,65,16,73,4,64,32,1,65,4,116,32,2,106,65,2,116,65,176,3,106,65,0,54,2,96,32,2,65,1,106,33,2,12,1,11,11,32,1,65,1,106,33,1,12,1,11,11,65,176,3,65,224,15,63,0,65,16,116,16,3,65,176,3,36,0,11,32,0,11,45,0,32,0,65,240,255,255,255,3,79,4,64,65,32,65,224,0,65,201,3,65,29,16,0,0,11,32,0,65,15,106,65,112,113,34,0,65,16,32,0,65,16,75,27,11,169,1,1,1,127,32,0,32,1,65,128,2,73,4,127,32,1,65,4,118,33,1,65,0,5,32,1,65,248,255,255,255,1,73,4,64,32,1,65,1,65,27,32,1,103,107,116,106,65,1,107,33,1,11,32,1,65,31,32,1,103,107,34,2,65,4,107,118,65,16,115,33,1,32,2,65,7,107,11,34,2,65,2,116,106,40,2,4,65,127,32,1,116,113,34,1,4,127,32,0,32,1,104,32,2,65,4,116,106,65,2,116,106,40,2,96,5,32,0,40,2,0,65,127,32,2,65,1,106,116,113,34,1,4,127,32,0,32,0,32,1,104,34,0,65,2,116,106,40,2,4,104,32,0,65,4,116,106,65,2,116,106,40,2,96,5,65,0,11,11,11,111,1,1,127,63,0,34,2,32,1,65,248,255,255,255,1,73,4,127,32,1,65,1,65,27,32,1,103,107,116,65,1,107,106,5,32,1,11,65,16,32,0,40,2,160,12,32,2,65,16,116,65,16,107,71,116,106,65,255,255,3,106,65,128,128,124,113,65,16,118,34,1,32,2,32,1,74,27,64,0,65,0,72,4,64,32,1,64,0,65,0,72,4,64,0,11,11,32,0,32,2,65,16,116,63,0,65,16,116,16,3,11,113,1,2,127,32,1,40,2,0,34,3,65,124,113,32,2,107,34,4,65,32,79,4,64,32,1,32,2,32,3,65,2,113,114,54,2,0,32,2,32,1,65,16,106,106,34,1,32,4,65,16,107,65,1,114,54,2,0,32,0,32,1,16,2,5,32,1,32,3,65,126,113,54,2,0,32,1,65,16,106,32,1,40,2,0,65,124,113,106,32,1,65,16,106,32,1,40,2,0,65,124,113,106,40,2,0,65,125,113,54,2,0,11,11,91,1,2,127,32,0,32,1,16,5,34,4,16,6,34,3,69,4,64,65,1,36,1,65,0,36,1,32,0,32,4,16,6,34,3,69,4,64,32,0,32,4,16,7,32,0,32,4,16,6,33,3,11,11,32,3,65,0,54,2,4,32,3,32,2,54,2,8,32,3,32,1,54,2,12,32,0,32,3,16,1,32,0,32,3,32,4,16,8,32,3,11,13,0,16,4,32,0,32,1,16,9,65,16,106,11,33,1,1,127,32,0,65,172,3,75,4,64,32,0,65,16,107,34,1,32,1,40,2,4,65,1,106,54,2,4,11,32,0,11,18,0,32,0,65,172,3,75,4,64,32,0,65,16,107,16,52,11,11,140,3,1,1,127,2,64,32,1,69,13,0,32,0,65,0,58,0,0,32,0,32,1,106,65,1,107,65,0,58,0,0,32,1,65,2,77,13,0,32,0,65,1,106,65,0,58,0,0,32,0,65,2,106,65,0,58,0,0,32,0,32,1,106,34,2,65,2,107,65,0,58,0,0,32,2,65,3,107,65,0,58,0,0,32,1,65,6,77,13,0,32,0,65,3,106,65,0,58,0,0,32,0,32,1,106,65,4,107,65,0,58,0,0,32,1,65,8,77,13,0,32,1,65,0,32,0,107,65,3,113,34,1,107,33,2,32,0,32,1,106,34,0,65,0,54,2,0,32,0,32,2,65,124,113,34,1,106,65,4,107,65,0,54,2,0,32,1,65,8,77,13,0,32,0,65,4,106,65,0,54,2,0,32,0,65,8,106,65,0,54,2,0,32,0,32,1,106,34,2,65,12,107,65,0,54,2,0,32,2,65,8,107,65,0,54,2,0,32,1,65,24,77,13,0,32,0,65,12,106,65,0,54,2,0,32,0,65,16,106,65,0,54,2,0,32,0,65,20,106,65,0,54,2,0,32,0,65,24,106,65,0,54,2,0,32,0,32,1,106,34,2,65,28,107,65,0,54,2,0,32,2,65,24,107,65,0,54,2,0,32,2,65,20,107,65,0,54,2,0,32,2,65,16,107,65,0,54,2,0,32,0,32,0,65,4,113,65,24,106,34,2,106,33,0,32,1,32,2,107,33,1,3,64,32,1,65,32,79,4,64,32,0,66,0,55,3,0,32,0,65,8,106,66,0,55,3,0,32,0,65,16,106,66,0,55,3,0,32,0,65,24,106,66,0,55,3,0,32,1,65,32,107,33,1,32,0,65,32,106,33,0,12,1,11,11,11,11,178,1,1,3,127,32,1,65,240,255,255,255,3,32,2,118,75,4,64,65,144,1,65,192,1,65,23,65,56,16,0,0,11,32,1,32,2,116,34,3,65,0,16,10,34,2,32,3,16,13,32,0,69,4,64,65,12,65,2,16,10,34,0,65,172,3,75,4,64,32,0,65,16,107,34,1,32,1,40,2,4,65,1,106,54,2,4,11,11,32,0,65,0,54,2,0,32,0,65,0,54,2,4,32,0,65,0,54,2,8,32,2,34,1,32,0,40,2,0,34,4,71,4,64,32,1,65,172,3,75,4,64,32,1,65,16,107,34,5,32,5,40,2,4,65,1,106,54,2,4,11,32,4,16,12,11,32,0,32,1,54,2,0,32,0,32,2,54,2,4,32,0,32,3,54,2,8,32,0,11,46,1,2,127,65,12,65,5,16,10,34,0,65,172,3,75,4,64,32,0,65,16,107,34,1,32,1,40,2,4,65,1,106,54,2,4,11,32,0,65,128,2,65,3,16,14,11,9,0,65,63,32,0,121,167,107,11,49,1,2,127,65,63,32,1,121,167,107,33,2,3,64,65,63,32,0,121,167,107,32,2,107,34,3,65,0,78,4,64,32,0,32,1,32,3,172,134,133,33,0,12,1,11,11,32,0,11,40,0,32,1,32,0,40,2,8,79,4,64,65,128,2,65,192,2,65,163,1,65,44,16,0,0,11,32,1,32,0,40,2,4,106,65,0,58,0,0,11,38,0,32,1,32,0,40,2,8,79,4,64,65,128,2,65,192,2,65,152,1,65,44,16,0,0,11,32,1,32,0,40,2,4,106,45,0,0,11,254,5,2,1,127,4,126,32,0,69,4,64,65,232,0,65,6,16,10,34,0,65,172,3,75,4,64,32,0,65,16,107,34,5,32,5,40,2,4,65,1,106,54,2,4,11,11,32,0,65,0,54,2,0,32,0,65,0,54,2,4,32,0,65,0,54,2,8,32,0,66,0,55,3,16,32,0,66,0,55,3,24,32,0,66,0,55,3,32,32,0,66,0,55,3,40,32,0,66,0,55,3,48,32,0,66,0,55,3,56,32,0,66,0,55,3,64,32,0,66,0,55,3,72,32,0,66,0,55,3,80,32,0,66,0,55,3,88,32,0,66,0,55,3,96,32,0,32,2,173,55,3,80,32,0,32,3,173,55,3,88,65,12,65,4,16,10,34,2,65,172,3,75,4,64,32,2,65,16,107,34,3,32,3,40,2,4,65,1,106,54,2,4,11,32,2,32,4,65,0,16,14,33,2,32,0,40,2,0,16,12,32,0,32,2,54,2,0,32,0,32,4,54,2,4,32,0,66,1,32,1,173,134,66,1,125,55,3,96,32,0,66,243,130,183,218,216,230,232,30,55,3,72,35,4,69,4,64,65,0,33,2,3,64,32,2,65,128,2,72,4,64,32,2,65,255,1,113,173,33,6,32,0,41,3,72,34,7,33,8,65,63,32,7,121,167,107,33,1,3,64,65,63,32,6,121,167,107,32,1,107,34,3,65,0,78,4,64,32,6,32,8,32,3,172,134,133,33,6,12,1,11,11,65,0,33,4,3,64,32,4,32,0,40,2,4,65,1,107,72,4,64,32,6,66,8,134,33,6,32,0,41,3,72,34,7,33,8,65,63,32,7,121,167,107,33,1,3,64,65,63,32,6,121,167,107,32,1,107,34,3,65,0,78,4,64,32,6,32,8,32,3,172,134,133,33,6,12,1,11,11,32,4,65,1,106,33,4,12,1,11,11,35,6,40,2,4,32,2,65,3,116,106,32,6,55,3,0,32,2,65,1,106,33,2,12,1,11,11,65,63,32,0,41,3,72,121,167,107,172,33,7,65,0,33,2,3,64,32,2,65,128,2,72,4,64,35,5,33,1,32,2,172,32,7,134,34,8,33,6,65,63,32,0,41,3,72,34,9,121,167,107,33,3,3,64,65,63,32,6,121,167,107,32,3,107,34,4,65,0,78,4,64,32,6,32,9,32,4,172,134,133,33,6,12,1,11,11,32,1,40,2,4,32,2,65,3,116,106,32,6,32,8,132,55,3,0,32,2,65,1,106,33,2,12,1,11,11,65,1,36,4,11,32,0,66,0,55,3,24,32,0,66,0,55,3,32,65,0,33,2,3,64,32,2,32,0,40,2,4,72,4,64,32,0,40,2,0,32,2,16,18,32,2,65,1,106,33,2,12,1,11,11,32,0,66,0,55,3,40,32,0,65,0,54,2,8,32,0,66,0,55,3,16,32,0,66,0,55,3,40,32,0,40,2,0,32,0,40,2,8,16,19,33,1,32,0,40,2,8,32,0,40,2,0,40,2,4,106,65,1,58,0,0,32,0,32,0,41,3,40,35,6,40,2,4,32,1,65,3,116,106,41,3,0,133,55,3,40,32,0,32,0,40,2,8,65,1,106,32,0,40,2,4,111,54,2,8,32,0,35,5,40,2,4,32,0,41,3,40,34,6,66,45,136,167,65,3,116,106,41,3,0,32,6,66,8,134,66,1,132,133,55,3,40,32,0,11,38,1,1,127,32,0,40,2,0,34,0,65,172,3,75,4,64,32,0,65,16,107,34,1,32,1,40,2,4,65,1,106,54,2,4,11,32,0,11,55,1,2,127,32,1,32,0,40,2,0,34,2,71,4,64,32,1,65,172,3,75,4,64,32,1,65,16,107,34,3,32,3,40,2,4,65,1,106,54,2,4,11,32,2,16,12,11,32,0,32,1,54,2,0,11,7,0,32,0,40,2,4,11,9,0,32,0,32,1,54,2,4,11,7,0,32,0,40,2,8,11,9,0,32,0,32,1,54,2,8,11,7,0,32,0,41,3,16,11,9,0,32,0,32,1,55,3,16,11,7,0,32,0,41,3,24,11,9,0,32,0,32,1,55,3,24,11,7,0,32,0,41,3,32,11,9,0,32,0,32,1,55,3,32,11,7,0,32,0,41,3,40,11,9,0,32,0,32,1,55,3,40,11,7,0,32,0,41,3,48,11,9,0,32,0,32,1,55,3,48,11,7,0,32,0,41,3,56,11,9,0,32,0,32,1,55,3,56,11,7,0,32,0,41,3,64,11,9,0,32,0,32,1,55,3,64,11,7,0,32,0,41,3,72,11,9,0,32,0,32,1,55,3,72,11,7,0,32,0,41,3,80,11,9,0,32,0,32,1,55,3,80,11,7,0,32,0,41,3,88,11,9,0,32,0,32,1,55,3,88,11,7,0,32,0,41,3,96,11,9,0,32,0,32,1,55,3,96,11,172,4,2,5,127,1,126,32,2,65,172,3,75,4,64,32,2,65,16,107,34,4,32,4,40,2,4,65,1,106,54,2,4,11,32,2,33,4,65,0,33,2,32,1,40,2,8,33,5,32,1,40,2,4,33,6,3,64,2,127,65,0,33,3,3,64,32,3,32,5,72,4,64,32,3,32,6,106,45,0,0,33,1,32,0,40,2,0,32,0,40,2,8,16,19,33,7,32,0,40,2,8,32,0,40,2,0,40,2,4,106,32,1,58,0,0,32,0,32,0,41,3,40,35,6,40,2,4,32,7,65,3,116,106,41,3,0,133,55,3,40,32,0,32,0,40,2,8,65,1,106,32,0,40,2,4,111,54,2,8,32,0,35,5,40,2,4,32,0,41,3,40,34,8,66,45,136,167,65,3,116,106,41,3,0,32,1,173,32,8,66,8,134,132,133,55,3,40,32,0,32,0,41,3,16,66,1,124,55,3,16,32,0,32,0,41,3,24,66,1,124,55,3,24,32,0,41,3,16,32,0,41,3,80,90,4,127,32,0,41,3,40,32,0,41,3,96,131,80,5,65,0,11,4,127,65,1,5,32,0,41,3,16,32,0,41,3,88,90,11,4,64,32,0,32,0,41,3,32,55,3,48,32,0,32,0,41,3,16,55,3,56,32,0,32,0,41,3,40,55,3,64,65,0,33,1,3,64,32,1,32,0,40,2,4,72,4,64,32,0,40,2,0,32,1,16,18,32,1,65,1,106,33,1,12,1,11,11,32,0,66,0,55,3,40,32,0,65,0,54,2,8,32,0,66,0,55,3,16,32,0,66,0,55,3,40,32,0,40,2,0,32,0,40,2,8,16,19,33,1,32,0,40,2,8,32,0,40,2,0,40,2,4,106,65,1,58,0,0,32,0,32,0,41,3,40,35,6,40,2,4,32,1,65,3,116,106,41,3,0,133,55,3,40,32,0,32,0,40,2,8,65,1,106,32,0,40,2,4,111,54,2,8,32,0,35,5,40,2,4,32,0,41,3,40,34,8,66,45,136,167,65,3,116,106,41,3,0,32,8,66,8,134,66,1,132,133,55,3,40,32,3,65,1,106,12,3,11,32,3,65,1,106,33,3,12,1,11,11,65,127,11,34,1,65,0,78,4,64,32,5,32,1,107,33,5,32,1,32,6,106,33,6,32,2,34,1,65,1,106,33,2,32,4,40,2,4,32,1,65,2,116,106,32,0,41,3,56,62,2,0,12,1,11,11,32,4,11,10,0,16,15,36,5,16,15,36,6,11,3,0,1,11,73,1,2,127,32,0,40,2,4,34,1,65,255,255,255,255,0,113,34,2,65,1,70,4,64,32,0,65,16,106,16,53,32,0,32,0,40,2,0,65,1,114,54,2,0,35,0,32,0,16,2,5,32,0,32,2,65,1,107,32,1,65,128,128,128,128,127,113,114,54,2,4,11,11,58,0,2,64,2,64,2,64,32,0,65,8,107,40,2,0,14,7,0,0,1,1,1,1,1,2,11,15,11,32,0,40,2,0,34,0,4,64,32,0,65,172,3,79,4,64,32,0,65,16,107,16,52,11,11,15,11,0,11,11,137,3,7,0,65,16,11,55,40,0,0,0,1,0,0,0,1,0,0,0,40,0,0,0,97,0,108,0,108,0,111,0,99,0,97,0,116,0,105,0,111,0,110,0,32,0,116,0,111,0,111,0,32,0,108,0,97,0,114,0,103,0,101,0,65,208,0,11,45,30,0,0,0,1,0,0,0,1,0,0,0,30,0,0,0,126,0,108,0,105,0,98,0,47,0,114,0,116,0,47,0,116,0,108,0,115,0,102,0,46,0,116,0,115,0,65,128,1,11,43,28,0,0,0,1,0,0,0,1,0,0,0,28,0,0,0,73,0,110,0,118,0,97,0,108,0,105,0,100,0,32,0,108,0,101,0,110,0,103,0,116,0,104,0,65,176,1,11,53,38,0,0,0,1,0,0,0,1,0,0,0,38,0,0,0,126,0,108,0,105,0,98,0,47,0,97,0,114,0,114,0,97,0,121,0,98,0,117,0,102,0,102,0,101,0,114,0,46,0,116,0,115,0,65,240,1,11,51,36,0,0,0,1,0,0,0,1,0,0,0,36,0,0,0,73,0,110,0,100,0,101,0,120,0,32,0,111,0,117,0,116,0,32,0,111,0,102,0,32,0,114,0,97,0,110,0,103,0,101,0,65,176,2,11,51,36,0,0,0,1,0,0,0,1,0,0,0,36,0,0,0,126,0,108,0,105,0,98,0,47,0,116,0,121,0,112,0,101,0,100,0,97,0,114,0,114,0,97,0,121,0,46,0,116,0,115,0,65,240,2,11,53,7,0,0,0,16,0,0,0,0,0,0,0,16,0,0,0,0,0,0,0,16,0,0,0,0,0,0,0,145,4,0,0,2,0,0,0,49,0,0,0,2,0,0,0,17,1,0,0,2,0,0,0,16,0,34,16,115,111,117,114,99,101,77,97,112,112,105,110,103,85,82,76,16,46,47,114,97,98,105,110,46,119,97,115,109,46,109,97,112]);return qS(new Response(new Blob([e],{type:"application/wasm"})),r)}h2.exports=Jh});var g2=le((BV,y2)=>{var m2=s2(),YS=p2(),WS=async(r,e,t,n,i)=>{let o=await YS();return new m2(o,r,e,t,n,i)};y2.exports={Rabin:m2,create:WS}});var z2=le((XM,$2)=>{"use strict";$2.exports=r=>{if(Object.prototype.toString.call(r)!=="[object Object]")return!1;let e=Object.getPrototypeOf(r);return e===null||e===Object.prototype}});var j2=le((Y2,W2)=>{"use strict";var Xl=z2(),{hasOwnProperty:G2}=Object.prototype,{propertyIsEnumerable:x4}=Object,$o=(r,e,t)=>Object.defineProperty(r,e,{value:t,writable:!0,enumerable:!0,configurable:!0}),b4=Y2,K2={concatArrays:!1,ignoreUndefined:!1},Zl=r=>{let e=[];for(let t in r)G2.call(r,t)&&e.push(t);if(Object.getOwnPropertySymbols){let t=Object.getOwnPropertySymbols(r);for(let n of t)x4.call(r,n)&&e.push(n)}return e};function zo(r){return Array.isArray(r)?v4(r):Xl(r)?A4(r):r}function v4(r){let e=r.slice(0,0);return Zl(r).forEach(t=>{$o(e,t,zo(r[t]))}),e}function A4(r){let e=Object.getPrototypeOf(r)===null?Object.create(null):{};return Zl(r).forEach(t=>{$o(e,t,zo(r[t]))}),e}var q2=(r,e,t,n)=>(t.forEach(i=>{typeof e[i]>"u"&&n.ignoreUndefined||(i in r&&r[i]!==Object.getPrototypeOf(r)?$o(r,i,t0(r[i],e[i],n)):$o(r,i,zo(e[i])))}),r),_4=(r,e,t)=>{let n=r.slice(0,0),i=0;return[r,e].forEach(o=>{let s=[];for(let a=0;a<o.length;a++)G2.call(o,a)&&(s.push(String(a)),o===r?$o(n,i++,o[a]):$o(n,i++,zo(o[a])));n=q2(n,o,Zl(o).filter(a=>!s.includes(a)),t)}),n};function t0(r,e,t){return t.concatArrays&&Array.isArray(r)&&Array.isArray(e)?_4(r,e,t):!Xl(e)||!Xl(r)?zo(e):q2(r,e,Zl(e),t)}W2.exports=function(...r){let e=t0(zo(K2),this!==b4&&this||{},K2),t={_:{}};for(let n of r)if(n!==void 0){if(!Xl(n))throw new TypeError("`"+n+"` is not an Option Object");t=t0(t,{_:n},e)}return t._}});var EE=le((fK,wE)=>{"use strict";wE.exports={RTLD_LAZY:1,RTLD_NOW:2,RTLD_GLOBAL:256,RTLD_LOCAL:0,RTLD_DEEPBIND:8,E2BIG:7,EACCES:13,EADDRINUSE:98,EADDRNOTAVAIL:99,EAFNOSUPPORT:97,EAGAIN:11,EALREADY:114,EBADF:9,EBADMSG:74,EBUSY:16,ECANCELED:125,ECHILD:10,ECONNABORTED:103,ECONNREFUSED:111,ECONNRESET:104,EDEADLK:35,EDESTADDRREQ:89,EDOM:33,EDQUOT:122,EEXIST:17,EFAULT:14,EFBIG:27,EHOSTUNREACH:113,EIDRM:43,EILSEQ:84,EINPROGRESS:115,EINTR:4,EINVAL:22,EIO:5,EISCONN:106,EISDIR:21,ELOOP:40,EMFILE:24,EMLINK:31,EMSGSIZE:90,EMULTIHOP:72,ENAMETOOLONG:36,ENETDOWN:100,ENETRESET:102,ENETUNREACH:101,ENFILE:23,ENOBUFS:105,ENODATA:61,ENODEV:19,ENOENT:2,ENOEXEC:8,ENOLCK:37,ENOLINK:67,ENOMEM:12,ENOMSG:42,ENOPROTOOPT:92,ENOSPC:28,ENOSR:63,ENOSTR:60,ENOSYS:38,ENOTCONN:107,ENOTDIR:20,ENOTEMPTY:39,ENOTSOCK:88,ENOTSUP:95,ENOTTY:25,ENXIO:6,EOPNOTSUPP:95,EOVERFLOW:75,EPERM:1,EPIPE:32,EPROTO:71,EPROTONOSUPPORT:93,EPROTOTYPE:91,ERANGE:34,EROFS:30,ESPIPE:29,ESRCH:3,ESTALE:116,ETIME:62,ETIMEDOUT:110,ETXTBSY:26,EWOULDBLOCK:11,EXDEV:18,PRIORITY_LOW:19,PRIORITY_BELOW_NORMAL:10,PRIORITY_NORMAL:0,PRIORITY_ABOVE_NORMAL:-7,PRIORITY_HIGH:-14,PRIORITY_HIGHEST:-20,SIGHUP:1,SIGINT:2,SIGQUIT:3,SIGILL:4,SIGTRAP:5,SIGABRT:6,SIGIOT:6,SIGBUS:7,SIGFPE:8,SIGKILL:9,SIGUSR1:10,SIGSEGV:11,SIGUSR2:12,SIGPIPE:13,SIGALRM:14,SIGTERM:15,SIGCHLD:17,SIGSTKFLT:16,SIGCONT:18,SIGSTOP:19,SIGTSTP:20,SIGTTIN:21,SIGTTOU:22,SIGURG:23,SIGXCPU:24,SIGXFSZ:25,SIGVTALRM:26,SIGPROF:27,SIGWINCH:28,SIGIO:29,SIGPOLL:29,SIGPWR:30,SIGSYS:31,UV_FS_SYMLINK_DIR:1,UV_FS_SYMLINK_JUNCTION:2,O_RDONLY:0,O_WRONLY:1,O_RDWR:2,UV_DIRENT_UNKNOWN:0,UV_DIRENT_FILE:1,UV_DIRENT_DIR:2,UV_DIRENT_LINK:3,UV_DIRENT_FIFO:4,UV_DIRENT_SOCKET:5,UV_DIRENT_CHAR:6,UV_DIRENT_BLOCK:7,EXTENSIONLESS_FORMAT_JAVASCRIPT:0,EXTENSIONLESS_FORMAT_WASM:1,S_IFMT:61440,S_IFREG:32768,S_IFDIR:16384,S_IFCHR:8192,S_IFBLK:24576,S_IFIFO:4096,S_IFLNK:40960,S_IFSOCK:49152,O_CREAT:64,O_EXCL:128,UV_FS_O_FILEMAP:0,O_NOCTTY:256,O_TRUNC:512,O_APPEND:1024,O_DIRECTORY:65536,O_NOATIME:262144,O_NOFOLLOW:131072,O_SYNC:1052672,O_DSYNC:4096,O_DIRECT:16384,O_NONBLOCK:2048,S_IRWXU:448,S_IRUSR:256,S_IWUSR:128,S_IXUSR:64,S_IRWXG:56,S_IRGRP:32,S_IWGRP:16,S_IXGRP:8,S_IRWXO:7,S_IROTH:4,S_IWOTH:2,S_IXOTH:1,F_OK:0,R_OK:4,W_OK:2,X_OK:1,UV_FS_COPYFILE_EXCL:1,COPYFILE_EXCL:1,UV_FS_COPYFILE_FICLONE:2,COPYFILE_FICLONE:2,UV_FS_COPYFILE_FICLONE_FORCE:4,COPYFILE_FICLONE_FORCE:4,OPENSSL_VERSION_NUMBER:805306576,SSL_OP_ALL:2147485776,SSL_OP_ALLOW_NO_DHE_KEX:1024,SSL_OP_ALLOW_UNSAFE_LEGACY_RENEGOTIATION:262144,SSL_OP_CIPHER_SERVER_PREFERENCE:4194304,SSL_OP_CISCO_ANYCONNECT:32768,SSL_OP_COOKIE_EXCHANGE:8192,SSL_OP_CRYPTOPRO_TLSEXT_BUG:2147483648,SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS:2048,SSL_OP_LEGACY_SERVER_CONNECT:4,SSL_OP_NO_COMPRESSION:131072,SSL_OP_NO_ENCRYPT_THEN_MAC:524288,SSL_OP_NO_QUERY_MTU:4096,SSL_OP_NO_RENEGOTIATION:1073741824,SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION:65536,SSL_OP_NO_SSLv2:0,SSL_OP_NO_SSLv3:33554432,SSL_OP_NO_TICKET:16384,SSL_OP_NO_TLSv1:67108864,SSL_OP_NO_TLSv1_1:268435456,SSL_OP_NO_TLSv1_2:134217728,SSL_OP_NO_TLSv1_3:536870912,SSL_OP_PRIORITIZE_CHACHA:2097152,SSL_OP_TLS_ROLLBACK_BUG:8388608,ENGINE_METHOD_RSA:1,ENGINE_METHOD_DSA:2,ENGINE_METHOD_DH:4,ENGINE_METHOD_RAND:8,ENGINE_METHOD_EC:2048,ENGINE_METHOD_CIPHERS:64,ENGINE_METHOD_DIGESTS:128,ENGINE_METHOD_PKEY_METHS:512,ENGINE_METHOD_PKEY_ASN1_METHS:1024,ENGINE_METHOD_ALL:65535,ENGINE_METHOD_NONE:0,DH_CHECK_P_NOT_SAFE_PRIME:2,DH_CHECK_P_NOT_PRIME:1,DH_UNABLE_TO_CHECK_GENERATOR:4,DH_NOT_SUITABLE_GENERATOR:8,RSA_PKCS1_PADDING:1,RSA_NO_PADDING:3,RSA_PKCS1_OAEP_PADDING:4,RSA_X931_PADDING:5,RSA_PKCS1_PSS_PADDING:6,RSA_PSS_SALTLEN_DIGEST:-1,RSA_PSS_SALTLEN_MAX_SIGN:-2,RSA_PSS_SALTLEN_AUTO:-2,defaultCoreCipherList:"TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256:TLS_AES_128_GCM_SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA384:DHE-RSA-AES256-SHA384:ECDHE-RSA-AES256-SHA256:DHE-RSA-AES256-SHA256:HIGH:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!SRP:!CAMELLIA",TLS1_VERSION:769,TLS1_1_VERSION:770,TLS1_2_VERSION:771,TLS1_3_VERSION:772,POINT_CONVERSION_COMPRESSED:2,POINT_CONVERSION_UNCOMPRESSED:4,POINT_CONVERSION_HYBRID:6}});var KI={};Be(KI,{createVerifiedFetch:()=>f0,verifiedFetch:()=>yu});function ci(r){let e=new globalThis.AbortController;function t(){e.abort();for(let o of r)o?.removeEventListener!=null&&o.removeEventListener("abort",t)}for(let o of r){if(o?.aborted===!0){t();break}o?.addEventListener!=null&&o.addEventListener("abort",t)}function n(){for(let o of r)o?.removeEventListener!=null&&o.removeEventListener("abort",t)}let i=e.signal;return i.clear=n,i}function qE(r){let[e,t]=r[Symbol.asyncIterator]!=null?[r[Symbol.asyncIterator](),Symbol.asyncIterator]:[r[Symbol.iterator](),Symbol.iterator],n=[];return{peek:()=>e.next(),push:i=>{n.push(i)},next:()=>n.length>0?{done:!1,value:n.shift()}:e.next(),[t](){return this}}}var Mi=qE;function YE(r){return r[Symbol.asyncIterator]!=null}function v0(r){return r?.then!=null}function WE(r,e){if(YE(r))return async function*(){for await(let a of r){let c=e(a);v0(c)&&await c,yield a}}();let t=Mi(r),{value:n,done:i}=t.next();if(i===!0)return function*(){}();if(typeof e(n)?.then=="function")return async function*(){yield n;for await(let a of t){let c=e(a);v0(c)&&await c,yield a}}();let s=e;return function*(){yield n;for(let a of t)s(a),yield a}()}var wu=WE;var Iu={};Be(Iu,{base32:()=>qe,base32hex:()=>ox,base32hexpad:()=>ax,base32hexpadupper:()=>cx,base32hexupper:()=>sx,base32pad:()=>nx,base32padupper:()=>ix,base32upper:()=>I0,base32z:()=>lx});var Hi={};Be(Hi,{coerce:()=>Ot,empty:()=>A0,equals:()=>Eu,fromHex:()=>XE,fromString:()=>xu,isBinary:()=>ZE,toHex:()=>jE,toString:()=>bu});var A0=new Uint8Array(0);function jE(r){return r.reduce((e,t)=>e+t.toString(16).padStart(2,"0"),"")}function XE(r){let e=r.match(/../g);return e!=null?new Uint8Array(e.map(t=>parseInt(t,16))):A0}function Eu(r,e){if(r===e)return!0;if(r.byteLength!==e.byteLength)return!1;for(let t=0;t<r.byteLength;t++)if(r[t]!==e[t])return!1;return!0}function Ot(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return r;if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return new Uint8Array(r.buffer,r.byteOffset,r.byteLength);throw new Error("Unknown type, must be binary type")}function ZE(r){return r instanceof ArrayBuffer||ArrayBuffer.isView(r)}function xu(r){return new TextEncoder().encode(r)}function bu(r){return new TextDecoder().decode(r)}function JE(r,e){if(r.length>=255)throw new TypeError("Alphabet too long");for(var t=new Uint8Array(256),n=0;n<t.length;n++)t[n]=255;for(var i=0;i<r.length;i++){var o=r.charAt(i),s=o.charCodeAt(0);if(t[s]!==255)throw new TypeError(o+" is ambiguous");t[s]=i}var a=r.length,c=r.charAt(0),u=Math.log(a)/Math.log(256),l=Math.log(256)/Math.log(a);function d(h){if(h instanceof Uint8Array||(ArrayBuffer.isView(h)?h=new Uint8Array(h.buffer,h.byteOffset,h.byteLength):Array.isArray(h)&&(h=Uint8Array.from(h))),!(h instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(h.length===0)return"";for(var m=0,y=0,g=0,E=h.length;g!==E&&h[g]===0;)g++,m++;for(var x=(E-g)*l+1>>>0,_=new Uint8Array(x);g!==E;){for(var S=h[g],A=0,v=x-1;(S!==0||A<y)&&v!==-1;v--,A++)S+=256*_[v]>>>0,_[v]=S%a>>>0,S=S/a>>>0;if(S!==0)throw new Error("Non-zero carry");y=A,g++}for(var b=x-y;b!==x&&_[b]===0;)b++;for(var T=c.repeat(m);b<x;++b)T+=r.charAt(_[b]);return T}function p(h){if(typeof h!="string")throw new TypeError("Expected String");if(h.length===0)return new Uint8Array;var m=0;if(h[m]!==" "){for(var y=0,g=0;h[m]===c;)y++,m++;for(var E=(h.length-m)*u+1>>>0,x=new Uint8Array(E);h[m];){var _=t[h.charCodeAt(m)];if(_===255)return;for(var S=0,A=E-1;(_!==0||S<g)&&A!==-1;A--,S++)_+=a*x[A]>>>0,x[A]=_%256>>>0,_=_/256>>>0;if(_!==0)throw new Error("Non-zero carry");g=S,m++}if(h[m]!==" "){for(var v=E-g;v!==E&&x[v]===0;)v++;for(var b=new Uint8Array(y+(E-v)),T=y;v!==E;)b[T++]=x[v++];return b}}}function f(h){var m=p(h);if(m)return m;throw new Error(`Non-${e} character`)}return{encode:d,decodeUnsafe:p,decode:f}}var QE=JE,ex=QE,_0=ex;var vu=class{name;prefix;baseEncode;constructor(e,t,n){this.name=e,this.prefix=t,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},Au=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,t,n){if(this.name=e,this.prefix=t,t.codePointAt(0)===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=t.codePointAt(0),this.baseDecode=n}decode(e){if(typeof e=="string"){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(e){return S0(this,e)}},_u=class{decoders;constructor(e){this.decoders=e}or(e){return S0(this,e)}decode(e){let t=e[0],n=this.decoders[t];if(n!=null)return n.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function S0(r,e){return new _u({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}var Su=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,t,n,i){this.name=e,this.prefix=t,this.baseEncode=n,this.baseDecode=i,this.encoder=new vu(e,t,n),this.decoder=new Au(e,t,i)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function $i({name:r,prefix:e,encode:t,decode:n}){return new Su(r,e,t,n)}function vn({name:r,prefix:e,alphabet:t}){let{encode:n,decode:i}=_0(t,r);return $i({prefix:e,name:r,encode:n,decode:o=>Ot(i(o))})}function tx(r,e,t,n){let i={};for(let l=0;l<e.length;++l)i[e[l]]=l;let o=r.length;for(;r[o-1]==="=";)--o;let s=new Uint8Array(o*t/8|0),a=0,c=0,u=0;for(let l=0;l<o;++l){let d=i[r[l]];if(d===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<t|d,a+=t,a>=8&&(a-=8,s[u++]=255&c>>a)}if(a>=t||255&c<<8-a)throw new SyntaxError("Unexpected end of data");return s}function rx(r,e,t){let n=e[e.length-1]==="=",i=(1<<t)-1,o="",s=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],s+=8;s>t;)s-=t,o+=e[i&a>>s];if(s!==0&&(o+=e[i&a<<t-s]),n)for(;o.length*t&7;)o+="=";return o}function ke({name:r,prefix:e,bitsPerChar:t,alphabet:n}){return $i({prefix:e,name:r,encode(i){return rx(i,n,t)},decode(i){return tx(i,n,t,r)}})}var qe=ke({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),I0=ke({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),nx=ke({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),ix=ke({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),ox=ke({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),sx=ke({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),ax=ke({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),cx=ke({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),lx=ke({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Bu={};Be(Bu,{base58btc:()=>Ne,base58flickr:()=>ux});var Ne=vn({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),ux=vn({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var dx=R0,B0=128,fx=127,hx=~fx,px=Math.pow(2,31);function R0(r,e,t){e=e||[],t=t||0;for(var n=t;r>=px;)e[t++]=r&255|B0,r/=128;for(;r&hx;)e[t++]=r&255|B0,r>>>=7;return e[t]=r|0,R0.bytes=t-n+1,e}var mx=ku,yx=128,k0=127;function ku(r,n){var t=0,n=n||0,i=0,o=n,s,a=r.length;do{if(o>=a)throw ku.bytes=0,new RangeError("Could not decode varint");s=r[o++],t+=i<28?(s&k0)<<i:(s&k0)*Math.pow(2,i),i+=7}while(s>=yx);return ku.bytes=o-n,t}var gx=Math.pow(2,7),wx=Math.pow(2,14),Ex=Math.pow(2,21),xx=Math.pow(2,28),bx=Math.pow(2,35),vx=Math.pow(2,42),Ax=Math.pow(2,49),_x=Math.pow(2,56),Sx=Math.pow(2,63),Ix=function(r){return r<gx?1:r<wx?2:r<Ex?3:r<xx?4:r<bx?5:r<vx?6:r<Ax?7:r<_x?8:r<Sx?9:10},Bx={encode:dx,decode:mx,encodingLength:Ix},kx=Bx,Zo=kx;function Jo(r,e=0){return[Zo.decode(r,e),Zo.decode.bytes]}function zi(r,e,t=0){return Zo.encode(r,e,t),e}function Ki(r){return Zo.encodingLength(r)}function mr(r,e){let t=e.byteLength,n=Ki(r),i=n+Ki(t),o=new Uint8Array(i+t);return zi(r,o,0),zi(t,o,n),o.set(e,i),new Gi(r,t,e,o)}function st(r){let e=Ot(r),[t,n]=Jo(e),[i,o]=Jo(e.subarray(n)),s=e.subarray(n+o);if(s.byteLength!==i)throw new Error("Incorrect length");return new Gi(t,i,s,e)}function T0(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&Eu(r.bytes,t.bytes)}}var Gi=class{code;size;digest;bytes;constructor(e,t,n,i){this.code=e,this.size=t,this.digest=n,this.bytes=i}};function N0(r,e){let{bytes:t,version:n}=r;switch(n){case 0:return Tx(t,Ru(r),e??Ne.encoder);default:return Nx(t,Ru(r),e??qe.encoder)}}var C0=new WeakMap;function Ru(r){let e=C0.get(r);if(e==null){let t=new Map;return C0.set(r,t),t}return e}var F=class r{code;version;multihash;bytes;"/";constructor(e,t,n,i){this.code=t,this.version=e,this.multihash=n,this.bytes=i,this["/"]=i}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:e,multihash:t}=this;if(e!==Qo)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==Cx)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(t)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:e,digest:t}=this.multihash,n=mr(e,t);return r.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(e){return r.equals(this,e)}static equals(e,t){let n=t;return n!=null&&e.code===n.code&&e.version===n.version&&T0(e.multihash,n.multihash)}toString(e){return N0(this,e)}toJSON(){return{"/":N0(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(e){if(e==null)return null;let t=e;if(t instanceof r)return t;if(t["/"]!=null&&t["/"]===t.bytes||t.asCID===t){let{version:n,code:i,multihash:o,bytes:s}=t;return new r(n,i,o,s??L0(n,i,o.bytes))}else if(t[Lx]===!0){let{version:n,multihash:i,code:o}=t,s=st(i);return r.create(n,o,s)}else return null}static create(e,t,n){if(typeof t!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(e){case 0:{if(t!==Qo)throw new Error(`Version 0 CID must use dag-pb (code: ${Qo}) block encoding`);return new r(e,t,n,n.bytes)}case 1:{let i=L0(e,t,n.bytes);return new r(e,t,n,i)}default:throw new Error("Invalid version")}}static createV0(e){return r.create(0,Qo,e)}static createV1(e,t){return r.create(1,e,t)}static decode(e){let[t,n]=r.decodeFirst(e);if(n.length!==0)throw new Error("Incorrect length");return t}static decodeFirst(e){let t=r.inspectBytes(e),n=t.size-t.multihashSize,i=Ot(e.subarray(n,n+t.multihashSize));if(i.byteLength!==t.multihashSize)throw new Error("Incorrect length");let o=i.subarray(t.multihashSize-t.digestSize),s=new Gi(t.multihashCode,t.digestSize,o,i);return[t.version===0?r.createV0(s):r.createV1(t.codec,s),e.subarray(t.size)]}static inspectBytes(e){let t=0,n=()=>{let[d,p]=Jo(e.subarray(t));return t+=p,d},i=n(),o=Qo;if(i===18?(i=0,t=0):o=n(),i!==0&&i!==1)throw new RangeError(`Invalid CID version ${i}`);let s=t,a=n(),c=n(),u=t+c,l=u-s;return{version:i,codec:o,multihashCode:a,digestSize:c,multihashSize:l,size:u}}static parse(e,t){let[n,i]=Rx(e,t),o=r.decode(i);if(o.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Ru(o).set(n,e),o}};function Rx(r,e){switch(r[0]){case"Q":{let t=e??Ne;return[Ne.prefix,t.decode(`${Ne.prefix}${r}`)]}case Ne.prefix:{let t=e??Ne;return[Ne.prefix,t.decode(r)]}case qe.prefix:{let t=e??qe;return[qe.prefix,t.decode(r)]}default:{if(e==null)throw Error("To parse non base32 or base58btc encoded CID multibase decoder must be provided");return[r[0],e.decode(r)]}}}function Tx(r,e,t){let{prefix:n}=t;if(n!==Ne.prefix)throw Error(`Cannot string encode V0 in ${t.name} encoding`);let i=e.get(n);if(i==null){let o=t.encode(r).slice(1);return e.set(n,o),o}else return i}function Nx(r,e,t){let{prefix:n}=t,i=e.get(n);if(i==null){let o=t.encode(r);return e.set(n,o),o}else return i}var Qo=112,Cx=18;function L0(r,e,t){let n=Ki(r),i=n+Ki(e),o=new Uint8Array(i+t.byteLength);return zi(r,o,0),zi(e,o,n),o.set(t,i),o}var Lx=Symbol.for("@ipld/js-cid/CID");var es=Symbol.for("@libp2p/content-routing");var Tu=Symbol.for("@libp2p/peer-id");function U0(r){return r!=null&&!!r[Tu]}var ts=Symbol.for("@libp2p/peer-routing");var An=class r extends Error{code;type;constructor(e="The operation was aborted"){super(e),this.code=r.code,this.type=r.type}static code="ABORT_ERR";static type="aborted"},O=class extends Error{code;props;constructor(e,t,n){super(e),this.code=t,this.name=n?.name??"CodeError",this.props=n??{}}};var Aa=class extends EventTarget{#e=new Map;listenerCount(e){let t=this.#e.get(e);return t==null?0:t.length}addEventListener(e,t,n){super.addEventListener(e,t,n);let i=this.#e.get(e);i==null&&(i=[],this.#e.set(e,i)),i.push({callback:t,once:(n!==!0&&n!==!1&&n?.once)??!1})}removeEventListener(e,t,n){super.removeEventListener(e.toString(),t??null,n);let i=this.#e.get(e);i!=null&&(i=i.filter(({callback:o})=>o!==t),this.#e.set(e,i))}dispatchEvent(e){let t=super.dispatchEvent(e),n=this.#e.get(e.type);return n==null||(n=n.filter(({once:i})=>!i),this.#e.set(e.type,n)),t}safeDispatchEvent(e,t={}){return this.dispatchEvent(new Ux(e,t))}},Nu=class extends Event{detail;constructor(e,t){super(e,t),this.detail=t?.detail}},Ux=globalThis.CustomEvent??Nu;var _a=(r,...e)=>{try{[...e]}catch{}};function D0(r){return r!=null&&typeof r.start=="function"&&typeof r.stop=="function"}async function _n(...r){let e=[];for(let t of r)D0(t)&&e.push(t);await Promise.all(e.map(async t=>{t.beforeStart!=null&&await t.beforeStart()})),await Promise.all(e.map(async t=>{await t.start()})),await Promise.all(e.map(async t=>{t.afterStart!=null&&await t.afterStart()}))}async function Sn(...r){let e=[];for(let t of r)D0(t)&&e.push(t);await Promise.all(e.map(async t=>{t.beforeStop!=null&&await t.beforeStop()})),await Promise.all(e.map(async t=>{await t.stop()})),await Promise.all(e.map(async t=>{t.afterStop!=null&&await t.afterStop()}))}var Uu={};Be(Uu,{sha256:()=>fe,sha512:()=>Lu});function li({name:r,code:e,encode:t}){return new Cu(r,e,t)}var Cu=class{name;code;encode;constructor(e,t,n){this.name=e,this.code=t,this.encode=n}digest(e){if(e instanceof Uint8Array){let t=this.encode(e);return t instanceof Uint8Array?mr(this.code,t):t.then(n=>mr(this.code,n))}else throw Error("Unknown type, must be binary type")}};function P0(r){return async e=>new Uint8Array(await crypto.subtle.digest(r,e))}var fe=li({name:"sha2-256",code:18,encode:P0("SHA-256")}),Lu=li({name:"sha2-512",code:19,encode:P0("SHA-512")});var St=Q(Ou(),1);var Pu={};Be(Pu,{base64:()=>yr,base64pad:()=>Yx,base64url:()=>H0,base64urlpad:()=>Wx});var yr=ke({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Yx=ke({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),H0=ke({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Wx=ke({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});St.default.formatters.b=r=>r==null?"undefined":Ne.baseEncode(r);St.default.formatters.t=r=>r==null?"undefined":qe.baseEncode(r);St.default.formatters.m=r=>r==null?"undefined":yr.baseEncode(r);St.default.formatters.p=r=>r==null?"undefined":r.toString();St.default.formatters.c=r=>r==null?"undefined":r.toString();St.default.formatters.k=r=>r==null?"undefined":r.toString();St.default.formatters.a=r=>r==null?"undefined":r.toString();function jx(r){let e=()=>{};return e.enabled=!1,e.color="",e.diff=0,e.log=()=>{},e.namespace=r,e.destroy=()=>!0,e.extend=()=>e,e}function $0(){return{forComponent(r){return oe(r)}}}function oe(r){let e=jx(`${r}:trace`);return St.default.enabled(`${r}:trace`)&&St.default.names.map(t=>t.toString()).find(t=>t.includes(":trace"))!=null&&(e=(0,St.default)(`${r}:trace`)),Object.assign((0,St.default)(r),{error:(0,St.default)(`${r}:error`),trace:e})}function he(r,e){if(r===e)return!0;if(r.byteLength!==e.byteLength)return!1;for(let t=0;t<r.byteLength;t++)if(r[t]!==e[t])return!1;return!0}function In(r){return globalThis.Buffer!=null?new Uint8Array(r.buffer,r.byteOffset,r.byteLength):r}function Mr(r=0){return globalThis.Buffer?.alloc!=null?In(globalThis.Buffer.alloc(r)):new Uint8Array(r)}function mt(r=0){return globalThis.Buffer?.allocUnsafe!=null?In(globalThis.Buffer.allocUnsafe(r)):new Uint8Array(r)}var lb=Math.pow(2,7),ub=Math.pow(2,14),db=Math.pow(2,21),Mu=Math.pow(2,28),Hu=Math.pow(2,35),$u=Math.pow(2,42),zu=Math.pow(2,49),pe=128,Je=127;function yt(r){if(r<lb)return 1;if(r<ub)return 2;if(r<db)return 3;if(r<Mu)return 4;if(r<Hu)return 5;if(r<$u)return 6;if(r<zu)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Ku(r,e,t=0){switch(yt(r)){case 8:e[t++]=r&255|pe,r/=128;case 7:e[t++]=r&255|pe,r/=128;case 6:e[t++]=r&255|pe,r/=128;case 5:e[t++]=r&255|pe,r/=128;case 4:e[t++]=r&255|pe,r>>>=7;case 3:e[t++]=r&255|pe,r>>>=7;case 2:e[t++]=r&255|pe,r>>>=7;case 1:{e[t++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return e}function fb(r,e,t=0){switch(yt(r)){case 8:e.set(t++,r&255|pe),r/=128;case 7:e.set(t++,r&255|pe),r/=128;case 6:e.set(t++,r&255|pe),r/=128;case 5:e.set(t++,r&255|pe),r/=128;case 4:e.set(t++,r&255|pe),r>>>=7;case 3:e.set(t++,r&255|pe),r>>>=7;case 2:e.set(t++,r&255|pe),r>>>=7;case 1:{e.set(t++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return e}function Gu(r,e){let t=r[e],n=0;if(n+=t&Je,t<pe||(t=r[e+1],n+=(t&Je)<<7,t<pe)||(t=r[e+2],n+=(t&Je)<<14,t<pe)||(t=r[e+3],n+=(t&Je)<<21,t<pe)||(t=r[e+4],n+=(t&Je)*Mu,t<pe)||(t=r[e+5],n+=(t&Je)*Hu,t<pe)||(t=r[e+6],n+=(t&Je)*$u,t<pe)||(t=r[e+7],n+=(t&Je)*zu,t<pe))return n;throw new RangeError("Could not decode varint")}function hb(r,e){let t=r.get(e),n=0;if(n+=t&Je,t<pe||(t=r.get(e+1),n+=(t&Je)<<7,t<pe)||(t=r.get(e+2),n+=(t&Je)<<14,t<pe)||(t=r.get(e+3),n+=(t&Je)<<21,t<pe)||(t=r.get(e+4),n+=(t&Je)*Mu,t<pe)||(t=r.get(e+5),n+=(t&Je)*Hu,t<pe)||(t=r.get(e+6),n+=(t&Je)*$u,t<pe)||(t=r.get(e+7),n+=(t&Je)*zu,t<pe))return n;throw new RangeError("Could not decode varint")}function ji(r,e,t=0){return e==null&&(e=mt(yt(r))),e instanceof Uint8Array?Ku(r,e,t):fb(r,e,t)}function di(r,e=0){return r instanceof Uint8Array?Gu(r,e):hb(r,e)}var qu=new Float32Array([-0]),Bn=new Uint8Array(qu.buffer);function Q0(r,e,t){qu[0]=r,e[t]=Bn[0],e[t+1]=Bn[1],e[t+2]=Bn[2],e[t+3]=Bn[3]}function ep(r,e){return Bn[0]=r[e],Bn[1]=r[e+1],Bn[2]=r[e+2],Bn[3]=r[e+3],qu[0]}var Yu=new Float64Array([-0]),Qe=new Uint8Array(Yu.buffer);function tp(r,e,t){Yu[0]=r,e[t]=Qe[0],e[t+1]=Qe[1],e[t+2]=Qe[2],e[t+3]=Qe[3],e[t+4]=Qe[4],e[t+5]=Qe[5],e[t+6]=Qe[6],e[t+7]=Qe[7]}function rp(r,e){return Qe[0]=r[e],Qe[1]=r[e+1],Qe[2]=r[e+2],Qe[3]=r[e+3],Qe[4]=r[e+4],Qe[5]=r[e+5],Qe[6]=r[e+6],Qe[7]=r[e+7],Yu[0]}var pb=BigInt(Number.MAX_SAFE_INTEGER),mb=BigInt(Number.MIN_SAFE_INTEGER),It=class r{lo;hi;constructor(e,t){this.lo=e|0,this.hi=t|0}toNumber(e=!1){if(!e&&this.hi>>>31>0){let t=~this.lo+1>>>0,n=~this.hi>>>0;return t===0&&(n=n+1>>>0),-(t+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(e=!1){if(e)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let t=~this.lo+1>>>0,n=~this.hi>>>0;return t===0&&(n=n+1>>>0),-(BigInt(t)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(e=!1){return this.toBigInt(e).toString()}zzEncode(){let e=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^e)>>>0,this.lo=(this.lo<<1^e)>>>0,this}zzDecode(){let e=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^e)>>>0,this.hi=(this.hi>>>1^e)>>>0,this}length(){let e=this.lo,t=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?t===0?e<16384?e<128?1:2:e<2097152?3:4:t<16384?t<128?5:6:t<2097152?7:8:n<128?9:10}static fromBigInt(e){if(e===0n)return fi;if(e<pb&&e>mb)return this.fromNumber(Number(e));let t=e<0n;t&&(e=-e);let n=e>>32n,i=e-(n<<32n);return t&&(n=~n|0n,i=~i|0n,++i>np&&(i=0n,++n>np&&(n=0n))),new r(Number(i),Number(n))}static fromNumber(e){if(e===0)return fi;let t=e<0;t&&(e=-e);let n=e>>>0,i=(e-n)/4294967296>>>0;return t&&(i=~i>>>0,n=~n>>>0,++n>4294967295&&(n=0,++i>4294967295&&(i=0))),new r(n,i)}static from(e){return typeof e=="number"?r.fromNumber(e):typeof e=="bigint"?r.fromBigInt(e):typeof e=="string"?r.fromBigInt(BigInt(e)):e.low!=null||e.high!=null?new r(e.low>>>0,e.high>>>0):fi}},fi=new It(0,0);fi.toBigInt=function(){return 0n};fi.zzEncode=fi.zzDecode=function(){return this};fi.length=function(){return 1};var np=4294967296n;function ip(r){let e=0,t=0;for(let n=0;n<r.length;++n)t=r.charCodeAt(n),t<128?e+=1:t<2048?e+=2:(t&64512)===55296&&(r.charCodeAt(n+1)&64512)===56320?(++n,e+=4):e+=3;return e}function op(r,e,t){if(t-e<1)return"";let i,o=[],s=0,a;for(;e<t;)a=r[e++],a<128?o[s++]=a:a>191&&a<224?o[s++]=(a&31)<<6|r[e++]&63:a>239&&a<365?(a=((a&7)<<18|(r[e++]&63)<<12|(r[e++]&63)<<6|r[e++]&63)-65536,o[s++]=55296+(a>>10),o[s++]=56320+(a&1023)):o[s++]=(a&15)<<12|(r[e++]&63)<<6|r[e++]&63,s>8191&&((i??(i=[])).push(String.fromCharCode.apply(String,o)),s=0);return i!=null?(s>0&&i.push(String.fromCharCode.apply(String,o.slice(0,s))),i.join("")):String.fromCharCode.apply(String,o.slice(0,s))}function Wu(r,e,t){let n=t,i,o;for(let s=0;s<r.length;++s)i=r.charCodeAt(s),i<128?e[t++]=i:i<2048?(e[t++]=i>>6|192,e[t++]=i&63|128):(i&64512)===55296&&((o=r.charCodeAt(s+1))&64512)===56320?(i=65536+((i&1023)<<10)+(o&1023),++s,e[t++]=i>>18|240,e[t++]=i>>12&63|128,e[t++]=i>>6&63|128,e[t++]=i&63|128):(e[t++]=i>>12|224,e[t++]=i>>6&63|128,e[t++]=i&63|128);return t-n}function Xt(r,e){return RangeError(`index out of range: ${r.pos} + ${e??1} > ${r.len}`)}function ka(r,e){return(r[e-4]|r[e-3]<<8|r[e-2]<<16|r[e-1]<<24)>>>0}var ju=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(e){this.buf=e,this.pos=0,this.len=e.length}uint32(){let e=4294967295;if(e=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(e=(e|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return e;if((this.pos+=5)>this.len)throw this.pos=this.len,Xt(this,10);return e}int32(){return this.uint32()|0}sint32(){let e=this.uint32();return e>>>1^-(e&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw Xt(this,4);return ka(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Xt(this,4);return ka(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Xt(this,4);let e=ep(this.buf,this.pos);return this.pos+=4,e}double(){if(this.pos+8>this.len)throw Xt(this,4);let e=rp(this.buf,this.pos);return this.pos+=8,e}bytes(){let e=this.uint32(),t=this.pos,n=this.pos+e;if(n>this.len)throw Xt(this,e);return this.pos+=e,t===n?new Uint8Array(0):this.buf.subarray(t,n)}string(){let e=this.bytes();return op(e,0,e.length)}skip(e){if(typeof e=="number"){if(this.pos+e>this.len)throw Xt(this,e);this.pos+=e}else do if(this.pos>=this.len)throw Xt(this);while(this.buf[this.pos++]&128);return this}skipType(e){switch(e){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(e=this.uint32()&7)!==4;)this.skipType(e);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${e} at offset ${this.pos}`)}return this}readLongVarint(){let e=new It(0,0),t=0;if(this.len-this.pos>4){for(;t<4;++t)if(e.lo=(e.lo|(this.buf[this.pos]&127)<<t*7)>>>0,this.buf[this.pos++]<128)return e;if(e.lo=(e.lo|(this.buf[this.pos]&127)<<28)>>>0,e.hi=(e.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return e;t=0}else{for(;t<3;++t){if(this.pos>=this.len)throw Xt(this);if(e.lo=(e.lo|(this.buf[this.pos]&127)<<t*7)>>>0,this.buf[this.pos++]<128)return e}return e.lo=(e.lo|(this.buf[this.pos++]&127)<<t*7)>>>0,e}if(this.len-this.pos>4){for(;t<5;++t)if(e.hi=(e.hi|(this.buf[this.pos]&127)<<t*7+3)>>>0,this.buf[this.pos++]<128)return e}else for(;t<5;++t){if(this.pos>=this.len)throw Xt(this);if(e.hi=(e.hi|(this.buf[this.pos]&127)<<t*7+3)>>>0,this.buf[this.pos++]<128)return e}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw Xt(this,8);let e=ka(this.buf,this.pos+=4),t=ka(this.buf,this.pos+=4);return new It(e,t)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let e=Gu(this.buf,this.pos);return this.pos+=yt(e),e}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function Xu(r){return new ju(r instanceof Uint8Array?r:r.subarray())}function Ft(r,e,t){let n=Xu(r);return e.decode(n,void 0,t)}var Zu={};Be(Zu,{base10:()=>yb});var yb=vn({prefix:"9",name:"base10",alphabet:"0123456789"});var Ju={};Be(Ju,{base16:()=>gb,base16upper:()=>wb});var gb=ke({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),wb=ke({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Qu={};Be(Qu,{base2:()=>Eb});var Eb=ke({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var ed={};Be(ed,{base256emoji:()=>_b});var ap=Array.from("\u{1F680}\u{1FA90}\u2604\u{1F6F0}\u{1F30C}\u{1F311}\u{1F312}\u{1F313}\u{1F314}\u{1F315}\u{1F316}\u{1F317}\u{1F318}\u{1F30D}\u{1F30F}\u{1F30E}\u{1F409}\u2600\u{1F4BB}\u{1F5A5}\u{1F4BE}\u{1F4BF}\u{1F602}\u2764\u{1F60D}\u{1F923}\u{1F60A}\u{1F64F}\u{1F495}\u{1F62D}\u{1F618}\u{1F44D}\u{1F605}\u{1F44F}\u{1F601}\u{1F525}\u{1F970}\u{1F494}\u{1F496}\u{1F499}\u{1F622}\u{1F914}\u{1F606}\u{1F644}\u{1F4AA}\u{1F609}\u263A\u{1F44C}\u{1F917}\u{1F49C}\u{1F614}\u{1F60E}\u{1F607}\u{1F339}\u{1F926}\u{1F389}\u{1F49E}\u270C\u2728\u{1F937}\u{1F631}\u{1F60C}\u{1F338}\u{1F64C}\u{1F60B}\u{1F497}\u{1F49A}\u{1F60F}\u{1F49B}\u{1F642}\u{1F493}\u{1F929}\u{1F604}\u{1F600}\u{1F5A4}\u{1F603}\u{1F4AF}\u{1F648}\u{1F447}\u{1F3B6}\u{1F612}\u{1F92D}\u2763\u{1F61C}\u{1F48B}\u{1F440}\u{1F62A}\u{1F611}\u{1F4A5}\u{1F64B}\u{1F61E}\u{1F629}\u{1F621}\u{1F92A}\u{1F44A}\u{1F973}\u{1F625}\u{1F924}\u{1F449}\u{1F483}\u{1F633}\u270B\u{1F61A}\u{1F61D}\u{1F634}\u{1F31F}\u{1F62C}\u{1F643}\u{1F340}\u{1F337}\u{1F63B}\u{1F613}\u2B50\u2705\u{1F97A}\u{1F308}\u{1F608}\u{1F918}\u{1F4A6}\u2714\u{1F623}\u{1F3C3}\u{1F490}\u2639\u{1F38A}\u{1F498}\u{1F620}\u261D\u{1F615}\u{1F33A}\u{1F382}\u{1F33B}\u{1F610}\u{1F595}\u{1F49D}\u{1F64A}\u{1F639}\u{1F5E3}\u{1F4AB}\u{1F480}\u{1F451}\u{1F3B5}\u{1F91E}\u{1F61B}\u{1F534}\u{1F624}\u{1F33C}\u{1F62B}\u26BD\u{1F919}\u2615\u{1F3C6}\u{1F92B}\u{1F448}\u{1F62E}\u{1F646}\u{1F37B}\u{1F343}\u{1F436}\u{1F481}\u{1F632}\u{1F33F}\u{1F9E1}\u{1F381}\u26A1\u{1F31E}\u{1F388}\u274C\u270A\u{1F44B}\u{1F630}\u{1F928}\u{1F636}\u{1F91D}\u{1F6B6}\u{1F4B0}\u{1F353}\u{1F4A2}\u{1F91F}\u{1F641}\u{1F6A8}\u{1F4A8}\u{1F92C}\u2708\u{1F380}\u{1F37A}\u{1F913}\u{1F619}\u{1F49F}\u{1F331}\u{1F616}\u{1F476}\u{1F974}\u25B6\u27A1\u2753\u{1F48E}\u{1F4B8}\u2B07\u{1F628}\u{1F31A}\u{1F98B}\u{1F637}\u{1F57A}\u26A0\u{1F645}\u{1F61F}\u{1F635}\u{1F44E}\u{1F932}\u{1F920}\u{1F927}\u{1F4CC}\u{1F535}\u{1F485}\u{1F9D0}\u{1F43E}\u{1F352}\u{1F617}\u{1F911}\u{1F30A}\u{1F92F}\u{1F437}\u260E\u{1F4A7}\u{1F62F}\u{1F486}\u{1F446}\u{1F3A4}\u{1F647}\u{1F351}\u2744\u{1F334}\u{1F4A3}\u{1F438}\u{1F48C}\u{1F4CD}\u{1F940}\u{1F922}\u{1F445}\u{1F4A1}\u{1F4A9}\u{1F450}\u{1F4F8}\u{1F47B}\u{1F910}\u{1F92E}\u{1F3BC}\u{1F975}\u{1F6A9}\u{1F34E}\u{1F34A}\u{1F47C}\u{1F48D}\u{1F4E3}\u{1F942}"),xb=ap.reduce((r,e,t)=>(r[t]=e,r),[]),bb=ap.reduce((r,e,t)=>(r[e.codePointAt(0)]=t,r),[]);function vb(r){return r.reduce((e,t)=>(e+=xb[t],e),"")}function Ab(r){let e=[];for(let t of r){let n=bb[t.codePointAt(0)];if(n===void 0)throw new Error(`Non-base256emoji character: ${t}`);e.push(n)}return new Uint8Array(e)}var _b=$i({prefix:"\u{1F680}",name:"base256emoji",encode:vb,decode:Ab});var td={};Be(td,{base36:()=>kn,base36upper:()=>Sb});var kn=vn({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Sb=vn({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var rd={};Be(rd,{base8:()=>Ib});var Ib=ke({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var nd={};Be(nd,{identity:()=>Bb});var Bb=$i({prefix:"\0",name:"identity",encode:r=>bu(r),decode:r=>xu(r)});var XB=new TextEncoder,kb=new TextDecoder;var Rn=512;function cp(r){return JSON.parse(kb.decode(r))}var Vt={};Be(Vt,{code:()=>Ae,decode:()=>Nb,encode:()=>Tb,name:()=>Rb});var Rb="raw",Ae=85;function Tb(r){return Ot(r)}function Nb(r){return Ot(r)}var id={};Be(id,{identity:()=>et});var lp=0,Cb="identity",up=Ot;function Lb(r){return mr(lp,up(r))}var et={code:lp,name:Cb,encode:up,digest:Lb};var Tn={...nd,...Qu,...rd,...Zu,...Ju,...Iu,...td,...Bu,...Pu,...ed},c8={...Uu,...id};function fp(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}var dp=fp("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),od=fp("ascii","a",r=>{let e="a";for(let t=0;t<r.length;t++)e+=String.fromCharCode(r[t]);return e},r=>{r=r.substring(1);let e=mt(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),Ub={utf8:dp,"utf-8":dp,hex:Tn.base16,latin1:od,ascii:od,binary:od,...Tn},Ta=Ub;function H(r,e="utf8"){let t=Ta[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return(e==="utf8"||e==="utf-8")&&globalThis.Buffer!=null&&globalThis.Buffer.from!=null?In(globalThis.Buffer.from(r,"utf-8")):t.decoder.decode(`${t.prefix}${r}`)}function sd(r){let e=r??8192,t=e>>>1,n,i=e;return function(s){if(s<1||s>t)return mt(s);i+s>e&&(n=mt(e),i=0);let a=n.subarray(i,i+=s);return i&7&&(i=(i|7)+1),a}}var hi=class{fn;len;next;val;constructor(e,t,n){this.fn=e,this.len=t,this.next=void 0,this.val=n}};function ad(){}var ld=class{head;tail;len;next;constructor(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}},Db=sd();function Ob(r){return globalThis.Buffer!=null?mt(r):Db(r)}var ns=class{len;head;tail;states;constructor(){this.len=0,this.head=new hi(ad,0,0),this.tail=this.head,this.states=null}_push(e,t,n){return this.tail=this.tail.next=new hi(e,t,n),this.len+=t,this}uint32(e){return this.len+=(this.tail=this.tail.next=new ud((e=e>>>0)<128?1:e<16384?2:e<2097152?3:e<268435456?4:5,e)).len,this}int32(e){return e<0?this._push(Na,10,It.fromNumber(e)):this.uint32(e)}sint32(e){return this.uint32((e<<1^e>>31)>>>0)}uint64(e){let t=It.fromBigInt(e);return this._push(Na,t.length(),t)}uint64Number(e){return this._push(Ku,yt(e),e)}uint64String(e){return this.uint64(BigInt(e))}int64(e){return this.uint64(e)}int64Number(e){return this.uint64Number(e)}int64String(e){return this.uint64String(e)}sint64(e){let t=It.fromBigInt(e).zzEncode();return this._push(Na,t.length(),t)}sint64Number(e){let t=It.fromNumber(e).zzEncode();return this._push(Na,t.length(),t)}sint64String(e){return this.sint64(BigInt(e))}bool(e){return this._push(cd,1,e?1:0)}fixed32(e){return this._push(rs,4,e>>>0)}sfixed32(e){return this.fixed32(e)}fixed64(e){let t=It.fromBigInt(e);return this._push(rs,4,t.lo)._push(rs,4,t.hi)}fixed64Number(e){let t=It.fromNumber(e);return this._push(rs,4,t.lo)._push(rs,4,t.hi)}fixed64String(e){return this.fixed64(BigInt(e))}sfixed64(e){return this.fixed64(e)}sfixed64Number(e){return this.fixed64Number(e)}sfixed64String(e){return this.fixed64String(e)}float(e){return this._push(Q0,4,e)}double(e){return this._push(tp,8,e)}bytes(e){let t=e.length>>>0;return t===0?this._push(cd,1,0):this.uint32(t)._push(Fb,t,e)}string(e){let t=ip(e);return t!==0?this.uint32(t)._push(Wu,t,e):this._push(cd,1,0)}fork(){return this.states=new ld(this),this.head=this.tail=new hi(ad,0,0),this.len=0,this}reset(){return this.states!=null?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new hi(ad,0,0),this.len=0),this}ldelim(){let e=this.head,t=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=e.next,this.tail=t,this.len+=n),this}finish(){let e=this.head.next,t=Ob(this.len),n=0;for(;e!=null;)e.fn(e.val,t,n),n+=e.len,e=e.next;return t}};function cd(r,e,t){e[t]=r&255}function Pb(r,e,t){for(;r>127;)e[t++]=r&127|128,r>>>=7;e[t]=r}var ud=class extends hi{next;constructor(e,t){super(Pb,e,t),this.next=void 0}};function Na(r,e,t){for(;r.hi!==0;)e[t++]=r.lo&127|128,r.lo=(r.lo>>>7|r.hi<<25)>>>0,r.hi>>>=7;for(;r.lo>127;)e[t++]=r.lo&127|128,r.lo=r.lo>>>7;e[t++]=r.lo}function rs(r,e,t){e[t]=r&255,e[t+1]=r>>>8&255,e[t+2]=r>>>16&255,e[t+3]=r>>>24}function Fb(r,e,t){e.set(r,t)}globalThis.Buffer!=null&&(ns.prototype.bytes=function(r){let e=r.length>>>0;return this.uint32(e),e>0&&this._push(Vb,e,r),this},ns.prototype.string=function(r){let e=globalThis.Buffer.byteLength(r);return this.uint32(e),e>0&&this._push(Mb,e,r),this});function Vb(r,e,t){e.set(r,t)}function Mb(r,e,t){r.length<40?Wu(r,e,t):e.utf8Write!=null?e.utf8Write(r,t):e.set(H(r),t)}function dd(){return new ns}function Mt(r,e){let t=dd();return e.encode(r,t,{lengthDelimited:!1}),t.finish()}var Xi;(function(r){r[r.VARINT=0]="VARINT",r[r.BIT64=1]="BIT64",r[r.LENGTH_DELIMITED=2]="LENGTH_DELIMITED",r[r.START_GROUP=3]="START_GROUP",r[r.END_GROUP=4]="END_GROUP",r[r.BIT32=5]="BIT32"})(Xi||(Xi={}));function Ca(r,e,t,n){return{name:r,type:e,encode:t,decode:n}}function pi(r){function e(i){if(r[i.toString()]==null)throw new Error("Invalid enum value");return r[i]}let t=function(o,s){let a=e(o);s.int32(a)},n=function(o){let s=o.int32();return e(s)};return Ca("enum",Xi.VARINT,t,n)}function Ht(r,e){return Ca("message",Xi.LENGTH_DELIMITED,r,e)}function Hb(r){return r[Symbol.asyncIterator]!=null}function $b(r){if(Hb(r))return(async()=>{for await(let e of r);})();for(let e of r);}var Zt=$b;function we(r,e){if(globalThis.Buffer!=null)return In(globalThis.Buffer.concat(r,e));e==null&&(e=r.reduce((i,o)=>i+o.length,0));let t=mt(e),n=0;for(let i of r)t.set(i,n),n+=i.length;return In(t)}var pp=Symbol.for("@achingbrain/uint8arraylist");function hp(r,e){if(e==null||e<0)throw new RangeError("index is out of bounds");let t=0;for(let n of r){let i=t+n.byteLength;if(e<i)return{buf:n,index:e-t};t=i}throw new RangeError("index is out of bounds")}function gr(r){return!!r?.[pp]}var $t=class r{bufs;length;[pp]=!0;constructor(...e){this.bufs=[],this.length=0,e.length>0&&this.appendAll(e)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...e){this.appendAll(e)}appendAll(e){let t=0;for(let n of e)if(n instanceof Uint8Array)t+=n.byteLength,this.bufs.push(n);else if(gr(n))t+=n.byteLength,this.bufs.push(...n.bufs);else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=t}prepend(...e){this.prependAll(e)}prependAll(e){let t=0;for(let n of e.reverse())if(n instanceof Uint8Array)t+=n.byteLength,this.bufs.unshift(n);else if(gr(n))t+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=t}get(e){let t=hp(this.bufs,e);return t.buf[t.index]}set(e,t){let n=hp(this.bufs,e);n.buf[n.index]=t}write(e,t=0){if(e instanceof Uint8Array)for(let n=0;n<e.length;n++)this.set(t+n,e[n]);else if(gr(e))for(let n=0;n<e.length;n++)this.set(t+n,e.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(e){if(e=Math.trunc(e),!(Number.isNaN(e)||e<=0)){if(e===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(e>=this.bufs[0].byteLength)e-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(e),this.length-=e;break}}}slice(e,t){let{bufs:n,length:i}=this._subList(e,t);return we(n,i)}subarray(e,t){let{bufs:n,length:i}=this._subList(e,t);return n.length===1?n[0]:we(n,i)}sublist(e,t){let{bufs:n,length:i}=this._subList(e,t),o=new r;return o.length=i,o.bufs=[...n],o}_subList(e,t){if(e=e??0,t=t??this.length,e<0&&(e=this.length+e),t<0&&(t=this.length+t),e<0||t>this.length)throw new RangeError("index is out of bounds");if(e===t)return{bufs:[],length:0};if(e===0&&t===this.length)return{bufs:this.bufs,length:this.length};let n=[],i=0;for(let o=0;o<this.bufs.length;o++){let s=this.bufs[o],a=i,c=a+s.byteLength;if(i=c,e>=c)continue;let u=e>=a&&e<c,l=t>a&&t<=c;if(u&&l){if(e===a&&t===c){n.push(s);break}let d=e-a;n.push(s.subarray(d,d+(t-e)));break}if(u){if(e===0){n.push(s);continue}n.push(s.subarray(e-a));continue}if(l){if(t===c){n.push(s);break}n.push(s.subarray(0,t-a));break}n.push(s)}return{bufs:n,length:t-e}}indexOf(e,t=0){if(!gr(e)&&!(e instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=e instanceof Uint8Array?e:e.subarray();if(t=Number(t??0),isNaN(t)&&(t=0),t<0&&(t=this.length+t),t<0&&(t=0),e.length===0)return t>this.length?this.length:t;let i=n.byteLength;if(i===0)throw new TypeError("search must be at least 1 byte long");let o=256,s=new Int32Array(o);for(let d=0;d<o;d++)s[d]=-1;for(let d=0;d<i;d++)s[n[d]]=d;let a=s,c=this.byteLength-n.byteLength,u=n.byteLength-1,l;for(let d=t;d<=c;d+=l){l=0;for(let p=u;p>=0;p--){let f=this.get(d+p);if(n[p]!==f){l=Math.max(1,p-a[f]);break}}if(l===0)return d}return-1}getInt8(e){let t=this.subarray(e,e+1);return new DataView(t.buffer,t.byteOffset,t.byteLength).getInt8(0)}setInt8(e,t){let n=mt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,t),this.write(n,e)}getInt16(e,t){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,t)}setInt16(e,t,n){let i=Mr(2);new DataView(i.buffer,i.byteOffset,i.byteLength).setInt16(0,t,n),this.write(i,e)}getInt32(e,t){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,t)}setInt32(e,t,n){let i=Mr(4);new DataView(i.buffer,i.byteOffset,i.byteLength).setInt32(0,t,n),this.write(i,e)}getBigInt64(e,t){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,t)}setBigInt64(e,t,n){let i=Mr(8);new DataView(i.buffer,i.byteOffset,i.byteLength).setBigInt64(0,t,n),this.write(i,e)}getUint8(e){let t=this.subarray(e,e+1);return new DataView(t.buffer,t.byteOffset,t.byteLength).getUint8(0)}setUint8(e,t){let n=mt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,t),this.write(n,e)}getUint16(e,t){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,t)}setUint16(e,t,n){let i=Mr(2);new DataView(i.buffer,i.byteOffset,i.byteLength).setUint16(0,t,n),this.write(i,e)}getUint32(e,t){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,t)}setUint32(e,t,n){let i=Mr(4);new DataView(i.buffer,i.byteOffset,i.byteLength).setUint32(0,t,n),this.write(i,e)}getBigUint64(e,t){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,t)}setBigUint64(e,t,n){let i=Mr(8);new DataView(i.buffer,i.byteOffset,i.byteLength).setBigUint64(0,t,n),this.write(i,e)}getFloat32(e,t){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,t)}setFloat32(e,t,n){let i=Mr(4);new DataView(i.buffer,i.byteOffset,i.byteLength).setFloat32(0,t,n),this.write(i,e)}getFloat64(e,t){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,t)}setFloat64(e,t,n){let i=Mr(8);new DataView(i.buffer,i.byteOffset,i.byteLength).setFloat64(0,t,n),this.write(i,e)}equals(e){if(e==null||!(e instanceof r)||e.bufs.length!==this.bufs.length)return!1;for(let t=0;t<this.bufs.length;t++)if(!he(this.bufs[t],e.bufs[t]))return!1;return!0}static fromUint8Arrays(e,t){let n=new r;return n.bufs=e,t==null&&(t=e.reduce((i,o)=>i+o.byteLength,0)),n.length=t,n}};function Kb(r){return r[Symbol.asyncIterator]!=null}function Gb(r,e){if(Kb(r))return async function*(){for await(let a of r)yield e(a)}();let t=Mi(r),{value:n,done:i}=t.next();if(i===!0)return function*(){}();let o=e(n);if(typeof o.then=="function")return async function*(){yield await o;for await(let a of t)yield e(a)}();let s=e;return function*(){yield o;for(let a of t)yield s(a)}()}var at=Gb;function _e(){let r={};return r.promise=new Promise((e,t)=>{r.resolve=e,r.reject=t}),r}var La=class{buffer;mask;top;btm;next;constructor(e){if(!(e>0)||e-1&e)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(e),this.mask=e-1,this.top=0,this.btm=0,this.next=null}push(e){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=e,this.top=this.top+1&this.mask,!0)}shift(){let e=this.buffer[this.btm];if(e!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,e}isEmpty(){return this.buffer[this.btm]===void 0}},Zi=class{size;hwm;head;tail;constructor(e={}){this.hwm=e.splitLimit??16,this.head=new La(this.hwm),this.tail=this.head,this.size=0}calculateSize(e){return e?.byteLength!=null?e.byteLength:1}push(e){if(e?.value!=null&&(this.size+=this.calculateSize(e.value)),!this.head.push(e)){let t=this.head;this.head=t.next=new La(2*this.head.buffer.length),this.head.push(e)}}shift(){let e=this.tail.shift();if(e===void 0&&this.tail.next!=null){let t=this.tail.next;this.tail.next=null,this.tail=t,e=this.tail.shift()}return e?.value!=null&&(this.size-=this.calculateSize(e.value)),e}isEmpty(){return this.head.isEmpty()}};var fd=class extends Error{type;code;constructor(e,t){super(e??"The operation was aborted"),this.type="aborted",this.code=t??"ABORT_ERR"}};function zt(r={}){return qb(t=>{let n=t.shift();if(n==null)return{done:!0};if(n.error!=null)throw n.error;return{done:n.done===!0,value:n.value}},r)}function qb(r,e){e=e??{};let t=e.onEnd,n=new Zi,i,o,s,a=_e(),c=async()=>{try{return n.isEmpty()?s?{done:!0}:await new Promise((y,g)=>{o=E=>{o=null,n.push(E);try{y(r(n))}catch(x){g(x)}return i}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=_e()})}},u=y=>o!=null?o(y):(n.push(y),i),l=y=>(n=new Zi,o!=null?o({error:y}):(n.push({error:y}),i)),d=y=>{if(s)return i;if(e?.objectMode!==!0&&y?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return u({done:!1,value:y})},p=y=>s?i:(s=!0,y!=null?l(y):u({done:!0})),f=()=>(n=new Zi,p(),{done:!0}),h=y=>(p(y),{done:!0});if(i={[Symbol.asyncIterator](){return this},next:c,return:f,throw:h,push:d,end:p,get readableLength(){return n.size},onEmpty:async y=>{let g=y?.signal;if(g?.throwIfAborted(),n.isEmpty())return;let E,x;g!=null&&(E=new Promise((_,S)=>{x=()=>{S(new fd)},g.addEventListener("abort",x)}));try{await Promise.race([a.promise,E])}finally{x!=null&&g!=null&&g?.removeEventListener("abort",x)}}},t==null)return i;let m=i;return i={[Symbol.asyncIterator](){return this},next(){return m.next()},throw(y){return m.throw(y),t!=null&&(t(y),t=void 0),{done:!0}},return(){return m.return(),t!=null&&(t(),t=void 0),{done:!0}},push:d,end(y){return m.end(y),t!=null&&(t(y),t=void 0),i},get readableLength(){return m.readableLength},onEmpty:y=>m.onEmpty(y)},i}function Yb(r){return r[Symbol.asyncIterator]!=null}function Wb(...r){let e=[];for(let t of r)Yb(t)||e.push(t);return e.length===r.length?function*(){for(let t of e)yield*t}():async function*(){let t=zt({objectMode:!0});Promise.resolve().then(async()=>{try{await Promise.all(r.map(async n=>{for await(let i of n)t.push(i)})),t.end()}catch(n){t.end(n)}}),yield*t}()}var Hr=Wb;function gt(r,...e){if(r==null)throw new Error("Empty pipeline");if(hd(r)){let n=r;r=()=>n.source}else if(wp(r)||gp(r)){let n=r;r=()=>n}let t=[r,...e];if(t.length>1&&hd(t[t.length-1])&&(t[t.length-1]=t[t.length-1].sink),t.length>2)for(let n=1;n<t.length-1;n++)hd(t[n])&&(t[n]=Xb(t[n]));return jb(...t)}var jb=(...r)=>{let e;for(;r.length>0;)e=r.shift()(e);return e},gp=r=>r?.[Symbol.asyncIterator]!=null,wp=r=>r?.[Symbol.iterator]!=null,hd=r=>r==null?!1:r.sink!=null&&r.source!=null,Xb=r=>e=>{let t=r.sink(e);if(t?.then!=null){let n=zt({objectMode:!0});t.then(()=>{n.end()},s=>{n.end(s)});let i,o=r.source;if(gp(o))i=async function*(){yield*o,n.end()};else if(wp(o))i=function*(){yield*o,n.end()};else throw new Error("Unknown duplex source type - must be Iterable or AsyncIterable");return Hr(n,i())}return r.source};function Zb(r){return r[Symbol.asyncIterator]!=null}function Jb(r,e){return Zb(r)?async function*(){let t=0;if(!(e<1)){for await(let n of r)if(yield n,t++,t===e)return}}():function*(){let t=0;if(!(e<1)){for(let n of r)if(yield n,t++,t===e)return}}()}var Ua=Jb;var V=class extends Event{constructor(e,t){super(e),this.detail=t}};function J(r,e="utf8"){let t=Ta[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return(e==="utf8"||e==="utf-8")&&globalThis.Buffer!=null&&globalThis.Buffer.from!=null?globalThis.Buffer.from(r.buffer,r.byteOffset,r.byteLength).toString("utf8"):t.encoder.encode(r).substring(1)}var Da=class{url;#e=0;#t=0;#r=0;#s=0;constructor(e){this.url=e instanceof URL?e:new URL(e)}async getRawBlock(e,t){let n=this.url;if(n.pathname=`/ipfs/${e.toString()}`,n.search="?format=raw",t?.aborted===!0)throw new Error(`Signal to fetch raw block for CID ${e} from gateway ${this.url} was aborted prior to fetch`);try{this.#e++;let i=await fetch(n.toString(),{signal:t,headers:{Accept:"application/vnd.ipld.raw"},cache:"force-cache"});if(!i.ok)throw this.#t++,new Error(`unable to fetch raw block for CID ${e} from gateway ${this.url}`);return this.#s++,new Uint8Array(await i.arrayBuffer())}catch{throw t?.aborted===!0?new Error(`fetching raw block for CID ${e} from gateway ${this.url} was aborted`):(this.#t++,new Error(`unable to fetch raw block for CID ${e}`))}}reliability(){return this.#e===0?1:this.#r>0?-1/0:this.#s/(this.#e+this.#t*3)}incrementInvalidBlocks(){this.#r++}};var Oa=class{gateways;log;constructor(e,t={}){this.log=e.logger.forComponent("helia:trustless-gateway-block-broker"),this.gateways=(t.gateways??Ep).map(n=>new Da(n))}async retrieve(e,t={}){let n=this.gateways.sort((o,s)=>s.reliability()-o.reliability()),i=[];for(let o of n){this.log("getting block for %c from %s",e,o.url);try{let s=await o.getRawBlock(e,t.signal);this.log.trace("got block for %c from %s",e,o.url);try{await t.validateFn?.(s)}catch(a){throw this.log.error("failed to validate block for %c from %s",e,o.url,a),o.incrementInvalidBlocks(),new Error(`unable to validate block for CID ${e} from gateway ${o.url}`)}return s}catch(s){if(this.log.error("failed to get block for %c from %s",e,o.url,s),s instanceof Error?i.push(s):i.push(new Error(`unable to fetch raw block for CID ${e} from gateway ${o.url}`)),t.signal?.aborted===!0){this.log.trace("request aborted while fetching raw block for CID %c from gateway %s",e,o.url);break}}}throw new AggregateError(i,`unable to fetch raw block for CID ${e} from any gateway`)}};var Ep=["https://trustless-gateway.link","https://cloudflare-ipfs.com","https://4everland.io"];function is(r={}){return e=>new Oa(e,r)}var Qb=Symbol.for("nodejs.util.inspect.custom"),xp=Object.values(Tn).map(r=>r.decoder).reduce((r,e)=>r.or(e),Tn.identity.decoder),bp=114,pd=36,md=37,os=class{type;multihash;privateKey;publicKey;string;constructor(e){this.type=e.type,this.multihash=e.multihash,this.privateKey=e.privateKey,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[Tu]=!0;toString(){return this.string==null&&(this.string=Ne.encode(this.multihash.bytes).slice(1)),this.string}toCID(){return F.createV1(bp,this.multihash)}toBytes(){return this.multihash.bytes}toJSON(){return this.toString()}equals(e){if(e==null)return!1;if(e instanceof Uint8Array)return he(this.multihash.bytes,e);if(typeof e=="string")return Jt(e).equals(this);if(e?.multihash?.bytes!=null)return he(this.multihash.bytes,e.multihash.bytes);throw new Error("not valid Id")}[Qb](){return`PeerId(${this.toString()})`}},Ji=class extends os{type="RSA";publicKey;constructor(e){super({...e,type:"RSA"}),this.publicKey=e.publicKey}},Qi=class extends os{type="Ed25519";publicKey;constructor(e){super({...e,type:"Ed25519"}),this.publicKey=e.multihash.digest}},eo=class extends os{type="secp256k1";publicKey;constructor(e){super({...e,type:"secp256k1"}),this.publicKey=e.multihash.digest}};function Jt(r,e){if(e=e??xp,r.charAt(0)==="1"||r.charAt(0)==="Q"){let t=st(Ne.decode(`z${r}`));return r.startsWith("12D")?new Qi({multihash:t}):r.startsWith("16U")?new eo({multihash:t}):new Ji({multihash:t})}return ss(xp.decode(r))}function ss(r){try{let e=st(r);if(e.code===et.code){if(e.digest.length===pd)return new Qi({multihash:e});if(e.digest.length===md)return new eo({multihash:e})}if(e.code===fe.code)return new Ji({multihash:e})}catch{return e3(F.decode(r))}throw new Error("Supplied PeerID CID is invalid")}function e3(r){if(r==null||r.multihash==null||r.version==null||r.version===1&&r.code!==bp)throw new Error("Supplied PeerID CID is invalid");let e=r.multihash;if(e.code===fe.code)return new Ji({multihash:r.multihash});if(e.code===et.code){if(e.digest.length===pd)return new Qi({multihash:r.multihash});if(e.digest.length===md)return new eo({multihash:r.multihash})}throw new Error("Supplied PeerID CID is invalid")}async function vp(r,e){return r.length===pd?new Qi({multihash:mr(et.code,r),privateKey:e}):r.length===md?new eo({multihash:mr(et.code,r),privateKey:e}):new Ji({multihash:await fe.digest(r),publicKey:r,privateKey:e})}var Pa=class{index=0;input="";new(e){return this.index=0,this.input=e,this}readAtomically(e){let t=this.index,n=e();return n===void 0&&(this.index=t),n}parseWith(e){let t=e();if(this.index===this.input.length)return t}peekChar(){if(!(this.index>=this.input.length))return this.input[this.index]}readChar(){if(!(this.index>=this.input.length))return this.input[this.index++]}readGivenChar(e){return this.readAtomically(()=>{let t=this.readChar();if(t===e)return t})}readSeparator(e,t,n){return this.readAtomically(()=>{if(!(t>0&&this.readGivenChar(e)===void 0))return n()})}readNumber(e,t,n,i){return this.readAtomically(()=>{let o=0,s=0,a=this.peekChar();if(a===void 0)return;let c=a==="0",u=2**(8*i)-1;for(;;){let l=this.readAtomically(()=>{let d=this.readChar();if(d===void 0)return;let p=Number.parseInt(d,e);if(!Number.isNaN(p))return p});if(l===void 0)break;if(o*=e,o+=l,o>u||(s+=1,t!==void 0&&s>t))return}if(s!==0)return!n&&c&&s>1?void 0:o})}readIPv4Addr(){return this.readAtomically(()=>{let e=new Uint8Array(4);for(let t=0;t<e.length;t++){let n=this.readSeparator(".",t,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;e[t]=n}return e})}readIPv6Addr(){let e=t=>{for(let n=0;n<t.length/2;n++){let i=n*2;if(n<t.length-3){let s=this.readSeparator(":",n,()=>this.readIPv4Addr());if(s!==void 0)return t[i]=s[0],t[i+1]=s[1],t[i+2]=s[2],t[i+3]=s[3],[i+4,!0]}let o=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(o===void 0)return[i,!1];t[i]=o>>8,t[i+1]=o&255}return[t.length,!1]};return this.readAtomically(()=>{let t=new Uint8Array(16),[n,i]=e(t);if(n===16)return t;if(i||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let o=new Uint8Array(14),s=16-(n+2),[a]=e(o.subarray(0,s));return t.set(o.subarray(0,a),16-a),t})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var Ap=45,t3=15,to=new Pa;function yd(r){if(!(r.length>t3))return to.new(r).parseWith(()=>to.readIPv4Addr())}function gd(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>Ap))return to.new(r).parseWith(()=>to.readIPv6Addr())}function Fa(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>Ap))return to.new(r).parseWith(()=>to.readIPAddr())}var F5=parseInt("0xFFFF",16),V5=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function Ip(r){return!!yd(r)}function Bp(r){return!!gd(r)}function Va(r){return!!Fa(r)}var kp=Ip,s3=Bp,wd=function(r){let e=0;if(r=r.toString().trim(),kp(r)){let t=new Uint8Array(e+4);return r.split(/\./g).forEach(n=>{t[e++]=parseInt(n,10)&255}),t}if(s3(r)){let t=r.split(":",8),n;for(n=0;n<t.length;n++){let o=kp(t[n]),s;o&&(s=wd(t[n]),t[n]=J(s.slice(0,2),"base16")),s!=null&&++n<8&&t.splice(n,0,J(s.slice(2,4),"base16"))}if(t[0]==="")for(;t.length<8;)t.unshift("0");else if(t[t.length-1]==="")for(;t.length<8;)t.push("0");else if(t.length<8){for(n=0;n<t.length&&t[n]!=="";n++);let o=[n,1];for(n=9-t.length;n>0;n--)o.push("0");t.splice.apply(t,o)}let i=new Uint8Array(e+16);for(n=0;n<t.length;n++){let o=parseInt(t[n],16);i[e++]=o>>8&255,i[e++]=o&255}return i}throw new Error("invalid ip address")},Rp=function(r,e=0,t){e=~~e,t=t??r.length-e;let n=new DataView(r.buffer);if(t===4){let i=[];for(let o=0;o<t;o++)i.push(r[e+o]);return i.join(".")}if(t===16){let i=[];for(let o=0;o<t;o+=2)i.push(n.getUint16(e+o).toString(16));return i.join(":").replace(/(^|:)0(:0)*:0(:|$)/,"$1::$3").replace(/:{3,4}/,"::")}return""};var ro={},Ed={},c3=[[4,32,"ip4"],[6,16,"tcp"],[33,16,"dccp"],[41,128,"ip6"],[42,-1,"ip6zone"],[43,8,"ipcidr"],[53,-1,"dns",!0],[54,-1,"dns4",!0],[55,-1,"dns6",!0],[56,-1,"dnsaddr",!0],[132,16,"sctp"],[273,16,"udp"],[275,0,"p2p-webrtc-star"],[276,0,"p2p-webrtc-direct"],[277,0,"p2p-stardust"],[280,0,"webrtc-direct"],[281,0,"webrtc"],[290,0,"p2p-circuit"],[301,0,"udt"],[302,0,"utp"],[400,-1,"unix",!1,!0],[421,-1,"ipfs"],[421,-1,"p2p"],[443,0,"https"],[444,96,"onion"],[445,296,"onion3"],[446,-1,"garlic64"],[448,0,"tls"],[449,-1,"sni"],[460,0,"quic"],[461,0,"quic-v1"],[465,0,"webtransport"],[466,-1,"certhash"],[477,0,"ws"],[478,0,"wss"],[479,0,"p2p-websocket-star"],[480,0,"http"],[777,-1,"memory"]];c3.forEach(r=>{let e=l3(...r);Ed[e.code]=e,ro[e.name]=e});function l3(r,e,t,n,i){return{code:r,size:e,name:t,resolvable:!!n,path:!!i}}function ge(r){if(typeof r=="number"){if(Ed[r]!=null)return Ed[r];throw new Error(`no protocol with code: ${r}`)}else if(typeof r=="string"){if(ro[r]!=null)return ro[r];throw new Error(`no protocol with name: ${r}`)}throw new Error(`invalid protocol id type: ${typeof r}`)}var vk=ge("ip4"),Ak=ge("ip6"),_k=ge("ipcidr");function bd(r,e){switch(ge(r).code){case 4:case 41:return d3(e);case 42:return Cp(e);case 6:case 273:case 33:case 132:return Up(e).toString();case 53:case 54:case 55:case 56:case 400:case 449:case 777:return Cp(e);case 421:return m3(e);case 444:return Lp(e);case 445:return Lp(e);case 466:return p3(e);default:return J(e,"base16")}}function vd(r,e){switch(ge(r).code){case 4:return Tp(e);case 41:return Tp(e);case 42:return Np(e);case 6:case 273:case 33:case 132:return Ad(parseInt(e,10));case 53:case 54:case 55:case 56:case 400:case 449:case 777:return Np(e);case 421:return f3(e);case 444:return y3(e);case 445:return g3(e);case 466:return h3(e);default:return H(e,"base16")}}var xd=Object.values(Tn).map(r=>r.decoder),u3=function(){let r=xd[0].or(xd[1]);return xd.slice(2).forEach(e=>r=r.or(e)),r}();function Tp(r){if(!Va(r))throw new Error("invalid ip address");return wd(r)}function d3(r){let e=Rp(r,0,r.length);if(e==null)throw new Error("ipBuff is required");if(!Va(e))throw new Error("invalid ip address");return e}function Ad(r){let e=new ArrayBuffer(2);return new DataView(e).setUint16(0,r),new Uint8Array(e)}function Up(r){return new DataView(r.buffer).getUint16(r.byteOffset)}function Np(r){let e=H(r),t=Uint8Array.from(ji(e.length));return we([t,e],t.length+e.length)}function Cp(r){let e=di(r);if(r=r.slice(yt(e)),r.length!==e)throw new Error("inconsistent lengths");return J(r)}function f3(r){let e;r[0]==="Q"||r[0]==="1"?e=st(Ne.decode(`z${r}`)).bytes:e=F.parse(r).multihash.bytes;let t=Uint8Array.from(ji(e.length));return we([t,e],t.length+e.length)}function h3(r){let e=u3.decode(r),t=Uint8Array.from(ji(e.length));return we([t,e],t.length+e.length)}function p3(r){let e=di(r),t=r.slice(yt(e));if(t.length!==e)throw new Error("inconsistent lengths");return"u"+J(t,"base64url")}function m3(r){let e=di(r),t=r.slice(yt(e));if(t.length!==e)throw new Error("inconsistent lengths");return J(t,"base58btc")}function y3(r){let e=r.split(":");if(e.length!==2)throw new Error(`failed to parse onion addr: ["'${e.join('", "')}'"]' does not contain a port number`);if(e[0].length!==16)throw new Error(`failed to parse onion addr: ${e[0]} not a Tor onion address.`);let t=qe.decode("b"+e[0]),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let i=Ad(n);return we([t,i],t.length+i.length)}function g3(r){let e=r.split(":");if(e.length!==2)throw new Error(`failed to parse onion addr: ["'${e.join('", "')}'"]' does not contain a port number`);if(e[0].length!==56)throw new Error(`failed to parse onion addr: ${e[0]} not a Tor onion3 address.`);let t=qe.decode(`b${e[0]}`),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let i=Ad(n);return we([t,i],t.length+i.length)}function Lp(r){let e=r.slice(0,r.length-2),t=r.slice(r.length-2),n=J(e,"base32"),i=Up(t);return`${n}:${i}`}function Dp(r){r=_d(r);let e=[],t=[],n=null,i=r.split("/").slice(1);if(i.length===1&&i[0]==="")return{bytes:new Uint8Array,string:"/",tuples:[],stringTuples:[],path:null};for(let o=0;o<i.length;o++){let s=i[o],a=ge(s);if(a.size===0){e.push([a.code]),t.push([a.code]);continue}if(o++,o>=i.length)throw Pp("invalid address: "+r);if(a.path===!0){n=_d(i.slice(o).join("/")),e.push([a.code,vd(a.code,n)]),t.push([a.code,n]);break}let c=vd(a.code,i[o]);e.push([a.code,c]),t.push([a.code,bd(a.code,c)])}return{string:Op(t),bytes:Id(e),tuples:e,stringTuples:t,path:n}}function Sd(r){let e=[],t=[],n=null,i=0;for(;i<r.length;){let o=di(r,i),s=yt(o),a=ge(o),c=w3(a,r.slice(i+s));if(c===0){e.push([o]),t.push([o]),i+=s;continue}let u=r.slice(i+s,i+s+c);if(i+=c+s,i>r.length)throw Pp("Invalid address Uint8Array: "+J(r,"base16"));e.push([o,u]);let l=bd(o,u);if(t.push([o,l]),a.path===!0){n=l;break}}return{bytes:Uint8Array.from(r),string:Op(t),tuples:e,stringTuples:t,path:n}}function Op(r){let e=[];return r.map(t=>{let n=ge(t[0]);return e.push(n.name),t.length>1&&t[1]!=null&&e.push(t[1]),null}),_d(e.join("/"))}function Id(r){return we(r.map(e=>{let t=ge(e[0]),n=Uint8Array.from(ji(t.code));return e.length>1&&e[1]!=null&&(n=we([n,e[1]])),n}))}function w3(r,e){if(r.size>0)return r.size/8;if(r.size===0)return 0;{let t=di(e instanceof Uint8Array?e:Uint8Array.from(e));return t+yt(t)}}function _d(r){return"/"+r.trim().split("/").filter(e=>e).join("/")}function Pp(r){return new Error("Error parsing address: "+r)}var E3=Symbol.for("nodejs.util.inspect.custom"),Bd=Symbol.for("@multiformats/js-multiaddr/multiaddr"),x3=[ge("dns").code,ge("dns4").code,ge("dns6").code,ge("dnsaddr").code],Ma=class r{bytes;#e;#t;#r;#s;[Bd]=!0;constructor(e){e==null&&(e="");let t;if(e instanceof Uint8Array)t=Sd(e);else if(typeof e=="string"){if(e.length>0&&e.charAt(0)!=="/")throw new Error(`multiaddr "${e}" must start with a "/"`);t=Dp(e)}else if(Vp(e))t=Sd(e.bytes);else throw new Error("addr must be a string, Buffer, or another Multiaddr");this.bytes=t.bytes,this.#e=t.string,this.#t=t.tuples,this.#r=t.stringTuples,this.#s=t.path}toString(){return this.#e}toJSON(){return this.toString()}toOptions(){let e,t,n,i,o="",s=ge("tcp"),a=ge("udp"),c=ge("ip4"),u=ge("ip6"),l=ge("dns6"),d=ge("ip6zone");for(let[f,h]of this.stringTuples())f===d.code&&(o=`%${h??""}`),x3.includes(f)&&(t=s.name,i=443,n=`${h??""}${o}`,e=f===l.code?6:4),(f===s.code||f===a.code)&&(t=ge(f).name,i=parseInt(h??"")),(f===c.code||f===u.code)&&(t=ge(f).name,n=`${h??""}${o}`,e=f===u.code?6:4);if(e==null||t==null||n==null||i==null)throw new Error('multiaddr must have a valid format: "/{ip4, ip6, dns4, dns6, dnsaddr}/{address}/{tcp, udp}/{port}".');return{family:e,host:n,transport:t,port:i}}protos(){return this.#t.map(([e])=>Object.assign({},ge(e)))}protoCodes(){return this.#t.map(([e])=>e)}protoNames(){return this.#t.map(([e])=>ge(e).name)}tuples(){return this.#t}stringTuples(){return this.#r}encapsulate(e){return e=new r(e),new r(this.toString()+e.toString())}decapsulate(e){let t=e.toString(),n=this.toString(),i=n.lastIndexOf(t);if(i<0)throw new Error(`Address ${this.toString()} does not contain subaddress: ${e.toString()}`);return new r(n.slice(0,i))}decapsulateCode(e){let t=this.tuples();for(let n=t.length-1;n>=0;n--)if(t[n][0]===e)return new r(Id(t.slice(0,n)));return this}getPeerId(){try{let e=[];this.stringTuples().forEach(([n,i])=>{n===ro.p2p.code&&e.push([n,i]),n===ro["p2p-circuit"].code&&(e=[])});let t=e.pop();if(t?.[1]!=null){let n=t[1];return n[0]==="Q"||n[0]==="1"?J(Ne.decode(`z${n}`),"base58btc"):J(F.parse(n).multihash.bytes,"base58btc")}return null}catch{return null}}getPath(){return this.#s}equals(e){return he(this.bytes,e.bytes)}async resolve(e){let t=this.protos().find(o=>o.resolvable);if(t==null)return[this];let n=Fp.get(t.name);if(n==null)throw new O(`no available resolver for ${t.name}`,"ERR_NO_AVAILABLE_RESOLVER");return(await n(this,e)).map(o=>new r(o))}nodeAddress(){let e=this.toOptions();if(e.transport!=="tcp"&&e.transport!=="udp")throw new Error(`multiaddr must have a valid format - no protocol with name: "${e.transport}". Must have a valid transport protocol: "{tcp, udp}"`);return{family:e.family,address:e.host,port:e.port}}isThinWaistAddress(e){let t=(e??this).protos();return!(t.length!==2||t[0].code!==4&&t[0].code!==41||t[1].code!==6&&t[1].code!==273)}[E3](){return`Multiaddr(${this.#e})`}};var Fp=new Map;function Vp(r){return!!r?.[Bd]}function kd(r){return new Ma(r)}async function*Ha(r,e={}){let t=r.getReader();try{for(;;){let n=await t.read();if(n.done)return;yield n.value}}finally{e.preventCancel!==!0&&await t.cancel(),t.releaseLock()}}var qd={};Be(qd,{Ed25519PrivateKey:()=>wi,Ed25519PublicKey:()=>ls,generateKeyPair:()=>N6,generateKeyPairFromSeed:()=>d1,unmarshalEd25519PrivateKey:()=>R6,unmarshalEd25519PublicKey:()=>T6});function Kt(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}function no(r){if(!Number.isSafeInteger(r)||r<0)throw new Error(`Wrong positive integer: ${r}`)}function b3(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}function Rd(r,...e){if(!b3(r))throw new Error("Expected Uint8Array");if(e.length>0&&!e.includes(r.length))throw new Error(`Expected Uint8Array of length ${e}, not of length=${r.length}`)}function $a(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");no(r.outputLen),no(r.blockLen)}function io(r,e=!0){if(r.destroyed)throw new Error("Hash instance has been destroyed");if(e&&r.finished)throw new Error("Hash#digest() has already been called")}function Mp(r,e){Rd(r);let t=e.outputLen;if(r.length<t)throw new Error(`digestInto() expects output buffer of length at least ${t}`)}var za=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function Hp(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}var so=r=>new DataView(r.buffer,r.byteOffset,r.byteLength),Qt=(r,e)=>r<<32-e|r>>>e,v3=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;if(!v3)throw new Error("Non little-endian hardware is not supported");var A3=async()=>{};async function $p(r,e,t){let n=Date.now();for(let i=0;i<r;i++){t(i);let o=Date.now()-n;o>=0&&o<e||(await A3(),n+=o)}}function Td(r){if(typeof r!="string")throw new Error(`utf8ToBytes expected string, got ${typeof r}`);return new Uint8Array(new TextEncoder().encode(r))}function Nn(r){if(typeof r=="string"&&(r=Td(r)),!Hp(r))throw new Error(`expected Uint8Array, got ${typeof r}`);return r}function Ka(...r){let e=0;for(let n=0;n<r.length;n++){let i=r[n];if(!Hp(i))throw new Error("Uint8Array expected");e+=i.length}let t=new Uint8Array(e);for(let n=0,i=0;n<r.length;n++){let o=r[n];t.set(o,i),i+=o.length}return t}var oo=class{clone(){return this._cloneInto()}},_3={}.toString;function zp(r,e){if(e!==void 0&&_3.call(e)!=="[object Object]")throw new Error("Options should be object or undefined");return Object.assign(r,e)}function Ga(r){let e=n=>r().update(Nn(n)).digest(),t=r();return e.outputLen=t.outputLen,e.blockLen=t.blockLen,e.create=()=>r(),e}function ao(r=32){if(za&&typeof za.getRandomValues=="function")return za.getRandomValues(new Uint8Array(r));throw new Error("crypto.getRandomValues must be defined")}function S3(r,e,t,n){if(typeof r.setBigUint64=="function")return r.setBigUint64(e,t,n);let i=BigInt(32),o=BigInt(4294967295),s=Number(t>>i&o),a=Number(t&o),c=n?4:0,u=n?0:4;r.setUint32(e+c,s,n),r.setUint32(e+u,a,n)}var co=class extends oo{constructor(e,t,n,i){super(),this.blockLen=e,this.outputLen=t,this.padOffset=n,this.isLE=i,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(e),this.view=so(this.buffer)}update(e){io(this);let{view:t,buffer:n,blockLen:i}=this;e=Nn(e);let o=e.length;for(let s=0;s<o;){let a=Math.min(i-this.pos,o-s);if(a===i){let c=so(e);for(;i<=o-s;s+=i)this.process(c,s);continue}n.set(e.subarray(s,s+a),this.pos),this.pos+=a,s+=a,this.pos===i&&(this.process(t,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){io(this),Mp(e,this),this.finished=!0;let{buffer:t,view:n,blockLen:i,isLE:o}=this,{pos:s}=this;t[s++]=128,this.buffer.subarray(s).fill(0),this.padOffset>i-s&&(this.process(n,0),s=0);for(let d=s;d<i;d++)t[d]=0;S3(n,i-8,BigInt(this.length*8),o),this.process(n,0);let a=so(e),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let u=c/4,l=this.get();if(u>l.length)throw new Error("_sha2: outputLen bigger than state");for(let d=0;d<u;d++)a.setUint32(4*d,l[d],o)}digest(){let{buffer:e,outputLen:t}=this;this.digestInto(e);let n=e.slice(0,t);return this.destroy(),n}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());let{blockLen:t,buffer:n,length:i,finished:o,destroyed:s,pos:a}=this;return e.length=i,e.pos=a,e.finished=o,e.destroyed=s,i%t&&e.buffer.set(n),e}};var qa=BigInt(4294967295),Nd=BigInt(32);function Kp(r,e=!1){return e?{h:Number(r&qa),l:Number(r>>Nd&qa)}:{h:Number(r>>Nd&qa)|0,l:Number(r&qa)|0}}function I3(r,e=!1){let t=new Uint32Array(r.length),n=new Uint32Array(r.length);for(let i=0;i<r.length;i++){let{h:o,l:s}=Kp(r[i],e);[t[i],n[i]]=[o,s]}return[t,n]}var B3=(r,e)=>BigInt(r>>>0)<<Nd|BigInt(e>>>0),k3=(r,e,t)=>r>>>t,R3=(r,e,t)=>r<<32-t|e>>>t,T3=(r,e,t)=>r>>>t|e<<32-t,N3=(r,e,t)=>r<<32-t|e>>>t,C3=(r,e,t)=>r<<64-t|e>>>t-32,L3=(r,e,t)=>r>>>t-32|e<<64-t,U3=(r,e)=>e,D3=(r,e)=>r,O3=(r,e,t)=>r<<t|e>>>32-t,P3=(r,e,t)=>e<<t|r>>>32-t,F3=(r,e,t)=>e<<t-32|r>>>64-t,V3=(r,e,t)=>r<<t-32|e>>>64-t;function M3(r,e,t,n){let i=(e>>>0)+(n>>>0);return{h:r+t+(i/2**32|0)|0,l:i|0}}var H3=(r,e,t)=>(r>>>0)+(e>>>0)+(t>>>0),$3=(r,e,t,n)=>e+t+n+(r/2**32|0)|0,z3=(r,e,t,n)=>(r>>>0)+(e>>>0)+(t>>>0)+(n>>>0),K3=(r,e,t,n,i)=>e+t+n+i+(r/2**32|0)|0,G3=(r,e,t,n,i)=>(r>>>0)+(e>>>0)+(t>>>0)+(n>>>0)+(i>>>0),q3=(r,e,t,n,i,o)=>e+t+n+i+o+(r/2**32|0)|0;var Y3={fromBig:Kp,split:I3,toBig:B3,shrSH:k3,shrSL:R3,rotrSH:T3,rotrSL:N3,rotrBH:C3,rotrBL:L3,rotr32H:U3,rotr32L:D3,rotlSH:O3,rotlSL:P3,rotlBH:F3,rotlBL:V3,add:M3,add3L:H3,add3H:$3,add4L:z3,add4H:K3,add5H:q3,add5L:G3},ee=Y3;var[W3,j3]=ee.split(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(r=>BigInt(r))),Cn=new Uint32Array(80),Ln=new Uint32Array(80),Cd=class extends co{constructor(){super(128,64,16,!1),this.Ah=1779033703,this.Al=-205731576,this.Bh=-1150833019,this.Bl=-2067093701,this.Ch=1013904242,this.Cl=-23791573,this.Dh=-1521486534,this.Dl=1595750129,this.Eh=1359893119,this.El=-1377402159,this.Fh=-1694144372,this.Fl=725511199,this.Gh=528734635,this.Gl=-79577749,this.Hh=1541459225,this.Hl=327033209}get(){let{Ah:e,Al:t,Bh:n,Bl:i,Ch:o,Cl:s,Dh:a,Dl:c,Eh:u,El:l,Fh:d,Fl:p,Gh:f,Gl:h,Hh:m,Hl:y}=this;return[e,t,n,i,o,s,a,c,u,l,d,p,f,h,m,y]}set(e,t,n,i,o,s,a,c,u,l,d,p,f,h,m,y){this.Ah=e|0,this.Al=t|0,this.Bh=n|0,this.Bl=i|0,this.Ch=o|0,this.Cl=s|0,this.Dh=a|0,this.Dl=c|0,this.Eh=u|0,this.El=l|0,this.Fh=d|0,this.Fl=p|0,this.Gh=f|0,this.Gl=h|0,this.Hh=m|0,this.Hl=y|0}process(e,t){for(let x=0;x<16;x++,t+=4)Cn[x]=e.getUint32(t),Ln[x]=e.getUint32(t+=4);for(let x=16;x<80;x++){let _=Cn[x-15]|0,S=Ln[x-15]|0,A=ee.rotrSH(_,S,1)^ee.rotrSH(_,S,8)^ee.shrSH(_,S,7),v=ee.rotrSL(_,S,1)^ee.rotrSL(_,S,8)^ee.shrSL(_,S,7),b=Cn[x-2]|0,T=Ln[x-2]|0,C=ee.rotrSH(b,T,19)^ee.rotrBH(b,T,61)^ee.shrSH(b,T,6),N=ee.rotrSL(b,T,19)^ee.rotrBL(b,T,61)^ee.shrSL(b,T,6),$=ee.add4L(v,N,Ln[x-7],Ln[x-16]),D=ee.add4H($,A,C,Cn[x-7],Cn[x-16]);Cn[x]=D|0,Ln[x]=$|0}let{Ah:n,Al:i,Bh:o,Bl:s,Ch:a,Cl:c,Dh:u,Dl:l,Eh:d,El:p,Fh:f,Fl:h,Gh:m,Gl:y,Hh:g,Hl:E}=this;for(let x=0;x<80;x++){let _=ee.rotrSH(d,p,14)^ee.rotrSH(d,p,18)^ee.rotrBH(d,p,41),S=ee.rotrSL(d,p,14)^ee.rotrSL(d,p,18)^ee.rotrBL(d,p,41),A=d&f^~d&m,v=p&h^~p&y,b=ee.add5L(E,S,v,j3[x],Ln[x]),T=ee.add5H(b,g,_,A,W3[x],Cn[x]),C=b|0,N=ee.rotrSH(n,i,28)^ee.rotrBH(n,i,34)^ee.rotrBH(n,i,39),$=ee.rotrSL(n,i,28)^ee.rotrBL(n,i,34)^ee.rotrBL(n,i,39),D=n&o^n&a^o&a,ne=i&s^i&c^s&c;g=m|0,E=y|0,m=f|0,y=h|0,f=d|0,h=p|0,{h:d,l:p}=ee.add(u|0,l|0,T|0,C|0),u=a|0,l=c|0,a=o|0,c=s|0,o=n|0,s=i|0;let B=ee.add3L(C,$,ne);n=ee.add3H(B,T,N,D),i=B|0}({h:n,l:i}=ee.add(this.Ah|0,this.Al|0,n|0,i|0)),{h:o,l:s}=ee.add(this.Bh|0,this.Bl|0,o|0,s|0),{h:a,l:c}=ee.add(this.Ch|0,this.Cl|0,a|0,c|0),{h:u,l}=ee.add(this.Dh|0,this.Dl|0,u|0,l|0),{h:d,l:p}=ee.add(this.Eh|0,this.El|0,d|0,p|0),{h:f,l:h}=ee.add(this.Fh|0,this.Fl|0,f|0,h|0),{h:m,l:y}=ee.add(this.Gh|0,this.Gl|0,m|0,y|0),{h:g,l:E}=ee.add(this.Hh|0,this.Hl|0,g|0,E|0),this.set(n,i,o,s,a,c,u,l,d,p,f,h,m,y,g,E)}roundClean(){Cn.fill(0),Ln.fill(0)}destroy(){this.buffer.fill(0),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var lo=Ga(()=>new Cd);var Wa={};Be(Wa,{bitGet:()=>r6,bitLen:()=>t6,bitMask:()=>as,bitSet:()=>n6,bytesToHex:()=>zr,bytesToNumberBE:()=>Kr,bytesToNumberLE:()=>Un,concatBytes:()=>Gr,createHmacDrbg:()=>Dd,ensureBytes:()=>Re,equalBytes:()=>Q3,hexToBytes:()=>mi,hexToNumber:()=>Ud,isBytes:()=>er,numberToBytesBE:()=>Dn,numberToBytesLE:()=>yi,numberToHexUnpadded:()=>Wp,numberToVarBytesBE:()=>J3,utf8ToBytes:()=>e6,validateObject:()=>wr});var Yp=BigInt(0),Ya=BigInt(1),X3=BigInt(2);function er(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}var Z3=Array.from({length:256},(r,e)=>e.toString(16).padStart(2,"0"));function zr(r){if(!er(r))throw new Error("Uint8Array expected");let e="";for(let t=0;t<r.length;t++)e+=Z3[r[t]];return e}function Wp(r){let e=r.toString(16);return e.length&1?`0${e}`:e}function Ud(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return BigInt(r===""?"0":`0x${r}`)}var $r={_0:48,_9:57,_A:65,_F:70,_a:97,_f:102};function Gp(r){if(r>=$r._0&&r<=$r._9)return r-$r._0;if(r>=$r._A&&r<=$r._F)return r-($r._A-10);if(r>=$r._a&&r<=$r._f)return r-($r._a-10)}function mi(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);let e=r.length,t=e/2;if(e%2)throw new Error("padded hex string expected, got unpadded hex of length "+e);let n=new Uint8Array(t);for(let i=0,o=0;i<t;i++,o+=2){let s=Gp(r.charCodeAt(o)),a=Gp(r.charCodeAt(o+1));if(s===void 0||a===void 0){let c=r[o]+r[o+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+o)}n[i]=s*16+a}return n}function Kr(r){return Ud(zr(r))}function Un(r){if(!er(r))throw new Error("Uint8Array expected");return Ud(zr(Uint8Array.from(r).reverse()))}function Dn(r,e){return mi(r.toString(16).padStart(e*2,"0"))}function yi(r,e){return Dn(r,e).reverse()}function J3(r){return mi(Wp(r))}function Re(r,e,t){let n;if(typeof e=="string")try{n=mi(e)}catch(o){throw new Error(`${r} must be valid hex string, got "${e}". Cause: ${o}`)}else if(er(e))n=Uint8Array.from(e);else throw new Error(`${r} must be hex string or Uint8Array`);let i=n.length;if(typeof t=="number"&&i!==t)throw new Error(`${r} expected ${t} bytes, got ${i}`);return n}function Gr(...r){let e=0;for(let i=0;i<r.length;i++){let o=r[i];if(!er(o))throw new Error("Uint8Array expected");e+=o.length}let t=new Uint8Array(e),n=0;for(let i=0;i<r.length;i++){let o=r[i];t.set(o,n),n+=o.length}return t}function Q3(r,e){if(r.length!==e.length)return!1;let t=0;for(let n=0;n<r.length;n++)t|=r[n]^e[n];return t===0}function e6(r){if(typeof r!="string")throw new Error(`utf8ToBytes expected string, got ${typeof r}`);return new Uint8Array(new TextEncoder().encode(r))}function t6(r){let e;for(e=0;r>Yp;r>>=Ya,e+=1);return e}function r6(r,e){return r>>BigInt(e)&Ya}var n6=(r,e,t)=>r|(t?Ya:Yp)<<BigInt(e),as=r=>(X3<<BigInt(r-1))-Ya,Ld=r=>new Uint8Array(r),qp=r=>Uint8Array.from(r);function Dd(r,e,t){if(typeof r!="number"||r<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 t!="function")throw new Error("hmacFn must be a function");let n=Ld(r),i=Ld(r),o=0,s=()=>{n.fill(1),i.fill(0),o=0},a=(...d)=>t(i,n,...d),c=(d=Ld())=>{i=a(qp([0]),d),n=a(),d.length!==0&&(i=a(qp([1]),d),n=a())},u=()=>{if(o++>=1e3)throw new Error("drbg: tried 1000 values");let d=0,p=[];for(;d<e;){n=a();let f=n.slice();p.push(f),d+=n.length}return Gr(...p)};return(d,p)=>{s(),c(d);let f;for(;!(f=p(u()));)c();return s(),f}}var i6={bigint:r=>typeof r=="bigint",function:r=>typeof r=="function",boolean:r=>typeof r=="boolean",string:r=>typeof r=="string",stringOrUint8Array:r=>typeof r=="string"||er(r),isSafeInteger:r=>Number.isSafeInteger(r),array:r=>Array.isArray(r),field:(r,e)=>e.Fp.isValid(r),hash:r=>typeof r=="function"&&Number.isSafeInteger(r.outputLen)};function wr(r,e,t={}){let n=(i,o,s)=>{let a=i6[o];if(typeof a!="function")throw new Error(`Invalid validator "${o}", expected function`);let c=r[i];if(!(s&&c===void 0)&&!a(c,r))throw new Error(`Invalid param ${String(i)}=${c} (${typeof c}), expected ${o}`)};for(let[i,o]of Object.entries(e))n(i,o,!1);for(let[i,o]of Object.entries(t))n(i,o,!0);return r}var Pe=BigInt(0),Ee=BigInt(1),gi=BigInt(2),o6=BigInt(3),Od=BigInt(4),jp=BigInt(5),Xp=BigInt(8),s6=BigInt(9),a6=BigInt(16);function ye(r,e){let t=r%e;return t>=Pe?t:e+t}function c6(r,e,t){if(t<=Pe||e<Pe)throw new Error("Expected power/modulo > 0");if(t===Ee)return Pe;let n=Ee;for(;e>Pe;)e&Ee&&(n=n*r%t),r=r*r%t,e>>=Ee;return n}function xe(r,e,t){let n=r;for(;e-- >Pe;)n*=n,n%=t;return n}function ja(r,e){if(r===Pe||e<=Pe)throw new Error(`invert: expected positive integers, got n=${r} mod=${e}`);let t=ye(r,e),n=e,i=Pe,o=Ee,s=Ee,a=Pe;for(;t!==Pe;){let u=n/t,l=n%t,d=i-s*u,p=o-a*u;n=t,t=l,i=s,o=a,s=d,a=p}if(n!==Ee)throw new Error("invert: does not exist");return ye(i,e)}function l6(r){let e=(r-Ee)/gi,t,n,i;for(t=r-Ee,n=0;t%gi===Pe;t/=gi,n++);for(i=gi;i<r&&c6(i,e,r)!==r-Ee;i++);if(n===1){let s=(r+Ee)/Od;return function(c,u){let l=c.pow(u,s);if(!c.eql(c.sqr(l),u))throw new Error("Cannot find square root");return l}}let o=(t+Ee)/gi;return function(a,c){if(a.pow(c,e)===a.neg(a.ONE))throw new Error("Cannot find square root");let u=n,l=a.pow(a.mul(a.ONE,i),t),d=a.pow(c,o),p=a.pow(c,t);for(;!a.eql(p,a.ONE);){if(a.eql(p,a.ZERO))return a.ZERO;let f=1;for(let m=a.sqr(p);f<u&&!a.eql(m,a.ONE);f++)m=a.sqr(m);let h=a.pow(l,Ee<<BigInt(u-f-1));l=a.sqr(h),d=a.mul(d,h),p=a.mul(p,l),u=f}return d}}function u6(r){if(r%Od===o6){let e=(r+Ee)/Od;return function(n,i){let o=n.pow(i,e);if(!n.eql(n.sqr(o),i))throw new Error("Cannot find square root");return o}}if(r%Xp===jp){let e=(r-jp)/Xp;return function(n,i){let o=n.mul(i,gi),s=n.pow(o,e),a=n.mul(i,s),c=n.mul(n.mul(a,gi),s),u=n.mul(a,n.sub(c,n.ONE));if(!n.eql(n.sqr(u),i))throw new Error("Cannot find square root");return u}}return r%a6,l6(r)}var Zp=(r,e)=>(ye(r,e)&Ee)===Ee,d6=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Pd(r){let e={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},t=d6.reduce((n,i)=>(n[i]="function",n),e);return wr(r,t)}function f6(r,e,t){if(t<Pe)throw new Error("Expected power > 0");if(t===Pe)return r.ONE;if(t===Ee)return e;let n=r.ONE,i=e;for(;t>Pe;)t&Ee&&(n=r.mul(n,i)),i=r.sqr(i),t>>=Ee;return n}function h6(r,e){let t=new Array(e.length),n=e.reduce((o,s,a)=>r.is0(s)?o:(t[a]=o,r.mul(o,s)),r.ONE),i=r.inv(n);return e.reduceRight((o,s,a)=>r.is0(s)?o:(t[a]=r.mul(o,t[a]),r.mul(o,s)),i),t}function Fd(r,e){let t=e!==void 0?e:r.toString(2).length,n=Math.ceil(t/8);return{nBitLength:t,nByteLength:n}}function Xa(r,e,t=!1,n={}){if(r<=Pe)throw new Error(`Expected Field ORDER > 0, got ${r}`);let{nBitLength:i,nByteLength:o}=Fd(r,e);if(o>2048)throw new Error("Field lengths over 2048 bytes are not supported");let s=u6(r),a=Object.freeze({ORDER:r,BITS:i,BYTES:o,MASK:as(i),ZERO:Pe,ONE:Ee,create:c=>ye(c,r),isValid:c=>{if(typeof c!="bigint")throw new Error(`Invalid field element: expected bigint, got ${typeof c}`);return Pe<=c&&c<r},is0:c=>c===Pe,isOdd:c=>(c&Ee)===Ee,neg:c=>ye(-c,r),eql:(c,u)=>c===u,sqr:c=>ye(c*c,r),add:(c,u)=>ye(c+u,r),sub:(c,u)=>ye(c-u,r),mul:(c,u)=>ye(c*u,r),pow:(c,u)=>f6(a,c,u),div:(c,u)=>ye(c*ja(u,r),r),sqrN:c=>c*c,addN:(c,u)=>c+u,subN:(c,u)=>c-u,mulN:(c,u)=>c*u,inv:c=>ja(c,r),sqrt:n.sqrt||(c=>s(a,c)),invertBatch:c=>h6(a,c),cmov:(c,u,l)=>l?u:c,toBytes:c=>t?yi(c,o):Dn(c,o),fromBytes:c=>{if(c.length!==o)throw new Error(`Fp.fromBytes: expected ${o}, got ${c.length}`);return t?Un(c):Kr(c)}});return Object.freeze(a)}function Jp(r,e){if(!r.isOdd)throw new Error("Field doesn't have isOdd");let t=r.sqrt(e);return r.isOdd(t)?r.neg(t):t}function Qp(r){if(typeof r!="bigint")throw new Error("field order must be bigint");let e=r.toString(2).length;return Math.ceil(e/8)}function Vd(r){let e=Qp(r);return e+Math.ceil(e/2)}function e1(r,e,t=!1){let n=r.length,i=Qp(e),o=Vd(e);if(n<16||n<o||n>1024)throw new Error(`expected ${o}-1024 bytes of input, got ${n}`);let s=t?Kr(r):Un(r),a=ye(s,e-Ee)+Ee;return t?yi(a,i):Dn(a,i)}var m6=BigInt(0),Md=BigInt(1);function Za(r,e){let t=(i,o)=>{let s=o.negate();return i?s:o},n=i=>{let o=Math.ceil(e/i)+1,s=2**(i-1);return{windows:o,windowSize:s}};return{constTimeNegate:t,unsafeLadder(i,o){let s=r.ZERO,a=i;for(;o>m6;)o&Md&&(s=s.add(a)),a=a.double(),o>>=Md;return s},precomputeWindow(i,o){let{windows:s,windowSize:a}=n(o),c=[],u=i,l=u;for(let d=0;d<s;d++){l=u,c.push(l);for(let p=1;p<a;p++)l=l.add(u),c.push(l);u=l.double()}return c},wNAF(i,o,s){let{windows:a,windowSize:c}=n(i),u=r.ZERO,l=r.BASE,d=BigInt(2**i-1),p=2**i,f=BigInt(i);for(let h=0;h<a;h++){let m=h*c,y=Number(s&d);s>>=f,y>c&&(y-=p,s+=Md);let g=m,E=m+Math.abs(y)-1,x=h%2!==0,_=y<0;y===0?l=l.add(t(x,o[g])):u=u.add(t(_,o[E]))}return{p:u,f:l}},wNAFCached(i,o,s,a){let c=i._WINDOW_SIZE||1,u=o.get(i);return u||(u=this.precomputeWindow(i,c),c!==1&&o.set(i,a(u))),this.wNAF(c,u,s)}}}function cs(r){return Pd(r.Fp),wr(r,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...Fd(r.n,r.nBitLength),...r,p:r.Fp.ORDER})}var tr=BigInt(0),Bt=BigInt(1),Ja=BigInt(2),y6=BigInt(8),g6={zip215:!0};function w6(r){let e=cs(r);return wr(r,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...e})}function Qa(r){let e=w6(r),{Fp:t,n,prehash:i,hash:o,randomBytes:s,nByteLength:a,h:c}=e,u=Ja<<BigInt(a*8)-Bt,l=t.create,d=e.uvRatio||((L,k)=>{try{return{isValid:!0,value:t.sqrt(L*t.inv(k))}}catch{return{isValid:!1,value:tr}}}),p=e.adjustScalarBytes||(L=>L),f=e.domain||((L,k,K)=>{if(k.length||K)throw new Error("Contexts/pre-hash are not supported");return L}),h=L=>typeof L=="bigint"&&tr<L,m=(L,k)=>h(L)&&h(k)&&L<k,y=L=>L===tr||m(L,u);function g(L,k){if(m(L,k))return L;throw new Error(`Expected valid scalar < ${k}, got ${typeof L} ${L}`)}function E(L){return L===tr?L:g(L,n)}let x=new Map;function _(L){if(!(L instanceof S))throw new Error("ExtendedPoint expected")}class S{constructor(k,K,W,Z){if(this.ex=k,this.ey=K,this.ez=W,this.et=Z,!y(k))throw new Error("x required");if(!y(K))throw new Error("y required");if(!y(W))throw new Error("z required");if(!y(Z))throw new Error("t required")}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(k){if(k instanceof S)throw new Error("extended point not allowed");let{x:K,y:W}=k||{};if(!y(K)||!y(W))throw new Error("invalid affine point");return new S(K,W,Bt,l(K*W))}static normalizeZ(k){let K=t.invertBatch(k.map(W=>W.ez));return k.map((W,Z)=>W.toAffine(K[Z])).map(S.fromAffine)}_setWindowSize(k){this._WINDOW_SIZE=k,x.delete(this)}assertValidity(){let{a:k,d:K}=e;if(this.is0())throw new Error("bad point: ZERO");let{ex:W,ey:Z,ez:re,et:ie}=this,me=l(W*W),ae=l(Z*Z),ue=l(re*re),Le=l(ue*ue),Ie=l(me*k),Ke=l(ue*l(Ie+ae)),Ge=l(Le+l(K*l(me*ae)));if(Ke!==Ge)throw new Error("bad point: equation left != right (1)");let Oe=l(W*Z),Ze=l(re*ie);if(Oe!==Ze)throw new Error("bad point: equation left != right (2)")}equals(k){_(k);let{ex:K,ey:W,ez:Z}=this,{ex:re,ey:ie,ez:me}=k,ae=l(K*me),ue=l(re*Z),Le=l(W*me),Ie=l(ie*Z);return ae===ue&&Le===Ie}is0(){return this.equals(S.ZERO)}negate(){return new S(l(-this.ex),this.ey,this.ez,l(-this.et))}double(){let{a:k}=e,{ex:K,ey:W,ez:Z}=this,re=l(K*K),ie=l(W*W),me=l(Ja*l(Z*Z)),ae=l(k*re),ue=K+W,Le=l(l(ue*ue)-re-ie),Ie=ae+ie,Ke=Ie-me,Ge=ae-ie,Oe=l(Le*Ke),Ze=l(Ie*Ge),Vr=l(Le*Ge),ai=l(Ke*Ie);return new S(Oe,Ze,ai,Vr)}add(k){_(k);let{a:K,d:W}=e,{ex:Z,ey:re,ez:ie,et:me}=this,{ex:ae,ey:ue,ez:Le,et:Ie}=k;if(K===BigInt(-1)){let p0=l((re-Z)*(ue+ae)),m0=l((re+Z)*(ue-ae)),gu=l(m0-p0);if(gu===tr)return this.double();let y0=l(ie*Ja*Ie),g0=l(me*Ja*Le),w0=g0+y0,E0=m0+p0,x0=g0-y0,OE=l(w0*gu),PE=l(E0*x0),FE=l(w0*x0),VE=l(gu*E0);return new S(OE,PE,VE,FE)}let Ke=l(Z*ae),Ge=l(re*ue),Oe=l(me*W*Ie),Ze=l(ie*Le),Vr=l((Z+re)*(ae+ue)-Ke-Ge),ai=Ze-Oe,Xo=Ze+Oe,h0=l(Ge-K*Ke),CE=l(Vr*ai),LE=l(Xo*h0),UE=l(Vr*h0),DE=l(ai*Xo);return new S(CE,LE,DE,UE)}subtract(k){return this.add(k.negate())}wNAF(k){return b.wNAFCached(this,x,k,S.normalizeZ)}multiply(k){let{p:K,f:W}=this.wNAF(g(k,n));return S.normalizeZ([K,W])[0]}multiplyUnsafe(k){let K=E(k);return K===tr?v:this.equals(v)||K===Bt?this:this.equals(A)?this.wNAF(K).p:b.unsafeLadder(this,K)}isSmallOrder(){return this.multiplyUnsafe(c).is0()}isTorsionFree(){return b.unsafeLadder(this,n).is0()}toAffine(k){let{ex:K,ey:W,ez:Z}=this,re=this.is0();k==null&&(k=re?y6:t.inv(Z));let ie=l(K*k),me=l(W*k),ae=l(Z*k);if(re)return{x:tr,y:Bt};if(ae!==Bt)throw new Error("invZ was invalid");return{x:ie,y:me}}clearCofactor(){let{h:k}=e;return k===Bt?this:this.multiplyUnsafe(k)}static fromHex(k,K=!1){let{d:W,a:Z}=e,re=t.BYTES;k=Re("pointHex",k,re);let ie=k.slice(),me=k[re-1];ie[re-1]=me&-129;let ae=Un(ie);ae===tr||(K?g(ae,u):g(ae,t.ORDER));let ue=l(ae*ae),Le=l(ue-Bt),Ie=l(W*ue-Z),{isValid:Ke,value:Ge}=d(Le,Ie);if(!Ke)throw new Error("Point.fromHex: invalid y coordinate");let Oe=(Ge&Bt)===Bt,Ze=(me&128)!==0;if(!K&&Ge===tr&&Ze)throw new Error("Point.fromHex: x=0 and x_0=1");return Ze!==Oe&&(Ge=l(-Ge)),S.fromAffine({x:Ge,y:ae})}static fromPrivateKey(k){return N(k).point}toRawBytes(){let{x:k,y:K}=this.toAffine(),W=yi(K,t.BYTES);return W[W.length-1]|=k&Bt?128:0,W}toHex(){return zr(this.toRawBytes())}}S.BASE=new S(e.Gx,e.Gy,Bt,l(e.Gx*e.Gy)),S.ZERO=new S(tr,Bt,Bt,tr);let{BASE:A,ZERO:v}=S,b=Za(S,a*8);function T(L){return ye(L,n)}function C(L){return T(Un(L))}function N(L){let k=a;L=Re("private key",L,k);let K=Re("hashed private key",o(L),2*k),W=p(K.slice(0,k)),Z=K.slice(k,2*k),re=C(W),ie=A.multiply(re),me=ie.toRawBytes();return{head:W,prefix:Z,scalar:re,point:ie,pointBytes:me}}function $(L){return N(L).pointBytes}function D(L=new Uint8Array,...k){let K=Gr(...k);return C(o(f(K,Re("context",L),!!i)))}function ne(L,k,K={}){L=Re("message",L),i&&(L=i(L));let{prefix:W,scalar:Z,pointBytes:re}=N(k),ie=D(K.context,W,L),me=A.multiply(ie).toRawBytes(),ae=D(K.context,me,re,L),ue=T(ie+ae*Z);E(ue);let Le=Gr(me,yi(ue,t.BYTES));return Re("result",Le,a*2)}let B=g6;function U(L,k,K,W=B){let{context:Z,zip215:re}=W,ie=t.BYTES;L=Re("signature",L,2*ie),k=Re("message",k),i&&(k=i(k));let me=Un(L.slice(ie,2*ie)),ae,ue,Le;try{ae=S.fromHex(K,re),ue=S.fromHex(L.slice(0,ie),re),Le=A.multiplyUnsafe(me)}catch{return!1}if(!re&&ae.isSmallOrder())return!1;let Ie=D(Z,ue.toRawBytes(),ae.toRawBytes(),k);return ue.add(ae.multiplyUnsafe(Ie)).subtract(Le).clearCofactor().equals(S.ZERO)}return A._setWindowSize(8),{CURVE:e,getPublicKey:$,sign:ne,verify:U,ExtendedPoint:S,utils:{getExtendedPublicKey:N,randomPrivateKey:()=>s(t.BYTES),precompute(L=8,k=S.BASE){return k._setWindowSize(L),k.multiply(BigInt(3)),k}}}}var $d=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),t1=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),AR=BigInt(0),E6=BigInt(1),Hd=BigInt(2),x6=BigInt(5),r1=BigInt(10),b6=BigInt(20),v6=BigInt(40),n1=BigInt(80);function A6(r){let e=$d,n=r*r%e*r%e,i=xe(n,Hd,e)*n%e,o=xe(i,E6,e)*r%e,s=xe(o,x6,e)*o%e,a=xe(s,r1,e)*s%e,c=xe(a,b6,e)*a%e,u=xe(c,v6,e)*c%e,l=xe(u,n1,e)*u%e,d=xe(l,n1,e)*u%e,p=xe(d,r1,e)*s%e;return{pow_p_5_8:xe(p,Hd,e)*r%e,b2:n}}function _6(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}function S6(r,e){let t=$d,n=ye(e*e*e,t),i=ye(n*n*e,t),o=A6(r*i).pow_p_5_8,s=ye(r*n*o,t),a=ye(e*s*s,t),c=s,u=ye(s*t1,t),l=a===r,d=a===ye(-r,t),p=a===ye(-r*t1,t);return l&&(s=c),(d||p)&&(s=u),Zp(s,t)&&(s=ye(-s,t)),{isValid:l||d,value:s}}var qr=Xa($d,void 0,!0),zd={a:BigInt(-1),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:qr,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:BigInt(8),Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:lo,randomBytes:ao,adjustScalarBytes:_6,uvRatio:S6},uo=Qa(zd);function i1(r,e,t){if(e.length>255)throw new Error("Context is too big");return Ka(Td("SigEd25519 no Ed25519 collisions"),new Uint8Array([t?1:0,e.length]),e,r)}var _R=Qa({...zd,domain:i1}),SR=Qa({...zd,domain:i1,prehash:lo});var I6=(qr.ORDER+BigInt(3))/BigInt(8),IR=qr.pow(Hd,I6),BR=qr.sqrt(qr.neg(qr.ONE)),kR=(qr.ORDER-BigInt(5))/BigInt(8),RR=BigInt(486662);var TR=Jp(qr,qr.neg(BigInt(486664)));var NR=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),CR=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),LR=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),UR=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952");var DR=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");var fo=32,Yr=64,ec=32;function o1(){let r=uo.utils.randomPrivateKey(),e=uo.getPublicKey(r);return{privateKey:l1(r,e),publicKey:e}}function s1(r){if(r.length!==ec)throw new TypeError('"seed" must be 32 bytes in length.');if(!(r instanceof Uint8Array))throw new TypeError('"seed" must be a node.js Buffer, or Uint8Array.');let e=r,t=uo.getPublicKey(e);return{privateKey:l1(e,t),publicKey:t}}function a1(r,e){let t=r.subarray(0,ec);return uo.sign(e instanceof Uint8Array?e:e.subarray(),t)}function c1(r,e,t){return uo.verify(e,t instanceof Uint8Array?t:t.subarray(),r)}function l1(r,e){let t=new Uint8Array(Yr);for(let n=0;n<ec;n++)t[n]=r[n],t[ec+n]=e[n];return t}var ct={get(r=globalThis){let e=r.crypto;if(e==null||e.subtle==null)throw Object.assign(new Error("Missing Web Crypto API. The most likely cause of this error is that this page is being accessed from an insecure context (i.e. not HTTPS). For more information and possible resolutions see https://github.com/libp2p/js-libp2p/blob/main/packages/crypto/README.md#web-crypto-api"),{code:"ERR_MISSING_WEB_CRYPTO"});return e}};var Kd={alg:"A128GCM",ext:!0,k:"scm9jmO_4BJAgdwWGVulLg",key_ops:["encrypt","decrypt"],kty:"oct"};function u1(r){let e=r?.algorithm??"AES-GCM",t=r?.keyLength??16,n=r?.nonceLength??12,i=r?.digest??"SHA-256",o=r?.saltLength??16,s=r?.iterations??32767,a=ct.get();t*=8;async function c(d,p){let f=a.getRandomValues(new Uint8Array(o)),h=a.getRandomValues(new Uint8Array(n)),m={name:e,iv:h};typeof p=="string"&&(p=H(p));let y;if(p.length===0){y=await a.subtle.importKey("jwk",Kd,{name:"AES-GCM"},!0,["encrypt"]);try{let E={name:"PBKDF2",salt:f,iterations:s,hash:{name:i}},x=await a.subtle.importKey("raw",p,{name:"PBKDF2"},!1,["deriveKey"]);y=await a.subtle.deriveKey(E,x,{name:e,length:t},!0,["encrypt"])}catch{y=await a.subtle.importKey("jwk",Kd,{name:"AES-GCM"},!0,["encrypt"])}}else{let E={name:"PBKDF2",salt:f,iterations:s,hash:{name:i}},x=await a.subtle.importKey("raw",p,{name:"PBKDF2"},!1,["deriveKey"]);y=await a.subtle.deriveKey(E,x,{name:e,length:t},!0,["encrypt"])}let g=await a.subtle.encrypt(m,y,d);return we([f,m.iv,new Uint8Array(g)])}async function u(d,p){let f=d.subarray(0,o),h=d.subarray(o,o+n),m=d.subarray(o+n),y={name:e,iv:h};typeof p=="string"&&(p=H(p));let g;if(p.length===0)try{let x={name:"PBKDF2",salt:f,iterations:s,hash:{name:i}},_=await a.subtle.importKey("raw",p,{name:"PBKDF2"},!1,["deriveKey"]);g=await a.subtle.deriveKey(x,_,{name:e,length:t},!0,["decrypt"])}catch{g=await a.subtle.importKey("jwk",Kd,{name:"AES-GCM"},!0,["decrypt"])}else{let x={name:"PBKDF2",salt:f,iterations:s,hash:{name:i}},_=await a.subtle.importKey("raw",p,{name:"PBKDF2"},!1,["deriveKey"]);g=await a.subtle.deriveKey(x,_,{name:e,length:t},!0,["decrypt"])}let E=await a.subtle.decrypt(y,g,m);return new Uint8Array(E)}return{encrypt:c,decrypt:u}}async function ho(r,e){let n=await u1().encrypt(r,e);return yr.encode(n)}var be;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.Secp256k1="Secp256k1"})(be||(be={}));var Gd;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.Secp256k1=2]="Secp256k1"})(Gd||(Gd={}));(function(r){r.codec=()=>pi(Gd)})(be||(be={}));var Er;(function(r){let e;r.codec=()=>(e==null&&(e=Ht((t,n,i={})=>{i.lengthDelimited!==!1&&n.fork(),t.Type!=null&&(n.uint32(8),be.codec().encode(t.Type,n)),t.Data!=null&&(n.uint32(18),n.bytes(t.Data)),i.lengthDelimited!==!1&&n.ldelim()},(t,n)=>{let i={},o=n==null?t.len:t.pos+n;for(;t.pos<o;){let s=t.uint32();switch(s>>>3){case 1:i.Type=be.codec().decode(t);break;case 2:i.Data=t.bytes();break;default:t.skipType(s&7);break}}return i})),e),r.encode=t=>Mt(t,r.codec()),r.decode=t=>Ft(t,r.codec())})(Er||(Er={}));var xr;(function(r){let e;r.codec=()=>(e==null&&(e=Ht((t,n,i={})=>{i.lengthDelimited!==!1&&n.fork(),t.Type!=null&&(n.uint32(8),be.codec().encode(t.Type,n)),t.Data!=null&&(n.uint32(18),n.bytes(t.Data)),i.lengthDelimited!==!1&&n.ldelim()},(t,n)=>{let i={},o=n==null?t.len:t.pos+n;for(;t.pos<o;){let s=t.uint32();switch(s>>>3){case 1:i.Type=be.codec().decode(t);break;case 2:i.Data=t.bytes();break;default:t.skipType(s&7);break}}return i})),e),r.encode=t=>Mt(t,r.codec()),r.decode=t=>Ft(t,r.codec())})(xr||(xr={}));var ls=class{_key;constructor(e){this._key=po(e,fo)}verify(e,t){return c1(this._key,t,e)}marshal(){return this._key}get bytes(){return Er.encode({Type:be.Ed25519,Data:this.marshal()}).subarray()}equals(e){return he(this.bytes,e.bytes)}hash(){let e=fe.digest(this.bytes);return Kt(e)?e.then(({bytes:t})=>t):e.bytes}},wi=class{_key;_publicKey;constructor(e,t){this._key=po(e,Yr),this._publicKey=po(t,fo)}sign(e){return a1(this._key,e)}get public(){return new ls(this._publicKey)}marshal(){return this._key}get bytes(){return xr.encode({Type:be.Ed25519,Data:this.marshal()}).subarray()}equals(e){return he(this.bytes,e.bytes)}async hash(){let e=fe.digest(this.bytes),t;return Kt(e)?{bytes:t}=await e:t=e.bytes,t}async id(){let e=et.digest(this.public.bytes);return Ne.encode(e.bytes).substring(1)}async export(e,t="libp2p-key"){if(t==="libp2p-key")return ho(this.bytes,e);throw new O(`export format '${t}' is not supported`,"ERR_INVALID_EXPORT_FORMAT")}};function R6(r){if(r.length>Yr){r=po(r,Yr+fo);let n=r.subarray(0,Yr),i=r.subarray(Yr,r.length);return new wi(n,i)}r=po(r,Yr);let e=r.subarray(0,Yr),t=r.subarray(fo);return new wi(e,t)}function T6(r){return r=po(r,fo),new ls(r)}async function N6(){let{privateKey:r,publicKey:e}=o1();return new wi(r,e)}async function d1(r){let{privateKey:e,publicKey:t}=s1(r);return new wi(e,t)}function po(r,e){if(r=Uint8Array.from(r??[]),r.length!==e)throw new O(`Key must be a Uint8Array of length ${e}, got ${r.length}`,"ERR_INVALID_KEY_TYPE");return r}var rf={};Be(rf,{MAX_RSA_KEY_SIZE:()=>bs,RsaPrivateKey:()=>Eo,RsaPublicKey:()=>xs,fromJwk:()=>iv,generateKeyPair:()=>ov,unmarshalRsaPrivateKey:()=>ef,unmarshalRsaPublicKey:()=>nv});function Ei(r){if(isNaN(r)||r<=0)throw new O("random bytes length must be a Number bigger than 0","ERR_INVALID_LENGTH");return ao(r)}var Vn={};Be(Vn,{exportToPem:()=>J6,importFromPem:()=>Q6,jwkToPkcs1:()=>W6,jwkToPkix:()=>X6,pkcs1ToJwk:()=>Y6,pkixToJwk:()=>j6});var rc=class extends oo{constructor(e,t){super(),this.finished=!1,this.destroyed=!1,$a(e);let n=Nn(t);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 i=this.blockLen,o=new Uint8Array(i);o.set(n.length>i?e.create().update(n).digest():n);for(let s=0;s<o.length;s++)o[s]^=54;this.iHash.update(o),this.oHash=e.create();for(let s=0;s<o.length;s++)o[s]^=106;this.oHash.update(o),o.fill(0)}update(e){return io(this),this.iHash.update(e),this}digestInto(e){io(this),Rd(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:t,iHash:n,finished:i,destroyed:o,blockLen:s,outputLen:a}=this;return e=e,e.finished=i,e.destroyed=o,e.blockLen=s,e.outputLen=a,e.oHash=t._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},us=(r,e,t)=>new rc(r,e).update(t).digest();us.create=(r,e)=>new rc(r,e);function C6(r,e,t,n){$a(r);let i=zp({dkLen:32,asyncTick:10},n),{c:o,dkLen:s,asyncTick:a}=i;if(no(o),no(s),no(a),o<1)throw new Error("PBKDF2: iterations (c) should be >= 1");let c=Nn(e),u=Nn(t),l=new Uint8Array(s),d=us.create(r,c),p=d._cloneInto().update(u);return{c:o,dkLen:s,asyncTick:a,DK:l,PRF:d,PRFSalt:p}}function L6(r,e,t,n,i){return r.destroy(),e.destroy(),n&&n.destroy(),i.fill(0),t}async function Yd(r,e,t,n){let{c:i,dkLen:o,asyncTick:s,DK:a,PRF:c,PRFSalt:u}=C6(r,e,t,n),l,d=new Uint8Array(4),p=so(d),f=new Uint8Array(c.outputLen);for(let h=1,m=0;m<o;h++,m+=c.outputLen){let y=a.subarray(m,m+c.outputLen);p.setInt32(0,h,!1),(l=u._cloneInto(l)).update(d).digestInto(f),y.set(f.subarray(0,y.length)),await $p(i-1,s,()=>{c._cloneInto(l).update(f).digestInto(f);for(let g=0;g<y.length;g++)y[g]^=f[g]})}return L6(c,u,a,l,f)}var se=Q(f1());function xi(r,e){let t=0;if(r.length===1)return r[0];for(let n=r.length-1;n>=0;n--)t+=r[r.length-1-n]*Math.pow(2,e*n);return t}function On(r,e,t=-1){let n=t,i=r,o=0,s=Math.pow(2,e);for(let a=1;a<8;a++){if(r<s){let c;if(n<0)c=new ArrayBuffer(a),o=a;else{if(n<a)return new ArrayBuffer(0);c=new ArrayBuffer(n),o=n}let u=new Uint8Array(c);for(let l=a-1;l>=0;l--){let d=Math.pow(2,l*e);u[o-l-1]=Math.floor(i/d),i-=u[o-l-1]*d}return c}s*=Math.pow(2,e)}return new ArrayBuffer(0)}function oc(...r){let e=0,t=0;for(let o of r)e+=o.length;let n=new ArrayBuffer(e),i=new Uint8Array(n);for(let o of r)i.set(o,t),t+=o.length;return i}function jd(){let r=new Uint8Array(this.valueHex);if(this.valueHex.byteLength>=2){let a=r[0]===255&&r[1]&128,c=r[0]===0&&(r[1]&128)===0;(a||c)&&this.warnings.push("Needlessly long format")}let e=new ArrayBuffer(this.valueHex.byteLength),t=new Uint8Array(e);for(let a=0;a<this.valueHex.byteLength;a++)t[a]=0;t[0]=r[0]&128;let n=xi(t,8),i=new ArrayBuffer(this.valueHex.byteLength),o=new Uint8Array(i);for(let a=0;a<this.valueHex.byteLength;a++)o[a]=r[a];return o[0]&=127,xi(o,8)-n}function h1(r){let e=r<0?r*-1:r,t=128;for(let n=1;n<8;n++){if(e<=t){if(r<0){let s=t-e,a=On(s,8,n),c=new Uint8Array(a);return c[0]|=128,a}let i=On(e,8,n),o=new Uint8Array(i);if(o[0]&128){let s=i.slice(0),a=new Uint8Array(s);i=new ArrayBuffer(i.byteLength+1),o=new Uint8Array(i);for(let c=0;c<s.byteLength;c++)o[c+1]=a[c];o[0]=0}return i}t*=Math.pow(2,8)}return new ArrayBuffer(0)}function p1(r,e){if(r.byteLength!==e.byteLength)return!1;let t=new Uint8Array(r),n=new Uint8Array(e);for(let i=0;i<t.length;i++)if(t[i]!==n[i])return!1;return!0}function wt(r,e){let t=r.toString(10);if(e<t.length)return"";let n=e-t.length,i=new Array(n);for(let s=0;s<n;s++)i[s]="0";return i.join("").concat(t)}var lT=Math.log(2);function sc(){if(typeof BigInt>"u")throw new Error("BigInt is not defined. Your environment doesn't implement BigInt.")}function Xd(r){let e=0,t=0;for(let i=0;i<r.length;i++){let o=r[i];e+=o.byteLength}let n=new Uint8Array(e);for(let i=0;i<r.length;i++){let o=r[i];n.set(new Uint8Array(o),t),t+=o.byteLength}return n.buffer}function Jr(r,e,t,n){return e instanceof Uint8Array?e.byteLength?t<0?(r.error="Wrong parameter: inputOffset less than zero",!1):n<0?(r.error="Wrong parameter: inputLength less than zero",!1):e.byteLength-t-n<0?(r.error="End of input reached before message was fully decoded (inconsistent offset and length values)",!1):!0:(r.error="Wrong parameter: inputBuffer has zero length",!1):(r.error="Wrong parameter: inputBuffer must be 'Uint8Array'",!1)}var fs=class{constructor(){this.items=[]}write(e){this.items.push(e)}final(){return Xd(this.items)}},ds=[new Uint8Array([1])],m1="0123456789";var go="",nr=new ArrayBuffer(0),Zd=new Uint8Array(0),hs="EndOfContent",g1="OCTET STRING",w1="BIT STRING";function Qr(r){var e;return e=class extends r{constructor(...n){var i;super(...n);let o=n[0]||{};this.isHexOnly=(i=o.isHexOnly)!==null&&i!==void 0?i:!1,this.valueHexView=o.valueHex?se.BufferSourceConverter.toUint8Array(o.valueHex):Zd}get valueHex(){return this.valueHexView.slice().buffer}set valueHex(n){this.valueHexView=new Uint8Array(n)}fromBER(n,i,o){let s=n instanceof ArrayBuffer?new Uint8Array(n):n;if(!Jr(this,s,i,o))return-1;let a=i+o;return this.valueHexView=s.subarray(i,a),this.valueHexView.length?(this.blockLength=o,a):(this.warnings.push("Zero buffer length"),i)}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",nr)}toJSON(){return{...super.toJSON(),isHexOnly:this.isHexOnly,valueHex:se.Convert.ToHex(this.valueHexView)}}},e.NAME="hexBlock",e}var jr=class{constructor({blockLength:e=0,error:t=go,warnings:n=[],valueBeforeDecode:i=Zd}={}){this.blockLength=e,this.error=t,this.warnings=n,this.valueBeforeDecodeView=se.BufferSourceConverter.toUint8Array(i)}static blockName(){return this.NAME}get valueBeforeDecode(){return this.valueBeforeDecodeView.slice().buffer}set valueBeforeDecode(e){this.valueBeforeDecodeView=new Uint8Array(e)}toJSON(){return{blockName:this.constructor.NAME,blockLength:this.blockLength,error:this.error,warnings:this.warnings,valueBeforeDecode:se.Convert.ToHex(this.valueBeforeDecodeView)}}};jr.NAME="baseBlock";var tt=class extends jr{fromBER(e,t,n){throw TypeError("User need to make a specific function in a class which extends 'ValueBlock'")}toBER(e,t){throw TypeError("User need to make a specific function in a class which extends 'ValueBlock'")}};tt.NAME="valueBlock";var ac=class extends Qr(jr){constructor({idBlock:e={}}={}){var t,n,i,o;super(),e?(this.isHexOnly=(t=e.isHexOnly)!==null&&t!==void 0?t:!1,this.valueHexView=e.valueHex?se.BufferSourceConverter.toUint8Array(e.valueHex):Zd,this.tagClass=(n=e.tagClass)!==null&&n!==void 0?n:-1,this.tagNumber=(i=e.tagNumber)!==null&&i!==void 0?i:-1,this.isConstructed=(o=e.isConstructed)!==null&&o!==void 0?o:!1):(this.tagClass=-1,this.tagNumber=-1,this.isConstructed=!1)}toBER(e=!1){let t=0;switch(this.tagClass){case 1:t|=0;break;case 2:t|=64;break;case 3:t|=128;break;case 4:t|=192;break;default:return this.error="Unknown tag class",nr}if(this.isConstructed&&(t|=32),this.tagNumber<31&&!this.isHexOnly){let i=new Uint8Array(1);if(!e){let o=this.tagNumber;o&=31,t|=o,i[0]=t}return i.buffer}if(!this.isHexOnly){let i=On(this.tagNumber,7),o=new Uint8Array(i),s=i.byteLength,a=new Uint8Array(s+1);if(a[0]=t|31,!e){for(let c=0;c<s-1;c++)a[c+1]=o[c]|128;a[s]=o[s-1]}return a.buffer}let n=new Uint8Array(this.valueHexView.byteLength+1);if(n[0]=t|31,!e){let i=this.valueHexView;for(let o=0;o<i.length-1;o++)n[o+1]=i[o]|128;n[this.valueHexView.byteLength]=i[i.length-1]}return n.buffer}fromBER(e,t,n){let i=se.BufferSourceConverter.toUint8Array(e);if(!Jr(this,i,t,n))return-1;let o=i.subarray(t,t+n);if(o.length===0)return this.error="Zero buffer length",-1;switch(o[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=(o[0]&32)===32,this.isHexOnly=!1;let a=o[0]&31;if(a!==31)this.tagNumber=a,this.blockLength=1;else{let c=1,u=this.valueHexView=new Uint8Array(255),l=255;for(;o[c]&128;){if(u[c-1]=o[c]&127,c++,c>=o.length)return this.error="End of input reached before message was fully decoded",-1;if(c===l){l+=255;let p=new Uint8Array(l);for(let f=0;f<u.length;f++)p[f]=u[f];u=this.valueHexView=new Uint8Array(l)}}this.blockLength=c+1,u[c-1]=o[c]&127;let d=new Uint8Array(c);for(let p=0;p<c;p++)d[p]=u[p];u=this.valueHexView=new Uint8Array(c),u.set(d),this.blockLength<=9?this.tagNumber=xi(u,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 t+this.blockLength}toJSON(){return{...super.toJSON(),tagClass:this.tagClass,tagNumber:this.tagNumber,isConstructed:this.isConstructed}}};ac.NAME="identificationBlock";var cc=class extends jr{constructor({lenBlock:e={}}={}){var t,n,i;super(),this.isIndefiniteForm=(t=e.isIndefiniteForm)!==null&&t!==void 0?t:!1,this.longFormUsed=(n=e.longFormUsed)!==null&&n!==void 0?n:!1,this.length=(i=e.length)!==null&&i!==void 0?i:0}fromBER(e,t,n){let i=se.BufferSourceConverter.toUint8Array(e);if(!Jr(this,i,t,n))return-1;let o=i.subarray(t,t+n);if(o.length===0)return this.error="Zero buffer length",-1;if(o[0]===255)return this.error="Length block 0xFF is reserved by standard",-1;if(this.isIndefiniteForm=o[0]===128,this.isIndefiniteForm)return this.blockLength=1,t+this.blockLength;if(this.longFormUsed=!!(o[0]&128),this.longFormUsed===!1)return this.length=o[0],this.blockLength=1,t+this.blockLength;let s=o[0]&127;if(s>8)return this.error="Too big integer",-1;if(s+1>o.length)return this.error="End of input reached before message was fully decoded",-1;let a=t+1,c=i.subarray(a,a+s);return c[s-1]===0&&this.warnings.push("Needlessly long encoded length"),this.length=xi(c,8),this.longFormUsed&&this.length<=127&&this.warnings.push("Unnecessary usage of long length form"),this.blockLength=s+1,t+this.blockLength}toBER(e=!1){let t,n;if(this.length>127&&(this.longFormUsed=!0),this.isIndefiniteForm)return t=new ArrayBuffer(1),e===!1&&(n=new Uint8Array(t),n[0]=128),t;if(this.longFormUsed){let i=On(this.length,8);if(i.byteLength>127)return this.error="Too big length",nr;if(t=new ArrayBuffer(i.byteLength+1),e)return t;let o=new Uint8Array(i);n=new Uint8Array(t),n[0]=i.byteLength|128;for(let s=0;s<i.byteLength;s++)n[s+1]=o[s];return t}return t=new ArrayBuffer(1),e===!1&&(n=new Uint8Array(t),n[0]=this.length),t}toJSON(){return{...super.toJSON(),isIndefiniteForm:this.isIndefiniteForm,longFormUsed:this.longFormUsed,length:this.length}}};cc.NAME="lengthBlock";var z={},Ye=class extends jr{constructor({name:e=go,optional:t=!1,primitiveSchema:n,...i}={},o){super(i),this.name=e,this.optional=t,n&&(this.primitiveSchema=n),this.idBlock=new ac(i),this.lenBlock=new cc(i),this.valueBlock=o?new o(i):new tt(i)}fromBER(e,t,n){let i=this.valueBlock.fromBER(e,t,this.lenBlock.isIndefiniteForm?n:this.lenBlock.length);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,t){let n=t||new fs;t||E1(this);let i=this.idBlock.toBER(e);if(n.write(i),this.lenBlock.isIndefiniteForm)n.write(new Uint8Array([128]).buffer),this.valueBlock.toBER(e,n),n.write(new ArrayBuffer(2));else{let o=this.valueBlock.toBER(e);this.lenBlock.length=o.byteLength;let s=this.lenBlock.toBER(e);n.write(s),n.write(o)}return t?nr: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():se.Convert.ToHex(this.toBER())}onAsciiEncoding(){return`${this.constructor.NAME} : ${se.Convert.ToHex(this.valueBlock.valueBeforeDecodeView)}`}isEqual(e){if(this===e)return!0;if(!(e instanceof this.constructor))return!1;let t=this.toBER(),n=e.toBER();return p1(t,n)}};Ye.NAME="BaseBlock";function E1(r){if(r instanceof z.Constructed)for(let e of r.valueBlock.value)E1(e)&&(r.lenBlock.isIndefiniteForm=!0);return!!r.lenBlock.isIndefiniteForm}var lc=class extends Ye{constructor({value:e=go,...t}={},n){super(t,n),e&&this.fromString(e)}getValue(){return this.valueBlock.value}setValue(e){this.valueBlock.value=e}fromBER(e,t,n){let i=this.valueBlock.fromBER(e,t,this.lenBlock.isIndefiniteForm?n:this.lenBlock.length);return i===-1?(this.error=this.valueBlock.error,i):(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),i)}onAsciiEncoding(){return`${this.constructor.NAME} : '${this.valueBlock.value}'`}};lc.NAME="BaseStringBlock";var uc=class extends Qr(tt){constructor({isHexOnly:e=!0,...t}={}){super(t),this.isHexOnly=e}};uc.NAME="PrimitiveValueBlock";var x1,dc=class extends Ye{constructor(e={}){super(e,uc),this.idBlock.isConstructed=!1}};x1=dc;z.Primitive=x1;dc.NAME="PRIMITIVE";function $6(r,e){if(r instanceof e)return r;let t=new e;return t.idBlock=r.idBlock,t.lenBlock=r.lenBlock,t.warnings=r.warnings,t.valueBeforeDecodeView=r.valueBeforeDecodeView,t}function Kc(r,e=0,t=r.length){let n=e,i=new Ye({},tt),o=new jr;if(!Jr(o,r,e,t))return i.error=o.error,{offset:-1,result:i};if(!r.subarray(e,e+t).length)return i.error="Zero buffer length",{offset:-1,result:i};let a=i.idBlock.fromBER(r,e,t);if(i.idBlock.warnings.length&&i.warnings.concat(i.idBlock.warnings),a===-1)return i.error=i.idBlock.error,{offset:-1,result:i};if(e=a,t-=i.idBlock.blockLength,a=i.lenBlock.fromBER(r,e,t),i.lenBlock.warnings.length&&i.warnings.concat(i.lenBlock.warnings),a===-1)return i.error=i.lenBlock.error,{offset:-1,result:i};if(e=a,t-=i.lenBlock.blockLength,!i.idBlock.isConstructed&&i.lenBlock.isIndefiniteForm)return i.error="Indefinite length form used for primitive encoding form",{offset:-1,result:i};let c=Ye;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};c=z.EndOfContent;break;case 1:c=z.Boolean;break;case 2:c=z.Integer;break;case 3:c=z.BitString;break;case 4:c=z.OctetString;break;case 5:c=z.Null;break;case 6:c=z.ObjectIdentifier;break;case 10:c=z.Enumerated;break;case 12:c=z.Utf8String;break;case 13:c=z.RelativeObjectIdentifier;break;case 14:c=z.TIME;break;case 15:return i.error="[UNIVERSAL 15] is reserved by ASN.1 standard",{offset:-1,result:i};case 16:c=z.Sequence;break;case 17:c=z.Set;break;case 18:c=z.NumericString;break;case 19:c=z.PrintableString;break;case 20:c=z.TeletexString;break;case 21:c=z.VideotexString;break;case 22:c=z.IA5String;break;case 23:c=z.UTCTime;break;case 24:c=z.GeneralizedTime;break;case 25:c=z.GraphicString;break;case 26:c=z.VisibleString;break;case 27:c=z.GeneralString;break;case 28:c=z.UniversalString;break;case 29:c=z.CharacterString;break;case 30:c=z.BmpString;break;case 31:c=z.DATE;break;case 32:c=z.TimeOfDay;break;case 33:c=z.DateTime;break;case 34:c=z.Duration;break;default:{let u=i.idBlock.isConstructed?new z.Constructed:new z.Primitive;u.idBlock=i.idBlock,u.lenBlock=i.lenBlock,u.warnings=i.warnings,i=u}}break;case 2:case 3:case 4:default:c=i.idBlock.isConstructed?z.Constructed:z.Primitive}return i=$6(i,c),a=i.fromBER(r,e,i.lenBlock.isIndefiniteForm?t:i.lenBlock.length),i.valueBeforeDecodeView=r.subarray(n,n+i.blockLength),{offset:a,result:i}}function wo(r){if(!r.byteLength){let e=new Ye({},tt);return e.error="Input buffer has zero length",{offset:-1,result:e}}return Kc(se.BufferSourceConverter.toUint8Array(r).slice(),0,r.byteLength)}function z6(r,e){return r?1:e}var br=class extends tt{constructor({value:e=[],isIndefiniteForm:t=!1,...n}={}){super(n),this.value=e,this.isIndefiniteForm=t}fromBER(e,t,n){let i=se.BufferSourceConverter.toUint8Array(e);if(!Jr(this,i,t,n))return-1;if(this.valueBeforeDecodeView=i.subarray(t,t+n),this.valueBeforeDecodeView.length===0)return this.warnings.push("Zero buffer length"),t;let o=t;for(;z6(this.isIndefiniteForm,n)>0;){let s=Kc(i,o,n);if(s.offset===-1)return this.error=s.result.error,this.warnings.concat(s.result.warnings),-1;if(o=s.offset,this.blockLength+=s.result.blockLength,n-=s.result.blockLength,this.value.push(s.result),this.isIndefiniteForm&&s.result.constructor.NAME===hs)break}return this.isIndefiniteForm&&(this.value[this.value.length-1].constructor.NAME===hs?this.value.pop():this.warnings.push("No EndOfContent block encoded")),o}toBER(e,t){let n=t||new fs;for(let i=0;i<this.value.length;i++)this.value[i].toBER(e,n);return t?nr:n.final()}toJSON(){let e={...super.toJSON(),isIndefiniteForm:this.isIndefiniteForm,value:[]};for(let t of this.value)e.value.push(t.toJSON());return e}};br.NAME="ConstructedValueBlock";var b1,Pn=class extends Ye{constructor(e={}){super(e,br),this.idBlock.isConstructed=!0}fromBER(e,t,n){this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm;let i=this.valueBlock.fromBER(e,t,this.lenBlock.isIndefiniteForm?n:this.lenBlock.length);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(`
|
|
4
4
|
`).map(i=>` ${i}`).join(`
|
|
5
5
|
`));let t=this.idBlock.tagClass===3?`[${this.idBlock.tagNumber}]`:this.constructor.NAME;return e.length?`${t} :
|
|
6
6
|
${e.join(`
|
|
7
|
-
`)}`:`${t} :`}};v1=Pn;z.Constructed=v1;Pn.NAME="CONSTRUCTED";var fc=class extends tt{fromBER(e,t,n){return t}toBER(e){return nr}};fc.override="EndOfContentValueBlock";var A1,hc=class extends Ye{constructor(e={}){super(e,fc),this.idBlock.tagClass=1,this.idBlock.tagNumber=0}};A1=hc;z.EndOfContent=A1;hc.NAME=hs;var _1,Fn=class extends Ye{constructor(e={}){super(e,tt),this.idBlock.tagClass=1,this.idBlock.tagNumber=5}fromBER(e,t,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,t+n>e.byteLength?(this.error="End of input reached before message was fully decoded (inconsistent offset and length values)",-1):t+n}toBER(e,t){let n=new ArrayBuffer(2);if(!e){let i=new Uint8Array(n);i[0]=5,i[1]=0}return t&&t.write(n),n}onAsciiEncoding(){return`${this.constructor.NAME}`}};_1=Fn;z.Null=_1;Fn.NAME="NULL";var pc=class extends Qr(tt){constructor({value:e,...t}={}){super(t),t.valueHex?this.valueHexView=se.BufferSourceConverter.toUint8Array(t.valueHex):this.valueHexView=new Uint8Array(1),e&&(this.value=e)}get value(){for(let e of this.valueHexView)if(e>0)return!0;return!1}set value(e){this.valueHexView[0]=e?255:0}fromBER(e,t,n){let i=se.BufferSourceConverter.toUint8Array(e);return Jr(this,i,t,n)?(this.valueHexView=i.subarray(t,t+n),n>1&&this.warnings.push("Boolean value encoded in more then 1 octet"),this.isHexOnly=!0,Wd.call(this),this.blockLength=n,t+n):-1}toBER(){return this.valueHexView.slice()}toJSON(){return{...super.toJSON(),value:this.value}}};pc.NAME="BooleanValueBlock";var S1,mc=class extends Ye{constructor(e={}){super(e,pc),this.idBlock.tagClass=1,this.idBlock.tagNumber=1}getValue(){return this.valueBlock.value}setValue(e){this.valueBlock.value=e}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.getValue}`}};S1=mc;z.Boolean=S1;mc.NAME="BOOLEAN";var yc=class extends Qr(br){constructor({isConstructed:e=!1,...t}={}){super(t),this.isConstructed=e}fromBER(e,t,n){let i=0;if(this.isConstructed){if(this.isHexOnly=!1,i=br.prototype.fromBER.call(this,e,t,n),i===-1)return i;for(let o=0;o<this.value.length;o++){let s=this.value[o].constructor.NAME;if(s===hs){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, OCTET STRING may consists of OCTET STRINGs only",-1}if(s!==w1)return this.error="OCTET STRING may consists of OCTET STRINGs only",-1}}else this.isHexOnly=!0,i=super.fromBER(e,t,n),this.blockLength=n;return i}toBER(e,t){return this.isConstructed?br.prototype.toBER.call(this,e,t):e?new ArrayBuffer(this.valueHexView.byteLength):this.valueHexView.slice().buffer}toJSON(){return{...super.toJSON(),isConstructed:this.isConstructed}}};yc.NAME="OctetStringValueBlock";var I1,Xr=class r extends Ye{constructor({idBlock:e={},lenBlock:t={},...n}={}){var i,o;(i=n.isConstructed)!==null&&i!==void 0||(n.isConstructed=!!(!((o=n.value)===null||o===void 0)&&o.length)),super({idBlock:{isConstructed:n.isConstructed,...e},lenBlock:{...t,isIndefiniteForm:!!n.isIndefiniteForm},...n},yc),this.idBlock.tagClass=1,this.idBlock.tagNumber=4}fromBER(e,t,n){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),t;if(!this.valueBlock.isConstructed){let o=(e instanceof ArrayBuffer?new Uint8Array(e):e).subarray(t,t+n);try{if(o.byteLength){let s=Kc(o,0,o.byteLength);s.offset!==-1&&s.offset===n&&(this.valueBlock.value=[s.result])}}catch{}}return super.fromBER(e,t,n)}onAsciiEncoding(){return this.valueBlock.isConstructed||this.valueBlock.value&&this.valueBlock.value.length?Pn.prototype.onAsciiEncoding.call(this):`${this.constructor.NAME} : ${se.Convert.ToHex(this.valueBlock.valueHexView)}`}getValue(){if(!this.idBlock.isConstructed)return this.valueBlock.valueHexView.slice().buffer;let e=[];for(let t of this.valueBlock.value)t instanceof r&&e.push(t.valueBlock.valueHexView);return se.BufferSourceConverter.concat(e)}};I1=Xr;z.OctetString=I1;Xr.NAME=w1;var gc=class extends Qr(br){constructor({unusedBits:e=0,isConstructed:t=!1,...n}={}){super(n),this.unusedBits=e,this.isConstructed=t,this.blockLength=this.valueHexView.byteLength}fromBER(e,t,n){if(!n)return t;let i=-1;if(this.isConstructed){if(i=br.prototype.fromBER.call(this,e,t,n),i===-1)return i;for(let a of this.value){let c=a.constructor.NAME;if(c===hs){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, BIT STRING may consists of BIT STRINGs only",-1}if(c!==E1)return this.error="BIT STRING may consists of BIT STRINGs only",-1;let u=a.valueBlock;if(this.unusedBits>0&&u.unusedBits>0)return this.error='Using of "unused bits" inside constructive BIT STRING allowed for least one only',-1;this.unusedBits=u.unusedBits}return i}let o=se.BufferSourceConverter.toUint8Array(e);if(!Jr(this,o,t,n))return-1;let s=o.subarray(t,t+n);if(this.unusedBits=s[0],this.unusedBits>7)return this.error="Unused bits for BitString must be in range 0-7",-1;if(!this.unusedBits){let a=s.subarray(1);try{if(a.byteLength){let c=Kc(a,0,a.byteLength);c.offset!==-1&&c.offset===n-1&&(this.value=[c.result])}}catch{}}return this.valueHexView=s.subarray(1),this.blockLength=s.length,t+n}toBER(e,t){if(this.isConstructed)return br.prototype.toBER.call(this,e,t);if(e)return new ArrayBuffer(this.valueHexView.byteLength+1);if(!this.valueHexView.byteLength)return nr;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}}};gc.NAME="BitStringValueBlock";var B1,go=class extends Ye{constructor({idBlock:e={},lenBlock:t={},...n}={}){var i,o;(i=n.isConstructed)!==null&&i!==void 0||(n.isConstructed=!!(!((o=n.value)===null||o===void 0)&&o.length)),super({idBlock:{isConstructed:n.isConstructed,...e},lenBlock:{...t,isIndefiniteForm:!!n.isIndefiniteForm},...n},gc),this.idBlock.tagClass=1,this.idBlock.tagNumber=3}fromBER(e,t,n){return this.valueBlock.isConstructed=this.idBlock.isConstructed,this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm,super.fromBER(e,t,n)}onAsciiEncoding(){if(this.valueBlock.isConstructed||this.valueBlock.value&&this.valueBlock.value.length)return Pn.prototype.onAsciiEncoding.call(this);{let e=[],t=this.valueBlock.valueHexView;for(let i of t)e.push(i.toString(2).padStart(8,"0"));let n=e.join("");return`${this.constructor.NAME} : ${n.substring(0,n.length-this.valueBlock.unusedBits)}`}}};B1=go;z.BitString=B1;go.NAME=E1;var k1;function q6(r,e){let t=new Uint8Array([0]),n=new Uint8Array(r),i=new Uint8Array(e),o=n.slice(0),s=o.length-1,a=i.slice(0),c=a.length-1,u=0,l=c<s?s:c,d=0;for(let p=l;p>=0;p--,d++){switch(!0){case d<a.length:u=o[s-d]+a[c-d]+t[0];break;default:u=o[s-d]+t[0]}switch(t[0]=u/10,!0){case d>=o.length:o=oc(new Uint8Array([u%10]),o);break;default:o[s-d]=u%10}}return t[0]>0&&(o=oc(t,o)),o}function g1(r){if(r>=ds.length)for(let e=ds.length;e<=r;e++){let t=new Uint8Array([0]),n=ds[e-1].slice(0);for(let i=n.length-1;i>=0;i--){let o=new Uint8Array([(n[i]<<1)+t[0]]);t[0]=o[0]/10,n[i]=o[0]%10}t[0]>0&&(n=oc(t,n)),ds.push(n)}return ds[r]}function Y6(r,e){let t=0,n=new Uint8Array(r),i=new Uint8Array(e),o=n.slice(0),s=o.length-1,a=i.slice(0),c=a.length-1,u,l=0;for(let d=c;d>=0;d--,l++)switch(u=o[s-l]-a[c-l]-t,!0){case u<0:t=1,o[s-l]=u+10;break;default:t=0,o[s-l]=u}if(t>0)for(let d=s-c+1;d>=0;d--,l++)if(u=o[s-l]-t,u<0)t=1,o[s-l]=u+10;else{t=0,o[s-l]=u;break}return o.slice()}var ps=class extends Qr(tt){constructor({value:e,...t}={}){super(t),this._valueDec=0,t.valueHex&&this.setValueHex(),e!==void 0&&(this.valueDec=e)}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=Wd.call(this)))}set valueDec(e){this._valueDec=e,this.isHexOnly=!1,this.valueHexView=new Uint8Array(p1(e))}get valueDec(){return this._valueDec}fromDER(e,t,n,i=0){let o=this.fromBER(e,t,n);if(o===-1)return o;let s=this.valueHexView;return s[0]===0&&s[1]&128?this.valueHexView=s.subarray(1):i!==0&&s.length<i&&(i-s.length>1&&(i=s.length+1),this.valueHexView=s.subarray(i-s.length)),o}toDER(e=!1){let t=this.valueHexView;switch(!0){case(t[0]&128)!==0:{let n=new Uint8Array(this.valueHexView.length+1);n[0]=0,n.set(t,1),this.valueHexView=n}break;case(t[0]===0&&(t[1]&128)===0):this.valueHexView=this.valueHexView.subarray(1);break}return this.toBER(e)}fromBER(e,t,n){let i=super.fromBER(e,t,n);return i===-1||this.setValueHex(),i}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,t=new Uint8Array(this.valueHexView.length*8/3),n=0,i,o=this.valueHexView,s="",a=!1;for(let c=o.byteLength-1;c>=0;c--){i=o[c];for(let u=0;u<8;u++){if((i&1)===1)switch(n){case e:t=Y6(g1(n),t),s="-";break;default:t=q6(t,g1(n))}n++,i>>=1}}for(let c=0;c<t.length;c++)t[c]&&(a=!0),a&&(s+=y1.charAt(t[c]));return a===!1&&(s+=y1.charAt(0)),s}};k1=ps;ps.NAME="IntegerValueBlock";Object.defineProperty(k1.prototype,"valueHex",{set:function(r){this.valueHexView=new Uint8Array(r),this.setValueHex()},get:function(){return this.valueHexView.slice().buffer}});var R1,De=class r extends Ye{constructor(e={}){super(e,ps),this.idBlock.tagClass=1,this.idBlock.tagNumber=2}toBigInt(){return sc(),BigInt(this.valueBlock.toString())}static fromBigInt(e){sc();let t=BigInt(e),n=new fs,i=t.toString(16).replace(/^-/,""),o=new Uint8Array(se.Convert.FromHex(i));if(t<0){let a=new Uint8Array(o.length+(o[0]&128?1:0));a[0]|=128;let u=BigInt(`0x${se.Convert.ToHex(a)}`)+t,l=se.BufferSourceConverter.toUint8Array(se.Convert.FromHex(u.toString(16)));l[0]|=128,n.write(l)}else o[0]&128&&n.write(new Uint8Array([0])),n.write(o);return new r({valueHex:n.final()})}convertToDER(){let e=new r({valueHex:this.valueBlock.valueHexView});return e.valueBlock.toDER(),e}convertFromDER(){return new r({valueHex:this.valueBlock.valueHexView[0]===0?this.valueBlock.valueHexView.subarray(1):this.valueBlock.valueHexView})}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()}`}};R1=De;z.Integer=R1;De.NAME="INTEGER";var T1,wc=class extends De{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=10}};T1=wc;z.Enumerated=T1;wc.NAME="ENUMERATED";var ms=class extends Qr(tt){constructor({valueDec:e=-1,isFirstSid:t=!1,...n}={}){super(n),this.valueDec=e,this.isFirstSid=t}fromBER(e,t,n){if(!n)return t;let i=se.BufferSourceConverter.toUint8Array(e);if(!Jr(this,i,t,n))return-1;let o=i.subarray(t,t+n);this.valueHexView=new Uint8Array(n);for(let a=0;a<n&&(this.valueHexView[a]=o[a]&127,this.blockLength++,!!(o[a]&128));a++);let s=new Uint8Array(this.blockLength);for(let a=0;a<this.blockLength;a++)s[a]=this.valueHexView[a];return this.valueHexView=s,o[this.blockLength-1]&128?(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=vi(this.valueHexView,7):(this.isHexOnly=!0,this.warnings.push("Too big SID for decoding, hex only")),t+this.blockLength)}set valueBigInt(e){sc();let t=BigInt(e).toString(2);for(;t.length%7;)t="0"+t;let n=new Uint8Array(t.length/7);for(let i=0;i<n.length;i++)n[i]=parseInt(t.slice(i*7,i*7+7),2)+(i+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 i=this.valueHexView,o=new Uint8Array(this.blockLength);for(let s=0;s<this.blockLength-1;s++)o[s]=i[s]|128;return o[this.blockLength-1]=i[this.blockLength-1],o.buffer}let t=On(this.valueDec,7);if(t.byteLength===0)return this.error="Error during encoding SID value",nr;let n=new Uint8Array(t.byteLength);if(!e){let i=new Uint8Array(t),o=t.byteLength-1;for(let s=0;s<o;s++)n[s]=i[s]|128;n[o]=i[o]}return n}toString(){let e="";if(this.isHexOnly)e=se.Convert.ToHex(this.valueHexView);else if(this.isFirstSid){let t=this.valueDec;this.valueDec<=39?e="0.":this.valueDec<=79?(e="1.",t-=40):(e="2.",t-=80),e+=t.toString()}else e=this.valueDec.toString();return e}toJSON(){return{...super.toJSON(),valueDec:this.valueDec,isFirstSid:this.isFirstSid}}};ms.NAME="sidBlock";var Ec=class extends tt{constructor({value:e=wo,...t}={}){super(t),this.value=[],e&&this.fromString(e)}fromBER(e,t,n){let i=t;for(;n>0;){let o=new ms;if(i=o.fromBER(e,i,n),i===-1)return this.blockLength=0,this.error=o.error,i;this.value.length===0&&(o.isFirstSid=!0),this.blockLength+=o.blockLength,n-=o.blockLength,this.value.push(o)}return i}toBER(e){let t=[];for(let n=0;n<this.value.length;n++){let i=this.value[n].toBER(e);if(i.byteLength===0)return this.error=this.value[n].error,nr;t.push(i)}return jd(t)}fromString(e){this.value=[];let t=0,n=0,i="",o=!1;do if(n=e.indexOf(".",t),n===-1?i=e.substring(t):i=e.substring(t,n),t=n+1,o){let s=this.value[0],a=0;switch(s.valueDec){case 0:break;case 1:a=40;break;case 2:a=80;break;default:this.value=[];return}let c=parseInt(i,10);if(isNaN(c))return;s.valueDec=c+a,o=!1}else{let s=new ms;if(i>Number.MAX_SAFE_INTEGER){sc();let a=BigInt(i);s.valueBigInt=a}else if(s.valueDec=parseInt(i,10),isNaN(s.valueDec))return;this.value.length||(s.isFirstSid=!0,o=!0),this.value.push(s)}while(n!==-1)}toString(){let e="",t=!1;for(let n=0;n<this.value.length;n++){t=this.value[n].isHexOnly;let i=this.value[n].toString();n!==0&&(e=`${e}.`),t?(i=`{${i}}`,this.value[n].isFirstSid?e=`2.{${i} - 80}`:e+=i):e+=i}return e}toJSON(){let e={...super.toJSON(),value:this.toString(),sidArray:[]};for(let t=0;t<this.value.length;t++)e.sidArray.push(this.value[t].toJSON());return e}};Ec.NAME="ObjectIdentifierValueBlock";var N1,rr=class extends Ye{constructor(e={}){super(e,Ec),this.idBlock.tagClass=1,this.idBlock.tagNumber=6}getValue(){return this.valueBlock.toString()}setValue(e){this.valueBlock.fromString(e)}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()||"empty"}`}toJSON(){return{...super.toJSON(),value:this.getValue()}}};N1=rr;z.ObjectIdentifier=N1;rr.NAME="OBJECT IDENTIFIER";var ys=class extends Qr(jr){constructor({valueDec:e=0,...t}={}){super(t),this.valueDec=e}fromBER(e,t,n){if(n===0)return t;let i=se.BufferSourceConverter.toUint8Array(e);if(!Jr(this,i,t,n))return-1;let o=i.subarray(t,t+n);this.valueHexView=new Uint8Array(n);for(let a=0;a<n&&(this.valueHexView[a]=o[a]&127,this.blockLength++,!!(o[a]&128));a++);let s=new Uint8Array(this.blockLength);for(let a=0;a<this.blockLength;a++)s[a]=this.valueHexView[a];return this.valueHexView=s,o[this.blockLength-1]&128?(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=vi(this.valueHexView,7):(this.isHexOnly=!0,this.warnings.push("Too big SID for decoding, hex only")),t+this.blockLength)}toBER(e){if(this.isHexOnly){if(e)return new ArrayBuffer(this.valueHexView.byteLength);let i=this.valueHexView,o=new Uint8Array(this.blockLength);for(let s=0;s<this.blockLength-1;s++)o[s]=i[s]|128;return o[this.blockLength-1]=i[this.blockLength-1],o.buffer}let t=On(this.valueDec,7);if(t.byteLength===0)return this.error="Error during encoding SID value",nr;let n=new Uint8Array(t.byteLength);if(!e){let i=new Uint8Array(t),o=t.byteLength-1;for(let s=0;s<o;s++)n[s]=i[s]|128;n[o]=i[o]}return n.buffer}toString(){let e="";return this.isHexOnly?e=se.Convert.ToHex(this.valueHexView):e=this.valueDec.toString(),e}toJSON(){return{...super.toJSON(),valueDec:this.valueDec}}};ys.NAME="relativeSidBlock";var xc=class extends tt{constructor({value:e=wo,...t}={}){super(t),this.value=[],e&&this.fromString(e)}fromBER(e,t,n){let i=t;for(;n>0;){let o=new ys;if(i=o.fromBER(e,i,n),i===-1)return this.blockLength=0,this.error=o.error,i;this.blockLength+=o.blockLength,n-=o.blockLength,this.value.push(o)}return i}toBER(e,t){let n=[];for(let i=0;i<this.value.length;i++){let o=this.value[i].toBER(e);if(o.byteLength===0)return this.error=this.value[i].error,nr;n.push(o)}return jd(n)}fromString(e){this.value=[];let t=0,n=0,i="";do{n=e.indexOf(".",t),n===-1?i=e.substring(t):i=e.substring(t,n),t=n+1;let o=new ys;if(o.valueDec=parseInt(i,10),isNaN(o.valueDec))return!0;this.value.push(o)}while(n!==-1);return!0}toString(){let e="",t=!1;for(let n=0;n<this.value.length;n++){t=this.value[n].isHexOnly;let i=this.value[n].toString();n!==0&&(e=`${e}.`),t&&(i=`{${i}}`),e+=i}return e}toJSON(){let e={...super.toJSON(),value:this.toString(),sidArray:[]};for(let t=0;t<this.value.length;t++)e.sidArray.push(this.value[t].toJSON());return e}};xc.NAME="RelativeObjectIdentifierValueBlock";var C1,bc=class extends Ye{constructor(e={}){super(e,xc),this.idBlock.tagClass=1,this.idBlock.tagNumber=13}getValue(){return this.valueBlock.toString()}setValue(e){this.valueBlock.fromString(e)}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()||"empty"}`}toJSON(){return{...super.toJSON(),value:this.getValue()}}};C1=bc;z.RelativeObjectIdentifier=C1;bc.NAME="RelativeObjectIdentifier";var L1,Me=class extends Pn{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=16}};L1=Me;z.Sequence=L1;Me.NAME="SEQUENCE";var U1,vc=class extends Pn{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=17}};U1=vc;z.Set=U1;vc.NAME="SET";var Ac=class extends Qr(tt){constructor({...e}={}){super(e),this.isHexOnly=!0,this.value=wo}toJSON(){return{...super.toJSON(),value:this.value}}};Ac.NAME="StringValueBlock";var _c=class extends Ac{};_c.NAME="SimpleStringValueBlock";var lt=class extends lc{constructor({...e}={}){super(e,_c)}fromBuffer(e){this.valueBlock.value=String.fromCharCode.apply(null,se.BufferSourceConverter.toUint8Array(e))}fromString(e){let t=e.length,n=this.valueBlock.valueHexView=new Uint8Array(t);for(let i=0;i<t;i++)n[i]=e.charCodeAt(i);this.valueBlock.value=e}};lt.NAME="SIMPLE STRING";var Sc=class extends lt{fromBuffer(e){this.valueBlock.valueHexView=se.BufferSourceConverter.toUint8Array(e);try{this.valueBlock.value=se.Convert.ToUtf8String(e)}catch(t){this.warnings.push(`Error during "decodeURIComponent": ${t}, using raw string`),this.valueBlock.value=se.Convert.ToBinary(e)}}fromString(e){this.valueBlock.valueHexView=new Uint8Array(se.Convert.FromUtf8String(e)),this.valueBlock.value=e}};Sc.NAME="Utf8StringValueBlock";var D1,Zr=class extends Sc{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=12}};D1=Zr;z.Utf8String=D1;Zr.NAME="UTF8String";var Ic=class extends lt{fromBuffer(e){this.valueBlock.value=se.Convert.ToUtf16String(e),this.valueBlock.valueHexView=se.BufferSourceConverter.toUint8Array(e)}fromString(e){this.valueBlock.value=e,this.valueBlock.valueHexView=new Uint8Array(se.Convert.FromUtf16String(e))}};Ic.NAME="BmpStringValueBlock";var O1,Bc=class extends Ic{constructor({...e}={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=30}};O1=Bc;z.BmpString=O1;Bc.NAME="BMPString";var kc=class extends lt{fromBuffer(e){let t=ArrayBuffer.isView(e)?e.slice().buffer:e.slice(0),n=new Uint8Array(t);for(let i=0;i<n.length;i+=4)n[i]=n[i+3],n[i+1]=n[i+2],n[i+2]=0,n[i+3]=0;this.valueBlock.value=String.fromCharCode.apply(null,new Uint32Array(t))}fromString(e){let t=e.length,n=this.valueBlock.valueHexView=new Uint8Array(t*4);for(let i=0;i<t;i++){let o=On(e.charCodeAt(i),8),s=new Uint8Array(o);if(s.length>4)continue;let a=4-s.length;for(let c=s.length-1;c>=0;c--)n[i*4+c+a]=s[c]}this.valueBlock.value=e}};kc.NAME="UniversalStringValueBlock";var P1,Rc=class extends kc{constructor({...e}={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=28}};P1=Rc;z.UniversalString=P1;Rc.NAME="UniversalString";var F1,Tc=class extends lt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=18}};F1=Tc;z.NumericString=F1;Tc.NAME="NumericString";var V1,Nc=class extends lt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=19}};V1=Nc;z.PrintableString=V1;Nc.NAME="PrintableString";var M1,Cc=class extends lt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=20}};M1=Cc;z.TeletexString=M1;Cc.NAME="TeletexString";var H1,Lc=class extends lt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=21}};H1=Lc;z.VideotexString=H1;Lc.NAME="VideotexString";var $1,Uc=class extends lt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=22}};$1=Uc;z.IA5String=$1;Uc.NAME="IA5String";var z1,Dc=class extends lt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=25}};z1=Dc;z.GraphicString=z1;Dc.NAME="GraphicString";var K1,gs=class extends lt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=26}};K1=gs;z.VisibleString=K1;gs.NAME="VisibleString";var G1,Oc=class extends lt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=27}};G1=Oc;z.GeneralString=G1;Oc.NAME="GeneralString";var q1,Pc=class extends lt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=29}};q1=Pc;z.CharacterString=q1;Pc.NAME="CharacterString";var Y1,ws=class extends gs{constructor({value:e,valueDate:t,...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 i=0;i<e.length;i++)this.valueBlock.valueHexView[i]=e.charCodeAt(i)}t&&(this.fromDate(t),this.valueBlock.valueHexView=new Uint8Array(this.toBuffer())),this.idBlock.tagClass=1,this.idBlock.tagNumber=23}fromBuffer(e){this.fromString(String.fromCharCode.apply(null,se.BufferSourceConverter.toUint8Array(e)))}toBuffer(){let e=this.toString(),t=new ArrayBuffer(e.length),n=new Uint8Array(t);for(let i=0;i<e.length;i++)n[i]=e.charCodeAt(i);return t}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 i=parseInt(n[1],10);i>=50?this.year=1900+i:this.year=2e3+i,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 t=new Array(7);return t[0]=wt(this.year<2e3?this.year-1900:this.year-2e3,2),t[1]=wt(this.month,2),t[2]=wt(this.day,2),t[3]=wt(this.hour,2),t[4]=wt(this.minute,2),t[5]=wt(this.second,2),t[6]="Z",t.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}}};Y1=ws;z.UTCTime=Y1;ws.NAME="UTCTime";var W1,Fc=class extends ws{constructor(e={}){var t;super(e),(t=this.millisecond)!==null&&t!==void 0||(this.millisecond=0),this.idBlock.tagClass=1,this.idBlock.tagNumber=24}fromDate(e){super.fromDate(e),this.millisecond=e.getUTCMilliseconds()}toDate(){return new Date(Date.UTC(this.year,this.month-1,this.day,this.hour,this.minute,this.second,this.millisecond))}fromString(e){let t=!1,n="",i="",o=0,s,a=0,c=0;if(e[e.length-1]==="Z")n=e.substring(0,e.length-1),t=!0;else{let d=new Number(e[e.length-1]);if(isNaN(d.valueOf()))throw new Error("Wrong input string for conversion");n=e}if(t){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 d=1,p=n.indexOf("+"),f="";if(p===-1&&(p=n.indexOf("-"),d=-1),p!==-1){if(f=n.substring(p+1),n=n.substring(0,p),f.length!==2&&f.length!==4)throw new Error("Wrong input string for conversion");let h=parseInt(f.substring(0,2),10);if(isNaN(h.valueOf()))throw new Error("Wrong input string for conversion");if(a=d*h,f.length===4){if(h=parseInt(f.substring(2,4),10),isNaN(h.valueOf()))throw new Error("Wrong input string for conversion");c=d*h}}}let u=n.indexOf(".");if(u===-1&&(u=n.indexOf(",")),u!==-1){let d=new Number(`0${n.substring(u)}`);if(isNaN(d.valueOf()))throw new Error("Wrong input string for conversion");o=d.valueOf(),i=n.substring(0,u)}else i=n;switch(!0){case i.length===8:if(s=/(\d{4})(\d{2})(\d{2})/ig,u!==-1)throw new Error("Wrong input string for conversion");break;case i.length===10:if(s=/(\d{4})(\d{2})(\d{2})(\d{2})/ig,u!==-1){let d=60*o;this.minute=Math.floor(d),d=60*(d-this.minute),this.second=Math.floor(d),d=1e3*(d-this.second),this.millisecond=Math.floor(d)}break;case i.length===12:if(s=/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})/ig,u!==-1){let d=60*o;this.second=Math.floor(d),d=1e3*(d-this.second),this.millisecond=Math.floor(d)}break;case i.length===14:if(s=/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/ig,u!==-1){let d=1e3*o;this.millisecond=Math.floor(d)}break;default:throw new Error("Wrong input string for conversion")}let l=s.exec(i);if(l===null)throw new Error("Wrong input string for conversion");for(let d=1;d<l.length;d++)switch(d){case 1:this.year=parseInt(l[d],10);break;case 2:this.month=parseInt(l[d],10);break;case 3:this.day=parseInt(l[d],10);break;case 4:this.hour=parseInt(l[d],10)+a;break;case 5:this.minute=parseInt(l[d],10)+c;break;case 6:this.second=parseInt(l[d],10);break;default:throw new Error("Wrong input string for conversion")}if(t===!1){let d=new Date(this.year,this.month,this.day,this.hour,this.minute,this.second,this.millisecond);this.year=d.getUTCFullYear(),this.month=d.getUTCMonth(),this.day=d.getUTCDay(),this.hour=d.getUTCHours(),this.minute=d.getUTCMinutes(),this.second=d.getUTCSeconds(),this.millisecond=d.getUTCMilliseconds()}}toString(e="iso"){if(e==="iso"){let t=[];return t.push(wt(this.year,4)),t.push(wt(this.month,2)),t.push(wt(this.day,2)),t.push(wt(this.hour,2)),t.push(wt(this.minute,2)),t.push(wt(this.second,2)),this.millisecond!==0&&(t.push("."),t.push(wt(this.millisecond,3))),t.push("Z"),t.join("")}return super.toString(e)}toJSON(){return{...super.toJSON(),millisecond:this.millisecond}}};W1=Fc;z.GeneralizedTime=W1;Fc.NAME="GeneralizedTime";var j1,Vc=class extends Zr{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=31}};j1=Vc;z.DATE=j1;Vc.NAME="DATE";var X1,Mc=class extends Zr{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=32}};X1=Mc;z.TimeOfDay=X1;Mc.NAME="TimeOfDay";var Z1,Hc=class extends Zr{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=33}};Z1=Hc;z.DateTime=Z1;Hc.NAME="DateTime";var J1,$c=class extends Zr{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=34}};J1=$c;z.Duration=J1;$c.NAME="Duration";var Q1,zc=class extends Zr{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=14}};Q1=zc;z.TIME=Q1;zc.NAME="TIME";function j6(r){let{result:e}=Eo(r),t=e.valueBlock.value;return{n:Z(vr(t[1].toBigInt()),"base64url"),e:Z(vr(t[2].toBigInt()),"base64url"),d:Z(vr(t[3].toBigInt()),"base64url"),p:Z(vr(t[4].toBigInt()),"base64url"),q:Z(vr(t[5].toBigInt()),"base64url"),dp:Z(vr(t[6].toBigInt()),"base64url"),dq:Z(vr(t[7].toBigInt()),"base64url"),qi:Z(vr(t[8].toBigInt()),"base64url"),kty:"RSA",alg:"RS256"}}function X6(r){if(r.n==null||r.e==null||r.d==null||r.p==null||r.q==null||r.dp==null||r.dq==null||r.qi==null)throw new O("JWK was missing components","ERR_INVALID_PARAMETERS");let t=new Me({value:[new De({value:0}),De.fromBigInt(Ar(V(r.n,"base64url"))),De.fromBigInt(Ar(V(r.e,"base64url"))),De.fromBigInt(Ar(V(r.d,"base64url"))),De.fromBigInt(Ar(V(r.p,"base64url"))),De.fromBigInt(Ar(V(r.q,"base64url"))),De.fromBigInt(Ar(V(r.dp,"base64url"))),De.fromBigInt(Ar(V(r.dq,"base64url"))),De.fromBigInt(Ar(V(r.qi,"base64url")))]}).toBER();return new Uint8Array(t,0,t.byteLength)}function Z6(r){let{result:e}=Eo(r),t=e.valueBlock.value[1].valueBlock.value[0].valueBlock.value;return{kty:"RSA",n:Z(vr(t[0].toBigInt()),"base64url"),e:Z(vr(t[1].toBigInt()),"base64url")}}function J6(r){if(r.n==null||r.e==null)throw new O("JWK was missing components","ERR_INVALID_PARAMETERS");let t=new Me({value:[new Me({value:[new rr({value:"1.2.840.113549.1.1.1"}),new Fn]}),new go({valueHex:new Me({value:[De.fromBigInt(Ar(V(r.n,"base64url"))),De.fromBigInt(Ar(V(r.e,"base64url")))]}).toBER()})]}).toBER();return new Uint8Array(t,0,t.byteLength)}function vr(r){let e=r.toString(16);e.length%2>0&&(e=`0${e}`);let t=e.length/2,n=new Uint8Array(t),i=0,o=0;for(;i<t;)n[i]=parseInt(e.slice(o,o+2),16),i+=1,o+=2;return n}function Ar(r){let e=[];return r.forEach(function(t){let n=t.toString(16);n.length%2>0&&(n=`0${n}`),e.push(n)}),BigInt("0x"+e.join(""))}var Q6=16,Zd=32,Jd=1e4;async function ev(r,e){let t=ct.get(),i=new Me({value:[new De({value:0}),new Me({value:[new rr({value:"1.2.840.113549.1.1.1"}),new Fn]}),new Xr({valueHex:r.marshal()})]}).toBER(),o=new Uint8Array(i,0,i.byteLength),s=bi(Q6),a=await qd(uo,e,s,{c:Jd,dkLen:Zd}),c=bi(16),u=await t.subtle.importKey("raw",a,"AES-CBC",!1,["encrypt"]),l=await t.subtle.encrypt({name:"AES-CBC",iv:c},u,o),d=new Me({value:[new Xr({valueHex:s}),new De({value:Jd}),new De({value:Zd}),new Me({value:[new rr({value:"1.2.840.113549.2.11"}),new Fn]})]}),p=new Me({value:[new rr({value:"1.2.840.113549.1.5.13"}),new Me({value:[new Me({value:[new rr({value:"1.2.840.113549.1.5.12"}),d]}),new Me({value:[new rr({value:"2.16.840.1.101.3.4.1.42"}),new Xr({valueHex:c})]})]})]}),h=new Me({value:[p,new Xr({valueHex:l})]}).toBER(),m=new Uint8Array(h,0,h.byteLength);return["-----BEGIN ENCRYPTED PRIVATE KEY-----",...Z(m,"base64pad").split(/(.{64})/).filter(Boolean),"-----END ENCRYPTED PRIVATE KEY-----"].join(`
|
|
8
|
-
`)}async function tv(r,e){let t=ct.get(),n;if(r.includes("-----BEGIN ENCRYPTED PRIVATE KEY-----")){let i=V(r.replace("-----BEGIN ENCRYPTED PRIVATE KEY-----","").replace("-----END ENCRYPTED PRIVATE KEY-----","").replace(/\n/g,"").trim(),"base64pad"),{result:o}=Eo(i),{iv:s,salt:a,iterations:c,keySize:u,cipherText:l}=rv(o),d=await qd(uo,e,a,{c,dkLen:u}),p=await t.subtle.importKey("raw",d,"AES-CBC",!1,["decrypt"]),f=Es(await t.subtle.decrypt({name:"AES-CBC",iv:s},p,l)),{result:h}=Eo(f);n=em(h)}else if(r.includes("-----BEGIN PRIVATE KEY-----")){let i=V(r.replace("-----BEGIN PRIVATE KEY-----","").replace("-----END PRIVATE KEY-----","").replace(/\n/g,"").trim(),"base64pad"),{result:o}=Eo(i);n=em(o)}else throw new O("Could not parse private key from PEM data","ERR_INVALID_PARAMETERS");return Qd(n)}function rv(r){let e=r.valueBlock.value[0];if(e.valueBlock.value[0].toString()!=="OBJECT IDENTIFIER : 1.2.840.113549.1.5.13")throw new O("Only pkcs5PBES2 encrypted private keys are supported","ERR_INVALID_PARAMS");let n=e.valueBlock.value[1].valueBlock.value[0];if(n.valueBlock.value[0].toString()!=="OBJECT IDENTIFIER : 1.2.840.113549.1.5.12")throw new O("Only pkcs5PBKDF2 key derivation functions are supported","ERR_INVALID_PARAMS");let o=n.valueBlock.value[1],s=Es(o.valueBlock.value[0].getValue()),a=Jd,c=Zd;if(o.valueBlock.value.length===3)a=Number(o.valueBlock.value[1].toBigInt()),c=Number(o.valueBlock.value[2].toBigInt());else if(o.valueBlock.value.length===2)throw new O("Could not derive key size and iterations from PEM file - please use @libp2p/rsa to re-import your key","ERR_INVALID_PARAMS");let u=e.valueBlock.value[1].valueBlock.value[1],l=u.valueBlock.value[0].toString();if(l!=="OBJECT IDENTIFIER : 1.2.840.113549.3.7"){if(l!=="OBJECT IDENTIFIER : 1.3.14.3.2.7"){if(l!=="OBJECT IDENTIFIER : 2.16.840.1.101.3.4.1.2"){if(l!=="OBJECT IDENTIFIER : 2.16.840.1.101.3.4.1.22"){if(l!=="OBJECT IDENTIFIER : 2.16.840.1.101.3.4.1.42")throw new O("Only AES-CBC encryption schemes are supported","ERR_INVALID_PARAMS")}}}}let d=Es(u.valueBlock.value[1].getValue());return{cipherText:Es(r.valueBlock.value[1].getValue()),salt:s,iterations:a,keySize:c,iv:d}}function em(r){return Es(r.valueBlock.value[2].getValue())}function Es(r){return new Uint8Array(r,0,r.byteLength)}async function tm(r){let e=await ct.get().subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:r,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!0,["sign","verify"]),t=await im(e);return{privateKey:t[0],publicKey:t[1]}}async function ef(r){let t=[await ct.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!0,["sign"]),await nv(r)],n=await im({privateKey:t[0],publicKey:t[1]});return{privateKey:n[0],publicKey:n[1]}}async function rm(r,e){let t=await ct.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]),n=await ct.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},t,e instanceof Uint8Array?e:e.subarray());return new Uint8Array(n,0,n.byteLength)}async function nm(r,e,t){let n=await ct.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);return ct.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},n,e,t instanceof Uint8Array?t:t.subarray())}async function im(r){if(r.privateKey==null||r.publicKey==null)throw new O("Private and public key are required","ERR_INVALID_PARAMETERS");return Promise.all([ct.get().subtle.exportKey("jwk",r.privateKey),ct.get().subtle.exportKey("jwk",r.publicKey)])}async function nv(r){return ct.get().subtle.importKey("jwk",{kty:r.kty,n:r.n,e:r.e},{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!0,["verify"])}function Gc(r){if(r.kty!=="RSA")throw new O("invalid key type","ERR_INVALID_KEY_TYPE");if(r.n==null)throw new O("invalid key modulus","ERR_INVALID_KEY_MODULUS");return V(r.n,"base64url").length*8}var bs=8192,xs=class{_key;constructor(e){this._key=e}verify(e,t){return nm(this._key,t,e)}marshal(){return Vn.jwkToPkix(this._key)}get bytes(){return Er.encode({Type:be.RSA,Data:this.marshal()}).subarray()}equals(e){return he(this.bytes,e.bytes)}hash(){let e=fe.digest(this.bytes);return Gt(e)?e.then(({bytes:t})=>t):e.bytes}},xo=class{_key;_publicKey;constructor(e,t){this._key=e,this._publicKey=t}genSecret(){return bi(16)}sign(e){return rm(this._key,e)}get public(){if(this._publicKey==null)throw new O("public key not provided","ERR_PUBKEY_NOT_PROVIDED");return new xs(this._publicKey)}marshal(){return Vn.jwkToPkcs1(this._key)}get bytes(){return xr.encode({Type:be.RSA,Data:this.marshal()}).subarray()}equals(e){return he(this.bytes,e.bytes)}hash(){let e=fe.digest(this.bytes);return Gt(e)?e.then(({bytes:t})=>t):e.bytes}async id(){let e=await this.public.hash();return Z(e,"base58btc")}async export(e,t="pkcs-8"){if(t==="pkcs-8")return Vn.exportToPem(this,e);if(t==="libp2p-key")return po(this.bytes,e);throw new O(`export format '${t}' is not supported`,"ERR_INVALID_EXPORT_FORMAT")}};async function Qd(r){let e=Vn.pkcs1ToJwk(r);if(Gc(e)>bs)throw new O("key size is too large","ERR_KEY_SIZE_TOO_LARGE");let t=await ef(e);return new xo(t.privateKey,t.publicKey)}function ov(r){let e=Vn.pkixToJwk(r);if(Gc(e)>bs)throw new O("key size is too large","ERR_KEY_SIZE_TOO_LARGE");return new xs(e)}async function sv(r){if(Gc(r)>bs)throw new O("key size is too large","ERR_KEY_SIZE_TOO_LARGE");let e=await ef(r);return new xo(e.privateKey,e.publicKey)}async function av(r){if(r>bs)throw new O("key size is too large","ERR_KEY_SIZE_TOO_LARGE");let e=await tm(r);return new xo(e.privateKey,e.publicKey)}var af={};Be(af,{Secp256k1PrivateKey:()=>As,Secp256k1PublicKey:()=>vs,generateKeyPair:()=>vv,unmarshalSecp256k1PrivateKey:()=>xv,unmarshalSecp256k1PublicKey:()=>bv});var cv=(r,e,t)=>r&e^~r&t,lv=(r,e,t)=>r&e^r&t^e&t,uv=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),Mn=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Hn=new Uint32Array(64),rf=class extends lo{constructor(){super(64,32,8,!1),this.A=Mn[0]|0,this.B=Mn[1]|0,this.C=Mn[2]|0,this.D=Mn[3]|0,this.E=Mn[4]|0,this.F=Mn[5]|0,this.G=Mn[6]|0,this.H=Mn[7]|0}get(){let{A:e,B:t,C:n,D:i,E:o,F:s,G:a,H:c}=this;return[e,t,n,i,o,s,a,c]}set(e,t,n,i,o,s,a,c){this.A=e|0,this.B=t|0,this.C=n|0,this.D=i|0,this.E=o|0,this.F=s|0,this.G=a|0,this.H=c|0}process(e,t){for(let d=0;d<16;d++,t+=4)Hn[d]=e.getUint32(t,!1);for(let d=16;d<64;d++){let p=Hn[d-15],f=Hn[d-2],h=Qt(p,7)^Qt(p,18)^p>>>3,m=Qt(f,17)^Qt(f,19)^f>>>10;Hn[d]=m+Hn[d-7]+h+Hn[d-16]|0}let{A:n,B:i,C:o,D:s,E:a,F:c,G:u,H:l}=this;for(let d=0;d<64;d++){let p=Qt(a,6)^Qt(a,11)^Qt(a,25),f=l+p+cv(a,c,u)+uv[d]+Hn[d]|0,m=(Qt(n,2)^Qt(n,13)^Qt(n,22))+lv(n,i,o)|0;l=u,u=c,c=a,a=s+f|0,s=o,o=i,i=n,n=f+m|0}n=n+this.A|0,i=i+this.B|0,o=o+this.C|0,s=s+this.D|0,a=a+this.E|0,c=c+this.F|0,u=u+this.G|0,l=l+this.H|0,this.set(n,i,o,s,a,c,u,l)}roundClean(){Hn.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};var om=Ga(()=>new rf);function dv(r){let e=cs(r);wr(e,{a:"field",b:"field"},{allowedPrivateKeyLengths:"array",wrapPrivateKey:"boolean",isTorsionFree:"function",clearCofactor:"function",allowInfinityPoint:"boolean",fromBytes:"function",toBytes:"function"});let{endo:t,Fp:n,a:i}=e;if(t){if(!n.eql(i,n.ZERO))throw new Error("Endomorphism can only be defined for Koblitz curves that have a=0");if(typeof t!="object"||typeof t.beta!="bigint"||typeof t.splitScalar!="function")throw new Error("Expected endomorphism with beta: bigint and splitScalar: function")}return Object.freeze({...e})}var{bytesToNumberBE:fv,hexToBytes:hv}=Wa,Ai={Err:class extends Error{constructor(e=""){super(e)}},_parseInt(r){let{Err:e}=Ai;if(r.length<2||r[0]!==2)throw new e("Invalid signature integer tag");let t=r[1],n=r.subarray(2,t+2);if(!t||n.length!==t)throw new e("Invalid signature integer: wrong length");if(n[0]&128)throw new e("Invalid signature integer: negative");if(n[0]===0&&!(n[1]&128))throw new e("Invalid signature integer: unnecessary leading zero");return{d:fv(n),l:r.subarray(t+2)}},toSig(r){let{Err:e}=Ai,t=typeof r=="string"?hv(r):r;if(!er(t))throw new Error("ui8a expected");let n=t.length;if(n<2||t[0]!=48)throw new e("Invalid signature tag");if(t[1]!==n-2)throw new e("Invalid signature: incorrect length");let{d:i,l:o}=Ai._parseInt(t.subarray(2)),{d:s,l:a}=Ai._parseInt(o);if(a.length)throw new e("Invalid signature: left bytes after parsing");return{r:i,s}},hexFromSig(r){let e=u=>Number.parseInt(u[0],16)&8?"00"+u:u,t=u=>{let l=u.toString(16);return l.length&1?`0${l}`:l},n=e(t(r.s)),i=e(t(r.r)),o=n.length/2,s=i.length/2,a=t(o),c=t(s);return`30${t(s+o+4)}02${c}${i}02${a}${n}`}},en=BigInt(0),Yt=BigInt(1),PT=BigInt(2),sm=BigInt(3),FT=BigInt(4);function pv(r){let e=dv(r),{Fp:t}=e,n=e.toBytes||((h,m,y)=>{let g=m.toAffine();return Gr(Uint8Array.from([4]),t.toBytes(g.x),t.toBytes(g.y))}),i=e.fromBytes||(h=>{let m=h.subarray(1),y=t.fromBytes(m.subarray(0,t.BYTES)),g=t.fromBytes(m.subarray(t.BYTES,2*t.BYTES));return{x:y,y:g}});function o(h){let{a:m,b:y}=e,g=t.sqr(h),E=t.mul(g,h);return t.add(t.add(E,t.mul(h,m)),y)}if(!t.eql(t.sqr(e.Gy),o(e.Gx)))throw new Error("bad generator point: equation left != right");function s(h){return typeof h=="bigint"&&en<h&&h<e.n}function a(h){if(!s(h))throw new Error("Expected valid bigint: 0 < bigint < curve.n")}function c(h){let{allowedPrivateKeyLengths:m,nByteLength:y,wrapPrivateKey:g,n:E}=e;if(m&&typeof h!="bigint"){if(er(h)&&(h=zr(h)),typeof h!="string"||!m.includes(h.length))throw new Error("Invalid key");h=h.padStart(y*2,"0")}let x;try{x=typeof h=="bigint"?h:Kr(Re("private key",h,y))}catch{throw new Error(`private key must be ${y} bytes, hex or bigint, not ${typeof h}`)}return g&&(x=ge(x,E)),a(x),x}let u=new Map;function l(h){if(!(h instanceof d))throw new Error("ProjectivePoint expected")}class d{constructor(m,y,g){if(this.px=m,this.py=y,this.pz=g,m==null||!t.isValid(m))throw new Error("x required");if(y==null||!t.isValid(y))throw new Error("y required");if(g==null||!t.isValid(g))throw new Error("z required")}static fromAffine(m){let{x:y,y:g}=m||{};if(!m||!t.isValid(y)||!t.isValid(g))throw new Error("invalid affine point");if(m instanceof d)throw new Error("projective point not allowed");let E=x=>t.eql(x,t.ZERO);return E(y)&&E(g)?d.ZERO:new d(y,g,t.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(m){let y=t.invertBatch(m.map(g=>g.pz));return m.map((g,E)=>g.toAffine(y[E])).map(d.fromAffine)}static fromHex(m){let y=d.fromAffine(i(Re("pointHex",m)));return y.assertValidity(),y}static fromPrivateKey(m){return d.BASE.multiply(c(m))}_setWindowSize(m){this._WINDOW_SIZE=m,u.delete(this)}assertValidity(){if(this.is0()){if(e.allowInfinityPoint&&!t.is0(this.py))return;throw new Error("bad point: ZERO")}let{x:m,y}=this.toAffine();if(!t.isValid(m)||!t.isValid(y))throw new Error("bad point: x or y not FE");let g=t.sqr(y),E=o(m);if(!t.eql(g,E))throw new Error("bad point: equation left != right");if(!this.isTorsionFree())throw new Error("bad point: not in prime-order subgroup")}hasEvenY(){let{y:m}=this.toAffine();if(t.isOdd)return!t.isOdd(m);throw new Error("Field doesn't support isOdd")}equals(m){l(m);let{px:y,py:g,pz:E}=this,{px:x,py:_,pz:S}=m,A=t.eql(t.mul(y,S),t.mul(x,E)),v=t.eql(t.mul(g,S),t.mul(_,E));return A&&v}negate(){return new d(this.px,t.neg(this.py),this.pz)}double(){let{a:m,b:y}=e,g=t.mul(y,sm),{px:E,py:x,pz:_}=this,S=t.ZERO,A=t.ZERO,v=t.ZERO,b=t.mul(E,E),T=t.mul(x,x),C=t.mul(_,_),N=t.mul(E,x);return N=t.add(N,N),v=t.mul(E,_),v=t.add(v,v),S=t.mul(m,v),A=t.mul(g,C),A=t.add(S,A),S=t.sub(T,A),A=t.add(T,A),A=t.mul(S,A),S=t.mul(N,S),v=t.mul(g,v),C=t.mul(m,C),N=t.sub(b,C),N=t.mul(m,N),N=t.add(N,v),v=t.add(b,b),b=t.add(v,b),b=t.add(b,C),b=t.mul(b,N),A=t.add(A,b),C=t.mul(x,_),C=t.add(C,C),b=t.mul(C,N),S=t.sub(S,b),v=t.mul(C,T),v=t.add(v,v),v=t.add(v,v),new d(S,A,v)}add(m){l(m);let{px:y,py:g,pz:E}=this,{px:x,py:_,pz:S}=m,A=t.ZERO,v=t.ZERO,b=t.ZERO,T=e.a,C=t.mul(e.b,sm),N=t.mul(y,x),$=t.mul(g,_),D=t.mul(E,S),ne=t.add(y,g),B=t.add(x,_);ne=t.mul(ne,B),B=t.add(N,$),ne=t.sub(ne,B),B=t.add(y,E);let U=t.add(x,S);return B=t.mul(B,U),U=t.add(N,D),B=t.sub(B,U),U=t.add(g,E),A=t.add(_,S),U=t.mul(U,A),A=t.add($,D),U=t.sub(U,A),b=t.mul(T,B),A=t.mul(C,D),b=t.add(A,b),A=t.sub($,b),b=t.add($,b),v=t.mul(A,b),$=t.add(N,N),$=t.add($,N),D=t.mul(T,D),B=t.mul(C,B),$=t.add($,D),D=t.sub(N,D),D=t.mul(T,D),B=t.add(B,D),N=t.mul($,B),v=t.add(v,N),N=t.mul(U,B),A=t.mul(ne,A),A=t.sub(A,N),N=t.mul(ne,$),b=t.mul(U,b),b=t.add(b,N),new d(A,v,b)}subtract(m){return this.add(m.negate())}is0(){return this.equals(d.ZERO)}wNAF(m){return f.wNAFCached(this,u,m,y=>{let g=t.invertBatch(y.map(E=>E.pz));return y.map((E,x)=>E.toAffine(g[x])).map(d.fromAffine)})}multiplyUnsafe(m){let y=d.ZERO;if(m===en)return y;if(a(m),m===Yt)return this;let{endo:g}=e;if(!g)return f.unsafeLadder(this,m);let{k1neg:E,k1:x,k2neg:_,k2:S}=g.splitScalar(m),A=y,v=y,b=this;for(;x>en||S>en;)x&Yt&&(A=A.add(b)),S&Yt&&(v=v.add(b)),b=b.double(),x>>=Yt,S>>=Yt;return E&&(A=A.negate()),_&&(v=v.negate()),v=new d(t.mul(v.px,g.beta),v.py,v.pz),A.add(v)}multiply(m){a(m);let y=m,g,E,{endo:x}=e;if(x){let{k1neg:_,k1:S,k2neg:A,k2:v}=x.splitScalar(y),{p:b,f:T}=this.wNAF(S),{p:C,f:N}=this.wNAF(v);b=f.constTimeNegate(_,b),C=f.constTimeNegate(A,C),C=new d(t.mul(C.px,x.beta),C.py,C.pz),g=b.add(C),E=T.add(N)}else{let{p:_,f:S}=this.wNAF(y);g=_,E=S}return d.normalizeZ([g,E])[0]}multiplyAndAddUnsafe(m,y,g){let E=d.BASE,x=(S,A)=>A===en||A===Yt||!S.equals(E)?S.multiplyUnsafe(A):S.multiply(A),_=x(this,y).add(x(m,g));return _.is0()?void 0:_}toAffine(m){let{px:y,py:g,pz:E}=this,x=this.is0();m==null&&(m=x?t.ONE:t.inv(E));let _=t.mul(y,m),S=t.mul(g,m),A=t.mul(E,m);if(x)return{x:t.ZERO,y:t.ZERO};if(!t.eql(A,t.ONE))throw new Error("invZ was invalid");return{x:_,y:S}}isTorsionFree(){let{h:m,isTorsionFree:y}=e;if(m===Yt)return!0;if(y)return y(d,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){let{h:m,clearCofactor:y}=e;return m===Yt?this:y?y(d,this):this.multiplyUnsafe(e.h)}toRawBytes(m=!0){return this.assertValidity(),n(d,this,m)}toHex(m=!0){return zr(this.toRawBytes(m))}}d.BASE=new d(e.Gx,e.Gy,t.ONE),d.ZERO=new d(t.ZERO,t.ONE,t.ZERO);let p=e.nBitLength,f=Za(d,e.endo?Math.ceil(p/2):p);return{CURVE:e,ProjectivePoint:d,normPrivateKeyToScalar:c,weierstrassEquation:o,isWithinCurveOrder:s}}function mv(r){let e=cs(r);return wr(e,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...e})}function am(r){let e=mv(r),{Fp:t,n}=e,i=t.BYTES+1,o=2*t.BYTES+1;function s(B){return en<B&&B<t.ORDER}function a(B){return ge(B,n)}function c(B){return ja(B,n)}let{ProjectivePoint:u,normPrivateKeyToScalar:l,weierstrassEquation:d,isWithinCurveOrder:p}=pv({...e,toBytes(B,U,X){let L=U.toAffine(),k=t.toBytes(L.x),K=Gr;return X?K(Uint8Array.from([U.hasEvenY()?2:3]),k):K(Uint8Array.from([4]),k,t.toBytes(L.y))},fromBytes(B){let U=B.length,X=B[0],L=B.subarray(1);if(U===i&&(X===2||X===3)){let k=Kr(L);if(!s(k))throw new Error("Point is not on curve");let K=d(k),W=t.sqrt(K),J=(W&Yt)===Yt;return(X&1)===1!==J&&(W=t.neg(W)),{x:k,y:W}}else if(U===o&&X===4){let k=t.fromBytes(L.subarray(0,t.BYTES)),K=t.fromBytes(L.subarray(t.BYTES,2*t.BYTES));return{x:k,y:K}}else throw new Error(`Point of length ${U} was invalid. Expected ${i} compressed bytes or ${o} uncompressed bytes`)}}),f=B=>zr(Dn(B,e.nByteLength));function h(B){let U=n>>Yt;return B>U}function m(B){return h(B)?a(-B):B}let y=(B,U,X)=>Kr(B.slice(U,X));class g{constructor(U,X,L){this.r=U,this.s=X,this.recovery=L,this.assertValidity()}static fromCompact(U){let X=e.nByteLength;return U=Re("compactSignature",U,X*2),new g(y(U,0,X),y(U,X,2*X))}static fromDER(U){let{r:X,s:L}=Ai.toSig(Re("DER",U));return new g(X,L)}assertValidity(){if(!p(this.r))throw new Error("r must be 0 < r < CURVE.n");if(!p(this.s))throw new Error("s must be 0 < s < CURVE.n")}addRecoveryBit(U){return new g(this.r,this.s,U)}recoverPublicKey(U){let{r:X,s:L,recovery:k}=this,K=v(Re("msgHash",U));if(k==null||![0,1,2,3].includes(k))throw new Error("recovery id invalid");let W=k===2||k===3?X+e.n:X;if(W>=t.ORDER)throw new Error("recovery id 2 or 3 invalid");let J=k&1?"03":"02",re=u.fromHex(J+f(W)),ie=c(W),me=a(-K*ie),ae=a(L*ie),ue=u.BASE.multiplyAndAddUnsafe(re,me,ae);if(!ue)throw new Error("point at infinify");return ue.assertValidity(),ue}hasHighS(){return h(this.s)}normalizeS(){return this.hasHighS()?new g(this.r,a(-this.s),this.recovery):this}toDERRawBytes(){return gi(this.toDERHex())}toDERHex(){return Ai.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return gi(this.toCompactHex())}toCompactHex(){return f(this.r)+f(this.s)}}let E={isValidPrivateKey(B){try{return l(B),!0}catch{return!1}},normPrivateKeyToScalar:l,randomPrivateKey:()=>{let B=Fd(e.n);return t1(e.randomBytes(B),e.n)},precompute(B=8,U=u.BASE){return U._setWindowSize(B),U.multiply(BigInt(3)),U}};function x(B,U=!0){return u.fromPrivateKey(B).toRawBytes(U)}function _(B){let U=er(B),X=typeof B=="string",L=(U||X)&&B.length;return U?L===i||L===o:X?L===2*i||L===2*o:B instanceof u}function S(B,U,X=!0){if(_(B))throw new Error("first arg must be private key");if(!_(U))throw new Error("second arg must be public key");return u.fromHex(U).multiply(l(B)).toRawBytes(X)}let A=e.bits2int||function(B){let U=Kr(B),X=B.length*8-e.nBitLength;return X>0?U>>BigInt(X):U},v=e.bits2int_modN||function(B){return a(A(B))},b=as(e.nBitLength);function T(B){if(typeof B!="bigint")throw new Error("bigint expected");if(!(en<=B&&B<b))throw new Error(`bigint expected < 2^${e.nBitLength}`);return Dn(B,e.nByteLength)}function C(B,U,X=N){if(["recovered","canonical"].some(Ie=>Ie in X))throw new Error("sign() legacy options not supported");let{hash:L,randomBytes:k}=e,{lowS:K,prehash:W,extraEntropy:J}=X;K==null&&(K=!0),B=Re("msgHash",B),W&&(B=Re("prehashed msgHash",L(B)));let re=v(B),ie=l(U),me=[T(ie),T(re)];if(J!=null){let Ie=J===!0?k(t.BYTES):J;me.push(Re("extraEntropy",Ie))}let ae=Gr(...me),ue=re;function Ue(Ie){let Ke=A(Ie);if(!p(Ke))return;let Ge=c(Ke),Pe=u.BASE.multiply(Ke).toAffine(),Ze=a(Pe.x);if(Ze===en)return;let Vr=a(Ge*a(ue+Ze*ie));if(Vr===en)return;let li=(Pe.x===Ze?0:2)|Number(Pe.y&Yt),Xo=Vr;return K&&h(Vr)&&(Xo=m(Vr),li^=1),new g(Ze,Xo,li)}return{seed:ae,k2sig:Ue}}let N={lowS:e.lowS,prehash:!1},$={lowS:e.lowS,prehash:!1};function D(B,U,X=N){let{seed:L,k2sig:k}=C(B,U,X),K=e;return Ud(K.hash.outputLen,K.nByteLength,K.hmac)(L,k)}u.BASE._setWindowSize(8);function ne(B,U,X,L=$){let k=B;if(U=Re("msgHash",U),X=Re("publicKey",X),"strict"in L)throw new Error("options.strict was renamed to lowS");let{lowS:K,prehash:W}=L,J,re;try{if(typeof k=="string"||er(k))try{J=g.fromDER(k)}catch(Pe){if(!(Pe instanceof Ai.Err))throw Pe;J=g.fromCompact(k)}else if(typeof k=="object"&&typeof k.r=="bigint"&&typeof k.s=="bigint"){let{r:Pe,s:Ze}=k;J=new g(Pe,Ze)}else throw new Error("PARSE");re=u.fromHex(X)}catch(Pe){if(Pe.message==="PARSE")throw new Error("signature must be Signature instance, Uint8Array or hex string");return!1}if(K&&J.hasHighS())return!1;W&&(U=e.hash(U));let{r:ie,s:me}=J,ae=v(U),ue=c(me),Ue=a(ae*ue),Ie=a(ie*ue),Ke=u.BASE.multiplyAndAddUnsafe(re,Ue,Ie)?.toAffine();return Ke?a(Ke.x)===ie:!1}return{CURVE:e,getPublicKey:x,getSharedSecret:S,sign:D,verify:ne,ProjectivePoint:u,Signature:g,utils:E}}function yv(r){return{hash:r,hmac:(e,...t)=>us(r,e,Ka(...t)),randomBytes:co}}function cm(r,e){let t=n=>am({...r,...yv(n)});return Object.freeze({...t(e),create:t})}var dm=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),lm=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),gv=BigInt(1),nf=BigInt(2),um=(r,e)=>(r+e/nf)/e;function wv(r){let e=dm,t=BigInt(3),n=BigInt(6),i=BigInt(11),o=BigInt(22),s=BigInt(23),a=BigInt(44),c=BigInt(88),u=r*r*r%e,l=u*u*r%e,d=xe(l,t,e)*l%e,p=xe(d,t,e)*l%e,f=xe(p,nf,e)*u%e,h=xe(f,i,e)*f%e,m=xe(h,o,e)*h%e,y=xe(m,a,e)*m%e,g=xe(y,c,e)*y%e,E=xe(g,a,e)*m%e,x=xe(E,t,e)*l%e,_=xe(x,s,e)*h%e,S=xe(_,n,e)*u%e,A=xe(S,nf,e);if(!of.eql(of.sqr(A),r))throw new Error("Cannot find square root");return A}var of=Xa(dm,void 0,void 0,{sqrt:wv}),ir=cm({a:BigInt(0),b:BigInt(7),Fp:of,n:lm,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:r=>{let e=lm,t=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-gv*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),i=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),o=t,s=BigInt("0x100000000000000000000000000000000"),a=um(o*r,e),c=um(-n*r,e),u=ge(r-a*t-c*i,e),l=ge(-a*n-c*o,e),d=u>s,p=l>s;if(d&&(u=e-u),p&&(l=e-l),u>s||l>s)throw new Error("splitScalar: Endomorphism failed, k="+r);return{k1neg:d,k1:u,k2neg:p,k2:l}}}},om),YT=BigInt(0);var WT=ir.ProjectivePoint;function fm(){return ir.utils.randomPrivateKey()}function hm(r,e){let t=fe.digest(e instanceof Uint8Array?e:e.subarray());if(Gt(t))return t.then(({digest:n})=>ir.sign(n,r).toDERRawBytes()).catch(n=>{throw new O(String(n),"ERR_INVALID_INPUT")});try{return ir.sign(t.digest,r).toDERRawBytes()}catch(n){throw new O(String(n),"ERR_INVALID_INPUT")}}function pm(r,e,t){let n=fe.digest(t instanceof Uint8Array?t:t.subarray());if(Gt(n))return n.then(({digest:i})=>ir.verify(e,i,r)).catch(i=>{throw new O(String(i),"ERR_INVALID_INPUT")});try{return ir.verify(e,n.digest,r)}catch(i){throw new O(String(i),"ERR_INVALID_INPUT")}}function mm(r){return ir.ProjectivePoint.fromHex(r).toRawBytes(!0)}function ym(r){try{ir.getPublicKey(r,!0)}catch(e){throw new O(String(e),"ERR_INVALID_PRIVATE_KEY")}}function sf(r){try{ir.ProjectivePoint.fromHex(r)}catch(e){throw new O(String(e),"ERR_INVALID_PUBLIC_KEY")}}function gm(r){try{return ir.getPublicKey(r,!0)}catch(e){throw new O(String(e),"ERR_INVALID_PRIVATE_KEY")}}var vs=class{_key;constructor(e){sf(e),this._key=e}verify(e,t){return pm(this._key,t,e)}marshal(){return mm(this._key)}get bytes(){return Er.encode({Type:be.Secp256k1,Data:this.marshal()}).subarray()}equals(e){return he(this.bytes,e.bytes)}async hash(){let e=fe.digest(this.bytes),t;return Gt(e)?{bytes:t}=await e:t=e.bytes,t}},As=class{_key;_publicKey;constructor(e,t){this._key=e,this._publicKey=t??gm(e),ym(this._key),sf(this._publicKey)}sign(e){return hm(this._key,e)}get public(){return new vs(this._publicKey)}marshal(){return this._key}get bytes(){return xr.encode({Type:be.Secp256k1,Data:this.marshal()}).subarray()}equals(e){return he(this.bytes,e.bytes)}hash(){let e=fe.digest(this.bytes);return Gt(e)?e.then(({bytes:t})=>t):e.bytes}async id(){let e=await this.public.hash();return Z(e,"base58btc")}async export(e,t="libp2p-key"){if(t==="libp2p-key")return po(this.bytes,e);throw new O(`export format '${t}' is not supported`,"ERR_INVALID_EXPORT_FORMAT")}};function xv(r){return new As(r)}function bv(r){return new vs(r)}async function vv(){let r=fm();return new As(r)}var _i={rsa:tf,ed25519:Gd,secp256k1:af};function wm(r){let e=Object.keys(_i).join(" / ");return new O(`invalid or unsupported key type ${r}. Must be ${e}`,"ERR_UNSUPPORTED_KEY_TYPE")}function cf(r){let e=Er.decode(r),t=e.Data??new Uint8Array;switch(e.Type){case be.RSA:return _i.rsa.unmarshalRsaPublicKey(t);case be.Ed25519:return _i.ed25519.unmarshalEd25519PublicKey(t);case be.Secp256k1:return _i.secp256k1.unmarshalSecp256k1PublicKey(t);default:throw wm(e.Type??"unknown")}}async function Em(r){let e=xr.decode(r),t=e.Data??new Uint8Array;switch(e.Type){case be.RSA:return _i.rsa.unmarshalRsaPrivateKey(t);case be.Ed25519:return _i.ed25519.unmarshalEd25519PrivateKey(t);case be.Secp256k1:return _i.secp256k1.unmarshalSecp256k1PrivateKey(t);default:throw wm(e.Type??"RSA")}}var _f=Q(Ce(),1);var tn="/",xm=new TextEncoder().encode(tn),qc=xm[0],Le=class r{_buf;constructor(e,t){if(typeof e=="string")this._buf=V(e);else if(e instanceof Uint8Array)this._buf=e;else throw new Error("Invalid key, should be String of Uint8Array");if(t==null&&(t=!0),t&&this.clean(),this._buf.byteLength===0||this._buf[0]!==qc)throw new Error("Invalid key")}toString(e="utf8"){return Z(this._buf,e)}uint8Array(){return this._buf}get[Symbol.toStringTag](){return`Key(${this.toString()})`}static withNamespaces(e){return new r(e.join(tn))}static random(){return new r(Math.random().toString().substring(2))}static asKey(e){return e instanceof Uint8Array||typeof e=="string"?new r(e):typeof e.uint8Array=="function"?new r(e.uint8Array()):null}clean(){if((this._buf==null||this._buf.byteLength===0)&&(this._buf=xm),this._buf[0]!==qc){let e=new Uint8Array(this._buf.byteLength+1);e.fill(qc,0,1),e.set(this._buf,1),this._buf=e}for(;this._buf.byteLength>1&&this._buf[this._buf.byteLength-1]===qc;)this._buf=this._buf.subarray(0,-1)}less(e){let t=this.list(),n=e.list();for(let i=0;i<t.length;i++){if(n.length<i+1)return!1;let o=t[i],s=n[i];if(o<s)return!0;if(o>s)return!1}return t.length<n.length}reverse(){return r.withNamespaces(this.list().slice().reverse())}namespaces(){return this.list()}baseNamespace(){let e=this.namespaces();return e[e.length-1]}list(){return this.toString().split(tn).slice(1)}type(){return Av(this.baseNamespace())}name(){return _v(this.baseNamespace())}instance(e){return new r(this.toString()+":"+e)}path(){let e=this.parent().toString();return e.endsWith(tn)||(e+=tn),e+=this.type(),new r(e)}parent(){let e=this.list();return e.length===1?new r(tn):new r(e.slice(0,-1).join(tn))}child(e){return this.toString()===tn?e:e.toString()===tn?this:new r(this.toString()+e.toString(),!1)}isAncestorOf(e){return e.toString()===this.toString()?!1:e.toString().startsWith(this.toString())}isDecendantOf(e){return e.toString()===this.toString()?!1:this.toString().startsWith(e.toString())}isTopLevel(){return this.list().length===1}concat(...e){return r.withNamespaces([...this.namespaces(),...Sv(e.map(t=>t.namespaces()))])}};function Av(r){let e=r.split(":");return e.length<2?"":e.slice(0,-1).join(":")}function _v(r){let e=r.split(":");return e[e.length-1]}function Sv(r){return[].concat(...r)}var Oy=Q(Yc(),1);var bm="ERR_IPNS_EXPIRED_RECORD",_s="ERR_UNRECOGNIZED_VALIDITY",vm="ERR_SIGNATURE_CREATION",rn="ERR_SIGNATURE_VERIFICATION";var uf="ERR_UNDEFINED_PARAMETER",Am="ERR_INVALID_RECORD_DATA",_m="ERR_INVALID_VALUE",Sm="ERR_INVALID_EMBEDDED_KEY",Im="ERR_MISSING_PRIVATE_KEY",Bm="ERR_RECORD_TOO_LARGE";var We;(function(r){let e;(function(i){i.EOL="EOL"})(e=r.ValidityType||(r.ValidityType={}));let t;(function(i){i[i.EOL=0]="EOL"})(t||(t={})),function(i){i.codec=()=>yi(t)}(e=r.ValidityType||(r.ValidityType={}));let n;r.codec=()=>(n==null&&(n=$t((i,o,s={})=>{s.lengthDelimited!==!1&&o.fork(),i.value!=null&&(o.uint32(10),o.bytes(i.value)),i.signatureV1!=null&&(o.uint32(18),o.bytes(i.signatureV1)),i.validityType!=null&&(o.uint32(24),r.ValidityType.codec().encode(i.validityType,o)),i.validity!=null&&(o.uint32(34),o.bytes(i.validity)),i.sequence!=null&&(o.uint32(40),o.uint64(i.sequence)),i.ttl!=null&&(o.uint32(48),o.uint64(i.ttl)),i.pubKey!=null&&(o.uint32(58),o.bytes(i.pubKey)),i.signatureV2!=null&&(o.uint32(66),o.bytes(i.signatureV2)),i.data!=null&&(o.uint32(74),o.bytes(i.data)),s.lengthDelimited!==!1&&o.ldelim()},(i,o)=>{let s={},a=o==null?i.len:i.pos+o;for(;i.pos<a;){let c=i.uint32();switch(c>>>3){case 1:s.value=i.bytes();break;case 2:s.signatureV1=i.bytes();break;case 3:s.validityType=r.ValidityType.codec().decode(i);break;case 4:s.validity=i.bytes();break;case 5:s.sequence=i.uint64();break;case 6:s.ttl=i.uint64();break;case 7:s.pubKey=i.bytes();break;case 8:s.signatureV2=i.bytes();break;case 9:s.data=i.bytes();break;default:i.skipType(c&7);break}}return s})),n),r.encode=i=>Ht(i,r.codec()),r.decode=i=>Vt(i,r.codec())})(We||(We={}));var Iv=["string","number","bigint","symbol"],Bv=["Function","Generator","AsyncGenerator","GeneratorFunction","AsyncGeneratorFunction","AsyncFunction","Observable","Array","Buffer","Object","RegExp","Date","Error","Map","Set","WeakMap","WeakSet","ArrayBuffer","SharedArrayBuffer","DataView","Promise","URL","HTMLElement","Int8Array","Uint8Array","Uint8ClampedArray","Int16Array","Uint16Array","Int32Array","Uint32Array","Float32Array","Float64Array","BigInt64Array","BigUint64Array"];function km(r){if(r===null)return"null";if(r===void 0)return"undefined";if(r===!0||r===!1)return"boolean";let e=typeof r;if(Iv.includes(e))return e;if(e==="function")return"Function";if(Array.isArray(r))return"Array";if(kv(r))return"Buffer";let t=Rv(r);return t||"Object"}function kv(r){return r&&r.constructor&&r.constructor.isBuffer&&r.constructor.isBuffer.call(null,r)}function Rv(r){let e=Object.prototype.toString.call(r).slice(8,-1);if(Bv.includes(e))return e}var w=class{constructor(e,t,n){this.major=e,this.majorEncoded=e<<5,this.name=t,this.terminal=n}toString(){return`Type[${this.major}].${this.name}`}compare(e){return this.major<e.major?-1:this.major>e.major?1:0}};w.uint=new w(0,"uint",!0);w.negint=new w(1,"negint",!0);w.bytes=new w(2,"bytes",!0);w.string=new w(3,"string",!0);w.array=new w(4,"array",!1);w.map=new w(5,"map",!1);w.tag=new w(6,"tag",!1);w.float=new w(7,"float",!0);w.false=new w(7,"false",!0);w.true=new w(7,"true",!0);w.null=new w(7,"null",!0);w.undefined=new w(7,"undefined",!0);w.break=new w(7,"break",!0);var R=class{constructor(e,t,n){this.type=e,this.value=t,this.encodedLength=n,this.encodedBytes=void 0,this.byteValue=void 0}toString(){return`Token[${this.type}].${this.value}`}};var bo=globalThis.process&&!globalThis.process.browser&&globalThis.Buffer&&typeof globalThis.Buffer.isBuffer=="function",Tv=new TextDecoder,Nv=new TextEncoder;function Wc(r){return bo&&globalThis.Buffer.isBuffer(r)}function Ss(r){return r instanceof Uint8Array?Wc(r)?new Uint8Array(r.buffer,r.byteOffset,r.byteLength):r:Uint8Array.from(r)}var Cm=bo?(r,e,t)=>t-e>64?globalThis.Buffer.from(r.subarray(e,t)).toString("utf8"):Tm(r,e,t):(r,e,t)=>t-e>64?Tv.decode(r.subarray(e,t)):Tm(r,e,t),jc=bo?r=>r.length>64?globalThis.Buffer.from(r):Rm(r):r=>r.length>64?Nv.encode(r):Rm(r),_r=r=>Uint8Array.from(r),vo=bo?(r,e,t)=>Wc(r)?new Uint8Array(r.subarray(e,t)):r.slice(e,t):(r,e,t)=>r.slice(e,t),Lm=bo?(r,e)=>(r=r.map(t=>t instanceof Uint8Array?t:globalThis.Buffer.from(t)),Ss(globalThis.Buffer.concat(r,e))):(r,e)=>{let t=new Uint8Array(e),n=0;for(let i of r)n+i.length>t.length&&(i=i.subarray(0,t.length-n)),t.set(i,n),n+=i.length;return t},Um=bo?r=>globalThis.Buffer.allocUnsafe(r):r=>new Uint8Array(r);function Dm(r,e){if(Wc(r)&&Wc(e))return r.compare(e);for(let t=0;t<r.length;t++)if(r[t]!==e[t])return r[t]<e[t]?-1:1;return 0}function Rm(r){let e=[],t=0;for(let n=0;n<r.length;n++){let i=r.charCodeAt(n);i<128?e[t++]=i:i<2048?(e[t++]=i>>6|192,e[t++]=i&63|128):(i&64512)===55296&&n+1<r.length&&(r.charCodeAt(n+1)&64512)===56320?(i=65536+((i&1023)<<10)+(r.charCodeAt(++n)&1023),e[t++]=i>>18|240,e[t++]=i>>12&63|128,e[t++]=i>>6&63|128,e[t++]=i&63|128):(e[t++]=i>>12|224,e[t++]=i>>6&63|128,e[t++]=i&63|128)}return e}function Tm(r,e,t){let n=[];for(;e<t;){let i=r[e],o=null,s=i>239?4:i>223?3:i>191?2:1;if(e+s<=t){let a,c,u,l;switch(s){case 1:i<128&&(o=i);break;case 2:a=r[e+1],(a&192)===128&&(l=(i&31)<<6|a&63,l>127&&(o=l));break;case 3:a=r[e+1],c=r[e+2],(a&192)===128&&(c&192)===128&&(l=(i&15)<<12|(a&63)<<6|c&63,l>2047&&(l<55296||l>57343)&&(o=l));break;case 4:a=r[e+1],c=r[e+2],u=r[e+3],(a&192)===128&&(c&192)===128&&(u&192)===128&&(l=(i&15)<<18|(a&63)<<12|(c&63)<<6|u&63,l>65535&&l<1114112&&(o=l))}}o===null?(o=65533,s=1):o>65535&&(o-=65536,n.push(o>>>10&1023|55296),o=56320|o&1023),n.push(o),e+=s}return ff(n)}var Nm=4096;function ff(r){let e=r.length;if(e<=Nm)return String.fromCharCode.apply(String,r);let t="",n=0;for(;n<e;)t+=String.fromCharCode.apply(String,r.slice(n,n+=Nm));return t}var Cv=256,Is=class{constructor(e=Cv){this.chunkSize=e,this.cursor=0,this.maxCursor=-1,this.chunks=[],this._initReuseChunk=null}reset(){this.cursor=0,this.maxCursor=-1,this.chunks.length&&(this.chunks=[]),this._initReuseChunk!==null&&(this.chunks.push(this._initReuseChunk),this.maxCursor=this._initReuseChunk.length-1)}push(e){let t=this.chunks[this.chunks.length-1];if(this.cursor+e.length<=this.maxCursor+1){let i=t.length-(this.maxCursor-this.cursor)-1;t.set(e,i)}else{if(t){let i=t.length-(this.maxCursor-this.cursor)-1;i<t.length&&(this.chunks[this.chunks.length-1]=t.subarray(0,i),this.maxCursor=this.cursor-1)}e.length<64&&e.length<this.chunkSize?(t=Um(this.chunkSize),this.chunks.push(t),this.maxCursor+=t.length,this._initReuseChunk===null&&(this._initReuseChunk=t),t.set(e,0)):(this.chunks.push(e),this.maxCursor+=e.length)}this.cursor+=e.length}toBytes(e=!1){let t;if(this.chunks.length===1){let n=this.chunks[0];e&&this.cursor>n.length/2?(t=this.cursor===n.length?n:n.subarray(0,this.cursor),this._initReuseChunk=null,this.chunks=[]):t=vo(n,0,this.cursor)}else t=Lm(this.chunks,this.cursor);return e&&this.reset(),t}};var G="CBOR decode error:",nn="CBOR encode error:",Bs=[];Bs[23]=1;Bs[24]=2;Bs[25]=3;Bs[26]=5;Bs[27]=9;function on(r,e,t){if(r.length-e<t)throw new Error(`${G} not enough data for type`)}var He=[24,256,65536,4294967296,BigInt("18446744073709551616")];function Rt(r,e,t){on(r,e,1);let n=r[e];if(t.strict===!0&&n<He[0])throw new Error(`${G} integer encoded in more bytes than necessary (strict decode)`);return n}function Tt(r,e,t){on(r,e,2);let n=r[e]<<8|r[e+1];if(t.strict===!0&&n<He[1])throw new Error(`${G} integer encoded in more bytes than necessary (strict decode)`);return n}function Nt(r,e,t){on(r,e,4);let n=r[e]*16777216+(r[e+1]<<16)+(r[e+2]<<8)+r[e+3];if(t.strict===!0&&n<He[2])throw new Error(`${G} integer encoded in more bytes than necessary (strict decode)`);return n}function Ct(r,e,t){on(r,e,8);let n=r[e]*16777216+(r[e+1]<<16)+(r[e+2]<<8)+r[e+3],i=r[e+4]*16777216+(r[e+5]<<16)+(r[e+6]<<8)+r[e+7],o=(BigInt(n)<<BigInt(32))+BigInt(i);if(t.strict===!0&&o<He[3])throw new Error(`${G} integer encoded in more bytes than necessary (strict decode)`);if(o<=Number.MAX_SAFE_INTEGER)return Number(o);if(t.allowBigInt===!0)return o;throw new Error(`${G} integers outside of the safe integer range are not supported`)}function Om(r,e,t,n){return new R(w.uint,Rt(r,e+1,n),2)}function Pm(r,e,t,n){return new R(w.uint,Tt(r,e+1,n),3)}function Fm(r,e,t,n){return new R(w.uint,Nt(r,e+1,n),5)}function Vm(r,e,t,n){return new R(w.uint,Ct(r,e+1,n),9)}function Wt(r,e){return je(r,0,e.value)}function je(r,e,t){if(t<He[0]){let n=Number(t);r.push([e|n])}else if(t<He[1]){let n=Number(t);r.push([e|24,n])}else if(t<He[2]){let n=Number(t);r.push([e|25,n>>>8,n&255])}else if(t<He[3]){let n=Number(t);r.push([e|26,n>>>24&255,n>>>16&255,n>>>8&255,n&255])}else{let n=BigInt(t);if(n<He[4]){let i=[e|27,0,0,0,0,0,0,0],o=Number(n&BigInt(4294967295)),s=Number(n>>BigInt(32)&BigInt(4294967295));i[8]=o&255,o=o>>8,i[7]=o&255,o=o>>8,i[6]=o&255,o=o>>8,i[5]=o&255,i[4]=s&255,s=s>>8,i[3]=s&255,s=s>>8,i[2]=s&255,s=s>>8,i[1]=s&255,r.push(i)}else throw new Error(`${G} encountered BigInt larger than allowable range`)}}Wt.encodedSize=function(e){return je.encodedSize(e.value)};je.encodedSize=function(e){return e<He[0]?1:e<He[1]?2:e<He[2]?3:e<He[3]?5:9};Wt.compareTokens=function(e,t){return e.value<t.value?-1:e.value>t.value?1:0};function Mm(r,e,t,n){return new R(w.negint,-1-Rt(r,e+1,n),2)}function Hm(r,e,t,n){return new R(w.negint,-1-Tt(r,e+1,n),3)}function $m(r,e,t,n){return new R(w.negint,-1-Nt(r,e+1,n),5)}var hf=BigInt(-1),zm=BigInt(1);function Km(r,e,t,n){let i=Ct(r,e+1,n);if(typeof i!="bigint"){let o=-1-i;if(o>=Number.MIN_SAFE_INTEGER)return new R(w.negint,o,9)}if(n.allowBigInt!==!0)throw new Error(`${G} integers outside of the safe integer range are not supported`);return new R(w.negint,hf-BigInt(i),9)}function Xc(r,e){let t=e.value,n=typeof t=="bigint"?t*hf-zm:t*-1-1;je(r,e.type.majorEncoded,n)}Xc.encodedSize=function(e){let t=e.value,n=typeof t=="bigint"?t*hf-zm:t*-1-1;return n<He[0]?1:n<He[1]?2:n<He[2]?3:n<He[3]?5:9};Xc.compareTokens=function(e,t){return e.value<t.value?1:e.value>t.value?-1:0};function ks(r,e,t,n){on(r,e,t+n);let i=vo(r,e+t,e+t+n);return new R(w.bytes,i,t+n)}function Gm(r,e,t,n){return ks(r,e,1,t)}function qm(r,e,t,n){return ks(r,e,2,Rt(r,e+1,n))}function Ym(r,e,t,n){return ks(r,e,3,Tt(r,e+1,n))}function Wm(r,e,t,n){return ks(r,e,5,Nt(r,e+1,n))}function jm(r,e,t,n){let i=Ct(r,e+1,n);if(typeof i=="bigint")throw new Error(`${G} 64-bit integer bytes lengths not supported`);return ks(r,e,9,i)}function Zc(r){return r.encodedBytes===void 0&&(r.encodedBytes=r.type===w.string?jc(r.value):r.value),r.encodedBytes}function Ao(r,e){let t=Zc(e);je(r,e.type.majorEncoded,t.length),r.push(t)}Ao.encodedSize=function(e){let t=Zc(e);return je.encodedSize(t.length)+t.length};Ao.compareTokens=function(e,t){return Uv(Zc(e),Zc(t))};function Uv(r,e){return r.length<e.length?-1:r.length>e.length?1:Dm(r,e)}function Rs(r,e,t,n,i){let o=t+n;on(r,e,o);let s=new R(w.string,Cm(r,e+t,e+o),o);return i.retainStringBytes===!0&&(s.byteValue=vo(r,e+t,e+o)),s}function Xm(r,e,t,n){return Rs(r,e,1,t,n)}function Zm(r,e,t,n){return Rs(r,e,2,Rt(r,e+1,n),n)}function Jm(r,e,t,n){return Rs(r,e,3,Tt(r,e+1,n),n)}function Qm(r,e,t,n){return Rs(r,e,5,Nt(r,e+1,n),n)}function ey(r,e,t,n){let i=Ct(r,e+1,n);if(typeof i=="bigint")throw new Error(`${G} 64-bit integer string lengths not supported`);return Rs(r,e,9,i,n)}var ty=Ao;function _o(r,e,t,n){return new R(w.array,n,t)}function ry(r,e,t,n){return _o(r,e,1,t)}function ny(r,e,t,n){return _o(r,e,2,Rt(r,e+1,n))}function iy(r,e,t,n){return _o(r,e,3,Tt(r,e+1,n))}function oy(r,e,t,n){return _o(r,e,5,Nt(r,e+1,n))}function sy(r,e,t,n){let i=Ct(r,e+1,n);if(typeof i=="bigint")throw new Error(`${G} 64-bit integer array lengths not supported`);return _o(r,e,9,i)}function ay(r,e,t,n){if(n.allowIndefinite===!1)throw new Error(`${G} indefinite length items not allowed`);return _o(r,e,1,1/0)}function Jc(r,e){je(r,w.array.majorEncoded,e.value)}Jc.compareTokens=Wt.compareTokens;Jc.encodedSize=function(e){return je.encodedSize(e.value)};function So(r,e,t,n){return new R(w.map,n,t)}function cy(r,e,t,n){return So(r,e,1,t)}function ly(r,e,t,n){return So(r,e,2,Rt(r,e+1,n))}function uy(r,e,t,n){return So(r,e,3,Tt(r,e+1,n))}function dy(r,e,t,n){return So(r,e,5,Nt(r,e+1,n))}function fy(r,e,t,n){let i=Ct(r,e+1,n);if(typeof i=="bigint")throw new Error(`${G} 64-bit integer map lengths not supported`);return So(r,e,9,i)}function hy(r,e,t,n){if(n.allowIndefinite===!1)throw new Error(`${G} indefinite length items not allowed`);return So(r,e,1,1/0)}function Qc(r,e){je(r,w.map.majorEncoded,e.value)}Qc.compareTokens=Wt.compareTokens;Qc.encodedSize=function(e){return je.encodedSize(e.value)};function py(r,e,t,n){return new R(w.tag,t,1)}function my(r,e,t,n){return new R(w.tag,Rt(r,e+1,n),2)}function yy(r,e,t,n){return new R(w.tag,Tt(r,e+1,n),3)}function gy(r,e,t,n){return new R(w.tag,Nt(r,e+1,n),5)}function wy(r,e,t,n){return new R(w.tag,Ct(r,e+1,n),9)}function el(r,e){je(r,w.tag.majorEncoded,e.value)}el.compareTokens=Wt.compareTokens;el.encodedSize=function(e){return je.encodedSize(e.value)};var Mv=20,Hv=21,$v=22,zv=23;function Ey(r,e,t,n){if(n.allowUndefined===!1)throw new Error(`${G} undefined values are not supported`);return n.coerceUndefinedToNull===!0?new R(w.null,null,1):new R(w.undefined,void 0,1)}function xy(r,e,t,n){if(n.allowIndefinite===!1)throw new Error(`${G} indefinite length items not allowed`);return new R(w.break,void 0,1)}function pf(r,e,t){if(t){if(t.allowNaN===!1&&Number.isNaN(r))throw new Error(`${G} NaN values are not supported`);if(t.allowInfinity===!1&&(r===1/0||r===-1/0))throw new Error(`${G} Infinity values are not supported`)}return new R(w.float,r,e)}function by(r,e,t,n){return pf(mf(r,e+1),3,n)}function vy(r,e,t,n){return pf(yf(r,e+1),5,n)}function Ay(r,e,t,n){return pf(By(r,e+1),9,n)}function tl(r,e,t){let n=e.value;if(n===!1)r.push([w.float.majorEncoded|Mv]);else if(n===!0)r.push([w.float.majorEncoded|Hv]);else if(n===null)r.push([w.float.majorEncoded|$v]);else if(n===void 0)r.push([w.float.majorEncoded|zv]);else{let i,o=!1;(!t||t.float64!==!0)&&(Sy(n),i=mf(or,1),n===i||Number.isNaN(n)?(or[0]=249,r.push(or.slice(0,3)),o=!0):(Iy(n),i=yf(or,1),n===i&&(or[0]=250,r.push(or.slice(0,5)),o=!0))),o||(Kv(n),i=By(or,1),or[0]=251,r.push(or.slice(0,9)))}}tl.encodedSize=function(e,t){let n=e.value;if(n===!1||n===!0||n===null||n===void 0)return 1;if(!t||t.float64!==!0){Sy(n);let i=mf(or,1);if(n===i||Number.isNaN(n))return 3;if(Iy(n),i=yf(or,1),n===i)return 5}return 9};var _y=new ArrayBuffer(9),jt=new DataView(_y,1),or=new Uint8Array(_y,0);function Sy(r){if(r===1/0)jt.setUint16(0,31744,!1);else if(r===-1/0)jt.setUint16(0,64512,!1);else if(Number.isNaN(r))jt.setUint16(0,32256,!1);else{jt.setFloat32(0,r);let e=jt.getUint32(0),t=(e&2139095040)>>23,n=e&8388607;if(t===255)jt.setUint16(0,31744,!1);else if(t===0)jt.setUint16(0,(r&2147483648)>>16|n>>13,!1);else{let i=t-127;i<-24?jt.setUint16(0,0):i<-14?jt.setUint16(0,(e&2147483648)>>16|1<<24+i,!1):jt.setUint16(0,(e&2147483648)>>16|i+15<<10|n>>13,!1)}}}function mf(r,e){if(r.length-e<2)throw new Error(`${G} not enough data for float16`);let t=(r[e]<<8)+r[e+1];if(t===31744)return 1/0;if(t===64512)return-1/0;if(t===32256)return NaN;let n=t>>10&31,i=t&1023,o;return n===0?o=i*2**-24:n!==31?o=(i+1024)*2**(n-25):o=i===0?1/0:NaN,t&32768?-o:o}function Iy(r){jt.setFloat32(0,r,!1)}function yf(r,e){if(r.length-e<4)throw new Error(`${G} not enough data for float32`);let t=(r.byteOffset||0)+e;return new DataView(r.buffer,t,4).getFloat32(0,!1)}function Kv(r){jt.setFloat64(0,r,!1)}function By(r,e){if(r.length-e<8)throw new Error(`${G} not enough data for float64`);let t=(r.byteOffset||0)+e;return new DataView(r.buffer,t,8).getFloat64(0,!1)}tl.compareTokens=Wt.compareTokens;function de(r,e,t){throw new Error(`${G} encountered invalid minor (${t}) for major ${r[e]>>>5}`)}function rl(r){return()=>{throw new Error(`${G} ${r}`)}}var P=[];for(let r=0;r<=23;r++)P[r]=de;P[24]=Om;P[25]=Pm;P[26]=Fm;P[27]=Vm;P[28]=de;P[29]=de;P[30]=de;P[31]=de;for(let r=32;r<=55;r++)P[r]=de;P[56]=Mm;P[57]=Hm;P[58]=$m;P[59]=Km;P[60]=de;P[61]=de;P[62]=de;P[63]=de;for(let r=64;r<=87;r++)P[r]=Gm;P[88]=qm;P[89]=Ym;P[90]=Wm;P[91]=jm;P[92]=de;P[93]=de;P[94]=de;P[95]=rl("indefinite length bytes/strings are not supported");for(let r=96;r<=119;r++)P[r]=Xm;P[120]=Zm;P[121]=Jm;P[122]=Qm;P[123]=ey;P[124]=de;P[125]=de;P[126]=de;P[127]=rl("indefinite length bytes/strings are not supported");for(let r=128;r<=151;r++)P[r]=ry;P[152]=ny;P[153]=iy;P[154]=oy;P[155]=sy;P[156]=de;P[157]=de;P[158]=de;P[159]=ay;for(let r=160;r<=183;r++)P[r]=cy;P[184]=ly;P[185]=uy;P[186]=dy;P[187]=fy;P[188]=de;P[189]=de;P[190]=de;P[191]=hy;for(let r=192;r<=215;r++)P[r]=py;P[216]=my;P[217]=yy;P[218]=gy;P[219]=wy;P[220]=de;P[221]=de;P[222]=de;P[223]=de;for(let r=224;r<=243;r++)P[r]=rl("simple values are not supported");P[244]=de;P[245]=de;P[246]=de;P[247]=Ey;P[248]=rl("simple values are not supported");P[249]=by;P[250]=vy;P[251]=Ay;P[252]=de;P[253]=de;P[254]=de;P[255]=xy;var sr=[];for(let r=0;r<24;r++)sr[r]=new R(w.uint,r,1);for(let r=-1;r>=-24;r--)sr[31-r]=new R(w.negint,r,1);sr[64]=new R(w.bytes,new Uint8Array(0),1);sr[96]=new R(w.string,"",1);sr[128]=new R(w.array,0,1);sr[160]=new R(w.map,0,1);sr[244]=new R(w.false,!1,1);sr[245]=new R(w.true,!0,1);sr[246]=new R(w.null,null,1);function gf(r){switch(r.type){case w.false:return _r([244]);case w.true:return _r([245]);case w.null:return _r([246]);case w.bytes:return r.value.length?void 0:_r([64]);case w.string:return r.value===""?_r([96]):void 0;case w.array:return r.value===0?_r([128]):void 0;case w.map:return r.value===0?_r([160]):void 0;case w.uint:return r.value<24?_r([Number(r.value)]):void 0;case w.negint:if(r.value>=-24)return _r([31-Number(r.value)])}}var qv={float64:!1,mapSorter:Wv,quickEncodeToken:gf};function Ef(){let r=[];return r[w.uint.major]=Wt,r[w.negint.major]=Xc,r[w.bytes.major]=Ao,r[w.string.major]=ty,r[w.array.major]=Jc,r[w.map.major]=Qc,r[w.tag.major]=el,r[w.float.major]=tl,r}var ky=Ef(),wf=new Is,nl=class r{constructor(e,t){this.obj=e,this.parent=t}includes(e){let t=this;do if(t.obj===e)return!0;while(t=t.parent);return!1}static createCheck(e,t){if(e&&e.includes(t))throw new Error(`${nn} object contains circular references`);return new r(t,e)}},$n={null:new R(w.null,null),undefined:new R(w.undefined,void 0),true:new R(w.true,!0),false:new R(w.false,!1),emptyArray:new R(w.array,0),emptyMap:new R(w.map,0)},zn={number(r,e,t,n){return!Number.isInteger(r)||!Number.isSafeInteger(r)?new R(w.float,r):r>=0?new R(w.uint,r):new R(w.negint,r)},bigint(r,e,t,n){return r>=BigInt(0)?new R(w.uint,r):new R(w.negint,r)},Uint8Array(r,e,t,n){return new R(w.bytes,r)},string(r,e,t,n){return new R(w.string,r)},boolean(r,e,t,n){return r?$n.true:$n.false},null(r,e,t,n){return $n.null},undefined(r,e,t,n){return $n.undefined},ArrayBuffer(r,e,t,n){return new R(w.bytes,new Uint8Array(r))},DataView(r,e,t,n){return new R(w.bytes,new Uint8Array(r.buffer,r.byteOffset,r.byteLength))},Array(r,e,t,n){if(!r.length)return t.addBreakTokens===!0?[$n.emptyArray,new R(w.break)]:$n.emptyArray;n=nl.createCheck(n,r);let i=[],o=0;for(let s of r)i[o++]=Ts(s,t,n);return t.addBreakTokens?[new R(w.array,r.length),i,new R(w.break)]:[new R(w.array,r.length),i]},Object(r,e,t,n){let i=e!=="Object",o=i?r.keys():Object.keys(r),s=i?r.size:o.length;if(!s)return t.addBreakTokens===!0?[$n.emptyMap,new R(w.break)]:$n.emptyMap;n=nl.createCheck(n,r);let a=[],c=0;for(let u of o)a[c++]=[Ts(u,t,n),Ts(i?r.get(u):r[u],t,n)];return Yv(a,t),t.addBreakTokens?[new R(w.map,s),a,new R(w.break)]:[new R(w.map,s),a]}};zn.Map=zn.Object;zn.Buffer=zn.Uint8Array;for(let r of"Uint8Clamped Uint16 Uint32 Int8 Int16 Int32 BigUint64 BigInt64 Float32 Float64".split(" "))zn[`${r}Array`]=zn.DataView;function Ts(r,e={},t){let n=km(r),i=e&&e.typeEncoders&&e.typeEncoders[n]||zn[n];if(typeof i=="function"){let s=i(r,n,e,t);if(s!=null)return s}let o=zn[n];if(!o)throw new Error(`${nn} unsupported type: ${n}`);return o(r,n,e,t)}function Yv(r,e){e.mapSorter&&r.sort(e.mapSorter)}function Wv(r,e){let t=Array.isArray(r[0])?r[0][0]:r[0],n=Array.isArray(e[0])?e[0][0]:e[0];if(t.type!==n.type)return t.type.compare(n.type);let i=t.type.major,o=ky[i].compareTokens(t,n);return o===0&&console.warn("WARNING: complex key types used, CBOR key sorting guarantees are gone"),o}function Ry(r,e,t,n){if(Array.isArray(e))for(let i of e)Ry(r,i,t,n);else t[e.type.major](r,e,n)}function xf(r,e,t){let n=Ts(r,t);if(!Array.isArray(n)&&t.quickEncodeToken){let i=t.quickEncodeToken(n);if(i)return i;let o=e[n.type.major];if(o.encodedSize){let s=o.encodedSize(n,t),a=new Is(s);if(o(a,n,t),a.chunks.length!==1)throw new Error(`Unexpected error: pre-calculated length for ${n} was wrong`);return Ss(a.chunks[0])}}return wf.reset(),Ry(wf,n,e,t),wf.toBytes(!0)}function Kn(r,e){return e=Object.assign({},qv,e),xf(r,ky,e)}var jv={strict:!1,allowIndefinite:!0,allowUndefined:!0,allowBigInt:!0},bf=class{constructor(e,t={}){this._pos=0,this.data=e,this.options=t}pos(){return this._pos}done(){return this._pos>=this.data.length}next(){let e=this.data[this._pos],t=sr[e];if(t===void 0){let n=P[e];if(!n)throw new Error(`${G} no decoder for major type ${e>>>5} (byte 0x${e.toString(16).padStart(2,"0")})`);let i=e&31;t=n(this.data,this._pos,i,this.options)}return this._pos+=t.encodedLength,t}},Ns=Symbol.for("DONE"),il=Symbol.for("BREAK");function Xv(r,e,t){let n=[];for(let i=0;i<r.value;i++){let o=Cs(e,t);if(o===il){if(r.value===1/0)break;throw new Error(`${G} got unexpected break to lengthed array`)}if(o===Ns)throw new Error(`${G} found array but not enough entries (got ${i}, expected ${r.value})`);n[i]=o}return n}function Zv(r,e,t){let n=t.useMaps===!0,i=n?void 0:{},o=n?new Map:void 0;for(let s=0;s<r.value;s++){let a=Cs(e,t);if(a===il){if(r.value===1/0)break;throw new Error(`${G} got unexpected break to lengthed map`)}if(a===Ns)throw new Error(`${G} found map but not enough entries (got ${s} [no key], expected ${r.value})`);if(n!==!0&&typeof a!="string")throw new Error(`${G} non-string keys not supported (got ${typeof a})`);if(t.rejectDuplicateMapKeys===!0&&(n&&o.has(a)||!n&&a in i))throw new Error(`${G} found repeat map key "${a}"`);let c=Cs(e,t);if(c===Ns)throw new Error(`${G} found map but not enough entries (got ${s} [no value], expected ${r.value})`);n?o.set(a,c):i[a]=c}return n?o:i}function Cs(r,e){if(r.done())return Ns;let t=r.next();if(t.type===w.break)return il;if(t.type.terminal)return t.value;if(t.type===w.array)return Xv(t,r,e);if(t.type===w.map)return Zv(t,r,e);if(t.type===w.tag){if(e.tags&&typeof e.tags[t.value]=="function"){let n=Cs(r,e);return e.tags[t.value](n)}throw new Error(`${G} tag not supported (${t.value})`)}throw new Error("unsupported")}function vf(r,e){if(!(r instanceof Uint8Array))throw new Error(`${G} data to decode must be a Uint8Array`);e=Object.assign({},jv,e);let t=e.tokenizer||new bf(r,e),n=Cs(t,e);if(n===Ns)throw new Error(`${G} did not find any content to decode`);if(n===il)throw new Error(`${G} got unexpected break`);return[n,r.subarray(t.pos())]}function ut(r,e){let[t,n]=vf(r,e);if(n.length>0)throw new Error(`${G} too many terminals, data makes no sense`);return t}var Et=Q(Ce(),1);var Ty=oe("ipns:utils"),Ny=V("/ipns/"),Jv=114,Cy=async(r,e)=>{if(e==null||r==null){let n=new Error("one or more of the provided parameters are not defined");throw Ty.error(n),(0,Et.default)(n,uf)}let t;if(e.pubKey!=null){try{t=cf(e.pubKey)}catch(i){throw Ty.error(i),i}if(!(await A0(e.pubKey)).equals(r))throw(0,Et.default)(new Error("Embedded public key did not match PeerID"),Sm)}else r.publicKey!=null&&(t=cf(r.publicKey));if(t!=null)return t;throw(0,Et.default)(new Error("no public key is available"),uf)},Ly=(r,e,t)=>{let n=V(e);return ye([r,t,n])},sl=r=>{let e=V("ipns-signature:");return ye([e,r])},sn=r=>"signatureV1"in r?We.encode({value:V(r.value),signatureV1:r.signatureV1,validityType:r.validityType,validity:V(r.validity),sequence:r.sequence,ttl:r.ttl,pubKey:r.pubKey,signatureV2:r.signatureV2,data:r.data}):We.encode({pubKey:r.pubKey,signatureV2:r.signatureV2,data:r.data});function dt(r){let e=We.decode(r);if(e.sequence!=null&&(e.sequence=BigInt(e.sequence)),e.ttl!=null&&(e.ttl=BigInt(e.ttl)),e.signatureV2==null||e.data==null)throw(0,Et.default)(new Error("missing data or signatureV2"),rn);let t=Dy(e.data),n=Af(t.Value),i=Z(t.Validity);if(e.value!=null&&e.signatureV1!=null)return Qv(e),{value:n,validityType:We.ValidityType.EOL,validity:i,sequence:t.Sequence,ttl:t.TTL,pubKey:e.pubKey,signatureV1:e.signatureV1,signatureV2:e.signatureV2,data:e.data};if(e.signatureV2!=null)return{value:n,validityType:We.ValidityType.EOL,validity:i,sequence:t.Sequence,ttl:t.TTL,pubKey:e.pubKey,signatureV2:e.signatureV2,data:e.data};throw new Error("invalid record: does not include signatureV1 or signatureV2")}var Io=r=>ye([Ny,r.toBytes()]),Bo=r=>ss(r.slice(Ny.length)),Uy=(r,e,t,n,i)=>{let o;if(e===We.ValidityType.EOL)o=0;else throw(0,Et.default)(new Error("Unknown validity type"),_s);return Kn({Value:r,Validity:t,ValidityType:o,Sequence:n,TTL:i})},Dy=r=>{let e=ut(r);if(e.ValidityType===0)e.ValidityType=We.ValidityType.EOL;else throw(0,Et.default)(new Error("Unknown validity type"),_s);return Number.isInteger(e.Sequence)&&(e.Sequence=BigInt(e.Sequence)),Number.isInteger(e.TTL)&&(e.TTL=BigInt(e.TTL)),e},Af=r=>{if(r!=null){if(Dp(r))return`/ipns/${r.toCID().toString(kn)}`;if(r instanceof Uint8Array){let n=Z(r);n.startsWith("/")&&(r=n)}let e=r.toString().trim();if(e.startsWith("/")&&e.length>1)return e;let t=F.asCID(r);if(t!=null)return t.code===Jv?`/ipns/${t.toString(kn)}`:`/ipfs/${t.toV1().toString()}`;try{return r instanceof Uint8Array?`/ipfs/${F.decode(r).toV1().toString()}`:`/ipfs/${F.parse(e).toV1().toString()}`}catch{}}throw(0,Et.default)(new Error("Value must be a valid content path starting with /"),_m)},Qv=r=>{if(r.data==null)throw(0,Et.default)(new Error("Record data is missing"),Am);let e=Dy(r.data);if(!he(e.Value,r.value??new Uint8Array(0)))throw(0,Et.default)(new Error('Field "value" did not match between protobuf and CBOR'),rn);if(!he(e.Validity,r.validity??new Uint8Array(0)))throw(0,Et.default)(new Error('Field "validity" did not match between protobuf and CBOR'),rn);if(e.ValidityType!==r.validityType)throw(0,Et.default)(new Error('Field "validityType" did not match between protobuf and CBOR'),rn);if(e.Sequence!==r.sequence)throw(0,Et.default)(new Error('Field "sequence" did not match between protobuf and CBOR'),rn);if(e.TTL!==r.ttl)throw(0,Et.default)(new Error('Field "ttl" did not match between protobuf and CBOR'),rn)};var eA=oe("ipns"),tA=et.code,rA="/ipns/",LC=rA.length,Py={v1Compatible:!0};async function Fy(r,e,t,n,i=Py){let o=new Oy.default(Date.now()+Number(n)),s=We.ValidityType.EOL,[a,c]=n.toString().split("."),u=BigInt(a)*BigInt(1e5)+BigInt(c??"0");return nA(r,e,t,s,o.toString(),u,i)}var nA=async(r,e,t,n,i,o,s=Py)=>{t=BigInt(t);let a=V(i),c=Af(e),u=V(c);if(r.privateKey==null)throw(0,_f.default)(new Error("Missing private key"),Im);let l=await Em(r.privateKey),d=Uy(u,n,a,t,o),p=sl(d),f=await l.sign(p),h;if(r.publicKey!=null){let m=st(r.toBytes());(m.code!==tA||!he(r.publicKey,m.digest))&&(h=r.publicKey)}if(s.v1Compatible===!0){let m=await iA(l,u,n,a),y={value:c,signatureV1:m,validity:i,validityType:n,sequence:t,ttl:o,signatureV2:f,data:d};return h!=null&&(y.pubKey=h),y}else{let m={value:c,validity:i,validityType:n,sequence:t,ttl:o,signatureV2:f,data:d};return h!=null&&(m.pubKey=h),m}};var iA=async(r,e,t,n)=>{try{let i=Ly(e,t,n);return await r.sign(i)}catch(i){throw eA.error("record signature creation failed",i),(0,_f.default)(new Error("record signature creation failed"),vm)}};var Ls=Q(Ce(),1),Vy=Q(Yc(),1);var al=oe("ipns:validator"),oA=1024*10,sA=async(r,e)=>{let t=dt(e),n;try{let i=sl(t.data);n=await r.verify(i,t.signatureV2)}catch{n=!1}if(!n)throw al.error("record signature verification failed"),(0,Ls.default)(new Error("record signature verification failed"),rn);if(t.validityType===We.ValidityType.EOL){if(Vy.default.fromString(t.validity).toDate().getTime()<Date.now())throw al.error("record has expired"),(0,Ls.default)(new Error("record has expired"),bm)}else if(t.validityType!=null)throw al.error("unrecognized validity type"),(0,Ls.default)(new Error("unrecognized validity type"),_s);al("ipns record for %s is valid",t.value)};async function cl(r,e){if(e.byteLength>oA)throw(0,Ls.default)(new Error("record too large"),Bm);let t=Bo(r),n=dt(e),i=await Cy(t,n);await sA(i,e)}async function*Us(r){let e=/\r?\n/,t=new TextDecoder("utf8"),n="";for await(let i of r){typeof i=="string"&&(i=new TextEncoder().encode(i)),n+=t.decode(i,{stream:!0});let o=n.split(e);n=o.pop()??"";for(let s=0;s<o.length;s++)yield JSON.parse(o[s])}n+=t.decode(),n!==""&&(yield JSON.parse(n))}var If=Q(Hy(),1);var Os=class extends Error{constructor(e){super(e),this.name="TimeoutError"}},Bf=class extends Error{constructor(e){super(),this.name="AbortError",this.message=e}},$y=r=>globalThis.DOMException===void 0?new Bf(r):new DOMException(r),zy=r=>{let e=r.reason===void 0?$y("This operation was aborted."):r.reason;return e instanceof Error?e:$y(e)};function Ps(r,e){let{milliseconds:t,fallback:n,message:i,customTimers:o={setTimeout,clearTimeout}}=e,s,c=new Promise((u,l)=>{if(typeof t!="number"||Math.sign(t)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${t}\``);if(e.signal){let{signal:p}=e;p.aborted&&l(zy(p)),p.addEventListener("abort",()=>{l(zy(p))})}if(t===Number.POSITIVE_INFINITY){r.then(u,l);return}let d=new Os;s=o.setTimeout.call(void 0,()=>{if(n){try{u(n())}catch(p){l(p)}return}typeof r.cancel=="function"&&r.cancel(),i===!1?u():i instanceof Error?l(i):(d.message=i??`Promise timed out after ${t} milliseconds`,l(d))},t),(async()=>{try{u(await r)}catch(p){l(p)}})()}).finally(()=>{c.clear()});return c.clear=()=>{o.clearTimeout.call(void 0,s),s=void 0},c}function kf(r,e,t){let n=0,i=r.length;for(;i>0;){let o=Math.trunc(i/2),s=n+o;t(r[s],e)<=0?(n=++s,i-=o+1):i=o}return n}var Fs=class{#e=[];enqueue(e,t){t={priority:0,...t};let n={priority:t.priority,run:e};if(this.size&&this.#e[this.size-1].priority>=t.priority){this.#e.push(n);return}let i=kf(this.#e,n,(o,s)=>s.priority-o.priority);this.#e.splice(i,0,n)}dequeue(){return this.#e.shift()?.run}filter(e){return this.#e.filter(t=>t.priority===e.priority).map(t=>t.run)}get size(){return this.#e.length}};var nt=class extends If.default{#e;#t;#r=0;#s;#c;#p=0;#i;#l;#n;#m;#o=0;#u;#a;#y;timeout;constructor(e){if(super(),e={carryoverConcurrencyCount:!1,intervalCap:Number.POSITIVE_INFINITY,interval:0,concurrency:Number.POSITIVE_INFINITY,autoStart:!0,queueClass:Fs,...e},!(typeof e.intervalCap=="number"&&e.intervalCap>=1))throw new TypeError(`Expected \`intervalCap\` to be a number from 1 and up, got \`${e.intervalCap?.toString()??""}\` (${typeof e.intervalCap})`);if(e.interval===void 0||!(Number.isFinite(e.interval)&&e.interval>=0))throw new TypeError(`Expected \`interval\` to be a finite number >= 0, got \`${e.interval?.toString()??""}\` (${typeof e.interval})`);this.#e=e.carryoverConcurrencyCount,this.#t=e.intervalCap===Number.POSITIVE_INFINITY||e.interval===0,this.#s=e.intervalCap,this.#c=e.interval,this.#n=new e.queueClass,this.#m=e.queueClass,this.concurrency=e.concurrency,this.timeout=e.timeout,this.#y=e.throwOnTimeout===!0,this.#a=e.autoStart===!1}get#E(){return this.#t||this.#r<this.#s}get#x(){return this.#o<this.#u}#b(){this.#o--,this.#d(),this.emit("next")}#v(){this.#w(),this.#g(),this.#l=void 0}get#A(){let e=Date.now();if(this.#i===void 0){let t=this.#p-e;if(t<0)this.#r=this.#e?this.#o:0;else return this.#l===void 0&&(this.#l=setTimeout(()=>{this.#v()},t)),!0}return!1}#d(){if(this.#n.size===0)return this.#i&&clearInterval(this.#i),this.#i=void 0,this.emit("empty"),this.#o===0&&this.emit("idle"),!1;if(!this.#a){let e=!this.#A;if(this.#E&&this.#x){let t=this.#n.dequeue();return t?(this.emit("active"),t(),e&&this.#g(),!0):!1}}return!1}#g(){this.#t||this.#i!==void 0||(this.#i=setInterval(()=>{this.#w()},this.#c),this.#p=Date.now()+this.#c)}#w(){this.#r===0&&this.#o===0&&this.#i&&(clearInterval(this.#i),this.#i=void 0),this.#r=this.#e?this.#o:0,this.#f()}#f(){for(;this.#d(););}get concurrency(){return this.#u}set concurrency(e){if(!(typeof e=="number"&&e>=1))throw new TypeError(`Expected \`concurrency\` to be a number from 1 and up, got \`${e}\` (${typeof e})`);this.#u=e,this.#f()}async#_(e){return new Promise((t,n)=>{e.addEventListener("abort",()=>{n(e.reason)},{once:!0})})}async add(e,t={}){return t={timeout:this.timeout,throwOnTimeout:this.#y,...t},new Promise((n,i)=>{this.#n.enqueue(async()=>{this.#o++,this.#r++;try{t.signal?.throwIfAborted();let o=e({signal:t.signal});t.timeout&&(o=Ps(Promise.resolve(o),{milliseconds:t.timeout})),t.signal&&(o=Promise.race([o,this.#_(t.signal)]));let s=await o;n(s),this.emit("completed",s)}catch(o){if(o instanceof Os&&!t.throwOnTimeout){n();return}i(o),this.emit("error",o)}finally{this.#b()}},t),this.emit("add"),this.#d()})}async addAll(e,t){return Promise.all(e.map(async n=>this.add(n,t)))}start(){return this.#a?(this.#a=!1,this.#f(),this):this}pause(){this.#a=!0}clear(){this.#n=new this.#m}async onEmpty(){this.#n.size!==0&&await this.#h("empty")}async onSizeLessThan(e){this.#n.size<e||await this.#h("next",()=>this.#n.size<e)}async onIdle(){this.#o===0&&this.#n.size===0||await this.#h("idle")}async#h(e,t){return new Promise(n=>{let i=()=>{t&&!t()||(this.off(e,i),n())};this.on(e,i)})}get size(){return this.#n.size}sizeBy(e){return this.#n.filter(e).length}get pending(){return this.#o}get isPaused(){return this.#a}};function lA(r){return r[Symbol.asyncIterator]!=null}function uA(r){if(lA(r))return(async()=>{for await(let e of r)return e})();for(let e of r)return e}var Ii=uA;var Rf=V("/ipns/");function Ky(r){return he(r.subarray(0,Rf.byteLength),Rf)}var Gy=r=>ss(r.slice(Rf.length)),ul=class{client;constructor(e){this.client=e}async*findProviders(e,t={}){yield*at(this.client.getProviders(e,t),n=>({id:n.ID,multiaddrs:n.Addrs??[]}))}async provide(){}async put(e,t,n){if(!Ky(e))return;let i=Gy(e),o=dt(t);await this.client.putIPNS(i,o,n)}async get(e,t){if(!Ky(e))throw new O("Not found","ERR_NOT_FOUND");let n=Gy(e);try{let i=await this.client.getIPNS(n,t);return sn(i)}catch(i){throw i.code==="ERR_BAD_RESPONSE"?new O("Not found","ERR_NOT_FOUND"):i}}},dl=class{client;constructor(e){this.client=e}async findPeer(e,t={}){let n=await Ii(this.client.getPeers(e,t));if(n!=null)return{id:n.ID,multiaddrs:n.Addrs??[]};throw new O("Not found","ERR_NOT_FOUND")}async*getClosestPeers(e,t={}){}};var xt=oe("delegated-routing-v1-http-api-client"),qy={concurrentRequests:4,timeout:3e4},fl=class{started;httpQueue;shutDownController;clientUrl;timeout;contentRouting;peerRouting;constructor(e,t={}){this.started=!1,this.shutDownController=new AbortController,_a(1/0,this.shutDownController.signal),this.httpQueue=new nt({concurrency:t.concurrentRequests??qy.concurrentRequests}),this.clientUrl=e instanceof URL?e:new URL(e),this.timeout=t.timeout??qy.timeout,this.contentRouting=new ul(this),this.peerRouting=new dl(this)}get[es](){return this.contentRouting}get[ts](){return this.peerRouting}isStarted(){return this.started}start(){this.started=!0}stop(){this.httpQueue.clear(),this.shutDownController.abort(),this.started=!1}async*getProviders(e,t={}){xt("getProviders starts: %c",e);let n=ui([this.shutDownController.signal,t.signal,AbortSignal.timeout(this.timeout)]),i=_e(),o=_e();this.httpQueue.add(async()=>(i.resolve(),o.promise));try{await i.promise;let s=`${this.clientUrl}routing/v1/providers/${e.toString()}`,c=await fetch(s,{headers:{Accept:"application/x-ndjson"},signal:n});if(c.status===404)throw new O("No matching records found.","ERR_NOT_FOUND");if(c.status===422)throw new O("Request does not conform to schema or semantic constraints.","ERR_INVALID_REQUEST");if(c.body==null)throw new O("Routing response had no body","ERR_BAD_RESPONSE");if(c.headers.get("Content-Type")==="application/json"){let l=await c.json();for(let d of l.Providers){let p=this.#e(d);p!=null&&(yield p)}}else for await(let l of Us(Ha(c.body))){let d=this.#e(l);d!=null&&(yield d)}}catch(s){xt.error("getProviders errored:",s)}finally{n.clear(),o.resolve(),xt("getProviders finished: %c",e)}}async*getPeers(e,t={}){xt("getPeers starts: %c",e);let n=ui([this.shutDownController.signal,t.signal,AbortSignal.timeout(this.timeout)]),i=_e(),o=_e();this.httpQueue.add(async()=>(i.resolve(),o.promise));try{await i.promise;let s=`${this.clientUrl}routing/v1/peers/${e.toCID().toString()}`,c=await fetch(s,{headers:{Accept:"application/x-ndjson"},signal:n});if(c.status===404)throw new O("No matching records found.","ERR_NOT_FOUND");if(c.status===422)throw new O("Request does not conform to schema or semantic constraints.","ERR_INVALID_REQUEST");if(c.body==null)throw new O("Routing response had no body","ERR_BAD_RESPONSE");if(c.headers.get("Content-Type")==="application/json"){let l=await c.json();for(let d of l.Peers){let p=this.#e(d);p!=null&&(yield p)}}else for await(let l of Us(Ha(c.body))){let d=this.#e(l);d!=null&&(yield d)}}catch(s){xt.error("getPeers errored:",s)}finally{n.clear(),o.resolve(),xt("getPeers finished: %c",e)}}async getIPNS(e,t={}){xt("getIPNS starts: %c",e);let n=ui([this.shutDownController.signal,t.signal,AbortSignal.timeout(this.timeout)]),i=_e(),o=_e();this.httpQueue.add(async()=>(i.resolve(),o.promise));let s=`${this.clientUrl}routing/v1/ipns/${e.toCID().toString()}`;try{await i.promise;let c=await fetch(s,{headers:{Accept:"application/vnd.ipfs.ipns-record"},signal:n});if(xt("getIPNS GET %s %d",s,c.status),c.status===404)throw new O("No matching records found.","ERR_NOT_FOUND");if(c.status===422)throw new O("Request does not conform to schema or semantic constraints.","ERR_INVALID_REQUEST");if(c.body==null)throw new O("GET ipns response had no body","ERR_BAD_RESPONSE");let u=await c.arrayBuffer(),l=new Uint8Array(u,0,u.byteLength);return t.validate!==!1&&await cl(Io(e),l),dt(l)}catch(a){throw xt.error("getIPNS GET %s error:",s,a),a}finally{n.clear(),o.resolve(),xt("getIPNS finished: %c",e)}}async putIPNS(e,t,n={}){xt("putIPNS starts: %c",e);let i=ui([this.shutDownController.signal,n.signal,AbortSignal.timeout(this.timeout)]),o=_e(),s=_e();this.httpQueue.add(async()=>(o.resolve(),s.promise));let a=`${this.clientUrl}routing/v1/ipns/${e.toCID().toString()}`;try{await o.promise;let c=sn(t),l=await fetch(a,{method:"PUT",headers:{"Content-Type":"application/vnd.ipfs.ipns-record"},body:c,signal:i});if(xt("putIPNS PUT %s %d",a,l.status),l.status!==200)throw new O("PUT ipns response had status other than 200","ERR_BAD_RESPONSE")}catch(c){throw xt.error("putIPNS PUT %s error:",a,c.stack),c}finally{i.clear(),s.resolve(),xt("putIPNS finished: %c",e)}}#e(e){let t=[],n=e.Addrs?.map(Bd)??[];return e.Protocols!=null&&t.push(...e.Protocols),e.Protocol!=null&&(t.push(e.Protocol),delete e.Protocol),{...e,Schema:"peer",ID:Bt(e.ID),Addrs:n,Protocols:t}}};function Yy(r,e={}){return new fl(new URL(r),e)}var Wy=V("/ipns/");function jy(r){return he(r.subarray(0,Wy.byteLength),Wy)}var Tf=class{client;constructor(e){this.client=Yy(e)}async provide(e,t){}async*findProviders(e,t){yield*at(this.client.getProviders(e,t),n=>({id:n.ID,multiaddrs:n.Addrs,protocols:n.Protocols}))}async put(e,t,n){if(!jy(e))return;let i=Bo(e),o=dt(t);await this.client.putIPNS(i,o,n)}async get(e,t){if(!jy(e))throw new O("Not found","ERR_NOT_FOUND");let n=Bo(e);try{let i=await this.client.getIPNS(n,t);return sn(i)}catch(i){throw i.code==="ERR_BAD_RESPONSE"?new O("Not found","ERR_NOT_FOUND"):i}}async findPeer(e,t){let n=await Ii(this.client.getPeers(e,t));if(n!=null)return{id:n.ID,multiaddrs:n.Addrs??[]};throw new O("Not found","ERR_NOT_FOUND")}async*getClosestPeers(e,t){}};function Vs(r){return new Tf(new URL(r))}var Nf=class extends Error{type;code;constructor(e,t){super(e??"The operation was aborted"),this.type="aborted",this.name="AbortError",this.code=t??"ABORT_ERR"}};async function hl(r,e,t,n){let i=new Nf(n?.errorMessage,n?.errorCode);return t?.aborted===!0?Promise.reject(i):new Promise((o,s)=>{let a=u=>{try{if(n?.filter?.(u)===!1)return}catch(l){r.removeEventListener(e,a),t?.removeEventListener("abort",c),s(l);return}r.removeEventListener(e,a),t?.removeEventListener("abort",c),o(u)},c=()=>{r.removeEventListener(e,a),t?.removeEventListener("abort",c),s(i)};r.addEventListener(e,a),t?.addEventListener("abort",c)})}var pl=class extends Error{type;code;constructor(e,t){super(e??"The operation was aborted"),this.type="aborted",this.name="AbortError",this.code=t??"ABORT_ERR"}};async function Xy(r,e,t){if(e==null)return r;if(e.aborted)return Promise.reject(new pl(t?.errorMessage,t?.errorCode));let n,i=new pl(t?.errorMessage,t?.errorCode);try{return await Promise.race([r,new Promise((o,s)=>{n=()=>{s(i)},e.addEventListener("abort",n)})])}finally{n!=null&&e.removeEventListener("abort",n)}}var ml=class{deferred;signal;where;constructor(e,t){this.signal=t,this.deferred=_e(),this.where=e,this.onAbort=this.onAbort.bind(this),this.signal?.addEventListener("abort",this.onAbort)}onAbort(){this.deferred.reject(new An)}cleanup(){this.signal?.removeEventListener("abort",this.onAbort)}};function dA(){return`${parseInt(String(Math.random()*1e9),10).toString()}${Date.now()}`}var yl=class{id;fn;options;priority;recipients;status;timeline;controller;constructor(e,t,n=0){this.id=dA(),this.status="queued",this.fn=e,this.priority=n,this.options=t,this.recipients=[],this.timeline={created:Date.now()},this.controller=new AbortController,_a(1/0,this.controller.signal),this.onAbort=this.onAbort.bind(this)}abort(e){this.controller.abort(e)}onAbort(){this.recipients.reduce((t,n)=>t&&n.signal?.aborted===!0,!0)&&this.controller.abort(new An)}async join(e={}){let t=new ml(new Error("where").stack,e.signal);return this.recipients.push(t),e.signal?.addEventListener("abort",this.onAbort),t.deferred.promise}async run(){this.status="running",this.timeline.started=Date.now();try{this.controller.signal.throwIfAborted();let e=await Xy(this.fn({...this.options??{},signal:this.controller.signal}),this.controller.signal);this.recipients.forEach(t=>{t.deferred.resolve(e)}),this.status="complete"}catch(e){this.recipients.forEach(t=>{t.deferred.reject(e)}),this.status="errored"}finally{this.timeline.finished=Date.now(),this.cleanup()}}cleanup(){this.recipients.forEach(e=>{e.signal?.removeEventListener("abort",this.onAbort)})}};function fA(r,e,t){let n=0,i=r.length;for(;i>0;){let o=Math.trunc(i/2),s=n+o;t(r[s],e)<=0?(n=++s,i-=o+1):i=o}return n}var Ms=class extends Aa{concurrency;queue;pending;constructor(e={}){super(),this.concurrency=e.concurrency??Number.POSITIVE_INFINITY,this.pending=0,e.metricName!=null&&e.metrics?.registerMetricGroup(e.metricName,{calculate:()=>({size:this.queue.length,running:this.pending,queued:this.queue.length-this.pending})}),this.queue=[]}tryToStartAnother(){if(this.size===0)return queueMicrotask(()=>{this.safeDispatchEvent("empty")}),this.running===0&&queueMicrotask(()=>{this.safeDispatchEvent("idle")}),!1;if(this.pending<this.concurrency){let e;for(let t of this.queue)if(t.status==="queued"){e=t;break}return e==null?!1:(this.safeDispatchEvent("active"),this.pending++,e.run().finally(()=>{for(let t=0;t<this.queue.length;t++)if(this.queue[t]===e){this.queue.splice(t,1);break}this.pending--,this.tryToStartAnother(),this.safeDispatchEvent("next")}),!0)}return!1}enqueue(e){if(this.queue[this.size-1]?.priority>=e.priority){this.queue.push(e);return}let t=fA(this.queue,e,(n,i)=>i.priority-n.priority);this.queue.splice(t,0,e)}async add(e,t){t?.signal?.throwIfAborted();let n=new yl(e,t,t?.priority),i=n.join(t).then(o=>(this.safeDispatchEvent("completed",{detail:o}),o)).catch(o=>{throw this.safeDispatchEvent("error",{detail:o}),o});return this.enqueue(n),this.safeDispatchEvent("add"),this.tryToStartAnother(),i}clear(){this.queue.splice(0,this.queue.length)}abort(){this.queue.forEach(e=>{e.abort(new An)}),this.clear()}async onEmpty(e){this.size!==0&&await hl(this,"empty",e?.signal)}async onSizeLessThan(e,t){this.size<e||await hl(this,"next",t?.signal,{filter:()=>this.size<e})}async onIdle(e){this.pending===0&&this.size===0||await hl(this,"idle",e?.signal)}get size(){return this.queue.length}get queued(){return this.queue.length-this.pending}get running(){return this.pending}async*toGenerator(e){e?.signal?.throwIfAborted();let t=Kt({objectMode:!0}),n=c=>{c!=null?this.abort():this.clear(),t.end(c)},i=c=>{c.detail!=null&&t.push(c.detail)},o=c=>{n(c.detail)},s=()=>{n()},a=()=>{n(new O("Queue aborted","ERR_QUEUE_ABORTED"))};this.addEventListener("completed",i),this.addEventListener("error",o),this.addEventListener("idle",s),e?.signal?.addEventListener("abort",a);try{yield*t}finally{this.removeEventListener("completed",i),this.removeEventListener("error",o),this.removeEventListener("idle",s),e?.signal?.removeEventListener("abort",a),n()}}};var eg="/pin/",Zy="/pinned-block/",Cf=kn,Jy=1;function Qy(r){return r.version===0&&(r=r.toV1()),new Le(`${eg}${r.toString(Cf)}`)}var gl=class{datastore;blockstore;dagWalkers;constructor(e,t,n){this.datastore=e,this.blockstore=t,this.dagWalkers=n}async*add(e,t={}){let n=Qy(e);if(await this.datastore.has(n))throw new Error("Already pinned");let i=Math.round(t.depth??1/0);if(i<0)throw new Error("Depth must be greater than or equal to 0");let o=new Ms({concurrency:Jy});for await(let a of this.#e(e,o,{...t,depth:i}))await this.#t(a,c=>c.pinnedBy.find(u=>he(u,e.bytes))!=null?!1:(c.pinCount++,c.pinnedBy.push(e.bytes),!0),t),yield a;let s={depth:i,metadata:t.metadata??{}};await this.datastore.put(n,Kn(s),t)}async*#e(e,t,n){if(n.depth===-1)return;let i=this.dagWalkers[e.code];if(i==null)throw new Error(`No dag walker found for cid codec ${e.code}`);let o=await this.blockstore.get(e,n);yield e;for await(let s of i.walk(o))yield*await t.add(async()=>this.#e(s,t,{...n,depth:n.depth-1}))}async#t(e,t,n){let i=new Le(`${Zy}${Cf.encode(e.multihash.bytes)}`),o={pinCount:0,pinnedBy:[]};try{o=ut(await this.datastore.get(i,n))}catch(a){if(a.code!=="ERR_NOT_FOUND")throw a}if(t(o)){if(o.pinCount===0&&await this.datastore.has(i)){await this.datastore.delete(i);return}await this.datastore.put(i,Kn(o),n),n.onProgress?.(new M("helia:pin:add",e))}}async*rm(e,t={}){let n=Qy(e),i=await this.datastore.get(n,t),o=ut(i);await this.datastore.delete(n,t);let s=new Ms({concurrency:Jy});for await(let a of this.#e(e,s,{...t,depth:o.depth}))await this.#t(a,c=>(c.pinCount--,c.pinnedBy=c.pinnedBy.filter(u=>he(u,e.bytes)),!0),{...t,depth:o.depth}),yield a}async*ls(e={}){for await(let{key:t,value:n}of this.datastore.query({prefix:eg+(e.cid!=null?`${e.cid.toString(kn)}`:"")},e)){let i=F.parse(t.toString().substring(5),kn),o=ut(n);yield{cid:i,...o}}}async isPinned(e,t={}){let n=new Le(`${Zy}${Cf.encode(e.multihash.bytes)}`);return this.datastore.has(n,t)}};function Lf(r,e){let t={[Symbol.iterator]:()=>t,next:()=>{let n=r.next(),i=n.value;return n.done===!0||i==null?{done:!0,value:void 0}:{done:!1,value:e(i)}}};return t}var ko=class r{set;constructor(e){if(this.set=new Set,e!=null)for(let t of e)this.set.add(t.toString())}get size(){return this.set.size}[Symbol.iterator](){return this.values()}add(e){this.set.add(e.toString())}clear(){this.set.clear()}delete(e){this.set.delete(e.toString())}entries(){return Lf(this.set.entries(),e=>{let t=Bt(e[0]);return[t,t]})}forEach(e){this.set.forEach(t=>{let n=Bt(t);e(n,n,this)})}has(e){return this.set.has(e.toString())}values(){return Lf(this.set.values(),e=>Bt(e))}intersection(e){let t=new r;for(let n of e)this.has(n)&&t.add(n);return t}difference(e){let t=new r;for(let n of this)e.has(n)||t.add(n);return t}union(e){let t=new r;for(let n of e)t.add(n);for(let n of this)t.add(n);return t}};var wl=class{log;routers;constructor(e,t){this.log=e.logger.forComponent("helia:routing"),this.routers=t.routers??[]}async start(){await _n(...this.routers)}async stop(){await Sn(...this.routers)}async*findProviders(e,t={}){if(this.routers.length===0)throw new O("No content routers available","ERR_NO_ROUTERS_AVAILABLE");let n=new ko;for await(let i of Hr(...Ro(this.routers,"findProviders").map(o=>o.findProviders(e,t))))i!=null&&(n.has(i.id)||(n.add(i.id),yield i))}async provide(e,t={}){if(this.routers.length===0)throw new O("No content routers available","ERR_NO_ROUTERS_AVAILABLE");await Promise.all(Ro(this.routers,"provide").map(async n=>{await n.provide(e,t)}))}async put(e,t,n){await Promise.all(Ro(this.routers,"put").map(async i=>{await i.put(e,t,n)}))}async get(e,t){return Promise.any(Ro(this.routers,"get").map(async n=>n.get(e,t)))}async findPeer(e,t){if(this.routers.length===0)throw new O("No peer routers available","ERR_NO_ROUTERS_AVAILABLE");let n=this,i=Hr(...Ro(this.routers,"findPeer").map(o=>async function*(){try{yield await o.findPeer(e,t)}catch(s){n.log.error(s)}}()));for await(let o of i)if(o!=null)return o;throw new O("Could not find peer in routing","ERR_NOT_FOUND")}async*getClosestPeers(e,t={}){if(this.routers.length===0)throw new O("No peer routers available","ERR_NO_ROUTERS_AVAILABLE");let n=new ko;for await(let i of Hr(...Ro(this.routers,"getClosestPeers").map(o=>o.getClosestPeers(e,t))))i!=null&&(n.has(i.id)||(n.add(i.id),yield i))}};function Ro(r,e){return r.filter(t=>t[e]!=null)}var Gn={},To=r=>{r.addEventListener("message",e=>{To.dispatchEvent("message",r,e)}),r.port!=null&&r.port.addEventListener("message",e=>{To.dispatchEvent("message",r,e)})};To.addEventListener=(r,e)=>{Gn[r]==null&&(Gn[r]=[]),Gn[r].push(e)};To.removeEventListener=(r,e)=>{Gn[r]!=null&&(Gn[r]=Gn[r].filter(t=>t===e))};To.dispatchEvent=function(r,e,t){Gn[r]!=null&&Gn[r].forEach(n=>n(e,t))};var Uf=To;var Df="lock:worker:request-read",Of="lock:worker:release-read",Pf="lock:master:grant-read",Ff="lock:worker:request-write",Vf="lock:worker:release-write",Mf="lock:master:grant-write";var tg=(r=21)=>Math.random().toString().substring(2);var rg=(r,e,t,n,i)=>(o,s)=>{if(s.data.type!==t)return;let a={type:s.data.type,name:s.data.name,identifier:s.data.identifier};r.dispatchEvent(new MessageEvent(e,{data:{name:a.name,handler:async()=>{o.postMessage({type:i,name:a.name,identifier:a.identifier}),await new Promise(c=>{let u=l=>{if(l==null||l.data==null)return;let d={type:l.data.type,name:l.data.name,identifier:l.data.identifier};d.type===n&&d.identifier===a.identifier&&(o.removeEventListener("message",u),c())};o.addEventListener("message",u)})}}}))},ng=(r,e,t,n)=>async()=>{let i=tg();return globalThis.postMessage({type:e,identifier:i,name:r}),new Promise(o=>{let s=a=>{if(a==null||a.data==null)return;let c={type:a.data.type,identifier:a.data.identifier};c.type===t&&c.identifier===i&&(globalThis.removeEventListener("message",s),o(()=>{globalThis.postMessage({type:n,identifier:i,name:r})}))};globalThis.addEventListener("message",s)})},hA={singleProcess:!1},ig=r=>{if(r=Object.assign({},hA,r),!!globalThis.document||r.singleProcess){let t=new EventTarget;return Uf.addEventListener("message",rg(t,"requestReadLock",Df,Of,Pf)),Uf.addEventListener("message",rg(t,"requestWriteLock",Ff,Vf,Mf)),t}return{isWorker:!0,readLock:t=>ng(t,Df,Pf,Of),writeLock:t=>ng(t,Ff,Mf,Vf)}};var Bi={},qn;async function Hf(r,e){let t,n=new Promise(i=>{t=i});return r.add(async()=>Ps((async()=>{await new Promise(i=>{t(()=>{i()})})})(),{milliseconds:e.timeout})),n}var pA=(r,e)=>{if(qn.isWorker===!0)return{readLock:qn.readLock(r,e),writeLock:qn.writeLock(r,e)};let t=new nt({concurrency:1}),n;return{async readLock(){if(n!=null)return Hf(n,e);n=new nt({concurrency:e.concurrency,autoStart:!1});let i=n,o=Hf(n,e);return t.add(async()=>{i.start(),await i.onIdle().then(()=>{n===i&&(n=null)})}),o},async writeLock(){return n=null,Hf(t,e)}}},mA={name:"lock",concurrency:1/0,timeout:846e5,singleProcess:!1};function $f(r){let e=Object.assign({},mA,r);return qn==null&&(qn=ig(e),qn.isWorker!==!0&&(qn.addEventListener("requestReadLock",t=>{Bi[t.data.name]!=null&&Bi[t.data.name].readLock().then(async n=>t.data.handler().finally(()=>{n()}))}),qn.addEventListener("requestWriteLock",async t=>{Bi[t.data.name]!=null&&Bi[t.data.name].writeLock().then(async n=>t.data.handler().finally(()=>{n()}))}))),Bi[e.name]==null&&(Bi[e.name]=pA(e.name,e)),Bi[e.name]}var El=class{lock;child;pins;started;constructor(e,t,n={}){this.child=e,this.pins=t,this.lock=$f({singleProcess:n.holdGcLock}),this.started=!1}isStarted(){return this.started}async start(){await _n(this.child),this.started=!0}async stop(){await Sn(this.child),this.started=!1}unwrap(){return this.child}async put(e,t,n={}){let i=await this.lock.readLock();try{return await this.child.put(e,t,n)}finally{i()}}async*putMany(e,t={}){let n=await this.lock.readLock();try{yield*this.child.putMany(e,t)}finally{n()}}async get(e,t={}){let n=await this.lock.readLock();try{return await this.child.get(e,t)}finally{n()}}async*getMany(e,t={}){let n=await this.lock.readLock();try{yield*this.child.getMany(e,t)}finally{n()}}async delete(e,t={}){let n=await this.lock.writeLock();try{if(await this.pins.isPinned(e))throw new Error("CID was pinned");await this.child.delete(e,t)}finally{n()}}async*deleteMany(e,t={}){let n=await this.lock.writeLock();try{let i=this;yield*this.child.deleteMany(async function*(){for await(let o of e){if(await i.pins.isPinned(o))throw new Error("CID was pinned");yield o}}(),t)}finally{n()}}async has(e,t={}){let n=await this.lock.readLock();try{return await this.child.has(e,t)}finally{n()}}async*getAll(e={}){let t=await this.lock.readLock();try{yield*this.child.getAll(e)}finally{t()}}};var og=42;function yA(r){return r instanceof ArrayBuffer?new Uint8Array(r,0,r.byteLength):r}function gA(r){if(r.asCID!==r&&r["/"]!==r.bytes)return null;let e=F.asCID(r);if(!e)return null;let t=new Uint8Array(e.bytes.byteLength+1);return t.set(e.bytes,1),[new R(w.tag,og),new R(w.bytes,t)]}function wA(){throw new Error("`undefined` is not supported by the IPLD Data Model and cannot be encoded")}function EA(r){if(Number.isNaN(r))throw new Error("`NaN` is not supported by the IPLD Data Model and cannot be encoded");if(r===1/0||r===-1/0)throw new Error("`Infinity` and `-Infinity` is not supported by the IPLD Data Model and cannot be encoded");return null}var zf={float64:!0,typeEncoders:{Object:gA,undefined:wA,number:EA}},UU={...zf,typeEncoders:{...zf.typeEncoders}};function xA(r){if(r[0]!==0)throw new Error("Invalid CID for CBOR tag 42; expected leading 0x00");return F.decode(r.subarray(1))}var xl={allowIndefinite:!1,coerceUndefinedToNull:!0,allowNaN:!1,allowInfinity:!1,allowBigInt:!0,strict:!0,useMaps:!1,rejectDuplicateMapKeys:!0,tags:[]};xl.tags[og]=xA;var DU={...xl,tags:xl.tags.slice()};var Yn=113,Hs=r=>Kn(r,zf),ki=r=>ut(yA(r),xl);var Kf=class extends Array{constructor(){super(),this.inRecursive=[]}prefix(e){let t=this.inRecursive[this.inRecursive.length-1];t&&(t.type===w.array&&(t.elements++,t.elements!==1&&e.push([44])),t.type===w.map&&(t.elements++,t.elements!==1&&(t.elements%2===1?e.push([44]):e.push([58]))))}[w.uint.major](e,t){this.prefix(e);let n=String(t.value),i=[];for(let o=0;o<n.length;o++)i[o]=n.charCodeAt(o);e.push(i)}[w.negint.major](e,t){this[w.uint.major](e,t)}[w.bytes.major](e,t){throw new Error(`${nn} unsupported type: Uint8Array`)}[w.string.major](e,t){this.prefix(e);let n=jc(JSON.stringify(t.value));e.push(n.length>32?Ss(n):n)}[w.array.major](e,t){this.prefix(e),this.inRecursive.push({type:w.array,elements:0}),e.push([91])}[w.map.major](e,t){this.prefix(e),this.inRecursive.push({type:w.map,elements:0}),e.push([123])}[w.tag.major](e,t){}[w.float.major](e,t){if(t.type.name==="break"){let s=this.inRecursive.pop();if(s){if(s.type===w.array)e.push([93]);else if(s.type===w.map)e.push([125]);else throw new Error("Unexpected recursive type; this should not happen!");return}throw new Error("Unexpected break; this should not happen!")}if(t.value===void 0)throw new Error(`${nn} unsupported type: undefined`);if(this.prefix(e),t.type.name==="true"){e.push([116,114,117,101]);return}else if(t.type.name==="false"){e.push([102,97,108,115,101]);return}else if(t.type.name==="null"){e.push([110,117,108,108]);return}let n=String(t.value),i=[],o=!1;for(let s=0;s<n.length;s++)i[s]=n.charCodeAt(s),!o&&(i[s]===46||i[s]===101||i[s]===69)&&(o=!0);o||(i.push(46),i.push(48)),e.push(i)}};function bA(r,e){if(Array.isArray(r[0])||Array.isArray(e[0]))throw new Error(`${nn} complex map keys are not supported`);let t=r[0],n=e[0];if(t.type!==w.string||n.type!==w.string)throw new Error(`${nn} non-string map keys are not supported`);if(t<n)return-1;if(t>n)return 1;throw new Error(`${nn} unexpected duplicate map keys, this is not supported`)}var vA={addBreakTokens:!0,mapSorter:bA};function zs(r,e){return e=Object.assign({},vA,e),xf(r,new Kf,e)}var Wn=class{constructor(e,t={}){this._pos=0,this.data=e,this.options=t,this.modeStack=["value"],this.lastToken=""}pos(){return this._pos}done(){return this._pos>=this.data.length}ch(){return this.data[this._pos]}currentMode(){return this.modeStack[this.modeStack.length-1]}skipWhitespace(){let e=this.ch();for(;e===32||e===9||e===13||e===10;)e=this.data[++this._pos]}expect(e){if(this.data.length-this._pos<e.length)throw new Error(`${G} unexpected end of input at position ${this._pos}`);for(let t=0;t<e.length;t++)if(this.data[this._pos++]!==e[t])throw new Error(`${G} unexpected token at position ${this._pos}, expected to find '${String.fromCharCode(...e)}'`)}parseNumber(){let e=this._pos,t=!1,n=!1,i=a=>{for(;!this.done();){let c=this.ch();if(a.includes(c))this._pos++;else break}};if(this.ch()===45&&(t=!0,this._pos++),this.ch()===48)if(this._pos++,this.ch()===46)this._pos++,n=!0;else return new R(w.uint,0,this._pos-e);if(i([48,49,50,51,52,53,54,55,56,57]),t&&this._pos===e+1)throw new Error(`${G} unexpected token at position ${this._pos}`);if(!this.done()&&this.ch()===46){if(n)throw new Error(`${G} unexpected token at position ${this._pos}`);n=!0,this._pos++,i([48,49,50,51,52,53,54,55,56,57])}!this.done()&&(this.ch()===101||this.ch()===69)&&(n=!0,this._pos++,!this.done()&&(this.ch()===43||this.ch()===45)&&this._pos++,i([48,49,50,51,52,53,54,55,56,57]));let o=String.fromCharCode.apply(null,this.data.subarray(e,this._pos)),s=parseFloat(o);return n?new R(w.float,s,this._pos-e):this.options.allowBigInt!==!0||Number.isSafeInteger(s)?new R(s>=0?w.uint:w.negint,s,this._pos-e):new R(s>=0?w.uint:w.negint,BigInt(o),this._pos-e)}parseString(){if(this.ch()!==34)throw new Error(`${G} unexpected character at position ${this._pos}; this shouldn't happen`);this._pos++;for(let o=this._pos,s=0;o<this.data.length&&s<65536;o++,s++){let a=this.data[o];if(a===92||a<32||a>=128)break;if(a===34){let c=String.fromCharCode.apply(null,this.data.subarray(this._pos,o));return this._pos=o+1,new R(w.string,c,s)}}let e=this._pos,t=[],n=()=>{if(this._pos+4>=this.data.length)throw new Error(`${G} unexpected end of unicode escape sequence at position ${this._pos}`);let o=0;for(let s=0;s<4;s++){let a=this.ch();if(a>=48&&a<=57)a-=48;else if(a>=97&&a<=102)a=a-97+10;else if(a>=65&&a<=70)a=a-65+10;else throw new Error(`${G} unexpected unicode escape character at position ${this._pos}`);o=o*16+a,this._pos++}return o},i=()=>{let o=this.ch(),s=null,a=o>239?4:o>223?3:o>191?2:1;if(this._pos+a>this.data.length)throw new Error(`${G} unexpected unicode sequence at position ${this._pos}`);let c,u,l,d;switch(a){case 1:o<128&&(s=o);break;case 2:c=this.data[this._pos+1],(c&192)===128&&(d=(o&31)<<6|c&63,d>127&&(s=d));break;case 3:c=this.data[this._pos+1],u=this.data[this._pos+2],(c&192)===128&&(u&192)===128&&(d=(o&15)<<12|(c&63)<<6|u&63,d>2047&&(d<55296||d>57343)&&(s=d));break;case 4:c=this.data[this._pos+1],u=this.data[this._pos+2],l=this.data[this._pos+3],(c&192)===128&&(u&192)===128&&(l&192)===128&&(d=(o&15)<<18|(c&63)<<12|(u&63)<<6|l&63,d>65535&&d<1114112&&(s=d))}s===null?(s=65533,a=1):s>65535&&(s-=65536,t.push(s>>>10&1023|55296),s=56320|s&1023),t.push(s),this._pos+=a};for(;!this.done();){let o=this.ch(),s;switch(o){case 92:if(this._pos++,this.done())throw new Error(`${G} unexpected string termination at position ${this._pos}`);switch(s=this.ch(),this._pos++,s){case 34:case 39:case 92:case 47:t.push(s);break;case 98:t.push(8);break;case 116:t.push(9);break;case 110:t.push(10);break;case 102:t.push(12);break;case 114:t.push(13);break;case 117:t.push(n());break;default:throw new Error(`${G} unexpected string escape character at position ${this._pos}`)}break;case 34:return this._pos++,new R(w.string,ff(t),this._pos-e);default:if(o<32)throw new Error(`${G} invalid control character at position ${this._pos}`);o<128?(t.push(o),this._pos++):i()}}throw new Error(`${G} unexpected end of string at position ${this._pos}`)}parseValue(){switch(this.ch()){case 123:return this.modeStack.push("obj-start"),this._pos++,new R(w.map,1/0,1);case 91:return this.modeStack.push("array-start"),this._pos++,new R(w.array,1/0,1);case 34:return this.parseString();case 110:return this.expect([110,117,108,108]),new R(w.null,null,4);case 102:return this.expect([102,97,108,115,101]),new R(w.false,!1,5);case 116:return this.expect([116,114,117,101]),new R(w.true,!0,4);case 45:case 48:case 49:case 50:case 51:case 52:case 53:case 54:case 55:case 56:case 57:return this.parseNumber();default:throw new Error(`${G} unexpected character at position ${this._pos}`)}}next(){switch(this.skipWhitespace(),this.currentMode()){case"value":return this.modeStack.pop(),this.parseValue();case"array-value":{if(this.modeStack.pop(),this.ch()===93)return this._pos++,this.skipWhitespace(),new R(w.break,void 0,1);if(this.ch()!==44)throw new Error(`${G} unexpected character at position ${this._pos}, was expecting array delimiter but found '${String.fromCharCode(this.ch())}'`);return this._pos++,this.modeStack.push("array-value"),this.skipWhitespace(),this.parseValue()}case"array-start":return this.modeStack.pop(),this.ch()===93?(this._pos++,this.skipWhitespace(),new R(w.break,void 0,1)):(this.modeStack.push("array-value"),this.skipWhitespace(),this.parseValue());case"obj-key":if(this.ch()===125)return this.modeStack.pop(),this._pos++,this.skipWhitespace(),new R(w.break,void 0,1);if(this.ch()!==44)throw new Error(`${G} unexpected character at position ${this._pos}, was expecting object delimiter but found '${String.fromCharCode(this.ch())}'`);this._pos++,this.skipWhitespace();case"obj-start":{if(this.modeStack.pop(),this.ch()===125)return this._pos++,this.skipWhitespace(),new R(w.break,void 0,1);let e=this.parseString();if(this.skipWhitespace(),this.ch()!==58)throw new Error(`${G} unexpected character at position ${this._pos}, was expecting key/value delimiter ':' but found '${String.fromCharCode(this.ch())}'`);return this._pos++,this.modeStack.push("obj-value"),e}case"obj-value":return this.modeStack.pop(),this.modeStack.push("obj-key"),this.skipWhitespace(),this.parseValue();default:throw new Error(`${G} unexpected parse state at position ${this._pos}; this shouldn't happen`)}}};function Ks(r,e){return e=Object.assign({tokenizer:new Wn(r,e)},e),ut(r,e)}function AA(r){return r instanceof ArrayBuffer?new Uint8Array(r,0,r.byteLength):r}function _A(r){if(r.asCID!==r&&r["/"]!==r.bytes)return null;let e=F.asCID(r);if(!e)return null;let t=e.toString();return[new R(w.map,1/0,1),new R(w.string,"/",1),new R(w.string,t,t.length),new R(w.break,void 0,1)]}function bl(r){let e=yr.encode(r).slice(1);return[new R(w.map,1/0,1),new R(w.string,"/",1),new R(w.map,1/0,1),new R(w.string,"bytes",5),new R(w.string,e,e.length),new R(w.break,void 0,1),new R(w.break,void 0,1)]}function ar(r){return bl(new Uint8Array(r.buffer,r.byteOffset,r.byteLength))}function SA(r){return bl(new Uint8Array(r))}function IA(){throw new Error("`undefined` is not supported by the IPLD Data Model and cannot be encoded")}function BA(r){if(Number.isNaN(r))throw new Error("`NaN` is not supported by the IPLD Data Model and cannot be encoded");if(r===1/0||r===-1/0)throw new Error("`Infinity` and `-Infinity` is not supported by the IPLD Data Model and cannot be encoded");return null}var kA={typeEncoders:{Object:_A,Buffer:bl,Uint8Array:bl,Int8Array:ar,Uint16Array:ar,Int16Array:ar,Uint32Array:ar,Int32Array:ar,Float32Array:ar,Float64Array:ar,Uint8ClampedArray:ar,BigInt64Array:ar,BigUint64Array:ar,DataView:ar,ArrayBuffer:SA,undefined:IA,number:BA}},Gf=class extends Wn{constructor(e,t){super(e,t),this.tokenBuffer=[]}done(){return this.tokenBuffer.length===0&&super.done()}_next(){return this.tokenBuffer.length>0?this.tokenBuffer.pop():super.next()}next(){let e=this._next();if(e.type===w.map){let t=this._next();if(t.type===w.string&&t.value==="/"){let n=this._next();if(n.type===w.string){if(this._next().type!==w.break)throw new Error("Invalid encoded CID form");return this.tokenBuffer.push(n),new R(w.tag,42,0)}if(n.type===w.map){let i=this._next();if(i.type===w.string&&i.value==="bytes"){let o=this._next();if(o.type===w.string){for(let a=0;a<2;a++)if(this._next().type!==w.break)throw new Error("Invalid encoded Bytes form");let s=yr.decode(`m${o.value}`);return new R(w.bytes,s,o.value.length)}this.tokenBuffer.push(o)}this.tokenBuffer.push(i)}this.tokenBuffer.push(n)}this.tokenBuffer.push(t)}return e}},qf={allowIndefinite:!1,allowUndefined:!1,allowNaN:!1,allowInfinity:!1,allowBigInt:!0,strict:!0,useMaps:!1,rejectDuplicateMapKeys:!0,tags:[]};qf.tags[42]=F.parse;var jn=297,ag=r=>zs(r,kA),vl=r=>{let e=AA(r),t=Object.assign(qf,{tokenizer:new Gf(e,qf)});return Ks(e,t)};var JU=new TextDecoder;var QU=new TextEncoder;var Oe={};Be(Oe,{code:()=>ve,createLink:()=>gg,createNode:()=>yg,decode:()=>Se,encode:()=>ce,name:()=>VA,prepare:()=>Te,validate:()=>jf});var RA=new TextDecoder;function Yf(r,e){let t=0;for(let n=0;;n+=7){if(n>=64)throw new Error("protobuf: varint overflow");if(e>=r.length)throw new Error("protobuf: unexpected end of data");let i=r[e++];if(t+=n<28?(i&127)<<n:(i&127)*2**n,i<128)break}return[t,e]}function _l(r,e){let t;[t,e]=Yf(r,e);let n=e+t;if(t<0||n<0)throw new Error("protobuf: invalid length");if(n>r.length)throw new Error("protobuf: unexpected end of data");return[r.subarray(e,n),n]}function cg(r,e){let t;return[t,e]=Yf(r,e),[t&7,t>>3,e]}function TA(r){let e={},t=r.length,n=0;for(;n<t;){let i,o;if([i,o,n]=cg(r,n),o===1){if(e.Hash)throw new Error("protobuf: (PBLink) duplicate Hash section");if(i!==2)throw new Error(`protobuf: (PBLink) wrong wireType (${i}) for Hash`);if(e.Name!==void 0)throw new Error("protobuf: (PBLink) invalid order, found Name before Hash");if(e.Tsize!==void 0)throw new Error("protobuf: (PBLink) invalid order, found Tsize before Hash");[e.Hash,n]=_l(r,n)}else if(o===2){if(e.Name!==void 0)throw new Error("protobuf: (PBLink) duplicate Name section");if(i!==2)throw new Error(`protobuf: (PBLink) wrong wireType (${i}) for Name`);if(e.Tsize!==void 0)throw new Error("protobuf: (PBLink) invalid order, found Tsize before Name");let s;[s,n]=_l(r,n),e.Name=RA.decode(s)}else if(o===3){if(e.Tsize!==void 0)throw new Error("protobuf: (PBLink) duplicate Tsize section");if(i!==0)throw new Error(`protobuf: (PBLink) wrong wireType (${i}) for Tsize`);[e.Tsize,n]=Yf(r,n)}else throw new Error(`protobuf: (PBLink) invalid fieldNumber, expected 1, 2 or 3, got ${o}`)}if(n>t)throw new Error("protobuf: (PBLink) unexpected end of data");return e}function lg(r){let e=r.length,t=0,n,i=!1,o;for(;t<e;){let a,c;if([a,c,t]=cg(r,t),a!==2)throw new Error(`protobuf: (PBNode) invalid wireType, expected 2, got ${a}`);if(c===1){if(o)throw new Error("protobuf: (PBNode) duplicate Data section");[o,t]=_l(r,t),n&&(i=!0)}else if(c===2){if(i)throw new Error("protobuf: (PBNode) duplicate Links section");n||(n=[]);let u;[u,t]=_l(r,t),n.push(TA(u))}else throw new Error(`protobuf: (PBNode) invalid fieldNumber, expected 1 or 2, got ${c}`)}if(t>e)throw new Error("protobuf: (PBNode) unexpected end of data");let s={};return o&&(s.Data=o),s.Links=n||[],s}var dg=new TextEncoder,ug=2**32,NA=2**31;function CA(r,e){let t=e.length;if(typeof r.Tsize=="number"){if(r.Tsize<0)throw new Error("Tsize cannot be negative");if(!Number.isSafeInteger(r.Tsize))throw new Error("Tsize too large for encoding");t=Gs(e,t,r.Tsize)-1,e[t]=24}if(typeof r.Name=="string"){let n=dg.encode(r.Name);t-=n.length,e.set(n,t),t=Gs(e,t,n.length)-1,e[t]=18}return r.Hash&&(t-=r.Hash.length,e.set(r.Hash,t),t=Gs(e,t,r.Hash.length)-1,e[t]=10),e.length-t}function fg(r){let e=UA(r),t=new Uint8Array(e),n=e;if(r.Data&&(n-=r.Data.length,t.set(r.Data,n),n=Gs(t,n,r.Data.length)-1,t[n]=10),r.Links)for(let i=r.Links.length-1;i>=0;i--){let o=CA(r.Links[i],t.subarray(0,n));n-=o,n=Gs(t,n,o)-1,t[n]=18}return t}function LA(r){let e=0;if(r.Hash){let t=r.Hash.length;e+=1+t+No(t)}if(typeof r.Name=="string"){let t=dg.encode(r.Name).length;e+=1+t+No(t)}return typeof r.Tsize=="number"&&(e+=1+No(r.Tsize)),e}function UA(r){let e=0;if(r.Data){let t=r.Data.length;e+=1+t+No(t)}if(r.Links)for(let t of r.Links){let n=LA(t);e+=1+n+No(n)}return e}function Gs(r,e,t){e-=No(t);let n=e;for(;t>=NA;)r[e++]=t&127|128,t/=128;for(;t>=128;)r[e++]=t&127|128,t>>>=7;return r[e]=t,n}function No(r){return r%2===0&&r++,Math.floor((DA(r)+6)/7)}function DA(r){let e=0;return r>=ug&&(r=Math.floor(r/ug),e=32),r>=65536&&(r>>>=16,e+=16),r>=256&&(r>>>=8,e+=8),e+OA[r]}var OA=[0,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8];var PA=["Data","Links"],FA=["Hash","Name","Tsize"],Wf=new TextEncoder;function pg(r,e){if(r===e)return 0;let t=r.Name?Wf.encode(r.Name):[],n=e.Name?Wf.encode(e.Name):[],i=t.length,o=n.length;for(let s=0,a=Math.min(i,o);s<a;++s)if(t[s]!==n[s]){i=t[s],o=n[s];break}return i<o?-1:o<i?1:0}function hg(r,e){return!Object.keys(r).some(t=>!e.includes(t))}function mg(r){if(typeof r.asCID=="object"){let t=F.asCID(r);if(!t)throw new TypeError("Invalid DAG-PB form");return{Hash:t}}if(typeof r!="object"||Array.isArray(r))throw new TypeError("Invalid DAG-PB form");let e={};if(r.Hash){let t=F.asCID(r.Hash);try{t||(typeof r.Hash=="string"?t=F.parse(r.Hash):r.Hash instanceof Uint8Array&&(t=F.decode(r.Hash)))}catch(n){throw new TypeError(`Invalid DAG-PB form: ${n.message}`)}t&&(e.Hash=t)}if(!e.Hash)throw new TypeError("Invalid DAG-PB form");return typeof r.Name=="string"&&(e.Name=r.Name),typeof r.Tsize=="number"&&(e.Tsize=r.Tsize),e}function Te(r){if((r instanceof Uint8Array||typeof r=="string")&&(r={Data:r}),typeof r!="object"||Array.isArray(r))throw new TypeError("Invalid DAG-PB form");let e={};if(r.Data!==void 0)if(typeof r.Data=="string")e.Data=Wf.encode(r.Data);else if(r.Data instanceof Uint8Array)e.Data=r.Data;else throw new TypeError("Invalid DAG-PB form");if(r.Links!==void 0)if(Array.isArray(r.Links))e.Links=r.Links.map(mg),e.Links.sort(pg);else throw new TypeError("Invalid DAG-PB form");else e.Links=[];return e}function jf(r){if(!r||typeof r!="object"||Array.isArray(r)||r instanceof Uint8Array||r["/"]&&r["/"]===r.bytes)throw new TypeError("Invalid DAG-PB form");if(!hg(r,PA))throw new TypeError("Invalid DAG-PB form (extraneous properties)");if(r.Data!==void 0&&!(r.Data instanceof Uint8Array))throw new TypeError("Invalid DAG-PB form (Data must be bytes)");if(!Array.isArray(r.Links))throw new TypeError("Invalid DAG-PB form (Links must be a list)");for(let e=0;e<r.Links.length;e++){let t=r.Links[e];if(!t||typeof t!="object"||Array.isArray(t)||t instanceof Uint8Array||t["/"]&&t["/"]===t.bytes)throw new TypeError("Invalid DAG-PB form (bad link)");if(!hg(t,FA))throw new TypeError("Invalid DAG-PB form (extraneous properties on link)");if(t.Hash===void 0)throw new TypeError("Invalid DAG-PB form (link must have a Hash)");if(t.Hash==null||!t.Hash["/"]||t.Hash["/"]!==t.Hash.bytes)throw new TypeError("Invalid DAG-PB form (link Hash must be a CID)");if(t.Name!==void 0&&typeof t.Name!="string")throw new TypeError("Invalid DAG-PB form (link Name must be a string)");if(t.Tsize!==void 0){if(typeof t.Tsize!="number"||t.Tsize%1!==0)throw new TypeError("Invalid DAG-PB form (link Tsize must be an integer)");if(t.Tsize<0)throw new TypeError("Invalid DAG-PB form (link Tsize cannot be negative)")}if(e>0&&pg(t,r.Links[e-1])===-1)throw new TypeError("Invalid DAG-PB form (links must be sorted by Name bytes)")}}function yg(r,e=[]){return Te({Data:r,Links:e})}function gg(r,e,t){return mg({Hash:t,Name:r,Tsize:e})}function wg(r){return r instanceof ArrayBuffer?new Uint8Array(r,0,r.byteLength):r}var VA="dag-pb",ve=112;function ce(r){jf(r);let e={};return r.Links&&(e.Links=r.Links.map(t=>{let n={};return t.Hash&&(n.Hash=t.Hash.bytes),t.Name!==void 0&&(n.Name=t.Name),t.Tsize!==void 0&&(n.Tsize=t.Tsize),n})),r.Data&&(e.Data=r.Data),fg(e)}function Se(r){let e=wg(r),t=lg(e),n={};return t.Data&&(n.Data=t.Data),t.Links&&(n.Links=t.Links.map(i=>{let o={};try{o.Hash=F.decode(i.Hash)}catch{}if(!o.Hash)throw new Error("Invalid Hash field found in link, expected CID");return i.Name!==void 0&&(o.Name=i.Name),i.Tsize!==void 0&&(o.Tsize=i.Tsize),o})),n}var MA={codec:ve,*walk(r){yield*Se(r).Links.map(t=>t.Hash)}},HA={codec:Ae,*walk(){}},Eg=42,$A={codec:Yn,*walk(r){let e=[],t=[];t[Eg]=n=>{if(n[0]!==0)throw new Error("Invalid CID for CBOR tag 42; expected leading 0x00");let i=F.decode(n.subarray(1));return e.push(i),i},ut(r,{tags:t}),yield*e}},Xf=class extends Wn{tokenBuffer;constructor(e,t){super(e,t),this.tokenBuffer=[]}done(){return this.tokenBuffer.length===0&&super.done()}_next(){return this.tokenBuffer.length>0?this.tokenBuffer.pop():super.next()}next(){let e=this._next();if(e.type===w.map){let t=this._next();if(t.type===w.string&&t.value==="/"){let n=this._next();if(n.type===w.string){if(this._next().type!==w.break)throw new Error("Invalid encoded CID form");return this.tokenBuffer.push(n),new R(w.tag,42,0)}if(n.type===w.map){let i=this._next();if(i.type===w.string&&i.value==="bytes"){let o=this._next();if(o.type===w.string){for(let a=0;a<2;a++)if(this._next().type!==w.break)throw new Error("Invalid encoded Bytes form");let s=yr.decode(`m${o.value}`);return new R(w.bytes,s,o.value.length)}this.tokenBuffer.push(o)}this.tokenBuffer.push(i)}this.tokenBuffer.push(n)}this.tokenBuffer.push(t)}return e}},zA={codec:jn,*walk(r){let e=[],t=[];t[Eg]=n=>{let i=F.parse(n);return e.push(i),i},Ks(r,{tags:t,tokenizer:new Xf(r,{tags:t,allowIndefinite:!0,allowUndefined:!0,allowNaN:!0,allowInfinity:!0,allowBigInt:!0,strict:!1,rejectDuplicateMapKeys:!1})}),yield*e}},KA={codec:Rn,*walk(){}};function xg(r=[]){let e={};return[MA,HA,$A,zA,KA,...r].forEach(t=>{e[t.codec]=t}),e}var Zf=new Le("/version"),bg=1;async function vg(r){if(!await r.has(Zf)){await r.put(Zf,V(`${bg}`));return}let e=await r.get(Zf),t=Z(e);if(parseInt(t,10)!==bg)throw new Error("Unknown datastore version, a datastore migration may be required")}function Ag(r=[]){let e={};return[fe,Cu,et,...r].forEach(t=>{e[t.code]=t}),e}var Sr=class{has(e,t){return Promise.reject(new Error(".has is not implemented"))}put(e,t,n){return Promise.reject(new Error(".put is not implemented"))}async*putMany(e,t){for await(let{cid:n,block:i}of e)await this.put(n,i,t),yield n}get(e,t){return Promise.reject(new Error(".get is not implemented"))}async*getMany(e,t){for await(let n of e)yield{cid:n,block:await this.get(n,t)}}delete(e,t){return Promise.reject(new Error(".delete is not implemented"))}async*deleteMany(e,t){for await(let n of e)await this.delete(n,t),yield n}async*getAll(e){throw new Error(".getAll is not implemented")}};var Ri={};Be(Ri,{abortedError:()=>jA,closeFailedError:()=>qA,deleteFailedError:()=>Qf,getFailedError:()=>YA,hasFailedError:()=>WA,notFoundError:()=>Xn,openFailedError:()=>GA,putFailedError:()=>Jf});var an=Q(Ce(),1);function GA(r){return r=r??new Error("Open failed"),(0,an.default)(r,"ERR_OPEN_FAILED")}function qA(r){return r=r??new Error("Close failed"),(0,an.default)(r,"ERR_CLOSE_FAILED")}function Jf(r){return r=r??new Error("Put failed"),(0,an.default)(r,"ERR_PUT_FAILED")}function YA(r){return r=r??new Error("Get failed"),(0,an.default)(r,"ERR_GET_FAILED")}function Qf(r){return r=r??new Error("Delete failed"),(0,an.default)(r,"ERR_DELETE_FAILED")}function WA(r){return r=r??new Error("Has failed"),(0,an.default)(r,"ERR_HAS_FAILED")}function Xn(r){return r=r??new Error("Not Found"),(0,an.default)(r,"ERR_NOT_FOUND")}function jA(r){return r=r??new Error("Aborted"),(0,an.default)(r,"ERR_ABORTED")}var _g=0,Sl=class extends Sr{put(e){return e}get(e){if(e.code===_g)return e.multihash.digest;throw Xn()}has(e){return e.code===_g}delete(){}*getAll(){}};function XA(r){return r[Symbol.asyncIterator]!=null}function ZA(r,e){if(XA(r))return async function*(){for await(let a of r)await e(a)&&(yield a)}();let t=Hi(r),{value:n,done:i}=t.next();if(i===!0)return function*(){}();let o=e(n);if(typeof o.then=="function")return async function*(){await o&&(yield n);for await(let a of t)await e(a)&&(yield a)}();let s=e;return function*(){o===!0&&(yield n);for(let a of t)s(a)&&(yield a)}()}var bt=ZA;var JA=oe("blockstore:core:tiered"),qs=class extends Sr{stores;constructor(e){super(),this.stores=e.slice()}async put(e,t,n){try{return await Promise.all(this.stores.map(async i=>{await i.put(e,t,n)})),e}catch(i){throw Jf(i)}}async get(e,t){for(let n of this.stores)try{let i=await n.get(e,t);if(i!=null)return i}catch(i){JA.error(i)}throw Xn()}async has(e,t){for(let n of this.stores)if(await n.has(e,t))return!0;return!1}async delete(e,t){try{await Promise.all(this.stores.map(async n=>{await n.delete(e,t)}))}catch(n){throw Qf(n)}}async*putMany(e,t={}){let n,i=this.stores.map(o=>{let s=Kt({objectMode:!0});return Jt(o.putMany(s,t)).catch(a=>{n=a}),s});try{for await(let o of e){if(n!=null)throw n;i.forEach(s=>s.push(o)),yield o.cid}}finally{i.forEach(o=>o.end())}}async*deleteMany(e,t={}){let n,i=this.stores.map(o=>{let s=Kt({objectMode:!0});return Jt(o.deleteMany(s,t)).catch(a=>{n=a}),s});try{for await(let o of e){if(n!=null)throw n;i.forEach(s=>s.push(o)),yield o}}finally{i.forEach(o=>o.end())}}async*getAll(e){let t=new Set;yield*bt(Hr(...this.stores.map(n=>n.getAll(e))),n=>{let i=n.cid.toString();return t.has(i)?!1:(t.add(i),!0)})}};function QA(r){return typeof r.retrieve=="function"}function e_(r){return typeof r.announce=="function"}var Il=class{child;blockRetrievers;blockAnnouncers;hashers;started;log;constructor(e){this.log=e.logger.forComponent("helia:networked-storage"),this.child=new qs([new Sl,e.blockstore]),this.blockRetrievers=(e.blockBrokers??[]).filter(QA),this.blockAnnouncers=(e.blockBrokers??[]).filter(e_),this.hashers=e.hashers??{},this.started=!1}isStarted(){return this.started}async start(){await _n(this.child,...new Set([...this.blockRetrievers,...this.blockAnnouncers])),this.started=!0}async stop(){await Sn(this.child,...new Set([...this.blockRetrievers,...this.blockAnnouncers])),this.started=!1}unwrap(){return this.child}async put(e,t,n={}){return await this.child.has(e)?(n.onProgress?.(new M("blocks:put:duplicate",e)),e):(n.onProgress?.(new M("blocks:put:providers:notify",e)),this.blockAnnouncers.forEach(i=>{i.announce(e,t,n)}),n.onProgress?.(new M("blocks:put:blockstore:put",e)),this.child.put(e,t,n))}async*putMany(e,t={}){let n=bt(e,async({cid:o})=>{let s=await this.child.has(o);return s&&t.onProgress?.(new M("blocks:put-many:duplicate",o)),!s}),i=gu(n,({cid:o,block:s})=>{t.onProgress?.(new M("blocks:put-many:providers:notify",o)),this.blockAnnouncers.forEach(a=>{a.announce(o,s,t)})});t.onProgress?.(new M("blocks:put-many:blockstore:put-many")),yield*this.child.putMany(i,t)}async get(e,t={}){if(t.offline!==!0&&!await this.child.has(e)){t.onProgress?.(new M("blocks:get:providers:get",e));let n=await Sg(e,this.blockRetrievers,this.hashers[e.multihash.code],{...t,log:this.log});return t.onProgress?.(new M("blocks:get:blockstore:put",e)),await this.child.put(e,n,t),t.onProgress?.(new M("blocks:get:providers:notify",e)),this.blockAnnouncers.forEach(i=>{i.announce(e,n,t)}),n}return t.onProgress?.(new M("blocks:get:blockstore:get",e)),this.child.get(e,t)}async*getMany(e,t={}){t.onProgress?.(new M("blocks:get-many:blockstore:get-many")),yield*this.child.getMany(gu(e,async n=>{if(t.offline!==!0&&!await this.child.has(n)){t.onProgress?.(new M("blocks:get-many:providers:get",n));let i=await Sg(n,this.blockRetrievers,this.hashers[n.multihash.code],{...t,log:this.log});t.onProgress?.(new M("blocks:get-many:blockstore:put",n)),await this.child.put(n,i,t),t.onProgress?.(new M("blocks:get-many:providers:notify",n)),this.blockAnnouncers.forEach(o=>{o.announce(n,i,t)})}}))}async delete(e,t={}){t.onProgress?.(new M("blocks:delete:blockstore:delete",e)),await this.child.delete(e,t)}async*deleteMany(e,t={}){t.onProgress?.(new M("blocks:delete-many:blockstore:delete-many")),yield*this.child.deleteMany(async function*(){for await(let n of e)yield n}(),t)}async has(e,t={}){return this.child.has(e,t)}async*getAll(e={}){e.onProgress?.(new M("blocks:get-all:blockstore:get-many")),yield*this.child.getAll(e)}},t_=(r,e)=>{if(e==null)throw new O(`No hasher configured for multihash code 0x${r.multihash.code.toString(16)}, please configure one. You can look up which hash this is at https://github.com/multiformats/multicodec/blob/master/table.csv`,"ERR_UNKNOWN_HASH_ALG");return async t=>{let n=await e.digest(t);if(!he(n.digest,r.multihash.digest))throw new O("Hash of downloaded block did not match multihash from passed CID","ERR_HASH_MISMATCH")}};async function Sg(r,e,t,n){let i=t_(r,t),o=new AbortController,s=ui([o.signal,n.signal]);try{return await Promise.any(e.map(async a=>{try{let c=!1,u=await a.retrieve(r,{...n,signal:s,validateFn:async l=>{await i(l),c=!0}});return c||await i(u),u}catch(c){throw n.log.error("could not retrieve verified block for %c",r,c),c}}))}finally{s.clear()}}var Bl=class{blockstore;datastore;pins;logger;routing;dagWalkers;hashers;log;constructor(e){this.logger=e.logger??zp(),this.log=this.logger.forComponent("helia"),this.hashers=Ag(e.hashers),this.dagWalkers=xg(e.dagWalkers);let t={blockstore:e.blockstore,datastore:e.datastore,hashers:this.hashers,dagWalkers:this.dagWalkers,logger:this.logger,blockBrokers:[],...e.components??{}};t.blockBrokers=e.blockBrokers.map(i=>i(t));let n=new Il(t);this.pins=new gl(e.datastore,n,this.dagWalkers),this.blockstore=new El(n,this.pins,{holdGcLock:e.holdGcLock??!0}),this.datastore=e.datastore,this.routing=new wl(t,{routers:(e.routers??[]).flatMap(i=>{let o=[i];return i[es]!=null&&o.push(i[es]),i[ts]!=null&&o.push(i[ts]),o})})}async start(){await vg(this.datastore),await _n(this.blockstore,this.datastore,this.routing)}async stop(){await Sn(this.blockstore,this.datastore,this.routing)}async gc(e={}){let t=await this.blockstore.lock.writeLock();try{let n=this,i=this.blockstore.unwrap();this.log("gc start"),await Jt(i.deleteMany(async function*(){for await(let{cid:o}of i.getAll())try{if(await n.pins.isPinned(o,e))continue;yield o,e.onProgress?.(new M("helia:gc:deleted",o))}catch(s){n.log.error("Error during gc",s),e.onProgress?.(new M("helia:gc:error",s))}}()))}finally{t()}this.log("gc finished")}};var Ys=class extends Sr{data;constructor(){super(),this.data=new Map}put(e,t){return this.data.set(qe.encode(e.multihash.bytes),t),e}get(e){let t=this.data.get(qe.encode(e.multihash.bytes));if(t==null)throw Xn();return t}has(e){return this.data.has(qe.encode(e.multihash.bytes))}async delete(e){this.data.delete(qe.encode(e.multihash.bytes))}async*getAll(){for(let[e,t]of this.data.entries())yield{cid:F.createV1(Ae,st(qe.decode(e))),block:t}}};var oO={...Ri};var Ig=Q(Ce(),1);function kl(r){return r=r??new Error("Not Found"),(0,Ig.default)(r,"ERR_NOT_FOUND")}var Bg="SHARDING";function n_(r){return r[Symbol.asyncIterator]!=null}function i_(r){if(n_(r))return(async()=>{let t=[];for await(let n of r)t.push(n);return t})();let e=[];for(let t of r)e.push(t);return e}var Rl=i_;function o_(r){return r[Symbol.asyncIterator]!=null}function s_(r,e){return o_(r)?async function*(){yield*(await Rl(r)).sort(e)}():function*(){yield*Rl(r).sort(e)}()}var Tl=s_;var cn=class{put(e,t,n){return Promise.reject(new Error(".put is not implemented"))}get(e,t){return Promise.reject(new Error(".get is not implemented"))}has(e,t){return Promise.reject(new Error(".has is not implemented"))}delete(e,t){return Promise.reject(new Error(".delete is not implemented"))}async*putMany(e,t={}){for await(let{key:n,value:i}of e)await this.put(n,i,t),yield n}async*getMany(e,t={}){for await(let n of e)yield{key:n,value:await this.get(n,t)}}async*deleteMany(e,t={}){for await(let n of e)await this.delete(n,t),yield n}batch(){let e=[],t=[];return{put(n,i){e.push({key:n,value:i})},delete(n){t.push(n)},commit:async n=>{await Jt(this.putMany(e,n)),e=[],await Jt(this.deleteMany(t,n)),t=[]}}}async*_all(e,t){throw new Error("._all is not implemented")}async*_allKeys(e,t){throw new Error("._allKeys is not implemented")}query(e,t){let n=this._all(e,t);if(e.prefix!=null){let i=e.prefix;n=bt(n,o=>o.key.toString().startsWith(i))}if(Array.isArray(e.filters)&&(n=e.filters.reduce((i,o)=>bt(i,o),n)),Array.isArray(e.orders)&&(n=e.orders.reduce((i,o)=>Tl(i,o),n)),e.offset!=null){let i=0,o=e.offset;n=bt(n,()=>i++>=o)}return e.limit!=null&&(n=Ua(n,e.limit)),n}queryKeys(e,t){let n=this._allKeys(e,t);if(e.prefix!=null){let i=e.prefix;n=bt(n,o=>o.toString().startsWith(i))}if(Array.isArray(e.filters)&&(n=e.filters.reduce((i,o)=>bt(i,o),n)),Array.isArray(e.orders)&&(n=e.orders.reduce((i,o)=>Tl(i,o),n)),e.offset!=null){let i=e.offset,o=0;n=bt(n,()=>o++>=i)}return e.limit!=null&&(n=Ua(n,e.limit)),n}};var js=class extends cn{data;constructor(){super(),this.data=new Map}put(e,t){return this.data.set(e.toString(),t),e}get(e){let t=this.data.get(e.toString());if(t==null)throw kl();return t}has(e){return this.data.has(e.toString())}delete(e){this.data.delete(e.toString())}*_all(){for(let[e,t]of this.data.entries())yield{key:new Le(e),value:t}}*_allKeys(){for(let e of this.data.keys())yield new Le(e)}};var LO=new Le(Bg);var GO=oe("datastore:core:tiered");async function Rg(r={}){let e=r.datastore??new js,t=r.blockstore??new Ys,n=new Bl({...r,datastore:e,blockstore:t,blockBrokers:r.blockBrokers??[is()],routers:r.routers??[Vs("https://delegated-ipfs.dev")]});return r.start!==!1&&await n.start(),n}var eh=Q(Ba(),1);var th=40;function rh(r,e){if(!r.length)throw new Error("Unexpected end of data");let t=eh.default.decode(r);return e.seek(eh.default.decode.bytes),t}function nh(r){let e=new DataView(r.buffer,r.byteOffset,r.byteLength),t=0;return{version:2,characteristics:[e.getBigUint64(t,!0),e.getBigUint64(t+=8,!0)],dataOffset:Number(e.getBigUint64(t+=8,!0)),dataSize:Number(e.getBigUint64(t+=8,!0)),indexOffset:Number(e.getBigUint64(t+=8,!0))}}var Zn={Null:r=>r===null?r:void 0,Int:r=>Number.isInteger(r)?r:void 0,Float:r=>typeof r=="number"&&Number.isFinite(r)?r:void 0,String:r=>typeof r=="string"?r:void 0,Bool:r=>typeof r=="boolean"?r:void 0,Bytes:r=>r instanceof Uint8Array?r:void 0,Link:r=>r!==null&&typeof r=="object"&&r.asCID===r?r:void 0,List:r=>Array.isArray(r)?r:void 0,Map:r=>r!==null&&typeof r=="object"&&r.asCID!==r&&!Array.isArray(r)&&!(r instanceof Uint8Array)?r:void 0},Xs={"CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)":Zn.Link,"CarV1HeaderOrV2Pragma > roots (anon)":r=>{if(Zn.List(r)!==void 0){for(let e=0;e<r.length;e++){let t=r[e];if(t=Xs["CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)"](t),t===void 0)return;if(t!==r[e]){let n=r.slice(0,e);for(let i=e;i<r.length;i++){let o=r[i];if(o=Xs["CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)"](o),o===void 0)return;n.push(o)}return n}}return r}},Int:Zn.Int,CarV1HeaderOrV2Pragma:r=>{if(Zn.Map(r)===void 0)return;let e=Object.entries(r),t=r,n=1;for(let i=0;i<e.length;i++){let[o,s]=e[i];switch(o){case"roots":{let a=Xs["CarV1HeaderOrV2Pragma > roots (anon)"](r[o]);if(a===void 0)return;if(a!==s||t!==r){if(t===r){t={};for(let c=0;c<i;c++)t[e[c][0]]=e[c][1]}t.roots=a}}break;case"version":{n--;let a=Xs.Int(r[o]);if(a===void 0)return;if(a!==s||t!==r){if(t===r){t={};for(let c=0;c<i;c++)t[e[c][0]]=e[c][1]}t.version=a}}break;default:return}}if(!(n>0))return t}},Zs={"CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)":Zn.Link,"CarV1HeaderOrV2Pragma > roots (anon)":r=>{if(Zn.List(r)!==void 0){for(let e=0;e<r.length;e++){let t=r[e];if(t=Zs["CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)"](t),t===void 0)return;if(t!==r[e]){let n=r.slice(0,e);for(let i=e;i<r.length;i++){let o=r[i];if(o=Zs["CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)"](o),o===void 0)return;n.push(o)}return n}}return r}},Int:Zn.Int,CarV1HeaderOrV2Pragma:r=>{if(Zn.Map(r)===void 0)return;let e=Object.entries(r),t=r,n=1;for(let i=0;i<e.length;i++){let[o,s]=e[i];switch(o){case"roots":{let a=Zs["CarV1HeaderOrV2Pragma > roots (anon)"](s);if(a===void 0)return;if(a!==s||t!==r){if(t===r){t={};for(let c=0;c<i;c++)t[e[c][0]]=e[c][1]}t.roots=a}}break;case"version":{n--;let a=Zs.Int(s);if(a===void 0)return;if(a!==s||t!==r){if(t===r){t={};for(let c=0;c<i;c++)t[e[c][0]]=e[c][1]}t.version=a}}break;default:return}}if(!(n>0))return t}},ih={toTyped:Xs.CarV1HeaderOrV2Pragma,toRepresentation:Zs.CarV1HeaderOrV2Pragma};var kP=Ef();var f_=Q(Ba(),1);var LP=[new R(w.map,2),new R(w.string,"version"),new R(w.uint,1),new R(w.string,"roots")],UP=new R(w.tag,42);async function oh(r,e){let t=rh(await r.upTo(8),r);if(t===0)throw new Error("Invalid CAR header (zero length)");let n=await r.exactly(t,!0),i=ki(n);if(ih.toTyped(i)===void 0)throw new Error("Invalid CAR header format");if(i.version!==1&&i.version!==2||e!==void 0&&i.version!==e)throw new Error(`Invalid CAR version: ${i.version}${e!==void 0?` (expected ${e})`:""}`);if(i.version===1){if(!Array.isArray(i.roots))throw new Error("Invalid CAR header format");return i}if(i.roots!==void 0)throw new Error("Invalid CAR header format");let o=nh(await r.exactly(th,!0));r.seek(o.dataOffset-r.pos);let s=await oh(r,1);return Object.assign(s,o)}function Js(r){let e=0;return{async upTo(t){return r.subarray(e,e+Math.min(t,r.length-e))},async exactly(t,n=!1){if(t>r.length-e)throw new Error("Unexpected end of data");let i=r.subarray(e,e+t);return n&&(e+=t),i},seek(t){e+=t},get pos(){return e}}}var sh=Q(Ba(),1),Cg=1;function ah(r){let e=Hs({version:Cg,roots:r}),t=sh.default.encode(e.length),n=new Uint8Array(t.length+e.length);return n.set(t,0),n.set(e,t.length),n}function Lg(r){return{async setRoots(e){let t=ah(e);await r.write(t)},async writeBlock(e){let{cid:t,bytes:n}=e;await r.write(new Uint8Array(sh.default.encode(t.bytes.length+n.length))),await r.write(t.bytes),n.length&&await r.write(n)},async close(){await r.end()},version(){return Cg}}}function Nl(){}function Ug(){let r=[],e=null,t=Nl,n=!1,i=null,o=Nl,s=()=>(e||(e=new Promise(u=>{t=()=>{e=null,t=Nl,u()}})),e),a={write(u){r.push(u);let l=s();return o(),l},async end(){n=!0;let u=s();o(),await u}},c={async next(){let u=r.shift();return u?(r.length===0&&t(),{done:!1,value:u}):n?(t(),{done:!0,value:void 0}):(i||(i=new Promise(l=>{o=()=>(i=null,o=Nl,l(c.next()))})),i)}};return{writer:a,iterator:c}}var Qs=class r{constructor(e,t){this._encoder=t,this._mutex=t.setRoots(e),this._ended=!1}async put(e){if(!(e.bytes instanceof Uint8Array)||!e.cid)throw new TypeError("Can only write {cid, bytes} objects");if(this._ended)throw new Error("Already closed");let t=F.asCID(e.cid);if(!t)throw new TypeError("Can only write {cid, bytes} objects");return this._mutex=this._mutex.then(()=>this._encoder.writeBlock({cid:t,bytes:e.bytes})),this._mutex}async close(){if(this._ended)throw new Error("Already closed");return await this._mutex,this._ended=!0,this._encoder.close()}version(){return this._encoder.version()}static create(e){e=y_(e);let{encoder:t,iterator:n}=Dg(),i=new r(e,t),o=new Cl(n);return{writer:i,out:o}}static createAppender(){let{encoder:e,iterator:t}=Dg();e.setRoots=()=>Promise.resolve();let n=new r([],e),i=new Cl(t);return{writer:n,out:i}}static async updateRootsInBytes(e,t){let n=Js(e);await oh(n);let i=ah(t);if(Number(n.pos)!==i.length)throw new Error(`updateRoots() can only overwrite a header of the same length (old header is ${n.pos} bytes, new header is ${i.length} bytes)`);return e.set(i,0),e}},Cl=class{constructor(e){this._iterator=e}[Symbol.asyncIterator](){if(this._iterating)throw new Error("Multiple iterator not supported");return this._iterating=!0,this._iterator}};function Dg(){let r=Ug(),{writer:e,iterator:t}=r;return{encoder:Lg(e),iterator:t}}function y_(r){if(r===void 0)return[];if(!Array.isArray(r)){let t=F.asCID(r);if(!t)throw new TypeError("roots must be a single CID or an array of CIDs");return[t]}let e=[];for(let t of r){let n=F.asCID(t);if(!n)throw new TypeError("roots must be a single CID or an array of CIDs");e.push(n)}return e}var g_=1,ch=class{components;constructor(e,t){this.components=e}async import(e,t){await Jt(this.components.blockstore.putMany(at(e.blocks(),({cid:n,bytes:i})=>({cid:n,block:i})),t))}async export(e,t,n){let i=_e(),o=Array.isArray(e)?e:[e],s=new nt({concurrency:g_});s.on("idle",()=>{i.resolve()}),s.on("error",a=>{s.clear(),i.reject(a)});for(let a of o)s.add(async()=>{await this.#e(a,s,async(c,u)=>{await t.put({cid:c,bytes:u})},n)}).catch(()=>{});try{await i.promise}finally{await t.close()}}async*stream(e,t){let{writer:n,out:i}=Qs.create(e);this.export(e,n,t).catch(()=>{});for await(let o of i)yield o}async#e(e,t,n,i){let o=this.components.dagWalkers[e.code];if(o==null)throw new Error(`No dag walker found for cid codec ${e.code}`);let s=await this.components.blockstore.get(e,i);await n(e,s);for await(let a of o.walk(s))t.add(async()=>{await this.#e(a,t,n,i)})}};function Og(r,e={}){return new ch(r,e)}var lh=Q(Yc(),1);function Pg(r,e){let t=e.map((n,i)=>({record:dt(n),index:i}));return t.sort((n,i)=>{let o=n.record.sequence,s=i.record.sequence;if(o>s)return-1;if(o<s)return 1;if(n.record.validityType===We.ValidityType.EOL&&i.record.validityType===We.ValidityType.EOL){let a=lh.default.fromString(n.record.validity).toDate(),c=lh.default.fromString(i.record.validity).toDate();if(a.getTime()>c.getTime())return-1;if(a.getTime()<c.getTime())return 1}return 0}),t[0].index}var w_=r=>{let e=r.data;return e.startsWith('"')&&(e=e.substring(1)),e.endsWith('"')&&(e=e.substring(0,e.length-1)),e.replace("dnslink=","")},uh=(r,e)=>{let t=E_(r,e);return{ipfsPath:w_(t),answer:t}},E_=(r,e)=>{let t=e.Answer?.filter(n=>n.data.includes("dnslink=/ipfs")||n.data.includes("dnslink=/ipns")).pop();if(t==null)throw new O(`No dnslink records found for domain: ${r}`,"ERR_DNSLINK_NOT_FOUND");return t},ea=32,Co=async(r,e,t,n={})=>{if(e===0)throw new Error("recursion limit exceeded");let i;try{i=await t(r,n)}catch(a){if(a.code!=="ENOTFOUND"&&a.code!=="ERR_DNSLINK_NOT_FOUND"&&a.code!=="ENODATA")throw a;r.startsWith("_dnslink.")?r=r.replace("_dnslink.",""):r=`_dnslink.${r}`,i=await t(r,n)}let o=i.replace("dnslink=",""),s=o.split("/")[2];try{return F.parse(s),o}catch{}return Co(s,e-1,t,n)},x_=/^dnslink=.+$/,Fg=async(r,e)=>{let i=(await r.resolveTxt(e)).flat().filter(o=>x_.test(o))[0];if(i==null)throw new O(`No dnslink records found for domain: ${e}`,"ERR_DNSLINK_NOT_FOUND");return i};var fh=Q(Du(),1),hh=Q(Hg(),1);function Ll(r,e,t){return`${r}?name=${e}&type=${t}`}async function $g(r,e){return await(await fetch(r,{headers:new Headers({accept:"application/dns-json"}),signal:e})).json()}function Ti(r,e){return`${e}_${r}`}var dh=Object.assign((0,fh.default)("dns-over-http-resolver"),{error:(0,fh.default)("dns-over-http-resolver:error")}),ph=class{_cache;_TXTcache;_servers;_request;_abortControllers;constructor(e={}){this._cache=new hh.default({max:e?.maxCache??100}),this._TXTcache=new hh.default({max:e?.maxCache??100}),this._servers=["https://cloudflare-dns.com/dns-query","https://dns.google/resolve"],this._request=e.request??$g,this._abortControllers=[]}cancel(){this._abortControllers.forEach(e=>{e.abort()})}getServers(){return this._servers}_getShuffledServers(){let e=[...this._servers];for(let t=e.length-1;t>0;t--){let n=Math.floor(Math.random()*t),i=e[t];e[t]=e[n],e[n]=i}return e}setServers(e){this._servers=e}async resolve(e,t="A"){switch(t){case"A":return this.resolve4(e);case"AAAA":return this.resolve6(e);case"TXT":return this.resolveTxt(e);default:throw new Error(`${t} is not supported`)}}async resolve4(e){let t="A",n=this._cache.get(Ti(e,t));if(n!=null)return n;let i=!1;for(let o of this._getShuffledServers()){let s=new AbortController;this._abortControllers.push(s);try{let a=await this._request(Ll(o,e,t),s.signal),c=a.Answer.map(l=>l.data),u=Math.min(...a.Answer.map(l=>l.TTL));return this._cache.set(Ti(e,t),c,{ttl:u}),c}catch{s.signal.aborted&&(i=!0),dh.error(`${o} could not resolve ${e} record ${t}`)}finally{this._abortControllers=this._abortControllers.filter(a=>a!==s)}}throw i?Object.assign(new Error("queryA ECANCELLED"),{code:"ECANCELLED"}):new Error(`Could not resolve ${e} record ${t}`)}async resolve6(e){let t="AAAA",n=this._cache.get(Ti(e,t));if(n!=null)return n;let i=!1;for(let o of this._getShuffledServers()){let s=new AbortController;this._abortControllers.push(s);try{let a=await this._request(Ll(o,e,t),s.signal),c=a.Answer.map(l=>l.data),u=Math.min(...a.Answer.map(l=>l.TTL));return this._cache.set(Ti(e,t),c,{ttl:u}),c}catch{s.signal.aborted&&(i=!0),dh.error(`${o} could not resolve ${e} record ${t}`)}finally{this._abortControllers=this._abortControllers.filter(a=>a!==s)}}throw i?Object.assign(new Error("queryAaaa ECANCELLED"),{code:"ECANCELLED"}):new Error(`Could not resolve ${e} record ${t}`)}async resolveTxt(e){let t="TXT",n=this._TXTcache.get(Ti(e,t));if(n!=null)return n;let i=!1;for(let o of this._getShuffledServers()){let s=new AbortController;this._abortControllers.push(s);try{let a=await this._request(Ll(o,e,t),s.signal),c=a.Answer.map(l=>[l.data.replace(/['"]+/g,"")]),u=Math.min(...a.Answer.map(l=>l.TTL));return this._TXTcache.set(Ti(e,t),c,{ttl:u}),c}catch{s.signal.aborted&&(i=!0),dh.error(`${o} could not resolve ${e} record ${t}`)}finally{this._abortControllers=this._abortControllers.filter(a=>a!==s)}}throw i?Object.assign(new Error("queryTxt ECANCELLED"),{code:"ECANCELLED"}):new Error(`Could not resolve ${e} record ${t}`)}clearCache(){this._cache.clear(),this._TXTcache.clear()}},zg=ph;var Gg=Q(mh(),1),Qn=class{lru;constructor(e){this.lru=(0,Gg.default)(e)}get(e){let t=this.lru.get(e);if(t!=null){if(t.expire!=null&&t.expire<Date.now()){this.lru.remove(e);return}return t.value}}set(e,t,n){this.lru.set(e,{value:t,expire:Date.now()+n})}has(e){return this.get(e)!=null}remove(e){this.lru.remove(e)}clear(){this.lru.clear()}};var yh=new Qn(1e3),S_=60*1e3,I_=new nt({concurrency:4}),B_=async function(e,t={}){let n=new zg({maxCache:0});if(t.nocache!==!0&&yh.has(e)){let o=yh.get(e);if(o!=null)return t?.onProgress?.(new M("dnslink:cache",{detail:o})),o}t.onProgress?.(new M("dnslink:query",{detail:e}));let i=await I_.add(async()=>{let o=await Fg(n,e);return t.onProgress?.(new M("dnslink:answer",{detail:o})),yh.set(e,o,S_),o},{signal:t?.signal});if(i==null)throw new Error("No DNS response received");return i},qg=B_;function Yg(){return async(r,e={})=>Co(r,ea,qg,e)}var gh=class{routing;constructor(e){this.routing=e}async put(e,t,n={}){try{await this.routing.put(e,t,n)}catch(i){n.onProgress?.(new M("ipns:routing:helia:error",i))}}async get(e,t={}){try{return await this.routing.get(e,t)}catch(n){t.onProgress?.(new M("ipns:routing:helia:error",n))}throw new Error("Not found")}};function Wg(r){return new gh(r)}var Ul=globalThis.CustomEvent??Event;async function*Ni(r,e={}){let t=e.concurrency??1/0;t<1&&(t=1/0);let n=e.ordered==null?!1:e.ordered,i=new EventTarget,o=[],s=_e(),a=_e(),c=!1,u,l=!1;i.addEventListener("task-complete",()=>{a.resolve()}),Promise.resolve().then(async()=>{try{for await(let h of r){if(o.length===t&&(s=_e(),await s.promise),l)break;let m={done:!1};o.push(m),h().then(y=>{m.done=!0,m.ok=!0,m.value=y,i.dispatchEvent(new Ul("task-complete"))},y=>{m.done=!0,m.err=y,i.dispatchEvent(new Ul("task-complete"))})}c=!0,i.dispatchEvent(new Ul("task-complete"))}catch(h){u=h,i.dispatchEvent(new Ul("task-complete"))}});function d(){return n?o[0]?.done:!!o.find(h=>h.done)}function*p(){for(;o.length>0&&o[0].done;){let h=o[0];if(o.shift(),h.ok)yield h.value;else throw l=!0,s.resolve(),h.err;s.resolve()}}function*f(){for(;d();)for(let h=0;h<o.length;h++)if(o[h].done){let m=o[h];if(o.splice(h,1),h--,m.ok)yield m.value;else throw l=!0,s.resolve(),m.err;s.resolve()}}for(;;){if(d()||(a=_e(),await a.promise),u!=null)throw u;if(n?yield*p():yield*f(),c&&o.length===0)break}}var ta;(function(r){let e;r.codec=()=>(e==null&&(e=$t((t,n,i={})=>{i.lengthDelimited!==!1&&n.fork(),t.key!=null&&t.key.byteLength>0&&(n.uint32(10),n.bytes(t.key)),t.value!=null&&t.value.byteLength>0&&(n.uint32(18),n.bytes(t.value)),t.timeReceived!=null&&t.timeReceived!==""&&(n.uint32(42),n.string(t.timeReceived)),i.lengthDelimited!==!1&&n.ldelim()},(t,n)=>{let i={key:new Uint8Array(0),value:new Uint8Array(0),timeReceived:""},o=n==null?t.len:t.pos+n;for(;t.pos<o;){let s=t.uint32();switch(s>>>3){case 1:i.key=t.bytes();break;case 2:i.value=t.bytes();break;case 5:i.timeReceived=t.string();break;default:t.skipType(s&7);break}}return i})),e),r.encode=t=>Ht(t,r.codec()),r.decode=t=>Vt(t,r.codec())})(ta||(ta={}));function jg(r){let e=r.getUTCFullYear(),t=String(r.getUTCMonth()+1).padStart(2,"0"),n=String(r.getUTCDate()).padStart(2,"0"),i=String(r.getUTCHours()).padStart(2,"0"),o=String(r.getUTCMinutes()).padStart(2,"0"),s=String(r.getUTCSeconds()).padStart(2,"0"),a=r.getUTCMilliseconds(),c=String(a*1e3*1e3).padStart(9,"0");return`${e}-${t}-${n}T${i}:${o}:${s}.${c}Z`}function Xg(r){let e=new RegExp("(\\d{4})-(\\d{2})-(\\d{2})T(\\d{2}):(\\d{2}):(\\d{2})\\.(\\d+)Z"),t=String(r).trim().match(e);if(t==null)throw new Error("Invalid format");let n=parseInt(t[1],10),i=parseInt(t[2],10)-1,o=parseInt(t[3],10),s=parseInt(t[4],10),a=parseInt(t[5],10),c=parseInt(t[6],10),u=parseInt(t[7].slice(0,-6),10);return new Date(Date.UTC(n,i,o,s,a,c,u))}var ei=class r{key;value;timeReceived;constructor(e,t,n){if(!(e instanceof Uint8Array))throw new Error("key must be a Uint8Array");if(!(t instanceof Uint8Array))throw new Error("value must be a Uint8Array");this.key=e,this.value=t,this.timeReceived=n}serialize(){return ta.encode(this.prepareSerialize())}prepareSerialize(){return{key:this.key,value:this.value,timeReceived:jg(this.timeReceived)}}static deserialize(e){let t=ta.decode(e);return new r(t.key,t.value,new Date(t.timeReceived))}static fromDeserialized(e){let t=Xg(e.timeReceived);if(e.key==null)throw new Error("key missing from deserialized object");if(e.value==null)throw new Error("value missing from deserialized object");return new r(e.key,e.value,t)}};var Zg;(function(r){r[r.SEND_QUERY=0]="SEND_QUERY",r[r.PEER_RESPONSE=1]="PEER_RESPONSE",r[r.FINAL_PEER=2]="FINAL_PEER",r[r.QUERY_ERROR=3]="QUERY_ERROR",r[r.PROVIDER=4]="PROVIDER",r[r.VALUE=5]="VALUE",r[r.ADD_PEER=6]="ADD_PEER",r[r.DIAL_PEER=7]="DIAL_PEER"})(Zg||(Zg={}));var Jg;(function(r){r[r.PUT_VALUE=0]="PUT_VALUE",r[r.GET_VALUE=1]="GET_VALUE",r[r.ADD_PROVIDER=2]="ADD_PROVIDER",r[r.GET_PROVIDERS=3]="GET_PROVIDERS",r[r.FIND_NODE=4]="FIND_NODE",r[r.PING=5]="PING"})(Jg||(Jg={}));function wh(r){return new Le("/dht/record/"+Z(r,"base32"),!1)}function Qg(r){return{async put(e,t,n={}){try{let i=wh(e),o=new ei(e,t,new Date);n.onProgress?.(new M("ipns:routing:datastore:put")),await r.put(i,o.serialize(),n)}catch(i){throw n.onProgress?.(new M("ipns:routing:datastore:error",i)),i}},async get(e,t={}){try{let n=wh(e);t.onProgress?.(new M("ipns:routing:datastore:get"));let i=await r.get(n,t);return ei.deserialize(i).value}catch(n){throw t.onProgress?.(new M("ipns:routing:datastore:error",n)),n}},async has(e,t={}){let n=wh(e);return r.has(n,t)}}}var Ci=oe("helia:ipns"),R_=60*1e3,ew=60*R_,T_=24*ew,Eh=23*ew,xh=class{routers;localStore;timeout;defaultResolvers;constructor(e,t=[],n=[]){this.routers=[Wg(e.routing),...t],this.localStore=Qg(e.datastore),this.defaultResolvers=n.length>0?n:[Yg()]}async publish(e,t,n={}){try{let i=1n,o=Io(e);if(await this.localStore.has(o,n)){let c=await this.localStore.get(o,n);i=dt(c).sequence+1n}let s=await Fy(e,t,i,n.lifetime??T_,n),a=sn(s);return await this.localStore.put(o,a,n),n.offline!==!0&&await Promise.all(this.routers.map(async c=>{await c.put(o,a,n)})),s}catch(i){throw n.onProgress?.(new M("ipns:publish:error",i)),i}}async resolve(e,t={}){let n=Io(e),i=await this.#t(n,t);return this.#e(i.value,t)}async resolveDns(e,t={}){let n=t.resolvers??this.defaultResolvers,i=await Promise.any(n.map(async o=>o(e,t)));return this.#e(i,t)}republish(e={}){if(this.timeout!=null)throw new Error("Republish is already running");e.signal?.addEventListener("abort",()=>{clearTimeout(this.timeout)});async function t(){let n=Date.now();e.onProgress?.(new M("ipns:republish:start"));let o=Date.now()-n,s=Eh-o;s<0&&(s=e.interval??Eh),setTimeout(()=>{t().catch(a=>{Ci.error("error republishing",a)})},s)}this.timeout=setTimeout(()=>{t().catch(n=>{Ci.error("error republishing",n)})},e.interval??Eh)}async#e(e,t={}){let n=e.split("/");try{let i=n[1];if(i==="ipns"){let{cid:o}=await this.resolve(Bt(n[2]),t),s=n.slice(3).join("/");return{cid:o,path:s}}else if(i==="ipfs"){let o=F.parse(n[2]),s=n.slice(3).join("/");return{cid:o,path:s}}}catch(i){Ci.error("error parsing ipfs path",i)}throw Ci.error("invalid ipfs path %s",e),new Error("Invalid value")}async#t(e,t={}){let n=[this.localStore,...this.routers];t.offline===!0&&(n=[this.localStore]);let i=[],o=0;if(await Promise.all(n.map(async a=>{let c;try{c=await a.get(e,{...t,validate:!1})}catch(u){a===this.localStore&&u.code==="ERR_NOT_FOUND"?Ci("did not have record locally"):Ci.error("error finding IPNS record",u);return}try{await cl(e,c),i.push(c)}catch(u){o++,Ci.error("error finding IPNS record",u)}})),i.length===0)throw o>0?new O(`${o>1?`${o} records`:"Record"} found for routing key ${o>1?"were":"was"} invalid`,"ERR_RECORDS_FAILED_VALIDATION"):new O("Could not find record for routing key","ERR_NOT_FOUND");let s=i[Pg(e,i)];return await this.localStore.put(e,s,t),dt(s)}};function tw(r,{routers:e=[],resolvers:t=[]}={}){return new xh(r,e,t)}var yS=Q(Nh(),1),gS=Q(Cw(),1);var RF=new Qn(1e3),TF=60*1e3;var Hh=new Qn(1e3),wS=60*1e3;function Ml(r){let e=new nt({concurrency:4}),t=async(n,i={})=>{let o=new URLSearchParams;o.set("name",n),o.set("type","TXT");let s=o.toString();if(i.nocache!==!0&&Hh.has(s)){let c=Hh.get(s);if(c!=null)return i.onProgress?.(new M("dnslink:cache",{detail:c})),c}i.onProgress?.(new M("dnslink:query",{detail:n}));let a=await e.add(async()=>{let c=await fetch(`${r}?${o}`,{headers:{accept:"application/dns-json"},signal:i.signal});if(c.status!==200)throw new Error(`Unexpected HTTP status: ${c.status} - ${c.statusText}`);let u=new URL(c.url).search.slice(1),l=await c.json();i.onProgress?.(new M("dnslink:answer",{detail:l}));let{ipfsPath:d,answer:p}=uh(n,l);return Hh.set(u,d,p.TTL??wS),d},{signal:i.signal});if(a==null)throw new Error("No DNS response received");return a};return async(n,i={})=>Co(n,ea,t,i)}var Yh=Q(Ce(),1);function ES(r){return r[Symbol.asyncIterator]!=null}function xS(r,e=1){return e=Number(e),ES(r)?async function*(){let t=[];if(e<1&&(e=1),e!==Math.round(e))throw new Error("Batch size must be an integer");for await(let n of r)for(t.push(n);t.length>=e;)yield t.slice(0,e),t=t.slice(e);for(;t.length>0;)yield t.slice(0,e),t=t.slice(e)}():function*(){let t=[];if(e<1&&(e=1),e!==Math.round(e))throw new Error("Batch size must be an integer");for(let n of r)for(t.push(n);t.length>=e;)yield t.slice(0,e),t=t.slice(e);for(;t.length>0;)yield t.slice(0,e),t=t.slice(e)}()}var ia=xS;async function*oa(r,e=1){for await(let t of ia(r,e)){let n=t.map(async i=>i().then(o=>({ok:!0,value:o}),o=>({ok:!1,err:o})));for(let i=0;i<n.length;i++){let o=await n[i];if(o.ok)yield o.value;else throw o.err}}}var bS=262144,sa=(r={})=>{let e=r.chunkSize??bS;return async function*(n){let i=new zt,o=0,s=!1;for await(let a of n)for(i.append(a),o+=a.length;o>=e;)if(yield i.slice(0,e),s=!0,e===i.length)i=new zt,o=0;else{let c=new zt;c.append(i.sublist(e)),i=c,o-=e}(!s||o>0)&&(yield i.subarray(0,o))}};var $h=Q(Ce(),1);var dr;(function(r){let e;(function(i){i.Raw="Raw",i.Directory="Directory",i.File="File",i.Metadata="Metadata",i.Symlink="Symlink",i.HAMTShard="HAMTShard"})(e=r.DataType||(r.DataType={}));let t;(function(i){i[i.Raw=0]="Raw",i[i.Directory=1]="Directory",i[i.File=2]="File",i[i.Metadata=3]="Metadata",i[i.Symlink=4]="Symlink",i[i.HAMTShard=5]="HAMTShard"})(t||(t={})),function(i){i.codec=()=>yi(t)}(e=r.DataType||(r.DataType={}));let n;r.codec=()=>(n==null&&(n=$t((i,o,s={})=>{if(s.lengthDelimited!==!1&&o.fork(),i.Type!=null&&(o.uint32(8),r.DataType.codec().encode(i.Type,o)),i.Data!=null&&(o.uint32(18),o.bytes(i.Data)),i.filesize!=null&&(o.uint32(24),o.uint64(i.filesize)),i.blocksizes!=null)for(let a of i.blocksizes)o.uint32(32),o.uint64(a);i.hashType!=null&&(o.uint32(40),o.uint64(i.hashType)),i.fanout!=null&&(o.uint32(48),o.uint64(i.fanout)),i.mode!=null&&(o.uint32(56),o.uint32(i.mode)),i.mtime!=null&&(o.uint32(66),Hl.codec().encode(i.mtime,o)),s.lengthDelimited!==!1&&o.ldelim()},(i,o)=>{let s={blocksizes:[]},a=o==null?i.len:i.pos+o;for(;i.pos<a;){let c=i.uint32();switch(c>>>3){case 1:s.Type=r.DataType.codec().decode(i);break;case 2:s.Data=i.bytes();break;case 3:s.filesize=i.uint64();break;case 4:s.blocksizes.push(i.uint64());break;case 5:s.hashType=i.uint64();break;case 6:s.fanout=i.uint64();break;case 7:s.mode=i.uint32();break;case 8:s.mtime=Hl.codec().decode(i,i.uint32());break;default:i.skipType(c&7);break}}return s})),n),r.encode=i=>Ht(i,r.codec()),r.decode=i=>Vt(i,r.codec())})(dr||(dr={}));var Hl;(function(r){let e;r.codec=()=>(e==null&&(e=$t((t,n,i={})=>{i.lengthDelimited!==!1&&n.fork(),t.Seconds!=null&&(n.uint32(8),n.int64(t.Seconds)),t.FractionalNanoseconds!=null&&(n.uint32(21),n.fixed32(t.FractionalNanoseconds)),i.lengthDelimited!==!1&&n.ldelim()},(t,n)=>{let i={},o=n==null?t.len:t.pos+n;for(;t.pos<o;){let s=t.uint32();switch(s>>>3){case 1:i.Seconds=t.int64();break;case 2:i.FractionalNanoseconds=t.fixed32();break;default:t.skipType(s&7);break}}return i})),e),r.encode=t=>Ht(t,r.codec()),r.decode=t=>Vt(t,r.codec())})(Hl||(Hl={}));var Lw;(function(r){let e;r.codec=()=>(e==null&&(e=$t((t,n,i={})=>{i.lengthDelimited!==!1&&n.fork(),t.MimeType!=null&&(n.uint32(10),n.string(t.MimeType)),i.lengthDelimited!==!1&&n.ldelim()},(t,n)=>{let i={},o=n==null?t.len:t.pos+n;for(;t.pos<o;){let s=t.uint32();switch(s>>>3){case 1:i.MimeType=t.string();break;default:t.skipType(s&7);break}}return i})),e),r.encode=t=>Ht(t,r.codec()),r.decode=t=>Vt(t,r.codec())})(Lw||(Lw={}));var Uw={Raw:"raw",Directory:"directory",File:"file",Metadata:"metadata",Symlink:"symlink",HAMTShard:"hamt-sharded-directory"},vS=["directory","hamt-sharded-directory"],Dw=parseInt("0644",8),Ow=parseInt("0755",8),j=class r{static unmarshal(e){let t=dr.decode(e),n=new r({type:Uw[t.Type!=null?t.Type.toString():"File"],data:t.Data,blockSizes:t.blocksizes,mode:t.mode,mtime:t.mtime!=null?{secs:t.mtime.Seconds??0n,nsecs:t.mtime.FractionalNanoseconds}:void 0,fanout:t.fanout});return n._originalMode=t.mode??0,n}type;data;blockSizes;hashType;fanout;mtime;_mode;_originalMode;constructor(e={type:"file"}){let{type:t,data:n,blockSizes:i,hashType:o,fanout:s,mtime:a,mode:c}=e;if(t!=null&&!Object.values(Uw).includes(t))throw(0,$h.default)(new Error("Type: "+t+" is not valid"),"ERR_INVALID_TYPE");this.type=t??"file",this.data=n,this.hashType=o,this.fanout=s,this.blockSizes=i??[],this._originalMode=0,this.mode=c,this.mtime=a}set mode(e){e==null?this._mode=this.isDirectory()?Ow:Dw:this._mode=e&4095}get mode(){return this._mode}isDirectory(){return vS.includes(this.type)}addBlockSize(e){this.blockSizes.push(e)}removeBlockSize(e){this.blockSizes.splice(e,1)}fileSize(){if(this.isDirectory())return 0n;let e=0n;return this.blockSizes.forEach(t=>{e+=t}),this.data!=null&&(e+=BigInt(this.data.length)),e}marshal(){let e;switch(this.type){case"raw":e=dr.DataType.Raw;break;case"directory":e=dr.DataType.Directory;break;case"file":e=dr.DataType.File;break;case"metadata":e=dr.DataType.Metadata;break;case"symlink":e=dr.DataType.Symlink;break;case"hamt-sharded-directory":e=dr.DataType.HAMTShard;break;default:throw(0,$h.default)(new Error(`Type: ${e} is not valid`),"ERR_INVALID_TYPE")}let t=this.data;(this.data==null||this.data.length===0)&&(t=void 0);let n;this.mode!=null&&(n=this._originalMode&4294963200|(this.mode??0),n===Dw&&!this.isDirectory()&&(n=void 0),n===Ow&&this.isDirectory()&&(n=void 0));let i;return this.mtime!=null&&(i={Seconds:this.mtime.secs,FractionalNanoseconds:this.mtime.nsecs}),dr.encode({Type:e,Data:t,filesize:this.isDirectory()?void 0:this.fileSize(),blocksizes:this.blockSizes,hashType:this.hashType,fanout:this.fanout,mode:n,mtime:i})}};var fr=async(r,e,t)=>{t.codec==null&&(t.codec=Oe);let n=await fe.digest(r),i=F.create(t.cidVersion,t.codec.code,n);return await e.put(i,r,t),i};function Pw(r){return async function*(t,n){let i=0n;for await(let o of t.content)yield async()=>{let s,a={codec:Oe,cidVersion:r.cidVersion,onProgress:r.onProgress};r.rawLeaves?(a.codec=Mt,a.cidVersion=1):(s=new j({type:r.leafType,data:o}),o=ce({Data:s.marshal(),Links:[]}));let c=await fr(o,n,a);return i+=BigInt(o.byteLength),r.onProgress?.(new M("unixfs:importer:progress:file:write",{bytesWritten:i,cid:c,path:t.path})),{cid:c,unixfs:s,size:BigInt(o.length),block:o}}}}var zh=Q(Ce(),1);var Fw=async(r,e,t)=>{let n=new j({type:"directory",mtime:r.mtime,mode:r.mode}),i=ce(Te({Data:n.marshal()})),o=await fr(i,e,t),s=r.path;return{cid:o,path:s,unixfs:n,size:BigInt(i.length),originalPath:r.originalPath,block:i}};async function*AS(r,e,t){let n=-1,i;for await(let o of oa(t.bufferImporter(r,e),t.blockWriteConcurrency)){if(n++,n===0){i={...o,single:!0};continue}else n===1&&i!=null&&(yield{...i,block:void 0,single:void 0},i=void 0);yield{...o,block:void 0}}i!=null&&(yield i)}function Vw(r){return r.single===!0}var _S=(r,e,t)=>async function(i){if(i.length===1&&Vw(i[0])&&t.reduceSingleLeafToSelf){let l=i[0],d=l.block;return Vw(l)&&(r.mtime!==void 0||r.mode!==void 0)&&(l.unixfs=new j({type:"file",mtime:r.mtime,mode:r.mode,data:l.block}),d={Data:l.unixfs.marshal(),Links:[]},l.block=ce(Te(d)),l.cid=await fr(l.block,e,{...t,cidVersion:t.cidVersion}),l.size=BigInt(l.block.length)),t.onProgress?.(new M("unixfs:importer:progress:file:layout",{cid:l.cid,path:l.originalPath})),{cid:l.cid,path:r.path,unixfs:l.unixfs,size:l.size,originalPath:l.originalPath}}let o=new j({type:"file",mtime:r.mtime,mode:r.mode}),s=i.filter(l=>l.cid.code===Ae&&l.size>0||l.unixfs!=null&&l.unixfs.data==null&&l.unixfs.fileSize()>0n?!0:!!l.unixfs?.data?.length).map(l=>l.cid.code===Ae?(o.addBlockSize(l.size),{Name:"",Tsize:Number(l.size),Hash:l.cid}):(l.unixfs==null||l.unixfs.data==null?o.addBlockSize(l.unixfs?.fileSize()??0n):o.addBlockSize(BigInt(l.unixfs.data.length)),{Name:"",Tsize:Number(l.size),Hash:l.cid})),a={Data:o.marshal(),Links:s},c=ce(Te(a)),u=await fr(c,e,t);return t.onProgress?.(new M("unixfs:importer:progress:file:layout",{cid:u,path:r.originalPath})),{cid:u,path:r.path,unixfs:o,size:BigInt(c.length+a.Links.reduce((l,d)=>l+(d.Tsize??0),0)),originalPath:r.originalPath,block:c}},Mw=async(r,e,t)=>t.layout(AS(r,e,t),_S(r,e,t));function SS(r){return Symbol.iterator in r}function IS(r){return Symbol.asyncIterator in r}function BS(r){try{if(r instanceof Uint8Array)return async function*(){yield r}();if(SS(r))return async function*(){yield*r}();if(IS(r))return r}catch{throw(0,zh.default)(new Error("Content was invalid"),"ERR_INVALID_CONTENT")}throw(0,zh.default)(new Error("Content was invalid"),"ERR_INVALID_CONTENT")}function Hw(r){return async function*(t,n){for await(let i of t){let o;if(i.path!=null&&(o=i.path,i.path=i.path.split("/").filter(s=>s!=null&&s!==".").join("/")),kS(i)){let s={path:i.path,mtime:i.mtime,mode:i.mode,content:async function*(){let a=0n;for await(let c of r.chunker(r.chunkValidator(BS(i.content)))){let u=BigInt(c.byteLength);a+=u,r.onProgress?.(new M("unixfs:importer:progress:file:read",{bytesRead:a,chunkSize:u,path:i.path})),yield c}}(),originalPath:o};yield async()=>Mw(s,n,r)}else if(i.path!=null){let s={path:i.path,mtime:i.mtime,mode:i.mode,originalPath:o};yield async()=>Fw(s,n,r)}else throw new Error("Import candidate must have content or path or both")}}}function kS(r){return r.content!=null}var Kh=Q(Ce(),1);var $w=()=>async function*(e){for await(let t of e){if(t.length===void 0)throw(0,Kh.default)(new Error("Content was invalid"),"ERR_INVALID_CONTENT");if(typeof t=="string"||t instanceof String)yield V(t.toString());else if(Array.isArray(t))yield Uint8Array.from(t);else if(t instanceof Uint8Array)yield t;else throw(0,Kh.default)(new Error("Content was invalid"),"ERR_INVALID_CONTENT")}};var RS=174;function aa(r){let e=r?.maxChildrenPerNode??RS;return async function t(n,i){let o=[];for await(let s of ia(n,e))o.push(await i(s));return o.length>1?t(o,i):o[0]}}var Dr=class{options;root;dir;path;dirty;flat;parent;parentKey;unixfs;mode;mtime;cid;size;nodeSize;constructor(e,t){this.options=t??{},this.root=e.root,this.dir=e.dir,this.path=e.path,this.dirty=e.dirty,this.flat=e.flat,this.parent=e.parent,this.parentKey=e.parentKey,this.unixfs=e.unixfs,this.mode=e.mode,this.mtime=e.mtime}},ca=F.parse("QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn"),la=F.parse("zdj7WbTaiJT1fgatdet9Ei9iDB5hdCxkbVyhyh8YTUnXMiwYi");var Oi=class extends Dr{_children;constructor(e,t){super(e,t),this._children=new Map}async put(e,t){this.cid=void 0,this.size=void 0,this.nodeSize=void 0,this._children.set(e,t)}async get(e){return Promise.resolve(this._children.get(e))}childCount(){return this._children.size}directChildrenCount(){return this.childCount()}onlyChild(){return this._children.values().next().value}async*eachChildSeries(){for(let[e,t]of this._children.entries())yield{key:e,child:t}}estimateNodeSize(){if(this.nodeSize!==void 0)return this.nodeSize;this.nodeSize=0;for(let[e,t]of this._children.entries())t.size!=null&&t.cid!=null&&(this.nodeSize+=e.length+(this.options.cidVersion===1?la.bytes.byteLength:ca.bytes.byteLength));return this.nodeSize}async*flush(e){let t=[];for(let[c,u]of this._children.entries()){let l=u;if(u instanceof Dr)for await(let d of u.flush(e))l=d,yield d;l.size!=null&&l.cid!=null&&t.push({Name:c,Tsize:Number(l.size),Hash:l.cid})}let n=new j({type:"directory",mtime:this.mtime,mode:this.mode}),i={Data:n.marshal(),Links:t},o=ce(Te(i)),s=await fr(o,e,this.options),a=o.length+i.Links.reduce((c,u)=>c+(u.Tsize==null?0:u.Tsize),0);this.cid=s,this.size=a,yield{cid:s,unixfs:n,path:this.path,size:BigInt(a)}}};var zl=Q(Gw(),1);function TS(r){let e=new Array(4);for(let t=0;t<4;t++)e[t]=r&255,r=r>>8;return new Uint8Array(e)}var H9=di({name:"murmur3-32",code:35,encode:r=>TS(zl.default.x86.hash32(r))}),Pi=di({name:"murmur3-128",code:34,encode:r=>$i.fromHex(zl.default.x64.hash128(r))}),$9=di({name:"murmur3-x64-64",code:34,encode:r=>$i.fromHex(zl.default.x64.hash128(r)).subarray(0,8)});var Ww=Q(Kl(),1);var Ot=class r{_options;_popCount;_parent;_posAtParent;_children;key;constructor(e,t,n=0){this._options=e,this._popCount=0,this._parent=t,this._posAtParent=n,this._children=new Ww.default,this.key=null}async put(e,t){let n=await this._findNewBucketAndPos(e);n.bucket._putAt(n,e,t)}async get(e){let t=await this._findChild(e);if(t!=null)return t.value}async del(e){let t=await this._findPlace(e),n=t.bucket._at(t.pos);n!=null&&n.key===e&&t.bucket._delAt(t.pos)}leafCount(){return this._children.compactArray().reduce((t,n)=>n instanceof r?t+n.leafCount():t+1,0)}childrenCount(){return this._children.length}onlyChild(){return this._children.get(0)}*eachLeafSeries(){let e=this._children.compactArray();for(let t of e)t instanceof r?yield*t.eachLeafSeries():yield t}serialize(e,t){let n=[];return t(this._children.reduce((i,o,s)=>(o!=null&&(o instanceof r?i.push(o.serialize(e,t)):i.push(e(o,s))),i),n))}async asyncTransform(e,t){return jw(this,e,t)}toJSON(){return this.serialize(DS,OS)}prettyPrint(){return JSON.stringify(this.toJSON(),null," ")}tableSize(){return Math.pow(2,this._options.bits)}async _findChild(e){let t=await this._findPlace(e),n=t.bucket._at(t.pos);if(!(n instanceof r)&&n!=null&&n.key===e)return n}async _findPlace(e){let t=this._options.hash(typeof e=="string"?V(e):e),n=await t.take(this._options.bits),i=this._children.get(n);return i instanceof r?i._findPlace(t):{bucket:this,pos:n,hash:t,existingChild:i}}async _findNewBucketAndPos(e){let t=await this._findPlace(e);if(t.existingChild!=null&&t.existingChild.key!==e){let n=new r(this._options,t.bucket,t.pos);t.bucket._putObjectAt(t.pos,n);let i=await n._findPlace(t.existingChild.hash);return i.bucket._putAt(i,t.existingChild.key,t.existingChild.value),n._findNewBucketAndPos(t.hash)}return t}_putAt(e,t,n){this._putObjectAt(e.pos,{key:t,value:n,hash:e.hash})}_putObjectAt(e,t){this._children.get(e)==null&&this._popCount++,this._children.set(e,t)}_delAt(e){if(e===-1)throw new Error("Invalid position");this._children.get(e)!=null&&this._popCount--,this._children.unset(e),this._level()}_level(){if(this._parent!=null&&this._popCount<=1)if(this._popCount===1){let e=this._children.find(US);if(e!=null&&!(e instanceof r)){let t=e.hash;t.untake(this._options.bits);let n={pos:this._posAtParent,hash:t,bucket:this._parent};this._parent._putAt(n,e.key,e.value)}}else this._parent._delAt(this._posAtParent)}_at(e){return this._children.get(e)}};function US(r){return!!r}function DS(r,e){return r.key}function OS(r){return r}async function jw(r,e,t){let n=[];for(let i of r._children.compactArray())if(i instanceof Ot)await jw(i,e,t);else{let o=await e(i);n.push({bitField:r._children.bitField(),children:o})}return t(n)}var PS=[255,254,252,248,240,224,192,128],FS=[1,3,7,15,31,63,127,255],Gl=class{_value;_currentBytePos;_currentBitPos;constructor(e){this._value=e,this._currentBytePos=e.length-1,this._currentBitPos=7}availableBits(){return this._currentBitPos+1+this._currentBytePos*8}totalBits(){return this._value.length*8}take(e){let t=e,n=0;for(;t>0&&this._haveBits();){let i=this._value[this._currentBytePos],o=this._currentBitPos+1,s=Math.min(o,t),a=VS(i,o-s,s);n=(n<<s)+a,t-=s,this._currentBitPos-=s,this._currentBitPos<0&&(this._currentBitPos=7,this._currentBytePos--)}return n}untake(e){for(this._currentBitPos+=e;this._currentBitPos>7;)this._currentBitPos-=8,this._currentBytePos+=1}_haveBits(){return this._currentBytePos>=0}};function VS(r,e,t){let n=MS(e,t);return(r&n)>>>e}function MS(r,e){return PS[r]&FS[Math.min(e+r-1,7)]}function Xw(r){function e(t){return t instanceof ql?t:new ql(t,r)}return e}var ql=class{_value;_hashFn;_depth;_availableBits;_currentBufferIndex;_buffers;constructor(e,t){if(!(e instanceof Uint8Array))throw new Error("can only hash Uint8Arrays");this._value=e,this._hashFn=t,this._depth=-1,this._availableBits=0,this._currentBufferIndex=0,this._buffers=[]}async take(e){let t=e;for(;this._availableBits<t;)await this._produceMoreBits();let n=0;for(;t>0;){let i=this._buffers[this._currentBufferIndex],o=Math.min(i.availableBits(),t),s=i.take(o);n=(n<<o)+s,t-=o,this._availableBits-=o,i.availableBits()===0&&this._currentBufferIndex++}return n}untake(e){let t=e;for(;t>0;){let n=this._buffers[this._currentBufferIndex],i=Math.min(n.totalBits()-n.availableBits(),t);n.untake(i),t-=i,this._availableBits+=i,this._currentBufferIndex>0&&n.totalBits()===n.availableBits()&&(this._depth--,this._currentBufferIndex--)}}async _produceMoreBits(){this._depth++;let e=this._depth>0?ye([this._value,Uint8Array.from([this._depth])]):this._value,t=await this._hashFn(e),n=new Gl(t);this._buffers.push(n),this._availableBits+=n.availableBits()}};function Fo(r){if(r==null||r.hashFn==null)throw new Error("please define an options.hashFn");let e={bits:r.bits??8,hash:Xw(r.hashFn)};return new Ot(e)}async function HS(r){return(await Pi.encode(r)).slice(0,8).reverse()}var Zw=BigInt(34),$S=8,Gh=class extends Dr{_bucket;constructor(e,t){super(e,t),this._bucket=Fo({hashFn:HS,bits:t.shardFanoutBits??$S})}async put(e,t){this.cid=void 0,this.size=void 0,this.nodeSize=void 0,await this._bucket.put(e,t)}async get(e){return this._bucket.get(e)}childCount(){return this._bucket.leafCount()}directChildrenCount(){return this._bucket.childrenCount()}onlyChild(){return this._bucket.onlyChild()}async*eachChildSeries(){for await(let{key:e,value:t}of this._bucket.eachLeafSeries())yield{key:e,child:t}}estimateNodeSize(){return this.nodeSize!==void 0?this.nodeSize:(this.nodeSize=e2(this._bucket,this,this.options),this.nodeSize)}async*flush(e){for await(let t of Qw(this._bucket,e,this,this.options))yield{...t,path:this.path}}},Jw=Gh;async function*Qw(r,e,t,n){let i=r._children,o=(r.tableSize()-1).toString(16).length,s=[],a=0n;for(let h=0;h<i.length;h++){let m=i.get(h);if(m==null)continue;let y=h.toString(16).toUpperCase().padStart(o,"0");if(m instanceof Ot){let g;for await(let E of Qw(m,e,null,n))g=E;if(g==null)throw new Error("Could not flush sharded directory, no subshard found");s.push({Name:y,Tsize:Number(g.size),Hash:g.cid}),a+=g.size}else if(zS(m.value)){let g=m.value,E;for await(let _ of g.flush(e))E=_,yield E;if(E==null)throw new Error("Did not flush dir");let x=y+m.key;s.push({Name:x,Tsize:Number(E.size),Hash:E.cid}),a+=E.size}else{let g=m.value;if(g.cid==null)continue;let E=y+m.key,x=g.size;s.push({Name:E,Tsize:Number(x),Hash:g.cid}),a+=BigInt(x??0)}}let c=Uint8Array.from(i.bitField().reverse()),u=new j({type:"hamt-sharded-directory",data:c,fanout:BigInt(r.tableSize()),hashType:Zw,mtime:t?.mtime,mode:t?.mode}),l={Data:u.marshal(),Links:s},d=ce(Te(l)),p=await fr(d,e,n),f=BigInt(d.byteLength)+a;yield{cid:p,unixfs:u,size:f}}function zS(r){return typeof r.flush=="function"}function e2(r,e,t){let n=r._children,i=(r.tableSize()-1).toString(16).length,o=[];for(let u=0;u<n.length;u++){let l=n.get(u);if(l==null)continue;let d=u.toString(16).toUpperCase().padStart(i,"0");if(l instanceof Ot){let p=e2(l,null,t);o.push({Name:d,Tsize:Number(p),Hash:t.cidVersion===0?ca:la})}else if(typeof l.value.flush=="function"){let f=l.value.nodeSize();o.push({Name:d+l.key,Tsize:Number(f),Hash:t.cidVersion===0?ca:la})}else{let p=l.value;if(p.cid==null)continue;let f=d+l.key,h=p.size;o.push({Name:f,Tsize:Number(h),Hash:p.cid})}}let s=Uint8Array.from(n.bitField().reverse()),a=new j({type:"hamt-sharded-directory",data:s,fanout:BigInt(r.tableSize()),hashType:Zw,mtime:e?.mtime,mode:e?.mode});return ce(Te({Data:a.marshal(),Links:o})).length}async function qh(r,e,t,n){let i=e;e instanceof Oi&&e.estimateNodeSize()>t&&(i=await KS(e,n));let o=i.parent;if(o!=null){if(i!==e){if(r!=null&&(r.parent=i),i.parentKey==null)throw new Error("No parent key found");await o.put(i.parentKey,i)}return qh(i,o,t,n)}return i}async function KS(r,e){let t=new Jw({root:r.root,dir:!0,parent:r.parent,parentKey:r.parentKey,path:r.path,dirty:r.dirty,flat:!1,mtime:r.mtime,mode:r.mode},e);for await(let{key:n,child:i}of r.eachChildSeries())await t.put(n,i);return t}var t2=(r="")=>r.split(/(?<!\\)\//).filter(Boolean);async function GS(r,e,t){let n=t2(r.path??""),i=n.length-1,o=e,s="";for(let a=0;a<n.length;a++){let c=n[a];s+=`${s!==""?"/":""}${c}`;let u=a===i;if(o.dirty=!0,o.cid=void 0,o.size=void 0,u)await o.put(c,r),e=await qh(null,o,t.shardSplitThresholdBytes,t);else{let l=await o.get(c);(l==null||!(l instanceof Dr))&&(l=new Oi({root:!1,dir:!0,parent:o,parentKey:c,path:s,dirty:!0,flat:!0,mtime:l?.unixfs?.mtime,mode:l?.unixfs?.mode},t)),await o.put(c,l),o=l}}return e}async function*r2(r,e){if(!(r instanceof Dr)){r.unixfs?.isDirectory()===!0&&(yield r);return}yield*r.flush(e)}function n2(r){return async function*(t,n){let i=new Oi({root:!0,dir:!0,path:"",dirty:!0,flat:!0},r),o,s=!1;for await(let a of t){if(a==null)continue;let c=`${a.originalPath??""}`.split("/")[0];c!=null&&c!==""&&(o==null?(o=c,s=!0):o!==c&&(s=!1)),i=await GS(a,i,r),(a.unixfs==null||!a.unixfs.isDirectory())&&(yield a)}if(r.wrapWithDirectory||s&&i.childCount()>1)yield*r2(i,n);else for await(let a of i.eachChildSeries())a!=null&&(yield*r2(a.child,n))}}async function*ni(r,e,t={}){let n;Symbol.asyncIterator in r||Symbol.iterator in r?n=r:n=[r];let i=t.wrapWithDirectory??!1,o=t.shardSplitThresholdBytes??262144,s=t.shardFanoutBits??8,a=t.cidVersion??1,c=t.rawLeaves??!0,u=t.leafType??"file",l=t.fileImportConcurrency??50,d=t.blockWriteConcurrency??10,p=t.reduceSingleLeafToSelf??!0,f=t.chunker??sa(),h=t.chunkValidator??$w(),m=t.dagBuilder??Hw({chunker:f,chunkValidator:h,wrapWithDirectory:i,layout:t.layout??aa(),bufferImporter:t.bufferImporter??Pw({cidVersion:a,rawLeaves:c,leafType:u,onProgress:t.onProgress}),blockWriteConcurrency:d,reduceSingleLeafToSelf:p,cidVersion:a,onProgress:t.onProgress}),y=t.treeBuilder??n2({wrapWithDirectory:i,shardSplitThresholdBytes:o,shardFanoutBits:s,cidVersion:a,onProgress:t.onProgress});for await(let g of y(oa(m(n,e),l),e))yield{cid:g.cid,path:g.path,unixfs:g.unixfs,size:g.size}}async function Yl(r,e,t={}){let n=await Ii(ni([r],e,t));if(n==null)throw(0,Yh.default)(new Error("Nothing imported"),"ERR_INVALID_PARAMS");return n}async function i2(r,e,t={}){let n=await Ii(ni([r],e,t));if(n==null)throw(0,Yh.default)(new Error("Nothing imported"),"ERR_INVALID_PARAMS");return n}async function o2(r,e,t={}){return Yl({content:r},e,t)}async function s2(r,e,t={}){return Yl({content:r},e,t)}var ZS=Q(Ce(),1),JS=Q(E2(),1);var pa={cidVersion:1,rawLeaves:!0,layout:aa({maxChildrenPerNode:1024}),chunker:sa({chunkSize:1048576})};async function*x2(r,e,t={}){yield*ni(r,e,{...pa,...t})}async function b2(r,e,t={}){let{cid:n}=await o2(r,e,{...pa,...t});return n}async function v2(r,e,t={}){let{cid:n}=await s2(r,e,{...pa,...t});return n}async function A2(r,e,t={}){let{cid:n}=await Yl(r,e,{...pa,...t});return n}async function _2(r,e,t={}){let{cid:n}=await i2({...r,path:r.path??"-"},e,{...pa,...t});return n}var jl=Q(Ce(),1);function QS(r){return r[Symbol.asyncIterator]!=null}function e4(r){if(QS(r))return(async()=>{let t;for await(let n of r)t=n;return t})();let e;for(let t of r)e=t;return e}var ii=e4;var H2=Q(Ce(),1);var S2=Q(Ce(),1);function Vo(r,e,t,n,i,o,s){let a=r,c=i;for(;o.length>0;){let u=o[0];if(u in a){o.shift(),c=`${c}/${u}`;let l=F.asCID(a[u]);if(l!=null)return{entry:{type:"object",name:n,path:i,cid:t,node:e,depth:s,size:BigInt(e.length),content:async function*(){yield r}},next:{cid:l,name:u,path:c,toResolve:o}};a=a[u]}else throw(0,S2.default)(new Error(`No property named ${u} found in node ${t}`),"ERR_NO_PROP")}return{entry:{type:"object",name:n,path:i,cid:t,node:e,depth:s,size:BigInt(e.length),content:async function*(){yield r}}}}var t4=async(r,e,t,n,i,o,s,a)=>{let c=await s.get(r,a),u=ki(c);return Vo(u,c,r,e,t,n,o)},I2=t4;var r4=async(r,e,t,n,i,o,s,a)=>{let c=await s.get(r,a),u=vl(c);return Vo(u,c,r,e,t,n,o)},B2=r4;var k2=Q(Ce(),1);function n4(r,e,t,n){let i=BigInt(r.length),o=BigInt(e+i);return t>=o||n<e?new Uint8Array(0):(n>=e&&n<o&&(r=r.subarray(0,Number(n-e))),t>=e&&t<o&&(r=r.subarray(Number(t-e))),r)}var Fi=n4;var ma=Q(Ce(),1),i4=(r,e=0,t=r)=>{let n=BigInt(r),i=BigInt(e??0),o=BigInt(t);if(o!==n&&(o=i+o),o>n&&(o=n),i<0n)throw(0,ma.default)(new Error("Offset must be greater than or equal to 0"),"ERR_INVALID_PARAMS");if(i>n)throw(0,ma.default)(new Error("Offset must be less than the file size"),"ERR_INVALID_PARAMS");if(o<0n)throw(0,ma.default)(new Error("Length must be greater than or equal to 0"),"ERR_INVALID_PARAMS");if(o>n)throw(0,ma.default)(new Error("Length must be less than the file size"),"ERR_INVALID_PARAMS");return{start:i,end:o}},Mo=i4;var o4=r=>{async function*e(t={}){let{start:n,end:i}=Mo(r.length,t.offset,t.length),o=Fi(r,0n,n,i);t.onProgress?.(new M("unixfs:exporter:progress:identity",{bytesRead:BigInt(o.byteLength),totalBytes:i-n,fileSize:BigInt(r.byteLength)})),yield o}return e},s4=async(r,e,t,n,i,o,s,a)=>{if(n.length>0)throw(0,k2.default)(new Error(`No link named ${t} found in raw node ${r}`),"ERR_NOT_FOUND");let c=st(r.multihash.bytes);return{entry:{type:"identity",name:e,path:t,cid:r,content:o4(c.digest),depth:o,size:BigInt(c.digest.length),node:c.digest}}},R2=s4;var a4=async(r,e,t,n,i,o,s,a)=>{let c=await s.get(r,a),u=l0(c);return Vo(u,c,r,e,t,n,o)},T2=a4;var N2=Q(Ce(),1);var c4=r=>{async function*e(t={}){let{start:n,end:i}=Mo(r.length,t.offset,t.length),o=Fi(r,0n,n,i);t.onProgress?.(new M("unixfs:exporter:progress:raw",{bytesRead:BigInt(o.byteLength),totalBytes:i-n,fileSize:BigInt(r.byteLength)})),yield o}return e},l4=async(r,e,t,n,i,o,s,a)=>{if(n.length>0)throw(0,N2.default)(new Error(`No link named ${t} found in raw node ${r}`),"ERR_NOT_FOUND");let c=await s.get(r,a);return{entry:{type:"raw",name:e,path:t,cid:r,content:c4(c),depth:o,size:BigInt(c.length),node:c}}},C2=l4;var ga=Q(Ce(),1);var ya=Q(Ce(),1);var u4=async function(r){return(await Pi.encode(r)).slice(0,8).reverse()},d4=async(r,e,t)=>{let n=(e.tableSize()-1).toString(16).length;await Promise.all(r.map(async i=>{if(i.Name==null)throw new Error("Unexpected Link without a Name");if(i.Name.length===n){let o=parseInt(i.Name,16);e._putObjectAt(o,new Ot({hash:t._options.hash,bits:t._options.bits},e,o));return}await t.put(i.Name.substring(2),!0)}))},L2=(r,e)=>r.toString(16).toUpperCase().padStart(e,"0").substring(0,e),f4=r=>{let e=r.bucket,t=[];for(;e._parent!=null;)t.push(e),e=e._parent;return t.push(e),t.reverse()},U2=async(r,e,t,n,i)=>{if(n==null){if(r.Data==null)throw(0,ya.default)(new Error("no data in PBNode"),"ERR_NOT_UNIXFS");let d;try{d=j.unmarshal(r.Data)}catch(f){throw(0,ya.default)(f,"ERR_NOT_UNIXFS")}if(d.type!=="hamt-sharded-directory")throw(0,ya.default)(new Error("not a HAMT"),"ERR_NOT_UNIXFS");if(d.fanout==null)throw(0,ya.default)(new Error("missing fanout"),"ERR_NOT_UNIXFS");let p=Fo({hashFn:u4,bits:Math.log2(Number(d.fanout))});n={rootBucket:p,hamtDepth:1,lastBucket:p}}let o=(n.lastBucket.tableSize()-1).toString(16).length;await d4(r.Links,n.lastBucket,n.rootBucket);let s=await n.rootBucket._findNewBucketAndPos(e),a=L2(s.pos,o),c=f4(s);c.length>n.hamtDepth&&(n.lastBucket=c[n.hamtDepth],a=L2(n.lastBucket._posAtParent,o));let u=r.Links.find(d=>{if(d.Name==null)return!1;let p=d.Name.substring(0,o),f=d.Name.substring(o);return!(p!==a||f!==""&&f!==e)});if(u==null)return;if(u.Name!=null&&u.Name.substring(o)===e)return u.Hash;n.hamtDepth++;let l=await t.get(u.Hash,i);return r=Se(l),U2(r,e,t,n,i)},D2=U2;var h4=(r,e,t,n,i,o,s)=>{async function*a(c={}){let u=c.offset??0,l=c.length??e.Links.length,d=e.Links.slice(u,l);c.onProgress?.(new M("unixfs:exporter:walk:directory",{cid:r})),yield*gt(d,p=>at(p,f=>async()=>{let h=f.Name??"",m=`${n}/${h}`;return(await i(f.Hash,h,m,[],o+1,s,c)).entry}),p=>Ni(p,{ordered:!0,concurrency:c.blockReadConcurrency}),p=>bt(p,f=>f!=null))}return a},O2=h4;var Vi=Q(Ce(),1);async function P2(r,e,t,n,i,o,s){if(e instanceof Uint8Array){let u=Fi(e,n,i,o);t.push(u);return}if(e.Data==null)throw(0,Vi.default)(new Error("no data in PBNode"),"ERR_NOT_UNIXFS");let a;try{a=j.unmarshal(e.Data)}catch(u){throw(0,Vi.default)(u,"ERR_NOT_UNIXFS")}if(a.data!=null){let u=a.data,l=Fi(u,n,i,o);t.push(l),n+=BigInt(l.byteLength)}let c=[];if(e.Links.length!==a.blockSizes.length)throw(0,Vi.default)(new Error("Inconsistent block sizes and dag links"),"ERR_NOT_UNIXFS");for(let u=0;u<e.Links.length;u++){let l=e.Links[u],d=n,p=d+a.blockSizes[u];if((i>=d&&i<p||o>=d&&o<=p||i<d&&o>p)&&c.push({link:l,blockStart:n}),n=p,n>o)break}await gt(c,u=>at(u,l=>async()=>{let d=await r.get(l.link.Hash,s);return{...l,block:d}}),u=>Ni(u,{ordered:!0,concurrency:s.blockReadConcurrency}),async u=>{for await(let{link:l,block:d,blockStart:p}of u){let f;switch(l.Hash.code){case ve:f=Se(d);break;case Ae:f=d;break;default:t.end((0,Vi.default)(new Error(`Unsupported codec: ${l.Hash.code}`),"ERR_NOT_UNIXFS"));return}let h=new nt({concurrency:1});h.on("error",m=>{t.end(m)}),h.add(async()=>{s.onProgress?.(new M("unixfs:exporter:walk:file",{cid:l.Hash})),await P2(r,f,t,p,i,o,s)}),await h.onIdle()}}),n>=o&&t.end()}var p4=(r,e,t,n,i,o,s)=>{async function*a(c={}){let u=t.fileSize();if(u===void 0)throw new Error("File was a directory");let{start:l,end:d}=Mo(u,c.offset,c.length);if(d===0n)return;let p=0n,f=d-l,h=Kt();c.onProgress?.(new M("unixfs:exporter:walk:file",{cid:r})),P2(s,e,h,0n,l,d,c).catch(m=>{h.end(m)});for await(let m of h)if(m!=null){if(p+=BigInt(m.byteLength),p>f)throw h.end(),(0,Vi.default)(new Error("Read too many bytes - the file size reported by the UnixFS data in the root node may be incorrect"),"ERR_OVER_READ");p===f&&h.end(),c.onProgress?.(new M("unixfs:exporter:progress:unixfs:file",{bytesRead:p,totalBytes:f,fileSize:u})),yield m}if(p<f)throw(0,Vi.default)(new Error("Traversed entire DAG but did not read enough bytes"),"ERR_UNDER_READ")}return a},Jh=p4;var Wl=Q(Ce(),1);var m4=(r,e,t,n,i,o,s)=>{function a(c={}){return c.onProgress?.(new M("unixfs:exporter:walk:hamt-sharded-directory",{cid:r})),F2(e,n,i,o,s,c)}return a};async function*F2(r,e,t,n,i,o){let s=r.Links;if(r.Data==null)throw(0,Wl.default)(new Error("no data in PBNode"),"ERR_NOT_UNIXFS");let a;try{a=j.unmarshal(r.Data)}catch(l){throw(0,Wl.default)(l,"ERR_NOT_UNIXFS")}if(a.fanout==null)throw(0,Wl.default)(new Error("missing fanout"),"ERR_NOT_UNIXFS");let c=(a.fanout-1n).toString(16).length,u=gt(s,l=>at(l,d=>async()=>{let p=d.Name!=null?d.Name.substring(c):null;if(p!=null&&p!==""){let f=await t(d.Hash,p,`${e}/${p}`,[],n+1,i,o);return{entries:f.entry==null?[]:[f.entry]}}else{let f=await i.get(d.Hash,o);return r=Se(f),o.onProgress?.(new M("unixfs:exporter:walk:hamt-sharded-directory",{cid:d.Hash})),{entries:F2(r,e,t,n,i,o)}}}),l=>Ni(l,{ordered:!0,concurrency:o.blockReadConcurrency}));for await(let{entries:l}of u)yield*l}var V2=m4;var y4=(r,e)=>r.Links.find(n=>n.Name===e)?.Hash,g4={raw:Jh,file:Jh,directory:O2,"hamt-sharded-directory":V2,metadata:(r,e,t,n,i,o,s)=>()=>[],symlink:(r,e,t,n,i,o,s)=>()=>[]},w4=async(r,e,t,n,i,o,s,a)=>{let c=await s.get(r,a),u=Se(c),l,d;if(e==null&&(e=r.toString()),u.Data==null)throw(0,ga.default)(new Error("no data in PBNode"),"ERR_NOT_UNIXFS");try{l=j.unmarshal(u.Data)}catch(f){throw(0,ga.default)(f,"ERR_NOT_UNIXFS")}if(t==null&&(t=e),n.length>0){let f;if(l?.type==="hamt-sharded-directory"?f=await D2(u,n[0],s):f=y4(u,n[0]),f==null)throw(0,ga.default)(new Error("file does not exist"),"ERR_NOT_FOUND");let h=n.shift(),m=`${t}/${h}`;d={cid:f,toResolve:n,name:h??"",path:m}}let p=g4[l.type](r,u,l,t,i,o,s);if(p==null)throw(0,ga.default)(new Error("could not find content exporter"),"ERR_NOT_FOUND");return l.isDirectory()?{entry:{type:"directory",name:e,path:t,cid:r,content:p,unixfs:l,depth:o,node:u,size:l.fileSize()},next:d}:{entry:{type:"file",name:e,path:t,cid:r,content:p,unixfs:l,depth:o,node:u,size:l.fileSize()},next:d}},M2=w4;var E4={[ve]:M2,[Ae]:C2,[Yn]:I2,[jn]:B2,[et.code]:R2,[Rn]:T2},$2=async(r,e,t,n,i,o,s)=>{let a=E4[r.code];if(a==null)throw(0,H2.default)(new Error(`No resolver for code ${r.code}`),"ERR_NO_RESOLVER");return a(r,e,t,n,$2,i,o,s)},z2=$2;var x4=(r="")=>(r.trim().match(/([^\\^/]|\\\/)+/g)??[]).filter(Boolean),b4=r=>{if(r instanceof Uint8Array)return{cid:F.decode(r),toResolve:[]};let e=F.asCID(r);if(e!=null)return{cid:e,toResolve:[]};if(typeof r=="string"){r.indexOf("/ipfs/")===0&&(r=r.substring(6));let t=x4(r);return{cid:F.parse(t[0]),toResolve:t.slice(1)}}throw(0,jl.default)(new Error(`Unknown path type ${r}`),"ERR_BAD_PATH")};async function*Qh(r,e,t={}){let{cid:n,toResolve:i}=b4(r),o=n.toString(),s=o,a=i.length;for(;;){let c=await z2(n,o,s,i,a,e,t);if(c.entry==null&&c.next==null)throw(0,jl.default)(new Error(`Could not resolve ${r}`),"ERR_NOT_FOUND");if(c.entry!=null&&(yield c.entry),c.next==null)return;i=c.next.toResolve,n=c.next.cid,o=c.next.name,s=c.next.path}}async function Ve(r,e,t={}){let n=await ii(Qh(r,e,t));if(n==null)throw(0,jl.default)(new Error(`Could not resolve ${r}`),"ERR_NOT_FOUND");return n}async function*Ho(r,e,t={}){let n=await Ve(r,e,t);if(n==null)return;if(yield n,n.type==="directory")for await(let o of i(n,t))yield o;async function*i(o,s){for await(let a of o.content(s))yield a,!(a instanceof Uint8Array)&&a.type==="directory"&&(yield*i(a,s))}}var J2=Q(Z2(),1),it=J2.default;var hr=class extends Error{name;code;constructor(e,t,n){super(e),this.name=t,this.code=n}},Or=class extends hr{constructor(e="not a Unixfs node"){super(e,"NotUnixFSError","ERR_NOT_UNIXFS")}},pt=class extends hr{constructor(e="invalid PBNode"){super(e,"InvalidPBNodeError","ERR_INVALID_PBNODE")}},xn=class extends hr{constructor(e="unknown error"){super(e,"InvalidPBNodeError","ERR_UNKNOWN_ERROR")}},wa=class extends hr{constructor(e="path already exists"){super(e,"AlreadyExistsError","ERR_ALREADY_EXISTS")}},Jl=class extends hr{constructor(e="path does not exist"){super(e,"DoesNotExistError","ERR_DOES_NOT_EXIST")}},Ko=class extends hr{constructor(e="no content"){super(e,"NoContentError","ERR_NO_CONTENT")}},Ql=class extends hr{constructor(e="not a file"){super(e,"NotAFileError","ERR_NOT_A_FILE")}},oi=class extends hr{constructor(e="not a directory"){super(e,"NotADirectoryError","ERR_NOT_A_DIRECTORY")}},ot=class extends hr{constructor(e="invalid parameters"){super(e,"InvalidParametersError","ERR_INVALID_PARAMETERS")}};var ip=Q(Kl(),1);function tu(r){function e(t){return t instanceof eu?t:new eu(t,r)}return e}var eu=class{_value;_hashFn;_depth;_availableBits;_currentBufferIndex;_buffers;constructor(e,t){if(!(e instanceof Uint8Array))throw new Error("can only hash Uint8Arrays");this._value=e,this._hashFn=t,this._depth=-1,this._availableBits=0,this._currentBufferIndex=0,this._buffers=[]}async take(e){let t=e;for(;this._availableBits<t;)await this._produceMoreBits();let n=0;for(;t>0;){let i=this._buffers[this._currentBufferIndex],o=Math.min(i.availableBits(),t),s=i.take(o);n=(n<<o)+s,t-=o,this._availableBits-=o,i.availableBits()===0&&this._currentBufferIndex++}return n}untake(e){let t=e;for(;t>0;){let n=this._buffers[this._currentBufferIndex],i=Math.min(n.totalBits()-n.availableBits(),t);n.untake(i),t-=i,this._availableBits+=i,this._currentBufferIndex>0&&n.totalBits()===n.availableBits()&&(this._depth--,this._currentBufferIndex--)}}async _produceMoreBits(){this._depth++;let e=this._depth>0?ye([this._value,Uint8Array.from([this._depth])]):this._value,t=await this._hashFn(e),n=new tp(t);this._buffers.push(n),this._availableBits+=n.availableBits()}},B4=[255,254,252,248,240,224,192,128],k4=[1,3,7,15,31,63,127,255],tp=class{_value;_currentBytePos;_currentBitPos;constructor(e){this._value=e,this._currentBytePos=e.length-1,this._currentBitPos=7}availableBits(){return this._currentBitPos+1+this._currentBytePos*8}totalBits(){return this._value.length*8}take(e){let t=e,n=0;for(;t>0&&this._haveBits();){let i=this._value[this._currentBytePos],o=this._currentBitPos+1,s=Math.min(o,t),a=R4(i,o-s,s);n=(n<<s)+a,t-=s,this._currentBitPos-=s,this._currentBitPos<0&&(this._currentBitPos=7,this._currentBytePos--)}return n}untake(e){for(this._currentBitPos+=e;this._currentBitPos>7;)this._currentBitPos-=8,this._currentBytePos+=1}_haveBits(){return this._currentBytePos>=0}};function R4(r,e,t){let n=T4(e,t);return(r&n)>>>e}function T4(r,e){return B4[r]&k4[Math.min(e+r-1,7)]}var Ea=BigInt(Pi.code),Mi=8;async function Go(r){return(await Pi.encode(r)).subarray(0,8).reverse()}var tE=Q(Kl(),1);var pr=async(r,e,t)=>{t.codec==null&&(t.codec=Oe);let n=await fe.digest(r),i=F.create(t.cidVersion,t.codec.code,n);return await e.put(i,r,{...t,signal:t.signal}),i};var rp=class{options;root;dir;path;dirty;flat;parent;parentKey;unixfs;mode;mtime;cid;size;nodeSize;constructor(e,t){this.options=t??{},this.root=e.root,this.dir=e.dir,this.path=e.path,this.dirty=e.dirty,this.flat=e.flat,this.parent=e.parent,this.parentKey=e.parentKey,this.unixfs=e.unixfs,this.mode=e.mode,this.mtime=e.mtime}},ru=class extends rp{_bucket;constructor(e,t){super(e,t),this._bucket=Fo({hashFn:Go,bits:8})}async put(e,t){this.cid=void 0,this.size=void 0,this.nodeSize=void 0,await this._bucket.put(e,t)}async get(e){return this._bucket.get(e)}childCount(){return this._bucket.leafCount()}directChildrenCount(){return this._bucket.childrenCount()}onlyChild(){return this._bucket.onlyChild()}async*eachChildSeries(){for await(let{key:e,value:t}of this._bucket.eachLeafSeries())yield{key:e,child:t}}estimateNodeSize(){return this.nodeSize!==void 0?this.nodeSize:(this.nodeSize=eE(this._bucket,this,this.options),this.nodeSize)}async*flush(e){for await(let t of Q2(this._bucket,e,this,this.options))yield{...t,path:this.path}}};async function*Q2(r,e,t,n){let i=r._children,o=[],s=0n;for(let f=0;f<i.length;f++){let h=i.get(f);if(h==null)continue;let m=f.toString(16).toUpperCase().padStart(2,"0");if(h instanceof Ot){let y;for await(let g of Q2(h,e,null,n))y=g;if(y==null)throw new Error("Could not flush sharded directory, no subshard found");o.push({Name:m,Tsize:Number(y.size),Hash:y.cid}),s+=y.size}else if(N4(h.value)){let y=h.value,g;for await(let x of y.flush(e))g=x,yield g;if(g==null)throw new Error("Did not flush dir");let E=m+h.key;o.push({Name:E,Tsize:Number(g.size),Hash:g.cid}),s+=g.size}else{let y=h.value;if(y.cid==null)continue;let g=m+h.key,E=y.size;o.push({Name:g,Tsize:Number(E),Hash:y.cid}),s+=BigInt(E??0)}}let a=Uint8Array.from(i.bitField().reverse()),c=new j({type:"hamt-sharded-directory",data:a,fanout:BigInt(r.tableSize()),hashType:Ea,mtime:t?.mtime,mode:t?.mode}),u={Data:c.marshal(),Links:o},l=ce(Te(u)),d=await pr(l,e,n),p=BigInt(l.byteLength)+s;yield{cid:d,unixfs:c,size:p}}function N4(r){return typeof r.flush=="function"}function eE(r,e,t){let n=r._children,i=[];for(let c=0;c<n.length;c++){let u=n.get(c);if(u==null)continue;let l=c.toString(16).toUpperCase().padStart(2,"0");if(u instanceof Ot){let d=eE(u,null,t);i.push({Name:l,Tsize:Number(d),Hash:t.cidVersion===0?nu:iu})}else if(typeof u.value.flush=="function"){let p=u.value.nodeSize();i.push({Name:l+u.key,Tsize:Number(p),Hash:t.cidVersion===0?nu:iu})}else{let d=u.value;if(d.cid==null)continue;let p=l+u.key,f=d.size;i.push({Name:p,Tsize:Number(f),Hash:d.cid})}}let o=Uint8Array.from(n.bitField().reverse()),s=new j({type:"hamt-sharded-directory",data:o,fanout:BigInt(r.tableSize()),hashType:Ea,mtime:e?.mtime,mode:e?.mode});return ce(Te({Data:s.marshal(),Links:i})).length}var nu=F.parse("QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn"),iu=F.parse("zdj7WbTaiJT1fgatdet9Ei9iDB5hdCxkbVyhyh8YTUnXMiwYi");var np=oe("helia:unixfs:commands:utils:hamt-utils"),ou=r=>r.toString(16).toUpperCase().padStart(2,"0").substring(0,2),rE=async(r,e,t)=>{let n=new ru({root:!0,dir:!0,parent:void 0,parentKey:void 0,path:"",dirty:!0,flat:!1,mtime:t.mtime,mode:t.mode},t);for(let o=0;o<e.length;o++)await n._bucket.put(e[o].name,{size:e[o].size,cid:e[o].cid});let i=await ii(n.flush(r));if(i==null)throw new Error("Flushing shard yielded no result");return i},su=async(r,e,t)=>{let n=j.unmarshal(r[0].node.Data??new Uint8Array(0)),i=BigInt(Math.pow(2,Mi));r.reverse();let o,s;for(let a=0;a<r.length;a++){let c=a===r.length-1,u=r[a],l=Uint8Array.from(u.children.bitField().reverse()),d=new j({type:"hamt-sharded-directory",data:l,fanout:i,hashType:Ea});c&&(d.mtime=n.mtime,d.mode=n.mode),s={Data:d.marshal(),Links:u.node.Links};let p=ce(Te(s));if(o=await pr(p,e,t),!c){let f=r[a+1];if(f==null)throw new Error("Was not operating on shard root but also had no parent?");np("updating link in parent sub-shard with prefix %s",f.prefix),f.node.Links=f.node.Links.filter(h=>h.Name!==f.prefix),f.node.Links.push({Name:f.prefix,Hash:o,Tsize:u.node.Links.reduce((h,m)=>h+(m.Tsize??0),p.byteLength)})}}if(o==null||s==null)throw new Error("Noting persisted");return{cid:o,node:s}},au=async(r,e,t,n)=>{let o=tu(Go)(V(e)),s=[];for(;;){let a=await t.get(r,n),c=Se(a),u=new tE.default,l=await o.take(Mi),d=ou(l);s.push({prefix:d,children:u,node:c});let p;for(let h of c.Links){let m=h.Name??"";if(m.length<2)throw new Error("Invalid HAMT - link name was too short");let y=parseInt(m.substring(0,2),16);u.set(y,!0),m.startsWith(d)&&(p=h)}if(p==null){np("no link found with prefix %s for %s",d,e);break}let f=p.Name??"";if(f.length<2)throw new Error("Invalid HAMT - link name was too short");if(f.length===2){r=p.Hash,np("descend into sub-shard with prefix %s",f);continue}break}return{path:s,hash:o}};async function cu(r,e,t,n){if(r.Data==null)throw new Error("DagPB node had no data");let i=j.unmarshal(r.Data),o;if(i.type==="directory")o=C4(r);else if(i.type==="hamt-sharded-directory")o=await nE(r,0,t,e,n);else throw new Error("Can only estimate the size of directories or shards");return o>t}function C4(r){let e=0;for(let t of r.Links)e+=(t.Name??"").length,e+=t.Hash.version===1?iu.bytes.byteLength:nu.bytes.byteLength;return e}async function nE(r,e,t,n,i){if(e>t)return t;if(r.Data==null||!j.unmarshal(r.Data).isDirectory())return e;for(let s of r.Links){let a=s.Name??"";if(a=a.substring(2),e+=a.length,e+=s.Hash.bytes.byteLength,s.Hash.code===ve){let c=await n.get(s.Hash,i),u=Se(c);e+=await nE(u,e,t,n,i)}}return e}var Pr=oe("helia:unixfs:components:utils:add-link");async function qo(r,e,t,n){if(r.node.Data==null)throw new ot("Invalid parent passed to addLink");if(j.unmarshal(r.node.Data).type==="hamt-sharded-directory")return Pr("adding link to sharded directory"),D4(r,e,t,n);Pr(`adding ${e.Name} (${e.Hash}) to regular directory`);let o=await U4(r,e,t,n);if(await cu(o.node,t,n.shardSplitThresholdBytes,n)){Pr("converting directory to sharded directory");let s=await L4(o,t);o.cid=s.cid,o.node=Se(await t.get(s.cid,n))}return o}var L4=async(r,e)=>{if(r.node.Data==null)throw new ot("Invalid parent passed to convertToShardedDirectory");let t=j.unmarshal(r.node.Data),n=await rE(e,r.node.Links.map(i=>({name:i.Name??"",size:BigInt(i.Tsize??0),cid:i.Hash})),{mode:t.mode,mtime:t.mtime,cidVersion:r.cid.version});return Pr(`converted directory to sharded directory ${n.cid}`),n},U4=async(r,e,t,n)=>{let i=r.node.Links.filter(l=>{let d=l.Name===e.Name;if(d&&!n.allowOverwriting)throw new wa;return!d});if(i.push(e),r.node.Data==null)throw new pt("Parent node with no data passed to addToDirectory");let o=j.unmarshal(r.node.Data),s;if(o.mtime!=null){let l=Date.now(),d=Math.floor(l/1e3);o.mtime={secs:BigInt(d),nsecs:(l-d*1e3)*1e3},s=o.marshal()}else s=r.node.Data;r.node=Te({Data:s,Links:i});let a=ce(r.node),c=await fe.digest(a),u=F.create(r.cid.version,ve,c);return await t.put(u,a),{node:r.node,cid:u}},D4=async(r,e,t,n)=>{let{path:i,hash:o}=await au(r.cid,e.Name,t,n),s=i[i.length-1];if(s==null)throw new Error("Invalid HAMT, could not generate path");let a=s.prefix,c=parseInt(a,16);Pr("next prefix for %s is %s",e.Name,a);let u=`${a}${e.Name}`,l=s.node.Links.find(d=>(d.Name??"").startsWith(a));if(l!=null)if(Pr("link %s was present in shard",u),l.Name===u){if(!n.allowOverwriting)throw new wa;Pr("overwriting %s in subshard",e.Name),s.node.Links=s.node.Links.filter(d=>d.Name!==u),s.node.Links.push({Name:u,Hash:e.Hash,Tsize:e.Tsize})}else{if(l.Name?.length===2)throw new Error("Existing link was subshard?!");{Pr("prefix %s already exists, creating new subshard",a);let d=s.node.Links.findIndex(y=>y.Name?.startsWith(a)),p=s.node.Links.splice(d,1)[0],f=(p.Name??"").substring(2),m=tu(Go)(V(f));for(let y=0;y<i.length;y++)await m.take(Mi);for(;;){let y=await m.take(Mi),g=ou(y);p.Name=`${g}${f}`;let E=await o.take(Mi),x=ou(E);if(g===x){let S=new ip.default;S.set(E,!0),i.push({prefix:x,children:S,node:{Links:[]}});continue}let _=new ip.default;_.set(E,!0),_.set(y,!0),i.push({prefix:a,children:_,node:{Links:[p,{Name:`${x}${e.Name}`,Hash:e.Hash,Tsize:e.Tsize}]}});break}}}else Pr("link %s was not present in sub-shard",u),e.Name=u,s.node.Links.push(e),s.children.set(c,!0),Pr("adding %s to existing sub-shard",u);return su(i,t,n)};async function si(r,e,t={}){let n=await Ve(r,e,t);if(n.type!=="directory")throw new oi(`${r.toString()} was not a UnixFS directory`);return{cid:r,node:n.node}}async function Yo(r,e,t,n){let i=await Ve(r,t,n);if(i.type!=="directory"&&i.type!=="file"&&i.type!=="raw")throw new Or(`${r.toString()} was not a UnixFS node`);return{Name:e,Tsize:i.node instanceof Uint8Array?i.node.byteLength:O4(i.node),Hash:r}}function O4(r){let e=r.Links.reduce((t,n)=>t+(n.Tsize??0),0);return ce(r).byteLength+e}var op=oe("helia:unixfs:components:utils:resolve");async function Fr(r,e,t,n){if(e==null||e==="")return{cid:r};op('resolve "%s" under %c',e,r);let i=e.split("/").filter(Boolean),o=[{name:"",cid:r,size:0n}];for(let s=0;s<i.length;s++){let a=i[s],c=await Ve(r,t,n);if(op('resolving "%s"',a,c),c.type==="file"){if(s<i.length-1)throw new ot("Path was invalid");r=c.cid}else if(c.type==="directory"){let u;for await(let l of c.content())if(l.name===a){u=l.cid;break}if(u==null)throw new Jl("Could not find path in directory");r=u,o.push({name:a,cid:r,size:c.size})}else throw new ot("Could not resolve path")}return op("resolved %s to %c",e,r),{cid:r,path:e,segments:o}}async function Wo(r,e,t,n){if(e.segments==null||e.segments.length===0)return r;let i=e.segments.pop();if(i==null)throw new Error("Insufficient segments");i.cid=r,e.segments.reverse();for(let o of e.segments){let[s,a]=await Promise.all([si(o.cid,t,n),Yo(i.cid,i.name,t,n)]);r=(await qo(s,a,t,{...n,allowOverwriting:!0,cidVersion:r.version})).cid,o.cid=r,i=o}return r}var P4=it.bind({ignoreUndefined:!0}),F4={};async function*iE(r,e,t={}){let n=P4(F4,t),i=await Fr(r,n.path,e,n),o=await Ve(i.cid,e,n);if(o.type!=="file"&&o.type!=="raw")throw new Ql;if(o.content==null)throw new Ko;yield*o.content(n)}var V4=it.bind({ignoreUndefined:!0}),M4=oe("helia:unixfs:chmod"),H4={recursive:!1,shardSplitThresholdBytes:262144};async function oE(r,e,t,n={}){let i=V4(H4,n),o=await Fr(r,i.path,t,n);if(M4("chmod %c %d",o.cid,e),i.recursive){let p=await gt(async function*(){for await(let f of Ho(o.cid,t,n)){let h,m=[];if(f.type==="raw")h=new j({type:"file",data:f.node});else if(f.type==="file"||f.type==="directory")h=f.unixfs,m=f.node.Links;else throw new Or;h.mode=e;let y={Data:h.marshal(),Links:m};yield{path:f.path,content:y}}},f=>ni(f,t,{...i,dagBuilder:async function*(h,m){for await(let y of h)yield async function(){let g=y.content,E=ce(g),x=await pr(E,m,{...i,cidVersion:r.version});if(g.Data==null)throw new pt(`${x} had no data`);let _=j.unmarshal(g.Data);return{cid:x,size:BigInt(E.length),path:y.path,unixfs:_}}}}),async f=>ii(f));if(p==null)throw new xn(`Could not chmod ${o.cid.toString()}`);return Wo(p.cid,o,t,i)}let s=await t.get(o.cid,n),a,c=[];if(o.cid.code===Ae)a=new j({type:"file",data:s});else{let p=Se(s);if(p.Data==null)throw new pt(`${o.cid.toString()} had no data`);c=p.Links,a=j.unmarshal(p.Data)}a.mode=e;let u=ce({Data:a.marshal(),Links:c}),l=await fe.digest(u),d=F.create(o.cid.version,ve,l);return await t.put(d,u),Wo(d,o,t,i)}var $4=it.bind({ignoreUndefined:!0}),z4=oe("helia:unixfs:cp"),K4={force:!1,shardSplitThresholdBytes:262144};async function sE(r,e,t,n,i={}){let o=$4(K4,i);if(t.includes("/"))throw new ot("Name must not have slashes");let[s,a]=await Promise.all([si(e,n,o),Yo(r,t,n,o)]);return z4('Adding %c as "%s" to %c',r,t,e),(await qo(s,a,n,{allowOverwriting:o.force,cidVersion:e.version,...o})).cid}var G4=it.bind({ignoreUndefined:!0}),q4={};async function*aE(r,e,t={}){let n=G4(q4,t),i=await Fr(r,n.path,e,n),o=await Ve(i.cid,e);if(o.type==="file"||o.type==="raw"){yield o;return}if(o.content==null)throw new Ko;if(o.type!=="directory")throw new oi;yield*o.content({offset:t.offset,length:t.length})}var Y4=it.bind({ignoreUndefined:!0}),cE=oe("helia:unixfs:mkdir"),W4={cidVersion:1,force:!1,shardSplitThresholdBytes:262144};async function lE(r,e,t,n={}){let i=Y4(W4,n);if(e.includes("/"))throw new ot("Path must not have slashes");if((await Ve(r,t,n)).type!=="directory")throw new oi(`${r.toString()} was not a UnixFS directory`);cE("creating %s",e);let a={Data:new j({type:"directory",mode:i.mode,mtime:i.mtime}).marshal(),Links:[]},c=ce(a),u=await fe.digest(c),l=F.create(i.cidVersion,ve,u);await t.put(l,c);let[d,p]=await Promise.all([si(r,t,i),Yo(l,e,t,i)]);return cE("adding empty dir called %s to %c",e,r),(await qo(d,p,t,{...i,allowOverwriting:i.force})).cid}var lu=oe("helia:unixfs:utils:remove-link");async function uE(r,e,t,n){if(r.node.Data==null)throw new pt("Parent node had no data");if(j.unmarshal(r.node.Data).type==="hamt-sharded-directory"){lu(`removing ${e} from sharded directory`);let o=await X4(r,e,t,n);return await cu(o.node,t,n.shardSplitThresholdBytes,n)?o:(lu("converting shard to flat directory %c",r.cid),Z4(o,t,n))}return lu(`removing link ${e} regular directory`),j4(r,e,t,n)}var j4=async(r,e,t,n)=>{r.node.Links=r.node.Links.filter(s=>s.Name!==e);let i=ce(r.node),o=await pr(i,t,{...n,cidVersion:r.cid.version});return lu(`Updated regular directory ${o}`),{node:r.node,cid:o}},X4=async(r,e,t,n)=>{let{path:i}=await au(r.cid,e,t,n),o=i[i.length-1];if(o==null)throw new Error("Invalid HAMT, could not generate path");let s=o.node.Links.filter(u=>(u.Name??"").substring(2)===e).map(u=>u.Name).pop();if(s==null)throw new Error("File not found");let a=s.substring(0,2),c=parseInt(a,16);if(o.node.Links=o.node.Links.filter(u=>u.Name!==s),o.children.unset(c),o.node.Links.length===1)for(;i.length!==1;){let u=i[i.length-1];if(u==null||u.node.Links.length>1)break;i.pop();let l=i[i.length-1];if(l==null)break;let d=u.node.Links[0];l.node.Links=l.node.Links.filter(p=>!(p.Name??"").startsWith(l.prefix)),l.node.Links.push({Hash:d.Hash,Name:`${l.prefix}${(d.Name??"").substring(2)}`,Tsize:d.Tsize})}return su(i,t,n)},Z4=async(r,e,t)=>{if(r.node.Data==null)throw new ot("Invalid parent passed to convertToFlatDirectory");let n={Links:[]},i=await Ve(r.cid,e);if(i.type!=="directory")throw new Error("Unexpected node type");for await(let c of i.content()){let u=0;c.node instanceof Uint8Array?u=c.node.byteLength:u=ce(c.node).length,n.Links.push({Hash:c.cid,Name:c.name,Tsize:u})}let o=j.unmarshal(r.node.Data);n.Data=new j({type:"directory",mode:o.mode,mtime:o.mtime}).marshal();let s=ce(Te(n));return{cid:await pr(s,e,{codec:Oe,cidVersion:r.cid.version,signal:t.signal}),node:n}};var J4=it.bind({ignoreUndefined:!0}),Q4=oe("helia:unixfs:rm"),eI={shardSplitThresholdBytes:262144};async function dE(r,e,t,n={}){let i=J4(eI,n);if(e.includes("/"))throw new ot("Name must not have slashes");let o=await si(r,t,i);return Q4("Removing %s from %c",e,r),(await uE(o,e,t,{...i,cidVersion:r.version})).cid}var tI=it.bind({ignoreUndefined:!0}),rI=oe("helia:unixfs:stat"),nI={};async function fE(r,e,t={}){let n=tI(nI,t),i=await Fr(r,t.path,e,n);rI("stat %c",i.cid);let o=await Ve(i.cid,e,n);if(o.type!=="file"&&o.type!=="directory"&&o.type!=="raw")throw new Or;let s=0n,a=0n,c=0n,u=0n,l=0,d,p,f=o.type,h;if(o.type==="raw"&&(s=BigInt(o.node.byteLength),a=BigInt(o.node.byteLength),c=BigInt(o.node.byteLength),u=BigInt(o.node.byteLength),l=1),o.type==="directory"&&(s=0n,a=BigInt(o.unixfs.marshal().byteLength),c=0n,u=a,l=1,d=o.unixfs.mode,p=o.unixfs.mtime,h=o.unixfs),o.type==="file"){let m=await hE(i.cid,e,n);s=o.unixfs.fileSize(),a=BigInt((o.node.Data?.byteLength??0)+o.node.Links.reduce((y,g)=>y+(g.Tsize??0),0)),c=BigInt(m.localFileSize),u=BigInt(m.localDagSize),l=m.blocks,d=o.unixfs.mode,p=o.unixfs.mtime,h=o.unixfs}return{cid:i.cid,mode:d,mtime:p,fileSize:s,dagSize:a,localFileSize:c,localDagSize:u,blocks:l,type:f,unixfs:h}}async function hE(r,e,t){let n={localFileSize:0,localDagSize:0,blocks:0};if(await e.has(r,t)){let i=await e.get(r,t);if(n.blocks++,n.localDagSize+=i.byteLength,r.code===Ae)n.localFileSize+=i.byteLength;else if(r.code===ve){let o=Se(i);if(o.Links.length>0)for(let s of o.Links){let a=await hE(s.Hash,e,t);n.localFileSize+=a.localFileSize,n.localDagSize+=a.localDagSize,n.blocks+=a.blocks}else{if(o.Data==null)throw new pt(`PBNode ${r.toString()} had no data`);let s=j.unmarshal(o.Data);if(s.data==null)throw new pt(`UnixFS node ${r.toString()} had no data`);n.localFileSize+=s.data.byteLength??0}}else throw new xn(`${r.toString()} was neither DAG_PB nor RAW`)}return n}var iI=it.bind({ignoreUndefined:!0}),oI=oe("helia:unixfs:touch"),sI={recursive:!1,shardSplitThresholdBytes:262144};async function pE(r,e,t={}){let n=iI(sI,t),i=await Fr(r,n.path,e,n),o=n.mtime??{secs:BigInt(Math.round(Date.now()/1e3)),nsecs:0};if(oI("touch %c %o",i.cid,o),n.recursive){let p=await gt(async function*(){for await(let f of Ho(i.cid,e)){let h,m;if(f.type==="raw")h=new j({data:f.node}),m=[];else if(f.type==="file"||f.type==="directory")h=f.unixfs,m=f.node.Links;else throw new Or;h.mtime=o;let y={Data:h.marshal(),Links:m};yield{path:f.path,content:y}}},f=>ni(f,e,{...n,dagBuilder:async function*(h,m){for await(let y of h)yield async function(){let g=y.content,E=ce(g),x=await pr(E,m,{...n,cidVersion:r.version});if(g.Data==null)throw new pt(`${x} had no data`);let _=j.unmarshal(g.Data);return{cid:x,size:BigInt(E.length),path:y.path,unixfs:_}}}}),async f=>ii(f));if(p==null)throw new xn(`Could not chmod ${i.cid.toString()}`);return Wo(p.cid,i,e,n)}let s=await e.get(i.cid,t),a,c=[];if(i.cid.code===Ae)a=new j({data:s});else{let p=Se(s);if(c=p.Links,p.Data==null)throw new pt(`${i.cid.toString()} had no data`);a=j.unmarshal(p.Data)}a.mtime=o;let u=ce({Data:a.marshal(),Links:c}),l=await fe.digest(u),d=F.create(i.cid.version,ve,l);return await e.put(d,u),Wo(d,i,e,n)}var sp=class{components;constructor(e){this.components=e}async*addAll(e,t={}){yield*x2(e,this.components.blockstore,t)}async addBytes(e,t={}){return b2(e,this.components.blockstore,t)}async addByteStream(e,t={}){return v2(e,this.components.blockstore,t)}async addFile(e,t={}){return A2(e,this.components.blockstore,t)}async addDirectory(e={},t={}){return _2(e,this.components.blockstore,t)}async*cat(e,t={}){yield*iE(e,this.components.blockstore,t)}async chmod(e,t,n={}){return oE(e,t,this.components.blockstore,n)}async cp(e,t,n,i={}){return sE(e,t,n,this.components.blockstore,i)}async*ls(e,t={}){yield*aE(e,this.components.blockstore,t)}async mkdir(e,t,n={}){return lE(e,t,this.components.blockstore,n)}async rm(e,t,n={}){return dE(e,t,this.components.blockstore,n)}async stat(e,t={}){return fE(e,this.components.blockstore,t)}async touch(e,t={}){return pE(e,this.components.blockstore,t)}};function mE(r){return new sp(r)}function uu(r,e={}){let t={_cancelled:!1,async start(){this._cancelled=!1},async pull(n){try{let{value:i,done:o}=await r.next();if(this._cancelled)return;if(o===!0){n.close();return}n.enqueue(i)}catch(i){n.error(i)}},cancel(){this._cancelled=!0}};return new globalThis.ReadableStream(t,e)}var aI=42;function cI(r){if(r[0]!==0)throw new Error("Invalid CID for CBOR tag 42; expected leading 0x00");return F.decode(r.subarray(1))}function yE(r){let e=[];e[aI]=cI;let t=ut(r,{allowIndefinite:!1,coerceUndefinedToNull:!0,allowNaN:!1,allowInfinity:!1,strict:!0,useMaps:!1,rejectDuplicateMapKeys:!0,tags:e,allowBigInt:!1});return new TextDecoder().decode(zs(t))}function gE(r){let e=lI(r);return e===r?`filename="${r}"`:`filename="${e}"; filename*=UTF-8''${encodeURIComponent(r)}`}function lI(r){return r.replace(/[^\x00-\x7F]/g,"_")}function wE({cid:r,reqFormat:e,weak:t,rangeStart:n,rangeEnd:i}){let o=t===!0?"W/":"",s=e==null?"":`.${e}`;return(n!=null||i!=null)&&(s+=`.${n??"0"}-${i??"N"}`),`${o}"${r.toString()}${s}"`}async function EE(r,e,t,n){let i=t.forComponent("helia:verified-fetch:get-stream-from-async-iterable"),o=r[Symbol.asyncIterator](),{value:s,done:a}=await o.next();if(a===!0)throw i.error("No content found for path",e),new Error("No content found");return{stream:new ReadableStream({async start(u){n?.onProgress?.(new M("verified-fetch:request:progress:chunk")),u.enqueue(s)},async pull(u){let{value:l,done:d}=await o.next();if(d===!0){l!=null&&(n?.onProgress?.(new M("verified-fetch:request:progress:chunk")),u.enqueue(l)),u.close();return}n?.onProgress?.(new M("verified-fetch:request:progress:chunk")),u.enqueue(l)}}),firstChunk:s}}var Jz=V("ustar\0","binary"),Qz=V("ustar ","binary"),eK=V(" \0","binary");var _E=Q(bE(),1);function dI(r){return r[Symbol.asyncIterator]!=null}function fI(r){if(dI(r))return(async()=>{let n=new Uint8Array(0);for await(let i of r)n=ye([n,i],n.length+i.length);return n})();let e=[],t=0;for(let n of r)e.push(n),t+=n.byteLength;return ye(e,t)}var vE=fI;var hI="0000000000000000000",pI="7777777777777777777",mI=48,yI=V("ustar\0","binary"),gI=V("00","binary"),wI=parseInt("7777",8),EI=257,xI=263,bI=function(r){switch(r){case"file":return 0;case"link":return 1;case"symlink":return 2;case"character-device":return 3;case"block-device":return 4;case"directory":return 5;case"fifo":return 6;case"contiguous-file":return 7;case"pax-header":return 72;default:return 0}},vI=function(r){let e=256;for(let t=0;t<148;t++)e+=r[t];for(let t=156;t<512;t++)e+=r[t];return e},ai=function(r,e){let t=r.toString(8);return t.length>e?V(pI.slice(0,e)+" "):V(hI.slice(0,e-t.length)+t+" ")},ap=function(r){let e=V(r).byteLength,t=Math.floor(Math.log(e)/Math.log(10))+1;return e+t>=Math.pow(10,t)&&t++,`${e+t}${r}`};function AE(r){let e="";r.name!=null&&(e+=ap(" path="+r.name+`
|
|
9
|
-
`)),r.linkname!=null&&(e+=
|
|
10
|
-
`));let t=r.pax;if(t!=null)for(let n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e+=
|
|
11
|
-
`));return V(e)}function du(r){let e=new Uint8Array(512),t=r.name,n="";if(r.typeflag===5&&t[t.length-1]!=="/"&&(t+="/"),V(t).byteLength!==t.length)return null;for(;V(t).byteLength>100;){let i=t.indexOf("/");if(i===-1)return null;n+=n!==""?"/"+t.slice(0,i):t.slice(0,i),t=t.slice(i+1)}return V(t).byteLength>100||V(n).byteLength>155||r.linkname!=null&&V(r.linkname).byteLength>100?null:(e.set(V(t),0),e.set(ai(r.mode&wI,6),100),e.set(ai(r.uid,6),108),e.set(ai(r.gid,6),116),e.set(ai(r.size,11),124),e.set(ai(r.mtime.getTime()/1e3|0,11),136),e[156]=mI+bI(r.type),r.linkname!=null&&e.set(V(r.linkname),157),e.set(yI,EI),e.set(gI,xI),r.uname!=null&&e.set(V(r.uname),265),r.gname!=null&&e.set(V(r.gname),297),e.set(ai(r.devmajor??0,6),329),e.set(ai(r.devminor??0,6),337),n!=null&&e.set(V(n),345),e.set(ai(vI(e),6),148),e)}var{S_IFMT:_I,S_IFBLK:SI,S_IFCHR:II,S_IFDIR:BI,S_IFIFO:kI,S_IFLNK:RI}=_E.default,TI=parseInt("755",8),NI=parseInt("644",8),SE=new Uint8Array(1024);function CI(r=0){switch(r&_I){case SI:return"block-device";case II:return"character-device";case BI:return"directory";case kI:return"fifo";case RI:return"symlink";default:return"file"}}function lp(r){return r&=511,r!==0?SE.subarray(0,512-r):new Uint8Array(0)}function cp(r){if(r.pax==null){let e=du(r);if(e!=null)return e}return LI(r)}function LI(r){let e=AE(r),t={name:"PaxHeader",mode:r.mode,uid:r.uid,gid:r.gid,size:e.length,mtime:r.mtime,type:"pax-header",linkname:r.linkname,uname:r.uname,gname:r.gname,devmajor:r.devmajor,devminor:r.devminor};return new zt(du(t)??new Uint8Array(0),e,lp(e.length),du({...t,size:r.size,type:r.type})??new Uint8Array(0)).subarray()}function fu(){return async function*(r){for await(let{header:e,body:t}of r){let n={...e,size:e.type==="symlink"?0:e.size??0,type:e.type??CI(e.mode),mode:e.mode??(e.type==="directory"?TI:NI),uid:e.uid??0,gid:e.gid??0,mtime:e.mtime??new Date};if(typeof t=="string"&&(t=V(t)),t instanceof Uint8Array||gr(t)){n.size=t.length,yield cp(n),yield gr(t)?t.subarray():t,yield lp(n.size);continue}if(n.type==="symlink"&&n.linkname==null){if(t==null)throw new Error("type was symlink but no linkname or body specified");n.linkname=Z(await vE(t)),yield cp(n);continue}if(yield cp(n),n.type!=="file"&&n.type!=="contiguous-file")continue;let i=0;for await(let o of t??[])i+=o.length,yield gr(o)?o.subarray():o;if(i!==n.size)throw new Error(`size mismatch, wrote ${i} of ${n.size} bytes`);yield lp(n.size)}yield SE}}var UI=["file","raw","directory"];function DI(r){let e,t;return(r.type==="file"||r.type==="directory")&&(e=r.unixfs.mode,t=r.unixfs.mtime!=null?new Date(Number(r.unixfs.mtime.secs*1000n)):void 0),{name:r.path,mode:e,mtime:t,size:Number(r.size),type:r.type==="directory"?"directory":"file"}}function IE(r){if(!UI.includes(r.type))throw new O("Not a UnixFS node","ERR_NOT_UNIXFS");let e={header:DI(r)};return(r.type==="file"||r.type==="raw")&&(e.body=r.content()),e}async function*BE(r,e,t){let n=await Ve(r,e,t);if(n.type==="file"||n.type==="raw"){yield*gt([IE(n)],fu());return}if(n.type==="directory"){yield*gt(Ho(r,e,t),i=>at(i,o=>IE(o)),fu());return}throw new O("Not a UnixFS node","ERR_NOT_UNIXFS")}var kE=Q(mh(),1),hu=class{lru;constructor(e){this.lru=(0,kE.default)(e)}get(e){let t=this.lru.get(e);if(t!=null){if(t.expire!=null&&t.expire<Date.now()){this.lru.remove(e);return}return t.value}}set(e,t,n){this.lru.set(e,{value:t,expire:Date.now()+n})}has(e){return this.get(e)!=null}remove(e){this.lru.remove(e)}clear(){this.lru.clear()}};var up=new hu(1e3),OI=/^(?<protocol>ip[fn]s):\/\/(?<cidOrPeerIdOrDnsLink>[^/$?]+)\/?(?<path>[^$?]*)\??(?<queryString>.*)$/;async function RE({urlString:r,ipns:e,logger:t},n){let i=t.forComponent("helia:verified-fetch:parse-url-string"),o=r.match(OI);if(o==null||o.groups==null)throw new TypeError(`Invalid URL: ${r}, please use ipfs:// or ipns:// URLs only.`);let{protocol:s,cidOrPeerIdOrDnsLink:a,path:c,queryString:u}=o.groups,l,d,p=[];if(s==="ipfs")try{l=F.parse(a)}catch(y){i.error(y),p.push(new TypeError("Invalid CID for ipfs://<cid> URL"))}else{let y=up.get(a);if(y!=null)l=y.cid,d=y.path,i.trace("resolved %s to %c from cache",a,l);else{i.trace("Attempting to resolve PeerId for %s",a);let g=null;try{g=Bt(a),y=await e.resolve(g,{onProgress:n?.onProgress}),l=y?.cid,d=y?.path,i.trace("resolved %s to %c",a,l),up.set(a,y,60*1e3*2)}catch(E){g==null?(i.error('Could not parse PeerId string "%s"',a,E),p.push(new TypeError(`Could not parse PeerId in ipns url "${a}", ${E.message}`))):(i.error("Could not resolve PeerId %c",g,E),p.push(new TypeError(`Could not resolve PeerId "${a}", ${E.message}`)))}if(l==null){i.trace("Attempting to resolve DNSLink for %s",a);try{y=await e.resolveDns(a,{onProgress:n?.onProgress}),l=y?.cid,d=y?.path,i.trace("resolved %s to %c",a,l),up.set(a,y,60*1e3*2)}catch(E){i.error('Could not resolve DnsLink for "%s"',a,E),p.push(E)}}}}if(l==null)throw new AggregateError(p,`Invalid resource. Cannot determine CID from URL "${r}"`);let f={};if(u!=null&&u.length>0){let y=u.split("&");for(let g of y){let[E,x]=g.split("=");f[E]=decodeURIComponent(x)}f.download!=null&&(f.download=f.download==="true"),f.filename!=null&&(f.filename=f.filename.toString())}let h=[];c.length>0&&h.push(c),d!=null&&d.length>0&&h.push(d);let m=h.join("/");return{protocol:s,cid:l,path:m,query:f}}async function TE(r,{ipns:e,logger:t},n){if(typeof r=="string")return RE({urlString:r,ipns:e,logger:t},{onProgress:n?.onProgress});let i=F.asCID(r);if(i!=null)return{cid:i,protocol:"ipfs",path:"",query:{}};throw new TypeError(`Invalid resource. Cannot determine CID from resource: ${r}`)}function ci(r){return new Response(r,{status:200,statusText:"OK"})}function dp(r){let e=new Response(r,{status:501,statusText:"Not Implemented"});return e.headers.set("X-Content-Type-Options","nosniff"),e}function jo(r){return new Response(r,{status:406,statusText:"Not Acceptable"})}function fp(r){return new Response(r,{status:400,statusText:"Bad Request"})}var PI={[Yn]:["application/json","application/vnd.ipld.dag-cbor","application/cbor","application/vnd.ipld.dag-json","application/octet-stream","application/vnd.ipld.raw","application/vnd.ipfs.ipns-record","application/vnd.ipld.car"],[jn]:["application/json","application/vnd.ipld.dag-cbor","application/cbor","application/vnd.ipld.dag-json","application/octet-stream","application/vnd.ipld.raw","application/vnd.ipfs.ipns-record","application/vnd.ipld.car"],[Rn]:["application/json","application/vnd.ipld.dag-cbor","application/cbor","application/vnd.ipld.dag-json","application/octet-stream","application/vnd.ipld.raw","application/vnd.ipfs.ipns-record","application/vnd.ipld.car"],[ve]:["application/octet-stream","application/json","application/vnd.ipld.dag-cbor","application/cbor","application/vnd.ipld.dag-json","application/vnd.ipld.raw","application/vnd.ipfs.ipns-record","application/vnd.ipld.car","application/x-tar"],[Ae]:["application/octet-stream","application/vnd.ipld.raw","application/vnd.ipfs.ipns-record","application/vnd.ipld.car","application/x-tar"]};function NE(r,e){let t=PI[r.code];if(e!=null)return FI(e,t)}function FI(r,e){let t=r.split(",").map(n=>{let i=n.trim().split(";");return{mimeType:`${i[0]}`.trim(),weight:VI(i[1])}}).sort((n,i)=>n.weight===i.weight?0:n.weight>i.weight?-1:1).map(n=>n.mimeType);for(let n of t)for(let i of e)if(n.includes(i)||n==="*/*"||n.startsWith("*/")&&i.split("/")[1]===n.split("/")[1]||n.endsWith("/*")&&i.split("/")[0]===n.split("/")[0])return i}function VI(r){if(r!=null&&(r=r.trim()),r==null||!r.startsWith("q="))return 1;let e=parseFloat(r.replace("q=",""));return isNaN(e)?0:e}var MI={raw:"application/vnd.ipld.raw",car:"application/vnd.ipld.car","dag-json":"application/vnd.ipld.dag-json","dag-cbor":"application/vnd.ipld.dag-cbor",json:"application/json",cbor:"application/cbor","ipns-record":"application/vnd.ipfs.ipns-record",tar:"application/x-tar"};function CE(r){if(r!=null)return MI[r]}async function LE(r,e,t){let n=[],i;for await(let o of Qh(e,r,t))n.push(o.cid),i=o;if(i==null)throw new Error("No terminal element found");return{ipfsRoots:n,terminalElement:i}}function HI(r){if(r==null)return;let e;return r?.signal===null&&(e=void 0),{...r,signal:e}}var $I=["application/vnd.ipld.raw","application/octet-stream"];function zI(r){let t=(new Headers(r).get("accept")??"").split(",").map(n=>n.split(";")[0]).map(n=>n.trim());for(let n of t){if(n==="*/*")return;if($I.includes(n??""))return n}}var pu=class{helia;ipns;unixfs;log;contentTypeParser;constructor({helia:e,ipns:t,unixfs:n},i){this.helia=e,this.log=e.logger.forComponent("helia:verified-fetch"),this.ipns=t??tw(e,{resolvers:[Ml("https://mozilla.cloudflare-dns.com/dns-query"),Ml("https://dns.google/resolve")]}),this.unixfs=n??mE(e),this.contentTypeParser=i?.contentTypeParser,this.log.trace("created VerifiedFetch instance")}async handleIPNSRecord({resource:e,cid:t,path:n,options:i}){if(n!==""||!e.startsWith("ipns://"))return fp("Invalid IPNS name");let o;try{o=Bt(e.replace("ipns://",""))}catch{return this.log.error("could not parse peer id from IPNS url %s",e),fp("Invalid IPNS name")}let s=ye([V("/ipns/"),o.toBytes()]),a=new Le("/dht/record/"+Z(s,"base32"),!1),c=await this.helia.datastore.get(a,i),u=ei.deserialize(c),l=ci(u.value);return l.headers.set("content-type","application/vnd.ipfs.ipns-record"),l}async handleCar({cid:e,options:t}){let n=Og(this.helia),i=uu(n.stream(e,t)),o=ci(i);return o.headers.set("content-type","application/vnd.ipld.car; version=1"),o}async handleTar({cid:e,path:t,options:n}){if(e.code!==ve&&e.code!==Ae)return jo("only UnixFS data can be returned in a TAR file");let i=uu(BE(`/ipfs/${e}/${t}`,this.helia.blockstore,n)),o=ci(i);return o.headers.set("content-type","application/x-tar"),o}async handleJson({cid:e,path:t,accept:n,options:i}){this.log.trace("fetching %c/%s",e,t);let o=await this.helia.blockstore.get(e,i),s;if(n==="application/vnd.ipld.dag-cbor"||n==="application/cbor")try{let c=vl(o);s=Hs(c)}catch(c){return this.log.error("could not transform %c to application/vnd.ipld.dag-cbor",c),jo()}else s=o;let a=ci(s);return a.headers.set("content-type",n??"application/json"),a}async handleDagCbor({cid:e,path:t,accept:n,options:i}){this.log.trace("fetching %c/%s",e,t);let o=await this.helia.blockstore.get(e,i),s;if(n==="application/octet-stream"||n==="application/vnd.ipld.dag-cbor"||n==="application/cbor")s=o;else if(n==="application/vnd.ipld.dag-json")try{let c=ki(o);s=ag(c)}catch(c){return this.log.error("could not transform %c to application/vnd.ipld.dag-json",c),jo()}else try{s=yE(o)}catch(c){if(n==="application/json")return this.log('could not decode DAG-CBOR as JSON-safe, but the client sent "Accept: application/json"',c),jo();this.log("could not decode DAG-CBOR as JSON-safe, falling back to `application/octet-stream`",c),s=o}let a=ci(s);return n==null&&(n=s instanceof Uint8Array?"application/octet-stream":"application/json"),a.headers.set("content-type",n),a}async handleDagPb({cid:e,path:t,options:n}){let i,o;try{let p=await LE(this.helia.blockstore,`${e.toString()}/${t}`,n);o=p.ipfsRoots,i=p.terminalElement}catch(p){this.log.error("Error walking path %s",t,p)}let s=i?.cid??e,a;if(i?.type==="directory"){let p=i.cid,f="index.html";try{this.log.trace("found directory at %c/%s, looking for index.html",e,t),a=await this.unixfs.stat(p,{path:f,signal:n?.signal,onProgress:n?.onProgress}),this.log.trace("found root file at %c/%s with cid %c",p,f,a.cid),t=f,s=a.cid}catch(h){return this.log("error loading path %c/%s",p,f,h),dp("Unable to find index.html for directory at given path. Support for directories with implicit root is not implemented")}finally{n?.onProgress?.(new M("verified-fetch:request:end",{cid:p,path:f}))}}let c=this.unixfs.cat(s,{signal:n?.signal,onProgress:n?.onProgress});this.log("got async iterator for %c/%s",e,t);let{stream:u,firstChunk:l}=await EE(c,t??"",this.helia.logger,{onProgress:n?.onProgress}),d=ci(u);return await this.setContentType(l,t,d),o!=null&&d.headers.set("X-Ipfs-Roots",o.map(p=>p.toV1().toString()).join(",")),d}async handleRaw({cid:e,path:t,options:n}){let i=await this.helia.blockstore.get(e,n),o=ci(i),s=zI(n?.headers);return s!=null?o.headers.set("content-type",s):await this.setContentType(i,t,o),o}async setContentType(e,t,n){let i="application/octet-stream";if(this.contentTypeParser!=null)try{let o=t.split("/").pop()?.trim();o=o===""?void 0:o;let s=this.contentTypeParser(e,o);if(KI(s)){let a=await s;a!=null&&(i=a)}else s!=null&&(i=s)}catch(o){this.log.error("Error parsing content type",o)}n.headers.set("content-type",i)}codecHandlers={[ve]:this.handleDagPb,[jn]:this.handleJson,[Rn]:this.handleJson,[Yn]:this.handleDagCbor,[Ae]:this.handleRaw,[et.code]:this.handleRaw};async fetch(e,t){this.log("fetch %s",e);let n=HI(t);n?.onProgress?.(new M("verified-fetch:request:start",{resource:e}));let{path:i,query:o,cid:s}=await TE(e,{ipns:this.ipns,logger:this.helia.logger},n);n?.onProgress?.(new M("verified-fetch:request:resolve",{cid:s,path:i}));let c=new Headers(n?.headers).get("accept");c!=null&&this.log('incoming accept header "%s"',c);let u=CE(o.format);o.format!=null&&this.log('incoming query format "%s", mapped to %s',o.format,u);let l=c??u,d=NE(s,l);if(this.log("output type %s",d),l!=null&&d==null)return jo();let p,f,h={resource:e.toString(),cid:s,path:i,accept:d,options:n};if(d==="application/vnd.ipfs.ipns-record")f="ipns-record",p=await this.handleIPNSRecord(h);else if(d==="application/vnd.ipld.car")f="car",o.download=!0,o.filename=o.filename??`${s.toString()}.car`,p=await this.handleCar(h);else if(d==="application/vnd.ipld.raw")f="raw",o.download=!0,o.filename=o.filename??`${s.toString()}.bin`,p=await this.handleRaw(h);else if(d==="application/x-tar")f="tar",o.download=!0,o.filename=o.filename??`${s.toString()}.tar`,p=await this.handleTar(h);else{let y=this.codecHandlers[s.code];if(y==null)return dp(`Support for codec with code ${s.code} is not yet implemented. Please open an issue at https://github.com/ipfs/helia/issues/new`);p=await y.call(this,h)}p.headers.set("etag",wE({cid:s,reqFormat:f,weak:!1})),p.headers.set("cache-control","public, max-age=29030400, immutable"),p.headers.set("X-Ipfs-Path",e.toString());let m;return o.download===!0&&(m="attachment"),o.filename!=null&&(m==null&&(m="inline"),m=`${m}; ${gE(o.filename)}`),m!=null&&p.headers.set("Content-Disposition",m),n?.onProgress?.(new M("verified-fetch:request:end",{cid:s,path:i})),p}async start(){await this.helia.start()}async stop(){await this.helia.stop()}};function KI(r){return r?.then!=null}var xa,mu=async function(e,t){return xa==null&&(xa=await hp()),xa(e,t)};mu.start=async function(){await xa?.start()};mu.stop=async function(){await xa?.stop()};async function hp(r,e){let t=e?.contentTypeParser;GI(r)||(r=await Rg({blockBrokers:[is({gateways:r?.gateways})],routers:(r?.routers??["https://delegated-ipfs.dev"]).map(o=>Vs(o))}));let n=new pu({helia:r},{contentTypeParser:t});async function i(o,s){return n.fetch(o,s)}return i.stop=n.stop.bind(n),i.start=n.start.bind(n),i}function GI(r){return r?.blockstore!=null&&r?.datastore!=null&&r?.gc!=null&&r?.stop!=null&&r?.start!=null}return YE(qI);})();
|
|
7
|
+
`)}`:`${t} :`}};b1=Pn;z.Constructed=b1;Pn.NAME="CONSTRUCTED";var fc=class extends tt{fromBER(e,t,n){return t}toBER(e){return nr}};fc.override="EndOfContentValueBlock";var v1,hc=class extends Ye{constructor(e={}){super(e,fc),this.idBlock.tagClass=1,this.idBlock.tagNumber=0}};v1=hc;z.EndOfContent=v1;hc.NAME=hs;var A1,Fn=class extends Ye{constructor(e={}){super(e,tt),this.idBlock.tagClass=1,this.idBlock.tagNumber=5}fromBER(e,t,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,t+n>e.byteLength?(this.error="End of input reached before message was fully decoded (inconsistent offset and length values)",-1):t+n}toBER(e,t){let n=new ArrayBuffer(2);if(!e){let i=new Uint8Array(n);i[0]=5,i[1]=0}return t&&t.write(n),n}onAsciiEncoding(){return`${this.constructor.NAME}`}};A1=Fn;z.Null=A1;Fn.NAME="NULL";var pc=class extends Qr(tt){constructor({value:e,...t}={}){super(t),t.valueHex?this.valueHexView=se.BufferSourceConverter.toUint8Array(t.valueHex):this.valueHexView=new Uint8Array(1),e&&(this.value=e)}get value(){for(let e of this.valueHexView)if(e>0)return!0;return!1}set value(e){this.valueHexView[0]=e?255:0}fromBER(e,t,n){let i=se.BufferSourceConverter.toUint8Array(e);return Jr(this,i,t,n)?(this.valueHexView=i.subarray(t,t+n),n>1&&this.warnings.push("Boolean value encoded in more then 1 octet"),this.isHexOnly=!0,jd.call(this),this.blockLength=n,t+n):-1}toBER(){return this.valueHexView.slice()}toJSON(){return{...super.toJSON(),value:this.value}}};pc.NAME="BooleanValueBlock";var _1,mc=class extends Ye{constructor(e={}){super(e,pc),this.idBlock.tagClass=1,this.idBlock.tagNumber=1}getValue(){return this.valueBlock.value}setValue(e){this.valueBlock.value=e}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.getValue}`}};_1=mc;z.Boolean=_1;mc.NAME="BOOLEAN";var yc=class extends Qr(br){constructor({isConstructed:e=!1,...t}={}){super(t),this.isConstructed=e}fromBER(e,t,n){let i=0;if(this.isConstructed){if(this.isHexOnly=!1,i=br.prototype.fromBER.call(this,e,t,n),i===-1)return i;for(let o=0;o<this.value.length;o++){let s=this.value[o].constructor.NAME;if(s===hs){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, OCTET STRING may consists of OCTET STRINGs only",-1}if(s!==g1)return this.error="OCTET STRING may consists of OCTET STRINGs only",-1}}else this.isHexOnly=!0,i=super.fromBER(e,t,n),this.blockLength=n;return i}toBER(e,t){return this.isConstructed?br.prototype.toBER.call(this,e,t):e?new ArrayBuffer(this.valueHexView.byteLength):this.valueHexView.slice().buffer}toJSON(){return{...super.toJSON(),isConstructed:this.isConstructed}}};yc.NAME="OctetStringValueBlock";var S1,Xr=class r extends Ye{constructor({idBlock:e={},lenBlock:t={},...n}={}){var i,o;(i=n.isConstructed)!==null&&i!==void 0||(n.isConstructed=!!(!((o=n.value)===null||o===void 0)&&o.length)),super({idBlock:{isConstructed:n.isConstructed,...e},lenBlock:{...t,isIndefiniteForm:!!n.isIndefiniteForm},...n},yc),this.idBlock.tagClass=1,this.idBlock.tagNumber=4}fromBER(e,t,n){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),t;if(!this.valueBlock.isConstructed){let o=(e instanceof ArrayBuffer?new Uint8Array(e):e).subarray(t,t+n);try{if(o.byteLength){let s=Kc(o,0,o.byteLength);s.offset!==-1&&s.offset===n&&(this.valueBlock.value=[s.result])}}catch{}}return super.fromBER(e,t,n)}onAsciiEncoding(){return this.valueBlock.isConstructed||this.valueBlock.value&&this.valueBlock.value.length?Pn.prototype.onAsciiEncoding.call(this):`${this.constructor.NAME} : ${se.Convert.ToHex(this.valueBlock.valueHexView)}`}getValue(){if(!this.idBlock.isConstructed)return this.valueBlock.valueHexView.slice().buffer;let e=[];for(let t of this.valueBlock.value)t instanceof r&&e.push(t.valueBlock.valueHexView);return se.BufferSourceConverter.concat(e)}};S1=Xr;z.OctetString=S1;Xr.NAME=g1;var gc=class extends Qr(br){constructor({unusedBits:e=0,isConstructed:t=!1,...n}={}){super(n),this.unusedBits=e,this.isConstructed=t,this.blockLength=this.valueHexView.byteLength}fromBER(e,t,n){if(!n)return t;let i=-1;if(this.isConstructed){if(i=br.prototype.fromBER.call(this,e,t,n),i===-1)return i;for(let a of this.value){let c=a.constructor.NAME;if(c===hs){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, BIT STRING may consists of BIT STRINGs only",-1}if(c!==w1)return this.error="BIT STRING may consists of BIT STRINGs only",-1;let u=a.valueBlock;if(this.unusedBits>0&&u.unusedBits>0)return this.error='Using of "unused bits" inside constructive BIT STRING allowed for least one only',-1;this.unusedBits=u.unusedBits}return i}let o=se.BufferSourceConverter.toUint8Array(e);if(!Jr(this,o,t,n))return-1;let s=o.subarray(t,t+n);if(this.unusedBits=s[0],this.unusedBits>7)return this.error="Unused bits for BitString must be in range 0-7",-1;if(!this.unusedBits){let a=s.subarray(1);try{if(a.byteLength){let c=Kc(a,0,a.byteLength);c.offset!==-1&&c.offset===n-1&&(this.value=[c.result])}}catch{}}return this.valueHexView=s.subarray(1),this.blockLength=s.length,t+n}toBER(e,t){if(this.isConstructed)return br.prototype.toBER.call(this,e,t);if(e)return new ArrayBuffer(this.valueHexView.byteLength+1);if(!this.valueHexView.byteLength)return nr;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}}};gc.NAME="BitStringValueBlock";var I1,yo=class extends Ye{constructor({idBlock:e={},lenBlock:t={},...n}={}){var i,o;(i=n.isConstructed)!==null&&i!==void 0||(n.isConstructed=!!(!((o=n.value)===null||o===void 0)&&o.length)),super({idBlock:{isConstructed:n.isConstructed,...e},lenBlock:{...t,isIndefiniteForm:!!n.isIndefiniteForm},...n},gc),this.idBlock.tagClass=1,this.idBlock.tagNumber=3}fromBER(e,t,n){return this.valueBlock.isConstructed=this.idBlock.isConstructed,this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm,super.fromBER(e,t,n)}onAsciiEncoding(){if(this.valueBlock.isConstructed||this.valueBlock.value&&this.valueBlock.value.length)return Pn.prototype.onAsciiEncoding.call(this);{let e=[],t=this.valueBlock.valueHexView;for(let i of t)e.push(i.toString(2).padStart(8,"0"));let n=e.join("");return`${this.constructor.NAME} : ${n.substring(0,n.length-this.valueBlock.unusedBits)}`}}};I1=yo;z.BitString=I1;yo.NAME=w1;var B1;function K6(r,e){let t=new Uint8Array([0]),n=new Uint8Array(r),i=new Uint8Array(e),o=n.slice(0),s=o.length-1,a=i.slice(0),c=a.length-1,u=0,l=c<s?s:c,d=0;for(let p=l;p>=0;p--,d++){switch(!0){case d<a.length:u=o[s-d]+a[c-d]+t[0];break;default:u=o[s-d]+t[0]}switch(t[0]=u/10,!0){case d>=o.length:o=oc(new Uint8Array([u%10]),o);break;default:o[s-d]=u%10}}return t[0]>0&&(o=oc(t,o)),o}function y1(r){if(r>=ds.length)for(let e=ds.length;e<=r;e++){let t=new Uint8Array([0]),n=ds[e-1].slice(0);for(let i=n.length-1;i>=0;i--){let o=new Uint8Array([(n[i]<<1)+t[0]]);t[0]=o[0]/10,n[i]=o[0]%10}t[0]>0&&(n=oc(t,n)),ds.push(n)}return ds[r]}function G6(r,e){let t=0,n=new Uint8Array(r),i=new Uint8Array(e),o=n.slice(0),s=o.length-1,a=i.slice(0),c=a.length-1,u,l=0;for(let d=c;d>=0;d--,l++)switch(u=o[s-l]-a[c-l]-t,!0){case u<0:t=1,o[s-l]=u+10;break;default:t=0,o[s-l]=u}if(t>0)for(let d=s-c+1;d>=0;d--,l++)if(u=o[s-l]-t,u<0)t=1,o[s-l]=u+10;else{t=0,o[s-l]=u;break}return o.slice()}var ps=class extends Qr(tt){constructor({value:e,...t}={}){super(t),this._valueDec=0,t.valueHex&&this.setValueHex(),e!==void 0&&(this.valueDec=e)}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=jd.call(this)))}set valueDec(e){this._valueDec=e,this.isHexOnly=!1,this.valueHexView=new Uint8Array(h1(e))}get valueDec(){return this._valueDec}fromDER(e,t,n,i=0){let o=this.fromBER(e,t,n);if(o===-1)return o;let s=this.valueHexView;return s[0]===0&&s[1]&128?this.valueHexView=s.subarray(1):i!==0&&s.length<i&&(i-s.length>1&&(i=s.length+1),this.valueHexView=s.subarray(i-s.length)),o}toDER(e=!1){let t=this.valueHexView;switch(!0){case(t[0]&128)!==0:{let n=new Uint8Array(this.valueHexView.length+1);n[0]=0,n.set(t,1),this.valueHexView=n}break;case(t[0]===0&&(t[1]&128)===0):this.valueHexView=this.valueHexView.subarray(1);break}return this.toBER(e)}fromBER(e,t,n){let i=super.fromBER(e,t,n);return i===-1||this.setValueHex(),i}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,t=new Uint8Array(this.valueHexView.length*8/3),n=0,i,o=this.valueHexView,s="",a=!1;for(let c=o.byteLength-1;c>=0;c--){i=o[c];for(let u=0;u<8;u++){if((i&1)===1)switch(n){case e:t=G6(y1(n),t),s="-";break;default:t=K6(t,y1(n))}n++,i>>=1}}for(let c=0;c<t.length;c++)t[c]&&(a=!0),a&&(s+=m1.charAt(t[c]));return a===!1&&(s+=m1.charAt(0)),s}};B1=ps;ps.NAME="IntegerValueBlock";Object.defineProperty(B1.prototype,"valueHex",{set:function(r){this.valueHexView=new Uint8Array(r),this.setValueHex()},get:function(){return this.valueHexView.slice().buffer}});var k1,Ue=class r extends Ye{constructor(e={}){super(e,ps),this.idBlock.tagClass=1,this.idBlock.tagNumber=2}toBigInt(){return sc(),BigInt(this.valueBlock.toString())}static fromBigInt(e){sc();let t=BigInt(e),n=new fs,i=t.toString(16).replace(/^-/,""),o=new Uint8Array(se.Convert.FromHex(i));if(t<0){let a=new Uint8Array(o.length+(o[0]&128?1:0));a[0]|=128;let u=BigInt(`0x${se.Convert.ToHex(a)}`)+t,l=se.BufferSourceConverter.toUint8Array(se.Convert.FromHex(u.toString(16)));l[0]|=128,n.write(l)}else o[0]&128&&n.write(new Uint8Array([0])),n.write(o);return new r({valueHex:n.final()})}convertToDER(){let e=new r({valueHex:this.valueBlock.valueHexView});return e.valueBlock.toDER(),e}convertFromDER(){return new r({valueHex:this.valueBlock.valueHexView[0]===0?this.valueBlock.valueHexView.subarray(1):this.valueBlock.valueHexView})}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()}`}};k1=Ue;z.Integer=k1;Ue.NAME="INTEGER";var R1,wc=class extends Ue{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=10}};R1=wc;z.Enumerated=R1;wc.NAME="ENUMERATED";var ms=class extends Qr(tt){constructor({valueDec:e=-1,isFirstSid:t=!1,...n}={}){super(n),this.valueDec=e,this.isFirstSid=t}fromBER(e,t,n){if(!n)return t;let i=se.BufferSourceConverter.toUint8Array(e);if(!Jr(this,i,t,n))return-1;let o=i.subarray(t,t+n);this.valueHexView=new Uint8Array(n);for(let a=0;a<n&&(this.valueHexView[a]=o[a]&127,this.blockLength++,!!(o[a]&128));a++);let s=new Uint8Array(this.blockLength);for(let a=0;a<this.blockLength;a++)s[a]=this.valueHexView[a];return this.valueHexView=s,o[this.blockLength-1]&128?(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=xi(this.valueHexView,7):(this.isHexOnly=!0,this.warnings.push("Too big SID for decoding, hex only")),t+this.blockLength)}set valueBigInt(e){sc();let t=BigInt(e).toString(2);for(;t.length%7;)t="0"+t;let n=new Uint8Array(t.length/7);for(let i=0;i<n.length;i++)n[i]=parseInt(t.slice(i*7,i*7+7),2)+(i+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 i=this.valueHexView,o=new Uint8Array(this.blockLength);for(let s=0;s<this.blockLength-1;s++)o[s]=i[s]|128;return o[this.blockLength-1]=i[this.blockLength-1],o.buffer}let t=On(this.valueDec,7);if(t.byteLength===0)return this.error="Error during encoding SID value",nr;let n=new Uint8Array(t.byteLength);if(!e){let i=new Uint8Array(t),o=t.byteLength-1;for(let s=0;s<o;s++)n[s]=i[s]|128;n[o]=i[o]}return n}toString(){let e="";if(this.isHexOnly)e=se.Convert.ToHex(this.valueHexView);else if(this.isFirstSid){let t=this.valueDec;this.valueDec<=39?e="0.":this.valueDec<=79?(e="1.",t-=40):(e="2.",t-=80),e+=t.toString()}else e=this.valueDec.toString();return e}toJSON(){return{...super.toJSON(),valueDec:this.valueDec,isFirstSid:this.isFirstSid}}};ms.NAME="sidBlock";var Ec=class extends tt{constructor({value:e=go,...t}={}){super(t),this.value=[],e&&this.fromString(e)}fromBER(e,t,n){let i=t;for(;n>0;){let o=new ms;if(i=o.fromBER(e,i,n),i===-1)return this.blockLength=0,this.error=o.error,i;this.value.length===0&&(o.isFirstSid=!0),this.blockLength+=o.blockLength,n-=o.blockLength,this.value.push(o)}return i}toBER(e){let t=[];for(let n=0;n<this.value.length;n++){let i=this.value[n].toBER(e);if(i.byteLength===0)return this.error=this.value[n].error,nr;t.push(i)}return Xd(t)}fromString(e){this.value=[];let t=0,n=0,i="",o=!1;do if(n=e.indexOf(".",t),n===-1?i=e.substring(t):i=e.substring(t,n),t=n+1,o){let s=this.value[0],a=0;switch(s.valueDec){case 0:break;case 1:a=40;break;case 2:a=80;break;default:this.value=[];return}let c=parseInt(i,10);if(isNaN(c))return;s.valueDec=c+a,o=!1}else{let s=new ms;if(i>Number.MAX_SAFE_INTEGER){sc();let a=BigInt(i);s.valueBigInt=a}else if(s.valueDec=parseInt(i,10),isNaN(s.valueDec))return;this.value.length||(s.isFirstSid=!0,o=!0),this.value.push(s)}while(n!==-1)}toString(){let e="",t=!1;for(let n=0;n<this.value.length;n++){t=this.value[n].isHexOnly;let i=this.value[n].toString();n!==0&&(e=`${e}.`),t?(i=`{${i}}`,this.value[n].isFirstSid?e=`2.{${i} - 80}`:e+=i):e+=i}return e}toJSON(){let e={...super.toJSON(),value:this.toString(),sidArray:[]};for(let t=0;t<this.value.length;t++)e.sidArray.push(this.value[t].toJSON());return e}};Ec.NAME="ObjectIdentifierValueBlock";var T1,rr=class extends Ye{constructor(e={}){super(e,Ec),this.idBlock.tagClass=1,this.idBlock.tagNumber=6}getValue(){return this.valueBlock.toString()}setValue(e){this.valueBlock.fromString(e)}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()||"empty"}`}toJSON(){return{...super.toJSON(),value:this.getValue()}}};T1=rr;z.ObjectIdentifier=T1;rr.NAME="OBJECT IDENTIFIER";var ys=class extends Qr(jr){constructor({valueDec:e=0,...t}={}){super(t),this.valueDec=e}fromBER(e,t,n){if(n===0)return t;let i=se.BufferSourceConverter.toUint8Array(e);if(!Jr(this,i,t,n))return-1;let o=i.subarray(t,t+n);this.valueHexView=new Uint8Array(n);for(let a=0;a<n&&(this.valueHexView[a]=o[a]&127,this.blockLength++,!!(o[a]&128));a++);let s=new Uint8Array(this.blockLength);for(let a=0;a<this.blockLength;a++)s[a]=this.valueHexView[a];return this.valueHexView=s,o[this.blockLength-1]&128?(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=xi(this.valueHexView,7):(this.isHexOnly=!0,this.warnings.push("Too big SID for decoding, hex only")),t+this.blockLength)}toBER(e){if(this.isHexOnly){if(e)return new ArrayBuffer(this.valueHexView.byteLength);let i=this.valueHexView,o=new Uint8Array(this.blockLength);for(let s=0;s<this.blockLength-1;s++)o[s]=i[s]|128;return o[this.blockLength-1]=i[this.blockLength-1],o.buffer}let t=On(this.valueDec,7);if(t.byteLength===0)return this.error="Error during encoding SID value",nr;let n=new Uint8Array(t.byteLength);if(!e){let i=new Uint8Array(t),o=t.byteLength-1;for(let s=0;s<o;s++)n[s]=i[s]|128;n[o]=i[o]}return n.buffer}toString(){let e="";return this.isHexOnly?e=se.Convert.ToHex(this.valueHexView):e=this.valueDec.toString(),e}toJSON(){return{...super.toJSON(),valueDec:this.valueDec}}};ys.NAME="relativeSidBlock";var xc=class extends tt{constructor({value:e=go,...t}={}){super(t),this.value=[],e&&this.fromString(e)}fromBER(e,t,n){let i=t;for(;n>0;){let o=new ys;if(i=o.fromBER(e,i,n),i===-1)return this.blockLength=0,this.error=o.error,i;this.blockLength+=o.blockLength,n-=o.blockLength,this.value.push(o)}return i}toBER(e,t){let n=[];for(let i=0;i<this.value.length;i++){let o=this.value[i].toBER(e);if(o.byteLength===0)return this.error=this.value[i].error,nr;n.push(o)}return Xd(n)}fromString(e){this.value=[];let t=0,n=0,i="";do{n=e.indexOf(".",t),n===-1?i=e.substring(t):i=e.substring(t,n),t=n+1;let o=new ys;if(o.valueDec=parseInt(i,10),isNaN(o.valueDec))return!0;this.value.push(o)}while(n!==-1);return!0}toString(){let e="",t=!1;for(let n=0;n<this.value.length;n++){t=this.value[n].isHexOnly;let i=this.value[n].toString();n!==0&&(e=`${e}.`),t&&(i=`{${i}}`),e+=i}return e}toJSON(){let e={...super.toJSON(),value:this.toString(),sidArray:[]};for(let t=0;t<this.value.length;t++)e.sidArray.push(this.value[t].toJSON());return e}};xc.NAME="RelativeObjectIdentifierValueBlock";var N1,bc=class extends Ye{constructor(e={}){super(e,xc),this.idBlock.tagClass=1,this.idBlock.tagNumber=13}getValue(){return this.valueBlock.toString()}setValue(e){this.valueBlock.fromString(e)}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()||"empty"}`}toJSON(){return{...super.toJSON(),value:this.getValue()}}};N1=bc;z.RelativeObjectIdentifier=N1;bc.NAME="RelativeObjectIdentifier";var C1,Me=class extends Pn{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=16}};C1=Me;z.Sequence=C1;Me.NAME="SEQUENCE";var L1,vc=class extends Pn{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=17}};L1=vc;z.Set=L1;vc.NAME="SET";var Ac=class extends Qr(tt){constructor({...e}={}){super(e),this.isHexOnly=!0,this.value=go}toJSON(){return{...super.toJSON(),value:this.value}}};Ac.NAME="StringValueBlock";var _c=class extends Ac{};_c.NAME="SimpleStringValueBlock";var lt=class extends lc{constructor({...e}={}){super(e,_c)}fromBuffer(e){this.valueBlock.value=String.fromCharCode.apply(null,se.BufferSourceConverter.toUint8Array(e))}fromString(e){let t=e.length,n=this.valueBlock.valueHexView=new Uint8Array(t);for(let i=0;i<t;i++)n[i]=e.charCodeAt(i);this.valueBlock.value=e}};lt.NAME="SIMPLE STRING";var Sc=class extends lt{fromBuffer(e){this.valueBlock.valueHexView=se.BufferSourceConverter.toUint8Array(e);try{this.valueBlock.value=se.Convert.ToUtf8String(e)}catch(t){this.warnings.push(`Error during "decodeURIComponent": ${t}, using raw string`),this.valueBlock.value=se.Convert.ToBinary(e)}}fromString(e){this.valueBlock.valueHexView=new Uint8Array(se.Convert.FromUtf8String(e)),this.valueBlock.value=e}};Sc.NAME="Utf8StringValueBlock";var U1,Zr=class extends Sc{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=12}};U1=Zr;z.Utf8String=U1;Zr.NAME="UTF8String";var Ic=class extends lt{fromBuffer(e){this.valueBlock.value=se.Convert.ToUtf16String(e),this.valueBlock.valueHexView=se.BufferSourceConverter.toUint8Array(e)}fromString(e){this.valueBlock.value=e,this.valueBlock.valueHexView=new Uint8Array(se.Convert.FromUtf16String(e))}};Ic.NAME="BmpStringValueBlock";var D1,Bc=class extends Ic{constructor({...e}={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=30}};D1=Bc;z.BmpString=D1;Bc.NAME="BMPString";var kc=class extends lt{fromBuffer(e){let t=ArrayBuffer.isView(e)?e.slice().buffer:e.slice(0),n=new Uint8Array(t);for(let i=0;i<n.length;i+=4)n[i]=n[i+3],n[i+1]=n[i+2],n[i+2]=0,n[i+3]=0;this.valueBlock.value=String.fromCharCode.apply(null,new Uint32Array(t))}fromString(e){let t=e.length,n=this.valueBlock.valueHexView=new Uint8Array(t*4);for(let i=0;i<t;i++){let o=On(e.charCodeAt(i),8),s=new Uint8Array(o);if(s.length>4)continue;let a=4-s.length;for(let c=s.length-1;c>=0;c--)n[i*4+c+a]=s[c]}this.valueBlock.value=e}};kc.NAME="UniversalStringValueBlock";var O1,Rc=class extends kc{constructor({...e}={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=28}};O1=Rc;z.UniversalString=O1;Rc.NAME="UniversalString";var P1,Tc=class extends lt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=18}};P1=Tc;z.NumericString=P1;Tc.NAME="NumericString";var F1,Nc=class extends lt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=19}};F1=Nc;z.PrintableString=F1;Nc.NAME="PrintableString";var V1,Cc=class extends lt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=20}};V1=Cc;z.TeletexString=V1;Cc.NAME="TeletexString";var M1,Lc=class extends lt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=21}};M1=Lc;z.VideotexString=M1;Lc.NAME="VideotexString";var H1,Uc=class extends lt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=22}};H1=Uc;z.IA5String=H1;Uc.NAME="IA5String";var $1,Dc=class extends lt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=25}};$1=Dc;z.GraphicString=$1;Dc.NAME="GraphicString";var z1,gs=class extends lt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=26}};z1=gs;z.VisibleString=z1;gs.NAME="VisibleString";var K1,Oc=class extends lt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=27}};K1=Oc;z.GeneralString=K1;Oc.NAME="GeneralString";var G1,Pc=class extends lt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=29}};G1=Pc;z.CharacterString=G1;Pc.NAME="CharacterString";var q1,ws=class extends gs{constructor({value:e,valueDate:t,...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 i=0;i<e.length;i++)this.valueBlock.valueHexView[i]=e.charCodeAt(i)}t&&(this.fromDate(t),this.valueBlock.valueHexView=new Uint8Array(this.toBuffer())),this.idBlock.tagClass=1,this.idBlock.tagNumber=23}fromBuffer(e){this.fromString(String.fromCharCode.apply(null,se.BufferSourceConverter.toUint8Array(e)))}toBuffer(){let e=this.toString(),t=new ArrayBuffer(e.length),n=new Uint8Array(t);for(let i=0;i<e.length;i++)n[i]=e.charCodeAt(i);return t}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 i=parseInt(n[1],10);i>=50?this.year=1900+i:this.year=2e3+i,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 t=new Array(7);return t[0]=wt(this.year<2e3?this.year-1900:this.year-2e3,2),t[1]=wt(this.month,2),t[2]=wt(this.day,2),t[3]=wt(this.hour,2),t[4]=wt(this.minute,2),t[5]=wt(this.second,2),t[6]="Z",t.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}}};q1=ws;z.UTCTime=q1;ws.NAME="UTCTime";var Y1,Fc=class extends ws{constructor(e={}){var t;super(e),(t=this.millisecond)!==null&&t!==void 0||(this.millisecond=0),this.idBlock.tagClass=1,this.idBlock.tagNumber=24}fromDate(e){super.fromDate(e),this.millisecond=e.getUTCMilliseconds()}toDate(){return new Date(Date.UTC(this.year,this.month-1,this.day,this.hour,this.minute,this.second,this.millisecond))}fromString(e){let t=!1,n="",i="",o=0,s,a=0,c=0;if(e[e.length-1]==="Z")n=e.substring(0,e.length-1),t=!0;else{let d=new Number(e[e.length-1]);if(isNaN(d.valueOf()))throw new Error("Wrong input string for conversion");n=e}if(t){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 d=1,p=n.indexOf("+"),f="";if(p===-1&&(p=n.indexOf("-"),d=-1),p!==-1){if(f=n.substring(p+1),n=n.substring(0,p),f.length!==2&&f.length!==4)throw new Error("Wrong input string for conversion");let h=parseInt(f.substring(0,2),10);if(isNaN(h.valueOf()))throw new Error("Wrong input string for conversion");if(a=d*h,f.length===4){if(h=parseInt(f.substring(2,4),10),isNaN(h.valueOf()))throw new Error("Wrong input string for conversion");c=d*h}}}let u=n.indexOf(".");if(u===-1&&(u=n.indexOf(",")),u!==-1){let d=new Number(`0${n.substring(u)}`);if(isNaN(d.valueOf()))throw new Error("Wrong input string for conversion");o=d.valueOf(),i=n.substring(0,u)}else i=n;switch(!0){case i.length===8:if(s=/(\d{4})(\d{2})(\d{2})/ig,u!==-1)throw new Error("Wrong input string for conversion");break;case i.length===10:if(s=/(\d{4})(\d{2})(\d{2})(\d{2})/ig,u!==-1){let d=60*o;this.minute=Math.floor(d),d=60*(d-this.minute),this.second=Math.floor(d),d=1e3*(d-this.second),this.millisecond=Math.floor(d)}break;case i.length===12:if(s=/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})/ig,u!==-1){let d=60*o;this.second=Math.floor(d),d=1e3*(d-this.second),this.millisecond=Math.floor(d)}break;case i.length===14:if(s=/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/ig,u!==-1){let d=1e3*o;this.millisecond=Math.floor(d)}break;default:throw new Error("Wrong input string for conversion")}let l=s.exec(i);if(l===null)throw new Error("Wrong input string for conversion");for(let d=1;d<l.length;d++)switch(d){case 1:this.year=parseInt(l[d],10);break;case 2:this.month=parseInt(l[d],10);break;case 3:this.day=parseInt(l[d],10);break;case 4:this.hour=parseInt(l[d],10)+a;break;case 5:this.minute=parseInt(l[d],10)+c;break;case 6:this.second=parseInt(l[d],10);break;default:throw new Error("Wrong input string for conversion")}if(t===!1){let d=new Date(this.year,this.month,this.day,this.hour,this.minute,this.second,this.millisecond);this.year=d.getUTCFullYear(),this.month=d.getUTCMonth(),this.day=d.getUTCDay(),this.hour=d.getUTCHours(),this.minute=d.getUTCMinutes(),this.second=d.getUTCSeconds(),this.millisecond=d.getUTCMilliseconds()}}toString(e="iso"){if(e==="iso"){let t=[];return t.push(wt(this.year,4)),t.push(wt(this.month,2)),t.push(wt(this.day,2)),t.push(wt(this.hour,2)),t.push(wt(this.minute,2)),t.push(wt(this.second,2)),this.millisecond!==0&&(t.push("."),t.push(wt(this.millisecond,3))),t.push("Z"),t.join("")}return super.toString(e)}toJSON(){return{...super.toJSON(),millisecond:this.millisecond}}};Y1=Fc;z.GeneralizedTime=Y1;Fc.NAME="GeneralizedTime";var W1,Vc=class extends Zr{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=31}};W1=Vc;z.DATE=W1;Vc.NAME="DATE";var j1,Mc=class extends Zr{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=32}};j1=Mc;z.TimeOfDay=j1;Mc.NAME="TimeOfDay";var X1,Hc=class extends Zr{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=33}};X1=Hc;z.DateTime=X1;Hc.NAME="DateTime";var Z1,$c=class extends Zr{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=34}};Z1=$c;z.Duration=Z1;$c.NAME="Duration";var J1,zc=class extends Zr{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=14}};J1=zc;z.TIME=J1;zc.NAME="TIME";function Y6(r){let{result:e}=wo(r),t=e.valueBlock.value;return{n:J(vr(t[1].toBigInt()),"base64url"),e:J(vr(t[2].toBigInt()),"base64url"),d:J(vr(t[3].toBigInt()),"base64url"),p:J(vr(t[4].toBigInt()),"base64url"),q:J(vr(t[5].toBigInt()),"base64url"),dp:J(vr(t[6].toBigInt()),"base64url"),dq:J(vr(t[7].toBigInt()),"base64url"),qi:J(vr(t[8].toBigInt()),"base64url"),kty:"RSA",alg:"RS256"}}function W6(r){if(r.n==null||r.e==null||r.d==null||r.p==null||r.q==null||r.dp==null||r.dq==null||r.qi==null)throw new O("JWK was missing components","ERR_INVALID_PARAMETERS");let t=new Me({value:[new Ue({value:0}),Ue.fromBigInt(Ar(H(r.n,"base64url"))),Ue.fromBigInt(Ar(H(r.e,"base64url"))),Ue.fromBigInt(Ar(H(r.d,"base64url"))),Ue.fromBigInt(Ar(H(r.p,"base64url"))),Ue.fromBigInt(Ar(H(r.q,"base64url"))),Ue.fromBigInt(Ar(H(r.dp,"base64url"))),Ue.fromBigInt(Ar(H(r.dq,"base64url"))),Ue.fromBigInt(Ar(H(r.qi,"base64url")))]}).toBER();return new Uint8Array(t,0,t.byteLength)}function j6(r){let{result:e}=wo(r),t=e.valueBlock.value[1].valueBlock.value[0].valueBlock.value;return{kty:"RSA",n:J(vr(t[0].toBigInt()),"base64url"),e:J(vr(t[1].toBigInt()),"base64url")}}function X6(r){if(r.n==null||r.e==null)throw new O("JWK was missing components","ERR_INVALID_PARAMETERS");let t=new Me({value:[new Me({value:[new rr({value:"1.2.840.113549.1.1.1"}),new Fn]}),new yo({valueHex:new Me({value:[Ue.fromBigInt(Ar(H(r.n,"base64url"))),Ue.fromBigInt(Ar(H(r.e,"base64url")))]}).toBER()})]}).toBER();return new Uint8Array(t,0,t.byteLength)}function vr(r){let e=r.toString(16);e.length%2>0&&(e=`0${e}`);let t=e.length/2,n=new Uint8Array(t),i=0,o=0;for(;i<t;)n[i]=parseInt(e.slice(o,o+2),16),i+=1,o+=2;return n}function Ar(r){let e=[];return r.forEach(function(t){let n=t.toString(16);n.length%2>0&&(n=`0${n}`),e.push(n)}),BigInt("0x"+e.join(""))}var Z6=16,Jd=32,Qd=1e4;async function J6(r,e){let t=ct.get(),i=new Me({value:[new Ue({value:0}),new Me({value:[new rr({value:"1.2.840.113549.1.1.1"}),new Fn]}),new Xr({valueHex:r.marshal()})]}).toBER(),o=new Uint8Array(i,0,i.byteLength),s=Ei(Z6),a=await Yd(lo,e,s,{c:Qd,dkLen:Jd}),c=Ei(16),u=await t.subtle.importKey("raw",a,"AES-CBC",!1,["encrypt"]),l=await t.subtle.encrypt({name:"AES-CBC",iv:c},u,o),d=new Me({value:[new Xr({valueHex:s}),new Ue({value:Qd}),new Ue({value:Jd}),new Me({value:[new rr({value:"1.2.840.113549.2.11"}),new Fn]})]}),p=new Me({value:[new rr({value:"1.2.840.113549.1.5.13"}),new Me({value:[new Me({value:[new rr({value:"1.2.840.113549.1.5.12"}),d]}),new Me({value:[new rr({value:"2.16.840.1.101.3.4.1.42"}),new Xr({valueHex:c})]})]})]}),h=new Me({value:[p,new Xr({valueHex:l})]}).toBER(),m=new Uint8Array(h,0,h.byteLength);return["-----BEGIN ENCRYPTED PRIVATE KEY-----",...J(m,"base64pad").split(/(.{64})/).filter(Boolean),"-----END ENCRYPTED PRIVATE KEY-----"].join(`
|
|
8
|
+
`)}async function Q6(r,e){let t=ct.get(),n;if(r.includes("-----BEGIN ENCRYPTED PRIVATE KEY-----")){let i=H(r.replace("-----BEGIN ENCRYPTED PRIVATE KEY-----","").replace("-----END ENCRYPTED PRIVATE KEY-----","").replace(/\n/g,"").trim(),"base64pad"),{result:o}=wo(i),{iv:s,salt:a,iterations:c,keySize:u,cipherText:l}=ev(o),d=await Yd(lo,e,a,{c,dkLen:u}),p=await t.subtle.importKey("raw",d,"AES-CBC",!1,["decrypt"]),f=Es(await t.subtle.decrypt({name:"AES-CBC",iv:s},p,l)),{result:h}=wo(f);n=Q1(h)}else if(r.includes("-----BEGIN PRIVATE KEY-----")){let i=H(r.replace("-----BEGIN PRIVATE KEY-----","").replace("-----END PRIVATE KEY-----","").replace(/\n/g,"").trim(),"base64pad"),{result:o}=wo(i);n=Q1(o)}else throw new O("Could not parse private key from PEM data","ERR_INVALID_PARAMETERS");return ef(n)}function ev(r){let e=r.valueBlock.value[0];if(e.valueBlock.value[0].toString()!=="OBJECT IDENTIFIER : 1.2.840.113549.1.5.13")throw new O("Only pkcs5PBES2 encrypted private keys are supported","ERR_INVALID_PARAMS");let n=e.valueBlock.value[1].valueBlock.value[0];if(n.valueBlock.value[0].toString()!=="OBJECT IDENTIFIER : 1.2.840.113549.1.5.12")throw new O("Only pkcs5PBKDF2 key derivation functions are supported","ERR_INVALID_PARAMS");let o=n.valueBlock.value[1],s=Es(o.valueBlock.value[0].getValue()),a=Qd,c=Jd;if(o.valueBlock.value.length===3)a=Number(o.valueBlock.value[1].toBigInt()),c=Number(o.valueBlock.value[2].toBigInt());else if(o.valueBlock.value.length===2)throw new O("Could not derive key size and iterations from PEM file - please use @libp2p/rsa to re-import your key","ERR_INVALID_PARAMS");let u=e.valueBlock.value[1].valueBlock.value[1],l=u.valueBlock.value[0].toString();if(l!=="OBJECT IDENTIFIER : 1.2.840.113549.3.7"){if(l!=="OBJECT IDENTIFIER : 1.3.14.3.2.7"){if(l!=="OBJECT IDENTIFIER : 2.16.840.1.101.3.4.1.2"){if(l!=="OBJECT IDENTIFIER : 2.16.840.1.101.3.4.1.22"){if(l!=="OBJECT IDENTIFIER : 2.16.840.1.101.3.4.1.42")throw new O("Only AES-CBC encryption schemes are supported","ERR_INVALID_PARAMS")}}}}let d=Es(u.valueBlock.value[1].getValue());return{cipherText:Es(r.valueBlock.value[1].getValue()),salt:s,iterations:a,keySize:c,iv:d}}function Q1(r){return Es(r.valueBlock.value[2].getValue())}function Es(r){return new Uint8Array(r,0,r.byteLength)}async function em(r){let e=await ct.get().subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:r,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!0,["sign","verify"]),t=await nm(e);return{privateKey:t[0],publicKey:t[1]}}async function tf(r){let t=[await ct.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!0,["sign"]),await tv(r)],n=await nm({privateKey:t[0],publicKey:t[1]});return{privateKey:n[0],publicKey:n[1]}}async function tm(r,e){let t=await ct.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]),n=await ct.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},t,e instanceof Uint8Array?e:e.subarray());return new Uint8Array(n,0,n.byteLength)}async function rm(r,e,t){let n=await ct.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);return ct.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},n,e,t instanceof Uint8Array?t:t.subarray())}async function nm(r){if(r.privateKey==null||r.publicKey==null)throw new O("Private and public key are required","ERR_INVALID_PARAMETERS");return Promise.all([ct.get().subtle.exportKey("jwk",r.privateKey),ct.get().subtle.exportKey("jwk",r.publicKey)])}async function tv(r){return ct.get().subtle.importKey("jwk",{kty:r.kty,n:r.n,e:r.e},{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!0,["verify"])}function Gc(r){if(r.kty!=="RSA")throw new O("invalid key type","ERR_INVALID_KEY_TYPE");if(r.n==null)throw new O("invalid key modulus","ERR_INVALID_KEY_MODULUS");return H(r.n,"base64url").length*8}var bs=8192,xs=class{_key;constructor(e){this._key=e}verify(e,t){return rm(this._key,t,e)}marshal(){return Vn.jwkToPkix(this._key)}get bytes(){return Er.encode({Type:be.RSA,Data:this.marshal()}).subarray()}equals(e){return he(this.bytes,e.bytes)}hash(){let e=fe.digest(this.bytes);return Kt(e)?e.then(({bytes:t})=>t):e.bytes}},Eo=class{_key;_publicKey;constructor(e,t){this._key=e,this._publicKey=t}genSecret(){return Ei(16)}sign(e){return tm(this._key,e)}get public(){if(this._publicKey==null)throw new O("public key not provided","ERR_PUBKEY_NOT_PROVIDED");return new xs(this._publicKey)}marshal(){return Vn.jwkToPkcs1(this._key)}get bytes(){return xr.encode({Type:be.RSA,Data:this.marshal()}).subarray()}equals(e){return he(this.bytes,e.bytes)}hash(){let e=fe.digest(this.bytes);return Kt(e)?e.then(({bytes:t})=>t):e.bytes}async id(){let e=await this.public.hash();return J(e,"base58btc")}async export(e,t="pkcs-8"){if(t==="pkcs-8")return Vn.exportToPem(this,e);if(t==="libp2p-key")return ho(this.bytes,e);throw new O(`export format '${t}' is not supported`,"ERR_INVALID_EXPORT_FORMAT")}};async function ef(r){let e=Vn.pkcs1ToJwk(r);if(Gc(e)>bs)throw new O("key size is too large","ERR_KEY_SIZE_TOO_LARGE");let t=await tf(e);return new Eo(t.privateKey,t.publicKey)}function nv(r){let e=Vn.pkixToJwk(r);if(Gc(e)>bs)throw new O("key size is too large","ERR_KEY_SIZE_TOO_LARGE");return new xs(e)}async function iv(r){if(Gc(r)>bs)throw new O("key size is too large","ERR_KEY_SIZE_TOO_LARGE");let e=await tf(r);return new Eo(e.privateKey,e.publicKey)}async function ov(r){if(r>bs)throw new O("key size is too large","ERR_KEY_SIZE_TOO_LARGE");let e=await em(r);return new Eo(e.privateKey,e.publicKey)}var cf={};Be(cf,{Secp256k1PrivateKey:()=>As,Secp256k1PublicKey:()=>vs,generateKeyPair:()=>xv,unmarshalSecp256k1PrivateKey:()=>wv,unmarshalSecp256k1PublicKey:()=>Ev});var sv=(r,e,t)=>r&e^~r&t,av=(r,e,t)=>r&e^r&t^e&t,cv=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),Mn=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Hn=new Uint32Array(64),nf=class extends co{constructor(){super(64,32,8,!1),this.A=Mn[0]|0,this.B=Mn[1]|0,this.C=Mn[2]|0,this.D=Mn[3]|0,this.E=Mn[4]|0,this.F=Mn[5]|0,this.G=Mn[6]|0,this.H=Mn[7]|0}get(){let{A:e,B:t,C:n,D:i,E:o,F:s,G:a,H:c}=this;return[e,t,n,i,o,s,a,c]}set(e,t,n,i,o,s,a,c){this.A=e|0,this.B=t|0,this.C=n|0,this.D=i|0,this.E=o|0,this.F=s|0,this.G=a|0,this.H=c|0}process(e,t){for(let d=0;d<16;d++,t+=4)Hn[d]=e.getUint32(t,!1);for(let d=16;d<64;d++){let p=Hn[d-15],f=Hn[d-2],h=Qt(p,7)^Qt(p,18)^p>>>3,m=Qt(f,17)^Qt(f,19)^f>>>10;Hn[d]=m+Hn[d-7]+h+Hn[d-16]|0}let{A:n,B:i,C:o,D:s,E:a,F:c,G:u,H:l}=this;for(let d=0;d<64;d++){let p=Qt(a,6)^Qt(a,11)^Qt(a,25),f=l+p+sv(a,c,u)+cv[d]+Hn[d]|0,m=(Qt(n,2)^Qt(n,13)^Qt(n,22))+av(n,i,o)|0;l=u,u=c,c=a,a=s+f|0,s=o,o=i,i=n,n=f+m|0}n=n+this.A|0,i=i+this.B|0,o=o+this.C|0,s=s+this.D|0,a=a+this.E|0,c=c+this.F|0,u=u+this.G|0,l=l+this.H|0,this.set(n,i,o,s,a,c,u,l)}roundClean(){Hn.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};var im=Ga(()=>new nf);function lv(r){let e=cs(r);wr(e,{a:"field",b:"field"},{allowedPrivateKeyLengths:"array",wrapPrivateKey:"boolean",isTorsionFree:"function",clearCofactor:"function",allowInfinityPoint:"boolean",fromBytes:"function",toBytes:"function"});let{endo:t,Fp:n,a:i}=e;if(t){if(!n.eql(i,n.ZERO))throw new Error("Endomorphism can only be defined for Koblitz curves that have a=0");if(typeof t!="object"||typeof t.beta!="bigint"||typeof t.splitScalar!="function")throw new Error("Expected endomorphism with beta: bigint and splitScalar: function")}return Object.freeze({...e})}var{bytesToNumberBE:uv,hexToBytes:dv}=Wa,bi={Err:class extends Error{constructor(e=""){super(e)}},_parseInt(r){let{Err:e}=bi;if(r.length<2||r[0]!==2)throw new e("Invalid signature integer tag");let t=r[1],n=r.subarray(2,t+2);if(!t||n.length!==t)throw new e("Invalid signature integer: wrong length");if(n[0]&128)throw new e("Invalid signature integer: negative");if(n[0]===0&&!(n[1]&128))throw new e("Invalid signature integer: unnecessary leading zero");return{d:uv(n),l:r.subarray(t+2)}},toSig(r){let{Err:e}=bi,t=typeof r=="string"?dv(r):r;if(!er(t))throw new Error("ui8a expected");let n=t.length;if(n<2||t[0]!=48)throw new e("Invalid signature tag");if(t[1]!==n-2)throw new e("Invalid signature: incorrect length");let{d:i,l:o}=bi._parseInt(t.subarray(2)),{d:s,l:a}=bi._parseInt(o);if(a.length)throw new e("Invalid signature: left bytes after parsing");return{r:i,s}},hexFromSig(r){let e=u=>Number.parseInt(u[0],16)&8?"00"+u:u,t=u=>{let l=u.toString(16);return l.length&1?`0${l}`:l},n=e(t(r.s)),i=e(t(r.r)),o=n.length/2,s=i.length/2,a=t(o),c=t(s);return`30${t(s+o+4)}02${c}${i}02${a}${n}`}},en=BigInt(0),qt=BigInt(1),DT=BigInt(2),om=BigInt(3),OT=BigInt(4);function fv(r){let e=lv(r),{Fp:t}=e,n=e.toBytes||((h,m,y)=>{let g=m.toAffine();return Gr(Uint8Array.from([4]),t.toBytes(g.x),t.toBytes(g.y))}),i=e.fromBytes||(h=>{let m=h.subarray(1),y=t.fromBytes(m.subarray(0,t.BYTES)),g=t.fromBytes(m.subarray(t.BYTES,2*t.BYTES));return{x:y,y:g}});function o(h){let{a:m,b:y}=e,g=t.sqr(h),E=t.mul(g,h);return t.add(t.add(E,t.mul(h,m)),y)}if(!t.eql(t.sqr(e.Gy),o(e.Gx)))throw new Error("bad generator point: equation left != right");function s(h){return typeof h=="bigint"&&en<h&&h<e.n}function a(h){if(!s(h))throw new Error("Expected valid bigint: 0 < bigint < curve.n")}function c(h){let{allowedPrivateKeyLengths:m,nByteLength:y,wrapPrivateKey:g,n:E}=e;if(m&&typeof h!="bigint"){if(er(h)&&(h=zr(h)),typeof h!="string"||!m.includes(h.length))throw new Error("Invalid key");h=h.padStart(y*2,"0")}let x;try{x=typeof h=="bigint"?h:Kr(Re("private key",h,y))}catch{throw new Error(`private key must be ${y} bytes, hex or bigint, not ${typeof h}`)}return g&&(x=ye(x,E)),a(x),x}let u=new Map;function l(h){if(!(h instanceof d))throw new Error("ProjectivePoint expected")}class d{constructor(m,y,g){if(this.px=m,this.py=y,this.pz=g,m==null||!t.isValid(m))throw new Error("x required");if(y==null||!t.isValid(y))throw new Error("y required");if(g==null||!t.isValid(g))throw new Error("z required")}static fromAffine(m){let{x:y,y:g}=m||{};if(!m||!t.isValid(y)||!t.isValid(g))throw new Error("invalid affine point");if(m instanceof d)throw new Error("projective point not allowed");let E=x=>t.eql(x,t.ZERO);return E(y)&&E(g)?d.ZERO:new d(y,g,t.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(m){let y=t.invertBatch(m.map(g=>g.pz));return m.map((g,E)=>g.toAffine(y[E])).map(d.fromAffine)}static fromHex(m){let y=d.fromAffine(i(Re("pointHex",m)));return y.assertValidity(),y}static fromPrivateKey(m){return d.BASE.multiply(c(m))}_setWindowSize(m){this._WINDOW_SIZE=m,u.delete(this)}assertValidity(){if(this.is0()){if(e.allowInfinityPoint&&!t.is0(this.py))return;throw new Error("bad point: ZERO")}let{x:m,y}=this.toAffine();if(!t.isValid(m)||!t.isValid(y))throw new Error("bad point: x or y not FE");let g=t.sqr(y),E=o(m);if(!t.eql(g,E))throw new Error("bad point: equation left != right");if(!this.isTorsionFree())throw new Error("bad point: not in prime-order subgroup")}hasEvenY(){let{y:m}=this.toAffine();if(t.isOdd)return!t.isOdd(m);throw new Error("Field doesn't support isOdd")}equals(m){l(m);let{px:y,py:g,pz:E}=this,{px:x,py:_,pz:S}=m,A=t.eql(t.mul(y,S),t.mul(x,E)),v=t.eql(t.mul(g,S),t.mul(_,E));return A&&v}negate(){return new d(this.px,t.neg(this.py),this.pz)}double(){let{a:m,b:y}=e,g=t.mul(y,om),{px:E,py:x,pz:_}=this,S=t.ZERO,A=t.ZERO,v=t.ZERO,b=t.mul(E,E),T=t.mul(x,x),C=t.mul(_,_),N=t.mul(E,x);return N=t.add(N,N),v=t.mul(E,_),v=t.add(v,v),S=t.mul(m,v),A=t.mul(g,C),A=t.add(S,A),S=t.sub(T,A),A=t.add(T,A),A=t.mul(S,A),S=t.mul(N,S),v=t.mul(g,v),C=t.mul(m,C),N=t.sub(b,C),N=t.mul(m,N),N=t.add(N,v),v=t.add(b,b),b=t.add(v,b),b=t.add(b,C),b=t.mul(b,N),A=t.add(A,b),C=t.mul(x,_),C=t.add(C,C),b=t.mul(C,N),S=t.sub(S,b),v=t.mul(C,T),v=t.add(v,v),v=t.add(v,v),new d(S,A,v)}add(m){l(m);let{px:y,py:g,pz:E}=this,{px:x,py:_,pz:S}=m,A=t.ZERO,v=t.ZERO,b=t.ZERO,T=e.a,C=t.mul(e.b,om),N=t.mul(y,x),$=t.mul(g,_),D=t.mul(E,S),ne=t.add(y,g),B=t.add(x,_);ne=t.mul(ne,B),B=t.add(N,$),ne=t.sub(ne,B),B=t.add(y,E);let U=t.add(x,S);return B=t.mul(B,U),U=t.add(N,D),B=t.sub(B,U),U=t.add(g,E),A=t.add(_,S),U=t.mul(U,A),A=t.add($,D),U=t.sub(U,A),b=t.mul(T,B),A=t.mul(C,D),b=t.add(A,b),A=t.sub($,b),b=t.add($,b),v=t.mul(A,b),$=t.add(N,N),$=t.add($,N),D=t.mul(T,D),B=t.mul(C,B),$=t.add($,D),D=t.sub(N,D),D=t.mul(T,D),B=t.add(B,D),N=t.mul($,B),v=t.add(v,N),N=t.mul(U,B),A=t.mul(ne,A),A=t.sub(A,N),N=t.mul(ne,$),b=t.mul(U,b),b=t.add(b,N),new d(A,v,b)}subtract(m){return this.add(m.negate())}is0(){return this.equals(d.ZERO)}wNAF(m){return f.wNAFCached(this,u,m,y=>{let g=t.invertBatch(y.map(E=>E.pz));return y.map((E,x)=>E.toAffine(g[x])).map(d.fromAffine)})}multiplyUnsafe(m){let y=d.ZERO;if(m===en)return y;if(a(m),m===qt)return this;let{endo:g}=e;if(!g)return f.unsafeLadder(this,m);let{k1neg:E,k1:x,k2neg:_,k2:S}=g.splitScalar(m),A=y,v=y,b=this;for(;x>en||S>en;)x&qt&&(A=A.add(b)),S&qt&&(v=v.add(b)),b=b.double(),x>>=qt,S>>=qt;return E&&(A=A.negate()),_&&(v=v.negate()),v=new d(t.mul(v.px,g.beta),v.py,v.pz),A.add(v)}multiply(m){a(m);let y=m,g,E,{endo:x}=e;if(x){let{k1neg:_,k1:S,k2neg:A,k2:v}=x.splitScalar(y),{p:b,f:T}=this.wNAF(S),{p:C,f:N}=this.wNAF(v);b=f.constTimeNegate(_,b),C=f.constTimeNegate(A,C),C=new d(t.mul(C.px,x.beta),C.py,C.pz),g=b.add(C),E=T.add(N)}else{let{p:_,f:S}=this.wNAF(y);g=_,E=S}return d.normalizeZ([g,E])[0]}multiplyAndAddUnsafe(m,y,g){let E=d.BASE,x=(S,A)=>A===en||A===qt||!S.equals(E)?S.multiplyUnsafe(A):S.multiply(A),_=x(this,y).add(x(m,g));return _.is0()?void 0:_}toAffine(m){let{px:y,py:g,pz:E}=this,x=this.is0();m==null&&(m=x?t.ONE:t.inv(E));let _=t.mul(y,m),S=t.mul(g,m),A=t.mul(E,m);if(x)return{x:t.ZERO,y:t.ZERO};if(!t.eql(A,t.ONE))throw new Error("invZ was invalid");return{x:_,y:S}}isTorsionFree(){let{h:m,isTorsionFree:y}=e;if(m===qt)return!0;if(y)return y(d,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){let{h:m,clearCofactor:y}=e;return m===qt?this:y?y(d,this):this.multiplyUnsafe(e.h)}toRawBytes(m=!0){return this.assertValidity(),n(d,this,m)}toHex(m=!0){return zr(this.toRawBytes(m))}}d.BASE=new d(e.Gx,e.Gy,t.ONE),d.ZERO=new d(t.ZERO,t.ONE,t.ZERO);let p=e.nBitLength,f=Za(d,e.endo?Math.ceil(p/2):p);return{CURVE:e,ProjectivePoint:d,normPrivateKeyToScalar:c,weierstrassEquation:o,isWithinCurveOrder:s}}function hv(r){let e=cs(r);return wr(e,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...e})}function sm(r){let e=hv(r),{Fp:t,n}=e,i=t.BYTES+1,o=2*t.BYTES+1;function s(B){return en<B&&B<t.ORDER}function a(B){return ye(B,n)}function c(B){return ja(B,n)}let{ProjectivePoint:u,normPrivateKeyToScalar:l,weierstrassEquation:d,isWithinCurveOrder:p}=fv({...e,toBytes(B,U,X){let L=U.toAffine(),k=t.toBytes(L.x),K=Gr;return X?K(Uint8Array.from([U.hasEvenY()?2:3]),k):K(Uint8Array.from([4]),k,t.toBytes(L.y))},fromBytes(B){let U=B.length,X=B[0],L=B.subarray(1);if(U===i&&(X===2||X===3)){let k=Kr(L);if(!s(k))throw new Error("Point is not on curve");let K=d(k),W=t.sqrt(K),Z=(W&qt)===qt;return(X&1)===1!==Z&&(W=t.neg(W)),{x:k,y:W}}else if(U===o&&X===4){let k=t.fromBytes(L.subarray(0,t.BYTES)),K=t.fromBytes(L.subarray(t.BYTES,2*t.BYTES));return{x:k,y:K}}else throw new Error(`Point of length ${U} was invalid. Expected ${i} compressed bytes or ${o} uncompressed bytes`)}}),f=B=>zr(Dn(B,e.nByteLength));function h(B){let U=n>>qt;return B>U}function m(B){return h(B)?a(-B):B}let y=(B,U,X)=>Kr(B.slice(U,X));class g{constructor(U,X,L){this.r=U,this.s=X,this.recovery=L,this.assertValidity()}static fromCompact(U){let X=e.nByteLength;return U=Re("compactSignature",U,X*2),new g(y(U,0,X),y(U,X,2*X))}static fromDER(U){let{r:X,s:L}=bi.toSig(Re("DER",U));return new g(X,L)}assertValidity(){if(!p(this.r))throw new Error("r must be 0 < r < CURVE.n");if(!p(this.s))throw new Error("s must be 0 < s < CURVE.n")}addRecoveryBit(U){return new g(this.r,this.s,U)}recoverPublicKey(U){let{r:X,s:L,recovery:k}=this,K=v(Re("msgHash",U));if(k==null||![0,1,2,3].includes(k))throw new Error("recovery id invalid");let W=k===2||k===3?X+e.n:X;if(W>=t.ORDER)throw new Error("recovery id 2 or 3 invalid");let Z=k&1?"03":"02",re=u.fromHex(Z+f(W)),ie=c(W),me=a(-K*ie),ae=a(L*ie),ue=u.BASE.multiplyAndAddUnsafe(re,me,ae);if(!ue)throw new Error("point at infinify");return ue.assertValidity(),ue}hasHighS(){return h(this.s)}normalizeS(){return this.hasHighS()?new g(this.r,a(-this.s),this.recovery):this}toDERRawBytes(){return mi(this.toDERHex())}toDERHex(){return bi.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return mi(this.toCompactHex())}toCompactHex(){return f(this.r)+f(this.s)}}let E={isValidPrivateKey(B){try{return l(B),!0}catch{return!1}},normPrivateKeyToScalar:l,randomPrivateKey:()=>{let B=Vd(e.n);return e1(e.randomBytes(B),e.n)},precompute(B=8,U=u.BASE){return U._setWindowSize(B),U.multiply(BigInt(3)),U}};function x(B,U=!0){return u.fromPrivateKey(B).toRawBytes(U)}function _(B){let U=er(B),X=typeof B=="string",L=(U||X)&&B.length;return U?L===i||L===o:X?L===2*i||L===2*o:B instanceof u}function S(B,U,X=!0){if(_(B))throw new Error("first arg must be private key");if(!_(U))throw new Error("second arg must be public key");return u.fromHex(U).multiply(l(B)).toRawBytes(X)}let A=e.bits2int||function(B){let U=Kr(B),X=B.length*8-e.nBitLength;return X>0?U>>BigInt(X):U},v=e.bits2int_modN||function(B){return a(A(B))},b=as(e.nBitLength);function T(B){if(typeof B!="bigint")throw new Error("bigint expected");if(!(en<=B&&B<b))throw new Error(`bigint expected < 2^${e.nBitLength}`);return Dn(B,e.nByteLength)}function C(B,U,X=N){if(["recovered","canonical"].some(Ie=>Ie in X))throw new Error("sign() legacy options not supported");let{hash:L,randomBytes:k}=e,{lowS:K,prehash:W,extraEntropy:Z}=X;K==null&&(K=!0),B=Re("msgHash",B),W&&(B=Re("prehashed msgHash",L(B)));let re=v(B),ie=l(U),me=[T(ie),T(re)];if(Z!=null){let Ie=Z===!0?k(t.BYTES):Z;me.push(Re("extraEntropy",Ie))}let ae=Gr(...me),ue=re;function Le(Ie){let Ke=A(Ie);if(!p(Ke))return;let Ge=c(Ke),Oe=u.BASE.multiply(Ke).toAffine(),Ze=a(Oe.x);if(Ze===en)return;let Vr=a(Ge*a(ue+Ze*ie));if(Vr===en)return;let ai=(Oe.x===Ze?0:2)|Number(Oe.y&qt),Xo=Vr;return K&&h(Vr)&&(Xo=m(Vr),ai^=1),new g(Ze,Xo,ai)}return{seed:ae,k2sig:Le}}let N={lowS:e.lowS,prehash:!1},$={lowS:e.lowS,prehash:!1};function D(B,U,X=N){let{seed:L,k2sig:k}=C(B,U,X),K=e;return Dd(K.hash.outputLen,K.nByteLength,K.hmac)(L,k)}u.BASE._setWindowSize(8);function ne(B,U,X,L=$){let k=B;if(U=Re("msgHash",U),X=Re("publicKey",X),"strict"in L)throw new Error("options.strict was renamed to lowS");let{lowS:K,prehash:W}=L,Z,re;try{if(typeof k=="string"||er(k))try{Z=g.fromDER(k)}catch(Oe){if(!(Oe instanceof bi.Err))throw Oe;Z=g.fromCompact(k)}else if(typeof k=="object"&&typeof k.r=="bigint"&&typeof k.s=="bigint"){let{r:Oe,s:Ze}=k;Z=new g(Oe,Ze)}else throw new Error("PARSE");re=u.fromHex(X)}catch(Oe){if(Oe.message==="PARSE")throw new Error("signature must be Signature instance, Uint8Array or hex string");return!1}if(K&&Z.hasHighS())return!1;W&&(U=e.hash(U));let{r:ie,s:me}=Z,ae=v(U),ue=c(me),Le=a(ae*ue),Ie=a(ie*ue),Ke=u.BASE.multiplyAndAddUnsafe(re,Le,Ie)?.toAffine();return Ke?a(Ke.x)===ie:!1}return{CURVE:e,getPublicKey:x,getSharedSecret:S,sign:D,verify:ne,ProjectivePoint:u,Signature:g,utils:E}}function pv(r){return{hash:r,hmac:(e,...t)=>us(r,e,Ka(...t)),randomBytes:ao}}function am(r,e){let t=n=>sm({...r,...pv(n)});return Object.freeze({...t(e),create:t})}var um=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),cm=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),mv=BigInt(1),of=BigInt(2),lm=(r,e)=>(r+e/of)/e;function yv(r){let e=um,t=BigInt(3),n=BigInt(6),i=BigInt(11),o=BigInt(22),s=BigInt(23),a=BigInt(44),c=BigInt(88),u=r*r*r%e,l=u*u*r%e,d=xe(l,t,e)*l%e,p=xe(d,t,e)*l%e,f=xe(p,of,e)*u%e,h=xe(f,i,e)*f%e,m=xe(h,o,e)*h%e,y=xe(m,a,e)*m%e,g=xe(y,c,e)*y%e,E=xe(g,a,e)*m%e,x=xe(E,t,e)*l%e,_=xe(x,s,e)*h%e,S=xe(_,n,e)*u%e,A=xe(S,of,e);if(!sf.eql(sf.sqr(A),r))throw new Error("Cannot find square root");return A}var sf=Xa(um,void 0,void 0,{sqrt:yv}),ir=am({a:BigInt(0),b:BigInt(7),Fp:sf,n:cm,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:r=>{let e=cm,t=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-mv*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),i=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),o=t,s=BigInt("0x100000000000000000000000000000000"),a=lm(o*r,e),c=lm(-n*r,e),u=ye(r-a*t-c*i,e),l=ye(-a*n-c*o,e),d=u>s,p=l>s;if(d&&(u=e-u),p&&(l=e-l),u>s||l>s)throw new Error("splitScalar: Endomorphism failed, k="+r);return{k1neg:d,k1:u,k2neg:p,k2:l}}}},im),GT=BigInt(0);var qT=ir.ProjectivePoint;function dm(){return ir.utils.randomPrivateKey()}function fm(r,e){let t=fe.digest(e instanceof Uint8Array?e:e.subarray());if(Kt(t))return t.then(({digest:n})=>ir.sign(n,r).toDERRawBytes()).catch(n=>{throw new O(String(n),"ERR_INVALID_INPUT")});try{return ir.sign(t.digest,r).toDERRawBytes()}catch(n){throw new O(String(n),"ERR_INVALID_INPUT")}}function hm(r,e,t){let n=fe.digest(t instanceof Uint8Array?t:t.subarray());if(Kt(n))return n.then(({digest:i})=>ir.verify(e,i,r)).catch(i=>{throw new O(String(i),"ERR_INVALID_INPUT")});try{return ir.verify(e,n.digest,r)}catch(i){throw new O(String(i),"ERR_INVALID_INPUT")}}function pm(r){return ir.ProjectivePoint.fromHex(r).toRawBytes(!0)}function mm(r){try{ir.getPublicKey(r,!0)}catch(e){throw new O(String(e),"ERR_INVALID_PRIVATE_KEY")}}function af(r){try{ir.ProjectivePoint.fromHex(r)}catch(e){throw new O(String(e),"ERR_INVALID_PUBLIC_KEY")}}function ym(r){try{return ir.getPublicKey(r,!0)}catch(e){throw new O(String(e),"ERR_INVALID_PRIVATE_KEY")}}var vs=class{_key;constructor(e){af(e),this._key=e}verify(e,t){return hm(this._key,t,e)}marshal(){return pm(this._key)}get bytes(){return Er.encode({Type:be.Secp256k1,Data:this.marshal()}).subarray()}equals(e){return he(this.bytes,e.bytes)}async hash(){let e=fe.digest(this.bytes),t;return Kt(e)?{bytes:t}=await e:t=e.bytes,t}},As=class{_key;_publicKey;constructor(e,t){this._key=e,this._publicKey=t??ym(e),mm(this._key),af(this._publicKey)}sign(e){return fm(this._key,e)}get public(){return new vs(this._publicKey)}marshal(){return this._key}get bytes(){return xr.encode({Type:be.Secp256k1,Data:this.marshal()}).subarray()}equals(e){return he(this.bytes,e.bytes)}hash(){let e=fe.digest(this.bytes);return Kt(e)?e.then(({bytes:t})=>t):e.bytes}async id(){let e=await this.public.hash();return J(e,"base58btc")}async export(e,t="libp2p-key"){if(t==="libp2p-key")return ho(this.bytes,e);throw new O(`export format '${t}' is not supported`,"ERR_INVALID_EXPORT_FORMAT")}};function wv(r){return new As(r)}function Ev(r){return new vs(r)}async function xv(){let r=dm();return new As(r)}var vi={rsa:rf,ed25519:qd,secp256k1:cf};function gm(r){let e=Object.keys(vi).join(" / ");return new O(`invalid or unsupported key type ${r}. Must be ${e}`,"ERR_UNSUPPORTED_KEY_TYPE")}function lf(r){let e=Er.decode(r),t=e.Data??new Uint8Array;switch(e.Type){case be.RSA:return vi.rsa.unmarshalRsaPublicKey(t);case be.Ed25519:return vi.ed25519.unmarshalEd25519PublicKey(t);case be.Secp256k1:return vi.secp256k1.unmarshalSecp256k1PublicKey(t);default:throw gm(e.Type??"unknown")}}async function wm(r){let e=xr.decode(r),t=e.Data??new Uint8Array;switch(e.Type){case be.RSA:return vi.rsa.unmarshalRsaPrivateKey(t);case be.Ed25519:return vi.ed25519.unmarshalEd25519PrivateKey(t);case be.Secp256k1:return vi.secp256k1.unmarshalSecp256k1PrivateKey(t);default:throw gm(e.Type??"RSA")}}var Sf=Q(Ce(),1);var tn="/",Em=new TextEncoder().encode(tn),qc=Em[0],Fe=class r{_buf;constructor(e,t){if(typeof e=="string")this._buf=H(e);else if(e instanceof Uint8Array)this._buf=e;else throw new Error("Invalid key, should be String of Uint8Array");if(t==null&&(t=!0),t&&this.clean(),this._buf.byteLength===0||this._buf[0]!==qc)throw new Error("Invalid key")}toString(e="utf8"){return J(this._buf,e)}uint8Array(){return this._buf}get[Symbol.toStringTag](){return`Key(${this.toString()})`}static withNamespaces(e){return new r(e.join(tn))}static random(){return new r(Math.random().toString().substring(2))}static asKey(e){return e instanceof Uint8Array||typeof e=="string"?new r(e):typeof e.uint8Array=="function"?new r(e.uint8Array()):null}clean(){if((this._buf==null||this._buf.byteLength===0)&&(this._buf=Em),this._buf[0]!==qc){let e=new Uint8Array(this._buf.byteLength+1);e.fill(qc,0,1),e.set(this._buf,1),this._buf=e}for(;this._buf.byteLength>1&&this._buf[this._buf.byteLength-1]===qc;)this._buf=this._buf.subarray(0,-1)}less(e){let t=this.list(),n=e.list();for(let i=0;i<t.length;i++){if(n.length<i+1)return!1;let o=t[i],s=n[i];if(o<s)return!0;if(o>s)return!1}return t.length<n.length}reverse(){return r.withNamespaces(this.list().slice().reverse())}namespaces(){return this.list()}baseNamespace(){let e=this.namespaces();return e[e.length-1]}list(){return this.toString().split(tn).slice(1)}type(){return bv(this.baseNamespace())}name(){return vv(this.baseNamespace())}instance(e){return new r(this.toString()+":"+e)}path(){let e=this.parent().toString();return e.endsWith(tn)||(e+=tn),e+=this.type(),new r(e)}parent(){let e=this.list();return e.length===1?new r(tn):new r(e.slice(0,-1).join(tn))}child(e){return this.toString()===tn?e:e.toString()===tn?this:new r(this.toString()+e.toString(),!1)}isAncestorOf(e){return e.toString()===this.toString()?!1:e.toString().startsWith(this.toString())}isDecendantOf(e){return e.toString()===this.toString()?!1:this.toString().startsWith(e.toString())}isTopLevel(){return this.list().length===1}concat(...e){return r.withNamespaces([...this.namespaces(),...Av(e.map(t=>t.namespaces()))])}};function bv(r){let e=r.split(":");return e.length<2?"":e.slice(0,-1).join(":")}function vv(r){let e=r.split(":");return e[e.length-1]}function Av(r){return[].concat(...r)}var Dy=Q(Yc(),1);var xm="ERR_IPNS_EXPIRED_RECORD",_s="ERR_UNRECOGNIZED_VALIDITY",bm="ERR_SIGNATURE_CREATION",rn="ERR_SIGNATURE_VERIFICATION";var df="ERR_UNDEFINED_PARAMETER",vm="ERR_INVALID_RECORD_DATA",Am="ERR_INVALID_VALUE",_m="ERR_INVALID_EMBEDDED_KEY",Sm="ERR_MISSING_PRIVATE_KEY",Im="ERR_RECORD_TOO_LARGE";var We;(function(r){let e;(function(i){i.EOL="EOL"})(e=r.ValidityType||(r.ValidityType={}));let t;(function(i){i[i.EOL=0]="EOL"})(t||(t={})),function(i){i.codec=()=>pi(t)}(e=r.ValidityType||(r.ValidityType={}));let n;r.codec=()=>(n==null&&(n=Ht((i,o,s={})=>{s.lengthDelimited!==!1&&o.fork(),i.value!=null&&(o.uint32(10),o.bytes(i.value)),i.signatureV1!=null&&(o.uint32(18),o.bytes(i.signatureV1)),i.validityType!=null&&(o.uint32(24),r.ValidityType.codec().encode(i.validityType,o)),i.validity!=null&&(o.uint32(34),o.bytes(i.validity)),i.sequence!=null&&(o.uint32(40),o.uint64(i.sequence)),i.ttl!=null&&(o.uint32(48),o.uint64(i.ttl)),i.pubKey!=null&&(o.uint32(58),o.bytes(i.pubKey)),i.signatureV2!=null&&(o.uint32(66),o.bytes(i.signatureV2)),i.data!=null&&(o.uint32(74),o.bytes(i.data)),s.lengthDelimited!==!1&&o.ldelim()},(i,o)=>{let s={},a=o==null?i.len:i.pos+o;for(;i.pos<a;){let c=i.uint32();switch(c>>>3){case 1:s.value=i.bytes();break;case 2:s.signatureV1=i.bytes();break;case 3:s.validityType=r.ValidityType.codec().decode(i);break;case 4:s.validity=i.bytes();break;case 5:s.sequence=i.uint64();break;case 6:s.ttl=i.uint64();break;case 7:s.pubKey=i.bytes();break;case 8:s.signatureV2=i.bytes();break;case 9:s.data=i.bytes();break;default:i.skipType(c&7);break}}return s})),n),r.encode=i=>Mt(i,r.codec()),r.decode=i=>Ft(i,r.codec())})(We||(We={}));var _v=["string","number","bigint","symbol"],Sv=["Function","Generator","AsyncGenerator","GeneratorFunction","AsyncGeneratorFunction","AsyncFunction","Observable","Array","Buffer","Object","RegExp","Date","Error","Map","Set","WeakMap","WeakSet","ArrayBuffer","SharedArrayBuffer","DataView","Promise","URL","HTMLElement","Int8Array","Uint8Array","Uint8ClampedArray","Int16Array","Uint16Array","Int32Array","Uint32Array","Float32Array","Float64Array","BigInt64Array","BigUint64Array"];function Bm(r){if(r===null)return"null";if(r===void 0)return"undefined";if(r===!0||r===!1)return"boolean";let e=typeof r;if(_v.includes(e))return e;if(e==="function")return"Function";if(Array.isArray(r))return"Array";if(Iv(r))return"Buffer";let t=Bv(r);return t||"Object"}function Iv(r){return r&&r.constructor&&r.constructor.isBuffer&&r.constructor.isBuffer.call(null,r)}function Bv(r){let e=Object.prototype.toString.call(r).slice(8,-1);if(Sv.includes(e))return e}var w=class{constructor(e,t,n){this.major=e,this.majorEncoded=e<<5,this.name=t,this.terminal=n}toString(){return`Type[${this.major}].${this.name}`}compare(e){return this.major<e.major?-1:this.major>e.major?1:0}};w.uint=new w(0,"uint",!0);w.negint=new w(1,"negint",!0);w.bytes=new w(2,"bytes",!0);w.string=new w(3,"string",!0);w.array=new w(4,"array",!1);w.map=new w(5,"map",!1);w.tag=new w(6,"tag",!1);w.float=new w(7,"float",!0);w.false=new w(7,"false",!0);w.true=new w(7,"true",!0);w.null=new w(7,"null",!0);w.undefined=new w(7,"undefined",!0);w.break=new w(7,"break",!0);var R=class{constructor(e,t,n){this.type=e,this.value=t,this.encodedLength=n,this.encodedBytes=void 0,this.byteValue=void 0}toString(){return`Token[${this.type}].${this.value}`}};var xo=globalThis.process&&!globalThis.process.browser&&globalThis.Buffer&&typeof globalThis.Buffer.isBuffer=="function",kv=new TextDecoder,Rv=new TextEncoder;function Wc(r){return xo&&globalThis.Buffer.isBuffer(r)}function Ss(r){return r instanceof Uint8Array?Wc(r)?new Uint8Array(r.buffer,r.byteOffset,r.byteLength):r:Uint8Array.from(r)}var Nm=xo?(r,e,t)=>t-e>64?globalThis.Buffer.from(r.subarray(e,t)).toString("utf8"):Rm(r,e,t):(r,e,t)=>t-e>64?kv.decode(r.subarray(e,t)):Rm(r,e,t),jc=xo?r=>r.length>64?globalThis.Buffer.from(r):km(r):r=>r.length>64?Rv.encode(r):km(r),_r=r=>Uint8Array.from(r),bo=xo?(r,e,t)=>Wc(r)?new Uint8Array(r.subarray(e,t)):r.slice(e,t):(r,e,t)=>r.slice(e,t),Cm=xo?(r,e)=>(r=r.map(t=>t instanceof Uint8Array?t:globalThis.Buffer.from(t)),Ss(globalThis.Buffer.concat(r,e))):(r,e)=>{let t=new Uint8Array(e),n=0;for(let i of r)n+i.length>t.length&&(i=i.subarray(0,t.length-n)),t.set(i,n),n+=i.length;return t},Lm=xo?r=>globalThis.Buffer.allocUnsafe(r):r=>new Uint8Array(r);function Um(r,e){if(Wc(r)&&Wc(e))return r.compare(e);for(let t=0;t<r.length;t++)if(r[t]!==e[t])return r[t]<e[t]?-1:1;return 0}function km(r){let e=[],t=0;for(let n=0;n<r.length;n++){let i=r.charCodeAt(n);i<128?e[t++]=i:i<2048?(e[t++]=i>>6|192,e[t++]=i&63|128):(i&64512)===55296&&n+1<r.length&&(r.charCodeAt(n+1)&64512)===56320?(i=65536+((i&1023)<<10)+(r.charCodeAt(++n)&1023),e[t++]=i>>18|240,e[t++]=i>>12&63|128,e[t++]=i>>6&63|128,e[t++]=i&63|128):(e[t++]=i>>12|224,e[t++]=i>>6&63|128,e[t++]=i&63|128)}return e}function Rm(r,e,t){let n=[];for(;e<t;){let i=r[e],o=null,s=i>239?4:i>223?3:i>191?2:1;if(e+s<=t){let a,c,u,l;switch(s){case 1:i<128&&(o=i);break;case 2:a=r[e+1],(a&192)===128&&(l=(i&31)<<6|a&63,l>127&&(o=l));break;case 3:a=r[e+1],c=r[e+2],(a&192)===128&&(c&192)===128&&(l=(i&15)<<12|(a&63)<<6|c&63,l>2047&&(l<55296||l>57343)&&(o=l));break;case 4:a=r[e+1],c=r[e+2],u=r[e+3],(a&192)===128&&(c&192)===128&&(u&192)===128&&(l=(i&15)<<18|(a&63)<<12|(c&63)<<6|u&63,l>65535&&l<1114112&&(o=l))}}o===null?(o=65533,s=1):o>65535&&(o-=65536,n.push(o>>>10&1023|55296),o=56320|o&1023),n.push(o),e+=s}return hf(n)}var Tm=4096;function hf(r){let e=r.length;if(e<=Tm)return String.fromCharCode.apply(String,r);let t="",n=0;for(;n<e;)t+=String.fromCharCode.apply(String,r.slice(n,n+=Tm));return t}var Tv=256,Is=class{constructor(e=Tv){this.chunkSize=e,this.cursor=0,this.maxCursor=-1,this.chunks=[],this._initReuseChunk=null}reset(){this.cursor=0,this.maxCursor=-1,this.chunks.length&&(this.chunks=[]),this._initReuseChunk!==null&&(this.chunks.push(this._initReuseChunk),this.maxCursor=this._initReuseChunk.length-1)}push(e){let t=this.chunks[this.chunks.length-1];if(this.cursor+e.length<=this.maxCursor+1){let i=t.length-(this.maxCursor-this.cursor)-1;t.set(e,i)}else{if(t){let i=t.length-(this.maxCursor-this.cursor)-1;i<t.length&&(this.chunks[this.chunks.length-1]=t.subarray(0,i),this.maxCursor=this.cursor-1)}e.length<64&&e.length<this.chunkSize?(t=Lm(this.chunkSize),this.chunks.push(t),this.maxCursor+=t.length,this._initReuseChunk===null&&(this._initReuseChunk=t),t.set(e,0)):(this.chunks.push(e),this.maxCursor+=e.length)}this.cursor+=e.length}toBytes(e=!1){let t;if(this.chunks.length===1){let n=this.chunks[0];e&&this.cursor>n.length/2?(t=this.cursor===n.length?n:n.subarray(0,this.cursor),this._initReuseChunk=null,this.chunks=[]):t=bo(n,0,this.cursor)}else t=Cm(this.chunks,this.cursor);return e&&this.reset(),t}};var G="CBOR decode error:",nn="CBOR encode error:",Bs=[];Bs[23]=1;Bs[24]=2;Bs[25]=3;Bs[26]=5;Bs[27]=9;function on(r,e,t){if(r.length-e<t)throw new Error(`${G} not enough data for type`)}var He=[24,256,65536,4294967296,BigInt("18446744073709551616")];function kt(r,e,t){on(r,e,1);let n=r[e];if(t.strict===!0&&n<He[0])throw new Error(`${G} integer encoded in more bytes than necessary (strict decode)`);return n}function Rt(r,e,t){on(r,e,2);let n=r[e]<<8|r[e+1];if(t.strict===!0&&n<He[1])throw new Error(`${G} integer encoded in more bytes than necessary (strict decode)`);return n}function Tt(r,e,t){on(r,e,4);let n=r[e]*16777216+(r[e+1]<<16)+(r[e+2]<<8)+r[e+3];if(t.strict===!0&&n<He[2])throw new Error(`${G} integer encoded in more bytes than necessary (strict decode)`);return n}function Nt(r,e,t){on(r,e,8);let n=r[e]*16777216+(r[e+1]<<16)+(r[e+2]<<8)+r[e+3],i=r[e+4]*16777216+(r[e+5]<<16)+(r[e+6]<<8)+r[e+7],o=(BigInt(n)<<BigInt(32))+BigInt(i);if(t.strict===!0&&o<He[3])throw new Error(`${G} integer encoded in more bytes than necessary (strict decode)`);if(o<=Number.MAX_SAFE_INTEGER)return Number(o);if(t.allowBigInt===!0)return o;throw new Error(`${G} integers outside of the safe integer range are not supported`)}function Dm(r,e,t,n){return new R(w.uint,kt(r,e+1,n),2)}function Om(r,e,t,n){return new R(w.uint,Rt(r,e+1,n),3)}function Pm(r,e,t,n){return new R(w.uint,Tt(r,e+1,n),5)}function Fm(r,e,t,n){return new R(w.uint,Nt(r,e+1,n),9)}function Yt(r,e){return je(r,0,e.value)}function je(r,e,t){if(t<He[0]){let n=Number(t);r.push([e|n])}else if(t<He[1]){let n=Number(t);r.push([e|24,n])}else if(t<He[2]){let n=Number(t);r.push([e|25,n>>>8,n&255])}else if(t<He[3]){let n=Number(t);r.push([e|26,n>>>24&255,n>>>16&255,n>>>8&255,n&255])}else{let n=BigInt(t);if(n<He[4]){let i=[e|27,0,0,0,0,0,0,0],o=Number(n&BigInt(4294967295)),s=Number(n>>BigInt(32)&BigInt(4294967295));i[8]=o&255,o=o>>8,i[7]=o&255,o=o>>8,i[6]=o&255,o=o>>8,i[5]=o&255,i[4]=s&255,s=s>>8,i[3]=s&255,s=s>>8,i[2]=s&255,s=s>>8,i[1]=s&255,r.push(i)}else throw new Error(`${G} encountered BigInt larger than allowable range`)}}Yt.encodedSize=function(e){return je.encodedSize(e.value)};je.encodedSize=function(e){return e<He[0]?1:e<He[1]?2:e<He[2]?3:e<He[3]?5:9};Yt.compareTokens=function(e,t){return e.value<t.value?-1:e.value>t.value?1:0};function Vm(r,e,t,n){return new R(w.negint,-1-kt(r,e+1,n),2)}function Mm(r,e,t,n){return new R(w.negint,-1-Rt(r,e+1,n),3)}function Hm(r,e,t,n){return new R(w.negint,-1-Tt(r,e+1,n),5)}var pf=BigInt(-1),$m=BigInt(1);function zm(r,e,t,n){let i=Nt(r,e+1,n);if(typeof i!="bigint"){let o=-1-i;if(o>=Number.MIN_SAFE_INTEGER)return new R(w.negint,o,9)}if(n.allowBigInt!==!0)throw new Error(`${G} integers outside of the safe integer range are not supported`);return new R(w.negint,pf-BigInt(i),9)}function Xc(r,e){let t=e.value,n=typeof t=="bigint"?t*pf-$m:t*-1-1;je(r,e.type.majorEncoded,n)}Xc.encodedSize=function(e){let t=e.value,n=typeof t=="bigint"?t*pf-$m:t*-1-1;return n<He[0]?1:n<He[1]?2:n<He[2]?3:n<He[3]?5:9};Xc.compareTokens=function(e,t){return e.value<t.value?1:e.value>t.value?-1:0};function ks(r,e,t,n){on(r,e,t+n);let i=bo(r,e+t,e+t+n);return new R(w.bytes,i,t+n)}function Km(r,e,t,n){return ks(r,e,1,t)}function Gm(r,e,t,n){return ks(r,e,2,kt(r,e+1,n))}function qm(r,e,t,n){return ks(r,e,3,Rt(r,e+1,n))}function Ym(r,e,t,n){return ks(r,e,5,Tt(r,e+1,n))}function Wm(r,e,t,n){let i=Nt(r,e+1,n);if(typeof i=="bigint")throw new Error(`${G} 64-bit integer bytes lengths not supported`);return ks(r,e,9,i)}function Zc(r){return r.encodedBytes===void 0&&(r.encodedBytes=r.type===w.string?jc(r.value):r.value),r.encodedBytes}function vo(r,e){let t=Zc(e);je(r,e.type.majorEncoded,t.length),r.push(t)}vo.encodedSize=function(e){let t=Zc(e);return je.encodedSize(t.length)+t.length};vo.compareTokens=function(e,t){return Cv(Zc(e),Zc(t))};function Cv(r,e){return r.length<e.length?-1:r.length>e.length?1:Um(r,e)}function Rs(r,e,t,n,i){let o=t+n;on(r,e,o);let s=new R(w.string,Nm(r,e+t,e+o),o);return i.retainStringBytes===!0&&(s.byteValue=bo(r,e+t,e+o)),s}function jm(r,e,t,n){return Rs(r,e,1,t,n)}function Xm(r,e,t,n){return Rs(r,e,2,kt(r,e+1,n),n)}function Zm(r,e,t,n){return Rs(r,e,3,Rt(r,e+1,n),n)}function Jm(r,e,t,n){return Rs(r,e,5,Tt(r,e+1,n),n)}function Qm(r,e,t,n){let i=Nt(r,e+1,n);if(typeof i=="bigint")throw new Error(`${G} 64-bit integer string lengths not supported`);return Rs(r,e,9,i,n)}var ey=vo;function Ao(r,e,t,n){return new R(w.array,n,t)}function ty(r,e,t,n){return Ao(r,e,1,t)}function ry(r,e,t,n){return Ao(r,e,2,kt(r,e+1,n))}function ny(r,e,t,n){return Ao(r,e,3,Rt(r,e+1,n))}function iy(r,e,t,n){return Ao(r,e,5,Tt(r,e+1,n))}function oy(r,e,t,n){let i=Nt(r,e+1,n);if(typeof i=="bigint")throw new Error(`${G} 64-bit integer array lengths not supported`);return Ao(r,e,9,i)}function sy(r,e,t,n){if(n.allowIndefinite===!1)throw new Error(`${G} indefinite length items not allowed`);return Ao(r,e,1,1/0)}function Jc(r,e){je(r,w.array.majorEncoded,e.value)}Jc.compareTokens=Yt.compareTokens;Jc.encodedSize=function(e){return je.encodedSize(e.value)};function _o(r,e,t,n){return new R(w.map,n,t)}function ay(r,e,t,n){return _o(r,e,1,t)}function cy(r,e,t,n){return _o(r,e,2,kt(r,e+1,n))}function ly(r,e,t,n){return _o(r,e,3,Rt(r,e+1,n))}function uy(r,e,t,n){return _o(r,e,5,Tt(r,e+1,n))}function dy(r,e,t,n){let i=Nt(r,e+1,n);if(typeof i=="bigint")throw new Error(`${G} 64-bit integer map lengths not supported`);return _o(r,e,9,i)}function fy(r,e,t,n){if(n.allowIndefinite===!1)throw new Error(`${G} indefinite length items not allowed`);return _o(r,e,1,1/0)}function Qc(r,e){je(r,w.map.majorEncoded,e.value)}Qc.compareTokens=Yt.compareTokens;Qc.encodedSize=function(e){return je.encodedSize(e.value)};function hy(r,e,t,n){return new R(w.tag,t,1)}function py(r,e,t,n){return new R(w.tag,kt(r,e+1,n),2)}function my(r,e,t,n){return new R(w.tag,Rt(r,e+1,n),3)}function yy(r,e,t,n){return new R(w.tag,Tt(r,e+1,n),5)}function gy(r,e,t,n){return new R(w.tag,Nt(r,e+1,n),9)}function el(r,e){je(r,w.tag.majorEncoded,e.value)}el.compareTokens=Yt.compareTokens;el.encodedSize=function(e){return je.encodedSize(e.value)};var Fv=20,Vv=21,Mv=22,Hv=23;function wy(r,e,t,n){if(n.allowUndefined===!1)throw new Error(`${G} undefined values are not supported`);return n.coerceUndefinedToNull===!0?new R(w.null,null,1):new R(w.undefined,void 0,1)}function Ey(r,e,t,n){if(n.allowIndefinite===!1)throw new Error(`${G} indefinite length items not allowed`);return new R(w.break,void 0,1)}function mf(r,e,t){if(t){if(t.allowNaN===!1&&Number.isNaN(r))throw new Error(`${G} NaN values are not supported`);if(t.allowInfinity===!1&&(r===1/0||r===-1/0))throw new Error(`${G} Infinity values are not supported`)}return new R(w.float,r,e)}function xy(r,e,t,n){return mf(yf(r,e+1),3,n)}function by(r,e,t,n){return mf(gf(r,e+1),5,n)}function vy(r,e,t,n){return mf(Iy(r,e+1),9,n)}function tl(r,e,t){let n=e.value;if(n===!1)r.push([w.float.majorEncoded|Fv]);else if(n===!0)r.push([w.float.majorEncoded|Vv]);else if(n===null)r.push([w.float.majorEncoded|Mv]);else if(n===void 0)r.push([w.float.majorEncoded|Hv]);else{let i,o=!1;(!t||t.float64!==!0)&&(_y(n),i=yf(or,1),n===i||Number.isNaN(n)?(or[0]=249,r.push(or.slice(0,3)),o=!0):(Sy(n),i=gf(or,1),n===i&&(or[0]=250,r.push(or.slice(0,5)),o=!0))),o||($v(n),i=Iy(or,1),or[0]=251,r.push(or.slice(0,9)))}}tl.encodedSize=function(e,t){let n=e.value;if(n===!1||n===!0||n===null||n===void 0)return 1;if(!t||t.float64!==!0){_y(n);let i=yf(or,1);if(n===i||Number.isNaN(n))return 3;if(Sy(n),i=gf(or,1),n===i)return 5}return 9};var Ay=new ArrayBuffer(9),Wt=new DataView(Ay,1),or=new Uint8Array(Ay,0);function _y(r){if(r===1/0)Wt.setUint16(0,31744,!1);else if(r===-1/0)Wt.setUint16(0,64512,!1);else if(Number.isNaN(r))Wt.setUint16(0,32256,!1);else{Wt.setFloat32(0,r);let e=Wt.getUint32(0),t=(e&2139095040)>>23,n=e&8388607;if(t===255)Wt.setUint16(0,31744,!1);else if(t===0)Wt.setUint16(0,(r&2147483648)>>16|n>>13,!1);else{let i=t-127;i<-24?Wt.setUint16(0,0):i<-14?Wt.setUint16(0,(e&2147483648)>>16|1<<24+i,!1):Wt.setUint16(0,(e&2147483648)>>16|i+15<<10|n>>13,!1)}}}function yf(r,e){if(r.length-e<2)throw new Error(`${G} not enough data for float16`);let t=(r[e]<<8)+r[e+1];if(t===31744)return 1/0;if(t===64512)return-1/0;if(t===32256)return NaN;let n=t>>10&31,i=t&1023,o;return n===0?o=i*2**-24:n!==31?o=(i+1024)*2**(n-25):o=i===0?1/0:NaN,t&32768?-o:o}function Sy(r){Wt.setFloat32(0,r,!1)}function gf(r,e){if(r.length-e<4)throw new Error(`${G} not enough data for float32`);let t=(r.byteOffset||0)+e;return new DataView(r.buffer,t,4).getFloat32(0,!1)}function $v(r){Wt.setFloat64(0,r,!1)}function Iy(r,e){if(r.length-e<8)throw new Error(`${G} not enough data for float64`);let t=(r.byteOffset||0)+e;return new DataView(r.buffer,t,8).getFloat64(0,!1)}tl.compareTokens=Yt.compareTokens;function de(r,e,t){throw new Error(`${G} encountered invalid minor (${t}) for major ${r[e]>>>5}`)}function rl(r){return()=>{throw new Error(`${G} ${r}`)}}var P=[];for(let r=0;r<=23;r++)P[r]=de;P[24]=Dm;P[25]=Om;P[26]=Pm;P[27]=Fm;P[28]=de;P[29]=de;P[30]=de;P[31]=de;for(let r=32;r<=55;r++)P[r]=de;P[56]=Vm;P[57]=Mm;P[58]=Hm;P[59]=zm;P[60]=de;P[61]=de;P[62]=de;P[63]=de;for(let r=64;r<=87;r++)P[r]=Km;P[88]=Gm;P[89]=qm;P[90]=Ym;P[91]=Wm;P[92]=de;P[93]=de;P[94]=de;P[95]=rl("indefinite length bytes/strings are not supported");for(let r=96;r<=119;r++)P[r]=jm;P[120]=Xm;P[121]=Zm;P[122]=Jm;P[123]=Qm;P[124]=de;P[125]=de;P[126]=de;P[127]=rl("indefinite length bytes/strings are not supported");for(let r=128;r<=151;r++)P[r]=ty;P[152]=ry;P[153]=ny;P[154]=iy;P[155]=oy;P[156]=de;P[157]=de;P[158]=de;P[159]=sy;for(let r=160;r<=183;r++)P[r]=ay;P[184]=cy;P[185]=ly;P[186]=uy;P[187]=dy;P[188]=de;P[189]=de;P[190]=de;P[191]=fy;for(let r=192;r<=215;r++)P[r]=hy;P[216]=py;P[217]=my;P[218]=yy;P[219]=gy;P[220]=de;P[221]=de;P[222]=de;P[223]=de;for(let r=224;r<=243;r++)P[r]=rl("simple values are not supported");P[244]=de;P[245]=de;P[246]=de;P[247]=wy;P[248]=rl("simple values are not supported");P[249]=xy;P[250]=by;P[251]=vy;P[252]=de;P[253]=de;P[254]=de;P[255]=Ey;var sr=[];for(let r=0;r<24;r++)sr[r]=new R(w.uint,r,1);for(let r=-1;r>=-24;r--)sr[31-r]=new R(w.negint,r,1);sr[64]=new R(w.bytes,new Uint8Array(0),1);sr[96]=new R(w.string,"",1);sr[128]=new R(w.array,0,1);sr[160]=new R(w.map,0,1);sr[244]=new R(w.false,!1,1);sr[245]=new R(w.true,!0,1);sr[246]=new R(w.null,null,1);function wf(r){switch(r.type){case w.false:return _r([244]);case w.true:return _r([245]);case w.null:return _r([246]);case w.bytes:return r.value.length?void 0:_r([64]);case w.string:return r.value===""?_r([96]):void 0;case w.array:return r.value===0?_r([128]):void 0;case w.map:return r.value===0?_r([160]):void 0;case w.uint:return r.value<24?_r([Number(r.value)]):void 0;case w.negint:if(r.value>=-24)return _r([31-Number(r.value)])}}var Kv={float64:!1,mapSorter:qv,quickEncodeToken:wf};function xf(){let r=[];return r[w.uint.major]=Yt,r[w.negint.major]=Xc,r[w.bytes.major]=vo,r[w.string.major]=ey,r[w.array.major]=Jc,r[w.map.major]=Qc,r[w.tag.major]=el,r[w.float.major]=tl,r}var By=xf(),Ef=new Is,nl=class r{constructor(e,t){this.obj=e,this.parent=t}includes(e){let t=this;do if(t.obj===e)return!0;while(t=t.parent);return!1}static createCheck(e,t){if(e&&e.includes(t))throw new Error(`${nn} object contains circular references`);return new r(t,e)}},$n={null:new R(w.null,null),undefined:new R(w.undefined,void 0),true:new R(w.true,!0),false:new R(w.false,!1),emptyArray:new R(w.array,0),emptyMap:new R(w.map,0)},zn={number(r,e,t,n){return!Number.isInteger(r)||!Number.isSafeInteger(r)?new R(w.float,r):r>=0?new R(w.uint,r):new R(w.negint,r)},bigint(r,e,t,n){return r>=BigInt(0)?new R(w.uint,r):new R(w.negint,r)},Uint8Array(r,e,t,n){return new R(w.bytes,r)},string(r,e,t,n){return new R(w.string,r)},boolean(r,e,t,n){return r?$n.true:$n.false},null(r,e,t,n){return $n.null},undefined(r,e,t,n){return $n.undefined},ArrayBuffer(r,e,t,n){return new R(w.bytes,new Uint8Array(r))},DataView(r,e,t,n){return new R(w.bytes,new Uint8Array(r.buffer,r.byteOffset,r.byteLength))},Array(r,e,t,n){if(!r.length)return t.addBreakTokens===!0?[$n.emptyArray,new R(w.break)]:$n.emptyArray;n=nl.createCheck(n,r);let i=[],o=0;for(let s of r)i[o++]=Ts(s,t,n);return t.addBreakTokens?[new R(w.array,r.length),i,new R(w.break)]:[new R(w.array,r.length),i]},Object(r,e,t,n){let i=e!=="Object",o=i?r.keys():Object.keys(r),s=i?r.size:o.length;if(!s)return t.addBreakTokens===!0?[$n.emptyMap,new R(w.break)]:$n.emptyMap;n=nl.createCheck(n,r);let a=[],c=0;for(let u of o)a[c++]=[Ts(u,t,n),Ts(i?r.get(u):r[u],t,n)];return Gv(a,t),t.addBreakTokens?[new R(w.map,s),a,new R(w.break)]:[new R(w.map,s),a]}};zn.Map=zn.Object;zn.Buffer=zn.Uint8Array;for(let r of"Uint8Clamped Uint16 Uint32 Int8 Int16 Int32 BigUint64 BigInt64 Float32 Float64".split(" "))zn[`${r}Array`]=zn.DataView;function Ts(r,e={},t){let n=Bm(r),i=e&&e.typeEncoders&&e.typeEncoders[n]||zn[n];if(typeof i=="function"){let s=i(r,n,e,t);if(s!=null)return s}let o=zn[n];if(!o)throw new Error(`${nn} unsupported type: ${n}`);return o(r,n,e,t)}function Gv(r,e){e.mapSorter&&r.sort(e.mapSorter)}function qv(r,e){let t=Array.isArray(r[0])?r[0][0]:r[0],n=Array.isArray(e[0])?e[0][0]:e[0];if(t.type!==n.type)return t.type.compare(n.type);let i=t.type.major,o=By[i].compareTokens(t,n);return o===0&&console.warn("WARNING: complex key types used, CBOR key sorting guarantees are gone"),o}function ky(r,e,t,n){if(Array.isArray(e))for(let i of e)ky(r,i,t,n);else t[e.type.major](r,e,n)}function bf(r,e,t){let n=Ts(r,t);if(!Array.isArray(n)&&t.quickEncodeToken){let i=t.quickEncodeToken(n);if(i)return i;let o=e[n.type.major];if(o.encodedSize){let s=o.encodedSize(n,t),a=new Is(s);if(o(a,n,t),a.chunks.length!==1)throw new Error(`Unexpected error: pre-calculated length for ${n} was wrong`);return Ss(a.chunks[0])}}return Ef.reset(),ky(Ef,n,e,t),Ef.toBytes(!0)}function Kn(r,e){return e=Object.assign({},Kv,e),bf(r,By,e)}var Yv={strict:!1,allowIndefinite:!0,allowUndefined:!0,allowBigInt:!0},vf=class{constructor(e,t={}){this._pos=0,this.data=e,this.options=t}pos(){return this._pos}done(){return this._pos>=this.data.length}next(){let e=this.data[this._pos],t=sr[e];if(t===void 0){let n=P[e];if(!n)throw new Error(`${G} no decoder for major type ${e>>>5} (byte 0x${e.toString(16).padStart(2,"0")})`);let i=e&31;t=n(this.data,this._pos,i,this.options)}return this._pos+=t.encodedLength,t}},Ns=Symbol.for("DONE"),il=Symbol.for("BREAK");function Wv(r,e,t){let n=[];for(let i=0;i<r.value;i++){let o=Cs(e,t);if(o===il){if(r.value===1/0)break;throw new Error(`${G} got unexpected break to lengthed array`)}if(o===Ns)throw new Error(`${G} found array but not enough entries (got ${i}, expected ${r.value})`);n[i]=o}return n}function jv(r,e,t){let n=t.useMaps===!0,i=n?void 0:{},o=n?new Map:void 0;for(let s=0;s<r.value;s++){let a=Cs(e,t);if(a===il){if(r.value===1/0)break;throw new Error(`${G} got unexpected break to lengthed map`)}if(a===Ns)throw new Error(`${G} found map but not enough entries (got ${s} [no key], expected ${r.value})`);if(n!==!0&&typeof a!="string")throw new Error(`${G} non-string keys not supported (got ${typeof a})`);if(t.rejectDuplicateMapKeys===!0&&(n&&o.has(a)||!n&&a in i))throw new Error(`${G} found repeat map key "${a}"`);let c=Cs(e,t);if(c===Ns)throw new Error(`${G} found map but not enough entries (got ${s} [no value], expected ${r.value})`);n?o.set(a,c):i[a]=c}return n?o:i}function Cs(r,e){if(r.done())return Ns;let t=r.next();if(t.type===w.break)return il;if(t.type.terminal)return t.value;if(t.type===w.array)return Wv(t,r,e);if(t.type===w.map)return jv(t,r,e);if(t.type===w.tag){if(e.tags&&typeof e.tags[t.value]=="function"){let n=Cs(r,e);return e.tags[t.value](n)}throw new Error(`${G} tag not supported (${t.value})`)}throw new Error("unsupported")}function Af(r,e){if(!(r instanceof Uint8Array))throw new Error(`${G} data to decode must be a Uint8Array`);e=Object.assign({},Yv,e);let t=e.tokenizer||new vf(r,e),n=Cs(t,e);if(n===Ns)throw new Error(`${G} did not find any content to decode`);if(n===il)throw new Error(`${G} got unexpected break`);return[n,r.subarray(t.pos())]}function ut(r,e){let[t,n]=Af(r,e);if(n.length>0)throw new Error(`${G} too many terminals, data makes no sense`);return t}var Et=Q(Ce(),1);var Ry=oe("ipns:utils"),Ty=H("/ipns/"),Xv=114,Ny=async(r,e)=>{if(e==null||r==null){let n=new Error("one or more of the provided parameters are not defined");throw Ry.error(n),(0,Et.default)(n,df)}let t;if(e.pubKey!=null){try{t=lf(e.pubKey)}catch(i){throw Ry.error(i),i}if(!(await vp(e.pubKey)).equals(r))throw(0,Et.default)(new Error("Embedded public key did not match PeerID"),_m)}else r.publicKey!=null&&(t=lf(r.publicKey));if(t!=null)return t;throw(0,Et.default)(new Error("no public key is available"),df)},Cy=(r,e,t)=>{let n=H(e);return we([r,t,n])},sl=r=>{let e=H("ipns-signature:");return we([e,r])},sn=r=>"signatureV1"in r?We.encode({value:H(r.value),signatureV1:r.signatureV1,validityType:r.validityType,validity:H(r.validity),sequence:r.sequence,ttl:r.ttl,pubKey:r.pubKey,signatureV2:r.signatureV2,data:r.data}):We.encode({pubKey:r.pubKey,signatureV2:r.signatureV2,data:r.data});function dt(r){let e=We.decode(r);if(e.sequence!=null&&(e.sequence=BigInt(e.sequence)),e.ttl!=null&&(e.ttl=BigInt(e.ttl)),e.signatureV2==null||e.data==null)throw(0,Et.default)(new Error("missing data or signatureV2"),rn);let t=Uy(e.data),n=_f(t.Value),i=J(t.Validity);if(e.value!=null&&e.signatureV1!=null)return Zv(e),{value:n,validityType:We.ValidityType.EOL,validity:i,sequence:t.Sequence,ttl:t.TTL,pubKey:e.pubKey,signatureV1:e.signatureV1,signatureV2:e.signatureV2,data:e.data};if(e.signatureV2!=null)return{value:n,validityType:We.ValidityType.EOL,validity:i,sequence:t.Sequence,ttl:t.TTL,pubKey:e.pubKey,signatureV2:e.signatureV2,data:e.data};throw new Error("invalid record: does not include signatureV1 or signatureV2")}var So=r=>we([Ty,r.toBytes()]),Io=r=>ss(r.slice(Ty.length)),Ly=(r,e,t,n,i)=>{let o;if(e===We.ValidityType.EOL)o=0;else throw(0,Et.default)(new Error("Unknown validity type"),_s);return Kn({Value:r,Validity:t,ValidityType:o,Sequence:n,TTL:i})},Uy=r=>{let e=ut(r);if(e.ValidityType===0)e.ValidityType=We.ValidityType.EOL;else throw(0,Et.default)(new Error("Unknown validity type"),_s);return Number.isInteger(e.Sequence)&&(e.Sequence=BigInt(e.Sequence)),Number.isInteger(e.TTL)&&(e.TTL=BigInt(e.TTL)),e},_f=r=>{if(r!=null){if(U0(r))return`/ipns/${r.toCID().toString(kn)}`;if(r instanceof Uint8Array){let n=J(r);n.startsWith("/")&&(r=n)}let e=r.toString().trim();if(e.startsWith("/")&&e.length>1)return e;let t=F.asCID(r);if(t!=null)return t.code===Xv?`/ipns/${t.toString(kn)}`:`/ipfs/${t.toV1().toString()}`;try{return r instanceof Uint8Array?`/ipfs/${F.decode(r).toV1().toString()}`:`/ipfs/${F.parse(e).toV1().toString()}`}catch{}}throw(0,Et.default)(new Error("Value must be a valid content path starting with /"),Am)},Zv=r=>{if(r.data==null)throw(0,Et.default)(new Error("Record data is missing"),vm);let e=Uy(r.data);if(!he(e.Value,r.value??new Uint8Array(0)))throw(0,Et.default)(new Error('Field "value" did not match between protobuf and CBOR'),rn);if(!he(e.Validity,r.validity??new Uint8Array(0)))throw(0,Et.default)(new Error('Field "validity" did not match between protobuf and CBOR'),rn);if(e.ValidityType!==r.validityType)throw(0,Et.default)(new Error('Field "validityType" did not match between protobuf and CBOR'),rn);if(e.Sequence!==r.sequence)throw(0,Et.default)(new Error('Field "sequence" did not match between protobuf and CBOR'),rn);if(e.TTL!==r.ttl)throw(0,Et.default)(new Error('Field "ttl" did not match between protobuf and CBOR'),rn)};var Jv=oe("ipns"),Qv=et.code,eA="/ipns/",NC=eA.length,Oy={v1Compatible:!0};async function Py(r,e,t,n,i=Oy){let o=new Dy.default(Date.now()+Number(n)),s=We.ValidityType.EOL,[a,c]=n.toString().split("."),u=BigInt(a)*BigInt(1e5)+BigInt(c??"0");return tA(r,e,t,s,o.toString(),u,i)}var tA=async(r,e,t,n,i,o,s=Oy)=>{t=BigInt(t);let a=H(i),c=_f(e),u=H(c);if(r.privateKey==null)throw(0,Sf.default)(new Error("Missing private key"),Sm);let l=await wm(r.privateKey),d=Ly(u,n,a,t,o),p=sl(d),f=await l.sign(p),h;if(r.publicKey!=null){let m=st(r.toBytes());(m.code!==Qv||!he(r.publicKey,m.digest))&&(h=r.publicKey)}if(s.v1Compatible===!0){let m=await rA(l,u,n,a),y={value:c,signatureV1:m,validity:i,validityType:n,sequence:t,ttl:o,signatureV2:f,data:d};return h!=null&&(y.pubKey=h),y}else{let m={value:c,validity:i,validityType:n,sequence:t,ttl:o,signatureV2:f,data:d};return h!=null&&(m.pubKey=h),m}};var rA=async(r,e,t,n)=>{try{let i=Cy(e,t,n);return await r.sign(i)}catch(i){throw Jv.error("record signature creation failed",i),(0,Sf.default)(new Error("record signature creation failed"),bm)}};var Ls=Q(Ce(),1),Fy=Q(Yc(),1);var al=oe("ipns:validator"),nA=1024*10,iA=async(r,e)=>{let t=dt(e),n;try{let i=sl(t.data);n=await r.verify(i,t.signatureV2)}catch{n=!1}if(!n)throw al.error("record signature verification failed"),(0,Ls.default)(new Error("record signature verification failed"),rn);if(t.validityType===We.ValidityType.EOL){if(Fy.default.fromString(t.validity).toDate().getTime()<Date.now())throw al.error("record has expired"),(0,Ls.default)(new Error("record has expired"),xm)}else if(t.validityType!=null)throw al.error("unrecognized validity type"),(0,Ls.default)(new Error("unrecognized validity type"),_s);al("ipns record for %s is valid",t.value)};async function cl(r,e){if(e.byteLength>nA)throw(0,Ls.default)(new Error("record too large"),Im);let t=Io(r),n=dt(e),i=await Ny(t,n);await iA(i,e)}async function*Us(r){let e=/\r?\n/,t=new TextDecoder("utf8"),n="";for await(let i of r){typeof i=="string"&&(i=new TextEncoder().encode(i)),n+=t.decode(i,{stream:!0});let o=n.split(e);n=o.pop()??"";for(let s=0;s<o.length;s++)yield JSON.parse(o[s])}n+=t.decode(),n!==""&&(yield JSON.parse(n))}var Bf=Q(My(),1);var Os=class extends Error{constructor(e){super(e),this.name="TimeoutError"}},kf=class extends Error{constructor(e){super(),this.name="AbortError",this.message=e}},Hy=r=>globalThis.DOMException===void 0?new kf(r):new DOMException(r),$y=r=>{let e=r.reason===void 0?Hy("This operation was aborted."):r.reason;return e instanceof Error?e:Hy(e)};function Ps(r,e){let{milliseconds:t,fallback:n,message:i,customTimers:o={setTimeout,clearTimeout}}=e,s,c=new Promise((u,l)=>{if(typeof t!="number"||Math.sign(t)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${t}\``);if(e.signal){let{signal:p}=e;p.aborted&&l($y(p)),p.addEventListener("abort",()=>{l($y(p))})}if(t===Number.POSITIVE_INFINITY){r.then(u,l);return}let d=new Os;s=o.setTimeout.call(void 0,()=>{if(n){try{u(n())}catch(p){l(p)}return}typeof r.cancel=="function"&&r.cancel(),i===!1?u():i instanceof Error?l(i):(d.message=i??`Promise timed out after ${t} milliseconds`,l(d))},t),(async()=>{try{u(await r)}catch(p){l(p)}})()}).finally(()=>{c.clear()});return c.clear=()=>{o.clearTimeout.call(void 0,s),s=void 0},c}function Rf(r,e,t){let n=0,i=r.length;for(;i>0;){let o=Math.trunc(i/2),s=n+o;t(r[s],e)<=0?(n=++s,i-=o+1):i=o}return n}var Fs=class{#e=[];enqueue(e,t){t={priority:0,...t};let n={priority:t.priority,run:e};if(this.size&&this.#e[this.size-1].priority>=t.priority){this.#e.push(n);return}let i=Rf(this.#e,n,(o,s)=>s.priority-o.priority);this.#e.splice(i,0,n)}dequeue(){return this.#e.shift()?.run}filter(e){return this.#e.filter(t=>t.priority===e.priority).map(t=>t.run)}get size(){return this.#e.length}};var nt=class extends Bf.default{#e;#t;#r=0;#s;#c;#p=0;#i;#l;#n;#m;#o=0;#u;#a;#y;timeout;constructor(e){if(super(),e={carryoverConcurrencyCount:!1,intervalCap:Number.POSITIVE_INFINITY,interval:0,concurrency:Number.POSITIVE_INFINITY,autoStart:!0,queueClass:Fs,...e},!(typeof e.intervalCap=="number"&&e.intervalCap>=1))throw new TypeError(`Expected \`intervalCap\` to be a number from 1 and up, got \`${e.intervalCap?.toString()??""}\` (${typeof e.intervalCap})`);if(e.interval===void 0||!(Number.isFinite(e.interval)&&e.interval>=0))throw new TypeError(`Expected \`interval\` to be a finite number >= 0, got \`${e.interval?.toString()??""}\` (${typeof e.interval})`);this.#e=e.carryoverConcurrencyCount,this.#t=e.intervalCap===Number.POSITIVE_INFINITY||e.interval===0,this.#s=e.intervalCap,this.#c=e.interval,this.#n=new e.queueClass,this.#m=e.queueClass,this.concurrency=e.concurrency,this.timeout=e.timeout,this.#y=e.throwOnTimeout===!0,this.#a=e.autoStart===!1}get#E(){return this.#t||this.#r<this.#s}get#x(){return this.#o<this.#u}#b(){this.#o--,this.#d(),this.emit("next")}#v(){this.#w(),this.#g(),this.#l=void 0}get#A(){let e=Date.now();if(this.#i===void 0){let t=this.#p-e;if(t<0)this.#r=this.#e?this.#o:0;else return this.#l===void 0&&(this.#l=setTimeout(()=>{this.#v()},t)),!0}return!1}#d(){if(this.#n.size===0)return this.#i&&clearInterval(this.#i),this.#i=void 0,this.emit("empty"),this.#o===0&&this.emit("idle"),!1;if(!this.#a){let e=!this.#A;if(this.#E&&this.#x){let t=this.#n.dequeue();return t?(this.emit("active"),t(),e&&this.#g(),!0):!1}}return!1}#g(){this.#t||this.#i!==void 0||(this.#i=setInterval(()=>{this.#w()},this.#c),this.#p=Date.now()+this.#c)}#w(){this.#r===0&&this.#o===0&&this.#i&&(clearInterval(this.#i),this.#i=void 0),this.#r=this.#e?this.#o:0,this.#f()}#f(){for(;this.#d(););}get concurrency(){return this.#u}set concurrency(e){if(!(typeof e=="number"&&e>=1))throw new TypeError(`Expected \`concurrency\` to be a number from 1 and up, got \`${e}\` (${typeof e})`);this.#u=e,this.#f()}async#_(e){return new Promise((t,n)=>{e.addEventListener("abort",()=>{n(e.reason)},{once:!0})})}async add(e,t={}){return t={timeout:this.timeout,throwOnTimeout:this.#y,...t},new Promise((n,i)=>{this.#n.enqueue(async()=>{this.#o++,this.#r++;try{t.signal?.throwIfAborted();let o=e({signal:t.signal});t.timeout&&(o=Ps(Promise.resolve(o),{milliseconds:t.timeout})),t.signal&&(o=Promise.race([o,this.#_(t.signal)]));let s=await o;n(s),this.emit("completed",s)}catch(o){if(o instanceof Os&&!t.throwOnTimeout){n();return}i(o),this.emit("error",o)}finally{this.#b()}},t),this.emit("add"),this.#d()})}async addAll(e,t){return Promise.all(e.map(async n=>this.add(n,t)))}start(){return this.#a?(this.#a=!1,this.#f(),this):this}pause(){this.#a=!0}clear(){this.#n=new this.#m}async onEmpty(){this.#n.size!==0&&await this.#h("empty")}async onSizeLessThan(e){this.#n.size<e||await this.#h("next",()=>this.#n.size<e)}async onIdle(){this.#o===0&&this.#n.size===0||await this.#h("idle")}async#h(e,t){return new Promise(n=>{let i=()=>{t&&!t()||(this.off(e,i),n())};this.on(e,i)})}get size(){return this.#n.size}sizeBy(e){return this.#n.filter(e).length}get pending(){return this.#o}get isPaused(){return this.#a}};function aA(r){return r[Symbol.asyncIterator]!=null}function cA(r){if(aA(r))return(async()=>{for await(let e of r)return e})();for(let e of r)return e}var _i=cA;var Tf=H("/ipns/");function zy(r){return he(r.subarray(0,Tf.byteLength),Tf)}var Ky=r=>ss(r.slice(Tf.length)),ul=class{client;constructor(e){this.client=e}async*findProviders(e,t={}){yield*at(this.client.getProviders(e,t),n=>({id:n.ID,multiaddrs:n.Addrs??[]}))}async provide(){}async put(e,t,n){if(!zy(e))return;let i=Ky(e),o=dt(t);await this.client.putIPNS(i,o,n)}async get(e,t){if(!zy(e))throw new O("Not found","ERR_NOT_FOUND");let n=Ky(e);try{let i=await this.client.getIPNS(n,t);return sn(i)}catch(i){throw i.code==="ERR_BAD_RESPONSE"?new O("Not found","ERR_NOT_FOUND"):i}}},dl=class{client;constructor(e){this.client=e}async findPeer(e,t={}){let n=await _i(this.client.getPeers(e,t));if(n!=null)return{id:n.ID,multiaddrs:n.Addrs??[]};throw new O("Not found","ERR_NOT_FOUND")}async*getClosestPeers(e,t={}){}};var xt=oe("delegated-routing-v1-http-api-client"),Gy={concurrentRequests:4,timeout:3e4},fl=class{started;httpQueue;shutDownController;clientUrl;timeout;contentRouting;peerRouting;constructor(e,t={}){this.started=!1,this.shutDownController=new AbortController,_a(1/0,this.shutDownController.signal),this.httpQueue=new nt({concurrency:t.concurrentRequests??Gy.concurrentRequests}),this.clientUrl=e instanceof URL?e:new URL(e),this.timeout=t.timeout??Gy.timeout,this.contentRouting=new ul(this),this.peerRouting=new dl(this)}get[es](){return this.contentRouting}get[ts](){return this.peerRouting}isStarted(){return this.started}start(){this.started=!0}stop(){this.httpQueue.clear(),this.shutDownController.abort(),this.started=!1}async*getProviders(e,t={}){xt("getProviders starts: %c",e);let n=ci([this.shutDownController.signal,t.signal,AbortSignal.timeout(this.timeout)]),i=_e(),o=_e();this.httpQueue.add(async()=>(i.resolve(),o.promise));try{await i.promise;let s=`${this.clientUrl}routing/v1/providers/${e.toString()}`,c=await fetch(s,{headers:{Accept:"application/x-ndjson"},signal:n});if(c.status===404)throw new O("No matching records found.","ERR_NOT_FOUND");if(c.status===422)throw new O("Request does not conform to schema or semantic constraints.","ERR_INVALID_REQUEST");if(c.body==null)throw new O("Routing response had no body","ERR_BAD_RESPONSE");if(c.headers.get("Content-Type")==="application/json"){let l=await c.json();for(let d of l.Providers){let p=this.#e(d);p!=null&&(yield p)}}else for await(let l of Us(Ha(c.body))){let d=this.#e(l);d!=null&&(yield d)}}catch(s){xt.error("getProviders errored:",s)}finally{n.clear(),o.resolve(),xt("getProviders finished: %c",e)}}async*getPeers(e,t={}){xt("getPeers starts: %c",e);let n=ci([this.shutDownController.signal,t.signal,AbortSignal.timeout(this.timeout)]),i=_e(),o=_e();this.httpQueue.add(async()=>(i.resolve(),o.promise));try{await i.promise;let s=`${this.clientUrl}routing/v1/peers/${e.toCID().toString()}`,c=await fetch(s,{headers:{Accept:"application/x-ndjson"},signal:n});if(c.status===404)throw new O("No matching records found.","ERR_NOT_FOUND");if(c.status===422)throw new O("Request does not conform to schema or semantic constraints.","ERR_INVALID_REQUEST");if(c.body==null)throw new O("Routing response had no body","ERR_BAD_RESPONSE");if(c.headers.get("Content-Type")==="application/json"){let l=await c.json();for(let d of l.Peers){let p=this.#e(d);p!=null&&(yield p)}}else for await(let l of Us(Ha(c.body))){let d=this.#e(l);d!=null&&(yield d)}}catch(s){xt.error("getPeers errored:",s)}finally{n.clear(),o.resolve(),xt("getPeers finished: %c",e)}}async getIPNS(e,t={}){xt("getIPNS starts: %c",e);let n=ci([this.shutDownController.signal,t.signal,AbortSignal.timeout(this.timeout)]),i=_e(),o=_e();this.httpQueue.add(async()=>(i.resolve(),o.promise));let s=`${this.clientUrl}routing/v1/ipns/${e.toCID().toString()}`;try{await i.promise;let c=await fetch(s,{headers:{Accept:"application/vnd.ipfs.ipns-record"},signal:n});if(xt("getIPNS GET %s %d",s,c.status),c.status===404)throw new O("No matching records found.","ERR_NOT_FOUND");if(c.status===422)throw new O("Request does not conform to schema or semantic constraints.","ERR_INVALID_REQUEST");if(c.body==null)throw new O("GET ipns response had no body","ERR_BAD_RESPONSE");let u=await c.arrayBuffer(),l=new Uint8Array(u,0,u.byteLength);return t.validate!==!1&&await cl(So(e),l),dt(l)}catch(a){throw xt.error("getIPNS GET %s error:",s,a),a}finally{n.clear(),o.resolve(),xt("getIPNS finished: %c",e)}}async putIPNS(e,t,n={}){xt("putIPNS starts: %c",e);let i=ci([this.shutDownController.signal,n.signal,AbortSignal.timeout(this.timeout)]),o=_e(),s=_e();this.httpQueue.add(async()=>(o.resolve(),s.promise));let a=`${this.clientUrl}routing/v1/ipns/${e.toCID().toString()}`;try{await o.promise;let c=sn(t),l=await fetch(a,{method:"PUT",headers:{"Content-Type":"application/vnd.ipfs.ipns-record"},body:c,signal:i});if(xt("putIPNS PUT %s %d",a,l.status),l.status!==200)throw new O("PUT ipns response had status other than 200","ERR_BAD_RESPONSE")}catch(c){throw xt.error("putIPNS PUT %s error:",a,c.stack),c}finally{i.clear(),s.resolve(),xt("putIPNS finished: %c",e)}}#e(e){let t=[],n=e.Addrs?.map(kd)??[];return e.Protocols!=null&&t.push(...e.Protocols),e.Protocol!=null&&(t.push(e.Protocol),delete e.Protocol),{...e,Schema:"peer",ID:Jt(e.ID),Addrs:n,Protocols:t}}};function qy(r,e={}){return new fl(new URL(r),e)}var Yy=H("/ipns/");function Wy(r){return he(r.subarray(0,Yy.byteLength),Yy)}var Nf=class{client;constructor(e){this.client=qy(e)}async provide(e,t){}async*findProviders(e,t){yield*at(this.client.getProviders(e,t),n=>({id:n.ID,multiaddrs:n.Addrs,protocols:n.Protocols}))}async put(e,t,n){if(!Wy(e))return;let i=Io(e),o=dt(t);await this.client.putIPNS(i,o,n)}async get(e,t){if(!Wy(e))throw new O("Not found","ERR_NOT_FOUND");let n=Io(e);try{let i=await this.client.getIPNS(n,t);return sn(i)}catch(i){throw i.code==="ERR_BAD_RESPONSE"?new O("Not found","ERR_NOT_FOUND"):i}}async findPeer(e,t){let n=await _i(this.client.getPeers(e,t));if(n!=null)return{id:n.ID,multiaddrs:n.Addrs??[]};throw new O("Not found","ERR_NOT_FOUND")}async*getClosestPeers(e,t){}};function Vs(r){return new Nf(new URL(r))}var Cf=class extends Error{type;code;constructor(e,t){super(e??"The operation was aborted"),this.type="aborted",this.name="AbortError",this.code=t??"ABORT_ERR"}};async function hl(r,e,t,n){let i=new Cf(n?.errorMessage,n?.errorCode);return t?.aborted===!0?Promise.reject(i):new Promise((o,s)=>{let a=u=>{try{if(n?.filter?.(u)===!1)return}catch(l){r.removeEventListener(e,a),t?.removeEventListener("abort",c),s(l);return}r.removeEventListener(e,a),t?.removeEventListener("abort",c),o(u)},c=()=>{r.removeEventListener(e,a),t?.removeEventListener("abort",c),s(i)};r.addEventListener(e,a),t?.addEventListener("abort",c)})}var pl=class extends Error{type;code;constructor(e,t){super(e??"The operation was aborted"),this.type="aborted",this.name="AbortError",this.code=t??"ABORT_ERR"}};async function jy(r,e,t){if(e==null)return r;if(e.aborted)return Promise.reject(new pl(t?.errorMessage,t?.errorCode));let n,i=new pl(t?.errorMessage,t?.errorCode);try{return await Promise.race([r,new Promise((o,s)=>{n=()=>{s(i)},e.addEventListener("abort",n)})])}finally{n!=null&&e.removeEventListener("abort",n)}}var ml=class{deferred;signal;where;constructor(e,t){this.signal=t,this.deferred=_e(),this.where=e,this.onAbort=this.onAbort.bind(this),this.signal?.addEventListener("abort",this.onAbort)}onAbort(){this.deferred.reject(new An)}cleanup(){this.signal?.removeEventListener("abort",this.onAbort)}};function lA(){return`${parseInt(String(Math.random()*1e9),10).toString()}${Date.now()}`}var yl=class{id;fn;options;priority;recipients;status;timeline;controller;constructor(e,t,n=0){this.id=lA(),this.status="queued",this.fn=e,this.priority=n,this.options=t,this.recipients=[],this.timeline={created:Date.now()},this.controller=new AbortController,_a(1/0,this.controller.signal),this.onAbort=this.onAbort.bind(this)}abort(e){this.controller.abort(e)}onAbort(){this.recipients.reduce((t,n)=>t&&n.signal?.aborted===!0,!0)&&this.controller.abort(new An)}async join(e={}){let t=new ml(new Error("where").stack,e.signal);return this.recipients.push(t),e.signal?.addEventListener("abort",this.onAbort),t.deferred.promise}async run(){this.status="running",this.timeline.started=Date.now();try{this.controller.signal.throwIfAborted();let e=await jy(this.fn({...this.options??{},signal:this.controller.signal}),this.controller.signal);this.recipients.forEach(t=>{t.deferred.resolve(e)}),this.status="complete"}catch(e){this.recipients.forEach(t=>{t.deferred.reject(e)}),this.status="errored"}finally{this.timeline.finished=Date.now(),this.cleanup()}}cleanup(){this.recipients.forEach(e=>{e.signal?.removeEventListener("abort",this.onAbort)})}};function uA(r,e,t){let n=0,i=r.length;for(;i>0;){let o=Math.trunc(i/2),s=n+o;t(r[s],e)<=0?(n=++s,i-=o+1):i=o}return n}var Ms=class extends Aa{concurrency;queue;pending;constructor(e={}){super(),this.concurrency=e.concurrency??Number.POSITIVE_INFINITY,this.pending=0,e.metricName!=null&&e.metrics?.registerMetricGroup(e.metricName,{calculate:()=>({size:this.queue.length,running:this.pending,queued:this.queue.length-this.pending})}),this.queue=[]}tryToStartAnother(){if(this.size===0)return queueMicrotask(()=>{this.safeDispatchEvent("empty")}),this.running===0&&queueMicrotask(()=>{this.safeDispatchEvent("idle")}),!1;if(this.pending<this.concurrency){let e;for(let t of this.queue)if(t.status==="queued"){e=t;break}return e==null?!1:(this.safeDispatchEvent("active"),this.pending++,e.run().finally(()=>{for(let t=0;t<this.queue.length;t++)if(this.queue[t]===e){this.queue.splice(t,1);break}this.pending--,this.tryToStartAnother(),this.safeDispatchEvent("next")}),!0)}return!1}enqueue(e){if(this.queue[this.size-1]?.priority>=e.priority){this.queue.push(e);return}let t=uA(this.queue,e,(n,i)=>i.priority-n.priority);this.queue.splice(t,0,e)}async add(e,t){t?.signal?.throwIfAborted();let n=new yl(e,t,t?.priority),i=n.join(t).then(o=>(this.safeDispatchEvent("completed",{detail:o}),o)).catch(o=>{throw this.safeDispatchEvent("error",{detail:o}),o});return this.enqueue(n),this.safeDispatchEvent("add"),this.tryToStartAnother(),i}clear(){this.queue.splice(0,this.queue.length)}abort(){this.queue.forEach(e=>{e.abort(new An)}),this.clear()}async onEmpty(e){this.size!==0&&await hl(this,"empty",e?.signal)}async onSizeLessThan(e,t){this.size<e||await hl(this,"next",t?.signal,{filter:()=>this.size<e})}async onIdle(e){this.pending===0&&this.size===0||await hl(this,"idle",e?.signal)}get size(){return this.queue.length}get queued(){return this.queue.length-this.pending}get running(){return this.pending}async*toGenerator(e){e?.signal?.throwIfAborted();let t=zt({objectMode:!0}),n=c=>{c!=null?this.abort():this.clear(),t.end(c)},i=c=>{c.detail!=null&&t.push(c.detail)},o=c=>{n(c.detail)},s=()=>{n()},a=()=>{n(new O("Queue aborted","ERR_QUEUE_ABORTED"))};this.addEventListener("completed",i),this.addEventListener("error",o),this.addEventListener("idle",s),e?.signal?.addEventListener("abort",a);try{yield*t}finally{this.removeEventListener("completed",i),this.removeEventListener("error",o),this.removeEventListener("idle",s),e?.signal?.removeEventListener("abort",a),n()}}};var Qy="/pin/",Xy="/pinned-block/",Lf=kn,Zy=1;function Jy(r){return r.version===0&&(r=r.toV1()),new Fe(`${Qy}${r.toString(Lf)}`)}var gl=class{datastore;blockstore;dagWalkers;constructor(e,t,n){this.datastore=e,this.blockstore=t,this.dagWalkers=n}async*add(e,t={}){let n=Jy(e);if(await this.datastore.has(n))throw new Error("Already pinned");let i=Math.round(t.depth??1/0);if(i<0)throw new Error("Depth must be greater than or equal to 0");let o=new Ms({concurrency:Zy});for await(let a of this.#e(e,o,{...t,depth:i}))await this.#t(a,c=>c.pinnedBy.find(u=>he(u,e.bytes))!=null?!1:(c.pinCount++,c.pinnedBy.push(e.bytes),!0),t),yield a;let s={depth:i,metadata:t.metadata??{}};await this.datastore.put(n,Kn(s),t)}async*#e(e,t,n){if(n.depth===-1)return;let i=this.dagWalkers[e.code];if(i==null)throw new Error(`No dag walker found for cid codec ${e.code}`);let o=await this.blockstore.get(e,n);yield e;for await(let s of i.walk(o))yield*await t.add(async()=>this.#e(s,t,{...n,depth:n.depth-1}))}async#t(e,t,n){let i=new Fe(`${Xy}${Lf.encode(e.multihash.bytes)}`),o={pinCount:0,pinnedBy:[]};try{o=ut(await this.datastore.get(i,n))}catch(a){if(a.code!=="ERR_NOT_FOUND")throw a}if(t(o)){if(o.pinCount===0&&await this.datastore.has(i)){await this.datastore.delete(i);return}await this.datastore.put(i,Kn(o),n),n.onProgress?.(new V("helia:pin:add",e))}}async*rm(e,t={}){let n=Jy(e),i=await this.datastore.get(n,t),o=ut(i);await this.datastore.delete(n,t);let s=new Ms({concurrency:Zy});for await(let a of this.#e(e,s,{...t,depth:o.depth}))await this.#t(a,c=>(c.pinCount--,c.pinnedBy=c.pinnedBy.filter(u=>he(u,e.bytes)),!0),{...t,depth:o.depth}),yield a}async*ls(e={}){for await(let{key:t,value:n}of this.datastore.query({prefix:Qy+(e.cid!=null?`${e.cid.toString(kn)}`:"")},e)){let i=F.parse(t.toString().substring(5),kn),o=ut(n);yield{cid:i,...o}}}async isPinned(e,t={}){let n=new Fe(`${Xy}${Lf.encode(e.multihash.bytes)}`);return this.datastore.has(n,t)}};function Uf(r,e){let t={[Symbol.iterator]:()=>t,next:()=>{let n=r.next(),i=n.value;return n.done===!0||i==null?{done:!0,value:void 0}:{done:!1,value:e(i)}}};return t}var Bo=class r{set;constructor(e){if(this.set=new Set,e!=null)for(let t of e)this.set.add(t.toString())}get size(){return this.set.size}[Symbol.iterator](){return this.values()}add(e){this.set.add(e.toString())}clear(){this.set.clear()}delete(e){this.set.delete(e.toString())}entries(){return Uf(this.set.entries(),e=>{let t=Jt(e[0]);return[t,t]})}forEach(e){this.set.forEach(t=>{let n=Jt(t);e(n,n,this)})}has(e){return this.set.has(e.toString())}values(){return Uf(this.set.values(),e=>Jt(e))}intersection(e){let t=new r;for(let n of e)this.has(n)&&t.add(n);return t}difference(e){let t=new r;for(let n of this)e.has(n)||t.add(n);return t}union(e){let t=new r;for(let n of e)t.add(n);for(let n of this)t.add(n);return t}};var wl=class{log;routers;constructor(e,t){this.log=e.logger.forComponent("helia:routing"),this.routers=t.routers??[]}async start(){await _n(...this.routers)}async stop(){await Sn(...this.routers)}async*findProviders(e,t={}){if(this.routers.length===0)throw new O("No content routers available","ERR_NO_ROUTERS_AVAILABLE");let n=new Bo;for await(let i of Hr(...ko(this.routers,"findProviders").map(o=>o.findProviders(e,t))))i!=null&&(n.has(i.id)||(n.add(i.id),yield i))}async provide(e,t={}){if(this.routers.length===0)throw new O("No content routers available","ERR_NO_ROUTERS_AVAILABLE");await Promise.all(ko(this.routers,"provide").map(async n=>{await n.provide(e,t)}))}async put(e,t,n){await Promise.all(ko(this.routers,"put").map(async i=>{await i.put(e,t,n)}))}async get(e,t){return Promise.any(ko(this.routers,"get").map(async n=>n.get(e,t)))}async findPeer(e,t){if(this.routers.length===0)throw new O("No peer routers available","ERR_NO_ROUTERS_AVAILABLE");let n=this,i=Hr(...ko(this.routers,"findPeer").map(o=>async function*(){try{yield await o.findPeer(e,t)}catch(s){n.log.error(s)}}()));for await(let o of i)if(o!=null)return o;throw new O("Could not find peer in routing","ERR_NOT_FOUND")}async*getClosestPeers(e,t={}){if(this.routers.length===0)throw new O("No peer routers available","ERR_NO_ROUTERS_AVAILABLE");let n=new Bo;for await(let i of Hr(...ko(this.routers,"getClosestPeers").map(o=>o.getClosestPeers(e,t))))i!=null&&(n.has(i.id)||(n.add(i.id),yield i))}};function ko(r,e){return r.filter(t=>t[e]!=null)}var Gn={},Ro=r=>{r.addEventListener("message",e=>{Ro.dispatchEvent("message",r,e)}),r.port!=null&&r.port.addEventListener("message",e=>{Ro.dispatchEvent("message",r,e)})};Ro.addEventListener=(r,e)=>{Gn[r]==null&&(Gn[r]=[]),Gn[r].push(e)};Ro.removeEventListener=(r,e)=>{Gn[r]!=null&&(Gn[r]=Gn[r].filter(t=>t===e))};Ro.dispatchEvent=function(r,e,t){Gn[r]!=null&&Gn[r].forEach(n=>n(e,t))};var Df=Ro;var Of="lock:worker:request-read",Pf="lock:worker:release-read",Ff="lock:master:grant-read",Vf="lock:worker:request-write",Mf="lock:worker:release-write",Hf="lock:master:grant-write";var eg=(r=21)=>Math.random().toString().substring(2);var tg=(r,e,t,n,i)=>(o,s)=>{if(s.data.type!==t)return;let a={type:s.data.type,name:s.data.name,identifier:s.data.identifier};r.dispatchEvent(new MessageEvent(e,{data:{name:a.name,handler:async()=>{o.postMessage({type:i,name:a.name,identifier:a.identifier}),await new Promise(c=>{let u=l=>{if(l==null||l.data==null)return;let d={type:l.data.type,name:l.data.name,identifier:l.data.identifier};d.type===n&&d.identifier===a.identifier&&(o.removeEventListener("message",u),c())};o.addEventListener("message",u)})}}}))},rg=(r,e,t,n)=>async()=>{let i=eg();return globalThis.postMessage({type:e,identifier:i,name:r}),new Promise(o=>{let s=a=>{if(a==null||a.data==null)return;let c={type:a.data.type,identifier:a.data.identifier};c.type===t&&c.identifier===i&&(globalThis.removeEventListener("message",s),o(()=>{globalThis.postMessage({type:n,identifier:i,name:r})}))};globalThis.addEventListener("message",s)})},dA={singleProcess:!1},ng=r=>{if(r=Object.assign({},dA,r),!!globalThis.document||r.singleProcess){let t=new EventTarget;return Df.addEventListener("message",tg(t,"requestReadLock",Of,Pf,Ff)),Df.addEventListener("message",tg(t,"requestWriteLock",Vf,Mf,Hf)),t}return{isWorker:!0,readLock:t=>rg(t,Of,Ff,Pf),writeLock:t=>rg(t,Vf,Hf,Mf)}};var Si={},qn;async function $f(r,e){let t,n=new Promise(i=>{t=i});return r.add(async()=>Ps((async()=>{await new Promise(i=>{t(()=>{i()})})})(),{milliseconds:e.timeout})),n}var fA=(r,e)=>{if(qn.isWorker===!0)return{readLock:qn.readLock(r,e),writeLock:qn.writeLock(r,e)};let t=new nt({concurrency:1}),n;return{async readLock(){if(n!=null)return $f(n,e);n=new nt({concurrency:e.concurrency,autoStart:!1});let i=n,o=$f(n,e);return t.add(async()=>{i.start(),await i.onIdle().then(()=>{n===i&&(n=null)})}),o},async writeLock(){return n=null,$f(t,e)}}},hA={name:"lock",concurrency:1/0,timeout:846e5,singleProcess:!1};function zf(r){let e=Object.assign({},hA,r);return qn==null&&(qn=ng(e),qn.isWorker!==!0&&(qn.addEventListener("requestReadLock",t=>{Si[t.data.name]!=null&&Si[t.data.name].readLock().then(async n=>t.data.handler().finally(()=>{n()}))}),qn.addEventListener("requestWriteLock",async t=>{Si[t.data.name]!=null&&Si[t.data.name].writeLock().then(async n=>t.data.handler().finally(()=>{n()}))}))),Si[e.name]==null&&(Si[e.name]=fA(e.name,e)),Si[e.name]}var El=class{lock;child;pins;started;constructor(e,t,n={}){this.child=e,this.pins=t,this.lock=zf({singleProcess:n.holdGcLock}),this.started=!1}isStarted(){return this.started}async start(){await _n(this.child),this.started=!0}async stop(){await Sn(this.child),this.started=!1}unwrap(){return this.child}async put(e,t,n={}){let i=await this.lock.readLock();try{return await this.child.put(e,t,n)}finally{i()}}async*putMany(e,t={}){let n=await this.lock.readLock();try{yield*this.child.putMany(e,t)}finally{n()}}async get(e,t={}){let n=await this.lock.readLock();try{return await this.child.get(e,t)}finally{n()}}async*getMany(e,t={}){let n=await this.lock.readLock();try{yield*this.child.getMany(e,t)}finally{n()}}async delete(e,t={}){let n=await this.lock.writeLock();try{if(await this.pins.isPinned(e))throw new Error("CID was pinned");await this.child.delete(e,t)}finally{n()}}async*deleteMany(e,t={}){let n=await this.lock.writeLock();try{let i=this;yield*this.child.deleteMany(async function*(){for await(let o of e){if(await i.pins.isPinned(o))throw new Error("CID was pinned");yield o}}(),t)}finally{n()}}async has(e,t={}){let n=await this.lock.readLock();try{return await this.child.has(e,t)}finally{n()}}async*getAll(e={}){let t=await this.lock.readLock();try{yield*this.child.getAll(e)}finally{t()}}};var ig=42;function pA(r){return r instanceof ArrayBuffer?new Uint8Array(r,0,r.byteLength):r}function mA(r){if(r.asCID!==r&&r["/"]!==r.bytes)return null;let e=F.asCID(r);if(!e)return null;let t=new Uint8Array(e.bytes.byteLength+1);return t.set(e.bytes,1),[new R(w.tag,ig),new R(w.bytes,t)]}function yA(){throw new Error("`undefined` is not supported by the IPLD Data Model and cannot be encoded")}function gA(r){if(Number.isNaN(r))throw new Error("`NaN` is not supported by the IPLD Data Model and cannot be encoded");if(r===1/0||r===-1/0)throw new Error("`Infinity` and `-Infinity` is not supported by the IPLD Data Model and cannot be encoded");return null}var Kf={float64:!0,typeEncoders:{Object:mA,undefined:yA,number:gA}},CU={...Kf,typeEncoders:{...Kf.typeEncoders}};function wA(r){if(r[0]!==0)throw new Error("Invalid CID for CBOR tag 42; expected leading 0x00");return F.decode(r.subarray(1))}var xl={allowIndefinite:!1,coerceUndefinedToNull:!0,allowNaN:!1,allowInfinity:!1,allowBigInt:!0,strict:!0,useMaps:!1,rejectDuplicateMapKeys:!0,tags:[]};xl.tags[ig]=wA;var LU={...xl,tags:xl.tags.slice()};var Yn=113,Hs=r=>Kn(r,Kf),Ii=r=>ut(pA(r),xl);var Gf=class extends Array{constructor(){super(),this.inRecursive=[]}prefix(e){let t=this.inRecursive[this.inRecursive.length-1];t&&(t.type===w.array&&(t.elements++,t.elements!==1&&e.push([44])),t.type===w.map&&(t.elements++,t.elements!==1&&(t.elements%2===1?e.push([44]):e.push([58]))))}[w.uint.major](e,t){this.prefix(e);let n=String(t.value),i=[];for(let o=0;o<n.length;o++)i[o]=n.charCodeAt(o);e.push(i)}[w.negint.major](e,t){this[w.uint.major](e,t)}[w.bytes.major](e,t){throw new Error(`${nn} unsupported type: Uint8Array`)}[w.string.major](e,t){this.prefix(e);let n=jc(JSON.stringify(t.value));e.push(n.length>32?Ss(n):n)}[w.array.major](e,t){this.prefix(e),this.inRecursive.push({type:w.array,elements:0}),e.push([91])}[w.map.major](e,t){this.prefix(e),this.inRecursive.push({type:w.map,elements:0}),e.push([123])}[w.tag.major](e,t){}[w.float.major](e,t){if(t.type.name==="break"){let s=this.inRecursive.pop();if(s){if(s.type===w.array)e.push([93]);else if(s.type===w.map)e.push([125]);else throw new Error("Unexpected recursive type; this should not happen!");return}throw new Error("Unexpected break; this should not happen!")}if(t.value===void 0)throw new Error(`${nn} unsupported type: undefined`);if(this.prefix(e),t.type.name==="true"){e.push([116,114,117,101]);return}else if(t.type.name==="false"){e.push([102,97,108,115,101]);return}else if(t.type.name==="null"){e.push([110,117,108,108]);return}let n=String(t.value),i=[],o=!1;for(let s=0;s<n.length;s++)i[s]=n.charCodeAt(s),!o&&(i[s]===46||i[s]===101||i[s]===69)&&(o=!0);o||(i.push(46),i.push(48)),e.push(i)}};function EA(r,e){if(Array.isArray(r[0])||Array.isArray(e[0]))throw new Error(`${nn} complex map keys are not supported`);let t=r[0],n=e[0];if(t.type!==w.string||n.type!==w.string)throw new Error(`${nn} non-string map keys are not supported`);if(t<n)return-1;if(t>n)return 1;throw new Error(`${nn} unexpected duplicate map keys, this is not supported`)}var xA={addBreakTokens:!0,mapSorter:EA};function zs(r,e){return e=Object.assign({},xA,e),bf(r,new Gf,e)}var Wn=class{constructor(e,t={}){this._pos=0,this.data=e,this.options=t,this.modeStack=["value"],this.lastToken=""}pos(){return this._pos}done(){return this._pos>=this.data.length}ch(){return this.data[this._pos]}currentMode(){return this.modeStack[this.modeStack.length-1]}skipWhitespace(){let e=this.ch();for(;e===32||e===9||e===13||e===10;)e=this.data[++this._pos]}expect(e){if(this.data.length-this._pos<e.length)throw new Error(`${G} unexpected end of input at position ${this._pos}`);for(let t=0;t<e.length;t++)if(this.data[this._pos++]!==e[t])throw new Error(`${G} unexpected token at position ${this._pos}, expected to find '${String.fromCharCode(...e)}'`)}parseNumber(){let e=this._pos,t=!1,n=!1,i=a=>{for(;!this.done();){let c=this.ch();if(a.includes(c))this._pos++;else break}};if(this.ch()===45&&(t=!0,this._pos++),this.ch()===48)if(this._pos++,this.ch()===46)this._pos++,n=!0;else return new R(w.uint,0,this._pos-e);if(i([48,49,50,51,52,53,54,55,56,57]),t&&this._pos===e+1)throw new Error(`${G} unexpected token at position ${this._pos}`);if(!this.done()&&this.ch()===46){if(n)throw new Error(`${G} unexpected token at position ${this._pos}`);n=!0,this._pos++,i([48,49,50,51,52,53,54,55,56,57])}!this.done()&&(this.ch()===101||this.ch()===69)&&(n=!0,this._pos++,!this.done()&&(this.ch()===43||this.ch()===45)&&this._pos++,i([48,49,50,51,52,53,54,55,56,57]));let o=String.fromCharCode.apply(null,this.data.subarray(e,this._pos)),s=parseFloat(o);return n?new R(w.float,s,this._pos-e):this.options.allowBigInt!==!0||Number.isSafeInteger(s)?new R(s>=0?w.uint:w.negint,s,this._pos-e):new R(s>=0?w.uint:w.negint,BigInt(o),this._pos-e)}parseString(){if(this.ch()!==34)throw new Error(`${G} unexpected character at position ${this._pos}; this shouldn't happen`);this._pos++;for(let o=this._pos,s=0;o<this.data.length&&s<65536;o++,s++){let a=this.data[o];if(a===92||a<32||a>=128)break;if(a===34){let c=String.fromCharCode.apply(null,this.data.subarray(this._pos,o));return this._pos=o+1,new R(w.string,c,s)}}let e=this._pos,t=[],n=()=>{if(this._pos+4>=this.data.length)throw new Error(`${G} unexpected end of unicode escape sequence at position ${this._pos}`);let o=0;for(let s=0;s<4;s++){let a=this.ch();if(a>=48&&a<=57)a-=48;else if(a>=97&&a<=102)a=a-97+10;else if(a>=65&&a<=70)a=a-65+10;else throw new Error(`${G} unexpected unicode escape character at position ${this._pos}`);o=o*16+a,this._pos++}return o},i=()=>{let o=this.ch(),s=null,a=o>239?4:o>223?3:o>191?2:1;if(this._pos+a>this.data.length)throw new Error(`${G} unexpected unicode sequence at position ${this._pos}`);let c,u,l,d;switch(a){case 1:o<128&&(s=o);break;case 2:c=this.data[this._pos+1],(c&192)===128&&(d=(o&31)<<6|c&63,d>127&&(s=d));break;case 3:c=this.data[this._pos+1],u=this.data[this._pos+2],(c&192)===128&&(u&192)===128&&(d=(o&15)<<12|(c&63)<<6|u&63,d>2047&&(d<55296||d>57343)&&(s=d));break;case 4:c=this.data[this._pos+1],u=this.data[this._pos+2],l=this.data[this._pos+3],(c&192)===128&&(u&192)===128&&(l&192)===128&&(d=(o&15)<<18|(c&63)<<12|(u&63)<<6|l&63,d>65535&&d<1114112&&(s=d))}s===null?(s=65533,a=1):s>65535&&(s-=65536,t.push(s>>>10&1023|55296),s=56320|s&1023),t.push(s),this._pos+=a};for(;!this.done();){let o=this.ch(),s;switch(o){case 92:if(this._pos++,this.done())throw new Error(`${G} unexpected string termination at position ${this._pos}`);switch(s=this.ch(),this._pos++,s){case 34:case 39:case 92:case 47:t.push(s);break;case 98:t.push(8);break;case 116:t.push(9);break;case 110:t.push(10);break;case 102:t.push(12);break;case 114:t.push(13);break;case 117:t.push(n());break;default:throw new Error(`${G} unexpected string escape character at position ${this._pos}`)}break;case 34:return this._pos++,new R(w.string,hf(t),this._pos-e);default:if(o<32)throw new Error(`${G} invalid control character at position ${this._pos}`);o<128?(t.push(o),this._pos++):i()}}throw new Error(`${G} unexpected end of string at position ${this._pos}`)}parseValue(){switch(this.ch()){case 123:return this.modeStack.push("obj-start"),this._pos++,new R(w.map,1/0,1);case 91:return this.modeStack.push("array-start"),this._pos++,new R(w.array,1/0,1);case 34:return this.parseString();case 110:return this.expect([110,117,108,108]),new R(w.null,null,4);case 102:return this.expect([102,97,108,115,101]),new R(w.false,!1,5);case 116:return this.expect([116,114,117,101]),new R(w.true,!0,4);case 45:case 48:case 49:case 50:case 51:case 52:case 53:case 54:case 55:case 56:case 57:return this.parseNumber();default:throw new Error(`${G} unexpected character at position ${this._pos}`)}}next(){switch(this.skipWhitespace(),this.currentMode()){case"value":return this.modeStack.pop(),this.parseValue();case"array-value":{if(this.modeStack.pop(),this.ch()===93)return this._pos++,this.skipWhitespace(),new R(w.break,void 0,1);if(this.ch()!==44)throw new Error(`${G} unexpected character at position ${this._pos}, was expecting array delimiter but found '${String.fromCharCode(this.ch())}'`);return this._pos++,this.modeStack.push("array-value"),this.skipWhitespace(),this.parseValue()}case"array-start":return this.modeStack.pop(),this.ch()===93?(this._pos++,this.skipWhitespace(),new R(w.break,void 0,1)):(this.modeStack.push("array-value"),this.skipWhitespace(),this.parseValue());case"obj-key":if(this.ch()===125)return this.modeStack.pop(),this._pos++,this.skipWhitespace(),new R(w.break,void 0,1);if(this.ch()!==44)throw new Error(`${G} unexpected character at position ${this._pos}, was expecting object delimiter but found '${String.fromCharCode(this.ch())}'`);this._pos++,this.skipWhitespace();case"obj-start":{if(this.modeStack.pop(),this.ch()===125)return this._pos++,this.skipWhitespace(),new R(w.break,void 0,1);let e=this.parseString();if(this.skipWhitespace(),this.ch()!==58)throw new Error(`${G} unexpected character at position ${this._pos}, was expecting key/value delimiter ':' but found '${String.fromCharCode(this.ch())}'`);return this._pos++,this.modeStack.push("obj-value"),e}case"obj-value":return this.modeStack.pop(),this.modeStack.push("obj-key"),this.skipWhitespace(),this.parseValue();default:throw new Error(`${G} unexpected parse state at position ${this._pos}; this shouldn't happen`)}}};function Ks(r,e){return e=Object.assign({tokenizer:new Wn(r,e)},e),ut(r,e)}function bA(r){return r instanceof ArrayBuffer?new Uint8Array(r,0,r.byteLength):r}function vA(r){if(r.asCID!==r&&r["/"]!==r.bytes)return null;let e=F.asCID(r);if(!e)return null;let t=e.toString();return[new R(w.map,1/0,1),new R(w.string,"/",1),new R(w.string,t,t.length),new R(w.break,void 0,1)]}function bl(r){let e=yr.encode(r).slice(1);return[new R(w.map,1/0,1),new R(w.string,"/",1),new R(w.map,1/0,1),new R(w.string,"bytes",5),new R(w.string,e,e.length),new R(w.break,void 0,1),new R(w.break,void 0,1)]}function ar(r){return bl(new Uint8Array(r.buffer,r.byteOffset,r.byteLength))}function AA(r){return bl(new Uint8Array(r))}function _A(){throw new Error("`undefined` is not supported by the IPLD Data Model and cannot be encoded")}function SA(r){if(Number.isNaN(r))throw new Error("`NaN` is not supported by the IPLD Data Model and cannot be encoded");if(r===1/0||r===-1/0)throw new Error("`Infinity` and `-Infinity` is not supported by the IPLD Data Model and cannot be encoded");return null}var IA={typeEncoders:{Object:vA,Buffer:bl,Uint8Array:bl,Int8Array:ar,Uint16Array:ar,Int16Array:ar,Uint32Array:ar,Int32Array:ar,Float32Array:ar,Float64Array:ar,Uint8ClampedArray:ar,BigInt64Array:ar,BigUint64Array:ar,DataView:ar,ArrayBuffer:AA,undefined:_A,number:SA}},qf=class extends Wn{constructor(e,t){super(e,t),this.tokenBuffer=[]}done(){return this.tokenBuffer.length===0&&super.done()}_next(){return this.tokenBuffer.length>0?this.tokenBuffer.pop():super.next()}next(){let e=this._next();if(e.type===w.map){let t=this._next();if(t.type===w.string&&t.value==="/"){let n=this._next();if(n.type===w.string){if(this._next().type!==w.break)throw new Error("Invalid encoded CID form");return this.tokenBuffer.push(n),new R(w.tag,42,0)}if(n.type===w.map){let i=this._next();if(i.type===w.string&&i.value==="bytes"){let o=this._next();if(o.type===w.string){for(let a=0;a<2;a++)if(this._next().type!==w.break)throw new Error("Invalid encoded Bytes form");let s=yr.decode(`m${o.value}`);return new R(w.bytes,s,o.value.length)}this.tokenBuffer.push(o)}this.tokenBuffer.push(i)}this.tokenBuffer.push(n)}this.tokenBuffer.push(t)}return e}},Yf={allowIndefinite:!1,allowUndefined:!1,allowNaN:!1,allowInfinity:!1,allowBigInt:!0,strict:!0,useMaps:!1,rejectDuplicateMapKeys:!0,tags:[]};Yf.tags[42]=F.parse;var jn=297,sg=r=>zs(r,IA),vl=r=>{let e=bA(r),t=Object.assign(Yf,{tokenizer:new qf(e,Yf)});return Ks(e,t)};var XU=new TextDecoder;var ZU=new TextEncoder;var De={};Be(De,{code:()=>ve,createLink:()=>yg,createNode:()=>mg,decode:()=>Se,encode:()=>ce,name:()=>PA,prepare:()=>Te,validate:()=>Xf});var BA=new TextDecoder;function Wf(r,e){let t=0;for(let n=0;;n+=7){if(n>=64)throw new Error("protobuf: varint overflow");if(e>=r.length)throw new Error("protobuf: unexpected end of data");let i=r[e++];if(t+=n<28?(i&127)<<n:(i&127)*2**n,i<128)break}return[t,e]}function _l(r,e){let t;[t,e]=Wf(r,e);let n=e+t;if(t<0||n<0)throw new Error("protobuf: invalid length");if(n>r.length)throw new Error("protobuf: unexpected end of data");return[r.subarray(e,n),n]}function ag(r,e){let t;return[t,e]=Wf(r,e),[t&7,t>>3,e]}function kA(r){let e={},t=r.length,n=0;for(;n<t;){let i,o;if([i,o,n]=ag(r,n),o===1){if(e.Hash)throw new Error("protobuf: (PBLink) duplicate Hash section");if(i!==2)throw new Error(`protobuf: (PBLink) wrong wireType (${i}) for Hash`);if(e.Name!==void 0)throw new Error("protobuf: (PBLink) invalid order, found Name before Hash");if(e.Tsize!==void 0)throw new Error("protobuf: (PBLink) invalid order, found Tsize before Hash");[e.Hash,n]=_l(r,n)}else if(o===2){if(e.Name!==void 0)throw new Error("protobuf: (PBLink) duplicate Name section");if(i!==2)throw new Error(`protobuf: (PBLink) wrong wireType (${i}) for Name`);if(e.Tsize!==void 0)throw new Error("protobuf: (PBLink) invalid order, found Tsize before Name");let s;[s,n]=_l(r,n),e.Name=BA.decode(s)}else if(o===3){if(e.Tsize!==void 0)throw new Error("protobuf: (PBLink) duplicate Tsize section");if(i!==0)throw new Error(`protobuf: (PBLink) wrong wireType (${i}) for Tsize`);[e.Tsize,n]=Wf(r,n)}else throw new Error(`protobuf: (PBLink) invalid fieldNumber, expected 1, 2 or 3, got ${o}`)}if(n>t)throw new Error("protobuf: (PBLink) unexpected end of data");return e}function cg(r){let e=r.length,t=0,n,i=!1,o;for(;t<e;){let a,c;if([a,c,t]=ag(r,t),a!==2)throw new Error(`protobuf: (PBNode) invalid wireType, expected 2, got ${a}`);if(c===1){if(o)throw new Error("protobuf: (PBNode) duplicate Data section");[o,t]=_l(r,t),n&&(i=!0)}else if(c===2){if(i)throw new Error("protobuf: (PBNode) duplicate Links section");n||(n=[]);let u;[u,t]=_l(r,t),n.push(kA(u))}else throw new Error(`protobuf: (PBNode) invalid fieldNumber, expected 1 or 2, got ${c}`)}if(t>e)throw new Error("protobuf: (PBNode) unexpected end of data");let s={};return o&&(s.Data=o),s.Links=n||[],s}var ug=new TextEncoder,lg=2**32,RA=2**31;function TA(r,e){let t=e.length;if(typeof r.Tsize=="number"){if(r.Tsize<0)throw new Error("Tsize cannot be negative");if(!Number.isSafeInteger(r.Tsize))throw new Error("Tsize too large for encoding");t=Gs(e,t,r.Tsize)-1,e[t]=24}if(typeof r.Name=="string"){let n=ug.encode(r.Name);t-=n.length,e.set(n,t),t=Gs(e,t,n.length)-1,e[t]=18}return r.Hash&&(t-=r.Hash.length,e.set(r.Hash,t),t=Gs(e,t,r.Hash.length)-1,e[t]=10),e.length-t}function dg(r){let e=CA(r),t=new Uint8Array(e),n=e;if(r.Data&&(n-=r.Data.length,t.set(r.Data,n),n=Gs(t,n,r.Data.length)-1,t[n]=10),r.Links)for(let i=r.Links.length-1;i>=0;i--){let o=TA(r.Links[i],t.subarray(0,n));n-=o,n=Gs(t,n,o)-1,t[n]=18}return t}function NA(r){let e=0;if(r.Hash){let t=r.Hash.length;e+=1+t+To(t)}if(typeof r.Name=="string"){let t=ug.encode(r.Name).length;e+=1+t+To(t)}return typeof r.Tsize=="number"&&(e+=1+To(r.Tsize)),e}function CA(r){let e=0;if(r.Data){let t=r.Data.length;e+=1+t+To(t)}if(r.Links)for(let t of r.Links){let n=NA(t);e+=1+n+To(n)}return e}function Gs(r,e,t){e-=To(t);let n=e;for(;t>=RA;)r[e++]=t&127|128,t/=128;for(;t>=128;)r[e++]=t&127|128,t>>>=7;return r[e]=t,n}function To(r){return r%2===0&&r++,Math.floor((LA(r)+6)/7)}function LA(r){let e=0;return r>=lg&&(r=Math.floor(r/lg),e=32),r>=65536&&(r>>>=16,e+=16),r>=256&&(r>>>=8,e+=8),e+UA[r]}var UA=[0,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8];var DA=["Data","Links"],OA=["Hash","Name","Tsize"],jf=new TextEncoder;function hg(r,e){if(r===e)return 0;let t=r.Name?jf.encode(r.Name):[],n=e.Name?jf.encode(e.Name):[],i=t.length,o=n.length;for(let s=0,a=Math.min(i,o);s<a;++s)if(t[s]!==n[s]){i=t[s],o=n[s];break}return i<o?-1:o<i?1:0}function fg(r,e){return!Object.keys(r).some(t=>!e.includes(t))}function pg(r){if(typeof r.asCID=="object"){let t=F.asCID(r);if(!t)throw new TypeError("Invalid DAG-PB form");return{Hash:t}}if(typeof r!="object"||Array.isArray(r))throw new TypeError("Invalid DAG-PB form");let e={};if(r.Hash){let t=F.asCID(r.Hash);try{t||(typeof r.Hash=="string"?t=F.parse(r.Hash):r.Hash instanceof Uint8Array&&(t=F.decode(r.Hash)))}catch(n){throw new TypeError(`Invalid DAG-PB form: ${n.message}`)}t&&(e.Hash=t)}if(!e.Hash)throw new TypeError("Invalid DAG-PB form");return typeof r.Name=="string"&&(e.Name=r.Name),typeof r.Tsize=="number"&&(e.Tsize=r.Tsize),e}function Te(r){if((r instanceof Uint8Array||typeof r=="string")&&(r={Data:r}),typeof r!="object"||Array.isArray(r))throw new TypeError("Invalid DAG-PB form");let e={};if(r.Data!==void 0)if(typeof r.Data=="string")e.Data=jf.encode(r.Data);else if(r.Data instanceof Uint8Array)e.Data=r.Data;else throw new TypeError("Invalid DAG-PB form");if(r.Links!==void 0)if(Array.isArray(r.Links))e.Links=r.Links.map(pg),e.Links.sort(hg);else throw new TypeError("Invalid DAG-PB form");else e.Links=[];return e}function Xf(r){if(!r||typeof r!="object"||Array.isArray(r)||r instanceof Uint8Array||r["/"]&&r["/"]===r.bytes)throw new TypeError("Invalid DAG-PB form");if(!fg(r,DA))throw new TypeError("Invalid DAG-PB form (extraneous properties)");if(r.Data!==void 0&&!(r.Data instanceof Uint8Array))throw new TypeError("Invalid DAG-PB form (Data must be bytes)");if(!Array.isArray(r.Links))throw new TypeError("Invalid DAG-PB form (Links must be a list)");for(let e=0;e<r.Links.length;e++){let t=r.Links[e];if(!t||typeof t!="object"||Array.isArray(t)||t instanceof Uint8Array||t["/"]&&t["/"]===t.bytes)throw new TypeError("Invalid DAG-PB form (bad link)");if(!fg(t,OA))throw new TypeError("Invalid DAG-PB form (extraneous properties on link)");if(t.Hash===void 0)throw new TypeError("Invalid DAG-PB form (link must have a Hash)");if(t.Hash==null||!t.Hash["/"]||t.Hash["/"]!==t.Hash.bytes)throw new TypeError("Invalid DAG-PB form (link Hash must be a CID)");if(t.Name!==void 0&&typeof t.Name!="string")throw new TypeError("Invalid DAG-PB form (link Name must be a string)");if(t.Tsize!==void 0){if(typeof t.Tsize!="number"||t.Tsize%1!==0)throw new TypeError("Invalid DAG-PB form (link Tsize must be an integer)");if(t.Tsize<0)throw new TypeError("Invalid DAG-PB form (link Tsize cannot be negative)")}if(e>0&&hg(t,r.Links[e-1])===-1)throw new TypeError("Invalid DAG-PB form (links must be sorted by Name bytes)")}}function mg(r,e=[]){return Te({Data:r,Links:e})}function yg(r,e,t){return pg({Hash:t,Name:r,Tsize:e})}function gg(r){return r instanceof ArrayBuffer?new Uint8Array(r,0,r.byteLength):r}var PA="dag-pb",ve=112;function ce(r){Xf(r);let e={};return r.Links&&(e.Links=r.Links.map(t=>{let n={};return t.Hash&&(n.Hash=t.Hash.bytes),t.Name!==void 0&&(n.Name=t.Name),t.Tsize!==void 0&&(n.Tsize=t.Tsize),n})),r.Data&&(e.Data=r.Data),dg(e)}function Se(r){let e=gg(r),t=cg(e),n={};return t.Data&&(n.Data=t.Data),t.Links&&(n.Links=t.Links.map(i=>{let o={};try{o.Hash=F.decode(i.Hash)}catch{}if(!o.Hash)throw new Error("Invalid Hash field found in link, expected CID");return i.Name!==void 0&&(o.Name=i.Name),i.Tsize!==void 0&&(o.Tsize=i.Tsize),o})),n}var FA={codec:ve,*walk(r){yield*Se(r).Links.map(t=>t.Hash)}},VA={codec:Ae,*walk(){}},wg=42,MA={codec:Yn,*walk(r){let e=[],t=[];t[wg]=n=>{if(n[0]!==0)throw new Error("Invalid CID for CBOR tag 42; expected leading 0x00");let i=F.decode(n.subarray(1));return e.push(i),i},ut(r,{tags:t}),yield*e}},Zf=class extends Wn{tokenBuffer;constructor(e,t){super(e,t),this.tokenBuffer=[]}done(){return this.tokenBuffer.length===0&&super.done()}_next(){return this.tokenBuffer.length>0?this.tokenBuffer.pop():super.next()}next(){let e=this._next();if(e.type===w.map){let t=this._next();if(t.type===w.string&&t.value==="/"){let n=this._next();if(n.type===w.string){if(this._next().type!==w.break)throw new Error("Invalid encoded CID form");return this.tokenBuffer.push(n),new R(w.tag,42,0)}if(n.type===w.map){let i=this._next();if(i.type===w.string&&i.value==="bytes"){let o=this._next();if(o.type===w.string){for(let a=0;a<2;a++)if(this._next().type!==w.break)throw new Error("Invalid encoded Bytes form");let s=yr.decode(`m${o.value}`);return new R(w.bytes,s,o.value.length)}this.tokenBuffer.push(o)}this.tokenBuffer.push(i)}this.tokenBuffer.push(n)}this.tokenBuffer.push(t)}return e}},HA={codec:jn,*walk(r){let e=[],t=[];t[wg]=n=>{let i=F.parse(n);return e.push(i),i},Ks(r,{tags:t,tokenizer:new Zf(r,{tags:t,allowIndefinite:!0,allowUndefined:!0,allowNaN:!0,allowInfinity:!0,allowBigInt:!0,strict:!1,rejectDuplicateMapKeys:!1})}),yield*e}},$A={codec:Rn,*walk(){}};function Eg(r=[]){let e={};return[FA,VA,MA,HA,$A,...r].forEach(t=>{e[t.codec]=t}),e}var Jf=new Fe("/version"),xg=1;async function bg(r){if(!await r.has(Jf)){await r.put(Jf,H(`${xg}`));return}let e=await r.get(Jf),t=J(e);if(parseInt(t,10)!==xg)throw new Error("Unknown datastore version, a datastore migration may be required")}function vg(r=[]){let e={};return[fe,Lu,et,...r].forEach(t=>{e[t.code]=t}),e}var Sr=class{has(e,t){return Promise.reject(new Error(".has is not implemented"))}put(e,t,n){return Promise.reject(new Error(".put is not implemented"))}async*putMany(e,t){for await(let{cid:n,block:i}of e)await this.put(n,i,t),yield n}get(e,t){return Promise.reject(new Error(".get is not implemented"))}async*getMany(e,t){for await(let n of e)yield{cid:n,block:await this.get(n,t)}}delete(e,t){return Promise.reject(new Error(".delete is not implemented"))}async*deleteMany(e,t){for await(let n of e)await this.delete(n,t),yield n}async*getAll(e){throw new Error(".getAll is not implemented")}};var Bi={};Be(Bi,{abortedError:()=>YA,closeFailedError:()=>KA,deleteFailedError:()=>eh,getFailedError:()=>GA,hasFailedError:()=>qA,notFoundError:()=>Xn,openFailedError:()=>zA,putFailedError:()=>Qf});var an=Q(Ce(),1);function zA(r){return r=r??new Error("Open failed"),(0,an.default)(r,"ERR_OPEN_FAILED")}function KA(r){return r=r??new Error("Close failed"),(0,an.default)(r,"ERR_CLOSE_FAILED")}function Qf(r){return r=r??new Error("Put failed"),(0,an.default)(r,"ERR_PUT_FAILED")}function GA(r){return r=r??new Error("Get failed"),(0,an.default)(r,"ERR_GET_FAILED")}function eh(r){return r=r??new Error("Delete failed"),(0,an.default)(r,"ERR_DELETE_FAILED")}function qA(r){return r=r??new Error("Has failed"),(0,an.default)(r,"ERR_HAS_FAILED")}function Xn(r){return r=r??new Error("Not Found"),(0,an.default)(r,"ERR_NOT_FOUND")}function YA(r){return r=r??new Error("Aborted"),(0,an.default)(r,"ERR_ABORTED")}var Ag=0,Sl=class extends Sr{put(e){return e}get(e){if(e.code===Ag)return e.multihash.digest;throw Xn()}has(e){return e.code===Ag}delete(){}*getAll(){}};function WA(r){return r[Symbol.asyncIterator]!=null}function jA(r,e){if(WA(r))return async function*(){for await(let a of r)await e(a)&&(yield a)}();let t=Mi(r),{value:n,done:i}=t.next();if(i===!0)return function*(){}();let o=e(n);if(typeof o.then=="function")return async function*(){await o&&(yield n);for await(let a of t)await e(a)&&(yield a)}();let s=e;return function*(){o===!0&&(yield n);for(let a of t)s(a)&&(yield a)}()}var bt=jA;var XA=oe("blockstore:core:tiered"),qs=class extends Sr{stores;constructor(e){super(),this.stores=e.slice()}async put(e,t,n){try{return await Promise.all(this.stores.map(async i=>{await i.put(e,t,n)})),e}catch(i){throw Qf(i)}}async get(e,t){for(let n of this.stores)try{let i=await n.get(e,t);if(i!=null)return i}catch(i){XA.error(i)}throw Xn()}async has(e,t){for(let n of this.stores)if(await n.has(e,t))return!0;return!1}async delete(e,t){try{await Promise.all(this.stores.map(async n=>{await n.delete(e,t)}))}catch(n){throw eh(n)}}async*putMany(e,t={}){let n,i=this.stores.map(o=>{let s=zt({objectMode:!0});return Zt(o.putMany(s,t)).catch(a=>{n=a}),s});try{for await(let o of e){if(n!=null)throw n;i.forEach(s=>s.push(o)),yield o.cid}}finally{i.forEach(o=>o.end())}}async*deleteMany(e,t={}){let n,i=this.stores.map(o=>{let s=zt({objectMode:!0});return Zt(o.deleteMany(s,t)).catch(a=>{n=a}),s});try{for await(let o of e){if(n!=null)throw n;i.forEach(s=>s.push(o)),yield o}}finally{i.forEach(o=>o.end())}}async*getAll(e){let t=new Set;yield*bt(Hr(...this.stores.map(n=>n.getAll(e))),n=>{let i=n.cid.toString();return t.has(i)?!1:(t.add(i),!0)})}};function ZA(r){return typeof r.retrieve=="function"}function JA(r){return typeof r.announce=="function"}var Il=class{child;blockRetrievers;blockAnnouncers;hashers;started;log;constructor(e){this.log=e.logger.forComponent("helia:networked-storage"),this.child=new qs([new Sl,e.blockstore]),this.blockRetrievers=(e.blockBrokers??[]).filter(ZA),this.blockAnnouncers=(e.blockBrokers??[]).filter(JA),this.hashers=e.hashers??{},this.started=!1}isStarted(){return this.started}async start(){await _n(this.child,...new Set([...this.blockRetrievers,...this.blockAnnouncers])),this.started=!0}async stop(){await Sn(this.child,...new Set([...this.blockRetrievers,...this.blockAnnouncers])),this.started=!1}unwrap(){return this.child}async put(e,t,n={}){return await this.child.has(e)?(n.onProgress?.(new V("blocks:put:duplicate",e)),e):(n.onProgress?.(new V("blocks:put:providers:notify",e)),this.blockAnnouncers.forEach(i=>{i.announce(e,t,n)}),n.onProgress?.(new V("blocks:put:blockstore:put",e)),this.child.put(e,t,n))}async*putMany(e,t={}){let n=bt(e,async({cid:o})=>{let s=await this.child.has(o);return s&&t.onProgress?.(new V("blocks:put-many:duplicate",o)),!s}),i=wu(n,({cid:o,block:s})=>{t.onProgress?.(new V("blocks:put-many:providers:notify",o)),this.blockAnnouncers.forEach(a=>{a.announce(o,s,t)})});t.onProgress?.(new V("blocks:put-many:blockstore:put-many")),yield*this.child.putMany(i,t)}async get(e,t={}){if(t.offline!==!0&&!await this.child.has(e)){t.onProgress?.(new V("blocks:get:providers:get",e));let n=await _g(e,this.blockRetrievers,this.hashers[e.multihash.code],{...t,log:this.log});return t.onProgress?.(new V("blocks:get:blockstore:put",e)),await this.child.put(e,n,t),t.onProgress?.(new V("blocks:get:providers:notify",e)),this.blockAnnouncers.forEach(i=>{i.announce(e,n,t)}),n}return t.onProgress?.(new V("blocks:get:blockstore:get",e)),this.child.get(e,t)}async*getMany(e,t={}){t.onProgress?.(new V("blocks:get-many:blockstore:get-many")),yield*this.child.getMany(wu(e,async n=>{if(t.offline!==!0&&!await this.child.has(n)){t.onProgress?.(new V("blocks:get-many:providers:get",n));let i=await _g(n,this.blockRetrievers,this.hashers[n.multihash.code],{...t,log:this.log});t.onProgress?.(new V("blocks:get-many:blockstore:put",n)),await this.child.put(n,i,t),t.onProgress?.(new V("blocks:get-many:providers:notify",n)),this.blockAnnouncers.forEach(o=>{o.announce(n,i,t)})}}))}async delete(e,t={}){t.onProgress?.(new V("blocks:delete:blockstore:delete",e)),await this.child.delete(e,t)}async*deleteMany(e,t={}){t.onProgress?.(new V("blocks:delete-many:blockstore:delete-many")),yield*this.child.deleteMany(async function*(){for await(let n of e)yield n}(),t)}async has(e,t={}){return this.child.has(e,t)}async*getAll(e={}){e.onProgress?.(new V("blocks:get-all:blockstore:get-many")),yield*this.child.getAll(e)}},QA=(r,e)=>{if(e==null)throw new O(`No hasher configured for multihash code 0x${r.multihash.code.toString(16)}, please configure one. You can look up which hash this is at https://github.com/multiformats/multicodec/blob/master/table.csv`,"ERR_UNKNOWN_HASH_ALG");return async t=>{let n=await e.digest(t);if(!he(n.digest,r.multihash.digest))throw new O("Hash of downloaded block did not match multihash from passed CID","ERR_HASH_MISMATCH")}};async function _g(r,e,t,n){let i=QA(r,t),o=new AbortController,s=ci([o.signal,n.signal]);try{return await Promise.any(e.map(async a=>{try{let c=!1,u=await a.retrieve(r,{...n,signal:s,validateFn:async l=>{await i(l),c=!0}});return c||await i(u),u}catch(c){throw n.log.error("could not retrieve verified block for %c",r,c),c}}))}finally{s.clear()}}var Bl=class{blockstore;datastore;pins;logger;routing;dagWalkers;hashers;log;constructor(e){this.logger=e.logger??$0(),this.log=this.logger.forComponent("helia"),this.hashers=vg(e.hashers),this.dagWalkers=Eg(e.dagWalkers);let t={blockstore:e.blockstore,datastore:e.datastore,hashers:this.hashers,dagWalkers:this.dagWalkers,logger:this.logger,blockBrokers:[],...e.components??{}};t.blockBrokers=e.blockBrokers.map(i=>i(t));let n=new Il(t);this.pins=new gl(e.datastore,n,this.dagWalkers),this.blockstore=new El(n,this.pins,{holdGcLock:e.holdGcLock??!0}),this.datastore=e.datastore,this.routing=new wl(t,{routers:(e.routers??[]).flatMap(i=>{let o=[i];return i[es]!=null&&o.push(i[es]),i[ts]!=null&&o.push(i[ts]),o})})}async start(){await bg(this.datastore),await _n(this.blockstore,this.datastore,this.routing)}async stop(){await Sn(this.blockstore,this.datastore,this.routing)}async gc(e={}){let t=await this.blockstore.lock.writeLock();try{let n=this,i=this.blockstore.unwrap();this.log("gc start"),await Zt(i.deleteMany(async function*(){for await(let{cid:o}of i.getAll())try{if(await n.pins.isPinned(o,e))continue;yield o,e.onProgress?.(new V("helia:gc:deleted",o))}catch(s){n.log.error("Error during gc",s),e.onProgress?.(new V("helia:gc:error",s))}}()))}finally{t()}this.log("gc finished")}};var Ys=class extends Sr{data;constructor(){super(),this.data=new Map}put(e,t){return this.data.set(qe.encode(e.multihash.bytes),t),e}get(e){let t=this.data.get(qe.encode(e.multihash.bytes));if(t==null)throw Xn();return t}has(e){return this.data.has(qe.encode(e.multihash.bytes))}async delete(e){this.data.delete(qe.encode(e.multihash.bytes))}async*getAll(){for(let[e,t]of this.data.entries())yield{cid:F.createV1(Ae,st(qe.decode(e))),block:t}}};var nO={...Bi};var Sg=Q(Ce(),1);function kl(r){return r=r??new Error("Not Found"),(0,Sg.default)(r,"ERR_NOT_FOUND")}var Ig="SHARDING";function t_(r){return r[Symbol.asyncIterator]!=null}function r_(r){if(t_(r))return(async()=>{let t=[];for await(let n of r)t.push(n);return t})();let e=[];for(let t of r)e.push(t);return e}var Rl=r_;function n_(r){return r[Symbol.asyncIterator]!=null}function i_(r,e){return n_(r)?async function*(){yield*(await Rl(r)).sort(e)}():function*(){yield*Rl(r).sort(e)}()}var Tl=i_;var cn=class{put(e,t,n){return Promise.reject(new Error(".put is not implemented"))}get(e,t){return Promise.reject(new Error(".get is not implemented"))}has(e,t){return Promise.reject(new Error(".has is not implemented"))}delete(e,t){return Promise.reject(new Error(".delete is not implemented"))}async*putMany(e,t={}){for await(let{key:n,value:i}of e)await this.put(n,i,t),yield n}async*getMany(e,t={}){for await(let n of e)yield{key:n,value:await this.get(n,t)}}async*deleteMany(e,t={}){for await(let n of e)await this.delete(n,t),yield n}batch(){let e=[],t=[];return{put(n,i){e.push({key:n,value:i})},delete(n){t.push(n)},commit:async n=>{await Zt(this.putMany(e,n)),e=[],await Zt(this.deleteMany(t,n)),t=[]}}}async*_all(e,t){throw new Error("._all is not implemented")}async*_allKeys(e,t){throw new Error("._allKeys is not implemented")}query(e,t){let n=this._all(e,t);if(e.prefix!=null){let i=e.prefix;n=bt(n,o=>o.key.toString().startsWith(i))}if(Array.isArray(e.filters)&&(n=e.filters.reduce((i,o)=>bt(i,o),n)),Array.isArray(e.orders)&&(n=e.orders.reduce((i,o)=>Tl(i,o),n)),e.offset!=null){let i=0,o=e.offset;n=bt(n,()=>i++>=o)}return e.limit!=null&&(n=Ua(n,e.limit)),n}queryKeys(e,t){let n=this._allKeys(e,t);if(e.prefix!=null){let i=e.prefix;n=bt(n,o=>o.toString().startsWith(i))}if(Array.isArray(e.filters)&&(n=e.filters.reduce((i,o)=>bt(i,o),n)),Array.isArray(e.orders)&&(n=e.orders.reduce((i,o)=>Tl(i,o),n)),e.offset!=null){let i=e.offset,o=0;n=bt(n,()=>o++>=i)}return e.limit!=null&&(n=Ua(n,e.limit)),n}};var js=class extends cn{data;constructor(){super(),this.data=new Map}put(e,t){return this.data.set(e.toString(),t),e}get(e){let t=this.data.get(e.toString());if(t==null)throw kl();return t}has(e){return this.data.has(e.toString())}delete(e){this.data.delete(e.toString())}*_all(){for(let[e,t]of this.data.entries())yield{key:new Fe(e),value:t}}*_allKeys(){for(let e of this.data.keys())yield new Fe(e)}};var NO=new Fe(Ig);var zO=oe("datastore:core:tiered");async function kg(r={}){let e=r.datastore??new js,t=r.blockstore??new Ys,n=new Bl({...r,datastore:e,blockstore:t,blockBrokers:r.blockBrokers??[is()],routers:r.routers??[Vs("https://delegated-ipfs.dev")]});return r.start!==!1&&await n.start(),n}var th=Q(Ba(),1);var rh=40;function nh(r,e){if(!r.length)throw new Error("Unexpected end of data");let t=th.default.decode(r);return e.seek(th.default.decode.bytes),t}function ih(r){let e=new DataView(r.buffer,r.byteOffset,r.byteLength),t=0;return{version:2,characteristics:[e.getBigUint64(t,!0),e.getBigUint64(t+=8,!0)],dataOffset:Number(e.getBigUint64(t+=8,!0)),dataSize:Number(e.getBigUint64(t+=8,!0)),indexOffset:Number(e.getBigUint64(t+=8,!0))}}var Zn={Null:r=>r===null?r:void 0,Int:r=>Number.isInteger(r)?r:void 0,Float:r=>typeof r=="number"&&Number.isFinite(r)?r:void 0,String:r=>typeof r=="string"?r:void 0,Bool:r=>typeof r=="boolean"?r:void 0,Bytes:r=>r instanceof Uint8Array?r:void 0,Link:r=>r!==null&&typeof r=="object"&&r.asCID===r?r:void 0,List:r=>Array.isArray(r)?r:void 0,Map:r=>r!==null&&typeof r=="object"&&r.asCID!==r&&!Array.isArray(r)&&!(r instanceof Uint8Array)?r:void 0},Xs={"CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)":Zn.Link,"CarV1HeaderOrV2Pragma > roots (anon)":r=>{if(Zn.List(r)!==void 0){for(let e=0;e<r.length;e++){let t=r[e];if(t=Xs["CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)"](t),t===void 0)return;if(t!==r[e]){let n=r.slice(0,e);for(let i=e;i<r.length;i++){let o=r[i];if(o=Xs["CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)"](o),o===void 0)return;n.push(o)}return n}}return r}},Int:Zn.Int,CarV1HeaderOrV2Pragma:r=>{if(Zn.Map(r)===void 0)return;let e=Object.entries(r),t=r,n=1;for(let i=0;i<e.length;i++){let[o,s]=e[i];switch(o){case"roots":{let a=Xs["CarV1HeaderOrV2Pragma > roots (anon)"](r[o]);if(a===void 0)return;if(a!==s||t!==r){if(t===r){t={};for(let c=0;c<i;c++)t[e[c][0]]=e[c][1]}t.roots=a}}break;case"version":{n--;let a=Xs.Int(r[o]);if(a===void 0)return;if(a!==s||t!==r){if(t===r){t={};for(let c=0;c<i;c++)t[e[c][0]]=e[c][1]}t.version=a}}break;default:return}}if(!(n>0))return t}},Zs={"CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)":Zn.Link,"CarV1HeaderOrV2Pragma > roots (anon)":r=>{if(Zn.List(r)!==void 0){for(let e=0;e<r.length;e++){let t=r[e];if(t=Zs["CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)"](t),t===void 0)return;if(t!==r[e]){let n=r.slice(0,e);for(let i=e;i<r.length;i++){let o=r[i];if(o=Zs["CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)"](o),o===void 0)return;n.push(o)}return n}}return r}},Int:Zn.Int,CarV1HeaderOrV2Pragma:r=>{if(Zn.Map(r)===void 0)return;let e=Object.entries(r),t=r,n=1;for(let i=0;i<e.length;i++){let[o,s]=e[i];switch(o){case"roots":{let a=Zs["CarV1HeaderOrV2Pragma > roots (anon)"](s);if(a===void 0)return;if(a!==s||t!==r){if(t===r){t={};for(let c=0;c<i;c++)t[e[c][0]]=e[c][1]}t.roots=a}}break;case"version":{n--;let a=Zs.Int(s);if(a===void 0)return;if(a!==s||t!==r){if(t===r){t={};for(let c=0;c<i;c++)t[e[c][0]]=e[c][1]}t.version=a}}break;default:return}}if(!(n>0))return t}},oh={toTyped:Xs.CarV1HeaderOrV2Pragma,toRepresentation:Zs.CarV1HeaderOrV2Pragma};var IP=xf();var u_=Q(Ba(),1);var NP=[new R(w.map,2),new R(w.string,"version"),new R(w.uint,1),new R(w.string,"roots")],CP=new R(w.tag,42);async function sh(r,e){let t=nh(await r.upTo(8),r);if(t===0)throw new Error("Invalid CAR header (zero length)");let n=await r.exactly(t,!0),i=Ii(n);if(oh.toTyped(i)===void 0)throw new Error("Invalid CAR header format");if(i.version!==1&&i.version!==2||e!==void 0&&i.version!==e)throw new Error(`Invalid CAR version: ${i.version}${e!==void 0?` (expected ${e})`:""}`);if(i.version===1){if(!Array.isArray(i.roots))throw new Error("Invalid CAR header format");return i}if(i.roots!==void 0)throw new Error("Invalid CAR header format");let o=ih(await r.exactly(rh,!0));r.seek(o.dataOffset-r.pos);let s=await sh(r,1);return Object.assign(s,o)}function Js(r){let e=0;return{async upTo(t){return r.subarray(e,e+Math.min(t,r.length-e))},async exactly(t,n=!1){if(t>r.length-e)throw new Error("Unexpected end of data");let i=r.subarray(e,e+t);return n&&(e+=t),i},seek(t){e+=t},get pos(){return e}}}var ah=Q(Ba(),1);function ch(r){let e=Hs({version:1,roots:r}),t=ah.default.encode(e.length),n=new Uint8Array(t.length+e.length);return n.set(t,0),n.set(e,t.length),n}function Ng(r){return{async setRoots(e){let t=ch(e);await r.write(t)},async writeBlock(e){let{cid:t,bytes:n}=e;await r.write(new Uint8Array(ah.default.encode(t.bytes.length+n.length))),await r.write(t.bytes),n.length&&await r.write(n)},async close(){await r.end()}}}function Nl(){}function Cg(){let r=[],e=null,t=Nl,n=!1,i=null,o=Nl,s=()=>(e||(e=new Promise(u=>{t=()=>{e=null,t=Nl,u()}})),e),a={write(u){r.push(u);let l=s();return o(),l},async end(){n=!0;let u=s();o(),await u}},c={async next(){let u=r.shift();return u?(r.length===0&&t(),{done:!1,value:u}):n?(t(),{done:!0,value:void 0}):(i||(i=new Promise(l=>{o=()=>(i=null,o=Nl,l(c.next()))})),i)}};return{writer:a,iterator:c}}var Qs=class r{constructor(e,t){this._encoder=t,this._mutex=t.setRoots(e),this._ended=!1}async put(e){if(!(e.bytes instanceof Uint8Array)||!e.cid)throw new TypeError("Can only write {cid, bytes} objects");if(this._ended)throw new Error("Already closed");let t=F.asCID(e.cid);if(!t)throw new TypeError("Can only write {cid, bytes} objects");return this._mutex=this._mutex.then(()=>this._encoder.writeBlock({cid:t,bytes:e.bytes})),this._mutex}async close(){if(this._ended)throw new Error("Already closed");return await this._mutex,this._ended=!0,this._encoder.close()}static create(e){e=p_(e);let{encoder:t,iterator:n}=Lg(),i=new r(e,t),o=new Cl(n);return{writer:i,out:o}}static createAppender(){let{encoder:e,iterator:t}=Lg();e.setRoots=()=>Promise.resolve();let n=new r([],e),i=new Cl(t);return{writer:n,out:i}}static async updateRootsInBytes(e,t){let n=Js(e);await sh(n);let i=ch(t);if(Number(n.pos)!==i.length)throw new Error(`updateRoots() can only overwrite a header of the same length (old header is ${n.pos} bytes, new header is ${i.length} bytes)`);return e.set(i,0),e}},Cl=class{constructor(e){this._iterator=e}[Symbol.asyncIterator](){if(this._iterating)throw new Error("Multiple iterator not supported");return this._iterating=!0,this._iterator}};function Lg(){let r=Cg(),{writer:e,iterator:t}=r;return{encoder:Ng(e),iterator:t}}function p_(r){if(r===void 0)return[];if(!Array.isArray(r)){let t=F.asCID(r);if(!t)throw new TypeError("roots must be a single CID or an array of CIDs");return[t]}let e=[];for(let t of r){let n=F.asCID(t);if(!n)throw new TypeError("roots must be a single CID or an array of CIDs");e.push(n)}return e}var m_=1,lh=class{components;constructor(e,t){this.components=e}async import(e,t){await Zt(this.components.blockstore.putMany(at(e.blocks(),({cid:n,bytes:i})=>({cid:n,block:i})),t))}async export(e,t,n){let i=_e(),o=Array.isArray(e)?e:[e],s=new nt({concurrency:m_});s.on("idle",()=>{i.resolve()}),s.on("error",a=>{s.clear(),i.reject(a)});for(let a of o)s.add(async()=>{await this.#e(a,s,async(c,u)=>{await t.put({cid:c,bytes:u})},n)}).catch(()=>{});try{await i.promise}finally{await t.close()}}async*stream(e,t){let{writer:n,out:i}=Qs.create(e);this.export(e,n,t).catch(()=>{});for await(let o of i)yield o}async#e(e,t,n,i){let o=this.components.dagWalkers[e.code];if(o==null)throw new Error(`No dag walker found for cid codec ${e.code}`);let s=await this.components.blockstore.get(e,i);await n(e,s);for await(let a of o.walk(s))t.add(async()=>{await this.#e(a,t,n,i)})}};function Ug(r,e={}){return new lh(r,e)}var uh=Q(Yc(),1);function Dg(r,e){let t=e.map((n,i)=>({record:dt(n),index:i}));return t.sort((n,i)=>{let o=n.record.sequence,s=i.record.sequence;if(o>s)return-1;if(o<s)return 1;if(n.record.validityType===We.ValidityType.EOL&&i.record.validityType===We.ValidityType.EOL){let a=uh.default.fromString(n.record.validity).toDate(),c=uh.default.fromString(i.record.validity).toDate();if(a.getTime()>c.getTime())return-1;if(a.getTime()<c.getTime())return 1}return 0}),t[0].index}var y_=r=>{let e=r.data;return e.startsWith('"')&&(e=e.substring(1)),e.endsWith('"')&&(e=e.substring(0,e.length-1)),e.replace("dnslink=","")},dh=(r,e)=>{let t=g_(r,e);return{ipfsPath:y_(t),answer:t}},g_=(r,e)=>{let t=e.Answer?.filter(n=>n.data.includes("dnslink=/ipfs")||n.data.includes("dnslink=/ipns")).pop();if(t==null)throw new O(`No dnslink records found for domain: ${r}`,"ERR_DNSLINK_NOT_FOUND");return t},ea=32,No=async(r,e,t,n={})=>{if(e===0)throw new Error("recursion limit exceeded");let i;try{i=await t(r,n)}catch(a){if(a.code!=="ENOTFOUND"&&a.code!=="ERR_DNSLINK_NOT_FOUND"&&a.code!=="ENODATA")throw a;r.startsWith("_dnslink.")?r=r.replace("_dnslink.",""):r=`_dnslink.${r}`,i=await t(r,n)}let o=i.replace("dnslink=",""),s=o.split("/")[2];try{return F.parse(s),o}catch{}return No(s,e-1,t,n)},w_=/^dnslink=.+$/,Og=async(r,e)=>{let i=(await r.resolveTxt(e)).flat().filter(o=>w_.test(o))[0];if(i==null)throw new O(`No dnslink records found for domain: ${e}`,"ERR_DNSLINK_NOT_FOUND");return i};var hh=Q(Ou(),1),ph=Q(Vg(),1);function Ll(r,e,t){return`${r}?name=${e}&type=${t}`}async function Mg(r,e){return await(await fetch(r,{headers:new Headers({accept:"application/dns-json"}),signal:e})).json()}function ki(r,e){return`${e}_${r}`}var fh=Object.assign((0,hh.default)("dns-over-http-resolver"),{error:(0,hh.default)("dns-over-http-resolver:error")}),mh=class{_cache;_TXTcache;_servers;_request;_abortControllers;constructor(e={}){this._cache=new ph.default({max:e?.maxCache??100}),this._TXTcache=new ph.default({max:e?.maxCache??100}),this._servers=["https://cloudflare-dns.com/dns-query","https://dns.google/resolve"],this._request=e.request??Mg,this._abortControllers=[]}cancel(){this._abortControllers.forEach(e=>{e.abort()})}getServers(){return this._servers}_getShuffledServers(){let e=[...this._servers];for(let t=e.length-1;t>0;t--){let n=Math.floor(Math.random()*t),i=e[t];e[t]=e[n],e[n]=i}return e}setServers(e){this._servers=e}async resolve(e,t="A"){switch(t){case"A":return this.resolve4(e);case"AAAA":return this.resolve6(e);case"TXT":return this.resolveTxt(e);default:throw new Error(`${t} is not supported`)}}async resolve4(e){let t="A",n=this._cache.get(ki(e,t));if(n!=null)return n;let i=!1;for(let o of this._getShuffledServers()){let s=new AbortController;this._abortControllers.push(s);try{let a=await this._request(Ll(o,e,t),s.signal),c=a.Answer.map(l=>l.data),u=Math.min(...a.Answer.map(l=>l.TTL));return this._cache.set(ki(e,t),c,{ttl:u}),c}catch{s.signal.aborted&&(i=!0),fh.error(`${o} could not resolve ${e} record ${t}`)}finally{this._abortControllers=this._abortControllers.filter(a=>a!==s)}}throw i?Object.assign(new Error("queryA ECANCELLED"),{code:"ECANCELLED"}):new Error(`Could not resolve ${e} record ${t}`)}async resolve6(e){let t="AAAA",n=this._cache.get(ki(e,t));if(n!=null)return n;let i=!1;for(let o of this._getShuffledServers()){let s=new AbortController;this._abortControllers.push(s);try{let a=await this._request(Ll(o,e,t),s.signal),c=a.Answer.map(l=>l.data),u=Math.min(...a.Answer.map(l=>l.TTL));return this._cache.set(ki(e,t),c,{ttl:u}),c}catch{s.signal.aborted&&(i=!0),fh.error(`${o} could not resolve ${e} record ${t}`)}finally{this._abortControllers=this._abortControllers.filter(a=>a!==s)}}throw i?Object.assign(new Error("queryAaaa ECANCELLED"),{code:"ECANCELLED"}):new Error(`Could not resolve ${e} record ${t}`)}async resolveTxt(e){let t="TXT",n=this._TXTcache.get(ki(e,t));if(n!=null)return n;let i=!1;for(let o of this._getShuffledServers()){let s=new AbortController;this._abortControllers.push(s);try{let a=await this._request(Ll(o,e,t),s.signal),c=a.Answer.map(l=>[l.data.replace(/['"]+/g,"")]),u=Math.min(...a.Answer.map(l=>l.TTL));return this._TXTcache.set(ki(e,t),c,{ttl:u}),c}catch{s.signal.aborted&&(i=!0),fh.error(`${o} could not resolve ${e} record ${t}`)}finally{this._abortControllers=this._abortControllers.filter(a=>a!==s)}}throw i?Object.assign(new Error("queryTxt ECANCELLED"),{code:"ECANCELLED"}):new Error(`Could not resolve ${e} record ${t}`)}clearCache(){this._cache.clear(),this._TXTcache.clear()}},Hg=mh;var zg=Q(yh(),1),Qn=class{lru;constructor(e){this.lru=(0,zg.default)(e)}get(e){let t=this.lru.get(e);if(t!=null){if(t.expire!=null&&t.expire<Date.now()){this.lru.remove(e);return}return t.value}}set(e,t,n){this.lru.set(e,{value:t,expire:Date.now()+n})}has(e){return this.get(e)!=null}remove(e){this.lru.remove(e)}clear(){this.lru.clear()}};var gh=new Qn(1e3),A_=60*1e3,__=new nt({concurrency:4}),S_=async function(e,t={}){let n=new Hg({maxCache:0});if(t.nocache!==!0&&gh.has(e)){let o=gh.get(e);if(o!=null)return t?.onProgress?.(new V("dnslink:cache",{detail:o})),o}t.onProgress?.(new V("dnslink:query",{detail:e}));let i=await __.add(async()=>{let o=await Og(n,e);return t.onProgress?.(new V("dnslink:answer",{detail:o})),gh.set(e,o,A_),o},{signal:t?.signal});if(i==null)throw new Error("No DNS response received");return i},Kg=S_;function Gg(){return async(r,e={})=>No(r,ea,Kg,e)}var wh=class{routing;constructor(e){this.routing=e}async put(e,t,n={}){try{await this.routing.put(e,t,n)}catch(i){n.onProgress?.(new V("ipns:routing:helia:error",i))}}async get(e,t={}){try{return await this.routing.get(e,t)}catch(n){t.onProgress?.(new V("ipns:routing:helia:error",n))}throw new Error("Not found")}};function qg(r){return new wh(r)}var Ul=globalThis.CustomEvent??Event;async function*Ri(r,e={}){let t=e.concurrency??1/0;t<1&&(t=1/0);let n=e.ordered==null?!1:e.ordered,i=new EventTarget,o=[],s=_e(),a=_e(),c=!1,u,l=!1;i.addEventListener("task-complete",()=>{a.resolve()}),Promise.resolve().then(async()=>{try{for await(let h of r){if(o.length===t&&(s=_e(),await s.promise),l)break;let m={done:!1};o.push(m),h().then(y=>{m.done=!0,m.ok=!0,m.value=y,i.dispatchEvent(new Ul("task-complete"))},y=>{m.done=!0,m.err=y,i.dispatchEvent(new Ul("task-complete"))})}c=!0,i.dispatchEvent(new Ul("task-complete"))}catch(h){u=h,i.dispatchEvent(new Ul("task-complete"))}});function d(){return n?o[0]?.done:!!o.find(h=>h.done)}function*p(){for(;o.length>0&&o[0].done;){let h=o[0];if(o.shift(),h.ok)yield h.value;else throw l=!0,s.resolve(),h.err;s.resolve()}}function*f(){for(;d();)for(let h=0;h<o.length;h++)if(o[h].done){let m=o[h];if(o.splice(h,1),h--,m.ok)yield m.value;else throw l=!0,s.resolve(),m.err;s.resolve()}}for(;;){if(d()||(a=_e(),await a.promise),u!=null)throw u;if(n?yield*p():yield*f(),c&&o.length===0)break}}var ta;(function(r){let e;r.codec=()=>(e==null&&(e=Ht((t,n,i={})=>{i.lengthDelimited!==!1&&n.fork(),t.key!=null&&t.key.byteLength>0&&(n.uint32(10),n.bytes(t.key)),t.value!=null&&t.value.byteLength>0&&(n.uint32(18),n.bytes(t.value)),t.timeReceived!=null&&t.timeReceived!==""&&(n.uint32(42),n.string(t.timeReceived)),i.lengthDelimited!==!1&&n.ldelim()},(t,n)=>{let i={key:new Uint8Array(0),value:new Uint8Array(0),timeReceived:""},o=n==null?t.len:t.pos+n;for(;t.pos<o;){let s=t.uint32();switch(s>>>3){case 1:i.key=t.bytes();break;case 2:i.value=t.bytes();break;case 5:i.timeReceived=t.string();break;default:t.skipType(s&7);break}}return i})),e),r.encode=t=>Mt(t,r.codec()),r.decode=t=>Ft(t,r.codec())})(ta||(ta={}));function Yg(r){let e=r.getUTCFullYear(),t=String(r.getUTCMonth()+1).padStart(2,"0"),n=String(r.getUTCDate()).padStart(2,"0"),i=String(r.getUTCHours()).padStart(2,"0"),o=String(r.getUTCMinutes()).padStart(2,"0"),s=String(r.getUTCSeconds()).padStart(2,"0"),a=r.getUTCMilliseconds(),c=String(a*1e3*1e3).padStart(9,"0");return`${e}-${t}-${n}T${i}:${o}:${s}.${c}Z`}function Wg(r){let e=new RegExp("(\\d{4})-(\\d{2})-(\\d{2})T(\\d{2}):(\\d{2}):(\\d{2})\\.(\\d+)Z"),t=String(r).trim().match(e);if(t==null)throw new Error("Invalid format");let n=parseInt(t[1],10),i=parseInt(t[2],10)-1,o=parseInt(t[3],10),s=parseInt(t[4],10),a=parseInt(t[5],10),c=parseInt(t[6],10),u=parseInt(t[7].slice(0,-6),10);return new Date(Date.UTC(n,i,o,s,a,c,u))}var Co=class r{key;value;timeReceived;constructor(e,t,n){if(!(e instanceof Uint8Array))throw new Error("key must be a Uint8Array");if(!(t instanceof Uint8Array))throw new Error("value must be a Uint8Array");this.key=e,this.value=t,this.timeReceived=n}serialize(){return ta.encode(this.prepareSerialize())}prepareSerialize(){return{key:this.key,value:this.value,timeReceived:Yg(this.timeReceived)}}static deserialize(e){let t=ta.decode(e);return new r(t.key,t.value,new Date(t.timeReceived))}static fromDeserialized(e){let t=Wg(e.timeReceived);if(e.key==null)throw new Error("key missing from deserialized object");if(e.value==null)throw new Error("value missing from deserialized object");return new r(e.key,e.value,t)}};var jg;(function(r){r[r.SEND_QUERY=0]="SEND_QUERY",r[r.PEER_RESPONSE=1]="PEER_RESPONSE",r[r.FINAL_PEER=2]="FINAL_PEER",r[r.QUERY_ERROR=3]="QUERY_ERROR",r[r.PROVIDER=4]="PROVIDER",r[r.VALUE=5]="VALUE",r[r.ADD_PEER=6]="ADD_PEER",r[r.DIAL_PEER=7]="DIAL_PEER"})(jg||(jg={}));var Xg;(function(r){r[r.PUT_VALUE=0]="PUT_VALUE",r[r.GET_VALUE=1]="GET_VALUE",r[r.ADD_PROVIDER=2]="ADD_PROVIDER",r[r.GET_PROVIDERS=3]="GET_PROVIDERS",r[r.FIND_NODE=4]="FIND_NODE",r[r.PING=5]="PING"})(Xg||(Xg={}));function Eh(r){return new Fe("/dht/record/"+J(r,"base32"),!1)}function Zg(r){return{async put(e,t,n={}){try{let i=Eh(e),o=new Co(e,t,new Date);n.onProgress?.(new V("ipns:routing:datastore:put")),await r.put(i,o.serialize(),n)}catch(i){throw n.onProgress?.(new V("ipns:routing:datastore:error",i)),i}},async get(e,t={}){try{let n=Eh(e);t.onProgress?.(new V("ipns:routing:datastore:get"));let i=await r.get(n,t);return Co.deserialize(i).value}catch(n){throw t.onProgress?.(new V("ipns:routing:datastore:error",n)),n}},async has(e,t={}){let n=Eh(e);return r.has(n,t)}}}var Ti=oe("helia:ipns"),B_=60*1e3,Jg=60*B_,k_=24*Jg,xh=23*Jg,bh=class{routers;localStore;timeout;defaultResolvers;constructor(e,t=[],n=[]){this.routers=[qg(e.routing),...t],this.localStore=Zg(e.datastore),this.defaultResolvers=n.length>0?n:[Gg()]}async publish(e,t,n={}){try{let i=1n,o=So(e);if(await this.localStore.has(o,n)){let c=await this.localStore.get(o,n);i=dt(c).sequence+1n}let s=await Py(e,t,i,n.lifetime??k_,n),a=sn(s);return await this.localStore.put(o,a,n),n.offline!==!0&&await Promise.all(this.routers.map(async c=>{await c.put(o,a,n)})),s}catch(i){throw n.onProgress?.(new V("ipns:publish:error",i)),i}}async resolve(e,t={}){let n=So(e),i=await this.#t(n,t);return this.#e(i.value,t)}async resolveDns(e,t={}){let n=t.resolvers??this.defaultResolvers,i=await Promise.any(n.map(async o=>o(e,t)));return this.#e(i,t)}republish(e={}){if(this.timeout!=null)throw new Error("Republish is already running");e.signal?.addEventListener("abort",()=>{clearTimeout(this.timeout)});async function t(){let n=Date.now();e.onProgress?.(new V("ipns:republish:start"));let o=Date.now()-n,s=xh-o;s<0&&(s=e.interval??xh),setTimeout(()=>{t().catch(a=>{Ti.error("error republishing",a)})},s)}this.timeout=setTimeout(()=>{t().catch(n=>{Ti.error("error republishing",n)})},e.interval??xh)}async#e(e,t={}){let n=e.split("/");try{let i=n[1];if(i==="ipns"){let{cid:o}=await this.resolve(Jt(n[2]),t),s=n.slice(3).join("/");return{cid:o,path:s}}else if(i==="ipfs"){let o=F.parse(n[2]),s=n.slice(3).join("/");return{cid:o,path:s}}}catch(i){Ti.error("error parsing ipfs path",i)}throw Ti.error("invalid ipfs path %s",e),new Error("Invalid value")}async#t(e,t={}){let n=[this.localStore,...this.routers];t.offline===!0&&(n=[this.localStore]);let i=[],o=0;if(await Promise.all(n.map(async a=>{let c;try{c=await a.get(e,{...t,validate:!1})}catch(u){a===this.localStore&&u.code==="ERR_NOT_FOUND"?Ti("did not have record locally"):Ti.error("error finding IPNS record",u);return}try{await cl(e,c),i.push(c)}catch(u){o++,Ti.error("error finding IPNS record",u)}})),i.length===0)throw o>0?new O(`${o>1?`${o} records`:"Record"} found for routing key ${o>1?"were":"was"} invalid`,"ERR_RECORDS_FAILED_VALIDATION"):new O("Could not find record for routing key","ERR_NOT_FOUND");let s=i[Dg(e,i)];return await this.localStore.put(e,s,t),dt(s)}};function Qg(r,{routers:e=[],resolvers:t=[]}={}){return new bh(r,e,t)}var pS=Q(Ch(),1),mS=Q(Tw(),1);var BF=new Qn(1e3),kF=60*1e3;var $h=new Qn(1e3),yS=60*1e3;function Ml(r){let e=new nt({concurrency:4}),t=async(n,i={})=>{let o=new URLSearchParams;o.set("name",n),o.set("type","TXT");let s=o.toString();if(i.nocache!==!0&&$h.has(s)){let c=$h.get(s);if(c!=null)return i.onProgress?.(new V("dnslink:cache",{detail:c})),c}i.onProgress?.(new V("dnslink:query",{detail:n}));let a=await e.add(async()=>{let c=await fetch(`${r}?${o}`,{headers:{accept:"application/dns-json"},signal:i.signal});if(c.status!==200)throw new Error(`Unexpected HTTP status: ${c.status} - ${c.statusText}`);let u=new URL(c.url).search.slice(1),l=await c.json();i.onProgress?.(new V("dnslink:answer",{detail:l}));let{ipfsPath:d,answer:p}=dh(n,l);return $h.set(u,d,p.TTL??yS),d},{signal:i.signal});if(a==null)throw new Error("No DNS response received");return a};return async(n,i={})=>No(n,ea,t,i)}var Wh=Q(Ce(),1);function gS(r){return r[Symbol.asyncIterator]!=null}function wS(r,e=1){return e=Number(e),gS(r)?async function*(){let t=[];if(e<1&&(e=1),e!==Math.round(e))throw new Error("Batch size must be an integer");for await(let n of r)for(t.push(n);t.length>=e;)yield t.slice(0,e),t=t.slice(e);for(;t.length>0;)yield t.slice(0,e),t=t.slice(e)}():function*(){let t=[];if(e<1&&(e=1),e!==Math.round(e))throw new Error("Batch size must be an integer");for(let n of r)for(t.push(n);t.length>=e;)yield t.slice(0,e),t=t.slice(e);for(;t.length>0;)yield t.slice(0,e),t=t.slice(e)}()}var ia=wS;async function*oa(r,e=1){for await(let t of ia(r,e)){let n=t.map(async i=>i().then(o=>({ok:!0,value:o}),o=>({ok:!1,err:o})));for(let i=0;i<n.length;i++){let o=await n[i];if(o.ok)yield o.value;else throw o.err}}}var ES=262144,sa=(r={})=>{let e=r.chunkSize??ES;return async function*(n){let i=new $t,o=0,s=!1;for await(let a of n)for(i.append(a),o+=a.length;o>=e;)if(yield i.slice(0,e),s=!0,e===i.length)i=new $t,o=0;else{let c=new $t;c.append(i.sublist(e)),i=c,o-=e}(!s||o>0)&&(yield i.subarray(0,o))}};var zh=Q(Ce(),1);var dr;(function(r){let e;(function(i){i.Raw="Raw",i.Directory="Directory",i.File="File",i.Metadata="Metadata",i.Symlink="Symlink",i.HAMTShard="HAMTShard"})(e=r.DataType||(r.DataType={}));let t;(function(i){i[i.Raw=0]="Raw",i[i.Directory=1]="Directory",i[i.File=2]="File",i[i.Metadata=3]="Metadata",i[i.Symlink=4]="Symlink",i[i.HAMTShard=5]="HAMTShard"})(t||(t={})),function(i){i.codec=()=>pi(t)}(e=r.DataType||(r.DataType={}));let n;r.codec=()=>(n==null&&(n=Ht((i,o,s={})=>{if(s.lengthDelimited!==!1&&o.fork(),i.Type!=null&&(o.uint32(8),r.DataType.codec().encode(i.Type,o)),i.Data!=null&&(o.uint32(18),o.bytes(i.Data)),i.filesize!=null&&(o.uint32(24),o.uint64(i.filesize)),i.blocksizes!=null)for(let a of i.blocksizes)o.uint32(32),o.uint64(a);i.hashType!=null&&(o.uint32(40),o.uint64(i.hashType)),i.fanout!=null&&(o.uint32(48),o.uint64(i.fanout)),i.mode!=null&&(o.uint32(56),o.uint32(i.mode)),i.mtime!=null&&(o.uint32(66),Hl.codec().encode(i.mtime,o)),s.lengthDelimited!==!1&&o.ldelim()},(i,o)=>{let s={blocksizes:[]},a=o==null?i.len:i.pos+o;for(;i.pos<a;){let c=i.uint32();switch(c>>>3){case 1:s.Type=r.DataType.codec().decode(i);break;case 2:s.Data=i.bytes();break;case 3:s.filesize=i.uint64();break;case 4:s.blocksizes.push(i.uint64());break;case 5:s.hashType=i.uint64();break;case 6:s.fanout=i.uint64();break;case 7:s.mode=i.uint32();break;case 8:s.mtime=Hl.codec().decode(i,i.uint32());break;default:i.skipType(c&7);break}}return s})),n),r.encode=i=>Mt(i,r.codec()),r.decode=i=>Ft(i,r.codec())})(dr||(dr={}));var Hl;(function(r){let e;r.codec=()=>(e==null&&(e=Ht((t,n,i={})=>{i.lengthDelimited!==!1&&n.fork(),t.Seconds!=null&&(n.uint32(8),n.int64(t.Seconds)),t.FractionalNanoseconds!=null&&(n.uint32(21),n.fixed32(t.FractionalNanoseconds)),i.lengthDelimited!==!1&&n.ldelim()},(t,n)=>{let i={},o=n==null?t.len:t.pos+n;for(;t.pos<o;){let s=t.uint32();switch(s>>>3){case 1:i.Seconds=t.int64();break;case 2:i.FractionalNanoseconds=t.fixed32();break;default:t.skipType(s&7);break}}return i})),e),r.encode=t=>Mt(t,r.codec()),r.decode=t=>Ft(t,r.codec())})(Hl||(Hl={}));var Nw;(function(r){let e;r.codec=()=>(e==null&&(e=Ht((t,n,i={})=>{i.lengthDelimited!==!1&&n.fork(),t.MimeType!=null&&(n.uint32(10),n.string(t.MimeType)),i.lengthDelimited!==!1&&n.ldelim()},(t,n)=>{let i={},o=n==null?t.len:t.pos+n;for(;t.pos<o;){let s=t.uint32();switch(s>>>3){case 1:i.MimeType=t.string();break;default:t.skipType(s&7);break}}return i})),e),r.encode=t=>Mt(t,r.codec()),r.decode=t=>Ft(t,r.codec())})(Nw||(Nw={}));var Cw={Raw:"raw",Directory:"directory",File:"file",Metadata:"metadata",Symlink:"symlink",HAMTShard:"hamt-sharded-directory"},xS=["directory","hamt-sharded-directory"],Lw=parseInt("0644",8),Uw=parseInt("0755",8),j=class r{static unmarshal(e){let t=dr.decode(e),n=new r({type:Cw[t.Type!=null?t.Type.toString():"File"],data:t.Data,blockSizes:t.blocksizes,mode:t.mode,mtime:t.mtime!=null?{secs:t.mtime.Seconds??0n,nsecs:t.mtime.FractionalNanoseconds}:void 0,fanout:t.fanout});return n._originalMode=t.mode??0,n}type;data;blockSizes;hashType;fanout;mtime;_mode;_originalMode;constructor(e={type:"file"}){let{type:t,data:n,blockSizes:i,hashType:o,fanout:s,mtime:a,mode:c}=e;if(t!=null&&!Object.values(Cw).includes(t))throw(0,zh.default)(new Error("Type: "+t+" is not valid"),"ERR_INVALID_TYPE");this.type=t??"file",this.data=n,this.hashType=o,this.fanout=s,this.blockSizes=i??[],this._originalMode=0,this.mode=c,this.mtime=a}set mode(e){e==null?this._mode=this.isDirectory()?Uw:Lw:this._mode=e&4095}get mode(){return this._mode}isDirectory(){return xS.includes(this.type)}addBlockSize(e){this.blockSizes.push(e)}removeBlockSize(e){this.blockSizes.splice(e,1)}fileSize(){if(this.isDirectory())return 0n;let e=0n;return this.blockSizes.forEach(t=>{e+=t}),this.data!=null&&(e+=BigInt(this.data.length)),e}marshal(){let e;switch(this.type){case"raw":e=dr.DataType.Raw;break;case"directory":e=dr.DataType.Directory;break;case"file":e=dr.DataType.File;break;case"metadata":e=dr.DataType.Metadata;break;case"symlink":e=dr.DataType.Symlink;break;case"hamt-sharded-directory":e=dr.DataType.HAMTShard;break;default:throw(0,zh.default)(new Error(`Type: ${e} is not valid`),"ERR_INVALID_TYPE")}let t=this.data;(this.data==null||this.data.length===0)&&(t=void 0);let n;this.mode!=null&&(n=this._originalMode&4294963200|(this.mode??0),n===Lw&&!this.isDirectory()&&(n=void 0),n===Uw&&this.isDirectory()&&(n=void 0));let i;return this.mtime!=null&&(i={Seconds:this.mtime.secs,FractionalNanoseconds:this.mtime.nsecs}),dr.encode({Type:e,Data:t,filesize:this.isDirectory()?void 0:this.fileSize(),blocksizes:this.blockSizes,hashType:this.hashType,fanout:this.fanout,mode:n,mtime:i})}};var fr=async(r,e,t)=>{t.codec==null&&(t.codec=De);let n=await fe.digest(r),i=F.create(t.cidVersion,t.codec.code,n);return await e.put(i,r,t),i};function Dw(r){return async function*(t,n){let i=0n;for await(let o of t.content)yield async()=>{let s,a={codec:De,cidVersion:r.cidVersion,onProgress:r.onProgress};r.rawLeaves?(a.codec=Vt,a.cidVersion=1):(s=new j({type:r.leafType,data:o}),o=ce({Data:s.marshal(),Links:[]}));let c=await fr(o,n,a);return i+=BigInt(o.byteLength),r.onProgress?.(new V("unixfs:importer:progress:file:write",{bytesWritten:i,cid:c,path:t.path})),{cid:c,unixfs:s,size:BigInt(o.length),block:o}}}}var Kh=Q(Ce(),1);var Ow=async(r,e,t)=>{let n=new j({type:"directory",mtime:r.mtime,mode:r.mode}),i=ce(Te({Data:n.marshal()})),o=await fr(i,e,t),s=r.path;return{cid:o,path:s,unixfs:n,size:BigInt(i.length),originalPath:r.originalPath,block:i}};async function*bS(r,e,t){let n=-1,i;for await(let o of oa(t.bufferImporter(r,e),t.blockWriteConcurrency)){if(n++,n===0){i={...o,single:!0};continue}else n===1&&i!=null&&(yield{...i,block:void 0,single:void 0},i=void 0);yield{...o,block:void 0}}i!=null&&(yield i)}function Pw(r){return r.single===!0}var vS=(r,e,t)=>async function(i){if(i.length===1&&Pw(i[0])&&t.reduceSingleLeafToSelf){let l=i[0],d=l.block;return Pw(l)&&(r.mtime!==void 0||r.mode!==void 0)&&(l.unixfs=new j({type:"file",mtime:r.mtime,mode:r.mode,data:l.block}),d={Data:l.unixfs.marshal(),Links:[]},l.block=ce(Te(d)),l.cid=await fr(l.block,e,{...t,cidVersion:t.cidVersion}),l.size=BigInt(l.block.length)),t.onProgress?.(new V("unixfs:importer:progress:file:layout",{cid:l.cid,path:l.originalPath})),{cid:l.cid,path:r.path,unixfs:l.unixfs,size:l.size,originalPath:l.originalPath}}let o=new j({type:"file",mtime:r.mtime,mode:r.mode}),s=i.filter(l=>l.cid.code===Ae&&l.size>0||l.unixfs!=null&&l.unixfs.data==null&&l.unixfs.fileSize()>0n?!0:!!l.unixfs?.data?.length).map(l=>l.cid.code===Ae?(o.addBlockSize(l.size),{Name:"",Tsize:Number(l.size),Hash:l.cid}):(l.unixfs==null||l.unixfs.data==null?o.addBlockSize(l.unixfs?.fileSize()??0n):o.addBlockSize(BigInt(l.unixfs.data.length)),{Name:"",Tsize:Number(l.size),Hash:l.cid})),a={Data:o.marshal(),Links:s},c=ce(Te(a)),u=await fr(c,e,t);return t.onProgress?.(new V("unixfs:importer:progress:file:layout",{cid:u,path:r.originalPath})),{cid:u,path:r.path,unixfs:o,size:BigInt(c.length+a.Links.reduce((l,d)=>l+(d.Tsize??0),0)),originalPath:r.originalPath,block:c}},Fw=async(r,e,t)=>t.layout(bS(r,e,t),vS(r,e,t));function AS(r){return Symbol.iterator in r}function _S(r){return Symbol.asyncIterator in r}function SS(r){try{if(r instanceof Uint8Array)return async function*(){yield r}();if(AS(r))return async function*(){yield*r}();if(_S(r))return r}catch{throw(0,Kh.default)(new Error("Content was invalid"),"ERR_INVALID_CONTENT")}throw(0,Kh.default)(new Error("Content was invalid"),"ERR_INVALID_CONTENT")}function Vw(r){return async function*(t,n){for await(let i of t){let o;if(i.path!=null&&(o=i.path,i.path=i.path.split("/").filter(s=>s!=null&&s!==".").join("/")),IS(i)){let s={path:i.path,mtime:i.mtime,mode:i.mode,content:async function*(){let a=0n;for await(let c of r.chunker(r.chunkValidator(SS(i.content)))){let u=BigInt(c.byteLength);a+=u,r.onProgress?.(new V("unixfs:importer:progress:file:read",{bytesRead:a,chunkSize:u,path:i.path})),yield c}}(),originalPath:o};yield async()=>Fw(s,n,r)}else if(i.path!=null){let s={path:i.path,mtime:i.mtime,mode:i.mode,originalPath:o};yield async()=>Ow(s,n,r)}else throw new Error("Import candidate must have content or path or both")}}}function IS(r){return r.content!=null}var Gh=Q(Ce(),1);var Mw=()=>async function*(e){for await(let t of e){if(t.length===void 0)throw(0,Gh.default)(new Error("Content was invalid"),"ERR_INVALID_CONTENT");if(typeof t=="string"||t instanceof String)yield H(t.toString());else if(Array.isArray(t))yield Uint8Array.from(t);else if(t instanceof Uint8Array)yield t;else throw(0,Gh.default)(new Error("Content was invalid"),"ERR_INVALID_CONTENT")}};var BS=174;function aa(r){let e=r?.maxChildrenPerNode??BS;return async function t(n,i){let o=[];for await(let s of ia(n,e))o.push(await i(s));return o.length>1?t(o,i):o[0]}}var Dr=class{options;root;dir;path;dirty;flat;parent;parentKey;unixfs;mode;mtime;cid;size;nodeSize;constructor(e,t){this.options=t??{},this.root=e.root,this.dir=e.dir,this.path=e.path,this.dirty=e.dirty,this.flat=e.flat,this.parent=e.parent,this.parentKey=e.parentKey,this.unixfs=e.unixfs,this.mode=e.mode,this.mtime=e.mtime}},ca=F.parse("QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn"),la=F.parse("zdj7WbTaiJT1fgatdet9Ei9iDB5hdCxkbVyhyh8YTUnXMiwYi");var Ui=class extends Dr{_children;constructor(e,t){super(e,t),this._children=new Map}async put(e,t){this.cid=void 0,this.size=void 0,this.nodeSize=void 0,this._children.set(e,t)}async get(e){return Promise.resolve(this._children.get(e))}childCount(){return this._children.size}directChildrenCount(){return this.childCount()}onlyChild(){return this._children.values().next().value}async*eachChildSeries(){for(let[e,t]of this._children.entries())yield{key:e,child:t}}estimateNodeSize(){if(this.nodeSize!==void 0)return this.nodeSize;this.nodeSize=0;for(let[e,t]of this._children.entries())t.size!=null&&t.cid!=null&&(this.nodeSize+=e.length+(this.options.cidVersion===1?la.bytes.byteLength:ca.bytes.byteLength));return this.nodeSize}async*flush(e){let t=[];for(let[c,u]of this._children.entries()){let l=u;if(u instanceof Dr)for await(let d of u.flush(e))l=d,yield d;l.size!=null&&l.cid!=null&&t.push({Name:c,Tsize:Number(l.size),Hash:l.cid})}let n=new j({type:"directory",mtime:this.mtime,mode:this.mode}),i={Data:n.marshal(),Links:t},o=ce(Te(i)),s=await fr(o,e,this.options),a=o.length+i.Links.reduce((c,u)=>c+(u.Tsize==null?0:u.Tsize),0);this.cid=s,this.size=a,yield{cid:s,unixfs:n,path:this.path,size:BigInt(a)}}};var zl=Q(zw(),1);function kS(r){let e=new Array(4);for(let t=0;t<4;t++)e[t]=r&255,r=r>>8;return new Uint8Array(e)}var V9=li({name:"murmur3-32",code:35,encode:r=>kS(zl.default.x86.hash32(r))}),Di=li({name:"murmur3-128",code:34,encode:r=>Hi.fromHex(zl.default.x64.hash128(r))}),M9=li({name:"murmur3-x64-64",code:34,encode:r=>Hi.fromHex(zl.default.x64.hash128(r)).subarray(0,8)});var qw=Q(Kl(),1);var Dt=class r{_options;_popCount;_parent;_posAtParent;_children;key;constructor(e,t,n=0){this._options=e,this._popCount=0,this._parent=t,this._posAtParent=n,this._children=new qw.default,this.key=null}async put(e,t){let n=await this._findNewBucketAndPos(e);n.bucket._putAt(n,e,t)}async get(e){let t=await this._findChild(e);if(t!=null)return t.value}async del(e){let t=await this._findPlace(e),n=t.bucket._at(t.pos);n!=null&&n.key===e&&t.bucket._delAt(t.pos)}leafCount(){return this._children.compactArray().reduce((t,n)=>n instanceof r?t+n.leafCount():t+1,0)}childrenCount(){return this._children.length}onlyChild(){return this._children.get(0)}*eachLeafSeries(){let e=this._children.compactArray();for(let t of e)t instanceof r?yield*t.eachLeafSeries():yield t}serialize(e,t){let n=[];return t(this._children.reduce((i,o,s)=>(o!=null&&(o instanceof r?i.push(o.serialize(e,t)):i.push(e(o,s))),i),n))}async asyncTransform(e,t){return Yw(this,e,t)}toJSON(){return this.serialize(LS,US)}prettyPrint(){return JSON.stringify(this.toJSON(),null," ")}tableSize(){return Math.pow(2,this._options.bits)}async _findChild(e){let t=await this._findPlace(e),n=t.bucket._at(t.pos);if(!(n instanceof r)&&n!=null&&n.key===e)return n}async _findPlace(e){let t=this._options.hash(typeof e=="string"?H(e):e),n=await t.take(this._options.bits),i=this._children.get(n);return i instanceof r?i._findPlace(t):{bucket:this,pos:n,hash:t,existingChild:i}}async _findNewBucketAndPos(e){let t=await this._findPlace(e);if(t.existingChild!=null&&t.existingChild.key!==e){let n=new r(this._options,t.bucket,t.pos);t.bucket._putObjectAt(t.pos,n);let i=await n._findPlace(t.existingChild.hash);return i.bucket._putAt(i,t.existingChild.key,t.existingChild.value),n._findNewBucketAndPos(t.hash)}return t}_putAt(e,t,n){this._putObjectAt(e.pos,{key:t,value:n,hash:e.hash})}_putObjectAt(e,t){this._children.get(e)==null&&this._popCount++,this._children.set(e,t)}_delAt(e){if(e===-1)throw new Error("Invalid position");this._children.get(e)!=null&&this._popCount--,this._children.unset(e),this._level()}_level(){if(this._parent!=null&&this._popCount<=1)if(this._popCount===1){let e=this._children.find(CS);if(e!=null&&!(e instanceof r)){let t=e.hash;t.untake(this._options.bits);let n={pos:this._posAtParent,hash:t,bucket:this._parent};this._parent._putAt(n,e.key,e.value)}}else this._parent._delAt(this._posAtParent)}_at(e){return this._children.get(e)}};function CS(r){return!!r}function LS(r,e){return r.key}function US(r){return r}async function Yw(r,e,t){let n=[];for(let i of r._children.compactArray())if(i instanceof Dt)await Yw(i,e,t);else{let o=await e(i);n.push({bitField:r._children.bitField(),children:o})}return t(n)}var DS=[255,254,252,248,240,224,192,128],OS=[1,3,7,15,31,63,127,255],Gl=class{_value;_currentBytePos;_currentBitPos;constructor(e){this._value=e,this._currentBytePos=e.length-1,this._currentBitPos=7}availableBits(){return this._currentBitPos+1+this._currentBytePos*8}totalBits(){return this._value.length*8}take(e){let t=e,n=0;for(;t>0&&this._haveBits();){let i=this._value[this._currentBytePos],o=this._currentBitPos+1,s=Math.min(o,t),a=PS(i,o-s,s);n=(n<<s)+a,t-=s,this._currentBitPos-=s,this._currentBitPos<0&&(this._currentBitPos=7,this._currentBytePos--)}return n}untake(e){for(this._currentBitPos+=e;this._currentBitPos>7;)this._currentBitPos-=8,this._currentBytePos+=1}_haveBits(){return this._currentBytePos>=0}};function PS(r,e,t){let n=FS(e,t);return(r&n)>>>e}function FS(r,e){return DS[r]&OS[Math.min(e+r-1,7)]}function Ww(r){function e(t){return t instanceof ql?t:new ql(t,r)}return e}var ql=class{_value;_hashFn;_depth;_availableBits;_currentBufferIndex;_buffers;constructor(e,t){if(!(e instanceof Uint8Array))throw new Error("can only hash Uint8Arrays");this._value=e,this._hashFn=t,this._depth=-1,this._availableBits=0,this._currentBufferIndex=0,this._buffers=[]}async take(e){let t=e;for(;this._availableBits<t;)await this._produceMoreBits();let n=0;for(;t>0;){let i=this._buffers[this._currentBufferIndex],o=Math.min(i.availableBits(),t),s=i.take(o);n=(n<<o)+s,t-=o,this._availableBits-=o,i.availableBits()===0&&this._currentBufferIndex++}return n}untake(e){let t=e;for(;t>0;){let n=this._buffers[this._currentBufferIndex],i=Math.min(n.totalBits()-n.availableBits(),t);n.untake(i),t-=i,this._availableBits+=i,this._currentBufferIndex>0&&n.totalBits()===n.availableBits()&&(this._depth--,this._currentBufferIndex--)}}async _produceMoreBits(){this._depth++;let e=this._depth>0?we([this._value,Uint8Array.from([this._depth])]):this._value,t=await this._hashFn(e),n=new Gl(t);this._buffers.push(n),this._availableBits+=n.availableBits()}};function Fo(r){if(r==null||r.hashFn==null)throw new Error("please define an options.hashFn");let e={bits:r.bits??8,hash:Ww(r.hashFn)};return new Dt(e)}async function VS(r){return(await Di.encode(r)).slice(0,8).reverse()}var jw=BigInt(34),MS=8,qh=class extends Dr{_bucket;constructor(e,t){super(e,t),this._bucket=Fo({hashFn:VS,bits:t.shardFanoutBits??MS})}async put(e,t){this.cid=void 0,this.size=void 0,this.nodeSize=void 0,await this._bucket.put(e,t)}async get(e){return this._bucket.get(e)}childCount(){return this._bucket.leafCount()}directChildrenCount(){return this._bucket.childrenCount()}onlyChild(){return this._bucket.onlyChild()}async*eachChildSeries(){for await(let{key:e,value:t}of this._bucket.eachLeafSeries())yield{key:e,child:t}}estimateNodeSize(){return this.nodeSize!==void 0?this.nodeSize:(this.nodeSize=Jw(this._bucket,this,this.options),this.nodeSize)}async*flush(e){for await(let t of Zw(this._bucket,e,this,this.options))yield{...t,path:this.path}}},Xw=qh;async function*Zw(r,e,t,n){let i=r._children,o=(r.tableSize()-1).toString(16).length,s=[],a=0n;for(let h=0;h<i.length;h++){let m=i.get(h);if(m==null)continue;let y=h.toString(16).toUpperCase().padStart(o,"0");if(m instanceof Dt){let g;for await(let E of Zw(m,e,null,n))g=E;if(g==null)throw new Error("Could not flush sharded directory, no subshard found");s.push({Name:y,Tsize:Number(g.size),Hash:g.cid}),a+=g.size}else if(HS(m.value)){let g=m.value,E;for await(let _ of g.flush(e))E=_,yield E;if(E==null)throw new Error("Did not flush dir");let x=y+m.key;s.push({Name:x,Tsize:Number(E.size),Hash:E.cid}),a+=E.size}else{let g=m.value;if(g.cid==null)continue;let E=y+m.key,x=g.size;s.push({Name:E,Tsize:Number(x),Hash:g.cid}),a+=BigInt(x??0)}}let c=Uint8Array.from(i.bitField().reverse()),u=new j({type:"hamt-sharded-directory",data:c,fanout:BigInt(r.tableSize()),hashType:jw,mtime:t?.mtime,mode:t?.mode}),l={Data:u.marshal(),Links:s},d=ce(Te(l)),p=await fr(d,e,n),f=BigInt(d.byteLength)+a;yield{cid:p,unixfs:u,size:f}}function HS(r){return typeof r.flush=="function"}function Jw(r,e,t){let n=r._children,i=(r.tableSize()-1).toString(16).length,o=[];for(let u=0;u<n.length;u++){let l=n.get(u);if(l==null)continue;let d=u.toString(16).toUpperCase().padStart(i,"0");if(l instanceof Dt){let p=Jw(l,null,t);o.push({Name:d,Tsize:Number(p),Hash:t.cidVersion===0?ca:la})}else if(typeof l.value.flush=="function"){let f=l.value.nodeSize();o.push({Name:d+l.key,Tsize:Number(f),Hash:t.cidVersion===0?ca:la})}else{let p=l.value;if(p.cid==null)continue;let f=d+l.key,h=p.size;o.push({Name:f,Tsize:Number(h),Hash:p.cid})}}let s=Uint8Array.from(n.bitField().reverse()),a=new j({type:"hamt-sharded-directory",data:s,fanout:BigInt(r.tableSize()),hashType:jw,mtime:e?.mtime,mode:e?.mode});return ce(Te({Data:a.marshal(),Links:o})).length}async function Yh(r,e,t,n){let i=e;e instanceof Ui&&e.estimateNodeSize()>t&&(i=await $S(e,n));let o=i.parent;if(o!=null){if(i!==e){if(r!=null&&(r.parent=i),i.parentKey==null)throw new Error("No parent key found");await o.put(i.parentKey,i)}return Yh(i,o,t,n)}return i}async function $S(r,e){let t=new Xw({root:r.root,dir:!0,parent:r.parent,parentKey:r.parentKey,path:r.path,dirty:r.dirty,flat:!1,mtime:r.mtime,mode:r.mode},e);for await(let{key:n,child:i}of r.eachChildSeries())await t.put(n,i);return t}var Qw=(r="")=>r.split(/(?<!\\)\//).filter(Boolean);async function zS(r,e,t){let n=Qw(r.path??""),i=n.length-1,o=e,s="";for(let a=0;a<n.length;a++){let c=n[a];s+=`${s!==""?"/":""}${c}`;let u=a===i;if(o.dirty=!0,o.cid=void 0,o.size=void 0,u)await o.put(c,r),e=await Yh(null,o,t.shardSplitThresholdBytes,t);else{let l=await o.get(c);(l==null||!(l instanceof Dr))&&(l=new Ui({root:!1,dir:!0,parent:o,parentKey:c,path:s,dirty:!0,flat:!0,mtime:l?.unixfs?.mtime,mode:l?.unixfs?.mode},t)),await o.put(c,l),o=l}}return e}async function*e2(r,e){if(!(r instanceof Dr)){r.unixfs?.isDirectory()===!0&&(yield r);return}yield*r.flush(e)}function t2(r){return async function*(t,n){let i=new Ui({root:!0,dir:!0,path:"",dirty:!0,flat:!0},r),o,s=!1;for await(let a of t){if(a==null)continue;let c=`${a.originalPath??""}`.split("/")[0];c!=null&&c!==""&&(o==null?(o=c,s=!0):o!==c&&(s=!1)),i=await zS(a,i,r),(a.unixfs==null||!a.unixfs.isDirectory())&&(yield a)}if(r.wrapWithDirectory||s&&i.childCount()>1)yield*e2(i,n);else for await(let a of i.eachChildSeries())a!=null&&(yield*e2(a.child,n))}}async function*ri(r,e,t={}){let n;Symbol.asyncIterator in r||Symbol.iterator in r?n=r:n=[r];let i=t.wrapWithDirectory??!1,o=t.shardSplitThresholdBytes??262144,s=t.shardFanoutBits??8,a=t.cidVersion??1,c=t.rawLeaves??!0,u=t.leafType??"file",l=t.fileImportConcurrency??50,d=t.blockWriteConcurrency??10,p=t.reduceSingleLeafToSelf??!0,f=t.chunker??sa(),h=t.chunkValidator??Mw(),m=t.dagBuilder??Vw({chunker:f,chunkValidator:h,wrapWithDirectory:i,layout:t.layout??aa(),bufferImporter:t.bufferImporter??Dw({cidVersion:a,rawLeaves:c,leafType:u,onProgress:t.onProgress}),blockWriteConcurrency:d,reduceSingleLeafToSelf:p,cidVersion:a,onProgress:t.onProgress}),y=t.treeBuilder??t2({wrapWithDirectory:i,shardSplitThresholdBytes:o,shardFanoutBits:s,cidVersion:a,onProgress:t.onProgress});for await(let g of y(oa(m(n,e),l),e))yield{cid:g.cid,path:g.path,unixfs:g.unixfs,size:g.size}}async function Yl(r,e,t={}){let n=await _i(ri([r],e,t));if(n==null)throw(0,Wh.default)(new Error("Nothing imported"),"ERR_INVALID_PARAMS");return n}async function r2(r,e,t={}){let n=await _i(ri([r],e,t));if(n==null)throw(0,Wh.default)(new Error("Nothing imported"),"ERR_INVALID_PARAMS");return n}async function n2(r,e,t={}){return Yl({content:r},e,t)}async function i2(r,e,t={}){return Yl({content:r},e,t)}var jS=Q(Ce(),1),XS=Q(g2(),1);var pa={cidVersion:1,rawLeaves:!0,layout:aa({maxChildrenPerNode:1024}),chunker:sa({chunkSize:1048576})};async function*w2(r,e,t={}){yield*ri(r,e,{...pa,...t})}async function E2(r,e,t={}){let{cid:n}=await n2(r,e,{...pa,...t});return n}async function x2(r,e,t={}){let{cid:n}=await i2(r,e,{...pa,...t});return n}async function b2(r,e,t={}){let{cid:n}=await Yl(r,e,{...pa,...t});return n}async function v2(r,e,t={}){let{cid:n}=await r2({...r,path:r.path??"-"},e,{...pa,...t});return n}var jl=Q(Ce(),1);function ZS(r){return r[Symbol.asyncIterator]!=null}function JS(r){if(ZS(r))return(async()=>{let t;for await(let n of r)t=n;return t})();let e;for(let t of r)e=t;return e}var ni=JS;var V2=Q(Ce(),1);var A2=Q(Ce(),1);function Vo(r,e,t,n,i,o,s){let a=r,c=i;for(;o.length>0;){let u=o[0];if(u in a){o.shift(),c=`${c}/${u}`;let l=F.asCID(a[u]);if(l!=null)return{entry:{type:"object",name:n,path:i,cid:t,node:e,depth:s,size:BigInt(e.length),content:async function*(){yield r}},next:{cid:l,name:u,path:c,toResolve:o}};a=a[u]}else throw(0,A2.default)(new Error(`No property named ${u} found in node ${t}`),"ERR_NO_PROP")}return{entry:{type:"object",name:n,path:i,cid:t,node:e,depth:s,size:BigInt(e.length),content:async function*(){yield r}}}}var QS=async(r,e,t,n,i,o,s,a)=>{let c=await s.get(r,a),u=Ii(c);return Vo(u,c,r,e,t,n,o)},_2=QS;var e4=async(r,e,t,n,i,o,s,a)=>{let c=await s.get(r,a),u=vl(c);return Vo(u,c,r,e,t,n,o)},S2=e4;var I2=Q(Ce(),1);function t4(r,e,t,n){let i=BigInt(r.length),o=BigInt(e+i);return t>=o||n<e?new Uint8Array(0):(n>=e&&n<o&&(r=r.subarray(0,Number(n-e))),t>=e&&t<o&&(r=r.subarray(Number(t-e))),r)}var Oi=t4;var ma=Q(Ce(),1),r4=(r,e=0,t=r)=>{let n=BigInt(r),i=BigInt(e??0),o=BigInt(t);if(o!==n&&(o=i+o),o>n&&(o=n),i<0n)throw(0,ma.default)(new Error("Offset must be greater than or equal to 0"),"ERR_INVALID_PARAMS");if(i>n)throw(0,ma.default)(new Error("Offset must be less than the file size"),"ERR_INVALID_PARAMS");if(o<0n)throw(0,ma.default)(new Error("Length must be greater than or equal to 0"),"ERR_INVALID_PARAMS");if(o>n)throw(0,ma.default)(new Error("Length must be less than the file size"),"ERR_INVALID_PARAMS");return{start:i,end:o}},Mo=r4;var n4=r=>{async function*e(t={}){let{start:n,end:i}=Mo(r.length,t.offset,t.length),o=Oi(r,0n,n,i);t.onProgress?.(new V("unixfs:exporter:progress:identity",{bytesRead:BigInt(o.byteLength),totalBytes:i-n,fileSize:BigInt(r.byteLength)})),yield o}return e},i4=async(r,e,t,n,i,o,s,a)=>{if(n.length>0)throw(0,I2.default)(new Error(`No link named ${t} found in raw node ${r}`),"ERR_NOT_FOUND");let c=st(r.multihash.bytes);return{entry:{type:"identity",name:e,path:t,cid:r,content:n4(c.digest),depth:o,size:BigInt(c.digest.length),node:c.digest}}},B2=i4;var o4=async(r,e,t,n,i,o,s,a)=>{let c=await s.get(r,a),u=cp(c);return Vo(u,c,r,e,t,n,o)},k2=o4;var R2=Q(Ce(),1);var s4=r=>{async function*e(t={}){let{start:n,end:i}=Mo(r.length,t.offset,t.length),o=Oi(r,0n,n,i);t.onProgress?.(new V("unixfs:exporter:progress:raw",{bytesRead:BigInt(o.byteLength),totalBytes:i-n,fileSize:BigInt(r.byteLength)})),yield o}return e},a4=async(r,e,t,n,i,o,s,a)=>{if(n.length>0)throw(0,R2.default)(new Error(`No link named ${t} found in raw node ${r}`),"ERR_NOT_FOUND");let c=await s.get(r,a);return{entry:{type:"raw",name:e,path:t,cid:r,content:s4(c),depth:o,size:BigInt(c.length),node:c}}},T2=a4;var ga=Q(Ce(),1);var ya=Q(Ce(),1);var c4=async function(r){return(await Di.encode(r)).slice(0,8).reverse()},l4=async(r,e,t)=>{let n=(e.tableSize()-1).toString(16).length;await Promise.all(r.map(async i=>{if(i.Name==null)throw new Error("Unexpected Link without a Name");if(i.Name.length===n){let o=parseInt(i.Name,16);e._putObjectAt(o,new Dt({hash:t._options.hash,bits:t._options.bits},e,o));return}await t.put(i.Name.substring(2),!0)}))},N2=(r,e)=>r.toString(16).toUpperCase().padStart(e,"0").substring(0,e),u4=r=>{let e=r.bucket,t=[];for(;e._parent!=null;)t.push(e),e=e._parent;return t.push(e),t.reverse()},C2=async(r,e,t,n,i)=>{if(n==null){if(r.Data==null)throw(0,ya.default)(new Error("no data in PBNode"),"ERR_NOT_UNIXFS");let d;try{d=j.unmarshal(r.Data)}catch(f){throw(0,ya.default)(f,"ERR_NOT_UNIXFS")}if(d.type!=="hamt-sharded-directory")throw(0,ya.default)(new Error("not a HAMT"),"ERR_NOT_UNIXFS");if(d.fanout==null)throw(0,ya.default)(new Error("missing fanout"),"ERR_NOT_UNIXFS");let p=Fo({hashFn:c4,bits:Math.log2(Number(d.fanout))});n={rootBucket:p,hamtDepth:1,lastBucket:p}}let o=(n.lastBucket.tableSize()-1).toString(16).length;await l4(r.Links,n.lastBucket,n.rootBucket);let s=await n.rootBucket._findNewBucketAndPos(e),a=N2(s.pos,o),c=u4(s);c.length>n.hamtDepth&&(n.lastBucket=c[n.hamtDepth],a=N2(n.lastBucket._posAtParent,o));let u=r.Links.find(d=>{if(d.Name==null)return!1;let p=d.Name.substring(0,o),f=d.Name.substring(o);return!(p!==a||f!==""&&f!==e)});if(u==null)return;if(u.Name!=null&&u.Name.substring(o)===e)return u.Hash;n.hamtDepth++;let l=await t.get(u.Hash,i);return r=Se(l),C2(r,e,t,n,i)},L2=C2;var d4=(r,e,t,n,i,o,s)=>{async function*a(c={}){let u=c.offset??0,l=c.length??e.Links.length,d=e.Links.slice(u,l);c.onProgress?.(new V("unixfs:exporter:walk:directory",{cid:r})),yield*gt(d,p=>at(p,f=>async()=>{let h=f.Name??"",m=`${n}/${h}`;return(await i(f.Hash,h,m,[],o+1,s,c)).entry}),p=>Ri(p,{ordered:!0,concurrency:c.blockReadConcurrency}),p=>bt(p,f=>f!=null))}return a},U2=d4;var Pi=Q(Ce(),1);async function D2(r,e,t,n,i,o,s){if(e instanceof Uint8Array){let u=Oi(e,n,i,o);t.push(u);return}if(e.Data==null)throw(0,Pi.default)(new Error("no data in PBNode"),"ERR_NOT_UNIXFS");let a;try{a=j.unmarshal(e.Data)}catch(u){throw(0,Pi.default)(u,"ERR_NOT_UNIXFS")}if(a.data!=null){let u=a.data,l=Oi(u,n,i,o);t.push(l),n+=BigInt(l.byteLength)}let c=[];if(e.Links.length!==a.blockSizes.length)throw(0,Pi.default)(new Error("Inconsistent block sizes and dag links"),"ERR_NOT_UNIXFS");for(let u=0;u<e.Links.length;u++){let l=e.Links[u],d=n,p=d+a.blockSizes[u];if((i>=d&&i<p||o>=d&&o<=p||i<d&&o>p)&&c.push({link:l,blockStart:n}),n=p,n>o)break}await gt(c,u=>at(u,l=>async()=>{let d=await r.get(l.link.Hash,s);return{...l,block:d}}),u=>Ri(u,{ordered:!0,concurrency:s.blockReadConcurrency}),async u=>{for await(let{link:l,block:d,blockStart:p}of u){let f;switch(l.Hash.code){case ve:f=Se(d);break;case Ae:f=d;break;default:t.end((0,Pi.default)(new Error(`Unsupported codec: ${l.Hash.code}`),"ERR_NOT_UNIXFS"));return}let h=new nt({concurrency:1});h.on("error",m=>{t.end(m)}),h.add(async()=>{s.onProgress?.(new V("unixfs:exporter:walk:file",{cid:l.Hash})),await D2(r,f,t,p,i,o,s)}),await h.onIdle()}}),n>=o&&t.end()}var f4=(r,e,t,n,i,o,s)=>{async function*a(c={}){let u=t.fileSize();if(u===void 0)throw new Error("File was a directory");let{start:l,end:d}=Mo(u,c.offset,c.length);if(d===0n)return;let p=0n,f=d-l,h=zt();c.onProgress?.(new V("unixfs:exporter:walk:file",{cid:r})),D2(s,e,h,0n,l,d,c).catch(m=>{h.end(m)});for await(let m of h)if(m!=null){if(p+=BigInt(m.byteLength),p>f)throw h.end(),(0,Pi.default)(new Error("Read too many bytes - the file size reported by the UnixFS data in the root node may be incorrect"),"ERR_OVER_READ");p===f&&h.end(),c.onProgress?.(new V("unixfs:exporter:progress:unixfs:file",{bytesRead:p,totalBytes:f,fileSize:u})),yield m}if(p<f)throw(0,Pi.default)(new Error("Traversed entire DAG but did not read enough bytes"),"ERR_UNDER_READ")}return a},Qh=f4;var Wl=Q(Ce(),1);var h4=(r,e,t,n,i,o,s)=>{function a(c={}){return c.onProgress?.(new V("unixfs:exporter:walk:hamt-sharded-directory",{cid:r})),O2(e,n,i,o,s,c)}return a};async function*O2(r,e,t,n,i,o){let s=r.Links;if(r.Data==null)throw(0,Wl.default)(new Error("no data in PBNode"),"ERR_NOT_UNIXFS");let a;try{a=j.unmarshal(r.Data)}catch(l){throw(0,Wl.default)(l,"ERR_NOT_UNIXFS")}if(a.fanout==null)throw(0,Wl.default)(new Error("missing fanout"),"ERR_NOT_UNIXFS");let c=(a.fanout-1n).toString(16).length,u=gt(s,l=>at(l,d=>async()=>{let p=d.Name!=null?d.Name.substring(c):null;if(p!=null&&p!==""){let f=await t(d.Hash,p,`${e}/${p}`,[],n+1,i,o);return{entries:f.entry==null?[]:[f.entry]}}else{let f=await i.get(d.Hash,o);return r=Se(f),o.onProgress?.(new V("unixfs:exporter:walk:hamt-sharded-directory",{cid:d.Hash})),{entries:O2(r,e,t,n,i,o)}}}),l=>Ri(l,{ordered:!0,concurrency:o.blockReadConcurrency}));for await(let{entries:l}of u)yield*l}var P2=h4;var p4=(r,e)=>r.Links.find(n=>n.Name===e)?.Hash,m4={raw:Qh,file:Qh,directory:U2,"hamt-sharded-directory":P2,metadata:(r,e,t,n,i,o,s)=>()=>[],symlink:(r,e,t,n,i,o,s)=>()=>[]},y4=async(r,e,t,n,i,o,s,a)=>{let c=await s.get(r,a),u=Se(c),l,d;if(e==null&&(e=r.toString()),u.Data==null)throw(0,ga.default)(new Error("no data in PBNode"),"ERR_NOT_UNIXFS");try{l=j.unmarshal(u.Data)}catch(f){throw(0,ga.default)(f,"ERR_NOT_UNIXFS")}if(t==null&&(t=e),n.length>0){let f;if(l?.type==="hamt-sharded-directory"?f=await L2(u,n[0],s):f=p4(u,n[0]),f==null)throw(0,ga.default)(new Error("file does not exist"),"ERR_NOT_FOUND");let h=n.shift(),m=`${t}/${h}`;d={cid:f,toResolve:n,name:h??"",path:m}}let p=m4[l.type](r,u,l,t,i,o,s);if(p==null)throw(0,ga.default)(new Error("could not find content exporter"),"ERR_NOT_FOUND");return l.isDirectory()?{entry:{type:"directory",name:e,path:t,cid:r,content:p,unixfs:l,depth:o,node:u,size:l.fileSize()},next:d}:{entry:{type:"file",name:e,path:t,cid:r,content:p,unixfs:l,depth:o,node:u,size:l.fileSize()},next:d}},F2=y4;var g4={[ve]:F2,[Ae]:T2,[Yn]:_2,[jn]:S2,[et.code]:B2,[Rn]:k2},M2=async(r,e,t,n,i,o,s)=>{let a=g4[r.code];if(a==null)throw(0,V2.default)(new Error(`No resolver for code ${r.code}`),"ERR_NO_RESOLVER");return a(r,e,t,n,M2,i,o,s)},H2=M2;var w4=(r="")=>(r.trim().match(/([^\\^/]|\\\/)+/g)??[]).filter(Boolean),E4=r=>{if(r instanceof Uint8Array)return{cid:F.decode(r),toResolve:[]};let e=F.asCID(r);if(e!=null)return{cid:e,toResolve:[]};if(typeof r=="string"){r.indexOf("/ipfs/")===0&&(r=r.substring(6));let t=w4(r);return{cid:F.parse(t[0]),toResolve:t.slice(1)}}throw(0,jl.default)(new Error(`Unknown path type ${r}`),"ERR_BAD_PATH")};async function*e0(r,e,t={}){let{cid:n,toResolve:i}=E4(r),o=n.toString(),s=o,a=i.length;for(;;){let c=await H2(n,o,s,i,a,e,t);if(c.entry==null&&c.next==null)throw(0,jl.default)(new Error(`Could not resolve ${r}`),"ERR_NOT_FOUND");if(c.entry!=null&&(yield c.entry),c.next==null)return;i=c.next.toResolve,n=c.next.cid,o=c.next.name,s=c.next.path}}async function Ve(r,e,t={}){let n=await ni(e0(r,e,t));if(n==null)throw(0,jl.default)(new Error(`Could not resolve ${r}`),"ERR_NOT_FOUND");return n}async function*Ho(r,e,t={}){let n=await Ve(r,e,t);if(n==null)return;if(yield n,n.type==="directory")for await(let o of i(n,t))yield o;async function*i(o,s){for await(let a of o.content(s))yield a,!(a instanceof Uint8Array)&&a.type==="directory"&&(yield*i(a,s))}}var X2=Q(j2(),1),it=X2.default;var hr=class extends Error{name;code;constructor(e,t,n){super(e),this.name=t,this.code=n}},Or=class extends hr{constructor(e="not a Unixfs node"){super(e,"NotUnixFSError","ERR_NOT_UNIXFS")}},pt=class extends hr{constructor(e="invalid PBNode"){super(e,"InvalidPBNodeError","ERR_INVALID_PBNODE")}},xn=class extends hr{constructor(e="unknown error"){super(e,"InvalidPBNodeError","ERR_UNKNOWN_ERROR")}},wa=class extends hr{constructor(e="path already exists"){super(e,"AlreadyExistsError","ERR_ALREADY_EXISTS")}},Jl=class extends hr{constructor(e="path does not exist"){super(e,"DoesNotExistError","ERR_DOES_NOT_EXIST")}},Ko=class extends hr{constructor(e="no content"){super(e,"NoContentError","ERR_NO_CONTENT")}},Ql=class extends hr{constructor(e="not a file"){super(e,"NotAFileError","ERR_NOT_A_FILE")}},ii=class extends hr{constructor(e="not a directory"){super(e,"NotADirectoryError","ERR_NOT_A_DIRECTORY")}},ot=class extends hr{constructor(e="invalid parameters"){super(e,"InvalidParametersError","ERR_INVALID_PARAMETERS")}};var o0=Q(Kl(),1);function tu(r){function e(t){return t instanceof eu?t:new eu(t,r)}return e}var eu=class{_value;_hashFn;_depth;_availableBits;_currentBufferIndex;_buffers;constructor(e,t){if(!(e instanceof Uint8Array))throw new Error("can only hash Uint8Arrays");this._value=e,this._hashFn=t,this._depth=-1,this._availableBits=0,this._currentBufferIndex=0,this._buffers=[]}async take(e){let t=e;for(;this._availableBits<t;)await this._produceMoreBits();let n=0;for(;t>0;){let i=this._buffers[this._currentBufferIndex],o=Math.min(i.availableBits(),t),s=i.take(o);n=(n<<o)+s,t-=o,this._availableBits-=o,i.availableBits()===0&&this._currentBufferIndex++}return n}untake(e){let t=e;for(;t>0;){let n=this._buffers[this._currentBufferIndex],i=Math.min(n.totalBits()-n.availableBits(),t);n.untake(i),t-=i,this._availableBits+=i,this._currentBufferIndex>0&&n.totalBits()===n.availableBits()&&(this._depth--,this._currentBufferIndex--)}}async _produceMoreBits(){this._depth++;let e=this._depth>0?we([this._value,Uint8Array.from([this._depth])]):this._value,t=await this._hashFn(e),n=new r0(t);this._buffers.push(n),this._availableBits+=n.availableBits()}},S4=[255,254,252,248,240,224,192,128],I4=[1,3,7,15,31,63,127,255],r0=class{_value;_currentBytePos;_currentBitPos;constructor(e){this._value=e,this._currentBytePos=e.length-1,this._currentBitPos=7}availableBits(){return this._currentBitPos+1+this._currentBytePos*8}totalBits(){return this._value.length*8}take(e){let t=e,n=0;for(;t>0&&this._haveBits();){let i=this._value[this._currentBytePos],o=this._currentBitPos+1,s=Math.min(o,t),a=B4(i,o-s,s);n=(n<<s)+a,t-=s,this._currentBitPos-=s,this._currentBitPos<0&&(this._currentBitPos=7,this._currentBytePos--)}return n}untake(e){for(this._currentBitPos+=e;this._currentBitPos>7;)this._currentBitPos-=8,this._currentBytePos+=1}_haveBits(){return this._currentBytePos>=0}};function B4(r,e,t){let n=k4(e,t);return(r&n)>>>e}function k4(r,e){return S4[r]&I4[Math.min(e+r-1,7)]}var Ea=BigInt(Di.code),Fi=8;async function Go(r){return(await Di.encode(r)).subarray(0,8).reverse()}var Q2=Q(Kl(),1);var pr=async(r,e,t)=>{t.codec==null&&(t.codec=De);let n=await fe.digest(r),i=F.create(t.cidVersion,t.codec.code,n);return await e.put(i,r,{...t,signal:t.signal}),i};var n0=class{options;root;dir;path;dirty;flat;parent;parentKey;unixfs;mode;mtime;cid;size;nodeSize;constructor(e,t){this.options=t??{},this.root=e.root,this.dir=e.dir,this.path=e.path,this.dirty=e.dirty,this.flat=e.flat,this.parent=e.parent,this.parentKey=e.parentKey,this.unixfs=e.unixfs,this.mode=e.mode,this.mtime=e.mtime}},ru=class extends n0{_bucket;constructor(e,t){super(e,t),this._bucket=Fo({hashFn:Go,bits:8})}async put(e,t){this.cid=void 0,this.size=void 0,this.nodeSize=void 0,await this._bucket.put(e,t)}async get(e){return this._bucket.get(e)}childCount(){return this._bucket.leafCount()}directChildrenCount(){return this._bucket.childrenCount()}onlyChild(){return this._bucket.onlyChild()}async*eachChildSeries(){for await(let{key:e,value:t}of this._bucket.eachLeafSeries())yield{key:e,child:t}}estimateNodeSize(){return this.nodeSize!==void 0?this.nodeSize:(this.nodeSize=J2(this._bucket,this,this.options),this.nodeSize)}async*flush(e){for await(let t of Z2(this._bucket,e,this,this.options))yield{...t,path:this.path}}};async function*Z2(r,e,t,n){let i=r._children,o=[],s=0n;for(let f=0;f<i.length;f++){let h=i.get(f);if(h==null)continue;let m=f.toString(16).toUpperCase().padStart(2,"0");if(h instanceof Dt){let y;for await(let g of Z2(h,e,null,n))y=g;if(y==null)throw new Error("Could not flush sharded directory, no subshard found");o.push({Name:m,Tsize:Number(y.size),Hash:y.cid}),s+=y.size}else if(R4(h.value)){let y=h.value,g;for await(let x of y.flush(e))g=x,yield g;if(g==null)throw new Error("Did not flush dir");let E=m+h.key;o.push({Name:E,Tsize:Number(g.size),Hash:g.cid}),s+=g.size}else{let y=h.value;if(y.cid==null)continue;let g=m+h.key,E=y.size;o.push({Name:g,Tsize:Number(E),Hash:y.cid}),s+=BigInt(E??0)}}let a=Uint8Array.from(i.bitField().reverse()),c=new j({type:"hamt-sharded-directory",data:a,fanout:BigInt(r.tableSize()),hashType:Ea,mtime:t?.mtime,mode:t?.mode}),u={Data:c.marshal(),Links:o},l=ce(Te(u)),d=await pr(l,e,n),p=BigInt(l.byteLength)+s;yield{cid:d,unixfs:c,size:p}}function R4(r){return typeof r.flush=="function"}function J2(r,e,t){let n=r._children,i=[];for(let c=0;c<n.length;c++){let u=n.get(c);if(u==null)continue;let l=c.toString(16).toUpperCase().padStart(2,"0");if(u instanceof Dt){let d=J2(u,null,t);i.push({Name:l,Tsize:Number(d),Hash:t.cidVersion===0?nu:iu})}else if(typeof u.value.flush=="function"){let p=u.value.nodeSize();i.push({Name:l+u.key,Tsize:Number(p),Hash:t.cidVersion===0?nu:iu})}else{let d=u.value;if(d.cid==null)continue;let p=l+u.key,f=d.size;i.push({Name:p,Tsize:Number(f),Hash:d.cid})}}let o=Uint8Array.from(n.bitField().reverse()),s=new j({type:"hamt-sharded-directory",data:o,fanout:BigInt(r.tableSize()),hashType:Ea,mtime:e?.mtime,mode:e?.mode});return ce(Te({Data:s.marshal(),Links:i})).length}var nu=F.parse("QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn"),iu=F.parse("zdj7WbTaiJT1fgatdet9Ei9iDB5hdCxkbVyhyh8YTUnXMiwYi");var i0=oe("helia:unixfs:commands:utils:hamt-utils"),ou=r=>r.toString(16).toUpperCase().padStart(2,"0").substring(0,2),eE=async(r,e,t)=>{let n=new ru({root:!0,dir:!0,parent:void 0,parentKey:void 0,path:"",dirty:!0,flat:!1,mtime:t.mtime,mode:t.mode},t);for(let o=0;o<e.length;o++)await n._bucket.put(e[o].name,{size:e[o].size,cid:e[o].cid});let i=await ni(n.flush(r));if(i==null)throw new Error("Flushing shard yielded no result");return i},su=async(r,e,t)=>{let n=j.unmarshal(r[0].node.Data??new Uint8Array(0)),i=BigInt(Math.pow(2,Fi));r.reverse();let o,s;for(let a=0;a<r.length;a++){let c=a===r.length-1,u=r[a],l=Uint8Array.from(u.children.bitField().reverse()),d=new j({type:"hamt-sharded-directory",data:l,fanout:i,hashType:Ea});c&&(d.mtime=n.mtime,d.mode=n.mode),s={Data:d.marshal(),Links:u.node.Links};let p=ce(Te(s));if(o=await pr(p,e,t),!c){let f=r[a+1];if(f==null)throw new Error("Was not operating on shard root but also had no parent?");i0("updating link in parent sub-shard with prefix %s",f.prefix),f.node.Links=f.node.Links.filter(h=>h.Name!==f.prefix),f.node.Links.push({Name:f.prefix,Hash:o,Tsize:u.node.Links.reduce((h,m)=>h+(m.Tsize??0),p.byteLength)})}}if(o==null||s==null)throw new Error("Noting persisted");return{cid:o,node:s}},au=async(r,e,t,n)=>{let o=tu(Go)(H(e)),s=[];for(;;){let a=await t.get(r,n),c=Se(a),u=new Q2.default,l=await o.take(Fi),d=ou(l);s.push({prefix:d,children:u,node:c});let p;for(let h of c.Links){let m=h.Name??"";if(m.length<2)throw new Error("Invalid HAMT - link name was too short");let y=parseInt(m.substring(0,2),16);u.set(y,!0),m.startsWith(d)&&(p=h)}if(p==null){i0("no link found with prefix %s for %s",d,e);break}let f=p.Name??"";if(f.length<2)throw new Error("Invalid HAMT - link name was too short");if(f.length===2){r=p.Hash,i0("descend into sub-shard with prefix %s",f);continue}break}return{path:s,hash:o}};async function cu(r,e,t,n){if(r.Data==null)throw new Error("DagPB node had no data");let i=j.unmarshal(r.Data),o;if(i.type==="directory")o=T4(r);else if(i.type==="hamt-sharded-directory")o=await tE(r,0,t,e,n);else throw new Error("Can only estimate the size of directories or shards");return o>t}function T4(r){let e=0;for(let t of r.Links)e+=(t.Name??"").length,e+=t.Hash.version===1?iu.bytes.byteLength:nu.bytes.byteLength;return e}async function tE(r,e,t,n,i){if(e>t)return t;if(r.Data==null||!j.unmarshal(r.Data).isDirectory())return e;for(let s of r.Links){let a=s.Name??"";if(a=a.substring(2),e+=a.length,e+=s.Hash.bytes.byteLength,s.Hash.code===ve){let c=await n.get(s.Hash,i),u=Se(c);e+=await tE(u,e,t,n,i)}}return e}var Pr=oe("helia:unixfs:components:utils:add-link");async function qo(r,e,t,n){if(r.node.Data==null)throw new ot("Invalid parent passed to addLink");if(j.unmarshal(r.node.Data).type==="hamt-sharded-directory")return Pr("adding link to sharded directory"),L4(r,e,t,n);Pr(`adding ${e.Name} (${e.Hash}) to regular directory`);let o=await C4(r,e,t,n);if(await cu(o.node,t,n.shardSplitThresholdBytes,n)){Pr("converting directory to sharded directory");let s=await N4(o,t);o.cid=s.cid,o.node=Se(await t.get(s.cid,n))}return o}var N4=async(r,e)=>{if(r.node.Data==null)throw new ot("Invalid parent passed to convertToShardedDirectory");let t=j.unmarshal(r.node.Data),n=await eE(e,r.node.Links.map(i=>({name:i.Name??"",size:BigInt(i.Tsize??0),cid:i.Hash})),{mode:t.mode,mtime:t.mtime,cidVersion:r.cid.version});return Pr(`converted directory to sharded directory ${n.cid}`),n},C4=async(r,e,t,n)=>{let i=r.node.Links.filter(l=>{let d=l.Name===e.Name;if(d&&!n.allowOverwriting)throw new wa;return!d});if(i.push(e),r.node.Data==null)throw new pt("Parent node with no data passed to addToDirectory");let o=j.unmarshal(r.node.Data),s;if(o.mtime!=null){let l=Date.now(),d=Math.floor(l/1e3);o.mtime={secs:BigInt(d),nsecs:(l-d*1e3)*1e3},s=o.marshal()}else s=r.node.Data;r.node=Te({Data:s,Links:i});let a=ce(r.node),c=await fe.digest(a),u=F.create(r.cid.version,ve,c);return await t.put(u,a),{node:r.node,cid:u}},L4=async(r,e,t,n)=>{let{path:i,hash:o}=await au(r.cid,e.Name,t,n),s=i[i.length-1];if(s==null)throw new Error("Invalid HAMT, could not generate path");let a=s.prefix,c=parseInt(a,16);Pr("next prefix for %s is %s",e.Name,a);let u=`${a}${e.Name}`,l=s.node.Links.find(d=>(d.Name??"").startsWith(a));if(l!=null)if(Pr("link %s was present in shard",u),l.Name===u){if(!n.allowOverwriting)throw new wa;Pr("overwriting %s in subshard",e.Name),s.node.Links=s.node.Links.filter(d=>d.Name!==u),s.node.Links.push({Name:u,Hash:e.Hash,Tsize:e.Tsize})}else{if(l.Name?.length===2)throw new Error("Existing link was subshard?!");{Pr("prefix %s already exists, creating new subshard",a);let d=s.node.Links.findIndex(y=>y.Name?.startsWith(a)),p=s.node.Links.splice(d,1)[0],f=(p.Name??"").substring(2),m=tu(Go)(H(f));for(let y=0;y<i.length;y++)await m.take(Fi);for(;;){let y=await m.take(Fi),g=ou(y);p.Name=`${g}${f}`;let E=await o.take(Fi),x=ou(E);if(g===x){let S=new o0.default;S.set(E,!0),i.push({prefix:x,children:S,node:{Links:[]}});continue}let _=new o0.default;_.set(E,!0),_.set(y,!0),i.push({prefix:a,children:_,node:{Links:[p,{Name:`${x}${e.Name}`,Hash:e.Hash,Tsize:e.Tsize}]}});break}}}else Pr("link %s was not present in sub-shard",u),e.Name=u,s.node.Links.push(e),s.children.set(c,!0),Pr("adding %s to existing sub-shard",u);return su(i,t,n)};async function oi(r,e,t={}){let n=await Ve(r,e,t);if(n.type!=="directory")throw new ii(`${r.toString()} was not a UnixFS directory`);return{cid:r,node:n.node}}async function Yo(r,e,t,n){let i=await Ve(r,t,n);if(i.type!=="directory"&&i.type!=="file"&&i.type!=="raw")throw new Or(`${r.toString()} was not a UnixFS node`);return{Name:e,Tsize:i.node instanceof Uint8Array?i.node.byteLength:U4(i.node),Hash:r}}function U4(r){let e=r.Links.reduce((t,n)=>t+(n.Tsize??0),0);return ce(r).byteLength+e}var s0=oe("helia:unixfs:components:utils:resolve");async function Fr(r,e,t,n){if(e==null||e==="")return{cid:r};s0('resolve "%s" under %c',e,r);let i=e.split("/").filter(Boolean),o=[{name:"",cid:r,size:0n}];for(let s=0;s<i.length;s++){let a=i[s],c=await Ve(r,t,n);if(s0('resolving "%s"',a,c),c.type==="file"){if(s<i.length-1)throw new ot("Path was invalid");r=c.cid}else if(c.type==="directory"){let u;for await(let l of c.content())if(l.name===a){u=l.cid;break}if(u==null)throw new Jl("Could not find path in directory");r=u,o.push({name:a,cid:r,size:c.size})}else throw new ot("Could not resolve path")}return s0("resolved %s to %c",e,r),{cid:r,path:e,segments:o}}async function Wo(r,e,t,n){if(e.segments==null||e.segments.length===0)return r;let i=e.segments.pop();if(i==null)throw new Error("Insufficient segments");i.cid=r,e.segments.reverse();for(let o of e.segments){let[s,a]=await Promise.all([oi(o.cid,t,n),Yo(i.cid,i.name,t,n)]);r=(await qo(s,a,t,{...n,allowOverwriting:!0,cidVersion:r.version})).cid,o.cid=r,i=o}return r}var D4=it.bind({ignoreUndefined:!0}),O4={};async function*rE(r,e,t={}){let n=D4(O4,t),i=await Fr(r,n.path,e,n),o=await Ve(i.cid,e,n);if(o.type!=="file"&&o.type!=="raw")throw new Ql;if(o.content==null)throw new Ko;yield*o.content(n)}var P4=it.bind({ignoreUndefined:!0}),F4=oe("helia:unixfs:chmod"),V4={recursive:!1,shardSplitThresholdBytes:262144};async function nE(r,e,t,n={}){let i=P4(V4,n),o=await Fr(r,i.path,t,n);if(F4("chmod %c %d",o.cid,e),i.recursive){let p=await gt(async function*(){for await(let f of Ho(o.cid,t,n)){let h,m=[];if(f.type==="raw")h=new j({type:"file",data:f.node});else if(f.type==="file"||f.type==="directory")h=f.unixfs,m=f.node.Links;else throw new Or;h.mode=e;let y={Data:h.marshal(),Links:m};yield{path:f.path,content:y}}},f=>ri(f,t,{...i,dagBuilder:async function*(h,m){for await(let y of h)yield async function(){let g=y.content,E=ce(g),x=await pr(E,m,{...i,cidVersion:r.version});if(g.Data==null)throw new pt(`${x} had no data`);let _=j.unmarshal(g.Data);return{cid:x,size:BigInt(E.length),path:y.path,unixfs:_}}}}),async f=>ni(f));if(p==null)throw new xn(`Could not chmod ${o.cid.toString()}`);return Wo(p.cid,o,t,i)}let s=await t.get(o.cid,n),a,c=[];if(o.cid.code===Ae)a=new j({type:"file",data:s});else{let p=Se(s);if(p.Data==null)throw new pt(`${o.cid.toString()} had no data`);c=p.Links,a=j.unmarshal(p.Data)}a.mode=e;let u=ce({Data:a.marshal(),Links:c}),l=await fe.digest(u),d=F.create(o.cid.version,ve,l);return await t.put(d,u),Wo(d,o,t,i)}var M4=it.bind({ignoreUndefined:!0}),H4=oe("helia:unixfs:cp"),$4={force:!1,shardSplitThresholdBytes:262144};async function iE(r,e,t,n,i={}){let o=M4($4,i);if(t.includes("/"))throw new ot("Name must not have slashes");let[s,a]=await Promise.all([oi(e,n,o),Yo(r,t,n,o)]);return H4('Adding %c as "%s" to %c',r,t,e),(await qo(s,a,n,{allowOverwriting:o.force,cidVersion:e.version,...o})).cid}var z4=it.bind({ignoreUndefined:!0}),K4={};async function*oE(r,e,t={}){let n=z4(K4,t),i=await Fr(r,n.path,e,n),o=await Ve(i.cid,e);if(o.type==="file"||o.type==="raw"){yield o;return}if(o.content==null)throw new Ko;if(o.type!=="directory")throw new ii;yield*o.content({offset:t.offset,length:t.length})}var G4=it.bind({ignoreUndefined:!0}),sE=oe("helia:unixfs:mkdir"),q4={cidVersion:1,force:!1,shardSplitThresholdBytes:262144};async function aE(r,e,t,n={}){let i=G4(q4,n);if(e.includes("/"))throw new ot("Path must not have slashes");if((await Ve(r,t,n)).type!=="directory")throw new ii(`${r.toString()} was not a UnixFS directory`);sE("creating %s",e);let a={Data:new j({type:"directory",mode:i.mode,mtime:i.mtime}).marshal(),Links:[]},c=ce(a),u=await fe.digest(c),l=F.create(i.cidVersion,ve,u);await t.put(l,c);let[d,p]=await Promise.all([oi(r,t,i),Yo(l,e,t,i)]);return sE("adding empty dir called %s to %c",e,r),(await qo(d,p,t,{...i,allowOverwriting:i.force})).cid}var lu=oe("helia:unixfs:utils:remove-link");async function cE(r,e,t,n){if(r.node.Data==null)throw new pt("Parent node had no data");if(j.unmarshal(r.node.Data).type==="hamt-sharded-directory"){lu(`removing ${e} from sharded directory`);let o=await W4(r,e,t,n);return await cu(o.node,t,n.shardSplitThresholdBytes,n)?o:(lu("converting shard to flat directory %c",r.cid),j4(o,t,n))}return lu(`removing link ${e} regular directory`),Y4(r,e,t,n)}var Y4=async(r,e,t,n)=>{r.node.Links=r.node.Links.filter(s=>s.Name!==e);let i=ce(r.node),o=await pr(i,t,{...n,cidVersion:r.cid.version});return lu(`Updated regular directory ${o}`),{node:r.node,cid:o}},W4=async(r,e,t,n)=>{let{path:i}=await au(r.cid,e,t,n),o=i[i.length-1];if(o==null)throw new Error("Invalid HAMT, could not generate path");let s=o.node.Links.filter(u=>(u.Name??"").substring(2)===e).map(u=>u.Name).pop();if(s==null)throw new Error("File not found");let a=s.substring(0,2),c=parseInt(a,16);if(o.node.Links=o.node.Links.filter(u=>u.Name!==s),o.children.unset(c),o.node.Links.length===1)for(;i.length!==1;){let u=i[i.length-1];if(u==null||u.node.Links.length>1)break;i.pop();let l=i[i.length-1];if(l==null)break;let d=u.node.Links[0];l.node.Links=l.node.Links.filter(p=>!(p.Name??"").startsWith(l.prefix)),l.node.Links.push({Hash:d.Hash,Name:`${l.prefix}${(d.Name??"").substring(2)}`,Tsize:d.Tsize})}return su(i,t,n)},j4=async(r,e,t)=>{if(r.node.Data==null)throw new ot("Invalid parent passed to convertToFlatDirectory");let n={Links:[]},i=await Ve(r.cid,e);if(i.type!=="directory")throw new Error("Unexpected node type");for await(let c of i.content()){let u=0;c.node instanceof Uint8Array?u=c.node.byteLength:u=ce(c.node).length,n.Links.push({Hash:c.cid,Name:c.name,Tsize:u})}let o=j.unmarshal(r.node.Data);n.Data=new j({type:"directory",mode:o.mode,mtime:o.mtime}).marshal();let s=ce(Te(n));return{cid:await pr(s,e,{codec:De,cidVersion:r.cid.version,signal:t.signal}),node:n}};var X4=it.bind({ignoreUndefined:!0}),Z4=oe("helia:unixfs:rm"),J4={shardSplitThresholdBytes:262144};async function lE(r,e,t,n={}){let i=X4(J4,n);if(e.includes("/"))throw new ot("Name must not have slashes");let o=await oi(r,t,i);return Z4("Removing %s from %c",e,r),(await cE(o,e,t,{...i,cidVersion:r.version})).cid}var Q4=it.bind({ignoreUndefined:!0}),eI=oe("helia:unixfs:stat"),tI={};async function uE(r,e,t={}){let n=Q4(tI,t),i=await Fr(r,t.path,e,n);eI("stat %c",i.cid);let o=await Ve(i.cid,e,n);if(o.type!=="file"&&o.type!=="directory"&&o.type!=="raw")throw new Or;let s=0n,a=0n,c=0n,u=0n,l=0,d,p,f=o.type,h;if(o.type==="raw"&&(s=BigInt(o.node.byteLength),a=BigInt(o.node.byteLength),c=BigInt(o.node.byteLength),u=BigInt(o.node.byteLength),l=1),o.type==="directory"&&(s=0n,a=BigInt(o.unixfs.marshal().byteLength),c=0n,u=a,l=1,d=o.unixfs.mode,p=o.unixfs.mtime,h=o.unixfs),o.type==="file"){let m=await dE(i.cid,e,n);s=o.unixfs.fileSize(),a=BigInt((o.node.Data?.byteLength??0)+o.node.Links.reduce((y,g)=>y+(g.Tsize??0),0)),c=BigInt(m.localFileSize),u=BigInt(m.localDagSize),l=m.blocks,d=o.unixfs.mode,p=o.unixfs.mtime,h=o.unixfs}return{cid:i.cid,mode:d,mtime:p,fileSize:s,dagSize:a,localFileSize:c,localDagSize:u,blocks:l,type:f,unixfs:h}}async function dE(r,e,t){let n={localFileSize:0,localDagSize:0,blocks:0};if(await e.has(r,t)){let i=await e.get(r,t);if(n.blocks++,n.localDagSize+=i.byteLength,r.code===Ae)n.localFileSize+=i.byteLength;else if(r.code===ve){let o=Se(i);if(o.Links.length>0)for(let s of o.Links){let a=await dE(s.Hash,e,t);n.localFileSize+=a.localFileSize,n.localDagSize+=a.localDagSize,n.blocks+=a.blocks}else{if(o.Data==null)throw new pt(`PBNode ${r.toString()} had no data`);let s=j.unmarshal(o.Data);if(s.data==null)throw new pt(`UnixFS node ${r.toString()} had no data`);n.localFileSize+=s.data.byteLength??0}}else throw new xn(`${r.toString()} was neither DAG_PB nor RAW`)}return n}var rI=it.bind({ignoreUndefined:!0}),nI=oe("helia:unixfs:touch"),iI={recursive:!1,shardSplitThresholdBytes:262144};async function fE(r,e,t={}){let n=rI(iI,t),i=await Fr(r,n.path,e,n),o=n.mtime??{secs:BigInt(Math.round(Date.now()/1e3)),nsecs:0};if(nI("touch %c %o",i.cid,o),n.recursive){let p=await gt(async function*(){for await(let f of Ho(i.cid,e)){let h,m;if(f.type==="raw")h=new j({data:f.node}),m=[];else if(f.type==="file"||f.type==="directory")h=f.unixfs,m=f.node.Links;else throw new Or;h.mtime=o;let y={Data:h.marshal(),Links:m};yield{path:f.path,content:y}}},f=>ri(f,e,{...n,dagBuilder:async function*(h,m){for await(let y of h)yield async function(){let g=y.content,E=ce(g),x=await pr(E,m,{...n,cidVersion:r.version});if(g.Data==null)throw new pt(`${x} had no data`);let _=j.unmarshal(g.Data);return{cid:x,size:BigInt(E.length),path:y.path,unixfs:_}}}}),async f=>ni(f));if(p==null)throw new xn(`Could not chmod ${i.cid.toString()}`);return Wo(p.cid,i,e,n)}let s=await e.get(i.cid,t),a,c=[];if(i.cid.code===Ae)a=new j({data:s});else{let p=Se(s);if(c=p.Links,p.Data==null)throw new pt(`${i.cid.toString()} had no data`);a=j.unmarshal(p.Data)}a.mtime=o;let u=ce({Data:a.marshal(),Links:c}),l=await fe.digest(u),d=F.create(i.cid.version,ve,l);return await e.put(d,u),Wo(d,i,e,n)}var a0=class{components;constructor(e){this.components=e}async*addAll(e,t={}){yield*w2(e,this.components.blockstore,t)}async addBytes(e,t={}){return E2(e,this.components.blockstore,t)}async addByteStream(e,t={}){return x2(e,this.components.blockstore,t)}async addFile(e,t={}){return b2(e,this.components.blockstore,t)}async addDirectory(e={},t={}){return v2(e,this.components.blockstore,t)}async*cat(e,t={}){yield*rE(e,this.components.blockstore,t)}async chmod(e,t,n={}){return nE(e,t,this.components.blockstore,n)}async cp(e,t,n,i={}){return iE(e,t,n,this.components.blockstore,i)}async*ls(e,t={}){yield*oE(e,this.components.blockstore,t)}async mkdir(e,t,n={}){return aE(e,t,this.components.blockstore,n)}async rm(e,t,n={}){return lE(e,t,this.components.blockstore,n)}async stat(e,t={}){return uE(e,this.components.blockstore,t)}async touch(e,t={}){return fE(e,this.components.blockstore,t)}};function hE(r){return new a0(r)}function uu(r,e={}){let t={_cancelled:!1,async start(){this._cancelled=!1},async pull(n){try{let{value:i,done:o}=await r.next();if(this._cancelled)return;if(o===!0){n.close();return}n.enqueue(i)}catch(i){n.error(i)}},cancel(){this._cancelled=!0}};return new globalThis.ReadableStream(t,e)}var oI=42;function sI(r){if(r[0]!==0)throw new Error("Invalid CID for CBOR tag 42; expected leading 0x00");return F.decode(r.subarray(1))}function pE(r){let e=[];e[oI]=sI;let t=ut(r,{allowIndefinite:!1,coerceUndefinedToNull:!0,allowNaN:!1,allowInfinity:!1,strict:!0,useMaps:!1,rejectDuplicateMapKeys:!0,tags:e,allowBigInt:!1});return new TextDecoder().decode(zs(t))}function mE(r){let e=aI(r);return e===r?`filename="${r}"`:`filename="${e}"; filename*=UTF-8''${encodeURIComponent(r)}`}function aI(r){return r.replace(/[^\x00-\x7F]/g,"_")}function yE({cid:r,reqFormat:e,weak:t,rangeStart:n,rangeEnd:i}){let o=t===!0?"W/":"",s=e==null?"":`.${e}`;return(n!=null||i!=null)&&(s+=`.${n??"0"}-${i??"N"}`),`${o}"${r.toString()}${s}"`}async function gE(r,e,t,n){let i=t.forComponent("helia:verified-fetch:get-stream-from-async-iterable"),o=r[Symbol.asyncIterator](),{value:s,done:a}=await o.next();if(a===!0)throw i.error("No content found for path",e),new Error("No content found");return{stream:new ReadableStream({async start(u){n?.onProgress?.(new V("verified-fetch:request:progress:chunk")),u.enqueue(s)},async pull(u){let{value:l,done:d}=await o.next();if(d===!0){l!=null&&(n?.onProgress?.(new V("verified-fetch:request:progress:chunk")),u.enqueue(l)),u.close();return}n?.onProgress?.(new V("verified-fetch:request:progress:chunk")),u.enqueue(l)}}),firstChunk:s}}var Xz=H("ustar\0","binary"),Zz=H("ustar ","binary"),Jz=H(" \0","binary");var vE=Q(EE(),1);function lI(r){return r[Symbol.asyncIterator]!=null}function uI(r){if(lI(r))return(async()=>{let n=new Uint8Array(0);for await(let i of r)n=we([n,i],n.length+i.length);return n})();let e=[],t=0;for(let n of r)e.push(n),t+=n.byteLength;return we(e,t)}var xE=uI;var dI="0000000000000000000",fI="7777777777777777777",hI=48,pI=H("ustar\0","binary"),mI=H("00","binary"),yI=parseInt("7777",8),gI=257,wI=263,EI=function(r){switch(r){case"file":return 0;case"link":return 1;case"symlink":return 2;case"character-device":return 3;case"block-device":return 4;case"directory":return 5;case"fifo":return 6;case"contiguous-file":return 7;case"pax-header":return 72;default:return 0}},xI=function(r){let e=256;for(let t=0;t<148;t++)e+=r[t];for(let t=156;t<512;t++)e+=r[t];return e},si=function(r,e){let t=r.toString(8);return t.length>e?H(fI.slice(0,e)+" "):H(dI.slice(0,e-t.length)+t+" ")},c0=function(r){let e=H(r).byteLength,t=Math.floor(Math.log(e)/Math.log(10))+1;return e+t>=Math.pow(10,t)&&t++,`${e+t}${r}`};function bE(r){let e="";r.name!=null&&(e+=c0(" path="+r.name+`
|
|
9
|
+
`)),r.linkname!=null&&(e+=c0(" linkpath="+r.linkname+`
|
|
10
|
+
`));let t=r.pax;if(t!=null)for(let n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e+=c0(" "+n+"="+t[n]+`
|
|
11
|
+
`));return H(e)}function du(r){let e=new Uint8Array(512),t=r.name,n="";if(r.typeflag===5&&t[t.length-1]!=="/"&&(t+="/"),H(t).byteLength!==t.length)return null;for(;H(t).byteLength>100;){let i=t.indexOf("/");if(i===-1)return null;n+=n!==""?"/"+t.slice(0,i):t.slice(0,i),t=t.slice(i+1)}return H(t).byteLength>100||H(n).byteLength>155||r.linkname!=null&&H(r.linkname).byteLength>100?null:(e.set(H(t),0),e.set(si(r.mode&yI,6),100),e.set(si(r.uid,6),108),e.set(si(r.gid,6),116),e.set(si(r.size,11),124),e.set(si(r.mtime.getTime()/1e3|0,11),136),e[156]=hI+EI(r.type),r.linkname!=null&&e.set(H(r.linkname),157),e.set(pI,gI),e.set(mI,wI),r.uname!=null&&e.set(H(r.uname),265),r.gname!=null&&e.set(H(r.gname),297),e.set(si(r.devmajor??0,6),329),e.set(si(r.devminor??0,6),337),n!=null&&e.set(H(n),345),e.set(si(xI(e),6),148),e)}var{S_IFMT:vI,S_IFBLK:AI,S_IFCHR:_I,S_IFDIR:SI,S_IFIFO:II,S_IFLNK:BI}=vE.default,kI=parseInt("755",8),RI=parseInt("644",8),AE=new Uint8Array(1024);function TI(r=0){switch(r&vI){case AI:return"block-device";case _I:return"character-device";case SI:return"directory";case II:return"fifo";case BI:return"symlink";default:return"file"}}function u0(r){return r&=511,r!==0?AE.subarray(0,512-r):new Uint8Array(0)}function l0(r){if(r.pax==null){let e=du(r);if(e!=null)return e}return NI(r)}function NI(r){let e=bE(r),t={name:"PaxHeader",mode:r.mode,uid:r.uid,gid:r.gid,size:e.length,mtime:r.mtime,type:"pax-header",linkname:r.linkname,uname:r.uname,gname:r.gname,devmajor:r.devmajor,devminor:r.devminor};return new $t(du(t)??new Uint8Array(0),e,u0(e.length),du({...t,size:r.size,type:r.type})??new Uint8Array(0)).subarray()}function fu(){return async function*(r){for await(let{header:e,body:t}of r){let n={...e,size:e.type==="symlink"?0:e.size??0,type:e.type??TI(e.mode),mode:e.mode??(e.type==="directory"?kI:RI),uid:e.uid??0,gid:e.gid??0,mtime:e.mtime??new Date};if(typeof t=="string"&&(t=H(t)),t instanceof Uint8Array||gr(t)){n.size=t.length,yield l0(n),yield gr(t)?t.subarray():t,yield u0(n.size);continue}if(n.type==="symlink"&&n.linkname==null){if(t==null)throw new Error("type was symlink but no linkname or body specified");n.linkname=J(await xE(t)),yield l0(n);continue}if(yield l0(n),n.type!=="file"&&n.type!=="contiguous-file")continue;let i=0;for await(let o of t??[])i+=o.length,yield gr(o)?o.subarray():o;if(i!==n.size)throw new Error(`size mismatch, wrote ${i} of ${n.size} bytes`);yield u0(n.size)}yield AE}}var CI=["file","raw","directory"];function LI(r){let e,t;return(r.type==="file"||r.type==="directory")&&(e=r.unixfs.mode,t=r.unixfs.mtime!=null?new Date(Number(r.unixfs.mtime.secs*1000n)):void 0),{name:r.path,mode:e,mtime:t,size:Number(r.size),type:r.type==="directory"?"directory":"file"}}function _E(r){if(!CI.includes(r.type))throw new O("Not a UnixFS node","ERR_NOT_UNIXFS");let e={header:LI(r)};return(r.type==="file"||r.type==="raw")&&(e.body=r.content()),e}async function*SE(r,e,t){let n=await Ve(r,e,t);if(n.type==="file"||n.type==="raw"){yield*gt([_E(n)],fu());return}if(n.type==="directory"){yield*gt(Ho(r,e,t),i=>at(i,o=>_E(o)),fu());return}throw new O("Not a UnixFS node","ERR_NOT_UNIXFS")}var IE=Q(yh(),1),hu=class{lru;constructor(e){this.lru=(0,IE.default)(e)}get(e){let t=this.lru.get(e);if(t!=null){if(t.expire!=null&&t.expire<Date.now()){this.lru.remove(e);return}return t.value}}set(e,t,n){this.lru.set(e,{value:t,expire:Date.now()+n})}has(e){return this.get(e)!=null}remove(e){this.lru.remove(e)}clear(){this.lru.clear()}};var d0=new hu(1e3),UI=/^(?<protocol>ip[fn]s):\/\/(?<cidOrPeerIdOrDnsLink>[^/$?]+)\/?(?<path>[^$?]*)\??(?<queryString>.*)$/;async function BE({urlString:r,ipns:e,logger:t},n){let i=t.forComponent("helia:verified-fetch:parse-url-string"),o=r.match(UI);if(o==null||o.groups==null)throw new TypeError(`Invalid URL: ${r}, please use ipfs:// or ipns:// URLs only.`);let{protocol:s,cidOrPeerIdOrDnsLink:a,path:c,queryString:u}=o.groups,l,d,p=[];if(s==="ipfs")try{l=F.parse(a)}catch(y){i.error(y),p.push(new TypeError("Invalid CID for ipfs://<cid> URL"))}else{let y=d0.get(a);if(y!=null)l=y.cid,d=y.path,i.trace("resolved %s to %c from cache",a,l);else{i.trace("Attempting to resolve PeerId for %s",a);let g=null;try{g=Jt(a),y=await e.resolve(g,{onProgress:n?.onProgress}),l=y?.cid,d=y?.path,i.trace("resolved %s to %c",a,l),d0.set(a,y,60*1e3*2)}catch(E){g==null?(i.error('Could not parse PeerId string "%s"',a,E),p.push(new TypeError(`Could not parse PeerId in ipns url "${a}", ${E.message}`))):(i.error("Could not resolve PeerId %c",g,E),p.push(new TypeError(`Could not resolve PeerId "${a}", ${E.message}`)))}if(l==null){i.trace("Attempting to resolve DNSLink for %s",a);try{y=await e.resolveDns(a,{onProgress:n?.onProgress}),l=y?.cid,d=y?.path,i.trace("resolved %s to %c",a,l),d0.set(a,y,60*1e3*2)}catch(E){i.error('Could not resolve DnsLink for "%s"',a,E),p.push(E)}}}}if(l==null)throw new AggregateError(p,`Invalid resource. Cannot determine CID from URL "${r}"`);let f={};if(u!=null&&u.length>0){let y=u.split("&");for(let g of y){let[E,x]=g.split("=");f[E]=decodeURIComponent(x)}f.download!=null&&(f.download=f.download==="true"),f.filename!=null&&(f.filename=f.filename.toString())}let h=[];c.length>0&&h.push(c),d!=null&&d.length>0&&h.push(d);let m=h.join("/");return{protocol:s,cid:l,path:m,query:f}}async function kE(r,{ipns:e,logger:t},n){if(typeof r=="string")return BE({urlString:r,ipns:e,logger:t},{onProgress:n?.onProgress});let i=F.asCID(r);if(i!=null)return{cid:i,protocol:"ipfs",path:"",query:{}};throw new TypeError(`Invalid resource. Cannot determine CID from resource: ${r}`)}function Vi(r){return new Response(r,{status:200,statusText:"OK"})}function pu(r){let e=new Response(r,{status:501,statusText:"Not Implemented"});return e.headers.set("X-Content-Type-Options","nosniff"),e}function jo(r){return new Response(r,{status:406,statusText:"Not Acceptable"})}var DI={[Yn]:["application/json","application/vnd.ipld.dag-cbor","application/cbor","application/vnd.ipld.dag-json","application/octet-stream","application/vnd.ipld.raw","application/vnd.ipfs.ipns-record","application/vnd.ipld.car"],[jn]:["application/json","application/vnd.ipld.dag-cbor","application/cbor","application/vnd.ipld.dag-json","application/octet-stream","application/vnd.ipld.raw","application/vnd.ipfs.ipns-record","application/vnd.ipld.car"],[Rn]:["application/json","application/vnd.ipld.dag-cbor","application/cbor","application/vnd.ipld.dag-json","application/octet-stream","application/vnd.ipld.raw","application/vnd.ipfs.ipns-record","application/vnd.ipld.car"],[ve]:["application/octet-stream","application/json","application/vnd.ipld.dag-cbor","application/cbor","application/vnd.ipld.dag-json","application/vnd.ipld.raw","application/vnd.ipfs.ipns-record","application/vnd.ipld.car","application/x-tar"],[Ae]:["application/octet-stream","application/vnd.ipld.raw","application/vnd.ipfs.ipns-record","application/vnd.ipld.car","application/x-tar"]};function RE(r,e){let t=DI[r.code];if(e!=null)return OI(e,t)}function OI(r,e){let t=r.split(",").map(n=>{let i=n.trim().split(";");return{mimeType:`${i[0]}`.trim(),weight:PI(i[1])}}).sort((n,i)=>n.weight===i.weight?0:n.weight>i.weight?-1:1).map(n=>n.mimeType);for(let n of t)for(let i of e)if(n.includes(i)||n==="*/*"||n.startsWith("*/")&&i.split("/")[1]===n.split("/")[1]||n.endsWith("/*")&&i.split("/")[0]===n.split("/")[0])return i}function PI(r){if(r!=null&&(r=r.trim()),r==null||!r.startsWith("q="))return 1;let e=parseFloat(r.replace("q=",""));return isNaN(e)?0:e}var FI={raw:"application/vnd.ipld.raw",car:"application/vnd.ipld.car","dag-json":"application/vnd.ipld.dag-json","dag-cbor":"application/vnd.ipld.dag-cbor",json:"application/json",cbor:"application/cbor","ipns-record":"application/vnd.ipfs.ipns-record",tar:"application/x-tar"};function TE(r){if(r!=null)return FI[r]}async function NE(r,e,t){let n=[],i;for await(let o of e0(e,r,t))n.push(o.cid),i=o;if(i==null)throw new Error("No terminal element found");return{ipfsRoots:n,terminalElement:i}}function VI(r){if(r==null)return;let e;return r?.signal===null&&(e=void 0),{...r,signal:e}}var MI=["application/vnd.ipld.raw","application/octet-stream"];function HI(r){let t=(new Headers(r).get("accept")??"").split(",").map(n=>n.split(";")[0]).map(n=>n.trim());for(let n of t){if(n==="*/*")return;if(MI.includes(n??""))return n}}var mu=class{helia;ipns;unixfs;log;contentTypeParser;constructor({helia:e,ipns:t,unixfs:n},i){this.helia=e,this.log=e.logger.forComponent("helia:verified-fetch"),this.ipns=t??Qg(e,{resolvers:[Ml("https://mozilla.cloudflare-dns.com/dns-query"),Ml("https://dns.google/resolve")]}),this.unixfs=n??hE(e),this.contentTypeParser=i?.contentTypeParser,this.log.trace("created VerifiedFetch instance")}async handleIPNSRecord(e,t){return pu("vnd.ipfs.ipns-record support is not implemented")}async handleCar({cid:e,options:t}){let n=Ug(this.helia),i=uu(n.stream(e,t)),o=Vi(i);return o.headers.set("content-type","application/vnd.ipld.car; version=1"),o}async handleTar({cid:e,path:t,options:n}){if(e.code!==ve&&e.code!==Ae)return jo("only UnixFS data can be returned in a TAR file");let i=uu(SE(`/ipfs/${e}/${t}`,this.helia.blockstore,n)),o=Vi(i);return o.headers.set("content-type","application/x-tar"),o}async handleJson({cid:e,path:t,accept:n,options:i}){this.log.trace("fetching %c/%s",e,t);let o=await this.helia.blockstore.get(e,i),s;if(n==="application/vnd.ipld.dag-cbor"||n==="application/cbor")try{let c=vl(o);s=Hs(c)}catch(c){return this.log.error("could not transform %c to application/vnd.ipld.dag-cbor",c),jo()}else s=o;let a=Vi(s);return a.headers.set("content-type",n??"application/json"),a}async handleDagCbor({cid:e,path:t,accept:n,options:i}){this.log.trace("fetching %c/%s",e,t);let o=await this.helia.blockstore.get(e,i),s;if(n==="application/octet-stream"||n==="application/vnd.ipld.dag-cbor"||n==="application/cbor")s=o;else if(n==="application/vnd.ipld.dag-json")try{let c=Ii(o);s=sg(c)}catch(c){return this.log.error("could not transform %c to application/vnd.ipld.dag-json",c),jo()}else try{s=pE(o)}catch(c){if(n==="application/json")return this.log('could not decode DAG-CBOR as JSON-safe, but the client sent "Accept: application/json"',c),jo();this.log("could not decode DAG-CBOR as JSON-safe, falling back to `application/octet-stream`",c),s=o}let a=Vi(s);return n==null&&(n=s instanceof Uint8Array?"application/octet-stream":"application/json"),a.headers.set("content-type",n),a}async handleDagPb({cid:e,path:t,options:n}){let i,o;try{let p=await NE(this.helia.blockstore,`${e.toString()}/${t}`,n);o=p.ipfsRoots,i=p.terminalElement}catch(p){this.log.error("Error walking path %s",t,p)}let s=i?.cid??e,a;if(i?.type==="directory"){let p=i.cid,f="index.html";try{this.log.trace("found directory at %c/%s, looking for index.html",e,t),a=await this.unixfs.stat(p,{path:f,signal:n?.signal,onProgress:n?.onProgress}),this.log.trace("found root file at %c/%s with cid %c",p,f,a.cid),t=f,s=a.cid}catch(h){return this.log("error loading path %c/%s",p,f,h),pu("Unable to find index.html for directory at given path. Support for directories with implicit root is not implemented")}finally{n?.onProgress?.(new V("verified-fetch:request:end",{cid:p,path:f}))}}let c=this.unixfs.cat(s,{signal:n?.signal,onProgress:n?.onProgress});this.log("got async iterator for %c/%s",e,t);let{stream:u,firstChunk:l}=await gE(c,t??"",this.helia.logger,{onProgress:n?.onProgress}),d=Vi(u);return await this.setContentType(l,t,d),o!=null&&d.headers.set("X-Ipfs-Roots",o.map(p=>p.toV1().toString()).join(",")),d}async handleRaw({cid:e,path:t,options:n}){let i=await this.helia.blockstore.get(e,n),o=Vi(i),s=HI(n?.headers);return s!=null?o.headers.set("content-type",s):await this.setContentType(i,t,o),o}async setContentType(e,t,n){let i="application/octet-stream";if(this.contentTypeParser!=null)try{let o=t.split("/").pop()?.trim();o=o===""?void 0:o;let s=this.contentTypeParser(e,o);if($I(s)){let a=await s;a!=null&&(i=a)}else s!=null&&(i=s)}catch(o){this.log.error("Error parsing content type",o)}n.headers.set("content-type",i)}codecHandlers={[ve]:this.handleDagPb,[jn]:this.handleJson,[Rn]:this.handleJson,[Yn]:this.handleDagCbor,[Ae]:this.handleRaw,[et.code]:this.handleRaw};async fetch(e,t){this.log("fetch %s",e);let n=VI(t);n?.onProgress?.(new V("verified-fetch:request:start",{resource:e}));let{path:i,query:o,cid:s}=await kE(e,{ipns:this.ipns,logger:this.helia.logger},n);n?.onProgress?.(new V("verified-fetch:request:resolve",{cid:s,path:i}));let c=new Headers(n?.headers).get("accept");c!=null&&this.log('incoming accept header "%s"',c);let u=TE(o.format);o.format!=null&&this.log('incoming query format "%s", mapped to %s',o.format,u);let l=c??u,d=RE(s,l);if(this.log("output type %s",d),l!=null&&d==null)return jo();let p,f;if(d==="application/vnd.ipfs.ipns-record")f="ipns-record",p=await this.handleIPNSRecord(e.toString(),n);else if(d==="application/vnd.ipld.car")f="car",o.download=!0,o.filename=o.filename??`${s.toString()}.car`,p=await this.handleCar({cid:s,path:i,options:n});else if(d==="application/vnd.ipld.raw")f="raw",o.download=!0,o.filename=o.filename??`${s.toString()}.bin`,p=await this.handleRaw({cid:s,path:i,options:n});else if(d==="application/x-tar")f="tar",o.download=!0,o.filename=o.filename??`${s.toString()}.tar`,p=await this.handleTar({cid:s,path:i,options:n});else{let m=this.codecHandlers[s.code];if(m==null)return pu(`Support for codec with code ${s.code} is not yet implemented. Please open an issue at https://github.com/ipfs/helia/issues/new`);p=await m.call(this,{cid:s,path:i,accept:d,options:n})}p.headers.set("etag",yE({cid:s,reqFormat:f,weak:!1})),p.headers.set("cache-control","public, max-age=29030400, immutable"),p.headers.set("X-Ipfs-Path",e.toString());let h;return o.download===!0&&(h="attachment"),o.filename!=null&&(h==null&&(h="inline"),h=`${h}; ${mE(o.filename)}`),h!=null&&p.headers.set("Content-Disposition",h),n?.onProgress?.(new V("verified-fetch:request:end",{cid:s,path:i})),p}async start(){await this.helia.start()}async stop(){await this.helia.stop()}};function $I(r){return r?.then!=null}var xa,yu=async function(e,t){return xa==null&&(xa=await f0()),xa(e,t)};yu.start=async function(){await xa?.start()};yu.stop=async function(){await xa?.stop()};async function f0(r,e){let t=e?.contentTypeParser;zI(r)||(r=await kg({blockBrokers:[is({gateways:r?.gateways})],routers:(r?.routers??["https://delegated-ipfs.dev"]).map(o=>Vs(o))}));let n=new mu({helia:r},{contentTypeParser:t});async function i(o,s){return n.fetch(o,s)}return i.stop=n.stop.bind(n),i.start=n.start.bind(n),i}function zI(r){return r?.blockstore!=null&&r?.datastore!=null&&r?.gc!=null&&r?.stop!=null&&r?.start!=null}return GE(KI);})();
|
|
12
12
|
/*! Bundled license information:
|
|
13
13
|
|
|
14
14
|
pvtsutils/build/index.js:
|