@helia/car 5.3.2 → 5.3.3-4e19769a
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/index.min.js.map +4 -4
- package/dist/src/traversal-strategies/unixfs-path.d.ts.map +1 -1
- package/dist/src/traversal-strategies/unixfs-path.js +4 -3
- package/dist/src/traversal-strategies/unixfs-path.js.map +1 -1
- package/package.json +6 -6
- package/src/traversal-strategies/unixfs-path.ts +5 -3
- package/dist/typedoc-urls.json +0 -23
package/dist/index.min.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
(function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.HeliaCar = factory()}(typeof self !== 'undefined' ? self : this, function () {
|
|
2
|
-
"use strict";var HeliaCar=(()=>{var Fa=Object.create;var qt=Object.defineProperty;var Ra=Object.getOwnPropertyDescriptor;var za=Object.getOwnPropertyNames;var Ma=Object.getPrototypeOf,Oa=Object.prototype.hasOwnProperty;var ue=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),V=(t,e)=>{for(var r in e)qt(t,r,{get:e[r],enumerable:!0})},No=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of za(e))!Oa.call(t,o)&&o!==r&&qt(t,o,{get:()=>e[o],enumerable:!(n=Ra(e,o))||n.enumerable});return t};var Ee=(t,e,r)=>(r=t!=null?Fa(Ma(t)):{},No(e||!t||!t.__esModule?qt(r,"default",{value:t,enumerable:!0}):r,t)),$a=t=>No(qt({},"__esModule",{value:!0}),t);var Wi=ue((rd,ji)=>{ji.exports=pn;var Gi=128,fu=127,lu=~fu,hu=Math.pow(2,31);function pn(t,e,r){if(Number.MAX_SAFE_INTEGER&&t>Number.MAX_SAFE_INTEGER)throw pn.bytes=0,new RangeError("Could not encode varint");e=e||[],r=r||0;for(var n=r;t>=hu;)e[r++]=t&255|Gi,t/=128;for(;t&lu;)e[r++]=t&255|Gi,t>>>=7;return e[r]=t|0,pn.bytes=r-n+1,e}});var Xi=ue((nd,Ji)=>{Ji.exports=mn;var du=128,Qi=127;function mn(t,n){var r=0,n=n||0,o=0,i=n,s,a=t.length;do{if(i>=a||o>49)throw mn.bytes=0,new RangeError("Could not decode varint");s=t[i++],r+=o<28?(s&Qi)<<o:(s&Qi)*Math.pow(2,o),o+=7}while(s>=du);return mn.bytes=i-n,r}});var Ki=ue((od,Yi)=>{var pu=Math.pow(2,7),mu=Math.pow(2,14),yu=Math.pow(2,21),gu=Math.pow(2,28),wu=Math.pow(2,35),xu=Math.pow(2,42),bu=Math.pow(2,49),Eu=Math.pow(2,56),vu=Math.pow(2,63);Yi.exports=function(t){return t<pu?1:t<mu?2:t<yu?3:t<gu?4:t<wu?5:t<xu?6:t<bu?7:t<Eu?8:t<vu?9:10}});var ar=ue((id,Zi)=>{Zi.exports={encode:Wi(),decode:Xi(),encodingLength:Ki()}});var as=ue((dp,Tn)=>{"use strict";var Ou=Object.prototype.hasOwnProperty,$="~";function _t(){}Object.create&&(_t.prototype=Object.create(null),new _t().__proto__||($=!1));function $u(t,e,r){this.fn=t,this.context=e,this.once=r||!1}function ss(t,e,r,n,o){if(typeof r!="function")throw new TypeError("The listener must be a function");var i=new $u(r,n||t,o),s=$?$+e:e;return t._events[s]?t._events[s].fn?t._events[s]=[t._events[s],i]:t._events[s].push(i):(t._events[s]=i,t._eventsCount++),t}function hr(t,e){--t._eventsCount===0?t._events=new _t:delete t._events[e]}function z(){this._events=new _t,this._eventsCount=0}z.prototype.eventNames=function(){var e=[],r,n;if(this._eventsCount===0)return e;for(n in r=this._events)Ou.call(r,n)&&e.push($?n.slice(1):n);return Object.getOwnPropertySymbols?e.concat(Object.getOwnPropertySymbols(r)):e};z.prototype.listeners=function(e){var r=$?$+e:e,n=this._events[r];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};z.prototype.listenerCount=function(e){var r=$?$+e:e,n=this._events[r];return n?n.fn?1:n.length:0};z.prototype.emit=function(e,r,n,o,i,s){var a=$?$+e:e;if(!this._events[a])return!1;var c=this._events[a],l=arguments.length,p,d;if(c.fn){switch(c.once&&this.removeListener(e,c.fn,void 0,!0),l){case 1:return c.fn.call(c.context),!0;case 2:return c.fn.call(c.context,r),!0;case 3:return c.fn.call(c.context,r,n),!0;case 4:return c.fn.call(c.context,r,n,o),!0;case 5:return c.fn.call(c.context,r,n,o,i),!0;case 6:return c.fn.call(c.context,r,n,o,i,s),!0}for(d=1,p=new Array(l-1);d<l;d++)p[d-1]=arguments[d];c.fn.apply(c.context,p)}else{var k=c.length,u;for(d=0;d<k;d++)switch(c[d].once&&this.removeListener(e,c[d].fn,void 0,!0),l){case 1:c[d].fn.call(c[d].context);break;case 2:c[d].fn.call(c[d].context,r);break;case 3:c[d].fn.call(c[d].context,r,n);break;case 4:c[d].fn.call(c[d].context,r,n,o);break;default:if(!p)for(u=1,p=new Array(l-1);u<l;u++)p[u-1]=arguments[u];c[d].fn.apply(c[d].context,p)}}return!0};z.prototype.on=function(e,r,n){return ss(this,e,r,n,!1)};z.prototype.once=function(e,r,n){return ss(this,e,r,n,!0)};z.prototype.removeListener=function(e,r,n,o){var i=$?$+e:e;if(!this._events[i])return this;if(!r)return hr(this,i),this;var s=this._events[i];if(s.fn)s.fn===r&&(!o||s.once)&&(!n||s.context===n)&&hr(this,i);else{for(var a=0,c=[],l=s.length;a<l;a++)(s[a].fn!==r||o&&!s[a].once||n&&s[a].context!==n)&&c.push(s[a]);c.length?this._events[i]=c.length===1?c[0]:c:hr(this,i)}return this};z.prototype.removeAllListeners=function(e){var r;return e?(r=$?$+e:e,this._events[r]&&hr(this,r)):(this._events=new _t,this._eventsCount=0),this};z.prototype.off=z.prototype.removeListener;z.prototype.addListener=z.prototype.on;z.prefixed=$;z.EventEmitter=z;typeof Tn<"u"&&(Tn.exports=z)});var bs=ue((lm,xs)=>{xs.exports=function(t){if(!t)throw Error("hashlru must have a max value, of type number, greater than 0");var e=0,r=Object.create(null),n=Object.create(null);function o(i,s){r[i]=s,e++,e>=t&&(e=0,n=r,r=Object.create(null))}return{has:function(i){return r[i]!==void 0||n[i]!==void 0},remove:function(i){r[i]!==void 0&&(r[i]=void 0),n[i]!==void 0&&(n[i]=void 0)},get:function(i){var s=r[i];if(s!==void 0)return s;if((s=n[i])!==void 0)return o(i,s),s},set:function(i,s){r[i]!==void 0?r[i]=s:o(i,s)},clear:function(){r=Object.create(null),n=Object.create(null)}}}});var pa=ue((Ot,Fr)=>{(function(t,e){"use strict";var r={version:"3.0.0",x86:{},x64:{},inputValidation:!0};function n(u){if(!Array.isArray(u)&&!ArrayBuffer.isView(u))return!1;for(var h=0;h<u.length;h++)if(!Number.isInteger(u[h])||u[h]<0||u[h]>255)return!1;return!0}function o(u,h){return(u&65535)*h+(((u>>>16)*h&65535)<<16)}function i(u,h){return u<<h|u>>>32-h}function s(u){return u^=u>>>16,u=o(u,2246822507),u^=u>>>13,u=o(u,3266489909),u^=u>>>16,u}function a(u,h){u=[u[0]>>>16,u[0]&65535,u[1]>>>16,u[1]&65535],h=[h[0]>>>16,h[0]&65535,h[1]>>>16,h[1]&65535];var m=[0,0,0,0];return m[3]+=u[3]+h[3],m[2]+=m[3]>>>16,m[3]&=65535,m[2]+=u[2]+h[2],m[1]+=m[2]>>>16,m[2]&=65535,m[1]+=u[1]+h[1],m[0]+=m[1]>>>16,m[1]&=65535,m[0]+=u[0]+h[0],m[0]&=65535,[m[0]<<16|m[1],m[2]<<16|m[3]]}function c(u,h){u=[u[0]>>>16,u[0]&65535,u[1]>>>16,u[1]&65535],h=[h[0]>>>16,h[0]&65535,h[1]>>>16,h[1]&65535];var m=[0,0,0,0];return m[3]+=u[3]*h[3],m[2]+=m[3]>>>16,m[3]&=65535,m[2]+=u[2]*h[3],m[1]+=m[2]>>>16,m[2]&=65535,m[2]+=u[3]*h[2],m[1]+=m[2]>>>16,m[2]&=65535,m[1]+=u[1]*h[3],m[0]+=m[1]>>>16,m[1]&=65535,m[1]+=u[2]*h[2],m[0]+=m[1]>>>16,m[1]&=65535,m[1]+=u[3]*h[1],m[0]+=m[1]>>>16,m[1]&=65535,m[0]+=u[0]*h[3]+u[1]*h[2]+u[2]*h[1]+u[3]*h[0],m[0]&=65535,[m[0]<<16|m[1],m[2]<<16|m[3]]}function l(u,h){return h%=64,h===32?[u[1],u[0]]:h<32?[u[0]<<h|u[1]>>>32-h,u[1]<<h|u[0]>>>32-h]:(h-=32,[u[1]<<h|u[0]>>>32-h,u[0]<<h|u[1]>>>32-h])}function p(u,h){return h%=64,h===0?u:h<32?[u[0]<<h|u[1]>>>32-h,u[1]<<h]:[u[1]<<h-32,0]}function d(u,h){return[u[0]^h[0],u[1]^h[1]]}function k(u){return u=d(u,[0,u[0]>>>1]),u=c(u,[4283543511,3981806797]),u=d(u,[0,u[0]>>>1]),u=c(u,[3301882366,444984403]),u=d(u,[0,u[0]>>>1]),u}r.x86.hash32=function(u,h){if(r.inputValidation&&!n(u))return e;h=h||0;for(var m=u.length%4,I=u.length-m,g=h,w=0,b=3432918353,v=461845907,A=0;A<I;A=A+4)w=u[A]|u[A+1]<<8|u[A+2]<<16|u[A+3]<<24,w=o(w,b),w=i(w,15),w=o(w,v),g^=w,g=i(g,13),g=o(g,5)+3864292196;switch(w=0,m){case 3:w^=u[A+2]<<16;case 2:w^=u[A+1]<<8;case 1:w^=u[A],w=o(w,b),w=i(w,15),w=o(w,v),g^=w}return g^=u.length,g=s(g),g>>>0},r.x86.hash128=function(u,h){if(r.inputValidation&&!n(u))return e;h=h||0;for(var m=u.length%16,I=u.length-m,g=h,w=h,b=h,v=h,A=0,T=0,E=0,C=0,ce=597399067,$t=2869860233,Ht=951274213,Vt=2716044179,S=0;S<I;S=S+16)A=u[S]|u[S+1]<<8|u[S+2]<<16|u[S+3]<<24,T=u[S+4]|u[S+5]<<8|u[S+6]<<16|u[S+7]<<24,E=u[S+8]|u[S+9]<<8|u[S+10]<<16|u[S+11]<<24,C=u[S+12]|u[S+13]<<8|u[S+14]<<16|u[S+15]<<24,A=o(A,ce),A=i(A,15),A=o(A,$t),g^=A,g=i(g,19),g+=w,g=o(g,5)+1444728091,T=o(T,$t),T=i(T,16),T=o(T,Ht),w^=T,w=i(w,17),w+=b,w=o(w,5)+197830471,E=o(E,Ht),E=i(E,17),E=o(E,Vt),b^=E,b=i(b,15),b+=v,b=o(b,5)+2530024501,C=o(C,Vt),C=i(C,18),C=o(C,ce),v^=C,v=i(v,13),v+=g,v=o(v,5)+850148119;switch(A=0,T=0,E=0,C=0,m){case 15:C^=u[S+14]<<16;case 14:C^=u[S+13]<<8;case 13:C^=u[S+12],C=o(C,Vt),C=i(C,18),C=o(C,ce),v^=C;case 12:E^=u[S+11]<<24;case 11:E^=u[S+10]<<16;case 10:E^=u[S+9]<<8;case 9:E^=u[S+8],E=o(E,Ht),E=i(E,17),E=o(E,Vt),b^=E;case 8:T^=u[S+7]<<24;case 7:T^=u[S+6]<<16;case 6:T^=u[S+5]<<8;case 5:T^=u[S+4],T=o(T,$t),T=i(T,16),T=o(T,Ht),w^=T;case 4:A^=u[S+3]<<24;case 3:A^=u[S+2]<<16;case 2:A^=u[S+1]<<8;case 1:A^=u[S],A=o(A,ce),A=i(A,15),A=o(A,$t),g^=A}return g^=u.length,w^=u.length,b^=u.length,v^=u.length,g+=w,g+=b,g+=v,w+=g,b+=g,v+=g,g=s(g),w=s(w),b=s(b),v=s(v),g+=w,g+=b,g+=v,w+=g,b+=g,v+=g,("00000000"+(g>>>0).toString(16)).slice(-8)+("00000000"+(w>>>0).toString(16)).slice(-8)+("00000000"+(b>>>0).toString(16)).slice(-8)+("00000000"+(v>>>0).toString(16)).slice(-8)},r.x64.hash128=function(u,h){if(r.inputValidation&&!n(u))return e;h=h||0;for(var m=u.length%16,I=u.length-m,g=[0,h],w=[0,h],b=[0,0],v=[0,0],A=[2277735313,289559509],T=[1291169091,658871167],E=0;E<I;E=E+16)b=[u[E+4]|u[E+5]<<8|u[E+6]<<16|u[E+7]<<24,u[E]|u[E+1]<<8|u[E+2]<<16|u[E+3]<<24],v=[u[E+12]|u[E+13]<<8|u[E+14]<<16|u[E+15]<<24,u[E+8]|u[E+9]<<8|u[E+10]<<16|u[E+11]<<24],b=c(b,A),b=l(b,31),b=c(b,T),g=d(g,b),g=l(g,27),g=a(g,w),g=a(c(g,[0,5]),[0,1390208809]),v=c(v,T),v=l(v,33),v=c(v,A),w=d(w,v),w=l(w,31),w=a(w,g),w=a(c(w,[0,5]),[0,944331445]);switch(b=[0,0],v=[0,0],m){case 15:v=d(v,p([0,u[E+14]],48));case 14:v=d(v,p([0,u[E+13]],40));case 13:v=d(v,p([0,u[E+12]],32));case 12:v=d(v,p([0,u[E+11]],24));case 11:v=d(v,p([0,u[E+10]],16));case 10:v=d(v,p([0,u[E+9]],8));case 9:v=d(v,[0,u[E+8]]),v=c(v,T),v=l(v,33),v=c(v,A),w=d(w,v);case 8:b=d(b,p([0,u[E+7]],56));case 7:b=d(b,p([0,u[E+6]],48));case 6:b=d(b,p([0,u[E+5]],40));case 5:b=d(b,p([0,u[E+4]],32));case 4:b=d(b,p([0,u[E+3]],24));case 3:b=d(b,p([0,u[E+2]],16));case 2:b=d(b,p([0,u[E+1]],8));case 1:b=d(b,[0,u[E]]),b=c(b,A),b=l(b,31),b=c(b,T),g=d(g,b)}return g=d(g,[0,u.length]),w=d(w,[0,u.length]),g=a(g,w),w=a(w,g),g=k(g),w=k(w),g=a(g,w),w=a(w,g),("00000000"+(g[0]>>>0).toString(16)).slice(-8)+("00000000"+(g[1]>>>0).toString(16)).slice(-8)+("00000000"+(w[0]>>>0).toString(16)).slice(-8)+("00000000"+(w[1]>>>0).toString(16)).slice(-8)},typeof Ot<"u"?(typeof Fr<"u"&&Fr.exports&&(Ot=Fr.exports=r),Ot.murmurHash3=r):typeof define=="function"&&define.amd?define([],function(){return r}):(r._murmurHash3=t.murmurHash3,r.noConflict=function(){return t.murmurHash3=r._murmurHash3,r._murmurHash3=e,r.noConflict=e,r},t.murmurHash3=r)})(Ot)});var ya=ue((Yg,ma)=>{ma.exports=pa()});var ba=ue((ow,xa)=>{"use strict";xa.exports=class{constructor(){this._bitArrays=[],this._data=[],this._length=0,this._changedLength=!1,this._changedData=!1}set(e,r){let n=this._internalPositionFor(e,!1);if(r===void 0)n!==-1&&(this._unsetInternalPos(n),this._unsetBit(e),this._changedLength=!0,this._changedData=!0);else{let o=!1;n===-1?(n=this._data.length,this._setBit(e),this._changedData=!0):o=!0,this._setInternalPos(n,e,r,o),this._changedLength=!0}}unset(e){this.set(e,void 0)}get(e){this._sortData();let r=this._internalPositionFor(e,!0);if(r!==-1)return this._data[r][1]}push(e){return this.set(this.length,e),this.length}get length(){if(this._sortData(),this._changedLength){let e=this._data[this._data.length-1];this._length=e?e[0]+1:0,this._changedLength=!1}return this._length}forEach(e){let r=0;for(;r<this.length;)e(this.get(r),r,this),r++}map(e){let r=0,n=new Array(this.length);for(;r<this.length;)n[r]=e(this.get(r),r,this),r++;return n}reduce(e,r){let n=0,o=r;for(;n<this.length;){let i=this.get(n);o=e(o,i,n),n++}return o}find(e){let r=0,n,o;for(;r<this.length&&!n;)o=this.get(r),n=e(o),r++;return n?o:void 0}_internalPositionFor(e,r){let n=this._bytePosFor(e,r);if(n>=this._bitArrays.length)return-1;let o=this._bitArrays[n],i=e-n*7;if(!((o&1<<i)>0))return-1;let a=this._bitArrays.slice(0,n).reduce(ml,0),c=~(4294967295<<i+1),l=wa(o&c);return a+l-1}_bytePosFor(e,r){let n=Math.floor(e/7),o=n+1;for(;!r&&this._bitArrays.length<o;)this._bitArrays.push(0);return n}_setBit(e){let r=this._bytePosFor(e,!1);this._bitArrays[r]|=1<<e-r*7}_unsetBit(e){let r=this._bytePosFor(e,!1);this._bitArrays[r]&=~(1<<e-r*7)}_setInternalPos(e,r,n,o){let i=this._data,s=[r,n];if(o)this._sortData(),i[e]=s;else{if(i.length)if(i[i.length-1][0]>=r)i.push(s);else if(i[0][0]<=r)i.unshift(s);else{let a=Math.round(i.length/2);this._data=i.slice(0,a).concat(s).concat(i.slice(a))}else this._data.push(s);this._changedData=!0,this._changedLength=!0}}_unsetInternalPos(e){this._data.splice(e,1)}_sortData(){this._changedData&&this._data.sort(yl),this._changedData=!1}bitField(){let e=[],r=8,n=0,o=0,i,s=this._bitArrays.slice();for(;s.length||n;){n===0&&(i=s.shift(),n=7);let c=Math.min(n,r),l=~(255<<c),p=i&l;o|=p<<8-r,i=i>>>c,n-=c,r-=c,(!r||!n&&!s.length)&&(e.push(o),o=0,r=8)}for(var a=e.length-1;a>0&&e[a]===0;a--)e.pop();return e}compactArray(){return this._sortData(),this._data.map(gl)}};function ml(t,e){return t+wa(e)}function wa(t){let e=t;return e=e-(e>>1&1431655765),e=(e&858993459)+(e>>2&858993459),(e+(e>>4)&252645135)*16843009>>24}function yl(t,e){return t[0]-e[0]}function gl(t){return t[1]}});var zl={};V(zl,{BlockExporter:()=>Ao,CIDPath:()=>To,GraphSearch:()=>Io,SubgraphExporter:()=>Ft,UnixFSExporter:()=>Rt,UnixFSPath:()=>Bo,breadthFirstWalker:()=>Be,car:()=>Rl,depthFirstWalker:()=>Se,naturalOrderWalker:()=>_o});var Ha=["string","number","bigint","symbol"],Va=["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 Co(t){if(t===null)return"null";if(t===void 0)return"undefined";if(t===!0||t===!1)return"boolean";let e=typeof t;if(Ha.includes(e))return e;if(e==="function")return"Function";if(Array.isArray(t))return"Array";if(qa(t))return"Buffer";let r=Ga(t);return r||"Object"}function qa(t){return t&&t.constructor&&t.constructor.isBuffer&&t.constructor.isBuffer.call(null,t)}function Ga(t){let e=Object.prototype.toString.call(t).slice(8,-1);if(Va.includes(e))return e}var f=class{constructor(e,r,n){this.major=e,this.majorEncoded=e<<5,this.name=r,this.terminal=n}toString(){return`Type[${this.major}].${this.name}`}compare(e){return this.major<e.major?-1:this.major>e.major?1:0}};f.uint=new f(0,"uint",!0);f.negint=new f(1,"negint",!0);f.bytes=new f(2,"bytes",!0);f.string=new f(3,"string",!0);f.array=new f(4,"array",!1);f.map=new f(5,"map",!1);f.tag=new f(6,"tag",!1);f.float=new f(7,"float",!0);f.false=new f(7,"false",!0);f.true=new f(7,"true",!0);f.null=new f(7,"null",!0);f.undefined=new f(7,"undefined",!0);f.break=new f(7,"break",!0);var y=class{constructor(e,r,n){this.type=e,this.value=r,this.encodedLength=n,this.encodedBytes=void 0,this.byteValue=void 0}toString(){return`Token[${this.type}].${this.value}`}};var Pe=globalThis.process&&!globalThis.process.browser&&globalThis.Buffer&&typeof globalThis.Buffer.isBuffer=="function",ja=new TextDecoder,Wa=new TextEncoder;function Gt(t){return Pe&&globalThis.Buffer.isBuffer(t)}function at(t){return t instanceof Uint8Array?Gt(t)?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):t:Uint8Array.from(t)}var Uo=Pe?(t,e,r)=>r-e>64?globalThis.Buffer.from(t.subarray(e,r)).toString("utf8"):Lo(t,e,r):(t,e,r)=>r-e>64?ja.decode(t.subarray(e,r)):Lo(t,e,r),jt=Pe?t=>t.length>64?globalThis.Buffer.from(t):Do(t):t=>t.length>64?Wa.encode(t):Do(t),ne=t=>Uint8Array.from(t),Ue=Pe?(t,e,r)=>Gt(t)?new Uint8Array(t.subarray(e,r)):t.slice(e,r):(t,e,r)=>t.slice(e,r),Fo=Pe?(t,e)=>(t=t.map(r=>r instanceof Uint8Array?r:globalThis.Buffer.from(r)),at(globalThis.Buffer.concat(t,e))):(t,e)=>{let r=new Uint8Array(e),n=0;for(let o of t)n+o.length>r.length&&(o=o.subarray(0,r.length-n)),r.set(o,n),n+=o.length;return r},Ro=Pe?t=>globalThis.Buffer.allocUnsafe(t):t=>new Uint8Array(t);function Wt(t,e){if(Gt(t)&&Gt(e))return t.compare(e);for(let r=0;r<t.length;r++)if(t[r]!==e[r])return t[r]<e[r]?-1:1;return 0}function Do(t){let e=[],r=0;for(let n=0;n<t.length;n++){let o=t.charCodeAt(n);o<128?e[r++]=o:o<2048?(e[r++]=o>>6|192,e[r++]=o&63|128):(o&64512)===55296&&n+1<t.length&&(t.charCodeAt(n+1)&64512)===56320?(o=65536+((o&1023)<<10)+(t.charCodeAt(++n)&1023),e[r++]=o>>18|240,e[r++]=o>>12&63|128,e[r++]=o>>6&63|128,e[r++]=o&63|128):(e[r++]=o>>12|224,e[r++]=o>>6&63|128,e[r++]=o&63|128)}return e}function Lo(t,e,r){let n=[];for(;e<r;){let o=t[e],i=null,s=o>239?4:o>223?3:o>191?2:1;if(e+s<=r){let a,c,l,p;switch(s){case 1:o<128&&(i=o);break;case 2:a=t[e+1],(a&192)===128&&(p=(o&31)<<6|a&63,p>127&&(i=p));break;case 3:a=t[e+1],c=t[e+2],(a&192)===128&&(c&192)===128&&(p=(o&15)<<12|(a&63)<<6|c&63,p>2047&&(p<55296||p>57343)&&(i=p));break;case 4:a=t[e+1],c=t[e+2],l=t[e+3],(a&192)===128&&(c&192)===128&&(l&192)===128&&(p=(o&15)<<18|(a&63)<<12|(c&63)<<6|l&63,p>65535&&p<1114112&&(i=p))}}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 $r(n)}var Po=4096;function $r(t){let e=t.length;if(e<=Po)return String.fromCharCode.apply(String,t);let r="",n=0;for(;n<e;)r+=String.fromCharCode.apply(String,t.slice(n,n+=Po));return r}var Qa=256,ct=class{constructor(e=Qa){this.chunkSize=e,this.cursor=0,this.maxCursor=-1,this.chunks=[],this._initReuseChunk=null}reset(){this.cursor=0,this.maxCursor=-1,this.chunks.length&&(this.chunks=[]),this._initReuseChunk!==null&&(this.chunks.push(this._initReuseChunk),this.maxCursor=this._initReuseChunk.length-1)}push(e){let r=this.chunks[this.chunks.length-1];if(this.cursor+e.length<=this.maxCursor+1){let o=r.length-(this.maxCursor-this.cursor)-1;r.set(e,o)}else{if(r){let o=r.length-(this.maxCursor-this.cursor)-1;o<r.length&&(this.chunks[this.chunks.length-1]=r.subarray(0,o),this.maxCursor=this.cursor-1)}e.length<64&&e.length<this.chunkSize?(r=Ro(this.chunkSize),this.chunks.push(r),this.maxCursor+=r.length,this._initReuseChunk===null&&(this._initReuseChunk=r),r.set(e,0)):(this.chunks.push(e),this.maxCursor+=e.length)}this.cursor+=e.length}toBytes(e=!1){let r;if(this.chunks.length===1){let n=this.chunks[0];e&&this.cursor>n.length/2?(r=this.cursor===n.length?n:n.subarray(0,this.cursor),this._initReuseChunk=null,this.chunks=[]):r=Ue(n,0,this.cursor)}else r=Fo(this.chunks,this.cursor);return e&&this.reset(),r}};var _="CBOR decode error:",Fe="CBOR encode error:",ut=[];ut[23]=1;ut[24]=2;ut[25]=3;ut[26]=5;ut[27]=9;function fe(t,e,r){if(t.length-e<r)throw new Error(`${_} not enough data for type`)}var U=[24,256,65536,4294967296,BigInt("18446744073709551616")];function G(t,e,r){fe(t,e,1);let n=t[e];if(r.strict===!0&&n<U[0])throw new Error(`${_} integer encoded in more bytes than necessary (strict decode)`);return n}function j(t,e,r){fe(t,e,2);let n=t[e]<<8|t[e+1];if(r.strict===!0&&n<U[1])throw new Error(`${_} integer encoded in more bytes than necessary (strict decode)`);return n}function W(t,e,r){fe(t,e,4);let n=t[e]*16777216+(t[e+1]<<16)+(t[e+2]<<8)+t[e+3];if(r.strict===!0&&n<U[2])throw new Error(`${_} integer encoded in more bytes than necessary (strict decode)`);return n}function Q(t,e,r){fe(t,e,8);let n=t[e]*16777216+(t[e+1]<<16)+(t[e+2]<<8)+t[e+3],o=t[e+4]*16777216+(t[e+5]<<16)+(t[e+6]<<8)+t[e+7],i=(BigInt(n)<<BigInt(32))+BigInt(o);if(r.strict===!0&&i<U[3])throw new Error(`${_} integer encoded in more bytes than necessary (strict decode)`);if(i<=Number.MAX_SAFE_INTEGER)return Number(i);if(r.allowBigInt===!0)return i;throw new Error(`${_} integers outside of the safe integer range are not supported`)}function zo(t,e,r,n){return new y(f.uint,G(t,e+1,n),2)}function Mo(t,e,r,n){return new y(f.uint,j(t,e+1,n),3)}function Oo(t,e,r,n){return new y(f.uint,W(t,e+1,n),5)}function $o(t,e,r,n){return new y(f.uint,Q(t,e+1,n),9)}function X(t,e){return R(t,0,e.value)}function R(t,e,r){if(r<U[0]){let n=Number(r);t.push([e|n])}else if(r<U[1]){let n=Number(r);t.push([e|24,n])}else if(r<U[2]){let n=Number(r);t.push([e|25,n>>>8,n&255])}else if(r<U[3]){let n=Number(r);t.push([e|26,n>>>24&255,n>>>16&255,n>>>8&255,n&255])}else{let n=BigInt(r);if(n<U[4]){let o=[e|27,0,0,0,0,0,0,0],i=Number(n&BigInt(4294967295)),s=Number(n>>BigInt(32)&BigInt(4294967295));o[8]=i&255,i=i>>8,o[7]=i&255,i=i>>8,o[6]=i&255,i=i>>8,o[5]=i&255,o[4]=s&255,s=s>>8,o[3]=s&255,s=s>>8,o[2]=s&255,s=s>>8,o[1]=s&255,t.push(o)}else throw new Error(`${_} encountered BigInt larger than allowable range`)}}X.encodedSize=function(e){return R.encodedSize(e.value)};R.encodedSize=function(e){return e<U[0]?1:e<U[1]?2:e<U[2]?3:e<U[3]?5:9};X.compareTokens=function(e,r){return e.value<r.value?-1:e.value>r.value?1:0};function Ho(t,e,r,n){return new y(f.negint,-1-G(t,e+1,n),2)}function Vo(t,e,r,n){return new y(f.negint,-1-j(t,e+1,n),3)}function qo(t,e,r,n){return new y(f.negint,-1-W(t,e+1,n),5)}var Hr=BigInt(-1),Go=BigInt(1);function jo(t,e,r,n){let o=Q(t,e+1,n);if(typeof o!="bigint"){let i=-1-o;if(i>=Number.MIN_SAFE_INTEGER)return new y(f.negint,i,9)}if(n.allowBigInt!==!0)throw new Error(`${_} integers outside of the safe integer range are not supported`);return new y(f.negint,Hr-BigInt(o),9)}function Qt(t,e){let r=e.value,n=typeof r=="bigint"?r*Hr-Go:r*-1-1;R(t,e.type.majorEncoded,n)}Qt.encodedSize=function(e){let r=e.value,n=typeof r=="bigint"?r*Hr-Go:r*-1-1;return n<U[0]?1:n<U[1]?2:n<U[2]?3:n<U[3]?5:9};Qt.compareTokens=function(e,r){return e.value<r.value?1:e.value>r.value?-1:0};function ft(t,e,r,n){fe(t,e,r+n);let o=Ue(t,e+r,e+r+n);return new y(f.bytes,o,r+n)}function Wo(t,e,r,n){return ft(t,e,1,r)}function Qo(t,e,r,n){return ft(t,e,2,G(t,e+1,n))}function Jo(t,e,r,n){return ft(t,e,3,j(t,e+1,n))}function Xo(t,e,r,n){return ft(t,e,5,W(t,e+1,n))}function Yo(t,e,r,n){let o=Q(t,e+1,n);if(typeof o=="bigint")throw new Error(`${_} 64-bit integer bytes lengths not supported`);return ft(t,e,9,o)}function Jt(t){return t.encodedBytes===void 0&&(t.encodedBytes=t.type===f.string?jt(t.value):t.value),t.encodedBytes}function Re(t,e){let r=Jt(e);R(t,e.type.majorEncoded,r.length),t.push(r)}Re.encodedSize=function(e){let r=Jt(e);return R.encodedSize(r.length)+r.length};Re.compareTokens=function(e,r){return Xa(Jt(e),Jt(r))};function Xa(t,e){return t.length<e.length?-1:t.length>e.length?1:Wt(t,e)}function lt(t,e,r,n,o){let i=r+n;fe(t,e,i);let s=new y(f.string,Uo(t,e+r,e+i),i);return o.retainStringBytes===!0&&(s.byteValue=Ue(t,e+r,e+i)),s}function Ko(t,e,r,n){return lt(t,e,1,r,n)}function Zo(t,e,r,n){return lt(t,e,2,G(t,e+1,n),n)}function ei(t,e,r,n){return lt(t,e,3,j(t,e+1,n),n)}function ti(t,e,r,n){return lt(t,e,5,W(t,e+1,n),n)}function ri(t,e,r,n){let o=Q(t,e+1,n);if(typeof o=="bigint")throw new Error(`${_} 64-bit integer string lengths not supported`);return lt(t,e,9,o,n)}var ni=Re;function ze(t,e,r,n){return new y(f.array,n,r)}function oi(t,e,r,n){return ze(t,e,1,r)}function ii(t,e,r,n){return ze(t,e,2,G(t,e+1,n))}function si(t,e,r,n){return ze(t,e,3,j(t,e+1,n))}function ai(t,e,r,n){return ze(t,e,5,W(t,e+1,n))}function ci(t,e,r,n){let o=Q(t,e+1,n);if(typeof o=="bigint")throw new Error(`${_} 64-bit integer array lengths not supported`);return ze(t,e,9,o)}function ui(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${_} indefinite length items not allowed`);return ze(t,e,1,1/0)}function Xt(t,e){R(t,f.array.majorEncoded,e.value)}Xt.compareTokens=X.compareTokens;Xt.encodedSize=function(e){return R.encodedSize(e.value)};function Me(t,e,r,n){return new y(f.map,n,r)}function fi(t,e,r,n){return Me(t,e,1,r)}function li(t,e,r,n){return Me(t,e,2,G(t,e+1,n))}function hi(t,e,r,n){return Me(t,e,3,j(t,e+1,n))}function di(t,e,r,n){return Me(t,e,5,W(t,e+1,n))}function pi(t,e,r,n){let o=Q(t,e+1,n);if(typeof o=="bigint")throw new Error(`${_} 64-bit integer map lengths not supported`);return Me(t,e,9,o)}function mi(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${_} indefinite length items not allowed`);return Me(t,e,1,1/0)}function Yt(t,e){R(t,f.map.majorEncoded,e.value)}Yt.compareTokens=X.compareTokens;Yt.encodedSize=function(e){return R.encodedSize(e.value)};function yi(t,e,r,n){return new y(f.tag,r,1)}function gi(t,e,r,n){return new y(f.tag,G(t,e+1,n),2)}function wi(t,e,r,n){return new y(f.tag,j(t,e+1,n),3)}function xi(t,e,r,n){return new y(f.tag,W(t,e+1,n),5)}function bi(t,e,r,n){return new y(f.tag,Q(t,e+1,n),9)}function Kt(t,e){R(t,f.tag.majorEncoded,e.value)}Kt.compareTokens=X.compareTokens;Kt.encodedSize=function(e){return R.encodedSize(e.value)};var rc=20,nc=21,oc=22,ic=23;function Ei(t,e,r,n){if(n.allowUndefined===!1)throw new Error(`${_} undefined values are not supported`);return n.coerceUndefinedToNull===!0?new y(f.null,null,1):new y(f.undefined,void 0,1)}function vi(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${_} indefinite length items not allowed`);return new y(f.break,void 0,1)}function Vr(t,e,r){if(r){if(r.allowNaN===!1&&Number.isNaN(t))throw new Error(`${_} NaN values are not supported`);if(r.allowInfinity===!1&&(t===1/0||t===-1/0))throw new Error(`${_} Infinity values are not supported`)}return new y(f.float,t,e)}function ki(t,e,r,n){return Vr(qr(t,e+1),3,n)}function _i(t,e,r,n){return Vr(Gr(t,e+1),5,n)}function Ai(t,e,r,n){return Vr(Bi(t,e+1),9,n)}function Zt(t,e,r){let n=e.value;if(n===!1)t.push([f.float.majorEncoded|rc]);else if(n===!0)t.push([f.float.majorEncoded|nc]);else if(n===null)t.push([f.float.majorEncoded|oc]);else if(n===void 0)t.push([f.float.majorEncoded|ic]);else{let o,i=!1;(!r||r.float64!==!0)&&(Ti(n),o=qr(K,1),n===o||Number.isNaN(n)?(K[0]=249,t.push(K.slice(0,3)),i=!0):(Si(n),o=Gr(K,1),n===o&&(K[0]=250,t.push(K.slice(0,5)),i=!0))),i||(sc(n),o=Bi(K,1),K[0]=251,t.push(K.slice(0,9)))}}Zt.encodedSize=function(e,r){let n=e.value;if(n===!1||n===!0||n===null||n===void 0)return 1;if(!r||r.float64!==!0){Ti(n);let o=qr(K,1);if(n===o||Number.isNaN(n))return 3;if(Si(n),o=Gr(K,1),n===o)return 5}return 9};var Ii=new ArrayBuffer(9),Y=new DataView(Ii,1),K=new Uint8Array(Ii,0);function Ti(t){if(t===1/0)Y.setUint16(0,31744,!1);else if(t===-1/0)Y.setUint16(0,64512,!1);else if(Number.isNaN(t))Y.setUint16(0,32256,!1);else{Y.setFloat32(0,t);let e=Y.getUint32(0),r=(e&2139095040)>>23,n=e&8388607;if(r===255)Y.setUint16(0,31744,!1);else if(r===0)Y.setUint16(0,(t&2147483648)>>16|n>>13,!1);else{let o=r-127;o<-24?Y.setUint16(0,0):o<-14?Y.setUint16(0,(e&2147483648)>>16|1<<24+o,!1):Y.setUint16(0,(e&2147483648)>>16|o+15<<10|n>>13,!1)}}}function qr(t,e){if(t.length-e<2)throw new Error(`${_} not enough data for float16`);let r=(t[e]<<8)+t[e+1];if(r===31744)return 1/0;if(r===64512)return-1/0;if(r===32256)return NaN;let n=r>>10&31,o=r&1023,i;return n===0?i=o*2**-24:n!==31?i=(o+1024)*2**(n-25):i=o===0?1/0:NaN,r&32768?-i:i}function Si(t){Y.setFloat32(0,t,!1)}function Gr(t,e){if(t.length-e<4)throw new Error(`${_} not enough data for float32`);let r=(t.byteOffset||0)+e;return new DataView(t.buffer,r,4).getFloat32(0,!1)}function sc(t){Y.setFloat64(0,t,!1)}function Bi(t,e){if(t.length-e<8)throw new Error(`${_} not enough data for float64`);let r=(t.byteOffset||0)+e;return new DataView(t.buffer,r,8).getFloat64(0,!1)}Zt.compareTokens=X.compareTokens;function B(t,e,r){throw new Error(`${_} encountered invalid minor (${r}) for major ${t[e]>>>5}`)}function er(t){return()=>{throw new Error(`${_} ${t}`)}}var x=[];for(let t=0;t<=23;t++)x[t]=B;x[24]=zo;x[25]=Mo;x[26]=Oo;x[27]=$o;x[28]=B;x[29]=B;x[30]=B;x[31]=B;for(let t=32;t<=55;t++)x[t]=B;x[56]=Ho;x[57]=Vo;x[58]=qo;x[59]=jo;x[60]=B;x[61]=B;x[62]=B;x[63]=B;for(let t=64;t<=87;t++)x[t]=Wo;x[88]=Qo;x[89]=Jo;x[90]=Xo;x[91]=Yo;x[92]=B;x[93]=B;x[94]=B;x[95]=er("indefinite length bytes/strings are not supported");for(let t=96;t<=119;t++)x[t]=Ko;x[120]=Zo;x[121]=ei;x[122]=ti;x[123]=ri;x[124]=B;x[125]=B;x[126]=B;x[127]=er("indefinite length bytes/strings are not supported");for(let t=128;t<=151;t++)x[t]=oi;x[152]=ii;x[153]=si;x[154]=ai;x[155]=ci;x[156]=B;x[157]=B;x[158]=B;x[159]=ui;for(let t=160;t<=183;t++)x[t]=fi;x[184]=li;x[185]=hi;x[186]=di;x[187]=pi;x[188]=B;x[189]=B;x[190]=B;x[191]=mi;for(let t=192;t<=215;t++)x[t]=yi;x[216]=gi;x[217]=wi;x[218]=xi;x[219]=bi;x[220]=B;x[221]=B;x[222]=B;x[223]=B;for(let t=224;t<=243;t++)x[t]=er("simple values are not supported");x[244]=B;x[245]=B;x[246]=B;x[247]=Ei;x[248]=er("simple values are not supported");x[249]=ki;x[250]=_i;x[251]=Ai;x[252]=B;x[253]=B;x[254]=B;x[255]=vi;var Z=[];for(let t=0;t<24;t++)Z[t]=new y(f.uint,t,1);for(let t=-1;t>=-24;t--)Z[31-t]=new y(f.negint,t,1);Z[64]=new y(f.bytes,new Uint8Array(0),1);Z[96]=new y(f.string,"",1);Z[128]=new y(f.array,0,1);Z[160]=new y(f.map,0,1);Z[244]=new y(f.false,!1,1);Z[245]=new y(f.true,!0,1);Z[246]=new y(f.null,null,1);function tr(t){switch(t.type){case f.false:return ne([244]);case f.true:return ne([245]);case f.null:return ne([246]);case f.bytes:return t.value.length?void 0:ne([64]);case f.string:return t.value===""?ne([96]):void 0;case f.array:return t.value===0?ne([128]):void 0;case f.map:return t.value===0?ne([160]):void 0;case f.uint:return t.value<24?ne([Number(t.value)]):void 0;case f.negint:if(t.value>=-24)return ne([31-Number(t.value)])}}var cc={float64:!1,mapSorter:fc,quickEncodeToken:tr},Ci=Object.freeze({float64:!0,mapSorter:lc,quickEncodeToken:tr});function Wr(){let t=[];return t[f.uint.major]=X,t[f.negint.major]=Qt,t[f.bytes.major]=Re,t[f.string.major]=ni,t[f.array.major]=Xt,t[f.map.major]=Yt,t[f.tag.major]=Kt,t[f.float.major]=Zt,t}var Qr=Wr(),jr=new ct,rr=class t{constructor(e,r){this.obj=e,this.parent=r}includes(e){let r=this;do if(r.obj===e)return!0;while(r=r.parent);return!1}static createCheck(e,r){if(e&&e.includes(r))throw new Error(`${Fe} object contains circular references`);return new t(r,e)}},he={null:new y(f.null,null),undefined:new y(f.undefined,void 0),true:new y(f.true,!0),false:new y(f.false,!1),emptyArray:new y(f.array,0),emptyMap:new y(f.map,0)},de={number(t,e,r,n){return!Number.isInteger(t)||!Number.isSafeInteger(t)?new y(f.float,t):t>=0?new y(f.uint,t):new y(f.negint,t)},bigint(t,e,r,n){return t>=BigInt(0)?new y(f.uint,t):new y(f.negint,t)},Uint8Array(t,e,r,n){return new y(f.bytes,t)},string(t,e,r,n){return new y(f.string,t)},boolean(t,e,r,n){return t?he.true:he.false},null(t,e,r,n){return he.null},undefined(t,e,r,n){return he.undefined},ArrayBuffer(t,e,r,n){return new y(f.bytes,new Uint8Array(t))},DataView(t,e,r,n){return new y(f.bytes,new Uint8Array(t.buffer,t.byteOffset,t.byteLength))},Array(t,e,r,n){if(!t.length)return r.addBreakTokens===!0?[he.emptyArray,new y(f.break)]:he.emptyArray;n=rr.createCheck(n,t);let o=[],i=0;for(let s of t)o[i++]=ht(s,r,n);return r.addBreakTokens?[new y(f.array,t.length),o,new y(f.break)]:[new y(f.array,t.length),o]},Object(t,e,r,n){let o=e!=="Object",i=o?t.keys():Object.keys(t),s=o?t.size:i.length;if(!s)return r.addBreakTokens===!0?[he.emptyMap,new y(f.break)]:he.emptyMap;n=rr.createCheck(n,t);let a=[],c=0;for(let l of i)a[c++]=[ht(l,r,n),ht(o?t.get(l):t[l],r,n)];return uc(a,r),r.addBreakTokens?[new y(f.map,s),a,new y(f.break)]:[new y(f.map,s),a]}};de.Map=de.Object;de.Buffer=de.Uint8Array;for(let t of"Uint8Clamped Uint16 Uint32 Int8 Int16 Int32 BigUint64 BigInt64 Float32 Float64".split(" "))de[`${t}Array`]=de.DataView;function ht(t,e={},r){let n=Co(t),o=e&&e.typeEncoders&&e.typeEncoders[n]||de[n];if(typeof o=="function"){let s=o(t,n,e,r);if(s!=null)return s}let i=de[n];if(!i)throw new Error(`${Fe} unsupported type: ${n}`);return i(t,n,e,r)}function uc(t,e){e.mapSorter&&t.sort(e.mapSorter)}function fc(t,e){let r=Array.isArray(t[0])?t[0][0]:t[0],n=Array.isArray(e[0])?e[0][0]:e[0];if(r.type!==n.type)return r.type.compare(n.type);let o=r.type.major,i=Qr[o].compareTokens(r,n);return i===0&&console.warn("WARNING: complex key types used, CBOR key sorting guarantees are gone"),i}function lc(t,e){if(t[0]instanceof y&&e[0]instanceof y){let r=t[0],n=e[0];return r._keyBytes||(r._keyBytes=Ni(r.value)),n._keyBytes||(n._keyBytes=Ni(n.value)),Wt(r._keyBytes,n._keyBytes)}throw new Error("rfc8949MapSorter: complex key types are not supported yet")}function Ni(t){return Jr(t,Qr,Ci)}function Di(t,e,r,n){if(Array.isArray(e))for(let o of e)Di(t,o,r,n);else r[e.type.major](t,e,n)}function Jr(t,e,r){let n=ht(t,r);if(!Array.isArray(n)&&r.quickEncodeToken){let o=r.quickEncodeToken(n);if(o)return o;let i=e[n.type.major];if(i.encodedSize){let s=i.encodedSize(n,r),a=new ct(s);if(i(a,n,r),a.chunks.length!==1)throw new Error(`Unexpected error: pre-calculated length for ${n} was wrong`);return at(a.chunks[0])}}return jr.reset(),Di(jr,n,e,r),jr.toBytes(!0)}function Xr(t,e){return e=Object.assign({},cc,e),Jr(t,Qr,e)}var hc={strict:!1,allowIndefinite:!0,allowUndefined:!0,allowBigInt:!0},nr=class{constructor(e,r={}){this._pos=0,this.data=e,this.options=r}pos(){return this._pos}done(){return this._pos>=this.data.length}next(){let e=this.data[this._pos],r=Z[e];if(r===void 0){let n=x[e];if(!n)throw new Error(`${_} no decoder for major type ${e>>>5} (byte 0x${e.toString(16).padStart(2,"0")})`);let o=e&31;r=n(this.data,this._pos,o,this.options)}return this._pos+=r.encodedLength,r}},dt=Symbol.for("DONE"),or=Symbol.for("BREAK");function dc(t,e,r){let n=[];for(let o=0;o<t.value;o++){let i=Oe(e,r);if(i===or){if(t.value===1/0)break;throw new Error(`${_} got unexpected break to lengthed array`)}if(i===dt)throw new Error(`${_} found array but not enough entries (got ${o}, expected ${t.value})`);n[o]=i}return n}function pc(t,e,r){let n=r.useMaps===!0,o=n?void 0:{},i=n?new Map:void 0;for(let s=0;s<t.value;s++){let a=Oe(e,r);if(a===or){if(t.value===1/0)break;throw new Error(`${_} got unexpected break to lengthed map`)}if(a===dt)throw new Error(`${_} found map but not enough entries (got ${s} [no key], expected ${t.value})`);if(n!==!0&&typeof a!="string")throw new Error(`${_} non-string keys not supported (got ${typeof a})`);if(r.rejectDuplicateMapKeys===!0&&(n&&i.has(a)||!n&&a in o))throw new Error(`${_} found repeat map key "${a}"`);let c=Oe(e,r);if(c===dt)throw new Error(`${_} found map but not enough entries (got ${s} [no value], expected ${t.value})`);n?i.set(a,c):o[a]=c}return n?i:o}function Oe(t,e){if(t.done())return dt;let r=t.next();if(r.type===f.break)return or;if(r.type.terminal)return r.value;if(r.type===f.array)return dc(r,t,e);if(r.type===f.map)return pc(r,t,e);if(r.type===f.tag){if(e.tags&&typeof e.tags[r.value]=="function"){let n=Oe(t,e);return e.tags[r.value](n)}throw new Error(`${_} tag not supported (${r.value})`)}throw new Error("unsupported")}function Yr(t,e){if(!(t instanceof Uint8Array))throw new Error(`${_} data to decode must be a Uint8Array`);e=Object.assign({},hc,e);let r=e.tokenizer||new nr(t,e),n=Oe(r,e);if(n===dt)throw new Error(`${_} did not find any content to decode`);if(n===or)throw new Error(`${_} got unexpected break`);return[n,t.subarray(r.pos())]}function pt(t,e){let[r,n]=Yr(t,e);if(n.length>0)throw new Error(`${_} too many terminals, data makes no sense`);return r}var sn={};V(sn,{base32:()=>He,base32hex:()=>Sc,base32hexpad:()=>Nc,base32hexpadupper:()=>Cc,base32hexupper:()=>Bc,base32pad:()=>Ic,base32padupper:()=>Tc,base32upper:()=>Ac,base32z:()=>Dc});var ke={};V(ke,{coerce:()=>oe,empty:()=>Li,equals:()=>Kr,fromHex:()=>gc,fromString:()=>Zr,isBinary:()=>wc,toHex:()=>yc,toString:()=>en});var Li=new Uint8Array(0);function yc(t){return t.reduce((e,r)=>e+r.toString(16).padStart(2,"0"),"")}function gc(t){let e=t.match(/../g);return e!=null?new Uint8Array(e.map(r=>parseInt(r,16))):Li}function Kr(t,e){if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;for(let r=0;r<t.byteLength;r++)if(t[r]!==e[r])return!1;return!0}function oe(t){if(t instanceof Uint8Array&&t.constructor.name==="Uint8Array")return t;if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.isView(t))return new Uint8Array(t.buffer,t.byteOffset,t.byteLength);throw new Error("Unknown type, must be binary type")}function wc(t){return t instanceof ArrayBuffer||ArrayBuffer.isView(t)}function Zr(t){return new TextEncoder().encode(t)}function en(t){return new TextDecoder().decode(t)}function xc(t,e){if(t.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),n=0;n<r.length;n++)r[n]=255;for(var o=0;o<t.length;o++){var i=t.charAt(o),s=i.charCodeAt(0);if(r[s]!==255)throw new TypeError(i+" is ambiguous");r[s]=o}var a=t.length,c=t.charAt(0),l=Math.log(a)/Math.log(256),p=Math.log(256)/Math.log(a);function d(h){if(h instanceof Uint8Array||(ArrayBuffer.isView(h)?h=new Uint8Array(h.buffer,h.byteOffset,h.byteLength):Array.isArray(h)&&(h=Uint8Array.from(h))),!(h instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(h.length===0)return"";for(var m=0,I=0,g=0,w=h.length;g!==w&&h[g]===0;)g++,m++;for(var b=(w-g)*p+1>>>0,v=new Uint8Array(b);g!==w;){for(var A=h[g],T=0,E=b-1;(A!==0||T<I)&&E!==-1;E--,T++)A+=256*v[E]>>>0,v[E]=A%a>>>0,A=A/a>>>0;if(A!==0)throw new Error("Non-zero carry");I=T,g++}for(var C=b-I;C!==b&&v[C]===0;)C++;for(var ce=c.repeat(m);C<b;++C)ce+=t.charAt(v[C]);return ce}function k(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 I=0,g=0;h[m]===c;)I++,m++;for(var w=(h.length-m)*l+1>>>0,b=new Uint8Array(w);h[m];){var v=r[h.charCodeAt(m)];if(v===255)return;for(var A=0,T=w-1;(v!==0||A<g)&&T!==-1;T--,A++)v+=a*b[T]>>>0,b[T]=v%256>>>0,v=v/256>>>0;if(v!==0)throw new Error("Non-zero carry");g=A,m++}if(h[m]!==" "){for(var E=w-g;E!==w&&b[E]===0;)E++;for(var C=new Uint8Array(I+(w-E)),ce=I;E!==w;)C[ce++]=b[E++];return C}}}function u(h){var m=k(h);if(m)return m;throw new Error(`Non-${e} character`)}return{encode:d,decodeUnsafe:k,decode:u}}var bc=xc,Ec=bc,Pi=Ec;var tn=class{name;prefix;baseEncode;constructor(e,r,n){this.name=e,this.prefix=r,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},rn=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,r,n){this.name=e,this.prefix=r;let o=r.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 Ui(this,e)}},nn=class{decoders;constructor(e){this.decoders=e}or(e){return Ui(this,e)}decode(e){let r=e[0],n=this.decoders[r];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 Ui(t,e){return new nn({...t.decoders??{[t.prefix]:t},...e.decoders??{[e.prefix]:e}})}var on=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,r,n,o){this.name=e,this.prefix=r,this.baseEncode=n,this.baseDecode=o,this.encoder=new tn(e,r,n),this.decoder=new rn(e,r,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function $e({name:t,prefix:e,encode:r,decode:n}){return new on(t,e,r,n)}function pe({name:t,prefix:e,alphabet:r}){let{encode:n,decode:o}=Pi(r,t);return $e({prefix:e,name:t,encode:n,decode:i=>oe(o(i))})}function vc(t,e,r,n){let o=t.length;for(;t[o-1]==="=";)--o;let i=new Uint8Array(o*r/8|0),s=0,a=0,c=0;for(let l=0;l<o;++l){let p=e[t[l]];if(p===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|p,s+=r,s>=8&&(s-=8,i[c++]=255&a>>s)}if(s>=r||(255&a<<8-s)!==0)throw new SyntaxError("Unexpected end of data");return i}function kc(t,e,r){let n=e[e.length-1]==="=",o=(1<<r)-1,i="",s=0,a=0;for(let c=0;c<t.length;++c)for(a=a<<8|t[c],s+=8;s>r;)s-=r,i+=e[o&a>>s];if(s!==0&&(i+=e[o&a<<r-s]),n)for(;(i.length*r&7)!==0;)i+="=";return i}function _c(t){let e={};for(let r=0;r<t.length;++r)e[t[r]]=r;return e}function L({name:t,prefix:e,bitsPerChar:r,alphabet:n}){let o=_c(n);return $e({prefix:e,name:t,encode(i){return kc(i,n,r)},decode(i){return vc(i,o,r,t)}})}var He=L({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Ac=L({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Ic=L({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Tc=L({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Sc=L({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Bc=L({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Nc=L({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Cc=L({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Dc=L({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var an={};V(an,{base36:()=>mt,base36upper:()=>Lc});var mt=pe({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Lc=pe({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var cn={};V(cn,{base58btc:()=>ie,base58flickr:()=>Pc});var ie=pe({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Pc=pe({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Uc=zi,Fi=128,Fc=127,Rc=~Fc,zc=Math.pow(2,31);function zi(t,e,r){e=e||[],r=r||0;for(var n=r;t>=zc;)e[r++]=t&255|Fi,t/=128;for(;t&Rc;)e[r++]=t&255|Fi,t>>>=7;return e[r]=t|0,zi.bytes=r-n+1,e}var Mc=un,Oc=128,Ri=127;function un(t,n){var r=0,n=n||0,o=0,i=n,s,a=t.length;do{if(i>=a)throw un.bytes=0,new RangeError("Could not decode varint");s=t[i++],r+=o<28?(s&Ri)<<o:(s&Ri)*Math.pow(2,o),o+=7}while(s>=Oc);return un.bytes=i-n,r}var $c=Math.pow(2,7),Hc=Math.pow(2,14),Vc=Math.pow(2,21),qc=Math.pow(2,28),Gc=Math.pow(2,35),jc=Math.pow(2,42),Wc=Math.pow(2,49),Qc=Math.pow(2,56),Jc=Math.pow(2,63),Xc=function(t){return t<$c?1:t<Hc?2:t<Vc?3:t<qc?4:t<Gc?5:t<jc?6:t<Wc?7:t<Qc?8:t<Jc?9:10},Yc={encode:Uc,decode:Mc,encodingLength:Xc},Kc=Yc,yt=Kc;function gt(t,e=0){return[yt.decode(t,e),yt.decode.bytes]}function Ve(t,e,r=0){return yt.encode(t,e,r),e}function qe(t){return yt.encodingLength(t)}function je(t,e){let r=e.byteLength,n=qe(t),o=n+qe(r),i=new Uint8Array(o+r);return Ve(t,i,0),Ve(r,i,n),i.set(e,o),new Ge(t,r,e,i)}function We(t){let e=oe(t),[r,n]=gt(e),[o,i]=gt(e.subarray(n)),s=e.subarray(n+i);if(s.byteLength!==o)throw new Error("Incorrect length");return new Ge(r,o,s,e)}function Mi(t,e){if(t===e)return!0;{let r=e;return t.code===r.code&&t.size===r.size&&r.bytes instanceof Uint8Array&&Kr(t.bytes,r.bytes)}}var Ge=class{code;size;digest;bytes;constructor(e,r,n,o){this.code=e,this.size=r,this.digest=n,this.bytes=o}};function Oi(t,e){let{bytes:r,version:n}=t;switch(n){case 0:return eu(r,fn(t),e??ie.encoder);default:return tu(r,fn(t),e??He.encoder)}}var $i=new WeakMap;function fn(t){let e=$i.get(t);if(e==null){let r=new Map;return $i.set(t,r),r}return e}var N=class t{code;version;multihash;bytes;"/";constructor(e,r,n,o){this.code=r,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:r}=this;if(e!==wt)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==ru)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return t.createV0(r)}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:r}=this.multihash,n=je(e,r);return t.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 t.equals(this,e)}static equals(e,r){let n=r;return n!=null&&e.code===n.code&&e.version===n.version&&Mi(e.multihash,n.multihash)}toString(e){return Oi(this,e)}toJSON(){return{"/":Oi(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 r=e;if(r instanceof t)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:o,multihash:i,bytes:s}=r;return new t(n,o,i,s??Hi(n,o,i.bytes))}else if(r[nu]===!0){let{version:n,multihash:o,code:i}=r,s=We(o);return t.create(n,i,s)}else return null}static create(e,r,n){if(typeof r!="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(r!==wt)throw new Error(`Version 0 CID must use dag-pb (code: ${wt}) block encoding`);return new t(e,r,n,n.bytes)}case 1:{let o=Hi(e,r,n.bytes);return new t(e,r,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return t.create(0,wt,e)}static createV1(e,r){return t.create(1,e,r)}static decode(e){let[r,n]=t.decodeFirst(e);if(n.length!==0)throw new Error("Incorrect length");return r}static decodeFirst(e){let r=t.inspectBytes(e),n=r.size-r.multihashSize,o=oe(e.subarray(n,n+r.multihashSize));if(o.byteLength!==r.multihashSize)throw new Error("Incorrect length");let i=o.subarray(r.multihashSize-r.digestSize),s=new Ge(r.multihashCode,r.digestSize,i,o);return[r.version===0?t.createV0(s):t.createV1(r.codec,s),e.subarray(r.size)]}static inspectBytes(e){let r=0,n=()=>{let[d,k]=gt(e.subarray(r));return r+=k,d},o=n(),i=wt;if(o===18?(o=0,r=0):i=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let s=r,a=n(),c=n(),l=r+c,p=l-s;return{version:o,codec:i,multihashCode:a,digestSize:c,multihashSize:p,size:l}}static parse(e,r){let[n,o]=Zc(e,r),i=t.decode(o);if(i.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return fn(i).set(n,e),i}};function Zc(t,e){switch(t[0]){case"Q":{let r=e??ie;return[ie.prefix,r.decode(`${ie.prefix}${t}`)]}case ie.prefix:{let r=e??ie;return[ie.prefix,r.decode(t)]}case He.prefix:{let r=e??He;return[He.prefix,r.decode(t)]}case mt.prefix:{let r=e??mt;return[mt.prefix,r.decode(t)]}default:{if(e==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[t[0],e.decode(t)]}}}function eu(t,e,r){let{prefix:n}=r;if(n!==ie.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let o=e.get(n);if(o==null){let i=r.encode(t).slice(1);return e.set(n,i),i}else return o}function tu(t,e,r){let{prefix:n}=r,o=e.get(n);if(o==null){let i=r.encode(t);return e.set(n,i),i}else return o}var wt=112,ru=18;function Hi(t,e,r){let n=qe(t),o=n+qe(e),i=new Uint8Array(o+r.byteLength);return Ve(t,i,0),Ve(e,i,n),i.set(r,o),i}var nu=Symbol.for("@ipld/js-cid/CID");var Vi=42;function ou(t){return t instanceof ArrayBuffer?new Uint8Array(t,0,t.byteLength):t}function iu(t){if(t.asCID!==t&&t["/"]!==t.bytes)return null;let e=N.asCID(t);if(!e)return null;let r=new Uint8Array(e.bytes.byteLength+1);return r.set(e.bytes,1),[new y(f.tag,Vi),new y(f.bytes,r)]}function su(){throw new Error("`undefined` is not supported by the IPLD Data Model and cannot be encoded")}function au(t){if(Number.isNaN(t))throw new Error("`NaN` is not supported by the IPLD Data Model and cannot be encoded");if(t===1/0||t===-1/0)throw new Error("`Infinity` and `-Infinity` is not supported by the IPLD Data Model and cannot be encoded");return null}function cu(t){for(let e of t.keys())if(typeof e!="string"||e.length===0)throw new Error("Non-string Map keys are not supported by the IPLD Data Model and cannot be encoded");return null}var ln={float64:!0,typeEncoders:{Map:cu,Object:iu,undefined:su,number:au}},ed={...ln,typeEncoders:{...ln.typeEncoders}};function uu(t){if(t[0]!==0)throw new Error("Invalid CID for CBOR tag 42; expected leading 0x00");return N.decode(t.subarray(1))}var sr={allowIndefinite:!1,coerceUndefinedToNull:!0,allowNaN:!1,allowInfinity:!1,allowBigInt:!0,strict:!0,useMaps:!1,rejectDuplicateMapKeys:!0,tags:[]};sr.tags[Vi]=uu;var td={...sr,tags:sr.tags.slice()};var qi=113,hn=t=>Xr(t,ln),xt=t=>pt(ou(t),sr);var yn=Ee(ar(),1);var gn=40;function wn(t,e){if(!t.length)throw new Error("Unexpected end of data");let r=yn.default.decode(t);return e.seek(yn.default.decode.bytes),r}function xn(t){let e=new DataView(t.buffer,t.byteOffset,t.byteLength),r=0;return{version:2,characteristics:[e.getBigUint64(r,!0),e.getBigUint64(r+=8,!0)],dataOffset:Number(e.getBigUint64(r+=8,!0)),dataSize:Number(e.getBigUint64(r+=8,!0)),indexOffset:Number(e.getBigUint64(r+=8,!0))}}var ye={Null:t=>t===null?t:void 0,Int:t=>Number.isInteger(t)?t:void 0,Float:t=>typeof t=="number"&&Number.isFinite(t)?t:void 0,String:t=>typeof t=="string"?t:void 0,Bool:t=>typeof t=="boolean"?t:void 0,Bytes:t=>t instanceof Uint8Array?t:void 0,Link:t=>t!==null&&typeof t=="object"&&t.asCID===t?t:void 0,List:t=>Array.isArray(t)?t:void 0,Map:t=>t!==null&&typeof t=="object"&&t.asCID!==t&&!Array.isArray(t)&&!(t instanceof Uint8Array)?t:void 0},bt={"CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)":ye.Link,"CarV1HeaderOrV2Pragma > roots (anon)":t=>{if(ye.List(t)!==void 0){for(let e=0;e<t.length;e++){let r=t[e];if(r=bt["CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)"](r),r===void 0)return;if(r!==t[e]){let n=t.slice(0,e);for(let o=e;o<t.length;o++){let i=t[o];if(i=bt["CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)"](i),i===void 0)return;n.push(i)}return n}}return t}},Int:ye.Int,CarV1HeaderOrV2Pragma:t=>{if(ye.Map(t)===void 0)return;let e=Object.entries(t),r=t,n=1;for(let o=0;o<e.length;o++){let[i,s]=e[o];switch(i){case"roots":{let a=bt["CarV1HeaderOrV2Pragma > roots (anon)"](t[i]);if(a===void 0)return;if(a!==s||r!==t){if(r===t){r={};for(let c=0;c<o;c++)r[e[c][0]]=e[c][1]}r.roots=a}}break;case"version":{n--;let a=bt.Int(t[i]);if(a===void 0)return;if(a!==s||r!==t){if(r===t){r={};for(let c=0;c<o;c++)r[e[c][0]]=e[c][1]}r.version=a}}break;default:return}}if(!(n>0))return r}},Et={"CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)":ye.Link,"CarV1HeaderOrV2Pragma > roots (anon)":t=>{if(ye.List(t)!==void 0){for(let e=0;e<t.length;e++){let r=t[e];if(r=Et["CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)"](r),r===void 0)return;if(r!==t[e]){let n=t.slice(0,e);for(let o=e;o<t.length;o++){let i=t[o];if(i=Et["CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)"](i),i===void 0)return;n.push(i)}return n}}return t}},Int:ye.Int,CarV1HeaderOrV2Pragma:t=>{if(ye.Map(t)===void 0)return;let e=Object.entries(t),r=t,n=1;for(let o=0;o<e.length;o++){let[i,s]=e[o];switch(i){case"roots":{let a=Et["CarV1HeaderOrV2Pragma > roots (anon)"](s);if(a===void 0)return;if(a!==s||r!==t){if(r===t){r={};for(let c=0;c<o;c++)r[e[c][0]]=e[c][1]}r.roots=a}}break;case"version":{n--;let a=Et.Int(s);if(a===void 0)return;if(a!==s||r!==t){if(r===t){r={};for(let c=0;c<o;c++)r[e[c][0]]=e[c][1]}r.version=a}}break;default:return}}if(!(n>0))return r}},bn={toTyped:bt.CarV1HeaderOrV2Pragma,toRepresentation:Et.CarV1HeaderOrV2Pragma};var yd=Wr();var Iu=Ee(ar(),1);var Ed=[new y(f.map,2),new y(f.string,"version"),new y(f.uint,1),new y(f.string,"roots")],vd=new y(f.tag,42);async function En(t,e){let r=wn(await t.upTo(8),t);if(r===0)throw new Error("Invalid CAR header (zero length)");let n=await t.exactly(r,!0),o=xt(n);if(bn.toTyped(o)===void 0)throw new Error("Invalid CAR header format");if(o.version!==1&&o.version!==2||e!==void 0&&o.version!==e)throw new Error(`Invalid CAR version: ${o.version}${e!==void 0?` (expected ${e})`:""}`);if(o.version===1){if(!Array.isArray(o.roots))throw new Error("Invalid CAR header format");return o}if(o.roots!==void 0)throw new Error("Invalid CAR header format");let i=xn(await t.exactly(gn,!0));t.seek(i.dataOffset-t.pos);let s=await En(t,1);return Object.assign(s,i)}function vt(t){let e=0;return{async upTo(r){return t.subarray(e,e+Math.min(r,t.length-e))},async exactly(r,n=!1){if(r>t.length-e)throw new Error("Unexpected end of data");let o=t.subarray(e,e+r);return n&&(e+=r),o},seek(r){e+=r},get pos(){return e}}}var vn=Ee(ar(),1),rs=1;function kn(t){let e=hn({version:rs,roots:t}),r=vn.default.encode(e.length),n=new Uint8Array(r.length+e.length);return n.set(r,0),n.set(e,r.length),n}function ns(t){return{async setRoots(e){let r=kn(e);await t.write(r)},async writeBlock(e){let{cid:r,bytes:n}=e;await t.write(new Uint8Array(vn.default.encode(r.bytes.length+n.length))),await t.write(r.bytes),n.length&&await t.write(n)},async close(){await t.end()},version(){return rs}}}function cr(){}function os(){let t=[],e=null,r=cr,n=!1,o=null,i=cr,s=()=>(e||(e=new Promise(l=>{r=()=>{e=null,r=cr,l()}})),e),a={write(l){t.push(l);let p=s();return i(),p},async end(){n=!0;let l=s();i(),await l}},c={async next(){let l=t.shift();return l?(t.length===0&&r(),{done:!1,value:l}):n?(r(),{done:!0,value:void 0}):(o||(o=new Promise(p=>{i=()=>(o=null,i=cr,p(c.next()))})),o)}};return{writer:a,iterator:c}}var kt=class t{constructor(e,r){this._encoder=r,this._mutex=r.setRoots(e),this._ended=!1}async put(e){if(!(e.bytes instanceof Uint8Array)||!e.cid)throw new TypeError("Can only write {cid, bytes} objects");if(this._ended)throw new Error("Already closed");let r=N.asCID(e.cid);if(!r)throw new TypeError("Can only write {cid, bytes} objects");return this._mutex=this._mutex.then(()=>this._encoder.writeBlock({cid:r,bytes:e.bytes})),this._mutex}async close(){if(this._ended)throw new Error("Already closed");return await this._mutex,this._ended=!0,this._encoder.close()}version(){return this._encoder.version()}static create(e){e=Nu(e);let{encoder:r,iterator:n}=is(),o=new t(e,r),i=new ur(n);return{writer:o,out:i}}static createAppender(){let{encoder:e,iterator:r}=is();e.setRoots=()=>Promise.resolve();let n=new t([],e),o=new ur(r);return{writer:n,out:o}}static async updateRootsInBytes(e,r){let n=vt(e);await En(n);let o=kn(r);if(Number(n.pos)!==o.length)throw new Error(`updateRoots() can only overwrite a header of the same length (old header is ${n.pos} bytes, new header is ${o.length} bytes)`);return e.set(o,0),e}},ur=class{constructor(e){this._iterator=e}[Symbol.asyncIterator](){if(this._iterating)throw new Error("Multiple iterator not supported");return this._iterating=!0,this._iterator}};function is(){let t=os(),{writer:e,iterator:r}=t;return{encoder:ns(e),iterator:r}}function Nu(t){if(t===void 0)return[];if(!Array.isArray(t)){let r=N.asCID(t);if(!r)throw new TypeError("roots must be a single CID or an array of CIDs");return[r]}let e=[];for(let r of t){let n=N.asCID(r);if(!n)throw new TypeError("roots must be a single CID or an array of CIDs");e.push(n)}return e}function Cu(t){return t[Symbol.asyncIterator]!=null}function Du(t){if(Cu(t))return(async()=>{for await(let e of t);})();for(let e of t);}var _n=Du;function Lu(t){let[e,r]=t[Symbol.asyncIterator]!=null?[t[Symbol.asyncIterator](),Symbol.asyncIterator]:[t[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(),[r](){return this}}}var fr=Lu;function Pu(t){return t[Symbol.asyncIterator]!=null}function Uu(t,e){let r=0;if(Pu(t))return(async function*(){for await(let c of t)yield e(c,r++)})();let n=fr(t),{value:o,done:i}=n.next();if(i===!0)return(function*(){})();let s=e(o,r++);if(typeof s.then=="function")return(async function*(){yield await s;for(let c of n)yield e(c,r++)})();let a=e;return(function*(){yield s;for(let c of n)yield a(c,r++)})()}var ge=Uu;function Fu(t){return t.reason}async function Qe(t,e,r){if(e==null)return t;let n=r?.translateError??Fu;if(e.aborted)return t.catch(()=>{}),Promise.reject(n(e));let o;try{return await Promise.race([t,new Promise((i,s)=>{o=()=>{s(n(e))},e.addEventListener("abort",o)})])}finally{o!=null&&e.removeEventListener("abort",o)}}var le=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 lr=class extends EventTarget{#e=new Map;constructor(){super()}listenerCount(e){let r=this.#e.get(e);return r==null?0:r.length}addEventListener(e,r,n){super.addEventListener(e,r,n);let o=this.#e.get(e);o==null&&(o=[],this.#e.set(e,o)),o.push({callback:r,once:(n!==!0&&n!==!1&&n?.once)??!1})}removeEventListener(e,r,n){super.removeEventListener(e.toString(),r??null,n);let o=this.#e.get(e);o!=null&&(o=o.filter(({callback:i})=>i!==r),this.#e.set(e,o))}dispatchEvent(e){let r=super.dispatchEvent(e),n=this.#e.get(e.type);return n==null||(n=n.filter(({once:o})=>!o),this.#e.set(e.type,n)),r}safeDispatchEvent(e,r={}){return this.dispatchEvent(new CustomEvent(e,r))}};var In={};V(In,{base64:()=>An,base64pad:()=>Ru,base64url:()=>zu,base64urlpad:()=>Mu});var An=L({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Ru=L({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),zu=L({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Mu=L({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var F=class extends Event{type;detail;constructor(e,r){super(e),this.type=e,this.detail=r}};var Sn=Ee(as(),1);var Bn=class t extends Error{name="TimeoutError";constructor(e,r){super(e,r),Error.captureStackTrace?.(this,t)}},cs=t=>t.reason??new DOMException("This operation was aborted.","AbortError");function Nn(t,e){let{milliseconds:r,fallback:n,message:o,customTimers:i={setTimeout,clearTimeout},signal:s}=e,a,c,p=new Promise((d,k)=>{if(typeof r!="number"||Math.sign(r)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${r}\``);if(s?.aborted){k(cs(s));return}if(s&&(c=()=>{k(cs(s))},s.addEventListener("abort",c,{once:!0})),t.then(d,k),r===Number.POSITIVE_INFINITY)return;let u=new Bn;a=i.setTimeout.call(void 0,()=>{if(n){try{d(n())}catch(h){k(h)}return}typeof t.cancel=="function"&&t.cancel(),o===!1?d():o instanceof Error?k(o):(u.message=o??`Promise timed out after ${r} milliseconds`,k(u))},r)}).finally(()=>{p.clear(),c&&s&&s.removeEventListener("abort",c)});return p.clear=()=>{i.clearTimeout.call(void 0,a),a=void 0},p}function Cn(t,e,r){let n=0,o=t.length;for(;o>0;){let i=Math.trunc(o/2),s=n+i;r(t[s],e)<=0?(n=++s,o-=i+1):o=i}return n}var At=class{#e=[];enqueue(e,r){let{priority:n=0,id:o}=r??{},i={priority:n,id:o,run:e};if(this.size===0||this.#e[this.size-1].priority>=n){this.#e.push(i);return}let s=Cn(this.#e,i,(a,c)=>c.priority-a.priority);this.#e.splice(s,0,i)}setPriority(e,r){let n=this.#e.findIndex(i=>i.id===e);if(n===-1)throw new ReferenceError(`No promise function with the id "${e}" exists in the queue.`);let[o]=this.#e.splice(n,1);this.enqueue(o.run,{priority:r,id:e})}dequeue(){return this.#e.shift()?.run}filter(e){return this.#e.filter(r=>r.priority===e.priority).map(r=>r.run)}get size(){return this.#e.length}};var It=class extends Sn.default{#e;#n;#o=0;#d;#p=!1;#m=!1;#u;#x=0;#y=0;#i;#s;#t;#b;#r=0;#f;#a;#I=1n;#l=new Map;timeout;constructor(e){if(super(),e={carryoverIntervalCount:!1,intervalCap:Number.POSITIVE_INFINITY,interval:0,concurrency:Number.POSITIVE_INFINITY,autoStart:!0,queueClass:At,...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})`);if(this.#e=e.carryoverIntervalCount??e.carryoverConcurrencyCount??!1,this.#n=e.intervalCap===Number.POSITIVE_INFINITY||e.interval===0,this.#d=e.intervalCap,this.#u=e.interval,this.#t=new e.queueClass,this.#b=e.queueClass,this.concurrency=e.concurrency,e.timeout!==void 0&&!(Number.isFinite(e.timeout)&&e.timeout>0))throw new TypeError(`Expected \`timeout\` to be a positive finite number, got \`${e.timeout}\` (${typeof e.timeout})`);this.timeout=e.timeout,this.#a=e.autoStart===!1,this.#L()}get#T(){return this.#n||this.#o<this.#d}get#S(){return this.#r<this.#f}#B(){this.#r--,this.#r===0&&this.emit("pendingZero"),this.#g(),this.emit("next")}#N(){this.#_(),this.#k(),this.#s=void 0}get#C(){let e=Date.now();if(this.#i===void 0){let r=this.#x-e;if(r<0){if(this.#y>0){let n=e-this.#y;if(n<this.#u)return this.#E(this.#u-n),!0}this.#o=this.#e?this.#r:0}else return this.#E(r),!0}return!1}#E(e){this.#s===void 0&&(this.#s=setTimeout(()=>{this.#N()},e))}#v(){this.#i&&(clearInterval(this.#i),this.#i=void 0)}#D(){this.#s&&(clearTimeout(this.#s),this.#s=void 0)}#g(){if(this.#t.size===0)return this.#v(),this.emit("empty"),this.#r===0&&(this.#D(),this.emit("idle")),!1;let e=!1;if(!this.#a){let r=!this.#C;if(this.#T&&this.#S){let n=this.#t.dequeue();this.#n||(this.#o++,this.#h()),this.emit("active"),this.#y=Date.now(),n(),r&&this.#k(),e=!0}}return e}#k(){this.#n||this.#i!==void 0||(this.#i=setInterval(()=>{this.#_()},this.#u),this.#x=Date.now()+this.#u)}#_(){this.#o===0&&this.#r===0&&this.#i&&this.#v(),this.#o=this.#e?this.#r:0,this.#w(),this.#h()}#w(){for(;this.#g(););}get concurrency(){return this.#f}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.#f=e,this.#w()}setPriority(e,r){if(typeof r!="number"||!Number.isFinite(r))throw new TypeError(`Expected \`priority\` to be a finite number, got \`${r}\` (${typeof r})`);this.#t.setPriority(e,r)}async add(e,r={}){return r.id??=(this.#I++).toString(),r={timeout:this.timeout,...r},new Promise((n,o)=>{let i=Symbol(`task-${r.id}`);this.#t.enqueue(async()=>{this.#r++,this.#l.set(i,{id:r.id,priority:r.priority??0,startTime:Date.now(),timeout:r.timeout});let s;try{try{r.signal?.throwIfAborted()}catch(l){throw this.#n||this.#o--,this.#l.delete(i),l}let a=e({signal:r.signal});if(r.timeout&&(a=Nn(Promise.resolve(a),{milliseconds:r.timeout,message:`Task timed out after ${r.timeout}ms (queue has ${this.#r} running, ${this.#t.size} waiting)`})),r.signal){let{signal:l}=r;a=Promise.race([a,new Promise((p,d)=>{s=()=>{d(l.reason)},l.addEventListener("abort",s,{once:!0})})])}let c=await a;n(c),this.emit("completed",c)}catch(a){o(a),this.emit("error",a)}finally{s&&r.signal?.removeEventListener("abort",s),this.#l.delete(i),queueMicrotask(()=>{this.#B()})}},r),this.emit("add"),this.#g()})}async addAll(e,r){return Promise.all(e.map(async n=>this.add(n,r)))}start(){return this.#a?(this.#a=!1,this.#w(),this):this}pause(){this.#a=!0}clear(){this.#t=new this.#b,this.#A()}async onEmpty(){this.#t.size!==0&&await this.#c("empty")}async onSizeLessThan(e){this.#t.size<e||await this.#c("next",()=>this.#t.size<e)}async onIdle(){this.#r===0&&this.#t.size===0||await this.#c("idle")}async onPendingZero(){this.#r!==0&&await this.#c("pendingZero")}async onRateLimit(){this.isRateLimited||await this.#c("rateLimit")}async onRateLimitCleared(){this.isRateLimited&&await this.#c("rateLimitCleared")}async onError(){return new Promise((e,r)=>{let n=o=>{this.off("error",n),r(o)};this.on("error",n)})}async#c(e,r){return new Promise(n=>{let o=()=>{r&&!r()||(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.#r}get isPaused(){return this.#a}#L(){this.#n||(this.on("add",()=>{this.#t.size>0&&this.#h()}),this.on("next",()=>{this.#h()}))}#h(){this.#n||this.#m||(this.#m=!0,queueMicrotask(()=>{this.#m=!1,this.#A()}))}#A(){let e=this.#p,r=!this.#n&&this.#o>=this.#d&&this.#t.size>0;r!==e&&(this.#p=r,this.emit(r?"rateLimit":"rateLimitCleared"))}get isRateLimited(){return this.#p}get isSaturated(){return this.#r===this.#f&&this.#t.size>0||this.isRateLimited&&this.#t.size>0}get runningTasks(){return[...this.#l.values()].map(e=>({...e}))}};var Dn={};V(Dn,{base10:()=>Hu});var Hu=pe({prefix:"9",name:"base10",alphabet:"0123456789"});var Ln={};V(Ln,{base16:()=>Vu,base16upper:()=>qu});var Vu=L({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),qu=L({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Pn={};V(Pn,{base2:()=>Gu});var Gu=L({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Un={};V(Un,{base256emoji:()=>Xu});var us=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}"),ju=us.reduce((t,e,r)=>(t[r]=e,t),[]),Wu=us.reduce((t,e,r)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return t[n]=r,t},[]);function Qu(t){return t.reduce((e,r)=>(e+=ju[r],e),"")}function Ju(t){let e=[];for(let r of t){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=Wu[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);e.push(o)}return new Uint8Array(e)}var Xu=$e({prefix:"\u{1F680}",name:"base256emoji",encode:Qu,decode:Ju});var Fn={};V(Fn,{base8:()=>Yu});var Yu=L({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Rn={};V(Rn,{identity:()=>Ku});var Ku=$e({prefix:"\0",name:"identity",encode:t=>en(t),decode:t=>Zr(t)});var Dp=new TextEncoder,Zu=new TextDecoder;var fs=512;function ls(t){return JSON.parse(Zu.decode(t))}var dr=85;var $n={};V($n,{identity:()=>On});var hs=0,ef="identity",ds=oe;function tf(t,e){if(e?.truncate!=null&&e.truncate!==t.byteLength){if(e.truncate<0||e.truncate>t.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${t.byteLength}`);t=t.subarray(0,e.truncate)}return je(hs,ds(t))}var On={code:hs,name:ef,encode:ds,digest:tf};var Vn={};V(Vn,{sha256:()=>nf,sha512:()=>of});var rf=20;function Ae({name:t,code:e,encode:r,minDigestLength:n,maxDigestLength:o}){return new Hn(t,e,r,n,o)}var Hn=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,r,n,o,i){this.name=e,this.code=r,this.encode=n,this.minDigestLength=o??rf,this.maxDigestLength=i}digest(e,r){if(r?.truncate!=null){if(r.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&r.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(e instanceof Uint8Array){let n=this.encode(e);return n instanceof Uint8Array?ps(n,this.code,r?.truncate):n.then(o=>ps(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function ps(t,e,r){if(r!=null&&r!==t.byteLength){if(r>t.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${t.byteLength}`);t=t.subarray(0,r)}return je(e,t)}function ys(t){return async e=>new Uint8Array(await crypto.subtle.digest(t,e))}var nf=Ae({name:"sha2-256",code:18,encode:ys("SHA-256")}),of=Ae({name:"sha2-512",code:19,encode:ys("SHA-512")});var qn={...Rn,...Pn,...Fn,...Dn,...Ln,...sn,...an,...cn,...In,...Un},Gp={...Vn,...$n};function se(t=0){return new Uint8Array(t)}function ws(t,e,r,n){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:r},decoder:{decode:n}}}var gs=ws("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),Gn=ws("ascii","a",t=>{let e="a";for(let r=0;r<t.length;r++)e+=String.fromCharCode(t[r]);return e},t=>{t=t.substring(1);let e=se(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}),sf={utf8:gs,"utf-8":gs,hex:qn.base16,latin1:Gn,ascii:Gn,binary:Gn,...qn},jn=sf;var uf=Ee(bs(),1);var Je;(function(t){t[t.A=1]="A",t[t.CNAME=5]="CNAME",t[t.TXT=16]="TXT",t[t.AAAA=28]="AAAA"})(Je||(Je={}));function Tt(t,e){e==null&&(e=t.reduce((o,i)=>o+i.length,0));let r=se(e),n=0;for(let o of t)r.set(o,n),n+=o.length;return r}function pr(t,e="utf8"){let r=jn[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.decoder.decode(`${r.prefix}${t}`)}var ff=Math.pow(2,7),lf=Math.pow(2,14),hf=Math.pow(2,21),Es=Math.pow(2,28),vs=Math.pow(2,35),ks=Math.pow(2,42),_s=Math.pow(2,49),H=128,we=127;function St(t){if(t<ff)return 1;if(t<lf)return 2;if(t<hf)return 3;if(t<Es)return 4;if(t<vs)return 5;if(t<ks)return 6;if(t<_s)return 7;if(Number.MAX_SAFE_INTEGER!=null&&t>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function As(t,e,r=0){switch(St(t)){case 8:e[r++]=t&255|H,t/=128;case 7:e[r++]=t&255|H,t/=128;case 6:e[r++]=t&255|H,t/=128;case 5:e[r++]=t&255|H,t/=128;case 4:e[r++]=t&255|H,t>>>=7;case 3:e[r++]=t&255|H,t>>>=7;case 2:e[r++]=t&255|H,t>>>=7;case 1:{e[r++]=t&255,t>>>=7;break}default:throw new Error("unreachable")}return e}function Is(t,e){let r=t[e],n=0;if(n+=r&we,r<H||(r=t[e+1],n+=(r&we)<<7,r<H)||(r=t[e+2],n+=(r&we)<<14,r<H)||(r=t[e+3],n+=(r&we)<<21,r<H)||(r=t[e+4],n+=(r&we)*Es,r<H)||(r=t[e+5],n+=(r&we)*vs,r<H)||(r=t[e+6],n+=(r&we)*ks,r<H)||(r=t[e+7],n+=(r&we)*_s,r<H))return n;throw new RangeError("Could not decode varint")}var Wn=new Float32Array([-0]),xe=new Uint8Array(Wn.buffer);function Ts(t,e,r){Wn[0]=t,e[r]=xe[0],e[r+1]=xe[1],e[r+2]=xe[2],e[r+3]=xe[3]}function Ss(t,e){return xe[0]=t[e],xe[1]=t[e+1],xe[2]=t[e+2],xe[3]=t[e+3],Wn[0]}var Qn=new Float64Array([-0]),M=new Uint8Array(Qn.buffer);function Bs(t,e,r){Qn[0]=t,e[r]=M[0],e[r+1]=M[1],e[r+2]=M[2],e[r+3]=M[3],e[r+4]=M[4],e[r+5]=M[5],e[r+6]=M[6],e[r+7]=M[7]}function Ns(t,e){return M[0]=t[e],M[1]=t[e+1],M[2]=t[e+2],M[3]=t[e+3],M[4]=t[e+4],M[5]=t[e+5],M[6]=t[e+6],M[7]=t[e+7],Qn[0]}var df=BigInt(Number.MAX_SAFE_INTEGER),pf=BigInt(Number.MIN_SAFE_INTEGER),J=class t{lo;hi;constructor(e,r){this.lo=e|0,this.hi=r|0}toNumber(e=!1){if(!e&&this.hi>>>31>0){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(r+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(e=!1){if(e)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(BigInt(r)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(e=!1){return this.toBigInt(e).toString()}zzEncode(){let e=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^e)>>>0,this.lo=(this.lo<<1^e)>>>0,this}zzDecode(){let e=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^e)>>>0,this.hi=(this.hi>>>1^e)>>>0,this}length(){let e=this.lo,r=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?r===0?e<16384?e<128?1:2:e<2097152?3:4:r<16384?r<128?5:6:r<2097152?7:8:n<128?9:10}static fromBigInt(e){if(e===0n)return Ie;if(e<df&&e>pf)return this.fromNumber(Number(e));let r=e<0n;r&&(e=-e);let n=e>>32n,o=e-(n<<32n);return r&&(n=~n|0n,o=~o|0n,++o>Cs&&(o=0n,++n>Cs&&(n=0n))),new t(Number(o),Number(n))}static fromNumber(e){if(e===0)return Ie;let r=e<0;r&&(e=-e);let n=e>>>0,o=(e-n)/4294967296>>>0;return r&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new t(n,o)}static from(e){return typeof e=="number"?t.fromNumber(e):typeof e=="bigint"?t.fromBigInt(e):typeof e=="string"?t.fromBigInt(BigInt(e)):e.low!=null||e.high!=null?new t(e.low>>>0,e.high>>>0):Ie}},Ie=new J(0,0);Ie.toBigInt=function(){return 0n};Ie.zzEncode=Ie.zzDecode=function(){return this};Ie.length=function(){return 1};var Cs=4294967296n;function Ds(t){let e=0,r=0;for(let n=0;n<t.length;++n)r=t.charCodeAt(n),r<128?e+=1:r<2048?e+=2:(r&64512)===55296&&(t.charCodeAt(n+1)&64512)===56320?(++n,e+=4):e+=3;return e}function Ls(t,e,r){if(r-e<1)return"";let o,i=[],s=0,a;for(;e<r;)a=t[e++],a<128?i[s++]=a:a>191&&a<224?i[s++]=(a&31)<<6|t[e++]&63:a>239&&a<365?(a=((a&7)<<18|(t[e++]&63)<<12|(t[e++]&63)<<6|t[e++]&63)-65536,i[s++]=55296+(a>>10),i[s++]=56320+(a&1023)):i[s++]=(a&15)<<12|(t[e++]&63)<<6|t[e++]&63,s>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,i)),s=0);return o!=null?(s>0&&o.push(String.fromCharCode.apply(String,i.slice(0,s))),o.join("")):String.fromCharCode.apply(String,i.slice(0,s))}function Jn(t,e,r){let n=r,o,i;for(let s=0;s<t.length;++s)o=t.charCodeAt(s),o<128?e[r++]=o:o<2048?(e[r++]=o>>6|192,e[r++]=o&63|128):(o&64512)===55296&&((i=t.charCodeAt(s+1))&64512)===56320?(o=65536+((o&1023)<<10)+(i&1023),++s,e[r++]=o>>18|240,e[r++]=o>>12&63|128,e[r++]=o>>6&63|128,e[r++]=o&63|128):(e[r++]=o>>12|224,e[r++]=o>>6&63|128,e[r++]=o&63|128);return r-n}function ee(t,e){return RangeError(`index out of range: ${t.pos} + ${e??1} > ${t.len}`)}function mr(t,e){return(t[e-4]|t[e-3]<<8|t[e-2]<<16|t[e-1]<<24)>>>0}var Xn=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(e){this.buf=e,this.pos=0,this.len=e.length}uint32(){let e=4294967295;if(e=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(e=(e|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return e;if((this.pos+=5)>this.len)throw this.pos=this.len,ee(this,10);return e}int32(){return this.uint32()|0}sint32(){let e=this.uint32();return e>>>1^-(e&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw ee(this,4);return mr(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw ee(this,4);return mr(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw ee(this,4);let e=Ss(this.buf,this.pos);return this.pos+=4,e}double(){if(this.pos+8>this.len)throw ee(this,4);let e=Ns(this.buf,this.pos);return this.pos+=8,e}bytes(){let e=this.uint32(),r=this.pos,n=this.pos+e;if(n>this.len)throw ee(this,e);return this.pos+=e,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let e=this.bytes();return Ls(e,0,e.length)}skip(e){if(typeof e=="number"){if(this.pos+e>this.len)throw ee(this,e);this.pos+=e}else do if(this.pos>=this.len)throw ee(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(e){switch(e){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(e=this.uint32()&7)!==4;)this.skipType(e);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${e} at offset ${this.pos}`)}return this}readLongVarint(){let e=new J(0,0),r=0;if(this.len-this.pos>4){for(;r<4;++r)if(e.lo=(e.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return e;if(e.lo=(e.lo|(this.buf[this.pos]&127)<<28)>>>0,e.hi=(e.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return e;r=0}else{for(;r<3;++r){if(this.pos>=this.len)throw ee(this);if(e.lo=(e.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return e}return e.lo=(e.lo|(this.buf[this.pos++]&127)<<r*7)>>>0,e}if(this.len-this.pos>4){for(;r<5;++r)if(e.hi=(e.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return e}else for(;r<5;++r){if(this.pos>=this.len)throw ee(this);if(e.hi=(e.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return e}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw ee(this,8);let e=mr(this.buf,this.pos+=4),r=mr(this.buf,this.pos+=4);return new J(e,r)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let e=Is(this.buf,this.pos);return this.pos+=St(e),e}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function Yn(t){return new Xn(t instanceof Uint8Array?t:t.subarray())}function Bt(t,e,r){let n=Yn(t);return e.decode(n,void 0,r)}function Kn(t){let e=t??8192,r=e>>>1,n,o=e;return function(s){if(s<1||s>r)return se(s);o+s>e&&(n=se(e),o=0);let a=n.subarray(o,o+=s);return(o&7)!==0&&(o=(o|7)+1),a}}var Te=class{fn;len;next;val;constructor(e,r,n){this.fn=e,this.len=r,this.next=void 0,this.val=n}};function Zn(){}var to=class{head;tail;len;next;constructor(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}},mf=Kn();function yf(t){return globalThis.Buffer!=null?se(t):mf(t)}var Ct=class{len;head;tail;states;constructor(){this.len=0,this.head=new Te(Zn,0,0),this.tail=this.head,this.states=null}_push(e,r,n){return this.tail=this.tail.next=new Te(e,r,n),this.len+=r,this}uint32(e){return this.len+=(this.tail=this.tail.next=new ro((e=e>>>0)<128?1:e<16384?2:e<2097152?3:e<268435456?4:5,e)).len,this}int32(e){return e<0?this._push(yr,10,J.fromNumber(e)):this.uint32(e)}sint32(e){return this.uint32((e<<1^e>>31)>>>0)}uint64(e){let r=J.fromBigInt(e);return this._push(yr,r.length(),r)}uint64Number(e){return this._push(As,St(e),e)}uint64String(e){return this.uint64(BigInt(e))}int64(e){return this.uint64(e)}int64Number(e){return this.uint64Number(e)}int64String(e){return this.uint64String(e)}sint64(e){let r=J.fromBigInt(e).zzEncode();return this._push(yr,r.length(),r)}sint64Number(e){let r=J.fromNumber(e).zzEncode();return this._push(yr,r.length(),r)}sint64String(e){return this.sint64(BigInt(e))}bool(e){return this._push(eo,1,e?1:0)}fixed32(e){return this._push(Nt,4,e>>>0)}sfixed32(e){return this.fixed32(e)}fixed64(e){let r=J.fromBigInt(e);return this._push(Nt,4,r.lo)._push(Nt,4,r.hi)}fixed64Number(e){let r=J.fromNumber(e);return this._push(Nt,4,r.lo)._push(Nt,4,r.hi)}fixed64String(e){return this.fixed64(BigInt(e))}sfixed64(e){return this.fixed64(e)}sfixed64Number(e){return this.fixed64Number(e)}sfixed64String(e){return this.fixed64String(e)}float(e){return this._push(Ts,4,e)}double(e){return this._push(Bs,8,e)}bytes(e){let r=e.length>>>0;return r===0?this._push(eo,1,0):this.uint32(r)._push(wf,r,e)}string(e){let r=Ds(e);return r!==0?this.uint32(r)._push(Jn,r,e):this._push(eo,1,0)}fork(){return this.states=new to(this),this.head=this.tail=new Te(Zn,0,0),this.len=0,this}reset(){return this.states!=null?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new Te(Zn,0,0),this.len=0),this}ldelim(){let e=this.head,r=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=e.next,this.tail=r,this.len+=n),this}finish(){let e=this.head.next,r=yf(this.len),n=0;for(;e!=null;)e.fn(e.val,r,n),n+=e.len,e=e.next;return r}};function eo(t,e,r){e[r]=t&255}function gf(t,e,r){for(;t>127;)e[r++]=t&127|128,t>>>=7;e[r]=t}var ro=class extends Te{next;constructor(e,r){super(gf,e,r),this.next=void 0}};function yr(t,e,r){for(;t.hi!==0;)e[r++]=t.lo&127|128,t.lo=(t.lo>>>7|t.hi<<25)>>>0,t.hi>>>=7;for(;t.lo>127;)e[r++]=t.lo&127|128,t.lo=t.lo>>>7;e[r++]=t.lo}function Nt(t,e,r){e[r]=t&255,e[r+1]=t>>>8&255,e[r+2]=t>>>16&255,e[r+3]=t>>>24}function wf(t,e,r){e.set(t,r)}globalThis.Buffer!=null&&(Ct.prototype.bytes=function(t){let e=t.length>>>0;return this.uint32(e),e>0&&this._push(xf,e,t),this},Ct.prototype.string=function(t){let e=globalThis.Buffer.byteLength(t);return this.uint32(e),e>0&&this._push(bf,e,t),this});function xf(t,e,r){e.set(t,r)}function bf(t,e,r){t.length<40?Jn(t,e,r):e.utf8Write!=null?e.utf8Write(t,r):e.set(pr(t),r)}function no(){return new Ct}function Dt(t,e){let r=no();return e.encode(t,r,{lengthDelimited:!1}),r.finish()}var Xe;(function(t){t[t.VARINT=0]="VARINT",t[t.BIT64=1]="BIT64",t[t.LENGTH_DELIMITED=2]="LENGTH_DELIMITED",t[t.START_GROUP=3]="START_GROUP",t[t.END_GROUP=4]="END_GROUP",t[t.BIT32=5]="BIT32"})(Xe||(Xe={}));function gr(t,e,r,n){return{name:t,type:e,encode:r,decode:n}}function oo(t){function e(o){if(t[o.toString()]==null)throw new Error("Invalid enum value");return t[o]}let r=function(i,s){let a=e(i);s.int32(a)},n=function(i){let s=i.int32();return e(s)};return gr("enum",Xe.VARINT,r,n)}function Lt(t,e){return gr("message",Xe.LENGTH_DELIMITED,t,e)}function O(){let t={};return t.promise=new Promise((e,r)=>{t.resolve=e,t.reject=r}),t}var wr=class{buffer;mask;top;btm;next;constructor(e){if(!(e>0)||(e-1&e)!==0)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}},Ye=class{size;hwm;head;tail;constructor(e={}){this.hwm=e.splitLimit??16,this.head=new wr(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 r=this.head;this.head=r.next=new wr(2*this.head.buffer.length),this.head.push(e)}}shift(){let e=this.tail.shift();if(e===void 0&&this.tail.next!=null){let r=this.tail.next;this.tail.next=null,this.tail=r,e=this.tail.shift()}return e?.value!=null&&(this.size-=this.calculateSize(e.value)),e}isEmpty(){return this.head.isEmpty()}};var io=class extends Error{type;code;constructor(e,r){super(e??"The operation was aborted"),this.type="aborted",this.code=r??"ABORT_ERR"}};function Ke(t={}){return Ef(r=>{let n=r.shift();if(n==null)return{done:!0};if(n.error!=null)throw n.error;return{done:n.done===!0,value:n.value}},t)}function Ef(t,e){e=e??{};let r=e.onEnd,n=new Ye,o,i,s,a=O(),c=async()=>{try{return n.isEmpty()?s?{done:!0}:await new Promise((I,g)=>{i=w=>{i=null,n.push(w);try{I(t(n))}catch(b){g(b)}return o}}):t(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=O()})}},l=I=>i!=null?i(I):(n.push(I),o),p=I=>(n=new Ye,i!=null?i({error:I}):(n.push({error:I}),o)),d=I=>{if(s)return o;if(e?.objectMode!==!0&&I?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return l({done:!1,value:I})},k=I=>s?o:(s=!0,I!=null?p(I):l({done:!0})),u=()=>(n=new Ye,k(),{done:!0}),h=I=>(k(I),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:c,return:u,throw:h,push:d,end:k,get readableLength(){return n.size},onEmpty:async I=>{let g=I?.signal;if(g?.throwIfAborted(),n.isEmpty())return;let w,b;g!=null&&(w=new Promise((v,A)=>{b=()=>{A(new io)},g.addEventListener("abort",b)}));try{await Promise.race([a.promise,w])}finally{b!=null&&g!=null&&g?.removeEventListener("abort",b)}}},r==null)return o;let m=o;return o={[Symbol.asyncIterator](){return this},next(){return m.next()},throw(I){return m.throw(I),r!=null&&(r(I),r=void 0),{done:!0}},return(){return m.return(),r!=null&&(r(),r=void 0),{done:!0}},push:d,end(I){return m.end(I),r!=null&&(r(I),r=void 0),o},get readableLength(){return m.readableLength},onEmpty:I=>m.onEmpty(I)},o}var so=class extends Error{constructor(e){super(e),this.name="TimeoutError"}},ao=class extends Error{constructor(e){super(),this.name="AbortError",this.message=e}},Us=t=>globalThis.DOMException===void 0?new ao(t):new DOMException(t),Fs=t=>{let e=t.reason===void 0?Us("This operation was aborted."):t.reason;return e instanceof Error?e:Us(e)};function co(t,e){let{milliseconds:r,fallback:n,message:o,customTimers:i={setTimeout,clearTimeout}}=e,s,a,l=new Promise((p,d)=>{if(typeof r!="number"||Math.sign(r)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${r}\``);if(e.signal){let{signal:u}=e;u.aborted&&d(Fs(u)),a=()=>{d(Fs(u))},u.addEventListener("abort",a,{once:!0})}if(r===Number.POSITIVE_INFINITY){t.then(p,d);return}let k=new so;s=i.setTimeout.call(void 0,()=>{if(n){try{p(n())}catch(u){d(u)}return}typeof t.cancel=="function"&&t.cancel(),o===!1?p():o instanceof Error?d(o):(k.message=o??`Promise timed out after ${r} milliseconds`,d(k))},r),(async()=>{try{p(await t)}catch(u){d(u)}})()}).finally(()=>{l.clear(),a&&e.signal&&e.signal.removeEventListener("abort",a)});return l.clear=()=>{i.clearTimeout.call(void 0,s),s=void 0},l}var vf=t=>{let e=t.addEventListener||t.on||t.addListener,r=t.removeEventListener||t.off||t.removeListener;if(!e||!r)throw new TypeError("Emitter is not compatible");return{addListener:e.bind(t),removeListener:r.bind(t)}};function kf(t,e,r){let n,o=new Promise((i,s)=>{if(r={rejectionEvents:["error"],multiArgs:!1,rejectionMultiArgs:!1,resolveImmediately:!1,...r},!(r.count>=0&&(r.count===Number.POSITIVE_INFINITY||Number.isInteger(r.count))))throw new TypeError("The `count` option should be at least 0 or more");r.signal?.throwIfAborted();let a=[e].flat(),c=[],{addListener:l,removeListener:p}=vf(t),d=async(...u)=>{let h=r.multiArgs?u:u[0];if(r.filter)try{if(!await r.filter(h))return}catch(m){n(),s(m);return}c.push(h),r.count===c.length&&(n(),i(c))},k=(...u)=>{n(),s(r.rejectionMultiArgs?u:u[0])};n=()=>{for(let u of a)p(u,d);for(let u of r.rejectionEvents)a.includes(u)||p(u,k)};for(let u of a)l(u,d);for(let u of r.rejectionEvents)a.includes(u)||l(u,k);r.signal&&r.signal.addEventListener("abort",()=>{k(r.signal.reason)},{once:!0}),r.resolveImmediately&&i(c)});if(o.cancel=n,typeof r.timeout=="number"){let i=co(o,{milliseconds:r.timeout});return i.cancel=()=>{n(),i.clear()},i}return o}function xr(t,e,r){typeof r=="function"&&(r={filter:r}),r={...r,count:1,resolveImmediately:!1};let n=kf(t,e,r),o=n.then(i=>i[0]);return o.cancel=n.cancel,o}function uo(t,e){let r,n=function(){let o=function(){r=void 0,t()};clearTimeout(r),r=setTimeout(o,e)};return n.start=()=>{},n.stop=()=>{clearTimeout(r)},n}var br=class extends Error{static name="QueueFullError";constructor(e="The queue was full"){super(e),this.name="QueueFullError"}};var Er=class{deferred;signal;constructor(e){this.signal=e,this.deferred=O(),this.onAbort=this.onAbort.bind(this),this.signal?.addEventListener("abort",this.onAbort)}onAbort(){this.deferred.reject(this.signal?.reason??new le)}cleanup(){this.signal?.removeEventListener("abort",this.onAbort)}};function _f(){return`${parseInt(String(Math.random()*1e9),10).toString()}${Date.now()}`}var vr=class{id;fn;options;recipients;status;timeline;controller;constructor(e,r){this.id=_f(),this.status="queued",this.fn=e,this.options=r,this.recipients=[],this.timeline={created:Date.now()},this.controller=new AbortController,this.controller.signal,this.onAbort=this.onAbort.bind(this)}abort(e){this.controller.abort(e)}onAbort(){this.recipients.reduce((r,n)=>r&&n.signal?.aborted===!0,!0)&&(this.controller.abort(new le),this.cleanup())}async join(e={}){let r=new Er(e.signal);return this.recipients.push(r),e.signal?.addEventListener("abort",this.onAbort),r.deferred.promise}async run(){this.status="running",this.timeline.started=Date.now();try{this.controller.signal.throwIfAborted();let e=await Qe(this.fn({...this.options??{},signal:this.controller.signal}),this.controller.signal);this.recipients.forEach(r=>{r.deferred.resolve(e)}),this.status="complete"}catch(e){this.recipients.forEach(r=>{r.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 Ze=class extends lr{concurrency;maxSize;queue;pending;sort;paused;constructor(e={}){super(),this.concurrency=e.concurrency??Number.POSITIVE_INFINITY,this.maxSize=e.maxSize??Number.POSITIVE_INFINITY,this.pending=0,this.paused=!1,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=[],this.emitEmpty=uo(this.emitEmpty.bind(this),1),this.emitIdle=uo(this.emitIdle.bind(this),1)}emitEmpty(){this.size===0&&this.safeDispatchEvent("empty")}emitIdle(){this.running===0&&this.safeDispatchEvent("idle")}pause(){this.paused=!0}resume(){this.paused&&(this.paused=!1,this.tryToStartAnother())}tryToStartAnother(){if(this.paused)return!1;if(this.size===0)return this.emitEmpty(),this.running===0&&this.emitIdle(),!1;if(this.pending<this.concurrency){let e;for(let r of this.queue)if(r.status==="queued"){e=r;break}return e==null?!1:(this.safeDispatchEvent("active"),this.pending++,e.run().finally(()=>{for(let r=0;r<this.queue.length;r++)if(this.queue[r]===e){this.queue.splice(r,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,r){if(r?.signal?.throwIfAborted(),this.size===this.maxSize)throw new br;let n=new vr(e,r);return this.enqueue(n),this.safeDispatchEvent("add"),this.tryToStartAnother(),n.join(r).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("failure",{detail:{job:n,error:o}}),o})}clear(){this.queue.splice(0,this.queue.length)}abort(){this.queue.forEach(e=>{e.abort(new le)}),this.clear()}async onEmpty(e){this.size!==0&&await xr(this,"empty",e)}async onSizeLessThan(e,r){this.size<e||await xr(this,"next",{...r,filter:()=>this.size<e})}async onIdle(e){this.pending===0&&this.size===0||await xr(this,"idle",e)}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 r=Ke({objectMode:!0}),n=c=>{c!=null?this.abort():this.clear(),r.end(c)},o=c=>{c.detail!=null&&r.push(c.detail)},i=c=>{n(c.detail.error)},s=()=>{n()},a=()=>{n(new le("Queue aborted"))};this.addEventListener("completed",o),this.addEventListener("failure",i),this.addEventListener("idle",s),e?.signal?.addEventListener("abort",a);try{yield*r}finally{this.removeEventListener("completed",o),this.removeEventListener("failure",i),this.removeEventListener("idle",s),e?.signal?.removeEventListener("abort",a),n()}}};function Rs(t){let e=new globalThis.AbortController;function r(){e.abort();for(let i of t)i?.removeEventListener!=null&&i.removeEventListener("abort",r)}for(let i of t){if(i?.aborted===!0){r();break}i?.addEventListener!=null&&i.addEventListener("abort",r)}function n(){for(let i of t)i?.removeEventListener!=null&&i.removeEventListener("abort",r)}let o=e.signal;return o.clear=n,o}var fo=class{readNext;haveNext;ended;nextResult;error;constructor(){this.ended=!1,this.readNext=O(),this.haveNext=O()}[Symbol.asyncIterator](){return this}async next(){if(this.nextResult==null&&await this.haveNext.promise,this.nextResult==null)throw new Error("HaveNext promise resolved but nextResult was undefined");let e=this.nextResult;return this.nextResult=void 0,this.readNext.resolve(),this.readNext=O(),e}async throw(e){return this.ended=!0,this.error=e,e!=null&&(this.haveNext.promise.catch(()=>{}),this.haveNext.reject(e)),{done:!0,value:void 0}}async return(){let e={done:!0,value:void 0};return this.ended=!0,this.nextResult=e,this.haveNext.resolve(),e}async push(e,r){await this._push(e,r)}async end(e,r){e!=null?await this.throw(e):await this._push(void 0,r)}async _push(e,r){if(e!=null&&this.ended)throw this.error??new Error("Cannot push value onto an ended pushable");for(;this.nextResult!=null;)await this.readNext.promise;e!=null?this.nextResult={done:!1,value:e}:(this.ended=!0,this.nextResult={done:!0,value:void 0}),this.haveNext.resolve(),this.haveNext=O(),await Qe(this.readNext.promise,r?.signal,r)}};function zs(){return new fo}function Af(t){return t[Symbol.asyncIterator]!=null}async function If(t,e,r){try{await Promise.all(t.map(async n=>{for await(let o of n)await e.push(o,{signal:r}),r.throwIfAborted()})),await e.end(void 0,{signal:r})}catch(n){await e.end(n,{signal:r}).catch(()=>{})}}async function*Tf(t){let e=new AbortController,r=zs();If(t,r,e.signal).catch(()=>{});try{yield*r}finally{e.abort()}}function*Sf(t){for(let e of t)yield*e}function Bf(...t){let e=[];for(let r of t)Af(r)||e.push(r);return e.length===t.length?Sf(e):Tf(t)}var Ms=Bf;function et(t,...e){if(t==null)throw new Error("Empty pipeline");if(lo(t)){let n=t;t=()=>n.source}else if($s(t)||Os(t)){let n=t;t=()=>n}let r=[t,...e];if(r.length>1&&lo(r[r.length-1])&&(r[r.length-1]=r[r.length-1].sink),r.length>2)for(let n=1;n<r.length-1;n++)lo(r[n])&&(r[n]=Cf(r[n]));return Nf(...r)}var Nf=(...t)=>{let e;for(;t.length>0;)e=t.shift()(e);return e},Os=t=>t?.[Symbol.asyncIterator]!=null,$s=t=>t?.[Symbol.iterator]!=null,lo=t=>t==null?!1:t.sink!=null&&t.source!=null,Cf=t=>e=>{let r=t.sink(e);if(r?.then!=null){let n=Ke({objectMode:!0});r.then(()=>{n.end()},s=>{n.end(s)});let o,i=t.source;if(Os(i))o=async function*(){yield*i,n.end()};else if($s(i))o=function*(){yield*i,n.end()};else throw new Error("Unknown duplex source type - must be Iterable or AsyncIterable");return Ms(n,o())}return t.source};function Df(t){return t[Symbol.asyncIterator]!=null}function Lf(t){if(Df(t))return(async()=>{let n=new Uint8Array(0);for await(let o of t)n=Tt([n,o],n.length+o.length);return n})();let e=[],r=0;for(let n of t)e.push(n),r+=n.byteLength;return Tt(e,r)}var D=Lf;function kr({enumerable:t=!0,configurable:e=!1}={}){return{enumerable:t,configurable:e,writable:!1}}function*Pf(t,e){if(e!=null&&typeof e=="object")if(Array.isArray(e))for(let[r,n]of e.entries()){let o=[...t,r],i=N.asCID(n);i!=null?yield[o.join("/"),i]:typeof n=="object"&&(yield*ho(n,o))}else{let r=N.asCID(e);r!=null?yield[t.join("/"),r]:yield*ho(e,t)}}function*ho(t,e){if(t==null||t instanceof Uint8Array)return;let r=N.asCID(t);r!=null&&(yield[e.join("/"),r]);for(let[n,o]of Object.entries(t)){let i=[...e,n];yield*Pf(i,o)}}function*Uf(t,e){if(Array.isArray(e))for(let[r,n]of e.entries()){let o=[...t,r];yield o.join("/"),typeof n=="object"&&N.asCID(n)==null&&(yield*po(n,o))}else yield*po(e,t)}function*po(t,e){if(!(t==null||typeof t!="object"))for(let[r,n]of Object.entries(t)){let o=[...e,r];yield o.join("/"),n!=null&&!(n instanceof Uint8Array)&&typeof n=="object"&&N.asCID(n)==null&&(yield*Uf(o,n))}}function Ff(t,e){let r=t;for(let[n,o]of e.entries()){if(r=r[o],r==null)throw new Error(`Object has no property at ${e.slice(0,n+1).map(s=>`[${JSON.stringify(s)}]`).join("")}`);let i=N.asCID(r);if(i!=null)return{value:i,remaining:e.slice(n+1).join("/")}}return{value:r}}var mo=class{cid;bytes;value;asBlock;constructor({cid:e,bytes:r,value:n}){if(e==null||r==null||typeof n>"u")throw new Error("Missing required argument");this.cid=e,this.bytes=r,this.value=n,this.asBlock=this,Object.defineProperties(this,{cid:kr(),bytes:kr(),value:kr(),asBlock:kr()})}links(){return ho(this.value,[])}tree(){return po(this.value,[])}get(e="/"){return Ff(this.value,e.split("/").filter(Boolean))}};function ae({bytes:t,cid:e,value:r,codec:n}){let o=r!==void 0?r:n?.decode(t);if(o===void 0)throw new Error('Missing required argument, must either provide "value" or "codec"');return new mo({cid:e,bytes:t,value:o})}var Hs=class extends Array{constructor(){super(),this.inRecursive=[]}prefix(e){let r=this.inRecursive[this.inRecursive.length-1];r&&(r.type===f.array&&(r.elements++,r.elements!==1&&e.push([44])),r.type===f.map&&(r.elements++,r.elements!==1&&(r.elements%2===1?e.push([44]):e.push([58]))))}[f.uint.major](e,r){this.prefix(e);let n=String(r.value),o=[];for(let i=0;i<n.length;i++)o[i]=n.charCodeAt(i);e.push(o)}[f.negint.major](e,r){this[f.uint.major](e,r)}[f.bytes.major](e,r){throw new Error(`${Fe} unsupported type: Uint8Array`)}[f.string.major](e,r){this.prefix(e);let n=jt(JSON.stringify(r.value));e.push(n.length>32?at(n):n)}[f.array.major](e,r){this.prefix(e),this.inRecursive.push({type:f.array,elements:0}),e.push([91])}[f.map.major](e,r){this.prefix(e),this.inRecursive.push({type:f.map,elements:0}),e.push([123])}[f.tag.major](e,r){}[f.float.major](e,r){if(r.type.name==="break"){let s=this.inRecursive.pop();if(s){if(s.type===f.array)e.push([93]);else if(s.type===f.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(r.value===void 0)throw new Error(`${Fe} unsupported type: undefined`);if(this.prefix(e),r.type.name==="true"){e.push([116,114,117,101]);return}else if(r.type.name==="false"){e.push([102,97,108,115,101]);return}else if(r.type.name==="null"){e.push([110,117,108,108]);return}let n=String(r.value),o=[],i=!1;for(let s=0;s<n.length;s++)o[s]=n.charCodeAt(s),!i&&(o[s]===46||o[s]===101||o[s]===69)&&(i=!0);i||(o.push(46),o.push(48)),e.push(o)}};var tt=class{constructor(e,r={}){this._pos=0,this.data=e,this.options=r,this.modeStack=["value"],this.lastToken=""}pos(){return this._pos}done(){return this._pos>=this.data.length}ch(){return this.data[this._pos]}currentMode(){return this.modeStack[this.modeStack.length-1]}skipWhitespace(){let e=this.ch();for(;e===32||e===9||e===13||e===10;)e=this.data[++this._pos]}expect(e){if(this.data.length-this._pos<e.length)throw new Error(`${_} unexpected end of input at position ${this._pos}`);for(let r=0;r<e.length;r++)if(this.data[this._pos++]!==e[r])throw new Error(`${_} unexpected token at position ${this._pos}, expected to find '${String.fromCharCode(...e)}'`)}parseNumber(){let e=this._pos,r=!1,n=!1,o=a=>{for(;!this.done();){let c=this.ch();if(a.includes(c))this._pos++;else break}};if(this.ch()===45&&(r=!0,this._pos++),this.ch()===48)if(this._pos++,this.ch()===46)this._pos++,n=!0;else return new y(f.uint,0,this._pos-e);if(o([48,49,50,51,52,53,54,55,56,57]),r&&this._pos===e+1)throw new Error(`${_} unexpected token at position ${this._pos}`);if(!this.done()&&this.ch()===46){if(n)throw new Error(`${_} unexpected token at position ${this._pos}`);n=!0,this._pos++,o([48,49,50,51,52,53,54,55,56,57])}!this.done()&&(this.ch()===101||this.ch()===69)&&(n=!0,this._pos++,!this.done()&&(this.ch()===43||this.ch()===45)&&this._pos++,o([48,49,50,51,52,53,54,55,56,57]));let i=String.fromCharCode.apply(null,this.data.subarray(e,this._pos)),s=parseFloat(i);return n?new y(f.float,s,this._pos-e):this.options.allowBigInt!==!0||Number.isSafeInteger(s)?new y(s>=0?f.uint:f.negint,s,this._pos-e):new y(s>=0?f.uint:f.negint,BigInt(i),this._pos-e)}parseString(){if(this.ch()!==34)throw new Error(`${_} unexpected character at position ${this._pos}; this shouldn't happen`);this._pos++;for(let i=this._pos,s=0;i<this.data.length&&s<65536;i++,s++){let a=this.data[i];if(a===92||a<32||a>=128)break;if(a===34){let c=String.fromCharCode.apply(null,this.data.subarray(this._pos,i));return this._pos=i+1,new y(f.string,c,s)}}let e=this._pos,r=[],n=()=>{if(this._pos+4>=this.data.length)throw new Error(`${_} unexpected end of unicode escape sequence at position ${this._pos}`);let i=0;for(let s=0;s<4;s++){let a=this.ch();if(a>=48&&a<=57)a-=48;else if(a>=97&&a<=102)a=a-97+10;else if(a>=65&&a<=70)a=a-65+10;else throw new Error(`${_} unexpected unicode escape character at position ${this._pos}`);i=i*16+a,this._pos++}return i},o=()=>{let i=this.ch(),s=null,a=i>239?4:i>223?3:i>191?2:1;if(this._pos+a>this.data.length)throw new Error(`${_} unexpected unicode sequence at position ${this._pos}`);let c,l,p,d;switch(a){case 1:i<128&&(s=i);break;case 2:c=this.data[this._pos+1],(c&192)===128&&(d=(i&31)<<6|c&63,d>127&&(s=d));break;case 3:c=this.data[this._pos+1],l=this.data[this._pos+2],(c&192)===128&&(l&192)===128&&(d=(i&15)<<12|(c&63)<<6|l&63,d>2047&&(d<55296||d>57343)&&(s=d));break;case 4:c=this.data[this._pos+1],l=this.data[this._pos+2],p=this.data[this._pos+3],(c&192)===128&&(l&192)===128&&(p&192)===128&&(d=(i&15)<<18|(c&63)<<12|(l&63)<<6|p&63,d>65535&&d<1114112&&(s=d))}s===null?(s=65533,a=1):s>65535&&(s-=65536,r.push(s>>>10&1023|55296),s=56320|s&1023),r.push(s),this._pos+=a};for(;!this.done();){let i=this.ch(),s;switch(i){case 92:if(this._pos++,this.done())throw new Error(`${_} unexpected string termination at position ${this._pos}`);switch(s=this.ch(),this._pos++,s){case 34:case 39:case 92:case 47:r.push(s);break;case 98:r.push(8);break;case 116:r.push(9);break;case 110:r.push(10);break;case 102:r.push(12);break;case 114:r.push(13);break;case 117:r.push(n());break;default:throw new Error(`${_} unexpected string escape character at position ${this._pos}`)}break;case 34:return this._pos++,new y(f.string,$r(r),this._pos-e);default:if(i<32)throw new Error(`${_} invalid control character at position ${this._pos}`);i<128?(r.push(i),this._pos++):o()}}throw new Error(`${_} unexpected end of string at position ${this._pos}`)}parseValue(){switch(this.ch()){case 123:return this.modeStack.push("obj-start"),this._pos++,new y(f.map,1/0,1);case 91:return this.modeStack.push("array-start"),this._pos++,new y(f.array,1/0,1);case 34:return this.parseString();case 110:return this.expect([110,117,108,108]),new y(f.null,null,4);case 102:return this.expect([102,97,108,115,101]),new y(f.false,!1,5);case 116:return this.expect([116,114,117,101]),new y(f.true,!0,4);case 45:case 48:case 49:case 50:case 51:case 52:case 53:case 54:case 55:case 56:case 57:return this.parseNumber();default:throw new Error(`${_} unexpected character at position ${this._pos}`)}}next(){switch(this.skipWhitespace(),this.currentMode()){case"value":return this.modeStack.pop(),this.parseValue();case"array-value":{if(this.modeStack.pop(),this.ch()===93)return this._pos++,this.skipWhitespace(),new y(f.break,void 0,1);if(this.ch()!==44)throw new Error(`${_} unexpected character at position ${this._pos}, was expecting array delimiter but found '${String.fromCharCode(this.ch())}'`);return this._pos++,this.modeStack.push("array-value"),this.skipWhitespace(),this.parseValue()}case"array-start":return this.modeStack.pop(),this.ch()===93?(this._pos++,this.skipWhitespace(),new y(f.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 y(f.break,void 0,1);if(this.ch()!==44)throw new Error(`${_} unexpected character at position ${this._pos}, was expecting object delimiter but found '${String.fromCharCode(this.ch())}'`);this._pos++,this.skipWhitespace();case"obj-start":{if(this.modeStack.pop(),this.ch()===125)return this._pos++,this.skipWhitespace(),new y(f.break,void 0,1);let e=this.parseString();if(this.skipWhitespace(),this.ch()!==58)throw new Error(`${_} unexpected character at position ${this._pos}, was expecting key/value delimiter ':' but found '${String.fromCharCode(this.ch())}'`);return this._pos++,this.modeStack.push("obj-value"),e}case"obj-value":return this.modeStack.pop(),this.modeStack.push("obj-key"),this.skipWhitespace(),this.parseValue();default:throw new Error(`${_} unexpected parse state at position ${this._pos}; this shouldn't happen`)}}};function yo(t,e){return e=Object.assign({tokenizer:new tt(t,e)},e),pt(t,e)}function Mf(t){return t instanceof ArrayBuffer?new Uint8Array(t,0,t.byteLength):t}var go=class extends tt{constructor(e,r){super(e,r),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===f.map){let r=this._next();if(r.type===f.string&&r.value==="/"){let n=this._next();if(n.type===f.string){if(this._next().type!==f.break)throw new Error("Invalid encoded CID form");return this.tokenBuffer.push(n),new y(f.tag,42,0)}if(n.type===f.map){let o=this._next();if(o.type===f.string&&o.value==="bytes"){let i=this._next();if(i.type===f.string){for(let a=0;a<2;a++)if(this._next().type!==f.break)throw new Error("Invalid encoded Bytes form");let s=An.decode(`m${i.value}`);return new y(f.bytes,s,i.value.length)}this.tokenBuffer.push(i)}this.tokenBuffer.push(o)}this.tokenBuffer.push(n)}this.tokenBuffer.push(r)}return e}},wo={allowIndefinite:!1,allowUndefined:!1,allowNaN:!1,allowInfinity:!1,allowBigInt:!0,strict:!0,useMaps:!1,rejectDuplicateMapKeys:!0,tags:[]};wo.tags[42]=N.parse;var Vs=297;var qs=t=>{let e=Mf(t),r=Object.assign(wo,{tokenizer:new go(e,wo)});return yo(e,r)};var p0=new TextDecoder;var m0=new TextEncoder;var Of=new TextDecoder;function xo(t,e){let r=0;for(let n=0;;n+=7){if(n>=64)throw new Error("protobuf: varint overflow");if(e>=t.length)throw new Error("protobuf: unexpected end of data");let o=t[e++];if(r+=n<28?(o&127)<<n:(o&127)*2**n,o<128)break}return[r,e]}function _r(t,e){let r;[r,e]=xo(t,e);let n=e+r;if(r<0||n<0)throw new Error("protobuf: invalid length");if(n>t.length)throw new Error("protobuf: unexpected end of data");return[t.subarray(e,n),n]}function js(t,e){let r;return[r,e]=xo(t,e),[r&7,r>>3,e]}function $f(t){let e={},r=t.length,n=0;for(;n<r;){let o,i;if([o,i,n]=js(t,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]=_r(t,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]=_r(t,n),e.Name=Of.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]=xo(t,n)}else throw new Error(`protobuf: (PBLink) invalid fieldNumber, expected 1, 2 or 3, got ${i}`)}if(n>r)throw new Error("protobuf: (PBLink) unexpected end of data");return e}function Ws(t){let e=t.length,r=0,n,o=!1,i;for(;r<e;){let a,c;if([a,c,r]=js(t,r),a!==2)throw new Error(`protobuf: (PBNode) invalid wireType, expected 2, got ${a}`);if(c===1){if(i)throw new Error("protobuf: (PBNode) duplicate Data section");[i,r]=_r(t,r),n&&(o=!0)}else if(c===2){if(o)throw new Error("protobuf: (PBNode) duplicate Links section");n||(n=[]);let l;[l,r]=_r(t,r),n.push($f(l))}else throw new Error(`protobuf: (PBNode) invalid fieldNumber, expected 1 or 2, got ${c}`)}if(r>e)throw new Error("protobuf: (PBNode) unexpected end of data");let s={};return i&&(s.Data=i),s.Links=n||[],s}var Js=new TextEncoder,Qs=2**32,Hf=2**31;function Vf(t,e){let r=e.length;if(typeof t.Tsize=="number"){if(t.Tsize<0)throw new Error("Tsize cannot be negative");if(!Number.isSafeInteger(t.Tsize))throw new Error("Tsize too large for encoding");r=Pt(e,r,t.Tsize)-1,e[r]=24}if(typeof t.Name=="string"){let n=Js.encode(t.Name);r-=n.length,e.set(n,r),r=Pt(e,r,n.length)-1,e[r]=18}return t.Hash&&(r-=t.Hash.length,e.set(t.Hash,r),r=Pt(e,r,t.Hash.length)-1,e[r]=10),e.length-r}function Xs(t){let e=Gf(t),r=new Uint8Array(e),n=e;if(t.Data&&(n-=t.Data.length,r.set(t.Data,n),n=Pt(r,n,t.Data.length)-1,r[n]=10),t.Links)for(let o=t.Links.length-1;o>=0;o--){let i=Vf(t.Links[o],r.subarray(0,n));n-=i,n=Pt(r,n,i)-1,r[n]=18}return r}function qf(t){let e=0;if(t.Hash){let r=t.Hash.length;e+=1+r+rt(r)}if(typeof t.Name=="string"){let r=Js.encode(t.Name).length;e+=1+r+rt(r)}return typeof t.Tsize=="number"&&(e+=1+rt(t.Tsize)),e}function Gf(t){let e=0;if(t.Data){let r=t.Data.length;e+=1+r+rt(r)}if(t.Links)for(let r of t.Links){let n=qf(r);e+=1+n+rt(n)}return e}function Pt(t,e,r){e-=rt(r);let n=e;for(;r>=Hf;)t[e++]=r&127|128,r/=128;for(;r>=128;)t[e++]=r&127|128,r>>>=7;return t[e]=r,n}function rt(t){return t%2===0&&t++,Math.floor((jf(t)+6)/7)}function jf(t){let e=0;return t>=Qs&&(t=Math.floor(t/Qs),e=32),t>=65536&&(t>>>=16,e+=16),t>=256&&(t>>>=8,e+=8),e+Wf[t]}var Wf=[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 Qf=["Data","Links"],Jf=["Hash","Name","Tsize"],Ys=new TextEncoder;function Xf(t,e){if(t===e)return 0;let r=t.Name?Ys.encode(t.Name):[],n=e.Name?Ys.encode(e.Name):[],o=r.length,i=n.length;for(let s=0,a=Math.min(o,i);s<a;++s)if(r[s]!==n[s]){o=r[s],i=n[s];break}return o<i?-1:i<o?1:0}function Ks(t,e){return!Object.keys(t).some(r=>!e.includes(r))}function Zs(t){if(!t||typeof t!="object"||Array.isArray(t)||t instanceof Uint8Array||t["/"]&&t["/"]===t.bytes)throw new TypeError("Invalid DAG-PB form");if(!Ks(t,Qf))throw new TypeError("Invalid DAG-PB form (extraneous properties)");if(t.Data!==void 0&&!(t.Data instanceof Uint8Array))throw new TypeError("Invalid DAG-PB form (Data must be bytes)");if(!Array.isArray(t.Links))throw new TypeError("Invalid DAG-PB form (Links must be a list)");for(let e=0;e<t.Links.length;e++){let r=t.Links[e];if(!r||typeof r!="object"||Array.isArray(r)||r instanceof Uint8Array||r["/"]&&r["/"]===r.bytes)throw new TypeError("Invalid DAG-PB form (bad link)");if(!Ks(r,Jf))throw new TypeError("Invalid DAG-PB form (extraneous properties on link)");if(r.Hash===void 0)throw new TypeError("Invalid DAG-PB form (link must have a Hash)");if(r.Hash==null||!r.Hash["/"]||r.Hash["/"]!==r.Hash.bytes)throw new TypeError("Invalid DAG-PB form (link Hash must be a CID)");if(r.Name!==void 0&&typeof r.Name!="string")throw new TypeError("Invalid DAG-PB form (link Name must be a string)");if(r.Tsize!==void 0){if(typeof r.Tsize!="number"||r.Tsize%1!==0)throw new TypeError("Invalid DAG-PB form (link Tsize must be an integer)");if(r.Tsize<0)throw new TypeError("Invalid DAG-PB form (link Tsize cannot be negative)")}if(e>0&&Xf(r,t.Links[e-1])===-1)throw new TypeError("Invalid DAG-PB form (links must be sorted by Name bytes)")}}function ea(t){return t instanceof ArrayBuffer?new Uint8Array(t,0,t.byteLength):t}var Ar=112;function ta(t){Zs(t);let e={};return t.Links&&(e.Links=t.Links.map(r=>{let n={};return r.Hash&&(n.Hash=r.Hash.bytes),r.Name!==void 0&&(n.Name=r.Name),r.Tsize!==void 0&&(n.Tsize=r.Tsize),n})),t.Data&&(e.Data=t.Data),Xs(e)}function be(t){let e=ea(t),r=Ws(e),n={};return r.Data&&(n.Data=r.Data),r.Links&&(n.Links=r.Links.map(o=>{let i={};try{i.Hash=N.decode(o.Hash)}catch{}if(!i.Hash)throw new Error("Invalid Hash field found in link, expected CID");return o.Name!==void 0&&(i.Name=o.Name),o.Tsize!==void 0&&(i.Tsize=o.Tsize),i})),n}function Yf(t){return t[Symbol.asyncIterator]!=null}function Kf(t,e){let r=0;if(Yf(t))return(async function*(){for await(let c of t)await e(c,r++)&&(yield c)})();let n=fr(t),{value:o,done:i}=n.next();if(i===!0)return(function*(){})();let s=e(o,r++);if(typeof s.then=="function")return(async function*(){await s&&(yield o);for(let c of n)await e(c,r++)&&(yield c)})();let a=e;return(function*(){s===!0&&(yield o);for(let c of n)a(c,r++)&&(yield c)})()}var Ir=Kf;function Se(t){return e=>new Eo(e,t)}function Be(t){return e=>new vo(e,t)}function _o(t){return e=>new ko(e,t)}var Ut=class{components;constructor(e,r={}){this.components=e}async*walk(e,r){let n=this.getQueue(),o=Ir(n.toGenerator(r),a=>a!=null),i=!1,s=async a=>{let c=a.cid,l=await D(this.components.blockstore.get(c,a)),p=ae({cid:c,bytes:l,codec:await this.components.getCodec(c.code)});for(let[,d]of p.links())r?.includeChild?.(d,p)!==!1&&n.add(s,{...a,cid:d,depth:a.depth+1,path:[...a.path,d]}).catch(k=>{i||o.throw(k)});return{block:p,depth:a.depth,path:a.path}};n.add(s,{...r,cid:e,depth:0,path:[e]}).catch(a=>{i||o.throw(a)});try{yield*o}finally{i=!0,n.abort()}}},Eo=class extends Ut{getQueue(){return new Ze({concurrency:1,sort:(e,r)=>e.options.depth===r.options.depth?0:e.options.depth<r.options.depth?1:-1})}},vo=class extends Ut{getQueue(){return new Ze({concurrency:1,sort:(e,r)=>e.options.depth===r.options.depth?0:e.options.depth<r.options.depth?-1:1})}},ko=class extends Ut{getQueue(){return new Ze({concurrency:1})}};var Ft=class{walker;constructor(e){this.walker=e?.walker}async*export(e,r,n,o){let i,s={blockstore:r,getCodec:n};this.walker!=null?i=this.walker(s):i=Be()(s);for await(let a of i.walk(e,o))yield a.block}};var Tr=class{components;log;constructor(e){this.components=e,this.log=e.logger.forComponent("helia:car")}async import(e,r){await _n(this.components.blockstore.putMany(ge(e.blocks(),({cid:n,bytes:o})=>({cid:n,bytes:o})),r))}async*export(e,r){let n=Array.isArray(e)?e:[e],{writer:o,out:i}=kt.create(n),s=i[Symbol.asyncIterator](),a=new AbortController;for(this._export(n,o,r).catch(c=>{this.log.error("error during streaming export - %e",c),a.abort(c)});;){let{done:c,value:l}=await Qe(s.next(),a.signal);if(a.signal.aborted)throw a.signal.reason;if(l!=null&&(yield l),c===!0)break}}async _export(e,r,n){let o=n?.traversal;for(let i of e){if(i.multihash.code===0)continue;let s=n?.exporter??(i.code===112?new Rt:new Ft),a=i,c=!1;if(o!=null){for await(let{cid:l,bytes:p}of o.traverse(a,this.components.blockstore,this.components.getCodec,n))if(this.log.trace("next CID on path to %c is %c",i,l),a=l,i.equals(l)&&(c=!0),c||n?.includeTraversalBlocks===!0){if(n?.blockFilter?.has(l.multihash.bytes)===!0)continue;n?.blockFilter?.add(l.multihash.bytes),await r.put({cid:l,bytes:p})}}for await(let{cid:l,bytes:p}of s.export(a,this.components.blockstore,this.components.getCodec,n))n?.blockFilter?.has(l.multihash.bytes)!==!0&&l.multihash.code!==0&&(c&&l.equals(a)||(n?.blockFilter?.add(l.multihash.bytes),await r.put({cid:l,bytes:p})))}await r.close()}};var Ao=class{async*export(e,r,n,o){let i=await D(r.get(e,o));yield ae({cid:e,bytes:i,codec:await n(e.code)})}};var zt=class t extends Error{static name="InvalidTypeError";static code="ERR_INVALID_TYPE";name=t.name;code=t.code;constructor(e="Invalid type"){super(e)}},Sr=class t extends Error{static name="InvalidUnixFSMessageError";static code="ERR_INVALID_MESSAGE";name=t.name;code=t.code;constructor(e="Invalid message"){super(e)}};var te;(function(t){let e;(function(o){o.Raw="Raw",o.Directory="Directory",o.File="File",o.Metadata="Metadata",o.Symlink="Symlink",o.HAMTShard="HAMTShard"})(e=t.DataType||(t.DataType={}));let r;(function(o){o[o.Raw=0]="Raw",o[o.Directory=1]="Directory",o[o.File=2]="File",o[o.Metadata=3]="Metadata",o[o.Symlink=4]="Symlink",o[o.HAMTShard=5]="HAMTShard"})(r||(r={})),(function(o){o.codec=()=>oo(r)})(e=t.DataType||(t.DataType={}));let n;t.codec=()=>(n==null&&(n=Lt((o,i,s={})=>{if(s.lengthDelimited!==!1&&i.fork(),o.Type!=null&&(i.uint32(8),t.DataType.codec().encode(o.Type,i)),o.Data!=null&&(i.uint32(18),i.bytes(o.Data)),o.filesize!=null&&(i.uint32(24),i.uint64(o.filesize)),o.blocksizes!=null)for(let a of o.blocksizes)i.uint32(32),i.uint64(a);o.hashType!=null&&(i.uint32(40),i.uint64(o.hashType)),o.fanout!=null&&(i.uint32(48),i.uint64(o.fanout)),o.mode!=null&&(i.uint32(56),i.uint32(o.mode)),o.mtime!=null&&(i.uint32(66),Br.codec().encode(o.mtime,i)),s.lengthDelimited!==!1&&i.ldelim()},(o,i)=>{let s={blocksizes:[]},a=i==null?o.len:o.pos+i;for(;o.pos<a;){let c=o.uint32();switch(c>>>3){case 1:s.Type=t.DataType.codec().decode(o);break;case 2:s.Data=o.bytes();break;case 3:s.filesize=o.uint64();break;case 4:s.blocksizes.push(o.uint64());break;case 5:s.hashType=o.uint64();break;case 6:s.fanout=o.uint64();break;case 7:s.mode=o.uint32();break;case 8:s.mtime=Br.codec().decode(o,o.uint32());break;default:o.skipType(c&7);break}}return s})),n),t.encode=o=>Dt(o,t.codec()),t.decode=o=>Bt(o,t.codec())})(te||(te={}));var Br;(function(t){let e;t.codec=()=>(e==null&&(e=Lt((r,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),r.Seconds!=null&&(n.uint32(8),n.int64(r.Seconds)),r.FractionalNanoseconds!=null&&(n.uint32(21),n.fixed32(r.FractionalNanoseconds)),o.lengthDelimited!==!1&&n.ldelim()},(r,n)=>{let o={},i=n==null?r.len:r.pos+n;for(;r.pos<i;){let s=r.uint32();switch(s>>>3){case 1:o.Seconds=r.int64();break;case 2:o.FractionalNanoseconds=r.fixed32();break;default:r.skipType(s&7);break}}return o})),e),t.encode=r=>Dt(r,t.codec()),t.decode=r=>Bt(r,t.codec())})(Br||(Br={}));var na;(function(t){let e;t.codec=()=>(e==null&&(e=Lt((r,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),r.MimeType!=null&&(n.uint32(10),n.string(r.MimeType)),o.lengthDelimited!==!1&&n.ldelim()},(r,n)=>{let o={},i=n==null?r.len:r.pos+n;for(;r.pos<i;){let s=r.uint32();switch(s>>>3){case 1:o.MimeType=r.string();break;default:r.skipType(s&7);break}}return o})),e),t.encode=r=>Dt(r,t.codec()),t.decode=r=>Bt(r,t.codec())})(na||(na={}));var oa={Raw:"raw",Directory:"directory",File:"file",Metadata:"metadata",Symlink:"symlink",HAMTShard:"hamt-sharded-directory"},el=["directory","hamt-sharded-directory"],ia=parseInt("0644",8),sa=parseInt("0755",8),aa=BigInt(1024),q=class t{static unmarshal(e){let r=te.decode(e);if(r.fanout!=null&&r.fanout>aa)throw new Sr(`Fanout size was too large - ${r.fanout} > ${aa}`);let n=new t({type:oa[r.Type!=null?r.Type.toString():"File"],data:r.Data,blockSizes:r.blocksizes,mode:r.mode,mtime:r.mtime!=null?{secs:r.mtime.Seconds??0n,nsecs:r.mtime.FractionalNanoseconds}:void 0,fanout:r.fanout});return n._originalMode=r.mode??0,n}type;data;blockSizes;hashType;fanout;mtime;_mode;_originalMode;constructor(e={type:"file"}){let{type:r,data:n,blockSizes:o,hashType:i,fanout:s,mtime:a,mode:c}=e;if(r!=null&&!Object.values(oa).includes(r))throw new zt("Type: "+r+" is not valid");this.type=r??"file",this.data=n,this.hashType=i,this.fanout=s,this.blockSizes=o??[],this._originalMode=0,this.mode=c,this.mtime=a}set mode(e){e==null?this._mode=this.isDirectory()?sa:ia:this._mode=e&4095}get mode(){return this._mode}isDirectory(){return el.includes(this.type)}addBlockSize(e){this.blockSizes.push(e)}removeBlockSize(e){this.blockSizes.splice(e,1)}fileSize(){if(this.isDirectory())return 0n;let e=0n;return this.blockSizes.forEach(r=>{e+=r}),this.data!=null&&(e+=BigInt(this.data.length)),e}marshal(){let e;switch(this.type){case"raw":e=te.DataType.Raw;break;case"directory":e=te.DataType.Directory;break;case"file":e=te.DataType.File;break;case"metadata":e=te.DataType.Metadata;break;case"symlink":e=te.DataType.Symlink;break;case"hamt-sharded-directory":e=te.DataType.HAMTShard;break;default:throw new zt(`Type: ${e} is not valid`)}let r=this.data;(this.data==null||this.data.length===0)&&(r=void 0);let n;this.mode!=null&&(n=this._originalMode&4294963200|(this.mode??0),n===ia&&!this.isDirectory()&&(n=void 0),n===sa&&this.isDirectory()&&(n=void 0));let o;return this.mtime!=null&&(o={Seconds:this.mtime.secs,FractionalNanoseconds:this.mtime.nsecs}),te.encode({Type:e,Data:r,filesize:this.isDirectory()?void 0:this.fileSize(),blocksizes:this.blockSizes,hashType:this.hashType,fanout:this.fanout,mode:n,mtime:o})}};var Mt=class extends Error{static code="ERR_NOT_UNIXFS";static message="Not a UnixFS node";static name="NotUnixFSError";code="ERR_NOT_UNIXFS";message="Not a UnixFS node";name="NotUnixFSError"},Nr=class extends Error{static name="NotDescendantError";name="NotDescendantError"},nt=class extends Error{static name="InvalidTraversalError";name="InvalidTraversalError"};function rl(t){return t.cid.code===85}function nl(t){return t.cid.code===112}function ol(t){if(rl(t))return!0;if(nl(t)&&t.value.Data!=null){let e=q.unmarshal(t.value.Data);return e.type==="file"||e.type==="raw"}else throw new Mt("Encountered non raw/dag-pb CID in UnixFS DAG")}var Rt=class{options;constructor(e){this.options=e}async*export(e,r,n,o){if(e.code!==112&&e.code!==85)throw new Mt("Target CID was not UnixFS - use the SubGraphExporter to export arbitrary graphs");let i=Se()({blockstore:r,getCodec:n}),s=this.options?.offset??0,a=this.options?.length??1/0,c=this.options?.listingOnly??!1;if(s<0)throw new _e("Offset cannot be negative");if(a<0)throw new _e("Length cannot be negative");let l,p=new AbortController,d=Rs([p.signal,o?.signal]);p.signal;function k(u,h){if(l==null&&(l=ol(h)),!l){let A=h.value.Links.find(E=>E.Hash.equals(u)),T=q.unmarshal(h.value.Data??new Uint8Array);return T.type==="directory"?!c:T.type==="hamt-sharded-directory"&&c?A?.Name?.length===2:!0}let m=h.value.Links.findIndex(A=>A.Hash.equals(u)),I=q.unmarshal(h.value.Data??new Uint8Array),g=s,w=g+a,b=Number([...I.blockSizes].slice(0,m).reduce((A,T)=>A+T,0n)),v=b+Number(I.blockSizes[m]);return g>=b&&g<v||w>=b&&w<v||g<=b&&w>=v}try{for await(let u of i.walk(e,{...o,includeChild:k,signal:d}))yield u.block}finally{p.abort(),d.clear()}}};function ca(t){return t!=null&&t?.asCID===t}var Io=class{haystack;needle;options;walker;constructor(...e){if(ca(e[0]))ca(e[1])?(this.haystack=e[0],this.needle=e[1],this.options=e[2]):(this.needle=e[0],this.options=e[1]);else throw new _e("needle must be specified");this.walker=this.options?.walker}async*traverse(e,r,n,o){let i=this.haystack??e,s,a={blockstore:r,getCodec:n};this.walker!=null?s=this.walker(a):this.options?.strategy==="breadth-first"?s=Be()(a):s=Se()(a);for await(let c of s.walk(i,o))if(c.block.cid.equals(this.needle)){for(let l of c.path){let p=await D(r.get(l,o));yield ae({cid:l,bytes:p,codec:await n(l.code)})}return}throw new nt(`${this.needle} was not a child of ${i}`)}};var To=class{path;constructor(e){this.path=e}async*traverse(e,r,n,o){if(!this.path.some(s=>s.equals(e)))throw new nt(`CIDPath traversal must include ${e}`);let i;for(let s of this.path){if(i!=null){let l=!1;for(let[,p]of i.links())if(p.equals(s)){l=!0;break}if(!l)throw new Nr(`${s} is not a child of ${i.cid}`)}let a=await D(r.get(s,o)),c=ae({cid:s,bytes:a,codec:await n(s.code)});i=c,yield c}}};var Cr=class t extends Error{static name="BadPathError";static code="ERR_BAD_PATH";name=t.name;code=t.code;constructor(e="Bad path"){super(e)}},re=class t extends Error{static name="NotFoundError";static code="ERR_NOT_FOUND";name=t.name;code=t.code;constructor(e="Not found"){super(e)}},Dr=class t extends Error{static name="NoResolverError";static code="ERR_NO_RESOLVER";name=t.name;code=t.code;constructor(e="No resolver"){super(e)}},P=class t extends Error{static name="NotUnixFSError";static code="ERR_NOT_UNIXFS";name=t.name;code=t.code;constructor(e="Not UnixFS"){super(e)}},Lr=class t extends Error{static name="OverReadError";static code="ERR_OVER_READ";name=t.name;code=t.code;constructor(e="Over read"){super(e)}},Pr=class t extends Error{static name="UnderReadError";static code="ERR_UNDER_READ";name=t.name;code=t.code;constructor(e="Under read"){super(e)}},Ur=class t extends Error{static name="NoPropError";static code="ERR_NO_PROP";name=t.name;code=t.code;constructor(e="No Property found"){super(e)}},Ne=class t extends Error{static name="InvalidParametersError";static code="ERR_INVALID_PARAMS";name=t.name;code=t.code;constructor(e="Invalid parameters"){super(e)}};function ot(t,e,r,n,o,i,s){let a=t,c=o;for(;i.length>0;){let l=i[0];if(l in a){i.shift(),c=`${c}/${l}`;let p=N.asCID(a[l]);if(p!=null)return{entry:{type:"object",name:n,path:o,cid:r,node:e,depth:s,size:BigInt(e.length),content:async function*(){yield t}},next:{cid:p,name:l,path:c,toResolve:i}};a=a[l]}else throw new Ur(`No property named ${l} found in node ${r}`)}return{entry:{type:"object",name:n,path:o,cid:r,node:e,depth:s,size:BigInt(e.length),content:async function*(){yield t}}}}var il=async(t,e,r,n,o,i,s,a)=>{let c=await D(s.get(t,a)),l=xt(c);return ot(l,c,t,e,r,n,i)},ua=il;var sl=async(t,e,r,n,o,i,s,a)=>{let c=await D(s.get(t,a)),l=qs(c);return ot(l,c,t,e,r,n,i)},fa=sl;function al(t,e,r,n){let o=BigInt(t.length),i=BigInt(e+o);return r>=i||n<e?new Uint8Array(0):(n>=e&&n<i&&(t=t.subarray(0,Number(n-e))),r>=e&&r<i&&(t=t.subarray(Number(r-e))),t)}var Ce=al;var cl=(t,e=0,r=t)=>{let n=BigInt(t),o=BigInt(e??0),i=BigInt(r);if(i!==n&&(i=o+i),i>n&&(i=n),o<0n)throw new Ne("Offset must be greater than or equal to 0");if(o>n)throw new Ne("Offset must be less than the file size");if(i<0n)throw new Ne("Length must be greater than or equal to 0");if(i>n)throw new Ne("Length must be less than the file size");return{start:o,end:i}},it=cl;var ul=t=>{async function*e(r={}){let{start:n,end:o}=it(t.length,r.offset,r.length),i=Ce(t,0n,n,o);r.onProgress?.(new F("unixfs:exporter:progress:identity",{bytesRead:BigInt(i.byteLength),totalBytes:o-n,fileSize:BigInt(t.byteLength)})),yield i}return e},fl=async(t,e,r,n,o,i,s,a)=>{if(n.length>0)throw new re(`No link named ${r} found in raw node ${t}`);let c=We(t.multihash.bytes);return{entry:{type:"identity",name:e,path:r,cid:t,content:ul(c.digest),depth:i,size:BigInt(c.digest.length),node:c.digest}}},la=fl;var ll=async(t,e,r,n,o,i,s,a)=>{let c=await D(s.get(t,a)),l=ls(c);return ot(l,c,t,e,r,n,i)},ha=ll;var hl=t=>{async function*e(r={}){let{start:n,end:o}=it(t.length,r.offset,r.length),i=Ce(t,0n,n,o);r.onProgress?.(new F("unixfs:exporter:progress:raw",{bytesRead:BigInt(i.byteLength),totalBytes:o-n,fileSize:BigInt(t.byteLength)})),yield i}return e},dl=async(t,e,r,n,o,i,s,a)=>{if(n.length>0)throw new re(`No link named ${r} found in raw node ${t}`);let c=await D(s.get(t,a));return{entry:{type:"raw",name:e,path:r,cid:t,content:hl(c),depth:i,size:BigInt(c.length),node:c}}},da=dl;var Rr=Ee(ya(),1);function pl(t){let e=new Array(4);for(let r=0;r<4;r++)e[r]=t&255,t=t>>8;return new Uint8Array(e)}var ew=Ae({name:"murmur3-32",code:35,encode:t=>pl(Rr.default.x86.hash32(t))}),ga=Ae({name:"murmur3-128",code:34,encode:t=>ke.fromHex(Rr.default.x64.hash128(t))}),tw=Ae({name:"murmur3-x64-64",code:34,encode:t=>ke.fromHex(Rr.default.x64.hash128(t)).subarray(0,8)});var Ea=Ee(ba(),1);var De=class t{_options;_popCount;_parent;_posAtParent;_children;key;constructor(e,r,n=0){this._options=e,this._popCount=0,this._parent=r,this._posAtParent=n,this._children=new Ea.default,this.key=null}async put(e,r){let n=await this._findNewBucketAndPos(e);n.bucket._putAt(n,e,r)}async get(e){let r=await this._findChild(e);if(r!=null)return r.value}async del(e){let r=await this._findPlace(e),n=r.bucket._at(r.pos);n!=null&&n.key===e&&r.bucket._delAt(r.pos)}leafCount(){return this._children.compactArray().reduce((r,n)=>n instanceof t?r+n.leafCount():r+1,0)}childrenCount(){return this._children.length}onlyChild(){return this._children.get(0)}*eachLeafSeries(){let e=this._children.compactArray();for(let r of e)r instanceof t?yield*r.eachLeafSeries():yield r}serialize(e,r){let n=[];return r(this._children.reduce((o,i,s)=>(i!=null&&(i instanceof t?o.push(i.serialize(e,r)):o.push(e(i,s))),o),n))}async asyncTransform(e,r){return va(this,e,r)}toJSON(){return this.serialize(xl,bl)}prettyPrint(){return JSON.stringify(this.toJSON(),null," ")}tableSize(){return Math.pow(2,this._options.bits)}async _findChild(e){let r=await this._findPlace(e),n=r.bucket._at(r.pos);if(!(n instanceof t)&&n!=null&&n.key===e)return n}async _findPlace(e){let r=this._options.hash(typeof e=="string"?pr(e):e),n=await r.take(this._options.bits),o=this._children.get(n);return o instanceof t?o._findPlace(r):{bucket:this,pos:n,hash:r,existingChild:o}}async _findNewBucketAndPos(e){let r=await this._findPlace(e);if(r.existingChild!=null&&r.existingChild.key!==e){let n=new t(this._options,r.bucket,r.pos);r.bucket._putObjectAt(r.pos,n);let o=await n._findPlace(r.existingChild.hash);return o.bucket._putAt(o,r.existingChild.key,r.existingChild.value),n._findNewBucketAndPos(r.hash)}return r}_putAt(e,r,n){this._putObjectAt(e.pos,{key:r,value:n,hash:e.hash})}_putObjectAt(e,r){this._children.get(e)==null&&this._popCount++,this._children.set(e,r)}_delAt(e){if(e===-1)throw new Error("Invalid position");this._children.get(e)!=null&&this._popCount--,this._children.unset(e),this._level()}_level(){if(this._parent!=null&&this._popCount<=1)if(this._popCount===1){let e=this._children.find(wl);if(e!=null&&!(e instanceof t)){let r=e.hash;r.untake(this._options.bits);let n={pos:this._posAtParent,hash:r,bucket:this._parent};this._parent._putAt(n,e.key,e.value)}}else this._parent._delAt(this._posAtParent)}_at(e){return this._children.get(e)}};function wl(t){return!!t}function xl(t,e){return t.key}function bl(t){return t}async function va(t,e,r){let n=[];for(let o of t._children.compactArray())if(o instanceof De)await va(o,e,r);else{let i=await e(o);n.push({bitField:t._children.bitField(),children:i})}return r(n)}var El=[255,254,252,248,240,224,192,128],vl=[1,3,7,15,31,63,127,255],zr=class{_value;_currentBytePos;_currentBitPos;constructor(e){this._value=e,this._currentBytePos=e.length-1,this._currentBitPos=7}availableBits(){return this._currentBitPos+1+this._currentBytePos*8}totalBits(){return this._value.length*8}take(e){let r=e,n=0;for(;r>0&&this._haveBits();){let o=this._value[this._currentBytePos],i=this._currentBitPos+1,s=Math.min(i,r),a=kl(o,i-s,s);n=(n<<s)+a,r-=s,this._currentBitPos-=s,this._currentBitPos<0&&(this._currentBitPos=7,this._currentBytePos--)}return n}untake(e){for(this._currentBitPos+=e;this._currentBitPos>7;)this._currentBitPos-=8,this._currentBytePos+=1}_haveBits(){return this._currentBytePos>=0}};function kl(t,e,r){let n=_l(e,r);return(t&n)>>>e}function _l(t,e){return El[t]&vl[Math.min(e+t-1,7)]}function ka(t){function e(r){return r instanceof Mr?r:new Mr(r,t)}return e}var Mr=class{_value;_hashFn;_depth;_availableBits;_currentBufferIndex;_buffers;constructor(e,r){if(!(e instanceof Uint8Array))throw new Error("can only hash Uint8Arrays");this._value=e,this._hashFn=r,this._depth=-1,this._availableBits=0,this._currentBufferIndex=0,this._buffers=[]}async take(e){let r=e;for(;this._availableBits<r;)await this._produceMoreBits();let n=0;for(;r>0;){let o=this._buffers[this._currentBufferIndex],i=Math.min(o.availableBits(),r),s=o.take(i);n=(n<<i)+s,r-=i,this._availableBits-=i,o.availableBits()===0&&this._currentBufferIndex++}return n}untake(e){let r=e;for(;r>0;){let n=this._buffers[this._currentBufferIndex],o=Math.min(n.totalBits()-n.availableBits(),r);n.untake(o),r-=o,this._availableBits+=o,this._currentBufferIndex>0&&n.totalBits()===n.availableBits()&&(this._depth--,this._currentBufferIndex--)}}async _produceMoreBits(){this._depth++;let e=this._depth>0?Tt([this._value,Uint8Array.from([this._depth])]):this._value,r=await this._hashFn(e),n=new zr(r);this._buffers.push(n),this._availableBits+=n.availableBits()}};function _a(t){if(t==null||t.hashFn==null)throw new Error("please define an options.hashFn");let e={bits:t.bits??8,hash:ka(t.hashFn)};return new De(e)}var Al=async function(t){return(await ga.encode(t)).slice(0,8).reverse()},Il=async(t,e,r)=>{let n=(e.tableSize()-1).toString(16).length;await Promise.all(t.map(async o=>{if(o.Name==null)throw new Error("Unexpected Link without a Name");if(o.Name.length===n){let i=parseInt(o.Name,16);e._putObjectAt(i,new De({hash:r._options.hash,bits:r._options.bits},e,i));return}await r.put(o.Name.substring(2),!0)}))},Aa=(t,e)=>t.toString(16).toUpperCase().padStart(e,"0").substring(0,e),Tl=t=>{let e=t.bucket,r=[];for(;e._parent!=null;)r.push(e),e=e._parent;return r.push(e),r.reverse()},Ia=async(t,e,r,n,o)=>{if(n==null){if(t.Data==null)throw new P("no data in PBNode");let d;try{d=q.unmarshal(t.Data)}catch(u){throw new P(u.message)}if(d.type!=="hamt-sharded-directory")throw new P("not a HAMT");if(d.fanout==null)throw new P("missing fanout");let k=_a({hashFn:Al,bits:Math.log2(Number(d.fanout))});n={rootBucket:k,hamtDepth:1,lastBucket:k}}let i=(n.lastBucket.tableSize()-1).toString(16).length;await Il(t.Links,n.lastBucket,n.rootBucket);let s=await n.rootBucket._findNewBucketAndPos(e),a=Aa(s.pos,i),c=Tl(s);c.length>n.hamtDepth&&(n.lastBucket=c[n.hamtDepth],a=Aa(n.lastBucket._posAtParent,i));let l=t.Links.find(d=>{if(d.Name==null)return!1;let k=d.Name.substring(0,i),u=d.Name.substring(i);return!(k!==a||u!==""&&u!==e)});if(l==null)return;if(l.Name!=null&&l.Name.substring(i)===e)return l.Hash;n.hamtDepth++;let p=await D(r.get(l.Hash,o));return t=be(p),Ia(t,e,r,n,o)},Ta=Ia;function st(t){return t?.extended===!1}var Or=globalThis.CustomEvent??Event;async function*Le(t,e={}){let r=e.concurrency??1/0;r<1&&(r=1/0);let n=e.ordered??!1,o=new EventTarget,i=[],s=O(),a=O(),c=!1,l,p=!1;o.addEventListener("task-complete",()=>{a.resolve()}),Promise.resolve().then(async()=>{try{for await(let h of t){if(i.length===r&&(s=O(),await s.promise),p)break;let m={done:!1};i.push(m),h().then(I=>{m.done=!0,m.ok=!0,m.value=I,o.dispatchEvent(new Or("task-complete"))},I=>{m.done=!0,m.err=I,o.dispatchEvent(new Or("task-complete"))})}c=!0,o.dispatchEvent(new Or("task-complete"))}catch(h){l=h,o.dispatchEvent(new Or("task-complete"))}});function d(){return n?i[0]?.done:!!i.find(h=>h.done)}function*k(){for(;i.length>0&&i[0].done;){let h=i[0];if(i.shift(),h.ok)yield h.value;else throw p=!0,s.resolve(),h.err;s.resolve()}}function*u(){for(;d();)for(let h=0;h<i.length;h++)if(i[h].done){let m=i[h];if(i.splice(h,1),h--,m.ok)yield m.value;else throw p=!0,s.resolve(),m.err;s.resolve()}}for(;;){if(d()||(a=O(),await a.promise),l!=null||(n?yield*k():yield*u(),l!=null))throw l;if(c&&i.length===0)break}}var Sl=(t,e,r,n,o,i,s)=>{async function*a(c={}){let l=c.offset??0,p=c.length??e.Links.length,d=e.Links.slice(l,p);c.onProgress?.(new F("unixfs:exporter:walk:directory",{cid:t})),yield*et(d,k=>ge(k,u=>async()=>{let h=u.Name??"",m=`${n}/${h}`;return st(c)?{cid:u.Hash,name:h,path:m}:(await o(u.Hash,h,m,[],i+1,s,c)).entry}),k=>Le(k,{ordered:!0,concurrency:c.blockReadConcurrency}),k=>Ir(k,u=>u!=null))}return a},Sa=Sl;async function Ba(t,e,r,n,o,i,s){if(e instanceof Uint8Array){let l=Ce(e,n,o,i);r.push(l);return}if(e.Data==null)throw new P("no data in PBNode");let a;try{a=q.unmarshal(e.Data)}catch(l){throw new P(l.message)}if(a.data!=null){let l=a.data,p=Ce(l,n,o,i);r.push(p),n+=BigInt(p.byteLength)}let c=[];if(e.Links.length!==a.blockSizes.length)throw new P("Inconsistent block sizes and dag links");for(let l=0;l<e.Links.length;l++){let p=e.Links[l],d=n,k=d+a.blockSizes[l];if((o>=d&&o<k||i>=d&&i<=k||o<d&&i>k)&&c.push({link:p,blockStart:n}),n=k,n>i)break}await et(c,l=>ge(l,p=>async()=>{let d=await D(t.get(p.link.Hash,s));return{...p,block:d}}),l=>Le(l,{ordered:!0,concurrency:s.blockReadConcurrency}),async l=>{for await(let{link:p,block:d,blockStart:k}of l){let u;switch(p.Hash.code){case Ar:u=be(d);break;case dr:u=d;break;default:r.end(new P(`Unsupported codec: ${p.Hash.code}`));return}let h=new It({concurrency:1});h.on("error",m=>{r.end(m)}),h.add(async()=>{s.onProgress?.(new F("unixfs:exporter:walk:file",{cid:p.Hash})),await Ba(t,u,r,k,o,i,s)}),await h.onIdle()}}),n>=i&&r.end()}var Bl=(t,e,r,n,o,i,s)=>{async function*a(c={}){let l=r.fileSize();if(l===void 0)throw new Error("File was a directory");let{start:p,end:d}=it(l,c.offset,c.length);if(d===0n)return;let k=0n,u=d-p,h=Ke();c.onProgress?.(new F("unixfs:exporter:walk:file",{cid:t})),Ba(s,e,h,0n,p,d,c).catch(m=>{h.end(m)});for await(let m of h)if(m!=null){if(k+=BigInt(m.byteLength),k>u)throw h.end(),new Lr("Read too many bytes - the file size reported by the UnixFS data in the root node may be incorrect");k===u&&h.end(),c.onProgress?.(new F("unixfs:exporter:progress:unixfs:file",{bytesRead:k,totalBytes:u,fileSize:l})),yield m}if(k<u)throw new Pr("Traversed entire DAG but did not read enough bytes")}return a},So=Bl;var Nl=(t,e,r,n,o,i,s)=>{function a(c={}){return c.onProgress?.(new F("unixfs:exporter:walk:hamt-sharded-directory",{cid:t})),Na(e,n,o,i,s,c)}return a};async function*Na(t,e,r,n,o,i){let s=t.Links;if(t.Data==null)throw new P("no data in PBNode");let a;try{a=q.unmarshal(t.Data)}catch(p){throw new P(p.message)}if(a.fanout==null)throw new P("missing fanout");let c=(a.fanout-1n).toString(16).length,l=et(s,p=>ge(p,d=>async()=>{let k=d.Name!=null?d.Name.substring(c):null;if(k!=null&&k!==""){let u=`${e}/${k}`;return st(i)?{entries:[{cid:d.Hash,name:k,path:u}]}:{entries:[(await r(d.Hash,k,u,[],n+1,o,i)).entry].filter(Boolean)}}else{let u=await D(o.get(d.Hash,i));return t=be(u),i.onProgress?.(new F("unixfs:exporter:walk:hamt-sharded-directory",{cid:d.Hash})),{entries:Na(t,e,r,n,o,i)}}}),p=>Le(p,{ordered:!0,concurrency:i.blockReadConcurrency}));for await(let{entries:p}of l)yield*p}var Ca=Nl;var Cl=(t,e)=>t.Links.find(n=>n.Name===e)?.Hash,Dl={raw:So,file:So,directory:Sa,"hamt-sharded-directory":Ca,metadata:(t,e,r,n,o,i,s)=>()=>[],symlink:(t,e,r,n,o,i,s)=>()=>[]},Ll=async(t,e,r,n,o,i,s,a)=>{if(st(a)&&n.length===0)return{entry:{cid:t,name:e,path:r}};let c=await D(s.get(t,a)),l;try{l=be(c)}catch(u){throw new P(u.message)}let p,d;if(e==null&&(e=t.toString()),l.Data==null)throw new P("no data in PBNode");try{p=q.unmarshal(l.Data)}catch(u){throw new P(u.message)}if(r==null&&(r=e),n.length>0){let u;if(p?.type==="hamt-sharded-directory"?u=await Ta(l,n[0],s):u=Cl(l,n[0]),u==null)throw new re("file does not exist");let h=n.shift(),m=`${r}/${h}`;d={cid:u,toResolve:n,name:h??"",path:m}}let k=Dl[p.type](t,l,p,r,o,i,s);if(k==null)throw new re("could not find content exporter");return p.isDirectory()?{entry:{type:"directory",name:e,path:r,cid:t,content:k,unixfs:p,depth:i,node:l,size:p.fileSize()},next:d}:{entry:{type:"file",name:e,path:r,cid:t,content:k,unixfs:p,depth:i,node:l,size:p.fileSize()},next:d}},Da=Ll;var Pl={[Ar]:Da,[dr]:da,[qi]:ua,[Vs]:fa,[On.code]:la,[fs]:ha},La=async(t,e,r,n,o,i,s)=>{let a=Pl[t.code];if(a==null)throw new Dr(`No resolver for code ${t.code}`);return a(t,e,r,n,La,o,i,s)},Pa=La;var Ul=(t="")=>(t.trim().match(/([^\\^/]|\\\/)+/g)??[]).filter(Boolean),Fl=t=>{if(t instanceof Uint8Array)return{cid:N.decode(t),toResolve:[]};let e=N.asCID(t);if(e!=null)return{cid:e,toResolve:[]};if(typeof t=="string"){t.indexOf("/ipfs/")===0&&(t=t.substring(6));let r=Ul(t);return{cid:N.parse(r[0]),toResolve:r.slice(1)}}throw new Cr(`Unknown path type ${t}`)};async function*Ua(t,e,r={}){let{cid:n,toResolve:o}=Fl(t),i=n.toString(),s=i,a=o.length;for(;;){let c=await Pa(n,i,s,o,a,e,r);if(c.entry==null&&c.next==null)throw new re(`Could not resolve ${t}`);if(c.entry!=null&&(yield c.entry),c.next==null)return;o=c.next.toResolve,n=c.next.cid,i=c.next.name,s=c.next.path}}var Bo=class{root;path;constructor(...e){let r=e[0],n=e[1];if(typeof r=="string")n=r,r=void 0;else if(e.length<2)throw new Error("path or CID and path must be specified");n.startsWith("/")||(n=`/${n}`),this.root=r,this.path=n}async*traverse(e,r,n,o){for await(let i of Ua(`${this.root??e}${this.path}`,r,o))yield ae({cid:i.cid,bytes:i.node instanceof Uint8Array?i.node:ta(i.node),codec:await n(i.cid.code)})}};function Rl(t){return new Tr(t)}return $a(zl);})();
|
|
2
|
+
"use strict";var HeliaCar=(()=>{var Oa=Object.create;var Xt=Object.defineProperty;var Ha=Object.getOwnPropertyDescriptor;var Va=Object.getOwnPropertyNames;var qa=Object.getPrototypeOf,ja=Object.prototype.hasOwnProperty;var fe=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),q=(t,e)=>{for(var r in e)Xt(t,r,{get:e[r],enumerable:!0})},Mo=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Va(e))!ja.call(t,o)&&o!==r&&Xt(t,o,{get:()=>e[o],enumerable:!(n=Ha(e,o))||n.enumerable});return t};var Ee=(t,e,r)=>(r=t!=null?Oa(qa(t)):{},Mo(e||!t||!t.__esModule?Xt(r,"default",{value:t,enumerable:!0}):r,t)),Ga=t=>Mo(Xt({},"__esModule",{value:!0}),t);var ts=fe((Qh,es)=>{es.exports=_n;var Zi=128,mu=127,yu=~mu,gu=Math.pow(2,31);function _n(t,e,r){if(Number.MAX_SAFE_INTEGER&&t>Number.MAX_SAFE_INTEGER)throw _n.bytes=0,new RangeError("Could not encode varint");e=e||[],r=r||0;for(var n=r;t>=gu;)e[r++]=t&255|Zi,t/=128;for(;t&yu;)e[r++]=t&255|Zi,t>>>=7;return e[r]=t|0,_n.bytes=r-n+1,e}});var os=fe((Xh,ns)=>{ns.exports=In;var wu=128,rs=127;function In(t,n){var r=0,n=n||0,o=0,i=n,s,a=t.length;do{if(i>=a||o>49)throw In.bytes=0,new RangeError("Could not decode varint");s=t[i++],r+=o<28?(s&rs)<<o:(s&rs)*Math.pow(2,o),o+=7}while(s>=wu);return In.bytes=i-n,r}});var ss=fe((Yh,is)=>{var xu=Math.pow(2,7),bu=Math.pow(2,14),Eu=Math.pow(2,21),vu=Math.pow(2,28),ku=Math.pow(2,35),_u=Math.pow(2,42),Iu=Math.pow(2,49),Au=Math.pow(2,56),Tu=Math.pow(2,63);is.exports=function(t){return t<xu?1:t<bu?2:t<Eu?3:t<vu?4:t<ku?5:t<_u?6:t<Iu?7:t<Au?8:t<Tu?9:10}});var pr=fe((Kh,as)=>{as.exports={encode:ts(),decode:os(),encodingLength:ss()}});var ms=fe((sp,Fn)=>{"use strict";var ju=Object.prototype.hasOwnProperty,H="~";function It(){}Object.create&&(It.prototype=Object.create(null),new It().__proto__||(H=!1));function Gu(t,e,r){this.fn=t,this.context=e,this.once=r||!1}function ps(t,e,r,n,o){if(typeof r!="function")throw new TypeError("The listener must be a function");var i=new Gu(r,n||t,o),s=H?H+e:e;return t._events[s]?t._events[s].fn?t._events[s]=[t._events[s],i]:t._events[s].push(i):(t._events[s]=i,t._eventsCount++),t}function xr(t,e){--t._eventsCount===0?t._events=new It:delete t._events[e]}function z(){this._events=new It,this._eventsCount=0}z.prototype.eventNames=function(){var e=[],r,n;if(this._eventsCount===0)return e;for(n in r=this._events)ju.call(r,n)&&e.push(H?n.slice(1):n);return Object.getOwnPropertySymbols?e.concat(Object.getOwnPropertySymbols(r)):e};z.prototype.listeners=function(e){var r=H?H+e:e,n=this._events[r];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};z.prototype.listenerCount=function(e){var r=H?H+e:e,n=this._events[r];return n?n.fn?1:n.length:0};z.prototype.emit=function(e,r,n,o,i,s){var a=H?H+e:e;if(!this._events[a])return!1;var u=this._events[a],l=arguments.length,d,p;if(u.fn){switch(u.once&&this.removeListener(e,u.fn,void 0,!0),l){case 1:return u.fn.call(u.context),!0;case 2:return u.fn.call(u.context,r),!0;case 3:return u.fn.call(u.context,r,n),!0;case 4:return u.fn.call(u.context,r,n,o),!0;case 5:return u.fn.call(u.context,r,n,o,i),!0;case 6:return u.fn.call(u.context,r,n,o,i,s),!0}for(p=1,d=new Array(l-1);p<l;p++)d[p-1]=arguments[p];u.fn.apply(u.context,d)}else{var _=u.length,c;for(p=0;p<_;p++)switch(u[p].once&&this.removeListener(e,u[p].fn,void 0,!0),l){case 1:u[p].fn.call(u[p].context);break;case 2:u[p].fn.call(u[p].context,r);break;case 3:u[p].fn.call(u[p].context,r,n);break;case 4:u[p].fn.call(u[p].context,r,n,o);break;default:if(!d)for(c=1,d=new Array(l-1);c<l;c++)d[c-1]=arguments[c];u[p].fn.apply(u[p].context,d)}}return!0};z.prototype.on=function(e,r,n){return ps(this,e,r,n,!1)};z.prototype.once=function(e,r,n){return ps(this,e,r,n,!0)};z.prototype.removeListener=function(e,r,n,o){var i=H?H+e:e;if(!this._events[i])return this;if(!r)return xr(this,i),this;var s=this._events[i];if(s.fn)s.fn===r&&(!o||s.once)&&(!n||s.context===n)&&xr(this,i);else{for(var a=0,u=[],l=s.length;a<l;a++)(s[a].fn!==r||o&&!s[a].once||n&&s[a].context!==n)&&u.push(s[a]);u.length?this._events[i]=u.length===1?u[0]:u:xr(this,i)}return this};z.prototype.removeAllListeners=function(e){var r;return e?(r=H?H+e:e,this._events[r]&&xr(this,r)):(this._events=new It,this._eventsCount=0),this};z.prototype.off=z.prototype.removeListener;z.prototype.addListener=z.prototype.on;z.prefixed=H;z.EventEmitter=z;typeof Fn<"u"&&(Fn.exports=z)});var As=fe((om,Is)=>{Is.exports=function(t){if(!t)throw Error("hashlru must have a max value, of type number, greater than 0");var e=0,r=Object.create(null),n=Object.create(null);function o(i,s){r[i]=s,e++,e>=t&&(e=0,n=r,r=Object.create(null))}return{has:function(i){return r[i]!==void 0||n[i]!==void 0},remove:function(i){r[i]!==void 0&&(r[i]=void 0),n[i]!==void 0&&(n[i]=void 0)},get:function(i){var s=r[i];if(s!==void 0)return s;if((s=n[i])!==void 0)return o(i,s),s},set:function(i,s){r[i]!==void 0?r[i]=s:o(i,s)},clear:function(){r=Object.create(null),n=Object.create(null)}}}});var pa=fe((qt,qr)=>{(function(t,e){"use strict";var r={version:"3.0.0",x86:{},x64:{},inputValidation:!0};function n(c){if(!Array.isArray(c)&&!ArrayBuffer.isView(c))return!1;for(var h=0;h<c.length;h++)if(!Number.isInteger(c[h])||c[h]<0||c[h]>255)return!1;return!0}function o(c,h){return(c&65535)*h+(((c>>>16)*h&65535)<<16)}function i(c,h){return c<<h|c>>>32-h}function s(c){return c^=c>>>16,c=o(c,2246822507),c^=c>>>13,c=o(c,3266489909),c^=c>>>16,c}function a(c,h){c=[c[0]>>>16,c[0]&65535,c[1]>>>16,c[1]&65535],h=[h[0]>>>16,h[0]&65535,h[1]>>>16,h[1]&65535];var m=[0,0,0,0];return m[3]+=c[3]+h[3],m[2]+=m[3]>>>16,m[3]&=65535,m[2]+=c[2]+h[2],m[1]+=m[2]>>>16,m[2]&=65535,m[1]+=c[1]+h[1],m[0]+=m[1]>>>16,m[1]&=65535,m[0]+=c[0]+h[0],m[0]&=65535,[m[0]<<16|m[1],m[2]<<16|m[3]]}function u(c,h){c=[c[0]>>>16,c[0]&65535,c[1]>>>16,c[1]&65535],h=[h[0]>>>16,h[0]&65535,h[1]>>>16,h[1]&65535];var m=[0,0,0,0];return m[3]+=c[3]*h[3],m[2]+=m[3]>>>16,m[3]&=65535,m[2]+=c[2]*h[3],m[1]+=m[2]>>>16,m[2]&=65535,m[2]+=c[3]*h[2],m[1]+=m[2]>>>16,m[2]&=65535,m[1]+=c[1]*h[3],m[0]+=m[1]>>>16,m[1]&=65535,m[1]+=c[2]*h[2],m[0]+=m[1]>>>16,m[1]&=65535,m[1]+=c[3]*h[1],m[0]+=m[1]>>>16,m[1]&=65535,m[0]+=c[0]*h[3]+c[1]*h[2]+c[2]*h[1]+c[3]*h[0],m[0]&=65535,[m[0]<<16|m[1],m[2]<<16|m[3]]}function l(c,h){return h%=64,h===32?[c[1],c[0]]:h<32?[c[0]<<h|c[1]>>>32-h,c[1]<<h|c[0]>>>32-h]:(h-=32,[c[1]<<h|c[0]>>>32-h,c[0]<<h|c[1]>>>32-h])}function d(c,h){return h%=64,h===0?c:h<32?[c[0]<<h|c[1]>>>32-h,c[1]<<h]:[c[1]<<h-32,0]}function p(c,h){return[c[0]^h[0],c[1]^h[1]]}function _(c){return c=p(c,[0,c[0]>>>1]),c=u(c,[4283543511,3981806797]),c=p(c,[0,c[0]>>>1]),c=u(c,[3301882366,444984403]),c=p(c,[0,c[0]>>>1]),c}r.x86.hash32=function(c,h){if(r.inputValidation&&!n(c))return e;h=h||0;for(var m=c.length%4,A=c.length-m,g=h,w=0,b=3432918353,v=461845907,I=0;I<A;I=I+4)w=c[I]|c[I+1]<<8|c[I+2]<<16|c[I+3]<<24,w=o(w,b),w=i(w,15),w=o(w,v),g^=w,g=i(g,13),g=o(g,5)+3864292196;switch(w=0,m){case 3:w^=c[I+2]<<16;case 2:w^=c[I+1]<<8;case 1:w^=c[I],w=o(w,b),w=i(w,15),w=o(w,v),g^=w}return g^=c.length,g=s(g),g>>>0},r.x86.hash128=function(c,h){if(r.inputValidation&&!n(c))return e;h=h||0;for(var m=c.length%16,A=c.length-m,g=h,w=h,b=h,v=h,I=0,T=0,E=0,D=0,ue=597399067,Wt=2869860233,Jt=951274213,Qt=2716044179,S=0;S<A;S=S+16)I=c[S]|c[S+1]<<8|c[S+2]<<16|c[S+3]<<24,T=c[S+4]|c[S+5]<<8|c[S+6]<<16|c[S+7]<<24,E=c[S+8]|c[S+9]<<8|c[S+10]<<16|c[S+11]<<24,D=c[S+12]|c[S+13]<<8|c[S+14]<<16|c[S+15]<<24,I=o(I,ue),I=i(I,15),I=o(I,Wt),g^=I,g=i(g,19),g+=w,g=o(g,5)+1444728091,T=o(T,Wt),T=i(T,16),T=o(T,Jt),w^=T,w=i(w,17),w+=b,w=o(w,5)+197830471,E=o(E,Jt),E=i(E,17),E=o(E,Qt),b^=E,b=i(b,15),b+=v,b=o(b,5)+2530024501,D=o(D,Qt),D=i(D,18),D=o(D,ue),v^=D,v=i(v,13),v+=g,v=o(v,5)+850148119;switch(I=0,T=0,E=0,D=0,m){case 15:D^=c[S+14]<<16;case 14:D^=c[S+13]<<8;case 13:D^=c[S+12],D=o(D,Qt),D=i(D,18),D=o(D,ue),v^=D;case 12:E^=c[S+11]<<24;case 11:E^=c[S+10]<<16;case 10:E^=c[S+9]<<8;case 9:E^=c[S+8],E=o(E,Jt),E=i(E,17),E=o(E,Qt),b^=E;case 8:T^=c[S+7]<<24;case 7:T^=c[S+6]<<16;case 6:T^=c[S+5]<<8;case 5:T^=c[S+4],T=o(T,Wt),T=i(T,16),T=o(T,Jt),w^=T;case 4:I^=c[S+3]<<24;case 3:I^=c[S+2]<<16;case 2:I^=c[S+1]<<8;case 1:I^=c[S],I=o(I,ue),I=i(I,15),I=o(I,Wt),g^=I}return g^=c.length,w^=c.length,b^=c.length,v^=c.length,g+=w,g+=b,g+=v,w+=g,b+=g,v+=g,g=s(g),w=s(w),b=s(b),v=s(v),g+=w,g+=b,g+=v,w+=g,b+=g,v+=g,("00000000"+(g>>>0).toString(16)).slice(-8)+("00000000"+(w>>>0).toString(16)).slice(-8)+("00000000"+(b>>>0).toString(16)).slice(-8)+("00000000"+(v>>>0).toString(16)).slice(-8)},r.x64.hash128=function(c,h){if(r.inputValidation&&!n(c))return e;h=h||0;for(var m=c.length%16,A=c.length-m,g=[0,h],w=[0,h],b=[0,0],v=[0,0],I=[2277735313,289559509],T=[1291169091,658871167],E=0;E<A;E=E+16)b=[c[E+4]|c[E+5]<<8|c[E+6]<<16|c[E+7]<<24,c[E]|c[E+1]<<8|c[E+2]<<16|c[E+3]<<24],v=[c[E+12]|c[E+13]<<8|c[E+14]<<16|c[E+15]<<24,c[E+8]|c[E+9]<<8|c[E+10]<<16|c[E+11]<<24],b=u(b,I),b=l(b,31),b=u(b,T),g=p(g,b),g=l(g,27),g=a(g,w),g=a(u(g,[0,5]),[0,1390208809]),v=u(v,T),v=l(v,33),v=u(v,I),w=p(w,v),w=l(w,31),w=a(w,g),w=a(u(w,[0,5]),[0,944331445]);switch(b=[0,0],v=[0,0],m){case 15:v=p(v,d([0,c[E+14]],48));case 14:v=p(v,d([0,c[E+13]],40));case 13:v=p(v,d([0,c[E+12]],32));case 12:v=p(v,d([0,c[E+11]],24));case 11:v=p(v,d([0,c[E+10]],16));case 10:v=p(v,d([0,c[E+9]],8));case 9:v=p(v,[0,c[E+8]]),v=u(v,T),v=l(v,33),v=u(v,I),w=p(w,v);case 8:b=p(b,d([0,c[E+7]],56));case 7:b=p(b,d([0,c[E+6]],48));case 6:b=p(b,d([0,c[E+5]],40));case 5:b=p(b,d([0,c[E+4]],32));case 4:b=p(b,d([0,c[E+3]],24));case 3:b=p(b,d([0,c[E+2]],16));case 2:b=p(b,d([0,c[E+1]],8));case 1:b=p(b,[0,c[E]]),b=u(b,I),b=l(b,31),b=u(b,T),g=p(g,b)}return g=p(g,[0,c.length]),w=p(w,[0,c.length]),g=a(g,w),w=a(w,g),g=_(g),w=_(w),g=a(g,w),w=a(w,g),("00000000"+(g[0]>>>0).toString(16)).slice(-8)+("00000000"+(g[1]>>>0).toString(16)).slice(-8)+("00000000"+(w[0]>>>0).toString(16)).slice(-8)+("00000000"+(w[1]>>>0).toString(16)).slice(-8)},typeof qt<"u"?(typeof qr<"u"&&qr.exports&&(qt=qr.exports=r),qt.murmurHash3=r):typeof define=="function"&&define.amd?define([],function(){return r}):(r._murmurHash3=t.murmurHash3,r.noConflict=function(){return t.murmurHash3=r._murmurHash3,r._murmurHash3=e,r.noConflict=e,r},t.murmurHash3=r)})(qt)});var ya=fe((Pg,ma)=>{ma.exports=pa()});var ba=fe((Og,xa)=>{"use strict";xa.exports=class{constructor(){this._bitArrays=[],this._data=[],this._length=0,this._changedLength=!1,this._changedData=!1}set(e,r){let n=this._internalPositionFor(e,!1);if(r===void 0)n!==-1&&(this._unsetInternalPos(n),this._unsetBit(e),this._changedLength=!0,this._changedData=!0);else{let o=!1;n===-1?(n=this._data.length,this._setBit(e),this._changedData=!0):o=!0,this._setInternalPos(n,e,r,o),this._changedLength=!0}}unset(e){this.set(e,void 0)}get(e){this._sortData();let r=this._internalPositionFor(e,!0);if(r!==-1)return this._data[r][1]}push(e){return this.set(this.length,e),this.length}get length(){if(this._sortData(),this._changedLength){let e=this._data[this._data.length-1];this._length=e?e[0]+1:0,this._changedLength=!1}return this._length}forEach(e){let r=0;for(;r<this.length;)e(this.get(r),r,this),r++}map(e){let r=0,n=new Array(this.length);for(;r<this.length;)n[r]=e(this.get(r),r,this),r++;return n}reduce(e,r){let n=0,o=r;for(;n<this.length;){let i=this.get(n);o=e(o,i,n),n++}return o}find(e){let r=0,n,o;for(;r<this.length&&!n;)o=this.get(r),n=e(o),r++;return n?o:void 0}_internalPositionFor(e,r){let n=this._bytePosFor(e,r);if(n>=this._bitArrays.length)return-1;let o=this._bitArrays[n],i=e-n*7;if(!((o&1<<i)>0))return-1;let a=this._bitArrays.slice(0,n).reduce(ll,0),u=~(4294967295<<i+1),l=wa(o&u);return a+l-1}_bytePosFor(e,r){let n=Math.floor(e/7),o=n+1;for(;!r&&this._bitArrays.length<o;)this._bitArrays.push(0);return n}_setBit(e){let r=this._bytePosFor(e,!1);this._bitArrays[r]|=1<<e-r*7}_unsetBit(e){let r=this._bytePosFor(e,!1);this._bitArrays[r]&=~(1<<e-r*7)}_setInternalPos(e,r,n,o){let i=this._data,s=[r,n];if(o)this._sortData(),i[e]=s;else{if(i.length)if(i[i.length-1][0]>=r)i.push(s);else if(i[0][0]<=r)i.unshift(s);else{let a=Math.round(i.length/2);this._data=i.slice(0,a).concat(s).concat(i.slice(a))}else this._data.push(s);this._changedData=!0,this._changedLength=!0}}_unsetInternalPos(e){this._data.splice(e,1)}_sortData(){this._changedData&&this._data.sort(hl),this._changedData=!1}bitField(){let e=[],r=8,n=0,o=0,i,s=this._bitArrays.slice();for(;s.length||n;){n===0&&(i=s.shift(),n=7);let u=Math.min(n,r),l=~(255<<u),d=i&l;o|=d<<8-r,i=i>>>u,n-=u,r-=u,(!r||!n&&!s.length)&&(e.push(o),o=0,r=8)}for(var a=e.length-1;a>0&&e[a]===0;a--)e.pop();return e}compactArray(){return this._sortData(),this._data.map(dl)}};function ll(t,e){return t+wa(e)}function wa(t){let e=t;return e=e-(e>>1&1431655765),e=(e&858993459)+(e>>2&858993459),(e+(e>>4)&252645135)*16843009>>24}function hl(t,e){return t[0]-e[0]}function dl(t){return t[1]}});var Nl={};q(Nl,{BlockExporter:()=>No,CIDPath:()=>Lo,GraphSearch:()=>Do,SubgraphExporter:()=>$t,UnixFSExporter:()=>Ot,UnixFSPath:()=>zo,breadthFirstWalker:()=>Ce,car:()=>Cl,depthFirstWalker:()=>Be,naturalOrderWalker:()=>Co});var Wa=["string","number","bigint","symbol"],Ja=["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 $o(t){if(t===null)return"null";if(t===void 0)return"undefined";if(t===!0||t===!1)return"boolean";let e=typeof t;if(Wa.includes(e))return e;if(e==="function")return"Function";if(Array.isArray(t))return"Array";if(Qa(t))return"Buffer";let r=Xa(t);return r||"Object"}function Qa(t){return t&&t.constructor&&t.constructor.isBuffer&&t.constructor.isBuffer.call(null,t)}function Xa(t){let e=Object.prototype.toString.call(t).slice(8,-1);if(Ja.includes(e))return e}var f=class{constructor(e,r,n){this.major=e,this.majorEncoded=e<<5,this.name=r,this.terminal=n}toString(){return`Type[${this.major}].${this.name}`}compare(e){return this.major<e.major?-1:this.major>e.major?1:0}};f.uint=new f(0,"uint",!0);f.negint=new f(1,"negint",!0);f.bytes=new f(2,"bytes",!0);f.string=new f(3,"string",!0);f.array=new f(4,"array",!1);f.map=new f(5,"map",!1);f.tag=new f(6,"tag",!1);f.float=new f(7,"float",!0);f.false=new f(7,"false",!0);f.true=new f(7,"true",!0);f.null=new f(7,"null",!0);f.undefined=new f(7,"undefined",!0);f.break=new f(7,"break",!0);var y=class{constructor(e,r,n){this.type=e,this.value=r,this.encodedLength=n,this.encodedBytes=void 0,this.byteValue=void 0}toString(){return`Token[${this.type}].${this.value}`}};var De=globalThis.process&&!globalThis.process.browser&&globalThis.Buffer&&typeof globalThis.Buffer.isBuffer=="function",Ya=new TextDecoder,Ka=new TextEncoder;function Yt(t){return De&&globalThis.Buffer.isBuffer(t)}function ct(t){return t instanceof Uint8Array?Yt(t)?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):t:Uint8Array.from(t)}var qo=De?(t,e,r)=>r-e>64?globalThis.Buffer.from(t.subarray(e,r)).toString("utf8"):Ho(t,e,r):(t,e,r)=>r-e>64?Ya.decode(t.subarray(e,r)):Ho(t,e,r),Kt=De?t=>t.length>64?globalThis.Buffer.from(t):Oo(t):t=>t.length>64?Ka.encode(t):Oo(t),ne=t=>Uint8Array.from(t),Le=De?(t,e,r)=>Yt(t)?new Uint8Array(t.subarray(e,r)):t.slice(e,r):(t,e,r)=>t.slice(e,r),jo=De?(t,e)=>(t=t.map(r=>r instanceof Uint8Array?r:globalThis.Buffer.from(r)),ct(globalThis.Buffer.concat(t,e))):(t,e)=>{let r=new Uint8Array(e),n=0;for(let o of t)n+o.length>r.length&&(o=o.subarray(0,r.length-n)),r.set(o,n),n+=o.length;return r},Go=De?t=>globalThis.Buffer.allocUnsafe(t):t=>new Uint8Array(t);function Zt(t,e){if(Yt(t)&&Yt(e))return t.compare(e);for(let r=0;r<t.length;r++)if(t[r]!==e[r])return t[r]<e[r]?-1:1;return 0}function Oo(t){let e=[],r=0;for(let n=0;n<t.length;n++){let o=t.charCodeAt(n);o<128?e[r++]=o:o<2048?(e[r++]=o>>6|192,e[r++]=o&63|128):(o&64512)===55296&&n+1<t.length&&(t.charCodeAt(n+1)&64512)===56320?(o=65536+((o&1023)<<10)+(t.charCodeAt(++n)&1023),e[r++]=o>>18|240,e[r++]=o>>12&63|128,e[r++]=o>>6&63|128,e[r++]=o&63|128):(e[r++]=o>>12|224,e[r++]=o>>6&63|128,e[r++]=o&63|128)}return e}function Ho(t,e,r){let n=[];for(;e<r;){let o=t[e],i=null,s=o>239?4:o>223?3:o>191?2:1;if(e+s<=r){let a,u,l,d;switch(s){case 1:o<128&&(i=o);break;case 2:a=t[e+1],(a&192)===128&&(d=(o&31)<<6|a&63,d>127&&(i=d));break;case 3:a=t[e+1],u=t[e+2],(a&192)===128&&(u&192)===128&&(d=(o&15)<<12|(a&63)<<6|u&63,d>2047&&(d<55296||d>57343)&&(i=d));break;case 4:a=t[e+1],u=t[e+2],l=t[e+3],(a&192)===128&&(u&192)===128&&(l&192)===128&&(d=(o&15)<<18|(a&63)<<12|(u&63)<<6|l&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 Kr(n)}var Vo=4096;function Kr(t){let e=t.length;if(e<=Vo)return String.fromCharCode.apply(String,t);let r="",n=0;for(;n<e;)r+=String.fromCharCode.apply(String,t.slice(n,n+=Vo));return r}var Za=256,ut=class{constructor(e=Za){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 r=this.chunks[this.chunks.length-1];if(this.cursor+e.length<=this.maxCursor+1){let o=r.length-(this.maxCursor-this.cursor)-1;r.set(e,o)}else{if(r){let o=r.length-(this.maxCursor-this.cursor)-1;o<r.length&&(this.chunks[this.chunks.length-1]=r.subarray(0,o),this.maxCursor=this.cursor-1)}e.length<64&&e.length<this.chunkSize?(r=Go(this.chunkSize),this.chunks.push(r),this.maxCursor+=r.length,this._initReuseChunk===null&&(this._initReuseChunk=r),r.set(e,0)):(this.chunks.push(e),this.maxCursor+=e.length)}this.cursor+=e.length}toBytes(e=!1){let r;if(this.chunks.length===1){let n=this.chunks[0];e&&this.cursor>n.length/2?(r=this.cursor===n.length?n:n.subarray(0,this.cursor),this._initReuseChunk=null,this.chunks=[]):r=Le(n,0,this.cursor)}else r=jo(this.chunks,this.cursor);return e&&this.reset(),r}};var k="CBOR decode error:",Pe="CBOR encode error:",ft=[];ft[23]=1;ft[24]=2;ft[25]=3;ft[26]=5;ft[27]=9;function le(t,e,r){if(t.length-e<r)throw new Error(`${k} not enough data for type`)}var U=[24,256,65536,4294967296,BigInt("18446744073709551616")];function j(t,e,r){le(t,e,1);let n=t[e];if(r.strict===!0&&n<U[0])throw new Error(`${k} integer encoded in more bytes than necessary (strict decode)`);return n}function G(t,e,r){le(t,e,2);let n=t[e]<<8|t[e+1];if(r.strict===!0&&n<U[1])throw new Error(`${k} integer encoded in more bytes than necessary (strict decode)`);return n}function W(t,e,r){le(t,e,4);let n=t[e]*16777216+(t[e+1]<<16)+(t[e+2]<<8)+t[e+3];if(r.strict===!0&&n<U[2])throw new Error(`${k} integer encoded in more bytes than necessary (strict decode)`);return n}function J(t,e,r){le(t,e,8);let n=t[e]*16777216+(t[e+1]<<16)+(t[e+2]<<8)+t[e+3],o=t[e+4]*16777216+(t[e+5]<<16)+(t[e+6]<<8)+t[e+7],i=(BigInt(n)<<BigInt(32))+BigInt(o);if(r.strict===!0&&i<U[3])throw new Error(`${k} integer encoded in more bytes than necessary (strict decode)`);if(i<=Number.MAX_SAFE_INTEGER)return Number(i);if(r.allowBigInt===!0)return i;throw new Error(`${k} integers outside of the safe integer range are not supported`)}function Wo(t,e,r,n){return new y(f.uint,j(t,e+1,n),2)}function Jo(t,e,r,n){return new y(f.uint,G(t,e+1,n),3)}function Qo(t,e,r,n){return new y(f.uint,W(t,e+1,n),5)}function Xo(t,e,r,n){return new y(f.uint,J(t,e+1,n),9)}function Y(t,e){return R(t,0,e.value)}function R(t,e,r){if(r<U[0]){let n=Number(r);t.push([e|n])}else if(r<U[1]){let n=Number(r);t.push([e|24,n])}else if(r<U[2]){let n=Number(r);t.push([e|25,n>>>8,n&255])}else if(r<U[3]){let n=Number(r);t.push([e|26,n>>>24&255,n>>>16&255,n>>>8&255,n&255])}else{let n=BigInt(r);if(n<U[4]){let o=[e|27,0,0,0,0,0,0,0],i=Number(n&BigInt(4294967295)),s=Number(n>>BigInt(32)&BigInt(4294967295));o[8]=i&255,i=i>>8,o[7]=i&255,i=i>>8,o[6]=i&255,i=i>>8,o[5]=i&255,o[4]=s&255,s=s>>8,o[3]=s&255,s=s>>8,o[2]=s&255,s=s>>8,o[1]=s&255,t.push(o)}else throw new Error(`${k} encountered BigInt larger than allowable range`)}}Y.encodedSize=function(e){return R.encodedSize(e.value)};R.encodedSize=function(e){return e<U[0]?1:e<U[1]?2:e<U[2]?3:e<U[3]?5:9};Y.compareTokens=function(e,r){return e.value<r.value?-1:e.value>r.value?1:0};function Yo(t,e,r,n){return new y(f.negint,-1-j(t,e+1,n),2)}function Ko(t,e,r,n){return new y(f.negint,-1-G(t,e+1,n),3)}function Zo(t,e,r,n){return new y(f.negint,-1-W(t,e+1,n),5)}var Zr=BigInt(-1),ei=BigInt(1);function ti(t,e,r,n){let o=J(t,e+1,n);if(typeof o!="bigint"){let i=-1-o;if(i>=Number.MIN_SAFE_INTEGER)return new y(f.negint,i,9)}if(n.allowBigInt!==!0)throw new Error(`${k} integers outside of the safe integer range are not supported`);return new y(f.negint,Zr-BigInt(o),9)}function er(t,e){let r=e.value,n=typeof r=="bigint"?r*Zr-ei:r*-1-1;R(t,e.type.majorEncoded,n)}er.encodedSize=function(e){let r=e.value,n=typeof r=="bigint"?r*Zr-ei:r*-1-1;return n<U[0]?1:n<U[1]?2:n<U[2]?3:n<U[3]?5:9};er.compareTokens=function(e,r){return e.value<r.value?1:e.value>r.value?-1:0};function lt(t,e,r,n){le(t,e,r+n);let o=Le(t,e+r,e+r+n);return new y(f.bytes,o,r+n)}function ri(t,e,r,n){return lt(t,e,1,r)}function ni(t,e,r,n){return lt(t,e,2,j(t,e+1,n))}function oi(t,e,r,n){return lt(t,e,3,G(t,e+1,n))}function ii(t,e,r,n){return lt(t,e,5,W(t,e+1,n))}function si(t,e,r,n){let o=J(t,e+1,n);if(typeof o=="bigint")throw new Error(`${k} 64-bit integer bytes lengths not supported`);return lt(t,e,9,o)}function tr(t){return t.encodedBytes===void 0&&(t.encodedBytes=t.type===f.string?Kt(t.value):t.value),t.encodedBytes}function Ue(t,e){let r=tr(e);R(t,e.type.majorEncoded,r.length),t.push(r)}Ue.encodedSize=function(e){let r=tr(e);return R.encodedSize(r.length)+r.length};Ue.compareTokens=function(e,r){return tc(tr(e),tr(r))};function tc(t,e){return t.length<e.length?-1:t.length>e.length?1:Zt(t,e)}function ht(t,e,r,n,o){let i=r+n;le(t,e,i);let s=new y(f.string,qo(t,e+r,e+i),i);return o.retainStringBytes===!0&&(s.byteValue=Le(t,e+r,e+i)),s}function ai(t,e,r,n){return ht(t,e,1,r,n)}function ci(t,e,r,n){return ht(t,e,2,j(t,e+1,n),n)}function ui(t,e,r,n){return ht(t,e,3,G(t,e+1,n),n)}function fi(t,e,r,n){return ht(t,e,5,W(t,e+1,n),n)}function li(t,e,r,n){let o=J(t,e+1,n);if(typeof o=="bigint")throw new Error(`${k} 64-bit integer string lengths not supported`);return ht(t,e,9,o,n)}var hi=Ue;function Re(t,e,r,n){return new y(f.array,n,r)}function di(t,e,r,n){return Re(t,e,1,r)}function pi(t,e,r,n){return Re(t,e,2,j(t,e+1,n))}function mi(t,e,r,n){return Re(t,e,3,G(t,e+1,n))}function yi(t,e,r,n){return Re(t,e,5,W(t,e+1,n))}function gi(t,e,r,n){let o=J(t,e+1,n);if(typeof o=="bigint")throw new Error(`${k} 64-bit integer array lengths not supported`);return Re(t,e,9,o)}function wi(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${k} indefinite length items not allowed`);return Re(t,e,1,1/0)}function rr(t,e){R(t,f.array.majorEncoded,e.value)}rr.compareTokens=Y.compareTokens;rr.encodedSize=function(e){return R.encodedSize(e.value)};function Fe(t,e,r,n){return new y(f.map,n,r)}function xi(t,e,r,n){return Fe(t,e,1,r)}function bi(t,e,r,n){return Fe(t,e,2,j(t,e+1,n))}function Ei(t,e,r,n){return Fe(t,e,3,G(t,e+1,n))}function vi(t,e,r,n){return Fe(t,e,5,W(t,e+1,n))}function ki(t,e,r,n){let o=J(t,e+1,n);if(typeof o=="bigint")throw new Error(`${k} 64-bit integer map lengths not supported`);return Fe(t,e,9,o)}function _i(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${k} indefinite length items not allowed`);return Fe(t,e,1,1/0)}function nr(t,e){R(t,f.map.majorEncoded,e.value)}nr.compareTokens=Y.compareTokens;nr.encodedSize=function(e){return R.encodedSize(e.value)};function Ii(t,e,r,n){return new y(f.tag,r,1)}function Ai(t,e,r,n){return new y(f.tag,j(t,e+1,n),2)}function Ti(t,e,r,n){return new y(f.tag,G(t,e+1,n),3)}function Si(t,e,r,n){return new y(f.tag,W(t,e+1,n),5)}function Bi(t,e,r,n){return new y(f.tag,J(t,e+1,n),9)}function or(t,e){R(t,f.tag.majorEncoded,e.value)}or.compareTokens=Y.compareTokens;or.encodedSize=function(e){return R.encodedSize(e.value)};var ac=20,cc=21,uc=22,fc=23;function Ci(t,e,r,n){if(n.allowUndefined===!1)throw new Error(`${k} undefined values are not supported`);return n.coerceUndefinedToNull===!0?new y(f.null,null,1):new y(f.undefined,void 0,1)}function Ni(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${k} indefinite length items not allowed`);return new y(f.break,void 0,1)}function en(t,e,r){if(r){if(r.allowNaN===!1&&Number.isNaN(t))throw new Error(`${k} NaN values are not supported`);if(r.allowInfinity===!1&&(t===1/0||t===-1/0))throw new Error(`${k} Infinity values are not supported`)}return new y(f.float,t,e)}function Di(t,e,r,n){return en(tn(t,e+1),3,n)}function Li(t,e,r,n){return en(rn(t,e+1),5,n)}function Pi(t,e,r,n){return en(zi(t,e+1),9,n)}function ir(t,e,r){let n=e.value;if(n===!1)t.push([f.float.majorEncoded|ac]);else if(n===!0)t.push([f.float.majorEncoded|cc]);else if(n===null)t.push([f.float.majorEncoded|uc]);else if(n===void 0)t.push([f.float.majorEncoded|fc]);else{let o,i=!1;(!r||r.float64!==!0)&&(Ri(n),o=tn(Z,1),n===o||Number.isNaN(n)?(Z[0]=249,t.push(Z.slice(0,3)),i=!0):(Fi(n),o=rn(Z,1),n===o&&(Z[0]=250,t.push(Z.slice(0,5)),i=!0))),i||(lc(n),o=zi(Z,1),Z[0]=251,t.push(Z.slice(0,9)))}}ir.encodedSize=function(e,r){let n=e.value;if(n===!1||n===!0||n===null||n===void 0)return 1;if(!r||r.float64!==!0){Ri(n);let o=tn(Z,1);if(n===o||Number.isNaN(n))return 3;if(Fi(n),o=rn(Z,1),n===o)return 5}return 9};var Ui=new ArrayBuffer(9),K=new DataView(Ui,1),Z=new Uint8Array(Ui,0);function Ri(t){if(t===1/0)K.setUint16(0,31744,!1);else if(t===-1/0)K.setUint16(0,64512,!1);else if(Number.isNaN(t))K.setUint16(0,32256,!1);else{K.setFloat32(0,t);let e=K.getUint32(0),r=(e&2139095040)>>23,n=e&8388607;if(r===255)K.setUint16(0,31744,!1);else if(r===0)K.setUint16(0,(t&2147483648)>>16|n>>13,!1);else{let o=r-127;o<-24?K.setUint16(0,0):o<-14?K.setUint16(0,(e&2147483648)>>16|1<<24+o,!1):K.setUint16(0,(e&2147483648)>>16|o+15<<10|n>>13,!1)}}}function tn(t,e){if(t.length-e<2)throw new Error(`${k} not enough data for float16`);let r=(t[e]<<8)+t[e+1];if(r===31744)return 1/0;if(r===64512)return-1/0;if(r===32256)return NaN;let n=r>>10&31,o=r&1023,i;return n===0?i=o*2**-24:n!==31?i=(o+1024)*2**(n-25):i=o===0?1/0:NaN,r&32768?-i:i}function Fi(t){K.setFloat32(0,t,!1)}function rn(t,e){if(t.length-e<4)throw new Error(`${k} not enough data for float32`);let r=(t.byteOffset||0)+e;return new DataView(t.buffer,r,4).getFloat32(0,!1)}function lc(t){K.setFloat64(0,t,!1)}function zi(t,e){if(t.length-e<8)throw new Error(`${k} not enough data for float64`);let r=(t.byteOffset||0)+e;return new DataView(t.buffer,r,8).getFloat64(0,!1)}ir.compareTokens=Y.compareTokens;function C(t,e,r){throw new Error(`${k} encountered invalid minor (${r}) for major ${t[e]>>>5}`)}function sr(t){return()=>{throw new Error(`${k} ${t}`)}}var x=[];for(let t=0;t<=23;t++)x[t]=C;x[24]=Wo;x[25]=Jo;x[26]=Qo;x[27]=Xo;x[28]=C;x[29]=C;x[30]=C;x[31]=C;for(let t=32;t<=55;t++)x[t]=C;x[56]=Yo;x[57]=Ko;x[58]=Zo;x[59]=ti;x[60]=C;x[61]=C;x[62]=C;x[63]=C;for(let t=64;t<=87;t++)x[t]=ri;x[88]=ni;x[89]=oi;x[90]=ii;x[91]=si;x[92]=C;x[93]=C;x[94]=C;x[95]=sr("indefinite length bytes/strings are not supported");for(let t=96;t<=119;t++)x[t]=ai;x[120]=ci;x[121]=ui;x[122]=fi;x[123]=li;x[124]=C;x[125]=C;x[126]=C;x[127]=sr("indefinite length bytes/strings are not supported");for(let t=128;t<=151;t++)x[t]=di;x[152]=pi;x[153]=mi;x[154]=yi;x[155]=gi;x[156]=C;x[157]=C;x[158]=C;x[159]=wi;for(let t=160;t<=183;t++)x[t]=xi;x[184]=bi;x[185]=Ei;x[186]=vi;x[187]=ki;x[188]=C;x[189]=C;x[190]=C;x[191]=_i;for(let t=192;t<=215;t++)x[t]=Ii;x[216]=Ai;x[217]=Ti;x[218]=Si;x[219]=Bi;x[220]=C;x[221]=C;x[222]=C;x[223]=C;for(let t=224;t<=243;t++)x[t]=sr("simple values are not supported");x[244]=C;x[245]=C;x[246]=C;x[247]=Ci;x[248]=sr("simple values are not supported");x[249]=Di;x[250]=Li;x[251]=Pi;x[252]=C;x[253]=C;x[254]=C;x[255]=Ni;var ee=[];for(let t=0;t<24;t++)ee[t]=new y(f.uint,t,1);for(let t=-1;t>=-24;t--)ee[31-t]=new y(f.negint,t,1);ee[64]=new y(f.bytes,new Uint8Array(0),1);ee[96]=new y(f.string,"",1);ee[128]=new y(f.array,0,1);ee[160]=new y(f.map,0,1);ee[244]=new y(f.false,!1,1);ee[245]=new y(f.true,!0,1);ee[246]=new y(f.null,null,1);function ar(t){switch(t.type){case f.false:return ne([244]);case f.true:return ne([245]);case f.null:return ne([246]);case f.bytes:return t.value.length?void 0:ne([64]);case f.string:return t.value===""?ne([96]):void 0;case f.array:return t.value===0?ne([128]):void 0;case f.map:return t.value===0?ne([160]):void 0;case f.uint:return t.value<24?ne([Number(t.value)]):void 0;case f.negint:if(t.value>=-24)return ne([31-Number(t.value)])}}var dc={float64:!1,mapSorter:mc,quickEncodeToken:ar},$i=Object.freeze({float64:!0,mapSorter:yc,quickEncodeToken:ar});function on(){let t=[];return t[f.uint.major]=Y,t[f.negint.major]=er,t[f.bytes.major]=Ue,t[f.string.major]=hi,t[f.array.major]=rr,t[f.map.major]=nr,t[f.tag.major]=or,t[f.float.major]=ir,t}var sn=on(),nn=new ut,cr=class t{constructor(e,r){this.obj=e,this.parent=r}includes(e){let r=this;do if(r.obj===e)return!0;while(r=r.parent);return!1}static createCheck(e,r){if(e&&e.includes(r))throw new Error(`${Pe} object contains circular references`);return new t(r,e)}},pe={null:new y(f.null,null),undefined:new y(f.undefined,void 0),true:new y(f.true,!0),false:new y(f.false,!1),emptyArray:new y(f.array,0),emptyMap:new y(f.map,0)},me={number(t,e,r,n){return!Number.isInteger(t)||!Number.isSafeInteger(t)?new y(f.float,t):t>=0?new y(f.uint,t):new y(f.negint,t)},bigint(t,e,r,n){return t>=BigInt(0)?new y(f.uint,t):new y(f.negint,t)},Uint8Array(t,e,r,n){return new y(f.bytes,t)},string(t,e,r,n){return new y(f.string,t)},boolean(t,e,r,n){return t?pe.true:pe.false},null(t,e,r,n){return pe.null},undefined(t,e,r,n){return pe.undefined},ArrayBuffer(t,e,r,n){return new y(f.bytes,new Uint8Array(t))},DataView(t,e,r,n){return new y(f.bytes,new Uint8Array(t.buffer,t.byteOffset,t.byteLength))},Array(t,e,r,n){if(!t.length)return r.addBreakTokens===!0?[pe.emptyArray,new y(f.break)]:pe.emptyArray;n=cr.createCheck(n,t);let o=[],i=0;for(let s of t)o[i++]=dt(s,r,n);return r.addBreakTokens?[new y(f.array,t.length),o,new y(f.break)]:[new y(f.array,t.length),o]},Object(t,e,r,n){let o=e!=="Object",i=o?t.keys():Object.keys(t),s=o?t.size:i.length;if(!s)return r.addBreakTokens===!0?[pe.emptyMap,new y(f.break)]:pe.emptyMap;n=cr.createCheck(n,t);let a=[],u=0;for(let l of i)a[u++]=[dt(l,r,n),dt(o?t.get(l):t[l],r,n)];return pc(a,r),r.addBreakTokens?[new y(f.map,s),a,new y(f.break)]:[new y(f.map,s),a]}};me.Map=me.Object;me.Buffer=me.Uint8Array;for(let t of"Uint8Clamped Uint16 Uint32 Int8 Int16 Int32 BigUint64 BigInt64 Float32 Float64".split(" "))me[`${t}Array`]=me.DataView;function dt(t,e={},r){let n=$o(t),o=e&&e.typeEncoders&&e.typeEncoders[n]||me[n];if(typeof o=="function"){let s=o(t,n,e,r);if(s!=null)return s}let i=me[n];if(!i)throw new Error(`${Pe} unsupported type: ${n}`);return i(t,n,e,r)}function pc(t,e){e.mapSorter&&t.sort(e.mapSorter)}function mc(t,e){let r=Array.isArray(t[0])?t[0][0]:t[0],n=Array.isArray(e[0])?e[0][0]:e[0];if(r.type!==n.type)return r.type.compare(n.type);let o=r.type.major,i=sn[o].compareTokens(r,n);return i===0&&console.warn("WARNING: complex key types used, CBOR key sorting guarantees are gone"),i}function yc(t,e){if(t[0]instanceof y&&e[0]instanceof y){let r=t[0],n=e[0];return r._keyBytes||(r._keyBytes=Mi(r.value)),n._keyBytes||(n._keyBytes=Mi(n.value)),Zt(r._keyBytes,n._keyBytes)}throw new Error("rfc8949MapSorter: complex key types are not supported yet")}function Mi(t){return an(t,sn,$i)}function Oi(t,e,r,n){if(Array.isArray(e))for(let o of e)Oi(t,o,r,n);else r[e.type.major](t,e,n)}function an(t,e,r){let n=dt(t,r);if(!Array.isArray(n)&&r.quickEncodeToken){let o=r.quickEncodeToken(n);if(o)return o;let i=e[n.type.major];if(i.encodedSize){let s=i.encodedSize(n,r),a=new ut(s);if(i(a,n,r),a.chunks.length!==1)throw new Error(`Unexpected error: pre-calculated length for ${n} was wrong`);return ct(a.chunks[0])}}return nn.reset(),Oi(nn,n,e,r),nn.toBytes(!0)}function cn(t,e){return e=Object.assign({},dc,e),an(t,sn,e)}var gc={strict:!1,allowIndefinite:!0,allowUndefined:!0,allowBigInt:!0},ur=class{constructor(e,r={}){this._pos=0,this.data=e,this.options=r}pos(){return this._pos}done(){return this._pos>=this.data.length}next(){let e=this.data[this._pos],r=ee[e];if(r===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;r=n(this.data,this._pos,o,this.options)}return this._pos+=r.encodedLength,r}},pt=Symbol.for("DONE"),fr=Symbol.for("BREAK");function wc(t,e,r){let n=[];for(let o=0;o<t.value;o++){let i=ze(e,r);if(i===fr){if(t.value===1/0)break;throw new Error(`${k} got unexpected break to lengthed array`)}if(i===pt)throw new Error(`${k} found array but not enough entries (got ${o}, expected ${t.value})`);n[o]=i}return n}function xc(t,e,r){let n=r.useMaps===!0,o=n?void 0:{},i=n?new Map:void 0;for(let s=0;s<t.value;s++){let a=ze(e,r);if(a===fr){if(t.value===1/0)break;throw new Error(`${k} got unexpected break to lengthed map`)}if(a===pt)throw new Error(`${k} found map but not enough entries (got ${s} [no key], expected ${t.value})`);if(n!==!0&&typeof a!="string")throw new Error(`${k} non-string keys not supported (got ${typeof a})`);if(r.rejectDuplicateMapKeys===!0&&(n&&i.has(a)||!n&&a in o))throw new Error(`${k} found repeat map key "${a}"`);let u=ze(e,r);if(u===pt)throw new Error(`${k} found map but not enough entries (got ${s} [no value], expected ${t.value})`);n?i.set(a,u):o[a]=u}return n?i:o}function ze(t,e){if(t.done())return pt;let r=t.next();if(r.type===f.break)return fr;if(r.type.terminal)return r.value;if(r.type===f.array)return wc(r,t,e);if(r.type===f.map)return xc(r,t,e);if(r.type===f.tag){if(e.tags&&typeof e.tags[r.value]=="function"){let n=ze(t,e);return e.tags[r.value](n)}throw new Error(`${k} tag not supported (${r.value})`)}throw new Error("unsupported")}function un(t,e){if(!(t instanceof Uint8Array))throw new Error(`${k} data to decode must be a Uint8Array`);e=Object.assign({},gc,e);let r=e.tokenizer||new ur(t,e),n=ze(r,e);if(n===pt)throw new Error(`${k} did not find any content to decode`);if(n===fr)throw new Error(`${k} got unexpected break`);return[n,t.subarray(r.pos())]}function mt(t,e){let[r,n]=un(t,e);if(n.length>0)throw new Error(`${k} too many terminals, data makes no sense`);return r}var gn={};q(gn,{base32:()=>$e,base32hex:()=>Lc,base32hexpad:()=>Uc,base32hexpadupper:()=>Rc,base32hexupper:()=>Pc,base32pad:()=>Nc,base32padupper:()=>Dc,base32upper:()=>Cc,base32z:()=>Fc});var ke={};q(ke,{coerce:()=>oe,empty:()=>Hi,equals:()=>fn,fromHex:()=>vc,fromString:()=>ln,isBinary:()=>kc,toHex:()=>Ec,toString:()=>hn});var Hi=new Uint8Array(0);function Ec(t){return t.reduce((e,r)=>e+r.toString(16).padStart(2,"0"),"")}function vc(t){let e=t.match(/../g);return e!=null?new Uint8Array(e.map(r=>parseInt(r,16))):Hi}function fn(t,e){if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;for(let r=0;r<t.byteLength;r++)if(t[r]!==e[r])return!1;return!0}function oe(t){if(t instanceof Uint8Array&&t.constructor.name==="Uint8Array")return t;if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.isView(t))return new Uint8Array(t.buffer,t.byteOffset,t.byteLength);throw new Error("Unknown type, must be binary type")}function kc(t){return t instanceof ArrayBuffer||ArrayBuffer.isView(t)}function ln(t){return new TextEncoder().encode(t)}function hn(t){return new TextDecoder().decode(t)}function _c(t,e){if(t.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),n=0;n<r.length;n++)r[n]=255;for(var o=0;o<t.length;o++){var i=t.charAt(o),s=i.charCodeAt(0);if(r[s]!==255)throw new TypeError(i+" is ambiguous");r[s]=o}var a=t.length,u=t.charAt(0),l=Math.log(a)/Math.log(256),d=Math.log(256)/Math.log(a);function p(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,g=0,w=h.length;g!==w&&h[g]===0;)g++,m++;for(var b=(w-g)*d+1>>>0,v=new Uint8Array(b);g!==w;){for(var I=h[g],T=0,E=b-1;(I!==0||T<A)&&E!==-1;E--,T++)I+=256*v[E]>>>0,v[E]=I%a>>>0,I=I/a>>>0;if(I!==0)throw new Error("Non-zero carry");A=T,g++}for(var D=b-A;D!==b&&v[D]===0;)D++;for(var ue=u.repeat(m);D<b;++D)ue+=t.charAt(v[D]);return ue}function _(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,g=0;h[m]===u;)A++,m++;for(var w=(h.length-m)*l+1>>>0,b=new Uint8Array(w);h[m];){var v=r[h.charCodeAt(m)];if(v===255)return;for(var I=0,T=w-1;(v!==0||I<g)&&T!==-1;T--,I++)v+=a*b[T]>>>0,b[T]=v%256>>>0,v=v/256>>>0;if(v!==0)throw new Error("Non-zero carry");g=I,m++}if(h[m]!==" "){for(var E=w-g;E!==w&&b[E]===0;)E++;for(var D=new Uint8Array(A+(w-E)),ue=A;E!==w;)D[ue++]=b[E++];return D}}}function c(h){var m=_(h);if(m)return m;throw new Error(`Non-${e} character`)}return{encode:p,decodeUnsafe:_,decode:c}}var Ic=_c,Ac=Ic,Vi=Ac;var dn=class{name;prefix;baseEncode;constructor(e,r,n){this.name=e,this.prefix=r,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},pn=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,r,n){this.name=e,this.prefix=r;let o=r.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 qi(this,e)}},mn=class{decoders;constructor(e){this.decoders=e}or(e){return qi(this,e)}decode(e){let r=e[0],n=this.decoders[r];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 qi(t,e){return new mn({...t.decoders??{[t.prefix]:t},...e.decoders??{[e.prefix]:e}})}var yn=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,r,n,o){this.name=e,this.prefix=r,this.baseEncode=n,this.baseDecode=o,this.encoder=new dn(e,r,n),this.decoder=new pn(e,r,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function Me({name:t,prefix:e,encode:r,decode:n}){return new yn(t,e,r,n)}function ye({name:t,prefix:e,alphabet:r}){let{encode:n,decode:o}=Vi(r,t);return Me({prefix:e,name:t,encode:n,decode:i=>oe(o(i))})}function Tc(t,e,r,n){let o=t.length;for(;t[o-1]==="=";)--o;let i=new Uint8Array(o*r/8|0),s=0,a=0,u=0;for(let l=0;l<o;++l){let d=e[t[l]];if(d===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|d,s+=r,s>=8&&(s-=8,i[u++]=255&a>>s)}if(s>=r||(255&a<<8-s)!==0)throw new SyntaxError("Unexpected end of data");return i}function Sc(t,e,r){let n=e[e.length-1]==="=",o=(1<<r)-1,i="",s=0,a=0;for(let u=0;u<t.length;++u)for(a=a<<8|t[u],s+=8;s>r;)s-=r,i+=e[o&a>>s];if(s!==0&&(i+=e[o&a<<r-s]),n)for(;(i.length*r&7)!==0;)i+="=";return i}function Bc(t){let e={};for(let r=0;r<t.length;++r)e[t[r]]=r;return e}function P({name:t,prefix:e,bitsPerChar:r,alphabet:n}){let o=Bc(n);return Me({prefix:e,name:t,encode(i){return Sc(i,n,r)},decode(i){return Tc(i,o,r,t)}})}var $e=P({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Cc=P({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Nc=P({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Dc=P({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Lc=P({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Pc=P({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Uc=P({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Rc=P({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Fc=P({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var wn={};q(wn,{base36:()=>yt,base36upper:()=>zc});var yt=ye({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),zc=ye({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var xn={};q(xn,{base58btc:()=>ie,base58flickr:()=>Mc});var ie=ye({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Mc=ye({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var $c=Wi,ji=128,Oc=127,Hc=~Oc,Vc=Math.pow(2,31);function Wi(t,e,r){e=e||[],r=r||0;for(var n=r;t>=Vc;)e[r++]=t&255|ji,t/=128;for(;t&Hc;)e[r++]=t&255|ji,t>>>=7;return e[r]=t|0,Wi.bytes=r-n+1,e}var qc=bn,jc=128,Gi=127;function bn(t,n){var r=0,n=n||0,o=0,i=n,s,a=t.length;do{if(i>=a)throw bn.bytes=0,new RangeError("Could not decode varint");s=t[i++],r+=o<28?(s&Gi)<<o:(s&Gi)*Math.pow(2,o),o+=7}while(s>=jc);return bn.bytes=i-n,r}var Gc=Math.pow(2,7),Wc=Math.pow(2,14),Jc=Math.pow(2,21),Qc=Math.pow(2,28),Xc=Math.pow(2,35),Yc=Math.pow(2,42),Kc=Math.pow(2,49),Zc=Math.pow(2,56),eu=Math.pow(2,63),tu=function(t){return t<Gc?1:t<Wc?2:t<Jc?3:t<Qc?4:t<Xc?5:t<Yc?6:t<Kc?7:t<Zc?8:t<eu?9:10},ru={encode:$c,decode:qc,encodingLength:tu},nu=ru,gt=nu;function wt(t,e=0){return[gt.decode(t,e),gt.decode.bytes]}function Oe(t,e,r=0){return gt.encode(t,e,r),e}function He(t){return gt.encodingLength(t)}function qe(t,e){let r=e.byteLength,n=He(t),o=n+He(r),i=new Uint8Array(o+r);return Oe(t,i,0),Oe(r,i,n),i.set(e,o),new Ve(t,r,e,i)}function je(t){let e=oe(t),[r,n]=wt(e),[o,i]=wt(e.subarray(n)),s=e.subarray(n+i);if(s.byteLength!==o)throw new Error("Incorrect length");return new Ve(r,o,s,e)}function Ji(t,e){if(t===e)return!0;{let r=e;return t.code===r.code&&t.size===r.size&&r.bytes instanceof Uint8Array&&fn(t.bytes,r.bytes)}}var Ve=class{code;size;digest;bytes;constructor(e,r,n,o){this.code=e,this.size=r,this.digest=n,this.bytes=o}};function Qi(t,e){let{bytes:r,version:n}=t;switch(n){case 0:return iu(r,En(t),e??ie.encoder);default:return su(r,En(t),e??$e.encoder)}}var Xi=new WeakMap;function En(t){let e=Xi.get(t);if(e==null){let r=new Map;return Xi.set(t,r),r}return e}var B=class t{code;version;multihash;bytes;"/";constructor(e,r,n,o){this.code=r,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:r}=this;if(e!==xt)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==au)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return t.createV0(r)}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:r}=this.multihash,n=qe(e,r);return t.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 t.equals(this,e)}static equals(e,r){let n=r;return n!=null&&e.code===n.code&&e.version===n.version&&Ji(e.multihash,n.multihash)}toString(e){return Qi(this,e)}toJSON(){return{"/":Qi(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 r=e;if(r instanceof t)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:o,multihash:i,bytes:s}=r;return new t(n,o,i,s??Yi(n,o,i.bytes))}else if(r[cu]===!0){let{version:n,multihash:o,code:i}=r,s=je(o);return t.create(n,i,s)}else return null}static create(e,r,n){if(typeof r!="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(r!==xt)throw new Error(`Version 0 CID must use dag-pb (code: ${xt}) block encoding`);return new t(e,r,n,n.bytes)}case 1:{let o=Yi(e,r,n.bytes);return new t(e,r,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return t.create(0,xt,e)}static createV1(e,r){return t.create(1,e,r)}static decode(e){let[r,n]=t.decodeFirst(e);if(n.length!==0)throw new Error("Incorrect length");return r}static decodeFirst(e){let r=t.inspectBytes(e),n=r.size-r.multihashSize,o=oe(e.subarray(n,n+r.multihashSize));if(o.byteLength!==r.multihashSize)throw new Error("Incorrect length");let i=o.subarray(r.multihashSize-r.digestSize),s=new Ve(r.multihashCode,r.digestSize,i,o);return[r.version===0?t.createV0(s):t.createV1(r.codec,s),e.subarray(r.size)]}static inspectBytes(e){let r=0,n=()=>{let[p,_]=wt(e.subarray(r));return r+=_,p},o=n(),i=xt;if(o===18?(o=0,r=0):i=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let s=r,a=n(),u=n(),l=r+u,d=l-s;return{version:o,codec:i,multihashCode:a,digestSize:u,multihashSize:d,size:l}}static parse(e,r){let[n,o]=ou(e,r),i=t.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 ou(t,e){switch(t[0]){case"Q":{let r=e??ie;return[ie.prefix,r.decode(`${ie.prefix}${t}`)]}case ie.prefix:{let r=e??ie;return[ie.prefix,r.decode(t)]}case $e.prefix:{let r=e??$e;return[$e.prefix,r.decode(t)]}case yt.prefix:{let r=e??yt;return[yt.prefix,r.decode(t)]}default:{if(e==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[t[0],e.decode(t)]}}}function iu(t,e,r){let{prefix:n}=r;if(n!==ie.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let o=e.get(n);if(o==null){let i=r.encode(t).slice(1);return e.set(n,i),i}else return o}function su(t,e,r){let{prefix:n}=r,o=e.get(n);if(o==null){let i=r.encode(t);return e.set(n,i),i}else return o}var xt=112,au=18;function Yi(t,e,r){let n=He(t),o=n+He(e),i=new Uint8Array(o+r.byteLength);return Oe(t,i,0),Oe(e,i,n),i.set(r,o),i}var cu=Symbol.for("@ipld/js-cid/CID");var Ki=42;function uu(t){return t instanceof ArrayBuffer?new Uint8Array(t,0,t.byteLength):t}function fu(t){if(t.asCID!==t&&t["/"]!==t.bytes)return null;let e=B.asCID(t);if(!e)return null;let r=new Uint8Array(e.bytes.byteLength+1);return r.set(e.bytes,1),[new y(f.tag,Ki),new y(f.bytes,r)]}function lu(){throw new Error("`undefined` is not supported by the IPLD Data Model and cannot be encoded")}function hu(t){if(Number.isNaN(t))throw new Error("`NaN` is not supported by the IPLD Data Model and cannot be encoded");if(t===1/0||t===-1/0)throw new Error("`Infinity` and `-Infinity` is not supported by the IPLD Data Model and cannot be encoded");return null}function du(t){for(let e of t.keys())if(typeof e!="string"||e.length===0)throw new Error("Non-string Map keys are not supported by the IPLD Data Model and cannot be encoded");return null}var vn={float64:!0,typeEncoders:{Map:du,Object:fu,undefined:lu,number:hu}},Wh={...vn,typeEncoders:{...vn.typeEncoders}};function pu(t){if(t[0]!==0)throw new Error("Invalid CID for CBOR tag 42; expected leading 0x00");return B.decode(t.subarray(1))}var hr={allowIndefinite:!1,coerceUndefinedToNull:!0,allowNaN:!1,allowInfinity:!1,allowBigInt:!0,strict:!0,useMaps:!1,rejectDuplicateMapKeys:!0,tags:[]};hr.tags[Ki]=pu;var Jh={...hr,tags:hr.tags.slice()};var dr=113,kn=t=>cn(t,vn),_e=t=>mt(uu(t),hr);var An=Ee(pr(),1);var Tn=40;function Sn(t,e){if(!t.length)throw new Error("Unexpected end of data");let r=An.default.decode(t);return e.seek(An.default.decode.bytes),r}function Bn(t){let e=new DataView(t.buffer,t.byteOffset,t.byteLength),r=0;return{version:2,characteristics:[e.getBigUint64(r,!0),e.getBigUint64(r+=8,!0)],dataOffset:Number(e.getBigUint64(r+=8,!0)),dataSize:Number(e.getBigUint64(r+=8,!0)),indexOffset:Number(e.getBigUint64(r+=8,!0))}}var we={Null:t=>t===null?t:void 0,Int:t=>Number.isInteger(t)?t:void 0,Float:t=>typeof t=="number"&&Number.isFinite(t)?t:void 0,String:t=>typeof t=="string"?t:void 0,Bool:t=>typeof t=="boolean"?t:void 0,Bytes:t=>t instanceof Uint8Array?t:void 0,Link:t=>t!==null&&typeof t=="object"&&t.asCID===t?t:void 0,List:t=>Array.isArray(t)?t:void 0,Map:t=>t!==null&&typeof t=="object"&&t.asCID!==t&&!Array.isArray(t)&&!(t instanceof Uint8Array)?t:void 0},Et={"CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)":we.Link,"CarV1HeaderOrV2Pragma > roots (anon)":t=>{if(we.List(t)!==void 0){for(let e=0;e<t.length;e++){let r=t[e];if(r=Et["CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)"](r),r===void 0)return;if(r!==t[e]){let n=t.slice(0,e);for(let o=e;o<t.length;o++){let i=t[o];if(i=Et["CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)"](i),i===void 0)return;n.push(i)}return n}}return t}},Int:we.Int,CarV1HeaderOrV2Pragma:t=>{if(we.Map(t)===void 0)return;let e=Object.entries(t),r=t,n=1;for(let o=0;o<e.length;o++){let[i,s]=e[o];switch(i){case"roots":{let a=Et["CarV1HeaderOrV2Pragma > roots (anon)"](t[i]);if(a===void 0)return;if(a!==s||r!==t){if(r===t){r={};for(let u=0;u<o;u++)r[e[u][0]]=e[u][1]}r.roots=a}}break;case"version":{n--;let a=Et.Int(t[i]);if(a===void 0)return;if(a!==s||r!==t){if(r===t){r={};for(let u=0;u<o;u++)r[e[u][0]]=e[u][1]}r.version=a}}break;default:return}}if(!(n>0))return r}},vt={"CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)":we.Link,"CarV1HeaderOrV2Pragma > roots (anon)":t=>{if(we.List(t)!==void 0){for(let e=0;e<t.length;e++){let r=t[e];if(r=vt["CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)"](r),r===void 0)return;if(r!==t[e]){let n=t.slice(0,e);for(let o=e;o<t.length;o++){let i=t[o];if(i=vt["CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)"](i),i===void 0)return;n.push(i)}return n}}return t}},Int:we.Int,CarV1HeaderOrV2Pragma:t=>{if(we.Map(t)===void 0)return;let e=Object.entries(t),r=t,n=1;for(let o=0;o<e.length;o++){let[i,s]=e[o];switch(i){case"roots":{let a=vt["CarV1HeaderOrV2Pragma > roots (anon)"](s);if(a===void 0)return;if(a!==s||r!==t){if(r===t){r={};for(let u=0;u<o;u++)r[e[u][0]]=e[u][1]}r.roots=a}}break;case"version":{n--;let a=vt.Int(s);if(a===void 0)return;if(a!==s||r!==t){if(r===t){r={};for(let u=0;u<o;u++)r[e[u][0]]=e[u][1]}r.version=a}}break;default:return}}if(!(n>0))return r}},Cn={toTyped:Et.CarV1HeaderOrV2Pragma,toRepresentation:vt.CarV1HeaderOrV2Pragma};var ud=on();var Nu=Ee(pr(),1);var pd=[new y(f.map,2),new y(f.string,"version"),new y(f.uint,1),new y(f.string,"roots")],md=new y(f.tag,42);async function Nn(t,e){let r=Sn(await t.upTo(8),t);if(r===0)throw new Error("Invalid CAR header (zero length)");let n=await t.exactly(r,!0),o=_e(n);if(Cn.toTyped(o)===void 0)throw new Error("Invalid CAR header format");if(o.version!==1&&o.version!==2||e!==void 0&&o.version!==e)throw new Error(`Invalid CAR version: ${o.version}${e!==void 0?` (expected ${e})`:""}`);if(o.version===1){if(!Array.isArray(o.roots))throw new Error("Invalid CAR header format");return o}if(o.roots!==void 0)throw new Error("Invalid CAR header format");let i=Bn(await t.exactly(Tn,!0));t.seek(i.dataOffset-t.pos);let s=await Nn(t,1);return Object.assign(s,i)}function kt(t){let e=0;return{async upTo(r){return t.subarray(e,e+Math.min(r,t.length-e))},async exactly(r,n=!1){if(r>t.length-e)throw new Error("Unexpected end of data");let o=t.subarray(e,e+r);return n&&(e+=r),o},seek(r){e+=r},get pos(){return e}}}var Dn=Ee(pr(),1),fs=1;function Ln(t){let e=kn({version:fs,roots:t}),r=Dn.default.encode(e.length),n=new Uint8Array(r.length+e.length);return n.set(r,0),n.set(e,r.length),n}function ls(t){return{async setRoots(e){let r=Ln(e);await t.write(r)},async writeBlock(e){let{cid:r,bytes:n}=e;await t.write(new Uint8Array(Dn.default.encode(r.bytes.length+n.length))),await t.write(r.bytes),n.length&&await t.write(n)},async close(){await t.end()},version(){return fs}}}function mr(){}function hs(){let t=[],e=null,r=mr,n=!1,o=null,i=mr,s=()=>(e||(e=new Promise(l=>{r=()=>{e=null,r=mr,l()}})),e),a={write(l){t.push(l);let d=s();return i(),d},async end(){n=!0;let l=s();i(),await l}},u={async next(){let l=t.shift();return l?(t.length===0&&r(),{done:!1,value:l}):n?(r(),{done:!0,value:void 0}):(o||(o=new Promise(d=>{i=()=>(o=null,i=mr,d(u.next()))})),o)}};return{writer:a,iterator:u}}var _t=class t{constructor(e,r){this._encoder=r,this._mutex=r.setRoots(e),this._ended=!1}async put(e){if(!(e.bytes instanceof Uint8Array)||!e.cid)throw new TypeError("Can only write {cid, bytes} objects");if(this._ended)throw new Error("Already closed");let r=B.asCID(e.cid);if(!r)throw new TypeError("Can only write {cid, bytes} objects");return this._mutex=this._mutex.then(()=>this._encoder.writeBlock({cid:r,bytes:e.bytes})),this._mutex}async close(){if(this._ended)throw new Error("Already closed");return await this._mutex,this._ended=!0,this._encoder.close()}version(){return this._encoder.version()}static create(e){e=Uu(e);let{encoder:r,iterator:n}=ds(),o=new t(e,r),i=new yr(n);return{writer:o,out:i}}static createAppender(){let{encoder:e,iterator:r}=ds();e.setRoots=()=>Promise.resolve();let n=new t([],e),o=new yr(r);return{writer:n,out:o}}static async updateRootsInBytes(e,r){let n=kt(e);await Nn(n);let o=Ln(r);if(Number(n.pos)!==o.length)throw new Error(`updateRoots() can only overwrite a header of the same length (old header is ${n.pos} bytes, new header is ${o.length} bytes)`);return e.set(o,0),e}},yr=class{constructor(e){this._iterator=e}[Symbol.asyncIterator](){if(this._iterating)throw new Error("Multiple iterator not supported");return this._iterating=!0,this._iterator}};function ds(){let t=hs(),{writer:e,iterator:r}=t;return{encoder:ls(e),iterator:r}}function Uu(t){if(t===void 0)return[];if(!Array.isArray(t)){let r=B.asCID(t);if(!r)throw new TypeError("roots must be a single CID or an array of CIDs");return[r]}let e=[];for(let r of t){let n=B.asCID(r);if(!n)throw new TypeError("roots must be a single CID or an array of CIDs");e.push(n)}return e}function Ru(t){return t[Symbol.asyncIterator]!=null}function Fu(t){if(Ru(t))return(async()=>{for await(let e of t);})();for(let e of t);}var Pn=Fu;function zu(t){let[e,r]=t[Symbol.asyncIterator]!=null?[t[Symbol.asyncIterator](),Symbol.asyncIterator]:[t[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(),[r](){return this}}}var gr=zu;function Mu(t){return t[Symbol.asyncIterator]!=null}function $u(t,e){let r=0;if(Mu(t))return(async function*(){for await(let u of t)yield e(u,r++)})();let n=gr(t),{value:o,done:i}=n.next();if(i===!0)return(function*(){})();let s=e(o,r++);if(typeof s.then=="function")return(async function*(){yield await s;for(let u of n)yield e(u,r++)})();let a=e;return(function*(){yield s;for(let u of n)yield a(u,r++)})()}var Ge=$u;function Ou(t){return t.reason}async function We(t,e,r){if(e==null)return t;let n=r?.translateError??Ou;if(e.aborted)return t.catch(()=>{}),Promise.reject(n(e));let o;try{return await Promise.race([t,new Promise((i,s)=>{o=()=>{s(n(e))},e.addEventListener("abort",o)})])}finally{o!=null&&e.removeEventListener("abort",o)}}var he=class extends Error{static name="AbortError";constructor(e="The operation was aborted"){super(e),this.name="AbortError"}};var Ie=class extends Error{static name="InvalidParametersError";constructor(e="Invalid parameters"){super(e),this.name="InvalidParametersError"}};var wr=class extends EventTarget{#e=new Map;constructor(){super()}listenerCount(e){let r=this.#e.get(e);return r==null?0:r.length}addEventListener(e,r,n){super.addEventListener(e,r,n);let o=this.#e.get(e);o==null&&(o=[],this.#e.set(e,o)),o.push({callback:r,once:(n!==!0&&n!==!1&&n?.once)??!1})}removeEventListener(e,r,n){super.removeEventListener(e.toString(),r??null,n);let o=this.#e.get(e);o!=null&&(o=o.filter(({callback:i})=>i!==r),this.#e.set(e,o))}dispatchEvent(e){let r=super.dispatchEvent(e),n=this.#e.get(e.type);return n==null||(n=n.filter(({once:o})=>!o),this.#e.set(e.type,n)),r}safeDispatchEvent(e,r={}){return this.dispatchEvent(new CustomEvent(e,r))}};var Rn={};q(Rn,{base64:()=>Un,base64pad:()=>Hu,base64url:()=>Vu,base64urlpad:()=>qu});var Un=P({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Hu=P({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Vu=P({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),qu=P({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var F=class extends Event{type;detail;constructor(e,r){super(e),this.type=e,this.detail=r}};var zn=Ee(ms(),1);var Mn=class t extends Error{name="TimeoutError";constructor(e,r){super(e,r),Error.captureStackTrace?.(this,t)}},ys=t=>t.reason??new DOMException("This operation was aborted.","AbortError");function $n(t,e){let{milliseconds:r,fallback:n,message:o,customTimers:i={setTimeout,clearTimeout},signal:s}=e,a,u,d=new Promise((p,_)=>{if(typeof r!="number"||Math.sign(r)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${r}\``);if(s?.aborted){_(ys(s));return}if(s&&(u=()=>{_(ys(s))},s.addEventListener("abort",u,{once:!0})),t.then(p,_),r===Number.POSITIVE_INFINITY)return;let c=new Mn;a=i.setTimeout.call(void 0,()=>{if(n){try{p(n())}catch(h){_(h)}return}typeof t.cancel=="function"&&t.cancel(),o===!1?p():o instanceof Error?_(o):(c.message=o??`Promise timed out after ${r} milliseconds`,_(c))},r)}).finally(()=>{d.clear(),u&&s&&s.removeEventListener("abort",u)});return d.clear=()=>{i.clearTimeout.call(void 0,a),a=void 0},d}function On(t,e,r){let n=0,o=t.length;for(;o>0;){let i=Math.trunc(o/2),s=n+i;r(t[s],e)<=0?(n=++s,o-=i+1):o=i}return n}var At=class{#e=[];enqueue(e,r){let{priority:n=0,id:o}=r??{},i={priority:n,id:o,run:e};if(this.size===0||this.#e[this.size-1].priority>=n){this.#e.push(i);return}let s=On(this.#e,i,(a,u)=>u.priority-a.priority);this.#e.splice(s,0,i)}setPriority(e,r){let n=this.#e.findIndex(i=>i.id===e);if(n===-1)throw new ReferenceError(`No promise function with the id "${e}" exists in the queue.`);let[o]=this.#e.splice(n,1);this.enqueue(o.run,{priority:r,id:e})}dequeue(){return this.#e.shift()?.run}filter(e){return this.#e.filter(r=>r.priority===e.priority).map(r=>r.run)}get size(){return this.#e.length}};var Tt=class extends zn.default{#e;#s;#a=0;#d;#m=!1;#w=!1;#c;#A=0;#x=0;#u;#f;#i;#o=[];#n=0;#t;#T;#r=0;#y;#l;#D=1n;#g=new Map;timeout;constructor(e){if(super(),e={carryoverIntervalCount:!1,intervalCap:Number.POSITIVE_INFINITY,interval:0,concurrency:Number.POSITIVE_INFINITY,autoStart:!0,queueClass:At,strict:!1,...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})`);if(e.strict&&e.interval===0)throw new TypeError("The `strict` option requires a non-zero `interval`");if(e.strict&&e.intervalCap===Number.POSITIVE_INFINITY)throw new TypeError("The `strict` option requires a finite `intervalCap`");if(this.#e=e.carryoverIntervalCount??e.carryoverConcurrencyCount??!1,this.#s=e.intervalCap===Number.POSITIVE_INFINITY||e.interval===0,this.#d=e.intervalCap,this.#c=e.interval,this.#i=e.strict,this.#t=new e.queueClass,this.#T=e.queueClass,this.concurrency=e.concurrency,e.timeout!==void 0&&!(Number.isFinite(e.timeout)&&e.timeout>0))throw new TypeError(`Expected \`timeout\` to be a positive finite number, got \`${e.timeout}\` (${typeof e.timeout})`);this.timeout=e.timeout,this.#l=e.autoStart===!1,this.#$()}#b(e){for(;this.#n<this.#o.length;){let n=this.#o[this.#n];if(n!==void 0&&e-n>=this.#c)this.#n++;else break}(this.#n>100&&this.#n>this.#o.length/2||this.#n===this.#o.length)&&(this.#o=this.#o.slice(this.#n),this.#n=0)}#L(e){this.#i?this.#o.push(e):this.#a++}#P(){this.#i?this.#o.length>this.#n&&this.#o.pop():this.#a>0&&this.#a--}#E(){return this.#o.length-this.#n}get#U(){return this.#s?!0:this.#i?this.#E()<this.#d:this.#a<this.#d}get#R(){return this.#r<this.#y}#F(){this.#r--,this.#r===0&&this.emit("pendingZero"),this.#_(),this.emit("next")}#z(){this.#f=void 0,this.#C(),this.#B()}#M(e){if(this.#i){if(this.#b(e),this.#E()>=this.#d){let n=this.#o[this.#n],o=this.#c-(e-n);return this.#v(o),!0}return!1}if(this.#u===void 0){let r=this.#A-e;if(r<0){if(this.#x>0){let n=e-this.#x;if(n<this.#c)return this.#v(this.#c-n),!0}this.#a=this.#e?this.#r:0}else return this.#v(r),!0}return!1}#v(e){this.#f===void 0&&(this.#f=setTimeout(()=>{this.#z()},e))}#k(){this.#u&&(clearInterval(this.#u),this.#u=void 0)}#S(){this.#f&&(clearTimeout(this.#f),this.#f=void 0)}#_(){if(this.#t.size===0){if(this.#k(),this.emit("empty"),this.#r===0){if(this.#S(),this.#i&&this.#n>0){let r=Date.now();this.#b(r)}this.emit("idle")}return!1}let e=!1;if(!this.#l){let r=Date.now(),n=!this.#M(r);if(this.#U&&this.#R){let o=this.#t.dequeue();this.#s||(this.#L(r),this.#p()),this.emit("active"),o(),n&&this.#B(),e=!0}}return e}#B(){this.#s||this.#u!==void 0||this.#i||(this.#u=setInterval(()=>{this.#C()},this.#c),this.#A=Date.now()+this.#c)}#C(){this.#i||(this.#a===0&&this.#r===0&&this.#u&&this.#k(),this.#a=this.#e?this.#r:0),this.#I(),this.#p()}#I(){for(;this.#_(););}get concurrency(){return this.#y}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.#y=e,this.#I()}setPriority(e,r){if(typeof r!="number"||!Number.isFinite(r))throw new TypeError(`Expected \`priority\` to be a finite number, got \`${r}\` (${typeof r})`);this.#t.setPriority(e,r)}async add(e,r={}){return r={timeout:this.timeout,...r,id:r.id??(this.#D++).toString()},new Promise((n,o)=>{let i=Symbol(`task-${r.id}`);this.#t.enqueue(async()=>{this.#r++,this.#g.set(i,{id:r.id,priority:r.priority??0,startTime:Date.now(),timeout:r.timeout});let s;try{try{r.signal?.throwIfAborted()}catch(l){throw this.#O(),this.#g.delete(i),l}this.#x=Date.now();let a=e({signal:r.signal});if(r.timeout&&(a=$n(Promise.resolve(a),{milliseconds:r.timeout,message:`Task timed out after ${r.timeout}ms (queue has ${this.#r} running, ${this.#t.size} waiting)`})),r.signal){let{signal:l}=r;a=Promise.race([a,new Promise((d,p)=>{s=()=>{p(l.reason)},l.addEventListener("abort",s,{once:!0})})])}let u=await a;n(u),this.emit("completed",u)}catch(a){o(a),this.emit("error",a)}finally{s&&r.signal?.removeEventListener("abort",s),this.#g.delete(i),queueMicrotask(()=>{this.#F()})}},r),this.emit("add"),this.#_()})}async addAll(e,r){return Promise.all(e.map(async n=>this.add(n,r)))}start(){return this.#l?(this.#l=!1,this.#I(),this):this}pause(){this.#l=!0}clear(){this.#t=new this.#T,this.#k(),this.#N(),this.emit("empty"),this.#r===0&&(this.#S(),this.emit("idle")),this.emit("next")}async onEmpty(){this.#t.size!==0&&await this.#h("empty")}async onSizeLessThan(e){this.#t.size<e||await this.#h("next",()=>this.#t.size<e)}async onIdle(){this.#r===0&&this.#t.size===0||await this.#h("idle")}async onPendingZero(){this.#r!==0&&await this.#h("pendingZero")}async onRateLimit(){this.isRateLimited||await this.#h("rateLimit")}async onRateLimitCleared(){this.isRateLimited&&await this.#h("rateLimitCleared")}onError(){return new Promise((e,r)=>{let n=o=>{this.off("error",n),r(o)};this.on("error",n)})}async#h(e,r){return new Promise(n=>{let o=()=>{r&&!r()||(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.#r}get isPaused(){return this.#l}#$(){this.#s||(this.on("add",()=>{this.#t.size>0&&this.#p()}),this.on("next",()=>{this.#p()}))}#p(){this.#s||this.#w||(this.#w=!0,queueMicrotask(()=>{this.#w=!1,this.#N()}))}#O(){this.#s||(this.#P(),this.#p())}#N(){let e=this.#m;if(this.#s||this.#t.size===0){e&&(this.#m=!1,this.emit("rateLimitCleared"));return}let r;if(this.#i){let o=Date.now();this.#b(o),r=this.#E()}else r=this.#a;let n=r>=this.#d;n!==e&&(this.#m=n,this.emit(n?"rateLimit":"rateLimitCleared"))}get isRateLimited(){return this.#m}get isSaturated(){return this.#r===this.#y&&this.#t.size>0||this.isRateLimited&&this.#t.size>0}get runningTasks(){return[...this.#g.values()].map(e=>({...e}))}};var Hn={};q(Hn,{base10:()=>Wu});var Wu=ye({prefix:"9",name:"base10",alphabet:"0123456789"});var Vn={};q(Vn,{base16:()=>Ju,base16upper:()=>Qu});var Ju=P({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Qu=P({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var qn={};q(qn,{base2:()=>Xu});var Xu=P({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var jn={};q(jn,{base256emoji:()=>tf});var gs=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}"),Yu=gs.reduce((t,e,r)=>(t[r]=e,t),[]),Ku=gs.reduce((t,e,r)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return t[n]=r,t},[]);function Zu(t){return t.reduce((e,r)=>(e+=Yu[r],e),"")}function ef(t){let e=[];for(let r of t){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=Ku[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);e.push(o)}return new Uint8Array(e)}var tf=Me({prefix:"\u{1F680}",name:"base256emoji",encode:Zu,decode:ef});var Gn={};q(Gn,{base8:()=>rf});var rf=P({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Wn={};q(Wn,{identity:()=>nf});var nf=Me({prefix:"\0",name:"identity",encode:t=>hn(t),decode:t=>ln(t)});var Ip=new TextEncoder,of=new TextDecoder;var br=512;function Er(t){return JSON.parse(of.decode(t))}var Qe=85;var Jn={};q(Jn,{identity:()=>Bt});var ws=0,sf="identity",xs=oe;function af(t,e){if(e?.truncate!=null&&e.truncate!==t.byteLength){if(e.truncate<0||e.truncate>t.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${t.byteLength}`);t=t.subarray(0,e.truncate)}return qe(ws,xs(t))}var Bt={code:ws,name:sf,encode:xs,digest:af};var Xn={};q(Xn,{sha256:()=>uf,sha512:()=>ff});var cf=20;function Ae({name:t,code:e,encode:r,minDigestLength:n,maxDigestLength:o}){return new Qn(t,e,r,n,o)}var Qn=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,r,n,o,i){this.name=e,this.code=r,this.encode=n,this.minDigestLength=o??cf,this.maxDigestLength=i}digest(e,r){if(r?.truncate!=null){if(r.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&r.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(e instanceof Uint8Array){let n=this.encode(e);return n instanceof Uint8Array?bs(n,this.code,r?.truncate):n.then(o=>bs(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function bs(t,e,r){if(r!=null&&r!==t.byteLength){if(r>t.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${t.byteLength}`);t=t.subarray(0,r)}return qe(e,t)}function vs(t){return async e=>new Uint8Array(await crypto.subtle.digest(t,e))}var uf=Ae({name:"sha2-256",code:18,encode:vs("SHA-256")}),ff=Ae({name:"sha2-512",code:19,encode:vs("SHA-512")});var Yn={...Wn,...qn,...Gn,...Hn,...Vn,...gn,...wn,...xn,...Rn,...jn},zp={...Xn,...Jn};function se(t=0){return new Uint8Array(t)}function _s(t,e,r,n){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:r},decoder:{decode:n}}}var ks=_s("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),Kn=_s("ascii","a",t=>{let e="a";for(let r=0;r<t.length;r++)e+=String.fromCharCode(t[r]);return e},t=>{t=t.substring(1);let e=se(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}),lf={utf8:ks,"utf-8":ks,hex:Yn.base16,latin1:Kn,ascii:Kn,binary:Kn,...Yn},Zn=lf;var pf=Ee(As(),1);var Je;(function(t){t[t.A=1]="A",t[t.CNAME=5]="CNAME",t[t.TXT=16]="TXT",t[t.AAAA=28]="AAAA"})(Je||(Je={}));function Ct(t,e){e==null&&(e=t.reduce((o,i)=>o+i.length,0));let r=se(e),n=0;for(let o of t)r.set(o,n),n+=o.length;return r}function kr(t,e="utf8"){let r=Zn[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.decoder.decode(`${r.prefix}${t}`)}var mf=Math.pow(2,7),yf=Math.pow(2,14),gf=Math.pow(2,21),Ts=Math.pow(2,28),Ss=Math.pow(2,35),Bs=Math.pow(2,42),Cs=Math.pow(2,49),V=128,xe=127;function Nt(t){if(t<mf)return 1;if(t<yf)return 2;if(t<gf)return 3;if(t<Ts)return 4;if(t<Ss)return 5;if(t<Bs)return 6;if(t<Cs)return 7;if(Number.MAX_SAFE_INTEGER!=null&&t>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Ns(t,e,r=0){switch(Nt(t)){case 8:e[r++]=t&255|V,t/=128;case 7:e[r++]=t&255|V,t/=128;case 6:e[r++]=t&255|V,t/=128;case 5:e[r++]=t&255|V,t/=128;case 4:e[r++]=t&255|V,t>>>=7;case 3:e[r++]=t&255|V,t>>>=7;case 2:e[r++]=t&255|V,t>>>=7;case 1:{e[r++]=t&255,t>>>=7;break}default:throw new Error("unreachable")}return e}function Ds(t,e){let r=t[e],n=0;if(n+=r&xe,r<V||(r=t[e+1],n+=(r&xe)<<7,r<V)||(r=t[e+2],n+=(r&xe)<<14,r<V)||(r=t[e+3],n+=(r&xe)<<21,r<V)||(r=t[e+4],n+=(r&xe)*Ts,r<V)||(r=t[e+5],n+=(r&xe)*Ss,r<V)||(r=t[e+6],n+=(r&xe)*Bs,r<V)||(r=t[e+7],n+=(r&xe)*Cs,r<V))return n;throw new RangeError("Could not decode varint")}var eo=new Float32Array([-0]),be=new Uint8Array(eo.buffer);function Ls(t,e,r){eo[0]=t,e[r]=be[0],e[r+1]=be[1],e[r+2]=be[2],e[r+3]=be[3]}function Ps(t,e){return be[0]=t[e],be[1]=t[e+1],be[2]=t[e+2],be[3]=t[e+3],eo[0]}var to=new Float64Array([-0]),M=new Uint8Array(to.buffer);function Us(t,e,r){to[0]=t,e[r]=M[0],e[r+1]=M[1],e[r+2]=M[2],e[r+3]=M[3],e[r+4]=M[4],e[r+5]=M[5],e[r+6]=M[6],e[r+7]=M[7]}function Rs(t,e){return M[0]=t[e],M[1]=t[e+1],M[2]=t[e+2],M[3]=t[e+3],M[4]=t[e+4],M[5]=t[e+5],M[6]=t[e+6],M[7]=t[e+7],to[0]}var wf=BigInt(Number.MAX_SAFE_INTEGER),xf=BigInt(Number.MIN_SAFE_INTEGER),Q=class t{lo;hi;constructor(e,r){this.lo=e|0,this.hi=r|0}toNumber(e=!1){if(!e&&this.hi>>>31>0){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(r+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(e=!1){if(e)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(BigInt(r)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(e=!1){return this.toBigInt(e).toString()}zzEncode(){let e=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^e)>>>0,this.lo=(this.lo<<1^e)>>>0,this}zzDecode(){let e=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^e)>>>0,this.hi=(this.hi>>>1^e)>>>0,this}length(){let e=this.lo,r=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?r===0?e<16384?e<128?1:2:e<2097152?3:4:r<16384?r<128?5:6:r<2097152?7:8:n<128?9:10}static fromBigInt(e){if(e===0n)return Te;if(e<wf&&e>xf)return this.fromNumber(Number(e));let r=e<0n;r&&(e=-e);let n=e>>32n,o=e-(n<<32n);return r&&(n=~n|0n,o=~o|0n,++o>Fs&&(o=0n,++n>Fs&&(n=0n))),new t(Number(o),Number(n))}static fromNumber(e){if(e===0)return Te;let r=e<0;r&&(e=-e);let n=e>>>0,o=(e-n)/4294967296>>>0;return r&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new t(n,o)}static from(e){return typeof e=="number"?t.fromNumber(e):typeof e=="bigint"?t.fromBigInt(e):typeof e=="string"?t.fromBigInt(BigInt(e)):e.low!=null||e.high!=null?new t(e.low>>>0,e.high>>>0):Te}},Te=new Q(0,0);Te.toBigInt=function(){return 0n};Te.zzEncode=Te.zzDecode=function(){return this};Te.length=function(){return 1};var Fs=4294967296n;function zs(t){let e=0,r=0;for(let n=0;n<t.length;++n)r=t.charCodeAt(n),r<128?e+=1:r<2048?e+=2:(r&64512)===55296&&(t.charCodeAt(n+1)&64512)===56320?(++n,e+=4):e+=3;return e}function Ms(t,e,r){if(r-e<1)return"";let o,i=[],s=0,a;for(;e<r;)a=t[e++],a<128?i[s++]=a:a>191&&a<224?i[s++]=(a&31)<<6|t[e++]&63:a>239&&a<365?(a=((a&7)<<18|(t[e++]&63)<<12|(t[e++]&63)<<6|t[e++]&63)-65536,i[s++]=55296+(a>>10),i[s++]=56320+(a&1023)):i[s++]=(a&15)<<12|(t[e++]&63)<<6|t[e++]&63,s>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,i)),s=0);return o!=null?(s>0&&o.push(String.fromCharCode.apply(String,i.slice(0,s))),o.join("")):String.fromCharCode.apply(String,i.slice(0,s))}function ro(t,e,r){let n=r,o,i;for(let s=0;s<t.length;++s)o=t.charCodeAt(s),o<128?e[r++]=o:o<2048?(e[r++]=o>>6|192,e[r++]=o&63|128):(o&64512)===55296&&((i=t.charCodeAt(s+1))&64512)===56320?(o=65536+((o&1023)<<10)+(i&1023),++s,e[r++]=o>>18|240,e[r++]=o>>12&63|128,e[r++]=o>>6&63|128,e[r++]=o&63|128):(e[r++]=o>>12|224,e[r++]=o>>6&63|128,e[r++]=o&63|128);return r-n}function te(t,e){return RangeError(`index out of range: ${t.pos} + ${e??1} > ${t.len}`)}function _r(t,e){return(t[e-4]|t[e-3]<<8|t[e-2]<<16|t[e-1]<<24)>>>0}var no=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(e){this.buf=e,this.pos=0,this.len=e.length}uint32(){let e=4294967295;if(e=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(e=(e|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return e;if((this.pos+=5)>this.len)throw this.pos=this.len,te(this,10);return e}int32(){return this.uint32()|0}sint32(){let e=this.uint32();return e>>>1^-(e&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw te(this,4);return _r(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw te(this,4);return _r(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw te(this,4);let e=Ps(this.buf,this.pos);return this.pos+=4,e}double(){if(this.pos+8>this.len)throw te(this,4);let e=Rs(this.buf,this.pos);return this.pos+=8,e}bytes(){let e=this.uint32(),r=this.pos,n=this.pos+e;if(n>this.len)throw te(this,e);return this.pos+=e,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let e=this.bytes();return Ms(e,0,e.length)}skip(e){if(typeof e=="number"){if(this.pos+e>this.len)throw te(this,e);this.pos+=e}else do if(this.pos>=this.len)throw te(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(e){switch(e){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(e=this.uint32()&7)!==4;)this.skipType(e);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${e} at offset ${this.pos}`)}return this}readLongVarint(){let e=new Q(0,0),r=0;if(this.len-this.pos>4){for(;r<4;++r)if(e.lo=(e.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return e;if(e.lo=(e.lo|(this.buf[this.pos]&127)<<28)>>>0,e.hi=(e.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return e;r=0}else{for(;r<3;++r){if(this.pos>=this.len)throw te(this);if(e.lo=(e.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return e}return e.lo=(e.lo|(this.buf[this.pos++]&127)<<r*7)>>>0,e}if(this.len-this.pos>4){for(;r<5;++r)if(e.hi=(e.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return e}else for(;r<5;++r){if(this.pos>=this.len)throw te(this);if(e.hi=(e.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return e}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw te(this,8);let e=_r(this.buf,this.pos+=4),r=_r(this.buf,this.pos+=4);return new Q(e,r)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let e=Ds(this.buf,this.pos);return this.pos+=Nt(e),e}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function oo(t){return new no(t instanceof Uint8Array?t:t.subarray())}function Dt(t,e,r){let n=oo(t);return e.decode(n,void 0,r)}function io(t){let e=t??8192,r=e>>>1,n,o=e;return function(s){if(s<1||s>r)return se(s);o+s>e&&(n=se(e),o=0);let a=n.subarray(o,o+=s);return(o&7)!==0&&(o=(o|7)+1),a}}var Se=class{fn;len;next;val;constructor(e,r,n){this.fn=e,this.len=r,this.next=void 0,this.val=n}};function so(){}var co=class{head;tail;len;next;constructor(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}},bf=io();function Ef(t){return globalThis.Buffer!=null?se(t):bf(t)}var Pt=class{len;head;tail;states;constructor(){this.len=0,this.head=new Se(so,0,0),this.tail=this.head,this.states=null}_push(e,r,n){return this.tail=this.tail.next=new Se(e,r,n),this.len+=r,this}uint32(e){return this.len+=(this.tail=this.tail.next=new uo((e=e>>>0)<128?1:e<16384?2:e<2097152?3:e<268435456?4:5,e)).len,this}int32(e){return e<0?this._push(Ir,10,Q.fromNumber(e)):this.uint32(e)}sint32(e){return this.uint32((e<<1^e>>31)>>>0)}uint64(e){let r=Q.fromBigInt(e);return this._push(Ir,r.length(),r)}uint64Number(e){return this._push(Ns,Nt(e),e)}uint64String(e){return this.uint64(BigInt(e))}int64(e){return this.uint64(e)}int64Number(e){return this.uint64Number(e)}int64String(e){return this.uint64String(e)}sint64(e){let r=Q.fromBigInt(e).zzEncode();return this._push(Ir,r.length(),r)}sint64Number(e){let r=Q.fromNumber(e).zzEncode();return this._push(Ir,r.length(),r)}sint64String(e){return this.sint64(BigInt(e))}bool(e){return this._push(ao,1,e?1:0)}fixed32(e){return this._push(Lt,4,e>>>0)}sfixed32(e){return this.fixed32(e)}fixed64(e){let r=Q.fromBigInt(e);return this._push(Lt,4,r.lo)._push(Lt,4,r.hi)}fixed64Number(e){let r=Q.fromNumber(e);return this._push(Lt,4,r.lo)._push(Lt,4,r.hi)}fixed64String(e){return this.fixed64(BigInt(e))}sfixed64(e){return this.fixed64(e)}sfixed64Number(e){return this.fixed64Number(e)}sfixed64String(e){return this.fixed64String(e)}float(e){return this._push(Ls,4,e)}double(e){return this._push(Us,8,e)}bytes(e){let r=e.length>>>0;return r===0?this._push(ao,1,0):this.uint32(r)._push(kf,r,e)}string(e){let r=zs(e);return r!==0?this.uint32(r)._push(ro,r,e):this._push(ao,1,0)}fork(){return this.states=new co(this),this.head=this.tail=new Se(so,0,0),this.len=0,this}reset(){return this.states!=null?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new Se(so,0,0),this.len=0),this}ldelim(){let e=this.head,r=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=e.next,this.tail=r,this.len+=n),this}finish(){let e=this.head.next,r=Ef(this.len),n=0;for(;e!=null;)e.fn(e.val,r,n),n+=e.len,e=e.next;return r}};function ao(t,e,r){e[r]=t&255}function vf(t,e,r){for(;t>127;)e[r++]=t&127|128,t>>>=7;e[r]=t}var uo=class extends Se{next;constructor(e,r){super(vf,e,r),this.next=void 0}};function Ir(t,e,r){for(;t.hi!==0;)e[r++]=t.lo&127|128,t.lo=(t.lo>>>7|t.hi<<25)>>>0,t.hi>>>=7;for(;t.lo>127;)e[r++]=t.lo&127|128,t.lo=t.lo>>>7;e[r++]=t.lo}function Lt(t,e,r){e[r]=t&255,e[r+1]=t>>>8&255,e[r+2]=t>>>16&255,e[r+3]=t>>>24}function kf(t,e,r){e.set(t,r)}globalThis.Buffer!=null&&(Pt.prototype.bytes=function(t){let e=t.length>>>0;return this.uint32(e),e>0&&this._push(_f,e,t),this},Pt.prototype.string=function(t){let e=globalThis.Buffer.byteLength(t);return this.uint32(e),e>0&&this._push(If,e,t),this});function _f(t,e,r){e.set(t,r)}function If(t,e,r){t.length<40?ro(t,e,r):e.utf8Write!=null?e.utf8Write(t,r):e.set(kr(t),r)}function fo(){return new Pt}function Ut(t,e){let r=fo();return e.encode(t,r,{lengthDelimited:!1}),r.finish()}var Xe;(function(t){t[t.VARINT=0]="VARINT",t[t.BIT64=1]="BIT64",t[t.LENGTH_DELIMITED=2]="LENGTH_DELIMITED",t[t.START_GROUP=3]="START_GROUP",t[t.END_GROUP=4]="END_GROUP",t[t.BIT32=5]="BIT32"})(Xe||(Xe={}));function Ar(t,e,r,n){return{name:t,type:e,encode:r,decode:n}}function lo(t){function e(o){if(t[o.toString()]==null)throw new Error("Invalid enum value");return t[o]}let r=function(i,s){let a=e(i);s.int32(a)},n=function(i){let s=i.int32();return e(s)};return Ar("enum",Xe.VARINT,r,n)}function Rt(t,e){return Ar("message",Xe.LENGTH_DELIMITED,t,e)}function $(){let t={};return t.promise=new Promise((e,r)=>{t.resolve=e,t.reject=r}),t}var Tr=class{buffer;mask;top;btm;next;constructor(e){if(!(e>0)||(e-1&e)!==0)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}},Ye=class{size;hwm;head;tail;constructor(e={}){this.hwm=e.splitLimit??16,this.head=new Tr(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 r=this.head;this.head=r.next=new Tr(2*this.head.buffer.length),this.head.push(e)}}shift(){let e=this.tail.shift();if(e===void 0&&this.tail.next!=null){let r=this.tail.next;this.tail.next=null,this.tail=r,e=this.tail.shift()}return e?.value!=null&&(this.size-=this.calculateSize(e.value)),e}isEmpty(){return this.head.isEmpty()}};var ho=class extends Error{type;code;constructor(e,r){super(e??"The operation was aborted"),this.type="aborted",this.code=r??"ABORT_ERR"}};function Ke(t={}){return Af(r=>{let n=r.shift();if(n==null)return{done:!0};if(n.error!=null)throw n.error;return{done:n.done===!0,value:n.value}},t)}function Af(t,e){e=e??{};let r=e.onEnd,n=new Ye,o,i,s,a=$(),u=async()=>{try{return n.isEmpty()?s?{done:!0}:await new Promise((A,g)=>{i=w=>{i=null,n.push(w);try{A(t(n))}catch(b){g(b)}return o}}):t(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=$()})}},l=A=>i!=null?i(A):(n.push(A),o),d=A=>(n=new Ye,i!=null?i({error:A}):(n.push({error:A}),o)),p=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 l({done:!1,value:A})},_=A=>s?o:(s=!0,A!=null?d(A):l({done:!0})),c=()=>(n=new Ye,_(),{done:!0}),h=A=>(_(A),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:u,return:c,throw:h,push:p,end:_,get readableLength(){return n.size},onEmpty:async A=>{let g=A?.signal;if(g?.throwIfAborted(),n.isEmpty())return;let w,b;g!=null&&(w=new Promise((v,I)=>{b=()=>{I(new ho)},g.addEventListener("abort",b)}));try{await Promise.race([a.promise,w])}finally{b!=null&&g!=null&&g?.removeEventListener("abort",b)}}},r==null)return o;let m=o;return o={[Symbol.asyncIterator](){return this},next(){return m.next()},throw(A){return m.throw(A),r!=null&&(r(A),r=void 0),{done:!0}},return(){return m.return(),r!=null&&(r(),r=void 0),{done:!0}},push:p,end(A){return m.end(A),r!=null&&(r(A),r=void 0),o},get readableLength(){return m.readableLength},onEmpty:A=>m.onEmpty(A)},o}var po=class extends Error{constructor(e){super(e),this.name="TimeoutError"}},mo=class extends Error{constructor(e){super(),this.name="AbortError",this.message=e}},Os=t=>globalThis.DOMException===void 0?new mo(t):new DOMException(t),Hs=t=>{let e=t.reason===void 0?Os("This operation was aborted."):t.reason;return e instanceof Error?e:Os(e)};function yo(t,e){let{milliseconds:r,fallback:n,message:o,customTimers:i={setTimeout,clearTimeout}}=e,s,a,l=new Promise((d,p)=>{if(typeof r!="number"||Math.sign(r)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${r}\``);if(e.signal){let{signal:c}=e;c.aborted&&p(Hs(c)),a=()=>{p(Hs(c))},c.addEventListener("abort",a,{once:!0})}if(r===Number.POSITIVE_INFINITY){t.then(d,p);return}let _=new po;s=i.setTimeout.call(void 0,()=>{if(n){try{d(n())}catch(c){p(c)}return}typeof t.cancel=="function"&&t.cancel(),o===!1?d():o instanceof Error?p(o):(_.message=o??`Promise timed out after ${r} milliseconds`,p(_))},r),(async()=>{try{d(await t)}catch(c){p(c)}})()}).finally(()=>{l.clear(),a&&e.signal&&e.signal.removeEventListener("abort",a)});return l.clear=()=>{i.clearTimeout.call(void 0,s),s=void 0},l}var Tf=t=>{let e=t.addEventListener||t.on||t.addListener,r=t.removeEventListener||t.off||t.removeListener;if(!e||!r)throw new TypeError("Emitter is not compatible");return{addListener:e.bind(t),removeListener:r.bind(t)}};function Sf(t,e,r){let n,o=new Promise((i,s)=>{if(r={rejectionEvents:["error"],multiArgs:!1,rejectionMultiArgs:!1,resolveImmediately:!1,...r},!(r.count>=0&&(r.count===Number.POSITIVE_INFINITY||Number.isInteger(r.count))))throw new TypeError("The `count` option should be at least 0 or more");r.signal?.throwIfAborted();let a=[e].flat(),u=[],{addListener:l,removeListener:d}=Tf(t),p=async(...c)=>{let h=r.multiArgs?c:c[0];if(r.filter)try{if(!await r.filter(h))return}catch(m){n(),s(m);return}u.push(h),r.count===u.length&&(n(),i(u))},_=(...c)=>{n(),s(r.rejectionMultiArgs?c:c[0])};n=()=>{for(let c of a)d(c,p);for(let c of r.rejectionEvents)a.includes(c)||d(c,_)};for(let c of a)l(c,p);for(let c of r.rejectionEvents)a.includes(c)||l(c,_);r.signal&&r.signal.addEventListener("abort",()=>{_(r.signal.reason)},{once:!0}),r.resolveImmediately&&i(u)});if(o.cancel=n,typeof r.timeout=="number"){let i=yo(o,{milliseconds:r.timeout});return i.cancel=()=>{n(),i.clear()},i}return o}function Sr(t,e,r){typeof r=="function"&&(r={filter:r}),r={...r,count:1,resolveImmediately:!1};let n=Sf(t,e,r),o=n.then(i=>i[0]);return o.cancel=n.cancel,o}function go(t,e){let r,n=function(){let o=function(){r=void 0,t()};clearTimeout(r),r=setTimeout(o,e)};return n.start=()=>{},n.stop=()=>{clearTimeout(r)},n}var Br=class extends Error{static name="QueueFullError";constructor(e="The queue was full"){super(e),this.name="QueueFullError"}};var Cr=class{deferred;signal;constructor(e){this.signal=e,this.deferred=$(),this.onAbort=this.onAbort.bind(this),this.signal?.addEventListener("abort",this.onAbort)}onAbort(){this.deferred.reject(this.signal?.reason??new he)}cleanup(){this.signal?.removeEventListener("abort",this.onAbort)}};function Bf(){return`${parseInt(String(Math.random()*1e9),10).toString()}${Date.now()}`}var Nr=class{id;fn;options;recipients;status;timeline;controller;constructor(e,r){this.id=Bf(),this.status="queued",this.fn=e,this.options=r,this.recipients=[],this.timeline={created:Date.now()},this.controller=new AbortController,this.controller.signal,this.onAbort=this.onAbort.bind(this)}abort(e){this.controller.abort(e)}onAbort(){this.recipients.reduce((r,n)=>r&&n.signal?.aborted===!0,!0)&&(this.controller.abort(new he),this.cleanup())}async join(e={}){let r=new Cr(e.signal);return this.recipients.push(r),e.signal?.addEventListener("abort",this.onAbort),r.deferred.promise}async run(){this.status="running",this.timeline.started=Date.now();try{this.controller.signal.throwIfAborted();let e=await We(this.fn({...this.options??{},signal:this.controller.signal}),this.controller.signal);this.recipients.forEach(r=>{r.deferred.resolve(e)}),this.status="complete"}catch(e){this.recipients.forEach(r=>{r.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 Ze=class extends wr{concurrency;maxSize;queue;pending;sort;paused;constructor(e={}){super(),this.concurrency=e.concurrency??Number.POSITIVE_INFINITY,this.maxSize=e.maxSize??Number.POSITIVE_INFINITY,this.pending=0,this.paused=!1,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=[],this.emitEmpty=go(this.emitEmpty.bind(this),1),this.emitIdle=go(this.emitIdle.bind(this),1)}emitEmpty(){this.size===0&&this.safeDispatchEvent("empty")}emitIdle(){this.running===0&&this.safeDispatchEvent("idle")}pause(){this.paused=!0}resume(){this.paused&&(this.paused=!1,this.tryToStartAnother())}tryToStartAnother(){if(this.paused)return!1;if(this.size===0)return this.emitEmpty(),this.running===0&&this.emitIdle(),!1;if(this.pending<this.concurrency){let e;for(let r of this.queue)if(r.status==="queued"){e=r;break}return e==null?!1:(this.safeDispatchEvent("active"),this.pending++,e.run().finally(()=>{for(let r=0;r<this.queue.length;r++)if(this.queue[r]===e){this.queue.splice(r,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,r){if(r?.signal?.throwIfAborted(),this.size===this.maxSize)throw new Br;let n=new Nr(e,r);return this.enqueue(n),this.safeDispatchEvent("add"),this.tryToStartAnother(),n.join(r).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("failure",{detail:{job:n,error:o}}),o})}clear(){this.queue.splice(0,this.queue.length)}abort(){this.queue.forEach(e=>{e.abort(new he)}),this.clear()}async onEmpty(e){this.size!==0&&await Sr(this,"empty",e)}async onSizeLessThan(e,r){this.size<e||await Sr(this,"next",{...r,filter:()=>this.size<e})}async onIdle(e){this.pending===0&&this.size===0||await Sr(this,"idle",e)}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 r=Ke({objectMode:!0}),n=u=>{u!=null?this.abort():this.clear(),r.end(u)},o=u=>{u.detail!=null&&r.push(u.detail)},i=u=>{n(u.detail.error)},s=()=>{n()},a=()=>{n(new he("Queue aborted"))};this.addEventListener("completed",o),this.addEventListener("failure",i),this.addEventListener("idle",s),e?.signal?.addEventListener("abort",a);try{yield*r}finally{this.removeEventListener("completed",o),this.removeEventListener("failure",i),this.removeEventListener("idle",s),e?.signal?.removeEventListener("abort",a),n()}}};function Vs(t){let e=new globalThis.AbortController;function r(){let i=t.filter(s=>s?.aborted===!0).map(s=>s?.reason).pop();e.abort(i);for(let s of t)s?.removeEventListener!=null&&s.removeEventListener("abort",r)}for(let i of t){if(i?.aborted===!0){r();break}i?.addEventListener!=null&&i.addEventListener("abort",r)}function n(){for(let i of t)i?.removeEventListener!=null&&i.removeEventListener("abort",r)}let o=e.signal;return o.clear=n,o}var wo=class{readNext;haveNext;ended;nextResult;error;constructor(){this.ended=!1,this.readNext=$(),this.haveNext=$()}[Symbol.asyncIterator](){return this}async next(){if(this.nextResult==null&&await this.haveNext.promise,this.nextResult==null)throw new Error("HaveNext promise resolved but nextResult was undefined");let e=this.nextResult;return this.nextResult=void 0,this.readNext.resolve(),this.readNext=$(),e}async throw(e){return this.ended=!0,this.error=e,e!=null&&(this.haveNext.promise.catch(()=>{}),this.haveNext.reject(e)),{done:!0,value:void 0}}async return(){let e={done:!0,value:void 0};return this.ended=!0,this.nextResult=e,this.haveNext.resolve(),e}async push(e,r){await this._push(e,r)}async end(e,r){e!=null?await this.throw(e):await this._push(void 0,r)}async _push(e,r){if(e!=null&&this.ended)throw this.error??new Error("Cannot push value onto an ended pushable");for(;this.nextResult!=null;)await this.readNext.promise;e!=null?this.nextResult={done:!1,value:e}:(this.ended=!0,this.nextResult={done:!0,value:void 0}),this.haveNext.resolve(),this.haveNext=$(),await We(this.readNext.promise,r?.signal,r)}};function qs(){return new wo}function Cf(t){return t[Symbol.asyncIterator]!=null}async function Nf(t,e,r){try{await Promise.all(t.map(async n=>{for await(let o of n)await e.push(o,{signal:r}),r.throwIfAborted()})),await e.end(void 0,{signal:r})}catch(n){await e.end(n,{signal:r}).catch(()=>{})}}async function*Df(t){let e=new AbortController,r=qs();Nf(t,r,e.signal).catch(()=>{});try{yield*r}finally{e.abort()}}function*Lf(t){for(let e of t)yield*e}function Pf(...t){let e=[];for(let r of t)Cf(r)||e.push(r);return e.length===t.length?Lf(e):Df(t)}var js=Pf;function Dr(t,...e){if(t==null)throw new Error("Empty pipeline");if(xo(t)){let n=t;t=()=>n.source}else if(Ws(t)||Gs(t)){let n=t;t=()=>n}let r=[t,...e];if(r.length>1&&xo(r[r.length-1])&&(r[r.length-1]=r[r.length-1].sink),r.length>2)for(let n=1;n<r.length-1;n++)xo(r[n])&&(r[n]=Rf(r[n]));return Uf(...r)}var Uf=(...t)=>{let e;for(;t.length>0;)e=t.shift()(e);return e},Gs=t=>t?.[Symbol.asyncIterator]!=null,Ws=t=>t?.[Symbol.iterator]!=null,xo=t=>t==null?!1:t.sink!=null&&t.source!=null,Rf=t=>e=>{let r=t.sink(e);if(r?.then!=null){let n=Ke({objectMode:!0});r.then(()=>{n.end()},s=>{n.end(s)});let o,i=t.source;if(Gs(i))o=async function*(){yield*i,n.end()};else if(Ws(i))o=function*(){yield*i,n.end()};else throw new Error("Unknown duplex source type - must be Iterable or AsyncIterable");return js(n,o())}return t.source};function Ff(t){return t[Symbol.asyncIterator]!=null}function zf(t){if(Ff(t))return(async()=>{let n=new Uint8Array(0);for await(let o of t)n=Ct([n,o],n.length+o.length);return n})();let e=[],r=0;for(let n of t)e.push(n),r+=n.byteLength;return Ct(e,r)}var N=zf;function Lr({enumerable:t=!0,configurable:e=!1}={}){return{enumerable:t,configurable:e,writable:!1}}function*Mf(t,e){if(e!=null&&typeof e=="object")if(Array.isArray(e))for(let[r,n]of e.entries()){let o=[...t,r],i=B.asCID(n);i!=null?yield[o.join("/"),i]:typeof n=="object"&&(yield*bo(n,o))}else{let r=B.asCID(e);r!=null?yield[t.join("/"),r]:yield*bo(e,t)}}function*bo(t,e){if(t==null||t instanceof Uint8Array)return;let r=B.asCID(t);r!=null&&(yield[e.join("/"),r]);for(let[n,o]of Object.entries(t)){let i=[...e,n];yield*Mf(i,o)}}function*$f(t,e){if(Array.isArray(e))for(let[r,n]of e.entries()){let o=[...t,r];yield o.join("/"),typeof n=="object"&&B.asCID(n)==null&&(yield*Eo(n,o))}else yield*Eo(e,t)}function*Eo(t,e){if(!(t==null||typeof t!="object"))for(let[r,n]of Object.entries(t)){let o=[...e,r];yield o.join("/"),n!=null&&!(n instanceof Uint8Array)&&typeof n=="object"&&B.asCID(n)==null&&(yield*$f(o,n))}}function Of(t,e){let r=t;for(let[n,o]of e.entries()){if(r=r[o],r==null)throw new Error(`Object has no property at ${e.slice(0,n+1).map(s=>`[${JSON.stringify(s)}]`).join("")}`);let i=B.asCID(r);if(i!=null)return{value:i,remaining:e.slice(n+1).join("/")}}return{value:r}}var vo=class{cid;bytes;value;asBlock;constructor({cid:e,bytes:r,value:n}){if(e==null||r==null||typeof n>"u")throw new Error("Missing required argument");this.cid=e,this.bytes=r,this.value=n,this.asBlock=this,Object.defineProperties(this,{cid:Lr(),bytes:Lr(),value:Lr(),asBlock:Lr()})}links(){return bo(this.value,[])}tree(){return Eo(this.value,[])}get(e="/"){return Of(this.value,e.split("/").filter(Boolean))}};function ae({bytes:t,cid:e,value:r,codec:n}){let o=r!==void 0?r:n?.decode(t);if(o===void 0)throw new Error('Missing required argument, must either provide "value" or "codec"');return new vo({cid:e,bytes:t,value:o})}var Js=class extends Array{constructor(){super(),this.inRecursive=[]}prefix(e){let r=this.inRecursive[this.inRecursive.length-1];r&&(r.type===f.array&&(r.elements++,r.elements!==1&&e.push([44])),r.type===f.map&&(r.elements++,r.elements!==1&&(r.elements%2===1?e.push([44]):e.push([58]))))}[f.uint.major](e,r){this.prefix(e);let n=String(r.value),o=[];for(let i=0;i<n.length;i++)o[i]=n.charCodeAt(i);e.push(o)}[f.negint.major](e,r){this[f.uint.major](e,r)}[f.bytes.major](e,r){throw new Error(`${Pe} unsupported type: Uint8Array`)}[f.string.major](e,r){this.prefix(e);let n=Kt(JSON.stringify(r.value));e.push(n.length>32?ct(n):n)}[f.array.major](e,r){this.prefix(e),this.inRecursive.push({type:f.array,elements:0}),e.push([91])}[f.map.major](e,r){this.prefix(e),this.inRecursive.push({type:f.map,elements:0}),e.push([123])}[f.tag.major](e,r){}[f.float.major](e,r){if(r.type.name==="break"){let s=this.inRecursive.pop();if(s){if(s.type===f.array)e.push([93]);else if(s.type===f.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(r.value===void 0)throw new Error(`${Pe} unsupported type: undefined`);if(this.prefix(e),r.type.name==="true"){e.push([116,114,117,101]);return}else if(r.type.name==="false"){e.push([102,97,108,115,101]);return}else if(r.type.name==="null"){e.push([110,117,108,108]);return}let n=String(r.value),o=[],i=!1;for(let s=0;s<n.length;s++)o[s]=n.charCodeAt(s),!i&&(o[s]===46||o[s]===101||o[s]===69)&&(i=!0);i||(o.push(46),o.push(48)),e.push(o)}};var et=class{constructor(e,r={}){this._pos=0,this.data=e,this.options=r,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 r=0;r<e.length;r++)if(this.data[this._pos++]!==e[r])throw new Error(`${k} unexpected token at position ${this._pos}, expected to find '${String.fromCharCode(...e)}'`)}parseNumber(){let e=this._pos,r=!1,n=!1,o=a=>{for(;!this.done();){let u=this.ch();if(a.includes(u))this._pos++;else break}};if(this.ch()===45&&(r=!0,this._pos++),this.ch()===48)if(this._pos++,this.ch()===46)this._pos++,n=!0;else return new y(f.uint,0,this._pos-e);if(o([48,49,50,51,52,53,54,55,56,57]),r&&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 y(f.float,s,this._pos-e):this.options.allowBigInt!==!0||Number.isSafeInteger(s)?new y(s>=0?f.uint:f.negint,s,this._pos-e):new y(s>=0?f.uint:f.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 a=this.data[i];if(a===92||a<32||a>=128)break;if(a===34){let u=String.fromCharCode.apply(null,this.data.subarray(this._pos,i));return this._pos=i+1,new y(f.string,u,s)}}let e=this._pos,r=[],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 a=this.ch();if(a>=48&&a<=57)a-=48;else if(a>=97&&a<=102)a=a-97+10;else if(a>=65&&a<=70)a=a-65+10;else throw new Error(`${k} unexpected unicode escape character at position ${this._pos}`);i=i*16+a,this._pos++}return i},o=()=>{let i=this.ch(),s=null,a=i>239?4:i>223?3:i>191?2:1;if(this._pos+a>this.data.length)throw new Error(`${k} unexpected unicode sequence at position ${this._pos}`);let u,l,d,p;switch(a){case 1:i<128&&(s=i);break;case 2:u=this.data[this._pos+1],(u&192)===128&&(p=(i&31)<<6|u&63,p>127&&(s=p));break;case 3:u=this.data[this._pos+1],l=this.data[this._pos+2],(u&192)===128&&(l&192)===128&&(p=(i&15)<<12|(u&63)<<6|l&63,p>2047&&(p<55296||p>57343)&&(s=p));break;case 4:u=this.data[this._pos+1],l=this.data[this._pos+2],d=this.data[this._pos+3],(u&192)===128&&(l&192)===128&&(d&192)===128&&(p=(i&15)<<18|(u&63)<<12|(l&63)<<6|d&63,p>65535&&p<1114112&&(s=p))}s===null?(s=65533,a=1):s>65535&&(s-=65536,r.push(s>>>10&1023|55296),s=56320|s&1023),r.push(s),this._pos+=a};for(;!this.done();){let i=this.ch(),s;switch(i){case 92:if(this._pos++,this.done())throw new Error(`${k} unexpected string termination at position ${this._pos}`);switch(s=this.ch(),this._pos++,s){case 34:case 39:case 92:case 47:r.push(s);break;case 98:r.push(8);break;case 116:r.push(9);break;case 110:r.push(10);break;case 102:r.push(12);break;case 114:r.push(13);break;case 117:r.push(n());break;default:throw new Error(`${k} unexpected string escape character at position ${this._pos}`)}break;case 34:return this._pos++,new y(f.string,Kr(r),this._pos-e);default:if(i<32)throw new Error(`${k} invalid control character at position ${this._pos}`);i<128?(r.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 y(f.map,1/0,1);case 91:return this.modeStack.push("array-start"),this._pos++,new y(f.array,1/0,1);case 34:return this.parseString();case 110:return this.expect([110,117,108,108]),new y(f.null,null,4);case 102:return this.expect([102,97,108,115,101]),new y(f.false,!1,5);case 116:return this.expect([116,114,117,101]),new y(f.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 y(f.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 y(f.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 y(f.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 y(f.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 ko(t,e){return e=Object.assign({tokenizer:new et(t,e)},e),mt(t,e)}function qf(t){return t instanceof ArrayBuffer?new Uint8Array(t,0,t.byteLength):t}var _o=class extends et{constructor(e,r){super(e,r),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===f.map){let r=this._next();if(r.type===f.string&&r.value==="/"){let n=this._next();if(n.type===f.string){if(this._next().type!==f.break)throw new Error("Invalid encoded CID form");return this.tokenBuffer.push(n),new y(f.tag,42,0)}if(n.type===f.map){let o=this._next();if(o.type===f.string&&o.value==="bytes"){let i=this._next();if(i.type===f.string){for(let a=0;a<2;a++)if(this._next().type!==f.break)throw new Error("Invalid encoded Bytes form");let s=Un.decode(`m${i.value}`);return new y(f.bytes,s,i.value.length)}this.tokenBuffer.push(i)}this.tokenBuffer.push(o)}this.tokenBuffer.push(n)}this.tokenBuffer.push(r)}return e}},Io={allowIndefinite:!1,allowUndefined:!1,allowNaN:!1,allowInfinity:!1,allowBigInt:!0,strict:!0,useMaps:!1,rejectDuplicateMapKeys:!0,tags:[]};Io.tags[42]=B.parse;var Pr=297;var Ur=t=>{let e=qf(t),r=Object.assign(Io,{tokenizer:new _o(e,Io)});return ko(e,r)};var a0=new TextDecoder;var c0=new TextEncoder;var jf=new TextDecoder;function Ao(t,e){let r=0;for(let n=0;;n+=7){if(n>=64)throw new Error("protobuf: varint overflow");if(e>=t.length)throw new Error("protobuf: unexpected end of data");let o=t[e++];if(r+=n<28?(o&127)<<n:(o&127)*2**n,o<128)break}return[r,e]}function Fr(t,e){let r;[r,e]=Ao(t,e);let n=e+r;if(r<0||n<0)throw new Error("protobuf: invalid length");if(n>t.length)throw new Error("protobuf: unexpected end of data");return[t.subarray(e,n),n]}function Qs(t,e){let r;return[r,e]=Ao(t,e),[r&7,r>>3,e]}function Gf(t){let e={},r=t.length,n=0;for(;n<r;){let o,i;if([o,i,n]=Qs(t,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]=Fr(t,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]=Fr(t,n),e.Name=jf.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]=Ao(t,n)}else throw new Error(`protobuf: (PBLink) invalid fieldNumber, expected 1, 2 or 3, got ${i}`)}if(n>r)throw new Error("protobuf: (PBLink) unexpected end of data");return e}function Xs(t){let e=t.length,r=0,n,o=!1,i;for(;r<e;){let a,u;if([a,u,r]=Qs(t,r),a!==2)throw new Error(`protobuf: (PBNode) invalid wireType, expected 2, got ${a}`);if(u===1){if(i)throw new Error("protobuf: (PBNode) duplicate Data section");[i,r]=Fr(t,r),n&&(o=!0)}else if(u===2){if(o)throw new Error("protobuf: (PBNode) duplicate Links section");n||(n=[]);let l;[l,r]=Fr(t,r),n.push(Gf(l))}else throw new Error(`protobuf: (PBNode) invalid fieldNumber, expected 1 or 2, got ${u}`)}if(r>e)throw new Error("protobuf: (PBNode) unexpected end of data");let s={};return i&&(s.Data=i),s.Links=n||[],s}var Ks=new TextEncoder,Ys=2**32,Wf=2**31;function Jf(t,e){let r=e.length;if(typeof t.Tsize=="number"){if(t.Tsize<0)throw new Error("Tsize cannot be negative");if(!Number.isSafeInteger(t.Tsize))throw new Error("Tsize too large for encoding");r=Ft(e,r,t.Tsize)-1,e[r]=24}if(typeof t.Name=="string"){let n=Ks.encode(t.Name);r-=n.length,e.set(n,r),r=Ft(e,r,n.length)-1,e[r]=18}return t.Hash&&(r-=t.Hash.length,e.set(t.Hash,r),r=Ft(e,r,t.Hash.length)-1,e[r]=10),e.length-r}function Zs(t){let e=Xf(t),r=new Uint8Array(e),n=e;if(t.Data&&(n-=t.Data.length,r.set(t.Data,n),n=Ft(r,n,t.Data.length)-1,r[n]=10),t.Links)for(let o=t.Links.length-1;o>=0;o--){let i=Jf(t.Links[o],r.subarray(0,n));n-=i,n=Ft(r,n,i)-1,r[n]=18}return r}function Qf(t){let e=0;if(t.Hash){let r=t.Hash.length;e+=1+r+tt(r)}if(typeof t.Name=="string"){let r=Ks.encode(t.Name).length;e+=1+r+tt(r)}return typeof t.Tsize=="number"&&(e+=1+tt(t.Tsize)),e}function Xf(t){let e=0;if(t.Data){let r=t.Data.length;e+=1+r+tt(r)}if(t.Links)for(let r of t.Links){let n=Qf(r);e+=1+n+tt(n)}return e}function Ft(t,e,r){e-=tt(r);let n=e;for(;r>=Wf;)t[e++]=r&127|128,r/=128;for(;r>=128;)t[e++]=r&127|128,r>>>=7;return t[e]=r,n}function tt(t){return t%2===0&&t++,Math.floor((Yf(t)+6)/7)}function Yf(t){let e=0;return t>=Ys&&(t=Math.floor(t/Ys),e=32),t>=65536&&(t>>>=16,e+=16),t>=256&&(t>>>=8,e+=8),e+Kf[t]}var Kf=[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 Zf=["Data","Links"],el=["Hash","Name","Tsize"],ea=new TextEncoder;function tl(t,e){if(t===e)return 0;let r=t.Name?ea.encode(t.Name):[],n=e.Name?ea.encode(e.Name):[],o=r.length,i=n.length;for(let s=0,a=Math.min(o,i);s<a;++s)if(r[s]!==n[s]){o=r[s],i=n[s];break}return o<i?-1:i<o?1:0}function ta(t,e){return!Object.keys(t).some(r=>!e.includes(r))}function ra(t){if(!t||typeof t!="object"||Array.isArray(t)||t instanceof Uint8Array||t["/"]&&t["/"]===t.bytes)throw new TypeError("Invalid DAG-PB form");if(!ta(t,Zf))throw new TypeError("Invalid DAG-PB form (extraneous properties)");if(t.Data!==void 0&&!(t.Data instanceof Uint8Array))throw new TypeError("Invalid DAG-PB form (Data must be bytes)");if(!Array.isArray(t.Links))throw new TypeError("Invalid DAG-PB form (Links must be a list)");for(let e=0;e<t.Links.length;e++){let r=t.Links[e];if(!r||typeof r!="object"||Array.isArray(r)||r instanceof Uint8Array||r["/"]&&r["/"]===r.bytes)throw new TypeError("Invalid DAG-PB form (bad link)");if(!ta(r,el))throw new TypeError("Invalid DAG-PB form (extraneous properties on link)");if(r.Hash===void 0)throw new TypeError("Invalid DAG-PB form (link must have a Hash)");if(r.Hash==null||!r.Hash["/"]||r.Hash["/"]!==r.Hash.bytes)throw new TypeError("Invalid DAG-PB form (link Hash must be a CID)");if(r.Name!==void 0&&typeof r.Name!="string")throw new TypeError("Invalid DAG-PB form (link Name must be a string)");if(r.Tsize!==void 0){if(typeof r.Tsize!="number"||r.Tsize%1!==0)throw new TypeError("Invalid DAG-PB form (link Tsize must be an integer)");if(r.Tsize<0)throw new TypeError("Invalid DAG-PB form (link Tsize cannot be negative)")}if(e>0&&tl(r,t.Links[e-1])===-1)throw new TypeError("Invalid DAG-PB form (links must be sorted by Name bytes)")}}function na(t){return t instanceof ArrayBuffer?new Uint8Array(t,0,t.byteLength):t}var rt=112;function oa(t){ra(t);let e={};return t.Links&&(e.Links=t.Links.map(r=>{let n={};return r.Hash&&(n.Hash=r.Hash.bytes),r.Name!==void 0&&(n.Name=r.Name),r.Tsize!==void 0&&(n.Tsize=r.Tsize),n})),t.Data&&(e.Data=t.Data),Zs(e)}function ce(t){let e=na(t),r=Xs(e),n={};return r.Data&&(n.Data=r.Data),r.Links&&(n.Links=r.Links.map(o=>{let i={};try{i.Hash=B.decode(o.Hash)}catch{}if(!i.Hash)throw new Error("Invalid Hash field found in link, expected CID");return o.Name!==void 0&&(i.Name=o.Name),o.Tsize!==void 0&&(i.Tsize=o.Tsize),i})),n}function rl(t){return t[Symbol.asyncIterator]!=null}function nl(t,e){let r=0;if(rl(t))return(async function*(){for await(let u of t)await e(u,r++)&&(yield u)})();let n=gr(t),{value:o,done:i}=n.next();if(i===!0)return(function*(){})();let s=e(o,r++);if(typeof s.then=="function")return(async function*(){await s&&(yield o);for(let u of n)await e(u,r++)&&(yield u)})();let a=e;return(function*(){s===!0&&(yield o);for(let u of n)a(u,r++)&&(yield u)})()}var ia=nl;function Be(t){return e=>new To(e,t)}function Ce(t){return e=>new So(e,t)}function Co(t){return e=>new Bo(e,t)}var Mt=class{components;constructor(e,r={}){this.components=e}async*walk(e,r){let n=this.getQueue(),o=ia(n.toGenerator(r),a=>a!=null),i=!1,s=async a=>{let u=a.cid,l=await N(this.components.blockstore.get(u,a)),d=ae({cid:u,bytes:l,codec:await this.components.getCodec(u.code)});for(let[,p]of d.links())r?.includeChild?.(p,d)!==!1&&n.add(s,{...a,cid:p,depth:a.depth+1,path:[...a.path,p]}).catch(_=>{i||o.throw(_)});return{block:d,depth:a.depth,path:a.path}};n.add(s,{...r,cid:e,depth:0,path:[e]}).catch(a=>{i||o.throw(a)});try{yield*o}finally{i=!0,n.abort()}}},To=class extends Mt{getQueue(){return new Ze({concurrency:1,sort:(e,r)=>e.options.depth===r.options.depth?0:e.options.depth<r.options.depth?1:-1})}},So=class extends Mt{getQueue(){return new Ze({concurrency:1,sort:(e,r)=>e.options.depth===r.options.depth?0:e.options.depth<r.options.depth?-1:1})}},Bo=class extends Mt{getQueue(){return new Ze({concurrency:1})}};var $t=class{walker;constructor(e){this.walker=e?.walker}async*export(e,r,n,o){let i,s={blockstore:r,getCodec:n};this.walker!=null?i=this.walker(s):i=Ce()(s);for await(let a of i.walk(e,o))yield a.block}};var zr=class{components;log;constructor(e){this.components=e,this.log=e.logger.forComponent("helia:car")}async import(e,r){await Pn(this.components.blockstore.putMany(Ge(e.blocks(),({cid:n,bytes:o})=>({cid:n,bytes:o})),r))}async*export(e,r){let n=Array.isArray(e)?e:[e],{writer:o,out:i}=_t.create(n),s=i[Symbol.asyncIterator](),a=new AbortController;for(this._export(n,o,r).catch(u=>{this.log.error("error during streaming export - %e",u),a.abort(u)});;){let{done:u,value:l}=await We(s.next(),a.signal);if(a.signal.aborted)throw a.signal.reason;if(l!=null&&(yield l),u===!0)break}}async _export(e,r,n){let o=n?.traversal;for(let i of e){if(i.multihash.code===0)continue;let s=n?.exporter??(i.code===112?new Ot:new $t),a=i,u=!1;if(o!=null){for await(let{cid:l,bytes:d}of o.traverse(a,this.components.blockstore,this.components.getCodec,n))if(this.log.trace("next CID on path to %c is %c",i,l),a=l,i.equals(l)&&(u=!0),u||n?.includeTraversalBlocks===!0){if(n?.blockFilter?.has(l.multihash.bytes)===!0)continue;n?.blockFilter?.add(l.multihash.bytes),await r.put({cid:l,bytes:d})}}for await(let{cid:l,bytes:d}of s.export(a,this.components.blockstore,this.components.getCodec,n))n?.blockFilter?.has(l.multihash.bytes)!==!0&&l.multihash.code!==0&&(u&&l.equals(a)||(n?.blockFilter?.add(l.multihash.bytes),await r.put({cid:l,bytes:d})))}await r.close()}};var No=class{async*export(e,r,n,o){let i=await N(r.get(e,o));yield ae({cid:e,bytes:i,codec:await n(e.code)})}};var Ht=class t extends Error{static name="InvalidTypeError";static code="ERR_INVALID_TYPE";name=t.name;code=t.code;constructor(e="Invalid type"){super(e)}},Mr=class t extends Error{static name="InvalidUnixFSMessageError";static code="ERR_INVALID_MESSAGE";name=t.name;code=t.code;constructor(e="Invalid message"){super(e)}};var re;(function(t){let e;(function(o){o.Raw="Raw",o.Directory="Directory",o.File="File",o.Metadata="Metadata",o.Symlink="Symlink",o.HAMTShard="HAMTShard"})(e=t.DataType||(t.DataType={}));let r;(function(o){o[o.Raw=0]="Raw",o[o.Directory=1]="Directory",o[o.File=2]="File",o[o.Metadata=3]="Metadata",o[o.Symlink=4]="Symlink",o[o.HAMTShard=5]="HAMTShard"})(r||(r={})),(function(o){o.codec=()=>lo(r)})(e=t.DataType||(t.DataType={}));let n;t.codec=()=>(n==null&&(n=Rt((o,i,s={})=>{if(s.lengthDelimited!==!1&&i.fork(),o.Type!=null&&(i.uint32(8),t.DataType.codec().encode(o.Type,i)),o.Data!=null&&(i.uint32(18),i.bytes(o.Data)),o.filesize!=null&&(i.uint32(24),i.uint64(o.filesize)),o.blocksizes!=null)for(let a of o.blocksizes)i.uint32(32),i.uint64(a);o.hashType!=null&&(i.uint32(40),i.uint64(o.hashType)),o.fanout!=null&&(i.uint32(48),i.uint64(o.fanout)),o.mode!=null&&(i.uint32(56),i.uint32(o.mode)),o.mtime!=null&&(i.uint32(66),$r.codec().encode(o.mtime,i)),s.lengthDelimited!==!1&&i.ldelim()},(o,i)=>{let s={blocksizes:[]},a=i==null?o.len:o.pos+i;for(;o.pos<a;){let u=o.uint32();switch(u>>>3){case 1:s.Type=t.DataType.codec().decode(o);break;case 2:s.Data=o.bytes();break;case 3:s.filesize=o.uint64();break;case 4:s.blocksizes.push(o.uint64());break;case 5:s.hashType=o.uint64();break;case 6:s.fanout=o.uint64();break;case 7:s.mode=o.uint32();break;case 8:s.mtime=$r.codec().decode(o,o.uint32());break;default:o.skipType(u&7);break}}return s})),n),t.encode=o=>Ut(o,t.codec()),t.decode=o=>Dt(o,t.codec())})(re||(re={}));var $r;(function(t){let e;t.codec=()=>(e==null&&(e=Rt((r,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),r.Seconds!=null&&(n.uint32(8),n.int64(r.Seconds)),r.FractionalNanoseconds!=null&&(n.uint32(21),n.fixed32(r.FractionalNanoseconds)),o.lengthDelimited!==!1&&n.ldelim()},(r,n)=>{let o={},i=n==null?r.len:r.pos+n;for(;r.pos<i;){let s=r.uint32();switch(s>>>3){case 1:o.Seconds=r.int64();break;case 2:o.FractionalNanoseconds=r.fixed32();break;default:r.skipType(s&7);break}}return o})),e),t.encode=r=>Ut(r,t.codec()),t.decode=r=>Dt(r,t.codec())})($r||($r={}));var aa;(function(t){let e;t.codec=()=>(e==null&&(e=Rt((r,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),r.MimeType!=null&&(n.uint32(10),n.string(r.MimeType)),o.lengthDelimited!==!1&&n.ldelim()},(r,n)=>{let o={},i=n==null?r.len:r.pos+n;for(;r.pos<i;){let s=r.uint32();switch(s>>>3){case 1:o.MimeType=r.string();break;default:r.skipType(s&7);break}}return o})),e),t.encode=r=>Ut(r,t.codec()),t.decode=r=>Dt(r,t.codec())})(aa||(aa={}));var ca={Raw:"raw",Directory:"directory",File:"file",Metadata:"metadata",Symlink:"symlink",HAMTShard:"hamt-sharded-directory"},il=["directory","hamt-sharded-directory"],ua=parseInt("0644",8),fa=parseInt("0755",8),la=BigInt(1024),O=class t{static unmarshal(e){let r=re.decode(e);if(r.fanout!=null&&r.fanout>la)throw new Mr(`Fanout size was too large - ${r.fanout} > ${la}`);let n=new t({type:ca[r.Type!=null?r.Type.toString():"File"],data:r.Data,blockSizes:r.blocksizes,mode:r.mode,mtime:r.mtime!=null?{secs:r.mtime.Seconds??0n,nsecs:r.mtime.FractionalNanoseconds}:void 0,fanout:r.fanout});return n._originalMode=r.mode??0,n}type;data;blockSizes;hashType;fanout;mtime;_mode;_originalMode;constructor(e={type:"file"}){let{type:r,data:n,blockSizes:o,hashType:i,fanout:s,mtime:a,mode:u}=e;if(r!=null&&!Object.values(ca).includes(r))throw new Ht("Type: "+r+" is not valid");this.type=r??"file",this.data=n,this.hashType=i,this.fanout=s,this.blockSizes=o??[],this._originalMode=0,this.mode=u,this.mtime=a}set mode(e){e==null?this._mode=this.isDirectory()?fa:ua:this._mode=e&4095}get mode(){return this._mode}isDirectory(){return il.includes(this.type)}addBlockSize(e){this.blockSizes.push(e)}removeBlockSize(e){this.blockSizes.splice(e,1)}fileSize(){if(this.isDirectory())return 0n;let e=0n;return this.blockSizes.forEach(r=>{e+=r}),this.data!=null&&(e+=BigInt(this.data.length)),e}marshal(){let e;switch(this.type){case"raw":e=re.DataType.Raw;break;case"directory":e=re.DataType.Directory;break;case"file":e=re.DataType.File;break;case"metadata":e=re.DataType.Metadata;break;case"symlink":e=re.DataType.Symlink;break;case"hamt-sharded-directory":e=re.DataType.HAMTShard;break;default:throw new Ht(`Type: ${e} is not valid`)}let r=this.data;(this.data==null||this.data.length===0)&&(r=void 0);let n;this.mode!=null&&(n=this._originalMode&4294963200|(this.mode??0),n===ua&&!this.isDirectory()&&(n=void 0),n===fa&&this.isDirectory()&&(n=void 0));let o;return this.mtime!=null&&(o={Seconds:this.mtime.secs,FractionalNanoseconds:this.mtime.nsecs}),re.encode({Type:e,Data:r,filesize:this.isDirectory()?void 0:this.fileSize(),blocksizes:this.blockSizes,hashType:this.hashType,fanout:this.fanout,mode:n,mtime:o})}};var Vt=class extends Error{static code="ERR_NOT_UNIXFS";static message="Not a UnixFS node";static name="NotUnixFSError";code="ERR_NOT_UNIXFS";message="Not a UnixFS node";name="NotUnixFSError"},Or=class extends Error{static name="NotDescendantError";name="NotDescendantError"},nt=class extends Error{static name="InvalidTraversalError";name="InvalidTraversalError"};function al(t){return t.cid.code===85}function cl(t){return t.cid.code===112}function ul(t){if(al(t))return!0;if(cl(t)&&t.value.Data!=null){let e=O.unmarshal(t.value.Data);return e.type==="file"||e.type==="raw"}else throw new Vt("Encountered non raw/dag-pb CID in UnixFS DAG")}var Ot=class{options;constructor(e){this.options=e}async*export(e,r,n,o){if(e.code!==112&&e.code!==85)throw new Vt("Target CID was not UnixFS - use the SubGraphExporter to export arbitrary graphs");let i=Be()({blockstore:r,getCodec:n}),s=this.options?.offset??0,a=this.options?.length??1/0,u=this.options?.listingOnly??!1;if(s<0)throw new Ie("Offset cannot be negative");if(a<0)throw new Ie("Length cannot be negative");let l,d=new AbortController,p=Vs([d.signal,o?.signal]);d.signal;function _(c,h){if(l==null&&(l=ul(h)),!l){let I=h.value.Links.find(E=>E.Hash.equals(c)),T=O.unmarshal(h.value.Data??new Uint8Array);return T.type==="directory"?!u:T.type==="hamt-sharded-directory"&&u?I?.Name?.length===2:!0}let m=h.value.Links.findIndex(I=>I.Hash.equals(c)),A=O.unmarshal(h.value.Data??new Uint8Array),g=s,w=g+a,b=Number([...A.blockSizes].slice(0,m).reduce((I,T)=>I+T,0n)),v=b+Number(A.blockSizes[m]);return g>=b&&g<v||w>=b&&w<v||g<=b&&w>=v}try{for await(let c of i.walk(e,{...o,includeChild:_,signal:p}))yield c.block}finally{d.abort(),p.clear()}}};function ha(t){return t!=null&&t?.asCID===t}var Do=class{haystack;needle;options;walker;constructor(...e){if(ha(e[0]))ha(e[1])?(this.haystack=e[0],this.needle=e[1],this.options=e[2]):(this.needle=e[0],this.options=e[1]);else throw new Ie("needle must be specified");this.walker=this.options?.walker}async*traverse(e,r,n,o){let i=this.haystack??e,s,a={blockstore:r,getCodec:n};this.walker!=null?s=this.walker(a):this.options?.strategy==="breadth-first"?s=Ce()(a):s=Be()(a);for await(let u of s.walk(i,o))if(u.block.cid.equals(this.needle)){for(let l of u.path){let d=await N(r.get(l,o));yield ae({cid:l,bytes:d,codec:await n(l.code)})}return}throw new nt(`${this.needle} was not a child of ${i}`)}};var Lo=class{path;constructor(e){this.path=e}async*traverse(e,r,n,o){if(!this.path.some(s=>s.equals(e)))throw new nt(`CIDPath traversal must include ${e}`);let i;for(let s of this.path){if(i!=null){let l=!1;for(let[,d]of i.links())if(d.equals(s)){l=!0;break}if(!l)throw new Or(`${s} is not a child of ${i.cid}`)}let a=await N(r.get(s,o)),u=ae({cid:s,bytes:a,codec:await n(s.code)});i=u,yield u}}};var ot=class t extends Error{static name="BadPathError";static code="ERR_BAD_PATH";name=t.name;code=t.code;constructor(e="Bad path"){super(e)}},X=class t extends Error{static name="NotFoundError";static code="ERR_NOT_FOUND";name=t.name;code=t.code;constructor(e="Not found"){super(e)}},it=class t extends Error{static name="NoResolverError";static code="ERR_NO_RESOLVER";name=t.name;code=t.code;constructor(e="No resolver"){super(e)}},L=class t extends Error{static name="NotUnixFSError";static code="ERR_NOT_UNIXFS";name=t.name;code=t.code;constructor(e="Not UnixFS"){super(e)}},Hr=class t extends Error{static name="OverReadError";static code="ERR_OVER_READ";name=t.name;code=t.code;constructor(e="Over read"){super(e)}},Vr=class t extends Error{static name="UnderReadError";static code="ERR_UNDER_READ";name=t.name;code=t.code;constructor(e="Under read"){super(e)}},de=class t extends Error{static name="InvalidParametersError";static code="ERR_INVALID_PARAMS";name=t.name;code=t.code;constructor(e="Invalid parameters"){super(e)}};function st(t){return t==null?!1:B.asCID(t)===t}function at(t,e){let r,n=0,o="";for(;n<e.length;){let i=e[n];if(n++,!Object.hasOwnProperty.call(t,i))throw new ot(`Object did not have key "${i}"`);if(o+=`/${i}`,r=t[i],t=r,st(r))break}return{value:r,rest:e.slice(n),path:o.substring(1)}}async function*Po(t,e,r,n){let o=await N(r.get(t,n)),i=_e(o),s=at(i,e);yield{cid:st(s.value)?s.value:t,name:s.path,rest:s.rest}}async function*da(t,e,r,n){let o=await N(r.get(t,n)),i=Ur(o),s=at(i,e);yield{cid:st(s.value)?s.value:t,name:s.path,rest:s.rest}}var jr=Ee(ya(),1);function fl(t){let e=new Array(4);for(let r=0;r<4;r++)e[r]=t&255,t=t>>8;return new Uint8Array(e)}var Fg=Ae({name:"murmur3-32",code:35,encode:t=>fl(jr.default.x86.hash32(t))}),ga=Ae({name:"murmur3-128",code:34,encode:t=>ke.fromHex(jr.default.x64.hash128(t))}),zg=Ae({name:"murmur3-x64-64",code:34,encode:t=>ke.fromHex(jr.default.x64.hash128(t)).subarray(0,8)});var Ea=Ee(ba(),1);var Ne=class t{_options;_popCount;_parent;_posAtParent;_children;key;constructor(e,r,n=0){this._options=e,this._popCount=0,this._parent=r,this._posAtParent=n,this._children=new Ea.default,this.key=null}async put(e,r){let n=await this._findNewBucketAndPos(e);n.bucket._putAt(n,e,r)}async get(e){let r=await this._findChild(e);if(r!=null)return r.value}async del(e){let r=await this._findPlace(e),n=r.bucket._at(r.pos);n!=null&&n.key===e&&r.bucket._delAt(r.pos)}leafCount(){return this._children.compactArray().reduce((r,n)=>n instanceof t?r+n.leafCount():r+1,0)}childrenCount(){return this._children.length}onlyChild(){return this._children.get(0)}*eachLeafSeries(){let e=this._children.compactArray();for(let r of e)r instanceof t?yield*r.eachLeafSeries():yield r}serialize(e,r){let n=[];return r(this._children.reduce((o,i,s)=>(i!=null&&(i instanceof t?o.push(i.serialize(e,r)):o.push(e(i,s))),o),n))}async asyncTransform(e,r){return va(this,e,r)}toJSON(){return this.serialize(ml,yl)}prettyPrint(){return JSON.stringify(this.toJSON(),null," ")}tableSize(){return Math.pow(2,this._options.bits)}async _findChild(e){let r=await this._findPlace(e),n=r.bucket._at(r.pos);if(!(n instanceof t)&&n!=null&&n.key===e)return n}async _findPlace(e){let r=this._options.hash(typeof e=="string"?kr(e):e),n=await r.take(this._options.bits),o=this._children.get(n);return o instanceof t?o._findPlace(r):{bucket:this,pos:n,hash:r,existingChild:o}}async _findNewBucketAndPos(e){let r=await this._findPlace(e);if(r.existingChild!=null&&r.existingChild.key!==e){let n=new t(this._options,r.bucket,r.pos);r.bucket._putObjectAt(r.pos,n);let o=await n._findPlace(r.existingChild.hash);return o.bucket._putAt(o,r.existingChild.key,r.existingChild.value),n._findNewBucketAndPos(r.hash)}return r}_putAt(e,r,n){this._putObjectAt(e.pos,{key:r,value:n,hash:e.hash})}_putObjectAt(e,r){this._children.get(e)==null&&this._popCount++,this._children.set(e,r)}_delAt(e){if(e===-1)throw new Error("Invalid position");this._children.get(e)!=null&&this._popCount--,this._children.unset(e),this._level()}_level(){if(this._parent!=null&&this._popCount<=1)if(this._popCount===1){let e=this._children.find(pl);if(e!=null&&!(e instanceof t)){let r=e.hash;r.untake(this._options.bits);let n={pos:this._posAtParent,hash:r,bucket:this._parent};this._parent._putAt(n,e.key,e.value)}}else this._parent._delAt(this._posAtParent)}_at(e){return this._children.get(e)}};function pl(t){return!!t}function ml(t,e){return t.key}function yl(t){return t}async function va(t,e,r){let n=[];for(let o of t._children.compactArray())if(o instanceof Ne)await va(o,e,r);else{let i=await e(o);n.push({bitField:t._children.bitField(),children:i})}return r(n)}var gl=[255,254,252,248,240,224,192,128],wl=[1,3,7,15,31,63,127,255],Gr=class{_value;_currentBytePos;_currentBitPos;constructor(e){this._value=e,this._currentBytePos=e.length-1,this._currentBitPos=7}availableBits(){return this._currentBitPos+1+this._currentBytePos*8}totalBits(){return this._value.length*8}take(e){let r=e,n=0;for(;r>0&&this._haveBits();){let o=this._value[this._currentBytePos],i=this._currentBitPos+1,s=Math.min(i,r),a=xl(o,i-s,s);n=(n<<s)+a,r-=s,this._currentBitPos-=s,this._currentBitPos<0&&(this._currentBitPos=7,this._currentBytePos--)}return n}untake(e){for(this._currentBitPos+=e;this._currentBitPos>7;)this._currentBitPos-=8,this._currentBytePos+=1}_haveBits(){return this._currentBytePos>=0}};function xl(t,e,r){let n=bl(e,r);return(t&n)>>>e}function bl(t,e){return gl[t]&wl[Math.min(e+t-1,7)]}function ka(t){function e(r){return r instanceof Wr?r:new Wr(r,t)}return e}var Wr=class{_value;_hashFn;_depth;_availableBits;_currentBufferIndex;_buffers;constructor(e,r){if(!(e instanceof Uint8Array))throw new Error("can only hash Uint8Arrays");this._value=e,this._hashFn=r,this._depth=-1,this._availableBits=0,this._currentBufferIndex=0,this._buffers=[]}async take(e){let r=e;for(;this._availableBits<r;)await this._produceMoreBits();let n=0;for(;r>0;){let o=this._buffers[this._currentBufferIndex],i=Math.min(o.availableBits(),r),s=o.take(i);n=(n<<i)+s,r-=i,this._availableBits-=i,o.availableBits()===0&&this._currentBufferIndex++}return n}untake(e){let r=e;for(;r>0;){let n=this._buffers[this._currentBufferIndex],o=Math.min(n.totalBits()-n.availableBits(),r);n.untake(o),r-=o,this._availableBits+=o,this._currentBufferIndex>0&&n.totalBits()===n.availableBits()&&(this._depth--,this._currentBufferIndex--)}}async _produceMoreBits(){this._depth++;let e=this._depth>0?Ct([this._value,Uint8Array.from([this._depth])]):this._value,r=await this._hashFn(e),n=new Gr(r);this._buffers.push(n),this._availableBits+=n.availableBits()}};function _a(t){if(t==null||t.hashFn==null)throw new Error("please define an options.hashFn");let e={bits:t.bits??8,hash:ka(t.hashFn)};return new Ne(e)}var El=async function(t){return(await ga.encode(t)).slice(0,8).reverse()},vl=async(t,e,r)=>{let n=(e.tableSize()-1).toString(16).length;await Promise.all(t.map(async o=>{if(o.Name==null)throw new Error("Unexpected Link without a Name");if(o.Name.length===n){let i=parseInt(o.Name,16);e._putObjectAt(i,new Ne({hash:r._options.hash,bits:r._options.bits},e,i));return}await r.put(o.Name.substring(2),!0)}))},Ia=(t,e)=>t.toString(16).toUpperCase().padStart(e,"0").substring(0,e),kl=t=>{let e=t.bucket,r=[];for(;e._parent!=null;)r.push(e),e=e._parent;return r.push(e),r.reverse()};async function*Uo(t,e,r,n,o,i){if(o==null){if(t.Data==null)throw new L("No data in PBNode");let _;try{_=O.unmarshal(t.Data)}catch(h){throw new L(h.message)}if(_.type!=="hamt-sharded-directory")throw new L("Not a HAMT");if(_.fanout==null)throw new L("Missing fanout");let c=_a({hashFn:El,bits:Math.log2(Number(_.fanout))});o={rootBucket:c,hamtDepth:1,lastBucket:c}}let s=(o.lastBucket.tableSize()-1).toString(16).length;await vl(t.Links,o.lastBucket,o.rootBucket);let a=await o.rootBucket._findNewBucketAndPos(e),u=Ia(a.pos,s),l=kl(a);l.length>o.hamtDepth&&(o.lastBucket=l[o.hamtDepth],u=Ia(o.lastBucket._posAtParent,s));let d=t.Links.find(_=>{if(_.Name==null)return!1;let c=_.Name.substring(0,s),h=_.Name.substring(s);return!(c!==u||h!==""&&h!==e)});if(d==null)return;if(d.Name!=null&&d.Name.substring(s)===e){yield{cid:d.Hash,name:d.Name.substring(s),rest:r};return}o.hamtDepth++;let p=await N(n.get(d.Hash,i));t=ce(p),i?.yieldSubShards===!0&&(yield{cid:d.Hash,name:d.Name??"",rest:[e,...r]}),yield*Uo(t,e,r,n,o,i)}async function*Aa(t,e,r,n){let o=await N(r.get(t,n)),i;try{i=ce(o)}catch(a){throw new L(a.message)}if(i.Data==null)throw new L("no data in PBNode");let s;try{s=O.unmarshal(i.Data)}catch(a){throw new L(a.message)}if(s.type==="directory"||s.type==="hamt-sharded-directory"&&n?.translateHamtPath===!1){let a=i.Links.find(u=>u.Name===e[0]);if(a==null)throw new X(`No link "${e[0]}" found under ${t}`);yield{cid:a.Hash,name:e[0],rest:e.slice(1)}}else if(s.type==="hamt-sharded-directory"){let a=!1;for await(let u of Uo(i,e[0],e.slice(1),r,void 0,n))u.name===e[0]&&(a=!0),yield u;if(!a)throw new X(`No link "${e[0]}" found under ${t}`)}}async function*Ta(t,e,r,n){if(e.length!==0)throw new ot(`Cannot load path /${e.join("/")} from identity block`)}async function*Sa(t,e,r,n){let o=await N(r.get(t,n)),i=Er(o),s=at(i,e);yield{cid:t,name:s.path,rest:s.rest}}async function*Ba(t,e,r,n){if(e.length!==0)throw new X(`Cannot load path /${e.join("/")} from raw block`)}var Il={[rt]:Aa,[Qe]:Ba,[dr]:Po,81:Po,[Pr]:da,[Bt.code]:Ta,[br]:Sa};async function*Jr(t,e,r={}){for(t=t.toString(),t.startsWith("/ipfs/")&&(t=t.substring(6));t.endsWith("/");)t=t.substring(0,t.length-1);let[n,...o]=t.split(/(?<!\\)\//g).filter(Boolean),i=B.parse(n),s=[i],a=`${i}`;for(yield{cid:i,name:a,path:a,roots:s,remainder:o};o.length>0;){let u=Il[i.code];if(u==null)throw new it(`No resolver for code ${i.code}`);let l=!1;for await(let d of u(i,o,e,r)){if(i=d.cid,l=!s[s.length-1].equals(i),o=d.rest,!l)break;s=[...s,d.cid],a=`${a}/${d.name}`,yield{cid:d.cid,name:d.name,path:a,roots:s,remainder:d.rest}}if(!l)break}if(r?.signal?.throwIfAborted(),o.length!==0)throw new X(`Could not resolve path /${o.join("/")} under ${t}`)}function Al(t){return t[Symbol.asyncIterator]!=null}function Tl(t){if(Al(t))return(async()=>{let r;for await(let n of t)r=n;return r})();let e;for(let r of t)e=r;return e}var Ca=Tl;async function Ro(t,e,r,n,o){let i=await N(n.get(t,o)),s=_e(i);return{type:"object",cid:t,name:e,path:r,object:s,node:i}}async function Na(t,e,r,n,o){let i=await N(n.get(t,o)),s=Ur(i);return{type:"object",cid:t,name:e,path:r,object:s,node:i}}function jt(t,e,r,n){let o=BigInt(t.length),i=BigInt(e+o);return r>=i||n<e?new Uint8Array(0):(n>=e&&n<i&&(t=t.subarray(0,Number(n-e))),r>=e&&r<i&&(t=t.subarray(Number(r-e))),t)}var Qr=(t,e=0,r=t)=>{let n=BigInt(t),o=BigInt(e??0),i=BigInt(r);if(i!==n&&(i=o+i),i>n&&(i=n),o<0n)throw new de("Offset must be greater than or equal to 0");if(o>n)throw new de("Offset must be less than the file size");if(i<0n)throw new de("Length must be greater than or equal to 0");if(i>n)throw new de("Length must be less than the file size");return{start:o,end:i}};function Xr(t,e){async function*r(n={}){let{start:o,end:i}=Qr(t.length,n.offset,n.length),s=jt(t,0n,o,i);n.onProgress?.(new F(e,{bytesRead:BigInt(s.byteLength),totalBytes:i-o,fileSize:BigInt(t.byteLength)})),yield s}return r}async function Da(t,e,r,n,o){let i=je(t.multihash.bytes);return{type:"identity",cid:t,name:e,path:r,content:Xr(i.digest,"unixfs:exporter:progress:identity"),size:BigInt(i.bytes.length),node:i.bytes}}async function La(t,e,r,n,o){let i=await N(n.get(t,o)),s=Er(i);return{type:"object",cid:t,name:e,path:r,object:s,node:i}}async function Pa(t,e,r,n,o){let i=await N(n.get(t,o));return{type:"raw",cid:t,name:e,path:r,content:Xr(i,"unixfs:exporter:progress:raw"),size:BigInt(i.length),node:i}}function Ua(t,e,r,n){async function*o(i={}){let s=i.offset??0,a=i.length??e.Links.length,u=e.Links.slice(s,a);i.onProgress?.(new F("unixfs:exporter:walk:directory",{cid:t})),yield*u.map(l=>({cid:l.Hash,name:l.Name??"",path:`${n}/${l.Name??""}`}))}return o}var Yr=globalThis.CustomEvent??Event;async function*Gt(t,e={}){let r=e.concurrency??1/0;r<1&&(r=1/0);let n=e.ordered??!1,o=new EventTarget,i=[],s=$(),a=$(),u=!1,l,d=!1;o.addEventListener("task-complete",()=>{a.resolve()}),Promise.resolve().then(async()=>{try{for await(let h of t){if(i.length===r&&(s=$(),await s.promise),d)break;let m={done:!1};i.push(m),h().then(A=>{m.done=!0,m.ok=!0,m.value=A,o.dispatchEvent(new Yr("task-complete"))},A=>{m.done=!0,m.err=A,o.dispatchEvent(new Yr("task-complete"))})}u=!0,o.dispatchEvent(new Yr("task-complete"))}catch(h){l=h,o.dispatchEvent(new Yr("task-complete"))}});function p(){return n?i[0]?.done:!!i.find(h=>h.done)}function*_(){for(;i.length>0&&i[0].done;){let h=i[0];if(i.shift(),h.ok)yield h.value;else throw d=!0,s.resolve(),h.err;s.resolve()}}function*c(){for(;p();)for(let h=0;h<i.length;h++)if(i[h].done){let m=i[h];if(i.splice(h,1),h--,m.ok)yield m.value;else throw d=!0,s.resolve(),m.err;s.resolve()}}for(;;){if(p()||(a=$(),await a.promise),l!=null||(n?yield*_():yield*c(),l!=null))throw l;if(u&&i.length===0)break}}async function Ra(t,e,r,n,o,i,s){if(e instanceof Uint8Array){let l=jt(e,n,o,i);r.push(l);return}if(e.Data==null)throw new L("no data in PBNode");let a;try{a=O.unmarshal(e.Data)}catch(l){throw new L(l.message)}if(a.data!=null){let l=a.data,d=jt(l,n,o,i);r.push(d),n+=BigInt(d.byteLength)}let u=[];if(e.Links.length!==a.blockSizes.length)throw new L("Inconsistent block sizes and dag links");for(let l=0;l<e.Links.length;l++){let d=e.Links[l],p=n,_=p+a.blockSizes[l];if((o>=p&&o<_||i>=p&&i<=_||o<p&&i>_)&&u.push({link:d,blockStart:n}),n=_,n>i)break}await Dr(u,l=>Ge(l,d=>async()=>{let p=await N(t.get(d.link.Hash,s));return{...d,block:p}}),l=>Gt(l,{ordered:!0,concurrency:s.blockReadConcurrency}),async l=>{for await(let{link:d,block:p,blockStart:_}of l){let c;switch(d.Hash.code){case rt:c=ce(p);break;case Qe:c=p;break;default:r.end(new L(`Unsupported codec: ${d.Hash.code}`));return}let h=new Tt({concurrency:1});h.on("error",m=>{r.end(m)}),h.add(async()=>{s.onProgress?.(new F("unixfs:exporter:walk:file",{cid:d.Hash})),await Ra(t,c,r,_,o,i,s)}),await h.onIdle()}}),n>=i&&r.end()}function Fo(t,e,r,n,o){async function*i(s={}){let a=r.fileSize();if(a===void 0)throw new Error("File was a directory");let{start:u,end:l}=Qr(a,s.offset,s.length);if(l===0n)return;let d=0n,p=l-u,_=Ke();s.onProgress?.(new F("unixfs:exporter:walk:file",{cid:t})),Ra(o,e,_,0n,u,l,s).catch(c=>{_.end(c)});for await(let c of _)if(c!=null){if(d+=BigInt(c.byteLength),d>p)throw _.end(),new Hr("Read too many bytes - the file size reported by the UnixFS data in the root node may be incorrect");d===p&&_.end(),s.onProgress?.(new F("unixfs:exporter:progress:unixfs:file",{bytesRead:d,totalBytes:p,fileSize:a})),yield c}if(d<p)throw new Vr("Traversed entire DAG but did not read enough bytes")}return i}async function*Fa(t,e,r,n){let o=t.Links;if(t.Data==null)throw new L("no data in PBNode");let i;try{i=O.unmarshal(t.Data)}catch(u){throw new L(u.message)}if(i.fanout==null)throw new L("missing fanout");let s=(i.fanout-1n).toString(16).length,a=Dr(o,u=>Ge(u,l=>async()=>{let d=l.Name!=null?l.Name.substring(s):null;if(d!=null&&d!=="")return{entries:[{cid:l.Hash,name:d,path:`${e}/${d}`}]};{let p=await N(r.get(l.Hash,n));return t=ce(p),n.onProgress?.(new F("unixfs:exporter:walk:hamt-sharded-directory",{cid:l.Hash})),{entries:Fa(t,e,r,n)}}}),u=>Gt(u,{ordered:!0,concurrency:n.blockReadConcurrency}));for await(let{entries:u}of a)yield*u}function za(t,e,r,n,o){function i(s={}){return s.onProgress?.(new F("unixfs:exporter:walk:hamt-sharded-directory",{cid:t})),Fa(e,n,o,s)}return i}var Sl={raw:Fo,file:Fo,directory:Ua,"hamt-sharded-directory":za,metadata:(t,e,r,n)=>()=>[],symlink:(t,e,r,n)=>()=>[]};async function Ma(t,e,r,n,o){let i=await N(n.get(t,o)),s;try{s=ce(i)}catch(l){throw new L(l.message)}if(s.Data==null)throw new L("no data in PBNode");let a;try{a=O.unmarshal(s.Data)}catch(l){throw new L(l.message)}let u=Sl[a.type](t,s,a,r,n);if(u==null)throw new X("could not find content exporter");return a.isDirectory()?{type:"directory",cid:t,name:e,path:r,entries:u,unixfs:a,node:s}:{type:"file",cid:t,name:e,path:r,content:u,unixfs:a,node:s,size:a.fileSize()}}var Bl={[rt]:Ma,[Qe]:Pa,[dr]:Ro,81:Ro,[Pr]:Na,[Bt.code]:Da,[br]:La};async function $a(t,e,r={}){let n,o;if(t instanceof String||typeof t=="string"){let s=await Ca(Jr(t,e,r));if(s==null)throw new X(`Could not walk path to ${t}`);n=s.cid,o=s.name,t=s.path}else if(B.asCID(t)===t||t instanceof B)n=t,o=t=n.toString();else throw new de("Path must be string or CID");let i=Bl[n.code];if(i==null)throw new it(`No resolver for code ${n.code}`);return i(n,o,t,e,r)}var zo=class{root;path;constructor(...e){let r=e[0],n=e[1];if(typeof r=="string")n=r,r=void 0;else if(e.length<2)throw new Error("path or CID and path must be specified");n.startsWith("/")||(n=`/${n}`),this.root=r,this.path=n}async*traverse(e,r,n,o){for await(let i of Jr(`${this.root??e}${this.path}`,r,o)){let s=await $a(i.cid,r,o);yield ae({cid:s.cid,bytes:s.node instanceof Uint8Array?s.node:oa(s.node),codec:await n(i.cid.code)})}}};function Cl(t){return new zr(t)}return Ga(Nl);})();
|
|
3
3
|
return HeliaCar}));
|
|
4
4
|
//# sourceMappingURL=index.min.js.map
|