@helia/utils 0.3.2 → 0.3.3-3bf5ab0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/index.min.js +1 -1
- package/dist/src/index.js.map +1 -1
- package/package.json +4 -4
- package/src/index.ts +1 -1
- package/dist/typedoc-urls.json +0 -9
package/README.md
CHANGED
|
@@ -53,7 +53,7 @@ $ npm i @helia/utils
|
|
|
53
53
|
|
|
54
54
|
## Browser `<script>` tag
|
|
55
55
|
|
|
56
|
-
Loading this module through a script tag will make
|
|
56
|
+
Loading this module through a script tag will make its exports available as `HeliaUtils` in the global namespace.
|
|
57
57
|
|
|
58
58
|
```html
|
|
59
59
|
<script src="https://unpkg.com/@helia/utils/dist/index.min.js"></script>
|
package/dist/index.min.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
(function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.HeliaUtils = factory()}(typeof self !== 'undefined' ? self : this, function () {
|
|
2
|
-
"use strict";var HeliaUtils=(()=>{var cs=Object.create;var vt=Object.defineProperty;var us=Object.getOwnPropertyDescriptor;var fs=Object.getOwnPropertyNames;var ls=Object.getPrototypeOf,hs=Object.prototype.hasOwnProperty;var he=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),$=(r,e)=>{for(var t in e)vt(r,t,{get:e[t],enumerable:!0})},Dn=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of fs(e))!hs.call(r,o)&&o!==t&&vt(r,o,{get:()=>e[o],enumerable:!(n=us(e,o))||n.enumerable});return r};var et=(r,e,t)=>(t=r!=null?cs(ls(r)):{},Dn(e||!r||!r.__esModule?vt(t,"default",{value:r,enumerable:!0}):t,r)),ds=r=>Dn(vt({},"__esModule",{value:!0}),r);var Bn=he((su,Nn)=>{var Ne=1e3,Be=Ne*60,Pe=Be*60,Ae=Pe*24,ms=Ae*7,gs=Ae*365.25;Nn.exports=function(r,e){e=e||{};var t=typeof r;if(t==="string"&&r.length>0)return ys(r);if(t==="number"&&isFinite(r))return e.long?bs(r):ws(r);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(r))};function ys(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*gs;case"weeks":case"week":case"w":return t*ms;case"days":case"day":case"d":return t*Ae;case"hours":case"hour":case"hrs":case"hr":case"h":return t*Pe;case"minutes":case"minute":case"mins":case"min":case"m":return t*Be;case"seconds":case"second":case"secs":case"sec":case"s":return t*Ne;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return t;default:return}}}}function ws(r){var e=Math.abs(r);return e>=Ae?Math.round(r/Ae)+"d":e>=Pe?Math.round(r/Pe)+"h":e>=Be?Math.round(r/Be)+"m":e>=Ne?Math.round(r/Ne)+"s":r+"ms"}function bs(r){var e=Math.abs(r);return e>=Ae?kt(r,e,Ae,"day"):e>=Pe?kt(r,e,Pe,"hour"):e>=Be?kt(r,e,Be,"minute"):e>=Ne?kt(r,e,Ne,"second"):r+" ms"}function kt(r,e,t,n){var o=e>=t*1.5;return Math.round(r/t)+" "+n+(o?"s":"")}});var Rn=he((au,Pn)=>{function xs(r){t.debug=t,t.default=t,t.coerce=f,t.disable=i,t.enable=o,t.enabled=s,t.humanize=Bn(),t.destroy=p,Object.keys(r).forEach(h=>{t[h]=r[h]}),t.names=[],t.skips=[],t.formatters={};function e(h){let l=0;for(let C=0;C<h.length;C++)l=(l<<5)-l+h.charCodeAt(C),l|=0;return t.colors[Math.abs(l)%t.colors.length]}t.selectColor=e;function t(h){let l,C=null,a,d;function m(...A){if(!m.enabled)return;let y=m,w=Number(new Date),x=w-(l||w);y.diff=x,y.prev=l,y.curr=w,l=w,A[0]=t.coerce(A[0]),typeof A[0]!="string"&&A.unshift("%O");let E=0;A[0]=A[0].replace(/%([a-zA-Z%])/g,(T,v)=>{if(T==="%%")return"%";E++;let L=t.formatters[v];if(typeof L=="function"){let J=A[E];T=L.call(y,J),A.splice(E,1),E--}return T}),t.formatArgs.call(y,A),(y.log||t.log).apply(y,A)}return m.namespace=h,m.useColors=t.useColors(),m.color=t.selectColor(h),m.extend=n,m.destroy=t.destroy,Object.defineProperty(m,"enabled",{enumerable:!0,configurable:!1,get:()=>C!==null?C:(a!==t.namespaces&&(a=t.namespaces,d=t.enabled(h)),d),set:A=>{C=A}}),typeof t.init=="function"&&t.init(m),m}function n(h,l){let C=t(this.namespace+(typeof l>"u"?":":l)+h);return C.log=this.log,C}function o(h){t.save(h),t.namespaces=h,t.names=[],t.skips=[];let l,C=(typeof h=="string"?h:"").split(/[\s,]+/),a=C.length;for(l=0;l<a;l++)C[l]&&(h=C[l].replace(/\*/g,".*?"),h[0]==="-"?t.skips.push(new RegExp("^"+h.slice(1)+"$")):t.names.push(new RegExp("^"+h+"$")))}function i(){let h=[...t.names.map(c),...t.skips.map(c).map(l=>"-"+l)].join(",");return t.enable(""),h}function s(h){if(h[h.length-1]==="*")return!0;let l,C;for(l=0,C=t.skips.length;l<C;l++)if(t.skips[l].test(h))return!1;for(l=0,C=t.names.length;l<C;l++)if(t.names[l].test(h))return!0;return!1}function c(h){return h.toString().substring(2,h.toString().length-2).replace(/\.\*\?$/,"*")}function f(h){return h instanceof Error?h.stack||h.message:h}function p(){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}Pn.exports=xs});var On=he((z,At)=>{z.formatArgs=vs;z.save=ks;z.load=As;z.useColors=Es;z.storage=Cs();z.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`."))}})();z.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 Es(){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 vs(r){if(r[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+r[0]+(this.useColors?"%c ":" ")+"+"+At.exports.humanize(this.diff),!this.useColors)return;let e="color: "+this.color;r.splice(1,0,e,"color: inherit");let t=0,n=0;r[0].replace(/%[a-zA-Z%]/g,o=>{o!=="%%"&&(t++,o==="%c"&&(n=t))}),r.splice(n,0,e)}z.log=console.debug||console.log||(()=>{});function ks(r){try{r?z.storage.setItem("debug",r):z.storage.removeItem("debug")}catch{}}function As(){let r;try{r=z.storage.getItem("debug")}catch{}return!r&&typeof process<"u"&&"env"in process&&(r=process.env.DEBUG),r}function Cs(){try{return localStorage}catch{}}At.exports=Rn()(z);var{formatters:_s}=At.exports;_s.j=function(r){try{return JSON.stringify(r)}catch(e){return"[UnexpectedJSONParseError]: "+e.message}}});var Wn=he((Eu,Cr)=>{"use strict";var Hs=Object.prototype.hasOwnProperty,M="~";function tt(){}Object.create&&(tt.prototype=Object.create(null),new tt().__proto__||(M=!1));function Ws(r,e,t){this.fn=r,this.context=e,this.once=t||!1}function Hn(r,e,t,n,o){if(typeof t!="function")throw new TypeError("The listener must be a function");var i=new Ws(t,n||r,o),s=M?M+e:e;return r._events[s]?r._events[s].fn?r._events[s]=[r._events[s],i]:r._events[s].push(i):(r._events[s]=i,r._eventsCount++),r}function Ct(r,e){--r._eventsCount===0?r._events=new tt:delete r._events[e]}function F(){this._events=new tt,this._eventsCount=0}F.prototype.eventNames=function(){var e=[],t,n;if(this._eventsCount===0)return e;for(n in t=this._events)Hs.call(t,n)&&e.push(M?n.slice(1):n);return Object.getOwnPropertySymbols?e.concat(Object.getOwnPropertySymbols(t)):e};F.prototype.listeners=function(e){var t=M?M+e:e,n=this._events[t];if(!n)return[];if(n.fn)return[n.fn];for(var o=0,i=n.length,s=new Array(i);o<i;o++)s[o]=n[o].fn;return s};F.prototype.listenerCount=function(e){var t=M?M+e:e,n=this._events[t];return n?n.fn?1:n.length:0};F.prototype.emit=function(e,t,n,o,i,s){var c=M?M+e:e;if(!this._events[c])return!1;var f=this._events[c],p=arguments.length,h,l;if(f.fn){switch(f.once&&this.removeListener(e,f.fn,void 0,!0),p){case 1:return f.fn.call(f.context),!0;case 2:return f.fn.call(f.context,t),!0;case 3:return f.fn.call(f.context,t,n),!0;case 4:return f.fn.call(f.context,t,n,o),!0;case 5:return f.fn.call(f.context,t,n,o,i),!0;case 6:return f.fn.call(f.context,t,n,o,i,s),!0}for(l=1,h=new Array(p-1);l<p;l++)h[l-1]=arguments[l];f.fn.apply(f.context,h)}else{var C=f.length,a;for(l=0;l<C;l++)switch(f[l].once&&this.removeListener(e,f[l].fn,void 0,!0),p){case 1:f[l].fn.call(f[l].context);break;case 2:f[l].fn.call(f[l].context,t);break;case 3:f[l].fn.call(f[l].context,t,n);break;case 4:f[l].fn.call(f[l].context,t,n,o);break;default:if(!h)for(a=1,h=new Array(p-1);a<p;a++)h[a-1]=arguments[a];f[l].fn.apply(f[l].context,h)}}return!0};F.prototype.on=function(e,t,n){return Hn(this,e,t,n,!1)};F.prototype.once=function(e,t,n){return Hn(this,e,t,n,!0)};F.prototype.removeListener=function(e,t,n,o){var i=M?M+e:e;if(!this._events[i])return this;if(!t)return Ct(this,i),this;var s=this._events[i];if(s.fn)s.fn===t&&(!o||s.once)&&(!n||s.context===n)&&Ct(this,i);else{for(var c=0,f=[],p=s.length;c<p;c++)(s[c].fn!==t||o&&!s[c].once||n&&s[c].context!==n)&&f.push(s[c]);f.length?this._events[i]=f.length===1?f[0]:f:Ct(this,i)}return this};F.prototype.removeAllListeners=function(e){var t;return e?(t=M?M+e:e,this._events[t]&&Ct(this,t)):(this._events=new tt,this._eventsCount=0),this};F.prototype.off=F.prototype.removeListener;F.prototype.addListener=F.prototype.on;F.prefixed=M;F.EventEmitter=F;typeof Cr<"u"&&(Cr.exports=F)});var po=he((Lf,ho)=>{ho.exports=function(r){if(!r)throw Error("hashlru must have a max value, of type number, greater than 0");var e=0,t=Object.create(null),n=Object.create(null);function o(i,s){t[i]=s,e++,e>=r&&(e=0,n=t,t=Object.create(null))}return{has:function(i){return t[i]!==void 0||n[i]!==void 0},remove:function(i){t[i]!==void 0&&(t[i]=void 0),n[i]!==void 0&&(n[i]=void 0)},get:function(i){var s=t[i];if(s!==void 0)return s;if((s=n[i])!==void 0)return o(i,s),s},set:function(i,s){t[i]!==void 0?t[i]=s:o(i,s)},clear:function(){t=Object.create(null),n=Object.create(null)}}}});var Ji=he((Od,Qi)=>{"use strict";function Ki(r,e){for(let t in e)Object.defineProperty(r,t,{value:e[t],enumerable:!0,configurable:!0});return r}function Pc(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 Ki(r,t)}catch{t.message=r.message,t.stack=r.stack;let o=function(){};return o.prototype=Object.create(Object.getPrototypeOf(r)),Ki(new o,t)}}Qi.exports=Pc});var ns=he((wt,fr)=>{(function(r,e){"use strict";var t={version:"3.0.0",x86:{},x64:{},inputValidation:!0};function n(a){if(!Array.isArray(a)&&!ArrayBuffer.isView(a))return!1;for(var d=0;d<a.length;d++)if(!Number.isInteger(a[d])||a[d]<0||a[d]>255)return!1;return!0}function o(a,d){return(a&65535)*d+(((a>>>16)*d&65535)<<16)}function i(a,d){return a<<d|a>>>32-d}function s(a){return a^=a>>>16,a=o(a,2246822507),a^=a>>>13,a=o(a,3266489909),a^=a>>>16,a}function c(a,d){a=[a[0]>>>16,a[0]&65535,a[1]>>>16,a[1]&65535],d=[d[0]>>>16,d[0]&65535,d[1]>>>16,d[1]&65535];var m=[0,0,0,0];return m[3]+=a[3]+d[3],m[2]+=m[3]>>>16,m[3]&=65535,m[2]+=a[2]+d[2],m[1]+=m[2]>>>16,m[2]&=65535,m[1]+=a[1]+d[1],m[0]+=m[1]>>>16,m[1]&=65535,m[0]+=a[0]+d[0],m[0]&=65535,[m[0]<<16|m[1],m[2]<<16|m[3]]}function f(a,d){a=[a[0]>>>16,a[0]&65535,a[1]>>>16,a[1]&65535],d=[d[0]>>>16,d[0]&65535,d[1]>>>16,d[1]&65535];var m=[0,0,0,0];return m[3]+=a[3]*d[3],m[2]+=m[3]>>>16,m[3]&=65535,m[2]+=a[2]*d[3],m[1]+=m[2]>>>16,m[2]&=65535,m[2]+=a[3]*d[2],m[1]+=m[2]>>>16,m[2]&=65535,m[1]+=a[1]*d[3],m[0]+=m[1]>>>16,m[1]&=65535,m[1]+=a[2]*d[2],m[0]+=m[1]>>>16,m[1]&=65535,m[1]+=a[3]*d[1],m[0]+=m[1]>>>16,m[1]&=65535,m[0]+=a[0]*d[3]+a[1]*d[2]+a[2]*d[1]+a[3]*d[0],m[0]&=65535,[m[0]<<16|m[1],m[2]<<16|m[3]]}function p(a,d){return d%=64,d===32?[a[1],a[0]]:d<32?[a[0]<<d|a[1]>>>32-d,a[1]<<d|a[0]>>>32-d]:(d-=32,[a[1]<<d|a[0]>>>32-d,a[0]<<d|a[1]>>>32-d])}function h(a,d){return d%=64,d===0?a:d<32?[a[0]<<d|a[1]>>>32-d,a[1]<<d]:[a[1]<<d-32,0]}function l(a,d){return[a[0]^d[0],a[1]^d[1]]}function C(a){return a=l(a,[0,a[0]>>>1]),a=f(a,[4283543511,3981806797]),a=l(a,[0,a[0]>>>1]),a=f(a,[3301882366,444984403]),a=l(a,[0,a[0]>>>1]),a}t.x86.hash32=function(a,d){if(t.inputValidation&&!n(a))return e;d=d||0;for(var m=a.length%4,A=a.length-m,y=d,w=0,x=3432918353,E=461845907,_=0;_<A;_=_+4)w=a[_]|a[_+1]<<8|a[_+2]<<16|a[_+3]<<24,w=o(w,x),w=i(w,15),w=o(w,E),y^=w,y=i(y,13),y=o(y,5)+3864292196;switch(w=0,m){case 3:w^=a[_+2]<<16;case 2:w^=a[_+1]<<8;case 1:w^=a[_],w=o(w,x),w=i(w,15),w=o(w,E),y^=w}return y^=a.length,y=s(y),y>>>0},t.x86.hash128=function(a,d){if(t.inputValidation&&!n(a))return e;d=d||0;for(var m=a.length%16,A=a.length-m,y=d,w=d,x=d,E=d,_=0,T=0,v=0,L=0,J=597399067,bt=2869860233,xt=951274213,Et=2716044179,S=0;S<A;S=S+16)_=a[S]|a[S+1]<<8|a[S+2]<<16|a[S+3]<<24,T=a[S+4]|a[S+5]<<8|a[S+6]<<16|a[S+7]<<24,v=a[S+8]|a[S+9]<<8|a[S+10]<<16|a[S+11]<<24,L=a[S+12]|a[S+13]<<8|a[S+14]<<16|a[S+15]<<24,_=o(_,J),_=i(_,15),_=o(_,bt),y^=_,y=i(y,19),y+=w,y=o(y,5)+1444728091,T=o(T,bt),T=i(T,16),T=o(T,xt),w^=T,w=i(w,17),w+=x,w=o(w,5)+197830471,v=o(v,xt),v=i(v,17),v=o(v,Et),x^=v,x=i(x,15),x+=E,x=o(x,5)+2530024501,L=o(L,Et),L=i(L,18),L=o(L,J),E^=L,E=i(E,13),E+=y,E=o(E,5)+850148119;switch(_=0,T=0,v=0,L=0,m){case 15:L^=a[S+14]<<16;case 14:L^=a[S+13]<<8;case 13:L^=a[S+12],L=o(L,Et),L=i(L,18),L=o(L,J),E^=L;case 12:v^=a[S+11]<<24;case 11:v^=a[S+10]<<16;case 10:v^=a[S+9]<<8;case 9:v^=a[S+8],v=o(v,xt),v=i(v,17),v=o(v,Et),x^=v;case 8:T^=a[S+7]<<24;case 7:T^=a[S+6]<<16;case 6:T^=a[S+5]<<8;case 5:T^=a[S+4],T=o(T,bt),T=i(T,16),T=o(T,xt),w^=T;case 4:_^=a[S+3]<<24;case 3:_^=a[S+2]<<16;case 2:_^=a[S+1]<<8;case 1:_^=a[S],_=o(_,J),_=i(_,15),_=o(_,bt),y^=_}return y^=a.length,w^=a.length,x^=a.length,E^=a.length,y+=w,y+=x,y+=E,w+=y,x+=y,E+=y,y=s(y),w=s(w),x=s(x),E=s(E),y+=w,y+=x,y+=E,w+=y,x+=y,E+=y,("00000000"+(y>>>0).toString(16)).slice(-8)+("00000000"+(w>>>0).toString(16)).slice(-8)+("00000000"+(x>>>0).toString(16)).slice(-8)+("00000000"+(E>>>0).toString(16)).slice(-8)},t.x64.hash128=function(a,d){if(t.inputValidation&&!n(a))return e;d=d||0;for(var m=a.length%16,A=a.length-m,y=[0,d],w=[0,d],x=[0,0],E=[0,0],_=[2277735313,289559509],T=[1291169091,658871167],v=0;v<A;v=v+16)x=[a[v+4]|a[v+5]<<8|a[v+6]<<16|a[v+7]<<24,a[v]|a[v+1]<<8|a[v+2]<<16|a[v+3]<<24],E=[a[v+12]|a[v+13]<<8|a[v+14]<<16|a[v+15]<<24,a[v+8]|a[v+9]<<8|a[v+10]<<16|a[v+11]<<24],x=f(x,_),x=p(x,31),x=f(x,T),y=l(y,x),y=p(y,27),y=c(y,w),y=c(f(y,[0,5]),[0,1390208809]),E=f(E,T),E=p(E,33),E=f(E,_),w=l(w,E),w=p(w,31),w=c(w,y),w=c(f(w,[0,5]),[0,944331445]);switch(x=[0,0],E=[0,0],m){case 15:E=l(E,h([0,a[v+14]],48));case 14:E=l(E,h([0,a[v+13]],40));case 13:E=l(E,h([0,a[v+12]],32));case 12:E=l(E,h([0,a[v+11]],24));case 11:E=l(E,h([0,a[v+10]],16));case 10:E=l(E,h([0,a[v+9]],8));case 9:E=l(E,[0,a[v+8]]),E=f(E,T),E=p(E,33),E=f(E,_),w=l(w,E);case 8:x=l(x,h([0,a[v+7]],56));case 7:x=l(x,h([0,a[v+6]],48));case 6:x=l(x,h([0,a[v+5]],40));case 5:x=l(x,h([0,a[v+4]],32));case 4:x=l(x,h([0,a[v+3]],24));case 3:x=l(x,h([0,a[v+2]],16));case 2:x=l(x,h([0,a[v+1]],8));case 1:x=l(x,[0,a[v]]),x=f(x,_),x=p(x,31),x=f(x,T),y=l(y,x)}return y=l(y,[0,a.length]),w=l(w,[0,a.length]),y=c(y,w),w=c(w,y),y=C(y),w=C(w),y=c(y,w),w=c(w,y),("00000000"+(y[0]>>>0).toString(16)).slice(-8)+("00000000"+(y[1]>>>0).toString(16)).slice(-8)+("00000000"+(w[0]>>>0).toString(16)).slice(-8)+("00000000"+(w[1]>>>0).toString(16)).slice(-8)},typeof wt<"u"?(typeof fr<"u"&&fr.exports&&(wt=fr.exports=t),wt.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)})(wt)});var is=he((Op,os)=>{os.exports=ns()});var Xc={};$(Xc,{AbstractSession:()=>dr,BloomFilter:()=>Ze,Helia:()=>In});var pr=Symbol.for("@libp2p/content-routing");var mr=Symbol.for("@libp2p/peer-routing");var de=class r extends Error{code;type;constructor(e="The operation was aborted"){super(e),this.name="AbortError",this.code=r.code,this.type=r.type}static code="ABORT_ERR";static type="aborted"},P=class extends Error{code;props;constructor(e,t,n){super(e),this.code=t,this.name=n?.name??"CodeError",this.props=n??{}}};var R=(r,...e)=>{try{[...e]}catch{}};var Ue=class extends EventTarget{#e=new Map;constructor(){super(),R(1/0,this)}listenerCount(e){let t=this.#e.get(e);return t==null?0:t.length}addEventListener(e,t,n){super.addEventListener(e,t,n);let o=this.#e.get(e);o==null&&(o=[],this.#e.set(e,o)),o.push({callback:t,once:(n!==!0&&n!==!1&&n?.once)??!1})}removeEventListener(e,t,n){super.removeEventListener(e.toString(),t??null,n);let o=this.#e.get(e);o!=null&&(o=o.filter(({callback:i})=>i!==t),this.#e.set(e,o))}dispatchEvent(e){let t=super.dispatchEvent(e),n=this.#e.get(e.type);return n==null||(n=n.filter(({once:o})=>!o),this.#e.set(e.type,n)),t}safeDispatchEvent(e,t={}){return this.dispatchEvent(new ps(e,t))}},gr=class extends Event{detail;constructor(e,t){super(e,t),this.detail=t?.detail}},ps=globalThis.CustomEvent??gr;function Un(r){return r!=null&&typeof r.start=="function"&&typeof r.stop=="function"}async function pe(...r){let e=[];for(let t of r)Un(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 me(...r){let e=[];for(let t of r)Un(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 V=et(On(),1);var Er={};$(Er,{base32:()=>ie,base32hex:()=>Ps,base32hexpad:()=>Os,base32hexpadupper:()=>Fs,base32hexupper:()=>Rs,base32pad:()=>Ns,base32padupper:()=>Bs,base32upper:()=>Us,base32z:()=>Ms});var cu=new Uint8Array(0);function Fn(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 oe(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 Mn(r){return new TextEncoder().encode(r)}function $n(r){return new TextDecoder().decode(r)}function Ts(r,e){if(r.length>=255)throw new TypeError("Alphabet too long");for(var t=new Uint8Array(256),n=0;n<t.length;n++)t[n]=255;for(var o=0;o<r.length;o++){var i=r.charAt(o),s=i.charCodeAt(0);if(t[s]!==255)throw new TypeError(i+" is ambiguous");t[s]=o}var c=r.length,f=r.charAt(0),p=Math.log(c)/Math.log(256),h=Math.log(256)/Math.log(c);function l(d){if(d instanceof Uint8Array||(ArrayBuffer.isView(d)?d=new Uint8Array(d.buffer,d.byteOffset,d.byteLength):Array.isArray(d)&&(d=Uint8Array.from(d))),!(d instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(d.length===0)return"";for(var m=0,A=0,y=0,w=d.length;y!==w&&d[y]===0;)y++,m++;for(var x=(w-y)*h+1>>>0,E=new Uint8Array(x);y!==w;){for(var _=d[y],T=0,v=x-1;(_!==0||T<A)&&v!==-1;v--,T++)_+=256*E[v]>>>0,E[v]=_%c>>>0,_=_/c>>>0;if(_!==0)throw new Error("Non-zero carry");A=T,y++}for(var L=x-A;L!==x&&E[L]===0;)L++;for(var J=f.repeat(m);L<x;++L)J+=r.charAt(E[L]);return J}function C(d){if(typeof d!="string")throw new TypeError("Expected String");if(d.length===0)return new Uint8Array;var m=0;if(d[m]!==" "){for(var A=0,y=0;d[m]===f;)A++,m++;for(var w=(d.length-m)*p+1>>>0,x=new Uint8Array(w);d[m];){var E=t[d.charCodeAt(m)];if(E===255)return;for(var _=0,T=w-1;(E!==0||_<y)&&T!==-1;T--,_++)E+=c*x[T]>>>0,x[T]=E%256>>>0,E=E/256>>>0;if(E!==0)throw new Error("Non-zero carry");y=_,m++}if(d[m]!==" "){for(var v=w-y;v!==w&&x[v]===0;)v++;for(var L=new Uint8Array(A+(w-v)),J=A;v!==w;)L[J++]=x[v++];return L}}}function a(d){var m=C(d);if(m)return m;throw new Error(`Non-${e} character`)}return{encode:l,decodeUnsafe:C,decode:a}}var Ss=Ts,Ls=Ss,Vn=Ls;var yr=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")}},wr=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 qn(this,e)}},br=class{decoders;constructor(e){this.decoders=e}or(e){return qn(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 qn(r,e){return new br({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}var xr=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,t,n,o){this.name=e,this.prefix=t,this.baseEncode=n,this.baseDecode=o,this.encoder=new yr(e,t,n),this.decoder=new wr(e,t,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function Re({name:r,prefix:e,encode:t,decode:n}){return new xr(r,e,t,n)}function ge({name:r,prefix:e,alphabet:t}){let{encode:n,decode:o}=Vn(t,r);return Re({prefix:e,name:r,encode:n,decode:i=>oe(o(i))})}function Is(r,e,t,n){let o={};for(let h=0;h<e.length;++h)o[e[h]]=h;let i=r.length;for(;r[i-1]==="=";)--i;let s=new Uint8Array(i*t/8|0),c=0,f=0,p=0;for(let h=0;h<i;++h){let l=o[r[h]];if(l===void 0)throw new SyntaxError(`Non-${n} character`);f=f<<t|l,c+=t,c>=8&&(c-=8,s[p++]=255&f>>c)}if(c>=t||255&f<<8-c)throw new SyntaxError("Unexpected end of data");return s}function Ds(r,e,t){let n=e[e.length-1]==="=",o=(1<<t)-1,i="",s=0,c=0;for(let f=0;f<r.length;++f)for(c=c<<8|r[f],s+=8;s>t;)s-=t,i+=e[o&c>>s];if(s!==0&&(i+=e[o&c<<t-s]),n)for(;i.length*t&7;)i+="=";return i}function U({name:r,prefix:e,bitsPerChar:t,alphabet:n}){return Re({prefix:e,name:r,encode(o){return Ds(o,n,t)},decode(o){return Is(o,n,t,r)}})}var ie=U({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Us=U({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Ns=U({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Bs=U({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Ps=U({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Rs=U({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Os=U({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Fs=U({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Ms=U({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var vr={};$(vr,{base58btc:()=>G,base58flickr:()=>$s});var G=ge({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),$s=ge({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var kr={};$(kr,{base64:()=>ye,base64pad:()=>zs,base64url:()=>Vs,base64urlpad:()=>qs});var ye=U({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),zs=U({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Vs=U({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),qs=U({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});V.default.formatters.b=r=>r==null?"undefined":G.baseEncode(r);V.default.formatters.t=r=>r==null?"undefined":ie.baseEncode(r);V.default.formatters.m=r=>r==null?"undefined":ye.baseEncode(r);V.default.formatters.p=r=>r==null?"undefined":r.toString();V.default.formatters.c=r=>r==null?"undefined":r.toString();V.default.formatters.k=r=>r==null?"undefined":r.toString();V.default.formatters.a=r=>r==null?"undefined":r.toString();function js(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 jn(){return{forComponent(r){return Ar(r)}}}function Ar(r){let e=js(`${r}:trace`);return V.default.enabled(`${r}:trace`)&&V.default.names.map(t=>t.toString()).find(t=>t.includes(":trace"))!=null&&(e=(0,V.default)(`${r}:trace`)),Object.assign((0,V.default)(r),{error:(0,V.default)(`${r}:error`),trace:e})}var D=class extends Event{constructor(e,t){super(e),this.detail=t}};var _r=et(Wn(),1);var rt=class extends Error{constructor(e){super(e),this.name="TimeoutError"}},Tr=class extends Error{constructor(e){super(),this.name="AbortError",this.message=e}},Gn=r=>globalThis.DOMException===void 0?new Tr(r):new DOMException(r),Kn=r=>{let e=r.reason===void 0?Gn("This operation was aborted."):r.reason;return e instanceof Error?e:Gn(e)};function nt(r,e){let{milliseconds:t,fallback:n,message:o,customTimers:i={setTimeout,clearTimeout}}=e,s,f=new Promise((p,h)=>{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:C}=e;C.aborted&&h(Kn(C)),C.addEventListener("abort",()=>{h(Kn(C))})}if(t===Number.POSITIVE_INFINITY){r.then(p,h);return}let l=new rt;s=i.setTimeout.call(void 0,()=>{if(n){try{p(n())}catch(C){h(C)}return}typeof r.cancel=="function"&&r.cancel(),o===!1?p():o instanceof Error?h(o):(l.message=o??`Promise timed out after ${t} milliseconds`,h(l))},t),(async()=>{try{p(await r)}catch(C){h(C)}})()}).finally(()=>{f.clear()});return f.clear=()=>{i.clearTimeout.call(void 0,s),s=void 0},f}function Sr(r,e,t){let n=0,o=r.length;for(;o>0;){let i=Math.trunc(o/2),s=n+i;t(r[s],e)<=0?(n=++s,o-=i+1):o=i}return n}var ot=class{#e=[];enqueue(e,t){t={priority:0,...t};let n={priority:t.priority,run:e};if(this.size&&this.#e[this.size-1].priority>=t.priority){this.#e.push(n);return}let o=Sr(this.#e,n,(i,s)=>s.priority-i.priority);this.#e.splice(o,0,n)}dequeue(){return this.#e.shift()?.run}filter(e){return this.#e.filter(t=>t.priority===e.priority).map(t=>t.run)}get size(){return this.#e.length}};var we=class extends _r.default{#e;#o;#s=0;#d;#a;#p=0;#r;#c;#t;#m;#n=0;#u;#i;#g;timeout;constructor(e){if(super(),e={carryoverConcurrencyCount:!1,intervalCap:Number.POSITIVE_INFINITY,interval:0,concurrency:Number.POSITIVE_INFINITY,autoStart:!0,queueClass:ot,...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.#o=e.intervalCap===Number.POSITIVE_INFINITY||e.interval===0,this.#d=e.intervalCap,this.#a=e.interval,this.#t=new e.queueClass,this.#m=e.queueClass,this.concurrency=e.concurrency,this.timeout=e.timeout,this.#g=e.throwOnTimeout===!0,this.#i=e.autoStart===!1}get#b(){return this.#o||this.#s<this.#d}get#x(){return this.#n<this.#u}#E(){this.#n--,this.#f(),this.emit("next")}#v(){this.#w(),this.#y(),this.#c=void 0}get#k(){let e=Date.now();if(this.#r===void 0){let t=this.#p-e;if(t<0)this.#s=this.#e?this.#n:0;else return this.#c===void 0&&(this.#c=setTimeout(()=>{this.#v()},t)),!0}return!1}#f(){if(this.#t.size===0)return this.#r&&clearInterval(this.#r),this.#r=void 0,this.emit("empty"),this.#n===0&&this.emit("idle"),!1;if(!this.#i){let e=!this.#k;if(this.#b&&this.#x){let t=this.#t.dequeue();return t?(this.emit("active"),t(),e&&this.#y(),!0):!1}}return!1}#y(){this.#o||this.#r!==void 0||(this.#r=setInterval(()=>{this.#w()},this.#a),this.#p=Date.now()+this.#a)}#w(){this.#s===0&&this.#n===0&&this.#r&&(clearInterval(this.#r),this.#r=void 0),this.#s=this.#e?this.#n:0,this.#l()}#l(){for(;this.#f(););}get concurrency(){return this.#u}set concurrency(e){if(!(typeof e=="number"&&e>=1))throw new TypeError(`Expected \`concurrency\` to be a number from 1 and up, got \`${e}\` (${typeof e})`);this.#u=e,this.#l()}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.#g,...t},new Promise((n,o)=>{this.#t.enqueue(async()=>{this.#n++,this.#s++;try{t.signal?.throwIfAborted();let i=e({signal:t.signal});t.timeout&&(i=nt(Promise.resolve(i),{milliseconds:t.timeout})),t.signal&&(i=Promise.race([i,this.#A(t.signal)]));let s=await i;n(s),this.emit("completed",s)}catch(i){if(i instanceof rt&&!t.throwOnTimeout){n();return}o(i),this.emit("error",i)}finally{this.#E()}},t),this.emit("add"),this.#f()})}async addAll(e,t){return Promise.all(e.map(async n=>this.add(n,t)))}start(){return this.#i?(this.#i=!1,this.#l(),this):this}pause(){this.#i=!0}clear(){this.#t=new this.#m}async onEmpty(){this.#t.size!==0&&await this.#h("empty")}async onSizeLessThan(e){this.#t.size<e||await this.#h("next",()=>this.#t.size<e)}async onIdle(){this.#n===0&&this.#t.size===0||await this.#h("idle")}async#h(e,t){return new Promise(n=>{let o=()=>{t&&!t()||(this.off(e,o),n())};this.on(e,o)})}get size(){return this.#t.size}sizeBy(e){return this.#t.filter(e).length}get pending(){return this.#n}get isPaused(){return this.#i}};function _t(r){let e=[X.A];return r==null?e:Array.isArray(r)?r.length===0?e:r:[r]}var Lr={};$(Lr,{base10:()=>Gs});var Gs=ge({prefix:"9",name:"base10",alphabet:"0123456789"});var Ir={};$(Ir,{base16:()=>Ks,base16upper:()=>Qs});var Ks=U({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Qs=U({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Dr={};$(Dr,{base2:()=>Js});var Js=U({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Ur={};$(Ur,{base256emoji:()=>ta});var Qn=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}"),Xs=Qn.reduce((r,e,t)=>(r[t]=e,r),[]),Ys=Qn.reduce((r,e,t)=>(r[e.codePointAt(0)]=t,r),[]);function Zs(r){return r.reduce((e,t)=>(e+=Xs[t],e),"")}function ea(r){let e=[];for(let t of r){let n=Ys[t.codePointAt(0)];if(n===void 0)throw new Error(`Non-base256emoji character: ${t}`);e.push(n)}return new Uint8Array(e)}var ta=Re({prefix:"\u{1F680}",name:"base256emoji",encode:Zs,decode:ea});var Nr={};$(Nr,{base36:()=>it,base36upper:()=>ra});var it=ge({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),ra=ge({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Br={};$(Br,{base8:()=>na});var na=U({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Pr={};$(Pr,{identity:()=>oa});var oa=Re({prefix:"\0",name:"identity",encode:r=>$n(r),decode:r=>Mn(r)});var zu=new TextEncoder,Vu=new TextDecoder;var Jn=512;var Rr=85;var zr={};$(zr,{identity:()=>$r});var ia=eo,Yn=128,sa=127,aa=~sa,ca=Math.pow(2,31);function eo(r,e,t){e=e||[],t=t||0;for(var n=t;r>=ca;)e[t++]=r&255|Yn,r/=128;for(;r&aa;)e[t++]=r&255|Yn,r>>>=7;return e[t]=r|0,eo.bytes=t-n+1,e}var ua=Fr,fa=128,Zn=127;function Fr(r,n){var t=0,n=n||0,o=0,i=n,s,c=r.length;do{if(i>=c)throw Fr.bytes=0,new RangeError("Could not decode varint");s=r[i++],t+=o<28?(s&Zn)<<o:(s&Zn)*Math.pow(2,o),o+=7}while(s>=fa);return Fr.bytes=i-n,t}var la=Math.pow(2,7),ha=Math.pow(2,14),da=Math.pow(2,21),pa=Math.pow(2,28),ma=Math.pow(2,35),ga=Math.pow(2,42),ya=Math.pow(2,49),wa=Math.pow(2,56),ba=Math.pow(2,63),xa=function(r){return r<la?1:r<ha?2:r<da?3:r<pa?4:r<ma?5:r<ga?6:r<ya?7:r<wa?8:r<ba?9:10},Ea={encode:ia,decode:ua,encodingLength:xa},va=Ea,st=va;function at(r,e=0){return[st.decode(r,e),st.decode.bytes]}function Oe(r,e,t=0){return st.encode(r,e,t),e}function Fe(r){return st.encodingLength(r)}function Ce(r,e){let t=e.byteLength,n=Fe(r),o=n+Fe(t),i=new Uint8Array(o+t);return Oe(r,i,0),Oe(t,i,n),i.set(e,o),new Me(r,t,e,i)}function Mr(r){let e=oe(r),[t,n]=at(e),[o,i]=at(e.subarray(n)),s=e.subarray(n+i);if(s.byteLength!==o)throw new Error("Incorrect length");return new Me(t,o,s,e)}function to(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&Fn(r.bytes,t.bytes)}}var Me=class{code;size;digest;bytes;constructor(e,t,n,o){this.code=e,this.size=t,this.digest=n,this.bytes=o}};var ro=0,ka="identity",no=oe;function Aa(r){return Ce(ro,no(r))}var $r={code:ro,name:ka,encode:no,digest:Aa};var Wr={};$(Wr,{sha256:()=>jr,sha512:()=>Hr});function qr({name:r,code:e,encode:t}){return new Vr(r,e,t)}var Vr=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?Ce(this.code,t):t.then(n=>Ce(this.code,n))}else throw Error("Unknown type, must be binary type")}};function io(r){return async e=>new Uint8Array(await crypto.subtle.digest(r,e))}var jr=qr({name:"sha2-256",code:18,encode:io("SHA-256")}),Hr=qr({name:"sha2-512",code:19,encode:io("SHA-512")});function so(r,e){let{bytes:t,version:n}=r;switch(n){case 0:return _a(t,Gr(r),e??G.encoder);default:return Ta(t,Gr(r),e??ie.encoder)}}var ao=new WeakMap;function Gr(r){let e=ao.get(r);if(e==null){let t=new Map;return ao.set(r,t),t}return e}var N=class r{code;version;multihash;bytes;"/";constructor(e,t,n,o){this.code=t,this.version=e,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:e,multihash:t}=this;if(e!==ct)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==Sa)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=Ce(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&&to(e.multihash,n.multihash)}toString(e){return so(this,e)}toJSON(){return{"/":so(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(e){if(e==null)return null;let t=e;if(t instanceof r)return t;if(t["/"]!=null&&t["/"]===t.bytes||t.asCID===t){let{version:n,code:o,multihash:i,bytes:s}=t;return new r(n,o,i,s??co(n,o,i.bytes))}else if(t[La]===!0){let{version:n,multihash:o,code:i}=t,s=Mr(o);return r.create(n,i,s)}else return null}static create(e,t,n){if(typeof t!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(e){case 0:{if(t!==ct)throw new Error(`Version 0 CID must use dag-pb (code: ${ct}) block encoding`);return new r(e,t,n,n.bytes)}case 1:{let o=co(e,t,n.bytes);return new r(e,t,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return r.create(0,ct,e)}static createV1(e,t){return r.create(1,e,t)}static decode(e){let[t,n]=r.decodeFirst(e);if(n.length!==0)throw new Error("Incorrect length");return t}static decodeFirst(e){let t=r.inspectBytes(e),n=t.size-t.multihashSize,o=oe(e.subarray(n,n+t.multihashSize));if(o.byteLength!==t.multihashSize)throw new Error("Incorrect length");let i=o.subarray(t.multihashSize-t.digestSize),s=new Me(t.multihashCode,t.digestSize,i,o);return[t.version===0?r.createV0(s):r.createV1(t.codec,s),e.subarray(t.size)]}static inspectBytes(e){let t=0,n=()=>{let[l,C]=at(e.subarray(t));return t+=C,l},o=n(),i=ct;if(o===18?(o=0,t=0):i=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let s=t,c=n(),f=n(),p=t+f,h=p-s;return{version:o,codec:i,multihashCode:c,digestSize:f,multihashSize:h,size:p}}static parse(e,t){let[n,o]=Ca(e,t),i=r.decode(o);if(i.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Gr(i).set(n,e),i}};function Ca(r,e){switch(r[0]){case"Q":{let t=e??G;return[G.prefix,t.decode(`${G.prefix}${r}`)]}case G.prefix:{let t=e??G;return[G.prefix,t.decode(r)]}case ie.prefix:{let t=e??ie;return[ie.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 _a(r,e,t){let{prefix:n}=t;if(n!==G.prefix)throw Error(`Cannot string encode V0 in ${t.name} encoding`);let o=e.get(n);if(o==null){let i=t.encode(r).slice(1);return e.set(n,i),i}else return o}function Ta(r,e,t){let{prefix:n}=t,o=e.get(n);if(o==null){let i=t.encode(r);return e.set(n,i),i}else return o}var ct=112,Sa=18;function co(r,e,t){let n=Fe(r),o=n+Fe(e),i=new Uint8Array(o+t.byteLength);return Oe(r,i,0),Oe(e,i,n),i.set(t,o),i}var La=Symbol.for("@ipld/js-cid/CID");var Kr={...Pr,...Dr,...Br,...Lr,...Ir,...Er,...Nr,...vr,...kr,...Ur},ff={...Wr,...zr};function Y(r=0){return new Uint8Array(r)}function _e(r=0){return new Uint8Array(r)}function fo(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}var uo=fo("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Qr=fo("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=_e(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),Ia={utf8:uo,"utf-8":uo,hex:Kr.base16,latin1:Qr,ascii:Qr,binary:Qr,...Kr},St=Ia;function ze(r,e="utf8"){let t=St[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.encoder.encode(r).substring(1)}var Jr=60;function Lt(r){return{Status:r.Status??0,TC:r.TC??r.flag_tc??!1,RD:r.RD??r.flag_rd??!1,RA:r.RA??r.flag_ra??!1,AD:r.AD??r.flag_ad??!1,CD:r.CD??r.flag_cd??!1,Question:(r.Question??r.questions??[]).map(e=>({name:e.name,type:X[e.type]})),Answer:(r.Answer??r.answers??[]).map(e=>({name:e.name,type:X[e.type],TTL:e.TTL??e.ttl??Jr,data:e.data instanceof Uint8Array?ze(e.data):e.data}))}}var Da=4;function Xr(r,e={}){let t=new we({concurrency:e.queryConcurrency??Da});return async(n,o={})=>{let i=new URLSearchParams;i.set("name",n),_t(o.types).forEach(c=>{i.append("type",X[c])}),o.onProgress?.(new D("dns:query",{detail:n}));let s=await t.add(async()=>{let c=await fetch(`${r}?${i}`,{headers:{accept:"application/dns-json"},signal:o?.signal});if(c.status!==200)throw new Error(`Unexpected HTTP status: ${c.status} - ${c.statusText}`);let f=Lt(await c.json());return o.onProgress?.(new D("dns:response",{detail:f})),f},{signal:o.signal});if(s==null)throw new Error("No DNS response received");return s}}function lo(){return[Xr("https://cloudflare-dns.com/dns-query"),Xr("https://dns.google/resolve")]}var mo=et(po(),1);var Yr=class{lru;constructor(e){this.lru=(0,mo.default)(e)}get(e,t){let n=!0,o=[];for(let i of t){let s=this.getAnswers(e,i);if(s.length===0){n=!1;break}o.push(...s)}if(n)return Lt({answers:o})}getAnswers(e,t){let n=`${e.toLowerCase()}-${t}`,o=this.lru.get(n);if(o!=null){let i=o.filter(s=>s.expires>Date.now()).map(({expires:s,value:c})=>({...c,TTL:Math.round((s-Date.now())/1e3),type:X[c.type]}));return i.length===0&&this.lru.remove(n),i}return[]}add(e,t){let n=`${e.toLowerCase()}-${t.type}`,o=this.lru.get(n)??[];o.push({expires:Date.now()+(t.TTL??Jr)*1e3,value:t}),this.lru.set(n,o)}remove(e,t){let n=`${e.toLowerCase()}-${t}`;this.lru.remove(n)}clear(){this.lru.clear()}};function go(r){return new Yr(r)}var Ua=1e3,It=class{resolvers;cache;constructor(e){this.resolvers={},this.cache=go(e.cacheSize??Ua),Object.entries(e.resolvers??{}).forEach(([t,n])=>{Array.isArray(n)||(n=[n]),t.endsWith(".")||(t=`${t}.`),this.resolvers[t]=n}),this.resolvers["."]==null&&(this.resolvers["."]=lo())}async query(e,t={}){let n=_t(t.types),o=t.cached!==!1?this.cache.get(e,n):void 0;if(o!=null)return t.onProgress?.(new D("dns:cache",{detail:o})),o;let i=`${e.split(".").pop()}.`,s=(this.resolvers[i]??this.resolvers["."]).sort(()=>Math.random()>.5?-1:1),c=[];for(let f of s){if(t.signal?.aborted===!0)break;try{let p=await f(e,{...t,types:n});for(let h of p.Answer)this.cache.add(e,h);return p}catch(p){c.push(p),t.onProgress?.(new D("dns:error",{detail:p}))}}throw c.length===1?c[0]:new AggregateError(c,`DNS lookup of ${e} ${n} failed`)}};var X;(function(r){r[r.A=1]="A",r[r.CNAME=5]="CNAME",r[r.TXT=16]="TXT",r[r.AAAA=28]="AAAA"})(X||(X={}));function yo(r={}){return new It(r)}function Na(r){return r[Symbol.asyncIterator]!=null}function Ba(r){if(Na(r))return(async()=>{for await(let e of r);})();for(let e of r);}var Zr=Ba;function se(){let r={};return r.promise=new Promise((e,t)=>{r.resolve=e,r.reject=t}),r}var Dt=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}},Ve=class{size;hwm;head;tail;constructor(e={}){this.hwm=e.splitLimit??16,this.head=new Dt(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 Dt(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 en=class extends Error{type;code;constructor(e,t){super(e??"The operation was aborted"),this.type="aborted",this.code=t??"ABORT_ERR"}};function ut(r={}){return Pa(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 Pa(r,e){e=e??{};let t=e.onEnd,n=new Ve,o,i,s,c=se(),f=async()=>{try{return n.isEmpty()?s?{done:!0}:await new Promise((A,y)=>{i=w=>{i=null,n.push(w);try{A(r(n))}catch(x){y(x)}return o}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{c.resolve(),c=se()})}},p=A=>i!=null?i(A):(n.push(A),o),h=A=>(n=new Ve,i!=null?i({error:A}):(n.push({error:A}),o)),l=A=>{if(s)return o;if(e?.objectMode!==!0&&A?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return p({done:!1,value:A})},C=A=>s?o:(s=!0,A!=null?h(A):p({done:!0})),a=()=>(n=new Ve,C(),{done:!0}),d=A=>(C(A),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:f,return:a,throw:d,push:l,end:C,get readableLength(){return n.size},onEmpty:async A=>{let y=A?.signal;if(y?.throwIfAborted(),n.isEmpty())return;let w,x;y!=null&&(w=new Promise((E,_)=>{x=()=>{_(new en)},y.addEventListener("abort",x)}));try{await Promise.race([c.promise,w])}finally{x!=null&&y!=null&&y?.removeEventListener("abort",x)}}},t==null)return o;let m=o;return o={[Symbol.asyncIterator](){return this},next(){return m.next()},throw(A){return m.throw(A),t!=null&&(t(A),t=void 0),{done:!0}},return(){return m.return(),t!=null&&(t(),t=void 0),{done:!0}},push:l,end(A){return m.end(A),t!=null&&(t(A),t=void 0),o},get readableLength(){return m.readableLength},onEmpty:A=>m.onEmpty(A)},o}var tn=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 Ut(r,e,t,n){let o=new tn(n?.errorMessage,n?.errorCode);return t?.aborted===!0?Promise.reject(o):new Promise((i,s)=>{function c(){t?.removeEventListener("abort",h),r.removeEventListener(e,f),n?.errorEvent!=null&&r.removeEventListener(n.errorEvent,p)}let f=l=>{try{if(n?.filter?.(l)===!1)return}catch(C){c(),s(C);return}c(),i(l)},p=l=>{c(),s(l.detail)},h=()=>{c(),s(o)};t?.addEventListener("abort",h),r.addEventListener(e,f),n?.errorEvent!=null&&r.addEventListener(n.errorEvent,p)})}var Nt=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 wo(r,e,t){if(e==null)return r;if(e.aborted)return Promise.reject(new Nt(t?.errorMessage,t?.errorCode));let n,o=new Nt(t?.errorMessage,t?.errorCode);try{return await Promise.race([r,new Promise((i,s)=>{n=()=>{s(o)},e.addEventListener("abort",n)})])}finally{n!=null&&e.removeEventListener("abort",n)}}var Bt=class{deferred;signal;where;constructor(e,t){this.signal=t,this.deferred=se(),this.where=e,this.onAbort=this.onAbort.bind(this),this.signal?.addEventListener("abort",this.onAbort)}onAbort(){this.deferred.reject(this.signal?.reason??new de)}cleanup(){this.signal?.removeEventListener("abort",this.onAbort)}};function Ra(){return`${parseInt(String(Math.random()*1e9),10).toString()}${Date.now()}`}var Pt=class{id;fn;options;recipients;status;timeline;controller;constructor(e,t){this.id=Ra(),this.status="queued",this.fn=e,this.options=t,this.recipients=[],this.timeline={created:Date.now()},this.controller=new AbortController,R(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 de),this.cleanup())}async join(e={}){let t=new Bt(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 wo(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.cleanup(),e.signal?.removeEventListener("abort",this.onAbort)})}};var ae=class extends Ue{concurrency;queue;pending;sort;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.sort=e.sort,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){this.queue.push(e),this.sort!=null&&this.queue.sort(this.sort)}async add(e,t){t?.signal?.throwIfAborted();let n=new Pt(e,t),o=n.join(t).then(i=>(this.safeDispatchEvent("completed",{detail:i}),this.safeDispatchEvent("success",{detail:{job:n,result:i}}),i)).catch(i=>{if(n.status==="queued"){for(let s=0;s<this.queue.length;s++)if(this.queue[s]===n){this.queue.splice(s,1);break}}throw this.safeDispatchEvent("error",{detail:i}),this.safeDispatchEvent("failure",{detail:{job:n,error:i}}),i});return this.enqueue(n),this.safeDispatchEvent("add"),this.tryToStartAnother(),o}clear(){this.queue.splice(0,this.queue.length)}abort(){this.queue.forEach(e=>{e.abort(new de)}),this.clear()}async onEmpty(e){this.size!==0&&await Ut(this,"empty",e?.signal)}async onSizeLessThan(e,t){this.size<e||await Ut(this,"next",t?.signal,{filter:()=>this.size<e})}async onIdle(e){this.pending===0&&this.size===0||await Ut(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=ut({objectMode:!0}),n=f=>{f!=null?this.abort():this.clear(),t.end(f)},o=f=>{f.detail!=null&&t.push(f.detail)},i=f=>{n(f.detail)},s=()=>{n()},c=()=>{n(new P("Queue aborted","ERR_QUEUE_ABORTED"))};this.addEventListener("completed",o),this.addEventListener("error",i),this.addEventListener("idle",s),e?.signal?.addEventListener("abort",c);try{yield*t}finally{this.removeEventListener("completed",o),this.removeEventListener("error",i),this.removeEventListener("idle",s),e?.signal?.removeEventListener("abort",c),n()}}};var Oa=["string","number","bigint","symbol"],Fa=["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 bo(r){if(r===null)return"null";if(r===void 0)return"undefined";if(r===!0||r===!1)return"boolean";let e=typeof r;if(Oa.includes(e))return e;if(e==="function")return"Function";if(Array.isArray(r))return"Array";if(Ma(r))return"Buffer";let t=$a(r);return t||"Object"}function Ma(r){return r&&r.constructor&&r.constructor.isBuffer&&r.constructor.isBuffer.call(null,r)}function $a(r){let e=Object.prototype.toString.call(r).slice(8,-1);if(Fa.includes(e))return e}var u=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}};u.uint=new u(0,"uint",!0);u.negint=new u(1,"negint",!0);u.bytes=new u(2,"bytes",!0);u.string=new u(3,"string",!0);u.array=new u(4,"array",!1);u.map=new u(5,"map",!1);u.tag=new u(6,"tag",!1);u.float=new u(7,"float",!0);u.false=new u(7,"false",!0);u.true=new u(7,"true",!0);u.null=new u(7,"null",!0);u.undefined=new u(7,"undefined",!0);u.break=new u(7,"break",!0);var g=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 qe=globalThis.process&&!globalThis.process.browser&&globalThis.Buffer&&typeof globalThis.Buffer.isBuffer=="function",za=new TextDecoder,Va=new TextEncoder;function Rt(r){return qe&&globalThis.Buffer.isBuffer(r)}function ft(r){return r instanceof Uint8Array?Rt(r)?new Uint8Array(r.buffer,r.byteOffset,r.byteLength):r:Uint8Array.from(r)}var ko=qe?(r,e,t)=>t-e>64?globalThis.Buffer.from(r.subarray(e,t)).toString("utf8"):Eo(r,e,t):(r,e,t)=>t-e>64?za.decode(r.subarray(e,t)):Eo(r,e,t),Ot=qe?r=>r.length>64?globalThis.Buffer.from(r):xo(r):r=>r.length>64?Va.encode(r):xo(r),te=r=>Uint8Array.from(r),je=qe?(r,e,t)=>Rt(r)?new Uint8Array(r.subarray(e,t)):r.slice(e,t):(r,e,t)=>r.slice(e,t),Ao=qe?(r,e)=>(r=r.map(t=>t instanceof Uint8Array?t:globalThis.Buffer.from(t)),ft(globalThis.Buffer.concat(r,e))):(r,e)=>{let t=new Uint8Array(e),n=0;for(let o of r)n+o.length>t.length&&(o=o.subarray(0,t.length-n)),t.set(o,n),n+=o.length;return t},Co=qe?r=>globalThis.Buffer.allocUnsafe(r):r=>new Uint8Array(r);function _o(r,e){if(Rt(r)&&Rt(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 xo(r){let e=[],t=0;for(let n=0;n<r.length;n++){let o=r.charCodeAt(n);o<128?e[t++]=o:o<2048?(e[t++]=o>>6|192,e[t++]=o&63|128):(o&64512)===55296&&n+1<r.length&&(r.charCodeAt(n+1)&64512)===56320?(o=65536+((o&1023)<<10)+(r.charCodeAt(++n)&1023),e[t++]=o>>18|240,e[t++]=o>>12&63|128,e[t++]=o>>6&63|128,e[t++]=o&63|128):(e[t++]=o>>12|224,e[t++]=o>>6&63|128,e[t++]=o&63|128)}return e}function Eo(r,e,t){let n=[];for(;e<t;){let o=r[e],i=null,s=o>239?4:o>223?3:o>191?2:1;if(e+s<=t){let c,f,p,h;switch(s){case 1:o<128&&(i=o);break;case 2:c=r[e+1],(c&192)===128&&(h=(o&31)<<6|c&63,h>127&&(i=h));break;case 3:c=r[e+1],f=r[e+2],(c&192)===128&&(f&192)===128&&(h=(o&15)<<12|(c&63)<<6|f&63,h>2047&&(h<55296||h>57343)&&(i=h));break;case 4:c=r[e+1],f=r[e+2],p=r[e+3],(c&192)===128&&(f&192)===128&&(p&192)===128&&(h=(o&15)<<18|(c&63)<<12|(f&63)<<6|p&63,h>65535&&h<1114112&&(i=h))}}i===null?(i=65533,s=1):i>65535&&(i-=65536,n.push(i>>>10&1023|55296),i=56320|i&1023),n.push(i),e+=s}return rn(n)}var vo=4096;function rn(r){let e=r.length;if(e<=vo)return String.fromCharCode.apply(String,r);let t="",n=0;for(;n<e;)t+=String.fromCharCode.apply(String,r.slice(n,n+=vo));return t}var qa=256,lt=class{constructor(e=qa){this.chunkSize=e,this.cursor=0,this.maxCursor=-1,this.chunks=[],this._initReuseChunk=null}reset(){this.cursor=0,this.maxCursor=-1,this.chunks.length&&(this.chunks=[]),this._initReuseChunk!==null&&(this.chunks.push(this._initReuseChunk),this.maxCursor=this._initReuseChunk.length-1)}push(e){let t=this.chunks[this.chunks.length-1];if(this.cursor+e.length<=this.maxCursor+1){let o=t.length-(this.maxCursor-this.cursor)-1;t.set(e,o)}else{if(t){let o=t.length-(this.maxCursor-this.cursor)-1;o<t.length&&(this.chunks[this.chunks.length-1]=t.subarray(0,o),this.maxCursor=this.cursor-1)}e.length<64&&e.length<this.chunkSize?(t=Co(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=je(n,0,this.cursor)}else t=Ao(this.chunks,this.cursor);return e&&this.reset(),t}};var k="CBOR decode error:",He="CBOR encode error:",ht=[];ht[23]=1;ht[24]=2;ht[25]=3;ht[26]=5;ht[27]=9;function ce(r,e,t){if(r.length-e<t)throw new Error(`${k} not enough data for type`)}var B=[24,256,65536,4294967296,BigInt("18446744073709551616")];function q(r,e,t){ce(r,e,1);let n=r[e];if(t.strict===!0&&n<B[0])throw new Error(`${k} integer encoded in more bytes than necessary (strict decode)`);return n}function j(r,e,t){ce(r,e,2);let n=r[e]<<8|r[e+1];if(t.strict===!0&&n<B[1])throw new Error(`${k} integer encoded in more bytes than necessary (strict decode)`);return n}function H(r,e,t){ce(r,e,4);let n=r[e]*16777216+(r[e+1]<<16)+(r[e+2]<<8)+r[e+3];if(t.strict===!0&&n<B[2])throw new Error(`${k} integer encoded in more bytes than necessary (strict decode)`);return n}function W(r,e,t){ce(r,e,8);let n=r[e]*16777216+(r[e+1]<<16)+(r[e+2]<<8)+r[e+3],o=r[e+4]*16777216+(r[e+5]<<16)+(r[e+6]<<8)+r[e+7],i=(BigInt(n)<<BigInt(32))+BigInt(o);if(t.strict===!0&&i<B[3])throw new Error(`${k} integer encoded in more bytes than necessary (strict decode)`);if(i<=Number.MAX_SAFE_INTEGER)return Number(i);if(t.allowBigInt===!0)return i;throw new Error(`${k} integers outside of the safe integer range are not supported`)}function To(r,e,t,n){return new g(u.uint,q(r,e+1,n),2)}function So(r,e,t,n){return new g(u.uint,j(r,e+1,n),3)}function Lo(r,e,t,n){return new g(u.uint,H(r,e+1,n),5)}function Io(r,e,t,n){return new g(u.uint,W(r,e+1,n),9)}function K(r,e){return O(r,0,e.value)}function O(r,e,t){if(t<B[0]){let n=Number(t);r.push([e|n])}else if(t<B[1]){let n=Number(t);r.push([e|24,n])}else if(t<B[2]){let n=Number(t);r.push([e|25,n>>>8,n&255])}else if(t<B[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<B[4]){let o=[e|27,0,0,0,0,0,0,0],i=Number(n&BigInt(4294967295)),s=Number(n>>BigInt(32)&BigInt(4294967295));o[8]=i&255,i=i>>8,o[7]=i&255,i=i>>8,o[6]=i&255,i=i>>8,o[5]=i&255,o[4]=s&255,s=s>>8,o[3]=s&255,s=s>>8,o[2]=s&255,s=s>>8,o[1]=s&255,r.push(o)}else throw new Error(`${k} encountered BigInt larger than allowable range`)}}K.encodedSize=function(e){return O.encodedSize(e.value)};O.encodedSize=function(e){return e<B[0]?1:e<B[1]?2:e<B[2]?3:e<B[3]?5:9};K.compareTokens=function(e,t){return e.value<t.value?-1:e.value>t.value?1:0};function Do(r,e,t,n){return new g(u.negint,-1-q(r,e+1,n),2)}function Uo(r,e,t,n){return new g(u.negint,-1-j(r,e+1,n),3)}function No(r,e,t,n){return new g(u.negint,-1-H(r,e+1,n),5)}var nn=BigInt(-1),Bo=BigInt(1);function Po(r,e,t,n){let o=W(r,e+1,n);if(typeof o!="bigint"){let i=-1-o;if(i>=Number.MIN_SAFE_INTEGER)return new g(u.negint,i,9)}if(n.allowBigInt!==!0)throw new Error(`${k} integers outside of the safe integer range are not supported`);return new g(u.negint,nn-BigInt(o),9)}function Ft(r,e){let t=e.value,n=typeof t=="bigint"?t*nn-Bo:t*-1-1;O(r,e.type.majorEncoded,n)}Ft.encodedSize=function(e){let t=e.value,n=typeof t=="bigint"?t*nn-Bo:t*-1-1;return n<B[0]?1:n<B[1]?2:n<B[2]?3:n<B[3]?5:9};Ft.compareTokens=function(e,t){return e.value<t.value?1:e.value>t.value?-1:0};function dt(r,e,t,n){ce(r,e,t+n);let o=je(r,e+t,e+t+n);return new g(u.bytes,o,t+n)}function Ro(r,e,t,n){return dt(r,e,1,t)}function Oo(r,e,t,n){return dt(r,e,2,q(r,e+1,n))}function Fo(r,e,t,n){return dt(r,e,3,j(r,e+1,n))}function Mo(r,e,t,n){return dt(r,e,5,H(r,e+1,n))}function $o(r,e,t,n){let o=W(r,e+1,n);if(typeof o=="bigint")throw new Error(`${k} 64-bit integer bytes lengths not supported`);return dt(r,e,9,o)}function Mt(r){return r.encodedBytes===void 0&&(r.encodedBytes=r.type===u.string?Ot(r.value):r.value),r.encodedBytes}function We(r,e){let t=Mt(e);O(r,e.type.majorEncoded,t.length),r.push(t)}We.encodedSize=function(e){let t=Mt(e);return O.encodedSize(t.length)+t.length};We.compareTokens=function(e,t){return Ha(Mt(e),Mt(t))};function Ha(r,e){return r.length<e.length?-1:r.length>e.length?1:_o(r,e)}function pt(r,e,t,n,o){let i=t+n;ce(r,e,i);let s=new g(u.string,ko(r,e+t,e+i),i);return o.retainStringBytes===!0&&(s.byteValue=je(r,e+t,e+i)),s}function zo(r,e,t,n){return pt(r,e,1,t,n)}function Vo(r,e,t,n){return pt(r,e,2,q(r,e+1,n),n)}function qo(r,e,t,n){return pt(r,e,3,j(r,e+1,n),n)}function jo(r,e,t,n){return pt(r,e,5,H(r,e+1,n),n)}function Ho(r,e,t,n){let o=W(r,e+1,n);if(typeof o=="bigint")throw new Error(`${k} 64-bit integer string lengths not supported`);return pt(r,e,9,o,n)}var Wo=We;function Ge(r,e,t,n){return new g(u.array,n,t)}function Go(r,e,t,n){return Ge(r,e,1,t)}function Ko(r,e,t,n){return Ge(r,e,2,q(r,e+1,n))}function Qo(r,e,t,n){return Ge(r,e,3,j(r,e+1,n))}function Jo(r,e,t,n){return Ge(r,e,5,H(r,e+1,n))}function Xo(r,e,t,n){let o=W(r,e+1,n);if(typeof o=="bigint")throw new Error(`${k} 64-bit integer array lengths not supported`);return Ge(r,e,9,o)}function Yo(r,e,t,n){if(n.allowIndefinite===!1)throw new Error(`${k} indefinite length items not allowed`);return Ge(r,e,1,1/0)}function $t(r,e){O(r,u.array.majorEncoded,e.value)}$t.compareTokens=K.compareTokens;$t.encodedSize=function(e){return O.encodedSize(e.value)};function Ke(r,e,t,n){return new g(u.map,n,t)}function Zo(r,e,t,n){return Ke(r,e,1,t)}function ei(r,e,t,n){return Ke(r,e,2,q(r,e+1,n))}function ti(r,e,t,n){return Ke(r,e,3,j(r,e+1,n))}function ri(r,e,t,n){return Ke(r,e,5,H(r,e+1,n))}function ni(r,e,t,n){let o=W(r,e+1,n);if(typeof o=="bigint")throw new Error(`${k} 64-bit integer map lengths not supported`);return Ke(r,e,9,o)}function oi(r,e,t,n){if(n.allowIndefinite===!1)throw new Error(`${k} indefinite length items not allowed`);return Ke(r,e,1,1/0)}function zt(r,e){O(r,u.map.majorEncoded,e.value)}zt.compareTokens=K.compareTokens;zt.encodedSize=function(e){return O.encodedSize(e.value)};function ii(r,e,t,n){return new g(u.tag,t,1)}function si(r,e,t,n){return new g(u.tag,q(r,e+1,n),2)}function ai(r,e,t,n){return new g(u.tag,j(r,e+1,n),3)}function ci(r,e,t,n){return new g(u.tag,H(r,e+1,n),5)}function ui(r,e,t,n){return new g(u.tag,W(r,e+1,n),9)}function Vt(r,e){O(r,u.tag.majorEncoded,e.value)}Vt.compareTokens=K.compareTokens;Vt.encodedSize=function(e){return O.encodedSize(e.value)};var Xa=20,Ya=21,Za=22,ec=23;function fi(r,e,t,n){if(n.allowUndefined===!1)throw new Error(`${k} undefined values are not supported`);return n.coerceUndefinedToNull===!0?new g(u.null,null,1):new g(u.undefined,void 0,1)}function li(r,e,t,n){if(n.allowIndefinite===!1)throw new Error(`${k} indefinite length items not allowed`);return new g(u.break,void 0,1)}function on(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 g(u.float,r,e)}function hi(r,e,t,n){return on(sn(r,e+1),3,n)}function di(r,e,t,n){return on(an(r,e+1),5,n)}function pi(r,e,t,n){return on(wi(r,e+1),9,n)}function qt(r,e,t){let n=e.value;if(n===!1)r.push([u.float.majorEncoded|Xa]);else if(n===!0)r.push([u.float.majorEncoded|Ya]);else if(n===null)r.push([u.float.majorEncoded|Za]);else if(n===void 0)r.push([u.float.majorEncoded|ec]);else{let o,i=!1;(!t||t.float64!==!0)&&(gi(n),o=sn(Z,1),n===o||Number.isNaN(n)?(Z[0]=249,r.push(Z.slice(0,3)),i=!0):(yi(n),o=an(Z,1),n===o&&(Z[0]=250,r.push(Z.slice(0,5)),i=!0))),i||(tc(n),o=wi(Z,1),Z[0]=251,r.push(Z.slice(0,9)))}}qt.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){gi(n);let o=sn(Z,1);if(n===o||Number.isNaN(n))return 3;if(yi(n),o=an(Z,1),n===o)return 5}return 9};var mi=new ArrayBuffer(9),Q=new DataView(mi,1),Z=new Uint8Array(mi,0);function gi(r){if(r===1/0)Q.setUint16(0,31744,!1);else if(r===-1/0)Q.setUint16(0,64512,!1);else if(Number.isNaN(r))Q.setUint16(0,32256,!1);else{Q.setFloat32(0,r);let e=Q.getUint32(0),t=(e&2139095040)>>23,n=e&8388607;if(t===255)Q.setUint16(0,31744,!1);else if(t===0)Q.setUint16(0,(r&2147483648)>>16|n>>13,!1);else{let o=t-127;o<-24?Q.setUint16(0,0):o<-14?Q.setUint16(0,(e&2147483648)>>16|1<<24+o,!1):Q.setUint16(0,(e&2147483648)>>16|o+15<<10|n>>13,!1)}}}function sn(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,o=t&1023,i;return n===0?i=o*2**-24:n!==31?i=(o+1024)*2**(n-25):i=o===0?1/0:NaN,t&32768?-i:i}function yi(r){Q.setFloat32(0,r,!1)}function an(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 tc(r){Q.setFloat64(0,r,!1)}function wi(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)}qt.compareTokens=K.compareTokens;function I(r,e,t){throw new Error(`${k} encountered invalid minor (${t}) for major ${r[e]>>>5}`)}function jt(r){return()=>{throw new Error(`${k} ${r}`)}}var b=[];for(let r=0;r<=23;r++)b[r]=I;b[24]=To;b[25]=So;b[26]=Lo;b[27]=Io;b[28]=I;b[29]=I;b[30]=I;b[31]=I;for(let r=32;r<=55;r++)b[r]=I;b[56]=Do;b[57]=Uo;b[58]=No;b[59]=Po;b[60]=I;b[61]=I;b[62]=I;b[63]=I;for(let r=64;r<=87;r++)b[r]=Ro;b[88]=Oo;b[89]=Fo;b[90]=Mo;b[91]=$o;b[92]=I;b[93]=I;b[94]=I;b[95]=jt("indefinite length bytes/strings are not supported");for(let r=96;r<=119;r++)b[r]=zo;b[120]=Vo;b[121]=qo;b[122]=jo;b[123]=Ho;b[124]=I;b[125]=I;b[126]=I;b[127]=jt("indefinite length bytes/strings are not supported");for(let r=128;r<=151;r++)b[r]=Go;b[152]=Ko;b[153]=Qo;b[154]=Jo;b[155]=Xo;b[156]=I;b[157]=I;b[158]=I;b[159]=Yo;for(let r=160;r<=183;r++)b[r]=Zo;b[184]=ei;b[185]=ti;b[186]=ri;b[187]=ni;b[188]=I;b[189]=I;b[190]=I;b[191]=oi;for(let r=192;r<=215;r++)b[r]=ii;b[216]=si;b[217]=ai;b[218]=ci;b[219]=ui;b[220]=I;b[221]=I;b[222]=I;b[223]=I;for(let r=224;r<=243;r++)b[r]=jt("simple values are not supported");b[244]=I;b[245]=I;b[246]=I;b[247]=fi;b[248]=jt("simple values are not supported");b[249]=hi;b[250]=di;b[251]=pi;b[252]=I;b[253]=I;b[254]=I;b[255]=li;var ee=[];for(let r=0;r<24;r++)ee[r]=new g(u.uint,r,1);for(let r=-1;r>=-24;r--)ee[31-r]=new g(u.negint,r,1);ee[64]=new g(u.bytes,new Uint8Array(0),1);ee[96]=new g(u.string,"",1);ee[128]=new g(u.array,0,1);ee[160]=new g(u.map,0,1);ee[244]=new g(u.false,!1,1);ee[245]=new g(u.true,!0,1);ee[246]=new g(u.null,null,1);function bi(r){switch(r.type){case u.false:return te([244]);case u.true:return te([245]);case u.null:return te([246]);case u.bytes:return r.value.length?void 0:te([64]);case u.string:return r.value===""?te([96]):void 0;case u.array:return r.value===0?te([128]):void 0;case u.map:return r.value===0?te([160]):void 0;case u.uint:return r.value<24?te([Number(r.value)]):void 0;case u.negint:if(r.value>=-24)return te([31-Number(r.value)])}}var nc={float64:!1,mapSorter:sc,quickEncodeToken:bi};function oc(){let r=[];return r[u.uint.major]=K,r[u.negint.major]=Ft,r[u.bytes.major]=We,r[u.string.major]=Wo,r[u.array.major]=$t,r[u.map.major]=zt,r[u.tag.major]=Vt,r[u.float.major]=qt,r}var xi=oc(),cn=new lt,Wt=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(`${He} object contains circular references`);return new r(t,e)}},be={null:new g(u.null,null),undefined:new g(u.undefined,void 0),true:new g(u.true,!0),false:new g(u.false,!1),emptyArray:new g(u.array,0),emptyMap:new g(u.map,0)},xe={number(r,e,t,n){return!Number.isInteger(r)||!Number.isSafeInteger(r)?new g(u.float,r):r>=0?new g(u.uint,r):new g(u.negint,r)},bigint(r,e,t,n){return r>=BigInt(0)?new g(u.uint,r):new g(u.negint,r)},Uint8Array(r,e,t,n){return new g(u.bytes,r)},string(r,e,t,n){return new g(u.string,r)},boolean(r,e,t,n){return r?be.true:be.false},null(r,e,t,n){return be.null},undefined(r,e,t,n){return be.undefined},ArrayBuffer(r,e,t,n){return new g(u.bytes,new Uint8Array(r))},DataView(r,e,t,n){return new g(u.bytes,new Uint8Array(r.buffer,r.byteOffset,r.byteLength))},Array(r,e,t,n){if(!r.length)return t.addBreakTokens===!0?[be.emptyArray,new g(u.break)]:be.emptyArray;n=Wt.createCheck(n,r);let o=[],i=0;for(let s of r)o[i++]=Ht(s,t,n);return t.addBreakTokens?[new g(u.array,r.length),o,new g(u.break)]:[new g(u.array,r.length),o]},Object(r,e,t,n){let o=e!=="Object",i=o?r.keys():Object.keys(r),s=o?r.size:i.length;if(!s)return t.addBreakTokens===!0?[be.emptyMap,new g(u.break)]:be.emptyMap;n=Wt.createCheck(n,r);let c=[],f=0;for(let p of i)c[f++]=[Ht(p,t,n),Ht(o?r.get(p):r[p],t,n)];return ic(c,t),t.addBreakTokens?[new g(u.map,s),c,new g(u.break)]:[new g(u.map,s),c]}};xe.Map=xe.Object;xe.Buffer=xe.Uint8Array;for(let r of"Uint8Clamped Uint16 Uint32 Int8 Int16 Int32 BigUint64 BigInt64 Float32 Float64".split(" "))xe[`${r}Array`]=xe.DataView;function Ht(r,e={},t){let n=bo(r),o=e&&e.typeEncoders&&e.typeEncoders[n]||xe[n];if(typeof o=="function"){let s=o(r,n,e,t);if(s!=null)return s}let i=xe[n];if(!i)throw new Error(`${He} unsupported type: ${n}`);return i(r,n,e,t)}function ic(r,e){e.mapSorter&&r.sort(e.mapSorter)}function sc(r,e){let t=Array.isArray(r[0])?r[0][0]:r[0],n=Array.isArray(e[0])?e[0][0]:e[0];if(t.type!==n.type)return t.type.compare(n.type);let o=t.type.major,i=xi[o].compareTokens(t,n);return i===0&&console.warn("WARNING: complex key types used, CBOR key sorting guarantees are gone"),i}function Ei(r,e,t,n){if(Array.isArray(e))for(let o of e)Ei(r,o,t,n);else t[e.type.major](r,e,n)}function vi(r,e,t){let n=Ht(r,t);if(!Array.isArray(n)&&t.quickEncodeToken){let o=t.quickEncodeToken(n);if(o)return o;let i=e[n.type.major];if(i.encodedSize){let s=i.encodedSize(n,t),c=new lt(s);if(i(c,n,t),c.chunks.length!==1)throw new Error(`Unexpected error: pre-calculated length for ${n} was wrong`);return ft(c.chunks[0])}}return cn.reset(),Ei(cn,n,e,t),cn.toBytes(!0)}function mt(r,e){return e=Object.assign({},nc,e),vi(r,xi,e)}var ac={strict:!1,allowIndefinite:!0,allowUndefined:!0,allowBigInt:!0},Gt=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=ee[e];if(t===void 0){let n=b[e];if(!n)throw new Error(`${k} no decoder for major type ${e>>>5} (byte 0x${e.toString(16).padStart(2,"0")})`);let o=e&31;t=n(this.data,this._pos,o,this.options)}return this._pos+=t.encodedLength,t}},gt=Symbol.for("DONE"),Kt=Symbol.for("BREAK");function cc(r,e,t){let n=[];for(let o=0;o<r.value;o++){let i=Qe(e,t);if(i===Kt){if(r.value===1/0)break;throw new Error(`${k} got unexpected break to lengthed array`)}if(i===gt)throw new Error(`${k} found array but not enough entries (got ${o}, expected ${r.value})`);n[o]=i}return n}function uc(r,e,t){let n=t.useMaps===!0,o=n?void 0:{},i=n?new Map:void 0;for(let s=0;s<r.value;s++){let c=Qe(e,t);if(c===Kt){if(r.value===1/0)break;throw new Error(`${k} got unexpected break to lengthed map`)}if(c===gt)throw new Error(`${k} found map but not enough entries (got ${s} [no key], expected ${r.value})`);if(n!==!0&&typeof c!="string")throw new Error(`${k} non-string keys not supported (got ${typeof c})`);if(t.rejectDuplicateMapKeys===!0&&(n&&i.has(c)||!n&&c in o))throw new Error(`${k} found repeat map key "${c}"`);let f=Qe(e,t);if(f===gt)throw new Error(`${k} found map but not enough entries (got ${s} [no value], expected ${r.value})`);n?i.set(c,f):o[c]=f}return n?i:o}function Qe(r,e){if(r.done())return gt;let t=r.next();if(t.type===u.break)return Kt;if(t.type.terminal)return t.value;if(t.type===u.array)return cc(t,r,e);if(t.type===u.map)return uc(t,r,e);if(t.type===u.tag){if(e.tags&&typeof e.tags[t.value]=="function"){let n=Qe(r,e);return e.tags[t.value](n)}throw new Error(`${k} tag not supported (${t.value})`)}throw new Error("unsupported")}function un(r,e){if(!(r instanceof Uint8Array))throw new Error(`${k} data to decode must be a Uint8Array`);e=Object.assign({},ac,e);let t=e.tokenizer||new Gt(r,e),n=Qe(t,e);if(n===gt)throw new Error(`${k} did not find any content to decode`);if(n===Kt)throw new Error(`${k} got unexpected break`);return[n,r.subarray(t.pos())]}function re(r,e){let[t,n]=un(r,e);if(n.length>0)throw new Error(`${k} too many terminals, data makes no sense`);return t}function Se(r,e="utf8"){let t=St[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.decoder.decode(`${t.prefix}${r}`)}var ue="/",ki=new TextEncoder().encode(ue),Qt=ki[0],fe=class r{_buf;constructor(e,t){if(typeof e=="string")this._buf=Se(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]!==Qt)throw new Error("Invalid key")}toString(e="utf8"){return ze(this._buf,e)}uint8Array(){return this._buf}get[Symbol.toStringTag](){return`Key(${this.toString()})`}static withNamespaces(e){return new r(e.join(ue))}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=ki),this._buf[0]!==Qt){let e=new Uint8Array(this._buf.byteLength+1);e.fill(Qt,0,1),e.set(this._buf,1),this._buf=e}for(;this._buf.byteLength>1&&this._buf[this._buf.byteLength-1]===Qt;)this._buf=this._buf.subarray(0,-1)}less(e){let t=this.list(),n=e.list();for(let o=0;o<t.length;o++){if(n.length<o+1)return!1;let i=t[o],s=n[o];if(i<s)return!0;if(i>s)return!1}return t.length<n.length}reverse(){return r.withNamespaces(this.list().slice().reverse())}namespaces(){return this.list()}baseNamespace(){let e=this.namespaces();return e[e.length-1]}list(){return this.toString().split(ue).slice(1)}type(){return fc(this.baseNamespace())}name(){return lc(this.baseNamespace())}instance(e){return new r(this.toString()+":"+e)}path(){let e=this.parent().toString();return e.endsWith(ue)||(e+=ue),e+=this.type(),new r(e)}parent(){let e=this.list();return e.length===1?new r(ue):new r(e.slice(0,-1).join(ue))}child(e){return this.toString()===ue?e:e.toString()===ue?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(),...hc(e.map(t=>t.namespaces()))])}};function fc(r){let e=r.split(":");return e.length<2?"":e.slice(0,-1).join(":")}function lc(r){let e=r.split(":");return e[e.length-1]}function hc(r){return[].concat(...r)}function Le(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}var Ti="/pin/",Ai="/pinned-block/",ln=it,Ci=1;function _i(r){return r.version===0&&(r=r.toV1()),new fe(`${Ti}${r.toString(ln)}`)}var Jt=class{datastore;blockstore;dagWalkers;constructor(e,t,n){this.datastore=e,this.blockstore=t,this.dagWalkers=n}async*add(e,t={}){let n=_i(e);if(await this.datastore.has(n))throw new Error("Already pinned");let o=Math.round(t.depth??1/0);if(o<0)throw new Error("Depth must be greater than or equal to 0");let i=new ae({concurrency:Ci});for await(let c of this.#e(e,i,{...t,depth:o}))await this.#o(c,f=>f.pinnedBy.find(p=>Le(p,e.bytes))!=null?!1:(f.pinCount++,f.pinnedBy.push(e.bytes),!0),t),yield c;let s={depth:o,metadata:t.metadata??{}};await this.datastore.put(n,mt(s),t)}async*#e(e,t,n){if(n.depth===-1)return;let o=this.dagWalkers[e.code];if(o==null)throw new Error(`No dag walker found for cid codec ${e.code}`);let i=await this.blockstore.get(e,n);yield e;for await(let s of o.walk(i))yield*await t.add(async()=>this.#e(s,t,{...n,depth:n.depth-1}))}async#o(e,t,n){let o=new fe(`${Ai}${ln.encode(e.multihash.bytes)}`),i={pinCount:0,pinnedBy:[]};try{i=re(await this.datastore.get(o,n))}catch(c){if(c.code!=="ERR_NOT_FOUND")throw c}if(t(i)){if(i.pinCount===0&&await this.datastore.has(o)){await this.datastore.delete(o);return}await this.datastore.put(o,mt(i),n),n.onProgress?.(new D("helia:pin:add",e))}}async*rm(e,t={}){let n=_i(e),o=await this.datastore.get(n,t),i=re(o);await this.datastore.delete(n,t);let s=new ae({concurrency:Ci});for await(let c of this.#e(e,s,{...t,depth:i.depth}))await this.#o(c,f=>(f.pinCount--,f.pinnedBy=f.pinnedBy.filter(p=>Le(p,e.bytes)),!0),{...t,depth:i.depth}),yield c}async*ls(e={}){for await(let{key:t,value:n}of this.datastore.query({prefix:Ti+(e.cid!=null?`${e.cid.toString(it)}`:"")},e)){let o=N.parse(t.toString().substring(5),it),i=re(n);yield{cid:o,...i}}}async isPinned(e,t={}){let n=new fe(`${Ai}${ln.encode(e.multihash.bytes)}`);return this.datastore.has(n,t)}};var Xt=class extends ae{has(e){return this.find(e)!=null}find(e){return this.queue.find(t=>e.equals(t.options.peerId))}};function dc(r){return r[Symbol.asyncIterator]!=null}function pc(...r){let e=[];for(let t of r)dc(t)||e.push(t);return e.length===r.length?function*(){for(let t of e)yield*t}():async function*(){let t=ut({objectMode:!0});Promise.resolve().then(async()=>{try{await Promise.all(r.map(async n=>{for await(let o of n)t.push(o)})),t.end()}catch(n){t.end(n)}}),yield*t}()}var yt=pc;var mc=5,Yt=class{log;routers;providerLookupConcurrency;constructor(e,t){this.log=e.logger.forComponent("helia:routing"),this.routers=t.routers??[],this.providerLookupConcurrency=t.providerLookupConcurrency??mc}async start(){await pe(...this.routers)}async stop(){await me(...this.routers)}async*findProviders(e,t={}){if(this.routers.length===0)throw new P("No content routers available","ERR_NO_ROUTERS_AVAILABLE");let n=new Xt({concurrency:this.providerLookupConcurrency});n.addEventListener("error",()=>{});for await(let o of yt(n.toGenerator(),...Je(this.routers,"findProviders").map(i=>i.findProviders(e,t))))if(o!=null){if(o.multiaddrs.length===0){if(n.find(o.id)!=null)continue;n.add(async()=>{try{let i=await this.findPeer(o.id,t);return i.multiaddrs.length===0?null:i}catch(i){return this.log.error("could not load multiaddrs for peer %p",o.id,i),null}},{peerId:o.id,signal:t.signal}).catch(i=>{this.log.error("could not load multiaddrs for peer %p",o.id,i)})}yield o}}async provide(e,t={}){if(this.routers.length===0)throw new P("No content routers available","ERR_NO_ROUTERS_AVAILABLE");await Promise.all(Je(this.routers,"provide").map(async n=>{await n.provide(e,t)}))}async put(e,t,n){await Promise.all(Je(this.routers,"put").map(async o=>{await o.put(e,t,n)}))}async get(e,t){return Promise.any(Je(this.routers,"get").map(async n=>n.get(e,t)))}async findPeer(e,t){if(this.routers.length===0)throw new P("No peer routers available","ERR_NO_ROUTERS_AVAILABLE");let n=this,o=yt(...Je(this.routers,"findPeer").map(i=>async function*(){try{yield await i.findPeer(e,t)}catch(s){n.log.error(s)}}()));for await(let i of o)if(i!=null)return i;throw new P("Could not find peer in routing","ERR_NOT_FOUND")}async*getClosestPeers(e,t={}){if(this.routers.length===0)throw new P("No peer routers available","ERR_NO_ROUTERS_AVAILABLE");for await(let n of yt(...Je(this.routers,"getClosestPeers").map(o=>o.getClosestPeers(e,t))))n!=null&&(yield n)}};function Je(r,e){return r.filter(t=>t[e]!=null)}var Ee={},Xe=r=>{r.addEventListener("message",e=>{Xe.dispatchEvent("message",r,e)}),r.port!=null&&r.port.addEventListener("message",e=>{Xe.dispatchEvent("message",r,e)})};Xe.addEventListener=(r,e)=>{Ee[r]==null&&(Ee[r]=[]),Ee[r].push(e)};Xe.removeEventListener=(r,e)=>{Ee[r]!=null&&(Ee[r]=Ee[r].filter(t=>t===e))};Xe.dispatchEvent=function(r,e,t){Ee[r]!=null&&Ee[r].forEach(n=>n(e,t))};var hn=Xe;var dn="lock:worker:request-read",pn="lock:worker:release-read",mn="lock:master:grant-read",gn="lock:worker:request-write",yn="lock:worker:release-write",wn="lock:master:grant-write";var Si=(r=21)=>Math.random().toString().substring(2);var Li=(r,e,t,n,o)=>(i,s)=>{if(s.data.type!==t)return;let c={type:s.data.type,name:s.data.name,identifier:s.data.identifier};r.dispatchEvent(new MessageEvent(e,{data:{name:c.name,handler:async()=>{i.postMessage({type:o,name:c.name,identifier:c.identifier}),await new Promise(f=>{let p=h=>{if(h==null||h.data==null)return;let l={type:h.data.type,name:h.data.name,identifier:h.data.identifier};l.type===n&&l.identifier===c.identifier&&(i.removeEventListener("message",p),f())};i.addEventListener("message",p)})}}}))},Ii=(r,e,t,n)=>async()=>{let o=Si();return globalThis.postMessage({type:e,identifier:o,name:r}),new Promise(i=>{let s=c=>{if(c==null||c.data==null)return;let f={type:c.data.type,identifier:c.data.identifier};f.type===t&&f.identifier===o&&(globalThis.removeEventListener("message",s),i(()=>{globalThis.postMessage({type:n,identifier:o,name:r})}))};globalThis.addEventListener("message",s)})},gc={singleProcess:!1},Di=r=>{if(r=Object.assign({},gc,r),!!globalThis.document||r.singleProcess){let t=new EventTarget;return hn.addEventListener("message",Li(t,"requestReadLock",dn,pn,mn)),hn.addEventListener("message",Li(t,"requestWriteLock",gn,yn,wn)),t}return{isWorker:!0,readLock:t=>Ii(t,dn,mn,pn),writeLock:t=>Ii(t,gn,wn,yn)}};var Ie={},ve;async function bn(r,e){let t,n=new Promise(o=>{t=o});return r.add(async()=>nt((async()=>{await new Promise(o=>{t(()=>{o()})})})(),{milliseconds:e.timeout})),n}var yc=(r,e)=>{if(ve.isWorker===!0)return{readLock:ve.readLock(r,e),writeLock:ve.writeLock(r,e)};let t=new we({concurrency:1}),n;return{async readLock(){if(n!=null)return bn(n,e);n=new we({concurrency:e.concurrency,autoStart:!1});let o=n,i=bn(n,e);return t.add(async()=>{o.start(),await o.onIdle().then(()=>{n===o&&(n=null)})}),i},async writeLock(){return n=null,bn(t,e)}}},wc={name:"lock",concurrency:1/0,timeout:846e5,singleProcess:!1};function xn(r){let e=Object.assign({},wc,r);return ve==null&&(ve=Di(e),ve.isWorker!==!0&&(ve.addEventListener("requestReadLock",t=>{Ie[t.data.name]!=null&&Ie[t.data.name].readLock().then(async n=>t.data.handler().finally(()=>{n()}))}),ve.addEventListener("requestWriteLock",async t=>{Ie[t.data.name]!=null&&Ie[t.data.name].writeLock().then(async n=>t.data.handler().finally(()=>{n()}))}))),Ie[e.name]==null&&(Ie[e.name]=yc(e.name,e)),Ie[e.name]}var Zt=class{lock;child;pins;started;constructor(e,t,n={}){this.child=e,this.pins=t,this.lock=xn({singleProcess:n.holdGcLock}),this.started=!1}isStarted(){return this.started}async start(){await pe(this.child),this.started=!0}async stop(){await me(this.child),this.started=!1}unwrap(){return this.child}async put(e,t,n={}){n?.signal?.throwIfAborted();let o=await this.lock.readLock();try{return await this.child.put(e,t,n)}finally{o()}}async*putMany(e,t={}){t?.signal?.throwIfAborted();let n=await this.lock.readLock();try{yield*this.child.putMany(e,t)}finally{n()}}async get(e,t={}){t?.signal?.throwIfAborted();let n=await this.lock.readLock();try{return await this.child.get(e,t)}finally{n()}}async*getMany(e,t={}){t?.signal?.throwIfAborted();let n=await this.lock.readLock();try{yield*this.child.getMany(e,t)}finally{n()}}async delete(e,t={}){t?.signal?.throwIfAborted();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={}){t?.signal?.throwIfAborted();let n=await this.lock.writeLock();try{let o=this;yield*this.child.deleteMany(async function*(){for await(let i of e){if(await o.pins.isPinned(i))throw new Error("CID was pinned");yield i}}(),t)}finally{n()}}async has(e,t={}){t?.signal?.throwIfAborted();let n=await this.lock.readLock();try{return await this.child.has(e,t)}finally{n()}}async*getAll(e={}){e?.signal?.throwIfAborted();let t=await this.lock.readLock();try{yield*this.child.getAll(e)}finally{t()}}createSession(e,t){return t?.signal?.throwIfAborted(),this.child.createSession(e,t)}};var Ni=42;function bc(r){if(r.asCID!==r&&r["/"]!==r.bytes)return null;let e=N.asCID(r);if(!e)return null;let t=new Uint8Array(e.bytes.byteLength+1);return t.set(e.bytes,1),[new g(u.tag,Ni),new g(u.bytes,t)]}function xc(){throw new Error("`undefined` is not supported by the IPLD Data Model and cannot be encoded")}function Ec(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 Ui={float64:!0,typeEncoders:{Object:bc,undefined:xc,number:Ec}},zh={...Ui,typeEncoders:{...Ui.typeEncoders}};function vc(r){if(r[0]!==0)throw new Error("Invalid CID for CBOR tag 42; expected leading 0x00");return N.decode(r.subarray(1))}var En={allowIndefinite:!1,coerceUndefinedToNull:!0,allowNaN:!1,allowInfinity:!1,allowBigInt:!0,strict:!0,useMaps:!1,rejectDuplicateMapKeys:!0,tags:[]};En.tags[Ni]=vc;var Vh={...En,tags:En.tags.slice()};var Bi=113;var Pi=class extends Array{constructor(){super(),this.inRecursive=[]}prefix(e){let t=this.inRecursive[this.inRecursive.length-1];t&&(t.type===u.array&&(t.elements++,t.elements!==1&&e.push([44])),t.type===u.map&&(t.elements++,t.elements!==1&&(t.elements%2===1?e.push([44]):e.push([58]))))}[u.uint.major](e,t){this.prefix(e);let n=String(t.value),o=[];for(let i=0;i<n.length;i++)o[i]=n.charCodeAt(i);e.push(o)}[u.negint.major](e,t){this[u.uint.major](e,t)}[u.bytes.major](e,t){throw new Error(`${He} unsupported type: Uint8Array`)}[u.string.major](e,t){this.prefix(e);let n=Ot(JSON.stringify(t.value));e.push(n.length>32?ft(n):n)}[u.array.major](e,t){this.prefix(e),this.inRecursive.push({type:u.array,elements:0}),e.push([91])}[u.map.major](e,t){this.prefix(e),this.inRecursive.push({type:u.map,elements:0}),e.push([123])}[u.tag.major](e,t){}[u.float.major](e,t){if(t.type.name==="break"){let s=this.inRecursive.pop();if(s){if(s.type===u.array)e.push([93]);else if(s.type===u.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(`${He} unsupported type: undefined`);if(this.prefix(e),t.type.name==="true"){e.push([116,114,117,101]);return}else if(t.type.name==="false"){e.push([102,97,108,115,101]);return}else if(t.type.name==="null"){e.push([110,117,108,108]);return}let n=String(t.value),o=[],i=!1;for(let s=0;s<n.length;s++)o[s]=n.charCodeAt(s),!i&&(o[s]===46||o[s]===101||o[s]===69)&&(i=!0);i||(o.push(46),o.push(48)),e.push(o)}};var De=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,o=c=>{for(;!this.done();){let f=this.ch();if(c.includes(f))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 g(u.uint,0,this._pos-e);if(o([48,49,50,51,52,53,54,55,56,57]),t&&this._pos===e+1)throw new Error(`${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++,o([48,49,50,51,52,53,54,55,56,57])}!this.done()&&(this.ch()===101||this.ch()===69)&&(n=!0,this._pos++,!this.done()&&(this.ch()===43||this.ch()===45)&&this._pos++,o([48,49,50,51,52,53,54,55,56,57]));let i=String.fromCharCode.apply(null,this.data.subarray(e,this._pos)),s=parseFloat(i);return n?new g(u.float,s,this._pos-e):this.options.allowBigInt!==!0||Number.isSafeInteger(s)?new g(s>=0?u.uint:u.negint,s,this._pos-e):new g(s>=0?u.uint:u.negint,BigInt(i),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 i=this._pos,s=0;i<this.data.length&&s<65536;i++,s++){let c=this.data[i];if(c===92||c<32||c>=128)break;if(c===34){let f=String.fromCharCode.apply(null,this.data.subarray(this._pos,i));return this._pos=i+1,new g(u.string,f,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 i=0;for(let s=0;s<4;s++){let c=this.ch();if(c>=48&&c<=57)c-=48;else if(c>=97&&c<=102)c=c-97+10;else if(c>=65&&c<=70)c=c-65+10;else throw new Error(`${k} unexpected unicode escape character at position ${this._pos}`);i=i*16+c,this._pos++}return i},o=()=>{let i=this.ch(),s=null,c=i>239?4:i>223?3:i>191?2:1;if(this._pos+c>this.data.length)throw new Error(`${k} unexpected unicode sequence at position ${this._pos}`);let f,p,h,l;switch(c){case 1:i<128&&(s=i);break;case 2:f=this.data[this._pos+1],(f&192)===128&&(l=(i&31)<<6|f&63,l>127&&(s=l));break;case 3:f=this.data[this._pos+1],p=this.data[this._pos+2],(f&192)===128&&(p&192)===128&&(l=(i&15)<<12|(f&63)<<6|p&63,l>2047&&(l<55296||l>57343)&&(s=l));break;case 4:f=this.data[this._pos+1],p=this.data[this._pos+2],h=this.data[this._pos+3],(f&192)===128&&(p&192)===128&&(h&192)===128&&(l=(i&15)<<18|(f&63)<<12|(p&63)<<6|h&63,l>65535&&l<1114112&&(s=l))}s===null?(s=65533,c=1):s>65535&&(s-=65536,t.push(s>>>10&1023|55296),s=56320|s&1023),t.push(s),this._pos+=c};for(;!this.done();){let i=this.ch(),s;switch(i){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 g(u.string,rn(t),this._pos-e);default:if(i<32)throw new Error(`${k} invalid control character at position ${this._pos}`);i<128?(t.push(i),this._pos++):o()}}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 g(u.map,1/0,1);case 91:return this.modeStack.push("array-start"),this._pos++,new g(u.array,1/0,1);case 34:return this.parseString();case 110:return this.expect([110,117,108,108]),new g(u.null,null,4);case 102:return this.expect([102,97,108,115,101]),new g(u.false,!1,5);case 116:return this.expect([116,114,117,101]),new g(u.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 g(u.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 g(u.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 g(u.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 g(u.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 er(r,e){return e=Object.assign({tokenizer:new De(r,e)},e),re(r,e)}var Cc={allowIndefinite:!1,allowUndefined:!1,allowNaN:!1,allowInfinity:!1,allowBigInt:!0,strict:!0,useMaps:!1,rejectDuplicateMapKeys:!0,tags:[]};Cc.tags[42]=N.parse;var Oi=297;var id=new TextDecoder;var sd=new TextEncoder;var Tc=new TextDecoder;function vn(r,e){let t=0;for(let n=0;;n+=7){if(n>=64)throw new Error("protobuf: varint overflow");if(e>=r.length)throw new Error("protobuf: unexpected end of data");let o=r[e++];if(t+=n<28?(o&127)<<n:(o&127)*2**n,o<128)break}return[t,e]}function tr(r,e){let t;[t,e]=vn(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 Fi(r,e){let t;return[t,e]=vn(r,e),[t&7,t>>3,e]}function Sc(r){let e={},t=r.length,n=0;for(;n<t;){let o,i;if([o,i,n]=Fi(r,n),i===1){if(e.Hash)throw new Error("protobuf: (PBLink) duplicate Hash section");if(o!==2)throw new Error(`protobuf: (PBLink) wrong wireType (${o}) for Hash`);if(e.Name!==void 0)throw new Error("protobuf: (PBLink) invalid order, found Name before Hash");if(e.Tsize!==void 0)throw new Error("protobuf: (PBLink) invalid order, found Tsize before Hash");[e.Hash,n]=tr(r,n)}else if(i===2){if(e.Name!==void 0)throw new Error("protobuf: (PBLink) duplicate Name section");if(o!==2)throw new Error(`protobuf: (PBLink) wrong wireType (${o}) for Name`);if(e.Tsize!==void 0)throw new Error("protobuf: (PBLink) invalid order, found Tsize before Name");let s;[s,n]=tr(r,n),e.Name=Tc.decode(s)}else if(i===3){if(e.Tsize!==void 0)throw new Error("protobuf: (PBLink) duplicate Tsize section");if(o!==0)throw new Error(`protobuf: (PBLink) wrong wireType (${o}) for Tsize`);[e.Tsize,n]=vn(r,n)}else throw new Error(`protobuf: (PBLink) invalid fieldNumber, expected 1, 2 or 3, got ${i}`)}if(n>t)throw new Error("protobuf: (PBLink) unexpected end of data");return e}function Mi(r){let e=r.length,t=0,n,o=!1,i;for(;t<e;){let c,f;if([c,f,t]=Fi(r,t),c!==2)throw new Error(`protobuf: (PBNode) invalid wireType, expected 2, got ${c}`);if(f===1){if(i)throw new Error("protobuf: (PBNode) duplicate Data section");[i,t]=tr(r,t),n&&(o=!0)}else if(f===2){if(o)throw new Error("protobuf: (PBNode) duplicate Links section");n||(n=[]);let p;[p,t]=tr(r,t),n.push(Sc(p))}else throw new Error(`protobuf: (PBNode) invalid fieldNumber, expected 1 or 2, got ${f}`)}if(t>e)throw new Error("protobuf: (PBNode) unexpected end of data");let s={};return i&&(s.Data=i),s.Links=n||[],s}var cd=new TextEncoder,ud=2**32,fd=2**31;var dd=new TextEncoder;function $i(r){return r instanceof ArrayBuffer?new Uint8Array(r,0,r.byteLength):r}var zi=112;function Vi(r){let e=$i(r),t=Mi(e),n={};return t.Data&&(n.Data=t.Data),t.Links&&(n.Links=t.Links.map(o=>{let i={};try{i.Hash=N.decode(o.Hash)}catch{}if(!i.Hash)throw new Error("Invalid Hash field found in link, expected CID");return o.Name!==void 0&&(i.Name=o.Name),o.Tsize!==void 0&&(i.Tsize=o.Tsize),i})),n}var Ic={codec:zi,*walk(r){yield*Vi(r).Links.map(t=>t.Hash)}},Dc={codec:Rr,*walk(){}},qi=42,Uc={codec:Bi,*walk(r){let e=[],t=[];t[qi]=n=>{if(n[0]!==0)throw new Error("Invalid CID for CBOR tag 42; expected leading 0x00");let o=N.decode(n.subarray(1));return e.push(o),o},re(r,{tags:t}),yield*e}},kn=class extends De{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===u.map){let t=this._next();if(t.type===u.string&&t.value==="/"){let n=this._next();if(n.type===u.string){if(this._next().type!==u.break)throw new Error("Invalid encoded CID form");return this.tokenBuffer.push(n),new g(u.tag,42,0)}if(n.type===u.map){let o=this._next();if(o.type===u.string&&o.value==="bytes"){let i=this._next();if(i.type===u.string){for(let c=0;c<2;c++)if(this._next().type!==u.break)throw new Error("Invalid encoded Bytes form");let s=ye.decode(`m${i.value}`);return new g(u.bytes,s,i.value.length)}this.tokenBuffer.push(i)}this.tokenBuffer.push(o)}this.tokenBuffer.push(n)}this.tokenBuffer.push(t)}return e}},Nc={codec:Oi,*walk(r){let e=[],t=[];t[qi]=n=>{let o=N.parse(n);return e.push(o),o},er(r,{tags:t,tokenizer:new kn(r,{tags:t,allowIndefinite:!0,allowUndefined:!0,allowNaN:!0,allowInfinity:!0,allowBigInt:!0,strict:!1,rejectDuplicateMapKeys:!1})}),yield*e}},Bc={codec:Jn,*walk(){}};function ji(r=[]){let e={};return[Ic,Dc,Uc,Nc,Bc,...r].forEach(t=>{e[t.codec]=t}),e}var An=new fe("/version"),Hi=1;async function Wi(r){if(!await r.has(An)){await r.put(An,Se(`${Hi}`));return}let e=await r.get(An),t=ze(e);if(parseInt(t,10)!==Hi)throw new Error("Unknown datastore version, a datastore migration may be required")}function Gi(r=[]){let e={};return[jr,Hr,$r,...r].forEach(t=>{e[t.code]=t}),e}function ne(r){let e=new globalThis.AbortController;function t(){e.abort();for(let i of r)i?.removeEventListener!=null&&i.removeEventListener("abort",t)}for(let i of r){if(i?.aborted===!0){t();break}i?.addEventListener!=null&&i.addEventListener("abort",t)}function n(){for(let i of r)i?.removeEventListener!=null&&i.removeEventListener("abort",t)}let o=e.signal;return o.clear=n,o}var ke=class{has(e,t){return Promise.reject(new Error(".has is not implemented"))}put(e,t,n){return Promise.reject(new Error(".put is not implemented"))}async*putMany(e,t){for await(let{cid:n,block:o}of e)await this.put(n,o,t),yield n}get(e,t){return Promise.reject(new Error(".get is not implemented"))}async*getMany(e,t){for await(let n of e)yield{cid:n,block:await this.get(n,t)}}delete(e,t){return Promise.reject(new Error(".delete is not implemented"))}async*deleteMany(e,t){for await(let n of e)await this.delete(n,t),yield n}async*getAll(e){throw new Error(".getAll is not implemented")}};var Ye={};$(Ye,{abortedError:()=>$c,closeFailedError:()=>Oc,deleteFailedError:()=>Yi,getFailedError:()=>Fc,hasFailedError:()=>Mc,notFoundError:()=>rr,openFailedError:()=>Rc,putFailedError:()=>Xi});var le=et(Ji(),1);function Rc(r){return r=r??new Error("Open failed"),(0,le.default)(r,"ERR_OPEN_FAILED")}function Oc(r){return r=r??new Error("Close failed"),(0,le.default)(r,"ERR_CLOSE_FAILED")}function Xi(r){return r=r??new Error("Put failed"),(0,le.default)(r,"ERR_PUT_FAILED")}function Fc(r){return r=r??new Error("Get failed"),(0,le.default)(r,"ERR_GET_FAILED")}function Yi(r){return r=r??new Error("Delete failed"),(0,le.default)(r,"ERR_DELETE_FAILED")}function Mc(r){return r=r??new Error("Has failed"),(0,le.default)(r,"ERR_HAS_FAILED")}function rr(r){return r=r??new Error("Not Found"),(0,le.default)(r,"ERR_NOT_FOUND")}function $c(r){return r=r??new Error("Aborted"),(0,le.default)(r,"ERR_ABORTED")}function zc(r){let[e,t]=r[Symbol.asyncIterator]!=null?[r[Symbol.asyncIterator](),Symbol.asyncIterator]:[r[Symbol.iterator](),Symbol.iterator],n=[];return{peek:()=>e.next(),push:o=>{n.push(o)},next:()=>n.length>0?{done:!1,value:n.shift()}:e.next(),[t](){return this}}}var nr=zc;function Vc(r){return r[Symbol.asyncIterator]!=null}function qc(r,e){let t=0;if(Vc(r))return async function*(){for await(let f of r)await e(f,t++)&&(yield f)}();let n=nr(r),{value:o,done:i}=n.next();if(i===!0)return function*(){}();let s=e(o,t++);if(typeof s.then=="function")return async function*(){await s&&(yield o);for await(let f of n)await e(f,t++)&&(yield f)}();let c=e;return function*(){s===!0&&(yield o);for(let f of n)c(f,t++)&&(yield f)}()}var Cn=qc;var Zd=Ar("blockstore:core:tiered");var Zi={...Ye};var or=0,ir=class extends ke{child;constructor(e){super(),this.child=e}put(e,t){return e.multihash.code===or||this.child==null?e:this.child.put(e,t)}get(e){if(e.multihash.code===or)return e.multihash.digest;if(this.child==null)throw Zi.notFoundError();return this.child.get(e)}has(e){return e.multihash.code===or?!0:this.child==null?!1:this.child.has(e)}delete(e){if(e.code!==or&&this.child!=null)return this.child.delete(e)}getAll(e){return this.child!=null?this.child.getAll(e):[]}};function jc(r){return r[Symbol.asyncIterator]!=null}function es(r){return r?.then!=null}function Hc(r,e){let t=0;if(jc(r))return async function*(){for await(let f of r){let p=e(f,t++);es(p)&&await p,yield f}}();let n=nr(r),{value:o,done:i}=n.next();if(i===!0)return function*(){}();if(typeof e(o,t++)?.then=="function")return async function*(){yield o;for await(let f of n){let p=e(f,t++);es(p)&&await p,yield f}}();let c=e;return function*(){yield o;for(let f of n)c(f,t++),yield f}()}var _n=Hc;var sr=class{child;hashers;log;logger;components;constructor(e){this.log=e.logger.forComponent("helia:networked-storage"),this.logger=e.logger,this.components=e,this.child=new ir(e.blockstore),this.hashers=e.hashers??{}}async put(e,t,n={}){return await this.child.has(e,n)?(n.onProgress?.(new D("blocks:put:duplicate",e)),e):(n.onProgress?.(new D("blocks:put:providers:notify",e)),await Promise.all(this.components.blockBrokers.map(async o=>o.announce?.(e,t,n))),n.onProgress?.(new D("blocks:put:blockstore:put",e)),this.child.put(e,t,n))}async*putMany(e,t={}){let n=Cn(e,async({cid:i})=>{let s=await this.child.has(i,t);return s&&t.onProgress?.(new D("blocks:put-many:duplicate",i)),!s}),o=_n(n,async({cid:i,block:s})=>{t.onProgress?.(new D("blocks:put-many:providers:notify",i)),await Promise.all(this.components.blockBrokers.map(async c=>c.announce?.(i,s,t)))});t.onProgress?.(new D("blocks:put-many:blockstore:put-many")),yield*this.child.putMany(o,t)}async get(e,t={}){if(t.offline!==!0&&!await this.child.has(e,t)){t.onProgress?.(new D("blocks:get:providers:get",e));let n=await ts(e,this.components.blockBrokers,this.hashers[e.multihash.code],{...t,log:this.log});return t.onProgress?.(new D("blocks:get:blockstore:put",e)),await this.child.put(e,n,t),t.onProgress?.(new D("blocks:get:providers:notify",e)),await Promise.all(this.components.blockBrokers.map(async o=>o.announce?.(e,n,t))),n}return t.onProgress?.(new D("blocks:get:blockstore:get",e)),this.child.get(e,t)}async*getMany(e,t={}){t.onProgress?.(new D("blocks:get-many:blockstore:get-many")),yield*this.child.getMany(_n(e,async n=>{if(t.offline!==!0&&!await this.child.has(n,t)){t.onProgress?.(new D("blocks:get-many:providers:get",n));let o=await ts(n,this.components.blockBrokers,this.hashers[n.multihash.code],{...t,log:this.log});t.onProgress?.(new D("blocks:get-many:blockstore:put",n)),await this.child.put(n,o,t),t.onProgress?.(new D("blocks:get-many:providers:notify",n)),await Promise.all(this.components.blockBrokers.map(async i=>i.announce?.(n,o,t)))}}))}async delete(e,t={}){t.onProgress?.(new D("blocks:delete:blockstore:delete",e)),await this.child.delete(e,t)}async*deleteMany(e,t={}){t.onProgress?.(new D("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 D("blocks:get-all:blockstore:get-many")),yield*this.child.getAll(e)}},ar=class extends sr{started;constructor(e){super(e),this.started=!1}isStarted(){return this.started}async start(){await pe(this.child,...this.components.blockBrokers),this.started=!0}async stop(){await me(this.child,...this.components.blockBrokers),this.started=!1}unwrap(){return this.child}createSession(e,t){let n=this.components.blockBrokers.map(o=>o.createSession==null?o:o.createSession(t));return new Tn({blockstore:this.child,blockBrokers:n,hashers:this.hashers,logger:this.logger},{root:e})}},Tn=class extends sr{closeController;constructor(e,t){super(e),this.closeController=new AbortController,R(1/0,this.closeController.signal),this.log=e.logger.forComponent(`helia:session-storage:${t.root}`)}close(){this.closeController.abort()}async put(e,t,n={}){let o=ne([this.closeController.signal,n.signal]);R(1/0,o);try{return await super.put(e,t,{...n,signal:o})}finally{o.clear()}}async*putMany(e,t={}){let n=ne([this.closeController.signal,t.signal]);R(1/0,n);try{yield*super.putMany(e,{...t,signal:n})}finally{n.clear()}}async get(e,t={}){let n=ne([this.closeController.signal,t.signal]);R(1/0,n);try{return await super.get(e,{...t,signal:n})}finally{n.clear()}}async*getMany(e,t={}){let n=ne([this.closeController.signal,t.signal]);R(1/0,n);try{yield*super.getMany(e,{...t,signal:n})}finally{n.clear()}}async delete(e,t={}){let n=ne([this.closeController.signal,t.signal]);R(1/0,n);try{await super.delete(e,{...t,signal:n})}finally{n.clear()}}async*deleteMany(e,t={}){let n=ne([this.closeController.signal,t.signal]);R(1/0,n);try{yield*super.deleteMany(e,{...t,signal:n})}finally{n.clear()}}async has(e,t={}){let n=ne([this.closeController.signal,t.signal]);R(1/0,n);try{return await super.has(e,{...t,signal:n})}finally{n.clear()}}async*getAll(e={}){let t=ne([this.closeController.signal,e.signal]);R(1/0,t);try{yield*super.getAll({...e,signal:t})}finally{t.clear()}}};function Wc(r){return typeof r.retrieve=="function"}var Gc=(r,e)=>{if(e==null)throw new P(`No hasher configured for multihash code 0x${r.multihash.code.toString(16)}, please configure one. You can look up which hash this is at https://github.com/multiformats/multicodec/blob/master/table.csv`,"ERR_UNKNOWN_HASH_ALG");return async t=>{let n=await e.digest(t);if(!Le(n.digest,r.multihash.digest))throw new P("Hash of downloaded block did not match multihash from passed CID","ERR_HASH_MISMATCH")}};async function ts(r,e,t,n){let o=Gc(r,t),i=new AbortController,s=ne([i.signal,n.signal]);R(1/0,i.signal,s);let c=[];for(let f of e)Wc(f)&&c.push(f);try{return await Promise.any(c.map(async f=>{try{let p=!1,h=await f.retrieve(r,{...n,signal:s,validateFn:async l=>{await o(l),p=!0}});return p||await o(h),h}catch(p){throw n.log.error("could not retrieve verified block for %c",r,p),p}}))}finally{i.abort(),s.clear()}}function Sn(r,e){e==null&&(e=r.reduce((o,i)=>o+i.length,0));let t=_e(e),n=0;for(let o of r)t.set(o,n),n+=o.length;return t}var cr=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;var Lp=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;var Ip={}.toString;function rs(r=32){if(cr&&typeof cr.getRandomValues=="function")return cr.getRandomValues(new Uint8Array(r));throw new Error("crypto.getRandomValues must be defined")}function ur(r){if(isNaN(r)||r<=0)throw new P("random bytes length must be a Number bigger than 0","ERR_INVALID_LENGTH");return rs(r)}var Ln=et(is(),1);var as=Symbol.for("@achingbrain/uint8arraylist");function ss(r,e){if(e==null||e<0)throw new RangeError("index is out of bounds");let t=0;for(let n of r){let o=t+n.byteLength;if(e<o)return{buf:n,index:e-t};t=o}throw new RangeError("index is out of bounds")}function lr(r){return!!r?.[as]}var hr=class r{bufs;length;[as]=!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(lr(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(lr(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=ss(this.bufs,e);return t.buf[t.index]}set(e,t){let n=ss(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(lr(e))for(let n=0;n<e.length;n++)this.set(t+n,e.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(e){if(e=Math.trunc(e),!(Number.isNaN(e)||e<=0)){if(e===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(e>=this.bufs[0].byteLength)e-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(e),this.length-=e;break}}}slice(e,t){let{bufs:n,length:o}=this._subList(e,t);return Sn(n,o)}subarray(e,t){let{bufs:n,length:o}=this._subList(e,t);return n.length===1?n[0]:Sn(n,o)}sublist(e,t){let{bufs:n,length:o}=this._subList(e,t),i=new r;return i.length=o,i.bufs=[...n],i}_subList(e,t){if(e=e??0,t=t??this.length,e<0&&(e=this.length+e),t<0&&(t=this.length+t),e<0||t>this.length)throw new RangeError("index is out of bounds");if(e===t)return{bufs:[],length:0};if(e===0&&t===this.length)return{bufs:this.bufs,length:this.length};let n=[],o=0;for(let i=0;i<this.bufs.length;i++){let s=this.bufs[i],c=o,f=c+s.byteLength;if(o=f,e>=f)continue;let p=e>=c&&e<f,h=t>c&&t<=f;if(p&&h){if(e===c&&t===f){n.push(s);break}let l=e-c;n.push(s.subarray(l,l+(t-e)));break}if(p){if(e===0){n.push(s);continue}n.push(s.subarray(e-c));continue}if(h){if(t===f){n.push(s);break}n.push(s.subarray(0,t-c));break}n.push(s)}return{bufs:n,length:t-e}}indexOf(e,t=0){if(!lr(e)&&!(e instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=e instanceof Uint8Array?e:e.subarray();if(t=Number(t??0),isNaN(t)&&(t=0),t<0&&(t=this.length+t),t<0&&(t=0),e.length===0)return t>this.length?this.length:t;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let i=256,s=new Int32Array(i);for(let l=0;l<i;l++)s[l]=-1;for(let l=0;l<o;l++)s[n[l]]=l;let c=s,f=this.byteLength-n.byteLength,p=n.byteLength-1,h;for(let l=t;l<=f;l+=h){h=0;for(let C=p;C>=0;C--){let a=this.get(l+C);if(n[C]!==a){h=Math.max(1,C-c[a]);break}}if(h===0)return l}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=_e(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,t),this.write(n,e)}getInt16(e,t){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,t)}setInt16(e,t,n){let o=Y(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,t,n),this.write(o,e)}getInt32(e,t){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,t)}setInt32(e,t,n){let o=Y(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,t,n),this.write(o,e)}getBigInt64(e,t){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,t)}setBigInt64(e,t,n){let o=Y(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,t,n),this.write(o,e)}getUint8(e){let t=this.subarray(e,e+1);return new DataView(t.buffer,t.byteOffset,t.byteLength).getUint8(0)}setUint8(e,t){let n=_e(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,t),this.write(n,e)}getUint16(e,t){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,t)}setUint16(e,t,n){let o=Y(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,t,n),this.write(o,e)}getUint32(e,t){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,t)}setUint32(e,t,n){let o=Y(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,t,n),this.write(o,e)}getBigUint64(e,t){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,t)}setBigUint64(e,t,n){let o=Y(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,t,n),this.write(o,e)}getFloat32(e,t){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,t)}setFloat32(e,t,n){let o=Y(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,t,n),this.write(o,e)}getFloat64(e,t){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,t)}setFloat64(e,t,n){let o=Y(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,t,n),this.write(o,e)}equals(e){if(e==null||!(e instanceof r)||e.bufs.length!==this.bufs.length)return!1;for(let t=0;t<this.bufs.length;t++)if(!Le(this.bufs[t],e.bufs[t]))return!1;return!0}static fromUint8Arrays(e,t){let n=new r;return n.bufs=e,t==null&&(t=e.reduce((o,i)=>o+i.byteLength,0)),n.length=t,n}};var Kc=Math.LN2*Math.LN2,Ze=class r{static create(e,t=.005){let n=Qc(e,t);return new r(n)}seeds;bits;buffer;constructor(e={}){e.seeds!=null?this.seeds=e.seeds:this.seeds=Jc(e.hashes??8),this.bits=e.bits??1024,this.buffer=Y(Math.ceil(this.bits/8))}add(e){typeof e=="string"&&(e=Se(e));for(let t=0;t<this.seeds.length;t++){let o=Ln.default.x86.hash32(e,this.seeds[t])%this.bits;this.setbit(o)}}has(e){typeof e=="string"&&(e=Se(e));for(let t=0;t<this.seeds.length;t++){let o=Ln.default.x86.hash32(e,this.seeds[t])%this.bits;if(!this.getbit(o))return!1}return!0}clear(){this.buffer.fill(0)}setbit(e){let t=0,n=e;for(;n>7;)t++,n-=8;let o=this.buffer[t];o|=1<<n,this.buffer[t]=o}getbit(e){let t=0,n=e;for(;n>7;)t++,n-=8;return(this.buffer[t]&1<<n)!==0}};function Qc(r,e=.005){let t=Math.round(-1*r*Math.log(e)/Kc),n=Math.round(t/r*Math.LN2);return{bits:t,hashes:n}}function Jc(r){let e,t,n=[];for(let o=0;o<r;o++)for(e=new hr(ur(4)),n[o]=e.getUint32(0,!0),t=0;t<o;t++)if(n[o]===n[t]){o--;break}return n}var dr=class extends Ue{intialPeerSearchComplete;requests;name;log;logger;minProviders;maxProviders;providers;evictionFilter;constructor(e,t){super(),R(1/0,this),this.name=t.name,this.logger=e.logger,this.log=e.logger.forComponent(this.name),this.requests=new Map,this.minProviders=t.minProviders??1,this.maxProviders=t.maxProviders??5,this.providers=[],this.evictionFilter=Ze.create(this.maxProviders)}async retrieve(e,t={}){let n=ye.encode(e.multihash.bytes),o=this.requests.get(n);if(o!=null)return this.log("join existing request for %c",e),o;let i=se();if(this.requests.set(n,i.promise),this.providers.length===0){let p=!1;this.intialPeerSearchComplete==null&&(p=!0,this.log=this.logger.forComponent(`${this.name}:${e}`),this.intialPeerSearchComplete=this.findProviders(e,this.minProviders,t)),await this.intialPeerSearchComplete,p&&this.log("found initial session peers for %c",e)}let s=!1,c=new ae({concurrency:this.maxProviders});c.addEventListener("error",()=>{}),c.addEventListener("failure",p=>{this.log.error("error querying provider %o, evicting from session",p.detail.job.options.provider,p.detail.error),this.evict(p.detail.job.options.provider)}),c.addEventListener("success",p=>{s=!0,i.resolve(p.detail.result)}),c.addEventListener("idle",()=>{s||t.signal?.aborted===!0||Promise.resolve().then(async()=>{this.log("no session peers had block for for %c, finding new providers",e);for(let p=0;p<this.minProviders&&this.providers.length!==0;p++){let h=this.providers[Math.floor(Math.random()*this.providers.length)];this.evict(h)}await this.findProviders(e,this.minProviders,t),this.log("found new providers re-retrieving %c",e),this.requests.delete(n),i.resolve(await this.retrieve(e,t))}).catch(p=>{this.log.error("could not find new providers for %c",e,p),i.reject(p)})});let f=p=>{c.add(async()=>this.queryProvider(e,p.detail,t),{provider:p.detail}).catch(h=>{t.signal?.aborted!==!0&&this.log.error("error retrieving session block for %c",e,h)})};this.addEventListener("provider",f),Promise.all([...this.providers].map(async p=>c.add(async()=>this.queryProvider(e,p,t),{provider:p}))).catch(p=>{t.signal?.aborted!==!0&&this.log.error("error retrieving session block for %c",e,p)});try{return await i.promise}finally{this.removeEventListener("provider",f),c.clear(),this.requests.delete(n)}}evict(e){this.evictionFilter.add(this.toEvictionKey(e));let t=this.providers.findIndex(n=>this.equals(n,e));t!==-1&&this.providers.splice(t,1)}isEvicted(e){return this.evictionFilter.has(this.toEvictionKey(e))}hasProvider(e){return!!(this.providers.find(t=>this.equals(t,e))!=null||this.isEvicted(e))}async findProviders(e,t,n){let o=se(),i=0;return Promise.resolve().then(async()=>{this.log("finding %d-%d new provider(s) for %c",t,this.maxProviders,e);for await(let s of this.findNewProviders(e,n)){if(i===this.maxProviders||n.signal?.aborted===!0)break;if(!this.hasProvider(s)&&(this.log("found %d/%d new providers",i,this.maxProviders),this.providers.push(s),this.safeDispatchEvent("provider",{detail:s}),i++,i===t&&(this.log("session is ready"),o.resolve()),this.providers.length===this.maxProviders)){this.log("found max session peers",i);break}}if(this.log("found %d/%d new session peers",i,this.maxProviders),i<t)throw new P(`Found ${i} of ${t} ${this.name} providers for ${e}`,"ERR_INSUFFICIENT_PROVIDERS_FOUND")}).catch(s=>{this.log.error("error searching routing for potential session peers for %c",e,s.errors??s),o.reject(s)}),o.promise}};var In=class{blockstore;datastore;pins;logger;routing;dagWalkers;hashers;dns;metrics;log;constructor(e){this.logger=e.logger??jn(),this.log=this.logger.forComponent("helia"),this.hashers=Gi(e.hashers),this.dagWalkers=ji(e.dagWalkers),this.dns=e.dns??yo(),this.metrics=e.metrics;let t={blockstore:e.blockstore,datastore:e.datastore,hashers:this.hashers,dagWalkers:this.dagWalkers,logger:this.logger,blockBrokers:[],dns:this.dns,metrics:this.metrics,...e.components??{}};this.routing=t.routing=new Yt(t,{routers:(e.routers??[]).flatMap(o=>{let i=[o];return o[pr]!=null&&i.push(o[pr]),o[mr]!=null&&i.push(o[mr]),i}),providerLookupConcurrency:e.providerLookupConcurrency});let n=new ar(t);this.pins=new Jt(e.datastore,n,this.dagWalkers),this.blockstore=new Zt(n,this.pins,{holdGcLock:e.holdGcLock??!0}),this.datastore=e.datastore,t.blockBrokers=e.blockBrokers.map(o=>o(t))}async start(){await Wi(this.datastore),await pe(this.blockstore,this.datastore,this.routing)}async stop(){await me(this.blockstore,this.datastore,this.routing)}async gc(e={}){let t=await this.blockstore.lock.writeLock();try{let n=this,o=this.blockstore.unwrap();this.log("gc start"),await Zr(o.deleteMany(async function*(){for await(let{cid:i}of o.getAll())try{if(await n.pins.isPinned(i,e))continue;yield i,e.onProgress?.(new D("helia:gc:deleted",i))}catch(s){n.log.error("Error during gc",s),e.onProgress?.(new D("helia:gc:error",s))}}()))}finally{t()}this.log("gc finished")}};return ds(Xc);})();
|
|
2
|
+
"use strict";var HeliaUtils=(()=>{var es=Object.create;var yt=Object.defineProperty;var ts=Object.getOwnPropertyDescriptor;var rs=Object.getOwnPropertyNames;var ns=Object.getPrototypeOf,os=Object.prototype.hasOwnProperty;var Je=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),M=(r,e)=>{for(var t in e)yt(r,t,{get:e[t],enumerable:!0})},Tn=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of rs(e))!os.call(r,o)&&o!==t&&yt(r,o,{get:()=>e[o],enumerable:!(n=ts(e,o))||n.enumerable});return r};var wt=(r,e,t)=>(t=r!=null?es(ns(r)):{},Tn(e||!r||!r.__esModule?yt(t,"default",{value:r,enumerable:!0}):t,r)),is=r=>Tn(yt({},"__esModule",{value:!0}),r);var Fn=Je((Eu,Er)=>{"use strict";var Fs=Object.prototype.hasOwnProperty,$="~";function Xe(){}Object.create&&(Xe.prototype=Object.create(null),new Xe().__proto__||($=!1));function $s(r,e,t){this.fn=r,this.context=e,this.once=t||!1}function On(r,e,t,n,o){if(typeof t!="function")throw new TypeError("The listener must be a function");var i=new $s(t,n||r,o),s=$?$+e:e;return r._events[s]?r._events[s].fn?r._events[s]=[r._events[s],i]:r._events[s].push(i):(r._events[s]=i,r._eventsCount++),r}function vt(r,e){--r._eventsCount===0?r._events=new Xe:delete r._events[e]}function F(){this._events=new Xe,this._eventsCount=0}F.prototype.eventNames=function(){var e=[],t,n;if(this._eventsCount===0)return e;for(n in t=this._events)Fs.call(t,n)&&e.push($?n.slice(1):n);return Object.getOwnPropertySymbols?e.concat(Object.getOwnPropertySymbols(t)):e};F.prototype.listeners=function(e){var t=$?$+e:e,n=this._events[t];if(!n)return[];if(n.fn)return[n.fn];for(var o=0,i=n.length,s=new Array(i);o<i;o++)s[o]=n[o].fn;return s};F.prototype.listenerCount=function(e){var t=$?$+e:e,n=this._events[t];return n?n.fn?1:n.length:0};F.prototype.emit=function(e,t,n,o,i,s){var c=$?$+e:e;if(!this._events[c])return!1;var f=this._events[c],p=arguments.length,h,l;if(f.fn){switch(f.once&&this.removeListener(e,f.fn,void 0,!0),p){case 1:return f.fn.call(f.context),!0;case 2:return f.fn.call(f.context,t),!0;case 3:return f.fn.call(f.context,t,n),!0;case 4:return f.fn.call(f.context,t,n,o),!0;case 5:return f.fn.call(f.context,t,n,o,i),!0;case 6:return f.fn.call(f.context,t,n,o,i,s),!0}for(l=1,h=new Array(p-1);l<p;l++)h[l-1]=arguments[l];f.fn.apply(f.context,h)}else{var C=f.length,a;for(l=0;l<C;l++)switch(f[l].once&&this.removeListener(e,f[l].fn,void 0,!0),p){case 1:f[l].fn.call(f[l].context);break;case 2:f[l].fn.call(f[l].context,t);break;case 3:f[l].fn.call(f[l].context,t,n);break;case 4:f[l].fn.call(f[l].context,t,n,o);break;default:if(!h)for(a=1,h=new Array(p-1);a<p;a++)h[a-1]=arguments[a];f[l].fn.apply(f[l].context,h)}}return!0};F.prototype.on=function(e,t,n){return On(this,e,t,n,!1)};F.prototype.once=function(e,t,n){return On(this,e,t,n,!0)};F.prototype.removeListener=function(e,t,n,o){var i=$?$+e:e;if(!this._events[i])return this;if(!t)return vt(this,i),this;var s=this._events[i];if(s.fn)s.fn===t&&(!o||s.once)&&(!n||s.context===n)&&vt(this,i);else{for(var c=0,f=[],p=s.length;c<p;c++)(s[c].fn!==t||o&&!s[c].once||n&&s[c].context!==n)&&f.push(s[c]);f.length?this._events[i]=f.length===1?f[0]:f:vt(this,i)}return this};F.prototype.removeAllListeners=function(e){var t;return e?(t=$?$+e:e,this._events[t]&&vt(this,t)):(this._events=new Xe,this._eventsCount=0),this};F.prototype.off=F.prototype.removeListener;F.prototype.addListener=F.prototype.on;F.prefixed=$;F.EventEmitter=F;typeof Er<"u"&&(Er.exports=F)});var io=Je((If,oo)=>{oo.exports=function(r){if(!r)throw Error("hashlru must have a max value, of type number, greater than 0");var e=0,t=Object.create(null),n=Object.create(null);function o(i,s){t[i]=s,e++,e>=r&&(e=0,n=t,t=Object.create(null))}return{has:function(i){return t[i]!==void 0||n[i]!==void 0},remove:function(i){t[i]!==void 0&&(t[i]=void 0),n[i]!==void 0&&(n[i]=void 0)},get:function(i){var s=t[i];if(s!==void 0)return s;if((s=n[i])!==void 0)return o(i,s),s},set:function(i,s){t[i]!==void 0?t[i]=s:o(i,s)},clear:function(){t=Object.create(null),n=Object.create(null)}}}});var Vi=Je((Fd,zi)=>{"use strict";function Mi(r,e){for(let t in e)Object.defineProperty(r,t,{value:e[t],enumerable:!0,configurable:!0});return r}function Sc(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 Mi(r,t)}catch{t.message=r.message,t.stack=r.stack;let o=function(){};return o.prototype=Object.create(Object.getPrototypeOf(r)),Mi(new o,t)}}zi.exports=Sc});var Qi=Je((dt,sr)=>{(function(r,e){"use strict";var t={version:"3.0.0",x86:{},x64:{},inputValidation:!0};function n(a){if(!Array.isArray(a)&&!ArrayBuffer.isView(a))return!1;for(var d=0;d<a.length;d++)if(!Number.isInteger(a[d])||a[d]<0||a[d]>255)return!1;return!0}function o(a,d){return(a&65535)*d+(((a>>>16)*d&65535)<<16)}function i(a,d){return a<<d|a>>>32-d}function s(a){return a^=a>>>16,a=o(a,2246822507),a^=a>>>13,a=o(a,3266489909),a^=a>>>16,a}function c(a,d){a=[a[0]>>>16,a[0]&65535,a[1]>>>16,a[1]&65535],d=[d[0]>>>16,d[0]&65535,d[1]>>>16,d[1]&65535];var m=[0,0,0,0];return m[3]+=a[3]+d[3],m[2]+=m[3]>>>16,m[3]&=65535,m[2]+=a[2]+d[2],m[1]+=m[2]>>>16,m[2]&=65535,m[1]+=a[1]+d[1],m[0]+=m[1]>>>16,m[1]&=65535,m[0]+=a[0]+d[0],m[0]&=65535,[m[0]<<16|m[1],m[2]<<16|m[3]]}function f(a,d){a=[a[0]>>>16,a[0]&65535,a[1]>>>16,a[1]&65535],d=[d[0]>>>16,d[0]&65535,d[1]>>>16,d[1]&65535];var m=[0,0,0,0];return m[3]+=a[3]*d[3],m[2]+=m[3]>>>16,m[3]&=65535,m[2]+=a[2]*d[3],m[1]+=m[2]>>>16,m[2]&=65535,m[2]+=a[3]*d[2],m[1]+=m[2]>>>16,m[2]&=65535,m[1]+=a[1]*d[3],m[0]+=m[1]>>>16,m[1]&=65535,m[1]+=a[2]*d[2],m[0]+=m[1]>>>16,m[1]&=65535,m[1]+=a[3]*d[1],m[0]+=m[1]>>>16,m[1]&=65535,m[0]+=a[0]*d[3]+a[1]*d[2]+a[2]*d[1]+a[3]*d[0],m[0]&=65535,[m[0]<<16|m[1],m[2]<<16|m[3]]}function p(a,d){return d%=64,d===32?[a[1],a[0]]:d<32?[a[0]<<d|a[1]>>>32-d,a[1]<<d|a[0]>>>32-d]:(d-=32,[a[1]<<d|a[0]>>>32-d,a[0]<<d|a[1]>>>32-d])}function h(a,d){return d%=64,d===0?a:d<32?[a[0]<<d|a[1]>>>32-d,a[1]<<d]:[a[1]<<d-32,0]}function l(a,d){return[a[0]^d[0],a[1]^d[1]]}function C(a){return a=l(a,[0,a[0]>>>1]),a=f(a,[4283543511,3981806797]),a=l(a,[0,a[0]>>>1]),a=f(a,[3301882366,444984403]),a=l(a,[0,a[0]>>>1]),a}t.x86.hash32=function(a,d){if(t.inputValidation&&!n(a))return e;d=d||0;for(var m=a.length%4,A=a.length-m,y=d,w=0,x=3432918353,E=461845907,_=0;_<A;_=_+4)w=a[_]|a[_+1]<<8|a[_+2]<<16|a[_+3]<<24,w=o(w,x),w=i(w,15),w=o(w,E),y^=w,y=i(y,13),y=o(y,5)+3864292196;switch(w=0,m){case 3:w^=a[_+2]<<16;case 2:w^=a[_+1]<<8;case 1:w^=a[_],w=o(w,x),w=i(w,15),w=o(w,E),y^=w}return y^=a.length,y=s(y),y>>>0},t.x86.hash128=function(a,d){if(t.inputValidation&&!n(a))return e;d=d||0;for(var m=a.length%16,A=a.length-m,y=d,w=d,x=d,E=d,_=0,T=0,v=0,L=0,Q=597399067,pt=2869860233,mt=951274213,gt=2716044179,S=0;S<A;S=S+16)_=a[S]|a[S+1]<<8|a[S+2]<<16|a[S+3]<<24,T=a[S+4]|a[S+5]<<8|a[S+6]<<16|a[S+7]<<24,v=a[S+8]|a[S+9]<<8|a[S+10]<<16|a[S+11]<<24,L=a[S+12]|a[S+13]<<8|a[S+14]<<16|a[S+15]<<24,_=o(_,Q),_=i(_,15),_=o(_,pt),y^=_,y=i(y,19),y+=w,y=o(y,5)+1444728091,T=o(T,pt),T=i(T,16),T=o(T,mt),w^=T,w=i(w,17),w+=x,w=o(w,5)+197830471,v=o(v,mt),v=i(v,17),v=o(v,gt),x^=v,x=i(x,15),x+=E,x=o(x,5)+2530024501,L=o(L,gt),L=i(L,18),L=o(L,Q),E^=L,E=i(E,13),E+=y,E=o(E,5)+850148119;switch(_=0,T=0,v=0,L=0,m){case 15:L^=a[S+14]<<16;case 14:L^=a[S+13]<<8;case 13:L^=a[S+12],L=o(L,gt),L=i(L,18),L=o(L,Q),E^=L;case 12:v^=a[S+11]<<24;case 11:v^=a[S+10]<<16;case 10:v^=a[S+9]<<8;case 9:v^=a[S+8],v=o(v,mt),v=i(v,17),v=o(v,gt),x^=v;case 8:T^=a[S+7]<<24;case 7:T^=a[S+6]<<16;case 6:T^=a[S+5]<<8;case 5:T^=a[S+4],T=o(T,pt),T=i(T,16),T=o(T,mt),w^=T;case 4:_^=a[S+3]<<24;case 3:_^=a[S+2]<<16;case 2:_^=a[S+1]<<8;case 1:_^=a[S],_=o(_,Q),_=i(_,15),_=o(_,pt),y^=_}return y^=a.length,w^=a.length,x^=a.length,E^=a.length,y+=w,y+=x,y+=E,w+=y,x+=y,E+=y,y=s(y),w=s(w),x=s(x),E=s(E),y+=w,y+=x,y+=E,w+=y,x+=y,E+=y,("00000000"+(y>>>0).toString(16)).slice(-8)+("00000000"+(w>>>0).toString(16)).slice(-8)+("00000000"+(x>>>0).toString(16)).slice(-8)+("00000000"+(E>>>0).toString(16)).slice(-8)},t.x64.hash128=function(a,d){if(t.inputValidation&&!n(a))return e;d=d||0;for(var m=a.length%16,A=a.length-m,y=[0,d],w=[0,d],x=[0,0],E=[0,0],_=[2277735313,289559509],T=[1291169091,658871167],v=0;v<A;v=v+16)x=[a[v+4]|a[v+5]<<8|a[v+6]<<16|a[v+7]<<24,a[v]|a[v+1]<<8|a[v+2]<<16|a[v+3]<<24],E=[a[v+12]|a[v+13]<<8|a[v+14]<<16|a[v+15]<<24,a[v+8]|a[v+9]<<8|a[v+10]<<16|a[v+11]<<24],x=f(x,_),x=p(x,31),x=f(x,T),y=l(y,x),y=p(y,27),y=c(y,w),y=c(f(y,[0,5]),[0,1390208809]),E=f(E,T),E=p(E,33),E=f(E,_),w=l(w,E),w=p(w,31),w=c(w,y),w=c(f(w,[0,5]),[0,944331445]);switch(x=[0,0],E=[0,0],m){case 15:E=l(E,h([0,a[v+14]],48));case 14:E=l(E,h([0,a[v+13]],40));case 13:E=l(E,h([0,a[v+12]],32));case 12:E=l(E,h([0,a[v+11]],24));case 11:E=l(E,h([0,a[v+10]],16));case 10:E=l(E,h([0,a[v+9]],8));case 9:E=l(E,[0,a[v+8]]),E=f(E,T),E=p(E,33),E=f(E,_),w=l(w,E);case 8:x=l(x,h([0,a[v+7]],56));case 7:x=l(x,h([0,a[v+6]],48));case 6:x=l(x,h([0,a[v+5]],40));case 5:x=l(x,h([0,a[v+4]],32));case 4:x=l(x,h([0,a[v+3]],24));case 3:x=l(x,h([0,a[v+2]],16));case 2:x=l(x,h([0,a[v+1]],8));case 1:x=l(x,[0,a[v]]),x=f(x,_),x=p(x,31),x=f(x,T),y=l(y,x)}return y=l(y,[0,a.length]),w=l(w,[0,a.length]),y=c(y,w),w=c(w,y),y=C(y),w=C(w),y=c(y,w),w=c(w,y),("00000000"+(y[0]>>>0).toString(16)).slice(-8)+("00000000"+(y[1]>>>0).toString(16)).slice(-8)+("00000000"+(w[0]>>>0).toString(16)).slice(-8)+("00000000"+(w[1]>>>0).toString(16)).slice(-8)},typeof dt<"u"?(typeof sr<"u"&&sr.exports&&(dt=sr.exports=t),dt.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)})(dt)});var Xi=Je((Fp,Ji)=>{Ji.exports=Qi()});var jc={};M(jc,{AbstractSession:()=>ur,BloomFilter:()=>Qe,Helia:()=>_n});var fr=Symbol.for("@libp2p/content-routing");var lr=Symbol.for("@libp2p/peer-routing");var he=class r extends Error{code;type;constructor(e="The operation was aborted"){super(e),this.name="AbortError",this.code=r.code,this.type=r.type}static code="ABORT_ERR";static type="aborted"},P=class extends Error{code;props;constructor(e,t,n){super(e),this.code=t,this.name=n?.name??"CodeError",this.props=n??{}}};var R=(r,...e)=>{try{[...e]}catch{}};var De=class extends EventTarget{#e=new Map;constructor(){super(),R(1/0,this)}listenerCount(e){let t=this.#e.get(e);return t==null?0:t.length}addEventListener(e,t,n){super.addEventListener(e,t,n);let o=this.#e.get(e);o==null&&(o=[],this.#e.set(e,o)),o.push({callback:t,once:(n!==!0&&n!==!1&&n?.once)??!1})}removeEventListener(e,t,n){super.removeEventListener(e.toString(),t??null,n);let o=this.#e.get(e);o!=null&&(o=o.filter(({callback:i})=>i!==t),this.#e.set(e,o))}dispatchEvent(e){let t=super.dispatchEvent(e),n=this.#e.get(e.type);return n==null||(n=n.filter(({once:o})=>!o),this.#e.set(e.type,n)),t}safeDispatchEvent(e,t={}){return this.dispatchEvent(new ss(e,t))}},ss=globalThis.CustomEvent;function Sn(r){return r!=null&&typeof r.start=="function"&&typeof r.stop=="function"}async function de(...r){let e=[];for(let t of r)Sn(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 pe(...r){let e=[];for(let t of r)Sn(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 gr={};M(gr,{base32:()=>oe,base32hex:()=>ms,base32hexpad:()=>ys,base32hexpadupper:()=>ws,base32hexupper:()=>gs,base32pad:()=>ds,base32padupper:()=>ps,base32upper:()=>hs,base32z:()=>bs});var Zc=new Uint8Array(0);function Ln(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 ne(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 In(r){return new TextEncoder().encode(r)}function Dn(r){return new TextDecoder().decode(r)}function as(r,e){if(r.length>=255)throw new TypeError("Alphabet too long");for(var t=new Uint8Array(256),n=0;n<t.length;n++)t[n]=255;for(var o=0;o<r.length;o++){var i=r.charAt(o),s=i.charCodeAt(0);if(t[s]!==255)throw new TypeError(i+" is ambiguous");t[s]=o}var c=r.length,f=r.charAt(0),p=Math.log(c)/Math.log(256),h=Math.log(256)/Math.log(c);function l(d){if(d instanceof Uint8Array||(ArrayBuffer.isView(d)?d=new Uint8Array(d.buffer,d.byteOffset,d.byteLength):Array.isArray(d)&&(d=Uint8Array.from(d))),!(d instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(d.length===0)return"";for(var m=0,A=0,y=0,w=d.length;y!==w&&d[y]===0;)y++,m++;for(var x=(w-y)*h+1>>>0,E=new Uint8Array(x);y!==w;){for(var _=d[y],T=0,v=x-1;(_!==0||T<A)&&v!==-1;v--,T++)_+=256*E[v]>>>0,E[v]=_%c>>>0,_=_/c>>>0;if(_!==0)throw new Error("Non-zero carry");A=T,y++}for(var L=x-A;L!==x&&E[L]===0;)L++;for(var Q=f.repeat(m);L<x;++L)Q+=r.charAt(E[L]);return Q}function C(d){if(typeof d!="string")throw new TypeError("Expected String");if(d.length===0)return new Uint8Array;var m=0;if(d[m]!==" "){for(var A=0,y=0;d[m]===f;)A++,m++;for(var w=(d.length-m)*p+1>>>0,x=new Uint8Array(w);d[m];){var E=t[d.charCodeAt(m)];if(E===255)return;for(var _=0,T=w-1;(E!==0||_<y)&&T!==-1;T--,_++)E+=c*x[T]>>>0,x[T]=E%256>>>0,E=E/256>>>0;if(E!==0)throw new Error("Non-zero carry");y=_,m++}if(d[m]!==" "){for(var v=w-y;v!==w&&x[v]===0;)v++;for(var L=new Uint8Array(A+(w-v)),Q=A;v!==w;)L[Q++]=x[v++];return L}}}function a(d){var m=C(d);if(m)return m;throw new Error(`Non-${e} character`)}return{encode:l,decodeUnsafe:C,decode:a}}var cs=as,us=cs,Bn=us;var hr=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")}},dr=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 Un(this,e)}},pr=class{decoders;constructor(e){this.decoders=e}or(e){return Un(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 Un(r,e){return new pr({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}var mr=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,t,n,o){this.name=e,this.prefix=t,this.baseEncode=n,this.baseDecode=o,this.encoder=new hr(e,t,n),this.decoder=new dr(e,t,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function Ne({name:r,prefix:e,encode:t,decode:n}){return new mr(r,e,t,n)}function me({name:r,prefix:e,alphabet:t}){let{encode:n,decode:o}=Bn(t,r);return Ne({prefix:e,name:r,encode:n,decode:i=>ne(o(i))})}function fs(r,e,t,n){let o={};for(let h=0;h<e.length;++h)o[e[h]]=h;let i=r.length;for(;r[i-1]==="=";)--i;let s=new Uint8Array(i*t/8|0),c=0,f=0,p=0;for(let h=0;h<i;++h){let l=o[r[h]];if(l===void 0)throw new SyntaxError(`Non-${n} character`);f=f<<t|l,c+=t,c>=8&&(c-=8,s[p++]=255&f>>c)}if(c>=t||255&f<<8-c)throw new SyntaxError("Unexpected end of data");return s}function ls(r,e,t){let n=e[e.length-1]==="=",o=(1<<t)-1,i="",s=0,c=0;for(let f=0;f<r.length;++f)for(c=c<<8|r[f],s+=8;s>t;)s-=t,i+=e[o&c>>s];if(s!==0&&(i+=e[o&c<<t-s]),n)for(;i.length*t&7;)i+="=";return i}function N({name:r,prefix:e,bitsPerChar:t,alphabet:n}){return Ne({prefix:e,name:r,encode(o){return ls(o,n,t)},decode(o){return fs(o,n,t,r)}})}var oe=N({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),hs=N({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),ds=N({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),ps=N({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),ms=N({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),gs=N({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),ys=N({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),ws=N({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),bs=N({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var yr={};M(yr,{base58btc:()=>W,base58flickr:()=>xs});var W=me({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),xs=me({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var wr={};M(wr,{base64:()=>ge,base64pad:()=>Es,base64url:()=>vs,base64urlpad:()=>ks});var ge=N({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Es=N({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),vs=N({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),ks=N({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});function As(r,e){try{if(typeof r=="string"&&r.length>0)return Cs(r);if(typeof r=="number"&&isFinite(r))return e?.long?Ts(r):_s(r);throw new Error("Value is not a string or number.")}catch(t){let n=Ss(t)?`${t.message}. value=${JSON.stringify(r)}`:"An unknown error has occured.";throw new Error(n)}}function Cs(r){if(r=String(r),r.length>100)throw new Error("Value exceeds the maximum length of 100 characters.");let 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)return NaN;let t=parseFloat(e[1]),n=(e[2]||"ms").toLowerCase();switch(n){case"years":case"year":case"yrs":case"yr":case"y":return t*315576e5;case"weeks":case"week":case"w":return t*6048e5;case"days":case"day":case"d":return t*864e5;case"hours":case"hour":case"hrs":case"hr":case"h":return t*36e5;case"minutes":case"minute":case"mins":case"min":case"m":return t*6e4;case"seconds":case"second":case"secs":case"sec":case"s":return t*1e3;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return t;default:throw new Error(`The unit ${n} was matched, but no matching case exists.`)}}var xt=As;function _s(r){let e=Math.abs(r);return e>=864e5?`${Math.round(r/864e5)}d`:e>=36e5?`${Math.round(r/36e5)}h`:e>=6e4?`${Math.round(r/6e4)}m`:e>=1e3?`${Math.round(r/1e3)}s`:`${r}ms`}function Ts(r){let e=Math.abs(r);return e>=864e5?bt(r,e,864e5,"day"):e>=36e5?bt(r,e,36e5,"hour"):e>=6e4?bt(r,e,6e4,"minute"):e>=1e3?bt(r,e,1e3,"second"):`${r} ms`}function bt(r,e,t,n){let o=e>=t*1.5;return`${Math.round(r/t)} ${n}${o?"s":""}`}function Ss(r){return typeof r=="object"&&r!==null&&"message"in r}function br(r){t.debug=t,t.default=t,t.coerce=f,t.disable=i,t.enable=o,t.enabled=s,t.humanize=xt,t.destroy=p,Object.keys(r).forEach(h=>{t[h]=r[h]}),t.names=[],t.skips=[],t.formatters={};function e(h){let l=0;for(let C=0;C<h.length;C++)l=(l<<5)-l+h.charCodeAt(C),l|=0;return t.colors[Math.abs(l)%t.colors.length]}t.selectColor=e;function t(h){let l,C=null,a,d;function m(...A){if(!m.enabled)return;let y=m,w=Number(new Date),x=w-(l||w);y.diff=x,y.prev=l,y.curr=w,l=w,A[0]=t.coerce(A[0]),typeof A[0]!="string"&&A.unshift("%O");let E=0;A[0]=A[0].replace(/%([a-zA-Z%])/g,(T,v)=>{if(T==="%%")return"%";E++;let L=t.formatters[v];if(typeof L=="function"){let Q=A[E];T=L.call(y,Q),A.splice(E,1),E--}return T}),t.formatArgs.call(y,A),(y.log||t.log).apply(y,A)}return m.namespace=h,m.useColors=t.useColors(),m.color=t.selectColor(h),m.extend=n,m.destroy=t.destroy,Object.defineProperty(m,"enabled",{enumerable:!0,configurable:!1,get:()=>C!==null?C:(a!==t.namespaces&&(a=t.namespaces,d=t.enabled(h)),d),set:A=>{C=A}}),typeof t.init=="function"&&t.init(m),m}function n(h,l){let C=t(this.namespace+(typeof l>"u"?":":l)+h);return C.log=this.log,C}function o(h){t.save(h),t.namespaces=h,t.names=[],t.skips=[];let l,C=(typeof h=="string"?h:"").split(/[\s,]+/),a=C.length;for(l=0;l<a;l++)C[l]&&(h=C[l].replace(/\*/g,".*?"),h[0]==="-"?t.skips.push(new RegExp("^"+h.substr(1)+"$")):t.names.push(new RegExp("^"+h+"$")))}function i(){let h=[...t.names.map(c),...t.skips.map(c).map(l=>"-"+l)].join(",");return t.enable(""),h}function s(h){if(h[h.length-1]==="*")return!0;let l,C;for(l=0,C=t.skips.length;l<C;l++)if(t.skips[l].test(h))return!1;for(l=0,C=t.names.length;l<C;l++)if(t.names[l].test(h))return!0;return!1}function c(h){return h.toString().substring(2,h.toString().length-2).replace(/\.\*\?$/,"*")}function f(h){return h instanceof Error?h.stack??h.message:h}function p(){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.setupFormatters(t.formatters),t.enable(t.load()),t}var Et=Ps(),Ls=["#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 Is(){return typeof window<"u"&&window.process&&(window.process.type==="renderer"||window.process.__nwjs)?!0:typeof navigator<"u"&&navigator.userAgent?.toLowerCase().match(/(edge|trident)\/(\d+)/)!=null?!1:typeof document<"u"&&document.documentElement?.style?.WebkitAppearance||typeof window<"u"&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||typeof navigator<"u"&&navigator.userAgent?.toLowerCase().match(/firefox\/(\d+)/)!=null&&parseInt(RegExp.$1,10)>=31||typeof navigator<"u"&&navigator.userAgent?.toLowerCase().match(/applewebkit\/(\d+)/)}function Ds(r){if(r[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+r[0]+(this.useColors?"%c ":" ")+"+"+xt(this.diff),!this.useColors)return;let e="color: "+this.color;r.splice(1,0,e,"color: inherit");let t=0,n=0;r[0].replace(/%[a-zA-Z%]/g,o=>{o!=="%%"&&(t++,o==="%c"&&(n=t))}),r.splice(n,0,e)}var Ns=console.debug??console.log??(()=>{});function Bs(r){try{r?Et?.setItem("debug",r):Et?.removeItem("debug")}catch{}}function Us(){let r;try{r=Et?.getItem("debug")}catch{}return!r&&typeof process<"u"&&"env"in process&&(r=process.env.DEBUG),r}function Ps(){try{return localStorage}catch{}}function Rs(r){r.j=function(e){try{return JSON.stringify(e)}catch(t){return"[UnexpectedJSONParseError]: "+t.message}}}var Pn=br({formatArgs:Ds,save:Bs,load:Us,useColors:Is,setupFormatters:Rs,colors:Ls,storage:Et,log:Ns});var z=Pn;z.formatters.b=r=>r==null?"undefined":W.baseEncode(r);z.formatters.t=r=>r==null?"undefined":oe.baseEncode(r);z.formatters.m=r=>r==null?"undefined":ge.baseEncode(r);z.formatters.p=r=>r==null?"undefined":r.toString();z.formatters.c=r=>r==null?"undefined":r.toString();z.formatters.k=r=>r==null?"undefined":r.toString();z.formatters.a=r=>r==null?"undefined":r.toString();function Os(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 Rn(){return{forComponent(r){return xr(r)}}}function xr(r){let e=Os(`${r}:trace`);return z.enabled(`${r}:trace`)&&z.names.map(t=>t.toString()).find(t=>t.includes(":trace"))!=null&&(e=z(`${r}:trace`)),Object.assign(z(r),{error:z(`${r}:error`),trace:e})}var D=class extends Event{type;detail;constructor(e,t){super(e),this.type=e,this.detail=t}};var vr=wt(Fn(),1);var Ye=class extends Error{constructor(e){super(e),this.name="TimeoutError"}},kr=class extends Error{constructor(e){super(),this.name="AbortError",this.message=e}},$n=r=>globalThis.DOMException===void 0?new kr(r):new DOMException(r),Mn=r=>{let e=r.reason===void 0?$n("This operation was aborted."):r.reason;return e instanceof Error?e:$n(e)};function Ze(r,e){let{milliseconds:t,fallback:n,message:o,customTimers:i={setTimeout,clearTimeout}}=e,s,f=new Promise((p,h)=>{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:C}=e;C.aborted&&h(Mn(C)),C.addEventListener("abort",()=>{h(Mn(C))})}if(t===Number.POSITIVE_INFINITY){r.then(p,h);return}let l=new Ye;s=i.setTimeout.call(void 0,()=>{if(n){try{p(n())}catch(C){h(C)}return}typeof r.cancel=="function"&&r.cancel(),o===!1?p():o instanceof Error?h(o):(l.message=o??`Promise timed out after ${t} milliseconds`,h(l))},t),(async()=>{try{p(await r)}catch(C){h(C)}})()}).finally(()=>{f.clear()});return f.clear=()=>{i.clearTimeout.call(void 0,s),s=void 0},f}function Ar(r,e,t){let n=0,o=r.length;for(;o>0;){let i=Math.trunc(o/2),s=n+i;t(r[s],e)<=0?(n=++s,o-=i+1):o=i}return n}var et=class{#e=[];enqueue(e,t){t={priority:0,...t};let n={priority:t.priority,run:e};if(this.size&&this.#e[this.size-1].priority>=t.priority){this.#e.push(n);return}let o=Ar(this.#e,n,(i,s)=>s.priority-i.priority);this.#e.splice(o,0,n)}dequeue(){return this.#e.shift()?.run}filter(e){return this.#e.filter(t=>t.priority===e.priority).map(t=>t.run)}get size(){return this.#e.length}};var ye=class extends vr.default{#e;#o;#s=0;#d;#a;#p=0;#r;#c;#t;#m;#n=0;#u;#i;#g;timeout;constructor(e){if(super(),e={carryoverConcurrencyCount:!1,intervalCap:Number.POSITIVE_INFINITY,interval:0,concurrency:Number.POSITIVE_INFINITY,autoStart:!0,queueClass:et,...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.#o=e.intervalCap===Number.POSITIVE_INFINITY||e.interval===0,this.#d=e.intervalCap,this.#a=e.interval,this.#t=new e.queueClass,this.#m=e.queueClass,this.concurrency=e.concurrency,this.timeout=e.timeout,this.#g=e.throwOnTimeout===!0,this.#i=e.autoStart===!1}get#b(){return this.#o||this.#s<this.#d}get#x(){return this.#n<this.#u}#E(){this.#n--,this.#f(),this.emit("next")}#v(){this.#w(),this.#y(),this.#c=void 0}get#k(){let e=Date.now();if(this.#r===void 0){let t=this.#p-e;if(t<0)this.#s=this.#e?this.#n:0;else return this.#c===void 0&&(this.#c=setTimeout(()=>{this.#v()},t)),!0}return!1}#f(){if(this.#t.size===0)return this.#r&&clearInterval(this.#r),this.#r=void 0,this.emit("empty"),this.#n===0&&this.emit("idle"),!1;if(!this.#i){let e=!this.#k;if(this.#b&&this.#x){let t=this.#t.dequeue();return t?(this.emit("active"),t(),e&&this.#y(),!0):!1}}return!1}#y(){this.#o||this.#r!==void 0||(this.#r=setInterval(()=>{this.#w()},this.#a),this.#p=Date.now()+this.#a)}#w(){this.#s===0&&this.#n===0&&this.#r&&(clearInterval(this.#r),this.#r=void 0),this.#s=this.#e?this.#n:0,this.#l()}#l(){for(;this.#f(););}get concurrency(){return this.#u}set concurrency(e){if(!(typeof e=="number"&&e>=1))throw new TypeError(`Expected \`concurrency\` to be a number from 1 and up, got \`${e}\` (${typeof e})`);this.#u=e,this.#l()}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.#g,...t},new Promise((n,o)=>{this.#t.enqueue(async()=>{this.#n++,this.#s++;try{t.signal?.throwIfAborted();let i=e({signal:t.signal});t.timeout&&(i=Ze(Promise.resolve(i),{milliseconds:t.timeout})),t.signal&&(i=Promise.race([i,this.#A(t.signal)]));let s=await i;n(s),this.emit("completed",s)}catch(i){if(i instanceof Ye&&!t.throwOnTimeout){n();return}o(i),this.emit("error",i)}finally{this.#E()}},t),this.emit("add"),this.#f()})}async addAll(e,t){return Promise.all(e.map(async n=>this.add(n,t)))}start(){return this.#i?(this.#i=!1,this.#l(),this):this}pause(){this.#i=!0}clear(){this.#t=new this.#m}async onEmpty(){this.#t.size!==0&&await this.#h("empty")}async onSizeLessThan(e){this.#t.size<e||await this.#h("next",()=>this.#t.size<e)}async onIdle(){this.#n===0&&this.#t.size===0||await this.#h("idle")}async#h(e,t){return new Promise(n=>{let o=()=>{t&&!t()||(this.off(e,o),n())};this.on(e,o)})}get size(){return this.#t.size}sizeBy(e){return this.#t.filter(e).length}get pending(){return this.#n}get isPaused(){return this.#i}};function kt(r){let e=[J.A];return r==null?e:Array.isArray(r)?r.length===0?e:r:[r]}var Cr={};M(Cr,{base10:()=>Ms});var Ms=me({prefix:"9",name:"base10",alphabet:"0123456789"});var _r={};M(_r,{base16:()=>zs,base16upper:()=>Vs});var zs=N({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Vs=N({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Tr={};M(Tr,{base2:()=>qs});var qs=N({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Sr={};M(Sr,{base256emoji:()=>Ks});var zn=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}"),js=zn.reduce((r,e,t)=>(r[t]=e,r),[]),Hs=zn.reduce((r,e,t)=>(r[e.codePointAt(0)]=t,r),[]);function Ws(r){return r.reduce((e,t)=>(e+=js[t],e),"")}function Gs(r){let e=[];for(let t of r){let n=Hs[t.codePointAt(0)];if(n===void 0)throw new Error(`Non-base256emoji character: ${t}`);e.push(n)}return new Uint8Array(e)}var Ks=Ne({prefix:"\u{1F680}",name:"base256emoji",encode:Ws,decode:Gs});var Lr={};M(Lr,{base36:()=>ie,base36upper:()=>Qs});var ie=me({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Qs=me({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Ir={};M(Ir,{base8:()=>Js});var Js=N({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Dr={};M(Dr,{identity:()=>Xs});var Xs=Ne({prefix:"\0",name:"identity",encode:r=>Dn(r),decode:r=>In(r)});var zu=new TextEncoder,Vu=new TextDecoder;var Vn=512;var Nr=85;var Or={};M(Or,{identity:()=>Rr});var Ys=Wn,jn=128,Zs=127,ea=~Zs,ta=Math.pow(2,31);function Wn(r,e,t){e=e||[],t=t||0;for(var n=t;r>=ta;)e[t++]=r&255|jn,r/=128;for(;r&ea;)e[t++]=r&255|jn,r>>>=7;return e[t]=r|0,Wn.bytes=t-n+1,e}var ra=Ur,na=128,Hn=127;function Ur(r,n){var t=0,n=n||0,o=0,i=n,s,c=r.length;do{if(i>=c)throw Ur.bytes=0,new RangeError("Could not decode varint");s=r[i++],t+=o<28?(s&Hn)<<o:(s&Hn)*Math.pow(2,o),o+=7}while(s>=na);return Ur.bytes=i-n,t}var oa=Math.pow(2,7),ia=Math.pow(2,14),sa=Math.pow(2,21),aa=Math.pow(2,28),ca=Math.pow(2,35),ua=Math.pow(2,42),fa=Math.pow(2,49),la=Math.pow(2,56),ha=Math.pow(2,63),da=function(r){return r<oa?1:r<ia?2:r<sa?3:r<aa?4:r<ca?5:r<ua?6:r<fa?7:r<la?8:r<ha?9:10},pa={encode:Ys,decode:ra,encodingLength:da},ma=pa,tt=ma;function rt(r,e=0){return[tt.decode(r,e),tt.decode.bytes]}function Be(r,e,t=0){return tt.encode(r,e,t),e}function Ue(r){return tt.encodingLength(r)}function ke(r,e){let t=e.byteLength,n=Ue(r),o=n+Ue(t),i=new Uint8Array(o+t);return Be(r,i,0),Be(t,i,n),i.set(e,o),new Pe(r,t,e,i)}function Pr(r){let e=ne(r),[t,n]=rt(e),[o,i]=rt(e.subarray(n)),s=e.subarray(n+i);if(s.byteLength!==o)throw new Error("Incorrect length");return new Pe(t,o,s,e)}function Gn(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&Ln(r.bytes,t.bytes)}}var Pe=class{code;size;digest;bytes;constructor(e,t,n,o){this.code=e,this.size=t,this.digest=n,this.bytes=o}};var Kn=0,ga="identity",Qn=ne;function ya(r){return ke(Kn,Qn(r))}var Rr={code:Kn,name:ga,encode:Qn,digest:ya};var Vr={};M(Vr,{sha256:()=>Mr,sha512:()=>zr});function $r({name:r,code:e,encode:t}){return new Fr(r,e,t)}var Fr=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?ke(this.code,t):t.then(n=>ke(this.code,n))}else throw Error("Unknown type, must be binary type")}};function Xn(r){return async e=>new Uint8Array(await crypto.subtle.digest(r,e))}var Mr=$r({name:"sha2-256",code:18,encode:Xn("SHA-256")}),zr=$r({name:"sha2-512",code:19,encode:Xn("SHA-512")});function Yn(r,e){let{bytes:t,version:n}=r;switch(n){case 0:return ba(t,qr(r),e??W.encoder);default:return xa(t,qr(r),e??oe.encoder)}}var Zn=new WeakMap;function qr(r){let e=Zn.get(r);if(e==null){let t=new Map;return Zn.set(r,t),t}return e}var B=class r{code;version;multihash;bytes;"/";constructor(e,t,n,o){this.code=t,this.version=e,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:e,multihash:t}=this;if(e!==nt)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==Ea)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=ke(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&&Gn(e.multihash,n.multihash)}toString(e){return Yn(this,e)}toJSON(){return{"/":Yn(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(e){if(e==null)return null;let t=e;if(t instanceof r)return t;if(t["/"]!=null&&t["/"]===t.bytes||t.asCID===t){let{version:n,code:o,multihash:i,bytes:s}=t;return new r(n,o,i,s??eo(n,o,i.bytes))}else if(t[va]===!0){let{version:n,multihash:o,code:i}=t,s=Pr(o);return r.create(n,i,s)}else return null}static create(e,t,n){if(typeof t!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(e){case 0:{if(t!==nt)throw new Error(`Version 0 CID must use dag-pb (code: ${nt}) block encoding`);return new r(e,t,n,n.bytes)}case 1:{let o=eo(e,t,n.bytes);return new r(e,t,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return r.create(0,nt,e)}static createV1(e,t){return r.create(1,e,t)}static decode(e){let[t,n]=r.decodeFirst(e);if(n.length!==0)throw new Error("Incorrect length");return t}static decodeFirst(e){let t=r.inspectBytes(e),n=t.size-t.multihashSize,o=ne(e.subarray(n,n+t.multihashSize));if(o.byteLength!==t.multihashSize)throw new Error("Incorrect length");let i=o.subarray(t.multihashSize-t.digestSize),s=new Pe(t.multihashCode,t.digestSize,i,o);return[t.version===0?r.createV0(s):r.createV1(t.codec,s),e.subarray(t.size)]}static inspectBytes(e){let t=0,n=()=>{let[l,C]=rt(e.subarray(t));return t+=C,l},o=n(),i=nt;if(o===18?(o=0,t=0):i=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let s=t,c=n(),f=n(),p=t+f,h=p-s;return{version:o,codec:i,multihashCode:c,digestSize:f,multihashSize:h,size:p}}static parse(e,t){let[n,o]=wa(e,t),i=r.decode(o);if(i.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return qr(i).set(n,e),i}};function wa(r,e){switch(r[0]){case"Q":{let t=e??W;return[W.prefix,t.decode(`${W.prefix}${r}`)]}case W.prefix:{let t=e??W;return[W.prefix,t.decode(r)]}case oe.prefix:{let t=e??oe;return[oe.prefix,t.decode(r)]}case ie.prefix:{let t=e??ie;return[ie.prefix,t.decode(r)]}default:{if(e==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[r[0],e.decode(r)]}}}function ba(r,e,t){let{prefix:n}=t;if(n!==W.prefix)throw Error(`Cannot string encode V0 in ${t.name} encoding`);let o=e.get(n);if(o==null){let i=t.encode(r).slice(1);return e.set(n,i),i}else return o}function xa(r,e,t){let{prefix:n}=t,o=e.get(n);if(o==null){let i=t.encode(r);return e.set(n,i),i}else return o}var nt=112,Ea=18;function eo(r,e,t){let n=Ue(r),o=n+Ue(e),i=new Uint8Array(o+t.byteLength);return Be(r,i,0),Be(e,i,n),i.set(t,o),i}var va=Symbol.for("@ipld/js-cid/CID");var jr={...Dr,...Tr,...Ir,...Cr,..._r,...gr,...Lr,...yr,...wr,...Sr},lf={...Vr,...Or};function X(r=0){return new Uint8Array(r)}function Ae(r=0){return new Uint8Array(r)}function ro(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}var to=ro("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Hr=ro("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=Ae(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),ka={utf8:to,"utf-8":to,hex:jr.base16,latin1:Hr,ascii:Hr,binary:Hr,...jr},Ct=ka;function Oe(r,e="utf8"){let t=Ct[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.encoder.encode(r).substring(1)}var Wr=60;function _t(r){return{Status:r.Status??0,TC:r.TC??r.flag_tc??!1,RD:r.RD??r.flag_rd??!1,RA:r.RA??r.flag_ra??!1,AD:r.AD??r.flag_ad??!1,CD:r.CD??r.flag_cd??!1,Question:(r.Question??r.questions??[]).map(e=>({name:e.name,type:J[e.type]})),Answer:(r.Answer??r.answers??[]).map(e=>({name:e.name,type:J[e.type],TTL:e.TTL??e.ttl??Wr,data:e.data instanceof Uint8Array?Oe(e.data):e.data}))}}var Aa=4;function Gr(r,e={}){let t=new ye({concurrency:e.queryConcurrency??Aa});return async(n,o={})=>{let i=new URLSearchParams;i.set("name",n),kt(o.types).forEach(c=>{i.append("type",J[c])}),o.onProgress?.(new D("dns:query",{detail:n}));let s=await t.add(async()=>{let c=await fetch(`${r}?${i}`,{headers:{accept:"application/dns-json"},signal:o?.signal});if(c.status!==200)throw new Error(`Unexpected HTTP status: ${c.status} - ${c.statusText}`);let f=_t(await c.json());return o.onProgress?.(new D("dns:response",{detail:f})),f},{signal:o.signal});if(s==null)throw new Error("No DNS response received");return s}}function no(){return[Gr("https://cloudflare-dns.com/dns-query"),Gr("https://dns.google/resolve")]}var so=wt(io(),1);var Kr=class{lru;constructor(e){this.lru=(0,so.default)(e)}get(e,t){let n=!0,o=[];for(let i of t){let s=this.getAnswers(e,i);if(s.length===0){n=!1;break}o.push(...s)}if(n)return _t({answers:o})}getAnswers(e,t){let n=`${e.toLowerCase()}-${t}`,o=this.lru.get(n);if(o!=null){let i=o.filter(s=>s.expires>Date.now()).map(({expires:s,value:c})=>({...c,TTL:Math.round((s-Date.now())/1e3),type:J[c.type]}));return i.length===0&&this.lru.remove(n),i}return[]}add(e,t){let n=`${e.toLowerCase()}-${t.type}`,o=this.lru.get(n)??[];o.push({expires:Date.now()+(t.TTL??Wr)*1e3,value:t}),this.lru.set(n,o)}remove(e,t){let n=`${e.toLowerCase()}-${t}`;this.lru.remove(n)}clear(){this.lru.clear()}};function ao(r){return new Kr(r)}var Ca=1e3,Tt=class{resolvers;cache;constructor(e){this.resolvers={},this.cache=ao(e.cacheSize??Ca),Object.entries(e.resolvers??{}).forEach(([t,n])=>{Array.isArray(n)||(n=[n]),t.endsWith(".")||(t=`${t}.`),this.resolvers[t]=n}),this.resolvers["."]==null&&(this.resolvers["."]=no())}async query(e,t={}){let n=kt(t.types),o=t.cached!==!1?this.cache.get(e,n):void 0;if(o!=null)return t.onProgress?.(new D("dns:cache",{detail:o})),o;let i=`${e.split(".").pop()}.`,s=(this.resolvers[i]??this.resolvers["."]).sort(()=>Math.random()>.5?-1:1),c=[];for(let f of s){if(t.signal?.aborted===!0)break;try{let p=await f(e,{...t,types:n});for(let h of p.Answer)this.cache.add(e,h);return p}catch(p){c.push(p),t.onProgress?.(new D("dns:error",{detail:p}))}}throw c.length===1?c[0]:new AggregateError(c,`DNS lookup of ${e} ${n} failed`)}};var J;(function(r){r[r.A=1]="A",r[r.CNAME=5]="CNAME",r[r.TXT=16]="TXT",r[r.AAAA=28]="AAAA"})(J||(J={}));function co(r={}){return new Tt(r)}function _a(r){return r[Symbol.asyncIterator]!=null}function Ta(r){if(_a(r))return(async()=>{for await(let e of r);})();for(let e of r);}var Qr=Ta;function se(){let r={};return r.promise=new Promise((e,t)=>{r.resolve=e,r.reject=t}),r}var St=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}},Fe=class{size;hwm;head;tail;constructor(e={}){this.hwm=e.splitLimit??16,this.head=new St(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 St(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 Jr=class extends Error{type;code;constructor(e,t){super(e??"The operation was aborted"),this.type="aborted",this.code=t??"ABORT_ERR"}};function ot(r={}){return Sa(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 Sa(r,e){e=e??{};let t=e.onEnd,n=new Fe,o,i,s,c=se(),f=async()=>{try{return n.isEmpty()?s?{done:!0}:await new Promise((A,y)=>{i=w=>{i=null,n.push(w);try{A(r(n))}catch(x){y(x)}return o}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{c.resolve(),c=se()})}},p=A=>i!=null?i(A):(n.push(A),o),h=A=>(n=new Fe,i!=null?i({error:A}):(n.push({error:A}),o)),l=A=>{if(s)return o;if(e?.objectMode!==!0&&A?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return p({done:!1,value:A})},C=A=>s?o:(s=!0,A!=null?h(A):p({done:!0})),a=()=>(n=new Fe,C(),{done:!0}),d=A=>(C(A),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:f,return:a,throw:d,push:l,end:C,get readableLength(){return n.size},onEmpty:async A=>{let y=A?.signal;if(y?.throwIfAborted(),n.isEmpty())return;let w,x;y!=null&&(w=new Promise((E,_)=>{x=()=>{_(new Jr)},y.addEventListener("abort",x)}));try{await Promise.race([c.promise,w])}finally{x!=null&&y!=null&&y?.removeEventListener("abort",x)}}},t==null)return o;let m=o;return o={[Symbol.asyncIterator](){return this},next(){return m.next()},throw(A){return m.throw(A),t!=null&&(t(A),t=void 0),{done:!0}},return(){return m.return(),t!=null&&(t(),t=void 0),{done:!0}},push:l,end(A){return m.end(A),t!=null&&(t(A),t=void 0),o},get readableLength(){return m.readableLength},onEmpty:A=>m.onEmpty(A)},o}var Xr=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 Lt(r,e,t,n){let o=new Xr(n?.errorMessage,n?.errorCode);return t?.aborted===!0?Promise.reject(o):new Promise((i,s)=>{function c(){t?.removeEventListener("abort",h),r.removeEventListener(e,f),n?.errorEvent!=null&&r.removeEventListener(n.errorEvent,p)}let f=l=>{try{if(n?.filter?.(l)===!1)return}catch(C){c(),s(C);return}c(),i(l)},p=l=>{c(),s(l.detail)},h=()=>{c(),s(o)};t?.addEventListener("abort",h),r.addEventListener(e,f),n?.errorEvent!=null&&r.addEventListener(n.errorEvent,p)})}var It=class extends Error{type;code;constructor(e,t,n){super(e??"The operation was aborted"),this.type="aborted",this.name=n??"AbortError",this.code=t??"ABORT_ERR"}};async function uo(r,e,t){if(e==null)return r;if(e.aborted)return Promise.reject(new It(t?.errorMessage,t?.errorCode,t?.errorName));let n,o=new It(t?.errorMessage,t?.errorCode,t?.errorName);try{return await Promise.race([r,new Promise((i,s)=>{n=()=>{s(o)},e.addEventListener("abort",n)})])}finally{n!=null&&e.removeEventListener("abort",n)}}var Dt=class{deferred;signal;constructor(e){this.signal=e,this.deferred=se(),this.onAbort=this.onAbort.bind(this),this.signal?.addEventListener("abort",this.onAbort)}onAbort(){this.deferred.reject(this.signal?.reason??new he)}cleanup(){this.signal?.removeEventListener("abort",this.onAbort)}};function La(){return`${parseInt(String(Math.random()*1e9),10).toString()}${Date.now()}`}var Nt=class{id;fn;options;recipients;status;timeline;controller;constructor(e,t){this.id=La(),this.status="queued",this.fn=e,this.options=t,this.recipients=[],this.timeline={created:Date.now()},this.controller=new AbortController,R(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 he),this.cleanup())}async join(e={}){let t=new Dt(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 uo(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.cleanup(),e.signal?.removeEventListener("abort",this.onAbort)})}};var ae=class extends De{concurrency;queue;pending;sort;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.sort=e.sort,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){this.queue.push(e),this.sort!=null&&this.queue.sort(this.sort)}async add(e,t){t?.signal?.throwIfAborted();let n=new Nt(e,t);return this.enqueue(n),this.safeDispatchEvent("add"),this.tryToStartAnother(),n.join(t).then(o=>(this.safeDispatchEvent("completed",{detail:o}),this.safeDispatchEvent("success",{detail:{job:n,result:o}}),o)).catch(o=>{if(n.status==="queued"){for(let i=0;i<this.queue.length;i++)if(this.queue[i]===n){this.queue.splice(i,1);break}}throw this.safeDispatchEvent("error",{detail:o}),this.safeDispatchEvent("failure",{detail:{job:n,error:o}}),o})}clear(){this.queue.splice(0,this.queue.length)}abort(){this.queue.forEach(e=>{e.abort(new he)}),this.clear()}async onEmpty(e){this.size!==0&&await Lt(this,"empty",e?.signal)}async onSizeLessThan(e,t){this.size<e||await Lt(this,"next",t?.signal,{filter:()=>this.size<e})}async onIdle(e){this.pending===0&&this.size===0||await Lt(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=ot({objectMode:!0}),n=f=>{f!=null?this.abort():this.clear(),t.end(f)},o=f=>{f.detail!=null&&t.push(f.detail)},i=f=>{n(f.detail)},s=()=>{n()},c=()=>{n(new P("Queue aborted","ERR_QUEUE_ABORTED"))};this.addEventListener("completed",o),this.addEventListener("error",i),this.addEventListener("idle",s),e?.signal?.addEventListener("abort",c);try{yield*t}finally{this.removeEventListener("completed",o),this.removeEventListener("error",i),this.removeEventListener("idle",s),e?.signal?.removeEventListener("abort",c),n()}}};var Ia=["string","number","bigint","symbol"],Da=["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 fo(r){if(r===null)return"null";if(r===void 0)return"undefined";if(r===!0||r===!1)return"boolean";let e=typeof r;if(Ia.includes(e))return e;if(e==="function")return"Function";if(Array.isArray(r))return"Array";if(Na(r))return"Buffer";let t=Ba(r);return t||"Object"}function Na(r){return r&&r.constructor&&r.constructor.isBuffer&&r.constructor.isBuffer.call(null,r)}function Ba(r){let e=Object.prototype.toString.call(r).slice(8,-1);if(Da.includes(e))return e}var u=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}};u.uint=new u(0,"uint",!0);u.negint=new u(1,"negint",!0);u.bytes=new u(2,"bytes",!0);u.string=new u(3,"string",!0);u.array=new u(4,"array",!1);u.map=new u(5,"map",!1);u.tag=new u(6,"tag",!1);u.float=new u(7,"float",!0);u.false=new u(7,"false",!0);u.true=new u(7,"true",!0);u.null=new u(7,"null",!0);u.undefined=new u(7,"undefined",!0);u.break=new u(7,"break",!0);var g=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 $e=globalThis.process&&!globalThis.process.browser&&globalThis.Buffer&&typeof globalThis.Buffer.isBuffer=="function",Ua=new TextDecoder,Pa=new TextEncoder;function Bt(r){return $e&&globalThis.Buffer.isBuffer(r)}function it(r){return r instanceof Uint8Array?Bt(r)?new Uint8Array(r.buffer,r.byteOffset,r.byteLength):r:Uint8Array.from(r)}var mo=$e?(r,e,t)=>t-e>64?globalThis.Buffer.from(r.subarray(e,t)).toString("utf8"):ho(r,e,t):(r,e,t)=>t-e>64?Ua.decode(r.subarray(e,t)):ho(r,e,t),Ut=$e?r=>r.length>64?globalThis.Buffer.from(r):lo(r):r=>r.length>64?Pa.encode(r):lo(r),ee=r=>Uint8Array.from(r),Me=$e?(r,e,t)=>Bt(r)?new Uint8Array(r.subarray(e,t)):r.slice(e,t):(r,e,t)=>r.slice(e,t),go=$e?(r,e)=>(r=r.map(t=>t instanceof Uint8Array?t:globalThis.Buffer.from(t)),it(globalThis.Buffer.concat(r,e))):(r,e)=>{let t=new Uint8Array(e),n=0;for(let o of r)n+o.length>t.length&&(o=o.subarray(0,t.length-n)),t.set(o,n),n+=o.length;return t},yo=$e?r=>globalThis.Buffer.allocUnsafe(r):r=>new Uint8Array(r);function wo(r,e){if(Bt(r)&&Bt(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 lo(r){let e=[],t=0;for(let n=0;n<r.length;n++){let o=r.charCodeAt(n);o<128?e[t++]=o:o<2048?(e[t++]=o>>6|192,e[t++]=o&63|128):(o&64512)===55296&&n+1<r.length&&(r.charCodeAt(n+1)&64512)===56320?(o=65536+((o&1023)<<10)+(r.charCodeAt(++n)&1023),e[t++]=o>>18|240,e[t++]=o>>12&63|128,e[t++]=o>>6&63|128,e[t++]=o&63|128):(e[t++]=o>>12|224,e[t++]=o>>6&63|128,e[t++]=o&63|128)}return e}function ho(r,e,t){let n=[];for(;e<t;){let o=r[e],i=null,s=o>239?4:o>223?3:o>191?2:1;if(e+s<=t){let c,f,p,h;switch(s){case 1:o<128&&(i=o);break;case 2:c=r[e+1],(c&192)===128&&(h=(o&31)<<6|c&63,h>127&&(i=h));break;case 3:c=r[e+1],f=r[e+2],(c&192)===128&&(f&192)===128&&(h=(o&15)<<12|(c&63)<<6|f&63,h>2047&&(h<55296||h>57343)&&(i=h));break;case 4:c=r[e+1],f=r[e+2],p=r[e+3],(c&192)===128&&(f&192)===128&&(p&192)===128&&(h=(o&15)<<18|(c&63)<<12|(f&63)<<6|p&63,h>65535&&h<1114112&&(i=h))}}i===null?(i=65533,s=1):i>65535&&(i-=65536,n.push(i>>>10&1023|55296),i=56320|i&1023),n.push(i),e+=s}return Yr(n)}var po=4096;function Yr(r){let e=r.length;if(e<=po)return String.fromCharCode.apply(String,r);let t="",n=0;for(;n<e;)t+=String.fromCharCode.apply(String,r.slice(n,n+=po));return t}var Ra=256,st=class{constructor(e=Ra){this.chunkSize=e,this.cursor=0,this.maxCursor=-1,this.chunks=[],this._initReuseChunk=null}reset(){this.cursor=0,this.maxCursor=-1,this.chunks.length&&(this.chunks=[]),this._initReuseChunk!==null&&(this.chunks.push(this._initReuseChunk),this.maxCursor=this._initReuseChunk.length-1)}push(e){let t=this.chunks[this.chunks.length-1];if(this.cursor+e.length<=this.maxCursor+1){let o=t.length-(this.maxCursor-this.cursor)-1;t.set(e,o)}else{if(t){let o=t.length-(this.maxCursor-this.cursor)-1;o<t.length&&(this.chunks[this.chunks.length-1]=t.subarray(0,o),this.maxCursor=this.cursor-1)}e.length<64&&e.length<this.chunkSize?(t=yo(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=Me(n,0,this.cursor)}else t=go(this.chunks,this.cursor);return e&&this.reset(),t}};var k="CBOR decode error:",ze="CBOR encode error:",at=[];at[23]=1;at[24]=2;at[25]=3;at[26]=5;at[27]=9;function ce(r,e,t){if(r.length-e<t)throw new Error(`${k} not enough data for type`)}var U=[24,256,65536,4294967296,BigInt("18446744073709551616")];function V(r,e,t){ce(r,e,1);let n=r[e];if(t.strict===!0&&n<U[0])throw new Error(`${k} integer encoded in more bytes than necessary (strict decode)`);return n}function q(r,e,t){ce(r,e,2);let n=r[e]<<8|r[e+1];if(t.strict===!0&&n<U[1])throw new Error(`${k} integer encoded in more bytes than necessary (strict decode)`);return n}function j(r,e,t){ce(r,e,4);let n=r[e]*16777216+(r[e+1]<<16)+(r[e+2]<<8)+r[e+3];if(t.strict===!0&&n<U[2])throw new Error(`${k} integer encoded in more bytes than necessary (strict decode)`);return n}function H(r,e,t){ce(r,e,8);let n=r[e]*16777216+(r[e+1]<<16)+(r[e+2]<<8)+r[e+3],o=r[e+4]*16777216+(r[e+5]<<16)+(r[e+6]<<8)+r[e+7],i=(BigInt(n)<<BigInt(32))+BigInt(o);if(t.strict===!0&&i<U[3])throw new Error(`${k} integer encoded in more bytes than necessary (strict decode)`);if(i<=Number.MAX_SAFE_INTEGER)return Number(i);if(t.allowBigInt===!0)return i;throw new Error(`${k} integers outside of the safe integer range are not supported`)}function bo(r,e,t,n){return new g(u.uint,V(r,e+1,n),2)}function xo(r,e,t,n){return new g(u.uint,q(r,e+1,n),3)}function Eo(r,e,t,n){return new g(u.uint,j(r,e+1,n),5)}function vo(r,e,t,n){return new g(u.uint,H(r,e+1,n),9)}function G(r,e){return O(r,0,e.value)}function O(r,e,t){if(t<U[0]){let n=Number(t);r.push([e|n])}else if(t<U[1]){let n=Number(t);r.push([e|24,n])}else if(t<U[2]){let n=Number(t);r.push([e|25,n>>>8,n&255])}else if(t<U[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<U[4]){let o=[e|27,0,0,0,0,0,0,0],i=Number(n&BigInt(4294967295)),s=Number(n>>BigInt(32)&BigInt(4294967295));o[8]=i&255,i=i>>8,o[7]=i&255,i=i>>8,o[6]=i&255,i=i>>8,o[5]=i&255,o[4]=s&255,s=s>>8,o[3]=s&255,s=s>>8,o[2]=s&255,s=s>>8,o[1]=s&255,r.push(o)}else throw new Error(`${k} encountered BigInt larger than allowable range`)}}G.encodedSize=function(e){return O.encodedSize(e.value)};O.encodedSize=function(e){return e<U[0]?1:e<U[1]?2:e<U[2]?3:e<U[3]?5:9};G.compareTokens=function(e,t){return e.value<t.value?-1:e.value>t.value?1:0};function ko(r,e,t,n){return new g(u.negint,-1-V(r,e+1,n),2)}function Ao(r,e,t,n){return new g(u.negint,-1-q(r,e+1,n),3)}function Co(r,e,t,n){return new g(u.negint,-1-j(r,e+1,n),5)}var Zr=BigInt(-1),_o=BigInt(1);function To(r,e,t,n){let o=H(r,e+1,n);if(typeof o!="bigint"){let i=-1-o;if(i>=Number.MIN_SAFE_INTEGER)return new g(u.negint,i,9)}if(n.allowBigInt!==!0)throw new Error(`${k} integers outside of the safe integer range are not supported`);return new g(u.negint,Zr-BigInt(o),9)}function Pt(r,e){let t=e.value,n=typeof t=="bigint"?t*Zr-_o:t*-1-1;O(r,e.type.majorEncoded,n)}Pt.encodedSize=function(e){let t=e.value,n=typeof t=="bigint"?t*Zr-_o:t*-1-1;return n<U[0]?1:n<U[1]?2:n<U[2]?3:n<U[3]?5:9};Pt.compareTokens=function(e,t){return e.value<t.value?1:e.value>t.value?-1:0};function ct(r,e,t,n){ce(r,e,t+n);let o=Me(r,e+t,e+t+n);return new g(u.bytes,o,t+n)}function So(r,e,t,n){return ct(r,e,1,t)}function Lo(r,e,t,n){return ct(r,e,2,V(r,e+1,n))}function Io(r,e,t,n){return ct(r,e,3,q(r,e+1,n))}function Do(r,e,t,n){return ct(r,e,5,j(r,e+1,n))}function No(r,e,t,n){let o=H(r,e+1,n);if(typeof o=="bigint")throw new Error(`${k} 64-bit integer bytes lengths not supported`);return ct(r,e,9,o)}function Rt(r){return r.encodedBytes===void 0&&(r.encodedBytes=r.type===u.string?Ut(r.value):r.value),r.encodedBytes}function Ve(r,e){let t=Rt(e);O(r,e.type.majorEncoded,t.length),r.push(t)}Ve.encodedSize=function(e){let t=Rt(e);return O.encodedSize(t.length)+t.length};Ve.compareTokens=function(e,t){return Fa(Rt(e),Rt(t))};function Fa(r,e){return r.length<e.length?-1:r.length>e.length?1:wo(r,e)}function ut(r,e,t,n,o){let i=t+n;ce(r,e,i);let s=new g(u.string,mo(r,e+t,e+i),i);return o.retainStringBytes===!0&&(s.byteValue=Me(r,e+t,e+i)),s}function Bo(r,e,t,n){return ut(r,e,1,t,n)}function Uo(r,e,t,n){return ut(r,e,2,V(r,e+1,n),n)}function Po(r,e,t,n){return ut(r,e,3,q(r,e+1,n),n)}function Ro(r,e,t,n){return ut(r,e,5,j(r,e+1,n),n)}function Oo(r,e,t,n){let o=H(r,e+1,n);if(typeof o=="bigint")throw new Error(`${k} 64-bit integer string lengths not supported`);return ut(r,e,9,o,n)}var Fo=Ve;function qe(r,e,t,n){return new g(u.array,n,t)}function $o(r,e,t,n){return qe(r,e,1,t)}function Mo(r,e,t,n){return qe(r,e,2,V(r,e+1,n))}function zo(r,e,t,n){return qe(r,e,3,q(r,e+1,n))}function Vo(r,e,t,n){return qe(r,e,5,j(r,e+1,n))}function qo(r,e,t,n){let o=H(r,e+1,n);if(typeof o=="bigint")throw new Error(`${k} 64-bit integer array lengths not supported`);return qe(r,e,9,o)}function jo(r,e,t,n){if(n.allowIndefinite===!1)throw new Error(`${k} indefinite length items not allowed`);return qe(r,e,1,1/0)}function Ot(r,e){O(r,u.array.majorEncoded,e.value)}Ot.compareTokens=G.compareTokens;Ot.encodedSize=function(e){return O.encodedSize(e.value)};function je(r,e,t,n){return new g(u.map,n,t)}function Ho(r,e,t,n){return je(r,e,1,t)}function Wo(r,e,t,n){return je(r,e,2,V(r,e+1,n))}function Go(r,e,t,n){return je(r,e,3,q(r,e+1,n))}function Ko(r,e,t,n){return je(r,e,5,j(r,e+1,n))}function Qo(r,e,t,n){let o=H(r,e+1,n);if(typeof o=="bigint")throw new Error(`${k} 64-bit integer map lengths not supported`);return je(r,e,9,o)}function Jo(r,e,t,n){if(n.allowIndefinite===!1)throw new Error(`${k} indefinite length items not allowed`);return je(r,e,1,1/0)}function Ft(r,e){O(r,u.map.majorEncoded,e.value)}Ft.compareTokens=G.compareTokens;Ft.encodedSize=function(e){return O.encodedSize(e.value)};function Xo(r,e,t,n){return new g(u.tag,t,1)}function Yo(r,e,t,n){return new g(u.tag,V(r,e+1,n),2)}function Zo(r,e,t,n){return new g(u.tag,q(r,e+1,n),3)}function ei(r,e,t,n){return new g(u.tag,j(r,e+1,n),5)}function ti(r,e,t,n){return new g(u.tag,H(r,e+1,n),9)}function $t(r,e){O(r,u.tag.majorEncoded,e.value)}$t.compareTokens=G.compareTokens;$t.encodedSize=function(e){return O.encodedSize(e.value)};var ja=20,Ha=21,Wa=22,Ga=23;function ri(r,e,t,n){if(n.allowUndefined===!1)throw new Error(`${k} undefined values are not supported`);return n.coerceUndefinedToNull===!0?new g(u.null,null,1):new g(u.undefined,void 0,1)}function ni(r,e,t,n){if(n.allowIndefinite===!1)throw new Error(`${k} indefinite length items not allowed`);return new g(u.break,void 0,1)}function en(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 g(u.float,r,e)}function oi(r,e,t,n){return en(tn(r,e+1),3,n)}function ii(r,e,t,n){return en(rn(r,e+1),5,n)}function si(r,e,t,n){return en(fi(r,e+1),9,n)}function Mt(r,e,t){let n=e.value;if(n===!1)r.push([u.float.majorEncoded|ja]);else if(n===!0)r.push([u.float.majorEncoded|Ha]);else if(n===null)r.push([u.float.majorEncoded|Wa]);else if(n===void 0)r.push([u.float.majorEncoded|Ga]);else{let o,i=!1;(!t||t.float64!==!0)&&(ci(n),o=tn(Y,1),n===o||Number.isNaN(n)?(Y[0]=249,r.push(Y.slice(0,3)),i=!0):(ui(n),o=rn(Y,1),n===o&&(Y[0]=250,r.push(Y.slice(0,5)),i=!0))),i||(Ka(n),o=fi(Y,1),Y[0]=251,r.push(Y.slice(0,9)))}}Mt.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){ci(n);let o=tn(Y,1);if(n===o||Number.isNaN(n))return 3;if(ui(n),o=rn(Y,1),n===o)return 5}return 9};var ai=new ArrayBuffer(9),K=new DataView(ai,1),Y=new Uint8Array(ai,0);function ci(r){if(r===1/0)K.setUint16(0,31744,!1);else if(r===-1/0)K.setUint16(0,64512,!1);else if(Number.isNaN(r))K.setUint16(0,32256,!1);else{K.setFloat32(0,r);let e=K.getUint32(0),t=(e&2139095040)>>23,n=e&8388607;if(t===255)K.setUint16(0,31744,!1);else if(t===0)K.setUint16(0,(r&2147483648)>>16|n>>13,!1);else{let o=t-127;o<-24?K.setUint16(0,0):o<-14?K.setUint16(0,(e&2147483648)>>16|1<<24+o,!1):K.setUint16(0,(e&2147483648)>>16|o+15<<10|n>>13,!1)}}}function tn(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,o=t&1023,i;return n===0?i=o*2**-24:n!==31?i=(o+1024)*2**(n-25):i=o===0?1/0:NaN,t&32768?-i:i}function ui(r){K.setFloat32(0,r,!1)}function rn(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 Ka(r){K.setFloat64(0,r,!1)}function fi(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)}Mt.compareTokens=G.compareTokens;function I(r,e,t){throw new Error(`${k} encountered invalid minor (${t}) for major ${r[e]>>>5}`)}function zt(r){return()=>{throw new Error(`${k} ${r}`)}}var b=[];for(let r=0;r<=23;r++)b[r]=I;b[24]=bo;b[25]=xo;b[26]=Eo;b[27]=vo;b[28]=I;b[29]=I;b[30]=I;b[31]=I;for(let r=32;r<=55;r++)b[r]=I;b[56]=ko;b[57]=Ao;b[58]=Co;b[59]=To;b[60]=I;b[61]=I;b[62]=I;b[63]=I;for(let r=64;r<=87;r++)b[r]=So;b[88]=Lo;b[89]=Io;b[90]=Do;b[91]=No;b[92]=I;b[93]=I;b[94]=I;b[95]=zt("indefinite length bytes/strings are not supported");for(let r=96;r<=119;r++)b[r]=Bo;b[120]=Uo;b[121]=Po;b[122]=Ro;b[123]=Oo;b[124]=I;b[125]=I;b[126]=I;b[127]=zt("indefinite length bytes/strings are not supported");for(let r=128;r<=151;r++)b[r]=$o;b[152]=Mo;b[153]=zo;b[154]=Vo;b[155]=qo;b[156]=I;b[157]=I;b[158]=I;b[159]=jo;for(let r=160;r<=183;r++)b[r]=Ho;b[184]=Wo;b[185]=Go;b[186]=Ko;b[187]=Qo;b[188]=I;b[189]=I;b[190]=I;b[191]=Jo;for(let r=192;r<=215;r++)b[r]=Xo;b[216]=Yo;b[217]=Zo;b[218]=ei;b[219]=ti;b[220]=I;b[221]=I;b[222]=I;b[223]=I;for(let r=224;r<=243;r++)b[r]=zt("simple values are not supported");b[244]=I;b[245]=I;b[246]=I;b[247]=ri;b[248]=zt("simple values are not supported");b[249]=oi;b[250]=ii;b[251]=si;b[252]=I;b[253]=I;b[254]=I;b[255]=ni;var Z=[];for(let r=0;r<24;r++)Z[r]=new g(u.uint,r,1);for(let r=-1;r>=-24;r--)Z[31-r]=new g(u.negint,r,1);Z[64]=new g(u.bytes,new Uint8Array(0),1);Z[96]=new g(u.string,"",1);Z[128]=new g(u.array,0,1);Z[160]=new g(u.map,0,1);Z[244]=new g(u.false,!1,1);Z[245]=new g(u.true,!0,1);Z[246]=new g(u.null,null,1);function li(r){switch(r.type){case u.false:return ee([244]);case u.true:return ee([245]);case u.null:return ee([246]);case u.bytes:return r.value.length?void 0:ee([64]);case u.string:return r.value===""?ee([96]):void 0;case u.array:return r.value===0?ee([128]):void 0;case u.map:return r.value===0?ee([160]):void 0;case u.uint:return r.value<24?ee([Number(r.value)]):void 0;case u.negint:if(r.value>=-24)return ee([31-Number(r.value)])}}var Ja={float64:!1,mapSorter:Za,quickEncodeToken:li};function Xa(){let r=[];return r[u.uint.major]=G,r[u.negint.major]=Pt,r[u.bytes.major]=Ve,r[u.string.major]=Fo,r[u.array.major]=Ot,r[u.map.major]=Ft,r[u.tag.major]=$t,r[u.float.major]=Mt,r}var hi=Xa(),nn=new st,qt=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(`${ze} object contains circular references`);return new r(t,e)}},we={null:new g(u.null,null),undefined:new g(u.undefined,void 0),true:new g(u.true,!0),false:new g(u.false,!1),emptyArray:new g(u.array,0),emptyMap:new g(u.map,0)},be={number(r,e,t,n){return!Number.isInteger(r)||!Number.isSafeInteger(r)?new g(u.float,r):r>=0?new g(u.uint,r):new g(u.negint,r)},bigint(r,e,t,n){return r>=BigInt(0)?new g(u.uint,r):new g(u.negint,r)},Uint8Array(r,e,t,n){return new g(u.bytes,r)},string(r,e,t,n){return new g(u.string,r)},boolean(r,e,t,n){return r?we.true:we.false},null(r,e,t,n){return we.null},undefined(r,e,t,n){return we.undefined},ArrayBuffer(r,e,t,n){return new g(u.bytes,new Uint8Array(r))},DataView(r,e,t,n){return new g(u.bytes,new Uint8Array(r.buffer,r.byteOffset,r.byteLength))},Array(r,e,t,n){if(!r.length)return t.addBreakTokens===!0?[we.emptyArray,new g(u.break)]:we.emptyArray;n=qt.createCheck(n,r);let o=[],i=0;for(let s of r)o[i++]=Vt(s,t,n);return t.addBreakTokens?[new g(u.array,r.length),o,new g(u.break)]:[new g(u.array,r.length),o]},Object(r,e,t,n){let o=e!=="Object",i=o?r.keys():Object.keys(r),s=o?r.size:i.length;if(!s)return t.addBreakTokens===!0?[we.emptyMap,new g(u.break)]:we.emptyMap;n=qt.createCheck(n,r);let c=[],f=0;for(let p of i)c[f++]=[Vt(p,t,n),Vt(o?r.get(p):r[p],t,n)];return Ya(c,t),t.addBreakTokens?[new g(u.map,s),c,new g(u.break)]:[new g(u.map,s),c]}};be.Map=be.Object;be.Buffer=be.Uint8Array;for(let r of"Uint8Clamped Uint16 Uint32 Int8 Int16 Int32 BigUint64 BigInt64 Float32 Float64".split(" "))be[`${r}Array`]=be.DataView;function Vt(r,e={},t){let n=fo(r),o=e&&e.typeEncoders&&e.typeEncoders[n]||be[n];if(typeof o=="function"){let s=o(r,n,e,t);if(s!=null)return s}let i=be[n];if(!i)throw new Error(`${ze} unsupported type: ${n}`);return i(r,n,e,t)}function Ya(r,e){e.mapSorter&&r.sort(e.mapSorter)}function Za(r,e){let t=Array.isArray(r[0])?r[0][0]:r[0],n=Array.isArray(e[0])?e[0][0]:e[0];if(t.type!==n.type)return t.type.compare(n.type);let o=t.type.major,i=hi[o].compareTokens(t,n);return i===0&&console.warn("WARNING: complex key types used, CBOR key sorting guarantees are gone"),i}function di(r,e,t,n){if(Array.isArray(e))for(let o of e)di(r,o,t,n);else t[e.type.major](r,e,n)}function pi(r,e,t){let n=Vt(r,t);if(!Array.isArray(n)&&t.quickEncodeToken){let o=t.quickEncodeToken(n);if(o)return o;let i=e[n.type.major];if(i.encodedSize){let s=i.encodedSize(n,t),c=new st(s);if(i(c,n,t),c.chunks.length!==1)throw new Error(`Unexpected error: pre-calculated length for ${n} was wrong`);return it(c.chunks[0])}}return nn.reset(),di(nn,n,e,t),nn.toBytes(!0)}function ft(r,e){return e=Object.assign({},Ja,e),pi(r,hi,e)}var ec={strict:!1,allowIndefinite:!0,allowUndefined:!0,allowBigInt:!0},jt=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=Z[e];if(t===void 0){let n=b[e];if(!n)throw new Error(`${k} no decoder for major type ${e>>>5} (byte 0x${e.toString(16).padStart(2,"0")})`);let o=e&31;t=n(this.data,this._pos,o,this.options)}return this._pos+=t.encodedLength,t}},lt=Symbol.for("DONE"),Ht=Symbol.for("BREAK");function tc(r,e,t){let n=[];for(let o=0;o<r.value;o++){let i=He(e,t);if(i===Ht){if(r.value===1/0)break;throw new Error(`${k} got unexpected break to lengthed array`)}if(i===lt)throw new Error(`${k} found array but not enough entries (got ${o}, expected ${r.value})`);n[o]=i}return n}function rc(r,e,t){let n=t.useMaps===!0,o=n?void 0:{},i=n?new Map:void 0;for(let s=0;s<r.value;s++){let c=He(e,t);if(c===Ht){if(r.value===1/0)break;throw new Error(`${k} got unexpected break to lengthed map`)}if(c===lt)throw new Error(`${k} found map but not enough entries (got ${s} [no key], expected ${r.value})`);if(n!==!0&&typeof c!="string")throw new Error(`${k} non-string keys not supported (got ${typeof c})`);if(t.rejectDuplicateMapKeys===!0&&(n&&i.has(c)||!n&&c in o))throw new Error(`${k} found repeat map key "${c}"`);let f=He(e,t);if(f===lt)throw new Error(`${k} found map but not enough entries (got ${s} [no value], expected ${r.value})`);n?i.set(c,f):o[c]=f}return n?i:o}function He(r,e){if(r.done())return lt;let t=r.next();if(t.type===u.break)return Ht;if(t.type.terminal)return t.value;if(t.type===u.array)return tc(t,r,e);if(t.type===u.map)return rc(t,r,e);if(t.type===u.tag){if(e.tags&&typeof e.tags[t.value]=="function"){let n=He(r,e);return e.tags[t.value](n)}throw new Error(`${k} tag not supported (${t.value})`)}throw new Error("unsupported")}function on(r,e){if(!(r instanceof Uint8Array))throw new Error(`${k} data to decode must be a Uint8Array`);e=Object.assign({},ec,e);let t=e.tokenizer||new jt(r,e),n=He(t,e);if(n===lt)throw new Error(`${k} did not find any content to decode`);if(n===Ht)throw new Error(`${k} got unexpected break`);return[n,r.subarray(t.pos())]}function te(r,e){let[t,n]=on(r,e);if(n.length>0)throw new Error(`${k} too many terminals, data makes no sense`);return t}function _e(r,e="utf8"){let t=Ct[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.decoder.decode(`${t.prefix}${r}`)}var ue="/",mi=new TextEncoder().encode(ue),Wt=mi[0],fe=class r{_buf;constructor(e,t){if(typeof e=="string")this._buf=_e(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]!==Wt)throw new Error("Invalid key")}toString(e="utf8"){return Oe(this._buf,e)}uint8Array(){return this._buf}get[Symbol.toStringTag](){return`Key(${this.toString()})`}static withNamespaces(e){return new r(e.join(ue))}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=mi),this._buf[0]!==Wt){let e=new Uint8Array(this._buf.byteLength+1);e.fill(Wt,0,1),e.set(this._buf,1),this._buf=e}for(;this._buf.byteLength>1&&this._buf[this._buf.byteLength-1]===Wt;)this._buf=this._buf.subarray(0,-1)}less(e){let t=this.list(),n=e.list();for(let o=0;o<t.length;o++){if(n.length<o+1)return!1;let i=t[o],s=n[o];if(i<s)return!0;if(i>s)return!1}return t.length<n.length}reverse(){return r.withNamespaces(this.list().slice().reverse())}namespaces(){return this.list()}baseNamespace(){let e=this.namespaces();return e[e.length-1]}list(){return this.toString().split(ue).slice(1)}type(){return nc(this.baseNamespace())}name(){return oc(this.baseNamespace())}instance(e){return new r(this.toString()+":"+e)}path(){let e=this.parent().toString();return e.endsWith(ue)||(e+=ue),e+=this.type(),new r(e)}parent(){let e=this.list();return e.length===1?new r(ue):new r(e.slice(0,-1).join(ue))}child(e){return this.toString()===ue?e:e.toString()===ue?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(),...ic(e.map(t=>t.namespaces()))])}};function nc(r){let e=r.split(":");return e.length<2?"":e.slice(0,-1).join(":")}function oc(r){let e=r.split(":");return e[e.length-1]}function ic(r){return[].concat(...r)}function Te(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}var bi="/pin/",gi="/pinned-block/",an=ie,yi=1;function wi(r){return r.version===0&&(r=r.toV1()),new fe(`${bi}${r.toString(an)}`)}var Gt=class{datastore;blockstore;dagWalkers;constructor(e,t,n){this.datastore=e,this.blockstore=t,this.dagWalkers=n}async*add(e,t={}){let n=wi(e);if(await this.datastore.has(n))throw new Error("Already pinned");let o=Math.round(t.depth??1/0);if(o<0)throw new Error("Depth must be greater than or equal to 0");let i=new ae({concurrency:yi});for await(let c of this.#e(e,i,{...t,depth:o}))await this.#o(c,f=>f.pinnedBy.find(p=>Te(p,e.bytes))!=null?!1:(f.pinCount++,f.pinnedBy.push(e.bytes),!0),t),yield c;let s={depth:o,metadata:t.metadata??{}};await this.datastore.put(n,ft(s),t)}async*#e(e,t,n){if(n.depth===-1)return;let o=this.dagWalkers[e.code];if(o==null)throw new Error(`No dag walker found for cid codec ${e.code}`);let i=await this.blockstore.get(e,n);yield e;for await(let s of o.walk(i))yield*await t.add(async()=>this.#e(s,t,{...n,depth:n.depth-1}))}async#o(e,t,n){let o=new fe(`${gi}${an.encode(e.multihash.bytes)}`),i={pinCount:0,pinnedBy:[]};try{i=te(await this.datastore.get(o,n))}catch(c){if(c.code!=="ERR_NOT_FOUND")throw c}if(t(i)){if(i.pinCount===0&&await this.datastore.has(o)){await this.datastore.delete(o);return}await this.datastore.put(o,ft(i),n),n.onProgress?.(new D("helia:pin:add",e))}}async*rm(e,t={}){let n=wi(e),o=await this.datastore.get(n,t),i=te(o);await this.datastore.delete(n,t);let s=new ae({concurrency:yi});for await(let c of this.#e(e,s,{...t,depth:i.depth}))await this.#o(c,f=>(f.pinCount--,f.pinnedBy=f.pinnedBy.filter(p=>Te(p,e.bytes)),!0),{...t,depth:i.depth}),yield c}async*ls(e={}){for await(let{key:t,value:n}of this.datastore.query({prefix:bi+(e.cid!=null?`${e.cid.toString(ie)}`:"")},e)){let o=B.parse(t.toString().substring(5),ie),i=te(n);yield{cid:o,...i}}}async isPinned(e,t={}){let n=new fe(`${gi}${an.encode(e.multihash.bytes)}`);return this.datastore.has(n,t)}};var Kt=class extends ae{has(e){return this.find(e)!=null}find(e){return this.queue.find(t=>e.equals(t.options.peerId))}};function sc(r){return r[Symbol.asyncIterator]!=null}function ac(...r){let e=[];for(let t of r)sc(t)||e.push(t);return e.length===r.length?function*(){for(let t of e)yield*t}():async function*(){let t=ot({objectMode:!0});Promise.resolve().then(async()=>{try{await Promise.all(r.map(async n=>{for await(let o of n)t.push(o)})),t.end()}catch(n){t.end(n)}}),yield*t}()}var ht=ac;var cc=5,Qt=class{log;routers;providerLookupConcurrency;constructor(e,t){this.log=e.logger.forComponent("helia:routing"),this.routers=t.routers??[],this.providerLookupConcurrency=t.providerLookupConcurrency??cc}async start(){await de(...this.routers)}async stop(){await pe(...this.routers)}async*findProviders(e,t={}){if(this.routers.length===0)throw new P("No content routers available","ERR_NO_ROUTERS_AVAILABLE");let n=new Kt({concurrency:this.providerLookupConcurrency});n.addEventListener("error",()=>{});for await(let o of ht(n.toGenerator(),...We(this.routers,"findProviders").map(i=>i.findProviders(e,t))))if(o!=null){if(o.multiaddrs.length===0){if(n.find(o.id)!=null)continue;n.add(async()=>{try{let i=await this.findPeer(o.id,t);return i.multiaddrs.length===0?null:i}catch(i){return this.log.error("could not load multiaddrs for peer %p",o.id,i),null}},{peerId:o.id,signal:t.signal}).catch(i=>{this.log.error("could not load multiaddrs for peer %p",o.id,i)})}yield o}}async provide(e,t={}){if(this.routers.length===0)throw new P("No content routers available","ERR_NO_ROUTERS_AVAILABLE");await Promise.all(We(this.routers,"provide").map(async n=>{await n.provide(e,t)}))}async put(e,t,n){await Promise.all(We(this.routers,"put").map(async o=>{await o.put(e,t,n)}))}async get(e,t){return Promise.any(We(this.routers,"get").map(async n=>n.get(e,t)))}async findPeer(e,t){if(this.routers.length===0)throw new P("No peer routers available","ERR_NO_ROUTERS_AVAILABLE");let n=this,o=ht(...We(this.routers,"findPeer").map(i=>async function*(){try{yield await i.findPeer(e,t)}catch(s){n.log.error(s)}}()));for await(let i of o)if(i!=null)return i;throw new P("Could not find peer in routing","ERR_NOT_FOUND")}async*getClosestPeers(e,t={}){if(this.routers.length===0)throw new P("No peer routers available","ERR_NO_ROUTERS_AVAILABLE");for await(let n of ht(...We(this.routers,"getClosestPeers").map(o=>o.getClosestPeers(e,t))))n!=null&&(yield n)}};function We(r,e){return r.filter(t=>t[e]!=null)}var xe={},Ge=r=>{r.addEventListener("message",e=>{Ge.dispatchEvent("message",r,e)}),r.port!=null&&r.port.addEventListener("message",e=>{Ge.dispatchEvent("message",r,e)})};Ge.addEventListener=(r,e)=>{xe[r]==null&&(xe[r]=[]),xe[r].push(e)};Ge.removeEventListener=(r,e)=>{xe[r]!=null&&(xe[r]=xe[r].filter(t=>t===e))};Ge.dispatchEvent=function(r,e,t){xe[r]!=null&&xe[r].forEach(n=>n(e,t))};var cn=Ge;var un="lock:worker:request-read",fn="lock:worker:release-read",ln="lock:master:grant-read",hn="lock:worker:request-write",dn="lock:worker:release-write",pn="lock:master:grant-write";var xi=(r=21)=>Math.random().toString().substring(2);var Ei=(r,e,t,n,o)=>(i,s)=>{if(s.data.type!==t)return;let c={type:s.data.type,name:s.data.name,identifier:s.data.identifier};r.dispatchEvent(new MessageEvent(e,{data:{name:c.name,handler:async()=>{i.postMessage({type:o,name:c.name,identifier:c.identifier}),await new Promise(f=>{let p=h=>{if(h==null||h.data==null)return;let l={type:h.data.type,name:h.data.name,identifier:h.data.identifier};l.type===n&&l.identifier===c.identifier&&(i.removeEventListener("message",p),f())};i.addEventListener("message",p)})}}}))},vi=(r,e,t,n)=>async()=>{let o=xi();return globalThis.postMessage({type:e,identifier:o,name:r}),new Promise(i=>{let s=c=>{if(c==null||c.data==null)return;let f={type:c.data.type,identifier:c.data.identifier};f.type===t&&f.identifier===o&&(globalThis.removeEventListener("message",s),i(()=>{globalThis.postMessage({type:n,identifier:o,name:r})}))};globalThis.addEventListener("message",s)})},uc={singleProcess:!1},ki=r=>{if(r=Object.assign({},uc,r),!!globalThis.document||r.singleProcess){let t=new EventTarget;return cn.addEventListener("message",Ei(t,"requestReadLock",un,fn,ln)),cn.addEventListener("message",Ei(t,"requestWriteLock",hn,dn,pn)),t}return{isWorker:!0,readLock:t=>vi(t,un,ln,fn),writeLock:t=>vi(t,hn,pn,dn)}};var Se={},Ee;async function mn(r,e){let t,n=new Promise(o=>{t=o});return r.add(async()=>Ze((async()=>{await new Promise(o=>{t(()=>{o()})})})(),{milliseconds:e.timeout})),n}var fc=(r,e)=>{if(Ee.isWorker===!0)return{readLock:Ee.readLock(r,e),writeLock:Ee.writeLock(r,e)};let t=new ye({concurrency:1}),n;return{async readLock(){if(n!=null)return mn(n,e);n=new ye({concurrency:e.concurrency,autoStart:!1});let o=n,i=mn(n,e);return t.add(async()=>{o.start(),await o.onIdle().then(()=>{n===o&&(n=null)})}),i},async writeLock(){return n=null,mn(t,e)}}},lc={name:"lock",concurrency:1/0,timeout:846e5,singleProcess:!1};function gn(r){let e=Object.assign({},lc,r);return Ee==null&&(Ee=ki(e),Ee.isWorker!==!0&&(Ee.addEventListener("requestReadLock",t=>{Se[t.data.name]!=null&&Se[t.data.name].readLock().then(async n=>t.data.handler().finally(()=>{n()}))}),Ee.addEventListener("requestWriteLock",async t=>{Se[t.data.name]!=null&&Se[t.data.name].writeLock().then(async n=>t.data.handler().finally(()=>{n()}))}))),Se[e.name]==null&&(Se[e.name]=fc(e.name,e)),Se[e.name]}var Jt=class{lock;child;pins;started;constructor(e,t,n={}){this.child=e,this.pins=t,this.lock=gn({singleProcess:n.holdGcLock}),this.started=!1}isStarted(){return this.started}async start(){await de(this.child),this.started=!0}async stop(){await pe(this.child),this.started=!1}unwrap(){return this.child}async put(e,t,n={}){n?.signal?.throwIfAborted();let o=await this.lock.readLock();try{return await this.child.put(e,t,n)}finally{o()}}async*putMany(e,t={}){t?.signal?.throwIfAborted();let n=await this.lock.readLock();try{yield*this.child.putMany(e,t)}finally{n()}}async get(e,t={}){t?.signal?.throwIfAborted();let n=await this.lock.readLock();try{return await this.child.get(e,t)}finally{n()}}async*getMany(e,t={}){t?.signal?.throwIfAborted();let n=await this.lock.readLock();try{yield*this.child.getMany(e,t)}finally{n()}}async delete(e,t={}){t?.signal?.throwIfAborted();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={}){t?.signal?.throwIfAborted();let n=await this.lock.writeLock();try{let o=this;yield*this.child.deleteMany(async function*(){for await(let i of e){if(await o.pins.isPinned(i))throw new Error("CID was pinned");yield i}}(),t)}finally{n()}}async has(e,t={}){t?.signal?.throwIfAborted();let n=await this.lock.readLock();try{return await this.child.has(e,t)}finally{n()}}async*getAll(e={}){e?.signal?.throwIfAborted();let t=await this.lock.readLock();try{yield*this.child.getAll(e)}finally{t()}}createSession(e,t){return t?.signal?.throwIfAborted(),this.child.createSession(e,t)}};var Ci=42;function hc(r){if(r.asCID!==r&&r["/"]!==r.bytes)return null;let e=B.asCID(r);if(!e)return null;let t=new Uint8Array(e.bytes.byteLength+1);return t.set(e.bytes,1),[new g(u.tag,Ci),new g(u.bytes,t)]}function dc(){throw new Error("`undefined` is not supported by the IPLD Data Model and cannot be encoded")}function pc(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 Ai={float64:!0,typeEncoders:{Object:hc,undefined:dc,number:pc}},Vh={...Ai,typeEncoders:{...Ai.typeEncoders}};function mc(r){if(r[0]!==0)throw new Error("Invalid CID for CBOR tag 42; expected leading 0x00");return B.decode(r.subarray(1))}var yn={allowIndefinite:!1,coerceUndefinedToNull:!0,allowNaN:!1,allowInfinity:!1,allowBigInt:!0,strict:!0,useMaps:!1,rejectDuplicateMapKeys:!0,tags:[]};yn.tags[Ci]=mc;var qh={...yn,tags:yn.tags.slice()};var _i=113;var Ti=class extends Array{constructor(){super(),this.inRecursive=[]}prefix(e){let t=this.inRecursive[this.inRecursive.length-1];t&&(t.type===u.array&&(t.elements++,t.elements!==1&&e.push([44])),t.type===u.map&&(t.elements++,t.elements!==1&&(t.elements%2===1?e.push([44]):e.push([58]))))}[u.uint.major](e,t){this.prefix(e);let n=String(t.value),o=[];for(let i=0;i<n.length;i++)o[i]=n.charCodeAt(i);e.push(o)}[u.negint.major](e,t){this[u.uint.major](e,t)}[u.bytes.major](e,t){throw new Error(`${ze} unsupported type: Uint8Array`)}[u.string.major](e,t){this.prefix(e);let n=Ut(JSON.stringify(t.value));e.push(n.length>32?it(n):n)}[u.array.major](e,t){this.prefix(e),this.inRecursive.push({type:u.array,elements:0}),e.push([91])}[u.map.major](e,t){this.prefix(e),this.inRecursive.push({type:u.map,elements:0}),e.push([123])}[u.tag.major](e,t){}[u.float.major](e,t){if(t.type.name==="break"){let s=this.inRecursive.pop();if(s){if(s.type===u.array)e.push([93]);else if(s.type===u.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(`${ze} unsupported type: undefined`);if(this.prefix(e),t.type.name==="true"){e.push([116,114,117,101]);return}else if(t.type.name==="false"){e.push([102,97,108,115,101]);return}else if(t.type.name==="null"){e.push([110,117,108,108]);return}let n=String(t.value),o=[],i=!1;for(let s=0;s<n.length;s++)o[s]=n.charCodeAt(s),!i&&(o[s]===46||o[s]===101||o[s]===69)&&(i=!0);i||(o.push(46),o.push(48)),e.push(o)}};var Le=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,o=c=>{for(;!this.done();){let f=this.ch();if(c.includes(f))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 g(u.uint,0,this._pos-e);if(o([48,49,50,51,52,53,54,55,56,57]),t&&this._pos===e+1)throw new Error(`${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++,o([48,49,50,51,52,53,54,55,56,57])}!this.done()&&(this.ch()===101||this.ch()===69)&&(n=!0,this._pos++,!this.done()&&(this.ch()===43||this.ch()===45)&&this._pos++,o([48,49,50,51,52,53,54,55,56,57]));let i=String.fromCharCode.apply(null,this.data.subarray(e,this._pos)),s=parseFloat(i);return n?new g(u.float,s,this._pos-e):this.options.allowBigInt!==!0||Number.isSafeInteger(s)?new g(s>=0?u.uint:u.negint,s,this._pos-e):new g(s>=0?u.uint:u.negint,BigInt(i),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 i=this._pos,s=0;i<this.data.length&&s<65536;i++,s++){let c=this.data[i];if(c===92||c<32||c>=128)break;if(c===34){let f=String.fromCharCode.apply(null,this.data.subarray(this._pos,i));return this._pos=i+1,new g(u.string,f,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 i=0;for(let s=0;s<4;s++){let c=this.ch();if(c>=48&&c<=57)c-=48;else if(c>=97&&c<=102)c=c-97+10;else if(c>=65&&c<=70)c=c-65+10;else throw new Error(`${k} unexpected unicode escape character at position ${this._pos}`);i=i*16+c,this._pos++}return i},o=()=>{let i=this.ch(),s=null,c=i>239?4:i>223?3:i>191?2:1;if(this._pos+c>this.data.length)throw new Error(`${k} unexpected unicode sequence at position ${this._pos}`);let f,p,h,l;switch(c){case 1:i<128&&(s=i);break;case 2:f=this.data[this._pos+1],(f&192)===128&&(l=(i&31)<<6|f&63,l>127&&(s=l));break;case 3:f=this.data[this._pos+1],p=this.data[this._pos+2],(f&192)===128&&(p&192)===128&&(l=(i&15)<<12|(f&63)<<6|p&63,l>2047&&(l<55296||l>57343)&&(s=l));break;case 4:f=this.data[this._pos+1],p=this.data[this._pos+2],h=this.data[this._pos+3],(f&192)===128&&(p&192)===128&&(h&192)===128&&(l=(i&15)<<18|(f&63)<<12|(p&63)<<6|h&63,l>65535&&l<1114112&&(s=l))}s===null?(s=65533,c=1):s>65535&&(s-=65536,t.push(s>>>10&1023|55296),s=56320|s&1023),t.push(s),this._pos+=c};for(;!this.done();){let i=this.ch(),s;switch(i){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 g(u.string,Yr(t),this._pos-e);default:if(i<32)throw new Error(`${k} invalid control character at position ${this._pos}`);i<128?(t.push(i),this._pos++):o()}}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 g(u.map,1/0,1);case 91:return this.modeStack.push("array-start"),this._pos++,new g(u.array,1/0,1);case 34:return this.parseString();case 110:return this.expect([110,117,108,108]),new g(u.null,null,4);case 102:return this.expect([102,97,108,115,101]),new g(u.false,!1,5);case 116:return this.expect([116,114,117,101]),new g(u.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 g(u.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 g(u.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 g(u.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 g(u.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 Xt(r,e){return e=Object.assign({tokenizer:new Le(r,e)},e),te(r,e)}var wc={allowIndefinite:!1,allowUndefined:!1,allowNaN:!1,allowInfinity:!1,allowBigInt:!0,strict:!0,useMaps:!1,rejectDuplicateMapKeys:!0,tags:[]};wc.tags[42]=B.parse;var Li=297;var sd=new TextDecoder;var ad=new TextEncoder;var xc=new TextDecoder;function wn(r,e){let t=0;for(let n=0;;n+=7){if(n>=64)throw new Error("protobuf: varint overflow");if(e>=r.length)throw new Error("protobuf: unexpected end of data");let o=r[e++];if(t+=n<28?(o&127)<<n:(o&127)*2**n,o<128)break}return[t,e]}function Yt(r,e){let t;[t,e]=wn(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 Ii(r,e){let t;return[t,e]=wn(r,e),[t&7,t>>3,e]}function Ec(r){let e={},t=r.length,n=0;for(;n<t;){let o,i;if([o,i,n]=Ii(r,n),i===1){if(e.Hash)throw new Error("protobuf: (PBLink) duplicate Hash section");if(o!==2)throw new Error(`protobuf: (PBLink) wrong wireType (${o}) for Hash`);if(e.Name!==void 0)throw new Error("protobuf: (PBLink) invalid order, found Name before Hash");if(e.Tsize!==void 0)throw new Error("protobuf: (PBLink) invalid order, found Tsize before Hash");[e.Hash,n]=Yt(r,n)}else if(i===2){if(e.Name!==void 0)throw new Error("protobuf: (PBLink) duplicate Name section");if(o!==2)throw new Error(`protobuf: (PBLink) wrong wireType (${o}) for Name`);if(e.Tsize!==void 0)throw new Error("protobuf: (PBLink) invalid order, found Tsize before Name");let s;[s,n]=Yt(r,n),e.Name=xc.decode(s)}else if(i===3){if(e.Tsize!==void 0)throw new Error("protobuf: (PBLink) duplicate Tsize section");if(o!==0)throw new Error(`protobuf: (PBLink) wrong wireType (${o}) for Tsize`);[e.Tsize,n]=wn(r,n)}else throw new Error(`protobuf: (PBLink) invalid fieldNumber, expected 1, 2 or 3, got ${i}`)}if(n>t)throw new Error("protobuf: (PBLink) unexpected end of data");return e}function Di(r){let e=r.length,t=0,n,o=!1,i;for(;t<e;){let c,f;if([c,f,t]=Ii(r,t),c!==2)throw new Error(`protobuf: (PBNode) invalid wireType, expected 2, got ${c}`);if(f===1){if(i)throw new Error("protobuf: (PBNode) duplicate Data section");[i,t]=Yt(r,t),n&&(o=!0)}else if(f===2){if(o)throw new Error("protobuf: (PBNode) duplicate Links section");n||(n=[]);let p;[p,t]=Yt(r,t),n.push(Ec(p))}else throw new Error(`protobuf: (PBNode) invalid fieldNumber, expected 1 or 2, got ${f}`)}if(t>e)throw new Error("protobuf: (PBNode) unexpected end of data");let s={};return i&&(s.Data=i),s.Links=n||[],s}var ud=new TextEncoder,fd=2**32,ld=2**31;var pd=new TextEncoder;function Ni(r){return r instanceof ArrayBuffer?new Uint8Array(r,0,r.byteLength):r}var Bi=112;function Ui(r){let e=Ni(r),t=Di(e),n={};return t.Data&&(n.Data=t.Data),t.Links&&(n.Links=t.Links.map(o=>{let i={};try{i.Hash=B.decode(o.Hash)}catch{}if(!i.Hash)throw new Error("Invalid Hash field found in link, expected CID");return o.Name!==void 0&&(i.Name=o.Name),o.Tsize!==void 0&&(i.Tsize=o.Tsize),i})),n}var kc={codec:Bi,*walk(r){yield*Ui(r).Links.map(t=>t.Hash)}},Ac={codec:Nr,*walk(){}},Pi=42,Cc={codec:_i,*walk(r){let e=[],t=[];t[Pi]=n=>{if(n[0]!==0)throw new Error("Invalid CID for CBOR tag 42; expected leading 0x00");let o=B.decode(n.subarray(1));return e.push(o),o},te(r,{tags:t}),yield*e}},bn=class extends Le{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===u.map){let t=this._next();if(t.type===u.string&&t.value==="/"){let n=this._next();if(n.type===u.string){if(this._next().type!==u.break)throw new Error("Invalid encoded CID form");return this.tokenBuffer.push(n),new g(u.tag,42,0)}if(n.type===u.map){let o=this._next();if(o.type===u.string&&o.value==="bytes"){let i=this._next();if(i.type===u.string){for(let c=0;c<2;c++)if(this._next().type!==u.break)throw new Error("Invalid encoded Bytes form");let s=ge.decode(`m${i.value}`);return new g(u.bytes,s,i.value.length)}this.tokenBuffer.push(i)}this.tokenBuffer.push(o)}this.tokenBuffer.push(n)}this.tokenBuffer.push(t)}return e}},_c={codec:Li,*walk(r){let e=[],t=[];t[Pi]=n=>{let o=B.parse(n);return e.push(o),o},Xt(r,{tags:t,tokenizer:new bn(r,{tags:t,allowIndefinite:!0,allowUndefined:!0,allowNaN:!0,allowInfinity:!0,allowBigInt:!0,strict:!1,rejectDuplicateMapKeys:!1})}),yield*e}},Tc={codec:Vn,*walk(){}};function Ri(r=[]){let e={};return[kc,Ac,Cc,_c,Tc,...r].forEach(t=>{e[t.codec]=t}),e}var xn=new fe("/version"),Oi=1;async function Fi(r){if(!await r.has(xn)){await r.put(xn,_e(`${Oi}`));return}let e=await r.get(xn),t=Oe(e);if(parseInt(t,10)!==Oi)throw new Error("Unknown datastore version, a datastore migration may be required")}function $i(r=[]){let e={};return[Mr,zr,Rr,...r].forEach(t=>{e[t.code]=t}),e}function re(r){let e=new globalThis.AbortController;function t(){e.abort();for(let i of r)i?.removeEventListener!=null&&i.removeEventListener("abort",t)}for(let i of r){if(i?.aborted===!0){t();break}i?.addEventListener!=null&&i.addEventListener("abort",t)}function n(){for(let i of r)i?.removeEventListener!=null&&i.removeEventListener("abort",t)}let o=e.signal;return o.clear=n,o}var ve=class{has(e,t){return Promise.reject(new Error(".has is not implemented"))}put(e,t,n){return Promise.reject(new Error(".put is not implemented"))}async*putMany(e,t){for await(let{cid:n,block:o}of e)await this.put(n,o,t),yield n}get(e,t){return Promise.reject(new Error(".get is not implemented"))}async*getMany(e,t){for await(let n of e)yield{cid:n,block:await this.get(n,t)}}delete(e,t){return Promise.reject(new Error(".delete is not implemented"))}async*deleteMany(e,t){for await(let n of e)await this.delete(n,t),yield n}async*getAll(e){throw new Error(".getAll is not implemented")}};var Ke={};M(Ke,{abortedError:()=>Bc,closeFailedError:()=>Ic,deleteFailedError:()=>ji,getFailedError:()=>Dc,hasFailedError:()=>Nc,notFoundError:()=>Zt,openFailedError:()=>Lc,putFailedError:()=>qi});var le=wt(Vi(),1);function Lc(r){return r=r??new Error("Open failed"),(0,le.default)(r,"ERR_OPEN_FAILED")}function Ic(r){return r=r??new Error("Close failed"),(0,le.default)(r,"ERR_CLOSE_FAILED")}function qi(r){return r=r??new Error("Put failed"),(0,le.default)(r,"ERR_PUT_FAILED")}function Dc(r){return r=r??new Error("Get failed"),(0,le.default)(r,"ERR_GET_FAILED")}function ji(r){return r=r??new Error("Delete failed"),(0,le.default)(r,"ERR_DELETE_FAILED")}function Nc(r){return r=r??new Error("Has failed"),(0,le.default)(r,"ERR_HAS_FAILED")}function Zt(r){return r=r??new Error("Not Found"),(0,le.default)(r,"ERR_NOT_FOUND")}function Bc(r){return r=r??new Error("Aborted"),(0,le.default)(r,"ERR_ABORTED")}function Uc(r){let[e,t]=r[Symbol.asyncIterator]!=null?[r[Symbol.asyncIterator](),Symbol.asyncIterator]:[r[Symbol.iterator](),Symbol.iterator],n=[];return{peek:()=>e.next(),push:o=>{n.push(o)},next:()=>n.length>0?{done:!1,value:n.shift()}:e.next(),[t](){return this}}}var er=Uc;function Pc(r){return r[Symbol.asyncIterator]!=null}function Rc(r,e){let t=0;if(Pc(r))return async function*(){for await(let f of r)await e(f,t++)&&(yield f)}();let n=er(r),{value:o,done:i}=n.next();if(i===!0)return function*(){}();let s=e(o,t++);if(typeof s.then=="function")return async function*(){await s&&(yield o);for await(let f of n)await e(f,t++)&&(yield f)}();let c=e;return function*(){s===!0&&(yield o);for(let f of n)c(f,t++)&&(yield f)}()}var En=Rc;var ep=xr("blockstore:core:tiered");var Hi={...Ke};var tr=0,rr=class extends ve{child;constructor(e){super(),this.child=e}put(e,t){return e.multihash.code===tr||this.child==null?e:this.child.put(e,t)}get(e){if(e.multihash.code===tr)return e.multihash.digest;if(this.child==null)throw Hi.notFoundError();return this.child.get(e)}has(e){return e.multihash.code===tr?!0:this.child==null?!1:this.child.has(e)}delete(e){if(e.code!==tr&&this.child!=null)return this.child.delete(e)}getAll(e){return this.child!=null?this.child.getAll(e):[]}};function Oc(r){return r[Symbol.asyncIterator]!=null}function Wi(r){return r?.then!=null}function Fc(r,e){let t=0;if(Oc(r))return async function*(){for await(let f of r){let p=e(f,t++);Wi(p)&&await p,yield f}}();let n=er(r),{value:o,done:i}=n.next();if(i===!0)return function*(){}();if(typeof e(o,t++)?.then=="function")return async function*(){yield o;for await(let f of n){let p=e(f,t++);Wi(p)&&await p,yield f}}();let c=e;return function*(){yield o;for(let f of n)c(f,t++),yield f}()}var vn=Fc;var nr=class{child;hashers;log;logger;components;constructor(e){this.log=e.logger.forComponent("helia:networked-storage"),this.logger=e.logger,this.components=e,this.child=new rr(e.blockstore),this.hashers=e.hashers??{}}async put(e,t,n={}){return await this.child.has(e,n)?(n.onProgress?.(new D("blocks:put:duplicate",e)),e):(n.onProgress?.(new D("blocks:put:providers:notify",e)),await Promise.all(this.components.blockBrokers.map(async o=>o.announce?.(e,t,n))),n.onProgress?.(new D("blocks:put:blockstore:put",e)),this.child.put(e,t,n))}async*putMany(e,t={}){let n=En(e,async({cid:i})=>{let s=await this.child.has(i,t);return s&&t.onProgress?.(new D("blocks:put-many:duplicate",i)),!s}),o=vn(n,async({cid:i,block:s})=>{t.onProgress?.(new D("blocks:put-many:providers:notify",i)),await Promise.all(this.components.blockBrokers.map(async c=>c.announce?.(i,s,t)))});t.onProgress?.(new D("blocks:put-many:blockstore:put-many")),yield*this.child.putMany(o,t)}async get(e,t={}){if(t.offline!==!0&&!await this.child.has(e,t)){t.onProgress?.(new D("blocks:get:providers:get",e));let n=await Gi(e,this.components.blockBrokers,this.hashers[e.multihash.code],{...t,log:this.log});return t.onProgress?.(new D("blocks:get:blockstore:put",e)),await this.child.put(e,n,t),t.onProgress?.(new D("blocks:get:providers:notify",e)),await Promise.all(this.components.blockBrokers.map(async o=>o.announce?.(e,n,t))),n}return t.onProgress?.(new D("blocks:get:blockstore:get",e)),this.child.get(e,t)}async*getMany(e,t={}){t.onProgress?.(new D("blocks:get-many:blockstore:get-many")),yield*this.child.getMany(vn(e,async n=>{if(t.offline!==!0&&!await this.child.has(n,t)){t.onProgress?.(new D("blocks:get-many:providers:get",n));let o=await Gi(n,this.components.blockBrokers,this.hashers[n.multihash.code],{...t,log:this.log});t.onProgress?.(new D("blocks:get-many:blockstore:put",n)),await this.child.put(n,o,t),t.onProgress?.(new D("blocks:get-many:providers:notify",n)),await Promise.all(this.components.blockBrokers.map(async i=>i.announce?.(n,o,t)))}}))}async delete(e,t={}){t.onProgress?.(new D("blocks:delete:blockstore:delete",e)),await this.child.delete(e,t)}async*deleteMany(e,t={}){t.onProgress?.(new D("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 D("blocks:get-all:blockstore:get-many")),yield*this.child.getAll(e)}},or=class extends nr{started;constructor(e){super(e),this.started=!1}isStarted(){return this.started}async start(){await de(this.child,...this.components.blockBrokers),this.started=!0}async stop(){await pe(this.child,...this.components.blockBrokers),this.started=!1}unwrap(){return this.child}createSession(e,t){let n=this.components.blockBrokers.map(o=>o.createSession==null?o:o.createSession(t));return new kn({blockstore:this.child,blockBrokers:n,hashers:this.hashers,logger:this.logger},{root:e})}},kn=class extends nr{closeController;constructor(e,t){super(e),this.closeController=new AbortController,R(1/0,this.closeController.signal),this.log=e.logger.forComponent(`helia:session-storage:${t.root}`)}close(){this.closeController.abort()}async put(e,t,n={}){let o=re([this.closeController.signal,n.signal]);R(1/0,o);try{return await super.put(e,t,{...n,signal:o})}finally{o.clear()}}async*putMany(e,t={}){let n=re([this.closeController.signal,t.signal]);R(1/0,n);try{yield*super.putMany(e,{...t,signal:n})}finally{n.clear()}}async get(e,t={}){let n=re([this.closeController.signal,t.signal]);R(1/0,n);try{return await super.get(e,{...t,signal:n})}finally{n.clear()}}async*getMany(e,t={}){let n=re([this.closeController.signal,t.signal]);R(1/0,n);try{yield*super.getMany(e,{...t,signal:n})}finally{n.clear()}}async delete(e,t={}){let n=re([this.closeController.signal,t.signal]);R(1/0,n);try{await super.delete(e,{...t,signal:n})}finally{n.clear()}}async*deleteMany(e,t={}){let n=re([this.closeController.signal,t.signal]);R(1/0,n);try{yield*super.deleteMany(e,{...t,signal:n})}finally{n.clear()}}async has(e,t={}){let n=re([this.closeController.signal,t.signal]);R(1/0,n);try{return await super.has(e,{...t,signal:n})}finally{n.clear()}}async*getAll(e={}){let t=re([this.closeController.signal,e.signal]);R(1/0,t);try{yield*super.getAll({...e,signal:t})}finally{t.clear()}}};function $c(r){return typeof r.retrieve=="function"}var Mc=(r,e)=>{if(e==null)throw new P(`No hasher configured for multihash code 0x${r.multihash.code.toString(16)}, please configure one. You can look up which hash this is at https://github.com/multiformats/multicodec/blob/master/table.csv`,"ERR_UNKNOWN_HASH_ALG");return async t=>{let n=await e.digest(t);if(!Te(n.digest,r.multihash.digest))throw new P("Hash of downloaded block did not match multihash from passed CID","ERR_HASH_MISMATCH")}};async function Gi(r,e,t,n){let o=Mc(r,t),i=new AbortController,s=re([i.signal,n.signal]);R(1/0,i.signal,s);let c=[];for(let f of e)$c(f)&&c.push(f);try{return await Promise.any(c.map(async f=>{try{let p=!1,h=await f.retrieve(r,{...n,signal:s,validateFn:async l=>{await o(l),p=!0}});return p||await o(h),h}catch(p){throw n.log.error("could not retrieve verified block for %c",r,p),p}}))}finally{i.abort(),s.clear()}}function An(r,e){e==null&&(e=r.reduce((o,i)=>o+i.length,0));let t=Ae(e),n=0;for(let o of r)t.set(o,n),n+=o.length;return t}var Ie=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;var Ip=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;var Dp={}.toString;function Ki(r=32){if(Ie&&typeof Ie.getRandomValues=="function")return Ie.getRandomValues(new Uint8Array(r));if(Ie&&typeof Ie.randomBytes=="function")return Ie.randomBytes(r);throw new Error("crypto.getRandomValues must be defined")}function ir(r){if(isNaN(r)||r<=0)throw new P("random bytes length must be a Number bigger than 0","ERR_INVALID_LENGTH");return Ki(r)}var Cn=wt(Xi(),1);var Zi=Symbol.for("@achingbrain/uint8arraylist");function Yi(r,e){if(e==null||e<0)throw new RangeError("index is out of bounds");let t=0;for(let n of r){let o=t+n.byteLength;if(e<o)return{buf:n,index:e-t};t=o}throw new RangeError("index is out of bounds")}function ar(r){return!!r?.[Zi]}var cr=class r{bufs;length;[Zi]=!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(ar(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(ar(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=Yi(this.bufs,e);return t.buf[t.index]}set(e,t){let n=Yi(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(ar(e))for(let n=0;n<e.length;n++)this.set(t+n,e.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(e){if(e=Math.trunc(e),!(Number.isNaN(e)||e<=0)){if(e===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(e>=this.bufs[0].byteLength)e-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(e),this.length-=e;break}}}slice(e,t){let{bufs:n,length:o}=this._subList(e,t);return An(n,o)}subarray(e,t){let{bufs:n,length:o}=this._subList(e,t);return n.length===1?n[0]:An(n,o)}sublist(e,t){let{bufs:n,length:o}=this._subList(e,t),i=new r;return i.length=o,i.bufs=[...n],i}_subList(e,t){if(e=e??0,t=t??this.length,e<0&&(e=this.length+e),t<0&&(t=this.length+t),e<0||t>this.length)throw new RangeError("index is out of bounds");if(e===t)return{bufs:[],length:0};if(e===0&&t===this.length)return{bufs:this.bufs,length:this.length};let n=[],o=0;for(let i=0;i<this.bufs.length;i++){let s=this.bufs[i],c=o,f=c+s.byteLength;if(o=f,e>=f)continue;let p=e>=c&&e<f,h=t>c&&t<=f;if(p&&h){if(e===c&&t===f){n.push(s);break}let l=e-c;n.push(s.subarray(l,l+(t-e)));break}if(p){if(e===0){n.push(s);continue}n.push(s.subarray(e-c));continue}if(h){if(t===f){n.push(s);break}n.push(s.subarray(0,t-c));break}n.push(s)}return{bufs:n,length:t-e}}indexOf(e,t=0){if(!ar(e)&&!(e instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=e instanceof Uint8Array?e:e.subarray();if(t=Number(t??0),isNaN(t)&&(t=0),t<0&&(t=this.length+t),t<0&&(t=0),e.length===0)return t>this.length?this.length:t;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let i=256,s=new Int32Array(i);for(let l=0;l<i;l++)s[l]=-1;for(let l=0;l<o;l++)s[n[l]]=l;let c=s,f=this.byteLength-n.byteLength,p=n.byteLength-1,h;for(let l=t;l<=f;l+=h){h=0;for(let C=p;C>=0;C--){let a=this.get(l+C);if(n[C]!==a){h=Math.max(1,C-c[a]);break}}if(h===0)return l}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=Ae(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,t),this.write(n,e)}getInt16(e,t){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,t)}setInt16(e,t,n){let o=X(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,t,n),this.write(o,e)}getInt32(e,t){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,t)}setInt32(e,t,n){let o=X(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,t,n),this.write(o,e)}getBigInt64(e,t){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,t)}setBigInt64(e,t,n){let o=X(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,t,n),this.write(o,e)}getUint8(e){let t=this.subarray(e,e+1);return new DataView(t.buffer,t.byteOffset,t.byteLength).getUint8(0)}setUint8(e,t){let n=Ae(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,t),this.write(n,e)}getUint16(e,t){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,t)}setUint16(e,t,n){let o=X(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,t,n),this.write(o,e)}getUint32(e,t){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,t)}setUint32(e,t,n){let o=X(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,t,n),this.write(o,e)}getBigUint64(e,t){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,t)}setBigUint64(e,t,n){let o=X(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,t,n),this.write(o,e)}getFloat32(e,t){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,t)}setFloat32(e,t,n){let o=X(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,t,n),this.write(o,e)}getFloat64(e,t){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,t)}setFloat64(e,t,n){let o=X(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,t,n),this.write(o,e)}equals(e){if(e==null||!(e instanceof r)||e.bufs.length!==this.bufs.length)return!1;for(let t=0;t<this.bufs.length;t++)if(!Te(this.bufs[t],e.bufs[t]))return!1;return!0}static fromUint8Arrays(e,t){let n=new r;return n.bufs=e,t==null&&(t=e.reduce((o,i)=>o+i.byteLength,0)),n.length=t,n}};var zc=Math.LN2*Math.LN2,Qe=class r{static create(e,t=.005){let n=Vc(e,t);return new r(n)}seeds;bits;buffer;constructor(e={}){e.seeds!=null?this.seeds=e.seeds:this.seeds=qc(e.hashes??8),this.bits=e.bits??1024,this.buffer=X(Math.ceil(this.bits/8))}add(e){typeof e=="string"&&(e=_e(e));for(let t=0;t<this.seeds.length;t++){let o=Cn.default.x86.hash32(e,this.seeds[t])%this.bits;this.setbit(o)}}has(e){typeof e=="string"&&(e=_e(e));for(let t=0;t<this.seeds.length;t++){let o=Cn.default.x86.hash32(e,this.seeds[t])%this.bits;if(!this.getbit(o))return!1}return!0}clear(){this.buffer.fill(0)}setbit(e){let t=0,n=e;for(;n>7;)t++,n-=8;let o=this.buffer[t];o|=1<<n,this.buffer[t]=o}getbit(e){let t=0,n=e;for(;n>7;)t++,n-=8;return(this.buffer[t]&1<<n)!==0}};function Vc(r,e=.005){let t=Math.round(-1*r*Math.log(e)/zc),n=Math.round(t/r*Math.LN2);return{bits:t,hashes:n}}function qc(r){let e,t,n=[];for(let o=0;o<r;o++)for(e=new cr(ir(4)),n[o]=e.getUint32(0,!0),t=0;t<o;t++)if(n[o]===n[t]){o--;break}return n}var ur=class extends De{intialPeerSearchComplete;requests;name;log;logger;minProviders;maxProviders;providers;evictionFilter;constructor(e,t){super(),R(1/0,this),this.name=t.name,this.logger=e.logger,this.log=e.logger.forComponent(this.name),this.requests=new Map,this.minProviders=t.minProviders??1,this.maxProviders=t.maxProviders??5,this.providers=[],this.evictionFilter=Qe.create(this.maxProviders)}async retrieve(e,t={}){let n=ge.encode(e.multihash.bytes),o=this.requests.get(n);if(o!=null)return this.log("join existing request for %c",e),o;let i=se();if(this.requests.set(n,i.promise),this.providers.length===0){let p=!1;this.intialPeerSearchComplete==null&&(p=!0,this.log=this.logger.forComponent(`${this.name}:${e}`),this.intialPeerSearchComplete=this.findProviders(e,this.minProviders,t)),await this.intialPeerSearchComplete,p&&this.log("found initial session peers for %c",e)}let s=!1,c=new ae({concurrency:this.maxProviders});c.addEventListener("error",()=>{}),c.addEventListener("failure",p=>{this.log.error("error querying provider %o, evicting from session",p.detail.job.options.provider,p.detail.error),this.evict(p.detail.job.options.provider)}),c.addEventListener("success",p=>{s=!0,i.resolve(p.detail.result)}),c.addEventListener("idle",()=>{s||t.signal?.aborted===!0||Promise.resolve().then(async()=>{this.log("no session peers had block for for %c, finding new providers",e);for(let p=0;p<this.minProviders&&this.providers.length!==0;p++){let h=this.providers[Math.floor(Math.random()*this.providers.length)];this.evict(h)}await this.findProviders(e,this.minProviders,t),this.log("found new providers re-retrieving %c",e),this.requests.delete(n),i.resolve(await this.retrieve(e,t))}).catch(p=>{this.log.error("could not find new providers for %c",e,p),i.reject(p)})});let f=p=>{c.add(async()=>this.queryProvider(e,p.detail,t),{provider:p.detail}).catch(h=>{t.signal?.aborted!==!0&&this.log.error("error retrieving session block for %c",e,h)})};this.addEventListener("provider",f),Promise.all([...this.providers].map(async p=>c.add(async()=>this.queryProvider(e,p,t),{provider:p}))).catch(p=>{t.signal?.aborted!==!0&&this.log.error("error retrieving session block for %c",e,p)});try{return await i.promise}finally{this.removeEventListener("provider",f),c.clear(),this.requests.delete(n)}}evict(e){this.evictionFilter.add(this.toEvictionKey(e));let t=this.providers.findIndex(n=>this.equals(n,e));t!==-1&&this.providers.splice(t,1)}isEvicted(e){return this.evictionFilter.has(this.toEvictionKey(e))}hasProvider(e){return!!(this.providers.find(t=>this.equals(t,e))!=null||this.isEvicted(e))}async findProviders(e,t,n){let o=se(),i=0;return Promise.resolve().then(async()=>{this.log("finding %d-%d new provider(s) for %c",t,this.maxProviders,e);for await(let s of this.findNewProviders(e,n)){if(i===this.maxProviders||n.signal?.aborted===!0)break;if(!this.hasProvider(s)&&(this.log("found %d/%d new providers",i,this.maxProviders),this.providers.push(s),this.safeDispatchEvent("provider",{detail:s}),i++,i===t&&(this.log("session is ready"),o.resolve()),this.providers.length===this.maxProviders)){this.log("found max session peers",i);break}}if(this.log("found %d/%d new session peers",i,this.maxProviders),i<t)throw new P(`Found ${i} of ${t} ${this.name} providers for ${e}`,"ERR_INSUFFICIENT_PROVIDERS_FOUND")}).catch(s=>{this.log.error("error searching routing for potential session peers for %c",e,s.errors??s),o.reject(s)}),o.promise}};var _n=class{blockstore;datastore;pins;logger;routing;dagWalkers;hashers;dns;metrics;log;constructor(e){this.logger=e.logger??Rn(),this.log=this.logger.forComponent("helia"),this.hashers=$i(e.hashers),this.dagWalkers=Ri(e.dagWalkers),this.dns=e.dns??co(),this.metrics=e.metrics;let t={blockstore:e.blockstore,datastore:e.datastore,hashers:this.hashers,dagWalkers:this.dagWalkers,logger:this.logger,blockBrokers:[],dns:this.dns,metrics:this.metrics,...e.components??{}};this.routing=t.routing=new Qt(t,{routers:(e.routers??[]).flatMap(o=>{let i=[o];return o[fr]!=null&&i.push(o[fr]),o[lr]!=null&&i.push(o[lr]),i}),providerLookupConcurrency:e.providerLookupConcurrency});let n=new or(t);this.pins=new Gt(e.datastore,n,this.dagWalkers),this.blockstore=new Jt(n,this.pins,{holdGcLock:e.holdGcLock??!0}),this.datastore=e.datastore,t.blockBrokers=e.blockBrokers.map(o=>o(t))}async start(){await Fi(this.datastore),await de(this.blockstore,this.datastore,this.routing)}async stop(){await pe(this.blockstore,this.datastore,this.routing)}async gc(e={}){let t=await this.blockstore.lock.writeLock();try{let n=this,o=this.blockstore.unwrap();this.log("gc start"),await Qr(o.deleteMany(async function*(){for await(let{cid:i}of o.getAll())try{if(await n.pins.isPinned(i,e))continue;yield i,e.onProgress?.(new D("helia:gc:deleted",i))}catch(s){n.log.error("Error during gc",s),e.onProgress?.(new D("helia:gc:error",s))}}()))}finally{t()}this.log("gc finished")}};return is(jc);})();
|
|
3
3
|
/*! Bundled license information:
|
|
4
4
|
|
|
5
5
|
@noble/hashes/esm/utils.js:
|
package/dist/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAA;AACxF,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAC9C,OAAO,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAA;AACvC,OAAO,KAAK,MAAM,UAAU,CAAA;AAC5B,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAA;AACrD,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAA;AACpC,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,cAAc,CAAA;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAC3C,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAC1D,OAAO,EAAE,+BAA+B,EAAE,MAAM,8BAA8B,CAAA;AAC9E,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAA;AAC3D,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAA;AAW/D,OAAO,EAAE,eAAe,EAAqC,MAAM,uBAAuB,CAAA;AAC1F,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AA+G/C,MAAM,OAAO,KAAK;IACT,UAAU,CAAc;IACxB,SAAS,CAAW;IACpB,IAAI,CAAM;IACV,MAAM,CAAiB;IACvB,OAAO,CAAS;IAChB,UAAU,CAA2B;IACrC,OAAO,CAAiC;IACxC,GAAG,CAAK;IACR,OAAO,CAAU;IACP,GAAG,CAAQ;IAE5B,YAAa,IAAe;QAC1B,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,IAAI,aAAa,EAAE,CAAA;QAC5C,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,OAAO,CAAC,CAAA;QAC5C,IAAI,CAAC,OAAO,GAAG,cAAc,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;QAC3C,IAAI,CAAC,UAAU,GAAG,iBAAiB,CAAC,IAAI,CAAC,UAAU,CAAC,CAAA;QACpD,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC,GAAG,IAAI,GAAG,EAAE,CAAA;QAC5B,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAA;QAE3B,sCAAsC;QACtC,MAAM,UAAU,GAAe;YAC7B,UAAU,EAAE,IAAI,CAAC,UAAU;YAC3B,SAAS,EAAE,IAAI,CAAC,SAAS;YACzB,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,UAAU,EAAE,IAAI,CAAC,UAAU;YAC3B,MAAM,EAAE,IAAI,CAAC,MAAM;YACnB,YAAY,EAAE,EAAE;YAChB,GAAG,EAAE,IAAI,CAAC,GAAG;YACb,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,GAAG,CAAC,IAAI,CAAC,UAAU,IAAI,EAAE,CAAC;SAC3B,CAAA;QAED,IAAI,CAAC,OAAO,GAAG,UAAU,CAAC,OAAO,GAAG,IAAI,YAAY,CAAC,UAAU,EAAE;YAC/D,OAAO,EAAE,CAAC,IAAI,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,MAAW,EAAE,EAAE;gBACpD,mCAAmC;gBACnC,MAAM,OAAO,GAAG;oBACd,MAAM;iBACP,CAAA;gBAED,sDAAsD;gBACtD,IAAI,MAAM,CAAC,oBAAoB,CAAC,IAAI,IAAI,EAAE,CAAC;oBACzC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,oBAAoB,CAAC,CAAC,CAAA;gBAC5C,CAAC;gBAED,mDAAmD;gBACnD,IAAI,MAAM,CAAC,iBAAiB,CAAC,IAAI,IAAI,EAAE,CAAC;oBACtC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,iBAAiB,CAAC,CAAC,CAAA;gBACzC,CAAC;gBAED,OAAO,OAAO,CAAA;YAChB,CAAC,CAAC;YACF,yBAAyB,EAAE,IAAI,CAAC,yBAAyB;SAC1D,CAAC,CAAA;QAEF,MAAM,gBAAgB,GAAG,IAAI,gBAAgB,CAAC,UAAU,CAAC,CAAA;QACzD,IAAI,CAAC,IAAI,GAAG,IAAI,QAAQ,CAAC,IAAI,CAAC,SAAS,EAAE,gBAAgB,EAAE,IAAI,CAAC,UAAU,CAAC,CAAA;QAC3E,IAAI,CAAC,UAAU,GAAG,IAAI,YAAY,CAAC,gBAAgB,EAAE,IAAI,CAAC,IAAI,EAAE;YAC9D,UAAU,EAAE,IAAI,CAAC,UAAU,IAAI,IAAI;SACpC,CAAC,CAAA;QACF,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,SAAS,CAAA;QAE/B,UAAU,CAAC,YAAY,GAAG,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE;YACrD,OAAO,EAAE,CAAC,UAAU,CAAC,CAAA;QACvB,CAAC,CAAC,CAAA;IACJ,CAAC;IAED,KAAK,CAAC,KAAK;QACT,MAAM,+BAA+B,CAAC,IAAI,CAAC,SAAS,CAAC,CAAA;QACrD,MAAM,KAAK,CACT,IAAI,CAAC,UAAU,EACf,IAAI,CAAC,SAAS,EACd,IAAI,CAAC,OAAO,CACb,CAAA;IACH,CAAC;IAED,KAAK,CAAC,IAAI;QACR,MAAM,IAAI,CACR,IAAI,CAAC,UAAU,EACf,IAAI,CAAC,SAAS,EACd,IAAI,CAAC,OAAO,CACb,CAAA;IACH,CAAC;IAED,KAAK,CAAC,EAAE,CAAE,UAAqB,EAAE;QAC/B,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,SAAS,EAAE,CAAA;QAE1D,IAAI,CAAC;YACH,MAAM,KAAK,GAAG,IAAI,CAAA;YAClB,MAAM,UAAU,GAAG,IAAI,CAAC,UAAU,CAAC,MAAM,EAAE,CAAA;YAE3C,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,CAAA;YAEpB,MAAM,KAAK,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC,KAAK,SAAU,CAAC;gBACjD,IAAI,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,IAAI,UAAU,CAAC,MAAM,EAAE,EAAE,CAAC;oBAChD,IAAI,CAAC;wBACH,IAAI,MAAM,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,EAAE,OAAO,CAAC,EAAE,CAAC;4BAC5C,SAAQ;wBACV,CAAC;wBAED,MAAM,GAAG,CAAA;wBAET,OAAO,CAAC,UAAU,EAAE,CAAC,IAAI,mBAAmB,CAAM,kBAAkB,EAAE,GAAG,CAAC,CAAC,CAAA;oBAC7E,CAAC;oBAAC,OAAO,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAA;AACxF,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAC9C,OAAO,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAA;AACvC,OAAO,KAAK,MAAM,UAAU,CAAA;AAC5B,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAA;AACrD,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAA;AACpC,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,cAAc,CAAA;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAC3C,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAC1D,OAAO,EAAE,+BAA+B,EAAE,MAAM,8BAA8B,CAAA;AAC9E,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAA;AAC3D,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAA;AAW/D,OAAO,EAAE,eAAe,EAAqC,MAAM,uBAAuB,CAAA;AAC1F,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AA+G/C,MAAM,OAAO,KAAK;IACT,UAAU,CAAc;IACxB,SAAS,CAAW;IACpB,IAAI,CAAM;IACV,MAAM,CAAiB;IACvB,OAAO,CAAS;IAChB,UAAU,CAA2B;IACrC,OAAO,CAAiC;IACxC,GAAG,CAAK;IACR,OAAO,CAAU;IACP,GAAG,CAAQ;IAE5B,YAAa,IAAe;QAC1B,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,IAAI,aAAa,EAAE,CAAA;QAC5C,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,OAAO,CAAC,CAAA;QAC5C,IAAI,CAAC,OAAO,GAAG,cAAc,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;QAC3C,IAAI,CAAC,UAAU,GAAG,iBAAiB,CAAC,IAAI,CAAC,UAAU,CAAC,CAAA;QACpD,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC,GAAG,IAAI,GAAG,EAAE,CAAA;QAC5B,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAA;QAE3B,sCAAsC;QACtC,MAAM,UAAU,GAAe;YAC7B,UAAU,EAAE,IAAI,CAAC,UAAU;YAC3B,SAAS,EAAE,IAAI,CAAC,SAAS;YACzB,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,UAAU,EAAE,IAAI,CAAC,UAAU;YAC3B,MAAM,EAAE,IAAI,CAAC,MAAM;YACnB,YAAY,EAAE,EAAE;YAChB,GAAG,EAAE,IAAI,CAAC,GAAG;YACb,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,GAAG,CAAC,IAAI,CAAC,UAAU,IAAI,EAAE,CAAC;SAC3B,CAAA;QAED,IAAI,CAAC,OAAO,GAAG,UAAU,CAAC,OAAO,GAAG,IAAI,YAAY,CAAC,UAAU,EAAE;YAC/D,OAAO,EAAE,CAAC,IAAI,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,MAAW,EAAE,EAAE;gBACpD,mCAAmC;gBACnC,MAAM,OAAO,GAAG;oBACd,MAAM;iBACP,CAAA;gBAED,sDAAsD;gBACtD,IAAI,MAAM,CAAC,oBAAoB,CAAC,IAAI,IAAI,EAAE,CAAC;oBACzC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,oBAAoB,CAAC,CAAC,CAAA;gBAC5C,CAAC;gBAED,mDAAmD;gBACnD,IAAI,MAAM,CAAC,iBAAiB,CAAC,IAAI,IAAI,EAAE,CAAC;oBACtC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,iBAAiB,CAAC,CAAC,CAAA;gBACzC,CAAC;gBAED,OAAO,OAAO,CAAA;YAChB,CAAC,CAAC;YACF,yBAAyB,EAAE,IAAI,CAAC,yBAAyB;SAC1D,CAAC,CAAA;QAEF,MAAM,gBAAgB,GAAG,IAAI,gBAAgB,CAAC,UAAU,CAAC,CAAA;QACzD,IAAI,CAAC,IAAI,GAAG,IAAI,QAAQ,CAAC,IAAI,CAAC,SAAS,EAAE,gBAAgB,EAAE,IAAI,CAAC,UAAU,CAAC,CAAA;QAC3E,IAAI,CAAC,UAAU,GAAG,IAAI,YAAY,CAAC,gBAAgB,EAAE,IAAI,CAAC,IAAI,EAAE;YAC9D,UAAU,EAAE,IAAI,CAAC,UAAU,IAAI,IAAI;SACpC,CAAC,CAAA;QACF,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,SAAS,CAAA;QAE/B,UAAU,CAAC,YAAY,GAAG,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE;YACrD,OAAO,EAAE,CAAC,UAAU,CAAC,CAAA;QACvB,CAAC,CAAC,CAAA;IACJ,CAAC;IAED,KAAK,CAAC,KAAK;QACT,MAAM,+BAA+B,CAAC,IAAI,CAAC,SAAS,CAAC,CAAA;QACrD,MAAM,KAAK,CACT,IAAI,CAAC,UAAU,EACf,IAAI,CAAC,SAAS,EACd,IAAI,CAAC,OAAO,CACb,CAAA;IACH,CAAC;IAED,KAAK,CAAC,IAAI;QACR,MAAM,IAAI,CACR,IAAI,CAAC,UAAU,EACf,IAAI,CAAC,SAAS,EACd,IAAI,CAAC,OAAO,CACb,CAAA;IACH,CAAC;IAED,KAAK,CAAC,EAAE,CAAE,UAAqB,EAAE;QAC/B,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,SAAS,EAAE,CAAA;QAE1D,IAAI,CAAC;YACH,MAAM,KAAK,GAAG,IAAI,CAAA;YAClB,MAAM,UAAU,GAAG,IAAI,CAAC,UAAU,CAAC,MAAM,EAAE,CAAA;YAE3C,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,CAAA;YAEpB,MAAM,KAAK,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC,KAAK,SAAU,CAAC;gBACjD,IAAI,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,IAAI,UAAU,CAAC,MAAM,EAAE,EAAE,CAAC;oBAChD,IAAI,CAAC;wBACH,IAAI,MAAM,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,EAAE,OAAO,CAAC,EAAE,CAAC;4BAC5C,SAAQ;wBACV,CAAC;wBAED,MAAM,GAAG,CAAA;wBAET,OAAO,CAAC,UAAU,EAAE,CAAC,IAAI,mBAAmB,CAAM,kBAAkB,EAAE,GAAG,CAAC,CAAC,CAAA;oBAC7E,CAAC;oBAAC,OAAO,GAAQ,EAAE,CAAC;wBAClB,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,iBAAiB,EAAE,GAAG,CAAC,CAAA;wBACvC,OAAO,CAAC,UAAU,EAAE,CAAC,IAAI,mBAAmB,CAAQ,gBAAgB,EAAE,GAAG,CAAC,CAAC,CAAA;oBAC7E,CAAC;gBACH,CAAC;YACH,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;QACR,CAAC;gBAAS,CAAC;YACT,WAAW,EAAE,CAAA;QACf,CAAC;QAED,IAAI,CAAC,GAAG,CAAC,aAAa,CAAC,CAAA;IACzB,CAAC;CACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@helia/utils",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.3-3bf5ab0",
|
|
4
4
|
"description": "Shared code that implements the Helia API",
|
|
5
5
|
"license": "Apache-2.0 OR MIT",
|
|
6
6
|
"homepage": "https://github.com/ipfs/helia/tree/main/packages/utils#readme",
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"test:electron-main": "aegir test -t electron-main"
|
|
54
54
|
},
|
|
55
55
|
"dependencies": {
|
|
56
|
-
"@helia/interface": "
|
|
56
|
+
"@helia/interface": "4.3.1-3bf5ab0",
|
|
57
57
|
"@ipld/dag-cbor": "^9.2.0",
|
|
58
58
|
"@ipld/dag-json": "^10.2.0",
|
|
59
59
|
"@ipld/dag-pb": "^4.1.0",
|
|
@@ -84,12 +84,12 @@
|
|
|
84
84
|
"devDependencies": {
|
|
85
85
|
"@libp2p/peer-id-factory": "^4.0.9",
|
|
86
86
|
"@types/sinon": "^17.0.3",
|
|
87
|
-
"aegir": "^
|
|
87
|
+
"aegir": "^44.0.1",
|
|
88
88
|
"datastore-core": "^9.2.9",
|
|
89
89
|
"delay": "^6.0.0",
|
|
90
90
|
"it-all": "^3.0.4",
|
|
91
91
|
"race-signal": "^1.0.2",
|
|
92
|
-
"sinon": "^
|
|
92
|
+
"sinon": "^18.0.0",
|
|
93
93
|
"sinon-ts": "^2.0.0"
|
|
94
94
|
},
|
|
95
95
|
"browser": {
|
package/src/index.ts
CHANGED
|
@@ -254,7 +254,7 @@ export class Helia implements HeliaInterface {
|
|
|
254
254
|
yield cid
|
|
255
255
|
|
|
256
256
|
options.onProgress?.(new CustomProgressEvent<CID>('helia:gc:deleted', cid))
|
|
257
|
-
} catch (err) {
|
|
257
|
+
} catch (err: any) {
|
|
258
258
|
helia.log.error('Error during gc', err)
|
|
259
259
|
options.onProgress?.(new CustomProgressEvent<Error>('helia:gc:error', err))
|
|
260
260
|
}
|
package/dist/typedoc-urls.json
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"AbstractSession": "https://ipfs.github.io/helia/classes/_helia_utils.AbstractSession.html",
|
|
3
|
-
"BloomFilter": "https://ipfs.github.io/helia/classes/_helia_utils.BloomFilter.html",
|
|
4
|
-
"Helia": "https://ipfs.github.io/helia/classes/_helia_utils.Helia.html",
|
|
5
|
-
".:Helia": "https://ipfs.github.io/helia/classes/_helia_utils.Helia.html",
|
|
6
|
-
"AbstractCreateSessionOptions": "https://ipfs.github.io/helia/interfaces/_helia_utils.AbstractCreateSessionOptions.html",
|
|
7
|
-
"HeliaInit": "https://ipfs.github.io/helia/interfaces/_helia_utils.HeliaInit.html",
|
|
8
|
-
".:HeliaInit": "https://ipfs.github.io/helia/interfaces/_helia_utils.HeliaInit.html"
|
|
9
|
-
}
|