@helia/verified-fetch 1.1.3 → 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. package/dist/index.min.js +7 -7
  2. package/dist/src/types.d.ts +1 -0
  3. package/dist/src/types.d.ts.map +1 -1
  4. package/dist/src/utils/byte-range-context.d.ts +80 -0
  5. package/dist/src/utils/byte-range-context.d.ts.map +1 -0
  6. package/dist/src/utils/byte-range-context.js +277 -0
  7. package/dist/src/utils/byte-range-context.js.map +1 -0
  8. package/dist/src/utils/get-stream-from-async-iterable.js +1 -1
  9. package/dist/src/utils/parse-url-string.js +4 -4
  10. package/dist/src/utils/request-headers.d.ts +13 -0
  11. package/dist/src/utils/request-headers.d.ts.map +1 -0
  12. package/dist/src/utils/request-headers.js +62 -0
  13. package/dist/src/utils/request-headers.js.map +1 -0
  14. package/dist/src/utils/response-headers.d.ts +12 -0
  15. package/dist/src/utils/response-headers.d.ts.map +1 -0
  16. package/dist/src/utils/response-headers.js +37 -0
  17. package/dist/src/utils/response-headers.js.map +1 -0
  18. package/dist/src/utils/responses.d.ts +21 -4
  19. package/dist/src/utils/responses.d.ts.map +1 -1
  20. package/dist/src/utils/responses.js +58 -0
  21. package/dist/src/utils/responses.js.map +1 -1
  22. package/dist/src/verified-fetch.d.ts.map +1 -1
  23. package/dist/src/verified-fetch.js +60 -18
  24. package/dist/src/verified-fetch.js.map +1 -1
  25. package/package.json +1 -1
  26. package/src/types.ts +2 -0
  27. package/src/utils/byte-range-context.ts +301 -0
  28. package/src/utils/get-stream-from-async-iterable.ts +1 -1
  29. package/src/utils/parse-url-string.ts +4 -4
  30. package/src/utils/request-headers.ts +63 -0
  31. package/src/utils/response-headers.ts +42 -0
  32. package/src/utils/responses.ts +82 -4
  33. package/src/verified-fetch.ts +65 -21
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 Uw=Object.create;var Rs=Object.defineProperty;var Fw=Object.getOwnPropertyDescriptor;var Vw=Object.getOwnPropertyNames;var Hw=Object.getPrototypeOf,Mw=Object.prototype.hasOwnProperty;var Ee=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),ve=(r,e)=>{for(var t in e)Rs(r,t,{get:e[t],enumerable:!0})},Xd=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Vw(e))!Mw.call(r,o)&&o!==t&&Rs(r,o,{get:()=>e[o],enumerable:!(n=Fw(e,o))||n.enumerable});return r};var J=(r,e,t)=>(t=r!=null?Uw(Hw(r)):{},Xd(e||!r||!r.__esModule?Rs(t,"default",{value:r,enumerable:!0}):t,r)),zw=r=>Xd(Rs({},"__esModule",{value:!0}),r);var ph=Ee((B_,hh)=>{var ro=1e3,no=ro*60,oo=no*60,Sn=oo*24,C2=Sn*7,L2=Sn*365.25;hh.exports=function(r,e){e=e||{};var t=typeof r;if(t==="string"&&r.length>0)return D2(r);if(t==="number"&&isFinite(r))return e.long?O2(r):P2(r);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(r))};function D2(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*L2;case"weeks":case"week":case"w":return t*C2;case"days":case"day":case"d":return t*Sn;case"hours":case"hour":case"hrs":case"hr":case"h":return t*oo;case"minutes":case"minute":case"mins":case"min":case"m":return t*no;case"seconds":case"second":case"secs":case"sec":case"s":return t*ro;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return t;default:return}}}}function P2(r){var e=Math.abs(r);return e>=Sn?Math.round(r/Sn)+"d":e>=oo?Math.round(r/oo)+"h":e>=no?Math.round(r/no)+"m":e>=ro?Math.round(r/ro)+"s":r+"ms"}function O2(r){var e=Math.abs(r);return e>=Sn?Cs(r,e,Sn,"day"):e>=oo?Cs(r,e,oo,"hour"):e>=no?Cs(r,e,no,"minute"):e>=ro?Cs(r,e,ro,"second"):r+" ms"}function Cs(r,e,t,n){var o=e>=t*1.5;return Math.round(r/t)+" "+n+(o?"s":"")}});var yh=Ee((R_,mh)=>{function U2(r){t.debug=t,t.default=t,t.coerce=c,t.disable=i,t.enable=o,t.enabled=s,t.humanize=ph(),t.destroy=u,Object.keys(r).forEach(l=>{t[l]=r[l]}),t.names=[],t.skips=[],t.formatters={};function e(l){let f=0;for(let m=0;m<l.length;m++)f=(f<<5)-f+l.charCodeAt(m),f|=0;return t.colors[Math.abs(f)%t.colors.length]}t.selectColor=e;function t(l){let f,m=null,d,p;function h(...g){if(!h.enabled)return;let y=h,x=Number(new Date),b=x-(f||x);y.diff=b,y.prev=f,y.curr=x,f=x,g[0]=t.coerce(g[0]),typeof g[0]!="string"&&g.unshift("%O");let S=0;g[0]=g[0].replace(/%([a-zA-Z%])/g,(A,v)=>{if(A==="%%")return"%";S++;let E=t.formatters[v];if(typeof E=="function"){let R=g[S];A=E.call(y,R),g.splice(S,1),S--}return A}),t.formatArgs.call(y,g),(y.log||t.log).apply(y,g)}return h.namespace=l,h.useColors=t.useColors(),h.color=t.selectColor(l),h.extend=n,h.destroy=t.destroy,Object.defineProperty(h,"enabled",{enumerable:!0,configurable:!1,get:()=>m!==null?m:(d!==t.namespaces&&(d=t.namespaces,p=t.enabled(l)),p),set:g=>{m=g}}),typeof t.init=="function"&&t.init(h),h}function n(l,f){let m=t(this.namespace+(typeof f>"u"?":":f)+l);return m.log=this.log,m}function o(l){t.save(l),t.namespaces=l,t.names=[],t.skips=[];let f,m=(typeof l=="string"?l:"").split(/[\s,]+/),d=m.length;for(f=0;f<d;f++)m[f]&&(l=m[f].replace(/\*/g,".*?"),l[0]==="-"?t.skips.push(new RegExp("^"+l.slice(1)+"$")):t.names.push(new RegExp("^"+l+"$")))}function i(){let l=[...t.names.map(a),...t.skips.map(a).map(f=>"-"+f)].join(",");return t.enable(""),l}function s(l){if(l[l.length-1]==="*")return!0;let f,m;for(f=0,m=t.skips.length;f<m;f++)if(t.skips[f].test(l))return!1;for(f=0,m=t.names.length;f<m;f++)if(t.names[f].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}mh.exports=U2});var gh=Ee((ht,Ls)=>{ht.formatArgs=V2;ht.save=H2;ht.load=M2;ht.useColors=F2;ht.storage=z2();ht.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`."))}})();ht.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 F2(){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 V2(r){if(r[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+r[0]+(this.useColors?"%c ":" ")+"+"+Ls.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,o=>{o!=="%%"&&(t++,o==="%c"&&(n=t))}),r.splice(n,0,e)}ht.log=console.debug||console.log||(()=>{});function H2(r){try{r?ht.storage.setItem("debug",r):ht.storage.removeItem("debug")}catch{}}function M2(){let r;try{r=ht.storage.getItem("debug")}catch{}return!r&&typeof process<"u"&&"env"in process&&(r=process.env.DEBUG),r}function z2(){try{return localStorage}catch{}}Ls.exports=yh()(ht);var{formatters:$2}=Ls.exports;$2.j=function(r){try{return JSON.stringify(r)}catch(e){return"[UnexpectedJSONParseError]: "+e.message}}});var Eh=Ee((O_,xh)=>{xh.exports=Vl;var bh=128,j2=127,Y2=~j2,X2=Math.pow(2,31);function Vl(r,e,t){if(Number.MAX_SAFE_INTEGER&&r>Number.MAX_SAFE_INTEGER)throw Vl.bytes=0,new RangeError("Could not encode varint");e=e||[],t=t||0;for(var n=t;r>=X2;)e[t++]=r&255|bh,r/=128;for(;r&Y2;)e[t++]=r&255|bh,r>>>=7;return e[t]=r|0,Vl.bytes=t-n+1,e}});var Sh=Ee((U_,Ah)=>{Ah.exports=Hl;var Z2=128,vh=127;function Hl(r,n){var t=0,n=n||0,o=0,i=n,s,a=r.length;do{if(i>=a||o>49)throw Hl.bytes=0,new RangeError("Could not decode varint");s=r[i++],t+=o<28?(s&vh)<<o:(s&vh)*Math.pow(2,o),o+=7}while(s>=Z2);return Hl.bytes=i-n,t}});var kh=Ee((F_,_h)=>{var J2=Math.pow(2,7),Q2=Math.pow(2,14),eb=Math.pow(2,21),tb=Math.pow(2,28),rb=Math.pow(2,35),nb=Math.pow(2,42),ob=Math.pow(2,49),ib=Math.pow(2,56),sb=Math.pow(2,63);_h.exports=function(r){return r<J2?1:r<Q2?2:r<eb?3:r<tb?4:r<rb?5:r<nb?6:r<ob?7:r<ib?8:r<sb?9:10}});var Ds=Ee((V_,Ih)=>{Ih.exports={encode:Eh(),decode:Sh(),encodingLength:kh()}});var Ie=Ee((r5,qh)=>{"use strict";function Gh(r,e){for(let t in e)Object.defineProperty(r,t,{value:e[t],enumerable:!0,configurable:!0});return r}function Mb(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 Gh(r,t)}catch{t.message=r.message,t.stack=r.stack;let o=function(){};return o.prototype=Object.create(Object.getPrototypeOf(r)),Gh(new o,t)}}qh.exports=Mb});var $p=Ee(Io=>{"use strict";var NE="[object ArrayBuffer]",Er=class r{static isArrayBuffer(e){return Object.prototype.toString.call(e)===NE}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),o=r.toUint8Array(t);if(n.length!==o.byteLength)return!1;for(let i=0;i<n.length;i++)if(n[i]!==o[i])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 o=new Uint8Array(n),i=0;for(let s of t){let a=this.toUint8Array(s);o.set(a,i),i+=a.length}return e[e.length-1]instanceof Function?this.toView(o,e[e.length-1]):o.buffer}},Wu="string",CE=/^[0-9a-f]+$/i,LE=/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/,DE=/^[a-zA-Z0-9-_]+$/,ua=class{static fromString(e){let t=unescape(encodeURIComponent(e)),n=new Uint8Array(t.length);for(let o=0;o<t.length;o++)n[o]=t.charCodeAt(o);return n.buffer}static toString(e){let t=Er.toUint8Array(e),n="";for(let i=0;i<t.length;i++)n+=String.fromCharCode(t[i]);return decodeURIComponent(escape(n))}},Ct=class{static toString(e,t=!1){let n=Er.toArrayBuffer(e),o=new DataView(n),i="";for(let s=0;s<n.byteLength;s+=2){let a=o.getUint16(s,t);i+=String.fromCharCode(a)}return i}static fromString(e,t=!1){let n=new ArrayBuffer(e.length*2),o=new DataView(n);for(let i=0;i<e.length;i++)o.setUint16(i*2,e.charCodeAt(i),t);return n}},fa=class r{static isHex(e){return typeof e===Wu&&CE.test(e)}static isBase64(e){return typeof e===Wu&&LE.test(e)}static isBase64Url(e){return typeof e===Wu&&DE.test(e)}static ToString(e,t="utf8"){let n=Er.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 Ct.toString(n,!0);case"utf16":case"utf16be":return Ct.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 Ct.fromString(e,!0);case"utf16":case"utf16be":return Ct.fromString(e);default:throw new Error(`Unknown type of encoding '${t}'`)}}static ToBase64(e){let t=Er.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 ua.fromString(e);case"utf16":case"utf16be":return Ct.fromString(e);case"utf16le":case"usc2":return Ct.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 ua.toString(e);case"utf16":case"utf16be":return Ct.toString(e);case"utf16le":case"usc2":return Ct.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 o=0;o<t;o++)n[o]=e.charCodeAt(o);return n.buffer}static ToBinary(e){let t=Er.toUint8Array(e),n="";for(let o=0;o<t.length;o++)n+=String.fromCharCode(t[o]);return n}static ToHex(e){let t=Er.toUint8Array(e),n="",o=t.length;for(let i=0;i<o;i++){let s=t[i];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 o=0;o<t.length;o=o+2){let i=t.slice(o,o+2);n[o/2]=parseInt(i,16)}return n.buffer}static ToUtf16String(e,t=!1){return Ct.toString(e,t)}static FromUtf16String(e,t=!1){return Ct.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,"")||""}};fa.DEFAULT_UTF8_ENCODING="utf8";function PE(r,...e){let t=arguments[0];for(let n=1;n<arguments.length;n++){let o=arguments[n];for(let i in o)t[i]=o[i]}return t}function OE(...r){let e=r.map(o=>o.byteLength).reduce((o,i)=>o+i),t=new Uint8Array(e),n=0;return r.map(o=>new Uint8Array(o)).forEach(o=>{for(let i of o)t[n++]=i}),t.buffer}function UE(r,e){if(!(r&&e)||r.byteLength!==e.byteLength)return!1;let t=new Uint8Array(r),n=new Uint8Array(e);for(let o=0;o<r.byteLength;o++)if(t[o]!==n[o])return!1;return!0}Io.BufferSourceConverter=Er;Io.Convert=fa;Io.assign=PE;Io.combine=OE;Io.isEqual=UE});var ec=Ee((EB,lf)=>{var xB=function(){typeof lf<"u"&&(lf.exports=h);var r=86400,e=3200,t=146097*e/400,n=r*t,o=1e3*n,i=864e13,s=4294967296,a=1e6,c="000000000",u=Math.trunc||function(E){var R=E-E%1;return R==0&&(E<0||E===0&&1/E!=1/0)?-0:R},l=h.prototype,f=(h.fromDate=function(E){return new h(+E)},h.fromInt64BE=S(0,1,2,3,0,4),h.fromInt64LE=S(3,2,1,0,4,0),h.fromString=function(T){var R,N=new h,T=(T+="").replace(/^\s*[+\-]?\d+/,function(D){var D=+D,Q=1970+(D-1970)%400;return N.year=D-Q,Q}).replace(/(?:Z|([+\-]\d{2}):?(\d{2}))$/,function(H,D,Q){return D<0&&(Q*=-1),R=6e4*(60*+D+ +Q),""}).replace(/\.\d+$/,function(H){return N.nano=+(H+c).substr(1,9),""}).split(/\D+/);if(1<T.length?T[1]--:T[1]=0,N.time=R=Date.UTC.apply(Date,T)-(R||0),isNaN(R))throw new TypeError("Invalid Date");return g(N)},h.fromTimeT=function(E){return x(E,0)},l.year=0,l.time=0,l.nano=0,l.addNano=function(E){return this.nano+=+E||0,this},l.getNano=function(){var E=g(this);return(E.time%1e3*a+ +E.nano+1e9)%1e9},l.getTimeT=function(){var R=g(this),E=Math.floor(R.time/1e3),R=R.year;return R&&(E+=R*t*r/e),E},l.getYear=function(){return this.toDate().getUTCFullYear()+this.year},l.toDate=function(){return y(g(this).time)},l.toJSON=function(){return this.toString().replace(/0{1,6}Z$/,"Z")},l.toString=function(E){var R=this,N=R.toDate(),T={H:function(){return A(N.getUTCHours())},L:function(){return v(N.getUTCMilliseconds(),3)},M:function(){return A(N.getUTCMinutes())},N:function(){return v(R.getNano(),9)},S:function(){return A(N.getUTCSeconds())},Y:function(){var H=R.getYear();return 999999<H?"+"+H:9999<H?"+"+v(H,6):0<=H?v(H,4):-999999<=H?"-"+v(-H,6):H},a:function(){return d[N.getUTCDay()]},b:function(){return m[N.getUTCMonth()]},d:function(){return A(N.getUTCDate())},e:function(){return function(H){return(9<H?"":" ")+(0|H)}(N.getUTCDate())},m:function(){return A(N.getUTCMonth()+1)}};return function H(D){return D.replace(/%./g,function(Q){var L=Q[1],k=p[L],L=T[L];return k?H(k):L?L():Q})}(E||f)},l.writeInt64BE=b(0,1,2,3,0,4),l.writeInt64LE=b(3,2,1,0,4,0),"%Y-%m-%dT%H:%M:%S.%NZ"),m=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],d=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],p={"%":"%",F:"%Y-%m-%d",n:`
3
- `,R:"%H:%M",T:"%H:%M:%S",t:" ",X:"%T",Z:"GMT",z:"+0000"};return h;function h(E,R,N){var T=this;if(!(T instanceof h))return new h(E,R,N);T.time=+E||0,T.nano=+R||0,T.year=+N||0,g(T)}function g(E){var R,N,T,H=E.year,D=E.time,Q=E.nano,k=((Q<0||a<=Q)&&(Q-=(N=Math.floor(Q/a))*a,D+=N,N=1),H%e);return(D<-i||i<D||k)&&((R=u(D/o))&&(H+=R*e,D-=R*o),(T=y(D)).setUTCFullYear(k+T.getUTCFullYear()),T=(D=+T)+(R=u((H-=k)/e))*o,R&&-i<=T&&T<=i&&(H-=R*e,D=T),N=1),N&&(E.year=H,E.time=D,E.nano=Q),E}function y(E){var R=new Date(0);return R.setTime(E),R}function x(H,T){H=+H||0;var N=u((T=(T|0)*s)/n)+u(H/n),T=T%n+H%n,H=u(T/n);return H&&(N+=H,T-=H*n),new h(1e3*T,0,N*e)}function b(E,R,N,T,H,D){return function(k,L){var C=g(this);k=k||new Array(8),_(k,L|=0);var I=Math.floor(C.time/1e3),C=C.year*(t*r/e),q=u(C/s)+u(I/s),C=C%s+I%s,I=Math.floor(C/s);return I&&(q+=I,C-=I*s),Q(k,L+H,q),Q(k,L+D,C),k};function Q(k,L,q){k[L+E]=q>>24&255,k[L+R]=q>>16&255,k[L+N]=q>>8&255,k[L+T]=255&q}}function S(E,R,N,T,H,D){return function(k,L){_(k,L|=0);var q=Q(k,L+H);return x(Q(k,L+D),q)};function Q(k,L){return 16777216*k[L+E]+(k[L+R]<<16|k[L+N]<<8|k[L+T])}}function _(E,R){if(E=E&&E.length,E==null)throw new TypeError("Invalid Buffer");if(E<R+8)throw new RangeError("Out of range")}function A(E){return(9<E?"":"0")+(0|E)}function v(E,R){return(c+(0|E)).substr(-R)}}()});var g1=Ee((oT,Sf)=>{"use strict";var e6=Object.prototype.hasOwnProperty,nt="~";function zi(){}Object.create&&(zi.prototype=Object.create(null),new zi().__proto__||(nt=!1));function t6(r,e,t){this.fn=r,this.context=e,this.once=t||!1}function y1(r,e,t,n,o){if(typeof t!="function")throw new TypeError("The listener must be a function");var i=new t6(t,n||r,o),s=nt?nt+e:e;return r._events[s]?r._events[s].fn?r._events[s]=[r._events[s],i]:r._events[s].push(i):(r._events[s]=i,r._eventsCount++),r}function gc(r,e){--r._eventsCount===0?r._events=new zi:delete r._events[e]}function Ye(){this._events=new zi,this._eventsCount=0}Ye.prototype.eventNames=function(){var e=[],t,n;if(this._eventsCount===0)return e;for(n in t=this._events)e6.call(t,n)&&e.push(nt?n.slice(1):n);return Object.getOwnPropertySymbols?e.concat(Object.getOwnPropertySymbols(t)):e};Ye.prototype.listeners=function(e){var t=nt?nt+e:e,n=this._events[t];if(!n)return[];if(n.fn)return[n.fn];for(var o=0,i=n.length,s=new Array(i);o<i;o++)s[o]=n[o].fn;return s};Ye.prototype.listenerCount=function(e){var t=nt?nt+e:e,n=this._events[t];return n?n.fn?1:n.length:0};Ye.prototype.emit=function(e,t,n,o,i,s){var a=nt?nt+e:e;if(!this._events[a])return!1;var c=this._events[a],u=arguments.length,l,f;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,o),!0;case 5:return c.fn.call(c.context,t,n,o,i),!0;case 6:return c.fn.call(c.context,t,n,o,i,s),!0}for(f=1,l=new Array(u-1);f<u;f++)l[f-1]=arguments[f];c.fn.apply(c.context,l)}else{var m=c.length,d;for(f=0;f<m;f++)switch(c[f].once&&this.removeListener(e,c[f].fn,void 0,!0),u){case 1:c[f].fn.call(c[f].context);break;case 2:c[f].fn.call(c[f].context,t);break;case 3:c[f].fn.call(c[f].context,t,n);break;case 4:c[f].fn.call(c[f].context,t,n,o);break;default:if(!l)for(d=1,l=new Array(u-1);d<u;d++)l[d-1]=arguments[d];c[f].fn.apply(c[f].context,l)}}return!0};Ye.prototype.on=function(e,t,n){return y1(this,e,t,n,!1)};Ye.prototype.once=function(e,t,n){return y1(this,e,t,n,!0)};Ye.prototype.removeListener=function(e,t,n,o){var i=nt?nt+e:e;if(!this._events[i])return this;if(!t)return gc(this,i),this;var s=this._events[i];if(s.fn)s.fn===t&&(!o||s.once)&&(!n||s.context===n)&&gc(this,i);else{for(var a=0,c=[],u=s.length;a<u;a++)(s[a].fn!==t||o&&!s[a].once||n&&s[a].context!==n)&&c.push(s[a]);c.length?this._events[i]=c.length===1?c[0]:c:gc(this,i)}return this};Ye.prototype.removeAllListeners=function(e){var t;return e?(t=nt?nt+e:e,this._events[t]&&gc(this,t)):(this._events=new zi,this._eventsCount=0),this};Ye.prototype.off=Ye.prototype.removeListener;Ye.prototype.addListener=Ye.prototype.on;Ye.prefixed=nt;Ye.EventEmitter=Ye;typeof Sf<"u"&&(Sf.exports=Ye)});var Cf=Ee((sN,I1)=>{I1.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 o(i,s){t[i]=s,e++,e>=r&&(e=0,n=t,t=Object.create(null))}return{has:function(i){return t[i]!==void 0||n[i]!==void 0},remove:function(i){t[i]!==void 0&&(t[i]=void 0),n[i]!==void 0&&(n[i]=void 0)},get:function(i){var s=t[i];if(s!==void 0)return s;if((s=n[i])!==void 0)return o(i,s),s},set:function(i,s){t[i]!==void 0?t[i]=s:o(i,s)},clear:function(){t=Object.create(null),n=Object.create(null)}}}});var Uy=Ee((ms,qc)=>{(function(r,e){"use strict";var t={version:"3.0.0",x86:{},x64:{},inputValidation:!0};function n(d){if(!Array.isArray(d)&&!ArrayBuffer.isView(d))return!1;for(var p=0;p<d.length;p++)if(!Number.isInteger(d[p])||d[p]<0||d[p]>255)return!1;return!0}function o(d,p){return(d&65535)*p+(((d>>>16)*p&65535)<<16)}function i(d,p){return d<<p|d>>>32-p}function s(d){return d^=d>>>16,d=o(d,2246822507),d^=d>>>13,d=o(d,3266489909),d^=d>>>16,d}function a(d,p){d=[d[0]>>>16,d[0]&65535,d[1]>>>16,d[1]&65535],p=[p[0]>>>16,p[0]&65535,p[1]>>>16,p[1]&65535];var h=[0,0,0,0];return h[3]+=d[3]+p[3],h[2]+=h[3]>>>16,h[3]&=65535,h[2]+=d[2]+p[2],h[1]+=h[2]>>>16,h[2]&=65535,h[1]+=d[1]+p[1],h[0]+=h[1]>>>16,h[1]&=65535,h[0]+=d[0]+p[0],h[0]&=65535,[h[0]<<16|h[1],h[2]<<16|h[3]]}function c(d,p){d=[d[0]>>>16,d[0]&65535,d[1]>>>16,d[1]&65535],p=[p[0]>>>16,p[0]&65535,p[1]>>>16,p[1]&65535];var h=[0,0,0,0];return h[3]+=d[3]*p[3],h[2]+=h[3]>>>16,h[3]&=65535,h[2]+=d[2]*p[3],h[1]+=h[2]>>>16,h[2]&=65535,h[2]+=d[3]*p[2],h[1]+=h[2]>>>16,h[2]&=65535,h[1]+=d[1]*p[3],h[0]+=h[1]>>>16,h[1]&=65535,h[1]+=d[2]*p[2],h[0]+=h[1]>>>16,h[1]&=65535,h[1]+=d[3]*p[1],h[0]+=h[1]>>>16,h[1]&=65535,h[0]+=d[0]*p[3]+d[1]*p[2]+d[2]*p[1]+d[3]*p[0],h[0]&=65535,[h[0]<<16|h[1],h[2]<<16|h[3]]}function u(d,p){return p%=64,p===32?[d[1],d[0]]:p<32?[d[0]<<p|d[1]>>>32-p,d[1]<<p|d[0]>>>32-p]:(p-=32,[d[1]<<p|d[0]>>>32-p,d[0]<<p|d[1]>>>32-p])}function l(d,p){return p%=64,p===0?d:p<32?[d[0]<<p|d[1]>>>32-p,d[1]<<p]:[d[1]<<p-32,0]}function f(d,p){return[d[0]^p[0],d[1]^p[1]]}function m(d){return d=f(d,[0,d[0]>>>1]),d=c(d,[4283543511,3981806797]),d=f(d,[0,d[0]>>>1]),d=c(d,[3301882366,444984403]),d=f(d,[0,d[0]>>>1]),d}t.x86.hash32=function(d,p){if(t.inputValidation&&!n(d))return e;p=p||0;for(var h=d.length%4,g=d.length-h,y=p,x=0,b=3432918353,S=461845907,_=0;_<g;_=_+4)x=d[_]|d[_+1]<<8|d[_+2]<<16|d[_+3]<<24,x=o(x,b),x=i(x,15),x=o(x,S),y^=x,y=i(y,13),y=o(y,5)+3864292196;switch(x=0,h){case 3:x^=d[_+2]<<16;case 2:x^=d[_+1]<<8;case 1:x^=d[_],x=o(x,b),x=i(x,15),x=o(x,S),y^=x}return y^=d.length,y=s(y),y>>>0},t.x86.hash128=function(d,p){if(t.inputValidation&&!n(d))return e;p=p||0;for(var h=d.length%16,g=d.length-h,y=p,x=p,b=p,S=p,_=0,A=0,v=0,E=0,R=597399067,N=2869860233,T=951274213,H=2716044179,D=0;D<g;D=D+16)_=d[D]|d[D+1]<<8|d[D+2]<<16|d[D+3]<<24,A=d[D+4]|d[D+5]<<8|d[D+6]<<16|d[D+7]<<24,v=d[D+8]|d[D+9]<<8|d[D+10]<<16|d[D+11]<<24,E=d[D+12]|d[D+13]<<8|d[D+14]<<16|d[D+15]<<24,_=o(_,R),_=i(_,15),_=o(_,N),y^=_,y=i(y,19),y+=x,y=o(y,5)+1444728091,A=o(A,N),A=i(A,16),A=o(A,T),x^=A,x=i(x,17),x+=b,x=o(x,5)+197830471,v=o(v,T),v=i(v,17),v=o(v,H),b^=v,b=i(b,15),b+=S,b=o(b,5)+2530024501,E=o(E,H),E=i(E,18),E=o(E,R),S^=E,S=i(S,13),S+=y,S=o(S,5)+850148119;switch(_=0,A=0,v=0,E=0,h){case 15:E^=d[D+14]<<16;case 14:E^=d[D+13]<<8;case 13:E^=d[D+12],E=o(E,H),E=i(E,18),E=o(E,R),S^=E;case 12:v^=d[D+11]<<24;case 11:v^=d[D+10]<<16;case 10:v^=d[D+9]<<8;case 9:v^=d[D+8],v=o(v,T),v=i(v,17),v=o(v,H),b^=v;case 8:A^=d[D+7]<<24;case 7:A^=d[D+6]<<16;case 6:A^=d[D+5]<<8;case 5:A^=d[D+4],A=o(A,N),A=i(A,16),A=o(A,T),x^=A;case 4:_^=d[D+3]<<24;case 3:_^=d[D+2]<<16;case 2:_^=d[D+1]<<8;case 1:_^=d[D],_=o(_,R),_=i(_,15),_=o(_,N),y^=_}return y^=d.length,x^=d.length,b^=d.length,S^=d.length,y+=x,y+=b,y+=S,x+=y,b+=y,S+=y,y=s(y),x=s(x),b=s(b),S=s(S),y+=x,y+=b,y+=S,x+=y,b+=y,S+=y,("00000000"+(y>>>0).toString(16)).slice(-8)+("00000000"+(x>>>0).toString(16)).slice(-8)+("00000000"+(b>>>0).toString(16)).slice(-8)+("00000000"+(S>>>0).toString(16)).slice(-8)},t.x64.hash128=function(d,p){if(t.inputValidation&&!n(d))return e;p=p||0;for(var h=d.length%16,g=d.length-h,y=[0,p],x=[0,p],b=[0,0],S=[0,0],_=[2277735313,289559509],A=[1291169091,658871167],v=0;v<g;v=v+16)b=[d[v+4]|d[v+5]<<8|d[v+6]<<16|d[v+7]<<24,d[v]|d[v+1]<<8|d[v+2]<<16|d[v+3]<<24],S=[d[v+12]|d[v+13]<<8|d[v+14]<<16|d[v+15]<<24,d[v+8]|d[v+9]<<8|d[v+10]<<16|d[v+11]<<24],b=c(b,_),b=u(b,31),b=c(b,A),y=f(y,b),y=u(y,27),y=a(y,x),y=a(c(y,[0,5]),[0,1390208809]),S=c(S,A),S=u(S,33),S=c(S,_),x=f(x,S),x=u(x,31),x=a(x,y),x=a(c(x,[0,5]),[0,944331445]);switch(b=[0,0],S=[0,0],h){case 15:S=f(S,l([0,d[v+14]],48));case 14:S=f(S,l([0,d[v+13]],40));case 13:S=f(S,l([0,d[v+12]],32));case 12:S=f(S,l([0,d[v+11]],24));case 11:S=f(S,l([0,d[v+10]],16));case 10:S=f(S,l([0,d[v+9]],8));case 9:S=f(S,[0,d[v+8]]),S=c(S,A),S=u(S,33),S=c(S,_),x=f(x,S);case 8:b=f(b,l([0,d[v+7]],56));case 7:b=f(b,l([0,d[v+6]],48));case 6:b=f(b,l([0,d[v+5]],40));case 5:b=f(b,l([0,d[v+4]],32));case 4:b=f(b,l([0,d[v+3]],24));case 3:b=f(b,l([0,d[v+2]],16));case 2:b=f(b,l([0,d[v+1]],8));case 1:b=f(b,[0,d[v]]),b=c(b,_),b=u(b,31),b=c(b,A),y=f(y,b)}return y=f(y,[0,d.length]),x=f(x,[0,d.length]),y=a(y,x),x=a(x,y),y=m(y),x=m(x),y=a(y,x),x=a(x,y),("00000000"+(y[0]>>>0).toString(16)).slice(-8)+("00000000"+(y[1]>>>0).toString(16)).slice(-8)+("00000000"+(x[0]>>>0).toString(16)).slice(-8)+("00000000"+(x[1]>>>0).toString(16)).slice(-8)},typeof ms<"u"?(typeof qc<"u"&&qc.exports&&(ms=qc.exports=t),ms.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)})(ms)});var Vy=Ee((D7,Fy)=>{Fy.exports=Uy()});var jc=Ee((M7,My)=>{"use strict";My.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 o=!1;n===-1?(n=this._data.length,this._setBit(e),this._changedData=!0):o=!0,this._setInternalPos(n,e,t,o),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,o=t;for(;n<this.length;){let i=this.get(n);o=e(o,i,n),n++}return o}find(e){let t=0,n,o;for(;t<this.length&&!n;)o=this.get(t),n=e(o),t++;return n?o:void 0}_internalPositionFor(e,t){let n=this._bytePosFor(e,t);if(n>=this._bitArrays.length)return-1;let o=this._bitArrays[n],i=e-n*7;if(!((o&1<<i)>0))return-1;let a=this._bitArrays.slice(0,n).reduce(Rv,0),c=~(4294967295<<i+1),u=Hy(o&c);return a+u-1}_bytePosFor(e,t){let n=Math.floor(e/7),o=n+1;for(;!t&&this._bitArrays.length<o;)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,o){let i=this._data,s=[t,n];if(o)this._sortData(),i[e]=s;else{if(i.length)if(i[i.length-1][0]>=t)i.push(s);else if(i[0][0]<=t)i.unshift(s);else{let a=Math.round(i.length/2);this._data=i.slice(0,a).concat(s).concat(i.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(Tv),this._changedData=!1}bitField(){let e=[],t=8,n=0,o=0,i,s=this._bitArrays.slice();for(;s.length||n;){n===0&&(i=s.shift(),n=7);let c=Math.min(n,t),u=~(255<<c),l=i&u;o|=l<<8-t,i=i>>>c,n-=c,t-=c,(!t||!n&&!s.length)&&(e.push(o),o=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(Nv)}};function Rv(r,e){return r+Hy(e)}function Hy(r){let e=r;return e=e-(e>>1&1431655765),e=(e&858993459)+(e>>2&858993459),(e+(e>>4)&252645135)*16843009>>24}function Tv(r,e){return r[0]-e[0]}function Nv(r){return r[1]}});var rg=Ee((vU,tg)=>{var Ad=class{constructor(e,t=12,n=8*1024,o=32*1024,i=64,s){this.bits=t,this.min=n,this.max=o,this.asModule=e,this.rabin=new e.Rabin(t,n,o,i,s),this.polynomial=s}fingerprint(e){let{__retain:t,__release:n,__allocArray:o,__getInt32Array:i,Int32Array_ID:s,Uint8Array_ID:a}=this.asModule,c=new Int32Array(Math.ceil(e.length/this.min)),u=t(o(s,c)),l=t(o(a,e)),f=this.rabin.fingerprint(l,u),m=i(f);n(l),n(u);let d=m.indexOf(0);return d>=0?m.subarray(0,d):m}};tg.exports=Ad});var cg=Ee(ws=>{"use strict";var Kv=typeof BigUint64Array<"u",ys=Symbol(),gs=1024;function ng(r,e){let t=new Uint32Array(r),n=new Uint16Array(r);var o=t[e+-4>>>2]>>>1,i=e>>>1;if(o<=gs)return String.fromCharCode.apply(String,n.subarray(i,i+o));let s=[];do{let a=n[i+gs-1],c=a>=55296&&a<56320?gs-1:gs;s.push(String.fromCharCode.apply(String,n.subarray(i,i+=c))),o-=c}while(o>gs);return s.join("")+String.fromCharCode.apply(String,n.subarray(i,i+o))}function Sd(r){let e={};function t(o,i){return o?ng(o.buffer,i):"<yet unknown>"}let n=r.env=r.env||{};return n.abort=n.abort||function(i,s,a,c){let u=e.memory||n.memory;throw Error("abort: "+t(u,i)+" at "+t(u,s)+":"+a+":"+c)},n.trace=n.trace||function(i,s){let a=e.memory||n.memory;console.log("trace: "+t(a,i)+(s?" ":"")+Array.prototype.slice.call(arguments,2,2+s).join(", "))},r.Math=r.Math||Math,r.Date=r.Date||Date,e}function _d(r,e){let t=e.exports,n=t.memory,o=t.table,i=t.__alloc,s=t.__retain,a=t.__rtti_base||-1;function c(A){let v=new Uint32Array(n.buffer),E=v[a>>>2];if((A>>>=0)>=E)throw Error("invalid id: "+A);return v[(a+4>>>2)+A*2]}function u(A){let v=new Uint32Array(n.buffer),E=v[a>>>2];if((A>>>=0)>=E)throw Error("invalid id: "+A);return v[(a+4>>>2)+A*2+1]}function l(A){return 31-Math.clz32(A>>>5&31)}function f(A){return 31-Math.clz32(A>>>14&31)}function m(A){let v=A.length,E=i(v<<1,1),R=new Uint16Array(n.buffer);for(var N=0,T=E>>>1;N<v;++N)R[T+N]=A.charCodeAt(N);return E}r.__allocString=m;function d(A){let v=n.buffer;if(new Uint32Array(v)[A+-8>>>2]!==1)throw Error("not a string: "+A);return ng(v,A)}r.__getString=d;function p(A,v,E){let R=n.buffer;if(E)switch(A){case 2:return new Float32Array(R);case 3:return new Float64Array(R)}else switch(A){case 0:return new(v?Int8Array:Uint8Array)(R);case 1:return new(v?Int16Array:Uint16Array)(R);case 2:return new(v?Int32Array:Uint32Array)(R);case 3:return new(v?BigInt64Array:BigUint64Array)(R)}throw Error("unsupported align: "+A)}function h(A,v){let E=c(A);if(!(E&3))throw Error("not an array: "+A+" @ "+E);let R=l(E),N=v.length,T=i(N<<R,0),H=i(E&2?16:12,A),D=new Uint32Array(n.buffer);D[H+0>>>2]=s(T),D[H+4>>>2]=T,D[H+8>>>2]=N<<R,E&2&&(D[H+12>>>2]=N);let Q=p(R,E&1024,E&2048);if(E&8192)for(let k=0;k<N;++k)Q[(T>>>R)+k]=s(v[k]);else Q.set(v,T>>>R);return H}r.__allocArray=h;function g(A){let v=new Uint32Array(n.buffer),E=v[A+-8>>>2],R=c(E);if(!(R&1))throw Error("not an array: "+E);let N=l(R);var T=v[A+4>>>2];let H=R&2?v[A+12>>>2]:v[T+-4>>>2]>>>N;return p(N,R&1024,R&2048).subarray(T>>>=N,T+H)}r.__getArrayView=g;function y(A){let v=g(A),E=v.length,R=new Array(E);for(let N=0;N<E;N++)R[N]=v[N];return R}r.__getArray=y;function x(A){let v=n.buffer,E=new Uint32Array(v)[A+-4>>>2];return v.slice(A,A+E)}r.__getArrayBuffer=x;function b(A,v,E){return new A(S(A,v,E))}function S(A,v,E){let R=n.buffer,N=new Uint32Array(R),T=N[E+4>>>2];return new A(R,T,N[T+-4>>>2]>>>v)}r.__getInt8Array=b.bind(null,Int8Array,0),r.__getInt8ArrayView=S.bind(null,Int8Array,0),r.__getUint8Array=b.bind(null,Uint8Array,0),r.__getUint8ArrayView=S.bind(null,Uint8Array,0),r.__getUint8ClampedArray=b.bind(null,Uint8ClampedArray,0),r.__getUint8ClampedArrayView=S.bind(null,Uint8ClampedArray,0),r.__getInt16Array=b.bind(null,Int16Array,1),r.__getInt16ArrayView=S.bind(null,Int16Array,1),r.__getUint16Array=b.bind(null,Uint16Array,1),r.__getUint16ArrayView=S.bind(null,Uint16Array,1),r.__getInt32Array=b.bind(null,Int32Array,2),r.__getInt32ArrayView=S.bind(null,Int32Array,2),r.__getUint32Array=b.bind(null,Uint32Array,2),r.__getUint32ArrayView=S.bind(null,Uint32Array,2),Kv&&(r.__getInt64Array=b.bind(null,BigInt64Array,3),r.__getInt64ArrayView=S.bind(null,BigInt64Array,3),r.__getUint64Array=b.bind(null,BigUint64Array,3),r.__getUint64ArrayView=S.bind(null,BigUint64Array,3)),r.__getFloat32Array=b.bind(null,Float32Array,2),r.__getFloat32ArrayView=S.bind(null,Float32Array,2),r.__getFloat64Array=b.bind(null,Float64Array,3),r.__getFloat64ArrayView=S.bind(null,Float64Array,3);function _(A,v){let E=new Uint32Array(n.buffer);var R=E[A+-8>>>2];if(R<=E[a>>>2])do if(R==v)return!0;while(R=u(R));return!1}return r.__instanceof=_,r.memory=r.memory||n,r.table=r.table||o,ag(t,r)}function og(r){return typeof Response<"u"&&r instanceof Response}async function ig(r,e){return og(r=await r)?sg(r,e):_d(Sd(e||(e={})),await WebAssembly.instantiate(r instanceof WebAssembly.Module?r:await WebAssembly.compile(r),e))}ws.instantiate=ig;function Gv(r,e){return _d(Sd(e||(e={})),new WebAssembly.Instance(r instanceof WebAssembly.Module?r:new WebAssembly.Module(r),e))}ws.instantiateSync=Gv;async function sg(r,e){return WebAssembly.instantiateStreaming?_d(Sd(e||(e={})),(await WebAssembly.instantiateStreaming(r,e)).instance):ig(og(r=await r)?r.arrayBuffer():r,e)}ws.instantiateStreaming=sg;function ag(r,e){var t=e?Object.create(e):{},n=r.__argumentsLength?function(o){r.__argumentsLength.value=o}:r.__setArgumentsLength||r.__setargc||function(){};for(let o in r){if(!Object.prototype.hasOwnProperty.call(r,o))continue;let i=r[o],s=o.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),f=a[l];if(typeof f>"u"||!f.prototype){let m=function(...d){return m.wrap(m.prototype.constructor(0,...d))};m.prototype={valueOf:function(){return this[ys]}},m.wrap=function(d){return Object.create(m.prototype,{[ys]:{value:d,writable:!1}})},f&&Object.getOwnPropertyNames(f).forEach(d=>Object.defineProperty(m,d,Object.getOwnPropertyDescriptor(f,d))),a[l]=m}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 m=r[o.replace("set:","get:")],d=r[o.replace("get:","set:")];Object.defineProperty(a,c,{get:function(){return m(this[ys])},set:function(p){d(this[ys],p)},enumerable:!0})}}else c==="constructor"?(a[c]=(...m)=>(n(m.length),i(...m))).original=i:(a[c]=function(...m){return n(m.length),i(this[ys],...m)}).original=i}else/^(get|set):/.test(c)?Object.prototype.hasOwnProperty.call(a,c=c.substring(4))||Object.defineProperty(a,c,{get:r[o.replace("set:","get:")],set:r[o.replace("get:","set:")],enumerable:!0}):typeof i=="function"&&i!==n?(a[c]=(...l)=>(n(l.length),i(...l))).original=i:a[c]=i}return t}ws.demangle=ag});var ug=Ee((SU,lg)=>{var{instantiate:qv}=cg();kd.supported=typeof WebAssembly<"u";function kd(r={}){if(!kd.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 qv(new Response(new Blob([e],{type:"application/wasm"})),r)}lg.exports=kd});var hg=Ee((_U,dg)=>{var fg=rg(),Wv=ug(),jv=async(r,e,t,n,o)=>{let i=await Wv();return new fg(i,r,e,t,n,o)};dg.exports={Rabin:fg,create:jv}});var Vg=Ee((jF,Fg)=>{"use strict";Fg.exports=r=>{if(Object.prototype.toString.call(r)!=="[object Object]")return!1;let e=Object.getPrototypeOf(r);return e===null||e===Object.prototype}});var Gg=Ee(($g,Kg)=>{"use strict";var el=Vg(),{hasOwnProperty:Mg}=Object.prototype,{propertyIsEnumerable:xA}=Object,Yo=(r,e,t)=>Object.defineProperty(r,e,{value:t,writable:!0,enumerable:!0,configurable:!0}),EA=$g,Hg={concatArrays:!1,ignoreUndefined:!1},tl=r=>{let e=[];for(let t in r)Mg.call(r,t)&&e.push(t);if(Object.getOwnPropertySymbols){let t=Object.getOwnPropertySymbols(r);for(let n of t)xA.call(r,n)&&e.push(n)}return e};function Xo(r){return Array.isArray(r)?vA(r):el(r)?AA(r):r}function vA(r){let e=r.slice(0,0);return tl(r).forEach(t=>{Yo(e,t,Xo(r[t]))}),e}function AA(r){let e=Object.getPrototypeOf(r)===null?Object.create(null):{};return tl(r).forEach(t=>{Yo(e,t,Xo(r[t]))}),e}var zg=(r,e,t,n)=>(t.forEach(o=>{typeof e[o]>"u"&&n.ignoreUndefined||(o in r&&r[o]!==Object.getPrototypeOf(r)?Yo(r,o,Bd(r[o],e[o],n)):Yo(r,o,Xo(e[o])))}),r),SA=(r,e,t)=>{let n=r.slice(0,0),o=0;return[r,e].forEach(i=>{let s=[];for(let a=0;a<i.length;a++)Mg.call(i,a)&&(s.push(String(a)),i===r?Yo(n,o++,i[a]):Yo(n,o++,Xo(i[a])));n=zg(n,i,tl(i).filter(a=>!s.includes(a)),t)}),n};function Bd(r,e,t){return t.concatArrays&&Array.isArray(r)&&Array.isArray(e)?SA(r,e,t):!el(e)||!el(r)?Xo(e):zg(r,e,tl(e),t)}Kg.exports=function(...r){let e=Bd(Xo(Hg),this!==EA&&this||{},Hg),t={_:{}};for(let n of r)if(n!==void 0){if(!el(n))throw new TypeError("`"+n+"` is not an Option Object");t=Bd(t,{_:n},e)}return t._}});var mw=Ee((uM,pw)=>{"use strict";pw.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 QS={};ve(QS,{createVerifiedFetch:()=>Md,verifiedFetch:()=>bl});function vn(r){let e=new globalThis.AbortController;function t(){e.abort();for(let i of r)i?.removeEventListener!=null&&i.removeEventListener("abort",t)}for(let i of r){if(i?.aborted===!0){t();break}i?.addEventListener!=null&&i.addEventListener("abort",t)}function n(){for(let i of r)i?.removeEventListener!=null&&i.removeEventListener("abort",t)}let o=e.signal;return o.clear=n,o}function $w(r){let[e,t]=r[Symbol.asyncIterator]!=null?[r[Symbol.asyncIterator](),Symbol.asyncIterator]:[r[Symbol.iterator](),Symbol.iterator],n=[];return{peek:()=>e.next(),push:o=>{n.push(o)},next:()=>n.length>0?{done:!1,value:n.shift()}:e.next(),[t](){return this}}}var Yn=$w;function Kw(r){return r[Symbol.asyncIterator]!=null}function Zd(r){return r?.then!=null}function Gw(r,e){if(Kw(r))return async function*(){for await(let a of r){let c=e(a);Zd(c)&&await c,yield a}}();let t=Yn(r),{value:n,done:o}=t.next();if(o===!0)return function*(){}();if(typeof e(n)?.then=="function")return async function*(){yield n;for await(let a of t){let c=e(a);Zd(c)&&await c,yield a}}();let s=e;return function*(){yield n;for(let a of t)s(a),yield a}()}var El=Gw;var Rl={};ve(Rl,{base32:()=>Fe,base32hex:()=>r2,base32hexpad:()=>o2,base32hexpadupper:()=>i2,base32hexupper:()=>n2,base32pad:()=>e2,base32padupper:()=>t2,base32upper:()=>th,base32z:()=>s2});var Xn={};ve(Xn,{coerce:()=>At,empty:()=>Jd,equals:()=>vl,fromHex:()=>Ww,fromString:()=>Al,isBinary:()=>jw,toHex:()=>qw,toString:()=>Sl});var Jd=new Uint8Array(0);function qw(r){return r.reduce((e,t)=>e+t.toString(16).padStart(2,"0"),"")}function Ww(r){let e=r.match(/../g);return e!=null?new Uint8Array(e.map(t=>parseInt(t,16))):Jd}function vl(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 At(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 jw(r){return r instanceof ArrayBuffer||ArrayBuffer.isView(r)}function Al(r){return new TextEncoder().encode(r)}function Sl(r){return new TextDecoder().decode(r)}function Yw(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 o=0;o<r.length;o++){var i=r.charAt(o),s=i.charCodeAt(0);if(t[s]!==255)throw new TypeError(i+" is ambiguous");t[s]=o}var a=r.length,c=r.charAt(0),u=Math.log(a)/Math.log(256),l=Math.log(256)/Math.log(a);function f(p){if(p instanceof Uint8Array||(ArrayBuffer.isView(p)?p=new Uint8Array(p.buffer,p.byteOffset,p.byteLength):Array.isArray(p)&&(p=Uint8Array.from(p))),!(p instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(p.length===0)return"";for(var h=0,g=0,y=0,x=p.length;y!==x&&p[y]===0;)y++,h++;for(var b=(x-y)*l+1>>>0,S=new Uint8Array(b);y!==x;){for(var _=p[y],A=0,v=b-1;(_!==0||A<g)&&v!==-1;v--,A++)_+=256*S[v]>>>0,S[v]=_%a>>>0,_=_/a>>>0;if(_!==0)throw new Error("Non-zero carry");g=A,y++}for(var E=b-g;E!==b&&S[E]===0;)E++;for(var R=c.repeat(h);E<b;++E)R+=r.charAt(S[E]);return R}function m(p){if(typeof p!="string")throw new TypeError("Expected String");if(p.length===0)return new Uint8Array;var h=0;if(p[h]!==" "){for(var g=0,y=0;p[h]===c;)g++,h++;for(var x=(p.length-h)*u+1>>>0,b=new Uint8Array(x);p[h];){var S=t[p.charCodeAt(h)];if(S===255)return;for(var _=0,A=x-1;(S!==0||_<y)&&A!==-1;A--,_++)S+=a*b[A]>>>0,b[A]=S%256>>>0,S=S/256>>>0;if(S!==0)throw new Error("Non-zero carry");y=_,h++}if(p[h]!==" "){for(var v=x-y;v!==x&&b[v]===0;)v++;for(var E=new Uint8Array(g+(x-v)),R=g;v!==x;)E[R++]=b[v++];return E}}}function d(p){var h=m(p);if(h)return h;throw new Error(`Non-${e} character`)}return{encode:f,decodeUnsafe:m,decode:d}}var Xw=Yw,Zw=Xw,Qd=Zw;var _l=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")}},kl=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 eh(this,e)}},Il=class{decoders;constructor(e){this.decoders=e}or(e){return eh(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 eh(r,e){return new Il({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}var Bl=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,t,n,o){this.name=e,this.prefix=t,this.baseEncode=n,this.baseDecode=o,this.encoder=new _l(e,t,n),this.decoder=new kl(e,t,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function Zn({name:r,prefix:e,encode:t,decode:n}){return new Bl(r,e,t,n)}function Ur({name:r,prefix:e,alphabet:t}){let{encode:n,decode:o}=Qd(t,r);return Zn({prefix:e,name:r,encode:n,decode:i=>At(o(i))})}function Jw(r,e,t,n){let o={};for(let l=0;l<e.length;++l)o[e[l]]=l;let i=r.length;for(;r[i-1]==="=";)--i;let s=new Uint8Array(i*t/8|0),a=0,c=0,u=0;for(let l=0;l<i;++l){let f=o[r[l]];if(f===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<t|f,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 Qw(r,e,t){let n=e[e.length-1]==="=",o=(1<<t)-1,i="",s=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],s+=8;s>t;)s-=t,i+=e[o&a>>s];if(s!==0&&(i+=e[o&a<<t-s]),n)for(;i.length*t&7;)i+="=";return i}function Ae({name:r,prefix:e,bitsPerChar:t,alphabet:n}){return Zn({prefix:e,name:r,encode(o){return Qw(o,n,t)},decode(o){return Jw(o,n,t,r)}})}var Fe=Ae({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),th=Ae({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),e2=Ae({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),t2=Ae({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),r2=Ae({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),n2=Ae({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),o2=Ae({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),i2=Ae({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),s2=Ae({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Tl={};ve(Tl,{base58btc:()=>ke,base58flickr:()=>a2});var ke=Ur({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),a2=Ur({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var c2=oh,rh=128,l2=127,u2=~l2,f2=Math.pow(2,31);function oh(r,e,t){e=e||[],t=t||0;for(var n=t;r>=f2;)e[t++]=r&255|rh,r/=128;for(;r&u2;)e[t++]=r&255|rh,r>>>=7;return e[t]=r|0,oh.bytes=t-n+1,e}var d2=Nl,h2=128,nh=127;function Nl(r,n){var t=0,n=n||0,o=0,i=n,s,a=r.length;do{if(i>=a)throw Nl.bytes=0,new RangeError("Could not decode varint");s=r[i++],t+=o<28?(s&nh)<<o:(s&nh)*Math.pow(2,o),o+=7}while(s>=h2);return Nl.bytes=i-n,t}var p2=Math.pow(2,7),m2=Math.pow(2,14),y2=Math.pow(2,21),g2=Math.pow(2,28),w2=Math.pow(2,35),b2=Math.pow(2,42),x2=Math.pow(2,49),E2=Math.pow(2,56),v2=Math.pow(2,63),A2=function(r){return r<p2?1:r<m2?2:r<y2?3:r<g2?4:r<w2?5:r<b2?6:r<x2?7:r<E2?8:r<v2?9:10},S2={encode:c2,decode:d2,encodingLength:A2},_2=S2,oi=_2;function ii(r,e=0){return[oi.decode(r,e),oi.decode.bytes]}function Jn(r,e,t=0){return oi.encode(r,e,t),e}function Qn(r){return oi.encodingLength(r)}function Zt(r,e){let t=e.byteLength,n=Qn(r),o=n+Qn(t),i=new Uint8Array(o+t);return Jn(r,i,0),Jn(t,i,n),i.set(e,o),new eo(r,t,e,i)}function Ze(r){let e=At(r),[t,n]=ii(e),[o,i]=ii(e.subarray(n)),s=e.subarray(n+i);if(s.byteLength!==o)throw new Error("Incorrect length");return new eo(t,o,s,e)}function ih(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&vl(r.bytes,t.bytes)}}var eo=class{code;size;digest;bytes;constructor(e,t,n,o){this.code=e,this.size=t,this.digest=n,this.bytes=o}};function sh(r,e){let{bytes:t,version:n}=r;switch(n){case 0:return I2(t,Cl(r),e??ke.encoder);default:return B2(t,Cl(r),e??Fe.encoder)}}var ah=new WeakMap;function Cl(r){let e=ah.get(r);if(e==null){let t=new Map;return ah.set(r,t),t}return e}var U=class r{code;version;multihash;bytes;"/";constructor(e,t,n,o){this.code=t,this.version=e,this.multihash=n,this.bytes=o,this["/"]=o}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!==si)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==R2)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=Zt(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&&ih(e.multihash,n.multihash)}toString(e){return sh(this,e)}toJSON(){return{"/":sh(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:o,multihash:i,bytes:s}=t;return new r(n,o,i,s??ch(n,o,i.bytes))}else if(t[T2]===!0){let{version:n,multihash:o,code:i}=t,s=Ze(o);return r.create(n,i,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!==si)throw new Error(`Version 0 CID must use dag-pb (code: ${si}) block encoding`);return new r(e,t,n,n.bytes)}case 1:{let o=ch(e,t,n.bytes);return new r(e,t,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return r.create(0,si,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,o=At(e.subarray(n,n+t.multihashSize));if(o.byteLength!==t.multihashSize)throw new Error("Incorrect length");let i=o.subarray(t.multihashSize-t.digestSize),s=new eo(t.multihashCode,t.digestSize,i,o);return[t.version===0?r.createV0(s):r.createV1(t.codec,s),e.subarray(t.size)]}static inspectBytes(e){let t=0,n=()=>{let[f,m]=ii(e.subarray(t));return t+=m,f},o=n(),i=si;if(o===18?(o=0,t=0):i=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let s=t,a=n(),c=n(),u=t+c,l=u-s;return{version:o,codec:i,multihashCode:a,digestSize:c,multihashSize:l,size:u}}static parse(e,t){let[n,o]=k2(e,t),i=r.decode(o);if(i.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Cl(i).set(n,e),i}};function k2(r,e){switch(r[0]){case"Q":{let t=e??ke;return[ke.prefix,t.decode(`${ke.prefix}${r}`)]}case ke.prefix:{let t=e??ke;return[ke.prefix,t.decode(r)]}case Fe.prefix:{let t=e??Fe;return[Fe.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 I2(r,e,t){let{prefix:n}=t;if(n!==ke.prefix)throw Error(`Cannot string encode V0 in ${t.name} encoding`);let o=e.get(n);if(o==null){let i=t.encode(r).slice(1);return e.set(n,i),i}else return o}function B2(r,e,t){let{prefix:n}=t,o=e.get(n);if(o==null){let i=t.encode(r);return e.set(n,i),i}else return o}var si=112,R2=18;function ch(r,e,t){let n=Qn(r),o=n+Qn(e),i=new Uint8Array(o+t.byteLength);return Jn(r,i,0),Jn(e,i,n),i.set(t,o),i}var T2=Symbol.for("@ipld/js-cid/CID");var ai=Symbol.for("@libp2p/content-routing");var Ll=Symbol.for("@libp2p/peer-id");function lh(r){return r!=null&&!!r[Ll]}var ci=Symbol.for("@libp2p/peer-routing");var Fr=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"},P=class extends Error{code;props;constructor(e,t,n){super(e),this.code=t,this.name=n?.name??"CodeError",this.props=n??{}}};var to=(r,...e)=>{try{[...e]}catch{}};var Ns=class extends EventTarget{#e=new Map;constructor(){super(),to(1/0,this)}listenerCount(e){let t=this.#e.get(e);return t==null?0:t.length}addEventListener(e,t,n){super.addEventListener(e,t,n);let o=this.#e.get(e);o==null&&(o=[],this.#e.set(e,o)),o.push({callback:t,once:(n!==!0&&n!==!1&&n?.once)??!1})}removeEventListener(e,t,n){super.removeEventListener(e.toString(),t??null,n);let o=this.#e.get(e);o!=null&&(o=o.filter(({callback:i})=>i!==t),this.#e.set(e,o))}dispatchEvent(e){let t=super.dispatchEvent(e),n=this.#e.get(e.type);return n==null||(n=n.filter(({once:o})=>!o),this.#e.set(e.type,n)),t}safeDispatchEvent(e,t={}){return this.dispatchEvent(new N2(e,t))}},Dl=class extends Event{detail;constructor(e,t){super(e,t),this.detail=t?.detail}},N2=globalThis.CustomEvent??Dl;function uh(r){return r!=null&&typeof r.start=="function"&&typeof r.stop=="function"}async function Vr(...r){let e=[];for(let t of r)uh(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 Hr(...r){let e=[];for(let t of r)uh(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 Ul={};ve(Ul,{sha256:()=>ae,sha512:()=>Ol});function An({name:r,code:e,encode:t}){return new Pl(r,e,t)}var Pl=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?Zt(this.code,t):t.then(n=>Zt(this.code,n))}else throw Error("Unknown type, must be binary type")}};function dh(r){return async e=>new Uint8Array(await crypto.subtle.digest(r,e))}var ae=An({name:"sha2-256",code:18,encode:dh("SHA-256")}),Ol=An({name:"sha2-512",code:19,encode:dh("SHA-512")});var pt=J(gh(),1);var Fl={};ve(Fl,{base64:()=>Jt,base64pad:()=>K2,base64url:()=>G2,base64urlpad:()=>q2});var Jt=Ae({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),K2=Ae({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),G2=Ae({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),q2=Ae({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});pt.default.formatters.b=r=>r==null?"undefined":ke.baseEncode(r);pt.default.formatters.t=r=>r==null?"undefined":Fe.baseEncode(r);pt.default.formatters.m=r=>r==null?"undefined":Jt.baseEncode(r);pt.default.formatters.p=r=>r==null?"undefined":r.toString();pt.default.formatters.c=r=>r==null?"undefined":r.toString();pt.default.formatters.k=r=>r==null?"undefined":r.toString();pt.default.formatters.a=r=>r==null?"undefined":r.toString();function W2(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 wh(){return{forComponent(r){return ee(r)}}}function ee(r){let e=W2(`${r}:trace`);return pt.default.enabled(`${r}:trace`)&&pt.default.names.map(t=>t.toString()).find(t=>t.includes(":trace"))!=null&&(e=(0,pt.default)(`${r}:trace`)),Object.assign((0,pt.default)(r),{error:(0,pt.default)(`${r}:error`),trace:e})}function ce(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 hr(r=0){return new Uint8Array(r)}function it(r=0){return new Uint8Array(r)}var ab=Math.pow(2,7),cb=Math.pow(2,14),lb=Math.pow(2,21),Ml=Math.pow(2,28),zl=Math.pow(2,35),$l=Math.pow(2,42),Kl=Math.pow(2,49),le=128,Ke=127;function st(r){if(r<ab)return 1;if(r<cb)return 2;if(r<lb)return 3;if(r<Ml)return 4;if(r<zl)return 5;if(r<$l)return 6;if(r<Kl)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Gl(r,e,t=0){switch(st(r)){case 8:e[t++]=r&255|le,r/=128;case 7:e[t++]=r&255|le,r/=128;case 6:e[t++]=r&255|le,r/=128;case 5:e[t++]=r&255|le,r/=128;case 4:e[t++]=r&255|le,r>>>=7;case 3:e[t++]=r&255|le,r>>>=7;case 2:e[t++]=r&255|le,r>>>=7;case 1:{e[t++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return e}function ub(r,e,t=0){switch(st(r)){case 8:e.set(t++,r&255|le),r/=128;case 7:e.set(t++,r&255|le),r/=128;case 6:e.set(t++,r&255|le),r/=128;case 5:e.set(t++,r&255|le),r/=128;case 4:e.set(t++,r&255|le),r>>>=7;case 3:e.set(t++,r&255|le),r>>>=7;case 2:e.set(t++,r&255|le),r>>>=7;case 1:{e.set(t++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return e}function ql(r,e){let t=r[e],n=0;if(n+=t&Ke,t<le||(t=r[e+1],n+=(t&Ke)<<7,t<le)||(t=r[e+2],n+=(t&Ke)<<14,t<le)||(t=r[e+3],n+=(t&Ke)<<21,t<le)||(t=r[e+4],n+=(t&Ke)*Ml,t<le)||(t=r[e+5],n+=(t&Ke)*zl,t<le)||(t=r[e+6],n+=(t&Ke)*$l,t<le)||(t=r[e+7],n+=(t&Ke)*Kl,t<le))return n;throw new RangeError("Could not decode varint")}function fb(r,e){let t=r.get(e),n=0;if(n+=t&Ke,t<le||(t=r.get(e+1),n+=(t&Ke)<<7,t<le)||(t=r.get(e+2),n+=(t&Ke)<<14,t<le)||(t=r.get(e+3),n+=(t&Ke)<<21,t<le)||(t=r.get(e+4),n+=(t&Ke)*Ml,t<le)||(t=r.get(e+5),n+=(t&Ke)*zl,t<le)||(t=r.get(e+6),n+=(t&Ke)*$l,t<le)||(t=r.get(e+7),n+=(t&Ke)*Kl,t<le))return n;throw new RangeError("Could not decode varint")}function io(r,e,t=0){return e==null&&(e=it(st(r))),e instanceof Uint8Array?Gl(r,e,t):ub(r,e,t)}function _n(r,e=0){return r instanceof Uint8Array?ql(r,e):fb(r,e)}var Wl=new Float32Array([-0]),Mr=new Uint8Array(Wl.buffer);function Rh(r,e,t){Wl[0]=r,e[t]=Mr[0],e[t+1]=Mr[1],e[t+2]=Mr[2],e[t+3]=Mr[3]}function Th(r,e){return Mr[0]=r[e],Mr[1]=r[e+1],Mr[2]=r[e+2],Mr[3]=r[e+3],Wl[0]}var jl=new Float64Array([-0]),Ge=new Uint8Array(jl.buffer);function Nh(r,e,t){jl[0]=r,e[t]=Ge[0],e[t+1]=Ge[1],e[t+2]=Ge[2],e[t+3]=Ge[3],e[t+4]=Ge[4],e[t+5]=Ge[5],e[t+6]=Ge[6],e[t+7]=Ge[7]}function Ch(r,e){return Ge[0]=r[e],Ge[1]=r[e+1],Ge[2]=r[e+2],Ge[3]=r[e+3],Ge[4]=r[e+4],Ge[5]=r[e+5],Ge[6]=r[e+6],Ge[7]=r[e+7],jl[0]}var db=BigInt(Number.MAX_SAFE_INTEGER),hb=BigInt(Number.MIN_SAFE_INTEGER),mt=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 kn;if(e<db&&e>hb)return this.fromNumber(Number(e));let t=e<0n;t&&(e=-e);let n=e>>32n,o=e-(n<<32n);return t&&(n=~n|0n,o=~o|0n,++o>Lh&&(o=0n,++n>Lh&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(e){if(e===0)return kn;let t=e<0;t&&(e=-e);let n=e>>>0,o=(e-n)/4294967296>>>0;return t&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new r(n,o)}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):kn}},kn=new mt(0,0);kn.toBigInt=function(){return 0n};kn.zzEncode=kn.zzDecode=function(){return this};kn.length=function(){return 1};var Lh=4294967296n;function Dh(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 Ph(r,e,t){if(t-e<1)return"";let o,i=[],s=0,a;for(;e<t;)a=r[e++],a<128?i[s++]=a:a>191&&a<224?i[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,i[s++]=55296+(a>>10),i[s++]=56320+(a&1023)):i[s++]=(a&15)<<12|(r[e++]&63)<<6|r[e++]&63,s>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,i)),s=0);return o!=null?(s>0&&o.push(String.fromCharCode.apply(String,i.slice(0,s))),o.join("")):String.fromCharCode.apply(String,i.slice(0,s))}function Yl(r,e,t){let n=t,o,i;for(let s=0;s<r.length;++s)o=r.charCodeAt(s),o<128?e[t++]=o:o<2048?(e[t++]=o>>6|192,e[t++]=o&63|128):(o&64512)===55296&&((i=r.charCodeAt(s+1))&64512)===56320?(o=65536+((o&1023)<<10)+(i&1023),++s,e[t++]=o>>18|240,e[t++]=o>>12&63|128,e[t++]=o>>6&63|128,e[t++]=o&63|128):(e[t++]=o>>12|224,e[t++]=o>>6&63|128,e[t++]=o&63|128);return t-n}function Ut(r,e){return RangeError(`index out of range: ${r.pos} + ${e??1} > ${r.len}`)}function Ps(r,e){return(r[e-4]|r[e-3]<<8|r[e-2]<<16|r[e-1]<<24)>>>0}var Xl=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,Ut(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 Ut(this,4);return Ps(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Ut(this,4);return Ps(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Ut(this,4);let e=Th(this.buf,this.pos);return this.pos+=4,e}double(){if(this.pos+8>this.len)throw Ut(this,4);let e=Ch(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 Ut(this,e);return this.pos+=e,t===n?new Uint8Array(0):this.buf.subarray(t,n)}string(){let e=this.bytes();return Ph(e,0,e.length)}skip(e){if(typeof e=="number"){if(this.pos+e>this.len)throw Ut(this,e);this.pos+=e}else do if(this.pos>=this.len)throw Ut(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 mt(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 Ut(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 Ut(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 Ut(this,8);let e=Ps(this.buf,this.pos+=4),t=Ps(this.buf,this.pos+=4);return new mt(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=ql(this.buf,this.pos);return this.pos+=st(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 Zl(r){return new Xl(r instanceof Uint8Array?r:r.subarray())}function _t(r,e,t){let n=Zl(r);return e.decode(n,void 0,t)}var Jl={};ve(Jl,{base10:()=>pb});var pb=Ur({prefix:"9",name:"base10",alphabet:"0123456789"});var Ql={};ve(Ql,{base16:()=>mb,base16upper:()=>yb});var mb=Ae({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),yb=Ae({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var eu={};ve(eu,{base2:()=>gb});var gb=Ae({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var tu={};ve(tu,{base256emoji:()=>vb});var Uh=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}"),wb=Uh.reduce((r,e,t)=>(r[t]=e,r),[]),bb=Uh.reduce((r,e,t)=>(r[e.codePointAt(0)]=t,r),[]);function xb(r){return r.reduce((e,t)=>(e+=wb[t],e),"")}function Eb(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 vb=Zn({prefix:"\u{1F680}",name:"base256emoji",encode:xb,decode:Eb});var ru={};ve(ru,{base36:()=>zr,base36upper:()=>Ab});var zr=Ur({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Ab=Ur({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var nu={};ve(nu,{base8:()=>Sb});var Sb=Ae({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var ou={};ve(ou,{identity:()=>_b});var _b=Zn({prefix:"\0",name:"identity",encode:r=>Sl(r),decode:r=>Al(r)});var o4=new TextEncoder,kb=new TextDecoder;var $r=512;function Fh(r){return JSON.parse(kb.decode(r))}var kt={};ve(kt,{code:()=>ge,decode:()=>Rb,encode:()=>Bb,name:()=>Ib});var Ib="raw",ge=85;function Bb(r){return At(r)}function Rb(r){return At(r)}var iu={};ve(iu,{identity:()=>qe});var Vh=0,Tb="identity",Hh=At;function Nb(r){return Zt(Vh,Hh(r))}var qe={code:Vh,name:Tb,encode:Hh,digest:Nb};var Kr={...ou,...eu,...nu,...Jl,...Ql,...Rl,...ru,...Tl,...Fl,...tu},y4={...Ul,...iu};function zh(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}var Mh=zh("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),su=zh("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=it(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),Cb={utf8:Mh,"utf-8":Mh,hex:Kr.base16,latin1:su,ascii:su,binary:su,...Kr},Us=Cb;function F(r,e="utf8"){let t=Us[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.decoder.decode(`${t.prefix}${r}`)}function au(r){let e=r??8192,t=e>>>1,n,o=e;return function(s){if(s<1||s>t)return it(s);o+s>e&&(n=it(e),o=0);let a=n.subarray(o,o+=s);return o&7&&(o=(o|7)+1),a}}var In=class{fn;len;next;val;constructor(e,t,n){this.fn=e,this.len=t,this.next=void 0,this.val=n}};function cu(){}var uu=class{head;tail;len;next;constructor(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}},Lb=au();function Db(r){return globalThis.Buffer!=null?it(r):Lb(r)}var ui=class{len;head;tail;states;constructor(){this.len=0,this.head=new In(cu,0,0),this.tail=this.head,this.states=null}_push(e,t,n){return this.tail=this.tail.next=new In(e,t,n),this.len+=t,this}uint32(e){return this.len+=(this.tail=this.tail.next=new fu((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(Fs,10,mt.fromNumber(e)):this.uint32(e)}sint32(e){return this.uint32((e<<1^e>>31)>>>0)}uint64(e){let t=mt.fromBigInt(e);return this._push(Fs,t.length(),t)}uint64Number(e){return this._push(Gl,st(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=mt.fromBigInt(e).zzEncode();return this._push(Fs,t.length(),t)}sint64Number(e){let t=mt.fromNumber(e).zzEncode();return this._push(Fs,t.length(),t)}sint64String(e){return this.sint64(BigInt(e))}bool(e){return this._push(lu,1,e?1:0)}fixed32(e){return this._push(li,4,e>>>0)}sfixed32(e){return this.fixed32(e)}fixed64(e){let t=mt.fromBigInt(e);return this._push(li,4,t.lo)._push(li,4,t.hi)}fixed64Number(e){let t=mt.fromNumber(e);return this._push(li,4,t.lo)._push(li,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(Rh,4,e)}double(e){return this._push(Nh,8,e)}bytes(e){let t=e.length>>>0;return t===0?this._push(lu,1,0):this.uint32(t)._push(Ob,t,e)}string(e){let t=Dh(e);return t!==0?this.uint32(t)._push(Yl,t,e):this._push(lu,1,0)}fork(){return this.states=new uu(this),this.head=this.tail=new In(cu,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 In(cu,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=Db(this.len),n=0;for(;e!=null;)e.fn(e.val,t,n),n+=e.len,e=e.next;return t}};function lu(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 fu=class extends In{next;constructor(e,t){super(Pb,e,t),this.next=void 0}};function Fs(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 li(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 Ob(r,e,t){e.set(r,t)}globalThis.Buffer!=null&&(ui.prototype.bytes=function(r){let e=r.length>>>0;return this.uint32(e),e>0&&this._push(Ub,e,r),this},ui.prototype.string=function(r){let e=globalThis.Buffer.byteLength(r);return this.uint32(e),e>0&&this._push(Fb,e,r),this});function Ub(r,e,t){e.set(r,t)}function Fb(r,e,t){r.length<40?Yl(r,e,t):e.utf8Write!=null?e.utf8Write(r,t):e.set(F(r),t)}function du(){return new ui}function It(r,e){let t=du();return e.encode(r,t,{lengthDelimited:!1}),t.finish()}var so;(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"})(so||(so={}));function Vs(r,e,t,n){return{name:r,type:e,encode:t,decode:n}}function Bn(r){function e(o){if(r[o.toString()]==null)throw new Error("Invalid enum value");return r[o]}let t=function(i,s){let a=e(i);s.int32(a)},n=function(i){let s=i.int32();return e(s)};return Vs("enum",so.VARINT,t,n)}function Bt(r,e){return Vs("message",so.LENGTH_DELIMITED,r,e)}function Vb(r){return r[Symbol.asyncIterator]!=null}function Hb(r){if(Vb(r))return(async()=>{for await(let e of r);})();for(let e of r);}var Ft=Hb;function ue(r,e){e==null&&(e=r.reduce((o,i)=>o+i.length,0));let t=it(e),n=0;for(let o of r)t.set(o,n),n+=o.length;return t}var Kh=Symbol.for("@achingbrain/uint8arraylist");function $h(r,e){if(e==null||e<0)throw new RangeError("index is out of bounds");let t=0;for(let n of r){let o=t+n.byteLength;if(e<o)return{buf:n,index:e-t};t=o}throw new RangeError("index is out of bounds")}function Qt(r){return!!r?.[Kh]}var Rt=class r{bufs;length;[Kh]=!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(Qt(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(Qt(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=$h(this.bufs,e);return t.buf[t.index]}set(e,t){let n=$h(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(Qt(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:o}=this._subList(e,t);return ue(n,o)}subarray(e,t){let{bufs:n,length:o}=this._subList(e,t);return n.length===1?n[0]:ue(n,o)}sublist(e,t){let{bufs:n,length:o}=this._subList(e,t),i=new r;return i.length=o,i.bufs=[...n],i}_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=[],o=0;for(let i=0;i<this.bufs.length;i++){let s=this.bufs[i],a=o,c=a+s.byteLength;if(o=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 f=e-a;n.push(s.subarray(f,f+(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(!Qt(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 o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let i=256,s=new Int32Array(i);for(let f=0;f<i;f++)s[f]=-1;for(let f=0;f<o;f++)s[n[f]]=f;let a=s,c=this.byteLength-n.byteLength,u=n.byteLength-1,l;for(let f=t;f<=c;f+=l){l=0;for(let m=u;m>=0;m--){let d=this.get(f+m);if(n[m]!==d){l=Math.max(1,m-a[d]);break}}if(l===0)return f}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=it(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 o=hr(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,t,n),this.write(o,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 o=hr(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,t,n),this.write(o,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 o=hr(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,t,n),this.write(o,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=it(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 o=hr(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,t,n),this.write(o,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 o=hr(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,t,n),this.write(o,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 o=hr(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,t,n),this.write(o,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 o=hr(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,t,n),this.write(o,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 o=hr(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,t,n),this.write(o,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(!ce(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((o,i)=>o+i.byteLength,0)),n.length=t,n}};function zb(r){return r[Symbol.asyncIterator]!=null}function $b(r,e){if(zb(r))return async function*(){for await(let a of r)yield e(a)}();let t=Yn(r),{value:n,done:o}=t.next();if(o===!0)return function*(){}();let i=e(n);if(typeof i.then=="function")return async function*(){yield await i;for await(let a of t)yield e(a)}();let s=e;return function*(){yield i;for(let a of t)yield s(a)}()}var We=$b;function we(){let r={};return r.promise=new Promise((e,t)=>{r.resolve=e,r.reject=t}),r}var Hs=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}},ao=class{size;hwm;head;tail;constructor(e={}){this.hwm=e.splitLimit??16,this.head=new Hs(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 Hs(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 hu=class extends Error{type;code;constructor(e,t){super(e??"The operation was aborted"),this.type="aborted",this.code=t??"ABORT_ERR"}};function Tt(r={}){return Kb(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 Kb(r,e){e=e??{};let t=e.onEnd,n=new ao,o,i,s,a=we(),c=async()=>{try{return n.isEmpty()?s?{done:!0}:await new Promise((g,y)=>{i=x=>{i=null,n.push(x);try{g(r(n))}catch(b){y(b)}return o}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=we()})}},u=g=>i!=null?i(g):(n.push(g),o),l=g=>(n=new ao,i!=null?i({error:g}):(n.push({error:g}),o)),f=g=>{if(s)return o;if(e?.objectMode!==!0&&g?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return u({done:!1,value:g})},m=g=>s?o:(s=!0,g!=null?l(g):u({done:!0})),d=()=>(n=new ao,m(),{done:!0}),p=g=>(m(g),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:c,return:d,throw:p,push:f,end:m,get readableLength(){return n.size},onEmpty:async g=>{let y=g?.signal;if(y?.throwIfAborted(),n.isEmpty())return;let x,b;y!=null&&(x=new Promise((S,_)=>{b=()=>{_(new hu)},y.addEventListener("abort",b)}));try{await Promise.race([a.promise,x])}finally{b!=null&&y!=null&&y?.removeEventListener("abort",b)}}},t==null)return o;let h=o;return o={[Symbol.asyncIterator](){return this},next(){return h.next()},throw(g){return h.throw(g),t!=null&&(t(g),t=void 0),{done:!0}},return(){return h.return(),t!=null&&(t(),t=void 0),{done:!0}},push:f,end(g){return h.end(g),t!=null&&(t(g),t=void 0),o},get readableLength(){return h.readableLength},onEmpty:g=>h.onEmpty(g)},o}function Gb(r){return r[Symbol.asyncIterator]!=null}function qb(...r){let e=[];for(let t of r)Gb(t)||e.push(t);return e.length===r.length?function*(){for(let t of e)yield*t}():async function*(){let t=Tt({objectMode:!0});Promise.resolve().then(async()=>{try{await Promise.all(r.map(async n=>{for await(let o of n)t.push(o)})),t.end()}catch(n){t.end(n)}}),yield*t}()}var pr=qb;function at(r,...e){if(r==null)throw new Error("Empty pipeline");if(pu(r)){let n=r;r=()=>n.source}else if(jh(r)||Wh(r)){let n=r;r=()=>n}let t=[r,...e];if(t.length>1&&pu(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++)pu(t[n])&&(t[n]=jb(t[n]));return Wb(...t)}var Wb=(...r)=>{let e;for(;r.length>0;)e=r.shift()(e);return e},Wh=r=>r?.[Symbol.asyncIterator]!=null,jh=r=>r?.[Symbol.iterator]!=null,pu=r=>r==null?!1:r.sink!=null&&r.source!=null,jb=r=>e=>{let t=r.sink(e);if(t?.then!=null){let n=Tt({objectMode:!0});t.then(()=>{n.end()},s=>{n.end(s)});let o,i=r.source;if(Wh(i))o=async function*(){yield*i,n.end()};else if(jh(i))o=function*(){yield*i,n.end()};else throw new Error("Unknown duplex source type - must be Iterable or AsyncIterable");return pr(n,o())}return r.source};function Yb(r){return r[Symbol.asyncIterator]!=null}function Xb(r,e){return Yb(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 Ms=Xb;var V=class extends Event{constructor(e,t){super(e),this.detail=t}};function W(r,e="utf8"){let t=Us[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.encoder.encode(r).substring(1)}var zs=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 o=await fetch(n.toString(),{signal:t,headers:{Accept:"application/vnd.ipld.raw"},cache:"force-cache"});if(!o.ok)throw this.#t++,new Error(`unable to fetch raw block for CID ${e} from gateway ${this.url}`);return this.#s++,new Uint8Array(await o.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 $s=class{gateways;log;constructor(e,t={}){this.log=e.logger.forComponent("helia:trustless-gateway-block-broker"),this.gateways=(t.gateways??Yh).map(n=>new zs(n))}async retrieve(e,t={}){let n=this.gateways.sort((i,s)=>s.reliability()-i.reliability()),o=[];for(let i of n){this.log("getting block for %c from %s",e,i.url);try{let s=await i.getRawBlock(e,t.signal);this.log.trace("got block for %c from %s",e,i.url);try{await t.validateFn?.(s)}catch(a){throw this.log.error("failed to validate block for %c from %s",e,i.url,a),i.incrementInvalidBlocks(),new Error(`unable to validate block for CID ${e} from gateway ${i.url}`)}return s}catch(s){if(this.log.error("failed to get block for %c from %s",e,i.url,s),s instanceof Error?o.push(s):o.push(new Error(`unable to fetch raw block for CID ${e} from gateway ${i.url}`)),t.signal?.aborted===!0){this.log.trace("request aborted while fetching raw block for CID %c from gateway %s",e,i.url);break}}}throw new AggregateError(o,`unable to fetch raw block for CID ${e} from any gateway`)}};var Yh=["https://trustless-gateway.link","https://cloudflare-ipfs.com","https://4everland.io"];function fi(r={}){return e=>new $s(e,r)}var Zb=Symbol.for("nodejs.util.inspect.custom"),Xh=Object.values(Kr).map(r=>r.decoder).reduce((r,e)=>r.or(e),Kr.identity.decoder),Zh=114,mu=36,yu=37,di=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()})`}[Ll]=!0;toString(){return this.string==null&&(this.string=ke.encode(this.multihash.bytes).slice(1)),this.string}toCID(){return U.createV1(Zh,this.multihash)}toBytes(){return this.multihash.bytes}toJSON(){return this.toString()}equals(e){if(e==null)return!1;if(e instanceof Uint8Array)return ce(this.multihash.bytes,e);if(typeof e=="string")return Je(e).equals(this);if(e?.multihash?.bytes!=null)return ce(this.multihash.bytes,e.multihash.bytes);throw new Error("not valid Id")}[Zb](){return`PeerId(${this.toString()})`}},co=class extends di{type="RSA";publicKey;constructor(e){super({...e,type:"RSA"}),this.publicKey=e.publicKey}},lo=class extends di{type="Ed25519";publicKey;constructor(e){super({...e,type:"Ed25519"}),this.publicKey=e.multihash.digest}},uo=class extends di{type="secp256k1";publicKey;constructor(e){super({...e,type:"secp256k1"}),this.publicKey=e.multihash.digest}};function Je(r,e){if(e=e??Xh,r.charAt(0)==="1"||r.charAt(0)==="Q"){let t=Ze(ke.decode(`z${r}`));return r.startsWith("12D")?new lo({multihash:t}):r.startsWith("16U")?new uo({multihash:t}):new co({multihash:t})}return hi(Xh.decode(r))}function hi(r){try{let e=Ze(r);if(e.code===qe.code){if(e.digest.length===mu)return new lo({multihash:e});if(e.digest.length===yu)return new uo({multihash:e})}if(e.code===ae.code)return new co({multihash:e})}catch{return Jb(U.decode(r))}throw new Error("Supplied PeerID CID is invalid")}function Jb(r){if(r==null||r.multihash==null||r.version==null||r.version===1&&r.code!==Zh)throw new Error("Supplied PeerID CID is invalid");let e=r.multihash;if(e.code===ae.code)return new co({multihash:r.multihash});if(e.code===qe.code){if(e.digest.length===mu)return new lo({multihash:r.multihash});if(e.digest.length===yu)return new uo({multihash:r.multihash})}throw new Error("Supplied PeerID CID is invalid")}async function Jh(r,e){return r.length===mu?new lo({multihash:Zt(qe.code,r),privateKey:e}):r.length===yu?new uo({multihash:Zt(qe.code,r),privateKey:e}):new co({multihash:await ae.digest(r),publicKey:r,privateKey:e})}var Ks=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,o){return this.readAtomically(()=>{let i=0,s=0,a=this.peekChar();if(a===void 0)return;let c=a==="0",u=2**(8*o)-1;for(;;){let l=this.readAtomically(()=>{let f=this.readChar();if(f===void 0)return;let m=Number.parseInt(f,e);if(!Number.isNaN(m))return m});if(l===void 0)break;if(i*=e,i+=l,i>u||(s+=1,t!==void 0&&s>t))return}if(s!==0)return!n&&c&&s>1?void 0:i})}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 o=n*2;if(n<t.length-3){let s=this.readSeparator(":",n,()=>this.readIPv4Addr());if(s!==void 0)return t[o]=s[0],t[o+1]=s[1],t[o+2]=s[2],t[o+3]=s[3],[o+4,!0]}let i=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(i===void 0)return[o,!1];t[o]=i>>8,t[o+1]=i&255}return[t.length,!1]};return this.readAtomically(()=>{let t=new Uint8Array(16),[n,o]=e(t);if(n===16)return t;if(o||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let i=new Uint8Array(14),s=16-(n+2),[a]=e(i.subarray(0,s));return t.set(i.subarray(0,a),16-a),t})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var Qh=45,Qb=15,fo=new Ks;function gu(r){if(!(r.length>Qb))return fo.new(r).parseWith(()=>fo.readIPv4Addr())}function wu(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>Qh))return fo.new(r).parseWith(()=>fo.readIPv6Addr())}function Gs(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>Qh))return fo.new(r).parseWith(()=>fo.readIPAddr())}var W5=parseInt("0xFFFF",16),j5=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function rp(r){return!!gu(r)}function np(r){return!!wu(r)}function qs(r){return!!Gs(r)}var op=rp,ox=np,bu=function(r){let e=0;if(r=r.toString().trim(),op(r)){let t=new Uint8Array(e+4);return r.split(/\./g).forEach(n=>{t[e++]=parseInt(n,10)&255}),t}if(ox(r)){let t=r.split(":",8),n;for(n=0;n<t.length;n++){let i=op(t[n]),s;i&&(s=bu(t[n]),t[n]=W(s.slice(0,2),"base16")),s!=null&&++n<8&&t.splice(n,0,W(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 i=[n,1];for(n=9-t.length;n>0;n--)i.push("0");t.splice.apply(t,i)}let o=new Uint8Array(e+16);for(n=0;n<t.length;n++){let i=parseInt(t[n],16);o[e++]=i>>8&255,o[e++]=i&255}return o}throw new Error("invalid ip address")},ip=function(r,e=0,t){e=~~e,t=t??r.length-e;let n=new DataView(r.buffer);if(t===4){let o=[];for(let i=0;i<t;i++)o.push(r[e+i]);return o.join(".")}if(t===16){let o=[];for(let i=0;i<t;i+=2)o.push(n.getUint16(e+i).toString(16));return o.join(":").replace(/(^|:)0(:0)*:0(:|$)/,"$1::$3").replace(/:{3,4}/,"::")}return""};var ho={},xu={},sx=[[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"]];sx.forEach(r=>{let e=ax(...r);xu[e.code]=e,ho[e.name]=e});function ax(r,e,t,n,o){return{code:r,size:e,name:t,resolvable:!!n,path:!!o}}function de(r){if(typeof r=="number"){if(xu[r]!=null)return xu[r];throw new Error(`no protocol with code: ${r}`)}else if(typeof r=="string"){if(ho[r]!=null)return ho[r];throw new Error(`no protocol with name: ${r}`)}throw new Error(`invalid protocol id type: ${typeof r}`)}var N8=de("ip4"),C8=de("ip6"),L8=de("ipcidr");function vu(r,e){switch(de(r).code){case 4:case 41:return lx(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 hx(e);case 444:return lp(e);case 445:return lp(e);case 466:return dx(e);default:return W(e,"base16")}}function Au(r,e){switch(de(r).code){case 4:return sp(e);case 41:return sp(e);case 42:return ap(e);case 6:case 273:case 33:case 132:return Su(parseInt(e,10));case 53:case 54:case 55:case 56:case 400:case 449:case 777:return ap(e);case 421:return ux(e);case 444:return px(e);case 445:return mx(e);case 466:return fx(e);default:return F(e,"base16")}}var Eu=Object.values(Kr).map(r=>r.decoder),cx=function(){let r=Eu[0].or(Eu[1]);return Eu.slice(2).forEach(e=>r=r.or(e)),r}();function sp(r){if(!qs(r))throw new Error("invalid ip address");return bu(r)}function lx(r){let e=ip(r,0,r.length);if(e==null)throw new Error("ipBuff is required");if(!qs(e))throw new Error("invalid ip address");return e}function Su(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 ap(r){let e=F(r),t=Uint8Array.from(io(e.length));return ue([t,e],t.length+e.length)}function cp(r){let e=_n(r);if(r=r.slice(st(e)),r.length!==e)throw new Error("inconsistent lengths");return W(r)}function ux(r){let e;r[0]==="Q"||r[0]==="1"?e=Ze(ke.decode(`z${r}`)).bytes:e=U.parse(r).multihash.bytes;let t=Uint8Array.from(io(e.length));return ue([t,e],t.length+e.length)}function fx(r){let e=cx.decode(r),t=Uint8Array.from(io(e.length));return ue([t,e],t.length+e.length)}function dx(r){let e=_n(r),t=r.slice(st(e));if(t.length!==e)throw new Error("inconsistent lengths");return"u"+W(t,"base64url")}function hx(r){let e=_n(r),t=r.slice(st(e));if(t.length!==e)throw new Error("inconsistent lengths");return W(t,"base58btc")}function px(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=Fe.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 o=Su(n);return ue([t,o],t.length+o.length)}function mx(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=Fe.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 o=Su(n);return ue([t,o],t.length+o.length)}function lp(r){let e=r.slice(0,r.length-2),t=r.slice(r.length-2),n=W(e,"base32"),o=up(t);return`${n}:${o}`}function fp(r){r=_u(r);let e=[],t=[],n=null,o=r.split("/").slice(1);if(o.length===1&&o[0]==="")return{bytes:new Uint8Array,string:"/",tuples:[],stringTuples:[],path:null};for(let i=0;i<o.length;i++){let s=o[i],a=de(s);if(a.size===0){e.push([a.code]),t.push([a.code]);continue}if(i++,i>=o.length)throw hp("invalid address: "+r);if(a.path===!0){n=_u(o.slice(i).join("/")),e.push([a.code,Au(a.code,n)]),t.push([a.code,n]);break}let c=Au(a.code,o[i]);e.push([a.code,c]),t.push([a.code,vu(a.code,c)])}return{string:dp(t),bytes:Iu(e),tuples:e,stringTuples:t,path:n}}function ku(r){let e=[],t=[],n=null,o=0;for(;o<r.length;){let i=_n(r,o),s=st(i),a=de(i),c=yx(a,r.slice(o+s));if(c===0){e.push([i]),t.push([i]),o+=s;continue}let u=r.slice(o+s,o+s+c);if(o+=c+s,o>r.length)throw hp("Invalid address Uint8Array: "+W(r,"base16"));e.push([i,u]);let l=vu(i,u);if(t.push([i,l]),a.path===!0){n=l;break}}return{bytes:Uint8Array.from(r),string:dp(t),tuples:e,stringTuples:t,path:n}}function dp(r){let e=[];return r.map(t=>{let n=de(t[0]);return e.push(n.name),t.length>1&&t[1]!=null&&e.push(t[1]),null}),_u(e.join("/"))}function Iu(r){return ue(r.map(e=>{let t=de(e[0]),n=Uint8Array.from(io(t.code));return e.length>1&&e[1]!=null&&(n=ue([n,e[1]])),n}))}function yx(r,e){if(r.size>0)return r.size/8;if(r.size===0)return 0;{let t=_n(e instanceof Uint8Array?e:Uint8Array.from(e));return t+st(t)}}function _u(r){return"/"+r.trim().split("/").filter(e=>e).join("/")}function hp(r){return new Error("Error parsing address: "+r)}var gx=Symbol.for("nodejs.util.inspect.custom"),Bu=Symbol.for("@multiformats/js-multiaddr/multiaddr"),wx=[de("dns").code,de("dns4").code,de("dns6").code,de("dnsaddr").code],Ws=class r{bytes;#e;#t;#r;#s;[Bu]=!0;constructor(e){e==null&&(e="");let t;if(e instanceof Uint8Array)t=ku(e);else if(typeof e=="string"){if(e.length>0&&e.charAt(0)!=="/")throw new Error(`multiaddr "${e}" must start with a "/"`);t=fp(e)}else if(mp(e))t=ku(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,o,i="",s=de("tcp"),a=de("udp"),c=de("ip4"),u=de("ip6"),l=de("dns6"),f=de("ip6zone");for(let[d,p]of this.stringTuples())d===f.code&&(i=`%${p??""}`),wx.includes(d)&&(t=s.name,o=443,n=`${p??""}${i}`,e=d===l.code?6:4),(d===s.code||d===a.code)&&(t=de(d).name,o=parseInt(p??"")),(d===c.code||d===u.code)&&(t=de(d).name,n=`${p??""}${i}`,e=d===u.code?6:4);if(e==null||t==null||n==null||o==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:o}}protos(){return this.#t.map(([e])=>Object.assign({},de(e)))}protoCodes(){return this.#t.map(([e])=>e)}protoNames(){return this.#t.map(([e])=>de(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(),o=n.lastIndexOf(t);if(o<0)throw new Error(`Address ${this.toString()} does not contain subaddress: ${e.toString()}`);return new r(n.slice(0,o))}decapsulateCode(e){let t=this.tuples();for(let n=t.length-1;n>=0;n--)if(t[n][0]===e)return new r(Iu(t.slice(0,n)));return this}getPeerId(){try{let e=[];this.stringTuples().forEach(([n,o])=>{n===ho.p2p.code&&e.push([n,o]),n===ho["p2p-circuit"].code&&(e=[])});let t=e.pop();if(t?.[1]!=null){let n=t[1];return n[0]==="Q"||n[0]==="1"?W(ke.decode(`z${n}`),"base58btc"):W(U.parse(n).multihash.bytes,"base58btc")}return null}catch{return null}}getPath(){return this.#s}equals(e){return ce(this.bytes,e.bytes)}async resolve(e){let t=this.protos().find(i=>i.resolvable);if(t==null)return[this];let n=pp.get(t.name);if(n==null)throw new P(`no available resolver for ${t.name}`,"ERR_NO_AVAILABLE_RESOLVER");return(await n(this,e)).map(i=>pi(i))}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)}[gx](){return`Multiaddr(${this.#e})`}};var pp=new Map;function mp(r){return!!r?.[Bu]}function pi(r){return new Ws(r)}async function*js(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 Gu={};ve(Gu,{Ed25519PrivateKey:()=>Cn,Ed25519PublicKey:()=>gi,generateKeyPair:()=>BE,generateKeyPairFromSeed:()=>zp,unmarshalEd25519PrivateKey:()=>kE,unmarshalEd25519PublicKey:()=>IE});function Nt(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}function po(r){if(!Number.isSafeInteger(r)||r<0)throw new Error(`positive integer expected, not ${r}`)}function bx(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}function mo(r,...e){if(!bx(r))throw new Error("Uint8Array expected");if(e.length>0&&!e.includes(r.length))throw new Error(`Uint8Array expected of length ${e}, not of length=${r.length}`)}function Ys(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");po(r.outputLen),po(r.blockLen)}function yo(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 yp(r,e){mo(r);let t=e.outputLen;if(r.length<t)throw new Error(`digestInto() expects output buffer of length at least ${t}`)}var Xs=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;var wo=r=>new DataView(r.buffer,r.byteOffset,r.byteLength),Vt=(r,e)=>r<<32-e|r>>>e;var dk=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;var xx=async()=>{};async function gp(r,e,t){let n=Date.now();for(let o=0;o<r;o++){t(o);let i=Date.now()-n;i>=0&&i<e||(await xx(),n+=i)}}function Ru(r){if(typeof r!="string")throw new Error(`utf8ToBytes expected string, got ${typeof r}`);return new Uint8Array(new TextEncoder().encode(r))}function Gr(r){return typeof r=="string"&&(r=Ru(r)),mo(r),r}function Zs(...r){let e=0;for(let n=0;n<r.length;n++){let o=r[n];mo(o),e+=o.length}let t=new Uint8Array(e);for(let n=0,o=0;n<r.length;n++){let i=r[n];t.set(i,o),o+=i.length}return t}var go=class{clone(){return this._cloneInto()}},Ex={}.toString;function wp(r,e){if(e!==void 0&&Ex.call(e)!=="[object Object]")throw new Error("Options should be object or undefined");return Object.assign(r,e)}function Js(r){let e=n=>r().update(Gr(n)).digest(),t=r();return e.outputLen=t.outputLen,e.blockLen=t.blockLen,e.create=()=>r(),e}function bo(r=32){if(Xs&&typeof Xs.getRandomValues=="function")return Xs.getRandomValues(new Uint8Array(r));throw new Error("crypto.getRandomValues must be defined")}function vx(r,e,t,n){if(typeof r.setBigUint64=="function")return r.setBigUint64(e,t,n);let o=BigInt(32),i=BigInt(4294967295),s=Number(t>>o&i),a=Number(t&i),c=n?4:0,u=n?0:4;r.setUint32(e+c,s,n),r.setUint32(e+u,a,n)}var bp=(r,e,t)=>r&e^~r&t,xp=(r,e,t)=>r&e^r&t^e&t,xo=class extends go{constructor(e,t,n,o){super(),this.blockLen=e,this.outputLen=t,this.padOffset=n,this.isLE=o,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(e),this.view=wo(this.buffer)}update(e){yo(this);let{view:t,buffer:n,blockLen:o}=this;e=Gr(e);let i=e.length;for(let s=0;s<i;){let a=Math.min(o-this.pos,i-s);if(a===o){let c=wo(e);for(;o<=i-s;s+=o)this.process(c,s);continue}n.set(e.subarray(s,s+a),this.pos),this.pos+=a,s+=a,this.pos===o&&(this.process(t,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){yo(this),yp(e,this),this.finished=!0;let{buffer:t,view:n,blockLen:o,isLE:i}=this,{pos:s}=this;t[s++]=128,this.buffer.subarray(s).fill(0),this.padOffset>o-s&&(this.process(n,0),s=0);for(let f=s;f<o;f++)t[f]=0;vx(n,o-8,BigInt(this.length*8),i),this.process(n,0);let a=wo(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 f=0;f<u;f++)a.setUint32(4*f,l[f],i)}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:o,finished:i,destroyed:s,pos:a}=this;return e.length=o,e.pos=a,e.finished=i,e.destroyed=s,o%t&&e.buffer.set(n),e}};var Qs=BigInt(4294967295),Tu=BigInt(32);function Ep(r,e=!1){return e?{h:Number(r&Qs),l:Number(r>>Tu&Qs)}:{h:Number(r>>Tu&Qs)|0,l:Number(r&Qs)|0}}function Ax(r,e=!1){let t=new Uint32Array(r.length),n=new Uint32Array(r.length);for(let o=0;o<r.length;o++){let{h:i,l:s}=Ep(r[o],e);[t[o],n[o]]=[i,s]}return[t,n]}var Sx=(r,e)=>BigInt(r>>>0)<<Tu|BigInt(e>>>0),_x=(r,e,t)=>r>>>t,kx=(r,e,t)=>r<<32-t|e>>>t,Ix=(r,e,t)=>r>>>t|e<<32-t,Bx=(r,e,t)=>r<<32-t|e>>>t,Rx=(r,e,t)=>r<<64-t|e>>>t-32,Tx=(r,e,t)=>r>>>t-32|e<<64-t,Nx=(r,e)=>e,Cx=(r,e)=>r,Lx=(r,e,t)=>r<<t|e>>>32-t,Dx=(r,e,t)=>e<<t|r>>>32-t,Px=(r,e,t)=>e<<t-32|r>>>64-t,Ox=(r,e,t)=>r<<t-32|e>>>64-t;function Ux(r,e,t,n){let o=(e>>>0)+(n>>>0);return{h:r+t+(o/2**32|0)|0,l:o|0}}var Fx=(r,e,t)=>(r>>>0)+(e>>>0)+(t>>>0),Vx=(r,e,t,n)=>e+t+n+(r/2**32|0)|0,Hx=(r,e,t,n)=>(r>>>0)+(e>>>0)+(t>>>0)+(n>>>0),Mx=(r,e,t,n,o)=>e+t+n+o+(r/2**32|0)|0,zx=(r,e,t,n,o)=>(r>>>0)+(e>>>0)+(t>>>0)+(n>>>0)+(o>>>0),$x=(r,e,t,n,o,i)=>e+t+n+o+i+(r/2**32|0)|0;var Kx={fromBig:Ep,split:Ax,toBig:Sx,shrSH:_x,shrSL:kx,rotrSH:Ix,rotrSL:Bx,rotrBH:Rx,rotrBL:Tx,rotr32H:Nx,rotr32L:Cx,rotlSH:Lx,rotlSL:Dx,rotlBH:Px,rotlBL:Ox,add:Ux,add3L:Fx,add3H:Vx,add4L:Hx,add4H:Mx,add5H:$x,add5L:zx},Y=Kx;var[Gx,qx]=Y.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))),qr=new Uint32Array(80),Wr=new Uint32Array(80),Nu=class extends xo{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:o,Ch:i,Cl:s,Dh:a,Dl:c,Eh:u,El:l,Fh:f,Fl:m,Gh:d,Gl:p,Hh:h,Hl:g}=this;return[e,t,n,o,i,s,a,c,u,l,f,m,d,p,h,g]}set(e,t,n,o,i,s,a,c,u,l,f,m,d,p,h,g){this.Ah=e|0,this.Al=t|0,this.Bh=n|0,this.Bl=o|0,this.Ch=i|0,this.Cl=s|0,this.Dh=a|0,this.Dl=c|0,this.Eh=u|0,this.El=l|0,this.Fh=f|0,this.Fl=m|0,this.Gh=d|0,this.Gl=p|0,this.Hh=h|0,this.Hl=g|0}process(e,t){for(let b=0;b<16;b++,t+=4)qr[b]=e.getUint32(t),Wr[b]=e.getUint32(t+=4);for(let b=16;b<80;b++){let S=qr[b-15]|0,_=Wr[b-15]|0,A=Y.rotrSH(S,_,1)^Y.rotrSH(S,_,8)^Y.shrSH(S,_,7),v=Y.rotrSL(S,_,1)^Y.rotrSL(S,_,8)^Y.shrSL(S,_,7),E=qr[b-2]|0,R=Wr[b-2]|0,N=Y.rotrSH(E,R,19)^Y.rotrBH(E,R,61)^Y.shrSH(E,R,6),T=Y.rotrSL(E,R,19)^Y.rotrBL(E,R,61)^Y.shrSL(E,R,6),H=Y.add4L(v,T,Wr[b-7],Wr[b-16]),D=Y.add4H(H,A,N,qr[b-7],qr[b-16]);qr[b]=D|0,Wr[b]=H|0}let{Ah:n,Al:o,Bh:i,Bl:s,Ch:a,Cl:c,Dh:u,Dl:l,Eh:f,El:m,Fh:d,Fl:p,Gh:h,Gl:g,Hh:y,Hl:x}=this;for(let b=0;b<80;b++){let S=Y.rotrSH(f,m,14)^Y.rotrSH(f,m,18)^Y.rotrBH(f,m,41),_=Y.rotrSL(f,m,14)^Y.rotrSL(f,m,18)^Y.rotrBL(f,m,41),A=f&d^~f&h,v=m&p^~m&g,E=Y.add5L(x,_,v,qx[b],Wr[b]),R=Y.add5H(E,y,S,A,Gx[b],qr[b]),N=E|0,T=Y.rotrSH(n,o,28)^Y.rotrBH(n,o,34)^Y.rotrBH(n,o,39),H=Y.rotrSL(n,o,28)^Y.rotrBL(n,o,34)^Y.rotrBL(n,o,39),D=n&i^n&a^i&a,Q=o&s^o&c^s&c;y=h|0,x=g|0,h=d|0,g=p|0,d=f|0,p=m|0,{h:f,l:m}=Y.add(u|0,l|0,R|0,N|0),u=a|0,l=c|0,a=i|0,c=s|0,i=n|0,s=o|0;let k=Y.add3L(N,H,Q);n=Y.add3H(k,R,T,D),o=k|0}({h:n,l:o}=Y.add(this.Ah|0,this.Al|0,n|0,o|0)),{h:i,l:s}=Y.add(this.Bh|0,this.Bl|0,i|0,s|0),{h:a,l:c}=Y.add(this.Ch|0,this.Cl|0,a|0,c|0),{h:u,l}=Y.add(this.Dh|0,this.Dl|0,u|0,l|0),{h:f,l:m}=Y.add(this.Eh|0,this.El|0,f|0,m|0),{h:d,l:p}=Y.add(this.Fh|0,this.Fl|0,d|0,p|0),{h,l:g}=Y.add(this.Gh|0,this.Gl|0,h|0,g|0),{h:y,l:x}=Y.add(this.Hh|0,this.Hl|0,y|0,x|0),this.set(n,o,i,s,a,c,u,l,f,m,d,p,h,g,y,x)}roundClean(){qr.fill(0),Wr.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 Eo=Js(()=>new Nu);var ta={};ve(ta,{abytes:()=>vo,bitGet:()=>Qx,bitLen:()=>Jx,bitMask:()=>mi,bitSet:()=>eE,bytesToHex:()=>yr,bytesToNumberBE:()=>gr,bytesToNumberLE:()=>Yr,concatBytes:()=>wr,createHmacDrbg:()=>Du,ensureBytes:()=>Se,equalBytes:()=>Xx,hexToBytes:()=>Rn,hexToNumber:()=>Lu,isBytes:()=>jr,numberToBytesBE:()=>Xr,numberToBytesLE:()=>Tn,numberToHexUnpadded:()=>_p,numberToVarBytesBE:()=>Yx,utf8ToBytes:()=>Zx,validateObject:()=>er});var Sp=BigInt(0),ea=BigInt(1),Wx=BigInt(2);function jr(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}function vo(r){if(!jr(r))throw new Error("Uint8Array expected")}var jx=Array.from({length:256},(r,e)=>e.toString(16).padStart(2,"0"));function yr(r){vo(r);let e="";for(let t=0;t<r.length;t++)e+=jx[r[t]];return e}function _p(r){let e=r.toString(16);return e.length&1?`0${e}`:e}function Lu(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return BigInt(r===""?"0":`0x${r}`)}var mr={_0:48,_9:57,_A:65,_F:70,_a:97,_f:102};function vp(r){if(r>=mr._0&&r<=mr._9)return r-mr._0;if(r>=mr._A&&r<=mr._F)return r-(mr._A-10);if(r>=mr._a&&r<=mr._f)return r-(mr._a-10)}function Rn(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 o=0,i=0;o<t;o++,i+=2){let s=vp(r.charCodeAt(i)),a=vp(r.charCodeAt(i+1));if(s===void 0||a===void 0){let c=r[i]+r[i+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+i)}n[o]=s*16+a}return n}function gr(r){return Lu(yr(r))}function Yr(r){return vo(r),Lu(yr(Uint8Array.from(r).reverse()))}function Xr(r,e){return Rn(r.toString(16).padStart(e*2,"0"))}function Tn(r,e){return Xr(r,e).reverse()}function Yx(r){return Rn(_p(r))}function Se(r,e,t){let n;if(typeof e=="string")try{n=Rn(e)}catch(i){throw new Error(`${r} must be valid hex string, got "${e}". Cause: ${i}`)}else if(jr(e))n=Uint8Array.from(e);else throw new Error(`${r} must be hex string or Uint8Array`);let o=n.length;if(typeof t=="number"&&o!==t)throw new Error(`${r} expected ${t} bytes, got ${o}`);return n}function wr(...r){let e=0;for(let n=0;n<r.length;n++){let o=r[n];vo(o),e+=o.length}let t=new Uint8Array(e);for(let n=0,o=0;n<r.length;n++){let i=r[n];t.set(i,o),o+=i.length}return t}function Xx(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 Zx(r){if(typeof r!="string")throw new Error(`utf8ToBytes expected string, got ${typeof r}`);return new Uint8Array(new TextEncoder().encode(r))}function Jx(r){let e;for(e=0;r>Sp;r>>=ea,e+=1);return e}function Qx(r,e){return r>>BigInt(e)&ea}function eE(r,e,t){return r|(t?ea:Sp)<<BigInt(e)}var mi=r=>(Wx<<BigInt(r-1))-ea,Cu=r=>new Uint8Array(r),Ap=r=>Uint8Array.from(r);function Du(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=Cu(r),o=Cu(r),i=0,s=()=>{n.fill(1),o.fill(0),i=0},a=(...f)=>t(o,n,...f),c=(f=Cu())=>{o=a(Ap([0]),f),n=a(),f.length!==0&&(o=a(Ap([1]),f),n=a())},u=()=>{if(i++>=1e3)throw new Error("drbg: tried 1000 values");let f=0,m=[];for(;f<e;){n=a();let d=n.slice();m.push(d),f+=n.length}return wr(...m)};return(f,m)=>{s(),c(f);let d;for(;!(d=m(u()));)c();return s(),d}}var tE={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"||jr(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 er(r,e,t={}){let n=(o,i,s)=>{let a=tE[i];if(typeof a!="function")throw new Error(`Invalid validator "${i}", expected function`);let c=r[o];if(!(s&&c===void 0)&&!a(c,r))throw new Error(`Invalid param ${String(o)}=${c} (${typeof c}), expected ${i}`)};for(let[o,i]of Object.entries(e))n(o,i,!1);for(let[o,i]of Object.entries(t))n(o,i,!0);return r}var Le=BigInt(0),he=BigInt(1),Nn=BigInt(2),rE=BigInt(3),Pu=BigInt(4),kp=BigInt(5),Ip=BigInt(8),nE=BigInt(9),oE=BigInt(16);function fe(r,e){let t=r%e;return t>=Le?t:e+t}function iE(r,e,t){if(t<=Le||e<Le)throw new Error("Expected power/modulo > 0");if(t===he)return Le;let n=he;for(;e>Le;)e&he&&(n=n*r%t),r=r*r%t,e>>=he;return n}function pe(r,e,t){let n=r;for(;e-- >Le;)n*=n,n%=t;return n}function ra(r,e){if(r===Le||e<=Le)throw new Error(`invert: expected positive integers, got n=${r} mod=${e}`);let t=fe(r,e),n=e,o=Le,i=he,s=he,a=Le;for(;t!==Le;){let u=n/t,l=n%t,f=o-s*u,m=i-a*u;n=t,t=l,o=s,i=a,s=f,a=m}if(n!==he)throw new Error("invert: does not exist");return fe(o,e)}function sE(r){let e=(r-he)/Nn,t,n,o;for(t=r-he,n=0;t%Nn===Le;t/=Nn,n++);for(o=Nn;o<r&&iE(o,e,r)!==r-he;o++);if(n===1){let s=(r+he)/Pu;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 i=(t+he)/Nn;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,o),t),f=a.pow(c,i),m=a.pow(c,t);for(;!a.eql(m,a.ONE);){if(a.eql(m,a.ZERO))return a.ZERO;let d=1;for(let h=a.sqr(m);d<u&&!a.eql(h,a.ONE);d++)h=a.sqr(h);let p=a.pow(l,he<<BigInt(u-d-1));l=a.sqr(p),f=a.mul(f,p),m=a.mul(m,l),u=d}return f}}function aE(r){if(r%Pu===rE){let e=(r+he)/Pu;return function(n,o){let i=n.pow(o,e);if(!n.eql(n.sqr(i),o))throw new Error("Cannot find square root");return i}}if(r%Ip===kp){let e=(r-kp)/Ip;return function(n,o){let i=n.mul(o,Nn),s=n.pow(i,e),a=n.mul(o,s),c=n.mul(n.mul(a,Nn),s),u=n.mul(a,n.sub(c,n.ONE));if(!n.eql(n.sqr(u),o))throw new Error("Cannot find square root");return u}}return r%oE,sE(r)}var Bp=(r,e)=>(fe(r,e)&he)===he,cE=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Ou(r){let e={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},t=cE.reduce((n,o)=>(n[o]="function",n),e);return er(r,t)}function lE(r,e,t){if(t<Le)throw new Error("Expected power > 0");if(t===Le)return r.ONE;if(t===he)return e;let n=r.ONE,o=e;for(;t>Le;)t&he&&(n=r.mul(n,o)),o=r.sqr(o),t>>=he;return n}function uE(r,e){let t=new Array(e.length),n=e.reduce((i,s,a)=>r.is0(s)?i:(t[a]=i,r.mul(i,s)),r.ONE),o=r.inv(n);return e.reduceRight((i,s,a)=>r.is0(s)?i:(t[a]=r.mul(i,t[a]),r.mul(i,s)),o),t}function Uu(r,e){let t=e!==void 0?e:r.toString(2).length,n=Math.ceil(t/8);return{nBitLength:t,nByteLength:n}}function na(r,e,t=!1,n={}){if(r<=Le)throw new Error(`Expected Field ORDER > 0, got ${r}`);let{nBitLength:o,nByteLength:i}=Uu(r,e);if(i>2048)throw new Error("Field lengths over 2048 bytes are not supported");let s=aE(r),a=Object.freeze({ORDER:r,BITS:o,BYTES:i,MASK:mi(o),ZERO:Le,ONE:he,create:c=>fe(c,r),isValid:c=>{if(typeof c!="bigint")throw new Error(`Invalid field element: expected bigint, got ${typeof c}`);return Le<=c&&c<r},is0:c=>c===Le,isOdd:c=>(c&he)===he,neg:c=>fe(-c,r),eql:(c,u)=>c===u,sqr:c=>fe(c*c,r),add:(c,u)=>fe(c+u,r),sub:(c,u)=>fe(c-u,r),mul:(c,u)=>fe(c*u,r),pow:(c,u)=>lE(a,c,u),div:(c,u)=>fe(c*ra(u,r),r),sqrN:c=>c*c,addN:(c,u)=>c+u,subN:(c,u)=>c-u,mulN:(c,u)=>c*u,inv:c=>ra(c,r),sqrt:n.sqrt||(c=>s(a,c)),invertBatch:c=>uE(a,c),cmov:(c,u,l)=>l?u:c,toBytes:c=>t?Tn(c,i):Xr(c,i),fromBytes:c=>{if(c.length!==i)throw new Error(`Fp.fromBytes: expected ${i}, got ${c.length}`);return t?Yr(c):gr(c)}});return Object.freeze(a)}function Rp(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 Tp(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 Fu(r){let e=Tp(r);return e+Math.ceil(e/2)}function Np(r,e,t=!1){let n=r.length,o=Tp(e),i=Fu(e);if(n<16||n<i||n>1024)throw new Error(`expected ${i}-1024 bytes of input, got ${n}`);let s=t?gr(r):Yr(r),a=fe(s,e-he)+he;return t?Tn(a,o):Xr(a,o)}var dE=BigInt(0),Vu=BigInt(1);function oa(r,e){let t=(o,i)=>{let s=i.negate();return o?s:i},n=o=>{let i=Math.ceil(e/o)+1,s=2**(o-1);return{windows:i,windowSize:s}};return{constTimeNegate:t,unsafeLadder(o,i){let s=r.ZERO,a=o;for(;i>dE;)i&Vu&&(s=s.add(a)),a=a.double(),i>>=Vu;return s},precomputeWindow(o,i){let{windows:s,windowSize:a}=n(i),c=[],u=o,l=u;for(let f=0;f<s;f++){l=u,c.push(l);for(let m=1;m<a;m++)l=l.add(u),c.push(l);u=l.double()}return c},wNAF(o,i,s){let{windows:a,windowSize:c}=n(o),u=r.ZERO,l=r.BASE,f=BigInt(2**o-1),m=2**o,d=BigInt(o);for(let p=0;p<a;p++){let h=p*c,g=Number(s&f);s>>=d,g>c&&(g-=m,s+=Vu);let y=h,x=h+Math.abs(g)-1,b=p%2!==0,S=g<0;g===0?l=l.add(t(b,i[y])):u=u.add(t(S,i[x]))}return{p:u,f:l}},wNAFCached(o,i,s,a){let c=o._WINDOW_SIZE||1,u=i.get(o);return u||(u=this.precomputeWindow(o,c),c!==1&&i.set(o,a(u))),this.wNAF(c,u,s)}}}function yi(r){return Ou(r.Fp),er(r,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...Uu(r.n,r.nBitLength),...r,p:r.Fp.ORDER})}var Ht=BigInt(0),yt=BigInt(1),ia=BigInt(2),hE=BigInt(8),pE={zip215:!0};function mE(r){let e=yi(r);return er(r,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...e})}function sa(r){let e=mE(r),{Fp:t,n,prehash:o,hash:i,randomBytes:s,nByteLength:a,h:c}=e,u=ia<<BigInt(a*8)-yt,l=t.create,f=e.uvRatio||((C,I)=>{try{return{isValid:!0,value:t.sqrt(C*t.inv(I))}}catch{return{isValid:!1,value:Ht}}}),m=e.adjustScalarBytes||(C=>C),d=e.domain||((C,I,z)=>{if(I.length||z)throw new Error("Contexts/pre-hash are not supported");return C}),p=C=>typeof C=="bigint"&&Ht<C,h=(C,I)=>p(C)&&p(I)&&C<I,g=C=>C===Ht||h(C,u);function y(C,I){if(h(C,I))return C;throw new Error(`Expected valid scalar < ${I}, got ${typeof C} ${C}`)}function x(C){return C===Ht?C:y(C,n)}let b=new Map;function S(C){if(!(C instanceof _))throw new Error("ExtendedPoint expected")}class _{constructor(I,z,K,j){if(this.ex=I,this.ey=z,this.ez=K,this.et=j,!g(I))throw new Error("x required");if(!g(z))throw new Error("y required");if(!g(K))throw new Error("z required");if(!g(j))throw new Error("t required")}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(I){if(I instanceof _)throw new Error("extended point not allowed");let{x:z,y:K}=I||{};if(!g(z)||!g(K))throw new Error("invalid affine point");return new _(z,K,yt,l(z*K))}static normalizeZ(I){let z=t.invertBatch(I.map(K=>K.ez));return I.map((K,j)=>K.toAffine(z[j])).map(_.fromAffine)}_setWindowSize(I){this._WINDOW_SIZE=I,b.delete(this)}assertValidity(){let{a:I,d:z}=e;if(this.is0())throw new Error("bad point: ZERO");let{ex:K,ey:j,ez:X,et:Z}=this,se=l(K*K),re=l(j*j),oe=l(X*X),Re=l(oe*oe),xe=l(se*I),Oe=l(oe*l(xe+re)),Ue=l(Re+l(z*l(se*re)));if(Oe!==Ue)throw new Error("bad point: equation left != right (1)");let Ce=l(K*j),$e=l(X*Z);if(Ce!==$e)throw new Error("bad point: equation left != right (2)")}equals(I){S(I);let{ex:z,ey:K,ez:j}=this,{ex:X,ey:Z,ez:se}=I,re=l(z*se),oe=l(X*j),Re=l(K*se),xe=l(Z*j);return re===oe&&Re===xe}is0(){return this.equals(_.ZERO)}negate(){return new _(l(-this.ex),this.ey,this.ez,l(-this.et))}double(){let{a:I}=e,{ex:z,ey:K,ez:j}=this,X=l(z*z),Z=l(K*K),se=l(ia*l(j*j)),re=l(I*X),oe=z+K,Re=l(l(oe*oe)-X-Z),xe=re+Z,Oe=xe-se,Ue=re-Z,Ce=l(Re*Oe),$e=l(xe*Ue),dr=l(Re*Ue),En=l(Oe*xe);return new _(Ce,$e,En,dr)}add(I){S(I);let{a:z,d:K}=e,{ex:j,ey:X,ez:Z,et:se}=this,{ex:re,ey:oe,ez:Re,et:xe}=I;if(z===BigInt(-1)){let $d=l((X-j)*(oe+re)),Kd=l((X+j)*(oe-re)),xl=l(Kd-$d);if(xl===Ht)return this.double();let Gd=l(Z*ia*xe),qd=l(se*ia*Re),Wd=qd+Gd,jd=Kd+$d,Yd=qd-Gd,Lw=l(Wd*xl),Dw=l(jd*Yd),Pw=l(Wd*Yd),Ow=l(xl*jd);return new _(Lw,Dw,Ow,Pw)}let Oe=l(j*re),Ue=l(X*oe),Ce=l(se*K*xe),$e=l(Z*Re),dr=l((j+X)*(re+oe)-Oe-Ue),En=$e-Ce,ni=$e+Ce,zd=l(Ue-z*Oe),Rw=l(dr*En),Tw=l(ni*zd),Nw=l(dr*zd),Cw=l(En*ni);return new _(Rw,Tw,Cw,Nw)}subtract(I){return this.add(I.negate())}wNAF(I){return E.wNAFCached(this,b,I,_.normalizeZ)}multiply(I){let{p:z,f:K}=this.wNAF(y(I,n));return _.normalizeZ([z,K])[0]}multiplyUnsafe(I){let z=x(I);return z===Ht?v:this.equals(v)||z===yt?this:this.equals(A)?this.wNAF(z).p:E.unsafeLadder(this,z)}isSmallOrder(){return this.multiplyUnsafe(c).is0()}isTorsionFree(){return E.unsafeLadder(this,n).is0()}toAffine(I){let{ex:z,ey:K,ez:j}=this,X=this.is0();I==null&&(I=X?hE:t.inv(j));let Z=l(z*I),se=l(K*I),re=l(j*I);if(X)return{x:Ht,y:yt};if(re!==yt)throw new Error("invZ was invalid");return{x:Z,y:se}}clearCofactor(){let{h:I}=e;return I===yt?this:this.multiplyUnsafe(I)}static fromHex(I,z=!1){let{d:K,a:j}=e,X=t.BYTES;I=Se("pointHex",I,X);let Z=I.slice(),se=I[X-1];Z[X-1]=se&-129;let re=Yr(Z);re===Ht||(z?y(re,u):y(re,t.ORDER));let oe=l(re*re),Re=l(oe-yt),xe=l(K*oe-j),{isValid:Oe,value:Ue}=f(Re,xe);if(!Oe)throw new Error("Point.fromHex: invalid y coordinate");let Ce=(Ue&yt)===yt,$e=(se&128)!==0;if(!z&&Ue===Ht&&$e)throw new Error("Point.fromHex: x=0 and x_0=1");return $e!==Ce&&(Ue=l(-Ue)),_.fromAffine({x:Ue,y:re})}static fromPrivateKey(I){return T(I).point}toRawBytes(){let{x:I,y:z}=this.toAffine(),K=Tn(z,t.BYTES);return K[K.length-1]|=I&yt?128:0,K}toHex(){return yr(this.toRawBytes())}}_.BASE=new _(e.Gx,e.Gy,yt,l(e.Gx*e.Gy)),_.ZERO=new _(Ht,yt,yt,Ht);let{BASE:A,ZERO:v}=_,E=oa(_,a*8);function R(C){return fe(C,n)}function N(C){return R(Yr(C))}function T(C){let I=a;C=Se("private key",C,I);let z=Se("hashed private key",i(C),2*I),K=m(z.slice(0,I)),j=z.slice(I,2*I),X=N(K),Z=A.multiply(X),se=Z.toRawBytes();return{head:K,prefix:j,scalar:X,point:Z,pointBytes:se}}function H(C){return T(C).pointBytes}function D(C=new Uint8Array,...I){let z=wr(...I);return N(i(d(z,Se("context",C),!!o)))}function Q(C,I,z={}){C=Se("message",C),o&&(C=o(C));let{prefix:K,scalar:j,pointBytes:X}=T(I),Z=D(z.context,K,C),se=A.multiply(Z).toRawBytes(),re=D(z.context,se,X,C),oe=R(Z+re*j);x(oe);let Re=wr(se,Tn(oe,t.BYTES));return Se("result",Re,a*2)}let k=pE;function L(C,I,z,K=k){let{context:j,zip215:X}=K,Z=t.BYTES;C=Se("signature",C,2*Z),I=Se("message",I),o&&(I=o(I));let se=Yr(C.slice(Z,2*Z)),re,oe,Re;try{re=_.fromHex(z,X),oe=_.fromHex(C.slice(0,Z),X),Re=A.multiplyUnsafe(se)}catch{return!1}if(!X&&re.isSmallOrder())return!1;let xe=D(j,oe.toRawBytes(),re.toRawBytes(),I);return oe.add(re.multiplyUnsafe(xe)).subtract(Re).clearCofactor().equals(_.ZERO)}return A._setWindowSize(8),{CURVE:e,getPublicKey:H,sign:Q,verify:L,ExtendedPoint:_,utils:{getExtendedPublicKey:T,randomPrivateKey:()=>s(t.BYTES),precompute(C=8,I=_.BASE){return I._setWindowSize(C),I.multiply(BigInt(3)),I}}}}var Mu=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),Cp=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),Dk=BigInt(0),yE=BigInt(1),Hu=BigInt(2),gE=BigInt(5),Lp=BigInt(10),wE=BigInt(20),bE=BigInt(40),Dp=BigInt(80);function xE(r){let e=Mu,n=r*r%e*r%e,o=pe(n,Hu,e)*n%e,i=pe(o,yE,e)*r%e,s=pe(i,gE,e)*i%e,a=pe(s,Lp,e)*s%e,c=pe(a,wE,e)*a%e,u=pe(c,bE,e)*c%e,l=pe(u,Dp,e)*u%e,f=pe(l,Dp,e)*u%e,m=pe(f,Lp,e)*s%e;return{pow_p_5_8:pe(m,Hu,e)*r%e,b2:n}}function EE(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}function vE(r,e){let t=Mu,n=fe(e*e*e,t),o=fe(n*n*e,t),i=xE(r*o).pow_p_5_8,s=fe(r*n*i,t),a=fe(e*s*s,t),c=s,u=fe(s*Cp,t),l=a===r,f=a===fe(-r,t),m=a===fe(-r*Cp,t);return l&&(s=c),(f||m)&&(s=u),Bp(s,t)&&(s=fe(-s,t)),{isValid:l||f,value:s}}var br=na(Mu,void 0,!0),zu={a:BigInt(-1),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:br,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:BigInt(8),Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:Eo,randomBytes:bo,adjustScalarBytes:EE,uvRatio:vE},Ao=sa(zu);function Pp(r,e,t){if(e.length>255)throw new Error("Context is too big");return Zs(Ru("SigEd25519 no Ed25519 collisions"),new Uint8Array([t?1:0,e.length]),e,r)}var Pk=sa({...zu,domain:Pp}),Ok=sa({...zu,domain:Pp,prehash:Eo});var AE=(br.ORDER+BigInt(3))/BigInt(8),Uk=br.pow(Hu,AE),Fk=br.sqrt(br.neg(br.ONE)),Vk=(br.ORDER-BigInt(5))/BigInt(8),Hk=BigInt(486662);var Mk=Rp(br,br.neg(BigInt(486664)));var zk=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),$k=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),Kk=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),Gk=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952");var qk=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");var So=32,xr=64,aa=32;function Op(){let r=Ao.utils.randomPrivateKey(),e=Ao.getPublicKey(r);return{privateKey:Hp(r,e),publicKey:e}}function Up(r){if(r.length!==aa)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=Ao.getPublicKey(e);return{privateKey:Hp(e,t),publicKey:t}}function Fp(r,e){let t=r.subarray(0,aa);return Ao.sign(e instanceof Uint8Array?e:e.subarray(),t)}function Vp(r,e,t){return Ao.verify(e,t instanceof Uint8Array?t:t.subarray(),r)}function Hp(r,e){let t=new Uint8Array(xr);for(let n=0;n<aa;n++)t[n]=r[n],t[aa+n]=e[n];return t}var Qe={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 $u={alg:"A128GCM",ext:!0,k:"scm9jmO_4BJAgdwWGVulLg",key_ops:["encrypt","decrypt"],kty:"oct"};function Mp(r){let e=r?.algorithm??"AES-GCM",t=r?.keyLength??16,n=r?.nonceLength??12,o=r?.digest??"SHA-256",i=r?.saltLength??16,s=r?.iterations??32767,a=Qe.get();t*=8;async function c(f,m){let d=a.getRandomValues(new Uint8Array(i)),p=a.getRandomValues(new Uint8Array(n)),h={name:e,iv:p};typeof m=="string"&&(m=F(m));let g;if(m.length===0){g=await a.subtle.importKey("jwk",$u,{name:"AES-GCM"},!0,["encrypt"]);try{let x={name:"PBKDF2",salt:d,iterations:s,hash:{name:o}},b=await a.subtle.importKey("raw",m,{name:"PBKDF2"},!1,["deriveKey"]);g=await a.subtle.deriveKey(x,b,{name:e,length:t},!0,["encrypt"])}catch{g=await a.subtle.importKey("jwk",$u,{name:"AES-GCM"},!0,["encrypt"])}}else{let x={name:"PBKDF2",salt:d,iterations:s,hash:{name:o}},b=await a.subtle.importKey("raw",m,{name:"PBKDF2"},!1,["deriveKey"]);g=await a.subtle.deriveKey(x,b,{name:e,length:t},!0,["encrypt"])}let y=await a.subtle.encrypt(h,g,f);return ue([d,h.iv,new Uint8Array(y)])}async function u(f,m){let d=f.subarray(0,i),p=f.subarray(i,i+n),h=f.subarray(i+n),g={name:e,iv:p};typeof m=="string"&&(m=F(m));let y;if(m.length===0)try{let b={name:"PBKDF2",salt:d,iterations:s,hash:{name:o}},S=await a.subtle.importKey("raw",m,{name:"PBKDF2"},!1,["deriveKey"]);y=await a.subtle.deriveKey(b,S,{name:e,length:t},!0,["decrypt"])}catch{y=await a.subtle.importKey("jwk",$u,{name:"AES-GCM"},!0,["decrypt"])}else{let b={name:"PBKDF2",salt:d,iterations:s,hash:{name:o}},S=await a.subtle.importKey("raw",m,{name:"PBKDF2"},!1,["deriveKey"]);y=await a.subtle.deriveKey(b,S,{name:e,length:t},!0,["decrypt"])}let x=await a.subtle.decrypt(g,y,h);return new Uint8Array(x)}return{encrypt:c,decrypt:u}}async function _o(r,e){let n=await Mp().encrypt(r,e);return Jt.encode(n)}var me;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.Secp256k1="Secp256k1"})(me||(me={}));var Ku;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.Secp256k1=2]="Secp256k1"})(Ku||(Ku={}));(function(r){r.codec=()=>Bn(Ku)})(me||(me={}));var tr;(function(r){let e;r.codec=()=>(e==null&&(e=Bt((t,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),t.Type!=null&&(n.uint32(8),me.codec().encode(t.Type,n)),t.Data!=null&&(n.uint32(18),n.bytes(t.Data)),o.lengthDelimited!==!1&&n.ldelim()},(t,n)=>{let o={},i=n==null?t.len:t.pos+n;for(;t.pos<i;){let s=t.uint32();switch(s>>>3){case 1:o.Type=me.codec().decode(t);break;case 2:o.Data=t.bytes();break;default:t.skipType(s&7);break}}return o})),e),r.encode=t=>It(t,r.codec()),r.decode=t=>_t(t,r.codec())})(tr||(tr={}));var rr;(function(r){let e;r.codec=()=>(e==null&&(e=Bt((t,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),t.Type!=null&&(n.uint32(8),me.codec().encode(t.Type,n)),t.Data!=null&&(n.uint32(18),n.bytes(t.Data)),o.lengthDelimited!==!1&&n.ldelim()},(t,n)=>{let o={},i=n==null?t.len:t.pos+n;for(;t.pos<i;){let s=t.uint32();switch(s>>>3){case 1:o.Type=me.codec().decode(t);break;case 2:o.Data=t.bytes();break;default:t.skipType(s&7);break}}return o})),e),r.encode=t=>It(t,r.codec()),r.decode=t=>_t(t,r.codec())})(rr||(rr={}));var gi=class{_key;constructor(e){this._key=ko(e,So)}verify(e,t){return Vp(this._key,t,e)}marshal(){return this._key}get bytes(){return tr.encode({Type:me.Ed25519,Data:this.marshal()}).subarray()}equals(e){return ce(this.bytes,e.bytes)}hash(){let e=ae.digest(this.bytes);return Nt(e)?e.then(({bytes:t})=>t):e.bytes}},Cn=class{_key;_publicKey;constructor(e,t){this._key=ko(e,xr),this._publicKey=ko(t,So)}sign(e){return Fp(this._key,e)}get public(){return new gi(this._publicKey)}marshal(){return this._key}get bytes(){return rr.encode({Type:me.Ed25519,Data:this.marshal()}).subarray()}equals(e){return ce(this.bytes,e.bytes)}async hash(){let e=ae.digest(this.bytes),t;return Nt(e)?{bytes:t}=await e:t=e.bytes,t}async id(){let e=qe.digest(this.public.bytes);return ke.encode(e.bytes).substring(1)}async export(e,t="libp2p-key"){if(t==="libp2p-key")return _o(this.bytes,e);throw new P(`export format '${t}' is not supported`,"ERR_INVALID_EXPORT_FORMAT")}};function kE(r){if(r.length>xr){r=ko(r,xr+So);let n=r.subarray(0,xr),o=r.subarray(xr,r.length);return new Cn(n,o)}r=ko(r,xr);let e=r.subarray(0,xr),t=r.subarray(So);return new Cn(e,t)}function IE(r){return r=ko(r,So),new gi(r)}async function BE(){let{privateKey:r,publicKey:e}=Op();return new Cn(r,e)}async function zp(r){let{privateKey:e,publicKey:t}=Up(r);return new Cn(e,t)}function ko(r,e){if(r=Uint8Array.from(r??[]),r.length!==e)throw new P(`Key must be a Uint8Array of length ${e}, got ${r.length}`,"ERR_INVALID_KEY_TYPE");return r}var tf={};ve(tf,{MAX_RSA_KEY_SIZE:()=>Ri,RsaPrivateKey:()=>No,RsaPublicKey:()=>Bi,fromJwk:()=>t3,generateKeyPair:()=>r3,unmarshalRsaPrivateKey:()=>Qu,unmarshalRsaPublicKey:()=>e3});function Ln(r){if(isNaN(r)||r<=0)throw new P("random bytes length must be a Number bigger than 0","ERR_INVALID_LENGTH");return bo(r)}var en={};ve(en,{exportToPem:()=>YE,importFromPem:()=>XE,jwkToPkcs1:()=>GE,jwkToPkix:()=>WE,pkcs1ToJwk:()=>KE,pkixToJwk:()=>qE});var la=class extends go{constructor(e,t){super(),this.finished=!1,this.destroyed=!1,Ys(e);let n=Gr(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 o=this.blockLen,i=new Uint8Array(o);i.set(n.length>o?e.create().update(n).digest():n);for(let s=0;s<i.length;s++)i[s]^=54;this.iHash.update(i),this.oHash=e.create();for(let s=0;s<i.length;s++)i[s]^=106;this.oHash.update(i),i.fill(0)}update(e){return yo(this),this.iHash.update(e),this}digestInto(e){yo(this),mo(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:o,destroyed:i,blockLen:s,outputLen:a}=this;return e=e,e.finished=o,e.destroyed=i,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()}},wi=(r,e,t)=>new la(r,e).update(t).digest();wi.create=(r,e)=>new la(r,e);function RE(r,e,t,n){Ys(r);let o=wp({dkLen:32,asyncTick:10},n),{c:i,dkLen:s,asyncTick:a}=o;if(po(i),po(s),po(a),i<1)throw new Error("PBKDF2: iterations (c) should be >= 1");let c=Gr(e),u=Gr(t),l=new Uint8Array(s),f=wi.create(r,c),m=f._cloneInto().update(u);return{c:i,dkLen:s,asyncTick:a,DK:l,PRF:f,PRFSalt:m}}function TE(r,e,t,n,o){return r.destroy(),e.destroy(),n&&n.destroy(),o.fill(0),t}async function qu(r,e,t,n){let{c:o,dkLen:i,asyncTick:s,DK:a,PRF:c,PRFSalt:u}=RE(r,e,t,n),l,f=new Uint8Array(4),m=wo(f),d=new Uint8Array(c.outputLen);for(let p=1,h=0;h<i;p++,h+=c.outputLen){let g=a.subarray(h,h+c.outputLen);m.setInt32(0,p,!1),(l=u._cloneInto(l)).update(f).digestInto(d),g.set(d.subarray(0,g.length)),await gp(o-1,s,()=>{c._cloneInto(l).update(d).digestInto(d);for(let y=0;y<g.length;y++)g[y]^=d[y]})}return TE(c,u,a,l,d)}var te=J($p());function Dn(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 Zr(r,e,t=-1){let n=t,o=r,i=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),i=a;else{if(n<a)return new ArrayBuffer(0);c=new ArrayBuffer(n),i=n}let u=new Uint8Array(c);for(let l=a-1;l>=0;l--){let f=Math.pow(2,l*e);u[i-l-1]=Math.floor(o/f),o-=u[i-l-1]*f}return c}s*=Math.pow(2,e)}return new ArrayBuffer(0)}function da(...r){let e=0,t=0;for(let i of r)e+=i.length;let n=new ArrayBuffer(e),o=new Uint8Array(n);for(let i of r)o.set(i,t),t+=i.length;return o}function ju(){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=Dn(t,8),o=new ArrayBuffer(this.valueHex.byteLength),i=new Uint8Array(o);for(let a=0;a<this.valueHex.byteLength;a++)i[a]=r[a];return i[0]&=127,Dn(i,8)-n}function Kp(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=Zr(s,8,n),c=new Uint8Array(a);return c[0]|=128,a}let o=Zr(e,8,n),i=new Uint8Array(o);if(i[0]&128){let s=o.slice(0),a=new Uint8Array(s);o=new ArrayBuffer(o.byteLength+1),i=new Uint8Array(o);for(let c=0;c<s.byteLength;c++)i[c+1]=a[c];i[0]=0}return o}t*=Math.pow(2,8)}return new ArrayBuffer(0)}function Gp(r,e){if(r.byteLength!==e.byteLength)return!1;let t=new Uint8Array(r),n=new Uint8Array(e);for(let o=0;o<t.length;o++)if(t[o]!==n[o])return!1;return!0}function ct(r,e){let t=r.toString(10);if(e<t.length)return"";let n=e-t.length,o=new Array(n);for(let s=0;s<n;s++)o[s]="0";return o.join("").concat(t)}var xI=Math.log(2);function ha(){if(typeof BigInt>"u")throw new Error("BigInt is not defined. Your environment doesn't implement BigInt.")}function Yu(r){let e=0,t=0;for(let o=0;o<r.length;o++){let i=r[o];e+=i.byteLength}let n=new Uint8Array(e);for(let o=0;o<r.length;o++){let i=r[o];n.set(new Uint8Array(i),t),t+=i.byteLength}return n.buffer}function _r(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 xi=class{constructor(){this.items=[]}write(e){this.items.push(e)}final(){return Yu(this.items)}},bi=[new Uint8Array([1])],qp="0123456789";var Ro="",zt=new ArrayBuffer(0),Xu=new Uint8Array(0),Ei="EndOfContent",jp="OCTET STRING",Yp="BIT STRING";function kr(r){var e;return e=class extends r{constructor(...n){var o;super(...n);let i=n[0]||{};this.isHexOnly=(o=i.isHexOnly)!==null&&o!==void 0?o:!1,this.valueHexView=i.valueHex?te.BufferSourceConverter.toUint8Array(i.valueHex):Xu}get valueHex(){return this.valueHexView.slice().buffer}set valueHex(n){this.valueHexView=new Uint8Array(n)}fromBER(n,o,i){let s=n instanceof ArrayBuffer?new Uint8Array(n):n;if(!_r(this,s,o,i))return-1;let a=o+i;return this.valueHexView=s.subarray(o,a),this.valueHexView.length?(this.blockLength=i,a):(this.warnings.push("Zero buffer length"),o)}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",zt)}toJSON(){return{...super.toJSON(),isHexOnly:this.isHexOnly,valueHex:te.Convert.ToHex(this.valueHexView)}}},e.NAME="hexBlock",e}var vr=class{constructor({blockLength:e=0,error:t=Ro,warnings:n=[],valueBeforeDecode:o=Xu}={}){this.blockLength=e,this.error=t,this.warnings=n,this.valueBeforeDecodeView=te.BufferSourceConverter.toUint8Array(o)}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:te.Convert.ToHex(this.valueBeforeDecodeView)}}};vr.NAME="baseBlock";var je=class extends vr{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'")}};je.NAME="valueBlock";var pa=class extends kr(vr){constructor({idBlock:e={}}={}){var t,n,o,i;super(),e?(this.isHexOnly=(t=e.isHexOnly)!==null&&t!==void 0?t:!1,this.valueHexView=e.valueHex?te.BufferSourceConverter.toUint8Array(e.valueHex):Xu,this.tagClass=(n=e.tagClass)!==null&&n!==void 0?n:-1,this.tagNumber=(o=e.tagNumber)!==null&&o!==void 0?o:-1,this.isConstructed=(i=e.isConstructed)!==null&&i!==void 0?i:!1):(this.tagClass=-1,this.tagNumber=-1,this.isConstructed=!1)}toBER(e=!1){let 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",zt}if(this.isConstructed&&(t|=32),this.tagNumber<31&&!this.isHexOnly){let o=new Uint8Array(1);if(!e){let i=this.tagNumber;i&=31,t|=i,o[0]=t}return o.buffer}if(!this.isHexOnly){let o=Zr(this.tagNumber,7),i=new Uint8Array(o),s=o.byteLength,a=new Uint8Array(s+1);if(a[0]=t|31,!e){for(let c=0;c<s-1;c++)a[c+1]=i[c]|128;a[s]=i[s-1]}return a.buffer}let n=new Uint8Array(this.valueHexView.byteLength+1);if(n[0]=t|31,!e){let o=this.valueHexView;for(let i=0;i<o.length-1;i++)n[i+1]=o[i]|128;n[this.valueHexView.byteLength]=o[o.length-1]}return n.buffer}fromBER(e,t,n){let o=te.BufferSourceConverter.toUint8Array(e);if(!_r(this,o,t,n))return-1;let i=o.subarray(t,t+n);if(i.length===0)return this.error="Zero buffer length",-1;switch(i[0]&192){case 0:this.tagClass=1;break;case 64:this.tagClass=2;break;case 128:this.tagClass=3;break;case 192:this.tagClass=4;break;default:return this.error="Unknown tag class",-1}this.isConstructed=(i[0]&32)===32,this.isHexOnly=!1;let a=i[0]&31;if(a!==31)this.tagNumber=a,this.blockLength=1;else{let c=1,u=this.valueHexView=new Uint8Array(255),l=255;for(;i[c]&128;){if(u[c-1]=i[c]&127,c++,c>=i.length)return this.error="End of input reached before message was fully decoded",-1;if(c===l){l+=255;let m=new Uint8Array(l);for(let d=0;d<u.length;d++)m[d]=u[d];u=this.valueHexView=new Uint8Array(l)}}this.blockLength=c+1,u[c-1]=i[c]&127;let f=new Uint8Array(c);for(let m=0;m<c;m++)f[m]=u[m];u=this.valueHexView=new Uint8Array(c),u.set(f),this.blockLength<=9?this.tagNumber=Dn(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}}};pa.NAME="identificationBlock";var ma=class extends vr{constructor({lenBlock:e={}}={}){var t,n,o;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=(o=e.length)!==null&&o!==void 0?o:0}fromBER(e,t,n){let o=te.BufferSourceConverter.toUint8Array(e);if(!_r(this,o,t,n))return-1;let i=o.subarray(t,t+n);if(i.length===0)return this.error="Zero buffer length",-1;if(i[0]===255)return this.error="Length block 0xFF is reserved by standard",-1;if(this.isIndefiniteForm=i[0]===128,this.isIndefiniteForm)return this.blockLength=1,t+this.blockLength;if(this.longFormUsed=!!(i[0]&128),this.longFormUsed===!1)return this.length=i[0],this.blockLength=1,t+this.blockLength;let s=i[0]&127;if(s>8)return this.error="Too big integer",-1;if(s+1>i.length)return this.error="End of input reached before message was fully decoded",-1;let a=t+1,c=o.subarray(a,a+s);return c[s-1]===0&&this.warnings.push("Needlessly long encoded length"),this.length=Dn(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 o=Zr(this.length,8);if(o.byteLength>127)return this.error="Too big length",zt;if(t=new ArrayBuffer(o.byteLength+1),e)return t;let i=new Uint8Array(o);n=new Uint8Array(t),n[0]=o.byteLength|128;for(let s=0;s<o.byteLength;s++)n[s+1]=i[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}}};ma.NAME="lengthBlock";var M={},Ve=class extends vr{constructor({name:e=Ro,optional:t=!1,primitiveSchema:n,...o}={},i){super(o),this.name=e,this.optional=t,n&&(this.primitiveSchema=n),this.idBlock=new pa(o),this.lenBlock=new ma(o),this.valueBlock=i?new i(o):new je(o)}fromBER(e,t,n){let o=this.valueBlock.fromBER(e,t,this.lenBlock.isIndefiniteForm?n:this.lenBlock.length);return o===-1?(this.error=this.valueBlock.error,o):(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),o)}toBER(e,t){let n=t||new xi;t||Xp(this);let o=this.idBlock.toBER(e);if(n.write(o),this.lenBlock.isIndefiniteForm)n.write(new Uint8Array([128]).buffer),this.valueBlock.toBER(e,n),n.write(new ArrayBuffer(2));else{let i=this.valueBlock.toBER(e);this.lenBlock.length=i.byteLength;let s=this.lenBlock.toBER(e);n.write(s),n.write(i)}return t?zt: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():te.Convert.ToHex(this.toBER())}onAsciiEncoding(){return`${this.constructor.NAME} : ${te.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 Gp(t,n)}};Ve.NAME="BaseBlock";function Xp(r){if(r instanceof M.Constructed)for(let e of r.valueBlock.value)Xp(e)&&(r.lenBlock.isIndefiniteForm=!0);return!!r.lenBlock.isIndefiniteForm}var ya=class extends Ve{constructor({value:e=Ro,...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 o=this.valueBlock.fromBER(e,t,this.lenBlock.isIndefiniteForm?n:this.lenBlock.length);return o===-1?(this.error=this.valueBlock.error,o):(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),o)}onAsciiEncoding(){return`${this.constructor.NAME} : '${this.valueBlock.value}'`}};ya.NAME="BaseStringBlock";var ga=class extends kr(je){constructor({isHexOnly:e=!0,...t}={}){super(t),this.isHexOnly=e}};ga.NAME="PrimitiveValueBlock";var Zp,wa=class extends Ve{constructor(e={}){super(e,ga),this.idBlock.isConstructed=!1}};Zp=wa;M.Primitive=Zp;wa.NAME="PRIMITIVE";function VE(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 Za(r,e=0,t=r.length){let n=e,o=new Ve({},je),i=new vr;if(!_r(i,r,e,t))return o.error=i.error,{offset:-1,result:o};if(!r.subarray(e,e+t).length)return o.error="Zero buffer length",{offset:-1,result:o};let a=o.idBlock.fromBER(r,e,t);if(o.idBlock.warnings.length&&o.warnings.concat(o.idBlock.warnings),a===-1)return o.error=o.idBlock.error,{offset:-1,result:o};if(e=a,t-=o.idBlock.blockLength,a=o.lenBlock.fromBER(r,e,t),o.lenBlock.warnings.length&&o.warnings.concat(o.lenBlock.warnings),a===-1)return o.error=o.lenBlock.error,{offset:-1,result:o};if(e=a,t-=o.lenBlock.blockLength,!o.idBlock.isConstructed&&o.lenBlock.isIndefiniteForm)return o.error="Indefinite length form used for primitive encoding form",{offset:-1,result:o};let c=Ve;switch(o.idBlock.tagClass){case 1:if(o.idBlock.tagNumber>=37&&o.idBlock.isHexOnly===!1)return o.error="UNIVERSAL 37 and upper tags are reserved by ASN.1 standard",{offset:-1,result:o};switch(o.idBlock.tagNumber){case 0:if(o.idBlock.isConstructed&&o.lenBlock.length>0)return o.error="Type [UNIVERSAL 0] is reserved",{offset:-1,result:o};c=M.EndOfContent;break;case 1:c=M.Boolean;break;case 2:c=M.Integer;break;case 3:c=M.BitString;break;case 4:c=M.OctetString;break;case 5:c=M.Null;break;case 6:c=M.ObjectIdentifier;break;case 10:c=M.Enumerated;break;case 12:c=M.Utf8String;break;case 13:c=M.RelativeObjectIdentifier;break;case 14:c=M.TIME;break;case 15:return o.error="[UNIVERSAL 15] is reserved by ASN.1 standard",{offset:-1,result:o};case 16:c=M.Sequence;break;case 17:c=M.Set;break;case 18:c=M.NumericString;break;case 19:c=M.PrintableString;break;case 20:c=M.TeletexString;break;case 21:c=M.VideotexString;break;case 22:c=M.IA5String;break;case 23:c=M.UTCTime;break;case 24:c=M.GeneralizedTime;break;case 25:c=M.GraphicString;break;case 26:c=M.VisibleString;break;case 27:c=M.GeneralString;break;case 28:c=M.UniversalString;break;case 29:c=M.CharacterString;break;case 30:c=M.BmpString;break;case 31:c=M.DATE;break;case 32:c=M.TimeOfDay;break;case 33:c=M.DateTime;break;case 34:c=M.Duration;break;default:{let u=o.idBlock.isConstructed?new M.Constructed:new M.Primitive;u.idBlock=o.idBlock,u.lenBlock=o.lenBlock,u.warnings=o.warnings,o=u}}break;case 2:case 3:case 4:default:c=o.idBlock.isConstructed?M.Constructed:M.Primitive}return o=VE(o,c),a=o.fromBER(r,e,o.lenBlock.isIndefiniteForm?t:o.lenBlock.length),o.valueBeforeDecodeView=r.subarray(n,n+o.blockLength),{offset:a,result:o}}function To(r){if(!r.byteLength){let e=new Ve({},je);return e.error="Input buffer has zero length",{offset:-1,result:e}}return Za(te.BufferSourceConverter.toUint8Array(r).slice(),0,r.byteLength)}function HE(r,e){return r?1:e}var nr=class extends je{constructor({value:e=[],isIndefiniteForm:t=!1,...n}={}){super(n),this.value=e,this.isIndefiniteForm=t}fromBER(e,t,n){let o=te.BufferSourceConverter.toUint8Array(e);if(!_r(this,o,t,n))return-1;if(this.valueBeforeDecodeView=o.subarray(t,t+n),this.valueBeforeDecodeView.length===0)return this.warnings.push("Zero buffer length"),t;let i=t;for(;HE(this.isIndefiniteForm,n)>0;){let s=Za(o,i,n);if(s.offset===-1)return this.error=s.result.error,this.warnings.concat(s.result.warnings),-1;if(i=s.offset,this.blockLength+=s.result.blockLength,n-=s.result.blockLength,this.value.push(s.result),this.isIndefiniteForm&&s.result.constructor.NAME===Ei)break}return this.isIndefiniteForm&&(this.value[this.value.length-1].constructor.NAME===Ei?this.value.pop():this.warnings.push("No EndOfContent block encoded")),i}toBER(e,t){let n=t||new xi;for(let o=0;o<this.value.length;o++)this.value[o].toBER(e,n);return t?zt:n.final()}toJSON(){let e={...super.toJSON(),isIndefiniteForm:this.isIndefiniteForm,value:[]};for(let t of this.value)e.value.push(t.toJSON());return e}};nr.NAME="ConstructedValueBlock";var Jp,Jr=class extends Ve{constructor(e={}){super(e,nr),this.idBlock.isConstructed=!0}fromBER(e,t,n){this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm;let o=this.valueBlock.fromBER(e,t,this.lenBlock.isIndefiniteForm?n:this.lenBlock.length);return o===-1?(this.error=this.valueBlock.error,o):(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),o)}onAsciiEncoding(){let e=[];for(let n of this.valueBlock.value)e.push(n.toString("ascii").split(`
2
+ "use strict";var HeliaVerifiedFetch=(()=>{var qw=Object.create;var Ts=Object.defineProperty;var Gw=Object.getOwnPropertyDescriptor;var Ww=Object.getOwnPropertyNames;var jw=Object.getPrototypeOf,Yw=Object.prototype.hasOwnProperty;var Ee=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),ve=(r,e)=>{for(var t in e)Ts(r,t,{get:e[t],enumerable:!0})},eh=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Ww(e))!Yw.call(r,o)&&o!==t&&Ts(r,o,{get:()=>e[o],enumerable:!(n=Gw(e,o))||n.enumerable});return r};var J=(r,e,t)=>(t=r!=null?qw(jw(r)):{},eh(e||!r||!r.__esModule?Ts(t,"default",{value:r,enumerable:!0}):t,r)),Xw=r=>eh(Ts({},"__esModule",{value:!0}),r);var wh=Ee((UA,gh)=>{var oo=1e3,io=oo*60,so=io*60,An=so*24,Hb=An*7,Mb=An*365.25;gh.exports=function(r,e){e=e||{};var t=typeof r;if(t==="string"&&r.length>0)return zb(r);if(t==="number"&&isFinite(r))return e.long?Kb(r):$b(r);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(r))};function zb(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*Mb;case"weeks":case"week":case"w":return t*Hb;case"days":case"day":case"d":return t*An;case"hours":case"hour":case"hrs":case"hr":case"h":return t*so;case"minutes":case"minute":case"mins":case"min":case"m":return t*io;case"seconds":case"second":case"secs":case"sec":case"s":return t*oo;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return t;default:return}}}}function $b(r){var e=Math.abs(r);return e>=An?Math.round(r/An)+"d":e>=so?Math.round(r/so)+"h":e>=io?Math.round(r/io)+"m":e>=oo?Math.round(r/oo)+"s":r+"ms"}function Kb(r){var e=Math.abs(r);return e>=An?Ls(r,e,An,"day"):e>=so?Ls(r,e,so,"hour"):e>=io?Ls(r,e,io,"minute"):e>=oo?Ls(r,e,oo,"second"):r+" ms"}function Ls(r,e,t,n){var o=e>=t*1.5;return Math.round(r/t)+" "+n+(o?"s":"")}});var xh=Ee((FA,bh)=>{function qb(r){t.debug=t,t.default=t,t.coerce=c,t.disable=i,t.enable=o,t.enabled=s,t.humanize=wh(),t.destroy=u,Object.keys(r).forEach(l=>{t[l]=r[l]}),t.names=[],t.skips=[],t.formatters={};function e(l){let f=0;for(let m=0;m<l.length;m++)f=(f<<5)-f+l.charCodeAt(m),f|=0;return t.colors[Math.abs(f)%t.colors.length]}t.selectColor=e;function t(l){let f,m=null,d,p;function h(...y){if(!h.enabled)return;let g=h,x=Number(new Date),b=x-(f||x);g.diff=b,g.prev=f,g.curr=x,f=x,y[0]=t.coerce(y[0]),typeof y[0]!="string"&&y.unshift("%O");let _=0;y[0]=y[0].replace(/%([a-zA-Z%])/g,(S,v)=>{if(S==="%%")return"%";_++;let E=t.formatters[v];if(typeof E=="function"){let R=y[_];S=E.call(g,R),y.splice(_,1),_--}return S}),t.formatArgs.call(g,y),(g.log||t.log).apply(g,y)}return h.namespace=l,h.useColors=t.useColors(),h.color=t.selectColor(l),h.extend=n,h.destroy=t.destroy,Object.defineProperty(h,"enabled",{enumerable:!0,configurable:!1,get:()=>m!==null?m:(d!==t.namespaces&&(d=t.namespaces,p=t.enabled(l)),p),set:y=>{m=y}}),typeof t.init=="function"&&t.init(h),h}function n(l,f){let m=t(this.namespace+(typeof f>"u"?":":f)+l);return m.log=this.log,m}function o(l){t.save(l),t.namespaces=l,t.names=[],t.skips=[];let f,m=(typeof l=="string"?l:"").split(/[\s,]+/),d=m.length;for(f=0;f<d;f++)m[f]&&(l=m[f].replace(/\*/g,".*?"),l[0]==="-"?t.skips.push(new RegExp("^"+l.slice(1)+"$")):t.names.push(new RegExp("^"+l+"$")))}function i(){let l=[...t.names.map(a),...t.skips.map(a).map(f=>"-"+f)].join(",");return t.enable(""),l}function s(l){if(l[l.length-1]==="*")return!0;let f,m;for(f=0,m=t.skips.length;f<m;f++)if(t.skips[f].test(l))return!1;for(f=0,m=t.names.length;f<m;f++)if(t.names[f].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}bh.exports=qb});var Eh=Ee((ht,Ds)=>{ht.formatArgs=Wb;ht.save=jb;ht.load=Yb;ht.useColors=Gb;ht.storage=Xb();ht.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`."))}})();ht.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 Gb(){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 Wb(r){if(r[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+r[0]+(this.useColors?"%c ":" ")+"+"+Ds.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,o=>{o!=="%%"&&(t++,o==="%c"&&(n=t))}),r.splice(n,0,e)}ht.log=console.debug||console.log||(()=>{});function jb(r){try{r?ht.storage.setItem("debug",r):ht.storage.removeItem("debug")}catch{}}function Yb(){let r;try{r=ht.storage.getItem("debug")}catch{}return!r&&typeof process<"u"&&"env"in process&&(r=process.env.DEBUG),r}function Xb(){try{return localStorage}catch{}}Ds.exports=xh()(ht);var{formatters:Zb}=Ds.exports;Zb.j=function(r){try{return JSON.stringify(r)}catch(e){return"[UnexpectedJSONParseError]: "+e.message}}});var Ah=Ee((qA,_h)=>{_h.exports=zl;var Sh=128,r2=127,n2=~r2,o2=Math.pow(2,31);function zl(r,e,t){if(Number.MAX_SAFE_INTEGER&&r>Number.MAX_SAFE_INTEGER)throw zl.bytes=0,new RangeError("Could not encode varint");e=e||[],t=t||0;for(var n=t;r>=o2;)e[t++]=r&255|Sh,r/=128;for(;r&n2;)e[t++]=r&255|Sh,r>>>=7;return e[t]=r|0,zl.bytes=t-n+1,e}});var Bh=Ee((GA,Ih)=>{Ih.exports=$l;var i2=128,kh=127;function $l(r,n){var t=0,n=n||0,o=0,i=n,s,a=r.length;do{if(i>=a||o>49)throw $l.bytes=0,new RangeError("Could not decode varint");s=r[i++],t+=o<28?(s&kh)<<o:(s&kh)*Math.pow(2,o),o+=7}while(s>=i2);return $l.bytes=i-n,t}});var Th=Ee((WA,Rh)=>{var s2=Math.pow(2,7),a2=Math.pow(2,14),c2=Math.pow(2,21),l2=Math.pow(2,28),u2=Math.pow(2,35),f2=Math.pow(2,42),d2=Math.pow(2,49),h2=Math.pow(2,56),p2=Math.pow(2,63);Rh.exports=function(r){return r<s2?1:r<a2?2:r<c2?3:r<l2?4:r<u2?5:r<f2?6:r<d2?7:r<h2?8:r<p2?9:10}});var Ps=Ee((jA,Nh)=>{Nh.exports={encode:Ah(),decode:Bh(),encodingLength:Th()}});var Ie=Ee((f5,Xh)=>{"use strict";function Yh(r,e){for(let t in e)Object.defineProperty(r,t,{value:e[t],enumerable:!0,configurable:!0});return r}function Y2(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 Yh(r,t)}catch{t.message=r.message,t.stack=r.stack;let o=function(){};return o.prototype=Object.create(Object.getPrototypeOf(r)),Yh(new o,t)}}Xh.exports=Y2});var Wp=Ee(Ro=>{"use strict";var VE="[object ArrayBuffer]",Er=class r{static isArrayBuffer(e){return Object.prototype.toString.call(e)===VE}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),o=r.toUint8Array(t);if(n.length!==o.byteLength)return!1;for(let i=0;i<n.length;i++)if(n[i]!==o[i])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 o=new Uint8Array(n),i=0;for(let s of t){let a=this.toUint8Array(s);o.set(a,i),i+=a.length}return e[e.length-1]instanceof Function?this.toView(o,e[e.length-1]):o.buffer}},Xu="string",HE=/^[0-9a-f]+$/i,ME=/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/,zE=/^[a-zA-Z0-9-_]+$/,fa=class{static fromString(e){let t=unescape(encodeURIComponent(e)),n=new Uint8Array(t.length);for(let o=0;o<t.length;o++)n[o]=t.charCodeAt(o);return n.buffer}static toString(e){let t=Er.toUint8Array(e),n="";for(let i=0;i<t.length;i++)n+=String.fromCharCode(t[i]);return decodeURIComponent(escape(n))}},Ct=class{static toString(e,t=!1){let n=Er.toArrayBuffer(e),o=new DataView(n),i="";for(let s=0;s<n.byteLength;s+=2){let a=o.getUint16(s,t);i+=String.fromCharCode(a)}return i}static fromString(e,t=!1){let n=new ArrayBuffer(e.length*2),o=new DataView(n);for(let i=0;i<e.length;i++)o.setUint16(i*2,e.charCodeAt(i),t);return n}},da=class r{static isHex(e){return typeof e===Xu&&HE.test(e)}static isBase64(e){return typeof e===Xu&&ME.test(e)}static isBase64Url(e){return typeof e===Xu&&zE.test(e)}static ToString(e,t="utf8"){let n=Er.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 Ct.toString(n,!0);case"utf16":case"utf16be":return Ct.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 Ct.fromString(e,!0);case"utf16":case"utf16be":return Ct.fromString(e);default:throw new Error(`Unknown type of encoding '${t}'`)}}static ToBase64(e){let t=Er.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 fa.fromString(e);case"utf16":case"utf16be":return Ct.fromString(e);case"utf16le":case"usc2":return Ct.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 fa.toString(e);case"utf16":case"utf16be":return Ct.toString(e);case"utf16le":case"usc2":return Ct.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 o=0;o<t;o++)n[o]=e.charCodeAt(o);return n.buffer}static ToBinary(e){let t=Er.toUint8Array(e),n="";for(let o=0;o<t.length;o++)n+=String.fromCharCode(t[o]);return n}static ToHex(e){let t=Er.toUint8Array(e),n="",o=t.length;for(let i=0;i<o;i++){let s=t[i];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 o=0;o<t.length;o=o+2){let i=t.slice(o,o+2);n[o/2]=parseInt(i,16)}return n.buffer}static ToUtf16String(e,t=!1){return Ct.toString(e,t)}static FromUtf16String(e,t=!1){return Ct.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,"")||""}};da.DEFAULT_UTF8_ENCODING="utf8";function $E(r,...e){let t=arguments[0];for(let n=1;n<arguments.length;n++){let o=arguments[n];for(let i in o)t[i]=o[i]}return t}function KE(...r){let e=r.map(o=>o.byteLength).reduce((o,i)=>o+i),t=new Uint8Array(e),n=0;return r.map(o=>new Uint8Array(o)).forEach(o=>{for(let i of o)t[n++]=i}),t.buffer}function qE(r,e){if(!(r&&e)||r.byteLength!==e.byteLength)return!1;let t=new Uint8Array(r),n=new Uint8Array(e);for(let o=0;o<r.byteLength;o++)if(t[o]!==n[o])return!1;return!0}Ro.BufferSourceConverter=Er;Ro.Convert=da;Ro.assign=$E;Ro.combine=KE;Ro.isEqual=qE});var tc=Ee((TB,df)=>{var RB=function(){typeof df<"u"&&(df.exports=h);var r=86400,e=3200,t=146097*e/400,n=r*t,o=1e3*n,i=864e13,s=4294967296,a=1e6,c="000000000",u=Math.trunc||function(E){var R=E-E%1;return R==0&&(E<0||E===0&&1/E!=1/0)?-0:R},l=h.prototype,f=(h.fromDate=function(E){return new h(+E)},h.fromInt64BE=_(0,1,2,3,0,4),h.fromInt64LE=_(3,2,1,0,4,0),h.fromString=function(T){var R,N=new h,T=(T+="").replace(/^\s*[+\-]?\d+/,function(D){var D=+D,Q=1970+(D-1970)%400;return N.year=D-Q,Q}).replace(/(?:Z|([+\-]\d{2}):?(\d{2}))$/,function(H,D,Q){return D<0&&(Q*=-1),R=6e4*(60*+D+ +Q),""}).replace(/\.\d+$/,function(H){return N.nano=+(H+c).substr(1,9),""}).split(/\D+/);if(1<T.length?T[1]--:T[1]=0,N.time=R=Date.UTC.apply(Date,T)-(R||0),isNaN(R))throw new TypeError("Invalid Date");return y(N)},h.fromTimeT=function(E){return x(E,0)},l.year=0,l.time=0,l.nano=0,l.addNano=function(E){return this.nano+=+E||0,this},l.getNano=function(){var E=y(this);return(E.time%1e3*a+ +E.nano+1e9)%1e9},l.getTimeT=function(){var R=y(this),E=Math.floor(R.time/1e3),R=R.year;return R&&(E+=R*t*r/e),E},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(E){var R=this,N=R.toDate(),T={H:function(){return S(N.getUTCHours())},L:function(){return v(N.getUTCMilliseconds(),3)},M:function(){return S(N.getUTCMinutes())},N:function(){return v(R.getNano(),9)},S:function(){return S(N.getUTCSeconds())},Y:function(){var H=R.getYear();return 999999<H?"+"+H:9999<H?"+"+v(H,6):0<=H?v(H,4):-999999<=H?"-"+v(-H,6):H},a:function(){return d[N.getUTCDay()]},b:function(){return m[N.getUTCMonth()]},d:function(){return S(N.getUTCDate())},e:function(){return function(H){return(9<H?"":" ")+(0|H)}(N.getUTCDate())},m:function(){return S(N.getUTCMonth()+1)}};return function H(D){return D.replace(/%./g,function(Q){var L=Q[1],k=p[L],L=T[L];return k?H(k):L?L():Q})}(E||f)},l.writeInt64BE=b(0,1,2,3,0,4),l.writeInt64LE=b(3,2,1,0,4,0),"%Y-%m-%dT%H:%M:%S.%NZ"),m=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],d=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],p={"%":"%",F:"%Y-%m-%d",n:`
3
+ `,R:"%H:%M",T:"%H:%M:%S",t:" ",X:"%T",Z:"GMT",z:"+0000"};return h;function h(E,R,N){var T=this;if(!(T instanceof h))return new h(E,R,N);T.time=+E||0,T.nano=+R||0,T.year=+N||0,y(T)}function y(E){var R,N,T,H=E.year,D=E.time,Q=E.nano,k=((Q<0||a<=Q)&&(Q-=(N=Math.floor(Q/a))*a,D+=N,N=1),H%e);return(D<-i||i<D||k)&&((R=u(D/o))&&(H+=R*e,D-=R*o),(T=g(D)).setUTCFullYear(k+T.getUTCFullYear()),T=(D=+T)+(R=u((H-=k)/e))*o,R&&-i<=T&&T<=i&&(H-=R*e,D=T),N=1),N&&(E.year=H,E.time=D,E.nano=Q),E}function g(E){var R=new Date(0);return R.setTime(E),R}function x(H,T){H=+H||0;var N=u((T=(T|0)*s)/n)+u(H/n),T=T%n+H%n,H=u(T/n);return H&&(N+=H,T-=H*n),new h(1e3*T,0,N*e)}function b(E,R,N,T,H,D){return function(k,L){var C=y(this);k=k||new Array(8),A(k,L|=0);var I=Math.floor(C.time/1e3),C=C.year*(t*r/e),G=u(C/s)+u(I/s),C=C%s+I%s,I=Math.floor(C/s);return I&&(G+=I,C-=I*s),Q(k,L+H,G),Q(k,L+D,C),k};function Q(k,L,G){k[L+E]=G>>24&255,k[L+R]=G>>16&255,k[L+N]=G>>8&255,k[L+T]=255&G}}function _(E,R,N,T,H,D){return function(k,L){A(k,L|=0);var G=Q(k,L+H);return x(Q(k,L+D),G)};function Q(k,L){return 16777216*k[L+E]+(k[L+R]<<16|k[L+N]<<8|k[L+T])}}function A(E,R){if(E=E&&E.length,E==null)throw new TypeError("Invalid Buffer");if(E<R+8)throw new RangeError("Out of range")}function S(E){return(9<E?"":"0")+(0|E)}function v(E,R){return(c+(0|E)).substr(-R)}}()});var E1=Ee((hT,If)=>{"use strict";var c6=Object.prototype.hasOwnProperty,nt="~";function Ki(){}Object.create&&(Ki.prototype=Object.create(null),new Ki().__proto__||(nt=!1));function l6(r,e,t){this.fn=r,this.context=e,this.once=t||!1}function x1(r,e,t,n,o){if(typeof t!="function")throw new TypeError("The listener must be a function");var i=new l6(t,n||r,o),s=nt?nt+e:e;return r._events[s]?r._events[s].fn?r._events[s]=[r._events[s],i]:r._events[s].push(i):(r._events[s]=i,r._eventsCount++),r}function wc(r,e){--r._eventsCount===0?r._events=new Ki:delete r._events[e]}function Ye(){this._events=new Ki,this._eventsCount=0}Ye.prototype.eventNames=function(){var e=[],t,n;if(this._eventsCount===0)return e;for(n in t=this._events)c6.call(t,n)&&e.push(nt?n.slice(1):n);return Object.getOwnPropertySymbols?e.concat(Object.getOwnPropertySymbols(t)):e};Ye.prototype.listeners=function(e){var t=nt?nt+e:e,n=this._events[t];if(!n)return[];if(n.fn)return[n.fn];for(var o=0,i=n.length,s=new Array(i);o<i;o++)s[o]=n[o].fn;return s};Ye.prototype.listenerCount=function(e){var t=nt?nt+e:e,n=this._events[t];return n?n.fn?1:n.length:0};Ye.prototype.emit=function(e,t,n,o,i,s){var a=nt?nt+e:e;if(!this._events[a])return!1;var c=this._events[a],u=arguments.length,l,f;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,o),!0;case 5:return c.fn.call(c.context,t,n,o,i),!0;case 6:return c.fn.call(c.context,t,n,o,i,s),!0}for(f=1,l=new Array(u-1);f<u;f++)l[f-1]=arguments[f];c.fn.apply(c.context,l)}else{var m=c.length,d;for(f=0;f<m;f++)switch(c[f].once&&this.removeListener(e,c[f].fn,void 0,!0),u){case 1:c[f].fn.call(c[f].context);break;case 2:c[f].fn.call(c[f].context,t);break;case 3:c[f].fn.call(c[f].context,t,n);break;case 4:c[f].fn.call(c[f].context,t,n,o);break;default:if(!l)for(d=1,l=new Array(u-1);d<u;d++)l[d-1]=arguments[d];c[f].fn.apply(c[f].context,l)}}return!0};Ye.prototype.on=function(e,t,n){return x1(this,e,t,n,!1)};Ye.prototype.once=function(e,t,n){return x1(this,e,t,n,!0)};Ye.prototype.removeListener=function(e,t,n,o){var i=nt?nt+e:e;if(!this._events[i])return this;if(!t)return wc(this,i),this;var s=this._events[i];if(s.fn)s.fn===t&&(!o||s.once)&&(!n||s.context===n)&&wc(this,i);else{for(var a=0,c=[],u=s.length;a<u;a++)(s[a].fn!==t||o&&!s[a].once||n&&s[a].context!==n)&&c.push(s[a]);c.length?this._events[i]=c.length===1?c[0]:c:wc(this,i)}return this};Ye.prototype.removeAllListeners=function(e){var t;return e?(t=nt?nt+e:e,this._events[t]&&wc(this,t)):(this._events=new Ki,this._eventsCount=0),this};Ye.prototype.off=Ye.prototype.removeListener;Ye.prototype.addListener=Ye.prototype.on;Ye.prefixed=nt;Ye.EventEmitter=Ye;typeof If<"u"&&(If.exports=Ye)});var Pf=Ee((mN,N1)=>{N1.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 o(i,s){t[i]=s,e++,e>=r&&(e=0,n=t,t=Object.create(null))}return{has:function(i){return t[i]!==void 0||n[i]!==void 0},remove:function(i){t[i]!==void 0&&(t[i]=void 0),n[i]!==void 0&&(n[i]=void 0)},get:function(i){var s=t[i];if(s!==void 0)return s;if((s=n[i])!==void 0)return o(i,s),s},set:function(i,s){t[i]!==void 0?t[i]=s:o(i,s)},clear:function(){t=Object.create(null),n=Object.create(null)}}}});var My=Ee((gs,Wc)=>{(function(r,e){"use strict";var t={version:"3.0.0",x86:{},x64:{},inputValidation:!0};function n(d){if(!Array.isArray(d)&&!ArrayBuffer.isView(d))return!1;for(var p=0;p<d.length;p++)if(!Number.isInteger(d[p])||d[p]<0||d[p]>255)return!1;return!0}function o(d,p){return(d&65535)*p+(((d>>>16)*p&65535)<<16)}function i(d,p){return d<<p|d>>>32-p}function s(d){return d^=d>>>16,d=o(d,2246822507),d^=d>>>13,d=o(d,3266489909),d^=d>>>16,d}function a(d,p){d=[d[0]>>>16,d[0]&65535,d[1]>>>16,d[1]&65535],p=[p[0]>>>16,p[0]&65535,p[1]>>>16,p[1]&65535];var h=[0,0,0,0];return h[3]+=d[3]+p[3],h[2]+=h[3]>>>16,h[3]&=65535,h[2]+=d[2]+p[2],h[1]+=h[2]>>>16,h[2]&=65535,h[1]+=d[1]+p[1],h[0]+=h[1]>>>16,h[1]&=65535,h[0]+=d[0]+p[0],h[0]&=65535,[h[0]<<16|h[1],h[2]<<16|h[3]]}function c(d,p){d=[d[0]>>>16,d[0]&65535,d[1]>>>16,d[1]&65535],p=[p[0]>>>16,p[0]&65535,p[1]>>>16,p[1]&65535];var h=[0,0,0,0];return h[3]+=d[3]*p[3],h[2]+=h[3]>>>16,h[3]&=65535,h[2]+=d[2]*p[3],h[1]+=h[2]>>>16,h[2]&=65535,h[2]+=d[3]*p[2],h[1]+=h[2]>>>16,h[2]&=65535,h[1]+=d[1]*p[3],h[0]+=h[1]>>>16,h[1]&=65535,h[1]+=d[2]*p[2],h[0]+=h[1]>>>16,h[1]&=65535,h[1]+=d[3]*p[1],h[0]+=h[1]>>>16,h[1]&=65535,h[0]+=d[0]*p[3]+d[1]*p[2]+d[2]*p[1]+d[3]*p[0],h[0]&=65535,[h[0]<<16|h[1],h[2]<<16|h[3]]}function u(d,p){return p%=64,p===32?[d[1],d[0]]:p<32?[d[0]<<p|d[1]>>>32-p,d[1]<<p|d[0]>>>32-p]:(p-=32,[d[1]<<p|d[0]>>>32-p,d[0]<<p|d[1]>>>32-p])}function l(d,p){return p%=64,p===0?d:p<32?[d[0]<<p|d[1]>>>32-p,d[1]<<p]:[d[1]<<p-32,0]}function f(d,p){return[d[0]^p[0],d[1]^p[1]]}function m(d){return d=f(d,[0,d[0]>>>1]),d=c(d,[4283543511,3981806797]),d=f(d,[0,d[0]>>>1]),d=c(d,[3301882366,444984403]),d=f(d,[0,d[0]>>>1]),d}t.x86.hash32=function(d,p){if(t.inputValidation&&!n(d))return e;p=p||0;for(var h=d.length%4,y=d.length-h,g=p,x=0,b=3432918353,_=461845907,A=0;A<y;A=A+4)x=d[A]|d[A+1]<<8|d[A+2]<<16|d[A+3]<<24,x=o(x,b),x=i(x,15),x=o(x,_),g^=x,g=i(g,13),g=o(g,5)+3864292196;switch(x=0,h){case 3:x^=d[A+2]<<16;case 2:x^=d[A+1]<<8;case 1:x^=d[A],x=o(x,b),x=i(x,15),x=o(x,_),g^=x}return g^=d.length,g=s(g),g>>>0},t.x86.hash128=function(d,p){if(t.inputValidation&&!n(d))return e;p=p||0;for(var h=d.length%16,y=d.length-h,g=p,x=p,b=p,_=p,A=0,S=0,v=0,E=0,R=597399067,N=2869860233,T=951274213,H=2716044179,D=0;D<y;D=D+16)A=d[D]|d[D+1]<<8|d[D+2]<<16|d[D+3]<<24,S=d[D+4]|d[D+5]<<8|d[D+6]<<16|d[D+7]<<24,v=d[D+8]|d[D+9]<<8|d[D+10]<<16|d[D+11]<<24,E=d[D+12]|d[D+13]<<8|d[D+14]<<16|d[D+15]<<24,A=o(A,R),A=i(A,15),A=o(A,N),g^=A,g=i(g,19),g+=x,g=o(g,5)+1444728091,S=o(S,N),S=i(S,16),S=o(S,T),x^=S,x=i(x,17),x+=b,x=o(x,5)+197830471,v=o(v,T),v=i(v,17),v=o(v,H),b^=v,b=i(b,15),b+=_,b=o(b,5)+2530024501,E=o(E,H),E=i(E,18),E=o(E,R),_^=E,_=i(_,13),_+=g,_=o(_,5)+850148119;switch(A=0,S=0,v=0,E=0,h){case 15:E^=d[D+14]<<16;case 14:E^=d[D+13]<<8;case 13:E^=d[D+12],E=o(E,H),E=i(E,18),E=o(E,R),_^=E;case 12:v^=d[D+11]<<24;case 11:v^=d[D+10]<<16;case 10:v^=d[D+9]<<8;case 9:v^=d[D+8],v=o(v,T),v=i(v,17),v=o(v,H),b^=v;case 8:S^=d[D+7]<<24;case 7:S^=d[D+6]<<16;case 6:S^=d[D+5]<<8;case 5:S^=d[D+4],S=o(S,N),S=i(S,16),S=o(S,T),x^=S;case 4:A^=d[D+3]<<24;case 3:A^=d[D+2]<<16;case 2:A^=d[D+1]<<8;case 1:A^=d[D],A=o(A,R),A=i(A,15),A=o(A,N),g^=A}return g^=d.length,x^=d.length,b^=d.length,_^=d.length,g+=x,g+=b,g+=_,x+=g,b+=g,_+=g,g=s(g),x=s(x),b=s(b),_=s(_),g+=x,g+=b,g+=_,x+=g,b+=g,_+=g,("00000000"+(g>>>0).toString(16)).slice(-8)+("00000000"+(x>>>0).toString(16)).slice(-8)+("00000000"+(b>>>0).toString(16)).slice(-8)+("00000000"+(_>>>0).toString(16)).slice(-8)},t.x64.hash128=function(d,p){if(t.inputValidation&&!n(d))return e;p=p||0;for(var h=d.length%16,y=d.length-h,g=[0,p],x=[0,p],b=[0,0],_=[0,0],A=[2277735313,289559509],S=[1291169091,658871167],v=0;v<y;v=v+16)b=[d[v+4]|d[v+5]<<8|d[v+6]<<16|d[v+7]<<24,d[v]|d[v+1]<<8|d[v+2]<<16|d[v+3]<<24],_=[d[v+12]|d[v+13]<<8|d[v+14]<<16|d[v+15]<<24,d[v+8]|d[v+9]<<8|d[v+10]<<16|d[v+11]<<24],b=c(b,A),b=u(b,31),b=c(b,S),g=f(g,b),g=u(g,27),g=a(g,x),g=a(c(g,[0,5]),[0,1390208809]),_=c(_,S),_=u(_,33),_=c(_,A),x=f(x,_),x=u(x,31),x=a(x,g),x=a(c(x,[0,5]),[0,944331445]);switch(b=[0,0],_=[0,0],h){case 15:_=f(_,l([0,d[v+14]],48));case 14:_=f(_,l([0,d[v+13]],40));case 13:_=f(_,l([0,d[v+12]],32));case 12:_=f(_,l([0,d[v+11]],24));case 11:_=f(_,l([0,d[v+10]],16));case 10:_=f(_,l([0,d[v+9]],8));case 9:_=f(_,[0,d[v+8]]),_=c(_,S),_=u(_,33),_=c(_,A),x=f(x,_);case 8:b=f(b,l([0,d[v+7]],56));case 7:b=f(b,l([0,d[v+6]],48));case 6:b=f(b,l([0,d[v+5]],40));case 5:b=f(b,l([0,d[v+4]],32));case 4:b=f(b,l([0,d[v+3]],24));case 3:b=f(b,l([0,d[v+2]],16));case 2:b=f(b,l([0,d[v+1]],8));case 1:b=f(b,[0,d[v]]),b=c(b,A),b=u(b,31),b=c(b,S),g=f(g,b)}return g=f(g,[0,d.length]),x=f(x,[0,d.length]),g=a(g,x),x=a(x,g),g=m(g),x=m(x),g=a(g,x),x=a(x,g),("00000000"+(g[0]>>>0).toString(16)).slice(-8)+("00000000"+(g[1]>>>0).toString(16)).slice(-8)+("00000000"+(x[0]>>>0).toString(16)).slice(-8)+("00000000"+(x[1]>>>0).toString(16)).slice(-8)},typeof gs<"u"?(typeof Wc<"u"&&Wc.exports&&(gs=Wc.exports=t),gs.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)})(gs)});var $y=Ee(($7,zy)=>{zy.exports=My()});var Yc=Ee((X7,qy)=>{"use strict";qy.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 o=!1;n===-1?(n=this._data.length,this._setBit(e),this._changedData=!0):o=!0,this._setInternalPos(n,e,t,o),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,o=t;for(;n<this.length;){let i=this.get(n);o=e(o,i,n),n++}return o}find(e){let t=0,n,o;for(;t<this.length&&!n;)o=this.get(t),n=e(o),t++;return n?o:void 0}_internalPositionFor(e,t){let n=this._bytePosFor(e,t);if(n>=this._bitArrays.length)return-1;let o=this._bitArrays[n],i=e-n*7;if(!((o&1<<i)>0))return-1;let a=this._bitArrays.slice(0,n).reduce(Uv,0),c=~(4294967295<<i+1),u=Ky(o&c);return a+u-1}_bytePosFor(e,t){let n=Math.floor(e/7),o=n+1;for(;!t&&this._bitArrays.length<o;)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,o){let i=this._data,s=[t,n];if(o)this._sortData(),i[e]=s;else{if(i.length)if(i[i.length-1][0]>=t)i.push(s);else if(i[0][0]<=t)i.unshift(s);else{let a=Math.round(i.length/2);this._data=i.slice(0,a).concat(s).concat(i.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(Fv),this._changedData=!1}bitField(){let e=[],t=8,n=0,o=0,i,s=this._bitArrays.slice();for(;s.length||n;){n===0&&(i=s.shift(),n=7);let c=Math.min(n,t),u=~(255<<c),l=i&u;o|=l<<8-t,i=i>>>c,n-=c,t-=c,(!t||!n&&!s.length)&&(e.push(o),o=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(Vv)}};function Uv(r,e){return r+Ky(e)}function Ky(r){let e=r;return e=e-(e>>1&1431655765),e=(e&858993459)+(e>>2&858993459),(e+(e>>4)&252645135)*16843009>>24}function Fv(r,e){return r[0]-e[0]}function Vv(r){return r[1]}});var sg=Ee((NU,ig)=>{var kd=class{constructor(e,t=12,n=8*1024,o=32*1024,i=64,s){this.bits=t,this.min=n,this.max=o,this.asModule=e,this.rabin=new e.Rabin(t,n,o,i,s),this.polynomial=s}fingerprint(e){let{__retain:t,__release:n,__allocArray:o,__getInt32Array:i,Int32Array_ID:s,Uint8Array_ID:a}=this.asModule,c=new Int32Array(Math.ceil(e.length/this.min)),u=t(o(s,c)),l=t(o(a,e)),f=this.rabin.fingerprint(l,u),m=i(f);n(l),n(u);let d=m.indexOf(0);return d>=0?m.subarray(0,d):m}};ig.exports=kd});var dg=Ee(xs=>{"use strict";var Jv=typeof BigUint64Array<"u",ws=Symbol(),bs=1024;function ag(r,e){let t=new Uint32Array(r),n=new Uint16Array(r);var o=t[e+-4>>>2]>>>1,i=e>>>1;if(o<=bs)return String.fromCharCode.apply(String,n.subarray(i,i+o));let s=[];do{let a=n[i+bs-1],c=a>=55296&&a<56320?bs-1:bs;s.push(String.fromCharCode.apply(String,n.subarray(i,i+=c))),o-=c}while(o>bs);return s.join("")+String.fromCharCode.apply(String,n.subarray(i,i+o))}function Id(r){let e={};function t(o,i){return o?ag(o.buffer,i):"<yet unknown>"}let n=r.env=r.env||{};return n.abort=n.abort||function(i,s,a,c){let u=e.memory||n.memory;throw Error("abort: "+t(u,i)+" at "+t(u,s)+":"+a+":"+c)},n.trace=n.trace||function(i,s){let a=e.memory||n.memory;console.log("trace: "+t(a,i)+(s?" ":"")+Array.prototype.slice.call(arguments,2,2+s).join(", "))},r.Math=r.Math||Math,r.Date=r.Date||Date,e}function Bd(r,e){let t=e.exports,n=t.memory,o=t.table,i=t.__alloc,s=t.__retain,a=t.__rtti_base||-1;function c(S){let v=new Uint32Array(n.buffer),E=v[a>>>2];if((S>>>=0)>=E)throw Error("invalid id: "+S);return v[(a+4>>>2)+S*2]}function u(S){let v=new Uint32Array(n.buffer),E=v[a>>>2];if((S>>>=0)>=E)throw Error("invalid id: "+S);return v[(a+4>>>2)+S*2+1]}function l(S){return 31-Math.clz32(S>>>5&31)}function f(S){return 31-Math.clz32(S>>>14&31)}function m(S){let v=S.length,E=i(v<<1,1),R=new Uint16Array(n.buffer);for(var N=0,T=E>>>1;N<v;++N)R[T+N]=S.charCodeAt(N);return E}r.__allocString=m;function d(S){let v=n.buffer;if(new Uint32Array(v)[S+-8>>>2]!==1)throw Error("not a string: "+S);return ag(v,S)}r.__getString=d;function p(S,v,E){let R=n.buffer;if(E)switch(S){case 2:return new Float32Array(R);case 3:return new Float64Array(R)}else switch(S){case 0:return new(v?Int8Array:Uint8Array)(R);case 1:return new(v?Int16Array:Uint16Array)(R);case 2:return new(v?Int32Array:Uint32Array)(R);case 3:return new(v?BigInt64Array:BigUint64Array)(R)}throw Error("unsupported align: "+S)}function h(S,v){let E=c(S);if(!(E&3))throw Error("not an array: "+S+" @ "+E);let R=l(E),N=v.length,T=i(N<<R,0),H=i(E&2?16:12,S),D=new Uint32Array(n.buffer);D[H+0>>>2]=s(T),D[H+4>>>2]=T,D[H+8>>>2]=N<<R,E&2&&(D[H+12>>>2]=N);let Q=p(R,E&1024,E&2048);if(E&8192)for(let k=0;k<N;++k)Q[(T>>>R)+k]=s(v[k]);else Q.set(v,T>>>R);return H}r.__allocArray=h;function y(S){let v=new Uint32Array(n.buffer),E=v[S+-8>>>2],R=c(E);if(!(R&1))throw Error("not an array: "+E);let N=l(R);var T=v[S+4>>>2];let H=R&2?v[S+12>>>2]:v[T+-4>>>2]>>>N;return p(N,R&1024,R&2048).subarray(T>>>=N,T+H)}r.__getArrayView=y;function g(S){let v=y(S),E=v.length,R=new Array(E);for(let N=0;N<E;N++)R[N]=v[N];return R}r.__getArray=g;function x(S){let v=n.buffer,E=new Uint32Array(v)[S+-4>>>2];return v.slice(S,S+E)}r.__getArrayBuffer=x;function b(S,v,E){return new S(_(S,v,E))}function _(S,v,E){let R=n.buffer,N=new Uint32Array(R),T=N[E+4>>>2];return new S(R,T,N[T+-4>>>2]>>>v)}r.__getInt8Array=b.bind(null,Int8Array,0),r.__getInt8ArrayView=_.bind(null,Int8Array,0),r.__getUint8Array=b.bind(null,Uint8Array,0),r.__getUint8ArrayView=_.bind(null,Uint8Array,0),r.__getUint8ClampedArray=b.bind(null,Uint8ClampedArray,0),r.__getUint8ClampedArrayView=_.bind(null,Uint8ClampedArray,0),r.__getInt16Array=b.bind(null,Int16Array,1),r.__getInt16ArrayView=_.bind(null,Int16Array,1),r.__getUint16Array=b.bind(null,Uint16Array,1),r.__getUint16ArrayView=_.bind(null,Uint16Array,1),r.__getInt32Array=b.bind(null,Int32Array,2),r.__getInt32ArrayView=_.bind(null,Int32Array,2),r.__getUint32Array=b.bind(null,Uint32Array,2),r.__getUint32ArrayView=_.bind(null,Uint32Array,2),Jv&&(r.__getInt64Array=b.bind(null,BigInt64Array,3),r.__getInt64ArrayView=_.bind(null,BigInt64Array,3),r.__getUint64Array=b.bind(null,BigUint64Array,3),r.__getUint64ArrayView=_.bind(null,BigUint64Array,3)),r.__getFloat32Array=b.bind(null,Float32Array,2),r.__getFloat32ArrayView=_.bind(null,Float32Array,2),r.__getFloat64Array=b.bind(null,Float64Array,3),r.__getFloat64ArrayView=_.bind(null,Float64Array,3);function A(S,v){let E=new Uint32Array(n.buffer);var R=E[S+-8>>>2];if(R<=E[a>>>2])do if(R==v)return!0;while(R=u(R));return!1}return r.__instanceof=A,r.memory=r.memory||n,r.table=r.table||o,fg(t,r)}function cg(r){return typeof Response<"u"&&r instanceof Response}async function lg(r,e){return cg(r=await r)?ug(r,e):Bd(Id(e||(e={})),await WebAssembly.instantiate(r instanceof WebAssembly.Module?r:await WebAssembly.compile(r),e))}xs.instantiate=lg;function Qv(r,e){return Bd(Id(e||(e={})),new WebAssembly.Instance(r instanceof WebAssembly.Module?r:new WebAssembly.Module(r),e))}xs.instantiateSync=Qv;async function ug(r,e){return WebAssembly.instantiateStreaming?Bd(Id(e||(e={})),(await WebAssembly.instantiateStreaming(r,e)).instance):lg(cg(r=await r)?r.arrayBuffer():r,e)}xs.instantiateStreaming=ug;function fg(r,e){var t=e?Object.create(e):{},n=r.__argumentsLength?function(o){r.__argumentsLength.value=o}:r.__setArgumentsLength||r.__setargc||function(){};for(let o in r){if(!Object.prototype.hasOwnProperty.call(r,o))continue;let i=r[o],s=o.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),f=a[l];if(typeof f>"u"||!f.prototype){let m=function(...d){return m.wrap(m.prototype.constructor(0,...d))};m.prototype={valueOf:function(){return this[ws]}},m.wrap=function(d){return Object.create(m.prototype,{[ws]:{value:d,writable:!1}})},f&&Object.getOwnPropertyNames(f).forEach(d=>Object.defineProperty(m,d,Object.getOwnPropertyDescriptor(f,d))),a[l]=m}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 m=r[o.replace("set:","get:")],d=r[o.replace("get:","set:")];Object.defineProperty(a,c,{get:function(){return m(this[ws])},set:function(p){d(this[ws],p)},enumerable:!0})}}else c==="constructor"?(a[c]=(...m)=>(n(m.length),i(...m))).original=i:(a[c]=function(...m){return n(m.length),i(this[ws],...m)}).original=i}else/^(get|set):/.test(c)?Object.prototype.hasOwnProperty.call(a,c=c.substring(4))||Object.defineProperty(a,c,{get:r[o.replace("set:","get:")],set:r[o.replace("get:","set:")],enumerable:!0}):typeof i=="function"&&i!==n?(a[c]=(...l)=>(n(l.length),i(...l))).original=i:a[c]=i}return t}xs.demangle=fg});var pg=Ee((LU,hg)=>{var{instantiate:eS}=dg();Rd.supported=typeof WebAssembly<"u";function Rd(r={}){if(!Rd.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 eS(new Response(new Blob([e],{type:"application/wasm"})),r)}hg.exports=Rd});var gg=Ee((DU,yg)=>{var mg=sg(),tS=pg(),rS=async(r,e,t,n,o)=>{let i=await tS();return new mg(i,r,e,t,n,o)};yg.exports={Rabin:mg,create:rS}});var $g=Ee((n9,zg)=>{"use strict";zg.exports=r=>{if(Object.prototype.toString.call(r)!=="[object Object]")return!1;let e=Object.getPrototypeOf(r);return e===null||e===Object.prototype}});var Yg=Ee((Wg,jg)=>{"use strict";var tl=$g(),{hasOwnProperty:qg}=Object.prototype,{propertyIsEnumerable:BS}=Object,Zo=(r,e,t)=>Object.defineProperty(r,e,{value:t,writable:!0,enumerable:!0,configurable:!0}),RS=Wg,Kg={concatArrays:!1,ignoreUndefined:!1},rl=r=>{let e=[];for(let t in r)qg.call(r,t)&&e.push(t);if(Object.getOwnPropertySymbols){let t=Object.getOwnPropertySymbols(r);for(let n of t)BS.call(r,n)&&e.push(n)}return e};function Jo(r){return Array.isArray(r)?TS(r):tl(r)?NS(r):r}function TS(r){let e=r.slice(0,0);return rl(r).forEach(t=>{Zo(e,t,Jo(r[t]))}),e}function NS(r){let e=Object.getPrototypeOf(r)===null?Object.create(null):{};return rl(r).forEach(t=>{Zo(e,t,Jo(r[t]))}),e}var Gg=(r,e,t,n)=>(t.forEach(o=>{typeof e[o]>"u"&&n.ignoreUndefined||(o in r&&r[o]!==Object.getPrototypeOf(r)?Zo(r,o,Nd(r[o],e[o],n)):Zo(r,o,Jo(e[o])))}),r),CS=(r,e,t)=>{let n=r.slice(0,0),o=0;return[r,e].forEach(i=>{let s=[];for(let a=0;a<i.length;a++)qg.call(i,a)&&(s.push(String(a)),i===r?Zo(n,o++,i[a]):Zo(n,o++,Jo(i[a])));n=Gg(n,i,rl(i).filter(a=>!s.includes(a)),t)}),n};function Nd(r,e,t){return t.concatArrays&&Array.isArray(r)&&Array.isArray(e)?CS(r,e,t):!tl(e)||!tl(r)?Jo(e):Gg(r,e,rl(e),t)}jg.exports=function(...r){let e=Nd(Jo(Kg),this!==RS&&this||{},Kg),t={_:{}};for(let n of r)if(n!==void 0){if(!tl(n))throw new TypeError("`"+n+"` is not an Option Object");t=Nd(t,{_:n},e)}return t._}});var vw=Ee((_M,Ew)=>{"use strict";Ew.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 cA={};ve(cA,{createVerifiedFetch:()=>qd,verifiedFetch:()=>vl});function Sn(r){let e=new globalThis.AbortController;function t(){e.abort();for(let i of r)i?.removeEventListener!=null&&i.removeEventListener("abort",t)}for(let i of r){if(i?.aborted===!0){t();break}i?.addEventListener!=null&&i.addEventListener("abort",t)}function n(){for(let i of r)i?.removeEventListener!=null&&i.removeEventListener("abort",t)}let o=e.signal;return o.clear=n,o}function Zw(r){let[e,t]=r[Symbol.asyncIterator]!=null?[r[Symbol.asyncIterator](),Symbol.asyncIterator]:[r[Symbol.iterator](),Symbol.iterator],n=[];return{peek:()=>e.next(),push:o=>{n.push(o)},next:()=>n.length>0?{done:!1,value:n.shift()}:e.next(),[t](){return this}}}var Zn=Zw;function Jw(r){return r[Symbol.asyncIterator]!=null}function th(r){return r?.then!=null}function Qw(r,e){if(Jw(r))return async function*(){for await(let a of r){let c=e(a);th(c)&&await c,yield a}}();let t=Zn(r),{value:n,done:o}=t.next();if(o===!0)return function*(){}();if(typeof e(n)?.then=="function")return async function*(){yield n;for await(let a of t){let c=e(a);th(c)&&await c,yield a}}();let s=e;return function*(){yield n;for(let a of t)s(a),yield a}()}var _l=Qw;var Cl={};ve(Cl,{base32:()=>Fe,base32hex:()=>ub,base32hexpad:()=>db,base32hexpadupper:()=>hb,base32hexupper:()=>fb,base32pad:()=>cb,base32padupper:()=>lb,base32upper:()=>ih,base32z:()=>pb});var Jn={};ve(Jn,{coerce:()=>St,empty:()=>rh,equals:()=>Al,fromHex:()=>tb,fromString:()=>kl,isBinary:()=>rb,toHex:()=>eb,toString:()=>Il});var rh=new Uint8Array(0);function eb(r){return r.reduce((e,t)=>e+t.toString(16).padStart(2,"0"),"")}function tb(r){let e=r.match(/../g);return e!=null?new Uint8Array(e.map(t=>parseInt(t,16))):rh}function Al(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 St(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 rb(r){return r instanceof ArrayBuffer||ArrayBuffer.isView(r)}function kl(r){return new TextEncoder().encode(r)}function Il(r){return new TextDecoder().decode(r)}function nb(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 o=0;o<r.length;o++){var i=r.charAt(o),s=i.charCodeAt(0);if(t[s]!==255)throw new TypeError(i+" is ambiguous");t[s]=o}var a=r.length,c=r.charAt(0),u=Math.log(a)/Math.log(256),l=Math.log(256)/Math.log(a);function f(p){if(p instanceof Uint8Array||(ArrayBuffer.isView(p)?p=new Uint8Array(p.buffer,p.byteOffset,p.byteLength):Array.isArray(p)&&(p=Uint8Array.from(p))),!(p instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(p.length===0)return"";for(var h=0,y=0,g=0,x=p.length;g!==x&&p[g]===0;)g++,h++;for(var b=(x-g)*l+1>>>0,_=new Uint8Array(b);g!==x;){for(var A=p[g],S=0,v=b-1;(A!==0||S<y)&&v!==-1;v--,S++)A+=256*_[v]>>>0,_[v]=A%a>>>0,A=A/a>>>0;if(A!==0)throw new Error("Non-zero carry");y=S,g++}for(var E=b-y;E!==b&&_[E]===0;)E++;for(var R=c.repeat(h);E<b;++E)R+=r.charAt(_[E]);return R}function m(p){if(typeof p!="string")throw new TypeError("Expected String");if(p.length===0)return new Uint8Array;var h=0;if(p[h]!==" "){for(var y=0,g=0;p[h]===c;)y++,h++;for(var x=(p.length-h)*u+1>>>0,b=new Uint8Array(x);p[h];){var _=t[p.charCodeAt(h)];if(_===255)return;for(var A=0,S=x-1;(_!==0||A<g)&&S!==-1;S--,A++)_+=a*b[S]>>>0,b[S]=_%256>>>0,_=_/256>>>0;if(_!==0)throw new Error("Non-zero carry");g=A,h++}if(p[h]!==" "){for(var v=x-g;v!==x&&b[v]===0;)v++;for(var E=new Uint8Array(y+(x-v)),R=y;v!==x;)E[R++]=b[v++];return E}}}function d(p){var h=m(p);if(h)return h;throw new Error(`Non-${e} character`)}return{encode:f,decodeUnsafe:m,decode:d}}var ob=nb,ib=ob,nh=ib;var Bl=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")}},Rl=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 oh(this,e)}},Tl=class{decoders;constructor(e){this.decoders=e}or(e){return oh(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 oh(r,e){return new Tl({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}var Nl=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,t,n,o){this.name=e,this.prefix=t,this.baseEncode=n,this.baseDecode=o,this.encoder=new Bl(e,t,n),this.decoder=new Rl(e,t,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function Qn({name:r,prefix:e,encode:t,decode:n}){return new Nl(r,e,t,n)}function Ur({name:r,prefix:e,alphabet:t}){let{encode:n,decode:o}=nh(t,r);return Qn({prefix:e,name:r,encode:n,decode:i=>St(o(i))})}function sb(r,e,t,n){let o={};for(let l=0;l<e.length;++l)o[e[l]]=l;let i=r.length;for(;r[i-1]==="=";)--i;let s=new Uint8Array(i*t/8|0),a=0,c=0,u=0;for(let l=0;l<i;++l){let f=o[r[l]];if(f===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<t|f,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 ab(r,e,t){let n=e[e.length-1]==="=",o=(1<<t)-1,i="",s=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],s+=8;s>t;)s-=t,i+=e[o&a>>s];if(s!==0&&(i+=e[o&a<<t-s]),n)for(;i.length*t&7;)i+="=";return i}function Se({name:r,prefix:e,bitsPerChar:t,alphabet:n}){return Qn({prefix:e,name:r,encode(o){return ab(o,n,t)},decode(o){return sb(o,n,t,r)}})}var Fe=Se({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),ih=Se({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),cb=Se({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),lb=Se({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),ub=Se({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),fb=Se({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),db=Se({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),hb=Se({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),pb=Se({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Ll={};ve(Ll,{base58btc:()=>ke,base58flickr:()=>mb});var ke=Ur({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),mb=Ur({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var yb=ch,sh=128,gb=127,wb=~gb,bb=Math.pow(2,31);function ch(r,e,t){e=e||[],t=t||0;for(var n=t;r>=bb;)e[t++]=r&255|sh,r/=128;for(;r&wb;)e[t++]=r&255|sh,r>>>=7;return e[t]=r|0,ch.bytes=t-n+1,e}var xb=Dl,Eb=128,ah=127;function Dl(r,n){var t=0,n=n||0,o=0,i=n,s,a=r.length;do{if(i>=a)throw Dl.bytes=0,new RangeError("Could not decode varint");s=r[i++],t+=o<28?(s&ah)<<o:(s&ah)*Math.pow(2,o),o+=7}while(s>=Eb);return Dl.bytes=i-n,t}var vb=Math.pow(2,7),Sb=Math.pow(2,14),_b=Math.pow(2,21),Ab=Math.pow(2,28),kb=Math.pow(2,35),Ib=Math.pow(2,42),Bb=Math.pow(2,49),Rb=Math.pow(2,56),Tb=Math.pow(2,63),Nb=function(r){return r<vb?1:r<Sb?2:r<_b?3:r<Ab?4:r<kb?5:r<Ib?6:r<Bb?7:r<Rb?8:r<Tb?9:10},Cb={encode:yb,decode:xb,encodingLength:Nb},Lb=Cb,si=Lb;function ai(r,e=0){return[si.decode(r,e),si.decode.bytes]}function eo(r,e,t=0){return si.encode(r,e,t),e}function to(r){return si.encodingLength(r)}function Zt(r,e){let t=e.byteLength,n=to(r),o=n+to(t),i=new Uint8Array(o+t);return eo(r,i,0),eo(t,i,n),i.set(e,o),new ro(r,t,e,i)}function Ze(r){let e=St(r),[t,n]=ai(e),[o,i]=ai(e.subarray(n)),s=e.subarray(n+i);if(s.byteLength!==o)throw new Error("Incorrect length");return new ro(t,o,s,e)}function lh(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&Al(r.bytes,t.bytes)}}var ro=class{code;size;digest;bytes;constructor(e,t,n,o){this.code=e,this.size=t,this.digest=n,this.bytes=o}};function uh(r,e){let{bytes:t,version:n}=r;switch(n){case 0:return Pb(t,Pl(r),e??ke.encoder);default:return Ob(t,Pl(r),e??Fe.encoder)}}var fh=new WeakMap;function Pl(r){let e=fh.get(r);if(e==null){let t=new Map;return fh.set(r,t),t}return e}var U=class r{code;version;multihash;bytes;"/";constructor(e,t,n,o){this.code=t,this.version=e,this.multihash=n,this.bytes=o,this["/"]=o}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!==ci)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==Ub)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=Zt(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&&lh(e.multihash,n.multihash)}toString(e){return uh(this,e)}toJSON(){return{"/":uh(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:o,multihash:i,bytes:s}=t;return new r(n,o,i,s??dh(n,o,i.bytes))}else if(t[Fb]===!0){let{version:n,multihash:o,code:i}=t,s=Ze(o);return r.create(n,i,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!==ci)throw new Error(`Version 0 CID must use dag-pb (code: ${ci}) block encoding`);return new r(e,t,n,n.bytes)}case 1:{let o=dh(e,t,n.bytes);return new r(e,t,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return r.create(0,ci,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,o=St(e.subarray(n,n+t.multihashSize));if(o.byteLength!==t.multihashSize)throw new Error("Incorrect length");let i=o.subarray(t.multihashSize-t.digestSize),s=new ro(t.multihashCode,t.digestSize,i,o);return[t.version===0?r.createV0(s):r.createV1(t.codec,s),e.subarray(t.size)]}static inspectBytes(e){let t=0,n=()=>{let[f,m]=ai(e.subarray(t));return t+=m,f},o=n(),i=ci;if(o===18?(o=0,t=0):i=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let s=t,a=n(),c=n(),u=t+c,l=u-s;return{version:o,codec:i,multihashCode:a,digestSize:c,multihashSize:l,size:u}}static parse(e,t){let[n,o]=Db(e,t),i=r.decode(o);if(i.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Pl(i).set(n,e),i}};function Db(r,e){switch(r[0]){case"Q":{let t=e??ke;return[ke.prefix,t.decode(`${ke.prefix}${r}`)]}case ke.prefix:{let t=e??ke;return[ke.prefix,t.decode(r)]}case Fe.prefix:{let t=e??Fe;return[Fe.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 Pb(r,e,t){let{prefix:n}=t;if(n!==ke.prefix)throw Error(`Cannot string encode V0 in ${t.name} encoding`);let o=e.get(n);if(o==null){let i=t.encode(r).slice(1);return e.set(n,i),i}else return o}function Ob(r,e,t){let{prefix:n}=t,o=e.get(n);if(o==null){let i=t.encode(r);return e.set(n,i),i}else return o}var ci=112,Ub=18;function dh(r,e,t){let n=to(r),o=n+to(e),i=new Uint8Array(o+t.byteLength);return eo(r,i,0),eo(e,i,n),i.set(t,o),i}var Fb=Symbol.for("@ipld/js-cid/CID");var li=Symbol.for("@libp2p/content-routing");var Ol=Symbol.for("@libp2p/peer-id");function hh(r){return r!=null&&!!r[Ol]}var ui=Symbol.for("@libp2p/peer-routing");var Fr=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"},P=class extends Error{code;props;constructor(e,t,n){super(e),this.code=t,this.name=n?.name??"CodeError",this.props=n??{}}};var no=(r,...e)=>{try{[...e]}catch{}};var Cs=class extends EventTarget{#e=new Map;constructor(){super(),no(1/0,this)}listenerCount(e){let t=this.#e.get(e);return t==null?0:t.length}addEventListener(e,t,n){super.addEventListener(e,t,n);let o=this.#e.get(e);o==null&&(o=[],this.#e.set(e,o)),o.push({callback:t,once:(n!==!0&&n!==!1&&n?.once)??!1})}removeEventListener(e,t,n){super.removeEventListener(e.toString(),t??null,n);let o=this.#e.get(e);o!=null&&(o=o.filter(({callback:i})=>i!==t),this.#e.set(e,o))}dispatchEvent(e){let t=super.dispatchEvent(e),n=this.#e.get(e.type);return n==null||(n=n.filter(({once:o})=>!o),this.#e.set(e.type,n)),t}safeDispatchEvent(e,t={}){return this.dispatchEvent(new Vb(e,t))}},Ul=class extends Event{detail;constructor(e,t){super(e,t),this.detail=t?.detail}},Vb=globalThis.CustomEvent??Ul;function ph(r){return r!=null&&typeof r.start=="function"&&typeof r.stop=="function"}async function Vr(...r){let e=[];for(let t of r)ph(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 Hr(...r){let e=[];for(let t of r)ph(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 Hl={};ve(Hl,{sha256:()=>ae,sha512:()=>Vl});function _n({name:r,code:e,encode:t}){return new Fl(r,e,t)}var Fl=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?Zt(this.code,t):t.then(n=>Zt(this.code,n))}else throw Error("Unknown type, must be binary type")}};function yh(r){return async e=>new Uint8Array(await crypto.subtle.digest(r,e))}var ae=_n({name:"sha2-256",code:18,encode:yh("SHA-256")}),Vl=_n({name:"sha2-512",code:19,encode:yh("SHA-512")});var pt=J(Eh(),1);var Ml={};ve(Ml,{base64:()=>Jt,base64pad:()=>Jb,base64url:()=>Qb,base64urlpad:()=>e2});var Jt=Se({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Jb=Se({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Qb=Se({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),e2=Se({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});pt.default.formatters.b=r=>r==null?"undefined":ke.baseEncode(r);pt.default.formatters.t=r=>r==null?"undefined":Fe.baseEncode(r);pt.default.formatters.m=r=>r==null?"undefined":Jt.baseEncode(r);pt.default.formatters.p=r=>r==null?"undefined":r.toString();pt.default.formatters.c=r=>r==null?"undefined":r.toString();pt.default.formatters.k=r=>r==null?"undefined":r.toString();pt.default.formatters.a=r=>r==null?"undefined":r.toString();function t2(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 vh(){return{forComponent(r){return ee(r)}}}function ee(r){let e=t2(`${r}:trace`);return pt.default.enabled(`${r}:trace`)&&pt.default.names.map(t=>t.toString()).find(t=>t.includes(":trace"))!=null&&(e=(0,pt.default)(`${r}:trace`)),Object.assign((0,pt.default)(r),{error:(0,pt.default)(`${r}:error`),trace:e})}function ce(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 hr(r=0){return new Uint8Array(r)}function it(r=0){return new Uint8Array(r)}var m2=Math.pow(2,7),y2=Math.pow(2,14),g2=Math.pow(2,21),Kl=Math.pow(2,28),ql=Math.pow(2,35),Gl=Math.pow(2,42),Wl=Math.pow(2,49),le=128,Ke=127;function st(r){if(r<m2)return 1;if(r<y2)return 2;if(r<g2)return 3;if(r<Kl)return 4;if(r<ql)return 5;if(r<Gl)return 6;if(r<Wl)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function jl(r,e,t=0){switch(st(r)){case 8:e[t++]=r&255|le,r/=128;case 7:e[t++]=r&255|le,r/=128;case 6:e[t++]=r&255|le,r/=128;case 5:e[t++]=r&255|le,r/=128;case 4:e[t++]=r&255|le,r>>>=7;case 3:e[t++]=r&255|le,r>>>=7;case 2:e[t++]=r&255|le,r>>>=7;case 1:{e[t++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return e}function w2(r,e,t=0){switch(st(r)){case 8:e.set(t++,r&255|le),r/=128;case 7:e.set(t++,r&255|le),r/=128;case 6:e.set(t++,r&255|le),r/=128;case 5:e.set(t++,r&255|le),r/=128;case 4:e.set(t++,r&255|le),r>>>=7;case 3:e.set(t++,r&255|le),r>>>=7;case 2:e.set(t++,r&255|le),r>>>=7;case 1:{e.set(t++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return e}function Yl(r,e){let t=r[e],n=0;if(n+=t&Ke,t<le||(t=r[e+1],n+=(t&Ke)<<7,t<le)||(t=r[e+2],n+=(t&Ke)<<14,t<le)||(t=r[e+3],n+=(t&Ke)<<21,t<le)||(t=r[e+4],n+=(t&Ke)*Kl,t<le)||(t=r[e+5],n+=(t&Ke)*ql,t<le)||(t=r[e+6],n+=(t&Ke)*Gl,t<le)||(t=r[e+7],n+=(t&Ke)*Wl,t<le))return n;throw new RangeError("Could not decode varint")}function b2(r,e){let t=r.get(e),n=0;if(n+=t&Ke,t<le||(t=r.get(e+1),n+=(t&Ke)<<7,t<le)||(t=r.get(e+2),n+=(t&Ke)<<14,t<le)||(t=r.get(e+3),n+=(t&Ke)<<21,t<le)||(t=r.get(e+4),n+=(t&Ke)*Kl,t<le)||(t=r.get(e+5),n+=(t&Ke)*ql,t<le)||(t=r.get(e+6),n+=(t&Ke)*Gl,t<le)||(t=r.get(e+7),n+=(t&Ke)*Wl,t<le))return n;throw new RangeError("Could not decode varint")}function ao(r,e,t=0){return e==null&&(e=it(st(r))),e instanceof Uint8Array?jl(r,e,t):w2(r,e,t)}function kn(r,e=0){return r instanceof Uint8Array?Yl(r,e):b2(r,e)}var Xl=new Float32Array([-0]),Mr=new Uint8Array(Xl.buffer);function Lh(r,e,t){Xl[0]=r,e[t]=Mr[0],e[t+1]=Mr[1],e[t+2]=Mr[2],e[t+3]=Mr[3]}function Dh(r,e){return Mr[0]=r[e],Mr[1]=r[e+1],Mr[2]=r[e+2],Mr[3]=r[e+3],Xl[0]}var Zl=new Float64Array([-0]),qe=new Uint8Array(Zl.buffer);function Ph(r,e,t){Zl[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 Oh(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],Zl[0]}var x2=BigInt(Number.MAX_SAFE_INTEGER),E2=BigInt(Number.MIN_SAFE_INTEGER),mt=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 In;if(e<x2&&e>E2)return this.fromNumber(Number(e));let t=e<0n;t&&(e=-e);let n=e>>32n,o=e-(n<<32n);return t&&(n=~n|0n,o=~o|0n,++o>Uh&&(o=0n,++n>Uh&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(e){if(e===0)return In;let t=e<0;t&&(e=-e);let n=e>>>0,o=(e-n)/4294967296>>>0;return t&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new r(n,o)}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):In}},In=new mt(0,0);In.toBigInt=function(){return 0n};In.zzEncode=In.zzDecode=function(){return this};In.length=function(){return 1};var Uh=4294967296n;function Fh(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 Vh(r,e,t){if(t-e<1)return"";let o,i=[],s=0,a;for(;e<t;)a=r[e++],a<128?i[s++]=a:a>191&&a<224?i[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,i[s++]=55296+(a>>10),i[s++]=56320+(a&1023)):i[s++]=(a&15)<<12|(r[e++]&63)<<6|r[e++]&63,s>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,i)),s=0);return o!=null?(s>0&&o.push(String.fromCharCode.apply(String,i.slice(0,s))),o.join("")):String.fromCharCode.apply(String,i.slice(0,s))}function Jl(r,e,t){let n=t,o,i;for(let s=0;s<r.length;++s)o=r.charCodeAt(s),o<128?e[t++]=o:o<2048?(e[t++]=o>>6|192,e[t++]=o&63|128):(o&64512)===55296&&((i=r.charCodeAt(s+1))&64512)===56320?(o=65536+((o&1023)<<10)+(i&1023),++s,e[t++]=o>>18|240,e[t++]=o>>12&63|128,e[t++]=o>>6&63|128,e[t++]=o&63|128):(e[t++]=o>>12|224,e[t++]=o>>6&63|128,e[t++]=o&63|128);return t-n}function Ut(r,e){return RangeError(`index out of range: ${r.pos} + ${e??1} > ${r.len}`)}function Os(r,e){return(r[e-4]|r[e-3]<<8|r[e-2]<<16|r[e-1]<<24)>>>0}var Ql=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,Ut(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 Ut(this,4);return Os(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Ut(this,4);return Os(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Ut(this,4);let e=Dh(this.buf,this.pos);return this.pos+=4,e}double(){if(this.pos+8>this.len)throw Ut(this,4);let e=Oh(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 Ut(this,e);return this.pos+=e,t===n?new Uint8Array(0):this.buf.subarray(t,n)}string(){let e=this.bytes();return Vh(e,0,e.length)}skip(e){if(typeof e=="number"){if(this.pos+e>this.len)throw Ut(this,e);this.pos+=e}else do if(this.pos>=this.len)throw Ut(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 mt(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 Ut(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 Ut(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 Ut(this,8);let e=Os(this.buf,this.pos+=4),t=Os(this.buf,this.pos+=4);return new mt(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=Yl(this.buf,this.pos);return this.pos+=st(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 eu(r){return new Ql(r instanceof Uint8Array?r:r.subarray())}function At(r,e,t){let n=eu(r);return e.decode(n,void 0,t)}var tu={};ve(tu,{base10:()=>v2});var v2=Ur({prefix:"9",name:"base10",alphabet:"0123456789"});var ru={};ve(ru,{base16:()=>S2,base16upper:()=>_2});var S2=Se({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),_2=Se({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var nu={};ve(nu,{base2:()=>A2});var A2=Se({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var ou={};ve(ou,{base256emoji:()=>T2});var Mh=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}"),k2=Mh.reduce((r,e,t)=>(r[t]=e,r),[]),I2=Mh.reduce((r,e,t)=>(r[e.codePointAt(0)]=t,r),[]);function B2(r){return r.reduce((e,t)=>(e+=k2[t],e),"")}function R2(r){let e=[];for(let t of r){let n=I2[t.codePointAt(0)];if(n===void 0)throw new Error(`Non-base256emoji character: ${t}`);e.push(n)}return new Uint8Array(e)}var T2=Qn({prefix:"\u{1F680}",name:"base256emoji",encode:B2,decode:R2});var iu={};ve(iu,{base36:()=>zr,base36upper:()=>N2});var zr=Ur({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),N2=Ur({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var su={};ve(su,{base8:()=>C2});var C2=Se({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var au={};ve(au,{identity:()=>L2});var L2=Qn({prefix:"\0",name:"identity",encode:r=>Il(r),decode:r=>kl(r)});var h4=new TextEncoder,D2=new TextDecoder;var $r=512;function zh(r){return JSON.parse(D2.decode(r))}var kt={};ve(kt,{code:()=>ge,decode:()=>U2,encode:()=>O2,name:()=>P2});var P2="raw",ge=85;function O2(r){return St(r)}function U2(r){return St(r)}var cu={};ve(cu,{identity:()=>Ge});var $h=0,F2="identity",Kh=St;function V2(r){return Zt($h,Kh(r))}var Ge={code:$h,name:F2,encode:Kh,digest:V2};var Kr={...au,...nu,...su,...tu,...ru,...Cl,...iu,...Ll,...Ml,...ou},A4={...Hl,...cu};function Gh(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}var qh=Gh("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),lu=Gh("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=it(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),H2={utf8:qh,"utf-8":qh,hex:Kr.base16,latin1:lu,ascii:lu,binary:lu,...Kr},Fs=H2;function F(r,e="utf8"){let t=Fs[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.decoder.decode(`${t.prefix}${r}`)}function uu(r){let e=r??8192,t=e>>>1,n,o=e;return function(s){if(s<1||s>t)return it(s);o+s>e&&(n=it(e),o=0);let a=n.subarray(o,o+=s);return o&7&&(o=(o|7)+1),a}}var Bn=class{fn;len;next;val;constructor(e,t,n){this.fn=e,this.len=t,this.next=void 0,this.val=n}};function fu(){}var hu=class{head;tail;len;next;constructor(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}},M2=uu();function z2(r){return globalThis.Buffer!=null?it(r):M2(r)}var di=class{len;head;tail;states;constructor(){this.len=0,this.head=new Bn(fu,0,0),this.tail=this.head,this.states=null}_push(e,t,n){return this.tail=this.tail.next=new Bn(e,t,n),this.len+=t,this}uint32(e){return this.len+=(this.tail=this.tail.next=new pu((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(Vs,10,mt.fromNumber(e)):this.uint32(e)}sint32(e){return this.uint32((e<<1^e>>31)>>>0)}uint64(e){let t=mt.fromBigInt(e);return this._push(Vs,t.length(),t)}uint64Number(e){return this._push(jl,st(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=mt.fromBigInt(e).zzEncode();return this._push(Vs,t.length(),t)}sint64Number(e){let t=mt.fromNumber(e).zzEncode();return this._push(Vs,t.length(),t)}sint64String(e){return this.sint64(BigInt(e))}bool(e){return this._push(du,1,e?1:0)}fixed32(e){return this._push(fi,4,e>>>0)}sfixed32(e){return this.fixed32(e)}fixed64(e){let t=mt.fromBigInt(e);return this._push(fi,4,t.lo)._push(fi,4,t.hi)}fixed64Number(e){let t=mt.fromNumber(e);return this._push(fi,4,t.lo)._push(fi,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(Lh,4,e)}double(e){return this._push(Ph,8,e)}bytes(e){let t=e.length>>>0;return t===0?this._push(du,1,0):this.uint32(t)._push(K2,t,e)}string(e){let t=Fh(e);return t!==0?this.uint32(t)._push(Jl,t,e):this._push(du,1,0)}fork(){return this.states=new hu(this),this.head=this.tail=new Bn(fu,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 Bn(fu,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=z2(this.len),n=0;for(;e!=null;)e.fn(e.val,t,n),n+=e.len,e=e.next;return t}};function du(r,e,t){e[t]=r&255}function $2(r,e,t){for(;r>127;)e[t++]=r&127|128,r>>>=7;e[t]=r}var pu=class extends Bn{next;constructor(e,t){super($2,e,t),this.next=void 0}};function Vs(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 fi(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 K2(r,e,t){e.set(r,t)}globalThis.Buffer!=null&&(di.prototype.bytes=function(r){let e=r.length>>>0;return this.uint32(e),e>0&&this._push(q2,e,r),this},di.prototype.string=function(r){let e=globalThis.Buffer.byteLength(r);return this.uint32(e),e>0&&this._push(G2,e,r),this});function q2(r,e,t){e.set(r,t)}function G2(r,e,t){r.length<40?Jl(r,e,t):e.utf8Write!=null?e.utf8Write(r,t):e.set(F(r),t)}function mu(){return new di}function It(r,e){let t=mu();return e.encode(r,t,{lengthDelimited:!1}),t.finish()}var co;(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"})(co||(co={}));function Hs(r,e,t,n){return{name:r,type:e,encode:t,decode:n}}function Rn(r){function e(o){if(r[o.toString()]==null)throw new Error("Invalid enum value");return r[o]}let t=function(i,s){let a=e(i);s.int32(a)},n=function(i){let s=i.int32();return e(s)};return Hs("enum",co.VARINT,t,n)}function Bt(r,e){return Hs("message",co.LENGTH_DELIMITED,r,e)}function W2(r){return r[Symbol.asyncIterator]!=null}function j2(r){if(W2(r))return(async()=>{for await(let e of r);})();for(let e of r);}var Ft=j2;function ue(r,e){e==null&&(e=r.reduce((o,i)=>o+i.length,0));let t=it(e),n=0;for(let o of r)t.set(o,n),n+=o.length;return t}var jh=Symbol.for("@achingbrain/uint8arraylist");function Wh(r,e){if(e==null||e<0)throw new RangeError("index is out of bounds");let t=0;for(let n of r){let o=t+n.byteLength;if(e<o)return{buf:n,index:e-t};t=o}throw new RangeError("index is out of bounds")}function Qt(r){return!!r?.[jh]}var Rt=class r{bufs;length;[jh]=!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(Qt(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(Qt(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=Wh(this.bufs,e);return t.buf[t.index]}set(e,t){let n=Wh(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(Qt(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:o}=this._subList(e,t);return ue(n,o)}subarray(e,t){let{bufs:n,length:o}=this._subList(e,t);return n.length===1?n[0]:ue(n,o)}sublist(e,t){let{bufs:n,length:o}=this._subList(e,t),i=new r;return i.length=o,i.bufs=[...n],i}_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=[],o=0;for(let i=0;i<this.bufs.length;i++){let s=this.bufs[i],a=o,c=a+s.byteLength;if(o=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 f=e-a;n.push(s.subarray(f,f+(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(!Qt(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 o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let i=256,s=new Int32Array(i);for(let f=0;f<i;f++)s[f]=-1;for(let f=0;f<o;f++)s[n[f]]=f;let a=s,c=this.byteLength-n.byteLength,u=n.byteLength-1,l;for(let f=t;f<=c;f+=l){l=0;for(let m=u;m>=0;m--){let d=this.get(f+m);if(n[m]!==d){l=Math.max(1,m-a[d]);break}}if(l===0)return f}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=it(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 o=hr(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,t,n),this.write(o,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 o=hr(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,t,n),this.write(o,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 o=hr(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,t,n),this.write(o,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=it(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 o=hr(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,t,n),this.write(o,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 o=hr(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,t,n),this.write(o,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 o=hr(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,t,n),this.write(o,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 o=hr(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,t,n),this.write(o,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 o=hr(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,t,n),this.write(o,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(!ce(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((o,i)=>o+i.byteLength,0)),n.length=t,n}};function X2(r){return r[Symbol.asyncIterator]!=null}function Z2(r,e){if(X2(r))return async function*(){for await(let a of r)yield e(a)}();let t=Zn(r),{value:n,done:o}=t.next();if(o===!0)return function*(){}();let i=e(n);if(typeof i.then=="function")return async function*(){yield await i;for await(let a of t)yield e(a)}();let s=e;return function*(){yield i;for(let a of t)yield s(a)}()}var We=Z2;function we(){let r={};return r.promise=new Promise((e,t)=>{r.resolve=e,r.reject=t}),r}var Ms=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}},lo=class{size;hwm;head;tail;constructor(e={}){this.hwm=e.splitLimit??16,this.head=new Ms(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 Ms(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 yu=class extends Error{type;code;constructor(e,t){super(e??"The operation was aborted"),this.type="aborted",this.code=t??"ABORT_ERR"}};function Tt(r={}){return J2(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 J2(r,e){e=e??{};let t=e.onEnd,n=new lo,o,i,s,a=we(),c=async()=>{try{return n.isEmpty()?s?{done:!0}:await new Promise((y,g)=>{i=x=>{i=null,n.push(x);try{y(r(n))}catch(b){g(b)}return o}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=we()})}},u=y=>i!=null?i(y):(n.push(y),o),l=y=>(n=new lo,i!=null?i({error:y}):(n.push({error:y}),o)),f=y=>{if(s)return o;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})},m=y=>s?o:(s=!0,y!=null?l(y):u({done:!0})),d=()=>(n=new lo,m(),{done:!0}),p=y=>(m(y),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:c,return:d,throw:p,push:f,end:m,get readableLength(){return n.size},onEmpty:async y=>{let g=y?.signal;if(g?.throwIfAborted(),n.isEmpty())return;let x,b;g!=null&&(x=new Promise((_,A)=>{b=()=>{A(new yu)},g.addEventListener("abort",b)}));try{await Promise.race([a.promise,x])}finally{b!=null&&g!=null&&g?.removeEventListener("abort",b)}}},t==null)return o;let h=o;return o={[Symbol.asyncIterator](){return this},next(){return h.next()},throw(y){return h.throw(y),t!=null&&(t(y),t=void 0),{done:!0}},return(){return h.return(),t!=null&&(t(),t=void 0),{done:!0}},push:f,end(y){return h.end(y),t!=null&&(t(y),t=void 0),o},get readableLength(){return h.readableLength},onEmpty:y=>h.onEmpty(y)},o}function Q2(r){return r[Symbol.asyncIterator]!=null}function ex(...r){let e=[];for(let t of r)Q2(t)||e.push(t);return e.length===r.length?function*(){for(let t of e)yield*t}():async function*(){let t=Tt({objectMode:!0});Promise.resolve().then(async()=>{try{await Promise.all(r.map(async n=>{for await(let o of n)t.push(o)})),t.end()}catch(n){t.end(n)}}),yield*t}()}var pr=ex;function at(r,...e){if(r==null)throw new Error("Empty pipeline");if(gu(r)){let n=r;r=()=>n.source}else if(Jh(r)||Zh(r)){let n=r;r=()=>n}let t=[r,...e];if(t.length>1&&gu(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++)gu(t[n])&&(t[n]=rx(t[n]));return tx(...t)}var tx=(...r)=>{let e;for(;r.length>0;)e=r.shift()(e);return e},Zh=r=>r?.[Symbol.asyncIterator]!=null,Jh=r=>r?.[Symbol.iterator]!=null,gu=r=>r==null?!1:r.sink!=null&&r.source!=null,rx=r=>e=>{let t=r.sink(e);if(t?.then!=null){let n=Tt({objectMode:!0});t.then(()=>{n.end()},s=>{n.end(s)});let o,i=r.source;if(Zh(i))o=async function*(){yield*i,n.end()};else if(Jh(i))o=function*(){yield*i,n.end()};else throw new Error("Unknown duplex source type - must be Iterable or AsyncIterable");return pr(n,o())}return r.source};function nx(r){return r[Symbol.asyncIterator]!=null}function ox(r,e){return nx(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 zs=ox;var V=class extends Event{constructor(e,t){super(e),this.detail=t}};function W(r,e="utf8"){let t=Fs[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.encoder.encode(r).substring(1)}var $s=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 o=await fetch(n.toString(),{signal:t,headers:{Accept:"application/vnd.ipld.raw"},cache:"force-cache"});if(!o.ok)throw this.#t++,new Error(`unable to fetch raw block for CID ${e} from gateway ${this.url}`);return this.#s++,new Uint8Array(await o.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 Ks=class{gateways;log;constructor(e,t={}){this.log=e.logger.forComponent("helia:trustless-gateway-block-broker"),this.gateways=(t.gateways??Qh).map(n=>new $s(n))}async retrieve(e,t={}){let n=this.gateways.sort((i,s)=>s.reliability()-i.reliability()),o=[];for(let i of n){this.log("getting block for %c from %s",e,i.url);try{let s=await i.getRawBlock(e,t.signal);this.log.trace("got block for %c from %s",e,i.url);try{await t.validateFn?.(s)}catch(a){throw this.log.error("failed to validate block for %c from %s",e,i.url,a),i.incrementInvalidBlocks(),new Error(`unable to validate block for CID ${e} from gateway ${i.url}`)}return s}catch(s){if(this.log.error("failed to get block for %c from %s",e,i.url,s),s instanceof Error?o.push(s):o.push(new Error(`unable to fetch raw block for CID ${e} from gateway ${i.url}`)),t.signal?.aborted===!0){this.log.trace("request aborted while fetching raw block for CID %c from gateway %s",e,i.url);break}}}throw new AggregateError(o,`unable to fetch raw block for CID ${e} from any gateway`)}};var Qh=["https://trustless-gateway.link","https://cloudflare-ipfs.com","https://4everland.io"];function hi(r={}){return e=>new Ks(e,r)}var ix=Symbol.for("nodejs.util.inspect.custom"),ep=Object.values(Kr).map(r=>r.decoder).reduce((r,e)=>r.or(e),Kr.identity.decoder),tp=114,wu=36,bu=37,pi=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()})`}[Ol]=!0;toString(){return this.string==null&&(this.string=ke.encode(this.multihash.bytes).slice(1)),this.string}toCID(){return U.createV1(tp,this.multihash)}toBytes(){return this.multihash.bytes}toJSON(){return this.toString()}equals(e){if(e==null)return!1;if(e instanceof Uint8Array)return ce(this.multihash.bytes,e);if(typeof e=="string")return Je(e).equals(this);if(e?.multihash?.bytes!=null)return ce(this.multihash.bytes,e.multihash.bytes);throw new Error("not valid Id")}[ix](){return`PeerId(${this.toString()})`}},uo=class extends pi{type="RSA";publicKey;constructor(e){super({...e,type:"RSA"}),this.publicKey=e.publicKey}},fo=class extends pi{type="Ed25519";publicKey;constructor(e){super({...e,type:"Ed25519"}),this.publicKey=e.multihash.digest}},ho=class extends pi{type="secp256k1";publicKey;constructor(e){super({...e,type:"secp256k1"}),this.publicKey=e.multihash.digest}};function Je(r,e){if(e=e??ep,r.charAt(0)==="1"||r.charAt(0)==="Q"){let t=Ze(ke.decode(`z${r}`));return r.startsWith("12D")?new fo({multihash:t}):r.startsWith("16U")?new ho({multihash:t}):new uo({multihash:t})}return mi(ep.decode(r))}function mi(r){try{let e=Ze(r);if(e.code===Ge.code){if(e.digest.length===wu)return new fo({multihash:e});if(e.digest.length===bu)return new ho({multihash:e})}if(e.code===ae.code)return new uo({multihash:e})}catch{return sx(U.decode(r))}throw new Error("Supplied PeerID CID is invalid")}function sx(r){if(r==null||r.multihash==null||r.version==null||r.version===1&&r.code!==tp)throw new Error("Supplied PeerID CID is invalid");let e=r.multihash;if(e.code===ae.code)return new uo({multihash:r.multihash});if(e.code===Ge.code){if(e.digest.length===wu)return new fo({multihash:r.multihash});if(e.digest.length===bu)return new ho({multihash:r.multihash})}throw new Error("Supplied PeerID CID is invalid")}async function rp(r,e){return r.length===wu?new fo({multihash:Zt(Ge.code,r),privateKey:e}):r.length===bu?new ho({multihash:Zt(Ge.code,r),privateKey:e}):new uo({multihash:await ae.digest(r),publicKey:r,privateKey:e})}var qs=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,o){return this.readAtomically(()=>{let i=0,s=0,a=this.peekChar();if(a===void 0)return;let c=a==="0",u=2**(8*o)-1;for(;;){let l=this.readAtomically(()=>{let f=this.readChar();if(f===void 0)return;let m=Number.parseInt(f,e);if(!Number.isNaN(m))return m});if(l===void 0)break;if(i*=e,i+=l,i>u||(s+=1,t!==void 0&&s>t))return}if(s!==0)return!n&&c&&s>1?void 0:i})}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 o=n*2;if(n<t.length-3){let s=this.readSeparator(":",n,()=>this.readIPv4Addr());if(s!==void 0)return t[o]=s[0],t[o+1]=s[1],t[o+2]=s[2],t[o+3]=s[3],[o+4,!0]}let i=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(i===void 0)return[o,!1];t[o]=i>>8,t[o+1]=i&255}return[t.length,!1]};return this.readAtomically(()=>{let t=new Uint8Array(16),[n,o]=e(t);if(n===16)return t;if(o||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let i=new Uint8Array(14),s=16-(n+2),[a]=e(i.subarray(0,s));return t.set(i.subarray(0,a),16-a),t})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var np=45,ax=15,po=new qs;function xu(r){if(!(r.length>ax))return po.new(r).parseWith(()=>po.readIPv4Addr())}function Eu(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>np))return po.new(r).parseWith(()=>po.readIPv6Addr())}function Gs(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>np))return po.new(r).parseWith(()=>po.readIPAddr())}var rk=parseInt("0xFFFF",16),nk=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function sp(r){return!!xu(r)}function ap(r){return!!Eu(r)}function Ws(r){return!!Gs(r)}var cp=sp,dx=ap,vu=function(r){let e=0;if(r=r.toString().trim(),cp(r)){let t=new Uint8Array(e+4);return r.split(/\./g).forEach(n=>{t[e++]=parseInt(n,10)&255}),t}if(dx(r)){let t=r.split(":",8),n;for(n=0;n<t.length;n++){let i=cp(t[n]),s;i&&(s=vu(t[n]),t[n]=W(s.slice(0,2),"base16")),s!=null&&++n<8&&t.splice(n,0,W(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 i=[n,1];for(n=9-t.length;n>0;n--)i.push("0");t.splice.apply(t,i)}let o=new Uint8Array(e+16);for(n=0;n<t.length;n++){let i=parseInt(t[n],16);o[e++]=i>>8&255,o[e++]=i&255}return o}throw new Error("invalid ip address")},lp=function(r,e=0,t){e=~~e,t=t??r.length-e;let n=new DataView(r.buffer);if(t===4){let o=[];for(let i=0;i<t;i++)o.push(r[e+i]);return o.join(".")}if(t===16){let o=[];for(let i=0;i<t;i+=2)o.push(n.getUint16(e+i).toString(16));return o.join(":").replace(/(^|:)0(:0)*:0(:|$)/,"$1::$3").replace(/:{3,4}/,"::")}return""};var mo={},Su={},px=[[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"]];px.forEach(r=>{let e=mx(...r);Su[e.code]=e,mo[e.name]=e});function mx(r,e,t,n,o){return{code:r,size:e,name:t,resolvable:!!n,path:!!o}}function de(r){if(typeof r=="number"){if(Su[r]!=null)return Su[r];throw new Error(`no protocol with code: ${r}`)}else if(typeof r=="string"){if(mo[r]!=null)return mo[r];throw new Error(`no protocol with name: ${r}`)}throw new Error(`invalid protocol id type: ${typeof r}`)}var Hk=de("ip4"),Mk=de("ip6"),zk=de("ipcidr");function Au(r,e){switch(de(r).code){case 4:case 41:return gx(e);case 42:return dp(e);case 6:case 273:case 33:case 132:return pp(e).toString();case 53:case 54:case 55:case 56:case 400:case 449:case 777:return dp(e);case 421:return Ex(e);case 444:return hp(e);case 445:return hp(e);case 466:return xx(e);default:return W(e,"base16")}}function ku(r,e){switch(de(r).code){case 4:return up(e);case 41:return up(e);case 42:return fp(e);case 6:case 273:case 33:case 132:return Iu(parseInt(e,10));case 53:case 54:case 55:case 56:case 400:case 449:case 777:return fp(e);case 421:return wx(e);case 444:return vx(e);case 445:return Sx(e);case 466:return bx(e);default:return F(e,"base16")}}var _u=Object.values(Kr).map(r=>r.decoder),yx=function(){let r=_u[0].or(_u[1]);return _u.slice(2).forEach(e=>r=r.or(e)),r}();function up(r){if(!Ws(r))throw new Error("invalid ip address");return vu(r)}function gx(r){let e=lp(r,0,r.length);if(e==null)throw new Error("ipBuff is required");if(!Ws(e))throw new Error("invalid ip address");return e}function Iu(r){let e=new ArrayBuffer(2);return new DataView(e).setUint16(0,r),new Uint8Array(e)}function pp(r){return new DataView(r.buffer).getUint16(r.byteOffset)}function fp(r){let e=F(r),t=Uint8Array.from(ao(e.length));return ue([t,e],t.length+e.length)}function dp(r){let e=kn(r);if(r=r.slice(st(e)),r.length!==e)throw new Error("inconsistent lengths");return W(r)}function wx(r){let e;r[0]==="Q"||r[0]==="1"?e=Ze(ke.decode(`z${r}`)).bytes:e=U.parse(r).multihash.bytes;let t=Uint8Array.from(ao(e.length));return ue([t,e],t.length+e.length)}function bx(r){let e=yx.decode(r),t=Uint8Array.from(ao(e.length));return ue([t,e],t.length+e.length)}function xx(r){let e=kn(r),t=r.slice(st(e));if(t.length!==e)throw new Error("inconsistent lengths");return"u"+W(t,"base64url")}function Ex(r){let e=kn(r),t=r.slice(st(e));if(t.length!==e)throw new Error("inconsistent lengths");return W(t,"base58btc")}function vx(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=Fe.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 o=Iu(n);return ue([t,o],t.length+o.length)}function Sx(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=Fe.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 o=Iu(n);return ue([t,o],t.length+o.length)}function hp(r){let e=r.slice(0,r.length-2),t=r.slice(r.length-2),n=W(e,"base32"),o=pp(t);return`${n}:${o}`}function mp(r){r=Bu(r);let e=[],t=[],n=null,o=r.split("/").slice(1);if(o.length===1&&o[0]==="")return{bytes:new Uint8Array,string:"/",tuples:[],stringTuples:[],path:null};for(let i=0;i<o.length;i++){let s=o[i],a=de(s);if(a.size===0){e.push([a.code]),t.push([a.code]);continue}if(i++,i>=o.length)throw gp("invalid address: "+r);if(a.path===!0){n=Bu(o.slice(i).join("/")),e.push([a.code,ku(a.code,n)]),t.push([a.code,n]);break}let c=ku(a.code,o[i]);e.push([a.code,c]),t.push([a.code,Au(a.code,c)])}return{string:yp(t),bytes:Tu(e),tuples:e,stringTuples:t,path:n}}function Ru(r){let e=[],t=[],n=null,o=0;for(;o<r.length;){let i=kn(r,o),s=st(i),a=de(i),c=_x(a,r.slice(o+s));if(c===0){e.push([i]),t.push([i]),o+=s;continue}let u=r.slice(o+s,o+s+c);if(o+=c+s,o>r.length)throw gp("Invalid address Uint8Array: "+W(r,"base16"));e.push([i,u]);let l=Au(i,u);if(t.push([i,l]),a.path===!0){n=l;break}}return{bytes:Uint8Array.from(r),string:yp(t),tuples:e,stringTuples:t,path:n}}function yp(r){let e=[];return r.map(t=>{let n=de(t[0]);return e.push(n.name),t.length>1&&t[1]!=null&&e.push(t[1]),null}),Bu(e.join("/"))}function Tu(r){return ue(r.map(e=>{let t=de(e[0]),n=Uint8Array.from(ao(t.code));return e.length>1&&e[1]!=null&&(n=ue([n,e[1]])),n}))}function _x(r,e){if(r.size>0)return r.size/8;if(r.size===0)return 0;{let t=kn(e instanceof Uint8Array?e:Uint8Array.from(e));return t+st(t)}}function Bu(r){return"/"+r.trim().split("/").filter(e=>e).join("/")}function gp(r){return new Error("Error parsing address: "+r)}var Ax=Symbol.for("nodejs.util.inspect.custom"),Nu=Symbol.for("@multiformats/js-multiaddr/multiaddr"),kx=[de("dns").code,de("dns4").code,de("dns6").code,de("dnsaddr").code],js=class r{bytes;#e;#t;#r;#s;[Nu]=!0;constructor(e){e==null&&(e="");let t;if(e instanceof Uint8Array)t=Ru(e);else if(typeof e=="string"){if(e.length>0&&e.charAt(0)!=="/")throw new Error(`multiaddr "${e}" must start with a "/"`);t=mp(e)}else if(bp(e))t=Ru(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,o,i="",s=de("tcp"),a=de("udp"),c=de("ip4"),u=de("ip6"),l=de("dns6"),f=de("ip6zone");for(let[d,p]of this.stringTuples())d===f.code&&(i=`%${p??""}`),kx.includes(d)&&(t=s.name,o=443,n=`${p??""}${i}`,e=d===l.code?6:4),(d===s.code||d===a.code)&&(t=de(d).name,o=parseInt(p??"")),(d===c.code||d===u.code)&&(t=de(d).name,n=`${p??""}${i}`,e=d===u.code?6:4);if(e==null||t==null||n==null||o==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:o}}protos(){return this.#t.map(([e])=>Object.assign({},de(e)))}protoCodes(){return this.#t.map(([e])=>e)}protoNames(){return this.#t.map(([e])=>de(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(),o=n.lastIndexOf(t);if(o<0)throw new Error(`Address ${this.toString()} does not contain subaddress: ${e.toString()}`);return new r(n.slice(0,o))}decapsulateCode(e){let t=this.tuples();for(let n=t.length-1;n>=0;n--)if(t[n][0]===e)return new r(Tu(t.slice(0,n)));return this}getPeerId(){try{let e=[];this.stringTuples().forEach(([n,o])=>{n===mo.p2p.code&&e.push([n,o]),n===mo["p2p-circuit"].code&&(e=[])});let t=e.pop();if(t?.[1]!=null){let n=t[1];return n[0]==="Q"||n[0]==="1"?W(ke.decode(`z${n}`),"base58btc"):W(U.parse(n).multihash.bytes,"base58btc")}return null}catch{return null}}getPath(){return this.#s}equals(e){return ce(this.bytes,e.bytes)}async resolve(e){let t=this.protos().find(i=>i.resolvable);if(t==null)return[this];let n=wp.get(t.name);if(n==null)throw new P(`no available resolver for ${t.name}`,"ERR_NO_AVAILABLE_RESOLVER");return(await n(this,e)).map(i=>yi(i))}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)}[Ax](){return`Multiaddr(${this.#e})`}};var wp=new Map;function bp(r){return!!r?.[Nu]}function yi(r){return new js(r)}async function*Ys(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 ju={};ve(ju,{Ed25519PrivateKey:()=>Ln,Ed25519PublicKey:()=>bi,generateKeyPair:()=>OE,generateKeyPairFromSeed:()=>Gp,unmarshalEd25519PrivateKey:()=>DE,unmarshalEd25519PublicKey:()=>PE});function Nt(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}function yo(r){if(!Number.isSafeInteger(r)||r<0)throw new Error(`positive integer expected, not ${r}`)}function Ix(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}function go(r,...e){if(!Ix(r))throw new Error("Uint8Array expected");if(e.length>0&&!e.includes(r.length))throw new Error(`Uint8Array expected of length ${e}, not of length=${r.length}`)}function Xs(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");yo(r.outputLen),yo(r.blockLen)}function wo(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 xp(r,e){go(r);let t=e.outputLen;if(r.length<t)throw new Error(`digestInto() expects output buffer of length at least ${t}`)}var Zs=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;var xo=r=>new DataView(r.buffer,r.byteOffset,r.byteLength),Vt=(r,e)=>r<<32-e|r>>>e;var E8=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;var Bx=async()=>{};async function Ep(r,e,t){let n=Date.now();for(let o=0;o<r;o++){t(o);let i=Date.now()-n;i>=0&&i<e||(await Bx(),n+=i)}}function Cu(r){if(typeof r!="string")throw new Error(`utf8ToBytes expected string, got ${typeof r}`);return new Uint8Array(new TextEncoder().encode(r))}function qr(r){return typeof r=="string"&&(r=Cu(r)),go(r),r}function Js(...r){let e=0;for(let n=0;n<r.length;n++){let o=r[n];go(o),e+=o.length}let t=new Uint8Array(e);for(let n=0,o=0;n<r.length;n++){let i=r[n];t.set(i,o),o+=i.length}return t}var bo=class{clone(){return this._cloneInto()}},Rx={}.toString;function vp(r,e){if(e!==void 0&&Rx.call(e)!=="[object Object]")throw new Error("Options should be object or undefined");return Object.assign(r,e)}function Qs(r){let e=n=>r().update(qr(n)).digest(),t=r();return e.outputLen=t.outputLen,e.blockLen=t.blockLen,e.create=()=>r(),e}function Eo(r=32){if(Zs&&typeof Zs.getRandomValues=="function")return Zs.getRandomValues(new Uint8Array(r));throw new Error("crypto.getRandomValues must be defined")}function Tx(r,e,t,n){if(typeof r.setBigUint64=="function")return r.setBigUint64(e,t,n);let o=BigInt(32),i=BigInt(4294967295),s=Number(t>>o&i),a=Number(t&i),c=n?4:0,u=n?0:4;r.setUint32(e+c,s,n),r.setUint32(e+u,a,n)}var Sp=(r,e,t)=>r&e^~r&t,_p=(r,e,t)=>r&e^r&t^e&t,vo=class extends bo{constructor(e,t,n,o){super(),this.blockLen=e,this.outputLen=t,this.padOffset=n,this.isLE=o,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(e),this.view=xo(this.buffer)}update(e){wo(this);let{view:t,buffer:n,blockLen:o}=this;e=qr(e);let i=e.length;for(let s=0;s<i;){let a=Math.min(o-this.pos,i-s);if(a===o){let c=xo(e);for(;o<=i-s;s+=o)this.process(c,s);continue}n.set(e.subarray(s,s+a),this.pos),this.pos+=a,s+=a,this.pos===o&&(this.process(t,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){wo(this),xp(e,this),this.finished=!0;let{buffer:t,view:n,blockLen:o,isLE:i}=this,{pos:s}=this;t[s++]=128,this.buffer.subarray(s).fill(0),this.padOffset>o-s&&(this.process(n,0),s=0);for(let f=s;f<o;f++)t[f]=0;Tx(n,o-8,BigInt(this.length*8),i),this.process(n,0);let a=xo(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 f=0;f<u;f++)a.setUint32(4*f,l[f],i)}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:o,finished:i,destroyed:s,pos:a}=this;return e.length=o,e.pos=a,e.finished=i,e.destroyed=s,o%t&&e.buffer.set(n),e}};var ea=BigInt(4294967295),Lu=BigInt(32);function Ap(r,e=!1){return e?{h:Number(r&ea),l:Number(r>>Lu&ea)}:{h:Number(r>>Lu&ea)|0,l:Number(r&ea)|0}}function Nx(r,e=!1){let t=new Uint32Array(r.length),n=new Uint32Array(r.length);for(let o=0;o<r.length;o++){let{h:i,l:s}=Ap(r[o],e);[t[o],n[o]]=[i,s]}return[t,n]}var Cx=(r,e)=>BigInt(r>>>0)<<Lu|BigInt(e>>>0),Lx=(r,e,t)=>r>>>t,Dx=(r,e,t)=>r<<32-t|e>>>t,Px=(r,e,t)=>r>>>t|e<<32-t,Ox=(r,e,t)=>r<<32-t|e>>>t,Ux=(r,e,t)=>r<<64-t|e>>>t-32,Fx=(r,e,t)=>r>>>t-32|e<<64-t,Vx=(r,e)=>e,Hx=(r,e)=>r,Mx=(r,e,t)=>r<<t|e>>>32-t,zx=(r,e,t)=>e<<t|r>>>32-t,$x=(r,e,t)=>e<<t-32|r>>>64-t,Kx=(r,e,t)=>r<<t-32|e>>>64-t;function qx(r,e,t,n){let o=(e>>>0)+(n>>>0);return{h:r+t+(o/2**32|0)|0,l:o|0}}var Gx=(r,e,t)=>(r>>>0)+(e>>>0)+(t>>>0),Wx=(r,e,t,n)=>e+t+n+(r/2**32|0)|0,jx=(r,e,t,n)=>(r>>>0)+(e>>>0)+(t>>>0)+(n>>>0),Yx=(r,e,t,n,o)=>e+t+n+o+(r/2**32|0)|0,Xx=(r,e,t,n,o)=>(r>>>0)+(e>>>0)+(t>>>0)+(n>>>0)+(o>>>0),Zx=(r,e,t,n,o,i)=>e+t+n+o+i+(r/2**32|0)|0;var Jx={fromBig:Ap,split:Nx,toBig:Cx,shrSH:Lx,shrSL:Dx,rotrSH:Px,rotrSL:Ox,rotrBH:Ux,rotrBL:Fx,rotr32H:Vx,rotr32L:Hx,rotlSH:Mx,rotlSL:zx,rotlBH:$x,rotlBL:Kx,add:qx,add3L:Gx,add3H:Wx,add4L:jx,add4H:Yx,add5H:Zx,add5L:Xx},Y=Jx;var[Qx,eE]=Y.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))),Gr=new Uint32Array(80),Wr=new Uint32Array(80),Du=class extends vo{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:o,Ch:i,Cl:s,Dh:a,Dl:c,Eh:u,El:l,Fh:f,Fl:m,Gh:d,Gl:p,Hh:h,Hl:y}=this;return[e,t,n,o,i,s,a,c,u,l,f,m,d,p,h,y]}set(e,t,n,o,i,s,a,c,u,l,f,m,d,p,h,y){this.Ah=e|0,this.Al=t|0,this.Bh=n|0,this.Bl=o|0,this.Ch=i|0,this.Cl=s|0,this.Dh=a|0,this.Dl=c|0,this.Eh=u|0,this.El=l|0,this.Fh=f|0,this.Fl=m|0,this.Gh=d|0,this.Gl=p|0,this.Hh=h|0,this.Hl=y|0}process(e,t){for(let b=0;b<16;b++,t+=4)Gr[b]=e.getUint32(t),Wr[b]=e.getUint32(t+=4);for(let b=16;b<80;b++){let _=Gr[b-15]|0,A=Wr[b-15]|0,S=Y.rotrSH(_,A,1)^Y.rotrSH(_,A,8)^Y.shrSH(_,A,7),v=Y.rotrSL(_,A,1)^Y.rotrSL(_,A,8)^Y.shrSL(_,A,7),E=Gr[b-2]|0,R=Wr[b-2]|0,N=Y.rotrSH(E,R,19)^Y.rotrBH(E,R,61)^Y.shrSH(E,R,6),T=Y.rotrSL(E,R,19)^Y.rotrBL(E,R,61)^Y.shrSL(E,R,6),H=Y.add4L(v,T,Wr[b-7],Wr[b-16]),D=Y.add4H(H,S,N,Gr[b-7],Gr[b-16]);Gr[b]=D|0,Wr[b]=H|0}let{Ah:n,Al:o,Bh:i,Bl:s,Ch:a,Cl:c,Dh:u,Dl:l,Eh:f,El:m,Fh:d,Fl:p,Gh:h,Gl:y,Hh:g,Hl:x}=this;for(let b=0;b<80;b++){let _=Y.rotrSH(f,m,14)^Y.rotrSH(f,m,18)^Y.rotrBH(f,m,41),A=Y.rotrSL(f,m,14)^Y.rotrSL(f,m,18)^Y.rotrBL(f,m,41),S=f&d^~f&h,v=m&p^~m&y,E=Y.add5L(x,A,v,eE[b],Wr[b]),R=Y.add5H(E,g,_,S,Qx[b],Gr[b]),N=E|0,T=Y.rotrSH(n,o,28)^Y.rotrBH(n,o,34)^Y.rotrBH(n,o,39),H=Y.rotrSL(n,o,28)^Y.rotrBL(n,o,34)^Y.rotrBL(n,o,39),D=n&i^n&a^i&a,Q=o&s^o&c^s&c;g=h|0,x=y|0,h=d|0,y=p|0,d=f|0,p=m|0,{h:f,l:m}=Y.add(u|0,l|0,R|0,N|0),u=a|0,l=c|0,a=i|0,c=s|0,i=n|0,s=o|0;let k=Y.add3L(N,H,Q);n=Y.add3H(k,R,T,D),o=k|0}({h:n,l:o}=Y.add(this.Ah|0,this.Al|0,n|0,o|0)),{h:i,l:s}=Y.add(this.Bh|0,this.Bl|0,i|0,s|0),{h:a,l:c}=Y.add(this.Ch|0,this.Cl|0,a|0,c|0),{h:u,l}=Y.add(this.Dh|0,this.Dl|0,u|0,l|0),{h:f,l:m}=Y.add(this.Eh|0,this.El|0,f|0,m|0),{h:d,l:p}=Y.add(this.Fh|0,this.Fl|0,d|0,p|0),{h,l:y}=Y.add(this.Gh|0,this.Gl|0,h|0,y|0),{h:g,l:x}=Y.add(this.Hh|0,this.Hl|0,g|0,x|0),this.set(n,o,i,s,a,c,u,l,f,m,d,p,h,y,g,x)}roundClean(){Gr.fill(0),Wr.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 So=Qs(()=>new Du);var ra={};ve(ra,{abytes:()=>_o,bitGet:()=>aE,bitLen:()=>sE,bitMask:()=>gi,bitSet:()=>cE,bytesToHex:()=>yr,bytesToNumberBE:()=>gr,bytesToNumberLE:()=>Yr,concatBytes:()=>wr,createHmacDrbg:()=>Uu,ensureBytes:()=>_e,equalBytes:()=>oE,hexToBytes:()=>Tn,hexToNumber:()=>Ou,isBytes:()=>jr,numberToBytesBE:()=>Xr,numberToBytesLE:()=>Nn,numberToHexUnpadded:()=>Rp,numberToVarBytesBE:()=>nE,utf8ToBytes:()=>iE,validateObject:()=>er});var Bp=BigInt(0),ta=BigInt(1),tE=BigInt(2);function jr(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}function _o(r){if(!jr(r))throw new Error("Uint8Array expected")}var rE=Array.from({length:256},(r,e)=>e.toString(16).padStart(2,"0"));function yr(r){_o(r);let e="";for(let t=0;t<r.length;t++)e+=rE[r[t]];return e}function Rp(r){let e=r.toString(16);return e.length&1?`0${e}`:e}function Ou(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return BigInt(r===""?"0":`0x${r}`)}var mr={_0:48,_9:57,_A:65,_F:70,_a:97,_f:102};function kp(r){if(r>=mr._0&&r<=mr._9)return r-mr._0;if(r>=mr._A&&r<=mr._F)return r-(mr._A-10);if(r>=mr._a&&r<=mr._f)return r-(mr._a-10)}function Tn(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 o=0,i=0;o<t;o++,i+=2){let s=kp(r.charCodeAt(i)),a=kp(r.charCodeAt(i+1));if(s===void 0||a===void 0){let c=r[i]+r[i+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+i)}n[o]=s*16+a}return n}function gr(r){return Ou(yr(r))}function Yr(r){return _o(r),Ou(yr(Uint8Array.from(r).reverse()))}function Xr(r,e){return Tn(r.toString(16).padStart(e*2,"0"))}function Nn(r,e){return Xr(r,e).reverse()}function nE(r){return Tn(Rp(r))}function _e(r,e,t){let n;if(typeof e=="string")try{n=Tn(e)}catch(i){throw new Error(`${r} must be valid hex string, got "${e}". Cause: ${i}`)}else if(jr(e))n=Uint8Array.from(e);else throw new Error(`${r} must be hex string or Uint8Array`);let o=n.length;if(typeof t=="number"&&o!==t)throw new Error(`${r} expected ${t} bytes, got ${o}`);return n}function wr(...r){let e=0;for(let n=0;n<r.length;n++){let o=r[n];_o(o),e+=o.length}let t=new Uint8Array(e);for(let n=0,o=0;n<r.length;n++){let i=r[n];t.set(i,o),o+=i.length}return t}function oE(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 iE(r){if(typeof r!="string")throw new Error(`utf8ToBytes expected string, got ${typeof r}`);return new Uint8Array(new TextEncoder().encode(r))}function sE(r){let e;for(e=0;r>Bp;r>>=ta,e+=1);return e}function aE(r,e){return r>>BigInt(e)&ta}function cE(r,e,t){return r|(t?ta:Bp)<<BigInt(e)}var gi=r=>(tE<<BigInt(r-1))-ta,Pu=r=>new Uint8Array(r),Ip=r=>Uint8Array.from(r);function Uu(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=Pu(r),o=Pu(r),i=0,s=()=>{n.fill(1),o.fill(0),i=0},a=(...f)=>t(o,n,...f),c=(f=Pu())=>{o=a(Ip([0]),f),n=a(),f.length!==0&&(o=a(Ip([1]),f),n=a())},u=()=>{if(i++>=1e3)throw new Error("drbg: tried 1000 values");let f=0,m=[];for(;f<e;){n=a();let d=n.slice();m.push(d),f+=n.length}return wr(...m)};return(f,m)=>{s(),c(f);let d;for(;!(d=m(u()));)c();return s(),d}}var lE={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"||jr(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 er(r,e,t={}){let n=(o,i,s)=>{let a=lE[i];if(typeof a!="function")throw new Error(`Invalid validator "${i}", expected function`);let c=r[o];if(!(s&&c===void 0)&&!a(c,r))throw new Error(`Invalid param ${String(o)}=${c} (${typeof c}), expected ${i}`)};for(let[o,i]of Object.entries(e))n(o,i,!1);for(let[o,i]of Object.entries(t))n(o,i,!0);return r}var Le=BigInt(0),he=BigInt(1),Cn=BigInt(2),uE=BigInt(3),Fu=BigInt(4),Tp=BigInt(5),Np=BigInt(8),fE=BigInt(9),dE=BigInt(16);function fe(r,e){let t=r%e;return t>=Le?t:e+t}function hE(r,e,t){if(t<=Le||e<Le)throw new Error("Expected power/modulo > 0");if(t===he)return Le;let n=he;for(;e>Le;)e&he&&(n=n*r%t),r=r*r%t,e>>=he;return n}function pe(r,e,t){let n=r;for(;e-- >Le;)n*=n,n%=t;return n}function na(r,e){if(r===Le||e<=Le)throw new Error(`invert: expected positive integers, got n=${r} mod=${e}`);let t=fe(r,e),n=e,o=Le,i=he,s=he,a=Le;for(;t!==Le;){let u=n/t,l=n%t,f=o-s*u,m=i-a*u;n=t,t=l,o=s,i=a,s=f,a=m}if(n!==he)throw new Error("invert: does not exist");return fe(o,e)}function pE(r){let e=(r-he)/Cn,t,n,o;for(t=r-he,n=0;t%Cn===Le;t/=Cn,n++);for(o=Cn;o<r&&hE(o,e,r)!==r-he;o++);if(n===1){let s=(r+he)/Fu;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 i=(t+he)/Cn;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,o),t),f=a.pow(c,i),m=a.pow(c,t);for(;!a.eql(m,a.ONE);){if(a.eql(m,a.ZERO))return a.ZERO;let d=1;for(let h=a.sqr(m);d<u&&!a.eql(h,a.ONE);d++)h=a.sqr(h);let p=a.pow(l,he<<BigInt(u-d-1));l=a.sqr(p),f=a.mul(f,p),m=a.mul(m,l),u=d}return f}}function mE(r){if(r%Fu===uE){let e=(r+he)/Fu;return function(n,o){let i=n.pow(o,e);if(!n.eql(n.sqr(i),o))throw new Error("Cannot find square root");return i}}if(r%Np===Tp){let e=(r-Tp)/Np;return function(n,o){let i=n.mul(o,Cn),s=n.pow(i,e),a=n.mul(o,s),c=n.mul(n.mul(a,Cn),s),u=n.mul(a,n.sub(c,n.ONE));if(!n.eql(n.sqr(u),o))throw new Error("Cannot find square root");return u}}return r%dE,pE(r)}var Cp=(r,e)=>(fe(r,e)&he)===he,yE=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Vu(r){let e={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},t=yE.reduce((n,o)=>(n[o]="function",n),e);return er(r,t)}function gE(r,e,t){if(t<Le)throw new Error("Expected power > 0");if(t===Le)return r.ONE;if(t===he)return e;let n=r.ONE,o=e;for(;t>Le;)t&he&&(n=r.mul(n,o)),o=r.sqr(o),t>>=he;return n}function wE(r,e){let t=new Array(e.length),n=e.reduce((i,s,a)=>r.is0(s)?i:(t[a]=i,r.mul(i,s)),r.ONE),o=r.inv(n);return e.reduceRight((i,s,a)=>r.is0(s)?i:(t[a]=r.mul(i,t[a]),r.mul(i,s)),o),t}function Hu(r,e){let t=e!==void 0?e:r.toString(2).length,n=Math.ceil(t/8);return{nBitLength:t,nByteLength:n}}function oa(r,e,t=!1,n={}){if(r<=Le)throw new Error(`Expected Field ORDER > 0, got ${r}`);let{nBitLength:o,nByteLength:i}=Hu(r,e);if(i>2048)throw new Error("Field lengths over 2048 bytes are not supported");let s=mE(r),a=Object.freeze({ORDER:r,BITS:o,BYTES:i,MASK:gi(o),ZERO:Le,ONE:he,create:c=>fe(c,r),isValid:c=>{if(typeof c!="bigint")throw new Error(`Invalid field element: expected bigint, got ${typeof c}`);return Le<=c&&c<r},is0:c=>c===Le,isOdd:c=>(c&he)===he,neg:c=>fe(-c,r),eql:(c,u)=>c===u,sqr:c=>fe(c*c,r),add:(c,u)=>fe(c+u,r),sub:(c,u)=>fe(c-u,r),mul:(c,u)=>fe(c*u,r),pow:(c,u)=>gE(a,c,u),div:(c,u)=>fe(c*na(u,r),r),sqrN:c=>c*c,addN:(c,u)=>c+u,subN:(c,u)=>c-u,mulN:(c,u)=>c*u,inv:c=>na(c,r),sqrt:n.sqrt||(c=>s(a,c)),invertBatch:c=>wE(a,c),cmov:(c,u,l)=>l?u:c,toBytes:c=>t?Nn(c,i):Xr(c,i),fromBytes:c=>{if(c.length!==i)throw new Error(`Fp.fromBytes: expected ${i}, got ${c.length}`);return t?Yr(c):gr(c)}});return Object.freeze(a)}function Lp(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 Dp(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 Mu(r){let e=Dp(r);return e+Math.ceil(e/2)}function Pp(r,e,t=!1){let n=r.length,o=Dp(e),i=Mu(e);if(n<16||n<i||n>1024)throw new Error(`expected ${i}-1024 bytes of input, got ${n}`);let s=t?gr(r):Yr(r),a=fe(s,e-he)+he;return t?Nn(a,o):Xr(a,o)}var xE=BigInt(0),zu=BigInt(1);function ia(r,e){let t=(o,i)=>{let s=i.negate();return o?s:i},n=o=>{let i=Math.ceil(e/o)+1,s=2**(o-1);return{windows:i,windowSize:s}};return{constTimeNegate:t,unsafeLadder(o,i){let s=r.ZERO,a=o;for(;i>xE;)i&zu&&(s=s.add(a)),a=a.double(),i>>=zu;return s},precomputeWindow(o,i){let{windows:s,windowSize:a}=n(i),c=[],u=o,l=u;for(let f=0;f<s;f++){l=u,c.push(l);for(let m=1;m<a;m++)l=l.add(u),c.push(l);u=l.double()}return c},wNAF(o,i,s){let{windows:a,windowSize:c}=n(o),u=r.ZERO,l=r.BASE,f=BigInt(2**o-1),m=2**o,d=BigInt(o);for(let p=0;p<a;p++){let h=p*c,y=Number(s&f);s>>=d,y>c&&(y-=m,s+=zu);let g=h,x=h+Math.abs(y)-1,b=p%2!==0,_=y<0;y===0?l=l.add(t(b,i[g])):u=u.add(t(_,i[x]))}return{p:u,f:l}},wNAFCached(o,i,s,a){let c=o._WINDOW_SIZE||1,u=i.get(o);return u||(u=this.precomputeWindow(o,c),c!==1&&i.set(o,a(u))),this.wNAF(c,u,s)}}}function wi(r){return Vu(r.Fp),er(r,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...Hu(r.n,r.nBitLength),...r,p:r.Fp.ORDER})}var Ht=BigInt(0),yt=BigInt(1),sa=BigInt(2),EE=BigInt(8),vE={zip215:!0};function SE(r){let e=wi(r);return er(r,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...e})}function aa(r){let e=SE(r),{Fp:t,n,prehash:o,hash:i,randomBytes:s,nByteLength:a,h:c}=e,u=sa<<BigInt(a*8)-yt,l=t.create,f=e.uvRatio||((C,I)=>{try{return{isValid:!0,value:t.sqrt(C*t.inv(I))}}catch{return{isValid:!1,value:Ht}}}),m=e.adjustScalarBytes||(C=>C),d=e.domain||((C,I,z)=>{if(I.length||z)throw new Error("Contexts/pre-hash are not supported");return C}),p=C=>typeof C=="bigint"&&Ht<C,h=(C,I)=>p(C)&&p(I)&&C<I,y=C=>C===Ht||h(C,u);function g(C,I){if(h(C,I))return C;throw new Error(`Expected valid scalar < ${I}, got ${typeof C} ${C}`)}function x(C){return C===Ht?C:g(C,n)}let b=new Map;function _(C){if(!(C instanceof A))throw new Error("ExtendedPoint expected")}class A{constructor(I,z,K,j){if(this.ex=I,this.ey=z,this.ez=K,this.et=j,!y(I))throw new Error("x required");if(!y(z))throw new Error("y required");if(!y(K))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(I){if(I instanceof A)throw new Error("extended point not allowed");let{x:z,y:K}=I||{};if(!y(z)||!y(K))throw new Error("invalid affine point");return new A(z,K,yt,l(z*K))}static normalizeZ(I){let z=t.invertBatch(I.map(K=>K.ez));return I.map((K,j)=>K.toAffine(z[j])).map(A.fromAffine)}_setWindowSize(I){this._WINDOW_SIZE=I,b.delete(this)}assertValidity(){let{a:I,d:z}=e;if(this.is0())throw new Error("bad point: ZERO");let{ex:K,ey:j,ez:X,et:Z}=this,se=l(K*K),re=l(j*j),oe=l(X*X),Re=l(oe*oe),xe=l(se*I),Oe=l(oe*l(xe+re)),Ue=l(Re+l(z*l(se*re)));if(Oe!==Ue)throw new Error("bad point: equation left != right (1)");let Ce=l(K*j),$e=l(X*Z);if(Ce!==$e)throw new Error("bad point: equation left != right (2)")}equals(I){_(I);let{ex:z,ey:K,ez:j}=this,{ex:X,ey:Z,ez:se}=I,re=l(z*se),oe=l(X*j),Re=l(K*se),xe=l(Z*j);return re===oe&&Re===xe}is0(){return this.equals(A.ZERO)}negate(){return new A(l(-this.ex),this.ey,this.ez,l(-this.et))}double(){let{a:I}=e,{ex:z,ey:K,ez:j}=this,X=l(z*z),Z=l(K*K),se=l(sa*l(j*j)),re=l(I*X),oe=z+K,Re=l(l(oe*oe)-X-Z),xe=re+Z,Oe=xe-se,Ue=re-Z,Ce=l(Re*Oe),$e=l(xe*Ue),dr=l(Re*Ue),vn=l(Oe*xe);return new A(Ce,$e,vn,dr)}add(I){_(I);let{a:z,d:K}=e,{ex:j,ey:X,ez:Z,et:se}=this,{ex:re,ey:oe,ez:Re,et:xe}=I;if(z===BigInt(-1)){let Wd=l((X-j)*(oe+re)),jd=l((X+j)*(oe-re)),Sl=l(jd-Wd);if(Sl===Ht)return this.double();let Yd=l(Z*sa*xe),Xd=l(se*sa*Re),Zd=Xd+Yd,Jd=jd+Wd,Qd=Xd-Yd,Mw=l(Zd*Sl),zw=l(Jd*Qd),$w=l(Zd*Qd),Kw=l(Sl*Jd);return new A(Mw,zw,Kw,$w)}let Oe=l(j*re),Ue=l(X*oe),Ce=l(se*K*xe),$e=l(Z*Re),dr=l((j+X)*(re+oe)-Oe-Ue),vn=$e-Ce,ii=$e+Ce,Gd=l(Ue-z*Oe),Uw=l(dr*vn),Fw=l(ii*Gd),Vw=l(dr*Gd),Hw=l(vn*ii);return new A(Uw,Fw,Hw,Vw)}subtract(I){return this.add(I.negate())}wNAF(I){return E.wNAFCached(this,b,I,A.normalizeZ)}multiply(I){let{p:z,f:K}=this.wNAF(g(I,n));return A.normalizeZ([z,K])[0]}multiplyUnsafe(I){let z=x(I);return z===Ht?v:this.equals(v)||z===yt?this:this.equals(S)?this.wNAF(z).p:E.unsafeLadder(this,z)}isSmallOrder(){return this.multiplyUnsafe(c).is0()}isTorsionFree(){return E.unsafeLadder(this,n).is0()}toAffine(I){let{ex:z,ey:K,ez:j}=this,X=this.is0();I==null&&(I=X?EE:t.inv(j));let Z=l(z*I),se=l(K*I),re=l(j*I);if(X)return{x:Ht,y:yt};if(re!==yt)throw new Error("invZ was invalid");return{x:Z,y:se}}clearCofactor(){let{h:I}=e;return I===yt?this:this.multiplyUnsafe(I)}static fromHex(I,z=!1){let{d:K,a:j}=e,X=t.BYTES;I=_e("pointHex",I,X);let Z=I.slice(),se=I[X-1];Z[X-1]=se&-129;let re=Yr(Z);re===Ht||(z?g(re,u):g(re,t.ORDER));let oe=l(re*re),Re=l(oe-yt),xe=l(K*oe-j),{isValid:Oe,value:Ue}=f(Re,xe);if(!Oe)throw new Error("Point.fromHex: invalid y coordinate");let Ce=(Ue&yt)===yt,$e=(se&128)!==0;if(!z&&Ue===Ht&&$e)throw new Error("Point.fromHex: x=0 and x_0=1");return $e!==Ce&&(Ue=l(-Ue)),A.fromAffine({x:Ue,y:re})}static fromPrivateKey(I){return T(I).point}toRawBytes(){let{x:I,y:z}=this.toAffine(),K=Nn(z,t.BYTES);return K[K.length-1]|=I&yt?128:0,K}toHex(){return yr(this.toRawBytes())}}A.BASE=new A(e.Gx,e.Gy,yt,l(e.Gx*e.Gy)),A.ZERO=new A(Ht,yt,yt,Ht);let{BASE:S,ZERO:v}=A,E=ia(A,a*8);function R(C){return fe(C,n)}function N(C){return R(Yr(C))}function T(C){let I=a;C=_e("private key",C,I);let z=_e("hashed private key",i(C),2*I),K=m(z.slice(0,I)),j=z.slice(I,2*I),X=N(K),Z=S.multiply(X),se=Z.toRawBytes();return{head:K,prefix:j,scalar:X,point:Z,pointBytes:se}}function H(C){return T(C).pointBytes}function D(C=new Uint8Array,...I){let z=wr(...I);return N(i(d(z,_e("context",C),!!o)))}function Q(C,I,z={}){C=_e("message",C),o&&(C=o(C));let{prefix:K,scalar:j,pointBytes:X}=T(I),Z=D(z.context,K,C),se=S.multiply(Z).toRawBytes(),re=D(z.context,se,X,C),oe=R(Z+re*j);x(oe);let Re=wr(se,Nn(oe,t.BYTES));return _e("result",Re,a*2)}let k=vE;function L(C,I,z,K=k){let{context:j,zip215:X}=K,Z=t.BYTES;C=_e("signature",C,2*Z),I=_e("message",I),o&&(I=o(I));let se=Yr(C.slice(Z,2*Z)),re,oe,Re;try{re=A.fromHex(z,X),oe=A.fromHex(C.slice(0,Z),X),Re=S.multiplyUnsafe(se)}catch{return!1}if(!X&&re.isSmallOrder())return!1;let xe=D(j,oe.toRawBytes(),re.toRawBytes(),I);return oe.add(re.multiplyUnsafe(xe)).subtract(Re).clearCofactor().equals(A.ZERO)}return S._setWindowSize(8),{CURVE:e,getPublicKey:H,sign:Q,verify:L,ExtendedPoint:A,utils:{getExtendedPublicKey:T,randomPrivateKey:()=>s(t.BYTES),precompute(C=8,I=A.BASE){return I._setWindowSize(C),I.multiply(BigInt(3)),I}}}}var Ku=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),Op=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),$8=BigInt(0),_E=BigInt(1),$u=BigInt(2),AE=BigInt(5),Up=BigInt(10),kE=BigInt(20),IE=BigInt(40),Fp=BigInt(80);function BE(r){let e=Ku,n=r*r%e*r%e,o=pe(n,$u,e)*n%e,i=pe(o,_E,e)*r%e,s=pe(i,AE,e)*i%e,a=pe(s,Up,e)*s%e,c=pe(a,kE,e)*a%e,u=pe(c,IE,e)*c%e,l=pe(u,Fp,e)*u%e,f=pe(l,Fp,e)*u%e,m=pe(f,Up,e)*s%e;return{pow_p_5_8:pe(m,$u,e)*r%e,b2:n}}function RE(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}function TE(r,e){let t=Ku,n=fe(e*e*e,t),o=fe(n*n*e,t),i=BE(r*o).pow_p_5_8,s=fe(r*n*i,t),a=fe(e*s*s,t),c=s,u=fe(s*Op,t),l=a===r,f=a===fe(-r,t),m=a===fe(-r*Op,t);return l&&(s=c),(f||m)&&(s=u),Cp(s,t)&&(s=fe(-s,t)),{isValid:l||f,value:s}}var br=oa(Ku,void 0,!0),qu={a:BigInt(-1),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:br,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:BigInt(8),Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:So,randomBytes:Eo,adjustScalarBytes:RE,uvRatio:TE},Ao=aa(qu);function Vp(r,e,t){if(e.length>255)throw new Error("Context is too big");return Js(Cu("SigEd25519 no Ed25519 collisions"),new Uint8Array([t?1:0,e.length]),e,r)}var K8=aa({...qu,domain:Vp}),q8=aa({...qu,domain:Vp,prehash:So});var NE=(br.ORDER+BigInt(3))/BigInt(8),G8=br.pow($u,NE),W8=br.sqrt(br.neg(br.ONE)),j8=(br.ORDER-BigInt(5))/BigInt(8),Y8=BigInt(486662);var X8=Lp(br,br.neg(BigInt(486664)));var Z8=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),J8=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),Q8=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),eI=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952");var tI=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");var ko=32,xr=64,ca=32;function Hp(){let r=Ao.utils.randomPrivateKey(),e=Ao.getPublicKey(r);return{privateKey:Kp(r,e),publicKey:e}}function Mp(r){if(r.length!==ca)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=Ao.getPublicKey(e);return{privateKey:Kp(e,t),publicKey:t}}function zp(r,e){let t=r.subarray(0,ca);return Ao.sign(e instanceof Uint8Array?e:e.subarray(),t)}function $p(r,e,t){return Ao.verify(e,t instanceof Uint8Array?t:t.subarray(),r)}function Kp(r,e){let t=new Uint8Array(xr);for(let n=0;n<ca;n++)t[n]=r[n],t[ca+n]=e[n];return t}var Qe={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 Gu={alg:"A128GCM",ext:!0,k:"scm9jmO_4BJAgdwWGVulLg",key_ops:["encrypt","decrypt"],kty:"oct"};function qp(r){let e=r?.algorithm??"AES-GCM",t=r?.keyLength??16,n=r?.nonceLength??12,o=r?.digest??"SHA-256",i=r?.saltLength??16,s=r?.iterations??32767,a=Qe.get();t*=8;async function c(f,m){let d=a.getRandomValues(new Uint8Array(i)),p=a.getRandomValues(new Uint8Array(n)),h={name:e,iv:p};typeof m=="string"&&(m=F(m));let y;if(m.length===0){y=await a.subtle.importKey("jwk",Gu,{name:"AES-GCM"},!0,["encrypt"]);try{let x={name:"PBKDF2",salt:d,iterations:s,hash:{name:o}},b=await a.subtle.importKey("raw",m,{name:"PBKDF2"},!1,["deriveKey"]);y=await a.subtle.deriveKey(x,b,{name:e,length:t},!0,["encrypt"])}catch{y=await a.subtle.importKey("jwk",Gu,{name:"AES-GCM"},!0,["encrypt"])}}else{let x={name:"PBKDF2",salt:d,iterations:s,hash:{name:o}},b=await a.subtle.importKey("raw",m,{name:"PBKDF2"},!1,["deriveKey"]);y=await a.subtle.deriveKey(x,b,{name:e,length:t},!0,["encrypt"])}let g=await a.subtle.encrypt(h,y,f);return ue([d,h.iv,new Uint8Array(g)])}async function u(f,m){let d=f.subarray(0,i),p=f.subarray(i,i+n),h=f.subarray(i+n),y={name:e,iv:p};typeof m=="string"&&(m=F(m));let g;if(m.length===0)try{let b={name:"PBKDF2",salt:d,iterations:s,hash:{name:o}},_=await a.subtle.importKey("raw",m,{name:"PBKDF2"},!1,["deriveKey"]);g=await a.subtle.deriveKey(b,_,{name:e,length:t},!0,["decrypt"])}catch{g=await a.subtle.importKey("jwk",Gu,{name:"AES-GCM"},!0,["decrypt"])}else{let b={name:"PBKDF2",salt:d,iterations:s,hash:{name:o}},_=await a.subtle.importKey("raw",m,{name:"PBKDF2"},!1,["deriveKey"]);g=await a.subtle.deriveKey(b,_,{name:e,length:t},!0,["decrypt"])}let x=await a.subtle.decrypt(y,g,h);return new Uint8Array(x)}return{encrypt:c,decrypt:u}}async function Io(r,e){let n=await qp().encrypt(r,e);return Jt.encode(n)}var me;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.Secp256k1="Secp256k1"})(me||(me={}));var Wu;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.Secp256k1=2]="Secp256k1"})(Wu||(Wu={}));(function(r){r.codec=()=>Rn(Wu)})(me||(me={}));var tr;(function(r){let e;r.codec=()=>(e==null&&(e=Bt((t,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),t.Type!=null&&(n.uint32(8),me.codec().encode(t.Type,n)),t.Data!=null&&(n.uint32(18),n.bytes(t.Data)),o.lengthDelimited!==!1&&n.ldelim()},(t,n)=>{let o={},i=n==null?t.len:t.pos+n;for(;t.pos<i;){let s=t.uint32();switch(s>>>3){case 1:o.Type=me.codec().decode(t);break;case 2:o.Data=t.bytes();break;default:t.skipType(s&7);break}}return o})),e),r.encode=t=>It(t,r.codec()),r.decode=t=>At(t,r.codec())})(tr||(tr={}));var rr;(function(r){let e;r.codec=()=>(e==null&&(e=Bt((t,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),t.Type!=null&&(n.uint32(8),me.codec().encode(t.Type,n)),t.Data!=null&&(n.uint32(18),n.bytes(t.Data)),o.lengthDelimited!==!1&&n.ldelim()},(t,n)=>{let o={},i=n==null?t.len:t.pos+n;for(;t.pos<i;){let s=t.uint32();switch(s>>>3){case 1:o.Type=me.codec().decode(t);break;case 2:o.Data=t.bytes();break;default:t.skipType(s&7);break}}return o})),e),r.encode=t=>It(t,r.codec()),r.decode=t=>At(t,r.codec())})(rr||(rr={}));var bi=class{_key;constructor(e){this._key=Bo(e,ko)}verify(e,t){return $p(this._key,t,e)}marshal(){return this._key}get bytes(){return tr.encode({Type:me.Ed25519,Data:this.marshal()}).subarray()}equals(e){return ce(this.bytes,e.bytes)}hash(){let e=ae.digest(this.bytes);return Nt(e)?e.then(({bytes:t})=>t):e.bytes}},Ln=class{_key;_publicKey;constructor(e,t){this._key=Bo(e,xr),this._publicKey=Bo(t,ko)}sign(e){return zp(this._key,e)}get public(){return new bi(this._publicKey)}marshal(){return this._key}get bytes(){return rr.encode({Type:me.Ed25519,Data:this.marshal()}).subarray()}equals(e){return ce(this.bytes,e.bytes)}async hash(){let e=ae.digest(this.bytes),t;return Nt(e)?{bytes:t}=await e:t=e.bytes,t}async id(){let e=Ge.digest(this.public.bytes);return ke.encode(e.bytes).substring(1)}async export(e,t="libp2p-key"){if(t==="libp2p-key")return Io(this.bytes,e);throw new P(`export format '${t}' is not supported`,"ERR_INVALID_EXPORT_FORMAT")}};function DE(r){if(r.length>xr){r=Bo(r,xr+ko);let n=r.subarray(0,xr),o=r.subarray(xr,r.length);return new Ln(n,o)}r=Bo(r,xr);let e=r.subarray(0,xr),t=r.subarray(ko);return new Ln(e,t)}function PE(r){return r=Bo(r,ko),new bi(r)}async function OE(){let{privateKey:r,publicKey:e}=Hp();return new Ln(r,e)}async function Gp(r){let{privateKey:e,publicKey:t}=Mp(r);return new Ln(e,t)}function Bo(r,e){if(r=Uint8Array.from(r??[]),r.length!==e)throw new P(`Key must be a Uint8Array of length ${e}, got ${r.length}`,"ERR_INVALID_KEY_TYPE");return r}var of={};ve(of,{MAX_RSA_KEY_SIZE:()=>Ni,RsaPrivateKey:()=>Lo,RsaPublicKey:()=>Ti,fromJwk:()=>l3,generateKeyPair:()=>u3,unmarshalRsaPrivateKey:()=>rf,unmarshalRsaPublicKey:()=>c3});function Dn(r){if(isNaN(r)||r<=0)throw new P("random bytes length must be a Number bigger than 0","ERR_INVALID_LENGTH");return Eo(r)}var en={};ve(en,{exportToPem:()=>n3,importFromPem:()=>o3,jwkToPkcs1:()=>QE,jwkToPkix:()=>t3,pkcs1ToJwk:()=>JE,pkixToJwk:()=>e3});var ua=class extends bo{constructor(e,t){super(),this.finished=!1,this.destroyed=!1,Xs(e);let n=qr(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 o=this.blockLen,i=new Uint8Array(o);i.set(n.length>o?e.create().update(n).digest():n);for(let s=0;s<i.length;s++)i[s]^=54;this.iHash.update(i),this.oHash=e.create();for(let s=0;s<i.length;s++)i[s]^=106;this.oHash.update(i),i.fill(0)}update(e){return wo(this),this.iHash.update(e),this}digestInto(e){wo(this),go(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:o,destroyed:i,blockLen:s,outputLen:a}=this;return e=e,e.finished=o,e.destroyed=i,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()}},xi=(r,e,t)=>new ua(r,e).update(t).digest();xi.create=(r,e)=>new ua(r,e);function UE(r,e,t,n){Xs(r);let o=vp({dkLen:32,asyncTick:10},n),{c:i,dkLen:s,asyncTick:a}=o;if(yo(i),yo(s),yo(a),i<1)throw new Error("PBKDF2: iterations (c) should be >= 1");let c=qr(e),u=qr(t),l=new Uint8Array(s),f=xi.create(r,c),m=f._cloneInto().update(u);return{c:i,dkLen:s,asyncTick:a,DK:l,PRF:f,PRFSalt:m}}function FE(r,e,t,n,o){return r.destroy(),e.destroy(),n&&n.destroy(),o.fill(0),t}async function Yu(r,e,t,n){let{c:o,dkLen:i,asyncTick:s,DK:a,PRF:c,PRFSalt:u}=UE(r,e,t,n),l,f=new Uint8Array(4),m=xo(f),d=new Uint8Array(c.outputLen);for(let p=1,h=0;h<i;p++,h+=c.outputLen){let y=a.subarray(h,h+c.outputLen);m.setInt32(0,p,!1),(l=u._cloneInto(l)).update(f).digestInto(d),y.set(d.subarray(0,y.length)),await Ep(o-1,s,()=>{c._cloneInto(l).update(d).digestInto(d);for(let g=0;g<y.length;g++)y[g]^=d[g]})}return FE(c,u,a,l,d)}var te=J(Wp());function Pn(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 Zr(r,e,t=-1){let n=t,o=r,i=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),i=a;else{if(n<a)return new ArrayBuffer(0);c=new ArrayBuffer(n),i=n}let u=new Uint8Array(c);for(let l=a-1;l>=0;l--){let f=Math.pow(2,l*e);u[i-l-1]=Math.floor(o/f),o-=u[i-l-1]*f}return c}s*=Math.pow(2,e)}return new ArrayBuffer(0)}function ha(...r){let e=0,t=0;for(let i of r)e+=i.length;let n=new ArrayBuffer(e),o=new Uint8Array(n);for(let i of r)o.set(i,t),t+=i.length;return o}function Zu(){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=Pn(t,8),o=new ArrayBuffer(this.valueHex.byteLength),i=new Uint8Array(o);for(let a=0;a<this.valueHex.byteLength;a++)i[a]=r[a];return i[0]&=127,Pn(i,8)-n}function jp(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=Zr(s,8,n),c=new Uint8Array(a);return c[0]|=128,a}let o=Zr(e,8,n),i=new Uint8Array(o);if(i[0]&128){let s=o.slice(0),a=new Uint8Array(s);o=new ArrayBuffer(o.byteLength+1),i=new Uint8Array(o);for(let c=0;c<s.byteLength;c++)i[c+1]=a[c];i[0]=0}return o}t*=Math.pow(2,8)}return new ArrayBuffer(0)}function Yp(r,e){if(r.byteLength!==e.byteLength)return!1;let t=new Uint8Array(r),n=new Uint8Array(e);for(let o=0;o<t.length;o++)if(t[o]!==n[o])return!1;return!0}function ct(r,e){let t=r.toString(10);if(e<t.length)return"";let n=e-t.length,o=new Array(n);for(let s=0;s<n;s++)o[s]="0";return o.join("").concat(t)}var RI=Math.log(2);function pa(){if(typeof BigInt>"u")throw new Error("BigInt is not defined. Your environment doesn't implement BigInt.")}function Ju(r){let e=0,t=0;for(let o=0;o<r.length;o++){let i=r[o];e+=i.byteLength}let n=new Uint8Array(e);for(let o=0;o<r.length;o++){let i=r[o];n.set(new Uint8Array(i),t),t+=i.byteLength}return n.buffer}function Ar(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 vi=class{constructor(){this.items=[]}write(e){this.items.push(e)}final(){return Ju(this.items)}},Ei=[new Uint8Array([1])],Xp="0123456789";var No="",zt=new ArrayBuffer(0),Qu=new Uint8Array(0),Si="EndOfContent",Jp="OCTET STRING",Qp="BIT STRING";function kr(r){var e;return e=class extends r{constructor(...n){var o;super(...n);let i=n[0]||{};this.isHexOnly=(o=i.isHexOnly)!==null&&o!==void 0?o:!1,this.valueHexView=i.valueHex?te.BufferSourceConverter.toUint8Array(i.valueHex):Qu}get valueHex(){return this.valueHexView.slice().buffer}set valueHex(n){this.valueHexView=new Uint8Array(n)}fromBER(n,o,i){let s=n instanceof ArrayBuffer?new Uint8Array(n):n;if(!Ar(this,s,o,i))return-1;let a=o+i;return this.valueHexView=s.subarray(o,a),this.valueHexView.length?(this.blockLength=i,a):(this.warnings.push("Zero buffer length"),o)}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",zt)}toJSON(){return{...super.toJSON(),isHexOnly:this.isHexOnly,valueHex:te.Convert.ToHex(this.valueHexView)}}},e.NAME="hexBlock",e}var vr=class{constructor({blockLength:e=0,error:t=No,warnings:n=[],valueBeforeDecode:o=Qu}={}){this.blockLength=e,this.error=t,this.warnings=n,this.valueBeforeDecodeView=te.BufferSourceConverter.toUint8Array(o)}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:te.Convert.ToHex(this.valueBeforeDecodeView)}}};vr.NAME="baseBlock";var je=class extends vr{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'")}};je.NAME="valueBlock";var ma=class extends kr(vr){constructor({idBlock:e={}}={}){var t,n,o,i;super(),e?(this.isHexOnly=(t=e.isHexOnly)!==null&&t!==void 0?t:!1,this.valueHexView=e.valueHex?te.BufferSourceConverter.toUint8Array(e.valueHex):Qu,this.tagClass=(n=e.tagClass)!==null&&n!==void 0?n:-1,this.tagNumber=(o=e.tagNumber)!==null&&o!==void 0?o:-1,this.isConstructed=(i=e.isConstructed)!==null&&i!==void 0?i:!1):(this.tagClass=-1,this.tagNumber=-1,this.isConstructed=!1)}toBER(e=!1){let 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",zt}if(this.isConstructed&&(t|=32),this.tagNumber<31&&!this.isHexOnly){let o=new Uint8Array(1);if(!e){let i=this.tagNumber;i&=31,t|=i,o[0]=t}return o.buffer}if(!this.isHexOnly){let o=Zr(this.tagNumber,7),i=new Uint8Array(o),s=o.byteLength,a=new Uint8Array(s+1);if(a[0]=t|31,!e){for(let c=0;c<s-1;c++)a[c+1]=i[c]|128;a[s]=i[s-1]}return a.buffer}let n=new Uint8Array(this.valueHexView.byteLength+1);if(n[0]=t|31,!e){let o=this.valueHexView;for(let i=0;i<o.length-1;i++)n[i+1]=o[i]|128;n[this.valueHexView.byteLength]=o[o.length-1]}return n.buffer}fromBER(e,t,n){let o=te.BufferSourceConverter.toUint8Array(e);if(!Ar(this,o,t,n))return-1;let i=o.subarray(t,t+n);if(i.length===0)return this.error="Zero buffer length",-1;switch(i[0]&192){case 0:this.tagClass=1;break;case 64:this.tagClass=2;break;case 128:this.tagClass=3;break;case 192:this.tagClass=4;break;default:return this.error="Unknown tag class",-1}this.isConstructed=(i[0]&32)===32,this.isHexOnly=!1;let a=i[0]&31;if(a!==31)this.tagNumber=a,this.blockLength=1;else{let c=1,u=this.valueHexView=new Uint8Array(255),l=255;for(;i[c]&128;){if(u[c-1]=i[c]&127,c++,c>=i.length)return this.error="End of input reached before message was fully decoded",-1;if(c===l){l+=255;let m=new Uint8Array(l);for(let d=0;d<u.length;d++)m[d]=u[d];u=this.valueHexView=new Uint8Array(l)}}this.blockLength=c+1,u[c-1]=i[c]&127;let f=new Uint8Array(c);for(let m=0;m<c;m++)f[m]=u[m];u=this.valueHexView=new Uint8Array(c),u.set(f),this.blockLength<=9?this.tagNumber=Pn(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}}};ma.NAME="identificationBlock";var ya=class extends vr{constructor({lenBlock:e={}}={}){var t,n,o;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=(o=e.length)!==null&&o!==void 0?o:0}fromBER(e,t,n){let o=te.BufferSourceConverter.toUint8Array(e);if(!Ar(this,o,t,n))return-1;let i=o.subarray(t,t+n);if(i.length===0)return this.error="Zero buffer length",-1;if(i[0]===255)return this.error="Length block 0xFF is reserved by standard",-1;if(this.isIndefiniteForm=i[0]===128,this.isIndefiniteForm)return this.blockLength=1,t+this.blockLength;if(this.longFormUsed=!!(i[0]&128),this.longFormUsed===!1)return this.length=i[0],this.blockLength=1,t+this.blockLength;let s=i[0]&127;if(s>8)return this.error="Too big integer",-1;if(s+1>i.length)return this.error="End of input reached before message was fully decoded",-1;let a=t+1,c=o.subarray(a,a+s);return c[s-1]===0&&this.warnings.push("Needlessly long encoded length"),this.length=Pn(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 o=Zr(this.length,8);if(o.byteLength>127)return this.error="Too big length",zt;if(t=new ArrayBuffer(o.byteLength+1),e)return t;let i=new Uint8Array(o);n=new Uint8Array(t),n[0]=o.byteLength|128;for(let s=0;s<o.byteLength;s++)n[s+1]=i[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}}};ya.NAME="lengthBlock";var M={},Ve=class extends vr{constructor({name:e=No,optional:t=!1,primitiveSchema:n,...o}={},i){super(o),this.name=e,this.optional=t,n&&(this.primitiveSchema=n),this.idBlock=new ma(o),this.lenBlock=new ya(o),this.valueBlock=i?new i(o):new je(o)}fromBER(e,t,n){let o=this.valueBlock.fromBER(e,t,this.lenBlock.isIndefiniteForm?n:this.lenBlock.length);return o===-1?(this.error=this.valueBlock.error,o):(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),o)}toBER(e,t){let n=t||new vi;t||e0(this);let o=this.idBlock.toBER(e);if(n.write(o),this.lenBlock.isIndefiniteForm)n.write(new Uint8Array([128]).buffer),this.valueBlock.toBER(e,n),n.write(new ArrayBuffer(2));else{let i=this.valueBlock.toBER(e);this.lenBlock.length=i.byteLength;let s=this.lenBlock.toBER(e);n.write(s),n.write(i)}return t?zt: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():te.Convert.ToHex(this.toBER())}onAsciiEncoding(){return`${this.constructor.NAME} : ${te.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 Yp(t,n)}};Ve.NAME="BaseBlock";function e0(r){if(r instanceof M.Constructed)for(let e of r.valueBlock.value)e0(e)&&(r.lenBlock.isIndefiniteForm=!0);return!!r.lenBlock.isIndefiniteForm}var ga=class extends Ve{constructor({value:e=No,...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 o=this.valueBlock.fromBER(e,t,this.lenBlock.isIndefiniteForm?n:this.lenBlock.length);return o===-1?(this.error=this.valueBlock.error,o):(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),o)}onAsciiEncoding(){return`${this.constructor.NAME} : '${this.valueBlock.value}'`}};ga.NAME="BaseStringBlock";var wa=class extends kr(je){constructor({isHexOnly:e=!0,...t}={}){super(t),this.isHexOnly=e}};wa.NAME="PrimitiveValueBlock";var t0,ba=class extends Ve{constructor(e={}){super(e,wa),this.idBlock.isConstructed=!1}};t0=ba;M.Primitive=t0;ba.NAME="PRIMITIVE";function WE(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 Ja(r,e=0,t=r.length){let n=e,o=new Ve({},je),i=new vr;if(!Ar(i,r,e,t))return o.error=i.error,{offset:-1,result:o};if(!r.subarray(e,e+t).length)return o.error="Zero buffer length",{offset:-1,result:o};let a=o.idBlock.fromBER(r,e,t);if(o.idBlock.warnings.length&&o.warnings.concat(o.idBlock.warnings),a===-1)return o.error=o.idBlock.error,{offset:-1,result:o};if(e=a,t-=o.idBlock.blockLength,a=o.lenBlock.fromBER(r,e,t),o.lenBlock.warnings.length&&o.warnings.concat(o.lenBlock.warnings),a===-1)return o.error=o.lenBlock.error,{offset:-1,result:o};if(e=a,t-=o.lenBlock.blockLength,!o.idBlock.isConstructed&&o.lenBlock.isIndefiniteForm)return o.error="Indefinite length form used for primitive encoding form",{offset:-1,result:o};let c=Ve;switch(o.idBlock.tagClass){case 1:if(o.idBlock.tagNumber>=37&&o.idBlock.isHexOnly===!1)return o.error="UNIVERSAL 37 and upper tags are reserved by ASN.1 standard",{offset:-1,result:o};switch(o.idBlock.tagNumber){case 0:if(o.idBlock.isConstructed&&o.lenBlock.length>0)return o.error="Type [UNIVERSAL 0] is reserved",{offset:-1,result:o};c=M.EndOfContent;break;case 1:c=M.Boolean;break;case 2:c=M.Integer;break;case 3:c=M.BitString;break;case 4:c=M.OctetString;break;case 5:c=M.Null;break;case 6:c=M.ObjectIdentifier;break;case 10:c=M.Enumerated;break;case 12:c=M.Utf8String;break;case 13:c=M.RelativeObjectIdentifier;break;case 14:c=M.TIME;break;case 15:return o.error="[UNIVERSAL 15] is reserved by ASN.1 standard",{offset:-1,result:o};case 16:c=M.Sequence;break;case 17:c=M.Set;break;case 18:c=M.NumericString;break;case 19:c=M.PrintableString;break;case 20:c=M.TeletexString;break;case 21:c=M.VideotexString;break;case 22:c=M.IA5String;break;case 23:c=M.UTCTime;break;case 24:c=M.GeneralizedTime;break;case 25:c=M.GraphicString;break;case 26:c=M.VisibleString;break;case 27:c=M.GeneralString;break;case 28:c=M.UniversalString;break;case 29:c=M.CharacterString;break;case 30:c=M.BmpString;break;case 31:c=M.DATE;break;case 32:c=M.TimeOfDay;break;case 33:c=M.DateTime;break;case 34:c=M.Duration;break;default:{let u=o.idBlock.isConstructed?new M.Constructed:new M.Primitive;u.idBlock=o.idBlock,u.lenBlock=o.lenBlock,u.warnings=o.warnings,o=u}}break;case 2:case 3:case 4:default:c=o.idBlock.isConstructed?M.Constructed:M.Primitive}return o=WE(o,c),a=o.fromBER(r,e,o.lenBlock.isIndefiniteForm?t:o.lenBlock.length),o.valueBeforeDecodeView=r.subarray(n,n+o.blockLength),{offset:a,result:o}}function Co(r){if(!r.byteLength){let e=new Ve({},je);return e.error="Input buffer has zero length",{offset:-1,result:e}}return Ja(te.BufferSourceConverter.toUint8Array(r).slice(),0,r.byteLength)}function jE(r,e){return r?1:e}var nr=class extends je{constructor({value:e=[],isIndefiniteForm:t=!1,...n}={}){super(n),this.value=e,this.isIndefiniteForm=t}fromBER(e,t,n){let o=te.BufferSourceConverter.toUint8Array(e);if(!Ar(this,o,t,n))return-1;if(this.valueBeforeDecodeView=o.subarray(t,t+n),this.valueBeforeDecodeView.length===0)return this.warnings.push("Zero buffer length"),t;let i=t;for(;jE(this.isIndefiniteForm,n)>0;){let s=Ja(o,i,n);if(s.offset===-1)return this.error=s.result.error,this.warnings.concat(s.result.warnings),-1;if(i=s.offset,this.blockLength+=s.result.blockLength,n-=s.result.blockLength,this.value.push(s.result),this.isIndefiniteForm&&s.result.constructor.NAME===Si)break}return this.isIndefiniteForm&&(this.value[this.value.length-1].constructor.NAME===Si?this.value.pop():this.warnings.push("No EndOfContent block encoded")),i}toBER(e,t){let n=t||new vi;for(let o=0;o<this.value.length;o++)this.value[o].toBER(e,n);return t?zt:n.final()}toJSON(){let e={...super.toJSON(),isIndefiniteForm:this.isIndefiniteForm,value:[]};for(let t of this.value)e.value.push(t.toJSON());return e}};nr.NAME="ConstructedValueBlock";var r0,Jr=class extends Ve{constructor(e={}){super(e,nr),this.idBlock.isConstructed=!0}fromBER(e,t,n){this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm;let o=this.valueBlock.fromBER(e,t,this.lenBlock.isIndefiniteForm?n:this.lenBlock.length);return o===-1?(this.error=this.valueBlock.error,o):(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),o)}onAsciiEncoding(){let e=[];for(let n of this.valueBlock.value)e.push(n.toString("ascii").split(`
4
4
  `).map(o=>` ${o}`).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} :`}};Jp=Jr;M.Constructed=Jp;Jr.NAME="CONSTRUCTED";var ba=class extends je{fromBER(e,t,n){return t}toBER(e){return zt}};ba.override="EndOfContentValueBlock";var Qp,xa=class extends Ve{constructor(e={}){super(e,ba),this.idBlock.tagClass=1,this.idBlock.tagNumber=0}};Qp=xa;M.EndOfContent=Qp;xa.NAME=Ei;var e0,Qr=class extends Ve{constructor(e={}){super(e,je),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 o=new Uint8Array(n);o[0]=5,o[1]=0}return t&&t.write(n),n}onAsciiEncoding(){return`${this.constructor.NAME}`}};e0=Qr;M.Null=e0;Qr.NAME="NULL";var Ea=class extends kr(je){constructor({value:e,...t}={}){super(t),t.valueHex?this.valueHexView=te.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 o=te.BufferSourceConverter.toUint8Array(e);return _r(this,o,t,n)?(this.valueHexView=o.subarray(t,t+n),n>1&&this.warnings.push("Boolean value encoded in more then 1 octet"),this.isHexOnly=!0,ju.call(this),this.blockLength=n,t+n):-1}toBER(){return this.valueHexView.slice()}toJSON(){return{...super.toJSON(),value:this.value}}};Ea.NAME="BooleanValueBlock";var t0,va=class extends Ve{constructor(e={}){super(e,Ea),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}`}};t0=va;M.Boolean=t0;va.NAME="BOOLEAN";var Aa=class extends kr(nr){constructor({isConstructed:e=!1,...t}={}){super(t),this.isConstructed=e}fromBER(e,t,n){let o=0;if(this.isConstructed){if(this.isHexOnly=!1,o=nr.prototype.fromBER.call(this,e,t,n),o===-1)return o;for(let i=0;i<this.value.length;i++){let s=this.value[i].constructor.NAME;if(s===Ei){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, OCTET STRING may consists of OCTET STRINGs only",-1}if(s!==jp)return this.error="OCTET STRING may consists of OCTET STRINGs only",-1}}else this.isHexOnly=!0,o=super.fromBER(e,t,n),this.blockLength=n;return o}toBER(e,t){return this.isConstructed?nr.prototype.toBER.call(this,e,t):e?new ArrayBuffer(this.valueHexView.byteLength):this.valueHexView.slice().buffer}toJSON(){return{...super.toJSON(),isConstructed:this.isConstructed}}};Aa.NAME="OctetStringValueBlock";var r0,Ar=class r extends Ve{constructor({idBlock:e={},lenBlock:t={},...n}={}){var o,i;(o=n.isConstructed)!==null&&o!==void 0||(n.isConstructed=!!(!((i=n.value)===null||i===void 0)&&i.length)),super({idBlock:{isConstructed:n.isConstructed,...e},lenBlock:{...t,isIndefiniteForm:!!n.isIndefiniteForm},...n},Aa),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 i=(e instanceof ArrayBuffer?new Uint8Array(e):e).subarray(t,t+n);try{if(i.byteLength){let s=Za(i,0,i.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?Jr.prototype.onAsciiEncoding.call(this):`${this.constructor.NAME} : ${te.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 te.BufferSourceConverter.concat(e)}};r0=Ar;M.OctetString=r0;Ar.NAME=jp;var Sa=class extends kr(nr){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 o=-1;if(this.isConstructed){if(o=nr.prototype.fromBER.call(this,e,t,n),o===-1)return o;for(let a of this.value){let c=a.constructor.NAME;if(c===Ei){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, BIT STRING may consists of BIT STRINGs only",-1}if(c!==Yp)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 o}let i=te.BufferSourceConverter.toUint8Array(e);if(!_r(this,i,t,n))return-1;let s=i.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=Za(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 nr.prototype.toBER.call(this,e,t);if(e)return new ArrayBuffer(this.valueHexView.byteLength+1);if(!this.valueHexView.byteLength)return zt;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}}};Sa.NAME="BitStringValueBlock";var n0,Bo=class extends Ve{constructor({idBlock:e={},lenBlock:t={},...n}={}){var o,i;(o=n.isConstructed)!==null&&o!==void 0||(n.isConstructed=!!(!((i=n.value)===null||i===void 0)&&i.length)),super({idBlock:{isConstructed:n.isConstructed,...e},lenBlock:{...t,isIndefiniteForm:!!n.isIndefiniteForm},...n},Sa),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 Jr.prototype.onAsciiEncoding.call(this);{let e=[],t=this.valueBlock.valueHexView;for(let o of t)e.push(o.toString(2).padStart(8,"0"));let n=e.join("");return`${this.constructor.NAME} : ${n.substring(0,n.length-this.valueBlock.unusedBits)}`}}};n0=Bo;M.BitString=n0;Bo.NAME=Yp;var o0;function ME(r,e){let t=new Uint8Array([0]),n=new Uint8Array(r),o=new Uint8Array(e),i=n.slice(0),s=i.length-1,a=o.slice(0),c=a.length-1,u=0,l=c<s?s:c,f=0;for(let m=l;m>=0;m--,f++){switch(!0){case f<a.length:u=i[s-f]+a[c-f]+t[0];break;default:u=i[s-f]+t[0]}switch(t[0]=u/10,!0){case f>=i.length:i=da(new Uint8Array([u%10]),i);break;default:i[s-f]=u%10}}return t[0]>0&&(i=da(t,i)),i}function Wp(r){if(r>=bi.length)for(let e=bi.length;e<=r;e++){let t=new Uint8Array([0]),n=bi[e-1].slice(0);for(let o=n.length-1;o>=0;o--){let i=new Uint8Array([(n[o]<<1)+t[0]]);t[0]=i[0]/10,n[o]=i[0]%10}t[0]>0&&(n=da(t,n)),bi.push(n)}return bi[r]}function zE(r,e){let t=0,n=new Uint8Array(r),o=new Uint8Array(e),i=n.slice(0),s=i.length-1,a=o.slice(0),c=a.length-1,u,l=0;for(let f=c;f>=0;f--,l++)switch(u=i[s-l]-a[c-l]-t,!0){case u<0:t=1,i[s-l]=u+10;break;default:t=0,i[s-l]=u}if(t>0)for(let f=s-c+1;f>=0;f--,l++)if(u=i[s-l]-t,u<0)t=1,i[s-l]=u+10;else{t=0,i[s-l]=u;break}return i.slice()}var vi=class extends kr(je){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=ju.call(this)))}set valueDec(e){this._valueDec=e,this.isHexOnly=!1,this.valueHexView=new Uint8Array(Kp(e))}get valueDec(){return this._valueDec}fromDER(e,t,n,o=0){let i=this.fromBER(e,t,n);if(i===-1)return i;let s=this.valueHexView;return s[0]===0&&s[1]&128?this.valueHexView=s.subarray(1):o!==0&&s.length<o&&(o-s.length>1&&(o=s.length+1),this.valueHexView=s.subarray(o-s.length)),i}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 o=super.fromBER(e,t,n);return o===-1||this.setValueHex(),o}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,o,i=this.valueHexView,s="",a=!1;for(let c=i.byteLength-1;c>=0;c--){o=i[c];for(let u=0;u<8;u++){if((o&1)===1)switch(n){case e:t=zE(Wp(n),t),s="-";break;default:t=ME(t,Wp(n))}n++,o>>=1}}for(let c=0;c<t.length;c++)t[c]&&(a=!0),a&&(s+=qp.charAt(t[c]));return a===!1&&(s+=qp.charAt(0)),s}};o0=vi;vi.NAME="IntegerValueBlock";Object.defineProperty(o0.prototype,"valueHex",{set:function(r){this.valueHexView=new Uint8Array(r),this.setValueHex()},get:function(){return this.valueHexView.slice().buffer}});var i0,Te=class r extends Ve{constructor(e={}){super(e,vi),this.idBlock.tagClass=1,this.idBlock.tagNumber=2}toBigInt(){return ha(),BigInt(this.valueBlock.toString())}static fromBigInt(e){ha();let t=BigInt(e),n=new xi,o=t.toString(16).replace(/^-/,""),i=new Uint8Array(te.Convert.FromHex(o));if(t<0){let a=new Uint8Array(i.length+(i[0]&128?1:0));a[0]|=128;let u=BigInt(`0x${te.Convert.ToHex(a)}`)+t,l=te.BufferSourceConverter.toUint8Array(te.Convert.FromHex(u.toString(16)));l[0]|=128,n.write(l)}else i[0]&128&&n.write(new Uint8Array([0])),n.write(i);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()}`}};i0=Te;M.Integer=i0;Te.NAME="INTEGER";var s0,_a=class extends Te{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=10}};s0=_a;M.Enumerated=s0;_a.NAME="ENUMERATED";var Ai=class extends kr(je){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 o=te.BufferSourceConverter.toUint8Array(e);if(!_r(this,o,t,n))return-1;let i=o.subarray(t,t+n);this.valueHexView=new Uint8Array(n);for(let a=0;a<n&&(this.valueHexView[a]=i[a]&127,this.blockLength++,!!(i[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,i[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=Dn(this.valueHexView,7):(this.isHexOnly=!0,this.warnings.push("Too big SID for decoding, hex only")),t+this.blockLength)}set valueBigInt(e){ha();let t=BigInt(e).toString(2);for(;t.length%7;)t="0"+t;let n=new Uint8Array(t.length/7);for(let o=0;o<n.length;o++)n[o]=parseInt(t.slice(o*7,o*7+7),2)+(o+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 o=this.valueHexView,i=new Uint8Array(this.blockLength);for(let s=0;s<this.blockLength-1;s++)i[s]=o[s]|128;return i[this.blockLength-1]=o[this.blockLength-1],i.buffer}let t=Zr(this.valueDec,7);if(t.byteLength===0)return this.error="Error during encoding SID value",zt;let n=new Uint8Array(t.byteLength);if(!e){let o=new Uint8Array(t),i=t.byteLength-1;for(let s=0;s<i;s++)n[s]=o[s]|128;n[i]=o[i]}return n}toString(){let e="";if(this.isHexOnly)e=te.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}}};Ai.NAME="sidBlock";var ka=class extends je{constructor({value:e=Ro,...t}={}){super(t),this.value=[],e&&this.fromString(e)}fromBER(e,t,n){let o=t;for(;n>0;){let i=new Ai;if(o=i.fromBER(e,o,n),o===-1)return this.blockLength=0,this.error=i.error,o;this.value.length===0&&(i.isFirstSid=!0),this.blockLength+=i.blockLength,n-=i.blockLength,this.value.push(i)}return o}toBER(e){let t=[];for(let n=0;n<this.value.length;n++){let o=this.value[n].toBER(e);if(o.byteLength===0)return this.error=this.value[n].error,zt;t.push(o)}return Yu(t)}fromString(e){this.value=[];let t=0,n=0,o="",i=!1;do if(n=e.indexOf(".",t),n===-1?o=e.substring(t):o=e.substring(t,n),t=n+1,i){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(o,10);if(isNaN(c))return;s.valueDec=c+a,i=!1}else{let s=new Ai;if(o>Number.MAX_SAFE_INTEGER){ha();let a=BigInt(o);s.valueBigInt=a}else if(s.valueDec=parseInt(o,10),isNaN(s.valueDec))return;this.value.length||(s.isFirstSid=!0,i=!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 o=this.value[n].toString();n!==0&&(e=`${e}.`),t?(o=`{${o}}`,this.value[n].isFirstSid?e=`2.{${o} - 80}`:e+=o):e+=o}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}};ka.NAME="ObjectIdentifierValueBlock";var a0,Mt=class extends Ve{constructor(e={}){super(e,ka),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()}}};a0=Mt;M.ObjectIdentifier=a0;Mt.NAME="OBJECT IDENTIFIER";var Si=class extends kr(vr){constructor({valueDec:e=0,...t}={}){super(t),this.valueDec=e}fromBER(e,t,n){if(n===0)return t;let o=te.BufferSourceConverter.toUint8Array(e);if(!_r(this,o,t,n))return-1;let i=o.subarray(t,t+n);this.valueHexView=new Uint8Array(n);for(let a=0;a<n&&(this.valueHexView[a]=i[a]&127,this.blockLength++,!!(i[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,i[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=Dn(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 o=this.valueHexView,i=new Uint8Array(this.blockLength);for(let s=0;s<this.blockLength-1;s++)i[s]=o[s]|128;return i[this.blockLength-1]=o[this.blockLength-1],i.buffer}let t=Zr(this.valueDec,7);if(t.byteLength===0)return this.error="Error during encoding SID value",zt;let n=new Uint8Array(t.byteLength);if(!e){let o=new Uint8Array(t),i=t.byteLength-1;for(let s=0;s<i;s++)n[s]=o[s]|128;n[i]=o[i]}return n.buffer}toString(){let e="";return this.isHexOnly?e=te.Convert.ToHex(this.valueHexView):e=this.valueDec.toString(),e}toJSON(){return{...super.toJSON(),valueDec:this.valueDec}}};Si.NAME="relativeSidBlock";var Ia=class extends je{constructor({value:e=Ro,...t}={}){super(t),this.value=[],e&&this.fromString(e)}fromBER(e,t,n){let o=t;for(;n>0;){let i=new Si;if(o=i.fromBER(e,o,n),o===-1)return this.blockLength=0,this.error=i.error,o;this.blockLength+=i.blockLength,n-=i.blockLength,this.value.push(i)}return o}toBER(e,t){let n=[];for(let o=0;o<this.value.length;o++){let i=this.value[o].toBER(e);if(i.byteLength===0)return this.error=this.value[o].error,zt;n.push(i)}return Yu(n)}fromString(e){this.value=[];let t=0,n=0,o="";do{n=e.indexOf(".",t),n===-1?o=e.substring(t):o=e.substring(t,n),t=n+1;let i=new Si;if(i.valueDec=parseInt(o,10),isNaN(i.valueDec))return!0;this.value.push(i)}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 o=this.value[n].toString();n!==0&&(e=`${e}.`),t&&(o=`{${o}}`),e+=o}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}};Ia.NAME="RelativeObjectIdentifierValueBlock";var c0,Ba=class extends Ve{constructor(e={}){super(e,Ia),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()}}};c0=Ba;M.RelativeObjectIdentifier=c0;Ba.NAME="RelativeObjectIdentifier";var l0,De=class extends Jr{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=16}};l0=De;M.Sequence=l0;De.NAME="SEQUENCE";var u0,Ra=class extends Jr{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=17}};u0=Ra;M.Set=u0;Ra.NAME="SET";var Ta=class extends kr(je){constructor({...e}={}){super(e),this.isHexOnly=!0,this.value=Ro}toJSON(){return{...super.toJSON(),value:this.value}}};Ta.NAME="StringValueBlock";var Na=class extends Ta{};Na.NAME="SimpleStringValueBlock";var et=class extends ya{constructor({...e}={}){super(e,Na)}fromBuffer(e){this.valueBlock.value=String.fromCharCode.apply(null,te.BufferSourceConverter.toUint8Array(e))}fromString(e){let t=e.length,n=this.valueBlock.valueHexView=new Uint8Array(t);for(let o=0;o<t;o++)n[o]=e.charCodeAt(o);this.valueBlock.value=e}};et.NAME="SIMPLE STRING";var Ca=class extends et{fromBuffer(e){this.valueBlock.valueHexView=te.BufferSourceConverter.toUint8Array(e);try{this.valueBlock.value=te.Convert.ToUtf8String(e)}catch(t){this.warnings.push(`Error during "decodeURIComponent": ${t}, using raw string`),this.valueBlock.value=te.Convert.ToBinary(e)}}fromString(e){this.valueBlock.valueHexView=new Uint8Array(te.Convert.FromUtf8String(e)),this.valueBlock.value=e}};Ca.NAME="Utf8StringValueBlock";var f0,Sr=class extends Ca{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=12}};f0=Sr;M.Utf8String=f0;Sr.NAME="UTF8String";var La=class extends et{fromBuffer(e){this.valueBlock.value=te.Convert.ToUtf16String(e),this.valueBlock.valueHexView=te.BufferSourceConverter.toUint8Array(e)}fromString(e){this.valueBlock.value=e,this.valueBlock.valueHexView=new Uint8Array(te.Convert.FromUtf16String(e))}};La.NAME="BmpStringValueBlock";var d0,Da=class extends La{constructor({...e}={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=30}};d0=Da;M.BmpString=d0;Da.NAME="BMPString";var Pa=class extends et{fromBuffer(e){let t=ArrayBuffer.isView(e)?e.slice().buffer:e.slice(0),n=new Uint8Array(t);for(let o=0;o<n.length;o+=4)n[o]=n[o+3],n[o+1]=n[o+2],n[o+2]=0,n[o+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 o=0;o<t;o++){let i=Zr(e.charCodeAt(o),8),s=new Uint8Array(i);if(s.length>4)continue;let a=4-s.length;for(let c=s.length-1;c>=0;c--)n[o*4+c+a]=s[c]}this.valueBlock.value=e}};Pa.NAME="UniversalStringValueBlock";var h0,Oa=class extends Pa{constructor({...e}={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=28}};h0=Oa;M.UniversalString=h0;Oa.NAME="UniversalString";var p0,Ua=class extends et{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=18}};p0=Ua;M.NumericString=p0;Ua.NAME="NumericString";var m0,Fa=class extends et{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=19}};m0=Fa;M.PrintableString=m0;Fa.NAME="PrintableString";var y0,Va=class extends et{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=20}};y0=Va;M.TeletexString=y0;Va.NAME="TeletexString";var g0,Ha=class extends et{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=21}};g0=Ha;M.VideotexString=g0;Ha.NAME="VideotexString";var w0,Ma=class extends et{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=22}};w0=Ma;M.IA5String=w0;Ma.NAME="IA5String";var b0,za=class extends et{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=25}};b0=za;M.GraphicString=b0;za.NAME="GraphicString";var x0,_i=class extends et{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=26}};x0=_i;M.VisibleString=x0;_i.NAME="VisibleString";var E0,$a=class extends et{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=27}};E0=$a;M.GeneralString=E0;$a.NAME="GeneralString";var v0,Ka=class extends et{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=29}};v0=Ka;M.CharacterString=v0;Ka.NAME="CharacterString";var A0,ki=class extends _i{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 o=0;o<e.length;o++)this.valueBlock.valueHexView[o]=e.charCodeAt(o)}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,te.BufferSourceConverter.toUint8Array(e)))}toBuffer(){let e=this.toString(),t=new ArrayBuffer(e.length),n=new Uint8Array(t);for(let o=0;o<e.length;o++)n[o]=e.charCodeAt(o);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 o=parseInt(n[1],10);o>=50?this.year=1900+o:this.year=2e3+o,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]=ct(this.year<2e3?this.year-1900:this.year-2e3,2),t[1]=ct(this.month,2),t[2]=ct(this.day,2),t[3]=ct(this.hour,2),t[4]=ct(this.minute,2),t[5]=ct(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}}};A0=ki;M.UTCTime=A0;ki.NAME="UTCTime";var S0,Ga=class extends ki{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="",o="",i=0,s,a=0,c=0;if(e[e.length-1]==="Z")n=e.substring(0,e.length-1),t=!0;else{let f=new Number(e[e.length-1]);if(isNaN(f.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 f=1,m=n.indexOf("+"),d="";if(m===-1&&(m=n.indexOf("-"),f=-1),m!==-1){if(d=n.substring(m+1),n=n.substring(0,m),d.length!==2&&d.length!==4)throw new Error("Wrong input string for conversion");let p=parseInt(d.substring(0,2),10);if(isNaN(p.valueOf()))throw new Error("Wrong input string for conversion");if(a=f*p,d.length===4){if(p=parseInt(d.substring(2,4),10),isNaN(p.valueOf()))throw new Error("Wrong input string for conversion");c=f*p}}}let u=n.indexOf(".");if(u===-1&&(u=n.indexOf(",")),u!==-1){let f=new Number(`0${n.substring(u)}`);if(isNaN(f.valueOf()))throw new Error("Wrong input string for conversion");i=f.valueOf(),o=n.substring(0,u)}else o=n;switch(!0){case o.length===8:if(s=/(\d{4})(\d{2})(\d{2})/ig,u!==-1)throw new Error("Wrong input string for conversion");break;case o.length===10:if(s=/(\d{4})(\d{2})(\d{2})(\d{2})/ig,u!==-1){let f=60*i;this.minute=Math.floor(f),f=60*(f-this.minute),this.second=Math.floor(f),f=1e3*(f-this.second),this.millisecond=Math.floor(f)}break;case o.length===12:if(s=/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})/ig,u!==-1){let f=60*i;this.second=Math.floor(f),f=1e3*(f-this.second),this.millisecond=Math.floor(f)}break;case o.length===14:if(s=/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/ig,u!==-1){let f=1e3*i;this.millisecond=Math.floor(f)}break;default:throw new Error("Wrong input string for conversion")}let l=s.exec(o);if(l===null)throw new Error("Wrong input string for conversion");for(let f=1;f<l.length;f++)switch(f){case 1:this.year=parseInt(l[f],10);break;case 2:this.month=parseInt(l[f],10);break;case 3:this.day=parseInt(l[f],10);break;case 4:this.hour=parseInt(l[f],10)+a;break;case 5:this.minute=parseInt(l[f],10)+c;break;case 6:this.second=parseInt(l[f],10);break;default:throw new Error("Wrong input string for conversion")}if(t===!1){let f=new Date(this.year,this.month,this.day,this.hour,this.minute,this.second,this.millisecond);this.year=f.getUTCFullYear(),this.month=f.getUTCMonth(),this.day=f.getUTCDay(),this.hour=f.getUTCHours(),this.minute=f.getUTCMinutes(),this.second=f.getUTCSeconds(),this.millisecond=f.getUTCMilliseconds()}}toString(e="iso"){if(e==="iso"){let t=[];return t.push(ct(this.year,4)),t.push(ct(this.month,2)),t.push(ct(this.day,2)),t.push(ct(this.hour,2)),t.push(ct(this.minute,2)),t.push(ct(this.second,2)),this.millisecond!==0&&(t.push("."),t.push(ct(this.millisecond,3))),t.push("Z"),t.join("")}return super.toString(e)}toJSON(){return{...super.toJSON(),millisecond:this.millisecond}}};S0=Ga;M.GeneralizedTime=S0;Ga.NAME="GeneralizedTime";var _0,qa=class extends Sr{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=31}};_0=qa;M.DATE=_0;qa.NAME="DATE";var k0,Wa=class extends Sr{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=32}};k0=Wa;M.TimeOfDay=k0;Wa.NAME="TimeOfDay";var I0,ja=class extends Sr{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=33}};I0=ja;M.DateTime=I0;ja.NAME="DateTime";var B0,Ya=class extends Sr{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=34}};B0=Ya;M.Duration=B0;Ya.NAME="Duration";var R0,Xa=class extends Sr{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=14}};R0=Xa;M.TIME=R0;Xa.NAME="TIME";function KE(r){let{result:e}=To(r),t=e.valueBlock.value;return{n:W(or(t[1].toBigInt()),"base64url"),e:W(or(t[2].toBigInt()),"base64url"),d:W(or(t[3].toBigInt()),"base64url"),p:W(or(t[4].toBigInt()),"base64url"),q:W(or(t[5].toBigInt()),"base64url"),dp:W(or(t[6].toBigInt()),"base64url"),dq:W(or(t[7].toBigInt()),"base64url"),qi:W(or(t[8].toBigInt()),"base64url"),kty:"RSA",alg:"RS256"}}function GE(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 P("JWK was missing components","ERR_INVALID_PARAMETERS");let t=new De({value:[new Te({value:0}),Te.fromBigInt(ir(F(r.n,"base64url"))),Te.fromBigInt(ir(F(r.e,"base64url"))),Te.fromBigInt(ir(F(r.d,"base64url"))),Te.fromBigInt(ir(F(r.p,"base64url"))),Te.fromBigInt(ir(F(r.q,"base64url"))),Te.fromBigInt(ir(F(r.dp,"base64url"))),Te.fromBigInt(ir(F(r.dq,"base64url"))),Te.fromBigInt(ir(F(r.qi,"base64url")))]}).toBER();return new Uint8Array(t,0,t.byteLength)}function qE(r){let{result:e}=To(r),t=e.valueBlock.value[1].valueBlock.value[0].valueBlock.value;return{kty:"RSA",n:W(or(t[0].toBigInt()),"base64url"),e:W(or(t[1].toBigInt()),"base64url")}}function WE(r){if(r.n==null||r.e==null)throw new P("JWK was missing components","ERR_INVALID_PARAMETERS");let t=new De({value:[new De({value:[new Mt({value:"1.2.840.113549.1.1.1"}),new Qr]}),new Bo({valueHex:new De({value:[Te.fromBigInt(ir(F(r.n,"base64url"))),Te.fromBigInt(ir(F(r.e,"base64url")))]}).toBER()})]}).toBER();return new Uint8Array(t,0,t.byteLength)}function or(r){let e=r.toString(16);e.length%2>0&&(e=`0${e}`);let t=e.length/2,n=new Uint8Array(t),o=0,i=0;for(;o<t;)n[o]=parseInt(e.slice(i,i+2),16),o+=1,i+=2;return n}function ir(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 jE=16,Zu=32,Ju=1e4;async function YE(r,e){let t=Qe.get(),o=new De({value:[new Te({value:0}),new De({value:[new Mt({value:"1.2.840.113549.1.1.1"}),new Qr]}),new Ar({valueHex:r.marshal()})]}).toBER(),i=new Uint8Array(o,0,o.byteLength),s=Ln(jE),a=await qu(Eo,e,s,{c:Ju,dkLen:Zu}),c=Ln(16),u=await t.subtle.importKey("raw",a,"AES-CBC",!1,["encrypt"]),l=await t.subtle.encrypt({name:"AES-CBC",iv:c},u,i),f=new De({value:[new Ar({valueHex:s}),new Te({value:Ju}),new Te({value:Zu}),new De({value:[new Mt({value:"1.2.840.113549.2.11"}),new Qr]})]}),m=new De({value:[new Mt({value:"1.2.840.113549.1.5.13"}),new De({value:[new De({value:[new Mt({value:"1.2.840.113549.1.5.12"}),f]}),new De({value:[new Mt({value:"2.16.840.1.101.3.4.1.42"}),new Ar({valueHex:c})]})]})]}),p=new De({value:[m,new Ar({valueHex:l})]}).toBER(),h=new Uint8Array(p,0,p.byteLength);return["-----BEGIN ENCRYPTED PRIVATE KEY-----",...W(h,"base64pad").split(/(.{64})/).filter(Boolean),"-----END ENCRYPTED PRIVATE KEY-----"].join(`
8
- `)}async function XE(r,e){let t=Qe.get(),n;if(r.includes("-----BEGIN ENCRYPTED PRIVATE KEY-----")){let o=F(r.replace("-----BEGIN ENCRYPTED PRIVATE KEY-----","").replace("-----END ENCRYPTED PRIVATE KEY-----","").replace(/\n/g,"").trim(),"base64pad"),{result:i}=To(o),{iv:s,salt:a,iterations:c,keySize:u,cipherText:l}=ZE(i),f=await qu(Eo,e,a,{c,dkLen:u}),m=await t.subtle.importKey("raw",f,"AES-CBC",!1,["decrypt"]),d=Ii(await t.subtle.decrypt({name:"AES-CBC",iv:s},m,l)),{result:p}=To(d);n=T0(p)}else if(r.includes("-----BEGIN PRIVATE KEY-----")){let o=F(r.replace("-----BEGIN PRIVATE KEY-----","").replace("-----END PRIVATE KEY-----","").replace(/\n/g,"").trim(),"base64pad"),{result:i}=To(o);n=T0(i)}else throw new P("Could not parse private key from PEM data","ERR_INVALID_PARAMETERS");return Qu(n)}function ZE(r){let e=r.valueBlock.value[0];if(e.valueBlock.value[0].toString()!=="OBJECT IDENTIFIER : 1.2.840.113549.1.5.13")throw new P("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 P("Only pkcs5PBKDF2 key derivation functions are supported","ERR_INVALID_PARAMS");let i=n.valueBlock.value[1],s=Ii(i.valueBlock.value[0].getValue()),a=Ju,c=Zu;if(i.valueBlock.value.length===3)a=Number(i.valueBlock.value[1].toBigInt()),c=Number(i.valueBlock.value[2].toBigInt());else if(i.valueBlock.value.length===2)throw new P("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 P("Only AES-CBC encryption schemes are supported","ERR_INVALID_PARAMS")}}}}let f=Ii(u.valueBlock.value[1].getValue());return{cipherText:Ii(r.valueBlock.value[1].getValue()),salt:s,iterations:a,keySize:c,iv:f}}function T0(r){return Ii(r.valueBlock.value[2].getValue())}function Ii(r){return new Uint8Array(r,0,r.byteLength)}async function N0(r){let e=await Qe.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 D0(e);return{privateKey:t[0],publicKey:t[1]}}async function ef(r){let t=[await Qe.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!0,["sign"]),await JE(r)],n=await D0({privateKey:t[0],publicKey:t[1]});return{privateKey:n[0],publicKey:n[1]}}async function C0(r,e){let t=await Qe.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]),n=await Qe.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},t,e instanceof Uint8Array?e:e.subarray());return new Uint8Array(n,0,n.byteLength)}async function L0(r,e,t){let n=await Qe.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);return Qe.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},n,e,t instanceof Uint8Array?t:t.subarray())}async function D0(r){if(r.privateKey==null||r.publicKey==null)throw new P("Private and public key are required","ERR_INVALID_PARAMETERS");return Promise.all([Qe.get().subtle.exportKey("jwk",r.privateKey),Qe.get().subtle.exportKey("jwk",r.publicKey)])}async function JE(r){return Qe.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 Ja(r){if(r.kty!=="RSA")throw new P("invalid key type","ERR_INVALID_KEY_TYPE");if(r.n==null)throw new P("invalid key modulus","ERR_INVALID_KEY_MODULUS");return F(r.n,"base64url").length*8}var Ri=8192,Bi=class{_key;constructor(e){this._key=e}verify(e,t){return L0(this._key,t,e)}marshal(){return en.jwkToPkix(this._key)}get bytes(){return tr.encode({Type:me.RSA,Data:this.marshal()}).subarray()}equals(e){return ce(this.bytes,e.bytes)}hash(){let e=ae.digest(this.bytes);return Nt(e)?e.then(({bytes:t})=>t):e.bytes}},No=class{_key;_publicKey;constructor(e,t){this._key=e,this._publicKey=t}genSecret(){return Ln(16)}sign(e){return C0(this._key,e)}get public(){if(this._publicKey==null)throw new P("public key not provided","ERR_PUBKEY_NOT_PROVIDED");return new Bi(this._publicKey)}marshal(){return en.jwkToPkcs1(this._key)}get bytes(){return rr.encode({Type:me.RSA,Data:this.marshal()}).subarray()}equals(e){return ce(this.bytes,e.bytes)}hash(){let e=ae.digest(this.bytes);return Nt(e)?e.then(({bytes:t})=>t):e.bytes}async id(){let e=await this.public.hash();return W(e,"base58btc")}async export(e,t="pkcs-8"){if(t==="pkcs-8")return en.exportToPem(this,e);if(t==="libp2p-key")return _o(this.bytes,e);throw new P(`export format '${t}' is not supported`,"ERR_INVALID_EXPORT_FORMAT")}};async function Qu(r){let e=en.pkcs1ToJwk(r);if(Ja(e)>Ri)throw new P("key size is too large","ERR_KEY_SIZE_TOO_LARGE");let t=await ef(e);return new No(t.privateKey,t.publicKey)}function e3(r){let e=en.pkixToJwk(r);if(Ja(e)>Ri)throw new P("key size is too large","ERR_KEY_SIZE_TOO_LARGE");return new Bi(e)}async function t3(r){if(Ja(r)>Ri)throw new P("key size is too large","ERR_KEY_SIZE_TOO_LARGE");let e=await ef(r);return new No(e.privateKey,e.publicKey)}async function r3(r){if(r>Ri)throw new P("key size is too large","ERR_KEY_SIZE_TOO_LARGE");let e=await N0(r);return new No(e.privateKey,e.publicKey)}var af={};ve(af,{Secp256k1PrivateKey:()=>Ni,Secp256k1PublicKey:()=>Ti,generateKeyPair:()=>m3,unmarshalSecp256k1PrivateKey:()=>h3,unmarshalSecp256k1PublicKey:()=>p3});var n3=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]),tn=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),rn=new Uint32Array(64),rf=class extends xo{constructor(){super(64,32,8,!1),this.A=tn[0]|0,this.B=tn[1]|0,this.C=tn[2]|0,this.D=tn[3]|0,this.E=tn[4]|0,this.F=tn[5]|0,this.G=tn[6]|0,this.H=tn[7]|0}get(){let{A:e,B:t,C:n,D:o,E:i,F:s,G:a,H:c}=this;return[e,t,n,o,i,s,a,c]}set(e,t,n,o,i,s,a,c){this.A=e|0,this.B=t|0,this.C=n|0,this.D=o|0,this.E=i|0,this.F=s|0,this.G=a|0,this.H=c|0}process(e,t){for(let f=0;f<16;f++,t+=4)rn[f]=e.getUint32(t,!1);for(let f=16;f<64;f++){let m=rn[f-15],d=rn[f-2],p=Vt(m,7)^Vt(m,18)^m>>>3,h=Vt(d,17)^Vt(d,19)^d>>>10;rn[f]=h+rn[f-7]+p+rn[f-16]|0}let{A:n,B:o,C:i,D:s,E:a,F:c,G:u,H:l}=this;for(let f=0;f<64;f++){let m=Vt(a,6)^Vt(a,11)^Vt(a,25),d=l+m+bp(a,c,u)+n3[f]+rn[f]|0,h=(Vt(n,2)^Vt(n,13)^Vt(n,22))+xp(n,o,i)|0;l=u,u=c,c=a,a=s+d|0,s=i,i=o,o=n,n=d+h|0}n=n+this.A|0,o=o+this.B|0,i=i+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,o,i,s,a,c,u,l)}roundClean(){rn.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};var P0=Js(()=>new rf);function o3(r){let e=yi(r);er(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:o}=e;if(t){if(!n.eql(o,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:i3,hexToBytes:s3}=ta,Pn={Err:class extends Error{constructor(e=""){super(e)}},_parseInt(r){let{Err:e}=Pn;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:i3(n),l:r.subarray(t+2)}},toSig(r){let{Err:e}=Pn,t=typeof r=="string"?s3(r):r;vo(t);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:o,l:i}=Pn._parseInt(t.subarray(2)),{d:s,l:a}=Pn._parseInt(i);if(a.length)throw new e("Invalid signature: left bytes after parsing");return{r:o,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)),o=e(t(r.r)),i=n.length/2,s=o.length/2,a=t(i),c=t(s);return`30${t(s+i+4)}02${c}${o}02${a}${n}`}},Ir=BigInt(0),Lt=BigInt(1),qI=BigInt(2),O0=BigInt(3),WI=BigInt(4);function a3(r){let e=o3(r),{Fp:t}=e,n=e.toBytes||((p,h,g)=>{let y=h.toAffine();return wr(Uint8Array.from([4]),t.toBytes(y.x),t.toBytes(y.y))}),o=e.fromBytes||(p=>{let h=p.subarray(1),g=t.fromBytes(h.subarray(0,t.BYTES)),y=t.fromBytes(h.subarray(t.BYTES,2*t.BYTES));return{x:g,y}});function i(p){let{a:h,b:g}=e,y=t.sqr(p),x=t.mul(y,p);return t.add(t.add(x,t.mul(p,h)),g)}if(!t.eql(t.sqr(e.Gy),i(e.Gx)))throw new Error("bad generator point: equation left != right");function s(p){return typeof p=="bigint"&&Ir<p&&p<e.n}function a(p){if(!s(p))throw new Error("Expected valid bigint: 0 < bigint < curve.n")}function c(p){let{allowedPrivateKeyLengths:h,nByteLength:g,wrapPrivateKey:y,n:x}=e;if(h&&typeof p!="bigint"){if(jr(p)&&(p=yr(p)),typeof p!="string"||!h.includes(p.length))throw new Error("Invalid key");p=p.padStart(g*2,"0")}let b;try{b=typeof p=="bigint"?p:gr(Se("private key",p,g))}catch{throw new Error(`private key must be ${g} bytes, hex or bigint, not ${typeof p}`)}return y&&(b=fe(b,x)),a(b),b}let u=new Map;function l(p){if(!(p instanceof f))throw new Error("ProjectivePoint expected")}class f{constructor(h,g,y){if(this.px=h,this.py=g,this.pz=y,h==null||!t.isValid(h))throw new Error("x required");if(g==null||!t.isValid(g))throw new Error("y required");if(y==null||!t.isValid(y))throw new Error("z required")}static fromAffine(h){let{x:g,y}=h||{};if(!h||!t.isValid(g)||!t.isValid(y))throw new Error("invalid affine point");if(h instanceof f)throw new Error("projective point not allowed");let x=b=>t.eql(b,t.ZERO);return x(g)&&x(y)?f.ZERO:new f(g,y,t.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(h){let g=t.invertBatch(h.map(y=>y.pz));return h.map((y,x)=>y.toAffine(g[x])).map(f.fromAffine)}static fromHex(h){let g=f.fromAffine(o(Se("pointHex",h)));return g.assertValidity(),g}static fromPrivateKey(h){return f.BASE.multiply(c(h))}_setWindowSize(h){this._WINDOW_SIZE=h,u.delete(this)}assertValidity(){if(this.is0()){if(e.allowInfinityPoint&&!t.is0(this.py))return;throw new Error("bad point: ZERO")}let{x:h,y:g}=this.toAffine();if(!t.isValid(h)||!t.isValid(g))throw new Error("bad point: x or y not FE");let y=t.sqr(g),x=i(h);if(!t.eql(y,x))throw new Error("bad point: equation left != right");if(!this.isTorsionFree())throw new Error("bad point: not in prime-order subgroup")}hasEvenY(){let{y:h}=this.toAffine();if(t.isOdd)return!t.isOdd(h);throw new Error("Field doesn't support isOdd")}equals(h){l(h);let{px:g,py:y,pz:x}=this,{px:b,py:S,pz:_}=h,A=t.eql(t.mul(g,_),t.mul(b,x)),v=t.eql(t.mul(y,_),t.mul(S,x));return A&&v}negate(){return new f(this.px,t.neg(this.py),this.pz)}double(){let{a:h,b:g}=e,y=t.mul(g,O0),{px:x,py:b,pz:S}=this,_=t.ZERO,A=t.ZERO,v=t.ZERO,E=t.mul(x,x),R=t.mul(b,b),N=t.mul(S,S),T=t.mul(x,b);return T=t.add(T,T),v=t.mul(x,S),v=t.add(v,v),_=t.mul(h,v),A=t.mul(y,N),A=t.add(_,A),_=t.sub(R,A),A=t.add(R,A),A=t.mul(_,A),_=t.mul(T,_),v=t.mul(y,v),N=t.mul(h,N),T=t.sub(E,N),T=t.mul(h,T),T=t.add(T,v),v=t.add(E,E),E=t.add(v,E),E=t.add(E,N),E=t.mul(E,T),A=t.add(A,E),N=t.mul(b,S),N=t.add(N,N),E=t.mul(N,T),_=t.sub(_,E),v=t.mul(N,R),v=t.add(v,v),v=t.add(v,v),new f(_,A,v)}add(h){l(h);let{px:g,py:y,pz:x}=this,{px:b,py:S,pz:_}=h,A=t.ZERO,v=t.ZERO,E=t.ZERO,R=e.a,N=t.mul(e.b,O0),T=t.mul(g,b),H=t.mul(y,S),D=t.mul(x,_),Q=t.add(g,y),k=t.add(b,S);Q=t.mul(Q,k),k=t.add(T,H),Q=t.sub(Q,k),k=t.add(g,x);let L=t.add(b,_);return k=t.mul(k,L),L=t.add(T,D),k=t.sub(k,L),L=t.add(y,x),A=t.add(S,_),L=t.mul(L,A),A=t.add(H,D),L=t.sub(L,A),E=t.mul(R,k),A=t.mul(N,D),E=t.add(A,E),A=t.sub(H,E),E=t.add(H,E),v=t.mul(A,E),H=t.add(T,T),H=t.add(H,T),D=t.mul(R,D),k=t.mul(N,k),H=t.add(H,D),D=t.sub(T,D),D=t.mul(R,D),k=t.add(k,D),T=t.mul(H,k),v=t.add(v,T),T=t.mul(L,k),A=t.mul(Q,A),A=t.sub(A,T),T=t.mul(Q,H),E=t.mul(L,E),E=t.add(E,T),new f(A,v,E)}subtract(h){return this.add(h.negate())}is0(){return this.equals(f.ZERO)}wNAF(h){return d.wNAFCached(this,u,h,g=>{let y=t.invertBatch(g.map(x=>x.pz));return g.map((x,b)=>x.toAffine(y[b])).map(f.fromAffine)})}multiplyUnsafe(h){let g=f.ZERO;if(h===Ir)return g;if(a(h),h===Lt)return this;let{endo:y}=e;if(!y)return d.unsafeLadder(this,h);let{k1neg:x,k1:b,k2neg:S,k2:_}=y.splitScalar(h),A=g,v=g,E=this;for(;b>Ir||_>Ir;)b&Lt&&(A=A.add(E)),_&Lt&&(v=v.add(E)),E=E.double(),b>>=Lt,_>>=Lt;return x&&(A=A.negate()),S&&(v=v.negate()),v=new f(t.mul(v.px,y.beta),v.py,v.pz),A.add(v)}multiply(h){a(h);let g=h,y,x,{endo:b}=e;if(b){let{k1neg:S,k1:_,k2neg:A,k2:v}=b.splitScalar(g),{p:E,f:R}=this.wNAF(_),{p:N,f:T}=this.wNAF(v);E=d.constTimeNegate(S,E),N=d.constTimeNegate(A,N),N=new f(t.mul(N.px,b.beta),N.py,N.pz),y=E.add(N),x=R.add(T)}else{let{p:S,f:_}=this.wNAF(g);y=S,x=_}return f.normalizeZ([y,x])[0]}multiplyAndAddUnsafe(h,g,y){let x=f.BASE,b=(_,A)=>A===Ir||A===Lt||!_.equals(x)?_.multiplyUnsafe(A):_.multiply(A),S=b(this,g).add(b(h,y));return S.is0()?void 0:S}toAffine(h){let{px:g,py:y,pz:x}=this,b=this.is0();h==null&&(h=b?t.ONE:t.inv(x));let S=t.mul(g,h),_=t.mul(y,h),A=t.mul(x,h);if(b)return{x:t.ZERO,y:t.ZERO};if(!t.eql(A,t.ONE))throw new Error("invZ was invalid");return{x:S,y:_}}isTorsionFree(){let{h,isTorsionFree:g}=e;if(h===Lt)return!0;if(g)return g(f,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){let{h,clearCofactor:g}=e;return h===Lt?this:g?g(f,this):this.multiplyUnsafe(e.h)}toRawBytes(h=!0){return this.assertValidity(),n(f,this,h)}toHex(h=!0){return yr(this.toRawBytes(h))}}f.BASE=new f(e.Gx,e.Gy,t.ONE),f.ZERO=new f(t.ZERO,t.ONE,t.ZERO);let m=e.nBitLength,d=oa(f,e.endo?Math.ceil(m/2):m);return{CURVE:e,ProjectivePoint:f,normPrivateKeyToScalar:c,weierstrassEquation:i,isWithinCurveOrder:s}}function c3(r){let e=yi(r);return er(e,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...e})}function U0(r){let e=c3(r),{Fp:t,n}=e,o=t.BYTES+1,i=2*t.BYTES+1;function s(k){return Ir<k&&k<t.ORDER}function a(k){return fe(k,n)}function c(k){return ra(k,n)}let{ProjectivePoint:u,normPrivateKeyToScalar:l,weierstrassEquation:f,isWithinCurveOrder:m}=a3({...e,toBytes(k,L,q){let C=L.toAffine(),I=t.toBytes(C.x),z=wr;return q?z(Uint8Array.from([L.hasEvenY()?2:3]),I):z(Uint8Array.from([4]),I,t.toBytes(C.y))},fromBytes(k){let L=k.length,q=k[0],C=k.subarray(1);if(L===o&&(q===2||q===3)){let I=gr(C);if(!s(I))throw new Error("Point is not on curve");let z=f(I),K;try{K=t.sqrt(z)}catch(Z){let se=Z instanceof Error?": "+Z.message:"";throw new Error("Point is not on curve"+se)}let j=(K&Lt)===Lt;return(q&1)===1!==j&&(K=t.neg(K)),{x:I,y:K}}else if(L===i&&q===4){let I=t.fromBytes(C.subarray(0,t.BYTES)),z=t.fromBytes(C.subarray(t.BYTES,2*t.BYTES));return{x:I,y:z}}else throw new Error(`Point of length ${L} was invalid. Expected ${o} compressed bytes or ${i} uncompressed bytes`)}}),d=k=>yr(Xr(k,e.nByteLength));function p(k){let L=n>>Lt;return k>L}function h(k){return p(k)?a(-k):k}let g=(k,L,q)=>gr(k.slice(L,q));class y{constructor(L,q,C){this.r=L,this.s=q,this.recovery=C,this.assertValidity()}static fromCompact(L){let q=e.nByteLength;return L=Se("compactSignature",L,q*2),new y(g(L,0,q),g(L,q,2*q))}static fromDER(L){let{r:q,s:C}=Pn.toSig(Se("DER",L));return new y(q,C)}assertValidity(){if(!m(this.r))throw new Error("r must be 0 < r < CURVE.n");if(!m(this.s))throw new Error("s must be 0 < s < CURVE.n")}addRecoveryBit(L){return new y(this.r,this.s,L)}recoverPublicKey(L){let{r:q,s:C,recovery:I}=this,z=v(Se("msgHash",L));if(I==null||![0,1,2,3].includes(I))throw new Error("recovery id invalid");let K=I===2||I===3?q+e.n:q;if(K>=t.ORDER)throw new Error("recovery id 2 or 3 invalid");let j=I&1?"03":"02",X=u.fromHex(j+d(K)),Z=c(K),se=a(-z*Z),re=a(C*Z),oe=u.BASE.multiplyAndAddUnsafe(X,se,re);if(!oe)throw new Error("point at infinify");return oe.assertValidity(),oe}hasHighS(){return p(this.s)}normalizeS(){return this.hasHighS()?new y(this.r,a(-this.s),this.recovery):this}toDERRawBytes(){return Rn(this.toDERHex())}toDERHex(){return Pn.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return Rn(this.toCompactHex())}toCompactHex(){return d(this.r)+d(this.s)}}let x={isValidPrivateKey(k){try{return l(k),!0}catch{return!1}},normPrivateKeyToScalar:l,randomPrivateKey:()=>{let k=Fu(e.n);return Np(e.randomBytes(k),e.n)},precompute(k=8,L=u.BASE){return L._setWindowSize(k),L.multiply(BigInt(3)),L}};function b(k,L=!0){return u.fromPrivateKey(k).toRawBytes(L)}function S(k){let L=jr(k),q=typeof k=="string",C=(L||q)&&k.length;return L?C===o||C===i:q?C===2*o||C===2*i:k instanceof u}function _(k,L,q=!0){if(S(k))throw new Error("first arg must be private key");if(!S(L))throw new Error("second arg must be public key");return u.fromHex(L).multiply(l(k)).toRawBytes(q)}let A=e.bits2int||function(k){let L=gr(k),q=k.length*8-e.nBitLength;return q>0?L>>BigInt(q):L},v=e.bits2int_modN||function(k){return a(A(k))},E=mi(e.nBitLength);function R(k){if(typeof k!="bigint")throw new Error("bigint expected");if(!(Ir<=k&&k<E))throw new Error(`bigint expected < 2^${e.nBitLength}`);return Xr(k,e.nByteLength)}function N(k,L,q=T){if(["recovered","canonical"].some(xe=>xe in q))throw new Error("sign() legacy options not supported");let{hash:C,randomBytes:I}=e,{lowS:z,prehash:K,extraEntropy:j}=q;z==null&&(z=!0),k=Se("msgHash",k),K&&(k=Se("prehashed msgHash",C(k)));let X=v(k),Z=l(L),se=[R(Z),R(X)];if(j!=null&&j!==!1){let xe=j===!0?I(t.BYTES):j;se.push(Se("extraEntropy",xe))}let re=wr(...se),oe=X;function Re(xe){let Oe=A(xe);if(!m(Oe))return;let Ue=c(Oe),Ce=u.BASE.multiply(Oe).toAffine(),$e=a(Ce.x);if($e===Ir)return;let dr=a(Ue*a(oe+$e*Z));if(dr===Ir)return;let En=(Ce.x===$e?0:2)|Number(Ce.y&Lt),ni=dr;return z&&p(dr)&&(ni=h(dr),En^=1),new y($e,ni,En)}return{seed:re,k2sig:Re}}let T={lowS:e.lowS,prehash:!1},H={lowS:e.lowS,prehash:!1};function D(k,L,q=T){let{seed:C,k2sig:I}=N(k,L,q),z=e;return Du(z.hash.outputLen,z.nByteLength,z.hmac)(C,I)}u.BASE._setWindowSize(8);function Q(k,L,q,C=H){let I=k;if(L=Se("msgHash",L),q=Se("publicKey",q),"strict"in C)throw new Error("options.strict was renamed to lowS");let{lowS:z,prehash:K}=C,j,X;try{if(typeof I=="string"||jr(I))try{j=y.fromDER(I)}catch(Ce){if(!(Ce instanceof Pn.Err))throw Ce;j=y.fromCompact(I)}else if(typeof I=="object"&&typeof I.r=="bigint"&&typeof I.s=="bigint"){let{r:Ce,s:$e}=I;j=new y(Ce,$e)}else throw new Error("PARSE");X=u.fromHex(q)}catch(Ce){if(Ce.message==="PARSE")throw new Error("signature must be Signature instance, Uint8Array or hex string");return!1}if(z&&j.hasHighS())return!1;K&&(L=e.hash(L));let{r:Z,s:se}=j,re=v(L),oe=c(se),Re=a(re*oe),xe=a(Z*oe),Oe=u.BASE.multiplyAndAddUnsafe(X,Re,xe)?.toAffine();return Oe?a(Oe.x)===Z:!1}return{CURVE:e,getPublicKey:b,getSharedSecret:_,sign:D,verify:Q,ProjectivePoint:u,Signature:y,utils:x}}function l3(r){return{hash:r,hmac:(e,...t)=>wi(r,e,Zs(...t)),randomBytes:bo}}function F0(r,e){let t=n=>U0({...r,...l3(n)});return Object.freeze({...t(e),create:t})}var M0=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),V0=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),u3=BigInt(1),nf=BigInt(2),H0=(r,e)=>(r+e/nf)/e;function f3(r){let e=M0,t=BigInt(3),n=BigInt(6),o=BigInt(11),i=BigInt(22),s=BigInt(23),a=BigInt(44),c=BigInt(88),u=r*r*r%e,l=u*u*r%e,f=pe(l,t,e)*l%e,m=pe(f,t,e)*l%e,d=pe(m,nf,e)*u%e,p=pe(d,o,e)*d%e,h=pe(p,i,e)*p%e,g=pe(h,a,e)*h%e,y=pe(g,c,e)*g%e,x=pe(y,a,e)*h%e,b=pe(x,t,e)*l%e,S=pe(b,s,e)*p%e,_=pe(S,n,e)*u%e,A=pe(_,nf,e);if(!of.eql(of.sqr(A),r))throw new Error("Cannot find square root");return A}var of=na(M0,void 0,void 0,{sqrt:f3}),$t=F0({a:BigInt(0),b:BigInt(7),Fp:of,n:V0,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:r=>{let e=V0,t=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-u3*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),o=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),i=t,s=BigInt("0x100000000000000000000000000000000"),a=H0(i*r,e),c=H0(-n*r,e),u=fe(r-a*t-c*o,e),l=fe(-a*n-c*i,e),f=u>s,m=l>s;if(f&&(u=e-u),m&&(l=e-l),u>s||l>s)throw new Error("splitScalar: Endomorphism failed, k="+r);return{k1neg:f,k1:u,k2neg:m,k2:l}}}},P0),rB=BigInt(0);var nB=$t.ProjectivePoint;function z0(){return $t.utils.randomPrivateKey()}function $0(r,e){let t=ae.digest(e instanceof Uint8Array?e:e.subarray());if(Nt(t))return t.then(({digest:n})=>$t.sign(n,r).toDERRawBytes()).catch(n=>{throw new P(String(n),"ERR_INVALID_INPUT")});try{return $t.sign(t.digest,r).toDERRawBytes()}catch(n){throw new P(String(n),"ERR_INVALID_INPUT")}}function K0(r,e,t){let n=ae.digest(t instanceof Uint8Array?t:t.subarray());if(Nt(n))return n.then(({digest:o})=>$t.verify(e,o,r)).catch(o=>{throw new P(String(o),"ERR_INVALID_INPUT")});try{return $t.verify(e,n.digest,r)}catch(o){throw new P(String(o),"ERR_INVALID_INPUT")}}function G0(r){return $t.ProjectivePoint.fromHex(r).toRawBytes(!0)}function q0(r){try{$t.getPublicKey(r,!0)}catch(e){throw new P(String(e),"ERR_INVALID_PRIVATE_KEY")}}function sf(r){try{$t.ProjectivePoint.fromHex(r)}catch(e){throw new P(String(e),"ERR_INVALID_PUBLIC_KEY")}}function W0(r){try{return $t.getPublicKey(r,!0)}catch(e){throw new P(String(e),"ERR_INVALID_PRIVATE_KEY")}}var Ti=class{_key;constructor(e){sf(e),this._key=e}verify(e,t){return K0(this._key,t,e)}marshal(){return G0(this._key)}get bytes(){return tr.encode({Type:me.Secp256k1,Data:this.marshal()}).subarray()}equals(e){return ce(this.bytes,e.bytes)}async hash(){let e=ae.digest(this.bytes),t;return Nt(e)?{bytes:t}=await e:t=e.bytes,t}},Ni=class{_key;_publicKey;constructor(e,t){this._key=e,this._publicKey=t??W0(e),q0(this._key),sf(this._publicKey)}sign(e){return $0(this._key,e)}get public(){return new Ti(this._publicKey)}marshal(){return this._key}get bytes(){return rr.encode({Type:me.Secp256k1,Data:this.marshal()}).subarray()}equals(e){return ce(this.bytes,e.bytes)}hash(){let e=ae.digest(this.bytes);return Nt(e)?e.then(({bytes:t})=>t):e.bytes}async id(){let e=await this.public.hash();return W(e,"base58btc")}async export(e,t="libp2p-key"){if(t==="libp2p-key")return _o(this.bytes,e);throw new P(`export format '${t}' is not supported`,"ERR_INVALID_EXPORT_FORMAT")}};function h3(r){return new Ni(r)}function p3(r){return new Ti(r)}async function m3(){let r=z0();return new Ni(r)}var On={rsa:tf,ed25519:Gu,secp256k1:af};function j0(r){let e=Object.keys(On).join(" / ");return new P(`invalid or unsupported key type ${r}. Must be ${e}`,"ERR_UNSUPPORTED_KEY_TYPE")}function cf(r){let e=tr.decode(r),t=e.Data??new Uint8Array;switch(e.Type){case me.RSA:return On.rsa.unmarshalRsaPublicKey(t);case me.Ed25519:return On.ed25519.unmarshalEd25519PublicKey(t);case me.Secp256k1:return On.secp256k1.unmarshalSecp256k1PublicKey(t);default:throw j0(e.Type??"unknown")}}async function Y0(r){let e=rr.decode(r),t=e.Data??new Uint8Array;switch(e.Type){case me.RSA:return On.rsa.unmarshalRsaPrivateKey(t);case me.Ed25519:return On.ed25519.unmarshalEd25519PrivateKey(t);case me.Secp256k1:return On.secp256k1.unmarshalSecp256k1PrivateKey(t);default:throw j0(e.Type??"RSA")}}var Af=J(Ie(),1);var Br="/",X0=new TextEncoder().encode(Br),Qa=X0[0],Be=class r{_buf;constructor(e,t){if(typeof e=="string")this._buf=F(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]!==Qa)throw new Error("Invalid key")}toString(e="utf8"){return W(this._buf,e)}uint8Array(){return this._buf}get[Symbol.toStringTag](){return`Key(${this.toString()})`}static withNamespaces(e){return new r(e.join(Br))}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=X0),this._buf[0]!==Qa){let e=new Uint8Array(this._buf.byteLength+1);e.fill(Qa,0,1),e.set(this._buf,1),this._buf=e}for(;this._buf.byteLength>1&&this._buf[this._buf.byteLength-1]===Qa;)this._buf=this._buf.subarray(0,-1)}less(e){let t=this.list(),n=e.list();for(let o=0;o<t.length;o++){if(n.length<o+1)return!1;let i=t[o],s=n[o];if(i<s)return!0;if(i>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(Br).slice(1)}type(){return y3(this.baseNamespace())}name(){return g3(this.baseNamespace())}instance(e){return new r(this.toString()+":"+e)}path(){let e=this.parent().toString();return e.endsWith(Br)||(e+=Br),e+=this.type(),new r(e)}parent(){let e=this.list();return e.length===1?new r(Br):new r(e.slice(0,-1).join(Br))}child(e){return this.toString()===Br?e:e.toString()===Br?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(),...w3(e.map(t=>t.namespaces()))])}};function y3(r){let e=r.split(":");return e.length<2?"":e.slice(0,-1).join(":")}function g3(r){let e=r.split(":");return e[e.length-1]}function w3(r){return[].concat(...r)}var d1=J(ec(),1);var Z0="ERR_IPNS_EXPIRED_RECORD",Ci="ERR_UNRECOGNIZED_VALIDITY",J0="ERR_SIGNATURE_CREATION",Rr="ERR_SIGNATURE_VERIFICATION";var uf="ERR_UNDEFINED_PARAMETER",Q0="ERR_INVALID_RECORD_DATA",em="ERR_INVALID_VALUE",tm="ERR_INVALID_EMBEDDED_KEY",rm="ERR_MISSING_PRIVATE_KEY",nm="ERR_RECORD_TOO_LARGE";var He;(function(r){let e;(function(o){o.EOL="EOL"})(e=r.ValidityType||(r.ValidityType={}));let t;(function(o){o[o.EOL=0]="EOL"})(t||(t={})),function(o){o.codec=()=>Bn(t)}(e=r.ValidityType||(r.ValidityType={}));let n;r.codec=()=>(n==null&&(n=Bt((o,i,s={})=>{s.lengthDelimited!==!1&&i.fork(),o.value!=null&&(i.uint32(10),i.bytes(o.value)),o.signatureV1!=null&&(i.uint32(18),i.bytes(o.signatureV1)),o.validityType!=null&&(i.uint32(24),r.ValidityType.codec().encode(o.validityType,i)),o.validity!=null&&(i.uint32(34),i.bytes(o.validity)),o.sequence!=null&&(i.uint32(40),i.uint64(o.sequence)),o.ttl!=null&&(i.uint32(48),i.uint64(o.ttl)),o.pubKey!=null&&(i.uint32(58),i.bytes(o.pubKey)),o.signatureV2!=null&&(i.uint32(66),i.bytes(o.signatureV2)),o.data!=null&&(i.uint32(74),i.bytes(o.data)),s.lengthDelimited!==!1&&i.ldelim()},(o,i)=>{let s={},a=i==null?o.len:o.pos+i;for(;o.pos<a;){let c=o.uint32();switch(c>>>3){case 1:s.value=o.bytes();break;case 2:s.signatureV1=o.bytes();break;case 3:s.validityType=r.ValidityType.codec().decode(o);break;case 4:s.validity=o.bytes();break;case 5:s.sequence=o.uint64();break;case 6:s.ttl=o.uint64();break;case 7:s.pubKey=o.bytes();break;case 8:s.signatureV2=o.bytes();break;case 9:s.data=o.bytes();break;default:o.skipType(c&7);break}}return s})),n),r.encode=o=>It(o,r.codec()),r.decode=o=>_t(o,r.codec())})(He||(He={}));var b3=["string","number","bigint","symbol"],x3=["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 om(r){if(r===null)return"null";if(r===void 0)return"undefined";if(r===!0||r===!1)return"boolean";let e=typeof r;if(b3.includes(e))return e;if(e==="function")return"Function";if(Array.isArray(r))return"Array";if(E3(r))return"Buffer";let t=v3(r);return t||"Object"}function E3(r){return r&&r.constructor&&r.constructor.isBuffer&&r.constructor.isBuffer.call(null,r)}function v3(r){let e=Object.prototype.toString.call(r).slice(8,-1);if(x3.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 B=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 Co=globalThis.process&&!globalThis.process.browser&&globalThis.Buffer&&typeof globalThis.Buffer.isBuffer=="function",A3=new TextDecoder,S3=new TextEncoder;function tc(r){return Co&&globalThis.Buffer.isBuffer(r)}function Li(r){return r instanceof Uint8Array?tc(r)?new Uint8Array(r.buffer,r.byteOffset,r.byteLength):r:Uint8Array.from(r)}var cm=Co?(r,e,t)=>t-e>64?globalThis.Buffer.from(r.subarray(e,t)).toString("utf8"):sm(r,e,t):(r,e,t)=>t-e>64?A3.decode(r.subarray(e,t)):sm(r,e,t),rc=Co?r=>r.length>64?globalThis.Buffer.from(r):im(r):r=>r.length>64?S3.encode(r):im(r),sr=r=>Uint8Array.from(r),Lo=Co?(r,e,t)=>tc(r)?new Uint8Array(r.subarray(e,t)):r.slice(e,t):(r,e,t)=>r.slice(e,t),lm=Co?(r,e)=>(r=r.map(t=>t instanceof Uint8Array?t:globalThis.Buffer.from(t)),Li(globalThis.Buffer.concat(r,e))):(r,e)=>{let t=new Uint8Array(e),n=0;for(let o of r)n+o.length>t.length&&(o=o.subarray(0,t.length-n)),t.set(o,n),n+=o.length;return t},um=Co?r=>globalThis.Buffer.allocUnsafe(r):r=>new Uint8Array(r);function fm(r,e){if(tc(r)&&tc(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 im(r){let e=[],t=0;for(let n=0;n<r.length;n++){let o=r.charCodeAt(n);o<128?e[t++]=o:o<2048?(e[t++]=o>>6|192,e[t++]=o&63|128):(o&64512)===55296&&n+1<r.length&&(r.charCodeAt(n+1)&64512)===56320?(o=65536+((o&1023)<<10)+(r.charCodeAt(++n)&1023),e[t++]=o>>18|240,e[t++]=o>>12&63|128,e[t++]=o>>6&63|128,e[t++]=o&63|128):(e[t++]=o>>12|224,e[t++]=o>>6&63|128,e[t++]=o&63|128)}return e}function sm(r,e,t){let n=[];for(;e<t;){let o=r[e],i=null,s=o>239?4:o>223?3:o>191?2:1;if(e+s<=t){let a,c,u,l;switch(s){case 1:o<128&&(i=o);break;case 2:a=r[e+1],(a&192)===128&&(l=(o&31)<<6|a&63,l>127&&(i=l));break;case 3:a=r[e+1],c=r[e+2],(a&192)===128&&(c&192)===128&&(l=(o&15)<<12|(a&63)<<6|c&63,l>2047&&(l<55296||l>57343)&&(i=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=(o&15)<<18|(a&63)<<12|(c&63)<<6|u&63,l>65535&&l<1114112&&(i=l))}}i===null?(i=65533,s=1):i>65535&&(i-=65536,n.push(i>>>10&1023|55296),i=56320|i&1023),n.push(i),e+=s}return df(n)}var am=4096;function df(r){let e=r.length;if(e<=am)return String.fromCharCode.apply(String,r);let t="",n=0;for(;n<e;)t+=String.fromCharCode.apply(String,r.slice(n,n+=am));return t}var _3=256,Di=class{constructor(e=_3){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 o=t.length-(this.maxCursor-this.cursor)-1;t.set(e,o)}else{if(t){let o=t.length-(this.maxCursor-this.cursor)-1;o<t.length&&(this.chunks[this.chunks.length-1]=t.subarray(0,o),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=Lo(n,0,this.cursor)}else t=lm(this.chunks,this.cursor);return e&&this.reset(),t}};var $="CBOR decode error:",Tr="CBOR encode error:",Pi=[];Pi[23]=1;Pi[24]=2;Pi[25]=3;Pi[26]=5;Pi[27]=9;function Nr(r,e,t){if(r.length-e<t)throw new Error(`${$} not enough data for type`)}var Pe=[24,256,65536,4294967296,BigInt("18446744073709551616")];function gt(r,e,t){Nr(r,e,1);let n=r[e];if(t.strict===!0&&n<Pe[0])throw new Error(`${$} integer encoded in more bytes than necessary (strict decode)`);return n}function wt(r,e,t){Nr(r,e,2);let n=r[e]<<8|r[e+1];if(t.strict===!0&&n<Pe[1])throw new Error(`${$} integer encoded in more bytes than necessary (strict decode)`);return n}function bt(r,e,t){Nr(r,e,4);let n=r[e]*16777216+(r[e+1]<<16)+(r[e+2]<<8)+r[e+3];if(t.strict===!0&&n<Pe[2])throw new Error(`${$} integer encoded in more bytes than necessary (strict decode)`);return n}function xt(r,e,t){Nr(r,e,8);let n=r[e]*16777216+(r[e+1]<<16)+(r[e+2]<<8)+r[e+3],o=r[e+4]*16777216+(r[e+5]<<16)+(r[e+6]<<8)+r[e+7],i=(BigInt(n)<<BigInt(32))+BigInt(o);if(t.strict===!0&&i<Pe[3])throw new Error(`${$} integer encoded in more bytes than necessary (strict decode)`);if(i<=Number.MAX_SAFE_INTEGER)return Number(i);if(t.allowBigInt===!0)return i;throw new Error(`${$} integers outside of the safe integer range are not supported`)}function dm(r,e,t,n){return new B(w.uint,gt(r,e+1,n),2)}function hm(r,e,t,n){return new B(w.uint,wt(r,e+1,n),3)}function pm(r,e,t,n){return new B(w.uint,bt(r,e+1,n),5)}function mm(r,e,t,n){return new B(w.uint,xt(r,e+1,n),9)}function Dt(r,e){return Me(r,0,e.value)}function Me(r,e,t){if(t<Pe[0]){let n=Number(t);r.push([e|n])}else if(t<Pe[1]){let n=Number(t);r.push([e|24,n])}else if(t<Pe[2]){let n=Number(t);r.push([e|25,n>>>8,n&255])}else if(t<Pe[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<Pe[4]){let o=[e|27,0,0,0,0,0,0,0],i=Number(n&BigInt(4294967295)),s=Number(n>>BigInt(32)&BigInt(4294967295));o[8]=i&255,i=i>>8,o[7]=i&255,i=i>>8,o[6]=i&255,i=i>>8,o[5]=i&255,o[4]=s&255,s=s>>8,o[3]=s&255,s=s>>8,o[2]=s&255,s=s>>8,o[1]=s&255,r.push(o)}else throw new Error(`${$} encountered BigInt larger than allowable range`)}}Dt.encodedSize=function(e){return Me.encodedSize(e.value)};Me.encodedSize=function(e){return e<Pe[0]?1:e<Pe[1]?2:e<Pe[2]?3:e<Pe[3]?5:9};Dt.compareTokens=function(e,t){return e.value<t.value?-1:e.value>t.value?1:0};function ym(r,e,t,n){return new B(w.negint,-1-gt(r,e+1,n),2)}function gm(r,e,t,n){return new B(w.negint,-1-wt(r,e+1,n),3)}function wm(r,e,t,n){return new B(w.negint,-1-bt(r,e+1,n),5)}var hf=BigInt(-1),bm=BigInt(1);function xm(r,e,t,n){let o=xt(r,e+1,n);if(typeof o!="bigint"){let i=-1-o;if(i>=Number.MIN_SAFE_INTEGER)return new B(w.negint,i,9)}if(n.allowBigInt!==!0)throw new Error(`${$} integers outside of the safe integer range are not supported`);return new B(w.negint,hf-BigInt(o),9)}function nc(r,e){let t=e.value,n=typeof t=="bigint"?t*hf-bm:t*-1-1;Me(r,e.type.majorEncoded,n)}nc.encodedSize=function(e){let t=e.value,n=typeof t=="bigint"?t*hf-bm:t*-1-1;return n<Pe[0]?1:n<Pe[1]?2:n<Pe[2]?3:n<Pe[3]?5:9};nc.compareTokens=function(e,t){return e.value<t.value?1:e.value>t.value?-1:0};function Oi(r,e,t,n){Nr(r,e,t+n);let o=Lo(r,e+t,e+t+n);return new B(w.bytes,o,t+n)}function Em(r,e,t,n){return Oi(r,e,1,t)}function vm(r,e,t,n){return Oi(r,e,2,gt(r,e+1,n))}function Am(r,e,t,n){return Oi(r,e,3,wt(r,e+1,n))}function Sm(r,e,t,n){return Oi(r,e,5,bt(r,e+1,n))}function _m(r,e,t,n){let o=xt(r,e+1,n);if(typeof o=="bigint")throw new Error(`${$} 64-bit integer bytes lengths not supported`);return Oi(r,e,9,o)}function oc(r){return r.encodedBytes===void 0&&(r.encodedBytes=r.type===w.string?rc(r.value):r.value),r.encodedBytes}function Do(r,e){let t=oc(e);Me(r,e.type.majorEncoded,t.length),r.push(t)}Do.encodedSize=function(e){let t=oc(e);return Me.encodedSize(t.length)+t.length};Do.compareTokens=function(e,t){return I3(oc(e),oc(t))};function I3(r,e){return r.length<e.length?-1:r.length>e.length?1:fm(r,e)}function Ui(r,e,t,n,o){let i=t+n;Nr(r,e,i);let s=new B(w.string,cm(r,e+t,e+i),i);return o.retainStringBytes===!0&&(s.byteValue=Lo(r,e+t,e+i)),s}function km(r,e,t,n){return Ui(r,e,1,t,n)}function Im(r,e,t,n){return Ui(r,e,2,gt(r,e+1,n),n)}function Bm(r,e,t,n){return Ui(r,e,3,wt(r,e+1,n),n)}function Rm(r,e,t,n){return Ui(r,e,5,bt(r,e+1,n),n)}function Tm(r,e,t,n){let o=xt(r,e+1,n);if(typeof o=="bigint")throw new Error(`${$} 64-bit integer string lengths not supported`);return Ui(r,e,9,o,n)}var Nm=Do;function Po(r,e,t,n){return new B(w.array,n,t)}function Cm(r,e,t,n){return Po(r,e,1,t)}function Lm(r,e,t,n){return Po(r,e,2,gt(r,e+1,n))}function Dm(r,e,t,n){return Po(r,e,3,wt(r,e+1,n))}function Pm(r,e,t,n){return Po(r,e,5,bt(r,e+1,n))}function Om(r,e,t,n){let o=xt(r,e+1,n);if(typeof o=="bigint")throw new Error(`${$} 64-bit integer array lengths not supported`);return Po(r,e,9,o)}function Um(r,e,t,n){if(n.allowIndefinite===!1)throw new Error(`${$} indefinite length items not allowed`);return Po(r,e,1,1/0)}function ic(r,e){Me(r,w.array.majorEncoded,e.value)}ic.compareTokens=Dt.compareTokens;ic.encodedSize=function(e){return Me.encodedSize(e.value)};function Oo(r,e,t,n){return new B(w.map,n,t)}function Fm(r,e,t,n){return Oo(r,e,1,t)}function Vm(r,e,t,n){return Oo(r,e,2,gt(r,e+1,n))}function Hm(r,e,t,n){return Oo(r,e,3,wt(r,e+1,n))}function Mm(r,e,t,n){return Oo(r,e,5,bt(r,e+1,n))}function zm(r,e,t,n){let o=xt(r,e+1,n);if(typeof o=="bigint")throw new Error(`${$} 64-bit integer map lengths not supported`);return Oo(r,e,9,o)}function $m(r,e,t,n){if(n.allowIndefinite===!1)throw new Error(`${$} indefinite length items not allowed`);return Oo(r,e,1,1/0)}function sc(r,e){Me(r,w.map.majorEncoded,e.value)}sc.compareTokens=Dt.compareTokens;sc.encodedSize=function(e){return Me.encodedSize(e.value)};function Km(r,e,t,n){return new B(w.tag,t,1)}function Gm(r,e,t,n){return new B(w.tag,gt(r,e+1,n),2)}function qm(r,e,t,n){return new B(w.tag,wt(r,e+1,n),3)}function Wm(r,e,t,n){return new B(w.tag,bt(r,e+1,n),5)}function jm(r,e,t,n){return new B(w.tag,xt(r,e+1,n),9)}function ac(r,e){Me(r,w.tag.majorEncoded,e.value)}ac.compareTokens=Dt.compareTokens;ac.encodedSize=function(e){return Me.encodedSize(e.value)};var L3=20,D3=21,P3=22,O3=23;function Ym(r,e,t,n){if(n.allowUndefined===!1)throw new Error(`${$} undefined values are not supported`);return n.coerceUndefinedToNull===!0?new B(w.null,null,1):new B(w.undefined,void 0,1)}function Xm(r,e,t,n){if(n.allowIndefinite===!1)throw new Error(`${$} indefinite length items not allowed`);return new B(w.break,void 0,1)}function pf(r,e,t){if(t){if(t.allowNaN===!1&&Number.isNaN(r))throw new Error(`${$} NaN values are not supported`);if(t.allowInfinity===!1&&(r===1/0||r===-1/0))throw new Error(`${$} Infinity values are not supported`)}return new B(w.float,r,e)}function Zm(r,e,t,n){return pf(mf(r,e+1),3,n)}function Jm(r,e,t,n){return pf(yf(r,e+1),5,n)}function Qm(r,e,t,n){return pf(n1(r,e+1),9,n)}function cc(r,e,t){let n=e.value;if(n===!1)r.push([w.float.majorEncoded|L3]);else if(n===!0)r.push([w.float.majorEncoded|D3]);else if(n===null)r.push([w.float.majorEncoded|P3]);else if(n===void 0)r.push([w.float.majorEncoded|O3]);else{let o,i=!1;(!t||t.float64!==!0)&&(t1(n),o=mf(Kt,1),n===o||Number.isNaN(n)?(Kt[0]=249,r.push(Kt.slice(0,3)),i=!0):(r1(n),o=yf(Kt,1),n===o&&(Kt[0]=250,r.push(Kt.slice(0,5)),i=!0))),i||(U3(n),o=n1(Kt,1),Kt[0]=251,r.push(Kt.slice(0,9)))}}cc.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){t1(n);let o=mf(Kt,1);if(n===o||Number.isNaN(n))return 3;if(r1(n),o=yf(Kt,1),n===o)return 5}return 9};var e1=new ArrayBuffer(9),Pt=new DataView(e1,1),Kt=new Uint8Array(e1,0);function t1(r){if(r===1/0)Pt.setUint16(0,31744,!1);else if(r===-1/0)Pt.setUint16(0,64512,!1);else if(Number.isNaN(r))Pt.setUint16(0,32256,!1);else{Pt.setFloat32(0,r);let e=Pt.getUint32(0),t=(e&2139095040)>>23,n=e&8388607;if(t===255)Pt.setUint16(0,31744,!1);else if(t===0)Pt.setUint16(0,(r&2147483648)>>16|n>>13,!1);else{let o=t-127;o<-24?Pt.setUint16(0,0):o<-14?Pt.setUint16(0,(e&2147483648)>>16|1<<24+o,!1):Pt.setUint16(0,(e&2147483648)>>16|o+15<<10|n>>13,!1)}}}function mf(r,e){if(r.length-e<2)throw new Error(`${$} 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,o=t&1023,i;return n===0?i=o*2**-24:n!==31?i=(o+1024)*2**(n-25):i=o===0?1/0:NaN,t&32768?-i:i}function r1(r){Pt.setFloat32(0,r,!1)}function yf(r,e){if(r.length-e<4)throw new Error(`${$} not enough data for float32`);let t=(r.byteOffset||0)+e;return new DataView(r.buffer,t,4).getFloat32(0,!1)}function U3(r){Pt.setFloat64(0,r,!1)}function n1(r,e){if(r.length-e<8)throw new Error(`${$} not enough data for float64`);let t=(r.byteOffset||0)+e;return new DataView(r.buffer,t,8).getFloat64(0,!1)}cc.compareTokens=Dt.compareTokens;function ie(r,e,t){throw new Error(`${$} encountered invalid minor (${t}) for major ${r[e]>>>5}`)}function lc(r){return()=>{throw new Error(`${$} ${r}`)}}var O=[];for(let r=0;r<=23;r++)O[r]=ie;O[24]=dm;O[25]=hm;O[26]=pm;O[27]=mm;O[28]=ie;O[29]=ie;O[30]=ie;O[31]=ie;for(let r=32;r<=55;r++)O[r]=ie;O[56]=ym;O[57]=gm;O[58]=wm;O[59]=xm;O[60]=ie;O[61]=ie;O[62]=ie;O[63]=ie;for(let r=64;r<=87;r++)O[r]=Em;O[88]=vm;O[89]=Am;O[90]=Sm;O[91]=_m;O[92]=ie;O[93]=ie;O[94]=ie;O[95]=lc("indefinite length bytes/strings are not supported");for(let r=96;r<=119;r++)O[r]=km;O[120]=Im;O[121]=Bm;O[122]=Rm;O[123]=Tm;O[124]=ie;O[125]=ie;O[126]=ie;O[127]=lc("indefinite length bytes/strings are not supported");for(let r=128;r<=151;r++)O[r]=Cm;O[152]=Lm;O[153]=Dm;O[154]=Pm;O[155]=Om;O[156]=ie;O[157]=ie;O[158]=ie;O[159]=Um;for(let r=160;r<=183;r++)O[r]=Fm;O[184]=Vm;O[185]=Hm;O[186]=Mm;O[187]=zm;O[188]=ie;O[189]=ie;O[190]=ie;O[191]=$m;for(let r=192;r<=215;r++)O[r]=Km;O[216]=Gm;O[217]=qm;O[218]=Wm;O[219]=jm;O[220]=ie;O[221]=ie;O[222]=ie;O[223]=ie;for(let r=224;r<=243;r++)O[r]=lc("simple values are not supported");O[244]=ie;O[245]=ie;O[246]=ie;O[247]=Ym;O[248]=lc("simple values are not supported");O[249]=Zm;O[250]=Jm;O[251]=Qm;O[252]=ie;O[253]=ie;O[254]=ie;O[255]=Xm;var Gt=[];for(let r=0;r<24;r++)Gt[r]=new B(w.uint,r,1);for(let r=-1;r>=-24;r--)Gt[31-r]=new B(w.negint,r,1);Gt[64]=new B(w.bytes,new Uint8Array(0),1);Gt[96]=new B(w.string,"",1);Gt[128]=new B(w.array,0,1);Gt[160]=new B(w.map,0,1);Gt[244]=new B(w.false,!1,1);Gt[245]=new B(w.true,!0,1);Gt[246]=new B(w.null,null,1);function gf(r){switch(r.type){case w.false:return sr([244]);case w.true:return sr([245]);case w.null:return sr([246]);case w.bytes:return r.value.length?void 0:sr([64]);case w.string:return r.value===""?sr([96]):void 0;case w.array:return r.value===0?sr([128]):void 0;case w.map:return r.value===0?sr([160]):void 0;case w.uint:return r.value<24?sr([Number(r.value)]):void 0;case w.negint:if(r.value>=-24)return sr([31-Number(r.value)])}}var V3={float64:!1,mapSorter:M3,quickEncodeToken:gf};function bf(){let r=[];return r[w.uint.major]=Dt,r[w.negint.major]=nc,r[w.bytes.major]=Do,r[w.string.major]=Nm,r[w.array.major]=ic,r[w.map.major]=sc,r[w.tag.major]=ac,r[w.float.major]=cc,r}var o1=bf(),wf=new Di,uc=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(`${Tr} object contains circular references`);return new r(t,e)}},nn={null:new B(w.null,null),undefined:new B(w.undefined,void 0),true:new B(w.true,!0),false:new B(w.false,!1),emptyArray:new B(w.array,0),emptyMap:new B(w.map,0)},on={number(r,e,t,n){return!Number.isInteger(r)||!Number.isSafeInteger(r)?new B(w.float,r):r>=0?new B(w.uint,r):new B(w.negint,r)},bigint(r,e,t,n){return r>=BigInt(0)?new B(w.uint,r):new B(w.negint,r)},Uint8Array(r,e,t,n){return new B(w.bytes,r)},string(r,e,t,n){return new B(w.string,r)},boolean(r,e,t,n){return r?nn.true:nn.false},null(r,e,t,n){return nn.null},undefined(r,e,t,n){return nn.undefined},ArrayBuffer(r,e,t,n){return new B(w.bytes,new Uint8Array(r))},DataView(r,e,t,n){return new B(w.bytes,new Uint8Array(r.buffer,r.byteOffset,r.byteLength))},Array(r,e,t,n){if(!r.length)return t.addBreakTokens===!0?[nn.emptyArray,new B(w.break)]:nn.emptyArray;n=uc.createCheck(n,r);let o=[],i=0;for(let s of r)o[i++]=Fi(s,t,n);return t.addBreakTokens?[new B(w.array,r.length),o,new B(w.break)]:[new B(w.array,r.length),o]},Object(r,e,t,n){let o=e!=="Object",i=o?r.keys():Object.keys(r),s=o?r.size:i.length;if(!s)return t.addBreakTokens===!0?[nn.emptyMap,new B(w.break)]:nn.emptyMap;n=uc.createCheck(n,r);let a=[],c=0;for(let u of i)a[c++]=[Fi(u,t,n),Fi(o?r.get(u):r[u],t,n)];return H3(a,t),t.addBreakTokens?[new B(w.map,s),a,new B(w.break)]:[new B(w.map,s),a]}};on.Map=on.Object;on.Buffer=on.Uint8Array;for(let r of"Uint8Clamped Uint16 Uint32 Int8 Int16 Int32 BigUint64 BigInt64 Float32 Float64".split(" "))on[`${r}Array`]=on.DataView;function Fi(r,e={},t){let n=om(r),o=e&&e.typeEncoders&&e.typeEncoders[n]||on[n];if(typeof o=="function"){let s=o(r,n,e,t);if(s!=null)return s}let i=on[n];if(!i)throw new Error(`${Tr} unsupported type: ${n}`);return i(r,n,e,t)}function H3(r,e){e.mapSorter&&r.sort(e.mapSorter)}function M3(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 o=t.type.major,i=o1[o].compareTokens(t,n);return i===0&&console.warn("WARNING: complex key types used, CBOR key sorting guarantees are gone"),i}function i1(r,e,t,n){if(Array.isArray(e))for(let o of e)i1(r,o,t,n);else t[e.type.major](r,e,n)}function xf(r,e,t){let n=Fi(r,t);if(!Array.isArray(n)&&t.quickEncodeToken){let o=t.quickEncodeToken(n);if(o)return o;let i=e[n.type.major];if(i.encodedSize){let s=i.encodedSize(n,t),a=new Di(s);if(i(a,n,t),a.chunks.length!==1)throw new Error(`Unexpected error: pre-calculated length for ${n} was wrong`);return Li(a.chunks[0])}}return wf.reset(),i1(wf,n,e,t),wf.toBytes(!0)}function sn(r,e){return e=Object.assign({},V3,e),xf(r,o1,e)}var z3={strict:!1,allowIndefinite:!0,allowUndefined:!0,allowBigInt:!0},fc=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=Gt[e];if(t===void 0){let n=O[e];if(!n)throw new Error(`${$} no decoder for major type ${e>>>5} (byte 0x${e.toString(16).padStart(2,"0")})`);let o=e&31;t=n(this.data,this._pos,o,this.options)}return this._pos+=t.encodedLength,t}},Vi=Symbol.for("DONE"),dc=Symbol.for("BREAK");function $3(r,e,t){let n=[];for(let o=0;o<r.value;o++){let i=Uo(e,t);if(i===dc){if(r.value===1/0)break;throw new Error(`${$} got unexpected break to lengthed array`)}if(i===Vi)throw new Error(`${$} found array but not enough entries (got ${o}, expected ${r.value})`);n[o]=i}return n}function K3(r,e,t){let n=t.useMaps===!0,o=n?void 0:{},i=n?new Map:void 0;for(let s=0;s<r.value;s++){let a=Uo(e,t);if(a===dc){if(r.value===1/0)break;throw new Error(`${$} got unexpected break to lengthed map`)}if(a===Vi)throw new Error(`${$} found map but not enough entries (got ${s} [no key], expected ${r.value})`);if(n!==!0&&typeof a!="string")throw new Error(`${$} non-string keys not supported (got ${typeof a})`);if(t.rejectDuplicateMapKeys===!0&&(n&&i.has(a)||!n&&a in o))throw new Error(`${$} found repeat map key "${a}"`);let c=Uo(e,t);if(c===Vi)throw new Error(`${$} found map but not enough entries (got ${s} [no value], expected ${r.value})`);n?i.set(a,c):o[a]=c}return n?i:o}function Uo(r,e){if(r.done())return Vi;let t=r.next();if(t.type===w.break)return dc;if(t.type.terminal)return t.value;if(t.type===w.array)return $3(t,r,e);if(t.type===w.map)return K3(t,r,e);if(t.type===w.tag){if(e.tags&&typeof e.tags[t.value]=="function"){let n=Uo(r,e);return e.tags[t.value](n)}throw new Error(`${$} tag not supported (${t.value})`)}throw new Error("unsupported")}function Ef(r,e){if(!(r instanceof Uint8Array))throw new Error(`${$} data to decode must be a Uint8Array`);e=Object.assign({},z3,e);let t=e.tokenizer||new fc(r,e),n=Uo(t,e);if(n===Vi)throw new Error(`${$} did not find any content to decode`);if(n===dc)throw new Error(`${$} got unexpected break`);return[n,r.subarray(t.pos())]}function tt(r,e){let[t,n]=Ef(r,e);if(n.length>0)throw new Error(`${$} too many terminals, data makes no sense`);return t}var lt=J(Ie(),1);var s1=ee("ipns:utils"),a1=F("/ipns/"),G3=114,c1=async(r,e)=>{if(e==null||r==null){let n=new Error("one or more of the provided parameters are not defined");throw s1.error(n),(0,lt.default)(n,uf)}let t;if(e.pubKey!=null){try{t=cf(e.pubKey)}catch(o){throw s1.error(o),o}if(!(await Jh(e.pubKey)).equals(r))throw(0,lt.default)(new Error("Embedded public key did not match PeerID"),tm)}else r.publicKey!=null&&(t=cf(r.publicKey));if(t!=null)return t;throw(0,lt.default)(new Error("no public key is available"),uf)},l1=(r,e,t)=>{let n=F(e);return ue([r,t,n])},pc=r=>{let e=F("ipns-signature:");return ue([e,r])},Cr=r=>"signatureV1"in r?He.encode({value:F(r.value),signatureV1:r.signatureV1,validityType:r.validityType,validity:F(r.validity),sequence:r.sequence,ttl:r.ttl,pubKey:r.pubKey,signatureV2:r.signatureV2,data:r.data}):He.encode({pubKey:r.pubKey,signatureV2:r.signatureV2,data:r.data});function rt(r){let e=He.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,lt.default)(new Error("missing data or signatureV2"),Rr);let t=f1(e.data),n=vf(t.Value),o=W(t.Validity);if(e.value!=null&&e.signatureV1!=null)return q3(e),{value:n,validityType:He.ValidityType.EOL,validity:o,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:He.ValidityType.EOL,validity:o,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 Fo=r=>ue([a1,r.toBytes()]),Vo=r=>hi(r.slice(a1.length)),u1=(r,e,t,n,o)=>{let i;if(e===He.ValidityType.EOL)i=0;else throw(0,lt.default)(new Error("Unknown validity type"),Ci);return sn({Value:r,Validity:t,ValidityType:i,Sequence:n,TTL:o})},f1=r=>{let e=tt(r);if(e.ValidityType===0)e.ValidityType=He.ValidityType.EOL;else throw(0,lt.default)(new Error("Unknown validity type"),Ci);return Number.isInteger(e.Sequence)&&(e.Sequence=BigInt(e.Sequence)),Number.isInteger(e.TTL)&&(e.TTL=BigInt(e.TTL)),e},vf=r=>{if(r!=null){if(lh(r))return`/ipns/${r.toCID().toString(zr)}`;if(r instanceof Uint8Array){let n=W(r);n.startsWith("/")&&(r=n)}let e=r.toString().trim();if(e.startsWith("/")&&e.length>1)return e;let t=U.asCID(r);if(t!=null)return t.code===G3?`/ipns/${t.toString(zr)}`:`/ipfs/${t.toV1().toString()}`;try{return r instanceof Uint8Array?`/ipfs/${U.decode(r).toV1().toString()}`:`/ipfs/${U.parse(e).toV1().toString()}`}catch{}}throw(0,lt.default)(new Error("Value must be a valid content path starting with /"),em)},q3=r=>{if(r.data==null)throw(0,lt.default)(new Error("Record data is missing"),Q0);let e=f1(r.data);if(!ce(e.Value,r.value??new Uint8Array(0)))throw(0,lt.default)(new Error('Field "value" did not match between protobuf and CBOR'),Rr);if(!ce(e.Validity,r.validity??new Uint8Array(0)))throw(0,lt.default)(new Error('Field "validity" did not match between protobuf and CBOR'),Rr);if(e.ValidityType!==r.validityType)throw(0,lt.default)(new Error('Field "validityType" did not match between protobuf and CBOR'),Rr);if(e.Sequence!==r.sequence)throw(0,lt.default)(new Error('Field "sequence" did not match between protobuf and CBOR'),Rr);if(e.TTL!==r.ttl)throw(0,lt.default)(new Error('Field "ttl" did not match between protobuf and CBOR'),Rr)};var W3=ee("ipns"),j3=qe.code,Y3="/ipns/",zR=Y3.length,h1={v1Compatible:!0};async function p1(r,e,t,n,o=h1){let i=new d1.default(Date.now()+Number(n)),s=He.ValidityType.EOL,[a,c]=n.toString().split("."),u=BigInt(a)*BigInt(1e5)+BigInt(c??"0");return X3(r,e,t,s,i.toString(),u,o)}var X3=async(r,e,t,n,o,i,s=h1)=>{t=BigInt(t);let a=F(o),c=vf(e),u=F(c);if(r.privateKey==null)throw(0,Af.default)(new Error("Missing private key"),rm);let l=await Y0(r.privateKey),f=u1(u,n,a,t,i),m=pc(f),d=await l.sign(m),p;if(r.publicKey!=null){let h=Ze(r.toBytes());(h.code!==j3||!ce(r.publicKey,h.digest))&&(p=r.publicKey)}if(s.v1Compatible===!0){let h=await Z3(l,u,n,a),g={value:c,signatureV1:h,validity:o,validityType:n,sequence:t,ttl:i,signatureV2:d,data:f};return p!=null&&(g.pubKey=p),g}else{let h={value:c,validity:o,validityType:n,sequence:t,ttl:i,signatureV2:d,data:f};return p!=null&&(h.pubKey=p),h}};var Z3=async(r,e,t,n)=>{try{let o=l1(e,t,n);return await r.sign(o)}catch(o){throw W3.error("record signature creation failed",o),(0,Af.default)(new Error("record signature creation failed"),J0)}};var Hi=J(Ie(),1),m1=J(ec(),1);var mc=ee("ipns:validator"),J3=1024*10,Q3=async(r,e)=>{let t=rt(e),n;try{let o=pc(t.data);n=await r.verify(o,t.signatureV2)}catch{n=!1}if(!n)throw mc.error("record signature verification failed"),(0,Hi.default)(new Error("record signature verification failed"),Rr);if(t.validityType===He.ValidityType.EOL){if(m1.default.fromString(t.validity).toDate().getTime()<Date.now())throw mc.error("record has expired"),(0,Hi.default)(new Error("record has expired"),Z0)}else if(t.validityType!=null)throw mc.error("unrecognized validity type"),(0,Hi.default)(new Error("unrecognized validity type"),Ci);mc("ipns record for %s is valid",t.value)};async function yc(r,e){if(e.byteLength>J3)throw(0,Hi.default)(new Error("record too large"),nm);let t=Vo(r),n=rt(e),o=await c1(t,n);await Q3(o,e)}async function*Mi(r){let e=/\r?\n/,t=new TextDecoder("utf8"),n="";for await(let o of r){typeof o=="string"&&(o=new TextEncoder().encode(o)),n+=t.decode(o,{stream:!0});let i=n.split(e);n=i.pop()??"";for(let s=0;s<i.length;s++)yield JSON.parse(i[s])}n+=t.decode(),n!==""&&(yield JSON.parse(n))}var _f=J(g1(),1);var $i=class extends Error{constructor(e){super(e),this.name="TimeoutError"}},kf=class extends Error{constructor(e){super(),this.name="AbortError",this.message=e}},w1=r=>globalThis.DOMException===void 0?new kf(r):new DOMException(r),b1=r=>{let e=r.reason===void 0?w1("This operation was aborted."):r.reason;return e instanceof Error?e:w1(e)};function Ki(r,e){let{milliseconds:t,fallback:n,message:o,customTimers:i={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:m}=e;m.aborted&&l(b1(m)),m.addEventListener("abort",()=>{l(b1(m))})}if(t===Number.POSITIVE_INFINITY){r.then(u,l);return}let f=new $i;s=i.setTimeout.call(void 0,()=>{if(n){try{u(n())}catch(m){l(m)}return}typeof r.cancel=="function"&&r.cancel(),o===!1?u():o instanceof Error?l(o):(f.message=o??`Promise timed out after ${t} milliseconds`,l(f))},t),(async()=>{try{u(await r)}catch(m){l(m)}})()}).finally(()=>{c.clear()});return c.clear=()=>{i.clearTimeout.call(void 0,s),s=void 0},c}function If(r,e,t){let n=0,o=r.length;for(;o>0;){let i=Math.trunc(o/2),s=n+i;t(r[s],e)<=0?(n=++s,o-=i+1):o=i}return n}var Gi=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 o=If(this.#e,n,(i,s)=>s.priority-i.priority);this.#e.splice(o,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 ut=class extends _f.default{#e;#t;#r=0;#s;#c;#p=0;#o;#l;#n;#m;#i=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:Gi,...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#b(){return this.#t||this.#r<this.#s}get#x(){return this.#i<this.#u}#E(){this.#i--,this.#f(),this.emit("next")}#v(){this.#w(),this.#g(),this.#l=void 0}get#A(){let e=Date.now();if(this.#o===void 0){let t=this.#p-e;if(t<0)this.#r=this.#e?this.#i:0;else return this.#l===void 0&&(this.#l=setTimeout(()=>{this.#v()},t)),!0}return!1}#f(){if(this.#n.size===0)return this.#o&&clearInterval(this.#o),this.#o=void 0,this.emit("empty"),this.#i===0&&this.emit("idle"),!1;if(!this.#a){let e=!this.#A;if(this.#b&&this.#x){let t=this.#n.dequeue();return t?(this.emit("active"),t(),e&&this.#g(),!0):!1}}return!1}#g(){this.#t||this.#o!==void 0||(this.#o=setInterval(()=>{this.#w()},this.#c),this.#p=Date.now()+this.#c)}#w(){this.#r===0&&this.#i===0&&this.#o&&(clearInterval(this.#o),this.#o=void 0),this.#r=this.#e?this.#i:0,this.#d()}#d(){for(;this.#f(););}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.#d()}async#S(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,o)=>{this.#n.enqueue(async()=>{this.#i++,this.#r++;try{t.signal?.throwIfAborted();let i=e({signal:t.signal});t.timeout&&(i=Ki(Promise.resolve(i),{milliseconds:t.timeout})),t.signal&&(i=Promise.race([i,this.#S(t.signal)]));let s=await i;n(s),this.emit("completed",s)}catch(i){if(i instanceof $i&&!t.throwOnTimeout){n();return}o(i),this.emit("error",i)}finally{this.#E()}},t),this.emit("add"),this.#f()})}async addAll(e,t){return Promise.all(e.map(async n=>this.add(n,t)))}start(){return this.#a?(this.#a=!1,this.#d(),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.#i===0&&this.#n.size===0||await this.#h("idle")}async#h(e,t){return new Promise(n=>{let o=()=>{t&&!t()||(this.off(e,o),n())};this.on(e,o)})}get size(){return this.#n.size}sizeBy(e){return this.#n.filter(e).length}get pending(){return this.#i}get isPaused(){return this.#a}};function r6(r){return r[Symbol.asyncIterator]!=null}function n6(r){if(r6(r))return(async()=>{for await(let e of r)return e})();for(let e of r)return e}var Fn=n6;var Bf=F("/ipns/");function x1(r){return ce(r.subarray(0,Bf.byteLength),Bf)}var E1=r=>hi(r.slice(Bf.length)),wc=class{client;constructor(e){this.client=e}async*findProviders(e,t={}){yield*We(this.client.getProviders(e,t),n=>({id:n.ID,multiaddrs:n.Addrs??[]}))}async provide(){}async put(e,t,n){if(!x1(e))return;let o=E1(e),i=rt(t);await this.client.putIPNS(o,i,n)}async get(e,t){if(!x1(e))throw new P("Not found","ERR_NOT_FOUND");let n=E1(e);try{let o=await this.client.getIPNS(n,t);return Cr(o)}catch(o){throw o.code==="ERR_BAD_RESPONSE"?new P("Not found","ERR_NOT_FOUND"):o}}},bc=class{client;constructor(e){this.client=e}async findPeer(e,t={}){let n=await Fn(this.client.getPeers(e,t));if(n!=null)return{id:n.ID,multiaddrs:n.Addrs??[]};throw new P("Not found","ERR_NOT_FOUND")}async*getClosestPeers(e,t={}){}};var ft=ee("delegated-routing-v1-http-api-client"),v1={concurrentRequests:4,timeout:3e4},xc=class{started;httpQueue;shutDownController;clientUrl;timeout;contentRouting;peerRouting;constructor(e,t={}){this.started=!1,this.shutDownController=new AbortController,to(1/0,this.shutDownController.signal),this.httpQueue=new ut({concurrency:t.concurrentRequests??v1.concurrentRequests}),this.clientUrl=e instanceof URL?e:new URL(e),this.timeout=t.timeout??v1.timeout,this.contentRouting=new wc(this),this.peerRouting=new bc(this)}get[ai](){return this.contentRouting}get[ci](){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={}){ft("getProviders starts: %c",e);let n=vn([this.shutDownController.signal,t.signal,AbortSignal.timeout(this.timeout)]),o=we(),i=we();this.httpQueue.add(async()=>(o.resolve(),i.promise));try{await o.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 P("No matching records found.","ERR_NOT_FOUND");if(c.status===422)throw new P("Request does not conform to schema or semantic constraints.","ERR_INVALID_REQUEST");if(c.body==null)throw new P("Routing response had no body","ERR_BAD_RESPONSE");if(c.headers.get("Content-Type")==="application/json"){let l=await c.json();for(let f of l.Providers){let m=this.#e(f);m!=null&&(yield m)}}else for await(let l of Mi(js(c.body))){let f=this.#e(l);f!=null&&(yield f)}}catch(s){ft.error("getProviders errored:",s)}finally{n.clear(),i.resolve(),ft("getProviders finished: %c",e)}}async*getPeers(e,t={}){ft("getPeers starts: %c",e);let n=vn([this.shutDownController.signal,t.signal,AbortSignal.timeout(this.timeout)]),o=we(),i=we();this.httpQueue.add(async()=>(o.resolve(),i.promise));try{await o.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 P("No matching records found.","ERR_NOT_FOUND");if(c.status===422)throw new P("Request does not conform to schema or semantic constraints.","ERR_INVALID_REQUEST");if(c.body==null)throw new P("Routing response had no body","ERR_BAD_RESPONSE");if(c.headers.get("Content-Type")==="application/json"){let l=await c.json();for(let f of l.Peers){let m=this.#e(f);m!=null&&(yield m)}}else for await(let l of Mi(js(c.body))){let f=this.#e(l);f!=null&&(yield f)}}catch(s){ft.error("getPeers errored:",s)}finally{n.clear(),i.resolve(),ft("getPeers finished: %c",e)}}async getIPNS(e,t={}){ft("getIPNS starts: %c",e);let n=vn([this.shutDownController.signal,t.signal,AbortSignal.timeout(this.timeout)]),o=we(),i=we();this.httpQueue.add(async()=>(o.resolve(),i.promise));let s=`${this.clientUrl}routing/v1/ipns/${e.toCID().toString()}`;try{await o.promise;let c=await fetch(s,{headers:{Accept:"application/vnd.ipfs.ipns-record"},signal:n});if(ft("getIPNS GET %s %d",s,c.status),c.status===404)throw new P("No matching records found.","ERR_NOT_FOUND");if(c.status===422)throw new P("Request does not conform to schema or semantic constraints.","ERR_INVALID_REQUEST");if(c.body==null)throw new P("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 yc(Fo(e),l),rt(l)}catch(a){throw ft.error("getIPNS GET %s error:",s,a),a}finally{n.clear(),i.resolve(),ft("getIPNS finished: %c",e)}}async putIPNS(e,t,n={}){ft("putIPNS starts: %c",e);let o=vn([this.shutDownController.signal,n.signal,AbortSignal.timeout(this.timeout)]),i=we(),s=we();this.httpQueue.add(async()=>(i.resolve(),s.promise));let a=`${this.clientUrl}routing/v1/ipns/${e.toCID().toString()}`;try{await i.promise;let c=Cr(t),l=await fetch(a,{method:"PUT",headers:{"Content-Type":"application/vnd.ipfs.ipns-record"},body:c,signal:o});if(ft("putIPNS PUT %s %d",a,l.status),l.status!==200)throw new P("PUT ipns response had status other than 200","ERR_BAD_RESPONSE")}catch(c){throw ft.error("putIPNS PUT %s error:",a,c.stack),c}finally{o.clear(),s.resolve(),ft("putIPNS finished: %c",e)}}#e(e){let t=[],n=e.Addrs?.map(pi)??[];return e.Protocols!=null&&t.push(...e.Protocols),e.Protocol!=null&&(t.push(e.Protocol),delete e.Protocol),{...e,Schema:"peer",ID:Je(e.ID),Addrs:n,Protocols:t}}};function A1(r,e={}){return new xc(new URL(r),e)}var S1=F("/ipns/");function _1(r){return ce(r.subarray(0,S1.byteLength),S1)}var Rf=class{client;constructor(e){this.client=A1(e)}async provide(e,t){}async*findProviders(e,t){yield*We(this.client.getProviders(e,t),n=>({id:n.ID,multiaddrs:n.Addrs,protocols:n.Protocols}))}async put(e,t,n){if(!_1(e))return;let o=Vo(e),i=rt(t);await this.client.putIPNS(o,i,n)}async get(e,t){if(!_1(e))throw new P("Not found","ERR_NOT_FOUND");let n=Vo(e);try{let o=await this.client.getIPNS(n,t);return Cr(o)}catch(o){throw o.code==="ERR_BAD_RESPONSE"?new P("Not found","ERR_NOT_FOUND"):o}}async findPeer(e,t){let n=await Fn(this.client.getPeers(e,t));if(n!=null)return{id:n.ID,multiaddrs:n.Addrs??[]};throw new P("Not found","ERR_NOT_FOUND")}async*getClosestPeers(e,t){}};function qi(r){return new Rf(new URL(r))}function Ec(r){let e=[Ot.A];return r==null?e:Array.isArray(r)?r.length===0?e:r:[r]}var Tf=60;function vc(r){return{Status:r.Status??0,TC:r.TC??r.flag_tc??!1,RD:r.RD??r.flag_rd??!1,RA:r.RA??r.flag_ra??!1,AD:r.AD??r.flag_ad??!1,CD:r.CD??r.flag_cd??!1,Question:(r.Question??r.questions??[]).map(e=>({name:e.name,type:Ot[e.type]})),Answer:(r.Answer??r.answers??[]).map(e=>({name:e.name,type:Ot[e.type],TTL:e.TTL??e.ttl??Tf,data:e.data instanceof Uint8Array?W(e.data):e.data}))}}var o6=4;function Nf(r,e={}){let t=new ut({concurrency:e.queryConcurrency??o6});return async(n,o={})=>{let i=new URLSearchParams;i.set("name",n),Ec(o.types).forEach(a=>{i.append("type",a.toString())}),o.onProgress?.(new V("dns:query",{detail:n}));let s=await t.add(async()=>{let a=await fetch(`${r}?${i}`,{headers:{accept:"application/dns-json"},signal:o?.signal});if(a.status!==200)throw new Error(`Unexpected HTTP status: ${a.status} - ${a.statusText}`);let c=vc(await a.json());return o.onProgress?.(new V("dns:response",{detail:c})),c},{signal:o.signal});if(s==null)throw new Error("No DNS response received");return s}}function k1(){return[Nf("https://cloudflare-dns.com/dns-query"),Nf("https://dns.google/resolve")]}var B1=J(Cf(),1);var Lf=class{lru;constructor(e){this.lru=(0,B1.default)(e)}get(e,t){let n=!0,o=[];for(let i of t){let s=this.getAnswers(e,i);if(s.length===0){n=!1;break}o.push(...s)}if(n)return vc({answers:o})}getAnswers(e,t){let n=`${e.toLowerCase()}-${t}`,o=this.lru.get(n);if(o!=null){let i=o.filter(s=>s.expires>Date.now()).map(({value:s})=>({...s,type:Ot[s.type]}));return i.length===0&&this.lru.remove(n),i}return[]}add(e,t){let n=`${e.toLowerCase()}-${t.type}`,o=this.lru.get(n)??[];o.push({expires:Date.now()+(t.TTL??Tf)*1e3,value:t}),this.lru.set(n,o)}remove(e,t){let n=`${e.toLowerCase()}-${t}`;this.lru.remove(n)}clear(){this.lru.clear()}};function R1(r){return new Lf(r)}var i6=1e3,Ac=class{resolvers;cache;constructor(e){this.resolvers={},this.cache=R1(e.cacheSize??i6),Object.entries(e.resolvers??{}).forEach(([t,n])=>{Array.isArray(n)||(n=[n]),t.endsWith(".")||(t=`${t}.`),this.resolvers[t]=n}),this.resolvers["."]==null&&(this.resolvers["."]=k1())}async query(e,t={}){let n=Ec(t.types),o=t.cached!==!1?this.cache.get(e,n):void 0;if(o!=null)return t.onProgress?.(new V("dns:cache",{detail:o})),o;let i=`${e.split(".").pop()}.`,s=(this.resolvers[i]??this.resolvers["."]).sort(()=>Math.random()>.5?-1:1),a=[];for(let c of s){if(t.signal?.aborted===!0)break;try{let u=await c(e,{...t,types:n});for(let l of u.Answer)this.cache.add(e,l);return u}catch(u){a.push(u),t.onProgress?.(new V("dns:error",{detail:u}))}}throw a.length===1?a[0]:new AggregateError(a,`DNS lookup of ${e} ${n} failed`)}};var Ot;(function(r){r[r.A=1]="A",r[r.CNAME=5]="CNAME",r[r.TXT=16]="TXT",r[r.AAAA=28]="AAAA"})(Ot||(Ot={}));function Wi(r={}){return new Ac(r)}var Df=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 Sc(r,e,t,n){let o=new Df(n?.errorMessage,n?.errorCode);return t?.aborted===!0?Promise.reject(o):new Promise((i,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),i(u)},c=()=>{r.removeEventListener(e,a),t?.removeEventListener("abort",c),s(o)};r.addEventListener(e,a),t?.addEventListener("abort",c)})}var _c=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 T1(r,e,t){if(e==null)return r;if(e.aborted)return Promise.reject(new _c(t?.errorMessage,t?.errorCode));let n,o=new _c(t?.errorMessage,t?.errorCode);try{return await Promise.race([r,new Promise((i,s)=>{n=()=>{s(o)},e.addEventListener("abort",n)})])}finally{n!=null&&e.removeEventListener("abort",n)}}var kc=class{deferred;signal;where;constructor(e,t){this.signal=t,this.deferred=we(),this.where=e,this.onAbort=this.onAbort.bind(this),this.signal?.addEventListener("abort",this.onAbort)}onAbort(){this.deferred.reject(new Fr)}cleanup(){this.signal?.removeEventListener("abort",this.onAbort)}};function s6(){return`${parseInt(String(Math.random()*1e9),10).toString()}${Date.now()}`}var Ic=class{id;fn;options;priority;recipients;status;timeline;controller;constructor(e,t,n=0){this.id=s6(),this.status="queued",this.fn=e,this.priority=n,this.options=t,this.recipients=[],this.timeline={created:Date.now()},this.controller=new AbortController,to(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 Fr)}async join(e={}){let t=new kc(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 T1(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 a6(r,e,t){let n=0,o=r.length;for(;o>0;){let i=Math.trunc(o/2),s=n+i;t(r[s],e)<=0?(n=++s,o-=i+1):o=i}return n}var ji=class extends Ns{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=a6(this.queue,e,(n,o)=>o.priority-n.priority);this.queue.splice(t,0,e)}async add(e,t){t?.signal?.throwIfAborted();let n=new Ic(e,t,t?.priority),o=n.join(t).then(i=>(this.safeDispatchEvent("completed",{detail:i}),i)).catch(i=>{throw this.safeDispatchEvent("error",{detail:i}),i});return this.enqueue(n),this.safeDispatchEvent("add"),this.tryToStartAnother(),o}clear(){this.queue.splice(0,this.queue.length)}abort(){this.queue.forEach(e=>{e.abort(new Fr)}),this.clear()}async onEmpty(e){this.size!==0&&await Sc(this,"empty",e?.signal)}async onSizeLessThan(e,t){this.size<e||await Sc(this,"next",t?.signal,{filter:()=>this.size<e})}async onIdle(e){this.pending===0&&this.size===0||await Sc(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=Tt({objectMode:!0}),n=c=>{c!=null?this.abort():this.clear(),t.end(c)},o=c=>{c.detail!=null&&t.push(c.detail)},i=c=>{n(c.detail)},s=()=>{n()},a=()=>{n(new P("Queue aborted","ERR_QUEUE_ABORTED"))};this.addEventListener("completed",o),this.addEventListener("error",i),this.addEventListener("idle",s),e?.signal?.addEventListener("abort",a);try{yield*t}finally{this.removeEventListener("completed",o),this.removeEventListener("error",i),this.removeEventListener("idle",s),e?.signal?.removeEventListener("abort",a),n()}}};var D1="/pin/",N1="/pinned-block/",Pf=zr,C1=1;function L1(r){return r.version===0&&(r=r.toV1()),new Be(`${D1}${r.toString(Pf)}`)}var Bc=class{datastore;blockstore;dagWalkers;constructor(e,t,n){this.datastore=e,this.blockstore=t,this.dagWalkers=n}async*add(e,t={}){let n=L1(e);if(await this.datastore.has(n))throw new Error("Already pinned");let o=Math.round(t.depth??1/0);if(o<0)throw new Error("Depth must be greater than or equal to 0");let i=new ji({concurrency:C1});for await(let a of this.#e(e,i,{...t,depth:o}))await this.#t(a,c=>c.pinnedBy.find(u=>ce(u,e.bytes))!=null?!1:(c.pinCount++,c.pinnedBy.push(e.bytes),!0),t),yield a;let s={depth:o,metadata:t.metadata??{}};await this.datastore.put(n,sn(s),t)}async*#e(e,t,n){if(n.depth===-1)return;let o=this.dagWalkers[e.code];if(o==null)throw new Error(`No dag walker found for cid codec ${e.code}`);let i=await this.blockstore.get(e,n);yield e;for await(let s of o.walk(i))yield*await t.add(async()=>this.#e(s,t,{...n,depth:n.depth-1}))}async#t(e,t,n){let o=new Be(`${N1}${Pf.encode(e.multihash.bytes)}`),i={pinCount:0,pinnedBy:[]};try{i=tt(await this.datastore.get(o,n))}catch(a){if(a.code!=="ERR_NOT_FOUND")throw a}if(t(i)){if(i.pinCount===0&&await this.datastore.has(o)){await this.datastore.delete(o);return}await this.datastore.put(o,sn(i),n),n.onProgress?.(new V("helia:pin:add",e))}}async*rm(e,t={}){let n=L1(e),o=await this.datastore.get(n,t),i=tt(o);await this.datastore.delete(n,t);let s=new ji({concurrency:C1});for await(let a of this.#e(e,s,{...t,depth:i.depth}))await this.#t(a,c=>(c.pinCount--,c.pinnedBy=c.pinnedBy.filter(u=>ce(u,e.bytes)),!0),{...t,depth:i.depth}),yield a}async*ls(e={}){for await(let{key:t,value:n}of this.datastore.query({prefix:D1+(e.cid!=null?`${e.cid.toString(zr)}`:"")},e)){let o=U.parse(t.toString().substring(5),zr),i=tt(n);yield{cid:o,...i}}}async isPinned(e,t={}){let n=new Be(`${N1}${Pf.encode(e.multihash.bytes)}`);return this.datastore.has(n,t)}};function Of(r,e){let t={[Symbol.iterator]:()=>t,next:()=>{let n=r.next(),o=n.value;return n.done===!0||o==null?{done:!0,value:void 0}:{done:!1,value:e(o)}}};return t}var Ho=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 Of(this.set.entries(),e=>{let t=Je(e[0]);return[t,t]})}forEach(e){this.set.forEach(t=>{let n=Je(t);e(n,n,this)})}has(e){return this.set.has(e.toString())}values(){return Of(this.set.values(),e=>Je(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 Rc=class{log;routers;constructor(e,t){this.log=e.logger.forComponent("helia:routing"),this.routers=t.routers??[]}async start(){await Vr(...this.routers)}async stop(){await Hr(...this.routers)}async*findProviders(e,t={}){if(this.routers.length===0)throw new P("No content routers available","ERR_NO_ROUTERS_AVAILABLE");let n=new Ho;for await(let o of pr(...Mo(this.routers,"findProviders").map(i=>i.findProviders(e,t))))o!=null&&(n.has(o.id)||(n.add(o.id),yield o))}async provide(e,t={}){if(this.routers.length===0)throw new P("No content routers available","ERR_NO_ROUTERS_AVAILABLE");await Promise.all(Mo(this.routers,"provide").map(async n=>{await n.provide(e,t)}))}async put(e,t,n){await Promise.all(Mo(this.routers,"put").map(async o=>{await o.put(e,t,n)}))}async get(e,t){return Promise.any(Mo(this.routers,"get").map(async n=>n.get(e,t)))}async findPeer(e,t){if(this.routers.length===0)throw new P("No peer routers available","ERR_NO_ROUTERS_AVAILABLE");let n=this,o=pr(...Mo(this.routers,"findPeer").map(i=>async function*(){try{yield await i.findPeer(e,t)}catch(s){n.log.error(s)}}()));for await(let i of o)if(i!=null)return i;throw new P("Could not find peer in routing","ERR_NOT_FOUND")}async*getClosestPeers(e,t={}){if(this.routers.length===0)throw new P("No peer routers available","ERR_NO_ROUTERS_AVAILABLE");let n=new Ho;for await(let o of pr(...Mo(this.routers,"getClosestPeers").map(i=>i.getClosestPeers(e,t))))o!=null&&(n.has(o.id)||(n.add(o.id),yield o))}};function Mo(r,e){return r.filter(t=>t[e]!=null)}var an={},zo=r=>{r.addEventListener("message",e=>{zo.dispatchEvent("message",r,e)}),r.port!=null&&r.port.addEventListener("message",e=>{zo.dispatchEvent("message",r,e)})};zo.addEventListener=(r,e)=>{an[r]==null&&(an[r]=[]),an[r].push(e)};zo.removeEventListener=(r,e)=>{an[r]!=null&&(an[r]=an[r].filter(t=>t===e))};zo.dispatchEvent=function(r,e,t){an[r]!=null&&an[r].forEach(n=>n(e,t))};var Uf=zo;var Ff="lock:worker:request-read",Vf="lock:worker:release-read",Hf="lock:master:grant-read",Mf="lock:worker:request-write",zf="lock:worker:release-write",$f="lock:master:grant-write";var P1=(r=21)=>Math.random().toString().substring(2);var O1=(r,e,t,n,o)=>(i,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()=>{i.postMessage({type:o,name:a.name,identifier:a.identifier}),await new Promise(c=>{let u=l=>{if(l==null||l.data==null)return;let f={type:l.data.type,name:l.data.name,identifier:l.data.identifier};f.type===n&&f.identifier===a.identifier&&(i.removeEventListener("message",u),c())};i.addEventListener("message",u)})}}}))},U1=(r,e,t,n)=>async()=>{let o=P1();return globalThis.postMessage({type:e,identifier:o,name:r}),new Promise(i=>{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===o&&(globalThis.removeEventListener("message",s),i(()=>{globalThis.postMessage({type:n,identifier:o,name:r})}))};globalThis.addEventListener("message",s)})},c6={singleProcess:!1},F1=r=>{if(r=Object.assign({},c6,r),!!globalThis.document||r.singleProcess){let t=new EventTarget;return Uf.addEventListener("message",O1(t,"requestReadLock",Ff,Vf,Hf)),Uf.addEventListener("message",O1(t,"requestWriteLock",Mf,zf,$f)),t}return{isWorker:!0,readLock:t=>U1(t,Ff,Hf,Vf),writeLock:t=>U1(t,Mf,$f,zf)}};var Vn={},cn;async function Kf(r,e){let t,n=new Promise(o=>{t=o});return r.add(async()=>Ki((async()=>{await new Promise(o=>{t(()=>{o()})})})(),{milliseconds:e.timeout})),n}var l6=(r,e)=>{if(cn.isWorker===!0)return{readLock:cn.readLock(r,e),writeLock:cn.writeLock(r,e)};let t=new ut({concurrency:1}),n;return{async readLock(){if(n!=null)return Kf(n,e);n=new ut({concurrency:e.concurrency,autoStart:!1});let o=n,i=Kf(n,e);return t.add(async()=>{o.start(),await o.onIdle().then(()=>{n===o&&(n=null)})}),i},async writeLock(){return n=null,Kf(t,e)}}},u6={name:"lock",concurrency:1/0,timeout:846e5,singleProcess:!1};function Gf(r){let e=Object.assign({},u6,r);return cn==null&&(cn=F1(e),cn.isWorker!==!0&&(cn.addEventListener("requestReadLock",t=>{Vn[t.data.name]!=null&&Vn[t.data.name].readLock().then(async n=>t.data.handler().finally(()=>{n()}))}),cn.addEventListener("requestWriteLock",async t=>{Vn[t.data.name]!=null&&Vn[t.data.name].writeLock().then(async n=>t.data.handler().finally(()=>{n()}))}))),Vn[e.name]==null&&(Vn[e.name]=l6(e.name,e)),Vn[e.name]}var Tc=class{lock;child;pins;started;constructor(e,t,n={}){this.child=e,this.pins=t,this.lock=Gf({singleProcess:n.holdGcLock}),this.started=!1}isStarted(){return this.started}async start(){await Vr(this.child),this.started=!0}async stop(){await Hr(this.child),this.started=!1}unwrap(){return this.child}async put(e,t,n={}){let o=await this.lock.readLock();try{return await this.child.put(e,t,n)}finally{o()}}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 o=this;yield*this.child.deleteMany(async function*(){for await(let i of e){if(await o.pins.isPinned(i))throw new Error("CID was pinned");yield i}}(),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 V1=42;function f6(r){return r instanceof ArrayBuffer?new Uint8Array(r,0,r.byteLength):r}function d6(r){if(r.asCID!==r&&r["/"]!==r.bytes)return null;let e=U.asCID(r);if(!e)return null;let t=new Uint8Array(e.bytes.byteLength+1);return t.set(e.bytes,1),[new B(w.tag,V1),new B(w.bytes,t)]}function h6(){throw new Error("`undefined` is not supported by the IPLD Data Model and cannot be encoded")}function p6(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 qf={float64:!0,typeEncoders:{Object:d6,undefined:h6,number:p6}},dC={...qf,typeEncoders:{...qf.typeEncoders}};function m6(r){if(r[0]!==0)throw new Error("Invalid CID for CBOR tag 42; expected leading 0x00");return U.decode(r.subarray(1))}var Nc={allowIndefinite:!1,coerceUndefinedToNull:!0,allowNaN:!1,allowInfinity:!1,allowBigInt:!0,strict:!0,useMaps:!1,rejectDuplicateMapKeys:!0,tags:[]};Nc.tags[V1]=m6;var hC={...Nc,tags:Nc.tags.slice()};var ln=113,Yi=r=>sn(r,qf),Hn=r=>tt(f6(r),Nc);var Wf=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),o=[];for(let i=0;i<n.length;i++)o[i]=n.charCodeAt(i);e.push(o)}[w.negint.major](e,t){this[w.uint.major](e,t)}[w.bytes.major](e,t){throw new Error(`${Tr} unsupported type: Uint8Array`)}[w.string.major](e,t){this.prefix(e);let n=rc(JSON.stringify(t.value));e.push(n.length>32?Li(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(`${Tr} 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),o=[],i=!1;for(let s=0;s<n.length;s++)o[s]=n.charCodeAt(s),!i&&(o[s]===46||o[s]===101||o[s]===69)&&(i=!0);i||(o.push(46),o.push(48)),e.push(o)}};function y6(r,e){if(Array.isArray(r[0])||Array.isArray(e[0]))throw new Error(`${Tr} 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(`${Tr} non-string map keys are not supported`);if(t<n)return-1;if(t>n)return 1;throw new Error(`${Tr} unexpected duplicate map keys, this is not supported`)}var g6={addBreakTokens:!0,mapSorter:y6};function Zi(r,e){return e=Object.assign({},g6,e),xf(r,new Wf,e)}var un=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(`${$} 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(`${$} unexpected token at position ${this._pos}, expected to find '${String.fromCharCode(...e)}'`)}parseNumber(){let e=this._pos,t=!1,n=!1,o=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 B(w.uint,0,this._pos-e);if(o([48,49,50,51,52,53,54,55,56,57]),t&&this._pos===e+1)throw new Error(`${$} unexpected token at position ${this._pos}`);if(!this.done()&&this.ch()===46){if(n)throw new Error(`${$} unexpected token at position ${this._pos}`);n=!0,this._pos++,o([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++,o([48,49,50,51,52,53,54,55,56,57]));let i=String.fromCharCode.apply(null,this.data.subarray(e,this._pos)),s=parseFloat(i);return n?new B(w.float,s,this._pos-e):this.options.allowBigInt!==!0||Number.isSafeInteger(s)?new B(s>=0?w.uint:w.negint,s,this._pos-e):new B(s>=0?w.uint:w.negint,BigInt(i),this._pos-e)}parseString(){if(this.ch()!==34)throw new Error(`${$} unexpected character at position ${this._pos}; this shouldn't happen`);this._pos++;for(let i=this._pos,s=0;i<this.data.length&&s<65536;i++,s++){let a=this.data[i];if(a===92||a<32||a>=128)break;if(a===34){let c=String.fromCharCode.apply(null,this.data.subarray(this._pos,i));return this._pos=i+1,new B(w.string,c,s)}}let e=this._pos,t=[],n=()=>{if(this._pos+4>=this.data.length)throw new Error(`${$} unexpected end of unicode escape sequence at position ${this._pos}`);let i=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(`${$} unexpected unicode escape character at position ${this._pos}`);i=i*16+a,this._pos++}return i},o=()=>{let i=this.ch(),s=null,a=i>239?4:i>223?3:i>191?2:1;if(this._pos+a>this.data.length)throw new Error(`${$} unexpected unicode sequence at position ${this._pos}`);let c,u,l,f;switch(a){case 1:i<128&&(s=i);break;case 2:c=this.data[this._pos+1],(c&192)===128&&(f=(i&31)<<6|c&63,f>127&&(s=f));break;case 3:c=this.data[this._pos+1],u=this.data[this._pos+2],(c&192)===128&&(u&192)===128&&(f=(i&15)<<12|(c&63)<<6|u&63,f>2047&&(f<55296||f>57343)&&(s=f));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&&(f=(i&15)<<18|(c&63)<<12|(u&63)<<6|l&63,f>65535&&f<1114112&&(s=f))}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 i=this.ch(),s;switch(i){case 92:if(this._pos++,this.done())throw new Error(`${$} 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(`${$} unexpected string escape character at position ${this._pos}`)}break;case 34:return this._pos++,new B(w.string,df(t),this._pos-e);default:if(i<32)throw new Error(`${$} invalid control character at position ${this._pos}`);i<128?(t.push(i),this._pos++):o()}}throw new Error(`${$} unexpected end of string at position ${this._pos}`)}parseValue(){switch(this.ch()){case 123:return this.modeStack.push("obj-start"),this._pos++,new B(w.map,1/0,1);case 91:return this.modeStack.push("array-start"),this._pos++,new B(w.array,1/0,1);case 34:return this.parseString();case 110:return this.expect([110,117,108,108]),new B(w.null,null,4);case 102:return this.expect([102,97,108,115,101]),new B(w.false,!1,5);case 116:return this.expect([116,114,117,101]),new B(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(`${$} 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 B(w.break,void 0,1);if(this.ch()!==44)throw new Error(`${$} 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 B(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 B(w.break,void 0,1);if(this.ch()!==44)throw new Error(`${$} 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 B(w.break,void 0,1);let e=this.parseString();if(this.skipWhitespace(),this.ch()!==58)throw new Error(`${$} 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(`${$} unexpected parse state at position ${this._pos}; this shouldn't happen`)}}};function Ji(r,e){return e=Object.assign({tokenizer:new un(r,e)},e),tt(r,e)}function w6(r){return r instanceof ArrayBuffer?new Uint8Array(r,0,r.byteLength):r}function b6(r){if(r.asCID!==r&&r["/"]!==r.bytes)return null;let e=U.asCID(r);if(!e)return null;let t=e.toString();return[new B(w.map,1/0,1),new B(w.string,"/",1),new B(w.string,t,t.length),new B(w.break,void 0,1)]}function Cc(r){let e=Jt.encode(r).slice(1);return[new B(w.map,1/0,1),new B(w.string,"/",1),new B(w.map,1/0,1),new B(w.string,"bytes",5),new B(w.string,e,e.length),new B(w.break,void 0,1),new B(w.break,void 0,1)]}function qt(r){return Cc(new Uint8Array(r.buffer,r.byteOffset,r.byteLength))}function x6(r){return Cc(new Uint8Array(r))}function E6(){throw new Error("`undefined` is not supported by the IPLD Data Model and cannot be encoded")}function v6(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 A6={typeEncoders:{Object:b6,Buffer:Cc,Uint8Array:Cc,Int8Array:qt,Uint16Array:qt,Int16Array:qt,Uint32Array:qt,Int32Array:qt,Float32Array:qt,Float64Array:qt,Uint8ClampedArray:qt,BigInt64Array:qt,BigUint64Array:qt,DataView:qt,ArrayBuffer:x6,undefined:E6,number:v6}},jf=class extends un{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 B(w.tag,42,0)}if(n.type===w.map){let o=this._next();if(o.type===w.string&&o.value==="bytes"){let i=this._next();if(i.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=Jt.decode(`m${i.value}`);return new B(w.bytes,s,i.value.length)}this.tokenBuffer.push(i)}this.tokenBuffer.push(o)}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]=U.parse;var fn=297,M1=r=>Zi(r,A6),Lc=r=>{let e=w6(r),t=Object.assign(Yf,{tokenizer:new jf(e,Yf)});return Ji(e,t)};var TC=new TextDecoder;var NC=new TextEncoder;var Ne={};ve(Ne,{code:()=>ye,createLink:()=>Z1,createNode:()=>X1,decode:()=>be,encode:()=>ne,name:()=>D6,prepare:()=>_e,validate:()=>Jf});var S6=new TextDecoder;function Xf(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 o=r[e++];if(t+=n<28?(o&127)<<n:(o&127)*2**n,o<128)break}return[t,e]}function Pc(r,e){let t;[t,e]=Xf(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 z1(r,e){let t;return[t,e]=Xf(r,e),[t&7,t>>3,e]}function _6(r){let e={},t=r.length,n=0;for(;n<t;){let o,i;if([o,i,n]=z1(r,n),i===1){if(e.Hash)throw new Error("protobuf: (PBLink) duplicate Hash section");if(o!==2)throw new Error(`protobuf: (PBLink) wrong wireType (${o}) 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]=Pc(r,n)}else if(i===2){if(e.Name!==void 0)throw new Error("protobuf: (PBLink) duplicate Name section");if(o!==2)throw new Error(`protobuf: (PBLink) wrong wireType (${o}) for Name`);if(e.Tsize!==void 0)throw new Error("protobuf: (PBLink) invalid order, found Tsize before Name");let s;[s,n]=Pc(r,n),e.Name=S6.decode(s)}else if(i===3){if(e.Tsize!==void 0)throw new Error("protobuf: (PBLink) duplicate Tsize section");if(o!==0)throw new Error(`protobuf: (PBLink) wrong wireType (${o}) for Tsize`);[e.Tsize,n]=Xf(r,n)}else throw new Error(`protobuf: (PBLink) invalid fieldNumber, expected 1, 2 or 3, got ${i}`)}if(n>t)throw new Error("protobuf: (PBLink) unexpected end of data");return e}function $1(r){let e=r.length,t=0,n,o=!1,i;for(;t<e;){let a,c;if([a,c,t]=z1(r,t),a!==2)throw new Error(`protobuf: (PBNode) invalid wireType, expected 2, got ${a}`);if(c===1){if(i)throw new Error("protobuf: (PBNode) duplicate Data section");[i,t]=Pc(r,t),n&&(o=!0)}else if(c===2){if(o)throw new Error("protobuf: (PBNode) duplicate Links section");n||(n=[]);let u;[u,t]=Pc(r,t),n.push(_6(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 i&&(s.Data=i),s.Links=n||[],s}var G1=new TextEncoder,K1=2**32,k6=2**31;function I6(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=Qi(e,t,r.Tsize)-1,e[t]=24}if(typeof r.Name=="string"){let n=G1.encode(r.Name);t-=n.length,e.set(n,t),t=Qi(e,t,n.length)-1,e[t]=18}return r.Hash&&(t-=r.Hash.length,e.set(r.Hash,t),t=Qi(e,t,r.Hash.length)-1,e[t]=10),e.length-t}function q1(r){let e=R6(r),t=new Uint8Array(e),n=e;if(r.Data&&(n-=r.Data.length,t.set(r.Data,n),n=Qi(t,n,r.Data.length)-1,t[n]=10),r.Links)for(let o=r.Links.length-1;o>=0;o--){let i=I6(r.Links[o],t.subarray(0,n));n-=i,n=Qi(t,n,i)-1,t[n]=18}return t}function B6(r){let e=0;if(r.Hash){let t=r.Hash.length;e+=1+t+$o(t)}if(typeof r.Name=="string"){let t=G1.encode(r.Name).length;e+=1+t+$o(t)}return typeof r.Tsize=="number"&&(e+=1+$o(r.Tsize)),e}function R6(r){let e=0;if(r.Data){let t=r.Data.length;e+=1+t+$o(t)}if(r.Links)for(let t of r.Links){let n=B6(t);e+=1+n+$o(n)}return e}function Qi(r,e,t){e-=$o(t);let n=e;for(;t>=k6;)r[e++]=t&127|128,t/=128;for(;t>=128;)r[e++]=t&127|128,t>>>=7;return r[e]=t,n}function $o(r){return r%2===0&&r++,Math.floor((T6(r)+6)/7)}function T6(r){let e=0;return r>=K1&&(r=Math.floor(r/K1),e=32),r>=65536&&(r>>>=16,e+=16),r>=256&&(r>>>=8,e+=8),e+N6[r]}var N6=[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 C6=["Data","Links"],L6=["Hash","Name","Tsize"],Zf=new TextEncoder;function j1(r,e){if(r===e)return 0;let t=r.Name?Zf.encode(r.Name):[],n=e.Name?Zf.encode(e.Name):[],o=t.length,i=n.length;for(let s=0,a=Math.min(o,i);s<a;++s)if(t[s]!==n[s]){o=t[s],i=n[s];break}return o<i?-1:i<o?1:0}function W1(r,e){return!Object.keys(r).some(t=>!e.includes(t))}function Y1(r){if(typeof r.asCID=="object"){let t=U.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=U.asCID(r.Hash);try{t||(typeof r.Hash=="string"?t=U.parse(r.Hash):r.Hash instanceof Uint8Array&&(t=U.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 _e(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=Zf.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(Y1),e.Links.sort(j1);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(!W1(r,C6))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(!W1(t,L6))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&&j1(t,r.Links[e-1])===-1)throw new TypeError("Invalid DAG-PB form (links must be sorted by Name bytes)")}}function X1(r,e=[]){return _e({Data:r,Links:e})}function Z1(r,e,t){return Y1({Hash:t,Name:r,Tsize:e})}function J1(r){return r instanceof ArrayBuffer?new Uint8Array(r,0,r.byteLength):r}var D6="dag-pb",ye=112;function ne(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),q1(e)}function be(r){let e=J1(r),t=$1(e),n={};return t.Data&&(n.Data=t.Data),t.Links&&(n.Links=t.Links.map(o=>{let i={};try{i.Hash=U.decode(o.Hash)}catch{}if(!i.Hash)throw new Error("Invalid Hash field found in link, expected CID");return o.Name!==void 0&&(i.Name=o.Name),o.Tsize!==void 0&&(i.Tsize=o.Tsize),i})),n}var P6={codec:ye,*walk(r){yield*be(r).Links.map(t=>t.Hash)}},O6={codec:ge,*walk(){}},Q1=42,U6={codec:ln,*walk(r){let e=[],t=[];t[Q1]=n=>{if(n[0]!==0)throw new Error("Invalid CID for CBOR tag 42; expected leading 0x00");let o=U.decode(n.subarray(1));return e.push(o),o},tt(r,{tags:t}),yield*e}},Qf=class extends un{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 B(w.tag,42,0)}if(n.type===w.map){let o=this._next();if(o.type===w.string&&o.value==="bytes"){let i=this._next();if(i.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=Jt.decode(`m${i.value}`);return new B(w.bytes,s,i.value.length)}this.tokenBuffer.push(i)}this.tokenBuffer.push(o)}this.tokenBuffer.push(n)}this.tokenBuffer.push(t)}return e}},F6={codec:fn,*walk(r){let e=[],t=[];t[Q1]=n=>{let o=U.parse(n);return e.push(o),o},Ji(r,{tags:t,tokenizer:new Qf(r,{tags:t,allowIndefinite:!0,allowUndefined:!0,allowNaN:!0,allowInfinity:!0,allowBigInt:!0,strict:!1,rejectDuplicateMapKeys:!1})}),yield*e}},V6={codec:$r,*walk(){}};function ey(r=[]){let e={};return[P6,O6,U6,F6,V6,...r].forEach(t=>{e[t.codec]=t}),e}var ed=new Be("/version"),ty=1;async function ry(r){if(!await r.has(ed)){await r.put(ed,F(`${ty}`));return}let e=await r.get(ed),t=W(e);if(parseInt(t,10)!==ty)throw new Error("Unknown datastore version, a datastore migration may be required")}function ny(r=[]){let e={};return[ae,Ol,qe,...r].forEach(t=>{e[t.code]=t}),e}var ar=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:o}of e)await this.put(n,o,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 Mn={};ve(Mn,{abortedError:()=>K6,closeFailedError:()=>M6,deleteFailedError:()=>rd,getFailedError:()=>z6,hasFailedError:()=>$6,notFoundError:()=>dn,openFailedError:()=>H6,putFailedError:()=>td});var Lr=J(Ie(),1);function H6(r){return r=r??new Error("Open failed"),(0,Lr.default)(r,"ERR_OPEN_FAILED")}function M6(r){return r=r??new Error("Close failed"),(0,Lr.default)(r,"ERR_CLOSE_FAILED")}function td(r){return r=r??new Error("Put failed"),(0,Lr.default)(r,"ERR_PUT_FAILED")}function z6(r){return r=r??new Error("Get failed"),(0,Lr.default)(r,"ERR_GET_FAILED")}function rd(r){return r=r??new Error("Delete failed"),(0,Lr.default)(r,"ERR_DELETE_FAILED")}function $6(r){return r=r??new Error("Has failed"),(0,Lr.default)(r,"ERR_HAS_FAILED")}function dn(r){return r=r??new Error("Not Found"),(0,Lr.default)(r,"ERR_NOT_FOUND")}function K6(r){return r=r??new Error("Aborted"),(0,Lr.default)(r,"ERR_ABORTED")}var oy=0,Oc=class extends ar{put(e){return e}get(e){if(e.code===oy)return e.multihash.digest;throw dn()}has(e){return e.code===oy}delete(){}*getAll(){}};function G6(r){return r[Symbol.asyncIterator]!=null}function q6(r,e){if(G6(r))return async function*(){for await(let a of r)await e(a)&&(yield a)}();let t=Yn(r),{value:n,done:o}=t.next();if(o===!0)return function*(){}();let i=e(n);if(typeof i.then=="function")return async function*(){await i&&(yield n);for await(let a of t)await e(a)&&(yield a)}();let s=e;return function*(){i===!0&&(yield n);for(let a of t)s(a)&&(yield a)}()}var dt=q6;var W6=ee("blockstore:core:tiered"),es=class extends ar{stores;constructor(e){super(),this.stores=e.slice()}async put(e,t,n){try{return await Promise.all(this.stores.map(async o=>{await o.put(e,t,n)})),e}catch(o){throw td(o)}}async get(e,t){for(let n of this.stores)try{let o=await n.get(e,t);if(o!=null)return o}catch(o){W6.error(o)}throw dn()}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 rd(n)}}async*putMany(e,t={}){let n,o=this.stores.map(i=>{let s=Tt({objectMode:!0});return Ft(i.putMany(s,t)).catch(a=>{n=a}),s});try{for await(let i of e){if(n!=null)throw n;o.forEach(s=>s.push(i)),yield i.cid}}finally{o.forEach(i=>i.end())}}async*deleteMany(e,t={}){let n,o=this.stores.map(i=>{let s=Tt({objectMode:!0});return Ft(i.deleteMany(s,t)).catch(a=>{n=a}),s});try{for await(let i of e){if(n!=null)throw n;o.forEach(s=>s.push(i)),yield i}}finally{o.forEach(i=>i.end())}}async*getAll(e){let t=new Set;yield*dt(pr(...this.stores.map(n=>n.getAll(e))),n=>{let o=n.cid.toString();return t.has(o)?!1:(t.add(o),!0)})}};function j6(r){return typeof r.retrieve=="function"}function Y6(r){return typeof r.announce=="function"}var Uc=class{child;blockRetrievers;blockAnnouncers;hashers;started;log;constructor(e){this.log=e.logger.forComponent("helia:networked-storage"),this.child=new es([new Oc,e.blockstore]),this.blockRetrievers=(e.blockBrokers??[]).filter(j6),this.blockAnnouncers=(e.blockBrokers??[]).filter(Y6),this.hashers=e.hashers??{},this.started=!1}isStarted(){return this.started}async start(){await Vr(this.child,...new Set([...this.blockRetrievers,...this.blockAnnouncers])),this.started=!0}async stop(){await Hr(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(o=>{o.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=dt(e,async({cid:i})=>{let s=await this.child.has(i);return s&&t.onProgress?.(new V("blocks:put-many:duplicate",i)),!s}),o=El(n,({cid:i,block:s})=>{t.onProgress?.(new V("blocks:put-many:providers:notify",i)),this.blockAnnouncers.forEach(a=>{a.announce(i,s,t)})});t.onProgress?.(new V("blocks:put-many:blockstore:put-many")),yield*this.child.putMany(o,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 iy(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(o=>{o.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(El(e,async n=>{if(t.offline!==!0&&!await this.child.has(n)){t.onProgress?.(new V("blocks:get-many:providers:get",n));let o=await iy(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,o,t),t.onProgress?.(new V("blocks:get-many:providers:notify",n)),this.blockAnnouncers.forEach(i=>{i.announce(n,o,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)}},X6=(r,e)=>{if(e==null)throw new P(`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(!ce(n.digest,r.multihash.digest))throw new P("Hash of downloaded block did not match multihash from passed CID","ERR_HASH_MISMATCH")}};async function iy(r,e,t,n){let o=X6(r,t),i=new AbortController,s=vn([i.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 o(l),c=!0}});return c||await o(u),u}catch(c){throw n.log.error("could not retrieve verified block for %c",r,c),c}}))}finally{s.clear()}}var Fc=class{blockstore;datastore;pins;logger;routing;dagWalkers;hashers;dns;log;constructor(e){this.logger=e.logger??wh(),this.log=this.logger.forComponent("helia"),this.hashers=ny(e.hashers),this.dagWalkers=ey(e.dagWalkers),this.dns=e.dns??Wi();let t={blockstore:e.blockstore,datastore:e.datastore,hashers:this.hashers,dagWalkers:this.dagWalkers,logger:this.logger,blockBrokers:[],dns:this.dns,...e.components??{}};t.blockBrokers=e.blockBrokers.map(o=>o(t));let n=new Uc(t);this.pins=new Bc(e.datastore,n,this.dagWalkers),this.blockstore=new Tc(n,this.pins,{holdGcLock:e.holdGcLock??!0}),this.datastore=e.datastore,this.routing=new Rc(t,{routers:(e.routers??[]).flatMap(o=>{let i=[o];return o[ai]!=null&&i.push(o[ai]),o[ci]!=null&&i.push(o[ci]),i})})}async start(){await ry(this.datastore),await Vr(this.blockstore,this.datastore,this.routing)}async stop(){await Hr(this.blockstore,this.datastore,this.routing)}async gc(e={}){let t=await this.blockstore.lock.writeLock();try{let n=this,o=this.blockstore.unwrap();this.log("gc start"),await Ft(o.deleteMany(async function*(){for await(let{cid:i}of o.getAll())try{if(await n.pins.isPinned(i,e))continue;yield i,e.onProgress?.(new V("helia:gc:deleted",i))}catch(s){n.log.error("Error during gc",s),e.onProgress?.(new V("helia:gc:error",s))}}()))}finally{t()}this.log("gc finished")}};var ts=class extends ar{data;constructor(){super(),this.data=new Map}put(e,t){return this.data.set(Fe.encode(e.multihash.bytes),t),e}get(e){let t=this.data.get(Fe.encode(e.multihash.bytes));if(t==null)throw dn();return t}has(e){return this.data.has(Fe.encode(e.multihash.bytes))}async delete(e){this.data.delete(Fe.encode(e.multihash.bytes))}async*getAll(){for(let[e,t]of this.data.entries())yield{cid:U.createV1(ge,Ze(Fe.decode(e))),block:t}}};var FL={...Mn};var sy=J(Ie(),1);function Vc(r){return r=r??new Error("Not Found"),(0,sy.default)(r,"ERR_NOT_FOUND")}var ay="SHARDING";function J6(r){return r[Symbol.asyncIterator]!=null}function Q6(r){if(J6(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 Ko=Q6;function ev(r){return r[Symbol.asyncIterator]!=null}function tv(r,e){return ev(r)?async function*(){yield*(await Ko(r)).sort(e)}():function*(){yield*Ko(r).sort(e)}()}var Hc=tv;var Dr=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:o}of e)await this.put(n,o,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,o){e.push({key:n,value:o})},delete(n){t.push(n)},commit:async n=>{await Ft(this.putMany(e,n)),e=[],await Ft(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 o=e.prefix;n=dt(n,i=>i.key.toString().startsWith(o))}if(Array.isArray(e.filters)&&(n=e.filters.reduce((o,i)=>dt(o,i),n)),Array.isArray(e.orders)&&(n=e.orders.reduce((o,i)=>Hc(o,i),n)),e.offset!=null){let o=0,i=e.offset;n=dt(n,()=>o++>=i)}return e.limit!=null&&(n=Ms(n,e.limit)),n}queryKeys(e,t){let n=this._allKeys(e,t);if(e.prefix!=null){let o=e.prefix;n=dt(n,i=>i.toString().startsWith(o))}if(Array.isArray(e.filters)&&(n=e.filters.reduce((o,i)=>dt(o,i),n)),Array.isArray(e.orders)&&(n=e.orders.reduce((o,i)=>Hc(o,i),n)),e.offset!=null){let o=e.offset,i=0;n=dt(n,()=>i++>=o)}return e.limit!=null&&(n=Ms(n,e.limit)),n}};var ns=class extends Dr{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 Vc();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 Be(e),value:t}}*_allKeys(){for(let e of this.data.keys())yield new Be(e)}};var dD=new Be(ay);var SD=ee("datastore:core:tiered");async function ly(r={}){let e=r.datastore??new ns,t=r.blockstore??new ts,n=new Fc({...r,datastore:e,blockstore:t,blockBrokers:r.blockBrokers??[fi()],routers:r.routers??[qi("https://delegated-ipfs.dev")]});return r.start!==!1&&await n.start(),n}var nd=J(Ds(),1);var od=40;function id(r,e){if(!r.length)throw new Error("Unexpected end of data");let t=nd.default.decode(r);return e.seek(nd.default.decode.bytes),t}function sd(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 hn={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},os={"CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)":hn.Link,"CarV1HeaderOrV2Pragma > roots (anon)":r=>{if(hn.List(r)!==void 0){for(let e=0;e<r.length;e++){let t=r[e];if(t=os["CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)"](t),t===void 0)return;if(t!==r[e]){let n=r.slice(0,e);for(let o=e;o<r.length;o++){let i=r[o];if(i=os["CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)"](i),i===void 0)return;n.push(i)}return n}}return r}},Int:hn.Int,CarV1HeaderOrV2Pragma:r=>{if(hn.Map(r)===void 0)return;let e=Object.entries(r),t=r,n=1;for(let o=0;o<e.length;o++){let[i,s]=e[o];switch(i){case"roots":{let a=os["CarV1HeaderOrV2Pragma > roots (anon)"](r[i]);if(a===void 0)return;if(a!==s||t!==r){if(t===r){t={};for(let c=0;c<o;c++)t[e[c][0]]=e[c][1]}t.roots=a}}break;case"version":{n--;let a=os.Int(r[i]);if(a===void 0)return;if(a!==s||t!==r){if(t===r){t={};for(let c=0;c<o;c++)t[e[c][0]]=e[c][1]}t.version=a}}break;default:return}}if(!(n>0))return t}},is={"CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)":hn.Link,"CarV1HeaderOrV2Pragma > roots (anon)":r=>{if(hn.List(r)!==void 0){for(let e=0;e<r.length;e++){let t=r[e];if(t=is["CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)"](t),t===void 0)return;if(t!==r[e]){let n=r.slice(0,e);for(let o=e;o<r.length;o++){let i=r[o];if(i=is["CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)"](i),i===void 0)return;n.push(i)}return n}}return r}},Int:hn.Int,CarV1HeaderOrV2Pragma:r=>{if(hn.Map(r)===void 0)return;let e=Object.entries(r),t=r,n=1;for(let o=0;o<e.length;o++){let[i,s]=e[o];switch(i){case"roots":{let a=is["CarV1HeaderOrV2Pragma > roots (anon)"](s);if(a===void 0)return;if(a!==s||t!==r){if(t===r){t={};for(let c=0;c<o;c++)t[e[c][0]]=e[c][1]}t.roots=a}}break;case"version":{n--;let a=is.Int(s);if(a===void 0)return;if(a!==s||t!==r){if(t===r){t={};for(let c=0;c<o;c++)t[e[c][0]]=e[c][1]}t.version=a}}break;default:return}}if(!(n>0))return t}},ad={toTyped:os.CarV1HeaderOrV2Pragma,toRepresentation:is.CarV1HeaderOrV2Pragma};var cP=bf();var av=J(Ds(),1);var hP=[new B(w.map,2),new B(w.string,"version"),new B(w.uint,1),new B(w.string,"roots")],pP=new B(w.tag,42);async function cd(r,e){let t=id(await r.upTo(8),r);if(t===0)throw new Error("Invalid CAR header (zero length)");let n=await r.exactly(t,!0),o=Hn(n);if(ad.toTyped(o)===void 0)throw new Error("Invalid CAR header format");if(o.version!==1&&o.version!==2||e!==void 0&&o.version!==e)throw new Error(`Invalid CAR version: ${o.version}${e!==void 0?` (expected ${e})`:""}`);if(o.version===1){if(!Array.isArray(o.roots))throw new Error("Invalid CAR header format");return o}if(o.roots!==void 0)throw new Error("Invalid CAR header format");let i=sd(await r.exactly(od,!0));r.seek(i.dataOffset-r.pos);let s=await cd(r,1);return Object.assign(s,i)}function ss(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 o=r.subarray(e,e+t);return n&&(e+=t),o},seek(t){e+=t},get pos(){return e}}}var ld=J(Ds(),1),dy=1;function ud(r){let e=Yi({version:dy,roots:r}),t=ld.default.encode(e.length),n=new Uint8Array(t.length+e.length);return n.set(t,0),n.set(e,t.length),n}function hy(r){return{async setRoots(e){let t=ud(e);await r.write(t)},async writeBlock(e){let{cid:t,bytes:n}=e;await r.write(new Uint8Array(ld.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 dy}}}function Mc(){}function py(){let r=[],e=null,t=Mc,n=!1,o=null,i=Mc,s=()=>(e||(e=new Promise(u=>{t=()=>{e=null,t=Mc,u()}})),e),a={write(u){r.push(u);let l=s();return i(),l},async end(){n=!0;let u=s();i(),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}):(o||(o=new Promise(l=>{i=()=>(o=null,i=Mc,l(c.next()))})),o)}};return{writer:a,iterator:c}}var as=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=U.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=fv(e);let{encoder:t,iterator:n}=my(),o=new r(e,t),i=new zc(n);return{writer:o,out:i}}static createAppender(){let{encoder:e,iterator:t}=my();e.setRoots=()=>Promise.resolve();let n=new r([],e),o=new zc(t);return{writer:n,out:o}}static async updateRootsInBytes(e,t){let n=ss(e);await cd(n);let o=ud(t);if(Number(n.pos)!==o.length)throw new Error(`updateRoots() can only overwrite a header of the same length (old header is ${n.pos} bytes, new header is ${o.length} bytes)`);return e.set(o,0),e}},zc=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 my(){let r=py(),{writer:e,iterator:t}=r;return{encoder:hy(e),iterator:t}}function fv(r){if(r===void 0)return[];if(!Array.isArray(r)){let t=U.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=U.asCID(t);if(!n)throw new TypeError("roots must be a single CID or an array of CIDs");e.push(n)}return e}var dv=1,fd=class{components;constructor(e,t){this.components=e}async import(e,t){await Ft(this.components.blockstore.putMany(We(e.blocks(),({cid:n,bytes:o})=>({cid:n,block:o})),t))}async export(e,t,n){let o=we(),i=Array.isArray(e)?e:[e],s=new ut({concurrency:dv});s.on("idle",()=>{o.resolve()}),s.on("error",a=>{s.clear(),o.reject(a)});for(let a of i)s.add(async()=>{await this.#e(a,s,async(c,u)=>{await t.put({cid:c,bytes:u})},n)}).catch(()=>{});try{await o.promise}finally{await t.close()}}async*stream(e,t){let{writer:n,out:o}=as.create(e);this.export(e,n,t).catch(()=>{});for await(let i of o)yield i}async#e(e,t,n,o){let i=this.components.dagWalkers[e.code];if(i==null)throw new Error(`No dag walker found for cid codec ${e.code}`);let s=await this.components.blockstore.get(e,o);await n(e,s);for await(let a of i.walk(s))t.add(async()=>{await this.#e(a,t,n,o)})}};function yy(r,e={}){return new fd(r,e)}var dd=J(ec(),1);function gy(r,e){let t=e.map((n,o)=>({record:rt(n),index:o}));return t.sort((n,o)=>{let i=n.record.sequence,s=o.record.sequence;if(i>s)return-1;if(i<s)return 1;if(n.record.validityType===He.ValidityType.EOL&&o.record.validityType===He.ValidityType.EOL){let a=dd.default.fromString(n.record.validity).toDate(),c=dd.default.fromString(o.record.validity).toDate();if(a.getTime()>c.getTime())return-1;if(a.getTime()<c.getTime())return 1}return 0}),t[0].index}var hv=32;async function wy(r,e,t,n,o={}){if(e===0)throw new Error("recursion limit exceeded");n("query %s for TXT and CNAME records",r);let s=(await t.query(r,{...o,types:[Ot.TXT]})).Answer.sort((u,l)=>u.data.localeCompare(l.data));n("found %d TXT records for %s",s.length,r);for(let u of s)try{let l=u.data;if(l.startsWith('"')&&l.endsWith('"')&&(l=l.substring(1,l.length-1)),!l.startsWith("dnslink="))continue;n("%s TXT %s",u.name,l),l=l.replace("dnslink=","");let[,f,m,...d]=l.split("/");if(f==="ipfs")try{return`/ipfs/${U.parse(m)}${d.length>0?`/${d.join("/")}`:""}`}catch{}else if(f==="ipns"){try{return`/ipns/${Je(m)}${d.length>0?`/${d.join("/")}`:""}`}catch{}return await $c(m,e-1,t,n,o)}else{if(f==="dnslink")return await $c(m,e-1,t,n,o);n('unknown protocol "%s" in DNSLink record for domain: %s',f,r);continue}}catch(l){n.error("could not parse DNS link record for domain %s, %s",r,u.data,l)}n("no DNSLink records found for %s, falling back to CNAME",r);let c=(await t.query(r,{...o,types:[Ot.CNAME]})).Answer.sort((u,l)=>u.data.localeCompare(l.data));n("found %d CNAME records for %s",c.length,r);for(let u of c)try{return await $c(u.data,e-1,t,n,o)}catch(l){n.error("domain %s cname %s had no DNSLink records",r,u.data,l)}throw new P(`No DNSLink records found for domain: ${r}`,"ERR_DNSLINK_NOT_FOUND")}async function $c(r,e,t,n,o={}){if(e===0)throw new Error("recursion limit exceeded");r.startsWith("_dnslink.")||(r=`_dnslink.${r}`);try{return await wy(r,e,t,n,o)}catch(i){if(i.code!=="ENOTFOUND"&&i.code!=="ERR_DNSLINK_NOT_FOUND"&&i.code!=="ENODATA")throw i;return r.startsWith("_dnslink.")?r=r.replace("_dnslink.",""):r=`_dnslink.${r}`,await wy(r,e,t,n,o)}}async function by(r,e,t,n={}){return $c(r,n.maxRecursiveDepth??hv,e,t,n)}var hd=class{routing;constructor(e){this.routing=e}async put(e,t,n={}){try{await this.routing.put(e,t,n)}catch(o){n.onProgress?.(new V("ipns:routing:helia:error",o))}}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 xy(r){return new hd(r)}var Kc=globalThis.CustomEvent??Event;async function*zn(r,e={}){let t=e.concurrency??1/0;t<1&&(t=1/0);let n=e.ordered==null?!1:e.ordered,o=new EventTarget,i=[],s=we(),a=we(),c=!1,u,l=!1;o.addEventListener("task-complete",()=>{a.resolve()}),Promise.resolve().then(async()=>{try{for await(let p of r){if(i.length===t&&(s=we(),await s.promise),l)break;let h={done:!1};i.push(h),p().then(g=>{h.done=!0,h.ok=!0,h.value=g,o.dispatchEvent(new Kc("task-complete"))},g=>{h.done=!0,h.err=g,o.dispatchEvent(new Kc("task-complete"))})}c=!0,o.dispatchEvent(new Kc("task-complete"))}catch(p){u=p,o.dispatchEvent(new Kc("task-complete"))}});function f(){return n?i[0]?.done:!!i.find(p=>p.done)}function*m(){for(;i.length>0&&i[0].done;){let p=i[0];if(i.shift(),p.ok)yield p.value;else throw l=!0,s.resolve(),p.err;s.resolve()}}function*d(){for(;f();)for(let p=0;p<i.length;p++)if(i[p].done){let h=i[p];if(i.splice(p,1),p--,h.ok)yield h.value;else throw l=!0,s.resolve(),h.err;s.resolve()}}for(;;){if(f()||(a=we(),await a.promise),u!=null)throw u;if(n?yield*m():yield*d(),c&&i.length===0)break}}var cs;(function(r){let e;r.codec=()=>(e==null&&(e=Bt((t,n,o={})=>{o.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)),o.lengthDelimited!==!1&&n.ldelim()},(t,n)=>{let o={key:new Uint8Array(0),value:new Uint8Array(0),timeReceived:""},i=n==null?t.len:t.pos+n;for(;t.pos<i;){let s=t.uint32();switch(s>>>3){case 1:o.key=t.bytes();break;case 2:o.value=t.bytes();break;case 5:o.timeReceived=t.string();break;default:t.skipType(s&7);break}}return o})),e),r.encode=t=>It(t,r.codec()),r.decode=t=>_t(t,r.codec())})(cs||(cs={}));function Ey(r){let e=r.getUTCFullYear(),t=String(r.getUTCMonth()+1).padStart(2,"0"),n=String(r.getUTCDate()).padStart(2,"0"),o=String(r.getUTCHours()).padStart(2,"0"),i=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${o}:${i}:${s}.${c}Z`}function vy(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),o=parseInt(t[2],10)-1,i=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,o,i,s,a,c,u))}var pn=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 cs.encode(this.prepareSerialize())}prepareSerialize(){return{key:this.key,value:this.value,timeReceived:Ey(this.timeReceived)}}static deserialize(e){let t=cs.decode(e);return new r(t.key,t.value,new Date(t.timeReceived))}static fromDeserialized(e){let t=vy(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 Ay;(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"})(Ay||(Ay={}));function pd(r){return new Be("/dht/record/"+W(r,"base32"),!1)}function Sy(r){return{async put(e,t,n={}){try{let o=pd(e),i=new pn(e,t,new Date);n.onProgress?.(new V("ipns:routing:datastore:put")),await r.put(o,i.serialize(),n)}catch(o){throw n.onProgress?.(new V("ipns:routing:datastore:error",o)),o}},async get(e,t={}){try{let n=pd(e);t.onProgress?.(new V("ipns:routing:datastore:get"));let o=await r.get(n,t);return pn.deserialize(o).value}catch(n){throw t.onProgress?.(new V("ipns:routing:datastore:error",n)),n}},async has(e,t={}){let n=pd(e);return r.has(n,t)}}}var $n=ee("helia:ipns"),mv=60*1e3,_y=60*mv,yv=24*_y,md=23*_y,yd=class{routers;localStore;timeout;dns;log;constructor(e,t=[]){this.routers=[xy(e.routing),...t],this.localStore=Sy(e.datastore),this.dns=e.dns,this.log=e.logger.forComponent("helia:ipns")}async publish(e,t,n={}){try{let o=1n,i=Fo(e);if(await this.localStore.has(i,n)){let c=await this.localStore.get(i,n);o=rt(c).sequence+1n}let s=await p1(e,t,o,n.lifetime??yv,n),a=Cr(s);return await this.localStore.put(i,a,n),n.offline!==!0&&await Promise.all(this.routers.map(async c=>{await c.put(i,a,n)})),s}catch(o){throw n.onProgress?.(new V("ipns:publish:error",o)),o}}async resolve(e,t={}){let n=Fo(e),o=await this.#t(n,t);return this.#e(o.value,t)}async resolveDNSLink(e,t={}){let n=await by(e,this.dns,this.log,t);return this.#e(n,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 i=Date.now()-n,s=md-i;s<0&&(s=e.interval??md),setTimeout(()=>{t().catch(a=>{$n.error("error republishing",a)})},s)}this.timeout=setTimeout(()=>{t().catch(n=>{$n.error("error republishing",n)})},e.interval??md)}async#e(e,t={}){let n=e.split("/");try{let o=n[1];if(o==="ipns"){let{cid:i}=await this.resolve(Je(n[2]),t),s=n.slice(3).join("/");return{cid:i,path:s}}else if(o==="ipfs"){let i=U.parse(n[2]),s=n.slice(3).join("/");return{cid:i,path:s}}}catch(o){$n.error("error parsing ipfs path",o)}throw $n.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 o=[],i=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"?$n("did not have record locally"):$n.error("error finding IPNS record",u);return}try{await yc(e,c),o.push(c)}catch(u){i++,$n.error("error finding IPNS record",u)}})),o.length===0)throw i>0?new P(`${i>1?`${i} records`:"Record"} found for routing key ${i>1?"were":"was"} invalid`,"ERR_RECORDS_FAILED_VALIDATION"):new P("Could not find record for routing key","ERR_NOT_FOUND");let s=o[gy(e,o)];return await this.localStore.put(e,s,t),rt(s)}};function ky(r,{routers:e=[]}={}){return new yd(r,e)}var vd=J(Ie(),1);function gv(r){return r[Symbol.asyncIterator]!=null}function wv(r,e=1){return e=Number(e),gv(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 ls=wv;async function*us(r,e=1){for await(let t of ls(r,e)){let n=t.map(async o=>o().then(i=>({ok:!0,value:i}),i=>({ok:!1,err:i})));for(let o=0;o<n.length;o++){let i=await n[o];if(i.ok)yield i.value;else throw i.err}}}var bv=262144,fs=(r={})=>{let e=r.chunkSize??bv;return async function*(n){let o=new Rt,i=0,s=!1;for await(let a of n)for(o.append(a),i+=a.length;i>=e;)if(yield o.slice(0,e),s=!0,e===o.length)o=new Rt,i=0;else{let c=new Rt;c.append(o.sublist(e)),o=c,i-=e}(!s||i>0)&&(yield o.subarray(0,i))}};var gd=J(Ie(),1);var Wt;(function(r){let e;(function(o){o.Raw="Raw",o.Directory="Directory",o.File="File",o.Metadata="Metadata",o.Symlink="Symlink",o.HAMTShard="HAMTShard"})(e=r.DataType||(r.DataType={}));let t;(function(o){o[o.Raw=0]="Raw",o[o.Directory=1]="Directory",o[o.File=2]="File",o[o.Metadata=3]="Metadata",o[o.Symlink=4]="Symlink",o[o.HAMTShard=5]="HAMTShard"})(t||(t={})),function(o){o.codec=()=>Bn(t)}(e=r.DataType||(r.DataType={}));let n;r.codec=()=>(n==null&&(n=Bt((o,i,s={})=>{if(s.lengthDelimited!==!1&&i.fork(),o.Type!=null&&(i.uint32(8),r.DataType.codec().encode(o.Type,i)),o.Data!=null&&(i.uint32(18),i.bytes(o.Data)),o.filesize!=null&&(i.uint32(24),i.uint64(o.filesize)),o.blocksizes!=null)for(let a of o.blocksizes)i.uint32(32),i.uint64(a);o.hashType!=null&&(i.uint32(40),i.uint64(o.hashType)),o.fanout!=null&&(i.uint32(48),i.uint64(o.fanout)),o.mode!=null&&(i.uint32(56),i.uint32(o.mode)),o.mtime!=null&&(i.uint32(66),Gc.codec().encode(o.mtime,i)),s.lengthDelimited!==!1&&i.ldelim()},(o,i)=>{let s={blocksizes:[]},a=i==null?o.len:o.pos+i;for(;o.pos<a;){let c=o.uint32();switch(c>>>3){case 1:s.Type=r.DataType.codec().decode(o);break;case 2:s.Data=o.bytes();break;case 3:s.filesize=o.uint64();break;case 4:s.blocksizes.push(o.uint64());break;case 5:s.hashType=o.uint64();break;case 6:s.fanout=o.uint64();break;case 7:s.mode=o.uint32();break;case 8:s.mtime=Gc.codec().decode(o,o.uint32());break;default:o.skipType(c&7);break}}return s})),n),r.encode=o=>It(o,r.codec()),r.decode=o=>_t(o,r.codec())})(Wt||(Wt={}));var Gc;(function(r){let e;r.codec=()=>(e==null&&(e=Bt((t,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),t.Seconds!=null&&(n.uint32(8),n.int64(t.Seconds)),t.FractionalNanoseconds!=null&&(n.uint32(21),n.fixed32(t.FractionalNanoseconds)),o.lengthDelimited!==!1&&n.ldelim()},(t,n)=>{let o={},i=n==null?t.len:t.pos+n;for(;t.pos<i;){let s=t.uint32();switch(s>>>3){case 1:o.Seconds=t.int64();break;case 2:o.FractionalNanoseconds=t.fixed32();break;default:t.skipType(s&7);break}}return o})),e),r.encode=t=>It(t,r.codec()),r.decode=t=>_t(t,r.codec())})(Gc||(Gc={}));var Iy;(function(r){let e;r.codec=()=>(e==null&&(e=Bt((t,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),t.MimeType!=null&&(n.uint32(10),n.string(t.MimeType)),o.lengthDelimited!==!1&&n.ldelim()},(t,n)=>{let o={},i=n==null?t.len:t.pos+n;for(;t.pos<i;){let s=t.uint32();switch(s>>>3){case 1:o.MimeType=t.string();break;default:t.skipType(s&7);break}}return o})),e),r.encode=t=>It(t,r.codec()),r.decode=t=>_t(t,r.codec())})(Iy||(Iy={}));var By={Raw:"raw",Directory:"directory",File:"file",Metadata:"metadata",Symlink:"symlink",HAMTShard:"hamt-sharded-directory"},xv=["directory","hamt-sharded-directory"],Ry=parseInt("0644",8),Ty=parseInt("0755",8),G=class r{static unmarshal(e){let t=Wt.decode(e),n=new r({type:By[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:o,hashType:i,fanout:s,mtime:a,mode:c}=e;if(t!=null&&!Object.values(By).includes(t))throw(0,gd.default)(new Error("Type: "+t+" is not valid"),"ERR_INVALID_TYPE");this.type=t??"file",this.data=n,this.hashType=i,this.fanout=s,this.blockSizes=o??[],this._originalMode=0,this.mode=c,this.mtime=a}set mode(e){e==null?this._mode=this.isDirectory()?Ty:Ry:this._mode=e&4095}get mode(){return this._mode}isDirectory(){return xv.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=Wt.DataType.Raw;break;case"directory":e=Wt.DataType.Directory;break;case"file":e=Wt.DataType.File;break;case"metadata":e=Wt.DataType.Metadata;break;case"symlink":e=Wt.DataType.Symlink;break;case"hamt-sharded-directory":e=Wt.DataType.HAMTShard;break;default:throw(0,gd.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===Ry&&!this.isDirectory()&&(n=void 0),n===Ty&&this.isDirectory()&&(n=void 0));let o;return this.mtime!=null&&(o={Seconds:this.mtime.secs,FractionalNanoseconds:this.mtime.nsecs}),Wt.encode({Type:e,Data:t,filesize:this.isDirectory()?void 0:this.fileSize(),blocksizes:this.blockSizes,hashType:this.hashType,fanout:this.fanout,mode:n,mtime:o})}};var jt=async(r,e,t)=>{t.codec==null&&(t.codec=Ne);let n=await ae.digest(r),o=U.create(t.cidVersion,t.codec.code,n);return await e.put(o,r,t),o};function Ny(r){return async function*(t,n){let o=0n;for await(let i of t.content)yield async()=>{let s,a={codec:Ne,cidVersion:r.cidVersion,onProgress:r.onProgress};r.rawLeaves?(a.codec=kt,a.cidVersion=1):(s=new G({type:r.leafType,data:i}),i=ne({Data:s.marshal(),Links:[]}));let c=await jt(i,n,a);return o+=BigInt(i.byteLength),r.onProgress?.(new V("unixfs:importer:progress:file:write",{bytesWritten:o,cid:c,path:t.path})),{cid:c,unixfs:s,size:BigInt(i.length),block:i}}}}var wd=J(Ie(),1);var Cy=async(r,e,t)=>{let n=new G({type:"directory",mtime:r.mtime,mode:r.mode}),o=ne(_e({Data:n.marshal()})),i=await jt(o,e,t),s=r.path;return{cid:i,path:s,unixfs:n,size:BigInt(o.length),originalPath:r.originalPath,block:o}};async function*Ev(r,e,t){let n=-1,o;for await(let i of us(t.bufferImporter(r,e),t.blockWriteConcurrency)){if(n++,n===0){o={...i,single:!0};continue}else n===1&&o!=null&&(yield{...o,block:void 0,single:void 0},o=void 0);yield{...i,block:void 0}}o!=null&&(yield o)}function Ly(r){return r.single===!0}var vv=(r,e,t)=>async function(o){if(o.length===1&&Ly(o[0])&&t.reduceSingleLeafToSelf){let l=o[0],f=l.block;return Ly(l)&&(r.mtime!==void 0||r.mode!==void 0)&&(l.unixfs=new G({type:"file",mtime:r.mtime,mode:r.mode,data:l.block}),f={Data:l.unixfs.marshal(),Links:[]},l.block=ne(_e(f)),l.cid=await jt(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 i=new G({type:"file",mtime:r.mtime,mode:r.mode}),s=o.filter(l=>l.cid.code===ge&&l.size>0||l.unixfs!=null&&l.unixfs.data==null&&l.unixfs.fileSize()>0n?!0:!!l.unixfs?.data?.length).map(l=>l.cid.code===ge?(i.addBlockSize(l.size),{Name:"",Tsize:Number(l.size),Hash:l.cid}):(l.unixfs==null||l.unixfs.data==null?i.addBlockSize(l.unixfs?.fileSize()??0n):i.addBlockSize(BigInt(l.unixfs.data.length)),{Name:"",Tsize:Number(l.size),Hash:l.cid})),a={Data:i.marshal(),Links:s},c=ne(_e(a)),u=await jt(c,e,t);return t.onProgress?.(new V("unixfs:importer:progress:file:layout",{cid:u,path:r.originalPath})),{cid:u,path:r.path,unixfs:i,size:BigInt(c.length+a.Links.reduce((l,f)=>l+(f.Tsize??0),0)),originalPath:r.originalPath,block:c}},Dy=async(r,e,t)=>t.layout(Ev(r,e,t),vv(r,e,t));function Av(r){return Symbol.iterator in r}function Sv(r){return Symbol.asyncIterator in r}function _v(r){try{if(r instanceof Uint8Array)return async function*(){yield r}();if(Av(r))return async function*(){yield*r}();if(Sv(r))return r}catch{throw(0,wd.default)(new Error("Content was invalid"),"ERR_INVALID_CONTENT")}throw(0,wd.default)(new Error("Content was invalid"),"ERR_INVALID_CONTENT")}function Py(r){return async function*(t,n){for await(let o of t){let i;if(o.path!=null&&(i=o.path,o.path=o.path.split("/").filter(s=>s!=null&&s!==".").join("/")),kv(o)){let s={path:o.path,mtime:o.mtime,mode:o.mode,content:async function*(){let a=0n;for await(let c of r.chunker(r.chunkValidator(_v(o.content)))){let u=BigInt(c.byteLength);a+=u,r.onProgress?.(new V("unixfs:importer:progress:file:read",{bytesRead:a,chunkSize:u,path:o.path})),yield c}}(),originalPath:i};yield async()=>Dy(s,n,r)}else if(o.path!=null){let s={path:o.path,mtime:o.mtime,mode:o.mode,originalPath:i};yield async()=>Cy(s,n,r)}else throw new Error("Import candidate must have content or path or both")}}}function kv(r){return r.content!=null}var bd=J(Ie(),1);var Oy=()=>async function*(e){for await(let t of e){if(t.length===void 0)throw(0,bd.default)(new Error("Content was invalid"),"ERR_INVALID_CONTENT");if(typeof t=="string"||t instanceof String)yield F(t.toString());else if(Array.isArray(t))yield Uint8Array.from(t);else if(t instanceof Uint8Array)yield t;else throw(0,bd.default)(new Error("Content was invalid"),"ERR_INVALID_CONTENT")}};var Iv=174;function ds(r){let e=r?.maxChildrenPerNode??Iv;return async function t(n,o){let i=[];for await(let s of ls(n,e))i.push(await o(s));return i.length>1?t(i,o):i[0]}}var cr=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}},hs=U.parse("QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn"),ps=U.parse("zdj7WbTaiJT1fgatdet9Ei9iDB5hdCxkbVyhyh8YTUnXMiwYi");var Kn=class extends cr{_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?ps.bytes.byteLength:hs.bytes.byteLength));return this.nodeSize}async*flush(e){let t=[];for(let[c,u]of this._children.entries()){let l=u;if(u instanceof cr)for await(let f of u.flush(e))l=f,yield f;l.size!=null&&l.cid!=null&&t.push({Name:c,Tsize:Number(l.size),Hash:l.cid})}let n=new G({type:"directory",mtime:this.mtime,mode:this.mode}),o={Data:n.marshal(),Links:t},i=ne(_e(o)),s=await jt(i,e,this.options),a=i.length+o.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 Wc=J(Vy(),1);function Bv(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 U7=An({name:"murmur3-32",code:35,encode:r=>Bv(Wc.default.x86.hash32(r))}),Gn=An({name:"murmur3-128",code:34,encode:r=>Xn.fromHex(Wc.default.x64.hash128(r))}),F7=An({name:"murmur3-x64-64",code:34,encode:r=>Xn.fromHex(Wc.default.x64.hash128(r)).subarray(0,8)});var zy=J(jc(),1);var Et=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 zy.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((o,i,s)=>(i!=null&&(i instanceof r?o.push(i.serialize(e,t)):o.push(e(i,s))),o),n))}async asyncTransform(e,t){return $y(this,e,t)}toJSON(){return this.serialize(Lv,Dv)}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"?F(e):e),n=await t.take(this._options.bits),o=this._children.get(n);return o instanceof r?o._findPlace(t):{bucket:this,pos:n,hash:t,existingChild:o}}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 o=await n._findPlace(t.existingChild.hash);return o.bucket._putAt(o,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(Cv);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 Cv(r){return!!r}function Lv(r,e){return r.key}function Dv(r){return r}async function $y(r,e,t){let n=[];for(let o of r._children.compactArray())if(o instanceof Et)await $y(o,e,t);else{let i=await e(o);n.push({bitField:r._children.bitField(),children:i})}return t(n)}var Pv=[255,254,252,248,240,224,192,128],Ov=[1,3,7,15,31,63,127,255],Yc=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 o=this._value[this._currentBytePos],i=this._currentBitPos+1,s=Math.min(i,t),a=Uv(o,i-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 Uv(r,e,t){let n=Fv(e,t);return(r&n)>>>e}function Fv(r,e){return Pv[r]&Ov[Math.min(e+r-1,7)]}function Ky(r){function e(t){return t instanceof Xc?t:new Xc(t,r)}return e}var Xc=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 o=this._buffers[this._currentBufferIndex],i=Math.min(o.availableBits(),t),s=o.take(i);n=(n<<i)+s,t-=i,this._availableBits-=i,o.availableBits()===0&&this._currentBufferIndex++}return n}untake(e){let t=e;for(;t>0;){let n=this._buffers[this._currentBufferIndex],o=Math.min(n.totalBits()-n.availableBits(),t);n.untake(o),t-=o,this._availableBits+=o,this._currentBufferIndex>0&&n.totalBits()===n.availableBits()&&(this._depth--,this._currentBufferIndex--)}}async _produceMoreBits(){this._depth++;let e=this._depth>0?ue([this._value,Uint8Array.from([this._depth])]):this._value,t=await this._hashFn(e),n=new Yc(t);this._buffers.push(n),this._availableBits+=n.availableBits()}};function Go(r){if(r==null||r.hashFn==null)throw new Error("please define an options.hashFn");let e={bits:r.bits??8,hash:Ky(r.hashFn)};return new Et(e)}async function Vv(r){return(await Gn.encode(r)).slice(0,8).reverse()}var Gy=BigInt(34),Hv=8,xd=class extends cr{_bucket;constructor(e,t){super(e,t),this._bucket=Go({hashFn:Vv,bits:t.shardFanoutBits??Hv})}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=jy(this._bucket,this,this.options),this.nodeSize)}async*flush(e){for await(let t of Wy(this._bucket,e,this,this.options))yield{...t,path:this.path}}},qy=xd;async function*Wy(r,e,t,n){let o=r._children,i=(r.tableSize()-1).toString(16).length,s=[],a=0n;for(let p=0;p<o.length;p++){let h=o.get(p);if(h==null)continue;let g=p.toString(16).toUpperCase().padStart(i,"0");if(h instanceof Et){let y;for await(let x of Wy(h,e,null,n))y=x;if(y==null)throw new Error("Could not flush sharded directory, no subshard found");s.push({Name:g,Tsize:Number(y.size),Hash:y.cid}),a+=y.size}else if(Mv(h.value)){let y=h.value,x;for await(let S of y.flush(e))x=S,yield x;if(x==null)throw new Error("Did not flush dir");let b=g+h.key;s.push({Name:b,Tsize:Number(x.size),Hash:x.cid}),a+=x.size}else{let y=h.value;if(y.cid==null)continue;let x=g+h.key,b=y.size;s.push({Name:x,Tsize:Number(b),Hash:y.cid}),a+=BigInt(b??0)}}let c=Uint8Array.from(o.bitField().reverse()),u=new G({type:"hamt-sharded-directory",data:c,fanout:BigInt(r.tableSize()),hashType:Gy,mtime:t?.mtime,mode:t?.mode}),l={Data:u.marshal(),Links:s},f=ne(_e(l)),m=await jt(f,e,n),d=BigInt(f.byteLength)+a;yield{cid:m,unixfs:u,size:d}}function Mv(r){return typeof r.flush=="function"}function jy(r,e,t){let n=r._children,o=(r.tableSize()-1).toString(16).length,i=[];for(let u=0;u<n.length;u++){let l=n.get(u);if(l==null)continue;let f=u.toString(16).toUpperCase().padStart(o,"0");if(l instanceof Et){let m=jy(l,null,t);i.push({Name:f,Tsize:Number(m),Hash:t.cidVersion===0?hs:ps})}else if(typeof l.value.flush=="function"){let d=l.value.nodeSize();i.push({Name:f+l.key,Tsize:Number(d),Hash:t.cidVersion===0?hs:ps})}else{let m=l.value;if(m.cid==null)continue;let d=f+l.key,p=m.size;i.push({Name:d,Tsize:Number(p),Hash:m.cid})}}let s=Uint8Array.from(n.bitField().reverse()),a=new G({type:"hamt-sharded-directory",data:s,fanout:BigInt(r.tableSize()),hashType:Gy,mtime:e?.mtime,mode:e?.mode});return ne(_e({Data:a.marshal(),Links:i})).length}async function Ed(r,e,t,n){let o=e;e instanceof Kn&&e.estimateNodeSize()>t&&(o=await zv(e,n));let i=o.parent;if(i!=null){if(o!==e){if(r!=null&&(r.parent=o),o.parentKey==null)throw new Error("No parent key found");await i.put(o.parentKey,o)}return Ed(o,i,t,n)}return o}async function zv(r,e){let t=new qy({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:o}of r.eachChildSeries())await t.put(n,o);return t}var Yy=(r="")=>r.split(/(?<!\\)\//).filter(Boolean);async function $v(r,e,t){let n=Yy(r.path??""),o=n.length-1,i=e,s="";for(let a=0;a<n.length;a++){let c=n[a];s+=`${s!==""?"/":""}${c}`;let u=a===o;if(i.dirty=!0,i.cid=void 0,i.size=void 0,u)await i.put(c,r),e=await Ed(null,i,t.shardSplitThresholdBytes,t);else{let l=await i.get(c);(l==null||!(l instanceof cr))&&(l=new Kn({root:!1,dir:!0,parent:i,parentKey:c,path:s,dirty:!0,flat:!0,mtime:l?.unixfs?.mtime,mode:l?.unixfs?.mode},t)),await i.put(c,l),i=l}}return e}async function*Xy(r,e){if(!(r instanceof cr)){r.unixfs?.isDirectory()===!0&&(yield r);return}yield*r.flush(e)}function Zy(r){return async function*(t,n){let o=new Kn({root:!0,dir:!0,path:"",dirty:!0,flat:!0},r),i,s=!1;for await(let a of t){if(a==null)continue;let c=`${a.originalPath??""}`.split("/")[0];c!=null&&c!==""&&(i==null?(i=c,s=!0):i!==c&&(s=!1)),o=await $v(a,o,r),(a.unixfs==null||!a.unixfs.isDirectory())&&(yield a)}if(r.wrapWithDirectory||s&&o.childCount()>1)yield*Xy(o,n);else for await(let a of o.eachChildSeries())a!=null&&(yield*Xy(a.child,n))}}async function*mn(r,e,t={}){let n;Symbol.asyncIterator in r||Symbol.iterator in r?n=r:n=[r];let o=t.wrapWithDirectory??!1,i=t.shardSplitThresholdBytes??262144,s=t.shardFanoutBits??8,a=t.cidVersion??1,c=t.rawLeaves??!0,u=t.leafType??"file",l=t.fileImportConcurrency??50,f=t.blockWriteConcurrency??10,m=t.reduceSingleLeafToSelf??!0,d=t.chunker??fs(),p=t.chunkValidator??Oy(),h=t.dagBuilder??Py({chunker:d,chunkValidator:p,wrapWithDirectory:o,layout:t.layout??ds(),bufferImporter:t.bufferImporter??Ny({cidVersion:a,rawLeaves:c,leafType:u,onProgress:t.onProgress}),blockWriteConcurrency:f,reduceSingleLeafToSelf:m,cidVersion:a,onProgress:t.onProgress}),g=t.treeBuilder??Zy({wrapWithDirectory:o,shardSplitThresholdBytes:i,shardFanoutBits:s,cidVersion:a,onProgress:t.onProgress});for await(let y of g(us(h(n,e),l),e))yield{cid:y.cid,path:y.path,unixfs:y.unixfs,size:y.size}}async function Zc(r,e,t={}){let n=await Fn(mn([r],e,t));if(n==null)throw(0,vd.default)(new Error("Nothing imported"),"ERR_INVALID_PARAMS");return n}async function Jy(r,e,t={}){let n=await Fn(mn([r],e,t));if(n==null)throw(0,vd.default)(new Error("Nothing imported"),"ERR_INVALID_PARAMS");return n}async function Qy(r,e,t={}){return Zc({content:r},e,t)}async function eg(r,e,t={}){return Zc({content:r},e,t)}var Yv=J(Ie(),1),Xv=J(hg(),1);var bs={cidVersion:1,rawLeaves:!0,layout:ds({maxChildrenPerNode:1024}),chunker:fs({chunkSize:1048576})};async function*pg(r,e,t={}){yield*mn(r,e,{...bs,...t})}async function mg(r,e,t={}){let{cid:n}=await Qy(r,e,{...bs,...t});return n}async function yg(r,e,t={}){let{cid:n}=await eg(r,e,{...bs,...t});return n}async function gg(r,e,t={}){let{cid:n}=await Zc(r,e,{...bs,...t});return n}async function wg(r,e,t={}){let{cid:n}=await Jy({...r,path:r.path??"-"},e,{...bs,...t});return n}var Qc=J(Ie(),1);function Zv(r){return r[Symbol.asyncIterator]!=null}function Jv(r){if(Zv(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 yn=Jv;var Pg=J(Ie(),1);var bg=J(Ie(),1);function qo(r,e,t,n,o,i,s){let a=r,c=o;for(;i.length>0;){let u=i[0];if(u in a){i.shift(),c=`${c}/${u}`;let l=U.asCID(a[u]);if(l!=null)return{entry:{type:"object",name:n,path:o,cid:t,node:e,depth:s,size:BigInt(e.length),content:async function*(){yield r}},next:{cid:l,name:u,path:c,toResolve:i}};a=a[u]}else throw(0,bg.default)(new Error(`No property named ${u} found in node ${t}`),"ERR_NO_PROP")}return{entry:{type:"object",name:n,path:o,cid:t,node:e,depth:s,size:BigInt(e.length),content:async function*(){yield r}}}}var Qv=async(r,e,t,n,o,i,s,a)=>{let c=await s.get(r,a),u=Hn(c);return qo(u,c,r,e,t,n,i)},xg=Qv;var eA=async(r,e,t,n,o,i,s,a)=>{let c=await s.get(r,a),u=Lc(c);return qo(u,c,r,e,t,n,i)},Eg=eA;var vg=J(Ie(),1);function tA(r,e,t,n){let o=BigInt(r.length),i=BigInt(e+o);return t>=i||n<e?new Uint8Array(0):(n>=e&&n<i&&(r=r.subarray(0,Number(n-e))),t>=e&&t<i&&(r=r.subarray(Number(t-e))),r)}var qn=tA;var xs=J(Ie(),1),rA=(r,e=0,t=r)=>{let n=BigInt(r),o=BigInt(e??0),i=BigInt(t);if(i!==n&&(i=o+i),i>n&&(i=n),o<0n)throw(0,xs.default)(new Error("Offset must be greater than or equal to 0"),"ERR_INVALID_PARAMS");if(o>n)throw(0,xs.default)(new Error("Offset must be less than the file size"),"ERR_INVALID_PARAMS");if(i<0n)throw(0,xs.default)(new Error("Length must be greater than or equal to 0"),"ERR_INVALID_PARAMS");if(i>n)throw(0,xs.default)(new Error("Length must be less than the file size"),"ERR_INVALID_PARAMS");return{start:o,end:i}},Wo=rA;var nA=r=>{async function*e(t={}){let{start:n,end:o}=Wo(r.length,t.offset,t.length),i=qn(r,0n,n,o);t.onProgress?.(new V("unixfs:exporter:progress:identity",{bytesRead:BigInt(i.byteLength),totalBytes:o-n,fileSize:BigInt(r.byteLength)})),yield i}return e},oA=async(r,e,t,n,o,i,s,a)=>{if(n.length>0)throw(0,vg.default)(new Error(`No link named ${t} found in raw node ${r}`),"ERR_NOT_FOUND");let c=Ze(r.multihash.bytes);return{entry:{type:"identity",name:e,path:t,cid:r,content:nA(c.digest),depth:i,size:BigInt(c.digest.length),node:c.digest}}},Ag=oA;var iA=async(r,e,t,n,o,i,s,a)=>{let c=await s.get(r,a),u=Fh(c);return qo(u,c,r,e,t,n,i)},Sg=iA;var _g=J(Ie(),1);var sA=r=>{async function*e(t={}){let{start:n,end:o}=Wo(r.length,t.offset,t.length),i=qn(r,0n,n,o);t.onProgress?.(new V("unixfs:exporter:progress:raw",{bytesRead:BigInt(i.byteLength),totalBytes:o-n,fileSize:BigInt(r.byteLength)})),yield i}return e},aA=async(r,e,t,n,o,i,s,a)=>{if(n.length>0)throw(0,_g.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:sA(c),depth:i,size:BigInt(c.length),node:c}}},kg=aA;var vs=J(Ie(),1);var Es=J(Ie(),1);var cA=async function(r){return(await Gn.encode(r)).slice(0,8).reverse()},lA=async(r,e,t)=>{let n=(e.tableSize()-1).toString(16).length;await Promise.all(r.map(async o=>{if(o.Name==null)throw new Error("Unexpected Link without a Name");if(o.Name.length===n){let i=parseInt(o.Name,16);e._putObjectAt(i,new Et({hash:t._options.hash,bits:t._options.bits},e,i));return}await t.put(o.Name.substring(2),!0)}))},Ig=(r,e)=>r.toString(16).toUpperCase().padStart(e,"0").substring(0,e),uA=r=>{let e=r.bucket,t=[];for(;e._parent!=null;)t.push(e),e=e._parent;return t.push(e),t.reverse()},Bg=async(r,e,t,n,o)=>{if(n==null){if(r.Data==null)throw(0,Es.default)(new Error("no data in PBNode"),"ERR_NOT_UNIXFS");let f;try{f=G.unmarshal(r.Data)}catch(d){throw(0,Es.default)(d,"ERR_NOT_UNIXFS")}if(f.type!=="hamt-sharded-directory")throw(0,Es.default)(new Error("not a HAMT"),"ERR_NOT_UNIXFS");if(f.fanout==null)throw(0,Es.default)(new Error("missing fanout"),"ERR_NOT_UNIXFS");let m=Go({hashFn:cA,bits:Math.log2(Number(f.fanout))});n={rootBucket:m,hamtDepth:1,lastBucket:m}}let i=(n.lastBucket.tableSize()-1).toString(16).length;await lA(r.Links,n.lastBucket,n.rootBucket);let s=await n.rootBucket._findNewBucketAndPos(e),a=Ig(s.pos,i),c=uA(s);c.length>n.hamtDepth&&(n.lastBucket=c[n.hamtDepth],a=Ig(n.lastBucket._posAtParent,i));let u=r.Links.find(f=>{if(f.Name==null)return!1;let m=f.Name.substring(0,i),d=f.Name.substring(i);return!(m!==a||d!==""&&d!==e)});if(u==null)return;if(u.Name!=null&&u.Name.substring(i)===e)return u.Hash;n.hamtDepth++;let l=await t.get(u.Hash,o);return r=be(l),Bg(r,e,t,n,o)},Rg=Bg;var fA=(r,e,t,n,o,i,s)=>{async function*a(c={}){let u=c.offset??0,l=c.length??e.Links.length,f=e.Links.slice(u,l);c.onProgress?.(new V("unixfs:exporter:walk:directory",{cid:r})),yield*at(f,m=>We(m,d=>async()=>{let p=d.Name??"",h=`${n}/${p}`;return(await o(d.Hash,p,h,[],i+1,s,c)).entry}),m=>zn(m,{ordered:!0,concurrency:c.blockReadConcurrency}),m=>dt(m,d=>d!=null))}return a},Tg=fA;var Wn=J(Ie(),1);async function Ng(r,e,t,n,o,i,s){if(e instanceof Uint8Array){let u=qn(e,n,o,i);t.push(u);return}if(e.Data==null)throw(0,Wn.default)(new Error("no data in PBNode"),"ERR_NOT_UNIXFS");let a;try{a=G.unmarshal(e.Data)}catch(u){throw(0,Wn.default)(u,"ERR_NOT_UNIXFS")}if(a.data!=null){let u=a.data,l=qn(u,n,o,i);t.push(l),n+=BigInt(l.byteLength)}let c=[];if(e.Links.length!==a.blockSizes.length)throw(0,Wn.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],f=n,m=f+a.blockSizes[u];if((o>=f&&o<m||i>=f&&i<=m||o<f&&i>m)&&c.push({link:l,blockStart:n}),n=m,n>i)break}await at(c,u=>We(u,l=>async()=>{let f=await r.get(l.link.Hash,s);return{...l,block:f}}),u=>zn(u,{ordered:!0,concurrency:s.blockReadConcurrency}),async u=>{for await(let{link:l,block:f,blockStart:m}of u){let d;switch(l.Hash.code){case ye:d=be(f);break;case ge:d=f;break;default:t.end((0,Wn.default)(new Error(`Unsupported codec: ${l.Hash.code}`),"ERR_NOT_UNIXFS"));return}let p=new ut({concurrency:1});p.on("error",h=>{t.end(h)}),p.add(async()=>{s.onProgress?.(new V("unixfs:exporter:walk:file",{cid:l.Hash})),await Ng(r,d,t,m,o,i,s)}),await p.onIdle()}}),n>=i&&t.end()}var dA=(r,e,t,n,o,i,s)=>{async function*a(c={}){let u=t.fileSize();if(u===void 0)throw new Error("File was a directory");let{start:l,end:f}=Wo(u,c.offset,c.length);if(f===0n)return;let m=0n,d=f-l,p=Tt();c.onProgress?.(new V("unixfs:exporter:walk:file",{cid:r})),Ng(s,e,p,0n,l,f,c).catch(h=>{p.end(h)});for await(let h of p)if(h!=null){if(m+=BigInt(h.byteLength),m>d)throw p.end(),(0,Wn.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");m===d&&p.end(),c.onProgress?.(new V("unixfs:exporter:progress:unixfs:file",{bytesRead:m,totalBytes:d,fileSize:u})),yield h}if(m<d)throw(0,Wn.default)(new Error("Traversed entire DAG but did not read enough bytes"),"ERR_UNDER_READ")}return a},Id=dA;var Jc=J(Ie(),1);var hA=(r,e,t,n,o,i,s)=>{function a(c={}){return c.onProgress?.(new V("unixfs:exporter:walk:hamt-sharded-directory",{cid:r})),Cg(e,n,o,i,s,c)}return a};async function*Cg(r,e,t,n,o,i){let s=r.Links;if(r.Data==null)throw(0,Jc.default)(new Error("no data in PBNode"),"ERR_NOT_UNIXFS");let a;try{a=G.unmarshal(r.Data)}catch(l){throw(0,Jc.default)(l,"ERR_NOT_UNIXFS")}if(a.fanout==null)throw(0,Jc.default)(new Error("missing fanout"),"ERR_NOT_UNIXFS");let c=(a.fanout-1n).toString(16).length,u=at(s,l=>We(l,f=>async()=>{let m=f.Name!=null?f.Name.substring(c):null;if(m!=null&&m!==""){let d=await t(f.Hash,m,`${e}/${m}`,[],n+1,o,i);return{entries:d.entry==null?[]:[d.entry]}}else{let d=await o.get(f.Hash,i);return r=be(d),i.onProgress?.(new V("unixfs:exporter:walk:hamt-sharded-directory",{cid:f.Hash})),{entries:Cg(r,e,t,n,o,i)}}}),l=>zn(l,{ordered:!0,concurrency:i.blockReadConcurrency}));for await(let{entries:l}of u)yield*l}var Lg=hA;var pA=(r,e)=>r.Links.find(n=>n.Name===e)?.Hash,mA={raw:Id,file:Id,directory:Tg,"hamt-sharded-directory":Lg,metadata:(r,e,t,n,o,i,s)=>()=>[],symlink:(r,e,t,n,o,i,s)=>()=>[]},yA=async(r,e,t,n,o,i,s,a)=>{let c=await s.get(r,a),u=be(c),l,f;if(e==null&&(e=r.toString()),u.Data==null)throw(0,vs.default)(new Error("no data in PBNode"),"ERR_NOT_UNIXFS");try{l=G.unmarshal(u.Data)}catch(d){throw(0,vs.default)(d,"ERR_NOT_UNIXFS")}if(t==null&&(t=e),n.length>0){let d;if(l?.type==="hamt-sharded-directory"?d=await Rg(u,n[0],s):d=pA(u,n[0]),d==null)throw(0,vs.default)(new Error("file does not exist"),"ERR_NOT_FOUND");let p=n.shift(),h=`${t}/${p}`;f={cid:d,toResolve:n,name:p??"",path:h}}let m=mA[l.type](r,u,l,t,o,i,s);if(m==null)throw(0,vs.default)(new Error("could not find content exporter"),"ERR_NOT_FOUND");return l.isDirectory()?{entry:{type:"directory",name:e,path:t,cid:r,content:m,unixfs:l,depth:i,node:u,size:l.fileSize()},next:f}:{entry:{type:"file",name:e,path:t,cid:r,content:m,unixfs:l,depth:i,node:u,size:l.fileSize()},next:f}},Dg=yA;var gA={[ye]:Dg,[ge]:kg,[ln]:xg,[fn]:Eg,[qe.code]:Ag,[$r]:Sg},Og=async(r,e,t,n,o,i,s)=>{let a=gA[r.code];if(a==null)throw(0,Pg.default)(new Error(`No resolver for code ${r.code}`),"ERR_NO_RESOLVER");return a(r,e,t,n,Og,o,i,s)},Ug=Og;var wA=(r="")=>(r.trim().match(/([^\\^/]|\\\/)+/g)??[]).filter(Boolean),bA=r=>{if(r instanceof Uint8Array)return{cid:U.decode(r),toResolve:[]};let e=U.asCID(r);if(e!=null)return{cid:e,toResolve:[]};if(typeof r=="string"){r.indexOf("/ipfs/")===0&&(r=r.substring(6));let t=wA(r);return{cid:U.parse(t[0]),toResolve:t.slice(1)}}throw(0,Qc.default)(new Error(`Unknown path type ${r}`),"ERR_BAD_PATH")};async function*As(r,e,t={}){let{cid:n,toResolve:o}=bA(r),i=n.toString(),s=i,a=o.length;for(;;){let c=await Ug(n,i,s,o,a,e,t);if(c.entry==null&&c.next==null)throw(0,Qc.default)(new Error(`Could not resolve ${r}`),"ERR_NOT_FOUND");if(c.entry!=null&&(yield c.entry),c.next==null)return;o=c.next.toResolve,n=c.next.cid,i=c.next.name,s=c.next.path}}async function ze(r,e,t={}){let n=await yn(As(r,e,t));if(n==null)throw(0,Qc.default)(new Error(`Could not resolve ${r}`),"ERR_NOT_FOUND");return n}async function*jo(r,e,t={}){let n=await ze(r,e,t);if(n==null)return;if(yield n,n.type==="directory")for await(let i of o(n,t))yield i;async function*o(i,s){for await(let a of i.content(s))yield a,!(a instanceof Uint8Array)&&a.type==="directory"&&(yield*o(a,s))}}var qg=J(Gg(),1),Xe=qg.default;var Yt=class extends Error{name;code;constructor(e,t,n){super(e),this.name=t,this.code=n}},lr=class extends Yt{constructor(e="not a Unixfs node"){super(e,"NotUnixFSError","ERR_NOT_UNIXFS")}},ot=class extends Yt{constructor(e="invalid PBNode"){super(e,"InvalidPBNodeError","ERR_INVALID_PBNODE")}},Pr=class extends Yt{constructor(e="unknown error"){super(e,"InvalidPBNodeError","ERR_UNKNOWN_ERROR")}},Ss=class extends Yt{constructor(e="path already exists"){super(e,"AlreadyExistsError","ERR_ALREADY_EXISTS")}},rl=class extends Yt{constructor(e="path does not exist"){super(e,"DoesNotExistError","ERR_DOES_NOT_EXIST")}},Zo=class extends Yt{constructor(e="no content"){super(e,"NoContentError","ERR_NO_CONTENT")}},nl=class extends Yt{constructor(e="not a file"){super(e,"NotAFileError","ERR_NOT_A_FILE")}},gn=class extends Yt{constructor(e="not a directory"){super(e,"NotADirectoryError","ERR_NOT_A_DIRECTORY")}},vt=class extends Yt{constructor(e="invalid parameters"){super(e,"InvalidParametersError","ERR_INVALID_PARAMETERS")}};var Cd=J(jc(),1);function il(r){function e(t){return t instanceof ol?t:new ol(t,r)}return e}var ol=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 o=this._buffers[this._currentBufferIndex],i=Math.min(o.availableBits(),t),s=o.take(i);n=(n<<i)+s,t-=i,this._availableBits-=i,o.availableBits()===0&&this._currentBufferIndex++}return n}untake(e){let t=e;for(;t>0;){let n=this._buffers[this._currentBufferIndex],o=Math.min(n.totalBits()-n.availableBits(),t);n.untake(o),t-=o,this._availableBits+=o,this._currentBufferIndex>0&&n.totalBits()===n.availableBits()&&(this._depth--,this._currentBufferIndex--)}}async _produceMoreBits(){this._depth++;let e=this._depth>0?ue([this._value,Uint8Array.from([this._depth])]):this._value,t=await this._hashFn(e),n=new Rd(t);this._buffers.push(n),this._availableBits+=n.availableBits()}},_A=[255,254,252,248,240,224,192,128],kA=[1,3,7,15,31,63,127,255],Rd=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 o=this._value[this._currentBytePos],i=this._currentBitPos+1,s=Math.min(i,t),a=IA(o,i-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 IA(r,e,t){let n=BA(e,t);return(r&n)>>>e}function BA(r,e){return _A[r]&kA[Math.min(e+r-1,7)]}var _s=BigInt(Gn.code),jn=8;async function Jo(r){return(await Gn.encode(r)).subarray(0,8).reverse()}var Yg=J(jc(),1);var Xt=async(r,e,t)=>{t.codec==null&&(t.codec=Ne);let n=await ae.digest(r),o=U.create(t.cidVersion,t.codec.code,n);return await e.put(o,r,{...t,signal:t.signal}),o};var Td=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}},sl=class extends Td{_bucket;constructor(e,t){super(e,t),this._bucket=Go({hashFn:Jo,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=jg(this._bucket,this,this.options),this.nodeSize)}async*flush(e){for await(let t of Wg(this._bucket,e,this,this.options))yield{...t,path:this.path}}};async function*Wg(r,e,t,n){let o=r._children,i=[],s=0n;for(let d=0;d<o.length;d++){let p=o.get(d);if(p==null)continue;let h=d.toString(16).toUpperCase().padStart(2,"0");if(p instanceof Et){let g;for await(let y of Wg(p,e,null,n))g=y;if(g==null)throw new Error("Could not flush sharded directory, no subshard found");i.push({Name:h,Tsize:Number(g.size),Hash:g.cid}),s+=g.size}else if(RA(p.value)){let g=p.value,y;for await(let b of g.flush(e))y=b,yield y;if(y==null)throw new Error("Did not flush dir");let x=h+p.key;i.push({Name:x,Tsize:Number(y.size),Hash:y.cid}),s+=y.size}else{let g=p.value;if(g.cid==null)continue;let y=h+p.key,x=g.size;i.push({Name:y,Tsize:Number(x),Hash:g.cid}),s+=BigInt(x??0)}}let a=Uint8Array.from(o.bitField().reverse()),c=new G({type:"hamt-sharded-directory",data:a,fanout:BigInt(r.tableSize()),hashType:_s,mtime:t?.mtime,mode:t?.mode}),u={Data:c.marshal(),Links:i},l=ne(_e(u)),f=await Xt(l,e,n),m=BigInt(l.byteLength)+s;yield{cid:f,unixfs:c,size:m}}function RA(r){return typeof r.flush=="function"}function jg(r,e,t){let n=r._children,o=[];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 Et){let f=jg(u,null,t);o.push({Name:l,Tsize:Number(f),Hash:t.cidVersion===0?al:cl})}else if(typeof u.value.flush=="function"){let m=u.value.nodeSize();o.push({Name:l+u.key,Tsize:Number(m),Hash:t.cidVersion===0?al:cl})}else{let f=u.value;if(f.cid==null)continue;let m=l+u.key,d=f.size;o.push({Name:m,Tsize:Number(d),Hash:f.cid})}}let i=Uint8Array.from(n.bitField().reverse()),s=new G({type:"hamt-sharded-directory",data:i,fanout:BigInt(r.tableSize()),hashType:_s,mtime:e?.mtime,mode:e?.mode});return ne(_e({Data:s.marshal(),Links:o})).length}var al=U.parse("QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn"),cl=U.parse("zdj7WbTaiJT1fgatdet9Ei9iDB5hdCxkbVyhyh8YTUnXMiwYi");var Nd=ee("helia:unixfs:commands:utils:hamt-utils"),ll=r=>r.toString(16).toUpperCase().padStart(2,"0").substring(0,2),Xg=async(r,e,t)=>{let n=new sl({root:!0,dir:!0,parent:void 0,parentKey:void 0,path:"",dirty:!0,flat:!1,mtime:t.mtime,mode:t.mode},t);for(let i=0;i<e.length;i++)await n._bucket.put(e[i].name,{size:e[i].size,cid:e[i].cid});let o=await yn(n.flush(r));if(o==null)throw new Error("Flushing shard yielded no result");return o},ul=async(r,e,t)=>{let n=G.unmarshal(r[0].node.Data??new Uint8Array(0)),o=BigInt(Math.pow(2,jn));r.reverse();let i,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()),f=new G({type:"hamt-sharded-directory",data:l,fanout:o,hashType:_s});c&&(f.mtime=n.mtime,f.mode=n.mode),s={Data:f.marshal(),Links:u.node.Links};let m=ne(_e(s));if(i=await Xt(m,e,t),!c){let d=r[a+1];if(d==null)throw new Error("Was not operating on shard root but also had no parent?");Nd("updating link in parent sub-shard with prefix %s",d.prefix),d.node.Links=d.node.Links.filter(p=>p.Name!==d.prefix),d.node.Links.push({Name:d.prefix,Hash:i,Tsize:u.node.Links.reduce((p,h)=>p+(h.Tsize??0),m.byteLength)})}}if(i==null||s==null)throw new Error("Noting persisted");return{cid:i,node:s}},fl=async(r,e,t,n)=>{let i=il(Jo)(F(e)),s=[];for(;;){let a=await t.get(r,n),c=be(a),u=new Yg.default,l=await i.take(jn),f=ll(l);s.push({prefix:f,children:u,node:c});let m;for(let p of c.Links){let h=p.Name??"";if(h.length<2)throw new Error("Invalid HAMT - link name was too short");let g=parseInt(h.substring(0,2),16);u.set(g,!0),h.startsWith(f)&&(m=p)}if(m==null){Nd("no link found with prefix %s for %s",f,e);break}let d=m.Name??"";if(d.length<2)throw new Error("Invalid HAMT - link name was too short");if(d.length===2){r=m.Hash,Nd("descend into sub-shard with prefix %s",d);continue}break}return{path:s,hash:i}};async function dl(r,e,t,n){if(r.Data==null)throw new Error("DagPB node had no data");let o=G.unmarshal(r.Data),i;if(o.type==="directory")i=TA(r);else if(o.type==="hamt-sharded-directory")i=await Zg(r,0,t,e,n);else throw new Error("Can only estimate the size of directories or shards");return i>t}function TA(r){let e=0;for(let t of r.Links)e+=(t.Name??"").length,e+=t.Hash.version===1?cl.bytes.byteLength:al.bytes.byteLength;return e}async function Zg(r,e,t,n,o){if(e>t)return t;if(r.Data==null||!G.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===ye){let c=await n.get(s.Hash,o),u=be(c);e+=await Zg(u,e,t,n,o)}}return e}var ur=ee("helia:unixfs:components:utils:add-link");async function Qo(r,e,t,n){if(r.node.Data==null)throw new vt("Invalid parent passed to addLink");if(G.unmarshal(r.node.Data).type==="hamt-sharded-directory")return ur("adding link to sharded directory"),LA(r,e,t,n);ur(`adding ${e.Name} (${e.Hash}) to regular directory`);let i=await CA(r,e,t,n);if(await dl(i.node,t,n.shardSplitThresholdBytes,n)){ur("converting directory to sharded directory");let s=await NA(i,t);i.cid=s.cid,i.node=be(await t.get(s.cid,n))}return i}var NA=async(r,e)=>{if(r.node.Data==null)throw new vt("Invalid parent passed to convertToShardedDirectory");let t=G.unmarshal(r.node.Data),n=await Xg(e,r.node.Links.map(o=>({name:o.Name??"",size:BigInt(o.Tsize??0),cid:o.Hash})),{mode:t.mode,mtime:t.mtime,cidVersion:r.cid.version});return ur(`converted directory to sharded directory ${n.cid}`),n},CA=async(r,e,t,n)=>{let o=r.node.Links.filter(l=>{let f=l.Name===e.Name;if(f&&!n.allowOverwriting)throw new Ss;return!f});if(o.push(e),r.node.Data==null)throw new ot("Parent node with no data passed to addToDirectory");let i=G.unmarshal(r.node.Data),s;if(i.mtime!=null){let l=Date.now(),f=Math.floor(l/1e3);i.mtime={secs:BigInt(f),nsecs:(l-f*1e3)*1e3},s=i.marshal()}else s=r.node.Data;r.node=_e({Data:s,Links:o});let a=ne(r.node),c=await ae.digest(a),u=U.create(r.cid.version,ye,c);return await t.put(u,a),{node:r.node,cid:u}},LA=async(r,e,t,n)=>{let{path:o,hash:i}=await fl(r.cid,e.Name,t,n),s=o[o.length-1];if(s==null)throw new Error("Invalid HAMT, could not generate path");let a=s.prefix,c=parseInt(a,16);ur("next prefix for %s is %s",e.Name,a);let u=`${a}${e.Name}`,l=s.node.Links.find(f=>(f.Name??"").startsWith(a));if(l!=null)if(ur("link %s was present in shard",u),l.Name===u){if(!n.allowOverwriting)throw new Ss;ur("overwriting %s in subshard",e.Name),s.node.Links=s.node.Links.filter(f=>f.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?!");{ur("prefix %s already exists, creating new subshard",a);let f=s.node.Links.findIndex(g=>g.Name?.startsWith(a)),m=s.node.Links.splice(f,1)[0],d=(m.Name??"").substring(2),h=il(Jo)(F(d));for(let g=0;g<o.length;g++)await h.take(jn);for(;;){let g=await h.take(jn),y=ll(g);m.Name=`${y}${d}`;let x=await i.take(jn),b=ll(x);if(y===b){let _=new Cd.default;_.set(x,!0),o.push({prefix:b,children:_,node:{Links:[]}});continue}let S=new Cd.default;S.set(x,!0),S.set(g,!0),o.push({prefix:a,children:S,node:{Links:[m,{Name:`${b}${e.Name}`,Hash:e.Hash,Tsize:e.Tsize}]}});break}}}else ur("link %s was not present in sub-shard",u),e.Name=u,s.node.Links.push(e),s.children.set(c,!0),ur("adding %s to existing sub-shard",u);return ul(o,t,n)};async function wn(r,e,t={}){let n=await ze(r,e,t);if(n.type!=="directory")throw new gn(`${r.toString()} was not a UnixFS directory`);return{cid:r,node:n.node}}async function ei(r,e,t,n){let o=await ze(r,t,n);if(o.type!=="directory"&&o.type!=="file"&&o.type!=="raw")throw new lr(`${r.toString()} was not a UnixFS node`);return{Name:e,Tsize:o.node instanceof Uint8Array?o.node.byteLength:DA(o.node),Hash:r}}function DA(r){let e=r.Links.reduce((t,n)=>t+(n.Tsize??0),0);return ne(r).byteLength+e}var PA=ee("helia:unixfs:components:utils:resolve");async function fr(r,e,t,n){if(e==null||e==="")return{cid:r};let o=`/ipfs/${r}${e==null?"":`/${e}`}`,i=await Ko(As(o,t,n));if(i.length===0)throw new rl("Could not find path in directory");return PA("resolved %s to %c",e,r),{cid:i[i.length-1].cid,path:e,segments:i}}async function ti(r,e,t,n){if(e.segments==null||e.segments.length===0)return r;let o=e.segments.pop();if(o==null)throw new Error("Insufficient segments");o.cid=r,e.segments.reverse();for(let i of e.segments){let[s,a]=await Promise.all([wn(i.cid,t,n),ei(o.cid,o.name,t,n)]);r=(await Qo(s,a,t,{...n,allowOverwriting:!0,cidVersion:r.version})).cid,i.cid=r,o=i}return r}var OA=Xe.bind({ignoreUndefined:!0}),UA={};async function*Jg(r,e,t={}){let n=OA(UA,t),o=await fr(r,n.path,e,n),i=await ze(o.cid,e,n);if(i.type!=="file"&&i.type!=="raw")throw new nl;if(i.content==null)throw new Zo;yield*i.content(n)}var FA=Xe.bind({ignoreUndefined:!0}),VA=ee("helia:unixfs:chmod"),HA={recursive:!1,shardSplitThresholdBytes:262144};async function Qg(r,e,t,n={}){let o=FA(HA,n),i=await fr(r,o.path,t,n);if(VA("chmod %c %d",i.cid,e),o.recursive){let m=await at(async function*(){for await(let d of jo(i.cid,t,n)){let p,h=[];if(d.type==="raw")p=new G({type:"file",data:d.node});else if(d.type==="file"||d.type==="directory")p=d.unixfs,h=d.node.Links;else throw new lr;p.mode=e;let g={Data:p.marshal(),Links:h};yield{path:d.path,content:g}}},d=>mn(d,t,{...o,dagBuilder:async function*(p,h){for await(let g of p)yield async function(){let y=g.content,x=ne(y),b=await Xt(x,h,{...o,cidVersion:r.version});if(y.Data==null)throw new ot(`${b} had no data`);let S=G.unmarshal(y.Data);return{cid:b,size:BigInt(x.length),path:g.path,unixfs:S}}}}),async d=>yn(d));if(m==null)throw new Pr(`Could not chmod ${i.cid.toString()}`);return ti(m.cid,i,t,o)}let s=await t.get(i.cid,n),a,c=[];if(i.cid.code===ge)a=new G({type:"file",data:s});else{let m=be(s);if(m.Data==null)throw new ot(`${i.cid.toString()} had no data`);c=m.Links,a=G.unmarshal(m.Data)}a.mode=e;let u=ne({Data:a.marshal(),Links:c}),l=await ae.digest(u),f=U.create(i.cid.version,ye,l);return await t.put(f,u),ti(f,i,t,o)}var MA=Xe.bind({ignoreUndefined:!0}),zA=ee("helia:unixfs:cp"),$A={force:!1,shardSplitThresholdBytes:262144};async function ew(r,e,t,n,o={}){let i=MA($A,o);if(t.includes("/"))throw new vt("Name must not have slashes");let[s,a]=await Promise.all([wn(e,n,i),ei(r,t,n,i)]);return zA('Adding %c as "%s" to %c',r,t,e),(await Qo(s,a,n,{allowOverwriting:i.force,cidVersion:e.version,...i})).cid}var KA=Xe.bind({ignoreUndefined:!0}),GA={};async function*tw(r,e,t={}){let n=KA(GA,t),o=await fr(r,n.path,e,n),i=await ze(o.cid,e);if(i.type==="file"||i.type==="raw"){yield i;return}if(i.content==null)throw new Zo;if(i.type!=="directory")throw new gn;yield*i.content({offset:t.offset,length:t.length})}var qA=Xe.bind({ignoreUndefined:!0}),rw=ee("helia:unixfs:mkdir"),WA={cidVersion:1,force:!1,shardSplitThresholdBytes:262144};async function nw(r,e,t,n={}){let o=qA(WA,n);if(e.includes("/"))throw new vt("Path must not have slashes");if((await ze(r,t,n)).type!=="directory")throw new gn(`${r.toString()} was not a UnixFS directory`);rw("creating %s",e);let a={Data:new G({type:"directory",mode:o.mode,mtime:o.mtime}).marshal(),Links:[]},c=ne(a),u=await ae.digest(c),l=U.create(o.cidVersion,ye,u);await t.put(l,c);let[f,m]=await Promise.all([wn(r,t,o),ei(l,e,t,o)]);return rw("adding empty dir called %s to %c",e,r),(await Qo(f,m,t,{...o,allowOverwriting:o.force})).cid}var hl=ee("helia:unixfs:utils:remove-link");async function ow(r,e,t,n){if(r.node.Data==null)throw new ot("Parent node had no data");if(G.unmarshal(r.node.Data).type==="hamt-sharded-directory"){hl(`removing ${e} from sharded directory`);let i=await YA(r,e,t,n);return await dl(i.node,t,n.shardSplitThresholdBytes,n)?i:(hl("converting shard to flat directory %c",r.cid),XA(i,t,n))}return hl(`removing link ${e} regular directory`),jA(r,e,t,n)}var jA=async(r,e,t,n)=>{r.node.Links=r.node.Links.filter(s=>s.Name!==e);let o=ne(r.node),i=await Xt(o,t,{...n,cidVersion:r.cid.version});return hl(`Updated regular directory ${i}`),{node:r.node,cid:i}},YA=async(r,e,t,n)=>{let{path:o}=await fl(r.cid,e,t,n),i=o[o.length-1];if(i==null)throw new Error("Invalid HAMT, could not generate path");let s=i.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(i.node.Links=i.node.Links.filter(u=>u.Name!==s),i.children.unset(c),i.node.Links.length===1)for(;o.length!==1;){let u=o[o.length-1];if(u==null||u.node.Links.length>1)break;o.pop();let l=o[o.length-1];if(l==null)break;let f=u.node.Links[0];l.node.Links=l.node.Links.filter(m=>!(m.Name??"").startsWith(l.prefix)),l.node.Links.push({Hash:f.Hash,Name:`${l.prefix}${(f.Name??"").substring(2)}`,Tsize:f.Tsize})}return ul(o,t,n)},XA=async(r,e,t)=>{if(r.node.Data==null)throw new vt("Invalid parent passed to convertToFlatDirectory");let n={Links:[]},o=await ze(r.cid,e);if(o.type!=="directory")throw new Error("Unexpected node type");for await(let c of o.content()){let u=0;c.node instanceof Uint8Array?u=c.node.byteLength:u=ne(c.node).length,n.Links.push({Hash:c.cid,Name:c.name,Tsize:u})}let i=G.unmarshal(r.node.Data);n.Data=new G({type:"directory",mode:i.mode,mtime:i.mtime}).marshal();let s=ne(_e(n));return{cid:await Xt(s,e,{codec:Ne,cidVersion:r.cid.version,signal:t.signal}),node:n}};var ZA=Xe.bind({ignoreUndefined:!0}),JA=ee("helia:unixfs:rm"),QA={shardSplitThresholdBytes:262144};async function iw(r,e,t,n={}){let o=ZA(QA,n);if(e.includes("/"))throw new vt("Name must not have slashes");let i=await wn(r,t,o);return JA("Removing %s from %c",e,r),(await ow(i,e,t,{...o,cidVersion:r.version})).cid}var eS=Xe.bind({ignoreUndefined:!0}),tS=ee("helia:unixfs:stat"),rS={};async function sw(r,e,t={}){let n=eS(rS,t),o=await fr(r,t.path,e,n);tS("stat %c",o.cid);let i=await ze(o.cid,e,n);if(i.type!=="file"&&i.type!=="directory"&&i.type!=="raw")throw new lr;let s=0n,a=0n,c=0n,u=0n,l=0,f,m,d=i.type,p;if(i.type==="raw"&&(s=BigInt(i.node.byteLength),a=BigInt(i.node.byteLength),c=BigInt(i.node.byteLength),u=BigInt(i.node.byteLength),l=1),i.type==="directory"&&(s=0n,a=BigInt(i.unixfs.marshal().byteLength),c=0n,u=a,l=1,f=i.unixfs.mode,m=i.unixfs.mtime,p=i.unixfs),i.type==="file"){let h=await aw(o.cid,e,n);s=i.unixfs.fileSize(),a=BigInt((i.node.Data?.byteLength??0)+i.node.Links.reduce((g,y)=>g+(y.Tsize??0),0)),c=BigInt(h.localFileSize),u=BigInt(h.localDagSize),l=h.blocks,f=i.unixfs.mode,m=i.unixfs.mtime,p=i.unixfs}return{cid:o.cid,mode:f,mtime:m,fileSize:s,dagSize:a,localFileSize:c,localDagSize:u,blocks:l,type:d,unixfs:p}}async function aw(r,e,t){let n={localFileSize:0,localDagSize:0,blocks:0};if(await e.has(r,t)){let o=await e.get(r,t);if(n.blocks++,n.localDagSize+=o.byteLength,r.code===ge)n.localFileSize+=o.byteLength;else if(r.code===ye){let i=be(o);if(i.Links.length>0)for(let s of i.Links){let a=await aw(s.Hash,e,t);n.localFileSize+=a.localFileSize,n.localDagSize+=a.localDagSize,n.blocks+=a.blocks}else{if(i.Data==null)throw new ot(`PBNode ${r.toString()} had no data`);let s=G.unmarshal(i.Data);if(s.data==null)throw new ot(`UnixFS node ${r.toString()} had no data`);n.localFileSize+=s.data.byteLength??0}}else throw new Pr(`${r.toString()} was neither DAG_PB nor RAW`)}return n}var nS=Xe.bind({ignoreUndefined:!0}),oS=ee("helia:unixfs:touch"),iS={recursive:!1,shardSplitThresholdBytes:262144};async function cw(r,e,t={}){let n=nS(iS,t),o=await fr(r,n.path,e,n),i=n.mtime??{secs:BigInt(Math.round(Date.now()/1e3)),nsecs:0};if(oS("touch %c %o",o.cid,i),n.recursive){let m=await at(async function*(){for await(let d of jo(o.cid,e)){let p,h;if(d.type==="raw")p=new G({data:d.node}),h=[];else if(d.type==="file"||d.type==="directory")p=d.unixfs,h=d.node.Links;else throw new lr;p.mtime=i;let g={Data:p.marshal(),Links:h};yield{path:d.path,content:g}}},d=>mn(d,e,{...n,dagBuilder:async function*(p,h){for await(let g of p)yield async function(){let y=g.content,x=ne(y),b=await Xt(x,h,{...n,cidVersion:r.version});if(y.Data==null)throw new ot(`${b} had no data`);let S=G.unmarshal(y.Data);return{cid:b,size:BigInt(x.length),path:g.path,unixfs:S}}}}),async d=>yn(d));if(m==null)throw new Pr(`Could not chmod ${o.cid.toString()}`);return ti(m.cid,o,e,n)}let s=await e.get(o.cid,t),a,c=[];if(o.cid.code===ge)a=new G({data:s});else{let m=be(s);if(c=m.Links,m.Data==null)throw new ot(`${o.cid.toString()} had no data`);a=G.unmarshal(m.Data)}a.mtime=i;let u=ne({Data:a.marshal(),Links:c}),l=await ae.digest(u),f=U.create(o.cid.version,ye,l);return await e.put(f,u),ti(f,o,e,n)}var Ld=class{components;constructor(e){this.components=e}async*addAll(e,t={}){yield*pg(e,this.components.blockstore,t)}async addBytes(e,t={}){return mg(e,this.components.blockstore,t)}async addByteStream(e,t={}){return yg(e,this.components.blockstore,t)}async addFile(e,t={}){return gg(e,this.components.blockstore,t)}async addDirectory(e={},t={}){return wg(e,this.components.blockstore,t)}async*cat(e,t={}){yield*Jg(e,this.components.blockstore,t)}async chmod(e,t,n={}){return Qg(e,t,this.components.blockstore,n)}async cp(e,t,n,o={}){return ew(e,t,n,this.components.blockstore,o)}async*ls(e,t={}){yield*tw(e,this.components.blockstore,t)}async mkdir(e,t,n={}){return nw(e,t,this.components.blockstore,n)}async rm(e,t,n={}){return iw(e,t,this.components.blockstore,n)}async stat(e,t={}){return sw(e,this.components.blockstore,t)}async touch(e,t={}){return cw(e,this.components.blockstore,t)}};function lw(r){return new Ld(r)}function pl(r,e={}){let t={_cancelled:!1,async start(){this._cancelled=!1},async pull(n){try{let{value:o,done:i}=await r.next();if(this._cancelled)return;if(i===!0){n.close();return}n.enqueue(o)}catch(o){n.error(o)}},cancel(){this._cancelled=!0}};return new globalThis.ReadableStream(t,e)}function uw(r){let e=tt(r,{allowIndefinite:!1,coerceUndefinedToNull:!1,allowNaN:!1,allowInfinity:!1,strict:!0,useMaps:!1,rejectDuplicateMapKeys:!0,allowBigInt:!1});return new TextDecoder().decode(Zi(e))}function fw(r){let e=sS(r);return e===r?`filename="${r}"`:`filename="${e}"; filename*=UTF-8''${encodeURIComponent(r)}`}function sS(r){return r.replace(/[^\x00-\x7F]/g,"_")}function dw({cid:r,reqFormat:e,weak:t,rangeStart:n,rangeEnd:o}){let i=t===!0?"W/":"",s=e==null?"":`.${e}`;return(n!=null||o!=null)&&(s+=`.${n??"0"}-${o??"N"}`),`${i}"${r.toString()}${s}"`}async function hw(r,e,t,n){let o=t.forComponent("helia:verified-fetch:get-stream-from-async-iterable"),i=r[Symbol.asyncIterator](),{value:s,done:a}=await i.next();if(a===!0)throw o.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:f}=await i.next();if(f===!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 jH=F("ustar\0","binary"),YH=F("ustar ","binary"),XH=F(" \0","binary");var ww=J(mw(),1);function cS(r){return r[Symbol.asyncIterator]!=null}function lS(r){if(cS(r))return(async()=>{let n=new Uint8Array(0);for await(let o of r)n=ue([n,o],n.length+o.length);return n})();let e=[],t=0;for(let n of r)e.push(n),t+=n.byteLength;return ue(e,t)}var yw=lS;var uS="0000000000000000000",fS="7777777777777777777",dS=48,hS=F("ustar\0","binary"),pS=F("00","binary"),mS=parseInt("7777",8),yS=257,gS=263,wS=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}},bS=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},bn=function(r,e){let t=r.toString(8);return t.length>e?F(fS.slice(0,e)+" "):F(uS.slice(0,e-t.length)+t+" ")},Dd=function(r){let e=F(r).byteLength,t=Math.floor(Math.log(e)/Math.log(10))+1;return e+t>=Math.pow(10,t)&&t++,`${e+t}${r}`};function gw(r){let e="";r.name!=null&&(e+=Dd(" path="+r.name+`
9
- `)),r.linkname!=null&&(e+=Dd(" linkpath="+r.linkname+`
10
- `));let t=r.pax;if(t!=null)for(let n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e+=Dd(" "+n+"="+t[n]+`
11
- `));return F(e)}function ml(r){let e=new Uint8Array(512),t=r.name,n="";if(r.typeflag===5&&t[t.length-1]!=="/"&&(t+="/"),F(t).byteLength!==t.length)return null;for(;F(t).byteLength>100;){let o=t.indexOf("/");if(o===-1)return null;n+=n!==""?"/"+t.slice(0,o):t.slice(0,o),t=t.slice(o+1)}return F(t).byteLength>100||F(n).byteLength>155||r.linkname!=null&&F(r.linkname).byteLength>100?null:(e.set(F(t),0),e.set(bn(r.mode&mS,6),100),e.set(bn(r.uid,6),108),e.set(bn(r.gid,6),116),e.set(bn(r.size,11),124),e.set(bn(r.mtime.getTime()/1e3|0,11),136),e[156]=dS+wS(r.type),r.linkname!=null&&e.set(F(r.linkname),157),e.set(hS,yS),e.set(pS,gS),r.uname!=null&&e.set(F(r.uname),265),r.gname!=null&&e.set(F(r.gname),297),e.set(bn(r.devmajor??0,6),329),e.set(bn(r.devminor??0,6),337),n!=null&&e.set(F(n),345),e.set(bn(bS(e),6),148),e)}var{S_IFMT:ES,S_IFBLK:vS,S_IFCHR:AS,S_IFDIR:SS,S_IFIFO:_S,S_IFLNK:kS}=ww.default,IS=parseInt("755",8),BS=parseInt("644",8),bw=new Uint8Array(1024);function RS(r=0){switch(r&ES){case vS:return"block-device";case AS:return"character-device";case SS:return"directory";case _S:return"fifo";case kS:return"symlink";default:return"file"}}function Od(r){return r&=511,r!==0?bw.subarray(0,512-r):new Uint8Array(0)}function Pd(r){if(r.pax==null){let e=ml(r);if(e!=null)return e}return TS(r)}function TS(r){let e=gw(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 Rt(ml(t)??new Uint8Array(0),e,Od(e.length),ml({...t,size:r.size,type:r.type})??new Uint8Array(0)).subarray()}function yl(){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??RS(e.mode),mode:e.mode??(e.type==="directory"?IS:BS),uid:e.uid??0,gid:e.gid??0,mtime:e.mtime??new Date};if(typeof t=="string"&&(t=F(t)),t instanceof Uint8Array||Qt(t)){n.size=t.length,yield Pd(n),yield Qt(t)?t.subarray():t,yield Od(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=W(await yw(t)),yield Pd(n);continue}if(yield Pd(n),n.type!=="file"&&n.type!=="contiguous-file")continue;let o=0;for await(let i of t??[])o+=i.length,yield Qt(i)?i.subarray():i;if(o!==n.size)throw new Error(`size mismatch, wrote ${o} of ${n.size} bytes`);yield Od(n.size)}yield bw}}var NS=["file","raw","directory"];function CS(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 xw(r){if(!NS.includes(r.type))throw new P("Not a UnixFS node","ERR_NOT_UNIXFS");let e={header:CS(r)};return(r.type==="file"||r.type==="raw")&&(e.body=r.content()),e}async function*Ew(r,e,t){let n=await ze(r,e,t);if(n.type==="file"||n.type==="raw"){yield*at([xw(n)],yl());return}if(n.type==="directory"){yield*at(jo(r,e,t),o=>We(o,i=>xw(i)),yl());return}throw new P("Not a UnixFS node","ERR_NOT_UNIXFS")}var vw=J(Cf(),1),gl=class{lru;constructor(e){this.lru=(0,vw.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 Ud=new gl(1e3),LS=/^(?<protocol>ip[fn]s):\/\/(?<cidOrPeerIdOrDnsLink>[^/?]+)\/?(?<path>[^?]*)\??(?<queryString>.*)$/,DS=/^\/(?<protocol>ip[fn]s)\/(?<cidOrPeerIdOrDnsLink>[^/?]+)\/?(?<path>[^?]*)\??(?<queryString>.*)$/,PS=/^https?:\/\/(.*[^/])\/(?<protocol>ip[fn]s)\/(?<cidOrPeerIdOrDnsLink>[^/?]+)\/?(?<path>[^?]*)\??(?<queryString>.*)$/,OS=/^https?:\/\/(?<cidOrPeerIdOrDnsLink>[^/?]+)\.(?<protocol>ip[fn]s)\.([^/?]+)\/?(?<path>[^?]*)\??(?<queryString>.*)$/;function US(r){for(let e of[LS,DS,PS,OS]){let t=r.match(e);if(t?.groups!=null)return t.groups}throw new TypeError(`Invalid URL: ${r}, please use ipfs://, ipns://, or gateway URLs only`)}var FS=/^[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?$/;function VS(r){return FS.test(r)&&r.includes("-")&&!r.includes(".")}function HS(r){return r.replace(/--/g,"%").replace(/-/g,".").replace(/%/g,"-")}async function Aw({urlString:r,ipns:e,logger:t},n){let o=t.forComponent("helia:verified-fetch:parse-url-string"),{protocol:i,cidOrPeerIdOrDnsLink:s,path:a,queryString:c}=US(r),u,l,f=[];if(i==="ipfs")try{u=U.parse(s)}catch(d){o.error(d),f.push(new TypeError("Invalid CID for ipfs://<cid> URL"))}else{let d=Ud.get(s);if(d!=null)u=d.cid,l=d.path,o.trace("resolved %s to %c from cache",s,u);else{o.trace("Attempting to resolve PeerId for %s",s);let p=null;try{p=Je(s),d=await e.resolve(p,{onProgress:n?.onProgress}),u=d?.cid,l=d?.path,o.trace("resolved %s to %c",s,u),Ud.set(s,d,60*1e3*2)}catch(h){p==null?(o.error('Could not parse PeerId string "%s"',s,h),f.push(new TypeError(`Could not parse PeerId in ipns url "${s}", ${h.message}`))):(o.error("Could not resolve PeerId %c",p,h),f.push(new TypeError(`Could not resolve PeerId "${s}", ${h.message}`)))}if(u==null){let h=s;VS(s)&&(h=HS(s),o.trace('decoded dnslink from "%s" to "%s"',s,h)),o.trace("Attempting to resolve DNSLink for %s",h);try{d=await e.resolveDNSLink(h,{onProgress:n?.onProgress}),u=d?.cid,l=d?.path,o.trace("resolved %s to %c",h,u),Ud.set(s,d,60*1e3*2)}catch(g){o.error('Could not resolve DnsLink for "%s"',s,g),f.push(g)}}}}if(u==null)throw f.length===1?f[0]:new AggregateError(f,`Invalid resource. Cannot determine CID from URL "${r}"`);let m={};if(c!=null&&c.length>0){let d=c.split("&");for(let p of d){let[h,g]=p.split("=");m[h]=decodeURIComponent(g)}m.download!=null&&(m.download=m.download==="true"),m.filename!=null&&(m.filename=m.filename.toString())}return{protocol:i,cid:u,path:MS(l,a),query:m}}function MS(r,e){let t="";return r!=null&&(t+=r),e.length>0&&(t=`${t.length>0?`${t}/`:t}${e}`),t=t.replace(/\/(\/)+/g,"/"),t.startsWith("/")&&(t=t.substring(1)),t}async function Sw(r,{ipns:e,logger:t},n){if(typeof r=="string")return Aw({urlString:r,ipns:e,logger:t},{onProgress:n?.onProgress});let o=U.asCID(r);if(o!=null)return{cid:o,protocol:"ipfs",path:"",query:{}};throw new TypeError(`Invalid resource. Cannot determine CID from resource: ${r}`)}function Fd(r,e,t){Object.defineProperty(r,e,{enumerable:!0,configurable:!1,set:()=>{},get:()=>t})}function ks(r,e){Fd(r,"type",e)}function Is(r,e){Fd(r,"url",e)}function zS(r){Fd(r,"redirected",!0)}function xn(r,e,t){let n=new Response(e,{...t??{},status:200,statusText:"OK"});return t?.redirected===!0&&zS(n),ks(n,"basic"),Is(n,r),n}function Vd(r,e,t){let n=new Response(e,{...t??{},status:501,statusText:"Not Implemented"});return n.headers.set("X-Content-Type-Options","nosniff"),ks(n,"basic"),Is(n,r),n}function ri(r,e,t){let n=new Response(e,{...t??{},status:406,statusText:"Not Acceptable"});return ks(n,"basic"),Is(n,r),n}function Hd(r,e,t){let n=new Response(e,{...t??{},status:400,statusText:"Bad Request"});return ks(n,"basic"),Is(n,r),n}function _w(r,e,t){let n=new Response(null,{...t??{},status:301,statusText:"Moved Permanently",headers:{...t?.headers??{},location:e}});return ks(n,"basic"),Is(n,r),n}var $S={[ln]:["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"],[fn]:["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"],[$r]:["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"],[ye]:["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"],[ge]:["application/octet-stream","application/vnd.ipld.raw","application/vnd.ipfs.ipns-record","application/vnd.ipld.car","application/x-tar"]};function kw(r,e){let t=$S[r.code];if(e!=null)return KS(e,t)}function KS(r,e){let t=r.split(",").map(n=>{let o=n.trim().split(";");return{mimeType:`${o[0]}`.trim(),weight:GS(o[1])}}).sort((n,o)=>n.weight===o.weight?0:n.weight>o.weight?-1:1).map(n=>n.mimeType);for(let n of t)for(let o of e)if(n.includes(o)||n==="*/*"||n.startsWith("*/")&&o.split("/")[1]===n.split("/")[1]||n.endsWith("/*")&&o.split("/")[0]===n.split("/")[0])return o}function GS(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 qS={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 Iw(r){if(r!=null)return qS[r]}async function Bw(r,e,t){let n=[],o;for await(let i of As(e,r,t))n.push(i.cid),o=i;if(o==null)throw new Error("No terminal element found");return{ipfsRoots:n,terminalElement:o}}function WS(r){if(r==null)return;let e;return r?.signal===null&&(e=void 0),{...r,signal:e}}var jS=["application/vnd.ipld.raw","application/octet-stream"];function YS(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(jS.includes(n??""))return n}}var wl=class{helia;ipns;unixfs;log;contentTypeParser;constructor({helia:e,ipns:t,unixfs:n},o){this.helia=e,this.log=e.logger.forComponent("helia:verified-fetch"),this.ipns=t??ky(e),this.unixfs=n??lw(e),this.contentTypeParser=o?.contentTypeParser,this.log.trace("created VerifiedFetch instance")}async handleIPNSRecord({resource:e,cid:t,path:n,options:o}){if(n!==""||!e.startsWith("ipns://"))return Hd("Invalid IPNS name");let i;try{i=Je(e.replace("ipns://",""))}catch{return this.log.error("could not parse peer id from IPNS url %s",e),Hd("Invalid IPNS name")}let s=ue([F("/ipns/"),i.toBytes()]),a=new Be("/dht/record/"+W(s,"base32"),!1),c=await this.helia.datastore.get(a,o),u=pn.deserialize(c),l=xn(e,u.value);return l.headers.set("content-type","application/vnd.ipfs.ipns-record"),l}async handleCar({resource:e,cid:t,options:n}){let o=yy(this.helia),i=pl(o.stream(t,n)),s=xn(e,i);return s.headers.set("content-type","application/vnd.ipld.car; version=1"),s}async handleTar({resource:e,cid:t,path:n,options:o}){if(t.code!==ye&&t.code!==ge)return ri("only UnixFS data can be returned in a TAR file");let i=pl(Ew(`/ipfs/${t}/${n}`,this.helia.blockstore,o)),s=xn(e,i);return s.headers.set("content-type","application/x-tar"),s}async handleJson({resource:e,cid:t,path:n,accept:o,options:i}){this.log.trace("fetching %c/%s",t,n);let s=await this.helia.blockstore.get(t,i),a;if(o==="application/vnd.ipld.dag-cbor"||o==="application/cbor")try{let u=Lc(s);a=Yi(u)}catch(u){return this.log.error("could not transform %c to application/vnd.ipld.dag-cbor",u),ri(e)}else a=s;let c=xn(e,a);return c.headers.set("content-type",o??"application/json"),c}async handleDagCbor({resource:e,cid:t,path:n,accept:o,options:i}){this.log.trace("fetching %c/%s",t,n);let s=await this.helia.blockstore.get(t,i),a;if(o==="application/octet-stream"||o==="application/vnd.ipld.dag-cbor"||o==="application/cbor")a=s;else if(o==="application/vnd.ipld.dag-json")try{let u=Hn(s);a=M1(u)}catch(u){return this.log.error("could not transform %c to application/vnd.ipld.dag-json",u),ri(e)}else try{a=uw(s)}catch(u){if(o==="application/json")return this.log('could not decode DAG-CBOR as JSON-safe, but the client sent "Accept: application/json"',u),ri(e);this.log("could not decode DAG-CBOR as JSON-safe, falling back to `application/octet-stream`",u),a=s}let c=xn(e,a);return o==null&&(o=a instanceof Uint8Array?"application/octet-stream":"application/json"),c.headers.set("content-type",o),c}async handleDagPb({cid:e,path:t,resource:n,options:o}){let i,s,a=!1;try{let p=await Bw(this.helia.blockstore,`${e.toString()}/${t}`,o);s=p.ipfsRoots,i=p.terminalElement}catch(p){this.log.error("Error walking path %s",t,p)}let c=i?.cid??e,u;if(i?.type==="directory"){let p=i.cid;if(t!==""&&!t.endsWith("/")){if(o?.redirect==="error")throw this.log('could not redirect to %s/ as redirect option was set to "error"',n),new TypeError("Failed to fetch");if(o?.redirect==="manual")return this.log("returning 301 permanent redirect to %s/",n),_w(n,`${n}/`);n=`${n}/`,a=!0}let h="index.html";try{this.log.trace("found directory at %c/%s, looking for index.html",e,t),u=await this.unixfs.stat(p,{path:h,signal:o?.signal,onProgress:o?.onProgress}),this.log.trace("found root file at %c/%s with cid %c",p,h,u.cid),t=h,c=u.cid}catch(g){return this.log("error loading path %c/%s",p,h,g),Vd("Unable to find index.html for directory at given path. Support for directories with implicit root is not implemented")}finally{o?.onProgress?.(new V("verified-fetch:request:end",{cid:p,path:h}))}}let l=this.unixfs.cat(c,{signal:o?.signal,onProgress:o?.onProgress});this.log("got async iterator for %c/%s",e,t);let{stream:f,firstChunk:m}=await hw(l,t??"",this.helia.logger,{onProgress:o?.onProgress}),d=xn(n,f,{redirected:a});return await this.setContentType(m,t,d),s!=null&&d.headers.set("X-Ipfs-Roots",s.map(p=>p.toV1().toString()).join(",")),d}async handleRaw({resource:e,cid:t,path:n,options:o}){let i=await this.helia.blockstore.get(t,o),s=xn(e,i),a=YS(o?.headers);return a!=null?s.headers.set("content-type",a):await this.setContentType(i,n,s),s}async setContentType(e,t,n){let o="application/octet-stream";if(this.contentTypeParser!=null)try{let i=t.split("/").pop()?.trim();i=i===""?void 0:i;let s=this.contentTypeParser(e,i);if(XS(s)){let a=await s;a!=null&&(o=a)}else s!=null&&(o=s)}catch(i){this.log.error("Error parsing content type",i)}n.headers.set("content-type",o)}codecHandlers={[ye]:this.handleDagPb,[fn]:this.handleJson,[$r]:this.handleJson,[ln]:this.handleDagCbor,[ge]:this.handleRaw,[qe.code]:this.handleRaw};async fetch(e,t){this.log("fetch %s",e);let n=WS(t);n?.onProgress?.(new V("verified-fetch:request:start",{resource:e}));let{path:o,query:i,cid:s}=await Sw(e,{ipns:this.ipns,logger:this.helia.logger},n);n?.onProgress?.(new V("verified-fetch:request:resolve",{cid:s,path:o}));let c=new Headers(n?.headers).get("accept");c!=null&&this.log('incoming accept header "%s"',c);let u=Iw(i.format);i.format!=null&&this.log('incoming query format "%s", mapped to %s',i.format,u);let l=c??u,f=kw(s,l);if(this.log("output type %s",f),l!=null&&f==null)return ri(e.toString());let m,d,p={resource:e.toString(),cid:s,path:o,accept:f,options:n};if(f==="application/vnd.ipfs.ipns-record")d="ipns-record",m=await this.handleIPNSRecord(p);else if(f==="application/vnd.ipld.car")d="car",i.download=!0,i.filename=i.filename??`${s.toString()}.car`,m=await this.handleCar(p);else if(f==="application/vnd.ipld.raw")d="raw",i.download=!0,i.filename=i.filename??`${s.toString()}.bin`,m=await this.handleRaw(p);else if(f==="application/x-tar")d="tar",i.download=!0,i.filename=i.filename??`${s.toString()}.tar`,m=await this.handleTar(p);else{let g=this.codecHandlers[s.code];if(g==null)return Vd(`Support for codec with code ${s.code} is not yet implemented. Please open an issue at https://github.com/ipfs/helia/issues/new`);m=await g.call(this,p)}m.headers.set("etag",dw({cid:s,reqFormat:d,weak:!1})),m.headers.set("cache-control","public, max-age=29030400, immutable"),m.headers.set("X-Ipfs-Path",e.toString());let h;return i.download===!0&&(h="attachment"),i.filename!=null&&(h==null&&(h="inline"),h=`${h}; ${fw(i.filename)}`),h!=null&&m.headers.set("Content-Disposition",h),n?.onProgress?.(new V("verified-fetch:request:end",{cid:s,path:o})),m}async start(){await this.helia.start()}async stop(){await this.helia.stop()}};function XS(r){return r?.then!=null}var Bs,bl=async function(e,t){return Bs==null&&(Bs=await Md()),Bs(e,t)};bl.start=async function(){await Bs?.start()};bl.stop=async function(){await Bs?.stop()};async function Md(r,e){ZS(r)||(r=await ly({blockBrokers:[fi({gateways:r?.gateways})],routers:(r?.routers??["https://delegated-ipfs.dev"]).map(o=>qi(o)),dns:JS(r?.dnsResolvers)}));let t=new wl({helia:r},e);async function n(o,i){return t.fetch(o,i)}return n.stop=t.stop.bind(t),n.start=t.start.bind(t),n}function ZS(r){return r?.blockstore!=null&&r?.datastore!=null&&r?.gc!=null&&r?.stop!=null&&r?.start!=null}function JS(r){if(r!=null)return Array.isArray(r)?Wi({resolvers:{".":r}}):Wi({resolvers:r})}return zw(QS);})();
7
+ `)}`:`${t} :`}};r0=Jr;M.Constructed=r0;Jr.NAME="CONSTRUCTED";var xa=class extends je{fromBER(e,t,n){return t}toBER(e){return zt}};xa.override="EndOfContentValueBlock";var n0,Ea=class extends Ve{constructor(e={}){super(e,xa),this.idBlock.tagClass=1,this.idBlock.tagNumber=0}};n0=Ea;M.EndOfContent=n0;Ea.NAME=Si;var o0,Qr=class extends Ve{constructor(e={}){super(e,je),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 o=new Uint8Array(n);o[0]=5,o[1]=0}return t&&t.write(n),n}onAsciiEncoding(){return`${this.constructor.NAME}`}};o0=Qr;M.Null=o0;Qr.NAME="NULL";var va=class extends kr(je){constructor({value:e,...t}={}){super(t),t.valueHex?this.valueHexView=te.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 o=te.BufferSourceConverter.toUint8Array(e);return Ar(this,o,t,n)?(this.valueHexView=o.subarray(t,t+n),n>1&&this.warnings.push("Boolean value encoded in more then 1 octet"),this.isHexOnly=!0,Zu.call(this),this.blockLength=n,t+n):-1}toBER(){return this.valueHexView.slice()}toJSON(){return{...super.toJSON(),value:this.value}}};va.NAME="BooleanValueBlock";var i0,Sa=class extends Ve{constructor(e={}){super(e,va),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}`}};i0=Sa;M.Boolean=i0;Sa.NAME="BOOLEAN";var _a=class extends kr(nr){constructor({isConstructed:e=!1,...t}={}){super(t),this.isConstructed=e}fromBER(e,t,n){let o=0;if(this.isConstructed){if(this.isHexOnly=!1,o=nr.prototype.fromBER.call(this,e,t,n),o===-1)return o;for(let i=0;i<this.value.length;i++){let s=this.value[i].constructor.NAME;if(s===Si){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, OCTET STRING may consists of OCTET STRINGs only",-1}if(s!==Jp)return this.error="OCTET STRING may consists of OCTET STRINGs only",-1}}else this.isHexOnly=!0,o=super.fromBER(e,t,n),this.blockLength=n;return o}toBER(e,t){return this.isConstructed?nr.prototype.toBER.call(this,e,t):e?new ArrayBuffer(this.valueHexView.byteLength):this.valueHexView.slice().buffer}toJSON(){return{...super.toJSON(),isConstructed:this.isConstructed}}};_a.NAME="OctetStringValueBlock";var s0,Sr=class r extends Ve{constructor({idBlock:e={},lenBlock:t={},...n}={}){var o,i;(o=n.isConstructed)!==null&&o!==void 0||(n.isConstructed=!!(!((i=n.value)===null||i===void 0)&&i.length)),super({idBlock:{isConstructed:n.isConstructed,...e},lenBlock:{...t,isIndefiniteForm:!!n.isIndefiniteForm},...n},_a),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 i=(e instanceof ArrayBuffer?new Uint8Array(e):e).subarray(t,t+n);try{if(i.byteLength){let s=Ja(i,0,i.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?Jr.prototype.onAsciiEncoding.call(this):`${this.constructor.NAME} : ${te.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 te.BufferSourceConverter.concat(e)}};s0=Sr;M.OctetString=s0;Sr.NAME=Jp;var Aa=class extends kr(nr){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 o=-1;if(this.isConstructed){if(o=nr.prototype.fromBER.call(this,e,t,n),o===-1)return o;for(let a of this.value){let c=a.constructor.NAME;if(c===Si){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, BIT STRING may consists of BIT STRINGs only",-1}if(c!==Qp)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 o}let i=te.BufferSourceConverter.toUint8Array(e);if(!Ar(this,i,t,n))return-1;let s=i.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=Ja(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 nr.prototype.toBER.call(this,e,t);if(e)return new ArrayBuffer(this.valueHexView.byteLength+1);if(!this.valueHexView.byteLength)return zt;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}}};Aa.NAME="BitStringValueBlock";var a0,To=class extends Ve{constructor({idBlock:e={},lenBlock:t={},...n}={}){var o,i;(o=n.isConstructed)!==null&&o!==void 0||(n.isConstructed=!!(!((i=n.value)===null||i===void 0)&&i.length)),super({idBlock:{isConstructed:n.isConstructed,...e},lenBlock:{...t,isIndefiniteForm:!!n.isIndefiniteForm},...n},Aa),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 Jr.prototype.onAsciiEncoding.call(this);{let e=[],t=this.valueBlock.valueHexView;for(let o of t)e.push(o.toString(2).padStart(8,"0"));let n=e.join("");return`${this.constructor.NAME} : ${n.substring(0,n.length-this.valueBlock.unusedBits)}`}}};a0=To;M.BitString=a0;To.NAME=Qp;var c0;function YE(r,e){let t=new Uint8Array([0]),n=new Uint8Array(r),o=new Uint8Array(e),i=n.slice(0),s=i.length-1,a=o.slice(0),c=a.length-1,u=0,l=c<s?s:c,f=0;for(let m=l;m>=0;m--,f++){switch(!0){case f<a.length:u=i[s-f]+a[c-f]+t[0];break;default:u=i[s-f]+t[0]}switch(t[0]=u/10,!0){case f>=i.length:i=ha(new Uint8Array([u%10]),i);break;default:i[s-f]=u%10}}return t[0]>0&&(i=ha(t,i)),i}function Zp(r){if(r>=Ei.length)for(let e=Ei.length;e<=r;e++){let t=new Uint8Array([0]),n=Ei[e-1].slice(0);for(let o=n.length-1;o>=0;o--){let i=new Uint8Array([(n[o]<<1)+t[0]]);t[0]=i[0]/10,n[o]=i[0]%10}t[0]>0&&(n=ha(t,n)),Ei.push(n)}return Ei[r]}function XE(r,e){let t=0,n=new Uint8Array(r),o=new Uint8Array(e),i=n.slice(0),s=i.length-1,a=o.slice(0),c=a.length-1,u,l=0;for(let f=c;f>=0;f--,l++)switch(u=i[s-l]-a[c-l]-t,!0){case u<0:t=1,i[s-l]=u+10;break;default:t=0,i[s-l]=u}if(t>0)for(let f=s-c+1;f>=0;f--,l++)if(u=i[s-l]-t,u<0)t=1,i[s-l]=u+10;else{t=0,i[s-l]=u;break}return i.slice()}var _i=class extends kr(je){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=Zu.call(this)))}set valueDec(e){this._valueDec=e,this.isHexOnly=!1,this.valueHexView=new Uint8Array(jp(e))}get valueDec(){return this._valueDec}fromDER(e,t,n,o=0){let i=this.fromBER(e,t,n);if(i===-1)return i;let s=this.valueHexView;return s[0]===0&&s[1]&128?this.valueHexView=s.subarray(1):o!==0&&s.length<o&&(o-s.length>1&&(o=s.length+1),this.valueHexView=s.subarray(o-s.length)),i}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 o=super.fromBER(e,t,n);return o===-1||this.setValueHex(),o}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,o,i=this.valueHexView,s="",a=!1;for(let c=i.byteLength-1;c>=0;c--){o=i[c];for(let u=0;u<8;u++){if((o&1)===1)switch(n){case e:t=XE(Zp(n),t),s="-";break;default:t=YE(t,Zp(n))}n++,o>>=1}}for(let c=0;c<t.length;c++)t[c]&&(a=!0),a&&(s+=Xp.charAt(t[c]));return a===!1&&(s+=Xp.charAt(0)),s}};c0=_i;_i.NAME="IntegerValueBlock";Object.defineProperty(c0.prototype,"valueHex",{set:function(r){this.valueHexView=new Uint8Array(r),this.setValueHex()},get:function(){return this.valueHexView.slice().buffer}});var l0,Te=class r extends Ve{constructor(e={}){super(e,_i),this.idBlock.tagClass=1,this.idBlock.tagNumber=2}toBigInt(){return pa(),BigInt(this.valueBlock.toString())}static fromBigInt(e){pa();let t=BigInt(e),n=new vi,o=t.toString(16).replace(/^-/,""),i=new Uint8Array(te.Convert.FromHex(o));if(t<0){let a=new Uint8Array(i.length+(i[0]&128?1:0));a[0]|=128;let u=BigInt(`0x${te.Convert.ToHex(a)}`)+t,l=te.BufferSourceConverter.toUint8Array(te.Convert.FromHex(u.toString(16)));l[0]|=128,n.write(l)}else i[0]&128&&n.write(new Uint8Array([0])),n.write(i);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()}`}};l0=Te;M.Integer=l0;Te.NAME="INTEGER";var u0,ka=class extends Te{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=10}};u0=ka;M.Enumerated=u0;ka.NAME="ENUMERATED";var Ai=class extends kr(je){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 o=te.BufferSourceConverter.toUint8Array(e);if(!Ar(this,o,t,n))return-1;let i=o.subarray(t,t+n);this.valueHexView=new Uint8Array(n);for(let a=0;a<n&&(this.valueHexView[a]=i[a]&127,this.blockLength++,!!(i[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,i[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=Pn(this.valueHexView,7):(this.isHexOnly=!0,this.warnings.push("Too big SID for decoding, hex only")),t+this.blockLength)}set valueBigInt(e){pa();let t=BigInt(e).toString(2);for(;t.length%7;)t="0"+t;let n=new Uint8Array(t.length/7);for(let o=0;o<n.length;o++)n[o]=parseInt(t.slice(o*7,o*7+7),2)+(o+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 o=this.valueHexView,i=new Uint8Array(this.blockLength);for(let s=0;s<this.blockLength-1;s++)i[s]=o[s]|128;return i[this.blockLength-1]=o[this.blockLength-1],i.buffer}let t=Zr(this.valueDec,7);if(t.byteLength===0)return this.error="Error during encoding SID value",zt;let n=new Uint8Array(t.byteLength);if(!e){let o=new Uint8Array(t),i=t.byteLength-1;for(let s=0;s<i;s++)n[s]=o[s]|128;n[i]=o[i]}return n}toString(){let e="";if(this.isHexOnly)e=te.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}}};Ai.NAME="sidBlock";var Ia=class extends je{constructor({value:e=No,...t}={}){super(t),this.value=[],e&&this.fromString(e)}fromBER(e,t,n){let o=t;for(;n>0;){let i=new Ai;if(o=i.fromBER(e,o,n),o===-1)return this.blockLength=0,this.error=i.error,o;this.value.length===0&&(i.isFirstSid=!0),this.blockLength+=i.blockLength,n-=i.blockLength,this.value.push(i)}return o}toBER(e){let t=[];for(let n=0;n<this.value.length;n++){let o=this.value[n].toBER(e);if(o.byteLength===0)return this.error=this.value[n].error,zt;t.push(o)}return Ju(t)}fromString(e){this.value=[];let t=0,n=0,o="",i=!1;do if(n=e.indexOf(".",t),n===-1?o=e.substring(t):o=e.substring(t,n),t=n+1,i){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(o,10);if(isNaN(c))return;s.valueDec=c+a,i=!1}else{let s=new Ai;if(o>Number.MAX_SAFE_INTEGER){pa();let a=BigInt(o);s.valueBigInt=a}else if(s.valueDec=parseInt(o,10),isNaN(s.valueDec))return;this.value.length||(s.isFirstSid=!0,i=!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 o=this.value[n].toString();n!==0&&(e=`${e}.`),t?(o=`{${o}}`,this.value[n].isFirstSid?e=`2.{${o} - 80}`:e+=o):e+=o}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}};Ia.NAME="ObjectIdentifierValueBlock";var f0,Mt=class extends Ve{constructor(e={}){super(e,Ia),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()}}};f0=Mt;M.ObjectIdentifier=f0;Mt.NAME="OBJECT IDENTIFIER";var ki=class extends kr(vr){constructor({valueDec:e=0,...t}={}){super(t),this.valueDec=e}fromBER(e,t,n){if(n===0)return t;let o=te.BufferSourceConverter.toUint8Array(e);if(!Ar(this,o,t,n))return-1;let i=o.subarray(t,t+n);this.valueHexView=new Uint8Array(n);for(let a=0;a<n&&(this.valueHexView[a]=i[a]&127,this.blockLength++,!!(i[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,i[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=Pn(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 o=this.valueHexView,i=new Uint8Array(this.blockLength);for(let s=0;s<this.blockLength-1;s++)i[s]=o[s]|128;return i[this.blockLength-1]=o[this.blockLength-1],i.buffer}let t=Zr(this.valueDec,7);if(t.byteLength===0)return this.error="Error during encoding SID value",zt;let n=new Uint8Array(t.byteLength);if(!e){let o=new Uint8Array(t),i=t.byteLength-1;for(let s=0;s<i;s++)n[s]=o[s]|128;n[i]=o[i]}return n.buffer}toString(){let e="";return this.isHexOnly?e=te.Convert.ToHex(this.valueHexView):e=this.valueDec.toString(),e}toJSON(){return{...super.toJSON(),valueDec:this.valueDec}}};ki.NAME="relativeSidBlock";var Ba=class extends je{constructor({value:e=No,...t}={}){super(t),this.value=[],e&&this.fromString(e)}fromBER(e,t,n){let o=t;for(;n>0;){let i=new ki;if(o=i.fromBER(e,o,n),o===-1)return this.blockLength=0,this.error=i.error,o;this.blockLength+=i.blockLength,n-=i.blockLength,this.value.push(i)}return o}toBER(e,t){let n=[];for(let o=0;o<this.value.length;o++){let i=this.value[o].toBER(e);if(i.byteLength===0)return this.error=this.value[o].error,zt;n.push(i)}return Ju(n)}fromString(e){this.value=[];let t=0,n=0,o="";do{n=e.indexOf(".",t),n===-1?o=e.substring(t):o=e.substring(t,n),t=n+1;let i=new ki;if(i.valueDec=parseInt(o,10),isNaN(i.valueDec))return!0;this.value.push(i)}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 o=this.value[n].toString();n!==0&&(e=`${e}.`),t&&(o=`{${o}}`),e+=o}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}};Ba.NAME="RelativeObjectIdentifierValueBlock";var d0,Ra=class extends Ve{constructor(e={}){super(e,Ba),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()}}};d0=Ra;M.RelativeObjectIdentifier=d0;Ra.NAME="RelativeObjectIdentifier";var h0,De=class extends Jr{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=16}};h0=De;M.Sequence=h0;De.NAME="SEQUENCE";var p0,Ta=class extends Jr{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=17}};p0=Ta;M.Set=p0;Ta.NAME="SET";var Na=class extends kr(je){constructor({...e}={}){super(e),this.isHexOnly=!0,this.value=No}toJSON(){return{...super.toJSON(),value:this.value}}};Na.NAME="StringValueBlock";var Ca=class extends Na{};Ca.NAME="SimpleStringValueBlock";var et=class extends ga{constructor({...e}={}){super(e,Ca)}fromBuffer(e){this.valueBlock.value=String.fromCharCode.apply(null,te.BufferSourceConverter.toUint8Array(e))}fromString(e){let t=e.length,n=this.valueBlock.valueHexView=new Uint8Array(t);for(let o=0;o<t;o++)n[o]=e.charCodeAt(o);this.valueBlock.value=e}};et.NAME="SIMPLE STRING";var La=class extends et{fromBuffer(e){this.valueBlock.valueHexView=te.BufferSourceConverter.toUint8Array(e);try{this.valueBlock.value=te.Convert.ToUtf8String(e)}catch(t){this.warnings.push(`Error during "decodeURIComponent": ${t}, using raw string`),this.valueBlock.value=te.Convert.ToBinary(e)}}fromString(e){this.valueBlock.valueHexView=new Uint8Array(te.Convert.FromUtf8String(e)),this.valueBlock.value=e}};La.NAME="Utf8StringValueBlock";var m0,_r=class extends La{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=12}};m0=_r;M.Utf8String=m0;_r.NAME="UTF8String";var Da=class extends et{fromBuffer(e){this.valueBlock.value=te.Convert.ToUtf16String(e),this.valueBlock.valueHexView=te.BufferSourceConverter.toUint8Array(e)}fromString(e){this.valueBlock.value=e,this.valueBlock.valueHexView=new Uint8Array(te.Convert.FromUtf16String(e))}};Da.NAME="BmpStringValueBlock";var y0,Pa=class extends Da{constructor({...e}={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=30}};y0=Pa;M.BmpString=y0;Pa.NAME="BMPString";var Oa=class extends et{fromBuffer(e){let t=ArrayBuffer.isView(e)?e.slice().buffer:e.slice(0),n=new Uint8Array(t);for(let o=0;o<n.length;o+=4)n[o]=n[o+3],n[o+1]=n[o+2],n[o+2]=0,n[o+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 o=0;o<t;o++){let i=Zr(e.charCodeAt(o),8),s=new Uint8Array(i);if(s.length>4)continue;let a=4-s.length;for(let c=s.length-1;c>=0;c--)n[o*4+c+a]=s[c]}this.valueBlock.value=e}};Oa.NAME="UniversalStringValueBlock";var g0,Ua=class extends Oa{constructor({...e}={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=28}};g0=Ua;M.UniversalString=g0;Ua.NAME="UniversalString";var w0,Fa=class extends et{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=18}};w0=Fa;M.NumericString=w0;Fa.NAME="NumericString";var b0,Va=class extends et{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=19}};b0=Va;M.PrintableString=b0;Va.NAME="PrintableString";var x0,Ha=class extends et{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=20}};x0=Ha;M.TeletexString=x0;Ha.NAME="TeletexString";var E0,Ma=class extends et{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=21}};E0=Ma;M.VideotexString=E0;Ma.NAME="VideotexString";var v0,za=class extends et{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=22}};v0=za;M.IA5String=v0;za.NAME="IA5String";var S0,$a=class extends et{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=25}};S0=$a;M.GraphicString=S0;$a.NAME="GraphicString";var _0,Ii=class extends et{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=26}};_0=Ii;M.VisibleString=_0;Ii.NAME="VisibleString";var A0,Ka=class extends et{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=27}};A0=Ka;M.GeneralString=A0;Ka.NAME="GeneralString";var k0,qa=class extends et{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=29}};k0=qa;M.CharacterString=k0;qa.NAME="CharacterString";var I0,Bi=class extends Ii{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 o=0;o<e.length;o++)this.valueBlock.valueHexView[o]=e.charCodeAt(o)}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,te.BufferSourceConverter.toUint8Array(e)))}toBuffer(){let e=this.toString(),t=new ArrayBuffer(e.length),n=new Uint8Array(t);for(let o=0;o<e.length;o++)n[o]=e.charCodeAt(o);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 o=parseInt(n[1],10);o>=50?this.year=1900+o:this.year=2e3+o,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]=ct(this.year<2e3?this.year-1900:this.year-2e3,2),t[1]=ct(this.month,2),t[2]=ct(this.day,2),t[3]=ct(this.hour,2),t[4]=ct(this.minute,2),t[5]=ct(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}}};I0=Bi;M.UTCTime=I0;Bi.NAME="UTCTime";var B0,Ga=class extends Bi{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="",o="",i=0,s,a=0,c=0;if(e[e.length-1]==="Z")n=e.substring(0,e.length-1),t=!0;else{let f=new Number(e[e.length-1]);if(isNaN(f.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 f=1,m=n.indexOf("+"),d="";if(m===-1&&(m=n.indexOf("-"),f=-1),m!==-1){if(d=n.substring(m+1),n=n.substring(0,m),d.length!==2&&d.length!==4)throw new Error("Wrong input string for conversion");let p=parseInt(d.substring(0,2),10);if(isNaN(p.valueOf()))throw new Error("Wrong input string for conversion");if(a=f*p,d.length===4){if(p=parseInt(d.substring(2,4),10),isNaN(p.valueOf()))throw new Error("Wrong input string for conversion");c=f*p}}}let u=n.indexOf(".");if(u===-1&&(u=n.indexOf(",")),u!==-1){let f=new Number(`0${n.substring(u)}`);if(isNaN(f.valueOf()))throw new Error("Wrong input string for conversion");i=f.valueOf(),o=n.substring(0,u)}else o=n;switch(!0){case o.length===8:if(s=/(\d{4})(\d{2})(\d{2})/ig,u!==-1)throw new Error("Wrong input string for conversion");break;case o.length===10:if(s=/(\d{4})(\d{2})(\d{2})(\d{2})/ig,u!==-1){let f=60*i;this.minute=Math.floor(f),f=60*(f-this.minute),this.second=Math.floor(f),f=1e3*(f-this.second),this.millisecond=Math.floor(f)}break;case o.length===12:if(s=/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})/ig,u!==-1){let f=60*i;this.second=Math.floor(f),f=1e3*(f-this.second),this.millisecond=Math.floor(f)}break;case o.length===14:if(s=/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/ig,u!==-1){let f=1e3*i;this.millisecond=Math.floor(f)}break;default:throw new Error("Wrong input string for conversion")}let l=s.exec(o);if(l===null)throw new Error("Wrong input string for conversion");for(let f=1;f<l.length;f++)switch(f){case 1:this.year=parseInt(l[f],10);break;case 2:this.month=parseInt(l[f],10);break;case 3:this.day=parseInt(l[f],10);break;case 4:this.hour=parseInt(l[f],10)+a;break;case 5:this.minute=parseInt(l[f],10)+c;break;case 6:this.second=parseInt(l[f],10);break;default:throw new Error("Wrong input string for conversion")}if(t===!1){let f=new Date(this.year,this.month,this.day,this.hour,this.minute,this.second,this.millisecond);this.year=f.getUTCFullYear(),this.month=f.getUTCMonth(),this.day=f.getUTCDay(),this.hour=f.getUTCHours(),this.minute=f.getUTCMinutes(),this.second=f.getUTCSeconds(),this.millisecond=f.getUTCMilliseconds()}}toString(e="iso"){if(e==="iso"){let t=[];return t.push(ct(this.year,4)),t.push(ct(this.month,2)),t.push(ct(this.day,2)),t.push(ct(this.hour,2)),t.push(ct(this.minute,2)),t.push(ct(this.second,2)),this.millisecond!==0&&(t.push("."),t.push(ct(this.millisecond,3))),t.push("Z"),t.join("")}return super.toString(e)}toJSON(){return{...super.toJSON(),millisecond:this.millisecond}}};B0=Ga;M.GeneralizedTime=B0;Ga.NAME="GeneralizedTime";var R0,Wa=class extends _r{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=31}};R0=Wa;M.DATE=R0;Wa.NAME="DATE";var T0,ja=class extends _r{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=32}};T0=ja;M.TimeOfDay=T0;ja.NAME="TimeOfDay";var N0,Ya=class extends _r{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=33}};N0=Ya;M.DateTime=N0;Ya.NAME="DateTime";var C0,Xa=class extends _r{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=34}};C0=Xa;M.Duration=C0;Xa.NAME="Duration";var L0,Za=class extends _r{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=14}};L0=Za;M.TIME=L0;Za.NAME="TIME";function JE(r){let{result:e}=Co(r),t=e.valueBlock.value;return{n:W(or(t[1].toBigInt()),"base64url"),e:W(or(t[2].toBigInt()),"base64url"),d:W(or(t[3].toBigInt()),"base64url"),p:W(or(t[4].toBigInt()),"base64url"),q:W(or(t[5].toBigInt()),"base64url"),dp:W(or(t[6].toBigInt()),"base64url"),dq:W(or(t[7].toBigInt()),"base64url"),qi:W(or(t[8].toBigInt()),"base64url"),kty:"RSA",alg:"RS256"}}function QE(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 P("JWK was missing components","ERR_INVALID_PARAMETERS");let t=new De({value:[new Te({value:0}),Te.fromBigInt(ir(F(r.n,"base64url"))),Te.fromBigInt(ir(F(r.e,"base64url"))),Te.fromBigInt(ir(F(r.d,"base64url"))),Te.fromBigInt(ir(F(r.p,"base64url"))),Te.fromBigInt(ir(F(r.q,"base64url"))),Te.fromBigInt(ir(F(r.dp,"base64url"))),Te.fromBigInt(ir(F(r.dq,"base64url"))),Te.fromBigInt(ir(F(r.qi,"base64url")))]}).toBER();return new Uint8Array(t,0,t.byteLength)}function e3(r){let{result:e}=Co(r),t=e.valueBlock.value[1].valueBlock.value[0].valueBlock.value;return{kty:"RSA",n:W(or(t[0].toBigInt()),"base64url"),e:W(or(t[1].toBigInt()),"base64url")}}function t3(r){if(r.n==null||r.e==null)throw new P("JWK was missing components","ERR_INVALID_PARAMETERS");let t=new De({value:[new De({value:[new Mt({value:"1.2.840.113549.1.1.1"}),new Qr]}),new To({valueHex:new De({value:[Te.fromBigInt(ir(F(r.n,"base64url"))),Te.fromBigInt(ir(F(r.e,"base64url")))]}).toBER()})]}).toBER();return new Uint8Array(t,0,t.byteLength)}function or(r){let e=r.toString(16);e.length%2>0&&(e=`0${e}`);let t=e.length/2,n=new Uint8Array(t),o=0,i=0;for(;o<t;)n[o]=parseInt(e.slice(i,i+2),16),o+=1,i+=2;return n}function ir(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 r3=16,ef=32,tf=1e4;async function n3(r,e){let t=Qe.get(),o=new De({value:[new Te({value:0}),new De({value:[new Mt({value:"1.2.840.113549.1.1.1"}),new Qr]}),new Sr({valueHex:r.marshal()})]}).toBER(),i=new Uint8Array(o,0,o.byteLength),s=Dn(r3),a=await Yu(So,e,s,{c:tf,dkLen:ef}),c=Dn(16),u=await t.subtle.importKey("raw",a,"AES-CBC",!1,["encrypt"]),l=await t.subtle.encrypt({name:"AES-CBC",iv:c},u,i),f=new De({value:[new Sr({valueHex:s}),new Te({value:tf}),new Te({value:ef}),new De({value:[new Mt({value:"1.2.840.113549.2.11"}),new Qr]})]}),m=new De({value:[new Mt({value:"1.2.840.113549.1.5.13"}),new De({value:[new De({value:[new Mt({value:"1.2.840.113549.1.5.12"}),f]}),new De({value:[new Mt({value:"2.16.840.1.101.3.4.1.42"}),new Sr({valueHex:c})]})]})]}),p=new De({value:[m,new Sr({valueHex:l})]}).toBER(),h=new Uint8Array(p,0,p.byteLength);return["-----BEGIN ENCRYPTED PRIVATE KEY-----",...W(h,"base64pad").split(/(.{64})/).filter(Boolean),"-----END ENCRYPTED PRIVATE KEY-----"].join(`
8
+ `)}async function o3(r,e){let t=Qe.get(),n;if(r.includes("-----BEGIN ENCRYPTED PRIVATE KEY-----")){let o=F(r.replace("-----BEGIN ENCRYPTED PRIVATE KEY-----","").replace("-----END ENCRYPTED PRIVATE KEY-----","").replace(/\n/g,"").trim(),"base64pad"),{result:i}=Co(o),{iv:s,salt:a,iterations:c,keySize:u,cipherText:l}=i3(i),f=await Yu(So,e,a,{c,dkLen:u}),m=await t.subtle.importKey("raw",f,"AES-CBC",!1,["decrypt"]),d=Ri(await t.subtle.decrypt({name:"AES-CBC",iv:s},m,l)),{result:p}=Co(d);n=D0(p)}else if(r.includes("-----BEGIN PRIVATE KEY-----")){let o=F(r.replace("-----BEGIN PRIVATE KEY-----","").replace("-----END PRIVATE KEY-----","").replace(/\n/g,"").trim(),"base64pad"),{result:i}=Co(o);n=D0(i)}else throw new P("Could not parse private key from PEM data","ERR_INVALID_PARAMETERS");return rf(n)}function i3(r){let e=r.valueBlock.value[0];if(e.valueBlock.value[0].toString()!=="OBJECT IDENTIFIER : 1.2.840.113549.1.5.13")throw new P("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 P("Only pkcs5PBKDF2 key derivation functions are supported","ERR_INVALID_PARAMS");let i=n.valueBlock.value[1],s=Ri(i.valueBlock.value[0].getValue()),a=tf,c=ef;if(i.valueBlock.value.length===3)a=Number(i.valueBlock.value[1].toBigInt()),c=Number(i.valueBlock.value[2].toBigInt());else if(i.valueBlock.value.length===2)throw new P("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 P("Only AES-CBC encryption schemes are supported","ERR_INVALID_PARAMS")}}}}let f=Ri(u.valueBlock.value[1].getValue());return{cipherText:Ri(r.valueBlock.value[1].getValue()),salt:s,iterations:a,keySize:c,iv:f}}function D0(r){return Ri(r.valueBlock.value[2].getValue())}function Ri(r){return new Uint8Array(r,0,r.byteLength)}async function P0(r){let e=await Qe.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 F0(e);return{privateKey:t[0],publicKey:t[1]}}async function nf(r){let t=[await Qe.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!0,["sign"]),await s3(r)],n=await F0({privateKey:t[0],publicKey:t[1]});return{privateKey:n[0],publicKey:n[1]}}async function O0(r,e){let t=await Qe.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]),n=await Qe.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},t,e instanceof Uint8Array?e:e.subarray());return new Uint8Array(n,0,n.byteLength)}async function U0(r,e,t){let n=await Qe.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);return Qe.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},n,e,t instanceof Uint8Array?t:t.subarray())}async function F0(r){if(r.privateKey==null||r.publicKey==null)throw new P("Private and public key are required","ERR_INVALID_PARAMETERS");return Promise.all([Qe.get().subtle.exportKey("jwk",r.privateKey),Qe.get().subtle.exportKey("jwk",r.publicKey)])}async function s3(r){return Qe.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 Qa(r){if(r.kty!=="RSA")throw new P("invalid key type","ERR_INVALID_KEY_TYPE");if(r.n==null)throw new P("invalid key modulus","ERR_INVALID_KEY_MODULUS");return F(r.n,"base64url").length*8}var Ni=8192,Ti=class{_key;constructor(e){this._key=e}verify(e,t){return U0(this._key,t,e)}marshal(){return en.jwkToPkix(this._key)}get bytes(){return tr.encode({Type:me.RSA,Data:this.marshal()}).subarray()}equals(e){return ce(this.bytes,e.bytes)}hash(){let e=ae.digest(this.bytes);return Nt(e)?e.then(({bytes:t})=>t):e.bytes}},Lo=class{_key;_publicKey;constructor(e,t){this._key=e,this._publicKey=t}genSecret(){return Dn(16)}sign(e){return O0(this._key,e)}get public(){if(this._publicKey==null)throw new P("public key not provided","ERR_PUBKEY_NOT_PROVIDED");return new Ti(this._publicKey)}marshal(){return en.jwkToPkcs1(this._key)}get bytes(){return rr.encode({Type:me.RSA,Data:this.marshal()}).subarray()}equals(e){return ce(this.bytes,e.bytes)}hash(){let e=ae.digest(this.bytes);return Nt(e)?e.then(({bytes:t})=>t):e.bytes}async id(){let e=await this.public.hash();return W(e,"base58btc")}async export(e,t="pkcs-8"){if(t==="pkcs-8")return en.exportToPem(this,e);if(t==="libp2p-key")return Io(this.bytes,e);throw new P(`export format '${t}' is not supported`,"ERR_INVALID_EXPORT_FORMAT")}};async function rf(r){let e=en.pkcs1ToJwk(r);if(Qa(e)>Ni)throw new P("key size is too large","ERR_KEY_SIZE_TOO_LARGE");let t=await nf(e);return new Lo(t.privateKey,t.publicKey)}function c3(r){let e=en.pkixToJwk(r);if(Qa(e)>Ni)throw new P("key size is too large","ERR_KEY_SIZE_TOO_LARGE");return new Ti(e)}async function l3(r){if(Qa(r)>Ni)throw new P("key size is too large","ERR_KEY_SIZE_TOO_LARGE");let e=await nf(r);return new Lo(e.privateKey,e.publicKey)}async function u3(r){if(r>Ni)throw new P("key size is too large","ERR_KEY_SIZE_TOO_LARGE");let e=await P0(r);return new Lo(e.privateKey,e.publicKey)}var uf={};ve(uf,{Secp256k1PrivateKey:()=>Li,Secp256k1PublicKey:()=>Ci,generateKeyPair:()=>S3,unmarshalSecp256k1PrivateKey:()=>E3,unmarshalSecp256k1PublicKey:()=>v3});var f3=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]),tn=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),rn=new Uint32Array(64),sf=class extends vo{constructor(){super(64,32,8,!1),this.A=tn[0]|0,this.B=tn[1]|0,this.C=tn[2]|0,this.D=tn[3]|0,this.E=tn[4]|0,this.F=tn[5]|0,this.G=tn[6]|0,this.H=tn[7]|0}get(){let{A:e,B:t,C:n,D:o,E:i,F:s,G:a,H:c}=this;return[e,t,n,o,i,s,a,c]}set(e,t,n,o,i,s,a,c){this.A=e|0,this.B=t|0,this.C=n|0,this.D=o|0,this.E=i|0,this.F=s|0,this.G=a|0,this.H=c|0}process(e,t){for(let f=0;f<16;f++,t+=4)rn[f]=e.getUint32(t,!1);for(let f=16;f<64;f++){let m=rn[f-15],d=rn[f-2],p=Vt(m,7)^Vt(m,18)^m>>>3,h=Vt(d,17)^Vt(d,19)^d>>>10;rn[f]=h+rn[f-7]+p+rn[f-16]|0}let{A:n,B:o,C:i,D:s,E:a,F:c,G:u,H:l}=this;for(let f=0;f<64;f++){let m=Vt(a,6)^Vt(a,11)^Vt(a,25),d=l+m+Sp(a,c,u)+f3[f]+rn[f]|0,h=(Vt(n,2)^Vt(n,13)^Vt(n,22))+_p(n,o,i)|0;l=u,u=c,c=a,a=s+d|0,s=i,i=o,o=n,n=d+h|0}n=n+this.A|0,o=o+this.B|0,i=i+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,o,i,s,a,c,u,l)}roundClean(){rn.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};var V0=Qs(()=>new sf);function d3(r){let e=wi(r);er(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:o}=e;if(t){if(!n.eql(o,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:h3,hexToBytes:p3}=ra,On={Err:class extends Error{constructor(e=""){super(e)}},_parseInt(r){let{Err:e}=On;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:h3(n),l:r.subarray(t+2)}},toSig(r){let{Err:e}=On,t=typeof r=="string"?p3(r):r;_o(t);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:o,l:i}=On._parseInt(t.subarray(2)),{d:s,l:a}=On._parseInt(i);if(a.length)throw new e("Invalid signature: left bytes after parsing");return{r:o,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)),o=e(t(r.r)),i=n.length/2,s=o.length/2,a=t(i),c=t(s);return`30${t(s+i+4)}02${c}${o}02${a}${n}`}},Ir=BigInt(0),Lt=BigInt(1),tB=BigInt(2),H0=BigInt(3),rB=BigInt(4);function m3(r){let e=d3(r),{Fp:t}=e,n=e.toBytes||((p,h,y)=>{let g=h.toAffine();return wr(Uint8Array.from([4]),t.toBytes(g.x),t.toBytes(g.y))}),o=e.fromBytes||(p=>{let h=p.subarray(1),y=t.fromBytes(h.subarray(0,t.BYTES)),g=t.fromBytes(h.subarray(t.BYTES,2*t.BYTES));return{x:y,y:g}});function i(p){let{a:h,b:y}=e,g=t.sqr(p),x=t.mul(g,p);return t.add(t.add(x,t.mul(p,h)),y)}if(!t.eql(t.sqr(e.Gy),i(e.Gx)))throw new Error("bad generator point: equation left != right");function s(p){return typeof p=="bigint"&&Ir<p&&p<e.n}function a(p){if(!s(p))throw new Error("Expected valid bigint: 0 < bigint < curve.n")}function c(p){let{allowedPrivateKeyLengths:h,nByteLength:y,wrapPrivateKey:g,n:x}=e;if(h&&typeof p!="bigint"){if(jr(p)&&(p=yr(p)),typeof p!="string"||!h.includes(p.length))throw new Error("Invalid key");p=p.padStart(y*2,"0")}let b;try{b=typeof p=="bigint"?p:gr(_e("private key",p,y))}catch{throw new Error(`private key must be ${y} bytes, hex or bigint, not ${typeof p}`)}return g&&(b=fe(b,x)),a(b),b}let u=new Map;function l(p){if(!(p instanceof f))throw new Error("ProjectivePoint expected")}class f{constructor(h,y,g){if(this.px=h,this.py=y,this.pz=g,h==null||!t.isValid(h))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(h){let{x:y,y:g}=h||{};if(!h||!t.isValid(y)||!t.isValid(g))throw new Error("invalid affine point");if(h instanceof f)throw new Error("projective point not allowed");let x=b=>t.eql(b,t.ZERO);return x(y)&&x(g)?f.ZERO:new f(y,g,t.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(h){let y=t.invertBatch(h.map(g=>g.pz));return h.map((g,x)=>g.toAffine(y[x])).map(f.fromAffine)}static fromHex(h){let y=f.fromAffine(o(_e("pointHex",h)));return y.assertValidity(),y}static fromPrivateKey(h){return f.BASE.multiply(c(h))}_setWindowSize(h){this._WINDOW_SIZE=h,u.delete(this)}assertValidity(){if(this.is0()){if(e.allowInfinityPoint&&!t.is0(this.py))return;throw new Error("bad point: ZERO")}let{x:h,y}=this.toAffine();if(!t.isValid(h)||!t.isValid(y))throw new Error("bad point: x or y not FE");let g=t.sqr(y),x=i(h);if(!t.eql(g,x))throw new Error("bad point: equation left != right");if(!this.isTorsionFree())throw new Error("bad point: not in prime-order subgroup")}hasEvenY(){let{y:h}=this.toAffine();if(t.isOdd)return!t.isOdd(h);throw new Error("Field doesn't support isOdd")}equals(h){l(h);let{px:y,py:g,pz:x}=this,{px:b,py:_,pz:A}=h,S=t.eql(t.mul(y,A),t.mul(b,x)),v=t.eql(t.mul(g,A),t.mul(_,x));return S&&v}negate(){return new f(this.px,t.neg(this.py),this.pz)}double(){let{a:h,b:y}=e,g=t.mul(y,H0),{px:x,py:b,pz:_}=this,A=t.ZERO,S=t.ZERO,v=t.ZERO,E=t.mul(x,x),R=t.mul(b,b),N=t.mul(_,_),T=t.mul(x,b);return T=t.add(T,T),v=t.mul(x,_),v=t.add(v,v),A=t.mul(h,v),S=t.mul(g,N),S=t.add(A,S),A=t.sub(R,S),S=t.add(R,S),S=t.mul(A,S),A=t.mul(T,A),v=t.mul(g,v),N=t.mul(h,N),T=t.sub(E,N),T=t.mul(h,T),T=t.add(T,v),v=t.add(E,E),E=t.add(v,E),E=t.add(E,N),E=t.mul(E,T),S=t.add(S,E),N=t.mul(b,_),N=t.add(N,N),E=t.mul(N,T),A=t.sub(A,E),v=t.mul(N,R),v=t.add(v,v),v=t.add(v,v),new f(A,S,v)}add(h){l(h);let{px:y,py:g,pz:x}=this,{px:b,py:_,pz:A}=h,S=t.ZERO,v=t.ZERO,E=t.ZERO,R=e.a,N=t.mul(e.b,H0),T=t.mul(y,b),H=t.mul(g,_),D=t.mul(x,A),Q=t.add(y,g),k=t.add(b,_);Q=t.mul(Q,k),k=t.add(T,H),Q=t.sub(Q,k),k=t.add(y,x);let L=t.add(b,A);return k=t.mul(k,L),L=t.add(T,D),k=t.sub(k,L),L=t.add(g,x),S=t.add(_,A),L=t.mul(L,S),S=t.add(H,D),L=t.sub(L,S),E=t.mul(R,k),S=t.mul(N,D),E=t.add(S,E),S=t.sub(H,E),E=t.add(H,E),v=t.mul(S,E),H=t.add(T,T),H=t.add(H,T),D=t.mul(R,D),k=t.mul(N,k),H=t.add(H,D),D=t.sub(T,D),D=t.mul(R,D),k=t.add(k,D),T=t.mul(H,k),v=t.add(v,T),T=t.mul(L,k),S=t.mul(Q,S),S=t.sub(S,T),T=t.mul(Q,H),E=t.mul(L,E),E=t.add(E,T),new f(S,v,E)}subtract(h){return this.add(h.negate())}is0(){return this.equals(f.ZERO)}wNAF(h){return d.wNAFCached(this,u,h,y=>{let g=t.invertBatch(y.map(x=>x.pz));return y.map((x,b)=>x.toAffine(g[b])).map(f.fromAffine)})}multiplyUnsafe(h){let y=f.ZERO;if(h===Ir)return y;if(a(h),h===Lt)return this;let{endo:g}=e;if(!g)return d.unsafeLadder(this,h);let{k1neg:x,k1:b,k2neg:_,k2:A}=g.splitScalar(h),S=y,v=y,E=this;for(;b>Ir||A>Ir;)b&Lt&&(S=S.add(E)),A&Lt&&(v=v.add(E)),E=E.double(),b>>=Lt,A>>=Lt;return x&&(S=S.negate()),_&&(v=v.negate()),v=new f(t.mul(v.px,g.beta),v.py,v.pz),S.add(v)}multiply(h){a(h);let y=h,g,x,{endo:b}=e;if(b){let{k1neg:_,k1:A,k2neg:S,k2:v}=b.splitScalar(y),{p:E,f:R}=this.wNAF(A),{p:N,f:T}=this.wNAF(v);E=d.constTimeNegate(_,E),N=d.constTimeNegate(S,N),N=new f(t.mul(N.px,b.beta),N.py,N.pz),g=E.add(N),x=R.add(T)}else{let{p:_,f:A}=this.wNAF(y);g=_,x=A}return f.normalizeZ([g,x])[0]}multiplyAndAddUnsafe(h,y,g){let x=f.BASE,b=(A,S)=>S===Ir||S===Lt||!A.equals(x)?A.multiplyUnsafe(S):A.multiply(S),_=b(this,y).add(b(h,g));return _.is0()?void 0:_}toAffine(h){let{px:y,py:g,pz:x}=this,b=this.is0();h==null&&(h=b?t.ONE:t.inv(x));let _=t.mul(y,h),A=t.mul(g,h),S=t.mul(x,h);if(b)return{x:t.ZERO,y:t.ZERO};if(!t.eql(S,t.ONE))throw new Error("invZ was invalid");return{x:_,y:A}}isTorsionFree(){let{h,isTorsionFree:y}=e;if(h===Lt)return!0;if(y)return y(f,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){let{h,clearCofactor:y}=e;return h===Lt?this:y?y(f,this):this.multiplyUnsafe(e.h)}toRawBytes(h=!0){return this.assertValidity(),n(f,this,h)}toHex(h=!0){return yr(this.toRawBytes(h))}}f.BASE=new f(e.Gx,e.Gy,t.ONE),f.ZERO=new f(t.ZERO,t.ONE,t.ZERO);let m=e.nBitLength,d=ia(f,e.endo?Math.ceil(m/2):m);return{CURVE:e,ProjectivePoint:f,normPrivateKeyToScalar:c,weierstrassEquation:i,isWithinCurveOrder:s}}function y3(r){let e=wi(r);return er(e,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...e})}function M0(r){let e=y3(r),{Fp:t,n}=e,o=t.BYTES+1,i=2*t.BYTES+1;function s(k){return Ir<k&&k<t.ORDER}function a(k){return fe(k,n)}function c(k){return na(k,n)}let{ProjectivePoint:u,normPrivateKeyToScalar:l,weierstrassEquation:f,isWithinCurveOrder:m}=m3({...e,toBytes(k,L,G){let C=L.toAffine(),I=t.toBytes(C.x),z=wr;return G?z(Uint8Array.from([L.hasEvenY()?2:3]),I):z(Uint8Array.from([4]),I,t.toBytes(C.y))},fromBytes(k){let L=k.length,G=k[0],C=k.subarray(1);if(L===o&&(G===2||G===3)){let I=gr(C);if(!s(I))throw new Error("Point is not on curve");let z=f(I),K;try{K=t.sqrt(z)}catch(Z){let se=Z instanceof Error?": "+Z.message:"";throw new Error("Point is not on curve"+se)}let j=(K&Lt)===Lt;return(G&1)===1!==j&&(K=t.neg(K)),{x:I,y:K}}else if(L===i&&G===4){let I=t.fromBytes(C.subarray(0,t.BYTES)),z=t.fromBytes(C.subarray(t.BYTES,2*t.BYTES));return{x:I,y:z}}else throw new Error(`Point of length ${L} was invalid. Expected ${o} compressed bytes or ${i} uncompressed bytes`)}}),d=k=>yr(Xr(k,e.nByteLength));function p(k){let L=n>>Lt;return k>L}function h(k){return p(k)?a(-k):k}let y=(k,L,G)=>gr(k.slice(L,G));class g{constructor(L,G,C){this.r=L,this.s=G,this.recovery=C,this.assertValidity()}static fromCompact(L){let G=e.nByteLength;return L=_e("compactSignature",L,G*2),new g(y(L,0,G),y(L,G,2*G))}static fromDER(L){let{r:G,s:C}=On.toSig(_e("DER",L));return new g(G,C)}assertValidity(){if(!m(this.r))throw new Error("r must be 0 < r < CURVE.n");if(!m(this.s))throw new Error("s must be 0 < s < CURVE.n")}addRecoveryBit(L){return new g(this.r,this.s,L)}recoverPublicKey(L){let{r:G,s:C,recovery:I}=this,z=v(_e("msgHash",L));if(I==null||![0,1,2,3].includes(I))throw new Error("recovery id invalid");let K=I===2||I===3?G+e.n:G;if(K>=t.ORDER)throw new Error("recovery id 2 or 3 invalid");let j=I&1?"03":"02",X=u.fromHex(j+d(K)),Z=c(K),se=a(-z*Z),re=a(C*Z),oe=u.BASE.multiplyAndAddUnsafe(X,se,re);if(!oe)throw new Error("point at infinify");return oe.assertValidity(),oe}hasHighS(){return p(this.s)}normalizeS(){return this.hasHighS()?new g(this.r,a(-this.s),this.recovery):this}toDERRawBytes(){return Tn(this.toDERHex())}toDERHex(){return On.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return Tn(this.toCompactHex())}toCompactHex(){return d(this.r)+d(this.s)}}let x={isValidPrivateKey(k){try{return l(k),!0}catch{return!1}},normPrivateKeyToScalar:l,randomPrivateKey:()=>{let k=Mu(e.n);return Pp(e.randomBytes(k),e.n)},precompute(k=8,L=u.BASE){return L._setWindowSize(k),L.multiply(BigInt(3)),L}};function b(k,L=!0){return u.fromPrivateKey(k).toRawBytes(L)}function _(k){let L=jr(k),G=typeof k=="string",C=(L||G)&&k.length;return L?C===o||C===i:G?C===2*o||C===2*i:k instanceof u}function A(k,L,G=!0){if(_(k))throw new Error("first arg must be private key");if(!_(L))throw new Error("second arg must be public key");return u.fromHex(L).multiply(l(k)).toRawBytes(G)}let S=e.bits2int||function(k){let L=gr(k),G=k.length*8-e.nBitLength;return G>0?L>>BigInt(G):L},v=e.bits2int_modN||function(k){return a(S(k))},E=gi(e.nBitLength);function R(k){if(typeof k!="bigint")throw new Error("bigint expected");if(!(Ir<=k&&k<E))throw new Error(`bigint expected < 2^${e.nBitLength}`);return Xr(k,e.nByteLength)}function N(k,L,G=T){if(["recovered","canonical"].some(xe=>xe in G))throw new Error("sign() legacy options not supported");let{hash:C,randomBytes:I}=e,{lowS:z,prehash:K,extraEntropy:j}=G;z==null&&(z=!0),k=_e("msgHash",k),K&&(k=_e("prehashed msgHash",C(k)));let X=v(k),Z=l(L),se=[R(Z),R(X)];if(j!=null&&j!==!1){let xe=j===!0?I(t.BYTES):j;se.push(_e("extraEntropy",xe))}let re=wr(...se),oe=X;function Re(xe){let Oe=S(xe);if(!m(Oe))return;let Ue=c(Oe),Ce=u.BASE.multiply(Oe).toAffine(),$e=a(Ce.x);if($e===Ir)return;let dr=a(Ue*a(oe+$e*Z));if(dr===Ir)return;let vn=(Ce.x===$e?0:2)|Number(Ce.y&Lt),ii=dr;return z&&p(dr)&&(ii=h(dr),vn^=1),new g($e,ii,vn)}return{seed:re,k2sig:Re}}let T={lowS:e.lowS,prehash:!1},H={lowS:e.lowS,prehash:!1};function D(k,L,G=T){let{seed:C,k2sig:I}=N(k,L,G),z=e;return Uu(z.hash.outputLen,z.nByteLength,z.hmac)(C,I)}u.BASE._setWindowSize(8);function Q(k,L,G,C=H){let I=k;if(L=_e("msgHash",L),G=_e("publicKey",G),"strict"in C)throw new Error("options.strict was renamed to lowS");let{lowS:z,prehash:K}=C,j,X;try{if(typeof I=="string"||jr(I))try{j=g.fromDER(I)}catch(Ce){if(!(Ce instanceof On.Err))throw Ce;j=g.fromCompact(I)}else if(typeof I=="object"&&typeof I.r=="bigint"&&typeof I.s=="bigint"){let{r:Ce,s:$e}=I;j=new g(Ce,$e)}else throw new Error("PARSE");X=u.fromHex(G)}catch(Ce){if(Ce.message==="PARSE")throw new Error("signature must be Signature instance, Uint8Array or hex string");return!1}if(z&&j.hasHighS())return!1;K&&(L=e.hash(L));let{r:Z,s:se}=j,re=v(L),oe=c(se),Re=a(re*oe),xe=a(Z*oe),Oe=u.BASE.multiplyAndAddUnsafe(X,Re,xe)?.toAffine();return Oe?a(Oe.x)===Z:!1}return{CURVE:e,getPublicKey:b,getSharedSecret:A,sign:D,verify:Q,ProjectivePoint:u,Signature:g,utils:x}}function g3(r){return{hash:r,hmac:(e,...t)=>xi(r,e,Js(...t)),randomBytes:Eo}}function z0(r,e){let t=n=>M0({...r,...g3(n)});return Object.freeze({...t(e),create:t})}var q0=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),$0=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),w3=BigInt(1),af=BigInt(2),K0=(r,e)=>(r+e/af)/e;function b3(r){let e=q0,t=BigInt(3),n=BigInt(6),o=BigInt(11),i=BigInt(22),s=BigInt(23),a=BigInt(44),c=BigInt(88),u=r*r*r%e,l=u*u*r%e,f=pe(l,t,e)*l%e,m=pe(f,t,e)*l%e,d=pe(m,af,e)*u%e,p=pe(d,o,e)*d%e,h=pe(p,i,e)*p%e,y=pe(h,a,e)*h%e,g=pe(y,c,e)*y%e,x=pe(g,a,e)*h%e,b=pe(x,t,e)*l%e,_=pe(b,s,e)*p%e,A=pe(_,n,e)*u%e,S=pe(A,af,e);if(!cf.eql(cf.sqr(S),r))throw new Error("Cannot find square root");return S}var cf=oa(q0,void 0,void 0,{sqrt:b3}),$t=z0({a:BigInt(0),b:BigInt(7),Fp:cf,n:$0,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:r=>{let e=$0,t=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-w3*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),o=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),i=t,s=BigInt("0x100000000000000000000000000000000"),a=K0(i*r,e),c=K0(-n*r,e),u=fe(r-a*t-c*o,e),l=fe(-a*n-c*i,e),f=u>s,m=l>s;if(f&&(u=e-u),m&&(l=e-l),u>s||l>s)throw new Error("splitScalar: Endomorphism failed, k="+r);return{k1neg:f,k1:u,k2neg:m,k2:l}}}},V0),fB=BigInt(0);var dB=$t.ProjectivePoint;function G0(){return $t.utils.randomPrivateKey()}function W0(r,e){let t=ae.digest(e instanceof Uint8Array?e:e.subarray());if(Nt(t))return t.then(({digest:n})=>$t.sign(n,r).toDERRawBytes()).catch(n=>{throw new P(String(n),"ERR_INVALID_INPUT")});try{return $t.sign(t.digest,r).toDERRawBytes()}catch(n){throw new P(String(n),"ERR_INVALID_INPUT")}}function j0(r,e,t){let n=ae.digest(t instanceof Uint8Array?t:t.subarray());if(Nt(n))return n.then(({digest:o})=>$t.verify(e,o,r)).catch(o=>{throw new P(String(o),"ERR_INVALID_INPUT")});try{return $t.verify(e,n.digest,r)}catch(o){throw new P(String(o),"ERR_INVALID_INPUT")}}function Y0(r){return $t.ProjectivePoint.fromHex(r).toRawBytes(!0)}function X0(r){try{$t.getPublicKey(r,!0)}catch(e){throw new P(String(e),"ERR_INVALID_PRIVATE_KEY")}}function lf(r){try{$t.ProjectivePoint.fromHex(r)}catch(e){throw new P(String(e),"ERR_INVALID_PUBLIC_KEY")}}function Z0(r){try{return $t.getPublicKey(r,!0)}catch(e){throw new P(String(e),"ERR_INVALID_PRIVATE_KEY")}}var Ci=class{_key;constructor(e){lf(e),this._key=e}verify(e,t){return j0(this._key,t,e)}marshal(){return Y0(this._key)}get bytes(){return tr.encode({Type:me.Secp256k1,Data:this.marshal()}).subarray()}equals(e){return ce(this.bytes,e.bytes)}async hash(){let e=ae.digest(this.bytes),t;return Nt(e)?{bytes:t}=await e:t=e.bytes,t}},Li=class{_key;_publicKey;constructor(e,t){this._key=e,this._publicKey=t??Z0(e),X0(this._key),lf(this._publicKey)}sign(e){return W0(this._key,e)}get public(){return new Ci(this._publicKey)}marshal(){return this._key}get bytes(){return rr.encode({Type:me.Secp256k1,Data:this.marshal()}).subarray()}equals(e){return ce(this.bytes,e.bytes)}hash(){let e=ae.digest(this.bytes);return Nt(e)?e.then(({bytes:t})=>t):e.bytes}async id(){let e=await this.public.hash();return W(e,"base58btc")}async export(e,t="libp2p-key"){if(t==="libp2p-key")return Io(this.bytes,e);throw new P(`export format '${t}' is not supported`,"ERR_INVALID_EXPORT_FORMAT")}};function E3(r){return new Li(r)}function v3(r){return new Ci(r)}async function S3(){let r=G0();return new Li(r)}var Un={rsa:of,ed25519:ju,secp256k1:uf};function J0(r){let e=Object.keys(Un).join(" / ");return new P(`invalid or unsupported key type ${r}. Must be ${e}`,"ERR_UNSUPPORTED_KEY_TYPE")}function ff(r){let e=tr.decode(r),t=e.Data??new Uint8Array;switch(e.Type){case me.RSA:return Un.rsa.unmarshalRsaPublicKey(t);case me.Ed25519:return Un.ed25519.unmarshalEd25519PublicKey(t);case me.Secp256k1:return Un.secp256k1.unmarshalSecp256k1PublicKey(t);default:throw J0(e.Type??"unknown")}}async function Q0(r){let e=rr.decode(r),t=e.Data??new Uint8Array;switch(e.Type){case me.RSA:return Un.rsa.unmarshalRsaPrivateKey(t);case me.Ed25519:return Un.ed25519.unmarshalEd25519PrivateKey(t);case me.Secp256k1:return Un.secp256k1.unmarshalSecp256k1PrivateKey(t);default:throw J0(e.Type??"RSA")}}var kf=J(Ie(),1);var Br="/",em=new TextEncoder().encode(Br),ec=em[0],Be=class r{_buf;constructor(e,t){if(typeof e=="string")this._buf=F(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]!==ec)throw new Error("Invalid key")}toString(e="utf8"){return W(this._buf,e)}uint8Array(){return this._buf}get[Symbol.toStringTag](){return`Key(${this.toString()})`}static withNamespaces(e){return new r(e.join(Br))}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]!==ec){let e=new Uint8Array(this._buf.byteLength+1);e.fill(ec,0,1),e.set(this._buf,1),this._buf=e}for(;this._buf.byteLength>1&&this._buf[this._buf.byteLength-1]===ec;)this._buf=this._buf.subarray(0,-1)}less(e){let t=this.list(),n=e.list();for(let o=0;o<t.length;o++){if(n.length<o+1)return!1;let i=t[o],s=n[o];if(i<s)return!0;if(i>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(Br).slice(1)}type(){return _3(this.baseNamespace())}name(){return A3(this.baseNamespace())}instance(e){return new r(this.toString()+":"+e)}path(){let e=this.parent().toString();return e.endsWith(Br)||(e+=Br),e+=this.type(),new r(e)}parent(){let e=this.list();return e.length===1?new r(Br):new r(e.slice(0,-1).join(Br))}child(e){return this.toString()===Br?e:e.toString()===Br?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(),...k3(e.map(t=>t.namespaces()))])}};function _3(r){let e=r.split(":");return e.length<2?"":e.slice(0,-1).join(":")}function A3(r){let e=r.split(":");return e[e.length-1]}function k3(r){return[].concat(...r)}var y1=J(tc(),1);var tm="ERR_IPNS_EXPIRED_RECORD",Di="ERR_UNRECOGNIZED_VALIDITY",rm="ERR_SIGNATURE_CREATION",Rr="ERR_SIGNATURE_VERIFICATION";var hf="ERR_UNDEFINED_PARAMETER",nm="ERR_INVALID_RECORD_DATA",om="ERR_INVALID_VALUE",im="ERR_INVALID_EMBEDDED_KEY",sm="ERR_MISSING_PRIVATE_KEY",am="ERR_RECORD_TOO_LARGE";var He;(function(r){let e;(function(o){o.EOL="EOL"})(e=r.ValidityType||(r.ValidityType={}));let t;(function(o){o[o.EOL=0]="EOL"})(t||(t={})),function(o){o.codec=()=>Rn(t)}(e=r.ValidityType||(r.ValidityType={}));let n;r.codec=()=>(n==null&&(n=Bt((o,i,s={})=>{s.lengthDelimited!==!1&&i.fork(),o.value!=null&&(i.uint32(10),i.bytes(o.value)),o.signatureV1!=null&&(i.uint32(18),i.bytes(o.signatureV1)),o.validityType!=null&&(i.uint32(24),r.ValidityType.codec().encode(o.validityType,i)),o.validity!=null&&(i.uint32(34),i.bytes(o.validity)),o.sequence!=null&&(i.uint32(40),i.uint64(o.sequence)),o.ttl!=null&&(i.uint32(48),i.uint64(o.ttl)),o.pubKey!=null&&(i.uint32(58),i.bytes(o.pubKey)),o.signatureV2!=null&&(i.uint32(66),i.bytes(o.signatureV2)),o.data!=null&&(i.uint32(74),i.bytes(o.data)),s.lengthDelimited!==!1&&i.ldelim()},(o,i)=>{let s={},a=i==null?o.len:o.pos+i;for(;o.pos<a;){let c=o.uint32();switch(c>>>3){case 1:s.value=o.bytes();break;case 2:s.signatureV1=o.bytes();break;case 3:s.validityType=r.ValidityType.codec().decode(o);break;case 4:s.validity=o.bytes();break;case 5:s.sequence=o.uint64();break;case 6:s.ttl=o.uint64();break;case 7:s.pubKey=o.bytes();break;case 8:s.signatureV2=o.bytes();break;case 9:s.data=o.bytes();break;default:o.skipType(c&7);break}}return s})),n),r.encode=o=>It(o,r.codec()),r.decode=o=>At(o,r.codec())})(He||(He={}));var I3=["string","number","bigint","symbol"],B3=["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 cm(r){if(r===null)return"null";if(r===void 0)return"undefined";if(r===!0||r===!1)return"boolean";let e=typeof r;if(I3.includes(e))return e;if(e==="function")return"Function";if(Array.isArray(r))return"Array";if(R3(r))return"Buffer";let t=T3(r);return t||"Object"}function R3(r){return r&&r.constructor&&r.constructor.isBuffer&&r.constructor.isBuffer.call(null,r)}function T3(r){let e=Object.prototype.toString.call(r).slice(8,-1);if(B3.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 B=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 Do=globalThis.process&&!globalThis.process.browser&&globalThis.Buffer&&typeof globalThis.Buffer.isBuffer=="function",N3=new TextDecoder,C3=new TextEncoder;function rc(r){return Do&&globalThis.Buffer.isBuffer(r)}function Pi(r){return r instanceof Uint8Array?rc(r)?new Uint8Array(r.buffer,r.byteOffset,r.byteLength):r:Uint8Array.from(r)}var dm=Do?(r,e,t)=>t-e>64?globalThis.Buffer.from(r.subarray(e,t)).toString("utf8"):um(r,e,t):(r,e,t)=>t-e>64?N3.decode(r.subarray(e,t)):um(r,e,t),nc=Do?r=>r.length>64?globalThis.Buffer.from(r):lm(r):r=>r.length>64?C3.encode(r):lm(r),sr=r=>Uint8Array.from(r),Po=Do?(r,e,t)=>rc(r)?new Uint8Array(r.subarray(e,t)):r.slice(e,t):(r,e,t)=>r.slice(e,t),hm=Do?(r,e)=>(r=r.map(t=>t instanceof Uint8Array?t:globalThis.Buffer.from(t)),Pi(globalThis.Buffer.concat(r,e))):(r,e)=>{let t=new Uint8Array(e),n=0;for(let o of r)n+o.length>t.length&&(o=o.subarray(0,t.length-n)),t.set(o,n),n+=o.length;return t},pm=Do?r=>globalThis.Buffer.allocUnsafe(r):r=>new Uint8Array(r);function mm(r,e){if(rc(r)&&rc(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 lm(r){let e=[],t=0;for(let n=0;n<r.length;n++){let o=r.charCodeAt(n);o<128?e[t++]=o:o<2048?(e[t++]=o>>6|192,e[t++]=o&63|128):(o&64512)===55296&&n+1<r.length&&(r.charCodeAt(n+1)&64512)===56320?(o=65536+((o&1023)<<10)+(r.charCodeAt(++n)&1023),e[t++]=o>>18|240,e[t++]=o>>12&63|128,e[t++]=o>>6&63|128,e[t++]=o&63|128):(e[t++]=o>>12|224,e[t++]=o>>6&63|128,e[t++]=o&63|128)}return e}function um(r,e,t){let n=[];for(;e<t;){let o=r[e],i=null,s=o>239?4:o>223?3:o>191?2:1;if(e+s<=t){let a,c,u,l;switch(s){case 1:o<128&&(i=o);break;case 2:a=r[e+1],(a&192)===128&&(l=(o&31)<<6|a&63,l>127&&(i=l));break;case 3:a=r[e+1],c=r[e+2],(a&192)===128&&(c&192)===128&&(l=(o&15)<<12|(a&63)<<6|c&63,l>2047&&(l<55296||l>57343)&&(i=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=(o&15)<<18|(a&63)<<12|(c&63)<<6|u&63,l>65535&&l<1114112&&(i=l))}}i===null?(i=65533,s=1):i>65535&&(i-=65536,n.push(i>>>10&1023|55296),i=56320|i&1023),n.push(i),e+=s}return mf(n)}var fm=4096;function mf(r){let e=r.length;if(e<=fm)return String.fromCharCode.apply(String,r);let t="",n=0;for(;n<e;)t+=String.fromCharCode.apply(String,r.slice(n,n+=fm));return t}var L3=256,Oi=class{constructor(e=L3){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 o=t.length-(this.maxCursor-this.cursor)-1;t.set(e,o)}else{if(t){let o=t.length-(this.maxCursor-this.cursor)-1;o<t.length&&(this.chunks[this.chunks.length-1]=t.subarray(0,o),this.maxCursor=this.cursor-1)}e.length<64&&e.length<this.chunkSize?(t=pm(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=Po(n,0,this.cursor)}else t=hm(this.chunks,this.cursor);return e&&this.reset(),t}};var $="CBOR decode error:",Tr="CBOR encode error:",Ui=[];Ui[23]=1;Ui[24]=2;Ui[25]=3;Ui[26]=5;Ui[27]=9;function Nr(r,e,t){if(r.length-e<t)throw new Error(`${$} not enough data for type`)}var Pe=[24,256,65536,4294967296,BigInt("18446744073709551616")];function gt(r,e,t){Nr(r,e,1);let n=r[e];if(t.strict===!0&&n<Pe[0])throw new Error(`${$} integer encoded in more bytes than necessary (strict decode)`);return n}function wt(r,e,t){Nr(r,e,2);let n=r[e]<<8|r[e+1];if(t.strict===!0&&n<Pe[1])throw new Error(`${$} integer encoded in more bytes than necessary (strict decode)`);return n}function bt(r,e,t){Nr(r,e,4);let n=r[e]*16777216+(r[e+1]<<16)+(r[e+2]<<8)+r[e+3];if(t.strict===!0&&n<Pe[2])throw new Error(`${$} integer encoded in more bytes than necessary (strict decode)`);return n}function xt(r,e,t){Nr(r,e,8);let n=r[e]*16777216+(r[e+1]<<16)+(r[e+2]<<8)+r[e+3],o=r[e+4]*16777216+(r[e+5]<<16)+(r[e+6]<<8)+r[e+7],i=(BigInt(n)<<BigInt(32))+BigInt(o);if(t.strict===!0&&i<Pe[3])throw new Error(`${$} integer encoded in more bytes than necessary (strict decode)`);if(i<=Number.MAX_SAFE_INTEGER)return Number(i);if(t.allowBigInt===!0)return i;throw new Error(`${$} integers outside of the safe integer range are not supported`)}function ym(r,e,t,n){return new B(w.uint,gt(r,e+1,n),2)}function gm(r,e,t,n){return new B(w.uint,wt(r,e+1,n),3)}function wm(r,e,t,n){return new B(w.uint,bt(r,e+1,n),5)}function bm(r,e,t,n){return new B(w.uint,xt(r,e+1,n),9)}function Dt(r,e){return Me(r,0,e.value)}function Me(r,e,t){if(t<Pe[0]){let n=Number(t);r.push([e|n])}else if(t<Pe[1]){let n=Number(t);r.push([e|24,n])}else if(t<Pe[2]){let n=Number(t);r.push([e|25,n>>>8,n&255])}else if(t<Pe[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<Pe[4]){let o=[e|27,0,0,0,0,0,0,0],i=Number(n&BigInt(4294967295)),s=Number(n>>BigInt(32)&BigInt(4294967295));o[8]=i&255,i=i>>8,o[7]=i&255,i=i>>8,o[6]=i&255,i=i>>8,o[5]=i&255,o[4]=s&255,s=s>>8,o[3]=s&255,s=s>>8,o[2]=s&255,s=s>>8,o[1]=s&255,r.push(o)}else throw new Error(`${$} encountered BigInt larger than allowable range`)}}Dt.encodedSize=function(e){return Me.encodedSize(e.value)};Me.encodedSize=function(e){return e<Pe[0]?1:e<Pe[1]?2:e<Pe[2]?3:e<Pe[3]?5:9};Dt.compareTokens=function(e,t){return e.value<t.value?-1:e.value>t.value?1:0};function xm(r,e,t,n){return new B(w.negint,-1-gt(r,e+1,n),2)}function Em(r,e,t,n){return new B(w.negint,-1-wt(r,e+1,n),3)}function vm(r,e,t,n){return new B(w.negint,-1-bt(r,e+1,n),5)}var yf=BigInt(-1),Sm=BigInt(1);function _m(r,e,t,n){let o=xt(r,e+1,n);if(typeof o!="bigint"){let i=-1-o;if(i>=Number.MIN_SAFE_INTEGER)return new B(w.negint,i,9)}if(n.allowBigInt!==!0)throw new Error(`${$} integers outside of the safe integer range are not supported`);return new B(w.negint,yf-BigInt(o),9)}function oc(r,e){let t=e.value,n=typeof t=="bigint"?t*yf-Sm:t*-1-1;Me(r,e.type.majorEncoded,n)}oc.encodedSize=function(e){let t=e.value,n=typeof t=="bigint"?t*yf-Sm:t*-1-1;return n<Pe[0]?1:n<Pe[1]?2:n<Pe[2]?3:n<Pe[3]?5:9};oc.compareTokens=function(e,t){return e.value<t.value?1:e.value>t.value?-1:0};function Fi(r,e,t,n){Nr(r,e,t+n);let o=Po(r,e+t,e+t+n);return new B(w.bytes,o,t+n)}function Am(r,e,t,n){return Fi(r,e,1,t)}function km(r,e,t,n){return Fi(r,e,2,gt(r,e+1,n))}function Im(r,e,t,n){return Fi(r,e,3,wt(r,e+1,n))}function Bm(r,e,t,n){return Fi(r,e,5,bt(r,e+1,n))}function Rm(r,e,t,n){let o=xt(r,e+1,n);if(typeof o=="bigint")throw new Error(`${$} 64-bit integer bytes lengths not supported`);return Fi(r,e,9,o)}function ic(r){return r.encodedBytes===void 0&&(r.encodedBytes=r.type===w.string?nc(r.value):r.value),r.encodedBytes}function Oo(r,e){let t=ic(e);Me(r,e.type.majorEncoded,t.length),r.push(t)}Oo.encodedSize=function(e){let t=ic(e);return Me.encodedSize(t.length)+t.length};Oo.compareTokens=function(e,t){return P3(ic(e),ic(t))};function P3(r,e){return r.length<e.length?-1:r.length>e.length?1:mm(r,e)}function Vi(r,e,t,n,o){let i=t+n;Nr(r,e,i);let s=new B(w.string,dm(r,e+t,e+i),i);return o.retainStringBytes===!0&&(s.byteValue=Po(r,e+t,e+i)),s}function Tm(r,e,t,n){return Vi(r,e,1,t,n)}function Nm(r,e,t,n){return Vi(r,e,2,gt(r,e+1,n),n)}function Cm(r,e,t,n){return Vi(r,e,3,wt(r,e+1,n),n)}function Lm(r,e,t,n){return Vi(r,e,5,bt(r,e+1,n),n)}function Dm(r,e,t,n){let o=xt(r,e+1,n);if(typeof o=="bigint")throw new Error(`${$} 64-bit integer string lengths not supported`);return Vi(r,e,9,o,n)}var Pm=Oo;function Uo(r,e,t,n){return new B(w.array,n,t)}function Om(r,e,t,n){return Uo(r,e,1,t)}function Um(r,e,t,n){return Uo(r,e,2,gt(r,e+1,n))}function Fm(r,e,t,n){return Uo(r,e,3,wt(r,e+1,n))}function Vm(r,e,t,n){return Uo(r,e,5,bt(r,e+1,n))}function Hm(r,e,t,n){let o=xt(r,e+1,n);if(typeof o=="bigint")throw new Error(`${$} 64-bit integer array lengths not supported`);return Uo(r,e,9,o)}function Mm(r,e,t,n){if(n.allowIndefinite===!1)throw new Error(`${$} indefinite length items not allowed`);return Uo(r,e,1,1/0)}function sc(r,e){Me(r,w.array.majorEncoded,e.value)}sc.compareTokens=Dt.compareTokens;sc.encodedSize=function(e){return Me.encodedSize(e.value)};function Fo(r,e,t,n){return new B(w.map,n,t)}function zm(r,e,t,n){return Fo(r,e,1,t)}function $m(r,e,t,n){return Fo(r,e,2,gt(r,e+1,n))}function Km(r,e,t,n){return Fo(r,e,3,wt(r,e+1,n))}function qm(r,e,t,n){return Fo(r,e,5,bt(r,e+1,n))}function Gm(r,e,t,n){let o=xt(r,e+1,n);if(typeof o=="bigint")throw new Error(`${$} 64-bit integer map lengths not supported`);return Fo(r,e,9,o)}function Wm(r,e,t,n){if(n.allowIndefinite===!1)throw new Error(`${$} indefinite length items not allowed`);return Fo(r,e,1,1/0)}function ac(r,e){Me(r,w.map.majorEncoded,e.value)}ac.compareTokens=Dt.compareTokens;ac.encodedSize=function(e){return Me.encodedSize(e.value)};function jm(r,e,t,n){return new B(w.tag,t,1)}function Ym(r,e,t,n){return new B(w.tag,gt(r,e+1,n),2)}function Xm(r,e,t,n){return new B(w.tag,wt(r,e+1,n),3)}function Zm(r,e,t,n){return new B(w.tag,bt(r,e+1,n),5)}function Jm(r,e,t,n){return new B(w.tag,xt(r,e+1,n),9)}function cc(r,e){Me(r,w.tag.majorEncoded,e.value)}cc.compareTokens=Dt.compareTokens;cc.encodedSize=function(e){return Me.encodedSize(e.value)};var M3=20,z3=21,$3=22,K3=23;function Qm(r,e,t,n){if(n.allowUndefined===!1)throw new Error(`${$} undefined values are not supported`);return n.coerceUndefinedToNull===!0?new B(w.null,null,1):new B(w.undefined,void 0,1)}function e1(r,e,t,n){if(n.allowIndefinite===!1)throw new Error(`${$} indefinite length items not allowed`);return new B(w.break,void 0,1)}function gf(r,e,t){if(t){if(t.allowNaN===!1&&Number.isNaN(r))throw new Error(`${$} NaN values are not supported`);if(t.allowInfinity===!1&&(r===1/0||r===-1/0))throw new Error(`${$} Infinity values are not supported`)}return new B(w.float,r,e)}function t1(r,e,t,n){return gf(wf(r,e+1),3,n)}function r1(r,e,t,n){return gf(bf(r,e+1),5,n)}function n1(r,e,t,n){return gf(a1(r,e+1),9,n)}function lc(r,e,t){let n=e.value;if(n===!1)r.push([w.float.majorEncoded|M3]);else if(n===!0)r.push([w.float.majorEncoded|z3]);else if(n===null)r.push([w.float.majorEncoded|$3]);else if(n===void 0)r.push([w.float.majorEncoded|K3]);else{let o,i=!1;(!t||t.float64!==!0)&&(i1(n),o=wf(Kt,1),n===o||Number.isNaN(n)?(Kt[0]=249,r.push(Kt.slice(0,3)),i=!0):(s1(n),o=bf(Kt,1),n===o&&(Kt[0]=250,r.push(Kt.slice(0,5)),i=!0))),i||(q3(n),o=a1(Kt,1),Kt[0]=251,r.push(Kt.slice(0,9)))}}lc.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){i1(n);let o=wf(Kt,1);if(n===o||Number.isNaN(n))return 3;if(s1(n),o=bf(Kt,1),n===o)return 5}return 9};var o1=new ArrayBuffer(9),Pt=new DataView(o1,1),Kt=new Uint8Array(o1,0);function i1(r){if(r===1/0)Pt.setUint16(0,31744,!1);else if(r===-1/0)Pt.setUint16(0,64512,!1);else if(Number.isNaN(r))Pt.setUint16(0,32256,!1);else{Pt.setFloat32(0,r);let e=Pt.getUint32(0),t=(e&2139095040)>>23,n=e&8388607;if(t===255)Pt.setUint16(0,31744,!1);else if(t===0)Pt.setUint16(0,(r&2147483648)>>16|n>>13,!1);else{let o=t-127;o<-24?Pt.setUint16(0,0):o<-14?Pt.setUint16(0,(e&2147483648)>>16|1<<24+o,!1):Pt.setUint16(0,(e&2147483648)>>16|o+15<<10|n>>13,!1)}}}function wf(r,e){if(r.length-e<2)throw new Error(`${$} 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,o=t&1023,i;return n===0?i=o*2**-24:n!==31?i=(o+1024)*2**(n-25):i=o===0?1/0:NaN,t&32768?-i:i}function s1(r){Pt.setFloat32(0,r,!1)}function bf(r,e){if(r.length-e<4)throw new Error(`${$} not enough data for float32`);let t=(r.byteOffset||0)+e;return new DataView(r.buffer,t,4).getFloat32(0,!1)}function q3(r){Pt.setFloat64(0,r,!1)}function a1(r,e){if(r.length-e<8)throw new Error(`${$} not enough data for float64`);let t=(r.byteOffset||0)+e;return new DataView(r.buffer,t,8).getFloat64(0,!1)}lc.compareTokens=Dt.compareTokens;function ie(r,e,t){throw new Error(`${$} encountered invalid minor (${t}) for major ${r[e]>>>5}`)}function uc(r){return()=>{throw new Error(`${$} ${r}`)}}var O=[];for(let r=0;r<=23;r++)O[r]=ie;O[24]=ym;O[25]=gm;O[26]=wm;O[27]=bm;O[28]=ie;O[29]=ie;O[30]=ie;O[31]=ie;for(let r=32;r<=55;r++)O[r]=ie;O[56]=xm;O[57]=Em;O[58]=vm;O[59]=_m;O[60]=ie;O[61]=ie;O[62]=ie;O[63]=ie;for(let r=64;r<=87;r++)O[r]=Am;O[88]=km;O[89]=Im;O[90]=Bm;O[91]=Rm;O[92]=ie;O[93]=ie;O[94]=ie;O[95]=uc("indefinite length bytes/strings are not supported");for(let r=96;r<=119;r++)O[r]=Tm;O[120]=Nm;O[121]=Cm;O[122]=Lm;O[123]=Dm;O[124]=ie;O[125]=ie;O[126]=ie;O[127]=uc("indefinite length bytes/strings are not supported");for(let r=128;r<=151;r++)O[r]=Om;O[152]=Um;O[153]=Fm;O[154]=Vm;O[155]=Hm;O[156]=ie;O[157]=ie;O[158]=ie;O[159]=Mm;for(let r=160;r<=183;r++)O[r]=zm;O[184]=$m;O[185]=Km;O[186]=qm;O[187]=Gm;O[188]=ie;O[189]=ie;O[190]=ie;O[191]=Wm;for(let r=192;r<=215;r++)O[r]=jm;O[216]=Ym;O[217]=Xm;O[218]=Zm;O[219]=Jm;O[220]=ie;O[221]=ie;O[222]=ie;O[223]=ie;for(let r=224;r<=243;r++)O[r]=uc("simple values are not supported");O[244]=ie;O[245]=ie;O[246]=ie;O[247]=Qm;O[248]=uc("simple values are not supported");O[249]=t1;O[250]=r1;O[251]=n1;O[252]=ie;O[253]=ie;O[254]=ie;O[255]=e1;var qt=[];for(let r=0;r<24;r++)qt[r]=new B(w.uint,r,1);for(let r=-1;r>=-24;r--)qt[31-r]=new B(w.negint,r,1);qt[64]=new B(w.bytes,new Uint8Array(0),1);qt[96]=new B(w.string,"",1);qt[128]=new B(w.array,0,1);qt[160]=new B(w.map,0,1);qt[244]=new B(w.false,!1,1);qt[245]=new B(w.true,!0,1);qt[246]=new B(w.null,null,1);function xf(r){switch(r.type){case w.false:return sr([244]);case w.true:return sr([245]);case w.null:return sr([246]);case w.bytes:return r.value.length?void 0:sr([64]);case w.string:return r.value===""?sr([96]):void 0;case w.array:return r.value===0?sr([128]):void 0;case w.map:return r.value===0?sr([160]):void 0;case w.uint:return r.value<24?sr([Number(r.value)]):void 0;case w.negint:if(r.value>=-24)return sr([31-Number(r.value)])}}var W3={float64:!1,mapSorter:Y3,quickEncodeToken:xf};function vf(){let r=[];return r[w.uint.major]=Dt,r[w.negint.major]=oc,r[w.bytes.major]=Oo,r[w.string.major]=Pm,r[w.array.major]=sc,r[w.map.major]=ac,r[w.tag.major]=cc,r[w.float.major]=lc,r}var c1=vf(),Ef=new Oi,fc=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(`${Tr} object contains circular references`);return new r(t,e)}},nn={null:new B(w.null,null),undefined:new B(w.undefined,void 0),true:new B(w.true,!0),false:new B(w.false,!1),emptyArray:new B(w.array,0),emptyMap:new B(w.map,0)},on={number(r,e,t,n){return!Number.isInteger(r)||!Number.isSafeInteger(r)?new B(w.float,r):r>=0?new B(w.uint,r):new B(w.negint,r)},bigint(r,e,t,n){return r>=BigInt(0)?new B(w.uint,r):new B(w.negint,r)},Uint8Array(r,e,t,n){return new B(w.bytes,r)},string(r,e,t,n){return new B(w.string,r)},boolean(r,e,t,n){return r?nn.true:nn.false},null(r,e,t,n){return nn.null},undefined(r,e,t,n){return nn.undefined},ArrayBuffer(r,e,t,n){return new B(w.bytes,new Uint8Array(r))},DataView(r,e,t,n){return new B(w.bytes,new Uint8Array(r.buffer,r.byteOffset,r.byteLength))},Array(r,e,t,n){if(!r.length)return t.addBreakTokens===!0?[nn.emptyArray,new B(w.break)]:nn.emptyArray;n=fc.createCheck(n,r);let o=[],i=0;for(let s of r)o[i++]=Hi(s,t,n);return t.addBreakTokens?[new B(w.array,r.length),o,new B(w.break)]:[new B(w.array,r.length),o]},Object(r,e,t,n){let o=e!=="Object",i=o?r.keys():Object.keys(r),s=o?r.size:i.length;if(!s)return t.addBreakTokens===!0?[nn.emptyMap,new B(w.break)]:nn.emptyMap;n=fc.createCheck(n,r);let a=[],c=0;for(let u of i)a[c++]=[Hi(u,t,n),Hi(o?r.get(u):r[u],t,n)];return j3(a,t),t.addBreakTokens?[new B(w.map,s),a,new B(w.break)]:[new B(w.map,s),a]}};on.Map=on.Object;on.Buffer=on.Uint8Array;for(let r of"Uint8Clamped Uint16 Uint32 Int8 Int16 Int32 BigUint64 BigInt64 Float32 Float64".split(" "))on[`${r}Array`]=on.DataView;function Hi(r,e={},t){let n=cm(r),o=e&&e.typeEncoders&&e.typeEncoders[n]||on[n];if(typeof o=="function"){let s=o(r,n,e,t);if(s!=null)return s}let i=on[n];if(!i)throw new Error(`${Tr} unsupported type: ${n}`);return i(r,n,e,t)}function j3(r,e){e.mapSorter&&r.sort(e.mapSorter)}function Y3(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 o=t.type.major,i=c1[o].compareTokens(t,n);return i===0&&console.warn("WARNING: complex key types used, CBOR key sorting guarantees are gone"),i}function l1(r,e,t,n){if(Array.isArray(e))for(let o of e)l1(r,o,t,n);else t[e.type.major](r,e,n)}function Sf(r,e,t){let n=Hi(r,t);if(!Array.isArray(n)&&t.quickEncodeToken){let o=t.quickEncodeToken(n);if(o)return o;let i=e[n.type.major];if(i.encodedSize){let s=i.encodedSize(n,t),a=new Oi(s);if(i(a,n,t),a.chunks.length!==1)throw new Error(`Unexpected error: pre-calculated length for ${n} was wrong`);return Pi(a.chunks[0])}}return Ef.reset(),l1(Ef,n,e,t),Ef.toBytes(!0)}function sn(r,e){return e=Object.assign({},W3,e),Sf(r,c1,e)}var X3={strict:!1,allowIndefinite:!0,allowUndefined:!0,allowBigInt:!0},dc=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=qt[e];if(t===void 0){let n=O[e];if(!n)throw new Error(`${$} no decoder for major type ${e>>>5} (byte 0x${e.toString(16).padStart(2,"0")})`);let o=e&31;t=n(this.data,this._pos,o,this.options)}return this._pos+=t.encodedLength,t}},Mi=Symbol.for("DONE"),hc=Symbol.for("BREAK");function Z3(r,e,t){let n=[];for(let o=0;o<r.value;o++){let i=Vo(e,t);if(i===hc){if(r.value===1/0)break;throw new Error(`${$} got unexpected break to lengthed array`)}if(i===Mi)throw new Error(`${$} found array but not enough entries (got ${o}, expected ${r.value})`);n[o]=i}return n}function J3(r,e,t){let n=t.useMaps===!0,o=n?void 0:{},i=n?new Map:void 0;for(let s=0;s<r.value;s++){let a=Vo(e,t);if(a===hc){if(r.value===1/0)break;throw new Error(`${$} got unexpected break to lengthed map`)}if(a===Mi)throw new Error(`${$} found map but not enough entries (got ${s} [no key], expected ${r.value})`);if(n!==!0&&typeof a!="string")throw new Error(`${$} non-string keys not supported (got ${typeof a})`);if(t.rejectDuplicateMapKeys===!0&&(n&&i.has(a)||!n&&a in o))throw new Error(`${$} found repeat map key "${a}"`);let c=Vo(e,t);if(c===Mi)throw new Error(`${$} found map but not enough entries (got ${s} [no value], expected ${r.value})`);n?i.set(a,c):o[a]=c}return n?i:o}function Vo(r,e){if(r.done())return Mi;let t=r.next();if(t.type===w.break)return hc;if(t.type.terminal)return t.value;if(t.type===w.array)return Z3(t,r,e);if(t.type===w.map)return J3(t,r,e);if(t.type===w.tag){if(e.tags&&typeof e.tags[t.value]=="function"){let n=Vo(r,e);return e.tags[t.value](n)}throw new Error(`${$} tag not supported (${t.value})`)}throw new Error("unsupported")}function _f(r,e){if(!(r instanceof Uint8Array))throw new Error(`${$} data to decode must be a Uint8Array`);e=Object.assign({},X3,e);let t=e.tokenizer||new dc(r,e),n=Vo(t,e);if(n===Mi)throw new Error(`${$} did not find any content to decode`);if(n===hc)throw new Error(`${$} got unexpected break`);return[n,r.subarray(t.pos())]}function tt(r,e){let[t,n]=_f(r,e);if(n.length>0)throw new Error(`${$} too many terminals, data makes no sense`);return t}var lt=J(Ie(),1);var u1=ee("ipns:utils"),f1=F("/ipns/"),Q3=114,d1=async(r,e)=>{if(e==null||r==null){let n=new Error("one or more of the provided parameters are not defined");throw u1.error(n),(0,lt.default)(n,hf)}let t;if(e.pubKey!=null){try{t=ff(e.pubKey)}catch(o){throw u1.error(o),o}if(!(await rp(e.pubKey)).equals(r))throw(0,lt.default)(new Error("Embedded public key did not match PeerID"),im)}else r.publicKey!=null&&(t=ff(r.publicKey));if(t!=null)return t;throw(0,lt.default)(new Error("no public key is available"),hf)},h1=(r,e,t)=>{let n=F(e);return ue([r,t,n])},mc=r=>{let e=F("ipns-signature:");return ue([e,r])},Cr=r=>"signatureV1"in r?He.encode({value:F(r.value),signatureV1:r.signatureV1,validityType:r.validityType,validity:F(r.validity),sequence:r.sequence,ttl:r.ttl,pubKey:r.pubKey,signatureV2:r.signatureV2,data:r.data}):He.encode({pubKey:r.pubKey,signatureV2:r.signatureV2,data:r.data});function rt(r){let e=He.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,lt.default)(new Error("missing data or signatureV2"),Rr);let t=m1(e.data),n=Af(t.Value),o=W(t.Validity);if(e.value!=null&&e.signatureV1!=null)return e6(e),{value:n,validityType:He.ValidityType.EOL,validity:o,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:He.ValidityType.EOL,validity:o,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 Ho=r=>ue([f1,r.toBytes()]),Mo=r=>mi(r.slice(f1.length)),p1=(r,e,t,n,o)=>{let i;if(e===He.ValidityType.EOL)i=0;else throw(0,lt.default)(new Error("Unknown validity type"),Di);return sn({Value:r,Validity:t,ValidityType:i,Sequence:n,TTL:o})},m1=r=>{let e=tt(r);if(e.ValidityType===0)e.ValidityType=He.ValidityType.EOL;else throw(0,lt.default)(new Error("Unknown validity type"),Di);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(hh(r))return`/ipns/${r.toCID().toString(zr)}`;if(r instanceof Uint8Array){let n=W(r);n.startsWith("/")&&(r=n)}let e=r.toString().trim();if(e.startsWith("/")&&e.length>1)return e;let t=U.asCID(r);if(t!=null)return t.code===Q3?`/ipns/${t.toString(zr)}`:`/ipfs/${t.toV1().toString()}`;try{return r instanceof Uint8Array?`/ipfs/${U.decode(r).toV1().toString()}`:`/ipfs/${U.parse(e).toV1().toString()}`}catch{}}throw(0,lt.default)(new Error("Value must be a valid content path starting with /"),om)},e6=r=>{if(r.data==null)throw(0,lt.default)(new Error("Record data is missing"),nm);let e=m1(r.data);if(!ce(e.Value,r.value??new Uint8Array(0)))throw(0,lt.default)(new Error('Field "value" did not match between protobuf and CBOR'),Rr);if(!ce(e.Validity,r.validity??new Uint8Array(0)))throw(0,lt.default)(new Error('Field "validity" did not match between protobuf and CBOR'),Rr);if(e.ValidityType!==r.validityType)throw(0,lt.default)(new Error('Field "validityType" did not match between protobuf and CBOR'),Rr);if(e.Sequence!==r.sequence)throw(0,lt.default)(new Error('Field "sequence" did not match between protobuf and CBOR'),Rr);if(e.TTL!==r.ttl)throw(0,lt.default)(new Error('Field "ttl" did not match between protobuf and CBOR'),Rr)};var t6=ee("ipns"),r6=Ge.code,n6="/ipns/",ZR=n6.length,g1={v1Compatible:!0};async function w1(r,e,t,n,o=g1){let i=new y1.default(Date.now()+Number(n)),s=He.ValidityType.EOL,[a,c]=n.toString().split("."),u=BigInt(a)*BigInt(1e5)+BigInt(c??"0");return o6(r,e,t,s,i.toString(),u,o)}var o6=async(r,e,t,n,o,i,s=g1)=>{t=BigInt(t);let a=F(o),c=Af(e),u=F(c);if(r.privateKey==null)throw(0,kf.default)(new Error("Missing private key"),sm);let l=await Q0(r.privateKey),f=p1(u,n,a,t,i),m=mc(f),d=await l.sign(m),p;if(r.publicKey!=null){let h=Ze(r.toBytes());(h.code!==r6||!ce(r.publicKey,h.digest))&&(p=r.publicKey)}if(s.v1Compatible===!0){let h=await i6(l,u,n,a),y={value:c,signatureV1:h,validity:o,validityType:n,sequence:t,ttl:i,signatureV2:d,data:f};return p!=null&&(y.pubKey=p),y}else{let h={value:c,validity:o,validityType:n,sequence:t,ttl:i,signatureV2:d,data:f};return p!=null&&(h.pubKey=p),h}};var i6=async(r,e,t,n)=>{try{let o=h1(e,t,n);return await r.sign(o)}catch(o){throw t6.error("record signature creation failed",o),(0,kf.default)(new Error("record signature creation failed"),rm)}};var zi=J(Ie(),1),b1=J(tc(),1);var yc=ee("ipns:validator"),s6=1024*10,a6=async(r,e)=>{let t=rt(e),n;try{let o=mc(t.data);n=await r.verify(o,t.signatureV2)}catch{n=!1}if(!n)throw yc.error("record signature verification failed"),(0,zi.default)(new Error("record signature verification failed"),Rr);if(t.validityType===He.ValidityType.EOL){if(b1.default.fromString(t.validity).toDate().getTime()<Date.now())throw yc.error("record has expired"),(0,zi.default)(new Error("record has expired"),tm)}else if(t.validityType!=null)throw yc.error("unrecognized validity type"),(0,zi.default)(new Error("unrecognized validity type"),Di);yc("ipns record for %s is valid",t.value)};async function gc(r,e){if(e.byteLength>s6)throw(0,zi.default)(new Error("record too large"),am);let t=Mo(r),n=rt(e),o=await d1(t,n);await a6(o,e)}async function*$i(r){let e=/\r?\n/,t=new TextDecoder("utf8"),n="";for await(let o of r){typeof o=="string"&&(o=new TextEncoder().encode(o)),n+=t.decode(o,{stream:!0});let i=n.split(e);n=i.pop()??"";for(let s=0;s<i.length;s++)yield JSON.parse(i[s])}n+=t.decode(),n!==""&&(yield JSON.parse(n))}var Bf=J(E1(),1);var qi=class extends Error{constructor(e){super(e),this.name="TimeoutError"}},Rf=class extends Error{constructor(e){super(),this.name="AbortError",this.message=e}},v1=r=>globalThis.DOMException===void 0?new Rf(r):new DOMException(r),S1=r=>{let e=r.reason===void 0?v1("This operation was aborted."):r.reason;return e instanceof Error?e:v1(e)};function Gi(r,e){let{milliseconds:t,fallback:n,message:o,customTimers:i={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:m}=e;m.aborted&&l(S1(m)),m.addEventListener("abort",()=>{l(S1(m))})}if(t===Number.POSITIVE_INFINITY){r.then(u,l);return}let f=new qi;s=i.setTimeout.call(void 0,()=>{if(n){try{u(n())}catch(m){l(m)}return}typeof r.cancel=="function"&&r.cancel(),o===!1?u():o instanceof Error?l(o):(f.message=o??`Promise timed out after ${t} milliseconds`,l(f))},t),(async()=>{try{u(await r)}catch(m){l(m)}})()}).finally(()=>{c.clear()});return c.clear=()=>{i.clearTimeout.call(void 0,s),s=void 0},c}function Tf(r,e,t){let n=0,o=r.length;for(;o>0;){let i=Math.trunc(o/2),s=n+i;t(r[s],e)<=0?(n=++s,o-=i+1):o=i}return n}var Wi=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 o=Tf(this.#e,n,(i,s)=>s.priority-i.priority);this.#e.splice(o,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 ut=class extends Bf.default{#e;#t;#r=0;#s;#c;#p=0;#o;#l;#n;#m;#i=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:Wi,...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#b(){return this.#t||this.#r<this.#s}get#x(){return this.#i<this.#u}#E(){this.#i--,this.#f(),this.emit("next")}#v(){this.#w(),this.#g(),this.#l=void 0}get#S(){let e=Date.now();if(this.#o===void 0){let t=this.#p-e;if(t<0)this.#r=this.#e?this.#i:0;else return this.#l===void 0&&(this.#l=setTimeout(()=>{this.#v()},t)),!0}return!1}#f(){if(this.#n.size===0)return this.#o&&clearInterval(this.#o),this.#o=void 0,this.emit("empty"),this.#i===0&&this.emit("idle"),!1;if(!this.#a){let e=!this.#S;if(this.#b&&this.#x){let t=this.#n.dequeue();return t?(this.emit("active"),t(),e&&this.#g(),!0):!1}}return!1}#g(){this.#t||this.#o!==void 0||(this.#o=setInterval(()=>{this.#w()},this.#c),this.#p=Date.now()+this.#c)}#w(){this.#r===0&&this.#i===0&&this.#o&&(clearInterval(this.#o),this.#o=void 0),this.#r=this.#e?this.#i:0,this.#d()}#d(){for(;this.#f(););}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.#d()}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,o)=>{this.#n.enqueue(async()=>{this.#i++,this.#r++;try{t.signal?.throwIfAborted();let i=e({signal:t.signal});t.timeout&&(i=Gi(Promise.resolve(i),{milliseconds:t.timeout})),t.signal&&(i=Promise.race([i,this.#_(t.signal)]));let s=await i;n(s),this.emit("completed",s)}catch(i){if(i instanceof qi&&!t.throwOnTimeout){n();return}o(i),this.emit("error",i)}finally{this.#E()}},t),this.emit("add"),this.#f()})}async addAll(e,t){return Promise.all(e.map(async n=>this.add(n,t)))}start(){return this.#a?(this.#a=!1,this.#d(),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.#i===0&&this.#n.size===0||await this.#h("idle")}async#h(e,t){return new Promise(n=>{let o=()=>{t&&!t()||(this.off(e,o),n())};this.on(e,o)})}get size(){return this.#n.size}sizeBy(e){return this.#n.filter(e).length}get pending(){return this.#i}get isPaused(){return this.#a}};function u6(r){return r[Symbol.asyncIterator]!=null}function f6(r){if(u6(r))return(async()=>{for await(let e of r)return e})();for(let e of r)return e}var Vn=f6;var Nf=F("/ipns/");function _1(r){return ce(r.subarray(0,Nf.byteLength),Nf)}var A1=r=>mi(r.slice(Nf.length)),bc=class{client;constructor(e){this.client=e}async*findProviders(e,t={}){yield*We(this.client.getProviders(e,t),n=>({id:n.ID,multiaddrs:n.Addrs??[]}))}async provide(){}async put(e,t,n){if(!_1(e))return;let o=A1(e),i=rt(t);await this.client.putIPNS(o,i,n)}async get(e,t){if(!_1(e))throw new P("Not found","ERR_NOT_FOUND");let n=A1(e);try{let o=await this.client.getIPNS(n,t);return Cr(o)}catch(o){throw o.code==="ERR_BAD_RESPONSE"?new P("Not found","ERR_NOT_FOUND"):o}}},xc=class{client;constructor(e){this.client=e}async findPeer(e,t={}){let n=await Vn(this.client.getPeers(e,t));if(n!=null)return{id:n.ID,multiaddrs:n.Addrs??[]};throw new P("Not found","ERR_NOT_FOUND")}async*getClosestPeers(e,t={}){}};var ft=ee("delegated-routing-v1-http-api-client"),k1={concurrentRequests:4,timeout:3e4},Ec=class{started;httpQueue;shutDownController;clientUrl;timeout;contentRouting;peerRouting;constructor(e,t={}){this.started=!1,this.shutDownController=new AbortController,no(1/0,this.shutDownController.signal),this.httpQueue=new ut({concurrency:t.concurrentRequests??k1.concurrentRequests}),this.clientUrl=e instanceof URL?e:new URL(e),this.timeout=t.timeout??k1.timeout,this.contentRouting=new bc(this),this.peerRouting=new xc(this)}get[li](){return this.contentRouting}get[ui](){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={}){ft("getProviders starts: %c",e);let n=Sn([this.shutDownController.signal,t.signal,AbortSignal.timeout(this.timeout)]),o=we(),i=we();this.httpQueue.add(async()=>(o.resolve(),i.promise));try{await o.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 P("No matching records found.","ERR_NOT_FOUND");if(c.status===422)throw new P("Request does not conform to schema or semantic constraints.","ERR_INVALID_REQUEST");if(c.body==null)throw new P("Routing response had no body","ERR_BAD_RESPONSE");if(c.headers.get("Content-Type")==="application/json"){let l=await c.json();for(let f of l.Providers){let m=this.#e(f);m!=null&&(yield m)}}else for await(let l of $i(Ys(c.body))){let f=this.#e(l);f!=null&&(yield f)}}catch(s){ft.error("getProviders errored:",s)}finally{n.clear(),i.resolve(),ft("getProviders finished: %c",e)}}async*getPeers(e,t={}){ft("getPeers starts: %c",e);let n=Sn([this.shutDownController.signal,t.signal,AbortSignal.timeout(this.timeout)]),o=we(),i=we();this.httpQueue.add(async()=>(o.resolve(),i.promise));try{await o.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 P("No matching records found.","ERR_NOT_FOUND");if(c.status===422)throw new P("Request does not conform to schema or semantic constraints.","ERR_INVALID_REQUEST");if(c.body==null)throw new P("Routing response had no body","ERR_BAD_RESPONSE");if(c.headers.get("Content-Type")==="application/json"){let l=await c.json();for(let f of l.Peers){let m=this.#e(f);m!=null&&(yield m)}}else for await(let l of $i(Ys(c.body))){let f=this.#e(l);f!=null&&(yield f)}}catch(s){ft.error("getPeers errored:",s)}finally{n.clear(),i.resolve(),ft("getPeers finished: %c",e)}}async getIPNS(e,t={}){ft("getIPNS starts: %c",e);let n=Sn([this.shutDownController.signal,t.signal,AbortSignal.timeout(this.timeout)]),o=we(),i=we();this.httpQueue.add(async()=>(o.resolve(),i.promise));let s=`${this.clientUrl}routing/v1/ipns/${e.toCID().toString()}`;try{await o.promise;let c=await fetch(s,{headers:{Accept:"application/vnd.ipfs.ipns-record"},signal:n});if(ft("getIPNS GET %s %d",s,c.status),c.status===404)throw new P("No matching records found.","ERR_NOT_FOUND");if(c.status===422)throw new P("Request does not conform to schema or semantic constraints.","ERR_INVALID_REQUEST");if(c.body==null)throw new P("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 gc(Ho(e),l),rt(l)}catch(a){throw ft.error("getIPNS GET %s error:",s,a),a}finally{n.clear(),i.resolve(),ft("getIPNS finished: %c",e)}}async putIPNS(e,t,n={}){ft("putIPNS starts: %c",e);let o=Sn([this.shutDownController.signal,n.signal,AbortSignal.timeout(this.timeout)]),i=we(),s=we();this.httpQueue.add(async()=>(i.resolve(),s.promise));let a=`${this.clientUrl}routing/v1/ipns/${e.toCID().toString()}`;try{await i.promise;let c=Cr(t),l=await fetch(a,{method:"PUT",headers:{"Content-Type":"application/vnd.ipfs.ipns-record"},body:c,signal:o});if(ft("putIPNS PUT %s %d",a,l.status),l.status!==200)throw new P("PUT ipns response had status other than 200","ERR_BAD_RESPONSE")}catch(c){throw ft.error("putIPNS PUT %s error:",a,c.stack),c}finally{o.clear(),s.resolve(),ft("putIPNS finished: %c",e)}}#e(e){let t=[],n=e.Addrs?.map(yi)??[];return e.Protocols!=null&&t.push(...e.Protocols),e.Protocol!=null&&(t.push(e.Protocol),delete e.Protocol),{...e,Schema:"peer",ID:Je(e.ID),Addrs:n,Protocols:t}}};function I1(r,e={}){return new Ec(new URL(r),e)}var B1=F("/ipns/");function R1(r){return ce(r.subarray(0,B1.byteLength),B1)}var Cf=class{client;constructor(e){this.client=I1(e)}async provide(e,t){}async*findProviders(e,t){yield*We(this.client.getProviders(e,t),n=>({id:n.ID,multiaddrs:n.Addrs,protocols:n.Protocols}))}async put(e,t,n){if(!R1(e))return;let o=Mo(e),i=rt(t);await this.client.putIPNS(o,i,n)}async get(e,t){if(!R1(e))throw new P("Not found","ERR_NOT_FOUND");let n=Mo(e);try{let o=await this.client.getIPNS(n,t);return Cr(o)}catch(o){throw o.code==="ERR_BAD_RESPONSE"?new P("Not found","ERR_NOT_FOUND"):o}}async findPeer(e,t){let n=await Vn(this.client.getPeers(e,t));if(n!=null)return{id:n.ID,multiaddrs:n.Addrs??[]};throw new P("Not found","ERR_NOT_FOUND")}async*getClosestPeers(e,t){}};function ji(r){return new Cf(new URL(r))}function vc(r){let e=[Ot.A];return r==null?e:Array.isArray(r)?r.length===0?e:r:[r]}var Lf=60;function Sc(r){return{Status:r.Status??0,TC:r.TC??r.flag_tc??!1,RD:r.RD??r.flag_rd??!1,RA:r.RA??r.flag_ra??!1,AD:r.AD??r.flag_ad??!1,CD:r.CD??r.flag_cd??!1,Question:(r.Question??r.questions??[]).map(e=>({name:e.name,type:Ot[e.type]})),Answer:(r.Answer??r.answers??[]).map(e=>({name:e.name,type:Ot[e.type],TTL:e.TTL??e.ttl??Lf,data:e.data instanceof Uint8Array?W(e.data):e.data}))}}var d6=4;function Df(r,e={}){let t=new ut({concurrency:e.queryConcurrency??d6});return async(n,o={})=>{let i=new URLSearchParams;i.set("name",n),vc(o.types).forEach(a=>{i.append("type",a.toString())}),o.onProgress?.(new V("dns:query",{detail:n}));let s=await t.add(async()=>{let a=await fetch(`${r}?${i}`,{headers:{accept:"application/dns-json"},signal:o?.signal});if(a.status!==200)throw new Error(`Unexpected HTTP status: ${a.status} - ${a.statusText}`);let c=Sc(await a.json());return o.onProgress?.(new V("dns:response",{detail:c})),c},{signal:o.signal});if(s==null)throw new Error("No DNS response received");return s}}function T1(){return[Df("https://cloudflare-dns.com/dns-query"),Df("https://dns.google/resolve")]}var C1=J(Pf(),1);var Of=class{lru;constructor(e){this.lru=(0,C1.default)(e)}get(e,t){let n=!0,o=[];for(let i of t){let s=this.getAnswers(e,i);if(s.length===0){n=!1;break}o.push(...s)}if(n)return Sc({answers:o})}getAnswers(e,t){let n=`${e.toLowerCase()}-${t}`,o=this.lru.get(n);if(o!=null){let i=o.filter(s=>s.expires>Date.now()).map(({expires:s,value:a})=>({...a,TTL:Math.round((s-Date.now())/1e3),type:Ot[a.type]}));return i.length===0&&this.lru.remove(n),i}return[]}add(e,t){let n=`${e.toLowerCase()}-${t.type}`,o=this.lru.get(n)??[];o.push({expires:Date.now()+(t.TTL??Lf)*1e3,value:t}),this.lru.set(n,o)}remove(e,t){let n=`${e.toLowerCase()}-${t}`;this.lru.remove(n)}clear(){this.lru.clear()}};function L1(r){return new Of(r)}var h6=1e3,_c=class{resolvers;cache;constructor(e){this.resolvers={},this.cache=L1(e.cacheSize??h6),Object.entries(e.resolvers??{}).forEach(([t,n])=>{Array.isArray(n)||(n=[n]),t.endsWith(".")||(t=`${t}.`),this.resolvers[t]=n}),this.resolvers["."]==null&&(this.resolvers["."]=T1())}async query(e,t={}){let n=vc(t.types),o=t.cached!==!1?this.cache.get(e,n):void 0;if(o!=null)return t.onProgress?.(new V("dns:cache",{detail:o})),o;let i=`${e.split(".").pop()}.`,s=(this.resolvers[i]??this.resolvers["."]).sort(()=>Math.random()>.5?-1:1),a=[];for(let c of s){if(t.signal?.aborted===!0)break;try{let u=await c(e,{...t,types:n});for(let l of u.Answer)this.cache.add(e,l);return u}catch(u){a.push(u),t.onProgress?.(new V("dns:error",{detail:u}))}}throw a.length===1?a[0]:new AggregateError(a,`DNS lookup of ${e} ${n} failed`)}};var Ot;(function(r){r[r.A=1]="A",r[r.CNAME=5]="CNAME",r[r.TXT=16]="TXT",r[r.AAAA=28]="AAAA"})(Ot||(Ot={}));function Yi(r={}){return new _c(r)}var Uf=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 Ac(r,e,t,n){let o=new Uf(n?.errorMessage,n?.errorCode);return t?.aborted===!0?Promise.reject(o):new Promise((i,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),i(u)},c=()=>{r.removeEventListener(e,a),t?.removeEventListener("abort",c),s(o)};r.addEventListener(e,a),t?.addEventListener("abort",c)})}var kc=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 D1(r,e,t){if(e==null)return r;if(e.aborted)return Promise.reject(new kc(t?.errorMessage,t?.errorCode));let n,o=new kc(t?.errorMessage,t?.errorCode);try{return await Promise.race([r,new Promise((i,s)=>{n=()=>{s(o)},e.addEventListener("abort",n)})])}finally{n!=null&&e.removeEventListener("abort",n)}}var Ic=class{deferred;signal;where;constructor(e,t){this.signal=t,this.deferred=we(),this.where=e,this.onAbort=this.onAbort.bind(this),this.signal?.addEventListener("abort",this.onAbort)}onAbort(){this.deferred.reject(new Fr)}cleanup(){this.signal?.removeEventListener("abort",this.onAbort)}};function p6(){return`${parseInt(String(Math.random()*1e9),10).toString()}${Date.now()}`}var Bc=class{id;fn;options;priority;recipients;status;timeline;controller;constructor(e,t,n=0){this.id=p6(),this.status="queued",this.fn=e,this.priority=n,this.options=t,this.recipients=[],this.timeline={created:Date.now()},this.controller=new AbortController,no(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 Fr)}async join(e={}){let t=new Ic(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 D1(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 m6(r,e,t){let n=0,o=r.length;for(;o>0;){let i=Math.trunc(o/2),s=n+i;t(r[s],e)<=0?(n=++s,o-=i+1):o=i}return n}var Xi=class extends Cs{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=m6(this.queue,e,(n,o)=>o.priority-n.priority);this.queue.splice(t,0,e)}async add(e,t){t?.signal?.throwIfAborted();let n=new Bc(e,t,t?.priority),o=n.join(t).then(i=>(this.safeDispatchEvent("completed",{detail:i}),i)).catch(i=>{throw this.safeDispatchEvent("error",{detail:i}),i});return this.enqueue(n),this.safeDispatchEvent("add"),this.tryToStartAnother(),o}clear(){this.queue.splice(0,this.queue.length)}abort(){this.queue.forEach(e=>{e.abort(new Fr)}),this.clear()}async onEmpty(e){this.size!==0&&await Ac(this,"empty",e?.signal)}async onSizeLessThan(e,t){this.size<e||await Ac(this,"next",t?.signal,{filter:()=>this.size<e})}async onIdle(e){this.pending===0&&this.size===0||await Ac(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=Tt({objectMode:!0}),n=c=>{c!=null?this.abort():this.clear(),t.end(c)},o=c=>{c.detail!=null&&t.push(c.detail)},i=c=>{n(c.detail)},s=()=>{n()},a=()=>{n(new P("Queue aborted","ERR_QUEUE_ABORTED"))};this.addEventListener("completed",o),this.addEventListener("error",i),this.addEventListener("idle",s),e?.signal?.addEventListener("abort",a);try{yield*t}finally{this.removeEventListener("completed",o),this.removeEventListener("error",i),this.removeEventListener("idle",s),e?.signal?.removeEventListener("abort",a),n()}}};var F1="/pin/",P1="/pinned-block/",Ff=zr,O1=1;function U1(r){return r.version===0&&(r=r.toV1()),new Be(`${F1}${r.toString(Ff)}`)}var Rc=class{datastore;blockstore;dagWalkers;constructor(e,t,n){this.datastore=e,this.blockstore=t,this.dagWalkers=n}async*add(e,t={}){let n=U1(e);if(await this.datastore.has(n))throw new Error("Already pinned");let o=Math.round(t.depth??1/0);if(o<0)throw new Error("Depth must be greater than or equal to 0");let i=new Xi({concurrency:O1});for await(let a of this.#e(e,i,{...t,depth:o}))await this.#t(a,c=>c.pinnedBy.find(u=>ce(u,e.bytes))!=null?!1:(c.pinCount++,c.pinnedBy.push(e.bytes),!0),t),yield a;let s={depth:o,metadata:t.metadata??{}};await this.datastore.put(n,sn(s),t)}async*#e(e,t,n){if(n.depth===-1)return;let o=this.dagWalkers[e.code];if(o==null)throw new Error(`No dag walker found for cid codec ${e.code}`);let i=await this.blockstore.get(e,n);yield e;for await(let s of o.walk(i))yield*await t.add(async()=>this.#e(s,t,{...n,depth:n.depth-1}))}async#t(e,t,n){let o=new Be(`${P1}${Ff.encode(e.multihash.bytes)}`),i={pinCount:0,pinnedBy:[]};try{i=tt(await this.datastore.get(o,n))}catch(a){if(a.code!=="ERR_NOT_FOUND")throw a}if(t(i)){if(i.pinCount===0&&await this.datastore.has(o)){await this.datastore.delete(o);return}await this.datastore.put(o,sn(i),n),n.onProgress?.(new V("helia:pin:add",e))}}async*rm(e,t={}){let n=U1(e),o=await this.datastore.get(n,t),i=tt(o);await this.datastore.delete(n,t);let s=new Xi({concurrency:O1});for await(let a of this.#e(e,s,{...t,depth:i.depth}))await this.#t(a,c=>(c.pinCount--,c.pinnedBy=c.pinnedBy.filter(u=>ce(u,e.bytes)),!0),{...t,depth:i.depth}),yield a}async*ls(e={}){for await(let{key:t,value:n}of this.datastore.query({prefix:F1+(e.cid!=null?`${e.cid.toString(zr)}`:"")},e)){let o=U.parse(t.toString().substring(5),zr),i=tt(n);yield{cid:o,...i}}}async isPinned(e,t={}){let n=new Be(`${P1}${Ff.encode(e.multihash.bytes)}`);return this.datastore.has(n,t)}};function Vf(r,e){let t={[Symbol.iterator]:()=>t,next:()=>{let n=r.next(),o=n.value;return n.done===!0||o==null?{done:!0,value:void 0}:{done:!1,value:e(o)}}};return t}var zo=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 Vf(this.set.entries(),e=>{let t=Je(e[0]);return[t,t]})}forEach(e){this.set.forEach(t=>{let n=Je(t);e(n,n,this)})}has(e){return this.set.has(e.toString())}values(){return Vf(this.set.values(),e=>Je(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 Tc=class{log;routers;constructor(e,t){this.log=e.logger.forComponent("helia:routing"),this.routers=t.routers??[]}async start(){await Vr(...this.routers)}async stop(){await Hr(...this.routers)}async*findProviders(e,t={}){if(this.routers.length===0)throw new P("No content routers available","ERR_NO_ROUTERS_AVAILABLE");let n=new zo;for await(let o of pr(...$o(this.routers,"findProviders").map(i=>i.findProviders(e,t))))o!=null&&(n.has(o.id)||(n.add(o.id),yield o))}async provide(e,t={}){if(this.routers.length===0)throw new P("No content routers available","ERR_NO_ROUTERS_AVAILABLE");await Promise.all($o(this.routers,"provide").map(async n=>{await n.provide(e,t)}))}async put(e,t,n){await Promise.all($o(this.routers,"put").map(async o=>{await o.put(e,t,n)}))}async get(e,t){return Promise.any($o(this.routers,"get").map(async n=>n.get(e,t)))}async findPeer(e,t){if(this.routers.length===0)throw new P("No peer routers available","ERR_NO_ROUTERS_AVAILABLE");let n=this,o=pr(...$o(this.routers,"findPeer").map(i=>async function*(){try{yield await i.findPeer(e,t)}catch(s){n.log.error(s)}}()));for await(let i of o)if(i!=null)return i;throw new P("Could not find peer in routing","ERR_NOT_FOUND")}async*getClosestPeers(e,t={}){if(this.routers.length===0)throw new P("No peer routers available","ERR_NO_ROUTERS_AVAILABLE");let n=new zo;for await(let o of pr(...$o(this.routers,"getClosestPeers").map(i=>i.getClosestPeers(e,t))))o!=null&&(n.has(o.id)||(n.add(o.id),yield o))}};function $o(r,e){return r.filter(t=>t[e]!=null)}var an={},Ko=r=>{r.addEventListener("message",e=>{Ko.dispatchEvent("message",r,e)}),r.port!=null&&r.port.addEventListener("message",e=>{Ko.dispatchEvent("message",r,e)})};Ko.addEventListener=(r,e)=>{an[r]==null&&(an[r]=[]),an[r].push(e)};Ko.removeEventListener=(r,e)=>{an[r]!=null&&(an[r]=an[r].filter(t=>t===e))};Ko.dispatchEvent=function(r,e,t){an[r]!=null&&an[r].forEach(n=>n(e,t))};var Hf=Ko;var Mf="lock:worker:request-read",zf="lock:worker:release-read",$f="lock:master:grant-read",Kf="lock:worker:request-write",qf="lock:worker:release-write",Gf="lock:master:grant-write";var V1=(r=21)=>Math.random().toString().substring(2);var H1=(r,e,t,n,o)=>(i,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()=>{i.postMessage({type:o,name:a.name,identifier:a.identifier}),await new Promise(c=>{let u=l=>{if(l==null||l.data==null)return;let f={type:l.data.type,name:l.data.name,identifier:l.data.identifier};f.type===n&&f.identifier===a.identifier&&(i.removeEventListener("message",u),c())};i.addEventListener("message",u)})}}}))},M1=(r,e,t,n)=>async()=>{let o=V1();return globalThis.postMessage({type:e,identifier:o,name:r}),new Promise(i=>{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===o&&(globalThis.removeEventListener("message",s),i(()=>{globalThis.postMessage({type:n,identifier:o,name:r})}))};globalThis.addEventListener("message",s)})},y6={singleProcess:!1},z1=r=>{if(r=Object.assign({},y6,r),!!globalThis.document||r.singleProcess){let t=new EventTarget;return Hf.addEventListener("message",H1(t,"requestReadLock",Mf,zf,$f)),Hf.addEventListener("message",H1(t,"requestWriteLock",Kf,qf,Gf)),t}return{isWorker:!0,readLock:t=>M1(t,Mf,$f,zf),writeLock:t=>M1(t,Kf,Gf,qf)}};var Hn={},cn;async function Wf(r,e){let t,n=new Promise(o=>{t=o});return r.add(async()=>Gi((async()=>{await new Promise(o=>{t(()=>{o()})})})(),{milliseconds:e.timeout})),n}var g6=(r,e)=>{if(cn.isWorker===!0)return{readLock:cn.readLock(r,e),writeLock:cn.writeLock(r,e)};let t=new ut({concurrency:1}),n;return{async readLock(){if(n!=null)return Wf(n,e);n=new ut({concurrency:e.concurrency,autoStart:!1});let o=n,i=Wf(n,e);return t.add(async()=>{o.start(),await o.onIdle().then(()=>{n===o&&(n=null)})}),i},async writeLock(){return n=null,Wf(t,e)}}},w6={name:"lock",concurrency:1/0,timeout:846e5,singleProcess:!1};function jf(r){let e=Object.assign({},w6,r);return cn==null&&(cn=z1(e),cn.isWorker!==!0&&(cn.addEventListener("requestReadLock",t=>{Hn[t.data.name]!=null&&Hn[t.data.name].readLock().then(async n=>t.data.handler().finally(()=>{n()}))}),cn.addEventListener("requestWriteLock",async t=>{Hn[t.data.name]!=null&&Hn[t.data.name].writeLock().then(async n=>t.data.handler().finally(()=>{n()}))}))),Hn[e.name]==null&&(Hn[e.name]=g6(e.name,e)),Hn[e.name]}var Nc=class{lock;child;pins;started;constructor(e,t,n={}){this.child=e,this.pins=t,this.lock=jf({singleProcess:n.holdGcLock}),this.started=!1}isStarted(){return this.started}async start(){await Vr(this.child),this.started=!0}async stop(){await Hr(this.child),this.started=!1}unwrap(){return this.child}async put(e,t,n={}){let o=await this.lock.readLock();try{return await this.child.put(e,t,n)}finally{o()}}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 o=this;yield*this.child.deleteMany(async function*(){for await(let i of e){if(await o.pins.isPinned(i))throw new Error("CID was pinned");yield i}}(),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 $1=42;function b6(r){return r instanceof ArrayBuffer?new Uint8Array(r,0,r.byteLength):r}function x6(r){if(r.asCID!==r&&r["/"]!==r.bytes)return null;let e=U.asCID(r);if(!e)return null;let t=new Uint8Array(e.bytes.byteLength+1);return t.set(e.bytes,1),[new B(w.tag,$1),new B(w.bytes,t)]}function E6(){throw new Error("`undefined` is not supported by the IPLD Data Model and cannot be encoded")}function v6(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 Yf={float64:!0,typeEncoders:{Object:x6,undefined:E6,number:v6}},EC={...Yf,typeEncoders:{...Yf.typeEncoders}};function S6(r){if(r[0]!==0)throw new Error("Invalid CID for CBOR tag 42; expected leading 0x00");return U.decode(r.subarray(1))}var Cc={allowIndefinite:!1,coerceUndefinedToNull:!0,allowNaN:!1,allowInfinity:!1,allowBigInt:!0,strict:!0,useMaps:!1,rejectDuplicateMapKeys:!0,tags:[]};Cc.tags[$1]=S6;var vC={...Cc,tags:Cc.tags.slice()};var ln=113,Zi=r=>sn(r,Yf),Mn=r=>tt(b6(r),Cc);var Xf=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),o=[];for(let i=0;i<n.length;i++)o[i]=n.charCodeAt(i);e.push(o)}[w.negint.major](e,t){this[w.uint.major](e,t)}[w.bytes.major](e,t){throw new Error(`${Tr} unsupported type: Uint8Array`)}[w.string.major](e,t){this.prefix(e);let n=nc(JSON.stringify(t.value));e.push(n.length>32?Pi(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(`${Tr} 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),o=[],i=!1;for(let s=0;s<n.length;s++)o[s]=n.charCodeAt(s),!i&&(o[s]===46||o[s]===101||o[s]===69)&&(i=!0);i||(o.push(46),o.push(48)),e.push(o)}};function _6(r,e){if(Array.isArray(r[0])||Array.isArray(e[0]))throw new Error(`${Tr} 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(`${Tr} non-string map keys are not supported`);if(t<n)return-1;if(t>n)return 1;throw new Error(`${Tr} unexpected duplicate map keys, this is not supported`)}var A6={addBreakTokens:!0,mapSorter:_6};function Qi(r,e){return e=Object.assign({},A6,e),Sf(r,new Xf,e)}var un=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(`${$} 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(`${$} unexpected token at position ${this._pos}, expected to find '${String.fromCharCode(...e)}'`)}parseNumber(){let e=this._pos,t=!1,n=!1,o=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 B(w.uint,0,this._pos-e);if(o([48,49,50,51,52,53,54,55,56,57]),t&&this._pos===e+1)throw new Error(`${$} unexpected token at position ${this._pos}`);if(!this.done()&&this.ch()===46){if(n)throw new Error(`${$} unexpected token at position ${this._pos}`);n=!0,this._pos++,o([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++,o([48,49,50,51,52,53,54,55,56,57]));let i=String.fromCharCode.apply(null,this.data.subarray(e,this._pos)),s=parseFloat(i);return n?new B(w.float,s,this._pos-e):this.options.allowBigInt!==!0||Number.isSafeInteger(s)?new B(s>=0?w.uint:w.negint,s,this._pos-e):new B(s>=0?w.uint:w.negint,BigInt(i),this._pos-e)}parseString(){if(this.ch()!==34)throw new Error(`${$} unexpected character at position ${this._pos}; this shouldn't happen`);this._pos++;for(let i=this._pos,s=0;i<this.data.length&&s<65536;i++,s++){let a=this.data[i];if(a===92||a<32||a>=128)break;if(a===34){let c=String.fromCharCode.apply(null,this.data.subarray(this._pos,i));return this._pos=i+1,new B(w.string,c,s)}}let e=this._pos,t=[],n=()=>{if(this._pos+4>=this.data.length)throw new Error(`${$} unexpected end of unicode escape sequence at position ${this._pos}`);let i=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(`${$} unexpected unicode escape character at position ${this._pos}`);i=i*16+a,this._pos++}return i},o=()=>{let i=this.ch(),s=null,a=i>239?4:i>223?3:i>191?2:1;if(this._pos+a>this.data.length)throw new Error(`${$} unexpected unicode sequence at position ${this._pos}`);let c,u,l,f;switch(a){case 1:i<128&&(s=i);break;case 2:c=this.data[this._pos+1],(c&192)===128&&(f=(i&31)<<6|c&63,f>127&&(s=f));break;case 3:c=this.data[this._pos+1],u=this.data[this._pos+2],(c&192)===128&&(u&192)===128&&(f=(i&15)<<12|(c&63)<<6|u&63,f>2047&&(f<55296||f>57343)&&(s=f));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&&(f=(i&15)<<18|(c&63)<<12|(u&63)<<6|l&63,f>65535&&f<1114112&&(s=f))}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 i=this.ch(),s;switch(i){case 92:if(this._pos++,this.done())throw new Error(`${$} 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(`${$} unexpected string escape character at position ${this._pos}`)}break;case 34:return this._pos++,new B(w.string,mf(t),this._pos-e);default:if(i<32)throw new Error(`${$} invalid control character at position ${this._pos}`);i<128?(t.push(i),this._pos++):o()}}throw new Error(`${$} unexpected end of string at position ${this._pos}`)}parseValue(){switch(this.ch()){case 123:return this.modeStack.push("obj-start"),this._pos++,new B(w.map,1/0,1);case 91:return this.modeStack.push("array-start"),this._pos++,new B(w.array,1/0,1);case 34:return this.parseString();case 110:return this.expect([110,117,108,108]),new B(w.null,null,4);case 102:return this.expect([102,97,108,115,101]),new B(w.false,!1,5);case 116:return this.expect([116,114,117,101]),new B(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(`${$} 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 B(w.break,void 0,1);if(this.ch()!==44)throw new Error(`${$} 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 B(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 B(w.break,void 0,1);if(this.ch()!==44)throw new Error(`${$} 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 B(w.break,void 0,1);let e=this.parseString();if(this.skipWhitespace(),this.ch()!==58)throw new Error(`${$} 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(`${$} unexpected parse state at position ${this._pos}; this shouldn't happen`)}}};function es(r,e){return e=Object.assign({tokenizer:new un(r,e)},e),tt(r,e)}function k6(r){return r instanceof ArrayBuffer?new Uint8Array(r,0,r.byteLength):r}function I6(r){if(r.asCID!==r&&r["/"]!==r.bytes)return null;let e=U.asCID(r);if(!e)return null;let t=e.toString();return[new B(w.map,1/0,1),new B(w.string,"/",1),new B(w.string,t,t.length),new B(w.break,void 0,1)]}function Lc(r){let e=Jt.encode(r).slice(1);return[new B(w.map,1/0,1),new B(w.string,"/",1),new B(w.map,1/0,1),new B(w.string,"bytes",5),new B(w.string,e,e.length),new B(w.break,void 0,1),new B(w.break,void 0,1)]}function Gt(r){return Lc(new Uint8Array(r.buffer,r.byteOffset,r.byteLength))}function B6(r){return Lc(new Uint8Array(r))}function R6(){throw new Error("`undefined` is not supported by the IPLD Data Model and cannot be encoded")}function T6(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 N6={typeEncoders:{Object:I6,Buffer:Lc,Uint8Array:Lc,Int8Array:Gt,Uint16Array:Gt,Int16Array:Gt,Uint32Array:Gt,Int32Array:Gt,Float32Array:Gt,Float64Array:Gt,Uint8ClampedArray:Gt,BigInt64Array:Gt,BigUint64Array:Gt,DataView:Gt,ArrayBuffer:B6,undefined:R6,number:T6}},Zf=class extends un{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 B(w.tag,42,0)}if(n.type===w.map){let o=this._next();if(o.type===w.string&&o.value==="bytes"){let i=this._next();if(i.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=Jt.decode(`m${i.value}`);return new B(w.bytes,s,i.value.length)}this.tokenBuffer.push(i)}this.tokenBuffer.push(o)}this.tokenBuffer.push(n)}this.tokenBuffer.push(t)}return e}},Jf={allowIndefinite:!1,allowUndefined:!1,allowNaN:!1,allowInfinity:!1,allowBigInt:!0,strict:!0,useMaps:!1,rejectDuplicateMapKeys:!0,tags:[]};Jf.tags[42]=U.parse;var fn=297,q1=r=>Qi(r,N6),Dc=r=>{let e=k6(r),t=Object.assign(Jf,{tokenizer:new Zf(e,Jf)});return es(e,t)};var VC=new TextDecoder;var HC=new TextEncoder;var Ne={};ve(Ne,{code:()=>ye,createLink:()=>ty,createNode:()=>ey,decode:()=>be,encode:()=>ne,name:()=>z6,prepare:()=>Ae,validate:()=>td});var C6=new TextDecoder;function Qf(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 o=r[e++];if(t+=n<28?(o&127)<<n:(o&127)*2**n,o<128)break}return[t,e]}function Oc(r,e){let t;[t,e]=Qf(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 G1(r,e){let t;return[t,e]=Qf(r,e),[t&7,t>>3,e]}function L6(r){let e={},t=r.length,n=0;for(;n<t;){let o,i;if([o,i,n]=G1(r,n),i===1){if(e.Hash)throw new Error("protobuf: (PBLink) duplicate Hash section");if(o!==2)throw new Error(`protobuf: (PBLink) wrong wireType (${o}) 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]=Oc(r,n)}else if(i===2){if(e.Name!==void 0)throw new Error("protobuf: (PBLink) duplicate Name section");if(o!==2)throw new Error(`protobuf: (PBLink) wrong wireType (${o}) for Name`);if(e.Tsize!==void 0)throw new Error("protobuf: (PBLink) invalid order, found Tsize before Name");let s;[s,n]=Oc(r,n),e.Name=C6.decode(s)}else if(i===3){if(e.Tsize!==void 0)throw new Error("protobuf: (PBLink) duplicate Tsize section");if(o!==0)throw new Error(`protobuf: (PBLink) wrong wireType (${o}) for Tsize`);[e.Tsize,n]=Qf(r,n)}else throw new Error(`protobuf: (PBLink) invalid fieldNumber, expected 1, 2 or 3, got ${i}`)}if(n>t)throw new Error("protobuf: (PBLink) unexpected end of data");return e}function W1(r){let e=r.length,t=0,n,o=!1,i;for(;t<e;){let a,c;if([a,c,t]=G1(r,t),a!==2)throw new Error(`protobuf: (PBNode) invalid wireType, expected 2, got ${a}`);if(c===1){if(i)throw new Error("protobuf: (PBNode) duplicate Data section");[i,t]=Oc(r,t),n&&(o=!0)}else if(c===2){if(o)throw new Error("protobuf: (PBNode) duplicate Links section");n||(n=[]);let u;[u,t]=Oc(r,t),n.push(L6(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 i&&(s.Data=i),s.Links=n||[],s}var Y1=new TextEncoder,j1=2**32,D6=2**31;function P6(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=ts(e,t,r.Tsize)-1,e[t]=24}if(typeof r.Name=="string"){let n=Y1.encode(r.Name);t-=n.length,e.set(n,t),t=ts(e,t,n.length)-1,e[t]=18}return r.Hash&&(t-=r.Hash.length,e.set(r.Hash,t),t=ts(e,t,r.Hash.length)-1,e[t]=10),e.length-t}function X1(r){let e=U6(r),t=new Uint8Array(e),n=e;if(r.Data&&(n-=r.Data.length,t.set(r.Data,n),n=ts(t,n,r.Data.length)-1,t[n]=10),r.Links)for(let o=r.Links.length-1;o>=0;o--){let i=P6(r.Links[o],t.subarray(0,n));n-=i,n=ts(t,n,i)-1,t[n]=18}return t}function O6(r){let e=0;if(r.Hash){let t=r.Hash.length;e+=1+t+qo(t)}if(typeof r.Name=="string"){let t=Y1.encode(r.Name).length;e+=1+t+qo(t)}return typeof r.Tsize=="number"&&(e+=1+qo(r.Tsize)),e}function U6(r){let e=0;if(r.Data){let t=r.Data.length;e+=1+t+qo(t)}if(r.Links)for(let t of r.Links){let n=O6(t);e+=1+n+qo(n)}return e}function ts(r,e,t){e-=qo(t);let n=e;for(;t>=D6;)r[e++]=t&127|128,t/=128;for(;t>=128;)r[e++]=t&127|128,t>>>=7;return r[e]=t,n}function qo(r){return r%2===0&&r++,Math.floor((F6(r)+6)/7)}function F6(r){let e=0;return r>=j1&&(r=Math.floor(r/j1),e=32),r>=65536&&(r>>>=16,e+=16),r>=256&&(r>>>=8,e+=8),e+V6[r]}var V6=[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 H6=["Data","Links"],M6=["Hash","Name","Tsize"],ed=new TextEncoder;function J1(r,e){if(r===e)return 0;let t=r.Name?ed.encode(r.Name):[],n=e.Name?ed.encode(e.Name):[],o=t.length,i=n.length;for(let s=0,a=Math.min(o,i);s<a;++s)if(t[s]!==n[s]){o=t[s],i=n[s];break}return o<i?-1:i<o?1:0}function Z1(r,e){return!Object.keys(r).some(t=>!e.includes(t))}function Q1(r){if(typeof r.asCID=="object"){let t=U.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=U.asCID(r.Hash);try{t||(typeof r.Hash=="string"?t=U.parse(r.Hash):r.Hash instanceof Uint8Array&&(t=U.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 Ae(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=ed.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(Q1),e.Links.sort(J1);else throw new TypeError("Invalid DAG-PB form");else e.Links=[];return e}function td(r){if(!r||typeof r!="object"||Array.isArray(r)||r instanceof Uint8Array||r["/"]&&r["/"]===r.bytes)throw new TypeError("Invalid DAG-PB form");if(!Z1(r,H6))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(!Z1(t,M6))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&&J1(t,r.Links[e-1])===-1)throw new TypeError("Invalid DAG-PB form (links must be sorted by Name bytes)")}}function ey(r,e=[]){return Ae({Data:r,Links:e})}function ty(r,e,t){return Q1({Hash:t,Name:r,Tsize:e})}function ry(r){return r instanceof ArrayBuffer?new Uint8Array(r,0,r.byteLength):r}var z6="dag-pb",ye=112;function ne(r){td(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),X1(e)}function be(r){let e=ry(r),t=W1(e),n={};return t.Data&&(n.Data=t.Data),t.Links&&(n.Links=t.Links.map(o=>{let i={};try{i.Hash=U.decode(o.Hash)}catch{}if(!i.Hash)throw new Error("Invalid Hash field found in link, expected CID");return o.Name!==void 0&&(i.Name=o.Name),o.Tsize!==void 0&&(i.Tsize=o.Tsize),i})),n}var $6={codec:ye,*walk(r){yield*be(r).Links.map(t=>t.Hash)}},K6={codec:ge,*walk(){}},ny=42,q6={codec:ln,*walk(r){let e=[],t=[];t[ny]=n=>{if(n[0]!==0)throw new Error("Invalid CID for CBOR tag 42; expected leading 0x00");let o=U.decode(n.subarray(1));return e.push(o),o},tt(r,{tags:t}),yield*e}},rd=class extends un{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 B(w.tag,42,0)}if(n.type===w.map){let o=this._next();if(o.type===w.string&&o.value==="bytes"){let i=this._next();if(i.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=Jt.decode(`m${i.value}`);return new B(w.bytes,s,i.value.length)}this.tokenBuffer.push(i)}this.tokenBuffer.push(o)}this.tokenBuffer.push(n)}this.tokenBuffer.push(t)}return e}},G6={codec:fn,*walk(r){let e=[],t=[];t[ny]=n=>{let o=U.parse(n);return e.push(o),o},es(r,{tags:t,tokenizer:new rd(r,{tags:t,allowIndefinite:!0,allowUndefined:!0,allowNaN:!0,allowInfinity:!0,allowBigInt:!0,strict:!1,rejectDuplicateMapKeys:!1})}),yield*e}},W6={codec:$r,*walk(){}};function oy(r=[]){let e={};return[$6,K6,q6,G6,W6,...r].forEach(t=>{e[t.codec]=t}),e}var nd=new Be("/version"),iy=1;async function sy(r){if(!await r.has(nd)){await r.put(nd,F(`${iy}`));return}let e=await r.get(nd),t=W(e);if(parseInt(t,10)!==iy)throw new Error("Unknown datastore version, a datastore migration may be required")}function ay(r=[]){let e={};return[ae,Vl,Ge,...r].forEach(t=>{e[t.code]=t}),e}var ar=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:o}of e)await this.put(n,o,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 zn={};ve(zn,{abortedError:()=>J6,closeFailedError:()=>Y6,deleteFailedError:()=>id,getFailedError:()=>X6,hasFailedError:()=>Z6,notFoundError:()=>dn,openFailedError:()=>j6,putFailedError:()=>od});var Lr=J(Ie(),1);function j6(r){return r=r??new Error("Open failed"),(0,Lr.default)(r,"ERR_OPEN_FAILED")}function Y6(r){return r=r??new Error("Close failed"),(0,Lr.default)(r,"ERR_CLOSE_FAILED")}function od(r){return r=r??new Error("Put failed"),(0,Lr.default)(r,"ERR_PUT_FAILED")}function X6(r){return r=r??new Error("Get failed"),(0,Lr.default)(r,"ERR_GET_FAILED")}function id(r){return r=r??new Error("Delete failed"),(0,Lr.default)(r,"ERR_DELETE_FAILED")}function Z6(r){return r=r??new Error("Has failed"),(0,Lr.default)(r,"ERR_HAS_FAILED")}function dn(r){return r=r??new Error("Not Found"),(0,Lr.default)(r,"ERR_NOT_FOUND")}function J6(r){return r=r??new Error("Aborted"),(0,Lr.default)(r,"ERR_ABORTED")}var cy=0,Uc=class extends ar{put(e){return e}get(e){if(e.code===cy)return e.multihash.digest;throw dn()}has(e){return e.code===cy}delete(){}*getAll(){}};function Q6(r){return r[Symbol.asyncIterator]!=null}function ev(r,e){if(Q6(r))return async function*(){for await(let a of r)await e(a)&&(yield a)}();let t=Zn(r),{value:n,done:o}=t.next();if(o===!0)return function*(){}();let i=e(n);if(typeof i.then=="function")return async function*(){await i&&(yield n);for await(let a of t)await e(a)&&(yield a)}();let s=e;return function*(){i===!0&&(yield n);for(let a of t)s(a)&&(yield a)}()}var dt=ev;var tv=ee("blockstore:core:tiered"),rs=class extends ar{stores;constructor(e){super(),this.stores=e.slice()}async put(e,t,n){try{return await Promise.all(this.stores.map(async o=>{await o.put(e,t,n)})),e}catch(o){throw od(o)}}async get(e,t){for(let n of this.stores)try{let o=await n.get(e,t);if(o!=null)return o}catch(o){tv.error(o)}throw dn()}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 id(n)}}async*putMany(e,t={}){let n,o=this.stores.map(i=>{let s=Tt({objectMode:!0});return Ft(i.putMany(s,t)).catch(a=>{n=a}),s});try{for await(let i of e){if(n!=null)throw n;o.forEach(s=>s.push(i)),yield i.cid}}finally{o.forEach(i=>i.end())}}async*deleteMany(e,t={}){let n,o=this.stores.map(i=>{let s=Tt({objectMode:!0});return Ft(i.deleteMany(s,t)).catch(a=>{n=a}),s});try{for await(let i of e){if(n!=null)throw n;o.forEach(s=>s.push(i)),yield i}}finally{o.forEach(i=>i.end())}}async*getAll(e){let t=new Set;yield*dt(pr(...this.stores.map(n=>n.getAll(e))),n=>{let o=n.cid.toString();return t.has(o)?!1:(t.add(o),!0)})}};function rv(r){return typeof r.retrieve=="function"}function nv(r){return typeof r.announce=="function"}var Fc=class{child;blockRetrievers;blockAnnouncers;hashers;started;log;constructor(e){this.log=e.logger.forComponent("helia:networked-storage"),this.child=new rs([new Uc,e.blockstore]),this.blockRetrievers=(e.blockBrokers??[]).filter(rv),this.blockAnnouncers=(e.blockBrokers??[]).filter(nv),this.hashers=e.hashers??{},this.started=!1}isStarted(){return this.started}async start(){await Vr(this.child,...new Set([...this.blockRetrievers,...this.blockAnnouncers])),this.started=!0}async stop(){await Hr(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(o=>{o.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=dt(e,async({cid:i})=>{let s=await this.child.has(i);return s&&t.onProgress?.(new V("blocks:put-many:duplicate",i)),!s}),o=_l(n,({cid:i,block:s})=>{t.onProgress?.(new V("blocks:put-many:providers:notify",i)),this.blockAnnouncers.forEach(a=>{a.announce(i,s,t)})});t.onProgress?.(new V("blocks:put-many:blockstore:put-many")),yield*this.child.putMany(o,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 ly(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(o=>{o.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(_l(e,async n=>{if(t.offline!==!0&&!await this.child.has(n)){t.onProgress?.(new V("blocks:get-many:providers:get",n));let o=await ly(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,o,t),t.onProgress?.(new V("blocks:get-many:providers:notify",n)),this.blockAnnouncers.forEach(i=>{i.announce(n,o,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)}},ov=(r,e)=>{if(e==null)throw new P(`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(!ce(n.digest,r.multihash.digest))throw new P("Hash of downloaded block did not match multihash from passed CID","ERR_HASH_MISMATCH")}};async function ly(r,e,t,n){let o=ov(r,t),i=new AbortController,s=Sn([i.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 o(l),c=!0}});return c||await o(u),u}catch(c){throw n.log.error("could not retrieve verified block for %c",r,c),c}}))}finally{s.clear()}}var Vc=class{blockstore;datastore;pins;logger;routing;dagWalkers;hashers;dns;log;constructor(e){this.logger=e.logger??vh(),this.log=this.logger.forComponent("helia"),this.hashers=ay(e.hashers),this.dagWalkers=oy(e.dagWalkers),this.dns=e.dns??Yi();let t={blockstore:e.blockstore,datastore:e.datastore,hashers:this.hashers,dagWalkers:this.dagWalkers,logger:this.logger,blockBrokers:[],dns:this.dns,...e.components??{}};t.blockBrokers=e.blockBrokers.map(o=>o(t));let n=new Fc(t);this.pins=new Rc(e.datastore,n,this.dagWalkers),this.blockstore=new Nc(n,this.pins,{holdGcLock:e.holdGcLock??!0}),this.datastore=e.datastore,this.routing=new Tc(t,{routers:(e.routers??[]).flatMap(o=>{let i=[o];return o[li]!=null&&i.push(o[li]),o[ui]!=null&&i.push(o[ui]),i})})}async start(){await sy(this.datastore),await Vr(this.blockstore,this.datastore,this.routing)}async stop(){await Hr(this.blockstore,this.datastore,this.routing)}async gc(e={}){let t=await this.blockstore.lock.writeLock();try{let n=this,o=this.blockstore.unwrap();this.log("gc start"),await Ft(o.deleteMany(async function*(){for await(let{cid:i}of o.getAll())try{if(await n.pins.isPinned(i,e))continue;yield i,e.onProgress?.(new V("helia:gc:deleted",i))}catch(s){n.log.error("Error during gc",s),e.onProgress?.(new V("helia:gc:error",s))}}()))}finally{t()}this.log("gc finished")}};var ns=class extends ar{data;constructor(){super(),this.data=new Map}put(e,t){return this.data.set(Fe.encode(e.multihash.bytes),t),e}get(e){let t=this.data.get(Fe.encode(e.multihash.bytes));if(t==null)throw dn();return t}has(e){return this.data.has(Fe.encode(e.multihash.bytes))}async delete(e){this.data.delete(Fe.encode(e.multihash.bytes))}async*getAll(){for(let[e,t]of this.data.entries())yield{cid:U.createV1(ge,Ze(Fe.decode(e))),block:t}}};var WL={...zn};var uy=J(Ie(),1);function Hc(r){return r=r??new Error("Not Found"),(0,uy.default)(r,"ERR_NOT_FOUND")}var fy="SHARDING";function sv(r){return r[Symbol.asyncIterator]!=null}function av(r){if(sv(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 Go=av;function cv(r){return r[Symbol.asyncIterator]!=null}function lv(r,e){return cv(r)?async function*(){yield*(await Go(r)).sort(e)}():function*(){yield*Go(r).sort(e)}()}var Mc=lv;var Dr=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:o}of e)await this.put(n,o,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,o){e.push({key:n,value:o})},delete(n){t.push(n)},commit:async n=>{await Ft(this.putMany(e,n)),e=[],await Ft(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 o=e.prefix;n=dt(n,i=>i.key.toString().startsWith(o))}if(Array.isArray(e.filters)&&(n=e.filters.reduce((o,i)=>dt(o,i),n)),Array.isArray(e.orders)&&(n=e.orders.reduce((o,i)=>Mc(o,i),n)),e.offset!=null){let o=0,i=e.offset;n=dt(n,()=>o++>=i)}return e.limit!=null&&(n=zs(n,e.limit)),n}queryKeys(e,t){let n=this._allKeys(e,t);if(e.prefix!=null){let o=e.prefix;n=dt(n,i=>i.toString().startsWith(o))}if(Array.isArray(e.filters)&&(n=e.filters.reduce((o,i)=>dt(o,i),n)),Array.isArray(e.orders)&&(n=e.orders.reduce((o,i)=>Mc(o,i),n)),e.offset!=null){let o=e.offset,i=0;n=dt(n,()=>i++>=o)}return e.limit!=null&&(n=zs(n,e.limit)),n}};var is=class extends Dr{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 Hc();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 Be(e),value:t}}*_allKeys(){for(let e of this.data.keys())yield new Be(e)}};var ED=new Be(fy);var LD=ee("datastore:core:tiered");async function hy(r={}){let e=r.datastore??new is,t=r.blockstore??new ns,n=new Vc({...r,datastore:e,blockstore:t,blockBrokers:r.blockBrokers??[hi()],routers:r.routers??[ji("https://delegated-ipfs.dev")]});return r.start!==!1&&await n.start(),n}var sd=J(Ps(),1);var ad=40;function cd(r,e){if(!r.length)throw new Error("Unexpected end of data");let t=sd.default.decode(r);return e.seek(sd.default.decode.bytes),t}function ld(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 hn={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},ss={"CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)":hn.Link,"CarV1HeaderOrV2Pragma > roots (anon)":r=>{if(hn.List(r)!==void 0){for(let e=0;e<r.length;e++){let t=r[e];if(t=ss["CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)"](t),t===void 0)return;if(t!==r[e]){let n=r.slice(0,e);for(let o=e;o<r.length;o++){let i=r[o];if(i=ss["CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)"](i),i===void 0)return;n.push(i)}return n}}return r}},Int:hn.Int,CarV1HeaderOrV2Pragma:r=>{if(hn.Map(r)===void 0)return;let e=Object.entries(r),t=r,n=1;for(let o=0;o<e.length;o++){let[i,s]=e[o];switch(i){case"roots":{let a=ss["CarV1HeaderOrV2Pragma > roots (anon)"](r[i]);if(a===void 0)return;if(a!==s||t!==r){if(t===r){t={};for(let c=0;c<o;c++)t[e[c][0]]=e[c][1]}t.roots=a}}break;case"version":{n--;let a=ss.Int(r[i]);if(a===void 0)return;if(a!==s||t!==r){if(t===r){t={};for(let c=0;c<o;c++)t[e[c][0]]=e[c][1]}t.version=a}}break;default:return}}if(!(n>0))return t}},as={"CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)":hn.Link,"CarV1HeaderOrV2Pragma > roots (anon)":r=>{if(hn.List(r)!==void 0){for(let e=0;e<r.length;e++){let t=r[e];if(t=as["CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)"](t),t===void 0)return;if(t!==r[e]){let n=r.slice(0,e);for(let o=e;o<r.length;o++){let i=r[o];if(i=as["CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)"](i),i===void 0)return;n.push(i)}return n}}return r}},Int:hn.Int,CarV1HeaderOrV2Pragma:r=>{if(hn.Map(r)===void 0)return;let e=Object.entries(r),t=r,n=1;for(let o=0;o<e.length;o++){let[i,s]=e[o];switch(i){case"roots":{let a=as["CarV1HeaderOrV2Pragma > roots (anon)"](s);if(a===void 0)return;if(a!==s||t!==r){if(t===r){t={};for(let c=0;c<o;c++)t[e[c][0]]=e[c][1]}t.roots=a}}break;case"version":{n--;let a=as.Int(s);if(a===void 0)return;if(a!==s||t!==r){if(t===r){t={};for(let c=0;c<o;c++)t[e[c][0]]=e[c][1]}t.version=a}}break;default:return}}if(!(n>0))return t}},ud={toTyped:ss.CarV1HeaderOrV2Pragma,toRepresentation:as.CarV1HeaderOrV2Pragma};var gP=vf();var mv=J(Ps(),1);var vP=[new B(w.map,2),new B(w.string,"version"),new B(w.uint,1),new B(w.string,"roots")],SP=new B(w.tag,42);async function fd(r,e){let t=cd(await r.upTo(8),r);if(t===0)throw new Error("Invalid CAR header (zero length)");let n=await r.exactly(t,!0),o=Mn(n);if(ud.toTyped(o)===void 0)throw new Error("Invalid CAR header format");if(o.version!==1&&o.version!==2||e!==void 0&&o.version!==e)throw new Error(`Invalid CAR version: ${o.version}${e!==void 0?` (expected ${e})`:""}`);if(o.version===1){if(!Array.isArray(o.roots))throw new Error("Invalid CAR header format");return o}if(o.roots!==void 0)throw new Error("Invalid CAR header format");let i=ld(await r.exactly(ad,!0));r.seek(i.dataOffset-r.pos);let s=await fd(r,1);return Object.assign(s,i)}function cs(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 o=r.subarray(e,e+t);return n&&(e+=t),o},seek(t){e+=t},get pos(){return e}}}var dd=J(Ps(),1),yy=1;function hd(r){let e=Zi({version:yy,roots:r}),t=dd.default.encode(e.length),n=new Uint8Array(t.length+e.length);return n.set(t,0),n.set(e,t.length),n}function gy(r){return{async setRoots(e){let t=hd(e);await r.write(t)},async writeBlock(e){let{cid:t,bytes:n}=e;await r.write(new Uint8Array(dd.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 yy}}}function zc(){}function wy(){let r=[],e=null,t=zc,n=!1,o=null,i=zc,s=()=>(e||(e=new Promise(u=>{t=()=>{e=null,t=zc,u()}})),e),a={write(u){r.push(u);let l=s();return i(),l},async end(){n=!0;let u=s();i(),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}):(o||(o=new Promise(l=>{i=()=>(o=null,i=zc,l(c.next()))})),o)}};return{writer:a,iterator:c}}var ls=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=U.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=bv(e);let{encoder:t,iterator:n}=by(),o=new r(e,t),i=new $c(n);return{writer:o,out:i}}static createAppender(){let{encoder:e,iterator:t}=by();e.setRoots=()=>Promise.resolve();let n=new r([],e),o=new $c(t);return{writer:n,out:o}}static async updateRootsInBytes(e,t){let n=cs(e);await fd(n);let o=hd(t);if(Number(n.pos)!==o.length)throw new Error(`updateRoots() can only overwrite a header of the same length (old header is ${n.pos} bytes, new header is ${o.length} bytes)`);return e.set(o,0),e}},$c=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 by(){let r=wy(),{writer:e,iterator:t}=r;return{encoder:gy(e),iterator:t}}function bv(r){if(r===void 0)return[];if(!Array.isArray(r)){let t=U.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=U.asCID(t);if(!n)throw new TypeError("roots must be a single CID or an array of CIDs");e.push(n)}return e}var xv=1,pd=class{components;constructor(e,t){this.components=e}async import(e,t){await Ft(this.components.blockstore.putMany(We(e.blocks(),({cid:n,bytes:o})=>({cid:n,block:o})),t))}async export(e,t,n){let o=we(),i=Array.isArray(e)?e:[e],s=new ut({concurrency:xv});s.on("idle",()=>{o.resolve()}),s.on("error",a=>{s.clear(),o.reject(a)});for(let a of i)s.add(async()=>{await this.#e(a,s,async(c,u)=>{await t.put({cid:c,bytes:u})},n)}).catch(()=>{});try{await o.promise}finally{await t.close()}}async*stream(e,t){let{writer:n,out:o}=ls.create(e);this.export(e,n,t).catch(()=>{});for await(let i of o)yield i}async#e(e,t,n,o){let i=this.components.dagWalkers[e.code];if(i==null)throw new Error(`No dag walker found for cid codec ${e.code}`);let s=await this.components.blockstore.get(e,o);await n(e,s);for await(let a of i.walk(s))t.add(async()=>{await this.#e(a,t,n,o)})}};function xy(r,e={}){return new pd(r,e)}var md=J(tc(),1);function Ey(r,e){let t=e.map((n,o)=>({record:rt(n),index:o}));return t.sort((n,o)=>{let i=n.record.sequence,s=o.record.sequence;if(i>s)return-1;if(i<s)return 1;if(n.record.validityType===He.ValidityType.EOL&&o.record.validityType===He.ValidityType.EOL){let a=md.default.fromString(n.record.validity).toDate(),c=md.default.fromString(o.record.validity).toDate();if(a.getTime()>c.getTime())return-1;if(a.getTime()<c.getTime())return 1}return 0}),t[0].index}var Ev=32;async function vy(r,e,t,n,o={}){if(e===0)throw new Error("recursion limit exceeded");n("query %s for TXT and CNAME records",r);let s=(await t.query(r,{...o,types:[Ot.TXT]})).Answer.sort((u,l)=>u.data.localeCompare(l.data));n("found %d TXT records for %s",s.length,r);for(let u of s)try{let l=u.data;if(l.startsWith('"')&&l.endsWith('"')&&(l=l.substring(1,l.length-1)),!l.startsWith("dnslink="))continue;n("%s TXT %s",u.name,l),l=l.replace("dnslink=","");let[,f,m,...d]=l.split("/");if(f==="ipfs")try{return{value:`/ipfs/${U.parse(m)}${d.length>0?`/${d.join("/")}`:""}`,answer:u}}catch{}else if(f==="ipns"){try{return{value:`/ipns/${Je(m)}${d.length>0?`/${d.join("/")}`:""}`,answer:u}}catch{}return await Kc(m,e-1,t,n,o)}else{if(f==="dnslink")return await Kc(m,e-1,t,n,o);n('unknown protocol "%s" in DNSLink record for domain: %s',f,r);continue}}catch(l){n.error("could not parse DNS link record for domain %s, %s",r,u.data,l)}n("no DNSLink records found for %s, falling back to CNAME",r);let c=(await t.query(r,{...o,types:[Ot.CNAME]})).Answer.sort((u,l)=>u.data.localeCompare(l.data));n("found %d CNAME records for %s",c.length,r);for(let u of c)try{return await Kc(u.data,e-1,t,n,o)}catch(l){n.error("domain %s cname %s had no DNSLink records",r,u.data,l)}throw new P(`No DNSLink records found for domain: ${r}`,"ERR_DNSLINK_NOT_FOUND")}async function Kc(r,e,t,n,o={}){if(e===0)throw new Error("recursion limit exceeded");r.startsWith("_dnslink.")||(r=`_dnslink.${r}`);try{return await vy(r,e,t,n,o)}catch(i){if(i.code!=="ENOTFOUND"&&i.code!=="ERR_DNSLINK_NOT_FOUND"&&i.code!=="ENODATA")throw i;return r.startsWith("_dnslink.")?r=r.replace("_dnslink.",""):r=`_dnslink.${r}`,await vy(r,e,t,n,o)}}async function Sy(r,e,t,n={}){return Kc(r,n.maxRecursiveDepth??Ev,e,t,n)}var yd=class{routing;constructor(e){this.routing=e}async put(e,t,n={}){try{await this.routing.put(e,t,n)}catch(o){n.onProgress?.(new V("ipns:routing:helia:error",o))}}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 _y(r){return new yd(r)}var qc=globalThis.CustomEvent??Event;async function*$n(r,e={}){let t=e.concurrency??1/0;t<1&&(t=1/0);let n=e.ordered==null?!1:e.ordered,o=new EventTarget,i=[],s=we(),a=we(),c=!1,u,l=!1;o.addEventListener("task-complete",()=>{a.resolve()}),Promise.resolve().then(async()=>{try{for await(let p of r){if(i.length===t&&(s=we(),await s.promise),l)break;let h={done:!1};i.push(h),p().then(y=>{h.done=!0,h.ok=!0,h.value=y,o.dispatchEvent(new qc("task-complete"))},y=>{h.done=!0,h.err=y,o.dispatchEvent(new qc("task-complete"))})}c=!0,o.dispatchEvent(new qc("task-complete"))}catch(p){u=p,o.dispatchEvent(new qc("task-complete"))}});function f(){return n?i[0]?.done:!!i.find(p=>p.done)}function*m(){for(;i.length>0&&i[0].done;){let p=i[0];if(i.shift(),p.ok)yield p.value;else throw l=!0,s.resolve(),p.err;s.resolve()}}function*d(){for(;f();)for(let p=0;p<i.length;p++)if(i[p].done){let h=i[p];if(i.splice(p,1),p--,h.ok)yield h.value;else throw l=!0,s.resolve(),h.err;s.resolve()}}for(;;){if(f()||(a=we(),await a.promise),u!=null)throw u;if(n?yield*m():yield*d(),c&&i.length===0)break}}var us;(function(r){let e;r.codec=()=>(e==null&&(e=Bt((t,n,o={})=>{o.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)),o.lengthDelimited!==!1&&n.ldelim()},(t,n)=>{let o={key:new Uint8Array(0),value:new Uint8Array(0),timeReceived:""},i=n==null?t.len:t.pos+n;for(;t.pos<i;){let s=t.uint32();switch(s>>>3){case 1:o.key=t.bytes();break;case 2:o.value=t.bytes();break;case 5:o.timeReceived=t.string();break;default:t.skipType(s&7);break}}return o})),e),r.encode=t=>It(t,r.codec()),r.decode=t=>At(t,r.codec())})(us||(us={}));function Ay(r){let e=r.getUTCFullYear(),t=String(r.getUTCMonth()+1).padStart(2,"0"),n=String(r.getUTCDate()).padStart(2,"0"),o=String(r.getUTCHours()).padStart(2,"0"),i=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${o}:${i}:${s}.${c}Z`}function ky(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),o=parseInt(t[2],10)-1,i=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,o,i,s,a,c,u))}var pn=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 us.encode(this.prepareSerialize())}prepareSerialize(){return{key:this.key,value:this.value,timeReceived:Ay(this.timeReceived)}}static deserialize(e){let t=us.decode(e);return new r(t.key,t.value,new Date(t.timeReceived))}static fromDeserialized(e){let t=ky(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 Iy;(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"})(Iy||(Iy={}));function gd(r){return new Be("/dht/record/"+W(r,"base32"),!1)}function By(r){return{async put(e,t,n={}){try{let o=gd(e),i=new pn(e,t,new Date);n.onProgress?.(new V("ipns:routing:datastore:put")),await r.put(o,i.serialize(),n)}catch(o){throw n.onProgress?.(new V("ipns:routing:datastore:error",o)),o}},async get(e,t={}){try{let n=gd(e);t.onProgress?.(new V("ipns:routing:datastore:get"));let o=await r.get(n,t);return pn.deserialize(o).value}catch(n){throw t.onProgress?.(new V("ipns:routing:datastore:error",n)),n}},async has(e,t={}){let n=gd(e);return r.has(n,t)}}}var Kn=ee("helia:ipns"),Sv=60*1e3,Ry=60*Sv,_v=24*Ry,wd=23*Ry,bd=class{routers;localStore;timeout;dns;log;constructor(e,t=[]){this.routers=[_y(e.routing),...t],this.localStore=By(e.datastore),this.dns=e.dns,this.log=e.logger.forComponent("helia:ipns")}async publish(e,t,n={}){try{let o=1n,i=Ho(e);if(await this.localStore.has(i,n)){let c=await this.localStore.get(i,n);o=rt(c).sequence+1n}let s=await w1(e,t,o,n.lifetime??_v,n),a=Cr(s);return await this.localStore.put(i,a,n),n.offline!==!0&&await Promise.all(this.routers.map(async c=>{await c.put(i,a,n)})),s}catch(o){throw n.onProgress?.(new V("ipns:publish:error",o)),o}}async resolve(e,t={}){let n=Ho(e),o=await this.#t(n,t);return{...await this.#e(o.value,t),record:o}}async resolveDNSLink(e,t={}){let n=await Sy(e,this.dns,this.log,t);return{...await this.#e(n.value,t),answer:n.answer}}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 i=Date.now()-n,s=wd-i;s<0&&(s=e.interval??wd),setTimeout(()=>{t().catch(a=>{Kn.error("error republishing",a)})},s)}this.timeout=setTimeout(()=>{t().catch(n=>{Kn.error("error republishing",n)})},e.interval??wd)}async#e(e,t={}){let n=e.split("/");try{let o=n[1];if(o==="ipns"){let{cid:i}=await this.resolve(Je(n[2]),t),s=n.slice(3).join("/");return{cid:i,path:s}}else if(o==="ipfs"){let i=U.parse(n[2]),s=n.slice(3).join("/");return{cid:i,path:s}}}catch(o){Kn.error("error parsing ipfs path",o)}throw Kn.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 o=[],i=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"?Kn("did not have record locally"):Kn.error("error finding IPNS record",u);return}try{await gc(e,c),o.push(c)}catch(u){i++,Kn.error("error finding IPNS record",u)}})),o.length===0)throw i>0?new P(`${i>1?`${i} records`:"Record"} found for routing key ${i>1?"were":"was"} invalid`,"ERR_RECORDS_FAILED_VALIDATION"):new P("Could not find record for routing key","ERR_NOT_FOUND");let s=o[Ey(e,o)];return await this.localStore.put(e,s,t),rt(s)}};function Ty(r,{routers:e=[]}={}){return new bd(r,e)}var Ad=J(Ie(),1);function Av(r){return r[Symbol.asyncIterator]!=null}function kv(r,e=1){return e=Number(e),Av(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 fs=kv;async function*ds(r,e=1){for await(let t of fs(r,e)){let n=t.map(async o=>o().then(i=>({ok:!0,value:i}),i=>({ok:!1,err:i})));for(let o=0;o<n.length;o++){let i=await n[o];if(i.ok)yield i.value;else throw i.err}}}var Iv=262144,hs=(r={})=>{let e=r.chunkSize??Iv;return async function*(n){let o=new Rt,i=0,s=!1;for await(let a of n)for(o.append(a),i+=a.length;i>=e;)if(yield o.slice(0,e),s=!0,e===o.length)o=new Rt,i=0;else{let c=new Rt;c.append(o.sublist(e)),o=c,i-=e}(!s||i>0)&&(yield o.subarray(0,i))}};var xd=J(Ie(),1);var Wt;(function(r){let e;(function(o){o.Raw="Raw",o.Directory="Directory",o.File="File",o.Metadata="Metadata",o.Symlink="Symlink",o.HAMTShard="HAMTShard"})(e=r.DataType||(r.DataType={}));let t;(function(o){o[o.Raw=0]="Raw",o[o.Directory=1]="Directory",o[o.File=2]="File",o[o.Metadata=3]="Metadata",o[o.Symlink=4]="Symlink",o[o.HAMTShard=5]="HAMTShard"})(t||(t={})),function(o){o.codec=()=>Rn(t)}(e=r.DataType||(r.DataType={}));let n;r.codec=()=>(n==null&&(n=Bt((o,i,s={})=>{if(s.lengthDelimited!==!1&&i.fork(),o.Type!=null&&(i.uint32(8),r.DataType.codec().encode(o.Type,i)),o.Data!=null&&(i.uint32(18),i.bytes(o.Data)),o.filesize!=null&&(i.uint32(24),i.uint64(o.filesize)),o.blocksizes!=null)for(let a of o.blocksizes)i.uint32(32),i.uint64(a);o.hashType!=null&&(i.uint32(40),i.uint64(o.hashType)),o.fanout!=null&&(i.uint32(48),i.uint64(o.fanout)),o.mode!=null&&(i.uint32(56),i.uint32(o.mode)),o.mtime!=null&&(i.uint32(66),Gc.codec().encode(o.mtime,i)),s.lengthDelimited!==!1&&i.ldelim()},(o,i)=>{let s={blocksizes:[]},a=i==null?o.len:o.pos+i;for(;o.pos<a;){let c=o.uint32();switch(c>>>3){case 1:s.Type=r.DataType.codec().decode(o);break;case 2:s.Data=o.bytes();break;case 3:s.filesize=o.uint64();break;case 4:s.blocksizes.push(o.uint64());break;case 5:s.hashType=o.uint64();break;case 6:s.fanout=o.uint64();break;case 7:s.mode=o.uint32();break;case 8:s.mtime=Gc.codec().decode(o,o.uint32());break;default:o.skipType(c&7);break}}return s})),n),r.encode=o=>It(o,r.codec()),r.decode=o=>At(o,r.codec())})(Wt||(Wt={}));var Gc;(function(r){let e;r.codec=()=>(e==null&&(e=Bt((t,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),t.Seconds!=null&&(n.uint32(8),n.int64(t.Seconds)),t.FractionalNanoseconds!=null&&(n.uint32(21),n.fixed32(t.FractionalNanoseconds)),o.lengthDelimited!==!1&&n.ldelim()},(t,n)=>{let o={},i=n==null?t.len:t.pos+n;for(;t.pos<i;){let s=t.uint32();switch(s>>>3){case 1:o.Seconds=t.int64();break;case 2:o.FractionalNanoseconds=t.fixed32();break;default:t.skipType(s&7);break}}return o})),e),r.encode=t=>It(t,r.codec()),r.decode=t=>At(t,r.codec())})(Gc||(Gc={}));var Ny;(function(r){let e;r.codec=()=>(e==null&&(e=Bt((t,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),t.MimeType!=null&&(n.uint32(10),n.string(t.MimeType)),o.lengthDelimited!==!1&&n.ldelim()},(t,n)=>{let o={},i=n==null?t.len:t.pos+n;for(;t.pos<i;){let s=t.uint32();switch(s>>>3){case 1:o.MimeType=t.string();break;default:t.skipType(s&7);break}}return o})),e),r.encode=t=>It(t,r.codec()),r.decode=t=>At(t,r.codec())})(Ny||(Ny={}));var Cy={Raw:"raw",Directory:"directory",File:"file",Metadata:"metadata",Symlink:"symlink",HAMTShard:"hamt-sharded-directory"},Bv=["directory","hamt-sharded-directory"],Ly=parseInt("0644",8),Dy=parseInt("0755",8),q=class r{static unmarshal(e){let t=Wt.decode(e),n=new r({type:Cy[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:o,hashType:i,fanout:s,mtime:a,mode:c}=e;if(t!=null&&!Object.values(Cy).includes(t))throw(0,xd.default)(new Error("Type: "+t+" is not valid"),"ERR_INVALID_TYPE");this.type=t??"file",this.data=n,this.hashType=i,this.fanout=s,this.blockSizes=o??[],this._originalMode=0,this.mode=c,this.mtime=a}set mode(e){e==null?this._mode=this.isDirectory()?Dy:Ly:this._mode=e&4095}get mode(){return this._mode}isDirectory(){return Bv.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=Wt.DataType.Raw;break;case"directory":e=Wt.DataType.Directory;break;case"file":e=Wt.DataType.File;break;case"metadata":e=Wt.DataType.Metadata;break;case"symlink":e=Wt.DataType.Symlink;break;case"hamt-sharded-directory":e=Wt.DataType.HAMTShard;break;default:throw(0,xd.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===Ly&&!this.isDirectory()&&(n=void 0),n===Dy&&this.isDirectory()&&(n=void 0));let o;return this.mtime!=null&&(o={Seconds:this.mtime.secs,FractionalNanoseconds:this.mtime.nsecs}),Wt.encode({Type:e,Data:t,filesize:this.isDirectory()?void 0:this.fileSize(),blocksizes:this.blockSizes,hashType:this.hashType,fanout:this.fanout,mode:n,mtime:o})}};var jt=async(r,e,t)=>{t.codec==null&&(t.codec=Ne);let n=await ae.digest(r),o=U.create(t.cidVersion,t.codec.code,n);return await e.put(o,r,t),o};function Py(r){return async function*(t,n){let o=0n;for await(let i of t.content)yield async()=>{let s,a={codec:Ne,cidVersion:r.cidVersion,onProgress:r.onProgress};r.rawLeaves?(a.codec=kt,a.cidVersion=1):(s=new q({type:r.leafType,data:i}),i=ne({Data:s.marshal(),Links:[]}));let c=await jt(i,n,a);return o+=BigInt(i.byteLength),r.onProgress?.(new V("unixfs:importer:progress:file:write",{bytesWritten:o,cid:c,path:t.path})),{cid:c,unixfs:s,size:BigInt(i.length),block:i}}}}var Ed=J(Ie(),1);var Oy=async(r,e,t)=>{let n=new q({type:"directory",mtime:r.mtime,mode:r.mode}),o=ne(Ae({Data:n.marshal()})),i=await jt(o,e,t),s=r.path;return{cid:i,path:s,unixfs:n,size:BigInt(o.length),originalPath:r.originalPath,block:o}};async function*Rv(r,e,t){let n=-1,o;for await(let i of ds(t.bufferImporter(r,e),t.blockWriteConcurrency)){if(n++,n===0){o={...i,single:!0};continue}else n===1&&o!=null&&(yield{...o,block:void 0,single:void 0},o=void 0);yield{...i,block:void 0}}o!=null&&(yield o)}function Uy(r){return r.single===!0}var Tv=(r,e,t)=>async function(o){if(o.length===1&&Uy(o[0])&&t.reduceSingleLeafToSelf){let l=o[0],f=l.block;return Uy(l)&&(r.mtime!==void 0||r.mode!==void 0)&&(l.unixfs=new q({type:"file",mtime:r.mtime,mode:r.mode,data:l.block}),f={Data:l.unixfs.marshal(),Links:[]},l.block=ne(Ae(f)),l.cid=await jt(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 i=new q({type:"file",mtime:r.mtime,mode:r.mode}),s=o.filter(l=>l.cid.code===ge&&l.size>0||l.unixfs!=null&&l.unixfs.data==null&&l.unixfs.fileSize()>0n?!0:!!l.unixfs?.data?.length).map(l=>l.cid.code===ge?(i.addBlockSize(l.size),{Name:"",Tsize:Number(l.size),Hash:l.cid}):(l.unixfs==null||l.unixfs.data==null?i.addBlockSize(l.unixfs?.fileSize()??0n):i.addBlockSize(BigInt(l.unixfs.data.length)),{Name:"",Tsize:Number(l.size),Hash:l.cid})),a={Data:i.marshal(),Links:s},c=ne(Ae(a)),u=await jt(c,e,t);return t.onProgress?.(new V("unixfs:importer:progress:file:layout",{cid:u,path:r.originalPath})),{cid:u,path:r.path,unixfs:i,size:BigInt(c.length+a.Links.reduce((l,f)=>l+(f.Tsize??0),0)),originalPath:r.originalPath,block:c}},Fy=async(r,e,t)=>t.layout(Rv(r,e,t),Tv(r,e,t));function Nv(r){return Symbol.iterator in r}function Cv(r){return Symbol.asyncIterator in r}function Lv(r){try{if(r instanceof Uint8Array)return async function*(){yield r}();if(Nv(r))return async function*(){yield*r}();if(Cv(r))return r}catch{throw(0,Ed.default)(new Error("Content was invalid"),"ERR_INVALID_CONTENT")}throw(0,Ed.default)(new Error("Content was invalid"),"ERR_INVALID_CONTENT")}function Vy(r){return async function*(t,n){for await(let o of t){let i;if(o.path!=null&&(i=o.path,o.path=o.path.split("/").filter(s=>s!=null&&s!==".").join("/")),Dv(o)){let s={path:o.path,mtime:o.mtime,mode:o.mode,content:async function*(){let a=0n;for await(let c of r.chunker(r.chunkValidator(Lv(o.content)))){let u=BigInt(c.byteLength);a+=u,r.onProgress?.(new V("unixfs:importer:progress:file:read",{bytesRead:a,chunkSize:u,path:o.path})),yield c}}(),originalPath:i};yield async()=>Fy(s,n,r)}else if(o.path!=null){let s={path:o.path,mtime:o.mtime,mode:o.mode,originalPath:i};yield async()=>Oy(s,n,r)}else throw new Error("Import candidate must have content or path or both")}}}function Dv(r){return r.content!=null}var vd=J(Ie(),1);var Hy=()=>async function*(e){for await(let t of e){if(t.length===void 0)throw(0,vd.default)(new Error("Content was invalid"),"ERR_INVALID_CONTENT");if(typeof t=="string"||t instanceof String)yield F(t.toString());else if(Array.isArray(t))yield Uint8Array.from(t);else if(t instanceof Uint8Array)yield t;else throw(0,vd.default)(new Error("Content was invalid"),"ERR_INVALID_CONTENT")}};var Pv=174;function ps(r){let e=r?.maxChildrenPerNode??Pv;return async function t(n,o){let i=[];for await(let s of fs(n,e))i.push(await o(s));return i.length>1?t(i,o):i[0]}}var cr=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}},ms=U.parse("QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn"),ys=U.parse("zdj7WbTaiJT1fgatdet9Ei9iDB5hdCxkbVyhyh8YTUnXMiwYi");var qn=class extends cr{_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?ys.bytes.byteLength:ms.bytes.byteLength));return this.nodeSize}async*flush(e){let t=[];for(let[c,u]of this._children.entries()){let l=u;if(u instanceof cr)for await(let f of u.flush(e))l=f,yield f;l.size!=null&&l.cid!=null&&t.push({Name:c,Tsize:Number(l.size),Hash:l.cid})}let n=new q({type:"directory",mtime:this.mtime,mode:this.mode}),o={Data:n.marshal(),Links:t},i=ne(Ae(o)),s=await jt(i,e,this.options),a=i.length+o.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 jc=J($y(),1);function Ov(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 G7=_n({name:"murmur3-32",code:35,encode:r=>Ov(jc.default.x86.hash32(r))}),Gn=_n({name:"murmur3-128",code:34,encode:r=>Jn.fromHex(jc.default.x64.hash128(r))}),W7=_n({name:"murmur3-x64-64",code:34,encode:r=>Jn.fromHex(jc.default.x64.hash128(r)).subarray(0,8)});var Gy=J(Yc(),1);var Et=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 Gy.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((o,i,s)=>(i!=null&&(i instanceof r?o.push(i.serialize(e,t)):o.push(e(i,s))),o),n))}async asyncTransform(e,t){return Wy(this,e,t)}toJSON(){return this.serialize(Mv,zv)}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"?F(e):e),n=await t.take(this._options.bits),o=this._children.get(n);return o instanceof r?o._findPlace(t):{bucket:this,pos:n,hash:t,existingChild:o}}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 o=await n._findPlace(t.existingChild.hash);return o.bucket._putAt(o,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(Hv);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 Hv(r){return!!r}function Mv(r,e){return r.key}function zv(r){return r}async function Wy(r,e,t){let n=[];for(let o of r._children.compactArray())if(o instanceof Et)await Wy(o,e,t);else{let i=await e(o);n.push({bitField:r._children.bitField(),children:i})}return t(n)}var $v=[255,254,252,248,240,224,192,128],Kv=[1,3,7,15,31,63,127,255],Xc=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 o=this._value[this._currentBytePos],i=this._currentBitPos+1,s=Math.min(i,t),a=qv(o,i-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 qv(r,e,t){let n=Gv(e,t);return(r&n)>>>e}function Gv(r,e){return $v[r]&Kv[Math.min(e+r-1,7)]}function jy(r){function e(t){return t instanceof Zc?t:new Zc(t,r)}return e}var Zc=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 o=this._buffers[this._currentBufferIndex],i=Math.min(o.availableBits(),t),s=o.take(i);n=(n<<i)+s,t-=i,this._availableBits-=i,o.availableBits()===0&&this._currentBufferIndex++}return n}untake(e){let t=e;for(;t>0;){let n=this._buffers[this._currentBufferIndex],o=Math.min(n.totalBits()-n.availableBits(),t);n.untake(o),t-=o,this._availableBits+=o,this._currentBufferIndex>0&&n.totalBits()===n.availableBits()&&(this._depth--,this._currentBufferIndex--)}}async _produceMoreBits(){this._depth++;let e=this._depth>0?ue([this._value,Uint8Array.from([this._depth])]):this._value,t=await this._hashFn(e),n=new Xc(t);this._buffers.push(n),this._availableBits+=n.availableBits()}};function Wo(r){if(r==null||r.hashFn==null)throw new Error("please define an options.hashFn");let e={bits:r.bits??8,hash:jy(r.hashFn)};return new Et(e)}async function Wv(r){return(await Gn.encode(r)).slice(0,8).reverse()}var Yy=BigInt(34),jv=8,Sd=class extends cr{_bucket;constructor(e,t){super(e,t),this._bucket=Wo({hashFn:Wv,bits:t.shardFanoutBits??jv})}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=Jy(this._bucket,this,this.options),this.nodeSize)}async*flush(e){for await(let t of Zy(this._bucket,e,this,this.options))yield{...t,path:this.path}}},Xy=Sd;async function*Zy(r,e,t,n){let o=r._children,i=(r.tableSize()-1).toString(16).length,s=[],a=0n;for(let p=0;p<o.length;p++){let h=o.get(p);if(h==null)continue;let y=p.toString(16).toUpperCase().padStart(i,"0");if(h instanceof Et){let g;for await(let x of Zy(h,e,null,n))g=x;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(Yv(h.value)){let g=h.value,x;for await(let _ of g.flush(e))x=_,yield x;if(x==null)throw new Error("Did not flush dir");let b=y+h.key;s.push({Name:b,Tsize:Number(x.size),Hash:x.cid}),a+=x.size}else{let g=h.value;if(g.cid==null)continue;let x=y+h.key,b=g.size;s.push({Name:x,Tsize:Number(b),Hash:g.cid}),a+=BigInt(b??0)}}let c=Uint8Array.from(o.bitField().reverse()),u=new q({type:"hamt-sharded-directory",data:c,fanout:BigInt(r.tableSize()),hashType:Yy,mtime:t?.mtime,mode:t?.mode}),l={Data:u.marshal(),Links:s},f=ne(Ae(l)),m=await jt(f,e,n),d=BigInt(f.byteLength)+a;yield{cid:m,unixfs:u,size:d}}function Yv(r){return typeof r.flush=="function"}function Jy(r,e,t){let n=r._children,o=(r.tableSize()-1).toString(16).length,i=[];for(let u=0;u<n.length;u++){let l=n.get(u);if(l==null)continue;let f=u.toString(16).toUpperCase().padStart(o,"0");if(l instanceof Et){let m=Jy(l,null,t);i.push({Name:f,Tsize:Number(m),Hash:t.cidVersion===0?ms:ys})}else if(typeof l.value.flush=="function"){let d=l.value.nodeSize();i.push({Name:f+l.key,Tsize:Number(d),Hash:t.cidVersion===0?ms:ys})}else{let m=l.value;if(m.cid==null)continue;let d=f+l.key,p=m.size;i.push({Name:d,Tsize:Number(p),Hash:m.cid})}}let s=Uint8Array.from(n.bitField().reverse()),a=new q({type:"hamt-sharded-directory",data:s,fanout:BigInt(r.tableSize()),hashType:Yy,mtime:e?.mtime,mode:e?.mode});return ne(Ae({Data:a.marshal(),Links:i})).length}async function _d(r,e,t,n){let o=e;e instanceof qn&&e.estimateNodeSize()>t&&(o=await Xv(e,n));let i=o.parent;if(i!=null){if(o!==e){if(r!=null&&(r.parent=o),o.parentKey==null)throw new Error("No parent key found");await i.put(o.parentKey,o)}return _d(o,i,t,n)}return o}async function Xv(r,e){let t=new Xy({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:o}of r.eachChildSeries())await t.put(n,o);return t}var Qy=(r="")=>r.split(/(?<!\\)\//).filter(Boolean);async function Zv(r,e,t){let n=Qy(r.path??""),o=n.length-1,i=e,s="";for(let a=0;a<n.length;a++){let c=n[a];s+=`${s!==""?"/":""}${c}`;let u=a===o;if(i.dirty=!0,i.cid=void 0,i.size=void 0,u)await i.put(c,r),e=await _d(null,i,t.shardSplitThresholdBytes,t);else{let l=await i.get(c);(l==null||!(l instanceof cr))&&(l=new qn({root:!1,dir:!0,parent:i,parentKey:c,path:s,dirty:!0,flat:!0,mtime:l?.unixfs?.mtime,mode:l?.unixfs?.mode},t)),await i.put(c,l),i=l}}return e}async function*eg(r,e){if(!(r instanceof cr)){r.unixfs?.isDirectory()===!0&&(yield r);return}yield*r.flush(e)}function tg(r){return async function*(t,n){let o=new qn({root:!0,dir:!0,path:"",dirty:!0,flat:!0},r),i,s=!1;for await(let a of t){if(a==null)continue;let c=`${a.originalPath??""}`.split("/")[0];c!=null&&c!==""&&(i==null?(i=c,s=!0):i!==c&&(s=!1)),o=await Zv(a,o,r),(a.unixfs==null||!a.unixfs.isDirectory())&&(yield a)}if(r.wrapWithDirectory||s&&o.childCount()>1)yield*eg(o,n);else for await(let a of o.eachChildSeries())a!=null&&(yield*eg(a.child,n))}}async function*mn(r,e,t={}){let n;Symbol.asyncIterator in r||Symbol.iterator in r?n=r:n=[r];let o=t.wrapWithDirectory??!1,i=t.shardSplitThresholdBytes??262144,s=t.shardFanoutBits??8,a=t.cidVersion??1,c=t.rawLeaves??!0,u=t.leafType??"file",l=t.fileImportConcurrency??50,f=t.blockWriteConcurrency??10,m=t.reduceSingleLeafToSelf??!0,d=t.chunker??hs(),p=t.chunkValidator??Hy(),h=t.dagBuilder??Vy({chunker:d,chunkValidator:p,wrapWithDirectory:o,layout:t.layout??ps(),bufferImporter:t.bufferImporter??Py({cidVersion:a,rawLeaves:c,leafType:u,onProgress:t.onProgress}),blockWriteConcurrency:f,reduceSingleLeafToSelf:m,cidVersion:a,onProgress:t.onProgress}),y=t.treeBuilder??tg({wrapWithDirectory:o,shardSplitThresholdBytes:i,shardFanoutBits:s,cidVersion:a,onProgress:t.onProgress});for await(let g of y(ds(h(n,e),l),e))yield{cid:g.cid,path:g.path,unixfs:g.unixfs,size:g.size}}async function Jc(r,e,t={}){let n=await Vn(mn([r],e,t));if(n==null)throw(0,Ad.default)(new Error("Nothing imported"),"ERR_INVALID_PARAMS");return n}async function rg(r,e,t={}){let n=await Vn(mn([r],e,t));if(n==null)throw(0,Ad.default)(new Error("Nothing imported"),"ERR_INVALID_PARAMS");return n}async function ng(r,e,t={}){return Jc({content:r},e,t)}async function og(r,e,t={}){return Jc({content:r},e,t)}var nS=J(Ie(),1),oS=J(gg(),1);var Es={cidVersion:1,rawLeaves:!0,layout:ps({maxChildrenPerNode:1024}),chunker:hs({chunkSize:1048576})};async function*wg(r,e,t={}){yield*mn(r,e,{...Es,...t})}async function bg(r,e,t={}){let{cid:n}=await ng(r,e,{...Es,...t});return n}async function xg(r,e,t={}){let{cid:n}=await og(r,e,{...Es,...t});return n}async function Eg(r,e,t={}){let{cid:n}=await Jc(r,e,{...Es,...t});return n}async function vg(r,e,t={}){let{cid:n}=await rg({...r,path:r.path??"-"},e,{...Es,...t});return n}var el=J(Ie(),1);function iS(r){return r[Symbol.asyncIterator]!=null}function sS(r){if(iS(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 yn=sS;var Vg=J(Ie(),1);var Sg=J(Ie(),1);function jo(r,e,t,n,o,i,s){let a=r,c=o;for(;i.length>0;){let u=i[0];if(u in a){i.shift(),c=`${c}/${u}`;let l=U.asCID(a[u]);if(l!=null)return{entry:{type:"object",name:n,path:o,cid:t,node:e,depth:s,size:BigInt(e.length),content:async function*(){yield r}},next:{cid:l,name:u,path:c,toResolve:i}};a=a[u]}else throw(0,Sg.default)(new Error(`No property named ${u} found in node ${t}`),"ERR_NO_PROP")}return{entry:{type:"object",name:n,path:o,cid:t,node:e,depth:s,size:BigInt(e.length),content:async function*(){yield r}}}}var aS=async(r,e,t,n,o,i,s,a)=>{let c=await s.get(r,a),u=Mn(c);return jo(u,c,r,e,t,n,i)},_g=aS;var cS=async(r,e,t,n,o,i,s,a)=>{let c=await s.get(r,a),u=Dc(c);return jo(u,c,r,e,t,n,i)},Ag=cS;var kg=J(Ie(),1);function lS(r,e,t,n){let o=BigInt(r.length),i=BigInt(e+o);return t>=i||n<e?new Uint8Array(0):(n>=e&&n<i&&(r=r.subarray(0,Number(n-e))),t>=e&&t<i&&(r=r.subarray(Number(t-e))),r)}var Wn=lS;var vs=J(Ie(),1),uS=(r,e=0,t=r)=>{let n=BigInt(r),o=BigInt(e??0),i=BigInt(t);if(i!==n&&(i=o+i),i>n&&(i=n),o<0n)throw(0,vs.default)(new Error("Offset must be greater than or equal to 0"),"ERR_INVALID_PARAMS");if(o>n)throw(0,vs.default)(new Error("Offset must be less than the file size"),"ERR_INVALID_PARAMS");if(i<0n)throw(0,vs.default)(new Error("Length must be greater than or equal to 0"),"ERR_INVALID_PARAMS");if(i>n)throw(0,vs.default)(new Error("Length must be less than the file size"),"ERR_INVALID_PARAMS");return{start:o,end:i}},Yo=uS;var fS=r=>{async function*e(t={}){let{start:n,end:o}=Yo(r.length,t.offset,t.length),i=Wn(r,0n,n,o);t.onProgress?.(new V("unixfs:exporter:progress:identity",{bytesRead:BigInt(i.byteLength),totalBytes:o-n,fileSize:BigInt(r.byteLength)})),yield i}return e},dS=async(r,e,t,n,o,i,s,a)=>{if(n.length>0)throw(0,kg.default)(new Error(`No link named ${t} found in raw node ${r}`),"ERR_NOT_FOUND");let c=Ze(r.multihash.bytes);return{entry:{type:"identity",name:e,path:t,cid:r,content:fS(c.digest),depth:i,size:BigInt(c.digest.length),node:c.digest}}},Ig=dS;var hS=async(r,e,t,n,o,i,s,a)=>{let c=await s.get(r,a),u=zh(c);return jo(u,c,r,e,t,n,i)},Bg=hS;var Rg=J(Ie(),1);var pS=r=>{async function*e(t={}){let{start:n,end:o}=Yo(r.length,t.offset,t.length),i=Wn(r,0n,n,o);t.onProgress?.(new V("unixfs:exporter:progress:raw",{bytesRead:BigInt(i.byteLength),totalBytes:o-n,fileSize:BigInt(r.byteLength)})),yield i}return e},mS=async(r,e,t,n,o,i,s,a)=>{if(n.length>0)throw(0,Rg.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:pS(c),depth:i,size:BigInt(c.length),node:c}}},Tg=mS;var _s=J(Ie(),1);var Ss=J(Ie(),1);var yS=async function(r){return(await Gn.encode(r)).slice(0,8).reverse()},gS=async(r,e,t)=>{let n=(e.tableSize()-1).toString(16).length;await Promise.all(r.map(async o=>{if(o.Name==null)throw new Error("Unexpected Link without a Name");if(o.Name.length===n){let i=parseInt(o.Name,16);e._putObjectAt(i,new Et({hash:t._options.hash,bits:t._options.bits},e,i));return}await t.put(o.Name.substring(2),!0)}))},Ng=(r,e)=>r.toString(16).toUpperCase().padStart(e,"0").substring(0,e),wS=r=>{let e=r.bucket,t=[];for(;e._parent!=null;)t.push(e),e=e._parent;return t.push(e),t.reverse()},Cg=async(r,e,t,n,o)=>{if(n==null){if(r.Data==null)throw(0,Ss.default)(new Error("no data in PBNode"),"ERR_NOT_UNIXFS");let f;try{f=q.unmarshal(r.Data)}catch(d){throw(0,Ss.default)(d,"ERR_NOT_UNIXFS")}if(f.type!=="hamt-sharded-directory")throw(0,Ss.default)(new Error("not a HAMT"),"ERR_NOT_UNIXFS");if(f.fanout==null)throw(0,Ss.default)(new Error("missing fanout"),"ERR_NOT_UNIXFS");let m=Wo({hashFn:yS,bits:Math.log2(Number(f.fanout))});n={rootBucket:m,hamtDepth:1,lastBucket:m}}let i=(n.lastBucket.tableSize()-1).toString(16).length;await gS(r.Links,n.lastBucket,n.rootBucket);let s=await n.rootBucket._findNewBucketAndPos(e),a=Ng(s.pos,i),c=wS(s);c.length>n.hamtDepth&&(n.lastBucket=c[n.hamtDepth],a=Ng(n.lastBucket._posAtParent,i));let u=r.Links.find(f=>{if(f.Name==null)return!1;let m=f.Name.substring(0,i),d=f.Name.substring(i);return!(m!==a||d!==""&&d!==e)});if(u==null)return;if(u.Name!=null&&u.Name.substring(i)===e)return u.Hash;n.hamtDepth++;let l=await t.get(u.Hash,o);return r=be(l),Cg(r,e,t,n,o)},Lg=Cg;var bS=(r,e,t,n,o,i,s)=>{async function*a(c={}){let u=c.offset??0,l=c.length??e.Links.length,f=e.Links.slice(u,l);c.onProgress?.(new V("unixfs:exporter:walk:directory",{cid:r})),yield*at(f,m=>We(m,d=>async()=>{let p=d.Name??"",h=`${n}/${p}`;return(await o(d.Hash,p,h,[],i+1,s,c)).entry}),m=>$n(m,{ordered:!0,concurrency:c.blockReadConcurrency}),m=>dt(m,d=>d!=null))}return a},Dg=bS;var jn=J(Ie(),1);async function Pg(r,e,t,n,o,i,s){if(e instanceof Uint8Array){let u=Wn(e,n,o,i);t.push(u);return}if(e.Data==null)throw(0,jn.default)(new Error("no data in PBNode"),"ERR_NOT_UNIXFS");let a;try{a=q.unmarshal(e.Data)}catch(u){throw(0,jn.default)(u,"ERR_NOT_UNIXFS")}if(a.data!=null){let u=a.data,l=Wn(u,n,o,i);t.push(l),n+=BigInt(l.byteLength)}let c=[];if(e.Links.length!==a.blockSizes.length)throw(0,jn.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],f=n,m=f+a.blockSizes[u];if((o>=f&&o<m||i>=f&&i<=m||o<f&&i>m)&&c.push({link:l,blockStart:n}),n=m,n>i)break}await at(c,u=>We(u,l=>async()=>{let f=await r.get(l.link.Hash,s);return{...l,block:f}}),u=>$n(u,{ordered:!0,concurrency:s.blockReadConcurrency}),async u=>{for await(let{link:l,block:f,blockStart:m}of u){let d;switch(l.Hash.code){case ye:d=be(f);break;case ge:d=f;break;default:t.end((0,jn.default)(new Error(`Unsupported codec: ${l.Hash.code}`),"ERR_NOT_UNIXFS"));return}let p=new ut({concurrency:1});p.on("error",h=>{t.end(h)}),p.add(async()=>{s.onProgress?.(new V("unixfs:exporter:walk:file",{cid:l.Hash})),await Pg(r,d,t,m,o,i,s)}),await p.onIdle()}}),n>=i&&t.end()}var xS=(r,e,t,n,o,i,s)=>{async function*a(c={}){let u=t.fileSize();if(u===void 0)throw new Error("File was a directory");let{start:l,end:f}=Yo(u,c.offset,c.length);if(f===0n)return;let m=0n,d=f-l,p=Tt();c.onProgress?.(new V("unixfs:exporter:walk:file",{cid:r})),Pg(s,e,p,0n,l,f,c).catch(h=>{p.end(h)});for await(let h of p)if(h!=null){if(m+=BigInt(h.byteLength),m>d)throw p.end(),(0,jn.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");m===d&&p.end(),c.onProgress?.(new V("unixfs:exporter:progress:unixfs:file",{bytesRead:m,totalBytes:d,fileSize:u})),yield h}if(m<d)throw(0,jn.default)(new Error("Traversed entire DAG but did not read enough bytes"),"ERR_UNDER_READ")}return a},Td=xS;var Qc=J(Ie(),1);var ES=(r,e,t,n,o,i,s)=>{function a(c={}){return c.onProgress?.(new V("unixfs:exporter:walk:hamt-sharded-directory",{cid:r})),Og(e,n,o,i,s,c)}return a};async function*Og(r,e,t,n,o,i){let s=r.Links;if(r.Data==null)throw(0,Qc.default)(new Error("no data in PBNode"),"ERR_NOT_UNIXFS");let a;try{a=q.unmarshal(r.Data)}catch(l){throw(0,Qc.default)(l,"ERR_NOT_UNIXFS")}if(a.fanout==null)throw(0,Qc.default)(new Error("missing fanout"),"ERR_NOT_UNIXFS");let c=(a.fanout-1n).toString(16).length,u=at(s,l=>We(l,f=>async()=>{let m=f.Name!=null?f.Name.substring(c):null;if(m!=null&&m!==""){let d=await t(f.Hash,m,`${e}/${m}`,[],n+1,o,i);return{entries:d.entry==null?[]:[d.entry]}}else{let d=await o.get(f.Hash,i);return r=be(d),i.onProgress?.(new V("unixfs:exporter:walk:hamt-sharded-directory",{cid:f.Hash})),{entries:Og(r,e,t,n,o,i)}}}),l=>$n(l,{ordered:!0,concurrency:i.blockReadConcurrency}));for await(let{entries:l}of u)yield*l}var Ug=ES;var vS=(r,e)=>r.Links.find(n=>n.Name===e)?.Hash,SS={raw:Td,file:Td,directory:Dg,"hamt-sharded-directory":Ug,metadata:(r,e,t,n,o,i,s)=>()=>[],symlink:(r,e,t,n,o,i,s)=>()=>[]},_S=async(r,e,t,n,o,i,s,a)=>{let c=await s.get(r,a),u=be(c),l,f;if(e==null&&(e=r.toString()),u.Data==null)throw(0,_s.default)(new Error("no data in PBNode"),"ERR_NOT_UNIXFS");try{l=q.unmarshal(u.Data)}catch(d){throw(0,_s.default)(d,"ERR_NOT_UNIXFS")}if(t==null&&(t=e),n.length>0){let d;if(l?.type==="hamt-sharded-directory"?d=await Lg(u,n[0],s):d=vS(u,n[0]),d==null)throw(0,_s.default)(new Error("file does not exist"),"ERR_NOT_FOUND");let p=n.shift(),h=`${t}/${p}`;f={cid:d,toResolve:n,name:p??"",path:h}}let m=SS[l.type](r,u,l,t,o,i,s);if(m==null)throw(0,_s.default)(new Error("could not find content exporter"),"ERR_NOT_FOUND");return l.isDirectory()?{entry:{type:"directory",name:e,path:t,cid:r,content:m,unixfs:l,depth:i,node:u,size:l.fileSize()},next:f}:{entry:{type:"file",name:e,path:t,cid:r,content:m,unixfs:l,depth:i,node:u,size:l.fileSize()},next:f}},Fg=_S;var AS={[ye]:Fg,[ge]:Tg,[ln]:_g,[fn]:Ag,[Ge.code]:Ig,[$r]:Bg},Hg=async(r,e,t,n,o,i,s)=>{let a=AS[r.code];if(a==null)throw(0,Vg.default)(new Error(`No resolver for code ${r.code}`),"ERR_NO_RESOLVER");return a(r,e,t,n,Hg,o,i,s)},Mg=Hg;var kS=(r="")=>(r.trim().match(/([^\\^/]|\\\/)+/g)??[]).filter(Boolean),IS=r=>{if(r instanceof Uint8Array)return{cid:U.decode(r),toResolve:[]};let e=U.asCID(r);if(e!=null)return{cid:e,toResolve:[]};if(typeof r=="string"){r.indexOf("/ipfs/")===0&&(r=r.substring(6));let t=kS(r);return{cid:U.parse(t[0]),toResolve:t.slice(1)}}throw(0,el.default)(new Error(`Unknown path type ${r}`),"ERR_BAD_PATH")};async function*As(r,e,t={}){let{cid:n,toResolve:o}=IS(r),i=n.toString(),s=i,a=o.length;for(;;){let c=await Mg(n,i,s,o,a,e,t);if(c.entry==null&&c.next==null)throw(0,el.default)(new Error(`Could not resolve ${r}`),"ERR_NOT_FOUND");if(c.entry!=null&&(yield c.entry),c.next==null)return;o=c.next.toResolve,n=c.next.cid,i=c.next.name,s=c.next.path}}async function ze(r,e,t={}){let n=await yn(As(r,e,t));if(n==null)throw(0,el.default)(new Error(`Could not resolve ${r}`),"ERR_NOT_FOUND");return n}async function*Xo(r,e,t={}){let n=await ze(r,e,t);if(n==null)return;if(yield n,n.type==="directory")for await(let i of o(n,t))yield i;async function*o(i,s){for await(let a of i.content(s))yield a,!(a instanceof Uint8Array)&&a.type==="directory"&&(yield*o(a,s))}}var Xg=J(Yg(),1),Xe=Xg.default;var Yt=class extends Error{name;code;constructor(e,t,n){super(e),this.name=t,this.code=n}},lr=class extends Yt{constructor(e="not a Unixfs node"){super(e,"NotUnixFSError","ERR_NOT_UNIXFS")}},ot=class extends Yt{constructor(e="invalid PBNode"){super(e,"InvalidPBNodeError","ERR_INVALID_PBNODE")}},Pr=class extends Yt{constructor(e="unknown error"){super(e,"InvalidPBNodeError","ERR_UNKNOWN_ERROR")}},ks=class extends Yt{constructor(e="path already exists"){super(e,"AlreadyExistsError","ERR_ALREADY_EXISTS")}},nl=class extends Yt{constructor(e="path does not exist"){super(e,"DoesNotExistError","ERR_DOES_NOT_EXIST")}},Qo=class extends Yt{constructor(e="no content"){super(e,"NoContentError","ERR_NO_CONTENT")}},ol=class extends Yt{constructor(e="not a file"){super(e,"NotAFileError","ERR_NOT_A_FILE")}},gn=class extends Yt{constructor(e="not a directory"){super(e,"NotADirectoryError","ERR_NOT_A_DIRECTORY")}},vt=class extends Yt{constructor(e="invalid parameters"){super(e,"InvalidParametersError","ERR_INVALID_PARAMETERS")}};var Pd=J(Yc(),1);function sl(r){function e(t){return t instanceof il?t:new il(t,r)}return e}var il=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 o=this._buffers[this._currentBufferIndex],i=Math.min(o.availableBits(),t),s=o.take(i);n=(n<<i)+s,t-=i,this._availableBits-=i,o.availableBits()===0&&this._currentBufferIndex++}return n}untake(e){let t=e;for(;t>0;){let n=this._buffers[this._currentBufferIndex],o=Math.min(n.totalBits()-n.availableBits(),t);n.untake(o),t-=o,this._availableBits+=o,this._currentBufferIndex>0&&n.totalBits()===n.availableBits()&&(this._depth--,this._currentBufferIndex--)}}async _produceMoreBits(){this._depth++;let e=this._depth>0?ue([this._value,Uint8Array.from([this._depth])]):this._value,t=await this._hashFn(e),n=new Cd(t);this._buffers.push(n),this._availableBits+=n.availableBits()}},LS=[255,254,252,248,240,224,192,128],DS=[1,3,7,15,31,63,127,255],Cd=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 o=this._value[this._currentBytePos],i=this._currentBitPos+1,s=Math.min(i,t),a=PS(o,i-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=OS(e,t);return(r&n)>>>e}function OS(r,e){return LS[r]&DS[Math.min(e+r-1,7)]}var Is=BigInt(Gn.code),Yn=8;async function ei(r){return(await Gn.encode(r)).subarray(0,8).reverse()}var Qg=J(Yc(),1);var Xt=async(r,e,t)=>{t.codec==null&&(t.codec=Ne);let n=await ae.digest(r),o=U.create(t.cidVersion,t.codec.code,n);return await e.put(o,r,{...t,signal:t.signal}),o};var Ld=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}},al=class extends Ld{_bucket;constructor(e,t){super(e,t),this._bucket=Wo({hashFn:ei,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=Jg(this._bucket,this,this.options),this.nodeSize)}async*flush(e){for await(let t of Zg(this._bucket,e,this,this.options))yield{...t,path:this.path}}};async function*Zg(r,e,t,n){let o=r._children,i=[],s=0n;for(let d=0;d<o.length;d++){let p=o.get(d);if(p==null)continue;let h=d.toString(16).toUpperCase().padStart(2,"0");if(p instanceof Et){let y;for await(let g of Zg(p,e,null,n))y=g;if(y==null)throw new Error("Could not flush sharded directory, no subshard found");i.push({Name:h,Tsize:Number(y.size),Hash:y.cid}),s+=y.size}else if(US(p.value)){let y=p.value,g;for await(let b of y.flush(e))g=b,yield g;if(g==null)throw new Error("Did not flush dir");let x=h+p.key;i.push({Name:x,Tsize:Number(g.size),Hash:g.cid}),s+=g.size}else{let y=p.value;if(y.cid==null)continue;let g=h+p.key,x=y.size;i.push({Name:g,Tsize:Number(x),Hash:y.cid}),s+=BigInt(x??0)}}let a=Uint8Array.from(o.bitField().reverse()),c=new q({type:"hamt-sharded-directory",data:a,fanout:BigInt(r.tableSize()),hashType:Is,mtime:t?.mtime,mode:t?.mode}),u={Data:c.marshal(),Links:i},l=ne(Ae(u)),f=await Xt(l,e,n),m=BigInt(l.byteLength)+s;yield{cid:f,unixfs:c,size:m}}function US(r){return typeof r.flush=="function"}function Jg(r,e,t){let n=r._children,o=[];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 Et){let f=Jg(u,null,t);o.push({Name:l,Tsize:Number(f),Hash:t.cidVersion===0?cl:ll})}else if(typeof u.value.flush=="function"){let m=u.value.nodeSize();o.push({Name:l+u.key,Tsize:Number(m),Hash:t.cidVersion===0?cl:ll})}else{let f=u.value;if(f.cid==null)continue;let m=l+u.key,d=f.size;o.push({Name:m,Tsize:Number(d),Hash:f.cid})}}let i=Uint8Array.from(n.bitField().reverse()),s=new q({type:"hamt-sharded-directory",data:i,fanout:BigInt(r.tableSize()),hashType:Is,mtime:e?.mtime,mode:e?.mode});return ne(Ae({Data:s.marshal(),Links:o})).length}var cl=U.parse("QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn"),ll=U.parse("zdj7WbTaiJT1fgatdet9Ei9iDB5hdCxkbVyhyh8YTUnXMiwYi");var Dd=ee("helia:unixfs:commands:utils:hamt-utils"),ul=r=>r.toString(16).toUpperCase().padStart(2,"0").substring(0,2),ew=async(r,e,t)=>{let n=new al({root:!0,dir:!0,parent:void 0,parentKey:void 0,path:"",dirty:!0,flat:!1,mtime:t.mtime,mode:t.mode},t);for(let i=0;i<e.length;i++)await n._bucket.put(e[i].name,{size:e[i].size,cid:e[i].cid});let o=await yn(n.flush(r));if(o==null)throw new Error("Flushing shard yielded no result");return o},fl=async(r,e,t)=>{let n=q.unmarshal(r[0].node.Data??new Uint8Array(0)),o=BigInt(Math.pow(2,Yn));r.reverse();let i,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()),f=new q({type:"hamt-sharded-directory",data:l,fanout:o,hashType:Is});c&&(f.mtime=n.mtime,f.mode=n.mode),s={Data:f.marshal(),Links:u.node.Links};let m=ne(Ae(s));if(i=await Xt(m,e,t),!c){let d=r[a+1];if(d==null)throw new Error("Was not operating on shard root but also had no parent?");Dd("updating link in parent sub-shard with prefix %s",d.prefix),d.node.Links=d.node.Links.filter(p=>p.Name!==d.prefix),d.node.Links.push({Name:d.prefix,Hash:i,Tsize:u.node.Links.reduce((p,h)=>p+(h.Tsize??0),m.byteLength)})}}if(i==null||s==null)throw new Error("Noting persisted");return{cid:i,node:s}},dl=async(r,e,t,n)=>{let i=sl(ei)(F(e)),s=[];for(;;){let a=await t.get(r,n),c=be(a),u=new Qg.default,l=await i.take(Yn),f=ul(l);s.push({prefix:f,children:u,node:c});let m;for(let p of c.Links){let h=p.Name??"";if(h.length<2)throw new Error("Invalid HAMT - link name was too short");let y=parseInt(h.substring(0,2),16);u.set(y,!0),h.startsWith(f)&&(m=p)}if(m==null){Dd("no link found with prefix %s for %s",f,e);break}let d=m.Name??"";if(d.length<2)throw new Error("Invalid HAMT - link name was too short");if(d.length===2){r=m.Hash,Dd("descend into sub-shard with prefix %s",d);continue}break}return{path:s,hash:i}};async function hl(r,e,t,n){if(r.Data==null)throw new Error("DagPB node had no data");let o=q.unmarshal(r.Data),i;if(o.type==="directory")i=FS(r);else if(o.type==="hamt-sharded-directory")i=await tw(r,0,t,e,n);else throw new Error("Can only estimate the size of directories or shards");return i>t}function FS(r){let e=0;for(let t of r.Links)e+=(t.Name??"").length,e+=t.Hash.version===1?ll.bytes.byteLength:cl.bytes.byteLength;return e}async function tw(r,e,t,n,o){if(e>t)return t;if(r.Data==null||!q.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===ye){let c=await n.get(s.Hash,o),u=be(c);e+=await tw(u,e,t,n,o)}}return e}var ur=ee("helia:unixfs:components:utils:add-link");async function ti(r,e,t,n){if(r.node.Data==null)throw new vt("Invalid parent passed to addLink");if(q.unmarshal(r.node.Data).type==="hamt-sharded-directory")return ur("adding link to sharded directory"),MS(r,e,t,n);ur(`adding ${e.Name} (${e.Hash}) to regular directory`);let i=await HS(r,e,t,n);if(await hl(i.node,t,n.shardSplitThresholdBytes,n)){ur("converting directory to sharded directory");let s=await VS(i,t);i.cid=s.cid,i.node=be(await t.get(s.cid,n))}return i}var VS=async(r,e)=>{if(r.node.Data==null)throw new vt("Invalid parent passed to convertToShardedDirectory");let t=q.unmarshal(r.node.Data),n=await ew(e,r.node.Links.map(o=>({name:o.Name??"",size:BigInt(o.Tsize??0),cid:o.Hash})),{mode:t.mode,mtime:t.mtime,cidVersion:r.cid.version});return ur(`converted directory to sharded directory ${n.cid}`),n},HS=async(r,e,t,n)=>{let o=r.node.Links.filter(l=>{let f=l.Name===e.Name;if(f&&!n.allowOverwriting)throw new ks;return!f});if(o.push(e),r.node.Data==null)throw new ot("Parent node with no data passed to addToDirectory");let i=q.unmarshal(r.node.Data),s;if(i.mtime!=null){let l=Date.now(),f=Math.floor(l/1e3);i.mtime={secs:BigInt(f),nsecs:(l-f*1e3)*1e3},s=i.marshal()}else s=r.node.Data;r.node=Ae({Data:s,Links:o});let a=ne(r.node),c=await ae.digest(a),u=U.create(r.cid.version,ye,c);return await t.put(u,a),{node:r.node,cid:u}},MS=async(r,e,t,n)=>{let{path:o,hash:i}=await dl(r.cid,e.Name,t,n),s=o[o.length-1];if(s==null)throw new Error("Invalid HAMT, could not generate path");let a=s.prefix,c=parseInt(a,16);ur("next prefix for %s is %s",e.Name,a);let u=`${a}${e.Name}`,l=s.node.Links.find(f=>(f.Name??"").startsWith(a));if(l!=null)if(ur("link %s was present in shard",u),l.Name===u){if(!n.allowOverwriting)throw new ks;ur("overwriting %s in subshard",e.Name),s.node.Links=s.node.Links.filter(f=>f.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?!");{ur("prefix %s already exists, creating new subshard",a);let f=s.node.Links.findIndex(y=>y.Name?.startsWith(a)),m=s.node.Links.splice(f,1)[0],d=(m.Name??"").substring(2),h=sl(ei)(F(d));for(let y=0;y<o.length;y++)await h.take(Yn);for(;;){let y=await h.take(Yn),g=ul(y);m.Name=`${g}${d}`;let x=await i.take(Yn),b=ul(x);if(g===b){let A=new Pd.default;A.set(x,!0),o.push({prefix:b,children:A,node:{Links:[]}});continue}let _=new Pd.default;_.set(x,!0),_.set(y,!0),o.push({prefix:a,children:_,node:{Links:[m,{Name:`${b}${e.Name}`,Hash:e.Hash,Tsize:e.Tsize}]}});break}}}else ur("link %s was not present in sub-shard",u),e.Name=u,s.node.Links.push(e),s.children.set(c,!0),ur("adding %s to existing sub-shard",u);return fl(o,t,n)};async function wn(r,e,t={}){let n=await ze(r,e,t);if(n.type!=="directory")throw new gn(`${r.toString()} was not a UnixFS directory`);return{cid:r,node:n.node}}async function ri(r,e,t,n){let o=await ze(r,t,n);if(o.type!=="directory"&&o.type!=="file"&&o.type!=="raw")throw new lr(`${r.toString()} was not a UnixFS node`);return{Name:e,Tsize:o.node instanceof Uint8Array?o.node.byteLength:zS(o.node),Hash:r}}function zS(r){let e=r.Links.reduce((t,n)=>t+(n.Tsize??0),0);return ne(r).byteLength+e}var $S=ee("helia:unixfs:components:utils:resolve");async function fr(r,e,t,n){if(e==null||e==="")return{cid:r};let o=`/ipfs/${r}${e==null?"":`/${e}`}`,i=await Go(As(o,t,n));if(i.length===0)throw new nl("Could not find path in directory");return $S("resolved %s to %c",e,r),{cid:i[i.length-1].cid,path:e,segments:i}}async function ni(r,e,t,n){if(e.segments==null||e.segments.length===0)return r;let o=e.segments.pop();if(o==null)throw new Error("Insufficient segments");o.cid=r,e.segments.reverse();for(let i of e.segments){let[s,a]=await Promise.all([wn(i.cid,t,n),ri(o.cid,o.name,t,n)]);r=(await ti(s,a,t,{...n,allowOverwriting:!0,cidVersion:r.version})).cid,i.cid=r,o=i}return r}var KS=Xe.bind({ignoreUndefined:!0}),qS={};async function*rw(r,e,t={}){let n=KS(qS,t),o=await fr(r,n.path,e,n),i=await ze(o.cid,e,n);if(i.type!=="file"&&i.type!=="raw")throw new ol;if(i.content==null)throw new Qo;yield*i.content(n)}var GS=Xe.bind({ignoreUndefined:!0}),WS=ee("helia:unixfs:chmod"),jS={recursive:!1,shardSplitThresholdBytes:262144};async function nw(r,e,t,n={}){let o=GS(jS,n),i=await fr(r,o.path,t,n);if(WS("chmod %c %d",i.cid,e),o.recursive){let m=await at(async function*(){for await(let d of Xo(i.cid,t,n)){let p,h=[];if(d.type==="raw")p=new q({type:"file",data:d.node});else if(d.type==="file"||d.type==="directory")p=d.unixfs,h=d.node.Links;else throw new lr;p.mode=e;let y={Data:p.marshal(),Links:h};yield{path:d.path,content:y}}},d=>mn(d,t,{...o,dagBuilder:async function*(p,h){for await(let y of p)yield async function(){let g=y.content,x=ne(g),b=await Xt(x,h,{...o,cidVersion:r.version});if(g.Data==null)throw new ot(`${b} had no data`);let _=q.unmarshal(g.Data);return{cid:b,size:BigInt(x.length),path:y.path,unixfs:_}}}}),async d=>yn(d));if(m==null)throw new Pr(`Could not chmod ${i.cid.toString()}`);return ni(m.cid,i,t,o)}let s=await t.get(i.cid,n),a,c=[];if(i.cid.code===ge)a=new q({type:"file",data:s});else{let m=be(s);if(m.Data==null)throw new ot(`${i.cid.toString()} had no data`);c=m.Links,a=q.unmarshal(m.Data)}a.mode=e;let u=ne({Data:a.marshal(),Links:c}),l=await ae.digest(u),f=U.create(i.cid.version,ye,l);return await t.put(f,u),ni(f,i,t,o)}var YS=Xe.bind({ignoreUndefined:!0}),XS=ee("helia:unixfs:cp"),ZS={force:!1,shardSplitThresholdBytes:262144};async function ow(r,e,t,n,o={}){let i=YS(ZS,o);if(t.includes("/"))throw new vt("Name must not have slashes");let[s,a]=await Promise.all([wn(e,n,i),ri(r,t,n,i)]);return XS('Adding %c as "%s" to %c',r,t,e),(await ti(s,a,n,{allowOverwriting:i.force,cidVersion:e.version,...i})).cid}var JS=Xe.bind({ignoreUndefined:!0}),QS={};async function*iw(r,e,t={}){let n=JS(QS,t),o=await fr(r,n.path,e,n),i=await ze(o.cid,e);if(i.type==="file"||i.type==="raw"){yield i;return}if(i.content==null)throw new Qo;if(i.type!=="directory")throw new gn;yield*i.content({offset:t.offset,length:t.length})}var e_=Xe.bind({ignoreUndefined:!0}),sw=ee("helia:unixfs:mkdir"),t_={cidVersion:1,force:!1,shardSplitThresholdBytes:262144};async function aw(r,e,t,n={}){let o=e_(t_,n);if(e.includes("/"))throw new vt("Path must not have slashes");if((await ze(r,t,n)).type!=="directory")throw new gn(`${r.toString()} was not a UnixFS directory`);sw("creating %s",e);let a={Data:new q({type:"directory",mode:o.mode,mtime:o.mtime}).marshal(),Links:[]},c=ne(a),u=await ae.digest(c),l=U.create(o.cidVersion,ye,u);await t.put(l,c);let[f,m]=await Promise.all([wn(r,t,o),ri(l,e,t,o)]);return sw("adding empty dir called %s to %c",e,r),(await ti(f,m,t,{...o,allowOverwriting:o.force})).cid}var pl=ee("helia:unixfs:utils:remove-link");async function cw(r,e,t,n){if(r.node.Data==null)throw new ot("Parent node had no data");if(q.unmarshal(r.node.Data).type==="hamt-sharded-directory"){pl(`removing ${e} from sharded directory`);let i=await n_(r,e,t,n);return await hl(i.node,t,n.shardSplitThresholdBytes,n)?i:(pl("converting shard to flat directory %c",r.cid),o_(i,t,n))}return pl(`removing link ${e} regular directory`),r_(r,e,t,n)}var r_=async(r,e,t,n)=>{r.node.Links=r.node.Links.filter(s=>s.Name!==e);let o=ne(r.node),i=await Xt(o,t,{...n,cidVersion:r.cid.version});return pl(`Updated regular directory ${i}`),{node:r.node,cid:i}},n_=async(r,e,t,n)=>{let{path:o}=await dl(r.cid,e,t,n),i=o[o.length-1];if(i==null)throw new Error("Invalid HAMT, could not generate path");let s=i.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(i.node.Links=i.node.Links.filter(u=>u.Name!==s),i.children.unset(c),i.node.Links.length===1)for(;o.length!==1;){let u=o[o.length-1];if(u==null||u.node.Links.length>1)break;o.pop();let l=o[o.length-1];if(l==null)break;let f=u.node.Links[0];l.node.Links=l.node.Links.filter(m=>!(m.Name??"").startsWith(l.prefix)),l.node.Links.push({Hash:f.Hash,Name:`${l.prefix}${(f.Name??"").substring(2)}`,Tsize:f.Tsize})}return fl(o,t,n)},o_=async(r,e,t)=>{if(r.node.Data==null)throw new vt("Invalid parent passed to convertToFlatDirectory");let n={Links:[]},o=await ze(r.cid,e);if(o.type!=="directory")throw new Error("Unexpected node type");for await(let c of o.content()){let u=0;c.node instanceof Uint8Array?u=c.node.byteLength:u=ne(c.node).length,n.Links.push({Hash:c.cid,Name:c.name,Tsize:u})}let i=q.unmarshal(r.node.Data);n.Data=new q({type:"directory",mode:i.mode,mtime:i.mtime}).marshal();let s=ne(Ae(n));return{cid:await Xt(s,e,{codec:Ne,cidVersion:r.cid.version,signal:t.signal}),node:n}};var i_=Xe.bind({ignoreUndefined:!0}),s_=ee("helia:unixfs:rm"),a_={shardSplitThresholdBytes:262144};async function lw(r,e,t,n={}){let o=i_(a_,n);if(e.includes("/"))throw new vt("Name must not have slashes");let i=await wn(r,t,o);return s_("Removing %s from %c",e,r),(await cw(i,e,t,{...o,cidVersion:r.version})).cid}var c_=Xe.bind({ignoreUndefined:!0}),l_=ee("helia:unixfs:stat"),u_={};async function uw(r,e,t={}){let n=c_(u_,t),o=await fr(r,t.path,e,n);l_("stat %c",o.cid);let i=await ze(o.cid,e,n);if(i.type!=="file"&&i.type!=="directory"&&i.type!=="raw")throw new lr;let s=0n,a=0n,c=0n,u=0n,l=0,f,m,d=i.type,p;if(i.type==="raw"&&(s=BigInt(i.node.byteLength),a=BigInt(i.node.byteLength),c=BigInt(i.node.byteLength),u=BigInt(i.node.byteLength),l=1),i.type==="directory"&&(s=0n,a=BigInt(i.unixfs.marshal().byteLength),c=0n,u=a,l=1,f=i.unixfs.mode,m=i.unixfs.mtime,p=i.unixfs),i.type==="file"){let h=await fw(o.cid,e,n);s=i.unixfs.fileSize(),a=BigInt((i.node.Data?.byteLength??0)+i.node.Links.reduce((y,g)=>y+(g.Tsize??0),0)),c=BigInt(h.localFileSize),u=BigInt(h.localDagSize),l=h.blocks,f=i.unixfs.mode,m=i.unixfs.mtime,p=i.unixfs}return{cid:o.cid,mode:f,mtime:m,fileSize:s,dagSize:a,localFileSize:c,localDagSize:u,blocks:l,type:d,unixfs:p}}async function fw(r,e,t){let n={localFileSize:0,localDagSize:0,blocks:0};if(await e.has(r,t)){let o=await e.get(r,t);if(n.blocks++,n.localDagSize+=o.byteLength,r.code===ge)n.localFileSize+=o.byteLength;else if(r.code===ye){let i=be(o);if(i.Links.length>0)for(let s of i.Links){let a=await fw(s.Hash,e,t);n.localFileSize+=a.localFileSize,n.localDagSize+=a.localDagSize,n.blocks+=a.blocks}else{if(i.Data==null)throw new ot(`PBNode ${r.toString()} had no data`);let s=q.unmarshal(i.Data);if(s.data==null)throw new ot(`UnixFS node ${r.toString()} had no data`);n.localFileSize+=s.data.byteLength??0}}else throw new Pr(`${r.toString()} was neither DAG_PB nor RAW`)}return n}var f_=Xe.bind({ignoreUndefined:!0}),d_=ee("helia:unixfs:touch"),h_={recursive:!1,shardSplitThresholdBytes:262144};async function dw(r,e,t={}){let n=f_(h_,t),o=await fr(r,n.path,e,n),i=n.mtime??{secs:BigInt(Math.round(Date.now()/1e3)),nsecs:0};if(d_("touch %c %o",o.cid,i),n.recursive){let m=await at(async function*(){for await(let d of Xo(o.cid,e)){let p,h;if(d.type==="raw")p=new q({data:d.node}),h=[];else if(d.type==="file"||d.type==="directory")p=d.unixfs,h=d.node.Links;else throw new lr;p.mtime=i;let y={Data:p.marshal(),Links:h};yield{path:d.path,content:y}}},d=>mn(d,e,{...n,dagBuilder:async function*(p,h){for await(let y of p)yield async function(){let g=y.content,x=ne(g),b=await Xt(x,h,{...n,cidVersion:r.version});if(g.Data==null)throw new ot(`${b} had no data`);let _=q.unmarshal(g.Data);return{cid:b,size:BigInt(x.length),path:y.path,unixfs:_}}}}),async d=>yn(d));if(m==null)throw new Pr(`Could not chmod ${o.cid.toString()}`);return ni(m.cid,o,e,n)}let s=await e.get(o.cid,t),a,c=[];if(o.cid.code===ge)a=new q({data:s});else{let m=be(s);if(c=m.Links,m.Data==null)throw new ot(`${o.cid.toString()} had no data`);a=q.unmarshal(m.Data)}a.mtime=i;let u=ne({Data:a.marshal(),Links:c}),l=await ae.digest(u),f=U.create(o.cid.version,ye,l);return await e.put(f,u),ni(f,o,e,n)}var Od=class{components;constructor(e){this.components=e}async*addAll(e,t={}){yield*wg(e,this.components.blockstore,t)}async addBytes(e,t={}){return bg(e,this.components.blockstore,t)}async addByteStream(e,t={}){return xg(e,this.components.blockstore,t)}async addFile(e,t={}){return Eg(e,this.components.blockstore,t)}async addDirectory(e={},t={}){return vg(e,this.components.blockstore,t)}async*cat(e,t={}){yield*rw(e,this.components.blockstore,t)}async chmod(e,t,n={}){return nw(e,t,this.components.blockstore,n)}async cp(e,t,n,o={}){return ow(e,t,n,this.components.blockstore,o)}async*ls(e,t={}){yield*iw(e,this.components.blockstore,t)}async mkdir(e,t,n={}){return aw(e,t,this.components.blockstore,n)}async rm(e,t,n={}){return lw(e,t,this.components.blockstore,n)}async stat(e,t={}){return uw(e,this.components.blockstore,t)}async touch(e,t={}){return dw(e,this.components.blockstore,t)}};function hw(r){return new Od(r)}function ml(r,e={}){let t={_cancelled:!1,async start(){this._cancelled=!1},async pull(n){try{let{value:o,done:i}=await r.next();if(this._cancelled)return;if(i===!0){n.close();return}n.enqueue(o)}catch(o){n.error(o)}},cancel(){this._cancelled=!0}};return new globalThis.ReadableStream(t,e)}function pw(r,e){if(r==null)return;if(r instanceof Headers)return r.get(e)??void 0;if(Array.isArray(r))return r.find(([o])=>o.toLowerCase()===e.toLowerCase())?.[1];let t=Object.keys(r).find(n=>n.toLowerCase()===e.toLowerCase());if(t!=null)return r[t]}function mw(r,e,t){if((r??0)>(e??1/0))throw new Error("Invalid range: Range-start index is greater than range-end index.");if(r!=null&&(e??0)>=(t??1/0))throw new Error("Invalid range: Range-end index is greater than or equal to the size of the file.");if(r==null&&(e??0)>(t??1/0))throw new Error("Invalid range: Range-end index is greater than the size of the file.");if(r!=null&&r<0)throw new Error("Invalid range: Range-start index cannot be negative.");if(r!=null&&e!=null)return{byteSize:e-r+1,start:r,end:e};if(r==null&&e!=null)return t==null?{end:e}:e===t?{byteSize:t,start:0,end:t-1}:{byteSize:e,start:t-e,end:t-1};if(r!=null&&e==null){if(t==null)return{start:r};let n=t-1;return{byteSize:t-r,start:r,end:n}}return{byteSize:t,start:0,end:t!=null?t-1:0}}function yw({byteStart:r,byteEnd:e,byteSize:t}){let n=t??"*";if((e??0)>=(t??1/0))throw new Error("Invalid range: Range-end index is greater than or equal to the size of the file.");if((r??0)>=(t??1/0))throw new Error("Invalid range: Range-start index is greater than or equal to the size of the file.");if(r!=null&&e==null)return t==null?`bytes */${n}`:`bytes ${r}-${t-1}/${t}`;if(r==null&&e!=null){if(t==null)return`bytes */${n}`;let o=t-1;return`bytes ${o-e+1}-${o}/${t}`}return r==null&&e==null?`bytes */${n}`:`bytes ${r}-${e}/${n}`}function p_(r){return typeof r=="string"?r.length:r instanceof ArrayBuffer||r instanceof Uint8Array?r.byteLength:r instanceof Blob?r.size:(r instanceof ReadableStream,null)}function m_(r){let e=r.match(/^bytes=(?<start>\d+)?-(?<end>\d+)?$/);if(e?.groups==null)throw new Error("Invalid range request");let{start:t,end:n}=e.groups;return{start:t,end:n}}var Bs=class{headers;isRangeRequest;_fileSize;_body=null;rangeRequestHeader;log;requestRangeStart;requestRangeEnd;byteStart;byteEnd;byteSize;constructor(e,t){if(this.headers=t,this.log=e.forComponent("helia:verified-fetch:byte-range-context"),this.rangeRequestHeader=pw(this.headers,"Range"),this.rangeRequestHeader!=null){this.isRangeRequest=!0,this.log.trace("range request detected");try{let{start:n,end:o}=m_(this.rangeRequestHeader);this.requestRangeStart=n!=null?parseInt(n):null,this.requestRangeEnd=o!=null?parseInt(o):null}catch(n){this.log.error("error parsing range request header: %o",n),this.requestRangeStart=null,this.requestRangeEnd=null}this.setOffsetDetails()}else this.log.trace("no range request detected"),this.isRangeRequest=!1,this.requestRangeStart=null,this.requestRangeEnd=null}setBody(e){this._body=e,this.setFileSize(this._fileSize??p_(e)),this.log.trace("set request body with fileSize %o",this._fileSize)}getBody(){let e=this._body;if(e==null)return this.log.trace("body is null"),e;if(!this.isRangeRequest||!this.isValidRangeRequest)return this.log.trace("returning body unmodified for non-range, or invalid range, request"),e;let t=this.byteStart,n=this.byteEnd,o=this.byteSize;return t!=null||n!=null?(this.log.trace("returning body with byteStart=%o, byteEnd=%o, byteSize=%o",t,n,o),e instanceof ReadableStream?e:this.getSlicedBody(e)):(this.log.error("returning unmodified body for valid range request"),e)}getSlicedBody(e){let t=this.byteStart??0,n=this.byteEnd==null?void 0:this.byteEnd+1;return this.log.trace("returning body with offset %o and length %o",t,n),e.slice(t,n)}setFileSize(e){this._fileSize=e!=null?Number(e):null,this.log.trace("set _fileSize to %o",this._fileSize),this.setOffsetDetails()}getFileSize(){return this._fileSize}isValidByteStart(){return!(this.byteStart!=null&&(this.byteStart<0||this._fileSize!=null&&this.byteStart>=this._fileSize||this.byteEnd!=null&&this.byteStart>this.byteEnd))}isValidByteEnd(){return!(this.byteEnd!=null&&(this.byteEnd<0||this._fileSize!=null&&this.byteEnd>=this._fileSize||this.byteStart!=null&&this.byteEnd<this.byteStart))}get isValidRangeRequest(){if(!this.isRangeRequest)return!1;if(this.requestRangeStart==null&&this.requestRangeEnd==null)return this.log.trace("invalid range request, range request values not provided"),!1;if(!this.isValidByteStart())return this.log.trace("invalid range request, byteStart is less than 0 or greater than fileSize"),!1;if(!this.isValidByteEnd())return this.log.trace("invalid range request, byteEnd is less than 0 or greater than fileSize"),!1;if(this.requestRangeEnd!=null&&this.requestRangeStart!=null){if(this.requestRangeStart>this.requestRangeEnd)return this.log.trace("invalid range request, start is greater than end"),!1;if(this.requestRangeStart<0)return this.log.trace("invalid range request, start is less than 0"),!1;if(this.requestRangeEnd<0)return this.log.trace("invalid range request, end is less than 0"),!1}return this.byteEnd==null&&this.byteStart==null&&this.byteSize==null?(this.log.trace("invalid range request, could not calculate byteStart, byteEnd, or byteSize"),!1):!0}get offset(){return this.byteStart??0}get length(){return this.byteEnd!=null&&this.byteStart!=null&&this.byteStart===this.byteEnd?1:this.byteEnd!=null?this.byteEnd+1:this.byteSize!=null?this.byteSize-1:void 0}setOffsetDetails(){if(this.requestRangeStart==null&&this.requestRangeEnd==null){this.log.trace("requestRangeStart and requestRangeEnd are null");return}try{let{start:e,end:t,byteSize:n}=mw(this.requestRangeStart??void 0,this.requestRangeEnd??void 0,this._fileSize??void 0);this.log.trace("set byteStart to %o, byteEnd to %o, byteSize to %o",e,t,n),this.byteStart=e,this.byteEnd=t,this.byteSize=n}catch(e){this.log.error("error setting offset details: %o",e),this.byteStart=void 0,this.byteEnd=void 0,this.byteSize=void 0}}get contentRangeHeaderValue(){if(!this.isValidRangeRequest)throw this.log.error("cannot get contentRangeHeaderValue for invalid range request"),new Error("Invalid range request");return yw({byteStart:this.byteStart,byteEnd:this.byteEnd,byteSize:this._fileSize??void 0})}};function gw(r){let e=tt(r,{allowIndefinite:!1,coerceUndefinedToNull:!1,allowNaN:!1,allowInfinity:!1,strict:!0,useMaps:!1,rejectDuplicateMapKeys:!0,allowBigInt:!1});return new TextDecoder().decode(Qi(e))}function ww(r){let e=y_(r);return e===r?`filename="${r}"`:`filename="${e}"; filename*=UTF-8''${encodeURIComponent(r)}`}function y_(r){return r.replace(/[^\x00-\x7F]/g,"_")}function bw({cid:r,reqFormat:e,weak:t,rangeStart:n,rangeEnd:o}){let i=t===!0?"W/":"",s=e==null?"":`.${e}`;return(n!=null||o!=null)&&(s+=`.${n??"0"}-${o??"N"}`),`${i}"${r.toString()}${s}"`}async function xw(r,e,t,n){let o=t.forComponent("helia:verified-fetch:get-stream-from-async-iterable"),i=r[Symbol.asyncIterator](),{value:s,done:a}=await i.next();if(a===!0)throw o.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:f}=await i.next();if(f===!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 cM=F("ustar\0","binary"),lM=F("ustar ","binary"),uM=F(" \0","binary");var Aw=J(vw(),1);function w_(r){return r[Symbol.asyncIterator]!=null}function b_(r){if(w_(r))return(async()=>{let n=new Uint8Array(0);for await(let o of r)n=ue([n,o],n.length+o.length);return n})();let e=[],t=0;for(let n of r)e.push(n),t+=n.byteLength;return ue(e,t)}var Sw=b_;var x_="0000000000000000000",E_="7777777777777777777",v_=48,S_=F("ustar\0","binary"),__=F("00","binary"),A_=parseInt("7777",8),k_=257,I_=263,B_=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}},R_=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},bn=function(r,e){let t=r.toString(8);return t.length>e?F(E_.slice(0,e)+" "):F(x_.slice(0,e-t.length)+t+" ")},Ud=function(r){let e=F(r).byteLength,t=Math.floor(Math.log(e)/Math.log(10))+1;return e+t>=Math.pow(10,t)&&t++,`${e+t}${r}`};function _w(r){let e="";r.name!=null&&(e+=Ud(" path="+r.name+`
9
+ `)),r.linkname!=null&&(e+=Ud(" linkpath="+r.linkname+`
10
+ `));let t=r.pax;if(t!=null)for(let n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e+=Ud(" "+n+"="+t[n]+`
11
+ `));return F(e)}function yl(r){let e=new Uint8Array(512),t=r.name,n="";if(r.typeflag===5&&t[t.length-1]!=="/"&&(t+="/"),F(t).byteLength!==t.length)return null;for(;F(t).byteLength>100;){let o=t.indexOf("/");if(o===-1)return null;n+=n!==""?"/"+t.slice(0,o):t.slice(0,o),t=t.slice(o+1)}return F(t).byteLength>100||F(n).byteLength>155||r.linkname!=null&&F(r.linkname).byteLength>100?null:(e.set(F(t),0),e.set(bn(r.mode&A_,6),100),e.set(bn(r.uid,6),108),e.set(bn(r.gid,6),116),e.set(bn(r.size,11),124),e.set(bn(r.mtime.getTime()/1e3|0,11),136),e[156]=v_+B_(r.type),r.linkname!=null&&e.set(F(r.linkname),157),e.set(S_,k_),e.set(__,I_),r.uname!=null&&e.set(F(r.uname),265),r.gname!=null&&e.set(F(r.gname),297),e.set(bn(r.devmajor??0,6),329),e.set(bn(r.devminor??0,6),337),n!=null&&e.set(F(n),345),e.set(bn(R_(e),6),148),e)}var{S_IFMT:N_,S_IFBLK:C_,S_IFCHR:L_,S_IFDIR:D_,S_IFIFO:P_,S_IFLNK:O_}=Aw.default,U_=parseInt("755",8),F_=parseInt("644",8),kw=new Uint8Array(1024);function V_(r=0){switch(r&N_){case C_:return"block-device";case L_:return"character-device";case D_:return"directory";case P_:return"fifo";case O_:return"symlink";default:return"file"}}function Vd(r){return r&=511,r!==0?kw.subarray(0,512-r):new Uint8Array(0)}function Fd(r){if(r.pax==null){let e=yl(r);if(e!=null)return e}return H_(r)}function H_(r){let e=_w(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 Rt(yl(t)??new Uint8Array(0),e,Vd(e.length),yl({...t,size:r.size,type:r.type})??new Uint8Array(0)).subarray()}function gl(){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??V_(e.mode),mode:e.mode??(e.type==="directory"?U_:F_),uid:e.uid??0,gid:e.gid??0,mtime:e.mtime??new Date};if(typeof t=="string"&&(t=F(t)),t instanceof Uint8Array||Qt(t)){n.size=t.length,yield Fd(n),yield Qt(t)?t.subarray():t,yield Vd(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=W(await Sw(t)),yield Fd(n);continue}if(yield Fd(n),n.type!=="file"&&n.type!=="contiguous-file")continue;let o=0;for await(let i of t??[])o+=i.length,yield Qt(i)?i.subarray():i;if(o!==n.size)throw new Error(`size mismatch, wrote ${o} of ${n.size} bytes`);yield Vd(n.size)}yield kw}}var M_=["file","raw","directory"];function z_(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 Iw(r){if(!M_.includes(r.type))throw new P("Not a UnixFS node","ERR_NOT_UNIXFS");let e={header:z_(r)};return(r.type==="file"||r.type==="raw")&&(e.body=r.content()),e}async function*Bw(r,e,t){let n=await ze(r,e,t);if(n.type==="file"||n.type==="raw"){yield*at([Iw(n)],gl());return}if(n.type==="directory"){yield*at(Xo(r,e,t),o=>We(o,i=>Iw(i)),gl());return}throw new P("Not a UnixFS node","ERR_NOT_UNIXFS")}var Rw=J(Pf(),1),wl=class{lru;constructor(e){this.lru=(0,Rw.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 Hd=new wl(1e3),$_=/^(?<protocol>ip[fn]s):\/\/(?<cidOrPeerIdOrDnsLink>[^/?]+)\/?(?<path>[^?]*)\??(?<queryString>.*)$/,K_=/^\/(?<protocol>ip[fn]s)\/(?<cidOrPeerIdOrDnsLink>[^/?]+)\/?(?<path>[^?]*)\??(?<queryString>.*)$/,q_=/^https?:\/\/(.*[^/])\/(?<protocol>ip[fn]s)\/(?<cidOrPeerIdOrDnsLink>[^/?]+)\/?(?<path>[^?]*)\??(?<queryString>.*)$/,G_=/^https?:\/\/(?<cidOrPeerIdOrDnsLink>[^/?]+)\.(?<protocol>ip[fn]s)\.([^/?]+)\/?(?<path>[^?]*)\??(?<queryString>.*)$/;function W_(r){for(let e of[$_,K_,q_,G_]){let t=r.match(e);if(t?.groups!=null)return t.groups}throw new TypeError(`Invalid URL: ${r}, please use ipfs://, ipns://, or gateway URLs only`)}var j_=/^[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?$/;function Y_(r){return j_.test(r)&&r.includes("-")&&!r.includes(".")}function X_(r){return r.replace(/--/g,"%").replace(/-/g,".").replace(/%/g,"-")}async function Tw({urlString:r,ipns:e,logger:t},n){let o=t.forComponent("helia:verified-fetch:parse-url-string"),{protocol:i,cidOrPeerIdOrDnsLink:s,path:a,queryString:c}=W_(r),u,l,f=[];if(i==="ipfs")try{u=U.parse(s)}catch(d){o.error(d),f.push(new TypeError("Invalid CID for ipfs://<cid> URL"))}else{let d=Hd.get(s);if(d!=null)u=d.cid,l=d.path,o.trace("resolved %s to %c from cache",s,u);else{o.trace("attempting to resolve PeerId for %s",s);let p=null;try{p=Je(s),d=await e.resolve(p,{onProgress:n?.onProgress}),u=d?.cid,l=d?.path,o.trace("resolved %s to %c",s,u),Hd.set(s,d,60*1e3*2)}catch(h){p==null?(o.error('could not parse PeerId string "%s"',s,h),f.push(new TypeError(`Could not parse PeerId in ipns url "${s}", ${h.message}`))):(o.error("could not resolve PeerId %c",p,h),f.push(new TypeError(`Could not resolve PeerId "${s}", ${h.message}`)))}if(u==null){let h=s;Y_(s)&&(h=X_(s),o.trace('decoded dnslink from "%s" to "%s"',s,h)),o.trace("Attempting to resolve DNSLink for %s",h);try{d=await e.resolveDNSLink(h,{onProgress:n?.onProgress}),u=d?.cid,l=d?.path,o.trace("resolved %s to %c",h,u),Hd.set(s,d,60*1e3*2)}catch(y){o.error('could not resolve DnsLink for "%s"',s,y),f.push(y)}}}}if(u==null)throw f.length===1?f[0]:new AggregateError(f,`Invalid resource. Cannot determine CID from URL "${r}"`);let m={};if(c!=null&&c.length>0){let d=c.split("&");for(let p of d){let[h,y]=p.split("=");m[h]=decodeURIComponent(y)}m.download!=null&&(m.download=m.download==="true"),m.filename!=null&&(m.filename=m.filename.toString())}return{protocol:i,cid:u,path:Z_(l,a),query:m}}function Z_(r,e){let t="";return r!=null&&(t+=r),e.length>0&&(t=`${t.length>0?`${t}/`:t}${e}`),t=t.replace(/\/(\/)+/g,"/"),t.startsWith("/")&&(t=t.substring(1)),t}async function Nw(r,{ipns:e,logger:t},n){if(typeof r=="string")return Tw({urlString:r,ipns:e,logger:t},{onProgress:n?.onProgress});let o=U.asCID(r);if(o!=null)return{cid:o,protocol:"ipfs",path:"",query:{}};throw new TypeError(`Invalid resource. Cannot determine CID from resource: ${r}`)}function Md(r,e,t){Object.defineProperty(r,e,{enumerable:!0,configurable:!1,set:()=>{},get:()=>t})}function xn(r,e){Md(r,"type",e)}function En(r,e){Md(r,"url",e)}function Cw(r){Md(r,"redirected",!0)}function Xn(r,e,t){let n=new Response(e,{...t??{},status:200,statusText:"OK"});return t?.redirected===!0&&Cw(n),xn(n,"basic"),En(n,r),n.headers.set("Accept-Ranges","bytes"),n}function zd(r,e,t){let n=new Response(e,{...t??{},status:502,statusText:"Bad Gateway"});return xn(n,"basic"),En(n,r),n}function $d(r,e,t){let n=new Response(e,{...t??{},status:501,statusText:"Not Implemented"});return n.headers.set("X-Content-Type-Options","nosniff"),xn(n,"basic"),En(n,r),n}function oi(r,e,t){let n=new Response(e,{...t??{},status:406,statusText:"Not Acceptable"});return xn(n,"basic"),En(n,r),n}function xl(r,e,t){let n=new Response(e,{...t??{},status:400,statusText:"Bad Request"});return xn(n,"basic"),En(n,r),n}function Lw(r,e,t){let n=new Response(null,{...t??{},status:301,statusText:"Moved Permanently",headers:{...t?.headers??{},location:e}});return xn(n,"basic"),En(n,r),n}function Kd(r,e,{byteRangeContext:t,log:n},o){if(!t.isRangeRequest)return Xn(r,e,o);if(!t.isValidRangeRequest)return bl(r,e,o);let i;try{i=new Response(e,{...o??{},status:206,statusText:"Partial Content",headers:{...o?.headers??{},"content-range":t.contentRangeHeaderValue}})}catch(s){return n?.error("failed to create range response",s),bl(r,e,o)}return o?.redirected===!0&&Cw(i),xn(i,"basic"),En(i,r),i.headers.set("Accept-Ranges","bytes"),i}function bl(r,e,t){let n=new Response(e,{...t??{},status:416,statusText:"Requested Range Not Satisfiable"});return xn(n,"basic"),En(n,r),n}var J_={[ln]:["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"],[fn]:["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"],[$r]:["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"],[ye]:["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"],[ge]:["application/octet-stream","application/vnd.ipld.raw","application/vnd.ipfs.ipns-record","application/vnd.ipld.car","application/x-tar"]};function Dw(r,e){let t=J_[r.code];if(e!=null)return Q_(e,t)}function Q_(r,e){let t=r.split(",").map(n=>{let o=n.trim().split(";");return{mimeType:`${o[0]}`.trim(),weight:eA(o[1])}}).sort((n,o)=>n.weight===o.weight?0:n.weight>o.weight?-1:1).map(n=>n.mimeType);for(let n of t)for(let o of e)if(n.includes(o)||n==="*/*"||n.startsWith("*/")&&o.split("/")[1]===n.split("/")[1]||n.endsWith("/*")&&o.split("/")[0]===n.split("/")[0])return o}function eA(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 tA={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 Pw(r){if(r!=null)return tA[r]}async function Ow(r,e,t){let n=[],o;for await(let i of As(e,r,t))n.push(i.cid),o=i;if(o==null)throw new Error("No terminal element found");return{ipfsRoots:n,terminalElement:o}}function rA(r){if(r==null)return;let e;return r?.signal===null&&(e=void 0),{...r,signal:e}}var nA=["application/vnd.ipld.raw","application/octet-stream"];function oA(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(nA.includes(n??""))return n}}var El=class{helia;ipns;unixfs;log;contentTypeParser;constructor({helia:e,ipns:t,unixfs:n},o){this.helia=e,this.log=e.logger.forComponent("helia:verified-fetch"),this.ipns=t??Ty(e),this.unixfs=n??hw(e),this.contentTypeParser=o?.contentTypeParser,this.log.trace("created VerifiedFetch instance")}async handleIPNSRecord({resource:e,cid:t,path:n,options:o}){if(n!==""||!e.startsWith("ipns://"))return xl("Invalid IPNS name");let i;try{i=Je(e.replace("ipns://",""))}catch{return this.log.error("could not parse peer id from IPNS url %s",e),xl("Invalid IPNS name")}let s=ue([F("/ipns/"),i.toBytes()]),a=new Be("/dht/record/"+W(s,"base32"),!1),c=await this.helia.datastore.get(a,o),u=pn.deserialize(c),l=Xn(e,u.value);return l.headers.set("content-type","application/vnd.ipfs.ipns-record"),l}async handleCar({resource:e,cid:t,options:n}){let o=xy(this.helia),i=ml(o.stream(t,n)),s=Xn(e,i);return s.headers.set("content-type","application/vnd.ipld.car; version=1"),s}async handleTar({resource:e,cid:t,path:n,options:o}){if(t.code!==ye&&t.code!==ge)return oi("only UnixFS data can be returned in a TAR file");let i=ml(Bw(`/ipfs/${t}/${n}`,this.helia.blockstore,o)),s=Xn(e,i);return s.headers.set("content-type","application/x-tar"),s}async handleJson({resource:e,cid:t,path:n,accept:o,options:i}){this.log.trace("fetching %c/%s",t,n);let s=await this.helia.blockstore.get(t,i),a;if(o==="application/vnd.ipld.dag-cbor"||o==="application/cbor")try{let u=Dc(s);a=Zi(u)}catch(u){return this.log.error("could not transform %c to application/vnd.ipld.dag-cbor",u),oi(e)}else a=s;let c=Xn(e,a);return c.headers.set("content-type",o??"application/json"),c}async handleDagCbor({resource:e,cid:t,path:n,accept:o,options:i}){this.log.trace("fetching %c/%s",t,n);let s=await this.helia.blockstore.get(t,i),a;if(o==="application/octet-stream"||o==="application/vnd.ipld.dag-cbor"||o==="application/cbor")a=s;else if(o==="application/vnd.ipld.dag-json")try{let u=Mn(s);a=q1(u)}catch(u){return this.log.error("could not transform %c to application/vnd.ipld.dag-json",u),oi(e)}else try{a=gw(s)}catch(u){if(o==="application/json")return this.log('could not decode DAG-CBOR as JSON-safe, but the client sent "Accept: application/json"',u),oi(e);this.log("could not decode DAG-CBOR as JSON-safe, falling back to `application/octet-stream`",u),a=s}let c=Xn(e,a);return o==null&&(o=a instanceof Uint8Array?"application/octet-stream":"application/json"),c.headers.set("content-type",o),c}async handleDagPb({cid:e,path:t,resource:n,options:o}){let i,s,a=!1,c=new Bs(this.helia.logger,o?.headers);try{let d=await Ow(this.helia.blockstore,`${e.toString()}/${t}`,o);s=d.ipfsRoots,i=d.terminalElement}catch(d){return this.log.error("error walking path %s",t,d),zd("Error walking path")}let u=i?.cid??e;if(i?.type==="directory"){let d=i.cid;if(t!==""&&!t.endsWith("/")){if(o?.redirect==="error")throw this.log('could not redirect to %s/ as redirect option was set to "error"',n),new TypeError("Failed to fetch");if(o?.redirect==="manual")return this.log("returning 301 permanent redirect to %s/",n),Lw(n,`${n}/`);n=`${n}/`,a=!0}let p="index.html";try{this.log.trace("found directory at %c/%s, looking for index.html",e,t);let h=await this.unixfs.stat(d,{path:p,signal:o?.signal,onProgress:o?.onProgress});this.log.trace("found root file at %c/%s with cid %c",d,p,h.cid),t=p,u=h.cid}catch(h){return this.log("error loading path %c/%s",d,p,h),$d("Unable to find index.html for directory at given path. Support for directories with implicit root is not implemented")}finally{o?.onProgress?.(new V("verified-fetch:request:end",{cid:d,path:p}))}}c.isRangeRequest&&c.isValidRangeRequest&&i.type==="file"&&(c.setFileSize(i.unixfs.fileSize()),this.log.trace("fileSize for rangeRequest %d",c.getFileSize()));let l=c.offset,f=c.length;this.log.trace("calling unixfs.cat for %c/%s with offset=%o & length=%o",u,t,l,f);let m=this.unixfs.cat(u,{signal:o?.signal,onProgress:o?.onProgress,offset:l,length:f});this.log("got async iterator for %c/%s",e,t);try{let{stream:d,firstChunk:p}=await xw(m,t??"",this.helia.logger,{onProgress:o?.onProgress});c.setBody(d);let h=Kd(n,c.getBody(),{byteRangeContext:c,log:this.log},{redirected:a});return await this.setContentType(p,t,h),s!=null&&h.headers.set("X-Ipfs-Roots",s.map(y=>y.toV1().toString()).join(",")),h}catch(d){return this.log.error("error streaming %c/%s",e,t,d),c.isRangeRequest&&d.code==="ERR_INVALID_PARAMS"?bl(n):zd("Unable to stream content")}}async handleRaw({resource:e,cid:t,path:n,options:o}){let i=new Bs(this.helia.logger,o?.headers),s=await this.helia.blockstore.get(t,o);i.setBody(s);let a=Kd(e,i.getBody(),{byteRangeContext:i,log:this.log},{redirected:!1}),c=oA(o?.headers);return c!=null?a.headers.set("content-type",c):await this.setContentType(s,n,a),a}async setContentType(e,t,n){let o="application/octet-stream";if(this.contentTypeParser!=null)try{let i=t.split("/").pop()?.trim();i=i===""?void 0:i;let s=this.contentTypeParser(e,i);if(iA(s)){let a=await s;a!=null&&(o=a)}else s!=null&&(o=s)}catch(i){this.log.error("error parsing content type",i)}this.log.trace('setting content type to "%s"',o),n.headers.set("content-type",o)}codecHandlers={[ye]:this.handleDagPb,[fn]:this.handleJson,[$r]:this.handleJson,[ln]:this.handleDagCbor,[ge]:this.handleRaw,[Ge.code]:this.handleRaw};async fetch(e,t){this.log("fetch %s",e);let n=rA(t);n?.onProgress?.(new V("verified-fetch:request:start",{resource:e}));let o,i,s;try{let y=await Nw(e,{ipns:this.ipns,logger:this.helia.logger},n);o=y.cid,i=y.path,s=y.query}catch(y){return this.log.error("error parsing resource %s",e,y),xl("Invalid resource")}n?.onProgress?.(new V("verified-fetch:request:resolve",{cid:o,path:i}));let c=new Headers(n?.headers).get("accept");c!=null&&this.log('incoming accept header "%s"',c);let u=Pw(s.format);s.format!=null&&this.log('incoming query format "%s", mapped to %s',s.format,u);let l=c??u,f=Dw(o,l);if(this.log("output type %s",f),l!=null&&f==null)return oi(e.toString());let m,d,p={resource:e.toString(),cid:o,path:i,accept:f,options:n};if(f==="application/vnd.ipfs.ipns-record")d="ipns-record",m=await this.handleIPNSRecord(p);else if(f==="application/vnd.ipld.car")d="car",s.download=!0,s.filename=s.filename??`${o.toString()}.car`,m=await this.handleCar(p);else if(f==="application/vnd.ipld.raw")d="raw",s.download=!0,s.filename=s.filename??`${o.toString()}.bin`,m=await this.handleRaw(p);else if(f==="application/x-tar")d="tar",s.download=!0,s.filename=s.filename??`${o.toString()}.tar`,m=await this.handleTar(p);else{this.log.trace('finding handler for cid code "%s" and output type "%s"',o.code,f);let y=this.codecHandlers[o.code];if(y==null)return $d(`Support for codec with code ${o.code} is not yet implemented. Please open an issue at https://github.com/ipfs/helia/issues/new`);this.log.trace('calling handler "%s"',y.name),m=await y.call(this,p)}m.headers.set("etag",bw({cid:o,reqFormat:d,weak:!1})),m.headers.set("cache-control","public, max-age=29030400, immutable"),m.headers.set("X-Ipfs-Path",e.toString());let h;return s.download===!0&&(h="attachment"),s.filename!=null&&(h==null&&(h="inline"),h=`${h}; ${ww(s.filename)}`),h!=null&&m.headers.set("Content-Disposition",h),n?.onProgress?.(new V("verified-fetch:request:end",{cid:o,path:i})),m}async start(){await this.helia.start()}async stop(){await this.helia.stop()}};function iA(r){return r?.then!=null}var Rs,vl=async function(e,t){return Rs==null&&(Rs=await qd()),Rs(e,t)};vl.start=async function(){await Rs?.start()};vl.stop=async function(){await Rs?.stop()};async function qd(r,e){sA(r)||(r=await hy({blockBrokers:[hi({gateways:r?.gateways})],routers:(r?.routers??["https://delegated-ipfs.dev"]).map(o=>ji(o)),dns:aA(r?.dnsResolvers)}));let t=new El({helia:r},e);async function n(o,i){return t.fetch(o,i)}return n.stop=t.stop.bind(t),n.start=t.start.bind(t),n}function sA(r){return r?.blockstore!=null&&r?.datastore!=null&&r?.gc!=null&&r?.stop!=null&&r?.start!=null}function aA(r){if(r!=null)return Array.isArray(r)?Yi({resolvers:{".":r}}):Yi({resolvers:r})}return Xw(cA);})();
12
12
  /*! Bundled license information:
13
13
 
14
14
  pvtsutils/build/index.js: