@helia/utils 0.3.3-5ff6998 → 0.3.3-9de08ef
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/dist/index.min.js +1 -1
- package/dist/src/index.d.ts +4 -15
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +9 -9
- package/dist/src/index.js.map +1 -1
- package/dist/src/pins.d.ts +3 -3
- package/dist/src/pins.d.ts.map +1 -1
- package/dist/src/pins.js +9 -8
- package/dist/src/pins.js.map +1 -1
- package/dist/src/utils/dag-walkers.d.ts +28 -0
- package/dist/src/utils/dag-walkers.d.ts.map +1 -0
- package/dist/src/utils/dag-walkers.js +171 -0
- package/dist/src/utils/dag-walkers.js.map +1 -0
- package/dist/src/utils/default-hashers.d.ts +3 -0
- package/dist/src/utils/default-hashers.d.ts.map +1 -0
- package/dist/src/utils/default-hashers.js +15 -0
- package/dist/src/utils/default-hashers.js.map +1 -0
- package/dist/src/utils/networked-storage.d.ts +2 -3
- package/dist/src/utils/networked-storage.d.ts.map +1 -1
- package/dist/src/utils/networked-storage.js +6 -16
- package/dist/src/utils/networked-storage.js.map +1 -1
- package/package.json +2 -2
- package/src/index.ts +13 -26
- package/src/pins.ts +12 -9
- package/src/utils/dag-walkers.ts +198 -0
- package/src/utils/default-hashers.ts +18 -0
- package/src/utils/networked-storage.ts +8 -21
- package/dist/src/utils/get-codec.d.ts +0 -4
- package/dist/src/utils/get-codec.d.ts.map +0 -1
- package/dist/src/utils/get-codec.js +0 -38
- package/dist/src/utils/get-codec.js.map +0 -1
- package/dist/src/utils/get-hasher.d.ts +0 -4
- package/dist/src/utils/get-hasher.d.ts.map +0 -1
- package/dist/src/utils/get-hasher.js +0 -32
- package/dist/src/utils/get-hasher.js.map +0 -1
- package/dist/src/utils/is-promise.d.ts +0 -2
- package/dist/src/utils/is-promise.d.ts.map +0 -1
- package/dist/src/utils/is-promise.js +0 -4
- package/dist/src/utils/is-promise.js.map +0 -1
- package/src/utils/get-codec.ts +0 -47
- package/src/utils/get-hasher.ts +0 -40
- package/src/utils/is-promise.ts +0 -3
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 ks=Object.create;var gt=Object.defineProperty;var As=Object.getOwnPropertyDescriptor;var Cs=Object.getOwnPropertyNames;var Ts=Object.getPrototypeOf,Ss=Object.prototype.hasOwnProperty;var yt=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),N=(r,e)=>{for(var t in e)gt(r,t,{get:e[t],enumerable:!0})},Yn=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Cs(e))!Ss.call(r,o)&&o!==t&>(r,o,{get:()=>e[o],enumerable:!(n=As(e,o))||n.enumerable});return r};var Ar=(r,e,t)=>(t=r!=null?ks(Ts(r)):{},Yn(e||!r||!r.__esModule?gt(t,"default",{value:r,enumerable:!0}):t,r)),Ls=r=>Yn(gt({},"__esModule",{value:!0}),r);var co=yt((xf,$r)=>{"use strict";var aa=Object.prototype.hasOwnProperty,M="~";function Xe(){}Object.create&&(Xe.prototype=Object.create(null),new Xe().__proto__||(M=!1));function ca(r,e,t){this.fn=r,this.context=e,this.once=t||!1}function ao(r,e,t,n,o){if(typeof t!="function")throw new TypeError("The listener must be a function");var i=new ca(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 kt(r,e){--r._eventsCount===0?r._events=new Xe:delete r._events[e]}function O(){this._events=new Xe,this._eventsCount=0}O.prototype.eventNames=function(){var e=[],t,n;if(this._eventsCount===0)return e;for(n in t=this._events)aa.call(t,n)&&e.push(M?n.slice(1):n);return Object.getOwnPropertySymbols?e.concat(Object.getOwnPropertySymbols(t)):e};O.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};O.prototype.listenerCount=function(e){var t=M?M+e:e,n=this._events[t];return n?n.fn?1:n.length:0};O.prototype.emit=function(e,t,n,o,i,s){var u=M?M+e:e;if(!this._events[u])return!1;var f=this._events[u],p=arguments.length,d,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,d=new Array(p-1);l<p;l++)d[l-1]=arguments[l];f.fn.apply(f.context,d)}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(!d)for(a=1,d=new Array(p-1);a<p;a++)d[a-1]=arguments[a];f[l].fn.apply(f[l].context,d)}}return!0};O.prototype.on=function(e,t,n){return ao(this,e,t,n,!1)};O.prototype.once=function(e,t,n){return ao(this,e,t,n,!0)};O.prototype.removeListener=function(e,t,n,o){var i=M?M+e:e;if(!this._events[i])return this;if(!t)return kt(this,i),this;var s=this._events[i];if(s.fn)s.fn===t&&(!o||s.once)&&(!n||s.context===n)&&kt(this,i);else{for(var u=0,f=[],p=s.length;u<p;u++)(s[u].fn!==t||o&&!s[u].once||n&&s[u].context!==n)&&f.push(s[u]);f.length?this._events[i]=f.length===1?f[0]:f:kt(this,i)}return this};O.prototype.removeAllListeners=function(e){var t;return e?(t=M?M+e:e,this._events[t]&&kt(this,t)):(this._events=new Xe,this._eventsCount=0),this};O.prototype.off=O.prototype.removeListener;O.prototype.addListener=O.prototype.on;O.prefixed=M;O.EventEmitter=O;typeof $r<"u"&&($r.exports=O)});var Io=yt((Cl,Lo)=>{Lo.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 ws=yt((dt,br)=>{(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 h=0;h<a.length;h++)if(!Number.isInteger(a[h])||a[h]<0||a[h]>255)return!1;return!0}function o(a,h){return(a&65535)*h+(((a>>>16)*h&65535)<<16)}function i(a,h){return a<<h|a>>>32-h}function s(a){return a^=a>>>16,a=o(a,2246822507),a^=a>>>13,a=o(a,3266489909),a^=a>>>16,a}function u(a,h){a=[a[0]>>>16,a[0]&65535,a[1]>>>16,a[1]&65535],h=[h[0]>>>16,h[0]&65535,h[1]>>>16,h[1]&65535];var g=[0,0,0,0];return g[3]+=a[3]+h[3],g[2]+=g[3]>>>16,g[3]&=65535,g[2]+=a[2]+h[2],g[1]+=g[2]>>>16,g[2]&=65535,g[1]+=a[1]+h[1],g[0]+=g[1]>>>16,g[1]&=65535,g[0]+=a[0]+h[0],g[0]&=65535,[g[0]<<16|g[1],g[2]<<16|g[3]]}function f(a,h){a=[a[0]>>>16,a[0]&65535,a[1]>>>16,a[1]&65535],h=[h[0]>>>16,h[0]&65535,h[1]>>>16,h[1]&65535];var g=[0,0,0,0];return g[3]+=a[3]*h[3],g[2]+=g[3]>>>16,g[3]&=65535,g[2]+=a[2]*h[3],g[1]+=g[2]>>>16,g[2]&=65535,g[2]+=a[3]*h[2],g[1]+=g[2]>>>16,g[2]&=65535,g[1]+=a[1]*h[3],g[0]+=g[1]>>>16,g[1]&=65535,g[1]+=a[2]*h[2],g[0]+=g[1]>>>16,g[1]&=65535,g[1]+=a[3]*h[1],g[0]+=g[1]>>>16,g[1]&=65535,g[0]+=a[0]*h[3]+a[1]*h[2]+a[2]*h[1]+a[3]*h[0],g[0]&=65535,[g[0]<<16|g[1],g[2]<<16|g[3]]}function p(a,h){return h%=64,h===32?[a[1],a[0]]:h<32?[a[0]<<h|a[1]>>>32-h,a[1]<<h|a[0]>>>32-h]:(h-=32,[a[1]<<h|a[0]>>>32-h,a[0]<<h|a[1]>>>32-h])}function d(a,h){return h%=64,h===0?a:h<32?[a[0]<<h|a[1]>>>32-h,a[1]<<h]:[a[1]<<h-32,0]}function l(a,h){return[a[0]^h[0],a[1]^h[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,h){if(t.inputValidation&&!n(a))return e;h=h||0;for(var g=a.length%4,A=a.length-g,y=h,w=0,b=3432918353,E=461845907,T=0;T<A;T=T+4)w=a[T]|a[T+1]<<8|a[T+2]<<16|a[T+3]<<24,w=o(w,b),w=i(w,15),w=o(w,E),y^=w,y=i(y,13),y=o(y,5)+3864292196;switch(w=0,g){case 3:w^=a[T+2]<<16;case 2:w^=a[T+1]<<8;case 1:w^=a[T],w=o(w,b),w=i(w,15),w=o(w,E),y^=w}return y^=a.length,y=s(y),y>>>0},t.x86.hash128=function(a,h){if(t.inputValidation&&!n(a))return e;h=h||0;for(var g=a.length%16,A=a.length-g,y=h,w=h,b=h,E=h,T=0,S=0,v=0,I=0,G=597399067,ht=2869860233,pt=951274213,mt=2716044179,L=0;L<A;L=L+16)T=a[L]|a[L+1]<<8|a[L+2]<<16|a[L+3]<<24,S=a[L+4]|a[L+5]<<8|a[L+6]<<16|a[L+7]<<24,v=a[L+8]|a[L+9]<<8|a[L+10]<<16|a[L+11]<<24,I=a[L+12]|a[L+13]<<8|a[L+14]<<16|a[L+15]<<24,T=o(T,G),T=i(T,15),T=o(T,ht),y^=T,y=i(y,19),y+=w,y=o(y,5)+1444728091,S=o(S,ht),S=i(S,16),S=o(S,pt),w^=S,w=i(w,17),w+=b,w=o(w,5)+197830471,v=o(v,pt),v=i(v,17),v=o(v,mt),b^=v,b=i(b,15),b+=E,b=o(b,5)+2530024501,I=o(I,mt),I=i(I,18),I=o(I,G),E^=I,E=i(E,13),E+=y,E=o(E,5)+850148119;switch(T=0,S=0,v=0,I=0,g){case 15:I^=a[L+14]<<16;case 14:I^=a[L+13]<<8;case 13:I^=a[L+12],I=o(I,mt),I=i(I,18),I=o(I,G),E^=I;case 12:v^=a[L+11]<<24;case 11:v^=a[L+10]<<16;case 10:v^=a[L+9]<<8;case 9:v^=a[L+8],v=o(v,pt),v=i(v,17),v=o(v,mt),b^=v;case 8:S^=a[L+7]<<24;case 7:S^=a[L+6]<<16;case 6:S^=a[L+5]<<8;case 5:S^=a[L+4],S=o(S,ht),S=i(S,16),S=o(S,pt),w^=S;case 4:T^=a[L+3]<<24;case 3:T^=a[L+2]<<16;case 2:T^=a[L+1]<<8;case 1:T^=a[L],T=o(T,G),T=i(T,15),T=o(T,ht),y^=T}return y^=a.length,w^=a.length,b^=a.length,E^=a.length,y+=w,y+=b,y+=E,w+=y,b+=y,E+=y,y=s(y),w=s(w),b=s(b),E=s(E),y+=w,y+=b,y+=E,w+=y,b+=y,E+=y,("00000000"+(y>>>0).toString(16)).slice(-8)+("00000000"+(w>>>0).toString(16)).slice(-8)+("00000000"+(b>>>0).toString(16)).slice(-8)+("00000000"+(E>>>0).toString(16)).slice(-8)},t.x64.hash128=function(a,h){if(t.inputValidation&&!n(a))return e;h=h||0;for(var g=a.length%16,A=a.length-g,y=[0,h],w=[0,h],b=[0,0],E=[0,0],T=[2277735313,289559509],S=[1291169091,658871167],v=0;v<A;v=v+16)b=[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],b=f(b,T),b=p(b,31),b=f(b,S),y=l(y,b),y=p(y,27),y=u(y,w),y=u(f(y,[0,5]),[0,1390208809]),E=f(E,S),E=p(E,33),E=f(E,T),w=l(w,E),w=p(w,31),w=u(w,y),w=u(f(w,[0,5]),[0,944331445]);switch(b=[0,0],E=[0,0],g){case 15:E=l(E,d([0,a[v+14]],48));case 14:E=l(E,d([0,a[v+13]],40));case 13:E=l(E,d([0,a[v+12]],32));case 12:E=l(E,d([0,a[v+11]],24));case 11:E=l(E,d([0,a[v+10]],16));case 10:E=l(E,d([0,a[v+9]],8));case 9:E=l(E,[0,a[v+8]]),E=f(E,S),E=p(E,33),E=f(E,T),w=l(w,E);case 8:b=l(b,d([0,a[v+7]],56));case 7:b=l(b,d([0,a[v+6]],48));case 6:b=l(b,d([0,a[v+5]],40));case 5:b=l(b,d([0,a[v+4]],32));case 4:b=l(b,d([0,a[v+3]],24));case 3:b=l(b,d([0,a[v+2]],16));case 2:b=l(b,d([0,a[v+1]],8));case 1:b=l(b,[0,a[v]]),b=f(b,T),b=p(b,31),b=f(b,S),y=l(y,b)}return y=l(y,[0,a.length]),w=l(w,[0,a.length]),y=u(y,w),w=u(w,y),y=C(y),w=C(w),y=u(y,w),w=u(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 br<"u"&&br.exports&&(dt=br.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 bs=yt((cm,xs)=>{xs.exports=ws()});var zu={};N(zu,{AbstractSession:()=>kr,BloomFilter:()=>Je,Helia:()=>Xn,hasCode:()=>Ru});var Cr=Symbol.for("@libp2p/content-routing");var Tr=Symbol.for("@libp2p/peer-routing");var ne=class extends Error{static name="AbortError";constructor(e="The operation was aborted"){super(e),this.name="AbortError"}};var _e=class extends Error{static name="InvalidParametersError";constructor(e="Invalid parameters"){super(e),this.name="InvalidParametersError"}};var wt=class extends Error{static name="NotFoundError";constructor(e="Not found"){super(e),this.name="NotFoundError"}};var xt=class extends Error{static name="InvalidMultihashError";constructor(e="Invalid Multihash"){super(e),this.name="InvalidMultihashError"}};var $=(r,...e)=>{try{[...e]}catch{}};var Ue=class extends EventTarget{#e=new Map;constructor(){super(),$(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 CustomEvent(e,t))}};function Zn(r){return r!=null&&typeof r.start=="function"&&typeof r.stop=="function"}async function de(...r){let e=[];for(let t of r)Zn(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 he(...r){let e=[];for(let t of r)Zn(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 Pr={};N(Pr,{base32:()=>me,base32hex:()=>Fs,base32hexpad:()=>Ms,base32hexpadupper:()=>Rs,base32hexupper:()=>Os,base32pad:()=>Bs,base32padupper:()=>$s,base32upper:()=>Ns,base32z:()=>zs});var Ju=new Uint8Array(0);function eo(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 Q(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 to(r){return new TextEncoder().encode(r)}function ro(r){return new TextDecoder().decode(r)}function Is(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 u=r.length,f=r.charAt(0),p=Math.log(u)/Math.log(256),d=Math.log(256)/Math.log(u);function l(h){if(h instanceof Uint8Array||(ArrayBuffer.isView(h)?h=new Uint8Array(h.buffer,h.byteOffset,h.byteLength):Array.isArray(h)&&(h=Uint8Array.from(h))),!(h instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(h.length===0)return"";for(var g=0,A=0,y=0,w=h.length;y!==w&&h[y]===0;)y++,g++;for(var b=(w-y)*d+1>>>0,E=new Uint8Array(b);y!==w;){for(var T=h[y],S=0,v=b-1;(T!==0||S<A)&&v!==-1;v--,S++)T+=256*E[v]>>>0,E[v]=T%u>>>0,T=T/u>>>0;if(T!==0)throw new Error("Non-zero carry");A=S,y++}for(var I=b-A;I!==b&&E[I]===0;)I++;for(var G=f.repeat(g);I<b;++I)G+=r.charAt(E[I]);return G}function C(h){if(typeof h!="string")throw new TypeError("Expected String");if(h.length===0)return new Uint8Array;var g=0;if(h[g]!==" "){for(var A=0,y=0;h[g]===f;)A++,g++;for(var w=(h.length-g)*p+1>>>0,b=new Uint8Array(w);h[g];){var E=t[h.charCodeAt(g)];if(E===255)return;for(var T=0,S=w-1;(E!==0||T<y)&&S!==-1;S--,T++)E+=u*b[S]>>>0,b[S]=E%256>>>0,E=E/256>>>0;if(E!==0)throw new Error("Non-zero carry");y=T,g++}if(h[g]!==" "){for(var v=w-y;v!==w&&b[v]===0;)v++;for(var I=new Uint8Array(A+(w-v)),G=A;v!==w;)I[G++]=b[v++];return I}}}function a(h){var g=C(h);if(g)return g;throw new Error(`Non-${e} character`)}return{encode:l,decodeUnsafe:C,decode:a}}var _s=Is,Us=_s,no=Us;var Lr=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")}},Ir=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,t,n){this.name=e,this.prefix=t;let o=t.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,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 oo(this,e)}},_r=class{decoders;constructor(e){this.decoders=e}or(e){return oo(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 oo(r,e){return new _r({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}var Ur=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 Lr(e,t,n),this.decoder=new Ir(e,t,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function Pe({name:r,prefix:e,encode:t,decode:n}){return new Ur(r,e,t,n)}function pe({name:r,prefix:e,alphabet:t}){let{encode:n,decode:o}=no(t,r);return Pe({prefix:e,name:r,encode:n,decode:i=>Q(o(i))})}function Ps(r,e,t,n){let o={};for(let d=0;d<e.length;++d)o[e[d]]=d;let i=r.length;for(;r[i-1]==="=";)--i;let s=new Uint8Array(i*t/8|0),u=0,f=0,p=0;for(let d=0;d<i;++d){let l=o[r[d]];if(l===void 0)throw new SyntaxError(`Non-${n} character`);f=f<<t|l,u+=t,u>=8&&(u-=8,s[p++]=255&f>>u)}if(u>=t||255&f<<8-u)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,u=0;for(let f=0;f<r.length;++f)for(u=u<<8|r[f],s+=8;s>t;)s-=t,i+=e[o&u>>s];if(s!==0&&(i+=e[o&u<<t-s]),n)for(;i.length*t&7;)i+="=";return i}function D({name:r,prefix:e,bitsPerChar:t,alphabet:n}){return Pe({prefix:e,name:r,encode(o){return Ds(o,n,t)},decode(o){return Ps(o,n,t,r)}})}var me=D({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Ns=D({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Bs=D({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),$s=D({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Fs=D({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Os=D({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Ms=D({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Rs=D({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),zs=D({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Dr={};N(Dr,{base58btc:()=>H,base58flickr:()=>qs});var H=pe({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),qs=pe({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Nr={};N(Nr,{base64:()=>ge,base64pad:()=>js,base64url:()=>Vs,base64urlpad:()=>Hs});var ge=D({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),js=D({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Vs=D({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Hs=D({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});function Ks(r,e){try{if(typeof r=="string"&&r.length>0)return Ws(r);if(typeof r=="number"&&isFinite(r))return e?.long?Qs(r):Gs(r);throw new Error("Value is not a string or number.")}catch(t){let n=Js(t)?`${t.message}. value=${JSON.stringify(r)}`:"An unknown error has occured.";throw new Error(n)}}function Ws(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 Et=Ks;function Gs(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 Qs(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 Js(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=Et,t.destroy=p,Object.keys(r).forEach(d=>{t[d]=r[d]}),t.names=[],t.skips=[],t.formatters={};function e(d){let l=0;for(let C=0;C<d.length;C++)l=(l<<5)-l+d.charCodeAt(C),l|=0;return t.colors[Math.abs(l)%t.colors.length]}t.selectColor=e;function t(d){let l,C=null,a,h;function g(...A){if(!g.enabled)return;let y=g,w=Number(new Date),b=w-(l||w);y.diff=b,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,(S,v)=>{if(S==="%%")return"%";E++;let I=t.formatters[v];if(typeof I=="function"){let G=A[E];S=I.call(y,G),A.splice(E,1),E--}return S}),t.formatArgs.call(y,A),(y.log||t.log).apply(y,A)}return g.namespace=d,g.useColors=t.useColors(),g.color=t.selectColor(d),g.extend=n,g.destroy=t.destroy,Object.defineProperty(g,"enabled",{enumerable:!0,configurable:!1,get:()=>C!==null?C:(a!==t.namespaces&&(a=t.namespaces,h=t.enabled(d)),h),set:A=>{C=A}}),typeof t.init=="function"&&t.init(g),g}function n(d,l){let C=t(this.namespace+(typeof l>"u"?":":l)+d);return C.log=this.log,C}function o(d){t.save(d),t.namespaces=d,t.names=[],t.skips=[];let l,C=(typeof d=="string"?d:"").split(/[\s,]+/),a=C.length;for(l=0;l<a;l++)C[l]&&(d=C[l].replace(/\*/g,".*?"),d[0]==="-"?t.skips.push(new RegExp("^"+d.substr(1)+"$")):t.names.push(new RegExp("^"+d+"$")))}function i(){let d=[...t.names.map(u),...t.skips.map(u).map(l=>"-"+l)].join(",");return t.enable(""),d}function s(d){if(d[d.length-1]==="*")return!0;let l,C;for(l=0,C=t.skips.length;l<C;l++)if(t.skips[l].test(d))return!1;for(l=0,C=t.names.length;l<C;l++)if(t.names[l].test(d))return!0;return!1}function u(d){return d.toString().substring(2,d.toString().length-2).replace(/\.\*\?$/,"*")}function f(d){return d instanceof Error?d.stack??d.message:d}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 vt=na(),Xs=["#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 Ys(){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 Zs(r){if(r[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+r[0]+(this.useColors?"%c ":" ")+"+"+Et(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 ea=console.debug??console.log??(()=>{});function ta(r){try{r?vt?.setItem("debug",r):vt?.removeItem("debug")}catch{}}function ra(){let r;try{r=vt?.getItem("debug")}catch{}return!r&&typeof process<"u"&&"env"in process&&(r=process.env.DEBUG),r}function na(){try{return localStorage}catch{}}function oa(r){r.j=function(e){try{return JSON.stringify(e)}catch(t){return"[UnexpectedJSONParseError]: "+t.message}}}var io=Br({formatArgs:Zs,save:ta,load:ra,useColors:Ys,setupFormatters:oa,colors:Xs,storage:vt,log:ea});var R=io;R.formatters.b=r=>r==null?"undefined":H.baseEncode(r);R.formatters.t=r=>r==null?"undefined":me.baseEncode(r);R.formatters.m=r=>r==null?"undefined":ge.baseEncode(r);R.formatters.p=r=>r==null?"undefined":r.toString();R.formatters.c=r=>r==null?"undefined":r.toString();R.formatters.k=r=>r==null?"undefined":r.toString();R.formatters.a=r=>r==null?"undefined":r.toString();function ia(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 so(){return{forComponent(r){return sa(r)}}}function sa(r){let e=ia(`${r}:trace`);return R.enabled(`${r}:trace`)&&R.names.map(t=>t.toString()).find(t=>t.includes(":trace"))!=null&&(e=R(`${r}:trace`)),Object.assign(R(r),{error:R(`${r}:error`),trace:e})}var U=class extends Event{type;detail;constructor(e,t){super(e),this.type=e,this.detail=t}};var Fr=Ar(co(),1);var Ye=class extends Error{constructor(e){super(e),this.name="TimeoutError"}},Or=class extends Error{constructor(e){super(),this.name="AbortError",this.message=e}},uo=r=>globalThis.DOMException===void 0?new Or(r):new DOMException(r),fo=r=>{let e=r.reason===void 0?uo("This operation was aborted."):r.reason;return e instanceof Error?e:uo(e)};function Ze(r,e){let{milliseconds:t,fallback:n,message:o,customTimers:i={setTimeout,clearTimeout}}=e,s,f=new Promise((p,d)=>{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&&d(fo(C)),C.addEventListener("abort",()=>{d(fo(C))})}if(t===Number.POSITIVE_INFINITY){r.then(p,d);return}let l=new Ye;s=i.setTimeout.call(void 0,()=>{if(n){try{p(n())}catch(C){d(C)}return}typeof r.cancel=="function"&&r.cancel(),o===!1?p():o instanceof Error?d(o):(l.message=o??`Promise timed out after ${t} milliseconds`,d(l))},t),(async()=>{try{p(await r)}catch(C){d(C)}})()}).finally(()=>{f.clear()});return f.clear=()=>{i.clearTimeout.call(void 0,s),s=void 0},f}function Mr(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=Mr(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 Fr.default{#e;#o;#s=0;#h;#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.#h=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#x(){return this.#o||this.#s<this.#h}get#b(){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.#x&&this.#b){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.#d("empty")}async onSizeLessThan(e){this.#t.size<e||await this.#d("next",()=>this.#t.size<e)}async onIdle(){this.#n===0&&this.#t.size===0||await this.#d("idle")}async#d(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 At(r){let e=[J.A];return r==null?e:Array.isArray(r)?r.length===0?e:r:[r]}var Rr={};N(Rr,{base10:()=>ua});var ua=pe({prefix:"9",name:"base10",alphabet:"0123456789"});var zr={};N(zr,{base16:()=>fa,base16upper:()=>la});var fa=D({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),la=D({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var qr={};N(qr,{base2:()=>da});var da=D({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var jr={};N(jr,{base256emoji:()=>ya});var lo=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}"),ha=lo.reduce((r,e,t)=>(r[t]=e,r),[]),pa=lo.reduce((r,e,t)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return r[n]=t,r},[]);function ma(r){return r.reduce((e,t)=>(e+=ha[t],e),"")}function ga(r){let e=[];for(let t of r){let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);let o=pa[n];if(o==null)throw new Error(`Non-base256emoji character: ${t}`);e.push(o)}return new Uint8Array(e)}var ya=Pe({prefix:"\u{1F680}",name:"base256emoji",encode:ma,decode:ga});var Vr={};N(Vr,{base36:()=>oe,base36upper:()=>wa});var oe=pe({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),wa=pe({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Hr={};N(Hr,{base8:()=>xa});var xa=D({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Kr={};N(Kr,{identity:()=>ba});var ba=Pe({prefix:"\0",name:"identity",encode:r=>ro(r),decode:r=>to(r)});var Ct={};N(Ct,{code:()=>Wr,decode:()=>Ca,encode:()=>Aa,name:()=>ka});var Ea=new TextEncoder,va=new TextDecoder,ka="json",Wr=512;function Aa(r){return Ea.encode(JSON.stringify(r))}function Ca(r){return JSON.parse(va.decode(r))}var Tt={};N(Tt,{code:()=>Gr,decode:()=>La,encode:()=>Sa,name:()=>Ta});var Ta="raw",Gr=85;function Sa(r){return Q(r)}function La(r){return Q(r)}var Jr={};N(Jr,{identity:()=>Lt});var Ia=mo,ho=128,_a=127,Ua=~_a,Pa=Math.pow(2,31);function mo(r,e,t){e=e||[],t=t||0;for(var n=t;r>=Pa;)e[t++]=r&255|ho,r/=128;for(;r&Ua;)e[t++]=r&255|ho,r>>>=7;return e[t]=r|0,mo.bytes=t-n+1,e}var Da=Qr,Na=128,po=127;function Qr(r,n){var t=0,n=n||0,o=0,i=n,s,u=r.length;do{if(i>=u)throw Qr.bytes=0,new RangeError("Could not decode varint");s=r[i++],t+=o<28?(s&po)<<o:(s&po)*Math.pow(2,o),o+=7}while(s>=Na);return Qr.bytes=i-n,t}var Ba=Math.pow(2,7),$a=Math.pow(2,14),Fa=Math.pow(2,21),Oa=Math.pow(2,28),Ma=Math.pow(2,35),Ra=Math.pow(2,42),za=Math.pow(2,49),qa=Math.pow(2,56),ja=Math.pow(2,63),Va=function(r){return r<Ba?1:r<$a?2:r<Fa?3:r<Oa?4:r<Ma?5:r<Ra?6:r<za?7:r<qa?8:r<ja?9:10},Ha={encode:Ia,decode:Da,encodingLength:Va},Ka=Ha,tt=Ka;function rt(r,e=0){return[tt.decode(r,e),tt.decode.bytes]}function De(r,e,t=0){return tt.encode(r,e,t),e}function Ne(r){return tt.encodingLength(r)}function ve(r,e){let t=e.byteLength,n=Ne(r),o=n+Ne(t),i=new Uint8Array(o+t);return De(r,i,0),De(t,i,n),i.set(e,o),new Be(r,t,e,i)}function go(r){let e=Q(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 Be(t,o,s,e)}function yo(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&eo(r.bytes,t.bytes)}}var Be=class{code;size;digest;bytes;constructor(e,t,n,o){this.code=e,this.size=t,this.digest=n,this.bytes=o}};var wo=0,Wa="identity",xo=Q;function Ga(r){return ve(wo,xo(r))}var Lt={code:wo,name:Wa,encode:xo,digest:Ga};var Zr={};N(Zr,{sha256:()=>It,sha512:()=>_t});function Yr({name:r,code:e,encode:t}){return new Xr(r,e,t)}var Xr=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?ve(this.code,t):t.then(n=>ve(this.code,n))}else throw Error("Unknown type, must be binary type")}};function Eo(r){return async e=>new Uint8Array(await crypto.subtle.digest(r,e))}var It=Yr({name:"sha2-256",code:18,encode:Eo("SHA-256")}),_t=Yr({name:"sha2-512",code:19,encode:Eo("SHA-512")});function vo(r,e){let{bytes:t,version:n}=r;switch(n){case 0:return Ja(t,en(r),e??H.encoder);default:return Xa(t,en(r),e??me.encoder)}}var ko=new WeakMap;function en(r){let e=ko.get(r);if(e==null){let t=new Map;return ko.set(r,t),t}return e}var P=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!==ot)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==Ya)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=ve(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&&yo(e.multihash,n.multihash)}toString(e){return vo(this,e)}toJSON(){return{"/":vo(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??Ao(n,o,i.bytes))}else if(t[Za]===!0){let{version:n,multihash:o,code:i}=t,s=go(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!==ot)throw new Error(`Version 0 CID must use dag-pb (code: ${ot}) block encoding`);return new r(e,t,n,n.bytes)}case 1:{let o=Ao(e,t,n.bytes);return new r(e,t,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return r.create(0,ot,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=Q(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 Be(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=ot;if(o===18?(o=0,t=0):i=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let s=t,u=n(),f=n(),p=t+f,d=p-s;return{version:o,codec:i,multihashCode:u,digestSize:f,multihashSize:d,size:p}}static parse(e,t){let[n,o]=Qa(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 en(i).set(n,e),i}};function Qa(r,e){switch(r[0]){case"Q":{let t=e??H;return[H.prefix,t.decode(`${H.prefix}${r}`)]}case H.prefix:{let t=e??H;return[H.prefix,t.decode(r)]}case me.prefix:{let t=e??me;return[me.prefix,t.decode(r)]}case oe.prefix:{let t=e??oe;return[oe.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 Ja(r,e,t){let{prefix:n}=t;if(n!==H.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 ot=112,Ya=18;function Ao(r,e,t){let n=Ne(r),o=n+Ne(e),i=new Uint8Array(o+t.byteLength);return De(r,i,0),De(e,i,n),i.set(t,o),i}var Za=Symbol.for("@ipld/js-cid/CID");var tn={...Kr,...qr,...Hr,...Rr,...zr,...Pr,...Vr,...Dr,...Nr,...jr},sl={...Zr,...Jr};function X(r=0){return new Uint8Array(r)}function ke(r=0){return new Uint8Array(r)}function To(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}var Co=To("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),rn=To("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=ke(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),ec={utf8:Co,"utf-8":Co,hex:tn.base16,latin1:rn,ascii:rn,binary:rn,...tn},Ut=ec;function $e(r,e="utf8"){let t=Ut[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.encoder.encode(r).substring(1)}var nn=60;function Pt(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??nn,data:e.data instanceof Uint8Array?$e(e.data):e.data}))}}var tc=4;function on(r,e={}){let t=new ye({concurrency:e.queryConcurrency??tc});return async(n,o={})=>{let i=new URLSearchParams;i.set("name",n),At(o.types).forEach(u=>{i.append("type",J[u])}),o.onProgress?.(new U("dns:query",{detail:n}));let s=await t.add(async()=>{let u=await fetch(`${r}?${i}`,{headers:{accept:"application/dns-json"},signal:o?.signal});if(u.status!==200)throw new Error(`Unexpected HTTP status: ${u.status} - ${u.statusText}`);let f=Pt(await u.json());return o.onProgress?.(new U("dns:response",{detail:f})),f},{signal:o.signal});if(s==null)throw new Error("No DNS response received");return s}}function So(){return[on("https://cloudflare-dns.com/dns-query"),on("https://dns.google/resolve")]}var _o=Ar(Io(),1);var sn=class{lru;constructor(e){this.lru=(0,_o.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 Pt({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:u})=>({...u,TTL:Math.round((s-Date.now())/1e3),type:J[u.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??nn)*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 Uo(r){return new sn(r)}var rc=1e3,Dt=class{resolvers;cache;constructor(e){this.resolvers={},this.cache=Uo(e.cacheSize??rc),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["."]=So())}async query(e,t={}){let n=At(t.types),o=t.cached!==!1?this.cache.get(e,n):void 0;if(o!=null)return t.onProgress?.(new U("dns:cache",{detail:o})),o;let i=`${e.split(".").pop()}.`,s=(this.resolvers[i]??this.resolvers["."]).sort(()=>Math.random()>.5?-1:1),u=[];for(let f of s){if(t.signal?.aborted===!0)break;try{let p=await f(e,{...t,types:n});for(let d of p.Answer)this.cache.add(e,d);return p}catch(p){u.push(p),t.onProgress?.(new U("dns:error",{detail:p}))}}throw u.length===1?u[0]:new AggregateError(u,`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 Po(r={}){return new Dt(r)}function nc(r){return r[Symbol.asyncIterator]!=null}function oc(r){if(nc(r))return(async()=>{for await(let e of r);})();for(let e of r);}var Do=oc;function ie(){let r={};return r.promise=new Promise((e,t)=>{r.resolve=e,r.reject=t}),r}var Nt=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 Nt(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 Nt(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 an=class extends Error{type;code;constructor(e,t){super(e??"The operation was aborted"),this.type="aborted",this.code=t??"ABORT_ERR"}};function Bt(r={}){return ic(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 ic(r,e){e=e??{};let t=e.onEnd,n=new Fe,o,i,s,u=ie(),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(b){y(b)}return o}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{u.resolve(),u=ie()})}},p=A=>i!=null?i(A):(n.push(A),o),d=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?d(A):p({done:!0})),a=()=>(n=new Fe,C(),{done:!0}),h=A=>(C(A),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:f,return:a,throw:h,push:l,end:C,get readableLength(){return n.size},onEmpty:async A=>{let y=A?.signal;if(y?.throwIfAborted(),n.isEmpty())return;let w,b;y!=null&&(w=new Promise((E,T)=>{b=()=>{T(new an)},y.addEventListener("abort",b)}));try{await Promise.race([u.promise,w])}finally{b!=null&&y!=null&&y?.removeEventListener("abort",b)}}},t==null)return o;let g=o;return o={[Symbol.asyncIterator](){return this},next(){return g.next()},throw(A){return g.throw(A),t!=null&&(t(A),t=void 0),{done:!0}},return(){return g.return(),t!=null&&(t(),t=void 0),{done:!0}},push:l,end(A){return g.end(A),t!=null&&(t(A),t=void 0),o},get readableLength(){return g.readableLength},onEmpty:A=>g.onEmpty(A)},o}var cn=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 $t(r,e,t,n){let o=new cn(n?.errorMessage,n?.errorCode);return t?.aborted===!0?Promise.reject(o):new Promise((i,s)=>{function u(){t?.removeEventListener("abort",d),r.removeEventListener(e,f),n?.errorEvent!=null&&r.removeEventListener(n.errorEvent,p)}let f=l=>{try{if(n?.filter?.(l)===!1)return}catch(C){u(),s(C);return}u(),i(l)},p=l=>{u(),s(l.detail)},d=()=>{u(),s(o)};t?.addEventListener("abort",d),r.addEventListener(e,f),n?.errorEvent!=null&&r.addEventListener(n.errorEvent,p)})}var Ft=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 No(r,e,t){if(e==null)return r;if(e.aborted)return Promise.reject(new Ft(t?.errorMessage,t?.errorCode,t?.errorName));let n,o=new Ft(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 Ot=class{deferred;signal;constructor(e){this.signal=e,this.deferred=ie(),this.onAbort=this.onAbort.bind(this),this.signal?.addEventListener("abort",this.onAbort)}onAbort(){this.deferred.reject(this.signal?.reason??new ne)}cleanup(){this.signal?.removeEventListener("abort",this.onAbort)}};function sc(){return`${parseInt(String(Math.random()*1e9),10).toString()}${Date.now()}`}var Mt=class{id;fn;options;recipients;status;timeline;controller;constructor(e,t){this.id=sc(),this.status="queued",this.fn=e,this.options=t,this.recipients=[],this.timeline={created:Date.now()},this.controller=new AbortController,$(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 ne),this.cleanup())}async join(e={}){let t=new Ot(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 No(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 se=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 Mt(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 ne)}),this.clear()}async onEmpty(e){this.size!==0&&await $t(this,"empty",e?.signal)}async onSizeLessThan(e,t){this.size<e||await $t(this,"next",t?.signal,{filter:()=>this.size<e})}async onIdle(e){this.pending===0&&this.size===0||await $t(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=Bt({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()},u=()=>{n(new ne("Queue aborted"))};this.addEventListener("completed",o),this.addEventListener("error",i),this.addEventListener("idle",s),e?.signal?.addEventListener("abort",u);try{yield*t}finally{this.removeEventListener("completed",o),this.removeEventListener("error",i),this.removeEventListener("idle",s),e?.signal?.removeEventListener("abort",u),n()}}};var ac=["string","number","bigint","symbol"],cc=["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(ac.includes(e))return e;if(e==="function")return"Function";if(Array.isArray(r))return"Array";if(uc(r))return"Buffer";let t=fc(r);return t||"Object"}function uc(r){return r&&r.constructor&&r.constructor.isBuffer&&r.constructor.isBuffer.call(null,r)}function fc(r){let e=Object.prototype.toString.call(r).slice(8,-1);if(cc.includes(e))return e}var c=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}};c.uint=new c(0,"uint",!0);c.negint=new c(1,"negint",!0);c.bytes=new c(2,"bytes",!0);c.string=new c(3,"string",!0);c.array=new c(4,"array",!1);c.map=new c(5,"map",!1);c.tag=new c(6,"tag",!1);c.float=new c(7,"float",!0);c.false=new c(7,"false",!0);c.true=new c(7,"true",!0);c.null=new c(7,"null",!0);c.undefined=new c(7,"undefined",!0);c.break=new c(7,"break",!0);var m=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 Oe=globalThis.process&&!globalThis.process.browser&&globalThis.Buffer&&typeof globalThis.Buffer.isBuffer=="function",lc=new TextDecoder,dc=new TextEncoder;function Rt(r){return Oe&&globalThis.Buffer.isBuffer(r)}function it(r){return r instanceof Uint8Array?Rt(r)?new Uint8Array(r.buffer,r.byteOffset,r.byteLength):r:Uint8Array.from(r)}var Mo=Oe?(r,e,t)=>t-e>64?globalThis.Buffer.from(r.subarray(e,t)).toString("utf8"):Fo(r,e,t):(r,e,t)=>t-e>64?lc.decode(r.subarray(e,t)):Fo(r,e,t),zt=Oe?r=>r.length>64?globalThis.Buffer.from(r):$o(r):r=>r.length>64?dc.encode(r):$o(r),te=r=>Uint8Array.from(r),Me=Oe?(r,e,t)=>Rt(r)?new Uint8Array(r.subarray(e,t)):r.slice(e,t):(r,e,t)=>r.slice(e,t),Ro=Oe?(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},zo=Oe?r=>globalThis.Buffer.allocUnsafe(r):r=>new Uint8Array(r);function qo(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 $o(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 Fo(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 u,f,p,d;switch(s){case 1:o<128&&(i=o);break;case 2:u=r[e+1],(u&192)===128&&(d=(o&31)<<6|u&63,d>127&&(i=d));break;case 3:u=r[e+1],f=r[e+2],(u&192)===128&&(f&192)===128&&(d=(o&15)<<12|(u&63)<<6|f&63,d>2047&&(d<55296||d>57343)&&(i=d));break;case 4:u=r[e+1],f=r[e+2],p=r[e+3],(u&192)===128&&(f&192)===128&&(p&192)===128&&(d=(o&15)<<18|(u&63)<<12|(f&63)<<6|p&63,d>65535&&d<1114112&&(i=d))}}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 un(n)}var Oo=4096;function un(r){let e=r.length;if(e<=Oo)return String.fromCharCode.apply(String,r);let t="",n=0;for(;n<e;)t+=String.fromCharCode.apply(String,r.slice(n,n+=Oo));return t}var hc=256,st=class{constructor(e=hc){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=zo(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=Ro(this.chunks,this.cursor);return e&&this.reset(),t}};var k="CBOR decode error:",ae="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 B=[24,256,65536,4294967296,BigInt("18446744073709551616")];function z(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 q(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 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<B[2])throw new Error(`${k} integer encoded in more bytes than necessary (strict decode)`);return n}function V(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 jo(r,e,t,n){return new m(c.uint,z(r,e+1,n),2)}function Vo(r,e,t,n){return new m(c.uint,q(r,e+1,n),3)}function Ho(r,e,t,n){return new m(c.uint,j(r,e+1,n),5)}function Ko(r,e,t,n){return new m(c.uint,V(r,e+1,n),9)}function K(r,e){return F(r,0,e.value)}function F(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 F.encodedSize(e.value)};F.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 Wo(r,e,t,n){return new m(c.negint,-1-z(r,e+1,n),2)}function Go(r,e,t,n){return new m(c.negint,-1-q(r,e+1,n),3)}function Qo(r,e,t,n){return new m(c.negint,-1-j(r,e+1,n),5)}var fn=BigInt(-1),Jo=BigInt(1);function Xo(r,e,t,n){let o=V(r,e+1,n);if(typeof o!="bigint"){let i=-1-o;if(i>=Number.MIN_SAFE_INTEGER)return new m(c.negint,i,9)}if(n.allowBigInt!==!0)throw new Error(`${k} integers outside of the safe integer range are not supported`);return new m(c.negint,fn-BigInt(o),9)}function qt(r,e){let t=e.value,n=typeof t=="bigint"?t*fn-Jo:t*-1-1;F(r,e.type.majorEncoded,n)}qt.encodedSize=function(e){let t=e.value,n=typeof t=="bigint"?t*fn-Jo:t*-1-1;return n<B[0]?1:n<B[1]?2:n<B[2]?3:n<B[3]?5:9};qt.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 m(c.bytes,o,t+n)}function Yo(r,e,t,n){return ct(r,e,1,t)}function Zo(r,e,t,n){return ct(r,e,2,z(r,e+1,n))}function ei(r,e,t,n){return ct(r,e,3,q(r,e+1,n))}function ti(r,e,t,n){return ct(r,e,5,j(r,e+1,n))}function ri(r,e,t,n){let o=V(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 jt(r){return r.encodedBytes===void 0&&(r.encodedBytes=r.type===c.string?zt(r.value):r.value),r.encodedBytes}function Re(r,e){let t=jt(e);F(r,e.type.majorEncoded,t.length),r.push(t)}Re.encodedSize=function(e){let t=jt(e);return F.encodedSize(t.length)+t.length};Re.compareTokens=function(e,t){return mc(jt(e),jt(t))};function mc(r,e){return r.length<e.length?-1:r.length>e.length?1:qo(r,e)}function ut(r,e,t,n,o){let i=t+n;ce(r,e,i);let s=new m(c.string,Mo(r,e+t,e+i),i);return o.retainStringBytes===!0&&(s.byteValue=Me(r,e+t,e+i)),s}function ni(r,e,t,n){return ut(r,e,1,t,n)}function oi(r,e,t,n){return ut(r,e,2,z(r,e+1,n),n)}function ii(r,e,t,n){return ut(r,e,3,q(r,e+1,n),n)}function si(r,e,t,n){return ut(r,e,5,j(r,e+1,n),n)}function ai(r,e,t,n){let o=V(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 ci=Re;function ze(r,e,t,n){return new m(c.array,n,t)}function ui(r,e,t,n){return ze(r,e,1,t)}function fi(r,e,t,n){return ze(r,e,2,z(r,e+1,n))}function li(r,e,t,n){return ze(r,e,3,q(r,e+1,n))}function di(r,e,t,n){return ze(r,e,5,j(r,e+1,n))}function hi(r,e,t,n){let o=V(r,e+1,n);if(typeof o=="bigint")throw new Error(`${k} 64-bit integer array lengths not supported`);return ze(r,e,9,o)}function pi(r,e,t,n){if(n.allowIndefinite===!1)throw new Error(`${k} indefinite length items not allowed`);return ze(r,e,1,1/0)}function Vt(r,e){F(r,c.array.majorEncoded,e.value)}Vt.compareTokens=K.compareTokens;Vt.encodedSize=function(e){return F.encodedSize(e.value)};function qe(r,e,t,n){return new m(c.map,n,t)}function mi(r,e,t,n){return qe(r,e,1,t)}function gi(r,e,t,n){return qe(r,e,2,z(r,e+1,n))}function yi(r,e,t,n){return qe(r,e,3,q(r,e+1,n))}function wi(r,e,t,n){return qe(r,e,5,j(r,e+1,n))}function xi(r,e,t,n){let o=V(r,e+1,n);if(typeof o=="bigint")throw new Error(`${k} 64-bit integer map lengths not supported`);return qe(r,e,9,o)}function bi(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 Ht(r,e){F(r,c.map.majorEncoded,e.value)}Ht.compareTokens=K.compareTokens;Ht.encodedSize=function(e){return F.encodedSize(e.value)};function Ei(r,e,t,n){return new m(c.tag,t,1)}function vi(r,e,t,n){return new m(c.tag,z(r,e+1,n),2)}function ki(r,e,t,n){return new m(c.tag,q(r,e+1,n),3)}function Ai(r,e,t,n){return new m(c.tag,j(r,e+1,n),5)}function Ci(r,e,t,n){return new m(c.tag,V(r,e+1,n),9)}function Kt(r,e){F(r,c.tag.majorEncoded,e.value)}Kt.compareTokens=K.compareTokens;Kt.encodedSize=function(e){return F.encodedSize(e.value)};var Ec=20,vc=21,kc=22,Ac=23;function Ti(r,e,t,n){if(n.allowUndefined===!1)throw new Error(`${k} undefined values are not supported`);return n.coerceUndefinedToNull===!0?new m(c.null,null,1):new m(c.undefined,void 0,1)}function Si(r,e,t,n){if(n.allowIndefinite===!1)throw new Error(`${k} indefinite length items not allowed`);return new m(c.break,void 0,1)}function ln(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 m(c.float,r,e)}function Li(r,e,t,n){return ln(dn(r,e+1),3,n)}function Ii(r,e,t,n){return ln(hn(r,e+1),5,n)}function _i(r,e,t,n){return ln(Ni(r,e+1),9,n)}function Wt(r,e,t){let n=e.value;if(n===!1)r.push([c.float.majorEncoded|Ec]);else if(n===!0)r.push([c.float.majorEncoded|vc]);else if(n===null)r.push([c.float.majorEncoded|kc]);else if(n===void 0)r.push([c.float.majorEncoded|Ac]);else{let o,i=!1;(!t||t.float64!==!0)&&(Pi(n),o=dn(Y,1),n===o||Number.isNaN(n)?(Y[0]=249,r.push(Y.slice(0,3)),i=!0):(Di(n),o=hn(Y,1),n===o&&(Y[0]=250,r.push(Y.slice(0,5)),i=!0))),i||(Cc(n),o=Ni(Y,1),Y[0]=251,r.push(Y.slice(0,9)))}}Wt.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){Pi(n);let o=dn(Y,1);if(n===o||Number.isNaN(n))return 3;if(Di(n),o=hn(Y,1),n===o)return 5}return 9};var Ui=new ArrayBuffer(9),W=new DataView(Ui,1),Y=new Uint8Array(Ui,0);function Pi(r){if(r===1/0)W.setUint16(0,31744,!1);else if(r===-1/0)W.setUint16(0,64512,!1);else if(Number.isNaN(r))W.setUint16(0,32256,!1);else{W.setFloat32(0,r);let e=W.getUint32(0),t=(e&2139095040)>>23,n=e&8388607;if(t===255)W.setUint16(0,31744,!1);else if(t===0)W.setUint16(0,(r&2147483648)>>16|n>>13,!1);else{let o=t-127;o<-24?W.setUint16(0,0):o<-14?W.setUint16(0,(e&2147483648)>>16|1<<24+o,!1):W.setUint16(0,(e&2147483648)>>16|o+15<<10|n>>13,!1)}}}function dn(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 Di(r){W.setFloat32(0,r,!1)}function hn(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 Cc(r){W.setFloat64(0,r,!1)}function Ni(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)}Wt.compareTokens=K.compareTokens;function _(r,e,t){throw new Error(`${k} encountered invalid minor (${t}) for major ${r[e]>>>5}`)}function Gt(r){return()=>{throw new Error(`${k} ${r}`)}}var x=[];for(let r=0;r<=23;r++)x[r]=_;x[24]=jo;x[25]=Vo;x[26]=Ho;x[27]=Ko;x[28]=_;x[29]=_;x[30]=_;x[31]=_;for(let r=32;r<=55;r++)x[r]=_;x[56]=Wo;x[57]=Go;x[58]=Qo;x[59]=Xo;x[60]=_;x[61]=_;x[62]=_;x[63]=_;for(let r=64;r<=87;r++)x[r]=Yo;x[88]=Zo;x[89]=ei;x[90]=ti;x[91]=ri;x[92]=_;x[93]=_;x[94]=_;x[95]=Gt("indefinite length bytes/strings are not supported");for(let r=96;r<=119;r++)x[r]=ni;x[120]=oi;x[121]=ii;x[122]=si;x[123]=ai;x[124]=_;x[125]=_;x[126]=_;x[127]=Gt("indefinite length bytes/strings are not supported");for(let r=128;r<=151;r++)x[r]=ui;x[152]=fi;x[153]=li;x[154]=di;x[155]=hi;x[156]=_;x[157]=_;x[158]=_;x[159]=pi;for(let r=160;r<=183;r++)x[r]=mi;x[184]=gi;x[185]=yi;x[186]=wi;x[187]=xi;x[188]=_;x[189]=_;x[190]=_;x[191]=bi;for(let r=192;r<=215;r++)x[r]=Ei;x[216]=vi;x[217]=ki;x[218]=Ai;x[219]=Ci;x[220]=_;x[221]=_;x[222]=_;x[223]=_;for(let r=224;r<=243;r++)x[r]=Gt("simple values are not supported");x[244]=_;x[245]=_;x[246]=_;x[247]=Ti;x[248]=Gt("simple values are not supported");x[249]=Li;x[250]=Ii;x[251]=_i;x[252]=_;x[253]=_;x[254]=_;x[255]=Si;var Z=[];for(let r=0;r<24;r++)Z[r]=new m(c.uint,r,1);for(let r=-1;r>=-24;r--)Z[31-r]=new m(c.negint,r,1);Z[64]=new m(c.bytes,new Uint8Array(0),1);Z[96]=new m(c.string,"",1);Z[128]=new m(c.array,0,1);Z[160]=new m(c.map,0,1);Z[244]=new m(c.false,!1,1);Z[245]=new m(c.true,!0,1);Z[246]=new m(c.null,null,1);function Bi(r){switch(r.type){case c.false:return te([244]);case c.true:return te([245]);case c.null:return te([246]);case c.bytes:return r.value.length?void 0:te([64]);case c.string:return r.value===""?te([96]):void 0;case c.array:return r.value===0?te([128]):void 0;case c.map:return r.value===0?te([160]):void 0;case c.uint:return r.value<24?te([Number(r.value)]):void 0;case c.negint:if(r.value>=-24)return te([31-Number(r.value)])}}var Sc={float64:!1,mapSorter:_c,quickEncodeToken:Bi};function Lc(){let r=[];return r[c.uint.major]=K,r[c.negint.major]=qt,r[c.bytes.major]=Re,r[c.string.major]=ci,r[c.array.major]=Vt,r[c.map.major]=Ht,r[c.tag.major]=Kt,r[c.float.major]=Wt,r}var $i=Lc(),pn=new st,Jt=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(`${ae} object contains circular references`);return new r(t,e)}},we={null:new m(c.null,null),undefined:new m(c.undefined,void 0),true:new m(c.true,!0),false:new m(c.false,!1),emptyArray:new m(c.array,0),emptyMap:new m(c.map,0)},xe={number(r,e,t,n){return!Number.isInteger(r)||!Number.isSafeInteger(r)?new m(c.float,r):r>=0?new m(c.uint,r):new m(c.negint,r)},bigint(r,e,t,n){return r>=BigInt(0)?new m(c.uint,r):new m(c.negint,r)},Uint8Array(r,e,t,n){return new m(c.bytes,r)},string(r,e,t,n){return new m(c.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 m(c.bytes,new Uint8Array(r))},DataView(r,e,t,n){return new m(c.bytes,new Uint8Array(r.buffer,r.byteOffset,r.byteLength))},Array(r,e,t,n){if(!r.length)return t.addBreakTokens===!0?[we.emptyArray,new m(c.break)]:we.emptyArray;n=Jt.createCheck(n,r);let o=[],i=0;for(let s of r)o[i++]=Qt(s,t,n);return t.addBreakTokens?[new m(c.array,r.length),o,new m(c.break)]:[new m(c.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 m(c.break)]:we.emptyMap;n=Jt.createCheck(n,r);let u=[],f=0;for(let p of i)u[f++]=[Qt(p,t,n),Qt(o?r.get(p):r[p],t,n)];return Ic(u,t),t.addBreakTokens?[new m(c.map,s),u,new m(c.break)]:[new m(c.map,s),u]}};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 Qt(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(`${ae} unsupported type: ${n}`);return i(r,n,e,t)}function Ic(r,e){e.mapSorter&&r.sort(e.mapSorter)}function _c(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=$i[o].compareTokens(t,n);return i===0&&console.warn("WARNING: complex key types used, CBOR key sorting guarantees are gone"),i}function Fi(r,e,t,n){if(Array.isArray(e))for(let o of e)Fi(r,o,t,n);else t[e.type.major](r,e,n)}function mn(r,e,t){let n=Qt(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),u=new st(s);if(i(u,n,t),u.chunks.length!==1)throw new Error(`Unexpected error: pre-calculated length for ${n} was wrong`);return it(u.chunks[0])}}return pn.reset(),Fi(pn,n,e,t),pn.toBytes(!0)}function je(r,e){return e=Object.assign({},Sc,e),mn(r,$i,e)}var Uc={strict:!1,allowIndefinite:!0,allowUndefined:!0,allowBigInt:!0},Xt=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=x[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}},ft=Symbol.for("DONE"),Yt=Symbol.for("BREAK");function Pc(r,e,t){let n=[];for(let o=0;o<r.value;o++){let i=Ve(e,t);if(i===Yt){if(r.value===1/0)break;throw new Error(`${k} got unexpected break to lengthed array`)}if(i===ft)throw new Error(`${k} found array but not enough entries (got ${o}, expected ${r.value})`);n[o]=i}return n}function Dc(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 u=Ve(e,t);if(u===Yt){if(r.value===1/0)break;throw new Error(`${k} got unexpected break to lengthed map`)}if(u===ft)throw new Error(`${k} found map but not enough entries (got ${s} [no key], expected ${r.value})`);if(n!==!0&&typeof u!="string")throw new Error(`${k} non-string keys not supported (got ${typeof u})`);if(t.rejectDuplicateMapKeys===!0&&(n&&i.has(u)||!n&&u in o))throw new Error(`${k} found repeat map key "${u}"`);let f=Ve(e,t);if(f===ft)throw new Error(`${k} found map but not enough entries (got ${s} [no value], expected ${r.value})`);n?i.set(u,f):o[u]=f}return n?i:o}function Ve(r,e){if(r.done())return ft;let t=r.next();if(t.type===c.break)return Yt;if(t.type.terminal)return t.value;if(t.type===c.array)return Pc(t,r,e);if(t.type===c.map)return Dc(t,r,e);if(t.type===c.tag){if(e.tags&&typeof e.tags[t.value]=="function"){let n=Ve(r,e);return e.tags[t.value](n)}throw new Error(`${k} tag not supported (${t.value})`)}throw new Error("unsupported")}function gn(r,e){if(!(r instanceof Uint8Array))throw new Error(`${k} data to decode must be a Uint8Array`);e=Object.assign({},Uc,e);let t=e.tokenizer||new Xt(r,e),n=Ve(t,e);if(n===ft)throw new Error(`${k} did not find any content to decode`);if(n===Yt)throw new Error(`${k} got unexpected break`);return[n,r.subarray(t.pos())]}function ue(r,e){let[t,n]=gn(r,e);if(n.length>0)throw new Error(`${k} too many terminals, data makes no sense`);return t}function Ce(r,e="utf8"){let t=Ut[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.decoder.decode(`${t.prefix}${r}`)}var fe="/",Mi=new TextEncoder().encode(fe),Zt=Mi[0],le=class r{_buf;constructor(e,t){if(typeof e=="string")this._buf=Ce(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]!==Zt)throw new Error("Invalid key")}toString(e="utf8"){return $e(this._buf,e)}uint8Array(){return this._buf}get[Symbol.toStringTag](){return`Key(${this.toString()})`}static withNamespaces(e){return new r(e.join(fe))}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]!==Zt){let e=new Uint8Array(this._buf.byteLength+1);e.fill(Zt,0,1),e.set(this._buf,1),this._buf=e}for(;this._buf.byteLength>1&&this._buf[this._buf.byteLength-1]===Zt;)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(fe).slice(1)}type(){return Nc(this.baseNamespace())}name(){return Bc(this.baseNamespace())}instance(e){return new r(this.toString()+":"+e)}path(){let e=this.parent().toString();return e.endsWith(fe)||(e+=fe),e+=this.type(),new r(e)}parent(){let e=this.list();return e.length===1?new r(fe):new r(e.slice(0,-1).join(fe))}child(e){return this.toString()===fe?e:e.toString()===fe?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(),...$c(e.map(t=>t.namespaces()))])}};function Nc(r){let e=r.split(":");return e.length<2?"":e.slice(0,-1).join(":")}function Bc(r){let e=r.split(":");return e[e.length-1]}function $c(r){return[].concat(...r)}function er({enumerable:r=!0,configurable:e=!1}={}){return{enumerable:r,configurable:e,writable:!1}}function*Fc(r,e){if(e!=null&&typeof e=="object")if(Array.isArray(e))for(let[t,n]of e.entries()){let o=[...r,t],i=P.asCID(n);i!=null?yield[o.join("/"),i]:typeof n=="object"&&(yield*yn(n,o))}else{let t=P.asCID(e);t!=null?yield[r.join("/"),t]:yield*yn(e,r)}}function*yn(r,e){if(r==null||r instanceof Uint8Array)return;let t=P.asCID(r);t!=null&&(yield[e.join("/"),t]);for(let[n,o]of Object.entries(r)){let i=[...e,n];yield*Fc(i,o)}}function*Oc(r,e){if(Array.isArray(e))for(let[t,n]of e.entries()){let o=[...r,t];yield o.join("/"),typeof n=="object"&&P.asCID(n)==null&&(yield*wn(n,o))}else yield*wn(e,r)}function*wn(r,e){if(!(r==null||typeof r!="object"))for(let[t,n]of Object.entries(r)){let o=[...e,t];yield o.join("/"),n!=null&&!(n instanceof Uint8Array)&&typeof n=="object"&&P.asCID(n)==null&&(yield*Oc(o,n))}}function Mc(r,e){let t=r;for(let[n,o]of e.entries()){if(t=t[o],t==null)throw new Error(`Object has no property at ${e.slice(0,n+1).map(s=>`[${JSON.stringify(s)}]`).join("")}`);let i=P.asCID(t);if(i!=null)return{value:i,remaining:e.slice(n+1).join("/")}}return{value:t}}var xn=class{cid;bytes;value;asBlock;constructor({cid:e,bytes:t,value:n}){if(e==null||t==null||typeof n>"u")throw new Error("Missing required argument");this.cid=e,this.bytes=t,this.value=n,this.asBlock=this,Object.defineProperties(this,{cid:er(),bytes:er(),value:er(),asBlock:er()})}links(){return yn(this.value,[])}tree(){return wn(this.value,[])}get(e="/"){return Mc(this.value,e.split("/").filter(Boolean))}};function Ri({bytes:r,cid:e,value:t,codec:n}){let o=t!==void 0?t:n?.decode(r);if(o===void 0)throw new Error('Missing required argument, must either provide "value" or "codec"');return new xn({cid:e,bytes:r,value:o})}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 Vi="/pin/",zi="/pinned-block/",bn=oe,qi=1;function ji(r){return r.version===0&&(r=r.toV1()),new le(`${Vi}${r.toString(bn)}`)}var tr=class{datastore;blockstore;getCodec;constructor(e,t,n){this.datastore=e,this.blockstore=t,this.getCodec=n}async*add(e,t={}){let n=ji(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 se({concurrency:qi});for await(let u of this.#e(e,i,{...t,depth:o}))await this.#o(u,f=>f.pinnedBy.find(p=>Te(p,e.bytes))!=null?!1:(f.pinCount++,f.pinnedBy.push(e.bytes),!0),t),yield u;let s={depth:o,metadata:t.metadata??{}};await this.datastore.put(n,je(s),t)}async*#e(e,t,n){if(n.depth===-1)return;let o=await this.getCodec(e.code),i=await this.blockstore.get(e,n),s=Ri({bytes:i,cid:e,codec:o});yield e;for await(let[,u]of s.links())yield*await t.add(async()=>this.#e(u,t,{...n,depth:n.depth-1}))}async#o(e,t,n){let o=new le(`${zi}${bn.encode(e.multihash.bytes)}`),i={pinCount:0,pinnedBy:[]};try{i=ue(await this.datastore.get(o,n))}catch(u){if(u.name!=="NotFoundError")throw u}if(t(i)){if(i.pinCount===0&&await this.datastore.has(o)){await this.datastore.delete(o);return}await this.datastore.put(o,je(i),n),n.onProgress?.(new U("helia:pin:add",e))}}async*rm(e,t={}){let n=ji(e),o=await this.datastore.get(n,t),i=ue(o);await this.datastore.delete(n,t);let s=new se({concurrency:qi});for await(let u of this.#e(e,s,{...t,depth:i.depth}))await this.#o(u,f=>(f.pinCount--,f.pinnedBy=f.pinnedBy.filter(p=>Te(p,e.bytes)),!0),{...t,depth:i.depth}),yield u}async*ls(e={}){for await(let{key:t,value:n}of this.datastore.query({prefix:Vi+(e.cid!=null?`${e.cid.toString(oe)}`:"")},e)){let o=P.parse(t.toString().substring(5),oe),i=ue(n);yield{cid:o,...i}}}async isPinned(e,t={}){let n=new le(`${zi}${bn.encode(e.multihash.bytes)}`);return this.datastore.has(n,t)}};var rr=class extends Error{static name="InsufficientProvidersError";constructor(e="Insufficient providers found"){super(e),this.name="InsufficientProvidersError"}},Se=class extends Error{static name="NoRoutersAvailableError";constructor(e="No routers available"){super(e),this.name="NoRoutersAvailableError"}},nr=class extends Error{static name="UnknownHashAlgorithmError";constructor(e="Unknown hash algorithm"){super(e),this.name="UnknownHashAlgorithmError"}},or=class extends Error{static name="UnknownCodecError";constructor(e="Unknown codec"){super(e),this.name="UnknownCodecError"}};var ir=class extends se{has(e){return this.find(e)!=null}find(e){return this.queue.find(t=>e.equals(t.options.peerId))}};function Rc(r){return r[Symbol.asyncIterator]!=null}function zc(...r){let e=[];for(let t of r)Rc(t)||e.push(t);return e.length===r.length?function*(){for(let t of e)yield*t}():async function*(){let t=Bt({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 sr=zc;var qc=5,ar=class{log;routers;providerLookupConcurrency;constructor(e,t){this.log=e.logger.forComponent("helia:routing"),this.routers=t.routers??[],this.providerLookupConcurrency=t.providerLookupConcurrency??qc}async start(){await de(...this.routers)}async stop(){await he(...this.routers)}async*findProviders(e,t={}){if(this.routers.length===0)throw new Se("No content routers available");let n=new ir({concurrency:this.providerLookupConcurrency});n.addEventListener("error",()=>{});for await(let o of sr(n.toGenerator(),...He(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 Se("No content routers available");await Promise.all(He(this.routers,"provide").map(async n=>{await n.provide(e,t)}))}async put(e,t,n){await Promise.all(He(this.routers,"put").map(async o=>{await o.put(e,t,n)}))}async get(e,t){return Promise.any(He(this.routers,"get").map(async n=>n.get(e,t)))}async findPeer(e,t){if(this.routers.length===0)throw new Se("No peer routers available");let n=this,o=sr(...He(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 wt("Could not find peer in routing")}async*getClosestPeers(e,t={}){if(this.routers.length===0)throw new Se("No peer routers available");for await(let n of sr(...He(this.routers,"getClosestPeers").map(o=>o.getClosestPeers(e,t))))n!=null&&(yield n)}};function He(r,e){return r.filter(t=>t[e]!=null)}var be={},Ke=r=>{r.addEventListener("message",e=>{Ke.dispatchEvent("message",r,e)}),r.port!=null&&r.port.addEventListener("message",e=>{Ke.dispatchEvent("message",r,e)})};Ke.addEventListener=(r,e)=>{be[r]==null&&(be[r]=[]),be[r].push(e)};Ke.removeEventListener=(r,e)=>{be[r]!=null&&(be[r]=be[r].filter(t=>t===e))};Ke.dispatchEvent=function(r,e,t){be[r]!=null&&be[r].forEach(n=>n(e,t))};var En=Ke;var vn="lock:worker:request-read",kn="lock:worker:release-read",An="lock:master:grant-read",Cn="lock:worker:request-write",Tn="lock:worker:release-write",Sn="lock:master:grant-write";var Hi=(r=21)=>Math.random().toString().substring(2);var Ki=(r,e,t,n,o)=>(i,s)=>{if(s.data.type!==t)return;let u={type:s.data.type,name:s.data.name,identifier:s.data.identifier};r.dispatchEvent(new MessageEvent(e,{data:{name:u.name,handler:async()=>{i.postMessage({type:o,name:u.name,identifier:u.identifier}),await new Promise(f=>{let p=d=>{if(d==null||d.data==null)return;let l={type:d.data.type,name:d.data.name,identifier:d.data.identifier};l.type===n&&l.identifier===u.identifier&&(i.removeEventListener("message",p),f())};i.addEventListener("message",p)})}}}))},Wi=(r,e,t,n)=>async()=>{let o=Hi();return globalThis.postMessage({type:e,identifier:o,name:r}),new Promise(i=>{let s=u=>{if(u==null||u.data==null)return;let f={type:u.data.type,identifier:u.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)})},jc={singleProcess:!1},Gi=r=>{if(r=Object.assign({},jc,r),!!globalThis.document||r.singleProcess){let t=new EventTarget;return En.addEventListener("message",Ki(t,"requestReadLock",vn,kn,An)),En.addEventListener("message",Ki(t,"requestWriteLock",Cn,Tn,Sn)),t}return{isWorker:!0,readLock:t=>Wi(t,vn,An,kn),writeLock:t=>Wi(t,Cn,Sn,Tn)}};var Le={},Ee;async function Ln(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 Vc=(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 Ln(n,e);n=new ye({concurrency:e.concurrency,autoStart:!1});let o=n,i=Ln(n,e);return t.add(async()=>{o.start(),await o.onIdle().then(()=>{n===o&&(n=null)})}),i},async writeLock(){return n=null,Ln(t,e)}}},Hc={name:"lock",concurrency:1/0,timeout:846e5,singleProcess:!1};function In(r){let e=Object.assign({},Hc,r);return Ee==null&&(Ee=Gi(e),Ee.isWorker!==!0&&(Ee.addEventListener("requestReadLock",t=>{Le[t.data.name]!=null&&Le[t.data.name].readLock().then(async n=>t.data.handler().finally(()=>{n()}))}),Ee.addEventListener("requestWriteLock",async t=>{Le[t.data.name]!=null&&Le[t.data.name].writeLock().then(async n=>t.data.handler().finally(()=>{n()}))}))),Le[e.name]==null&&(Le[e.name]=Vc(e.name,e)),Le[e.name]}var cr=class{lock;child;pins;started;constructor(e,t,n={}){this.child=e,this.pins=t,this.lock=In({singleProcess:n.holdGcLock}),this.started=!1}isStarted(){return this.started}async start(){await de(this.child),this.started=!0}async stop(){await he(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 _n=new le("/version"),Qi=1;async function Ji(r){if(!await r.has(_n)){await r.put(_n,Ce(`${Qi}`));return}let e=await r.get(_n),t=$e(e);if(parseInt(t,10)!==Qi)throw new Error("Unknown datastore version, a datastore migration may be required")}var Dn={};N(Dn,{code:()=>Pn,decode:()=>eu,decodeOptions:()=>Xc,encode:()=>Zc,encodeOptions:()=>Qc,name:()=>Yc,toByteView:()=>Yi});var Xi=42;function Yi(r){return r instanceof ArrayBuffer?new Uint8Array(r,0,r.byteLength):r}function Kc(r){if(r.asCID!==r&&r["/"]!==r.bytes)return null;let e=P.asCID(r);if(!e)return null;let t=new Uint8Array(e.bytes.byteLength+1);return t.set(e.bytes,1),[new m(c.tag,Xi),new m(c.bytes,t)]}function Wc(){throw new Error("`undefined` is not supported by the IPLD Data Model and cannot be encoded")}function Gc(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 Un={float64:!0,typeEncoders:{Object:Kc,undefined:Wc,number:Gc}},Qc={...Un,typeEncoders:{...Un.typeEncoders}};function Jc(r){if(r[0]!==0)throw new Error("Invalid CID for CBOR tag 42; expected leading 0x00");return P.decode(r.subarray(1))}var ur={allowIndefinite:!1,coerceUndefinedToNull:!0,allowNaN:!1,allowInfinity:!1,allowBigInt:!0,strict:!0,useMaps:!1,rejectDuplicateMapKeys:!0,tags:[]};ur.tags[Xi]=Jc;var Xc={...ur,tags:ur.tags.slice()},Yc="dag-cbor",Pn=113,Zc=r=>je(r,Un),eu=r=>ue(Yi(r),ur);var Rn={};N(Rn,{code:()=>Mn,decode:()=>es,encode:()=>Zi,format:()=>lu,name:()=>fu,parse:()=>hu,stringify:()=>lu});var Nn=class extends Array{constructor(){super(),this.inRecursive=[]}prefix(e){let t=this.inRecursive[this.inRecursive.length-1];t&&(t.type===c.array&&(t.elements++,t.elements!==1&&e.push([44])),t.type===c.map&&(t.elements++,t.elements!==1&&(t.elements%2===1?e.push([44]):e.push([58]))))}[c.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)}[c.negint.major](e,t){this[c.uint.major](e,t)}[c.bytes.major](e,t){throw new Error(`${ae} unsupported type: Uint8Array`)}[c.string.major](e,t){this.prefix(e);let n=zt(JSON.stringify(t.value));e.push(n.length>32?it(n):n)}[c.array.major](e,t){this.prefix(e),this.inRecursive.push({type:c.array,elements:0}),e.push([91])}[c.map.major](e,t){this.prefix(e),this.inRecursive.push({type:c.map,elements:0}),e.push([123])}[c.tag.major](e,t){}[c.float.major](e,t){if(t.type.name==="break"){let s=this.inRecursive.pop();if(s){if(s.type===c.array)e.push([93]);else if(s.type===c.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(`${ae} unsupported type: undefined`);if(this.prefix(e),t.type.name==="true"){e.push([116,114,117,101]);return}else if(t.type.name==="false"){e.push([102,97,108,115,101]);return}else if(t.type.name==="null"){e.push([110,117,108,108]);return}let n=String(t.value),o=[],i=!1;for(let s=0;s<n.length;s++)o[s]=n.charCodeAt(s),!i&&(o[s]===46||o[s]===101||o[s]===69)&&(i=!0);i||(o.push(46),o.push(48)),e.push(o)}};function tu(r,e){if(Array.isArray(r[0])||Array.isArray(e[0]))throw new Error(`${ae} complex map keys are not supported`);let t=r[0],n=e[0];if(t.type!==c.string||n.type!==c.string)throw new Error(`${ae} non-string map keys are not supported`);if(t<n)return-1;if(t>n)return 1;throw new Error(`${ae} unexpected duplicate map keys, this is not supported`)}var ru={addBreakTokens:!0,mapSorter:tu};function Bn(r,e){return e=Object.assign({},ru,e),mn(r,new Nn,e)}var We=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=u=>{for(;!this.done();){let f=this.ch();if(u.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 m(c.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 m(c.float,s,this._pos-e):this.options.allowBigInt!==!0||Number.isSafeInteger(s)?new m(s>=0?c.uint:c.negint,s,this._pos-e):new m(s>=0?c.uint:c.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 u=this.data[i];if(u===92||u<32||u>=128)break;if(u===34){let f=String.fromCharCode.apply(null,this.data.subarray(this._pos,i));return this._pos=i+1,new m(c.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 u=this.ch();if(u>=48&&u<=57)u-=48;else if(u>=97&&u<=102)u=u-97+10;else if(u>=65&&u<=70)u=u-65+10;else throw new Error(`${k} unexpected unicode escape character at position ${this._pos}`);i=i*16+u,this._pos++}return i},o=()=>{let i=this.ch(),s=null,u=i>239?4:i>223?3:i>191?2:1;if(this._pos+u>this.data.length)throw new Error(`${k} unexpected unicode sequence at position ${this._pos}`);let f,p,d,l;switch(u){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],d=this.data[this._pos+3],(f&192)===128&&(p&192)===128&&(d&192)===128&&(l=(i&15)<<18|(f&63)<<12|(p&63)<<6|d&63,l>65535&&l<1114112&&(s=l))}s===null?(s=65533,u=1):s>65535&&(s-=65536,t.push(s>>>10&1023|55296),s=56320|s&1023),t.push(s),this._pos+=u};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 m(c.string,un(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 m(c.map,1/0,1);case 91:return this.modeStack.push("array-start"),this._pos++,new m(c.array,1/0,1);case 34:return this.parseString();case 110:return this.expect([110,117,108,108]),new m(c.null,null,4);case 102:return this.expect([102,97,108,115,101]),new m(c.false,!1,5);case 116:return this.expect([116,114,117,101]),new m(c.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 m(c.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 m(c.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 m(c.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 m(c.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 $n(r,e){return e=Object.assign({tokenizer:new We(r,e)},e),ue(r,e)}function ou(r){return r instanceof ArrayBuffer?new Uint8Array(r,0,r.byteLength):r}function iu(r){if(r.asCID!==r&&r["/"]!==r.bytes)return null;let e=P.asCID(r);if(!e)return null;let t=e.toString();return[new m(c.map,1/0,1),new m(c.string,"/",1),new m(c.string,t,t.length),new m(c.break,void 0,1)]}function fr(r){let e=ge.encode(r).slice(1);return[new m(c.map,1/0,1),new m(c.string,"/",1),new m(c.map,1/0,1),new m(c.string,"bytes",5),new m(c.string,e,e.length),new m(c.break,void 0,1),new m(c.break,void 0,1)]}function ee(r){return fr(new Uint8Array(r.buffer,r.byteOffset,r.byteLength))}function su(r){return fr(new Uint8Array(r))}function au(){throw new Error("`undefined` is not supported by the IPLD Data Model and cannot be encoded")}function cu(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 uu={typeEncoders:{Object:iu,Buffer:fr,Uint8Array:fr,Int8Array:ee,Uint16Array:ee,Int16Array:ee,Uint32Array:ee,Int32Array:ee,Float32Array:ee,Float64Array:ee,Uint8ClampedArray:ee,BigInt64Array:ee,BigUint64Array:ee,DataView:ee,ArrayBuffer:su,undefined:au,number:cu}},Fn=class extends We{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===c.map){let t=this._next();if(t.type===c.string&&t.value==="/"){let n=this._next();if(n.type===c.string){if(this._next().type!==c.break)throw new Error("Invalid encoded CID form");return this.tokenBuffer.push(n),new m(c.tag,42,0)}if(n.type===c.map){let o=this._next();if(o.type===c.string&&o.value==="bytes"){let i=this._next();if(i.type===c.string){for(let u=0;u<2;u++)if(this._next().type!==c.break)throw new Error("Invalid encoded Bytes form");let s=ge.decode(`m${i.value}`);return new m(c.bytes,s,i.value.length)}this.tokenBuffer.push(i)}this.tokenBuffer.push(o)}this.tokenBuffer.push(n)}this.tokenBuffer.push(t)}return e}},On={allowIndefinite:!1,allowUndefined:!1,allowNaN:!1,allowInfinity:!1,allowBigInt:!0,strict:!0,useMaps:!1,rejectDuplicateMapKeys:!0,tags:[]};On.tags[42]=P.parse;var fu="dag-json",Mn=297,Zi=r=>Bn(r,uu),es=r=>{let e=ou(r),t=Object.assign(On,{tokenizer:new Fn(e,On)});return $n(e,t)},lu=r=>du.decode(Zi(r));var du=new TextDecoder,hu=r=>es(pu.encode(r)),pu=new TextEncoder;var Kn={};N(Kn,{code:()=>Hn,createLink:()=>fs,createNode:()=>us,decode:()=>Su,encode:()=>Tu,name:()=>Cu,prepare:()=>jn,validate:()=>Vn});var mu=new TextDecoder;function zn(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 lr(r,e){let t;[t,e]=zn(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 ts(r,e){let t;return[t,e]=zn(r,e),[t&7,t>>3,e]}function gu(r){let e={},t=r.length,n=0;for(;n<t;){let o,i;if([o,i,n]=ts(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]=lr(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]=lr(r,n),e.Name=mu.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]=zn(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 rs(r){let e=r.length,t=0,n,o=!1,i;for(;t<e;){let u,f;if([u,f,t]=ts(r,t),u!==2)throw new Error(`protobuf: (PBNode) invalid wireType, expected 2, got ${u}`);if(f===1){if(i)throw new Error("protobuf: (PBNode) duplicate Data section");[i,t]=lr(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]=lr(r,t),n.push(gu(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 os=new TextEncoder,ns=2**32,yu=2**31;function wu(r,e){let t=e.length;if(typeof r.Tsize=="number"){if(r.Tsize<0)throw new Error("Tsize cannot be negative");if(!Number.isSafeInteger(r.Tsize))throw new Error("Tsize too large for encoding");t=lt(e,t,r.Tsize)-1,e[t]=24}if(typeof r.Name=="string"){let n=os.encode(r.Name);t-=n.length,e.set(n,t),t=lt(e,t,n.length)-1,e[t]=18}return r.Hash&&(t-=r.Hash.length,e.set(r.Hash,t),t=lt(e,t,r.Hash.length)-1,e[t]=10),e.length-t}function is(r){let e=bu(r),t=new Uint8Array(e),n=e;if(r.Data&&(n-=r.Data.length,t.set(r.Data,n),n=lt(t,n,r.Data.length)-1,t[n]=10),r.Links)for(let o=r.Links.length-1;o>=0;o--){let i=wu(r.Links[o],t.subarray(0,n));n-=i,n=lt(t,n,i)-1,t[n]=18}return t}function xu(r){let e=0;if(r.Hash){let t=r.Hash.length;e+=1+t+Ge(t)}if(typeof r.Name=="string"){let t=os.encode(r.Name).length;e+=1+t+Ge(t)}return typeof r.Tsize=="number"&&(e+=1+Ge(r.Tsize)),e}function bu(r){let e=0;if(r.Data){let t=r.Data.length;e+=1+t+Ge(t)}if(r.Links)for(let t of r.Links){let n=xu(t);e+=1+n+Ge(n)}return e}function lt(r,e,t){e-=Ge(t);let n=e;for(;t>=yu;)r[e++]=t&127|128,t/=128;for(;t>=128;)r[e++]=t&127|128,t>>>=7;return r[e]=t,n}function Ge(r){return r%2===0&&r++,Math.floor((Eu(r)+6)/7)}function Eu(r){let e=0;return r>=ns&&(r=Math.floor(r/ns),e=32),r>=65536&&(r>>>=16,e+=16),r>=256&&(r>>>=8,e+=8),e+vu[r]}var vu=[0,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8];var ku=["Data","Links"],Au=["Hash","Name","Tsize"],qn=new TextEncoder;function as(r,e){if(r===e)return 0;let t=r.Name?qn.encode(r.Name):[],n=e.Name?qn.encode(e.Name):[],o=t.length,i=n.length;for(let s=0,u=Math.min(o,i);s<u;++s)if(t[s]!==n[s]){o=t[s],i=n[s];break}return o<i?-1:i<o?1:0}function ss(r,e){return!Object.keys(r).some(t=>!e.includes(t))}function cs(r){if(typeof r.asCID=="object"){let t=P.asCID(r);if(!t)throw new TypeError("Invalid DAG-PB form");return{Hash:t}}if(typeof r!="object"||Array.isArray(r))throw new TypeError("Invalid DAG-PB form");let e={};if(r.Hash){let t=P.asCID(r.Hash);try{t||(typeof r.Hash=="string"?t=P.parse(r.Hash):r.Hash instanceof Uint8Array&&(t=P.decode(r.Hash)))}catch(n){throw new TypeError(`Invalid DAG-PB form: ${n.message}`)}t&&(e.Hash=t)}if(!e.Hash)throw new TypeError("Invalid DAG-PB form");return typeof r.Name=="string"&&(e.Name=r.Name),typeof r.Tsize=="number"&&(e.Tsize=r.Tsize),e}function jn(r){if((r instanceof Uint8Array||typeof r=="string")&&(r={Data:r}),typeof r!="object"||Array.isArray(r))throw new TypeError("Invalid DAG-PB form");let e={};if(r.Data!==void 0)if(typeof r.Data=="string")e.Data=qn.encode(r.Data);else if(r.Data instanceof Uint8Array)e.Data=r.Data;else throw new TypeError("Invalid DAG-PB form");if(r.Links!==void 0)if(Array.isArray(r.Links))e.Links=r.Links.map(cs),e.Links.sort(as);else throw new TypeError("Invalid DAG-PB form");else e.Links=[];return e}function Vn(r){if(!r||typeof r!="object"||Array.isArray(r)||r instanceof Uint8Array||r["/"]&&r["/"]===r.bytes)throw new TypeError("Invalid DAG-PB form");if(!ss(r,ku))throw new TypeError("Invalid DAG-PB form (extraneous properties)");if(r.Data!==void 0&&!(r.Data instanceof Uint8Array))throw new TypeError("Invalid DAG-PB form (Data must be bytes)");if(!Array.isArray(r.Links))throw new TypeError("Invalid DAG-PB form (Links must be a list)");for(let e=0;e<r.Links.length;e++){let t=r.Links[e];if(!t||typeof t!="object"||Array.isArray(t)||t instanceof Uint8Array||t["/"]&&t["/"]===t.bytes)throw new TypeError("Invalid DAG-PB form (bad link)");if(!ss(t,Au))throw new TypeError("Invalid DAG-PB form (extraneous properties on link)");if(t.Hash===void 0)throw new TypeError("Invalid DAG-PB form (link must have a Hash)");if(t.Hash==null||!t.Hash["/"]||t.Hash["/"]!==t.Hash.bytes)throw new TypeError("Invalid DAG-PB form (link Hash must be a CID)");if(t.Name!==void 0&&typeof t.Name!="string")throw new TypeError("Invalid DAG-PB form (link Name must be a string)");if(t.Tsize!==void 0){if(typeof t.Tsize!="number"||t.Tsize%1!==0)throw new TypeError("Invalid DAG-PB form (link Tsize must be an integer)");if(t.Tsize<0)throw new TypeError("Invalid DAG-PB form (link Tsize cannot be negative)")}if(e>0&&as(t,r.Links[e-1])===-1)throw new TypeError("Invalid DAG-PB form (links must be sorted by Name bytes)")}}function us(r,e=[]){return jn({Data:r,Links:e})}function fs(r,e,t){return cs({Hash:t,Name:r,Tsize:e})}function ls(r){return r instanceof ArrayBuffer?new Uint8Array(r,0,r.byteLength):r}var Cu="dag-pb",Hn=112;function Tu(r){Vn(r);let e={};return r.Links&&(e.Links=r.Links.map(t=>{let n={};return t.Hash&&(n.Hash=t.Hash.bytes),t.Name!==void 0&&(n.Name=t.Name),t.Tsize!==void 0&&(n.Tsize=t.Tsize),n})),r.Data&&(e.Data=r.Data),is(e)}function Su(r){let e=ls(r),t=rs(e),n={};return t.Data&&(n.Data=t.Data),t.Links&&(n.Links=t.Links.map(o=>{let i={};try{i.Hash=P.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}function Qe(r){return r?.then!=null}function ds(r=[],e){let t={[Hn]:Kn,[Gr]:Tt,[Pn]:Dn,[Mn]:Rn,[Wr]:Ct};return r.forEach(n=>{t[n.code]=n}),async n=>{let o=t[n];if(o==null&&e!=null){let i=e(n);Qe(i)?o=await i:o=i,t[o.code]=o}if(o!=null)return o;throw new or(`Could not load codec for ${n}`)}}function hs(r=[],e){let t={[It.code]:It,[_t.code]:_t,[Lt.code]:Lt};return r.forEach(n=>{t[n.code]=n}),async n=>{let o=t[n];if(o==null&&e!=null){let i=e(n);Qe(i)?o=await i:o=i,t[o.code]=o}if(o!=null)return o;throw new nr(`No hasher configured for multihash code 0x${n.toString(16)}, please configure one. You can look up which hash this is at https://github.com/multiformats/multicodec/blob/master/table.csv`)}}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 dr=class r extends Error{static name="NotFoundError";static code="ERR_NOT_FOUND";name=r.name;code=r.code;constructor(e="Not Found"){super(e)}};var hr=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 pr=0,mr=class extends hr{child;constructor(e){super(),this.child=e}put(e,t){return e.multihash.code===pr||this.child==null?e:this.child.put(e,t)}get(e){if(e.multihash.code===pr)return e.multihash.digest;if(this.child==null)throw new dr;return this.child.get(e)}has(e){return e.multihash.code===pr?!0:this.child==null?!1:this.child.has(e)}delete(e){if(e.code!==pr&&this.child!=null)return this.child.delete(e)}getAll(e){return this.child!=null?this.child.getAll(e):[]}};function Lu(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 gr=Lu;function Iu(r){return r[Symbol.asyncIterator]!=null}function _u(r,e){let t=0;if(Iu(r))return async function*(){for await(let f of r)await e(f,t++)&&(yield f)}();let n=gr(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 u=e;return function*(){s===!0&&(yield o);for(let f of n)u(f,t++)&&(yield f)}()}var ps=_u;function Uu(r){return r[Symbol.asyncIterator]!=null}function ms(r){return r?.then!=null}function Pu(r,e){let t=0;if(Uu(r))return async function*(){for await(let f of r){let p=e(f,t++);ms(p)&&await p,yield f}}();let n=gr(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++);ms(p)&&await p,yield f}}();let u=e;return function*(){yield o;for(let f of n)u(f,t++),yield f}()}var Wn=Pu;var yr=class{child;getHasher;log;logger;components;constructor(e){this.log=e.logger.forComponent("helia:networked-storage"),this.logger=e.logger,this.components=e,this.child=new mr(e.blockstore),this.getHasher=e.getHasher}async put(e,t,n={}){return await this.child.has(e,n)?(n.onProgress?.(new U("blocks:put:duplicate",e)),e):(n.onProgress?.(new U("blocks:put:providers:notify",e)),await Promise.all(this.components.blockBrokers.map(async o=>o.announce?.(e,t,n))),n.onProgress?.(new U("blocks:put:blockstore:put",e)),this.child.put(e,t,n))}async*putMany(e,t={}){let n=ps(e,async({cid:i})=>{let s=await this.child.has(i,t);return s&&t.onProgress?.(new U("blocks:put-many:duplicate",i)),!s}),o=Wn(n,async({cid:i,block:s})=>{t.onProgress?.(new U("blocks:put-many:providers:notify",i)),await Promise.all(this.components.blockBrokers.map(async u=>u.announce?.(i,s,t)))});t.onProgress?.(new U("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)){let n=await this.getHasher(e.multihash.code);t.onProgress?.(new U("blocks:get:providers:get",e));let o=await gs(e,this.components.blockBrokers,n,{...t,log:this.log});return t.onProgress?.(new U("blocks:get:blockstore:put",e)),await this.child.put(e,o,t),t.onProgress?.(new U("blocks:get:providers:notify",e)),await Promise.all(this.components.blockBrokers.map(async i=>i.announce?.(e,o,t))),o}return t.onProgress?.(new U("blocks:get:blockstore:get",e)),this.child.get(e,t)}async*getMany(e,t={}){t.onProgress?.(new U("blocks:get-many:blockstore:get-many")),yield*this.child.getMany(Wn(e,async n=>{if(t.offline!==!0&&!await this.child.has(n,t)){let o=await this.getHasher(n.multihash.code);t.onProgress?.(new U("blocks:get-many:providers:get",n));let i=await gs(n,this.components.blockBrokers,o,{...t,log:this.log});t.onProgress?.(new U("blocks:get-many:blockstore:put",n)),await this.child.put(n,i,t),t.onProgress?.(new U("blocks:get-many:providers:notify",n)),await Promise.all(this.components.blockBrokers.map(async s=>s.announce?.(n,i,t)))}}))}async delete(e,t={}){t.onProgress?.(new U("blocks:delete:blockstore:delete",e)),await this.child.delete(e,t)}async*deleteMany(e,t={}){t.onProgress?.(new U("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 U("blocks:get-all:blockstore:get-many")),yield*this.child.getAll(e)}},wr=class extends yr{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 he(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 Gn({blockstore:this.child,blockBrokers:n,getHasher:this.getHasher,logger:this.logger},{root:e})}},Gn=class extends yr{closeController;constructor(e,t){super(e),this.closeController=new AbortController,$(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]);$(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]);$(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]);$(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]);$(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]);$(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]);$(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]);$(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]);$(1/0,t);try{yield*super.getAll({...e,signal:t})}finally{t.clear()}}};function Du(r){return typeof r.retrieve=="function"}var Nu=(r,e)=>{if(e==null)throw new _e(`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`);return async t=>{let n,o=e.digest(t);if(Qe(o)?n=await o:n=o,!Te(n.digest,r.multihash.digest))throw new xt("Hash of downloaded block did not match multihash from passed CID")}};async function gs(r,e,t,n){let o=Nu(r,t),i=new AbortController,s=re([i.signal,n.signal]);$(1/0,i.signal,s);let u=[];for(let f of e)Du(f)&&u.push(f);try{return await Promise.any(u.map(async f=>{try{let p=!1,d=await f.retrieve(r,{...n,signal:s,validateFn:async l=>{await o(l),p=!0}});return p||await o(d),d}catch(p){throw n.log.error("could not retrieve verified block for %c",r,p),p}}))}finally{i.abort(),s.clear()}}var Ie=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;var Qp=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;var Jp={}.toString;function ys(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 xr(r){if(isNaN(r)||r<=0)throw new _e("random bytes length must be a Number bigger than 0");return ys(r)}function Qn(r,e){e==null&&(e=r.reduce((o,i)=>o+i.length,0));let t=ke(e),n=0;for(let o of r)t.set(o,n),n+=o.length;return t}var Jn=Ar(bs(),1);var vs=Symbol.for("@achingbrain/uint8arraylist");function Es(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 Er(r){return!!r?.[vs]}var vr=class r{bufs;length;[vs]=!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(Er(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(Er(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=Es(this.bufs,e);return t.buf[t.index]}set(e,t){let n=Es(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(Er(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 Qn(n,o)}subarray(e,t){let{bufs:n,length:o}=this._subList(e,t);return n.length===1?n[0]:Qn(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],u=o,f=u+s.byteLength;if(o=f,e>=f)continue;let p=e>=u&&e<f,d=t>u&&t<=f;if(p&&d){if(e===u&&t===f){n.push(s);break}let l=e-u;n.push(s.subarray(l,l+(t-e)));break}if(p){if(e===0){n.push(s);continue}n.push(s.subarray(e-u));continue}if(d){if(t===f){n.push(s);break}n.push(s.subarray(0,t-u));break}n.push(s)}return{bufs:n,length:t-e}}indexOf(e,t=0){if(!Er(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 u=s,f=this.byteLength-n.byteLength,p=n.byteLength-1,d;for(let l=t;l<=f;l+=d){d=0;for(let C=p;C>=0;C--){let a=this.get(l+C);if(n[C]!==a){d=Math.max(1,C-u[a]);break}}if(d===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=ke(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=ke(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 Bu=Math.LN2*Math.LN2,Je=class r{static create(e,t=.005){let n=$u(e,t);return new r(n)}seeds;bits;buffer;constructor(e={}){e.seeds!=null?this.seeds=e.seeds:this.seeds=Fu(e.hashes??8),this.bits=e.bits??1024,this.buffer=X(Math.ceil(this.bits/8))}add(e){typeof e=="string"&&(e=Ce(e));for(let t=0;t<this.seeds.length;t++){let o=Jn.default.x86.hash32(e,this.seeds[t])%this.bits;this.setbit(o)}}has(e){typeof e=="string"&&(e=Ce(e));for(let t=0;t<this.seeds.length;t++){let o=Jn.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 $u(r,e=.005){let t=Math.round(-1*r*Math.log(e)/Bu),n=Math.round(t/r*Math.LN2);return{bits:t,hashes:n}}function Fu(r){let e,t,n=[];for(let o=0;o<r;o++)for(e=new vr(xr(4)),n[o]=e.getUint32(0,!0),t=0;t<o;t++)if(n[o]===n[t]){o--;break}return n}var kr=class extends Ue{intialPeerSearchComplete;requests;name;log;logger;minProviders;maxProviders;providers;evictionFilter;constructor(e,t){super(),$(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=Je.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=ie();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,u=new se({concurrency:this.maxProviders});u.addEventListener("error",()=>{}),u.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)}),u.addEventListener("success",p=>{s=!0,i.resolve(p.detail.result)}),u.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 d=this.providers[Math.floor(Math.random()*this.providers.length)];this.evict(d)}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=>{u.add(async()=>this.queryProvider(e,p.detail,t),{provider:p.detail}).catch(d=>{t.signal?.aborted!==!0&&this.log.error("error retrieving session block for %c",e,d)})};this.addEventListener("provider",f),Promise.all([...this.providers].map(async p=>u.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),u.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=ie(),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 rr(`Found ${i} of ${t} ${this.name} providers for ${e}`)}).catch(s=>{this.log.error("error searching routing for potential session peers for %c",e,s.errors??s),o.reject(s)}),o.promise}};var Xn=class{blockstore;datastore;pins;logger;routing;getCodec;getHasher;dns;metrics;log;constructor(e){this.logger=e.logger??so(),this.log=this.logger.forComponent("helia"),this.getHasher=hs(e.hashers,e.loadHasher),this.getCodec=ds(e.codecs,e.loadCodec),this.dns=e.dns??Po(),this.metrics=e.metrics;let t={blockstore:e.blockstore,datastore:e.datastore,logger:this.logger,blockBrokers:[],getHasher:this.getHasher,getCodec:this.getCodec,dns:this.dns,metrics:this.metrics,...e.components??{}};this.routing=t.routing=new ar(t,{routers:(e.routers??[]).flatMap(o=>{let i=[o];return o[Cr]!=null&&i.push(o[Cr]),o[Tr]!=null&&i.push(o[Tr]),i}),providerLookupConcurrency:e.providerLookupConcurrency});let n=new wr(t);this.pins=new tr(e.datastore,n,this.getCodec),this.blockstore=new cr(n,this.pins,{holdGcLock:e.holdGcLock??!0}),this.datastore=e.datastore,t.blockBrokers=e.blockBrokers.map(o=>o(t))}async start(){await Ji(this.datastore),await de(this.blockstore,this.datastore,this.routing)}async stop(){await he(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 Do(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 U("helia:gc:deleted",i))}catch(s){n.log.error("Error during gc",s),e.onProgress?.(new U("helia:gc:error",s))}}()))}finally{t()}this.log("gc finished")}};function Ru(r,e){return r.code===e}return Ls(zu);})();
|
|
2
|
+
"use strict";var HeliaUtils=(()=>{var Qs=Object.create;var dt=Object.defineProperty;var Js=Object.getOwnPropertyDescriptor;var Xs=Object.getOwnPropertyNames;var Ys=Object.getPrototypeOf,Zs=Object.prototype.hasOwnProperty;var ht=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),M=(r,e)=>{for(var t in e)dt(r,t,{get:e[t],enumerable:!0})},kn=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Xs(e))!Zs.call(r,o)&&o!==t&&dt(r,o,{get:()=>e[o],enumerable:!(n=Js(e,o))||n.enumerable});return r};var lr=(r,e,t)=>(t=r!=null?Qs(Ys(r)):{},kn(e||!r||!r.__esModule?dt(t,"default",{value:r,enumerable:!0}):t,r)),ei=r=>kn(dt({},"__esModule",{value:!0}),r);var Bn=ht((hu,vr)=>{"use strict";var Pi=Object.prototype.hasOwnProperty,O="~";function Ke(){}Object.create&&(Ke.prototype=Object.create(null),new Ke().__proto__||(O=!1));function Bi(r,e,t){this.fn=r,this.context=e,this.once=t||!1}function Pn(r,e,t,n,o){if(typeof t!="function")throw new TypeError("The listener must be a function");var s=new Bi(t,n||r,o),i=O?O+e:e;return r._events[i]?r._events[i].fn?r._events[i]=[r._events[i],s]:r._events[i].push(s):(r._events[i]=s,r._eventsCount++),r}function xt(r,e){--r._eventsCount===0?r._events=new Ke:delete r._events[e]}function F(){this._events=new Ke,this._eventsCount=0}F.prototype.eventNames=function(){var e=[],t,n;if(this._eventsCount===0)return e;for(n in t=this._events)Pi.call(t,n)&&e.push(O?n.slice(1):n);return Object.getOwnPropertySymbols?e.concat(Object.getOwnPropertySymbols(t)):e};F.prototype.listeners=function(e){var t=O?O+e:e,n=this._events[t];if(!n)return[];if(n.fn)return[n.fn];for(var o=0,s=n.length,i=new Array(s);o<s;o++)i[o]=n[o].fn;return i};F.prototype.listenerCount=function(e){var t=O?O+e:e,n=this._events[t];return n?n.fn?1:n.length:0};F.prototype.emit=function(e,t,n,o,s,i){var c=O?O+e:e;if(!this._events[c])return!1;var f=this._events[c],p=arguments.length,d,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,s),!0;case 6:return f.fn.call(f.context,t,n,o,s,i),!0}for(l=1,d=new Array(p-1);l<p;l++)d[l-1]=arguments[l];f.fn.apply(f.context,d)}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(!d)for(a=1,d=new Array(p-1);a<p;a++)d[a-1]=arguments[a];f[l].fn.apply(f[l].context,d)}}return!0};F.prototype.on=function(e,t,n){return Pn(this,e,t,n,!1)};F.prototype.once=function(e,t,n){return Pn(this,e,t,n,!0)};F.prototype.removeListener=function(e,t,n,o){var s=O?O+e:e;if(!this._events[s])return this;if(!t)return xt(this,s),this;var i=this._events[s];if(i.fn)i.fn===t&&(!o||i.once)&&(!n||i.context===n)&&xt(this,s);else{for(var c=0,f=[],p=i.length;c<p;c++)(i[c].fn!==t||o&&!i[c].once||n&&i[c].context!==n)&&f.push(i[c]);f.length?this._events[s]=f.length===1?f[0]:f:xt(this,s)}return this};F.prototype.removeAllListeners=function(e){var t;return e?(t=O?O+e:e,this._events[t]&&xt(this,t)):(this._events=new Ke,this._eventsCount=0),this};F.prototype.off=F.prototype.removeListener;F.prototype.addListener=F.prototype.on;F.prefixed=O;F.EventEmitter=F;typeof vr<"u"&&(vr.exports=F)});var oo=ht((vf,no)=>{no.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(s,i){t[s]=i,e++,e>=r&&(e=0,n=t,t=Object.create(null))}return{has:function(s){return t[s]!==void 0||n[s]!==void 0},remove:function(s){t[s]!==void 0&&(t[s]=void 0),n[s]!==void 0&&(n[s]=void 0)},get:function(s){var i=t[s];if(i!==void 0)return i;if((i=n[s])!==void 0)return o(s,i),i},set:function(s,i){t[s]!==void 0?t[s]=i:o(s,i)},clear:function(){t=Object.create(null),n=Object.create(null)}}}});var js=ht((ct,ar)=>{(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 h=0;h<a.length;h++)if(!Number.isInteger(a[h])||a[h]<0||a[h]>255)return!1;return!0}function o(a,h){return(a&65535)*h+(((a>>>16)*h&65535)<<16)}function s(a,h){return a<<h|a>>>32-h}function i(a){return a^=a>>>16,a=o(a,2246822507),a^=a>>>13,a=o(a,3266489909),a^=a>>>16,a}function c(a,h){a=[a[0]>>>16,a[0]&65535,a[1]>>>16,a[1]&65535],h=[h[0]>>>16,h[0]&65535,h[1]>>>16,h[1]&65535];var m=[0,0,0,0];return m[3]+=a[3]+h[3],m[2]+=m[3]>>>16,m[3]&=65535,m[2]+=a[2]+h[2],m[1]+=m[2]>>>16,m[2]&=65535,m[1]+=a[1]+h[1],m[0]+=m[1]>>>16,m[1]&=65535,m[0]+=a[0]+h[0],m[0]&=65535,[m[0]<<16|m[1],m[2]<<16|m[3]]}function f(a,h){a=[a[0]>>>16,a[0]&65535,a[1]>>>16,a[1]&65535],h=[h[0]>>>16,h[0]&65535,h[1]>>>16,h[1]&65535];var m=[0,0,0,0];return m[3]+=a[3]*h[3],m[2]+=m[3]>>>16,m[3]&=65535,m[2]+=a[2]*h[3],m[1]+=m[2]>>>16,m[2]&=65535,m[2]+=a[3]*h[2],m[1]+=m[2]>>>16,m[2]&=65535,m[1]+=a[1]*h[3],m[0]+=m[1]>>>16,m[1]&=65535,m[1]+=a[2]*h[2],m[0]+=m[1]>>>16,m[1]&=65535,m[1]+=a[3]*h[1],m[0]+=m[1]>>>16,m[1]&=65535,m[0]+=a[0]*h[3]+a[1]*h[2]+a[2]*h[1]+a[3]*h[0],m[0]&=65535,[m[0]<<16|m[1],m[2]<<16|m[3]]}function p(a,h){return h%=64,h===32?[a[1],a[0]]:h<32?[a[0]<<h|a[1]>>>32-h,a[1]<<h|a[0]>>>32-h]:(h-=32,[a[1]<<h|a[0]>>>32-h,a[0]<<h|a[1]>>>32-h])}function d(a,h){return h%=64,h===0?a:h<32?[a[0]<<h|a[1]>>>32-h,a[1]<<h]:[a[1]<<h-32,0]}function l(a,h){return[a[0]^h[0],a[1]^h[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,h){if(t.inputValidation&&!n(a))return e;h=h||0;for(var m=a.length%4,A=a.length-m,y=h,w=0,b=3432918353,E=461845907,T=0;T<A;T=T+4)w=a[T]|a[T+1]<<8|a[T+2]<<16|a[T+3]<<24,w=o(w,b),w=s(w,15),w=o(w,E),y^=w,y=s(y,13),y=o(y,5)+3864292196;switch(w=0,m){case 3:w^=a[T+2]<<16;case 2:w^=a[T+1]<<8;case 1:w^=a[T],w=o(w,b),w=s(w,15),w=o(w,E),y^=w}return y^=a.length,y=i(y),y>>>0},t.x86.hash128=function(a,h){if(t.inputValidation&&!n(a))return e;h=h||0;for(var m=a.length%16,A=a.length-m,y=h,w=h,b=h,E=h,T=0,S=0,v=0,_=0,G=597399067,ut=2869860233,ft=951274213,lt=2716044179,L=0;L<A;L=L+16)T=a[L]|a[L+1]<<8|a[L+2]<<16|a[L+3]<<24,S=a[L+4]|a[L+5]<<8|a[L+6]<<16|a[L+7]<<24,v=a[L+8]|a[L+9]<<8|a[L+10]<<16|a[L+11]<<24,_=a[L+12]|a[L+13]<<8|a[L+14]<<16|a[L+15]<<24,T=o(T,G),T=s(T,15),T=o(T,ut),y^=T,y=s(y,19),y+=w,y=o(y,5)+1444728091,S=o(S,ut),S=s(S,16),S=o(S,ft),w^=S,w=s(w,17),w+=b,w=o(w,5)+197830471,v=o(v,ft),v=s(v,17),v=o(v,lt),b^=v,b=s(b,15),b+=E,b=o(b,5)+2530024501,_=o(_,lt),_=s(_,18),_=o(_,G),E^=_,E=s(E,13),E+=y,E=o(E,5)+850148119;switch(T=0,S=0,v=0,_=0,m){case 15:_^=a[L+14]<<16;case 14:_^=a[L+13]<<8;case 13:_^=a[L+12],_=o(_,lt),_=s(_,18),_=o(_,G),E^=_;case 12:v^=a[L+11]<<24;case 11:v^=a[L+10]<<16;case 10:v^=a[L+9]<<8;case 9:v^=a[L+8],v=o(v,ft),v=s(v,17),v=o(v,lt),b^=v;case 8:S^=a[L+7]<<24;case 7:S^=a[L+6]<<16;case 6:S^=a[L+5]<<8;case 5:S^=a[L+4],S=o(S,ut),S=s(S,16),S=o(S,ft),w^=S;case 4:T^=a[L+3]<<24;case 3:T^=a[L+2]<<16;case 2:T^=a[L+1]<<8;case 1:T^=a[L],T=o(T,G),T=s(T,15),T=o(T,ut),y^=T}return y^=a.length,w^=a.length,b^=a.length,E^=a.length,y+=w,y+=b,y+=E,w+=y,b+=y,E+=y,y=i(y),w=i(w),b=i(b),E=i(E),y+=w,y+=b,y+=E,w+=y,b+=y,E+=y,("00000000"+(y>>>0).toString(16)).slice(-8)+("00000000"+(w>>>0).toString(16)).slice(-8)+("00000000"+(b>>>0).toString(16)).slice(-8)+("00000000"+(E>>>0).toString(16)).slice(-8)},t.x64.hash128=function(a,h){if(t.inputValidation&&!n(a))return e;h=h||0;for(var m=a.length%16,A=a.length-m,y=[0,h],w=[0,h],b=[0,0],E=[0,0],T=[2277735313,289559509],S=[1291169091,658871167],v=0;v<A;v=v+16)b=[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],b=f(b,T),b=p(b,31),b=f(b,S),y=l(y,b),y=p(y,27),y=c(y,w),y=c(f(y,[0,5]),[0,1390208809]),E=f(E,S),E=p(E,33),E=f(E,T),w=l(w,E),w=p(w,31),w=c(w,y),w=c(f(w,[0,5]),[0,944331445]);switch(b=[0,0],E=[0,0],m){case 15:E=l(E,d([0,a[v+14]],48));case 14:E=l(E,d([0,a[v+13]],40));case 13:E=l(E,d([0,a[v+12]],32));case 12:E=l(E,d([0,a[v+11]],24));case 11:E=l(E,d([0,a[v+10]],16));case 10:E=l(E,d([0,a[v+9]],8));case 9:E=l(E,[0,a[v+8]]),E=f(E,S),E=p(E,33),E=f(E,T),w=l(w,E);case 8:b=l(b,d([0,a[v+7]],56));case 7:b=l(b,d([0,a[v+6]],48));case 6:b=l(b,d([0,a[v+5]],40));case 5:b=l(b,d([0,a[v+4]],32));case 4:b=l(b,d([0,a[v+3]],24));case 3:b=l(b,d([0,a[v+2]],16));case 2:b=l(b,d([0,a[v+1]],8));case 1:b=l(b,[0,a[v]]),b=f(b,T),b=p(b,31),b=f(b,S),y=l(y,b)}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 ct<"u"?(typeof ar<"u"&&ar.exports&&(ct=ar.exports=t),ct.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)})(ct)});var Hs=ht((dp,Ws)=>{Ws.exports=js()});var $c={};M($c,{AbstractSession:()=>fr,BloomFilter:()=>He,Helia:()=>vn,hasCode:()=>Nc});var dr=Symbol.for("@libp2p/content-routing");var hr=Symbol.for("@libp2p/peer-routing");var re=class extends Error{static name="AbortError";constructor(e="The operation was aborted"){super(e),this.name="AbortError"}};var _e=class extends Error{static name="InvalidParametersError";constructor(e="Invalid parameters"){super(e),this.name="InvalidParametersError"}};var pt=class extends Error{static name="NotFoundError";constructor(e="Not found"){super(e),this.name="NotFoundError"}};var mt=class extends Error{static name="InvalidMultihashError";constructor(e="Invalid Multihash"){super(e),this.name="InvalidMultihashError"}};var B=(r,...e)=>{try{[...e]}catch{}};var Ie=class extends EventTarget{#e=new Map;constructor(){super(),B(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:s})=>s!==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 CustomEvent(e,t))}};function An(r){return r!=null&&typeof r.start=="function"&&typeof r.stop=="function"}async function fe(...r){let e=[];for(let t of r)An(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 le(...r){let e=[];for(let t of r)An(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 wr={};M(wr,{base32:()=>he,base32hex:()=>ui,base32hexpad:()=>li,base32hexpadupper:()=>di,base32hexupper:()=>fi,base32pad:()=>ai,base32padupper:()=>ci,base32upper:()=>ii,base32z:()=>hi});var Wc=new Uint8Array(0);function Cn(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 Tn(r){return new TextEncoder().encode(r)}function Sn(r){return new TextDecoder().decode(r)}function ti(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 s=r.charAt(o),i=s.charCodeAt(0);if(t[i]!==255)throw new TypeError(s+" is ambiguous");t[i]=o}var c=r.length,f=r.charAt(0),p=Math.log(c)/Math.log(256),d=Math.log(256)/Math.log(c);function l(h){if(h instanceof Uint8Array||(ArrayBuffer.isView(h)?h=new Uint8Array(h.buffer,h.byteOffset,h.byteLength):Array.isArray(h)&&(h=Uint8Array.from(h))),!(h instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(h.length===0)return"";for(var m=0,A=0,y=0,w=h.length;y!==w&&h[y]===0;)y++,m++;for(var b=(w-y)*d+1>>>0,E=new Uint8Array(b);y!==w;){for(var T=h[y],S=0,v=b-1;(T!==0||S<A)&&v!==-1;v--,S++)T+=256*E[v]>>>0,E[v]=T%c>>>0,T=T/c>>>0;if(T!==0)throw new Error("Non-zero carry");A=S,y++}for(var _=b-A;_!==b&&E[_]===0;)_++;for(var G=f.repeat(m);_<b;++_)G+=r.charAt(E[_]);return G}function C(h){if(typeof h!="string")throw new TypeError("Expected String");if(h.length===0)return new Uint8Array;var m=0;if(h[m]!==" "){for(var A=0,y=0;h[m]===f;)A++,m++;for(var w=(h.length-m)*p+1>>>0,b=new Uint8Array(w);h[m];){var E=t[h.charCodeAt(m)];if(E===255)return;for(var T=0,S=w-1;(E!==0||T<y)&&S!==-1;S--,T++)E+=c*b[S]>>>0,b[S]=E%256>>>0,E=E/256>>>0;if(E!==0)throw new Error("Non-zero carry");y=T,m++}if(h[m]!==" "){for(var v=w-y;v!==w&&b[v]===0;)v++;for(var _=new Uint8Array(A+(w-v)),G=A;v!==w;)_[G++]=b[v++];return _}}}function a(h){var m=C(h);if(m)return m;throw new Error(`Non-${e} character`)}return{encode:l,decodeUnsafe:C,decode:a}}var ri=ti,ni=ri,_n=ni;var pr=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")}},mr=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,t,n){this.name=e,this.prefix=t;let o=t.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,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 In(this,e)}},gr=class{decoders;constructor(e){this.decoders=e}or(e){return In(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 In(r,e){return new gr({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}var yr=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 pr(e,t,n),this.decoder=new mr(e,t,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function De({name:r,prefix:e,encode:t,decode:n}){return new yr(r,e,t,n)}function de({name:r,prefix:e,alphabet:t}){let{encode:n,decode:o}=_n(t,r);return De({prefix:e,name:r,encode:n,decode:s=>ne(o(s))})}function oi(r,e,t,n){let o={};for(let d=0;d<e.length;++d)o[e[d]]=d;let s=r.length;for(;r[s-1]==="=";)--s;let i=new Uint8Array(s*t/8|0),c=0,f=0,p=0;for(let d=0;d<s;++d){let l=o[r[d]];if(l===void 0)throw new SyntaxError(`Non-${n} character`);f=f<<t|l,c+=t,c>=8&&(c-=8,i[p++]=255&f>>c)}if(c>=t||255&f<<8-c)throw new SyntaxError("Unexpected end of data");return i}function si(r,e,t){let n=e[e.length-1]==="=",o=(1<<t)-1,s="",i=0,c=0;for(let f=0;f<r.length;++f)for(c=c<<8|r[f],i+=8;i>t;)i-=t,s+=e[o&c>>i];if(i!==0&&(s+=e[o&c<<t-i]),n)for(;s.length*t&7;)s+="=";return s}function U({name:r,prefix:e,bitsPerChar:t,alphabet:n}){return De({prefix:e,name:r,encode(o){return si(o,n,t)},decode(o){return oi(o,n,t,r)}})}var he=U({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),ii=U({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),ai=U({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),ci=U({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),ui=U({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),fi=U({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),li=U({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),di=U({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),hi=U({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var xr={};M(xr,{base58btc:()=>W,base58flickr:()=>pi});var W=de({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),pi=de({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var br={};M(br,{base64:()=>pe,base64pad:()=>mi,base64url:()=>gi,base64urlpad:()=>yi});var pe=U({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),mi=U({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),gi=U({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),yi=U({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});function wi(r,e){try{if(typeof r=="string"&&r.length>0)return xi(r);if(typeof r=="number"&&isFinite(r))return e?.long?Ei(r):bi(r);throw new Error("Value is not a string or number.")}catch(t){let n=vi(t)?`${t.message}. value=${JSON.stringify(r)}`:"An unknown error has occured.";throw new Error(n)}}function xi(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 yt=wi;function bi(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 Ei(r){let e=Math.abs(r);return e>=864e5?gt(r,e,864e5,"day"):e>=36e5?gt(r,e,36e5,"hour"):e>=6e4?gt(r,e,6e4,"minute"):e>=1e3?gt(r,e,1e3,"second"):`${r} ms`}function gt(r,e,t,n){let o=e>=t*1.5;return`${Math.round(r/t)} ${n}${o?"s":""}`}function vi(r){return typeof r=="object"&&r!==null&&"message"in r}function Er(r){t.debug=t,t.default=t,t.coerce=f,t.disable=s,t.enable=o,t.enabled=i,t.humanize=yt,t.destroy=p,Object.keys(r).forEach(d=>{t[d]=r[d]}),t.names=[],t.skips=[],t.formatters={};function e(d){let l=0;for(let C=0;C<d.length;C++)l=(l<<5)-l+d.charCodeAt(C),l|=0;return t.colors[Math.abs(l)%t.colors.length]}t.selectColor=e;function t(d){let l,C=null,a,h;function m(...A){if(!m.enabled)return;let y=m,w=Number(new Date),b=w-(l||w);y.diff=b,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,(S,v)=>{if(S==="%%")return"%";E++;let _=t.formatters[v];if(typeof _=="function"){let G=A[E];S=_.call(y,G),A.splice(E,1),E--}return S}),t.formatArgs.call(y,A),(y.log||t.log).apply(y,A)}return m.namespace=d,m.useColors=t.useColors(),m.color=t.selectColor(d),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,h=t.enabled(d)),h),set:A=>{C=A}}),typeof t.init=="function"&&t.init(m),m}function n(d,l){let C=t(this.namespace+(typeof l>"u"?":":l)+d);return C.log=this.log,C}function o(d){t.save(d),t.namespaces=d,t.names=[],t.skips=[];let l,C=(typeof d=="string"?d:"").split(/[\s,]+/),a=C.length;for(l=0;l<a;l++)C[l]&&(d=C[l].replace(/\*/g,".*?"),d[0]==="-"?t.skips.push(new RegExp("^"+d.substr(1)+"$")):t.names.push(new RegExp("^"+d+"$")))}function s(){let d=[...t.names.map(c),...t.skips.map(c).map(l=>"-"+l)].join(",");return t.enable(""),d}function i(d){if(d[d.length-1]==="*")return!0;let l,C;for(l=0,C=t.skips.length;l<C;l++)if(t.skips[l].test(d))return!1;for(l=0,C=t.names.length;l<C;l++)if(t.names[l].test(d))return!0;return!1}function c(d){return d.toString().substring(2,d.toString().length-2).replace(/\.\*\?$/,"*")}function f(d){return d instanceof Error?d.stack??d.message:d}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 wt=_i(),ki=["#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 Ai(){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 Ci(r){if(r[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+r[0]+(this.useColors?"%c ":" ")+"+"+yt(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 Ti=console.debug??console.log??(()=>{});function Si(r){try{r?wt?.setItem("debug",r):wt?.removeItem("debug")}catch{}}function Li(){let r;try{r=wt?.getItem("debug")}catch{}return!r&&typeof process<"u"&&"env"in process&&(r=process.env.DEBUG),r}function _i(){try{return localStorage}catch{}}function Ii(r){r.j=function(e){try{return JSON.stringify(e)}catch(t){return"[UnexpectedJSONParseError]: "+t.message}}}var Dn=Er({formatArgs:Ci,save:Si,load:Li,useColors:Ai,setupFormatters:Ii,colors:ki,storage:wt,log:Ti});var R=Dn;R.formatters.b=r=>r==null?"undefined":W.baseEncode(r);R.formatters.t=r=>r==null?"undefined":he.baseEncode(r);R.formatters.m=r=>r==null?"undefined":pe.baseEncode(r);R.formatters.p=r=>r==null?"undefined":r.toString();R.formatters.c=r=>r==null?"undefined":r.toString();R.formatters.k=r=>r==null?"undefined":r.toString();R.formatters.a=r=>r==null?"undefined":r.toString();function Di(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 Un(){return{forComponent(r){return Ui(r)}}}function Ui(r){let e=Di(`${r}:trace`);return R.enabled(`${r}:trace`)&&R.names.map(t=>t.toString()).find(t=>t.includes(":trace"))!=null&&(e=R(`${r}:trace`)),Object.assign(R(r),{error:R(`${r}:error`),trace:e})}var D=class extends Event{type;detail;constructor(e,t){super(e),this.type=e,this.detail=t}};var kr=lr(Bn(),1);var Ge=class extends Error{constructor(e){super(e),this.name="TimeoutError"}},Ar=class extends Error{constructor(e){super(),this.name="AbortError",this.message=e}},Nn=r=>globalThis.DOMException===void 0?new Ar(r):new DOMException(r),$n=r=>{let e=r.reason===void 0?Nn("This operation was aborted."):r.reason;return e instanceof Error?e:Nn(e)};function Qe(r,e){let{milliseconds:t,fallback:n,message:o,customTimers:s={setTimeout,clearTimeout}}=e,i,f=new Promise((p,d)=>{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&&d($n(C)),C.addEventListener("abort",()=>{d($n(C))})}if(t===Number.POSITIVE_INFINITY){r.then(p,d);return}let l=new Ge;i=s.setTimeout.call(void 0,()=>{if(n){try{p(n())}catch(C){d(C)}return}typeof r.cancel=="function"&&r.cancel(),o===!1?p():o instanceof Error?d(o):(l.message=o??`Promise timed out after ${t} milliseconds`,d(l))},t),(async()=>{try{p(await r)}catch(C){d(C)}})()}).finally(()=>{f.clear()});return f.clear=()=>{s.clearTimeout.call(void 0,i),i=void 0},f}function Cr(r,e,t){let n=0,o=r.length;for(;o>0;){let s=Math.trunc(o/2),i=n+s;t(r[i],e)<=0?(n=++i,o-=s+1):o=s}return n}var Je=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=Cr(this.#e,n,(s,i)=>i.priority-s.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 me=class extends kr.default{#e;#o;#i=0;#h;#a;#p=0;#r;#c;#t;#m;#n=0;#u;#s;#g;timeout;constructor(e){if(super(),e={carryoverConcurrencyCount:!1,intervalCap:Number.POSITIVE_INFINITY,interval:0,concurrency:Number.POSITIVE_INFINITY,autoStart:!0,queueClass:Je,...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.#h=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.#s=e.autoStart===!1}get#x(){return this.#o||this.#i<this.#h}get#b(){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.#i=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.#s){let e=!this.#k;if(this.#x&&this.#b){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.#i===0&&this.#n===0&&this.#r&&(clearInterval(this.#r),this.#r=void 0),this.#i=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.#i++;try{t.signal?.throwIfAborted();let s=e({signal:t.signal});t.timeout&&(s=Qe(Promise.resolve(s),{milliseconds:t.timeout})),t.signal&&(s=Promise.race([s,this.#A(t.signal)]));let i=await s;n(i),this.emit("completed",i)}catch(s){if(s instanceof Ge&&!t.throwOnTimeout){n();return}o(s),this.emit("error",s)}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.#s?(this.#s=!1,this.#l(),this):this}pause(){this.#s=!0}clear(){this.#t=new this.#m}async onEmpty(){this.#t.size!==0&&await this.#d("empty")}async onSizeLessThan(e){this.#t.size<e||await this.#d("next",()=>this.#t.size<e)}async onIdle(){this.#n===0&&this.#t.size===0||await this.#d("idle")}async#d(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.#s}};function bt(r){let e=[Q.A];return r==null?e:Array.isArray(r)?r.length===0?e:r:[r]}var Tr={};M(Tr,{base10:()=>Ni});var Ni=de({prefix:"9",name:"base10",alphabet:"0123456789"});var Sr={};M(Sr,{base16:()=>$i,base16upper:()=>Fi});var $i=U({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Fi=U({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Lr={};M(Lr,{base2:()=>Oi});var Oi=U({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var _r={};M(_r,{base256emoji:()=>qi});var Fn=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}"),Mi=Fn.reduce((r,e,t)=>(r[t]=e,r),[]),Ri=Fn.reduce((r,e,t)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return r[n]=t,r},[]);function zi(r){return r.reduce((e,t)=>(e+=Mi[t],e),"")}function Vi(r){let e=[];for(let t of r){let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);let o=Ri[n];if(o==null)throw new Error(`Non-base256emoji character: ${t}`);e.push(o)}return new Uint8Array(e)}var qi=De({prefix:"\u{1F680}",name:"base256emoji",encode:zi,decode:Vi});var Ir={};M(Ir,{base36:()=>oe,base36upper:()=>ji});var oe=de({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),ji=de({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Dr={};M(Dr,{base8:()=>Wi});var Wi=U({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Ur={};M(Ur,{identity:()=>Hi});var Hi=De({prefix:"\0",name:"identity",encode:r=>Sn(r),decode:r=>Tn(r)});var Pu=new TextEncoder,Bu=new TextDecoder;var On=512;var Rn=85;var Nr={};M(Nr,{identity:()=>Br});var Ki=jn,Vn=128,Gi=127,Qi=~Gi,Ji=Math.pow(2,31);function jn(r,e,t){e=e||[],t=t||0;for(var n=t;r>=Ji;)e[t++]=r&255|Vn,r/=128;for(;r&Qi;)e[t++]=r&255|Vn,r>>>=7;return e[t]=r|0,jn.bytes=t-n+1,e}var Xi=Pr,Yi=128,qn=127;function Pr(r,n){var t=0,n=n||0,o=0,s=n,i,c=r.length;do{if(s>=c)throw Pr.bytes=0,new RangeError("Could not decode varint");i=r[s++],t+=o<28?(i&qn)<<o:(i&qn)*Math.pow(2,o),o+=7}while(i>=Yi);return Pr.bytes=s-n,t}var Zi=Math.pow(2,7),ea=Math.pow(2,14),ta=Math.pow(2,21),ra=Math.pow(2,28),na=Math.pow(2,35),oa=Math.pow(2,42),sa=Math.pow(2,49),ia=Math.pow(2,56),aa=Math.pow(2,63),ca=function(r){return r<Zi?1:r<ea?2:r<ta?3:r<ra?4:r<na?5:r<oa?6:r<sa?7:r<ia?8:r<aa?9:10},ua={encode:Ki,decode:Xi,encodingLength:ca},fa=ua,Xe=fa;function Ye(r,e=0){return[Xe.decode(r,e),Xe.decode.bytes]}function Ue(r,e,t=0){return Xe.encode(r,e,t),e}function Pe(r){return Xe.encodingLength(r)}function be(r,e){let t=e.byteLength,n=Pe(r),o=n+Pe(t),s=new Uint8Array(o+t);return Ue(r,s,0),Ue(t,s,n),s.set(e,o),new Be(r,t,e,s)}function Wn(r){let e=ne(r),[t,n]=Ye(e),[o,s]=Ye(e.subarray(n)),i=e.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new Be(t,o,i,e)}function Hn(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&Cn(r.bytes,t.bytes)}}var Be=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,la="identity",Gn=ne;function da(r){return be(Kn,Gn(r))}var Br={code:Kn,name:la,encode:Gn,digest:da};var Rr={};M(Rr,{sha256:()=>Or,sha512:()=>Mr});function Fr({name:r,code:e,encode:t}){return new $r(r,e,t)}var $r=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?be(this.code,t):t.then(n=>be(this.code,n))}else throw Error("Unknown type, must be binary type")}};function Jn(r){return async e=>new Uint8Array(await crypto.subtle.digest(r,e))}var Or=Fr({name:"sha2-256",code:18,encode:Jn("SHA-256")}),Mr=Fr({name:"sha2-512",code:19,encode:Jn("SHA-512")});function Xn(r,e){let{bytes:t,version:n}=r;switch(n){case 0:return pa(t,zr(r),e??W.encoder);default:return ma(t,zr(r),e??he.encoder)}}var Yn=new WeakMap;function zr(r){let e=Yn.get(r);if(e==null){let t=new Map;return Yn.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!==et)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==ga)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=be(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&&Hn(e.multihash,n.multihash)}toString(e){return Xn(this,e)}toJSON(){return{"/":Xn(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:s,bytes:i}=t;return new r(n,o,s,i??Zn(n,o,s.bytes))}else if(t[ya]===!0){let{version:n,multihash:o,code:s}=t,i=Wn(o);return r.create(n,s,i)}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!==et)throw new Error(`Version 0 CID must use dag-pb (code: ${et}) block encoding`);return new r(e,t,n,n.bytes)}case 1:{let o=Zn(e,t,n.bytes);return new r(e,t,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return r.create(0,et,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 s=o.subarray(t.multihashSize-t.digestSize),i=new Be(t.multihashCode,t.digestSize,s,o);return[t.version===0?r.createV0(i):r.createV1(t.codec,i),e.subarray(t.size)]}static inspectBytes(e){let t=0,n=()=>{let[l,C]=Ye(e.subarray(t));return t+=C,l},o=n(),s=et;if(o===18?(o=0,t=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=t,c=n(),f=n(),p=t+f,d=p-i;return{version:o,codec:s,multihashCode:c,digestSize:f,multihashSize:d,size:p}}static parse(e,t){let[n,o]=ha(e,t),s=r.decode(o);if(s.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return zr(s).set(n,e),s}};function ha(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 he.prefix:{let t=e??he;return[he.prefix,t.decode(r)]}case oe.prefix:{let t=e??oe;return[oe.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 pa(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 s=t.encode(r).slice(1);return e.set(n,s),s}else return o}function ma(r,e,t){let{prefix:n}=t,o=e.get(n);if(o==null){let s=t.encode(r);return e.set(n,s),s}else return o}var et=112,ga=18;function Zn(r,e,t){let n=Pe(r),o=n+Pe(e),s=new Uint8Array(o+t.byteLength);return Ue(r,s,0),Ue(e,s,n),s.set(t,o),s}var ya=Symbol.for("@ipld/js-cid/CID");var Vr={...Ur,...Lr,...Dr,...Tr,...Sr,...wr,...Ir,...xr,...br,..._r},rf={...Rr,...Nr};function J(r=0){return new Uint8Array(r)}function Ee(r=0){return new Uint8Array(r)}function to(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}var eo=to("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),qr=to("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=Ee(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),wa={utf8:eo,"utf-8":eo,hex:Vr.base16,latin1:qr,ascii:qr,binary:qr,...Vr},vt=wa;function Ne(r,e="utf8"){let t=vt[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.encoder.encode(r).substring(1)}var jr=60;function kt(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:Q[e.type]})),Answer:(r.Answer??r.answers??[]).map(e=>({name:e.name,type:Q[e.type],TTL:e.TTL??e.ttl??jr,data:e.data instanceof Uint8Array?Ne(e.data):e.data}))}}var xa=4;function Wr(r,e={}){let t=new me({concurrency:e.queryConcurrency??xa});return async(n,o={})=>{let s=new URLSearchParams;s.set("name",n),bt(o.types).forEach(c=>{s.append("type",Q[c])}),o.onProgress?.(new D("dns:query",{detail:n}));let i=await t.add(async()=>{let c=await fetch(`${r}?${s}`,{headers:{accept:"application/dns-json"},signal:o?.signal});if(c.status!==200)throw new Error(`Unexpected HTTP status: ${c.status} - ${c.statusText}`);let f=kt(await c.json());return o.onProgress?.(new D("dns:response",{detail:f})),f},{signal:o.signal});if(i==null)throw new Error("No DNS response received");return i}}function ro(){return[Wr("https://cloudflare-dns.com/dns-query"),Wr("https://dns.google/resolve")]}var so=lr(oo(),1);var Hr=class{lru;constructor(e){this.lru=(0,so.default)(e)}get(e,t){let n=!0,o=[];for(let s of t){let i=this.getAnswers(e,s);if(i.length===0){n=!1;break}o.push(...i)}if(n)return kt({answers:o})}getAnswers(e,t){let n=`${e.toLowerCase()}-${t}`,o=this.lru.get(n);if(o!=null){let s=o.filter(i=>i.expires>Date.now()).map(({expires:i,value:c})=>({...c,TTL:Math.round((i-Date.now())/1e3),type:Q[c.type]}));return s.length===0&&this.lru.remove(n),s}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 io(r){return new Hr(r)}var ba=1e3,At=class{resolvers;cache;constructor(e){this.resolvers={},this.cache=io(e.cacheSize??ba),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["."]=ro())}async query(e,t={}){let n=bt(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 s=`${e.split(".").pop()}.`,i=(this.resolvers[s]??this.resolvers["."]).sort(()=>Math.random()>.5?-1:1),c=[];for(let f of i){if(t.signal?.aborted===!0)break;try{let p=await f(e,{...t,types:n});for(let d of p.Answer)this.cache.add(e,d);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 Q;(function(r){r[r.A=1]="A",r[r.CNAME=5]="CNAME",r[r.TXT=16]="TXT",r[r.AAAA=28]="AAAA"})(Q||(Q={}));function ao(r={}){return new At(r)}function Ea(r){return r[Symbol.asyncIterator]!=null}function va(r){if(Ea(r))return(async()=>{for await(let e of r);})();for(let e of r);}var co=va;function se(){let r={};return r.promise=new Promise((e,t)=>{r.resolve=e,r.reject=t}),r}var Ct=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}},$e=class{size;hwm;head;tail;constructor(e={}){this.hwm=e.splitLimit??16,this.head=new Ct(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 Ct(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 Kr=class extends Error{type;code;constructor(e,t){super(e??"The operation was aborted"),this.type="aborted",this.code=t??"ABORT_ERR"}};function Tt(r={}){return ka(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 ka(r,e){e=e??{};let t=e.onEnd,n=new $e,o,s,i,c=se(),f=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((A,y)=>{s=w=>{s=null,n.push(w);try{A(r(n))}catch(b){y(b)}return o}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{c.resolve(),c=se()})}},p=A=>s!=null?s(A):(n.push(A),o),d=A=>(n=new $e,s!=null?s({error:A}):(n.push({error:A}),o)),l=A=>{if(i)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=>i?o:(i=!0,A!=null?d(A):p({done:!0})),a=()=>(n=new $e,C(),{done:!0}),h=A=>(C(A),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:f,return:a,throw:h,push:l,end:C,get readableLength(){return n.size},onEmpty:async A=>{let y=A?.signal;if(y?.throwIfAborted(),n.isEmpty())return;let w,b;y!=null&&(w=new Promise((E,T)=>{b=()=>{T(new Kr)},y.addEventListener("abort",b)}));try{await Promise.race([c.promise,w])}finally{b!=null&&y!=null&&y?.removeEventListener("abort",b)}}},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 Gr=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 St(r,e,t,n){let o=new Gr(n?.errorMessage,n?.errorCode);return t?.aborted===!0?Promise.reject(o):new Promise((s,i)=>{function c(){t?.removeEventListener("abort",d),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(),i(C);return}c(),s(l)},p=l=>{c(),i(l.detail)},d=()=>{c(),i(o)};t?.addEventListener("abort",d),r.addEventListener(e,f),n?.errorEvent!=null&&r.addEventListener(n.errorEvent,p)})}var Lt=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 Lt(t?.errorMessage,t?.errorCode,t?.errorName));let n,o=new Lt(t?.errorMessage,t?.errorCode,t?.errorName);try{return await Promise.race([r,new Promise((s,i)=>{n=()=>{i(o)},e.addEventListener("abort",n)})])}finally{n!=null&&e.removeEventListener("abort",n)}}var _t=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 re)}cleanup(){this.signal?.removeEventListener("abort",this.onAbort)}};function Aa(){return`${parseInt(String(Math.random()*1e9),10).toString()}${Date.now()}`}var It=class{id;fn;options;recipients;status;timeline;controller;constructor(e,t){this.id=Aa(),this.status="queued",this.fn=e,this.options=t,this.recipients=[],this.timeline={created:Date.now()},this.controller=new AbortController,B(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 re),this.cleanup())}async join(e={}){let t=new _t(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 ie=class extends Ie{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 It(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 s=0;s<this.queue.length;s++)if(this.queue[s]===n){this.queue.splice(s,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 re)}),this.clear()}async onEmpty(e){this.size!==0&&await St(this,"empty",e?.signal)}async onSizeLessThan(e,t){this.size<e||await St(this,"next",t?.signal,{filter:()=>this.size<e})}async onIdle(e){this.pending===0&&this.size===0||await St(this,"idle",e?.signal)}get size(){return this.queue.length}get queued(){return this.queue.length-this.pending}get running(){return this.pending}async*toGenerator(e){e?.signal?.throwIfAborted();let t=Tt({objectMode:!0}),n=f=>{f!=null?this.abort():this.clear(),t.end(f)},o=f=>{f.detail!=null&&t.push(f.detail)},s=f=>{n(f.detail)},i=()=>{n()},c=()=>{n(new re("Queue aborted"))};this.addEventListener("completed",o),this.addEventListener("error",s),this.addEventListener("idle",i),e?.signal?.addEventListener("abort",c);try{yield*t}finally{this.removeEventListener("completed",o),this.removeEventListener("error",s),this.removeEventListener("idle",i),e?.signal?.removeEventListener("abort",c),n()}}};var Ca=["string","number","bigint","symbol"],Ta=["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(Ca.includes(e))return e;if(e==="function")return"Function";if(Array.isArray(r))return"Array";if(Sa(r))return"Buffer";let t=La(r);return t||"Object"}function Sa(r){return r&&r.constructor&&r.constructor.isBuffer&&r.constructor.isBuffer.call(null,r)}function La(r){let e=Object.prototype.toString.call(r).slice(8,-1);if(Ta.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 Fe=globalThis.process&&!globalThis.process.browser&&globalThis.Buffer&&typeof globalThis.Buffer.isBuffer=="function",_a=new TextDecoder,Ia=new TextEncoder;function Dt(r){return Fe&&globalThis.Buffer.isBuffer(r)}function tt(r){return r instanceof Uint8Array?Dt(r)?new Uint8Array(r.buffer,r.byteOffset,r.byteLength):r:Uint8Array.from(r)}var mo=Fe?(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?_a.decode(r.subarray(e,t)):ho(r,e,t),Ut=Fe?r=>r.length>64?globalThis.Buffer.from(r):lo(r):r=>r.length>64?Ia.encode(r):lo(r),Z=r=>Uint8Array.from(r),Oe=Fe?(r,e,t)=>Dt(r)?new Uint8Array(r.subarray(e,t)):r.slice(e,t):(r,e,t)=>r.slice(e,t),go=Fe?(r,e)=>(r=r.map(t=>t instanceof Uint8Array?t:globalThis.Buffer.from(t)),tt(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=Fe?r=>globalThis.Buffer.allocUnsafe(r):r=>new Uint8Array(r);function wo(r,e){if(Dt(r)&&Dt(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],s=null,i=o>239?4:o>223?3:o>191?2:1;if(e+i<=t){let c,f,p,d;switch(i){case 1:o<128&&(s=o);break;case 2:c=r[e+1],(c&192)===128&&(d=(o&31)<<6|c&63,d>127&&(s=d));break;case 3:c=r[e+1],f=r[e+2],(c&192)===128&&(f&192)===128&&(d=(o&15)<<12|(c&63)<<6|f&63,d>2047&&(d<55296||d>57343)&&(s=d));break;case 4:c=r[e+1],f=r[e+2],p=r[e+3],(c&192)===128&&(f&192)===128&&(p&192)===128&&(d=(o&15)<<18|(c&63)<<12|(f&63)<<6|p&63,d>65535&&d<1114112&&(s=d))}}s===null?(s=65533,i=1):s>65535&&(s-=65536,n.push(s>>>10&1023|55296),s=56320|s&1023),n.push(s),e+=i}return Qr(n)}var po=4096;function Qr(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 Da=256,rt=class{constructor(e=Da){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=Oe(n,0,this.cursor)}else t=go(this.chunks,this.cursor);return e&&this.reset(),t}};var k="CBOR decode error:",Me="CBOR encode error:",nt=[];nt[23]=1;nt[24]=2;nt[25]=3;nt[26]=5;nt[27]=9;function ae(r,e,t){if(r.length-e<t)throw new Error(`${k} not enough data for type`)}var P=[24,256,65536,4294967296,BigInt("18446744073709551616")];function z(r,e,t){ae(r,e,1);let n=r[e];if(t.strict===!0&&n<P[0])throw new Error(`${k} integer encoded in more bytes than necessary (strict decode)`);return n}function V(r,e,t){ae(r,e,2);let n=r[e]<<8|r[e+1];if(t.strict===!0&&n<P[1])throw new Error(`${k} integer encoded in more bytes than necessary (strict decode)`);return n}function q(r,e,t){ae(r,e,4);let n=r[e]*16777216+(r[e+1]<<16)+(r[e+2]<<8)+r[e+3];if(t.strict===!0&&n<P[2])throw new Error(`${k} integer encoded in more bytes than necessary (strict decode)`);return n}function j(r,e,t){ae(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],s=(BigInt(n)<<BigInt(32))+BigInt(o);if(t.strict===!0&&s<P[3])throw new Error(`${k} integer encoded in more bytes than necessary (strict decode)`);if(s<=Number.MAX_SAFE_INTEGER)return Number(s);if(t.allowBigInt===!0)return s;throw new Error(`${k} integers outside of the safe integer range are not supported`)}function xo(r,e,t,n){return new g(u.uint,z(r,e+1,n),2)}function bo(r,e,t,n){return new g(u.uint,V(r,e+1,n),3)}function Eo(r,e,t,n){return new g(u.uint,q(r,e+1,n),5)}function vo(r,e,t,n){return new g(u.uint,j(r,e+1,n),9)}function H(r,e){return $(r,0,e.value)}function $(r,e,t){if(t<P[0]){let n=Number(t);r.push([e|n])}else if(t<P[1]){let n=Number(t);r.push([e|24,n])}else if(t<P[2]){let n=Number(t);r.push([e|25,n>>>8,n&255])}else if(t<P[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<P[4]){let o=[e|27,0,0,0,0,0,0,0],s=Number(n&BigInt(4294967295)),i=Number(n>>BigInt(32)&BigInt(4294967295));o[8]=s&255,s=s>>8,o[7]=s&255,s=s>>8,o[6]=s&255,s=s>>8,o[5]=s&255,o[4]=i&255,i=i>>8,o[3]=i&255,i=i>>8,o[2]=i&255,i=i>>8,o[1]=i&255,r.push(o)}else throw new Error(`${k} encountered BigInt larger than allowable range`)}}H.encodedSize=function(e){return $.encodedSize(e.value)};$.encodedSize=function(e){return e<P[0]?1:e<P[1]?2:e<P[2]?3:e<P[3]?5:9};H.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-z(r,e+1,n),2)}function Ao(r,e,t,n){return new g(u.negint,-1-V(r,e+1,n),3)}function Co(r,e,t,n){return new g(u.negint,-1-q(r,e+1,n),5)}var Jr=BigInt(-1),To=BigInt(1);function So(r,e,t,n){let o=j(r,e+1,n);if(typeof o!="bigint"){let s=-1-o;if(s>=Number.MIN_SAFE_INTEGER)return new g(u.negint,s,9)}if(n.allowBigInt!==!0)throw new Error(`${k} integers outside of the safe integer range are not supported`);return new g(u.negint,Jr-BigInt(o),9)}function Pt(r,e){let t=e.value,n=typeof t=="bigint"?t*Jr-To:t*-1-1;$(r,e.type.majorEncoded,n)}Pt.encodedSize=function(e){let t=e.value,n=typeof t=="bigint"?t*Jr-To:t*-1-1;return n<P[0]?1:n<P[1]?2:n<P[2]?3:n<P[3]?5:9};Pt.compareTokens=function(e,t){return e.value<t.value?1:e.value>t.value?-1:0};function ot(r,e,t,n){ae(r,e,t+n);let o=Oe(r,e+t,e+t+n);return new g(u.bytes,o,t+n)}function Lo(r,e,t,n){return ot(r,e,1,t)}function _o(r,e,t,n){return ot(r,e,2,z(r,e+1,n))}function Io(r,e,t,n){return ot(r,e,3,V(r,e+1,n))}function Do(r,e,t,n){return ot(r,e,5,q(r,e+1,n))}function Uo(r,e,t,n){let o=j(r,e+1,n);if(typeof o=="bigint")throw new Error(`${k} 64-bit integer bytes lengths not supported`);return ot(r,e,9,o)}function Bt(r){return r.encodedBytes===void 0&&(r.encodedBytes=r.type===u.string?Ut(r.value):r.value),r.encodedBytes}function Re(r,e){let t=Bt(e);$(r,e.type.majorEncoded,t.length),r.push(t)}Re.encodedSize=function(e){let t=Bt(e);return $.encodedSize(t.length)+t.length};Re.compareTokens=function(e,t){return Pa(Bt(e),Bt(t))};function Pa(r,e){return r.length<e.length?-1:r.length>e.length?1:wo(r,e)}function st(r,e,t,n,o){let s=t+n;ae(r,e,s);let i=new g(u.string,mo(r,e+t,e+s),s);return o.retainStringBytes===!0&&(i.byteValue=Oe(r,e+t,e+s)),i}function Po(r,e,t,n){return st(r,e,1,t,n)}function Bo(r,e,t,n){return st(r,e,2,z(r,e+1,n),n)}function No(r,e,t,n){return st(r,e,3,V(r,e+1,n),n)}function $o(r,e,t,n){return st(r,e,5,q(r,e+1,n),n)}function Fo(r,e,t,n){let o=j(r,e+1,n);if(typeof o=="bigint")throw new Error(`${k} 64-bit integer string lengths not supported`);return st(r,e,9,o,n)}var Oo=Re;function ze(r,e,t,n){return new g(u.array,n,t)}function Mo(r,e,t,n){return ze(r,e,1,t)}function Ro(r,e,t,n){return ze(r,e,2,z(r,e+1,n))}function zo(r,e,t,n){return ze(r,e,3,V(r,e+1,n))}function Vo(r,e,t,n){return ze(r,e,5,q(r,e+1,n))}function qo(r,e,t,n){let o=j(r,e+1,n);if(typeof o=="bigint")throw new Error(`${k} 64-bit integer array lengths not supported`);return ze(r,e,9,o)}function jo(r,e,t,n){if(n.allowIndefinite===!1)throw new Error(`${k} indefinite length items not allowed`);return ze(r,e,1,1/0)}function Nt(r,e){$(r,u.array.majorEncoded,e.value)}Nt.compareTokens=H.compareTokens;Nt.encodedSize=function(e){return $.encodedSize(e.value)};function Ve(r,e,t,n){return new g(u.map,n,t)}function Wo(r,e,t,n){return Ve(r,e,1,t)}function Ho(r,e,t,n){return Ve(r,e,2,z(r,e+1,n))}function Ko(r,e,t,n){return Ve(r,e,3,V(r,e+1,n))}function Go(r,e,t,n){return Ve(r,e,5,q(r,e+1,n))}function Qo(r,e,t,n){let o=j(r,e+1,n);if(typeof o=="bigint")throw new Error(`${k} 64-bit integer map lengths not supported`);return Ve(r,e,9,o)}function Jo(r,e,t,n){if(n.allowIndefinite===!1)throw new Error(`${k} indefinite length items not allowed`);return Ve(r,e,1,1/0)}function $t(r,e){$(r,u.map.majorEncoded,e.value)}$t.compareTokens=H.compareTokens;$t.encodedSize=function(e){return $.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,z(r,e+1,n),2)}function Zo(r,e,t,n){return new g(u.tag,V(r,e+1,n),3)}function es(r,e,t,n){return new g(u.tag,q(r,e+1,n),5)}function ts(r,e,t,n){return new g(u.tag,j(r,e+1,n),9)}function Ft(r,e){$(r,u.tag.majorEncoded,e.value)}Ft.compareTokens=H.compareTokens;Ft.encodedSize=function(e){return $.encodedSize(e.value)};var Ma=20,Ra=21,za=22,Va=23;function rs(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 ns(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 Xr(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 os(r,e,t,n){return Xr(Yr(r,e+1),3,n)}function ss(r,e,t,n){return Xr(Zr(r,e+1),5,n)}function is(r,e,t,n){return Xr(fs(r,e+1),9,n)}function Ot(r,e,t){let n=e.value;if(n===!1)r.push([u.float.majorEncoded|Ma]);else if(n===!0)r.push([u.float.majorEncoded|Ra]);else if(n===null)r.push([u.float.majorEncoded|za]);else if(n===void 0)r.push([u.float.majorEncoded|Va]);else{let o,s=!1;(!t||t.float64!==!0)&&(cs(n),o=Yr(X,1),n===o||Number.isNaN(n)?(X[0]=249,r.push(X.slice(0,3)),s=!0):(us(n),o=Zr(X,1),n===o&&(X[0]=250,r.push(X.slice(0,5)),s=!0))),s||(qa(n),o=fs(X,1),X[0]=251,r.push(X.slice(0,9)))}}Ot.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){cs(n);let o=Yr(X,1);if(n===o||Number.isNaN(n))return 3;if(us(n),o=Zr(X,1),n===o)return 5}return 9};var as=new ArrayBuffer(9),K=new DataView(as,1),X=new Uint8Array(as,0);function cs(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 Yr(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,s;return n===0?s=o*2**-24:n!==31?s=(o+1024)*2**(n-25):s=o===0?1/0:NaN,t&32768?-s:s}function us(r){K.setFloat32(0,r,!1)}function Zr(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 qa(r){K.setFloat64(0,r,!1)}function fs(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)}Ot.compareTokens=H.compareTokens;function I(r,e,t){throw new Error(`${k} encountered invalid minor (${t}) for major ${r[e]>>>5}`)}function Mt(r){return()=>{throw new Error(`${k} ${r}`)}}var x=[];for(let r=0;r<=23;r++)x[r]=I;x[24]=xo;x[25]=bo;x[26]=Eo;x[27]=vo;x[28]=I;x[29]=I;x[30]=I;x[31]=I;for(let r=32;r<=55;r++)x[r]=I;x[56]=ko;x[57]=Ao;x[58]=Co;x[59]=So;x[60]=I;x[61]=I;x[62]=I;x[63]=I;for(let r=64;r<=87;r++)x[r]=Lo;x[88]=_o;x[89]=Io;x[90]=Do;x[91]=Uo;x[92]=I;x[93]=I;x[94]=I;x[95]=Mt("indefinite length bytes/strings are not supported");for(let r=96;r<=119;r++)x[r]=Po;x[120]=Bo;x[121]=No;x[122]=$o;x[123]=Fo;x[124]=I;x[125]=I;x[126]=I;x[127]=Mt("indefinite length bytes/strings are not supported");for(let r=128;r<=151;r++)x[r]=Mo;x[152]=Ro;x[153]=zo;x[154]=Vo;x[155]=qo;x[156]=I;x[157]=I;x[158]=I;x[159]=jo;for(let r=160;r<=183;r++)x[r]=Wo;x[184]=Ho;x[185]=Ko;x[186]=Go;x[187]=Qo;x[188]=I;x[189]=I;x[190]=I;x[191]=Jo;for(let r=192;r<=215;r++)x[r]=Xo;x[216]=Yo;x[217]=Zo;x[218]=es;x[219]=ts;x[220]=I;x[221]=I;x[222]=I;x[223]=I;for(let r=224;r<=243;r++)x[r]=Mt("simple values are not supported");x[244]=I;x[245]=I;x[246]=I;x[247]=rs;x[248]=Mt("simple values are not supported");x[249]=os;x[250]=ss;x[251]=is;x[252]=I;x[253]=I;x[254]=I;x[255]=ns;var Y=[];for(let r=0;r<24;r++)Y[r]=new g(u.uint,r,1);for(let r=-1;r>=-24;r--)Y[31-r]=new g(u.negint,r,1);Y[64]=new g(u.bytes,new Uint8Array(0),1);Y[96]=new g(u.string,"",1);Y[128]=new g(u.array,0,1);Y[160]=new g(u.map,0,1);Y[244]=new g(u.false,!1,1);Y[245]=new g(u.true,!0,1);Y[246]=new g(u.null,null,1);function ls(r){switch(r.type){case u.false:return Z([244]);case u.true:return Z([245]);case u.null:return Z([246]);case u.bytes:return r.value.length?void 0:Z([64]);case u.string:return r.value===""?Z([96]):void 0;case u.array:return r.value===0?Z([128]):void 0;case u.map:return r.value===0?Z([160]):void 0;case u.uint:return r.value<24?Z([Number(r.value)]):void 0;case u.negint:if(r.value>=-24)return Z([31-Number(r.value)])}}var Wa={float64:!1,mapSorter:Ga,quickEncodeToken:ls};function Ha(){let r=[];return r[u.uint.major]=H,r[u.negint.major]=Pt,r[u.bytes.major]=Re,r[u.string.major]=Oo,r[u.array.major]=Nt,r[u.map.major]=$t,r[u.tag.major]=Ft,r[u.float.major]=Ot,r}var ds=Ha(),en=new rt,zt=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(`${Me} object contains circular references`);return new r(t,e)}},ge={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)},ye={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?ge.true:ge.false},null(r,e,t,n){return ge.null},undefined(r,e,t,n){return ge.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?[ge.emptyArray,new g(u.break)]:ge.emptyArray;n=zt.createCheck(n,r);let o=[],s=0;for(let i of r)o[s++]=Rt(i,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",s=o?r.keys():Object.keys(r),i=o?r.size:s.length;if(!i)return t.addBreakTokens===!0?[ge.emptyMap,new g(u.break)]:ge.emptyMap;n=zt.createCheck(n,r);let c=[],f=0;for(let p of s)c[f++]=[Rt(p,t,n),Rt(o?r.get(p):r[p],t,n)];return Ka(c,t),t.addBreakTokens?[new g(u.map,i),c,new g(u.break)]:[new g(u.map,i),c]}};ye.Map=ye.Object;ye.Buffer=ye.Uint8Array;for(let r of"Uint8Clamped Uint16 Uint32 Int8 Int16 Int32 BigUint64 BigInt64 Float32 Float64".split(" "))ye[`${r}Array`]=ye.DataView;function Rt(r,e={},t){let n=fo(r),o=e&&e.typeEncoders&&e.typeEncoders[n]||ye[n];if(typeof o=="function"){let i=o(r,n,e,t);if(i!=null)return i}let s=ye[n];if(!s)throw new Error(`${Me} unsupported type: ${n}`);return s(r,n,e,t)}function Ka(r,e){e.mapSorter&&r.sort(e.mapSorter)}function Ga(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,s=ds[o].compareTokens(t,n);return s===0&&console.warn("WARNING: complex key types used, CBOR key sorting guarantees are gone"),s}function hs(r,e,t,n){if(Array.isArray(e))for(let o of e)hs(r,o,t,n);else t[e.type.major](r,e,n)}function ps(r,e,t){let n=Rt(r,t);if(!Array.isArray(n)&&t.quickEncodeToken){let o=t.quickEncodeToken(n);if(o)return o;let s=e[n.type.major];if(s.encodedSize){let i=s.encodedSize(n,t),c=new rt(i);if(s(c,n,t),c.chunks.length!==1)throw new Error(`Unexpected error: pre-calculated length for ${n} was wrong`);return tt(c.chunks[0])}}return en.reset(),hs(en,n,e,t),en.toBytes(!0)}function it(r,e){return e=Object.assign({},Wa,e),ps(r,ds,e)}var Qa={strict:!1,allowIndefinite:!0,allowUndefined:!0,allowBigInt:!0},Vt=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=Y[e];if(t===void 0){let n=x[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}},at=Symbol.for("DONE"),qt=Symbol.for("BREAK");function Ja(r,e,t){let n=[];for(let o=0;o<r.value;o++){let s=qe(e,t);if(s===qt){if(r.value===1/0)break;throw new Error(`${k} got unexpected break to lengthed array`)}if(s===at)throw new Error(`${k} found array but not enough entries (got ${o}, expected ${r.value})`);n[o]=s}return n}function Xa(r,e,t){let n=t.useMaps===!0,o=n?void 0:{},s=n?new Map:void 0;for(let i=0;i<r.value;i++){let c=qe(e,t);if(c===qt){if(r.value===1/0)break;throw new Error(`${k} got unexpected break to lengthed map`)}if(c===at)throw new Error(`${k} found map but not enough entries (got ${i} [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&&s.has(c)||!n&&c in o))throw new Error(`${k} found repeat map key "${c}"`);let f=qe(e,t);if(f===at)throw new Error(`${k} found map but not enough entries (got ${i} [no value], expected ${r.value})`);n?s.set(c,f):o[c]=f}return n?s:o}function qe(r,e){if(r.done())return at;let t=r.next();if(t.type===u.break)return qt;if(t.type.terminal)return t.value;if(t.type===u.array)return Ja(t,r,e);if(t.type===u.map)return Xa(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 tn(r,e){if(!(r instanceof Uint8Array))throw new Error(`${k} data to decode must be a Uint8Array`);e=Object.assign({},Qa,e);let t=e.tokenizer||new Vt(r,e),n=qe(t,e);if(n===at)throw new Error(`${k} did not find any content to decode`);if(n===qt)throw new Error(`${k} got unexpected break`);return[n,r.subarray(t.pos())]}function ee(r,e){let[t,n]=tn(r,e);if(n.length>0)throw new Error(`${k} too many terminals, data makes no sense`);return t}function ke(r,e="utf8"){let t=vt[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.decoder.decode(`${t.prefix}${r}`)}var ce="/",ms=new TextEncoder().encode(ce),jt=ms[0],ue=class r{_buf;constructor(e,t){if(typeof e=="string")this._buf=ke(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]!==jt)throw new Error("Invalid key")}toString(e="utf8"){return Ne(this._buf,e)}uint8Array(){return this._buf}get[Symbol.toStringTag](){return`Key(${this.toString()})`}static withNamespaces(e){return new r(e.join(ce))}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=ms),this._buf[0]!==jt){let e=new Uint8Array(this._buf.byteLength+1);e.fill(jt,0,1),e.set(this._buf,1),this._buf=e}for(;this._buf.byteLength>1&&this._buf[this._buf.byteLength-1]===jt;)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 s=t[o],i=n[o];if(s<i)return!0;if(s>i)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(ce).slice(1)}type(){return Ya(this.baseNamespace())}name(){return Za(this.baseNamespace())}instance(e){return new r(this.toString()+":"+e)}path(){let e=this.parent().toString();return e.endsWith(ce)||(e+=ce),e+=this.type(),new r(e)}parent(){let e=this.list();return e.length===1?new r(ce):new r(e.slice(0,-1).join(ce))}child(e){return this.toString()===ce?e:e.toString()===ce?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(),...ec(e.map(t=>t.namespaces()))])}};function Ya(r){let e=r.split(":");return e.length<2?"":e.slice(0,-1).join(":")}function Za(r){let e=r.split(":");return e[e.length-1]}function ec(r){return[].concat(...r)}function Ae(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 xs="/pin/",gs="/pinned-block/",nn=oe,ys=1;function ws(r){return r.version===0&&(r=r.toV1()),new ue(`${xs}${r.toString(nn)}`)}var Wt=class{datastore;blockstore;dagWalkers;constructor(e,t,n){this.datastore=e,this.blockstore=t,this.dagWalkers=n}async*add(e,t={}){let n=ws(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 s=new ie({concurrency:ys});for await(let c of this.#e(e,s,{...t,depth:o}))await this.#o(c,f=>f.pinnedBy.find(p=>Ae(p,e.bytes))!=null?!1:(f.pinCount++,f.pinnedBy.push(e.bytes),!0),t),yield c;let i={depth:o,metadata:t.metadata??{}};await this.datastore.put(n,it(i),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 s=await this.blockstore.get(e,n);yield e;for await(let i of o.walk(s))yield*await t.add(async()=>this.#e(i,t,{...n,depth:n.depth-1}))}async#o(e,t,n){let o=new ue(`${gs}${nn.encode(e.multihash.bytes)}`),s={pinCount:0,pinnedBy:[]};try{s=ee(await this.datastore.get(o,n))}catch(c){if(c.name!=="NotFoundError")throw c}if(t(s)){if(s.pinCount===0&&await this.datastore.has(o)){await this.datastore.delete(o);return}await this.datastore.put(o,it(s),n),n.onProgress?.(new D("helia:pin:add",e))}}async*rm(e,t={}){let n=ws(e),o=await this.datastore.get(n,t),s=ee(o);await this.datastore.delete(n,t);let i=new ie({concurrency:ys});for await(let c of this.#e(e,i,{...t,depth:s.depth}))await this.#o(c,f=>(f.pinCount--,f.pinnedBy=f.pinnedBy.filter(p=>Ae(p,e.bytes)),!0),{...t,depth:s.depth}),yield c}async*ls(e={}){for await(let{key:t,value:n}of this.datastore.query({prefix:xs+(e.cid!=null?`${e.cid.toString(oe)}`:"")},e)){let o=N.parse(t.toString().substring(5),oe),s=ee(n);yield{cid:o,...s}}}async isPinned(e,t={}){let n=new ue(`${gs}${nn.encode(e.multihash.bytes)}`);return this.datastore.has(n,t)}};var Ht=class extends Error{static name="InsufficientProvidersError";constructor(e="Insufficient providers found"){super(e),this.name="InsufficientProvidersError"}},Ce=class extends Error{static name="NoRoutersAvailableError";constructor(e="No routers available"){super(e),this.name="NoRoutersAvailableError"}};var Kt=class extends ie{has(e){return this.find(e)!=null}find(e){return this.queue.find(t=>e.equals(t.options.peerId))}};function tc(r){return r[Symbol.asyncIterator]!=null}function rc(...r){let e=[];for(let t of r)tc(t)||e.push(t);return e.length===r.length?function*(){for(let t of e)yield*t}():async function*(){let t=Tt({objectMode:!0});Promise.resolve().then(async()=>{try{await Promise.all(r.map(async n=>{for await(let o of n)t.push(o)})),t.end()}catch(n){t.end(n)}}),yield*t}()}var Gt=rc;var nc=5,Qt=class{log;routers;providerLookupConcurrency;constructor(e,t){this.log=e.logger.forComponent("helia:routing"),this.routers=t.routers??[],this.providerLookupConcurrency=t.providerLookupConcurrency??nc}async start(){await fe(...this.routers)}async stop(){await le(...this.routers)}async*findProviders(e,t={}){if(this.routers.length===0)throw new Ce("No content routers available");let n=new Kt({concurrency:this.providerLookupConcurrency});n.addEventListener("error",()=>{});for await(let o of Gt(n.toGenerator(),...je(this.routers,"findProviders").map(s=>s.findProviders(e,t))))if(o!=null){if(o.multiaddrs.length===0){if(n.find(o.id)!=null)continue;n.add(async()=>{try{let s=await this.findPeer(o.id,t);return s.multiaddrs.length===0?null:s}catch(s){return this.log.error("could not load multiaddrs for peer %p",o.id,s),null}},{peerId:o.id,signal:t.signal}).catch(s=>{this.log.error("could not load multiaddrs for peer %p",o.id,s)})}yield o}}async provide(e,t={}){if(this.routers.length===0)throw new Ce("No content 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 Ce("No peer routers available");let n=this,o=Gt(...je(this.routers,"findPeer").map(s=>async function*(){try{yield await s.findPeer(e,t)}catch(i){n.log.error(i)}}()));for await(let s of o)if(s!=null)return s;throw new pt("Could not find peer in routing")}async*getClosestPeers(e,t={}){if(this.routers.length===0)throw new Ce("No peer routers available");for await(let n of Gt(...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 we={},We=r=>{r.addEventListener("message",e=>{We.dispatchEvent("message",r,e)}),r.port!=null&&r.port.addEventListener("message",e=>{We.dispatchEvent("message",r,e)})};We.addEventListener=(r,e)=>{we[r]==null&&(we[r]=[]),we[r].push(e)};We.removeEventListener=(r,e)=>{we[r]!=null&&(we[r]=we[r].filter(t=>t===e))};We.dispatchEvent=function(r,e,t){we[r]!=null&&we[r].forEach(n=>n(e,t))};var on=We;var sn="lock:worker:request-read",an="lock:worker:release-read",cn="lock:master:grant-read",un="lock:worker:request-write",fn="lock:worker:release-write",ln="lock:master:grant-write";var bs=(r=21)=>Math.random().toString().substring(2);var Es=(r,e,t,n,o)=>(s,i)=>{if(i.data.type!==t)return;let c={type:i.data.type,name:i.data.name,identifier:i.data.identifier};r.dispatchEvent(new MessageEvent(e,{data:{name:c.name,handler:async()=>{s.postMessage({type:o,name:c.name,identifier:c.identifier}),await new Promise(f=>{let p=d=>{if(d==null||d.data==null)return;let l={type:d.data.type,name:d.data.name,identifier:d.data.identifier};l.type===n&&l.identifier===c.identifier&&(s.removeEventListener("message",p),f())};s.addEventListener("message",p)})}}}))},vs=(r,e,t,n)=>async()=>{let o=bs();return globalThis.postMessage({type:e,identifier:o,name:r}),new Promise(s=>{let i=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",i),s(()=>{globalThis.postMessage({type:n,identifier:o,name:r})}))};globalThis.addEventListener("message",i)})},oc={singleProcess:!1},ks=r=>{if(r=Object.assign({},oc,r),!!globalThis.document||r.singleProcess){let t=new EventTarget;return on.addEventListener("message",Es(t,"requestReadLock",sn,an,cn)),on.addEventListener("message",Es(t,"requestWriteLock",un,fn,ln)),t}return{isWorker:!0,readLock:t=>vs(t,sn,cn,an),writeLock:t=>vs(t,un,ln,fn)}};var Te={},xe;async function dn(r,e){let t,n=new Promise(o=>{t=o});return r.add(async()=>Qe((async()=>{await new Promise(o=>{t(()=>{o()})})})(),{milliseconds:e.timeout})),n}var sc=(r,e)=>{if(xe.isWorker===!0)return{readLock:xe.readLock(r,e),writeLock:xe.writeLock(r,e)};let t=new me({concurrency:1}),n;return{async readLock(){if(n!=null)return dn(n,e);n=new me({concurrency:e.concurrency,autoStart:!1});let o=n,s=dn(n,e);return t.add(async()=>{o.start(),await o.onIdle().then(()=>{n===o&&(n=null)})}),s},async writeLock(){return n=null,dn(t,e)}}},ic={name:"lock",concurrency:1/0,timeout:846e5,singleProcess:!1};function hn(r){let e=Object.assign({},ic,r);return xe==null&&(xe=ks(e),xe.isWorker!==!0&&(xe.addEventListener("requestReadLock",t=>{Te[t.data.name]!=null&&Te[t.data.name].readLock().then(async n=>t.data.handler().finally(()=>{n()}))}),xe.addEventListener("requestWriteLock",async t=>{Te[t.data.name]!=null&&Te[t.data.name].writeLock().then(async n=>t.data.handler().finally(()=>{n()}))}))),Te[e.name]==null&&(Te[e.name]=sc(e.name,e)),Te[e.name]}var Jt=class{lock;child;pins;started;constructor(e,t,n={}){this.child=e,this.pins=t,this.lock=hn({singleProcess:n.holdGcLock}),this.started=!1}isStarted(){return this.started}async start(){await fe(this.child),this.started=!0}async stop(){await le(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 s of e){if(await o.pins.isPinned(s))throw new Error("CID was pinned");yield s}}(),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 Cs=42;function ac(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,Cs),new g(u.bytes,t)]}function cc(){throw new Error("`undefined` is not supported by the IPLD Data Model and cannot be encoded")}function uc(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 As={float64:!0,typeEncoders:{Object:ac,undefined:cc,number:uc}},$d={...As,typeEncoders:{...As.typeEncoders}};function fc(r){if(r[0]!==0)throw new Error("Invalid CID for CBOR tag 42; expected leading 0x00");return N.decode(r.subarray(1))}var pn={allowIndefinite:!1,coerceUndefinedToNull:!0,allowNaN:!1,allowInfinity:!1,allowBigInt:!0,strict:!0,useMaps:!1,rejectDuplicateMapKeys:!0,tags:[]};pn.tags[Cs]=fc;var Fd={...pn,tags:pn.tags.slice()};var Ts=113;var Ss=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 s=0;s<n.length;s++)o[s]=n.charCodeAt(s);e.push(o)}[u.negint.major](e,t){this[u.uint.major](e,t)}[u.bytes.major](e,t){throw new Error(`${Me} unsupported type: Uint8Array`)}[u.string.major](e,t){this.prefix(e);let n=Ut(JSON.stringify(t.value));e.push(n.length>32?tt(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 i=this.inRecursive.pop();if(i){if(i.type===u.array)e.push([93]);else if(i.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(`${Me} 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=[],s=!1;for(let i=0;i<n.length;i++)o[i]=n.charCodeAt(i),!s&&(o[i]===46||o[i]===101||o[i]===69)&&(s=!0);s||(o.push(46),o.push(48)),e.push(o)}};var Se=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 s=String.fromCharCode.apply(null,this.data.subarray(e,this._pos)),i=parseFloat(s);return n?new g(u.float,i,this._pos-e):this.options.allowBigInt!==!0||Number.isSafeInteger(i)?new g(i>=0?u.uint:u.negint,i,this._pos-e):new g(i>=0?u.uint:u.negint,BigInt(s),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 s=this._pos,i=0;s<this.data.length&&i<65536;s++,i++){let c=this.data[s];if(c===92||c<32||c>=128)break;if(c===34){let f=String.fromCharCode.apply(null,this.data.subarray(this._pos,s));return this._pos=s+1,new g(u.string,f,i)}}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 s=0;for(let i=0;i<4;i++){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}`);s=s*16+c,this._pos++}return s},o=()=>{let s=this.ch(),i=null,c=s>239?4:s>223?3:s>191?2:1;if(this._pos+c>this.data.length)throw new Error(`${k} unexpected unicode sequence at position ${this._pos}`);let f,p,d,l;switch(c){case 1:s<128&&(i=s);break;case 2:f=this.data[this._pos+1],(f&192)===128&&(l=(s&31)<<6|f&63,l>127&&(i=l));break;case 3:f=this.data[this._pos+1],p=this.data[this._pos+2],(f&192)===128&&(p&192)===128&&(l=(s&15)<<12|(f&63)<<6|p&63,l>2047&&(l<55296||l>57343)&&(i=l));break;case 4:f=this.data[this._pos+1],p=this.data[this._pos+2],d=this.data[this._pos+3],(f&192)===128&&(p&192)===128&&(d&192)===128&&(l=(s&15)<<18|(f&63)<<12|(p&63)<<6|d&63,l>65535&&l<1114112&&(i=l))}i===null?(i=65533,c=1):i>65535&&(i-=65536,t.push(i>>>10&1023|55296),i=56320|i&1023),t.push(i),this._pos+=c};for(;!this.done();){let s=this.ch(),i;switch(s){case 92:if(this._pos++,this.done())throw new Error(`${k} unexpected string termination at position ${this._pos}`);switch(i=this.ch(),this._pos++,i){case 34:case 39:case 92:case 47:t.push(i);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,Qr(t),this._pos-e);default:if(s<32)throw new Error(`${k} invalid control character at position ${this._pos}`);s<128?(t.push(s),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 Se(r,e)},e),ee(r,e)}var hc={allowIndefinite:!1,allowUndefined:!1,allowNaN:!1,allowInfinity:!1,allowBigInt:!0,strict:!0,useMaps:!1,rejectDuplicateMapKeys:!0,tags:[]};hc.tags[42]=N.parse;var _s=297;var eh=new TextDecoder;var th=new TextEncoder;var mc=new TextDecoder;function mn(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]=mn(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 Is(r,e){let t;return[t,e]=mn(r,e),[t&7,t>>3,e]}function gc(r){let e={},t=r.length,n=0;for(;n<t;){let o,s;if([o,s,n]=Is(r,n),s===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(s===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 i;[i,n]=Yt(r,n),e.Name=mc.decode(i)}else if(s===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]=mn(r,n)}else throw new Error(`protobuf: (PBLink) invalid fieldNumber, expected 1, 2 or 3, got ${s}`)}if(n>t)throw new Error("protobuf: (PBLink) unexpected end of data");return e}function Ds(r){let e=r.length,t=0,n,o=!1,s;for(;t<e;){let c,f;if([c,f,t]=Is(r,t),c!==2)throw new Error(`protobuf: (PBNode) invalid wireType, expected 2, got ${c}`);if(f===1){if(s)throw new Error("protobuf: (PBNode) duplicate Data section");[s,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(gc(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 i={};return s&&(i.Data=s),i.Links=n||[],i}var nh=new TextEncoder,oh=2**32,sh=2**31;var ch=new TextEncoder;function Us(r){return r instanceof ArrayBuffer?new Uint8Array(r,0,r.byteLength):r}var Ps=112;function Bs(r){let e=Us(r),t=Ds(e),n={};return t.Data&&(n.Data=t.Data),t.Links&&(n.Links=t.Links.map(o=>{let s={};try{s.Hash=N.decode(o.Hash)}catch{}if(!s.Hash)throw new Error("Invalid Hash field found in link, expected CID");return o.Name!==void 0&&(s.Name=o.Name),o.Tsize!==void 0&&(s.Tsize=o.Tsize),s})),n}var wc={codec:Ps,*walk(r){yield*Bs(r).Links.map(t=>t.Hash)}},xc={codec:Rn,*walk(){}},Ns=42,bc={codec:Ts,*walk(r){let e=[],t=[];t[Ns]=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},ee(r,{tags:t}),yield*e}},gn=class extends Se{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 s=this._next();if(s.type===u.string){for(let c=0;c<2;c++)if(this._next().type!==u.break)throw new Error("Invalid encoded Bytes form");let i=pe.decode(`m${s.value}`);return new g(u.bytes,i,s.value.length)}this.tokenBuffer.push(s)}this.tokenBuffer.push(o)}this.tokenBuffer.push(n)}this.tokenBuffer.push(t)}return e}},Ec={codec:_s,*walk(r){let e=[],t=[];t[Ns]=n=>{let o=N.parse(n);return e.push(o),o},Xt(r,{tags:t,tokenizer:new gn(r,{tags:t,allowIndefinite:!0,allowUndefined:!0,allowNaN:!0,allowInfinity:!0,allowBigInt:!0,strict:!1,rejectDuplicateMapKeys:!1})}),yield*e}},vc={codec:On,*walk(){}};function $s(r=[]){let e={};return[wc,xc,bc,Ec,vc,...r].forEach(t=>{e[t.codec]=t}),e}var yn=new ue("/version"),Fs=1;async function Os(r){if(!await r.has(yn)){await r.put(yn,ke(`${Fs}`));return}let e=await r.get(yn),t=Ne(e);if(parseInt(t,10)!==Fs)throw new Error("Unknown datastore version, a datastore migration may be required")}function Ms(r=[]){let e={};return[Or,Mr,Br,...r].forEach(t=>{e[t.code]=t}),e}function te(r){let e=new globalThis.AbortController;function t(){e.abort();for(let s of r)s?.removeEventListener!=null&&s.removeEventListener("abort",t)}for(let s of r){if(s?.aborted===!0){t();break}s?.addEventListener!=null&&s.addEventListener("abort",t)}function n(){for(let s of r)s?.removeEventListener!=null&&s.removeEventListener("abort",t)}let o=e.signal;return o.clear=n,o}var Zt=class r extends Error{static name="NotFoundError";static code="ERR_NOT_FOUND";name=r.name;code=r.code;constructor(e="Not Found"){super(e)}};var er=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 tr=0,rr=class extends er{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 new Zt;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 kc(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=kc;function Ac(r){return r[Symbol.asyncIterator]!=null}function Cc(r,e){let t=0;if(Ac(r))return async function*(){for await(let f of r)await e(f,t++)&&(yield f)}();let n=nr(r),{value:o,done:s}=n.next();if(s===!0)return function*(){}();let i=e(o,t++);if(typeof i.then=="function")return async function*(){await i&&(yield o);for await(let f of n)await e(f,t++)&&(yield f)}();let c=e;return function*(){i===!0&&(yield o);for(let f of n)c(f,t++)&&(yield f)}()}var Rs=Cc;function Tc(r){return r[Symbol.asyncIterator]!=null}function zs(r){return r?.then!=null}function Sc(r,e){let t=0;if(Tc(r))return async function*(){for await(let f of r){let p=e(f,t++);zs(p)&&await p,yield f}}();let n=nr(r),{value:o,done:s}=n.next();if(s===!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++);zs(p)&&await p,yield f}}();let c=e;return function*(){yield o;for(let f of n)c(f,t++),yield f}()}var wn=Sc;var or=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=Rs(e,async({cid:s})=>{let i=await this.child.has(s,t);return i&&t.onProgress?.(new D("blocks:put-many:duplicate",s)),!i}),o=wn(n,async({cid:s,block:i})=>{t.onProgress?.(new D("blocks:put-many:providers:notify",s)),await Promise.all(this.components.blockBrokers.map(async c=>c.announce?.(s,i,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 Vs(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(wn(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 Vs(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 s=>s.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)}},sr=class extends or{started;constructor(e){super(e),this.started=!1}isStarted(){return this.started}async start(){await fe(this.child,...this.components.blockBrokers),this.started=!0}async stop(){await le(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 xn({blockstore:this.child,blockBrokers:n,hashers:this.hashers,logger:this.logger},{root:e})}},xn=class extends or{closeController;constructor(e,t){super(e),this.closeController=new AbortController,B(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=te([this.closeController.signal,n.signal]);B(1/0,o);try{return await super.put(e,t,{...n,signal:o})}finally{o.clear()}}async*putMany(e,t={}){let n=te([this.closeController.signal,t.signal]);B(1/0,n);try{yield*super.putMany(e,{...t,signal:n})}finally{n.clear()}}async get(e,t={}){let n=te([this.closeController.signal,t.signal]);B(1/0,n);try{return await super.get(e,{...t,signal:n})}finally{n.clear()}}async*getMany(e,t={}){let n=te([this.closeController.signal,t.signal]);B(1/0,n);try{yield*super.getMany(e,{...t,signal:n})}finally{n.clear()}}async delete(e,t={}){let n=te([this.closeController.signal,t.signal]);B(1/0,n);try{await super.delete(e,{...t,signal:n})}finally{n.clear()}}async*deleteMany(e,t={}){let n=te([this.closeController.signal,t.signal]);B(1/0,n);try{yield*super.deleteMany(e,{...t,signal:n})}finally{n.clear()}}async has(e,t={}){let n=te([this.closeController.signal,t.signal]);B(1/0,n);try{return await super.has(e,{...t,signal:n})}finally{n.clear()}}async*getAll(e={}){let t=te([this.closeController.signal,e.signal]);B(1/0,t);try{yield*super.getAll({...e,signal:t})}finally{t.clear()}}};function Lc(r){return typeof r.retrieve=="function"}var _c=(r,e)=>{if(e==null)throw new _e(`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`);return async t=>{let n=await e.digest(t);if(!Ae(n.digest,r.multihash.digest))throw new mt("Hash of downloaded block did not match multihash from passed CID")}};async function Vs(r,e,t,n){let o=_c(r,t),s=new AbortController,i=te([s.signal,n.signal]);B(1/0,s.signal,i);let c=[];for(let f of e)Lc(f)&&c.push(f);try{return await Promise.any(c.map(async f=>{try{let p=!1,d=await f.retrieve(r,{...n,signal:i,validateFn:async l=>{await o(l),p=!0}});return p||await o(d),d}catch(p){throw n.log.error("could not retrieve verified block for %c",r,p),p}}))}finally{s.abort(),i.clear()}}var Le=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;var Zh=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;var ep={}.toString;function qs(r=32){if(Le&&typeof Le.getRandomValues=="function")return Le.getRandomValues(new Uint8Array(r));if(Le&&typeof Le.randomBytes=="function")return Le.randomBytes(r);throw new Error("crypto.getRandomValues must be defined")}function ir(r){if(isNaN(r)||r<=0)throw new _e("random bytes length must be a Number bigger than 0");return qs(r)}function bn(r,e){e==null&&(e=r.reduce((o,s)=>o+s.length,0));let t=Ee(e),n=0;for(let o of r)t.set(o,n),n+=o.length;return t}var En=lr(Hs(),1);var Gs=Symbol.for("@achingbrain/uint8arraylist");function Ks(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 cr(r){return!!r?.[Gs]}var ur=class r{bufs;length;[Gs]=!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(cr(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(cr(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=Ks(this.bufs,e);return t.buf[t.index]}set(e,t){let n=Ks(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(cr(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 bn(n,o)}subarray(e,t){let{bufs:n,length:o}=this._subList(e,t);return n.length===1?n[0]:bn(n,o)}sublist(e,t){let{bufs:n,length:o}=this._subList(e,t),s=new r;return s.length=o,s.bufs=[...n],s}_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 s=0;s<this.bufs.length;s++){let i=this.bufs[s],c=o,f=c+i.byteLength;if(o=f,e>=f)continue;let p=e>=c&&e<f,d=t>c&&t<=f;if(p&&d){if(e===c&&t===f){n.push(i);break}let l=e-c;n.push(i.subarray(l,l+(t-e)));break}if(p){if(e===0){n.push(i);continue}n.push(i.subarray(e-c));continue}if(d){if(t===f){n.push(i);break}n.push(i.subarray(0,t-c));break}n.push(i)}return{bufs:n,length:t-e}}indexOf(e,t=0){if(!cr(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 s=256,i=new Int32Array(s);for(let l=0;l<s;l++)i[l]=-1;for(let l=0;l<o;l++)i[n[l]]=l;let c=i,f=this.byteLength-n.byteLength,p=n.byteLength-1,d;for(let l=t;l<=f;l+=d){d=0;for(let C=p;C>=0;C--){let a=this.get(l+C);if(n[C]!==a){d=Math.max(1,C-c[a]);break}}if(d===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=Ee(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=J(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=J(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=J(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=Ee(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=J(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=J(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=J(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=J(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=J(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(!Ae(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,s)=>o+s.byteLength,0)),n.length=t,n}};var Ic=Math.LN2*Math.LN2,He=class r{static create(e,t=.005){let n=Dc(e,t);return new r(n)}seeds;bits;buffer;constructor(e={}){e.seeds!=null?this.seeds=e.seeds:this.seeds=Uc(e.hashes??8),this.bits=e.bits??1024,this.buffer=J(Math.ceil(this.bits/8))}add(e){typeof e=="string"&&(e=ke(e));for(let t=0;t<this.seeds.length;t++){let o=En.default.x86.hash32(e,this.seeds[t])%this.bits;this.setbit(o)}}has(e){typeof e=="string"&&(e=ke(e));for(let t=0;t<this.seeds.length;t++){let o=En.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 Dc(r,e=.005){let t=Math.round(-1*r*Math.log(e)/Ic),n=Math.round(t/r*Math.LN2);return{bits:t,hashes:n}}function Uc(r){let e,t,n=[];for(let o=0;o<r;o++)for(e=new ur(ir(4)),n[o]=e.getUint32(0,!0),t=0;t<o;t++)if(n[o]===n[t]){o--;break}return n}var fr=class extends Ie{intialPeerSearchComplete;requests;name;log;logger;minProviders;maxProviders;providers;evictionFilter;constructor(e,t){super(),B(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=He.create(this.maxProviders)}async retrieve(e,t={}){let n=pe.encode(e.multihash.bytes),o=this.requests.get(n);if(o!=null)return this.log("join existing request for %c",e),o;let s=se();if(this.requests.set(n,s.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 i=!1,c=new ie({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=>{i=!0,s.resolve(p.detail.result)}),c.addEventListener("idle",()=>{i||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 d=this.providers[Math.floor(Math.random()*this.providers.length)];this.evict(d)}await this.findProviders(e,this.minProviders,t),this.log("found new providers re-retrieving %c",e),this.requests.delete(n),s.resolve(await this.retrieve(e,t))}).catch(p=>{this.log.error("could not find new providers for %c",e,p),s.reject(p)})});let f=p=>{c.add(async()=>this.queryProvider(e,p.detail,t),{provider:p.detail}).catch(d=>{t.signal?.aborted!==!0&&this.log.error("error retrieving session block for %c",e,d)})};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 s.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(),s=0;return Promise.resolve().then(async()=>{this.log("finding %d-%d new provider(s) for %c",t,this.maxProviders,e);for await(let i of this.findNewProviders(e,n)){if(s===this.maxProviders||n.signal?.aborted===!0)break;if(!this.hasProvider(i)&&(this.log("found %d/%d new providers",s,this.maxProviders),this.providers.push(i),this.safeDispatchEvent("provider",{detail:i}),s++,s===t&&(this.log("session is ready"),o.resolve()),this.providers.length===this.maxProviders)){this.log("found max session peers",s);break}}if(this.log("found %d/%d new session peers",s,this.maxProviders),s<t)throw new Ht(`Found ${s} of ${t} ${this.name} providers for ${e}`)}).catch(i=>{this.log.error("error searching routing for potential session peers for %c",e,i.errors??i),o.reject(i)}),o.promise}};var vn=class{blockstore;datastore;pins;logger;routing;dagWalkers;hashers;dns;metrics;log;constructor(e){this.logger=e.logger??Un(),this.log=this.logger.forComponent("helia"),this.hashers=Ms(e.hashers),this.dagWalkers=$s(e.dagWalkers),this.dns=e.dns??ao(),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 s=[o];return o[dr]!=null&&s.push(o[dr]),o[hr]!=null&&s.push(o[hr]),s}),providerLookupConcurrency:e.providerLookupConcurrency});let n=new sr(t);this.pins=new Wt(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 Os(this.datastore),await fe(this.blockstore,this.datastore,this.routing)}async stop(){await le(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 co(o.deleteMany(async function*(){for await(let{cid:s}of o.getAll())try{if(await n.pins.isPinned(s,e))continue;yield s,e.onProgress?.(new D("helia:gc:deleted",s))}catch(i){n.log.error("Error during gc",i),e.onProgress?.(new D("helia:gc:error",i))}}()))}finally{t()}this.log("gc finished")}};function Nc(r,e){return r.code===e}return ei($c);})();
|
|
3
3
|
/*! Bundled license information:
|
|
4
4
|
|
|
5
5
|
@noble/hashes/esm/utils.js:
|