@helia/verified-fetch 0.0.0-75d0a5b → 0.0.0-7c07e11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +205 -6
- package/dist/index.min.js +4 -4
- package/dist/src/index.d.ts +186 -4
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +186 -4
- package/dist/src/index.js.map +1 -1
- package/dist/src/types.d.ts +2 -0
- package/dist/src/types.d.ts.map +1 -0
- package/dist/src/types.js +2 -0
- package/dist/src/types.js.map +1 -0
- package/dist/src/utils/dag-cbor-to-safe-json.d.ts +7 -0
- package/dist/src/utils/dag-cbor-to-safe-json.d.ts.map +1 -0
- package/dist/src/utils/dag-cbor-to-safe-json.js +37 -0
- package/dist/src/utils/dag-cbor-to-safe-json.js.map +1 -0
- package/dist/src/utils/get-e-tag.d.ts +28 -0
- package/dist/src/utils/get-e-tag.d.ts.map +1 -0
- package/dist/src/utils/get-e-tag.js +18 -0
- package/dist/src/utils/get-e-tag.js.map +1 -0
- package/dist/src/utils/parse-url-string.d.ts +5 -1
- package/dist/src/utils/parse-url-string.d.ts.map +1 -1
- package/dist/src/utils/parse-url-string.js.map +1 -1
- package/dist/src/verified-fetch.d.ts +1 -11
- package/dist/src/verified-fetch.d.ts.map +1 -1
- package/dist/src/verified-fetch.js +25 -38
- package/dist/src/verified-fetch.js.map +1 -1
- package/package.json +18 -16
- package/src/index.ts +186 -4
- package/src/types.ts +1 -0
- package/src/utils/dag-cbor-to-safe-json.ts +44 -0
- package/src/utils/get-e-tag.ts +36 -0
- package/src/utils/parse-url-string.ts +6 -1
- package/src/verified-fetch.ts +31 -44
package/dist/index.min.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
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 q2=Object.create;var la=Object.defineProperty;var j2=Object.getOwnPropertyDescriptor;var G2=Object.getOwnPropertyNames;var W2=Object.getPrototypeOf,Y2=Object.prototype.hasOwnProperty;var me=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),Ae=(r,e)=>{for(var t in e)la(r,t,{get:e[t],enumerable:!0})},Xf=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of G2(e))!Y2.call(r,i)&&i!==t&&la(r,i,{get:()=>e[i],enumerable:!(n=j2(e,i))||n.enumerable});return r};var re=(r,e,t)=>(t=r!=null?q2(W2(r)):{},Xf(e||!r||!r.__esModule?la(t,"default",{value:r,enumerable:!0}):t,r)),X2=r=>Xf(la({},"__esModule",{value:!0}),r);var Eu=me((x8,f0)=>{var $i=1e3,zi=$i*60,Ki=zi*60,ai=Ki*24,Mx=ai*7,Hx=ai*365.25;f0.exports=function(r,e){e=e||{};var t=typeof r;if(t==="string"&&r.length>0)return $x(r);if(t==="number"&&isFinite(r))return e.long?Kx(r):zx(r);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(r))};function $x(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*Hx;case"weeks":case"week":case"w":return t*Mx;case"days":case"day":case"d":return t*ai;case"hours":case"hour":case"hrs":case"hr":case"h":return t*Ki;case"minutes":case"minute":case"mins":case"min":case"m":return t*zi;case"seconds":case"second":case"secs":case"sec":case"s":return t*$i;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return t;default:return}}}}function zx(r){var e=Math.abs(r);return e>=ai?Math.round(r/ai)+"d":e>=Ki?Math.round(r/Ki)+"h":e>=zi?Math.round(r/zi)+"m":e>=$i?Math.round(r/$i)+"s":r+"ms"}function Kx(r){var e=Math.abs(r);return e>=ai?fa(r,e,ai,"day"):e>=Ki?fa(r,e,Ki,"hour"):e>=zi?fa(r,e,zi,"minute"):e>=$i?fa(r,e,$i,"second"):r+" ms"}function fa(r,e,t,n){var i=e>=t*1.5;return Math.round(r/t)+" "+n+(i?"s":"")}});var m0=me((b8,p0)=>{function qx(r){t.debug=t,t.default=t,t.coerce=c,t.disable=o,t.enable=i,t.enabled=s,t.humanize=Eu(),t.destroy=u,Object.keys(r).forEach(l=>{t[l]=r[l]}),t.names=[],t.skips=[],t.formatters={};function e(l){let h=0;for(let p=0;p<l.length;p++)h=(h<<5)-h+l.charCodeAt(p),h|=0;return t.colors[Math.abs(h)%t.colors.length]}t.selectColor=e;function t(l){let h,p=null,d,f;function m(...y){if(!m.enabled)return;let g=m,x=Number(new Date),b=x-(h||x);g.diff=b,g.prev=h,g.curr=x,h=x,y[0]=t.coerce(y[0]),typeof y[0]!="string"&&y.unshift("%O");let A=0;y[0]=y[0].replace(/%([a-zA-Z%])/g,(B,v)=>{if(B==="%%")return"%";A++;let E=t.formatters[v];if(typeof E=="function"){let R=y[A];B=E.call(g,R),y.splice(A,1),A--}return B}),t.formatArgs.call(g,y),(g.log||t.log).apply(g,y)}return m.namespace=l,m.useColors=t.useColors(),m.color=t.selectColor(l),m.extend=n,m.destroy=t.destroy,Object.defineProperty(m,"enabled",{enumerable:!0,configurable:!1,get:()=>p!==null?p:(d!==t.namespaces&&(d=t.namespaces,f=t.enabled(l)),f),set:y=>{p=y}}),typeof t.init=="function"&&t.init(m),m}function n(l,h){let p=t(this.namespace+(typeof h>"u"?":":h)+l);return p.log=this.log,p}function i(l){t.save(l),t.namespaces=l,t.names=[],t.skips=[];let h,p=(typeof l=="string"?l:"").split(/[\s,]+/),d=p.length;for(h=0;h<d;h++)p[h]&&(l=p[h].replace(/\*/g,".*?"),l[0]==="-"?t.skips.push(new RegExp("^"+l.slice(1)+"$")):t.names.push(new RegExp("^"+l+"$")))}function o(){let l=[...t.names.map(a),...t.skips.map(a).map(h=>"-"+h)].join(",");return t.enable(""),l}function s(l){if(l[l.length-1]==="*")return!0;let h,p;for(h=0,p=t.skips.length;h<p;h++)if(t.skips[h].test(l))return!1;for(h=0,p=t.names.length;h<p;h++)if(t.names[h].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}p0.exports=qx});var vu=me((Et,pa)=>{Et.formatArgs=Gx;Et.save=Wx;Et.load=Yx;Et.useColors=jx;Et.storage=Xx();Et.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`."))}})();Et.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 jx(){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 Gx(r){if(r[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+r[0]+(this.useColors?"%c ":" ")+"+"+pa.exports.humanize(this.diff),!this.useColors)return;let e="color: "+this.color;r.splice(1,0,e,"color: inherit");let t=0,n=0;r[0].replace(/%[a-zA-Z%]/g,i=>{i!=="%%"&&(t++,i==="%c"&&(n=t))}),r.splice(n,0,e)}Et.log=console.debug||console.log||(()=>{});function Wx(r){try{r?Et.storage.setItem("debug",r):Et.storage.removeItem("debug")}catch{}}function Yx(){let r;try{r=Et.storage.getItem("debug")}catch{}return!r&&typeof process<"u"&&"env"in process&&(r=process.env.DEBUG),r}function Xx(){try{return localStorage}catch{}}pa.exports=m0()(Et);var{formatters:Zx}=pa.exports;Zx.j=function(r){try{return JSON.stringify(r)}catch(e){return"[UnexpectedJSONParseError]: "+e.message}}});var Re=me((zI,P0)=>{"use strict";function D0(r,e){for(let t in e)Object.defineProperty(r,t,{value:e[t],enumerable:!0,configurable:!0});return r}function Db(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 D0(r,t)}catch{t.message=r.message,t.stack=r.stack;let i=function(){};return i.prototype=Object.create(Object.getPrototypeOf(r)),D0(new i,t)}}P0.exports=Db});var Np=me(uo=>{"use strict";var S3="[object ArrayBuffer]",Gr=class r{static isArrayBuffer(e){return Object.prototype.toString.call(e)===S3}static toArrayBuffer(e){return this.isArrayBuffer(e)?e:e.byteLength===e.buffer.byteLength||e.byteOffset===0&&e.byteLength===e.buffer.byteLength?e.buffer:this.toUint8Array(e.buffer).slice(e.byteOffset,e.byteOffset+e.byteLength).buffer}static toUint8Array(e){return this.toView(e,Uint8Array)}static toView(e,t){if(e.constructor===t)return e;if(this.isArrayBuffer(e))return new t(e);if(this.isArrayBufferView(e))return new t(e.buffer,e.byteOffset,e.byteLength);throw new TypeError("The provided value is not of type '(ArrayBuffer or ArrayBufferView)'")}static isBufferSource(e){return this.isArrayBufferView(e)||this.isArrayBuffer(e)}static isArrayBufferView(e){return ArrayBuffer.isView(e)||e&&this.isArrayBuffer(e.buffer)}static isEqual(e,t){let n=r.toUint8Array(e),i=r.toUint8Array(t);if(n.length!==i.byteLength)return!1;for(let o=0;o<n.length;o++)if(n[o]!==i[o])return!1;return!0}static concat(...e){let t;Array.isArray(e[0])&&!(e[1]instanceof Function)||Array.isArray(e[0])&&e[1]instanceof Function?t=e[0]:e[e.length-1]instanceof Function?t=e.slice(0,e.length-1):t=e;let n=0;for(let s of t)n+=s.byteLength;let i=new Uint8Array(n),o=0;for(let s of t){let a=this.toUint8Array(s);i.set(a,o),o+=a.length}return e[e.length-1]instanceof Function?this.toView(i,e[e.length-1]):i.buffer}},Uh="string",_3=/^[0-9a-f]+$/i,k3=/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/,R3=/^[a-zA-Z0-9-_]+$/,qa=class{static fromString(e){let t=unescape(encodeURIComponent(e)),n=new Uint8Array(t.length);for(let i=0;i<t.length;i++)n[i]=t.charCodeAt(i);return n.buffer}static toString(e){let t=Gr.toUint8Array(e),n="";for(let o=0;o<t.length;o++)n+=String.fromCharCode(t[o]);return decodeURIComponent(escape(n))}},Ht=class{static toString(e,t=!1){let n=Gr.toArrayBuffer(e),i=new DataView(n),o="";for(let s=0;s<n.byteLength;s+=2){let a=i.getUint16(s,t);o+=String.fromCharCode(a)}return o}static fromString(e,t=!1){let n=new ArrayBuffer(e.length*2),i=new DataView(n);for(let o=0;o<e.length;o++)i.setUint16(o*2,e.charCodeAt(o),t);return n}},ja=class r{static isHex(e){return typeof e===Uh&&_3.test(e)}static isBase64(e){return typeof e===Uh&&k3.test(e)}static isBase64Url(e){return typeof e===Uh&&R3.test(e)}static ToString(e,t="utf8"){let n=Gr.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 Ht.toString(n,!0);case"utf16":case"utf16be":return Ht.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 Ht.fromString(e,!0);case"utf16":case"utf16be":return Ht.fromString(e);default:throw new Error(`Unknown type of encoding '${t}'`)}}static ToBase64(e){let t=Gr.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 qa.fromString(e);case"utf16":case"utf16be":return Ht.fromString(e);case"utf16le":case"usc2":return Ht.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 qa.toString(e);case"utf16":case"utf16be":return Ht.toString(e);case"utf16le":case"usc2":return Ht.toString(e,!0);default:throw new Error(`Unknown type of encoding '${t}'`)}}static FromBinary(e){let t=e.length,n=new Uint8Array(t);for(let i=0;i<t;i++)n[i]=e.charCodeAt(i);return n.buffer}static ToBinary(e){let t=Gr.toUint8Array(e),n="";for(let i=0;i<t.length;i++)n+=String.fromCharCode(t[i]);return n}static ToHex(e){let t=Gr.toUint8Array(e),n="",i=t.length;for(let o=0;o<i;o++){let s=t[o];s<16&&(n+="0"),n+=s.toString(16)}return n}static FromHex(e){let t=this.formatString(e);if(!t)return new ArrayBuffer(0);if(!r.isHex(t))throw new TypeError("Argument 'hexString' is not HEX encoded");t.length%2&&(t=`0${t}`);let n=new Uint8Array(t.length/2);for(let i=0;i<t.length;i=i+2){let o=t.slice(i,i+2);n[i/2]=parseInt(o,16)}return n.buffer}static ToUtf16String(e,t=!1){return Ht.toString(e,t)}static FromUtf16String(e,t=!1){return Ht.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,"")||""}};ja.DEFAULT_UTF8_ENCODING="utf8";function T3(r,...e){let t=arguments[0];for(let n=1;n<arguments.length;n++){let i=arguments[n];for(let o in i)t[o]=i[o]}return t}function C3(...r){let e=r.map(i=>i.byteLength).reduce((i,o)=>i+o),t=new Uint8Array(e),n=0;return r.map(i=>new Uint8Array(i)).forEach(i=>{for(let o of i)t[n++]=o}),t.buffer}function N3(r,e){if(!(r&&e)||r.byteLength!==e.byteLength)return!1;let t=new Uint8Array(r),n=new Uint8Array(e);for(let i=0;i<r.byteLength;i++)if(t[i]!==n[i])return!1;return!0}uo.BufferSourceConverter=Gr;uo.Convert=ja;uo.assign=T3;uo.combine=C3;uo.isEqual=N3});var Dc=me((sR,Wh)=>{var oR=function(){typeof Wh<"u"&&(Wh.exports=m);var r=86400,e=3200,t=146097*e/400,n=r*t,i=1e3*n,o=864e13,s=4294967296,a=1e6,c="000000000",u=Math.trunc||function(E){var R=E-E%1;return R==0&&(E<0||E===0&&1/E!=1/0)?-0:R},l=m.prototype,h=(m.fromDate=function(E){return new m(+E)},m.fromInt64BE=A(0,1,2,3,0,4),m.fromInt64LE=A(3,2,1,0,4,0),m.fromString=function(C){var R,N=new m,C=(C+="").replace(/^\s*[+\-]?\d+/,function(D){var D=+D,ie=1970+(D-1970)%400;return N.year=D-ie,ie}).replace(/(?:Z|([+\-]\d{2}):?(\d{2}))$/,function(H,D,ie){return D<0&&(ie*=-1),R=6e4*(60*+D+ +ie),""}).replace(/\.\d+$/,function(H){return N.nano=+(H+c).substr(1,9),""}).split(/\D+/);if(1<C.length?C[1]--:C[1]=0,N.time=R=Date.UTC.apply(Date,C)-(R||0),isNaN(R))throw new TypeError("Invalid Date");return y(N)},m.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(),C={H:function(){return B(N.getUTCHours())},L:function(){return v(N.getUTCMilliseconds(),3)},M:function(){return B(N.getUTCMinutes())},N:function(){return v(R.getNano(),9)},S:function(){return B(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 p[N.getUTCMonth()]},d:function(){return B(N.getUTCDate())},e:function(){return function(H){return(9<H?"":" ")+(0|H)}(N.getUTCDate())},m:function(){return B(N.getUTCMonth()+1)}};return function H(D){return D.replace(/%./g,function(ie){var L=ie[1],_=f[L],L=C[L];return _?H(_):L?L():ie})}(E||h)},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"),p=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],d=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],f={"%":"%",F:"%Y-%m-%d",n:`
|
|
3
|
-
`,R:"%H:%M",T:"%H:%M:%S",t:" ",X:"%T",Z:"GMT",z:"+0000"};return m;function m(E,R,N){var C=this;if(!(C instanceof m))return new m(E,R,N);C.time=+E||0,C.nano=+R||0,C.year=+N||0,y(C)}function y(E){var R,N,C,H=E.year,D=E.time,ie=E.nano,_=((ie<0||a<=ie)&&(ie-=(N=Math.floor(ie/a))*a,D+=N,N=1),H%e);return(D<-o||o<D||_)&&((R=u(D/i))&&(H+=R*e,D-=R*i),(C=g(D)).setUTCFullYear(_+C.getUTCFullYear()),C=(D=+C)+(R=u((H-=_)/e))*i,R&&-o<=C&&C<=o&&(H-=R*e,D=C),N=1),N&&(E.year=H,E.time=D,E.nano=ie),E}function g(E){var R=new Date(0);return R.setTime(E),R}function x(H,C){H=+H||0;var N=u((C=(C|0)*s)/n)+u(H/n),C=C%n+H%n,H=u(C/n);return H&&(N+=H,C-=H*n),new m(1e3*C,0,N*e)}function b(E,R,N,C,H,D){return function(_,L){var U=y(this);_=_||new Array(8),I(_,L|=0);var k=Math.floor(U.time/1e3),U=U.year*(t*r/e),X=u(U/s)+u(k/s),U=U%s+k%s,k=Math.floor(U/s);return k&&(X+=k,U-=k*s),ie(_,L+H,X),ie(_,L+D,U),_};function ie(_,L,X){_[L+E]=X>>24&255,_[L+R]=X>>16&255,_[L+N]=X>>8&255,_[L+C]=255&X}}function A(E,R,N,C,H,D){return function(_,L){I(_,L|=0);var X=ie(_,L+H);return x(ie(_,L+D),X)};function ie(_,L){return 16777216*_[L+E]+(_[L+R]<<16|_[L+N]<<8|_[L+C])}}function I(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 B(E){return(9<E?"":"0")+(0|E)}function v(E,R){return(c+(0|E)).substr(-R)}}()});var ay=me((zT,cd)=>{"use strict";var J6=Object.prototype.hasOwnProperty,ct="~";function Rs(){}Object.create&&(Rs.prototype=Object.create(null),new Rs().__proto__||(ct=!1));function Q6(r,e,t){this.fn=r,this.context=e,this.once=t||!1}function sy(r,e,t,n,i){if(typeof t!="function")throw new TypeError("The listener must be a function");var o=new Q6(t,n||r,i),s=ct?ct+e:e;return r._events[s]?r._events[s].fn?r._events[s]=[r._events[s],o]:r._events[s].push(o):(r._events[s]=o,r._eventsCount++),r}function Jc(r,e){--r._eventsCount===0?r._events=new Rs:delete r._events[e]}function rt(){this._events=new Rs,this._eventsCount=0}rt.prototype.eventNames=function(){var e=[],t,n;if(this._eventsCount===0)return e;for(n in t=this._events)J6.call(t,n)&&e.push(ct?n.slice(1):n);return Object.getOwnPropertySymbols?e.concat(Object.getOwnPropertySymbols(t)):e};rt.prototype.listeners=function(e){var t=ct?ct+e:e,n=this._events[t];if(!n)return[];if(n.fn)return[n.fn];for(var i=0,o=n.length,s=new Array(o);i<o;i++)s[i]=n[i].fn;return s};rt.prototype.listenerCount=function(e){var t=ct?ct+e:e,n=this._events[t];return n?n.fn?1:n.length:0};rt.prototype.emit=function(e,t,n,i,o,s){var a=ct?ct+e:e;if(!this._events[a])return!1;var c=this._events[a],u=arguments.length,l,h;if(c.fn){switch(c.once&&this.removeListener(e,c.fn,void 0,!0),u){case 1:return c.fn.call(c.context),!0;case 2:return c.fn.call(c.context,t),!0;case 3:return c.fn.call(c.context,t,n),!0;case 4:return c.fn.call(c.context,t,n,i),!0;case 5:return c.fn.call(c.context,t,n,i,o),!0;case 6:return c.fn.call(c.context,t,n,i,o,s),!0}for(h=1,l=new Array(u-1);h<u;h++)l[h-1]=arguments[h];c.fn.apply(c.context,l)}else{var p=c.length,d;for(h=0;h<p;h++)switch(c[h].once&&this.removeListener(e,c[h].fn,void 0,!0),u){case 1:c[h].fn.call(c[h].context);break;case 2:c[h].fn.call(c[h].context,t);break;case 3:c[h].fn.call(c[h].context,t,n);break;case 4:c[h].fn.call(c[h].context,t,n,i);break;default:if(!l)for(d=1,l=new Array(u-1);d<u;d++)l[d-1]=arguments[d];c[h].fn.apply(c[h].context,l)}}return!0};rt.prototype.on=function(e,t,n){return sy(this,e,t,n,!1)};rt.prototype.once=function(e,t,n){return sy(this,e,t,n,!0)};rt.prototype.removeListener=function(e,t,n,i){var o=ct?ct+e:e;if(!this._events[o])return this;if(!t)return Jc(this,o),this;var s=this._events[o];if(s.fn)s.fn===t&&(!i||s.once)&&(!n||s.context===n)&&Jc(this,o);else{for(var a=0,c=[],u=s.length;a<u;a++)(s[a].fn!==t||i&&!s[a].once||n&&s[a].context!==n)&&c.push(s[a]);c.length?this._events[o]=c.length===1?c[0]:c:Jc(this,o)}return this};rt.prototype.removeAllListeners=function(e){var t;return e?(t=ct?ct+e:e,this._events[t]&&Jc(this,t)):(this._events=new Rs,this._eventsCount=0),this};rt.prototype.off=rt.prototype.removeListener;rt.prototype.addListener=rt.prototype.on;rt.prefixed=ct;rt.EventEmitter=rt;typeof cd<"u"&&(cd.exports=rt)});var rg=me((AD,tg)=>{"use strict";tg.exports=eg;var t4=Eu(),Xn=eg.prototype,r4=new Date%1e9;function n4(){return(Math.random()*1e9>>>0)+r4++}function eg(r){r=r||{},this.id=r.id||n4(),this.max=r.max||1/0,this.items=r.items||[],this._lookup={},this.size=this.items.length,this.lastModified=new Date(r.lastModified||new Date);for(var e,t,n=this.items.length;n--;)e=this.items[n],t=new Date(e.expires)-new Date,this._lookup[e.key]=e,t>0?this.expire(e.key,t):t<=0&&this.delete(e.key)}Xn.has=function(r){return r in this._lookup};Xn.get=function(r){if(!this.has(r))return null;var e=this._lookup[r];return e.refresh&&this.expire(r,e.refresh),this.items.splice(this.items.indexOf(e),1),this.items.push(e),e.value};Xn.meta=function(r){if(!this.has(r))return null;var e=this._lookup[r];return"meta"in e?e.meta:null};Xn.set=function(r,e,t){var n=this._lookup[r],i=this._lookup[r]={key:r,value:e};return this.lastModified=new Date,n?(clearTimeout(n.timeout),this.items.splice(this.items.indexOf(n),1,i)):(this.size>=this.max&&this.delete(this.items[0].key),this.items.push(i),this.size++),t&&("ttl"in t&&this.expire(r,t.ttl),"meta"in t&&(i.meta=t.meta),t.refresh&&(i.refresh=t.ttl)),this};Xn.delete=function(r){var e=this._lookup[r];return e?(this.lastModified=new Date,this.items.splice(this.items.indexOf(e),1),clearTimeout(e.timeout),delete this._lookup[r],this.size--,this):!1};Xn.expire=function(r,e){var t=e||0,n=this._lookup[r];if(!n)return this;if(typeof t=="string"&&(t=t4(e)),typeof t!="number")throw new TypeError("Expiration time must be a string or number.");return clearTimeout(n.timeout),n.timeout=setTimeout(this.delete.bind(this,n.key),t),n.expires=Number(new Date)+t,this};Xn.clear=function(){for(var r=this.items.length;r--;)this.delete(this.items[r].key);return this};Xn.toJSON=function(){for(var r=new Array(this.items.length),e,t=r.length;t--;)e=this.items[t],r[t]={key:e.key,meta:e.meta,value:e.value,expires:e.expires,refresh:e.refresh};return{id:this.id,max:isFinite(this.max)?this.max:void 0,lastModified:this.lastModified,items:r}}});var jd=me((SD,og)=>{og.exports=function(r){if(!r)throw Error("hashlru must have a max value, of type number, greater than 0");var e=0,t=Object.create(null),n=Object.create(null);function i(o,s){t[o]=s,e++,e>=r&&(e=0,n=t,t=Object.create(null))}return{has:function(o){return t[o]!==void 0||n[o]!==void 0},remove:function(o){t[o]!==void 0&&(t[o]=void 0),n[o]!==void 0&&(n[o]=void 0)},get:function(o){var s=t[o];if(s!==void 0)return s;if((s=n[o])!==void 0)return i(o,s),s},set:function(o,s){t[o]!==void 0?t[o]=s:i(o,s)},clear:function(){t=Object.create(null),n=Object.create(null)}}}});var xg=me(Al=>{"use strict";Al.byteLength=d4;Al.toByteArray=p4;Al.fromByteArray=g4;var Br=[],qt=[],h4=typeof Uint8Array<"u"?Uint8Array:Array,Jd="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(ki=0,gg=Jd.length;ki<gg;++ki)Br[ki]=Jd[ki],qt[Jd.charCodeAt(ki)]=ki;var ki,gg;qt[45]=62;qt[95]=63;function wg(r){var e=r.length;if(e%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var t=r.indexOf("=");t===-1&&(t=e);var n=t===e?0:4-t%4;return[t,n]}function d4(r){var e=wg(r),t=e[0],n=e[1];return(t+n)*3/4-n}function f4(r,e,t){return(e+t)*3/4-t}function p4(r){var e,t=wg(r),n=t[0],i=t[1],o=new h4(f4(r,n,i)),s=0,a=i>0?n-4:n,c;for(c=0;c<a;c+=4)e=qt[r.charCodeAt(c)]<<18|qt[r.charCodeAt(c+1)]<<12|qt[r.charCodeAt(c+2)]<<6|qt[r.charCodeAt(c+3)],o[s++]=e>>16&255,o[s++]=e>>8&255,o[s++]=e&255;return i===2&&(e=qt[r.charCodeAt(c)]<<2|qt[r.charCodeAt(c+1)]>>4,o[s++]=e&255),i===1&&(e=qt[r.charCodeAt(c)]<<10|qt[r.charCodeAt(c+1)]<<4|qt[r.charCodeAt(c+2)]>>2,o[s++]=e>>8&255,o[s++]=e&255),o}function m4(r){return Br[r>>18&63]+Br[r>>12&63]+Br[r>>6&63]+Br[r&63]}function y4(r,e,t){for(var n,i=[],o=e;o<t;o+=3)n=(r[o]<<16&16711680)+(r[o+1]<<8&65280)+(r[o+2]&255),i.push(m4(n));return i.join("")}function g4(r){for(var e,t=r.length,n=t%3,i=[],o=16383,s=0,a=t-n;s<a;s+=o)i.push(y4(r,s,s+o>a?a:s+o));return n===1?(e=r[t-1],i.push(Br[e>>2]+Br[e<<4&63]+"==")):n===2&&(e=(r[t-2]<<8)+r[t-1],i.push(Br[e>>10]+Br[e>>4&63]+Br[e<<2&63]+"=")),i.join("")}});var bg=me(Qd=>{Qd.read=function(r,e,t,n,i){var o,s,a=i*8-n-1,c=(1<<a)-1,u=c>>1,l=-7,h=t?i-1:0,p=t?-1:1,d=r[e+h];for(h+=p,o=d&(1<<-l)-1,d>>=-l,l+=a;l>0;o=o*256+r[e+h],h+=p,l-=8);for(s=o&(1<<-l)-1,o>>=-l,l+=n;l>0;s=s*256+r[e+h],h+=p,l-=8);if(o===0)o=1-u;else{if(o===c)return s?NaN:(d?-1:1)*(1/0);s=s+Math.pow(2,n),o=o-u}return(d?-1:1)*s*Math.pow(2,o-n)};Qd.write=function(r,e,t,n,i,o){var s,a,c,u=o*8-i-1,l=(1<<u)-1,h=l>>1,p=i===23?Math.pow(2,-24)-Math.pow(2,-77):0,d=n?0:o-1,f=n?1:-1,m=e<0||e===0&&1/e<0?1:0;for(e=Math.abs(e),isNaN(e)||e===1/0?(a=isNaN(e)?1:0,s=l):(s=Math.floor(Math.log(e)/Math.LN2),e*(c=Math.pow(2,-s))<1&&(s--,c*=2),s+h>=1?e+=p/c:e+=p*Math.pow(2,1-h),e*c>=2&&(s++,c/=2),s+h>=l?(a=0,s=l):s+h>=1?(a=(e*c-1)*Math.pow(2,i),s=s+h):(a=e*Math.pow(2,h-1)*Math.pow(2,i),s=0));i>=8;r[t+d]=a&255,d+=f,a/=256,i-=8);for(s=s<<i|a,u+=i;u>0;r[t+d]=s&255,d+=f,s/=256,u-=8);r[t+d-f]|=m*128}});var lf=me(No=>{"use strict";var ef=xg(),To=bg(),Eg=typeof Symbol=="function"&&typeof Symbol.for=="function"?Symbol.for("nodejs.util.inspect.custom"):null;No.Buffer=S;No.SlowBuffer=B4;No.INSPECT_MAX_BYTES=50;var Il=2147483647;No.kMaxLength=Il;S.TYPED_ARRAY_SUPPORT=w4();!S.TYPED_ARRAY_SUPPORT&&typeof console<"u"&&typeof console.error=="function"&&console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support.");function w4(){try{let r=new Uint8Array(1),e={foo:function(){return 42}};return Object.setPrototypeOf(e,Uint8Array.prototype),Object.setPrototypeOf(r,e),r.foo()===42}catch{return!1}}Object.defineProperty(S.prototype,"parent",{enumerable:!0,get:function(){if(S.isBuffer(this))return this.buffer}});Object.defineProperty(S.prototype,"offset",{enumerable:!0,get:function(){if(S.isBuffer(this))return this.byteOffset}});function cn(r){if(r>Il)throw new RangeError('The value "'+r+'" is invalid for option "size"');let e=new Uint8Array(r);return Object.setPrototypeOf(e,S.prototype),e}function S(r,e,t){if(typeof r=="number"){if(typeof e=="string")throw new TypeError('The "string" argument must be of type string. Received type number');return of(r)}return Ig(r,e,t)}S.poolSize=8192;function Ig(r,e,t){if(typeof r=="string")return b4(r,e);if(ArrayBuffer.isView(r))return E4(r);if(r==null)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof r);if(Ar(r,ArrayBuffer)||r&&Ar(r.buffer,ArrayBuffer)||typeof SharedArrayBuffer<"u"&&(Ar(r,SharedArrayBuffer)||r&&Ar(r.buffer,SharedArrayBuffer)))return rf(r,e,t);if(typeof r=="number")throw new TypeError('The "value" argument must not be of type number. Received type number');let n=r.valueOf&&r.valueOf();if(n!=null&&n!==r)return S.from(n,e,t);let i=v4(r);if(i)return i;if(typeof Symbol<"u"&&Symbol.toPrimitive!=null&&typeof r[Symbol.toPrimitive]=="function")return S.from(r[Symbol.toPrimitive]("string"),e,t);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof r)}S.from=function(r,e,t){return Ig(r,e,t)};Object.setPrototypeOf(S.prototype,Uint8Array.prototype);Object.setPrototypeOf(S,Uint8Array);function Sg(r){if(typeof r!="number")throw new TypeError('"size" argument must be of type number');if(r<0)throw new RangeError('The value "'+r+'" is invalid for option "size"')}function x4(r,e,t){return Sg(r),r<=0?cn(r):e!==void 0?typeof t=="string"?cn(r).fill(e,t):cn(r).fill(e):cn(r)}S.alloc=function(r,e,t){return x4(r,e,t)};function of(r){return Sg(r),cn(r<0?0:sf(r)|0)}S.allocUnsafe=function(r){return of(r)};S.allocUnsafeSlow=function(r){return of(r)};function b4(r,e){if((typeof e!="string"||e==="")&&(e="utf8"),!S.isEncoding(e))throw new TypeError("Unknown encoding: "+e);let t=_g(r,e)|0,n=cn(t),i=n.write(r,e);return i!==t&&(n=n.slice(0,i)),n}function tf(r){let e=r.length<0?0:sf(r.length)|0,t=cn(e);for(let n=0;n<e;n+=1)t[n]=r[n]&255;return t}function E4(r){if(Ar(r,Uint8Array)){let e=new Uint8Array(r);return rf(e.buffer,e.byteOffset,e.byteLength)}return tf(r)}function rf(r,e,t){if(e<0||r.byteLength<e)throw new RangeError('"offset" is outside of buffer bounds');if(r.byteLength<e+(t||0))throw new RangeError('"length" is outside of buffer bounds');let n;return e===void 0&&t===void 0?n=new Uint8Array(r):t===void 0?n=new Uint8Array(r,e):n=new Uint8Array(r,e,t),Object.setPrototypeOf(n,S.prototype),n}function v4(r){if(S.isBuffer(r)){let e=sf(r.length)|0,t=cn(e);return t.length===0||r.copy(t,0,0,e),t}if(r.length!==void 0)return typeof r.length!="number"||cf(r.length)?cn(0):tf(r);if(r.type==="Buffer"&&Array.isArray(r.data))return tf(r.data)}function sf(r){if(r>=Il)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+Il.toString(16)+" bytes");return r|0}function B4(r){return+r!=r&&(r=0),S.alloc(+r)}S.isBuffer=function(e){return e!=null&&e._isBuffer===!0&&e!==S.prototype};S.compare=function(e,t){if(Ar(e,Uint8Array)&&(e=S.from(e,e.offset,e.byteLength)),Ar(t,Uint8Array)&&(t=S.from(t,t.offset,t.byteLength)),!S.isBuffer(e)||!S.isBuffer(t))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(e===t)return 0;let n=e.length,i=t.length;for(let o=0,s=Math.min(n,i);o<s;++o)if(e[o]!==t[o]){n=e[o],i=t[o];break}return n<i?-1:i<n?1:0};S.isEncoding=function(e){switch(String(e).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}};S.concat=function(e,t){if(!Array.isArray(e))throw new TypeError('"list" argument must be an Array of Buffers');if(e.length===0)return S.alloc(0);let n;if(t===void 0)for(t=0,n=0;n<e.length;++n)t+=e[n].length;let i=S.allocUnsafe(t),o=0;for(n=0;n<e.length;++n){let s=e[n];if(Ar(s,Uint8Array))o+s.length>i.length?(S.isBuffer(s)||(s=S.from(s)),s.copy(i,o)):Uint8Array.prototype.set.call(i,s,o);else if(S.isBuffer(s))s.copy(i,o);else throw new TypeError('"list" argument must be an Array of Buffers');o+=s.length}return i};function _g(r,e){if(S.isBuffer(r))return r.length;if(ArrayBuffer.isView(r)||Ar(r,ArrayBuffer))return r.byteLength;if(typeof r!="string")throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof r);let t=r.length,n=arguments.length>2&&arguments[2]===!0;if(!n&&t===0)return 0;let i=!1;for(;;)switch(e){case"ascii":case"latin1":case"binary":return t;case"utf8":case"utf-8":return nf(r).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return t*2;case"hex":return t>>>1;case"base64":return Pg(r).length;default:if(i)return n?-1:nf(r).length;e=(""+e).toLowerCase(),i=!0}}S.byteLength=_g;function A4(r,e,t){let n=!1;if((e===void 0||e<0)&&(e=0),e>this.length||((t===void 0||t>this.length)&&(t=this.length),t<=0)||(t>>>=0,e>>>=0,t<=e))return"";for(r||(r="utf8");;)switch(r){case"hex":return L4(this,e,t);case"utf8":case"utf-8":return Rg(this,e,t);case"ascii":return N4(this,e,t);case"latin1":case"binary":return U4(this,e,t);case"base64":return T4(this,e,t);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return D4(this,e,t);default:if(n)throw new TypeError("Unknown encoding: "+r);r=(r+"").toLowerCase(),n=!0}}S.prototype._isBuffer=!0;function Ri(r,e,t){let n=r[e];r[e]=r[t],r[t]=n}S.prototype.swap16=function(){let e=this.length;if(e%2!==0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(let t=0;t<e;t+=2)Ri(this,t,t+1);return this};S.prototype.swap32=function(){let e=this.length;if(e%4!==0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(let t=0;t<e;t+=4)Ri(this,t,t+3),Ri(this,t+1,t+2);return this};S.prototype.swap64=function(){let e=this.length;if(e%8!==0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(let t=0;t<e;t+=8)Ri(this,t,t+7),Ri(this,t+1,t+6),Ri(this,t+2,t+5),Ri(this,t+3,t+4);return this};S.prototype.toString=function(){let e=this.length;return e===0?"":arguments.length===0?Rg(this,0,e):A4.apply(this,arguments)};S.prototype.toLocaleString=S.prototype.toString;S.prototype.equals=function(e){if(!S.isBuffer(e))throw new TypeError("Argument must be a Buffer");return this===e?!0:S.compare(this,e)===0};S.prototype.inspect=function(){let e="",t=No.INSPECT_MAX_BYTES;return e=this.toString("hex",0,t).replace(/(.{2})/g,"$1 ").trim(),this.length>t&&(e+=" ... "),"<Buffer "+e+">"};Eg&&(S.prototype[Eg]=S.prototype.inspect);S.prototype.compare=function(e,t,n,i,o){if(Ar(e,Uint8Array)&&(e=S.from(e,e.offset,e.byteLength)),!S.isBuffer(e))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof e);if(t===void 0&&(t=0),n===void 0&&(n=e?e.length:0),i===void 0&&(i=0),o===void 0&&(o=this.length),t<0||n>e.length||i<0||o>this.length)throw new RangeError("out of range index");if(i>=o&&t>=n)return 0;if(i>=o)return-1;if(t>=n)return 1;if(t>>>=0,n>>>=0,i>>>=0,o>>>=0,this===e)return 0;let s=o-i,a=n-t,c=Math.min(s,a),u=this.slice(i,o),l=e.slice(t,n);for(let h=0;h<c;++h)if(u[h]!==l[h]){s=u[h],a=l[h];break}return s<a?-1:a<s?1:0};function kg(r,e,t,n,i){if(r.length===0)return-1;if(typeof t=="string"?(n=t,t=0):t>2147483647?t=2147483647:t<-2147483648&&(t=-2147483648),t=+t,cf(t)&&(t=i?0:r.length-1),t<0&&(t=r.length+t),t>=r.length){if(i)return-1;t=r.length-1}else if(t<0)if(i)t=0;else return-1;if(typeof e=="string"&&(e=S.from(e,n)),S.isBuffer(e))return e.length===0?-1:vg(r,e,t,n,i);if(typeof e=="number")return e=e&255,typeof Uint8Array.prototype.indexOf=="function"?i?Uint8Array.prototype.indexOf.call(r,e,t):Uint8Array.prototype.lastIndexOf.call(r,e,t):vg(r,[e],t,n,i);throw new TypeError("val must be string, number or Buffer")}function vg(r,e,t,n,i){let o=1,s=r.length,a=e.length;if(n!==void 0&&(n=String(n).toLowerCase(),n==="ucs2"||n==="ucs-2"||n==="utf16le"||n==="utf-16le")){if(r.length<2||e.length<2)return-1;o=2,s/=2,a/=2,t/=2}function c(l,h){return o===1?l[h]:l.readUInt16BE(h*o)}let u;if(i){let l=-1;for(u=t;u<s;u++)if(c(r,u)===c(e,l===-1?0:u-l)){if(l===-1&&(l=u),u-l+1===a)return l*o}else l!==-1&&(u-=u-l),l=-1}else for(t+a>s&&(t=s-a),u=t;u>=0;u--){let l=!0;for(let h=0;h<a;h++)if(c(r,u+h)!==c(e,h)){l=!1;break}if(l)return u}return-1}S.prototype.includes=function(e,t,n){return this.indexOf(e,t,n)!==-1};S.prototype.indexOf=function(e,t,n){return kg(this,e,t,n,!0)};S.prototype.lastIndexOf=function(e,t,n){return kg(this,e,t,n,!1)};function I4(r,e,t,n){t=Number(t)||0;let i=r.length-t;n?(n=Number(n),n>i&&(n=i)):n=i;let o=e.length;n>o/2&&(n=o/2);let s;for(s=0;s<n;++s){let a=parseInt(e.substr(s*2,2),16);if(cf(a))return s;r[t+s]=a}return s}function S4(r,e,t,n){return Sl(nf(e,r.length-t),r,t,n)}function _4(r,e,t,n){return Sl(V4(e),r,t,n)}function k4(r,e,t,n){return Sl(Pg(e),r,t,n)}function R4(r,e,t,n){return Sl(M4(e,r.length-t),r,t,n)}S.prototype.write=function(e,t,n,i){if(t===void 0)i="utf8",n=this.length,t=0;else if(n===void 0&&typeof t=="string")i=t,n=this.length,t=0;else if(isFinite(t))t=t>>>0,isFinite(n)?(n=n>>>0,i===void 0&&(i="utf8")):(i=n,n=void 0);else throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");let o=this.length-t;if((n===void 0||n>o)&&(n=o),e.length>0&&(n<0||t<0)||t>this.length)throw new RangeError("Attempt to write outside buffer bounds");i||(i="utf8");let s=!1;for(;;)switch(i){case"hex":return I4(this,e,t,n);case"utf8":case"utf-8":return S4(this,e,t,n);case"ascii":case"latin1":case"binary":return _4(this,e,t,n);case"base64":return k4(this,e,t,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return R4(this,e,t,n);default:if(s)throw new TypeError("Unknown encoding: "+i);i=(""+i).toLowerCase(),s=!0}};S.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function T4(r,e,t){return e===0&&t===r.length?ef.fromByteArray(r):ef.fromByteArray(r.slice(e,t))}function Rg(r,e,t){t=Math.min(r.length,t);let n=[],i=e;for(;i<t;){let o=r[i],s=null,a=o>239?4:o>223?3:o>191?2:1;if(i+a<=t){let c,u,l,h;switch(a){case 1:o<128&&(s=o);break;case 2:c=r[i+1],(c&192)===128&&(h=(o&31)<<6|c&63,h>127&&(s=h));break;case 3:c=r[i+1],u=r[i+2],(c&192)===128&&(u&192)===128&&(h=(o&15)<<12|(c&63)<<6|u&63,h>2047&&(h<55296||h>57343)&&(s=h));break;case 4:c=r[i+1],u=r[i+2],l=r[i+3],(c&192)===128&&(u&192)===128&&(l&192)===128&&(h=(o&15)<<18|(c&63)<<12|(u&63)<<6|l&63,h>65535&&h<1114112&&(s=h))}}s===null?(s=65533,a=1):s>65535&&(s-=65536,n.push(s>>>10&1023|55296),s=56320|s&1023),n.push(s),i+=a}return C4(n)}var Bg=4096;function C4(r){let e=r.length;if(e<=Bg)return String.fromCharCode.apply(String,r);let t="",n=0;for(;n<e;)t+=String.fromCharCode.apply(String,r.slice(n,n+=Bg));return t}function N4(r,e,t){let n="";t=Math.min(r.length,t);for(let i=e;i<t;++i)n+=String.fromCharCode(r[i]&127);return n}function U4(r,e,t){let n="";t=Math.min(r.length,t);for(let i=e;i<t;++i)n+=String.fromCharCode(r[i]);return n}function L4(r,e,t){let n=r.length;(!e||e<0)&&(e=0),(!t||t<0||t>n)&&(t=n);let i="";for(let o=e;o<t;++o)i+=H4[r[o]];return i}function D4(r,e,t){let n=r.slice(e,t),i="";for(let o=0;o<n.length-1;o+=2)i+=String.fromCharCode(n[o]+n[o+1]*256);return i}S.prototype.slice=function(e,t){let n=this.length;e=~~e,t=t===void 0?n:~~t,e<0?(e+=n,e<0&&(e=0)):e>n&&(e=n),t<0?(t+=n,t<0&&(t=0)):t>n&&(t=n),t<e&&(t=e);let i=this.subarray(e,t);return Object.setPrototypeOf(i,S.prototype),i};function He(r,e,t){if(r%1!==0||r<0)throw new RangeError("offset is not uint");if(r+e>t)throw new RangeError("Trying to access beyond buffer length")}S.prototype.readUintLE=S.prototype.readUIntLE=function(e,t,n){e=e>>>0,t=t>>>0,n||He(e,t,this.length);let i=this[e],o=1,s=0;for(;++s<t&&(o*=256);)i+=this[e+s]*o;return i};S.prototype.readUintBE=S.prototype.readUIntBE=function(e,t,n){e=e>>>0,t=t>>>0,n||He(e,t,this.length);let i=this[e+--t],o=1;for(;t>0&&(o*=256);)i+=this[e+--t]*o;return i};S.prototype.readUint8=S.prototype.readUInt8=function(e,t){return e=e>>>0,t||He(e,1,this.length),this[e]};S.prototype.readUint16LE=S.prototype.readUInt16LE=function(e,t){return e=e>>>0,t||He(e,2,this.length),this[e]|this[e+1]<<8};S.prototype.readUint16BE=S.prototype.readUInt16BE=function(e,t){return e=e>>>0,t||He(e,2,this.length),this[e]<<8|this[e+1]};S.prototype.readUint32LE=S.prototype.readUInt32LE=function(e,t){return e=e>>>0,t||He(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+this[e+3]*16777216};S.prototype.readUint32BE=S.prototype.readUInt32BE=function(e,t){return e=e>>>0,t||He(e,4,this.length),this[e]*16777216+(this[e+1]<<16|this[e+2]<<8|this[e+3])};S.prototype.readBigUInt64LE=Jn(function(e){e=e>>>0,Co(e,"offset");let t=this[e],n=this[e+7];(t===void 0||n===void 0)&&zs(e,this.length-8);let i=t+this[++e]*2**8+this[++e]*2**16+this[++e]*2**24,o=this[++e]+this[++e]*2**8+this[++e]*2**16+n*2**24;return BigInt(i)+(BigInt(o)<<BigInt(32))});S.prototype.readBigUInt64BE=Jn(function(e){e=e>>>0,Co(e,"offset");let t=this[e],n=this[e+7];(t===void 0||n===void 0)&&zs(e,this.length-8);let i=t*2**24+this[++e]*2**16+this[++e]*2**8+this[++e],o=this[++e]*2**24+this[++e]*2**16+this[++e]*2**8+n;return(BigInt(i)<<BigInt(32))+BigInt(o)});S.prototype.readIntLE=function(e,t,n){e=e>>>0,t=t>>>0,n||He(e,t,this.length);let i=this[e],o=1,s=0;for(;++s<t&&(o*=256);)i+=this[e+s]*o;return o*=128,i>=o&&(i-=Math.pow(2,8*t)),i};S.prototype.readIntBE=function(e,t,n){e=e>>>0,t=t>>>0,n||He(e,t,this.length);let i=t,o=1,s=this[e+--i];for(;i>0&&(o*=256);)s+=this[e+--i]*o;return o*=128,s>=o&&(s-=Math.pow(2,8*t)),s};S.prototype.readInt8=function(e,t){return e=e>>>0,t||He(e,1,this.length),this[e]&128?(255-this[e]+1)*-1:this[e]};S.prototype.readInt16LE=function(e,t){e=e>>>0,t||He(e,2,this.length);let n=this[e]|this[e+1]<<8;return n&32768?n|4294901760:n};S.prototype.readInt16BE=function(e,t){e=e>>>0,t||He(e,2,this.length);let n=this[e+1]|this[e]<<8;return n&32768?n|4294901760:n};S.prototype.readInt32LE=function(e,t){return e=e>>>0,t||He(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24};S.prototype.readInt32BE=function(e,t){return e=e>>>0,t||He(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]};S.prototype.readBigInt64LE=Jn(function(e){e=e>>>0,Co(e,"offset");let t=this[e],n=this[e+7];(t===void 0||n===void 0)&&zs(e,this.length-8);let i=this[e+4]+this[e+5]*2**8+this[e+6]*2**16+(n<<24);return(BigInt(i)<<BigInt(32))+BigInt(t+this[++e]*2**8+this[++e]*2**16+this[++e]*2**24)});S.prototype.readBigInt64BE=Jn(function(e){e=e>>>0,Co(e,"offset");let t=this[e],n=this[e+7];(t===void 0||n===void 0)&&zs(e,this.length-8);let i=(t<<24)+this[++e]*2**16+this[++e]*2**8+this[++e];return(BigInt(i)<<BigInt(32))+BigInt(this[++e]*2**24+this[++e]*2**16+this[++e]*2**8+n)});S.prototype.readFloatLE=function(e,t){return e=e>>>0,t||He(e,4,this.length),To.read(this,e,!0,23,4)};S.prototype.readFloatBE=function(e,t){return e=e>>>0,t||He(e,4,this.length),To.read(this,e,!1,23,4)};S.prototype.readDoubleLE=function(e,t){return e=e>>>0,t||He(e,8,this.length),To.read(this,e,!0,52,8)};S.prototype.readDoubleBE=function(e,t){return e=e>>>0,t||He(e,8,this.length),To.read(this,e,!1,52,8)};function wt(r,e,t,n,i,o){if(!S.isBuffer(r))throw new TypeError('"buffer" argument must be a Buffer instance');if(e>i||e<o)throw new RangeError('"value" argument is out of bounds');if(t+n>r.length)throw new RangeError("Index out of range")}S.prototype.writeUintLE=S.prototype.writeUIntLE=function(e,t,n,i){if(e=+e,t=t>>>0,n=n>>>0,!i){let a=Math.pow(2,8*n)-1;wt(this,e,t,n,a,0)}let o=1,s=0;for(this[t]=e&255;++s<n&&(o*=256);)this[t+s]=e/o&255;return t+n};S.prototype.writeUintBE=S.prototype.writeUIntBE=function(e,t,n,i){if(e=+e,t=t>>>0,n=n>>>0,!i){let a=Math.pow(2,8*n)-1;wt(this,e,t,n,a,0)}let o=n-1,s=1;for(this[t+o]=e&255;--o>=0&&(s*=256);)this[t+o]=e/s&255;return t+n};S.prototype.writeUint8=S.prototype.writeUInt8=function(e,t,n){return e=+e,t=t>>>0,n||wt(this,e,t,1,255,0),this[t]=e&255,t+1};S.prototype.writeUint16LE=S.prototype.writeUInt16LE=function(e,t,n){return e=+e,t=t>>>0,n||wt(this,e,t,2,65535,0),this[t]=e&255,this[t+1]=e>>>8,t+2};S.prototype.writeUint16BE=S.prototype.writeUInt16BE=function(e,t,n){return e=+e,t=t>>>0,n||wt(this,e,t,2,65535,0),this[t]=e>>>8,this[t+1]=e&255,t+2};S.prototype.writeUint32LE=S.prototype.writeUInt32LE=function(e,t,n){return e=+e,t=t>>>0,n||wt(this,e,t,4,4294967295,0),this[t+3]=e>>>24,this[t+2]=e>>>16,this[t+1]=e>>>8,this[t]=e&255,t+4};S.prototype.writeUint32BE=S.prototype.writeUInt32BE=function(e,t,n){return e=+e,t=t>>>0,n||wt(this,e,t,4,4294967295,0),this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=e&255,t+4};function Tg(r,e,t,n,i){Dg(e,n,i,r,t,7);let o=Number(e&BigInt(4294967295));r[t++]=o,o=o>>8,r[t++]=o,o=o>>8,r[t++]=o,o=o>>8,r[t++]=o;let s=Number(e>>BigInt(32)&BigInt(4294967295));return r[t++]=s,s=s>>8,r[t++]=s,s=s>>8,r[t++]=s,s=s>>8,r[t++]=s,t}function Cg(r,e,t,n,i){Dg(e,n,i,r,t,7);let o=Number(e&BigInt(4294967295));r[t+7]=o,o=o>>8,r[t+6]=o,o=o>>8,r[t+5]=o,o=o>>8,r[t+4]=o;let s=Number(e>>BigInt(32)&BigInt(4294967295));return r[t+3]=s,s=s>>8,r[t+2]=s,s=s>>8,r[t+1]=s,s=s>>8,r[t]=s,t+8}S.prototype.writeBigUInt64LE=Jn(function(e,t=0){return Tg(this,e,t,BigInt(0),BigInt("0xffffffffffffffff"))});S.prototype.writeBigUInt64BE=Jn(function(e,t=0){return Cg(this,e,t,BigInt(0),BigInt("0xffffffffffffffff"))});S.prototype.writeIntLE=function(e,t,n,i){if(e=+e,t=t>>>0,!i){let c=Math.pow(2,8*n-1);wt(this,e,t,n,c-1,-c)}let o=0,s=1,a=0;for(this[t]=e&255;++o<n&&(s*=256);)e<0&&a===0&&this[t+o-1]!==0&&(a=1),this[t+o]=(e/s>>0)-a&255;return t+n};S.prototype.writeIntBE=function(e,t,n,i){if(e=+e,t=t>>>0,!i){let c=Math.pow(2,8*n-1);wt(this,e,t,n,c-1,-c)}let o=n-1,s=1,a=0;for(this[t+o]=e&255;--o>=0&&(s*=256);)e<0&&a===0&&this[t+o+1]!==0&&(a=1),this[t+o]=(e/s>>0)-a&255;return t+n};S.prototype.writeInt8=function(e,t,n){return e=+e,t=t>>>0,n||wt(this,e,t,1,127,-128),e<0&&(e=255+e+1),this[t]=e&255,t+1};S.prototype.writeInt16LE=function(e,t,n){return e=+e,t=t>>>0,n||wt(this,e,t,2,32767,-32768),this[t]=e&255,this[t+1]=e>>>8,t+2};S.prototype.writeInt16BE=function(e,t,n){return e=+e,t=t>>>0,n||wt(this,e,t,2,32767,-32768),this[t]=e>>>8,this[t+1]=e&255,t+2};S.prototype.writeInt32LE=function(e,t,n){return e=+e,t=t>>>0,n||wt(this,e,t,4,2147483647,-2147483648),this[t]=e&255,this[t+1]=e>>>8,this[t+2]=e>>>16,this[t+3]=e>>>24,t+4};S.prototype.writeInt32BE=function(e,t,n){return e=+e,t=t>>>0,n||wt(this,e,t,4,2147483647,-2147483648),e<0&&(e=4294967295+e+1),this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=e&255,t+4};S.prototype.writeBigInt64LE=Jn(function(e,t=0){return Tg(this,e,t,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});S.prototype.writeBigInt64BE=Jn(function(e,t=0){return Cg(this,e,t,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});function Ng(r,e,t,n,i,o){if(t+n>r.length)throw new RangeError("Index out of range");if(t<0)throw new RangeError("Index out of range")}function Ug(r,e,t,n,i){return e=+e,t=t>>>0,i||Ng(r,e,t,4,34028234663852886e22,-34028234663852886e22),To.write(r,e,t,n,23,4),t+4}S.prototype.writeFloatLE=function(e,t,n){return Ug(this,e,t,!0,n)};S.prototype.writeFloatBE=function(e,t,n){return Ug(this,e,t,!1,n)};function Lg(r,e,t,n,i){return e=+e,t=t>>>0,i||Ng(r,e,t,8,17976931348623157e292,-17976931348623157e292),To.write(r,e,t,n,52,8),t+8}S.prototype.writeDoubleLE=function(e,t,n){return Lg(this,e,t,!0,n)};S.prototype.writeDoubleBE=function(e,t,n){return Lg(this,e,t,!1,n)};S.prototype.copy=function(e,t,n,i){if(!S.isBuffer(e))throw new TypeError("argument should be a Buffer");if(n||(n=0),!i&&i!==0&&(i=this.length),t>=e.length&&(t=e.length),t||(t=0),i>0&&i<n&&(i=n),i===n||e.length===0||this.length===0)return 0;if(t<0)throw new RangeError("targetStart out of bounds");if(n<0||n>=this.length)throw new RangeError("Index out of range");if(i<0)throw new RangeError("sourceEnd out of bounds");i>this.length&&(i=this.length),e.length-t<i-n&&(i=e.length-t+n);let o=i-n;return this===e&&typeof Uint8Array.prototype.copyWithin=="function"?this.copyWithin(t,n,i):Uint8Array.prototype.set.call(e,this.subarray(n,i),t),o};S.prototype.fill=function(e,t,n,i){if(typeof e=="string"){if(typeof t=="string"?(i=t,t=0,n=this.length):typeof n=="string"&&(i=n,n=this.length),i!==void 0&&typeof i!="string")throw new TypeError("encoding must be a string");if(typeof i=="string"&&!S.isEncoding(i))throw new TypeError("Unknown encoding: "+i);if(e.length===1){let s=e.charCodeAt(0);(i==="utf8"&&s<128||i==="latin1")&&(e=s)}}else typeof e=="number"?e=e&255:typeof e=="boolean"&&(e=Number(e));if(t<0||this.length<t||this.length<n)throw new RangeError("Out of range index");if(n<=t)return this;t=t>>>0,n=n===void 0?this.length:n>>>0,e||(e=0);let o;if(typeof e=="number")for(o=t;o<n;++o)this[o]=e;else{let s=S.isBuffer(e)?e:S.from(e,i),a=s.length;if(a===0)throw new TypeError('The value "'+e+'" is invalid for argument "value"');for(o=0;o<n-t;++o)this[o+t]=s[o%a]}return this};var Ro={};function af(r,e,t){Ro[r]=class extends t{constructor(){super(),Object.defineProperty(this,"message",{value:e.apply(this,arguments),writable:!0,configurable:!0}),this.name=`${this.name} [${r}]`,this.stack,delete this.name}get code(){return r}set code(i){Object.defineProperty(this,"code",{configurable:!0,enumerable:!0,value:i,writable:!0})}toString(){return`${this.name} [${r}]: ${this.message}`}}}af("ERR_BUFFER_OUT_OF_BOUNDS",function(r){return r?`${r} is outside of buffer bounds`:"Attempt to access memory outside buffer bounds"},RangeError);af("ERR_INVALID_ARG_TYPE",function(r,e){return`The "${r}" argument must be of type number. Received type ${typeof e}`},TypeError);af("ERR_OUT_OF_RANGE",function(r,e,t){let n=`The value of "${r}" is out of range.`,i=t;return Number.isInteger(t)&&Math.abs(t)>2**32?i=Ag(String(t)):typeof t=="bigint"&&(i=String(t),(t>BigInt(2)**BigInt(32)||t<-(BigInt(2)**BigInt(32)))&&(i=Ag(i)),i+="n"),n+=` It must be ${e}. Received ${i}`,n},RangeError);function Ag(r){let e="",t=r.length,n=r[0]==="-"?1:0;for(;t>=n+4;t-=3)e=`_${r.slice(t-3,t)}${e}`;return`${r.slice(0,t)}${e}`}function P4(r,e,t){Co(e,"offset"),(r[e]===void 0||r[e+t]===void 0)&&zs(e,r.length-(t+1))}function Dg(r,e,t,n,i,o){if(r>t||r<e){let s=typeof e=="bigint"?"n":"",a;throw o>3?e===0||e===BigInt(0)?a=`>= 0${s} and < 2${s} ** ${(o+1)*8}${s}`:a=`>= -(2${s} ** ${(o+1)*8-1}${s}) and < 2 ** ${(o+1)*8-1}${s}`:a=`>= ${e}${s} and <= ${t}${s}`,new Ro.ERR_OUT_OF_RANGE("value",a,r)}P4(n,i,o)}function Co(r,e){if(typeof r!="number")throw new Ro.ERR_INVALID_ARG_TYPE(e,"number",r)}function zs(r,e,t){throw Math.floor(r)!==r?(Co(r,t),new Ro.ERR_OUT_OF_RANGE(t||"offset","an integer",r)):e<0?new Ro.ERR_BUFFER_OUT_OF_BOUNDS:new Ro.ERR_OUT_OF_RANGE(t||"offset",`>= ${t?1:0} and <= ${e}`,r)}var O4=/[^+/0-9A-Za-z-_]/g;function F4(r){if(r=r.split("=")[0],r=r.trim().replace(O4,""),r.length<2)return"";for(;r.length%4!==0;)r=r+"=";return r}function nf(r,e){e=e||1/0;let t,n=r.length,i=null,o=[];for(let s=0;s<n;++s){if(t=r.charCodeAt(s),t>55295&&t<57344){if(!i){if(t>56319){(e-=3)>-1&&o.push(239,191,189);continue}else if(s+1===n){(e-=3)>-1&&o.push(239,191,189);continue}i=t;continue}if(t<56320){(e-=3)>-1&&o.push(239,191,189),i=t;continue}t=(i-55296<<10|t-56320)+65536}else i&&(e-=3)>-1&&o.push(239,191,189);if(i=null,t<128){if((e-=1)<0)break;o.push(t)}else if(t<2048){if((e-=2)<0)break;o.push(t>>6|192,t&63|128)}else if(t<65536){if((e-=3)<0)break;o.push(t>>12|224,t>>6&63|128,t&63|128)}else if(t<1114112){if((e-=4)<0)break;o.push(t>>18|240,t>>12&63|128,t>>6&63|128,t&63|128)}else throw new Error("Invalid code point")}return o}function V4(r){let e=[];for(let t=0;t<r.length;++t)e.push(r.charCodeAt(t)&255);return e}function M4(r,e){let t,n,i,o=[];for(let s=0;s<r.length&&!((e-=2)<0);++s)t=r.charCodeAt(s),n=t>>8,i=t%256,o.push(i),o.push(n);return o}function Pg(r){return ef.toByteArray(F4(r))}function Sl(r,e,t,n){let i;for(i=0;i<n&&!(i+t>=e.length||i>=r.length);++i)e[i+t]=r[i];return i}function Ar(r,e){return r instanceof e||r!=null&&r.constructor!=null&&r.constructor.name!=null&&r.constructor.name===e.name}function cf(r){return r!==r}var H4=function(){let r="0123456789abcdef",e=new Array(256);for(let t=0;t<16;++t){let n=t*16;for(let i=0;i<16;++i)e[n+i]=r[t]+r[i]}return e}();function Jn(r){return typeof BigInt>"u"?$4:r}function $4(){throw new Error("BigInt not supported")}});var Og=me(uf=>{"use strict";uf.toString=function(r){switch(r){case 1:return"A";case 10:return"NULL";case 28:return"AAAA";case 18:return"AFSDB";case 42:return"APL";case 257:return"CAA";case 60:return"CDNSKEY";case 59:return"CDS";case 37:return"CERT";case 5:return"CNAME";case 49:return"DHCID";case 32769:return"DLV";case 39:return"DNAME";case 48:return"DNSKEY";case 43:return"DS";case 55:return"HIP";case 13:return"HINFO";case 45:return"IPSECKEY";case 25:return"KEY";case 36:return"KX";case 29:return"LOC";case 15:return"MX";case 35:return"NAPTR";case 2:return"NS";case 47:return"NSEC";case 50:return"NSEC3";case 51:return"NSEC3PARAM";case 12:return"PTR";case 46:return"RRSIG";case 17:return"RP";case 24:return"SIG";case 6:return"SOA";case 99:return"SPF";case 33:return"SRV";case 44:return"SSHFP";case 32768:return"TA";case 249:return"TKEY";case 52:return"TLSA";case 250:return"TSIG";case 16:return"TXT";case 252:return"AXFR";case 251:return"IXFR";case 41:return"OPT";case 255:return"ANY"}return"UNKNOWN_"+r};uf.toType=function(r){switch(r.toUpperCase()){case"A":return 1;case"NULL":return 10;case"AAAA":return 28;case"AFSDB":return 18;case"APL":return 42;case"CAA":return 257;case"CDNSKEY":return 60;case"CDS":return 59;case"CERT":return 37;case"CNAME":return 5;case"DHCID":return 49;case"DLV":return 32769;case"DNAME":return 39;case"DNSKEY":return 48;case"DS":return 43;case"HIP":return 55;case"HINFO":return 13;case"IPSECKEY":return 45;case"KEY":return 25;case"KX":return 36;case"LOC":return 29;case"MX":return 15;case"NAPTR":return 35;case"NS":return 2;case"NSEC":return 47;case"NSEC3":return 50;case"NSEC3PARAM":return 51;case"PTR":return 12;case"RRSIG":return 46;case"RP":return 17;case"SIG":return 24;case"SOA":return 6;case"SPF":return 99;case"SRV":return 33;case"SSHFP":return 44;case"TA":return 32768;case"TKEY":return 249;case"TLSA":return 52;case"TSIG":return 250;case"TXT":return 16;case"AXFR":return 252;case"IXFR":return 251;case"OPT":return 41;case"ANY":return 255;case"*":return 255}return r.toUpperCase().startsWith("UNKNOWN_")?parseInt(r.slice(8)):0}});var Fg=me(hf=>{"use strict";hf.toString=function(r){switch(r){case 0:return"NOERROR";case 1:return"FORMERR";case 2:return"SERVFAIL";case 3:return"NXDOMAIN";case 4:return"NOTIMP";case 5:return"REFUSED";case 6:return"YXDOMAIN";case 7:return"YXRRSET";case 8:return"NXRRSET";case 9:return"NOTAUTH";case 10:return"NOTZONE";case 11:return"RCODE_11";case 12:return"RCODE_12";case 13:return"RCODE_13";case 14:return"RCODE_14";case 15:return"RCODE_15"}return"RCODE_"+r};hf.toRcode=function(r){switch(r.toUpperCase()){case"NOERROR":return 0;case"FORMERR":return 1;case"SERVFAIL":return 2;case"NXDOMAIN":return 3;case"NOTIMP":return 4;case"REFUSED":return 5;case"YXDOMAIN":return 6;case"YXRRSET":return 7;case"NXRRSET":return 8;case"NOTAUTH":return 9;case"NOTZONE":return 10;case"RCODE_11":return 11;case"RCODE_12":return 12;case"RCODE_13":return 13;case"RCODE_14":return 14;case"RCODE_15":return 15}return 0}});var Vg=me(df=>{"use strict";df.toString=function(r){switch(r){case 0:return"QUERY";case 1:return"IQUERY";case 2:return"STATUS";case 3:return"OPCODE_3";case 4:return"NOTIFY";case 5:return"UPDATE";case 6:return"OPCODE_6";case 7:return"OPCODE_7";case 8:return"OPCODE_8";case 9:return"OPCODE_9";case 10:return"OPCODE_10";case 11:return"OPCODE_11";case 12:return"OPCODE_12";case 13:return"OPCODE_13";case 14:return"OPCODE_14";case 15:return"OPCODE_15"}return"OPCODE_"+r};df.toOpcode=function(r){switch(r.toUpperCase()){case"QUERY":return 0;case"IQUERY":return 1;case"STATUS":return 2;case"OPCODE_3":return 3;case"NOTIFY":return 4;case"UPDATE":return 5;case"OPCODE_6":return 6;case"OPCODE_7":return 7;case"OPCODE_8":return 8;case"OPCODE_9":return 9;case"OPCODE_10":return 10;case"OPCODE_11":return 11;case"OPCODE_12":return 12;case"OPCODE_13":return 13;case"OPCODE_14":return 14;case"OPCODE_15":return 15}return 0}});var Mg=me(ff=>{"use strict";ff.toString=function(r){switch(r){case 1:return"IN";case 2:return"CS";case 3:return"CH";case 4:return"HS";case 255:return"ANY"}return"UNKNOWN_"+r};ff.toClass=function(r){switch(r.toUpperCase()){case"IN":return 1;case"CS":return 2;case"CH":return 3;case"HS":return 4;case"ANY":return 255}return 0}});var Hg=me(pf=>{"use strict";pf.toString=function(r){switch(r){case 1:return"LLQ";case 2:return"UL";case 3:return"NSID";case 5:return"DAU";case 6:return"DHU";case 7:return"N3U";case 8:return"CLIENT_SUBNET";case 9:return"EXPIRE";case 10:return"COOKIE";case 11:return"TCP_KEEPALIVE";case 12:return"PADDING";case 13:return"CHAIN";case 14:return"KEY_TAG";case 26946:return"DEVICEID"}return r<0?null:`OPTION_${r}`};pf.toCode=function(r){if(typeof r=="number")return r;if(!r)return-1;switch(r.toUpperCase()){case"OPTION_0":return 0;case"LLQ":return 1;case"UL":return 2;case"NSID":return 3;case"OPTION_4":return 4;case"DAU":return 5;case"DHU":return 6;case"N3U":return 7;case"CLIENT_SUBNET":return 8;case"EXPIRE":return 9;case"COOKIE":return 10;case"TCP_KEEPALIVE":return 11;case"PADDING":return 12;case"CHAIN":return 13;case"KEY_TAG":return 14;case"DEVICEID":return 26946;case"OPTION_65535":return 65535}let e=r.match(/_(\d+)$/);return e?parseInt(e[1],10):-1}});var Kg=me((zg,mf)=>{var $g=function(r){"use strict";Object.defineProperty(r,"__esModule",{value:!0}),r.decode=h,r.encode=l,r.familyOf=u,r.name=void 0,r.sizeOf=c,r.v6=r.v4=void 0;let e=/^(\d{1,3}\.){3,3}\d{1,3}$/,t=4,n=/^(::)?(((\d{1,3}\.){3}(\d{1,3}){1})?([0-9a-f]){0,4}:{0,2}){1,8}(::)?$/i,i=16,o={name:"v4",size:t,isFormat:p=>e.test(p),encode(p,d,f){f=~~f,d=d||new Uint8Array(f+t);let m=p.length,y=0;for(let g=0;g<m;){let x=p.charCodeAt(g++);x===46?(d[f++]=y,y=0):y=y*10+(x-48)}return d[f]=y,d},decode(p,d){return d=~~d,`${p[d++]}.${p[d++]}.${p[d++]}.${p[d]}`}};r.v4=o;let s={name:"v6",size:i,isFormat:p=>p.length>0&&n.test(p),encode(p,d,f){f=~~f;let m=f+i,y=-1,g=0,x=0,b=!0,A=!1;d=d||new Uint8Array(f+i);for(let I=0;I<p.length;I++){let B=p.charCodeAt(I);B===58?(b?y!==-1?(f<m&&(d[f]=0),f<m-1&&(d[f+1]=0),f+=2):f<m&&(y=f):(A===!0?(f<m&&(d[f]=x),f++):(f<m&&(d[f]=g>>8),f<m-1&&(d[f+1]=g&255),f+=2),g=0,x=0),b=!0,A=!1):B===46?(f<m&&(d[f]=x),f++,x=0,g=0,b=!1,A=!0):(b=!1,B>=97?B-=87:B>=65?B-=55:(B-=48,x=x*10+B),g=(g<<4)+B)}if(b===!1)A===!0?(f<m&&(d[f]=x),f++):(f<m&&(d[f]=g>>8),f<m-1&&(d[f+1]=g&255),f+=2);else if(y===0)f<m&&(d[f]=0),f<m-1&&(d[f+1]=0),f+=2;else if(y!==-1){f+=2;for(let I=Math.min(f-1,m-1);I>=y+2;I--)d[I]=d[I-2];d[y]=0,d[y+1]=0,y=f}if(y!==f&&y!==-1)for(f>m-2&&(f=m-2);m>y;)d[--m]=f<m&&f>y?d[--f]:0;else for(;f<m;)d[f++]=0;return d},decode(p,d){d=~~d;let f="";for(let m=0;m<i;m+=2)m!==0&&(f+=":"),f+=(p[d+m]<<8|p[d+m+1]).toString(16);return f.replace(/(^|:)0(:0)*:0(:|$)/,"$1::$3").replace(/:{3,4}/,"::")}};r.v6=s;let a="ip";r.name=a;function c(p){if(o.isFormat(p))return o.size;if(s.isFormat(p))return s.size;throw Error(`Invalid ip address: ${p}`)}function u(p){return c(p)===o.size?1:2}function l(p,d,f){f=~~f;let m=c(p);return typeof d=="function"&&(d=d(f+m)),m===o.size?o.encode(p,d,f):s.encode(p,d,f)}function h(p,d,f){if(d=~~d,f=f||p.length-d,f===o.size)return o.decode(p,d,f);if(f===s.size)return s.decode(p,d,f);throw Error(`Invalid buffer size needs to be ${o.size} for v4 or ${s.size} for v6.`)}return"default"in r?r.default:r}({});typeof define=="function"&&define.amd?define([],function(){return $g}):typeof mf=="object"&&typeof zg=="object"&&(mf.exports=$g)});var Gg=me(q=>{"use strict";var j=lf().Buffer,wn=Og(),z4=Fg(),K4=Vg(),kl=Mg(),yf=Hg(),Ti=Kg(),q4=0,qg=32768,gf=32768,j4=~gf,jg=32768,G4=~jg,M=q.name={};M.encode=function(r,e,t,{mail:n=!1}={}){e||(e=j.alloc(M.encodingLength(r))),t||(t=0);let i=t,o=r.replace(/^\.|\.$/gm,"");if(o.length){let s=[];if(n){let a="";o.split(".").forEach(c=>{c.endsWith("\\")?a+=(a.length?".":"")+c.slice(0,-1):s.length===0&&a.length?s.push(a+"."+c):s.push(c)})}else s=o.split(".");for(let a=0;a<s.length;a++){let c=e.write(s[a],t+1);e[t]=c,t+=c+1}}return e[t++]=0,M.encode.bytes=t-i,e};M.encode.bytes=0;M.decode=function(r,e,{mail:t=!1}={}){e||(e=0);let n=[],i=e,o=0,s=0,a=!1;for(;;){if(e>=r.length)throw new Error("Cannot decode name (buffer overflow)");let c=r[e++];if(s+=a?0:1,c===0)break;if(c&192)if((c&192)===192){if(e+1>r.length)throw new Error("Cannot decode name (buffer overflow)");let u=r.readUInt16BE(e-1)-49152;if(u>=i)throw new Error("Cannot decode name (bad pointer)");e=u,i=u,s+=a?0:1,a=!0}else throw new Error("Cannot decode name (bad label)");else{if(e+c>r.length)throw new Error("Cannot decode name (buffer overflow)");if(o+=c+1,o>254)throw new Error("Cannot decode name (name too long)");let u=r.toString("utf-8",e,e+c);t&&(u=u.replace(/\./g,"\\.")),n.push(u),e+=c,s+=a?0:c}}return M.decode.bytes=s,n.length===0?".":n.join(".")};M.decode.bytes=0;M.encodingLength=function(r){return r==="."||r===".."?1:j.byteLength(r.replace(/^\.|\.$/gm,""))+2};var ee={};ee.encode=function(r,e,t){e||(e=j.alloc(ee.encodingLength(r))),t||(t=0);let n=e.write(r,t+1);return e[t]=n,ee.encode.bytes=n+1,e};ee.encode.bytes=0;ee.decode=function(r,e){e||(e=0);let t=r[e],n=r.toString("utf-8",e+1,e+1+t);return ee.decode.bytes=t+1,n};ee.decode.bytes=0;ee.encodingLength=function(r){return j.byteLength(r)+1};var ar={};ar.encode=function(r,e,t){e||(e=ar.encodingLength(r)),t||(t=0);let n=(r.flags||0)&32767,i=r.type==="response"?qg:q4;return e.writeUInt16BE(r.id||0,t),e.writeUInt16BE(n|i,t+2),e.writeUInt16BE(r.questions.length,t+4),e.writeUInt16BE(r.answers.length,t+6),e.writeUInt16BE(r.authorities.length,t+8),e.writeUInt16BE(r.additionals.length,t+10),e};ar.encode.bytes=12;ar.decode=function(r,e){if(e||(e=0),r.length<12)throw new Error("Header must be 12 bytes");let t=r.readUInt16BE(e+2);return{id:r.readUInt16BE(e),type:t&qg?"response":"query",flags:t&32767,flag_qr:(t>>15&1)===1,opcode:K4.toString(t>>11&15),flag_aa:(t>>10&1)===1,flag_tc:(t>>9&1)===1,flag_rd:(t>>8&1)===1,flag_ra:(t>>7&1)===1,flag_z:(t>>6&1)===1,flag_ad:(t>>5&1)===1,flag_cd:(t>>4&1)===1,rcode:z4.toString(t&15),questions:new Array(r.readUInt16BE(e+4)),answers:new Array(r.readUInt16BE(e+6)),authorities:new Array(r.readUInt16BE(e+8)),additionals:new Array(r.readUInt16BE(e+10))}};ar.decode.bytes=12;ar.encodingLength=function(){return 12};var ln=q.unknown={};ln.encode=function(r,e,t){return e||(e=j.alloc(ln.encodingLength(r))),t||(t=0),e.writeUInt16BE(r.length,t),r.copy(e,t+2),ln.encode.bytes=r.length+2,e};ln.encode.bytes=0;ln.decode=function(r,e){e||(e=0);let t=r.readUInt16BE(e),n=r.slice(e+2,e+2+t);return ln.decode.bytes=t+2,n};ln.decode.bytes=0;ln.encodingLength=function(r){return r.length+2};var un=q.ns={};un.encode=function(r,e,t){return e||(e=j.alloc(un.encodingLength(r))),t||(t=0),M.encode(r,e,t+2),e.writeUInt16BE(M.encode.bytes,t),un.encode.bytes=M.encode.bytes+2,e};un.encode.bytes=0;un.decode=function(r,e){e||(e=0);let t=r.readUInt16BE(e),n=M.decode(r,e+2);return un.decode.bytes=t+2,n};un.decode.bytes=0;un.encodingLength=function(r){return M.encodingLength(r)+2};var hn=q.soa={};hn.encode=function(r,e,t){e||(e=j.alloc(hn.encodingLength(r))),t||(t=0);let n=t;return t+=2,M.encode(r.mname,e,t),t+=M.encode.bytes,M.encode(r.rname,e,t,{mail:!0}),t+=M.encode.bytes,e.writeUInt32BE(r.serial||0,t),t+=4,e.writeUInt32BE(r.refresh||0,t),t+=4,e.writeUInt32BE(r.retry||0,t),t+=4,e.writeUInt32BE(r.expire||0,t),t+=4,e.writeUInt32BE(r.minimum||0,t),t+=4,e.writeUInt16BE(t-n-2,n),hn.encode.bytes=t-n,e};hn.encode.bytes=0;hn.decode=function(r,e){e||(e=0);let t=e,n={};return e+=2,n.mname=M.decode(r,e),e+=M.decode.bytes,n.rname=M.decode(r,e,{mail:!0}),e+=M.decode.bytes,n.serial=r.readUInt32BE(e),e+=4,n.refresh=r.readUInt32BE(e),e+=4,n.retry=r.readUInt32BE(e),e+=4,n.expire=r.readUInt32BE(e),e+=4,n.minimum=r.readUInt32BE(e),e+=4,hn.decode.bytes=e-t,n};hn.decode.bytes=0;hn.encodingLength=function(r){return 22+M.encodingLength(r.mname)+M.encodingLength(r.rname)};var dn=q.txt={};dn.encode=function(r,e,t){Array.isArray(r)||(r=[r]);for(let i=0;i<r.length;i++)if(typeof r[i]=="string"&&(r[i]=j.from(r[i])),!j.isBuffer(r[i]))throw new Error("Must be a Buffer");e||(e=j.alloc(dn.encodingLength(r))),t||(t=0);let n=t;return t+=2,r.forEach(function(i){e[t++]=i.length,i.copy(e,t,0,i.length),t+=i.length}),e.writeUInt16BE(t-n-2,n),dn.encode.bytes=t-n,e};dn.encode.bytes=0;dn.decode=function(r,e){e||(e=0);let t=e,n=r.readUInt16BE(e);e+=2;let i=[];for(;n>0;){let o=r[e++];if(--n,n<o)throw new Error("Buffer overflow");i.push(r.slice(e,e+o)),e+=o,n-=o}return dn.decode.bytes=e-t,i};dn.decode.bytes=0;dn.encodingLength=function(r){Array.isArray(r)||(r=[r]);let e=2;return r.forEach(function(t){typeof t=="string"?e+=j.byteLength(t)+1:e+=t.length+1}),e};var fn=q.null={};fn.encode=function(r,e,t){e||(e=j.alloc(fn.encodingLength(r))),t||(t=0),typeof r=="string"&&(r=j.from(r)),r||(r=j.alloc(0));let n=t;t+=2;let i=r.length;return r.copy(e,t,0,i),t+=i,e.writeUInt16BE(t-n-2,n),fn.encode.bytes=t-n,e};fn.encode.bytes=0;fn.decode=function(r,e){e||(e=0);let t=e,n=r.readUInt16BE(e);e+=2;let i=r.slice(e,e+n);return e+=n,fn.decode.bytes=e-t,i};fn.decode.bytes=0;fn.encodingLength=function(r){return r?(j.isBuffer(r)?r.length:j.byteLength(r))+2:2};var pn=q.hinfo={};pn.encode=function(r,e,t){e||(e=j.alloc(pn.encodingLength(r))),t||(t=0);let n=t;return t+=2,ee.encode(r.cpu,e,t),t+=ee.encode.bytes,ee.encode(r.os,e,t),t+=ee.encode.bytes,e.writeUInt16BE(t-n-2,n),pn.encode.bytes=t-n,e};pn.encode.bytes=0;pn.decode=function(r,e){e||(e=0);let t=e,n={};return e+=2,n.cpu=ee.decode(r,e),e+=ee.decode.bytes,n.os=ee.decode(r,e),e+=ee.decode.bytes,pn.decode.bytes=e-t,n};pn.decode.bytes=0;pn.encodingLength=function(r){return ee.encodingLength(r.cpu)+ee.encodingLength(r.os)+2};var or=q.ptr={},W4=q.cname=or,Y4=q.dname=or;or.encode=function(r,e,t){return e||(e=j.alloc(or.encodingLength(r))),t||(t=0),M.encode(r,e,t+2),e.writeUInt16BE(M.encode.bytes,t),or.encode.bytes=M.encode.bytes+2,e};or.encode.bytes=0;or.decode=function(r,e){e||(e=0);let t=M.decode(r,e+2);return or.decode.bytes=M.decode.bytes+2,t};or.decode.bytes=0;or.encodingLength=function(r){return M.encodingLength(r)+2};var mn=q.srv={};mn.encode=function(r,e,t){e||(e=j.alloc(mn.encodingLength(r))),t||(t=0),e.writeUInt16BE(r.priority||0,t+2),e.writeUInt16BE(r.weight||0,t+4),e.writeUInt16BE(r.port||0,t+6),M.encode(r.target,e,t+8);let n=M.encode.bytes+6;return e.writeUInt16BE(n,t),mn.encode.bytes=n+2,e};mn.encode.bytes=0;mn.decode=function(r,e){e||(e=0);let t=r.readUInt16BE(e),n={};return n.priority=r.readUInt16BE(e+2),n.weight=r.readUInt16BE(e+4),n.port=r.readUInt16BE(e+6),n.target=M.decode(r,e+8),mn.decode.bytes=t+2,n};mn.decode.bytes=0;mn.encodingLength=function(r){return 8+M.encodingLength(r.target)};var Tt=q.caa={};Tt.ISSUER_CRITICAL=128;Tt.encode=function(r,e,t){let n=Tt.encodingLength(r);return e||(e=j.alloc(Tt.encodingLength(r))),t||(t=0),r.issuerCritical&&(r.flags=Tt.ISSUER_CRITICAL),e.writeUInt16BE(n-2,t),t+=2,e.writeUInt8(r.flags||0,t),t+=1,ee.encode(r.tag,e,t),t+=ee.encode.bytes,e.write(r.value,t),t+=j.byteLength(r.value),Tt.encode.bytes=n,e};Tt.encode.bytes=0;Tt.decode=function(r,e){e||(e=0);let t=r.readUInt16BE(e);e+=2;let n=e,i={};return i.flags=r.readUInt8(e),e+=1,i.tag=ee.decode(r,e),e+=ee.decode.bytes,i.value=r.toString("utf-8",e,n+t),i.issuerCritical=!!(i.flags&Tt.ISSUER_CRITICAL),Tt.decode.bytes=t+2,i};Tt.decode.bytes=0;Tt.encodingLength=function(r){return ee.encodingLength(r.tag)+ee.encodingLength(r.value)+2};var Qn=q.mx={};Qn.encode=function(r,e,t){e||(e=j.alloc(Qn.encodingLength(r))),t||(t=0);let n=t;return t+=2,e.writeUInt16BE(r.preference||0,t),t+=2,M.encode(r.exchange,e,t),t+=M.encode.bytes,e.writeUInt16BE(t-n-2,n),Qn.encode.bytes=t-n,e};Qn.encode.bytes=0;Qn.decode=function(r,e){e||(e=0);let t=e,n={};return e+=2,n.preference=r.readUInt16BE(e),e+=2,n.exchange=M.decode(r,e),e+=M.decode.bytes,Qn.decode.bytes=e-t,n};Qn.encodingLength=function(r){return 4+M.encodingLength(r.exchange)};var yn=q.a={};yn.encode=function(r,e,t){return e||(e=j.alloc(yn.encodingLength(r))),t||(t=0),e.writeUInt16BE(4,t),t+=2,Ti.v4.encode(r,e,t),yn.encode.bytes=6,e};yn.encode.bytes=0;yn.decode=function(r,e){e||(e=0),e+=2;let t=Ti.v4.decode(r,e);return yn.decode.bytes=6,t};yn.decode.bytes=0;yn.encodingLength=function(){return 6};var gn=q.aaaa={};gn.encode=function(r,e,t){return e||(e=j.alloc(gn.encodingLength(r))),t||(t=0),e.writeUInt16BE(16,t),t+=2,Ti.v6.encode(r,e,t),gn.encode.bytes=18,e};gn.encode.bytes=0;gn.decode=function(r,e){e||(e=0),e+=2;let t=Ti.v6.decode(r,e);return gn.decode.bytes=18,t};gn.decode.bytes=0;gn.encodingLength=function(){return 18};var xt=q.option={};xt.encode=function(r,e,t){e||(e=j.alloc(xt.encodingLength(r))),t||(t=0);let n=t,i=yf.toCode(r.code);if(e.writeUInt16BE(i,t),t+=2,r.data)e.writeUInt16BE(r.data.length,t),t+=2,r.data.copy(e,t),t+=r.data.length;else switch(i){case 8:let o=r.sourcePrefixLength||0,s=r.family||Ti.familyOf(r.ip),a=Ti.encode(r.ip,j.alloc),c=Math.ceil(o/8);e.writeUInt16BE(c+4,t),t+=2,e.writeUInt16BE(s,t),t+=2,e.writeUInt8(o,t++),e.writeUInt8(r.scopePrefixLength||0,t++),a.copy(e,t,0,c),t+=c;break;case 11:r.timeout?(e.writeUInt16BE(2,t),t+=2,e.writeUInt16BE(r.timeout,t),t+=2):(e.writeUInt16BE(0,t),t+=2);break;case 12:let u=r.length||0;e.writeUInt16BE(u,t),t+=2,e.fill(0,t,t+u),t+=u;break;case 14:let l=r.tags.length*2;e.writeUInt16BE(l,t),t+=2;for(let h of r.tags)e.writeUInt16BE(h,t),t+=2;break;default:throw new Error(`Unknown roption code: ${r.code}`)}return xt.encode.bytes=t-n,e};xt.encode.bytes=0;xt.decode=function(r,e){e||(e=0);let t={};t.code=r.readUInt16BE(e),t.type=yf.toString(t.code),e+=2;let n=r.readUInt16BE(e);switch(e+=2,t.data=r.slice(e,e+n),t.code){case 8:t.family=r.readUInt16BE(e),e+=2,t.sourcePrefixLength=r.readUInt8(e++),t.scopePrefixLength=r.readUInt8(e++);let i=j.alloc(t.family===1?4:16);r.copy(i,0,e,e+n-4),t.ip=Ti.decode(i);break;case 11:n>0&&(t.timeout=r.readUInt16BE(e),e+=2);break;case 14:t.tags=[];for(let o=0;o<n;o+=2)t.tags.push(r.readUInt16BE(e)),e+=2}return xt.decode.bytes=n+4,t};xt.decode.bytes=0;xt.encodingLength=function(r){if(r.data)return r.data.length+4;switch(yf.toCode(r.code)){case 8:let t=r.sourcePrefixLength||0;return Math.ceil(t/8)+8;case 11:return typeof r.timeout=="number"?6:4;case 12:return r.length+4;case 14:return 4+r.tags.length*2}throw new Error(`Unknown roption code: ${r.code}`)};var Nt=q.opt={};Nt.encode=function(r,e,t){e||(e=j.alloc(Nt.encodingLength(r))),t||(t=0);let n=t,i=Uo(r,xt);return e.writeUInt16BE(i,t),t=Ks(r,xt,e,t+2),Nt.encode.bytes=t-n,e};Nt.encode.bytes=0;Nt.decode=function(r,e){e||(e=0);let t=e,n=[],i=r.readUInt16BE(e);e+=2;let o=0;for(;i>0;)n[o++]=xt.decode(r,e),e+=xt.decode.bytes,i-=xt.decode.bytes;return Nt.decode.bytes=e-t,n};Nt.decode.bytes=0;Nt.encodingLength=function(r){return 2+Uo(r||[],xt)};var lt=q.dnskey={};lt.PROTOCOL_DNSSEC=3;lt.ZONE_KEY=128;lt.SECURE_ENTRYPOINT=32768;lt.encode=function(r,e,t){e||(e=j.alloc(lt.encodingLength(r))),t||(t=0);let n=t,i=r.key;if(!j.isBuffer(i))throw new Error("Key must be a Buffer");return t+=2,e.writeUInt16BE(r.flags,t),t+=2,e.writeUInt8(lt.PROTOCOL_DNSSEC,t),t+=1,e.writeUInt8(r.algorithm,t),t+=1,i.copy(e,t,0,i.length),t+=i.length,lt.encode.bytes=t-n,e.writeUInt16BE(lt.encode.bytes-2,n),e};lt.encode.bytes=0;lt.decode=function(r,e){e||(e=0);let t=e;var n={},i=r.readUInt16BE(e);if(e+=2,n.flags=r.readUInt16BE(e),e+=2,r.readUInt8(e)!==lt.PROTOCOL_DNSSEC)throw new Error("Protocol must be 3");return e+=1,n.algorithm=r.readUInt8(e),e+=1,n.key=r.slice(e,t+i+2),e+=n.key.length,lt.decode.bytes=e-t,n};lt.decode.bytes=0;lt.encodingLength=function(r){return 6+j.byteLength(r.key)};var Ir=q.rrsig={};Ir.encode=function(r,e,t){e||(e=j.alloc(Ir.encodingLength(r))),t||(t=0);let n=t,i=r.signature;if(!j.isBuffer(i))throw new Error("Signature must be a Buffer");return t+=2,e.writeUInt16BE(wn.toType(r.typeCovered),t),t+=2,e.writeUInt8(r.algorithm,t),t+=1,e.writeUInt8(r.labels,t),t+=1,e.writeUInt32BE(r.originalTTL,t),t+=4,e.writeUInt32BE(r.expiration,t),t+=4,e.writeUInt32BE(r.inception,t),t+=4,e.writeUInt16BE(r.keyTag,t),t+=2,M.encode(r.signersName,e,t),t+=M.encode.bytes,i.copy(e,t,0,i.length),t+=i.length,Ir.encode.bytes=t-n,e.writeUInt16BE(Ir.encode.bytes-2,n),e};Ir.encode.bytes=0;Ir.decode=function(r,e){e||(e=0);let t=e;var n={},i=r.readUInt16BE(e);return e+=2,n.typeCovered=wn.toString(r.readUInt16BE(e)),e+=2,n.algorithm=r.readUInt8(e),e+=1,n.labels=r.readUInt8(e),e+=1,n.originalTTL=r.readUInt32BE(e),e+=4,n.expiration=r.readUInt32BE(e),e+=4,n.inception=r.readUInt32BE(e),e+=4,n.keyTag=r.readUInt16BE(e),e+=2,n.signersName=M.decode(r,e),e+=M.decode.bytes,n.signature=r.slice(e,t+i+2),e+=n.signature.length,Ir.decode.bytes=e-t,n};Ir.decode.bytes=0;Ir.encodingLength=function(r){return 20+M.encodingLength(r.signersName)+j.byteLength(r.signature)};var Sr=q.rp={};Sr.encode=function(r,e,t){e||(e=j.alloc(Sr.encodingLength(r))),t||(t=0);let n=t;return t+=2,M.encode(r.mbox||".",e,t,{mail:!0}),t+=M.encode.bytes,M.encode(r.txt||".",e,t),t+=M.encode.bytes,Sr.encode.bytes=t-n,e.writeUInt16BE(Sr.encode.bytes-2,n),e};Sr.encode.bytes=0;Sr.decode=function(r,e){e||(e=0);let t=e,n={};return e+=2,n.mbox=M.decode(r,e,{mail:!0})||".",e+=M.decode.bytes,n.txt=M.decode(r,e)||".",e+=M.decode.bytes,Sr.decode.bytes=e-t,n};Sr.decode.bytes=0;Sr.encodingLength=function(r){return 2+M.encodingLength(r.mbox||".")+M.encodingLength(r.txt||".")};var $e={};$e.encode=function(r,e,t){e||(e=j.alloc($e.encodingLength(r))),t||(t=0);let n=t;for(var i=[],o=0;o<r.length;o++){var s=wn.toType(r[o]);i[s>>8]===void 0&&(i[s>>8]=[]),i[s>>8][s>>3&31]|=1<<7-(s&7)}for(o=0;o<i.length;o++)if(i[o]!==void 0){var a=j.from(i[o]);e.writeUInt8(o,t),t+=1,e.writeUInt8(a.length,t),t+=1,a.copy(e,t),t+=a.length}return $e.encode.bytes=t-n,e};$e.encode.bytes=0;$e.decode=function(r,e,t){e||(e=0);let n=e;for(var i=[];e-n<t;){var o=r.readUInt8(e);e+=1;var s=r.readUInt8(e);e+=1;for(var a=0;a<s;a++)for(var c=r.readUInt8(e+a),u=0;u<8;u++)if(c&1<<7-u){var l=wn.toString(o<<8|a<<3|u);i.push(l)}e+=s}return $e.decode.bytes=e-n,i};$e.decode.bytes=0;$e.encodingLength=function(r){for(var e=[],t=0;t<r.length;t++){var n=wn.toType(r[t]);e[n>>8]=Math.max(e[n>>8]||0,n&255)}var i=0;for(t=0;t<e.length;t++)e[t]!==void 0&&(i+=2+Math.ceil((e[t]+1)/8));return i};var _r=q.nsec={};_r.encode=function(r,e,t){e||(e=j.alloc(_r.encodingLength(r))),t||(t=0);let n=t;return t+=2,M.encode(r.nextDomain,e,t),t+=M.encode.bytes,$e.encode(r.rrtypes,e,t),t+=$e.encode.bytes,_r.encode.bytes=t-n,e.writeUInt16BE(_r.encode.bytes-2,n),e};_r.encode.bytes=0;_r.decode=function(r,e){e||(e=0);let t=e;var n={},i=r.readUInt16BE(e);return e+=2,n.nextDomain=M.decode(r,e),e+=M.decode.bytes,n.rrtypes=$e.decode(r,e,i-(e-t)),e+=$e.decode.bytes,_r.decode.bytes=e-t,n};_r.decode.bytes=0;_r.encodingLength=function(r){return 2+M.encodingLength(r.nextDomain)+$e.encodingLength(r.rrtypes)};var kr=q.nsec3={};kr.encode=function(r,e,t){e||(e=j.alloc(kr.encodingLength(r))),t||(t=0);let n=t,i=r.salt;if(!j.isBuffer(i))throw new Error("salt must be a Buffer");let o=r.nextDomain;if(!j.isBuffer(o))throw new Error("nextDomain must be a Buffer");return t+=2,e.writeUInt8(r.algorithm,t),t+=1,e.writeUInt8(r.flags,t),t+=1,e.writeUInt16BE(r.iterations,t),t+=2,e.writeUInt8(i.length,t),t+=1,i.copy(e,t,0,i.length),t+=i.length,e.writeUInt8(o.length,t),t+=1,o.copy(e,t,0,o.length),t+=o.length,$e.encode(r.rrtypes,e,t),t+=$e.encode.bytes,kr.encode.bytes=t-n,e.writeUInt16BE(kr.encode.bytes-2,n),e};kr.encode.bytes=0;kr.decode=function(r,e){e||(e=0);let t=e;var n={},i=r.readUInt16BE(e);e+=2,n.algorithm=r.readUInt8(e),e+=1,n.flags=r.readUInt8(e),e+=1,n.iterations=r.readUInt16BE(e),e+=2;let o=r.readUInt8(e);e+=1,n.salt=r.slice(e,e+o),e+=o;let s=r.readUInt8(e);return e+=1,n.nextDomain=r.slice(e,e+s),e+=s,n.rrtypes=$e.decode(r,e,i-(e-t)),e+=$e.decode.bytes,kr.decode.bytes=e-t,n};kr.decode.bytes=0;kr.encodingLength=function(r){return 8+r.salt.length+r.nextDomain.length+$e.encodingLength(r.rrtypes)};var Rr=q.ds={};Rr.encode=function(r,e,t){e||(e=j.alloc(Rr.encodingLength(r))),t||(t=0);let n=t,i=r.digest;if(!j.isBuffer(i))throw new Error("Digest must be a Buffer");return t+=2,e.writeUInt16BE(r.keyTag,t),t+=2,e.writeUInt8(r.algorithm,t),t+=1,e.writeUInt8(r.digestType,t),t+=1,i.copy(e,t,0,i.length),t+=i.length,Rr.encode.bytes=t-n,e.writeUInt16BE(Rr.encode.bytes-2,n),e};Rr.encode.bytes=0;Rr.decode=function(r,e){e||(e=0);let t=e;var n={},i=r.readUInt16BE(e);return e+=2,n.keyTag=r.readUInt16BE(e),e+=2,n.algorithm=r.readUInt8(e),e+=1,n.digestType=r.readUInt8(e),e+=1,n.digest=r.slice(e,t+i+2),e+=n.digest.length,Rr.decode.bytes=e-t,n};Rr.decode.bytes=0;Rr.encodingLength=function(r){return 6+j.byteLength(r.digest)};var Ct=q.sshfp={};Ct.getFingerprintLengthForHashType=function(e){switch(e){case 1:return 20;case 2:return 32}};Ct.encode=function(e,t,n){t||(t=j.alloc(Ct.encodingLength(e))),n||(n=0);let i=n;n+=2,t[n]=e.algorithm,n+=1,t[n]=e.hash,n+=1;let o=j.from(e.fingerprint.toUpperCase(),"hex");if(o.length!==Ct.getFingerprintLengthForHashType(e.hash))throw new Error("Invalid fingerprint length");return o.copy(t,n),n+=o.byteLength,Ct.encode.bytes=n-i,t.writeUInt16BE(Ct.encode.bytes-2,i),t};Ct.encode.bytes=0;Ct.decode=function(e,t){t||(t=0);let n=t,i={};t+=2,i.algorithm=e[t],t+=1,i.hash=e[t],t+=1;let o=Ct.getFingerprintLengthForHashType(i.hash);return i.fingerprint=e.slice(t,t+o).toString("hex").toUpperCase(),t+=o,Ct.decode.bytes=t-n,i};Ct.decode.bytes=0;Ct.encodingLength=function(r){return 4+j.from(r.fingerprint,"hex").byteLength};var Tr=q.naptr={};Tr.encode=function(r,e,t){e||(e=j.alloc(Tr.encodingLength(r))),t||(t=0);let n=t;return t+=2,e.writeUInt16BE(r.order||0,t),t+=2,e.writeUInt16BE(r.preference||0,t),t+=2,ee.encode(r.flags,e,t),t+=ee.encode.bytes,ee.encode(r.services,e,t),t+=ee.encode.bytes,ee.encode(r.regexp,e,t),t+=ee.encode.bytes,M.encode(r.replacement,e,t),t+=M.encode.bytes,Tr.encode.bytes=t-n,e.writeUInt16BE(Tr.encode.bytes-2,n),e};Tr.encode.bytes=0;Tr.decode=function(r,e){e||(e=0);let t=e,n={};return e+=2,n.order=r.readUInt16BE(e),e+=2,n.preference=r.readUInt16BE(e),e+=2,n.flags=ee.decode(r,e),e+=ee.decode.bytes,n.services=ee.decode(r,e),e+=ee.decode.bytes,n.regexp=ee.decode(r,e),e+=ee.decode.bytes,n.replacement=M.decode(r,e),e+=M.decode.bytes,Tr.decode.bytes=e-t,n};Tr.decode.bytes=0;Tr.encodingLength=function(r){return ee.encodingLength(r.flags)+ee.encodingLength(r.services)+ee.encodingLength(r.regexp)+M.encodingLength(r.replacement)+6};var Cr=q.tlsa={};Cr.encode=function(r,e,t){e||(e=j.alloc(Cr.encodingLength(r))),t||(t=0);let n=t,i=r.certificate;if(!j.isBuffer(i))throw new Error("Certificate must be a Buffer");return t+=2,e.writeUInt8(r.usage,t),t+=1,e.writeUInt8(r.selector,t),t+=1,e.writeUInt8(r.matchingType,t),t+=1,i.copy(e,t,0,i.length),t+=i.length,Cr.encode.bytes=t-n,e.writeUInt16BE(Cr.encode.bytes-2,n),e};Cr.encode.bytes=0;Cr.decode=function(r,e){e||(e=0);let t=e,n={},i=r.readUInt16BE(e);return e+=2,n.usage=r.readUInt8(e),e+=1,n.selector=r.readUInt8(e),e+=1,n.matchingType=r.readUInt8(e),e+=1,n.certificate=r.slice(e,t+i+2),e+=n.certificate.length,Cr.decode.bytes=e-t,n};Cr.decode.bytes=0;Cr.encodingLength=function(r){return 5+j.byteLength(r.certificate)};var wf=q.record=function(r){switch(r.toUpperCase()){case"A":return yn;case"PTR":return or;case"CNAME":return W4;case"DNAME":return Y4;case"TXT":return dn;case"NULL":return fn;case"AAAA":return gn;case"SRV":return mn;case"HINFO":return pn;case"CAA":return Tt;case"NS":return un;case"SOA":return hn;case"MX":return Qn;case"OPT":return Nt;case"DNSKEY":return lt;case"RRSIG":return Ir;case"RP":return Sr;case"NSEC":return _r;case"NSEC3":return kr;case"SSHFP":return Ct;case"DS":return Rr;case"NAPTR":return Tr;case"TLSA":return Cr}return ln},Ye=q.answer={};Ye.encode=function(r,e,t){e||(e=j.alloc(Ye.encodingLength(r))),t||(t=0);let n=t;if(M.encode(r.name,e,t),t+=M.encode.bytes,e.writeUInt16BE(wn.toType(r.type),t),r.type.toUpperCase()==="OPT"){if(r.name!==".")throw new Error("OPT name must be root.");e.writeUInt16BE(r.udpPayloadSize||4096,t+2),e.writeUInt8(r.extendedRcode||0,t+4),e.writeUInt8(r.ednsVersion||0,t+5),e.writeUInt16BE(r.flags||0,t+6),t+=8,Nt.encode(r.options||[],e,t),t+=Nt.encode.bytes}else{let i=kl.toClass(r.class===void 0?"IN":r.class);r.flush&&(i|=gf),e.writeUInt16BE(i,t+2),e.writeUInt32BE(r.ttl||0,t+4),t+=8;let o=wf(r.type);o.encode(r.data,e,t),t+=o.encode.bytes}return Ye.encode.bytes=t-n,e};Ye.encode.bytes=0;Ye.decode=function(r,e){e||(e=0);let t={},n=e;if(t.name=M.decode(r,e),e+=M.decode.bytes,t.type=wn.toString(r.readUInt16BE(e)),t.type==="OPT")t.udpPayloadSize=r.readUInt16BE(e+2),t.extendedRcode=r.readUInt8(e+4),t.ednsVersion=r.readUInt8(e+5),t.flags=r.readUInt16BE(e+6),t.flag_do=(t.flags>>15&1)===1,t.options=Nt.decode(r,e+8),e+=8+Nt.decode.bytes;else{let i=r.readUInt16BE(e+2);t.ttl=r.readUInt32BE(e+4),t.class=kl.toString(i&j4),t.flush=!!(i&gf);let o=wf(t.type);t.data=o.decode(r,e+8),e+=8+o.decode.bytes}return Ye.decode.bytes=e-n,t};Ye.decode.bytes=0;Ye.encodingLength=function(r){let e=r.data!==null&&r.data!==void 0?r.data:r.options;return M.encodingLength(r.name)+8+wf(r.type).encodingLength(e)};var sr=q.question={};sr.encode=function(r,e,t){e||(e=j.alloc(sr.encodingLength(r))),t||(t=0);let n=t;return M.encode(r.name,e,t),t+=M.encode.bytes,e.writeUInt16BE(wn.toType(r.type),t),t+=2,e.writeUInt16BE(kl.toClass(r.class===void 0?"IN":r.class),t),t+=2,sr.encode.bytes=t-n,r};sr.encode.bytes=0;sr.decode=function(r,e){e||(e=0);let t=e,n={};return n.name=M.decode(r,e),e+=M.decode.bytes,n.type=wn.toString(r.readUInt16BE(e)),e+=2,n.class=kl.toString(r.readUInt16BE(e)),e+=2,!!(n.class&jg)&&(n.class&=G4),sr.decode.bytes=e-t,n};sr.decode.bytes=0;sr.encodingLength=function(r){return M.encodingLength(r.name)+4};q.AUTHORITATIVE_ANSWER=1024;q.TRUNCATED_RESPONSE=512;q.RECURSION_DESIRED=256;q.RECURSION_AVAILABLE=128;q.AUTHENTIC_DATA=32;q.CHECKING_DISABLED=16;q.DNSSEC_OK=32768;q.encode=function(r,e,t){let n=!e;n&&(e=j.alloc(q.encodingLength(r))),t||(t=0);let i=t;return r.questions||(r.questions=[]),r.answers||(r.answers=[]),r.authorities||(r.authorities=[]),r.additionals||(r.additionals=[]),ar.encode(r,e,t),t+=ar.encode.bytes,t=Ks(r.questions,sr,e,t),t=Ks(r.answers,Ye,e,t),t=Ks(r.authorities,Ye,e,t),t=Ks(r.additionals,Ye,e,t),q.encode.bytes=t-i,n&&q.encode.bytes!==e.length?e.slice(0,q.encode.bytes):e};q.encode.bytes=0;q.decode=function(r,e){e||(e=0);let t=e,n=ar.decode(r,e);return e+=ar.decode.bytes,e=_l(n.questions,sr,r,e),e=_l(n.answers,Ye,r,e),e=_l(n.authorities,Ye,r,e),e=_l(n.additionals,Ye,r,e),q.decode.bytes=e-t,n};q.decode.bytes=0;q.encodingLength=function(r){return ar.encodingLength(r)+Uo(r.questions||[],sr)+Uo(r.answers||[],Ye)+Uo(r.authorities||[],Ye)+Uo(r.additionals||[],Ye)};q.streamEncode=function(r){let e=q.encode(r),t=j.alloc(2);t.writeUInt16BE(e.byteLength);let n=j.concat([t,e]);return q.streamEncode.bytes=n.byteLength,n};q.streamEncode.bytes=0;q.streamDecode=function(r){let e=r.readUInt16BE(0);if(r.byteLength<e+2)return null;let t=q.decode(r.slice(2));return q.streamDecode.bytes=q.decode.bytes,t};q.streamDecode.bytes=0;function Uo(r,e){let t=0;for(let n=0;n<r.length;n++)t+=e.encodingLength(r[n]);return t}function Ks(r,e,t,n){for(let i=0;i<r.length;i++)e.encode(r[i],t,n),n+=e.encode.bytes;return n}function _l(r,e,t,n){for(let i=0;i<r.length;i++)r[i]=e.decode(t,n),n+=e.decode.bytes;return n}});var ow=me((Zs,Cl)=>{(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 f=0;f<d.length;f++)if(!Number.isInteger(d[f])||d[f]<0||d[f]>255)return!1;return!0}function i(d,f){return(d&65535)*f+(((d>>>16)*f&65535)<<16)}function o(d,f){return d<<f|d>>>32-f}function s(d){return d^=d>>>16,d=i(d,2246822507),d^=d>>>13,d=i(d,3266489909),d^=d>>>16,d}function a(d,f){d=[d[0]>>>16,d[0]&65535,d[1]>>>16,d[1]&65535],f=[f[0]>>>16,f[0]&65535,f[1]>>>16,f[1]&65535];var m=[0,0,0,0];return m[3]+=d[3]+f[3],m[2]+=m[3]>>>16,m[3]&=65535,m[2]+=d[2]+f[2],m[1]+=m[2]>>>16,m[2]&=65535,m[1]+=d[1]+f[1],m[0]+=m[1]>>>16,m[1]&=65535,m[0]+=d[0]+f[0],m[0]&=65535,[m[0]<<16|m[1],m[2]<<16|m[3]]}function c(d,f){d=[d[0]>>>16,d[0]&65535,d[1]>>>16,d[1]&65535],f=[f[0]>>>16,f[0]&65535,f[1]>>>16,f[1]&65535];var m=[0,0,0,0];return m[3]+=d[3]*f[3],m[2]+=m[3]>>>16,m[3]&=65535,m[2]+=d[2]*f[3],m[1]+=m[2]>>>16,m[2]&=65535,m[2]+=d[3]*f[2],m[1]+=m[2]>>>16,m[2]&=65535,m[1]+=d[1]*f[3],m[0]+=m[1]>>>16,m[1]&=65535,m[1]+=d[2]*f[2],m[0]+=m[1]>>>16,m[1]&=65535,m[1]+=d[3]*f[1],m[0]+=m[1]>>>16,m[1]&=65535,m[0]+=d[0]*f[3]+d[1]*f[2]+d[2]*f[1]+d[3]*f[0],m[0]&=65535,[m[0]<<16|m[1],m[2]<<16|m[3]]}function u(d,f){return f%=64,f===32?[d[1],d[0]]:f<32?[d[0]<<f|d[1]>>>32-f,d[1]<<f|d[0]>>>32-f]:(f-=32,[d[1]<<f|d[0]>>>32-f,d[0]<<f|d[1]>>>32-f])}function l(d,f){return f%=64,f===0?d:f<32?[d[0]<<f|d[1]>>>32-f,d[1]<<f]:[d[1]<<f-32,0]}function h(d,f){return[d[0]^f[0],d[1]^f[1]]}function p(d){return d=h(d,[0,d[0]>>>1]),d=c(d,[4283543511,3981806797]),d=h(d,[0,d[0]>>>1]),d=c(d,[3301882366,444984403]),d=h(d,[0,d[0]>>>1]),d}t.x86.hash32=function(d,f){if(t.inputValidation&&!n(d))return e;f=f||0;for(var m=d.length%4,y=d.length-m,g=f,x=0,b=3432918353,A=461845907,I=0;I<y;I=I+4)x=d[I]|d[I+1]<<8|d[I+2]<<16|d[I+3]<<24,x=i(x,b),x=o(x,15),x=i(x,A),g^=x,g=o(g,13),g=i(g,5)+3864292196;switch(x=0,m){case 3:x^=d[I+2]<<16;case 2:x^=d[I+1]<<8;case 1:x^=d[I],x=i(x,b),x=o(x,15),x=i(x,A),g^=x}return g^=d.length,g=s(g),g>>>0},t.x86.hash128=function(d,f){if(t.inputValidation&&!n(d))return e;f=f||0;for(var m=d.length%16,y=d.length-m,g=f,x=f,b=f,A=f,I=0,B=0,v=0,E=0,R=597399067,N=2869860233,C=951274213,H=2716044179,D=0;D<y;D=D+16)I=d[D]|d[D+1]<<8|d[D+2]<<16|d[D+3]<<24,B=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,I=i(I,R),I=o(I,15),I=i(I,N),g^=I,g=o(g,19),g+=x,g=i(g,5)+1444728091,B=i(B,N),B=o(B,16),B=i(B,C),x^=B,x=o(x,17),x+=b,x=i(x,5)+197830471,v=i(v,C),v=o(v,17),v=i(v,H),b^=v,b=o(b,15),b+=A,b=i(b,5)+2530024501,E=i(E,H),E=o(E,18),E=i(E,R),A^=E,A=o(A,13),A+=g,A=i(A,5)+850148119;switch(I=0,B=0,v=0,E=0,m){case 15:E^=d[D+14]<<16;case 14:E^=d[D+13]<<8;case 13:E^=d[D+12],E=i(E,H),E=o(E,18),E=i(E,R),A^=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=i(v,C),v=o(v,17),v=i(v,H),b^=v;case 8:B^=d[D+7]<<24;case 7:B^=d[D+6]<<16;case 6:B^=d[D+5]<<8;case 5:B^=d[D+4],B=i(B,N),B=o(B,16),B=i(B,C),x^=B;case 4:I^=d[D+3]<<24;case 3:I^=d[D+2]<<16;case 2:I^=d[D+1]<<8;case 1:I^=d[D],I=i(I,R),I=o(I,15),I=i(I,N),g^=I}return g^=d.length,x^=d.length,b^=d.length,A^=d.length,g+=x,g+=b,g+=A,x+=g,b+=g,A+=g,g=s(g),x=s(x),b=s(b),A=s(A),g+=x,g+=b,g+=A,x+=g,b+=g,A+=g,("00000000"+(g>>>0).toString(16)).slice(-8)+("00000000"+(x>>>0).toString(16)).slice(-8)+("00000000"+(b>>>0).toString(16)).slice(-8)+("00000000"+(A>>>0).toString(16)).slice(-8)},t.x64.hash128=function(d,f){if(t.inputValidation&&!n(d))return e;f=f||0;for(var m=d.length%16,y=d.length-m,g=[0,f],x=[0,f],b=[0,0],A=[0,0],I=[2277735313,289559509],B=[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],A=[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,I),b=u(b,31),b=c(b,B),g=h(g,b),g=u(g,27),g=a(g,x),g=a(c(g,[0,5]),[0,1390208809]),A=c(A,B),A=u(A,33),A=c(A,I),x=h(x,A),x=u(x,31),x=a(x,g),x=a(c(x,[0,5]),[0,944331445]);switch(b=[0,0],A=[0,0],m){case 15:A=h(A,l([0,d[v+14]],48));case 14:A=h(A,l([0,d[v+13]],40));case 13:A=h(A,l([0,d[v+12]],32));case 12:A=h(A,l([0,d[v+11]],24));case 11:A=h(A,l([0,d[v+10]],16));case 10:A=h(A,l([0,d[v+9]],8));case 9:A=h(A,[0,d[v+8]]),A=c(A,B),A=u(A,33),A=c(A,I),x=h(x,A);case 8:b=h(b,l([0,d[v+7]],56));case 7:b=h(b,l([0,d[v+6]],48));case 6:b=h(b,l([0,d[v+5]],40));case 5:b=h(b,l([0,d[v+4]],32));case 4:b=h(b,l([0,d[v+3]],24));case 3:b=h(b,l([0,d[v+2]],16));case 2:b=h(b,l([0,d[v+1]],8));case 1:b=h(b,[0,d[v]]),b=c(b,I),b=u(b,31),b=c(b,B),g=h(g,b)}return g=h(g,[0,d.length]),x=h(x,[0,d.length]),g=a(g,x),x=a(x,g),g=p(g),x=p(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 Zs<"u"?(typeof Cl<"u"&&Cl.exports&&(Zs=Cl.exports=t),Zs.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)})(Zs)});var aw=me((O7,sw)=>{sw.exports=ow()});var Ul=me((K7,lw)=>{"use strict";lw.exports=class{constructor(){this._bitArrays=[],this._data=[],this._length=0,this._changedLength=!1,this._changedData=!1}set(e,t){let n=this._internalPositionFor(e,!1);if(t===void 0)n!==-1&&(this._unsetInternalPos(n),this._unsetBit(e),this._changedLength=!0,this._changedData=!0);else{let i=!1;n===-1?(n=this._data.length,this._setBit(e),this._changedData=!0):i=!0,this._setInternalPos(n,e,t,i),this._changedLength=!0}}unset(e){this.set(e,void 0)}get(e){this._sortData();let t=this._internalPositionFor(e,!0);if(t!==-1)return this._data[t][1]}push(e){return this.set(this.length,e),this.length}get length(){if(this._sortData(),this._changedLength){let e=this._data[this._data.length-1];this._length=e?e[0]+1:0,this._changedLength=!1}return this._length}forEach(e){let t=0;for(;t<this.length;)e(this.get(t),t,this),t++}map(e){let t=0,n=new Array(this.length);for(;t<this.length;)n[t]=e(this.get(t),t,this),t++;return n}reduce(e,t){let n=0,i=t;for(;n<this.length;){let o=this.get(n);i=e(i,o,n),n++}return i}find(e){let t=0,n,i;for(;t<this.length&&!n;)i=this.get(t),n=e(i),t++;return n?i:void 0}_internalPositionFor(e,t){let n=this._bytePosFor(e,t);if(n>=this._bitArrays.length)return-1;let i=this._bitArrays[n],o=e-n*7;if(!((i&1<<o)>0))return-1;let a=this._bitArrays.slice(0,n).reduce(hB,0),c=~(4294967295<<o+1),u=cw(i&c);return a+u-1}_bytePosFor(e,t){let n=Math.floor(e/7),i=n+1;for(;!t&&this._bitArrays.length<i;)this._bitArrays.push(0);return n}_setBit(e){let t=this._bytePosFor(e,!1);this._bitArrays[t]|=1<<e-t*7}_unsetBit(e){let t=this._bytePosFor(e,!1);this._bitArrays[t]&=~(1<<e-t*7)}_setInternalPos(e,t,n,i){let o=this._data,s=[t,n];if(i)this._sortData(),o[e]=s;else{if(o.length)if(o[o.length-1][0]>=t)o.push(s);else if(o[0][0]<=t)o.unshift(s);else{let a=Math.round(o.length/2);this._data=o.slice(0,a).concat(s).concat(o.slice(a))}else this._data.push(s);this._changedData=!0,this._changedLength=!0}}_unsetInternalPos(e){this._data.splice(e,1)}_sortData(){this._changedData&&this._data.sort(dB),this._changedData=!1}bitField(){let e=[],t=8,n=0,i=0,o,s=this._bitArrays.slice();for(;s.length||n;){n===0&&(o=s.shift(),n=7);let c=Math.min(n,t),u=~(255<<c),l=o&u;i|=l<<8-t,o=o>>>c,n-=c,t-=c,(!t||!n&&!s.length)&&(e.push(i),i=0,t=8)}for(var a=e.length-1;a>0&&e[a]===0;a--)e.pop();return e}compactArray(){return this._sortData(),this._data.map(fB)}};function hB(r,e){return r+cw(e)}function cw(r){let e=r;return e=e-(e>>1&1431655765),e=(e&858993459)+(e>>2&858993459),(e+(e>>4)&252645135)*16843009>>24}function dB(r,e){return r[0]-e[0]}function fB(r){return r[1]}});var Aw=me((IO,Bw)=>{var _f=class{constructor(e,t=12,n=8*1024,i=32*1024,o=64,s){this.bits=t,this.min=n,this.max=i,this.asModule=e,this.rabin=new e.Rabin(t,n,i,o,s),this.polynomial=s}fingerprint(e){let{__retain:t,__release:n,__allocArray:i,__getInt32Array:o,Int32Array_ID:s,Uint8Array_ID:a}=this.asModule,c=new Int32Array(Math.ceil(e.length/this.min)),u=t(i(s,c)),l=t(i(a,e)),h=this.rabin.fingerprint(l,u),p=o(h);n(l),n(u);let d=p.indexOf(0);return d>=0?p.subarray(0,d):p}};Bw.exports=_f});var Tw=me(ea=>{"use strict";var SB=typeof BigUint64Array<"u",Js=Symbol(),Qs=1024;function Iw(r,e){let t=new Uint32Array(r),n=new Uint16Array(r);var i=t[e+-4>>>2]>>>1,o=e>>>1;if(i<=Qs)return String.fromCharCode.apply(String,n.subarray(o,o+i));let s=[];do{let a=n[o+Qs-1],c=a>=55296&&a<56320?Qs-1:Qs;s.push(String.fromCharCode.apply(String,n.subarray(o,o+=c))),i-=c}while(i>Qs);return s.join("")+String.fromCharCode.apply(String,n.subarray(o,o+i))}function kf(r){let e={};function t(i,o){return i?Iw(i.buffer,o):"<yet unknown>"}let n=r.env=r.env||{};return n.abort=n.abort||function(o,s,a,c){let u=e.memory||n.memory;throw Error("abort: "+t(u,o)+" at "+t(u,s)+":"+a+":"+c)},n.trace=n.trace||function(o,s){let a=e.memory||n.memory;console.log("trace: "+t(a,o)+(s?" ":"")+Array.prototype.slice.call(arguments,2,2+s).join(", "))},r.Math=r.Math||Math,r.Date=r.Date||Date,e}function Rf(r,e){let t=e.exports,n=t.memory,i=t.table,o=t.__alloc,s=t.__retain,a=t.__rtti_base||-1;function c(B){let v=new Uint32Array(n.buffer),E=v[a>>>2];if((B>>>=0)>=E)throw Error("invalid id: "+B);return v[(a+4>>>2)+B*2]}function u(B){let v=new Uint32Array(n.buffer),E=v[a>>>2];if((B>>>=0)>=E)throw Error("invalid id: "+B);return v[(a+4>>>2)+B*2+1]}function l(B){return 31-Math.clz32(B>>>5&31)}function h(B){return 31-Math.clz32(B>>>14&31)}function p(B){let v=B.length,E=o(v<<1,1),R=new Uint16Array(n.buffer);for(var N=0,C=E>>>1;N<v;++N)R[C+N]=B.charCodeAt(N);return E}r.__allocString=p;function d(B){let v=n.buffer;if(new Uint32Array(v)[B+-8>>>2]!==1)throw Error("not a string: "+B);return Iw(v,B)}r.__getString=d;function f(B,v,E){let R=n.buffer;if(E)switch(B){case 2:return new Float32Array(R);case 3:return new Float64Array(R)}else switch(B){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: "+B)}function m(B,v){let E=c(B);if(!(E&3))throw Error("not an array: "+B+" @ "+E);let R=l(E),N=v.length,C=o(N<<R,0),H=o(E&2?16:12,B),D=new Uint32Array(n.buffer);D[H+0>>>2]=s(C),D[H+4>>>2]=C,D[H+8>>>2]=N<<R,E&2&&(D[H+12>>>2]=N);let ie=f(R,E&1024,E&2048);if(E&8192)for(let _=0;_<N;++_)ie[(C>>>R)+_]=s(v[_]);else ie.set(v,C>>>R);return H}r.__allocArray=m;function y(B){let v=new Uint32Array(n.buffer),E=v[B+-8>>>2],R=c(E);if(!(R&1))throw Error("not an array: "+E);let N=l(R);var C=v[B+4>>>2];let H=R&2?v[B+12>>>2]:v[C+-4>>>2]>>>N;return f(N,R&1024,R&2048).subarray(C>>>=N,C+H)}r.__getArrayView=y;function g(B){let v=y(B),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(B){let v=n.buffer,E=new Uint32Array(v)[B+-4>>>2];return v.slice(B,B+E)}r.__getArrayBuffer=x;function b(B,v,E){return new B(A(B,v,E))}function A(B,v,E){let R=n.buffer,N=new Uint32Array(R),C=N[E+4>>>2];return new B(R,C,N[C+-4>>>2]>>>v)}r.__getInt8Array=b.bind(null,Int8Array,0),r.__getInt8ArrayView=A.bind(null,Int8Array,0),r.__getUint8Array=b.bind(null,Uint8Array,0),r.__getUint8ArrayView=A.bind(null,Uint8Array,0),r.__getUint8ClampedArray=b.bind(null,Uint8ClampedArray,0),r.__getUint8ClampedArrayView=A.bind(null,Uint8ClampedArray,0),r.__getInt16Array=b.bind(null,Int16Array,1),r.__getInt16ArrayView=A.bind(null,Int16Array,1),r.__getUint16Array=b.bind(null,Uint16Array,1),r.__getUint16ArrayView=A.bind(null,Uint16Array,1),r.__getInt32Array=b.bind(null,Int32Array,2),r.__getInt32ArrayView=A.bind(null,Int32Array,2),r.__getUint32Array=b.bind(null,Uint32Array,2),r.__getUint32ArrayView=A.bind(null,Uint32Array,2),SB&&(r.__getInt64Array=b.bind(null,BigInt64Array,3),r.__getInt64ArrayView=A.bind(null,BigInt64Array,3),r.__getUint64Array=b.bind(null,BigUint64Array,3),r.__getUint64ArrayView=A.bind(null,BigUint64Array,3)),r.__getFloat32Array=b.bind(null,Float32Array,2),r.__getFloat32ArrayView=A.bind(null,Float32Array,2),r.__getFloat64Array=b.bind(null,Float64Array,3),r.__getFloat64ArrayView=A.bind(null,Float64Array,3);function I(B,v){let E=new Uint32Array(n.buffer);var R=E[B+-8>>>2];if(R<=E[a>>>2])do if(R==v)return!0;while(R=u(R));return!1}return r.__instanceof=I,r.memory=r.memory||n,r.table=r.table||i,Rw(t,r)}function Sw(r){return typeof Response<"u"&&r instanceof Response}async function _w(r,e){return Sw(r=await r)?kw(r,e):Rf(kf(e||(e={})),await WebAssembly.instantiate(r instanceof WebAssembly.Module?r:await WebAssembly.compile(r),e))}ea.instantiate=_w;function _B(r,e){return Rf(kf(e||(e={})),new WebAssembly.Instance(r instanceof WebAssembly.Module?r:new WebAssembly.Module(r),e))}ea.instantiateSync=_B;async function kw(r,e){return WebAssembly.instantiateStreaming?Rf(kf(e||(e={})),(await WebAssembly.instantiateStreaming(r,e)).instance):_w(Sw(r=await r)?r.arrayBuffer():r,e)}ea.instantiateStreaming=kw;function Rw(r,e){var t=e?Object.create(e):{},n=r.__argumentsLength?function(i){r.__argumentsLength.value=i}:r.__setArgumentsLength||r.__setargc||function(){};for(let i in r){if(!Object.prototype.hasOwnProperty.call(r,i))continue;let o=r[i],s=i.split("."),a=t;for(;s.length>1;){let l=s.shift();Object.prototype.hasOwnProperty.call(a,l)||(a[l]={}),a=a[l]}let c=s[0],u=c.indexOf("#");if(u>=0){let l=c.substring(0,u),h=a[l];if(typeof h>"u"||!h.prototype){let p=function(...d){return p.wrap(p.prototype.constructor(0,...d))};p.prototype={valueOf:function(){return this[Js]}},p.wrap=function(d){return Object.create(p.prototype,{[Js]:{value:d,writable:!1}})},h&&Object.getOwnPropertyNames(h).forEach(d=>Object.defineProperty(p,d,Object.getOwnPropertyDescriptor(h,d))),a[l]=p}if(c=c.substring(u+1),a=a[l].prototype,/^(get|set):/.test(c)){if(!Object.prototype.hasOwnProperty.call(a,c=c.substring(4))){let p=r[i.replace("set:","get:")],d=r[i.replace("get:","set:")];Object.defineProperty(a,c,{get:function(){return p(this[Js])},set:function(f){d(this[Js],f)},enumerable:!0})}}else c==="constructor"?(a[c]=(...p)=>(n(p.length),o(...p))).original=o:(a[c]=function(...p){return n(p.length),o(this[Js],...p)}).original=o}else/^(get|set):/.test(c)?Object.prototype.hasOwnProperty.call(a,c=c.substring(4))||Object.defineProperty(a,c,{get:r[i.replace("set:","get:")],set:r[i.replace("get:","set:")],enumerable:!0}):typeof o=="function"&&o!==n?(a[c]=(...l)=>(n(l.length),o(...l))).original=o:a[c]=o}return t}ea.demangle=Rw});var Nw=me((_O,Cw)=>{var{instantiate:kB}=Tw();Tf.supported=typeof WebAssembly<"u";function Tf(r={}){if(!Tf.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 kB(new Response(new Blob([e],{type:"application/wasm"})),r)}Cw.exports=Tf});var Dw=me((kO,Lw)=>{var Uw=Aw(),RB=Nw(),TB=async(r,e,t,n,i)=>{let o=await RB();return new Uw(o,r,e,t,n,i)};Lw.exports={Rabin:Uw,create:TB}});var a2=me((ZF,s2)=>{"use strict";s2.exports=r=>{if(Object.prototype.toString.call(r)!=="[object Object]")return!1;let e=Object.getPrototypeOf(r);return e===null||e===Object.prototype}});var f2=me((h2,d2)=>{"use strict";var Ml=a2(),{hasOwnProperty:l2}=Object.prototype,{propertyIsEnumerable:rA}=Object,Oo=(r,e,t)=>Object.defineProperty(r,e,{value:t,writable:!0,enumerable:!0,configurable:!0}),nA=h2,c2={concatArrays:!1,ignoreUndefined:!1},Hl=r=>{let e=[];for(let t in r)l2.call(r,t)&&e.push(t);if(Object.getOwnPropertySymbols){let t=Object.getOwnPropertySymbols(r);for(let n of t)rA.call(r,n)&&e.push(n)}return e};function Fo(r){return Array.isArray(r)?iA(r):Ml(r)?oA(r):r}function iA(r){let e=r.slice(0,0);return Hl(r).forEach(t=>{Oo(e,t,Fo(r[t]))}),e}function oA(r){let e=Object.getPrototypeOf(r)===null?Object.create(null):{};return Hl(r).forEach(t=>{Oo(e,t,Fo(r[t]))}),e}var u2=(r,e,t,n)=>(t.forEach(i=>{typeof e[i]>"u"&&n.ignoreUndefined||(i in r&&r[i]!==Object.getPrototypeOf(r)?Oo(r,i,Uf(r[i],e[i],n)):Oo(r,i,Fo(e[i])))}),r),sA=(r,e,t)=>{let n=r.slice(0,0),i=0;return[r,e].forEach(o=>{let s=[];for(let a=0;a<o.length;a++)l2.call(o,a)&&(s.push(String(a)),o===r?Oo(n,i++,o[a]):Oo(n,i++,Fo(o[a])));n=u2(n,o,Hl(o).filter(a=>!s.includes(a)),t)}),n};function Uf(r,e,t){return t.concatArrays&&Array.isArray(r)&&Array.isArray(e)?sA(r,e,t):!Ml(e)||!Ml(r)?Fo(e):u2(r,e,Hl(e),t)}d2.exports=function(...r){let e=Uf(Fo(c2),this!==nA&&this||{},c2),t={_:{}};for(let n of r)if(n!==void 0){if(!Ml(n))throw new TypeError("`"+n+"` is not an Option Object");t=Uf(t,{_:n},e)}return t._}});var qA={};Ae(qA,{createVerifiedFetch:()=>Hf,verifiedFetch:()=>ru});function oi(r){let e=new globalThis.AbortController;function t(){e.abort();for(let o of r)o?.removeEventListener!=null&&o.removeEventListener("abort",t)}for(let o of r){if(o?.aborted===!0){t();break}o?.addEventListener!=null&&o.addEventListener("abort",t)}function n(){for(let o of r)o?.removeEventListener!=null&&o.removeEventListener("abort",t)}let i=e.signal;return i.clear=n,i}function Z2(r){let[e,t]=r[Symbol.asyncIterator]!=null?[r[Symbol.asyncIterator](),Symbol.asyncIterator]:[r[Symbol.iterator](),Symbol.iterator],n=[];return{peek:()=>e.next(),push:i=>{n.push(i)},next:()=>n.length>0?{done:!1,value:n.shift()}:e.next(),[t](){return this}}}var Pi=Z2;function J2(r){return r[Symbol.asyncIterator]!=null}function Zf(r){return r?.then!=null}function Q2(r,e){if(J2(r))return async function*(){for await(let a of r){let c=e(a);Zf(c)&&await c,yield a}}();let t=Pi(r),{value:n,done:i}=t.next();if(i===!0)return function*(){}();if(typeof e(n)?.then=="function")return async function*(){yield n;for await(let a of t){let c=e(a);Zf(c)&&await c,yield a}}();let s=e;return function*(){yield n;for(let a of t)s(a),yield a}()}var iu=Q2;var du={};Ae(du,{base32:()=>qe,base32hex:()=>ux,base32hexpad:()=>dx,base32hexpadupper:()=>fx,base32hexupper:()=>hx,base32pad:()=>cx,base32padupper:()=>lx,base32upper:()=>t0,base32z:()=>px});var Oi={};Ae(Oi,{coerce:()=>Lt,empty:()=>Jf,equals:()=>ou,fromHex:()=>tx,fromString:()=>su,isBinary:()=>rx,toHex:()=>ex,toString:()=>au});var Jf=new Uint8Array(0);function ex(r){return r.reduce((e,t)=>e+t.toString(16).padStart(2,"0"),"")}function tx(r){let e=r.match(/../g);return e!=null?new Uint8Array(e.map(t=>parseInt(t,16))):Jf}function ou(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 Lt(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 rx(r){return r instanceof ArrayBuffer||ArrayBuffer.isView(r)}function su(r){return new TextEncoder().encode(r)}function au(r){return new TextDecoder().decode(r)}function nx(r,e){if(r.length>=255)throw new TypeError("Alphabet too long");for(var t=new Uint8Array(256),n=0;n<t.length;n++)t[n]=255;for(var i=0;i<r.length;i++){var o=r.charAt(i),s=o.charCodeAt(0);if(t[s]!==255)throw new TypeError(o+" is ambiguous");t[s]=i}var a=r.length,c=r.charAt(0),u=Math.log(a)/Math.log(256),l=Math.log(256)/Math.log(a);function h(f){if(f instanceof Uint8Array||(ArrayBuffer.isView(f)?f=new Uint8Array(f.buffer,f.byteOffset,f.byteLength):Array.isArray(f)&&(f=Uint8Array.from(f))),!(f instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(f.length===0)return"";for(var m=0,y=0,g=0,x=f.length;g!==x&&f[g]===0;)g++,m++;for(var b=(x-g)*l+1>>>0,A=new Uint8Array(b);g!==x;){for(var I=f[g],B=0,v=b-1;(I!==0||B<y)&&v!==-1;v--,B++)I+=256*A[v]>>>0,A[v]=I%a>>>0,I=I/a>>>0;if(I!==0)throw new Error("Non-zero carry");y=B,g++}for(var E=b-y;E!==b&&A[E]===0;)E++;for(var R=c.repeat(m);E<b;++E)R+=r.charAt(A[E]);return R}function p(f){if(typeof f!="string")throw new TypeError("Expected String");if(f.length===0)return new Uint8Array;var m=0;if(f[m]!==" "){for(var y=0,g=0;f[m]===c;)y++,m++;for(var x=(f.length-m)*u+1>>>0,b=new Uint8Array(x);f[m];){var A=t[f.charCodeAt(m)];if(A===255)return;for(var I=0,B=x-1;(A!==0||I<g)&&B!==-1;B--,I++)A+=a*b[B]>>>0,b[B]=A%256>>>0,A=A/256>>>0;if(A!==0)throw new Error("Non-zero carry");g=I,m++}if(f[m]!==" "){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(f){var m=p(f);if(m)return m;throw new Error(`Non-${e} character`)}return{encode:h,decodeUnsafe:p,decode:d}}var ix=nx,ox=ix,Qf=ox;var cu=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")}},lu=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 e0(this,e)}},uu=class{decoders;constructor(e){this.decoders=e}or(e){return e0(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 e0(r,e){return new uu({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}var hu=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,t,n,i){this.name=e,this.prefix=t,this.baseEncode=n,this.baseDecode=i,this.encoder=new cu(e,t,n),this.decoder=new lu(e,t,i)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function Fi({name:r,prefix:e,encode:t,decode:n}){return new hu(r,e,t,n)}function En({name:r,prefix:e,alphabet:t}){let{encode:n,decode:i}=Qf(t,r);return Fi({prefix:e,name:r,encode:n,decode:o=>Lt(i(o))})}function sx(r,e,t,n){let i={};for(let l=0;l<e.length;++l)i[e[l]]=l;let o=r.length;for(;r[o-1]==="=";)--o;let s=new Uint8Array(o*t/8|0),a=0,c=0,u=0;for(let l=0;l<o;++l){let h=i[r[l]];if(h===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<t|h,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 ax(r,e,t){let n=e[e.length-1]==="=",i=(1<<t)-1,o="",s=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],s+=8;s>t;)s-=t,o+=e[i&a>>s];if(s!==0&&(o+=e[i&a<<t-s]),n)for(;o.length*t&7;)o+="=";return o}function Ie({name:r,prefix:e,bitsPerChar:t,alphabet:n}){return Fi({prefix:e,name:r,encode(i){return ax(i,n,t)},decode(i){return sx(i,n,t,r)}})}var qe=Ie({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),t0=Ie({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),cx=Ie({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),lx=Ie({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),ux=Ie({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),hx=Ie({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),dx=Ie({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),fx=Ie({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),px=Ie({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var fu={};Ae(fu,{base58btc:()=>ke,base58flickr:()=>mx});var ke=En({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),mx=En({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var yx=i0,r0=128,gx=127,wx=~gx,xx=Math.pow(2,31);function i0(r,e,t){e=e||[],t=t||0;for(var n=t;r>=xx;)e[t++]=r&255|r0,r/=128;for(;r&wx;)e[t++]=r&255|r0,r>>>=7;return e[t]=r|0,i0.bytes=t-n+1,e}var bx=pu,Ex=128,n0=127;function pu(r,n){var t=0,n=n||0,i=0,o=n,s,a=r.length;do{if(o>=a)throw pu.bytes=0,new RangeError("Could not decode varint");s=r[o++],t+=i<28?(s&n0)<<i:(s&n0)*Math.pow(2,i),i+=7}while(s>=Ex);return pu.bytes=o-n,t}var vx=Math.pow(2,7),Bx=Math.pow(2,14),Ax=Math.pow(2,21),Ix=Math.pow(2,28),Sx=Math.pow(2,35),_x=Math.pow(2,42),kx=Math.pow(2,49),Rx=Math.pow(2,56),Tx=Math.pow(2,63),Cx=function(r){return r<vx?1:r<Bx?2:r<Ax?3:r<Ix?4:r<Sx?5:r<_x?6:r<kx?7:r<Rx?8:r<Tx?9:10},Nx={encode:yx,decode:bx,encodingLength:Cx},Ux=Nx,qo=Ux;function jo(r,e=0){return[qo.decode(r,e),qo.decode.bytes]}function Vi(r,e,t=0){return qo.encode(r,e,t),e}function Mi(r){return qo.encodingLength(r)}function dr(r,e){let t=e.byteLength,n=Mi(r),i=n+Mi(t),o=new Uint8Array(i+t);return Vi(r,o,0),Vi(t,o,n),o.set(e,i),new Hi(r,t,e,o)}function bt(r){let e=Lt(r),[t,n]=jo(e),[i,o]=jo(e.subarray(n)),s=e.subarray(n+o);if(s.byteLength!==i)throw new Error("Incorrect length");return new Hi(t,i,s,e)}function o0(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&ou(r.bytes,t.bytes)}}var Hi=class{code;size;digest;bytes;constructor(e,t,n,i){this.code=e,this.size=t,this.digest=n,this.bytes=i}};function s0(r,e){let{bytes:t,version:n}=r;switch(n){case 0:return Dx(t,mu(r),e??ke.encoder);default:return Px(t,mu(r),e??qe.encoder)}}var a0=new WeakMap;function mu(r){let e=a0.get(r);if(e==null){let t=new Map;return a0.set(r,t),t}return e}var V=class r{code;version;multihash;bytes;"/";constructor(e,t,n,i){this.code=t,this.version=e,this.multihash=n,this.bytes=i,this["/"]=i}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:e,multihash:t}=this;if(e!==Go)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==Ox)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=dr(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&&o0(e.multihash,n.multihash)}toString(e){return s0(this,e)}toJSON(){return{"/":s0(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(e){if(e==null)return null;let t=e;if(t instanceof r)return t;if(t["/"]!=null&&t["/"]===t.bytes||t.asCID===t){let{version:n,code:i,multihash:o,bytes:s}=t;return new r(n,i,o,s??c0(n,i,o.bytes))}else if(t[Fx]===!0){let{version:n,multihash:i,code:o}=t,s=bt(i);return r.create(n,o,s)}else return null}static create(e,t,n){if(typeof t!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(e){case 0:{if(t!==Go)throw new Error(`Version 0 CID must use dag-pb (code: ${Go}) block encoding`);return new r(e,t,n,n.bytes)}case 1:{let i=c0(e,t,n.bytes);return new r(e,t,n,i)}default:throw new Error("Invalid version")}}static createV0(e){return r.create(0,Go,e)}static createV1(e,t){return r.create(1,e,t)}static decode(e){let[t,n]=r.decodeFirst(e);if(n.length!==0)throw new Error("Incorrect length");return t}static decodeFirst(e){let t=r.inspectBytes(e),n=t.size-t.multihashSize,i=Lt(e.subarray(n,n+t.multihashSize));if(i.byteLength!==t.multihashSize)throw new Error("Incorrect length");let o=i.subarray(t.multihashSize-t.digestSize),s=new Hi(t.multihashCode,t.digestSize,o,i);return[t.version===0?r.createV0(s):r.createV1(t.codec,s),e.subarray(t.size)]}static inspectBytes(e){let t=0,n=()=>{let[h,p]=jo(e.subarray(t));return t+=p,h},i=n(),o=Go;if(i===18?(i=0,t=0):o=n(),i!==0&&i!==1)throw new RangeError(`Invalid CID version ${i}`);let s=t,a=n(),c=n(),u=t+c,l=u-s;return{version:i,codec:o,multihashCode:a,digestSize:c,multihashSize:l,size:u}}static parse(e,t){let[n,i]=Lx(e,t),o=r.decode(i);if(o.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return mu(o).set(n,e),o}};function Lx(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 qe.prefix:{let t=e??qe;return[qe.prefix,t.decode(r)]}default:{if(e==null)throw Error("To parse non base32 or base58btc encoded CID multibase decoder must be provided");return[r[0],e.decode(r)]}}}function Dx(r,e,t){let{prefix:n}=t;if(n!==ke.prefix)throw Error(`Cannot string encode V0 in ${t.name} encoding`);let i=e.get(n);if(i==null){let o=t.encode(r).slice(1);return e.set(n,o),o}else return i}function Px(r,e,t){let{prefix:n}=t,i=e.get(n);if(i==null){let o=t.encode(r);return e.set(n,o),o}else return i}var Go=112,Ox=18;function c0(r,e,t){let n=Mi(r),i=n+Mi(e),o=new Uint8Array(i+t.byteLength);return Vi(r,o,0),Vi(e,o,n),o.set(t,i),o}var Fx=Symbol.for("@ipld/js-cid/CID");var Wo=Symbol.for("@libp2p/content-routing");var yu=Symbol.for("@libp2p/peer-id");function l0(r){return r!=null&&!!r[yu]}var Yo=Symbol.for("@libp2p/peer-routing");var vn=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"},F=class extends Error{code;props;constructor(e,t,n){super(e),this.code=t,this.name=n?.name??"CodeError",this.props=n??{}}};var ha=class extends EventTarget{#e=new Map;listenerCount(e){let t=this.#e.get(e);return t==null?0:t.length}addEventListener(e,t,n){super.addEventListener(e,t,n);let i=this.#e.get(e);i==null&&(i=[],this.#e.set(e,i)),i.push({callback:t,once:(n!==!0&&n!==!1&&n?.once)??!1})}removeEventListener(e,t,n){super.removeEventListener(e.toString(),t??null,n);let i=this.#e.get(e);i!=null&&(i=i.filter(({callback:o})=>o!==t),this.#e.set(e,i))}dispatchEvent(e){let t=super.dispatchEvent(e),n=this.#e.get(e.type);return n==null||(n=n.filter(({once:i})=>!i),this.#e.set(e.type,n)),t}safeDispatchEvent(e,t={}){return this.dispatchEvent(new Vx(e,t))}},gu=class extends Event{detail;constructor(e,t){super(e,t),this.detail=t?.detail}},Vx=globalThis.CustomEvent??gu;var da=(r,...e)=>{try{[...e]}catch{}};function u0(r){return r!=null&&typeof r.start=="function"&&typeof r.stop=="function"}async function Bn(...r){let e=[];for(let t of r)u0(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 An(...r){let e=[];for(let t of r)u0(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 bu={};Ae(bu,{sha256:()=>ne,sha512:()=>xu});function si({name:r,code:e,encode:t}){return new wu(r,e,t)}var wu=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?dr(this.code,t):t.then(n=>dr(this.code,n))}else throw Error("Unknown type, must be binary type")}};function d0(r){return async e=>new Uint8Array(await crypto.subtle.digest(r,e))}var ne=si({name:"sha2-256",code:18,encode:d0("SHA-256")}),xu=si({name:"sha2-512",code:19,encode:d0("SHA-512")});var vt=re(vu(),1);var Bu={};Ae(Bu,{base64:()=>pr,base64pad:()=>Jx,base64url:()=>y0,base64urlpad:()=>Qx});var pr=Ie({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Jx=Ie({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),y0=Ie({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Qx=Ie({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});vt.default.formatters.b=r=>r==null?"undefined":ke.baseEncode(r);vt.default.formatters.t=r=>r==null?"undefined":qe.baseEncode(r);vt.default.formatters.m=r=>r==null?"undefined":pr.baseEncode(r);vt.default.formatters.p=r=>r==null?"undefined":r.toString();vt.default.formatters.c=r=>r==null?"undefined":r.toString();vt.default.formatters.k=r=>r==null?"undefined":r.toString();vt.default.formatters.a=r=>r==null?"undefined":r.toString();function eb(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 g0(){return{forComponent(r){return se(r)}}}function se(r){let e=eb(`${r}:trace`);return vt.default.enabled(`${r}:trace`)&&vt.default.names.map(t=>t.toString()).find(t=>t.includes(":trace"))!=null&&(e=(0,vt.default)(`${r}:trace`)),Object.assign((0,vt.default)(r),{error:(0,vt.default)(`${r}:error`),trace:e})}function de(r,e){if(r===e)return!0;if(r.byteLength!==e.byteLength)return!1;for(let t=0;t<r.byteLength;t++)if(r[t]!==e[t])return!1;return!0}function In(r){return globalThis.Buffer!=null?new Uint8Array(r.buffer,r.byteOffset,r.byteLength):r}function Fr(r=0){return globalThis.Buffer?.alloc!=null?In(globalThis.Buffer.alloc(r)):new Uint8Array(r)}function ht(r=0){return globalThis.Buffer?.allocUnsafe!=null?In(globalThis.Buffer.allocUnsafe(r)):new Uint8Array(r)}var tb=Math.pow(2,7),rb=Math.pow(2,14),nb=Math.pow(2,21),Au=Math.pow(2,28),Iu=Math.pow(2,35),Su=Math.pow(2,42),_u=Math.pow(2,49),fe=128,Je=127;function dt(r){if(r<tb)return 1;if(r<rb)return 2;if(r<nb)return 3;if(r<Au)return 4;if(r<Iu)return 5;if(r<Su)return 6;if(r<_u)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function ku(r,e,t=0){switch(dt(r)){case 8:e[t++]=r&255|fe,r/=128;case 7:e[t++]=r&255|fe,r/=128;case 6:e[t++]=r&255|fe,r/=128;case 5:e[t++]=r&255|fe,r/=128;case 4:e[t++]=r&255|fe,r>>>=7;case 3:e[t++]=r&255|fe,r>>>=7;case 2:e[t++]=r&255|fe,r>>>=7;case 1:{e[t++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return e}function ib(r,e,t=0){switch(dt(r)){case 8:e.set(t++,r&255|fe),r/=128;case 7:e.set(t++,r&255|fe),r/=128;case 6:e.set(t++,r&255|fe),r/=128;case 5:e.set(t++,r&255|fe),r/=128;case 4:e.set(t++,r&255|fe),r>>>=7;case 3:e.set(t++,r&255|fe),r>>>=7;case 2:e.set(t++,r&255|fe),r>>>=7;case 1:{e.set(t++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return e}function Ru(r,e){let t=r[e],n=0;if(n+=t&Je,t<fe||(t=r[e+1],n+=(t&Je)<<7,t<fe)||(t=r[e+2],n+=(t&Je)<<14,t<fe)||(t=r[e+3],n+=(t&Je)<<21,t<fe)||(t=r[e+4],n+=(t&Je)*Au,t<fe)||(t=r[e+5],n+=(t&Je)*Iu,t<fe)||(t=r[e+6],n+=(t&Je)*Su,t<fe)||(t=r[e+7],n+=(t&Je)*_u,t<fe))return n;throw new RangeError("Could not decode varint")}function ob(r,e){let t=r.get(e),n=0;if(n+=t&Je,t<fe||(t=r.get(e+1),n+=(t&Je)<<7,t<fe)||(t=r.get(e+2),n+=(t&Je)<<14,t<fe)||(t=r.get(e+3),n+=(t&Je)<<21,t<fe)||(t=r.get(e+4),n+=(t&Je)*Au,t<fe)||(t=r.get(e+5),n+=(t&Je)*Iu,t<fe)||(t=r.get(e+6),n+=(t&Je)*Su,t<fe)||(t=r.get(e+7),n+=(t&Je)*_u,t<fe))return n;throw new RangeError("Could not decode varint")}function qi(r,e,t=0){return e==null&&(e=ht(dt(r))),e instanceof Uint8Array?ku(r,e,t):ib(r,e,t)}function ci(r,e=0){return r instanceof Uint8Array?Ru(r,e):ob(r,e)}var Tu=new Float32Array([-0]),Sn=new Uint8Array(Tu.buffer);function x0(r,e,t){Tu[0]=r,e[t]=Sn[0],e[t+1]=Sn[1],e[t+2]=Sn[2],e[t+3]=Sn[3]}function b0(r,e){return Sn[0]=r[e],Sn[1]=r[e+1],Sn[2]=r[e+2],Sn[3]=r[e+3],Tu[0]}var Cu=new Float64Array([-0]),Qe=new Uint8Array(Cu.buffer);function E0(r,e,t){Cu[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 v0(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],Cu[0]}var sb=BigInt(Number.MAX_SAFE_INTEGER),ab=BigInt(Number.MIN_SAFE_INTEGER),Bt=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 li;if(e<sb&&e>ab)return this.fromNumber(Number(e));let t=e<0n;t&&(e=-e);let n=e>>32n,i=e-(n<<32n);return t&&(n=~n|0n,i=~i|0n,++i>B0&&(i=0n,++n>B0&&(n=0n))),new r(Number(i),Number(n))}static fromNumber(e){if(e===0)return li;let t=e<0;t&&(e=-e);let n=e>>>0,i=(e-n)/4294967296>>>0;return t&&(i=~i>>>0,n=~n>>>0,++n>4294967295&&(n=0,++i>4294967295&&(i=0))),new r(n,i)}static from(e){return typeof e=="number"?r.fromNumber(e):typeof e=="bigint"?r.fromBigInt(e):typeof e=="string"?r.fromBigInt(BigInt(e)):e.low!=null||e.high!=null?new r(e.low>>>0,e.high>>>0):li}},li=new Bt(0,0);li.toBigInt=function(){return 0n};li.zzEncode=li.zzDecode=function(){return this};li.length=function(){return 1};var B0=4294967296n;function A0(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 I0(r,e,t){if(t-e<1)return"";let i,o=[],s=0,a;for(;e<t;)a=r[e++],a<128?o[s++]=a:a>191&&a<224?o[s++]=(a&31)<<6|r[e++]&63:a>239&&a<365?(a=((a&7)<<18|(r[e++]&63)<<12|(r[e++]&63)<<6|r[e++]&63)-65536,o[s++]=55296+(a>>10),o[s++]=56320+(a&1023)):o[s++]=(a&15)<<12|(r[e++]&63)<<6|r[e++]&63,s>8191&&((i??(i=[])).push(String.fromCharCode.apply(String,o)),s=0);return i!=null?(s>0&&i.push(String.fromCharCode.apply(String,o.slice(0,s))),i.join("")):String.fromCharCode.apply(String,o.slice(0,s))}function Nu(r,e,t){let n=t,i,o;for(let s=0;s<r.length;++s)i=r.charCodeAt(s),i<128?e[t++]=i:i<2048?(e[t++]=i>>6|192,e[t++]=i&63|128):(i&64512)===55296&&((o=r.charCodeAt(s+1))&64512)===56320?(i=65536+((i&1023)<<10)+(o&1023),++s,e[t++]=i>>18|240,e[t++]=i>>12&63|128,e[t++]=i>>6&63|128,e[t++]=i&63|128):(e[t++]=i>>12|224,e[t++]=i>>6&63|128,e[t++]=i&63|128);return t-n}function jt(r,e){return RangeError(`index out of range: ${r.pos} + ${e??1} > ${r.len}`)}function ma(r,e){return(r[e-4]|r[e-3]<<8|r[e-2]<<16|r[e-1]<<24)>>>0}var Uu=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,jt(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 jt(this,4);return ma(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw jt(this,4);return ma(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw jt(this,4);let e=b0(this.buf,this.pos);return this.pos+=4,e}double(){if(this.pos+8>this.len)throw jt(this,4);let e=v0(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 jt(this,e);return this.pos+=e,t===n?new Uint8Array(0):this.buf.subarray(t,n)}string(){let e=this.bytes();return I0(e,0,e.length)}skip(e){if(typeof e=="number"){if(this.pos+e>this.len)throw jt(this,e);this.pos+=e}else do if(this.pos>=this.len)throw jt(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 Bt(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 jt(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 jt(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 jt(this,8);let e=ma(this.buf,this.pos+=4),t=ma(this.buf,this.pos+=4);return new Bt(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=Ru(this.buf,this.pos);return this.pos+=dt(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 Lu(r){return new Uu(r instanceof Uint8Array?r:r.subarray())}function Dt(r,e,t){let n=Lu(r);return e.decode(n,void 0,t)}var Du={};Ae(Du,{base10:()=>cb});var cb=En({prefix:"9",name:"base10",alphabet:"0123456789"});var Pu={};Ae(Pu,{base16:()=>lb,base16upper:()=>ub});var lb=Ie({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),ub=Ie({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Ou={};Ae(Ou,{base2:()=>hb});var hb=Ie({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Fu={};Ae(Fu,{base256emoji:()=>yb});var _0=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}"),db=_0.reduce((r,e,t)=>(r[t]=e,r),[]),fb=_0.reduce((r,e,t)=>(r[e.codePointAt(0)]=t,r),[]);function pb(r){return r.reduce((e,t)=>(e+=db[t],e),"")}function mb(r){let e=[];for(let t of r){let n=fb[t.codePointAt(0)];if(n===void 0)throw new Error(`Non-base256emoji character: ${t}`);e.push(n)}return new Uint8Array(e)}var yb=Fi({prefix:"\u{1F680}",name:"base256emoji",encode:pb,decode:mb});var Vu={};Ae(Vu,{base36:()=>_n,base36upper:()=>gb});var _n=En({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),gb=En({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Mu={};Ae(Mu,{base8:()=>wb});var wb=Ie({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Hu={};Ae(Hu,{identity:()=>xb});var xb=Fi({prefix:"\0",name:"identity",encode:r=>au(r),decode:r=>su(r)});var bb=new TextEncoder,Eb=new TextDecoder;var kn=512;function k0(r){return bb.encode(JSON.stringify(r))}function ya(r){return JSON.parse(Eb.decode(r))}var Pt={};Ae(Pt,{code:()=>Ne,decode:()=>$u,encode:()=>Bb,name:()=>vb});var vb="raw",Ne=85;function Bb(r){return Lt(r)}function $u(r){return Lt(r)}var zu={};Ae(zu,{identity:()=>et});var R0=0,Ab="identity",T0=Lt;function Ib(r){return dr(R0,T0(r))}var et={code:R0,name:Ab,encode:T0,digest:Ib};var Rn={...Hu,...Ou,...Mu,...Du,...Pu,...du,...Vu,...fu,...Bu,...Fu},iI={...bu,...zu};function N0(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}var C0=N0("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Ku=N0("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=ht(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),Sb={utf8:C0,"utf-8":C0,hex:Rn.base16,latin1:Ku,ascii:Ku,binary:Ku,...Rn},ga=Sb;function Y(r,e="utf8"){let t=ga[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return(e==="utf8"||e==="utf-8")&&globalThis.Buffer!=null&&globalThis.Buffer.from!=null?In(globalThis.Buffer.from(r,"utf-8")):t.decoder.decode(`${t.prefix}${r}`)}function qu(r){let e=r??8192,t=e>>>1,n,i=e;return function(s){if(s<1||s>t)return ht(s);i+s>e&&(n=ht(e),i=0);let a=n.subarray(i,i+=s);return i&7&&(i=(i|7)+1),a}}var ui=class{fn;len;next;val;constructor(e,t,n){this.fn=e,this.len=t,this.next=void 0,this.val=n}};function ju(){}var Wu=class{head;tail;len;next;constructor(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}},_b=qu();function kb(r){return globalThis.Buffer!=null?ht(r):_b(r)}var Jo=class{len;head;tail;states;constructor(){this.len=0,this.head=new ui(ju,0,0),this.tail=this.head,this.states=null}_push(e,t,n){return this.tail=this.tail.next=new ui(e,t,n),this.len+=t,this}uint32(e){return this.len+=(this.tail=this.tail.next=new Yu((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(wa,10,Bt.fromNumber(e)):this.uint32(e)}sint32(e){return this.uint32((e<<1^e>>31)>>>0)}uint64(e){let t=Bt.fromBigInt(e);return this._push(wa,t.length(),t)}uint64Number(e){return this._push(ku,dt(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=Bt.fromBigInt(e).zzEncode();return this._push(wa,t.length(),t)}sint64Number(e){let t=Bt.fromNumber(e).zzEncode();return this._push(wa,t.length(),t)}sint64String(e){return this.sint64(BigInt(e))}bool(e){return this._push(Gu,1,e?1:0)}fixed32(e){return this._push(Zo,4,e>>>0)}sfixed32(e){return this.fixed32(e)}fixed64(e){let t=Bt.fromBigInt(e);return this._push(Zo,4,t.lo)._push(Zo,4,t.hi)}fixed64Number(e){let t=Bt.fromNumber(e);return this._push(Zo,4,t.lo)._push(Zo,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(x0,4,e)}double(e){return this._push(E0,8,e)}bytes(e){let t=e.length>>>0;return t===0?this._push(Gu,1,0):this.uint32(t)._push(Tb,t,e)}string(e){let t=A0(e);return t!==0?this.uint32(t)._push(Nu,t,e):this._push(Gu,1,0)}fork(){return this.states=new Wu(this),this.head=this.tail=new ui(ju,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 ui(ju,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=kb(this.len),n=0;for(;e!=null;)e.fn(e.val,t,n),n+=e.len,e=e.next;return t}};function Gu(r,e,t){e[t]=r&255}function Rb(r,e,t){for(;r>127;)e[t++]=r&127|128,r>>>=7;e[t]=r}var Yu=class extends ui{next;constructor(e,t){super(Rb,e,t),this.next=void 0}};function wa(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 Zo(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 Tb(r,e,t){e.set(r,t)}globalThis.Buffer!=null&&(Jo.prototype.bytes=function(r){let e=r.length>>>0;return this.uint32(e),e>0&&this._push(Cb,e,r),this},Jo.prototype.string=function(r){let e=globalThis.Buffer.byteLength(r);return this.uint32(e),e>0&&this._push(Nb,e,r),this});function Cb(r,e,t){e.set(r,t)}function Nb(r,e,t){r.length<40?Nu(r,e,t):e.utf8Write!=null?e.utf8Write(r,t):e.set(Y(r),t)}function Xu(){return new Jo}function Ot(r,e){let t=Xu();return e.encode(r,t,{lengthDelimited:!1}),t.finish()}var ji;(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"})(ji||(ji={}));function xa(r,e,t,n){return{name:r,type:e,encode:t,decode:n}}function hi(r){function e(i){if(r[i.toString()]==null)throw new Error("Invalid enum value");return r[i]}let t=function(o,s){let a=e(o);s.int32(a)},n=function(o){let s=o.int32();return e(s)};return xa("enum",ji.VARINT,t,n)}function Ft(r,e){return xa("message",ji.LENGTH_DELIMITED,r,e)}function Ub(r){return r[Symbol.asyncIterator]!=null}function Lb(r){if(Ub(r))return(async()=>{for await(let e of r);})();for(let e of r);}var Vr=Lb;function Ee(r,e){if(globalThis.Buffer!=null)return In(globalThis.Buffer.concat(r,e));e==null&&(e=r.reduce((i,o)=>i+o.length,0));let t=ht(e),n=0;for(let i of r)t.set(i,n),n+=i.length;return In(t)}var L0=Symbol.for("@achingbrain/uint8arraylist");function U0(r,e){if(e==null||e<0)throw new RangeError("index is out of bounds");let t=0;for(let n of r){let i=t+n.byteLength;if(e<i)return{buf:n,index:e-t};t=i}throw new RangeError("index is out of bounds")}function ba(r){return!!r?.[L0]}var di=class r{bufs;length;[L0]=!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(ba(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(ba(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=U0(this.bufs,e);return t.buf[t.index]}set(e,t){let n=U0(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(ba(e))for(let n=0;n<e.length;n++)this.set(t+n,e.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(e){if(e=Math.trunc(e),!(Number.isNaN(e)||e<=0)){if(e===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(e>=this.bufs[0].byteLength)e-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(e),this.length-=e;break}}}slice(e,t){let{bufs:n,length:i}=this._subList(e,t);return Ee(n,i)}subarray(e,t){let{bufs:n,length:i}=this._subList(e,t);return n.length===1?n[0]:Ee(n,i)}sublist(e,t){let{bufs:n,length:i}=this._subList(e,t),o=new r;return o.length=i,o.bufs=[...n],o}_subList(e,t){if(e=e??0,t=t??this.length,e<0&&(e=this.length+e),t<0&&(t=this.length+t),e<0||t>this.length)throw new RangeError("index is out of bounds");if(e===t)return{bufs:[],length:0};if(e===0&&t===this.length)return{bufs:this.bufs,length:this.length};let n=[],i=0;for(let o=0;o<this.bufs.length;o++){let s=this.bufs[o],a=i,c=a+s.byteLength;if(i=c,e>=c)continue;let u=e>=a&&e<c,l=t>a&&t<=c;if(u&&l){if(e===a&&t===c){n.push(s);break}let h=e-a;n.push(s.subarray(h,h+(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(!ba(e)&&!(e instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=e instanceof Uint8Array?e:e.subarray();if(t=Number(t??0),isNaN(t)&&(t=0),t<0&&(t=this.length+t),t<0&&(t=0),e.length===0)return t>this.length?this.length:t;let i=n.byteLength;if(i===0)throw new TypeError("search must be at least 1 byte long");let o=256,s=new Int32Array(o);for(let h=0;h<o;h++)s[h]=-1;for(let h=0;h<i;h++)s[n[h]]=h;let a=s,c=this.byteLength-n.byteLength,u=n.byteLength-1,l;for(let h=t;h<=c;h+=l){l=0;for(let p=u;p>=0;p--){let d=this.get(h+p);if(n[p]!==d){l=Math.max(1,p-a[d]);break}}if(l===0)return h}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=ht(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,t),this.write(n,e)}getInt16(e,t){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,t)}setInt16(e,t,n){let i=Fr(2);new DataView(i.buffer,i.byteOffset,i.byteLength).setInt16(0,t,n),this.write(i,e)}getInt32(e,t){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,t)}setInt32(e,t,n){let i=Fr(4);new DataView(i.buffer,i.byteOffset,i.byteLength).setInt32(0,t,n),this.write(i,e)}getBigInt64(e,t){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,t)}setBigInt64(e,t,n){let i=Fr(8);new DataView(i.buffer,i.byteOffset,i.byteLength).setBigInt64(0,t,n),this.write(i,e)}getUint8(e){let t=this.subarray(e,e+1);return new DataView(t.buffer,t.byteOffset,t.byteLength).getUint8(0)}setUint8(e,t){let n=ht(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,t),this.write(n,e)}getUint16(e,t){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,t)}setUint16(e,t,n){let i=Fr(2);new DataView(i.buffer,i.byteOffset,i.byteLength).setUint16(0,t,n),this.write(i,e)}getUint32(e,t){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,t)}setUint32(e,t,n){let i=Fr(4);new DataView(i.buffer,i.byteOffset,i.byteLength).setUint32(0,t,n),this.write(i,e)}getBigUint64(e,t){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,t)}setBigUint64(e,t,n){let i=Fr(8);new DataView(i.buffer,i.byteOffset,i.byteLength).setBigUint64(0,t,n),this.write(i,e)}getFloat32(e,t){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,t)}setFloat32(e,t,n){let i=Fr(4);new DataView(i.buffer,i.byteOffset,i.byteLength).setFloat32(0,t,n),this.write(i,e)}getFloat64(e,t){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,t)}setFloat64(e,t,n){let i=Fr(8);new DataView(i.buffer,i.byteOffset,i.byteLength).setFloat64(0,t,n),this.write(i,e)}equals(e){if(e==null||!(e instanceof r)||e.bufs.length!==this.bufs.length)return!1;for(let t=0;t<this.bufs.length;t++)if(!de(this.bufs[t],e.bufs[t]))return!1;return!0}static fromUint8Arrays(e,t){let n=new r;return n.bufs=e,t==null&&(t=e.reduce((i,o)=>i+o.byteLength,0)),n.length=t,n}};function Pb(r){return r[Symbol.asyncIterator]!=null}function Ob(r,e){if(Pb(r))return async function*(){for await(let a of r)yield e(a)}();let t=Pi(r),{value:n,done:i}=t.next();if(i===!0)return function*(){}();let o=e(n);if(typeof o.then=="function")return async function*(){yield await o;for await(let a of t)yield e(a)}();let s=e;return function*(){yield o;for(let a of t)yield s(a)}()}var Gt=Ob;function Ue(){let r={};return r.promise=new Promise((e,t)=>{r.resolve=e,r.reject=t}),r}var Ea=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}},Gi=class{size;hwm;head;tail;constructor(e={}){this.hwm=e.splitLimit??16,this.head=new Ea(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 Ea(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 Zu=class extends Error{type;code;constructor(e,t){super(e??"The operation was aborted"),this.type="aborted",this.code=t??"ABORT_ERR"}};function Vt(r={}){return Fb(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 Fb(r,e){e=e??{};let t=e.onEnd,n=new Gi,i,o,s,a=Ue(),c=async()=>{try{return n.isEmpty()?s?{done:!0}:await new Promise((y,g)=>{o=x=>{o=null,n.push(x);try{y(r(n))}catch(b){g(b)}return i}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=Ue()})}},u=y=>o!=null?o(y):(n.push(y),i),l=y=>(n=new Gi,o!=null?o({error:y}):(n.push({error:y}),i)),h=y=>{if(s)return i;if(e?.objectMode!==!0&&y?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return u({done:!1,value:y})},p=y=>s?i:(s=!0,y!=null?l(y):u({done:!0})),d=()=>(n=new Gi,p(),{done:!0}),f=y=>(p(y),{done:!0});if(i={[Symbol.asyncIterator](){return this},next:c,return:d,throw:f,push:h,end:p,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,I)=>{b=()=>{I(new Zu)},g.addEventListener("abort",b)}));try{await Promise.race([a.promise,x])}finally{b!=null&&g!=null&&g?.removeEventListener("abort",b)}}},t==null)return i;let m=i;return i={[Symbol.asyncIterator](){return this},next(){return m.next()},throw(y){return m.throw(y),t!=null&&(t(y),t=void 0),{done:!0}},return(){return m.return(),t!=null&&(t(),t=void 0),{done:!0}},push:h,end(y){return m.end(y),t!=null&&(t(y),t=void 0),i},get readableLength(){return m.readableLength},onEmpty:y=>m.onEmpty(y)},i}function Vb(r){return r[Symbol.asyncIterator]!=null}function Mb(...r){let e=[];for(let t of r)Vb(t)||e.push(t);return e.length===r.length?function*(){for(let t of e)yield*t}():async function*(){let t=Vt({objectMode:!0});Promise.resolve().then(async()=>{try{await Promise.all(r.map(async n=>{for await(let i of n)t.push(i)})),t.end()}catch(n){t.end(n)}}),yield*t}()}var Mr=Mb;function Wt(r,...e){if(r==null)throw new Error("Empty pipeline");if(Ju(r)){let n=r;r=()=>n.source}else if(F0(r)||O0(r)){let n=r;r=()=>n}let t=[r,...e];if(t.length>1&&Ju(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++)Ju(t[n])&&(t[n]=$b(t[n]));return Hb(...t)}var Hb=(...r)=>{let e;for(;r.length>0;)e=r.shift()(e);return e},O0=r=>r?.[Symbol.asyncIterator]!=null,F0=r=>r?.[Symbol.iterator]!=null,Ju=r=>r==null?!1:r.sink!=null&&r.source!=null,$b=r=>e=>{let t=r.sink(e);if(t?.then!=null){let n=Vt({objectMode:!0});t.then(()=>{n.end()},s=>{n.end(s)});let i,o=r.source;if(O0(o))i=async function*(){yield*o,n.end()};else if(F0(o))i=function*(){yield*o,n.end()};else throw new Error("Unknown duplex source type - must be Iterable or AsyncIterable");return Mr(n,i())}return r.source};function zb(r){return r[Symbol.asyncIterator]!=null}function Kb(r,e){return zb(r)?async function*(){let t=0;if(!(e<1)){for await(let n of r)if(yield n,t++,t===e)return}}():function*(){let t=0;if(!(e<1)){for(let n of r)if(yield n,t++,t===e)return}}()}var va=Kb;var P=class extends Event{constructor(e,t){super(e),this.detail=t}};function Q(r,e="utf8"){let t=ga[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return(e==="utf8"||e==="utf-8")&&globalThis.Buffer!=null&&globalThis.Buffer.from!=null?globalThis.Buffer.from(r.buffer,r.byteOffset,r.byteLength).toString("utf8"):t.encoder.encode(r).substring(1)}var Ba=class{url;#e=0;#t=0;#r=0;#s=0;constructor(e){this.url=e instanceof URL?e:new URL(e)}async getRawBlock(e,t){let n=this.url;if(n.pathname=`/ipfs/${e.toString()}`,n.search="?format=raw",t?.aborted===!0)throw new Error(`Signal to fetch raw block for CID ${e} from gateway ${this.url} was aborted prior to fetch`);try{this.#e++;let i=await fetch(n.toString(),{signal:t,headers:{Accept:"application/vnd.ipld.raw"},cache:"force-cache"});if(!i.ok)throw this.#t++,new Error(`unable to fetch raw block for CID ${e} from gateway ${this.url}`);return this.#s++,new Uint8Array(await i.arrayBuffer())}catch{throw t?.aborted===!0?new Error(`fetching raw block for CID ${e} from gateway ${this.url} was aborted`):(this.#t++,new Error(`unable to fetch raw block for CID ${e}`))}}reliability(){return this.#e===0?1:this.#r>0?-1/0:this.#s/(this.#e+this.#t*3)}incrementInvalidBlocks(){this.#r++}};var Aa=class{gateways;log;constructor(e,t={}){this.log=e.logger.forComponent("helia:trustless-gateway-block-broker"),this.gateways=(t.gateways??V0).map(n=>new Ba(n))}async retrieve(e,t={}){let n=this.gateways.sort((o,s)=>s.reliability()-o.reliability()),i=[];for(let o of n){this.log("getting block for %c from %s",e,o.url);try{let s=await o.getRawBlock(e,t.signal);this.log.trace("got block for %c from %s",e,o.url);try{await t.validateFn?.(s)}catch(a){throw this.log.error("failed to validate block for %c from %s",e,o.url,a),o.incrementInvalidBlocks(),new Error(`unable to validate block for CID ${e} from gateway ${o.url}`)}return s}catch(s){if(this.log.error("failed to get block for %c from %s",e,o.url,s),s instanceof Error?i.push(s):i.push(new Error(`unable to fetch raw block for CID ${e} from gateway ${o.url}`)),t.signal?.aborted===!0){this.log.trace("request aborted while fetching raw block for CID %c from gateway %s",e,o.url);break}}}throw new AggregateError(i,`unable to fetch raw block for CID ${e} from any gateway`)}};var V0=["https://trustless-gateway.link","https://cloudflare-ipfs.com","https://4everland.io"];function Qo(r={}){return e=>new Aa(e,r)}var qb=Symbol.for("nodejs.util.inspect.custom"),M0=Object.values(Rn).map(r=>r.decoder).reduce((r,e)=>r.or(e),Rn.identity.decoder),H0=114,Qu=36,eh=37,es=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()})`}[yu]=!0;toString(){return this.string==null&&(this.string=ke.encode(this.multihash.bytes).slice(1)),this.string}toCID(){return V.createV1(H0,this.multihash)}toBytes(){return this.multihash.bytes}toJSON(){return this.toString()}equals(e){if(e==null)return!1;if(e instanceof Uint8Array)return de(this.multihash.bytes,e);if(typeof e=="string")return Yt(e).equals(this);if(e?.multihash?.bytes!=null)return de(this.multihash.bytes,e.multihash.bytes);throw new Error("not valid Id")}[qb](){return`PeerId(${this.toString()})`}},Wi=class extends es{type="RSA";publicKey;constructor(e){super({...e,type:"RSA"}),this.publicKey=e.publicKey}},Yi=class extends es{type="Ed25519";publicKey;constructor(e){super({...e,type:"Ed25519"}),this.publicKey=e.multihash.digest}},Xi=class extends es{type="secp256k1";publicKey;constructor(e){super({...e,type:"secp256k1"}),this.publicKey=e.multihash.digest}};function Yt(r,e){if(e=e??M0,r.charAt(0)==="1"||r.charAt(0)==="Q"){let t=bt(ke.decode(`z${r}`));return r.startsWith("12D")?new Yi({multihash:t}):r.startsWith("16U")?new Xi({multihash:t}):new Wi({multihash:t})}return ts(M0.decode(r))}function ts(r){try{let e=bt(r);if(e.code===et.code){if(e.digest.length===Qu)return new Yi({multihash:e});if(e.digest.length===eh)return new Xi({multihash:e})}if(e.code===ne.code)return new Wi({multihash:e})}catch{return jb(V.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!==H0)throw new Error("Supplied PeerID CID is invalid");let e=r.multihash;if(e.code===ne.code)return new Wi({multihash:r.multihash});if(e.code===et.code){if(e.digest.length===Qu)return new Yi({multihash:r.multihash});if(e.digest.length===eh)return new Xi({multihash:r.multihash})}throw new Error("Supplied PeerID CID is invalid")}async function $0(r,e){return r.length===Qu?new Yi({multihash:dr(et.code,r),privateKey:e}):r.length===eh?new Xi({multihash:dr(et.code,r),privateKey:e}):new Wi({multihash:await ne.digest(r),publicKey:r,privateKey:e})}var Ia=class{index=0;input="";new(e){return this.index=0,this.input=e,this}readAtomically(e){let t=this.index,n=e();return n===void 0&&(this.index=t),n}parseWith(e){let t=e();if(this.index===this.input.length)return t}peekChar(){if(!(this.index>=this.input.length))return this.input[this.index]}readChar(){if(!(this.index>=this.input.length))return this.input[this.index++]}readGivenChar(e){return this.readAtomically(()=>{let t=this.readChar();if(t===e)return t})}readSeparator(e,t,n){return this.readAtomically(()=>{if(!(t>0&&this.readGivenChar(e)===void 0))return n()})}readNumber(e,t,n,i){return this.readAtomically(()=>{let o=0,s=0,a=this.peekChar();if(a===void 0)return;let c=a==="0",u=2**(8*i)-1;for(;;){let l=this.readAtomically(()=>{let h=this.readChar();if(h===void 0)return;let p=Number.parseInt(h,e);if(!Number.isNaN(p))return p});if(l===void 0)break;if(o*=e,o+=l,o>u||(s+=1,t!==void 0&&s>t))return}if(s!==0)return!n&&c&&s>1?void 0:o})}readIPv4Addr(){return this.readAtomically(()=>{let e=new Uint8Array(4);for(let t=0;t<e.length;t++){let n=this.readSeparator(".",t,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;e[t]=n}return e})}readIPv6Addr(){let e=t=>{for(let n=0;n<t.length/2;n++){let i=n*2;if(n<t.length-3){let s=this.readSeparator(":",n,()=>this.readIPv4Addr());if(s!==void 0)return t[i]=s[0],t[i+1]=s[1],t[i+2]=s[2],t[i+3]=s[3],[i+4,!0]}let o=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(o===void 0)return[i,!1];t[i]=o>>8,t[i+1]=o&255}return[t.length,!1]};return this.readAtomically(()=>{let t=new Uint8Array(16),[n,i]=e(t);if(n===16)return t;if(i||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let o=new Uint8Array(14),s=16-(n+2),[a]=e(o.subarray(0,s));return t.set(o.subarray(0,a),16-a),t})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var z0=45,Gb=15,Zi=new Ia;function th(r){if(!(r.length>Gb))return Zi.new(r).parseWith(()=>Zi.readIPv4Addr())}function rh(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>z0))return Zi.new(r).parseWith(()=>Zi.readIPv6Addr())}function Sa(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>z0))return Zi.new(r).parseWith(()=>Zi.readIPAddr())}var L5=parseInt("0xFFFF",16),D5=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function j0(r){return!!th(r)}function G0(r){return!!rh(r)}function _a(r){return!!Sa(r)}var W0=j0,Jb=G0,nh=function(r){let e=0;if(r=r.toString().trim(),W0(r)){let t=new Uint8Array(e+4);return r.split(/\./g).forEach(n=>{t[e++]=parseInt(n,10)&255}),t}if(Jb(r)){let t=r.split(":",8),n;for(n=0;n<t.length;n++){let o=W0(t[n]),s;o&&(s=nh(t[n]),t[n]=Q(s.slice(0,2),"base16")),s!=null&&++n<8&&t.splice(n,0,Q(s.slice(2,4),"base16"))}if(t[0]==="")for(;t.length<8;)t.unshift("0");else if(t[t.length-1]==="")for(;t.length<8;)t.push("0");else if(t.length<8){for(n=0;n<t.length&&t[n]!=="";n++);let o=[n,1];for(n=9-t.length;n>0;n--)o.push("0");t.splice.apply(t,o)}let i=new Uint8Array(e+16);for(n=0;n<t.length;n++){let o=parseInt(t[n],16);i[e++]=o>>8&255,i[e++]=o&255}return i}throw new Error("invalid ip address")},Y0=function(r,e=0,t){e=~~e,t=t??r.length-e;let n=new DataView(r.buffer);if(t===4){let i=[];for(let o=0;o<t;o++)i.push(r[e+o]);return i.join(".")}if(t===16){let i=[];for(let o=0;o<t;o+=2)i.push(n.getUint16(e+o).toString(16));return i.join(":").replace(/(^|:)0(:0)*:0(:|$)/,"$1::$3").replace(/:{3,4}/,"::")}return""};var Ji={},ih={},eE=[[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"]];eE.forEach(r=>{let e=tE(...r);ih[e.code]=e,Ji[e.name]=e});function tE(r,e,t,n,i){return{code:r,size:e,name:t,resolvable:!!n,path:!!i}}function ge(r){if(typeof r=="number"){if(ih[r]!=null)return ih[r];throw new Error(`no protocol with code: ${r}`)}else if(typeof r=="string"){if(Ji[r]!=null)return Ji[r];throw new Error(`no protocol with name: ${r}`)}throw new Error(`invalid protocol id type: ${typeof r}`)}var wS=ge("ip4"),xS=ge("ip6"),bS=ge("ipcidr");function sh(r,e){switch(ge(r).code){case 4:case 41:return nE(e);case 42:return J0(e);case 6:case 273:case 33:case 132:return ep(e).toString();case 53:case 54:case 55:case 56:case 400:case 449:case 777:return J0(e);case 421:return aE(e);case 444:return Q0(e);case 445:return Q0(e);case 466:return sE(e);default:return Q(e,"base16")}}function ah(r,e){switch(ge(r).code){case 4:return X0(e);case 41:return X0(e);case 42:return Z0(e);case 6:case 273:case 33:case 132:return ch(parseInt(e,10));case 53:case 54:case 55:case 56:case 400:case 449:case 777:return Z0(e);case 421:return iE(e);case 444:return cE(e);case 445:return lE(e);case 466:return oE(e);default:return Y(e,"base16")}}var oh=Object.values(Rn).map(r=>r.decoder),rE=function(){let r=oh[0].or(oh[1]);return oh.slice(2).forEach(e=>r=r.or(e)),r}();function X0(r){if(!_a(r))throw new Error("invalid ip address");return nh(r)}function nE(r){let e=Y0(r,0,r.length);if(e==null)throw new Error("ipBuff is required");if(!_a(e))throw new Error("invalid ip address");return e}function ch(r){let e=new ArrayBuffer(2);return new DataView(e).setUint16(0,r),new Uint8Array(e)}function ep(r){return new DataView(r.buffer).getUint16(r.byteOffset)}function Z0(r){let e=Y(r),t=Uint8Array.from(qi(e.length));return Ee([t,e],t.length+e.length)}function J0(r){let e=ci(r);if(r=r.slice(dt(e)),r.length!==e)throw new Error("inconsistent lengths");return Q(r)}function iE(r){let e;r[0]==="Q"||r[0]==="1"?e=bt(ke.decode(`z${r}`)).bytes:e=V.parse(r).multihash.bytes;let t=Uint8Array.from(qi(e.length));return Ee([t,e],t.length+e.length)}function oE(r){let e=rE.decode(r),t=Uint8Array.from(qi(e.length));return Ee([t,e],t.length+e.length)}function sE(r){let e=ci(r),t=r.slice(dt(e));if(t.length!==e)throw new Error("inconsistent lengths");return"u"+Q(t,"base64url")}function aE(r){let e=ci(r),t=r.slice(dt(e));if(t.length!==e)throw new Error("inconsistent lengths");return Q(t,"base58btc")}function cE(r){let e=r.split(":");if(e.length!==2)throw new Error(`failed to parse onion addr: ["'${e.join('", "')}'"]' does not contain a port number`);if(e[0].length!==16)throw new Error(`failed to parse onion addr: ${e[0]} not a Tor onion address.`);let t=qe.decode("b"+e[0]),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let i=ch(n);return Ee([t,i],t.length+i.length)}function lE(r){let e=r.split(":");if(e.length!==2)throw new Error(`failed to parse onion addr: ["'${e.join('", "')}'"]' does not contain a port number`);if(e[0].length!==56)throw new Error(`failed to parse onion addr: ${e[0]} not a Tor onion3 address.`);let t=qe.decode(`b${e[0]}`),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let i=ch(n);return Ee([t,i],t.length+i.length)}function Q0(r){let e=r.slice(0,r.length-2),t=r.slice(r.length-2),n=Q(e,"base32"),i=ep(t);return`${n}:${i}`}function tp(r){r=lh(r);let e=[],t=[],n=null,i=r.split("/").slice(1);if(i.length===1&&i[0]==="")return{bytes:new Uint8Array,string:"/",tuples:[],stringTuples:[],path:null};for(let o=0;o<i.length;o++){let s=i[o],a=ge(s);if(a.size===0){e.push([a.code]),t.push([a.code]);continue}if(o++,o>=i.length)throw np("invalid address: "+r);if(a.path===!0){n=lh(i.slice(o).join("/")),e.push([a.code,ah(a.code,n)]),t.push([a.code,n]);break}let c=ah(a.code,i[o]);e.push([a.code,c]),t.push([a.code,sh(a.code,c)])}return{string:rp(t),bytes:hh(e),tuples:e,stringTuples:t,path:n}}function uh(r){let e=[],t=[],n=null,i=0;for(;i<r.length;){let o=ci(r,i),s=dt(o),a=ge(o),c=uE(a,r.slice(i+s));if(c===0){e.push([o]),t.push([o]),i+=s;continue}let u=r.slice(i+s,i+s+c);if(i+=c+s,i>r.length)throw np("Invalid address Uint8Array: "+Q(r,"base16"));e.push([o,u]);let l=sh(o,u);if(t.push([o,l]),a.path===!0){n=l;break}}return{bytes:Uint8Array.from(r),string:rp(t),tuples:e,stringTuples:t,path:n}}function rp(r){let e=[];return r.map(t=>{let n=ge(t[0]);return e.push(n.name),t.length>1&&t[1]!=null&&e.push(t[1]),null}),lh(e.join("/"))}function hh(r){return Ee(r.map(e=>{let t=ge(e[0]),n=Uint8Array.from(qi(t.code));return e.length>1&&e[1]!=null&&(n=Ee([n,e[1]])),n}))}function uE(r,e){if(r.size>0)return r.size/8;if(r.size===0)return 0;{let t=ci(e instanceof Uint8Array?e:Uint8Array.from(e));return t+dt(t)}}function lh(r){return"/"+r.trim().split("/").filter(e=>e).join("/")}function np(r){return new Error("Error parsing address: "+r)}var hE=Symbol.for("nodejs.util.inspect.custom"),dh=Symbol.for("@multiformats/js-multiaddr/multiaddr"),dE=[ge("dns").code,ge("dns4").code,ge("dns6").code,ge("dnsaddr").code],ka=class r{bytes;#e;#t;#r;#s;[dh]=!0;constructor(e){e==null&&(e="");let t;if(e instanceof Uint8Array)t=uh(e);else if(typeof e=="string"){if(e.length>0&&e.charAt(0)!=="/")throw new Error(`multiaddr "${e}" must start with a "/"`);t=tp(e)}else if(op(e))t=uh(e.bytes);else throw new Error("addr must be a string, Buffer, or another Multiaddr");this.bytes=t.bytes,this.#e=t.string,this.#t=t.tuples,this.#r=t.stringTuples,this.#s=t.path}toString(){return this.#e}toJSON(){return this.toString()}toOptions(){let e,t,n,i,o="",s=ge("tcp"),a=ge("udp"),c=ge("ip4"),u=ge("ip6"),l=ge("dns6"),h=ge("ip6zone");for(let[d,f]of this.stringTuples())d===h.code&&(o=`%${f??""}`),dE.includes(d)&&(t=s.name,i=443,n=`${f??""}${o}`,e=d===l.code?6:4),(d===s.code||d===a.code)&&(t=ge(d).name,i=parseInt(f??"")),(d===c.code||d===u.code)&&(t=ge(d).name,n=`${f??""}${o}`,e=d===u.code?6:4);if(e==null||t==null||n==null||i==null)throw new Error('multiaddr must have a valid format: "/{ip4, ip6, dns4, dns6, dnsaddr}/{address}/{tcp, udp}/{port}".');return{family:e,host:n,transport:t,port:i}}protos(){return this.#t.map(([e])=>Object.assign({},ge(e)))}protoCodes(){return this.#t.map(([e])=>e)}protoNames(){return this.#t.map(([e])=>ge(e).name)}tuples(){return this.#t}stringTuples(){return this.#r}encapsulate(e){return e=new r(e),new r(this.toString()+e.toString())}decapsulate(e){let t=e.toString(),n=this.toString(),i=n.lastIndexOf(t);if(i<0)throw new Error(`Address ${this.toString()} does not contain subaddress: ${e.toString()}`);return new r(n.slice(0,i))}decapsulateCode(e){let t=this.tuples();for(let n=t.length-1;n>=0;n--)if(t[n][0]===e)return new r(hh(t.slice(0,n)));return this}getPeerId(){try{let e=[];this.stringTuples().forEach(([n,i])=>{n===Ji.p2p.code&&e.push([n,i]),n===Ji["p2p-circuit"].code&&(e=[])});let t=e.pop();if(t?.[1]!=null){let n=t[1];return n[0]==="Q"||n[0]==="1"?Q(ke.decode(`z${n}`),"base58btc"):Q(V.parse(n).multihash.bytes,"base58btc")}return null}catch{return null}}getPath(){return this.#s}equals(e){return de(this.bytes,e.bytes)}async resolve(e){let t=this.protos().find(o=>o.resolvable);if(t==null)return[this];let n=ip.get(t.name);if(n==null)throw new F(`no available resolver for ${t.name}`,"ERR_NO_AVAILABLE_RESOLVER");return(await n(this,e)).map(o=>new r(o))}nodeAddress(){let e=this.toOptions();if(e.transport!=="tcp"&&e.transport!=="udp")throw new Error(`multiaddr must have a valid format - no protocol with name: "${e.transport}". Must have a valid transport protocol: "{tcp, udp}"`);return{family:e.family,address:e.host,port:e.port}}isThinWaistAddress(e){let t=(e??this).protos();return!(t.length!==2||t[0].code!==4&&t[0].code!==41||t[1].code!==6&&t[1].code!==273)}[hE](){return`Multiaddr(${this.#e})`}};var ip=new Map;function op(r){return!!r?.[dh]}function fh(r){return new ka(r)}async function*Ra(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 Ch={};Ae(Ch,{Ed25519PrivateKey:()=>yi,Ed25519PublicKey:()=>is,generateKeyPair:()=>B3,generateKeyPairFromSeed:()=>Cp,unmarshalEd25519PrivateKey:()=>E3,unmarshalEd25519PublicKey:()=>v3});function Mt(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}function Qi(r){if(!Number.isSafeInteger(r)||r<0)throw new Error(`Wrong positive integer: ${r}`)}function fE(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}function ph(r,...e){if(!fE(r))throw new Error("Expected Uint8Array");if(e.length>0&&!e.includes(r.length))throw new Error(`Expected Uint8Array of length ${e}, not of length=${r.length}`)}function Ta(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");Qi(r.outputLen),Qi(r.blockLen)}function eo(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 sp(r,e){ph(r);let t=e.outputLen;if(r.length<t)throw new Error(`digestInto() expects output buffer of length at least ${t}`)}var Ca=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function ap(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}var ro=r=>new DataView(r.buffer,r.byteOffset,r.byteLength),Xt=(r,e)=>r<<32-e|r>>>e,pE=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;if(!pE)throw new Error("Non little-endian hardware is not supported");var mE=async()=>{};async function cp(r,e,t){let n=Date.now();for(let i=0;i<r;i++){t(i);let o=Date.now()-n;o>=0&&o<e||(await mE(),n+=o)}}function mh(r){if(typeof r!="string")throw new Error(`utf8ToBytes expected string, got ${typeof r}`);return new Uint8Array(new TextEncoder().encode(r))}function Tn(r){if(typeof r=="string"&&(r=mh(r)),!ap(r))throw new Error(`expected Uint8Array, got ${typeof r}`);return r}function Na(...r){let e=0;for(let n=0;n<r.length;n++){let i=r[n];if(!ap(i))throw new Error("Uint8Array expected");e+=i.length}let t=new Uint8Array(e);for(let n=0,i=0;n<r.length;n++){let o=r[n];t.set(o,i),i+=o.length}return t}var to=class{clone(){return this._cloneInto()}},yE={}.toString;function lp(r,e){if(e!==void 0&&yE.call(e)!=="[object Object]")throw new Error("Options should be object or undefined");return Object.assign(r,e)}function Ua(r){let e=n=>r().update(Tn(n)).digest(),t=r();return e.outputLen=t.outputLen,e.blockLen=t.blockLen,e.create=()=>r(),e}function no(r=32){if(Ca&&typeof Ca.getRandomValues=="function")return Ca.getRandomValues(new Uint8Array(r));throw new Error("crypto.getRandomValues must be defined")}function gE(r,e,t,n){if(typeof r.setBigUint64=="function")return r.setBigUint64(e,t,n);let i=BigInt(32),o=BigInt(4294967295),s=Number(t>>i&o),a=Number(t&o),c=n?4:0,u=n?0:4;r.setUint32(e+c,s,n),r.setUint32(e+u,a,n)}var io=class extends to{constructor(e,t,n,i){super(),this.blockLen=e,this.outputLen=t,this.padOffset=n,this.isLE=i,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(e),this.view=ro(this.buffer)}update(e){eo(this);let{view:t,buffer:n,blockLen:i}=this;e=Tn(e);let o=e.length;for(let s=0;s<o;){let a=Math.min(i-this.pos,o-s);if(a===i){let c=ro(e);for(;i<=o-s;s+=i)this.process(c,s);continue}n.set(e.subarray(s,s+a),this.pos),this.pos+=a,s+=a,this.pos===i&&(this.process(t,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){eo(this),sp(e,this),this.finished=!0;let{buffer:t,view:n,blockLen:i,isLE:o}=this,{pos:s}=this;t[s++]=128,this.buffer.subarray(s).fill(0),this.padOffset>i-s&&(this.process(n,0),s=0);for(let h=s;h<i;h++)t[h]=0;gE(n,i-8,BigInt(this.length*8),o),this.process(n,0);let a=ro(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 h=0;h<u;h++)a.setUint32(4*h,l[h],o)}digest(){let{buffer:e,outputLen:t}=this;this.digestInto(e);let n=e.slice(0,t);return this.destroy(),n}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());let{blockLen:t,buffer:n,length:i,finished:o,destroyed:s,pos:a}=this;return e.length=i,e.pos=a,e.finished=o,e.destroyed=s,i%t&&e.buffer.set(n),e}};var La=BigInt(4294967295),yh=BigInt(32);function up(r,e=!1){return e?{h:Number(r&La),l:Number(r>>yh&La)}:{h:Number(r>>yh&La)|0,l:Number(r&La)|0}}function wE(r,e=!1){let t=new Uint32Array(r.length),n=new Uint32Array(r.length);for(let i=0;i<r.length;i++){let{h:o,l:s}=up(r[i],e);[t[i],n[i]]=[o,s]}return[t,n]}var xE=(r,e)=>BigInt(r>>>0)<<yh|BigInt(e>>>0),bE=(r,e,t)=>r>>>t,EE=(r,e,t)=>r<<32-t|e>>>t,vE=(r,e,t)=>r>>>t|e<<32-t,BE=(r,e,t)=>r<<32-t|e>>>t,AE=(r,e,t)=>r<<64-t|e>>>t-32,IE=(r,e,t)=>r>>>t-32|e<<64-t,SE=(r,e)=>e,_E=(r,e)=>r,kE=(r,e,t)=>r<<t|e>>>32-t,RE=(r,e,t)=>e<<t|r>>>32-t,TE=(r,e,t)=>e<<t-32|r>>>64-t,CE=(r,e,t)=>r<<t-32|e>>>64-t;function NE(r,e,t,n){let i=(e>>>0)+(n>>>0);return{h:r+t+(i/2**32|0)|0,l:i|0}}var UE=(r,e,t)=>(r>>>0)+(e>>>0)+(t>>>0),LE=(r,e,t,n)=>e+t+n+(r/2**32|0)|0,DE=(r,e,t,n)=>(r>>>0)+(e>>>0)+(t>>>0)+(n>>>0),PE=(r,e,t,n,i)=>e+t+n+i+(r/2**32|0)|0,OE=(r,e,t,n,i)=>(r>>>0)+(e>>>0)+(t>>>0)+(n>>>0)+(i>>>0),FE=(r,e,t,n,i,o)=>e+t+n+i+o+(r/2**32|0)|0;var VE={fromBig:up,split:wE,toBig:xE,shrSH:bE,shrSL:EE,rotrSH:vE,rotrSL:BE,rotrBH:AE,rotrBL:IE,rotr32H:SE,rotr32L:_E,rotlSH:kE,rotlSL:RE,rotlBH:TE,rotlBL:CE,add:NE,add3L:UE,add3H:LE,add4L:DE,add4H:PE,add5H:FE,add5L:OE},J=VE;var[ME,HE]=J.split(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(r=>BigInt(r))),Cn=new Uint32Array(80),Nn=new Uint32Array(80),gh=class extends io{constructor(){super(128,64,16,!1),this.Ah=1779033703,this.Al=-205731576,this.Bh=-1150833019,this.Bl=-2067093701,this.Ch=1013904242,this.Cl=-23791573,this.Dh=-1521486534,this.Dl=1595750129,this.Eh=1359893119,this.El=-1377402159,this.Fh=-1694144372,this.Fl=725511199,this.Gh=528734635,this.Gl=-79577749,this.Hh=1541459225,this.Hl=327033209}get(){let{Ah:e,Al:t,Bh:n,Bl:i,Ch:o,Cl:s,Dh:a,Dl:c,Eh:u,El:l,Fh:h,Fl:p,Gh:d,Gl:f,Hh:m,Hl:y}=this;return[e,t,n,i,o,s,a,c,u,l,h,p,d,f,m,y]}set(e,t,n,i,o,s,a,c,u,l,h,p,d,f,m,y){this.Ah=e|0,this.Al=t|0,this.Bh=n|0,this.Bl=i|0,this.Ch=o|0,this.Cl=s|0,this.Dh=a|0,this.Dl=c|0,this.Eh=u|0,this.El=l|0,this.Fh=h|0,this.Fl=p|0,this.Gh=d|0,this.Gl=f|0,this.Hh=m|0,this.Hl=y|0}process(e,t){for(let b=0;b<16;b++,t+=4)Cn[b]=e.getUint32(t),Nn[b]=e.getUint32(t+=4);for(let b=16;b<80;b++){let A=Cn[b-15]|0,I=Nn[b-15]|0,B=J.rotrSH(A,I,1)^J.rotrSH(A,I,8)^J.shrSH(A,I,7),v=J.rotrSL(A,I,1)^J.rotrSL(A,I,8)^J.shrSL(A,I,7),E=Cn[b-2]|0,R=Nn[b-2]|0,N=J.rotrSH(E,R,19)^J.rotrBH(E,R,61)^J.shrSH(E,R,6),C=J.rotrSL(E,R,19)^J.rotrBL(E,R,61)^J.shrSL(E,R,6),H=J.add4L(v,C,Nn[b-7],Nn[b-16]),D=J.add4H(H,B,N,Cn[b-7],Cn[b-16]);Cn[b]=D|0,Nn[b]=H|0}let{Ah:n,Al:i,Bh:o,Bl:s,Ch:a,Cl:c,Dh:u,Dl:l,Eh:h,El:p,Fh:d,Fl:f,Gh:m,Gl:y,Hh:g,Hl:x}=this;for(let b=0;b<80;b++){let A=J.rotrSH(h,p,14)^J.rotrSH(h,p,18)^J.rotrBH(h,p,41),I=J.rotrSL(h,p,14)^J.rotrSL(h,p,18)^J.rotrBL(h,p,41),B=h&d^~h&m,v=p&f^~p&y,E=J.add5L(x,I,v,HE[b],Nn[b]),R=J.add5H(E,g,A,B,ME[b],Cn[b]),N=E|0,C=J.rotrSH(n,i,28)^J.rotrBH(n,i,34)^J.rotrBH(n,i,39),H=J.rotrSL(n,i,28)^J.rotrBL(n,i,34)^J.rotrBL(n,i,39),D=n&o^n&a^o&a,ie=i&s^i&c^s&c;g=m|0,x=y|0,m=d|0,y=f|0,d=h|0,f=p|0,{h,l:p}=J.add(u|0,l|0,R|0,N|0),u=a|0,l=c|0,a=o|0,c=s|0,o=n|0,s=i|0;let _=J.add3L(N,H,ie);n=J.add3H(_,R,C,D),i=_|0}({h:n,l:i}=J.add(this.Ah|0,this.Al|0,n|0,i|0)),{h:o,l:s}=J.add(this.Bh|0,this.Bl|0,o|0,s|0),{h:a,l:c}=J.add(this.Ch|0,this.Cl|0,a|0,c|0),{h:u,l}=J.add(this.Dh|0,this.Dl|0,u|0,l|0),{h,l:p}=J.add(this.Eh|0,this.El|0,h|0,p|0),{h:d,l:f}=J.add(this.Fh|0,this.Fl|0,d|0,f|0),{h:m,l:y}=J.add(this.Gh|0,this.Gl|0,m|0,y|0),{h:g,l:x}=J.add(this.Hh|0,this.Hl|0,g|0,x|0),this.set(n,i,o,s,a,c,u,l,h,p,d,f,m,y,g,x)}roundClean(){Cn.fill(0),Nn.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 oo=Ua(()=>new gh);var Pa={};Ae(Pa,{bitGet:()=>WE,bitLen:()=>GE,bitMask:()=>rs,bitSet:()=>YE,bytesToHex:()=>$r,bytesToNumberBE:()=>zr,bytesToNumberLE:()=>Un,concatBytes:()=>Kr,createHmacDrbg:()=>bh,ensureBytes:()=>Se,equalBytes:()=>qE,hexToBytes:()=>fi,hexToNumber:()=>xh,isBytes:()=>Zt,numberToBytesBE:()=>Ln,numberToBytesLE:()=>pi,numberToHexUnpadded:()=>pp,numberToVarBytesBE:()=>KE,utf8ToBytes:()=>jE,validateObject:()=>mr});var fp=BigInt(0),Da=BigInt(1),$E=BigInt(2);function Zt(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}var zE=Array.from({length:256},(r,e)=>e.toString(16).padStart(2,"0"));function $r(r){if(!Zt(r))throw new Error("Uint8Array expected");let e="";for(let t=0;t<r.length;t++)e+=zE[r[t]];return e}function pp(r){let e=r.toString(16);return e.length&1?`0${e}`:e}function xh(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return BigInt(r===""?"0":`0x${r}`)}var Hr={_0:48,_9:57,_A:65,_F:70,_a:97,_f:102};function hp(r){if(r>=Hr._0&&r<=Hr._9)return r-Hr._0;if(r>=Hr._A&&r<=Hr._F)return r-(Hr._A-10);if(r>=Hr._a&&r<=Hr._f)return r-(Hr._a-10)}function fi(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);let e=r.length,t=e/2;if(e%2)throw new Error("padded hex string expected, got unpadded hex of length "+e);let n=new Uint8Array(t);for(let i=0,o=0;i<t;i++,o+=2){let s=hp(r.charCodeAt(o)),a=hp(r.charCodeAt(o+1));if(s===void 0||a===void 0){let c=r[o]+r[o+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+o)}n[i]=s*16+a}return n}function zr(r){return xh($r(r))}function Un(r){if(!Zt(r))throw new Error("Uint8Array expected");return xh($r(Uint8Array.from(r).reverse()))}function Ln(r,e){return fi(r.toString(16).padStart(e*2,"0"))}function pi(r,e){return Ln(r,e).reverse()}function KE(r){return fi(pp(r))}function Se(r,e,t){let n;if(typeof e=="string")try{n=fi(e)}catch(o){throw new Error(`${r} must be valid hex string, got "${e}". Cause: ${o}`)}else if(Zt(e))n=Uint8Array.from(e);else throw new Error(`${r} must be hex string or Uint8Array`);let i=n.length;if(typeof t=="number"&&i!==t)throw new Error(`${r} expected ${t} bytes, got ${i}`);return n}function Kr(...r){let e=0;for(let i=0;i<r.length;i++){let o=r[i];if(!Zt(o))throw new Error("Uint8Array expected");e+=o.length}let t=new Uint8Array(e),n=0;for(let i=0;i<r.length;i++){let o=r[i];t.set(o,n),n+=o.length}return t}function qE(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 jE(r){if(typeof r!="string")throw new Error(`utf8ToBytes expected string, got ${typeof r}`);return new Uint8Array(new TextEncoder().encode(r))}function GE(r){let e;for(e=0;r>fp;r>>=Da,e+=1);return e}function WE(r,e){return r>>BigInt(e)&Da}var YE=(r,e,t)=>r|(t?Da:fp)<<BigInt(e),rs=r=>($E<<BigInt(r-1))-Da,wh=r=>new Uint8Array(r),dp=r=>Uint8Array.from(r);function bh(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=wh(r),i=wh(r),o=0,s=()=>{n.fill(1),i.fill(0),o=0},a=(...h)=>t(i,n,...h),c=(h=wh())=>{i=a(dp([0]),h),n=a(),h.length!==0&&(i=a(dp([1]),h),n=a())},u=()=>{if(o++>=1e3)throw new Error("drbg: tried 1000 values");let h=0,p=[];for(;h<e;){n=a();let d=n.slice();p.push(d),h+=n.length}return Kr(...p)};return(h,p)=>{s(),c(h);let d;for(;!(d=p(u()));)c();return s(),d}}var XE={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"||Zt(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 mr(r,e,t={}){let n=(i,o,s)=>{let a=XE[o];if(typeof a!="function")throw new Error(`Invalid validator "${o}", expected function`);let c=r[i];if(!(s&&c===void 0)&&!a(c,r))throw new Error(`Invalid param ${String(i)}=${c} (${typeof c}), expected ${o}`)};for(let[i,o]of Object.entries(e))n(i,o,!1);for(let[i,o]of Object.entries(t))n(i,o,!0);return r}var Oe=BigInt(0),we=BigInt(1),mi=BigInt(2),ZE=BigInt(3),Eh=BigInt(4),mp=BigInt(5),yp=BigInt(8),JE=BigInt(9),QE=BigInt(16);function ye(r,e){let t=r%e;return t>=Oe?t:e+t}function e3(r,e,t){if(t<=Oe||e<Oe)throw new Error("Expected power/modulo > 0");if(t===we)return Oe;let n=we;for(;e>Oe;)e&we&&(n=n*r%t),r=r*r%t,e>>=we;return n}function xe(r,e,t){let n=r;for(;e-- >Oe;)n*=n,n%=t;return n}function Oa(r,e){if(r===Oe||e<=Oe)throw new Error(`invert: expected positive integers, got n=${r} mod=${e}`);let t=ye(r,e),n=e,i=Oe,o=we,s=we,a=Oe;for(;t!==Oe;){let u=n/t,l=n%t,h=i-s*u,p=o-a*u;n=t,t=l,i=s,o=a,s=h,a=p}if(n!==we)throw new Error("invert: does not exist");return ye(i,e)}function t3(r){let e=(r-we)/mi,t,n,i;for(t=r-we,n=0;t%mi===Oe;t/=mi,n++);for(i=mi;i<r&&e3(i,e,r)!==r-we;i++);if(n===1){let s=(r+we)/Eh;return function(c,u){let l=c.pow(u,s);if(!c.eql(c.sqr(l),u))throw new Error("Cannot find square root");return l}}let o=(t+we)/mi;return function(a,c){if(a.pow(c,e)===a.neg(a.ONE))throw new Error("Cannot find square root");let u=n,l=a.pow(a.mul(a.ONE,i),t),h=a.pow(c,o),p=a.pow(c,t);for(;!a.eql(p,a.ONE);){if(a.eql(p,a.ZERO))return a.ZERO;let d=1;for(let m=a.sqr(p);d<u&&!a.eql(m,a.ONE);d++)m=a.sqr(m);let f=a.pow(l,we<<BigInt(u-d-1));l=a.sqr(f),h=a.mul(h,f),p=a.mul(p,l),u=d}return h}}function r3(r){if(r%Eh===ZE){let e=(r+we)/Eh;return function(n,i){let o=n.pow(i,e);if(!n.eql(n.sqr(o),i))throw new Error("Cannot find square root");return o}}if(r%yp===mp){let e=(r-mp)/yp;return function(n,i){let o=n.mul(i,mi),s=n.pow(o,e),a=n.mul(i,s),c=n.mul(n.mul(a,mi),s),u=n.mul(a,n.sub(c,n.ONE));if(!n.eql(n.sqr(u),i))throw new Error("Cannot find square root");return u}}return r%QE,t3(r)}var gp=(r,e)=>(ye(r,e)&we)===we,n3=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function vh(r){let e={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},t=n3.reduce((n,i)=>(n[i]="function",n),e);return mr(r,t)}function i3(r,e,t){if(t<Oe)throw new Error("Expected power > 0");if(t===Oe)return r.ONE;if(t===we)return e;let n=r.ONE,i=e;for(;t>Oe;)t&we&&(n=r.mul(n,i)),i=r.sqr(i),t>>=we;return n}function o3(r,e){let t=new Array(e.length),n=e.reduce((o,s,a)=>r.is0(s)?o:(t[a]=o,r.mul(o,s)),r.ONE),i=r.inv(n);return e.reduceRight((o,s,a)=>r.is0(s)?o:(t[a]=r.mul(o,t[a]),r.mul(o,s)),i),t}function Bh(r,e){let t=e!==void 0?e:r.toString(2).length,n=Math.ceil(t/8);return{nBitLength:t,nByteLength:n}}function Fa(r,e,t=!1,n={}){if(r<=Oe)throw new Error(`Expected Field ORDER > 0, got ${r}`);let{nBitLength:i,nByteLength:o}=Bh(r,e);if(o>2048)throw new Error("Field lengths over 2048 bytes are not supported");let s=r3(r),a=Object.freeze({ORDER:r,BITS:i,BYTES:o,MASK:rs(i),ZERO:Oe,ONE:we,create:c=>ye(c,r),isValid:c=>{if(typeof c!="bigint")throw new Error(`Invalid field element: expected bigint, got ${typeof c}`);return Oe<=c&&c<r},is0:c=>c===Oe,isOdd:c=>(c&we)===we,neg:c=>ye(-c,r),eql:(c,u)=>c===u,sqr:c=>ye(c*c,r),add:(c,u)=>ye(c+u,r),sub:(c,u)=>ye(c-u,r),mul:(c,u)=>ye(c*u,r),pow:(c,u)=>i3(a,c,u),div:(c,u)=>ye(c*Oa(u,r),r),sqrN:c=>c*c,addN:(c,u)=>c+u,subN:(c,u)=>c-u,mulN:(c,u)=>c*u,inv:c=>Oa(c,r),sqrt:n.sqrt||(c=>s(a,c)),invertBatch:c=>o3(a,c),cmov:(c,u,l)=>l?u:c,toBytes:c=>t?pi(c,o):Ln(c,o),fromBytes:c=>{if(c.length!==o)throw new Error(`Fp.fromBytes: expected ${o}, got ${c.length}`);return t?Un(c):zr(c)}});return Object.freeze(a)}function wp(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 xp(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 Ah(r){let e=xp(r);return e+Math.ceil(e/2)}function bp(r,e,t=!1){let n=r.length,i=xp(e),o=Ah(e);if(n<16||n<o||n>1024)throw new Error(`expected ${o}-1024 bytes of input, got ${n}`);let s=t?zr(r):Un(r),a=ye(s,e-we)+we;return t?pi(a,i):Ln(a,i)}var a3=BigInt(0),Ih=BigInt(1);function Va(r,e){let t=(i,o)=>{let s=o.negate();return i?s:o},n=i=>{let o=Math.ceil(e/i)+1,s=2**(i-1);return{windows:o,windowSize:s}};return{constTimeNegate:t,unsafeLadder(i,o){let s=r.ZERO,a=i;for(;o>a3;)o&Ih&&(s=s.add(a)),a=a.double(),o>>=Ih;return s},precomputeWindow(i,o){let{windows:s,windowSize:a}=n(o),c=[],u=i,l=u;for(let h=0;h<s;h++){l=u,c.push(l);for(let p=1;p<a;p++)l=l.add(u),c.push(l);u=l.double()}return c},wNAF(i,o,s){let{windows:a,windowSize:c}=n(i),u=r.ZERO,l=r.BASE,h=BigInt(2**i-1),p=2**i,d=BigInt(i);for(let f=0;f<a;f++){let m=f*c,y=Number(s&h);s>>=d,y>c&&(y-=p,s+=Ih);let g=m,x=m+Math.abs(y)-1,b=f%2!==0,A=y<0;y===0?l=l.add(t(b,o[g])):u=u.add(t(A,o[x]))}return{p:u,f:l}},wNAFCached(i,o,s,a){let c=i._WINDOW_SIZE||1,u=o.get(i);return u||(u=this.precomputeWindow(i,c),c!==1&&o.set(i,a(u))),this.wNAF(c,u,s)}}}function ns(r){return vh(r.Fp),mr(r,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...Bh(r.n,r.nBitLength),...r,p:r.Fp.ORDER})}var Jt=BigInt(0),At=BigInt(1),Ma=BigInt(2),c3=BigInt(8),l3={zip215:!0};function u3(r){let e=ns(r);return mr(r,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...e})}function Ha(r){let e=u3(r),{Fp:t,n,prehash:i,hash:o,randomBytes:s,nByteLength:a,h:c}=e,u=Ma<<BigInt(a*8)-At,l=t.create,h=e.uvRatio||((U,k)=>{try{return{isValid:!0,value:t.sqrt(U*t.inv(k))}}catch{return{isValid:!1,value:Jt}}}),p=e.adjustScalarBytes||(U=>U),d=e.domain||((U,k,z)=>{if(k.length||z)throw new Error("Contexts/pre-hash are not supported");return U}),f=U=>typeof U=="bigint"&&Jt<U,m=(U,k)=>f(U)&&f(k)&&U<k,y=U=>U===Jt||m(U,u);function g(U,k){if(m(U,k))return U;throw new Error(`Expected valid scalar < ${k}, got ${typeof U} ${U}`)}function x(U){return U===Jt?U:g(U,n)}let b=new Map;function A(U){if(!(U instanceof I))throw new Error("ExtendedPoint expected")}class I{constructor(k,z,G,Z){if(this.ex=k,this.ey=z,this.ez=G,this.et=Z,!y(k))throw new Error("x required");if(!y(z))throw new Error("y required");if(!y(G))throw new Error("z required");if(!y(Z))throw new Error("t required")}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(k){if(k instanceof I)throw new Error("extended point not allowed");let{x:z,y:G}=k||{};if(!y(z)||!y(G))throw new Error("invalid affine point");return new I(z,G,At,l(z*G))}static normalizeZ(k){let z=t.invertBatch(k.map(G=>G.ez));return k.map((G,Z)=>G.toAffine(z[Z])).map(I.fromAffine)}_setWindowSize(k){this._WINDOW_SIZE=k,b.delete(this)}assertValidity(){let{a:k,d:z}=e;if(this.is0())throw new Error("bad point: ZERO");let{ex:G,ey:Z,ez:te,et:oe}=this,pe=l(G*G),ce=l(Z*Z),ue=l(te*te),Ce=l(ue*ue),Be=l(pe*k),ze=l(ue*l(Be+ce)),Ke=l(Ce+l(z*l(pe*ce)));if(ze!==Ke)throw new Error("bad point: equation left != right (1)");let Pe=l(G*Z),Ze=l(te*oe);if(Pe!==Ze)throw new Error("bad point: equation left != right (2)")}equals(k){A(k);let{ex:z,ey:G,ez:Z}=this,{ex:te,ey:oe,ez:pe}=k,ce=l(z*pe),ue=l(te*Z),Ce=l(G*pe),Be=l(oe*Z);return ce===ue&&Ce===Be}is0(){return this.equals(I.ZERO)}negate(){return new I(l(-this.ex),this.ey,this.ez,l(-this.et))}double(){let{a:k}=e,{ex:z,ey:G,ez:Z}=this,te=l(z*z),oe=l(G*G),pe=l(Ma*l(Z*Z)),ce=l(k*te),ue=z+G,Ce=l(l(ue*ue)-te-oe),Be=ce+oe,ze=Be-pe,Ke=ce-oe,Pe=l(Ce*ze),Ze=l(Be*Ke),Or=l(Ce*Ke),ii=l(ze*Be);return new I(Pe,Ze,ii,Or)}add(k){A(k);let{a:z,d:G}=e,{ex:Z,ey:te,ez:oe,et:pe}=this,{ex:ce,ey:ue,ez:Ce,et:Be}=k;if(z===BigInt(-1)){let zf=l((te-Z)*(ue+ce)),Kf=l((te+Z)*(ue-ce)),nu=l(Kf-zf);if(nu===Jt)return this.double();let qf=l(oe*Ma*Be),jf=l(pe*Ma*Ce),Gf=jf+qf,Wf=Kf+zf,Yf=jf-qf,H2=l(Gf*nu),$2=l(Wf*Yf),z2=l(Gf*Yf),K2=l(nu*Wf);return new I(H2,$2,K2,z2)}let ze=l(Z*ce),Ke=l(te*ue),Pe=l(pe*G*Be),Ze=l(oe*Ce),Or=l((Z+te)*(ce+ue)-ze-Ke),ii=Ze-Pe,Ko=Ze+Pe,$f=l(Ke-z*ze),O2=l(Or*ii),F2=l(Ko*$f),V2=l(Or*$f),M2=l(ii*Ko);return new I(O2,F2,M2,V2)}subtract(k){return this.add(k.negate())}wNAF(k){return E.wNAFCached(this,b,k,I.normalizeZ)}multiply(k){let{p:z,f:G}=this.wNAF(g(k,n));return I.normalizeZ([z,G])[0]}multiplyUnsafe(k){let z=x(k);return z===Jt?v:this.equals(v)||z===At?this:this.equals(B)?this.wNAF(z).p:E.unsafeLadder(this,z)}isSmallOrder(){return this.multiplyUnsafe(c).is0()}isTorsionFree(){return E.unsafeLadder(this,n).is0()}toAffine(k){let{ex:z,ey:G,ez:Z}=this,te=this.is0();k==null&&(k=te?c3:t.inv(Z));let oe=l(z*k),pe=l(G*k),ce=l(Z*k);if(te)return{x:Jt,y:At};if(ce!==At)throw new Error("invZ was invalid");return{x:oe,y:pe}}clearCofactor(){let{h:k}=e;return k===At?this:this.multiplyUnsafe(k)}static fromHex(k,z=!1){let{d:G,a:Z}=e,te=t.BYTES;k=Se("pointHex",k,te);let oe=k.slice(),pe=k[te-1];oe[te-1]=pe&-129;let ce=Un(oe);ce===Jt||(z?g(ce,u):g(ce,t.ORDER));let ue=l(ce*ce),Ce=l(ue-At),Be=l(G*ue-Z),{isValid:ze,value:Ke}=h(Ce,Be);if(!ze)throw new Error("Point.fromHex: invalid y coordinate");let Pe=(Ke&At)===At,Ze=(pe&128)!==0;if(!z&&Ke===Jt&&Ze)throw new Error("Point.fromHex: x=0 and x_0=1");return Ze!==Pe&&(Ke=l(-Ke)),I.fromAffine({x:Ke,y:ce})}static fromPrivateKey(k){return C(k).point}toRawBytes(){let{x:k,y:z}=this.toAffine(),G=pi(z,t.BYTES);return G[G.length-1]|=k&At?128:0,G}toHex(){return $r(this.toRawBytes())}}I.BASE=new I(e.Gx,e.Gy,At,l(e.Gx*e.Gy)),I.ZERO=new I(Jt,At,At,Jt);let{BASE:B,ZERO:v}=I,E=Va(I,a*8);function R(U){return ye(U,n)}function N(U){return R(Un(U))}function C(U){let k=a;U=Se("private key",U,k);let z=Se("hashed private key",o(U),2*k),G=p(z.slice(0,k)),Z=z.slice(k,2*k),te=N(G),oe=B.multiply(te),pe=oe.toRawBytes();return{head:G,prefix:Z,scalar:te,point:oe,pointBytes:pe}}function H(U){return C(U).pointBytes}function D(U=new Uint8Array,...k){let z=Kr(...k);return N(o(d(z,Se("context",U),!!i)))}function ie(U,k,z={}){U=Se("message",U),i&&(U=i(U));let{prefix:G,scalar:Z,pointBytes:te}=C(k),oe=D(z.context,G,U),pe=B.multiply(oe).toRawBytes(),ce=D(z.context,pe,te,U),ue=R(oe+ce*Z);x(ue);let Ce=Kr(pe,pi(ue,t.BYTES));return Se("result",Ce,a*2)}let _=l3;function L(U,k,z,G=_){let{context:Z,zip215:te}=G,oe=t.BYTES;U=Se("signature",U,2*oe),k=Se("message",k),i&&(k=i(k));let pe=Un(U.slice(oe,2*oe)),ce,ue,Ce;try{ce=I.fromHex(z,te),ue=I.fromHex(U.slice(0,oe),te),Ce=B.multiplyUnsafe(pe)}catch{return!1}if(!te&&ce.isSmallOrder())return!1;let Be=D(Z,ue.toRawBytes(),ce.toRawBytes(),k);return ue.add(ce.multiplyUnsafe(Be)).subtract(Ce).clearCofactor().equals(I.ZERO)}return B._setWindowSize(8),{CURVE:e,getPublicKey:H,sign:ie,verify:L,ExtendedPoint:I,utils:{getExtendedPublicKey:C,randomPrivateKey:()=>s(t.BYTES),precompute(U=8,k=I.BASE){return k._setWindowSize(U),k.multiply(BigInt(3)),k}}}}var _h=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),Ep=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),x_=BigInt(0),h3=BigInt(1),Sh=BigInt(2),d3=BigInt(5),vp=BigInt(10),f3=BigInt(20),p3=BigInt(40),Bp=BigInt(80);function m3(r){let e=_h,n=r*r%e*r%e,i=xe(n,Sh,e)*n%e,o=xe(i,h3,e)*r%e,s=xe(o,d3,e)*o%e,a=xe(s,vp,e)*s%e,c=xe(a,f3,e)*a%e,u=xe(c,p3,e)*c%e,l=xe(u,Bp,e)*u%e,h=xe(l,Bp,e)*u%e,p=xe(h,vp,e)*s%e;return{pow_p_5_8:xe(p,Sh,e)*r%e,b2:n}}function y3(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}function g3(r,e){let t=_h,n=ye(e*e*e,t),i=ye(n*n*e,t),o=m3(r*i).pow_p_5_8,s=ye(r*n*o,t),a=ye(e*s*s,t),c=s,u=ye(s*Ep,t),l=a===r,h=a===ye(-r,t),p=a===ye(-r*Ep,t);return l&&(s=c),(h||p)&&(s=u),gp(s,t)&&(s=ye(-s,t)),{isValid:l||h,value:s}}var qr=Fa(_h,void 0,!0),kh={a:BigInt(-1),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:qr,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:BigInt(8),Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:oo,randomBytes:no,adjustScalarBytes:y3,uvRatio:g3},so=Ha(kh);function Ap(r,e,t){if(e.length>255)throw new Error("Context is too big");return Na(mh("SigEd25519 no Ed25519 collisions"),new Uint8Array([t?1:0,e.length]),e,r)}var b_=Ha({...kh,domain:Ap}),E_=Ha({...kh,domain:Ap,prehash:oo});var w3=(qr.ORDER+BigInt(3))/BigInt(8),v_=qr.pow(Sh,w3),B_=qr.sqrt(qr.neg(qr.ONE)),A_=(qr.ORDER-BigInt(5))/BigInt(8),I_=BigInt(486662);var S_=wp(qr,qr.neg(BigInt(486664)));var __=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),k_=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),R_=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),T_=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952");var C_=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");var ao=32,jr=64,$a=32;function Ip(){let r=so.utils.randomPrivateKey(),e=so.getPublicKey(r);return{privateKey:Rp(r,e),publicKey:e}}function Sp(r){if(r.length!==$a)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=so.getPublicKey(e);return{privateKey:Rp(e,t),publicKey:t}}function _p(r,e){let t=r.subarray(0,$a);return so.sign(e instanceof Uint8Array?e:e.subarray(),t)}function kp(r,e,t){return so.verify(e,t instanceof Uint8Array?t:t.subarray(),r)}function Rp(r,e){let t=new Uint8Array(jr);for(let n=0;n<$a;n++)t[n]=r[n],t[$a+n]=e[n];return t}var ot={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 Rh={alg:"A128GCM",ext:!0,k:"scm9jmO_4BJAgdwWGVulLg",key_ops:["encrypt","decrypt"],kty:"oct"};function Tp(r){let e=r?.algorithm??"AES-GCM",t=r?.keyLength??16,n=r?.nonceLength??12,i=r?.digest??"SHA-256",o=r?.saltLength??16,s=r?.iterations??32767,a=ot.get();t*=8;async function c(h,p){let d=a.getRandomValues(new Uint8Array(o)),f=a.getRandomValues(new Uint8Array(n)),m={name:e,iv:f};typeof p=="string"&&(p=Y(p));let y;if(p.length===0){y=await a.subtle.importKey("jwk",Rh,{name:"AES-GCM"},!0,["encrypt"]);try{let x={name:"PBKDF2",salt:d,iterations:s,hash:{name:i}},b=await a.subtle.importKey("raw",p,{name:"PBKDF2"},!1,["deriveKey"]);y=await a.subtle.deriveKey(x,b,{name:e,length:t},!0,["encrypt"])}catch{y=await a.subtle.importKey("jwk",Rh,{name:"AES-GCM"},!0,["encrypt"])}}else{let x={name:"PBKDF2",salt:d,iterations:s,hash:{name:i}},b=await a.subtle.importKey("raw",p,{name:"PBKDF2"},!1,["deriveKey"]);y=await a.subtle.deriveKey(x,b,{name:e,length:t},!0,["encrypt"])}let g=await a.subtle.encrypt(m,y,h);return Ee([d,m.iv,new Uint8Array(g)])}async function u(h,p){let d=h.subarray(0,o),f=h.subarray(o,o+n),m=h.subarray(o+n),y={name:e,iv:f};typeof p=="string"&&(p=Y(p));let g;if(p.length===0)try{let b={name:"PBKDF2",salt:d,iterations:s,hash:{name:i}},A=await a.subtle.importKey("raw",p,{name:"PBKDF2"},!1,["deriveKey"]);g=await a.subtle.deriveKey(b,A,{name:e,length:t},!0,["decrypt"])}catch{g=await a.subtle.importKey("jwk",Rh,{name:"AES-GCM"},!0,["decrypt"])}else{let b={name:"PBKDF2",salt:d,iterations:s,hash:{name:i}},A=await a.subtle.importKey("raw",p,{name:"PBKDF2"},!1,["deriveKey"]);g=await a.subtle.deriveKey(b,A,{name:e,length:t},!0,["decrypt"])}let x=await a.subtle.decrypt(y,g,m);return new Uint8Array(x)}return{encrypt:c,decrypt:u}}async function co(r,e){let n=await Tp().encrypt(r,e);return pr.encode(n)}var be;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.Secp256k1="Secp256k1"})(be||(be={}));var Th;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.Secp256k1=2]="Secp256k1"})(Th||(Th={}));(function(r){r.codec=()=>hi(Th)})(be||(be={}));var yr;(function(r){let e;r.codec=()=>(e==null&&(e=Ft((t,n,i={})=>{i.lengthDelimited!==!1&&n.fork(),t.Type!=null&&(n.uint32(8),be.codec().encode(t.Type,n)),t.Data!=null&&(n.uint32(18),n.bytes(t.Data)),i.lengthDelimited!==!1&&n.ldelim()},(t,n)=>{let i={},o=n==null?t.len:t.pos+n;for(;t.pos<o;){let s=t.uint32();switch(s>>>3){case 1:i.Type=be.codec().decode(t);break;case 2:i.Data=t.bytes();break;default:t.skipType(s&7);break}}return i})),e),r.encode=t=>Ot(t,r.codec()),r.decode=t=>Dt(t,r.codec())})(yr||(yr={}));var gr;(function(r){let e;r.codec=()=>(e==null&&(e=Ft((t,n,i={})=>{i.lengthDelimited!==!1&&n.fork(),t.Type!=null&&(n.uint32(8),be.codec().encode(t.Type,n)),t.Data!=null&&(n.uint32(18),n.bytes(t.Data)),i.lengthDelimited!==!1&&n.ldelim()},(t,n)=>{let i={},o=n==null?t.len:t.pos+n;for(;t.pos<o;){let s=t.uint32();switch(s>>>3){case 1:i.Type=be.codec().decode(t);break;case 2:i.Data=t.bytes();break;default:t.skipType(s&7);break}}return i})),e),r.encode=t=>Ot(t,r.codec()),r.decode=t=>Dt(t,r.codec())})(gr||(gr={}));var is=class{_key;constructor(e){this._key=lo(e,ao)}verify(e,t){return kp(this._key,t,e)}marshal(){return this._key}get bytes(){return yr.encode({Type:be.Ed25519,Data:this.marshal()}).subarray()}equals(e){return de(this.bytes,e.bytes)}hash(){let e=ne.digest(this.bytes);return Mt(e)?e.then(({bytes:t})=>t):e.bytes}},yi=class{_key;_publicKey;constructor(e,t){this._key=lo(e,jr),this._publicKey=lo(t,ao)}sign(e){return _p(this._key,e)}get public(){return new is(this._publicKey)}marshal(){return this._key}get bytes(){return gr.encode({Type:be.Ed25519,Data:this.marshal()}).subarray()}equals(e){return de(this.bytes,e.bytes)}async hash(){let e=ne.digest(this.bytes),t;return Mt(e)?{bytes:t}=await e:t=e.bytes,t}async id(){let e=et.digest(this.public.bytes);return ke.encode(e.bytes).substring(1)}async export(e,t="libp2p-key"){if(t==="libp2p-key")return co(this.bytes,e);throw new F(`export format '${t}' is not supported`,"ERR_INVALID_EXPORT_FORMAT")}};function E3(r){if(r.length>jr){r=lo(r,jr+ao);let n=r.subarray(0,jr),i=r.subarray(jr,r.length);return new yi(n,i)}r=lo(r,jr);let e=r.subarray(0,jr),t=r.subarray(ao);return new yi(e,t)}function v3(r){return r=lo(r,ao),new is(r)}async function B3(){let{privateKey:r,publicKey:e}=Ip();return new yi(r,e)}async function Cp(r){let{privateKey:e,publicKey:t}=Sp(r);return new yi(e,t)}function lo(r,e){if(r=Uint8Array.from(r??[]),r.length!==e)throw new F(`Key must be a Uint8Array of length ${e}, got ${r.length}`,"ERR_INVALID_KEY_TYPE");return r}var Hh={};Ae(Hh,{MAX_RSA_KEY_SIZE:()=>ys,RsaPrivateKey:()=>mo,RsaPublicKey:()=>ms,fromJwk:()=>X3,generateKeyPair:()=>Z3,unmarshalRsaPrivateKey:()=>Vh,unmarshalRsaPublicKey:()=>Y3});function gi(r){if(isNaN(r)||r<=0)throw new F("random bytes length must be a Number bigger than 0","ERR_INVALID_LENGTH");return no(r)}var Fn={};Ae(Fn,{exportToPem:()=>K3,importFromPem:()=>q3,jwkToPkcs1:()=>M3,jwkToPkix:()=>$3,pkcs1ToJwk:()=>V3,pkixToJwk:()=>H3});var Ka=class extends to{constructor(e,t){super(),this.finished=!1,this.destroyed=!1,Ta(e);let n=Tn(t);if(this.iHash=e.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let i=this.blockLen,o=new Uint8Array(i);o.set(n.length>i?e.create().update(n).digest():n);for(let s=0;s<o.length;s++)o[s]^=54;this.iHash.update(o),this.oHash=e.create();for(let s=0;s<o.length;s++)o[s]^=106;this.oHash.update(o),o.fill(0)}update(e){return eo(this),this.iHash.update(e),this}digestInto(e){eo(this),ph(e,this.outputLen),this.finished=!0,this.iHash.digestInto(e),this.oHash.update(e),this.oHash.digestInto(e),this.destroy()}digest(){let e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||(e=Object.create(Object.getPrototypeOf(this),{}));let{oHash:t,iHash:n,finished:i,destroyed:o,blockLen:s,outputLen:a}=this;return e=e,e.finished=i,e.destroyed=o,e.blockLen=s,e.outputLen=a,e.oHash=t._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},os=(r,e,t)=>new Ka(r,e).update(t).digest();os.create=(r,e)=>new Ka(r,e);function A3(r,e,t,n){Ta(r);let i=lp({dkLen:32,asyncTick:10},n),{c:o,dkLen:s,asyncTick:a}=i;if(Qi(o),Qi(s),Qi(a),o<1)throw new Error("PBKDF2: iterations (c) should be >= 1");let c=Tn(e),u=Tn(t),l=new Uint8Array(s),h=os.create(r,c),p=h._cloneInto().update(u);return{c:o,dkLen:s,asyncTick:a,DK:l,PRF:h,PRFSalt:p}}function I3(r,e,t,n,i){return r.destroy(),e.destroy(),n&&n.destroy(),i.fill(0),t}async function Nh(r,e,t,n){let{c:i,dkLen:o,asyncTick:s,DK:a,PRF:c,PRFSalt:u}=A3(r,e,t,n),l,h=new Uint8Array(4),p=ro(h),d=new Uint8Array(c.outputLen);for(let f=1,m=0;m<o;f++,m+=c.outputLen){let y=a.subarray(m,m+c.outputLen);p.setInt32(0,f,!1),(l=u._cloneInto(l)).update(h).digestInto(d),y.set(d.subarray(0,y.length)),await cp(i-1,s,()=>{c._cloneInto(l).update(d).digestInto(d);for(let g=0;g<y.length;g++)y[g]^=d[g]})}return I3(c,u,a,l,d)}var ae=re(Np());function wi(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 Dn(r,e,t=-1){let n=t,i=r,o=0,s=Math.pow(2,e);for(let a=1;a<8;a++){if(r<s){let c;if(n<0)c=new ArrayBuffer(a),o=a;else{if(n<a)return new ArrayBuffer(0);c=new ArrayBuffer(n),o=n}let u=new Uint8Array(c);for(let l=a-1;l>=0;l--){let h=Math.pow(2,l*e);u[o-l-1]=Math.floor(i/h),i-=u[o-l-1]*h}return c}s*=Math.pow(2,e)}return new ArrayBuffer(0)}function Ga(...r){let e=0,t=0;for(let o of r)e+=o.length;let n=new ArrayBuffer(e),i=new Uint8Array(n);for(let o of r)i.set(o,t),t+=o.length;return i}function Lh(){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=wi(t,8),i=new ArrayBuffer(this.valueHex.byteLength),o=new Uint8Array(i);for(let a=0;a<this.valueHex.byteLength;a++)o[a]=r[a];return o[0]&=127,wi(o,8)-n}function Up(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=Dn(s,8,n),c=new Uint8Array(a);return c[0]|=128,a}let i=Dn(e,8,n),o=new Uint8Array(i);if(o[0]&128){let s=i.slice(0),a=new Uint8Array(s);i=new ArrayBuffer(i.byteLength+1),o=new Uint8Array(i);for(let c=0;c<s.byteLength;c++)o[c+1]=a[c];o[0]=0}return i}t*=Math.pow(2,8)}return new ArrayBuffer(0)}function Lp(r,e){if(r.byteLength!==e.byteLength)return!1;let t=new Uint8Array(r),n=new Uint8Array(e);for(let i=0;i<t.length;i++)if(t[i]!==n[i])return!1;return!0}function ft(r,e){let t=r.toString(10);if(e<t.length)return"";let n=e-t.length,i=new Array(n);for(let s=0;s<n;s++)i[s]="0";return i.join("").concat(t)}var ok=Math.log(2);function Wa(){if(typeof BigInt>"u")throw new Error("BigInt is not defined. Your environment doesn't implement BigInt.")}function Dh(r){let e=0,t=0;for(let i=0;i<r.length;i++){let o=r[i];e+=o.byteLength}let n=new Uint8Array(e);for(let i=0;i<r.length;i++){let o=r[i];n.set(new Uint8Array(o),t),t+=o.byteLength}return n.buffer}function Zr(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 as=class{constructor(){this.items=[]}write(e){this.items.push(e)}final(){return Dh(this.items)}},ss=[new Uint8Array([1])],Dp="0123456789";var fo="",er=new ArrayBuffer(0),Ph=new Uint8Array(0),cs="EndOfContent",Op="OCTET STRING",Fp="BIT STRING";function Jr(r){var e;return e=class extends r{constructor(...n){var i;super(...n);let o=n[0]||{};this.isHexOnly=(i=o.isHexOnly)!==null&&i!==void 0?i:!1,this.valueHexView=o.valueHex?ae.BufferSourceConverter.toUint8Array(o.valueHex):Ph}get valueHex(){return this.valueHexView.slice().buffer}set valueHex(n){this.valueHexView=new Uint8Array(n)}fromBER(n,i,o){let s=n instanceof ArrayBuffer?new Uint8Array(n):n;if(!Zr(this,s,i,o))return-1;let a=i+o;return this.valueHexView=s.subarray(i,a),this.valueHexView.length?(this.blockLength=o,a):(this.warnings.push("Zero buffer length"),i)}toBER(n=!1){return this.isHexOnly?n?new ArrayBuffer(this.valueHexView.byteLength):this.valueHexView.byteLength===this.valueHexView.buffer.byteLength?this.valueHexView.buffer:this.valueHexView.slice().buffer:(this.error="Flag 'isHexOnly' is not set, abort",er)}toJSON(){return{...super.toJSON(),isHexOnly:this.isHexOnly,valueHex:ae.Convert.ToHex(this.valueHexView)}}},e.NAME="hexBlock",e}var Wr=class{constructor({blockLength:e=0,error:t=fo,warnings:n=[],valueBeforeDecode:i=Ph}={}){this.blockLength=e,this.error=t,this.warnings=n,this.valueBeforeDecodeView=ae.BufferSourceConverter.toUint8Array(i)}static blockName(){return this.NAME}get valueBeforeDecode(){return this.valueBeforeDecodeView.slice().buffer}set valueBeforeDecode(e){this.valueBeforeDecodeView=new Uint8Array(e)}toJSON(){return{blockName:this.constructor.NAME,blockLength:this.blockLength,error:this.error,warnings:this.warnings,valueBeforeDecode:ae.Convert.ToHex(this.valueBeforeDecodeView)}}};Wr.NAME="baseBlock";var tt=class extends Wr{fromBER(e,t,n){throw TypeError("User need to make a specific function in a class which extends 'ValueBlock'")}toBER(e,t){throw TypeError("User need to make a specific function in a class which extends 'ValueBlock'")}};tt.NAME="valueBlock";var Ya=class extends Jr(Wr){constructor({idBlock:e={}}={}){var t,n,i,o;super(),e?(this.isHexOnly=(t=e.isHexOnly)!==null&&t!==void 0?t:!1,this.valueHexView=e.valueHex?ae.BufferSourceConverter.toUint8Array(e.valueHex):Ph,this.tagClass=(n=e.tagClass)!==null&&n!==void 0?n:-1,this.tagNumber=(i=e.tagNumber)!==null&&i!==void 0?i:-1,this.isConstructed=(o=e.isConstructed)!==null&&o!==void 0?o:!1):(this.tagClass=-1,this.tagNumber=-1,this.isConstructed=!1)}toBER(e=!1){let t=0;switch(this.tagClass){case 1:t|=0;break;case 2:t|=64;break;case 3:t|=128;break;case 4:t|=192;break;default:return this.error="Unknown tag class",er}if(this.isConstructed&&(t|=32),this.tagNumber<31&&!this.isHexOnly){let i=new Uint8Array(1);if(!e){let o=this.tagNumber;o&=31,t|=o,i[0]=t}return i.buffer}if(!this.isHexOnly){let i=Dn(this.tagNumber,7),o=new Uint8Array(i),s=i.byteLength,a=new Uint8Array(s+1);if(a[0]=t|31,!e){for(let c=0;c<s-1;c++)a[c+1]=o[c]|128;a[s]=o[s-1]}return a.buffer}let n=new Uint8Array(this.valueHexView.byteLength+1);if(n[0]=t|31,!e){let i=this.valueHexView;for(let o=0;o<i.length-1;o++)n[o+1]=i[o]|128;n[this.valueHexView.byteLength]=i[i.length-1]}return n.buffer}fromBER(e,t,n){let i=ae.BufferSourceConverter.toUint8Array(e);if(!Zr(this,i,t,n))return-1;let o=i.subarray(t,t+n);if(o.length===0)return this.error="Zero buffer length",-1;switch(o[0]&192){case 0:this.tagClass=1;break;case 64:this.tagClass=2;break;case 128:this.tagClass=3;break;case 192:this.tagClass=4;break;default:return this.error="Unknown tag class",-1}this.isConstructed=(o[0]&32)===32,this.isHexOnly=!1;let a=o[0]&31;if(a!==31)this.tagNumber=a,this.blockLength=1;else{let c=1,u=this.valueHexView=new Uint8Array(255),l=255;for(;o[c]&128;){if(u[c-1]=o[c]&127,c++,c>=o.length)return this.error="End of input reached before message was fully decoded",-1;if(c===l){l+=255;let p=new Uint8Array(l);for(let d=0;d<u.length;d++)p[d]=u[d];u=this.valueHexView=new Uint8Array(l)}}this.blockLength=c+1,u[c-1]=o[c]&127;let h=new Uint8Array(c);for(let p=0;p<c;p++)h[p]=u[p];u=this.valueHexView=new Uint8Array(c),u.set(h),this.blockLength<=9?this.tagNumber=wi(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}}};Ya.NAME="identificationBlock";var Xa=class extends Wr{constructor({lenBlock:e={}}={}){var t,n,i;super(),this.isIndefiniteForm=(t=e.isIndefiniteForm)!==null&&t!==void 0?t:!1,this.longFormUsed=(n=e.longFormUsed)!==null&&n!==void 0?n:!1,this.length=(i=e.length)!==null&&i!==void 0?i:0}fromBER(e,t,n){let i=ae.BufferSourceConverter.toUint8Array(e);if(!Zr(this,i,t,n))return-1;let o=i.subarray(t,t+n);if(o.length===0)return this.error="Zero buffer length",-1;if(o[0]===255)return this.error="Length block 0xFF is reserved by standard",-1;if(this.isIndefiniteForm=o[0]===128,this.isIndefiniteForm)return this.blockLength=1,t+this.blockLength;if(this.longFormUsed=!!(o[0]&128),this.longFormUsed===!1)return this.length=o[0],this.blockLength=1,t+this.blockLength;let s=o[0]&127;if(s>8)return this.error="Too big integer",-1;if(s+1>o.length)return this.error="End of input reached before message was fully decoded",-1;let a=t+1,c=i.subarray(a,a+s);return c[s-1]===0&&this.warnings.push("Needlessly long encoded length"),this.length=wi(c,8),this.longFormUsed&&this.length<=127&&this.warnings.push("Unnecessary usage of long length form"),this.blockLength=s+1,t+this.blockLength}toBER(e=!1){let t,n;if(this.length>127&&(this.longFormUsed=!0),this.isIndefiniteForm)return t=new ArrayBuffer(1),e===!1&&(n=new Uint8Array(t),n[0]=128),t;if(this.longFormUsed){let i=Dn(this.length,8);if(i.byteLength>127)return this.error="Too big length",er;if(t=new ArrayBuffer(i.byteLength+1),e)return t;let o=new Uint8Array(i);n=new Uint8Array(t),n[0]=i.byteLength|128;for(let s=0;s<i.byteLength;s++)n[s+1]=o[s];return t}return t=new ArrayBuffer(1),e===!1&&(n=new Uint8Array(t),n[0]=this.length),t}toJSON(){return{...super.toJSON(),isIndefiniteForm:this.isIndefiniteForm,longFormUsed:this.longFormUsed,length:this.length}}};Xa.NAME="lengthBlock";var $={},je=class extends Wr{constructor({name:e=fo,optional:t=!1,primitiveSchema:n,...i}={},o){super(i),this.name=e,this.optional=t,n&&(this.primitiveSchema=n),this.idBlock=new Ya(i),this.lenBlock=new Xa(i),this.valueBlock=o?new o(i):new tt(i)}fromBER(e,t,n){let i=this.valueBlock.fromBER(e,t,this.lenBlock.isIndefiniteForm?n:this.lenBlock.length);return i===-1?(this.error=this.valueBlock.error,i):(this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.valueBlock.error.length||(this.blockLength+=this.valueBlock.blockLength),i)}toBER(e,t){let n=t||new as;t||Vp(this);let i=this.idBlock.toBER(e);if(n.write(i),this.lenBlock.isIndefiniteForm)n.write(new Uint8Array([128]).buffer),this.valueBlock.toBER(e,n),n.write(new ArrayBuffer(2));else{let o=this.valueBlock.toBER(e);this.lenBlock.length=o.byteLength;let s=this.lenBlock.toBER(e);n.write(s),n.write(o)}return t?er: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():ae.Convert.ToHex(this.toBER())}onAsciiEncoding(){return`${this.constructor.NAME} : ${ae.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 Lp(t,n)}};je.NAME="BaseBlock";function Vp(r){if(r instanceof $.Constructed)for(let e of r.valueBlock.value)Vp(e)&&(r.lenBlock.isIndefiniteForm=!0);return!!r.lenBlock.isIndefiniteForm}var Za=class extends je{constructor({value:e=fo,...t}={},n){super(t,n),e&&this.fromString(e)}getValue(){return this.valueBlock.value}setValue(e){this.valueBlock.value=e}fromBER(e,t,n){let i=this.valueBlock.fromBER(e,t,this.lenBlock.isIndefiniteForm?n:this.lenBlock.length);return i===-1?(this.error=this.valueBlock.error,i):(this.fromBuffer(this.valueBlock.valueHexView),this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.valueBlock.error.length||(this.blockLength+=this.valueBlock.blockLength),i)}onAsciiEncoding(){return`${this.constructor.NAME} : '${this.valueBlock.value}'`}};Za.NAME="BaseStringBlock";var Ja=class extends Jr(tt){constructor({isHexOnly:e=!0,...t}={}){super(t),this.isHexOnly=e}};Ja.NAME="PrimitiveValueBlock";var Mp,Qa=class extends je{constructor(e={}){super(e,Ja),this.idBlock.isConstructed=!1}};Mp=Qa;$.Primitive=Mp;Qa.NAME="PRIMITIVE";function L3(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 Nc(r,e=0,t=r.length){let n=e,i=new je({},tt),o=new Wr;if(!Zr(o,r,e,t))return i.error=o.error,{offset:-1,result:i};if(!r.subarray(e,e+t).length)return i.error="Zero buffer length",{offset:-1,result:i};let a=i.idBlock.fromBER(r,e,t);if(i.idBlock.warnings.length&&i.warnings.concat(i.idBlock.warnings),a===-1)return i.error=i.idBlock.error,{offset:-1,result:i};if(e=a,t-=i.idBlock.blockLength,a=i.lenBlock.fromBER(r,e,t),i.lenBlock.warnings.length&&i.warnings.concat(i.lenBlock.warnings),a===-1)return i.error=i.lenBlock.error,{offset:-1,result:i};if(e=a,t-=i.lenBlock.blockLength,!i.idBlock.isConstructed&&i.lenBlock.isIndefiniteForm)return i.error="Indefinite length form used for primitive encoding form",{offset:-1,result:i};let c=je;switch(i.idBlock.tagClass){case 1:if(i.idBlock.tagNumber>=37&&i.idBlock.isHexOnly===!1)return i.error="UNIVERSAL 37 and upper tags are reserved by ASN.1 standard",{offset:-1,result:i};switch(i.idBlock.tagNumber){case 0:if(i.idBlock.isConstructed&&i.lenBlock.length>0)return i.error="Type [UNIVERSAL 0] is reserved",{offset:-1,result:i};c=$.EndOfContent;break;case 1:c=$.Boolean;break;case 2:c=$.Integer;break;case 3:c=$.BitString;break;case 4:c=$.OctetString;break;case 5:c=$.Null;break;case 6:c=$.ObjectIdentifier;break;case 10:c=$.Enumerated;break;case 12:c=$.Utf8String;break;case 13:c=$.RelativeObjectIdentifier;break;case 14:c=$.TIME;break;case 15:return i.error="[UNIVERSAL 15] is reserved by ASN.1 standard",{offset:-1,result:i};case 16:c=$.Sequence;break;case 17:c=$.Set;break;case 18:c=$.NumericString;break;case 19:c=$.PrintableString;break;case 20:c=$.TeletexString;break;case 21:c=$.VideotexString;break;case 22:c=$.IA5String;break;case 23:c=$.UTCTime;break;case 24:c=$.GeneralizedTime;break;case 25:c=$.GraphicString;break;case 26:c=$.VisibleString;break;case 27:c=$.GeneralString;break;case 28:c=$.UniversalString;break;case 29:c=$.CharacterString;break;case 30:c=$.BmpString;break;case 31:c=$.DATE;break;case 32:c=$.TimeOfDay;break;case 33:c=$.DateTime;break;case 34:c=$.Duration;break;default:{let u=i.idBlock.isConstructed?new $.Constructed:new $.Primitive;u.idBlock=i.idBlock,u.lenBlock=i.lenBlock,u.warnings=i.warnings,i=u}}break;case 2:case 3:case 4:default:c=i.idBlock.isConstructed?$.Constructed:$.Primitive}return i=L3(i,c),a=i.fromBER(r,e,i.lenBlock.isIndefiniteForm?t:i.lenBlock.length),i.valueBeforeDecodeView=r.subarray(n,n+i.blockLength),{offset:a,result:i}}function po(r){if(!r.byteLength){let e=new je({},tt);return e.error="Input buffer has zero length",{offset:-1,result:e}}return Nc(ae.BufferSourceConverter.toUint8Array(r).slice(),0,r.byteLength)}function D3(r,e){return r?1:e}var wr=class extends tt{constructor({value:e=[],isIndefiniteForm:t=!1,...n}={}){super(n),this.value=e,this.isIndefiniteForm=t}fromBER(e,t,n){let i=ae.BufferSourceConverter.toUint8Array(e);if(!Zr(this,i,t,n))return-1;if(this.valueBeforeDecodeView=i.subarray(t,t+n),this.valueBeforeDecodeView.length===0)return this.warnings.push("Zero buffer length"),t;let o=t;for(;D3(this.isIndefiniteForm,n)>0;){let s=Nc(i,o,n);if(s.offset===-1)return this.error=s.result.error,this.warnings.concat(s.result.warnings),-1;if(o=s.offset,this.blockLength+=s.result.blockLength,n-=s.result.blockLength,this.value.push(s.result),this.isIndefiniteForm&&s.result.constructor.NAME===cs)break}return this.isIndefiniteForm&&(this.value[this.value.length-1].constructor.NAME===cs?this.value.pop():this.warnings.push("No EndOfContent block encoded")),o}toBER(e,t){let n=t||new as;for(let i=0;i<this.value.length;i++)this.value[i].toBER(e,n);return t?er:n.final()}toJSON(){let e={...super.toJSON(),isIndefiniteForm:this.isIndefiniteForm,value:[]};for(let t of this.value)e.value.push(t.toJSON());return e}};wr.NAME="ConstructedValueBlock";var Hp,Pn=class extends je{constructor(e={}){super(e,wr),this.idBlock.isConstructed=!0}fromBER(e,t,n){this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm;let i=this.valueBlock.fromBER(e,t,this.lenBlock.isIndefiniteForm?n:this.lenBlock.length);return i===-1?(this.error=this.valueBlock.error,i):(this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.valueBlock.error.length||(this.blockLength+=this.valueBlock.blockLength),i)}onAsciiEncoding(){let e=[];for(let n of this.valueBlock.value)e.push(n.toString("ascii").split(`
|
|
2
|
+
"use strict";var HeliaVerifiedFetch=(()=>{var P2=Object.create;var sa=Object.defineProperty;var O2=Object.getOwnPropertyDescriptor;var F2=Object.getOwnPropertyNames;var V2=Object.getPrototypeOf,M2=Object.prototype.hasOwnProperty;var me=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),Ae=(r,e)=>{for(var t in e)sa(r,t,{get:e[t],enumerable:!0})},Mf=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of F2(e))!M2.call(r,i)&&i!==t&&sa(r,i,{get:()=>e[i],enumerable:!(n=O2(e,i))||n.enumerable});return r};var re=(r,e,t)=>(t=r!=null?P2(V2(r)):{},Mf(e||!r||!r.__esModule?sa(t,"default",{value:r,enumerable:!0}):t,r)),H2=r=>Mf(sa({},"__esModule",{value:!0}),r);var mu=me((l8,n0)=>{var Fi=1e3,Vi=Fi*60,Mi=Vi*60,ri=Mi*24,Cx=ri*7,Nx=ri*365.25;n0.exports=function(r,e){e=e||{};var t=typeof r;if(t==="string"&&r.length>0)return Ux(r);if(t==="number"&&isFinite(r))return e.long?Dx(r):Lx(r);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(r))};function Ux(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*Nx;case"weeks":case"week":case"w":return t*Cx;case"days":case"day":case"d":return t*ri;case"hours":case"hour":case"hrs":case"hr":case"h":return t*Mi;case"minutes":case"minute":case"mins":case"min":case"m":return t*Vi;case"seconds":case"second":case"secs":case"sec":case"s":return t*Fi;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return t;default:return}}}}function Lx(r){var e=Math.abs(r);return e>=ri?Math.round(r/ri)+"d":e>=Mi?Math.round(r/Mi)+"h":e>=Vi?Math.round(r/Vi)+"m":e>=Fi?Math.round(r/Fi)+"s":r+"ms"}function Dx(r){var e=Math.abs(r);return e>=ri?ua(r,e,ri,"day"):e>=Mi?ua(r,e,Mi,"hour"):e>=Vi?ua(r,e,Vi,"minute"):e>=Fi?ua(r,e,Fi,"second"):r+" ms"}function ua(r,e,t,n){var i=e>=t*1.5;return Math.round(r/t)+" "+n+(i?"s":"")}});var o0=me((u8,i0)=>{function Px(r){t.debug=t,t.default=t,t.coerce=c,t.disable=o,t.enable=i,t.enabled=s,t.humanize=mu(),t.destroy=u,Object.keys(r).forEach(l=>{t[l]=r[l]}),t.names=[],t.skips=[],t.formatters={};function e(l){let h=0;for(let p=0;p<l.length;p++)h=(h<<5)-h+l.charCodeAt(p),h|=0;return t.colors[Math.abs(h)%t.colors.length]}t.selectColor=e;function t(l){let h,p=null,d,f;function m(...y){if(!m.enabled)return;let g=m,w=Number(new Date),x=w-(h||w);g.diff=x,g.prev=h,g.curr=w,h=w,y[0]=t.coerce(y[0]),typeof y[0]!="string"&&y.unshift("%O");let A=0;y[0]=y[0].replace(/%([a-zA-Z%])/g,(B,v)=>{if(B==="%%")return"%";A++;let E=t.formatters[v];if(typeof E=="function"){let R=y[A];B=E.call(g,R),y.splice(A,1),A--}return B}),t.formatArgs.call(g,y),(g.log||t.log).apply(g,y)}return m.namespace=l,m.useColors=t.useColors(),m.color=t.selectColor(l),m.extend=n,m.destroy=t.destroy,Object.defineProperty(m,"enabled",{enumerable:!0,configurable:!1,get:()=>p!==null?p:(d!==t.namespaces&&(d=t.namespaces,f=t.enabled(l)),f),set:y=>{p=y}}),typeof t.init=="function"&&t.init(m),m}function n(l,h){let p=t(this.namespace+(typeof h>"u"?":":h)+l);return p.log=this.log,p}function i(l){t.save(l),t.namespaces=l,t.names=[],t.skips=[];let h,p=(typeof l=="string"?l:"").split(/[\s,]+/),d=p.length;for(h=0;h<d;h++)p[h]&&(l=p[h].replace(/\*/g,".*?"),l[0]==="-"?t.skips.push(new RegExp("^"+l.slice(1)+"$")):t.names.push(new RegExp("^"+l+"$")))}function o(){let l=[...t.names.map(a),...t.skips.map(a).map(h=>"-"+h)].join(",");return t.enable(""),l}function s(l){if(l[l.length-1]==="*")return!0;let h,p;for(h=0,p=t.skips.length;h<p;h++)if(t.skips[h].test(l))return!1;for(h=0,p=t.names.length;h<p;h++)if(t.names[h].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}i0.exports=Px});var yu=me((vt,ha)=>{vt.formatArgs=Fx;vt.save=Vx;vt.load=Mx;vt.useColors=Ox;vt.storage=Hx();vt.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`."))}})();vt.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 Ox(){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 Fx(r){if(r[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+r[0]+(this.useColors?"%c ":" ")+"+"+ha.exports.humanize(this.diff),!this.useColors)return;let e="color: "+this.color;r.splice(1,0,e,"color: inherit");let t=0,n=0;r[0].replace(/%[a-zA-Z%]/g,i=>{i!=="%%"&&(t++,i==="%c"&&(n=t))}),r.splice(n,0,e)}vt.log=console.debug||console.log||(()=>{});function Vx(r){try{r?vt.storage.setItem("debug",r):vt.storage.removeItem("debug")}catch{}}function Mx(){let r;try{r=vt.storage.getItem("debug")}catch{}return!r&&typeof process<"u"&&"env"in process&&(r=process.env.DEBUG),r}function Hx(){try{return localStorage}catch{}}ha.exports=o0()(vt);var{formatters:$x}=ha.exports;$x.j=function(r){try{return JSON.stringify(r)}catch(e){return"[UnexpectedJSONParseError]: "+e.message}}});var Re=me((LI,S0)=>{"use strict";function I0(r,e){for(let t in e)Object.defineProperty(r,t,{value:e[t],enumerable:!0,configurable:!0});return r}function Sb(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 I0(r,t)}catch{t.message=r.message,t.stack=r.stack;let i=function(){};return i.prototype=Object.create(Object.getPrototypeOf(r)),I0(new i,t)}}S0.exports=Sb});var vp=me(ao=>{"use strict";var g3="[object ArrayBuffer]",Gr=class r{static isArrayBuffer(e){return Object.prototype.toString.call(e)===g3}static toArrayBuffer(e){return this.isArrayBuffer(e)?e:e.byteLength===e.buffer.byteLength||e.byteOffset===0&&e.byteLength===e.buffer.byteLength?e.buffer:this.toUint8Array(e.buffer).slice(e.byteOffset,e.byteOffset+e.byteLength).buffer}static toUint8Array(e){return this.toView(e,Uint8Array)}static toView(e,t){if(e.constructor===t)return e;if(this.isArrayBuffer(e))return new t(e);if(this.isArrayBufferView(e))return new t(e.buffer,e.byteOffset,e.byteLength);throw new TypeError("The provided value is not of type '(ArrayBuffer or ArrayBufferView)'")}static isBufferSource(e){return this.isArrayBufferView(e)||this.isArrayBuffer(e)}static isArrayBufferView(e){return ArrayBuffer.isView(e)||e&&this.isArrayBuffer(e.buffer)}static isEqual(e,t){let n=r.toUint8Array(e),i=r.toUint8Array(t);if(n.length!==i.byteLength)return!1;for(let o=0;o<n.length;o++)if(n[o]!==i[o])return!1;return!0}static concat(...e){let t;Array.isArray(e[0])&&!(e[1]instanceof Function)||Array.isArray(e[0])&&e[1]instanceof Function?t=e[0]:e[e.length-1]instanceof Function?t=e.slice(0,e.length-1):t=e;let n=0;for(let s of t)n+=s.byteLength;let i=new Uint8Array(n),o=0;for(let s of t){let a=this.toUint8Array(s);i.set(a,o),o+=a.length}return e[e.length-1]instanceof Function?this.toView(i,e[e.length-1]):i.buffer}},Sh="string",w3=/^[0-9a-f]+$/i,x3=/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/,b3=/^[a-zA-Z0-9-_]+$/,$a=class{static fromString(e){let t=unescape(encodeURIComponent(e)),n=new Uint8Array(t.length);for(let i=0;i<t.length;i++)n[i]=t.charCodeAt(i);return n.buffer}static toString(e){let t=Gr.toUint8Array(e),n="";for(let o=0;o<t.length;o++)n+=String.fromCharCode(t[o]);return decodeURIComponent(escape(n))}},Ht=class{static toString(e,t=!1){let n=Gr.toArrayBuffer(e),i=new DataView(n),o="";for(let s=0;s<n.byteLength;s+=2){let a=i.getUint16(s,t);o+=String.fromCharCode(a)}return o}static fromString(e,t=!1){let n=new ArrayBuffer(e.length*2),i=new DataView(n);for(let o=0;o<e.length;o++)i.setUint16(o*2,e.charCodeAt(o),t);return n}},za=class r{static isHex(e){return typeof e===Sh&&w3.test(e)}static isBase64(e){return typeof e===Sh&&x3.test(e)}static isBase64Url(e){return typeof e===Sh&&b3.test(e)}static ToString(e,t="utf8"){let n=Gr.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 Ht.toString(n,!0);case"utf16":case"utf16be":return Ht.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 Ht.fromString(e,!0);case"utf16":case"utf16be":return Ht.fromString(e);default:throw new Error(`Unknown type of encoding '${t}'`)}}static ToBase64(e){let t=Gr.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 $a.fromString(e);case"utf16":case"utf16be":return Ht.fromString(e);case"utf16le":case"usc2":return Ht.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 $a.toString(e);case"utf16":case"utf16be":return Ht.toString(e);case"utf16le":case"usc2":return Ht.toString(e,!0);default:throw new Error(`Unknown type of encoding '${t}'`)}}static FromBinary(e){let t=e.length,n=new Uint8Array(t);for(let i=0;i<t;i++)n[i]=e.charCodeAt(i);return n.buffer}static ToBinary(e){let t=Gr.toUint8Array(e),n="";for(let i=0;i<t.length;i++)n+=String.fromCharCode(t[i]);return n}static ToHex(e){let t=Gr.toUint8Array(e),n="",i=t.length;for(let o=0;o<i;o++){let s=t[o];s<16&&(n+="0"),n+=s.toString(16)}return n}static FromHex(e){let t=this.formatString(e);if(!t)return new ArrayBuffer(0);if(!r.isHex(t))throw new TypeError("Argument 'hexString' is not HEX encoded");t.length%2&&(t=`0${t}`);let n=new Uint8Array(t.length/2);for(let i=0;i<t.length;i=i+2){let o=t.slice(i,i+2);n[i/2]=parseInt(o,16)}return n.buffer}static ToUtf16String(e,t=!1){return Ht.toString(e,t)}static FromUtf16String(e,t=!1){return Ht.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,"")||""}};za.DEFAULT_UTF8_ENCODING="utf8";function E3(r,...e){let t=arguments[0];for(let n=1;n<arguments.length;n++){let i=arguments[n];for(let o in i)t[o]=i[o]}return t}function v3(...r){let e=r.map(i=>i.byteLength).reduce((i,o)=>i+o),t=new Uint8Array(e),n=0;return r.map(i=>new Uint8Array(i)).forEach(i=>{for(let o of i)t[n++]=o}),t.buffer}function B3(r,e){if(!(r&&e)||r.byteLength!==e.byteLength)return!1;let t=new Uint8Array(r),n=new Uint8Array(e);for(let i=0;i<r.byteLength;i++)if(t[i]!==n[i])return!1;return!0}ao.BufferSourceConverter=Gr;ao.Convert=za;ao.assign=E3;ao.combine=v3;ao.isEqual=B3});var Nc=me((Zk,Hh)=>{var Xk=function(){typeof Hh<"u"&&(Hh.exports=m);var r=86400,e=3200,t=146097*e/400,n=r*t,i=1e3*n,o=864e13,s=4294967296,a=1e6,c="000000000",u=Math.trunc||function(E){var R=E-E%1;return R==0&&(E<0||E===0&&1/E!=1/0)?-0:R},l=m.prototype,h=(m.fromDate=function(E){return new m(+E)},m.fromInt64BE=A(0,1,2,3,0,4),m.fromInt64LE=A(3,2,1,0,4,0),m.fromString=function(T){var R,N=new m,T=(T+="").replace(/^\s*[+\-]?\d+/,function(D){var D=+D,ne=1970+(D-1970)%400;return N.year=D-ne,ne}).replace(/(?:Z|([+\-]\d{2}):?(\d{2}))$/,function(M,D,ne){return D<0&&(ne*=-1),R=6e4*(60*+D+ +ne),""}).replace(/\.\d+$/,function(M){return N.nano=+(M+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)},m.fromTimeT=function(E){return w(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 B(N.getUTCHours())},L:function(){return v(N.getUTCMilliseconds(),3)},M:function(){return B(N.getUTCMinutes())},N:function(){return v(R.getNano(),9)},S:function(){return B(N.getUTCSeconds())},Y:function(){var M=R.getYear();return 999999<M?"+"+M:9999<M?"+"+v(M,6):0<=M?v(M,4):-999999<=M?"-"+v(-M,6):M},a:function(){return d[N.getUTCDay()]},b:function(){return p[N.getUTCMonth()]},d:function(){return B(N.getUTCDate())},e:function(){return function(M){return(9<M?"":" ")+(0|M)}(N.getUTCDate())},m:function(){return B(N.getUTCMonth()+1)}};return function M(D){return D.replace(/%./g,function(ne){var L=ne[1],_=f[L],L=T[L];return _?M(_):L?L():ne})}(E||h)},l.writeInt64BE=x(0,1,2,3,0,4),l.writeInt64LE=x(3,2,1,0,4,0),"%Y-%m-%dT%H:%M:%S.%NZ"),p=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],d=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],f={"%":"%",F:"%Y-%m-%d",n:`
|
|
3
|
+
`,R:"%H:%M",T:"%H:%M:%S",t:" ",X:"%T",Z:"GMT",z:"+0000"};return m;function m(E,R,N){var T=this;if(!(T instanceof m))return new m(E,R,N);T.time=+E||0,T.nano=+R||0,T.year=+N||0,y(T)}function y(E){var R,N,T,M=E.year,D=E.time,ne=E.nano,_=((ne<0||a<=ne)&&(ne-=(N=Math.floor(ne/a))*a,D+=N,N=1),M%e);return(D<-o||o<D||_)&&((R=u(D/i))&&(M+=R*e,D-=R*i),(T=g(D)).setUTCFullYear(_+T.getUTCFullYear()),T=(D=+T)+(R=u((M-=_)/e))*i,R&&-o<=T&&T<=o&&(M-=R*e,D=T),N=1),N&&(E.year=M,E.time=D,E.nano=ne),E}function g(E){var R=new Date(0);return R.setTime(E),R}function w(M,T){M=+M||0;var N=u((T=(T|0)*s)/n)+u(M/n),T=T%n+M%n,M=u(T/n);return M&&(N+=M,T-=M*n),new m(1e3*T,0,N*e)}function x(E,R,N,T,M,D){return function(_,L){var U=y(this);_=_||new Array(8),I(_,L|=0);var k=Math.floor(U.time/1e3),U=U.year*(t*r/e),X=u(U/s)+u(k/s),U=U%s+k%s,k=Math.floor(U/s);return k&&(X+=k,U-=k*s),ne(_,L+M,X),ne(_,L+D,U),_};function ne(_,L,X){_[L+E]=X>>24&255,_[L+R]=X>>16&255,_[L+N]=X>>8&255,_[L+T]=255&X}}function A(E,R,N,T,M,D){return function(_,L){I(_,L|=0);var X=ne(_,L+M);return w(ne(_,L+D),X)};function ne(_,L){return 16777216*_[L+E]+(_[L+R]<<16|_[L+N]<<8|_[L+T])}}function I(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 B(E){return(9<E?"":"0")+(0|E)}function v(E,R){return(c+(0|E)).substr(-R)}}()});var Zm=me((LT,td)=>{"use strict";var z6=Object.prototype.hasOwnProperty,lt="~";function _s(){}Object.create&&(_s.prototype=Object.create(null),new _s().__proto__||(lt=!1));function K6(r,e,t){this.fn=r,this.context=e,this.once=t||!1}function Xm(r,e,t,n,i){if(typeof t!="function")throw new TypeError("The listener must be a function");var o=new K6(t,n||r,i),s=lt?lt+e:e;return r._events[s]?r._events[s].fn?r._events[s]=[r._events[s],o]:r._events[s].push(o):(r._events[s]=o,r._eventsCount++),r}function Yc(r,e){--r._eventsCount===0?r._events=new _s:delete r._events[e]}function rt(){this._events=new _s,this._eventsCount=0}rt.prototype.eventNames=function(){var e=[],t,n;if(this._eventsCount===0)return e;for(n in t=this._events)z6.call(t,n)&&e.push(lt?n.slice(1):n);return Object.getOwnPropertySymbols?e.concat(Object.getOwnPropertySymbols(t)):e};rt.prototype.listeners=function(e){var t=lt?lt+e:e,n=this._events[t];if(!n)return[];if(n.fn)return[n.fn];for(var i=0,o=n.length,s=new Array(o);i<o;i++)s[i]=n[i].fn;return s};rt.prototype.listenerCount=function(e){var t=lt?lt+e:e,n=this._events[t];return n?n.fn?1:n.length:0};rt.prototype.emit=function(e,t,n,i,o,s){var a=lt?lt+e:e;if(!this._events[a])return!1;var c=this._events[a],u=arguments.length,l,h;if(c.fn){switch(c.once&&this.removeListener(e,c.fn,void 0,!0),u){case 1:return c.fn.call(c.context),!0;case 2:return c.fn.call(c.context,t),!0;case 3:return c.fn.call(c.context,t,n),!0;case 4:return c.fn.call(c.context,t,n,i),!0;case 5:return c.fn.call(c.context,t,n,i,o),!0;case 6:return c.fn.call(c.context,t,n,i,o,s),!0}for(h=1,l=new Array(u-1);h<u;h++)l[h-1]=arguments[h];c.fn.apply(c.context,l)}else{var p=c.length,d;for(h=0;h<p;h++)switch(c[h].once&&this.removeListener(e,c[h].fn,void 0,!0),u){case 1:c[h].fn.call(c[h].context);break;case 2:c[h].fn.call(c[h].context,t);break;case 3:c[h].fn.call(c[h].context,t,n);break;case 4:c[h].fn.call(c[h].context,t,n,i);break;default:if(!l)for(d=1,l=new Array(u-1);d<u;d++)l[d-1]=arguments[d];c[h].fn.apply(c[h].context,l)}}return!0};rt.prototype.on=function(e,t,n){return Xm(this,e,t,n,!1)};rt.prototype.once=function(e,t,n){return Xm(this,e,t,n,!0)};rt.prototype.removeListener=function(e,t,n,i){var o=lt?lt+e:e;if(!this._events[o])return this;if(!t)return Yc(this,o),this;var s=this._events[o];if(s.fn)s.fn===t&&(!i||s.once)&&(!n||s.context===n)&&Yc(this,o);else{for(var a=0,c=[],u=s.length;a<u;a++)(s[a].fn!==t||i&&!s[a].once||n&&s[a].context!==n)&&c.push(s[a]);c.length?this._events[o]=c.length===1?c[0]:c:Yc(this,o)}return this};rt.prototype.removeAllListeners=function(e){var t;return e?(t=lt?lt+e:e,this._events[t]&&Yc(this,t)):(this._events=new _s,this._eventsCount=0),this};rt.prototype.off=rt.prototype.removeListener;rt.prototype.addListener=rt.prototype.on;rt.prefixed=lt;rt.EventEmitter=rt;typeof td<"u"&&(td.exports=rt)});var Gy=me((lD,qy)=>{"use strict";qy.exports=Ky;var zv=mu(),qn=Ky.prototype,Kv=new Date%1e9;function qv(){return(Math.random()*1e9>>>0)+Kv++}function Ky(r){r=r||{},this.id=r.id||qv(),this.max=r.max||1/0,this.items=r.items||[],this._lookup={},this.size=this.items.length,this.lastModified=new Date(r.lastModified||new Date);for(var e,t,n=this.items.length;n--;)e=this.items[n],t=new Date(e.expires)-new Date,this._lookup[e.key]=e,t>0?this.expire(e.key,t):t<=0&&this.delete(e.key)}qn.has=function(r){return r in this._lookup};qn.get=function(r){if(!this.has(r))return null;var e=this._lookup[r];return e.refresh&&this.expire(r,e.refresh),this.items.splice(this.items.indexOf(e),1),this.items.push(e),e.value};qn.meta=function(r){if(!this.has(r))return null;var e=this._lookup[r];return"meta"in e?e.meta:null};qn.set=function(r,e,t){var n=this._lookup[r],i=this._lookup[r]={key:r,value:e};return this.lastModified=new Date,n?(clearTimeout(n.timeout),this.items.splice(this.items.indexOf(n),1,i)):(this.size>=this.max&&this.delete(this.items[0].key),this.items.push(i),this.size++),t&&("ttl"in t&&this.expire(r,t.ttl),"meta"in t&&(i.meta=t.meta),t.refresh&&(i.refresh=t.ttl)),this};qn.delete=function(r){var e=this._lookup[r];return e?(this.lastModified=new Date,this.items.splice(this.items.indexOf(e),1),clearTimeout(e.timeout),delete this._lookup[r],this.size--,this):!1};qn.expire=function(r,e){var t=e||0,n=this._lookup[r];if(!n)return this;if(typeof t=="string"&&(t=zv(e)),typeof t!="number")throw new TypeError("Expiration time must be a string or number.");return clearTimeout(n.timeout),n.timeout=setTimeout(this.delete.bind(this,n.key),t),n.expires=Number(new Date)+t,this};qn.clear=function(){for(var r=this.items.length;r--;)this.delete(this.items[r].key);return this};qn.toJSON=function(){for(var r=new Array(this.items.length),e,t=r.length;t--;)e=this.items[t],r[t]={key:e.key,meta:e.meta,value:e.value,expires:e.expires,refresh:e.refresh};return{id:this.id,max:isFinite(this.max)?this.max:void 0,lastModified:this.lastModified,items:r}}});var Od=me((hD,Yy)=>{Yy.exports=function(r){if(!r)throw Error("hashlru must have a max value, of type number, greater than 0");var e=0,t=Object.create(null),n=Object.create(null);function i(o,s){t[o]=s,e++,e>=r&&(e=0,n=t,t=Object.create(null))}return{has:function(o){return t[o]!==void 0||n[o]!==void 0},remove:function(o){t[o]!==void 0&&(t[o]=void 0),n[o]!==void 0&&(n[o]=void 0)},get:function(o){var s=t[o];if(s!==void 0)return s;if((s=n[o])!==void 0)return i(o,s),s},set:function(o,s){t[o]!==void 0?t[o]=s:i(o,s)},clear:function(){t=Object.create(null),n=Object.create(null)}}}});var lg=me(gl=>{"use strict";gl.byteLength=e4;gl.toByteArray=r4;gl.fromByteArray=o4;var Er=[],qt=[],Qv=typeof Uint8Array<"u"?Uint8Array:Array,zd="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(Ai=0,ag=zd.length;Ai<ag;++Ai)Er[Ai]=zd[Ai],qt[zd.charCodeAt(Ai)]=Ai;var Ai,ag;qt[45]=62;qt[95]=63;function cg(r){var e=r.length;if(e%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var t=r.indexOf("=");t===-1&&(t=e);var n=t===e?0:4-t%4;return[t,n]}function e4(r){var e=cg(r),t=e[0],n=e[1];return(t+n)*3/4-n}function t4(r,e,t){return(e+t)*3/4-t}function r4(r){var e,t=cg(r),n=t[0],i=t[1],o=new Qv(t4(r,n,i)),s=0,a=i>0?n-4:n,c;for(c=0;c<a;c+=4)e=qt[r.charCodeAt(c)]<<18|qt[r.charCodeAt(c+1)]<<12|qt[r.charCodeAt(c+2)]<<6|qt[r.charCodeAt(c+3)],o[s++]=e>>16&255,o[s++]=e>>8&255,o[s++]=e&255;return i===2&&(e=qt[r.charCodeAt(c)]<<2|qt[r.charCodeAt(c+1)]>>4,o[s++]=e&255),i===1&&(e=qt[r.charCodeAt(c)]<<10|qt[r.charCodeAt(c+1)]<<4|qt[r.charCodeAt(c+2)]>>2,o[s++]=e>>8&255,o[s++]=e&255),o}function n4(r){return Er[r>>18&63]+Er[r>>12&63]+Er[r>>6&63]+Er[r&63]}function i4(r,e,t){for(var n,i=[],o=e;o<t;o+=3)n=(r[o]<<16&16711680)+(r[o+1]<<8&65280)+(r[o+2]&255),i.push(n4(n));return i.join("")}function o4(r){for(var e,t=r.length,n=t%3,i=[],o=16383,s=0,a=t-n;s<a;s+=o)i.push(i4(r,s,s+o>a?a:s+o));return n===1?(e=r[t-1],i.push(Er[e>>2]+Er[e<<4&63]+"==")):n===2&&(e=(r[t-2]<<8)+r[t-1],i.push(Er[e>>10]+Er[e>>4&63]+Er[e<<2&63]+"=")),i.join("")}});var ug=me(Kd=>{Kd.read=function(r,e,t,n,i){var o,s,a=i*8-n-1,c=(1<<a)-1,u=c>>1,l=-7,h=t?i-1:0,p=t?-1:1,d=r[e+h];for(h+=p,o=d&(1<<-l)-1,d>>=-l,l+=a;l>0;o=o*256+r[e+h],h+=p,l-=8);for(s=o&(1<<-l)-1,o>>=-l,l+=n;l>0;s=s*256+r[e+h],h+=p,l-=8);if(o===0)o=1-u;else{if(o===c)return s?NaN:(d?-1:1)*(1/0);s=s+Math.pow(2,n),o=o-u}return(d?-1:1)*s*Math.pow(2,o-n)};Kd.write=function(r,e,t,n,i,o){var s,a,c,u=o*8-i-1,l=(1<<u)-1,h=l>>1,p=i===23?Math.pow(2,-24)-Math.pow(2,-77):0,d=n?0:o-1,f=n?1:-1,m=e<0||e===0&&1/e<0?1:0;for(e=Math.abs(e),isNaN(e)||e===1/0?(a=isNaN(e)?1:0,s=l):(s=Math.floor(Math.log(e)/Math.LN2),e*(c=Math.pow(2,-s))<1&&(s--,c*=2),s+h>=1?e+=p/c:e+=p*Math.pow(2,1-h),e*c>=2&&(s++,c/=2),s+h>=l?(a=0,s=l):s+h>=1?(a=(e*c-1)*Math.pow(2,i),s=s+h):(a=e*Math.pow(2,h-1)*Math.pow(2,i),s=0));i>=8;r[t+d]=a&255,d+=f,a/=256,i-=8);for(s=s<<i|a,u+=i;u>0;r[t+d]=s&255,d+=f,s/=256,u-=8);r[t+d-f]|=m*128}});var Qd=me(Co=>{"use strict";var qd=lg(),Ro=ug(),hg=typeof Symbol=="function"&&typeof Symbol.for=="function"?Symbol.for("nodejs.util.inspect.custom"):null;Co.Buffer=S;Co.SlowBuffer=h4;Co.INSPECT_MAX_BYTES=50;var wl=2147483647;Co.kMaxLength=wl;S.TYPED_ARRAY_SUPPORT=s4();!S.TYPED_ARRAY_SUPPORT&&typeof console<"u"&&typeof console.error=="function"&&console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support.");function s4(){try{let r=new Uint8Array(1),e={foo:function(){return 42}};return Object.setPrototypeOf(e,Uint8Array.prototype),Object.setPrototypeOf(r,e),r.foo()===42}catch{return!1}}Object.defineProperty(S.prototype,"parent",{enumerable:!0,get:function(){if(S.isBuffer(this))return this.buffer}});Object.defineProperty(S.prototype,"offset",{enumerable:!0,get:function(){if(S.isBuffer(this))return this.byteOffset}});function an(r){if(r>wl)throw new RangeError('The value "'+r+'" is invalid for option "size"');let e=new Uint8Array(r);return Object.setPrototypeOf(e,S.prototype),e}function S(r,e,t){if(typeof r=="number"){if(typeof e=="string")throw new TypeError('The "string" argument must be of type string. Received type number');return Yd(r)}return mg(r,e,t)}S.poolSize=8192;function mg(r,e,t){if(typeof r=="string")return c4(r,e);if(ArrayBuffer.isView(r))return l4(r);if(r==null)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof r);if(vr(r,ArrayBuffer)||r&&vr(r.buffer,ArrayBuffer)||typeof SharedArrayBuffer<"u"&&(vr(r,SharedArrayBuffer)||r&&vr(r.buffer,SharedArrayBuffer)))return jd(r,e,t);if(typeof r=="number")throw new TypeError('The "value" argument must not be of type number. Received type number');let n=r.valueOf&&r.valueOf();if(n!=null&&n!==r)return S.from(n,e,t);let i=u4(r);if(i)return i;if(typeof Symbol<"u"&&Symbol.toPrimitive!=null&&typeof r[Symbol.toPrimitive]=="function")return S.from(r[Symbol.toPrimitive]("string"),e,t);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof r)}S.from=function(r,e,t){return mg(r,e,t)};Object.setPrototypeOf(S.prototype,Uint8Array.prototype);Object.setPrototypeOf(S,Uint8Array);function yg(r){if(typeof r!="number")throw new TypeError('"size" argument must be of type number');if(r<0)throw new RangeError('The value "'+r+'" is invalid for option "size"')}function a4(r,e,t){return yg(r),r<=0?an(r):e!==void 0?typeof t=="string"?an(r).fill(e,t):an(r).fill(e):an(r)}S.alloc=function(r,e,t){return a4(r,e,t)};function Yd(r){return yg(r),an(r<0?0:Xd(r)|0)}S.allocUnsafe=function(r){return Yd(r)};S.allocUnsafeSlow=function(r){return Yd(r)};function c4(r,e){if((typeof e!="string"||e==="")&&(e="utf8"),!S.isEncoding(e))throw new TypeError("Unknown encoding: "+e);let t=gg(r,e)|0,n=an(t),i=n.write(r,e);return i!==t&&(n=n.slice(0,i)),n}function Gd(r){let e=r.length<0?0:Xd(r.length)|0,t=an(e);for(let n=0;n<e;n+=1)t[n]=r[n]&255;return t}function l4(r){if(vr(r,Uint8Array)){let e=new Uint8Array(r);return jd(e.buffer,e.byteOffset,e.byteLength)}return Gd(r)}function jd(r,e,t){if(e<0||r.byteLength<e)throw new RangeError('"offset" is outside of buffer bounds');if(r.byteLength<e+(t||0))throw new RangeError('"length" is outside of buffer bounds');let n;return e===void 0&&t===void 0?n=new Uint8Array(r):t===void 0?n=new Uint8Array(r,e):n=new Uint8Array(r,e,t),Object.setPrototypeOf(n,S.prototype),n}function u4(r){if(S.isBuffer(r)){let e=Xd(r.length)|0,t=an(e);return t.length===0||r.copy(t,0,0,e),t}if(r.length!==void 0)return typeof r.length!="number"||Jd(r.length)?an(0):Gd(r);if(r.type==="Buffer"&&Array.isArray(r.data))return Gd(r.data)}function Xd(r){if(r>=wl)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+wl.toString(16)+" bytes");return r|0}function h4(r){return+r!=r&&(r=0),S.alloc(+r)}S.isBuffer=function(e){return e!=null&&e._isBuffer===!0&&e!==S.prototype};S.compare=function(e,t){if(vr(e,Uint8Array)&&(e=S.from(e,e.offset,e.byteLength)),vr(t,Uint8Array)&&(t=S.from(t,t.offset,t.byteLength)),!S.isBuffer(e)||!S.isBuffer(t))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(e===t)return 0;let n=e.length,i=t.length;for(let o=0,s=Math.min(n,i);o<s;++o)if(e[o]!==t[o]){n=e[o],i=t[o];break}return n<i?-1:i<n?1:0};S.isEncoding=function(e){switch(String(e).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}};S.concat=function(e,t){if(!Array.isArray(e))throw new TypeError('"list" argument must be an Array of Buffers');if(e.length===0)return S.alloc(0);let n;if(t===void 0)for(t=0,n=0;n<e.length;++n)t+=e[n].length;let i=S.allocUnsafe(t),o=0;for(n=0;n<e.length;++n){let s=e[n];if(vr(s,Uint8Array))o+s.length>i.length?(S.isBuffer(s)||(s=S.from(s)),s.copy(i,o)):Uint8Array.prototype.set.call(i,s,o);else if(S.isBuffer(s))s.copy(i,o);else throw new TypeError('"list" argument must be an Array of Buffers');o+=s.length}return i};function gg(r,e){if(S.isBuffer(r))return r.length;if(ArrayBuffer.isView(r)||vr(r,ArrayBuffer))return r.byteLength;if(typeof r!="string")throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof r);let t=r.length,n=arguments.length>2&&arguments[2]===!0;if(!n&&t===0)return 0;let i=!1;for(;;)switch(e){case"ascii":case"latin1":case"binary":return t;case"utf8":case"utf-8":return Wd(r).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return t*2;case"hex":return t>>>1;case"base64":return Sg(r).length;default:if(i)return n?-1:Wd(r).length;e=(""+e).toLowerCase(),i=!0}}S.byteLength=gg;function d4(r,e,t){let n=!1;if((e===void 0||e<0)&&(e=0),e>this.length||((t===void 0||t>this.length)&&(t=this.length),t<=0)||(t>>>=0,e>>>=0,t<=e))return"";for(r||(r="utf8");;)switch(r){case"hex":return v4(this,e,t);case"utf8":case"utf-8":return xg(this,e,t);case"ascii":return b4(this,e,t);case"latin1":case"binary":return E4(this,e,t);case"base64":return w4(this,e,t);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return B4(this,e,t);default:if(n)throw new TypeError("Unknown encoding: "+r);r=(r+"").toLowerCase(),n=!0}}S.prototype._isBuffer=!0;function Ii(r,e,t){let n=r[e];r[e]=r[t],r[t]=n}S.prototype.swap16=function(){let e=this.length;if(e%2!==0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(let t=0;t<e;t+=2)Ii(this,t,t+1);return this};S.prototype.swap32=function(){let e=this.length;if(e%4!==0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(let t=0;t<e;t+=4)Ii(this,t,t+3),Ii(this,t+1,t+2);return this};S.prototype.swap64=function(){let e=this.length;if(e%8!==0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(let t=0;t<e;t+=8)Ii(this,t,t+7),Ii(this,t+1,t+6),Ii(this,t+2,t+5),Ii(this,t+3,t+4);return this};S.prototype.toString=function(){let e=this.length;return e===0?"":arguments.length===0?xg(this,0,e):d4.apply(this,arguments)};S.prototype.toLocaleString=S.prototype.toString;S.prototype.equals=function(e){if(!S.isBuffer(e))throw new TypeError("Argument must be a Buffer");return this===e?!0:S.compare(this,e)===0};S.prototype.inspect=function(){let e="",t=Co.INSPECT_MAX_BYTES;return e=this.toString("hex",0,t).replace(/(.{2})/g,"$1 ").trim(),this.length>t&&(e+=" ... "),"<Buffer "+e+">"};hg&&(S.prototype[hg]=S.prototype.inspect);S.prototype.compare=function(e,t,n,i,o){if(vr(e,Uint8Array)&&(e=S.from(e,e.offset,e.byteLength)),!S.isBuffer(e))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof e);if(t===void 0&&(t=0),n===void 0&&(n=e?e.length:0),i===void 0&&(i=0),o===void 0&&(o=this.length),t<0||n>e.length||i<0||o>this.length)throw new RangeError("out of range index");if(i>=o&&t>=n)return 0;if(i>=o)return-1;if(t>=n)return 1;if(t>>>=0,n>>>=0,i>>>=0,o>>>=0,this===e)return 0;let s=o-i,a=n-t,c=Math.min(s,a),u=this.slice(i,o),l=e.slice(t,n);for(let h=0;h<c;++h)if(u[h]!==l[h]){s=u[h],a=l[h];break}return s<a?-1:a<s?1:0};function wg(r,e,t,n,i){if(r.length===0)return-1;if(typeof t=="string"?(n=t,t=0):t>2147483647?t=2147483647:t<-2147483648&&(t=-2147483648),t=+t,Jd(t)&&(t=i?0:r.length-1),t<0&&(t=r.length+t),t>=r.length){if(i)return-1;t=r.length-1}else if(t<0)if(i)t=0;else return-1;if(typeof e=="string"&&(e=S.from(e,n)),S.isBuffer(e))return e.length===0?-1:dg(r,e,t,n,i);if(typeof e=="number")return e=e&255,typeof Uint8Array.prototype.indexOf=="function"?i?Uint8Array.prototype.indexOf.call(r,e,t):Uint8Array.prototype.lastIndexOf.call(r,e,t):dg(r,[e],t,n,i);throw new TypeError("val must be string, number or Buffer")}function dg(r,e,t,n,i){let o=1,s=r.length,a=e.length;if(n!==void 0&&(n=String(n).toLowerCase(),n==="ucs2"||n==="ucs-2"||n==="utf16le"||n==="utf-16le")){if(r.length<2||e.length<2)return-1;o=2,s/=2,a/=2,t/=2}function c(l,h){return o===1?l[h]:l.readUInt16BE(h*o)}let u;if(i){let l=-1;for(u=t;u<s;u++)if(c(r,u)===c(e,l===-1?0:u-l)){if(l===-1&&(l=u),u-l+1===a)return l*o}else l!==-1&&(u-=u-l),l=-1}else for(t+a>s&&(t=s-a),u=t;u>=0;u--){let l=!0;for(let h=0;h<a;h++)if(c(r,u+h)!==c(e,h)){l=!1;break}if(l)return u}return-1}S.prototype.includes=function(e,t,n){return this.indexOf(e,t,n)!==-1};S.prototype.indexOf=function(e,t,n){return wg(this,e,t,n,!0)};S.prototype.lastIndexOf=function(e,t,n){return wg(this,e,t,n,!1)};function f4(r,e,t,n){t=Number(t)||0;let i=r.length-t;n?(n=Number(n),n>i&&(n=i)):n=i;let o=e.length;n>o/2&&(n=o/2);let s;for(s=0;s<n;++s){let a=parseInt(e.substr(s*2,2),16);if(Jd(a))return s;r[t+s]=a}return s}function p4(r,e,t,n){return xl(Wd(e,r.length-t),r,t,n)}function m4(r,e,t,n){return xl(_4(e),r,t,n)}function y4(r,e,t,n){return xl(Sg(e),r,t,n)}function g4(r,e,t,n){return xl(k4(e,r.length-t),r,t,n)}S.prototype.write=function(e,t,n,i){if(t===void 0)i="utf8",n=this.length,t=0;else if(n===void 0&&typeof t=="string")i=t,n=this.length,t=0;else if(isFinite(t))t=t>>>0,isFinite(n)?(n=n>>>0,i===void 0&&(i="utf8")):(i=n,n=void 0);else throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");let o=this.length-t;if((n===void 0||n>o)&&(n=o),e.length>0&&(n<0||t<0)||t>this.length)throw new RangeError("Attempt to write outside buffer bounds");i||(i="utf8");let s=!1;for(;;)switch(i){case"hex":return f4(this,e,t,n);case"utf8":case"utf-8":return p4(this,e,t,n);case"ascii":case"latin1":case"binary":return m4(this,e,t,n);case"base64":return y4(this,e,t,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return g4(this,e,t,n);default:if(s)throw new TypeError("Unknown encoding: "+i);i=(""+i).toLowerCase(),s=!0}};S.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function w4(r,e,t){return e===0&&t===r.length?qd.fromByteArray(r):qd.fromByteArray(r.slice(e,t))}function xg(r,e,t){t=Math.min(r.length,t);let n=[],i=e;for(;i<t;){let o=r[i],s=null,a=o>239?4:o>223?3:o>191?2:1;if(i+a<=t){let c,u,l,h;switch(a){case 1:o<128&&(s=o);break;case 2:c=r[i+1],(c&192)===128&&(h=(o&31)<<6|c&63,h>127&&(s=h));break;case 3:c=r[i+1],u=r[i+2],(c&192)===128&&(u&192)===128&&(h=(o&15)<<12|(c&63)<<6|u&63,h>2047&&(h<55296||h>57343)&&(s=h));break;case 4:c=r[i+1],u=r[i+2],l=r[i+3],(c&192)===128&&(u&192)===128&&(l&192)===128&&(h=(o&15)<<18|(c&63)<<12|(u&63)<<6|l&63,h>65535&&h<1114112&&(s=h))}}s===null?(s=65533,a=1):s>65535&&(s-=65536,n.push(s>>>10&1023|55296),s=56320|s&1023),n.push(s),i+=a}return x4(n)}var fg=4096;function x4(r){let e=r.length;if(e<=fg)return String.fromCharCode.apply(String,r);let t="",n=0;for(;n<e;)t+=String.fromCharCode.apply(String,r.slice(n,n+=fg));return t}function b4(r,e,t){let n="";t=Math.min(r.length,t);for(let i=e;i<t;++i)n+=String.fromCharCode(r[i]&127);return n}function E4(r,e,t){let n="";t=Math.min(r.length,t);for(let i=e;i<t;++i)n+=String.fromCharCode(r[i]);return n}function v4(r,e,t){let n=r.length;(!e||e<0)&&(e=0),(!t||t<0||t>n)&&(t=n);let i="";for(let o=e;o<t;++o)i+=R4[r[o]];return i}function B4(r,e,t){let n=r.slice(e,t),i="";for(let o=0;o<n.length-1;o+=2)i+=String.fromCharCode(n[o]+n[o+1]*256);return i}S.prototype.slice=function(e,t){let n=this.length;e=~~e,t=t===void 0?n:~~t,e<0?(e+=n,e<0&&(e=0)):e>n&&(e=n),t<0?(t+=n,t<0&&(t=0)):t>n&&(t=n),t<e&&(t=e);let i=this.subarray(e,t);return Object.setPrototypeOf(i,S.prototype),i};function He(r,e,t){if(r%1!==0||r<0)throw new RangeError("offset is not uint");if(r+e>t)throw new RangeError("Trying to access beyond buffer length")}S.prototype.readUintLE=S.prototype.readUIntLE=function(e,t,n){e=e>>>0,t=t>>>0,n||He(e,t,this.length);let i=this[e],o=1,s=0;for(;++s<t&&(o*=256);)i+=this[e+s]*o;return i};S.prototype.readUintBE=S.prototype.readUIntBE=function(e,t,n){e=e>>>0,t=t>>>0,n||He(e,t,this.length);let i=this[e+--t],o=1;for(;t>0&&(o*=256);)i+=this[e+--t]*o;return i};S.prototype.readUint8=S.prototype.readUInt8=function(e,t){return e=e>>>0,t||He(e,1,this.length),this[e]};S.prototype.readUint16LE=S.prototype.readUInt16LE=function(e,t){return e=e>>>0,t||He(e,2,this.length),this[e]|this[e+1]<<8};S.prototype.readUint16BE=S.prototype.readUInt16BE=function(e,t){return e=e>>>0,t||He(e,2,this.length),this[e]<<8|this[e+1]};S.prototype.readUint32LE=S.prototype.readUInt32LE=function(e,t){return e=e>>>0,t||He(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+this[e+3]*16777216};S.prototype.readUint32BE=S.prototype.readUInt32BE=function(e,t){return e=e>>>0,t||He(e,4,this.length),this[e]*16777216+(this[e+1]<<16|this[e+2]<<8|this[e+3])};S.prototype.readBigUInt64LE=jn(function(e){e=e>>>0,To(e,"offset");let t=this[e],n=this[e+7];(t===void 0||n===void 0)&&Hs(e,this.length-8);let i=t+this[++e]*2**8+this[++e]*2**16+this[++e]*2**24,o=this[++e]+this[++e]*2**8+this[++e]*2**16+n*2**24;return BigInt(i)+(BigInt(o)<<BigInt(32))});S.prototype.readBigUInt64BE=jn(function(e){e=e>>>0,To(e,"offset");let t=this[e],n=this[e+7];(t===void 0||n===void 0)&&Hs(e,this.length-8);let i=t*2**24+this[++e]*2**16+this[++e]*2**8+this[++e],o=this[++e]*2**24+this[++e]*2**16+this[++e]*2**8+n;return(BigInt(i)<<BigInt(32))+BigInt(o)});S.prototype.readIntLE=function(e,t,n){e=e>>>0,t=t>>>0,n||He(e,t,this.length);let i=this[e],o=1,s=0;for(;++s<t&&(o*=256);)i+=this[e+s]*o;return o*=128,i>=o&&(i-=Math.pow(2,8*t)),i};S.prototype.readIntBE=function(e,t,n){e=e>>>0,t=t>>>0,n||He(e,t,this.length);let i=t,o=1,s=this[e+--i];for(;i>0&&(o*=256);)s+=this[e+--i]*o;return o*=128,s>=o&&(s-=Math.pow(2,8*t)),s};S.prototype.readInt8=function(e,t){return e=e>>>0,t||He(e,1,this.length),this[e]&128?(255-this[e]+1)*-1:this[e]};S.prototype.readInt16LE=function(e,t){e=e>>>0,t||He(e,2,this.length);let n=this[e]|this[e+1]<<8;return n&32768?n|4294901760:n};S.prototype.readInt16BE=function(e,t){e=e>>>0,t||He(e,2,this.length);let n=this[e+1]|this[e]<<8;return n&32768?n|4294901760:n};S.prototype.readInt32LE=function(e,t){return e=e>>>0,t||He(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24};S.prototype.readInt32BE=function(e,t){return e=e>>>0,t||He(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]};S.prototype.readBigInt64LE=jn(function(e){e=e>>>0,To(e,"offset");let t=this[e],n=this[e+7];(t===void 0||n===void 0)&&Hs(e,this.length-8);let i=this[e+4]+this[e+5]*2**8+this[e+6]*2**16+(n<<24);return(BigInt(i)<<BigInt(32))+BigInt(t+this[++e]*2**8+this[++e]*2**16+this[++e]*2**24)});S.prototype.readBigInt64BE=jn(function(e){e=e>>>0,To(e,"offset");let t=this[e],n=this[e+7];(t===void 0||n===void 0)&&Hs(e,this.length-8);let i=(t<<24)+this[++e]*2**16+this[++e]*2**8+this[++e];return(BigInt(i)<<BigInt(32))+BigInt(this[++e]*2**24+this[++e]*2**16+this[++e]*2**8+n)});S.prototype.readFloatLE=function(e,t){return e=e>>>0,t||He(e,4,this.length),Ro.read(this,e,!0,23,4)};S.prototype.readFloatBE=function(e,t){return e=e>>>0,t||He(e,4,this.length),Ro.read(this,e,!1,23,4)};S.prototype.readDoubleLE=function(e,t){return e=e>>>0,t||He(e,8,this.length),Ro.read(this,e,!0,52,8)};S.prototype.readDoubleBE=function(e,t){return e=e>>>0,t||He(e,8,this.length),Ro.read(this,e,!1,52,8)};function xt(r,e,t,n,i,o){if(!S.isBuffer(r))throw new TypeError('"buffer" argument must be a Buffer instance');if(e>i||e<o)throw new RangeError('"value" argument is out of bounds');if(t+n>r.length)throw new RangeError("Index out of range")}S.prototype.writeUintLE=S.prototype.writeUIntLE=function(e,t,n,i){if(e=+e,t=t>>>0,n=n>>>0,!i){let a=Math.pow(2,8*n)-1;xt(this,e,t,n,a,0)}let o=1,s=0;for(this[t]=e&255;++s<n&&(o*=256);)this[t+s]=e/o&255;return t+n};S.prototype.writeUintBE=S.prototype.writeUIntBE=function(e,t,n,i){if(e=+e,t=t>>>0,n=n>>>0,!i){let a=Math.pow(2,8*n)-1;xt(this,e,t,n,a,0)}let o=n-1,s=1;for(this[t+o]=e&255;--o>=0&&(s*=256);)this[t+o]=e/s&255;return t+n};S.prototype.writeUint8=S.prototype.writeUInt8=function(e,t,n){return e=+e,t=t>>>0,n||xt(this,e,t,1,255,0),this[t]=e&255,t+1};S.prototype.writeUint16LE=S.prototype.writeUInt16LE=function(e,t,n){return e=+e,t=t>>>0,n||xt(this,e,t,2,65535,0),this[t]=e&255,this[t+1]=e>>>8,t+2};S.prototype.writeUint16BE=S.prototype.writeUInt16BE=function(e,t,n){return e=+e,t=t>>>0,n||xt(this,e,t,2,65535,0),this[t]=e>>>8,this[t+1]=e&255,t+2};S.prototype.writeUint32LE=S.prototype.writeUInt32LE=function(e,t,n){return e=+e,t=t>>>0,n||xt(this,e,t,4,4294967295,0),this[t+3]=e>>>24,this[t+2]=e>>>16,this[t+1]=e>>>8,this[t]=e&255,t+4};S.prototype.writeUint32BE=S.prototype.writeUInt32BE=function(e,t,n){return e=+e,t=t>>>0,n||xt(this,e,t,4,4294967295,0),this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=e&255,t+4};function bg(r,e,t,n,i){Ig(e,n,i,r,t,7);let o=Number(e&BigInt(4294967295));r[t++]=o,o=o>>8,r[t++]=o,o=o>>8,r[t++]=o,o=o>>8,r[t++]=o;let s=Number(e>>BigInt(32)&BigInt(4294967295));return r[t++]=s,s=s>>8,r[t++]=s,s=s>>8,r[t++]=s,s=s>>8,r[t++]=s,t}function Eg(r,e,t,n,i){Ig(e,n,i,r,t,7);let o=Number(e&BigInt(4294967295));r[t+7]=o,o=o>>8,r[t+6]=o,o=o>>8,r[t+5]=o,o=o>>8,r[t+4]=o;let s=Number(e>>BigInt(32)&BigInt(4294967295));return r[t+3]=s,s=s>>8,r[t+2]=s,s=s>>8,r[t+1]=s,s=s>>8,r[t]=s,t+8}S.prototype.writeBigUInt64LE=jn(function(e,t=0){return bg(this,e,t,BigInt(0),BigInt("0xffffffffffffffff"))});S.prototype.writeBigUInt64BE=jn(function(e,t=0){return Eg(this,e,t,BigInt(0),BigInt("0xffffffffffffffff"))});S.prototype.writeIntLE=function(e,t,n,i){if(e=+e,t=t>>>0,!i){let c=Math.pow(2,8*n-1);xt(this,e,t,n,c-1,-c)}let o=0,s=1,a=0;for(this[t]=e&255;++o<n&&(s*=256);)e<0&&a===0&&this[t+o-1]!==0&&(a=1),this[t+o]=(e/s>>0)-a&255;return t+n};S.prototype.writeIntBE=function(e,t,n,i){if(e=+e,t=t>>>0,!i){let c=Math.pow(2,8*n-1);xt(this,e,t,n,c-1,-c)}let o=n-1,s=1,a=0;for(this[t+o]=e&255;--o>=0&&(s*=256);)e<0&&a===0&&this[t+o+1]!==0&&(a=1),this[t+o]=(e/s>>0)-a&255;return t+n};S.prototype.writeInt8=function(e,t,n){return e=+e,t=t>>>0,n||xt(this,e,t,1,127,-128),e<0&&(e=255+e+1),this[t]=e&255,t+1};S.prototype.writeInt16LE=function(e,t,n){return e=+e,t=t>>>0,n||xt(this,e,t,2,32767,-32768),this[t]=e&255,this[t+1]=e>>>8,t+2};S.prototype.writeInt16BE=function(e,t,n){return e=+e,t=t>>>0,n||xt(this,e,t,2,32767,-32768),this[t]=e>>>8,this[t+1]=e&255,t+2};S.prototype.writeInt32LE=function(e,t,n){return e=+e,t=t>>>0,n||xt(this,e,t,4,2147483647,-2147483648),this[t]=e&255,this[t+1]=e>>>8,this[t+2]=e>>>16,this[t+3]=e>>>24,t+4};S.prototype.writeInt32BE=function(e,t,n){return e=+e,t=t>>>0,n||xt(this,e,t,4,2147483647,-2147483648),e<0&&(e=4294967295+e+1),this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=e&255,t+4};S.prototype.writeBigInt64LE=jn(function(e,t=0){return bg(this,e,t,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});S.prototype.writeBigInt64BE=jn(function(e,t=0){return Eg(this,e,t,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});function vg(r,e,t,n,i,o){if(t+n>r.length)throw new RangeError("Index out of range");if(t<0)throw new RangeError("Index out of range")}function Bg(r,e,t,n,i){return e=+e,t=t>>>0,i||vg(r,e,t,4,34028234663852886e22,-34028234663852886e22),Ro.write(r,e,t,n,23,4),t+4}S.prototype.writeFloatLE=function(e,t,n){return Bg(this,e,t,!0,n)};S.prototype.writeFloatBE=function(e,t,n){return Bg(this,e,t,!1,n)};function Ag(r,e,t,n,i){return e=+e,t=t>>>0,i||vg(r,e,t,8,17976931348623157e292,-17976931348623157e292),Ro.write(r,e,t,n,52,8),t+8}S.prototype.writeDoubleLE=function(e,t,n){return Ag(this,e,t,!0,n)};S.prototype.writeDoubleBE=function(e,t,n){return Ag(this,e,t,!1,n)};S.prototype.copy=function(e,t,n,i){if(!S.isBuffer(e))throw new TypeError("argument should be a Buffer");if(n||(n=0),!i&&i!==0&&(i=this.length),t>=e.length&&(t=e.length),t||(t=0),i>0&&i<n&&(i=n),i===n||e.length===0||this.length===0)return 0;if(t<0)throw new RangeError("targetStart out of bounds");if(n<0||n>=this.length)throw new RangeError("Index out of range");if(i<0)throw new RangeError("sourceEnd out of bounds");i>this.length&&(i=this.length),e.length-t<i-n&&(i=e.length-t+n);let o=i-n;return this===e&&typeof Uint8Array.prototype.copyWithin=="function"?this.copyWithin(t,n,i):Uint8Array.prototype.set.call(e,this.subarray(n,i),t),o};S.prototype.fill=function(e,t,n,i){if(typeof e=="string"){if(typeof t=="string"?(i=t,t=0,n=this.length):typeof n=="string"&&(i=n,n=this.length),i!==void 0&&typeof i!="string")throw new TypeError("encoding must be a string");if(typeof i=="string"&&!S.isEncoding(i))throw new TypeError("Unknown encoding: "+i);if(e.length===1){let s=e.charCodeAt(0);(i==="utf8"&&s<128||i==="latin1")&&(e=s)}}else typeof e=="number"?e=e&255:typeof e=="boolean"&&(e=Number(e));if(t<0||this.length<t||this.length<n)throw new RangeError("Out of range index");if(n<=t)return this;t=t>>>0,n=n===void 0?this.length:n>>>0,e||(e=0);let o;if(typeof e=="number")for(o=t;o<n;++o)this[o]=e;else{let s=S.isBuffer(e)?e:S.from(e,i),a=s.length;if(a===0)throw new TypeError('The value "'+e+'" is invalid for argument "value"');for(o=0;o<n-t;++o)this[o+t]=s[o%a]}return this};var ko={};function Zd(r,e,t){ko[r]=class extends t{constructor(){super(),Object.defineProperty(this,"message",{value:e.apply(this,arguments),writable:!0,configurable:!0}),this.name=`${this.name} [${r}]`,this.stack,delete this.name}get code(){return r}set code(i){Object.defineProperty(this,"code",{configurable:!0,enumerable:!0,value:i,writable:!0})}toString(){return`${this.name} [${r}]: ${this.message}`}}}Zd("ERR_BUFFER_OUT_OF_BOUNDS",function(r){return r?`${r} is outside of buffer bounds`:"Attempt to access memory outside buffer bounds"},RangeError);Zd("ERR_INVALID_ARG_TYPE",function(r,e){return`The "${r}" argument must be of type number. Received type ${typeof e}`},TypeError);Zd("ERR_OUT_OF_RANGE",function(r,e,t){let n=`The value of "${r}" is out of range.`,i=t;return Number.isInteger(t)&&Math.abs(t)>2**32?i=pg(String(t)):typeof t=="bigint"&&(i=String(t),(t>BigInt(2)**BigInt(32)||t<-(BigInt(2)**BigInt(32)))&&(i=pg(i)),i+="n"),n+=` It must be ${e}. Received ${i}`,n},RangeError);function pg(r){let e="",t=r.length,n=r[0]==="-"?1:0;for(;t>=n+4;t-=3)e=`_${r.slice(t-3,t)}${e}`;return`${r.slice(0,t)}${e}`}function A4(r,e,t){To(e,"offset"),(r[e]===void 0||r[e+t]===void 0)&&Hs(e,r.length-(t+1))}function Ig(r,e,t,n,i,o){if(r>t||r<e){let s=typeof e=="bigint"?"n":"",a;throw o>3?e===0||e===BigInt(0)?a=`>= 0${s} and < 2${s} ** ${(o+1)*8}${s}`:a=`>= -(2${s} ** ${(o+1)*8-1}${s}) and < 2 ** ${(o+1)*8-1}${s}`:a=`>= ${e}${s} and <= ${t}${s}`,new ko.ERR_OUT_OF_RANGE("value",a,r)}A4(n,i,o)}function To(r,e){if(typeof r!="number")throw new ko.ERR_INVALID_ARG_TYPE(e,"number",r)}function Hs(r,e,t){throw Math.floor(r)!==r?(To(r,t),new ko.ERR_OUT_OF_RANGE(t||"offset","an integer",r)):e<0?new ko.ERR_BUFFER_OUT_OF_BOUNDS:new ko.ERR_OUT_OF_RANGE(t||"offset",`>= ${t?1:0} and <= ${e}`,r)}var I4=/[^+/0-9A-Za-z-_]/g;function S4(r){if(r=r.split("=")[0],r=r.trim().replace(I4,""),r.length<2)return"";for(;r.length%4!==0;)r=r+"=";return r}function Wd(r,e){e=e||1/0;let t,n=r.length,i=null,o=[];for(let s=0;s<n;++s){if(t=r.charCodeAt(s),t>55295&&t<57344){if(!i){if(t>56319){(e-=3)>-1&&o.push(239,191,189);continue}else if(s+1===n){(e-=3)>-1&&o.push(239,191,189);continue}i=t;continue}if(t<56320){(e-=3)>-1&&o.push(239,191,189),i=t;continue}t=(i-55296<<10|t-56320)+65536}else i&&(e-=3)>-1&&o.push(239,191,189);if(i=null,t<128){if((e-=1)<0)break;o.push(t)}else if(t<2048){if((e-=2)<0)break;o.push(t>>6|192,t&63|128)}else if(t<65536){if((e-=3)<0)break;o.push(t>>12|224,t>>6&63|128,t&63|128)}else if(t<1114112){if((e-=4)<0)break;o.push(t>>18|240,t>>12&63|128,t>>6&63|128,t&63|128)}else throw new Error("Invalid code point")}return o}function _4(r){let e=[];for(let t=0;t<r.length;++t)e.push(r.charCodeAt(t)&255);return e}function k4(r,e){let t,n,i,o=[];for(let s=0;s<r.length&&!((e-=2)<0);++s)t=r.charCodeAt(s),n=t>>8,i=t%256,o.push(i),o.push(n);return o}function Sg(r){return qd.toByteArray(S4(r))}function xl(r,e,t,n){let i;for(i=0;i<n&&!(i+t>=e.length||i>=r.length);++i)e[i+t]=r[i];return i}function vr(r,e){return r instanceof e||r!=null&&r.constructor!=null&&r.constructor.name!=null&&r.constructor.name===e.name}function Jd(r){return r!==r}var R4=function(){let r="0123456789abcdef",e=new Array(256);for(let t=0;t<16;++t){let n=t*16;for(let i=0;i<16;++i)e[n+i]=r[t]+r[i]}return e}();function jn(r){return typeof BigInt>"u"?T4:r}function T4(){throw new Error("BigInt not supported")}});var _g=me(ef=>{"use strict";ef.toString=function(r){switch(r){case 1:return"A";case 10:return"NULL";case 28:return"AAAA";case 18:return"AFSDB";case 42:return"APL";case 257:return"CAA";case 60:return"CDNSKEY";case 59:return"CDS";case 37:return"CERT";case 5:return"CNAME";case 49:return"DHCID";case 32769:return"DLV";case 39:return"DNAME";case 48:return"DNSKEY";case 43:return"DS";case 55:return"HIP";case 13:return"HINFO";case 45:return"IPSECKEY";case 25:return"KEY";case 36:return"KX";case 29:return"LOC";case 15:return"MX";case 35:return"NAPTR";case 2:return"NS";case 47:return"NSEC";case 50:return"NSEC3";case 51:return"NSEC3PARAM";case 12:return"PTR";case 46:return"RRSIG";case 17:return"RP";case 24:return"SIG";case 6:return"SOA";case 99:return"SPF";case 33:return"SRV";case 44:return"SSHFP";case 32768:return"TA";case 249:return"TKEY";case 52:return"TLSA";case 250:return"TSIG";case 16:return"TXT";case 252:return"AXFR";case 251:return"IXFR";case 41:return"OPT";case 255:return"ANY"}return"UNKNOWN_"+r};ef.toType=function(r){switch(r.toUpperCase()){case"A":return 1;case"NULL":return 10;case"AAAA":return 28;case"AFSDB":return 18;case"APL":return 42;case"CAA":return 257;case"CDNSKEY":return 60;case"CDS":return 59;case"CERT":return 37;case"CNAME":return 5;case"DHCID":return 49;case"DLV":return 32769;case"DNAME":return 39;case"DNSKEY":return 48;case"DS":return 43;case"HIP":return 55;case"HINFO":return 13;case"IPSECKEY":return 45;case"KEY":return 25;case"KX":return 36;case"LOC":return 29;case"MX":return 15;case"NAPTR":return 35;case"NS":return 2;case"NSEC":return 47;case"NSEC3":return 50;case"NSEC3PARAM":return 51;case"PTR":return 12;case"RRSIG":return 46;case"RP":return 17;case"SIG":return 24;case"SOA":return 6;case"SPF":return 99;case"SRV":return 33;case"SSHFP":return 44;case"TA":return 32768;case"TKEY":return 249;case"TLSA":return 52;case"TSIG":return 250;case"TXT":return 16;case"AXFR":return 252;case"IXFR":return 251;case"OPT":return 41;case"ANY":return 255;case"*":return 255}return r.toUpperCase().startsWith("UNKNOWN_")?parseInt(r.slice(8)):0}});var kg=me(tf=>{"use strict";tf.toString=function(r){switch(r){case 0:return"NOERROR";case 1:return"FORMERR";case 2:return"SERVFAIL";case 3:return"NXDOMAIN";case 4:return"NOTIMP";case 5:return"REFUSED";case 6:return"YXDOMAIN";case 7:return"YXRRSET";case 8:return"NXRRSET";case 9:return"NOTAUTH";case 10:return"NOTZONE";case 11:return"RCODE_11";case 12:return"RCODE_12";case 13:return"RCODE_13";case 14:return"RCODE_14";case 15:return"RCODE_15"}return"RCODE_"+r};tf.toRcode=function(r){switch(r.toUpperCase()){case"NOERROR":return 0;case"FORMERR":return 1;case"SERVFAIL":return 2;case"NXDOMAIN":return 3;case"NOTIMP":return 4;case"REFUSED":return 5;case"YXDOMAIN":return 6;case"YXRRSET":return 7;case"NXRRSET":return 8;case"NOTAUTH":return 9;case"NOTZONE":return 10;case"RCODE_11":return 11;case"RCODE_12":return 12;case"RCODE_13":return 13;case"RCODE_14":return 14;case"RCODE_15":return 15}return 0}});var Rg=me(rf=>{"use strict";rf.toString=function(r){switch(r){case 0:return"QUERY";case 1:return"IQUERY";case 2:return"STATUS";case 3:return"OPCODE_3";case 4:return"NOTIFY";case 5:return"UPDATE";case 6:return"OPCODE_6";case 7:return"OPCODE_7";case 8:return"OPCODE_8";case 9:return"OPCODE_9";case 10:return"OPCODE_10";case 11:return"OPCODE_11";case 12:return"OPCODE_12";case 13:return"OPCODE_13";case 14:return"OPCODE_14";case 15:return"OPCODE_15"}return"OPCODE_"+r};rf.toOpcode=function(r){switch(r.toUpperCase()){case"QUERY":return 0;case"IQUERY":return 1;case"STATUS":return 2;case"OPCODE_3":return 3;case"NOTIFY":return 4;case"UPDATE":return 5;case"OPCODE_6":return 6;case"OPCODE_7":return 7;case"OPCODE_8":return 8;case"OPCODE_9":return 9;case"OPCODE_10":return 10;case"OPCODE_11":return 11;case"OPCODE_12":return 12;case"OPCODE_13":return 13;case"OPCODE_14":return 14;case"OPCODE_15":return 15}return 0}});var Tg=me(nf=>{"use strict";nf.toString=function(r){switch(r){case 1:return"IN";case 2:return"CS";case 3:return"CH";case 4:return"HS";case 255:return"ANY"}return"UNKNOWN_"+r};nf.toClass=function(r){switch(r.toUpperCase()){case"IN":return 1;case"CS":return 2;case"CH":return 3;case"HS":return 4;case"ANY":return 255}return 0}});var Cg=me(of=>{"use strict";of.toString=function(r){switch(r){case 1:return"LLQ";case 2:return"UL";case 3:return"NSID";case 5:return"DAU";case 6:return"DHU";case 7:return"N3U";case 8:return"CLIENT_SUBNET";case 9:return"EXPIRE";case 10:return"COOKIE";case 11:return"TCP_KEEPALIVE";case 12:return"PADDING";case 13:return"CHAIN";case 14:return"KEY_TAG";case 26946:return"DEVICEID"}return r<0?null:`OPTION_${r}`};of.toCode=function(r){if(typeof r=="number")return r;if(!r)return-1;switch(r.toUpperCase()){case"OPTION_0":return 0;case"LLQ":return 1;case"UL":return 2;case"NSID":return 3;case"OPTION_4":return 4;case"DAU":return 5;case"DHU":return 6;case"N3U":return 7;case"CLIENT_SUBNET":return 8;case"EXPIRE":return 9;case"COOKIE":return 10;case"TCP_KEEPALIVE":return 11;case"PADDING":return 12;case"CHAIN":return 13;case"KEY_TAG":return 14;case"DEVICEID":return 26946;case"OPTION_65535":return 65535}let e=r.match(/_(\d+)$/);return e?parseInt(e[1],10):-1}});var Lg=me((Ug,sf)=>{var Ng=function(r){"use strict";Object.defineProperty(r,"__esModule",{value:!0}),r.decode=h,r.encode=l,r.familyOf=u,r.name=void 0,r.sizeOf=c,r.v6=r.v4=void 0;let e=/^(\d{1,3}\.){3,3}\d{1,3}$/,t=4,n=/^(::)?(((\d{1,3}\.){3}(\d{1,3}){1})?([0-9a-f]){0,4}:{0,2}){1,8}(::)?$/i,i=16,o={name:"v4",size:t,isFormat:p=>e.test(p),encode(p,d,f){f=~~f,d=d||new Uint8Array(f+t);let m=p.length,y=0;for(let g=0;g<m;){let w=p.charCodeAt(g++);w===46?(d[f++]=y,y=0):y=y*10+(w-48)}return d[f]=y,d},decode(p,d){return d=~~d,`${p[d++]}.${p[d++]}.${p[d++]}.${p[d]}`}};r.v4=o;let s={name:"v6",size:i,isFormat:p=>p.length>0&&n.test(p),encode(p,d,f){f=~~f;let m=f+i,y=-1,g=0,w=0,x=!0,A=!1;d=d||new Uint8Array(f+i);for(let I=0;I<p.length;I++){let B=p.charCodeAt(I);B===58?(x?y!==-1?(f<m&&(d[f]=0),f<m-1&&(d[f+1]=0),f+=2):f<m&&(y=f):(A===!0?(f<m&&(d[f]=w),f++):(f<m&&(d[f]=g>>8),f<m-1&&(d[f+1]=g&255),f+=2),g=0,w=0),x=!0,A=!1):B===46?(f<m&&(d[f]=w),f++,w=0,g=0,x=!1,A=!0):(x=!1,B>=97?B-=87:B>=65?B-=55:(B-=48,w=w*10+B),g=(g<<4)+B)}if(x===!1)A===!0?(f<m&&(d[f]=w),f++):(f<m&&(d[f]=g>>8),f<m-1&&(d[f+1]=g&255),f+=2);else if(y===0)f<m&&(d[f]=0),f<m-1&&(d[f+1]=0),f+=2;else if(y!==-1){f+=2;for(let I=Math.min(f-1,m-1);I>=y+2;I--)d[I]=d[I-2];d[y]=0,d[y+1]=0,y=f}if(y!==f&&y!==-1)for(f>m-2&&(f=m-2);m>y;)d[--m]=f<m&&f>y?d[--f]:0;else for(;f<m;)d[f++]=0;return d},decode(p,d){d=~~d;let f="";for(let m=0;m<i;m+=2)m!==0&&(f+=":"),f+=(p[d+m]<<8|p[d+m+1]).toString(16);return f.replace(/(^|:)0(:0)*:0(:|$)/,"$1::$3").replace(/:{3,4}/,"::")}};r.v6=s;let a="ip";r.name=a;function c(p){if(o.isFormat(p))return o.size;if(s.isFormat(p))return s.size;throw Error(`Invalid ip address: ${p}`)}function u(p){return c(p)===o.size?1:2}function l(p,d,f){f=~~f;let m=c(p);return typeof d=="function"&&(d=d(f+m)),m===o.size?o.encode(p,d,f):s.encode(p,d,f)}function h(p,d,f){if(d=~~d,f=f||p.length-d,f===o.size)return o.decode(p,d,f);if(f===s.size)return s.decode(p,d,f);throw Error(`Invalid buffer size needs to be ${o.size} for v4 or ${s.size} for v6.`)}return"default"in r?r.default:r}({});typeof define=="function"&&define.amd?define([],function(){return Ng}):typeof sf=="object"&&typeof Ug=="object"&&(sf.exports=Ng)});var Og=me(q=>{"use strict";var G=Qd().Buffer,gn=_g(),C4=kg(),N4=Rg(),El=Tg(),af=Cg(),Si=Lg(),U4=0,Dg=32768,cf=32768,L4=~cf,Pg=32768,D4=~Pg,V=q.name={};V.encode=function(r,e,t,{mail:n=!1}={}){e||(e=G.alloc(V.encodingLength(r))),t||(t=0);let i=t,o=r.replace(/^\.|\.$/gm,"");if(o.length){let s=[];if(n){let a="";o.split(".").forEach(c=>{c.endsWith("\\")?a+=(a.length?".":"")+c.slice(0,-1):s.length===0&&a.length?s.push(a+"."+c):s.push(c)})}else s=o.split(".");for(let a=0;a<s.length;a++){let c=e.write(s[a],t+1);e[t]=c,t+=c+1}}return e[t++]=0,V.encode.bytes=t-i,e};V.encode.bytes=0;V.decode=function(r,e,{mail:t=!1}={}){e||(e=0);let n=[],i=e,o=0,s=0,a=!1;for(;;){if(e>=r.length)throw new Error("Cannot decode name (buffer overflow)");let c=r[e++];if(s+=a?0:1,c===0)break;if(c&192)if((c&192)===192){if(e+1>r.length)throw new Error("Cannot decode name (buffer overflow)");let u=r.readUInt16BE(e-1)-49152;if(u>=i)throw new Error("Cannot decode name (bad pointer)");e=u,i=u,s+=a?0:1,a=!0}else throw new Error("Cannot decode name (bad label)");else{if(e+c>r.length)throw new Error("Cannot decode name (buffer overflow)");if(o+=c+1,o>254)throw new Error("Cannot decode name (name too long)");let u=r.toString("utf-8",e,e+c);t&&(u=u.replace(/\./g,"\\.")),n.push(u),e+=c,s+=a?0:c}}return V.decode.bytes=s,n.length===0?".":n.join(".")};V.decode.bytes=0;V.encodingLength=function(r){return r==="."||r===".."?1:G.byteLength(r.replace(/^\.|\.$/gm,""))+2};var ee={};ee.encode=function(r,e,t){e||(e=G.alloc(ee.encodingLength(r))),t||(t=0);let n=e.write(r,t+1);return e[t]=n,ee.encode.bytes=n+1,e};ee.encode.bytes=0;ee.decode=function(r,e){e||(e=0);let t=r[e],n=r.toString("utf-8",e+1,e+1+t);return ee.decode.bytes=t+1,n};ee.decode.bytes=0;ee.encodingLength=function(r){return G.byteLength(r)+1};var sr={};sr.encode=function(r,e,t){e||(e=sr.encodingLength(r)),t||(t=0);let n=(r.flags||0)&32767,i=r.type==="response"?Dg:U4;return e.writeUInt16BE(r.id||0,t),e.writeUInt16BE(n|i,t+2),e.writeUInt16BE(r.questions.length,t+4),e.writeUInt16BE(r.answers.length,t+6),e.writeUInt16BE(r.authorities.length,t+8),e.writeUInt16BE(r.additionals.length,t+10),e};sr.encode.bytes=12;sr.decode=function(r,e){if(e||(e=0),r.length<12)throw new Error("Header must be 12 bytes");let t=r.readUInt16BE(e+2);return{id:r.readUInt16BE(e),type:t&Dg?"response":"query",flags:t&32767,flag_qr:(t>>15&1)===1,opcode:N4.toString(t>>11&15),flag_aa:(t>>10&1)===1,flag_tc:(t>>9&1)===1,flag_rd:(t>>8&1)===1,flag_ra:(t>>7&1)===1,flag_z:(t>>6&1)===1,flag_ad:(t>>5&1)===1,flag_cd:(t>>4&1)===1,rcode:C4.toString(t&15),questions:new Array(r.readUInt16BE(e+4)),answers:new Array(r.readUInt16BE(e+6)),authorities:new Array(r.readUInt16BE(e+8)),additionals:new Array(r.readUInt16BE(e+10))}};sr.decode.bytes=12;sr.encodingLength=function(){return 12};var cn=q.unknown={};cn.encode=function(r,e,t){return e||(e=G.alloc(cn.encodingLength(r))),t||(t=0),e.writeUInt16BE(r.length,t),r.copy(e,t+2),cn.encode.bytes=r.length+2,e};cn.encode.bytes=0;cn.decode=function(r,e){e||(e=0);let t=r.readUInt16BE(e),n=r.slice(e+2,e+2+t);return cn.decode.bytes=t+2,n};cn.decode.bytes=0;cn.encodingLength=function(r){return r.length+2};var ln=q.ns={};ln.encode=function(r,e,t){return e||(e=G.alloc(ln.encodingLength(r))),t||(t=0),V.encode(r,e,t+2),e.writeUInt16BE(V.encode.bytes,t),ln.encode.bytes=V.encode.bytes+2,e};ln.encode.bytes=0;ln.decode=function(r,e){e||(e=0);let t=r.readUInt16BE(e),n=V.decode(r,e+2);return ln.decode.bytes=t+2,n};ln.decode.bytes=0;ln.encodingLength=function(r){return V.encodingLength(r)+2};var un=q.soa={};un.encode=function(r,e,t){e||(e=G.alloc(un.encodingLength(r))),t||(t=0);let n=t;return t+=2,V.encode(r.mname,e,t),t+=V.encode.bytes,V.encode(r.rname,e,t,{mail:!0}),t+=V.encode.bytes,e.writeUInt32BE(r.serial||0,t),t+=4,e.writeUInt32BE(r.refresh||0,t),t+=4,e.writeUInt32BE(r.retry||0,t),t+=4,e.writeUInt32BE(r.expire||0,t),t+=4,e.writeUInt32BE(r.minimum||0,t),t+=4,e.writeUInt16BE(t-n-2,n),un.encode.bytes=t-n,e};un.encode.bytes=0;un.decode=function(r,e){e||(e=0);let t=e,n={};return e+=2,n.mname=V.decode(r,e),e+=V.decode.bytes,n.rname=V.decode(r,e,{mail:!0}),e+=V.decode.bytes,n.serial=r.readUInt32BE(e),e+=4,n.refresh=r.readUInt32BE(e),e+=4,n.retry=r.readUInt32BE(e),e+=4,n.expire=r.readUInt32BE(e),e+=4,n.minimum=r.readUInt32BE(e),e+=4,un.decode.bytes=e-t,n};un.decode.bytes=0;un.encodingLength=function(r){return 22+V.encodingLength(r.mname)+V.encodingLength(r.rname)};var hn=q.txt={};hn.encode=function(r,e,t){Array.isArray(r)||(r=[r]);for(let i=0;i<r.length;i++)if(typeof r[i]=="string"&&(r[i]=G.from(r[i])),!G.isBuffer(r[i]))throw new Error("Must be a Buffer");e||(e=G.alloc(hn.encodingLength(r))),t||(t=0);let n=t;return t+=2,r.forEach(function(i){e[t++]=i.length,i.copy(e,t,0,i.length),t+=i.length}),e.writeUInt16BE(t-n-2,n),hn.encode.bytes=t-n,e};hn.encode.bytes=0;hn.decode=function(r,e){e||(e=0);let t=e,n=r.readUInt16BE(e);e+=2;let i=[];for(;n>0;){let o=r[e++];if(--n,n<o)throw new Error("Buffer overflow");i.push(r.slice(e,e+o)),e+=o,n-=o}return hn.decode.bytes=e-t,i};hn.decode.bytes=0;hn.encodingLength=function(r){Array.isArray(r)||(r=[r]);let e=2;return r.forEach(function(t){typeof t=="string"?e+=G.byteLength(t)+1:e+=t.length+1}),e};var dn=q.null={};dn.encode=function(r,e,t){e||(e=G.alloc(dn.encodingLength(r))),t||(t=0),typeof r=="string"&&(r=G.from(r)),r||(r=G.alloc(0));let n=t;t+=2;let i=r.length;return r.copy(e,t,0,i),t+=i,e.writeUInt16BE(t-n-2,n),dn.encode.bytes=t-n,e};dn.encode.bytes=0;dn.decode=function(r,e){e||(e=0);let t=e,n=r.readUInt16BE(e);e+=2;let i=r.slice(e,e+n);return e+=n,dn.decode.bytes=e-t,i};dn.decode.bytes=0;dn.encodingLength=function(r){return r?(G.isBuffer(r)?r.length:G.byteLength(r))+2:2};var fn=q.hinfo={};fn.encode=function(r,e,t){e||(e=G.alloc(fn.encodingLength(r))),t||(t=0);let n=t;return t+=2,ee.encode(r.cpu,e,t),t+=ee.encode.bytes,ee.encode(r.os,e,t),t+=ee.encode.bytes,e.writeUInt16BE(t-n-2,n),fn.encode.bytes=t-n,e};fn.encode.bytes=0;fn.decode=function(r,e){e||(e=0);let t=e,n={};return e+=2,n.cpu=ee.decode(r,e),e+=ee.decode.bytes,n.os=ee.decode(r,e),e+=ee.decode.bytes,fn.decode.bytes=e-t,n};fn.decode.bytes=0;fn.encodingLength=function(r){return ee.encodingLength(r.cpu)+ee.encodingLength(r.os)+2};var ir=q.ptr={},P4=q.cname=ir,O4=q.dname=ir;ir.encode=function(r,e,t){return e||(e=G.alloc(ir.encodingLength(r))),t||(t=0),V.encode(r,e,t+2),e.writeUInt16BE(V.encode.bytes,t),ir.encode.bytes=V.encode.bytes+2,e};ir.encode.bytes=0;ir.decode=function(r,e){e||(e=0);let t=V.decode(r,e+2);return ir.decode.bytes=V.decode.bytes+2,t};ir.decode.bytes=0;ir.encodingLength=function(r){return V.encodingLength(r)+2};var pn=q.srv={};pn.encode=function(r,e,t){e||(e=G.alloc(pn.encodingLength(r))),t||(t=0),e.writeUInt16BE(r.priority||0,t+2),e.writeUInt16BE(r.weight||0,t+4),e.writeUInt16BE(r.port||0,t+6),V.encode(r.target,e,t+8);let n=V.encode.bytes+6;return e.writeUInt16BE(n,t),pn.encode.bytes=n+2,e};pn.encode.bytes=0;pn.decode=function(r,e){e||(e=0);let t=r.readUInt16BE(e),n={};return n.priority=r.readUInt16BE(e+2),n.weight=r.readUInt16BE(e+4),n.port=r.readUInt16BE(e+6),n.target=V.decode(r,e+8),pn.decode.bytes=t+2,n};pn.decode.bytes=0;pn.encodingLength=function(r){return 8+V.encodingLength(r.target)};var Tt=q.caa={};Tt.ISSUER_CRITICAL=128;Tt.encode=function(r,e,t){let n=Tt.encodingLength(r);return e||(e=G.alloc(Tt.encodingLength(r))),t||(t=0),r.issuerCritical&&(r.flags=Tt.ISSUER_CRITICAL),e.writeUInt16BE(n-2,t),t+=2,e.writeUInt8(r.flags||0,t),t+=1,ee.encode(r.tag,e,t),t+=ee.encode.bytes,e.write(r.value,t),t+=G.byteLength(r.value),Tt.encode.bytes=n,e};Tt.encode.bytes=0;Tt.decode=function(r,e){e||(e=0);let t=r.readUInt16BE(e);e+=2;let n=e,i={};return i.flags=r.readUInt8(e),e+=1,i.tag=ee.decode(r,e),e+=ee.decode.bytes,i.value=r.toString("utf-8",e,n+t),i.issuerCritical=!!(i.flags&Tt.ISSUER_CRITICAL),Tt.decode.bytes=t+2,i};Tt.decode.bytes=0;Tt.encodingLength=function(r){return ee.encodingLength(r.tag)+ee.encodingLength(r.value)+2};var Wn=q.mx={};Wn.encode=function(r,e,t){e||(e=G.alloc(Wn.encodingLength(r))),t||(t=0);let n=t;return t+=2,e.writeUInt16BE(r.preference||0,t),t+=2,V.encode(r.exchange,e,t),t+=V.encode.bytes,e.writeUInt16BE(t-n-2,n),Wn.encode.bytes=t-n,e};Wn.encode.bytes=0;Wn.decode=function(r,e){e||(e=0);let t=e,n={};return e+=2,n.preference=r.readUInt16BE(e),e+=2,n.exchange=V.decode(r,e),e+=V.decode.bytes,Wn.decode.bytes=e-t,n};Wn.encodingLength=function(r){return 4+V.encodingLength(r.exchange)};var mn=q.a={};mn.encode=function(r,e,t){return e||(e=G.alloc(mn.encodingLength(r))),t||(t=0),e.writeUInt16BE(4,t),t+=2,Si.v4.encode(r,e,t),mn.encode.bytes=6,e};mn.encode.bytes=0;mn.decode=function(r,e){e||(e=0),e+=2;let t=Si.v4.decode(r,e);return mn.decode.bytes=6,t};mn.decode.bytes=0;mn.encodingLength=function(){return 6};var yn=q.aaaa={};yn.encode=function(r,e,t){return e||(e=G.alloc(yn.encodingLength(r))),t||(t=0),e.writeUInt16BE(16,t),t+=2,Si.v6.encode(r,e,t),yn.encode.bytes=18,e};yn.encode.bytes=0;yn.decode=function(r,e){e||(e=0),e+=2;let t=Si.v6.decode(r,e);return yn.decode.bytes=18,t};yn.decode.bytes=0;yn.encodingLength=function(){return 18};var bt=q.option={};bt.encode=function(r,e,t){e||(e=G.alloc(bt.encodingLength(r))),t||(t=0);let n=t,i=af.toCode(r.code);if(e.writeUInt16BE(i,t),t+=2,r.data)e.writeUInt16BE(r.data.length,t),t+=2,r.data.copy(e,t),t+=r.data.length;else switch(i){case 8:let o=r.sourcePrefixLength||0,s=r.family||Si.familyOf(r.ip),a=Si.encode(r.ip,G.alloc),c=Math.ceil(o/8);e.writeUInt16BE(c+4,t),t+=2,e.writeUInt16BE(s,t),t+=2,e.writeUInt8(o,t++),e.writeUInt8(r.scopePrefixLength||0,t++),a.copy(e,t,0,c),t+=c;break;case 11:r.timeout?(e.writeUInt16BE(2,t),t+=2,e.writeUInt16BE(r.timeout,t),t+=2):(e.writeUInt16BE(0,t),t+=2);break;case 12:let u=r.length||0;e.writeUInt16BE(u,t),t+=2,e.fill(0,t,t+u),t+=u;break;case 14:let l=r.tags.length*2;e.writeUInt16BE(l,t),t+=2;for(let h of r.tags)e.writeUInt16BE(h,t),t+=2;break;default:throw new Error(`Unknown roption code: ${r.code}`)}return bt.encode.bytes=t-n,e};bt.encode.bytes=0;bt.decode=function(r,e){e||(e=0);let t={};t.code=r.readUInt16BE(e),t.type=af.toString(t.code),e+=2;let n=r.readUInt16BE(e);switch(e+=2,t.data=r.slice(e,e+n),t.code){case 8:t.family=r.readUInt16BE(e),e+=2,t.sourcePrefixLength=r.readUInt8(e++),t.scopePrefixLength=r.readUInt8(e++);let i=G.alloc(t.family===1?4:16);r.copy(i,0,e,e+n-4),t.ip=Si.decode(i);break;case 11:n>0&&(t.timeout=r.readUInt16BE(e),e+=2);break;case 14:t.tags=[];for(let o=0;o<n;o+=2)t.tags.push(r.readUInt16BE(e)),e+=2}return bt.decode.bytes=n+4,t};bt.decode.bytes=0;bt.encodingLength=function(r){if(r.data)return r.data.length+4;switch(af.toCode(r.code)){case 8:let t=r.sourcePrefixLength||0;return Math.ceil(t/8)+8;case 11:return typeof r.timeout=="number"?6:4;case 12:return r.length+4;case 14:return 4+r.tags.length*2}throw new Error(`Unknown roption code: ${r.code}`)};var Nt=q.opt={};Nt.encode=function(r,e,t){e||(e=G.alloc(Nt.encodingLength(r))),t||(t=0);let n=t,i=No(r,bt);return e.writeUInt16BE(i,t),t=$s(r,bt,e,t+2),Nt.encode.bytes=t-n,e};Nt.encode.bytes=0;Nt.decode=function(r,e){e||(e=0);let t=e,n=[],i=r.readUInt16BE(e);e+=2;let o=0;for(;i>0;)n[o++]=bt.decode(r,e),e+=bt.decode.bytes,i-=bt.decode.bytes;return Nt.decode.bytes=e-t,n};Nt.decode.bytes=0;Nt.encodingLength=function(r){return 2+No(r||[],bt)};var ut=q.dnskey={};ut.PROTOCOL_DNSSEC=3;ut.ZONE_KEY=128;ut.SECURE_ENTRYPOINT=32768;ut.encode=function(r,e,t){e||(e=G.alloc(ut.encodingLength(r))),t||(t=0);let n=t,i=r.key;if(!G.isBuffer(i))throw new Error("Key must be a Buffer");return t+=2,e.writeUInt16BE(r.flags,t),t+=2,e.writeUInt8(ut.PROTOCOL_DNSSEC,t),t+=1,e.writeUInt8(r.algorithm,t),t+=1,i.copy(e,t,0,i.length),t+=i.length,ut.encode.bytes=t-n,e.writeUInt16BE(ut.encode.bytes-2,n),e};ut.encode.bytes=0;ut.decode=function(r,e){e||(e=0);let t=e;var n={},i=r.readUInt16BE(e);if(e+=2,n.flags=r.readUInt16BE(e),e+=2,r.readUInt8(e)!==ut.PROTOCOL_DNSSEC)throw new Error("Protocol must be 3");return e+=1,n.algorithm=r.readUInt8(e),e+=1,n.key=r.slice(e,t+i+2),e+=n.key.length,ut.decode.bytes=e-t,n};ut.decode.bytes=0;ut.encodingLength=function(r){return 6+G.byteLength(r.key)};var Br=q.rrsig={};Br.encode=function(r,e,t){e||(e=G.alloc(Br.encodingLength(r))),t||(t=0);let n=t,i=r.signature;if(!G.isBuffer(i))throw new Error("Signature must be a Buffer");return t+=2,e.writeUInt16BE(gn.toType(r.typeCovered),t),t+=2,e.writeUInt8(r.algorithm,t),t+=1,e.writeUInt8(r.labels,t),t+=1,e.writeUInt32BE(r.originalTTL,t),t+=4,e.writeUInt32BE(r.expiration,t),t+=4,e.writeUInt32BE(r.inception,t),t+=4,e.writeUInt16BE(r.keyTag,t),t+=2,V.encode(r.signersName,e,t),t+=V.encode.bytes,i.copy(e,t,0,i.length),t+=i.length,Br.encode.bytes=t-n,e.writeUInt16BE(Br.encode.bytes-2,n),e};Br.encode.bytes=0;Br.decode=function(r,e){e||(e=0);let t=e;var n={},i=r.readUInt16BE(e);return e+=2,n.typeCovered=gn.toString(r.readUInt16BE(e)),e+=2,n.algorithm=r.readUInt8(e),e+=1,n.labels=r.readUInt8(e),e+=1,n.originalTTL=r.readUInt32BE(e),e+=4,n.expiration=r.readUInt32BE(e),e+=4,n.inception=r.readUInt32BE(e),e+=4,n.keyTag=r.readUInt16BE(e),e+=2,n.signersName=V.decode(r,e),e+=V.decode.bytes,n.signature=r.slice(e,t+i+2),e+=n.signature.length,Br.decode.bytes=e-t,n};Br.decode.bytes=0;Br.encodingLength=function(r){return 20+V.encodingLength(r.signersName)+G.byteLength(r.signature)};var Ar=q.rp={};Ar.encode=function(r,e,t){e||(e=G.alloc(Ar.encodingLength(r))),t||(t=0);let n=t;return t+=2,V.encode(r.mbox||".",e,t,{mail:!0}),t+=V.encode.bytes,V.encode(r.txt||".",e,t),t+=V.encode.bytes,Ar.encode.bytes=t-n,e.writeUInt16BE(Ar.encode.bytes-2,n),e};Ar.encode.bytes=0;Ar.decode=function(r,e){e||(e=0);let t=e,n={};return e+=2,n.mbox=V.decode(r,e,{mail:!0})||".",e+=V.decode.bytes,n.txt=V.decode(r,e)||".",e+=V.decode.bytes,Ar.decode.bytes=e-t,n};Ar.decode.bytes=0;Ar.encodingLength=function(r){return 2+V.encodingLength(r.mbox||".")+V.encodingLength(r.txt||".")};var $e={};$e.encode=function(r,e,t){e||(e=G.alloc($e.encodingLength(r))),t||(t=0);let n=t;for(var i=[],o=0;o<r.length;o++){var s=gn.toType(r[o]);i[s>>8]===void 0&&(i[s>>8]=[]),i[s>>8][s>>3&31]|=1<<7-(s&7)}for(o=0;o<i.length;o++)if(i[o]!==void 0){var a=G.from(i[o]);e.writeUInt8(o,t),t+=1,e.writeUInt8(a.length,t),t+=1,a.copy(e,t),t+=a.length}return $e.encode.bytes=t-n,e};$e.encode.bytes=0;$e.decode=function(r,e,t){e||(e=0);let n=e;for(var i=[];e-n<t;){var o=r.readUInt8(e);e+=1;var s=r.readUInt8(e);e+=1;for(var a=0;a<s;a++)for(var c=r.readUInt8(e+a),u=0;u<8;u++)if(c&1<<7-u){var l=gn.toString(o<<8|a<<3|u);i.push(l)}e+=s}return $e.decode.bytes=e-n,i};$e.decode.bytes=0;$e.encodingLength=function(r){for(var e=[],t=0;t<r.length;t++){var n=gn.toType(r[t]);e[n>>8]=Math.max(e[n>>8]||0,n&255)}var i=0;for(t=0;t<e.length;t++)e[t]!==void 0&&(i+=2+Math.ceil((e[t]+1)/8));return i};var Ir=q.nsec={};Ir.encode=function(r,e,t){e||(e=G.alloc(Ir.encodingLength(r))),t||(t=0);let n=t;return t+=2,V.encode(r.nextDomain,e,t),t+=V.encode.bytes,$e.encode(r.rrtypes,e,t),t+=$e.encode.bytes,Ir.encode.bytes=t-n,e.writeUInt16BE(Ir.encode.bytes-2,n),e};Ir.encode.bytes=0;Ir.decode=function(r,e){e||(e=0);let t=e;var n={},i=r.readUInt16BE(e);return e+=2,n.nextDomain=V.decode(r,e),e+=V.decode.bytes,n.rrtypes=$e.decode(r,e,i-(e-t)),e+=$e.decode.bytes,Ir.decode.bytes=e-t,n};Ir.decode.bytes=0;Ir.encodingLength=function(r){return 2+V.encodingLength(r.nextDomain)+$e.encodingLength(r.rrtypes)};var Sr=q.nsec3={};Sr.encode=function(r,e,t){e||(e=G.alloc(Sr.encodingLength(r))),t||(t=0);let n=t,i=r.salt;if(!G.isBuffer(i))throw new Error("salt must be a Buffer");let o=r.nextDomain;if(!G.isBuffer(o))throw new Error("nextDomain must be a Buffer");return t+=2,e.writeUInt8(r.algorithm,t),t+=1,e.writeUInt8(r.flags,t),t+=1,e.writeUInt16BE(r.iterations,t),t+=2,e.writeUInt8(i.length,t),t+=1,i.copy(e,t,0,i.length),t+=i.length,e.writeUInt8(o.length,t),t+=1,o.copy(e,t,0,o.length),t+=o.length,$e.encode(r.rrtypes,e,t),t+=$e.encode.bytes,Sr.encode.bytes=t-n,e.writeUInt16BE(Sr.encode.bytes-2,n),e};Sr.encode.bytes=0;Sr.decode=function(r,e){e||(e=0);let t=e;var n={},i=r.readUInt16BE(e);e+=2,n.algorithm=r.readUInt8(e),e+=1,n.flags=r.readUInt8(e),e+=1,n.iterations=r.readUInt16BE(e),e+=2;let o=r.readUInt8(e);e+=1,n.salt=r.slice(e,e+o),e+=o;let s=r.readUInt8(e);return e+=1,n.nextDomain=r.slice(e,e+s),e+=s,n.rrtypes=$e.decode(r,e,i-(e-t)),e+=$e.decode.bytes,Sr.decode.bytes=e-t,n};Sr.decode.bytes=0;Sr.encodingLength=function(r){return 8+r.salt.length+r.nextDomain.length+$e.encodingLength(r.rrtypes)};var _r=q.ds={};_r.encode=function(r,e,t){e||(e=G.alloc(_r.encodingLength(r))),t||(t=0);let n=t,i=r.digest;if(!G.isBuffer(i))throw new Error("Digest must be a Buffer");return t+=2,e.writeUInt16BE(r.keyTag,t),t+=2,e.writeUInt8(r.algorithm,t),t+=1,e.writeUInt8(r.digestType,t),t+=1,i.copy(e,t,0,i.length),t+=i.length,_r.encode.bytes=t-n,e.writeUInt16BE(_r.encode.bytes-2,n),e};_r.encode.bytes=0;_r.decode=function(r,e){e||(e=0);let t=e;var n={},i=r.readUInt16BE(e);return e+=2,n.keyTag=r.readUInt16BE(e),e+=2,n.algorithm=r.readUInt8(e),e+=1,n.digestType=r.readUInt8(e),e+=1,n.digest=r.slice(e,t+i+2),e+=n.digest.length,_r.decode.bytes=e-t,n};_r.decode.bytes=0;_r.encodingLength=function(r){return 6+G.byteLength(r.digest)};var Ct=q.sshfp={};Ct.getFingerprintLengthForHashType=function(e){switch(e){case 1:return 20;case 2:return 32}};Ct.encode=function(e,t,n){t||(t=G.alloc(Ct.encodingLength(e))),n||(n=0);let i=n;n+=2,t[n]=e.algorithm,n+=1,t[n]=e.hash,n+=1;let o=G.from(e.fingerprint.toUpperCase(),"hex");if(o.length!==Ct.getFingerprintLengthForHashType(e.hash))throw new Error("Invalid fingerprint length");return o.copy(t,n),n+=o.byteLength,Ct.encode.bytes=n-i,t.writeUInt16BE(Ct.encode.bytes-2,i),t};Ct.encode.bytes=0;Ct.decode=function(e,t){t||(t=0);let n=t,i={};t+=2,i.algorithm=e[t],t+=1,i.hash=e[t],t+=1;let o=Ct.getFingerprintLengthForHashType(i.hash);return i.fingerprint=e.slice(t,t+o).toString("hex").toUpperCase(),t+=o,Ct.decode.bytes=t-n,i};Ct.decode.bytes=0;Ct.encodingLength=function(r){return 4+G.from(r.fingerprint,"hex").byteLength};var kr=q.naptr={};kr.encode=function(r,e,t){e||(e=G.alloc(kr.encodingLength(r))),t||(t=0);let n=t;return t+=2,e.writeUInt16BE(r.order||0,t),t+=2,e.writeUInt16BE(r.preference||0,t),t+=2,ee.encode(r.flags,e,t),t+=ee.encode.bytes,ee.encode(r.services,e,t),t+=ee.encode.bytes,ee.encode(r.regexp,e,t),t+=ee.encode.bytes,V.encode(r.replacement,e,t),t+=V.encode.bytes,kr.encode.bytes=t-n,e.writeUInt16BE(kr.encode.bytes-2,n),e};kr.encode.bytes=0;kr.decode=function(r,e){e||(e=0);let t=e,n={};return e+=2,n.order=r.readUInt16BE(e),e+=2,n.preference=r.readUInt16BE(e),e+=2,n.flags=ee.decode(r,e),e+=ee.decode.bytes,n.services=ee.decode(r,e),e+=ee.decode.bytes,n.regexp=ee.decode(r,e),e+=ee.decode.bytes,n.replacement=V.decode(r,e),e+=V.decode.bytes,kr.decode.bytes=e-t,n};kr.decode.bytes=0;kr.encodingLength=function(r){return ee.encodingLength(r.flags)+ee.encodingLength(r.services)+ee.encodingLength(r.regexp)+V.encodingLength(r.replacement)+6};var Rr=q.tlsa={};Rr.encode=function(r,e,t){e||(e=G.alloc(Rr.encodingLength(r))),t||(t=0);let n=t,i=r.certificate;if(!G.isBuffer(i))throw new Error("Certificate must be a Buffer");return t+=2,e.writeUInt8(r.usage,t),t+=1,e.writeUInt8(r.selector,t),t+=1,e.writeUInt8(r.matchingType,t),t+=1,i.copy(e,t,0,i.length),t+=i.length,Rr.encode.bytes=t-n,e.writeUInt16BE(Rr.encode.bytes-2,n),e};Rr.encode.bytes=0;Rr.decode=function(r,e){e||(e=0);let t=e,n={},i=r.readUInt16BE(e);return e+=2,n.usage=r.readUInt8(e),e+=1,n.selector=r.readUInt8(e),e+=1,n.matchingType=r.readUInt8(e),e+=1,n.certificate=r.slice(e,t+i+2),e+=n.certificate.length,Rr.decode.bytes=e-t,n};Rr.decode.bytes=0;Rr.encodingLength=function(r){return 5+G.byteLength(r.certificate)};var lf=q.record=function(r){switch(r.toUpperCase()){case"A":return mn;case"PTR":return ir;case"CNAME":return P4;case"DNAME":return O4;case"TXT":return hn;case"NULL":return dn;case"AAAA":return yn;case"SRV":return pn;case"HINFO":return fn;case"CAA":return Tt;case"NS":return ln;case"SOA":return un;case"MX":return Wn;case"OPT":return Nt;case"DNSKEY":return ut;case"RRSIG":return Br;case"RP":return Ar;case"NSEC":return Ir;case"NSEC3":return Sr;case"SSHFP":return Ct;case"DS":return _r;case"NAPTR":return kr;case"TLSA":return Rr}return cn},Ye=q.answer={};Ye.encode=function(r,e,t){e||(e=G.alloc(Ye.encodingLength(r))),t||(t=0);let n=t;if(V.encode(r.name,e,t),t+=V.encode.bytes,e.writeUInt16BE(gn.toType(r.type),t),r.type.toUpperCase()==="OPT"){if(r.name!==".")throw new Error("OPT name must be root.");e.writeUInt16BE(r.udpPayloadSize||4096,t+2),e.writeUInt8(r.extendedRcode||0,t+4),e.writeUInt8(r.ednsVersion||0,t+5),e.writeUInt16BE(r.flags||0,t+6),t+=8,Nt.encode(r.options||[],e,t),t+=Nt.encode.bytes}else{let i=El.toClass(r.class===void 0?"IN":r.class);r.flush&&(i|=cf),e.writeUInt16BE(i,t+2),e.writeUInt32BE(r.ttl||0,t+4),t+=8;let o=lf(r.type);o.encode(r.data,e,t),t+=o.encode.bytes}return Ye.encode.bytes=t-n,e};Ye.encode.bytes=0;Ye.decode=function(r,e){e||(e=0);let t={},n=e;if(t.name=V.decode(r,e),e+=V.decode.bytes,t.type=gn.toString(r.readUInt16BE(e)),t.type==="OPT")t.udpPayloadSize=r.readUInt16BE(e+2),t.extendedRcode=r.readUInt8(e+4),t.ednsVersion=r.readUInt8(e+5),t.flags=r.readUInt16BE(e+6),t.flag_do=(t.flags>>15&1)===1,t.options=Nt.decode(r,e+8),e+=8+Nt.decode.bytes;else{let i=r.readUInt16BE(e+2);t.ttl=r.readUInt32BE(e+4),t.class=El.toString(i&L4),t.flush=!!(i&cf);let o=lf(t.type);t.data=o.decode(r,e+8),e+=8+o.decode.bytes}return Ye.decode.bytes=e-n,t};Ye.decode.bytes=0;Ye.encodingLength=function(r){let e=r.data!==null&&r.data!==void 0?r.data:r.options;return V.encodingLength(r.name)+8+lf(r.type).encodingLength(e)};var or=q.question={};or.encode=function(r,e,t){e||(e=G.alloc(or.encodingLength(r))),t||(t=0);let n=t;return V.encode(r.name,e,t),t+=V.encode.bytes,e.writeUInt16BE(gn.toType(r.type),t),t+=2,e.writeUInt16BE(El.toClass(r.class===void 0?"IN":r.class),t),t+=2,or.encode.bytes=t-n,r};or.encode.bytes=0;or.decode=function(r,e){e||(e=0);let t=e,n={};return n.name=V.decode(r,e),e+=V.decode.bytes,n.type=gn.toString(r.readUInt16BE(e)),e+=2,n.class=El.toString(r.readUInt16BE(e)),e+=2,!!(n.class&Pg)&&(n.class&=D4),or.decode.bytes=e-t,n};or.decode.bytes=0;or.encodingLength=function(r){return V.encodingLength(r.name)+4};q.AUTHORITATIVE_ANSWER=1024;q.TRUNCATED_RESPONSE=512;q.RECURSION_DESIRED=256;q.RECURSION_AVAILABLE=128;q.AUTHENTIC_DATA=32;q.CHECKING_DISABLED=16;q.DNSSEC_OK=32768;q.encode=function(r,e,t){let n=!e;n&&(e=G.alloc(q.encodingLength(r))),t||(t=0);let i=t;return r.questions||(r.questions=[]),r.answers||(r.answers=[]),r.authorities||(r.authorities=[]),r.additionals||(r.additionals=[]),sr.encode(r,e,t),t+=sr.encode.bytes,t=$s(r.questions,or,e,t),t=$s(r.answers,Ye,e,t),t=$s(r.authorities,Ye,e,t),t=$s(r.additionals,Ye,e,t),q.encode.bytes=t-i,n&&q.encode.bytes!==e.length?e.slice(0,q.encode.bytes):e};q.encode.bytes=0;q.decode=function(r,e){e||(e=0);let t=e,n=sr.decode(r,e);return e+=sr.decode.bytes,e=bl(n.questions,or,r,e),e=bl(n.answers,Ye,r,e),e=bl(n.authorities,Ye,r,e),e=bl(n.additionals,Ye,r,e),q.decode.bytes=e-t,n};q.decode.bytes=0;q.encodingLength=function(r){return sr.encodingLength(r)+No(r.questions||[],or)+No(r.answers||[],Ye)+No(r.authorities||[],Ye)+No(r.additionals||[],Ye)};q.streamEncode=function(r){let e=q.encode(r),t=G.alloc(2);t.writeUInt16BE(e.byteLength);let n=G.concat([t,e]);return q.streamEncode.bytes=n.byteLength,n};q.streamEncode.bytes=0;q.streamDecode=function(r){let e=r.readUInt16BE(0);if(r.byteLength<e+2)return null;let t=q.decode(r.slice(2));return q.streamDecode.bytes=q.decode.bytes,t};q.streamDecode.bytes=0;function No(r,e){let t=0;for(let n=0;n<r.length;n++)t+=e.encodingLength(r[n]);return t}function $s(r,e,t,n){for(let i=0;i<r.length;i++)e.encode(r[i],t,n),n+=e.encode.bytes;return n}function bl(r,e,t,n){for(let i=0;i<r.length;i++)r[i]=e.decode(t,n),n+=e.decode.bytes;return n}});var Wg=me((Ys,Al)=>{(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 f=0;f<d.length;f++)if(!Number.isInteger(d[f])||d[f]<0||d[f]>255)return!1;return!0}function i(d,f){return(d&65535)*f+(((d>>>16)*f&65535)<<16)}function o(d,f){return d<<f|d>>>32-f}function s(d){return d^=d>>>16,d=i(d,2246822507),d^=d>>>13,d=i(d,3266489909),d^=d>>>16,d}function a(d,f){d=[d[0]>>>16,d[0]&65535,d[1]>>>16,d[1]&65535],f=[f[0]>>>16,f[0]&65535,f[1]>>>16,f[1]&65535];var m=[0,0,0,0];return m[3]+=d[3]+f[3],m[2]+=m[3]>>>16,m[3]&=65535,m[2]+=d[2]+f[2],m[1]+=m[2]>>>16,m[2]&=65535,m[1]+=d[1]+f[1],m[0]+=m[1]>>>16,m[1]&=65535,m[0]+=d[0]+f[0],m[0]&=65535,[m[0]<<16|m[1],m[2]<<16|m[3]]}function c(d,f){d=[d[0]>>>16,d[0]&65535,d[1]>>>16,d[1]&65535],f=[f[0]>>>16,f[0]&65535,f[1]>>>16,f[1]&65535];var m=[0,0,0,0];return m[3]+=d[3]*f[3],m[2]+=m[3]>>>16,m[3]&=65535,m[2]+=d[2]*f[3],m[1]+=m[2]>>>16,m[2]&=65535,m[2]+=d[3]*f[2],m[1]+=m[2]>>>16,m[2]&=65535,m[1]+=d[1]*f[3],m[0]+=m[1]>>>16,m[1]&=65535,m[1]+=d[2]*f[2],m[0]+=m[1]>>>16,m[1]&=65535,m[1]+=d[3]*f[1],m[0]+=m[1]>>>16,m[1]&=65535,m[0]+=d[0]*f[3]+d[1]*f[2]+d[2]*f[1]+d[3]*f[0],m[0]&=65535,[m[0]<<16|m[1],m[2]<<16|m[3]]}function u(d,f){return f%=64,f===32?[d[1],d[0]]:f<32?[d[0]<<f|d[1]>>>32-f,d[1]<<f|d[0]>>>32-f]:(f-=32,[d[1]<<f|d[0]>>>32-f,d[0]<<f|d[1]>>>32-f])}function l(d,f){return f%=64,f===0?d:f<32?[d[0]<<f|d[1]>>>32-f,d[1]<<f]:[d[1]<<f-32,0]}function h(d,f){return[d[0]^f[0],d[1]^f[1]]}function p(d){return d=h(d,[0,d[0]>>>1]),d=c(d,[4283543511,3981806797]),d=h(d,[0,d[0]>>>1]),d=c(d,[3301882366,444984403]),d=h(d,[0,d[0]>>>1]),d}t.x86.hash32=function(d,f){if(t.inputValidation&&!n(d))return e;f=f||0;for(var m=d.length%4,y=d.length-m,g=f,w=0,x=3432918353,A=461845907,I=0;I<y;I=I+4)w=d[I]|d[I+1]<<8|d[I+2]<<16|d[I+3]<<24,w=i(w,x),w=o(w,15),w=i(w,A),g^=w,g=o(g,13),g=i(g,5)+3864292196;switch(w=0,m){case 3:w^=d[I+2]<<16;case 2:w^=d[I+1]<<8;case 1:w^=d[I],w=i(w,x),w=o(w,15),w=i(w,A),g^=w}return g^=d.length,g=s(g),g>>>0},t.x86.hash128=function(d,f){if(t.inputValidation&&!n(d))return e;f=f||0;for(var m=d.length%16,y=d.length-m,g=f,w=f,x=f,A=f,I=0,B=0,v=0,E=0,R=597399067,N=2869860233,T=951274213,M=2716044179,D=0;D<y;D=D+16)I=d[D]|d[D+1]<<8|d[D+2]<<16|d[D+3]<<24,B=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,I=i(I,R),I=o(I,15),I=i(I,N),g^=I,g=o(g,19),g+=w,g=i(g,5)+1444728091,B=i(B,N),B=o(B,16),B=i(B,T),w^=B,w=o(w,17),w+=x,w=i(w,5)+197830471,v=i(v,T),v=o(v,17),v=i(v,M),x^=v,x=o(x,15),x+=A,x=i(x,5)+2530024501,E=i(E,M),E=o(E,18),E=i(E,R),A^=E,A=o(A,13),A+=g,A=i(A,5)+850148119;switch(I=0,B=0,v=0,E=0,m){case 15:E^=d[D+14]<<16;case 14:E^=d[D+13]<<8;case 13:E^=d[D+12],E=i(E,M),E=o(E,18),E=i(E,R),A^=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=i(v,T),v=o(v,17),v=i(v,M),x^=v;case 8:B^=d[D+7]<<24;case 7:B^=d[D+6]<<16;case 6:B^=d[D+5]<<8;case 5:B^=d[D+4],B=i(B,N),B=o(B,16),B=i(B,T),w^=B;case 4:I^=d[D+3]<<24;case 3:I^=d[D+2]<<16;case 2:I^=d[D+1]<<8;case 1:I^=d[D],I=i(I,R),I=o(I,15),I=i(I,N),g^=I}return g^=d.length,w^=d.length,x^=d.length,A^=d.length,g+=w,g+=x,g+=A,w+=g,x+=g,A+=g,g=s(g),w=s(w),x=s(x),A=s(A),g+=w,g+=x,g+=A,w+=g,x+=g,A+=g,("00000000"+(g>>>0).toString(16)).slice(-8)+("00000000"+(w>>>0).toString(16)).slice(-8)+("00000000"+(x>>>0).toString(16)).slice(-8)+("00000000"+(A>>>0).toString(16)).slice(-8)},t.x64.hash128=function(d,f){if(t.inputValidation&&!n(d))return e;f=f||0;for(var m=d.length%16,y=d.length-m,g=[0,f],w=[0,f],x=[0,0],A=[0,0],I=[2277735313,289559509],B=[1291169091,658871167],v=0;v<y;v=v+16)x=[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],A=[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],x=c(x,I),x=u(x,31),x=c(x,B),g=h(g,x),g=u(g,27),g=a(g,w),g=a(c(g,[0,5]),[0,1390208809]),A=c(A,B),A=u(A,33),A=c(A,I),w=h(w,A),w=u(w,31),w=a(w,g),w=a(c(w,[0,5]),[0,944331445]);switch(x=[0,0],A=[0,0],m){case 15:A=h(A,l([0,d[v+14]],48));case 14:A=h(A,l([0,d[v+13]],40));case 13:A=h(A,l([0,d[v+12]],32));case 12:A=h(A,l([0,d[v+11]],24));case 11:A=h(A,l([0,d[v+10]],16));case 10:A=h(A,l([0,d[v+9]],8));case 9:A=h(A,[0,d[v+8]]),A=c(A,B),A=u(A,33),A=c(A,I),w=h(w,A);case 8:x=h(x,l([0,d[v+7]],56));case 7:x=h(x,l([0,d[v+6]],48));case 6:x=h(x,l([0,d[v+5]],40));case 5:x=h(x,l([0,d[v+4]],32));case 4:x=h(x,l([0,d[v+3]],24));case 3:x=h(x,l([0,d[v+2]],16));case 2:x=h(x,l([0,d[v+1]],8));case 1:x=h(x,[0,d[v]]),x=c(x,I),x=u(x,31),x=c(x,B),g=h(g,x)}return g=h(g,[0,d.length]),w=h(w,[0,d.length]),g=a(g,w),w=a(w,g),g=p(g),w=p(w),g=a(g,w),w=a(w,g),("00000000"+(g[0]>>>0).toString(16)).slice(-8)+("00000000"+(g[1]>>>0).toString(16)).slice(-8)+("00000000"+(w[0]>>>0).toString(16)).slice(-8)+("00000000"+(w[1]>>>0).toString(16)).slice(-8)},typeof Ys<"u"?(typeof Al<"u"&&Al.exports&&(Ys=Al.exports=t),Ys.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)})(Ys)});var Xg=me((x7,Yg)=>{Yg.exports=Wg()});var Sl=me((S7,Jg)=>{"use strict";Jg.exports=class{constructor(){this._bitArrays=[],this._data=[],this._length=0,this._changedLength=!1,this._changedData=!1}set(e,t){let n=this._internalPositionFor(e,!1);if(t===void 0)n!==-1&&(this._unsetInternalPos(n),this._unsetBit(e),this._changedLength=!0,this._changedData=!0);else{let i=!1;n===-1?(n=this._data.length,this._setBit(e),this._changedData=!0):i=!0,this._setInternalPos(n,e,t,i),this._changedLength=!0}}unset(e){this.set(e,void 0)}get(e){this._sortData();let t=this._internalPositionFor(e,!0);if(t!==-1)return this._data[t][1]}push(e){return this.set(this.length,e),this.length}get length(){if(this._sortData(),this._changedLength){let e=this._data[this._data.length-1];this._length=e?e[0]+1:0,this._changedLength=!1}return this._length}forEach(e){let t=0;for(;t<this.length;)e(this.get(t),t,this),t++}map(e){let t=0,n=new Array(this.length);for(;t<this.length;)n[t]=e(this.get(t),t,this),t++;return n}reduce(e,t){let n=0,i=t;for(;n<this.length;){let o=this.get(n);i=e(i,o,n),n++}return i}find(e){let t=0,n,i;for(;t<this.length&&!n;)i=this.get(t),n=e(i),t++;return n?i:void 0}_internalPositionFor(e,t){let n=this._bytePosFor(e,t);if(n>=this._bitArrays.length)return-1;let i=this._bitArrays[n],o=e-n*7;if(!((i&1<<o)>0))return-1;let a=this._bitArrays.slice(0,n).reduce(Q4,0),c=~(4294967295<<o+1),u=Zg(i&c);return a+u-1}_bytePosFor(e,t){let n=Math.floor(e/7),i=n+1;for(;!t&&this._bitArrays.length<i;)this._bitArrays.push(0);return n}_setBit(e){let t=this._bytePosFor(e,!1);this._bitArrays[t]|=1<<e-t*7}_unsetBit(e){let t=this._bytePosFor(e,!1);this._bitArrays[t]&=~(1<<e-t*7)}_setInternalPos(e,t,n,i){let o=this._data,s=[t,n];if(i)this._sortData(),o[e]=s;else{if(o.length)if(o[o.length-1][0]>=t)o.push(s);else if(o[0][0]<=t)o.unshift(s);else{let a=Math.round(o.length/2);this._data=o.slice(0,a).concat(s).concat(o.slice(a))}else this._data.push(s);this._changedData=!0,this._changedLength=!0}}_unsetInternalPos(e){this._data.splice(e,1)}_sortData(){this._changedData&&this._data.sort(eB),this._changedData=!1}bitField(){let e=[],t=8,n=0,i=0,o,s=this._bitArrays.slice();for(;s.length||n;){n===0&&(o=s.shift(),n=7);let c=Math.min(n,t),u=~(255<<c),l=o&u;i|=l<<8-t,o=o>>>c,n-=c,t-=c,(!t||!n&&!s.length)&&(e.push(i),i=0,t=8)}for(var a=e.length-1;a>0&&e[a]===0;a--)e.pop();return e}compactArray(){return this._sortData(),this._data.map(tB)}};function Q4(r,e){return r+Zg(e)}function Zg(r){let e=r;return e=e-(e>>1&1431655765),e=(e&858993459)+(e>>2&858993459),(e+(e>>4)&252645135)*16843009>>24}function eB(r,e){return r[0]-e[0]}function tB(r){return r[1]}});var fw=me((aO,dw)=>{var gf=class{constructor(e,t=12,n=8*1024,i=32*1024,o=64,s){this.bits=t,this.min=n,this.max=i,this.asModule=e,this.rabin=new e.Rabin(t,n,i,o,s),this.polynomial=s}fingerprint(e){let{__retain:t,__release:n,__allocArray:i,__getInt32Array:o,Int32Array_ID:s,Uint8Array_ID:a}=this.asModule,c=new Int32Array(Math.ceil(e.length/this.min)),u=t(i(s,c)),l=t(i(a,e)),h=this.rabin.fingerprint(l,u),p=o(h);n(l),n(u);let d=p.indexOf(0);return d>=0?p.subarray(0,d):p}};dw.exports=gf});var xw=me(Js=>{"use strict";var pB=typeof BigUint64Array<"u",Xs=Symbol(),Zs=1024;function pw(r,e){let t=new Uint32Array(r),n=new Uint16Array(r);var i=t[e+-4>>>2]>>>1,o=e>>>1;if(i<=Zs)return String.fromCharCode.apply(String,n.subarray(o,o+i));let s=[];do{let a=n[o+Zs-1],c=a>=55296&&a<56320?Zs-1:Zs;s.push(String.fromCharCode.apply(String,n.subarray(o,o+=c))),i-=c}while(i>Zs);return s.join("")+String.fromCharCode.apply(String,n.subarray(o,o+i))}function wf(r){let e={};function t(i,o){return i?pw(i.buffer,o):"<yet unknown>"}let n=r.env=r.env||{};return n.abort=n.abort||function(o,s,a,c){let u=e.memory||n.memory;throw Error("abort: "+t(u,o)+" at "+t(u,s)+":"+a+":"+c)},n.trace=n.trace||function(o,s){let a=e.memory||n.memory;console.log("trace: "+t(a,o)+(s?" ":"")+Array.prototype.slice.call(arguments,2,2+s).join(", "))},r.Math=r.Math||Math,r.Date=r.Date||Date,e}function xf(r,e){let t=e.exports,n=t.memory,i=t.table,o=t.__alloc,s=t.__retain,a=t.__rtti_base||-1;function c(B){let v=new Uint32Array(n.buffer),E=v[a>>>2];if((B>>>=0)>=E)throw Error("invalid id: "+B);return v[(a+4>>>2)+B*2]}function u(B){let v=new Uint32Array(n.buffer),E=v[a>>>2];if((B>>>=0)>=E)throw Error("invalid id: "+B);return v[(a+4>>>2)+B*2+1]}function l(B){return 31-Math.clz32(B>>>5&31)}function h(B){return 31-Math.clz32(B>>>14&31)}function p(B){let v=B.length,E=o(v<<1,1),R=new Uint16Array(n.buffer);for(var N=0,T=E>>>1;N<v;++N)R[T+N]=B.charCodeAt(N);return E}r.__allocString=p;function d(B){let v=n.buffer;if(new Uint32Array(v)[B+-8>>>2]!==1)throw Error("not a string: "+B);return pw(v,B)}r.__getString=d;function f(B,v,E){let R=n.buffer;if(E)switch(B){case 2:return new Float32Array(R);case 3:return new Float64Array(R)}else switch(B){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: "+B)}function m(B,v){let E=c(B);if(!(E&3))throw Error("not an array: "+B+" @ "+E);let R=l(E),N=v.length,T=o(N<<R,0),M=o(E&2?16:12,B),D=new Uint32Array(n.buffer);D[M+0>>>2]=s(T),D[M+4>>>2]=T,D[M+8>>>2]=N<<R,E&2&&(D[M+12>>>2]=N);let ne=f(R,E&1024,E&2048);if(E&8192)for(let _=0;_<N;++_)ne[(T>>>R)+_]=s(v[_]);else ne.set(v,T>>>R);return M}r.__allocArray=m;function y(B){let v=new Uint32Array(n.buffer),E=v[B+-8>>>2],R=c(E);if(!(R&1))throw Error("not an array: "+E);let N=l(R);var T=v[B+4>>>2];let M=R&2?v[B+12>>>2]:v[T+-4>>>2]>>>N;return f(N,R&1024,R&2048).subarray(T>>>=N,T+M)}r.__getArrayView=y;function g(B){let v=y(B),E=v.length,R=new Array(E);for(let N=0;N<E;N++)R[N]=v[N];return R}r.__getArray=g;function w(B){let v=n.buffer,E=new Uint32Array(v)[B+-4>>>2];return v.slice(B,B+E)}r.__getArrayBuffer=w;function x(B,v,E){return new B(A(B,v,E))}function A(B,v,E){let R=n.buffer,N=new Uint32Array(R),T=N[E+4>>>2];return new B(R,T,N[T+-4>>>2]>>>v)}r.__getInt8Array=x.bind(null,Int8Array,0),r.__getInt8ArrayView=A.bind(null,Int8Array,0),r.__getUint8Array=x.bind(null,Uint8Array,0),r.__getUint8ArrayView=A.bind(null,Uint8Array,0),r.__getUint8ClampedArray=x.bind(null,Uint8ClampedArray,0),r.__getUint8ClampedArrayView=A.bind(null,Uint8ClampedArray,0),r.__getInt16Array=x.bind(null,Int16Array,1),r.__getInt16ArrayView=A.bind(null,Int16Array,1),r.__getUint16Array=x.bind(null,Uint16Array,1),r.__getUint16ArrayView=A.bind(null,Uint16Array,1),r.__getInt32Array=x.bind(null,Int32Array,2),r.__getInt32ArrayView=A.bind(null,Int32Array,2),r.__getUint32Array=x.bind(null,Uint32Array,2),r.__getUint32ArrayView=A.bind(null,Uint32Array,2),pB&&(r.__getInt64Array=x.bind(null,BigInt64Array,3),r.__getInt64ArrayView=A.bind(null,BigInt64Array,3),r.__getUint64Array=x.bind(null,BigUint64Array,3),r.__getUint64ArrayView=A.bind(null,BigUint64Array,3)),r.__getFloat32Array=x.bind(null,Float32Array,2),r.__getFloat32ArrayView=A.bind(null,Float32Array,2),r.__getFloat64Array=x.bind(null,Float64Array,3),r.__getFloat64ArrayView=A.bind(null,Float64Array,3);function I(B,v){let E=new Uint32Array(n.buffer);var R=E[B+-8>>>2];if(R<=E[a>>>2])do if(R==v)return!0;while(R=u(R));return!1}return r.__instanceof=I,r.memory=r.memory||n,r.table=r.table||i,ww(t,r)}function mw(r){return typeof Response<"u"&&r instanceof Response}async function yw(r,e){return mw(r=await r)?gw(r,e):xf(wf(e||(e={})),await WebAssembly.instantiate(r instanceof WebAssembly.Module?r:await WebAssembly.compile(r),e))}Js.instantiate=yw;function mB(r,e){return xf(wf(e||(e={})),new WebAssembly.Instance(r instanceof WebAssembly.Module?r:new WebAssembly.Module(r),e))}Js.instantiateSync=mB;async function gw(r,e){return WebAssembly.instantiateStreaming?xf(wf(e||(e={})),(await WebAssembly.instantiateStreaming(r,e)).instance):yw(mw(r=await r)?r.arrayBuffer():r,e)}Js.instantiateStreaming=gw;function ww(r,e){var t=e?Object.create(e):{},n=r.__argumentsLength?function(i){r.__argumentsLength.value=i}:r.__setArgumentsLength||r.__setargc||function(){};for(let i in r){if(!Object.prototype.hasOwnProperty.call(r,i))continue;let o=r[i],s=i.split("."),a=t;for(;s.length>1;){let l=s.shift();Object.prototype.hasOwnProperty.call(a,l)||(a[l]={}),a=a[l]}let c=s[0],u=c.indexOf("#");if(u>=0){let l=c.substring(0,u),h=a[l];if(typeof h>"u"||!h.prototype){let p=function(...d){return p.wrap(p.prototype.constructor(0,...d))};p.prototype={valueOf:function(){return this[Xs]}},p.wrap=function(d){return Object.create(p.prototype,{[Xs]:{value:d,writable:!1}})},h&&Object.getOwnPropertyNames(h).forEach(d=>Object.defineProperty(p,d,Object.getOwnPropertyDescriptor(h,d))),a[l]=p}if(c=c.substring(u+1),a=a[l].prototype,/^(get|set):/.test(c)){if(!Object.prototype.hasOwnProperty.call(a,c=c.substring(4))){let p=r[i.replace("set:","get:")],d=r[i.replace("get:","set:")];Object.defineProperty(a,c,{get:function(){return p(this[Xs])},set:function(f){d(this[Xs],f)},enumerable:!0})}}else c==="constructor"?(a[c]=(...p)=>(n(p.length),o(...p))).original=o:(a[c]=function(...p){return n(p.length),o(this[Xs],...p)}).original=o}else/^(get|set):/.test(c)?Object.prototype.hasOwnProperty.call(a,c=c.substring(4))||Object.defineProperty(a,c,{get:r[i.replace("set:","get:")],set:r[i.replace("get:","set:")],enumerable:!0}):typeof o=="function"&&o!==n?(a[c]=(...l)=>(n(l.length),o(...l))).original=o:a[c]=o}return t}Js.demangle=ww});var Ew=me((lO,bw)=>{var{instantiate:yB}=xw();bf.supported=typeof WebAssembly<"u";function bf(r={}){if(!bf.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 yB(new Response(new Blob([e],{type:"application/wasm"})),r)}bw.exports=bf});var Aw=me((uO,Bw)=>{var vw=fw(),gB=Ew(),wB=async(r,e,t,n,i)=>{let o=await gB();return new vw(o,r,e,t,n,i)};Bw.exports={Rabin:vw,create:wB}});var Xw=me((UF,Yw)=>{"use strict";Yw.exports=r=>{if(Object.prototype.toString.call(r)!=="[object Object]")return!1;let e=Object.getPrototypeOf(r);return e===null||e===Object.prototype}});var r2=me((e2,t2)=>{"use strict";var Ul=Xw(),{hasOwnProperty:Jw}=Object.prototype,{propertyIsEnumerable:KB}=Object,Po=(r,e,t)=>Object.defineProperty(r,e,{value:t,writable:!0,enumerable:!0,configurable:!0}),qB=e2,Zw={concatArrays:!1,ignoreUndefined:!1},Ll=r=>{let e=[];for(let t in r)Jw.call(r,t)&&e.push(t);if(Object.getOwnPropertySymbols){let t=Object.getOwnPropertySymbols(r);for(let n of t)KB.call(r,n)&&e.push(n)}return e};function Oo(r){return Array.isArray(r)?GB(r):Ul(r)?jB(r):r}function GB(r){let e=r.slice(0,0);return Ll(r).forEach(t=>{Po(e,t,Oo(r[t]))}),e}function jB(r){let e=Object.getPrototypeOf(r)===null?Object.create(null):{};return Ll(r).forEach(t=>{Po(e,t,Oo(r[t]))}),e}var Qw=(r,e,t,n)=>(t.forEach(i=>{typeof e[i]>"u"&&n.ignoreUndefined||(i in r&&r[i]!==Object.getPrototypeOf(r)?Po(r,i,Bf(r[i],e[i],n)):Po(r,i,Oo(e[i])))}),r),WB=(r,e,t)=>{let n=r.slice(0,0),i=0;return[r,e].forEach(o=>{let s=[];for(let a=0;a<o.length;a++)Jw.call(o,a)&&(s.push(String(a)),o===r?Po(n,i++,o[a]):Po(n,i++,Oo(o[a])));n=Qw(n,o,Ll(o).filter(a=>!s.includes(a)),t)}),n};function Bf(r,e,t){return t.concatArrays&&Array.isArray(r)&&Array.isArray(e)?WB(r,e,t):!Ul(e)||!Ul(r)?Oo(e):Qw(r,e,Ll(e),t)}t2.exports=function(...r){let e=Bf(Oo(Zw),this!==qB&&this||{},Zw),t={_:{}};for(let n of r)if(n!==void 0){if(!Ul(n))throw new TypeError("`"+n+"` is not an Option Object");t=Bf(t,{_:n},e)}return t._}});var DA={};Ae(DA,{createVerifiedFetch:()=>Cf,verifiedFetch:()=>Xl});function ei(r){let e=new globalThis.AbortController;function t(){e.abort();for(let o of r)o?.removeEventListener!=null&&o.removeEventListener("abort",t)}for(let o of r){if(o?.aborted===!0){t();break}o?.addEventListener!=null&&o.addEventListener("abort",t)}function n(){for(let o of r)o?.removeEventListener!=null&&o.removeEventListener("abort",t)}let i=e.signal;return i.clear=n,i}function $2(r){let[e,t]=r[Symbol.asyncIterator]!=null?[r[Symbol.asyncIterator](),Symbol.asyncIterator]:[r[Symbol.iterator](),Symbol.iterator],n=[];return{peek:()=>e.next(),push:i=>{n.push(i)},next:()=>n.length>0?{done:!1,value:n.shift()}:e.next(),[t](){return this}}}var Ni=$2;function z2(r){return r[Symbol.asyncIterator]!=null}function Hf(r){return r?.then!=null}function K2(r,e){if(z2(r))return async function*(){for await(let a of r){let c=e(a);Hf(c)&&await c,yield a}}();let t=Ni(r),{value:n,done:i}=t.next();if(i===!0)return function*(){}();if(typeof e(n)?.then=="function")return async function*(){yield n;for await(let a of t){let c=e(a);Hf(c)&&await c,yield a}}();let s=e;return function*(){yield n;for(let a of t)s(a),yield a}()}var Jl=K2;var su={};Ae(su,{base32:()=>qe,base32hex:()=>tx,base32hexpad:()=>nx,base32hexpadupper:()=>ix,base32hexupper:()=>rx,base32pad:()=>Q2,base32padupper:()=>ex,base32upper:()=>qf,base32z:()=>ox});var Ui={};Ae(Ui,{coerce:()=>Lt,empty:()=>$f,equals:()=>Ql,fromHex:()=>G2,fromString:()=>eu,isBinary:()=>j2,toHex:()=>q2,toString:()=>tu});var $f=new Uint8Array(0);function q2(r){return r.reduce((e,t)=>e+t.toString(16).padStart(2,"0"),"")}function G2(r){let e=r.match(/../g);return e!=null?new Uint8Array(e.map(t=>parseInt(t,16))):$f}function Ql(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 Lt(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 j2(r){return r instanceof ArrayBuffer||ArrayBuffer.isView(r)}function eu(r){return new TextEncoder().encode(r)}function tu(r){return new TextDecoder().decode(r)}function W2(r,e){if(r.length>=255)throw new TypeError("Alphabet too long");for(var t=new Uint8Array(256),n=0;n<t.length;n++)t[n]=255;for(var i=0;i<r.length;i++){var o=r.charAt(i),s=o.charCodeAt(0);if(t[s]!==255)throw new TypeError(o+" is ambiguous");t[s]=i}var a=r.length,c=r.charAt(0),u=Math.log(a)/Math.log(256),l=Math.log(256)/Math.log(a);function h(f){if(f instanceof Uint8Array||(ArrayBuffer.isView(f)?f=new Uint8Array(f.buffer,f.byteOffset,f.byteLength):Array.isArray(f)&&(f=Uint8Array.from(f))),!(f instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(f.length===0)return"";for(var m=0,y=0,g=0,w=f.length;g!==w&&f[g]===0;)g++,m++;for(var x=(w-g)*l+1>>>0,A=new Uint8Array(x);g!==w;){for(var I=f[g],B=0,v=x-1;(I!==0||B<y)&&v!==-1;v--,B++)I+=256*A[v]>>>0,A[v]=I%a>>>0,I=I/a>>>0;if(I!==0)throw new Error("Non-zero carry");y=B,g++}for(var E=x-y;E!==x&&A[E]===0;)E++;for(var R=c.repeat(m);E<x;++E)R+=r.charAt(A[E]);return R}function p(f){if(typeof f!="string")throw new TypeError("Expected String");if(f.length===0)return new Uint8Array;var m=0;if(f[m]!==" "){for(var y=0,g=0;f[m]===c;)y++,m++;for(var w=(f.length-m)*u+1>>>0,x=new Uint8Array(w);f[m];){var A=t[f.charCodeAt(m)];if(A===255)return;for(var I=0,B=w-1;(A!==0||I<g)&&B!==-1;B--,I++)A+=a*x[B]>>>0,x[B]=A%256>>>0,A=A/256>>>0;if(A!==0)throw new Error("Non-zero carry");g=I,m++}if(f[m]!==" "){for(var v=w-g;v!==w&&x[v]===0;)v++;for(var E=new Uint8Array(y+(w-v)),R=y;v!==w;)E[R++]=x[v++];return E}}}function d(f){var m=p(f);if(m)return m;throw new Error(`Non-${e} character`)}return{encode:h,decodeUnsafe:p,decode:d}}var Y2=W2,X2=Y2,zf=X2;var ru=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")}},nu=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 Kf(this,e)}},iu=class{decoders;constructor(e){this.decoders=e}or(e){return Kf(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 Kf(r,e){return new iu({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}var ou=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,t,n,i){this.name=e,this.prefix=t,this.baseEncode=n,this.baseDecode=i,this.encoder=new ru(e,t,n),this.decoder=new nu(e,t,i)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function Li({name:r,prefix:e,encode:t,decode:n}){return new ou(r,e,t,n)}function bn({name:r,prefix:e,alphabet:t}){let{encode:n,decode:i}=zf(t,r);return Li({prefix:e,name:r,encode:n,decode:o=>Lt(i(o))})}function Z2(r,e,t,n){let i={};for(let l=0;l<e.length;++l)i[e[l]]=l;let o=r.length;for(;r[o-1]==="=";)--o;let s=new Uint8Array(o*t/8|0),a=0,c=0,u=0;for(let l=0;l<o;++l){let h=i[r[l]];if(h===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<t|h,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 J2(r,e,t){let n=e[e.length-1]==="=",i=(1<<t)-1,o="",s=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],s+=8;s>t;)s-=t,o+=e[i&a>>s];if(s!==0&&(o+=e[i&a<<t-s]),n)for(;o.length*t&7;)o+="=";return o}function Ie({name:r,prefix:e,bitsPerChar:t,alphabet:n}){return Li({prefix:e,name:r,encode(i){return J2(i,n,t)},decode(i){return Z2(i,n,t,r)}})}var qe=Ie({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),qf=Ie({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Q2=Ie({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),ex=Ie({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),tx=Ie({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),rx=Ie({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),nx=Ie({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),ix=Ie({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),ox=Ie({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var au={};Ae(au,{base58btc:()=>ke,base58flickr:()=>sx});var ke=bn({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),sx=bn({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var ax=Wf,Gf=128,cx=127,lx=~cx,ux=Math.pow(2,31);function Wf(r,e,t){e=e||[],t=t||0;for(var n=t;r>=ux;)e[t++]=r&255|Gf,r/=128;for(;r&lx;)e[t++]=r&255|Gf,r>>>=7;return e[t]=r|0,Wf.bytes=t-n+1,e}var hx=cu,dx=128,jf=127;function cu(r,n){var t=0,n=n||0,i=0,o=n,s,a=r.length;do{if(o>=a)throw cu.bytes=0,new RangeError("Could not decode varint");s=r[o++],t+=i<28?(s&jf)<<i:(s&jf)*Math.pow(2,i),i+=7}while(s>=dx);return cu.bytes=o-n,t}var fx=Math.pow(2,7),px=Math.pow(2,14),mx=Math.pow(2,21),yx=Math.pow(2,28),gx=Math.pow(2,35),wx=Math.pow(2,42),xx=Math.pow(2,49),bx=Math.pow(2,56),Ex=Math.pow(2,63),vx=function(r){return r<fx?1:r<px?2:r<mx?3:r<yx?4:r<gx?5:r<wx?6:r<xx?7:r<bx?8:r<Ex?9:10},Bx={encode:ax,decode:hx,encodingLength:vx},Ax=Bx,Ko=Ax;function qo(r,e=0){return[Ko.decode(r,e),Ko.decode.bytes]}function Di(r,e,t=0){return Ko.encode(r,e,t),e}function Pi(r){return Ko.encodingLength(r)}function hr(r,e){let t=e.byteLength,n=Pi(r),i=n+Pi(t),o=new Uint8Array(i+t);return Di(r,o,0),Di(t,o,n),o.set(e,i),new Oi(r,t,e,o)}function Et(r){let e=Lt(r),[t,n]=qo(e),[i,o]=qo(e.subarray(n)),s=e.subarray(n+o);if(s.byteLength!==i)throw new Error("Incorrect length");return new Oi(t,i,s,e)}function Yf(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&Ql(r.bytes,t.bytes)}}var Oi=class{code;size;digest;bytes;constructor(e,t,n,i){this.code=e,this.size=t,this.digest=n,this.bytes=i}};function Xf(r,e){let{bytes:t,version:n}=r;switch(n){case 0:return Sx(t,lu(r),e??ke.encoder);default:return _x(t,lu(r),e??qe.encoder)}}var Zf=new WeakMap;function lu(r){let e=Zf.get(r);if(e==null){let t=new Map;return Zf.set(r,t),t}return e}var H=class r{code;version;multihash;bytes;"/";constructor(e,t,n,i){this.code=t,this.version=e,this.multihash=n,this.bytes=i,this["/"]=i}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:e,multihash:t}=this;if(e!==Go)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==kx)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=hr(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&&Yf(e.multihash,n.multihash)}toString(e){return Xf(this,e)}toJSON(){return{"/":Xf(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(e){if(e==null)return null;let t=e;if(t instanceof r)return t;if(t["/"]!=null&&t["/"]===t.bytes||t.asCID===t){let{version:n,code:i,multihash:o,bytes:s}=t;return new r(n,i,o,s??Jf(n,i,o.bytes))}else if(t[Rx]===!0){let{version:n,multihash:i,code:o}=t,s=Et(i);return r.create(n,o,s)}else return null}static create(e,t,n){if(typeof t!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(e){case 0:{if(t!==Go)throw new Error(`Version 0 CID must use dag-pb (code: ${Go}) block encoding`);return new r(e,t,n,n.bytes)}case 1:{let i=Jf(e,t,n.bytes);return new r(e,t,n,i)}default:throw new Error("Invalid version")}}static createV0(e){return r.create(0,Go,e)}static createV1(e,t){return r.create(1,e,t)}static decode(e){let[t,n]=r.decodeFirst(e);if(n.length!==0)throw new Error("Incorrect length");return t}static decodeFirst(e){let t=r.inspectBytes(e),n=t.size-t.multihashSize,i=Lt(e.subarray(n,n+t.multihashSize));if(i.byteLength!==t.multihashSize)throw new Error("Incorrect length");let o=i.subarray(t.multihashSize-t.digestSize),s=new Oi(t.multihashCode,t.digestSize,o,i);return[t.version===0?r.createV0(s):r.createV1(t.codec,s),e.subarray(t.size)]}static inspectBytes(e){let t=0,n=()=>{let[h,p]=qo(e.subarray(t));return t+=p,h},i=n(),o=Go;if(i===18?(i=0,t=0):o=n(),i!==0&&i!==1)throw new RangeError(`Invalid CID version ${i}`);let s=t,a=n(),c=n(),u=t+c,l=u-s;return{version:i,codec:o,multihashCode:a,digestSize:c,multihashSize:l,size:u}}static parse(e,t){let[n,i]=Ix(e,t),o=r.decode(i);if(o.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return lu(o).set(n,e),o}};function Ix(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 qe.prefix:{let t=e??qe;return[qe.prefix,t.decode(r)]}default:{if(e==null)throw Error("To parse non base32 or base58btc encoded CID multibase decoder must be provided");return[r[0],e.decode(r)]}}}function Sx(r,e,t){let{prefix:n}=t;if(n!==ke.prefix)throw Error(`Cannot string encode V0 in ${t.name} encoding`);let i=e.get(n);if(i==null){let o=t.encode(r).slice(1);return e.set(n,o),o}else return i}function _x(r,e,t){let{prefix:n}=t,i=e.get(n);if(i==null){let o=t.encode(r);return e.set(n,o),o}else return i}var Go=112,kx=18;function Jf(r,e,t){let n=Pi(r),i=n+Pi(e),o=new Uint8Array(i+t.byteLength);return Di(r,o,0),Di(e,o,n),o.set(t,i),o}var Rx=Symbol.for("@ipld/js-cid/CID");var jo=Symbol.for("@libp2p/content-routing");var uu=Symbol.for("@libp2p/peer-id");function Qf(r){return r!=null&&!!r[uu]}var Wo=Symbol.for("@libp2p/peer-routing");var En=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"},F=class extends Error{code;props;constructor(e,t,n){super(e),this.code=t,this.name=n?.name??"CodeError",this.props=n??{}}};var ca=class extends EventTarget{#e=new Map;listenerCount(e){let t=this.#e.get(e);return t==null?0:t.length}addEventListener(e,t,n){super.addEventListener(e,t,n);let i=this.#e.get(e);i==null&&(i=[],this.#e.set(e,i)),i.push({callback:t,once:(n!==!0&&n!==!1&&n?.once)??!1})}removeEventListener(e,t,n){super.removeEventListener(e.toString(),t??null,n);let i=this.#e.get(e);i!=null&&(i=i.filter(({callback:o})=>o!==t),this.#e.set(e,i))}dispatchEvent(e){let t=super.dispatchEvent(e),n=this.#e.get(e.type);return n==null||(n=n.filter(({once:i})=>!i),this.#e.set(e.type,n)),t}safeDispatchEvent(e,t={}){return this.dispatchEvent(new Tx(e,t))}},hu=class extends Event{detail;constructor(e,t){super(e,t),this.detail=t?.detail}},Tx=globalThis.CustomEvent??hu;var la=(r,...e)=>{try{[...e]}catch{}};function e0(r){return r!=null&&typeof r.start=="function"&&typeof r.stop=="function"}async function vn(...r){let e=[];for(let t of r)e0(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 Bn(...r){let e=[];for(let t of r)e0(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 pu={};Ae(pu,{sha256:()=>he,sha512:()=>fu});function ti({name:r,code:e,encode:t}){return new du(r,e,t)}var du=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?hr(this.code,t):t.then(n=>hr(this.code,n))}else throw Error("Unknown type, must be binary type")}};function r0(r){return async e=>new Uint8Array(await crypto.subtle.digest(r,e))}var he=ti({name:"sha2-256",code:18,encode:r0("SHA-256")}),fu=ti({name:"sha2-512",code:19,encode:r0("SHA-512")});var Bt=re(yu(),1);var gu={};Ae(gu,{base64:()=>Pr,base64pad:()=>zx,base64url:()=>s0,base64urlpad:()=>Kx});var Pr=Ie({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),zx=Ie({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),s0=Ie({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Kx=Ie({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});Bt.default.formatters.b=r=>r==null?"undefined":ke.baseEncode(r);Bt.default.formatters.t=r=>r==null?"undefined":qe.baseEncode(r);Bt.default.formatters.m=r=>r==null?"undefined":Pr.baseEncode(r);Bt.default.formatters.p=r=>r==null?"undefined":r.toString();Bt.default.formatters.c=r=>r==null?"undefined":r.toString();Bt.default.formatters.k=r=>r==null?"undefined":r.toString();Bt.default.formatters.a=r=>r==null?"undefined":r.toString();function qx(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 a0(){return{forComponent(r){return oe(r)}}}function oe(r){let e=qx(`${r}:trace`);return Bt.default.enabled(`${r}:trace`)&&Bt.default.names.map(t=>t.toString()).find(t=>t.includes(":trace"))!=null&&(e=(0,Bt.default)(`${r}:trace`)),Object.assign((0,Bt.default)(r),{error:(0,Bt.default)(`${r}:error`),trace:e})}function de(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 An(r){return globalThis.Buffer!=null?new Uint8Array(r.buffer,r.byteOffset,r.byteLength):r}function Or(r=0){return globalThis.Buffer?.alloc!=null?An(globalThis.Buffer.alloc(r)):new Uint8Array(r)}function dt(r=0){return globalThis.Buffer?.allocUnsafe!=null?An(globalThis.Buffer.allocUnsafe(r)):new Uint8Array(r)}var Gx=Math.pow(2,7),jx=Math.pow(2,14),Wx=Math.pow(2,21),wu=Math.pow(2,28),xu=Math.pow(2,35),bu=Math.pow(2,42),Eu=Math.pow(2,49),fe=128,Je=127;function ft(r){if(r<Gx)return 1;if(r<jx)return 2;if(r<Wx)return 3;if(r<wu)return 4;if(r<xu)return 5;if(r<bu)return 6;if(r<Eu)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function vu(r,e,t=0){switch(ft(r)){case 8:e[t++]=r&255|fe,r/=128;case 7:e[t++]=r&255|fe,r/=128;case 6:e[t++]=r&255|fe,r/=128;case 5:e[t++]=r&255|fe,r/=128;case 4:e[t++]=r&255|fe,r>>>=7;case 3:e[t++]=r&255|fe,r>>>=7;case 2:e[t++]=r&255|fe,r>>>=7;case 1:{e[t++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return e}function Yx(r,e,t=0){switch(ft(r)){case 8:e.set(t++,r&255|fe),r/=128;case 7:e.set(t++,r&255|fe),r/=128;case 6:e.set(t++,r&255|fe),r/=128;case 5:e.set(t++,r&255|fe),r/=128;case 4:e.set(t++,r&255|fe),r>>>=7;case 3:e.set(t++,r&255|fe),r>>>=7;case 2:e.set(t++,r&255|fe),r>>>=7;case 1:{e.set(t++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return e}function Bu(r,e){let t=r[e],n=0;if(n+=t&Je,t<fe||(t=r[e+1],n+=(t&Je)<<7,t<fe)||(t=r[e+2],n+=(t&Je)<<14,t<fe)||(t=r[e+3],n+=(t&Je)<<21,t<fe)||(t=r[e+4],n+=(t&Je)*wu,t<fe)||(t=r[e+5],n+=(t&Je)*xu,t<fe)||(t=r[e+6],n+=(t&Je)*bu,t<fe)||(t=r[e+7],n+=(t&Je)*Eu,t<fe))return n;throw new RangeError("Could not decode varint")}function Xx(r,e){let t=r.get(e),n=0;if(n+=t&Je,t<fe||(t=r.get(e+1),n+=(t&Je)<<7,t<fe)||(t=r.get(e+2),n+=(t&Je)<<14,t<fe)||(t=r.get(e+3),n+=(t&Je)<<21,t<fe)||(t=r.get(e+4),n+=(t&Je)*wu,t<fe)||(t=r.get(e+5),n+=(t&Je)*xu,t<fe)||(t=r.get(e+6),n+=(t&Je)*bu,t<fe)||(t=r.get(e+7),n+=(t&Je)*Eu,t<fe))return n;throw new RangeError("Could not decode varint")}function Hi(r,e,t=0){return e==null&&(e=dt(ft(r))),e instanceof Uint8Array?vu(r,e,t):Yx(r,e,t)}function ni(r,e=0){return r instanceof Uint8Array?Bu(r,e):Xx(r,e)}var Au=new Float32Array([-0]),In=new Uint8Array(Au.buffer);function l0(r,e,t){Au[0]=r,e[t]=In[0],e[t+1]=In[1],e[t+2]=In[2],e[t+3]=In[3]}function u0(r,e){return In[0]=r[e],In[1]=r[e+1],In[2]=r[e+2],In[3]=r[e+3],Au[0]}var Iu=new Float64Array([-0]),Qe=new Uint8Array(Iu.buffer);function h0(r,e,t){Iu[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 d0(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],Iu[0]}var Zx=BigInt(Number.MAX_SAFE_INTEGER),Jx=BigInt(Number.MIN_SAFE_INTEGER),At=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 ii;if(e<Zx&&e>Jx)return this.fromNumber(Number(e));let t=e<0n;t&&(e=-e);let n=e>>32n,i=e-(n<<32n);return t&&(n=~n|0n,i=~i|0n,++i>f0&&(i=0n,++n>f0&&(n=0n))),new r(Number(i),Number(n))}static fromNumber(e){if(e===0)return ii;let t=e<0;t&&(e=-e);let n=e>>>0,i=(e-n)/4294967296>>>0;return t&&(i=~i>>>0,n=~n>>>0,++n>4294967295&&(n=0,++i>4294967295&&(i=0))),new r(n,i)}static from(e){return typeof e=="number"?r.fromNumber(e):typeof e=="bigint"?r.fromBigInt(e):typeof e=="string"?r.fromBigInt(BigInt(e)):e.low!=null||e.high!=null?new r(e.low>>>0,e.high>>>0):ii}},ii=new At(0,0);ii.toBigInt=function(){return 0n};ii.zzEncode=ii.zzDecode=function(){return this};ii.length=function(){return 1};var f0=4294967296n;function p0(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 m0(r,e,t){if(t-e<1)return"";let i,o=[],s=0,a;for(;e<t;)a=r[e++],a<128?o[s++]=a:a>191&&a<224?o[s++]=(a&31)<<6|r[e++]&63:a>239&&a<365?(a=((a&7)<<18|(r[e++]&63)<<12|(r[e++]&63)<<6|r[e++]&63)-65536,o[s++]=55296+(a>>10),o[s++]=56320+(a&1023)):o[s++]=(a&15)<<12|(r[e++]&63)<<6|r[e++]&63,s>8191&&((i??(i=[])).push(String.fromCharCode.apply(String,o)),s=0);return i!=null?(s>0&&i.push(String.fromCharCode.apply(String,o.slice(0,s))),i.join("")):String.fromCharCode.apply(String,o.slice(0,s))}function Su(r,e,t){let n=t,i,o;for(let s=0;s<r.length;++s)i=r.charCodeAt(s),i<128?e[t++]=i:i<2048?(e[t++]=i>>6|192,e[t++]=i&63|128):(i&64512)===55296&&((o=r.charCodeAt(s+1))&64512)===56320?(i=65536+((i&1023)<<10)+(o&1023),++s,e[t++]=i>>18|240,e[t++]=i>>12&63|128,e[t++]=i>>6&63|128,e[t++]=i&63|128):(e[t++]=i>>12|224,e[t++]=i>>6&63|128,e[t++]=i&63|128);return t-n}function Gt(r,e){return RangeError(`index out of range: ${r.pos} + ${e??1} > ${r.len}`)}function da(r,e){return(r[e-4]|r[e-3]<<8|r[e-2]<<16|r[e-1]<<24)>>>0}var _u=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,Gt(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 Gt(this,4);return da(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Gt(this,4);return da(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Gt(this,4);let e=u0(this.buf,this.pos);return this.pos+=4,e}double(){if(this.pos+8>this.len)throw Gt(this,4);let e=d0(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 Gt(this,e);return this.pos+=e,t===n?new Uint8Array(0):this.buf.subarray(t,n)}string(){let e=this.bytes();return m0(e,0,e.length)}skip(e){if(typeof e=="number"){if(this.pos+e>this.len)throw Gt(this,e);this.pos+=e}else do if(this.pos>=this.len)throw Gt(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 At(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 Gt(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 Gt(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 Gt(this,8);let e=da(this.buf,this.pos+=4),t=da(this.buf,this.pos+=4);return new At(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=Bu(this.buf,this.pos);return this.pos+=ft(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 ku(r){return new _u(r instanceof Uint8Array?r:r.subarray())}function Dt(r,e,t){let n=ku(r);return e.decode(n,void 0,t)}var Ru={};Ae(Ru,{base10:()=>Qx});var Qx=bn({prefix:"9",name:"base10",alphabet:"0123456789"});var Tu={};Ae(Tu,{base16:()=>eb,base16upper:()=>tb});var eb=Ie({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),tb=Ie({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Cu={};Ae(Cu,{base2:()=>rb});var rb=Ie({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Nu={};Ae(Nu,{base256emoji:()=>ab});var g0=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}"),nb=g0.reduce((r,e,t)=>(r[t]=e,r),[]),ib=g0.reduce((r,e,t)=>(r[e.codePointAt(0)]=t,r),[]);function ob(r){return r.reduce((e,t)=>(e+=nb[t],e),"")}function sb(r){let e=[];for(let t of r){let n=ib[t.codePointAt(0)];if(n===void 0)throw new Error(`Non-base256emoji character: ${t}`);e.push(n)}return new Uint8Array(e)}var ab=Li({prefix:"\u{1F680}",name:"base256emoji",encode:ob,decode:sb});var Uu={};Ae(Uu,{base36:()=>Sn,base36upper:()=>cb});var Sn=bn({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),cb=bn({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Lu={};Ae(Lu,{base8:()=>lb});var lb=Ie({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Du={};Ae(Du,{identity:()=>ub});var ub=Li({prefix:"\0",name:"identity",encode:r=>tu(r),decode:r=>eu(r)});var O8=new TextEncoder,hb=new TextDecoder;var $i=512;function w0(r){return JSON.parse(hb.decode(r))}var Pt={};Ae(Pt,{code:()=>Ne,decode:()=>pb,encode:()=>fb,name:()=>db});var db="raw",Ne=85;function fb(r){return Lt(r)}function pb(r){return Lt(r)}var Pu={};Ae(Pu,{identity:()=>et});var x0=0,mb="identity",b0=Lt;function yb(r){return hr(x0,b0(r))}var et={code:x0,name:mb,encode:b0,digest:yb};var _n={...Du,...Cu,...Lu,...Ru,...Tu,...su,...Uu,...au,...gu,...Nu},Y8={...pu,...Pu};function v0(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}var E0=v0("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Ou=v0("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=dt(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),gb={utf8:E0,"utf-8":E0,hex:_n.base16,latin1:Ou,ascii:Ou,binary:Ou,..._n},pa=gb;function Y(r,e="utf8"){let t=pa[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return(e==="utf8"||e==="utf-8")&&globalThis.Buffer!=null&&globalThis.Buffer.from!=null?An(globalThis.Buffer.from(r,"utf-8")):t.decoder.decode(`${t.prefix}${r}`)}function Fu(r){let e=r??8192,t=e>>>1,n,i=e;return function(s){if(s<1||s>t)return dt(s);i+s>e&&(n=dt(e),i=0);let a=n.subarray(i,i+=s);return i&7&&(i=(i|7)+1),a}}var oi=class{fn;len;next;val;constructor(e,t,n){this.fn=e,this.len=t,this.next=void 0,this.val=n}};function Vu(){}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}},wb=Fu();function xb(r){return globalThis.Buffer!=null?dt(r):wb(r)}var Xo=class{len;head;tail;states;constructor(){this.len=0,this.head=new oi(Vu,0,0),this.tail=this.head,this.states=null}_push(e,t,n){return this.tail=this.tail.next=new oi(e,t,n),this.len+=t,this}uint32(e){return this.len+=(this.tail=this.tail.next=new $u((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(ma,10,At.fromNumber(e)):this.uint32(e)}sint32(e){return this.uint32((e<<1^e>>31)>>>0)}uint64(e){let t=At.fromBigInt(e);return this._push(ma,t.length(),t)}uint64Number(e){return this._push(vu,ft(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=At.fromBigInt(e).zzEncode();return this._push(ma,t.length(),t)}sint64Number(e){let t=At.fromNumber(e).zzEncode();return this._push(ma,t.length(),t)}sint64String(e){return this.sint64(BigInt(e))}bool(e){return this._push(Mu,1,e?1:0)}fixed32(e){return this._push(Yo,4,e>>>0)}sfixed32(e){return this.fixed32(e)}fixed64(e){let t=At.fromBigInt(e);return this._push(Yo,4,t.lo)._push(Yo,4,t.hi)}fixed64Number(e){let t=At.fromNumber(e);return this._push(Yo,4,t.lo)._push(Yo,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(l0,4,e)}double(e){return this._push(h0,8,e)}bytes(e){let t=e.length>>>0;return t===0?this._push(Mu,1,0):this.uint32(t)._push(Eb,t,e)}string(e){let t=p0(e);return t!==0?this.uint32(t)._push(Su,t,e):this._push(Mu,1,0)}fork(){return this.states=new Hu(this),this.head=this.tail=new oi(Vu,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 oi(Vu,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=xb(this.len),n=0;for(;e!=null;)e.fn(e.val,t,n),n+=e.len,e=e.next;return t}};function Mu(r,e,t){e[t]=r&255}function bb(r,e,t){for(;r>127;)e[t++]=r&127|128,r>>>=7;e[t]=r}var $u=class extends oi{next;constructor(e,t){super(bb,e,t),this.next=void 0}};function ma(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 Yo(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 Eb(r,e,t){e.set(r,t)}globalThis.Buffer!=null&&(Xo.prototype.bytes=function(r){let e=r.length>>>0;return this.uint32(e),e>0&&this._push(vb,e,r),this},Xo.prototype.string=function(r){let e=globalThis.Buffer.byteLength(r);return this.uint32(e),e>0&&this._push(Bb,e,r),this});function vb(r,e,t){e.set(r,t)}function Bb(r,e,t){r.length<40?Su(r,e,t):e.utf8Write!=null?e.utf8Write(r,t):e.set(Y(r),t)}function zu(){return new Xo}function Ot(r,e){let t=zu();return e.encode(r,t,{lengthDelimited:!1}),t.finish()}var zi;(function(r){r[r.VARINT=0]="VARINT",r[r.BIT64=1]="BIT64",r[r.LENGTH_DELIMITED=2]="LENGTH_DELIMITED",r[r.START_GROUP=3]="START_GROUP",r[r.END_GROUP=4]="END_GROUP",r[r.BIT32=5]="BIT32"})(zi||(zi={}));function ya(r,e,t,n){return{name:r,type:e,encode:t,decode:n}}function si(r){function e(i){if(r[i.toString()]==null)throw new Error("Invalid enum value");return r[i]}let t=function(o,s){let a=e(o);s.int32(a)},n=function(o){let s=o.int32();return e(s)};return ya("enum",zi.VARINT,t,n)}function Ft(r,e){return ya("message",zi.LENGTH_DELIMITED,r,e)}function Ab(r){return r[Symbol.asyncIterator]!=null}function Ib(r){if(Ab(r))return(async()=>{for await(let e of r);})();for(let e of r);}var Fr=Ib;function Ee(r,e){if(globalThis.Buffer!=null)return An(globalThis.Buffer.concat(r,e));e==null&&(e=r.reduce((i,o)=>i+o.length,0));let t=dt(e),n=0;for(let i of r)t.set(i,n),n+=i.length;return An(t)}var A0=Symbol.for("@achingbrain/uint8arraylist");function B0(r,e){if(e==null||e<0)throw new RangeError("index is out of bounds");let t=0;for(let n of r){let i=t+n.byteLength;if(e<i)return{buf:n,index:e-t};t=i}throw new RangeError("index is out of bounds")}function ga(r){return!!r?.[A0]}var ai=class r{bufs;length;[A0]=!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(ga(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(ga(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=B0(this.bufs,e);return t.buf[t.index]}set(e,t){let n=B0(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(ga(e))for(let n=0;n<e.length;n++)this.set(t+n,e.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(e){if(e=Math.trunc(e),!(Number.isNaN(e)||e<=0)){if(e===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(e>=this.bufs[0].byteLength)e-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(e),this.length-=e;break}}}slice(e,t){let{bufs:n,length:i}=this._subList(e,t);return Ee(n,i)}subarray(e,t){let{bufs:n,length:i}=this._subList(e,t);return n.length===1?n[0]:Ee(n,i)}sublist(e,t){let{bufs:n,length:i}=this._subList(e,t),o=new r;return o.length=i,o.bufs=[...n],o}_subList(e,t){if(e=e??0,t=t??this.length,e<0&&(e=this.length+e),t<0&&(t=this.length+t),e<0||t>this.length)throw new RangeError("index is out of bounds");if(e===t)return{bufs:[],length:0};if(e===0&&t===this.length)return{bufs:this.bufs,length:this.length};let n=[],i=0;for(let o=0;o<this.bufs.length;o++){let s=this.bufs[o],a=i,c=a+s.byteLength;if(i=c,e>=c)continue;let u=e>=a&&e<c,l=t>a&&t<=c;if(u&&l){if(e===a&&t===c){n.push(s);break}let h=e-a;n.push(s.subarray(h,h+(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(!ga(e)&&!(e instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=e instanceof Uint8Array?e:e.subarray();if(t=Number(t??0),isNaN(t)&&(t=0),t<0&&(t=this.length+t),t<0&&(t=0),e.length===0)return t>this.length?this.length:t;let i=n.byteLength;if(i===0)throw new TypeError("search must be at least 1 byte long");let o=256,s=new Int32Array(o);for(let h=0;h<o;h++)s[h]=-1;for(let h=0;h<i;h++)s[n[h]]=h;let a=s,c=this.byteLength-n.byteLength,u=n.byteLength-1,l;for(let h=t;h<=c;h+=l){l=0;for(let p=u;p>=0;p--){let d=this.get(h+p);if(n[p]!==d){l=Math.max(1,p-a[d]);break}}if(l===0)return h}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=dt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,t),this.write(n,e)}getInt16(e,t){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,t)}setInt16(e,t,n){let i=Or(2);new DataView(i.buffer,i.byteOffset,i.byteLength).setInt16(0,t,n),this.write(i,e)}getInt32(e,t){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,t)}setInt32(e,t,n){let i=Or(4);new DataView(i.buffer,i.byteOffset,i.byteLength).setInt32(0,t,n),this.write(i,e)}getBigInt64(e,t){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,t)}setBigInt64(e,t,n){let i=Or(8);new DataView(i.buffer,i.byteOffset,i.byteLength).setBigInt64(0,t,n),this.write(i,e)}getUint8(e){let t=this.subarray(e,e+1);return new DataView(t.buffer,t.byteOffset,t.byteLength).getUint8(0)}setUint8(e,t){let n=dt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,t),this.write(n,e)}getUint16(e,t){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,t)}setUint16(e,t,n){let i=Or(2);new DataView(i.buffer,i.byteOffset,i.byteLength).setUint16(0,t,n),this.write(i,e)}getUint32(e,t){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,t)}setUint32(e,t,n){let i=Or(4);new DataView(i.buffer,i.byteOffset,i.byteLength).setUint32(0,t,n),this.write(i,e)}getBigUint64(e,t){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,t)}setBigUint64(e,t,n){let i=Or(8);new DataView(i.buffer,i.byteOffset,i.byteLength).setBigUint64(0,t,n),this.write(i,e)}getFloat32(e,t){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,t)}setFloat32(e,t,n){let i=Or(4);new DataView(i.buffer,i.byteOffset,i.byteLength).setFloat32(0,t,n),this.write(i,e)}getFloat64(e,t){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,t)}setFloat64(e,t,n){let i=Or(8);new DataView(i.buffer,i.byteOffset,i.byteLength).setFloat64(0,t,n),this.write(i,e)}equals(e){if(e==null||!(e instanceof r)||e.bufs.length!==this.bufs.length)return!1;for(let t=0;t<this.bufs.length;t++)if(!de(this.bufs[t],e.bufs[t]))return!1;return!0}static fromUint8Arrays(e,t){let n=new r;return n.bufs=e,t==null&&(t=e.reduce((i,o)=>i+o.byteLength,0)),n.length=t,n}};function _b(r){return r[Symbol.asyncIterator]!=null}function kb(r,e){if(_b(r))return async function*(){for await(let a of r)yield e(a)}();let t=Ni(r),{value:n,done:i}=t.next();if(i===!0)return function*(){}();let o=e(n);if(typeof o.then=="function")return async function*(){yield await o;for await(let a of t)yield e(a)}();let s=e;return function*(){yield o;for(let a of t)yield s(a)}()}var jt=kb;function Ue(){let r={};return r.promise=new Promise((e,t)=>{r.resolve=e,r.reject=t}),r}var wa=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}},Ki=class{size;hwm;head;tail;constructor(e={}){this.hwm=e.splitLimit??16,this.head=new wa(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 wa(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 Ku=class extends Error{type;code;constructor(e,t){super(e??"The operation was aborted"),this.type="aborted",this.code=t??"ABORT_ERR"}};function Vt(r={}){return Rb(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 Rb(r,e){e=e??{};let t=e.onEnd,n=new Ki,i,o,s,a=Ue(),c=async()=>{try{return n.isEmpty()?s?{done:!0}:await new Promise((y,g)=>{o=w=>{o=null,n.push(w);try{y(r(n))}catch(x){g(x)}return i}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=Ue()})}},u=y=>o!=null?o(y):(n.push(y),i),l=y=>(n=new Ki,o!=null?o({error:y}):(n.push({error:y}),i)),h=y=>{if(s)return i;if(e?.objectMode!==!0&&y?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return u({done:!1,value:y})},p=y=>s?i:(s=!0,y!=null?l(y):u({done:!0})),d=()=>(n=new Ki,p(),{done:!0}),f=y=>(p(y),{done:!0});if(i={[Symbol.asyncIterator](){return this},next:c,return:d,throw:f,push:h,end:p,get readableLength(){return n.size},onEmpty:async y=>{let g=y?.signal;if(g?.throwIfAborted(),n.isEmpty())return;let w,x;g!=null&&(w=new Promise((A,I)=>{x=()=>{I(new Ku)},g.addEventListener("abort",x)}));try{await Promise.race([a.promise,w])}finally{x!=null&&g!=null&&g?.removeEventListener("abort",x)}}},t==null)return i;let m=i;return i={[Symbol.asyncIterator](){return this},next(){return m.next()},throw(y){return m.throw(y),t!=null&&(t(y),t=void 0),{done:!0}},return(){return m.return(),t!=null&&(t(),t=void 0),{done:!0}},push:h,end(y){return m.end(y),t!=null&&(t(y),t=void 0),i},get readableLength(){return m.readableLength},onEmpty:y=>m.onEmpty(y)},i}function Tb(r){return r[Symbol.asyncIterator]!=null}function Cb(...r){let e=[];for(let t of r)Tb(t)||e.push(t);return e.length===r.length?function*(){for(let t of e)yield*t}():async function*(){let t=Vt({objectMode:!0});Promise.resolve().then(async()=>{try{await Promise.all(r.map(async n=>{for await(let i of n)t.push(i)})),t.end()}catch(n){t.end(n)}}),yield*t}()}var Vr=Cb;function Wt(r,...e){if(r==null)throw new Error("Empty pipeline");if(qu(r)){let n=r;r=()=>n.source}else if(k0(r)||_0(r)){let n=r;r=()=>n}let t=[r,...e];if(t.length>1&&qu(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++)qu(t[n])&&(t[n]=Ub(t[n]));return Nb(...t)}var Nb=(...r)=>{let e;for(;r.length>0;)e=r.shift()(e);return e},_0=r=>r?.[Symbol.asyncIterator]!=null,k0=r=>r?.[Symbol.iterator]!=null,qu=r=>r==null?!1:r.sink!=null&&r.source!=null,Ub=r=>e=>{let t=r.sink(e);if(t?.then!=null){let n=Vt({objectMode:!0});t.then(()=>{n.end()},s=>{n.end(s)});let i,o=r.source;if(_0(o))i=async function*(){yield*o,n.end()};else if(k0(o))i=function*(){yield*o,n.end()};else throw new Error("Unknown duplex source type - must be Iterable or AsyncIterable");return Vr(n,i())}return r.source};function Lb(r){return r[Symbol.asyncIterator]!=null}function Db(r,e){return Lb(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 xa=Db;var P=class extends Event{constructor(e,t){super(e),this.detail=t}};function Q(r,e="utf8"){let t=pa[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return(e==="utf8"||e==="utf-8")&&globalThis.Buffer!=null&&globalThis.Buffer.from!=null?globalThis.Buffer.from(r.buffer,r.byteOffset,r.byteLength).toString("utf8"):t.encoder.encode(r).substring(1)}var ba=class{url;#e=0;#t=0;#r=0;#s=0;constructor(e){this.url=e instanceof URL?e:new URL(e)}async getRawBlock(e,t){let n=this.url;if(n.pathname=`/ipfs/${e.toString()}`,n.search="?format=raw",t?.aborted===!0)throw new Error(`Signal to fetch raw block for CID ${e} from gateway ${this.url} was aborted prior to fetch`);try{this.#e++;let i=await fetch(n.toString(),{signal:t,headers:{Accept:"application/vnd.ipld.raw"},cache:"force-cache"});if(!i.ok)throw this.#t++,new Error(`unable to fetch raw block for CID ${e} from gateway ${this.url}`);return this.#s++,new Uint8Array(await i.arrayBuffer())}catch{throw t?.aborted===!0?new Error(`fetching raw block for CID ${e} from gateway ${this.url} was aborted`):(this.#t++,new Error(`unable to fetch raw block for CID ${e}`))}}reliability(){return this.#e===0?1:this.#r>0?-1/0:this.#s/(this.#e+this.#t*3)}incrementInvalidBlocks(){this.#r++}};var Ea=class{gateways;log;constructor(e,t={}){this.log=e.logger.forComponent("helia:trustless-gateway-block-broker"),this.gateways=(t.gateways??R0).map(n=>new ba(n))}async retrieve(e,t={}){let n=this.gateways.sort((o,s)=>s.reliability()-o.reliability()),i=[];for(let o of n){this.log("getting block for %c from %s",e,o.url);try{let s=await o.getRawBlock(e,t.signal);this.log.trace("got block for %c from %s",e,o.url);try{await t.validateFn?.(s)}catch(a){throw this.log.error("failed to validate block for %c from %s",e,o.url,a),o.incrementInvalidBlocks(),new Error(`unable to validate block for CID ${e} from gateway ${o.url}`)}return s}catch(s){if(this.log.error("failed to get block for %c from %s",e,o.url,s),s instanceof Error?i.push(s):i.push(new Error(`unable to fetch raw block for CID ${e} from gateway ${o.url}`)),t.signal?.aborted===!0){this.log.trace("request aborted while fetching raw block for CID %c from gateway %s",e,o.url);break}}}throw new AggregateError(i,`unable to fetch raw block for CID ${e} from any gateway`)}};var R0=["https://trustless-gateway.link","https://cloudflare-ipfs.com","https://4everland.io"];function Zo(r={}){return e=>new Ea(e,r)}var Pb=Symbol.for("nodejs.util.inspect.custom"),T0=Object.values(_n).map(r=>r.decoder).reduce((r,e)=>r.or(e),_n.identity.decoder),C0=114,Gu=36,ju=37,Jo=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()})`}[uu]=!0;toString(){return this.string==null&&(this.string=ke.encode(this.multihash.bytes).slice(1)),this.string}toCID(){return H.createV1(C0,this.multihash)}toBytes(){return this.multihash.bytes}toJSON(){return this.toString()}equals(e){if(e==null)return!1;if(e instanceof Uint8Array)return de(this.multihash.bytes,e);if(typeof e=="string")return Yt(e).equals(this);if(e?.multihash?.bytes!=null)return de(this.multihash.bytes,e.multihash.bytes);throw new Error("not valid Id")}[Pb](){return`PeerId(${this.toString()})`}},qi=class extends Jo{type="RSA";publicKey;constructor(e){super({...e,type:"RSA"}),this.publicKey=e.publicKey}},Gi=class extends Jo{type="Ed25519";publicKey;constructor(e){super({...e,type:"Ed25519"}),this.publicKey=e.multihash.digest}},ji=class extends Jo{type="secp256k1";publicKey;constructor(e){super({...e,type:"secp256k1"}),this.publicKey=e.multihash.digest}};function Yt(r,e){if(e=e??T0,r.charAt(0)==="1"||r.charAt(0)==="Q"){let t=Et(ke.decode(`z${r}`));return r.startsWith("12D")?new Gi({multihash:t}):r.startsWith("16U")?new ji({multihash:t}):new qi({multihash:t})}return Qo(T0.decode(r))}function Qo(r){try{let e=Et(r);if(e.code===et.code){if(e.digest.length===Gu)return new Gi({multihash:e});if(e.digest.length===ju)return new ji({multihash:e})}if(e.code===he.code)return new qi({multihash:e})}catch{return Ob(H.decode(r))}throw new Error("Supplied PeerID CID is invalid")}function Ob(r){if(r==null||r.multihash==null||r.version==null||r.version===1&&r.code!==C0)throw new Error("Supplied PeerID CID is invalid");let e=r.multihash;if(e.code===he.code)return new qi({multihash:r.multihash});if(e.code===et.code){if(e.digest.length===Gu)return new Gi({multihash:r.multihash});if(e.digest.length===ju)return new ji({multihash:r.multihash})}throw new Error("Supplied PeerID CID is invalid")}async function N0(r,e){return r.length===Gu?new Gi({multihash:hr(et.code,r),privateKey:e}):r.length===ju?new ji({multihash:hr(et.code,r),privateKey:e}):new qi({multihash:await he.digest(r),publicKey:r,privateKey:e})}var va=class{index=0;input="";new(e){return this.index=0,this.input=e,this}readAtomically(e){let t=this.index,n=e();return n===void 0&&(this.index=t),n}parseWith(e){let t=e();if(this.index===this.input.length)return t}peekChar(){if(!(this.index>=this.input.length))return this.input[this.index]}readChar(){if(!(this.index>=this.input.length))return this.input[this.index++]}readGivenChar(e){return this.readAtomically(()=>{let t=this.readChar();if(t===e)return t})}readSeparator(e,t,n){return this.readAtomically(()=>{if(!(t>0&&this.readGivenChar(e)===void 0))return n()})}readNumber(e,t,n,i){return this.readAtomically(()=>{let o=0,s=0,a=this.peekChar();if(a===void 0)return;let c=a==="0",u=2**(8*i)-1;for(;;){let l=this.readAtomically(()=>{let h=this.readChar();if(h===void 0)return;let p=Number.parseInt(h,e);if(!Number.isNaN(p))return p});if(l===void 0)break;if(o*=e,o+=l,o>u||(s+=1,t!==void 0&&s>t))return}if(s!==0)return!n&&c&&s>1?void 0:o})}readIPv4Addr(){return this.readAtomically(()=>{let e=new Uint8Array(4);for(let t=0;t<e.length;t++){let n=this.readSeparator(".",t,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;e[t]=n}return e})}readIPv6Addr(){let e=t=>{for(let n=0;n<t.length/2;n++){let i=n*2;if(n<t.length-3){let s=this.readSeparator(":",n,()=>this.readIPv4Addr());if(s!==void 0)return t[i]=s[0],t[i+1]=s[1],t[i+2]=s[2],t[i+3]=s[3],[i+4,!0]}let o=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(o===void 0)return[i,!1];t[i]=o>>8,t[i+1]=o&255}return[t.length,!1]};return this.readAtomically(()=>{let t=new Uint8Array(16),[n,i]=e(t);if(n===16)return t;if(i||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let o=new Uint8Array(14),s=16-(n+2),[a]=e(o.subarray(0,s));return t.set(o.subarray(0,a),16-a),t})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var U0=45,Fb=15,Wi=new va;function Wu(r){if(!(r.length>Fb))return Wi.new(r).parseWith(()=>Wi.readIPv4Addr())}function Yu(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>U0))return Wi.new(r).parseWith(()=>Wi.readIPv6Addr())}function Ba(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>U0))return Wi.new(r).parseWith(()=>Wi.readIPAddr())}var I5=parseInt("0xFFFF",16),S5=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function P0(r){return!!Wu(r)}function O0(r){return!!Yu(r)}function Aa(r){return!!Ba(r)}var F0=P0,zb=O0,Xu=function(r){let e=0;if(r=r.toString().trim(),F0(r)){let t=new Uint8Array(e+4);return r.split(/\./g).forEach(n=>{t[e++]=parseInt(n,10)&255}),t}if(zb(r)){let t=r.split(":",8),n;for(n=0;n<t.length;n++){let o=F0(t[n]),s;o&&(s=Xu(t[n]),t[n]=Q(s.slice(0,2),"base16")),s!=null&&++n<8&&t.splice(n,0,Q(s.slice(2,4),"base16"))}if(t[0]==="")for(;t.length<8;)t.unshift("0");else if(t[t.length-1]==="")for(;t.length<8;)t.push("0");else if(t.length<8){for(n=0;n<t.length&&t[n]!=="";n++);let o=[n,1];for(n=9-t.length;n>0;n--)o.push("0");t.splice.apply(t,o)}let i=new Uint8Array(e+16);for(n=0;n<t.length;n++){let o=parseInt(t[n],16);i[e++]=o>>8&255,i[e++]=o&255}return i}throw new Error("invalid ip address")},V0=function(r,e=0,t){e=~~e,t=t??r.length-e;let n=new DataView(r.buffer);if(t===4){let i=[];for(let o=0;o<t;o++)i.push(r[e+o]);return i.join(".")}if(t===16){let i=[];for(let o=0;o<t;o+=2)i.push(n.getUint16(e+o).toString(16));return i.join(":").replace(/(^|:)0(:0)*:0(:|$)/,"$1::$3").replace(/:{3,4}/,"::")}return""};var Yi={},Zu={},qb=[[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"]];qb.forEach(r=>{let e=Gb(...r);Zu[e.code]=e,Yi[e.name]=e});function Gb(r,e,t,n,i){return{code:r,size:e,name:t,resolvable:!!n,path:!!i}}function ge(r){if(typeof r=="number"){if(Zu[r]!=null)return Zu[r];throw new Error(`no protocol with code: ${r}`)}else if(typeof r=="string"){if(Yi[r]!=null)return Yi[r];throw new Error(`no protocol with name: ${r}`)}throw new Error(`invalid protocol id type: ${typeof r}`)}var lS=ge("ip4"),uS=ge("ip6"),hS=ge("ipcidr");function Qu(r,e){switch(ge(r).code){case 4:case 41:return Wb(e);case 42:return $0(e);case 6:case 273:case 33:case 132:return K0(e).toString();case 53:case 54:case 55:case 56:case 400:case 449:case 777:return $0(e);case 421:return Jb(e);case 444:return z0(e);case 445:return z0(e);case 466:return Zb(e);default:return Q(e,"base16")}}function eh(r,e){switch(ge(r).code){case 4:return M0(e);case 41:return M0(e);case 42:return H0(e);case 6:case 273:case 33:case 132:return th(parseInt(e,10));case 53:case 54:case 55:case 56:case 400:case 449:case 777:return H0(e);case 421:return Yb(e);case 444:return Qb(e);case 445:return eE(e);case 466:return Xb(e);default:return Y(e,"base16")}}var Ju=Object.values(_n).map(r=>r.decoder),jb=function(){let r=Ju[0].or(Ju[1]);return Ju.slice(2).forEach(e=>r=r.or(e)),r}();function M0(r){if(!Aa(r))throw new Error("invalid ip address");return Xu(r)}function Wb(r){let e=V0(r,0,r.length);if(e==null)throw new Error("ipBuff is required");if(!Aa(e))throw new Error("invalid ip address");return e}function th(r){let e=new ArrayBuffer(2);return new DataView(e).setUint16(0,r),new Uint8Array(e)}function K0(r){return new DataView(r.buffer).getUint16(r.byteOffset)}function H0(r){let e=Y(r),t=Uint8Array.from(Hi(e.length));return Ee([t,e],t.length+e.length)}function $0(r){let e=ni(r);if(r=r.slice(ft(e)),r.length!==e)throw new Error("inconsistent lengths");return Q(r)}function Yb(r){let e;r[0]==="Q"||r[0]==="1"?e=Et(ke.decode(`z${r}`)).bytes:e=H.parse(r).multihash.bytes;let t=Uint8Array.from(Hi(e.length));return Ee([t,e],t.length+e.length)}function Xb(r){let e=jb.decode(r),t=Uint8Array.from(Hi(e.length));return Ee([t,e],t.length+e.length)}function Zb(r){let e=ni(r),t=r.slice(ft(e));if(t.length!==e)throw new Error("inconsistent lengths");return"u"+Q(t,"base64url")}function Jb(r){let e=ni(r),t=r.slice(ft(e));if(t.length!==e)throw new Error("inconsistent lengths");return Q(t,"base58btc")}function Qb(r){let e=r.split(":");if(e.length!==2)throw new Error(`failed to parse onion addr: ["'${e.join('", "')}'"]' does not contain a port number`);if(e[0].length!==16)throw new Error(`failed to parse onion addr: ${e[0]} not a Tor onion address.`);let t=qe.decode("b"+e[0]),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let i=th(n);return Ee([t,i],t.length+i.length)}function eE(r){let e=r.split(":");if(e.length!==2)throw new Error(`failed to parse onion addr: ["'${e.join('", "')}'"]' does not contain a port number`);if(e[0].length!==56)throw new Error(`failed to parse onion addr: ${e[0]} not a Tor onion3 address.`);let t=qe.decode(`b${e[0]}`),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let i=th(n);return Ee([t,i],t.length+i.length)}function z0(r){let e=r.slice(0,r.length-2),t=r.slice(r.length-2),n=Q(e,"base32"),i=K0(t);return`${n}:${i}`}function q0(r){r=rh(r);let e=[],t=[],n=null,i=r.split("/").slice(1);if(i.length===1&&i[0]==="")return{bytes:new Uint8Array,string:"/",tuples:[],stringTuples:[],path:null};for(let o=0;o<i.length;o++){let s=i[o],a=ge(s);if(a.size===0){e.push([a.code]),t.push([a.code]);continue}if(o++,o>=i.length)throw j0("invalid address: "+r);if(a.path===!0){n=rh(i.slice(o).join("/")),e.push([a.code,eh(a.code,n)]),t.push([a.code,n]);break}let c=eh(a.code,i[o]);e.push([a.code,c]),t.push([a.code,Qu(a.code,c)])}return{string:G0(t),bytes:ih(e),tuples:e,stringTuples:t,path:n}}function nh(r){let e=[],t=[],n=null,i=0;for(;i<r.length;){let o=ni(r,i),s=ft(o),a=ge(o),c=tE(a,r.slice(i+s));if(c===0){e.push([o]),t.push([o]),i+=s;continue}let u=r.slice(i+s,i+s+c);if(i+=c+s,i>r.length)throw j0("Invalid address Uint8Array: "+Q(r,"base16"));e.push([o,u]);let l=Qu(o,u);if(t.push([o,l]),a.path===!0){n=l;break}}return{bytes:Uint8Array.from(r),string:G0(t),tuples:e,stringTuples:t,path:n}}function G0(r){let e=[];return r.map(t=>{let n=ge(t[0]);return e.push(n.name),t.length>1&&t[1]!=null&&e.push(t[1]),null}),rh(e.join("/"))}function ih(r){return Ee(r.map(e=>{let t=ge(e[0]),n=Uint8Array.from(Hi(t.code));return e.length>1&&e[1]!=null&&(n=Ee([n,e[1]])),n}))}function tE(r,e){if(r.size>0)return r.size/8;if(r.size===0)return 0;{let t=ni(e instanceof Uint8Array?e:Uint8Array.from(e));return t+ft(t)}}function rh(r){return"/"+r.trim().split("/").filter(e=>e).join("/")}function j0(r){return new Error("Error parsing address: "+r)}var rE=Symbol.for("nodejs.util.inspect.custom"),oh=Symbol.for("@multiformats/js-multiaddr/multiaddr"),nE=[ge("dns").code,ge("dns4").code,ge("dns6").code,ge("dnsaddr").code],Ia=class r{bytes;#e;#t;#r;#s;[oh]=!0;constructor(e){e==null&&(e="");let t;if(e instanceof Uint8Array)t=nh(e);else if(typeof e=="string"){if(e.length>0&&e.charAt(0)!=="/")throw new Error(`multiaddr "${e}" must start with a "/"`);t=q0(e)}else if(Y0(e))t=nh(e.bytes);else throw new Error("addr must be a string, Buffer, or another Multiaddr");this.bytes=t.bytes,this.#e=t.string,this.#t=t.tuples,this.#r=t.stringTuples,this.#s=t.path}toString(){return this.#e}toJSON(){return this.toString()}toOptions(){let e,t,n,i,o="",s=ge("tcp"),a=ge("udp"),c=ge("ip4"),u=ge("ip6"),l=ge("dns6"),h=ge("ip6zone");for(let[d,f]of this.stringTuples())d===h.code&&(o=`%${f??""}`),nE.includes(d)&&(t=s.name,i=443,n=`${f??""}${o}`,e=d===l.code?6:4),(d===s.code||d===a.code)&&(t=ge(d).name,i=parseInt(f??"")),(d===c.code||d===u.code)&&(t=ge(d).name,n=`${f??""}${o}`,e=d===u.code?6:4);if(e==null||t==null||n==null||i==null)throw new Error('multiaddr must have a valid format: "/{ip4, ip6, dns4, dns6, dnsaddr}/{address}/{tcp, udp}/{port}".');return{family:e,host:n,transport:t,port:i}}protos(){return this.#t.map(([e])=>Object.assign({},ge(e)))}protoCodes(){return this.#t.map(([e])=>e)}protoNames(){return this.#t.map(([e])=>ge(e).name)}tuples(){return this.#t}stringTuples(){return this.#r}encapsulate(e){return e=new r(e),new r(this.toString()+e.toString())}decapsulate(e){let t=e.toString(),n=this.toString(),i=n.lastIndexOf(t);if(i<0)throw new Error(`Address ${this.toString()} does not contain subaddress: ${e.toString()}`);return new r(n.slice(0,i))}decapsulateCode(e){let t=this.tuples();for(let n=t.length-1;n>=0;n--)if(t[n][0]===e)return new r(ih(t.slice(0,n)));return this}getPeerId(){try{let e=[];this.stringTuples().forEach(([n,i])=>{n===Yi.p2p.code&&e.push([n,i]),n===Yi["p2p-circuit"].code&&(e=[])});let t=e.pop();if(t?.[1]!=null){let n=t[1];return n[0]==="Q"||n[0]==="1"?Q(ke.decode(`z${n}`),"base58btc"):Q(H.parse(n).multihash.bytes,"base58btc")}return null}catch{return null}}getPath(){return this.#s}equals(e){return de(this.bytes,e.bytes)}async resolve(e){let t=this.protos().find(o=>o.resolvable);if(t==null)return[this];let n=W0.get(t.name);if(n==null)throw new F(`no available resolver for ${t.name}`,"ERR_NO_AVAILABLE_RESOLVER");return(await n(this,e)).map(o=>new r(o))}nodeAddress(){let e=this.toOptions();if(e.transport!=="tcp"&&e.transport!=="udp")throw new Error(`multiaddr must have a valid format - no protocol with name: "${e.transport}". Must have a valid transport protocol: "{tcp, udp}"`);return{family:e.family,address:e.host,port:e.port}}isThinWaistAddress(e){let t=(e??this).protos();return!(t.length!==2||t[0].code!==4&&t[0].code!==41||t[1].code!==6&&t[1].code!==273)}[rE](){return`Multiaddr(${this.#e})`}};var W0=new Map;function Y0(r){return!!r?.[oh]}function sh(r){return new Ia(r)}async function*Sa(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 Ah={};Ae(Ah,{Ed25519PrivateKey:()=>hi,Ed25519PublicKey:()=>rs,generateKeyPair:()=>p3,generateKeyPairFromSeed:()=>Ep,unmarshalEd25519PrivateKey:()=>d3,unmarshalEd25519PublicKey:()=>f3});function Mt(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}function Xi(r){if(!Number.isSafeInteger(r)||r<0)throw new Error(`Wrong positive integer: ${r}`)}function iE(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}function ah(r,...e){if(!iE(r))throw new Error("Expected Uint8Array");if(e.length>0&&!e.includes(r.length))throw new Error(`Expected Uint8Array of length ${e}, not of length=${r.length}`)}function _a(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");Xi(r.outputLen),Xi(r.blockLen)}function Zi(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 X0(r,e){ah(r);let t=e.outputLen;if(r.length<t)throw new Error(`digestInto() expects output buffer of length at least ${t}`)}var ka=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function Z0(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}var Qi=r=>new DataView(r.buffer,r.byteOffset,r.byteLength),Xt=(r,e)=>r<<32-e|r>>>e,oE=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;if(!oE)throw new Error("Non little-endian hardware is not supported");var sE=async()=>{};async function J0(r,e,t){let n=Date.now();for(let i=0;i<r;i++){t(i);let o=Date.now()-n;o>=0&&o<e||(await sE(),n+=o)}}function ch(r){if(typeof r!="string")throw new Error(`utf8ToBytes expected string, got ${typeof r}`);return new Uint8Array(new TextEncoder().encode(r))}function kn(r){if(typeof r=="string"&&(r=ch(r)),!Z0(r))throw new Error(`expected Uint8Array, got ${typeof r}`);return r}function Ra(...r){let e=0;for(let n=0;n<r.length;n++){let i=r[n];if(!Z0(i))throw new Error("Uint8Array expected");e+=i.length}let t=new Uint8Array(e);for(let n=0,i=0;n<r.length;n++){let o=r[n];t.set(o,i),i+=o.length}return t}var Ji=class{clone(){return this._cloneInto()}},aE={}.toString;function Q0(r,e){if(e!==void 0&&aE.call(e)!=="[object Object]")throw new Error("Options should be object or undefined");return Object.assign(r,e)}function Ta(r){let e=n=>r().update(kn(n)).digest(),t=r();return e.outputLen=t.outputLen,e.blockLen=t.blockLen,e.create=()=>r(),e}function eo(r=32){if(ka&&typeof ka.getRandomValues=="function")return ka.getRandomValues(new Uint8Array(r));throw new Error("crypto.getRandomValues must be defined")}function cE(r,e,t,n){if(typeof r.setBigUint64=="function")return r.setBigUint64(e,t,n);let i=BigInt(32),o=BigInt(4294967295),s=Number(t>>i&o),a=Number(t&o),c=n?4:0,u=n?0:4;r.setUint32(e+c,s,n),r.setUint32(e+u,a,n)}var to=class extends Ji{constructor(e,t,n,i){super(),this.blockLen=e,this.outputLen=t,this.padOffset=n,this.isLE=i,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(e),this.view=Qi(this.buffer)}update(e){Zi(this);let{view:t,buffer:n,blockLen:i}=this;e=kn(e);let o=e.length;for(let s=0;s<o;){let a=Math.min(i-this.pos,o-s);if(a===i){let c=Qi(e);for(;i<=o-s;s+=i)this.process(c,s);continue}n.set(e.subarray(s,s+a),this.pos),this.pos+=a,s+=a,this.pos===i&&(this.process(t,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){Zi(this),X0(e,this),this.finished=!0;let{buffer:t,view:n,blockLen:i,isLE:o}=this,{pos:s}=this;t[s++]=128,this.buffer.subarray(s).fill(0),this.padOffset>i-s&&(this.process(n,0),s=0);for(let h=s;h<i;h++)t[h]=0;cE(n,i-8,BigInt(this.length*8),o),this.process(n,0);let a=Qi(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 h=0;h<u;h++)a.setUint32(4*h,l[h],o)}digest(){let{buffer:e,outputLen:t}=this;this.digestInto(e);let n=e.slice(0,t);return this.destroy(),n}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());let{blockLen:t,buffer:n,length:i,finished:o,destroyed:s,pos:a}=this;return e.length=i,e.pos=a,e.finished=o,e.destroyed=s,i%t&&e.buffer.set(n),e}};var Ca=BigInt(4294967295),lh=BigInt(32);function ep(r,e=!1){return e?{h:Number(r&Ca),l:Number(r>>lh&Ca)}:{h:Number(r>>lh&Ca)|0,l:Number(r&Ca)|0}}function lE(r,e=!1){let t=new Uint32Array(r.length),n=new Uint32Array(r.length);for(let i=0;i<r.length;i++){let{h:o,l:s}=ep(r[i],e);[t[i],n[i]]=[o,s]}return[t,n]}var uE=(r,e)=>BigInt(r>>>0)<<lh|BigInt(e>>>0),hE=(r,e,t)=>r>>>t,dE=(r,e,t)=>r<<32-t|e>>>t,fE=(r,e,t)=>r>>>t|e<<32-t,pE=(r,e,t)=>r<<32-t|e>>>t,mE=(r,e,t)=>r<<64-t|e>>>t-32,yE=(r,e,t)=>r>>>t-32|e<<64-t,gE=(r,e)=>e,wE=(r,e)=>r,xE=(r,e,t)=>r<<t|e>>>32-t,bE=(r,e,t)=>e<<t|r>>>32-t,EE=(r,e,t)=>e<<t-32|r>>>64-t,vE=(r,e,t)=>r<<t-32|e>>>64-t;function BE(r,e,t,n){let i=(e>>>0)+(n>>>0);return{h:r+t+(i/2**32|0)|0,l:i|0}}var AE=(r,e,t)=>(r>>>0)+(e>>>0)+(t>>>0),IE=(r,e,t,n)=>e+t+n+(r/2**32|0)|0,SE=(r,e,t,n)=>(r>>>0)+(e>>>0)+(t>>>0)+(n>>>0),_E=(r,e,t,n,i)=>e+t+n+i+(r/2**32|0)|0,kE=(r,e,t,n,i)=>(r>>>0)+(e>>>0)+(t>>>0)+(n>>>0)+(i>>>0),RE=(r,e,t,n,i,o)=>e+t+n+i+o+(r/2**32|0)|0;var TE={fromBig:ep,split:lE,toBig:uE,shrSH:hE,shrSL:dE,rotrSH:fE,rotrSL:pE,rotrBH:mE,rotrBL:yE,rotr32H:gE,rotr32L:wE,rotlSH:xE,rotlSL:bE,rotlBH:EE,rotlBL:vE,add:BE,add3L:AE,add3H:IE,add4L:SE,add4H:_E,add5H:RE,add5L:kE},J=TE;var[CE,NE]=J.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))),Rn=new Uint32Array(80),Tn=new Uint32Array(80),uh=class extends to{constructor(){super(128,64,16,!1),this.Ah=1779033703,this.Al=-205731576,this.Bh=-1150833019,this.Bl=-2067093701,this.Ch=1013904242,this.Cl=-23791573,this.Dh=-1521486534,this.Dl=1595750129,this.Eh=1359893119,this.El=-1377402159,this.Fh=-1694144372,this.Fl=725511199,this.Gh=528734635,this.Gl=-79577749,this.Hh=1541459225,this.Hl=327033209}get(){let{Ah:e,Al:t,Bh:n,Bl:i,Ch:o,Cl:s,Dh:a,Dl:c,Eh:u,El:l,Fh:h,Fl:p,Gh:d,Gl:f,Hh:m,Hl:y}=this;return[e,t,n,i,o,s,a,c,u,l,h,p,d,f,m,y]}set(e,t,n,i,o,s,a,c,u,l,h,p,d,f,m,y){this.Ah=e|0,this.Al=t|0,this.Bh=n|0,this.Bl=i|0,this.Ch=o|0,this.Cl=s|0,this.Dh=a|0,this.Dl=c|0,this.Eh=u|0,this.El=l|0,this.Fh=h|0,this.Fl=p|0,this.Gh=d|0,this.Gl=f|0,this.Hh=m|0,this.Hl=y|0}process(e,t){for(let x=0;x<16;x++,t+=4)Rn[x]=e.getUint32(t),Tn[x]=e.getUint32(t+=4);for(let x=16;x<80;x++){let A=Rn[x-15]|0,I=Tn[x-15]|0,B=J.rotrSH(A,I,1)^J.rotrSH(A,I,8)^J.shrSH(A,I,7),v=J.rotrSL(A,I,1)^J.rotrSL(A,I,8)^J.shrSL(A,I,7),E=Rn[x-2]|0,R=Tn[x-2]|0,N=J.rotrSH(E,R,19)^J.rotrBH(E,R,61)^J.shrSH(E,R,6),T=J.rotrSL(E,R,19)^J.rotrBL(E,R,61)^J.shrSL(E,R,6),M=J.add4L(v,T,Tn[x-7],Tn[x-16]),D=J.add4H(M,B,N,Rn[x-7],Rn[x-16]);Rn[x]=D|0,Tn[x]=M|0}let{Ah:n,Al:i,Bh:o,Bl:s,Ch:a,Cl:c,Dh:u,Dl:l,Eh:h,El:p,Fh:d,Fl:f,Gh:m,Gl:y,Hh:g,Hl:w}=this;for(let x=0;x<80;x++){let A=J.rotrSH(h,p,14)^J.rotrSH(h,p,18)^J.rotrBH(h,p,41),I=J.rotrSL(h,p,14)^J.rotrSL(h,p,18)^J.rotrBL(h,p,41),B=h&d^~h&m,v=p&f^~p&y,E=J.add5L(w,I,v,NE[x],Tn[x]),R=J.add5H(E,g,A,B,CE[x],Rn[x]),N=E|0,T=J.rotrSH(n,i,28)^J.rotrBH(n,i,34)^J.rotrBH(n,i,39),M=J.rotrSL(n,i,28)^J.rotrBL(n,i,34)^J.rotrBL(n,i,39),D=n&o^n&a^o&a,ne=i&s^i&c^s&c;g=m|0,w=y|0,m=d|0,y=f|0,d=h|0,f=p|0,{h,l:p}=J.add(u|0,l|0,R|0,N|0),u=a|0,l=c|0,a=o|0,c=s|0,o=n|0,s=i|0;let _=J.add3L(N,M,ne);n=J.add3H(_,R,T,D),i=_|0}({h:n,l:i}=J.add(this.Ah|0,this.Al|0,n|0,i|0)),{h:o,l:s}=J.add(this.Bh|0,this.Bl|0,o|0,s|0),{h:a,l:c}=J.add(this.Ch|0,this.Cl|0,a|0,c|0),{h:u,l}=J.add(this.Dh|0,this.Dl|0,u|0,l|0),{h,l:p}=J.add(this.Eh|0,this.El|0,h|0,p|0),{h:d,l:f}=J.add(this.Fh|0,this.Fl|0,d|0,f|0),{h:m,l:y}=J.add(this.Gh|0,this.Gl|0,m|0,y|0),{h:g,l:w}=J.add(this.Hh|0,this.Hl|0,g|0,w|0),this.set(n,i,o,s,a,c,u,l,h,p,d,f,m,y,g,w)}roundClean(){Rn.fill(0),Tn.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 ro=Ta(()=>new uh);var Ua={};Ae(Ua,{bitGet:()=>VE,bitLen:()=>FE,bitMask:()=>es,bitSet:()=>ME,bytesToHex:()=>Hr,bytesToNumberBE:()=>$r,bytesToNumberLE:()=>Cn,concatBytes:()=>zr,createHmacDrbg:()=>fh,ensureBytes:()=>Se,equalBytes:()=>PE,hexToBytes:()=>ci,hexToNumber:()=>dh,isBytes:()=>Zt,numberToBytesBE:()=>Nn,numberToBytesLE:()=>li,numberToHexUnpadded:()=>ip,numberToVarBytesBE:()=>DE,utf8ToBytes:()=>OE,validateObject:()=>fr});var np=BigInt(0),Na=BigInt(1),UE=BigInt(2);function Zt(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}var LE=Array.from({length:256},(r,e)=>e.toString(16).padStart(2,"0"));function Hr(r){if(!Zt(r))throw new Error("Uint8Array expected");let e="";for(let t=0;t<r.length;t++)e+=LE[r[t]];return e}function ip(r){let e=r.toString(16);return e.length&1?`0${e}`:e}function dh(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 tp(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 ci(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);let e=r.length,t=e/2;if(e%2)throw new Error("padded hex string expected, got unpadded hex of length "+e);let n=new Uint8Array(t);for(let i=0,o=0;i<t;i++,o+=2){let s=tp(r.charCodeAt(o)),a=tp(r.charCodeAt(o+1));if(s===void 0||a===void 0){let c=r[o]+r[o+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+o)}n[i]=s*16+a}return n}function $r(r){return dh(Hr(r))}function Cn(r){if(!Zt(r))throw new Error("Uint8Array expected");return dh(Hr(Uint8Array.from(r).reverse()))}function Nn(r,e){return ci(r.toString(16).padStart(e*2,"0"))}function li(r,e){return Nn(r,e).reverse()}function DE(r){return ci(ip(r))}function Se(r,e,t){let n;if(typeof e=="string")try{n=ci(e)}catch(o){throw new Error(`${r} must be valid hex string, got "${e}". Cause: ${o}`)}else if(Zt(e))n=Uint8Array.from(e);else throw new Error(`${r} must be hex string or Uint8Array`);let i=n.length;if(typeof t=="number"&&i!==t)throw new Error(`${r} expected ${t} bytes, got ${i}`);return n}function zr(...r){let e=0;for(let i=0;i<r.length;i++){let o=r[i];if(!Zt(o))throw new Error("Uint8Array expected");e+=o.length}let t=new Uint8Array(e),n=0;for(let i=0;i<r.length;i++){let o=r[i];t.set(o,n),n+=o.length}return t}function PE(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 OE(r){if(typeof r!="string")throw new Error(`utf8ToBytes expected string, got ${typeof r}`);return new Uint8Array(new TextEncoder().encode(r))}function FE(r){let e;for(e=0;r>np;r>>=Na,e+=1);return e}function VE(r,e){return r>>BigInt(e)&Na}var ME=(r,e,t)=>r|(t?Na:np)<<BigInt(e),es=r=>(UE<<BigInt(r-1))-Na,hh=r=>new Uint8Array(r),rp=r=>Uint8Array.from(r);function fh(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=hh(r),i=hh(r),o=0,s=()=>{n.fill(1),i.fill(0),o=0},a=(...h)=>t(i,n,...h),c=(h=hh())=>{i=a(rp([0]),h),n=a(),h.length!==0&&(i=a(rp([1]),h),n=a())},u=()=>{if(o++>=1e3)throw new Error("drbg: tried 1000 values");let h=0,p=[];for(;h<e;){n=a();let d=n.slice();p.push(d),h+=n.length}return zr(...p)};return(h,p)=>{s(),c(h);let d;for(;!(d=p(u()));)c();return s(),d}}var HE={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"||Zt(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 fr(r,e,t={}){let n=(i,o,s)=>{let a=HE[o];if(typeof a!="function")throw new Error(`Invalid validator "${o}", expected function`);let c=r[i];if(!(s&&c===void 0)&&!a(c,r))throw new Error(`Invalid param ${String(i)}=${c} (${typeof c}), expected ${o}`)};for(let[i,o]of Object.entries(e))n(i,o,!1);for(let[i,o]of Object.entries(t))n(i,o,!0);return r}var Oe=BigInt(0),we=BigInt(1),ui=BigInt(2),$E=BigInt(3),ph=BigInt(4),op=BigInt(5),sp=BigInt(8),zE=BigInt(9),KE=BigInt(16);function ye(r,e){let t=r%e;return t>=Oe?t:e+t}function qE(r,e,t){if(t<=Oe||e<Oe)throw new Error("Expected power/modulo > 0");if(t===we)return Oe;let n=we;for(;e>Oe;)e&we&&(n=n*r%t),r=r*r%t,e>>=we;return n}function xe(r,e,t){let n=r;for(;e-- >Oe;)n*=n,n%=t;return n}function La(r,e){if(r===Oe||e<=Oe)throw new Error(`invert: expected positive integers, got n=${r} mod=${e}`);let t=ye(r,e),n=e,i=Oe,o=we,s=we,a=Oe;for(;t!==Oe;){let u=n/t,l=n%t,h=i-s*u,p=o-a*u;n=t,t=l,i=s,o=a,s=h,a=p}if(n!==we)throw new Error("invert: does not exist");return ye(i,e)}function GE(r){let e=(r-we)/ui,t,n,i;for(t=r-we,n=0;t%ui===Oe;t/=ui,n++);for(i=ui;i<r&&qE(i,e,r)!==r-we;i++);if(n===1){let s=(r+we)/ph;return function(c,u){let l=c.pow(u,s);if(!c.eql(c.sqr(l),u))throw new Error("Cannot find square root");return l}}let o=(t+we)/ui;return function(a,c){if(a.pow(c,e)===a.neg(a.ONE))throw new Error("Cannot find square root");let u=n,l=a.pow(a.mul(a.ONE,i),t),h=a.pow(c,o),p=a.pow(c,t);for(;!a.eql(p,a.ONE);){if(a.eql(p,a.ZERO))return a.ZERO;let d=1;for(let m=a.sqr(p);d<u&&!a.eql(m,a.ONE);d++)m=a.sqr(m);let f=a.pow(l,we<<BigInt(u-d-1));l=a.sqr(f),h=a.mul(h,f),p=a.mul(p,l),u=d}return h}}function jE(r){if(r%ph===$E){let e=(r+we)/ph;return function(n,i){let o=n.pow(i,e);if(!n.eql(n.sqr(o),i))throw new Error("Cannot find square root");return o}}if(r%sp===op){let e=(r-op)/sp;return function(n,i){let o=n.mul(i,ui),s=n.pow(o,e),a=n.mul(i,s),c=n.mul(n.mul(a,ui),s),u=n.mul(a,n.sub(c,n.ONE));if(!n.eql(n.sqr(u),i))throw new Error("Cannot find square root");return u}}return r%KE,GE(r)}var ap=(r,e)=>(ye(r,e)&we)===we,WE=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function mh(r){let e={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},t=WE.reduce((n,i)=>(n[i]="function",n),e);return fr(r,t)}function YE(r,e,t){if(t<Oe)throw new Error("Expected power > 0");if(t===Oe)return r.ONE;if(t===we)return e;let n=r.ONE,i=e;for(;t>Oe;)t&we&&(n=r.mul(n,i)),i=r.sqr(i),t>>=we;return n}function XE(r,e){let t=new Array(e.length),n=e.reduce((o,s,a)=>r.is0(s)?o:(t[a]=o,r.mul(o,s)),r.ONE),i=r.inv(n);return e.reduceRight((o,s,a)=>r.is0(s)?o:(t[a]=r.mul(o,t[a]),r.mul(o,s)),i),t}function yh(r,e){let t=e!==void 0?e:r.toString(2).length,n=Math.ceil(t/8);return{nBitLength:t,nByteLength:n}}function Da(r,e,t=!1,n={}){if(r<=Oe)throw new Error(`Expected Field ORDER > 0, got ${r}`);let{nBitLength:i,nByteLength:o}=yh(r,e);if(o>2048)throw new Error("Field lengths over 2048 bytes are not supported");let s=jE(r),a=Object.freeze({ORDER:r,BITS:i,BYTES:o,MASK:es(i),ZERO:Oe,ONE:we,create:c=>ye(c,r),isValid:c=>{if(typeof c!="bigint")throw new Error(`Invalid field element: expected bigint, got ${typeof c}`);return Oe<=c&&c<r},is0:c=>c===Oe,isOdd:c=>(c&we)===we,neg:c=>ye(-c,r),eql:(c,u)=>c===u,sqr:c=>ye(c*c,r),add:(c,u)=>ye(c+u,r),sub:(c,u)=>ye(c-u,r),mul:(c,u)=>ye(c*u,r),pow:(c,u)=>YE(a,c,u),div:(c,u)=>ye(c*La(u,r),r),sqrN:c=>c*c,addN:(c,u)=>c+u,subN:(c,u)=>c-u,mulN:(c,u)=>c*u,inv:c=>La(c,r),sqrt:n.sqrt||(c=>s(a,c)),invertBatch:c=>XE(a,c),cmov:(c,u,l)=>l?u:c,toBytes:c=>t?li(c,o):Nn(c,o),fromBytes:c=>{if(c.length!==o)throw new Error(`Fp.fromBytes: expected ${o}, got ${c.length}`);return t?Cn(c):$r(c)}});return Object.freeze(a)}function cp(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 lp(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 gh(r){let e=lp(r);return e+Math.ceil(e/2)}function up(r,e,t=!1){let n=r.length,i=lp(e),o=gh(e);if(n<16||n<o||n>1024)throw new Error(`expected ${o}-1024 bytes of input, got ${n}`);let s=t?$r(r):Cn(r),a=ye(s,e-we)+we;return t?li(a,i):Nn(a,i)}var JE=BigInt(0),wh=BigInt(1);function Pa(r,e){let t=(i,o)=>{let s=o.negate();return i?s:o},n=i=>{let o=Math.ceil(e/i)+1,s=2**(i-1);return{windows:o,windowSize:s}};return{constTimeNegate:t,unsafeLadder(i,o){let s=r.ZERO,a=i;for(;o>JE;)o&wh&&(s=s.add(a)),a=a.double(),o>>=wh;return s},precomputeWindow(i,o){let{windows:s,windowSize:a}=n(o),c=[],u=i,l=u;for(let h=0;h<s;h++){l=u,c.push(l);for(let p=1;p<a;p++)l=l.add(u),c.push(l);u=l.double()}return c},wNAF(i,o,s){let{windows:a,windowSize:c}=n(i),u=r.ZERO,l=r.BASE,h=BigInt(2**i-1),p=2**i,d=BigInt(i);for(let f=0;f<a;f++){let m=f*c,y=Number(s&h);s>>=d,y>c&&(y-=p,s+=wh);let g=m,w=m+Math.abs(y)-1,x=f%2!==0,A=y<0;y===0?l=l.add(t(x,o[g])):u=u.add(t(A,o[w]))}return{p:u,f:l}},wNAFCached(i,o,s,a){let c=i._WINDOW_SIZE||1,u=o.get(i);return u||(u=this.precomputeWindow(i,c),c!==1&&o.set(i,a(u))),this.wNAF(c,u,s)}}}function ts(r){return mh(r.Fp),fr(r,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...yh(r.n,r.nBitLength),...r,p:r.Fp.ORDER})}var Jt=BigInt(0),It=BigInt(1),Oa=BigInt(2),QE=BigInt(8),e3={zip215:!0};function t3(r){let e=ts(r);return fr(r,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...e})}function Fa(r){let e=t3(r),{Fp:t,n,prehash:i,hash:o,randomBytes:s,nByteLength:a,h:c}=e,u=Oa<<BigInt(a*8)-It,l=t.create,h=e.uvRatio||((U,k)=>{try{return{isValid:!0,value:t.sqrt(U*t.inv(k))}}catch{return{isValid:!1,value:Jt}}}),p=e.adjustScalarBytes||(U=>U),d=e.domain||((U,k,z)=>{if(k.length||z)throw new Error("Contexts/pre-hash are not supported");return U}),f=U=>typeof U=="bigint"&&Jt<U,m=(U,k)=>f(U)&&f(k)&&U<k,y=U=>U===Jt||m(U,u);function g(U,k){if(m(U,k))return U;throw new Error(`Expected valid scalar < ${k}, got ${typeof U} ${U}`)}function w(U){return U===Jt?U:g(U,n)}let x=new Map;function A(U){if(!(U instanceof I))throw new Error("ExtendedPoint expected")}class I{constructor(k,z,j,Z){if(this.ex=k,this.ey=z,this.ez=j,this.et=Z,!y(k))throw new Error("x required");if(!y(z))throw new Error("y required");if(!y(j))throw new Error("z required");if(!y(Z))throw new Error("t required")}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(k){if(k instanceof I)throw new Error("extended point not allowed");let{x:z,y:j}=k||{};if(!y(z)||!y(j))throw new Error("invalid affine point");return new I(z,j,It,l(z*j))}static normalizeZ(k){let z=t.invertBatch(k.map(j=>j.ez));return k.map((j,Z)=>j.toAffine(z[Z])).map(I.fromAffine)}_setWindowSize(k){this._WINDOW_SIZE=k,x.delete(this)}assertValidity(){let{a:k,d:z}=e;if(this.is0())throw new Error("bad point: ZERO");let{ex:j,ey:Z,ez:te,et:ie}=this,pe=l(j*j),ae=l(Z*Z),le=l(te*te),Ce=l(le*le),Be=l(pe*k),ze=l(le*l(Be+ae)),Ke=l(Ce+l(z*l(pe*ae)));if(ze!==Ke)throw new Error("bad point: equation left != right (1)");let Pe=l(j*Z),Ze=l(te*ie);if(Pe!==Ze)throw new Error("bad point: equation left != right (2)")}equals(k){A(k);let{ex:z,ey:j,ez:Z}=this,{ex:te,ey:ie,ez:pe}=k,ae=l(z*pe),le=l(te*Z),Ce=l(j*pe),Be=l(ie*Z);return ae===le&&Ce===Be}is0(){return this.equals(I.ZERO)}negate(){return new I(l(-this.ex),this.ey,this.ez,l(-this.et))}double(){let{a:k}=e,{ex:z,ey:j,ez:Z}=this,te=l(z*z),ie=l(j*j),pe=l(Oa*l(Z*Z)),ae=l(k*te),le=z+j,Ce=l(l(le*le)-te-ie),Be=ae+ie,ze=Be-pe,Ke=ae-ie,Pe=l(Ce*ze),Ze=l(Be*Ke),Dr=l(Ce*Ke),Qn=l(ze*Be);return new I(Pe,Ze,Qn,Dr)}add(k){A(k);let{a:z,d:j}=e,{ex:Z,ey:te,ez:ie,et:pe}=this,{ex:ae,ey:le,ez:Ce,et:Be}=k;if(z===BigInt(-1)){let Uf=l((te-Z)*(le+ae)),Lf=l((te+Z)*(le-ae)),Zl=l(Lf-Uf);if(Zl===Jt)return this.double();let Df=l(ie*Oa*Be),Pf=l(pe*Oa*Ce),Of=Pf+Df,Ff=Lf+Uf,Vf=Pf-Df,N2=l(Of*Zl),U2=l(Ff*Vf),L2=l(Of*Vf),D2=l(Zl*Ff);return new I(N2,U2,D2,L2)}let ze=l(Z*ae),Ke=l(te*le),Pe=l(pe*j*Be),Ze=l(ie*Ce),Dr=l((Z+te)*(ae+le)-ze-Ke),Qn=Ze-Pe,zo=Ze+Pe,Nf=l(Ke-z*ze),k2=l(Dr*Qn),R2=l(zo*Nf),T2=l(Dr*Nf),C2=l(Qn*zo);return new I(k2,R2,C2,T2)}subtract(k){return this.add(k.negate())}wNAF(k){return E.wNAFCached(this,x,k,I.normalizeZ)}multiply(k){let{p:z,f:j}=this.wNAF(g(k,n));return I.normalizeZ([z,j])[0]}multiplyUnsafe(k){let z=w(k);return z===Jt?v:this.equals(v)||z===It?this:this.equals(B)?this.wNAF(z).p:E.unsafeLadder(this,z)}isSmallOrder(){return this.multiplyUnsafe(c).is0()}isTorsionFree(){return E.unsafeLadder(this,n).is0()}toAffine(k){let{ex:z,ey:j,ez:Z}=this,te=this.is0();k==null&&(k=te?QE:t.inv(Z));let ie=l(z*k),pe=l(j*k),ae=l(Z*k);if(te)return{x:Jt,y:It};if(ae!==It)throw new Error("invZ was invalid");return{x:ie,y:pe}}clearCofactor(){let{h:k}=e;return k===It?this:this.multiplyUnsafe(k)}static fromHex(k,z=!1){let{d:j,a:Z}=e,te=t.BYTES;k=Se("pointHex",k,te);let ie=k.slice(),pe=k[te-1];ie[te-1]=pe&-129;let ae=Cn(ie);ae===Jt||(z?g(ae,u):g(ae,t.ORDER));let le=l(ae*ae),Ce=l(le-It),Be=l(j*le-Z),{isValid:ze,value:Ke}=h(Ce,Be);if(!ze)throw new Error("Point.fromHex: invalid y coordinate");let Pe=(Ke&It)===It,Ze=(pe&128)!==0;if(!z&&Ke===Jt&&Ze)throw new Error("Point.fromHex: x=0 and x_0=1");return Ze!==Pe&&(Ke=l(-Ke)),I.fromAffine({x:Ke,y:ae})}static fromPrivateKey(k){return T(k).point}toRawBytes(){let{x:k,y:z}=this.toAffine(),j=li(z,t.BYTES);return j[j.length-1]|=k&It?128:0,j}toHex(){return Hr(this.toRawBytes())}}I.BASE=new I(e.Gx,e.Gy,It,l(e.Gx*e.Gy)),I.ZERO=new I(Jt,It,It,Jt);let{BASE:B,ZERO:v}=I,E=Pa(I,a*8);function R(U){return ye(U,n)}function N(U){return R(Cn(U))}function T(U){let k=a;U=Se("private key",U,k);let z=Se("hashed private key",o(U),2*k),j=p(z.slice(0,k)),Z=z.slice(k,2*k),te=N(j),ie=B.multiply(te),pe=ie.toRawBytes();return{head:j,prefix:Z,scalar:te,point:ie,pointBytes:pe}}function M(U){return T(U).pointBytes}function D(U=new Uint8Array,...k){let z=zr(...k);return N(o(d(z,Se("context",U),!!i)))}function ne(U,k,z={}){U=Se("message",U),i&&(U=i(U));let{prefix:j,scalar:Z,pointBytes:te}=T(k),ie=D(z.context,j,U),pe=B.multiply(ie).toRawBytes(),ae=D(z.context,pe,te,U),le=R(ie+ae*Z);w(le);let Ce=zr(pe,li(le,t.BYTES));return Se("result",Ce,a*2)}let _=e3;function L(U,k,z,j=_){let{context:Z,zip215:te}=j,ie=t.BYTES;U=Se("signature",U,2*ie),k=Se("message",k),i&&(k=i(k));let pe=Cn(U.slice(ie,2*ie)),ae,le,Ce;try{ae=I.fromHex(z,te),le=I.fromHex(U.slice(0,ie),te),Ce=B.multiplyUnsafe(pe)}catch{return!1}if(!te&&ae.isSmallOrder())return!1;let Be=D(Z,le.toRawBytes(),ae.toRawBytes(),k);return le.add(ae.multiplyUnsafe(Be)).subtract(Ce).clearCofactor().equals(I.ZERO)}return B._setWindowSize(8),{CURVE:e,getPublicKey:M,sign:ne,verify:L,ExtendedPoint:I,utils:{getExtendedPublicKey:T,randomPrivateKey:()=>s(t.BYTES),precompute(U=8,k=I.BASE){return k._setWindowSize(U),k.multiply(BigInt(3)),k}}}}var bh=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),hp=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),u_=BigInt(0),r3=BigInt(1),xh=BigInt(2),n3=BigInt(5),dp=BigInt(10),i3=BigInt(20),o3=BigInt(40),fp=BigInt(80);function s3(r){let e=bh,n=r*r%e*r%e,i=xe(n,xh,e)*n%e,o=xe(i,r3,e)*r%e,s=xe(o,n3,e)*o%e,a=xe(s,dp,e)*s%e,c=xe(a,i3,e)*a%e,u=xe(c,o3,e)*c%e,l=xe(u,fp,e)*u%e,h=xe(l,fp,e)*u%e,p=xe(h,dp,e)*s%e;return{pow_p_5_8:xe(p,xh,e)*r%e,b2:n}}function a3(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}function c3(r,e){let t=bh,n=ye(e*e*e,t),i=ye(n*n*e,t),o=s3(r*i).pow_p_5_8,s=ye(r*n*o,t),a=ye(e*s*s,t),c=s,u=ye(s*hp,t),l=a===r,h=a===ye(-r,t),p=a===ye(-r*hp,t);return l&&(s=c),(h||p)&&(s=u),ap(s,t)&&(s=ye(-s,t)),{isValid:l||h,value:s}}var Kr=Da(bh,void 0,!0),Eh={a:BigInt(-1),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:Kr,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:BigInt(8),Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:ro,randomBytes:eo,adjustScalarBytes:a3,uvRatio:c3},no=Fa(Eh);function pp(r,e,t){if(e.length>255)throw new Error("Context is too big");return Ra(ch("SigEd25519 no Ed25519 collisions"),new Uint8Array([t?1:0,e.length]),e,r)}var h_=Fa({...Eh,domain:pp}),d_=Fa({...Eh,domain:pp,prehash:ro});var l3=(Kr.ORDER+BigInt(3))/BigInt(8),f_=Kr.pow(xh,l3),p_=Kr.sqrt(Kr.neg(Kr.ONE)),m_=(Kr.ORDER-BigInt(5))/BigInt(8),y_=BigInt(486662);var g_=cp(Kr,Kr.neg(BigInt(486664)));var w_=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),x_=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),b_=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),E_=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952");var v_=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");var io=32,qr=64,Va=32;function mp(){let r=no.utils.randomPrivateKey(),e=no.getPublicKey(r);return{privateKey:xp(r,e),publicKey:e}}function yp(r){if(r.length!==Va)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=no.getPublicKey(e);return{privateKey:xp(e,t),publicKey:t}}function gp(r,e){let t=r.subarray(0,Va);return no.sign(e instanceof Uint8Array?e:e.subarray(),t)}function wp(r,e,t){return no.verify(e,t instanceof Uint8Array?t:t.subarray(),r)}function xp(r,e){let t=new Uint8Array(qr);for(let n=0;n<Va;n++)t[n]=r[n],t[Va+n]=e[n];return t}var ot={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 vh={alg:"A128GCM",ext:!0,k:"scm9jmO_4BJAgdwWGVulLg",key_ops:["encrypt","decrypt"],kty:"oct"};function bp(r){let e=r?.algorithm??"AES-GCM",t=r?.keyLength??16,n=r?.nonceLength??12,i=r?.digest??"SHA-256",o=r?.saltLength??16,s=r?.iterations??32767,a=ot.get();t*=8;async function c(h,p){let d=a.getRandomValues(new Uint8Array(o)),f=a.getRandomValues(new Uint8Array(n)),m={name:e,iv:f};typeof p=="string"&&(p=Y(p));let y;if(p.length===0){y=await a.subtle.importKey("jwk",vh,{name:"AES-GCM"},!0,["encrypt"]);try{let w={name:"PBKDF2",salt:d,iterations:s,hash:{name:i}},x=await a.subtle.importKey("raw",p,{name:"PBKDF2"},!1,["deriveKey"]);y=await a.subtle.deriveKey(w,x,{name:e,length:t},!0,["encrypt"])}catch{y=await a.subtle.importKey("jwk",vh,{name:"AES-GCM"},!0,["encrypt"])}}else{let w={name:"PBKDF2",salt:d,iterations:s,hash:{name:i}},x=await a.subtle.importKey("raw",p,{name:"PBKDF2"},!1,["deriveKey"]);y=await a.subtle.deriveKey(w,x,{name:e,length:t},!0,["encrypt"])}let g=await a.subtle.encrypt(m,y,h);return Ee([d,m.iv,new Uint8Array(g)])}async function u(h,p){let d=h.subarray(0,o),f=h.subarray(o,o+n),m=h.subarray(o+n),y={name:e,iv:f};typeof p=="string"&&(p=Y(p));let g;if(p.length===0)try{let x={name:"PBKDF2",salt:d,iterations:s,hash:{name:i}},A=await a.subtle.importKey("raw",p,{name:"PBKDF2"},!1,["deriveKey"]);g=await a.subtle.deriveKey(x,A,{name:e,length:t},!0,["decrypt"])}catch{g=await a.subtle.importKey("jwk",vh,{name:"AES-GCM"},!0,["decrypt"])}else{let x={name:"PBKDF2",salt:d,iterations:s,hash:{name:i}},A=await a.subtle.importKey("raw",p,{name:"PBKDF2"},!1,["deriveKey"]);g=await a.subtle.deriveKey(x,A,{name:e,length:t},!0,["decrypt"])}let w=await a.subtle.decrypt(y,g,m);return new Uint8Array(w)}return{encrypt:c,decrypt:u}}async function oo(r,e){let n=await bp().encrypt(r,e);return Pr.encode(n)}var be;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.Secp256k1="Secp256k1"})(be||(be={}));var Bh;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.Secp256k1=2]="Secp256k1"})(Bh||(Bh={}));(function(r){r.codec=()=>si(Bh)})(be||(be={}));var pr;(function(r){let e;r.codec=()=>(e==null&&(e=Ft((t,n,i={})=>{i.lengthDelimited!==!1&&n.fork(),t.Type!=null&&(n.uint32(8),be.codec().encode(t.Type,n)),t.Data!=null&&(n.uint32(18),n.bytes(t.Data)),i.lengthDelimited!==!1&&n.ldelim()},(t,n)=>{let i={},o=n==null?t.len:t.pos+n;for(;t.pos<o;){let s=t.uint32();switch(s>>>3){case 1:i.Type=be.codec().decode(t);break;case 2:i.Data=t.bytes();break;default:t.skipType(s&7);break}}return i})),e),r.encode=t=>Ot(t,r.codec()),r.decode=t=>Dt(t,r.codec())})(pr||(pr={}));var mr;(function(r){let e;r.codec=()=>(e==null&&(e=Ft((t,n,i={})=>{i.lengthDelimited!==!1&&n.fork(),t.Type!=null&&(n.uint32(8),be.codec().encode(t.Type,n)),t.Data!=null&&(n.uint32(18),n.bytes(t.Data)),i.lengthDelimited!==!1&&n.ldelim()},(t,n)=>{let i={},o=n==null?t.len:t.pos+n;for(;t.pos<o;){let s=t.uint32();switch(s>>>3){case 1:i.Type=be.codec().decode(t);break;case 2:i.Data=t.bytes();break;default:t.skipType(s&7);break}}return i})),e),r.encode=t=>Ot(t,r.codec()),r.decode=t=>Dt(t,r.codec())})(mr||(mr={}));var rs=class{_key;constructor(e){this._key=so(e,io)}verify(e,t){return wp(this._key,t,e)}marshal(){return this._key}get bytes(){return pr.encode({Type:be.Ed25519,Data:this.marshal()}).subarray()}equals(e){return de(this.bytes,e.bytes)}hash(){let e=he.digest(this.bytes);return Mt(e)?e.then(({bytes:t})=>t):e.bytes}},hi=class{_key;_publicKey;constructor(e,t){this._key=so(e,qr),this._publicKey=so(t,io)}sign(e){return gp(this._key,e)}get public(){return new rs(this._publicKey)}marshal(){return this._key}get bytes(){return mr.encode({Type:be.Ed25519,Data:this.marshal()}).subarray()}equals(e){return de(this.bytes,e.bytes)}async hash(){let e=he.digest(this.bytes),t;return Mt(e)?{bytes:t}=await e:t=e.bytes,t}async id(){let e=et.digest(this.public.bytes);return ke.encode(e.bytes).substring(1)}async export(e,t="libp2p-key"){if(t==="libp2p-key")return oo(this.bytes,e);throw new F(`export format '${t}' is not supported`,"ERR_INVALID_EXPORT_FORMAT")}};function d3(r){if(r.length>qr){r=so(r,qr+io);let n=r.subarray(0,qr),i=r.subarray(qr,r.length);return new hi(n,i)}r=so(r,qr);let e=r.subarray(0,qr),t=r.subarray(io);return new hi(e,t)}function f3(r){return r=so(r,io),new rs(r)}async function p3(){let{privateKey:r,publicKey:e}=mp();return new hi(r,e)}async function Ep(r){let{privateKey:e,publicKey:t}=yp(r);return new hi(e,t)}function so(r,e){if(r=Uint8Array.from(r??[]),r.length!==e)throw new F(`Key must be a Uint8Array of length ${e}, got ${r.length}`,"ERR_INVALID_KEY_TYPE");return r}var Lh={};Ae(Lh,{MAX_RSA_KEY_SIZE:()=>ps,RsaPrivateKey:()=>ho,RsaPublicKey:()=>fs,fromJwk:()=>H3,generateKeyPair:()=>$3,unmarshalRsaPrivateKey:()=>Nh,unmarshalRsaPublicKey:()=>M3});function di(r){if(isNaN(r)||r<=0)throw new F("random bytes length must be a Number bigger than 0","ERR_INVALID_LENGTH");return eo(r)}var Pn={};Ae(Pn,{exportToPem:()=>D3,importFromPem:()=>P3,jwkToPkcs1:()=>C3,jwkToPkix:()=>U3,pkcs1ToJwk:()=>T3,pkixToJwk:()=>N3});var Ha=class extends Ji{constructor(e,t){super(),this.finished=!1,this.destroyed=!1,_a(e);let n=kn(t);if(this.iHash=e.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let i=this.blockLen,o=new Uint8Array(i);o.set(n.length>i?e.create().update(n).digest():n);for(let s=0;s<o.length;s++)o[s]^=54;this.iHash.update(o),this.oHash=e.create();for(let s=0;s<o.length;s++)o[s]^=106;this.oHash.update(o),o.fill(0)}update(e){return Zi(this),this.iHash.update(e),this}digestInto(e){Zi(this),ah(e,this.outputLen),this.finished=!0,this.iHash.digestInto(e),this.oHash.update(e),this.oHash.digestInto(e),this.destroy()}digest(){let e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||(e=Object.create(Object.getPrototypeOf(this),{}));let{oHash:t,iHash:n,finished:i,destroyed:o,blockLen:s,outputLen:a}=this;return e=e,e.finished=i,e.destroyed=o,e.blockLen=s,e.outputLen=a,e.oHash=t._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},ns=(r,e,t)=>new Ha(r,e).update(t).digest();ns.create=(r,e)=>new Ha(r,e);function m3(r,e,t,n){_a(r);let i=Q0({dkLen:32,asyncTick:10},n),{c:o,dkLen:s,asyncTick:a}=i;if(Xi(o),Xi(s),Xi(a),o<1)throw new Error("PBKDF2: iterations (c) should be >= 1");let c=kn(e),u=kn(t),l=new Uint8Array(s),h=ns.create(r,c),p=h._cloneInto().update(u);return{c:o,dkLen:s,asyncTick:a,DK:l,PRF:h,PRFSalt:p}}function y3(r,e,t,n,i){return r.destroy(),e.destroy(),n&&n.destroy(),i.fill(0),t}async function Ih(r,e,t,n){let{c:i,dkLen:o,asyncTick:s,DK:a,PRF:c,PRFSalt:u}=m3(r,e,t,n),l,h=new Uint8Array(4),p=Qi(h),d=new Uint8Array(c.outputLen);for(let f=1,m=0;m<o;f++,m+=c.outputLen){let y=a.subarray(m,m+c.outputLen);p.setInt32(0,f,!1),(l=u._cloneInto(l)).update(h).digestInto(d),y.set(d.subarray(0,y.length)),await J0(i-1,s,()=>{c._cloneInto(l).update(d).digestInto(d);for(let g=0;g<y.length;g++)y[g]^=d[g]})}return y3(c,u,a,l,d)}var se=re(vp());function fi(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 Un(r,e,t=-1){let n=t,i=r,o=0,s=Math.pow(2,e);for(let a=1;a<8;a++){if(r<s){let c;if(n<0)c=new ArrayBuffer(a),o=a;else{if(n<a)return new ArrayBuffer(0);c=new ArrayBuffer(n),o=n}let u=new Uint8Array(c);for(let l=a-1;l>=0;l--){let h=Math.pow(2,l*e);u[o-l-1]=Math.floor(i/h),i-=u[o-l-1]*h}return c}s*=Math.pow(2,e)}return new ArrayBuffer(0)}function Ka(...r){let e=0,t=0;for(let o of r)e+=o.length;let n=new ArrayBuffer(e),i=new Uint8Array(n);for(let o of r)i.set(o,t),t+=o.length;return i}function _h(){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=fi(t,8),i=new ArrayBuffer(this.valueHex.byteLength),o=new Uint8Array(i);for(let a=0;a<this.valueHex.byteLength;a++)o[a]=r[a];return o[0]&=127,fi(o,8)-n}function Bp(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=Un(s,8,n),c=new Uint8Array(a);return c[0]|=128,a}let i=Un(e,8,n),o=new Uint8Array(i);if(o[0]&128){let s=i.slice(0),a=new Uint8Array(s);i=new ArrayBuffer(i.byteLength+1),o=new Uint8Array(i);for(let c=0;c<s.byteLength;c++)o[c+1]=a[c];o[0]=0}return i}t*=Math.pow(2,8)}return new ArrayBuffer(0)}function Ap(r,e){if(r.byteLength!==e.byteLength)return!1;let t=new Uint8Array(r),n=new Uint8Array(e);for(let i=0;i<t.length;i++)if(t[i]!==n[i])return!1;return!0}function pt(r,e){let t=r.toString(10);if(e<t.length)return"";let n=e-t.length,i=new Array(n);for(let s=0;s<n;s++)i[s]="0";return i.join("").concat(t)}var X_=Math.log(2);function qa(){if(typeof BigInt>"u")throw new Error("BigInt is not defined. Your environment doesn't implement BigInt.")}function kh(r){let e=0,t=0;for(let i=0;i<r.length;i++){let o=r[i];e+=o.byteLength}let n=new Uint8Array(e);for(let i=0;i<r.length;i++){let o=r[i];n.set(new Uint8Array(o),t),t+=o.byteLength}return n.buffer}function Xr(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 os=class{constructor(){this.items=[]}write(e){this.items.push(e)}final(){return kh(this.items)}},is=[new Uint8Array([1])],Ip="0123456789";var lo="",er=new ArrayBuffer(0),Rh=new Uint8Array(0),ss="EndOfContent",_p="OCTET STRING",kp="BIT STRING";function Zr(r){var e;return e=class extends r{constructor(...n){var i;super(...n);let o=n[0]||{};this.isHexOnly=(i=o.isHexOnly)!==null&&i!==void 0?i:!1,this.valueHexView=o.valueHex?se.BufferSourceConverter.toUint8Array(o.valueHex):Rh}get valueHex(){return this.valueHexView.slice().buffer}set valueHex(n){this.valueHexView=new Uint8Array(n)}fromBER(n,i,o){let s=n instanceof ArrayBuffer?new Uint8Array(n):n;if(!Xr(this,s,i,o))return-1;let a=i+o;return this.valueHexView=s.subarray(i,a),this.valueHexView.length?(this.blockLength=o,a):(this.warnings.push("Zero buffer length"),i)}toBER(n=!1){return this.isHexOnly?n?new ArrayBuffer(this.valueHexView.byteLength):this.valueHexView.byteLength===this.valueHexView.buffer.byteLength?this.valueHexView.buffer:this.valueHexView.slice().buffer:(this.error="Flag 'isHexOnly' is not set, abort",er)}toJSON(){return{...super.toJSON(),isHexOnly:this.isHexOnly,valueHex:se.Convert.ToHex(this.valueHexView)}}},e.NAME="hexBlock",e}var jr=class{constructor({blockLength:e=0,error:t=lo,warnings:n=[],valueBeforeDecode:i=Rh}={}){this.blockLength=e,this.error=t,this.warnings=n,this.valueBeforeDecodeView=se.BufferSourceConverter.toUint8Array(i)}static blockName(){return this.NAME}get valueBeforeDecode(){return this.valueBeforeDecodeView.slice().buffer}set valueBeforeDecode(e){this.valueBeforeDecodeView=new Uint8Array(e)}toJSON(){return{blockName:this.constructor.NAME,blockLength:this.blockLength,error:this.error,warnings:this.warnings,valueBeforeDecode:se.Convert.ToHex(this.valueBeforeDecodeView)}}};jr.NAME="baseBlock";var tt=class extends jr{fromBER(e,t,n){throw TypeError("User need to make a specific function in a class which extends 'ValueBlock'")}toBER(e,t){throw TypeError("User need to make a specific function in a class which extends 'ValueBlock'")}};tt.NAME="valueBlock";var Ga=class extends Zr(jr){constructor({idBlock:e={}}={}){var t,n,i,o;super(),e?(this.isHexOnly=(t=e.isHexOnly)!==null&&t!==void 0?t:!1,this.valueHexView=e.valueHex?se.BufferSourceConverter.toUint8Array(e.valueHex):Rh,this.tagClass=(n=e.tagClass)!==null&&n!==void 0?n:-1,this.tagNumber=(i=e.tagNumber)!==null&&i!==void 0?i:-1,this.isConstructed=(o=e.isConstructed)!==null&&o!==void 0?o:!1):(this.tagClass=-1,this.tagNumber=-1,this.isConstructed=!1)}toBER(e=!1){let t=0;switch(this.tagClass){case 1:t|=0;break;case 2:t|=64;break;case 3:t|=128;break;case 4:t|=192;break;default:return this.error="Unknown tag class",er}if(this.isConstructed&&(t|=32),this.tagNumber<31&&!this.isHexOnly){let i=new Uint8Array(1);if(!e){let o=this.tagNumber;o&=31,t|=o,i[0]=t}return i.buffer}if(!this.isHexOnly){let i=Un(this.tagNumber,7),o=new Uint8Array(i),s=i.byteLength,a=new Uint8Array(s+1);if(a[0]=t|31,!e){for(let c=0;c<s-1;c++)a[c+1]=o[c]|128;a[s]=o[s-1]}return a.buffer}let n=new Uint8Array(this.valueHexView.byteLength+1);if(n[0]=t|31,!e){let i=this.valueHexView;for(let o=0;o<i.length-1;o++)n[o+1]=i[o]|128;n[this.valueHexView.byteLength]=i[i.length-1]}return n.buffer}fromBER(e,t,n){let i=se.BufferSourceConverter.toUint8Array(e);if(!Xr(this,i,t,n))return-1;let o=i.subarray(t,t+n);if(o.length===0)return this.error="Zero buffer length",-1;switch(o[0]&192){case 0:this.tagClass=1;break;case 64:this.tagClass=2;break;case 128:this.tagClass=3;break;case 192:this.tagClass=4;break;default:return this.error="Unknown tag class",-1}this.isConstructed=(o[0]&32)===32,this.isHexOnly=!1;let a=o[0]&31;if(a!==31)this.tagNumber=a,this.blockLength=1;else{let c=1,u=this.valueHexView=new Uint8Array(255),l=255;for(;o[c]&128;){if(u[c-1]=o[c]&127,c++,c>=o.length)return this.error="End of input reached before message was fully decoded",-1;if(c===l){l+=255;let p=new Uint8Array(l);for(let d=0;d<u.length;d++)p[d]=u[d];u=this.valueHexView=new Uint8Array(l)}}this.blockLength=c+1,u[c-1]=o[c]&127;let h=new Uint8Array(c);for(let p=0;p<c;p++)h[p]=u[p];u=this.valueHexView=new Uint8Array(c),u.set(h),this.blockLength<=9?this.tagNumber=fi(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}}};Ga.NAME="identificationBlock";var ja=class extends jr{constructor({lenBlock:e={}}={}){var t,n,i;super(),this.isIndefiniteForm=(t=e.isIndefiniteForm)!==null&&t!==void 0?t:!1,this.longFormUsed=(n=e.longFormUsed)!==null&&n!==void 0?n:!1,this.length=(i=e.length)!==null&&i!==void 0?i:0}fromBER(e,t,n){let i=se.BufferSourceConverter.toUint8Array(e);if(!Xr(this,i,t,n))return-1;let o=i.subarray(t,t+n);if(o.length===0)return this.error="Zero buffer length",-1;if(o[0]===255)return this.error="Length block 0xFF is reserved by standard",-1;if(this.isIndefiniteForm=o[0]===128,this.isIndefiniteForm)return this.blockLength=1,t+this.blockLength;if(this.longFormUsed=!!(o[0]&128),this.longFormUsed===!1)return this.length=o[0],this.blockLength=1,t+this.blockLength;let s=o[0]&127;if(s>8)return this.error="Too big integer",-1;if(s+1>o.length)return this.error="End of input reached before message was fully decoded",-1;let a=t+1,c=i.subarray(a,a+s);return c[s-1]===0&&this.warnings.push("Needlessly long encoded length"),this.length=fi(c,8),this.longFormUsed&&this.length<=127&&this.warnings.push("Unnecessary usage of long length form"),this.blockLength=s+1,t+this.blockLength}toBER(e=!1){let t,n;if(this.length>127&&(this.longFormUsed=!0),this.isIndefiniteForm)return t=new ArrayBuffer(1),e===!1&&(n=new Uint8Array(t),n[0]=128),t;if(this.longFormUsed){let i=Un(this.length,8);if(i.byteLength>127)return this.error="Too big length",er;if(t=new ArrayBuffer(i.byteLength+1),e)return t;let o=new Uint8Array(i);n=new Uint8Array(t),n[0]=i.byteLength|128;for(let s=0;s<i.byteLength;s++)n[s+1]=o[s];return t}return t=new ArrayBuffer(1),e===!1&&(n=new Uint8Array(t),n[0]=this.length),t}toJSON(){return{...super.toJSON(),isIndefiniteForm:this.isIndefiniteForm,longFormUsed:this.longFormUsed,length:this.length}}};ja.NAME="lengthBlock";var $={},Ge=class extends jr{constructor({name:e=lo,optional:t=!1,primitiveSchema:n,...i}={},o){super(i),this.name=e,this.optional=t,n&&(this.primitiveSchema=n),this.idBlock=new Ga(i),this.lenBlock=new ja(i),this.valueBlock=o?new o(i):new tt(i)}fromBER(e,t,n){let i=this.valueBlock.fromBER(e,t,this.lenBlock.isIndefiniteForm?n:this.lenBlock.length);return i===-1?(this.error=this.valueBlock.error,i):(this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.valueBlock.error.length||(this.blockLength+=this.valueBlock.blockLength),i)}toBER(e,t){let n=t||new os;t||Rp(this);let i=this.idBlock.toBER(e);if(n.write(i),this.lenBlock.isIndefiniteForm)n.write(new Uint8Array([128]).buffer),this.valueBlock.toBER(e,n),n.write(new ArrayBuffer(2));else{let o=this.valueBlock.toBER(e);this.lenBlock.length=o.byteLength;let s=this.lenBlock.toBER(e);n.write(s),n.write(o)}return t?er:n.final()}toJSON(){let e={...super.toJSON(),idBlock:this.idBlock.toJSON(),lenBlock:this.lenBlock.toJSON(),valueBlock:this.valueBlock.toJSON(),name:this.name,optional:this.optional};return this.primitiveSchema&&(e.primitiveSchema=this.primitiveSchema.toJSON()),e}toString(e="ascii"){return e==="ascii"?this.onAsciiEncoding():se.Convert.ToHex(this.toBER())}onAsciiEncoding(){return`${this.constructor.NAME} : ${se.Convert.ToHex(this.valueBlock.valueBeforeDecodeView)}`}isEqual(e){if(this===e)return!0;if(!(e instanceof this.constructor))return!1;let t=this.toBER(),n=e.toBER();return Ap(t,n)}};Ge.NAME="BaseBlock";function Rp(r){if(r instanceof $.Constructed)for(let e of r.valueBlock.value)Rp(e)&&(r.lenBlock.isIndefiniteForm=!0);return!!r.lenBlock.isIndefiniteForm}var Wa=class extends Ge{constructor({value:e=lo,...t}={},n){super(t,n),e&&this.fromString(e)}getValue(){return this.valueBlock.value}setValue(e){this.valueBlock.value=e}fromBER(e,t,n){let i=this.valueBlock.fromBER(e,t,this.lenBlock.isIndefiniteForm?n:this.lenBlock.length);return i===-1?(this.error=this.valueBlock.error,i):(this.fromBuffer(this.valueBlock.valueHexView),this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.valueBlock.error.length||(this.blockLength+=this.valueBlock.blockLength),i)}onAsciiEncoding(){return`${this.constructor.NAME} : '${this.valueBlock.value}'`}};Wa.NAME="BaseStringBlock";var Ya=class extends Zr(tt){constructor({isHexOnly:e=!0,...t}={}){super(t),this.isHexOnly=e}};Ya.NAME="PrimitiveValueBlock";var Tp,Xa=class extends Ge{constructor(e={}){super(e,Ya),this.idBlock.isConstructed=!1}};Tp=Xa;$.Primitive=Tp;Xa.NAME="PRIMITIVE";function I3(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 Rc(r,e=0,t=r.length){let n=e,i=new Ge({},tt),o=new jr;if(!Xr(o,r,e,t))return i.error=o.error,{offset:-1,result:i};if(!r.subarray(e,e+t).length)return i.error="Zero buffer length",{offset:-1,result:i};let a=i.idBlock.fromBER(r,e,t);if(i.idBlock.warnings.length&&i.warnings.concat(i.idBlock.warnings),a===-1)return i.error=i.idBlock.error,{offset:-1,result:i};if(e=a,t-=i.idBlock.blockLength,a=i.lenBlock.fromBER(r,e,t),i.lenBlock.warnings.length&&i.warnings.concat(i.lenBlock.warnings),a===-1)return i.error=i.lenBlock.error,{offset:-1,result:i};if(e=a,t-=i.lenBlock.blockLength,!i.idBlock.isConstructed&&i.lenBlock.isIndefiniteForm)return i.error="Indefinite length form used for primitive encoding form",{offset:-1,result:i};let c=Ge;switch(i.idBlock.tagClass){case 1:if(i.idBlock.tagNumber>=37&&i.idBlock.isHexOnly===!1)return i.error="UNIVERSAL 37 and upper tags are reserved by ASN.1 standard",{offset:-1,result:i};switch(i.idBlock.tagNumber){case 0:if(i.idBlock.isConstructed&&i.lenBlock.length>0)return i.error="Type [UNIVERSAL 0] is reserved",{offset:-1,result:i};c=$.EndOfContent;break;case 1:c=$.Boolean;break;case 2:c=$.Integer;break;case 3:c=$.BitString;break;case 4:c=$.OctetString;break;case 5:c=$.Null;break;case 6:c=$.ObjectIdentifier;break;case 10:c=$.Enumerated;break;case 12:c=$.Utf8String;break;case 13:c=$.RelativeObjectIdentifier;break;case 14:c=$.TIME;break;case 15:return i.error="[UNIVERSAL 15] is reserved by ASN.1 standard",{offset:-1,result:i};case 16:c=$.Sequence;break;case 17:c=$.Set;break;case 18:c=$.NumericString;break;case 19:c=$.PrintableString;break;case 20:c=$.TeletexString;break;case 21:c=$.VideotexString;break;case 22:c=$.IA5String;break;case 23:c=$.UTCTime;break;case 24:c=$.GeneralizedTime;break;case 25:c=$.GraphicString;break;case 26:c=$.VisibleString;break;case 27:c=$.GeneralString;break;case 28:c=$.UniversalString;break;case 29:c=$.CharacterString;break;case 30:c=$.BmpString;break;case 31:c=$.DATE;break;case 32:c=$.TimeOfDay;break;case 33:c=$.DateTime;break;case 34:c=$.Duration;break;default:{let u=i.idBlock.isConstructed?new $.Constructed:new $.Primitive;u.idBlock=i.idBlock,u.lenBlock=i.lenBlock,u.warnings=i.warnings,i=u}}break;case 2:case 3:case 4:default:c=i.idBlock.isConstructed?$.Constructed:$.Primitive}return i=I3(i,c),a=i.fromBER(r,e,i.lenBlock.isIndefiniteForm?t:i.lenBlock.length),i.valueBeforeDecodeView=r.subarray(n,n+i.blockLength),{offset:a,result:i}}function uo(r){if(!r.byteLength){let e=new Ge({},tt);return e.error="Input buffer has zero length",{offset:-1,result:e}}return Rc(se.BufferSourceConverter.toUint8Array(r).slice(),0,r.byteLength)}function S3(r,e){return r?1:e}var yr=class extends tt{constructor({value:e=[],isIndefiniteForm:t=!1,...n}={}){super(n),this.value=e,this.isIndefiniteForm=t}fromBER(e,t,n){let i=se.BufferSourceConverter.toUint8Array(e);if(!Xr(this,i,t,n))return-1;if(this.valueBeforeDecodeView=i.subarray(t,t+n),this.valueBeforeDecodeView.length===0)return this.warnings.push("Zero buffer length"),t;let o=t;for(;S3(this.isIndefiniteForm,n)>0;){let s=Rc(i,o,n);if(s.offset===-1)return this.error=s.result.error,this.warnings.concat(s.result.warnings),-1;if(o=s.offset,this.blockLength+=s.result.blockLength,n-=s.result.blockLength,this.value.push(s.result),this.isIndefiniteForm&&s.result.constructor.NAME===ss)break}return this.isIndefiniteForm&&(this.value[this.value.length-1].constructor.NAME===ss?this.value.pop():this.warnings.push("No EndOfContent block encoded")),o}toBER(e,t){let n=t||new os;for(let i=0;i<this.value.length;i++)this.value[i].toBER(e,n);return t?er:n.final()}toJSON(){let e={...super.toJSON(),isIndefiniteForm:this.isIndefiniteForm,value:[]};for(let t of this.value)e.value.push(t.toJSON());return e}};yr.NAME="ConstructedValueBlock";var Cp,Ln=class extends Ge{constructor(e={}){super(e,yr),this.idBlock.isConstructed=!0}fromBER(e,t,n){this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm;let i=this.valueBlock.fromBER(e,t,this.lenBlock.isIndefiniteForm?n:this.lenBlock.length);return i===-1?(this.error=this.valueBlock.error,i):(this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.valueBlock.error.length||(this.blockLength+=this.valueBlock.blockLength),i)}onAsciiEncoding(){let e=[];for(let n of this.valueBlock.value)e.push(n.toString("ascii").split(`
|
|
4
4
|
`).map(i=>` ${i}`).join(`
|
|
5
5
|
`));let t=this.idBlock.tagClass===3?`[${this.idBlock.tagNumber}]`:this.constructor.NAME;return e.length?`${t} :
|
|
6
6
|
${e.join(`
|
|
7
|
-
`)}`:`${t} :`}};Hp=Pn;$.Constructed=Hp;Pn.NAME="CONSTRUCTED";var ec=class extends tt{fromBER(e,t,n){return t}toBER(e){return er}};ec.override="EndOfContentValueBlock";var $p,tc=class extends je{constructor(e={}){super(e,ec),this.idBlock.tagClass=1,this.idBlock.tagNumber=0}};$p=tc;$.EndOfContent=$p;tc.NAME=cs;var zp,On=class extends je{constructor(e={}){super(e,tt),this.idBlock.tagClass=1,this.idBlock.tagNumber=5}fromBER(e,t,n){return this.lenBlock.length>0&&this.warnings.push("Non-zero length of value block for Null type"),this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.blockLength+=n,t+n>e.byteLength?(this.error="End of input reached before message was fully decoded (inconsistent offset and length values)",-1):t+n}toBER(e,t){let n=new ArrayBuffer(2);if(!e){let i=new Uint8Array(n);i[0]=5,i[1]=0}return t&&t.write(n),n}onAsciiEncoding(){return`${this.constructor.NAME}`}};zp=On;$.Null=zp;On.NAME="NULL";var rc=class extends Jr(tt){constructor({value:e,...t}={}){super(t),t.valueHex?this.valueHexView=ae.BufferSourceConverter.toUint8Array(t.valueHex):this.valueHexView=new Uint8Array(1),e&&(this.value=e)}get value(){for(let e of this.valueHexView)if(e>0)return!0;return!1}set value(e){this.valueHexView[0]=e?255:0}fromBER(e,t,n){let i=ae.BufferSourceConverter.toUint8Array(e);return Zr(this,i,t,n)?(this.valueHexView=i.subarray(t,t+n),n>1&&this.warnings.push("Boolean value encoded in more then 1 octet"),this.isHexOnly=!0,Lh.call(this),this.blockLength=n,t+n):-1}toBER(){return this.valueHexView.slice()}toJSON(){return{...super.toJSON(),value:this.value}}};rc.NAME="BooleanValueBlock";var Kp,nc=class extends je{constructor(e={}){super(e,rc),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}`}};Kp=nc;$.Boolean=Kp;nc.NAME="BOOLEAN";var ic=class extends Jr(wr){constructor({isConstructed:e=!1,...t}={}){super(t),this.isConstructed=e}fromBER(e,t,n){let i=0;if(this.isConstructed){if(this.isHexOnly=!1,i=wr.prototype.fromBER.call(this,e,t,n),i===-1)return i;for(let o=0;o<this.value.length;o++){let s=this.value[o].constructor.NAME;if(s===cs){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, OCTET STRING may consists of OCTET STRINGs only",-1}if(s!==Op)return this.error="OCTET STRING may consists of OCTET STRINGs only",-1}}else this.isHexOnly=!0,i=super.fromBER(e,t,n),this.blockLength=n;return i}toBER(e,t){return this.isConstructed?wr.prototype.toBER.call(this,e,t):e?new ArrayBuffer(this.valueHexView.byteLength):this.valueHexView.slice().buffer}toJSON(){return{...super.toJSON(),isConstructed:this.isConstructed}}};ic.NAME="OctetStringValueBlock";var qp,Yr=class r extends je{constructor({idBlock:e={},lenBlock:t={},...n}={}){var i,o;(i=n.isConstructed)!==null&&i!==void 0||(n.isConstructed=!!(!((o=n.value)===null||o===void 0)&&o.length)),super({idBlock:{isConstructed:n.isConstructed,...e},lenBlock:{...t,isIndefiniteForm:!!n.isIndefiniteForm},...n},ic),this.idBlock.tagClass=1,this.idBlock.tagNumber=4}fromBER(e,t,n){if(this.valueBlock.isConstructed=this.idBlock.isConstructed,this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm,n===0)return this.idBlock.error.length===0&&(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length===0&&(this.blockLength+=this.lenBlock.blockLength),t;if(!this.valueBlock.isConstructed){let o=(e instanceof ArrayBuffer?new Uint8Array(e):e).subarray(t,t+n);try{if(o.byteLength){let s=Nc(o,0,o.byteLength);s.offset!==-1&&s.offset===n&&(this.valueBlock.value=[s.result])}}catch{}}return super.fromBER(e,t,n)}onAsciiEncoding(){return this.valueBlock.isConstructed||this.valueBlock.value&&this.valueBlock.value.length?Pn.prototype.onAsciiEncoding.call(this):`${this.constructor.NAME} : ${ae.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 ae.BufferSourceConverter.concat(e)}};qp=Yr;$.OctetString=qp;Yr.NAME=Op;var oc=class extends Jr(wr){constructor({unusedBits:e=0,isConstructed:t=!1,...n}={}){super(n),this.unusedBits=e,this.isConstructed=t,this.blockLength=this.valueHexView.byteLength}fromBER(e,t,n){if(!n)return t;let i=-1;if(this.isConstructed){if(i=wr.prototype.fromBER.call(this,e,t,n),i===-1)return i;for(let a of this.value){let c=a.constructor.NAME;if(c===cs){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, BIT STRING may consists of BIT STRINGs only",-1}if(c!==Fp)return this.error="BIT STRING may consists of BIT STRINGs only",-1;let u=a.valueBlock;if(this.unusedBits>0&&u.unusedBits>0)return this.error='Using of "unused bits" inside constructive BIT STRING allowed for least one only',-1;this.unusedBits=u.unusedBits}return i}let o=ae.BufferSourceConverter.toUint8Array(e);if(!Zr(this,o,t,n))return-1;let s=o.subarray(t,t+n);if(this.unusedBits=s[0],this.unusedBits>7)return this.error="Unused bits for BitString must be in range 0-7",-1;if(!this.unusedBits){let a=s.subarray(1);try{if(a.byteLength){let c=Nc(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 wr.prototype.toBER.call(this,e,t);if(e)return new ArrayBuffer(this.valueHexView.byteLength+1);if(!this.valueHexView.byteLength)return er;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}}};oc.NAME="BitStringValueBlock";var jp,ho=class extends je{constructor({idBlock:e={},lenBlock:t={},...n}={}){var i,o;(i=n.isConstructed)!==null&&i!==void 0||(n.isConstructed=!!(!((o=n.value)===null||o===void 0)&&o.length)),super({idBlock:{isConstructed:n.isConstructed,...e},lenBlock:{...t,isIndefiniteForm:!!n.isIndefiniteForm},...n},oc),this.idBlock.tagClass=1,this.idBlock.tagNumber=3}fromBER(e,t,n){return this.valueBlock.isConstructed=this.idBlock.isConstructed,this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm,super.fromBER(e,t,n)}onAsciiEncoding(){if(this.valueBlock.isConstructed||this.valueBlock.value&&this.valueBlock.value.length)return Pn.prototype.onAsciiEncoding.call(this);{let e=[],t=this.valueBlock.valueHexView;for(let i of t)e.push(i.toString(2).padStart(8,"0"));let n=e.join("");return`${this.constructor.NAME} : ${n.substring(0,n.length-this.valueBlock.unusedBits)}`}}};jp=ho;$.BitString=jp;ho.NAME=Fp;var Gp;function P3(r,e){let t=new Uint8Array([0]),n=new Uint8Array(r),i=new Uint8Array(e),o=n.slice(0),s=o.length-1,a=i.slice(0),c=a.length-1,u=0,l=c<s?s:c,h=0;for(let p=l;p>=0;p--,h++){switch(!0){case h<a.length:u=o[s-h]+a[c-h]+t[0];break;default:u=o[s-h]+t[0]}switch(t[0]=u/10,!0){case h>=o.length:o=Ga(new Uint8Array([u%10]),o);break;default:o[s-h]=u%10}}return t[0]>0&&(o=Ga(t,o)),o}function Pp(r){if(r>=ss.length)for(let e=ss.length;e<=r;e++){let t=new Uint8Array([0]),n=ss[e-1].slice(0);for(let i=n.length-1;i>=0;i--){let o=new Uint8Array([(n[i]<<1)+t[0]]);t[0]=o[0]/10,n[i]=o[0]%10}t[0]>0&&(n=Ga(t,n)),ss.push(n)}return ss[r]}function O3(r,e){let t=0,n=new Uint8Array(r),i=new Uint8Array(e),o=n.slice(0),s=o.length-1,a=i.slice(0),c=a.length-1,u,l=0;for(let h=c;h>=0;h--,l++)switch(u=o[s-l]-a[c-l]-t,!0){case u<0:t=1,o[s-l]=u+10;break;default:t=0,o[s-l]=u}if(t>0)for(let h=s-c+1;h>=0;h--,l++)if(u=o[s-l]-t,u<0)t=1,o[s-l]=u+10;else{t=0,o[s-l]=u;break}return o.slice()}var ls=class extends Jr(tt){constructor({value:e,...t}={}){super(t),this._valueDec=0,t.valueHex&&this.setValueHex(),e!==void 0&&(this.valueDec=e)}setValueHex(){this.valueHexView.length>=4?(this.warnings.push("Too big Integer for decoding, hex only"),this.isHexOnly=!0,this._valueDec=0):(this.isHexOnly=!1,this.valueHexView.length>0&&(this._valueDec=Lh.call(this)))}set valueDec(e){this._valueDec=e,this.isHexOnly=!1,this.valueHexView=new Uint8Array(Up(e))}get valueDec(){return this._valueDec}fromDER(e,t,n,i=0){let o=this.fromBER(e,t,n);if(o===-1)return o;let s=this.valueHexView;return s[0]===0&&s[1]&128?this.valueHexView=s.subarray(1):i!==0&&s.length<i&&(i-s.length>1&&(i=s.length+1),this.valueHexView=s.subarray(i-s.length)),o}toDER(e=!1){let t=this.valueHexView;switch(!0){case(t[0]&128)!==0:{let n=new Uint8Array(this.valueHexView.length+1);n[0]=0,n.set(t,1),this.valueHexView=n}break;case(t[0]===0&&(t[1]&128)===0):this.valueHexView=this.valueHexView.subarray(1);break}return this.toBER(e)}fromBER(e,t,n){let i=super.fromBER(e,t,n);return i===-1||this.setValueHex(),i}toBER(e){return e?new ArrayBuffer(this.valueHexView.length):this.valueHexView.slice().buffer}toJSON(){return{...super.toJSON(),valueDec:this.valueDec}}toString(){let e=this.valueHexView.length*8-1,t=new Uint8Array(this.valueHexView.length*8/3),n=0,i,o=this.valueHexView,s="",a=!1;for(let c=o.byteLength-1;c>=0;c--){i=o[c];for(let u=0;u<8;u++){if((i&1)===1)switch(n){case e:t=O3(Pp(n),t),s="-";break;default:t=P3(t,Pp(n))}n++,i>>=1}}for(let c=0;c<t.length;c++)t[c]&&(a=!0),a&&(s+=Dp.charAt(t[c]));return a===!1&&(s+=Dp.charAt(0)),s}};Gp=ls;ls.NAME="IntegerValueBlock";Object.defineProperty(Gp.prototype,"valueHex",{set:function(r){this.valueHexView=new Uint8Array(r),this.setValueHex()},get:function(){return this.valueHexView.slice().buffer}});var Wp,Le=class r extends je{constructor(e={}){super(e,ls),this.idBlock.tagClass=1,this.idBlock.tagNumber=2}toBigInt(){return Wa(),BigInt(this.valueBlock.toString())}static fromBigInt(e){Wa();let t=BigInt(e),n=new as,i=t.toString(16).replace(/^-/,""),o=new Uint8Array(ae.Convert.FromHex(i));if(t<0){let a=new Uint8Array(o.length+(o[0]&128?1:0));a[0]|=128;let u=BigInt(`0x${ae.Convert.ToHex(a)}`)+t,l=ae.BufferSourceConverter.toUint8Array(ae.Convert.FromHex(u.toString(16)));l[0]|=128,n.write(l)}else o[0]&128&&n.write(new Uint8Array([0])),n.write(o);return new r({valueHex:n.final()})}convertToDER(){let e=new r({valueHex:this.valueBlock.valueHexView});return e.valueBlock.toDER(),e}convertFromDER(){return new r({valueHex:this.valueBlock.valueHexView[0]===0?this.valueBlock.valueHexView.subarray(1):this.valueBlock.valueHexView})}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()}`}};Wp=Le;$.Integer=Wp;Le.NAME="INTEGER";var Yp,sc=class extends Le{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=10}};Yp=sc;$.Enumerated=Yp;sc.NAME="ENUMERATED";var us=class extends Jr(tt){constructor({valueDec:e=-1,isFirstSid:t=!1,...n}={}){super(n),this.valueDec=e,this.isFirstSid=t}fromBER(e,t,n){if(!n)return t;let i=ae.BufferSourceConverter.toUint8Array(e);if(!Zr(this,i,t,n))return-1;let o=i.subarray(t,t+n);this.valueHexView=new Uint8Array(n);for(let a=0;a<n&&(this.valueHexView[a]=o[a]&127,this.blockLength++,!!(o[a]&128));a++);let s=new Uint8Array(this.blockLength);for(let a=0;a<this.blockLength;a++)s[a]=this.valueHexView[a];return this.valueHexView=s,o[this.blockLength-1]&128?(this.error="End of input reached before message was fully decoded",-1):(this.valueHexView[0]===0&&this.warnings.push("Needlessly long format of SID encoding"),this.blockLength<=8?this.valueDec=wi(this.valueHexView,7):(this.isHexOnly=!0,this.warnings.push("Too big SID for decoding, hex only")),t+this.blockLength)}set valueBigInt(e){Wa();let t=BigInt(e).toString(2);for(;t.length%7;)t="0"+t;let n=new Uint8Array(t.length/7);for(let i=0;i<n.length;i++)n[i]=parseInt(t.slice(i*7,i*7+7),2)+(i+1<n.length?128:0);this.fromBER(n.buffer,0,n.length)}toBER(e){if(this.isHexOnly){if(e)return new ArrayBuffer(this.valueHexView.byteLength);let i=this.valueHexView,o=new Uint8Array(this.blockLength);for(let s=0;s<this.blockLength-1;s++)o[s]=i[s]|128;return o[this.blockLength-1]=i[this.blockLength-1],o.buffer}let t=Dn(this.valueDec,7);if(t.byteLength===0)return this.error="Error during encoding SID value",er;let n=new Uint8Array(t.byteLength);if(!e){let i=new Uint8Array(t),o=t.byteLength-1;for(let s=0;s<o;s++)n[s]=i[s]|128;n[o]=i[o]}return n}toString(){let e="";if(this.isHexOnly)e=ae.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}}};us.NAME="sidBlock";var ac=class extends tt{constructor({value:e=fo,...t}={}){super(t),this.value=[],e&&this.fromString(e)}fromBER(e,t,n){let i=t;for(;n>0;){let o=new us;if(i=o.fromBER(e,i,n),i===-1)return this.blockLength=0,this.error=o.error,i;this.value.length===0&&(o.isFirstSid=!0),this.blockLength+=o.blockLength,n-=o.blockLength,this.value.push(o)}return i}toBER(e){let t=[];for(let n=0;n<this.value.length;n++){let i=this.value[n].toBER(e);if(i.byteLength===0)return this.error=this.value[n].error,er;t.push(i)}return Dh(t)}fromString(e){this.value=[];let t=0,n=0,i="",o=!1;do if(n=e.indexOf(".",t),n===-1?i=e.substring(t):i=e.substring(t,n),t=n+1,o){let s=this.value[0],a=0;switch(s.valueDec){case 0:break;case 1:a=40;break;case 2:a=80;break;default:this.value=[];return}let c=parseInt(i,10);if(isNaN(c))return;s.valueDec=c+a,o=!1}else{let s=new us;if(i>Number.MAX_SAFE_INTEGER){Wa();let a=BigInt(i);s.valueBigInt=a}else if(s.valueDec=parseInt(i,10),isNaN(s.valueDec))return;this.value.length||(s.isFirstSid=!0,o=!0),this.value.push(s)}while(n!==-1)}toString(){let e="",t=!1;for(let n=0;n<this.value.length;n++){t=this.value[n].isHexOnly;let i=this.value[n].toString();n!==0&&(e=`${e}.`),t?(i=`{${i}}`,this.value[n].isFirstSid?e=`2.{${i} - 80}`:e+=i):e+=i}return e}toJSON(){let e={...super.toJSON(),value:this.toString(),sidArray:[]};for(let t=0;t<this.value.length;t++)e.sidArray.push(this.value[t].toJSON());return e}};ac.NAME="ObjectIdentifierValueBlock";var Xp,Qt=class extends je{constructor(e={}){super(e,ac),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()}}};Xp=Qt;$.ObjectIdentifier=Xp;Qt.NAME="OBJECT IDENTIFIER";var hs=class extends Jr(Wr){constructor({valueDec:e=0,...t}={}){super(t),this.valueDec=e}fromBER(e,t,n){if(n===0)return t;let i=ae.BufferSourceConverter.toUint8Array(e);if(!Zr(this,i,t,n))return-1;let o=i.subarray(t,t+n);this.valueHexView=new Uint8Array(n);for(let a=0;a<n&&(this.valueHexView[a]=o[a]&127,this.blockLength++,!!(o[a]&128));a++);let s=new Uint8Array(this.blockLength);for(let a=0;a<this.blockLength;a++)s[a]=this.valueHexView[a];return this.valueHexView=s,o[this.blockLength-1]&128?(this.error="End of input reached before message was fully decoded",-1):(this.valueHexView[0]===0&&this.warnings.push("Needlessly long format of SID encoding"),this.blockLength<=8?this.valueDec=wi(this.valueHexView,7):(this.isHexOnly=!0,this.warnings.push("Too big SID for decoding, hex only")),t+this.blockLength)}toBER(e){if(this.isHexOnly){if(e)return new ArrayBuffer(this.valueHexView.byteLength);let i=this.valueHexView,o=new Uint8Array(this.blockLength);for(let s=0;s<this.blockLength-1;s++)o[s]=i[s]|128;return o[this.blockLength-1]=i[this.blockLength-1],o.buffer}let t=Dn(this.valueDec,7);if(t.byteLength===0)return this.error="Error during encoding SID value",er;let n=new Uint8Array(t.byteLength);if(!e){let i=new Uint8Array(t),o=t.byteLength-1;for(let s=0;s<o;s++)n[s]=i[s]|128;n[o]=i[o]}return n.buffer}toString(){let e="";return this.isHexOnly?e=ae.Convert.ToHex(this.valueHexView):e=this.valueDec.toString(),e}toJSON(){return{...super.toJSON(),valueDec:this.valueDec}}};hs.NAME="relativeSidBlock";var cc=class extends tt{constructor({value:e=fo,...t}={}){super(t),this.value=[],e&&this.fromString(e)}fromBER(e,t,n){let i=t;for(;n>0;){let o=new hs;if(i=o.fromBER(e,i,n),i===-1)return this.blockLength=0,this.error=o.error,i;this.blockLength+=o.blockLength,n-=o.blockLength,this.value.push(o)}return i}toBER(e,t){let n=[];for(let i=0;i<this.value.length;i++){let o=this.value[i].toBER(e);if(o.byteLength===0)return this.error=this.value[i].error,er;n.push(o)}return Dh(n)}fromString(e){this.value=[];let t=0,n=0,i="";do{n=e.indexOf(".",t),n===-1?i=e.substring(t):i=e.substring(t,n),t=n+1;let o=new hs;if(o.valueDec=parseInt(i,10),isNaN(o.valueDec))return!0;this.value.push(o)}while(n!==-1);return!0}toString(){let e="",t=!1;for(let n=0;n<this.value.length;n++){t=this.value[n].isHexOnly;let i=this.value[n].toString();n!==0&&(e=`${e}.`),t&&(i=`{${i}}`),e+=i}return e}toJSON(){let e={...super.toJSON(),value:this.toString(),sidArray:[]};for(let t=0;t<this.value.length;t++)e.sidArray.push(this.value[t].toJSON());return e}};cc.NAME="RelativeObjectIdentifierValueBlock";var Zp,lc=class extends je{constructor(e={}){super(e,cc),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()}}};Zp=lc;$.RelativeObjectIdentifier=Zp;lc.NAME="RelativeObjectIdentifier";var Jp,Ve=class extends Pn{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=16}};Jp=Ve;$.Sequence=Jp;Ve.NAME="SEQUENCE";var Qp,uc=class extends Pn{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=17}};Qp=uc;$.Set=Qp;uc.NAME="SET";var hc=class extends Jr(tt){constructor({...e}={}){super(e),this.isHexOnly=!0,this.value=fo}toJSON(){return{...super.toJSON(),value:this.value}}};hc.NAME="StringValueBlock";var dc=class extends hc{};dc.NAME="SimpleStringValueBlock";var st=class extends Za{constructor({...e}={}){super(e,dc)}fromBuffer(e){this.valueBlock.value=String.fromCharCode.apply(null,ae.BufferSourceConverter.toUint8Array(e))}fromString(e){let t=e.length,n=this.valueBlock.valueHexView=new Uint8Array(t);for(let i=0;i<t;i++)n[i]=e.charCodeAt(i);this.valueBlock.value=e}};st.NAME="SIMPLE STRING";var fc=class extends st{fromBuffer(e){this.valueBlock.valueHexView=ae.BufferSourceConverter.toUint8Array(e);try{this.valueBlock.value=ae.Convert.ToUtf8String(e)}catch(t){this.warnings.push(`Error during "decodeURIComponent": ${t}, using raw string`),this.valueBlock.value=ae.Convert.ToBinary(e)}}fromString(e){this.valueBlock.valueHexView=new Uint8Array(ae.Convert.FromUtf8String(e)),this.valueBlock.value=e}};fc.NAME="Utf8StringValueBlock";var e1,Xr=class extends fc{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=12}};e1=Xr;$.Utf8String=e1;Xr.NAME="UTF8String";var pc=class extends st{fromBuffer(e){this.valueBlock.value=ae.Convert.ToUtf16String(e),this.valueBlock.valueHexView=ae.BufferSourceConverter.toUint8Array(e)}fromString(e){this.valueBlock.value=e,this.valueBlock.valueHexView=new Uint8Array(ae.Convert.FromUtf16String(e))}};pc.NAME="BmpStringValueBlock";var t1,mc=class extends pc{constructor({...e}={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=30}};t1=mc;$.BmpString=t1;mc.NAME="BMPString";var yc=class extends st{fromBuffer(e){let t=ArrayBuffer.isView(e)?e.slice().buffer:e.slice(0),n=new Uint8Array(t);for(let i=0;i<n.length;i+=4)n[i]=n[i+3],n[i+1]=n[i+2],n[i+2]=0,n[i+3]=0;this.valueBlock.value=String.fromCharCode.apply(null,new Uint32Array(t))}fromString(e){let t=e.length,n=this.valueBlock.valueHexView=new Uint8Array(t*4);for(let i=0;i<t;i++){let o=Dn(e.charCodeAt(i),8),s=new Uint8Array(o);if(s.length>4)continue;let a=4-s.length;for(let c=s.length-1;c>=0;c--)n[i*4+c+a]=s[c]}this.valueBlock.value=e}};yc.NAME="UniversalStringValueBlock";var r1,gc=class extends yc{constructor({...e}={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=28}};r1=gc;$.UniversalString=r1;gc.NAME="UniversalString";var n1,wc=class extends st{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=18}};n1=wc;$.NumericString=n1;wc.NAME="NumericString";var i1,xc=class extends st{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=19}};i1=xc;$.PrintableString=i1;xc.NAME="PrintableString";var o1,bc=class extends st{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=20}};o1=bc;$.TeletexString=o1;bc.NAME="TeletexString";var s1,Ec=class extends st{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=21}};s1=Ec;$.VideotexString=s1;Ec.NAME="VideotexString";var a1,vc=class extends st{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=22}};a1=vc;$.IA5String=a1;vc.NAME="IA5String";var c1,Bc=class extends st{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=25}};c1=Bc;$.GraphicString=c1;Bc.NAME="GraphicString";var l1,ds=class extends st{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=26}};l1=ds;$.VisibleString=l1;ds.NAME="VisibleString";var u1,Ac=class extends st{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=27}};u1=Ac;$.GeneralString=u1;Ac.NAME="GeneralString";var h1,Ic=class extends st{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=29}};h1=Ic;$.CharacterString=h1;Ic.NAME="CharacterString";var d1,fs=class extends ds{constructor({value:e,valueDate:t,...n}={}){if(super(n),this.year=0,this.month=0,this.day=0,this.hour=0,this.minute=0,this.second=0,e){this.fromString(e),this.valueBlock.valueHexView=new Uint8Array(e.length);for(let i=0;i<e.length;i++)this.valueBlock.valueHexView[i]=e.charCodeAt(i)}t&&(this.fromDate(t),this.valueBlock.valueHexView=new Uint8Array(this.toBuffer())),this.idBlock.tagClass=1,this.idBlock.tagNumber=23}fromBuffer(e){this.fromString(String.fromCharCode.apply(null,ae.BufferSourceConverter.toUint8Array(e)))}toBuffer(){let e=this.toString(),t=new ArrayBuffer(e.length),n=new Uint8Array(t);for(let i=0;i<e.length;i++)n[i]=e.charCodeAt(i);return t}fromDate(e){this.year=e.getUTCFullYear(),this.month=e.getUTCMonth()+1,this.day=e.getUTCDate(),this.hour=e.getUTCHours(),this.minute=e.getUTCMinutes(),this.second=e.getUTCSeconds()}toDate(){return new Date(Date.UTC(this.year,this.month-1,this.day,this.hour,this.minute,this.second))}fromString(e){let n=/(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})Z/ig.exec(e);if(n===null){this.error="Wrong input string for conversion";return}let i=parseInt(n[1],10);i>=50?this.year=1900+i:this.year=2e3+i,this.month=parseInt(n[2],10),this.day=parseInt(n[3],10),this.hour=parseInt(n[4],10),this.minute=parseInt(n[5],10),this.second=parseInt(n[6],10)}toString(e="iso"){if(e==="iso"){let t=new Array(7);return t[0]=ft(this.year<2e3?this.year-1900:this.year-2e3,2),t[1]=ft(this.month,2),t[2]=ft(this.day,2),t[3]=ft(this.hour,2),t[4]=ft(this.minute,2),t[5]=ft(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}}};d1=fs;$.UTCTime=d1;fs.NAME="UTCTime";var f1,Sc=class extends fs{constructor(e={}){var t;super(e),(t=this.millisecond)!==null&&t!==void 0||(this.millisecond=0),this.idBlock.tagClass=1,this.idBlock.tagNumber=24}fromDate(e){super.fromDate(e),this.millisecond=e.getUTCMilliseconds()}toDate(){return new Date(Date.UTC(this.year,this.month-1,this.day,this.hour,this.minute,this.second,this.millisecond))}fromString(e){let t=!1,n="",i="",o=0,s,a=0,c=0;if(e[e.length-1]==="Z")n=e.substring(0,e.length-1),t=!0;else{let h=new Number(e[e.length-1]);if(isNaN(h.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 h=1,p=n.indexOf("+"),d="";if(p===-1&&(p=n.indexOf("-"),h=-1),p!==-1){if(d=n.substring(p+1),n=n.substring(0,p),d.length!==2&&d.length!==4)throw new Error("Wrong input string for conversion");let f=parseInt(d.substring(0,2),10);if(isNaN(f.valueOf()))throw new Error("Wrong input string for conversion");if(a=h*f,d.length===4){if(f=parseInt(d.substring(2,4),10),isNaN(f.valueOf()))throw new Error("Wrong input string for conversion");c=h*f}}}let u=n.indexOf(".");if(u===-1&&(u=n.indexOf(",")),u!==-1){let h=new Number(`0${n.substring(u)}`);if(isNaN(h.valueOf()))throw new Error("Wrong input string for conversion");o=h.valueOf(),i=n.substring(0,u)}else i=n;switch(!0){case i.length===8:if(s=/(\d{4})(\d{2})(\d{2})/ig,u!==-1)throw new Error("Wrong input string for conversion");break;case i.length===10:if(s=/(\d{4})(\d{2})(\d{2})(\d{2})/ig,u!==-1){let h=60*o;this.minute=Math.floor(h),h=60*(h-this.minute),this.second=Math.floor(h),h=1e3*(h-this.second),this.millisecond=Math.floor(h)}break;case i.length===12:if(s=/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})/ig,u!==-1){let h=60*o;this.second=Math.floor(h),h=1e3*(h-this.second),this.millisecond=Math.floor(h)}break;case i.length===14:if(s=/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/ig,u!==-1){let h=1e3*o;this.millisecond=Math.floor(h)}break;default:throw new Error("Wrong input string for conversion")}let l=s.exec(i);if(l===null)throw new Error("Wrong input string for conversion");for(let h=1;h<l.length;h++)switch(h){case 1:this.year=parseInt(l[h],10);break;case 2:this.month=parseInt(l[h],10);break;case 3:this.day=parseInt(l[h],10);break;case 4:this.hour=parseInt(l[h],10)+a;break;case 5:this.minute=parseInt(l[h],10)+c;break;case 6:this.second=parseInt(l[h],10);break;default:throw new Error("Wrong input string for conversion")}if(t===!1){let h=new Date(this.year,this.month,this.day,this.hour,this.minute,this.second,this.millisecond);this.year=h.getUTCFullYear(),this.month=h.getUTCMonth(),this.day=h.getUTCDay(),this.hour=h.getUTCHours(),this.minute=h.getUTCMinutes(),this.second=h.getUTCSeconds(),this.millisecond=h.getUTCMilliseconds()}}toString(e="iso"){if(e==="iso"){let t=[];return t.push(ft(this.year,4)),t.push(ft(this.month,2)),t.push(ft(this.day,2)),t.push(ft(this.hour,2)),t.push(ft(this.minute,2)),t.push(ft(this.second,2)),this.millisecond!==0&&(t.push("."),t.push(ft(this.millisecond,3))),t.push("Z"),t.join("")}return super.toString(e)}toJSON(){return{...super.toJSON(),millisecond:this.millisecond}}};f1=Sc;$.GeneralizedTime=f1;Sc.NAME="GeneralizedTime";var p1,_c=class extends Xr{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=31}};p1=_c;$.DATE=p1;_c.NAME="DATE";var m1,kc=class extends Xr{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=32}};m1=kc;$.TimeOfDay=m1;kc.NAME="TimeOfDay";var y1,Rc=class extends Xr{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=33}};y1=Rc;$.DateTime=y1;Rc.NAME="DateTime";var g1,Tc=class extends Xr{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=34}};g1=Tc;$.Duration=g1;Tc.NAME="Duration";var w1,Cc=class extends Xr{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=14}};w1=Cc;$.TIME=w1;Cc.NAME="TIME";function V3(r){let{result:e}=po(r),t=e.valueBlock.value;return{n:Q(xr(t[1].toBigInt()),"base64url"),e:Q(xr(t[2].toBigInt()),"base64url"),d:Q(xr(t[3].toBigInt()),"base64url"),p:Q(xr(t[4].toBigInt()),"base64url"),q:Q(xr(t[5].toBigInt()),"base64url"),dp:Q(xr(t[6].toBigInt()),"base64url"),dq:Q(xr(t[7].toBigInt()),"base64url"),qi:Q(xr(t[8].toBigInt()),"base64url"),kty:"RSA",alg:"RS256"}}function M3(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 F("JWK was missing components","ERR_INVALID_PARAMETERS");let t=new Ve({value:[new Le({value:0}),Le.fromBigInt(br(Y(r.n,"base64url"))),Le.fromBigInt(br(Y(r.e,"base64url"))),Le.fromBigInt(br(Y(r.d,"base64url"))),Le.fromBigInt(br(Y(r.p,"base64url"))),Le.fromBigInt(br(Y(r.q,"base64url"))),Le.fromBigInt(br(Y(r.dp,"base64url"))),Le.fromBigInt(br(Y(r.dq,"base64url"))),Le.fromBigInt(br(Y(r.qi,"base64url")))]}).toBER();return new Uint8Array(t,0,t.byteLength)}function H3(r){let{result:e}=po(r),t=e.valueBlock.value[1].valueBlock.value[0].valueBlock.value;return{kty:"RSA",n:Q(xr(t[0].toBigInt()),"base64url"),e:Q(xr(t[1].toBigInt()),"base64url")}}function $3(r){if(r.n==null||r.e==null)throw new F("JWK was missing components","ERR_INVALID_PARAMETERS");let t=new Ve({value:[new Ve({value:[new Qt({value:"1.2.840.113549.1.1.1"}),new On]}),new ho({valueHex:new Ve({value:[Le.fromBigInt(br(Y(r.n,"base64url"))),Le.fromBigInt(br(Y(r.e,"base64url")))]}).toBER()})]}).toBER();return new Uint8Array(t,0,t.byteLength)}function xr(r){let e=r.toString(16);e.length%2>0&&(e=`0${e}`);let t=e.length/2,n=new Uint8Array(t),i=0,o=0;for(;i<t;)n[i]=parseInt(e.slice(o,o+2),16),i+=1,o+=2;return n}function br(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 z3=16,Oh=32,Fh=1e4;async function K3(r,e){let t=ot.get(),i=new Ve({value:[new Le({value:0}),new Ve({value:[new Qt({value:"1.2.840.113549.1.1.1"}),new On]}),new Yr({valueHex:r.marshal()})]}).toBER(),o=new Uint8Array(i,0,i.byteLength),s=gi(z3),a=await Nh(oo,e,s,{c:Fh,dkLen:Oh}),c=gi(16),u=await t.subtle.importKey("raw",a,"AES-CBC",!1,["encrypt"]),l=await t.subtle.encrypt({name:"AES-CBC",iv:c},u,o),h=new Ve({value:[new Yr({valueHex:s}),new Le({value:Fh}),new Le({value:Oh}),new Ve({value:[new Qt({value:"1.2.840.113549.2.11"}),new On]})]}),p=new Ve({value:[new Qt({value:"1.2.840.113549.1.5.13"}),new Ve({value:[new Ve({value:[new Qt({value:"1.2.840.113549.1.5.12"}),h]}),new Ve({value:[new Qt({value:"2.16.840.1.101.3.4.1.42"}),new Yr({valueHex:c})]})]})]}),f=new Ve({value:[p,new Yr({valueHex:l})]}).toBER(),m=new Uint8Array(f,0,f.byteLength);return["-----BEGIN ENCRYPTED PRIVATE KEY-----",...Q(m,"base64pad").split(/(.{64})/).filter(Boolean),"-----END ENCRYPTED PRIVATE KEY-----"].join(`
|
|
8
|
-
`)}async function q3(r,e){let t=ot.get(),n;if(r.includes("-----BEGIN ENCRYPTED PRIVATE KEY-----")){let i=Y(r.replace("-----BEGIN ENCRYPTED PRIVATE KEY-----","").replace("-----END ENCRYPTED PRIVATE KEY-----","").replace(/\n/g,"").trim(),"base64pad"),{result:o}=po(i),{iv:s,salt:a,iterations:c,keySize:u,cipherText:l}=j3(o),h=await Nh(oo,e,a,{c,dkLen:u}),p=await t.subtle.importKey("raw",h,"AES-CBC",!1,["decrypt"]),d=ps(await t.subtle.decrypt({name:"AES-CBC",iv:s},p,l)),{result:f}=po(d);n=x1(f)}else if(r.includes("-----BEGIN PRIVATE KEY-----")){let i=Y(r.replace("-----BEGIN PRIVATE KEY-----","").replace("-----END PRIVATE KEY-----","").replace(/\n/g,"").trim(),"base64pad"),{result:o}=po(i);n=x1(o)}else throw new F("Could not parse private key from PEM data","ERR_INVALID_PARAMETERS");return Vh(n)}function j3(r){let e=r.valueBlock.value[0];if(e.valueBlock.value[0].toString()!=="OBJECT IDENTIFIER : 1.2.840.113549.1.5.13")throw new F("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 F("Only pkcs5PBKDF2 key derivation functions are supported","ERR_INVALID_PARAMS");let o=n.valueBlock.value[1],s=ps(o.valueBlock.value[0].getValue()),a=Fh,c=Oh;if(o.valueBlock.value.length===3)a=Number(o.valueBlock.value[1].toBigInt()),c=Number(o.valueBlock.value[2].toBigInt());else if(o.valueBlock.value.length===2)throw new F("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 F("Only AES-CBC encryption schemes are supported","ERR_INVALID_PARAMS")}}}}let h=ps(u.valueBlock.value[1].getValue());return{cipherText:ps(r.valueBlock.value[1].getValue()),salt:s,iterations:a,keySize:c,iv:h}}function x1(r){return ps(r.valueBlock.value[2].getValue())}function ps(r){return new Uint8Array(r,0,r.byteLength)}async function b1(r){let e=await ot.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 B1(e);return{privateKey:t[0],publicKey:t[1]}}async function Mh(r){let t=[await ot.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!0,["sign"]),await G3(r)],n=await B1({privateKey:t[0],publicKey:t[1]});return{privateKey:n[0],publicKey:n[1]}}async function E1(r,e){let t=await ot.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]),n=await ot.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},t,e instanceof Uint8Array?e:e.subarray());return new Uint8Array(n,0,n.byteLength)}async function v1(r,e,t){let n=await ot.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);return ot.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},n,e,t instanceof Uint8Array?t:t.subarray())}async function B1(r){if(r.privateKey==null||r.publicKey==null)throw new F("Private and public key are required","ERR_INVALID_PARAMETERS");return Promise.all([ot.get().subtle.exportKey("jwk",r.privateKey),ot.get().subtle.exportKey("jwk",r.publicKey)])}async function G3(r){return ot.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 Uc(r){if(r.kty!=="RSA")throw new F("invalid key type","ERR_INVALID_KEY_TYPE");if(r.n==null)throw new F("invalid key modulus","ERR_INVALID_KEY_MODULUS");return Y(r.n,"base64url").length*8}var ys=8192,ms=class{_key;constructor(e){this._key=e}verify(e,t){return v1(this._key,t,e)}marshal(){return Fn.jwkToPkix(this._key)}get bytes(){return yr.encode({Type:be.RSA,Data:this.marshal()}).subarray()}equals(e){return de(this.bytes,e.bytes)}hash(){let e=ne.digest(this.bytes);return Mt(e)?e.then(({bytes:t})=>t):e.bytes}},mo=class{_key;_publicKey;constructor(e,t){this._key=e,this._publicKey=t}genSecret(){return gi(16)}sign(e){return E1(this._key,e)}get public(){if(this._publicKey==null)throw new F("public key not provided","ERR_PUBKEY_NOT_PROVIDED");return new ms(this._publicKey)}marshal(){return Fn.jwkToPkcs1(this._key)}get bytes(){return gr.encode({Type:be.RSA,Data:this.marshal()}).subarray()}equals(e){return de(this.bytes,e.bytes)}hash(){let e=ne.digest(this.bytes);return Mt(e)?e.then(({bytes:t})=>t):e.bytes}async id(){let e=await this.public.hash();return Q(e,"base58btc")}async export(e,t="pkcs-8"){if(t==="pkcs-8")return Fn.exportToPem(this,e);if(t==="libp2p-key")return co(this.bytes,e);throw new F(`export format '${t}' is not supported`,"ERR_INVALID_EXPORT_FORMAT")}};async function Vh(r){let e=Fn.pkcs1ToJwk(r);if(Uc(e)>ys)throw new F("key size is too large","ERR_KEY_SIZE_TOO_LARGE");let t=await Mh(e);return new mo(t.privateKey,t.publicKey)}function Y3(r){let e=Fn.pkixToJwk(r);if(Uc(e)>ys)throw new F("key size is too large","ERR_KEY_SIZE_TOO_LARGE");return new ms(e)}async function X3(r){if(Uc(r)>ys)throw new F("key size is too large","ERR_KEY_SIZE_TOO_LARGE");let e=await Mh(r);return new mo(e.privateKey,e.publicKey)}async function Z3(r){if(r>ys)throw new F("key size is too large","ERR_KEY_SIZE_TOO_LARGE");let e=await b1(r);return new mo(e.privateKey,e.publicKey)}var jh={};Ae(jh,{Secp256k1PrivateKey:()=>ws,Secp256k1PublicKey:()=>gs,generateKeyPair:()=>d6,unmarshalSecp256k1PrivateKey:()=>u6,unmarshalSecp256k1PublicKey:()=>h6});var J3=(r,e,t)=>r&e^~r&t,Q3=(r,e,t)=>r&e^r&t^e&t,e6=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]),Vn=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Mn=new Uint32Array(64),$h=class extends io{constructor(){super(64,32,8,!1),this.A=Vn[0]|0,this.B=Vn[1]|0,this.C=Vn[2]|0,this.D=Vn[3]|0,this.E=Vn[4]|0,this.F=Vn[5]|0,this.G=Vn[6]|0,this.H=Vn[7]|0}get(){let{A:e,B:t,C:n,D:i,E:o,F:s,G:a,H:c}=this;return[e,t,n,i,o,s,a,c]}set(e,t,n,i,o,s,a,c){this.A=e|0,this.B=t|0,this.C=n|0,this.D=i|0,this.E=o|0,this.F=s|0,this.G=a|0,this.H=c|0}process(e,t){for(let h=0;h<16;h++,t+=4)Mn[h]=e.getUint32(t,!1);for(let h=16;h<64;h++){let p=Mn[h-15],d=Mn[h-2],f=Xt(p,7)^Xt(p,18)^p>>>3,m=Xt(d,17)^Xt(d,19)^d>>>10;Mn[h]=m+Mn[h-7]+f+Mn[h-16]|0}let{A:n,B:i,C:o,D:s,E:a,F:c,G:u,H:l}=this;for(let h=0;h<64;h++){let p=Xt(a,6)^Xt(a,11)^Xt(a,25),d=l+p+J3(a,c,u)+e6[h]+Mn[h]|0,m=(Xt(n,2)^Xt(n,13)^Xt(n,22))+Q3(n,i,o)|0;l=u,u=c,c=a,a=s+d|0,s=o,o=i,i=n,n=d+m|0}n=n+this.A|0,i=i+this.B|0,o=o+this.C|0,s=s+this.D|0,a=a+this.E|0,c=c+this.F|0,u=u+this.G|0,l=l+this.H|0,this.set(n,i,o,s,a,c,u,l)}roundClean(){Mn.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};var A1=Ua(()=>new $h);function t6(r){let e=ns(r);mr(e,{a:"field",b:"field"},{allowedPrivateKeyLengths:"array",wrapPrivateKey:"boolean",isTorsionFree:"function",clearCofactor:"function",allowInfinityPoint:"boolean",fromBytes:"function",toBytes:"function"});let{endo:t,Fp:n,a:i}=e;if(t){if(!n.eql(i,n.ZERO))throw new Error("Endomorphism can only be defined for Koblitz curves that have a=0");if(typeof t!="object"||typeof t.beta!="bigint"||typeof t.splitScalar!="function")throw new Error("Expected endomorphism with beta: bigint and splitScalar: function")}return Object.freeze({...e})}var{bytesToNumberBE:r6,hexToBytes:n6}=Pa,xi={Err:class extends Error{constructor(e=""){super(e)}},_parseInt(r){let{Err:e}=xi;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:r6(n),l:r.subarray(t+2)}},toSig(r){let{Err:e}=xi,t=typeof r=="string"?n6(r):r;if(!Zt(t))throw new Error("ui8a expected");let n=t.length;if(n<2||t[0]!=48)throw new e("Invalid signature tag");if(t[1]!==n-2)throw new e("Invalid signature: incorrect length");let{d:i,l:o}=xi._parseInt(t.subarray(2)),{d:s,l:a}=xi._parseInt(o);if(a.length)throw new e("Invalid signature: left bytes after parsing");return{r:i,s}},hexFromSig(r){let e=u=>Number.parseInt(u[0],16)&8?"00"+u:u,t=u=>{let l=u.toString(16);return l.length&1?`0${l}`:l},n=e(t(r.s)),i=e(t(r.r)),o=n.length/2,s=i.length/2,a=t(o),c=t(s);return`30${t(s+o+4)}02${c}${i}02${a}${n}`}},Qr=BigInt(0),$t=BigInt(1),Ck=BigInt(2),I1=BigInt(3),Nk=BigInt(4);function i6(r){let e=t6(r),{Fp:t}=e,n=e.toBytes||((f,m,y)=>{let g=m.toAffine();return Kr(Uint8Array.from([4]),t.toBytes(g.x),t.toBytes(g.y))}),i=e.fromBytes||(f=>{let m=f.subarray(1),y=t.fromBytes(m.subarray(0,t.BYTES)),g=t.fromBytes(m.subarray(t.BYTES,2*t.BYTES));return{x:y,y:g}});function o(f){let{a:m,b:y}=e,g=t.sqr(f),x=t.mul(g,f);return t.add(t.add(x,t.mul(f,m)),y)}if(!t.eql(t.sqr(e.Gy),o(e.Gx)))throw new Error("bad generator point: equation left != right");function s(f){return typeof f=="bigint"&&Qr<f&&f<e.n}function a(f){if(!s(f))throw new Error("Expected valid bigint: 0 < bigint < curve.n")}function c(f){let{allowedPrivateKeyLengths:m,nByteLength:y,wrapPrivateKey:g,n:x}=e;if(m&&typeof f!="bigint"){if(Zt(f)&&(f=$r(f)),typeof f!="string"||!m.includes(f.length))throw new Error("Invalid key");f=f.padStart(y*2,"0")}let b;try{b=typeof f=="bigint"?f:zr(Se("private key",f,y))}catch{throw new Error(`private key must be ${y} bytes, hex or bigint, not ${typeof f}`)}return g&&(b=ye(b,x)),a(b),b}let u=new Map;function l(f){if(!(f instanceof h))throw new Error("ProjectivePoint expected")}class h{constructor(m,y,g){if(this.px=m,this.py=y,this.pz=g,m==null||!t.isValid(m))throw new Error("x required");if(y==null||!t.isValid(y))throw new Error("y required");if(g==null||!t.isValid(g))throw new Error("z required")}static fromAffine(m){let{x:y,y:g}=m||{};if(!m||!t.isValid(y)||!t.isValid(g))throw new Error("invalid affine point");if(m instanceof h)throw new Error("projective point not allowed");let x=b=>t.eql(b,t.ZERO);return x(y)&&x(g)?h.ZERO:new h(y,g,t.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(m){let y=t.invertBatch(m.map(g=>g.pz));return m.map((g,x)=>g.toAffine(y[x])).map(h.fromAffine)}static fromHex(m){let y=h.fromAffine(i(Se("pointHex",m)));return y.assertValidity(),y}static fromPrivateKey(m){return h.BASE.multiply(c(m))}_setWindowSize(m){this._WINDOW_SIZE=m,u.delete(this)}assertValidity(){if(this.is0()){if(e.allowInfinityPoint&&!t.is0(this.py))return;throw new Error("bad point: ZERO")}let{x:m,y}=this.toAffine();if(!t.isValid(m)||!t.isValid(y))throw new Error("bad point: x or y not FE");let g=t.sqr(y),x=o(m);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:m}=this.toAffine();if(t.isOdd)return!t.isOdd(m);throw new Error("Field doesn't support isOdd")}equals(m){l(m);let{px:y,py:g,pz:x}=this,{px:b,py:A,pz:I}=m,B=t.eql(t.mul(y,I),t.mul(b,x)),v=t.eql(t.mul(g,I),t.mul(A,x));return B&&v}negate(){return new h(this.px,t.neg(this.py),this.pz)}double(){let{a:m,b:y}=e,g=t.mul(y,I1),{px:x,py:b,pz:A}=this,I=t.ZERO,B=t.ZERO,v=t.ZERO,E=t.mul(x,x),R=t.mul(b,b),N=t.mul(A,A),C=t.mul(x,b);return C=t.add(C,C),v=t.mul(x,A),v=t.add(v,v),I=t.mul(m,v),B=t.mul(g,N),B=t.add(I,B),I=t.sub(R,B),B=t.add(R,B),B=t.mul(I,B),I=t.mul(C,I),v=t.mul(g,v),N=t.mul(m,N),C=t.sub(E,N),C=t.mul(m,C),C=t.add(C,v),v=t.add(E,E),E=t.add(v,E),E=t.add(E,N),E=t.mul(E,C),B=t.add(B,E),N=t.mul(b,A),N=t.add(N,N),E=t.mul(N,C),I=t.sub(I,E),v=t.mul(N,R),v=t.add(v,v),v=t.add(v,v),new h(I,B,v)}add(m){l(m);let{px:y,py:g,pz:x}=this,{px:b,py:A,pz:I}=m,B=t.ZERO,v=t.ZERO,E=t.ZERO,R=e.a,N=t.mul(e.b,I1),C=t.mul(y,b),H=t.mul(g,A),D=t.mul(x,I),ie=t.add(y,g),_=t.add(b,A);ie=t.mul(ie,_),_=t.add(C,H),ie=t.sub(ie,_),_=t.add(y,x);let L=t.add(b,I);return _=t.mul(_,L),L=t.add(C,D),_=t.sub(_,L),L=t.add(g,x),B=t.add(A,I),L=t.mul(L,B),B=t.add(H,D),L=t.sub(L,B),E=t.mul(R,_),B=t.mul(N,D),E=t.add(B,E),B=t.sub(H,E),E=t.add(H,E),v=t.mul(B,E),H=t.add(C,C),H=t.add(H,C),D=t.mul(R,D),_=t.mul(N,_),H=t.add(H,D),D=t.sub(C,D),D=t.mul(R,D),_=t.add(_,D),C=t.mul(H,_),v=t.add(v,C),C=t.mul(L,_),B=t.mul(ie,B),B=t.sub(B,C),C=t.mul(ie,H),E=t.mul(L,E),E=t.add(E,C),new h(B,v,E)}subtract(m){return this.add(m.negate())}is0(){return this.equals(h.ZERO)}wNAF(m){return d.wNAFCached(this,u,m,y=>{let g=t.invertBatch(y.map(x=>x.pz));return y.map((x,b)=>x.toAffine(g[b])).map(h.fromAffine)})}multiplyUnsafe(m){let y=h.ZERO;if(m===Qr)return y;if(a(m),m===$t)return this;let{endo:g}=e;if(!g)return d.unsafeLadder(this,m);let{k1neg:x,k1:b,k2neg:A,k2:I}=g.splitScalar(m),B=y,v=y,E=this;for(;b>Qr||I>Qr;)b&$t&&(B=B.add(E)),I&$t&&(v=v.add(E)),E=E.double(),b>>=$t,I>>=$t;return x&&(B=B.negate()),A&&(v=v.negate()),v=new h(t.mul(v.px,g.beta),v.py,v.pz),B.add(v)}multiply(m){a(m);let y=m,g,x,{endo:b}=e;if(b){let{k1neg:A,k1:I,k2neg:B,k2:v}=b.splitScalar(y),{p:E,f:R}=this.wNAF(I),{p:N,f:C}=this.wNAF(v);E=d.constTimeNegate(A,E),N=d.constTimeNegate(B,N),N=new h(t.mul(N.px,b.beta),N.py,N.pz),g=E.add(N),x=R.add(C)}else{let{p:A,f:I}=this.wNAF(y);g=A,x=I}return h.normalizeZ([g,x])[0]}multiplyAndAddUnsafe(m,y,g){let x=h.BASE,b=(I,B)=>B===Qr||B===$t||!I.equals(x)?I.multiplyUnsafe(B):I.multiply(B),A=b(this,y).add(b(m,g));return A.is0()?void 0:A}toAffine(m){let{px:y,py:g,pz:x}=this,b=this.is0();m==null&&(m=b?t.ONE:t.inv(x));let A=t.mul(y,m),I=t.mul(g,m),B=t.mul(x,m);if(b)return{x:t.ZERO,y:t.ZERO};if(!t.eql(B,t.ONE))throw new Error("invZ was invalid");return{x:A,y:I}}isTorsionFree(){let{h:m,isTorsionFree:y}=e;if(m===$t)return!0;if(y)return y(h,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){let{h:m,clearCofactor:y}=e;return m===$t?this:y?y(h,this):this.multiplyUnsafe(e.h)}toRawBytes(m=!0){return this.assertValidity(),n(h,this,m)}toHex(m=!0){return $r(this.toRawBytes(m))}}h.BASE=new h(e.Gx,e.Gy,t.ONE),h.ZERO=new h(t.ZERO,t.ONE,t.ZERO);let p=e.nBitLength,d=Va(h,e.endo?Math.ceil(p/2):p);return{CURVE:e,ProjectivePoint:h,normPrivateKeyToScalar:c,weierstrassEquation:o,isWithinCurveOrder:s}}function o6(r){let e=ns(r);return mr(e,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...e})}function S1(r){let e=o6(r),{Fp:t,n}=e,i=t.BYTES+1,o=2*t.BYTES+1;function s(_){return Qr<_&&_<t.ORDER}function a(_){return ye(_,n)}function c(_){return Oa(_,n)}let{ProjectivePoint:u,normPrivateKeyToScalar:l,weierstrassEquation:h,isWithinCurveOrder:p}=i6({...e,toBytes(_,L,X){let U=L.toAffine(),k=t.toBytes(U.x),z=Kr;return X?z(Uint8Array.from([L.hasEvenY()?2:3]),k):z(Uint8Array.from([4]),k,t.toBytes(U.y))},fromBytes(_){let L=_.length,X=_[0],U=_.subarray(1);if(L===i&&(X===2||X===3)){let k=zr(U);if(!s(k))throw new Error("Point is not on curve");let z=h(k),G=t.sqrt(z),Z=(G&$t)===$t;return(X&1)===1!==Z&&(G=t.neg(G)),{x:k,y:G}}else if(L===o&&X===4){let k=t.fromBytes(U.subarray(0,t.BYTES)),z=t.fromBytes(U.subarray(t.BYTES,2*t.BYTES));return{x:k,y:z}}else throw new Error(`Point of length ${L} was invalid. Expected ${i} compressed bytes or ${o} uncompressed bytes`)}}),d=_=>$r(Ln(_,e.nByteLength));function f(_){let L=n>>$t;return _>L}function m(_){return f(_)?a(-_):_}let y=(_,L,X)=>zr(_.slice(L,X));class g{constructor(L,X,U){this.r=L,this.s=X,this.recovery=U,this.assertValidity()}static fromCompact(L){let X=e.nByteLength;return L=Se("compactSignature",L,X*2),new g(y(L,0,X),y(L,X,2*X))}static fromDER(L){let{r:X,s:U}=xi.toSig(Se("DER",L));return new g(X,U)}assertValidity(){if(!p(this.r))throw new Error("r must be 0 < r < CURVE.n");if(!p(this.s))throw new Error("s must be 0 < s < CURVE.n")}addRecoveryBit(L){return new g(this.r,this.s,L)}recoverPublicKey(L){let{r:X,s:U,recovery:k}=this,z=v(Se("msgHash",L));if(k==null||![0,1,2,3].includes(k))throw new Error("recovery id invalid");let G=k===2||k===3?X+e.n:X;if(G>=t.ORDER)throw new Error("recovery id 2 or 3 invalid");let Z=k&1?"03":"02",te=u.fromHex(Z+d(G)),oe=c(G),pe=a(-z*oe),ce=a(U*oe),ue=u.BASE.multiplyAndAddUnsafe(te,pe,ce);if(!ue)throw new Error("point at infinify");return ue.assertValidity(),ue}hasHighS(){return f(this.s)}normalizeS(){return this.hasHighS()?new g(this.r,a(-this.s),this.recovery):this}toDERRawBytes(){return fi(this.toDERHex())}toDERHex(){return xi.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return fi(this.toCompactHex())}toCompactHex(){return d(this.r)+d(this.s)}}let x={isValidPrivateKey(_){try{return l(_),!0}catch{return!1}},normPrivateKeyToScalar:l,randomPrivateKey:()=>{let _=Ah(e.n);return bp(e.randomBytes(_),e.n)},precompute(_=8,L=u.BASE){return L._setWindowSize(_),L.multiply(BigInt(3)),L}};function b(_,L=!0){return u.fromPrivateKey(_).toRawBytes(L)}function A(_){let L=Zt(_),X=typeof _=="string",U=(L||X)&&_.length;return L?U===i||U===o:X?U===2*i||U===2*o:_ instanceof u}function I(_,L,X=!0){if(A(_))throw new Error("first arg must be private key");if(!A(L))throw new Error("second arg must be public key");return u.fromHex(L).multiply(l(_)).toRawBytes(X)}let B=e.bits2int||function(_){let L=zr(_),X=_.length*8-e.nBitLength;return X>0?L>>BigInt(X):L},v=e.bits2int_modN||function(_){return a(B(_))},E=rs(e.nBitLength);function R(_){if(typeof _!="bigint")throw new Error("bigint expected");if(!(Qr<=_&&_<E))throw new Error(`bigint expected < 2^${e.nBitLength}`);return Ln(_,e.nByteLength)}function N(_,L,X=C){if(["recovered","canonical"].some(Be=>Be in X))throw new Error("sign() legacy options not supported");let{hash:U,randomBytes:k}=e,{lowS:z,prehash:G,extraEntropy:Z}=X;z==null&&(z=!0),_=Se("msgHash",_),G&&(_=Se("prehashed msgHash",U(_)));let te=v(_),oe=l(L),pe=[R(oe),R(te)];if(Z!=null){let Be=Z===!0?k(t.BYTES):Z;pe.push(Se("extraEntropy",Be))}let ce=Kr(...pe),ue=te;function Ce(Be){let ze=B(Be);if(!p(ze))return;let Ke=c(ze),Pe=u.BASE.multiply(ze).toAffine(),Ze=a(Pe.x);if(Ze===Qr)return;let Or=a(Ke*a(ue+Ze*oe));if(Or===Qr)return;let ii=(Pe.x===Ze?0:2)|Number(Pe.y&$t),Ko=Or;return z&&f(Or)&&(Ko=m(Or),ii^=1),new g(Ze,Ko,ii)}return{seed:ce,k2sig:Ce}}let C={lowS:e.lowS,prehash:!1},H={lowS:e.lowS,prehash:!1};function D(_,L,X=C){let{seed:U,k2sig:k}=N(_,L,X),z=e;return bh(z.hash.outputLen,z.nByteLength,z.hmac)(U,k)}u.BASE._setWindowSize(8);function ie(_,L,X,U=H){let k=_;if(L=Se("msgHash",L),X=Se("publicKey",X),"strict"in U)throw new Error("options.strict was renamed to lowS");let{lowS:z,prehash:G}=U,Z,te;try{if(typeof k=="string"||Zt(k))try{Z=g.fromDER(k)}catch(Pe){if(!(Pe instanceof xi.Err))throw Pe;Z=g.fromCompact(k)}else if(typeof k=="object"&&typeof k.r=="bigint"&&typeof k.s=="bigint"){let{r:Pe,s:Ze}=k;Z=new g(Pe,Ze)}else throw new Error("PARSE");te=u.fromHex(X)}catch(Pe){if(Pe.message==="PARSE")throw new Error("signature must be Signature instance, Uint8Array or hex string");return!1}if(z&&Z.hasHighS())return!1;G&&(L=e.hash(L));let{r:oe,s:pe}=Z,ce=v(L),ue=c(pe),Ce=a(ce*ue),Be=a(oe*ue),ze=u.BASE.multiplyAndAddUnsafe(te,Ce,Be)?.toAffine();return ze?a(ze.x)===oe:!1}return{CURVE:e,getPublicKey:b,getSharedSecret:I,sign:D,verify:ie,ProjectivePoint:u,Signature:g,utils:x}}function s6(r){return{hash:r,hmac:(e,...t)=>os(r,e,Na(...t)),randomBytes:no}}function _1(r,e){let t=n=>S1({...r,...s6(n)});return Object.freeze({...t(e),create:t})}var T1=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),k1=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),a6=BigInt(1),zh=BigInt(2),R1=(r,e)=>(r+e/zh)/e;function c6(r){let e=T1,t=BigInt(3),n=BigInt(6),i=BigInt(11),o=BigInt(22),s=BigInt(23),a=BigInt(44),c=BigInt(88),u=r*r*r%e,l=u*u*r%e,h=xe(l,t,e)*l%e,p=xe(h,t,e)*l%e,d=xe(p,zh,e)*u%e,f=xe(d,i,e)*d%e,m=xe(f,o,e)*f%e,y=xe(m,a,e)*m%e,g=xe(y,c,e)*y%e,x=xe(g,a,e)*m%e,b=xe(x,t,e)*l%e,A=xe(b,s,e)*f%e,I=xe(A,n,e)*u%e,B=xe(I,zh,e);if(!Kh.eql(Kh.sqr(B),r))throw new Error("Cannot find square root");return B}var Kh=Fa(T1,void 0,void 0,{sqrt:c6}),tr=_1({a:BigInt(0),b:BigInt(7),Fp:Kh,n:k1,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:r=>{let e=k1,t=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-a6*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),i=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),o=t,s=BigInt("0x100000000000000000000000000000000"),a=R1(o*r,e),c=R1(-n*r,e),u=ye(r-a*t-c*i,e),l=ye(-a*n-c*o,e),h=u>s,p=l>s;if(h&&(u=e-u),p&&(l=e-l),u>s||l>s)throw new Error("splitScalar: Endomorphism failed, k="+r);return{k1neg:h,k1:u,k2neg:p,k2:l}}}},A1),Hk=BigInt(0);var $k=tr.ProjectivePoint;function C1(){return tr.utils.randomPrivateKey()}function N1(r,e){let t=ne.digest(e instanceof Uint8Array?e:e.subarray());if(Mt(t))return t.then(({digest:n})=>tr.sign(n,r).toDERRawBytes()).catch(n=>{throw new F(String(n),"ERR_INVALID_INPUT")});try{return tr.sign(t.digest,r).toDERRawBytes()}catch(n){throw new F(String(n),"ERR_INVALID_INPUT")}}function U1(r,e,t){let n=ne.digest(t instanceof Uint8Array?t:t.subarray());if(Mt(n))return n.then(({digest:i})=>tr.verify(e,i,r)).catch(i=>{throw new F(String(i),"ERR_INVALID_INPUT")});try{return tr.verify(e,n.digest,r)}catch(i){throw new F(String(i),"ERR_INVALID_INPUT")}}function L1(r){return tr.ProjectivePoint.fromHex(r).toRawBytes(!0)}function D1(r){try{tr.getPublicKey(r,!0)}catch(e){throw new F(String(e),"ERR_INVALID_PRIVATE_KEY")}}function qh(r){try{tr.ProjectivePoint.fromHex(r)}catch(e){throw new F(String(e),"ERR_INVALID_PUBLIC_KEY")}}function P1(r){try{return tr.getPublicKey(r,!0)}catch(e){throw new F(String(e),"ERR_INVALID_PRIVATE_KEY")}}var gs=class{_key;constructor(e){qh(e),this._key=e}verify(e,t){return U1(this._key,t,e)}marshal(){return L1(this._key)}get bytes(){return yr.encode({Type:be.Secp256k1,Data:this.marshal()}).subarray()}equals(e){return de(this.bytes,e.bytes)}async hash(){let e=ne.digest(this.bytes),t;return Mt(e)?{bytes:t}=await e:t=e.bytes,t}},ws=class{_key;_publicKey;constructor(e,t){this._key=e,this._publicKey=t??P1(e),D1(this._key),qh(this._publicKey)}sign(e){return N1(this._key,e)}get public(){return new gs(this._publicKey)}marshal(){return this._key}get bytes(){return gr.encode({Type:be.Secp256k1,Data:this.marshal()}).subarray()}equals(e){return de(this.bytes,e.bytes)}hash(){let e=ne.digest(this.bytes);return Mt(e)?e.then(({bytes:t})=>t):e.bytes}async id(){let e=await this.public.hash();return Q(e,"base58btc")}async export(e,t="libp2p-key"){if(t==="libp2p-key")return co(this.bytes,e);throw new F(`export format '${t}' is not supported`,"ERR_INVALID_EXPORT_FORMAT")}};function u6(r){return new ws(r)}function h6(r){return new gs(r)}async function d6(){let r=C1();return new ws(r)}var bi={rsa:Hh,ed25519:Ch,secp256k1:jh};function O1(r){let e=Object.keys(bi).join(" / ");return new F(`invalid or unsupported key type ${r}. Must be ${e}`,"ERR_UNSUPPORTED_KEY_TYPE")}function Gh(r){let e=yr.decode(r),t=e.Data??new Uint8Array;switch(e.Type){case be.RSA:return bi.rsa.unmarshalRsaPublicKey(t);case be.Ed25519:return bi.ed25519.unmarshalEd25519PublicKey(t);case be.Secp256k1:return bi.secp256k1.unmarshalSecp256k1PublicKey(t);default:throw O1(e.Type??"unknown")}}async function F1(r){let e=gr.decode(r),t=e.Data??new Uint8Array;switch(e.Type){case be.RSA:return bi.rsa.unmarshalRsaPrivateKey(t);case be.Ed25519:return bi.ed25519.unmarshalEd25519PrivateKey(t);case be.Secp256k1:return bi.secp256k1.unmarshalSecp256k1PrivateKey(t);default:throw O1(e.Type??"RSA")}}var ad=re(Re(),1);var en="/",V1=new TextEncoder().encode(en),Lc=V1[0],Fe=class r{_buf;constructor(e,t){if(typeof e=="string")this._buf=Y(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]!==Lc)throw new Error("Invalid key")}toString(e="utf8"){return Q(this._buf,e)}uint8Array(){return this._buf}get[Symbol.toStringTag](){return`Key(${this.toString()})`}static withNamespaces(e){return new r(e.join(en))}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=V1),this._buf[0]!==Lc){let e=new Uint8Array(this._buf.byteLength+1);e.fill(Lc,0,1),e.set(this._buf,1),this._buf=e}for(;this._buf.byteLength>1&&this._buf[this._buf.byteLength-1]===Lc;)this._buf=this._buf.subarray(0,-1)}less(e){let t=this.list(),n=e.list();for(let i=0;i<t.length;i++){if(n.length<i+1)return!1;let o=t[i],s=n[i];if(o<s)return!0;if(o>s)return!1}return t.length<n.length}reverse(){return r.withNamespaces(this.list().slice().reverse())}namespaces(){return this.list()}baseNamespace(){let e=this.namespaces();return e[e.length-1]}list(){return this.toString().split(en).slice(1)}type(){return f6(this.baseNamespace())}name(){return p6(this.baseNamespace())}instance(e){return new r(this.toString()+":"+e)}path(){let e=this.parent().toString();return e.endsWith(en)||(e+=en),e+=this.type(),new r(e)}parent(){let e=this.list();return e.length===1?new r(en):new r(e.slice(0,-1).join(en))}child(e){return this.toString()===en?e:e.toString()===en?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(),...m6(e.map(t=>t.namespaces()))])}};function f6(r){let e=r.split(":");return e.length<2?"":e.slice(0,-1).join(":")}function p6(r){let e=r.split(":");return e[e.length-1]}function m6(r){return[].concat(...r)}var ry=re(Dc(),1);var M1="ERR_IPNS_EXPIRED_RECORD",xs="ERR_UNRECOGNIZED_VALIDITY",H1="ERR_SIGNATURE_CREATION",tn="ERR_SIGNATURE_VERIFICATION";var Yh="ERR_UNDEFINED_PARAMETER",$1="ERR_INVALID_RECORD_DATA",z1="ERR_INVALID_VALUE",K1="ERR_INVALID_EMBEDDED_KEY",q1="ERR_MISSING_PRIVATE_KEY",j1="ERR_RECORD_TOO_LARGE";var Ge;(function(r){let e;(function(i){i.EOL="EOL"})(e=r.ValidityType||(r.ValidityType={}));let t;(function(i){i[i.EOL=0]="EOL"})(t||(t={})),function(i){i.codec=()=>hi(t)}(e=r.ValidityType||(r.ValidityType={}));let n;r.codec=()=>(n==null&&(n=Ft((i,o,s={})=>{s.lengthDelimited!==!1&&o.fork(),i.value!=null&&(o.uint32(10),o.bytes(i.value)),i.signatureV1!=null&&(o.uint32(18),o.bytes(i.signatureV1)),i.validityType!=null&&(o.uint32(24),r.ValidityType.codec().encode(i.validityType,o)),i.validity!=null&&(o.uint32(34),o.bytes(i.validity)),i.sequence!=null&&(o.uint32(40),o.uint64(i.sequence)),i.ttl!=null&&(o.uint32(48),o.uint64(i.ttl)),i.pubKey!=null&&(o.uint32(58),o.bytes(i.pubKey)),i.signatureV2!=null&&(o.uint32(66),o.bytes(i.signatureV2)),i.data!=null&&(o.uint32(74),o.bytes(i.data)),s.lengthDelimited!==!1&&o.ldelim()},(i,o)=>{let s={},a=o==null?i.len:i.pos+o;for(;i.pos<a;){let c=i.uint32();switch(c>>>3){case 1:s.value=i.bytes();break;case 2:s.signatureV1=i.bytes();break;case 3:s.validityType=r.ValidityType.codec().decode(i);break;case 4:s.validity=i.bytes();break;case 5:s.sequence=i.uint64();break;case 6:s.ttl=i.uint64();break;case 7:s.pubKey=i.bytes();break;case 8:s.signatureV2=i.bytes();break;case 9:s.data=i.bytes();break;default:i.skipType(c&7);break}}return s})),n),r.encode=i=>Ot(i,r.codec()),r.decode=i=>Dt(i,r.codec())})(Ge||(Ge={}));var y6=["string","number","bigint","symbol"],g6=["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 G1(r){if(r===null)return"null";if(r===void 0)return"undefined";if(r===!0||r===!1)return"boolean";let e=typeof r;if(y6.includes(e))return e;if(e==="function")return"Function";if(Array.isArray(r))return"Array";if(w6(r))return"Buffer";let t=x6(r);return t||"Object"}function w6(r){return r&&r.constructor&&r.constructor.isBuffer&&r.constructor.isBuffer.call(null,r)}function x6(r){let e=Object.prototype.toString.call(r).slice(8,-1);if(g6.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 T=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 yo=globalThis.process&&!globalThis.process.browser&&globalThis.Buffer&&typeof globalThis.Buffer.isBuffer=="function",b6=new TextDecoder,E6=new TextEncoder;function Pc(r){return yo&&globalThis.Buffer.isBuffer(r)}function bs(r){return r instanceof Uint8Array?Pc(r)?new Uint8Array(r.buffer,r.byteOffset,r.byteLength):r:Uint8Array.from(r)}var Z1=yo?(r,e,t)=>t-e>64?globalThis.Buffer.from(r.subarray(e,t)).toString("utf8"):Y1(r,e,t):(r,e,t)=>t-e>64?b6.decode(r.subarray(e,t)):Y1(r,e,t),Oc=yo?r=>r.length>64?globalThis.Buffer.from(r):W1(r):r=>r.length>64?E6.encode(r):W1(r),Er=r=>Uint8Array.from(r),go=yo?(r,e,t)=>Pc(r)?new Uint8Array(r.subarray(e,t)):r.slice(e,t):(r,e,t)=>r.slice(e,t),J1=yo?(r,e)=>(r=r.map(t=>t instanceof Uint8Array?t:globalThis.Buffer.from(t)),bs(globalThis.Buffer.concat(r,e))):(r,e)=>{let t=new Uint8Array(e),n=0;for(let i of r)n+i.length>t.length&&(i=i.subarray(0,t.length-n)),t.set(i,n),n+=i.length;return t},Q1=yo?r=>globalThis.Buffer.allocUnsafe(r):r=>new Uint8Array(r);function em(r,e){if(Pc(r)&&Pc(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 W1(r){let e=[],t=0;for(let n=0;n<r.length;n++){let i=r.charCodeAt(n);i<128?e[t++]=i:i<2048?(e[t++]=i>>6|192,e[t++]=i&63|128):(i&64512)===55296&&n+1<r.length&&(r.charCodeAt(n+1)&64512)===56320?(i=65536+((i&1023)<<10)+(r.charCodeAt(++n)&1023),e[t++]=i>>18|240,e[t++]=i>>12&63|128,e[t++]=i>>6&63|128,e[t++]=i&63|128):(e[t++]=i>>12|224,e[t++]=i>>6&63|128,e[t++]=i&63|128)}return e}function Y1(r,e,t){let n=[];for(;e<t;){let i=r[e],o=null,s=i>239?4:i>223?3:i>191?2:1;if(e+s<=t){let a,c,u,l;switch(s){case 1:i<128&&(o=i);break;case 2:a=r[e+1],(a&192)===128&&(l=(i&31)<<6|a&63,l>127&&(o=l));break;case 3:a=r[e+1],c=r[e+2],(a&192)===128&&(c&192)===128&&(l=(i&15)<<12|(a&63)<<6|c&63,l>2047&&(l<55296||l>57343)&&(o=l));break;case 4:a=r[e+1],c=r[e+2],u=r[e+3],(a&192)===128&&(c&192)===128&&(u&192)===128&&(l=(i&15)<<18|(a&63)<<12|(c&63)<<6|u&63,l>65535&&l<1114112&&(o=l))}}o===null?(o=65533,s=1):o>65535&&(o-=65536,n.push(o>>>10&1023|55296),o=56320|o&1023),n.push(o),e+=s}return Zh(n)}var X1=4096;function Zh(r){let e=r.length;if(e<=X1)return String.fromCharCode.apply(String,r);let t="",n=0;for(;n<e;)t+=String.fromCharCode.apply(String,r.slice(n,n+=X1));return t}var v6=256,Es=class{constructor(e=v6){this.chunkSize=e,this.cursor=0,this.maxCursor=-1,this.chunks=[],this._initReuseChunk=null}reset(){this.cursor=0,this.maxCursor=-1,this.chunks.length&&(this.chunks=[]),this._initReuseChunk!==null&&(this.chunks.push(this._initReuseChunk),this.maxCursor=this._initReuseChunk.length-1)}push(e){let t=this.chunks[this.chunks.length-1];if(this.cursor+e.length<=this.maxCursor+1){let i=t.length-(this.maxCursor-this.cursor)-1;t.set(e,i)}else{if(t){let i=t.length-(this.maxCursor-this.cursor)-1;i<t.length&&(this.chunks[this.chunks.length-1]=t.subarray(0,i),this.maxCursor=this.cursor-1)}e.length<64&&e.length<this.chunkSize?(t=Q1(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=go(n,0,this.cursor)}else t=J1(this.chunks,this.cursor);return e&&this.reset(),t}};var K="CBOR decode error:",rn="CBOR encode error:",vs=[];vs[23]=1;vs[24]=2;vs[25]=3;vs[26]=5;vs[27]=9;function nn(r,e,t){if(r.length-e<t)throw new Error(`${K} not enough data for type`)}var Me=[24,256,65536,4294967296,BigInt("18446744073709551616")];function It(r,e,t){nn(r,e,1);let n=r[e];if(t.strict===!0&&n<Me[0])throw new Error(`${K} integer encoded in more bytes than necessary (strict decode)`);return n}function St(r,e,t){nn(r,e,2);let n=r[e]<<8|r[e+1];if(t.strict===!0&&n<Me[1])throw new Error(`${K} integer encoded in more bytes than necessary (strict decode)`);return n}function _t(r,e,t){nn(r,e,4);let n=r[e]*16777216+(r[e+1]<<16)+(r[e+2]<<8)+r[e+3];if(t.strict===!0&&n<Me[2])throw new Error(`${K} integer encoded in more bytes than necessary (strict decode)`);return n}function kt(r,e,t){nn(r,e,8);let n=r[e]*16777216+(r[e+1]<<16)+(r[e+2]<<8)+r[e+3],i=r[e+4]*16777216+(r[e+5]<<16)+(r[e+6]<<8)+r[e+7],o=(BigInt(n)<<BigInt(32))+BigInt(i);if(t.strict===!0&&o<Me[3])throw new Error(`${K} integer encoded in more bytes than necessary (strict decode)`);if(o<=Number.MAX_SAFE_INTEGER)return Number(o);if(t.allowBigInt===!0)return o;throw new Error(`${K} integers outside of the safe integer range are not supported`)}function tm(r,e,t,n){return new T(w.uint,It(r,e+1,n),2)}function rm(r,e,t,n){return new T(w.uint,St(r,e+1,n),3)}function nm(r,e,t,n){return new T(w.uint,_t(r,e+1,n),5)}function im(r,e,t,n){return new T(w.uint,kt(r,e+1,n),9)}function zt(r,e){return We(r,0,e.value)}function We(r,e,t){if(t<Me[0]){let n=Number(t);r.push([e|n])}else if(t<Me[1]){let n=Number(t);r.push([e|24,n])}else if(t<Me[2]){let n=Number(t);r.push([e|25,n>>>8,n&255])}else if(t<Me[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<Me[4]){let i=[e|27,0,0,0,0,0,0,0],o=Number(n&BigInt(4294967295)),s=Number(n>>BigInt(32)&BigInt(4294967295));i[8]=o&255,o=o>>8,i[7]=o&255,o=o>>8,i[6]=o&255,o=o>>8,i[5]=o&255,i[4]=s&255,s=s>>8,i[3]=s&255,s=s>>8,i[2]=s&255,s=s>>8,i[1]=s&255,r.push(i)}else throw new Error(`${K} encountered BigInt larger than allowable range`)}}zt.encodedSize=function(e){return We.encodedSize(e.value)};We.encodedSize=function(e){return e<Me[0]?1:e<Me[1]?2:e<Me[2]?3:e<Me[3]?5:9};zt.compareTokens=function(e,t){return e.value<t.value?-1:e.value>t.value?1:0};function om(r,e,t,n){return new T(w.negint,-1-It(r,e+1,n),2)}function sm(r,e,t,n){return new T(w.negint,-1-St(r,e+1,n),3)}function am(r,e,t,n){return new T(w.negint,-1-_t(r,e+1,n),5)}var Jh=BigInt(-1),cm=BigInt(1);function lm(r,e,t,n){let i=kt(r,e+1,n);if(typeof i!="bigint"){let o=-1-i;if(o>=Number.MIN_SAFE_INTEGER)return new T(w.negint,o,9)}if(n.allowBigInt!==!0)throw new Error(`${K} integers outside of the safe integer range are not supported`);return new T(w.negint,Jh-BigInt(i),9)}function Fc(r,e){let t=e.value,n=typeof t=="bigint"?t*Jh-cm:t*-1-1;We(r,e.type.majorEncoded,n)}Fc.encodedSize=function(e){let t=e.value,n=typeof t=="bigint"?t*Jh-cm:t*-1-1;return n<Me[0]?1:n<Me[1]?2:n<Me[2]?3:n<Me[3]?5:9};Fc.compareTokens=function(e,t){return e.value<t.value?1:e.value>t.value?-1:0};function Bs(r,e,t,n){nn(r,e,t+n);let i=go(r,e+t,e+t+n);return new T(w.bytes,i,t+n)}function um(r,e,t,n){return Bs(r,e,1,t)}function hm(r,e,t,n){return Bs(r,e,2,It(r,e+1,n))}function dm(r,e,t,n){return Bs(r,e,3,St(r,e+1,n))}function fm(r,e,t,n){return Bs(r,e,5,_t(r,e+1,n))}function pm(r,e,t,n){let i=kt(r,e+1,n);if(typeof i=="bigint")throw new Error(`${K} 64-bit integer bytes lengths not supported`);return Bs(r,e,9,i)}function Vc(r){return r.encodedBytes===void 0&&(r.encodedBytes=r.type===w.string?Oc(r.value):r.value),r.encodedBytes}function wo(r,e){let t=Vc(e);We(r,e.type.majorEncoded,t.length),r.push(t)}wo.encodedSize=function(e){let t=Vc(e);return We.encodedSize(t.length)+t.length};wo.compareTokens=function(e,t){return A6(Vc(e),Vc(t))};function A6(r,e){return r.length<e.length?-1:r.length>e.length?1:em(r,e)}function As(r,e,t,n,i){let o=t+n;nn(r,e,o);let s=new T(w.string,Z1(r,e+t,e+o),o);return i.retainStringBytes===!0&&(s.byteValue=go(r,e+t,e+o)),s}function mm(r,e,t,n){return As(r,e,1,t,n)}function ym(r,e,t,n){return As(r,e,2,It(r,e+1,n),n)}function gm(r,e,t,n){return As(r,e,3,St(r,e+1,n),n)}function wm(r,e,t,n){return As(r,e,5,_t(r,e+1,n),n)}function xm(r,e,t,n){let i=kt(r,e+1,n);if(typeof i=="bigint")throw new Error(`${K} 64-bit integer string lengths not supported`);return As(r,e,9,i,n)}var bm=wo;function xo(r,e,t,n){return new T(w.array,n,t)}function Em(r,e,t,n){return xo(r,e,1,t)}function vm(r,e,t,n){return xo(r,e,2,It(r,e+1,n))}function Bm(r,e,t,n){return xo(r,e,3,St(r,e+1,n))}function Am(r,e,t,n){return xo(r,e,5,_t(r,e+1,n))}function Im(r,e,t,n){let i=kt(r,e+1,n);if(typeof i=="bigint")throw new Error(`${K} 64-bit integer array lengths not supported`);return xo(r,e,9,i)}function Sm(r,e,t,n){if(n.allowIndefinite===!1)throw new Error(`${K} indefinite length items not allowed`);return xo(r,e,1,1/0)}function Mc(r,e){We(r,w.array.majorEncoded,e.value)}Mc.compareTokens=zt.compareTokens;Mc.encodedSize=function(e){return We.encodedSize(e.value)};function bo(r,e,t,n){return new T(w.map,n,t)}function _m(r,e,t,n){return bo(r,e,1,t)}function km(r,e,t,n){return bo(r,e,2,It(r,e+1,n))}function Rm(r,e,t,n){return bo(r,e,3,St(r,e+1,n))}function Tm(r,e,t,n){return bo(r,e,5,_t(r,e+1,n))}function Cm(r,e,t,n){let i=kt(r,e+1,n);if(typeof i=="bigint")throw new Error(`${K} 64-bit integer map lengths not supported`);return bo(r,e,9,i)}function Nm(r,e,t,n){if(n.allowIndefinite===!1)throw new Error(`${K} indefinite length items not allowed`);return bo(r,e,1,1/0)}function Hc(r,e){We(r,w.map.majorEncoded,e.value)}Hc.compareTokens=zt.compareTokens;Hc.encodedSize=function(e){return We.encodedSize(e.value)};function Um(r,e,t,n){return new T(w.tag,t,1)}function Lm(r,e,t,n){return new T(w.tag,It(r,e+1,n),2)}function Dm(r,e,t,n){return new T(w.tag,St(r,e+1,n),3)}function Pm(r,e,t,n){return new T(w.tag,_t(r,e+1,n),5)}function Om(r,e,t,n){return new T(w.tag,kt(r,e+1,n),9)}function $c(r,e){We(r,w.tag.majorEncoded,e.value)}$c.compareTokens=zt.compareTokens;$c.encodedSize=function(e){return We.encodedSize(e.value)};var T6=20,C6=21,N6=22,U6=23;function Fm(r,e,t,n){if(n.allowUndefined===!1)throw new Error(`${K} undefined values are not supported`);return n.coerceUndefinedToNull===!0?new T(w.null,null,1):new T(w.undefined,void 0,1)}function Vm(r,e,t,n){if(n.allowIndefinite===!1)throw new Error(`${K} indefinite length items not allowed`);return new T(w.break,void 0,1)}function Qh(r,e,t){if(t){if(t.allowNaN===!1&&Number.isNaN(r))throw new Error(`${K} NaN values are not supported`);if(t.allowInfinity===!1&&(r===1/0||r===-1/0))throw new Error(`${K} Infinity values are not supported`)}return new T(w.float,r,e)}function Mm(r,e,t,n){return Qh(ed(r,e+1),3,n)}function Hm(r,e,t,n){return Qh(td(r,e+1),5,n)}function $m(r,e,t,n){return Qh(jm(r,e+1),9,n)}function zc(r,e,t){let n=e.value;if(n===!1)r.push([w.float.majorEncoded|T6]);else if(n===!0)r.push([w.float.majorEncoded|C6]);else if(n===null)r.push([w.float.majorEncoded|N6]);else if(n===void 0)r.push([w.float.majorEncoded|U6]);else{let i,o=!1;(!t||t.float64!==!0)&&(Km(n),i=ed(rr,1),n===i||Number.isNaN(n)?(rr[0]=249,r.push(rr.slice(0,3)),o=!0):(qm(n),i=td(rr,1),n===i&&(rr[0]=250,r.push(rr.slice(0,5)),o=!0))),o||(L6(n),i=jm(rr,1),rr[0]=251,r.push(rr.slice(0,9)))}}zc.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){Km(n);let i=ed(rr,1);if(n===i||Number.isNaN(n))return 3;if(qm(n),i=td(rr,1),n===i)return 5}return 9};var zm=new ArrayBuffer(9),Kt=new DataView(zm,1),rr=new Uint8Array(zm,0);function Km(r){if(r===1/0)Kt.setUint16(0,31744,!1);else if(r===-1/0)Kt.setUint16(0,64512,!1);else if(Number.isNaN(r))Kt.setUint16(0,32256,!1);else{Kt.setFloat32(0,r);let e=Kt.getUint32(0),t=(e&2139095040)>>23,n=e&8388607;if(t===255)Kt.setUint16(0,31744,!1);else if(t===0)Kt.setUint16(0,(r&2147483648)>>16|n>>13,!1);else{let i=t-127;i<-24?Kt.setUint16(0,0):i<-14?Kt.setUint16(0,(e&2147483648)>>16|1<<24+i,!1):Kt.setUint16(0,(e&2147483648)>>16|i+15<<10|n>>13,!1)}}}function ed(r,e){if(r.length-e<2)throw new Error(`${K} not enough data for float16`);let t=(r[e]<<8)+r[e+1];if(t===31744)return 1/0;if(t===64512)return-1/0;if(t===32256)return NaN;let n=t>>10&31,i=t&1023,o;return n===0?o=i*2**-24:n!==31?o=(i+1024)*2**(n-25):o=i===0?1/0:NaN,t&32768?-o:o}function qm(r){Kt.setFloat32(0,r,!1)}function td(r,e){if(r.length-e<4)throw new Error(`${K} not enough data for float32`);let t=(r.byteOffset||0)+e;return new DataView(r.buffer,t,4).getFloat32(0,!1)}function L6(r){Kt.setFloat64(0,r,!1)}function jm(r,e){if(r.length-e<8)throw new Error(`${K} not enough data for float64`);let t=(r.byteOffset||0)+e;return new DataView(r.buffer,t,8).getFloat64(0,!1)}zc.compareTokens=zt.compareTokens;function he(r,e,t){throw new Error(`${K} encountered invalid minor (${t}) for major ${r[e]>>>5}`)}function Kc(r){return()=>{throw new Error(`${K} ${r}`)}}var O=[];for(let r=0;r<=23;r++)O[r]=he;O[24]=tm;O[25]=rm;O[26]=nm;O[27]=im;O[28]=he;O[29]=he;O[30]=he;O[31]=he;for(let r=32;r<=55;r++)O[r]=he;O[56]=om;O[57]=sm;O[58]=am;O[59]=lm;O[60]=he;O[61]=he;O[62]=he;O[63]=he;for(let r=64;r<=87;r++)O[r]=um;O[88]=hm;O[89]=dm;O[90]=fm;O[91]=pm;O[92]=he;O[93]=he;O[94]=he;O[95]=Kc("indefinite length bytes/strings are not supported");for(let r=96;r<=119;r++)O[r]=mm;O[120]=ym;O[121]=gm;O[122]=wm;O[123]=xm;O[124]=he;O[125]=he;O[126]=he;O[127]=Kc("indefinite length bytes/strings are not supported");for(let r=128;r<=151;r++)O[r]=Em;O[152]=vm;O[153]=Bm;O[154]=Am;O[155]=Im;O[156]=he;O[157]=he;O[158]=he;O[159]=Sm;for(let r=160;r<=183;r++)O[r]=_m;O[184]=km;O[185]=Rm;O[186]=Tm;O[187]=Cm;O[188]=he;O[189]=he;O[190]=he;O[191]=Nm;for(let r=192;r<=215;r++)O[r]=Um;O[216]=Lm;O[217]=Dm;O[218]=Pm;O[219]=Om;O[220]=he;O[221]=he;O[222]=he;O[223]=he;for(let r=224;r<=243;r++)O[r]=Kc("simple values are not supported");O[244]=he;O[245]=he;O[246]=he;O[247]=Fm;O[248]=Kc("simple values are not supported");O[249]=Mm;O[250]=Hm;O[251]=$m;O[252]=he;O[253]=he;O[254]=he;O[255]=Vm;var nr=[];for(let r=0;r<24;r++)nr[r]=new T(w.uint,r,1);for(let r=-1;r>=-24;r--)nr[31-r]=new T(w.negint,r,1);nr[64]=new T(w.bytes,new Uint8Array(0),1);nr[96]=new T(w.string,"",1);nr[128]=new T(w.array,0,1);nr[160]=new T(w.map,0,1);nr[244]=new T(w.false,!1,1);nr[245]=new T(w.true,!0,1);nr[246]=new T(w.null,null,1);function Gm(r){switch(r.type){case w.false:return Er([244]);case w.true:return Er([245]);case w.null:return Er([246]);case w.bytes:return r.value.length?void 0:Er([64]);case w.string:return r.value===""?Er([96]):void 0;case w.array:return r.value===0?Er([128]):void 0;case w.map:return r.value===0?Er([160]):void 0;case w.uint:return r.value<24?Er([Number(r.value)]):void 0;case w.negint:if(r.value>=-24)return Er([31-Number(r.value)])}}var P6={float64:!1,mapSorter:V6,quickEncodeToken:Gm};function O6(){let r=[];return r[w.uint.major]=zt,r[w.negint.major]=Fc,r[w.bytes.major]=wo,r[w.string.major]=bm,r[w.array.major]=Mc,r[w.map.major]=Hc,r[w.tag.major]=$c,r[w.float.major]=zc,r}var Wm=O6(),rd=new Es,jc=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(`${rn} object contains circular references`);return new r(t,e)}},Hn={null:new T(w.null,null),undefined:new T(w.undefined,void 0),true:new T(w.true,!0),false:new T(w.false,!1),emptyArray:new T(w.array,0),emptyMap:new T(w.map,0)},$n={number(r,e,t,n){return!Number.isInteger(r)||!Number.isSafeInteger(r)?new T(w.float,r):r>=0?new T(w.uint,r):new T(w.negint,r)},bigint(r,e,t,n){return r>=BigInt(0)?new T(w.uint,r):new T(w.negint,r)},Uint8Array(r,e,t,n){return new T(w.bytes,r)},string(r,e,t,n){return new T(w.string,r)},boolean(r,e,t,n){return r?Hn.true:Hn.false},null(r,e,t,n){return Hn.null},undefined(r,e,t,n){return Hn.undefined},ArrayBuffer(r,e,t,n){return new T(w.bytes,new Uint8Array(r))},DataView(r,e,t,n){return new T(w.bytes,new Uint8Array(r.buffer,r.byteOffset,r.byteLength))},Array(r,e,t,n){if(!r.length)return t.addBreakTokens===!0?[Hn.emptyArray,new T(w.break)]:Hn.emptyArray;n=jc.createCheck(n,r);let i=[],o=0;for(let s of r)i[o++]=qc(s,t,n);return t.addBreakTokens?[new T(w.array,r.length),i,new T(w.break)]:[new T(w.array,r.length),i]},Object(r,e,t,n){let i=e!=="Object",o=i?r.keys():Object.keys(r),s=i?r.size:o.length;if(!s)return t.addBreakTokens===!0?[Hn.emptyMap,new T(w.break)]:Hn.emptyMap;n=jc.createCheck(n,r);let a=[],c=0;for(let u of o)a[c++]=[qc(u,t,n),qc(i?r.get(u):r[u],t,n)];return F6(a,t),t.addBreakTokens?[new T(w.map,s),a,new T(w.break)]:[new T(w.map,s),a]}};$n.Map=$n.Object;$n.Buffer=$n.Uint8Array;for(let r of"Uint8Clamped Uint16 Uint32 Int8 Int16 Int32 BigUint64 BigInt64 Float32 Float64".split(" "))$n[`${r}Array`]=$n.DataView;function qc(r,e={},t){let n=G1(r),i=e&&e.typeEncoders&&e.typeEncoders[n]||$n[n];if(typeof i=="function"){let s=i(r,n,e,t);if(s!=null)return s}let o=$n[n];if(!o)throw new Error(`${rn} unsupported type: ${n}`);return o(r,n,e,t)}function F6(r,e){e.mapSorter&&r.sort(e.mapSorter)}function V6(r,e){let t=Array.isArray(r[0])?r[0][0]:r[0],n=Array.isArray(e[0])?e[0][0]:e[0];if(t.type!==n.type)return t.type.compare(n.type);let i=t.type.major,o=Wm[i].compareTokens(t,n);return o===0&&console.warn("WARNING: complex key types used, CBOR key sorting guarantees are gone"),o}function Ym(r,e,t,n){if(Array.isArray(e))for(let i of e)Ym(r,i,t,n);else t[e.type.major](r,e,n)}function nd(r,e,t){let n=qc(r,t);if(!Array.isArray(n)&&t.quickEncodeToken){let i=t.quickEncodeToken(n);if(i)return i;let o=e[n.type.major];if(o.encodedSize){let s=o.encodedSize(n,t),a=new Es(s);if(o(a,n,t),a.chunks.length!==1)throw new Error(`Unexpected error: pre-calculated length for ${n} was wrong`);return bs(a.chunks[0])}}return rd.reset(),Ym(rd,n,e,t),rd.toBytes(!0)}function zn(r,e){return e=Object.assign({},P6,e),nd(r,Wm,e)}var M6={strict:!1,allowIndefinite:!0,allowUndefined:!0,allowBigInt:!0},id=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=nr[e];if(t===void 0){let n=O[e];if(!n)throw new Error(`${K} no decoder for major type ${e>>>5} (byte 0x${e.toString(16).padStart(2,"0")})`);let i=e&31;t=n(this.data,this._pos,i,this.options)}return this._pos+=t.encodedLength,t}},Is=Symbol.for("DONE"),Gc=Symbol.for("BREAK");function H6(r,e,t){let n=[];for(let i=0;i<r.value;i++){let o=Ss(e,t);if(o===Gc){if(r.value===1/0)break;throw new Error(`${K} got unexpected break to lengthed array`)}if(o===Is)throw new Error(`${K} found array but not enough entries (got ${i}, expected ${r.value})`);n[i]=o}return n}function $6(r,e,t){let n=t.useMaps===!0,i=n?void 0:{},o=n?new Map:void 0;for(let s=0;s<r.value;s++){let a=Ss(e,t);if(a===Gc){if(r.value===1/0)break;throw new Error(`${K} got unexpected break to lengthed map`)}if(a===Is)throw new Error(`${K} found map but not enough entries (got ${s} [no key], expected ${r.value})`);if(n!==!0&&typeof a!="string")throw new Error(`${K} non-string keys not supported (got ${typeof a})`);if(t.rejectDuplicateMapKeys===!0&&(n&&o.has(a)||!n&&a in i))throw new Error(`${K} found repeat map key "${a}"`);let c=Ss(e,t);if(c===Is)throw new Error(`${K} found map but not enough entries (got ${s} [no value], expected ${r.value})`);n?o.set(a,c):i[a]=c}return n?o:i}function Ss(r,e){if(r.done())return Is;let t=r.next();if(t.type===w.break)return Gc;if(t.type.terminal)return t.value;if(t.type===w.array)return H6(t,r,e);if(t.type===w.map)return $6(t,r,e);if(t.type===w.tag){if(e.tags&&typeof e.tags[t.value]=="function"){let n=Ss(r,e);return e.tags[t.value](n)}throw new Error(`${K} tag not supported (${t.value})`)}throw new Error("unsupported")}function od(r,e){if(!(r instanceof Uint8Array))throw new Error(`${K} data to decode must be a Uint8Array`);e=Object.assign({},M6,e);let t=e.tokenizer||new id(r,e),n=Ss(t,e);if(n===Is)throw new Error(`${K} did not find any content to decode`);if(n===Gc)throw new Error(`${K} got unexpected break`);return[n,r.subarray(t.pos())]}function Rt(r,e){let[t,n]=od(r,e);if(n.length>0)throw new Error(`${K} too many terminals, data makes no sense`);return t}var pt=re(Re(),1);var Xm=se("ipns:utils"),Zm=Y("/ipns/"),z6=114,Jm=async(r,e)=>{if(e==null||r==null){let n=new Error("one or more of the provided parameters are not defined");throw Xm.error(n),(0,pt.default)(n,Yh)}let t;if(e.pubKey!=null){try{t=Gh(e.pubKey)}catch(i){throw Xm.error(i),i}if(!(await $0(e.pubKey)).equals(r))throw(0,pt.default)(new Error("Embedded public key did not match PeerID"),K1)}else r.publicKey!=null&&(t=Gh(r.publicKey));if(t!=null)return t;throw(0,pt.default)(new Error("no public key is available"),Yh)},Qm=(r,e,t)=>{let n=Y(e);return Ee([r,t,n])},Yc=r=>{let e=Y("ipns-signature:");return Ee([e,r])},on=r=>"signatureV1"in r?Ge.encode({value:Y(r.value),signatureV1:r.signatureV1,validityType:r.validityType,validity:Y(r.validity),sequence:r.sequence,ttl:r.ttl,pubKey:r.pubKey,signatureV2:r.signatureV2,data:r.data}):Ge.encode({pubKey:r.pubKey,signatureV2:r.signatureV2,data:r.data});function at(r){let e=Ge.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,pt.default)(new Error("missing data or signatureV2"),tn);let t=ty(e.data),n=sd(t.Value),i=Q(t.Validity);if(e.value!=null&&e.signatureV1!=null)return K6(e),{value:n,validityType:Ge.ValidityType.EOL,validity:i,sequence:t.Sequence,ttl:t.TTL,pubKey:e.pubKey,signatureV1:e.signatureV1,signatureV2:e.signatureV2,data:e.data};if(e.signatureV2!=null)return{value:n,validityType:Ge.ValidityType.EOL,validity:i,sequence:t.Sequence,ttl:t.TTL,pubKey:e.pubKey,signatureV2:e.signatureV2,data:e.data};throw new Error("invalid record: does not include signatureV1 or signatureV2")}var Eo=r=>Ee([Zm,r.toBytes()]),vo=r=>ts(r.slice(Zm.length)),ey=(r,e,t,n,i)=>{let o;if(e===Ge.ValidityType.EOL)o=0;else throw(0,pt.default)(new Error("Unknown validity type"),xs);return zn({Value:r,Validity:t,ValidityType:o,Sequence:n,TTL:i})},ty=r=>{let e=Rt(r);if(e.ValidityType===0)e.ValidityType=Ge.ValidityType.EOL;else throw(0,pt.default)(new Error("Unknown validity type"),xs);return Number.isInteger(e.Sequence)&&(e.Sequence=BigInt(e.Sequence)),Number.isInteger(e.TTL)&&(e.TTL=BigInt(e.TTL)),e},sd=r=>{if(r!=null){if(l0(r))return`/ipns/${r.toCID().toString(_n)}`;if(r instanceof Uint8Array){let n=Q(r);n.startsWith("/")&&(r=n)}let e=r.toString().trim();if(e.startsWith("/")&&e.length>1)return e;let t=V.asCID(r);if(t!=null)return t.code===z6?`/ipns/${t.toString(_n)}`:`/ipfs/${t.toV1().toString()}`;try{return r instanceof Uint8Array?`/ipfs/${V.decode(r).toV1().toString()}`:`/ipfs/${V.parse(e).toV1().toString()}`}catch{}}throw(0,pt.default)(new Error("Value must be a valid content path starting with /"),z1)},K6=r=>{if(r.data==null)throw(0,pt.default)(new Error("Record data is missing"),$1);let e=ty(r.data);if(!de(e.Value,r.value??new Uint8Array(0)))throw(0,pt.default)(new Error('Field "value" did not match between protobuf and CBOR'),tn);if(!de(e.Validity,r.validity??new Uint8Array(0)))throw(0,pt.default)(new Error('Field "validity" did not match between protobuf and CBOR'),tn);if(e.ValidityType!==r.validityType)throw(0,pt.default)(new Error('Field "validityType" did not match between protobuf and CBOR'),tn);if(e.Sequence!==r.sequence)throw(0,pt.default)(new Error('Field "sequence" did not match between protobuf and CBOR'),tn);if(e.TTL!==r.ttl)throw(0,pt.default)(new Error('Field "ttl" did not match between protobuf and CBOR'),tn)};var q6=se("ipns"),j6=et.code,G6="/ipns/",_T=G6.length,ny={v1Compatible:!0};async function iy(r,e,t,n,i=ny){let o=new ry.default(Date.now()+Number(n)),s=Ge.ValidityType.EOL,[a,c]=n.toString().split("."),u=BigInt(a)*BigInt(1e5)+BigInt(c??"0");return W6(r,e,t,s,o.toString(),u,i)}var W6=async(r,e,t,n,i,o,s=ny)=>{t=BigInt(t);let a=Y(i),c=sd(e),u=Y(c);if(r.privateKey==null)throw(0,ad.default)(new Error("Missing private key"),q1);let l=await F1(r.privateKey),h=ey(u,n,a,t,o),p=Yc(h),d=await l.sign(p),f;if(r.publicKey!=null){let m=bt(r.toBytes());(m.code!==j6||!de(r.publicKey,m.digest))&&(f=r.publicKey)}if(s.v1Compatible===!0){let m=await Y6(l,u,n,a),y={value:c,signatureV1:m,validity:i,validityType:n,sequence:t,ttl:o,signatureV2:d,data:h};return f!=null&&(y.pubKey=f),y}else{let m={value:c,validity:i,validityType:n,sequence:t,ttl:o,signatureV2:d,data:h};return f!=null&&(m.pubKey=f),m}};var Y6=async(r,e,t,n)=>{try{let i=Qm(e,t,n);return await r.sign(i)}catch(i){throw q6.error("record signature creation failed",i),(0,ad.default)(new Error("record signature creation failed"),H1)}};var _s=re(Re(),1),oy=re(Dc(),1);var Xc=se("ipns:validator"),X6=1024*10,Z6=async(r,e)=>{let t=at(e),n;try{let i=Yc(t.data);n=await r.verify(i,t.signatureV2)}catch{n=!1}if(!n)throw Xc.error("record signature verification failed"),(0,_s.default)(new Error("record signature verification failed"),tn);if(t.validityType===Ge.ValidityType.EOL){if(oy.default.fromString(t.validity).toDate().getTime()<Date.now())throw Xc.error("record has expired"),(0,_s.default)(new Error("record has expired"),M1)}else if(t.validityType!=null)throw Xc.error("unrecognized validity type"),(0,_s.default)(new Error("unrecognized validity type"),xs);Xc("ipns record for %s is valid",t.value)};async function Zc(r,e){if(e.byteLength>X6)throw(0,_s.default)(new Error("record too large"),j1);let t=vo(r),n=at(e),i=await Jm(t,n);await Z6(i,e)}async function*ks(r){let e=/\r?\n/,t=new TextDecoder("utf8"),n="";for await(let i of r){typeof i=="string"&&(i=new TextEncoder().encode(i)),n+=t.decode(i,{stream:!0});let o=n.split(e);n=o.pop()??"";for(let s=0;s<o.length;s++)yield JSON.parse(o[s])}n+=t.decode(),n!==""&&(yield JSON.parse(n))}var ld=re(ay(),1);var Ts=class extends Error{constructor(e){super(e),this.name="TimeoutError"}},ud=class extends Error{constructor(e){super(),this.name="AbortError",this.message=e}},cy=r=>globalThis.DOMException===void 0?new ud(r):new DOMException(r),ly=r=>{let e=r.reason===void 0?cy("This operation was aborted."):r.reason;return e instanceof Error?e:cy(e)};function Cs(r,e){let{milliseconds:t,fallback:n,message:i,customTimers:o={setTimeout,clearTimeout}}=e,s,c=new Promise((u,l)=>{if(typeof t!="number"||Math.sign(t)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${t}\``);if(e.signal){let{signal:p}=e;p.aborted&&l(ly(p)),p.addEventListener("abort",()=>{l(ly(p))})}if(t===Number.POSITIVE_INFINITY){r.then(u,l);return}let h=new Ts;s=o.setTimeout.call(void 0,()=>{if(n){try{u(n())}catch(p){l(p)}return}typeof r.cancel=="function"&&r.cancel(),i===!1?u():i instanceof Error?l(i):(h.message=i??`Promise timed out after ${t} milliseconds`,l(h))},t),(async()=>{try{u(await r)}catch(p){l(p)}})()}).finally(()=>{c.clear()});return c.clear=()=>{o.clearTimeout.call(void 0,s),s=void 0},c}function hd(r,e,t){let n=0,i=r.length;for(;i>0;){let o=Math.trunc(i/2),s=n+o;t(r[s],e)<=0?(n=++s,i-=o+1):i=o}return n}var Ns=class{#e=[];enqueue(e,t){t={priority:0,...t};let n={priority:t.priority,run:e};if(this.size&&this.#e[this.size-1].priority>=t.priority){this.#e.push(n);return}let i=hd(this.#e,n,(o,s)=>s.priority-o.priority);this.#e.splice(i,0,n)}dequeue(){return this.#e.shift()?.run}filter(e){return this.#e.filter(t=>t.priority===e.priority).map(t=>t.run)}get size(){return this.#e.length}};var mt=class extends ld.default{#e;#t;#r=0;#s;#c;#p=0;#i;#l;#n;#m;#o=0;#u;#a;#y;timeout;constructor(e){if(super(),e={carryoverConcurrencyCount:!1,intervalCap:Number.POSITIVE_INFINITY,interval:0,concurrency:Number.POSITIVE_INFINITY,autoStart:!0,queueClass:Ns,...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#x(){return this.#t||this.#r<this.#s}get#b(){return this.#o<this.#u}#E(){this.#o--,this.#h(),this.emit("next")}#v(){this.#w(),this.#g(),this.#l=void 0}get#B(){let e=Date.now();if(this.#i===void 0){let t=this.#p-e;if(t<0)this.#r=this.#e?this.#o:0;else return this.#l===void 0&&(this.#l=setTimeout(()=>{this.#v()},t)),!0}return!1}#h(){if(this.#n.size===0)return this.#i&&clearInterval(this.#i),this.#i=void 0,this.emit("empty"),this.#o===0&&this.emit("idle"),!1;if(!this.#a){let e=!this.#B;if(this.#x&&this.#b){let t=this.#n.dequeue();return t?(this.emit("active"),t(),e&&this.#g(),!0):!1}}return!1}#g(){this.#t||this.#i!==void 0||(this.#i=setInterval(()=>{this.#w()},this.#c),this.#p=Date.now()+this.#c)}#w(){this.#r===0&&this.#o===0&&this.#i&&(clearInterval(this.#i),this.#i=void 0),this.#r=this.#e?this.#o:0,this.#d()}#d(){for(;this.#h(););}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#A(e){return new Promise((t,n)=>{e.addEventListener("abort",()=>{n(e.reason)},{once:!0})})}async add(e,t={}){return t={timeout:this.timeout,throwOnTimeout:this.#y,...t},new Promise((n,i)=>{this.#n.enqueue(async()=>{this.#o++,this.#r++;try{t.signal?.throwIfAborted();let o=e({signal:t.signal});t.timeout&&(o=Cs(Promise.resolve(o),{milliseconds:t.timeout})),t.signal&&(o=Promise.race([o,this.#A(t.signal)]));let s=await o;n(s),this.emit("completed",s)}catch(o){if(o instanceof Ts&&!t.throwOnTimeout){n();return}i(o),this.emit("error",o)}finally{this.#E()}},t),this.emit("add"),this.#h()})}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.#f("empty")}async onSizeLessThan(e){this.#n.size<e||await this.#f("next",()=>this.#n.size<e)}async onIdle(){this.#o===0&&this.#n.size===0||await this.#f("idle")}async#f(e,t){return new Promise(n=>{let i=()=>{t&&!t()||(this.off(e,i),n())};this.on(e,i)})}get size(){return this.#n.size}sizeBy(e){return this.#n.filter(e).length}get pending(){return this.#o}get isPaused(){return this.#a}};function ev(r){return r[Symbol.asyncIterator]!=null}function tv(r){if(ev(r))return(async()=>{for await(let e of r)return e})();for(let e of r)return e}var vi=tv;var dd=Y("/ipns/");function uy(r){return de(r.subarray(0,dd.byteLength),dd)}var hy=r=>ts(r.slice(dd.length)),Qc=class{client;constructor(e){this.client=e}async*findProviders(e,t={}){yield*Gt(this.client.getProviders(e,t),n=>({id:n.ID,multiaddrs:n.Addrs??[]}))}async provide(){}async put(e,t,n){if(!uy(e))return;let i=hy(e),o=at(t);await this.client.putIPNS(i,o,n)}async get(e,t){if(!uy(e))throw new F("Not found","ERR_NOT_FOUND");let n=hy(e);try{let i=await this.client.getIPNS(n,t);return on(i)}catch(i){throw i.code==="ERR_BAD_RESPONSE"?new F("Not found","ERR_NOT_FOUND"):i}}},el=class{client;constructor(e){this.client=e}async findPeer(e,t={}){let n=await vi(this.client.getPeers(e,t));if(n!=null)return{id:n.ID,multiaddrs:n.Addrs??[]};throw new F("Not found","ERR_NOT_FOUND")}async*getClosestPeers(e,t={}){}};var yt=se("delegated-routing-v1-http-api-client"),dy={concurrentRequests:4,timeout:3e4},tl=class{started;httpQueue;shutDownController;clientUrl;timeout;contentRouting;peerRouting;constructor(e,t={}){this.started=!1,this.shutDownController=new AbortController,da(1/0,this.shutDownController.signal),this.httpQueue=new mt({concurrency:t.concurrentRequests??dy.concurrentRequests}),this.clientUrl=e instanceof URL?e:new URL(e),this.timeout=t.timeout??dy.timeout,this.contentRouting=new Qc(this),this.peerRouting=new el(this)}get[Wo](){return this.contentRouting}get[Yo](){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={}){yt("getProviders starts: %c",e);let n=oi([this.shutDownController.signal,t.signal,AbortSignal.timeout(this.timeout)]),i=Ue(),o=Ue();this.httpQueue.add(async()=>(i.resolve(),o.promise));try{await i.promise;let s=`${this.clientUrl}routing/v1/providers/${e.toString()}`,c=await fetch(s,{headers:{Accept:"application/x-ndjson"},signal:n});if(c.status===404)throw new F("No matching records found.","ERR_NOT_FOUND");if(c.status===422)throw new F("Request does not conform to schema or semantic constraints.","ERR_INVALID_REQUEST");if(c.body==null)throw new F("Routing response had no body","ERR_BAD_RESPONSE");if(c.headers.get("Content-Type")==="application/json"){let l=await c.json();for(let h of l.Providers){let p=this.#e(h);p!=null&&(yield p)}}else for await(let l of ks(Ra(c.body))){let h=this.#e(l);h!=null&&(yield h)}}catch(s){yt.error("getProviders errored:",s)}finally{n.clear(),o.resolve(),yt("getProviders finished: %c",e)}}async*getPeers(e,t={}){yt("getPeers starts: %c",e);let n=oi([this.shutDownController.signal,t.signal,AbortSignal.timeout(this.timeout)]),i=Ue(),o=Ue();this.httpQueue.add(async()=>(i.resolve(),o.promise));try{await i.promise;let s=`${this.clientUrl}routing/v1/peers/${e.toCID().toString()}`,c=await fetch(s,{headers:{Accept:"application/x-ndjson"},signal:n});if(c.status===404)throw new F("No matching records found.","ERR_NOT_FOUND");if(c.status===422)throw new F("Request does not conform to schema or semantic constraints.","ERR_INVALID_REQUEST");if(c.body==null)throw new F("Routing response had no body","ERR_BAD_RESPONSE");if(c.headers.get("Content-Type")==="application/json"){let l=await c.json();for(let h of l.Peers){let p=this.#e(h);p!=null&&(yield p)}}else for await(let l of ks(Ra(c.body))){let h=this.#e(l);h!=null&&(yield h)}}catch(s){yt.error("getPeers errored:",s)}finally{n.clear(),o.resolve(),yt("getPeers finished: %c",e)}}async getIPNS(e,t={}){yt("getIPNS starts: %c",e);let n=oi([this.shutDownController.signal,t.signal,AbortSignal.timeout(this.timeout)]),i=Ue(),o=Ue();this.httpQueue.add(async()=>(i.resolve(),o.promise));let s=`${this.clientUrl}routing/v1/ipns/${e.toCID().toString()}`;try{await i.promise;let c=await fetch(s,{headers:{Accept:"application/vnd.ipfs.ipns-record"},signal:n});if(yt("getIPNS GET %s %d",s,c.status),c.status===404)throw new F("No matching records found.","ERR_NOT_FOUND");if(c.status===422)throw new F("Request does not conform to schema or semantic constraints.","ERR_INVALID_REQUEST");if(c.body==null)throw new F("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 Zc(Eo(e),l),at(l)}catch(a){throw yt.error("getIPNS GET %s error:",s,a),a}finally{n.clear(),o.resolve(),yt("getIPNS finished: %c",e)}}async putIPNS(e,t,n={}){yt("putIPNS starts: %c",e);let i=oi([this.shutDownController.signal,n.signal,AbortSignal.timeout(this.timeout)]),o=Ue(),s=Ue();this.httpQueue.add(async()=>(o.resolve(),s.promise));let a=`${this.clientUrl}routing/v1/ipns/${e.toCID().toString()}`;try{await o.promise;let c=on(t),l=await fetch(a,{method:"PUT",headers:{"Content-Type":"application/vnd.ipfs.ipns-record"},body:c,signal:i});if(yt("putIPNS PUT %s %d",a,l.status),l.status!==200)throw new F("PUT ipns response had status other than 200","ERR_BAD_RESPONSE")}catch(c){throw yt.error("putIPNS PUT %s error:",a,c.stack),c}finally{i.clear(),s.resolve(),yt("putIPNS finished: %c",e)}}#e(e){let t=[],n=e.Addrs?.map(fh)??[];return e.Protocols!=null&&t.push(...e.Protocols),e.Protocol!=null&&(t.push(e.Protocol),delete e.Protocol),{...e,Schema:"peer",ID:Yt(e.ID),Addrs:n,Protocols:t}}};function fy(r,e={}){return new tl(new URL(r),e)}var py=Y("/ipns/");function my(r){return de(r.subarray(0,py.byteLength),py)}var fd=class{client;constructor(e){this.client=fy(e)}async provide(e,t){}async*findProviders(e,t){yield*Gt(this.client.getProviders(e,t),n=>({id:n.ID,multiaddrs:n.Addrs,protocols:n.Protocols}))}async put(e,t,n){if(!my(e))return;let i=vo(e),o=at(t);await this.client.putIPNS(i,o,n)}async get(e,t){if(!my(e))throw new F("Not found","ERR_NOT_FOUND");let n=vo(e);try{let i=await this.client.getIPNS(n,t);return on(i)}catch(i){throw i.code==="ERR_BAD_RESPONSE"?new F("Not found","ERR_NOT_FOUND"):i}}async findPeer(e,t){let n=await vi(this.client.getPeers(e,t));if(n!=null)return{id:n.ID,multiaddrs:n.Addrs??[]};throw new F("Not found","ERR_NOT_FOUND")}async*getClosestPeers(e,t){}};function Us(r){return new fd(new URL(r))}var pd=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 rl(r,e,t,n){let i=new pd(n?.errorMessage,n?.errorCode);return t?.aborted===!0?Promise.reject(i):new Promise((o,s)=>{let a=u=>{n?.filter?.(u)!==!1&&(r.removeEventListener(e,a),t?.removeEventListener("abort",c),o(u))},c=()=>{r.removeEventListener(e,a),t?.removeEventListener("abort",c),s(i)};r.addEventListener(e,a),t?.addEventListener("abort",c)})}var nl=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 yy(r,e,t){if(e==null)return r;if(e.aborted)return Promise.reject(new nl(t?.errorMessage,t?.errorCode));let n,i=new nl(t?.errorMessage,t?.errorCode);try{return await Promise.race([r,new Promise((o,s)=>{n=()=>{s(i)},e.addEventListener("abort",n)})])}finally{n!=null&&e.removeEventListener("abort",n)}}var il=class{deferred;signal;where;constructor(e,t){this.signal=t,this.deferred=Ue(),this.where=e,this.onAbort=this.onAbort.bind(this),this.signal?.addEventListener("abort",this.onAbort)}onAbort(){this.deferred.reject(new vn)}cleanup(){this.signal?.removeEventListener("abort",this.onAbort)}};function rv(){return`${parseInt(String(Math.random()*1e9),10).toString()}${Date.now()}`}var ol=class{id;fn;options;priority;recipients;status;timeline;controller;constructor(e,t,n=0){this.id=rv(),this.status="queued",this.fn=e,this.priority=n,this.options=t,this.recipients=[],this.timeline={created:Date.now()},this.controller=new AbortController,da(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 vn)}async join(e={}){let t=new il(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 yy(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 nv(r,e,t){let n=0,i=r.length;for(;i>0;){let o=Math.trunc(i/2),s=n+o;t(r[s],e)<=0?(n=++s,i-=o+1):i=o}return n}var Ls=class extends ha{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=nv(this.queue,e,(n,i)=>i.priority-n.priority);this.queue.splice(t,0,e)}async add(e,t){t?.signal?.throwIfAborted();let n=new ol(e,t,t?.priority),i=n.join(t).then(o=>(this.safeDispatchEvent("completed",{detail:o}),o)).catch(o=>{throw this.safeDispatchEvent("error",{detail:o}),o});return this.enqueue(n),this.safeDispatchEvent("add"),this.tryToStartAnother(),i}clear(){this.queue.splice(0,this.queue.length)}abort(){this.queue.forEach(e=>{e.abort(new vn)}),this.clear()}async onEmpty(e){this.size!==0&&await rl(this,"empty",e?.signal)}async onSizeLessThan(e,t){this.size<e||await rl(this,"next",t?.signal,{filter:()=>this.size<e})}async onIdle(e){this.pending===0&&this.size===0||await rl(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=Vt({objectMode:!0}),n=c=>{c!=null?this.abort():this.clear(),t.end(c)},i=c=>{c.detail!=null&&t.push(c.detail)},o=c=>{n(c.detail)},s=()=>{n()},a=()=>{n(new F("Queue aborted","ERR_QUEUE_ABORTED"))};this.addEventListener("completed",i),this.addEventListener("error",o),this.addEventListener("idle",s),e?.signal?.addEventListener("abort",a);try{yield*t}finally{this.removeEventListener("completed",i),this.removeEventListener("error",o),this.removeEventListener("idle",s),e?.signal?.removeEventListener("abort",a),n()}}};var by="/pin/",gy="/pinned-block/",md=_n,wy=1;function xy(r){return r.version===0&&(r=r.toV1()),new Fe(`${by}${r.toString(md)}`)}var sl=class{datastore;blockstore;dagWalkers;constructor(e,t,n){this.datastore=e,this.blockstore=t,this.dagWalkers=n}async*add(e,t={}){let n=xy(e);if(await this.datastore.has(n))throw new Error("Already pinned");let i=Math.round(t.depth??1/0);if(i<0)throw new Error("Depth must be greater than or equal to 0");let o=new Ls({concurrency:wy});for await(let a of this.#e(e,o,{...t,depth:i}))await this.#t(a,c=>c.pinnedBy.find(u=>de(u,e.bytes))!=null?!1:(c.pinCount++,c.pinnedBy.push(e.bytes),!0),t),yield a;let s={depth:i,metadata:t.metadata??{}};await this.datastore.put(n,zn(s),t)}async*#e(e,t,n){if(n.depth===-1)return;let i=this.dagWalkers[e.code];if(i==null)throw new Error(`No dag walker found for cid codec ${e.code}`);let o=await this.blockstore.get(e,n);yield e;for await(let s of i.walk(o))yield*await t.add(async()=>this.#e(s,t,{...n,depth:n.depth-1}))}async#t(e,t,n){let i=new Fe(`${gy}${md.encode(e.multihash.bytes)}`),o={pinCount:0,pinnedBy:[]};try{o=Rt(await this.datastore.get(i,n))}catch(a){if(a.code!=="ERR_NOT_FOUND")throw a}if(t(o)){if(o.pinCount===0&&await this.datastore.has(i)){await this.datastore.delete(i);return}await this.datastore.put(i,zn(o),n),n.onProgress?.(new P("helia:pin:add",e))}}async*rm(e,t={}){let n=xy(e),i=await this.datastore.get(n,t),o=Rt(i);await this.datastore.delete(n,t);let s=new Ls({concurrency:wy});for await(let a of this.#e(e,s,{...t,depth:o.depth}))await this.#t(a,c=>(c.pinCount--,c.pinnedBy=c.pinnedBy.filter(u=>de(u,e.bytes)),!0),{...t,depth:o.depth}),yield a}async*ls(e={}){for await(let{key:t,value:n}of this.datastore.query({prefix:by+(e.cid!=null?`${e.cid.toString(_n)}`:"")},e)){let i=V.parse(t.toString().substring(5),_n),o=Rt(n);yield{cid:i,...o}}}async isPinned(e,t={}){let n=new Fe(`${gy}${md.encode(e.multihash.bytes)}`);return this.datastore.has(n,t)}};function yd(r,e){let t={[Symbol.iterator]:()=>t,next:()=>{let n=r.next(),i=n.value;return n.done===!0||i==null?{done:!0,value:void 0}:{done:!1,value:e(i)}}};return t}var Bo=class r{set;constructor(e){if(this.set=new Set,e!=null)for(let t of e)this.set.add(t.toString())}get size(){return this.set.size}[Symbol.iterator](){return this.values()}add(e){this.set.add(e.toString())}clear(){this.set.clear()}delete(e){this.set.delete(e.toString())}entries(){return yd(this.set.entries(),e=>{let t=Yt(e[0]);return[t,t]})}forEach(e){this.set.forEach(t=>{let n=Yt(t);e(n,n,this)})}has(e){return this.set.has(e.toString())}values(){return yd(this.set.values(),e=>Yt(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 al=class{log;routers;constructor(e,t){this.log=e.logger.forComponent("helia:routing"),this.routers=t.routers??[]}async start(){await Bn(...this.routers)}async stop(){await An(...this.routers)}async*findProviders(e,t={}){if(this.routers.length===0)throw new F("No content routers available","ERR_NO_ROUTERS_AVAILABLE");let n=new Bo;for await(let i of Mr(...Ao(this.routers,"findProviders").map(o=>o.findProviders(e,t))))i!=null&&(n.has(i.id)||(n.add(i.id),yield i))}async provide(e,t={}){if(this.routers.length===0)throw new F("No content routers available","ERR_NO_ROUTERS_AVAILABLE");await Promise.all(Ao(this.routers,"provide").map(async n=>{await n.provide(e,t)}))}async put(e,t,n){await Promise.all(Ao(this.routers,"put").map(async i=>{await i.put(e,t,n)}))}async get(e,t){return Promise.any(Ao(this.routers,"get").map(async n=>n.get(e,t)))}async findPeer(e,t){if(this.routers.length===0)throw new F("No peer routers available","ERR_NO_ROUTERS_AVAILABLE");let n=this,i=Mr(...Ao(this.routers,"findPeer").map(o=>async function*(){try{yield await o.findPeer(e,t)}catch(s){n.log.error(s)}}()));for await(let o of i)if(o!=null)return o;throw new F("Could not find peer in routing","ERR_NOT_FOUND")}async*getClosestPeers(e,t={}){if(this.routers.length===0)throw new F("No peer routers available","ERR_NO_ROUTERS_AVAILABLE");let n=new Bo;for await(let i of Mr(...Ao(this.routers,"getClosestPeers").map(o=>o.getClosestPeers(e,t))))i!=null&&(n.has(i.id)||(n.add(i.id),yield i))}};function Ao(r,e){return r.filter(t=>t[e]!=null)}var Kn={},Io=r=>{r.addEventListener("message",e=>{Io.dispatchEvent("message",r,e)}),r.port!=null&&r.port.addEventListener("message",e=>{Io.dispatchEvent("message",r,e)})};Io.addEventListener=(r,e)=>{Kn[r]==null&&(Kn[r]=[]),Kn[r].push(e)};Io.removeEventListener=(r,e)=>{Kn[r]!=null&&(Kn[r]=Kn[r].filter(t=>t===e))};Io.dispatchEvent=function(r,e,t){Kn[r]!=null&&Kn[r].forEach(n=>n(e,t))};var gd=Io;var wd="lock:worker:request-read",xd="lock:worker:release-read",bd="lock:master:grant-read",Ed="lock:worker:request-write",vd="lock:worker:release-write",Bd="lock:master:grant-write";var Ey=(r=21)=>Math.random().toString().substring(2);var vy=(r,e,t,n,i)=>(o,s)=>{if(s.data.type!==t)return;let a={type:s.data.type,name:s.data.name,identifier:s.data.identifier};r.dispatchEvent(new MessageEvent(e,{data:{name:a.name,handler:async()=>{o.postMessage({type:i,name:a.name,identifier:a.identifier}),await new Promise(c=>{let u=l=>{if(l==null||l.data==null)return;let h={type:l.data.type,name:l.data.name,identifier:l.data.identifier};h.type===n&&h.identifier===a.identifier&&(o.removeEventListener("message",u),c())};o.addEventListener("message",u)})}}}))},By=(r,e,t,n)=>async()=>{let i=Ey();return globalThis.postMessage({type:e,identifier:i,name:r}),new Promise(o=>{let s=a=>{if(a==null||a.data==null)return;let c={type:a.data.type,identifier:a.data.identifier};c.type===t&&c.identifier===i&&(globalThis.removeEventListener("message",s),o(()=>{globalThis.postMessage({type:n,identifier:i,name:r})}))};globalThis.addEventListener("message",s)})},iv={singleProcess:!1},Ay=r=>{if(r=Object.assign({},iv,r),!!globalThis.document||r.singleProcess){let t=new EventTarget;return gd.addEventListener("message",vy(t,"requestReadLock",wd,xd,bd)),gd.addEventListener("message",vy(t,"requestWriteLock",Ed,vd,Bd)),t}return{isWorker:!0,readLock:t=>By(t,wd,bd,xd),writeLock:t=>By(t,Ed,Bd,vd)}};var Bi={},qn;async function Ad(r,e){let t,n=new Promise(i=>{t=i});return r.add(async()=>Cs((async()=>{await new Promise(i=>{t(()=>{i()})})})(),{milliseconds:e.timeout})),n}var ov=(r,e)=>{if(qn.isWorker===!0)return{readLock:qn.readLock(r,e),writeLock:qn.writeLock(r,e)};let t=new mt({concurrency:1}),n;return{async readLock(){if(n!=null)return Ad(n,e);n=new mt({concurrency:e.concurrency,autoStart:!1});let i=n,o=Ad(n,e);return t.add(async()=>{i.start(),await i.onIdle().then(()=>{n===i&&(n=null)})}),o},async writeLock(){return n=null,Ad(t,e)}}},sv={name:"lock",concurrency:1/0,timeout:846e5,singleProcess:!1};function Id(r){let e=Object.assign({},sv,r);return qn==null&&(qn=Ay(e),qn.isWorker!==!0&&(qn.addEventListener("requestReadLock",t=>{Bi[t.data.name]!=null&&Bi[t.data.name].readLock().then(async n=>t.data.handler().finally(()=>{n()}))}),qn.addEventListener("requestWriteLock",async t=>{Bi[t.data.name]!=null&&Bi[t.data.name].writeLock().then(async n=>t.data.handler().finally(()=>{n()}))}))),Bi[e.name]==null&&(Bi[e.name]=ov(e.name,e)),Bi[e.name]}var cl=class{lock;child;pins;started;constructor(e,t,n={}){this.child=e,this.pins=t,this.lock=Id({singleProcess:n.holdGcLock}),this.started=!1}isStarted(){return this.started}async start(){await Bn(this.child),this.started=!0}async stop(){await An(this.child),this.started=!1}unwrap(){return this.child}async put(e,t,n={}){let i=await this.lock.readLock();try{return await this.child.put(e,t,n)}finally{i()}}async*putMany(e,t={}){let n=await this.lock.readLock();try{yield*this.child.putMany(e,t)}finally{n()}}async get(e,t={}){let n=await this.lock.readLock();try{return await this.child.get(e,t)}finally{n()}}async*getMany(e,t={}){let n=await this.lock.readLock();try{yield*this.child.getMany(e,t)}finally{n()}}async delete(e,t={}){let n=await this.lock.writeLock();try{if(await this.pins.isPinned(e))throw new Error("CID was pinned");await this.child.delete(e,t)}finally{n()}}async*deleteMany(e,t={}){let n=await this.lock.writeLock();try{let i=this;yield*this.child.deleteMany(async function*(){for await(let o of e){if(await i.pins.isPinned(o))throw new Error("CID was pinned");yield o}}(),t)}finally{n()}}async has(e,t={}){let n=await this.lock.readLock();try{return await this.child.has(e,t)}finally{n()}}async*getAll(e={}){let t=await this.lock.readLock();try{yield*this.child.getAll(e)}finally{t()}}};var Iy=42;function av(r){if(r.asCID!==r&&r["/"]!==r.bytes)return null;let e=V.asCID(r);if(!e)return null;let t=new Uint8Array(e.bytes.byteLength+1);return t.set(e.bytes,1),[new T(w.tag,Iy),new T(w.bytes,t)]}function cv(){throw new Error("`undefined` is not supported by the IPLD Data Model and cannot be encoded")}function lv(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 Sd={float64:!0,typeEncoders:{Object:av,undefined:cv,number:lv}},kN={...Sd,typeEncoders:{...Sd.typeEncoders}};function uv(r){if(r[0]!==0)throw new Error("Invalid CID for CBOR tag 42; expected leading 0x00");return V.decode(r.subarray(1))}var ll={allowIndefinite:!1,coerceUndefinedToNull:!0,allowNaN:!1,allowInfinity:!1,allowBigInt:!0,strict:!0,useMaps:!1,rejectDuplicateMapKeys:!0,tags:[]};ll.tags[Iy]=uv;var RN={...ll,tags:ll.tags.slice()};var jn=113,Sy=r=>zn(r,Sd),ul=r=>Rt(r,ll);var _d=class extends Array{constructor(){super(),this.inRecursive=[]}prefix(e){let t=this.inRecursive[this.inRecursive.length-1];t&&(t.type===w.array&&(t.elements++,t.elements!==1&&e.push([44])),t.type===w.map&&(t.elements++,t.elements!==1&&(t.elements%2===1?e.push([44]):e.push([58]))))}[w.uint.major](e,t){this.prefix(e);let n=String(t.value),i=[];for(let o=0;o<n.length;o++)i[o]=n.charCodeAt(o);e.push(i)}[w.negint.major](e,t){this[w.uint.major](e,t)}[w.bytes.major](e,t){throw new Error(`${rn} unsupported type: Uint8Array`)}[w.string.major](e,t){this.prefix(e);let n=Oc(JSON.stringify(t.value));e.push(n.length>32?bs(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(`${rn} unsupported type: undefined`);if(this.prefix(e),t.type.name==="true"){e.push([116,114,117,101]);return}else if(t.type.name==="false"){e.push([102,97,108,115,101]);return}else if(t.type.name==="null"){e.push([110,117,108,108]);return}let n=String(t.value),i=[],o=!1;for(let s=0;s<n.length;s++)i[s]=n.charCodeAt(s),!o&&(i[s]===46||i[s]===101||i[s]===69)&&(o=!0);o||(i.push(46),i.push(48)),e.push(i)}};function hv(r,e){if(Array.isArray(r[0])||Array.isArray(e[0]))throw new Error(`${rn} 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(`${rn} non-string map keys are not supported`);if(t<n)return-1;if(t>n)return 1;throw new Error(`${rn} unexpected duplicate map keys, this is not supported`)}var dv={addBreakTokens:!0,mapSorter:hv};function kd(r,e){return e=Object.assign({},dv,e),nd(r,new _d,e)}var Gn=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(`${K} 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(`${K} unexpected token at position ${this._pos}, expected to find '${String.fromCharCode(...e)}'`)}parseNumber(){let e=this._pos,t=!1,n=!1,i=a=>{for(;!this.done();){let c=this.ch();if(a.includes(c))this._pos++;else break}};if(this.ch()===45&&(t=!0,this._pos++),this.ch()===48)if(this._pos++,this.ch()===46)this._pos++,n=!0;else return new T(w.uint,0,this._pos-e);if(i([48,49,50,51,52,53,54,55,56,57]),t&&this._pos===e+1)throw new Error(`${K} unexpected token at position ${this._pos}`);if(!this.done()&&this.ch()===46){if(n)throw new Error(`${K} unexpected token at position ${this._pos}`);n=!0,this._pos++,i([48,49,50,51,52,53,54,55,56,57])}!this.done()&&(this.ch()===101||this.ch()===69)&&(n=!0,this._pos++,!this.done()&&(this.ch()===43||this.ch()===45)&&this._pos++,i([48,49,50,51,52,53,54,55,56,57]));let o=String.fromCharCode.apply(null,this.data.subarray(e,this._pos)),s=parseFloat(o);return n?new T(w.float,s,this._pos-e):this.options.allowBigInt!==!0||Number.isSafeInteger(s)?new T(s>=0?w.uint:w.negint,s,this._pos-e):new T(s>=0?w.uint:w.negint,BigInt(o),this._pos-e)}parseString(){if(this.ch()!==34)throw new Error(`${K} unexpected character at position ${this._pos}; this shouldn't happen`);this._pos++;for(let o=this._pos,s=0;o<this.data.length&&s<65536;o++,s++){let a=this.data[o];if(a===92||a<32||a>=128)break;if(a===34){let c=String.fromCharCode.apply(null,this.data.subarray(this._pos,o));return this._pos=o+1,new T(w.string,c,s)}}let e=this._pos,t=[],n=()=>{if(this._pos+4>=this.data.length)throw new Error(`${K} unexpected end of unicode escape sequence at position ${this._pos}`);let o=0;for(let s=0;s<4;s++){let a=this.ch();if(a>=48&&a<=57)a-=48;else if(a>=97&&a<=102)a=a-97+10;else if(a>=65&&a<=70)a=a-65+10;else throw new Error(`${K} unexpected unicode escape character at position ${this._pos}`);o=o*16+a,this._pos++}return o},i=()=>{let o=this.ch(),s=null,a=o>239?4:o>223?3:o>191?2:1;if(this._pos+a>this.data.length)throw new Error(`${K} unexpected unicode sequence at position ${this._pos}`);let c,u,l,h;switch(a){case 1:o<128&&(s=o);break;case 2:c=this.data[this._pos+1],(c&192)===128&&(h=(o&31)<<6|c&63,h>127&&(s=h));break;case 3:c=this.data[this._pos+1],u=this.data[this._pos+2],(c&192)===128&&(u&192)===128&&(h=(o&15)<<12|(c&63)<<6|u&63,h>2047&&(h<55296||h>57343)&&(s=h));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&&(h=(o&15)<<18|(c&63)<<12|(u&63)<<6|l&63,h>65535&&h<1114112&&(s=h))}s===null?(s=65533,a=1):s>65535&&(s-=65536,t.push(s>>>10&1023|55296),s=56320|s&1023),t.push(s),this._pos+=a};for(;!this.done();){let o=this.ch(),s;switch(o){case 92:if(this._pos++,this.done())throw new Error(`${K} 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(`${K} unexpected string escape character at position ${this._pos}`)}break;case 34:return this._pos++,new T(w.string,Zh(t),this._pos-e);default:if(o<32)throw new Error(`${K} invalid control character at position ${this._pos}`);o<128?(t.push(o),this._pos++):i()}}throw new Error(`${K} unexpected end of string at position ${this._pos}`)}parseValue(){switch(this.ch()){case 123:return this.modeStack.push("obj-start"),this._pos++,new T(w.map,1/0,1);case 91:return this.modeStack.push("array-start"),this._pos++,new T(w.array,1/0,1);case 34:return this.parseString();case 110:return this.expect([110,117,108,108]),new T(w.null,null,4);case 102:return this.expect([102,97,108,115,101]),new T(w.false,!1,5);case 116:return this.expect([116,114,117,101]),new T(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(`${K} 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 T(w.break,void 0,1);if(this.ch()!==44)throw new Error(`${K} 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 T(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 T(w.break,void 0,1);if(this.ch()!==44)throw new Error(`${K} 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 T(w.break,void 0,1);let e=this.parseString();if(this.skipWhitespace(),this.ch()!==58)throw new Error(`${K} 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(`${K} unexpected parse state at position ${this._pos}; this shouldn't happen`)}}};function Ds(r,e){return e=Object.assign({tokenizer:new Gn(r,e)},e),Rt(r,e)}function fv(r){if(r.asCID!==r&&r["/"]!==r.bytes)return null;let e=V.asCID(r);if(!e)return null;let t=e.toString();return[new T(w.map,1/0,1),new T(w.string,"/",1),new T(w.string,t,t.length),new T(w.break,void 0,1)]}function dl(r){let e=pr.encode(r).slice(1);return[new T(w.map,1/0,1),new T(w.string,"/",1),new T(w.map,1/0,1),new T(w.string,"bytes",5),new T(w.string,e,e.length),new T(w.break,void 0,1),new T(w.break,void 0,1)]}function ir(r){return dl(new Uint8Array(r.buffer,r.byteOffset,r.byteLength))}function pv(r){return dl(new Uint8Array(r))}function mv(){throw new Error("`undefined` is not supported by the IPLD Data Model and cannot be encoded")}function yv(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 gv={typeEncoders:{Object:fv,Buffer:dl,Uint8Array:dl,Int8Array:ir,Uint16Array:ir,Int16Array:ir,Uint32Array:ir,Int32Array:ir,Float32Array:ir,Float64Array:ir,Uint8ClampedArray:ir,BigInt64Array:ir,BigUint64Array:ir,DataView:ir,ArrayBuffer:pv,undefined:mv,number:yv}},Rd=class extends Gn{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 T(w.tag,42,0)}if(n.type===w.map){let i=this._next();if(i.type===w.string&&i.value==="bytes"){let o=this._next();if(o.type===w.string){for(let a=0;a<2;a++)if(this._next().type!==w.break)throw new Error("Invalid encoded Bytes form");let s=pr.decode(`m${o.value}`);return new T(w.bytes,s,o.value.length)}this.tokenBuffer.push(o)}this.tokenBuffer.push(i)}this.tokenBuffer.push(n)}this.tokenBuffer.push(t)}return e}},Td={allowIndefinite:!1,allowUndefined:!1,allowNaN:!1,allowInfinity:!1,allowBigInt:!0,strict:!0,useMaps:!1,rejectDuplicateMapKeys:!0,tags:[]};Td.tags[42]=V.parse;var Wn=297,ky=r=>kd(r,gv),fl=r=>{let e=Object.assign(Td,{tokenizer:new Rd(r,Td)});return Ds(r,e)};var jN=new TextDecoder;var GN=new TextEncoder;var De={};Ae(De,{code:()=>Te,createLink:()=>Fy,createNode:()=>Oy,decode:()=>ve,encode:()=>le,name:()=>kv,prepare:()=>_e,validate:()=>Ud});var wv=new TextDecoder;function Cd(r,e){let t=0;for(let n=0;;n+=7){if(n>=64)throw new Error("protobuf: varint overflow");if(e>=r.length)throw new Error("protobuf: unexpected end of data");let i=r[e++];if(t+=n<28?(i&127)<<n:(i&127)*2**n,i<128)break}return[t,e]}function ml(r,e){let t;[t,e]=Cd(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 Ry(r,e){let t;return[t,e]=Cd(r,e),[t&7,t>>3,e]}function xv(r){let e={},t=r.length,n=0;for(;n<t;){let i,o;if([i,o,n]=Ry(r,n),o===1){if(e.Hash)throw new Error("protobuf: (PBLink) duplicate Hash section");if(i!==2)throw new Error(`protobuf: (PBLink) wrong wireType (${i}) for Hash`);if(e.Name!==void 0)throw new Error("protobuf: (PBLink) invalid order, found Name before Hash");if(e.Tsize!==void 0)throw new Error("protobuf: (PBLink) invalid order, found Tsize before Hash");[e.Hash,n]=ml(r,n)}else if(o===2){if(e.Name!==void 0)throw new Error("protobuf: (PBLink) duplicate Name section");if(i!==2)throw new Error(`protobuf: (PBLink) wrong wireType (${i}) for Name`);if(e.Tsize!==void 0)throw new Error("protobuf: (PBLink) invalid order, found Tsize before Name");let s;[s,n]=ml(r,n),e.Name=wv.decode(s)}else if(o===3){if(e.Tsize!==void 0)throw new Error("protobuf: (PBLink) duplicate Tsize section");if(i!==0)throw new Error(`protobuf: (PBLink) wrong wireType (${i}) for Tsize`);[e.Tsize,n]=Cd(r,n)}else throw new Error(`protobuf: (PBLink) invalid fieldNumber, expected 1, 2 or 3, got ${o}`)}if(n>t)throw new Error("protobuf: (PBLink) unexpected end of data");return e}function Ty(r){let e=r.length,t=0,n,i=!1,o;for(;t<e;){let a,c;if([a,c,t]=Ry(r,t),a!==2)throw new Error(`protobuf: (PBNode) invalid wireType, expected 2, got ${a}`);if(c===1){if(o)throw new Error("protobuf: (PBNode) duplicate Data section");[o,t]=ml(r,t),n&&(i=!0)}else if(c===2){if(i)throw new Error("protobuf: (PBNode) duplicate Links section");n||(n=[]);let u;[u,t]=ml(r,t),n.push(xv(u))}else throw new Error(`protobuf: (PBNode) invalid fieldNumber, expected 1 or 2, got ${c}`)}if(t>e)throw new Error("protobuf: (PBNode) unexpected end of data");let s={};return o&&(s.Data=o),s.Links=n||[],s}var Ny=new TextEncoder,Cy=2**32,bv=2**31;function Ev(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=Ps(e,t,r.Tsize)-1,e[t]=24}if(typeof r.Name=="string"){let n=Ny.encode(r.Name);t-=n.length,e.set(n,t),t=Ps(e,t,n.length)-1,e[t]=18}return r.Hash&&(t-=r.Hash.length,e.set(r.Hash,t),t=Ps(e,t,r.Hash.length)-1,e[t]=10),e.length-t}function Uy(r){let e=Bv(r),t=new Uint8Array(e),n=e;if(r.Data&&(n-=r.Data.length,t.set(r.Data,n),n=Ps(t,n,r.Data.length)-1,t[n]=10),r.Links)for(let i=r.Links.length-1;i>=0;i--){let o=Ev(r.Links[i],t.subarray(0,n));n-=o,n=Ps(t,n,o)-1,t[n]=18}return t}function vv(r){let e=0;if(r.Hash){let t=r.Hash.length;e+=1+t+So(t)}if(typeof r.Name=="string"){let t=Ny.encode(r.Name).length;e+=1+t+So(t)}return typeof r.Tsize=="number"&&(e+=1+So(r.Tsize)),e}function Bv(r){let e=0;if(r.Data){let t=r.Data.length;e+=1+t+So(t)}if(r.Links)for(let t of r.Links){let n=vv(t);e+=1+n+So(n)}return e}function Ps(r,e,t){e-=So(t);let n=e;for(;t>=bv;)r[e++]=t&127|128,t/=128;for(;t>=128;)r[e++]=t&127|128,t>>>=7;return r[e]=t,n}function So(r){return r%2===0&&r++,Math.floor((Av(r)+6)/7)}function Av(r){let e=0;return r>=Cy&&(r=Math.floor(r/Cy),e=32),r>=65536&&(r>>>=16,e+=16),r>=256&&(r>>>=8,e+=8),e+Iv[r]}var Iv=[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 Sv=["Data","Links"],_v=["Hash","Name","Tsize"],Nd=new TextEncoder;function Dy(r,e){if(r===e)return 0;let t=r.Name?Nd.encode(r.Name):[],n=e.Name?Nd.encode(e.Name):[],i=t.length,o=n.length;for(let s=0,a=Math.min(i,o);s<a;++s)if(t[s]!==n[s]){i=t[s],o=n[s];break}return i<o?-1:o<i?1:0}function Ly(r,e){return!Object.keys(r).some(t=>!e.includes(t))}function Py(r){if(typeof r.asCID=="object"){let t=V.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=V.asCID(r.Hash);try{t||(typeof r.Hash=="string"?t=V.parse(r.Hash):r.Hash instanceof Uint8Array&&(t=V.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=Nd.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(Py),e.Links.sort(Dy);else throw new TypeError("Invalid DAG-PB form");else e.Links=[];return e}function Ud(r){if(!r||typeof r!="object"||Array.isArray(r)||r instanceof Uint8Array||r["/"]&&r["/"]===r.bytes)throw new TypeError("Invalid DAG-PB form");if(!Ly(r,Sv))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(!Ly(t,_v))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&&Dy(t,r.Links[e-1])===-1)throw new TypeError("Invalid DAG-PB form (links must be sorted by Name bytes)")}}function Oy(r,e=[]){return _e({Data:r,Links:e})}function Fy(r,e,t){return Py({Hash:t,Name:r,Tsize:e})}var kv="dag-pb",Te=112;function le(r){Ud(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),Uy(e)}function ve(r){let e=Ty(r),t={};return e.Data&&(t.Data=e.Data),e.Links&&(t.Links=e.Links.map(n=>{let i={};try{i.Hash=V.decode(n.Hash)}catch{}if(!i.Hash)throw new Error("Invalid Hash field found in link, expected CID");return n.Name!==void 0&&(i.Name=n.Name),n.Tsize!==void 0&&(i.Tsize=n.Tsize),i})),t}var Rv={codec:Te,*walk(r){yield*ve(r).Links.map(t=>t.Hash)}},Tv={codec:Ne,*walk(){}},Vy=42,Cv={codec:jn,*walk(r){let e=[],t=[];t[Vy]=n=>{if(n[0]!==0)throw new Error("Invalid CID for CBOR tag 42; expected leading 0x00");let i=V.decode(n.subarray(1));return e.push(i),i},Rt(r,{tags:t}),yield*e}},Ld=class extends Gn{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 T(w.tag,42,0)}if(n.type===w.map){let i=this._next();if(i.type===w.string&&i.value==="bytes"){let o=this._next();if(o.type===w.string){for(let a=0;a<2;a++)if(this._next().type!==w.break)throw new Error("Invalid encoded Bytes form");let s=pr.decode(`m${o.value}`);return new T(w.bytes,s,o.value.length)}this.tokenBuffer.push(o)}this.tokenBuffer.push(i)}this.tokenBuffer.push(n)}this.tokenBuffer.push(t)}return e}},Nv={codec:Wn,*walk(r){let e=[],t=[];t[Vy]=n=>{let i=V.parse(n);return e.push(i),i},Ds(r,{tags:t,tokenizer:new Ld(r,{tags:t,allowIndefinite:!0,allowUndefined:!0,allowNaN:!0,allowInfinity:!0,allowBigInt:!0,strict:!1,rejectDuplicateMapKeys:!1})}),yield*e}},Uv={codec:kn,*walk(){}};function My(r=[]){let e={};return[Rv,Tv,Cv,Nv,Uv,...r].forEach(t=>{e[t.codec]=t}),e}var Dd=new Fe("/version"),Hy=1;async function $y(r){if(!await r.has(Dd)){await r.put(Dd,Y(`${Hy}`));return}let e=await r.get(Dd),t=Q(e);if(parseInt(t,10)!==Hy)throw new Error("Unknown datastore version, a datastore migration may be required")}function zy(r=[]){let e={};return[ne,xu,et,...r].forEach(t=>{e[t.code]=t}),e}var vr=class{has(e,t){return Promise.reject(new Error(".has is not implemented"))}put(e,t,n){return Promise.reject(new Error(".put is not implemented"))}async*putMany(e,t){for await(let{cid:n,block:i}of e)await this.put(n,i,t),yield n}get(e,t){return Promise.reject(new Error(".get is not implemented"))}async*getMany(e,t){for await(let n of e)yield{cid:n,block:await this.get(n,t)}}delete(e,t){return Promise.reject(new Error(".delete is not implemented"))}async*deleteMany(e,t){for await(let n of e)await this.delete(n,t),yield n}async*getAll(e){throw new Error(".getAll is not implemented")}};var Ai={};Ae(Ai,{abortedError:()=>Fv,closeFailedError:()=>Dv,deleteFailedError:()=>Od,getFailedError:()=>Pv,hasFailedError:()=>Ov,notFoundError:()=>Yn,openFailedError:()=>Lv,putFailedError:()=>Pd});var sn=re(Re(),1);function Lv(r){return r=r??new Error("Open failed"),(0,sn.default)(r,"ERR_OPEN_FAILED")}function Dv(r){return r=r??new Error("Close failed"),(0,sn.default)(r,"ERR_CLOSE_FAILED")}function Pd(r){return r=r??new Error("Put failed"),(0,sn.default)(r,"ERR_PUT_FAILED")}function Pv(r){return r=r??new Error("Get failed"),(0,sn.default)(r,"ERR_GET_FAILED")}function Od(r){return r=r??new Error("Delete failed"),(0,sn.default)(r,"ERR_DELETE_FAILED")}function Ov(r){return r=r??new Error("Has failed"),(0,sn.default)(r,"ERR_HAS_FAILED")}function Yn(r){return r=r??new Error("Not Found"),(0,sn.default)(r,"ERR_NOT_FOUND")}function Fv(r){return r=r??new Error("Aborted"),(0,sn.default)(r,"ERR_ABORTED")}var Ky=0,yl=class extends vr{put(e){return e}get(e){if(e.code===Ky)return e.multihash.digest;throw Yn()}has(e){return e.code===Ky}delete(){}*getAll(){}};function Vv(r){return r[Symbol.asyncIterator]!=null}function Mv(r,e){if(Vv(r))return async function*(){for await(let a of r)await e(a)&&(yield a)}();let t=Pi(r),{value:n,done:i}=t.next();if(i===!0)return function*(){}();let o=e(n);if(typeof o.then=="function")return async function*(){await o&&(yield n);for await(let a of t)await e(a)&&(yield a)}();let s=e;return function*(){o===!0&&(yield n);for(let a of t)s(a)&&(yield a)}()}var gt=Mv;var Hv=se("blockstore:core:tiered"),Os=class extends vr{stores;constructor(e){super(),this.stores=e.slice()}async put(e,t,n){try{return await Promise.all(this.stores.map(async i=>{await i.put(e,t,n)})),e}catch(i){throw Pd(i)}}async get(e,t){for(let n of this.stores)try{let i=await n.get(e,t);if(i!=null)return i}catch(i){Hv.error(i)}throw Yn()}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 Od(n)}}async*putMany(e,t={}){let n,i=this.stores.map(o=>{let s=Vt({objectMode:!0});return Vr(o.putMany(s,t)).catch(a=>{n=a}),s});try{for await(let o of e){if(n!=null)throw n;i.forEach(s=>s.push(o)),yield o.cid}}finally{i.forEach(o=>o.end())}}async*deleteMany(e,t={}){let n,i=this.stores.map(o=>{let s=Vt({objectMode:!0});return Vr(o.deleteMany(s,t)).catch(a=>{n=a}),s});try{for await(let o of e){if(n!=null)throw n;i.forEach(s=>s.push(o)),yield o}}finally{i.forEach(o=>o.end())}}async*getAll(e){let t=new Set;yield*gt(Mr(...this.stores.map(n=>n.getAll(e))),n=>{let i=n.cid.toString();return t.has(i)?!1:(t.add(i),!0)})}};function $v(r){return typeof r.retrieve=="function"}function zv(r){return typeof r.announce=="function"}var gl=class{child;blockRetrievers;blockAnnouncers;hashers;started;log;constructor(e){this.log=e.logger.forComponent("helia:networked-storage"),this.child=new Os([new yl,e.blockstore]),this.blockRetrievers=(e.blockBrokers??[]).filter($v),this.blockAnnouncers=(e.blockBrokers??[]).filter(zv),this.hashers=e.hashers??{},this.started=!1}isStarted(){return this.started}async start(){await Bn(this.child,...new Set([...this.blockRetrievers,...this.blockAnnouncers])),this.started=!0}async stop(){await An(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 P("blocks:put:duplicate",e)),e):(n.onProgress?.(new P("blocks:put:providers:notify",e)),this.blockAnnouncers.forEach(i=>{i.announce(e,t,n)}),n.onProgress?.(new P("blocks:put:blockstore:put",e)),this.child.put(e,t,n))}async*putMany(e,t={}){let n=gt(e,async({cid:o})=>{let s=await this.child.has(o);return s&&t.onProgress?.(new P("blocks:put-many:duplicate",o)),!s}),i=iu(n,({cid:o,block:s})=>{t.onProgress?.(new P("blocks:put-many:providers:notify",o)),this.blockAnnouncers.forEach(a=>{a.announce(o,s,t)})});t.onProgress?.(new P("blocks:put-many:blockstore:put-many")),yield*this.child.putMany(i,t)}async get(e,t={}){if(t.offline!==!0&&!await this.child.has(e)){t.onProgress?.(new P("blocks:get:providers:get",e));let n=await qy(e,this.blockRetrievers,this.hashers[e.multihash.code],{...t,log:this.log});return t.onProgress?.(new P("blocks:get:blockstore:put",e)),await this.child.put(e,n,t),t.onProgress?.(new P("blocks:get:providers:notify",e)),this.blockAnnouncers.forEach(i=>{i.announce(e,n,t)}),n}return t.onProgress?.(new P("blocks:get:blockstore:get",e)),this.child.get(e,t)}async*getMany(e,t={}){t.onProgress?.(new P("blocks:get-many:blockstore:get-many")),yield*this.child.getMany(iu(e,async n=>{if(t.offline!==!0&&!await this.child.has(n)){t.onProgress?.(new P("blocks:get-many:providers:get",n));let i=await qy(n,this.blockRetrievers,this.hashers[n.multihash.code],{...t,log:this.log});t.onProgress?.(new P("blocks:get-many:blockstore:put",n)),await this.child.put(n,i,t),t.onProgress?.(new P("blocks:get-many:providers:notify",n)),this.blockAnnouncers.forEach(o=>{o.announce(n,i,t)})}}))}async delete(e,t={}){t.onProgress?.(new P("blocks:delete:blockstore:delete",e)),await this.child.delete(e,t)}async*deleteMany(e,t={}){t.onProgress?.(new P("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 P("blocks:get-all:blockstore:get-many")),yield*this.child.getAll(e)}},Kv=(r,e)=>{if(e==null)throw new F(`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(!de(n.digest,r.multihash.digest))throw new F("Hash of downloaded block did not match multihash from passed CID","ERR_HASH_MISMATCH")}};async function qy(r,e,t,n){let i=Kv(r,t),o=new AbortController,s=oi([o.signal,n.signal]);try{return await Promise.any(e.map(async a=>{try{let c=!1,u=await a.retrieve(r,{...n,signal:s,validateFn:async l=>{await i(l),c=!0}});return c||await i(u),u}catch(c){throw n.log.error("could not retrieve verified block for %c",r,c),c}}))}finally{s.clear()}}var wl=class{blockstore;datastore;pins;logger;routing;dagWalkers;hashers;log;constructor(e){this.logger=e.logger??g0(),this.log=this.logger.forComponent("helia"),this.hashers=zy(e.hashers),this.dagWalkers=My(e.dagWalkers);let t={blockstore:e.blockstore,datastore:e.datastore,hashers:this.hashers,dagWalkers:this.dagWalkers,logger:this.logger,blockBrokers:[],...e.components??{}};t.blockBrokers=e.blockBrokers.map(i=>i(t));let n=new gl(t);this.pins=new sl(e.datastore,n,this.dagWalkers),this.blockstore=new cl(n,this.pins,{holdGcLock:e.holdGcLock??!0}),this.datastore=e.datastore,this.routing=new al(t,{routers:(e.routers??[]).flatMap(i=>{let o=[i];return i[Wo]!=null&&o.push(i[Wo]),i[Yo]!=null&&o.push(i[Yo]),o})})}async start(){await $y(this.datastore),await Bn(this.blockstore,this.datastore,this.routing)}async stop(){await An(this.blockstore,this.datastore,this.routing)}async gc(e={}){let t=await this.blockstore.lock.writeLock();try{let n=this,i=this.blockstore.unwrap();this.log("gc start"),await Vr(i.deleteMany(async function*(){for await(let{cid:o}of i.getAll())try{if(await n.pins.isPinned(o,e))continue;yield o,e.onProgress?.(new P("helia:gc:deleted",o))}catch(s){n.log.error("Error during gc",s),e.onProgress?.(new P("helia:gc:error",s))}}()))}finally{t()}this.log("gc finished")}};var Fs=class extends vr{data;constructor(){super(),this.data=new Map}put(e,t){return this.data.set(qe.encode(e.multihash.bytes),t),e}get(e){let t=this.data.get(qe.encode(e.multihash.bytes));if(t==null)throw Yn();return t}has(e){return this.data.has(qe.encode(e.multihash.bytes))}async delete(e){this.data.delete(qe.encode(e.multihash.bytes))}async*getAll(){for(let[e,t]of this.data.entries())yield{cid:V.createV1(Ne,bt(qe.decode(e))),block:t}}};var QU={...Ai};var jy=re(Re(),1);function xl(r){return r=r??new Error("Not Found"),(0,jy.default)(r,"ERR_NOT_FOUND")}var Gy="SHARDING";function jv(r){return r[Symbol.asyncIterator]!=null}function Gv(r){if(jv(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 bl=Gv;function Wv(r){return r[Symbol.asyncIterator]!=null}function Yv(r,e){return Wv(r)?async function*(){yield*(await bl(r)).sort(e)}():function*(){yield*bl(r).sort(e)}()}var El=Yv;var an=class{put(e,t,n){return Promise.reject(new Error(".put is not implemented"))}get(e,t){return Promise.reject(new Error(".get is not implemented"))}has(e,t){return Promise.reject(new Error(".has is not implemented"))}delete(e,t){return Promise.reject(new Error(".delete is not implemented"))}async*putMany(e,t={}){for await(let{key:n,value:i}of e)await this.put(n,i,t),yield n}async*getMany(e,t={}){for await(let n of e)yield{key:n,value:await this.get(n,t)}}async*deleteMany(e,t={}){for await(let n of e)await this.delete(n,t),yield n}batch(){let e=[],t=[];return{put(n,i){e.push({key:n,value:i})},delete(n){t.push(n)},commit:async n=>{await Vr(this.putMany(e,n)),e=[],await Vr(this.deleteMany(t,n)),t=[]}}}async*_all(e,t){throw new Error("._all is not implemented")}async*_allKeys(e,t){throw new Error("._allKeys is not implemented")}query(e,t){let n=this._all(e,t);if(e.prefix!=null){let i=e.prefix;n=gt(n,o=>o.key.toString().startsWith(i))}if(Array.isArray(e.filters)&&(n=e.filters.reduce((i,o)=>gt(i,o),n)),Array.isArray(e.orders)&&(n=e.orders.reduce((i,o)=>El(i,o),n)),e.offset!=null){let i=0,o=e.offset;n=gt(n,()=>i++>=o)}return e.limit!=null&&(n=va(n,e.limit)),n}queryKeys(e,t){let n=this._allKeys(e,t);if(e.prefix!=null){let i=e.prefix;n=gt(n,o=>o.toString().startsWith(i))}if(Array.isArray(e.filters)&&(n=e.filters.reduce((i,o)=>gt(i,o),n)),Array.isArray(e.orders)&&(n=e.orders.reduce((i,o)=>El(i,o),n)),e.offset!=null){let i=e.offset,o=0;n=gt(n,()=>o++>=i)}return e.limit!=null&&(n=va(n,e.limit)),n}};var Ms=class extends an{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 xl();return t}has(e){return this.data.has(e.toString())}delete(e){this.data.delete(e.toString())}*_all(){for(let[e,t]of this.data.entries())yield{key:new Fe(e),value:t}}*_allKeys(){for(let e of this.data.keys())yield new Fe(e)}};var _L=new Fe(Gy);var VL=se("datastore:core:tiered");async function Yy(r={}){let e=r.datastore??new Ms,t=r.blockstore??new Fs,n=new wl({...r,datastore:e,blockstore:t,blockBrokers:r.blockBrokers??[Qo()],routers:r.routers??[Us("https://delegated-ipfs.dev")]});return r.start!==!1&&await n.start(),n}var Fd=class{components;constructor(e){this.components=e}async add(e,t={}){let n=Sy(e),i=await(t.hasher??ne).digest(n),o=V.createV1(jn,i);return await this.components.blockstore.put(o,n,t),o}async get(e,t={}){let n=await this.components.blockstore.get(e,t);return ul(n)}};function Xy(r){return new Fd(r)}var Vd=class{components;constructor(e){this.components=e}async add(e,t={}){let n=ky(e),i=await(t.hasher??ne).digest(n),o=V.createV1(Wn,i);return await this.components.blockstore.put(o,n,t),o}async get(e,t={}){let n=await this.components.blockstore.get(e,t);return fl(n)}};function Zy(r){return new Vd(r)}var Md=re(Dc(),1);function Jy(r,e){let t=e.map((n,i)=>({record:at(n),index:i}));return t.sort((n,i)=>{let o=n.record.sequence,s=i.record.sequence;if(o>s)return-1;if(o<s)return 1;if(n.record.validityType===Ge.ValidityType.EOL&&i.record.validityType===Ge.ValidityType.EOL){let a=Md.default.fromString(n.record.validity).toDate(),c=Md.default.fromString(i.record.validity).toDate();if(a.getTime()>c.getTime())return-1;if(a.getTime()<c.getTime())return 1}return 0}),t[0].index}var Jv=r=>{let e=r.data;return e.startsWith('"')&&(e=e.substring(1)),e.endsWith('"')&&(e=e.substring(0,e.length-1)),e.replace("dnslink=","")},Hd=(r,e)=>{let t=Qv(r,e);return{ipfsPath:Jv(t),answer:t}},Qv=(r,e)=>{let t=e.Answer?.filter(n=>n.data.includes("dnslink=/ipfs")||n.data.includes("dnslink=/ipns")).pop();if(t==null)throw new F(`No dnslink records found for domain: ${r}`,"ERR_DNSLINK_NOT_FOUND");return t},Hs=32,_o=async(r,e,t,n={})=>{if(e===0)throw new Error("recursion limit exceeded");let i;try{i=await t(r,n)}catch(a){if(a.code!=="ENOTFOUND"&&a.code!=="ERR_DNSLINK_NOT_FOUND"&&a.code!=="ENODATA")throw a;r.startsWith("_dnslink.")?r=r.replace("_dnslink.",""):r=`_dnslink.${r}`,i=await t(r,n)}let o=i.replace("dnslink=",""),s=o.split("/")[2];try{return V.parse(s),o}catch{}return _o(s,e-1,t,n)},e4=/^dnslink=.+$/,Qy=async(r,e)=>{let i=(await r.resolveTxt(e)).flat().filter(o=>e4.test(o))[0];if(i==null)throw new F(`No dnslink records found for domain: ${e}`,"ERR_DNSLINK_NOT_FOUND");return i};var zd=re(vu(),1),Kd=re(rg(),1);function vl(r,e,t){return`${r}?name=${e}&type=${t}`}async function ng(r,e){return await(await fetch(r,{headers:new Headers({accept:"application/dns-json"}),signal:e})).json()}function Ii(r,e){return`${e}_${r}`}var $d=Object.assign((0,zd.default)("dns-over-http-resolver"),{error:(0,zd.default)("dns-over-http-resolver:error")}),qd=class{_cache;_TXTcache;_servers;_request;_abortControllers;constructor(e={}){this._cache=new Kd.default({max:e?.maxCache??100}),this._TXTcache=new Kd.default({max:e?.maxCache??100}),this._servers=["https://cloudflare-dns.com/dns-query","https://dns.google/resolve"],this._request=e.request??ng,this._abortControllers=[]}cancel(){this._abortControllers.forEach(e=>{e.abort()})}getServers(){return this._servers}_getShuffledServers(){let e=[...this._servers];for(let t=e.length-1;t>0;t--){let n=Math.floor(Math.random()*t),i=e[t];e[t]=e[n],e[n]=i}return e}setServers(e){this._servers=e}async resolve(e,t="A"){switch(t){case"A":return this.resolve4(e);case"AAAA":return this.resolve6(e);case"TXT":return this.resolveTxt(e);default:throw new Error(`${t} is not supported`)}}async resolve4(e){let t="A",n=this._cache.get(Ii(e,t));if(n!=null)return n;let i=!1;for(let o of this._getShuffledServers()){let s=new AbortController;this._abortControllers.push(s);try{let a=await this._request(vl(o,e,t),s.signal),c=a.Answer.map(l=>l.data),u=Math.min(...a.Answer.map(l=>l.TTL));return this._cache.set(Ii(e,t),c,{ttl:u}),c}catch{s.signal.aborted&&(i=!0),$d.error(`${o} could not resolve ${e} record ${t}`)}finally{this._abortControllers=this._abortControllers.filter(a=>a!==s)}}throw i?Object.assign(new Error("queryA ECANCELLED"),{code:"ECANCELLED"}):new Error(`Could not resolve ${e} record ${t}`)}async resolve6(e){let t="AAAA",n=this._cache.get(Ii(e,t));if(n!=null)return n;let i=!1;for(let o of this._getShuffledServers()){let s=new AbortController;this._abortControllers.push(s);try{let a=await this._request(vl(o,e,t),s.signal),c=a.Answer.map(l=>l.data),u=Math.min(...a.Answer.map(l=>l.TTL));return this._cache.set(Ii(e,t),c,{ttl:u}),c}catch{s.signal.aborted&&(i=!0),$d.error(`${o} could not resolve ${e} record ${t}`)}finally{this._abortControllers=this._abortControllers.filter(a=>a!==s)}}throw i?Object.assign(new Error("queryAaaa ECANCELLED"),{code:"ECANCELLED"}):new Error(`Could not resolve ${e} record ${t}`)}async resolveTxt(e){let t="TXT",n=this._TXTcache.get(Ii(e,t));if(n!=null)return n;let i=!1;for(let o of this._getShuffledServers()){let s=new AbortController;this._abortControllers.push(s);try{let a=await this._request(vl(o,e,t),s.signal),c=a.Answer.map(l=>[l.data.replace(/['"]+/g,"")]),u=Math.min(...a.Answer.map(l=>l.TTL));return this._TXTcache.set(Ii(e,t),c,{ttl:u}),c}catch{s.signal.aborted&&(i=!0),$d.error(`${o} could not resolve ${e} record ${t}`)}finally{this._abortControllers=this._abortControllers.filter(a=>a!==s)}}throw i?Object.assign(new Error("queryTxt ECANCELLED"),{code:"ECANCELLED"}):new Error(`Could not resolve ${e} record ${t}`)}clearCache(){this._cache.clear(),this._TXTcache.clear()}},ig=qd;var sg=re(jd(),1),Zn=class{lru;constructor(e){this.lru=(0,sg.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 Gd=new Zn(1e3),o4=60*1e3,s4=new mt({concurrency:4}),a4=async function(e,t={}){let n=new ig({maxCache:0});if(t.nocache!==!0&&Gd.has(e)){let o=Gd.get(e);if(o!=null)return t?.onProgress?.(new P("dnslink:cache",{detail:o})),o}t.onProgress?.(new P("dnslink:query",{detail:e}));let i=await s4.add(async()=>{let o=await Qy(n,e);return t.onProgress?.(new P("dnslink:answer",{detail:o})),Gd.set(e,o,o4),o},{signal:t?.signal});if(i==null)throw new Error("No DNS response received");return i},ag=a4;function cg(){return async(r,e={})=>_o(r,Hs,ag,e)}var Wd=class{routing;constructor(e){this.routing=e}async put(e,t,n={}){try{await this.routing.put(e,t,n)}catch(i){n.onProgress?.(new P("ipns:routing:helia:error",i))}}async get(e,t={}){try{return await this.routing.get(e,t)}catch(n){t.onProgress?.(new P("ipns:routing:helia:error",n))}throw new Error("Not found")}};function lg(r){return new Wd(r)}var Bl=globalThis.CustomEvent??Event;async function*Si(r,e={}){let t=e.concurrency??1/0;t<1&&(t=1/0);let n=e.ordered==null?!1:e.ordered,i=new EventTarget,o=[],s=Ue(),a=Ue(),c=!1,u,l=!1;i.addEventListener("task-complete",()=>{a.resolve()}),Promise.resolve().then(async()=>{try{for await(let f of r){if(o.length===t&&(s=Ue(),await s.promise),l)break;let m={done:!1};o.push(m),f().then(y=>{m.done=!0,m.ok=!0,m.value=y,i.dispatchEvent(new Bl("task-complete"))},y=>{m.done=!0,m.err=y,i.dispatchEvent(new Bl("task-complete"))})}c=!0,i.dispatchEvent(new Bl("task-complete"))}catch(f){u=f,i.dispatchEvent(new Bl("task-complete"))}});function h(){return n?o[0]?.done:!!o.find(f=>f.done)}function*p(){for(;o.length>0&&o[0].done;){let f=o[0];if(o.shift(),f.ok)yield f.value;else throw l=!0,s.resolve(),f.err;s.resolve()}}function*d(){for(;h();)for(let f=0;f<o.length;f++)if(o[f].done){let m=o[f];if(o.splice(f,1),f--,m.ok)yield m.value;else throw l=!0,s.resolve(),m.err;s.resolve()}}for(;;){if(h()||(a=Ue(),await a.promise),u!=null)throw u;if(n?yield*p():yield*d(),c&&o.length===0)break}}var $s;(function(r){let e;r.codec=()=>(e==null&&(e=Ft((t,n,i={})=>{i.lengthDelimited!==!1&&n.fork(),t.key!=null&&t.key.byteLength>0&&(n.uint32(10),n.bytes(t.key)),t.value!=null&&t.value.byteLength>0&&(n.uint32(18),n.bytes(t.value)),t.timeReceived!=null&&t.timeReceived!==""&&(n.uint32(42),n.string(t.timeReceived)),i.lengthDelimited!==!1&&n.ldelim()},(t,n)=>{let i={key:new Uint8Array(0),value:new Uint8Array(0),timeReceived:""},o=n==null?t.len:t.pos+n;for(;t.pos<o;){let s=t.uint32();switch(s>>>3){case 1:i.key=t.bytes();break;case 2:i.value=t.bytes();break;case 5:i.timeReceived=t.string();break;default:t.skipType(s&7);break}}return i})),e),r.encode=t=>Ot(t,r.codec()),r.decode=t=>Dt(t,r.codec())})($s||($s={}));function ug(r){let e=r.getUTCFullYear(),t=String(r.getUTCMonth()+1).padStart(2,"0"),n=String(r.getUTCDate()).padStart(2,"0"),i=String(r.getUTCHours()).padStart(2,"0"),o=String(r.getUTCMinutes()).padStart(2,"0"),s=String(r.getUTCSeconds()).padStart(2,"0"),a=r.getUTCMilliseconds(),c=String(a*1e3*1e3).padStart(9,"0");return`${e}-${t}-${n}T${i}:${o}:${s}.${c}Z`}function hg(r){let e=new RegExp("(\\d{4})-(\\d{2})-(\\d{2})T(\\d{2}):(\\d{2}):(\\d{2})\\.(\\d+)Z"),t=String(r).trim().match(e);if(t==null)throw new Error("Invalid format");let n=parseInt(t[1],10),i=parseInt(t[2],10)-1,o=parseInt(t[3],10),s=parseInt(t[4],10),a=parseInt(t[5],10),c=parseInt(t[6],10),u=parseInt(t[7].slice(0,-6),10);return new Date(Date.UTC(n,i,o,s,a,c,u))}var ko=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 $s.encode(this.prepareSerialize())}prepareSerialize(){return{key:this.key,value:this.value,timeReceived:ug(this.timeReceived)}}static deserialize(e){let t=$s.decode(e);return new r(t.key,t.value,new Date(t.timeReceived))}static fromDeserialized(e){let t=hg(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 dg;(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"})(dg||(dg={}));var fg;(function(r){r[r.PUT_VALUE=0]="PUT_VALUE",r[r.GET_VALUE=1]="GET_VALUE",r[r.ADD_PROVIDER=2]="ADD_PROVIDER",r[r.GET_PROVIDERS=3]="GET_PROVIDERS",r[r.FIND_NODE=4]="FIND_NODE",r[r.PING=5]="PING"})(fg||(fg={}));function Yd(r){return new Fe("/dht/record/"+Q(r,"base32"),!1)}function pg(r){return{async put(e,t,n={}){try{let i=Yd(e),o=new ko(e,t,new Date);n.onProgress?.(new P("ipns:routing:datastore:put")),await r.put(i,o.serialize(),n)}catch(i){throw n.onProgress?.(new P("ipns:routing:datastore:error",i)),i}},async get(e,t={}){try{let n=Yd(e);t.onProgress?.(new P("ipns:routing:datastore:get"));let i=await r.get(n,t);return ko.deserialize(i).value}catch(n){throw t.onProgress?.(new P("ipns:routing:datastore:error",n)),n}},async has(e,t={}){let n=Yd(e);return r.has(n,t)}}}var _i=se("helia:ipns"),l4=60*1e3,mg=60*l4,u4=24*mg,Xd=23*mg,Zd=class{routers;localStore;timeout;defaultResolvers;constructor(e,t=[],n=[]){this.routers=[lg(e.routing),...t],this.localStore=pg(e.datastore),this.defaultResolvers=n.length>0?n:[cg()]}async publish(e,t,n={}){try{let i=1n,o=Eo(e);if(await this.localStore.has(o,n)){let c=await this.localStore.get(o,n);i=at(c).sequence+1n}let s=await iy(e,t,i,n.lifetime??u4,n),a=on(s);return await this.localStore.put(o,a,n),n.offline!==!0&&await Promise.all(this.routers.map(async c=>{await c.put(o,a,n)})),s}catch(i){throw n.onProgress?.(new P("ipns:publish:error",i)),i}}async resolve(e,t={}){let n=Eo(e),i=await this.#t(n,t);return this.#e(i.value,t)}async resolveDns(e,t={}){let n=t.resolvers??this.defaultResolvers,i=await Promise.any(n.map(async o=>o(e,t)));return this.#e(i,t)}republish(e={}){if(this.timeout!=null)throw new Error("Republish is already running");e.signal?.addEventListener("abort",()=>{clearTimeout(this.timeout)});async function t(){let n=Date.now();e.onProgress?.(new P("ipns:republish:start"));let o=Date.now()-n,s=Xd-o;s<0&&(s=e.interval??Xd),setTimeout(()=>{t().catch(a=>{_i.error("error republishing",a)})},s)}this.timeout=setTimeout(()=>{t().catch(n=>{_i.error("error republishing",n)})},e.interval??Xd)}async#e(e,t={}){let n=e.split("/");try{let i=n[1];if(i==="ipns"){let{cid:o}=await this.resolve(Yt(n[2]),t),s=n.slice(3).join("/");return{cid:o,path:s}}else if(i==="ipfs"){let o=V.parse(n[2]),s=n.slice(3).join("/");return{cid:o,path:s}}}catch(i){_i.error("error parsing ipfs path",i)}throw _i.error("invalid ipfs path %s",e),new Error("Invalid value")}async#t(e,t={}){let n=[this.localStore,...this.routers];t.offline===!0&&(n=[this.localStore]);let i=[],o=0;if(await Promise.all(n.map(async a=>{let c;try{c=await a.get(e,{...t,validate:!1})}catch(u){a===this.localStore&&u.code==="ERR_NOT_FOUND"?_i("did not have record locally"):_i.error("error finding IPNS record",u);return}try{await Zc(e,c),i.push(c)}catch(u){o++,_i.error("error finding IPNS record",u)}})),i.length===0)throw o>0?new F(`${o>1?`${o} records`:"Record"} found for routing key ${o>1?"were":"was"} invalid`,"ERR_RECORDS_FAILED_VALIDATION"):new F("Could not find record for routing key","ERR_NOT_FOUND");let s=i[Jy(e,i)];return await this.localStore.put(e,s,t),at(s)}};function yg(r,{routers:e=[],resolvers:t=[]}={}){return new Zd(r,e,t)}var X4=re(lf(),1),Z4=re(Gg(),1);var IP=new Zn(1e3),SP=60*1e3;var xf=new Zn(1e3),J4=60*1e3;function Rl(r){let e=new mt({concurrency:4}),t=async(n,i={})=>{let o=new URLSearchParams;o.set("name",n),o.set("type","TXT");let s=o.toString();if(i.nocache!==!0&&xf.has(s)){let c=xf.get(s);if(c!=null)return i.onProgress?.(new P("dnslink:cache",{detail:c})),c}i.onProgress?.(new P("dnslink:query",{detail:n}));let a=await e.add(async()=>{let c=await fetch(`${r}?${o}`,{headers:{accept:"application/dns-json"},signal:i.signal});if(c.status!==200)throw new Error(`Unexpected HTTP status: ${c.status} - ${c.statusText}`);let u=new URL(c.url).search.slice(1),l=await c.json();i.onProgress?.(new P("dnslink:answer",{detail:l}));let{ipfsPath:h,answer:p}=Hd(n,l);return xf.set(u,h,p.TTL??J4),h},{signal:i.signal});if(a==null)throw new Error("No DNS response received");return a};return async(n,i={})=>_o(n,Hs,t,i)}var bf=class{components;constructor(e){this.components=e}async add(e,t={}){let n=k0(e),i=await(t.hasher??ne).digest(n),o=V.createV1(kn,i);return await this.components.blockstore.put(o,n,t),o}async get(e,t={}){let n=await this.components.blockstore.get(e,t);return ya(n)}};function Wg(r){return new bf(r)}var Sf=re(Re(),1);function Q4(r){return r[Symbol.asyncIterator]!=null}function eB(r,e=1){return e=Number(e),Q4(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 qs=eB;async function*js(r,e=1){for await(let t of qs(r,e)){let n=t.map(async i=>i().then(o=>({ok:!0,value:o}),o=>({ok:!1,err:o})));for(let i=0;i<n.length;i++){let o=await n[i];if(o.ok)yield o.value;else throw o.err}}}var tB=262144,Gs=(r={})=>{let e=r.chunkSize??tB;return async function*(n){let i=new di,o=0,s=!1;for await(let a of n)for(i.append(a),o+=a.length;o>=e;)if(yield i.slice(0,e),s=!0,e===i.length)i=new di,o=0;else{let c=new di;c.append(i.sublist(e)),i=c,o-=e}(!s||o>0)&&(yield i.subarray(0,o))}};var Ef=re(Re(),1);var cr;(function(r){let e;(function(i){i.Raw="Raw",i.Directory="Directory",i.File="File",i.Metadata="Metadata",i.Symlink="Symlink",i.HAMTShard="HAMTShard"})(e=r.DataType||(r.DataType={}));let t;(function(i){i[i.Raw=0]="Raw",i[i.Directory=1]="Directory",i[i.File=2]="File",i[i.Metadata=3]="Metadata",i[i.Symlink=4]="Symlink",i[i.HAMTShard=5]="HAMTShard"})(t||(t={})),function(i){i.codec=()=>hi(t)}(e=r.DataType||(r.DataType={}));let n;r.codec=()=>(n==null&&(n=Ft((i,o,s={})=>{if(s.lengthDelimited!==!1&&o.fork(),i.Type!=null&&(o.uint32(8),r.DataType.codec().encode(i.Type,o)),i.Data!=null&&(o.uint32(18),o.bytes(i.Data)),i.filesize!=null&&(o.uint32(24),o.uint64(i.filesize)),i.blocksizes!=null)for(let a of i.blocksizes)o.uint32(32),o.uint64(a);i.hashType!=null&&(o.uint32(40),o.uint64(i.hashType)),i.fanout!=null&&(o.uint32(48),o.uint64(i.fanout)),i.mode!=null&&(o.uint32(56),o.uint32(i.mode)),i.mtime!=null&&(o.uint32(66),Tl.codec().encode(i.mtime,o)),s.lengthDelimited!==!1&&o.ldelim()},(i,o)=>{let s={blocksizes:[]},a=o==null?i.len:i.pos+o;for(;i.pos<a;){let c=i.uint32();switch(c>>>3){case 1:s.Type=r.DataType.codec().decode(i);break;case 2:s.Data=i.bytes();break;case 3:s.filesize=i.uint64();break;case 4:s.blocksizes.push(i.uint64());break;case 5:s.hashType=i.uint64();break;case 6:s.fanout=i.uint64();break;case 7:s.mode=i.uint32();break;case 8:s.mtime=Tl.codec().decode(i,i.uint32());break;default:i.skipType(c&7);break}}return s})),n),r.encode=i=>Ot(i,r.codec()),r.decode=i=>Dt(i,r.codec())})(cr||(cr={}));var Tl;(function(r){let e;r.codec=()=>(e==null&&(e=Ft((t,n,i={})=>{i.lengthDelimited!==!1&&n.fork(),t.Seconds!=null&&(n.uint32(8),n.int64(t.Seconds)),t.FractionalNanoseconds!=null&&(n.uint32(21),n.fixed32(t.FractionalNanoseconds)),i.lengthDelimited!==!1&&n.ldelim()},(t,n)=>{let i={},o=n==null?t.len:t.pos+n;for(;t.pos<o;){let s=t.uint32();switch(s>>>3){case 1:i.Seconds=t.int64();break;case 2:i.FractionalNanoseconds=t.fixed32();break;default:t.skipType(s&7);break}}return i})),e),r.encode=t=>Ot(t,r.codec()),r.decode=t=>Dt(t,r.codec())})(Tl||(Tl={}));var Yg;(function(r){let e;r.codec=()=>(e==null&&(e=Ft((t,n,i={})=>{i.lengthDelimited!==!1&&n.fork(),t.MimeType!=null&&(n.uint32(10),n.string(t.MimeType)),i.lengthDelimited!==!1&&n.ldelim()},(t,n)=>{let i={},o=n==null?t.len:t.pos+n;for(;t.pos<o;){let s=t.uint32();switch(s>>>3){case 1:i.MimeType=t.string();break;default:t.skipType(s&7);break}}return i})),e),r.encode=t=>Ot(t,r.codec()),r.decode=t=>Dt(t,r.codec())})(Yg||(Yg={}));var Xg={Raw:"raw",Directory:"directory",File:"file",Metadata:"metadata",Symlink:"symlink",HAMTShard:"hamt-sharded-directory"},rB=["directory","hamt-sharded-directory"],Zg=parseInt("0644",8),Jg=parseInt("0755",8),W=class r{static unmarshal(e){let t=cr.decode(e),n=new r({type:Xg[t.Type!=null?t.Type.toString():"File"],data:t.Data,blockSizes:t.blocksizes,mode:t.mode,mtime:t.mtime!=null?{secs:t.mtime.Seconds??0n,nsecs:t.mtime.FractionalNanoseconds}:void 0,fanout:t.fanout});return n._originalMode=t.mode??0,n}type;data;blockSizes;hashType;fanout;mtime;_mode;_originalMode;constructor(e={type:"file"}){let{type:t,data:n,blockSizes:i,hashType:o,fanout:s,mtime:a,mode:c}=e;if(t!=null&&!Object.values(Xg).includes(t))throw(0,Ef.default)(new Error("Type: "+t+" is not valid"),"ERR_INVALID_TYPE");this.type=t??"file",this.data=n,this.hashType=o,this.fanout=s,this.blockSizes=i??[],this._originalMode=0,this.mode=c,this.mtime=a}set mode(e){e==null?this._mode=this.isDirectory()?Jg:Zg:this._mode=e&4095}get mode(){return this._mode}isDirectory(){return rB.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=cr.DataType.Raw;break;case"directory":e=cr.DataType.Directory;break;case"file":e=cr.DataType.File;break;case"metadata":e=cr.DataType.Metadata;break;case"symlink":e=cr.DataType.Symlink;break;case"hamt-sharded-directory":e=cr.DataType.HAMTShard;break;default:throw(0,Ef.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===Zg&&!this.isDirectory()&&(n=void 0),n===Jg&&this.isDirectory()&&(n=void 0));let i;return this.mtime!=null&&(i={Seconds:this.mtime.secs,FractionalNanoseconds:this.mtime.nsecs}),cr.encode({Type:e,Data:t,filesize:this.isDirectory()?void 0:this.fileSize(),blocksizes:this.blockSizes,hashType:this.hashType,fanout:this.fanout,mode:n,mtime:i})}};var lr=async(r,e,t)=>{t.codec==null&&(t.codec=De);let n=await ne.digest(r),i=V.create(t.cidVersion,t.codec.code,n);return await e.put(i,r,t),i};function Qg(r){return async function*(t,n){let i=0n;for await(let o of t.content)yield async()=>{let s,a={codec:De,cidVersion:r.cidVersion,onProgress:r.onProgress};r.rawLeaves?(a.codec=Pt,a.cidVersion=1):(s=new W({type:r.leafType,data:o}),o=le({Data:s.marshal(),Links:[]}));let c=await lr(o,n,a);return i+=BigInt(o.byteLength),r.onProgress?.(new P("unixfs:importer:progress:file:write",{bytesWritten:i,cid:c,path:t.path})),{cid:c,unixfs:s,size:BigInt(o.length),block:o}}}}var vf=re(Re(),1);var ew=async(r,e,t)=>{let n=new W({type:"directory",mtime:r.mtime,mode:r.mode}),i=le(_e({Data:n.marshal()})),o=await lr(i,e,t),s=r.path;return{cid:o,path:s,unixfs:n,size:BigInt(i.length),originalPath:r.originalPath,block:i}};async function*nB(r,e,t){let n=-1,i;for await(let o of js(t.bufferImporter(r,e),t.blockWriteConcurrency)){if(n++,n===0){i={...o,single:!0};continue}else n===1&&i!=null&&(yield{...i,block:void 0,single:void 0},i=void 0);yield{...o,block:void 0}}i!=null&&(yield i)}function tw(r){return r.single===!0}var iB=(r,e,t)=>async function(i){if(i.length===1&&tw(i[0])&&t.reduceSingleLeafToSelf){let l=i[0],h=l.block;return tw(l)&&(r.mtime!==void 0||r.mode!==void 0)&&(l.unixfs=new W({type:"file",mtime:r.mtime,mode:r.mode,data:l.block}),h={Data:l.unixfs.marshal(),Links:[]},l.block=le(_e(h)),l.cid=await lr(l.block,e,{...t,cidVersion:t.cidVersion}),l.size=BigInt(l.block.length)),t.onProgress?.(new P("unixfs:importer:progress:file:layout",{cid:l.cid,path:l.originalPath})),{cid:l.cid,path:r.path,unixfs:l.unixfs,size:l.size,originalPath:l.originalPath}}let o=new W({type:"file",mtime:r.mtime,mode:r.mode}),s=i.filter(l=>l.cid.code===Ne&&l.size>0||l.unixfs!=null&&l.unixfs.data==null&&l.unixfs.fileSize()>0n?!0:!!l.unixfs?.data?.length).map(l=>l.cid.code===Ne?(o.addBlockSize(l.size),{Name:"",Tsize:Number(l.size),Hash:l.cid}):(l.unixfs==null||l.unixfs.data==null?o.addBlockSize(l.unixfs?.fileSize()??0n):o.addBlockSize(BigInt(l.unixfs.data.length)),{Name:"",Tsize:Number(l.size),Hash:l.cid})),a={Data:o.marshal(),Links:s},c=le(_e(a)),u=await lr(c,e,t);return t.onProgress?.(new P("unixfs:importer:progress:file:layout",{cid:u,path:r.originalPath})),{cid:u,path:r.path,unixfs:o,size:BigInt(c.length+a.Links.reduce((l,h)=>l+(h.Tsize??0),0)),originalPath:r.originalPath,block:c}},rw=async(r,e,t)=>t.layout(nB(r,e,t),iB(r,e,t));function oB(r){return Symbol.iterator in r}function sB(r){return Symbol.asyncIterator in r}function aB(r){try{if(r instanceof Uint8Array)return async function*(){yield r}();if(oB(r))return async function*(){yield*r}();if(sB(r))return r}catch{throw(0,vf.default)(new Error("Content was invalid"),"ERR_INVALID_CONTENT")}throw(0,vf.default)(new Error("Content was invalid"),"ERR_INVALID_CONTENT")}function nw(r){return async function*(t,n){for await(let i of t){let o;if(i.path!=null&&(o=i.path,i.path=i.path.split("/").filter(s=>s!=null&&s!==".").join("/")),cB(i)){let s={path:i.path,mtime:i.mtime,mode:i.mode,content:async function*(){let a=0n;for await(let c of r.chunker(r.chunkValidator(aB(i.content)))){let u=BigInt(c.byteLength);a+=u,r.onProgress?.(new P("unixfs:importer:progress:file:read",{bytesRead:a,chunkSize:u,path:i.path})),yield c}}(),originalPath:o};yield async()=>rw(s,n,r)}else if(i.path!=null){let s={path:i.path,mtime:i.mtime,mode:i.mode,originalPath:o};yield async()=>ew(s,n,r)}else throw new Error("Import candidate must have content or path or both")}}}function cB(r){return r.content!=null}var Bf=re(Re(),1);var iw=()=>async function*(e){for await(let t of e){if(t.length===void 0)throw(0,Bf.default)(new Error("Content was invalid"),"ERR_INVALID_CONTENT");if(typeof t=="string"||t instanceof String)yield Y(t.toString());else if(Array.isArray(t))yield Uint8Array.from(t);else if(t instanceof Uint8Array)yield t;else throw(0,Bf.default)(new Error("Content was invalid"),"ERR_INVALID_CONTENT")}};var lB=174;function Ws(r){let e=r?.maxChildrenPerNode??lB;return async function t(n,i){let o=[];for await(let s of qs(n,e))o.push(await i(s));return o.length>1?t(o,i):o[0]}}var Nr=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}},Ys=V.parse("QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn"),Xs=V.parse("zdj7WbTaiJT1fgatdet9Ei9iDB5hdCxkbVyhyh8YTUnXMiwYi");var Ci=class extends Nr{_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?Xs.bytes.byteLength:Ys.bytes.byteLength));return this.nodeSize}async*flush(e){let t=[];for(let[c,u]of this._children.entries()){let l=u;if(u instanceof Nr)for await(let h of u.flush(e))l=h,yield h;l.size!=null&&l.cid!=null&&t.push({Name:c,Tsize:Number(l.size),Hash:l.cid})}let n=new W({type:"directory",mtime:this.mtime,mode:this.mode}),i={Data:n.marshal(),Links:t},o=le(_e(i)),s=await lr(o,e,this.options),a=o.length+i.Links.reduce((c,u)=>c+(u.Tsize==null?0:u.Tsize),0);this.cid=s,this.size=a,yield{cid:s,unixfs:n,path:this.path,size:BigInt(a)}}};var Nl=re(aw(),1);function uB(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 M7=si({name:"murmur3-32",code:35,encode:r=>uB(Nl.default.x86.hash32(r))}),Ni=si({name:"murmur3-128",code:34,encode:r=>Oi.fromHex(Nl.default.x64.hash128(r))}),H7=si({name:"murmur3-x64-64",code:34,encode:r=>Oi.fromHex(Nl.default.x64.hash128(r)).subarray(0,8)});var uw=re(Ul(),1);var Ut=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 uw.default,this.key=null}async put(e,t){let n=await this._findNewBucketAndPos(e);n.bucket._putAt(n,e,t)}async get(e){let t=await this._findChild(e);if(t!=null)return t.value}async del(e){let t=await this._findPlace(e),n=t.bucket._at(t.pos);n!=null&&n.key===e&&t.bucket._delAt(t.pos)}leafCount(){return this._children.compactArray().reduce((t,n)=>n instanceof r?t+n.leafCount():t+1,0)}childrenCount(){return this._children.length}onlyChild(){return this._children.get(0)}*eachLeafSeries(){let e=this._children.compactArray();for(let t of e)t instanceof r?yield*t.eachLeafSeries():yield t}serialize(e,t){let n=[];return t(this._children.reduce((i,o,s)=>(o!=null&&(o instanceof r?i.push(o.serialize(e,t)):i.push(e(o,s))),i),n))}async asyncTransform(e,t){return hw(this,e,t)}toJSON(){return this.serialize(mB,yB)}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"?Y(e):e),n=await t.take(this._options.bits),i=this._children.get(n);return i instanceof r?i._findPlace(t):{bucket:this,pos:n,hash:t,existingChild:i}}async _findNewBucketAndPos(e){let t=await this._findPlace(e);if(t.existingChild!=null&&t.existingChild.key!==e){let n=new r(this._options,t.bucket,t.pos);t.bucket._putObjectAt(t.pos,n);let i=await n._findPlace(t.existingChild.hash);return i.bucket._putAt(i,t.existingChild.key,t.existingChild.value),n._findNewBucketAndPos(t.hash)}return t}_putAt(e,t,n){this._putObjectAt(e.pos,{key:t,value:n,hash:e.hash})}_putObjectAt(e,t){this._children.get(e)==null&&this._popCount++,this._children.set(e,t)}_delAt(e){if(e===-1)throw new Error("Invalid position");this._children.get(e)!=null&&this._popCount--,this._children.unset(e),this._level()}_level(){if(this._parent!=null&&this._popCount<=1)if(this._popCount===1){let e=this._children.find(pB);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 pB(r){return!!r}function mB(r,e){return r.key}function yB(r){return r}async function hw(r,e,t){let n=[];for(let i of r._children.compactArray())if(i instanceof Ut)await hw(i,e,t);else{let o=await e(i);n.push({bitField:r._children.bitField(),children:o})}return t(n)}var gB=[255,254,252,248,240,224,192,128],wB=[1,3,7,15,31,63,127,255],Ll=class{_value;_currentBytePos;_currentBitPos;constructor(e){this._value=e,this._currentBytePos=e.length-1,this._currentBitPos=7}availableBits(){return this._currentBitPos+1+this._currentBytePos*8}totalBits(){return this._value.length*8}take(e){let t=e,n=0;for(;t>0&&this._haveBits();){let i=this._value[this._currentBytePos],o=this._currentBitPos+1,s=Math.min(o,t),a=xB(i,o-s,s);n=(n<<s)+a,t-=s,this._currentBitPos-=s,this._currentBitPos<0&&(this._currentBitPos=7,this._currentBytePos--)}return n}untake(e){for(this._currentBitPos+=e;this._currentBitPos>7;)this._currentBitPos-=8,this._currentBytePos+=1}_haveBits(){return this._currentBytePos>=0}};function xB(r,e,t){let n=bB(e,t);return(r&n)>>>e}function bB(r,e){return gB[r]&wB[Math.min(e+r-1,7)]}function dw(r){function e(t){return t instanceof Dl?t:new Dl(t,r)}return e}var Dl=class{_value;_hashFn;_depth;_availableBits;_currentBufferIndex;_buffers;constructor(e,t){if(!(e instanceof Uint8Array))throw new Error("can only hash Uint8Arrays");this._value=e,this._hashFn=t,this._depth=-1,this._availableBits=0,this._currentBufferIndex=0,this._buffers=[]}async take(e){let t=e;for(;this._availableBits<t;)await this._produceMoreBits();let n=0;for(;t>0;){let i=this._buffers[this._currentBufferIndex],o=Math.min(i.availableBits(),t),s=i.take(o);n=(n<<o)+s,t-=o,this._availableBits-=o,i.availableBits()===0&&this._currentBufferIndex++}return n}untake(e){let t=e;for(;t>0;){let n=this._buffers[this._currentBufferIndex],i=Math.min(n.totalBits()-n.availableBits(),t);n.untake(i),t-=i,this._availableBits+=i,this._currentBufferIndex>0&&n.totalBits()===n.availableBits()&&(this._depth--,this._currentBufferIndex--)}}async _produceMoreBits(){this._depth++;let e=this._depth>0?Ee([this._value,Uint8Array.from([this._depth])]):this._value,t=await this._hashFn(e),n=new Ll(t);this._buffers.push(n),this._availableBits+=n.availableBits()}};function Lo(r){if(r==null||r.hashFn==null)throw new Error("please define an options.hashFn");let e={bits:r.bits??8,hash:dw(r.hashFn)};return new Ut(e)}async function EB(r){return(await Ni.encode(r)).slice(0,8).reverse()}var fw=BigInt(34),vB=8,Af=class extends Nr{_bucket;constructor(e,t){super(e,t),this._bucket=Lo({hashFn:EB,bits:t.shardFanoutBits??vB})}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=yw(this._bucket,this,this.options),this.nodeSize)}async*flush(e){for await(let t of mw(this._bucket,e,this,this.options))yield{...t,path:this.path}}},pw=Af;async function*mw(r,e,t,n){let i=r._children,o=(r.tableSize()-1).toString(16).length,s=[],a=0n;for(let f=0;f<i.length;f++){let m=i.get(f);if(m==null)continue;let y=f.toString(16).toUpperCase().padStart(o,"0");if(m instanceof Ut){let g;for await(let x of mw(m,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(BB(m.value)){let g=m.value,x;for await(let A of g.flush(e))x=A,yield x;if(x==null)throw new Error("Did not flush dir");let b=y+m.key;s.push({Name:b,Tsize:Number(x.size),Hash:x.cid}),a+=x.size}else{let g=m.value;if(g.cid==null)continue;let x=y+m.key,b=g.size;s.push({Name:x,Tsize:Number(b),Hash:g.cid}),a+=BigInt(b??0)}}let c=Uint8Array.from(i.bitField().reverse()),u=new W({type:"hamt-sharded-directory",data:c,fanout:BigInt(r.tableSize()),hashType:fw,mtime:t?.mtime,mode:t?.mode}),l={Data:u.marshal(),Links:s},h=le(_e(l)),p=await lr(h,e,n),d=BigInt(h.byteLength)+a;yield{cid:p,unixfs:u,size:d}}function BB(r){return typeof r.flush=="function"}function yw(r,e,t){let n=r._children,i=(r.tableSize()-1).toString(16).length,o=[];for(let u=0;u<n.length;u++){let l=n.get(u);if(l==null)continue;let h=u.toString(16).toUpperCase().padStart(i,"0");if(l instanceof Ut){let p=yw(l,null,t);o.push({Name:h,Tsize:Number(p),Hash:t.cidVersion===0?Ys:Xs})}else if(typeof l.value.flush=="function"){let d=l.value.nodeSize();o.push({Name:h+l.key,Tsize:Number(d),Hash:t.cidVersion===0?Ys:Xs})}else{let p=l.value;if(p.cid==null)continue;let d=h+l.key,f=p.size;o.push({Name:d,Tsize:Number(f),Hash:p.cid})}}let s=Uint8Array.from(n.bitField().reverse()),a=new W({type:"hamt-sharded-directory",data:s,fanout:BigInt(r.tableSize()),hashType:fw,mtime:e?.mtime,mode:e?.mode});return le(_e({Data:a.marshal(),Links:o})).length}async function If(r,e,t,n){let i=e;e instanceof Ci&&e.estimateNodeSize()>t&&(i=await AB(e,n));let o=i.parent;if(o!=null){if(i!==e){if(r!=null&&(r.parent=i),i.parentKey==null)throw new Error("No parent key found");await o.put(i.parentKey,i)}return If(i,o,t,n)}return i}async function AB(r,e){let t=new pw({root:r.root,dir:!0,parent:r.parent,parentKey:r.parentKey,path:r.path,dirty:r.dirty,flat:!1,mtime:r.mtime,mode:r.mode},e);for await(let{key:n,child:i}of r.eachChildSeries())await t.put(n,i);return t}var gw=(r="")=>r.split(/(?<!\\)\//).filter(Boolean);async function IB(r,e,t){let n=gw(r.path??""),i=n.length-1,o=e,s="";for(let a=0;a<n.length;a++){let c=n[a];s+=`${s!==""?"/":""}${c}`;let u=a===i;if(o.dirty=!0,o.cid=void 0,o.size=void 0,u)await o.put(c,r),e=await If(null,o,t.shardSplitThresholdBytes,t);else{let l=await o.get(c);(l==null||!(l instanceof Nr))&&(l=new Ci({root:!1,dir:!0,parent:o,parentKey:c,path:s,dirty:!0,flat:!0,mtime:l?.unixfs?.mtime,mode:l?.unixfs?.mode},t)),await o.put(c,l),o=l}}return e}async function*ww(r,e){if(!(r instanceof Nr)){r.unixfs?.isDirectory()===!0&&(yield r);return}yield*r.flush(e)}function xw(r){return async function*(t,n){let i=new Ci({root:!0,dir:!0,path:"",dirty:!0,flat:!0},r),o,s=!1;for await(let a of t){if(a==null)continue;let c=`${a.originalPath??""}`.split("/")[0];c!=null&&c!==""&&(o==null?(o=c,s=!0):o!==c&&(s=!1)),i=await IB(a,i,r),(a.unixfs==null||!a.unixfs.isDirectory())&&(yield a)}if(r.wrapWithDirectory||s&&i.childCount()>1)yield*ww(i,n);else for await(let a of i.eachChildSeries())a!=null&&(yield*ww(a.child,n))}}async function*ei(r,e,t={}){let n;Symbol.asyncIterator in r||Symbol.iterator in r?n=r:n=[r];let i=t.wrapWithDirectory??!1,o=t.shardSplitThresholdBytes??262144,s=t.shardFanoutBits??8,a=t.cidVersion??1,c=t.rawLeaves??!0,u=t.leafType??"file",l=t.fileImportConcurrency??50,h=t.blockWriteConcurrency??10,p=t.reduceSingleLeafToSelf??!0,d=t.chunker??Gs(),f=t.chunkValidator??iw(),m=t.dagBuilder??nw({chunker:d,chunkValidator:f,wrapWithDirectory:i,layout:t.layout??Ws(),bufferImporter:t.bufferImporter??Qg({cidVersion:a,rawLeaves:c,leafType:u,onProgress:t.onProgress}),blockWriteConcurrency:h,reduceSingleLeafToSelf:p,cidVersion:a,onProgress:t.onProgress}),y=t.treeBuilder??xw({wrapWithDirectory:i,shardSplitThresholdBytes:o,shardFanoutBits:s,cidVersion:a,onProgress:t.onProgress});for await(let g of y(js(m(n,e),l),e))yield{cid:g.cid,path:g.path,unixfs:g.unixfs,size:g.size}}async function Pl(r,e,t={}){let n=await vi(ei([r],e,t));if(n==null)throw(0,Sf.default)(new Error("Nothing imported"),"ERR_INVALID_PARAMS");return n}async function bw(r,e,t={}){let n=await vi(ei([r],e,t));if(n==null)throw(0,Sf.default)(new Error("Nothing imported"),"ERR_INVALID_PARAMS");return n}async function Ew(r,e,t={}){return Pl({content:r},e,t)}async function vw(r,e,t={}){return Pl({content:r},e,t)}var CB=re(Re(),1),NB=re(Dw(),1);var ta={cidVersion:1,rawLeaves:!0,layout:Ws({maxChildrenPerNode:1024}),chunker:Gs({chunkSize:1048576})};async function*Pw(r,e,t={}){yield*ei(r,e,{...ta,...t})}async function Ow(r,e,t={}){let{cid:n}=await Ew(r,e,{...ta,...t});return n}async function Fw(r,e,t={}){let{cid:n}=await vw(r,e,{...ta,...t});return n}async function Vw(r,e,t={}){let{cid:n}=await Pl(r,e,{...ta,...t});return n}async function Mw(r,e,t={}){let{cid:n}=await bw({...r,path:r.path??"-"},e,{...ta,...t});return n}var Fl=re(Re(),1);function UB(r){return r[Symbol.asyncIterator]!=null}function LB(r){if(UB(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 ti=LB;var n2=re(Re(),1);var Hw=re(Re(),1);function Do(r,e,t,n,i,o,s){let a=r,c=i;for(;o.length>0;){let u=o[0];if(u in a){o.shift(),c=`${c}/${u}`;let l=V.asCID(a[u]);if(l!=null)return{entry:{type:"object",name:n,path:i,cid:t,node:e,depth:s,size:BigInt(e.length),content:async function*(){yield r}},next:{cid:l,name:u,path:c,toResolve:o}};a=a[u]}else throw(0,Hw.default)(new Error(`No property named ${u} found in node ${t}`),"ERR_NO_PROP")}return{entry:{type:"object",name:n,path:i,cid:t,node:e,depth:s,size:BigInt(e.length),content:async function*(){yield r}}}}var DB=async(r,e,t,n,i,o,s,a)=>{let c=await s.get(r,a),u=ul(c);return Do(u,c,r,e,t,n,o)},$w=DB;var PB=async(r,e,t,n,i,o,s,a)=>{let c=await s.get(r,a),u=fl(c);return Do(u,c,r,e,t,n,o)},zw=PB;var Kw=re(Re(),1);function OB(r,e,t,n){let i=BigInt(r.length),o=BigInt(e+i);return t>=o||n<e?new Uint8Array(0):(n>=e&&n<o&&(r=r.subarray(0,Number(n-e))),t>=e&&t<o&&(r=r.subarray(Number(t-e))),r)}var Ui=OB;var ra=re(Re(),1),FB=(r,e=0,t=r)=>{let n=BigInt(r),i=BigInt(e??0),o=BigInt(t);if(o!==n&&(o=i+o),o>n&&(o=n),i<0n)throw(0,ra.default)(new Error("Offset must be greater than or equal to 0"),"ERR_INVALID_PARAMS");if(i>n)throw(0,ra.default)(new Error("Offset must be less than the file size"),"ERR_INVALID_PARAMS");if(o<0n)throw(0,ra.default)(new Error("Length must be greater than or equal to 0"),"ERR_INVALID_PARAMS");if(o>n)throw(0,ra.default)(new Error("Length must be less than the file size"),"ERR_INVALID_PARAMS");return{start:i,end:o}},Po=FB;var VB=r=>{async function*e(t={}){let{start:n,end:i}=Po(r.length,t.offset,t.length),o=Ui(r,0n,n,i);t.onProgress?.(new P("unixfs:exporter:progress:identity",{bytesRead:BigInt(o.byteLength),totalBytes:i-n,fileSize:BigInt(r.byteLength)})),yield o}return e},MB=async(r,e,t,n,i,o,s,a)=>{if(n.length>0)throw(0,Kw.default)(new Error(`No link named ${t} found in raw node ${r}`),"ERR_NOT_FOUND");let c=bt(r.multihash.bytes);return{entry:{type:"identity",name:e,path:t,cid:r,content:VB(c.digest),depth:o,size:BigInt(c.digest.length),node:c.digest}}},qw=MB;var HB=async(r,e,t,n,i,o,s,a)=>{let c=await s.get(r,a),u=ya(c);return Do(u,c,r,e,t,n,o)},jw=HB;var Gw=re(Re(),1);var $B=r=>{async function*e(t={}){let{start:n,end:i}=Po(r.length,t.offset,t.length),o=Ui(r,0n,n,i);t.onProgress?.(new P("unixfs:exporter:progress:raw",{bytesRead:BigInt(o.byteLength),totalBytes:i-n,fileSize:BigInt(r.byteLength)})),yield o}return e},zB=async(r,e,t,n,i,o,s,a)=>{if(n.length>0)throw(0,Gw.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:$B(c),depth:o,size:BigInt(c.length),node:c}}},Ww=zB;var ia=re(Re(),1);var na=re(Re(),1);var KB=async function(r){return(await Ni.encode(r)).slice(0,8).reverse()},qB=async(r,e,t)=>{let n=(e.tableSize()-1).toString(16).length;await Promise.all(r.map(async i=>{if(i.Name==null)throw new Error("Unexpected Link without a Name");if(i.Name.length===n){let o=parseInt(i.Name,16);e._putObjectAt(o,new Ut({hash:t._options.hash,bits:t._options.bits},e,o));return}await t.put(i.Name.substring(2),!0)}))},Yw=(r,e)=>r.toString(16).toUpperCase().padStart(e,"0").substring(0,e),jB=r=>{let e=r.bucket,t=[];for(;e._parent!=null;)t.push(e),e=e._parent;return t.push(e),t.reverse()},Xw=async(r,e,t,n,i)=>{if(n==null){if(r.Data==null)throw(0,na.default)(new Error("no data in PBNode"),"ERR_NOT_UNIXFS");let h;try{h=W.unmarshal(r.Data)}catch(d){throw(0,na.default)(d,"ERR_NOT_UNIXFS")}if(h.type!=="hamt-sharded-directory")throw(0,na.default)(new Error("not a HAMT"),"ERR_NOT_UNIXFS");if(h.fanout==null)throw(0,na.default)(new Error("missing fanout"),"ERR_NOT_UNIXFS");let p=Lo({hashFn:KB,bits:Math.log2(Number(h.fanout))});n={rootBucket:p,hamtDepth:1,lastBucket:p}}let o=(n.lastBucket.tableSize()-1).toString(16).length;await qB(r.Links,n.lastBucket,n.rootBucket);let s=await n.rootBucket._findNewBucketAndPos(e),a=Yw(s.pos,o),c=jB(s);c.length>n.hamtDepth&&(n.lastBucket=c[n.hamtDepth],a=Yw(n.lastBucket._posAtParent,o));let u=r.Links.find(h=>{if(h.Name==null)return!1;let p=h.Name.substring(0,o),d=h.Name.substring(o);return!(p!==a||d!==""&&d!==e)});if(u==null)return;if(u.Name!=null&&u.Name.substring(o)===e)return u.Hash;n.hamtDepth++;let l=await t.get(u.Hash,i);return r=ve(l),Xw(r,e,t,n,i)},Zw=Xw;var GB=(r,e,t,n,i,o,s)=>{async function*a(c={}){let u=c.offset??0,l=c.length??e.Links.length,h=e.Links.slice(u,l);c.onProgress?.(new P("unixfs:exporter:walk:directory",{cid:r})),yield*Wt(h,p=>Gt(p,d=>async()=>{let f=d.Name??"",m=`${n}/${f}`;return(await i(d.Hash,f,m,[],o+1,s,c)).entry}),p=>Si(p,{ordered:!0,concurrency:c.blockReadConcurrency}),p=>gt(p,d=>d!=null))}return a},Jw=GB;var Li=re(Re(),1);async function Qw(r,e,t,n,i,o,s){if(e instanceof Uint8Array){let u=Ui(e,n,i,o);t.push(u);return}if(e.Data==null)throw(0,Li.default)(new Error("no data in PBNode"),"ERR_NOT_UNIXFS");let a;try{a=W.unmarshal(e.Data)}catch(u){throw(0,Li.default)(u,"ERR_NOT_UNIXFS")}if(a.data!=null){let u=a.data,l=Ui(u,n,i,o);t.push(l),n+=BigInt(l.byteLength)}let c=[];if(e.Links.length!==a.blockSizes.length)throw(0,Li.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],h=n,p=h+a.blockSizes[u];if((i>=h&&i<p||o>=h&&o<=p||i<h&&o>p)&&c.push({link:l,blockStart:n}),n=p,n>o)break}await Wt(c,u=>Gt(u,l=>async()=>{let h=await r.get(l.link.Hash,s);return{...l,block:h}}),u=>Si(u,{ordered:!0,concurrency:s.blockReadConcurrency}),async u=>{for await(let{link:l,block:h,blockStart:p}of u){let d;switch(l.Hash.code){case Te:d=ve(h);break;case Ne:d=h;break;default:t.end((0,Li.default)(new Error(`Unsupported codec: ${l.Hash.code}`),"ERR_NOT_UNIXFS"));return}let f=new mt({concurrency:1});f.on("error",m=>{t.end(m)}),f.add(async()=>{s.onProgress?.(new P("unixfs:exporter:walk:file",{cid:l.Hash})),await Qw(r,d,t,p,i,o,s)}),await f.onIdle()}}),n>=o&&t.end()}var WB=(r,e,t,n,i,o,s)=>{async function*a(c={}){let u=t.fileSize();if(u===void 0)throw new Error("File was a directory");let{start:l,end:h}=Po(u,c.offset,c.length);if(h===0n)return;let p=0n,d=h-l,f=Vt();c.onProgress?.(new P("unixfs:exporter:walk:file",{cid:r})),Qw(s,e,f,0n,l,h,c).catch(m=>{f.end(m)});for await(let m of f)if(m!=null){if(p+=BigInt(m.byteLength),p>d)throw f.end(),(0,Li.default)(new Error("Read too many bytes - the file size reported by the UnixFS data in the root node may be incorrect"),"ERR_OVER_READ");p===d&&f.end(),c.onProgress?.(new P("unixfs:exporter:progress:unixfs:file",{bytesRead:p,totalBytes:d,fileSize:u})),yield m}if(p<d)throw(0,Li.default)(new Error("Traversed entire DAG but did not read enough bytes"),"ERR_UNDER_READ")}return a},Cf=WB;var Ol=re(Re(),1);var YB=(r,e,t,n,i,o,s)=>{function a(c={}){return c.onProgress?.(new P("unixfs:exporter:walk:hamt-sharded-directory",{cid:r})),e2(e,n,i,o,s,c)}return a};async function*e2(r,e,t,n,i,o){let s=r.Links;if(r.Data==null)throw(0,Ol.default)(new Error("no data in PBNode"),"ERR_NOT_UNIXFS");let a;try{a=W.unmarshal(r.Data)}catch(l){throw(0,Ol.default)(l,"ERR_NOT_UNIXFS")}if(a.fanout==null)throw(0,Ol.default)(new Error("missing fanout"),"ERR_NOT_UNIXFS");let c=(a.fanout-1n).toString(16).length,u=Wt(s,l=>Gt(l,h=>async()=>{let p=h.Name!=null?h.Name.substring(c):null;if(p!=null&&p!==""){let d=await t(h.Hash,p,`${e}/${p}`,[],n+1,i,o);return{entries:d.entry==null?[]:[d.entry]}}else{let d=await i.get(h.Hash,o);return r=ve(d),o.onProgress?.(new P("unixfs:exporter:walk:hamt-sharded-directory",{cid:h.Hash})),{entries:e2(r,e,t,n,i,o)}}}),l=>Si(l,{ordered:!0,concurrency:o.blockReadConcurrency}));for await(let{entries:l}of u)yield*l}var t2=YB;var XB=(r,e)=>r.Links.find(n=>n.Name===e)?.Hash,ZB={raw:Cf,file:Cf,directory:Jw,"hamt-sharded-directory":t2,metadata:(r,e,t,n,i,o,s)=>()=>[],symlink:(r,e,t,n,i,o,s)=>()=>[]},JB=async(r,e,t,n,i,o,s,a)=>{let c=await s.get(r,a),u=ve(c),l,h;if(e==null&&(e=r.toString()),u.Data==null)throw(0,ia.default)(new Error("no data in PBNode"),"ERR_NOT_UNIXFS");try{l=W.unmarshal(u.Data)}catch(d){throw(0,ia.default)(d,"ERR_NOT_UNIXFS")}if(t==null&&(t=e),n.length>0){let d;if(l?.type==="hamt-sharded-directory"?d=await Zw(u,n[0],s):d=XB(u,n[0]),d==null)throw(0,ia.default)(new Error("file does not exist"),"ERR_NOT_FOUND");let f=n.shift(),m=`${t}/${f}`;h={cid:d,toResolve:n,name:f??"",path:m}}let p=ZB[l.type](r,u,l,t,i,o,s);if(p==null)throw(0,ia.default)(new Error("could not find content exporter"),"ERR_NOT_FOUND");return l.isDirectory()?{entry:{type:"directory",name:e,path:t,cid:r,content:p,unixfs:l,depth:o,node:u,size:l.fileSize()},next:h}:{entry:{type:"file",name:e,path:t,cid:r,content:p,unixfs:l,depth:o,node:u,size:l.fileSize()},next:h}},r2=JB;var QB={[Te]:r2,[Ne]:Ww,[jn]:$w,[Wn]:zw,[et.code]:qw,[kn]:jw},i2=async(r,e,t,n,i,o,s)=>{let a=QB[r.code];if(a==null)throw(0,n2.default)(new Error(`No resolver for code ${r.code}`),"ERR_NO_RESOLVER");return a(r,e,t,n,i2,i,o,s)},o2=i2;var eA=(r="")=>(r.trim().match(/([^\\^/]|\\\/)+/g)??[]).filter(Boolean),tA=r=>{if(r instanceof Uint8Array)return{cid:V.decode(r),toResolve:[]};let e=V.asCID(r);if(e!=null)return{cid:e,toResolve:[]};if(typeof r=="string"){r.indexOf("/ipfs/")===0&&(r=r.substring(6));let t=eA(r);return{cid:V.parse(t[0]),toResolve:t.slice(1)}}throw(0,Fl.default)(new Error(`Unknown path type ${r}`),"ERR_BAD_PATH")};async function*Nf(r,e,t={}){let{cid:n,toResolve:i}=tA(r),o=n.toString(),s=o,a=i.length;for(;;){let c=await o2(n,o,s,i,a,e,t);if(c.entry==null&&c.next==null)throw(0,Fl.default)(new Error(`Could not resolve ${r}`),"ERR_NOT_FOUND");if(c.entry!=null&&(yield c.entry),c.next==null)return;i=c.next.toResolve,n=c.next.cid,o=c.next.name,s=c.next.path}}async function Xe(r,e,t={}){let n=await ti(Nf(r,e,t));if(n==null)throw(0,Fl.default)(new Error(`Could not resolve ${r}`),"ERR_NOT_FOUND");return n}async function*Vl(r,e,t={}){let n=await Xe(r,e,t);if(n==null)return;if(yield n,n.type==="directory")for await(let o of i(n,t))yield o;async function*i(o,s){for await(let a of o.content(s))yield a,!(a instanceof Uint8Array)&&a.type==="directory"&&(yield*i(a,s))}}var p2=re(f2(),1),nt=p2.default;var ur=class extends Error{name;code;constructor(e,t,n){super(e),this.name=t,this.code=n}},Ur=class extends ur{constructor(e="not a Unixfs node"){super(e,"NotUnixFSError","ERR_NOT_UNIXFS")}},ut=class extends ur{constructor(e="invalid PBNode"){super(e,"InvalidPBNodeError","ERR_INVALID_PBNODE")}},xn=class extends ur{constructor(e="unknown error"){super(e,"InvalidPBNodeError","ERR_UNKNOWN_ERROR")}},oa=class extends ur{constructor(e="path already exists"){super(e,"AlreadyExistsError","ERR_ALREADY_EXISTS")}},$l=class extends ur{constructor(e="path does not exist"){super(e,"DoesNotExistError","ERR_DOES_NOT_EXIST")}},Vo=class extends ur{constructor(e="no content"){super(e,"NoContentError","ERR_NO_CONTENT")}},zl=class extends ur{constructor(e="not a file"){super(e,"NotAFileError","ERR_NOT_A_FILE")}},ri=class extends ur{constructor(e="not a directory"){super(e,"NotADirectoryError","ERR_NOT_A_DIRECTORY")}},it=class extends ur{constructor(e="invalid parameters"){super(e,"InvalidParametersError","ERR_INVALID_PARAMETERS")}};var Of=re(Ul(),1);function ql(r){function e(t){return t instanceof Kl?t:new Kl(t,r)}return e}var Kl=class{_value;_hashFn;_depth;_availableBits;_currentBufferIndex;_buffers;constructor(e,t){if(!(e instanceof Uint8Array))throw new Error("can only hash Uint8Arrays");this._value=e,this._hashFn=t,this._depth=-1,this._availableBits=0,this._currentBufferIndex=0,this._buffers=[]}async take(e){let t=e;for(;this._availableBits<t;)await this._produceMoreBits();let n=0;for(;t>0;){let i=this._buffers[this._currentBufferIndex],o=Math.min(i.availableBits(),t),s=i.take(o);n=(n<<o)+s,t-=o,this._availableBits-=o,i.availableBits()===0&&this._currentBufferIndex++}return n}untake(e){let t=e;for(;t>0;){let n=this._buffers[this._currentBufferIndex],i=Math.min(n.totalBits()-n.availableBits(),t);n.untake(i),t-=i,this._availableBits+=i,this._currentBufferIndex>0&&n.totalBits()===n.availableBits()&&(this._depth--,this._currentBufferIndex--)}}async _produceMoreBits(){this._depth++;let e=this._depth>0?Ee([this._value,Uint8Array.from([this._depth])]):this._value,t=await this._hashFn(e),n=new Lf(t);this._buffers.push(n),this._availableBits+=n.availableBits()}},aA=[255,254,252,248,240,224,192,128],cA=[1,3,7,15,31,63,127,255],Lf=class{_value;_currentBytePos;_currentBitPos;constructor(e){this._value=e,this._currentBytePos=e.length-1,this._currentBitPos=7}availableBits(){return this._currentBitPos+1+this._currentBytePos*8}totalBits(){return this._value.length*8}take(e){let t=e,n=0;for(;t>0&&this._haveBits();){let i=this._value[this._currentBytePos],o=this._currentBitPos+1,s=Math.min(o,t),a=lA(i,o-s,s);n=(n<<s)+a,t-=s,this._currentBitPos-=s,this._currentBitPos<0&&(this._currentBitPos=7,this._currentBytePos--)}return n}untake(e){for(this._currentBitPos+=e;this._currentBitPos>7;)this._currentBitPos-=8,this._currentBytePos+=1}_haveBits(){return this._currentBytePos>=0}};function lA(r,e,t){let n=uA(e,t);return(r&n)>>>e}function uA(r,e){return aA[r]&cA[Math.min(e+r-1,7)]}var sa=BigInt(Ni.code),Di=8;async function Mo(r){return(await Ni.encode(r)).subarray(0,8).reverse()}var g2=re(Ul(),1);var hr=async(r,e,t)=>{t.codec==null&&(t.codec=De);let n=await ne.digest(r),i=V.create(t.cidVersion,t.codec.code,n);return await e.put(i,r,{...t,signal:t.signal}),i};var Df=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}},jl=class extends Df{_bucket;constructor(e,t){super(e,t),this._bucket=Lo({hashFn:Mo,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=y2(this._bucket,this,this.options),this.nodeSize)}async*flush(e){for await(let t of m2(this._bucket,e,this,this.options))yield{...t,path:this.path}}};async function*m2(r,e,t,n){let i=r._children,o=[],s=0n;for(let d=0;d<i.length;d++){let f=i.get(d);if(f==null)continue;let m=d.toString(16).toUpperCase().padStart(2,"0");if(f instanceof Ut){let y;for await(let g of m2(f,e,null,n))y=g;if(y==null)throw new Error("Could not flush sharded directory, no subshard found");o.push({Name:m,Tsize:Number(y.size),Hash:y.cid}),s+=y.size}else if(hA(f.value)){let y=f.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=m+f.key;o.push({Name:x,Tsize:Number(g.size),Hash:g.cid}),s+=g.size}else{let y=f.value;if(y.cid==null)continue;let g=m+f.key,x=y.size;o.push({Name:g,Tsize:Number(x),Hash:y.cid}),s+=BigInt(x??0)}}let a=Uint8Array.from(i.bitField().reverse()),c=new W({type:"hamt-sharded-directory",data:a,fanout:BigInt(r.tableSize()),hashType:sa,mtime:t?.mtime,mode:t?.mode}),u={Data:c.marshal(),Links:o},l=le(_e(u)),h=await hr(l,e,n),p=BigInt(l.byteLength)+s;yield{cid:h,unixfs:c,size:p}}function hA(r){return typeof r.flush=="function"}function y2(r,e,t){let n=r._children,i=[];for(let c=0;c<n.length;c++){let u=n.get(c);if(u==null)continue;let l=c.toString(16).toUpperCase().padStart(2,"0");if(u instanceof Ut){let h=y2(u,null,t);i.push({Name:l,Tsize:Number(h),Hash:t.cidVersion===0?Gl:Wl})}else if(typeof u.value.flush=="function"){let p=u.value.nodeSize();i.push({Name:l+u.key,Tsize:Number(p),Hash:t.cidVersion===0?Gl:Wl})}else{let h=u.value;if(h.cid==null)continue;let p=l+u.key,d=h.size;i.push({Name:p,Tsize:Number(d),Hash:h.cid})}}let o=Uint8Array.from(n.bitField().reverse()),s=new W({type:"hamt-sharded-directory",data:o,fanout:BigInt(r.tableSize()),hashType:sa,mtime:e?.mtime,mode:e?.mode});return le(_e({Data:s.marshal(),Links:i})).length}var Gl=V.parse("QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn"),Wl=V.parse("zdj7WbTaiJT1fgatdet9Ei9iDB5hdCxkbVyhyh8YTUnXMiwYi");var Pf=se("helia:unixfs:commands:utils:hamt-utils"),Yl=r=>r.toString(16).toUpperCase().padStart(2,"0").substring(0,2),w2=async(r,e,t)=>{let n=new jl({root:!0,dir:!0,parent:void 0,parentKey:void 0,path:"",dirty:!0,flat:!1,mtime:t.mtime,mode:t.mode},t);for(let o=0;o<e.length;o++)await n._bucket.put(e[o].name,{size:e[o].size,cid:e[o].cid});let i=await ti(n.flush(r));if(i==null)throw new Error("Flushing shard yielded no result");return i},Xl=async(r,e,t)=>{let n=W.unmarshal(r[0].node.Data??new Uint8Array(0)),i=BigInt(Math.pow(2,Di));r.reverse();let o,s;for(let a=0;a<r.length;a++){let c=a===r.length-1,u=r[a],l=Uint8Array.from(u.children.bitField().reverse()),h=new W({type:"hamt-sharded-directory",data:l,fanout:i,hashType:sa});c&&(h.mtime=n.mtime,h.mode=n.mode),s={Data:h.marshal(),Links:u.node.Links};let p=le(_e(s));if(o=await hr(p,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?");Pf("updating link in parent sub-shard with prefix %s",d.prefix),d.node.Links=d.node.Links.filter(f=>f.Name!==d.prefix),d.node.Links.push({Name:d.prefix,Hash:o,Tsize:u.node.Links.reduce((f,m)=>f+(m.Tsize??0),p.byteLength)})}}if(o==null||s==null)throw new Error("Noting persisted");return{cid:o,node:s}},Zl=async(r,e,t,n)=>{let o=ql(Mo)(Y(e)),s=[];for(;;){let a=await t.get(r,n),c=ve(a),u=new g2.default,l=await o.take(Di),h=Yl(l);s.push({prefix:h,children:u,node:c});let p;for(let f of c.Links){let m=f.Name??"";if(m.length<2)throw new Error("Invalid HAMT - link name was too short");let y=parseInt(m.substring(0,2),16);u.set(y,!0),m.startsWith(h)&&(p=f)}if(p==null){Pf("no link found with prefix %s for %s",h,e);break}let d=p.Name??"";if(d.length<2)throw new Error("Invalid HAMT - link name was too short");if(d.length===2){r=p.Hash,Pf("descend into sub-shard with prefix %s",d);continue}break}return{path:s,hash:o}};async function Jl(r,e,t,n){if(r.Data==null)throw new Error("DagPB node had no data");let i=W.unmarshal(r.Data),o;if(i.type==="directory")o=dA(r);else if(i.type==="hamt-sharded-directory")o=await x2(r,0,t,e,n);else throw new Error("Can only estimate the size of directories or shards");return o>t}function dA(r){let e=0;for(let t of r.Links)e+=(t.Name??"").length,e+=t.Hash.version===1?Wl.bytes.byteLength:Gl.bytes.byteLength;return e}async function x2(r,e,t,n,i){if(e>t)return t;if(r.Data==null||!W.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===Te){let c=await n.get(s.Hash,i),u=ve(c);e+=await x2(u,e,t,n,i)}}return e}var Lr=se("helia:unixfs:components:utils:add-link");async function Ho(r,e,t,n){if(r.node.Data==null)throw new it("Invalid parent passed to addLink");if(W.unmarshal(r.node.Data).type==="hamt-sharded-directory")return Lr("adding link to sharded directory"),mA(r,e,t,n);Lr(`adding ${e.Name} (${e.Hash}) to regular directory`);let o=await pA(r,e,t,n);if(await Jl(o.node,t,n.shardSplitThresholdBytes,n)){Lr("converting directory to sharded directory");let s=await fA(o,t);o.cid=s.cid,o.node=ve(await t.get(s.cid,n))}return o}var fA=async(r,e)=>{if(r.node.Data==null)throw new it("Invalid parent passed to convertToShardedDirectory");let t=W.unmarshal(r.node.Data),n=await w2(e,r.node.Links.map(i=>({name:i.Name??"",size:BigInt(i.Tsize??0),cid:i.Hash})),{mode:t.mode,mtime:t.mtime,cidVersion:r.cid.version});return Lr(`converted directory to sharded directory ${n.cid}`),n},pA=async(r,e,t,n)=>{let i=r.node.Links.filter(l=>{let h=l.Name===e.Name;if(h&&!n.allowOverwriting)throw new oa;return!h});if(i.push(e),r.node.Data==null)throw new ut("Parent node with no data passed to addToDirectory");let o=W.unmarshal(r.node.Data),s;if(o.mtime!=null){let l=Date.now(),h=Math.floor(l/1e3);o.mtime={secs:BigInt(h),nsecs:(l-h*1e3)*1e3},s=o.marshal()}else s=r.node.Data;r.node=_e({Data:s,Links:i});let a=le(r.node),c=await ne.digest(a),u=V.create(r.cid.version,Te,c);return await t.put(u,a),{node:r.node,cid:u}},mA=async(r,e,t,n)=>{let{path:i,hash:o}=await Zl(r.cid,e.Name,t,n),s=i[i.length-1];if(s==null)throw new Error("Invalid HAMT, could not generate path");let a=s.prefix,c=parseInt(a,16);Lr("next prefix for %s is %s",e.Name,a);let u=`${a}${e.Name}`,l=s.node.Links.find(h=>(h.Name??"").startsWith(a));if(l!=null)if(Lr("link %s was present in shard",u),l.Name===u){if(!n.allowOverwriting)throw new oa;Lr("overwriting %s in subshard",e.Name),s.node.Links=s.node.Links.filter(h=>h.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?!");{Lr("prefix %s already exists, creating new subshard",a);let h=s.node.Links.findIndex(y=>y.Name?.startsWith(a)),p=s.node.Links.splice(h,1)[0],d=(p.Name??"").substring(2),m=ql(Mo)(Y(d));for(let y=0;y<i.length;y++)await m.take(Di);for(;;){let y=await m.take(Di),g=Yl(y);p.Name=`${g}${d}`;let x=await o.take(Di),b=Yl(x);if(g===b){let I=new Of.default;I.set(x,!0),i.push({prefix:b,children:I,node:{Links:[]}});continue}let A=new Of.default;A.set(x,!0),A.set(y,!0),i.push({prefix:a,children:A,node:{Links:[p,{Name:`${b}${e.Name}`,Hash:e.Hash,Tsize:e.Tsize}]}});break}}}else Lr("link %s was not present in sub-shard",u),e.Name=u,s.node.Links.push(e),s.children.set(c,!0),Lr("adding %s to existing sub-shard",u);return Xl(i,t,n)};async function ni(r,e,t={}){let n=await Xe(r,e,t);if(n.type!=="directory")throw new ri(`${r.toString()} was not a UnixFS directory`);return{cid:r,node:n.node}}async function $o(r,e,t,n){let i=await Xe(r,t,n);if(i.type!=="directory"&&i.type!=="file"&&i.type!=="raw")throw new Ur(`${r.toString()} was not a UnixFS node`);return{Name:e,Tsize:i.node instanceof Uint8Array?i.node.byteLength:yA(i.node),Hash:r}}function yA(r){let e=r.Links.reduce((t,n)=>t+(n.Tsize??0),0);return le(r).byteLength+e}var Ff=se("helia:unixfs:components:utils:resolve");async function Dr(r,e,t,n){if(e==null||e==="")return{cid:r};Ff('resolve "%s" under %c',e,r);let i=e.split("/").filter(Boolean),o=[{name:"",cid:r,size:0n}];for(let s=0;s<i.length;s++){let a=i[s],c=await Xe(r,t,n);if(Ff('resolving "%s"',a,c),c.type==="file"){if(s<i.length-1)throw new it("Path was invalid");r=c.cid}else if(c.type==="directory"){let u;for await(let l of c.content())if(l.name===a){u=l.cid;break}if(u==null)throw new $l("Could not find path in directory");r=u,o.push({name:a,cid:r,size:c.size})}else throw new it("Could not resolve path")}return Ff("resolved %s to %c",e,r),{cid:r,path:e,segments:o}}async function zo(r,e,t,n){if(e.segments==null||e.segments.length===0)return r;let i=e.segments.pop();if(i==null)throw new Error("Insufficient segments");i.cid=r,e.segments.reverse();for(let o of e.segments){let[s,a]=await Promise.all([ni(o.cid,t,n),$o(i.cid,i.name,t,n)]);r=(await Ho(s,a,t,{...n,allowOverwriting:!0,cidVersion:r.version})).cid,o.cid=r,i=o}return r}var gA=nt.bind({ignoreUndefined:!0}),wA={};async function*b2(r,e,t={}){let n=gA(wA,t),i=await Dr(r,n.path,e,n),o=await Xe(i.cid,e,n);if(o.type!=="file"&&o.type!=="raw")throw new zl;if(o.content==null)throw new Vo;yield*o.content(n)}var xA=nt.bind({ignoreUndefined:!0}),bA=se("helia:unixfs:chmod"),EA={recursive:!1,shardSplitThresholdBytes:262144};async function E2(r,e,t,n={}){let i=xA(EA,n),o=await Dr(r,i.path,t,n);if(bA("chmod %c %d",o.cid,e),i.recursive){let p=await Wt(async function*(){for await(let d of Vl(o.cid,t,n)){let f,m=[];if(d.type==="raw")f=new W({type:"file",data:d.node});else if(d.type==="file"||d.type==="directory")f=d.unixfs,m=d.node.Links;else throw new Ur;f.mode=e;let y={Data:f.marshal(),Links:m};yield{path:d.path,content:y}}},d=>ei(d,t,{...i,dagBuilder:async function*(f,m){for await(let y of f)yield async function(){let g=y.content,x=le(g),b=await hr(x,m,{...i,cidVersion:r.version});if(g.Data==null)throw new ut(`${b} had no data`);let A=W.unmarshal(g.Data);return{cid:b,size:BigInt(x.length),path:y.path,unixfs:A}}}}),async d=>ti(d));if(p==null)throw new xn(`Could not chmod ${o.cid.toString()}`);return zo(p.cid,o,t,i)}let s=await t.get(o.cid,n),a,c=[];if(o.cid.code===Ne)a=new W({type:"file",data:s});else{let p=ve(s);if(p.Data==null)throw new ut(`${o.cid.toString()} had no data`);c=p.Links,a=W.unmarshal(p.Data)}a.mode=e;let u=le({Data:a.marshal(),Links:c}),l=await ne.digest(u),h=V.create(o.cid.version,Te,l);return await t.put(h,u),zo(h,o,t,i)}var vA=nt.bind({ignoreUndefined:!0}),BA=se("helia:unixfs:cp"),AA={force:!1,shardSplitThresholdBytes:262144};async function v2(r,e,t,n,i={}){let o=vA(AA,i);if(t.includes("/"))throw new it("Name must not have slashes");let[s,a]=await Promise.all([ni(e,n,o),$o(r,t,n,o)]);return BA('Adding %c as "%s" to %c',r,t,e),(await Ho(s,a,n,{allowOverwriting:o.force,cidVersion:e.version,...o})).cid}var IA=nt.bind({ignoreUndefined:!0}),SA={};async function*B2(r,e,t={}){let n=IA(SA,t),i=await Dr(r,n.path,e,n),o=await Xe(i.cid,e);if(o.type==="file"||o.type==="raw"){yield o;return}if(o.content==null)throw new Vo;if(o.type!=="directory")throw new ri;yield*o.content({offset:t.offset,length:t.length})}var _A=nt.bind({ignoreUndefined:!0}),A2=se("helia:unixfs:mkdir"),kA={cidVersion:1,force:!1,shardSplitThresholdBytes:262144};async function I2(r,e,t,n={}){let i=_A(kA,n);if(e.includes("/"))throw new it("Path must not have slashes");if((await Xe(r,t,n)).type!=="directory")throw new ri(`${r.toString()} was not a UnixFS directory`);A2("creating %s",e);let a={Data:new W({type:"directory",mode:i.mode,mtime:i.mtime}).marshal(),Links:[]},c=le(a),u=await ne.digest(c),l=V.create(i.cidVersion,Te,u);await t.put(l,c);let[h,p]=await Promise.all([ni(r,t,i),$o(l,e,t,i)]);return A2("adding empty dir called %s to %c",e,r),(await Ho(h,p,t,{...i,allowOverwriting:i.force})).cid}var Ql=se("helia:unixfs:utils:remove-link");async function S2(r,e,t,n){if(r.node.Data==null)throw new ut("Parent node had no data");if(W.unmarshal(r.node.Data).type==="hamt-sharded-directory"){Ql(`removing ${e} from sharded directory`);let o=await TA(r,e,t,n);return await Jl(o.node,t,n.shardSplitThresholdBytes,n)?o:(Ql("converting shard to flat directory %c",r.cid),CA(o,t,n))}return Ql(`removing link ${e} regular directory`),RA(r,e,t,n)}var RA=async(r,e,t,n)=>{r.node.Links=r.node.Links.filter(s=>s.Name!==e);let i=le(r.node),o=await hr(i,t,{...n,cidVersion:r.cid.version});return Ql(`Updated regular directory ${o}`),{node:r.node,cid:o}},TA=async(r,e,t,n)=>{let{path:i}=await Zl(r.cid,e,t,n),o=i[i.length-1];if(o==null)throw new Error("Invalid HAMT, could not generate path");let s=o.node.Links.filter(u=>(u.Name??"").substring(2)===e).map(u=>u.Name).pop();if(s==null)throw new Error("File not found");let a=s.substring(0,2),c=parseInt(a,16);if(o.node.Links=o.node.Links.filter(u=>u.Name!==s),o.children.unset(c),o.node.Links.length===1)for(;i.length!==1;){let u=i[i.length-1];if(u==null||u.node.Links.length>1)break;i.pop();let l=i[i.length-1];if(l==null)break;let h=u.node.Links[0];l.node.Links=l.node.Links.filter(p=>!(p.Name??"").startsWith(l.prefix)),l.node.Links.push({Hash:h.Hash,Name:`${l.prefix}${(h.Name??"").substring(2)}`,Tsize:h.Tsize})}return Xl(i,t,n)},CA=async(r,e,t)=>{if(r.node.Data==null)throw new it("Invalid parent passed to convertToFlatDirectory");let n={Links:[]},i=await Xe(r.cid,e);if(i.type!=="directory")throw new Error("Unexpected node type");for await(let c of i.content()){let u=0;c.node instanceof Uint8Array?u=c.node.byteLength:u=le(c.node).length,n.Links.push({Hash:c.cid,Name:c.name,Tsize:u})}let o=W.unmarshal(r.node.Data);n.Data=new W({type:"directory",mode:o.mode,mtime:o.mtime}).marshal();let s=le(_e(n));return{cid:await hr(s,e,{codec:De,cidVersion:r.cid.version,signal:t.signal}),node:n}};var NA=nt.bind({ignoreUndefined:!0}),UA=se("helia:unixfs:rm"),LA={shardSplitThresholdBytes:262144};async function _2(r,e,t,n={}){let i=NA(LA,n);if(e.includes("/"))throw new it("Name must not have slashes");let o=await ni(r,t,i);return UA("Removing %s from %c",e,r),(await S2(o,e,t,{...i,cidVersion:r.version})).cid}var DA=nt.bind({ignoreUndefined:!0}),PA=se("helia:unixfs:stat"),OA={};async function k2(r,e,t={}){let n=DA(OA,t),i=await Dr(r,t.path,e,n);PA("stat %c",i.cid);let o=await Xe(i.cid,e,n);if(o.type!=="file"&&o.type!=="directory"&&o.type!=="raw")throw new Ur;let s=0n,a=0n,c=0n,u=0n,l=0,h,p,d=o.type,f;if(o.type==="raw"&&(s=BigInt(o.node.byteLength),a=BigInt(o.node.byteLength),c=BigInt(o.node.byteLength),u=BigInt(o.node.byteLength),l=1),o.type==="directory"&&(s=0n,a=BigInt(o.unixfs.marshal().byteLength),c=0n,u=a,l=1,h=o.unixfs.mode,p=o.unixfs.mtime,f=o.unixfs),o.type==="file"){let m=await R2(i.cid,e,n);s=o.unixfs.fileSize(),a=BigInt((o.node.Data?.byteLength??0)+o.node.Links.reduce((y,g)=>y+(g.Tsize??0),0)),c=BigInt(m.localFileSize),u=BigInt(m.localDagSize),l=m.blocks,h=o.unixfs.mode,p=o.unixfs.mtime,f=o.unixfs}return{cid:i.cid,mode:h,mtime:p,fileSize:s,dagSize:a,localFileSize:c,localDagSize:u,blocks:l,type:d,unixfs:f}}async function R2(r,e,t){let n={localFileSize:0,localDagSize:0,blocks:0};if(await e.has(r,t)){let i=await e.get(r,t);if(n.blocks++,n.localDagSize+=i.byteLength,r.code===Ne)n.localFileSize+=i.byteLength;else if(r.code===Te){let o=ve(i);if(o.Links.length>0)for(let s of o.Links){let a=await R2(s.Hash,e,t);n.localFileSize+=a.localFileSize,n.localDagSize+=a.localDagSize,n.blocks+=a.blocks}else{if(o.Data==null)throw new ut(`PBNode ${r.toString()} had no data`);let s=W.unmarshal(o.Data);if(s.data==null)throw new ut(`UnixFS node ${r.toString()} had no data`);n.localFileSize+=s.data.byteLength??0}}else throw new xn(`${r.toString()} was neither DAG_PB nor RAW`)}return n}var FA=nt.bind({ignoreUndefined:!0}),VA=se("helia:unixfs:touch"),MA={recursive:!1,shardSplitThresholdBytes:262144};async function T2(r,e,t={}){let n=FA(MA,t),i=await Dr(r,n.path,e,n),o=n.mtime??{secs:BigInt(Math.round(Date.now()/1e3)),nsecs:0};if(VA("touch %c %o",i.cid,o),n.recursive){let p=await Wt(async function*(){for await(let d of Vl(i.cid,e)){let f,m;if(d.type==="raw")f=new W({data:d.node}),m=[];else if(d.type==="file"||d.type==="directory")f=d.unixfs,m=d.node.Links;else throw new Ur;f.mtime=o;let y={Data:f.marshal(),Links:m};yield{path:d.path,content:y}}},d=>ei(d,e,{...n,dagBuilder:async function*(f,m){for await(let y of f)yield async function(){let g=y.content,x=le(g),b=await hr(x,m,{...n,cidVersion:r.version});if(g.Data==null)throw new ut(`${b} had no data`);let A=W.unmarshal(g.Data);return{cid:b,size:BigInt(x.length),path:y.path,unixfs:A}}}}),async d=>ti(d));if(p==null)throw new xn(`Could not chmod ${i.cid.toString()}`);return zo(p.cid,i,e,n)}let s=await e.get(i.cid,t),a,c=[];if(i.cid.code===Ne)a=new W({data:s});else{let p=ve(s);if(c=p.Links,p.Data==null)throw new ut(`${i.cid.toString()} had no data`);a=W.unmarshal(p.Data)}a.mtime=o;let u=le({Data:a.marshal(),Links:c}),l=await ne.digest(u),h=V.create(i.cid.version,Te,l);return await e.put(h,u),zo(h,i,e,n)}var Vf=class{components;constructor(e){this.components=e}async*addAll(e,t={}){yield*Pw(e,this.components.blockstore,t)}async addBytes(e,t={}){return Ow(e,this.components.blockstore,t)}async addByteStream(e,t={}){return Fw(e,this.components.blockstore,t)}async addFile(e,t={}){return Vw(e,this.components.blockstore,t)}async addDirectory(e={},t={}){return Mw(e,this.components.blockstore,t)}async*cat(e,t={}){yield*b2(e,this.components.blockstore,t)}async chmod(e,t,n={}){return E2(e,t,this.components.blockstore,n)}async cp(e,t,n,i={}){return v2(e,t,n,this.components.blockstore,i)}async*ls(e,t={}){yield*B2(e,this.components.blockstore,t)}async mkdir(e,t,n={}){return I2(e,t,this.components.blockstore,n)}async rm(e,t,n={}){return _2(e,t,this.components.blockstore,n)}async stat(e,t={}){return k2(e,this.components.blockstore,t)}async touch(e,t={}){return T2(e,this.components.blockstore,t)}};function C2(r){return new Vf(r)}async function N2(r,e,t,n){let i=t.forComponent("helia:verified-fetch:get-stream-from-async-iterable"),o=r[Symbol.asyncIterator](),{value:s,done:a}=await o.next();if(a===!0)throw i.error("No content found for path",e),new Error("No content found");return{stream:new ReadableStream({async start(u){n?.onProgress?.(new P("verified-fetch:request:progress:chunk")),u.enqueue(s)},async pull(u){let{value:l,done:h}=await o.next();if(h===!0){l!=null&&(n?.onProgress?.(new P("verified-fetch:request:progress:chunk")),u.enqueue(l)),u.close();return}n?.onProgress?.(new P("verified-fetch:request:progress:chunk")),u.enqueue(l)}}),firstChunk:s}}var U2=re(jd(),1),eu=class{lru;constructor(e){this.lru=(0,U2.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 Mf=new eu(1e3),HA=/^(?<protocol>ip[fn]s):\/\/(?<cidOrPeerIdOrDnsLink>[^/$?]+)\/?(?<path>[^$?]*)\??(?<queryString>.*)$/;async function L2({urlString:r,ipns:e,logger:t},n){let i=t.forComponent("helia:verified-fetch:parse-url-string"),o=r.match(HA);if(o==null||o.groups==null)throw new TypeError(`Invalid URL: ${r}, please use ipfs:// or ipns:// URLs only.`);let{protocol:s,cidOrPeerIdOrDnsLink:a,path:c,queryString:u}=o.groups,l,h,p=[];if(s==="ipfs")try{l=V.parse(a)}catch(y){i.error(y),p.push(new TypeError("Invalid CID for ipfs://<cid> URL"))}else{let y=Mf.get(a);if(y!=null)l=y.cid,h=y.path,i.trace("resolved %s to %c from cache",a,l);else{i.trace("Attempting to resolve PeerId for %s",a);let g=null;try{g=Yt(a),y=await e.resolve(g,{onProgress:n?.onProgress}),l=y?.cid,h=y?.path,i.trace("resolved %s to %c",a,l),Mf.set(a,y,60*1e3*2)}catch(x){g==null?(i.error('Could not parse PeerId string "%s"',a,x),p.push(new TypeError(`Could not parse PeerId in ipns url "${a}", ${x.message}`))):(i.error("Could not resolve PeerId %c",g,x),p.push(new TypeError(`Could not resolve PeerId "${a}", ${x.message}`)))}if(l==null){i.trace("Attempting to resolve DNSLink for %s",a);try{y=await e.resolveDns(a,{onProgress:n?.onProgress}),l=y?.cid,h=y?.path,i.trace("resolved %s to %c",a,l),Mf.set(a,y,60*1e3*2)}catch(x){i.error('Could not resolve DnsLink for "%s"',a,x),p.push(x)}}}}if(l==null)throw new AggregateError(p,`Invalid resource. Cannot determine CID from URL "${r}"`);let d={};if(u!=null&&u.length>0){let y=u.split("&");for(let g of y){let[x,b]=g.split("=");d[x]=decodeURIComponent(b)}}let f=[];c.length>0&&f.push(c),h!=null&&h.length>0&&f.push(h);let m=f.join("/");return{protocol:s,cid:l,path:m,query:d}}async function D2(r,{ipns:e,logger:t},n){if(typeof r=="string")return L2({urlString:r,ipns:e,logger:t},{onProgress:n?.onProgress});let i=V.asCID(r);if(i!=null)return{cid:i,protocol:"ipfs",path:"",query:{}};throw new TypeError(`Invalid resource. Cannot determine CID from resource: ${r}`)}async function P2(r,e,t){let n=[],i;for await(let o of Nf(e,r,t))n.push(o.cid),i=o;if(i==null)throw new Error("No terminal element found");return{ipfsRoots:n,terminalElement:i}}function $A(r){if(r==null)return;let e;return r?.signal===null&&(e=void 0),{...r,signal:e}}function aa(r){return new Response(r,{status:200,statusText:"OK"})}function Pr(r){return new Response(r,{status:501,statusText:"Not Implemented"})}var tu=class{helia;ipns;unixfs;dagJson;dagCbor;json;pathWalker;log;contentTypeParser;constructor({helia:e,ipns:t,unixfs:n,dagJson:i,json:o,dagCbor:s,pathWalker:a},c){this.helia=e,this.log=e.logger.forComponent("helia:verified-fetch"),this.ipns=t??yg(e,{resolvers:[Rl("https://mozilla.cloudflare-dns.com/dns-query"),Rl("https://dns.google/resolve")]}),this.unixfs=n??C2(e),this.dagJson=i??Zy(e),this.json=o??Wg(e),this.dagCbor=s??Xy(e),this.pathWalker=a??P2,this.contentTypeParser=c?.contentTypeParser,this.log.trace("created VerifiedFetch instance")}async handleIPNSRecord({cid:e,path:t,options:n}){let i=Pr("vnd.ipfs.ipns-record support is not implemented");return i.headers.set("X-Content-Type-Options","nosniff"),i}async handleIPLDCar({cid:e,path:t,options:n}){let i=Pr("vnd.ipld.car support is not implemented");return i.headers.set("X-Content-Type-Options","nosniff"),i}async handleDagJson({cid:e,path:t,options:n}){this.log.trace("fetching %c/%s",e,t),n?.onProgress?.(new P("verified-fetch:request:start",{cid:e,path:t}));let i=await this.dagJson.get(e,{signal:n?.signal,onProgress:n?.onProgress});n?.onProgress?.(new P("verified-fetch:request:end",{cid:e,path:t}));let o=aa(JSON.stringify(i));return o.headers.set("content-type","application/json"),o}async handleJson({cid:e,path:t,options:n}){this.log.trace("fetching %c/%s",e,t),n?.onProgress?.(new P("verified-fetch:request:start",{cid:e,path:t}));let i=await this.json.get(e,{signal:n?.signal,onProgress:n?.onProgress});n?.onProgress?.(new P("verified-fetch:request:end",{cid:e,path:t}));let o=aa(JSON.stringify(i));return o.headers.set("content-type","application/json"),o}async handleDagCbor({cid:e,path:t,options:n}){this.log.trace("fetching %c/%s",e,t),n?.onProgress?.(new P("verified-fetch:request:start",{cid:e,path:t}));let i=await this.dagCbor.get(e,{signal:n?.signal,onProgress:n?.onProgress});n?.onProgress?.(new P("verified-fetch:request:end",{cid:e,path:t}));let o=aa(JSON.stringify(i));return await this.setContentType(i,t,o),o}async handleDagPb({cid:e,path:t,options:n,terminalElement:i}){this.log.trace("fetching %c/%s",e,t);let o=i?.cid??e,s;if(i?.type==="directory"){let h=i.cid,p="index.html";try{this.log.trace("found directory at %c/%s, looking for index.html",e,t),n?.onProgress?.(new P("verified-fetch:request:start",{cid:h,path:p})),s=await this.unixfs.stat(h,{path:p,signal:n?.signal,onProgress:n?.onProgress}),this.log.trace("found root file at %c/%s with cid %c",h,p,s.cid),t=p,o=s.cid}catch(d){return this.log("error loading path %c/%s",h,p,d),Pr("Unable to find index.html for directory at given path. Support for directories with implicit root is not implemented")}finally{n?.onProgress?.(new P("verified-fetch:request:end",{cid:h,path:p}))}}n?.onProgress?.(new P("verified-fetch:request:start",{cid:o,path:""}));let a=this.unixfs.cat(o,{signal:n?.signal,onProgress:n?.onProgress});n?.onProgress?.(new P("verified-fetch:request:end",{cid:o,path:""})),this.log("got async iterator for %c/%s",e,t);let{stream:c,firstChunk:u}=await N2(a,t??"",this.helia.logger,{onProgress:n?.onProgress}),l=aa(c);return await this.setContentType(u,t,l),l}async handleRaw({cid:e,path:t,options:n}){this.log.trace("fetching %c/%s",e,t),n?.onProgress?.(new P("verified-fetch:request:start",{cid:e,path:t}));let i=await this.helia.blockstore.get(e);n?.onProgress?.(new P("verified-fetch:request:end",{cid:e,path:t}));let o=aa($u(i));return await this.setContentType(i,t,o),o}async setContentType(e,t,n){let i="application/octet-stream";if(this.contentTypeParser!=null)try{let o=t.split("/").pop()?.trim();o=o===""?void 0:o;let s=this.contentTypeParser(e,o);if(zA(s)){let a=await s;a!=null&&(i=a)}else s!=null&&(i=s)}catch(o){this.log.error("Error parsing content type",o)}n.headers.set("content-type",i)}getFormat({headerFormat:e,queryFormat:t}){let n={"vnd.ipld.raw":"raw","vnd.ipld.car":"car","application/x-tar":"tar","application/vnd.ipld.dag-json":"dag-json","application/vnd.ipld.dag-cbor":"dag-cbor","application/json":"json","application/cbor":"cbor","vnd.ipfs.ipns-record":"ipns-record"};if(e!=null){for(let i in n)if(e.includes(i))return n[i]}else if(t!=null)return t;return null}formatHandlers={raw:async()=>Pr("application/vnd.ipld.raw support is not implemented"),car:this.handleIPLDCar,"ipns-record":this.handleIPNSRecord,tar:async()=>Pr("application/x-tar support is not implemented"),"dag-json":async()=>Pr("application/vnd.ipld.dag-json support is not implemented"),"dag-cbor":async()=>Pr("application/vnd.ipld.dag-cbor support is not implemented"),json:async()=>Pr("application/json support is not implemented"),cbor:async()=>Pr("application/cbor support is not implemented")};codecHandlers={[Wn]:this.handleDagJson,[Te]:this.handleDagPb,[kn]:this.handleJson,[jn]:this.handleDagCbor,[Ne]:this.handleRaw,[et.code]:this.handleRaw};async fetch(e,t){let n=$A(t),{path:i,query:o,...s}=await D2(e,{ipns:this.ipns,logger:this.helia.logger},n),a=s.cid,c,u=this.getFormat({headerFormat:new Headers(n?.headers).get("accept"),queryFormat:o.format??null});if(u!=null){let p=this.formatHandlers[u];if(p!=null&&(c=await p.call(this,{cid:a,path:i,options:n}),c.status===501))return c}let l,h;try{let p=await this.pathWalker(this.helia.blockstore,`${a.toString()}/${i}`,n);h=p.ipfsRoots,l=p.terminalElement}catch(p){this.log.error("Error walking path %s",i,p)}if(c==null){let p=this.codecHandlers[a.code];if(p!=null)c=await p.call(this,{cid:a,path:i,options:n,terminalElement:l});else return Pr(`Support for codec with code ${a.code} is not yet implemented. Please open an issue at https://github.com/ipfs/helia/issues/new`)}return c.headers.set("etag",a.toString()),c.headers.set("cache-cotrol","public, max-age=29030400, immutable"),c.headers.set("X-Ipfs-Path",e.toString()),h!=null&&c.headers.set("X-Ipfs-Roots",h.map(p=>p.toV1().toString()).join(",")),c}async start(){await this.helia.start()}async stop(){await this.helia.stop()}};function zA(r){return r?.then!=null}var ca,ru=async function(e,t){return ca==null&&(ca=await Hf()),ca(e,t)};ru.start=async function(){await ca?.start()};ru.stop=async function(){await ca?.stop()};async function Hf(r,e){let t=e?.contentTypeParser;KA(r)||(r=await Yy({blockBrokers:[Qo({gateways:r?.gateways})],routers:(r?.routers??["https://delegated-ipfs.dev"]).map(o=>Us(o))}));let n=new tu({helia:r},{contentTypeParser:t});async function i(o,s){return n.fetch(o,s)}return i.stop=n.stop.bind(n),i.start=n.start.bind(n),i}function KA(r){return r?.blockstore!=null&&r?.datastore!=null&&r?.gc!=null&&r?.stop!=null&&r?.start!=null}return X2(qA);})();
|
|
7
|
+
`)}`:`${t} :`}};Cp=Ln;$.Constructed=Cp;Ln.NAME="CONSTRUCTED";var Za=class extends tt{fromBER(e,t,n){return t}toBER(e){return er}};Za.override="EndOfContentValueBlock";var Np,Ja=class extends Ge{constructor(e={}){super(e,Za),this.idBlock.tagClass=1,this.idBlock.tagNumber=0}};Np=Ja;$.EndOfContent=Np;Ja.NAME=ss;var Up,Dn=class extends Ge{constructor(e={}){super(e,tt),this.idBlock.tagClass=1,this.idBlock.tagNumber=5}fromBER(e,t,n){return this.lenBlock.length>0&&this.warnings.push("Non-zero length of value block for Null type"),this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.blockLength+=n,t+n>e.byteLength?(this.error="End of input reached before message was fully decoded (inconsistent offset and length values)",-1):t+n}toBER(e,t){let n=new ArrayBuffer(2);if(!e){let i=new Uint8Array(n);i[0]=5,i[1]=0}return t&&t.write(n),n}onAsciiEncoding(){return`${this.constructor.NAME}`}};Up=Dn;$.Null=Up;Dn.NAME="NULL";var Qa=class extends Zr(tt){constructor({value:e,...t}={}){super(t),t.valueHex?this.valueHexView=se.BufferSourceConverter.toUint8Array(t.valueHex):this.valueHexView=new Uint8Array(1),e&&(this.value=e)}get value(){for(let e of this.valueHexView)if(e>0)return!0;return!1}set value(e){this.valueHexView[0]=e?255:0}fromBER(e,t,n){let i=se.BufferSourceConverter.toUint8Array(e);return Xr(this,i,t,n)?(this.valueHexView=i.subarray(t,t+n),n>1&&this.warnings.push("Boolean value encoded in more then 1 octet"),this.isHexOnly=!0,_h.call(this),this.blockLength=n,t+n):-1}toBER(){return this.valueHexView.slice()}toJSON(){return{...super.toJSON(),value:this.value}}};Qa.NAME="BooleanValueBlock";var Lp,ec=class extends Ge{constructor(e={}){super(e,Qa),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}`}};Lp=ec;$.Boolean=Lp;ec.NAME="BOOLEAN";var tc=class extends Zr(yr){constructor({isConstructed:e=!1,...t}={}){super(t),this.isConstructed=e}fromBER(e,t,n){let i=0;if(this.isConstructed){if(this.isHexOnly=!1,i=yr.prototype.fromBER.call(this,e,t,n),i===-1)return i;for(let o=0;o<this.value.length;o++){let s=this.value[o].constructor.NAME;if(s===ss){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, OCTET STRING may consists of OCTET STRINGs only",-1}if(s!==_p)return this.error="OCTET STRING may consists of OCTET STRINGs only",-1}}else this.isHexOnly=!0,i=super.fromBER(e,t,n),this.blockLength=n;return i}toBER(e,t){return this.isConstructed?yr.prototype.toBER.call(this,e,t):e?new ArrayBuffer(this.valueHexView.byteLength):this.valueHexView.slice().buffer}toJSON(){return{...super.toJSON(),isConstructed:this.isConstructed}}};tc.NAME="OctetStringValueBlock";var Dp,Wr=class r extends Ge{constructor({idBlock:e={},lenBlock:t={},...n}={}){var i,o;(i=n.isConstructed)!==null&&i!==void 0||(n.isConstructed=!!(!((o=n.value)===null||o===void 0)&&o.length)),super({idBlock:{isConstructed:n.isConstructed,...e},lenBlock:{...t,isIndefiniteForm:!!n.isIndefiniteForm},...n},tc),this.idBlock.tagClass=1,this.idBlock.tagNumber=4}fromBER(e,t,n){if(this.valueBlock.isConstructed=this.idBlock.isConstructed,this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm,n===0)return this.idBlock.error.length===0&&(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length===0&&(this.blockLength+=this.lenBlock.blockLength),t;if(!this.valueBlock.isConstructed){let o=(e instanceof ArrayBuffer?new Uint8Array(e):e).subarray(t,t+n);try{if(o.byteLength){let s=Rc(o,0,o.byteLength);s.offset!==-1&&s.offset===n&&(this.valueBlock.value=[s.result])}}catch{}}return super.fromBER(e,t,n)}onAsciiEncoding(){return this.valueBlock.isConstructed||this.valueBlock.value&&this.valueBlock.value.length?Ln.prototype.onAsciiEncoding.call(this):`${this.constructor.NAME} : ${se.Convert.ToHex(this.valueBlock.valueHexView)}`}getValue(){if(!this.idBlock.isConstructed)return this.valueBlock.valueHexView.slice().buffer;let e=[];for(let t of this.valueBlock.value)t instanceof r&&e.push(t.valueBlock.valueHexView);return se.BufferSourceConverter.concat(e)}};Dp=Wr;$.OctetString=Dp;Wr.NAME=_p;var rc=class extends Zr(yr){constructor({unusedBits:e=0,isConstructed:t=!1,...n}={}){super(n),this.unusedBits=e,this.isConstructed=t,this.blockLength=this.valueHexView.byteLength}fromBER(e,t,n){if(!n)return t;let i=-1;if(this.isConstructed){if(i=yr.prototype.fromBER.call(this,e,t,n),i===-1)return i;for(let a of this.value){let c=a.constructor.NAME;if(c===ss){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, BIT STRING may consists of BIT STRINGs only",-1}if(c!==kp)return this.error="BIT STRING may consists of BIT STRINGs only",-1;let u=a.valueBlock;if(this.unusedBits>0&&u.unusedBits>0)return this.error='Using of "unused bits" inside constructive BIT STRING allowed for least one only',-1;this.unusedBits=u.unusedBits}return i}let o=se.BufferSourceConverter.toUint8Array(e);if(!Xr(this,o,t,n))return-1;let s=o.subarray(t,t+n);if(this.unusedBits=s[0],this.unusedBits>7)return this.error="Unused bits for BitString must be in range 0-7",-1;if(!this.unusedBits){let a=s.subarray(1);try{if(a.byteLength){let c=Rc(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 yr.prototype.toBER.call(this,e,t);if(e)return new ArrayBuffer(this.valueHexView.byteLength+1);if(!this.valueHexView.byteLength)return er;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}}};rc.NAME="BitStringValueBlock";var Pp,co=class extends Ge{constructor({idBlock:e={},lenBlock:t={},...n}={}){var i,o;(i=n.isConstructed)!==null&&i!==void 0||(n.isConstructed=!!(!((o=n.value)===null||o===void 0)&&o.length)),super({idBlock:{isConstructed:n.isConstructed,...e},lenBlock:{...t,isIndefiniteForm:!!n.isIndefiniteForm},...n},rc),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 Ln.prototype.onAsciiEncoding.call(this);{let e=[],t=this.valueBlock.valueHexView;for(let i of t)e.push(i.toString(2).padStart(8,"0"));let n=e.join("");return`${this.constructor.NAME} : ${n.substring(0,n.length-this.valueBlock.unusedBits)}`}}};Pp=co;$.BitString=Pp;co.NAME=kp;var Op;function _3(r,e){let t=new Uint8Array([0]),n=new Uint8Array(r),i=new Uint8Array(e),o=n.slice(0),s=o.length-1,a=i.slice(0),c=a.length-1,u=0,l=c<s?s:c,h=0;for(let p=l;p>=0;p--,h++){switch(!0){case h<a.length:u=o[s-h]+a[c-h]+t[0];break;default:u=o[s-h]+t[0]}switch(t[0]=u/10,!0){case h>=o.length:o=Ka(new Uint8Array([u%10]),o);break;default:o[s-h]=u%10}}return t[0]>0&&(o=Ka(t,o)),o}function Sp(r){if(r>=is.length)for(let e=is.length;e<=r;e++){let t=new Uint8Array([0]),n=is[e-1].slice(0);for(let i=n.length-1;i>=0;i--){let o=new Uint8Array([(n[i]<<1)+t[0]]);t[0]=o[0]/10,n[i]=o[0]%10}t[0]>0&&(n=Ka(t,n)),is.push(n)}return is[r]}function k3(r,e){let t=0,n=new Uint8Array(r),i=new Uint8Array(e),o=n.slice(0),s=o.length-1,a=i.slice(0),c=a.length-1,u,l=0;for(let h=c;h>=0;h--,l++)switch(u=o[s-l]-a[c-l]-t,!0){case u<0:t=1,o[s-l]=u+10;break;default:t=0,o[s-l]=u}if(t>0)for(let h=s-c+1;h>=0;h--,l++)if(u=o[s-l]-t,u<0)t=1,o[s-l]=u+10;else{t=0,o[s-l]=u;break}return o.slice()}var as=class extends Zr(tt){constructor({value:e,...t}={}){super(t),this._valueDec=0,t.valueHex&&this.setValueHex(),e!==void 0&&(this.valueDec=e)}setValueHex(){this.valueHexView.length>=4?(this.warnings.push("Too big Integer for decoding, hex only"),this.isHexOnly=!0,this._valueDec=0):(this.isHexOnly=!1,this.valueHexView.length>0&&(this._valueDec=_h.call(this)))}set valueDec(e){this._valueDec=e,this.isHexOnly=!1,this.valueHexView=new Uint8Array(Bp(e))}get valueDec(){return this._valueDec}fromDER(e,t,n,i=0){let o=this.fromBER(e,t,n);if(o===-1)return o;let s=this.valueHexView;return s[0]===0&&s[1]&128?this.valueHexView=s.subarray(1):i!==0&&s.length<i&&(i-s.length>1&&(i=s.length+1),this.valueHexView=s.subarray(i-s.length)),o}toDER(e=!1){let t=this.valueHexView;switch(!0){case(t[0]&128)!==0:{let n=new Uint8Array(this.valueHexView.length+1);n[0]=0,n.set(t,1),this.valueHexView=n}break;case(t[0]===0&&(t[1]&128)===0):this.valueHexView=this.valueHexView.subarray(1);break}return this.toBER(e)}fromBER(e,t,n){let i=super.fromBER(e,t,n);return i===-1||this.setValueHex(),i}toBER(e){return e?new ArrayBuffer(this.valueHexView.length):this.valueHexView.slice().buffer}toJSON(){return{...super.toJSON(),valueDec:this.valueDec}}toString(){let e=this.valueHexView.length*8-1,t=new Uint8Array(this.valueHexView.length*8/3),n=0,i,o=this.valueHexView,s="",a=!1;for(let c=o.byteLength-1;c>=0;c--){i=o[c];for(let u=0;u<8;u++){if((i&1)===1)switch(n){case e:t=k3(Sp(n),t),s="-";break;default:t=_3(t,Sp(n))}n++,i>>=1}}for(let c=0;c<t.length;c++)t[c]&&(a=!0),a&&(s+=Ip.charAt(t[c]));return a===!1&&(s+=Ip.charAt(0)),s}};Op=as;as.NAME="IntegerValueBlock";Object.defineProperty(Op.prototype,"valueHex",{set:function(r){this.valueHexView=new Uint8Array(r),this.setValueHex()},get:function(){return this.valueHexView.slice().buffer}});var Fp,Le=class r extends Ge{constructor(e={}){super(e,as),this.idBlock.tagClass=1,this.idBlock.tagNumber=2}toBigInt(){return qa(),BigInt(this.valueBlock.toString())}static fromBigInt(e){qa();let t=BigInt(e),n=new os,i=t.toString(16).replace(/^-/,""),o=new Uint8Array(se.Convert.FromHex(i));if(t<0){let a=new Uint8Array(o.length+(o[0]&128?1:0));a[0]|=128;let u=BigInt(`0x${se.Convert.ToHex(a)}`)+t,l=se.BufferSourceConverter.toUint8Array(se.Convert.FromHex(u.toString(16)));l[0]|=128,n.write(l)}else o[0]&128&&n.write(new Uint8Array([0])),n.write(o);return new r({valueHex:n.final()})}convertToDER(){let e=new r({valueHex:this.valueBlock.valueHexView});return e.valueBlock.toDER(),e}convertFromDER(){return new r({valueHex:this.valueBlock.valueHexView[0]===0?this.valueBlock.valueHexView.subarray(1):this.valueBlock.valueHexView})}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()}`}};Fp=Le;$.Integer=Fp;Le.NAME="INTEGER";var Vp,nc=class extends Le{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=10}};Vp=nc;$.Enumerated=Vp;nc.NAME="ENUMERATED";var cs=class extends Zr(tt){constructor({valueDec:e=-1,isFirstSid:t=!1,...n}={}){super(n),this.valueDec=e,this.isFirstSid=t}fromBER(e,t,n){if(!n)return t;let i=se.BufferSourceConverter.toUint8Array(e);if(!Xr(this,i,t,n))return-1;let o=i.subarray(t,t+n);this.valueHexView=new Uint8Array(n);for(let a=0;a<n&&(this.valueHexView[a]=o[a]&127,this.blockLength++,!!(o[a]&128));a++);let s=new Uint8Array(this.blockLength);for(let a=0;a<this.blockLength;a++)s[a]=this.valueHexView[a];return this.valueHexView=s,o[this.blockLength-1]&128?(this.error="End of input reached before message was fully decoded",-1):(this.valueHexView[0]===0&&this.warnings.push("Needlessly long format of SID encoding"),this.blockLength<=8?this.valueDec=fi(this.valueHexView,7):(this.isHexOnly=!0,this.warnings.push("Too big SID for decoding, hex only")),t+this.blockLength)}set valueBigInt(e){qa();let t=BigInt(e).toString(2);for(;t.length%7;)t="0"+t;let n=new Uint8Array(t.length/7);for(let i=0;i<n.length;i++)n[i]=parseInt(t.slice(i*7,i*7+7),2)+(i+1<n.length?128:0);this.fromBER(n.buffer,0,n.length)}toBER(e){if(this.isHexOnly){if(e)return new ArrayBuffer(this.valueHexView.byteLength);let i=this.valueHexView,o=new Uint8Array(this.blockLength);for(let s=0;s<this.blockLength-1;s++)o[s]=i[s]|128;return o[this.blockLength-1]=i[this.blockLength-1],o.buffer}let t=Un(this.valueDec,7);if(t.byteLength===0)return this.error="Error during encoding SID value",er;let n=new Uint8Array(t.byteLength);if(!e){let i=new Uint8Array(t),o=t.byteLength-1;for(let s=0;s<o;s++)n[s]=i[s]|128;n[o]=i[o]}return n}toString(){let e="";if(this.isHexOnly)e=se.Convert.ToHex(this.valueHexView);else if(this.isFirstSid){let t=this.valueDec;this.valueDec<=39?e="0.":this.valueDec<=79?(e="1.",t-=40):(e="2.",t-=80),e+=t.toString()}else e=this.valueDec.toString();return e}toJSON(){return{...super.toJSON(),valueDec:this.valueDec,isFirstSid:this.isFirstSid}}};cs.NAME="sidBlock";var ic=class extends tt{constructor({value:e=lo,...t}={}){super(t),this.value=[],e&&this.fromString(e)}fromBER(e,t,n){let i=t;for(;n>0;){let o=new cs;if(i=o.fromBER(e,i,n),i===-1)return this.blockLength=0,this.error=o.error,i;this.value.length===0&&(o.isFirstSid=!0),this.blockLength+=o.blockLength,n-=o.blockLength,this.value.push(o)}return i}toBER(e){let t=[];for(let n=0;n<this.value.length;n++){let i=this.value[n].toBER(e);if(i.byteLength===0)return this.error=this.value[n].error,er;t.push(i)}return kh(t)}fromString(e){this.value=[];let t=0,n=0,i="",o=!1;do if(n=e.indexOf(".",t),n===-1?i=e.substring(t):i=e.substring(t,n),t=n+1,o){let s=this.value[0],a=0;switch(s.valueDec){case 0:break;case 1:a=40;break;case 2:a=80;break;default:this.value=[];return}let c=parseInt(i,10);if(isNaN(c))return;s.valueDec=c+a,o=!1}else{let s=new cs;if(i>Number.MAX_SAFE_INTEGER){qa();let a=BigInt(i);s.valueBigInt=a}else if(s.valueDec=parseInt(i,10),isNaN(s.valueDec))return;this.value.length||(s.isFirstSid=!0,o=!0),this.value.push(s)}while(n!==-1)}toString(){let e="",t=!1;for(let n=0;n<this.value.length;n++){t=this.value[n].isHexOnly;let i=this.value[n].toString();n!==0&&(e=`${e}.`),t?(i=`{${i}}`,this.value[n].isFirstSid?e=`2.{${i} - 80}`:e+=i):e+=i}return e}toJSON(){let e={...super.toJSON(),value:this.toString(),sidArray:[]};for(let t=0;t<this.value.length;t++)e.sidArray.push(this.value[t].toJSON());return e}};ic.NAME="ObjectIdentifierValueBlock";var Mp,Qt=class extends Ge{constructor(e={}){super(e,ic),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()}}};Mp=Qt;$.ObjectIdentifier=Mp;Qt.NAME="OBJECT IDENTIFIER";var ls=class extends Zr(jr){constructor({valueDec:e=0,...t}={}){super(t),this.valueDec=e}fromBER(e,t,n){if(n===0)return t;let i=se.BufferSourceConverter.toUint8Array(e);if(!Xr(this,i,t,n))return-1;let o=i.subarray(t,t+n);this.valueHexView=new Uint8Array(n);for(let a=0;a<n&&(this.valueHexView[a]=o[a]&127,this.blockLength++,!!(o[a]&128));a++);let s=new Uint8Array(this.blockLength);for(let a=0;a<this.blockLength;a++)s[a]=this.valueHexView[a];return this.valueHexView=s,o[this.blockLength-1]&128?(this.error="End of input reached before message was fully decoded",-1):(this.valueHexView[0]===0&&this.warnings.push("Needlessly long format of SID encoding"),this.blockLength<=8?this.valueDec=fi(this.valueHexView,7):(this.isHexOnly=!0,this.warnings.push("Too big SID for decoding, hex only")),t+this.blockLength)}toBER(e){if(this.isHexOnly){if(e)return new ArrayBuffer(this.valueHexView.byteLength);let i=this.valueHexView,o=new Uint8Array(this.blockLength);for(let s=0;s<this.blockLength-1;s++)o[s]=i[s]|128;return o[this.blockLength-1]=i[this.blockLength-1],o.buffer}let t=Un(this.valueDec,7);if(t.byteLength===0)return this.error="Error during encoding SID value",er;let n=new Uint8Array(t.byteLength);if(!e){let i=new Uint8Array(t),o=t.byteLength-1;for(let s=0;s<o;s++)n[s]=i[s]|128;n[o]=i[o]}return n.buffer}toString(){let e="";return this.isHexOnly?e=se.Convert.ToHex(this.valueHexView):e=this.valueDec.toString(),e}toJSON(){return{...super.toJSON(),valueDec:this.valueDec}}};ls.NAME="relativeSidBlock";var oc=class extends tt{constructor({value:e=lo,...t}={}){super(t),this.value=[],e&&this.fromString(e)}fromBER(e,t,n){let i=t;for(;n>0;){let o=new ls;if(i=o.fromBER(e,i,n),i===-1)return this.blockLength=0,this.error=o.error,i;this.blockLength+=o.blockLength,n-=o.blockLength,this.value.push(o)}return i}toBER(e,t){let n=[];for(let i=0;i<this.value.length;i++){let o=this.value[i].toBER(e);if(o.byteLength===0)return this.error=this.value[i].error,er;n.push(o)}return kh(n)}fromString(e){this.value=[];let t=0,n=0,i="";do{n=e.indexOf(".",t),n===-1?i=e.substring(t):i=e.substring(t,n),t=n+1;let o=new ls;if(o.valueDec=parseInt(i,10),isNaN(o.valueDec))return!0;this.value.push(o)}while(n!==-1);return!0}toString(){let e="",t=!1;for(let n=0;n<this.value.length;n++){t=this.value[n].isHexOnly;let i=this.value[n].toString();n!==0&&(e=`${e}.`),t&&(i=`{${i}}`),e+=i}return e}toJSON(){let e={...super.toJSON(),value:this.toString(),sidArray:[]};for(let t=0;t<this.value.length;t++)e.sidArray.push(this.value[t].toJSON());return e}};oc.NAME="RelativeObjectIdentifierValueBlock";var Hp,sc=class extends Ge{constructor(e={}){super(e,oc),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()}}};Hp=sc;$.RelativeObjectIdentifier=Hp;sc.NAME="RelativeObjectIdentifier";var $p,Ve=class extends Ln{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=16}};$p=Ve;$.Sequence=$p;Ve.NAME="SEQUENCE";var zp,ac=class extends Ln{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=17}};zp=ac;$.Set=zp;ac.NAME="SET";var cc=class extends Zr(tt){constructor({...e}={}){super(e),this.isHexOnly=!0,this.value=lo}toJSON(){return{...super.toJSON(),value:this.value}}};cc.NAME="StringValueBlock";var lc=class extends cc{};lc.NAME="SimpleStringValueBlock";var st=class extends Wa{constructor({...e}={}){super(e,lc)}fromBuffer(e){this.valueBlock.value=String.fromCharCode.apply(null,se.BufferSourceConverter.toUint8Array(e))}fromString(e){let t=e.length,n=this.valueBlock.valueHexView=new Uint8Array(t);for(let i=0;i<t;i++)n[i]=e.charCodeAt(i);this.valueBlock.value=e}};st.NAME="SIMPLE STRING";var uc=class extends st{fromBuffer(e){this.valueBlock.valueHexView=se.BufferSourceConverter.toUint8Array(e);try{this.valueBlock.value=se.Convert.ToUtf8String(e)}catch(t){this.warnings.push(`Error during "decodeURIComponent": ${t}, using raw string`),this.valueBlock.value=se.Convert.ToBinary(e)}}fromString(e){this.valueBlock.valueHexView=new Uint8Array(se.Convert.FromUtf8String(e)),this.valueBlock.value=e}};uc.NAME="Utf8StringValueBlock";var Kp,Yr=class extends uc{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=12}};Kp=Yr;$.Utf8String=Kp;Yr.NAME="UTF8String";var hc=class extends st{fromBuffer(e){this.valueBlock.value=se.Convert.ToUtf16String(e),this.valueBlock.valueHexView=se.BufferSourceConverter.toUint8Array(e)}fromString(e){this.valueBlock.value=e,this.valueBlock.valueHexView=new Uint8Array(se.Convert.FromUtf16String(e))}};hc.NAME="BmpStringValueBlock";var qp,dc=class extends hc{constructor({...e}={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=30}};qp=dc;$.BmpString=qp;dc.NAME="BMPString";var fc=class extends st{fromBuffer(e){let t=ArrayBuffer.isView(e)?e.slice().buffer:e.slice(0),n=new Uint8Array(t);for(let i=0;i<n.length;i+=4)n[i]=n[i+3],n[i+1]=n[i+2],n[i+2]=0,n[i+3]=0;this.valueBlock.value=String.fromCharCode.apply(null,new Uint32Array(t))}fromString(e){let t=e.length,n=this.valueBlock.valueHexView=new Uint8Array(t*4);for(let i=0;i<t;i++){let o=Un(e.charCodeAt(i),8),s=new Uint8Array(o);if(s.length>4)continue;let a=4-s.length;for(let c=s.length-1;c>=0;c--)n[i*4+c+a]=s[c]}this.valueBlock.value=e}};fc.NAME="UniversalStringValueBlock";var Gp,pc=class extends fc{constructor({...e}={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=28}};Gp=pc;$.UniversalString=Gp;pc.NAME="UniversalString";var jp,mc=class extends st{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=18}};jp=mc;$.NumericString=jp;mc.NAME="NumericString";var Wp,yc=class extends st{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=19}};Wp=yc;$.PrintableString=Wp;yc.NAME="PrintableString";var Yp,gc=class extends st{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=20}};Yp=gc;$.TeletexString=Yp;gc.NAME="TeletexString";var Xp,wc=class extends st{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=21}};Xp=wc;$.VideotexString=Xp;wc.NAME="VideotexString";var Zp,xc=class extends st{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=22}};Zp=xc;$.IA5String=Zp;xc.NAME="IA5String";var Jp,bc=class extends st{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=25}};Jp=bc;$.GraphicString=Jp;bc.NAME="GraphicString";var Qp,us=class extends st{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=26}};Qp=us;$.VisibleString=Qp;us.NAME="VisibleString";var e1,Ec=class extends st{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=27}};e1=Ec;$.GeneralString=e1;Ec.NAME="GeneralString";var t1,vc=class extends st{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=29}};t1=vc;$.CharacterString=t1;vc.NAME="CharacterString";var r1,hs=class extends us{constructor({value:e,valueDate:t,...n}={}){if(super(n),this.year=0,this.month=0,this.day=0,this.hour=0,this.minute=0,this.second=0,e){this.fromString(e),this.valueBlock.valueHexView=new Uint8Array(e.length);for(let i=0;i<e.length;i++)this.valueBlock.valueHexView[i]=e.charCodeAt(i)}t&&(this.fromDate(t),this.valueBlock.valueHexView=new Uint8Array(this.toBuffer())),this.idBlock.tagClass=1,this.idBlock.tagNumber=23}fromBuffer(e){this.fromString(String.fromCharCode.apply(null,se.BufferSourceConverter.toUint8Array(e)))}toBuffer(){let e=this.toString(),t=new ArrayBuffer(e.length),n=new Uint8Array(t);for(let i=0;i<e.length;i++)n[i]=e.charCodeAt(i);return t}fromDate(e){this.year=e.getUTCFullYear(),this.month=e.getUTCMonth()+1,this.day=e.getUTCDate(),this.hour=e.getUTCHours(),this.minute=e.getUTCMinutes(),this.second=e.getUTCSeconds()}toDate(){return new Date(Date.UTC(this.year,this.month-1,this.day,this.hour,this.minute,this.second))}fromString(e){let n=/(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})Z/ig.exec(e);if(n===null){this.error="Wrong input string for conversion";return}let i=parseInt(n[1],10);i>=50?this.year=1900+i:this.year=2e3+i,this.month=parseInt(n[2],10),this.day=parseInt(n[3],10),this.hour=parseInt(n[4],10),this.minute=parseInt(n[5],10),this.second=parseInt(n[6],10)}toString(e="iso"){if(e==="iso"){let t=new Array(7);return t[0]=pt(this.year<2e3?this.year-1900:this.year-2e3,2),t[1]=pt(this.month,2),t[2]=pt(this.day,2),t[3]=pt(this.hour,2),t[4]=pt(this.minute,2),t[5]=pt(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}}};r1=hs;$.UTCTime=r1;hs.NAME="UTCTime";var n1,Bc=class extends hs{constructor(e={}){var t;super(e),(t=this.millisecond)!==null&&t!==void 0||(this.millisecond=0),this.idBlock.tagClass=1,this.idBlock.tagNumber=24}fromDate(e){super.fromDate(e),this.millisecond=e.getUTCMilliseconds()}toDate(){return new Date(Date.UTC(this.year,this.month-1,this.day,this.hour,this.minute,this.second,this.millisecond))}fromString(e){let t=!1,n="",i="",o=0,s,a=0,c=0;if(e[e.length-1]==="Z")n=e.substring(0,e.length-1),t=!0;else{let h=new Number(e[e.length-1]);if(isNaN(h.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 h=1,p=n.indexOf("+"),d="";if(p===-1&&(p=n.indexOf("-"),h=-1),p!==-1){if(d=n.substring(p+1),n=n.substring(0,p),d.length!==2&&d.length!==4)throw new Error("Wrong input string for conversion");let f=parseInt(d.substring(0,2),10);if(isNaN(f.valueOf()))throw new Error("Wrong input string for conversion");if(a=h*f,d.length===4){if(f=parseInt(d.substring(2,4),10),isNaN(f.valueOf()))throw new Error("Wrong input string for conversion");c=h*f}}}let u=n.indexOf(".");if(u===-1&&(u=n.indexOf(",")),u!==-1){let h=new Number(`0${n.substring(u)}`);if(isNaN(h.valueOf()))throw new Error("Wrong input string for conversion");o=h.valueOf(),i=n.substring(0,u)}else i=n;switch(!0){case i.length===8:if(s=/(\d{4})(\d{2})(\d{2})/ig,u!==-1)throw new Error("Wrong input string for conversion");break;case i.length===10:if(s=/(\d{4})(\d{2})(\d{2})(\d{2})/ig,u!==-1){let h=60*o;this.minute=Math.floor(h),h=60*(h-this.minute),this.second=Math.floor(h),h=1e3*(h-this.second),this.millisecond=Math.floor(h)}break;case i.length===12:if(s=/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})/ig,u!==-1){let h=60*o;this.second=Math.floor(h),h=1e3*(h-this.second),this.millisecond=Math.floor(h)}break;case i.length===14:if(s=/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/ig,u!==-1){let h=1e3*o;this.millisecond=Math.floor(h)}break;default:throw new Error("Wrong input string for conversion")}let l=s.exec(i);if(l===null)throw new Error("Wrong input string for conversion");for(let h=1;h<l.length;h++)switch(h){case 1:this.year=parseInt(l[h],10);break;case 2:this.month=parseInt(l[h],10);break;case 3:this.day=parseInt(l[h],10);break;case 4:this.hour=parseInt(l[h],10)+a;break;case 5:this.minute=parseInt(l[h],10)+c;break;case 6:this.second=parseInt(l[h],10);break;default:throw new Error("Wrong input string for conversion")}if(t===!1){let h=new Date(this.year,this.month,this.day,this.hour,this.minute,this.second,this.millisecond);this.year=h.getUTCFullYear(),this.month=h.getUTCMonth(),this.day=h.getUTCDay(),this.hour=h.getUTCHours(),this.minute=h.getUTCMinutes(),this.second=h.getUTCSeconds(),this.millisecond=h.getUTCMilliseconds()}}toString(e="iso"){if(e==="iso"){let t=[];return t.push(pt(this.year,4)),t.push(pt(this.month,2)),t.push(pt(this.day,2)),t.push(pt(this.hour,2)),t.push(pt(this.minute,2)),t.push(pt(this.second,2)),this.millisecond!==0&&(t.push("."),t.push(pt(this.millisecond,3))),t.push("Z"),t.join("")}return super.toString(e)}toJSON(){return{...super.toJSON(),millisecond:this.millisecond}}};n1=Bc;$.GeneralizedTime=n1;Bc.NAME="GeneralizedTime";var i1,Ac=class extends Yr{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=31}};i1=Ac;$.DATE=i1;Ac.NAME="DATE";var o1,Ic=class extends Yr{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=32}};o1=Ic;$.TimeOfDay=o1;Ic.NAME="TimeOfDay";var s1,Sc=class extends Yr{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=33}};s1=Sc;$.DateTime=s1;Sc.NAME="DateTime";var a1,_c=class extends Yr{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=34}};a1=_c;$.Duration=a1;_c.NAME="Duration";var c1,kc=class extends Yr{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=14}};c1=kc;$.TIME=c1;kc.NAME="TIME";function T3(r){let{result:e}=uo(r),t=e.valueBlock.value;return{n:Q(gr(t[1].toBigInt()),"base64url"),e:Q(gr(t[2].toBigInt()),"base64url"),d:Q(gr(t[3].toBigInt()),"base64url"),p:Q(gr(t[4].toBigInt()),"base64url"),q:Q(gr(t[5].toBigInt()),"base64url"),dp:Q(gr(t[6].toBigInt()),"base64url"),dq:Q(gr(t[7].toBigInt()),"base64url"),qi:Q(gr(t[8].toBigInt()),"base64url"),kty:"RSA",alg:"RS256"}}function C3(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 F("JWK was missing components","ERR_INVALID_PARAMETERS");let t=new Ve({value:[new Le({value:0}),Le.fromBigInt(wr(Y(r.n,"base64url"))),Le.fromBigInt(wr(Y(r.e,"base64url"))),Le.fromBigInt(wr(Y(r.d,"base64url"))),Le.fromBigInt(wr(Y(r.p,"base64url"))),Le.fromBigInt(wr(Y(r.q,"base64url"))),Le.fromBigInt(wr(Y(r.dp,"base64url"))),Le.fromBigInt(wr(Y(r.dq,"base64url"))),Le.fromBigInt(wr(Y(r.qi,"base64url")))]}).toBER();return new Uint8Array(t,0,t.byteLength)}function N3(r){let{result:e}=uo(r),t=e.valueBlock.value[1].valueBlock.value[0].valueBlock.value;return{kty:"RSA",n:Q(gr(t[0].toBigInt()),"base64url"),e:Q(gr(t[1].toBigInt()),"base64url")}}function U3(r){if(r.n==null||r.e==null)throw new F("JWK was missing components","ERR_INVALID_PARAMETERS");let t=new Ve({value:[new Ve({value:[new Qt({value:"1.2.840.113549.1.1.1"}),new Dn]}),new co({valueHex:new Ve({value:[Le.fromBigInt(wr(Y(r.n,"base64url"))),Le.fromBigInt(wr(Y(r.e,"base64url")))]}).toBER()})]}).toBER();return new Uint8Array(t,0,t.byteLength)}function gr(r){let e=r.toString(16);e.length%2>0&&(e=`0${e}`);let t=e.length/2,n=new Uint8Array(t),i=0,o=0;for(;i<t;)n[i]=parseInt(e.slice(o,o+2),16),i+=1,o+=2;return n}function wr(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 L3=16,Th=32,Ch=1e4;async function D3(r,e){let t=ot.get(),i=new Ve({value:[new Le({value:0}),new Ve({value:[new Qt({value:"1.2.840.113549.1.1.1"}),new Dn]}),new Wr({valueHex:r.marshal()})]}).toBER(),o=new Uint8Array(i,0,i.byteLength),s=di(L3),a=await Ih(ro,e,s,{c:Ch,dkLen:Th}),c=di(16),u=await t.subtle.importKey("raw",a,"AES-CBC",!1,["encrypt"]),l=await t.subtle.encrypt({name:"AES-CBC",iv:c},u,o),h=new Ve({value:[new Wr({valueHex:s}),new Le({value:Ch}),new Le({value:Th}),new Ve({value:[new Qt({value:"1.2.840.113549.2.11"}),new Dn]})]}),p=new Ve({value:[new Qt({value:"1.2.840.113549.1.5.13"}),new Ve({value:[new Ve({value:[new Qt({value:"1.2.840.113549.1.5.12"}),h]}),new Ve({value:[new Qt({value:"2.16.840.1.101.3.4.1.42"}),new Wr({valueHex:c})]})]})]}),f=new Ve({value:[p,new Wr({valueHex:l})]}).toBER(),m=new Uint8Array(f,0,f.byteLength);return["-----BEGIN ENCRYPTED PRIVATE KEY-----",...Q(m,"base64pad").split(/(.{64})/).filter(Boolean),"-----END ENCRYPTED PRIVATE KEY-----"].join(`
|
|
8
|
+
`)}async function P3(r,e){let t=ot.get(),n;if(r.includes("-----BEGIN ENCRYPTED PRIVATE KEY-----")){let i=Y(r.replace("-----BEGIN ENCRYPTED PRIVATE KEY-----","").replace("-----END ENCRYPTED PRIVATE KEY-----","").replace(/\n/g,"").trim(),"base64pad"),{result:o}=uo(i),{iv:s,salt:a,iterations:c,keySize:u,cipherText:l}=O3(o),h=await Ih(ro,e,a,{c,dkLen:u}),p=await t.subtle.importKey("raw",h,"AES-CBC",!1,["decrypt"]),d=ds(await t.subtle.decrypt({name:"AES-CBC",iv:s},p,l)),{result:f}=uo(d);n=l1(f)}else if(r.includes("-----BEGIN PRIVATE KEY-----")){let i=Y(r.replace("-----BEGIN PRIVATE KEY-----","").replace("-----END PRIVATE KEY-----","").replace(/\n/g,"").trim(),"base64pad"),{result:o}=uo(i);n=l1(o)}else throw new F("Could not parse private key from PEM data","ERR_INVALID_PARAMETERS");return Nh(n)}function O3(r){let e=r.valueBlock.value[0];if(e.valueBlock.value[0].toString()!=="OBJECT IDENTIFIER : 1.2.840.113549.1.5.13")throw new F("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 F("Only pkcs5PBKDF2 key derivation functions are supported","ERR_INVALID_PARAMS");let o=n.valueBlock.value[1],s=ds(o.valueBlock.value[0].getValue()),a=Ch,c=Th;if(o.valueBlock.value.length===3)a=Number(o.valueBlock.value[1].toBigInt()),c=Number(o.valueBlock.value[2].toBigInt());else if(o.valueBlock.value.length===2)throw new F("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 F("Only AES-CBC encryption schemes are supported","ERR_INVALID_PARAMS")}}}}let h=ds(u.valueBlock.value[1].getValue());return{cipherText:ds(r.valueBlock.value[1].getValue()),salt:s,iterations:a,keySize:c,iv:h}}function l1(r){return ds(r.valueBlock.value[2].getValue())}function ds(r){return new Uint8Array(r,0,r.byteLength)}async function u1(r){let e=await ot.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 f1(e);return{privateKey:t[0],publicKey:t[1]}}async function Uh(r){let t=[await ot.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!0,["sign"]),await F3(r)],n=await f1({privateKey:t[0],publicKey:t[1]});return{privateKey:n[0],publicKey:n[1]}}async function h1(r,e){let t=await ot.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]),n=await ot.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},t,e instanceof Uint8Array?e:e.subarray());return new Uint8Array(n,0,n.byteLength)}async function d1(r,e,t){let n=await ot.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);return ot.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},n,e,t instanceof Uint8Array?t:t.subarray())}async function f1(r){if(r.privateKey==null||r.publicKey==null)throw new F("Private and public key are required","ERR_INVALID_PARAMETERS");return Promise.all([ot.get().subtle.exportKey("jwk",r.privateKey),ot.get().subtle.exportKey("jwk",r.publicKey)])}async function F3(r){return ot.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 Tc(r){if(r.kty!=="RSA")throw new F("invalid key type","ERR_INVALID_KEY_TYPE");if(r.n==null)throw new F("invalid key modulus","ERR_INVALID_KEY_MODULUS");return Y(r.n,"base64url").length*8}var ps=8192,fs=class{_key;constructor(e){this._key=e}verify(e,t){return d1(this._key,t,e)}marshal(){return Pn.jwkToPkix(this._key)}get bytes(){return pr.encode({Type:be.RSA,Data:this.marshal()}).subarray()}equals(e){return de(this.bytes,e.bytes)}hash(){let e=he.digest(this.bytes);return Mt(e)?e.then(({bytes:t})=>t):e.bytes}},ho=class{_key;_publicKey;constructor(e,t){this._key=e,this._publicKey=t}genSecret(){return di(16)}sign(e){return h1(this._key,e)}get public(){if(this._publicKey==null)throw new F("public key not provided","ERR_PUBKEY_NOT_PROVIDED");return new fs(this._publicKey)}marshal(){return Pn.jwkToPkcs1(this._key)}get bytes(){return mr.encode({Type:be.RSA,Data:this.marshal()}).subarray()}equals(e){return de(this.bytes,e.bytes)}hash(){let e=he.digest(this.bytes);return Mt(e)?e.then(({bytes:t})=>t):e.bytes}async id(){let e=await this.public.hash();return Q(e,"base58btc")}async export(e,t="pkcs-8"){if(t==="pkcs-8")return Pn.exportToPem(this,e);if(t==="libp2p-key")return oo(this.bytes,e);throw new F(`export format '${t}' is not supported`,"ERR_INVALID_EXPORT_FORMAT")}};async function Nh(r){let e=Pn.pkcs1ToJwk(r);if(Tc(e)>ps)throw new F("key size is too large","ERR_KEY_SIZE_TOO_LARGE");let t=await Uh(e);return new ho(t.privateKey,t.publicKey)}function M3(r){let e=Pn.pkixToJwk(r);if(Tc(e)>ps)throw new F("key size is too large","ERR_KEY_SIZE_TOO_LARGE");return new fs(e)}async function H3(r){if(Tc(r)>ps)throw new F("key size is too large","ERR_KEY_SIZE_TOO_LARGE");let e=await Uh(r);return new ho(e.privateKey,e.publicKey)}async function $3(r){if(r>ps)throw new F("key size is too large","ERR_KEY_SIZE_TOO_LARGE");let e=await u1(r);return new ho(e.privateKey,e.publicKey)}var Vh={};Ae(Vh,{Secp256k1PrivateKey:()=>ys,Secp256k1PublicKey:()=>ms,generateKeyPair:()=>n6,unmarshalSecp256k1PrivateKey:()=>t6,unmarshalSecp256k1PublicKey:()=>r6});var z3=(r,e,t)=>r&e^~r&t,K3=(r,e,t)=>r&e^r&t^e&t,q3=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]),On=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Fn=new Uint32Array(64),Dh=class extends to{constructor(){super(64,32,8,!1),this.A=On[0]|0,this.B=On[1]|0,this.C=On[2]|0,this.D=On[3]|0,this.E=On[4]|0,this.F=On[5]|0,this.G=On[6]|0,this.H=On[7]|0}get(){let{A:e,B:t,C:n,D:i,E:o,F:s,G:a,H:c}=this;return[e,t,n,i,o,s,a,c]}set(e,t,n,i,o,s,a,c){this.A=e|0,this.B=t|0,this.C=n|0,this.D=i|0,this.E=o|0,this.F=s|0,this.G=a|0,this.H=c|0}process(e,t){for(let h=0;h<16;h++,t+=4)Fn[h]=e.getUint32(t,!1);for(let h=16;h<64;h++){let p=Fn[h-15],d=Fn[h-2],f=Xt(p,7)^Xt(p,18)^p>>>3,m=Xt(d,17)^Xt(d,19)^d>>>10;Fn[h]=m+Fn[h-7]+f+Fn[h-16]|0}let{A:n,B:i,C:o,D:s,E:a,F:c,G:u,H:l}=this;for(let h=0;h<64;h++){let p=Xt(a,6)^Xt(a,11)^Xt(a,25),d=l+p+z3(a,c,u)+q3[h]+Fn[h]|0,m=(Xt(n,2)^Xt(n,13)^Xt(n,22))+K3(n,i,o)|0;l=u,u=c,c=a,a=s+d|0,s=o,o=i,i=n,n=d+m|0}n=n+this.A|0,i=i+this.B|0,o=o+this.C|0,s=s+this.D|0,a=a+this.E|0,c=c+this.F|0,u=u+this.G|0,l=l+this.H|0,this.set(n,i,o,s,a,c,u,l)}roundClean(){Fn.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};var p1=Ta(()=>new Dh);function G3(r){let e=ts(r);fr(e,{a:"field",b:"field"},{allowedPrivateKeyLengths:"array",wrapPrivateKey:"boolean",isTorsionFree:"function",clearCofactor:"function",allowInfinityPoint:"boolean",fromBytes:"function",toBytes:"function"});let{endo:t,Fp:n,a:i}=e;if(t){if(!n.eql(i,n.ZERO))throw new Error("Endomorphism can only be defined for Koblitz curves that have a=0");if(typeof t!="object"||typeof t.beta!="bigint"||typeof t.splitScalar!="function")throw new Error("Expected endomorphism with beta: bigint and splitScalar: function")}return Object.freeze({...e})}var{bytesToNumberBE:j3,hexToBytes:W3}=Ua,pi={Err:class extends Error{constructor(e=""){super(e)}},_parseInt(r){let{Err:e}=pi;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:j3(n),l:r.subarray(t+2)}},toSig(r){let{Err:e}=pi,t=typeof r=="string"?W3(r):r;if(!Zt(t))throw new Error("ui8a expected");let n=t.length;if(n<2||t[0]!=48)throw new e("Invalid signature tag");if(t[1]!==n-2)throw new e("Invalid signature: incorrect length");let{d:i,l:o}=pi._parseInt(t.subarray(2)),{d:s,l:a}=pi._parseInt(o);if(a.length)throw new e("Invalid signature: left bytes after parsing");return{r:i,s}},hexFromSig(r){let e=u=>Number.parseInt(u[0],16)&8?"00"+u:u,t=u=>{let l=u.toString(16);return l.length&1?`0${l}`:l},n=e(t(r.s)),i=e(t(r.r)),o=n.length/2,s=i.length/2,a=t(o),c=t(s);return`30${t(s+o+4)}02${c}${i}02${a}${n}`}},Jr=BigInt(0),$t=BigInt(1),vk=BigInt(2),m1=BigInt(3),Bk=BigInt(4);function Y3(r){let e=G3(r),{Fp:t}=e,n=e.toBytes||((f,m,y)=>{let g=m.toAffine();return zr(Uint8Array.from([4]),t.toBytes(g.x),t.toBytes(g.y))}),i=e.fromBytes||(f=>{let m=f.subarray(1),y=t.fromBytes(m.subarray(0,t.BYTES)),g=t.fromBytes(m.subarray(t.BYTES,2*t.BYTES));return{x:y,y:g}});function o(f){let{a:m,b:y}=e,g=t.sqr(f),w=t.mul(g,f);return t.add(t.add(w,t.mul(f,m)),y)}if(!t.eql(t.sqr(e.Gy),o(e.Gx)))throw new Error("bad generator point: equation left != right");function s(f){return typeof f=="bigint"&&Jr<f&&f<e.n}function a(f){if(!s(f))throw new Error("Expected valid bigint: 0 < bigint < curve.n")}function c(f){let{allowedPrivateKeyLengths:m,nByteLength:y,wrapPrivateKey:g,n:w}=e;if(m&&typeof f!="bigint"){if(Zt(f)&&(f=Hr(f)),typeof f!="string"||!m.includes(f.length))throw new Error("Invalid key");f=f.padStart(y*2,"0")}let x;try{x=typeof f=="bigint"?f:$r(Se("private key",f,y))}catch{throw new Error(`private key must be ${y} bytes, hex or bigint, not ${typeof f}`)}return g&&(x=ye(x,w)),a(x),x}let u=new Map;function l(f){if(!(f instanceof h))throw new Error("ProjectivePoint expected")}class h{constructor(m,y,g){if(this.px=m,this.py=y,this.pz=g,m==null||!t.isValid(m))throw new Error("x required");if(y==null||!t.isValid(y))throw new Error("y required");if(g==null||!t.isValid(g))throw new Error("z required")}static fromAffine(m){let{x:y,y:g}=m||{};if(!m||!t.isValid(y)||!t.isValid(g))throw new Error("invalid affine point");if(m instanceof h)throw new Error("projective point not allowed");let w=x=>t.eql(x,t.ZERO);return w(y)&&w(g)?h.ZERO:new h(y,g,t.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(m){let y=t.invertBatch(m.map(g=>g.pz));return m.map((g,w)=>g.toAffine(y[w])).map(h.fromAffine)}static fromHex(m){let y=h.fromAffine(i(Se("pointHex",m)));return y.assertValidity(),y}static fromPrivateKey(m){return h.BASE.multiply(c(m))}_setWindowSize(m){this._WINDOW_SIZE=m,u.delete(this)}assertValidity(){if(this.is0()){if(e.allowInfinityPoint&&!t.is0(this.py))return;throw new Error("bad point: ZERO")}let{x:m,y}=this.toAffine();if(!t.isValid(m)||!t.isValid(y))throw new Error("bad point: x or y not FE");let g=t.sqr(y),w=o(m);if(!t.eql(g,w))throw new Error("bad point: equation left != right");if(!this.isTorsionFree())throw new Error("bad point: not in prime-order subgroup")}hasEvenY(){let{y:m}=this.toAffine();if(t.isOdd)return!t.isOdd(m);throw new Error("Field doesn't support isOdd")}equals(m){l(m);let{px:y,py:g,pz:w}=this,{px:x,py:A,pz:I}=m,B=t.eql(t.mul(y,I),t.mul(x,w)),v=t.eql(t.mul(g,I),t.mul(A,w));return B&&v}negate(){return new h(this.px,t.neg(this.py),this.pz)}double(){let{a:m,b:y}=e,g=t.mul(y,m1),{px:w,py:x,pz:A}=this,I=t.ZERO,B=t.ZERO,v=t.ZERO,E=t.mul(w,w),R=t.mul(x,x),N=t.mul(A,A),T=t.mul(w,x);return T=t.add(T,T),v=t.mul(w,A),v=t.add(v,v),I=t.mul(m,v),B=t.mul(g,N),B=t.add(I,B),I=t.sub(R,B),B=t.add(R,B),B=t.mul(I,B),I=t.mul(T,I),v=t.mul(g,v),N=t.mul(m,N),T=t.sub(E,N),T=t.mul(m,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),B=t.add(B,E),N=t.mul(x,A),N=t.add(N,N),E=t.mul(N,T),I=t.sub(I,E),v=t.mul(N,R),v=t.add(v,v),v=t.add(v,v),new h(I,B,v)}add(m){l(m);let{px:y,py:g,pz:w}=this,{px:x,py:A,pz:I}=m,B=t.ZERO,v=t.ZERO,E=t.ZERO,R=e.a,N=t.mul(e.b,m1),T=t.mul(y,x),M=t.mul(g,A),D=t.mul(w,I),ne=t.add(y,g),_=t.add(x,A);ne=t.mul(ne,_),_=t.add(T,M),ne=t.sub(ne,_),_=t.add(y,w);let L=t.add(x,I);return _=t.mul(_,L),L=t.add(T,D),_=t.sub(_,L),L=t.add(g,w),B=t.add(A,I),L=t.mul(L,B),B=t.add(M,D),L=t.sub(L,B),E=t.mul(R,_),B=t.mul(N,D),E=t.add(B,E),B=t.sub(M,E),E=t.add(M,E),v=t.mul(B,E),M=t.add(T,T),M=t.add(M,T),D=t.mul(R,D),_=t.mul(N,_),M=t.add(M,D),D=t.sub(T,D),D=t.mul(R,D),_=t.add(_,D),T=t.mul(M,_),v=t.add(v,T),T=t.mul(L,_),B=t.mul(ne,B),B=t.sub(B,T),T=t.mul(ne,M),E=t.mul(L,E),E=t.add(E,T),new h(B,v,E)}subtract(m){return this.add(m.negate())}is0(){return this.equals(h.ZERO)}wNAF(m){return d.wNAFCached(this,u,m,y=>{let g=t.invertBatch(y.map(w=>w.pz));return y.map((w,x)=>w.toAffine(g[x])).map(h.fromAffine)})}multiplyUnsafe(m){let y=h.ZERO;if(m===Jr)return y;if(a(m),m===$t)return this;let{endo:g}=e;if(!g)return d.unsafeLadder(this,m);let{k1neg:w,k1:x,k2neg:A,k2:I}=g.splitScalar(m),B=y,v=y,E=this;for(;x>Jr||I>Jr;)x&$t&&(B=B.add(E)),I&$t&&(v=v.add(E)),E=E.double(),x>>=$t,I>>=$t;return w&&(B=B.negate()),A&&(v=v.negate()),v=new h(t.mul(v.px,g.beta),v.py,v.pz),B.add(v)}multiply(m){a(m);let y=m,g,w,{endo:x}=e;if(x){let{k1neg:A,k1:I,k2neg:B,k2:v}=x.splitScalar(y),{p:E,f:R}=this.wNAF(I),{p:N,f:T}=this.wNAF(v);E=d.constTimeNegate(A,E),N=d.constTimeNegate(B,N),N=new h(t.mul(N.px,x.beta),N.py,N.pz),g=E.add(N),w=R.add(T)}else{let{p:A,f:I}=this.wNAF(y);g=A,w=I}return h.normalizeZ([g,w])[0]}multiplyAndAddUnsafe(m,y,g){let w=h.BASE,x=(I,B)=>B===Jr||B===$t||!I.equals(w)?I.multiplyUnsafe(B):I.multiply(B),A=x(this,y).add(x(m,g));return A.is0()?void 0:A}toAffine(m){let{px:y,py:g,pz:w}=this,x=this.is0();m==null&&(m=x?t.ONE:t.inv(w));let A=t.mul(y,m),I=t.mul(g,m),B=t.mul(w,m);if(x)return{x:t.ZERO,y:t.ZERO};if(!t.eql(B,t.ONE))throw new Error("invZ was invalid");return{x:A,y:I}}isTorsionFree(){let{h:m,isTorsionFree:y}=e;if(m===$t)return!0;if(y)return y(h,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){let{h:m,clearCofactor:y}=e;return m===$t?this:y?y(h,this):this.multiplyUnsafe(e.h)}toRawBytes(m=!0){return this.assertValidity(),n(h,this,m)}toHex(m=!0){return Hr(this.toRawBytes(m))}}h.BASE=new h(e.Gx,e.Gy,t.ONE),h.ZERO=new h(t.ZERO,t.ONE,t.ZERO);let p=e.nBitLength,d=Pa(h,e.endo?Math.ceil(p/2):p);return{CURVE:e,ProjectivePoint:h,normPrivateKeyToScalar:c,weierstrassEquation:o,isWithinCurveOrder:s}}function X3(r){let e=ts(r);return fr(e,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...e})}function y1(r){let e=X3(r),{Fp:t,n}=e,i=t.BYTES+1,o=2*t.BYTES+1;function s(_){return Jr<_&&_<t.ORDER}function a(_){return ye(_,n)}function c(_){return La(_,n)}let{ProjectivePoint:u,normPrivateKeyToScalar:l,weierstrassEquation:h,isWithinCurveOrder:p}=Y3({...e,toBytes(_,L,X){let U=L.toAffine(),k=t.toBytes(U.x),z=zr;return X?z(Uint8Array.from([L.hasEvenY()?2:3]),k):z(Uint8Array.from([4]),k,t.toBytes(U.y))},fromBytes(_){let L=_.length,X=_[0],U=_.subarray(1);if(L===i&&(X===2||X===3)){let k=$r(U);if(!s(k))throw new Error("Point is not on curve");let z=h(k),j=t.sqrt(z),Z=(j&$t)===$t;return(X&1)===1!==Z&&(j=t.neg(j)),{x:k,y:j}}else if(L===o&&X===4){let k=t.fromBytes(U.subarray(0,t.BYTES)),z=t.fromBytes(U.subarray(t.BYTES,2*t.BYTES));return{x:k,y:z}}else throw new Error(`Point of length ${L} was invalid. Expected ${i} compressed bytes or ${o} uncompressed bytes`)}}),d=_=>Hr(Nn(_,e.nByteLength));function f(_){let L=n>>$t;return _>L}function m(_){return f(_)?a(-_):_}let y=(_,L,X)=>$r(_.slice(L,X));class g{constructor(L,X,U){this.r=L,this.s=X,this.recovery=U,this.assertValidity()}static fromCompact(L){let X=e.nByteLength;return L=Se("compactSignature",L,X*2),new g(y(L,0,X),y(L,X,2*X))}static fromDER(L){let{r:X,s:U}=pi.toSig(Se("DER",L));return new g(X,U)}assertValidity(){if(!p(this.r))throw new Error("r must be 0 < r < CURVE.n");if(!p(this.s))throw new Error("s must be 0 < s < CURVE.n")}addRecoveryBit(L){return new g(this.r,this.s,L)}recoverPublicKey(L){let{r:X,s:U,recovery:k}=this,z=v(Se("msgHash",L));if(k==null||![0,1,2,3].includes(k))throw new Error("recovery id invalid");let j=k===2||k===3?X+e.n:X;if(j>=t.ORDER)throw new Error("recovery id 2 or 3 invalid");let Z=k&1?"03":"02",te=u.fromHex(Z+d(j)),ie=c(j),pe=a(-z*ie),ae=a(U*ie),le=u.BASE.multiplyAndAddUnsafe(te,pe,ae);if(!le)throw new Error("point at infinify");return le.assertValidity(),le}hasHighS(){return f(this.s)}normalizeS(){return this.hasHighS()?new g(this.r,a(-this.s),this.recovery):this}toDERRawBytes(){return ci(this.toDERHex())}toDERHex(){return pi.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return ci(this.toCompactHex())}toCompactHex(){return d(this.r)+d(this.s)}}let w={isValidPrivateKey(_){try{return l(_),!0}catch{return!1}},normPrivateKeyToScalar:l,randomPrivateKey:()=>{let _=gh(e.n);return up(e.randomBytes(_),e.n)},precompute(_=8,L=u.BASE){return L._setWindowSize(_),L.multiply(BigInt(3)),L}};function x(_,L=!0){return u.fromPrivateKey(_).toRawBytes(L)}function A(_){let L=Zt(_),X=typeof _=="string",U=(L||X)&&_.length;return L?U===i||U===o:X?U===2*i||U===2*o:_ instanceof u}function I(_,L,X=!0){if(A(_))throw new Error("first arg must be private key");if(!A(L))throw new Error("second arg must be public key");return u.fromHex(L).multiply(l(_)).toRawBytes(X)}let B=e.bits2int||function(_){let L=$r(_),X=_.length*8-e.nBitLength;return X>0?L>>BigInt(X):L},v=e.bits2int_modN||function(_){return a(B(_))},E=es(e.nBitLength);function R(_){if(typeof _!="bigint")throw new Error("bigint expected");if(!(Jr<=_&&_<E))throw new Error(`bigint expected < 2^${e.nBitLength}`);return Nn(_,e.nByteLength)}function N(_,L,X=T){if(["recovered","canonical"].some(Be=>Be in X))throw new Error("sign() legacy options not supported");let{hash:U,randomBytes:k}=e,{lowS:z,prehash:j,extraEntropy:Z}=X;z==null&&(z=!0),_=Se("msgHash",_),j&&(_=Se("prehashed msgHash",U(_)));let te=v(_),ie=l(L),pe=[R(ie),R(te)];if(Z!=null){let Be=Z===!0?k(t.BYTES):Z;pe.push(Se("extraEntropy",Be))}let ae=zr(...pe),le=te;function Ce(Be){let ze=B(Be);if(!p(ze))return;let Ke=c(ze),Pe=u.BASE.multiply(ze).toAffine(),Ze=a(Pe.x);if(Ze===Jr)return;let Dr=a(Ke*a(le+Ze*ie));if(Dr===Jr)return;let Qn=(Pe.x===Ze?0:2)|Number(Pe.y&$t),zo=Dr;return z&&f(Dr)&&(zo=m(Dr),Qn^=1),new g(Ze,zo,Qn)}return{seed:ae,k2sig:Ce}}let T={lowS:e.lowS,prehash:!1},M={lowS:e.lowS,prehash:!1};function D(_,L,X=T){let{seed:U,k2sig:k}=N(_,L,X),z=e;return fh(z.hash.outputLen,z.nByteLength,z.hmac)(U,k)}u.BASE._setWindowSize(8);function ne(_,L,X,U=M){let k=_;if(L=Se("msgHash",L),X=Se("publicKey",X),"strict"in U)throw new Error("options.strict was renamed to lowS");let{lowS:z,prehash:j}=U,Z,te;try{if(typeof k=="string"||Zt(k))try{Z=g.fromDER(k)}catch(Pe){if(!(Pe instanceof pi.Err))throw Pe;Z=g.fromCompact(k)}else if(typeof k=="object"&&typeof k.r=="bigint"&&typeof k.s=="bigint"){let{r:Pe,s:Ze}=k;Z=new g(Pe,Ze)}else throw new Error("PARSE");te=u.fromHex(X)}catch(Pe){if(Pe.message==="PARSE")throw new Error("signature must be Signature instance, Uint8Array or hex string");return!1}if(z&&Z.hasHighS())return!1;j&&(L=e.hash(L));let{r:ie,s:pe}=Z,ae=v(L),le=c(pe),Ce=a(ae*le),Be=a(ie*le),ze=u.BASE.multiplyAndAddUnsafe(te,Ce,Be)?.toAffine();return ze?a(ze.x)===ie:!1}return{CURVE:e,getPublicKey:x,getSharedSecret:I,sign:D,verify:ne,ProjectivePoint:u,Signature:g,utils:w}}function Z3(r){return{hash:r,hmac:(e,...t)=>ns(r,e,Ra(...t)),randomBytes:eo}}function g1(r,e){let t=n=>y1({...r,...Z3(n)});return Object.freeze({...t(e),create:t})}var b1=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),w1=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),J3=BigInt(1),Ph=BigInt(2),x1=(r,e)=>(r+e/Ph)/e;function Q3(r){let e=b1,t=BigInt(3),n=BigInt(6),i=BigInt(11),o=BigInt(22),s=BigInt(23),a=BigInt(44),c=BigInt(88),u=r*r*r%e,l=u*u*r%e,h=xe(l,t,e)*l%e,p=xe(h,t,e)*l%e,d=xe(p,Ph,e)*u%e,f=xe(d,i,e)*d%e,m=xe(f,o,e)*f%e,y=xe(m,a,e)*m%e,g=xe(y,c,e)*y%e,w=xe(g,a,e)*m%e,x=xe(w,t,e)*l%e,A=xe(x,s,e)*f%e,I=xe(A,n,e)*u%e,B=xe(I,Ph,e);if(!Oh.eql(Oh.sqr(B),r))throw new Error("Cannot find square root");return B}var Oh=Da(b1,void 0,void 0,{sqrt:Q3}),tr=g1({a:BigInt(0),b:BigInt(7),Fp:Oh,n:w1,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:r=>{let e=w1,t=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-J3*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),i=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),o=t,s=BigInt("0x100000000000000000000000000000000"),a=x1(o*r,e),c=x1(-n*r,e),u=ye(r-a*t-c*i,e),l=ye(-a*n-c*o,e),h=u>s,p=l>s;if(h&&(u=e-u),p&&(l=e-l),u>s||l>s)throw new Error("splitScalar: Endomorphism failed, k="+r);return{k1neg:h,k1:u,k2neg:p,k2:l}}}},p1),Nk=BigInt(0);var Uk=tr.ProjectivePoint;function E1(){return tr.utils.randomPrivateKey()}function v1(r,e){let t=he.digest(e instanceof Uint8Array?e:e.subarray());if(Mt(t))return t.then(({digest:n})=>tr.sign(n,r).toDERRawBytes()).catch(n=>{throw new F(String(n),"ERR_INVALID_INPUT")});try{return tr.sign(t.digest,r).toDERRawBytes()}catch(n){throw new F(String(n),"ERR_INVALID_INPUT")}}function B1(r,e,t){let n=he.digest(t instanceof Uint8Array?t:t.subarray());if(Mt(n))return n.then(({digest:i})=>tr.verify(e,i,r)).catch(i=>{throw new F(String(i),"ERR_INVALID_INPUT")});try{return tr.verify(e,n.digest,r)}catch(i){throw new F(String(i),"ERR_INVALID_INPUT")}}function A1(r){return tr.ProjectivePoint.fromHex(r).toRawBytes(!0)}function I1(r){try{tr.getPublicKey(r,!0)}catch(e){throw new F(String(e),"ERR_INVALID_PRIVATE_KEY")}}function Fh(r){try{tr.ProjectivePoint.fromHex(r)}catch(e){throw new F(String(e),"ERR_INVALID_PUBLIC_KEY")}}function S1(r){try{return tr.getPublicKey(r,!0)}catch(e){throw new F(String(e),"ERR_INVALID_PRIVATE_KEY")}}var ms=class{_key;constructor(e){Fh(e),this._key=e}verify(e,t){return B1(this._key,t,e)}marshal(){return A1(this._key)}get bytes(){return pr.encode({Type:be.Secp256k1,Data:this.marshal()}).subarray()}equals(e){return de(this.bytes,e.bytes)}async hash(){let e=he.digest(this.bytes),t;return Mt(e)?{bytes:t}=await e:t=e.bytes,t}},ys=class{_key;_publicKey;constructor(e,t){this._key=e,this._publicKey=t??S1(e),I1(this._key),Fh(this._publicKey)}sign(e){return v1(this._key,e)}get public(){return new ms(this._publicKey)}marshal(){return this._key}get bytes(){return mr.encode({Type:be.Secp256k1,Data:this.marshal()}).subarray()}equals(e){return de(this.bytes,e.bytes)}hash(){let e=he.digest(this.bytes);return Mt(e)?e.then(({bytes:t})=>t):e.bytes}async id(){let e=await this.public.hash();return Q(e,"base58btc")}async export(e,t="libp2p-key"){if(t==="libp2p-key")return oo(this.bytes,e);throw new F(`export format '${t}' is not supported`,"ERR_INVALID_EXPORT_FORMAT")}};function t6(r){return new ys(r)}function r6(r){return new ms(r)}async function n6(){let r=E1();return new ys(r)}var mi={rsa:Lh,ed25519:Ah,secp256k1:Vh};function _1(r){let e=Object.keys(mi).join(" / ");return new F(`invalid or unsupported key type ${r}. Must be ${e}`,"ERR_UNSUPPORTED_KEY_TYPE")}function Mh(r){let e=pr.decode(r),t=e.Data??new Uint8Array;switch(e.Type){case be.RSA:return mi.rsa.unmarshalRsaPublicKey(t);case be.Ed25519:return mi.ed25519.unmarshalEd25519PublicKey(t);case be.Secp256k1:return mi.secp256k1.unmarshalSecp256k1PublicKey(t);default:throw _1(e.Type??"unknown")}}async function k1(r){let e=mr.decode(r),t=e.Data??new Uint8Array;switch(e.Type){case be.RSA:return mi.rsa.unmarshalRsaPrivateKey(t);case be.Ed25519:return mi.ed25519.unmarshalEd25519PrivateKey(t);case be.Secp256k1:return mi.secp256k1.unmarshalSecp256k1PrivateKey(t);default:throw _1(e.Type??"RSA")}}var ed=re(Re(),1);var Qr="/",R1=new TextEncoder().encode(Qr),Cc=R1[0],Fe=class r{_buf;constructor(e,t){if(typeof e=="string")this._buf=Y(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]!==Cc)throw new Error("Invalid key")}toString(e="utf8"){return Q(this._buf,e)}uint8Array(){return this._buf}get[Symbol.toStringTag](){return`Key(${this.toString()})`}static withNamespaces(e){return new r(e.join(Qr))}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=R1),this._buf[0]!==Cc){let e=new Uint8Array(this._buf.byteLength+1);e.fill(Cc,0,1),e.set(this._buf,1),this._buf=e}for(;this._buf.byteLength>1&&this._buf[this._buf.byteLength-1]===Cc;)this._buf=this._buf.subarray(0,-1)}less(e){let t=this.list(),n=e.list();for(let i=0;i<t.length;i++){if(n.length<i+1)return!1;let o=t[i],s=n[i];if(o<s)return!0;if(o>s)return!1}return t.length<n.length}reverse(){return r.withNamespaces(this.list().slice().reverse())}namespaces(){return this.list()}baseNamespace(){let e=this.namespaces();return e[e.length-1]}list(){return this.toString().split(Qr).slice(1)}type(){return i6(this.baseNamespace())}name(){return o6(this.baseNamespace())}instance(e){return new r(this.toString()+":"+e)}path(){let e=this.parent().toString();return e.endsWith(Qr)||(e+=Qr),e+=this.type(),new r(e)}parent(){let e=this.list();return e.length===1?new r(Qr):new r(e.slice(0,-1).join(Qr))}child(e){return this.toString()===Qr?e:e.toString()===Qr?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(),...s6(e.map(t=>t.namespaces()))])}};function i6(r){let e=r.split(":");return e.length<2?"":e.slice(0,-1).join(":")}function o6(r){let e=r.split(":");return e[e.length-1]}function s6(r){return[].concat(...r)}var Gm=re(Nc(),1);var T1="ERR_IPNS_EXPIRED_RECORD",gs="ERR_UNRECOGNIZED_VALIDITY",C1="ERR_SIGNATURE_CREATION",en="ERR_SIGNATURE_VERIFICATION";var $h="ERR_UNDEFINED_PARAMETER",N1="ERR_INVALID_RECORD_DATA",U1="ERR_INVALID_VALUE",L1="ERR_INVALID_EMBEDDED_KEY",D1="ERR_MISSING_PRIVATE_KEY",P1="ERR_RECORD_TOO_LARGE";var je;(function(r){let e;(function(i){i.EOL="EOL"})(e=r.ValidityType||(r.ValidityType={}));let t;(function(i){i[i.EOL=0]="EOL"})(t||(t={})),function(i){i.codec=()=>si(t)}(e=r.ValidityType||(r.ValidityType={}));let n;r.codec=()=>(n==null&&(n=Ft((i,o,s={})=>{s.lengthDelimited!==!1&&o.fork(),i.value!=null&&(o.uint32(10),o.bytes(i.value)),i.signatureV1!=null&&(o.uint32(18),o.bytes(i.signatureV1)),i.validityType!=null&&(o.uint32(24),r.ValidityType.codec().encode(i.validityType,o)),i.validity!=null&&(o.uint32(34),o.bytes(i.validity)),i.sequence!=null&&(o.uint32(40),o.uint64(i.sequence)),i.ttl!=null&&(o.uint32(48),o.uint64(i.ttl)),i.pubKey!=null&&(o.uint32(58),o.bytes(i.pubKey)),i.signatureV2!=null&&(o.uint32(66),o.bytes(i.signatureV2)),i.data!=null&&(o.uint32(74),o.bytes(i.data)),s.lengthDelimited!==!1&&o.ldelim()},(i,o)=>{let s={},a=o==null?i.len:i.pos+o;for(;i.pos<a;){let c=i.uint32();switch(c>>>3){case 1:s.value=i.bytes();break;case 2:s.signatureV1=i.bytes();break;case 3:s.validityType=r.ValidityType.codec().decode(i);break;case 4:s.validity=i.bytes();break;case 5:s.sequence=i.uint64();break;case 6:s.ttl=i.uint64();break;case 7:s.pubKey=i.bytes();break;case 8:s.signatureV2=i.bytes();break;case 9:s.data=i.bytes();break;default:i.skipType(c&7);break}}return s})),n),r.encode=i=>Ot(i,r.codec()),r.decode=i=>Dt(i,r.codec())})(je||(je={}));var a6=["string","number","bigint","symbol"],c6=["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 O1(r){if(r===null)return"null";if(r===void 0)return"undefined";if(r===!0||r===!1)return"boolean";let e=typeof r;if(a6.includes(e))return e;if(e==="function")return"Function";if(Array.isArray(r))return"Array";if(l6(r))return"Buffer";let t=u6(r);return t||"Object"}function l6(r){return r&&r.constructor&&r.constructor.isBuffer&&r.constructor.isBuffer.call(null,r)}function u6(r){let e=Object.prototype.toString.call(r).slice(8,-1);if(c6.includes(e))return e}var b=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}};b.uint=new b(0,"uint",!0);b.negint=new b(1,"negint",!0);b.bytes=new b(2,"bytes",!0);b.string=new b(3,"string",!0);b.array=new b(4,"array",!1);b.map=new b(5,"map",!1);b.tag=new b(6,"tag",!1);b.float=new b(7,"float",!0);b.false=new b(7,"false",!0);b.true=new b(7,"true",!0);b.null=new b(7,"null",!0);b.undefined=new b(7,"undefined",!0);b.break=new b(7,"break",!0);var C=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 fo=globalThis.process&&!globalThis.process.browser&&globalThis.Buffer&&typeof globalThis.Buffer.isBuffer=="function",h6=new TextDecoder,d6=new TextEncoder;function Uc(r){return fo&&globalThis.Buffer.isBuffer(r)}function ws(r){return r instanceof Uint8Array?Uc(r)?new Uint8Array(r.buffer,r.byteOffset,r.byteLength):r:Uint8Array.from(r)}var H1=fo?(r,e,t)=>t-e>64?globalThis.Buffer.from(r.subarray(e,t)).toString("utf8"):V1(r,e,t):(r,e,t)=>t-e>64?h6.decode(r.subarray(e,t)):V1(r,e,t),Lc=fo?r=>r.length>64?globalThis.Buffer.from(r):F1(r):r=>r.length>64?d6.encode(r):F1(r),xr=r=>Uint8Array.from(r),po=fo?(r,e,t)=>Uc(r)?new Uint8Array(r.subarray(e,t)):r.slice(e,t):(r,e,t)=>r.slice(e,t),$1=fo?(r,e)=>(r=r.map(t=>t instanceof Uint8Array?t:globalThis.Buffer.from(t)),ws(globalThis.Buffer.concat(r,e))):(r,e)=>{let t=new Uint8Array(e),n=0;for(let i of r)n+i.length>t.length&&(i=i.subarray(0,t.length-n)),t.set(i,n),n+=i.length;return t},z1=fo?r=>globalThis.Buffer.allocUnsafe(r):r=>new Uint8Array(r);function K1(r,e){if(Uc(r)&&Uc(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 F1(r){let e=[],t=0;for(let n=0;n<r.length;n++){let i=r.charCodeAt(n);i<128?e[t++]=i:i<2048?(e[t++]=i>>6|192,e[t++]=i&63|128):(i&64512)===55296&&n+1<r.length&&(r.charCodeAt(n+1)&64512)===56320?(i=65536+((i&1023)<<10)+(r.charCodeAt(++n)&1023),e[t++]=i>>18|240,e[t++]=i>>12&63|128,e[t++]=i>>6&63|128,e[t++]=i&63|128):(e[t++]=i>>12|224,e[t++]=i>>6&63|128,e[t++]=i&63|128)}return e}function V1(r,e,t){let n=[];for(;e<t;){let i=r[e],o=null,s=i>239?4:i>223?3:i>191?2:1;if(e+s<=t){let a,c,u,l;switch(s){case 1:i<128&&(o=i);break;case 2:a=r[e+1],(a&192)===128&&(l=(i&31)<<6|a&63,l>127&&(o=l));break;case 3:a=r[e+1],c=r[e+2],(a&192)===128&&(c&192)===128&&(l=(i&15)<<12|(a&63)<<6|c&63,l>2047&&(l<55296||l>57343)&&(o=l));break;case 4:a=r[e+1],c=r[e+2],u=r[e+3],(a&192)===128&&(c&192)===128&&(u&192)===128&&(l=(i&15)<<18|(a&63)<<12|(c&63)<<6|u&63,l>65535&&l<1114112&&(o=l))}}o===null?(o=65533,s=1):o>65535&&(o-=65536,n.push(o>>>10&1023|55296),o=56320|o&1023),n.push(o),e+=s}return Kh(n)}var M1=4096;function Kh(r){let e=r.length;if(e<=M1)return String.fromCharCode.apply(String,r);let t="",n=0;for(;n<e;)t+=String.fromCharCode.apply(String,r.slice(n,n+=M1));return t}var f6=256,xs=class{constructor(e=f6){this.chunkSize=e,this.cursor=0,this.maxCursor=-1,this.chunks=[],this._initReuseChunk=null}reset(){this.cursor=0,this.maxCursor=-1,this.chunks.length&&(this.chunks=[]),this._initReuseChunk!==null&&(this.chunks.push(this._initReuseChunk),this.maxCursor=this._initReuseChunk.length-1)}push(e){let t=this.chunks[this.chunks.length-1];if(this.cursor+e.length<=this.maxCursor+1){let i=t.length-(this.maxCursor-this.cursor)-1;t.set(e,i)}else{if(t){let i=t.length-(this.maxCursor-this.cursor)-1;i<t.length&&(this.chunks[this.chunks.length-1]=t.subarray(0,i),this.maxCursor=this.cursor-1)}e.length<64&&e.length<this.chunkSize?(t=z1(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=$1(this.chunks,this.cursor);return e&&this.reset(),t}};var K="CBOR decode error:",tn="CBOR encode error:",bs=[];bs[23]=1;bs[24]=2;bs[25]=3;bs[26]=5;bs[27]=9;function rn(r,e,t){if(r.length-e<t)throw new Error(`${K} not enough data for type`)}var Me=[24,256,65536,4294967296,BigInt("18446744073709551616")];function St(r,e,t){rn(r,e,1);let n=r[e];if(t.strict===!0&&n<Me[0])throw new Error(`${K} integer encoded in more bytes than necessary (strict decode)`);return n}function _t(r,e,t){rn(r,e,2);let n=r[e]<<8|r[e+1];if(t.strict===!0&&n<Me[1])throw new Error(`${K} integer encoded in more bytes than necessary (strict decode)`);return n}function kt(r,e,t){rn(r,e,4);let n=r[e]*16777216+(r[e+1]<<16)+(r[e+2]<<8)+r[e+3];if(t.strict===!0&&n<Me[2])throw new Error(`${K} integer encoded in more bytes than necessary (strict decode)`);return n}function Rt(r,e,t){rn(r,e,8);let n=r[e]*16777216+(r[e+1]<<16)+(r[e+2]<<8)+r[e+3],i=r[e+4]*16777216+(r[e+5]<<16)+(r[e+6]<<8)+r[e+7],o=(BigInt(n)<<BigInt(32))+BigInt(i);if(t.strict===!0&&o<Me[3])throw new Error(`${K} integer encoded in more bytes than necessary (strict decode)`);if(o<=Number.MAX_SAFE_INTEGER)return Number(o);if(t.allowBigInt===!0)return o;throw new Error(`${K} integers outside of the safe integer range are not supported`)}function q1(r,e,t,n){return new C(b.uint,St(r,e+1,n),2)}function G1(r,e,t,n){return new C(b.uint,_t(r,e+1,n),3)}function j1(r,e,t,n){return new C(b.uint,kt(r,e+1,n),5)}function W1(r,e,t,n){return new C(b.uint,Rt(r,e+1,n),9)}function zt(r,e){return We(r,0,e.value)}function We(r,e,t){if(t<Me[0]){let n=Number(t);r.push([e|n])}else if(t<Me[1]){let n=Number(t);r.push([e|24,n])}else if(t<Me[2]){let n=Number(t);r.push([e|25,n>>>8,n&255])}else if(t<Me[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<Me[4]){let i=[e|27,0,0,0,0,0,0,0],o=Number(n&BigInt(4294967295)),s=Number(n>>BigInt(32)&BigInt(4294967295));i[8]=o&255,o=o>>8,i[7]=o&255,o=o>>8,i[6]=o&255,o=o>>8,i[5]=o&255,i[4]=s&255,s=s>>8,i[3]=s&255,s=s>>8,i[2]=s&255,s=s>>8,i[1]=s&255,r.push(i)}else throw new Error(`${K} encountered BigInt larger than allowable range`)}}zt.encodedSize=function(e){return We.encodedSize(e.value)};We.encodedSize=function(e){return e<Me[0]?1:e<Me[1]?2:e<Me[2]?3:e<Me[3]?5:9};zt.compareTokens=function(e,t){return e.value<t.value?-1:e.value>t.value?1:0};function Y1(r,e,t,n){return new C(b.negint,-1-St(r,e+1,n),2)}function X1(r,e,t,n){return new C(b.negint,-1-_t(r,e+1,n),3)}function Z1(r,e,t,n){return new C(b.negint,-1-kt(r,e+1,n),5)}var qh=BigInt(-1),J1=BigInt(1);function Q1(r,e,t,n){let i=Rt(r,e+1,n);if(typeof i!="bigint"){let o=-1-i;if(o>=Number.MIN_SAFE_INTEGER)return new C(b.negint,o,9)}if(n.allowBigInt!==!0)throw new Error(`${K} integers outside of the safe integer range are not supported`);return new C(b.negint,qh-BigInt(i),9)}function Dc(r,e){let t=e.value,n=typeof t=="bigint"?t*qh-J1:t*-1-1;We(r,e.type.majorEncoded,n)}Dc.encodedSize=function(e){let t=e.value,n=typeof t=="bigint"?t*qh-J1:t*-1-1;return n<Me[0]?1:n<Me[1]?2:n<Me[2]?3:n<Me[3]?5:9};Dc.compareTokens=function(e,t){return e.value<t.value?1:e.value>t.value?-1:0};function Es(r,e,t,n){rn(r,e,t+n);let i=po(r,e+t,e+t+n);return new C(b.bytes,i,t+n)}function em(r,e,t,n){return Es(r,e,1,t)}function tm(r,e,t,n){return Es(r,e,2,St(r,e+1,n))}function rm(r,e,t,n){return Es(r,e,3,_t(r,e+1,n))}function nm(r,e,t,n){return Es(r,e,5,kt(r,e+1,n))}function im(r,e,t,n){let i=Rt(r,e+1,n);if(typeof i=="bigint")throw new Error(`${K} 64-bit integer bytes lengths not supported`);return Es(r,e,9,i)}function Pc(r){return r.encodedBytes===void 0&&(r.encodedBytes=r.type===b.string?Lc(r.value):r.value),r.encodedBytes}function mo(r,e){let t=Pc(e);We(r,e.type.majorEncoded,t.length),r.push(t)}mo.encodedSize=function(e){let t=Pc(e);return We.encodedSize(t.length)+t.length};mo.compareTokens=function(e,t){return m6(Pc(e),Pc(t))};function m6(r,e){return r.length<e.length?-1:r.length>e.length?1:K1(r,e)}function vs(r,e,t,n,i){let o=t+n;rn(r,e,o);let s=new C(b.string,H1(r,e+t,e+o),o);return i.retainStringBytes===!0&&(s.byteValue=po(r,e+t,e+o)),s}function om(r,e,t,n){return vs(r,e,1,t,n)}function sm(r,e,t,n){return vs(r,e,2,St(r,e+1,n),n)}function am(r,e,t,n){return vs(r,e,3,_t(r,e+1,n),n)}function cm(r,e,t,n){return vs(r,e,5,kt(r,e+1,n),n)}function lm(r,e,t,n){let i=Rt(r,e+1,n);if(typeof i=="bigint")throw new Error(`${K} 64-bit integer string lengths not supported`);return vs(r,e,9,i,n)}var um=mo;function yo(r,e,t,n){return new C(b.array,n,t)}function hm(r,e,t,n){return yo(r,e,1,t)}function dm(r,e,t,n){return yo(r,e,2,St(r,e+1,n))}function fm(r,e,t,n){return yo(r,e,3,_t(r,e+1,n))}function pm(r,e,t,n){return yo(r,e,5,kt(r,e+1,n))}function mm(r,e,t,n){let i=Rt(r,e+1,n);if(typeof i=="bigint")throw new Error(`${K} 64-bit integer array lengths not supported`);return yo(r,e,9,i)}function ym(r,e,t,n){if(n.allowIndefinite===!1)throw new Error(`${K} indefinite length items not allowed`);return yo(r,e,1,1/0)}function Oc(r,e){We(r,b.array.majorEncoded,e.value)}Oc.compareTokens=zt.compareTokens;Oc.encodedSize=function(e){return We.encodedSize(e.value)};function go(r,e,t,n){return new C(b.map,n,t)}function gm(r,e,t,n){return go(r,e,1,t)}function wm(r,e,t,n){return go(r,e,2,St(r,e+1,n))}function xm(r,e,t,n){return go(r,e,3,_t(r,e+1,n))}function bm(r,e,t,n){return go(r,e,5,kt(r,e+1,n))}function Em(r,e,t,n){let i=Rt(r,e+1,n);if(typeof i=="bigint")throw new Error(`${K} 64-bit integer map lengths not supported`);return go(r,e,9,i)}function vm(r,e,t,n){if(n.allowIndefinite===!1)throw new Error(`${K} indefinite length items not allowed`);return go(r,e,1,1/0)}function Fc(r,e){We(r,b.map.majorEncoded,e.value)}Fc.compareTokens=zt.compareTokens;Fc.encodedSize=function(e){return We.encodedSize(e.value)};function Bm(r,e,t,n){return new C(b.tag,t,1)}function Am(r,e,t,n){return new C(b.tag,St(r,e+1,n),2)}function Im(r,e,t,n){return new C(b.tag,_t(r,e+1,n),3)}function Sm(r,e,t,n){return new C(b.tag,kt(r,e+1,n),5)}function _m(r,e,t,n){return new C(b.tag,Rt(r,e+1,n),9)}function Vc(r,e){We(r,b.tag.majorEncoded,e.value)}Vc.compareTokens=zt.compareTokens;Vc.encodedSize=function(e){return We.encodedSize(e.value)};var E6=20,v6=21,B6=22,A6=23;function km(r,e,t,n){if(n.allowUndefined===!1)throw new Error(`${K} undefined values are not supported`);return n.coerceUndefinedToNull===!0?new C(b.null,null,1):new C(b.undefined,void 0,1)}function Rm(r,e,t,n){if(n.allowIndefinite===!1)throw new Error(`${K} indefinite length items not allowed`);return new C(b.break,void 0,1)}function Gh(r,e,t){if(t){if(t.allowNaN===!1&&Number.isNaN(r))throw new Error(`${K} NaN values are not supported`);if(t.allowInfinity===!1&&(r===1/0||r===-1/0))throw new Error(`${K} Infinity values are not supported`)}return new C(b.float,r,e)}function Tm(r,e,t,n){return Gh(jh(r,e+1),3,n)}function Cm(r,e,t,n){return Gh(Wh(r,e+1),5,n)}function Nm(r,e,t,n){return Gh(Pm(r,e+1),9,n)}function Mc(r,e,t){let n=e.value;if(n===!1)r.push([b.float.majorEncoded|E6]);else if(n===!0)r.push([b.float.majorEncoded|v6]);else if(n===null)r.push([b.float.majorEncoded|B6]);else if(n===void 0)r.push([b.float.majorEncoded|A6]);else{let i,o=!1;(!t||t.float64!==!0)&&(Lm(n),i=jh(rr,1),n===i||Number.isNaN(n)?(rr[0]=249,r.push(rr.slice(0,3)),o=!0):(Dm(n),i=Wh(rr,1),n===i&&(rr[0]=250,r.push(rr.slice(0,5)),o=!0))),o||(I6(n),i=Pm(rr,1),rr[0]=251,r.push(rr.slice(0,9)))}}Mc.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){Lm(n);let i=jh(rr,1);if(n===i||Number.isNaN(n))return 3;if(Dm(n),i=Wh(rr,1),n===i)return 5}return 9};var Um=new ArrayBuffer(9),Kt=new DataView(Um,1),rr=new Uint8Array(Um,0);function Lm(r){if(r===1/0)Kt.setUint16(0,31744,!1);else if(r===-1/0)Kt.setUint16(0,64512,!1);else if(Number.isNaN(r))Kt.setUint16(0,32256,!1);else{Kt.setFloat32(0,r);let e=Kt.getUint32(0),t=(e&2139095040)>>23,n=e&8388607;if(t===255)Kt.setUint16(0,31744,!1);else if(t===0)Kt.setUint16(0,(r&2147483648)>>16|n>>13,!1);else{let i=t-127;i<-24?Kt.setUint16(0,0):i<-14?Kt.setUint16(0,(e&2147483648)>>16|1<<24+i,!1):Kt.setUint16(0,(e&2147483648)>>16|i+15<<10|n>>13,!1)}}}function jh(r,e){if(r.length-e<2)throw new Error(`${K} not enough data for float16`);let t=(r[e]<<8)+r[e+1];if(t===31744)return 1/0;if(t===64512)return-1/0;if(t===32256)return NaN;let n=t>>10&31,i=t&1023,o;return n===0?o=i*2**-24:n!==31?o=(i+1024)*2**(n-25):o=i===0?1/0:NaN,t&32768?-o:o}function Dm(r){Kt.setFloat32(0,r,!1)}function Wh(r,e){if(r.length-e<4)throw new Error(`${K} not enough data for float32`);let t=(r.byteOffset||0)+e;return new DataView(r.buffer,t,4).getFloat32(0,!1)}function I6(r){Kt.setFloat64(0,r,!1)}function Pm(r,e){if(r.length-e<8)throw new Error(`${K} not enough data for float64`);let t=(r.byteOffset||0)+e;return new DataView(r.buffer,t,8).getFloat64(0,!1)}Mc.compareTokens=zt.compareTokens;function ue(r,e,t){throw new Error(`${K} encountered invalid minor (${t}) for major ${r[e]>>>5}`)}function Hc(r){return()=>{throw new Error(`${K} ${r}`)}}var O=[];for(let r=0;r<=23;r++)O[r]=ue;O[24]=q1;O[25]=G1;O[26]=j1;O[27]=W1;O[28]=ue;O[29]=ue;O[30]=ue;O[31]=ue;for(let r=32;r<=55;r++)O[r]=ue;O[56]=Y1;O[57]=X1;O[58]=Z1;O[59]=Q1;O[60]=ue;O[61]=ue;O[62]=ue;O[63]=ue;for(let r=64;r<=87;r++)O[r]=em;O[88]=tm;O[89]=rm;O[90]=nm;O[91]=im;O[92]=ue;O[93]=ue;O[94]=ue;O[95]=Hc("indefinite length bytes/strings are not supported");for(let r=96;r<=119;r++)O[r]=om;O[120]=sm;O[121]=am;O[122]=cm;O[123]=lm;O[124]=ue;O[125]=ue;O[126]=ue;O[127]=Hc("indefinite length bytes/strings are not supported");for(let r=128;r<=151;r++)O[r]=hm;O[152]=dm;O[153]=fm;O[154]=pm;O[155]=mm;O[156]=ue;O[157]=ue;O[158]=ue;O[159]=ym;for(let r=160;r<=183;r++)O[r]=gm;O[184]=wm;O[185]=xm;O[186]=bm;O[187]=Em;O[188]=ue;O[189]=ue;O[190]=ue;O[191]=vm;for(let r=192;r<=215;r++)O[r]=Bm;O[216]=Am;O[217]=Im;O[218]=Sm;O[219]=_m;O[220]=ue;O[221]=ue;O[222]=ue;O[223]=ue;for(let r=224;r<=243;r++)O[r]=Hc("simple values are not supported");O[244]=ue;O[245]=ue;O[246]=ue;O[247]=km;O[248]=Hc("simple values are not supported");O[249]=Tm;O[250]=Cm;O[251]=Nm;O[252]=ue;O[253]=ue;O[254]=ue;O[255]=Rm;var nr=[];for(let r=0;r<24;r++)nr[r]=new C(b.uint,r,1);for(let r=-1;r>=-24;r--)nr[31-r]=new C(b.negint,r,1);nr[64]=new C(b.bytes,new Uint8Array(0),1);nr[96]=new C(b.string,"",1);nr[128]=new C(b.array,0,1);nr[160]=new C(b.map,0,1);nr[244]=new C(b.false,!1,1);nr[245]=new C(b.true,!0,1);nr[246]=new C(b.null,null,1);function Om(r){switch(r.type){case b.false:return xr([244]);case b.true:return xr([245]);case b.null:return xr([246]);case b.bytes:return r.value.length?void 0:xr([64]);case b.string:return r.value===""?xr([96]):void 0;case b.array:return r.value===0?xr([128]):void 0;case b.map:return r.value===0?xr([160]):void 0;case b.uint:return r.value<24?xr([Number(r.value)]):void 0;case b.negint:if(r.value>=-24)return xr([31-Number(r.value)])}}var _6={float64:!1,mapSorter:T6,quickEncodeToken:Om};function k6(){let r=[];return r[b.uint.major]=zt,r[b.negint.major]=Dc,r[b.bytes.major]=mo,r[b.string.major]=um,r[b.array.major]=Oc,r[b.map.major]=Fc,r[b.tag.major]=Vc,r[b.float.major]=Mc,r}var Fm=k6(),Yh=new xs,zc=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(`${tn} object contains circular references`);return new r(t,e)}},Vn={null:new C(b.null,null),undefined:new C(b.undefined,void 0),true:new C(b.true,!0),false:new C(b.false,!1),emptyArray:new C(b.array,0),emptyMap:new C(b.map,0)},Mn={number(r,e,t,n){return!Number.isInteger(r)||!Number.isSafeInteger(r)?new C(b.float,r):r>=0?new C(b.uint,r):new C(b.negint,r)},bigint(r,e,t,n){return r>=BigInt(0)?new C(b.uint,r):new C(b.negint,r)},Uint8Array(r,e,t,n){return new C(b.bytes,r)},string(r,e,t,n){return new C(b.string,r)},boolean(r,e,t,n){return r?Vn.true:Vn.false},null(r,e,t,n){return Vn.null},undefined(r,e,t,n){return Vn.undefined},ArrayBuffer(r,e,t,n){return new C(b.bytes,new Uint8Array(r))},DataView(r,e,t,n){return new C(b.bytes,new Uint8Array(r.buffer,r.byteOffset,r.byteLength))},Array(r,e,t,n){if(!r.length)return t.addBreakTokens===!0?[Vn.emptyArray,new C(b.break)]:Vn.emptyArray;n=zc.createCheck(n,r);let i=[],o=0;for(let s of r)i[o++]=$c(s,t,n);return t.addBreakTokens?[new C(b.array,r.length),i,new C(b.break)]:[new C(b.array,r.length),i]},Object(r,e,t,n){let i=e!=="Object",o=i?r.keys():Object.keys(r),s=i?r.size:o.length;if(!s)return t.addBreakTokens===!0?[Vn.emptyMap,new C(b.break)]:Vn.emptyMap;n=zc.createCheck(n,r);let a=[],c=0;for(let u of o)a[c++]=[$c(u,t,n),$c(i?r.get(u):r[u],t,n)];return R6(a,t),t.addBreakTokens?[new C(b.map,s),a,new C(b.break)]:[new C(b.map,s),a]}};Mn.Map=Mn.Object;Mn.Buffer=Mn.Uint8Array;for(let r of"Uint8Clamped Uint16 Uint32 Int8 Int16 Int32 BigUint64 BigInt64 Float32 Float64".split(" "))Mn[`${r}Array`]=Mn.DataView;function $c(r,e={},t){let n=O1(r),i=e&&e.typeEncoders&&e.typeEncoders[n]||Mn[n];if(typeof i=="function"){let s=i(r,n,e,t);if(s!=null)return s}let o=Mn[n];if(!o)throw new Error(`${tn} unsupported type: ${n}`);return o(r,n,e,t)}function R6(r,e){e.mapSorter&&r.sort(e.mapSorter)}function T6(r,e){let t=Array.isArray(r[0])?r[0][0]:r[0],n=Array.isArray(e[0])?e[0][0]:e[0];if(t.type!==n.type)return t.type.compare(n.type);let i=t.type.major,o=Fm[i].compareTokens(t,n);return o===0&&console.warn("WARNING: complex key types used, CBOR key sorting guarantees are gone"),o}function Vm(r,e,t,n){if(Array.isArray(e))for(let i of e)Vm(r,i,t,n);else t[e.type.major](r,e,n)}function Xh(r,e,t){let n=$c(r,t);if(!Array.isArray(n)&&t.quickEncodeToken){let i=t.quickEncodeToken(n);if(i)return i;let o=e[n.type.major];if(o.encodedSize){let s=o.encodedSize(n,t),a=new xs(s);if(o(a,n,t),a.chunks.length!==1)throw new Error(`Unexpected error: pre-calculated length for ${n} was wrong`);return ws(a.chunks[0])}}return Yh.reset(),Vm(Yh,n,e,t),Yh.toBytes(!0)}function gi(r,e){return e=Object.assign({},_6,e),Xh(r,Fm,e)}var C6={strict:!1,allowIndefinite:!0,allowUndefined:!0,allowBigInt:!0},Zh=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=nr[e];if(t===void 0){let n=O[e];if(!n)throw new Error(`${K} no decoder for major type ${e>>>5} (byte 0x${e.toString(16).padStart(2,"0")})`);let i=e&31;t=n(this.data,this._pos,i,this.options)}return this._pos+=t.encodedLength,t}},Bs=Symbol.for("DONE"),Kc=Symbol.for("BREAK");function N6(r,e,t){let n=[];for(let i=0;i<r.value;i++){let o=As(e,t);if(o===Kc){if(r.value===1/0)break;throw new Error(`${K} got unexpected break to lengthed array`)}if(o===Bs)throw new Error(`${K} found array but not enough entries (got ${i}, expected ${r.value})`);n[i]=o}return n}function U6(r,e,t){let n=t.useMaps===!0,i=n?void 0:{},o=n?new Map:void 0;for(let s=0;s<r.value;s++){let a=As(e,t);if(a===Kc){if(r.value===1/0)break;throw new Error(`${K} got unexpected break to lengthed map`)}if(a===Bs)throw new Error(`${K} found map but not enough entries (got ${s} [no key], expected ${r.value})`);if(n!==!0&&typeof a!="string")throw new Error(`${K} non-string keys not supported (got ${typeof a})`);if(t.rejectDuplicateMapKeys===!0&&(n&&o.has(a)||!n&&a in i))throw new Error(`${K} found repeat map key "${a}"`);let c=As(e,t);if(c===Bs)throw new Error(`${K} found map but not enough entries (got ${s} [no value], expected ${r.value})`);n?o.set(a,c):i[a]=c}return n?o:i}function As(r,e){if(r.done())return Bs;let t=r.next();if(t.type===b.break)return Kc;if(t.type.terminal)return t.value;if(t.type===b.array)return N6(t,r,e);if(t.type===b.map)return U6(t,r,e);if(t.type===b.tag){if(e.tags&&typeof e.tags[t.value]=="function"){let n=As(r,e);return e.tags[t.value](n)}throw new Error(`${K} tag not supported (${t.value})`)}throw new Error("unsupported")}function Jh(r,e){if(!(r instanceof Uint8Array))throw new Error(`${K} data to decode must be a Uint8Array`);e=Object.assign({},C6,e);let t=e.tokenizer||new Zh(r,e),n=As(t,e);if(n===Bs)throw new Error(`${K} did not find any content to decode`);if(n===Kc)throw new Error(`${K} got unexpected break`);return[n,r.subarray(t.pos())]}function at(r,e){let[t,n]=Jh(r,e);if(n.length>0)throw new Error(`${K} too many terminals, data makes no sense`);return t}var mt=re(Re(),1);var Mm=oe("ipns:utils"),Hm=Y("/ipns/"),L6=114,$m=async(r,e)=>{if(e==null||r==null){let n=new Error("one or more of the provided parameters are not defined");throw Mm.error(n),(0,mt.default)(n,$h)}let t;if(e.pubKey!=null){try{t=Mh(e.pubKey)}catch(i){throw Mm.error(i),i}if(!(await N0(e.pubKey)).equals(r))throw(0,mt.default)(new Error("Embedded public key did not match PeerID"),L1)}else r.publicKey!=null&&(t=Mh(r.publicKey));if(t!=null)return t;throw(0,mt.default)(new Error("no public key is available"),$h)},zm=(r,e,t)=>{let n=Y(e);return Ee([r,t,n])},Gc=r=>{let e=Y("ipns-signature:");return Ee([e,r])},nn=r=>"signatureV1"in r?je.encode({value:Y(r.value),signatureV1:r.signatureV1,validityType:r.validityType,validity:Y(r.validity),sequence:r.sequence,ttl:r.ttl,pubKey:r.pubKey,signatureV2:r.signatureV2,data:r.data}):je.encode({pubKey:r.pubKey,signatureV2:r.signatureV2,data:r.data});function ct(r){let e=je.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,mt.default)(new Error("missing data or signatureV2"),en);let t=qm(e.data),n=Qh(t.Value),i=Q(t.Validity);if(e.value!=null&&e.signatureV1!=null)return D6(e),{value:n,validityType:je.ValidityType.EOL,validity:i,sequence:t.Sequence,ttl:t.TTL,pubKey:e.pubKey,signatureV1:e.signatureV1,signatureV2:e.signatureV2,data:e.data};if(e.signatureV2!=null)return{value:n,validityType:je.ValidityType.EOL,validity:i,sequence:t.Sequence,ttl:t.TTL,pubKey:e.pubKey,signatureV2:e.signatureV2,data:e.data};throw new Error("invalid record: does not include signatureV1 or signatureV2")}var wo=r=>Ee([Hm,r.toBytes()]),xo=r=>Qo(r.slice(Hm.length)),Km=(r,e,t,n,i)=>{let o;if(e===je.ValidityType.EOL)o=0;else throw(0,mt.default)(new Error("Unknown validity type"),gs);return gi({Value:r,Validity:t,ValidityType:o,Sequence:n,TTL:i})},qm=r=>{let e=at(r);if(e.ValidityType===0)e.ValidityType=je.ValidityType.EOL;else throw(0,mt.default)(new Error("Unknown validity type"),gs);return Number.isInteger(e.Sequence)&&(e.Sequence=BigInt(e.Sequence)),Number.isInteger(e.TTL)&&(e.TTL=BigInt(e.TTL)),e},Qh=r=>{if(r!=null){if(Qf(r))return`/ipns/${r.toCID().toString(Sn)}`;if(r instanceof Uint8Array){let n=Q(r);n.startsWith("/")&&(r=n)}let e=r.toString().trim();if(e.startsWith("/")&&e.length>1)return e;let t=H.asCID(r);if(t!=null)return t.code===L6?`/ipns/${t.toString(Sn)}`:`/ipfs/${t.toV1().toString()}`;try{return r instanceof Uint8Array?`/ipfs/${H.decode(r).toV1().toString()}`:`/ipfs/${H.parse(e).toV1().toString()}`}catch{}}throw(0,mt.default)(new Error("Value must be a valid content path starting with /"),U1)},D6=r=>{if(r.data==null)throw(0,mt.default)(new Error("Record data is missing"),N1);let e=qm(r.data);if(!de(e.Value,r.value??new Uint8Array(0)))throw(0,mt.default)(new Error('Field "value" did not match between protobuf and CBOR'),en);if(!de(e.Validity,r.validity??new Uint8Array(0)))throw(0,mt.default)(new Error('Field "validity" did not match between protobuf and CBOR'),en);if(e.ValidityType!==r.validityType)throw(0,mt.default)(new Error('Field "validityType" did not match between protobuf and CBOR'),en);if(e.Sequence!==r.sequence)throw(0,mt.default)(new Error('Field "sequence" did not match between protobuf and CBOR'),en);if(e.TTL!==r.ttl)throw(0,mt.default)(new Error('Field "ttl" did not match between protobuf and CBOR'),en)};var P6=oe("ipns"),O6=et.code,F6="/ipns/",wT=F6.length,jm={v1Compatible:!0};async function Wm(r,e,t,n,i=jm){let o=new Gm.default(Date.now()+Number(n)),s=je.ValidityType.EOL,[a,c]=n.toString().split("."),u=BigInt(a)*BigInt(1e5)+BigInt(c??"0");return V6(r,e,t,s,o.toString(),u,i)}var V6=async(r,e,t,n,i,o,s=jm)=>{t=BigInt(t);let a=Y(i),c=Qh(e),u=Y(c);if(r.privateKey==null)throw(0,ed.default)(new Error("Missing private key"),D1);let l=await k1(r.privateKey),h=Km(u,n,a,t,o),p=Gc(h),d=await l.sign(p),f;if(r.publicKey!=null){let m=Et(r.toBytes());(m.code!==O6||!de(r.publicKey,m.digest))&&(f=r.publicKey)}if(s.v1Compatible===!0){let m=await M6(l,u,n,a),y={value:c,signatureV1:m,validity:i,validityType:n,sequence:t,ttl:o,signatureV2:d,data:h};return f!=null&&(y.pubKey=f),y}else{let m={value:c,validity:i,validityType:n,sequence:t,ttl:o,signatureV2:d,data:h};return f!=null&&(m.pubKey=f),m}};var M6=async(r,e,t,n)=>{try{let i=zm(e,t,n);return await r.sign(i)}catch(i){throw P6.error("record signature creation failed",i),(0,ed.default)(new Error("record signature creation failed"),C1)}};var Is=re(Re(),1),Ym=re(Nc(),1);var jc=oe("ipns:validator"),H6=1024*10,$6=async(r,e)=>{let t=ct(e),n;try{let i=Gc(t.data);n=await r.verify(i,t.signatureV2)}catch{n=!1}if(!n)throw jc.error("record signature verification failed"),(0,Is.default)(new Error("record signature verification failed"),en);if(t.validityType===je.ValidityType.EOL){if(Ym.default.fromString(t.validity).toDate().getTime()<Date.now())throw jc.error("record has expired"),(0,Is.default)(new Error("record has expired"),T1)}else if(t.validityType!=null)throw jc.error("unrecognized validity type"),(0,Is.default)(new Error("unrecognized validity type"),gs);jc("ipns record for %s is valid",t.value)};async function Wc(r,e){if(e.byteLength>H6)throw(0,Is.default)(new Error("record too large"),P1);let t=xo(r),n=ct(e),i=await $m(t,n);await $6(i,e)}async function*Ss(r){let e=/\r?\n/,t=new TextDecoder("utf8"),n="";for await(let i of r){typeof i=="string"&&(i=new TextEncoder().encode(i)),n+=t.decode(i,{stream:!0});let o=n.split(e);n=o.pop()??"";for(let s=0;s<o.length;s++)yield JSON.parse(o[s])}n+=t.decode(),n!==""&&(yield JSON.parse(n))}var rd=re(Zm(),1);var ks=class extends Error{constructor(e){super(e),this.name="TimeoutError"}},nd=class extends Error{constructor(e){super(),this.name="AbortError",this.message=e}},Jm=r=>globalThis.DOMException===void 0?new nd(r):new DOMException(r),Qm=r=>{let e=r.reason===void 0?Jm("This operation was aborted."):r.reason;return e instanceof Error?e:Jm(e)};function Rs(r,e){let{milliseconds:t,fallback:n,message:i,customTimers:o={setTimeout,clearTimeout}}=e,s,c=new Promise((u,l)=>{if(typeof t!="number"||Math.sign(t)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${t}\``);if(e.signal){let{signal:p}=e;p.aborted&&l(Qm(p)),p.addEventListener("abort",()=>{l(Qm(p))})}if(t===Number.POSITIVE_INFINITY){r.then(u,l);return}let h=new ks;s=o.setTimeout.call(void 0,()=>{if(n){try{u(n())}catch(p){l(p)}return}typeof r.cancel=="function"&&r.cancel(),i===!1?u():i instanceof Error?l(i):(h.message=i??`Promise timed out after ${t} milliseconds`,l(h))},t),(async()=>{try{u(await r)}catch(p){l(p)}})()}).finally(()=>{c.clear()});return c.clear=()=>{o.clearTimeout.call(void 0,s),s=void 0},c}function id(r,e,t){let n=0,i=r.length;for(;i>0;){let o=Math.trunc(i/2),s=n+o;t(r[s],e)<=0?(n=++s,i-=o+1):i=o}return n}var Ts=class{#e=[];enqueue(e,t){t={priority:0,...t};let n={priority:t.priority,run:e};if(this.size&&this.#e[this.size-1].priority>=t.priority){this.#e.push(n);return}let i=id(this.#e,n,(o,s)=>s.priority-o.priority);this.#e.splice(i,0,n)}dequeue(){return this.#e.shift()?.run}filter(e){return this.#e.filter(t=>t.priority===e.priority).map(t=>t.run)}get size(){return this.#e.length}};var yt=class extends rd.default{#e;#t;#r=0;#s;#c;#p=0;#i;#l;#n;#m;#o=0;#u;#a;#y;timeout;constructor(e){if(super(),e={carryoverConcurrencyCount:!1,intervalCap:Number.POSITIVE_INFINITY,interval:0,concurrency:Number.POSITIVE_INFINITY,autoStart:!0,queueClass:Ts,...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#x(){return this.#t||this.#r<this.#s}get#b(){return this.#o<this.#u}#E(){this.#o--,this.#h(),this.emit("next")}#v(){this.#w(),this.#g(),this.#l=void 0}get#B(){let e=Date.now();if(this.#i===void 0){let t=this.#p-e;if(t<0)this.#r=this.#e?this.#o:0;else return this.#l===void 0&&(this.#l=setTimeout(()=>{this.#v()},t)),!0}return!1}#h(){if(this.#n.size===0)return this.#i&&clearInterval(this.#i),this.#i=void 0,this.emit("empty"),this.#o===0&&this.emit("idle"),!1;if(!this.#a){let e=!this.#B;if(this.#x&&this.#b){let t=this.#n.dequeue();return t?(this.emit("active"),t(),e&&this.#g(),!0):!1}}return!1}#g(){this.#t||this.#i!==void 0||(this.#i=setInterval(()=>{this.#w()},this.#c),this.#p=Date.now()+this.#c)}#w(){this.#r===0&&this.#o===0&&this.#i&&(clearInterval(this.#i),this.#i=void 0),this.#r=this.#e?this.#o:0,this.#d()}#d(){for(;this.#h(););}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#A(e){return new Promise((t,n)=>{e.addEventListener("abort",()=>{n(e.reason)},{once:!0})})}async add(e,t={}){return t={timeout:this.timeout,throwOnTimeout:this.#y,...t},new Promise((n,i)=>{this.#n.enqueue(async()=>{this.#o++,this.#r++;try{t.signal?.throwIfAborted();let o=e({signal:t.signal});t.timeout&&(o=Rs(Promise.resolve(o),{milliseconds:t.timeout})),t.signal&&(o=Promise.race([o,this.#A(t.signal)]));let s=await o;n(s),this.emit("completed",s)}catch(o){if(o instanceof ks&&!t.throwOnTimeout){n();return}i(o),this.emit("error",o)}finally{this.#E()}},t),this.emit("add"),this.#h()})}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.#f("empty")}async onSizeLessThan(e){this.#n.size<e||await this.#f("next",()=>this.#n.size<e)}async onIdle(){this.#o===0&&this.#n.size===0||await this.#f("idle")}async#f(e,t){return new Promise(n=>{let i=()=>{t&&!t()||(this.off(e,i),n())};this.on(e,i)})}get size(){return this.#n.size}sizeBy(e){return this.#n.filter(e).length}get pending(){return this.#o}get isPaused(){return this.#a}};function q6(r){return r[Symbol.asyncIterator]!=null}function G6(r){if(q6(r))return(async()=>{for await(let e of r)return e})();for(let e of r)return e}var wi=G6;var od=Y("/ipns/");function ey(r){return de(r.subarray(0,od.byteLength),od)}var ty=r=>Qo(r.slice(od.length)),Xc=class{client;constructor(e){this.client=e}async*findProviders(e,t={}){yield*jt(this.client.getProviders(e,t),n=>({id:n.ID,multiaddrs:n.Addrs??[]}))}async provide(){}async put(e,t,n){if(!ey(e))return;let i=ty(e),o=ct(t);await this.client.putIPNS(i,o,n)}async get(e,t){if(!ey(e))throw new F("Not found","ERR_NOT_FOUND");let n=ty(e);try{let i=await this.client.getIPNS(n,t);return nn(i)}catch(i){throw i.code==="ERR_BAD_RESPONSE"?new F("Not found","ERR_NOT_FOUND"):i}}},Zc=class{client;constructor(e){this.client=e}async findPeer(e,t={}){let n=await wi(this.client.getPeers(e,t));if(n!=null)return{id:n.ID,multiaddrs:n.Addrs??[]};throw new F("Not found","ERR_NOT_FOUND")}async*getClosestPeers(e,t={}){}};var gt=oe("delegated-routing-v1-http-api-client"),ry={concurrentRequests:4,timeout:3e4},Jc=class{started;httpQueue;shutDownController;clientUrl;timeout;contentRouting;peerRouting;constructor(e,t={}){this.started=!1,this.shutDownController=new AbortController,la(1/0,this.shutDownController.signal),this.httpQueue=new yt({concurrency:t.concurrentRequests??ry.concurrentRequests}),this.clientUrl=e instanceof URL?e:new URL(e),this.timeout=t.timeout??ry.timeout,this.contentRouting=new Xc(this),this.peerRouting=new Zc(this)}get[jo](){return this.contentRouting}get[Wo](){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={}){gt("getProviders starts: %c",e);let n=ei([this.shutDownController.signal,t.signal,AbortSignal.timeout(this.timeout)]),i=Ue(),o=Ue();this.httpQueue.add(async()=>(i.resolve(),o.promise));try{await i.promise;let s=`${this.clientUrl}routing/v1/providers/${e.toString()}`,c=await fetch(s,{headers:{Accept:"application/x-ndjson"},signal:n});if(c.status===404)throw new F("No matching records found.","ERR_NOT_FOUND");if(c.status===422)throw new F("Request does not conform to schema or semantic constraints.","ERR_INVALID_REQUEST");if(c.body==null)throw new F("Routing response had no body","ERR_BAD_RESPONSE");if(c.headers.get("Content-Type")==="application/json"){let l=await c.json();for(let h of l.Providers){let p=this.#e(h);p!=null&&(yield p)}}else for await(let l of Ss(Sa(c.body))){let h=this.#e(l);h!=null&&(yield h)}}catch(s){gt.error("getProviders errored:",s)}finally{n.clear(),o.resolve(),gt("getProviders finished: %c",e)}}async*getPeers(e,t={}){gt("getPeers starts: %c",e);let n=ei([this.shutDownController.signal,t.signal,AbortSignal.timeout(this.timeout)]),i=Ue(),o=Ue();this.httpQueue.add(async()=>(i.resolve(),o.promise));try{await i.promise;let s=`${this.clientUrl}routing/v1/peers/${e.toCID().toString()}`,c=await fetch(s,{headers:{Accept:"application/x-ndjson"},signal:n});if(c.status===404)throw new F("No matching records found.","ERR_NOT_FOUND");if(c.status===422)throw new F("Request does not conform to schema or semantic constraints.","ERR_INVALID_REQUEST");if(c.body==null)throw new F("Routing response had no body","ERR_BAD_RESPONSE");if(c.headers.get("Content-Type")==="application/json"){let l=await c.json();for(let h of l.Peers){let p=this.#e(h);p!=null&&(yield p)}}else for await(let l of Ss(Sa(c.body))){let h=this.#e(l);h!=null&&(yield h)}}catch(s){gt.error("getPeers errored:",s)}finally{n.clear(),o.resolve(),gt("getPeers finished: %c",e)}}async getIPNS(e,t={}){gt("getIPNS starts: %c",e);let n=ei([this.shutDownController.signal,t.signal,AbortSignal.timeout(this.timeout)]),i=Ue(),o=Ue();this.httpQueue.add(async()=>(i.resolve(),o.promise));let s=`${this.clientUrl}routing/v1/ipns/${e.toCID().toString()}`;try{await i.promise;let c=await fetch(s,{headers:{Accept:"application/vnd.ipfs.ipns-record"},signal:n});if(gt("getIPNS GET %s %d",s,c.status),c.status===404)throw new F("No matching records found.","ERR_NOT_FOUND");if(c.status===422)throw new F("Request does not conform to schema or semantic constraints.","ERR_INVALID_REQUEST");if(c.body==null)throw new F("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 Wc(wo(e),l),ct(l)}catch(a){throw gt.error("getIPNS GET %s error:",s,a),a}finally{n.clear(),o.resolve(),gt("getIPNS finished: %c",e)}}async putIPNS(e,t,n={}){gt("putIPNS starts: %c",e);let i=ei([this.shutDownController.signal,n.signal,AbortSignal.timeout(this.timeout)]),o=Ue(),s=Ue();this.httpQueue.add(async()=>(o.resolve(),s.promise));let a=`${this.clientUrl}routing/v1/ipns/${e.toCID().toString()}`;try{await o.promise;let c=nn(t),l=await fetch(a,{method:"PUT",headers:{"Content-Type":"application/vnd.ipfs.ipns-record"},body:c,signal:i});if(gt("putIPNS PUT %s %d",a,l.status),l.status!==200)throw new F("PUT ipns response had status other than 200","ERR_BAD_RESPONSE")}catch(c){throw gt.error("putIPNS PUT %s error:",a,c.stack),c}finally{i.clear(),s.resolve(),gt("putIPNS finished: %c",e)}}#e(e){let t=[],n=e.Addrs?.map(sh)??[];return e.Protocols!=null&&t.push(...e.Protocols),e.Protocol!=null&&(t.push(e.Protocol),delete e.Protocol),{...e,Schema:"peer",ID:Yt(e.ID),Addrs:n,Protocols:t}}};function ny(r,e={}){return new Jc(new URL(r),e)}var iy=Y("/ipns/");function oy(r){return de(r.subarray(0,iy.byteLength),iy)}var sd=class{client;constructor(e){this.client=ny(e)}async provide(e,t){}async*findProviders(e,t){yield*jt(this.client.getProviders(e,t),n=>({id:n.ID,multiaddrs:n.Addrs,protocols:n.Protocols}))}async put(e,t,n){if(!oy(e))return;let i=xo(e),o=ct(t);await this.client.putIPNS(i,o,n)}async get(e,t){if(!oy(e))throw new F("Not found","ERR_NOT_FOUND");let n=xo(e);try{let i=await this.client.getIPNS(n,t);return nn(i)}catch(i){throw i.code==="ERR_BAD_RESPONSE"?new F("Not found","ERR_NOT_FOUND"):i}}async findPeer(e,t){let n=await wi(this.client.getPeers(e,t));if(n!=null)return{id:n.ID,multiaddrs:n.Addrs??[]};throw new F("Not found","ERR_NOT_FOUND")}async*getClosestPeers(e,t){}};function Cs(r){return new sd(new URL(r))}var ad=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 Qc(r,e,t,n){let i=new ad(n?.errorMessage,n?.errorCode);return t?.aborted===!0?Promise.reject(i):new Promise((o,s)=>{let a=u=>{try{if(n?.filter?.(u)===!1)return}catch(l){r.removeEventListener(e,a),t?.removeEventListener("abort",c),s(l);return}r.removeEventListener(e,a),t?.removeEventListener("abort",c),o(u)},c=()=>{r.removeEventListener(e,a),t?.removeEventListener("abort",c),s(i)};r.addEventListener(e,a),t?.addEventListener("abort",c)})}var el=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 sy(r,e,t){if(e==null)return r;if(e.aborted)return Promise.reject(new el(t?.errorMessage,t?.errorCode));let n,i=new el(t?.errorMessage,t?.errorCode);try{return await Promise.race([r,new Promise((o,s)=>{n=()=>{s(i)},e.addEventListener("abort",n)})])}finally{n!=null&&e.removeEventListener("abort",n)}}var tl=class{deferred;signal;where;constructor(e,t){this.signal=t,this.deferred=Ue(),this.where=e,this.onAbort=this.onAbort.bind(this),this.signal?.addEventListener("abort",this.onAbort)}onAbort(){this.deferred.reject(new En)}cleanup(){this.signal?.removeEventListener("abort",this.onAbort)}};function j6(){return`${parseInt(String(Math.random()*1e9),10).toString()}${Date.now()}`}var rl=class{id;fn;options;priority;recipients;status;timeline;controller;constructor(e,t,n=0){this.id=j6(),this.status="queued",this.fn=e,this.priority=n,this.options=t,this.recipients=[],this.timeline={created:Date.now()},this.controller=new AbortController,la(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 En)}async join(e={}){let t=new tl(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 sy(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 W6(r,e,t){let n=0,i=r.length;for(;i>0;){let o=Math.trunc(i/2),s=n+o;t(r[s],e)<=0?(n=++s,i-=o+1):i=o}return n}var Ns=class extends ca{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=W6(this.queue,e,(n,i)=>i.priority-n.priority);this.queue.splice(t,0,e)}async add(e,t){t?.signal?.throwIfAborted();let n=new rl(e,t,t?.priority),i=n.join(t).then(o=>(this.safeDispatchEvent("completed",{detail:o}),o)).catch(o=>{throw this.safeDispatchEvent("error",{detail:o}),o});return this.enqueue(n),this.safeDispatchEvent("add"),this.tryToStartAnother(),i}clear(){this.queue.splice(0,this.queue.length)}abort(){this.queue.forEach(e=>{e.abort(new En)}),this.clear()}async onEmpty(e){this.size!==0&&await Qc(this,"empty",e?.signal)}async onSizeLessThan(e,t){this.size<e||await Qc(this,"next",t?.signal,{filter:()=>this.size<e})}async onIdle(e){this.pending===0&&this.size===0||await Qc(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=Vt({objectMode:!0}),n=c=>{c!=null?this.abort():this.clear(),t.end(c)},i=c=>{c.detail!=null&&t.push(c.detail)},o=c=>{n(c.detail)},s=()=>{n()},a=()=>{n(new F("Queue aborted","ERR_QUEUE_ABORTED"))};this.addEventListener("completed",i),this.addEventListener("error",o),this.addEventListener("idle",s),e?.signal?.addEventListener("abort",a);try{yield*t}finally{this.removeEventListener("completed",i),this.removeEventListener("error",o),this.removeEventListener("idle",s),e?.signal?.removeEventListener("abort",a),n()}}};var uy="/pin/",ay="/pinned-block/",cd=Sn,cy=1;function ly(r){return r.version===0&&(r=r.toV1()),new Fe(`${uy}${r.toString(cd)}`)}var nl=class{datastore;blockstore;dagWalkers;constructor(e,t,n){this.datastore=e,this.blockstore=t,this.dagWalkers=n}async*add(e,t={}){let n=ly(e);if(await this.datastore.has(n))throw new Error("Already pinned");let i=Math.round(t.depth??1/0);if(i<0)throw new Error("Depth must be greater than or equal to 0");let o=new Ns({concurrency:cy});for await(let a of this.#e(e,o,{...t,depth:i}))await this.#t(a,c=>c.pinnedBy.find(u=>de(u,e.bytes))!=null?!1:(c.pinCount++,c.pinnedBy.push(e.bytes),!0),t),yield a;let s={depth:i,metadata:t.metadata??{}};await this.datastore.put(n,gi(s),t)}async*#e(e,t,n){if(n.depth===-1)return;let i=this.dagWalkers[e.code];if(i==null)throw new Error(`No dag walker found for cid codec ${e.code}`);let o=await this.blockstore.get(e,n);yield e;for await(let s of i.walk(o))yield*await t.add(async()=>this.#e(s,t,{...n,depth:n.depth-1}))}async#t(e,t,n){let i=new Fe(`${ay}${cd.encode(e.multihash.bytes)}`),o={pinCount:0,pinnedBy:[]};try{o=at(await this.datastore.get(i,n))}catch(a){if(a.code!=="ERR_NOT_FOUND")throw a}if(t(o)){if(o.pinCount===0&&await this.datastore.has(i)){await this.datastore.delete(i);return}await this.datastore.put(i,gi(o),n),n.onProgress?.(new P("helia:pin:add",e))}}async*rm(e,t={}){let n=ly(e),i=await this.datastore.get(n,t),o=at(i);await this.datastore.delete(n,t);let s=new Ns({concurrency:cy});for await(let a of this.#e(e,s,{...t,depth:o.depth}))await this.#t(a,c=>(c.pinCount--,c.pinnedBy=c.pinnedBy.filter(u=>de(u,e.bytes)),!0),{...t,depth:o.depth}),yield a}async*ls(e={}){for await(let{key:t,value:n}of this.datastore.query({prefix:uy+(e.cid!=null?`${e.cid.toString(Sn)}`:"")},e)){let i=H.parse(t.toString().substring(5),Sn),o=at(n);yield{cid:i,...o}}}async isPinned(e,t={}){let n=new Fe(`${ay}${cd.encode(e.multihash.bytes)}`);return this.datastore.has(n,t)}};function ld(r,e){let t={[Symbol.iterator]:()=>t,next:()=>{let n=r.next(),i=n.value;return n.done===!0||i==null?{done:!0,value:void 0}:{done:!1,value:e(i)}}};return t}var bo=class r{set;constructor(e){if(this.set=new Set,e!=null)for(let t of e)this.set.add(t.toString())}get size(){return this.set.size}[Symbol.iterator](){return this.values()}add(e){this.set.add(e.toString())}clear(){this.set.clear()}delete(e){this.set.delete(e.toString())}entries(){return ld(this.set.entries(),e=>{let t=Yt(e[0]);return[t,t]})}forEach(e){this.set.forEach(t=>{let n=Yt(t);e(n,n,this)})}has(e){return this.set.has(e.toString())}values(){return ld(this.set.values(),e=>Yt(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 il=class{log;routers;constructor(e,t){this.log=e.logger.forComponent("helia:routing"),this.routers=t.routers??[]}async start(){await vn(...this.routers)}async stop(){await Bn(...this.routers)}async*findProviders(e,t={}){if(this.routers.length===0)throw new F("No content routers available","ERR_NO_ROUTERS_AVAILABLE");let n=new bo;for await(let i of Vr(...Eo(this.routers,"findProviders").map(o=>o.findProviders(e,t))))i!=null&&(n.has(i.id)||(n.add(i.id),yield i))}async provide(e,t={}){if(this.routers.length===0)throw new F("No content routers available","ERR_NO_ROUTERS_AVAILABLE");await Promise.all(Eo(this.routers,"provide").map(async n=>{await n.provide(e,t)}))}async put(e,t,n){await Promise.all(Eo(this.routers,"put").map(async i=>{await i.put(e,t,n)}))}async get(e,t){return Promise.any(Eo(this.routers,"get").map(async n=>n.get(e,t)))}async findPeer(e,t){if(this.routers.length===0)throw new F("No peer routers available","ERR_NO_ROUTERS_AVAILABLE");let n=this,i=Vr(...Eo(this.routers,"findPeer").map(o=>async function*(){try{yield await o.findPeer(e,t)}catch(s){n.log.error(s)}}()));for await(let o of i)if(o!=null)return o;throw new F("Could not find peer in routing","ERR_NOT_FOUND")}async*getClosestPeers(e,t={}){if(this.routers.length===0)throw new F("No peer routers available","ERR_NO_ROUTERS_AVAILABLE");let n=new bo;for await(let i of Vr(...Eo(this.routers,"getClosestPeers").map(o=>o.getClosestPeers(e,t))))i!=null&&(n.has(i.id)||(n.add(i.id),yield i))}};function Eo(r,e){return r.filter(t=>t[e]!=null)}var Hn={},vo=r=>{r.addEventListener("message",e=>{vo.dispatchEvent("message",r,e)}),r.port!=null&&r.port.addEventListener("message",e=>{vo.dispatchEvent("message",r,e)})};vo.addEventListener=(r,e)=>{Hn[r]==null&&(Hn[r]=[]),Hn[r].push(e)};vo.removeEventListener=(r,e)=>{Hn[r]!=null&&(Hn[r]=Hn[r].filter(t=>t===e))};vo.dispatchEvent=function(r,e,t){Hn[r]!=null&&Hn[r].forEach(n=>n(e,t))};var ud=vo;var hd="lock:worker:request-read",dd="lock:worker:release-read",fd="lock:master:grant-read",pd="lock:worker:request-write",md="lock:worker:release-write",yd="lock:master:grant-write";var hy=(r=21)=>Math.random().toString().substring(2);var dy=(r,e,t,n,i)=>(o,s)=>{if(s.data.type!==t)return;let a={type:s.data.type,name:s.data.name,identifier:s.data.identifier};r.dispatchEvent(new MessageEvent(e,{data:{name:a.name,handler:async()=>{o.postMessage({type:i,name:a.name,identifier:a.identifier}),await new Promise(c=>{let u=l=>{if(l==null||l.data==null)return;let h={type:l.data.type,name:l.data.name,identifier:l.data.identifier};h.type===n&&h.identifier===a.identifier&&(o.removeEventListener("message",u),c())};o.addEventListener("message",u)})}}}))},fy=(r,e,t,n)=>async()=>{let i=hy();return globalThis.postMessage({type:e,identifier:i,name:r}),new Promise(o=>{let s=a=>{if(a==null||a.data==null)return;let c={type:a.data.type,identifier:a.data.identifier};c.type===t&&c.identifier===i&&(globalThis.removeEventListener("message",s),o(()=>{globalThis.postMessage({type:n,identifier:i,name:r})}))};globalThis.addEventListener("message",s)})},Y6={singleProcess:!1},py=r=>{if(r=Object.assign({},Y6,r),!!globalThis.document||r.singleProcess){let t=new EventTarget;return ud.addEventListener("message",dy(t,"requestReadLock",hd,dd,fd)),ud.addEventListener("message",dy(t,"requestWriteLock",pd,md,yd)),t}return{isWorker:!0,readLock:t=>fy(t,hd,fd,dd),writeLock:t=>fy(t,pd,yd,md)}};var xi={},$n;async function gd(r,e){let t,n=new Promise(i=>{t=i});return r.add(async()=>Rs((async()=>{await new Promise(i=>{t(()=>{i()})})})(),{milliseconds:e.timeout})),n}var X6=(r,e)=>{if($n.isWorker===!0)return{readLock:$n.readLock(r,e),writeLock:$n.writeLock(r,e)};let t=new yt({concurrency:1}),n;return{async readLock(){if(n!=null)return gd(n,e);n=new yt({concurrency:e.concurrency,autoStart:!1});let i=n,o=gd(n,e);return t.add(async()=>{i.start(),await i.onIdle().then(()=>{n===i&&(n=null)})}),o},async writeLock(){return n=null,gd(t,e)}}},Z6={name:"lock",concurrency:1/0,timeout:846e5,singleProcess:!1};function wd(r){let e=Object.assign({},Z6,r);return $n==null&&($n=py(e),$n.isWorker!==!0&&($n.addEventListener("requestReadLock",t=>{xi[t.data.name]!=null&&xi[t.data.name].readLock().then(async n=>t.data.handler().finally(()=>{n()}))}),$n.addEventListener("requestWriteLock",async t=>{xi[t.data.name]!=null&&xi[t.data.name].writeLock().then(async n=>t.data.handler().finally(()=>{n()}))}))),xi[e.name]==null&&(xi[e.name]=X6(e.name,e)),xi[e.name]}var ol=class{lock;child;pins;started;constructor(e,t,n={}){this.child=e,this.pins=t,this.lock=wd({singleProcess:n.holdGcLock}),this.started=!1}isStarted(){return this.started}async start(){await vn(this.child),this.started=!0}async stop(){await Bn(this.child),this.started=!1}unwrap(){return this.child}async put(e,t,n={}){let i=await this.lock.readLock();try{return await this.child.put(e,t,n)}finally{i()}}async*putMany(e,t={}){let n=await this.lock.readLock();try{yield*this.child.putMany(e,t)}finally{n()}}async get(e,t={}){let n=await this.lock.readLock();try{return await this.child.get(e,t)}finally{n()}}async*getMany(e,t={}){let n=await this.lock.readLock();try{yield*this.child.getMany(e,t)}finally{n()}}async delete(e,t={}){let n=await this.lock.writeLock();try{if(await this.pins.isPinned(e))throw new Error("CID was pinned");await this.child.delete(e,t)}finally{n()}}async*deleteMany(e,t={}){let n=await this.lock.writeLock();try{let i=this;yield*this.child.deleteMany(async function*(){for await(let o of e){if(await i.pins.isPinned(o))throw new Error("CID was pinned");yield o}}(),t)}finally{n()}}async has(e,t={}){let n=await this.lock.readLock();try{return await this.child.has(e,t)}finally{n()}}async*getAll(e={}){let t=await this.lock.readLock();try{yield*this.child.getAll(e)}finally{t()}}};var yy=42;function J6(r){return r instanceof ArrayBuffer?new Uint8Array(r,0,r.byteLength):r}function Q6(r){if(r.asCID!==r&&r["/"]!==r.bytes)return null;let e=H.asCID(r);if(!e)return null;let t=new Uint8Array(e.bytes.byteLength+1);return t.set(e.bytes,1),[new C(b.tag,yy),new C(b.bytes,t)]}function ev(){throw new Error("`undefined` is not supported by the IPLD Data Model and cannot be encoded")}function tv(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 my={float64:!0,typeEncoders:{Object:Q6,undefined:ev,number:tv}},xN={...my,typeEncoders:{...my.typeEncoders}};function rv(r){if(r[0]!==0)throw new Error("Invalid CID for CBOR tag 42; expected leading 0x00");return H.decode(r.subarray(1))}var sl={allowIndefinite:!1,coerceUndefinedToNull:!0,allowNaN:!1,allowInfinity:!1,allowBigInt:!0,strict:!0,useMaps:!1,rejectDuplicateMapKeys:!0,tags:[]};sl.tags[yy]=rv;var bN={...sl,tags:sl.tags.slice()};var Bo=113;var gy=r=>at(J6(r),sl);var bd=class extends Array{constructor(){super(),this.inRecursive=[]}prefix(e){let t=this.inRecursive[this.inRecursive.length-1];t&&(t.type===b.array&&(t.elements++,t.elements!==1&&e.push([44])),t.type===b.map&&(t.elements++,t.elements!==1&&(t.elements%2===1?e.push([44]):e.push([58]))))}[b.uint.major](e,t){this.prefix(e);let n=String(t.value),i=[];for(let o=0;o<n.length;o++)i[o]=n.charCodeAt(o);e.push(i)}[b.negint.major](e,t){this[b.uint.major](e,t)}[b.bytes.major](e,t){throw new Error(`${tn} unsupported type: Uint8Array`)}[b.string.major](e,t){this.prefix(e);let n=Lc(JSON.stringify(t.value));e.push(n.length>32?ws(n):n)}[b.array.major](e,t){this.prefix(e),this.inRecursive.push({type:b.array,elements:0}),e.push([91])}[b.map.major](e,t){this.prefix(e),this.inRecursive.push({type:b.map,elements:0}),e.push([123])}[b.tag.major](e,t){}[b.float.major](e,t){if(t.type.name==="break"){let s=this.inRecursive.pop();if(s){if(s.type===b.array)e.push([93]);else if(s.type===b.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(`${tn} unsupported type: undefined`);if(this.prefix(e),t.type.name==="true"){e.push([116,114,117,101]);return}else if(t.type.name==="false"){e.push([102,97,108,115,101]);return}else if(t.type.name==="null"){e.push([110,117,108,108]);return}let n=String(t.value),i=[],o=!1;for(let s=0;s<n.length;s++)i[s]=n.charCodeAt(s),!o&&(i[s]===46||i[s]===101||i[s]===69)&&(o=!0);o||(i.push(46),i.push(48)),e.push(i)}};function nv(r,e){if(Array.isArray(r[0])||Array.isArray(e[0]))throw new Error(`${tn} complex map keys are not supported`);let t=r[0],n=e[0];if(t.type!==b.string||n.type!==b.string)throw new Error(`${tn} non-string map keys are not supported`);if(t<n)return-1;if(t>n)return 1;throw new Error(`${tn} unexpected duplicate map keys, this is not supported`)}var iv={addBreakTokens:!0,mapSorter:nv};function al(r,e){return e=Object.assign({},iv,e),Xh(r,new bd,e)}var zn=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(`${K} 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(`${K} unexpected token at position ${this._pos}, expected to find '${String.fromCharCode(...e)}'`)}parseNumber(){let e=this._pos,t=!1,n=!1,i=a=>{for(;!this.done();){let c=this.ch();if(a.includes(c))this._pos++;else break}};if(this.ch()===45&&(t=!0,this._pos++),this.ch()===48)if(this._pos++,this.ch()===46)this._pos++,n=!0;else return new C(b.uint,0,this._pos-e);if(i([48,49,50,51,52,53,54,55,56,57]),t&&this._pos===e+1)throw new Error(`${K} unexpected token at position ${this._pos}`);if(!this.done()&&this.ch()===46){if(n)throw new Error(`${K} unexpected token at position ${this._pos}`);n=!0,this._pos++,i([48,49,50,51,52,53,54,55,56,57])}!this.done()&&(this.ch()===101||this.ch()===69)&&(n=!0,this._pos++,!this.done()&&(this.ch()===43||this.ch()===45)&&this._pos++,i([48,49,50,51,52,53,54,55,56,57]));let o=String.fromCharCode.apply(null,this.data.subarray(e,this._pos)),s=parseFloat(o);return n?new C(b.float,s,this._pos-e):this.options.allowBigInt!==!0||Number.isSafeInteger(s)?new C(s>=0?b.uint:b.negint,s,this._pos-e):new C(s>=0?b.uint:b.negint,BigInt(o),this._pos-e)}parseString(){if(this.ch()!==34)throw new Error(`${K} unexpected character at position ${this._pos}; this shouldn't happen`);this._pos++;for(let o=this._pos,s=0;o<this.data.length&&s<65536;o++,s++){let a=this.data[o];if(a===92||a<32||a>=128)break;if(a===34){let c=String.fromCharCode.apply(null,this.data.subarray(this._pos,o));return this._pos=o+1,new C(b.string,c,s)}}let e=this._pos,t=[],n=()=>{if(this._pos+4>=this.data.length)throw new Error(`${K} unexpected end of unicode escape sequence at position ${this._pos}`);let o=0;for(let s=0;s<4;s++){let a=this.ch();if(a>=48&&a<=57)a-=48;else if(a>=97&&a<=102)a=a-97+10;else if(a>=65&&a<=70)a=a-65+10;else throw new Error(`${K} unexpected unicode escape character at position ${this._pos}`);o=o*16+a,this._pos++}return o},i=()=>{let o=this.ch(),s=null,a=o>239?4:o>223?3:o>191?2:1;if(this._pos+a>this.data.length)throw new Error(`${K} unexpected unicode sequence at position ${this._pos}`);let c,u,l,h;switch(a){case 1:o<128&&(s=o);break;case 2:c=this.data[this._pos+1],(c&192)===128&&(h=(o&31)<<6|c&63,h>127&&(s=h));break;case 3:c=this.data[this._pos+1],u=this.data[this._pos+2],(c&192)===128&&(u&192)===128&&(h=(o&15)<<12|(c&63)<<6|u&63,h>2047&&(h<55296||h>57343)&&(s=h));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&&(h=(o&15)<<18|(c&63)<<12|(u&63)<<6|l&63,h>65535&&h<1114112&&(s=h))}s===null?(s=65533,a=1):s>65535&&(s-=65536,t.push(s>>>10&1023|55296),s=56320|s&1023),t.push(s),this._pos+=a};for(;!this.done();){let o=this.ch(),s;switch(o){case 92:if(this._pos++,this.done())throw new Error(`${K} 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(`${K} unexpected string escape character at position ${this._pos}`)}break;case 34:return this._pos++,new C(b.string,Kh(t),this._pos-e);default:if(o<32)throw new Error(`${K} invalid control character at position ${this._pos}`);o<128?(t.push(o),this._pos++):i()}}throw new Error(`${K} unexpected end of string at position ${this._pos}`)}parseValue(){switch(this.ch()){case 123:return this.modeStack.push("obj-start"),this._pos++,new C(b.map,1/0,1);case 91:return this.modeStack.push("array-start"),this._pos++,new C(b.array,1/0,1);case 34:return this.parseString();case 110:return this.expect([110,117,108,108]),new C(b.null,null,4);case 102:return this.expect([102,97,108,115,101]),new C(b.false,!1,5);case 116:return this.expect([116,114,117,101]),new C(b.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(`${K} 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 C(b.break,void 0,1);if(this.ch()!==44)throw new Error(`${K} 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 C(b.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 C(b.break,void 0,1);if(this.ch()!==44)throw new Error(`${K} 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 C(b.break,void 0,1);let e=this.parseString();if(this.skipWhitespace(),this.ch()!==58)throw new Error(`${K} 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(`${K} unexpected parse state at position ${this._pos}; this shouldn't happen`)}}};function Us(r,e){return e=Object.assign({tokenizer:new zn(r,e)},e),at(r,e)}function ov(r){return r instanceof ArrayBuffer?new Uint8Array(r,0,r.byteLength):r}var Ed=class extends zn{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===b.map){let t=this._next();if(t.type===b.string&&t.value==="/"){let n=this._next();if(n.type===b.string){if(this._next().type!==b.break)throw new Error("Invalid encoded CID form");return this.tokenBuffer.push(n),new C(b.tag,42,0)}if(n.type===b.map){let i=this._next();if(i.type===b.string&&i.value==="bytes"){let o=this._next();if(o.type===b.string){for(let a=0;a<2;a++)if(this._next().type!==b.break)throw new Error("Invalid encoded Bytes form");let s=Pr.decode(`m${o.value}`);return new C(b.bytes,s,o.value.length)}this.tokenBuffer.push(o)}this.tokenBuffer.push(i)}this.tokenBuffer.push(n)}this.tokenBuffer.push(t)}return e}},vd={allowIndefinite:!1,allowUndefined:!1,allowNaN:!1,allowInfinity:!1,allowBigInt:!0,strict:!0,useMaps:!1,rejectDuplicateMapKeys:!0,tags:[]};vd.tags[42]=H.parse;var Ao=297;var xy=r=>{let e=ov(r),t=Object.assign(vd,{tokenizer:new Ed(e,vd)});return Us(e,t)};var ON=new TextDecoder;var FN=new TextEncoder;var De={};Ae(De,{code:()=>Te,createLink:()=>Ry,createNode:()=>ky,decode:()=>ve,encode:()=>ce,name:()=>yv,prepare:()=>_e,validate:()=>Sd});var sv=new TextDecoder;function Ad(r,e){let t=0;for(let n=0;;n+=7){if(n>=64)throw new Error("protobuf: varint overflow");if(e>=r.length)throw new Error("protobuf: unexpected end of data");let i=r[e++];if(t+=n<28?(i&127)<<n:(i&127)*2**n,i<128)break}return[t,e]}function cl(r,e){let t;[t,e]=Ad(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 by(r,e){let t;return[t,e]=Ad(r,e),[t&7,t>>3,e]}function av(r){let e={},t=r.length,n=0;for(;n<t;){let i,o;if([i,o,n]=by(r,n),o===1){if(e.Hash)throw new Error("protobuf: (PBLink) duplicate Hash section");if(i!==2)throw new Error(`protobuf: (PBLink) wrong wireType (${i}) for Hash`);if(e.Name!==void 0)throw new Error("protobuf: (PBLink) invalid order, found Name before Hash");if(e.Tsize!==void 0)throw new Error("protobuf: (PBLink) invalid order, found Tsize before Hash");[e.Hash,n]=cl(r,n)}else if(o===2){if(e.Name!==void 0)throw new Error("protobuf: (PBLink) duplicate Name section");if(i!==2)throw new Error(`protobuf: (PBLink) wrong wireType (${i}) for Name`);if(e.Tsize!==void 0)throw new Error("protobuf: (PBLink) invalid order, found Tsize before Name");let s;[s,n]=cl(r,n),e.Name=sv.decode(s)}else if(o===3){if(e.Tsize!==void 0)throw new Error("protobuf: (PBLink) duplicate Tsize section");if(i!==0)throw new Error(`protobuf: (PBLink) wrong wireType (${i}) for Tsize`);[e.Tsize,n]=Ad(r,n)}else throw new Error(`protobuf: (PBLink) invalid fieldNumber, expected 1, 2 or 3, got ${o}`)}if(n>t)throw new Error("protobuf: (PBLink) unexpected end of data");return e}function Ey(r){let e=r.length,t=0,n,i=!1,o;for(;t<e;){let a,c;if([a,c,t]=by(r,t),a!==2)throw new Error(`protobuf: (PBNode) invalid wireType, expected 2, got ${a}`);if(c===1){if(o)throw new Error("protobuf: (PBNode) duplicate Data section");[o,t]=cl(r,t),n&&(i=!0)}else if(c===2){if(i)throw new Error("protobuf: (PBNode) duplicate Links section");n||(n=[]);let u;[u,t]=cl(r,t),n.push(av(u))}else throw new Error(`protobuf: (PBNode) invalid fieldNumber, expected 1 or 2, got ${c}`)}if(t>e)throw new Error("protobuf: (PBNode) unexpected end of data");let s={};return o&&(s.Data=o),s.Links=n||[],s}var By=new TextEncoder,vy=2**32,cv=2**31;function lv(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=Ls(e,t,r.Tsize)-1,e[t]=24}if(typeof r.Name=="string"){let n=By.encode(r.Name);t-=n.length,e.set(n,t),t=Ls(e,t,n.length)-1,e[t]=18}return r.Hash&&(t-=r.Hash.length,e.set(r.Hash,t),t=Ls(e,t,r.Hash.length)-1,e[t]=10),e.length-t}function Ay(r){let e=hv(r),t=new Uint8Array(e),n=e;if(r.Data&&(n-=r.Data.length,t.set(r.Data,n),n=Ls(t,n,r.Data.length)-1,t[n]=10),r.Links)for(let i=r.Links.length-1;i>=0;i--){let o=lv(r.Links[i],t.subarray(0,n));n-=o,n=Ls(t,n,o)-1,t[n]=18}return t}function uv(r){let e=0;if(r.Hash){let t=r.Hash.length;e+=1+t+Io(t)}if(typeof r.Name=="string"){let t=By.encode(r.Name).length;e+=1+t+Io(t)}return typeof r.Tsize=="number"&&(e+=1+Io(r.Tsize)),e}function hv(r){let e=0;if(r.Data){let t=r.Data.length;e+=1+t+Io(t)}if(r.Links)for(let t of r.Links){let n=uv(t);e+=1+n+Io(n)}return e}function Ls(r,e,t){e-=Io(t);let n=e;for(;t>=cv;)r[e++]=t&127|128,t/=128;for(;t>=128;)r[e++]=t&127|128,t>>>=7;return r[e]=t,n}function Io(r){return r%2===0&&r++,Math.floor((dv(r)+6)/7)}function dv(r){let e=0;return r>=vy&&(r=Math.floor(r/vy),e=32),r>=65536&&(r>>>=16,e+=16),r>=256&&(r>>>=8,e+=8),e+fv[r]}var fv=[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 pv=["Data","Links"],mv=["Hash","Name","Tsize"],Id=new TextEncoder;function Sy(r,e){if(r===e)return 0;let t=r.Name?Id.encode(r.Name):[],n=e.Name?Id.encode(e.Name):[],i=t.length,o=n.length;for(let s=0,a=Math.min(i,o);s<a;++s)if(t[s]!==n[s]){i=t[s],o=n[s];break}return i<o?-1:o<i?1:0}function Iy(r,e){return!Object.keys(r).some(t=>!e.includes(t))}function _y(r){if(typeof r.asCID=="object"){let t=H.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=H.asCID(r.Hash);try{t||(typeof r.Hash=="string"?t=H.parse(r.Hash):r.Hash instanceof Uint8Array&&(t=H.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=Id.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(_y),e.Links.sort(Sy);else throw new TypeError("Invalid DAG-PB form");else e.Links=[];return e}function Sd(r){if(!r||typeof r!="object"||Array.isArray(r)||r instanceof Uint8Array||r["/"]&&r["/"]===r.bytes)throw new TypeError("Invalid DAG-PB form");if(!Iy(r,pv))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(!Iy(t,mv))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&&Sy(t,r.Links[e-1])===-1)throw new TypeError("Invalid DAG-PB form (links must be sorted by Name bytes)")}}function ky(r,e=[]){return _e({Data:r,Links:e})}function Ry(r,e,t){return _y({Hash:t,Name:r,Tsize:e})}function Ty(r){return r instanceof ArrayBuffer?new Uint8Array(r,0,r.byteLength):r}var yv="dag-pb",Te=112;function ce(r){Sd(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),Ay(e)}function ve(r){let e=Ty(r),t=Ey(e),n={};return t.Data&&(n.Data=t.Data),t.Links&&(n.Links=t.Links.map(i=>{let o={};try{o.Hash=H.decode(i.Hash)}catch{}if(!o.Hash)throw new Error("Invalid Hash field found in link, expected CID");return i.Name!==void 0&&(o.Name=i.Name),i.Tsize!==void 0&&(o.Tsize=i.Tsize),o})),n}var gv={codec:Te,*walk(r){yield*ve(r).Links.map(t=>t.Hash)}},wv={codec:Ne,*walk(){}},Cy=42,xv={codec:Bo,*walk(r){let e=[],t=[];t[Cy]=n=>{if(n[0]!==0)throw new Error("Invalid CID for CBOR tag 42; expected leading 0x00");let i=H.decode(n.subarray(1));return e.push(i),i},at(r,{tags:t}),yield*e}},_d=class extends zn{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===b.map){let t=this._next();if(t.type===b.string&&t.value==="/"){let n=this._next();if(n.type===b.string){if(this._next().type!==b.break)throw new Error("Invalid encoded CID form");return this.tokenBuffer.push(n),new C(b.tag,42,0)}if(n.type===b.map){let i=this._next();if(i.type===b.string&&i.value==="bytes"){let o=this._next();if(o.type===b.string){for(let a=0;a<2;a++)if(this._next().type!==b.break)throw new Error("Invalid encoded Bytes form");let s=Pr.decode(`m${o.value}`);return new C(b.bytes,s,o.value.length)}this.tokenBuffer.push(o)}this.tokenBuffer.push(i)}this.tokenBuffer.push(n)}this.tokenBuffer.push(t)}return e}},bv={codec:Ao,*walk(r){let e=[],t=[];t[Cy]=n=>{let i=H.parse(n);return e.push(i),i},Us(r,{tags:t,tokenizer:new _d(r,{tags:t,allowIndefinite:!0,allowUndefined:!0,allowNaN:!0,allowInfinity:!0,allowBigInt:!0,strict:!1,rejectDuplicateMapKeys:!1})}),yield*e}},Ev={codec:$i,*walk(){}};function Ny(r=[]){let e={};return[gv,wv,xv,bv,Ev,...r].forEach(t=>{e[t.codec]=t}),e}var kd=new Fe("/version"),Uy=1;async function Ly(r){if(!await r.has(kd)){await r.put(kd,Y(`${Uy}`));return}let e=await r.get(kd),t=Q(e);if(parseInt(t,10)!==Uy)throw new Error("Unknown datastore version, a datastore migration may be required")}function Dy(r=[]){let e={};return[he,fu,et,...r].forEach(t=>{e[t.code]=t}),e}var br=class{has(e,t){return Promise.reject(new Error(".has is not implemented"))}put(e,t,n){return Promise.reject(new Error(".put is not implemented"))}async*putMany(e,t){for await(let{cid:n,block:i}of e)await this.put(n,i,t),yield n}get(e,t){return Promise.reject(new Error(".get is not implemented"))}async*getMany(e,t){for await(let n of e)yield{cid:n,block:await this.get(n,t)}}delete(e,t){return Promise.reject(new Error(".delete is not implemented"))}async*deleteMany(e,t){for await(let n of e)await this.delete(n,t),yield n}async*getAll(e){throw new Error(".getAll is not implemented")}};var bi={};Ae(bi,{abortedError:()=>Sv,closeFailedError:()=>Bv,deleteFailedError:()=>Td,getFailedError:()=>Av,hasFailedError:()=>Iv,notFoundError:()=>Kn,openFailedError:()=>vv,putFailedError:()=>Rd});var on=re(Re(),1);function vv(r){return r=r??new Error("Open failed"),(0,on.default)(r,"ERR_OPEN_FAILED")}function Bv(r){return r=r??new Error("Close failed"),(0,on.default)(r,"ERR_CLOSE_FAILED")}function Rd(r){return r=r??new Error("Put failed"),(0,on.default)(r,"ERR_PUT_FAILED")}function Av(r){return r=r??new Error("Get failed"),(0,on.default)(r,"ERR_GET_FAILED")}function Td(r){return r=r??new Error("Delete failed"),(0,on.default)(r,"ERR_DELETE_FAILED")}function Iv(r){return r=r??new Error("Has failed"),(0,on.default)(r,"ERR_HAS_FAILED")}function Kn(r){return r=r??new Error("Not Found"),(0,on.default)(r,"ERR_NOT_FOUND")}function Sv(r){return r=r??new Error("Aborted"),(0,on.default)(r,"ERR_ABORTED")}var Py=0,ll=class extends br{put(e){return e}get(e){if(e.code===Py)return e.multihash.digest;throw Kn()}has(e){return e.code===Py}delete(){}*getAll(){}};function _v(r){return r[Symbol.asyncIterator]!=null}function kv(r,e){if(_v(r))return async function*(){for await(let a of r)await e(a)&&(yield a)}();let t=Ni(r),{value:n,done:i}=t.next();if(i===!0)return function*(){}();let o=e(n);if(typeof o.then=="function")return async function*(){await o&&(yield n);for await(let a of t)await e(a)&&(yield a)}();let s=e;return function*(){o===!0&&(yield n);for(let a of t)s(a)&&(yield a)}()}var wt=kv;var Rv=oe("blockstore:core:tiered"),Ds=class extends br{stores;constructor(e){super(),this.stores=e.slice()}async put(e,t,n){try{return await Promise.all(this.stores.map(async i=>{await i.put(e,t,n)})),e}catch(i){throw Rd(i)}}async get(e,t){for(let n of this.stores)try{let i=await n.get(e,t);if(i!=null)return i}catch(i){Rv.error(i)}throw Kn()}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 Td(n)}}async*putMany(e,t={}){let n,i=this.stores.map(o=>{let s=Vt({objectMode:!0});return Fr(o.putMany(s,t)).catch(a=>{n=a}),s});try{for await(let o of e){if(n!=null)throw n;i.forEach(s=>s.push(o)),yield o.cid}}finally{i.forEach(o=>o.end())}}async*deleteMany(e,t={}){let n,i=this.stores.map(o=>{let s=Vt({objectMode:!0});return Fr(o.deleteMany(s,t)).catch(a=>{n=a}),s});try{for await(let o of e){if(n!=null)throw n;i.forEach(s=>s.push(o)),yield o}}finally{i.forEach(o=>o.end())}}async*getAll(e){let t=new Set;yield*wt(Vr(...this.stores.map(n=>n.getAll(e))),n=>{let i=n.cid.toString();return t.has(i)?!1:(t.add(i),!0)})}};function Tv(r){return typeof r.retrieve=="function"}function Cv(r){return typeof r.announce=="function"}var ul=class{child;blockRetrievers;blockAnnouncers;hashers;started;log;constructor(e){this.log=e.logger.forComponent("helia:networked-storage"),this.child=new Ds([new ll,e.blockstore]),this.blockRetrievers=(e.blockBrokers??[]).filter(Tv),this.blockAnnouncers=(e.blockBrokers??[]).filter(Cv),this.hashers=e.hashers??{},this.started=!1}isStarted(){return this.started}async start(){await vn(this.child,...new Set([...this.blockRetrievers,...this.blockAnnouncers])),this.started=!0}async stop(){await Bn(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 P("blocks:put:duplicate",e)),e):(n.onProgress?.(new P("blocks:put:providers:notify",e)),this.blockAnnouncers.forEach(i=>{i.announce(e,t,n)}),n.onProgress?.(new P("blocks:put:blockstore:put",e)),this.child.put(e,t,n))}async*putMany(e,t={}){let n=wt(e,async({cid:o})=>{let s=await this.child.has(o);return s&&t.onProgress?.(new P("blocks:put-many:duplicate",o)),!s}),i=Jl(n,({cid:o,block:s})=>{t.onProgress?.(new P("blocks:put-many:providers:notify",o)),this.blockAnnouncers.forEach(a=>{a.announce(o,s,t)})});t.onProgress?.(new P("blocks:put-many:blockstore:put-many")),yield*this.child.putMany(i,t)}async get(e,t={}){if(t.offline!==!0&&!await this.child.has(e)){t.onProgress?.(new P("blocks:get:providers:get",e));let n=await Oy(e,this.blockRetrievers,this.hashers[e.multihash.code],{...t,log:this.log});return t.onProgress?.(new P("blocks:get:blockstore:put",e)),await this.child.put(e,n,t),t.onProgress?.(new P("blocks:get:providers:notify",e)),this.blockAnnouncers.forEach(i=>{i.announce(e,n,t)}),n}return t.onProgress?.(new P("blocks:get:blockstore:get",e)),this.child.get(e,t)}async*getMany(e,t={}){t.onProgress?.(new P("blocks:get-many:blockstore:get-many")),yield*this.child.getMany(Jl(e,async n=>{if(t.offline!==!0&&!await this.child.has(n)){t.onProgress?.(new P("blocks:get-many:providers:get",n));let i=await Oy(n,this.blockRetrievers,this.hashers[n.multihash.code],{...t,log:this.log});t.onProgress?.(new P("blocks:get-many:blockstore:put",n)),await this.child.put(n,i,t),t.onProgress?.(new P("blocks:get-many:providers:notify",n)),this.blockAnnouncers.forEach(o=>{o.announce(n,i,t)})}}))}async delete(e,t={}){t.onProgress?.(new P("blocks:delete:blockstore:delete",e)),await this.child.delete(e,t)}async*deleteMany(e,t={}){t.onProgress?.(new P("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 P("blocks:get-all:blockstore:get-many")),yield*this.child.getAll(e)}},Nv=(r,e)=>{if(e==null)throw new F(`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(!de(n.digest,r.multihash.digest))throw new F("Hash of downloaded block did not match multihash from passed CID","ERR_HASH_MISMATCH")}};async function Oy(r,e,t,n){let i=Nv(r,t),o=new AbortController,s=ei([o.signal,n.signal]);try{return await Promise.any(e.map(async a=>{try{let c=!1,u=await a.retrieve(r,{...n,signal:s,validateFn:async l=>{await i(l),c=!0}});return c||await i(u),u}catch(c){throw n.log.error("could not retrieve verified block for %c",r,c),c}}))}finally{s.clear()}}var hl=class{blockstore;datastore;pins;logger;routing;dagWalkers;hashers;log;constructor(e){this.logger=e.logger??a0(),this.log=this.logger.forComponent("helia"),this.hashers=Dy(e.hashers),this.dagWalkers=Ny(e.dagWalkers);let t={blockstore:e.blockstore,datastore:e.datastore,hashers:this.hashers,dagWalkers:this.dagWalkers,logger:this.logger,blockBrokers:[],...e.components??{}};t.blockBrokers=e.blockBrokers.map(i=>i(t));let n=new ul(t);this.pins=new nl(e.datastore,n,this.dagWalkers),this.blockstore=new ol(n,this.pins,{holdGcLock:e.holdGcLock??!0}),this.datastore=e.datastore,this.routing=new il(t,{routers:(e.routers??[]).flatMap(i=>{let o=[i];return i[jo]!=null&&o.push(i[jo]),i[Wo]!=null&&o.push(i[Wo]),o})})}async start(){await Ly(this.datastore),await vn(this.blockstore,this.datastore,this.routing)}async stop(){await Bn(this.blockstore,this.datastore,this.routing)}async gc(e={}){let t=await this.blockstore.lock.writeLock();try{let n=this,i=this.blockstore.unwrap();this.log("gc start"),await Fr(i.deleteMany(async function*(){for await(let{cid:o}of i.getAll())try{if(await n.pins.isPinned(o,e))continue;yield o,e.onProgress?.(new P("helia:gc:deleted",o))}catch(s){n.log.error("Error during gc",s),e.onProgress?.(new P("helia:gc:error",s))}}()))}finally{t()}this.log("gc finished")}};var Ps=class extends br{data;constructor(){super(),this.data=new Map}put(e,t){return this.data.set(qe.encode(e.multihash.bytes),t),e}get(e){let t=this.data.get(qe.encode(e.multihash.bytes));if(t==null)throw Kn();return t}has(e){return this.data.has(qe.encode(e.multihash.bytes))}async delete(e){this.data.delete(qe.encode(e.multihash.bytes))}async*getAll(){for(let[e,t]of this.data.entries())yield{cid:H.createV1(Ne,Et(qe.decode(e))),block:t}}};var KU={...bi};var Fy=re(Re(),1);function dl(r){return r=r??new Error("Not Found"),(0,Fy.default)(r,"ERR_NOT_FOUND")}var Vy="SHARDING";function Lv(r){return r[Symbol.asyncIterator]!=null}function Dv(r){if(Lv(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 fl=Dv;function Pv(r){return r[Symbol.asyncIterator]!=null}function Ov(r,e){return Pv(r)?async function*(){yield*(await fl(r)).sort(e)}():function*(){yield*fl(r).sort(e)}()}var pl=Ov;var sn=class{put(e,t,n){return Promise.reject(new Error(".put is not implemented"))}get(e,t){return Promise.reject(new Error(".get is not implemented"))}has(e,t){return Promise.reject(new Error(".has is not implemented"))}delete(e,t){return Promise.reject(new Error(".delete is not implemented"))}async*putMany(e,t={}){for await(let{key:n,value:i}of e)await this.put(n,i,t),yield n}async*getMany(e,t={}){for await(let n of e)yield{key:n,value:await this.get(n,t)}}async*deleteMany(e,t={}){for await(let n of e)await this.delete(n,t),yield n}batch(){let e=[],t=[];return{put(n,i){e.push({key:n,value:i})},delete(n){t.push(n)},commit:async n=>{await Fr(this.putMany(e,n)),e=[],await Fr(this.deleteMany(t,n)),t=[]}}}async*_all(e,t){throw new Error("._all is not implemented")}async*_allKeys(e,t){throw new Error("._allKeys is not implemented")}query(e,t){let n=this._all(e,t);if(e.prefix!=null){let i=e.prefix;n=wt(n,o=>o.key.toString().startsWith(i))}if(Array.isArray(e.filters)&&(n=e.filters.reduce((i,o)=>wt(i,o),n)),Array.isArray(e.orders)&&(n=e.orders.reduce((i,o)=>pl(i,o),n)),e.offset!=null){let i=0,o=e.offset;n=wt(n,()=>i++>=o)}return e.limit!=null&&(n=xa(n,e.limit)),n}queryKeys(e,t){let n=this._allKeys(e,t);if(e.prefix!=null){let i=e.prefix;n=wt(n,o=>o.toString().startsWith(i))}if(Array.isArray(e.filters)&&(n=e.filters.reduce((i,o)=>wt(i,o),n)),Array.isArray(e.orders)&&(n=e.orders.reduce((i,o)=>pl(i,o),n)),e.offset!=null){let i=e.offset,o=0;n=wt(n,()=>o++>=i)}return e.limit!=null&&(n=xa(n,e.limit)),n}};var Fs=class extends sn{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 dl();return t}has(e){return this.data.has(e.toString())}delete(e){this.data.delete(e.toString())}*_all(){for(let[e,t]of this.data.entries())yield{key:new Fe(e),value:t}}*_allKeys(){for(let e of this.data.keys())yield new Fe(e)}};var wL=new Fe(Vy);var TL=oe("datastore:core:tiered");async function Hy(r={}){let e=r.datastore??new Fs,t=r.blockstore??new Ps,n=new hl({...r,datastore:e,blockstore:t,blockBrokers:r.blockBrokers??[Zo()],routers:r.routers??[Cs("https://delegated-ipfs.dev")]});return r.start!==!1&&await n.start(),n}var Cd=re(Nc(),1);function $y(r,e){let t=e.map((n,i)=>({record:ct(n),index:i}));return t.sort((n,i)=>{let o=n.record.sequence,s=i.record.sequence;if(o>s)return-1;if(o<s)return 1;if(n.record.validityType===je.ValidityType.EOL&&i.record.validityType===je.ValidityType.EOL){let a=Cd.default.fromString(n.record.validity).toDate(),c=Cd.default.fromString(i.record.validity).toDate();if(a.getTime()>c.getTime())return-1;if(a.getTime()<c.getTime())return 1}return 0}),t[0].index}var Mv=r=>{let e=r.data;return e.startsWith('"')&&(e=e.substring(1)),e.endsWith('"')&&(e=e.substring(0,e.length-1)),e.replace("dnslink=","")},Nd=(r,e)=>{let t=Hv(r,e);return{ipfsPath:Mv(t),answer:t}},Hv=(r,e)=>{let t=e.Answer?.filter(n=>n.data.includes("dnslink=/ipfs")||n.data.includes("dnslink=/ipns")).pop();if(t==null)throw new F(`No dnslink records found for domain: ${r}`,"ERR_DNSLINK_NOT_FOUND");return t},Vs=32,So=async(r,e,t,n={})=>{if(e===0)throw new Error("recursion limit exceeded");let i;try{i=await t(r,n)}catch(a){if(a.code!=="ENOTFOUND"&&a.code!=="ERR_DNSLINK_NOT_FOUND"&&a.code!=="ENODATA")throw a;r.startsWith("_dnslink.")?r=r.replace("_dnslink.",""):r=`_dnslink.${r}`,i=await t(r,n)}let o=i.replace("dnslink=",""),s=o.split("/")[2];try{return H.parse(s),o}catch{}return So(s,e-1,t,n)},$v=/^dnslink=.+$/,zy=async(r,e)=>{let i=(await r.resolveTxt(e)).flat().filter(o=>$v.test(o))[0];if(i==null)throw new F(`No dnslink records found for domain: ${e}`,"ERR_DNSLINK_NOT_FOUND");return i};var Ld=re(yu(),1),Dd=re(Gy(),1);function ml(r,e,t){return`${r}?name=${e}&type=${t}`}async function jy(r,e){return await(await fetch(r,{headers:new Headers({accept:"application/dns-json"}),signal:e})).json()}function Ei(r,e){return`${e}_${r}`}var Ud=Object.assign((0,Ld.default)("dns-over-http-resolver"),{error:(0,Ld.default)("dns-over-http-resolver:error")}),Pd=class{_cache;_TXTcache;_servers;_request;_abortControllers;constructor(e={}){this._cache=new Dd.default({max:e?.maxCache??100}),this._TXTcache=new Dd.default({max:e?.maxCache??100}),this._servers=["https://cloudflare-dns.com/dns-query","https://dns.google/resolve"],this._request=e.request??jy,this._abortControllers=[]}cancel(){this._abortControllers.forEach(e=>{e.abort()})}getServers(){return this._servers}_getShuffledServers(){let e=[...this._servers];for(let t=e.length-1;t>0;t--){let n=Math.floor(Math.random()*t),i=e[t];e[t]=e[n],e[n]=i}return e}setServers(e){this._servers=e}async resolve(e,t="A"){switch(t){case"A":return this.resolve4(e);case"AAAA":return this.resolve6(e);case"TXT":return this.resolveTxt(e);default:throw new Error(`${t} is not supported`)}}async resolve4(e){let t="A",n=this._cache.get(Ei(e,t));if(n!=null)return n;let i=!1;for(let o of this._getShuffledServers()){let s=new AbortController;this._abortControllers.push(s);try{let a=await this._request(ml(o,e,t),s.signal),c=a.Answer.map(l=>l.data),u=Math.min(...a.Answer.map(l=>l.TTL));return this._cache.set(Ei(e,t),c,{ttl:u}),c}catch{s.signal.aborted&&(i=!0),Ud.error(`${o} could not resolve ${e} record ${t}`)}finally{this._abortControllers=this._abortControllers.filter(a=>a!==s)}}throw i?Object.assign(new Error("queryA ECANCELLED"),{code:"ECANCELLED"}):new Error(`Could not resolve ${e} record ${t}`)}async resolve6(e){let t="AAAA",n=this._cache.get(Ei(e,t));if(n!=null)return n;let i=!1;for(let o of this._getShuffledServers()){let s=new AbortController;this._abortControllers.push(s);try{let a=await this._request(ml(o,e,t),s.signal),c=a.Answer.map(l=>l.data),u=Math.min(...a.Answer.map(l=>l.TTL));return this._cache.set(Ei(e,t),c,{ttl:u}),c}catch{s.signal.aborted&&(i=!0),Ud.error(`${o} could not resolve ${e} record ${t}`)}finally{this._abortControllers=this._abortControllers.filter(a=>a!==s)}}throw i?Object.assign(new Error("queryAaaa ECANCELLED"),{code:"ECANCELLED"}):new Error(`Could not resolve ${e} record ${t}`)}async resolveTxt(e){let t="TXT",n=this._TXTcache.get(Ei(e,t));if(n!=null)return n;let i=!1;for(let o of this._getShuffledServers()){let s=new AbortController;this._abortControllers.push(s);try{let a=await this._request(ml(o,e,t),s.signal),c=a.Answer.map(l=>[l.data.replace(/['"]+/g,"")]),u=Math.min(...a.Answer.map(l=>l.TTL));return this._TXTcache.set(Ei(e,t),c,{ttl:u}),c}catch{s.signal.aborted&&(i=!0),Ud.error(`${o} could not resolve ${e} record ${t}`)}finally{this._abortControllers=this._abortControllers.filter(a=>a!==s)}}throw i?Object.assign(new Error("queryTxt ECANCELLED"),{code:"ECANCELLED"}):new Error(`Could not resolve ${e} record ${t}`)}clearCache(){this._cache.clear(),this._TXTcache.clear()}},Wy=Pd;var Xy=re(Od(),1),Gn=class{lru;constructor(e){this.lru=(0,Xy.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 Fd=new Gn(1e3),jv=60*1e3,Wv=new yt({concurrency:4}),Yv=async function(e,t={}){let n=new Wy({maxCache:0});if(t.nocache!==!0&&Fd.has(e)){let o=Fd.get(e);if(o!=null)return t?.onProgress?.(new P("dnslink:cache",{detail:o})),o}t.onProgress?.(new P("dnslink:query",{detail:e}));let i=await Wv.add(async()=>{let o=await zy(n,e);return t.onProgress?.(new P("dnslink:answer",{detail:o})),Fd.set(e,o,jv),o},{signal:t?.signal});if(i==null)throw new Error("No DNS response received");return i},Zy=Yv;function Jy(){return async(r,e={})=>So(r,Vs,Zy,e)}var Vd=class{routing;constructor(e){this.routing=e}async put(e,t,n={}){try{await this.routing.put(e,t,n)}catch(i){n.onProgress?.(new P("ipns:routing:helia:error",i))}}async get(e,t={}){try{return await this.routing.get(e,t)}catch(n){t.onProgress?.(new P("ipns:routing:helia:error",n))}throw new Error("Not found")}};function Qy(r){return new Vd(r)}var yl=globalThis.CustomEvent??Event;async function*vi(r,e={}){let t=e.concurrency??1/0;t<1&&(t=1/0);let n=e.ordered==null?!1:e.ordered,i=new EventTarget,o=[],s=Ue(),a=Ue(),c=!1,u,l=!1;i.addEventListener("task-complete",()=>{a.resolve()}),Promise.resolve().then(async()=>{try{for await(let f of r){if(o.length===t&&(s=Ue(),await s.promise),l)break;let m={done:!1};o.push(m),f().then(y=>{m.done=!0,m.ok=!0,m.value=y,i.dispatchEvent(new yl("task-complete"))},y=>{m.done=!0,m.err=y,i.dispatchEvent(new yl("task-complete"))})}c=!0,i.dispatchEvent(new yl("task-complete"))}catch(f){u=f,i.dispatchEvent(new yl("task-complete"))}});function h(){return n?o[0]?.done:!!o.find(f=>f.done)}function*p(){for(;o.length>0&&o[0].done;){let f=o[0];if(o.shift(),f.ok)yield f.value;else throw l=!0,s.resolve(),f.err;s.resolve()}}function*d(){for(;h();)for(let f=0;f<o.length;f++)if(o[f].done){let m=o[f];if(o.splice(f,1),f--,m.ok)yield m.value;else throw l=!0,s.resolve(),m.err;s.resolve()}}for(;;){if(h()||(a=Ue(),await a.promise),u!=null)throw u;if(n?yield*p():yield*d(),c&&o.length===0)break}}var Ms;(function(r){let e;r.codec=()=>(e==null&&(e=Ft((t,n,i={})=>{i.lengthDelimited!==!1&&n.fork(),t.key!=null&&t.key.byteLength>0&&(n.uint32(10),n.bytes(t.key)),t.value!=null&&t.value.byteLength>0&&(n.uint32(18),n.bytes(t.value)),t.timeReceived!=null&&t.timeReceived!==""&&(n.uint32(42),n.string(t.timeReceived)),i.lengthDelimited!==!1&&n.ldelim()},(t,n)=>{let i={key:new Uint8Array(0),value:new Uint8Array(0),timeReceived:""},o=n==null?t.len:t.pos+n;for(;t.pos<o;){let s=t.uint32();switch(s>>>3){case 1:i.key=t.bytes();break;case 2:i.value=t.bytes();break;case 5:i.timeReceived=t.string();break;default:t.skipType(s&7);break}}return i})),e),r.encode=t=>Ot(t,r.codec()),r.decode=t=>Dt(t,r.codec())})(Ms||(Ms={}));function eg(r){let e=r.getUTCFullYear(),t=String(r.getUTCMonth()+1).padStart(2,"0"),n=String(r.getUTCDate()).padStart(2,"0"),i=String(r.getUTCHours()).padStart(2,"0"),o=String(r.getUTCMinutes()).padStart(2,"0"),s=String(r.getUTCSeconds()).padStart(2,"0"),a=r.getUTCMilliseconds(),c=String(a*1e3*1e3).padStart(9,"0");return`${e}-${t}-${n}T${i}:${o}:${s}.${c}Z`}function tg(r){let e=new RegExp("(\\d{4})-(\\d{2})-(\\d{2})T(\\d{2}):(\\d{2}):(\\d{2})\\.(\\d+)Z"),t=String(r).trim().match(e);if(t==null)throw new Error("Invalid format");let n=parseInt(t[1],10),i=parseInt(t[2],10)-1,o=parseInt(t[3],10),s=parseInt(t[4],10),a=parseInt(t[5],10),c=parseInt(t[6],10),u=parseInt(t[7].slice(0,-6),10);return new Date(Date.UTC(n,i,o,s,a,c,u))}var _o=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 Ms.encode(this.prepareSerialize())}prepareSerialize(){return{key:this.key,value:this.value,timeReceived:eg(this.timeReceived)}}static deserialize(e){let t=Ms.decode(e);return new r(t.key,t.value,new Date(t.timeReceived))}static fromDeserialized(e){let t=tg(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 rg;(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"})(rg||(rg={}));var ng;(function(r){r[r.PUT_VALUE=0]="PUT_VALUE",r[r.GET_VALUE=1]="GET_VALUE",r[r.ADD_PROVIDER=2]="ADD_PROVIDER",r[r.GET_PROVIDERS=3]="GET_PROVIDERS",r[r.FIND_NODE=4]="FIND_NODE",r[r.PING=5]="PING"})(ng||(ng={}));function Md(r){return new Fe("/dht/record/"+Q(r,"base32"),!1)}function ig(r){return{async put(e,t,n={}){try{let i=Md(e),o=new _o(e,t,new Date);n.onProgress?.(new P("ipns:routing:datastore:put")),await r.put(i,o.serialize(),n)}catch(i){throw n.onProgress?.(new P("ipns:routing:datastore:error",i)),i}},async get(e,t={}){try{let n=Md(e);t.onProgress?.(new P("ipns:routing:datastore:get"));let i=await r.get(n,t);return _o.deserialize(i).value}catch(n){throw t.onProgress?.(new P("ipns:routing:datastore:error",n)),n}},async has(e,t={}){let n=Md(e);return r.has(n,t)}}}var Bi=oe("helia:ipns"),Zv=60*1e3,og=60*Zv,Jv=24*og,Hd=23*og,$d=class{routers;localStore;timeout;defaultResolvers;constructor(e,t=[],n=[]){this.routers=[Qy(e.routing),...t],this.localStore=ig(e.datastore),this.defaultResolvers=n.length>0?n:[Jy()]}async publish(e,t,n={}){try{let i=1n,o=wo(e);if(await this.localStore.has(o,n)){let c=await this.localStore.get(o,n);i=ct(c).sequence+1n}let s=await Wm(e,t,i,n.lifetime??Jv,n),a=nn(s);return await this.localStore.put(o,a,n),n.offline!==!0&&await Promise.all(this.routers.map(async c=>{await c.put(o,a,n)})),s}catch(i){throw n.onProgress?.(new P("ipns:publish:error",i)),i}}async resolve(e,t={}){let n=wo(e),i=await this.#t(n,t);return this.#e(i.value,t)}async resolveDns(e,t={}){let n=t.resolvers??this.defaultResolvers,i=await Promise.any(n.map(async o=>o(e,t)));return this.#e(i,t)}republish(e={}){if(this.timeout!=null)throw new Error("Republish is already running");e.signal?.addEventListener("abort",()=>{clearTimeout(this.timeout)});async function t(){let n=Date.now();e.onProgress?.(new P("ipns:republish:start"));let o=Date.now()-n,s=Hd-o;s<0&&(s=e.interval??Hd),setTimeout(()=>{t().catch(a=>{Bi.error("error republishing",a)})},s)}this.timeout=setTimeout(()=>{t().catch(n=>{Bi.error("error republishing",n)})},e.interval??Hd)}async#e(e,t={}){let n=e.split("/");try{let i=n[1];if(i==="ipns"){let{cid:o}=await this.resolve(Yt(n[2]),t),s=n.slice(3).join("/");return{cid:o,path:s}}else if(i==="ipfs"){let o=H.parse(n[2]),s=n.slice(3).join("/");return{cid:o,path:s}}}catch(i){Bi.error("error parsing ipfs path",i)}throw Bi.error("invalid ipfs path %s",e),new Error("Invalid value")}async#t(e,t={}){let n=[this.localStore,...this.routers];t.offline===!0&&(n=[this.localStore]);let i=[],o=0;if(await Promise.all(n.map(async a=>{let c;try{c=await a.get(e,{...t,validate:!1})}catch(u){a===this.localStore&&u.code==="ERR_NOT_FOUND"?Bi("did not have record locally"):Bi.error("error finding IPNS record",u);return}try{await Wc(e,c),i.push(c)}catch(u){o++,Bi.error("error finding IPNS record",u)}})),i.length===0)throw o>0?new F(`${o>1?`${o} records`:"Record"} found for routing key ${o>1?"were":"was"} invalid`,"ERR_RECORDS_FAILED_VALIDATION"):new F("Could not find record for routing key","ERR_NOT_FOUND");let s=i[$y(e,i)];return await this.localStore.put(e,s,t),ct(s)}};function sg(r,{routers:e=[],resolvers:t=[]}={}){return new $d(r,e,t)}var F4=re(Qd(),1),V4=re(Og(),1);var uP=new Gn(1e3),hP=60*1e3;var uf=new Gn(1e3),M4=60*1e3;function vl(r){let e=new yt({concurrency:4}),t=async(n,i={})=>{let o=new URLSearchParams;o.set("name",n),o.set("type","TXT");let s=o.toString();if(i.nocache!==!0&&uf.has(s)){let c=uf.get(s);if(c!=null)return i.onProgress?.(new P("dnslink:cache",{detail:c})),c}i.onProgress?.(new P("dnslink:query",{detail:n}));let a=await e.add(async()=>{let c=await fetch(`${r}?${o}`,{headers:{accept:"application/dns-json"},signal:i.signal});if(c.status!==200)throw new Error(`Unexpected HTTP status: ${c.status} - ${c.statusText}`);let u=new URL(c.url).search.slice(1),l=await c.json();i.onProgress?.(new P("dnslink:answer",{detail:l}));let{ipfsPath:h,answer:p}=Nd(n,l);return uf.set(u,h,p.TTL??M4),h},{signal:i.signal});if(a==null)throw new Error("No DNS response received");return a};return async(n,i={})=>So(n,Vs,t,i)}var yf=re(Re(),1);function H4(r){return r[Symbol.asyncIterator]!=null}function $4(r,e=1){return e=Number(e),H4(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 zs=$4;async function*Ks(r,e=1){for await(let t of zs(r,e)){let n=t.map(async i=>i().then(o=>({ok:!0,value:o}),o=>({ok:!1,err:o})));for(let i=0;i<n.length;i++){let o=await n[i];if(o.ok)yield o.value;else throw o.err}}}var z4=262144,qs=(r={})=>{let e=r.chunkSize??z4;return async function*(n){let i=new ai,o=0,s=!1;for await(let a of n)for(i.append(a),o+=a.length;o>=e;)if(yield i.slice(0,e),s=!0,e===i.length)i=new ai,o=0;else{let c=new ai;c.append(i.sublist(e)),i=c,o-=e}(!s||o>0)&&(yield i.subarray(0,o))}};var hf=re(Re(),1);var ar;(function(r){let e;(function(i){i.Raw="Raw",i.Directory="Directory",i.File="File",i.Metadata="Metadata",i.Symlink="Symlink",i.HAMTShard="HAMTShard"})(e=r.DataType||(r.DataType={}));let t;(function(i){i[i.Raw=0]="Raw",i[i.Directory=1]="Directory",i[i.File=2]="File",i[i.Metadata=3]="Metadata",i[i.Symlink=4]="Symlink",i[i.HAMTShard=5]="HAMTShard"})(t||(t={})),function(i){i.codec=()=>si(t)}(e=r.DataType||(r.DataType={}));let n;r.codec=()=>(n==null&&(n=Ft((i,o,s={})=>{if(s.lengthDelimited!==!1&&o.fork(),i.Type!=null&&(o.uint32(8),r.DataType.codec().encode(i.Type,o)),i.Data!=null&&(o.uint32(18),o.bytes(i.Data)),i.filesize!=null&&(o.uint32(24),o.uint64(i.filesize)),i.blocksizes!=null)for(let a of i.blocksizes)o.uint32(32),o.uint64(a);i.hashType!=null&&(o.uint32(40),o.uint64(i.hashType)),i.fanout!=null&&(o.uint32(48),o.uint64(i.fanout)),i.mode!=null&&(o.uint32(56),o.uint32(i.mode)),i.mtime!=null&&(o.uint32(66),Bl.codec().encode(i.mtime,o)),s.lengthDelimited!==!1&&o.ldelim()},(i,o)=>{let s={blocksizes:[]},a=o==null?i.len:i.pos+o;for(;i.pos<a;){let c=i.uint32();switch(c>>>3){case 1:s.Type=r.DataType.codec().decode(i);break;case 2:s.Data=i.bytes();break;case 3:s.filesize=i.uint64();break;case 4:s.blocksizes.push(i.uint64());break;case 5:s.hashType=i.uint64();break;case 6:s.fanout=i.uint64();break;case 7:s.mode=i.uint32();break;case 8:s.mtime=Bl.codec().decode(i,i.uint32());break;default:i.skipType(c&7);break}}return s})),n),r.encode=i=>Ot(i,r.codec()),r.decode=i=>Dt(i,r.codec())})(ar||(ar={}));var Bl;(function(r){let e;r.codec=()=>(e==null&&(e=Ft((t,n,i={})=>{i.lengthDelimited!==!1&&n.fork(),t.Seconds!=null&&(n.uint32(8),n.int64(t.Seconds)),t.FractionalNanoseconds!=null&&(n.uint32(21),n.fixed32(t.FractionalNanoseconds)),i.lengthDelimited!==!1&&n.ldelim()},(t,n)=>{let i={},o=n==null?t.len:t.pos+n;for(;t.pos<o;){let s=t.uint32();switch(s>>>3){case 1:i.Seconds=t.int64();break;case 2:i.FractionalNanoseconds=t.fixed32();break;default:t.skipType(s&7);break}}return i})),e),r.encode=t=>Ot(t,r.codec()),r.decode=t=>Dt(t,r.codec())})(Bl||(Bl={}));var Fg;(function(r){let e;r.codec=()=>(e==null&&(e=Ft((t,n,i={})=>{i.lengthDelimited!==!1&&n.fork(),t.MimeType!=null&&(n.uint32(10),n.string(t.MimeType)),i.lengthDelimited!==!1&&n.ldelim()},(t,n)=>{let i={},o=n==null?t.len:t.pos+n;for(;t.pos<o;){let s=t.uint32();switch(s>>>3){case 1:i.MimeType=t.string();break;default:t.skipType(s&7);break}}return i})),e),r.encode=t=>Ot(t,r.codec()),r.decode=t=>Dt(t,r.codec())})(Fg||(Fg={}));var Vg={Raw:"raw",Directory:"directory",File:"file",Metadata:"metadata",Symlink:"symlink",HAMTShard:"hamt-sharded-directory"},K4=["directory","hamt-sharded-directory"],Mg=parseInt("0644",8),Hg=parseInt("0755",8),W=class r{static unmarshal(e){let t=ar.decode(e),n=new r({type:Vg[t.Type!=null?t.Type.toString():"File"],data:t.Data,blockSizes:t.blocksizes,mode:t.mode,mtime:t.mtime!=null?{secs:t.mtime.Seconds??0n,nsecs:t.mtime.FractionalNanoseconds}:void 0,fanout:t.fanout});return n._originalMode=t.mode??0,n}type;data;blockSizes;hashType;fanout;mtime;_mode;_originalMode;constructor(e={type:"file"}){let{type:t,data:n,blockSizes:i,hashType:o,fanout:s,mtime:a,mode:c}=e;if(t!=null&&!Object.values(Vg).includes(t))throw(0,hf.default)(new Error("Type: "+t+" is not valid"),"ERR_INVALID_TYPE");this.type=t??"file",this.data=n,this.hashType=o,this.fanout=s,this.blockSizes=i??[],this._originalMode=0,this.mode=c,this.mtime=a}set mode(e){e==null?this._mode=this.isDirectory()?Hg:Mg:this._mode=e&4095}get mode(){return this._mode}isDirectory(){return K4.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=ar.DataType.Raw;break;case"directory":e=ar.DataType.Directory;break;case"file":e=ar.DataType.File;break;case"metadata":e=ar.DataType.Metadata;break;case"symlink":e=ar.DataType.Symlink;break;case"hamt-sharded-directory":e=ar.DataType.HAMTShard;break;default:throw(0,hf.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===Mg&&!this.isDirectory()&&(n=void 0),n===Hg&&this.isDirectory()&&(n=void 0));let i;return this.mtime!=null&&(i={Seconds:this.mtime.secs,FractionalNanoseconds:this.mtime.nsecs}),ar.encode({Type:e,Data:t,filesize:this.isDirectory()?void 0:this.fileSize(),blocksizes:this.blockSizes,hashType:this.hashType,fanout:this.fanout,mode:n,mtime:i})}};var cr=async(r,e,t)=>{t.codec==null&&(t.codec=De);let n=await he.digest(r),i=H.create(t.cidVersion,t.codec.code,n);return await e.put(i,r,t),i};function $g(r){return async function*(t,n){let i=0n;for await(let o of t.content)yield async()=>{let s,a={codec:De,cidVersion:r.cidVersion,onProgress:r.onProgress};r.rawLeaves?(a.codec=Pt,a.cidVersion=1):(s=new W({type:r.leafType,data:o}),o=ce({Data:s.marshal(),Links:[]}));let c=await cr(o,n,a);return i+=BigInt(o.byteLength),r.onProgress?.(new P("unixfs:importer:progress:file:write",{bytesWritten:i,cid:c,path:t.path})),{cid:c,unixfs:s,size:BigInt(o.length),block:o}}}}var df=re(Re(),1);var zg=async(r,e,t)=>{let n=new W({type:"directory",mtime:r.mtime,mode:r.mode}),i=ce(_e({Data:n.marshal()})),o=await cr(i,e,t),s=r.path;return{cid:o,path:s,unixfs:n,size:BigInt(i.length),originalPath:r.originalPath,block:i}};async function*q4(r,e,t){let n=-1,i;for await(let o of Ks(t.bufferImporter(r,e),t.blockWriteConcurrency)){if(n++,n===0){i={...o,single:!0};continue}else n===1&&i!=null&&(yield{...i,block:void 0,single:void 0},i=void 0);yield{...o,block:void 0}}i!=null&&(yield i)}function Kg(r){return r.single===!0}var G4=(r,e,t)=>async function(i){if(i.length===1&&Kg(i[0])&&t.reduceSingleLeafToSelf){let l=i[0],h=l.block;return Kg(l)&&(r.mtime!==void 0||r.mode!==void 0)&&(l.unixfs=new W({type:"file",mtime:r.mtime,mode:r.mode,data:l.block}),h={Data:l.unixfs.marshal(),Links:[]},l.block=ce(_e(h)),l.cid=await cr(l.block,e,{...t,cidVersion:t.cidVersion}),l.size=BigInt(l.block.length)),t.onProgress?.(new P("unixfs:importer:progress:file:layout",{cid:l.cid,path:l.originalPath})),{cid:l.cid,path:r.path,unixfs:l.unixfs,size:l.size,originalPath:l.originalPath}}let o=new W({type:"file",mtime:r.mtime,mode:r.mode}),s=i.filter(l=>l.cid.code===Ne&&l.size>0||l.unixfs!=null&&l.unixfs.data==null&&l.unixfs.fileSize()>0n?!0:!!l.unixfs?.data?.length).map(l=>l.cid.code===Ne?(o.addBlockSize(l.size),{Name:"",Tsize:Number(l.size),Hash:l.cid}):(l.unixfs==null||l.unixfs.data==null?o.addBlockSize(l.unixfs?.fileSize()??0n):o.addBlockSize(BigInt(l.unixfs.data.length)),{Name:"",Tsize:Number(l.size),Hash:l.cid})),a={Data:o.marshal(),Links:s},c=ce(_e(a)),u=await cr(c,e,t);return t.onProgress?.(new P("unixfs:importer:progress:file:layout",{cid:u,path:r.originalPath})),{cid:u,path:r.path,unixfs:o,size:BigInt(c.length+a.Links.reduce((l,h)=>l+(h.Tsize??0),0)),originalPath:r.originalPath,block:c}},qg=async(r,e,t)=>t.layout(q4(r,e,t),G4(r,e,t));function j4(r){return Symbol.iterator in r}function W4(r){return Symbol.asyncIterator in r}function Y4(r){try{if(r instanceof Uint8Array)return async function*(){yield r}();if(j4(r))return async function*(){yield*r}();if(W4(r))return r}catch{throw(0,df.default)(new Error("Content was invalid"),"ERR_INVALID_CONTENT")}throw(0,df.default)(new Error("Content was invalid"),"ERR_INVALID_CONTENT")}function Gg(r){return async function*(t,n){for await(let i of t){let o;if(i.path!=null&&(o=i.path,i.path=i.path.split("/").filter(s=>s!=null&&s!==".").join("/")),X4(i)){let s={path:i.path,mtime:i.mtime,mode:i.mode,content:async function*(){let a=0n;for await(let c of r.chunker(r.chunkValidator(Y4(i.content)))){let u=BigInt(c.byteLength);a+=u,r.onProgress?.(new P("unixfs:importer:progress:file:read",{bytesRead:a,chunkSize:u,path:i.path})),yield c}}(),originalPath:o};yield async()=>qg(s,n,r)}else if(i.path!=null){let s={path:i.path,mtime:i.mtime,mode:i.mode,originalPath:o};yield async()=>zg(s,n,r)}else throw new Error("Import candidate must have content or path or both")}}}function X4(r){return r.content!=null}var ff=re(Re(),1);var jg=()=>async function*(e){for await(let t of e){if(t.length===void 0)throw(0,ff.default)(new Error("Content was invalid"),"ERR_INVALID_CONTENT");if(typeof t=="string"||t instanceof String)yield Y(t.toString());else if(Array.isArray(t))yield Uint8Array.from(t);else if(t instanceof Uint8Array)yield t;else throw(0,ff.default)(new Error("Content was invalid"),"ERR_INVALID_CONTENT")}};var Z4=174;function Gs(r){let e=r?.maxChildrenPerNode??Z4;return async function t(n,i){let o=[];for await(let s of zs(n,e))o.push(await i(s));return o.length>1?t(o,i):o[0]}}var Tr=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}},js=H.parse("QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn"),Ws=H.parse("zdj7WbTaiJT1fgatdet9Ei9iDB5hdCxkbVyhyh8YTUnXMiwYi");var _i=class extends Tr{_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?Ws.bytes.byteLength:js.bytes.byteLength));return this.nodeSize}async*flush(e){let t=[];for(let[c,u]of this._children.entries()){let l=u;if(u instanceof Tr)for await(let h of u.flush(e))l=h,yield h;l.size!=null&&l.cid!=null&&t.push({Name:c,Tsize:Number(l.size),Hash:l.cid})}let n=new W({type:"directory",mtime:this.mtime,mode:this.mode}),i={Data:n.marshal(),Links:t},o=ce(_e(i)),s=await cr(o,e,this.options),a=o.length+i.Links.reduce((c,u)=>c+(u.Tsize==null?0:u.Tsize),0);this.cid=s,this.size=a,yield{cid:s,unixfs:n,path:this.path,size:BigInt(a)}}};var Il=re(Xg(),1);function J4(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 v7=ti({name:"murmur3-32",code:35,encode:r=>J4(Il.default.x86.hash32(r))}),ki=ti({name:"murmur3-128",code:34,encode:r=>Ui.fromHex(Il.default.x64.hash128(r))}),B7=ti({name:"murmur3-x64-64",code:34,encode:r=>Ui.fromHex(Il.default.x64.hash128(r)).subarray(0,8)});var Qg=re(Sl(),1);var Ut=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 Qg.default,this.key=null}async put(e,t){let n=await this._findNewBucketAndPos(e);n.bucket._putAt(n,e,t)}async get(e){let t=await this._findChild(e);if(t!=null)return t.value}async del(e){let t=await this._findPlace(e),n=t.bucket._at(t.pos);n!=null&&n.key===e&&t.bucket._delAt(t.pos)}leafCount(){return this._children.compactArray().reduce((t,n)=>n instanceof r?t+n.leafCount():t+1,0)}childrenCount(){return this._children.length}onlyChild(){return this._children.get(0)}*eachLeafSeries(){let e=this._children.compactArray();for(let t of e)t instanceof r?yield*t.eachLeafSeries():yield t}serialize(e,t){let n=[];return t(this._children.reduce((i,o,s)=>(o!=null&&(o instanceof r?i.push(o.serialize(e,t)):i.push(e(o,s))),i),n))}async asyncTransform(e,t){return ew(this,e,t)}toJSON(){return this.serialize(nB,iB)}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"?Y(e):e),n=await t.take(this._options.bits),i=this._children.get(n);return i instanceof r?i._findPlace(t):{bucket:this,pos:n,hash:t,existingChild:i}}async _findNewBucketAndPos(e){let t=await this._findPlace(e);if(t.existingChild!=null&&t.existingChild.key!==e){let n=new r(this._options,t.bucket,t.pos);t.bucket._putObjectAt(t.pos,n);let i=await n._findPlace(t.existingChild.hash);return i.bucket._putAt(i,t.existingChild.key,t.existingChild.value),n._findNewBucketAndPos(t.hash)}return t}_putAt(e,t,n){this._putObjectAt(e.pos,{key:t,value:n,hash:e.hash})}_putObjectAt(e,t){this._children.get(e)==null&&this._popCount++,this._children.set(e,t)}_delAt(e){if(e===-1)throw new Error("Invalid position");this._children.get(e)!=null&&this._popCount--,this._children.unset(e),this._level()}_level(){if(this._parent!=null&&this._popCount<=1)if(this._popCount===1){let e=this._children.find(rB);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 rB(r){return!!r}function nB(r,e){return r.key}function iB(r){return r}async function ew(r,e,t){let n=[];for(let i of r._children.compactArray())if(i instanceof Ut)await ew(i,e,t);else{let o=await e(i);n.push({bitField:r._children.bitField(),children:o})}return t(n)}var oB=[255,254,252,248,240,224,192,128],sB=[1,3,7,15,31,63,127,255],_l=class{_value;_currentBytePos;_currentBitPos;constructor(e){this._value=e,this._currentBytePos=e.length-1,this._currentBitPos=7}availableBits(){return this._currentBitPos+1+this._currentBytePos*8}totalBits(){return this._value.length*8}take(e){let t=e,n=0;for(;t>0&&this._haveBits();){let i=this._value[this._currentBytePos],o=this._currentBitPos+1,s=Math.min(o,t),a=aB(i,o-s,s);n=(n<<s)+a,t-=s,this._currentBitPos-=s,this._currentBitPos<0&&(this._currentBitPos=7,this._currentBytePos--)}return n}untake(e){for(this._currentBitPos+=e;this._currentBitPos>7;)this._currentBitPos-=8,this._currentBytePos+=1}_haveBits(){return this._currentBytePos>=0}};function aB(r,e,t){let n=cB(e,t);return(r&n)>>>e}function cB(r,e){return oB[r]&sB[Math.min(e+r-1,7)]}function tw(r){function e(t){return t instanceof kl?t:new kl(t,r)}return e}var kl=class{_value;_hashFn;_depth;_availableBits;_currentBufferIndex;_buffers;constructor(e,t){if(!(e instanceof Uint8Array))throw new Error("can only hash Uint8Arrays");this._value=e,this._hashFn=t,this._depth=-1,this._availableBits=0,this._currentBufferIndex=0,this._buffers=[]}async take(e){let t=e;for(;this._availableBits<t;)await this._produceMoreBits();let n=0;for(;t>0;){let i=this._buffers[this._currentBufferIndex],o=Math.min(i.availableBits(),t),s=i.take(o);n=(n<<o)+s,t-=o,this._availableBits-=o,i.availableBits()===0&&this._currentBufferIndex++}return n}untake(e){let t=e;for(;t>0;){let n=this._buffers[this._currentBufferIndex],i=Math.min(n.totalBits()-n.availableBits(),t);n.untake(i),t-=i,this._availableBits+=i,this._currentBufferIndex>0&&n.totalBits()===n.availableBits()&&(this._depth--,this._currentBufferIndex--)}}async _produceMoreBits(){this._depth++;let e=this._depth>0?Ee([this._value,Uint8Array.from([this._depth])]):this._value,t=await this._hashFn(e),n=new _l(t);this._buffers.push(n),this._availableBits+=n.availableBits()}};function Uo(r){if(r==null||r.hashFn==null)throw new Error("please define an options.hashFn");let e={bits:r.bits??8,hash:tw(r.hashFn)};return new Ut(e)}async function lB(r){return(await ki.encode(r)).slice(0,8).reverse()}var rw=BigInt(34),uB=8,pf=class extends Tr{_bucket;constructor(e,t){super(e,t),this._bucket=Uo({hashFn:lB,bits:t.shardFanoutBits??uB})}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=ow(this._bucket,this,this.options),this.nodeSize)}async*flush(e){for await(let t of iw(this._bucket,e,this,this.options))yield{...t,path:this.path}}},nw=pf;async function*iw(r,e,t,n){let i=r._children,o=(r.tableSize()-1).toString(16).length,s=[],a=0n;for(let f=0;f<i.length;f++){let m=i.get(f);if(m==null)continue;let y=f.toString(16).toUpperCase().padStart(o,"0");if(m instanceof Ut){let g;for await(let w of iw(m,e,null,n))g=w;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(hB(m.value)){let g=m.value,w;for await(let A of g.flush(e))w=A,yield w;if(w==null)throw new Error("Did not flush dir");let x=y+m.key;s.push({Name:x,Tsize:Number(w.size),Hash:w.cid}),a+=w.size}else{let g=m.value;if(g.cid==null)continue;let w=y+m.key,x=g.size;s.push({Name:w,Tsize:Number(x),Hash:g.cid}),a+=BigInt(x??0)}}let c=Uint8Array.from(i.bitField().reverse()),u=new W({type:"hamt-sharded-directory",data:c,fanout:BigInt(r.tableSize()),hashType:rw,mtime:t?.mtime,mode:t?.mode}),l={Data:u.marshal(),Links:s},h=ce(_e(l)),p=await cr(h,e,n),d=BigInt(h.byteLength)+a;yield{cid:p,unixfs:u,size:d}}function hB(r){return typeof r.flush=="function"}function ow(r,e,t){let n=r._children,i=(r.tableSize()-1).toString(16).length,o=[];for(let u=0;u<n.length;u++){let l=n.get(u);if(l==null)continue;let h=u.toString(16).toUpperCase().padStart(i,"0");if(l instanceof Ut){let p=ow(l,null,t);o.push({Name:h,Tsize:Number(p),Hash:t.cidVersion===0?js:Ws})}else if(typeof l.value.flush=="function"){let d=l.value.nodeSize();o.push({Name:h+l.key,Tsize:Number(d),Hash:t.cidVersion===0?js:Ws})}else{let p=l.value;if(p.cid==null)continue;let d=h+l.key,f=p.size;o.push({Name:d,Tsize:Number(f),Hash:p.cid})}}let s=Uint8Array.from(n.bitField().reverse()),a=new W({type:"hamt-sharded-directory",data:s,fanout:BigInt(r.tableSize()),hashType:rw,mtime:e?.mtime,mode:e?.mode});return ce(_e({Data:a.marshal(),Links:o})).length}async function mf(r,e,t,n){let i=e;e instanceof _i&&e.estimateNodeSize()>t&&(i=await dB(e,n));let o=i.parent;if(o!=null){if(i!==e){if(r!=null&&(r.parent=i),i.parentKey==null)throw new Error("No parent key found");await o.put(i.parentKey,i)}return mf(i,o,t,n)}return i}async function dB(r,e){let t=new nw({root:r.root,dir:!0,parent:r.parent,parentKey:r.parentKey,path:r.path,dirty:r.dirty,flat:!1,mtime:r.mtime,mode:r.mode},e);for await(let{key:n,child:i}of r.eachChildSeries())await t.put(n,i);return t}var sw=(r="")=>r.split(/(?<!\\)\//).filter(Boolean);async function fB(r,e,t){let n=sw(r.path??""),i=n.length-1,o=e,s="";for(let a=0;a<n.length;a++){let c=n[a];s+=`${s!==""?"/":""}${c}`;let u=a===i;if(o.dirty=!0,o.cid=void 0,o.size=void 0,u)await o.put(c,r),e=await mf(null,o,t.shardSplitThresholdBytes,t);else{let l=await o.get(c);(l==null||!(l instanceof Tr))&&(l=new _i({root:!1,dir:!0,parent:o,parentKey:c,path:s,dirty:!0,flat:!0,mtime:l?.unixfs?.mtime,mode:l?.unixfs?.mode},t)),await o.put(c,l),o=l}}return e}async function*aw(r,e){if(!(r instanceof Tr)){r.unixfs?.isDirectory()===!0&&(yield r);return}yield*r.flush(e)}function cw(r){return async function*(t,n){let i=new _i({root:!0,dir:!0,path:"",dirty:!0,flat:!0},r),o,s=!1;for await(let a of t){if(a==null)continue;let c=`${a.originalPath??""}`.split("/")[0];c!=null&&c!==""&&(o==null?(o=c,s=!0):o!==c&&(s=!1)),i=await fB(a,i,r),(a.unixfs==null||!a.unixfs.isDirectory())&&(yield a)}if(r.wrapWithDirectory||s&&i.childCount()>1)yield*aw(i,n);else for await(let a of i.eachChildSeries())a!=null&&(yield*aw(a.child,n))}}async function*Yn(r,e,t={}){let n;Symbol.asyncIterator in r||Symbol.iterator in r?n=r:n=[r];let i=t.wrapWithDirectory??!1,o=t.shardSplitThresholdBytes??262144,s=t.shardFanoutBits??8,a=t.cidVersion??1,c=t.rawLeaves??!0,u=t.leafType??"file",l=t.fileImportConcurrency??50,h=t.blockWriteConcurrency??10,p=t.reduceSingleLeafToSelf??!0,d=t.chunker??qs(),f=t.chunkValidator??jg(),m=t.dagBuilder??Gg({chunker:d,chunkValidator:f,wrapWithDirectory:i,layout:t.layout??Gs(),bufferImporter:t.bufferImporter??$g({cidVersion:a,rawLeaves:c,leafType:u,onProgress:t.onProgress}),blockWriteConcurrency:h,reduceSingleLeafToSelf:p,cidVersion:a,onProgress:t.onProgress}),y=t.treeBuilder??cw({wrapWithDirectory:i,shardSplitThresholdBytes:o,shardFanoutBits:s,cidVersion:a,onProgress:t.onProgress});for await(let g of y(Ks(m(n,e),l),e))yield{cid:g.cid,path:g.path,unixfs:g.unixfs,size:g.size}}async function Rl(r,e,t={}){let n=await wi(Yn([r],e,t));if(n==null)throw(0,yf.default)(new Error("Nothing imported"),"ERR_INVALID_PARAMS");return n}async function lw(r,e,t={}){let n=await wi(Yn([r],e,t));if(n==null)throw(0,yf.default)(new Error("Nothing imported"),"ERR_INVALID_PARAMS");return n}async function uw(r,e,t={}){return Rl({content:r},e,t)}async function hw(r,e,t={}){return Rl({content:r},e,t)}var xB=re(Re(),1),bB=re(Aw(),1);var Qs={cidVersion:1,rawLeaves:!0,layout:Gs({maxChildrenPerNode:1024}),chunker:qs({chunkSize:1048576})};async function*Iw(r,e,t={}){yield*Yn(r,e,{...Qs,...t})}async function Sw(r,e,t={}){let{cid:n}=await uw(r,e,{...Qs,...t});return n}async function _w(r,e,t={}){let{cid:n}=await hw(r,e,{...Qs,...t});return n}async function kw(r,e,t={}){let{cid:n}=await Rl(r,e,{...Qs,...t});return n}async function Rw(r,e,t={}){let{cid:n}=await lw({...r,path:r.path??"-"},e,{...Qs,...t});return n}var Cl=re(Re(),1);function EB(r){return r[Symbol.asyncIterator]!=null}function vB(r){if(EB(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 Xn=vB;var Gw=re(Re(),1);var Tw=re(Re(),1);function Lo(r,e,t,n,i,o,s){let a=r,c=i;for(;o.length>0;){let u=o[0];if(u in a){o.shift(),c=`${c}/${u}`;let l=H.asCID(a[u]);if(l!=null)return{entry:{type:"object",name:n,path:i,cid:t,node:e,depth:s,size:BigInt(e.length),content:async function*(){yield r}},next:{cid:l,name:u,path:c,toResolve:o}};a=a[u]}else throw(0,Tw.default)(new Error(`No property named ${u} found in node ${t}`),"ERR_NO_PROP")}return{entry:{type:"object",name:n,path:i,cid:t,node:e,depth:s,size:BigInt(e.length),content:async function*(){yield r}}}}var BB=async(r,e,t,n,i,o,s,a)=>{let c=await s.get(r,a),u=gy(c);return Lo(u,c,r,e,t,n,o)},Cw=BB;var AB=async(r,e,t,n,i,o,s,a)=>{let c=await s.get(r,a),u=xy(c);return Lo(u,c,r,e,t,n,o)},Nw=AB;var Uw=re(Re(),1);function IB(r,e,t,n){let i=BigInt(r.length),o=BigInt(e+i);return t>=o||n<e?new Uint8Array(0):(n>=e&&n<o&&(r=r.subarray(0,Number(n-e))),t>=e&&t<o&&(r=r.subarray(Number(t-e))),r)}var Ri=IB;var ea=re(Re(),1),SB=(r,e=0,t=r)=>{let n=BigInt(r),i=BigInt(e??0),o=BigInt(t);if(o!==n&&(o=i+o),o>n&&(o=n),i<0n)throw(0,ea.default)(new Error("Offset must be greater than or equal to 0"),"ERR_INVALID_PARAMS");if(i>n)throw(0,ea.default)(new Error("Offset must be less than the file size"),"ERR_INVALID_PARAMS");if(o<0n)throw(0,ea.default)(new Error("Length must be greater than or equal to 0"),"ERR_INVALID_PARAMS");if(o>n)throw(0,ea.default)(new Error("Length must be less than the file size"),"ERR_INVALID_PARAMS");return{start:i,end:o}},Do=SB;var _B=r=>{async function*e(t={}){let{start:n,end:i}=Do(r.length,t.offset,t.length),o=Ri(r,0n,n,i);t.onProgress?.(new P("unixfs:exporter:progress:identity",{bytesRead:BigInt(o.byteLength),totalBytes:i-n,fileSize:BigInt(r.byteLength)})),yield o}return e},kB=async(r,e,t,n,i,o,s,a)=>{if(n.length>0)throw(0,Uw.default)(new Error(`No link named ${t} found in raw node ${r}`),"ERR_NOT_FOUND");let c=Et(r.multihash.bytes);return{entry:{type:"identity",name:e,path:t,cid:r,content:_B(c.digest),depth:o,size:BigInt(c.digest.length),node:c.digest}}},Lw=kB;var RB=async(r,e,t,n,i,o,s,a)=>{let c=await s.get(r,a),u=w0(c);return Lo(u,c,r,e,t,n,o)},Dw=RB;var Pw=re(Re(),1);var TB=r=>{async function*e(t={}){let{start:n,end:i}=Do(r.length,t.offset,t.length),o=Ri(r,0n,n,i);t.onProgress?.(new P("unixfs:exporter:progress:raw",{bytesRead:BigInt(o.byteLength),totalBytes:i-n,fileSize:BigInt(r.byteLength)})),yield o}return e},CB=async(r,e,t,n,i,o,s,a)=>{if(n.length>0)throw(0,Pw.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:TB(c),depth:o,size:BigInt(c.length),node:c}}},Ow=CB;var ra=re(Re(),1);var ta=re(Re(),1);var NB=async function(r){return(await ki.encode(r)).slice(0,8).reverse()},UB=async(r,e,t)=>{let n=(e.tableSize()-1).toString(16).length;await Promise.all(r.map(async i=>{if(i.Name==null)throw new Error("Unexpected Link without a Name");if(i.Name.length===n){let o=parseInt(i.Name,16);e._putObjectAt(o,new Ut({hash:t._options.hash,bits:t._options.bits},e,o));return}await t.put(i.Name.substring(2),!0)}))},Fw=(r,e)=>r.toString(16).toUpperCase().padStart(e,"0").substring(0,e),LB=r=>{let e=r.bucket,t=[];for(;e._parent!=null;)t.push(e),e=e._parent;return t.push(e),t.reverse()},Vw=async(r,e,t,n,i)=>{if(n==null){if(r.Data==null)throw(0,ta.default)(new Error("no data in PBNode"),"ERR_NOT_UNIXFS");let h;try{h=W.unmarshal(r.Data)}catch(d){throw(0,ta.default)(d,"ERR_NOT_UNIXFS")}if(h.type!=="hamt-sharded-directory")throw(0,ta.default)(new Error("not a HAMT"),"ERR_NOT_UNIXFS");if(h.fanout==null)throw(0,ta.default)(new Error("missing fanout"),"ERR_NOT_UNIXFS");let p=Uo({hashFn:NB,bits:Math.log2(Number(h.fanout))});n={rootBucket:p,hamtDepth:1,lastBucket:p}}let o=(n.lastBucket.tableSize()-1).toString(16).length;await UB(r.Links,n.lastBucket,n.rootBucket);let s=await n.rootBucket._findNewBucketAndPos(e),a=Fw(s.pos,o),c=LB(s);c.length>n.hamtDepth&&(n.lastBucket=c[n.hamtDepth],a=Fw(n.lastBucket._posAtParent,o));let u=r.Links.find(h=>{if(h.Name==null)return!1;let p=h.Name.substring(0,o),d=h.Name.substring(o);return!(p!==a||d!==""&&d!==e)});if(u==null)return;if(u.Name!=null&&u.Name.substring(o)===e)return u.Hash;n.hamtDepth++;let l=await t.get(u.Hash,i);return r=ve(l),Vw(r,e,t,n,i)},Mw=Vw;var DB=(r,e,t,n,i,o,s)=>{async function*a(c={}){let u=c.offset??0,l=c.length??e.Links.length,h=e.Links.slice(u,l);c.onProgress?.(new P("unixfs:exporter:walk:directory",{cid:r})),yield*Wt(h,p=>jt(p,d=>async()=>{let f=d.Name??"",m=`${n}/${f}`;return(await i(d.Hash,f,m,[],o+1,s,c)).entry}),p=>vi(p,{ordered:!0,concurrency:c.blockReadConcurrency}),p=>wt(p,d=>d!=null))}return a},Hw=DB;var Ti=re(Re(),1);async function $w(r,e,t,n,i,o,s){if(e instanceof Uint8Array){let u=Ri(e,n,i,o);t.push(u);return}if(e.Data==null)throw(0,Ti.default)(new Error("no data in PBNode"),"ERR_NOT_UNIXFS");let a;try{a=W.unmarshal(e.Data)}catch(u){throw(0,Ti.default)(u,"ERR_NOT_UNIXFS")}if(a.data!=null){let u=a.data,l=Ri(u,n,i,o);t.push(l),n+=BigInt(l.byteLength)}let c=[];if(e.Links.length!==a.blockSizes.length)throw(0,Ti.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],h=n,p=h+a.blockSizes[u];if((i>=h&&i<p||o>=h&&o<=p||i<h&&o>p)&&c.push({link:l,blockStart:n}),n=p,n>o)break}await Wt(c,u=>jt(u,l=>async()=>{let h=await r.get(l.link.Hash,s);return{...l,block:h}}),u=>vi(u,{ordered:!0,concurrency:s.blockReadConcurrency}),async u=>{for await(let{link:l,block:h,blockStart:p}of u){let d;switch(l.Hash.code){case Te:d=ve(h);break;case Ne:d=h;break;default:t.end((0,Ti.default)(new Error(`Unsupported codec: ${l.Hash.code}`),"ERR_NOT_UNIXFS"));return}let f=new yt({concurrency:1});f.on("error",m=>{t.end(m)}),f.add(async()=>{s.onProgress?.(new P("unixfs:exporter:walk:file",{cid:l.Hash})),await $w(r,d,t,p,i,o,s)}),await f.onIdle()}}),n>=o&&t.end()}var PB=(r,e,t,n,i,o,s)=>{async function*a(c={}){let u=t.fileSize();if(u===void 0)throw new Error("File was a directory");let{start:l,end:h}=Do(u,c.offset,c.length);if(h===0n)return;let p=0n,d=h-l,f=Vt();c.onProgress?.(new P("unixfs:exporter:walk:file",{cid:r})),$w(s,e,f,0n,l,h,c).catch(m=>{f.end(m)});for await(let m of f)if(m!=null){if(p+=BigInt(m.byteLength),p>d)throw f.end(),(0,Ti.default)(new Error("Read too many bytes - the file size reported by the UnixFS data in the root node may be incorrect"),"ERR_OVER_READ");p===d&&f.end(),c.onProgress?.(new P("unixfs:exporter:progress:unixfs:file",{bytesRead:p,totalBytes:d,fileSize:u})),yield m}if(p<d)throw(0,Ti.default)(new Error("Traversed entire DAG but did not read enough bytes"),"ERR_UNDER_READ")}return a},Ef=PB;var Tl=re(Re(),1);var OB=(r,e,t,n,i,o,s)=>{function a(c={}){return c.onProgress?.(new P("unixfs:exporter:walk:hamt-sharded-directory",{cid:r})),zw(e,n,i,o,s,c)}return a};async function*zw(r,e,t,n,i,o){let s=r.Links;if(r.Data==null)throw(0,Tl.default)(new Error("no data in PBNode"),"ERR_NOT_UNIXFS");let a;try{a=W.unmarshal(r.Data)}catch(l){throw(0,Tl.default)(l,"ERR_NOT_UNIXFS")}if(a.fanout==null)throw(0,Tl.default)(new Error("missing fanout"),"ERR_NOT_UNIXFS");let c=(a.fanout-1n).toString(16).length,u=Wt(s,l=>jt(l,h=>async()=>{let p=h.Name!=null?h.Name.substring(c):null;if(p!=null&&p!==""){let d=await t(h.Hash,p,`${e}/${p}`,[],n+1,i,o);return{entries:d.entry==null?[]:[d.entry]}}else{let d=await i.get(h.Hash,o);return r=ve(d),o.onProgress?.(new P("unixfs:exporter:walk:hamt-sharded-directory",{cid:h.Hash})),{entries:zw(r,e,t,n,i,o)}}}),l=>vi(l,{ordered:!0,concurrency:o.blockReadConcurrency}));for await(let{entries:l}of u)yield*l}var Kw=OB;var FB=(r,e)=>r.Links.find(n=>n.Name===e)?.Hash,VB={raw:Ef,file:Ef,directory:Hw,"hamt-sharded-directory":Kw,metadata:(r,e,t,n,i,o,s)=>()=>[],symlink:(r,e,t,n,i,o,s)=>()=>[]},MB=async(r,e,t,n,i,o,s,a)=>{let c=await s.get(r,a),u=ve(c),l,h;if(e==null&&(e=r.toString()),u.Data==null)throw(0,ra.default)(new Error("no data in PBNode"),"ERR_NOT_UNIXFS");try{l=W.unmarshal(u.Data)}catch(d){throw(0,ra.default)(d,"ERR_NOT_UNIXFS")}if(t==null&&(t=e),n.length>0){let d;if(l?.type==="hamt-sharded-directory"?d=await Mw(u,n[0],s):d=FB(u,n[0]),d==null)throw(0,ra.default)(new Error("file does not exist"),"ERR_NOT_FOUND");let f=n.shift(),m=`${t}/${f}`;h={cid:d,toResolve:n,name:f??"",path:m}}let p=VB[l.type](r,u,l,t,i,o,s);if(p==null)throw(0,ra.default)(new Error("could not find content exporter"),"ERR_NOT_FOUND");return l.isDirectory()?{entry:{type:"directory",name:e,path:t,cid:r,content:p,unixfs:l,depth:o,node:u,size:l.fileSize()},next:h}:{entry:{type:"file",name:e,path:t,cid:r,content:p,unixfs:l,depth:o,node:u,size:l.fileSize()},next:h}},qw=MB;var HB={[Te]:qw,[Ne]:Ow,[Bo]:Cw,[Ao]:Nw,[et.code]:Lw,[$i]:Dw},jw=async(r,e,t,n,i,o,s)=>{let a=HB[r.code];if(a==null)throw(0,Gw.default)(new Error(`No resolver for code ${r.code}`),"ERR_NO_RESOLVER");return a(r,e,t,n,jw,i,o,s)},Ww=jw;var $B=(r="")=>(r.trim().match(/([^\\^/]|\\\/)+/g)??[]).filter(Boolean),zB=r=>{if(r instanceof Uint8Array)return{cid:H.decode(r),toResolve:[]};let e=H.asCID(r);if(e!=null)return{cid:e,toResolve:[]};if(typeof r=="string"){r.indexOf("/ipfs/")===0&&(r=r.substring(6));let t=$B(r);return{cid:H.parse(t[0]),toResolve:t.slice(1)}}throw(0,Cl.default)(new Error(`Unknown path type ${r}`),"ERR_BAD_PATH")};async function*vf(r,e,t={}){let{cid:n,toResolve:i}=zB(r),o=n.toString(),s=o,a=i.length;for(;;){let c=await Ww(n,o,s,i,a,e,t);if(c.entry==null&&c.next==null)throw(0,Cl.default)(new Error(`Could not resolve ${r}`),"ERR_NOT_FOUND");if(c.entry!=null&&(yield c.entry),c.next==null)return;i=c.next.toResolve,n=c.next.cid,o=c.next.name,s=c.next.path}}async function Xe(r,e,t={}){let n=await Xn(vf(r,e,t));if(n==null)throw(0,Cl.default)(new Error(`Could not resolve ${r}`),"ERR_NOT_FOUND");return n}async function*Nl(r,e,t={}){let n=await Xe(r,e,t);if(n==null)return;if(yield n,n.type==="directory")for await(let o of i(n,t))yield o;async function*i(o,s){for await(let a of o.content(s))yield a,!(a instanceof Uint8Array)&&a.type==="directory"&&(yield*i(a,s))}}var n2=re(r2(),1),nt=n2.default;var lr=class extends Error{name;code;constructor(e,t,n){super(e),this.name=t,this.code=n}},Cr=class extends lr{constructor(e="not a Unixfs node"){super(e,"NotUnixFSError","ERR_NOT_UNIXFS")}},ht=class extends lr{constructor(e="invalid PBNode"){super(e,"InvalidPBNodeError","ERR_INVALID_PBNODE")}},wn=class extends lr{constructor(e="unknown error"){super(e,"InvalidPBNodeError","ERR_UNKNOWN_ERROR")}},na=class extends lr{constructor(e="path already exists"){super(e,"AlreadyExistsError","ERR_ALREADY_EXISTS")}},Dl=class extends lr{constructor(e="path does not exist"){super(e,"DoesNotExistError","ERR_DOES_NOT_EXIST")}},Fo=class extends lr{constructor(e="no content"){super(e,"NoContentError","ERR_NO_CONTENT")}},Pl=class extends lr{constructor(e="not a file"){super(e,"NotAFileError","ERR_NOT_A_FILE")}},Zn=class extends lr{constructor(e="not a directory"){super(e,"NotADirectoryError","ERR_NOT_A_DIRECTORY")}},it=class extends lr{constructor(e="invalid parameters"){super(e,"InvalidParametersError","ERR_INVALID_PARAMETERS")}};var _f=re(Sl(),1);function Fl(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 i=this._buffers[this._currentBufferIndex],o=Math.min(i.availableBits(),t),s=i.take(o);n=(n<<o)+s,t-=o,this._availableBits-=o,i.availableBits()===0&&this._currentBufferIndex++}return n}untake(e){let t=e;for(;t>0;){let n=this._buffers[this._currentBufferIndex],i=Math.min(n.totalBits()-n.availableBits(),t);n.untake(i),t-=i,this._availableBits+=i,this._currentBufferIndex>0&&n.totalBits()===n.availableBits()&&(this._depth--,this._currentBufferIndex--)}}async _produceMoreBits(){this._depth++;let e=this._depth>0?Ee([this._value,Uint8Array.from([this._depth])]):this._value,t=await this._hashFn(e),n=new Af(t);this._buffers.push(n),this._availableBits+=n.availableBits()}},YB=[255,254,252,248,240,224,192,128],XB=[1,3,7,15,31,63,127,255],Af=class{_value;_currentBytePos;_currentBitPos;constructor(e){this._value=e,this._currentBytePos=e.length-1,this._currentBitPos=7}availableBits(){return this._currentBitPos+1+this._currentBytePos*8}totalBits(){return this._value.length*8}take(e){let t=e,n=0;for(;t>0&&this._haveBits();){let i=this._value[this._currentBytePos],o=this._currentBitPos+1,s=Math.min(o,t),a=ZB(i,o-s,s);n=(n<<s)+a,t-=s,this._currentBitPos-=s,this._currentBitPos<0&&(this._currentBitPos=7,this._currentBytePos--)}return n}untake(e){for(this._currentBitPos+=e;this._currentBitPos>7;)this._currentBitPos-=8,this._currentBytePos+=1}_haveBits(){return this._currentBytePos>=0}};function ZB(r,e,t){let n=JB(e,t);return(r&n)>>>e}function JB(r,e){return YB[r]&XB[Math.min(e+r-1,7)]}var ia=BigInt(ki.code),Ci=8;async function Vo(r){return(await ki.encode(r)).subarray(0,8).reverse()}var s2=re(Sl(),1);var ur=async(r,e,t)=>{t.codec==null&&(t.codec=De);let n=await he.digest(r),i=H.create(t.cidVersion,t.codec.code,n);return await e.put(i,r,{...t,signal:t.signal}),i};var If=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}},Vl=class extends If{_bucket;constructor(e,t){super(e,t),this._bucket=Uo({hashFn:Vo,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=o2(this._bucket,this,this.options),this.nodeSize)}async*flush(e){for await(let t of i2(this._bucket,e,this,this.options))yield{...t,path:this.path}}};async function*i2(r,e,t,n){let i=r._children,o=[],s=0n;for(let d=0;d<i.length;d++){let f=i.get(d);if(f==null)continue;let m=d.toString(16).toUpperCase().padStart(2,"0");if(f instanceof Ut){let y;for await(let g of i2(f,e,null,n))y=g;if(y==null)throw new Error("Could not flush sharded directory, no subshard found");o.push({Name:m,Tsize:Number(y.size),Hash:y.cid}),s+=y.size}else if(QB(f.value)){let y=f.value,g;for await(let x of y.flush(e))g=x,yield g;if(g==null)throw new Error("Did not flush dir");let w=m+f.key;o.push({Name:w,Tsize:Number(g.size),Hash:g.cid}),s+=g.size}else{let y=f.value;if(y.cid==null)continue;let g=m+f.key,w=y.size;o.push({Name:g,Tsize:Number(w),Hash:y.cid}),s+=BigInt(w??0)}}let a=Uint8Array.from(i.bitField().reverse()),c=new W({type:"hamt-sharded-directory",data:a,fanout:BigInt(r.tableSize()),hashType:ia,mtime:t?.mtime,mode:t?.mode}),u={Data:c.marshal(),Links:o},l=ce(_e(u)),h=await ur(l,e,n),p=BigInt(l.byteLength)+s;yield{cid:h,unixfs:c,size:p}}function QB(r){return typeof r.flush=="function"}function o2(r,e,t){let n=r._children,i=[];for(let c=0;c<n.length;c++){let u=n.get(c);if(u==null)continue;let l=c.toString(16).toUpperCase().padStart(2,"0");if(u instanceof Ut){let h=o2(u,null,t);i.push({Name:l,Tsize:Number(h),Hash:t.cidVersion===0?Ml:Hl})}else if(typeof u.value.flush=="function"){let p=u.value.nodeSize();i.push({Name:l+u.key,Tsize:Number(p),Hash:t.cidVersion===0?Ml:Hl})}else{let h=u.value;if(h.cid==null)continue;let p=l+u.key,d=h.size;i.push({Name:p,Tsize:Number(d),Hash:h.cid})}}let o=Uint8Array.from(n.bitField().reverse()),s=new W({type:"hamt-sharded-directory",data:o,fanout:BigInt(r.tableSize()),hashType:ia,mtime:e?.mtime,mode:e?.mode});return ce(_e({Data:s.marshal(),Links:i})).length}var Ml=H.parse("QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn"),Hl=H.parse("zdj7WbTaiJT1fgatdet9Ei9iDB5hdCxkbVyhyh8YTUnXMiwYi");var Sf=oe("helia:unixfs:commands:utils:hamt-utils"),$l=r=>r.toString(16).toUpperCase().padStart(2,"0").substring(0,2),a2=async(r,e,t)=>{let n=new Vl({root:!0,dir:!0,parent:void 0,parentKey:void 0,path:"",dirty:!0,flat:!1,mtime:t.mtime,mode:t.mode},t);for(let o=0;o<e.length;o++)await n._bucket.put(e[o].name,{size:e[o].size,cid:e[o].cid});let i=await Xn(n.flush(r));if(i==null)throw new Error("Flushing shard yielded no result");return i},zl=async(r,e,t)=>{let n=W.unmarshal(r[0].node.Data??new Uint8Array(0)),i=BigInt(Math.pow(2,Ci));r.reverse();let o,s;for(let a=0;a<r.length;a++){let c=a===r.length-1,u=r[a],l=Uint8Array.from(u.children.bitField().reverse()),h=new W({type:"hamt-sharded-directory",data:l,fanout:i,hashType:ia});c&&(h.mtime=n.mtime,h.mode=n.mode),s={Data:h.marshal(),Links:u.node.Links};let p=ce(_e(s));if(o=await ur(p,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?");Sf("updating link in parent sub-shard with prefix %s",d.prefix),d.node.Links=d.node.Links.filter(f=>f.Name!==d.prefix),d.node.Links.push({Name:d.prefix,Hash:o,Tsize:u.node.Links.reduce((f,m)=>f+(m.Tsize??0),p.byteLength)})}}if(o==null||s==null)throw new Error("Noting persisted");return{cid:o,node:s}},Kl=async(r,e,t,n)=>{let o=Fl(Vo)(Y(e)),s=[];for(;;){let a=await t.get(r,n),c=ve(a),u=new s2.default,l=await o.take(Ci),h=$l(l);s.push({prefix:h,children:u,node:c});let p;for(let f of c.Links){let m=f.Name??"";if(m.length<2)throw new Error("Invalid HAMT - link name was too short");let y=parseInt(m.substring(0,2),16);u.set(y,!0),m.startsWith(h)&&(p=f)}if(p==null){Sf("no link found with prefix %s for %s",h,e);break}let d=p.Name??"";if(d.length<2)throw new Error("Invalid HAMT - link name was too short");if(d.length===2){r=p.Hash,Sf("descend into sub-shard with prefix %s",d);continue}break}return{path:s,hash:o}};async function ql(r,e,t,n){if(r.Data==null)throw new Error("DagPB node had no data");let i=W.unmarshal(r.Data),o;if(i.type==="directory")o=eA(r);else if(i.type==="hamt-sharded-directory")o=await c2(r,0,t,e,n);else throw new Error("Can only estimate the size of directories or shards");return o>t}function eA(r){let e=0;for(let t of r.Links)e+=(t.Name??"").length,e+=t.Hash.version===1?Hl.bytes.byteLength:Ml.bytes.byteLength;return e}async function c2(r,e,t,n,i){if(e>t)return t;if(r.Data==null||!W.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===Te){let c=await n.get(s.Hash,i),u=ve(c);e+=await c2(u,e,t,n,i)}}return e}var Nr=oe("helia:unixfs:components:utils:add-link");async function Mo(r,e,t,n){if(r.node.Data==null)throw new it("Invalid parent passed to addLink");if(W.unmarshal(r.node.Data).type==="hamt-sharded-directory")return Nr("adding link to sharded directory"),nA(r,e,t,n);Nr(`adding ${e.Name} (${e.Hash}) to regular directory`);let o=await rA(r,e,t,n);if(await ql(o.node,t,n.shardSplitThresholdBytes,n)){Nr("converting directory to sharded directory");let s=await tA(o,t);o.cid=s.cid,o.node=ve(await t.get(s.cid,n))}return o}var tA=async(r,e)=>{if(r.node.Data==null)throw new it("Invalid parent passed to convertToShardedDirectory");let t=W.unmarshal(r.node.Data),n=await a2(e,r.node.Links.map(i=>({name:i.Name??"",size:BigInt(i.Tsize??0),cid:i.Hash})),{mode:t.mode,mtime:t.mtime,cidVersion:r.cid.version});return Nr(`converted directory to sharded directory ${n.cid}`),n},rA=async(r,e,t,n)=>{let i=r.node.Links.filter(l=>{let h=l.Name===e.Name;if(h&&!n.allowOverwriting)throw new na;return!h});if(i.push(e),r.node.Data==null)throw new ht("Parent node with no data passed to addToDirectory");let o=W.unmarshal(r.node.Data),s;if(o.mtime!=null){let l=Date.now(),h=Math.floor(l/1e3);o.mtime={secs:BigInt(h),nsecs:(l-h*1e3)*1e3},s=o.marshal()}else s=r.node.Data;r.node=_e({Data:s,Links:i});let a=ce(r.node),c=await he.digest(a),u=H.create(r.cid.version,Te,c);return await t.put(u,a),{node:r.node,cid:u}},nA=async(r,e,t,n)=>{let{path:i,hash:o}=await Kl(r.cid,e.Name,t,n),s=i[i.length-1];if(s==null)throw new Error("Invalid HAMT, could not generate path");let a=s.prefix,c=parseInt(a,16);Nr("next prefix for %s is %s",e.Name,a);let u=`${a}${e.Name}`,l=s.node.Links.find(h=>(h.Name??"").startsWith(a));if(l!=null)if(Nr("link %s was present in shard",u),l.Name===u){if(!n.allowOverwriting)throw new na;Nr("overwriting %s in subshard",e.Name),s.node.Links=s.node.Links.filter(h=>h.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?!");{Nr("prefix %s already exists, creating new subshard",a);let h=s.node.Links.findIndex(y=>y.Name?.startsWith(a)),p=s.node.Links.splice(h,1)[0],d=(p.Name??"").substring(2),m=Fl(Vo)(Y(d));for(let y=0;y<i.length;y++)await m.take(Ci);for(;;){let y=await m.take(Ci),g=$l(y);p.Name=`${g}${d}`;let w=await o.take(Ci),x=$l(w);if(g===x){let I=new _f.default;I.set(w,!0),i.push({prefix:x,children:I,node:{Links:[]}});continue}let A=new _f.default;A.set(w,!0),A.set(y,!0),i.push({prefix:a,children:A,node:{Links:[p,{Name:`${x}${e.Name}`,Hash:e.Hash,Tsize:e.Tsize}]}});break}}}else Nr("link %s was not present in sub-shard",u),e.Name=u,s.node.Links.push(e),s.children.set(c,!0),Nr("adding %s to existing sub-shard",u);return zl(i,t,n)};async function Jn(r,e,t={}){let n=await Xe(r,e,t);if(n.type!=="directory")throw new Zn(`${r.toString()} was not a UnixFS directory`);return{cid:r,node:n.node}}async function Ho(r,e,t,n){let i=await Xe(r,t,n);if(i.type!=="directory"&&i.type!=="file"&&i.type!=="raw")throw new Cr(`${r.toString()} was not a UnixFS node`);return{Name:e,Tsize:i.node instanceof Uint8Array?i.node.byteLength:iA(i.node),Hash:r}}function iA(r){let e=r.Links.reduce((t,n)=>t+(n.Tsize??0),0);return ce(r).byteLength+e}var kf=oe("helia:unixfs:components:utils:resolve");async function Ur(r,e,t,n){if(e==null||e==="")return{cid:r};kf('resolve "%s" under %c',e,r);let i=e.split("/").filter(Boolean),o=[{name:"",cid:r,size:0n}];for(let s=0;s<i.length;s++){let a=i[s],c=await Xe(r,t,n);if(kf('resolving "%s"',a,c),c.type==="file"){if(s<i.length-1)throw new it("Path was invalid");r=c.cid}else if(c.type==="directory"){let u;for await(let l of c.content())if(l.name===a){u=l.cid;break}if(u==null)throw new Dl("Could not find path in directory");r=u,o.push({name:a,cid:r,size:c.size})}else throw new it("Could not resolve path")}return kf("resolved %s to %c",e,r),{cid:r,path:e,segments:o}}async function $o(r,e,t,n){if(e.segments==null||e.segments.length===0)return r;let i=e.segments.pop();if(i==null)throw new Error("Insufficient segments");i.cid=r,e.segments.reverse();for(let o of e.segments){let[s,a]=await Promise.all([Jn(o.cid,t,n),Ho(i.cid,i.name,t,n)]);r=(await Mo(s,a,t,{...n,allowOverwriting:!0,cidVersion:r.version})).cid,o.cid=r,i=o}return r}var oA=nt.bind({ignoreUndefined:!0}),sA={};async function*l2(r,e,t={}){let n=oA(sA,t),i=await Ur(r,n.path,e,n),o=await Xe(i.cid,e,n);if(o.type!=="file"&&o.type!=="raw")throw new Pl;if(o.content==null)throw new Fo;yield*o.content(n)}var aA=nt.bind({ignoreUndefined:!0}),cA=oe("helia:unixfs:chmod"),lA={recursive:!1,shardSplitThresholdBytes:262144};async function u2(r,e,t,n={}){let i=aA(lA,n),o=await Ur(r,i.path,t,n);if(cA("chmod %c %d",o.cid,e),i.recursive){let p=await Wt(async function*(){for await(let d of Nl(o.cid,t,n)){let f,m=[];if(d.type==="raw")f=new W({type:"file",data:d.node});else if(d.type==="file"||d.type==="directory")f=d.unixfs,m=d.node.Links;else throw new Cr;f.mode=e;let y={Data:f.marshal(),Links:m};yield{path:d.path,content:y}}},d=>Yn(d,t,{...i,dagBuilder:async function*(f,m){for await(let y of f)yield async function(){let g=y.content,w=ce(g),x=await ur(w,m,{...i,cidVersion:r.version});if(g.Data==null)throw new ht(`${x} had no data`);let A=W.unmarshal(g.Data);return{cid:x,size:BigInt(w.length),path:y.path,unixfs:A}}}}),async d=>Xn(d));if(p==null)throw new wn(`Could not chmod ${o.cid.toString()}`);return $o(p.cid,o,t,i)}let s=await t.get(o.cid,n),a,c=[];if(o.cid.code===Ne)a=new W({type:"file",data:s});else{let p=ve(s);if(p.Data==null)throw new ht(`${o.cid.toString()} had no data`);c=p.Links,a=W.unmarshal(p.Data)}a.mode=e;let u=ce({Data:a.marshal(),Links:c}),l=await he.digest(u),h=H.create(o.cid.version,Te,l);return await t.put(h,u),$o(h,o,t,i)}var uA=nt.bind({ignoreUndefined:!0}),hA=oe("helia:unixfs:cp"),dA={force:!1,shardSplitThresholdBytes:262144};async function h2(r,e,t,n,i={}){let o=uA(dA,i);if(t.includes("/"))throw new it("Name must not have slashes");let[s,a]=await Promise.all([Jn(e,n,o),Ho(r,t,n,o)]);return hA('Adding %c as "%s" to %c',r,t,e),(await Mo(s,a,n,{allowOverwriting:o.force,cidVersion:e.version,...o})).cid}var fA=nt.bind({ignoreUndefined:!0}),pA={};async function*d2(r,e,t={}){let n=fA(pA,t),i=await Ur(r,n.path,e,n),o=await Xe(i.cid,e);if(o.type==="file"||o.type==="raw"){yield o;return}if(o.content==null)throw new Fo;if(o.type!=="directory")throw new Zn;yield*o.content({offset:t.offset,length:t.length})}var mA=nt.bind({ignoreUndefined:!0}),f2=oe("helia:unixfs:mkdir"),yA={cidVersion:1,force:!1,shardSplitThresholdBytes:262144};async function p2(r,e,t,n={}){let i=mA(yA,n);if(e.includes("/"))throw new it("Path must not have slashes");if((await Xe(r,t,n)).type!=="directory")throw new Zn(`${r.toString()} was not a UnixFS directory`);f2("creating %s",e);let a={Data:new W({type:"directory",mode:i.mode,mtime:i.mtime}).marshal(),Links:[]},c=ce(a),u=await he.digest(c),l=H.create(i.cidVersion,Te,u);await t.put(l,c);let[h,p]=await Promise.all([Jn(r,t,i),Ho(l,e,t,i)]);return f2("adding empty dir called %s to %c",e,r),(await Mo(h,p,t,{...i,allowOverwriting:i.force})).cid}var Gl=oe("helia:unixfs:utils:remove-link");async function m2(r,e,t,n){if(r.node.Data==null)throw new ht("Parent node had no data");if(W.unmarshal(r.node.Data).type==="hamt-sharded-directory"){Gl(`removing ${e} from sharded directory`);let o=await wA(r,e,t,n);return await ql(o.node,t,n.shardSplitThresholdBytes,n)?o:(Gl("converting shard to flat directory %c",r.cid),xA(o,t,n))}return Gl(`removing link ${e} regular directory`),gA(r,e,t,n)}var gA=async(r,e,t,n)=>{r.node.Links=r.node.Links.filter(s=>s.Name!==e);let i=ce(r.node),o=await ur(i,t,{...n,cidVersion:r.cid.version});return Gl(`Updated regular directory ${o}`),{node:r.node,cid:o}},wA=async(r,e,t,n)=>{let{path:i}=await Kl(r.cid,e,t,n),o=i[i.length-1];if(o==null)throw new Error("Invalid HAMT, could not generate path");let s=o.node.Links.filter(u=>(u.Name??"").substring(2)===e).map(u=>u.Name).pop();if(s==null)throw new Error("File not found");let a=s.substring(0,2),c=parseInt(a,16);if(o.node.Links=o.node.Links.filter(u=>u.Name!==s),o.children.unset(c),o.node.Links.length===1)for(;i.length!==1;){let u=i[i.length-1];if(u==null||u.node.Links.length>1)break;i.pop();let l=i[i.length-1];if(l==null)break;let h=u.node.Links[0];l.node.Links=l.node.Links.filter(p=>!(p.Name??"").startsWith(l.prefix)),l.node.Links.push({Hash:h.Hash,Name:`${l.prefix}${(h.Name??"").substring(2)}`,Tsize:h.Tsize})}return zl(i,t,n)},xA=async(r,e,t)=>{if(r.node.Data==null)throw new it("Invalid parent passed to convertToFlatDirectory");let n={Links:[]},i=await Xe(r.cid,e);if(i.type!=="directory")throw new Error("Unexpected node type");for await(let c of i.content()){let u=0;c.node instanceof Uint8Array?u=c.node.byteLength:u=ce(c.node).length,n.Links.push({Hash:c.cid,Name:c.name,Tsize:u})}let o=W.unmarshal(r.node.Data);n.Data=new W({type:"directory",mode:o.mode,mtime:o.mtime}).marshal();let s=ce(_e(n));return{cid:await ur(s,e,{codec:De,cidVersion:r.cid.version,signal:t.signal}),node:n}};var bA=nt.bind({ignoreUndefined:!0}),EA=oe("helia:unixfs:rm"),vA={shardSplitThresholdBytes:262144};async function y2(r,e,t,n={}){let i=bA(vA,n);if(e.includes("/"))throw new it("Name must not have slashes");let o=await Jn(r,t,i);return EA("Removing %s from %c",e,r),(await m2(o,e,t,{...i,cidVersion:r.version})).cid}var BA=nt.bind({ignoreUndefined:!0}),AA=oe("helia:unixfs:stat"),IA={};async function g2(r,e,t={}){let n=BA(IA,t),i=await Ur(r,t.path,e,n);AA("stat %c",i.cid);let o=await Xe(i.cid,e,n);if(o.type!=="file"&&o.type!=="directory"&&o.type!=="raw")throw new Cr;let s=0n,a=0n,c=0n,u=0n,l=0,h,p,d=o.type,f;if(o.type==="raw"&&(s=BigInt(o.node.byteLength),a=BigInt(o.node.byteLength),c=BigInt(o.node.byteLength),u=BigInt(o.node.byteLength),l=1),o.type==="directory"&&(s=0n,a=BigInt(o.unixfs.marshal().byteLength),c=0n,u=a,l=1,h=o.unixfs.mode,p=o.unixfs.mtime,f=o.unixfs),o.type==="file"){let m=await w2(i.cid,e,n);s=o.unixfs.fileSize(),a=BigInt((o.node.Data?.byteLength??0)+o.node.Links.reduce((y,g)=>y+(g.Tsize??0),0)),c=BigInt(m.localFileSize),u=BigInt(m.localDagSize),l=m.blocks,h=o.unixfs.mode,p=o.unixfs.mtime,f=o.unixfs}return{cid:i.cid,mode:h,mtime:p,fileSize:s,dagSize:a,localFileSize:c,localDagSize:u,blocks:l,type:d,unixfs:f}}async function w2(r,e,t){let n={localFileSize:0,localDagSize:0,blocks:0};if(await e.has(r,t)){let i=await e.get(r,t);if(n.blocks++,n.localDagSize+=i.byteLength,r.code===Ne)n.localFileSize+=i.byteLength;else if(r.code===Te){let o=ve(i);if(o.Links.length>0)for(let s of o.Links){let a=await w2(s.Hash,e,t);n.localFileSize+=a.localFileSize,n.localDagSize+=a.localDagSize,n.blocks+=a.blocks}else{if(o.Data==null)throw new ht(`PBNode ${r.toString()} had no data`);let s=W.unmarshal(o.Data);if(s.data==null)throw new ht(`UnixFS node ${r.toString()} had no data`);n.localFileSize+=s.data.byteLength??0}}else throw new wn(`${r.toString()} was neither DAG_PB nor RAW`)}return n}var SA=nt.bind({ignoreUndefined:!0}),_A=oe("helia:unixfs:touch"),kA={recursive:!1,shardSplitThresholdBytes:262144};async function x2(r,e,t={}){let n=SA(kA,t),i=await Ur(r,n.path,e,n),o=n.mtime??{secs:BigInt(Math.round(Date.now()/1e3)),nsecs:0};if(_A("touch %c %o",i.cid,o),n.recursive){let p=await Wt(async function*(){for await(let d of Nl(i.cid,e)){let f,m;if(d.type==="raw")f=new W({data:d.node}),m=[];else if(d.type==="file"||d.type==="directory")f=d.unixfs,m=d.node.Links;else throw new Cr;f.mtime=o;let y={Data:f.marshal(),Links:m};yield{path:d.path,content:y}}},d=>Yn(d,e,{...n,dagBuilder:async function*(f,m){for await(let y of f)yield async function(){let g=y.content,w=ce(g),x=await ur(w,m,{...n,cidVersion:r.version});if(g.Data==null)throw new ht(`${x} had no data`);let A=W.unmarshal(g.Data);return{cid:x,size:BigInt(w.length),path:y.path,unixfs:A}}}}),async d=>Xn(d));if(p==null)throw new wn(`Could not chmod ${i.cid.toString()}`);return $o(p.cid,i,e,n)}let s=await e.get(i.cid,t),a,c=[];if(i.cid.code===Ne)a=new W({data:s});else{let p=ve(s);if(c=p.Links,p.Data==null)throw new ht(`${i.cid.toString()} had no data`);a=W.unmarshal(p.Data)}a.mtime=o;let u=ce({Data:a.marshal(),Links:c}),l=await he.digest(u),h=H.create(i.cid.version,Te,l);return await e.put(h,u),$o(h,i,e,n)}var Rf=class{components;constructor(e){this.components=e}async*addAll(e,t={}){yield*Iw(e,this.components.blockstore,t)}async addBytes(e,t={}){return Sw(e,this.components.blockstore,t)}async addByteStream(e,t={}){return _w(e,this.components.blockstore,t)}async addFile(e,t={}){return kw(e,this.components.blockstore,t)}async addDirectory(e={},t={}){return Rw(e,this.components.blockstore,t)}async*cat(e,t={}){yield*l2(e,this.components.blockstore,t)}async chmod(e,t,n={}){return u2(e,t,this.components.blockstore,n)}async cp(e,t,n,i={}){return h2(e,t,n,this.components.blockstore,i)}async*ls(e,t={}){yield*d2(e,this.components.blockstore,t)}async mkdir(e,t,n={}){return p2(e,t,this.components.blockstore,n)}async rm(e,t,n={}){return y2(e,t,this.components.blockstore,n)}async stat(e,t={}){return g2(e,this.components.blockstore,t)}async touch(e,t={}){return x2(e,this.components.blockstore,t)}};function b2(r){return new Rf(r)}var RA=42;function TA(r){if(r[0]!==0)throw new Error("Invalid CID for CBOR tag 42; expected leading 0x00");return H.decode(r.subarray(1))}function E2(r){let e=[];e[RA]=TA;let t=at(r,{allowIndefinite:!1,coerceUndefinedToNull:!0,allowNaN:!1,allowInfinity:!1,strict:!0,useMaps:!1,rejectDuplicateMapKeys:!0,tags:e,allowBigInt:!1});return new TextDecoder().decode(al(t))}function v2({cid:r,reqFormat:e,weak:t,rangeStart:n,rangeEnd:i}){let o=t===!0?"W/":"",s=e==null?"":`.${e}`;return(n!=null||i!=null)&&(s+=`.${n??"0"}-${i??"N"}`),`${o}"${r.toString()}${s}"`}async function B2(r,e,t,n){let i=t.forComponent("helia:verified-fetch:get-stream-from-async-iterable"),o=r[Symbol.asyncIterator](),{value:s,done:a}=await o.next();if(a===!0)throw i.error("No content found for path",e),new Error("No content found");return{stream:new ReadableStream({async start(u){n?.onProgress?.(new P("verified-fetch:request:progress:chunk")),u.enqueue(s)},async pull(u){let{value:l,done:h}=await o.next();if(h===!0){l!=null&&(n?.onProgress?.(new P("verified-fetch:request:progress:chunk")),u.enqueue(l)),u.close();return}n?.onProgress?.(new P("verified-fetch:request:progress:chunk")),u.enqueue(l)}}),firstChunk:s}}var A2=re(Od(),1),jl=class{lru;constructor(e){this.lru=(0,A2.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 Tf=new jl(1e3),CA=/^(?<protocol>ip[fn]s):\/\/(?<cidOrPeerIdOrDnsLink>[^/$?]+)\/?(?<path>[^$?]*)\??(?<queryString>.*)$/;async function I2({urlString:r,ipns:e,logger:t},n){let i=t.forComponent("helia:verified-fetch:parse-url-string"),o=r.match(CA);if(o==null||o.groups==null)throw new TypeError(`Invalid URL: ${r}, please use ipfs:// or ipns:// URLs only.`);let{protocol:s,cidOrPeerIdOrDnsLink:a,path:c,queryString:u}=o.groups,l,h,p=[];if(s==="ipfs")try{l=H.parse(a)}catch(y){i.error(y),p.push(new TypeError("Invalid CID for ipfs://<cid> URL"))}else{let y=Tf.get(a);if(y!=null)l=y.cid,h=y.path,i.trace("resolved %s to %c from cache",a,l);else{i.trace("Attempting to resolve PeerId for %s",a);let g=null;try{g=Yt(a),y=await e.resolve(g,{onProgress:n?.onProgress}),l=y?.cid,h=y?.path,i.trace("resolved %s to %c",a,l),Tf.set(a,y,60*1e3*2)}catch(w){g==null?(i.error('Could not parse PeerId string "%s"',a,w),p.push(new TypeError(`Could not parse PeerId in ipns url "${a}", ${w.message}`))):(i.error("Could not resolve PeerId %c",g,w),p.push(new TypeError(`Could not resolve PeerId "${a}", ${w.message}`)))}if(l==null){i.trace("Attempting to resolve DNSLink for %s",a);try{y=await e.resolveDns(a,{onProgress:n?.onProgress}),l=y?.cid,h=y?.path,i.trace("resolved %s to %c",a,l),Tf.set(a,y,60*1e3*2)}catch(w){i.error('Could not resolve DnsLink for "%s"',a,w),p.push(w)}}}}if(l==null)throw new AggregateError(p,`Invalid resource. Cannot determine CID from URL "${r}"`);let d={};if(u!=null&&u.length>0){let y=u.split("&");for(let g of y){let[w,x]=g.split("=");d[w]=decodeURIComponent(x)}}let f=[];c.length>0&&f.push(c),h!=null&&h.length>0&&f.push(h);let m=f.join("/");return{protocol:s,cid:l,path:m,query:d}}async function S2(r,{ipns:e,logger:t},n){if(typeof r=="string")return I2({urlString:r,ipns:e,logger:t},{onProgress:n?.onProgress});let i=H.asCID(r);if(i!=null)return{cid:i,protocol:"ipfs",path:"",query:{}};throw new TypeError(`Invalid resource. Cannot determine CID from resource: ${r}`)}async function _2(r,e,t){let n=[],i;for await(let o of vf(e,r,t))n.push(o.cid),i=o;if(i==null)throw new Error("No terminal element found");return{ipfsRoots:n,terminalElement:i}}function NA(r){if(r==null)return;let e;return r?.signal===null&&(e=void 0),{...r,signal:e}}function Wl(r){return new Response(r,{status:200,statusText:"OK"})}function Lr(r){return new Response(r,{status:501,statusText:"Not Implemented"})}var Yl=class{helia;ipns;unixfs;pathWalker;log;contentTypeParser;constructor({helia:e,ipns:t,unixfs:n,pathWalker:i},o){this.helia=e,this.log=e.logger.forComponent("helia:verified-fetch"),this.ipns=t??sg(e,{resolvers:[vl("https://mozilla.cloudflare-dns.com/dns-query"),vl("https://dns.google/resolve")]}),this.unixfs=n??b2(e),this.pathWalker=i??_2,this.contentTypeParser=o?.contentTypeParser,this.log.trace("created VerifiedFetch instance")}async handleIPNSRecord({cid:e,path:t,options:n}){let i=Lr("vnd.ipfs.ipns-record support is not implemented");return i.headers.set("X-Content-Type-Options","nosniff"),i}async handleIPLDCar({cid:e,path:t,options:n}){let i=Lr("vnd.ipld.car support is not implemented");return i.headers.set("X-Content-Type-Options","nosniff"),i}async handleJson({cid:e,path:t,options:n}){this.log.trace("fetching %c/%s",e,t),n?.onProgress?.(new P("verified-fetch:request:start",{cid:e,path:t}));let i=await this.helia.blockstore.get(e,{signal:n?.signal,onProgress:n?.onProgress}),o=Wl(i);return o.headers.set("content-type","application/json"),n?.onProgress?.(new P("verified-fetch:request:end",{cid:e,path:t})),o}async handleDagCbor({cid:e,path:t,options:n}){this.log.trace("fetching %c/%s",e,t),n?.onProgress?.(new P("verified-fetch:request:start",{cid:e,path:t}));let i=await this.helia.blockstore.get(e),o;try{o=E2(i)}catch(a){this.log("could not decode DAG-CBOR as JSON-safe, falling back to `application/octet-stream`",a),o=i}let s=Wl(o);return s.headers.set("content-type",o instanceof Uint8Array?"application/octet-stream":"application/json"),n?.onProgress?.(new P("verified-fetch:request:end",{cid:e,path:t})),s}async handleDagPb({cid:e,path:t,options:n,terminalElement:i}){this.log.trace("fetching %c/%s",e,t);let o=i?.cid??e,s;if(i?.type==="directory"){let h=i.cid,p="index.html";try{this.log.trace("found directory at %c/%s, looking for index.html",e,t),n?.onProgress?.(new P("verified-fetch:request:start",{cid:h,path:p})),s=await this.unixfs.stat(h,{path:p,signal:n?.signal,onProgress:n?.onProgress}),this.log.trace("found root file at %c/%s with cid %c",h,p,s.cid),t=p,o=s.cid}catch(d){return this.log("error loading path %c/%s",h,p,d),Lr("Unable to find index.html for directory at given path. Support for directories with implicit root is not implemented")}finally{n?.onProgress?.(new P("verified-fetch:request:end",{cid:h,path:p}))}}n?.onProgress?.(new P("verified-fetch:request:start",{cid:o,path:""}));let a=this.unixfs.cat(o,{signal:n?.signal,onProgress:n?.onProgress});this.log("got async iterator for %c/%s",e,t);let{stream:c,firstChunk:u}=await B2(a,t??"",this.helia.logger,{onProgress:n?.onProgress}),l=Wl(c);return await this.setContentType(u,t,l),n?.onProgress?.(new P("verified-fetch:request:end",{cid:o,path:""})),l}async handleRaw({cid:e,path:t,options:n}){this.log.trace("fetching %c/%s",e,t),n?.onProgress?.(new P("verified-fetch:request:start",{cid:e,path:t}));let i=await this.helia.blockstore.get(e),o=Wl(i);return await this.setContentType(i,t,o),n?.onProgress?.(new P("verified-fetch:request:end",{cid:e,path:t})),o}async setContentType(e,t,n){let i="application/octet-stream";if(this.contentTypeParser!=null)try{let o=t.split("/").pop()?.trim();o=o===""?void 0:o;let s=this.contentTypeParser(e,o);if(UA(s)){let a=await s;a!=null&&(i=a)}else s!=null&&(i=s)}catch(o){this.log.error("Error parsing content type",o)}n.headers.set("content-type",i)}getFormat({headerFormat:e,queryFormat:t}){let n={"vnd.ipld.raw":"raw","vnd.ipld.car":"car","application/x-tar":"tar","application/vnd.ipld.dag-json":"dag-json","application/vnd.ipld.dag-cbor":"dag-cbor","application/json":"json","application/cbor":"cbor","vnd.ipfs.ipns-record":"ipns-record"};if(e!=null){for(let i in n)if(e.includes(i))return n[i]}else if(t!=null)return t;return null}formatHandlers={raw:async()=>Lr("application/vnd.ipld.raw support is not implemented"),car:this.handleIPLDCar,"ipns-record":this.handleIPNSRecord,tar:async()=>Lr("application/x-tar support is not implemented"),"dag-json":async()=>Lr("application/vnd.ipld.dag-json support is not implemented"),"dag-cbor":async()=>Lr("application/vnd.ipld.dag-cbor support is not implemented"),json:async()=>Lr("application/json support is not implemented"),cbor:async()=>Lr("application/cbor support is not implemented")};codecHandlers={[Te]:this.handleDagPb,[Ao]:this.handleJson,[$i]:this.handleJson,[Bo]:this.handleDagCbor,[Ne]:this.handleRaw,[et.code]:this.handleRaw};async fetch(e,t){let n=NA(t),{path:i,query:o,...s}=await S2(e,{ipns:this.ipns,logger:this.helia.logger},n),a=s.cid,c,u=this.getFormat({headerFormat:new Headers(n?.headers).get("accept"),queryFormat:o.format??null});if(u!=null){let p=this.formatHandlers[u];if(p!=null&&(c=await p.call(this,{cid:a,path:i,options:n}),c.status===501))return c}let l,h;try{let p=await this.pathWalker(this.helia.blockstore,`${a.toString()}/${i}`,n);h=p.ipfsRoots,l=p.terminalElement}catch(p){this.log.error("Error walking path %s",i,p)}if(c==null){let p=this.codecHandlers[a.code];if(p!=null)c=await p.call(this,{cid:a,path:i,options:n,terminalElement:l});else return Lr(`Support for codec with code ${a.code} is not yet implemented. Please open an issue at https://github.com/ipfs/helia/issues/new`)}return c.headers.set("etag",v2({cid:a,reqFormat:u??void 0,weak:!1})),c.headers.set("cache-control","public, max-age=29030400, immutable"),c.headers.set("X-Ipfs-Path",e.toString()),h!=null&&c.headers.set("X-Ipfs-Roots",h.map(p=>p.toV1().toString()).join(",")),c}async start(){await this.helia.start()}async stop(){await this.helia.stop()}};function UA(r){return r?.then!=null}var oa,Xl=async function(e,t){return oa==null&&(oa=await Cf()),oa(e,t)};Xl.start=async function(){await oa?.start()};Xl.stop=async function(){await oa?.stop()};async function Cf(r,e){let t=e?.contentTypeParser;LA(r)||(r=await Hy({blockBrokers:[Zo({gateways:r?.gateways})],routers:(r?.routers??["https://delegated-ipfs.dev"]).map(o=>Cs(o))}));let n=new Yl({helia:r},{contentTypeParser:t});async function i(o,s){return n.fetch(o,s)}return i.stop=n.stop.bind(n),i.start=n.start.bind(n),i}function LA(r){return r?.blockstore!=null&&r?.datastore!=null&&r?.gc!=null&&r?.stop!=null&&r?.start!=null}return H2(DA);})();
|
|
9
9
|
/*! Bundled license information:
|
|
10
10
|
|
|
11
11
|
pvtsutils/build/index.js:
|