@helia/car 6.0.6 → 6.0.7-bbf05cb7

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 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 mc=Object.create;var lr=Object.defineProperty;var yc=Object.getOwnPropertyDescriptor;var gc=Object.getOwnPropertyNames;var wc=Object.getPrototypeOf,xc=Object.prototype.hasOwnProperty;var Ye=(t,e)=>()=>{try{return e||t((e={exports:{}}).exports,e),e.exports}catch(r){throw e=0,r}},j=(t,e)=>{for(var r in e)lr(t,r,{get:e[r],enumerable:!0})},ti=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of gc(e))!xc.call(t,i)&&i!==r&&lr(t,i,{get:()=>e[i],enumerable:!(n=yc(e,i))||n.enumerable});return t};var Bt=(t,e,r)=>(r=t!=null?mc(wc(t)):{},ti(e||!t||!t.__esModule?lr(r,"default",{value:t,enumerable:!0}):r,t)),bc=t=>ti(lr({},"__esModule",{value:!0}),t);var Es=Ye((Fd,bs)=>{bs.exports=jn;var xs=128,Ju=127,Ku=~Ju,Qu=Math.pow(2,31);function jn(t,e,r){if(Number.MAX_SAFE_INTEGER&&t>Number.MAX_SAFE_INTEGER)throw jn.bytes=0,new RangeError("Could not encode varint");e=e||[],r=r||0;for(var n=r;t>=Qu;)e[r++]=t&255|xs,t/=128;for(;t&Ku;)e[r++]=t&255|xs,t>>>=7;return e[r]=t|0,jn.bytes=r-n+1,e}});var _s=Ye((zd,ks)=>{ks.exports=Gn;var Xu=128,vs=127;function Gn(t,n){var r=0,n=n||0,i=0,o=n,s,a=t.length;do{if(o>=a||i>49)throw Gn.bytes=0,new RangeError("Could not decode varint");s=t[o++],r+=i<28?(s&vs)<<i:(s&vs)*Math.pow(2,i),i+=7}while(s>=Xu);return Gn.bytes=o-n,r}});var As=Ye(($d,Is)=>{var Zu=Math.pow(2,7),el=Math.pow(2,14),tl=Math.pow(2,21),rl=Math.pow(2,28),nl=Math.pow(2,35),ol=Math.pow(2,42),il=Math.pow(2,49),sl=Math.pow(2,56),al=Math.pow(2,63);Is.exports=function(t){return t<Zu?1:t<el?2:t<tl?3:t<rl?4:t<nl?5:t<ol?6:t<il?7:t<sl?8:t<al?9:10}});var Dr=Ye((Hd,Ts)=>{Ts.exports={encode:Es(),decode:_s(),encodingLength:As()}});var qa=Ye((O0,Va)=>{"use strict";Va.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 i=!1;n===-1?(n=this._data.length,this._setBit(e),this._changedData=!0):i=!0,this._setInternalPos(n,e,r,i),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,i=r;for(;n<this.length;){let o=this.get(n);i=e(i,o,n),n++}return i}find(e){let r=0,n,i;for(;r<this.length&&!n;)i=this.get(r),n=e(i),r++;return n?i:void 0}_internalPositionFor(e,r){let n=this._bytePosFor(e,r);if(n>=this._bitArrays.length)return-1;let i=this._bitArrays[n],o=e-n*7;if(!((i&1<<o)>0))return-1;let a=this._bitArrays.slice(0,n).reduce(Yf,0),c=~(4294967295<<o+1),u=Ha(i&c);return a+u-1}_bytePosFor(e,r){let n=Math.floor(e/7),i=n+1;for(;!r&&this._bitArrays.length<i;)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,i){let o=this._data,s=[r,n];if(i)this._sortData(),o[e]=s;else{if(o.length)if(o[o.length-1][0]>=r)o.push(s);else if(o[0][0]<=r)o.unshift(s);else{let a=Math.round(o.length/2);this._data=o.slice(0,a).concat(s).concat(o.slice(a))}else this._data.push(s);this._changedData=!0,this._changedLength=!0}}_unsetInternalPos(e){this._data.splice(e,1)}_sortData(){this._changedData&&this._data.sort(Jf),this._changedData=!1}bitField(){let e=[],r=8,n=0,i=0,o,s=this._bitArrays.slice();for(;s.length||n;){n===0&&(o=s.shift(),n=7);let c=Math.min(n,r),u=~(255<<c),f=o&u;i|=f<<8-r,o=o>>>c,n-=c,r-=c,(!r||!n&&!s.length)&&(e.push(i),i=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(Kf)}};function Yf(t,e){return t+Ha(e)}function Ha(t){let e=t;return e=e-(e>>1&1431655765),e=(e&858993459)+(e>>2&858993459),(e+(e>>4)&252645135)*16843009>>24}function Jf(t,e){return t[0]-e[0]}function Kf(t){return t[1]}});var uc=Ye((Zw,Ko)=>{"use strict";var lh=Object.prototype.hasOwnProperty,H="~";function ar(){}Object.create&&(ar.prototype=Object.create(null),new ar().__proto__||(H=!1));function fh(t,e,r){this.fn=t,this.context=e,this.once=r||!1}function cc(t,e,r,n,i){if(typeof r!="function")throw new TypeError("The listener must be a function");var o=new fh(r,n||t,i),s=H?H+e:e;return t._events[s]?t._events[s].fn?t._events[s]=[t._events[s],o]:t._events[s].push(o):(t._events[s]=o,t._eventsCount++),t}function wn(t,e){--t._eventsCount===0?t._events=new ar:delete t._events[e]}function F(){this._events=new ar,this._eventsCount=0}F.prototype.eventNames=function(){var e=[],r,n;if(this._eventsCount===0)return e;for(n in r=this._events)lh.call(r,n)&&e.push(H?n.slice(1):n);return Object.getOwnPropertySymbols?e.concat(Object.getOwnPropertySymbols(r)):e};F.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 i=0,o=n.length,s=new Array(o);i<o;i++)s[i]=n[i].fn;return s};F.prototype.listenerCount=function(e){var r=H?H+e:e,n=this._events[r];return n?n.fn?1:n.length:0};F.prototype.emit=function(e,r,n,i,o,s){var a=H?H+e:e;if(!this._events[a])return!1;var c=this._events[a],u=arguments.length,f,h;if(c.fn){switch(c.once&&this.removeListener(e,c.fn,void 0,!0),u){case 1:return c.fn.call(c.context),!0;case 2:return c.fn.call(c.context,r),!0;case 3:return c.fn.call(c.context,r,n),!0;case 4:return c.fn.call(c.context,r,n,i),!0;case 5:return c.fn.call(c.context,r,n,i,o),!0;case 6:return c.fn.call(c.context,r,n,i,o,s),!0}for(h=1,f=new Array(u-1);h<u;h++)f[h-1]=arguments[h];c.fn.apply(c.context,f)}else{var m=c.length,g;for(h=0;h<m;h++)switch(c[h].once&&this.removeListener(e,c[h].fn,void 0,!0),u){case 1:c[h].fn.call(c[h].context);break;case 2:c[h].fn.call(c[h].context,r);break;case 3:c[h].fn.call(c[h].context,r,n);break;case 4:c[h].fn.call(c[h].context,r,n,i);break;default:if(!f)for(g=1,f=new Array(u-1);g<u;g++)f[g-1]=arguments[g];c[h].fn.apply(c[h].context,f)}}return!0};F.prototype.on=function(e,r,n){return cc(this,e,r,n,!1)};F.prototype.once=function(e,r,n){return cc(this,e,r,n,!0)};F.prototype.removeListener=function(e,r,n,i){var o=H?H+e:e;if(!this._events[o])return this;if(!r)return wn(this,o),this;var s=this._events[o];if(s.fn)s.fn===r&&(!i||s.once)&&(!n||s.context===n)&&wn(this,o);else{for(var a=0,c=[],u=s.length;a<u;a++)(s[a].fn!==r||i&&!s[a].once||n&&s[a].context!==n)&&c.push(s[a]);c.length?this._events[o]=c.length===1?c[0]:c:wn(this,o)}return this};F.prototype.removeAllListeners=function(e){var r;return e?(r=H?H+e:e,this._events[r]&&wn(this,r)):(this._events=new ar,this._eventsCount=0),this};F.prototype.off=F.prototype.removeListener;F.prototype.addListener=F.prototype.on;F.prefixed=H;F.EventEmitter=F;typeof Ko<"u"&&(Ko.exports=F)});var gh={};j(gh,{BlockExporter:()=>Oo,CIDPath:()=>zo,GraphSearch:()=>Fo,SubgraphExporter:()=>er,UnixFSExporter:()=>tr,UnixFSPath:()=>ei,breadthFirstWalker:()=>yt,car:()=>yh,depthFirstWalker:()=>mt,naturalOrderWalker:()=>ya});var Ec=["Object","RegExp","Date","Error","Map","Set","WeakMap","WeakSet","ArrayBuffer","SharedArrayBuffer","DataView","Promise","URL","HTMLElement","Int8Array","Uint8ClampedArray","Int16Array","Uint16Array","Int32Array","Uint32Array","Float32Array","Float64Array","BigInt64Array","BigUint64Array","Tagged"];function xn(t){if(t===null)return"null";if(t===void 0)return"undefined";if(t===!0||t===!1)return"boolean";let e=typeof t;if(e==="string"||e==="number"||e==="bigint"||e==="symbol")return e;if(e==="function")return"Function";if(Array.isArray(t))return"Array";if(t instanceof Uint8Array)return"Uint8Array";if(t.constructor===Object)return"Object";let r=vc(t);return r||"Object"}function vc(t){let e=Object.prototype.toString.call(t).slice(8,-1);if(Ec.includes(e))return e}var l=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}static equals(e,r){return e===r||e.major===r.major&&e.name===r.name}};l.uint=new l(0,"uint",!0);l.negint=new l(1,"negint",!0);l.bytes=new l(2,"bytes",!0);l.string=new l(3,"string",!0);l.array=new l(4,"array",!1);l.map=new l(5,"map",!1);l.tag=new l(6,"tag",!1);l.float=new l(7,"float",!0);l.false=new l(7,"false",!0);l.true=new l(7,"true",!0);l.null=new l(7,"null",!0);l.undefined=new l(7,"undefined",!0);l.break=new l(7,"break",!0);var d=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 St=globalThis.process&&!globalThis.process.browser&&globalThis.Buffer&&typeof globalThis.Buffer.isBuffer=="function",kc=new TextEncoder;function fr(t){return St&&globalThis.Buffer.isBuffer(t)}function Re(t){return t instanceof Uint8Array?fr(t)?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):t:Uint8Array.from(t)}var _c=24,Ic=200,Je=St?t=>t.length>=_c?globalThis.Buffer.from(t):ri(t):t=>t.length>=Ic?kc.encode(t):ri(t),ie=t=>Uint8Array.from(t),oi=St?(t,e,r)=>fr(t)?new Uint8Array(t.subarray(e,r)):t.slice(e,r):(t,e,r)=>t.slice(e,r),ii=St?(t,e)=>(t=t.map(r=>r instanceof Uint8Array?r:globalThis.Buffer.from(r)),Re(globalThis.Buffer.concat(t,e))):(t,e)=>{let r=new Uint8Array(e),n=0;for(let i of t)n+i.length>r.length&&(i=i.subarray(0,r.length-n)),r.set(i,n),n+=i.length;return r},bn=St?t=>globalThis.Buffer.allocUnsafe(t):t=>new Uint8Array(t);function Ke(t,e){if(fr(t)&&fr(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 ri(t){let e=[],r=0;for(let n=0;n<t.length;n++){let i=t.charCodeAt(n);i<128?e[r++]=i:i<2048?(e[r++]=i>>6|192,e[r++]=i&63|128):(i&64512)===55296&&n+1<t.length&&(t.charCodeAt(n+1)&64512)===56320?(i=65536+((i&1023)<<10)+(t.charCodeAt(++n)&1023),e[r++]=i>>18|240,e[r++]=i>>12&63|128,e[r++]=i>>6&63|128,e[r++]=i&63|128):(i>=55296&&i<=57343&&(i=65533),e[r++]=i>>12|224,e[r++]=i>>6&63|128,e[r++]=i&63|128)}return e}var ni=4096;function si(t){let e=t.length;if(e<=ni)return String.fromCharCode.apply(String,t);let r="",n=0;for(;n<e;)r+=String.fromCharCode.apply(String,t.slice(n,n+=ni));return r}var Ac=256,Ct=class{constructor(e=Ac){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)}pushByte(e){let r=this.chunks[this.chunks.length-1];this.cursor>this.maxCursor&&(r=bn(this.chunkSize),this.chunks.push(r),this.maxCursor+=r.length,this._initReuseChunk===null&&(this._initReuseChunk=r));let n=r.length-(this.maxCursor-this.cursor)-1;r[n]=e,this.cursor++}push(e){let r=this.chunks[this.chunks.length-1];if(this.cursor+e.length<=this.maxCursor+1){let i=r.length-(this.maxCursor-this.cursor)-1;r.set(e,i)}else{if(r){let i=r.length-(this.maxCursor-this.cursor)-1;i<r.length&&(this.chunks[this.chunks.length-1]=r.subarray(0,i),this.maxCursor=this.cursor-1)}e.length<64&&e.length<this.chunkSize?(r=bn(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=oi(n,0,this.cursor)}else r=ii(this.chunks,this.cursor);return e&&this.reset(),r}},hr=class{constructor(e){this.dest=e,this.cursor=0,this.chunks=[e]}reset(){this.cursor=0}pushByte(e){if(this.cursor>=this.dest.length)throw new Error("write out of bounds, destination buffer is too small");this.dest[this.cursor++]=e}push(e){if(this.cursor+e.length>this.dest.length)throw new Error("write out of bounds, destination buffer is too small");this.dest.set(e,this.cursor),this.cursor+=e.length}toBytes(e=!1){let r=this.dest.subarray(0,this.cursor);return e&&this.reset(),r}};var y="CBOR decode error:",Me="CBOR encode error:",Dt=[];Dt[23]=1;Dt[24]=2;Dt[25]=3;Dt[26]=5;Dt[27]=9;function pe(t,e,r){if(t.length-e<r)throw new Error(`${y} not enough data for type`)}var P=[24,256,65536,4294967296,BigInt("18446744073709551616")];function G(t,e,r){pe(t,e,1);let n=t[e];if(r.strict===!0&&n<P[0])throw new Error(`${y} integer encoded in more bytes than necessary (strict decode)`);return n}function W(t,e,r){pe(t,e,2);let n=t[e]<<8|t[e+1];if(r.strict===!0&&n<P[1])throw new Error(`${y} integer encoded in more bytes than necessary (strict decode)`);return n}function Y(t,e,r){pe(t,e,4);let n=t[e]*16777216+(t[e+1]<<16)+(t[e+2]<<8)+t[e+3];if(r.strict===!0&&n<P[2])throw new Error(`${y} integer encoded in more bytes than necessary (strict decode)`);return n}function J(t,e,r){pe(t,e,8);let n=t[e]*16777216+(t[e+1]<<16)+(t[e+2]<<8)+t[e+3],i=t[e+4]*16777216+(t[e+5]<<16)+(t[e+6]<<8)+t[e+7],o=(BigInt(n)<<BigInt(32))+BigInt(i);if(r.strict===!0&&o<P[3])throw new Error(`${y} integer encoded in more bytes than necessary (strict decode)`);if(o<=Number.MAX_SAFE_INTEGER)return Number(o);if(r.allowBigInt===!0)return o;throw new Error(`${y} integers outside of the safe integer range are not supported`)}function ai(t,e,r,n){return new d(l.uint,G(t,e+1,n),2)}function ci(t,e,r,n){return new d(l.uint,W(t,e+1,n),3)}function ui(t,e,r,n){return new d(l.uint,Y(t,e+1,n),5)}function li(t,e,r,n){return new d(l.uint,J(t,e+1,n),9)}function se(t,e){return D(t,0,e.value)}function D(t,e,r){if(r<P[0]){let n=Number(r);t.pushByte(e|n)}else if(r<P[1]){let n=Number(r);t.push([e|24,n])}else if(r<P[2]){let n=Number(r);t.push([e|25,n>>>8,n&255])}else if(r<P[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<P[4]){let i=[e|27,0,0,0,0,0,0,0],o=Number(n&BigInt(4294967295)),s=Number(n>>BigInt(32)&BigInt(4294967295));i[8]=o&255,o=o>>8,i[7]=o&255,o=o>>8,i[6]=o&255,o=o>>8,i[5]=o&255,i[4]=s&255,s=s>>8,i[3]=s&255,s=s>>8,i[2]=s&255,s=s>>8,i[1]=s&255,t.push(i)}else throw new Error(`${y} encountered BigInt larger than allowable range`)}}se.encodedSize=function(e){return D.encodedSize(e.value)};D.encodedSize=function(e){return e<P[0]?1:e<P[1]?2:e<P[2]?3:e<P[3]?5:9};se.compareTokens=function(e,r){return e.value<r.value?-1:e.value>r.value?1:0};function fi(t,e,r,n){return new d(l.negint,-1-G(t,e+1,n),2)}function hi(t,e,r,n){return new d(l.negint,-1-W(t,e+1,n),3)}function di(t,e,r,n){return new d(l.negint,-1-Y(t,e+1,n),5)}var En=BigInt(-1),pi=BigInt(1);function mi(t,e,r,n){let i=J(t,e+1,n);if(typeof i!="bigint"){let o=-1-i;if(o>=Number.MIN_SAFE_INTEGER)return new d(l.negint,o,9)}if(n.allowBigInt!==!0)throw new Error(`${y} integers outside of the safe integer range are not supported`);return new d(l.negint,En-BigInt(i),9)}function dr(t,e){let r=e.value,n=typeof r=="bigint"?r*En-pi:r*-1-1;D(t,e.type.majorEncoded,n)}dr.encodedSize=function(e){let r=e.value,n=typeof r=="bigint"?r*En-pi:r*-1-1;return n<P[0]?1:n<P[1]?2:n<P[2]?3:n<P[3]?5:9};dr.compareTokens=function(e,r){return e.value<r.value?1:e.value>r.value?-1:0};function Nt(t,e,r,n){pe(t,e,r+n);let i=t.slice(e+r,e+r+n);return new d(l.bytes,i,r+n)}function yi(t,e,r,n){return Nt(t,e,1,r)}function gi(t,e,r,n){return Nt(t,e,2,G(t,e+1,n))}function wi(t,e,r,n){return Nt(t,e,3,W(t,e+1,n))}function xi(t,e,r,n){return Nt(t,e,5,Y(t,e+1,n))}function bi(t,e,r,n){let i=J(t,e+1,n);if(typeof i=="bigint")throw new Error(`${y} 64-bit integer bytes lengths not supported`);return Nt(t,e,9,i)}function pr(t){return t.encodedBytes===void 0&&(t.encodedBytes=l.equals(t.type,l.string)?Je(t.value):t.value),t.encodedBytes}function Qe(t,e){let r=pr(e);D(t,e.type.majorEncoded,r.length),t.push(r)}Qe.encodedSize=function(e){let r=pr(e);return D.encodedSize(r.length)+r.length};Qe.compareTokens=function(e,r){return Bc(pr(e),pr(r))};function Bc(t,e){return t.length<e.length?-1:t.length>e.length?1:Ke(t,e)}var Ei=new TextDecoder,Cc=32;function Dc(t,e,r){if(r-e<Cc){let i="";for(let o=e;o<r;o++){let s=t[o];if(s&128)return Ei.decode(t.subarray(e,r));i+=String.fromCharCode(s)}return i}return Ei.decode(t.subarray(e,r))}function Lt(t,e,r,n,i){let o=r+n;pe(t,e,o);let s=new d(l.string,Dc(t,e+r,e+o),o);return i.retainStringBytes===!0&&(s.byteValue=t.slice(e+r,e+o)),s}function vi(t,e,r,n){return Lt(t,e,1,r,n)}function ki(t,e,r,n){return Lt(t,e,2,G(t,e+1,n),n)}function _i(t,e,r,n){return Lt(t,e,3,W(t,e+1,n),n)}function Ii(t,e,r,n){return Lt(t,e,5,Y(t,e+1,n),n)}function Ai(t,e,r,n){let i=J(t,e+1,n);if(typeof i=="bigint")throw new Error(`${y} 64-bit integer string lengths not supported`);return Lt(t,e,9,i,n)}var Ti=Qe;function Xe(t,e,r,n){return new d(l.array,n,r)}function Bi(t,e,r,n){return Xe(t,e,1,r)}function Si(t,e,r,n){return Xe(t,e,2,G(t,e+1,n))}function Ci(t,e,r,n){return Xe(t,e,3,W(t,e+1,n))}function Di(t,e,r,n){return Xe(t,e,5,Y(t,e+1,n))}function Ni(t,e,r,n){let i=J(t,e+1,n);if(typeof i=="bigint")throw new Error(`${y} 64-bit integer array lengths not supported`);return Xe(t,e,9,i)}function Li(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${y} indefinite length items not allowed`);return Xe(t,e,1,1/0)}function mr(t,e){D(t,l.array.majorEncoded,e.value)}mr.compareTokens=se.compareTokens;mr.encodedSize=function(e){return D.encodedSize(e.value)};function Ze(t,e,r,n){return new d(l.map,n,r)}function Pi(t,e,r,n){return Ze(t,e,1,r)}function Ui(t,e,r,n){return Ze(t,e,2,G(t,e+1,n))}function Ri(t,e,r,n){return Ze(t,e,3,W(t,e+1,n))}function Mi(t,e,r,n){return Ze(t,e,5,Y(t,e+1,n))}function Oi(t,e,r,n){let i=J(t,e+1,n);if(typeof i=="bigint")throw new Error(`${y} 64-bit integer map lengths not supported`);return Ze(t,e,9,i)}function Fi(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${y} indefinite length items not allowed`);return Ze(t,e,1,1/0)}function yr(t,e){D(t,l.map.majorEncoded,e.value)}yr.compareTokens=se.compareTokens;yr.encodedSize=function(e){return D.encodedSize(e.value)};function zi(t,e,r,n){return new d(l.tag,r,1)}function $i(t,e,r,n){return new d(l.tag,G(t,e+1,n),2)}function Hi(t,e,r,n){return new d(l.tag,W(t,e+1,n),3)}function Vi(t,e,r,n){return new d(l.tag,Y(t,e+1,n),5)}function qi(t,e,r,n){return new d(l.tag,J(t,e+1,n),9)}function gr(t,e){D(t,l.tag.majorEncoded,e.value)}gr.compareTokens=se.compareTokens;gr.encodedSize=function(e){return D.encodedSize(e.value)};var wr=20,xr=21,br=22,Er=23;function Gi(t,e,r,n){if(n.allowUndefined===!1)throw new Error(`${y} undefined values are not supported`);return n.coerceUndefinedToNull===!0?new d(l.null,null,1):new d(l.undefined,void 0,1)}function Wi(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${y} indefinite length items not allowed`);return new d(l.break,void 0,1)}function vn(t,e,r){if(r){if(r.allowNaN===!1&&Number.isNaN(t))throw new Error(`${y} NaN values are not supported`);if(r.allowInfinity===!1&&(t===1/0||t===-1/0))throw new Error(`${y} Infinity values are not supported`)}return new d(l.float,t,e)}function Yi(t,e,r,n){return vn(vr(t,e+1),3,n)}function Ji(t,e,r,n){return vn(kr(t,e+1),5,n)}function Ki(t,e,r,n){return vn(Zi(t,e+1),9,n)}function Pt(t,e,r){let n=e.value;if(n===!1)t.pushByte(l.float.majorEncoded|wr);else if(n===!0)t.pushByte(l.float.majorEncoded|xr);else if(n===null)t.pushByte(l.float.majorEncoded|br);else if(n===void 0)t.pushByte(l.float.majorEncoded|Er);else{let i,o=!1;(!r||r.float64!==!0)&&(kn(n),i=vr(N,1),n===i||Number.isNaN(n)?(N[0]=249,t.push(N.slice(0,3)),o=!0):(_n(n),i=kr(N,1),n===i&&(N[0]=250,t.push(N.slice(0,5)),o=!0))),o||(Xi(n),i=Zi(N,1),N[0]=251,t.push(N.slice(0,9)))}}Pt.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){kn(n);let i=vr(N,1);if(n===i||Number.isNaN(n))return 3;if(_n(n),i=kr(N,1),n===i)return 5}return 9};var Qi=new ArrayBuffer(9),Q=new DataView(Qi,1),N=new Uint8Array(Qi,0);function kn(t){if(t===1/0)Q.setUint16(0,31744,!1);else if(t===-1/0)Q.setUint16(0,64512,!1);else if(Number.isNaN(t))Q.setUint16(0,32256,!1);else{Q.setFloat32(0,t);let e=Q.getUint32(0),r=(e&2139095040)>>23,n=e&8388607;if(r===255)Q.setUint16(0,31744,!1);else if(r===0)Q.setUint16(0,(e&2147483648)>>16|n>>13,!1);else{let i=r-127;i<-24?Q.setUint16(0,0):i<-14?Q.setUint16(0,(e&2147483648)>>16|1<<24+i,!1):Q.setUint16(0,(e&2147483648)>>16|i+15<<10|n>>13,!1)}}}function vr(t,e){if(t.length-e<2)throw new Error(`${y} 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,i=r&1023,o;return n===0?o=i*2**-24:n!==31?o=(i+1024)*2**(n-25):o=i===0?1/0:NaN,r&32768?-o:o}function _n(t){Q.setFloat32(0,t,!1)}function kr(t,e){if(t.length-e<4)throw new Error(`${y} not enough data for float32`);let r=(t.byteOffset||0)+e;return new DataView(t.buffer,r,4).getFloat32(0,!1)}function Xi(t){Q.setFloat64(0,t,!1)}function Zi(t,e){if(t.length-e<8)throw new Error(`${y} not enough data for float64`);let r=(t.byteOffset||0)+e;return new DataView(t.buffer,r,8).getFloat64(0,!1)}function Rc(t,e){let r=t.value;if(r===!1)return Uint8Array.of(l.float.majorEncoded|wr);if(r===!0)return Uint8Array.of(l.float.majorEncoded|xr);if(r===null)return Uint8Array.of(l.float.majorEncoded|br);if(r===void 0)return Uint8Array.of(l.float.majorEncoded|Er);if(!e){if(kn(r),r===vr(N,1)||Number.isNaN(r))return N[0]=249,N.slice(0,3);if(_n(r),r===kr(N,1))return N[0]=250,N.slice(0,5)}return Xi(r),N[0]=251,N.slice(0,9)}function ji(t,e){let r=t,n=e?.float64===!0,i=n?r._keyBytesFloat64:r._keyBytes;if(i!==void 0)return i;let o=Rc(t,n);return n?r._keyBytesFloat64=o:r._keyBytes=o,o}Pt.compareTokens=function(e,r,n){let i=ji(e,n),o=ji(r,n);return i.length!==o.length?i.length<o.length?-1:1:Ke(i,o)};function k(t,e,r){throw new Error(`${y} encountered invalid minor (${r}) for major ${t[e]>>>5}`)}function _r(t){return()=>{throw new Error(`${y} ${t}`)}}var p=[];for(let t=0;t<=23;t++)p[t]=k;p[24]=ai;p[25]=ci;p[26]=ui;p[27]=li;p[28]=k;p[29]=k;p[30]=k;p[31]=k;for(let t=32;t<=55;t++)p[t]=k;p[56]=fi;p[57]=hi;p[58]=di;p[59]=mi;p[60]=k;p[61]=k;p[62]=k;p[63]=k;for(let t=64;t<=87;t++)p[t]=yi;p[88]=gi;p[89]=wi;p[90]=xi;p[91]=bi;p[92]=k;p[93]=k;p[94]=k;p[95]=_r("indefinite length bytes/strings are not supported");for(let t=96;t<=119;t++)p[t]=vi;p[120]=ki;p[121]=_i;p[122]=Ii;p[123]=Ai;p[124]=k;p[125]=k;p[126]=k;p[127]=_r("indefinite length bytes/strings are not supported");for(let t=128;t<=151;t++)p[t]=Bi;p[152]=Si;p[153]=Ci;p[154]=Di;p[155]=Ni;p[156]=k;p[157]=k;p[158]=k;p[159]=Li;for(let t=160;t<=183;t++)p[t]=Pi;p[184]=Ui;p[185]=Ri;p[186]=Mi;p[187]=Oi;p[188]=k;p[189]=k;p[190]=k;p[191]=Fi;for(let t=192;t<=215;t++)p[t]=zi;p[216]=$i;p[217]=Hi;p[218]=Vi;p[219]=qi;p[220]=k;p[221]=k;p[222]=k;p[223]=k;for(let t=224;t<=243;t++)p[t]=_r("simple values are not supported");p[244]=k;p[245]=k;p[246]=k;p[247]=Gi;p[248]=_r("simple values are not supported");p[249]=Yi;p[250]=Ji;p[251]=Ki;p[252]=k;p[253]=k;p[254]=k;p[255]=Wi;var re=[];for(let t=0;t<24;t++)re[t]=new d(l.uint,t,1);for(let t=-1;t>=-24;t--)re[31-t]=new d(l.negint,t,1);re[64]=new d(l.bytes,new Uint8Array(0),1);re[96]=new d(l.string,"",1);re[128]=new d(l.array,0,1);re[160]=new d(l.map,0,1);re[244]=new d(l.false,!1,1);re[245]=new d(l.true,!0,1);re[246]=new d(l.null,null,1);function Ir(t){switch(t.type){case l.false:return ie([244]);case l.true:return ie([245]);case l.null:return ie([246]);case l.bytes:return t.value.length?void 0:ie([64]);case l.string:return t.value===""?ie([96]):void 0;case l.array:return t.value===0?ie([128]):void 0;case l.map:return t.value===0?ie([160]):void 0;case l.uint:return t.value<24?ie([Number(t.value)]):void 0;case l.negint:if(t.value>=-24)return ie([31-Number(t.value)])}}var Oc={float64:!1,mapSorter:Tn,quickEncodeToken:Ir},os=Object.freeze({mapSorter:zc,quickEncodeToken:Ir});function An(){let t=[];return t[l.uint.major]=se,t[l.negint.major]=dr,t[l.bytes.major]=Qe,t[l.string.major]=Ti,t[l.array.major]=mr,t[l.map.major]=yr,t[l.tag.major]=gr,t[l.float.major]=Pt,t}var Fe=An(),Ar=new Ct,tt=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(`${Me} object contains circular references`);return new t(r,e)}},xe={null:new d(l.null,null),undefined:new d(l.undefined,void 0),true:new d(l.true,!0),false:new d(l.false,!1),emptyArray:new d(l.array,0),emptyMap:new d(l.map,0)},ae={number(t,e,r,n){return!Number.isInteger(t)||!Number.isSafeInteger(t)?new d(l.float,t):t>=0?new d(l.uint,t):new d(l.negint,t)},bigint(t,e,r,n){return t>=BigInt(0)?new d(l.uint,t):new d(l.negint,t)},Uint8Array(t,e,r,n){return new d(l.bytes,t)},string(t,e,r,n){return new d(l.string,t)},boolean(t,e,r,n){return t?xe.true:xe.false},null(t,e,r,n){return xe.null},undefined(t,e,r,n){return xe.undefined},ArrayBuffer(t,e,r,n){return new d(l.bytes,new Uint8Array(t))},DataView(t,e,r,n){return new d(l.bytes,new Uint8Array(t.buffer,t.byteOffset,t.byteLength))},Array(t,e,r,n){if(!t.length)return r.addBreakTokens===!0?[xe.emptyArray,new d(l.break)]:xe.emptyArray;n=tt.createCheck(n,t);let i=[],o=0;for(let s of t)i[o++]=Ee(s,r,n);return r.addBreakTokens?[new d(l.array,t.length),i,new d(l.break)]:[new d(l.array,t.length),i]},Object(t,e,r,n){let i=e!=="Object",o=i?t.keys():Object.keys(t),s=i?t.size:o.length,a;if(s){a=new Array(s),n=tt.createCheck(n,t);let c=!i&&r.ignoreUndefinedProperties,u=0;for(let f of o){let h=i?t.get(f):t[f];c&&h===void 0||(a[u++]=[Ee(f,r,n),Ee(h,r,n)])}u<s&&(a.length=u)}return a?.length?(Fc(a,r),r.addBreakTokens?[new d(l.map,a.length),a,new d(l.break)]:[new d(l.map,a.length),a]):r.addBreakTokens===!0?[xe.emptyMap,new d(l.break)]:xe.emptyMap},Tagged(t,e,r,n){return[new d(l.tag,t.tag),Ee(t.value,r,n)]}};ae.Map=ae.Object;ae.Buffer=ae.Uint8Array;for(let t of"Uint8Clamped Uint16 Uint32 Int8 Int16 Int32 BigUint64 BigInt64 Float32 Float64".split(" "))ae[`${t}Array`]=ae.DataView;function Ee(t,e={},r){let n=xn(t),i=e&&e.typeEncoders&&e.typeEncoders[n]||ae[n];if(typeof i=="function"){let s=i(t,n,e,r);if(s!=null)return s}let o=ae[n];if(!o)throw new Error(`${Me} unsupported type: ${n}`);return o(t,n,e,r)}function Fc(t,e){let r=e.mapSorter;r&&t.sort((n,i)=>r(n,i,e))}function Tn(t,e,r){let n=Array.isArray(t[0])?t[0][0]:t[0],i=Array.isArray(e[0])?e[0][0]:e[0];if(n.type.major!==i.type.major)return n.type.compare(i.type);let o=n.type.major,s=Fe[o].compareTokens(n,i,r);return s===0&&console.warn("WARNING: complex key types used, CBOR key sorting guarantees are gone"),s}function zc(t,e){if(t[0]instanceof d&&e[0]instanceof d){let r=t[0],n=e[0];return r._keyBytes||(r._keyBytes=es(r.value)),n._keyBytes||(n._keyBytes=es(n.value)),Ke(r._keyBytes,n._keyBytes)}throw new Error("rfc8949MapSorter: complex key types are not supported yet")}function es(t){return Sn(t,Fe,os)}function et(t,e,r,n){if(Array.isArray(e))for(let i of e)et(t,i,r,n);else r[e.type.major](t,e,n)}var ts=l.uint.majorEncoded,rs=l.negint.majorEncoded,$c=l.bytes.majorEncoded,Hc=l.string.majorEncoded,ns=l.array.majorEncoded,In=l.map.majorEncoded,Vc=l.float.majorEncoded|wr,qc=l.float.majorEncoded|xr,jc=l.float.majorEncoded|br,Gc=l.float.majorEncoded|Er,Wc=BigInt(-1),Yc=BigInt(1);function be(t,e,r){r<24?t.pushByte(e|Number(r)):D(t,e,r)}function Jc(t){return t.addBreakTokens!==!0}function Kc(t,e,r,n,i){let o=r==="Map",s=o?e.keys():Object.keys(e),a=o?e.size:s.length;if(!a){t.pushByte(In);return}i=tt.createCheck(i,e);let c=!o&&n.ignoreUndefinedProperties,u=new Array(a),f=0;for(let h of s){let m=o?e.get(h):e[h];c&&m===void 0||(u[f++]=[Ee(h,n,i),m])}if(f===0){t.pushByte(In);return}f<a&&(u.length=f),u.sort((h,m)=>Tn(h,m,n)),be(t,In,f);for(let[h,m]of u)et(t,h,Fe,n),Bn(t,m,n,i)}function Bn(t,e,r,n){let i=xn(e),o=r.typeEncoders&&r.typeEncoders[i];if(o){let s=o(e,i,r,n);if(s!=null){et(t,s,Fe,r);return}}switch(i){case"null":t.pushByte(jc);return;case"undefined":t.pushByte(Gc);return;case"boolean":t.pushByte(e?qc:Vc);return;case"number":!Number.isInteger(e)||!Number.isSafeInteger(e)?Pt(t,new d(l.float,e),r):e>=0?be(t,ts,e):be(t,rs,e*-1-1);return;case"bigint":e>=BigInt(0)?be(t,ts,e):be(t,rs,e*Wc-Yc);return;case"string":{let s=Je(e);be(t,Hc,s.length),t.push(s);return}case"Uint8Array":be(t,$c,e.length),t.push(e);return;case"Array":if(!e.length){t.pushByte(ns);return}n=tt.createCheck(n,e),be(t,ns,e.length);for(let s of e)Bn(t,s,r,n);return;case"Object":case"Map":if(r.mapSorter===Tn)Kc(t,e,i,r,n);else{let s=ae.Object(e,i,r,n);et(t,s,Fe,r)}return;default:{let s=ae[i];if(!s)throw new Error(`${Me} unsupported type: ${i}`);let a=s(e,i,r,n);et(t,a,Fe,r)}}}function Sn(t,e,r,n){let i=n instanceof Uint8Array,o=i?new hr(n):Ar,s=Ee(t,r);if(!Array.isArray(s)&&r.quickEncodeToken){let a=r.quickEncodeToken(s);if(a)return i?(o.push(a),o.toBytes()):a;let c=e[s.type.major];if(c.encodedSize){let u=c.encodedSize(s,r);if(i||(o=new Ct(u)),c(o,s,r),o.chunks.length!==1)throw new Error(`Unexpected error: pre-calculated length for ${s} was wrong`);return i?o.toBytes():Re(o.chunks[0])}}return o.reset(),et(o,s,e,r),o.toBytes(!0)}function Cn(t,e){return e=Object.assign({},Oc,e),Jc(e)?(Ar.reset(),Bn(Ar,t,e,void 0),Ar.toBytes(!0)):Sn(t,Fe,e)}var Qc={strict:!1,allowIndefinite:!0,allowUndefined:!0,allowBigInt:!0},Tr=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=re[e];if(r===void 0){let n=p[e];if(!n)throw new Error(`${y} no decoder for major type ${e>>>5} (byte 0x${e.toString(16).padStart(2,"0")})`);let i=e&31;r=n(this.data,this._pos,i,this.options)}return this._pos+=r.encodedLength,r}},ve=Symbol.for("DONE"),rt=Symbol.for("BREAK");function Xc(t,e,r){let n=[];for(let i=0;i<t.value;i++){let o=ke(e,r);if(o===rt){if(t.value===1/0)break;throw new Error(`${y} got unexpected break to lengthed array`)}if(o===ve)throw new Error(`${y} found array but not enough entries (got ${i}, expected ${t.value})`);n[i]=o}return n}function Zc(t,e,r){let n=r.useMaps===!0,i=r.rejectDuplicateMapKeys===!0,o=n?void 0:{},s=n?new Map:void 0;for(let a=0;a<t.value;a++){let c=ke(e,r);if(c===rt){if(t.value===1/0)break;throw new Error(`${y} got unexpected break to lengthed map`)}if(c===ve)throw new Error(`${y} found map but not enough entries (got ${a} [no key], expected ${t.value})`);if(!n&&typeof c!="string")throw new Error(`${y} non-string keys not supported (got ${typeof c})`);if(i&&(n&&s.has(c)||!n&&Object.hasOwn(o,c)))throw new Error(`${y} found repeat map key "${c}"`);let u=ke(e,r);if(u===ve)throw new Error(`${y} found map but not enough entries (got ${a} [no value], expected ${t.value})`);n?s.set(c,u):c==="__proto__"?Object.defineProperty(o,c,{value:u,configurable:!0,enumerable:!0,writable:!0}):o[c]=u}return n?s:o}function*eu(t,e,r){for(let n=0;n<t.value;n++){let i=ke(e,r);if(i===rt){if(t.value===1/0)break;throw new Error(`${y} got unexpected break to lengthed map`)}if(i===ve)throw new Error(`${y} found map but not enough entries (got ${n} [no key], expected ${t.value})`);let o=ke(e,r);if(o===ve)throw new Error(`${y} found map but not enough entries (got ${n} [no value], expected ${t.value})`);yield[i,o]}}function tu(t,e){let r=function(){if(r._called)throw new Error(`${y} tag decode() may only be called once`);r._called=!0;let n=ke(t,e);if(n===ve)throw new Error(`${y} tag content missing`);if(n===rt)throw new Error(`${y} got unexpected break in tag content`);return n};return r.entries=function(){if(r._called)throw new Error(`${y} tag decode() may only be called once`);r._called=!0;let n=t.next();if(!l.equals(n.type,l.map))throw new Error(`${y} entries() requires map content, got ${n.type.name}`);let i=[];for(let o of eu(n,t,e))i.push(o);return i},r._called=!1,r}function ke(t,e){if(t.done())return ve;let r=t.next();if(l.equals(r.type,l.break))return rt;if(r.type.terminal)return r.value;if(l.equals(r.type,l.array))return Xc(r,t,e);if(l.equals(r.type,l.map))return Zc(r,t,e);if(l.equals(r.type,l.tag)){if(e.tags&&typeof e.tags[r.value]=="function"){let n=tu(t,e),i=e.tags[r.value](n);if(!n._called)throw new Error(`${y} tag decoder must call decode() or entries()`);return i}throw new Error(`${y} tag not supported (${r.value})`)}throw new Error("unsupported")}function Dn(t,e){if(!(t instanceof Uint8Array))throw new Error(`${y} data to decode must be a Uint8Array`);e=Object.assign({},Qc,e);let r=Re(t),n=e.tokenizer||new Tr(r,e),i=ke(n,e);if(i===ve)throw new Error(`${y} did not find any content to decode`);if(i===rt)throw new Error(`${y} got unexpected break`);return[i,t.subarray(n.pos())]}function Ut(t,e){let[r,n]=Dn(t,e);if(n.length>0)throw new Error(`${y} too many terminals, data makes no sense`);return r}var Br=class t{constructor(e,r){if(typeof e!="number"||!Number.isInteger(e)||e<0)throw new TypeError("Tagged: tag must be a non-negative integer");this.tag=e,this.value=r}static decoder(e){return r=>new t(e,r())}static preserve(...e){let r={};for(let n of e)r[n]=t.decoder(n);return r}};Object.defineProperty(Br.prototype,Symbol.toStringTag,{value:"Tagged"});var Mn={};j(Mn,{base32:()=>ot,base32hex:()=>du,base32hexpad:()=>mu,base32hexpadupper:()=>yu,base32hexupper:()=>pu,base32pad:()=>fu,base32padupper:()=>hu,base32upper:()=>lu,base32z:()=>gu});var xd=new Uint8Array(0);function ss(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 X(t){if(t instanceof Uint8Array&&t.constructor.name==="Uint8Array")return ze(t);if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.isView(t))return ze(new Uint8Array(t.buffer,t.byteOffset,t.byteLength));throw new Error("Unknown type, must be binary type")}function as(t){let e=new Uint8Array(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}var is=4096;function cs(t){let e=t.length;if(e<=is)return String.fromCharCode.apply(String,t);let r="",n=0;for(;n<e;)r+=String.fromCharCode.apply(String,t.subarray(n,n+=is));return r}function nu(t){return t?.buffer instanceof ArrayBuffer}function ze(t){return nu(t)?t:t.slice()}function ou(t,e,r){if(t.length>=255)throw new TypeError("Alphabet too long");for(var n=new Uint8Array(256),i=0;i<n.length;i++)n[i]=255;for(var o=0;o<t.length;o++){var s=t.charAt(o),a=s.charCodeAt(0);if(n[a]!==255)throw new TypeError(s+" is ambiguous");if(n[a]=o,r){var c=s.toLowerCase().charCodeAt(0),u=s.toUpperCase().charCodeAt(0);c!==a&&(n[c]=o),u!==a&&(n[u]=o)}}var f=t.length,h=t.charAt(0),m=Math.log(f)/Math.log(256),g=Math.log(256)/Math.log(f);function v(x){if(x instanceof Uint8Array||(ArrayBuffer.isView(x)?x=new Uint8Array(x.buffer,x.byteOffset,x.byteLength):Array.isArray(x)&&(x=Uint8Array.from(x))),!(x instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(x.length===0)return"";for(var T=0,C=0,R=0,L=x.length;R!==L&&x[R]===0;)R++,T++;for(var z=(L-R)*g+1>>>0,V=new Uint8Array(z);R!==L;){for(var oe=x[R],we=0,te=z-1;(oe!==0||we<C)&&te!==-1;te--,we++)oe+=256*V[te]>>>0,V[te]=oe%f>>>0,oe=oe/f>>>0;if(oe!==0)throw new Error("Non-zero carry");C=we,R++}for(var de=z-C;de!==z&&V[de]===0;)de++;for(var ur=h.repeat(T);de<z;++de)ur+=t.charAt(V[de]);return ur}function b(x){if(typeof x!="string")throw new TypeError("Expected String");if(x.length===0)return new Uint8Array;var T=0;if(x[T]!==" "){for(var C=0,R=0;x[T]===h;)C++,T++;for(var L=(x.length-T)*m+1>>>0,z=new Uint8Array(L);x[T];){var V=n[x.charCodeAt(T)];if(V===255)return;for(var oe=0,we=L-1;(V!==0||oe<R)&&we!==-1;we--,oe++)V+=f*z[we]>>>0,z[we]=V%256>>>0,V=V/256>>>0;if(V!==0)throw new Error("Non-zero carry");R=oe,T++}if(x[T]!==" "){for(var te=L-R;te!==L&&z[te]===0;)te++;for(var de=new Uint8Array(C+(L-te)),ur=C;te!==L;)de[ur++]=z[te++];return de}}}function w(x){var T=b(x);if(T)return T;throw new Error(`Non-${e} character`)}return{encode:v,decodeUnsafe:b,decode:w}}var iu=ou,su=iu,us=su;var Ln=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 i=r.codePointAt(0);if(i===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=i,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 ls(this,e)}},Un=class{decoders;constructor(e){this.decoders=e}or(e){return ls(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 ls(t,e){return new Un({...t.decoders??{[t.prefix]:t},...e.decoders??{[e.prefix]:e}})}var Rn=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,r,n,i){this.name=e,this.prefix=r,this.baseEncode=n,this.baseDecode=i,this.encoder=new Ln(e,r,n),this.decoder=new Pn(e,r,i)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function nt({name:t,prefix:e,encode:r,decode:n}){return new Rn(t,e,r,n)}function _e({name:t,prefix:e,alphabet:r,caseInsensitive:n=!1}){let{encode:i,decode:o}=us(r,t,n);return nt({prefix:e,name:t,encode:i,decode:s=>X(o(s))})}function au(t,e,r,n){let i=t.length;for(;t[i-1]==="=";)--i;let o=new Uint8Array(i*r/8|0),s=0,a=0,c=0;for(let u=0;u<i;++u){let f=e[t[u]];if(f===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|f,s+=r,s>=8&&(s-=8,o[c++]=255&a>>s)}if(s>=r||(255&a<<8-s)!==0)throw new SyntaxError("Unexpected end of data");return o}function cu(t,e,r){let n=e[e.length-1]==="=",i=(1<<r)-1,o="",s=0,a=0;for(let c=0;c<t.length;++c)for(a=a<<8|t[c],s+=8;s>r;)s-=r,o+=e[i&a>>s];if(s!==0&&(o+=e[i&a<<r-s]),n)for(;(o.length*r&7)!==0;)o+="=";return o}function uu(t,e){let r={};for(let n=0;n<t.length;++n)if(r[t[n]]=n,e){let i=t[n].toLowerCase(),o=t[n].toUpperCase();i!==t[n]&&(r[i]=n),o!==t[n]&&(r[o]=n)}return r}function S({name:t,prefix:e,bitsPerChar:r,alphabet:n,caseInsensitive:i=!1}){let o=uu(n,i);return nt({prefix:e,name:t,encode(s){return cu(s,n,r)},decode(s){return au(s,o,r,t)}})}var ot=S({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5,caseInsensitive:!0}),lu=S({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5,caseInsensitive:!0}),fu=S({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5,caseInsensitive:!0}),hu=S({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5,caseInsensitive:!0}),du=S({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5,caseInsensitive:!0}),pu=S({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5,caseInsensitive:!0}),mu=S({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5,caseInsensitive:!0}),yu=S({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5,caseInsensitive:!0}),gu=S({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var On={};j(On,{base36:()=>Rt,base36upper:()=>wu});var Rt=_e({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz",caseInsensitive:!0}),wu=_e({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",caseInsensitive:!0});var Fn={};j(Fn,{base58btc:()=>ce,base58flickr:()=>xu});var ce=_e({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),xu=_e({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var bu=ds,fs=128,Eu=127,vu=~Eu,ku=Math.pow(2,31);function ds(t,e,r){e=e||[],r=r||0;for(var n=r;t>=ku;)e[r++]=t&255|fs,t/=128;for(;t&vu;)e[r++]=t&255|fs,t>>>=7;return e[r]=t|0,ds.bytes=r-n+1,e}var _u=zn,Iu=128,hs=127;function zn(t,n){var r=0,n=n||0,i=0,o=n,s,a=t.length;do{if(o>=a)throw zn.bytes=0,new RangeError("Could not decode varint");s=t[o++],r+=i<28?(s&hs)<<i:(s&hs)*Math.pow(2,i),i+=7}while(s>=Iu);return zn.bytes=o-n,r}var Au=Math.pow(2,7),Tu=Math.pow(2,14),Bu=Math.pow(2,21),Su=Math.pow(2,28),Cu=Math.pow(2,35),Du=Math.pow(2,42),Nu=Math.pow(2,49),Lu=Math.pow(2,56),Pu=Math.pow(2,63),Uu=function(t){return t<Au?1:t<Tu?2:t<Bu?3:t<Su?4:t<Cu?5:t<Du?6:t<Nu?7:t<Lu?8:t<Pu?9:10},Ru={encode:bu,decode:_u,encodingLength:Uu},Mu=Ru,Mt=Mu;function Ot(t,e=0){let r=Mt.decode(t,e),n=Mt.decode.bytes;if(n>9)throw new RangeError("Invalid varint: too long");if(n>1&&t[e+n-1]===0)throw new RangeError("Invalid varint: not minimally encoded");return[r,n]}function it(t,e,r=0){return Mt.encode(t,e,r),e}function st(t){return Mt.encodingLength(t)}function ct(t,e){let r=e.byteLength,n=st(t),i=n+st(r),o=new Uint8Array(i+r);return it(t,o,0),it(r,o,n),o.set(e,i),new at(t,r,e,o)}function ut(t){let e=X(t),[r,n]=Ot(e),[i,o]=Ot(e.subarray(n)),s=e.subarray(n+o);if(s.byteLength!==i)throw new Error("Incorrect length");return new at(r,i,s,e)}function ps(t,e){if(t===e)return!0;{let r=e;return t.code===r.code&&t.size===r.size&&r.bytes instanceof Uint8Array&&ss(t.bytes,r.bytes)}}var at=class{code;size;digest;bytes;constructor(e,r,n,i){this.code=e,this.size=r,this.digest=ze(n),this.bytes=ze(i)}};function ms(t,e){let{bytes:r,version:n}=t;return n===0?Fu(r,$n(t),e??ce.encoder):zu(r,$n(t),e??ot.encoder)}var ys=new WeakMap;function $n(t){let e=ys.get(t);if(e==null){let r=new Map;return ys.set(t,r),r}return e}var E=class t{code;version;multihash;bytes;"/";constructor(e,r,n,i){this.code=r,this.version=e,this.multihash=n,this.bytes=ze(i),this["/"]=this.bytes}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!==Ft)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==$u)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=ct(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&&ps(e.multihash,n.multihash)}toString(e){return ms(this,e)}toJSON(){return{"/":ms(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:i,multihash:o,bytes:s}=r;return new t(n,i,o,s??gs(n,i,o.bytes))}else if(r[Hu]===!0){let{version:n,multihash:i,code:o}=r,s=ut(i);return t.create(n,o,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!==Ft)throw new Error(`Version 0 CID must use dag-pb (code: ${Ft}) block encoding`);return new t(e,r,n,n.bytes)}case 1:{let i=gs(e,r,n.bytes);return new t(e,r,n,i)}default:throw new Error("Invalid version")}}static createV0(e){return t.create(0,Ft,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,i=X(e.subarray(n,n+r.multihashSize));if(i.byteLength!==r.multihashSize)throw new Error("Incorrect length");let o=i.subarray(r.multihashSize-r.digestSize),s=new at(r.multihashCode,r.digestSize,o,i);return[r.version===0?t.createV0(s):t.createV1(r.codec,s),e.subarray(r.size)]}static inspectBytes(e){let r=0,n=()=>{let[h,m]=Ot(e.subarray(r));return r+=m,h},i=n(),o=Ft;if(i===18?(i=0,r=0):o=n(),i!==0&&i!==1)throw new RangeError(`Invalid CID version ${i}`);let s=r,a=n(),c=n(),u=r+c,f=u-s;return{version:i,codec:o,multihashCode:a,digestSize:c,multihashSize:f,size:u}}static parse(e,r){let[n,i]=Ou(e,r),o=t.decode(i);if(o.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return $n(o).set(n,e),o}};function Ou(t,e){switch(t[0]){case"Q":{let r=e??ce;return[ce.prefix,r.decode(`${ce.prefix}${t}`)]}case ce.prefix:{let r=e??ce;return[ce.prefix,r.decode(t)]}case ot.prefix:{let r=e??ot;return[ot.prefix,r.decode(t)]}case Rt.prefix:{let r=e??Rt;return[Rt.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 Fu(t,e,r){let{prefix:n}=r;if(n!==ce.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let i=e.get(n);if(i==null){let o=r.encode(t).slice(1);return e.set(n,o),o}else return i}function zu(t,e,r){let{prefix:n}=r,i=e.get(n);if(i==null){let o=r.encode(t);return e.set(n,o),o}else return i}var Ft=112,$u=18;function gs(t,e,r){let n=st(t),i=n+st(e),o=new Uint8Array(i+r.byteLength);return it(t,o,0),it(e,o,n),o.set(r,i),o}var Hu=Symbol.for("@ipld/js-cid/CID");var ws=42;function Vu(t){return t instanceof ArrayBuffer?new Uint8Array(t,0,t.byteLength):t}function qu(t){if(t.asCID!==t&&t["/"]!==t.bytes)return null;let e=E.asCID(t);if(!e)return null;let r=new Uint8Array(e.bytes.byteLength+1);return r.set(e.bytes,1),[new d(l.tag,ws),new d(l.bytes,r)]}function ju(){throw new Error("`undefined` is not supported by the IPLD Data Model and cannot be encoded")}function Gu(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 Wu(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 Hn={float64:!0,typeEncoders:{Map:Wu,Object:qu,undefined:ju,number:Gu}},Md={...Hn,typeEncoders:{...Hn.typeEncoders}};function Yu(t){let e=t();if(e[0]!==0)throw new Error("Invalid CID for CBOR tag 42; expected leading 0x00");return E.decode(e.subarray(1))}var Vn={allowIndefinite:!1,coerceUndefinedToNull:!0,allowNaN:!1,allowInfinity:!1,allowBigInt:!0,strict:!0,useMaps:!1,rejectDuplicateMapKeys:!0,tags:{[ws]:Yu}},Od={...Vn,tags:{...Vn.tags}};var Cr=113,qn=t=>Cn(t,Hn),$e=t=>Ut(Vu(t),Vn);var Wn=Bt(Dr(),1);var Yn=40;function Jn(t,e){if(!t.length)throw new Error("Unexpected end of data");let r=Wn.default.decode(t);return e.seek(Wn.default.decode.bytes),r}function Kn(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 Ae={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},$t={"CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)":Ae.Link,"CarV1HeaderOrV2Pragma > roots (anon)":t=>{if(Ae.List(t)!==void 0){for(let e=0;e<t.length;e++){let r=t[e];if(r=$t["CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)"](r),r===void 0)return;if(r!==t[e]){let n=t.slice(0,e);for(let i=e;i<t.length;i++){let o=t[i];if(o=$t["CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)"](o),o===void 0)return;n.push(o)}return n}}return t}},Int:Ae.Int,CarV1HeaderOrV2Pragma:t=>{if(Ae.Map(t)===void 0)return;let e=Object.entries(t),r=t,n=1;for(let i=0;i<e.length;i++){let[o,s]=e[i];switch(o){case"roots":{let a=$t["CarV1HeaderOrV2Pragma > roots (anon)"](t[o]);if(a===void 0)return;if(a!==s||r!==t){if(r===t){r={};for(let c=0;c<i;c++)r[e[c][0]]=e[c][1]}r.roots=a}}break;case"version":{n--;let a=$t.Int(t[o]);if(a===void 0)return;if(a!==s||r!==t){if(r===t){r={};for(let c=0;c<i;c++)r[e[c][0]]=e[c][1]}r.version=a}}break;default:return}}if(!(n>0))return r}},Ht={"CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)":Ae.Link,"CarV1HeaderOrV2Pragma > roots (anon)":t=>{if(Ae.List(t)!==void 0){for(let e=0;e<t.length;e++){let r=t[e];if(r=Ht["CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)"](r),r===void 0)return;if(r!==t[e]){let n=t.slice(0,e);for(let i=e;i<t.length;i++){let o=t[i];if(o=Ht["CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)"](o),o===void 0)return;n.push(o)}return n}}return t}},Int:Ae.Int,CarV1HeaderOrV2Pragma:t=>{if(Ae.Map(t)===void 0)return;let e=Object.entries(t),r=t,n=1;for(let i=0;i<e.length;i++){let[o,s]=e[i];switch(o){case"roots":{let a=Ht["CarV1HeaderOrV2Pragma > roots (anon)"](s);if(a===void 0)return;if(a!==s||r!==t){if(r===t){r={};for(let c=0;c<i;c++)r[e[c][0]]=e[c][1]}r.roots=a}}break;case"version":{n--;let a=Ht.Int(s);if(a===void 0)return;if(a!==s||r!==t){if(r===t){r={};for(let c=0;c<i;c++)r[e[c][0]]=e[c][1]}r.version=a}}break;default:return}}if(!(n>0))return r}},Qn={toTyped:$t.CarV1HeaderOrV2Pragma,toRepresentation:Ht.CarV1HeaderOrV2Pragma};var Zd=An();var fl=Bt(Dr(),1);var op=[new d(l.map,2),new d(l.string,"version"),new d(l.uint,1),new d(l.string,"roots")],ip=new d(l.tag,42);async function Xn(t,e){let r=Jn(await t.upTo(8),t);if(r===0)throw new Error("Invalid CAR header (zero length)");let n=await t.exactly(r,!0),i=$e(n);if(Qn.toTyped(i)===void 0)throw new Error("Invalid CAR header format");if(i.version!==1&&i.version!==2||e!==void 0&&i.version!==e)throw new Error(`Invalid CAR version: ${i.version}${e!==void 0?` (expected ${e})`:""}`);if(i.version===1){if(!Array.isArray(i.roots))throw new Error("Invalid CAR header format");return i}if(i.roots!==void 0)throw new Error("Invalid CAR header format");let o=Kn(await t.exactly(Yn,!0));t.seek(o.dataOffset-t.pos);let s=await Xn(t,1);return Object.assign(s,o)}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 i=t.subarray(e,e+r);return n&&(e+=r),i},seek(r){e+=r},get pos(){return e}}}var Zn=Bt(Dr(),1),Cs=1;function eo(t){let e=qn({version:Cs,roots:t}),r=Zn.default.encode(e.length),n=new Uint8Array(r.length+e.length);return n.set(r,0),n.set(e,r.length),n}function Ds(t){return{async setRoots(e){let r=eo(e);await t.write(r)},async writeBlock(e){let{cid:r,bytes:n}=e;await t.write(new Uint8Array(Zn.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 Cs}}}function Nr(){}function Ns(){let t=[],e=null,r=Nr,n=!1,i=null,o=Nr,s=()=>(e||(e=new Promise(u=>{r=()=>{e=null,r=Nr,u()}})),e),a={write(u){t.push(u);let f=s();return o(),f},async end(){n=!0;let u=s();o(),await u}},c={async next(){let u=t.shift();return u?(t.length===0&&r(),{done:!1,value:u}):n?(r(),{done:!0,value:void 0}):(i||(i=new Promise(f=>{o=()=>(i=null,o=Nr,f(c.next()))})),i)}};return{writer:a,iterator:c}}var qt=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=E.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=ml(e);let{encoder:r,iterator:n}=Ls(),i=new t(e,r),o=new Lr(n);return{writer:i,out:o}}static createAppender(){let{encoder:e,iterator:r}=Ls();e.setRoots=()=>Promise.resolve();let n=new t([],e),i=new Lr(r);return{writer:n,out:i}}static async updateRootsInBytes(e,r){let n=Vt(e);await Xn(n);let i=eo(r);if(Number(n.pos)!==i.length)throw new Error(`updateRoots() can only overwrite a header of the same length (old header is ${n.pos} bytes, new header is ${i.length} bytes)`);return e.set(i,0),e}},Lr=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 Ls(){let t=Ns(),{writer:e,iterator:r}=t;return{encoder:Ds(e),iterator:r}}function ml(t){if(t===void 0)return[];if(!Array.isArray(t)){let r=E.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=E.asCID(r);if(!n)throw new TypeError("roots must be a single CID or an array of CIDs");e.push(n)}return e}function yl(t){return t[Symbol.asyncIterator]!=null}function gl(t){if(yl(t))return(async()=>{for await(let e of t);})();for(let e of t);}var Ps=gl;function wl(t){let[e,r]=t[Symbol.asyncIterator]!=null?[t[Symbol.asyncIterator](),Symbol.asyncIterator]:[t[Symbol.iterator](),Symbol.iterator],n=[];return{peek:()=>e.next(),push:i=>{n.push(i)},next:()=>n.length>0?{done:!1,value:n.shift()}:e.next(),[r](){return this}}}var Pr=wl;function xl(t){return t[Symbol.asyncIterator]!=null}function bl(t,e){let r=0;if(xl(t))return(async function*(){for await(let c of t)yield e(c,r++)})();let n=Pr(t),{value:i,done:o}=n.next();if(o===!0)return(function*(){})();let s=e(i,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 Ur=bl;function El(t){return t.reason}function lt(t,e,r){if(e==null||t==null)return t;let n=r?.translateError??El;if(e.aborted)return t.catch(()=>{}),Promise.reject(n(e));let i;return Promise.race([t,new Promise((o,s)=>{i=()=>{s(n(e))},e.addEventListener("abort",i)})]).finally(()=>{i!=null&&e.removeEventListener("abort",i)})}var vl=20;function He({name:t,code:e,encode:r,minDigestLength:n,maxDigestLength:i}){return new to(t,e,r,n,i)}var to=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,r,n,i,o){this.name=e,this.code=r,this.encode=n,this.minDigestLength=i??vl,this.maxDigestLength=o}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?Us(n,this.code,r?.truncate):n.then(i=>Us(i,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function Us(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 ct(e,t)}var no={};j(no,{base64:()=>ro,base64pad:()=>kl,base64url:()=>_l,base64urlpad:()=>Il});var ro=S({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),kl=S({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),_l=S({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Il=S({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var oo={};j(oo,{identity:()=>jt});var Ms=0,Al="identity",Os=X;function Tl(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 ct(Ms,Os(t))}var jt={code:Ms,name:Al,encode:Os,digest:Tl};function ue(t=0){return new Uint8Array(t)}function Bl(t){return t?.buffer instanceof ArrayBuffer}function Fs(t){if(Bl(t))return t;let e=t.slice();return new Uint8Array(e.buffer,0,e.byteLength)}function Gt(t,e){e==null&&(e=t.reduce((i,o)=>i+o.length,0));let r=ue(e),n=0;for(let i of t)r.set(i,n),n+=i.length;return Fs(r)}function Sl(t){return t.buffer instanceof ArrayBuffer}function Rr(t){return Sl(t)?t:t.slice()}var Cl=Math.pow(2,7),Dl=Math.pow(2,14),Nl=Math.pow(2,21),zs=Math.pow(2,28),$s=Math.pow(2,35),Hs=Math.pow(2,42),Vs=Math.pow(2,49),$=128,Te=127;function Wt(t){if(t<Cl)return 1;if(t<Dl)return 2;if(t<Nl)return 3;if(t<zs)return 4;if(t<$s)return 5;if(t<Hs)return 6;if(t<Vs)return 7;if(Number.MAX_SAFE_INTEGER!=null&&t>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function qs(t,e,r=0){switch(Wt(t)){case 8:e[r++]=t&255|$,t/=128;case 7:e[r++]=t&255|$,t/=128;case 6:e[r++]=t&255|$,t/=128;case 5:e[r++]=t&255|$,t/=128;case 4:e[r++]=t&255|$,t>>>=7;case 3:e[r++]=t&255|$,t>>>=7;case 2:e[r++]=t&255|$,t>>>=7;case 1:{e[r++]=t&255,t>>>=7;break}default:throw new Error("unreachable")}return e}function js(t,e){let r=t[e],n=0;if(n+=r&Te,r<$||(r=t[e+1],n+=(r&Te)<<7,r<$)||(r=t[e+2],n+=(r&Te)<<14,r<$)||(r=t[e+3],n+=(r&Te)<<21,r<$)||(r=t[e+4],n+=(r&Te)*zs,r<$)||(r=t[e+5],n+=(r&Te)*$s,r<$)||(r=t[e+6],n+=(r&Te)*Hs,r<$)||(r=t[e+7],n+=(r&Te)*Vs,r<$))return n;throw new RangeError("Could not decode varint")}var io=new Float32Array([-0]),Be=new Uint8Array(io.buffer);function Gs(t,e,r){io[0]=t,e[r]=Be[0],e[r+1]=Be[1],e[r+2]=Be[2],e[r+3]=Be[3]}function Ws(t,e){return Be[0]=t[e],Be[1]=t[e+1],Be[2]=t[e+2],Be[3]=t[e+3],io[0]}var so=new Float64Array([-0]),M=new Uint8Array(so.buffer);function Ys(t,e,r){so[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 Js(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],so[0]}var Ll=BigInt(Number.MAX_SAFE_INTEGER),Pl=BigInt(Number.MIN_SAFE_INTEGER),K=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 Ve;if(e<Ll&&e>Pl)return this.fromNumber(Number(e));let r=e<0n;r&&(e=-e);let n=e>>32n,i=e-(n<<32n);return r&&(n=~n|0n,i=~i|0n,++i>Ks&&(i=0n,++n>Ks&&(n=0n))),new t(Number(i),Number(n))}static fromNumber(e){if(e===0)return Ve;let r=e<0;r&&(e=-e);let n=e>>>0,i=(e-n)/4294967296>>>0;return r&&(i=~i>>>0,n=~n>>>0,++n>4294967295&&(n=0,++i>4294967295&&(i=0))),new t(n,i)}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):Ve}},Ve=new K(0,0);Ve.toBigInt=function(){return 0n};Ve.zzEncode=Ve.zzDecode=function(){return this};Ve.length=function(){return 1};var Ks=4294967296n;function Qs(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 Xs(t,e,r){if(r-e<1)return"";let i,o=[],s=0,a;for(;e<r;)a=t[e++],a<128?o[s++]=a:a>191&&a<224?o[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,o[s++]=55296+(a>>10),o[s++]=56320+(a&1023)):o[s++]=(a&15)<<12|(t[e++]&63)<<6|t[e++]&63,s>8191&&((i??(i=[])).push(String.fromCharCode.apply(String,o)),s=0);return i!=null?(s>0&&i.push(String.fromCharCode.apply(String,o.slice(0,s))),i.join("")):String.fromCharCode.apply(String,o.slice(0,s))}function ao(t,e,r){let n=r,i,o;for(let s=0;s<t.length;++s)i=t.charCodeAt(s),i<128?e[r++]=i:i<2048?(e[r++]=i>>6|192,e[r++]=i&63|128):(i&64512)===55296&&((o=t.charCodeAt(s+1))&64512)===56320?(i=65536+((i&1023)<<10)+(o&1023),++s,e[r++]=i>>18|240,e[r++]=i>>12&63|128,e[r++]=i>>6&63|128,e[r++]=i&63|128):(e[r++]=i>>12|224,e[r++]=i>>6&63|128,e[r++]=i&63|128);return r-n}function ne(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 co=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(e){this.buf=Rr(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,ne(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 ne(this,4);return Mr(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw ne(this,4);return Mr(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw ne(this,4);let e=Ws(this.buf,this.pos);return this.pos+=4,e}double(){if(this.pos+8>this.len)throw ne(this,4);let e=Js(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 ne(this,e);return this.pos+=e,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let e=this.bytes();return Xs(e,0,e.length)}skip(e){if(typeof e=="number"){if(this.pos+e>this.len)throw ne(this,e);this.pos+=e}else do if(this.pos>=this.len)throw ne(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 K(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 ne(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 ne(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 ne(this,8);let e=Mr(this.buf,this.pos+=4),r=Mr(this.buf,this.pos+=4);return new K(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=js(this.buf,this.pos);return this.pos+=Wt(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 Yt(t){return new co(t instanceof Uint8Array?t:t.subarray())}function Se(t,e,r){let n=Yt(t);return e.decode(n,void 0,r)}var uo={};j(uo,{base10:()=>Ul});var Ul=_e({prefix:"9",name:"base10",alphabet:"0123456789"});var lo={};j(lo,{base16:()=>Rl,base16upper:()=>Ml});var Rl=S({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4,caseInsensitive:!0}),Ml=S({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4,caseInsensitive:!0});var fo={};j(fo,{base2:()=>Ol});var Ol=S({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var ho={};j(ho,{base256emoji:()=>Vl});var ea=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}"),Fl=ea.reduce((t,e,r)=>(t[r]=e,t),[]),zl=ea.reduce((t,e,r)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return t[n]=r,t},[]);function $l(t){return t.reduce((e,r)=>(e+=Fl[r],e),"")}function Hl(t){let e=[];for(let r of t){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let i=zl[n];if(i==null)throw new Error(`Non-base256emoji character: ${r}`);e.push(i)}return new Uint8Array(e)}var Vl=nt({prefix:"\u{1F680}",name:"base256emoji",encode:$l,decode:Hl});var po={};j(po,{base8:()=>ql});var ql=S({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var mo={};j(mo,{identity:()=>jl});var jl=nt({prefix:"\0",name:"identity",encode:t=>cs(X(t)),decode:t=>X(as(t))});var Im=new TextEncoder,Gl=new TextDecoder;var Or=512;function Fr(t){return JSON.parse(Gl.decode(t))}var ft=85;var yo={};j(yo,{sha256:()=>Wl,sha512:()=>Yl});function ta(t){return async e=>new Uint8Array(await crypto.subtle.digest(t,e))}var Wl=He({name:"sha2-256",code:18,encode:ta("SHA-256")}),Yl=He({name:"sha2-512",code:19,encode:ta("SHA-512")});var go={...mo,...fo,...po,...uo,...lo,...Mn,...On,...Fn,...no,...ho},Sm={...yo,...oo};function na(t,e,r,n){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:r},decoder:{decode:n}}}var ra=na("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),wo=na("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=ue(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}),Jl={utf8:ra,"utf-8":ra,hex:go.base16,latin1:wo,ascii:wo,binary:wo,...go},oa=Jl;function $r(t,e="utf8"){let r=oa[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.decoder.decode(`${r.prefix}${t}`)}function xo(t){let e=t??8192,r=e>>>1,n,i=e;return function(s){if(s<1||s>r)return ue(s);i+s>e&&(n=ue(e),i=0);let a=n.subarray(i,i+=s);return(i&7)!==0&&(i=(i|7)+1),a}}var qe=class{fn;len;next;val;constructor(e,r,n){this.fn=e,this.len=r,this.next=void 0,this.val=n}};function bo(){}var vo=class{head;tail;len;next;constructor(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}},Kl=xo();function Ql(t){return globalThis.Buffer!=null?ue(t):Kl(t)}var Qt=class{len;head;tail;states;constructor(){this.len=0,this.head=new qe(bo,0,0),this.tail=this.head,this.states=null}_push(e,r,n){return this.tail=this.tail.next=new qe(e,r,n),this.len+=r,this}uint32(e){return this.len+=(this.tail=this.tail.next=new ko((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(Hr,10,K.fromNumber(e)):this.uint32(e)}sint32(e){return this.uint32((e<<1^e>>31)>>>0)}uint64(e){let r=K.fromBigInt(e);return this._push(Hr,r.length(),r)}uint64Number(e){return this._push(qs,Wt(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=K.fromBigInt(e).zzEncode();return this._push(Hr,r.length(),r)}sint64Number(e){let r=K.fromNumber(e).zzEncode();return this._push(Hr,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(Kt,4,e>>>0)}sfixed32(e){return this.fixed32(e)}fixed64(e){let r=K.fromBigInt(e);return this._push(Kt,4,r.lo)._push(Kt,4,r.hi)}fixed64Number(e){let r=K.fromNumber(e);return this._push(Kt,4,r.lo)._push(Kt,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(Gs,4,e)}double(e){return this._push(Ys,8,e)}bytes(e){let r=e.length>>>0;return r===0?this._push(Eo,1,0):this.uint32(r)._push(Zl,r,e)}string(e){let r=Qs(e);return r!==0?this.uint32(r)._push(ao,r,e):this._push(Eo,1,0)}fork(){return this.states=new vo(this),this.head=this.tail=new qe(bo,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 qe(bo,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=Ql(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 Xl(t,e,r){for(;t>127;)e[r++]=t&127|128,t>>>=7;e[r]=t}var ko=class extends qe{next;constructor(e,r){super(Xl,e,r),this.next=void 0}};function Hr(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 Kt(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 Zl(t,e,r){e.set(t,r)}globalThis.Buffer!=null&&(Qt.prototype.bytes=function(t){let e=t.length>>>0;return this.uint32(e),e>0&&this._push(ef,e,t),this},Qt.prototype.string=function(t){let e=globalThis.Buffer.byteLength(t);return this.uint32(e),e>0&&this._push(tf,e,t),this});function ef(t,e,r){e.set(t,r)}function tf(t,e,r){t.length<40?ao(t,e,r):e.utf8Write!=null?e.utf8Write(t,r):e.set($r(t),r)}function _o(){return new Qt}function Ce(t,e){let r=_o();return e.encode(t,r,{lengthDelimited:!1}),r.finish()}function*De(t,e,r){let n=Yt(t);yield*e.stream(n,".",void 0,r)}var Vr={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function qr(t,e,r,n,i){return{name:t,type:e,encode:r,decode:n,stream:i}}function Io(t){function e(o){if(t[o.toString()]==null)throw new Error("Invalid enum value");return t[o]}let r=function(s,a){let c=e(s);a.int32(c)},n=function(s){let a=s.int32();return e(a)},i=function*(s,a){};return qr("enum",Vr.VARINT,r,n,i)}function Ne(t,e,r){return qr("message",Vr.LENGTH_DELIMITED,t,e,r)}var me=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var le=class extends Error{static name="AbortError";constructor(e="The operation was aborted"){super(e),this.name="AbortError"}};var je=class extends Error{static name="InvalidParametersError";constructor(e="Invalid parameters"){super(e),this.name="InvalidParametersError"}};function rf(t){return typeof t?.handleEvent=="function"}function nf(t){return t===!0||t===!1}function of(t){return nf(t)?t:t?.capture??!1}function Ao(t){let e={capture:of(t),once:!!t?.once};return t?.passive!=null&&(e.passive=t?.passive),t?.signal!=null&&(e.signal=t?.signal),e}function ia(t,e){return Ao(t).capture===Ao(e).capture}var jr=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){let i=Ao(n);if(i?.signal?.aborted===!0)return;let o=u=>{i.once&&this.removeEventListener(e,r,i),rf(r)?r.handleEvent(u):r(u)},s=this.#e.get(e);if(s==null&&(s=[],this.#e.set(e,s)),s.some(u=>u.callback!==r?!1:ia(u.options,i)))return;super.addEventListener(e,o,i);let c=()=>{this.removeEventListener(e,r,i)};i.signal?.addEventListener("abort",c),s.push({callback:r,wrapper:o,options:i,onAbort:c})}removeEventListener(e,r,n){let i=this.#e.get(e);if(i==null){super.removeEventListener(e,r??null,n);return}this.#e.set(e,i.filter(o=>o.callback===r&&ia(o.options,n)?(super.removeEventListener(e,o.wrapper,n),o.options?.signal?.removeEventListener("abort",o.onAbort),!1):!0))}safeDispatchEvent(e,r={}){return this.dispatchEvent(new CustomEvent(e,r))}};function O(){let t={};return t.promise=new Promise((e,r)=>{t.resolve=e,t.reject=r}),t}var Gr=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}},ht=class{size;hwm;head;tail;constructor(e={}){this.hwm=e.splitLimit??16,this.head=new Gr(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 Gr(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 To=class extends Error{type;code;constructor(e,r){super(e??"The operation was aborted"),this.type="aborted",this.code=r??"ABORT_ERR"}};function dt(t={}){return sf(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 sf(t,e){e=e??{};let r=e.onEnd,n=new ht,i,o,s,a=O(),c=async()=>{try{return n.isEmpty()?s?{done:!0}:await new Promise((w,x)=>{o=T=>{o=null,n.push(T);try{w(t(n))}catch(C){x(C)}return i}}):t(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=O()})}},u=w=>o!=null?o(w):(n.push(w),i),f=w=>(n=new ht,o!=null?o({error:w}):(n.push({error:w}),i)),h=w=>{if(s)return i;if(e?.objectMode!==!0&&w?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return u({done:!1,value:w})},m=w=>s?i:(s=!0,w!=null?f(w):u({done:!0})),g=()=>(n=new ht,m(),{done:!0}),v=w=>(m(w),{done:!0});if(i={[Symbol.asyncIterator](){return this},next:c,return:g,throw:v,push:h,end:m,get readableLength(){return n.size},onEmpty:async w=>{let x=w?.signal;if(x?.throwIfAborted(),n.isEmpty())return;let T,C;x!=null&&(T=new Promise((R,L)=>{C=()=>{L(new To)},x.addEventListener("abort",C)}));try{await Promise.race([a.promise,T])}finally{C!=null&&x!=null&&x?.removeEventListener("abort",C)}}},r==null)return i;let b=i;return i={[Symbol.asyncIterator](){return this},next(){return b.next()},throw(w){return b.throw(w),r!=null&&(r(w),r=void 0),{done:!0}},return(){return b.return(),r!=null&&(r(),r=void 0),{done:!0}},push:h,end(w){return b.end(w),r!=null&&(r(w),r=void 0),i},get readableLength(){return b.readableLength},onEmpty:w=>b.onEmpty(w)},i}var Bo=class t extends Error{name="TimeoutError";constructor(e,r){super(e,r),Error.captureStackTrace?.(this,t)}},sa=t=>t.reason??new DOMException("This operation was aborted.","AbortError");function Xt(t,e){let{milliseconds:r,fallback:n,message:i,customTimers:o={setTimeout,clearTimeout},signal:s}=e,a,c,f=new Promise((h,m)=>{if(typeof r!="number"||Math.sign(r)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${r}\``);if(s?.aborted){m(sa(s));return}if(s&&(c=()=>{m(sa(s))},s.addEventListener("abort",c,{once:!0})),t.then(h,m),r===Number.POSITIVE_INFINITY)return;let g=new Bo;a=o.setTimeout.call(void 0,()=>{if(n){try{h(n())}catch(v){m(v)}return}typeof t.cancel=="function"&&t.cancel(),i===!1?h():i instanceof Error?m(i):(g.message=i??`Promise timed out after ${r} milliseconds`,m(g))},r)}).finally(()=>{f.clear(),c&&s&&s.removeEventListener("abort",c)});return f.clear=()=>{o.clearTimeout.call(void 0,a),a=void 0},f}var af=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 cf(t,e,r){let n,i=new Promise((o,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:u,removeListener:f}=af(t),h=async(...g)=>{let v=r.multiArgs?g:g[0];if(r.filter)try{if(!await r.filter(v))return}catch(b){n(),s(b);return}c.push(v),r.count===c.length&&(n(),o(c))},m=(...g)=>{n(),s(r.rejectionMultiArgs?g:g[0])};n=()=>{for(let g of a)f(g,h);for(let g of r.rejectionEvents)a.includes(g)||f(g,m)};for(let g of a)u(g,h);for(let g of r.rejectionEvents)a.includes(g)||u(g,m);r.signal&&r.signal.addEventListener("abort",()=>{m(r.signal.reason)},{once:!0}),r.resolveImmediately&&o(c)});if(i.cancel=n,typeof r.timeout=="number"){let o=Xt(i,{milliseconds:r.timeout});return o.cancel=()=>{n(),o.clear()},o}return i}function Wr(t,e,r){typeof r=="function"&&(r={filter:r}),r={...r,count:1,resolveImmediately:!1};let n=cf(t,e,r),i=n.then(o=>o[0]);return i.cancel=n.cancel,i}function So(t,e){let r,n=function(){let i=function(){r=void 0,t()};clearTimeout(r),r=setTimeout(i,e)};return n.start=()=>{},n.stop=()=>{clearTimeout(r)},n}var Yr=class extends Error{static name="QueueFullError";constructor(e="The queue was full"){super(e),this.name="QueueFullError"}};var Jr=class{deferred;signal;onProgress;constructor(e){this.signal=e?.signal,this.onProgress=e?.onProgress,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 uf(){return`${parseInt(String(Math.random()*1e9),10).toString()}${Date.now()}`}var aa=new WeakMap,Kr=class{id;fn;options;recipients;status;timeline;controller;dispatchingProgress;constructor(e,r){this.id=uf(),this.status="queued",this.fn=e,this.options=r,this.recipients=[],this.timeline={created:Date.now()},this.controller=new AbortController,this.controller.signal,this.dispatchingProgress=!1,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 Jr(e);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 lt(this.fn({...this.options??{},signal:this.controller.signal,onProgress:r=>{if(this.recipients.length!==0&&!this.dispatchingProgress){if(typeof r=="object"&&r!==null){let n=aa.get(r);if(n==null&&(n=new WeakSet,aa.set(r,n)),n.has(this))return;n.add(this)}this.dispatchingProgress=!0;try{this.recipients.forEach(n=>{n.onProgress?.(r)})}finally{this.dispatchingProgress=!1}}}}),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.deferred.reject(e.signal?.reason??new le),e.cleanup(),e.signal?.removeEventListener("abort",this.onAbort)}),this.recipients.splice(0,this.recipients.length)}};var pt=class extends jr{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=So(this.emitEmpty.bind(this),1),this.emitIdle=So(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 Yr;let n=new Kr(e,r);this.enqueue(n),this.safeDispatchEvent("add");let i=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 s=0;s<this.queue.length;s++)if(this.queue[s]===n){this.queue.splice(s,1);break}}throw this.safeDispatchEvent("failure",{detail:{job:n,error:o}}),o});return this.tryToStartAnother(),i}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 Wr(this,"empty",e)}async onSizeLessThan(e,r){this.size<e||await Wr(this,"next",{...r,filter:()=>this.size<e})}async onIdle(e){this.pending===0&&this.size===0||await Wr(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=dt({objectMode:!0}),n=c=>{c!=null?this.abort():this.clear(),r.end(c)},i=c=>{c.detail!=null&&r.push(c.detail)},o=c=>{n(c.detail.error)},s=()=>{n()},a=()=>{n(new le("Queue aborted"))};this.addEventListener("completed",i),this.addEventListener("failure",o),this.addEventListener("idle",s),e?.signal?.addEventListener("abort",a);try{yield*r}finally{this.removeEventListener("completed",i),this.removeEventListener("failure",o),this.removeEventListener("idle",s),e?.signal?.removeEventListener("abort",a),n()}}};function ca(t){let e=new globalThis.AbortController;function r(){let o=t.filter(s=>s?.aborted===!0).map(s=>s?.reason).pop();e.abort(o);for(let s of t)s?.removeEventListener!=null&&s.removeEventListener("abort",r)}for(let o of t){if(o?.aborted===!0){r();break}o?.addEventListener!=null&&o.addEventListener("abort",r)}function n(){for(let o of t)o?.removeEventListener!=null&&o.removeEventListener("abort",r)}let i=e.signal;return i.clear=n,i}var Co=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 lt(this.readNext.promise,r?.signal,r)}};function ua(){return new Co}function la(t){return t[Symbol.asyncIterator]!=null}async function lf(t,e,r){try{await Promise.all(t.map(async n=>{for(;;){let{value:i,done:o}=await n.next();if(o===!0)break;await e.push(i,{signal:r}),r.throwIfAborted()}})),await e.end(void 0,{signal:r})}catch(n){await e.end(n,{signal:r}).catch(()=>{})}}async function*ff(t){let e=new AbortController,r=ua(),n=t.map(i=>la(i)?i[Symbol.asyncIterator]():i[Symbol.iterator]());lf(n,r,e.signal).catch(()=>{});try{yield*r}finally{e.abort();for(let i of n)try{Promise.resolve(i.return?.()).catch(()=>{})}catch{}}}function*hf(t){for(let e of t)yield*e}function df(...t){let e=[];for(let r of t)la(r)||e.push(r);return e.length===t.length?hf(e):ff(t)}var fa=df;function ha(t,...e){if(t==null)throw new Error("Empty pipeline");if(Do(t)){let n=t;t=()=>n.source}else if(pa(t)||da(t)){let n=t;t=()=>n}let r=[t,...e];if(r.length>1&&Do(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++)Do(r[n])&&(r[n]=mf(r[n]));return pf(...r)}var pf=(...t)=>{let e;for(;t.length>0;)e=t.shift()(e);return e},da=t=>t?.[Symbol.asyncIterator]!=null,pa=t=>t?.[Symbol.iterator]!=null,Do=t=>t==null?!1:t.sink!=null&&t.source!=null,mf=t=>e=>{let r=t.sink(e);if(r?.then!=null){let n=dt({objectMode:!0});r.then(()=>{n.end()},s=>{n.end(s)});let i,o=t.source;if(da(o))i=async function*(){yield*o,n.end()};else if(pa(o))i=function*(){yield*o,n.end()};else throw new Error("Unknown duplex source type - must be Iterable or AsyncIterable");return fa(n,i())}return t.source};function yf(t){return t[Symbol.asyncIterator]!=null}function gf(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=Pr(t),{value:i,done:o}=n.next();if(o===!0)return(function*(){})();let s=e(i,r++);if(typeof s.then=="function")return(async function*(){await s&&(yield i);for(let c of n)await e(c,r++)&&(yield c)})();let a=e;return(function*(){s===!0&&(yield i);for(let c of n)a(c,r++)&&(yield c)})()}var ma=gf;function wf(t){return t[Symbol.asyncIterator]!=null}function xf(t){if(wf(t))return(async()=>{let n=new Uint8Array(0);for await(let i of t)n=Gt([n,i],n.length+i.length);return n})();let e=[],r=0;for(let n of t)e.push(n),r+=n.byteLength;return Gt(e,r)}var _=xf;function Qr({enumerable:t=!0,configurable:e=!1}={}){return{enumerable:t,configurable:e,writable:!1}}function*bf(t,e){if(e!=null&&typeof e=="object")if(Array.isArray(e))for(let[r,n]of e.entries()){let i=[...t,r],o=E.asCID(n);o!=null?yield[i.join("/"),o]:typeof n=="object"&&(yield*No(n,i))}else{let r=E.asCID(e);r!=null?yield[t.join("/"),r]:yield*No(e,t)}}function*No(t,e){if(t==null||t instanceof Uint8Array)return;let r=E.asCID(t);r!=null&&(yield[e.join("/"),r]);for(let[n,i]of Object.entries(t)){let o=[...e,n];yield*bf(o,i)}}function*Ef(t,e){if(Array.isArray(e))for(let[r,n]of e.entries()){let i=[...t,r];yield i.join("/"),typeof n=="object"&&E.asCID(n)==null&&(yield*Lo(n,i))}else yield*Lo(e,t)}function*Lo(t,e){if(!(t==null||typeof t!="object"))for(let[r,n]of Object.entries(t)){let i=[...e,r];yield i.join("/"),n!=null&&!(n instanceof Uint8Array)&&typeof n=="object"&&E.asCID(n)==null&&(yield*Ef(i,n))}}function vf(t,e){let r=t;for(let[n,i]of e.entries()){if(r=r[i],r==null)throw new Error(`Object has no property at ${e.slice(0,n+1).map(s=>`[${JSON.stringify(s)}]`).join("")}`);let o=E.asCID(r);if(o!=null)return{value:o,remaining:e.slice(n+1).join("/")}}return{value:r}}var Po=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:Qr(),bytes:Qr(),value:Qr(),asBlock:Qr()})}links(){return No(this.value,[])}tree(){return Lo(this.value,[])}get(e="/"){return vf(this.value,e.split("/").filter(Boolean))}};function fe({bytes:t,cid:e,value:r,codec:n}){let i=r!==void 0?r:n?.decode(t);if(i===void 0)throw new Error('Missing required argument, must either provide "value" or "codec"');return new Po({cid:e,bytes:t,value:i})}function mt(t){return e=>new Uo(e,t)}function yt(t){return e=>new Ro(e,t)}function ya(t){return e=>new Mo(e,t)}var Zt=class{components;constructor(e,r={}){this.components=e}async*walk(e,r){let n=this.getQueue(),i=ma(n.toGenerator(r),c=>c!=null),o=!1,s=r?.depth??1/0,a=async c=>{let u=c.cid,f=await _(this.components.blockstore.get(u,c)),h=fe({cid:u,bytes:f,codec:await this.components.getCodec(u.code)});if(c.depth<s)for(let[,m]of h.links())r?.includeChild?.(m,h)!==!1&&n.add(a,{...c,cid:m,depth:c.depth+1,path:[...c.path,m]}).catch(g=>{o||i.throw(g)});return{block:h,depth:c.depth,path:c.path}};n.add(a,{...r,cid:e,depth:0,path:[e]}).catch(c=>{o||i.throw(c)});try{yield*i}finally{o=!0,n.abort()}}},Uo=class extends Zt{getQueue(){return new pt({concurrency:1,sort:(e,r)=>e.options.depth===r.options.depth?0:e.options.depth<r.options.depth?1:-1})}},Ro=class extends Zt{getQueue(){return new pt({concurrency:1,sort:(e,r)=>e.options.depth===r.options.depth?0:e.options.depth<r.options.depth?-1:1})}},Mo=class extends Zt{getQueue(){return new pt({concurrency:1})}};var er=class{walker;constructor(e){this.walker=e?.walker}async*export(e,r,n,i){let o,s={blockstore:r,getCodec:n};this.walker!=null?o=this.walker(s):o=yt()(s);for await(let a of o.walk(e,i))yield a.block}};var Xr=class{components;log;constructor(e){this.components=e,this.log=e.logger.forComponent("helia:car")}async import(e,r){await Ps(this.components.blockstore.putMany(Ur(e.blocks(),({cid:n,bytes:i})=>({cid:n,bytes:i})),r))}async*export(e,r){let n=Array.isArray(e)?e:[e],{writer:i,out:o}=qt.create(n),s=o[Symbol.asyncIterator](),a=new AbortController;for(this._export(n,i,r).catch(c=>{this.log.error("error during streaming export - %e",c),a.abort(c)});;){let{done:c,value:u}=await lt(s.next(),a.signal);if(a.signal.aborted)throw a.signal.reason;if(u!=null&&(yield u),c===!0)break}}async _export(e,r,n){let i=n?.traversal;for(let o of e){if(o.multihash.code===0)continue;let s=n?.exporter??(o.code===112?new tr:new er),a=o,c=!1;if(i!=null){for await(let{cid:u,bytes:f}of i.traverse(a,this.components.blockstore,this.components.getCodec,n))if(this.log.trace("next CID on path to %c is %c",o,u),a=u,o.equals(u)&&(c=!0),c||n?.includeTraversalBlocks===!0){if(n?.blockFilter?.has(u.multihash.bytes)===!0)continue;n?.blockFilter?.add(u.multihash.bytes),await r.put({cid:u,bytes:f})}}for await(let{cid:u,bytes:f}of s.export(a,this.components.blockstore,this.components.getCodec,n))n?.blockFilter?.has(u.multihash.bytes)!==!0&&u.multihash.code!==0&&(c&&u.equals(a)||(n?.blockFilter?.add(u.multihash.bytes),await r.put({cid:u,bytes:f})))}await r.close()}};var Oo=class{async*export(e,r,n,i){let o=await _(r.get(e,i));yield fe({cid:e,bytes:o,codec:await n(e.code)})}};var rr=class t extends Error{static name="InvalidTypeError";static code="ERR_INVALID_TYPE";name=t.name;code=t.code;constructor(e="Invalid type"){super(e)}};var U;(function(t){let e;(function(a){a.RAW="RAW",a.DIRECTORY="DIRECTORY",a.FILE="FILE",a.METADATA="METADATA",a.SYMLINK="SYMLINK",a.HAMT_SHARD="HAMT_SHARD"})(e=t.Type||(t.Type={}));let r;(function(a){a[a.RAW=0]="RAW",a[a.DIRECTORY=1]="DIRECTORY",a[a.FILE=2]="FILE",a[a.METADATA=3]="METADATA",a[a.SYMLINK=4]="SYMLINK",a[a.HAMT_SHARD=5]="HAMT_SHARD"})(r||(r={})),(function(a){a.codec=()=>Io(r)})(e=t.Type||(t.Type={}));let n;t.codec=()=>(n==null&&(n=Ne((a,c,u={})=>{if(u.lengthDelimited!==!1&&c.fork(),a.type!=null&&(c.uint32(8),t.Type.codec().encode(a.type,c)),a.data!=null&&(c.uint32(18),c.bytes(a.data)),a.fileSize!=null&&(c.uint32(24),c.uint64(a.fileSize)),a.blockSizes!=null&&a.blockSizes.length>0)for(let f of a.blockSizes)c.uint32(32),c.uint64(f);a.hashType!=null&&(c.uint32(40),c.uint64(a.hashType)),a.fanOut!=null&&(c.uint32(48),c.uint64(a.fanOut)),a.mode!=null&&(c.uint32(56),c.uint32(a.mode)),a.mtime!=null&&(c.uint32(66),nr.codec().encode(a.mtime,c)),u.lengthDelimited!==!1&&c.ldelim()},(a,c,u={})=>{let f={blockSizes:[]},h=c==null?a.len:a.pos+c;for(;a.pos<h;){let m=a.uint32();switch(m>>>3){case 1:{f.type=t.Type.codec().decode(a);break}case 2:{f.data=a.bytes();break}case 3:{f.fileSize=a.uint64();break}case 4:{if(u.limits?.blockSizes!=null&&f.blockSizes.length===u.limits.blockSizes)throw new me('Decode error - repeated field "blockSizes" had too many elements');f.blockSizes.push(a.uint64());break}case 5:{f.hashType=a.uint64();break}case 6:{f.fanOut=a.uint64();break}case 7:{f.mode=a.uint32();break}case 8:{f.mtime=nr.codec().decode(a,a.uint32(),{limits:u.limits?.mtime});break}default:{a.skipType(m&7);break}}}return f},function*(a,c,u,f={}){let h={blockSizes:0},m=u==null?a.len:a.pos+u;for(c!=="."&&(yield{field:c.endsWith(".")?c.substring(0,c.length-1):c,type:"start",message:"UnixFS"});a.pos<m;){let g=a.uint32();switch(g>>>3){case 1:{yield{field:`${c}type`,value:t.Type.codec().decode(a)};break}case 2:{yield{field:`${c}data`,value:a.bytes()};break}case 3:{yield{field:`${c}fileSize`,value:a.uint64()};break}case 4:{if(f.limits?.blockSizes!=null&&h.blockSizes===f.limits.blockSizes)throw new me('Streaming decode error - repeated field "blockSizes" had too many elements');yield{field:`${c}blockSizes[]`,index:h.blockSizes,value:a.uint64()},h.blockSizes++;break}case 5:{yield{field:`${c}hashType`,value:a.uint64()};break}case 6:{yield{field:`${c}fanOut`,value:a.uint64()};break}case 7:{yield{field:`${c}mode`,value:a.uint32()};break}case 8:{yield*nr.codec().stream(a,`${c}mtime.`,a.uint32(),{limits:f.limits?.mtime});break}default:{a.skipType(g&7);break}}}c!=="."&&(yield{field:c.endsWith(".")?c.substring(0,c.length-1):c,type:"end",message:"UnixFS"})})),n);function i(a){return Ce(a,t.codec())}t.encode=i;function o(a,c){return Se(a,t.codec(),c)}t.decode=o;function s(a,c){return De(a,t.codec(),c)}t.stream=s})(U||(U={}));var nr;(function(t){let e;t.codec=()=>(e==null&&(e=Ne((o,s,a={})=>{a.lengthDelimited!==!1&&s.fork(),o.seconds!=null&&(s.uint32(8),s.int64(o.seconds)),o.fractionalNanoseconds!=null&&(s.uint32(21),s.fixed32(o.fractionalNanoseconds)),a.lengthDelimited!==!1&&s.ldelim()},(o,s,a={})=>{let c={},u=s==null?o.len:o.pos+s;for(;o.pos<u;){let f=o.uint32();switch(f>>>3){case 1:{c.seconds=o.int64();break}case 2:{c.fractionalNanoseconds=o.fixed32();break}default:{o.skipType(f&7);break}}}return c},function*(o,s,a,c={}){let u=a==null?o.len:o.pos+a;for(s!=="."&&(yield{field:s.endsWith(".")?s.substring(0,s.length-1):s,type:"start",message:"UnixTime"});o.pos<u;){let f=o.uint32();switch(f>>>3){case 1:{yield{field:`${s}seconds`,value:o.int64()};break}case 2:{yield{field:`${s}fractionalNanoseconds`,value:o.fixed32()};break}default:{o.skipType(f&7);break}}}s!=="."&&(yield{field:s.endsWith(".")?s.substring(0,s.length-1):s,type:"end",message:"UnixTime"})})),e);function r(o){return Ce(o,t.codec())}t.encode=r;function n(o,s){return Se(o,t.codec(),s)}t.decode=n;function i(o,s){return De(o,t.codec(),s)}t.stream=i})(nr||(nr={}));var wa;(function(t){let e;t.codec=()=>(e==null&&(e=Ne((o,s,a={})=>{a.lengthDelimited!==!1&&s.fork(),o.mimeType!=null&&(s.uint32(10),s.string(o.mimeType)),a.lengthDelimited!==!1&&s.ldelim()},(o,s,a={})=>{let c={},u=s==null?o.len:o.pos+s;for(;o.pos<u;){let f=o.uint32();f>>>3===1?c.mimeType=o.string():o.skipType(f&7)}return c},function*(o,s,a,c={}){let u=a==null?o.len:o.pos+a;for(s!=="."&&(yield{field:s.endsWith(".")?s.substring(0,s.length-1):s,type:"start",message:"Metadata"});o.pos<u;){let f=o.uint32();f>>>3===1?yield{field:`${s}mimeType`,value:o.string()}:o.skipType(f&7)}s!=="."&&(yield{field:s.endsWith(".")?s.substring(0,s.length-1):s,type:"end",message:"Metadata"})})),e);function r(o){return Ce(o,t.codec())}t.encode=r;function n(o,s){return Se(o,t.codec(),s)}t.decode=n;function i(o,s){return De(o,t.codec(),s)}t.stream=i})(wa||(wa={}));var Le;(function(t){let e;t.codec=()=>(e==null&&(e=Ne((o,s,a={})=>{a.lengthDelimited!==!1&&s.fork(),o.hash!=null&&(s.uint32(10),s.bytes(o.hash)),o.name!=null&&(s.uint32(18),s.string(o.name)),o.tSize!=null&&(s.uint32(24),s.uint64(o.tSize)),a.lengthDelimited!==!1&&s.ldelim()},(o,s,a={})=>{let c={},u=s==null?o.len:o.pos+s;for(;o.pos<u;){let f=o.uint32();switch(f>>>3){case 1:{c.hash=o.bytes();break}case 2:{c.name=o.string();break}case 3:{c.tSize=o.uint64();break}default:{o.skipType(f&7);break}}}return c},function*(o,s,a,c={}){let u=a==null?o.len:o.pos+a;for(s!=="."&&(yield{field:s.endsWith(".")?s.substring(0,s.length-1):s,type:"start",message:"Link"});o.pos<u;){let f=o.uint32();switch(f>>>3){case 1:{yield{field:`${s}hash`,value:o.bytes()};break}case 2:{yield{field:`${s}name`,value:o.string()};break}case 3:{yield{field:`${s}tSize`,value:o.uint64()};break}default:{o.skipType(f&7);break}}}s!=="."&&(yield{field:s.endsWith(".")?s.substring(0,s.length-1):s,type:"end",message:"Link"})})),e);function r(o){return Ce(o,t.codec())}t.encode=r;function n(o,s){return Se(o,t.codec(),s)}t.decode=n;function i(o,s){return De(o,t.codec(),s)}t.stream=i})(Le||(Le={}));var gt;(function(t){let e;t.codec=()=>(e==null&&(e=Ne((o,s,a={})=>{if(a.lengthDelimited!==!1&&s.fork(),o.data!=null&&(s.uint32(10),U.codec().encode(o.data,s)),o.links!=null&&o.links.length>0)for(let c of o.links)s.uint32(18),Le.codec().encode(c,s);a.lengthDelimited!==!1&&s.ldelim()},(o,s,a={})=>{let c={links:[]},u=s==null?o.len:o.pos+s;for(;o.pos<u;){let f=o.uint32();switch(f>>>3){case 1:{c.data=U.codec().decode(o,o.uint32(),{limits:a.limits?.data});break}case 2:{if(a.limits?.links!=null&&c.links.length===a.limits.links)throw new me('Decode error - repeated field "links" had too many elements');c.links.push(Le.codec().decode(o,o.uint32(),{limits:a.limits?.links$}));break}default:{o.skipType(f&7);break}}}return c},function*(o,s,a,c={}){let u={links:0},f=a==null?o.len:o.pos+a;for(s!=="."&&(yield{field:s.endsWith(".")?s.substring(0,s.length-1):s,type:"start",message:"Node"});o.pos<f;){let h=o.uint32();switch(h>>>3){case 1:{yield*U.codec().stream(o,`${s}data.`,o.uint32(),{limits:c.limits?.data});break}case 2:{if(c.limits?.links!=null&&u.links===c.limits.links)throw new me('Streaming decode error - repeated field "links" had too many elements');for(let m of Le.codec().stream(o,`${s}links[].`,o.uint32(),{limits:c.limits?.links$}))yield{...m,index:u.links};u.links++;break}default:{o.skipType(h&7);break}}}s!=="."&&(yield{field:s.endsWith(".")?s.substring(0,s.length-1):s,type:"end",message:"Node"})})),e);function r(o){return Ce(o,t.codec())}t.encode=r;function n(o,s){return Se(o,t.codec(),s)}t.decode=n;function i(o,s){return De(o,t.codec(),s)}t.stream=i})(gt||(gt={}));var xa;(function(t){let e;t.codec=()=>(e==null&&(e=Ne((o,s,a={})=>{if(a.lengthDelimited!==!1&&s.fork(),o.links!=null&&o.links.length>0)for(let c of o.links)s.uint32(18),Le.codec().encode(c,s);o.data!=null&&(s.uint32(10),U.codec().encode(o.data,s)),a.lengthDelimited!==!1&&s.ldelim()},(o,s,a={})=>{let c={links:[]},u=s==null?o.len:o.pos+s;for(;o.pos<u;){let f=o.uint32();switch(f>>>3){case 2:{if(a.limits?.links!=null&&c.links.length===a.limits.links)throw new me('Decode error - repeated field "links" had too many elements');c.links.push(Le.codec().decode(o,o.uint32(),{limits:a.limits?.links$}));break}case 1:{c.data=U.codec().decode(o,o.uint32(),{limits:a.limits?.data});break}default:{o.skipType(f&7);break}}}return c},function*(o,s,a,c={}){let u={links:0},f=a==null?o.len:o.pos+a;for(s!=="."&&(yield{field:s.endsWith(".")?s.substring(0,s.length-1):s,type:"start",message:"LegacyNode"});o.pos<f;){let h=o.uint32();switch(h>>>3){case 2:{if(c.limits?.links!=null&&u.links===c.limits.links)throw new me('Streaming decode error - repeated field "links" had too many elements');for(let m of Le.codec().stream(o,`${s}links[].`,o.uint32(),{limits:c.limits?.links$}))yield{...m,index:u.links};u.links++;break}case 1:{yield*U.codec().stream(o,`${s}data.`,o.uint32(),{limits:c.limits?.data});break}default:{o.skipType(h&7);break}}}s!=="."&&(yield{field:s.endsWith(".")?s.substring(0,s.length-1):s,type:"end",message:"LegacyNode"})})),e);function r(o){return Ce(o,t.codec())}t.encode=r;function n(o,s){return Se(o,t.codec(),s)}t.decode=n;function i(o,s){return De(o,t.codec(),s)}t.stream=i})(xa||(xa={}));var ba={RAW:"raw",DIRECTORY:"directory",FILE:"file",METADATA:"metadata",SYMLINK:"symlink",HAMT_SHARD:"hamt-sharded-directory"},_f=["directory","hamt-sharded-directory"],Ea=parseInt("0644",8),va=parseInt("0755",8),he=class t{static unmarshal(e){let r=U.decode(e),n=new t({type:ba[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:i,hashType:o,fanout:s,mtime:a,mode:c}=e;if(r!=null&&!Object.values(ba).includes(r))throw new rr("Type: "+r+" is not valid");this.type=r??"file",this.hashType=o,this.fanout=s,this.blockSizes=i??[],this._originalMode=0,this.mode=c,this.mtime=a,n!=null&&(this.data=Rr(n))}set mode(e){e==null?this._mode=this.isDirectory()?va:Ea:this._mode=e&4095}get mode(){return this._mode}isDirectory(){return _f.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=U.Type.RAW;break;case"directory":e=U.Type.DIRECTORY;break;case"file":e=U.Type.FILE;break;case"metadata":e=U.Type.METADATA;break;case"symlink":e=U.Type.SYMLINK;break;case"hamt-sharded-directory":e=U.Type.HAMT_SHARD;break;default:throw new rr(`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===Ea&&!this.isDirectory()&&(n=void 0),n===va&&this.isDirectory()&&(n=void 0));let i;return this.mtime!=null&&(i={seconds:this.mtime.secs,fractionalNanoseconds:this.mtime.nsecs}),U.encode({type:e,data:r,fileSize:this.type==="file"||this.type==="raw"?this.fileSize():void 0,blockSizes:this.blockSizes,hashType:this.hashType,fanOut:this.fanout,mode:n,mtime:i})}};var or=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"},Zr=class extends Error{static name="NotDescendantError";name="NotDescendantError"},wt=class extends Error{static name="InvalidTraversalError";name="InvalidTraversalError"};function Af(t){return t.cid.code===85}function Tf(t){return t.cid.code===112}function Bf(t){if(Af(t))return!0;if(Tf(t)&&t.value.Data!=null){let e=he.unmarshal(t.value.Data);return e.type==="file"||e.type==="raw"}else throw new or("Encountered non raw/dag-pb CID in UnixFS DAG")}var tr=class{options;constructor(e){this.options=e}async*export(e,r,n,i){if(e.code!==112&&e.code!==85)throw new or("Target CID was not UnixFS - use the SubGraphExporter to export arbitrary graphs");let o=mt()({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 je("Offset cannot be negative");if(a<0)throw new je("Length cannot be negative");let u,f=new AbortController,h=ca([f.signal,i?.signal]);f.signal;function m(g,v){if(u==null&&(u=Bf(v)),!u){let L=v.value.Links.find(V=>V.Hash.equals(g)),z=he.unmarshal(v.value.Data??new Uint8Array);return z.type==="directory"?!c:z.type==="hamt-sharded-directory"&&c?L?.Name?.length===2:!0}let b=v.value.Links.findIndex(L=>L.Hash.equals(g)),w=he.unmarshal(v.value.Data??new Uint8Array),x=s,T=x+a,C=Number([...w.blockSizes].slice(0,b).reduce((L,z)=>L+z,0n)),R=C+Number(w.blockSizes[b]);return x>=C&&x<R||T>=C&&T<R||x<=C&&T>=R}try{for await(let g of o.walk(e,{...i,includeChild:m,signal:h}))yield g.block}finally{f.abort(),h.clear()}}};function ka(t){return t!=null&&t?.asCID===t}var Fo=class{haystack;needle;options;walker;constructor(...e){if(ka(e[0]))ka(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 je("needle must be specified");this.walker=this.options?.walker}async*traverse(e,r,n,i){let o=this.haystack??e,s,a={blockstore:r,getCodec:n};this.walker!=null?s=this.walker(a):this.options?.strategy==="breadth-first"?s=yt()(a):s=mt()(a);for await(let c of s.walk(o,i))if(c.block.cid.equals(this.needle)){for(let u of c.path){let f=await _(r.get(u,i));yield fe({cid:u,bytes:f,codec:await n(u.code)})}return}throw new wt(`${this.needle} was not a child of ${o}`)}};var zo=class{path;constructor(e){this.path=e}async*traverse(e,r,n,i){if(!this.path.some(s=>s.equals(e)))throw new wt(`CIDPath traversal must include ${e}`);let o;for(let s of this.path){if(o!=null){let u=!1;for(let[,f]of o.links())if(f.equals(s)){u=!0;break}if(!u)throw new Zr(`${s} is not a child of ${o.cid}`)}let a=await _(r.get(s,i)),c=fe({cid:s,bytes:a,codec:await n(s.code)});o=c,yield c}}};var Sf=new TextDecoder;function $o(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 i=t[e++];if(r+=n<28?(i&127)<<n:(i&127)*2**n,i<128)break}return[r,e]}function en(t,e){let r;[r,e]=$o(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 _a(t,e){let r;return[r,e]=$o(t,e),[r&7,r>>3,e]}function Cf(t){let e={},r=t.length,n=0;for(;n<r;){let i,o;if([i,o,n]=_a(t,n),o===1){if(e.Hash)throw new Error("protobuf: (PBLink) duplicate Hash section");if(i!==2)throw new Error(`protobuf: (PBLink) wrong wireType (${i}) for Hash`);if(e.Name!==void 0)throw new Error("protobuf: (PBLink) invalid order, found Name before Hash");if(e.Tsize!==void 0)throw new Error("protobuf: (PBLink) invalid order, found Tsize before Hash");[e.Hash,n]=en(t,n)}else if(o===2){if(e.Name!==void 0)throw new Error("protobuf: (PBLink) duplicate Name section");if(i!==2)throw new Error(`protobuf: (PBLink) wrong wireType (${i}) for Name`);if(e.Tsize!==void 0)throw new Error("protobuf: (PBLink) invalid order, found Tsize before Name");let s;[s,n]=en(t,n),e.Name=Sf.decode(s)}else if(o===3){if(e.Tsize!==void 0)throw new Error("protobuf: (PBLink) duplicate Tsize section");if(i!==0)throw new Error(`protobuf: (PBLink) wrong wireType (${i}) for Tsize`);[e.Tsize,n]=$o(t,n)}else throw new Error(`protobuf: (PBLink) invalid fieldNumber, expected 1, 2 or 3, got ${o}`)}if(n>r)throw new Error("protobuf: (PBLink) unexpected end of data");return e}function Ia(t){let e=t.length,r=0,n,i=!1,o;for(;r<e;){let a,c;if([a,c,r]=_a(t,r),a!==2)throw new Error(`protobuf: (PBNode) invalid wireType, expected 2, got ${a}`);if(c===1){if(o)throw new Error("protobuf: (PBNode) duplicate Data section");[o,r]=en(t,r),n&&(i=!0)}else if(c===2){if(i)throw new Error("protobuf: (PBNode) duplicate Links section");n||(n=[]);let u;[u,r]=en(t,r),n.push(Cf(u))}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 o&&(s.Data=o),s.Links=n||[],s}var Ba=new TextEncoder,Aa=2**32,Df=2**31;function Nf(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=ir(e,r,t.Tsize)-1,e[r]=24}if(typeof t.Name=="string"){let n=Ba.encode(t.Name);r-=n.length,e.set(n,r),r=ir(e,r,n.length)-1,e[r]=18}return t.Hash&&(r-=t.Hash.length,e.set(t.Hash,r),r=ir(e,r,t.Hash.length)-1,e[r]=10),e.length-r}function Ta(t,e,r){return t-=e.Data.length,r.set(e.Data,t),t=ir(r,t,e.Data.length)-1,r[t]=10,t}function Sa(t,e){let r=Pf(t),n=new Uint8Array(r),i=r,o=e?.fieldOrder==="data-first"?e.fieldOrder:"links-first";if(t.Data&&o==="links-first"&&(i=Ta(i,t,n)),t.Links)for(let s=t.Links.length-1;s>=0;s--){let a=Nf(t.Links[s],n.subarray(0,i));i-=a,i=ir(n,i,a)-1,n[i]=18}return t.Data&&o==="data-first"&&(i=Ta(i,t,n)),n}function Lf(t){let e=0;if(t.Hash){let r=t.Hash.length;e+=1+r+xt(r)}if(typeof t.Name=="string"){let r=Ba.encode(t.Name).length;e+=1+r+xt(r)}return typeof t.Tsize=="number"&&(e+=1+xt(t.Tsize)),e}function Pf(t){let e=0;if(t.Data){let r=t.Data.length;e+=1+r+xt(r)}if(t.Links)for(let r of t.Links){let n=Lf(r);e+=1+n+xt(n)}return e}function ir(t,e,r){e-=xt(r);let n=e;for(;r>=Df;)t[e++]=r&127|128,r/=128;for(;r>=128;)t[e++]=r&127|128,r>>>=7;return t[e]=r,n}function xt(t){return t%2===0&&t++,Math.floor((Uf(t)+6)/7)}function Uf(t){let e=0;return t>=Aa&&(t=Math.floor(t/Aa),e=32),t>=65536&&(t>>>=16,e+=16),t>=256&&(t>>>=8,e+=8),e+Rf[t]}var Rf=[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 Mf=["Data","Links"],Of=["Hash","Name","Tsize"],Ca=new TextEncoder;function Ff(t,e){if(t===e)return 0;let r=t.Name?Ca.encode(t.Name):[],n=e.Name?Ca.encode(e.Name):[],i=r.length,o=n.length;for(let s=0,a=Math.min(i,o);s<a;++s)if(r[s]!==n[s]){i=r[s],o=n[s];break}return i<o?-1:o<i?1:0}function Da(t,e){return!Object.keys(t).some(r=>!e.includes(r))}function Na(t){if(!t||typeof t!="object"||Array.isArray(t)||t instanceof Uint8Array||t["/"]&&t["/"]===t.bytes)throw new TypeError("Invalid DAG-PB form");if(!Da(t,Mf))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(!Da(r,Of))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&&Ff(r,t.Links[e-1])===-1)throw new TypeError("Invalid DAG-PB form (links must be sorted by Name bytes)")}}function La(t){return t instanceof ArrayBuffer?new Uint8Array(t,0,t.byteLength):t}var bt=112;function Pa(t,e){Na(t);let r={};return t.Links&&(r.Links=t.Links.map(n=>{let i={};return n.Hash&&(i.Hash=n.Hash.bytes),n.Name!==void 0&&(i.Name=n.Name),n.Tsize!==void 0&&(i.Tsize=n.Tsize),i})),t.Data&&(r.Data=t.Data),Sa(r,e)}function tn(t){let e=La(t),r=Ia(e),n={};return r.Data&&(n.Data=r.Data),r.Links&&(n.Links=r.Links.map(i=>{let o={};try{o.Hash=E.decode(i.Hash)}catch{}if(!o.Hash)throw new Error("Invalid Hash field found in link, expected CID");return i.Name!==void 0&&(o.Name=i.Name),i.Tsize!==void 0&&(o.Tsize=i.Tsize),o})),n}var Et=class t extends Error{static name="BadPathError";static code="ERR_BAD_PATH";name=t.name;code=t.code;constructor(e="Bad path"){super(e)}},q=class t extends Error{static name="NotFoundError";static code="ERR_NOT_FOUND";name=t.name;code=t.code;constructor(e="Not found"){super(e)}},vt=class t extends Error{static name="NoResolverError";static code="ERR_NO_RESOLVER";name=t.name;code=t.code;constructor(e="No resolver"){super(e)}},B=class t extends Error{static name="NotUnixFSError";static code="ERR_NOT_UNIXFS";name=t.name;code=t.code;constructor(e="Not UnixFS"){super(e)}},nn=class t extends Error{static name="OverReadError";static code="ERR_OVER_READ";name=t.name;code=t.code;constructor(e="Over read"){super(e)}},on=class t extends Error{static name="UnderReadError";static code="ERR_UNDER_READ";name=t.name;code=t.code;constructor(e="Under read"){super(e)}},ye=class t extends Error{static name="InvalidParametersError";static code="ERR_INVALID_PARAMS";name=t.name;code=t.code;constructor(e="Invalid parameters"){super(e)}};var Ua=class extends Array{constructor(){super(),this.inRecursive=[]}prefix(e){let r=this.inRecursive[this.inRecursive.length-1];r&&(l.equals(r.type,l.array)&&(r.elements++,r.elements!==1&&e.push([44])),l.equals(r.type,l.map)&&(r.elements++,r.elements!==1&&(r.elements%2===1?e.push([44]):e.push([58]))))}[l.uint.major](e,r){this.prefix(e);let n=String(r.value),i=[];for(let o=0;o<n.length;o++)i[o]=n.charCodeAt(o);e.push(i)}[l.negint.major](e,r){this[l.uint.major](e,r)}[l.bytes.major](e,r){throw new Error(`${Me} unsupported type: Uint8Array`)}[l.string.major](e,r){this.prefix(e);let n=Je(JSON.stringify(r.value));e.push(n.length>32?Re(n):n)}[l.array.major](e,r){this.prefix(e),this.inRecursive.push({type:l.array,elements:0}),e.push([91])}[l.map.major](e,r){this.prefix(e),this.inRecursive.push({type:l.map,elements:0}),e.push([123])}[l.tag.major](e,r){}[l.float.major](e,r){if(r.type.name==="break"){let s=this.inRecursive.pop();if(s){if(l.equals(s.type,l.array))e.push([93]);else if(l.equals(s.type,l.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(`${Me} 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),i=[],o=!1;for(let s=0;s<n.length;s++)i[s]=n.charCodeAt(s),!o&&(i[s]===46||i[s]===101||i[s]===69)&&(o=!0);o||(i.push(46),i.push(48)),e.push(i)}};var kt=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(`${y} 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(`${y} unexpected token at position ${this._pos}, expected to find '${String.fromCharCode(...e)}'`)}parseNumber(){let e=this._pos,r=!1,n=!1,i=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 d(l.uint,0,this._pos-e);if(i([48,49,50,51,52,53,54,55,56,57]),r&&this._pos===e+1)throw new Error(`${y} unexpected token at position ${this._pos}`);if(!this.done()&&this.ch()===46){if(n)throw new Error(`${y} unexpected token at position ${this._pos}`);n=!0,this._pos++,i([48,49,50,51,52,53,54,55,56,57])}!this.done()&&(this.ch()===101||this.ch()===69)&&(n=!0,this._pos++,!this.done()&&(this.ch()===43||this.ch()===45)&&this._pos++,i([48,49,50,51,52,53,54,55,56,57]));let o=String.fromCharCode.apply(null,this.data.subarray(e,this._pos)),s=parseFloat(o);return n?new d(l.float,s,this._pos-e):this.options.allowBigInt!==!0||Number.isSafeInteger(s)?new d(s>=0?l.uint:l.negint,s,this._pos-e):new d(s>=0?l.uint:l.negint,BigInt(o),this._pos-e)}parseString(){if(this.ch()!==34)throw new Error(`${y} unexpected character at position ${this._pos}; this shouldn't happen`);this._pos++;for(let o=this._pos,s=0;o<this.data.length&&s<65536;o++,s++){let a=this.data[o];if(a===92||a<32||a>=128)break;if(a===34){let c=String.fromCharCode.apply(null,this.data.subarray(this._pos,o));return this._pos=o+1,new d(l.string,c,s)}}let e=this._pos,r=[],n=()=>{if(this._pos+4>=this.data.length)throw new Error(`${y} unexpected end of unicode escape sequence at position ${this._pos}`);let o=0;for(let s=0;s<4;s++){let a=this.ch();if(a>=48&&a<=57)a-=48;else if(a>=97&&a<=102)a=a-97+10;else if(a>=65&&a<=70)a=a-65+10;else throw new Error(`${y} unexpected unicode escape character at position ${this._pos}`);o=o*16+a,this._pos++}return o},i=()=>{let o=this.ch(),s=null,a=o>239?4:o>223?3:o>191?2:1;if(this._pos+a>this.data.length)throw new Error(`${y} unexpected unicode sequence at position ${this._pos}`);let c,u,f,h;switch(a){case 1:o<128&&(s=o);break;case 2:c=this.data[this._pos+1],(c&192)===128&&(h=(o&31)<<6|c&63,h>127&&(s=h));break;case 3:c=this.data[this._pos+1],u=this.data[this._pos+2],(c&192)===128&&(u&192)===128&&(h=(o&15)<<12|(c&63)<<6|u&63,h>2047&&(h<55296||h>57343)&&(s=h));break;case 4:c=this.data[this._pos+1],u=this.data[this._pos+2],f=this.data[this._pos+3],(c&192)===128&&(u&192)===128&&(f&192)===128&&(h=(o&15)<<18|(c&63)<<12|(u&63)<<6|f&63,h>65535&&h<1114112&&(s=h))}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 o=this.ch(),s;switch(o){case 92:if(this._pos++,this.done())throw new Error(`${y} 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(`${y} unexpected string escape character at position ${this._pos}`)}break;case 34:return this._pos++,new d(l.string,si(r),this._pos-e);default:if(o<32)throw new Error(`${y} invalid control character at position ${this._pos}`);o<128?(r.push(o),this._pos++):i()}}throw new Error(`${y} unexpected end of string at position ${this._pos}`)}parseValue(){switch(this.ch()){case 123:return this.modeStack.push("obj-start"),this._pos++,new d(l.map,1/0,1);case 91:return this.modeStack.push("array-start"),this._pos++,new d(l.array,1/0,1);case 34:return this.parseString();case 110:return this.expect([110,117,108,108]),new d(l.null,null,4);case 102:return this.expect([102,97,108,115,101]),new d(l.false,!1,5);case 116:return this.expect([116,114,117,101]),new d(l.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(`${y} 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 d(l.break,void 0,1);if(this.ch()!==44)throw new Error(`${y} 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 d(l.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 d(l.break,void 0,1);if(this.ch()!==44)throw new Error(`${y} 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 d(l.break,void 0,1);let e=this.parseString();if(this.skipWhitespace(),this.ch()!==58)throw new Error(`${y} 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(`${y} unexpected parse state at position ${this._pos}; this shouldn't happen`)}}};function Ho(t,e){return e=Object.assign({tokenizer:new kt(t,e)},e),Ut(t,e)}function Hf(t){return t instanceof ArrayBuffer?new Uint8Array(t,0,t.byteLength):t}var Vo=class extends kt{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(l.equals(e.type,l.map)){let r=this._next();if(l.equals(r.type,l.string)&&r.value==="/"){let n=this._next();if(l.equals(n.type,l.string)){let i=this._next();if(!l.equals(i.type,l.break))throw new Error("Invalid encoded CID form");return this.tokenBuffer.push(n),new d(l.tag,42,0)}if(l.equals(n.type,l.map)){let i=this._next();if(l.equals(i.type,l.string)&&i.value==="bytes"){let o=this._next();if(l.equals(o.type,l.string)){for(let a=0;a<2;a++){let c=this._next();if(!l.equals(c.type,l.break))throw new Error("Invalid encoded Bytes form")}let s=ro.decode(`m${o.value}`);return new d(l.bytes,s,o.value.length)}this.tokenBuffer.push(o)}this.tokenBuffer.push(i)}this.tokenBuffer.push(n)}this.tokenBuffer.push(r)}return e}},Ra={allowIndefinite:!1,allowUndefined:!1,allowNaN:!1,allowInfinity:!1,allowBigInt:!0,strict:!0,useMaps:!1,rejectDuplicateMapKeys:!0,tags:{42:t=>E.parse(t())}};var sn=297;var an=t=>{let e=Hf(t),r=Object.assign(Ra,{tokenizer:new Vo(e,Ra)});return Ho(e,r)};var p0=new TextDecoder;var m0=new TextEncoder;function _t(t){return t==null?!1:E.asCID(t)===t}function It(t,e){let r,n=0,i="";for(;n<e.length;){let o=e[n];if(n++,!Object.hasOwnProperty.call(t,o))throw new Et(`Object did not have key "${o}"`);if(i+=`/${o}`,r=t[o],t=r,_t(r))break}return{value:r,rest:e.slice(n),path:i.substring(1)}}async function*qo(t,e,r,n){let i=await _(r.get(t,n)),o=$e(i),s=It(o,e);yield{cid:_t(s.value)?s.value:t,name:s.path,rest:s.rest}}async function*Ma(t,e,r,n){let i=await _(r.get(t,n)),o=an(i),s=It(o,e);yield{cid:_t(s.value)?s.value:t,name:s.path,rest:s.rest}}function Pe(t,e){let r=t.lo+e.lo>>>0,n=t.hi+e.hi+(r<t.lo?1:0)>>>0;return{lo:r,hi:n}}function Vf(t,e){return t+e>>>0}function Z(t,e){let r=t.lo&65535,n=t.lo>>>16,i=e.lo&65535,o=e.lo>>>16,s=r*i,a=r*o,c=n*i,u=n*o,f=(s>>>16)+(a&65535)+(c&65535)>>>0,h=(f<<16|s&65535)>>>0,m=u+(a>>>16)+(c>>>16)+(f>>>16),g=Math.imul(t.lo,e.hi),v=Math.imul(t.hi,e.lo),b=m+g+v>>>0;return{lo:h,hi:b}}function Ge(t,e){return Math.imul(t,e)>>>0}function At(t,e){if(e===0)return t;if(e===32)return{lo:t.hi,hi:t.lo};if(e<32){let i=(t.lo<<e|t.hi>>>32-e)>>>0,o=(t.hi<<e|t.lo>>>32-e)>>>0;return{lo:i,hi:o}}e-=32;let r=(t.hi<<e|t.lo>>>32-e)>>>0,n=(t.lo<<e|t.hi>>>32-e)>>>0;return{lo:r,hi:n}}function A(t,e){return{lo:(t.lo^e.lo)>>>0,hi:(t.hi^e.hi)>>>0}}function jo(t,e){if(e===0)return t;if(e<32){let r=(t.lo>>>e|t.hi<<32-e)>>>0,n=t.hi>>>e;return{lo:r,hi:n}}return{lo:t.hi>>>e-32,hi:0}}function I(t,e){return{lo:t>>>0,hi:e>>>0}}function Go(t,e){return(t<<e|t>>>32-e)>>>0}function Oa(t,e){let r=e*8,n=t[r]|t[r+1]<<8|t[r+2]<<16|t[r+3]<<24,i=t[r+4]|t[r+5]<<8|t[r+6]<<16|t[r+7]<<24;return{lo:n>>>0,hi:i>>>0}}function qf(t,e){let r=e*4;return(t[r]|t[r+1]<<8|t[r+2]<<16|t[r+3]<<24)>>>0}function Fa(t){return t=A(t,jo(t,33)),t=Z(t,I(3981806797,4283543511)),t=A(t,jo(t,33)),t=Z(t,I(444984403,3301882366)),t=A(t,jo(t,33)),t}function jf(t){return t^=t>>>16,t=Ge(t,2246822507),t^=t>>>13,t=Ge(t,3266489909),t^=t>>>16,t}function Wo(t,e=0){let r=I(e,0),n=I(e,0),i=t.length,o=Math.floor(i/16),s=I(289559509,2277735313),a=I(658871167,1291169091);for(let m=0;m<o;m++){let g=Oa(t,m*2),v=Oa(t,m*2+1);g=Z(g,s),g=At(g,31),g=Z(g,a),r=A(r,g),r=At(r,27),r=Pe(r,n),r=Pe(Z(r,I(5,0)),I(1390208809,0)),v=Z(v,a),v=At(v,33),v=Z(v,s),n=A(n,v),n=At(n,31),n=Pe(n,r),n=Pe(Z(n,I(5,0)),I(944331445,0))}let c=I(0,0),u=I(0,0),f=t.slice(o*16);switch(f.length){case 15:u=A(u,I(0,f[14]<<16));case 14:u=A(u,I(0,f[13]<<8));case 13:u=A(u,I(0,f[12]));case 12:u=A(u,I(f[11]<<24,0));case 11:u=A(u,I(f[10]<<16,0));case 10:u=A(u,I(f[9]<<8,0));case 9:u=A(u,I(f[8],0)),u=Z(u,a),u=At(u,33),u=Z(u,s),n=A(n,u);case 8:c=A(c,I(0,f[7]<<24));case 7:c=A(c,I(0,f[6]<<16));case 6:c=A(c,I(0,f[5]<<8));case 5:c=A(c,I(0,f[4]));case 4:c=A(c,I(f[3]<<24,0));case 3:c=A(c,I(f[2]<<16,0));case 2:c=A(c,I(f[1]<<8,0));case 1:c=A(c,I(f[0],0)),c=Z(c,s),c=At(c,31),c=Z(c,a),r=A(r,c)}let h=I(i,0);return r=A(r,h),n=A(n,h),r=Pe(r,n),n=Pe(n,r),r=Fa(r),n=Fa(n),r=Pe(r,n),n=Pe(n,r),new Uint8Array([r.hi>>>24&255,r.hi>>>16&255,r.hi>>>8&255,r.hi&255,r.lo>>>24&255,r.lo>>>16&255,r.lo>>>8&255,r.lo&255,n.hi>>>24&255,n.hi>>>16&255,n.hi>>>8&255,n.hi&255,n.lo>>>24&255,n.lo>>>16&255,n.lo>>>8&255,n.lo&255])}function za(t,e=0){let r=e>>>0,n=t.length,i=Math.floor(n/4),o=3432918353,s=461845907;for(let u=0;u<i;u++){let f=qf(t,u);f=Ge(f,o),f=Go(f,15),f=Ge(f,s),r^=f,r=Go(r,13),r=Vf(Ge(r,5),3864292196)}let a=t.slice(i*4),c=0;switch(a.length){case 3:c^=a[2]<<16;case 2:c^=a[1]<<8;case 1:c^=a[0],c=Ge(c,o),c=Go(c,15),c=Ge(c,s),r^=c}return r^=n,r=jf(r),r}function Wf(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 P0=He({name:"murmur3-32",code:35,encode:t=>Wf(za(t))}),$a=He({name:"murmur3-128",code:34,encode:t=>Wo(t)}),U0=He({name:"murmur3-x64-64",code:34,encode:t=>Wo(t).subarray(0,8)});var ja=Bt(qa(),1);var We=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 ja.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((i,o,s)=>(o!=null&&(o instanceof t?i.push(o.serialize(e,r)):i.push(e(o,s))),i),n))}async asyncTransform(e,r){return Ga(this,e,r)}toJSON(){return this.serialize(Xf,Zf)}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"?$r(e):e),n=await r.take(this._options.bits),i=this._children.get(n);return i instanceof t?i._findPlace(r):{bucket:this,pos:n,hash:r,existingChild:i}}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 i=await n._findPlace(r.existingChild.hash);return i.bucket._putAt(i,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(Qf);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 Qf(t){return!!t}function Xf(t,e){return t.key}function Zf(t){return t}async function Ga(t,e,r){let n=[];for(let i of t._children.compactArray())if(i instanceof We)await Ga(i,e,r);else{let o=await e(i);n.push({bitField:t._children.bitField(),children:o})}return r(n)}var eh=[255,254,252,248,240,224,192,128],th=[1,3,7,15,31,63,127,255],un=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 i=this._value[this._currentBytePos],o=this._currentBitPos+1,s=Math.min(o,r),a=rh(i,o-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 rh(t,e,r){let n=nh(e,r);return(t&n)>>>e}function nh(t,e){return eh[t]&th[Math.min(e+t-1,7)]}function Wa(t){function e(r){return r instanceof ln?r:new ln(r,t)}return e}var ln=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 i=this._buffers[this._currentBufferIndex],o=Math.min(i.availableBits(),r),s=i.take(o);n=(n<<o)+s,r-=o,this._availableBits-=o,i.availableBits()===0&&this._currentBufferIndex++}return n}untake(e){let r=e;for(;r>0;){let n=this._buffers[this._currentBufferIndex],i=Math.min(n.totalBits()-n.availableBits(),r);n.untake(i),r-=i,this._availableBits+=i,this._currentBufferIndex>0&&n.totalBits()===n.availableBits()&&(this._depth--,this._currentBufferIndex--)}}async _produceMoreBits(){this._depth++;let e=this._depth>0?Gt([this._value,Uint8Array.from([this._depth])]):this._value,r=await this._hashFn(e),n=new un(r);this._buffers.push(n),this._availableBits+=n.availableBits()}};function Ya(t){if(t==null||t.hashFn==null)throw new Error("please define an options.hashFn");let e={bits:t.bits??8,hash:Wa(t.hashFn)};return new We(e)}function fn(t){return t.type==="DIRECTORY"}function Ue(t){return t.type==="HAMT_SHARD"&&t.data instanceof Uint8Array&&typeof t.fanOut=="bigint"&&typeof t.hashType=="bigint"}function ge(t){return typeof t.name=="string"&&E.asCID(t.hash)===t.hash}function*hn(t){let e={},r={};for(let n of gt.stream(t))switch(n.field){case".data":{if(n.type==="start"&&(r={}),n.type==="end"){if(fn(r)||Ue(r)){yield r;return}throw new B("PBNode Data was not a directory or a HAMT shard")}break}case".data.type":{r.type=n.value;break}case".data.data":{r.data=n.value;break}case".data.fanOut":{r.fanOut=n.value;break}case".data.hashType":{r.hashType=n.value;break}case".links[]":{n.type==="start"&&(e={type:"LINK"}),n.type==="end"&&ge(e)&&(yield e);break}case".links[].name":{e.name=n.value;break}case".links[].hash":{e.hash=E.decode(n.value);break}default:}}var Ja=(t,e)=>t.toString(16).toUpperCase().padStart(e,"0").substring(0,e),oh=t=>{let e=t.bucket,r=[];for(;e._parent!=null;)r.push(e),e=e._parent;return r.push(e),r.reverse()};async function*dn(t,e,r,n,i,o,s){let a=(o.lastBucket.tableSize()-1).toString(16).length,c=[];for(let w of e){if(!ge(w))throw new B("Invalid link");if(c.push(w),w.name.length===a){let x=parseInt(w.name,16);o.lastBucket._putObjectAt(x,new We({hash:o.lastBucket._options.hash,bits:o.lastBucket._options.bits},o.lastBucket,x))}if(w.name.substring(a)===r){yield{cid:w.hash,name:r,rest:n};return}await o.rootBucket.put(w.name.substring(a),!0)}let u=await o.rootBucket._findNewBucketAndPos(r),f=Ja(u.pos,a),h=oh(u);h.length>o.hamtDepth&&(o.lastBucket=h[o.hamtDepth],f=Ja(o.lastBucket._posAtParent,a));let m=c.find(w=>w.name==null?!1:w.name===f);if(m==null)return;o.hamtDepth++;let g=await _(i.get(m.hash,s));s?.yieldSubShards===!0&&(yield{cid:m.hash,name:m.name,rest:[r,...n]});let v=hn(g),{value:b}=v.next();if(c=[],b!=null){if(Ue(b)){yield*dn(b,v,r,n,i,o,s);return}if(!ge(b))throw new B("Did not read Link or Data from dag-pb block");c.push(b);for(let w of v){if(Ue(w)){yield*dn(w,c,r,n,i,o,s);return}if(!ge(w))throw new B("Did not read Link or Data from dag-pb block");c.push(w)}}}function*Ka(t,e,r){for(let n of t){if(!ge(n))throw new B("Invalid link");if(n.name===e[0]){yield{cid:n.hash,name:e[0],rest:e.slice(1)};return}}throw new q(`No link "${e[0]}" found under ${r}`)}var ih=async function(t){return(await $a.encode(t)).slice(0,8).reverse()};async function*Qa(t,e,r,n,i,o){let s=Ya({hashFn:ih,bits:Math.log2(Number(t.fanOut))}),a={rootBucket:s,hamtDepth:1,lastBucket:s};for await(let c of dn(t,e,r[0],r.slice(1),i,a,o))if(yield c,c.name===r[0])return;throw new q(`No link "${r[0]}" found under ${n}`)}async function*Xa(t,e,r,n){let i=await _(r.get(t,n)),o=[],s=hn(i),{value:a}=s.next(),c=!1,u=!1;if(a!=null){if(u=fn(a),c=Ue(a),u||c&&n?.translateHAMTPath===!1){yield*Ka(s,e,t);return}if(c){yield*Qa(a,s,e,t,r,n);return}if(!ge(a))throw new B("Did not read Link or Data from dag-pb block");o.push(a);for(let f of s){if(u=fn(f),c=Ue(f),u||c&&n?.translateHAMTPath===!1){yield*Ka(o,e,t);return}if(Ue(f)){yield*Qa(f,o,e,t,r,n);return}if(!ge(f))throw new B("Did not read Link or Data from dag-pb block");o.push(f)}}throw new q(`No link "${e[0]}" found under ${t}`)}async function*Za(t,e,r,n){if(e.length!==0)throw new Et(`Cannot load path /${e.join("/")} from identity block`)}async function*ec(t,e,r,n){let i=await _(r.get(t,n)),o=Fr(i),s=It(o,e);yield{cid:t,name:s.path,rest:s.rest}}async function*tc(t,e,r,n){if(e.length!==0)throw new q(`Cannot load path /${e.join("/")} from raw block`)}var ah={[bt]:Xa,[ft]:tc,[Cr]:qo,81:qo,[sn]:Ma,[jt.code]:Za,[Or]:ec};async function*pn(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,...i]=t.split(/(?<!\\)\//g).filter(Boolean),o=E.parse(n),s=[o],a=`${o}`;for(yield{cid:o,name:a,path:a,roots:s,remainder:i};i.length>0;){let c=ah[o.code];if(c==null)throw new vt(`No resolver for code ${o.code}`);let u=!1;for await(let f of c(o,i,e,r)){if(o=f.cid,u=!s[s.length-1].equals(o),i=f.rest,!u)break;s=[...s,f.cid],a=`${a}/${f.name}`,yield{cid:f.cid,name:f.name,path:a,roots:s,remainder:f.rest}}if(!u)break}if(r?.signal?.throwIfAborted(),i.length!==0)throw new q(`Could not resolve path /${i.join("/")} under ${t}`)}function ch(t){return t[Symbol.asyncIterator]!=null}function uh(t){if(ch(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 rc=uh;async function Yo(t,e,r,n,i){let o=await _(n.get(t,i)),s=$e(o);return{type:"object",cid:t,name:e,path:r,object:s,node:o,size:BigInt(o.byteLength)}}async function nc(t,e,r,n,i){let o=await _(n.get(t,i)),s=an(o);return{type:"object",cid:t,name:e,path:r,object:s,node:o,size:BigInt(o.byteLength)}}var ee=class extends Event{type;detail;constructor(e,r){super(e),this.type=e,this.detail=r}};function sr(t,e,r,n){let i=BigInt(t.length),o=BigInt(e+i);return r>=o||n<e?new Uint8Array(0):(n>=e&&n<o&&(t=t.subarray(0,Number(n-e))),r>=e&&r<o&&(t=t.subarray(Number(r-e))),t)}var mn=(t,e=0,r=t)=>{let n=BigInt(t),i=BigInt(e??0),o=BigInt(r);if(o!==n&&(o=i+o),o>n&&(o=n),i<0n)throw new ye("Offset must be greater than or equal to 0");if(i>n)throw new ye("Offset must be less than the file size");if(o<0n)throw new ye("Length must be greater than or equal to 0");if(o>n)throw new ye("Length must be less than the file size");return{start:i,end:o}};function yn(t,e){async function*r(n={}){let{start:i,end:o}=mn(t.length,n.offset,n.length),s=sr(t,0n,i,o);n.onProgress?.(new ee(e,{bytesRead:BigInt(s.byteLength),totalBytes:o-i,fileSize:BigInt(t.byteLength)})),yield s}return r}async function oc(t,e,r,n,i){let o=ut(t.multihash.bytes);return{type:"identity",cid:t,name:e,path:r,content:yn(o.digest,"unixfs:exporter:progress:identity"),size:BigInt(o.bytes.byteLength),node:o.bytes}}async function ic(t,e,r,n,i){let o=await _(n.get(t,i)),s=Fr(o);return{type:"object",cid:t,name:e,path:r,object:s,size:BigInt(o.byteLength),node:o}}async function sc(t,e,r,n,i){let o=await _(n.get(t,i));return{type:"raw",cid:t,name:e,path:r,content:yn(o,"unixfs:exporter:progress:raw"),size:BigInt(o.length),node:o}}function ac(t,e,r,n){async function*i(o={}){let s=o.offset??0,a=o.length??e.Links.length,c=e.Links.slice(s,s+a);o.onProgress?.(new ee("unixfs:exporter:walk:directory",{cid:t})),yield*c.map(u=>({cid:u.Hash,name:u.Name??"",path:`${n}/${u.Name??""}`,size:BigInt(u.Tsize??0)}))}return i}var gn=globalThis.CustomEvent??Event;async function*Jo(t,e={}){let r=e.concurrency??1/0;r<1&&(r=1/0);let n=e.ordered??!1,i=new EventTarget,o=[],s=O(),a=O(),c=!1,u,f=!1,h=!1;i.addEventListener("task-complete",()=>{a.resolve()}),Promise.resolve().then(async()=>{try{for await(let b of t){if(o.length===r&&(s=O(),await s.promise),f||h)break;let w={done:!1};o.push(w),b().then(x=>{w.done=!0,w.ok=!0,w.value=x,i.dispatchEvent(new gn("task-complete"))},x=>{w.done=!0,w.err=x,i.dispatchEvent(new gn("task-complete"))})}c=!0,i.dispatchEvent(new gn("task-complete"))}catch(b){u=b,i.dispatchEvent(new gn("task-complete"))}});function m(){return n?o[0]?.done:!!o.find(b=>b.done)}function*g(){for(;o.length>0&&o[0].done;){let b=o[0];if(o.shift(),b.ok)yield b.value;else throw f=!0,s.resolve(),b.err;s.resolve()}}function*v(){for(;m();)for(let b=0;b<o.length;b++)if(o[b].done){let w=o[b];if(o.splice(b,1),b--,w.ok)yield w.value;else throw f=!0,s.resolve(),w.err;s.resolve()}}try{for(;;){if(m()||(a=O(),await a.promise),u!=null||(n?yield*g():yield*v(),u!=null))throw u;if(c&&o.length===0)break}}finally{h=!0,s.resolve()}}var Qo=Bt(uc(),1);function Xo(t,e,r){let n=0,i=t.length;for(;i>0;){let o=Math.trunc(i/2),s=n+o;r(t[s],e)<=0?(n=++s,i-=o+1):i=o}return n}var hh=100,Tt=class{#e=[];#t=0;enqueue(e,r){let{priority:n=0,id:i}=r??{},{size:o}=this,s={priority:n,id:i,run:e};if(o===0){this.#e.length=0,this.#t=0,this.#e.push(s);return}if(this.#e.at(-1).priority>=n){this.#e.push(s);return}this.#i();let a=Xo(this.#e,s,(c,u)=>u.priority-c.priority);this.#e.splice(a,0,s)}setPriority(e,r){let n=this.#e.findIndex((o,s)=>s>=this.#t&&o.id===e);if(n===-1)throw new ReferenceError(`No promise function with the id "${e}" exists in the queue.`);let[i]=this.#e.splice(n,1);this.enqueue(i.run,{priority:r,id:e})}remove(e){let r=this.#e.findIndex((n,i)=>i<this.#t?!1:typeof e=="string"?n.id===e:n.run===e);r!==-1&&this.#e.splice(r,1)}dequeue(){if(this.#t===this.#e.length)return;let e=this.#e[this.#t];return this.#t++,this.#t===this.#e.length?(this.#e.length=0,this.#t=0):this.#t>hh&&this.#t>this.#e.length/2&&this.#i(),e?.run}filter(e){let r=[];for(let n=this.#t;n<this.#e.length;n++){let i=this.#e[n];i.priority===e.priority&&r.push(i.run)}return r}get size(){return this.#e.length-this.#t}#i(){this.#t!==0&&(this.#e.splice(0,this.#t),this.#t=0)}};var cr=class extends Qo.default{#e;#t;#i=0;#d;#m=!1;#x=!1;#u;#b=0;#c;#l;#a;#s=[];#o=0;#r;#A;#n=0;#y;#f;#N=1n;#g=new Map;#E=new Set;timeout;constructor(e){if(super(),e={carryoverIntervalCount:!1,intervalCap:Number.POSITIVE_INFINITY,interval:0,concurrency:Number.POSITIVE_INFINITY,autoStart:!0,queueClass:Tt,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.#t=e.intervalCap===Number.POSITIVE_INFINITY||e.interval===0,this.#d=e.intervalCap,this.#u=e.interval,this.#a=e.strict,this.#r=new e.queueClass,this.#A=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.#f=e.autoStart===!1,this.#z()}#v(e){for(;this.#o<this.#s.length;){let n=this.#s[this.#o];if(n!==void 0&&e-n>=this.#u)this.#o++;else break}(this.#o>100&&this.#o>this.#s.length/2||this.#o===this.#s.length)&&(this.#s=this.#s.slice(this.#o),this.#o=0)}#L(e){this.#a?this.#s.push(e):this.#i++}#P(){this.#a?this.#s.length>this.#o&&this.#s.pop():this.#i>0&&this.#i--}#k(){return this.#s.length-this.#o}get#U(){return this.#t?!0:this.#a?this.#k()<this.#d:this.#i<this.#d}get#R(){return this.#n<this.#y}#M(){this.#n--,this.#n===0&&this.emit("pendingZero"),this.#w(),this.emit("next")}#O(){this.#l=void 0,this.#C(),this.#S()}#F(e){if(this.#a){if(this.#v(e),this.#k()>=this.#d){let n=this.#s[this.#o],i=this.#u-(e-n);return this.#T(i),!0}return!1}if(this.#c===void 0){let r=this.#b-e;if(r<0)this.#i=this.#e?this.#n:0;else return this.#T(r),!0}return!1}#T(e){this.#l===void 0&&(this.#l=setTimeout(()=>{this.#O()},e))}#_(){this.#c&&(clearInterval(this.#c),this.#c=void 0)}#B(){this.#l&&(clearTimeout(this.#l),this.#l=void 0)}#w(){if(this.#r.size===0){if(this.#_(),this.emit("empty"),this.#n===0){if(this.#B(),this.#a&&this.#o>0){let r=Date.now();this.#v(r)}this.emit("idle")}return!1}let e=!1;if(!this.#f){let r=Date.now(),n=!this.#F(r);if(this.#U&&this.#R){let i=this.#r.dequeue();this.#t||(this.#L(r),this.#p()),n&&this.#S(),this.emit("active"),i(),e=!0}}return e}#S(){this.#t||this.#c!==void 0||this.#a||(this.#c=setInterval(()=>{this.#C()},this.#u),this.#b=Date.now()+this.#u)}#C(){this.#a||(this.#c!==void 0&&(this.#i===0&&this.#n===0?this.#_():this.#b=Date.now()+this.#u),this.#i=this.#e?this.#n:0),this.#I(),this.#p()}#I(){for(;this.#w(););}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.#r.setPriority(e,r)}async add(e,r={}){if(r={timeout:this.timeout,...r,id:r.id??(this.#N++).toString()},r.timeout!==void 0&&!(Number.isFinite(r.timeout)&&r.timeout>0))throw new TypeError(`Expected \`timeout\` to be a positive finite number, got \`${r.timeout}\` (${typeof r.timeout})`);return new Promise((n,i)=>{let o=Symbol(`task-${r.id}`),s=()=>{},a=async()=>{s(),this.#n++,this.#g.set(o,{id:r.id,priority:r.priority??0,startTime:Date.now(),timeout:r.timeout});let u;try{try{r.signal?.throwIfAborted()}catch(m){throw this.#$(),this.#g.delete(o),m}let f=e({signal:r.signal});if(r.timeout!==void 0&&(f=Xt(Promise.resolve(f),{milliseconds:r.timeout,message:`Task timed out after ${r.timeout}ms (queue has ${this.#n} running, ${this.#r.size} waiting)`})),r.signal){let{signal:m}=r;f=Promise.race([f,new Promise((g,v)=>{u=()=>{v(m.reason)},m.addEventListener("abort",u,{once:!0})})])}let h=await f;n(h),this.emit("completed",h)}catch(f){i(f),this.emit("error",f)}finally{u&&r.signal?.removeEventListener("abort",u),this.#g.delete(o),queueMicrotask(()=>{this.#M()})}};this.#r.enqueue(a,r);let c=()=>{if(this.#r instanceof Tt){this.#r.remove(a);return}this.#r.remove?.(r.id)};if(r.signal){let{signal:u}=r,f=()=>{s(),c(),i(u.reason),this.#w(),this.emit("next")};if(s=()=>{u.removeEventListener("abort",f),this.#E.delete(s)},u.aborted){f();return}u.addEventListener("abort",f,{once:!0}),this.#E.add(s)}this.emit("add"),this.#w()})}async addAll(e,r){return Promise.all(e.map(async n=>this.add(n,r)))}start(){return this.#f?(this.#f=!1,this.#I(),this):this}pause(){this.#f=!0}clear(){for(let e of this.#E)e();this.#r=new this.#A,this.#_(),this.#D(),this.emit("empty"),this.#n===0&&(this.#B(),this.emit("idle")),this.emit("next")}async onEmpty(){this.#r.size!==0&&await this.#h("empty")}async onSizeLessThan(e){this.#r.size<e||await this.#h(["next","active"],()=>this.#r.size<e)}async onIdle(){this.#n===0&&this.#r.size===0||await this.#h("idle")}async onPendingZero(){this.#n!==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=i=>{this.off("error",n),r(i)};this.on("error",n)})}async#h(e,r){let n=Array.isArray(e)?e:[e];return new Promise(i=>{let o=()=>{if(!(r&&!r())){for(let s of n)this.off(s,o);i()}};for(let s of n)this.on(s,o)})}get size(){return this.#r.size}sizeBy(e){return this.#r.filter(e).length}get pending(){return this.#n}get isPaused(){return this.#f}#z(){this.#t||(this.on("add",()=>{this.#r.size>0&&this.#p()}),this.on("next",()=>{this.#p()}))}#p(){this.#t||this.#x||(this.#x=!0,queueMicrotask(()=>{this.#x=!1,this.#D()}))}#$(){this.#t||(this.#P(),this.#p())}#D(){let e=this.#m;if(this.#t||this.#r.size===0){e&&(this.#m=!1,this.emit("rateLimitCleared"));return}let r;if(this.#a){let i=Date.now();this.#v(i),r=this.#k()}else r=this.#i;let n=r>=this.#d;n!==e&&(this.#m=n,this.emit(n?"rateLimit":"rateLimitCleared"))}get isRateLimited(){return this.#m}get isSaturated(){return this.#n===this.#y&&this.#r.size>0||this.isRateLimited&&this.#r.size>0}get runningTasks(){return[...this.#g.values()].map(e=>({...e,timeoutRemaining:e.timeout?Math.max(0,e.startTime+e.timeout-Date.now()):void 0}))}};async function lc(t,e,r,n,i,o,s){if(e instanceof Uint8Array){let u=sr(e,n,i,o);r.push(u);return}if(e.Data==null)throw new B("no data in PBNode");let a;try{a=he.unmarshal(e.Data)}catch(u){throw new B(u.message)}if(a.data!=null){let u=a.data,f=sr(u,n,i,o);r.push(f),n+=BigInt(f.byteLength)}let c=[];if(e.Links.length!==a.blockSizes.length)throw new B("Inconsistent block sizes and dag links");for(let u=0;u<e.Links.length;u++){let f=e.Links[u],h=n,m=h+a.blockSizes[u];if((i>=h&&i<m||o>=h&&o<=m||i<h&&o>m)&&c.push({link:f,blockStart:n}),n=m,n>o)break}await ha(c,u=>Ur(u,f=>async()=>{let h=await _(t.get(f.link.Hash,s));return{...f,block:h}}),u=>Jo(u,{ordered:!0,concurrency:s.blockReadConcurrency}),async u=>{for await(let{link:f,block:h,blockStart:m}of u){let g;switch(f.Hash.code){case bt:g=tn(h);break;case ft:g=h;break;default:r.end(new B(`Unsupported codec: ${f.Hash.code}`));return}let v=new cr({concurrency:1});v.on("error",b=>{r.end(b)}),v.add(async()=>{s.onProgress?.(new ee("unixfs:exporter:walk:file",{cid:f.Hash})),await lc(t,g,r,m,i,o,s)}),await v.onIdle()}}),n>=o&&r.end()}function Zo(t,e,r,n,i){async function*o(s={}){let a=r.fileSize();if(a===void 0)throw new Error("File was a directory");let{start:c,end:u}=mn(a,s.offset,s.length);if(u===0n)return;let f=0n,h=u-c,m=dt();s.onProgress?.(new ee("unixfs:exporter:walk:file",{cid:t})),lc(i,e,m,0n,c,u,s).catch(g=>{m.end(g)});for await(let g of m)if(g!=null){if(f+=BigInt(g.byteLength),f>h)throw m.end(),new nn("Read too many bytes - the file size reported by the UnixFS data in the root node may be incorrect");f===h&&m.end(),s.onProgress?.(new ee("unixfs:exporter:progress:unixfs:file",{bytesRead:f,totalBytes:h,fileSize:a})),yield g}if(f<h)throw new on("Traversed entire DAG but did not read enough bytes")}return o}async function*dh(t,e,r,n){let i=-1,o=0;for await(let s of fc(t,e,r,n))if(i++,!(n.offset!=null&&n.offset<i)&&(yield s,o++,n.length!=null&&n.length===o))return}async function*fc(t,e,r,n){let i=await _(r.get(t,n)),o=gt.decode(i);if(o.data?.fanOut==null)throw new B("missing fanout");let s=(o.data.fanOut-1n).toString(16).length;for(let a of o.links){if(a.name==null||a.hash==null)continue;let c=E.decode(a.hash);if(a.name.length===s)yield*fc(c,e,r,n);else{let u=a.name.substring(s);yield{cid:c,name:a.name.substring(s),path:`${e}/${u}`,size:BigInt(a.tSize??0)}}}}function hc(t,e,r,n,i){function o(s={}){return s.onProgress?.(new ee("unixfs:exporter:walk:hamt-sharded-directory",{cid:t})),dh(t,n,i,s)}return o}var ph={raw:Zo,file:Zo,directory:ac,"hamt-sharded-directory":hc,metadata:(t,e,r,n)=>()=>[],symlink:(t,e,r,n)=>()=>[]};async function dc(t,e,r,n,i){let o=await _(n.get(t,i)),s;try{s=tn(o)}catch(u){throw new B(u.message)}if(s.Data==null)throw new B("no data in PBNode");let a;try{a=he.unmarshal(s.Data)}catch(u){throw new B(u.message)}let c=ph[a.type](t,s,a,r,n);if(c==null)throw new q("could not find content exporter");return a.isDirectory()?{type:"directory",cid:t,name:e,path:r,entries:c,unixfs:a,node:s,size:BigInt(o.byteLength)}:{type:"file",cid:t,name:e,path:r,content:c,unixfs:a,node:s,size:a.fileSize()}}var mh={[bt]:dc,[ft]:sc,[Cr]:Yo,81:Yo,[sn]:nc,[jt.code]:oc,[Or]:ic};async function pc(t,e,r={}){let n,i;if(t instanceof String||typeof t=="string"){let s=await rc(pn(t,e,r));if(s==null)throw new q(`Could not walk path to ${t}`);n=s.cid,i=s.name,t=s.path}else if(E.asCID(t)===t||t instanceof E)n=t,i=t=n.toString();else throw new ye("Path must be string or CID");let o=mh[n.code];if(o==null)throw new vt(`No resolver for code ${n.code}`);return o(n,i,t,e,r)}var ei=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,i){for await(let o of pn(`${this.root??e}${this.path}`,r,i)){let s=await pc(o.cid,r,i);yield fe({cid:s.cid,bytes:s.node instanceof Uint8Array?s.node:Pa(s.node),codec:await n(o.cid.code)})}}};function yh(t){return new Xr(t)}return bc(gh);})();
2
+ "use strict";var HeliaCar=(()=>{var wc=Object.create;var lr=Object.defineProperty;var xc=Object.getOwnPropertyDescriptor;var bc=Object.getOwnPropertyNames;var Ec=Object.getPrototypeOf,vc=Object.prototype.hasOwnProperty;var Ye=(t,e)=>()=>{try{return e||t((e={exports:{}}).exports,e),e.exports}catch(r){throw e=0,r}},j=(t,e)=>{for(var r in e)lr(t,r,{get:e[r],enumerable:!0})},oi=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of bc(e))!vc.call(t,i)&&i!==r&&lr(t,i,{get:()=>e[i],enumerable:!(n=xc(e,i))||n.enumerable});return t};var St=(t,e,r)=>(r=t!=null?wc(Ec(t)):{},oi(e||!t||!t.__esModule?lr(r,"default",{value:t,enumerable:!0}):r,t)),kc=t=>oi(lr({},"__esModule",{value:!0}),t);var _s=Ye((Hd,ks)=>{ks.exports=jn;var vs=128,Xu=127,Zu=~Xu,el=Math.pow(2,31);function jn(t,e,r){if(Number.MAX_SAFE_INTEGER&&t>Number.MAX_SAFE_INTEGER)throw jn.bytes=0,new RangeError("Could not encode varint");e=e||[],r=r||0;for(var n=r;t>=el;)e[r++]=t&255|vs,t/=128;for(;t&Zu;)e[r++]=t&255|vs,t>>>=7;return e[r]=t|0,jn.bytes=r-n+1,e}});var Ts=Ye((Vd,As)=>{As.exports=Gn;var tl=128,Is=127;function Gn(t,n){var r=0,n=n||0,i=0,o=n,s,a=t.length;do{if(o>=a||i>49)throw Gn.bytes=0,new RangeError("Could not decode varint");s=t[o++],r+=i<28?(s&Is)<<i:(s&Is)*Math.pow(2,i),i+=7}while(s>=tl);return Gn.bytes=o-n,r}});var Bs=Ye((qd,Ss)=>{var rl=Math.pow(2,7),nl=Math.pow(2,14),ol=Math.pow(2,21),il=Math.pow(2,28),sl=Math.pow(2,35),al=Math.pow(2,42),cl=Math.pow(2,49),ul=Math.pow(2,56),ll=Math.pow(2,63);Ss.exports=function(t){return t<rl?1:t<nl?2:t<ol?3:t<il?4:t<sl?5:t<al?6:t<cl?7:t<ul?8:t<ll?9:10}});var Dr=Ye((jd,Cs)=>{Cs.exports={encode:_s(),decode:Ts(),encodingLength:Bs()}});var Wa=Ye(($0,Ga)=>{"use strict";Ga.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 i=!1;n===-1?(n=this._data.length,this._setBit(e),this._changedData=!0):i=!0,this._setInternalPos(n,e,r,i),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,i=r;for(;n<this.length;){let o=this.get(n);i=e(i,o,n),n++}return i}find(e){let r=0,n,i;for(;r<this.length&&!n;)i=this.get(r),n=e(i),r++;return n?i:void 0}_internalPositionFor(e,r){let n=this._bytePosFor(e,r);if(n>=this._bitArrays.length)return-1;let i=this._bitArrays[n],o=e-n*7;if(!((i&1<<o)>0))return-1;let a=this._bitArrays.slice(0,n).reduce(Qf,0),c=~(4294967295<<o+1),u=ja(i&c);return a+u-1}_bytePosFor(e,r){let n=Math.floor(e/7),i=n+1;for(;!r&&this._bitArrays.length<i;)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,i){let o=this._data,s=[r,n];if(i)this._sortData(),o[e]=s;else{if(o.length)if(o[o.length-1][0]>=r)o.push(s);else if(o[0][0]<=r)o.unshift(s);else{let a=Math.round(o.length/2);this._data=o.slice(0,a).concat(s).concat(o.slice(a))}else this._data.push(s);this._changedData=!0,this._changedLength=!0}}_unsetInternalPos(e){this._data.splice(e,1)}_sortData(){this._changedData&&this._data.sort(Xf),this._changedData=!1}bitField(){let e=[],r=8,n=0,i=0,o,s=this._bitArrays.slice();for(;s.length||n;){n===0&&(o=s.shift(),n=7);let c=Math.min(n,r),u=~(255<<c),f=o&u;i|=f<<8-r,o=o>>>c,n-=c,r-=c,(!r||!n&&!s.length)&&(e.push(i),i=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(Zf)}};function Qf(t,e){return t+ja(e)}function ja(t){let e=t;return e=e-(e>>1&1431655765),e=(e&858993459)+(e>>2&858993459),(e+(e>>4)&252645135)*16843009>>24}function Xf(t,e){return t[0]-e[0]}function Zf(t){return t[1]}});var hc=Ye((rx,Zo)=>{"use strict";var dh=Object.prototype.hasOwnProperty,H="~";function ar(){}Object.create&&(ar.prototype=Object.create(null),new ar().__proto__||(H=!1));function ph(t,e,r){this.fn=t,this.context=e,this.once=r||!1}function fc(t,e,r,n,i){if(typeof r!="function")throw new TypeError("The listener must be a function");var o=new ph(r,n||t,i),s=H?H+e:e;return t._events[s]?t._events[s].fn?t._events[s]=[t._events[s],o]:t._events[s].push(o):(t._events[s]=o,t._eventsCount++),t}function wn(t,e){--t._eventsCount===0?t._events=new ar:delete t._events[e]}function O(){this._events=new ar,this._eventsCount=0}O.prototype.eventNames=function(){var e=[],r,n;if(this._eventsCount===0)return e;for(n in r=this._events)dh.call(r,n)&&e.push(H?n.slice(1):n);return Object.getOwnPropertySymbols?e.concat(Object.getOwnPropertySymbols(r)):e};O.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 i=0,o=n.length,s=new Array(o);i<o;i++)s[i]=n[i].fn;return s};O.prototype.listenerCount=function(e){var r=H?H+e:e,n=this._events[r];return n?n.fn?1:n.length:0};O.prototype.emit=function(e,r,n,i,o,s){var a=H?H+e:e;if(!this._events[a])return!1;var c=this._events[a],u=arguments.length,f,h;if(c.fn){switch(c.once&&this.removeListener(e,c.fn,void 0,!0),u){case 1:return c.fn.call(c.context),!0;case 2:return c.fn.call(c.context,r),!0;case 3:return c.fn.call(c.context,r,n),!0;case 4:return c.fn.call(c.context,r,n,i),!0;case 5:return c.fn.call(c.context,r,n,i,o),!0;case 6:return c.fn.call(c.context,r,n,i,o,s),!0}for(h=1,f=new Array(u-1);h<u;h++)f[h-1]=arguments[h];c.fn.apply(c.context,f)}else{var m=c.length,g;for(h=0;h<m;h++)switch(c[h].once&&this.removeListener(e,c[h].fn,void 0,!0),u){case 1:c[h].fn.call(c[h].context);break;case 2:c[h].fn.call(c[h].context,r);break;case 3:c[h].fn.call(c[h].context,r,n);break;case 4:c[h].fn.call(c[h].context,r,n,i);break;default:if(!f)for(g=1,f=new Array(u-1);g<u;g++)f[g-1]=arguments[g];c[h].fn.apply(c[h].context,f)}}return!0};O.prototype.on=function(e,r,n){return fc(this,e,r,n,!1)};O.prototype.once=function(e,r,n){return fc(this,e,r,n,!0)};O.prototype.removeListener=function(e,r,n,i){var o=H?H+e:e;if(!this._events[o])return this;if(!r)return wn(this,o),this;var s=this._events[o];if(s.fn)s.fn===r&&(!i||s.once)&&(!n||s.context===n)&&wn(this,o);else{for(var a=0,c=[],u=s.length;a<u;a++)(s[a].fn!==r||i&&!s[a].once||n&&s[a].context!==n)&&c.push(s[a]);c.length?this._events[o]=c.length===1?c[0]:c:wn(this,o)}return this};O.prototype.removeAllListeners=function(e){var r;return e?(r=H?H+e:e,this._events[r]&&wn(this,r)):(this._events=new ar,this._eventsCount=0),this};O.prototype.off=O.prototype.removeListener;O.prototype.addListener=O.prototype.on;O.prefixed=H;O.EventEmitter=O;typeof Zo<"u"&&(Zo.exports=O)});var bh={};j(bh,{BlockExporter:()=>Mo,CIDPath:()=>zo,GraphSearch:()=>Oo,SubgraphExporter:()=>er,UnixFSExporter:()=>tr,UnixFSPath:()=>ni,breadthFirstWalker:()=>yt,car:()=>xh,depthFirstWalker:()=>mt,naturalOrderWalker:()=>xa});var _c=["Object","RegExp","Date","Error","Map","Set","WeakMap","WeakSet","ArrayBuffer","SharedArrayBuffer","DataView","Promise","URL","HTMLElement","Int8Array","Uint8ClampedArray","Int16Array","Uint16Array","Int32Array","Uint32Array","Float32Array","Float64Array","BigInt64Array","BigUint64Array","Tagged"];function xn(t){if(t===null)return"null";if(t===void 0)return"undefined";if(t===!0||t===!1)return"boolean";let e=typeof t;if(e==="string"||e==="number"||e==="bigint"||e==="symbol")return e;if(e==="function")return"Function";if(Array.isArray(t))return"Array";if(t instanceof Uint8Array)return"Uint8Array";if(t.constructor===Object)return"Object";let r=Ic(t);return r||"Object"}function Ic(t){let e=Object.prototype.toString.call(t).slice(8,-1);if(_c.includes(e))return e}var l=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}static equals(e,r){return e===r||e.major===r.major&&e.name===r.name}};l.uint=new l(0,"uint",!0);l.negint=new l(1,"negint",!0);l.bytes=new l(2,"bytes",!0);l.string=new l(3,"string",!0);l.array=new l(4,"array",!1);l.map=new l(5,"map",!1);l.tag=new l(6,"tag",!1);l.float=new l(7,"float",!0);l.false=new l(7,"false",!0);l.true=new l(7,"true",!0);l.null=new l(7,"null",!0);l.undefined=new l(7,"undefined",!0);l.break=new l(7,"break",!0);var d=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 Bt=globalThis.process&&!globalThis.process.browser&&globalThis.Buffer&&typeof globalThis.Buffer.isBuffer=="function",Ac=new TextEncoder;function fr(t){return Bt&&globalThis.Buffer.isBuffer(t)}function Re(t){return t instanceof Uint8Array?fr(t)?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):t:Uint8Array.from(t)}var Tc=24,Sc=200,Je=Bt?t=>t.length>=Tc?globalThis.Buffer.from(t):ii(t):t=>t.length>=Sc?Ac.encode(t):ii(t),ie=t=>Uint8Array.from(t),ai=Bt?(t,e,r)=>fr(t)?new Uint8Array(t.subarray(e,r)):t.slice(e,r):(t,e,r)=>t.slice(e,r),ci=Bt?(t,e)=>(t=t.map(r=>r instanceof Uint8Array?r:globalThis.Buffer.from(r)),Re(globalThis.Buffer.concat(t,e))):(t,e)=>{let r=new Uint8Array(e),n=0;for(let i of t)n+i.length>r.length&&(i=i.subarray(0,r.length-n)),r.set(i,n),n+=i.length;return r},bn=Bt?t=>globalThis.Buffer.allocUnsafe(t):t=>new Uint8Array(t);function Ke(t,e){if(fr(t)&&fr(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 ii(t){let e=[],r=0;for(let n=0;n<t.length;n++){let i=t.charCodeAt(n);i<128?e[r++]=i:i<2048?(e[r++]=i>>6|192,e[r++]=i&63|128):(i&64512)===55296&&n+1<t.length&&(t.charCodeAt(n+1)&64512)===56320?(i=65536+((i&1023)<<10)+(t.charCodeAt(++n)&1023),e[r++]=i>>18|240,e[r++]=i>>12&63|128,e[r++]=i>>6&63|128,e[r++]=i&63|128):(i>=55296&&i<=57343&&(i=65533),e[r++]=i>>12|224,e[r++]=i>>6&63|128,e[r++]=i&63|128)}return e}var si=4096;function ui(t){let e=t.length;if(e<=si)return String.fromCharCode.apply(String,t);let r="",n=0;for(;n<e;)r+=String.fromCharCode.apply(String,t.slice(n,n+=si));return r}var Bc=256,Ct=class{constructor(e=Bc){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)}pushByte(e){let r=this.chunks[this.chunks.length-1];this.cursor>this.maxCursor&&(r=bn(this.chunkSize),this.chunks.push(r),this.maxCursor+=r.length,this._initReuseChunk===null&&(this._initReuseChunk=r));let n=r.length-(this.maxCursor-this.cursor)-1;r[n]=e,this.cursor++}push(e){let r=this.chunks[this.chunks.length-1];if(this.cursor+e.length<=this.maxCursor+1){let i=r.length-(this.maxCursor-this.cursor)-1;r.set(e,i)}else{if(r){let i=r.length-(this.maxCursor-this.cursor)-1;i<r.length&&(this.chunks[this.chunks.length-1]=r.subarray(0,i),this.maxCursor=this.cursor-1)}e.length<64&&e.length<this.chunkSize?(r=bn(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=ai(n,0,this.cursor)}else r=ci(this.chunks,this.cursor);return e&&this.reset(),r}},hr=class{constructor(e){this.dest=e,this.cursor=0,this.chunks=[e]}reset(){this.cursor=0}pushByte(e){if(this.cursor>=this.dest.length)throw new Error("write out of bounds, destination buffer is too small");this.dest[this.cursor++]=e}push(e){if(this.cursor+e.length>this.dest.length)throw new Error("write out of bounds, destination buffer is too small");this.dest.set(e,this.cursor),this.cursor+=e.length}toBytes(e=!1){let r=this.dest.subarray(0,this.cursor);return e&&this.reset(),r}};var y="CBOR decode error:",Fe="CBOR encode error:",Dt=[];Dt[23]=1;Dt[24]=2;Dt[25]=3;Dt[26]=5;Dt[27]=9;function pe(t,e,r){if(t.length-e<r)throw new Error(`${y} not enough data for type`)}var U=[24,256,65536,4294967296,BigInt("18446744073709551616")];function G(t,e,r){pe(t,e,1);let n=t[e];if(r.strict===!0&&n<U[0])throw new Error(`${y} integer encoded in more bytes than necessary (strict decode)`);return n}function W(t,e,r){pe(t,e,2);let n=t[e]<<8|t[e+1];if(r.strict===!0&&n<U[1])throw new Error(`${y} integer encoded in more bytes than necessary (strict decode)`);return n}function Y(t,e,r){pe(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(`${y} integer encoded in more bytes than necessary (strict decode)`);return n}function J(t,e,r){pe(t,e,8);let n=t[e]*16777216+(t[e+1]<<16)+(t[e+2]<<8)+t[e+3],i=t[e+4]*16777216+(t[e+5]<<16)+(t[e+6]<<8)+t[e+7],o=(BigInt(n)<<BigInt(32))+BigInt(i);if(r.strict===!0&&o<U[3])throw new Error(`${y} integer encoded in more bytes than necessary (strict decode)`);if(o<=Number.MAX_SAFE_INTEGER)return Number(o);if(r.allowBigInt===!0)return o;throw new Error(`${y} integers outside of the safe integer range are not supported`)}function li(t,e,r,n){return new d(l.uint,G(t,e+1,n),2)}function fi(t,e,r,n){return new d(l.uint,W(t,e+1,n),3)}function hi(t,e,r,n){return new d(l.uint,Y(t,e+1,n),5)}function di(t,e,r,n){return new d(l.uint,J(t,e+1,n),9)}function se(t,e){return D(t,0,e.value)}function D(t,e,r){if(r<U[0]){let n=Number(r);t.pushByte(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 i=[e|27,0,0,0,0,0,0,0],o=Number(n&BigInt(4294967295)),s=Number(n>>BigInt(32)&BigInt(4294967295));i[8]=o&255,o=o>>8,i[7]=o&255,o=o>>8,i[6]=o&255,o=o>>8,i[5]=o&255,i[4]=s&255,s=s>>8,i[3]=s&255,s=s>>8,i[2]=s&255,s=s>>8,i[1]=s&255,t.push(i)}else throw new Error(`${y} encountered BigInt larger than allowable range`)}}se.encodedSize=function(e){return D.encodedSize(e.value)};D.encodedSize=function(e){return e<U[0]?1:e<U[1]?2:e<U[2]?3:e<U[3]?5:9};se.compareTokens=function(e,r){return e.value<r.value?-1:e.value>r.value?1:0};function pi(t,e,r,n){return new d(l.negint,-1-G(t,e+1,n),2)}function mi(t,e,r,n){return new d(l.negint,-1-W(t,e+1,n),3)}function yi(t,e,r,n){return new d(l.negint,-1-Y(t,e+1,n),5)}var En=BigInt(-1),gi=BigInt(1);function wi(t,e,r,n){let i=J(t,e+1,n);if(typeof i!="bigint"){let o=-1-i;if(o>=Number.MIN_SAFE_INTEGER)return new d(l.negint,o,9)}if(n.allowBigInt!==!0)throw new Error(`${y} integers outside of the safe integer range are not supported`);return new d(l.negint,En-BigInt(i),9)}function dr(t,e){let r=e.value,n=typeof r=="bigint"?r*En-gi:r*-1-1;D(t,e.type.majorEncoded,n)}dr.encodedSize=function(e){let r=e.value,n=typeof r=="bigint"?r*En-gi:r*-1-1;return n<U[0]?1:n<U[1]?2:n<U[2]?3:n<U[3]?5:9};dr.compareTokens=function(e,r){return e.value<r.value?1:e.value>r.value?-1:0};function Nt(t,e,r,n){pe(t,e,r+n);let i=t.slice(e+r,e+r+n);return new d(l.bytes,i,r+n)}function xi(t,e,r,n){return Nt(t,e,1,r)}function bi(t,e,r,n){return Nt(t,e,2,G(t,e+1,n))}function Ei(t,e,r,n){return Nt(t,e,3,W(t,e+1,n))}function vi(t,e,r,n){return Nt(t,e,5,Y(t,e+1,n))}function ki(t,e,r,n){let i=J(t,e+1,n);if(typeof i=="bigint")throw new Error(`${y} 64-bit integer bytes lengths not supported`);return Nt(t,e,9,i)}function pr(t){return t.encodedBytes===void 0&&(t.encodedBytes=l.equals(t.type,l.string)?Je(t.value):t.value),t.encodedBytes}function Qe(t,e){let r=pr(e);D(t,e.type.majorEncoded,r.length),t.push(r)}Qe.encodedSize=function(e){let r=pr(e);return D.encodedSize(r.length)+r.length};Qe.compareTokens=function(e,r){return Dc(pr(e),pr(r))};function Dc(t,e){return t.length<e.length?-1:t.length>e.length?1:Ke(t,e)}var _i=new TextDecoder,Lc=32;function Uc(t,e,r){if(r-e<Lc){let i="";for(let o=e;o<r;o++){let s=t[o];if(s&128)return _i.decode(t.subarray(e,r));i+=String.fromCharCode(s)}return i}return _i.decode(t.subarray(e,r))}function Lt(t,e,r,n,i){let o=r+n;pe(t,e,o);let s=new d(l.string,Uc(t,e+r,e+o),o);return i.retainStringBytes===!0&&(s.byteValue=t.slice(e+r,e+o)),s}function Ii(t,e,r,n){return Lt(t,e,1,r,n)}function Ai(t,e,r,n){return Lt(t,e,2,G(t,e+1,n),n)}function Ti(t,e,r,n){return Lt(t,e,3,W(t,e+1,n),n)}function Si(t,e,r,n){return Lt(t,e,5,Y(t,e+1,n),n)}function Bi(t,e,r,n){let i=J(t,e+1,n);if(typeof i=="bigint")throw new Error(`${y} 64-bit integer string lengths not supported`);return Lt(t,e,9,i,n)}var Ci=Qe;function Xe(t,e,r,n){return new d(l.array,n,r)}function Di(t,e,r,n){return Xe(t,e,1,r)}function Ni(t,e,r,n){return Xe(t,e,2,G(t,e+1,n))}function Li(t,e,r,n){return Xe(t,e,3,W(t,e+1,n))}function Ui(t,e,r,n){return Xe(t,e,5,Y(t,e+1,n))}function Pi(t,e,r,n){let i=J(t,e+1,n);if(typeof i=="bigint")throw new Error(`${y} 64-bit integer array lengths not supported`);return Xe(t,e,9,i)}function Ri(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${y} indefinite length items not allowed`);return Xe(t,e,1,1/0)}function mr(t,e){D(t,l.array.majorEncoded,e.value)}mr.compareTokens=se.compareTokens;mr.encodedSize=function(e){return D.encodedSize(e.value)};function Ze(t,e,r,n){return new d(l.map,n,r)}function Fi(t,e,r,n){return Ze(t,e,1,r)}function Mi(t,e,r,n){return Ze(t,e,2,G(t,e+1,n))}function Oi(t,e,r,n){return Ze(t,e,3,W(t,e+1,n))}function zi(t,e,r,n){return Ze(t,e,5,Y(t,e+1,n))}function $i(t,e,r,n){let i=J(t,e+1,n);if(typeof i=="bigint")throw new Error(`${y} 64-bit integer map lengths not supported`);return Ze(t,e,9,i)}function Hi(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${y} indefinite length items not allowed`);return Ze(t,e,1,1/0)}function yr(t,e){D(t,l.map.majorEncoded,e.value)}yr.compareTokens=se.compareTokens;yr.encodedSize=function(e){return D.encodedSize(e.value)};function Vi(t,e,r,n){return new d(l.tag,r,1)}function qi(t,e,r,n){return new d(l.tag,G(t,e+1,n),2)}function ji(t,e,r,n){return new d(l.tag,W(t,e+1,n),3)}function Gi(t,e,r,n){return new d(l.tag,Y(t,e+1,n),5)}function Wi(t,e,r,n){return new d(l.tag,J(t,e+1,n),9)}function gr(t,e){D(t,l.tag.majorEncoded,e.value)}gr.compareTokens=se.compareTokens;gr.encodedSize=function(e){return D.encodedSize(e.value)};var wr=20,xr=21,br=22,Er=23;function Ji(t,e,r,n){if(n.allowUndefined===!1)throw new Error(`${y} undefined values are not supported`);return n.coerceUndefinedToNull===!0?new d(l.null,null,1):new d(l.undefined,void 0,1)}function Ki(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${y} indefinite length items not allowed`);return new d(l.break,void 0,1)}function vn(t,e,r){if(r){if(r.allowNaN===!1&&Number.isNaN(t))throw new Error(`${y} NaN values are not supported`);if(r.allowInfinity===!1&&(t===1/0||t===-1/0))throw new Error(`${y} Infinity values are not supported`)}return new d(l.float,t,e)}function Qi(t,e,r,n){return vn(vr(t,e+1),3,n)}function Xi(t,e,r,n){return vn(kr(t,e+1),5,n)}function Zi(t,e,r,n){return vn(rs(t,e+1),9,n)}function Ut(t,e,r){let n=e.value;if(n===!1)t.pushByte(l.float.majorEncoded|wr);else if(n===!0)t.pushByte(l.float.majorEncoded|xr);else if(n===null)t.pushByte(l.float.majorEncoded|br);else if(n===void 0)t.pushByte(l.float.majorEncoded|Er);else{let i,o=!1;(!r||r.float64!==!0)&&(kn(n),i=vr(N,1),n===i||Number.isNaN(n)?(N[0]=249,t.push(N.slice(0,3)),o=!0):(_n(n),i=kr(N,1),n===i&&(N[0]=250,t.push(N.slice(0,5)),o=!0))),o||(ts(n),i=rs(N,1),N[0]=251,t.push(N.slice(0,9)))}}Ut.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){kn(n);let i=vr(N,1);if(n===i||Number.isNaN(n))return 3;if(_n(n),i=kr(N,1),n===i)return 5}return 9};var es=new ArrayBuffer(9),Q=new DataView(es,1),N=new Uint8Array(es,0);function kn(t){if(t===1/0)Q.setUint16(0,31744,!1);else if(t===-1/0)Q.setUint16(0,64512,!1);else if(Number.isNaN(t))Q.setUint16(0,32256,!1);else{Q.setFloat32(0,t);let e=Q.getUint32(0),r=(e&2139095040)>>23,n=e&8388607;if(r===255)Q.setUint16(0,31744,!1);else if(r===0)Q.setUint16(0,(e&2147483648)>>16|n>>13,!1);else{let i=r-127;i<-24?Q.setUint16(0,0):i<-14?Q.setUint16(0,(e&2147483648)>>16|1<<24+i,!1):Q.setUint16(0,(e&2147483648)>>16|i+15<<10|n>>13,!1)}}}function vr(t,e){if(t.length-e<2)throw new Error(`${y} 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,i=r&1023,o;return n===0?o=i*2**-24:n!==31?o=(i+1024)*2**(n-25):o=i===0?1/0:NaN,r&32768?-o:o}function _n(t){Q.setFloat32(0,t,!1)}function kr(t,e){if(t.length-e<4)throw new Error(`${y} not enough data for float32`);let r=(t.byteOffset||0)+e;return new DataView(t.buffer,r,4).getFloat32(0,!1)}function ts(t){Q.setFloat64(0,t,!1)}function rs(t,e){if(t.length-e<8)throw new Error(`${y} not enough data for float64`);let r=(t.byteOffset||0)+e;return new DataView(t.buffer,r,8).getFloat64(0,!1)}function Oc(t,e){let r=t.value;if(r===!1)return Uint8Array.of(l.float.majorEncoded|wr);if(r===!0)return Uint8Array.of(l.float.majorEncoded|xr);if(r===null)return Uint8Array.of(l.float.majorEncoded|br);if(r===void 0)return Uint8Array.of(l.float.majorEncoded|Er);if(!e){if(kn(r),r===vr(N,1)||Number.isNaN(r))return N[0]=249,N.slice(0,3);if(_n(r),r===kr(N,1))return N[0]=250,N.slice(0,5)}return ts(r),N[0]=251,N.slice(0,9)}function Yi(t,e){let r=t,n=e?.float64===!0,i=n?r._keyBytesFloat64:r._keyBytes;if(i!==void 0)return i;let o=Oc(t,n);return n?r._keyBytesFloat64=o:r._keyBytes=o,o}Ut.compareTokens=function(e,r,n){let i=Yi(e,n),o=Yi(r,n);return i.length!==o.length?i.length<o.length?-1:1:Ke(i,o)};function k(t,e,r){throw new Error(`${y} encountered invalid minor (${r}) for major ${t[e]>>>5}`)}function _r(t){return()=>{throw new Error(`${y} ${t}`)}}var p=[];for(let t=0;t<=23;t++)p[t]=k;p[24]=li;p[25]=fi;p[26]=hi;p[27]=di;p[28]=k;p[29]=k;p[30]=k;p[31]=k;for(let t=32;t<=55;t++)p[t]=k;p[56]=pi;p[57]=mi;p[58]=yi;p[59]=wi;p[60]=k;p[61]=k;p[62]=k;p[63]=k;for(let t=64;t<=87;t++)p[t]=xi;p[88]=bi;p[89]=Ei;p[90]=vi;p[91]=ki;p[92]=k;p[93]=k;p[94]=k;p[95]=_r("indefinite length bytes/strings are not supported");for(let t=96;t<=119;t++)p[t]=Ii;p[120]=Ai;p[121]=Ti;p[122]=Si;p[123]=Bi;p[124]=k;p[125]=k;p[126]=k;p[127]=_r("indefinite length bytes/strings are not supported");for(let t=128;t<=151;t++)p[t]=Di;p[152]=Ni;p[153]=Li;p[154]=Ui;p[155]=Pi;p[156]=k;p[157]=k;p[158]=k;p[159]=Ri;for(let t=160;t<=183;t++)p[t]=Fi;p[184]=Mi;p[185]=Oi;p[186]=zi;p[187]=$i;p[188]=k;p[189]=k;p[190]=k;p[191]=Hi;for(let t=192;t<=215;t++)p[t]=Vi;p[216]=qi;p[217]=ji;p[218]=Gi;p[219]=Wi;p[220]=k;p[221]=k;p[222]=k;p[223]=k;for(let t=224;t<=243;t++)p[t]=_r("simple values are not supported");p[244]=k;p[245]=k;p[246]=k;p[247]=Ji;p[248]=_r("simple values are not supported");p[249]=Qi;p[250]=Xi;p[251]=Zi;p[252]=k;p[253]=k;p[254]=k;p[255]=Ki;var re=[];for(let t=0;t<24;t++)re[t]=new d(l.uint,t,1);for(let t=-1;t>=-24;t--)re[31-t]=new d(l.negint,t,1);re[64]=new d(l.bytes,new Uint8Array(0),1);re[96]=new d(l.string,"",1);re[128]=new d(l.array,0,1);re[160]=new d(l.map,0,1);re[244]=new d(l.false,!1,1);re[245]=new d(l.true,!0,1);re[246]=new d(l.null,null,1);function Ir(t){switch(t.type){case l.false:return ie([244]);case l.true:return ie([245]);case l.null:return ie([246]);case l.bytes:return t.value.length?void 0:ie([64]);case l.string:return t.value===""?ie([96]):void 0;case l.array:return t.value===0?ie([128]):void 0;case l.map:return t.value===0?ie([160]):void 0;case l.uint:return t.value<24?ie([Number(t.value)]):void 0;case l.negint:if(t.value>=-24)return ie([31-Number(t.value)])}}var $c={float64:!1,mapSorter:Tn,quickEncodeToken:Ir},as=Object.freeze({mapSorter:Vc,quickEncodeToken:Ir});function An(){let t=[];return t[l.uint.major]=se,t[l.negint.major]=dr,t[l.bytes.major]=Qe,t[l.string.major]=Ci,t[l.array.major]=mr,t[l.map.major]=yr,t[l.tag.major]=gr,t[l.float.major]=Ut,t}var Oe=An(),Ar=new Ct,tt=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)}},xe={null:new d(l.null,null),undefined:new d(l.undefined,void 0),true:new d(l.true,!0),false:new d(l.false,!1),emptyArray:new d(l.array,0),emptyMap:new d(l.map,0)},ae={number(t,e,r,n){return!Number.isInteger(t)||!Number.isSafeInteger(t)?new d(l.float,t):t>=0?new d(l.uint,t):new d(l.negint,t)},bigint(t,e,r,n){return t>=BigInt(0)?new d(l.uint,t):new d(l.negint,t)},Uint8Array(t,e,r,n){return new d(l.bytes,t)},string(t,e,r,n){return new d(l.string,t)},boolean(t,e,r,n){return t?xe.true:xe.false},null(t,e,r,n){return xe.null},undefined(t,e,r,n){return xe.undefined},ArrayBuffer(t,e,r,n){return new d(l.bytes,new Uint8Array(t))},DataView(t,e,r,n){return new d(l.bytes,new Uint8Array(t.buffer,t.byteOffset,t.byteLength))},Array(t,e,r,n){if(!t.length)return r.addBreakTokens===!0?[xe.emptyArray,new d(l.break)]:xe.emptyArray;n=tt.createCheck(n,t);let i=[],o=0;for(let s of t)i[o++]=Ee(s,r,n);return r.addBreakTokens?[new d(l.array,t.length),i,new d(l.break)]:[new d(l.array,t.length),i]},Object(t,e,r,n){let i=e!=="Object",o=i?t.keys():Object.keys(t),s=i?t.size:o.length,a;if(s){a=new Array(s),n=tt.createCheck(n,t);let c=!i&&r.ignoreUndefinedProperties,u=0;for(let f of o){let h=i?t.get(f):t[f];c&&h===void 0||(a[u++]=[Ee(f,r,n),Ee(h,r,n)])}u<s&&(a.length=u)}return a?.length?(Hc(a,r),r.addBreakTokens?[new d(l.map,a.length),a,new d(l.break)]:[new d(l.map,a.length),a]):r.addBreakTokens===!0?[xe.emptyMap,new d(l.break)]:xe.emptyMap},Tagged(t,e,r,n){return[new d(l.tag,t.tag),Ee(t.value,r,n)]}};ae.Map=ae.Object;ae.Buffer=ae.Uint8Array;for(let t of"Uint8Clamped Uint16 Uint32 Int8 Int16 Int32 BigUint64 BigInt64 Float32 Float64".split(" "))ae[`${t}Array`]=ae.DataView;function Ee(t,e={},r){let n=xn(t),i=e&&e.typeEncoders&&e.typeEncoders[n]||ae[n];if(typeof i=="function"){let s=i(t,n,e,r);if(s!=null)return s}let o=ae[n];if(!o)throw new Error(`${Fe} unsupported type: ${n}`);return o(t,n,e,r)}function Hc(t,e){let r=e.mapSorter;r&&t.sort((n,i)=>r(n,i,e))}function Tn(t,e,r){let n=Array.isArray(t[0])?t[0][0]:t[0],i=Array.isArray(e[0])?e[0][0]:e[0];if(n.type.major!==i.type.major)return n.type.compare(i.type);let o=n.type.major,s=Oe[o].compareTokens(n,i,r);return s===0&&console.warn("WARNING: complex key types used, CBOR key sorting guarantees are gone"),s}function Vc(t,e){if(t[0]instanceof d&&e[0]instanceof d){let r=t[0],n=e[0];return r._keyBytes||(r._keyBytes=ns(r.value)),n._keyBytes||(n._keyBytes=ns(n.value)),Ke(r._keyBytes,n._keyBytes)}throw new Error("rfc8949MapSorter: complex key types are not supported yet")}function ns(t){return Bn(t,Oe,as)}function et(t,e,r,n){if(Array.isArray(e))for(let i of e)et(t,i,r,n);else r[e.type.major](t,e,n)}var os=l.uint.majorEncoded,is=l.negint.majorEncoded,qc=l.bytes.majorEncoded,jc=l.string.majorEncoded,ss=l.array.majorEncoded,In=l.map.majorEncoded,Gc=l.float.majorEncoded|wr,Wc=l.float.majorEncoded|xr,Yc=l.float.majorEncoded|br,Jc=l.float.majorEncoded|Er,Kc=BigInt(-1),Qc=BigInt(1);function be(t,e,r){r<24?t.pushByte(e|Number(r)):D(t,e,r)}function Xc(t){return t.addBreakTokens!==!0}function Zc(t,e,r,n,i){let o=r==="Map",s=o?e.keys():Object.keys(e),a=o?e.size:s.length;if(!a){t.pushByte(In);return}i=tt.createCheck(i,e);let c=!o&&n.ignoreUndefinedProperties,u=new Array(a),f=0;for(let h of s){let m=o?e.get(h):e[h];c&&m===void 0||(u[f++]=[Ee(h,n,i),m])}if(f===0){t.pushByte(In);return}f<a&&(u.length=f),u.sort((h,m)=>Tn(h,m,n)),be(t,In,f);for(let[h,m]of u)et(t,h,Oe,n),Sn(t,m,n,i)}function Sn(t,e,r,n){let i=xn(e),o=r.typeEncoders&&r.typeEncoders[i];if(o){let s=o(e,i,r,n);if(s!=null){et(t,s,Oe,r);return}}switch(i){case"null":t.pushByte(Yc);return;case"undefined":t.pushByte(Jc);return;case"boolean":t.pushByte(e?Wc:Gc);return;case"number":!Number.isInteger(e)||!Number.isSafeInteger(e)?Ut(t,new d(l.float,e),r):e>=0?be(t,os,e):be(t,is,e*-1-1);return;case"bigint":e>=BigInt(0)?be(t,os,e):be(t,is,e*Kc-Qc);return;case"string":{let s=Je(e);be(t,jc,s.length),t.push(s);return}case"Uint8Array":be(t,qc,e.length),t.push(e);return;case"Array":if(!e.length){t.pushByte(ss);return}n=tt.createCheck(n,e),be(t,ss,e.length);for(let s of e)Sn(t,s,r,n);return;case"Object":case"Map":if(r.mapSorter===Tn)Zc(t,e,i,r,n);else{let s=ae.Object(e,i,r,n);et(t,s,Oe,r)}return;default:{let s=ae[i];if(!s)throw new Error(`${Fe} unsupported type: ${i}`);let a=s(e,i,r,n);et(t,a,Oe,r)}}}function Bn(t,e,r,n){let i=n instanceof Uint8Array,o=i?new hr(n):Ar,s=Ee(t,r);if(!Array.isArray(s)&&r.quickEncodeToken){let a=r.quickEncodeToken(s);if(a)return i?(o.push(a),o.toBytes()):a;let c=e[s.type.major];if(c.encodedSize){let u=c.encodedSize(s,r);if(i||(o=new Ct(u)),c(o,s,r),o.chunks.length!==1)throw new Error(`Unexpected error: pre-calculated length for ${s} was wrong`);return i?o.toBytes():Re(o.chunks[0])}}return o.reset(),et(o,s,e,r),o.toBytes(!0)}function Cn(t,e){return e=Object.assign({},$c,e),Xc(e)?(Ar.reset(),Sn(Ar,t,e,void 0),Ar.toBytes(!0)):Bn(t,Oe,e)}var eu={strict:!1,allowIndefinite:!0,allowUndefined:!0,allowBigInt:!0},Tr=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=re[e];if(r===void 0){let n=p[e];if(!n)throw new Error(`${y} no decoder for major type ${e>>>5} (byte 0x${e.toString(16).padStart(2,"0")})`);let i=e&31;r=n(this.data,this._pos,i,this.options)}return this._pos+=r.encodedLength,r}},ve=Symbol.for("DONE"),rt=Symbol.for("BREAK");function tu(t,e,r){let n=[];for(let i=0;i<t.value;i++){let o=ke(e,r);if(o===rt){if(t.value===1/0)break;throw new Error(`${y} got unexpected break to lengthed array`)}if(o===ve)throw new Error(`${y} found array but not enough entries (got ${i}, expected ${t.value})`);n[i]=o}return n}function ru(t,e,r){let n=r.useMaps===!0,i=r.rejectDuplicateMapKeys===!0,o=n?void 0:{},s=n?new Map:void 0;for(let a=0;a<t.value;a++){let c=ke(e,r);if(c===rt){if(t.value===1/0)break;throw new Error(`${y} got unexpected break to lengthed map`)}if(c===ve)throw new Error(`${y} found map but not enough entries (got ${a} [no key], expected ${t.value})`);if(!n&&typeof c!="string")throw new Error(`${y} non-string keys not supported (got ${typeof c})`);if(i&&(n&&s.has(c)||!n&&Object.hasOwn(o,c)))throw new Error(`${y} found repeat map key "${c}"`);let u=ke(e,r);if(u===ve)throw new Error(`${y} found map but not enough entries (got ${a} [no value], expected ${t.value})`);n?s.set(c,u):c==="__proto__"?Object.defineProperty(o,c,{value:u,configurable:!0,enumerable:!0,writable:!0}):o[c]=u}return n?s:o}function*nu(t,e,r){for(let n=0;n<t.value;n++){let i=ke(e,r);if(i===rt){if(t.value===1/0)break;throw new Error(`${y} got unexpected break to lengthed map`)}if(i===ve)throw new Error(`${y} found map but not enough entries (got ${n} [no key], expected ${t.value})`);let o=ke(e,r);if(o===ve)throw new Error(`${y} found map but not enough entries (got ${n} [no value], expected ${t.value})`);yield[i,o]}}function ou(t,e){let r=function(){if(r._called)throw new Error(`${y} tag decode() may only be called once`);r._called=!0;let n=ke(t,e);if(n===ve)throw new Error(`${y} tag content missing`);if(n===rt)throw new Error(`${y} got unexpected break in tag content`);return n};return r.entries=function(){if(r._called)throw new Error(`${y} tag decode() may only be called once`);r._called=!0;let n=t.next();if(!l.equals(n.type,l.map))throw new Error(`${y} entries() requires map content, got ${n.type.name}`);let i=[];for(let o of nu(n,t,e))i.push(o);return i},r._called=!1,r}function ke(t,e){if(t.done())return ve;let r=t.next();if(l.equals(r.type,l.break))return rt;if(r.type.terminal)return r.value;if(l.equals(r.type,l.array))return tu(r,t,e);if(l.equals(r.type,l.map))return ru(r,t,e);if(l.equals(r.type,l.tag)){if(e.tags&&typeof e.tags[r.value]=="function"){let n=ou(t,e),i=e.tags[r.value](n);if(!n._called)throw new Error(`${y} tag decoder must call decode() or entries()`);return i}throw new Error(`${y} tag not supported (${r.value})`)}throw new Error("unsupported")}function Dn(t,e){if(!(t instanceof Uint8Array))throw new Error(`${y} data to decode must be a Uint8Array`);e=Object.assign({},eu,e);let r=Re(t),n=e.tokenizer||new Tr(r,e),i=ke(n,e);if(i===ve)throw new Error(`${y} did not find any content to decode`);if(i===rt)throw new Error(`${y} got unexpected break`);return[i,t.subarray(n.pos())]}function Pt(t,e){let[r,n]=Dn(t,e);if(n.length>0)throw new Error(`${y} too many terminals, data makes no sense`);return r}var Sr=class t{constructor(e,r){if(typeof e!="number"||!Number.isInteger(e)||e<0)throw new TypeError("Tagged: tag must be a non-negative integer");this.tag=e,this.value=r}static decoder(e){return r=>new t(e,r())}static preserve(...e){let r={};for(let n of e)r[n]=t.decoder(n);return r}};Object.defineProperty(Sr.prototype,Symbol.toStringTag,{value:"Tagged"});var Fn={};j(Fn,{base32:()=>ot,base32hex:()=>yu,base32hexpad:()=>wu,base32hexpadupper:()=>xu,base32hexupper:()=>gu,base32pad:()=>pu,base32padupper:()=>mu,base32upper:()=>du,base32z:()=>bu});var vd=new Uint8Array(0);function us(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 X(t){if(t instanceof Uint8Array&&t.constructor.name==="Uint8Array")return ze(t);if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.isView(t))return ze(new Uint8Array(t.buffer,t.byteOffset,t.byteLength));throw new Error("Unknown type, must be binary type")}function ls(t){let e=new Uint8Array(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}var cs=4096;function fs(t){let e=t.length;if(e<=cs)return String.fromCharCode.apply(String,t);let r="",n=0;for(;n<e;)r+=String.fromCharCode.apply(String,t.subarray(n,n+=cs));return r}function su(t){return t?.buffer instanceof ArrayBuffer}function ze(t){return su(t)?t:t.slice()}function au(t,e,r){if(t.length>=255)throw new TypeError("Alphabet too long");for(var n=new Uint8Array(256),i=0;i<n.length;i++)n[i]=255;for(var o=0;o<t.length;o++){var s=t.charAt(o),a=s.charCodeAt(0);if(n[a]!==255)throw new TypeError(s+" is ambiguous");if(n[a]=o,r){var c=s.toLowerCase().charCodeAt(0),u=s.toUpperCase().charCodeAt(0);c!==a&&(n[c]=o),u!==a&&(n[u]=o)}}var f=t.length,h=t.charAt(0),m=Math.log(f)/Math.log(256),g=Math.log(256)/Math.log(f);function v(x){if(x instanceof Uint8Array||(ArrayBuffer.isView(x)?x=new Uint8Array(x.buffer,x.byteOffset,x.byteLength):Array.isArray(x)&&(x=Uint8Array.from(x))),!(x instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(x.length===0)return"";for(var T=0,C=0,R=0,L=x.length;R!==L&&x[R]===0;)R++,T++;for(var z=(L-R)*g+1>>>0,V=new Uint8Array(z);R!==L;){for(var oe=x[R],we=0,te=z-1;(oe!==0||we<C)&&te!==-1;te--,we++)oe+=256*V[te]>>>0,V[te]=oe%f>>>0,oe=oe/f>>>0;if(oe!==0)throw new Error("Non-zero carry");C=we,R++}for(var de=z-C;de!==z&&V[de]===0;)de++;for(var ur=h.repeat(T);de<z;++de)ur+=t.charAt(V[de]);return ur}function b(x){if(typeof x!="string")throw new TypeError("Expected String");if(x.length===0)return new Uint8Array;var T=0;if(x[T]!==" "){for(var C=0,R=0;x[T]===h;)C++,T++;for(var L=(x.length-T)*m+1>>>0,z=new Uint8Array(L);x[T];){var V=n[x.charCodeAt(T)];if(V===255)return;for(var oe=0,we=L-1;(V!==0||oe<R)&&we!==-1;we--,oe++)V+=f*z[we]>>>0,z[we]=V%256>>>0,V=V/256>>>0;if(V!==0)throw new Error("Non-zero carry");R=oe,T++}if(x[T]!==" "){for(var te=L-R;te!==L&&z[te]===0;)te++;for(var de=new Uint8Array(C+(L-te)),ur=C;te!==L;)de[ur++]=z[te++];return de}}}function w(x){var T=b(x);if(T)return T;throw new Error(`Non-${e} character`)}return{encode:v,decodeUnsafe:b,decode:w}}var cu=au,uu=cu,hs=uu;var Ln=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")}},Un=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,r,n){this.name=e,this.prefix=r;let i=r.codePointAt(0);if(i===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=i,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 ds(this,e)}},Pn=class{decoders;constructor(e){this.decoders=e}or(e){return ds(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 ds(t,e){return new Pn({...t.decoders??{[t.prefix]:t},...e.decoders??{[e.prefix]:e}})}var Rn=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,r,n,i){this.name=e,this.prefix=r,this.baseEncode=n,this.baseDecode=i,this.encoder=new Ln(e,r,n),this.decoder=new Un(e,r,i)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function nt({name:t,prefix:e,encode:r,decode:n}){return new Rn(t,e,r,n)}function _e({name:t,prefix:e,alphabet:r,caseInsensitive:n=!1}){let{encode:i,decode:o}=hs(r,t,n);return nt({prefix:e,name:t,encode:i,decode:s=>X(o(s))})}function lu(t,e,r,n){let i=t.length;for(;t[i-1]==="=";)--i;let o=new Uint8Array(i*r/8|0),s=0,a=0,c=0;for(let u=0;u<i;++u){let f=e[t[u]];if(f===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|f,s+=r,s>=8&&(s-=8,o[c++]=255&a>>s)}if(s>=r||(255&a<<8-s)!==0)throw new SyntaxError("Unexpected end of data");return o}function fu(t,e,r){let n=e[e.length-1]==="=",i=(1<<r)-1,o="",s=0,a=0;for(let c=0;c<t.length;++c)for(a=a<<8|t[c],s+=8;s>r;)s-=r,o+=e[i&a>>s];if(s!==0&&(o+=e[i&a<<r-s]),n)for(;(o.length*r&7)!==0;)o+="=";return o}function hu(t,e){let r={};for(let n=0;n<t.length;++n)if(r[t[n]]=n,e){let i=t[n].toLowerCase(),o=t[n].toUpperCase();i!==t[n]&&(r[i]=n),o!==t[n]&&(r[o]=n)}return r}function B({name:t,prefix:e,bitsPerChar:r,alphabet:n,caseInsensitive:i=!1}){let o=hu(n,i);return nt({prefix:e,name:t,encode(s){return fu(s,n,r)},decode(s){return lu(s,o,r,t)}})}var ot=B({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5,caseInsensitive:!0}),du=B({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5,caseInsensitive:!0}),pu=B({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5,caseInsensitive:!0}),mu=B({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5,caseInsensitive:!0}),yu=B({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5,caseInsensitive:!0}),gu=B({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5,caseInsensitive:!0}),wu=B({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5,caseInsensitive:!0}),xu=B({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5,caseInsensitive:!0}),bu=B({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Mn={};j(Mn,{base36:()=>Rt,base36upper:()=>Eu});var Rt=_e({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz",caseInsensitive:!0}),Eu=_e({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",caseInsensitive:!0});var On={};j(On,{base58btc:()=>ce,base58flickr:()=>vu});var ce=_e({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),vu=_e({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var ku=ys,ps=128,_u=127,Iu=~_u,Au=Math.pow(2,31);function ys(t,e,r){e=e||[],r=r||0;for(var n=r;t>=Au;)e[r++]=t&255|ps,t/=128;for(;t&Iu;)e[r++]=t&255|ps,t>>>=7;return e[r]=t|0,ys.bytes=r-n+1,e}var Tu=zn,Su=128,ms=127;function zn(t,n){var r=0,n=n||0,i=0,o=n,s,a=t.length;do{if(o>=a)throw zn.bytes=0,new RangeError("Could not decode varint");s=t[o++],r+=i<28?(s&ms)<<i:(s&ms)*Math.pow(2,i),i+=7}while(s>=Su);return zn.bytes=o-n,r}var Bu=Math.pow(2,7),Cu=Math.pow(2,14),Du=Math.pow(2,21),Nu=Math.pow(2,28),Lu=Math.pow(2,35),Uu=Math.pow(2,42),Pu=Math.pow(2,49),Ru=Math.pow(2,56),Fu=Math.pow(2,63),Mu=function(t){return t<Bu?1:t<Cu?2:t<Du?3:t<Nu?4:t<Lu?5:t<Uu?6:t<Pu?7:t<Ru?8:t<Fu?9:10},Ou={encode:ku,decode:Tu,encodingLength:Mu},zu=Ou,Ft=zu;function Mt(t,e=0){let r=Ft.decode(t,e),n=Ft.decode.bytes;if(n>9)throw new RangeError("Invalid varint: too long");if(n>1&&t[e+n-1]===0)throw new RangeError("Invalid varint: not minimally encoded");return[r,n]}function it(t,e,r=0){return Ft.encode(t,e,r),e}function st(t){return Ft.encodingLength(t)}function ct(t,e){let r=e.byteLength,n=st(t),i=n+st(r),o=new Uint8Array(i+r);return it(t,o,0),it(r,o,n),o.set(e,i),new at(t,r,e,o)}function ut(t){let e=X(t),[r,n]=Mt(e),[i,o]=Mt(e.subarray(n)),s=e.subarray(n+o);if(s.byteLength!==i)throw new Error("Incorrect length");return new at(r,i,s,e)}function gs(t,e){if(t===e)return!0;{let r=e;return t.code===r.code&&t.size===r.size&&r.bytes instanceof Uint8Array&&us(t.bytes,r.bytes)}}var at=class{code;size;digest;bytes;constructor(e,r,n,i){this.code=e,this.size=r,this.digest=ze(n),this.bytes=ze(i)}};function ws(t,e){let{bytes:r,version:n}=t;return n===0?Hu(r,$n(t),e??ce.encoder):Vu(r,$n(t),e??ot.encoder)}var xs=new WeakMap;function $n(t){let e=xs.get(t);if(e==null){let r=new Map;return xs.set(t,r),r}return e}var E=class t{code;version;multihash;bytes;"/";constructor(e,r,n,i){this.code=r,this.version=e,this.multihash=n,this.bytes=ze(i),this["/"]=this.bytes}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!==Ot)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==qu)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=ct(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&&gs(e.multihash,n.multihash)}toString(e){return ws(this,e)}toJSON(){return{"/":ws(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:i,multihash:o,bytes:s}=r;return new t(n,i,o,s??bs(n,i,o.bytes))}else if(r[ju]===!0){let{version:n,multihash:i,code:o}=r,s=ut(i);return t.create(n,o,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!==Ot)throw new Error(`Version 0 CID must use dag-pb (code: ${Ot}) block encoding`);return new t(e,r,n,n.bytes)}case 1:{let i=bs(e,r,n.bytes);return new t(e,r,n,i)}default:throw new Error("Invalid version")}}static createV0(e){return t.create(0,Ot,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,i=X(e.subarray(n,n+r.multihashSize));if(i.byteLength!==r.multihashSize)throw new Error("Incorrect length");let o=i.subarray(r.multihashSize-r.digestSize),s=new at(r.multihashCode,r.digestSize,o,i);return[r.version===0?t.createV0(s):t.createV1(r.codec,s),e.subarray(r.size)]}static inspectBytes(e){let r=0,n=()=>{let[h,m]=Mt(e.subarray(r));return r+=m,h},i=n(),o=Ot;if(i===18?(i=0,r=0):o=n(),i!==0&&i!==1)throw new RangeError(`Invalid CID version ${i}`);let s=r,a=n(),c=n(),u=r+c,f=u-s;return{version:i,codec:o,multihashCode:a,digestSize:c,multihashSize:f,size:u}}static parse(e,r){let[n,i]=$u(e,r),o=t.decode(i);if(o.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return $n(o).set(n,e),o}};function $u(t,e){switch(t[0]){case"Q":{let r=e??ce;return[ce.prefix,r.decode(`${ce.prefix}${t}`)]}case ce.prefix:{let r=e??ce;return[ce.prefix,r.decode(t)]}case ot.prefix:{let r=e??ot;return[ot.prefix,r.decode(t)]}case Rt.prefix:{let r=e??Rt;return[Rt.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 Hu(t,e,r){let{prefix:n}=r;if(n!==ce.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let i=e.get(n);if(i==null){let o=r.encode(t).slice(1);return e.set(n,o),o}else return i}function Vu(t,e,r){let{prefix:n}=r,i=e.get(n);if(i==null){let o=r.encode(t);return e.set(n,o),o}else return i}var Ot=112,qu=18;function bs(t,e,r){let n=st(t),i=n+st(e),o=new Uint8Array(i+r.byteLength);return it(t,o,0),it(e,o,n),o.set(r,i),o}var ju=Symbol.for("@ipld/js-cid/CID");var Es=42;function Gu(t){return t instanceof ArrayBuffer?new Uint8Array(t,0,t.byteLength):t}function Wu(t){if(t.asCID!==t&&t["/"]!==t.bytes)return null;let e=E.asCID(t);if(!e)return null;let r=new Uint8Array(e.bytes.byteLength+1);return r.set(e.bytes,1),[new d(l.tag,Es),new d(l.bytes,r)]}function Yu(){throw new Error("`undefined` is not supported by the IPLD Data Model and cannot be encoded")}function Ju(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 Ku(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 Hn={float64:!0,typeEncoders:{Map:Ku,Object:Wu,undefined:Yu,number:Ju}},zd={...Hn,typeEncoders:{...Hn.typeEncoders}};function Qu(t){let e=t();if(e[0]!==0)throw new Error("Invalid CID for CBOR tag 42; expected leading 0x00");return E.decode(e.subarray(1))}var Vn={allowIndefinite:!1,coerceUndefinedToNull:!0,allowNaN:!1,allowInfinity:!1,allowBigInt:!0,strict:!0,useMaps:!1,rejectDuplicateMapKeys:!0,tags:{[Es]:Qu}},$d={...Vn,tags:{...Vn.tags}};var Cr=113,qn=t=>Cn(t,Hn),$e=t=>Pt(Gu(t),Vn);var Wn=St(Dr(),1);var Yn=40;function Jn(t,e){if(!t.length)throw new Error("Unexpected end of data");let r=Wn.default.decode(t);return e.seek(Wn.default.decode.bytes),r}function Kn(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 Ae={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},$t={"CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)":Ae.Link,"CarV1HeaderOrV2Pragma > roots (anon)":t=>{if(Ae.List(t)!==void 0){for(let e=0;e<t.length;e++){let r=t[e];if(r=$t["CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)"](r),r===void 0)return;if(r!==t[e]){let n=t.slice(0,e);for(let i=e;i<t.length;i++){let o=t[i];if(o=$t["CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)"](o),o===void 0)return;n.push(o)}return n}}return t}},Int:Ae.Int,CarV1HeaderOrV2Pragma:t=>{if(Ae.Map(t)===void 0)return;let e=Object.entries(t),r=t,n=1;for(let i=0;i<e.length;i++){let[o,s]=e[i];switch(o){case"roots":{let a=$t["CarV1HeaderOrV2Pragma > roots (anon)"](t[o]);if(a===void 0)return;if(a!==s||r!==t){if(r===t){r={};for(let c=0;c<i;c++)r[e[c][0]]=e[c][1]}r.roots=a}}break;case"version":{n--;let a=$t.Int(t[o]);if(a===void 0)return;if(a!==s||r!==t){if(r===t){r={};for(let c=0;c<i;c++)r[e[c][0]]=e[c][1]}r.version=a}}break;default:return}}if(!(n>0))return r}},Ht={"CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)":Ae.Link,"CarV1HeaderOrV2Pragma > roots (anon)":t=>{if(Ae.List(t)!==void 0){for(let e=0;e<t.length;e++){let r=t[e];if(r=Ht["CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)"](r),r===void 0)return;if(r!==t[e]){let n=t.slice(0,e);for(let i=e;i<t.length;i++){let o=t[i];if(o=Ht["CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)"](o),o===void 0)return;n.push(o)}return n}}return t}},Int:Ae.Int,CarV1HeaderOrV2Pragma:t=>{if(Ae.Map(t)===void 0)return;let e=Object.entries(t),r=t,n=1;for(let i=0;i<e.length;i++){let[o,s]=e[i];switch(o){case"roots":{let a=Ht["CarV1HeaderOrV2Pragma > roots (anon)"](s);if(a===void 0)return;if(a!==s||r!==t){if(r===t){r={};for(let c=0;c<i;c++)r[e[c][0]]=e[c][1]}r.roots=a}}break;case"version":{n--;let a=Ht.Int(s);if(a===void 0)return;if(a!==s||r!==t){if(r===t){r={};for(let c=0;c<i;c++)r[e[c][0]]=e[c][1]}r.version=a}}break;default:return}}if(!(n>0))return r}},Qn={toTyped:$t.CarV1HeaderOrV2Pragma,toRepresentation:Ht.CarV1HeaderOrV2Pragma};var rp=An();var pl=St(Dr(),1);var ap=[new d(l.map,2),new d(l.string,"version"),new d(l.uint,1),new d(l.string,"roots")],cp=new d(l.tag,42);async function Xn(t,e){let r=Jn(await t.upTo(8),t);if(r===0)throw new Error("Invalid CAR header (zero length)");let n=await t.exactly(r,!0),i=$e(n);if(Qn.toTyped(i)===void 0)throw new Error("Invalid CAR header format");if(i.version!==1&&i.version!==2||e!==void 0&&i.version!==e)throw new Error(`Invalid CAR version: ${i.version}${e!==void 0?` (expected ${e})`:""}`);if(i.version===1){if(!Array.isArray(i.roots))throw new Error("Invalid CAR header format");return i}if(i.roots!==void 0)throw new Error("Invalid CAR header format");let o=Kn(await t.exactly(Yn,!0));t.seek(o.dataOffset-t.pos);let s=await Xn(t,1);return Object.assign(s,o)}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 i=t.subarray(e,e+r);return n&&(e+=r),i},seek(r){e+=r},get pos(){return e}}}var Zn=St(Dr(),1),Ls=1;function eo(t){let e=qn({version:Ls,roots:t}),r=Zn.default.encode(e.length),n=new Uint8Array(r.length+e.length);return n.set(r,0),n.set(e,r.length),n}function Us(t){return{async setRoots(e){let r=eo(e);await t.write(r)},async writeBlock(e){let{cid:r,bytes:n}=e;await t.write(new Uint8Array(Zn.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 Ls}}}function Nr(){}function Ps(){let t=[],e=null,r=Nr,n=!1,i=null,o=Nr,s=()=>(e||(e=new Promise(u=>{r=()=>{e=null,r=Nr,u()}})),e),a={write(u){t.push(u);let f=s();return o(),f},async end(){n=!0;let u=s();o(),await u}},c={async next(){let u=t.shift();return u?(t.length===0&&r(),{done:!1,value:u}):n?(r(),{done:!0,value:void 0}):(i||(i=new Promise(f=>{o=()=>(i=null,o=Nr,f(c.next()))})),i)}};return{writer:a,iterator:c}}var qt=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=E.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=wl(e);let{encoder:r,iterator:n}=Rs(),i=new t(e,r),o=new Lr(n);return{writer:i,out:o}}static createAppender(){let{encoder:e,iterator:r}=Rs();e.setRoots=()=>Promise.resolve();let n=new t([],e),i=new Lr(r);return{writer:n,out:i}}static async updateRootsInBytes(e,r){let n=Vt(e);await Xn(n);let i=eo(r);if(Number(n.pos)!==i.length)throw new Error(`updateRoots() can only overwrite a header of the same length (old header is ${n.pos} bytes, new header is ${i.length} bytes)`);return e.set(i,0),e}},Lr=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 Rs(){let t=Ps(),{writer:e,iterator:r}=t;return{encoder:Us(e),iterator:r}}function wl(t){if(t===void 0)return[];if(!Array.isArray(t)){let r=E.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=E.asCID(r);if(!n)throw new TypeError("roots must be a single CID or an array of CIDs");e.push(n)}return e}function xl(t){return t[Symbol.asyncIterator]!=null}function bl(t){if(xl(t))return(async()=>{for await(let e of t);})();for(let e of t);}var Fs=bl;function El(t){let[e,r]=t[Symbol.asyncIterator]!=null?[t[Symbol.asyncIterator](),Symbol.asyncIterator]:[t[Symbol.iterator](),Symbol.iterator],n=[];return{peek:()=>e.next(),push:i=>{n.push(i)},next:()=>n.length>0?{done:!1,value:n.shift()}:e.next(),[r](){return this}}}var Ur=El;function vl(t){return t[Symbol.asyncIterator]!=null}function kl(t,e){let r=0;if(vl(t))return(async function*(){for await(let c of t)yield e(c,r++)})();let n=Ur(t),{value:i,done:o}=n.next();if(o===!0)return(function*(){})();let s=e(i,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 Pr=kl;function _l(t){return t.reason}function lt(t,e,r){if(e==null||t==null)return t;let n=r?.translateError??_l;if(e.aborted)return t.catch(()=>{}),Promise.reject(n(e));let i;return Promise.race([t,new Promise((o,s)=>{i=()=>{s(n(e))},e.addEventListener("abort",i)})]).finally(()=>{i!=null&&e.removeEventListener("abort",i)})}var Il=20;function He({name:t,code:e,encode:r,minDigestLength:n,maxDigestLength:i}){return new to(t,e,r,n,i)}var to=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,r,n,i,o){this.name=e,this.code=r,this.encode=n,this.minDigestLength=i??Il,this.maxDigestLength=o}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?Ms(n,this.code,r?.truncate):n.then(i=>Ms(i,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function Ms(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 ct(e,t)}var no={};j(no,{base64:()=>ro,base64pad:()=>Al,base64url:()=>Tl,base64urlpad:()=>Sl});var ro=B({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Al=B({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Tl=B({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Sl=B({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var oo={};j(oo,{identity:()=>jt});var zs=0,Bl="identity",$s=X;function Cl(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 ct(zs,$s(t))}var jt={code:zs,name:Bl,encode:$s,digest:Cl};function ue(t=0){return new Uint8Array(t)}function Dl(t){return t?.buffer instanceof ArrayBuffer}function Hs(t){if(Dl(t))return t;let e=t.slice();return new Uint8Array(e.buffer,0,e.byteLength)}function Gt(t,e){e==null&&(e=t.reduce((i,o)=>i+o.length,0));let r=ue(e),n=0;for(let i of t)r.set(i,n),n+=i.length;return Hs(r)}function Nl(t){return t.buffer instanceof ArrayBuffer}function Rr(t){return Nl(t)?t:t.slice()}var Ll=Math.pow(2,7),Ul=Math.pow(2,14),Pl=Math.pow(2,21),Vs=Math.pow(2,28),qs=Math.pow(2,35),js=Math.pow(2,42),Gs=Math.pow(2,49),$=128,Te=127;function Wt(t){if(t<Ll)return 1;if(t<Ul)return 2;if(t<Pl)return 3;if(t<Vs)return 4;if(t<qs)return 5;if(t<js)return 6;if(t<Gs)return 7;if(Number.MAX_SAFE_INTEGER!=null&&t>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Ws(t,e,r=0){switch(Wt(t)){case 8:e[r++]=t&255|$,t/=128;case 7:e[r++]=t&255|$,t/=128;case 6:e[r++]=t&255|$,t/=128;case 5:e[r++]=t&255|$,t/=128;case 4:e[r++]=t&255|$,t>>>=7;case 3:e[r++]=t&255|$,t>>>=7;case 2:e[r++]=t&255|$,t>>>=7;case 1:{e[r++]=t&255,t>>>=7;break}default:throw new Error("unreachable")}return e}function Ys(t,e){let r=t[e],n=0;if(n+=r&Te,r<$||(r=t[e+1],n+=(r&Te)<<7,r<$)||(r=t[e+2],n+=(r&Te)<<14,r<$)||(r=t[e+3],n+=(r&Te)<<21,r<$)||(r=t[e+4],n+=(r&Te)*Vs,r<$)||(r=t[e+5],n+=(r&Te)*qs,r<$)||(r=t[e+6],n+=(r&Te)*js,r<$)||(r=t[e+7],n+=(r&Te)*Gs,r<$))return n;throw new RangeError("Could not decode varint")}var io=new Float32Array([-0]),Se=new Uint8Array(io.buffer);function Js(t,e,r){io[0]=t,e[r]=Se[0],e[r+1]=Se[1],e[r+2]=Se[2],e[r+3]=Se[3]}function Ks(t,e){return Se[0]=t[e],Se[1]=t[e+1],Se[2]=t[e+2],Se[3]=t[e+3],io[0]}var so=new Float64Array([-0]),F=new Uint8Array(so.buffer);function Qs(t,e,r){so[0]=t,e[r]=F[0],e[r+1]=F[1],e[r+2]=F[2],e[r+3]=F[3],e[r+4]=F[4],e[r+5]=F[5],e[r+6]=F[6],e[r+7]=F[7]}function Xs(t,e){return F[0]=t[e],F[1]=t[e+1],F[2]=t[e+2],F[3]=t[e+3],F[4]=t[e+4],F[5]=t[e+5],F[6]=t[e+6],F[7]=t[e+7],so[0]}var Rl=BigInt(Number.MAX_SAFE_INTEGER),Fl=BigInt(Number.MIN_SAFE_INTEGER),K=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 Ve;if(e<Rl&&e>Fl)return this.fromNumber(Number(e));let r=e<0n;r&&(e=-e);let n=e>>32n,i=e-(n<<32n);return r&&(n=~n|0n,i=~i|0n,++i>Zs&&(i=0n,++n>Zs&&(n=0n))),new t(Number(i),Number(n))}static fromNumber(e){if(e===0)return Ve;let r=e<0;r&&(e=-e);let n=e>>>0,i=(e-n)/4294967296>>>0;return r&&(i=~i>>>0,n=~n>>>0,++n>4294967295&&(n=0,++i>4294967295&&(i=0))),new t(n,i)}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):Ve}},Ve=new K(0,0);Ve.toBigInt=function(){return 0n};Ve.zzEncode=Ve.zzDecode=function(){return this};Ve.length=function(){return 1};var Zs=4294967296n;function ea(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 ta(t,e,r){if(r-e<1)return"";let i,o=[],s=0,a;for(;e<r;)a=t[e++],a<128?o[s++]=a:a>191&&a<224?o[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,o[s++]=55296+(a>>10),o[s++]=56320+(a&1023)):o[s++]=(a&15)<<12|(t[e++]&63)<<6|t[e++]&63,s>8191&&((i??(i=[])).push(String.fromCharCode.apply(String,o)),s=0);return i!=null?(s>0&&i.push(String.fromCharCode.apply(String,o.slice(0,s))),i.join("")):String.fromCharCode.apply(String,o.slice(0,s))}function ao(t,e,r){let n=r,i,o;for(let s=0;s<t.length;++s)i=t.charCodeAt(s),i<128?e[r++]=i:i<2048?(e[r++]=i>>6|192,e[r++]=i&63|128):(i&64512)===55296&&((o=t.charCodeAt(s+1))&64512)===56320?(i=65536+((i&1023)<<10)+(o&1023),++s,e[r++]=i>>18|240,e[r++]=i>>12&63|128,e[r++]=i>>6&63|128,e[r++]=i&63|128):(e[r++]=i>>12|224,e[r++]=i>>6&63|128,e[r++]=i&63|128);return r-n}function ne(t,e){return RangeError(`index out of range: ${t.pos} + ${e??1} > ${t.len}`)}function Fr(t,e){return(t[e-4]|t[e-3]<<8|t[e-2]<<16|t[e-1]<<24)>>>0}var co=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(e){this.buf=Rr(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,ne(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 ne(this,4);return Fr(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw ne(this,4);return Fr(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw ne(this,4);let e=Ks(this.buf,this.pos);return this.pos+=4,e}double(){if(this.pos+8>this.len)throw ne(this,4);let e=Xs(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 ne(this,e);return this.pos+=e,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let e=this.bytes();return ta(e,0,e.length)}skip(e){if(typeof e=="number"){if(this.pos+e>this.len)throw ne(this,e);this.pos+=e}else do if(this.pos>=this.len)throw ne(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 K(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 ne(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 ne(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 ne(this,8);let e=Fr(this.buf,this.pos+=4),r=Fr(this.buf,this.pos+=4);return new K(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=Ys(this.buf,this.pos);return this.pos+=Wt(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 Yt(t){return new co(t instanceof Uint8Array?t:t.subarray())}function Be(t,e,r){let n=Yt(t);return e.decode(n,void 0,r)}var uo={};j(uo,{base10:()=>Ml});var Ml=_e({prefix:"9",name:"base10",alphabet:"0123456789"});var lo={};j(lo,{base16:()=>Ol,base16upper:()=>zl});var Ol=B({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4,caseInsensitive:!0}),zl=B({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4,caseInsensitive:!0});var fo={};j(fo,{base2:()=>$l});var $l=B({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var ho={};j(ho,{base256emoji:()=>Gl});var na=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}"),Hl=na.reduce((t,e,r)=>(t[r]=e,t),[]),Vl=na.reduce((t,e,r)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return t[n]=r,t},[]);function ql(t){return t.reduce((e,r)=>(e+=Hl[r],e),"")}function jl(t){let e=[];for(let r of t){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let i=Vl[n];if(i==null)throw new Error(`Non-base256emoji character: ${r}`);e.push(i)}return new Uint8Array(e)}var Gl=nt({prefix:"\u{1F680}",name:"base256emoji",encode:ql,decode:jl});var po={};j(po,{base8:()=>Wl});var Wl=B({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var mo={};j(mo,{identity:()=>Yl});var Yl=nt({prefix:"\0",name:"identity",encode:t=>fs(X(t)),decode:t=>X(ls(t))});var Sm=new TextEncoder,Jl=new TextDecoder;var Mr=512;function Or(t){return JSON.parse(Jl.decode(t))}var ft=85;var yo={};j(yo,{sha256:()=>Kl,sha512:()=>Ql});function oa(t){return async e=>new Uint8Array(await crypto.subtle.digest(t,e))}var Kl=He({name:"sha2-256",code:18,encode:oa("SHA-256")}),Ql=He({name:"sha2-512",code:19,encode:oa("SHA-512")});var go={...mo,...fo,...po,...uo,...lo,...Fn,...Mn,...On,...no,...ho},Nm={...yo,...oo};function sa(t,e,r,n){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:r},decoder:{decode:n}}}var ia=sa("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),wo=sa("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=ue(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}),Xl={utf8:ia,"utf-8":ia,hex:go.base16,latin1:wo,ascii:wo,binary:wo,...go},aa=Xl;function $r(t,e="utf8"){let r=aa[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.decoder.decode(`${r.prefix}${t}`)}function xo(t){let e=t??8192,r=e>>>1,n,i=e;return function(s){if(s<1||s>r)return ue(s);i+s>e&&(n=ue(e),i=0);let a=n.subarray(i,i+=s);return(i&7)!==0&&(i=(i|7)+1),a}}var qe=class{fn;len;next;val;constructor(e,r,n){this.fn=e,this.len=r,this.next=void 0,this.val=n}};function bo(){}var vo=class{head;tail;len;next;constructor(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}},Zl=xo();function ef(t){return globalThis.Buffer!=null?ue(t):Zl(t)}var Qt=class{len;head;tail;states;constructor(){this.len=0,this.head=new qe(bo,0,0),this.tail=this.head,this.states=null}_push(e,r,n){return this.tail=this.tail.next=new qe(e,r,n),this.len+=r,this}uint32(e){return this.len+=(this.tail=this.tail.next=new ko((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(Hr,10,K.fromNumber(e)):this.uint32(e)}sint32(e){return this.uint32((e<<1^e>>31)>>>0)}uint64(e){let r=K.fromBigInt(e);return this._push(Hr,r.length(),r)}uint64Number(e){return this._push(Ws,Wt(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=K.fromBigInt(e).zzEncode();return this._push(Hr,r.length(),r)}sint64Number(e){let r=K.fromNumber(e).zzEncode();return this._push(Hr,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(Kt,4,e>>>0)}sfixed32(e){return this.fixed32(e)}fixed64(e){let r=K.fromBigInt(e);return this._push(Kt,4,r.lo)._push(Kt,4,r.hi)}fixed64Number(e){let r=K.fromNumber(e);return this._push(Kt,4,r.lo)._push(Kt,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(Js,4,e)}double(e){return this._push(Qs,8,e)}bytes(e){let r=e.length>>>0;return r===0?this._push(Eo,1,0):this.uint32(r)._push(rf,r,e)}string(e){let r=ea(e);return r!==0?this.uint32(r)._push(ao,r,e):this._push(Eo,1,0)}fork(){return this.states=new vo(this),this.head=this.tail=new qe(bo,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 qe(bo,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 Eo(t,e,r){e[r]=t&255}function tf(t,e,r){for(;t>127;)e[r++]=t&127|128,t>>>=7;e[r]=t}var ko=class extends qe{next;constructor(e,r){super(tf,e,r),this.next=void 0}};function Hr(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 Kt(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 rf(t,e,r){e.set(t,r)}globalThis.Buffer!=null&&(Qt.prototype.bytes=function(t){let e=t.length>>>0;return this.uint32(e),e>0&&this._push(nf,e,t),this},Qt.prototype.string=function(t){let e=globalThis.Buffer.byteLength(t);return this.uint32(e),e>0&&this._push(of,e,t),this});function nf(t,e,r){e.set(t,r)}function of(t,e,r){t.length<40?ao(t,e,r):e.utf8Write!=null?e.utf8Write(t,r):e.set($r(t),r)}function _o(){return new Qt}function Ce(t,e){let r=_o();return e.encode(t,r,{lengthDelimited:!1}),r.finish()}function*De(t,e,r){let n=Yt(t);yield*e.stream(n,void 0,".",r)}var Vr={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function qr(t,e,r,n,i){return{name:t,type:e,encode:r,decode:n,stream:i}}function Io(t){function e(o){if(t[o.toString()]==null)throw new Error("Invalid enum value");return t[o]}let r=function(s,a){let c=e(s);a.int32(c)},n=function(s){let a=s.int32();return e(a)},i=function*(s,a){};return qr("enum",Vr.VARINT,r,n,i)}function Ne(t,e,r){return qr("message",Vr.LENGTH_DELIMITED,t,e,r)}var me=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var le=class extends Error{static name="AbortError";constructor(e="The operation was aborted"){super(e),this.name="AbortError"}};var je=class extends Error{static name="InvalidParametersError";constructor(e="Invalid parameters"){super(e),this.name="InvalidParametersError"}};function sf(t){return typeof t?.handleEvent=="function"}function af(t){return t===!0||t===!1}function cf(t){return af(t)?t:t?.capture??!1}function Ao(t){let e={capture:cf(t),once:!!t?.once};return t?.passive!=null&&(e.passive=t?.passive),t?.signal!=null&&(e.signal=t?.signal),e}function ca(t,e){return Ao(t).capture===Ao(e).capture}var jr=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){let i=Ao(n);if(i?.signal?.aborted===!0)return;let o=u=>{i.once&&this.removeEventListener(e,r,i),sf(r)?r.handleEvent(u):r(u)},s=this.#e.get(e);if(s==null&&(s=[],this.#e.set(e,s)),s.some(u=>u.callback!==r?!1:ca(u.options,i)))return;super.addEventListener(e,o,i);let c=()=>{this.removeEventListener(e,r,i)};i.signal?.addEventListener("abort",c),s.push({callback:r,wrapper:o,options:i,onAbort:c})}removeEventListener(e,r,n){let i=this.#e.get(e);if(i==null){super.removeEventListener(e,r??null,n);return}this.#e.set(e,i.filter(o=>o.callback===r&&ca(o.options,n)?(super.removeEventListener(e,o.wrapper,n),o.options?.signal?.removeEventListener("abort",o.onAbort),!1):!0))}safeDispatchEvent(e,r={}){return this.dispatchEvent(new CustomEvent(e,r))}};function M(){let t={};return t.promise=new Promise((e,r)=>{t.resolve=e,t.reject=r}),t}var Gr=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}},ht=class{size;hwm;head;tail;constructor(e={}){this.hwm=e.splitLimit??16,this.head=new Gr(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 Gr(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 To=class extends Error{type;code;constructor(e,r){super(e??"The operation was aborted"),this.type="aborted",this.code=r??"ABORT_ERR"}};function dt(t={}){return uf(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 uf(t,e){e=e??{};let r=e.onEnd,n=new ht,i,o,s,a=M(),c=async()=>{try{return n.isEmpty()?s?{done:!0}:await new Promise((w,x)=>{o=T=>{o=null,n.push(T);try{w(t(n))}catch(C){x(C)}return i}}):t(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=M()})}},u=w=>o!=null?o(w):(n.push(w),i),f=w=>(n=new ht,o!=null?o({error:w}):(n.push({error:w}),i)),h=w=>{if(s)return i;if(e?.objectMode!==!0&&w?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return u({done:!1,value:w})},m=w=>s?i:(s=!0,w!=null?f(w):u({done:!0})),g=()=>(n=new ht,m(),{done:!0}),v=w=>(m(w),{done:!0});if(i={[Symbol.asyncIterator](){return this},next:c,return:g,throw:v,push:h,end:m,get readableLength(){return n.size},onEmpty:async w=>{let x=w?.signal;if(x?.throwIfAborted(),n.isEmpty())return;let T,C;x!=null&&(T=new Promise((R,L)=>{C=()=>{L(new To)},x.addEventListener("abort",C)}));try{await Promise.race([a.promise,T])}finally{C!=null&&x!=null&&x?.removeEventListener("abort",C)}}},r==null)return i;let b=i;return i={[Symbol.asyncIterator](){return this},next(){return b.next()},throw(w){return b.throw(w),r!=null&&(r(w),r=void 0),{done:!0}},return(){return b.return(),r!=null&&(r(),r=void 0),{done:!0}},push:h,end(w){return b.end(w),r!=null&&(r(w),r=void 0),i},get readableLength(){return b.readableLength},onEmpty:w=>b.onEmpty(w)},i}var So=class t extends Error{name="TimeoutError";constructor(e,r){super(e,r),Error.captureStackTrace?.(this,t)}},ua=t=>t.reason??new DOMException("This operation was aborted.","AbortError");function Xt(t,e){let{milliseconds:r,fallback:n,message:i,customTimers:o={setTimeout,clearTimeout},signal:s}=e,a,c,f=new Promise((h,m)=>{if(typeof r!="number"||Math.sign(r)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${r}\``);if(s?.aborted){m(ua(s)),t.then(h,m);return}if(s&&(c=()=>{m(ua(s))},s.addEventListener("abort",c,{once:!0})),t.then(h,m),r===Number.POSITIVE_INFINITY)return;let g=new So;a=o.setTimeout.call(void 0,()=>{if(n){try{h(n())}catch(v){m(v)}return}typeof t.cancel=="function"&&t.cancel(),i===!1?h():i instanceof Error?m(i):(g.message=i??`Promise timed out after ${r} milliseconds`,m(g))},r)}).finally(()=>{f.clear(),c&&s&&s.removeEventListener("abort",c)});return f.clear=()=>{o.clearTimeout.call(void 0,a),a=void 0},f}var lf=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 ff(t,e,r){let n,i=new Promise((o,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:u,removeListener:f}=lf(t),h=async(...g)=>{let v=r.multiArgs?g:g[0];if(r.filter)try{if(!await r.filter(v))return}catch(b){n(),s(b);return}c.push(v),r.count===c.length&&(n(),o(c))},m=(...g)=>{n(),s(r.rejectionMultiArgs?g:g[0])};n=()=>{for(let g of a)f(g,h);for(let g of r.rejectionEvents)a.includes(g)||f(g,m)};for(let g of a)u(g,h);for(let g of r.rejectionEvents)a.includes(g)||u(g,m);r.signal&&r.signal.addEventListener("abort",()=>{m(r.signal.reason)},{once:!0}),r.resolveImmediately&&o(c)});if(i.cancel=n,typeof r.timeout=="number"){let o=Xt(i,{milliseconds:r.timeout});return o.cancel=()=>{n(),o.clear()},o}return i}function Wr(t,e,r){typeof r=="function"&&(r={filter:r}),r={...r,count:1,resolveImmediately:!1};let n=ff(t,e,r),i=n.then(o=>o[0]);return i.cancel=n.cancel,i}function Bo(t,e){let r,n=function(){let i=function(){r=void 0,t()};clearTimeout(r),r=setTimeout(i,e)};return n.start=()=>{},n.stop=()=>{clearTimeout(r)},n}var Yr=class extends Error{static name="QueueFullError";constructor(e="The queue was full"){super(e),this.name="QueueFullError"}};var Jr=class{deferred;signal;onProgress;constructor(e){this.signal=e?.signal,this.onProgress=e?.onProgress,this.deferred=M(),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 hf(){return`${parseInt(String(Math.random()*1e9),10).toString()}${Date.now()}`}var la=new WeakMap,Kr=class{id;fn;options;recipients;status;timeline;controller;dispatchingProgress;constructor(e,r){this.id=hf(),this.status="queued",this.fn=e,this.options=r,this.recipients=[],this.timeline={created:Date.now()},this.controller=new AbortController,this.controller.signal,this.dispatchingProgress=!1,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 Jr(e);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 lt(this.fn({...this.options??{},signal:this.controller.signal,onProgress:r=>{if(this.recipients.length!==0&&!this.dispatchingProgress){if(typeof r=="object"&&r!==null){let n=la.get(r);if(n==null&&(n=new WeakSet,la.set(r,n)),n.has(this))return;n.add(this)}this.dispatchingProgress=!0;try{this.recipients.forEach(n=>{n.onProgress?.(r)})}finally{this.dispatchingProgress=!1}}}}),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.deferred.reject(e.signal?.reason??new le),e.cleanup(),e.signal?.removeEventListener("abort",this.onAbort)}),this.recipients.splice(0,this.recipients.length)}};var pt=class extends jr{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=Bo(this.emitEmpty.bind(this),1),this.emitIdle=Bo(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 Yr;let n=new Kr(e,r);this.enqueue(n),this.safeDispatchEvent("add");let i=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 s=0;s<this.queue.length;s++)if(this.queue[s]===n){this.queue.splice(s,1);break}}throw this.safeDispatchEvent("failure",{detail:{job:n,error:o}}),o});return this.tryToStartAnother(),i}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 Wr(this,"empty",e)}async onSizeLessThan(e,r){this.size<e||await Wr(this,"next",{...r,filter:()=>this.size<e})}async onIdle(e){this.pending===0&&this.size===0||await Wr(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=dt({objectMode:!0}),n=c=>{c!=null?this.abort():this.clear(),r.end(c)},i=c=>{c.detail!=null&&r.push(c.detail)},o=c=>{n(c.detail.error)},s=()=>{n()},a=()=>{n(new le("Queue aborted"))};this.addEventListener("completed",i),this.addEventListener("failure",o),this.addEventListener("idle",s),e?.signal?.addEventListener("abort",a);try{yield*r}finally{this.removeEventListener("completed",i),this.removeEventListener("failure",o),this.removeEventListener("idle",s),e?.signal?.removeEventListener("abort",a),n()}}};function fa(t){let e=new globalThis.AbortController;function r(){let o=t.filter(s=>s?.aborted===!0).map(s=>s?.reason).pop();e.abort(o);for(let s of t)s?.removeEventListener!=null&&s.removeEventListener("abort",r)}for(let o of t){if(o?.aborted===!0){r();break}o?.addEventListener!=null&&o.addEventListener("abort",r)}function n(){for(let o of t)o?.removeEventListener!=null&&o.removeEventListener("abort",r)}let i=e.signal;return i.clear=n,i}var Co=class{readNext;haveNext;ended;nextResult;error;constructor(){this.ended=!1,this.readNext=M(),this.haveNext=M()}[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=M(),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=M(),await lt(this.readNext.promise,r?.signal,r)}};function ha(){return new Co}function da(t){return t[Symbol.asyncIterator]!=null}async function df(t,e,r){try{await Promise.all(t.map(async n=>{for(;;){let{value:i,done:o}=await n.next();if(o===!0)break;await e.push(i,{signal:r}),r.throwIfAborted()}})),await e.end(void 0,{signal:r})}catch(n){await e.end(n,{signal:r}).catch(()=>{})}}async function*pf(t){let e=new AbortController,r=ha(),n=t.map(i=>da(i)?i[Symbol.asyncIterator]():i[Symbol.iterator]());df(n,r,e.signal).catch(()=>{});try{yield*r}finally{e.abort();for(let i of n)try{Promise.resolve(i.return?.()).catch(()=>{})}catch{}}}function*mf(t){for(let e of t)yield*e}function yf(...t){let e=[];for(let r of t)da(r)||e.push(r);return e.length===t.length?mf(e):pf(t)}var pa=yf;function ma(t,...e){if(t==null)throw new Error("Empty pipeline");if(Do(t)){let n=t;t=()=>n.source}else if(ga(t)||ya(t)){let n=t;t=()=>n}let r=[t,...e];if(r.length>1&&Do(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++)Do(r[n])&&(r[n]=wf(r[n]));return gf(...r)}var gf=(...t)=>{let e;for(;t.length>0;)e=t.shift()(e);return e},ya=t=>t?.[Symbol.asyncIterator]!=null,ga=t=>t?.[Symbol.iterator]!=null,Do=t=>t==null?!1:t.sink!=null&&t.source!=null,wf=t=>e=>{let r=t.sink(e);if(r?.then!=null){let n=dt({objectMode:!0});r.then(()=>{n.end()},s=>{n.end(s)});let i,o=t.source;if(ya(o))i=async function*(){yield*o,n.end()};else if(ga(o))i=function*(){yield*o,n.end()};else throw new Error("Unknown duplex source type - must be Iterable or AsyncIterable");return pa(n,i())}return t.source};function xf(t){return t[Symbol.asyncIterator]!=null}function bf(t,e){let r=0;if(xf(t))return(async function*(){for await(let c of t)await e(c,r++)&&(yield c)})();let n=Ur(t),{value:i,done:o}=n.next();if(o===!0)return(function*(){})();let s=e(i,r++);if(typeof s.then=="function")return(async function*(){await s&&(yield i);for(let c of n)await e(c,r++)&&(yield c)})();let a=e;return(function*(){s===!0&&(yield i);for(let c of n)a(c,r++)&&(yield c)})()}var wa=bf;function Ef(t){return t[Symbol.asyncIterator]!=null}function vf(t){if(Ef(t))return(async()=>{let n=new Uint8Array(0);for await(let i of t)n=Gt([n,i],n.length+i.length);return n})();let e=[],r=0;for(let n of t)e.push(n),r+=n.byteLength;return Gt(e,r)}var _=vf;function Qr({enumerable:t=!0,configurable:e=!1}={}){return{enumerable:t,configurable:e,writable:!1}}function*kf(t,e){if(e!=null&&typeof e=="object")if(Array.isArray(e))for(let[r,n]of e.entries()){let i=[...t,r],o=E.asCID(n);o!=null?yield[i.join("/"),o]:typeof n=="object"&&(yield*No(n,i))}else{let r=E.asCID(e);r!=null?yield[t.join("/"),r]:yield*No(e,t)}}function*No(t,e){if(t==null||t instanceof Uint8Array)return;let r=E.asCID(t);r!=null&&(yield[e.join("/"),r]);for(let[n,i]of Object.entries(t)){let o=[...e,n];yield*kf(o,i)}}function*_f(t,e){if(Array.isArray(e))for(let[r,n]of e.entries()){let i=[...t,r];yield i.join("/"),typeof n=="object"&&E.asCID(n)==null&&(yield*Lo(n,i))}else yield*Lo(e,t)}function*Lo(t,e){if(!(t==null||typeof t!="object"))for(let[r,n]of Object.entries(t)){let i=[...e,r];yield i.join("/"),n!=null&&!(n instanceof Uint8Array)&&typeof n=="object"&&E.asCID(n)==null&&(yield*_f(i,n))}}function If(t,e){let r=t;for(let[n,i]of e.entries()){if(r=r[i],r==null)throw new Error(`Object has no property at ${e.slice(0,n+1).map(s=>`[${JSON.stringify(s)}]`).join("")}`);let o=E.asCID(r);if(o!=null)return{value:o,remaining:e.slice(n+1).join("/")}}return{value:r}}var Uo=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:Qr(),bytes:Qr(),value:Qr(),asBlock:Qr()})}links(){return No(this.value,[])}tree(){return Lo(this.value,[])}get(e="/"){return If(this.value,e.split("/").filter(Boolean))}};function fe({bytes:t,cid:e,value:r,codec:n}){let i=r!==void 0?r:n?.decode(t);if(i===void 0)throw new Error('Missing required argument, must either provide "value" or "codec"');return new Uo({cid:e,bytes:t,value:i})}function mt(t){return e=>new Po(e,t)}function yt(t){return e=>new Ro(e,t)}function xa(t){return e=>new Fo(e,t)}var Zt=class{components;constructor(e,r={}){this.components=e}async*walk(e,r){let n=this.getQueue(),i=wa(n.toGenerator(r),c=>c!=null),o=!1,s=r?.depth??1/0,a=async c=>{let u=c.cid,f=await _(this.components.blockstore.get(u,c)),h=fe({cid:u,bytes:f,codec:await this.components.getCodec(u.code)});if(c.depth<s)for(let[,m]of h.links())r?.includeChild?.(m,h)!==!1&&n.add(a,{...c,cid:m,depth:c.depth+1,path:[...c.path,m]}).catch(g=>{o||i.throw(g)});return{block:h,depth:c.depth,path:c.path}};n.add(a,{...r,cid:e,depth:0,path:[e]}).catch(c=>{o||i.throw(c)});try{yield*i}finally{o=!0,n.abort()}}},Po=class extends Zt{getQueue(){return new pt({concurrency:1,sort:(e,r)=>e.options.depth===r.options.depth?0:e.options.depth<r.options.depth?1:-1})}},Ro=class extends Zt{getQueue(){return new pt({concurrency:1,sort:(e,r)=>e.options.depth===r.options.depth?0:e.options.depth<r.options.depth?-1:1})}},Fo=class extends Zt{getQueue(){return new pt({concurrency:1})}};var er=class{walker;constructor(e){this.walker=e?.walker}async*export(e,r,n,i){let o,s={blockstore:r,getCodec:n};this.walker!=null?o=this.walker(s):o=yt()(s);for await(let a of o.walk(e,i))yield a.block}};var Xr=class{components;log;constructor(e){this.components=e,this.log=e.logger.forComponent("helia:car")}async import(e,r){await Fs(this.components.blockstore.putMany(Pr(e.blocks(),({cid:n,bytes:i})=>({cid:n,bytes:i})),r))}async*export(e,r){let n=Array.isArray(e)?e:[e],{writer:i,out:o}=qt.create(n),s=o[Symbol.asyncIterator](),a=new AbortController;for(this._export(n,i,r).catch(c=>{this.log.error("error during streaming export - %e",c),a.abort(c)});;){let{done:c,value:u}=await lt(s.next(),a.signal);if(a.signal.aborted)throw a.signal.reason;if(u!=null&&(yield u),c===!0)break}}async _export(e,r,n){let i=n?.traversal;for(let o of e){if(o.multihash.code===0)continue;let s=n?.exporter??(o.code===112?new tr:new er),a=o,c=!1;if(i!=null){for await(let{cid:u,bytes:f}of i.traverse(a,this.components.blockstore,this.components.getCodec,n))if(this.log.trace("next CID on path to %c is %c",o,u),a=u,o.equals(u)&&(c=!0),c||n?.includeTraversalBlocks===!0){if(n?.blockFilter?.has(u.multihash.bytes)===!0)continue;n?.blockFilter?.add(u.multihash.bytes),await r.put({cid:u,bytes:f})}}for await(let{cid:u,bytes:f}of s.export(a,this.components.blockstore,this.components.getCodec,n))n?.blockFilter?.has(u.multihash.bytes)!==!0&&u.multihash.code!==0&&(c&&u.equals(a)||(n?.blockFilter?.add(u.multihash.bytes),await r.put({cid:u,bytes:f})))}await r.close()}};var Mo=class{async*export(e,r,n,i){let o=await _(r.get(e,i));yield fe({cid:e,bytes:o,codec:await n(e.code)})}};var rr=class t extends Error{static name="InvalidTypeError";static code="ERR_INVALID_TYPE";name=t.name;code=t.code;constructor(e="Invalid type"){super(e)}};var P;(function(t){let e;(function(a){a.RAW="RAW",a.DIRECTORY="DIRECTORY",a.FILE="FILE",a.METADATA="METADATA",a.SYMLINK="SYMLINK",a.HAMT_SHARD="HAMT_SHARD"})(e=t.Type||(t.Type={}));let r;(function(a){a[a.RAW=0]="RAW",a[a.DIRECTORY=1]="DIRECTORY",a[a.FILE=2]="FILE",a[a.METADATA=3]="METADATA",a[a.SYMLINK=4]="SYMLINK",a[a.HAMT_SHARD=5]="HAMT_SHARD"})(r||(r={})),(function(a){a.codec=()=>Io(r)})(e=t.Type||(t.Type={}));let n;t.codec=()=>(n==null&&(n=Ne((a,c,u={})=>{if(u.lengthDelimited!==!1&&c.fork(),a.type!=null&&(c.uint32(8),t.Type.codec().encode(a.type,c)),a.data!=null&&(c.uint32(18),c.bytes(a.data)),a.fileSize!=null&&(c.uint32(24),c.uint64(a.fileSize)),a.blockSizes!=null&&a.blockSizes.length>0)for(let f of a.blockSizes)c.uint32(32),c.uint64(f);a.hashType!=null&&(c.uint32(40),c.uint64(a.hashType)),a.fanOut!=null&&(c.uint32(48),c.uint64(a.fanOut)),a.mode!=null&&(c.uint32(56),c.uint32(a.mode)),a.mtime!=null&&(c.uint32(66),nr.codec().encode(a.mtime,c)),u.lengthDelimited!==!1&&c.ldelim()},(a,c,u={})=>{let f={blockSizes:[]},h=c==null?a.len:a.pos+c;for(;a.pos<h;){let m=a.uint32();switch(m>>>3){case 1:{f.type=t.Type.codec().decode(a);break}case 2:{f.data=a.bytes();break}case 3:{f.fileSize=a.uint64();break}case 4:{if(u.limits?.blockSizes!=null&&f.blockSizes.length===u.limits.blockSizes)throw new me('Decode error - repeated field "blockSizes" had too many elements');f.blockSizes.push(a.uint64());break}case 5:{f.hashType=a.uint64();break}case 6:{f.fanOut=a.uint64();break}case 7:{f.mode=a.uint32();break}case 8:{f.mtime=nr.codec().decode(a,a.uint32(),{limits:u.limits?.mtime});break}default:{a.skipType(m&7);break}}}return f},function*(a,c,u,f={}){let h={blockSizes:0},m=c==null?a.len:a.pos+c;for(u!=="."&&(yield{field:u.endsWith(".")?u.substring(0,u.length-1):u,type:"start",message:"UnixFS"});a.pos<m;){let g=a.uint32();switch(g>>>3){case 1:{yield{field:`${u}type`,value:t.Type.codec().decode(a)};break}case 2:{yield{field:`${u}data`,value:a.bytes()};break}case 3:{yield{field:`${u}fileSize`,value:a.uint64()};break}case 4:{if(f.limits?.blockSizes!=null&&h.blockSizes===f.limits.blockSizes)throw new me('Streaming decode error - repeated field "blockSizes" had too many elements');yield{field:`${u}blockSizes[]`,index:h.blockSizes,value:a.uint64()},h.blockSizes++;break}case 5:{yield{field:`${u}hashType`,value:a.uint64()};break}case 6:{yield{field:`${u}fanOut`,value:a.uint64()};break}case 7:{yield{field:`${u}mode`,value:a.uint32()};break}case 8:{yield*nr.codec().stream(a,a.uint32(),`${u}mtime.`,{limits:f.limits?.mtime});break}default:{a.skipType(g&7);break}}}u!=="."&&(yield{field:u.endsWith(".")?u.substring(0,u.length-1):u,type:"end",message:"UnixFS"})})),n);function i(a){return Ce(a,t.codec())}t.encode=i;function o(a,c){return Be(a,t.codec(),c)}t.decode=o;function s(a,c){return De(a,t.codec(),c)}t.stream=s})(P||(P={}));var nr;(function(t){let e;t.codec=()=>(e==null&&(e=Ne((o,s,a={})=>{a.lengthDelimited!==!1&&s.fork(),o.seconds!=null&&(s.uint32(8),s.int64(o.seconds)),o.fractionalNanoseconds!=null&&(s.uint32(21),s.fixed32(o.fractionalNanoseconds)),a.lengthDelimited!==!1&&s.ldelim()},(o,s,a={})=>{let c={},u=s==null?o.len:o.pos+s;for(;o.pos<u;){let f=o.uint32();switch(f>>>3){case 1:{c.seconds=o.int64();break}case 2:{c.fractionalNanoseconds=o.fixed32();break}default:{o.skipType(f&7);break}}}return c},function*(o,s,a,c={}){let u=s==null?o.len:o.pos+s;for(a!=="."&&(yield{field:a.endsWith(".")?a.substring(0,a.length-1):a,type:"start",message:"UnixTime"});o.pos<u;){let f=o.uint32();switch(f>>>3){case 1:{yield{field:`${a}seconds`,value:o.int64()};break}case 2:{yield{field:`${a}fractionalNanoseconds`,value:o.fixed32()};break}default:{o.skipType(f&7);break}}}a!=="."&&(yield{field:a.endsWith(".")?a.substring(0,a.length-1):a,type:"end",message:"UnixTime"})})),e);function r(o){return Ce(o,t.codec())}t.encode=r;function n(o,s){return Be(o,t.codec(),s)}t.decode=n;function i(o,s){return De(o,t.codec(),s)}t.stream=i})(nr||(nr={}));var Ea;(function(t){let e;t.codec=()=>(e==null&&(e=Ne((o,s,a={})=>{a.lengthDelimited!==!1&&s.fork(),o.mimeType!=null&&(s.uint32(10),s.string(o.mimeType)),a.lengthDelimited!==!1&&s.ldelim()},(o,s,a={})=>{let c={},u=s==null?o.len:o.pos+s;for(;o.pos<u;){let f=o.uint32();f>>>3===1?c.mimeType=o.string():o.skipType(f&7)}return c},function*(o,s,a,c={}){let u=s==null?o.len:o.pos+s;for(a!=="."&&(yield{field:a.endsWith(".")?a.substring(0,a.length-1):a,type:"start",message:"Metadata"});o.pos<u;){let f=o.uint32();f>>>3===1?yield{field:`${a}mimeType`,value:o.string()}:o.skipType(f&7)}a!=="."&&(yield{field:a.endsWith(".")?a.substring(0,a.length-1):a,type:"end",message:"Metadata"})})),e);function r(o){return Ce(o,t.codec())}t.encode=r;function n(o,s){return Be(o,t.codec(),s)}t.decode=n;function i(o,s){return De(o,t.codec(),s)}t.stream=i})(Ea||(Ea={}));var Le;(function(t){let e;t.codec=()=>(e==null&&(e=Ne((o,s,a={})=>{a.lengthDelimited!==!1&&s.fork(),o.hash!=null&&(s.uint32(10),s.bytes(o.hash)),o.name!=null&&(s.uint32(18),s.string(o.name)),o.tSize!=null&&(s.uint32(24),s.uint64(o.tSize)),a.lengthDelimited!==!1&&s.ldelim()},(o,s,a={})=>{let c={},u=s==null?o.len:o.pos+s;for(;o.pos<u;){let f=o.uint32();switch(f>>>3){case 1:{c.hash=o.bytes();break}case 2:{c.name=o.string();break}case 3:{c.tSize=o.uint64();break}default:{o.skipType(f&7);break}}}return c},function*(o,s,a,c={}){let u=s==null?o.len:o.pos+s;for(a!=="."&&(yield{field:a.endsWith(".")?a.substring(0,a.length-1):a,type:"start",message:"Link"});o.pos<u;){let f=o.uint32();switch(f>>>3){case 1:{yield{field:`${a}hash`,value:o.bytes()};break}case 2:{yield{field:`${a}name`,value:o.string()};break}case 3:{yield{field:`${a}tSize`,value:o.uint64()};break}default:{o.skipType(f&7);break}}}a!=="."&&(yield{field:a.endsWith(".")?a.substring(0,a.length-1):a,type:"end",message:"Link"})})),e);function r(o){return Ce(o,t.codec())}t.encode=r;function n(o,s){return Be(o,t.codec(),s)}t.decode=n;function i(o,s){return De(o,t.codec(),s)}t.stream=i})(Le||(Le={}));var gt;(function(t){let e;t.codec=()=>(e==null&&(e=Ne((o,s,a={})=>{if(a.lengthDelimited!==!1&&s.fork(),o.data!=null&&(s.uint32(10),P.codec().encode(o.data,s)),o.links!=null&&o.links.length>0)for(let c of o.links)s.uint32(18),Le.codec().encode(c,s);a.lengthDelimited!==!1&&s.ldelim()},(o,s,a={})=>{let c={links:[]},u=s==null?o.len:o.pos+s;for(;o.pos<u;){let f=o.uint32();switch(f>>>3){case 1:{c.data=P.codec().decode(o,o.uint32(),{limits:a.limits?.data});break}case 2:{if(a.limits?.links!=null&&c.links.length===a.limits.links)throw new me('Decode error - repeated field "links" had too many elements');c.links.push(Le.codec().decode(o,o.uint32(),{limits:a.limits?.links$}));break}default:{o.skipType(f&7);break}}}return c},function*(o,s,a,c={}){let u={links:0},f=s==null?o.len:o.pos+s;for(a!=="."&&(yield{field:a.endsWith(".")?a.substring(0,a.length-1):a,type:"start",message:"Node"});o.pos<f;){let h=o.uint32();switch(h>>>3){case 1:{yield*P.codec().stream(o,o.uint32(),`${a}data.`,{limits:c.limits?.data});break}case 2:{if(c.limits?.links!=null&&u.links===c.limits.links)throw new me('Streaming decode error - repeated field "links" had too many elements');for(let m of Le.codec().stream(o,o.uint32(),`${a}links[].`,{limits:c.limits?.links$}))yield{...m,index:u.links};u.links++;break}default:{o.skipType(h&7);break}}}a!=="."&&(yield{field:a.endsWith(".")?a.substring(0,a.length-1):a,type:"end",message:"Node"})})),e);function r(o){return Ce(o,t.codec())}t.encode=r;function n(o,s){return Be(o,t.codec(),s)}t.decode=n;function i(o,s){return De(o,t.codec(),s)}t.stream=i})(gt||(gt={}));var va;(function(t){let e;t.codec=()=>(e==null&&(e=Ne((o,s,a={})=>{if(a.lengthDelimited!==!1&&s.fork(),o.links!=null&&o.links.length>0)for(let c of o.links)s.uint32(18),Le.codec().encode(c,s);o.data!=null&&(s.uint32(10),P.codec().encode(o.data,s)),a.lengthDelimited!==!1&&s.ldelim()},(o,s,a={})=>{let c={links:[]},u=s==null?o.len:o.pos+s;for(;o.pos<u;){let f=o.uint32();switch(f>>>3){case 2:{if(a.limits?.links!=null&&c.links.length===a.limits.links)throw new me('Decode error - repeated field "links" had too many elements');c.links.push(Le.codec().decode(o,o.uint32(),{limits:a.limits?.links$}));break}case 1:{c.data=P.codec().decode(o,o.uint32(),{limits:a.limits?.data});break}default:{o.skipType(f&7);break}}}return c},function*(o,s,a,c={}){let u={links:0},f=s==null?o.len:o.pos+s;for(a!=="."&&(yield{field:a.endsWith(".")?a.substring(0,a.length-1):a,type:"start",message:"LegacyNode"});o.pos<f;){let h=o.uint32();switch(h>>>3){case 2:{if(c.limits?.links!=null&&u.links===c.limits.links)throw new me('Streaming decode error - repeated field "links" had too many elements');for(let m of Le.codec().stream(o,o.uint32(),`${a}links[].`,{limits:c.limits?.links$}))yield{...m,index:u.links};u.links++;break}case 1:{yield*P.codec().stream(o,o.uint32(),`${a}data.`,{limits:c.limits?.data});break}default:{o.skipType(h&7);break}}}a!=="."&&(yield{field:a.endsWith(".")?a.substring(0,a.length-1):a,type:"end",message:"LegacyNode"})})),e);function r(o){return Ce(o,t.codec())}t.encode=r;function n(o,s){return Be(o,t.codec(),s)}t.decode=n;function i(o,s){return De(o,t.codec(),s)}t.stream=i})(va||(va={}));var ka={RAW:"raw",DIRECTORY:"directory",FILE:"file",METADATA:"metadata",SYMLINK:"symlink",HAMT_SHARD:"hamt-sharded-directory"},Tf=["directory","hamt-sharded-directory"],_a=parseInt("0644",8),Ia=parseInt("0755",8),he=class t{static unmarshal(e){let r=P.decode(e),n=new t({type:ka[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:i,hashType:o,fanout:s,mtime:a,mode:c}=e;if(r!=null&&!Object.values(ka).includes(r))throw new rr("Type: "+r+" is not valid");this.type=r??"file",this.hashType=o,this.fanout=s,this.blockSizes=i??[],this._originalMode=0,this.mode=c,this.mtime=a,n!=null&&(this.data=Rr(n))}set mode(e){e==null?this._mode=this.isDirectory()?Ia:_a:this._mode=e&4095}get mode(){return this._mode}isDirectory(){return Tf.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=P.Type.RAW;break;case"directory":e=P.Type.DIRECTORY;break;case"file":e=P.Type.FILE;break;case"metadata":e=P.Type.METADATA;break;case"symlink":e=P.Type.SYMLINK;break;case"hamt-sharded-directory":e=P.Type.HAMT_SHARD;break;default:throw new rr(`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===_a&&!this.isDirectory()&&(n=void 0),n===Ia&&this.isDirectory()&&(n=void 0));let i;return this.mtime!=null&&(i={seconds:this.mtime.secs,fractionalNanoseconds:this.mtime.nsecs}),P.encode({type:e,data:r,fileSize:this.type==="file"||this.type==="raw"?this.fileSize():void 0,blockSizes:this.blockSizes,hashType:this.hashType,fanOut:this.fanout,mode:n,mtime:i})}};var or=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"},Zr=class extends Error{static name="NotDescendantError";name="NotDescendantError"},wt=class extends Error{static name="InvalidTraversalError";name="InvalidTraversalError"};function Bf(t){return t.cid.code===85}function Cf(t){return t.cid.code===112}function Df(t){if(Bf(t))return!0;if(Cf(t)&&t.value.Data!=null){let e=he.unmarshal(t.value.Data);return e.type==="file"||e.type==="raw"}else throw new or("Encountered non raw/dag-pb CID in UnixFS DAG")}var tr=class{options;constructor(e){this.options=e}async*export(e,r,n,i){if(e.code!==112&&e.code!==85)throw new or("Target CID was not UnixFS - use the SubGraphExporter to export arbitrary graphs");let o=mt()({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 je("Offset cannot be negative");if(a<0)throw new je("Length cannot be negative");let u,f=new AbortController,h=fa([f.signal,i?.signal]);f.signal;function m(g,v){if(u==null&&(u=Df(v)),!u){let L=v.value.Links.find(V=>V.Hash.equals(g)),z=he.unmarshal(v.value.Data??new Uint8Array);return z.type==="directory"?!c:z.type==="hamt-sharded-directory"&&c?L?.Name?.length===2:!0}let b=v.value.Links.findIndex(L=>L.Hash.equals(g)),w=he.unmarshal(v.value.Data??new Uint8Array),x=s,T=x+a,C=Number([...w.blockSizes].slice(0,b).reduce((L,z)=>L+z,0n)),R=C+Number(w.blockSizes[b]);return x>=C&&x<R||T>=C&&T<R||x<=C&&T>=R}try{for await(let g of o.walk(e,{...i,includeChild:m,signal:h}))yield g.block}finally{f.abort(),h.clear()}}};function Aa(t){return t!=null&&t?.asCID===t}var Oo=class{haystack;needle;options;walker;constructor(...e){if(Aa(e[0]))Aa(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 je("needle must be specified");this.walker=this.options?.walker}async*traverse(e,r,n,i){let o=this.haystack??e,s,a={blockstore:r,getCodec:n};this.walker!=null?s=this.walker(a):this.options?.strategy==="breadth-first"?s=yt()(a):s=mt()(a);for await(let c of s.walk(o,i))if(c.block.cid.equals(this.needle)){for(let u of c.path){let f=await _(r.get(u,i));yield fe({cid:u,bytes:f,codec:await n(u.code)})}return}throw new wt(`${this.needle} was not a child of ${o}`)}};var zo=class{path;constructor(e){this.path=e}async*traverse(e,r,n,i){if(!this.path.some(s=>s.equals(e)))throw new wt(`CIDPath traversal must include ${e}`);let o;for(let s of this.path){if(o!=null){let u=!1;for(let[,f]of o.links())if(f.equals(s)){u=!0;break}if(!u)throw new Zr(`${s} is not a child of ${o.cid}`)}let a=await _(r.get(s,i)),c=fe({cid:s,bytes:a,codec:await n(s.code)});o=c,yield c}}};var Nf=new TextDecoder;function $o(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 i=t[e++];if(r+=n<28?(i&127)<<n:(i&127)*2**n,i<128)break}return[r,e]}function en(t,e){let r;[r,e]=$o(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 Ta(t,e){let r;return[r,e]=$o(t,e),[r&7,r>>3,e]}function Lf(t){let e={},r=t.length,n=0;for(;n<r;){let i,o;if([i,o,n]=Ta(t,n),o===1){if(e.Hash)throw new Error("protobuf: (PBLink) duplicate Hash section");if(i!==2)throw new Error(`protobuf: (PBLink) wrong wireType (${i}) for Hash`);if(e.Name!==void 0)throw new Error("protobuf: (PBLink) invalid order, found Name before Hash");if(e.Tsize!==void 0)throw new Error("protobuf: (PBLink) invalid order, found Tsize before Hash");[e.Hash,n]=en(t,n)}else if(o===2){if(e.Name!==void 0)throw new Error("protobuf: (PBLink) duplicate Name section");if(i!==2)throw new Error(`protobuf: (PBLink) wrong wireType (${i}) for Name`);if(e.Tsize!==void 0)throw new Error("protobuf: (PBLink) invalid order, found Tsize before Name");let s;[s,n]=en(t,n),e.Name=Nf.decode(s)}else if(o===3){if(e.Tsize!==void 0)throw new Error("protobuf: (PBLink) duplicate Tsize section");if(i!==0)throw new Error(`protobuf: (PBLink) wrong wireType (${i}) for Tsize`);[e.Tsize,n]=$o(t,n)}else throw new Error(`protobuf: (PBLink) invalid fieldNumber, expected 1, 2 or 3, got ${o}`)}if(n>r)throw new Error("protobuf: (PBLink) unexpected end of data");return e}function Sa(t){let e=t.length,r=0,n,i=!1,o;for(;r<e;){let a,c;if([a,c,r]=Ta(t,r),a!==2)throw new Error(`protobuf: (PBNode) invalid wireType, expected 2, got ${a}`);if(c===1){if(o)throw new Error("protobuf: (PBNode) duplicate Data section");[o,r]=en(t,r),n&&(i=!0)}else if(c===2){if(i)throw new Error("protobuf: (PBNode) duplicate Links section");n||(n=[]);let u;[u,r]=en(t,r),n.push(Lf(u))}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 o&&(s.Data=o),s.Links=n||[],s}var Da=new TextEncoder,Ba=2**32,Uf=2**31;function Pf(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=ir(e,r,t.Tsize)-1,e[r]=24}if(typeof t.Name=="string"){let n=Da.encode(t.Name);r-=n.length,e.set(n,r),r=ir(e,r,n.length)-1,e[r]=18}return t.Hash&&(r-=t.Hash.length,e.set(t.Hash,r),r=ir(e,r,t.Hash.length)-1,e[r]=10),e.length-r}function Ca(t,e,r){return t-=e.Data.length,r.set(e.Data,t),t=ir(r,t,e.Data.length)-1,r[t]=10,t}function Na(t,e){let r=Ff(t),n=new Uint8Array(r),i=r,o=e?.fieldOrder==="data-first"?e.fieldOrder:"links-first";if(t.Data&&o==="links-first"&&(i=Ca(i,t,n)),t.Links)for(let s=t.Links.length-1;s>=0;s--){let a=Pf(t.Links[s],n.subarray(0,i));i-=a,i=ir(n,i,a)-1,n[i]=18}return t.Data&&o==="data-first"&&(i=Ca(i,t,n)),n}function Rf(t){let e=0;if(t.Hash){let r=t.Hash.length;e+=1+r+xt(r)}if(typeof t.Name=="string"){let r=Da.encode(t.Name).length;e+=1+r+xt(r)}return typeof t.Tsize=="number"&&(e+=1+xt(t.Tsize)),e}function Ff(t){let e=0;if(t.Data){let r=t.Data.length;e+=1+r+xt(r)}if(t.Links)for(let r of t.Links){let n=Rf(r);e+=1+n+xt(n)}return e}function ir(t,e,r){e-=xt(r);let n=e;for(;r>=Uf;)t[e++]=r&127|128,r/=128;for(;r>=128;)t[e++]=r&127|128,r>>>=7;return t[e]=r,n}function xt(t){return t%2===0&&t++,Math.floor((Mf(t)+6)/7)}function Mf(t){let e=0;return t>=Ba&&(t=Math.floor(t/Ba),e=32),t>=65536&&(t>>>=16,e+=16),t>=256&&(t>>>=8,e+=8),e+Of[t]}var Of=[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"],$f=["Hash","Name","Tsize"],La=new TextEncoder;function Hf(t,e){if(t===e)return 0;let r=t.Name?La.encode(t.Name):[],n=e.Name?La.encode(e.Name):[],i=r.length,o=n.length;for(let s=0,a=Math.min(i,o);s<a;++s)if(r[s]!==n[s]){i=r[s],o=n[s];break}return i<o?-1:o<i?1:0}function Ua(t,e){return!Object.keys(t).some(r=>!e.includes(r))}function Pa(t){if(!t||typeof t!="object"||Array.isArray(t)||t instanceof Uint8Array||t["/"]&&t["/"]===t.bytes)throw new TypeError("Invalid DAG-PB form");if(!Ua(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(!Ua(r,$f))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&&Hf(r,t.Links[e-1])===-1)throw new TypeError("Invalid DAG-PB form (links must be sorted by Name bytes)")}}function Ra(t){return t instanceof ArrayBuffer?new Uint8Array(t,0,t.byteLength):t}var bt=112;function Fa(t,e){Pa(t);let r={};return t.Links&&(r.Links=t.Links.map(n=>{let i={};return n.Hash&&(i.Hash=n.Hash.bytes),n.Name!==void 0&&(i.Name=n.Name),n.Tsize!==void 0&&(i.Tsize=n.Tsize),i})),t.Data&&(r.Data=t.Data),Na(r,e)}function tn(t){let e=Ra(t),r=Sa(e),n={};return r.Data&&(n.Data=r.Data),r.Links&&(n.Links=r.Links.map(i=>{let o={};try{o.Hash=E.decode(i.Hash)}catch{}if(!o.Hash)throw new Error("Invalid Hash field found in link, expected CID");return i.Name!==void 0&&(o.Name=i.Name),i.Tsize!==void 0&&(o.Tsize=i.Tsize),o})),n}var Et=class t extends Error{static name="BadPathError";static code="ERR_BAD_PATH";name=t.name;code=t.code;constructor(e="Bad path"){super(e)}},q=class t extends Error{static name="NotFoundError";static code="ERR_NOT_FOUND";name=t.name;code=t.code;constructor(e="Not found"){super(e)}},vt=class t extends Error{static name="NoResolverError";static code="ERR_NO_RESOLVER";name=t.name;code=t.code;constructor(e="No resolver"){super(e)}},S=class t extends Error{static name="NotUnixFSError";static code="ERR_NOT_UNIXFS";name=t.name;code=t.code;constructor(e="Not UnixFS"){super(e)}},nn=class t extends Error{static name="OverReadError";static code="ERR_OVER_READ";name=t.name;code=t.code;constructor(e="Over read"){super(e)}},on=class t extends Error{static name="UnderReadError";static code="ERR_UNDER_READ";name=t.name;code=t.code;constructor(e="Under read"){super(e)}},ye=class t extends Error{static name="InvalidParametersError";static code="ERR_INVALID_PARAMS";name=t.name;code=t.code;constructor(e="Invalid parameters"){super(e)}};var Ma=class extends Array{constructor(){super(),this.inRecursive=[]}prefix(e){let r=this.inRecursive[this.inRecursive.length-1];r&&(l.equals(r.type,l.array)&&(r.elements++,r.elements!==1&&e.push([44])),l.equals(r.type,l.map)&&(r.elements++,r.elements!==1&&(r.elements%2===1?e.push([44]):e.push([58]))))}[l.uint.major](e,r){this.prefix(e);let n=String(r.value),i=[];for(let o=0;o<n.length;o++)i[o]=n.charCodeAt(o);e.push(i)}[l.negint.major](e,r){this[l.uint.major](e,r)}[l.bytes.major](e,r){throw new Error(`${Fe} unsupported type: Uint8Array`)}[l.string.major](e,r){this.prefix(e);let n=Je(JSON.stringify(r.value));e.push(n.length>32?Re(n):n)}[l.array.major](e,r){this.prefix(e),this.inRecursive.push({type:l.array,elements:0}),e.push([91])}[l.map.major](e,r){this.prefix(e),this.inRecursive.push({type:l.map,elements:0}),e.push([123])}[l.tag.major](e,r){}[l.float.major](e,r){if(r.type.name==="break"){let s=this.inRecursive.pop();if(s){if(l.equals(s.type,l.array))e.push([93]);else if(l.equals(s.type,l.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),i=[],o=!1;for(let s=0;s<n.length;s++)i[s]=n.charCodeAt(s),!o&&(i[s]===46||i[s]===101||i[s]===69)&&(o=!0);o||(i.push(46),i.push(48)),e.push(i)}};var kt=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(`${y} 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(`${y} unexpected token at position ${this._pos}, expected to find '${String.fromCharCode(...e)}'`)}parseNumber(){let e=this._pos,r=!1,n=!1,i=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 d(l.uint,0,this._pos-e);if(i([48,49,50,51,52,53,54,55,56,57]),r&&this._pos===e+1)throw new Error(`${y} unexpected token at position ${this._pos}`);if(!this.done()&&this.ch()===46){if(n)throw new Error(`${y} unexpected token at position ${this._pos}`);n=!0,this._pos++,i([48,49,50,51,52,53,54,55,56,57])}!this.done()&&(this.ch()===101||this.ch()===69)&&(n=!0,this._pos++,!this.done()&&(this.ch()===43||this.ch()===45)&&this._pos++,i([48,49,50,51,52,53,54,55,56,57]));let o=String.fromCharCode.apply(null,this.data.subarray(e,this._pos)),s=parseFloat(o);return n?new d(l.float,s,this._pos-e):this.options.allowBigInt!==!0||Number.isSafeInteger(s)?new d(s>=0?l.uint:l.negint,s,this._pos-e):new d(s>=0?l.uint:l.negint,BigInt(o),this._pos-e)}parseString(){if(this.ch()!==34)throw new Error(`${y} unexpected character at position ${this._pos}; this shouldn't happen`);this._pos++;for(let o=this._pos,s=0;o<this.data.length&&s<65536;o++,s++){let a=this.data[o];if(a===92||a<32||a>=128)break;if(a===34){let c=String.fromCharCode.apply(null,this.data.subarray(this._pos,o));return this._pos=o+1,new d(l.string,c,s)}}let e=this._pos,r=[],n=()=>{if(this._pos+4>=this.data.length)throw new Error(`${y} unexpected end of unicode escape sequence at position ${this._pos}`);let o=0;for(let s=0;s<4;s++){let a=this.ch();if(a>=48&&a<=57)a-=48;else if(a>=97&&a<=102)a=a-97+10;else if(a>=65&&a<=70)a=a-65+10;else throw new Error(`${y} unexpected unicode escape character at position ${this._pos}`);o=o*16+a,this._pos++}return o},i=()=>{let o=this.ch(),s=null,a=o>239?4:o>223?3:o>191?2:1;if(this._pos+a>this.data.length)throw new Error(`${y} unexpected unicode sequence at position ${this._pos}`);let c,u,f,h;switch(a){case 1:o<128&&(s=o);break;case 2:c=this.data[this._pos+1],(c&192)===128&&(h=(o&31)<<6|c&63,h>127&&(s=h));break;case 3:c=this.data[this._pos+1],u=this.data[this._pos+2],(c&192)===128&&(u&192)===128&&(h=(o&15)<<12|(c&63)<<6|u&63,h>2047&&(h<55296||h>57343)&&(s=h));break;case 4:c=this.data[this._pos+1],u=this.data[this._pos+2],f=this.data[this._pos+3],(c&192)===128&&(u&192)===128&&(f&192)===128&&(h=(o&15)<<18|(c&63)<<12|(u&63)<<6|f&63,h>65535&&h<1114112&&(s=h))}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 o=this.ch(),s;switch(o){case 92:if(this._pos++,this.done())throw new Error(`${y} 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(`${y} unexpected string escape character at position ${this._pos}`)}break;case 34:return this._pos++,new d(l.string,ui(r),this._pos-e);default:if(o<32)throw new Error(`${y} invalid control character at position ${this._pos}`);o<128?(r.push(o),this._pos++):i()}}throw new Error(`${y} unexpected end of string at position ${this._pos}`)}parseValue(){switch(this.ch()){case 123:return this.modeStack.push("obj-start"),this._pos++,new d(l.map,1/0,1);case 91:return this.modeStack.push("array-start"),this._pos++,new d(l.array,1/0,1);case 34:return this.parseString();case 110:return this.expect([110,117,108,108]),new d(l.null,null,4);case 102:return this.expect([102,97,108,115,101]),new d(l.false,!1,5);case 116:return this.expect([116,114,117,101]),new d(l.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(`${y} 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 d(l.break,void 0,1);if(this.ch()!==44)throw new Error(`${y} 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 d(l.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 d(l.break,void 0,1);if(this.ch()!==44)throw new Error(`${y} 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 d(l.break,void 0,1);let e=this.parseString();if(this.skipWhitespace(),this.ch()!==58)throw new Error(`${y} 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(`${y} unexpected parse state at position ${this._pos}; this shouldn't happen`)}}};function Ho(t,e){return e=Object.assign({tokenizer:new kt(t,e)},e),Pt(t,e)}function jf(t){return t instanceof ArrayBuffer?new Uint8Array(t,0,t.byteLength):t}var Vo=class extends kt{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(l.equals(e.type,l.map)){let r=this._next();if(l.equals(r.type,l.string)&&r.value==="/"){let n=this._next();if(l.equals(n.type,l.string)){let i=this._next();if(!l.equals(i.type,l.break))throw new Error("Invalid encoded CID form");return this.tokenBuffer.push(n),new d(l.tag,42,0)}if(l.equals(n.type,l.map)){let i=this._next();if(l.equals(i.type,l.string)&&i.value==="bytes"){let o=this._next();if(l.equals(o.type,l.string)){for(let a=0;a<2;a++){let c=this._next();if(!l.equals(c.type,l.break))throw new Error("Invalid encoded Bytes form")}let s=ro.decode(`m${o.value}`);return new d(l.bytes,s,o.value.length)}this.tokenBuffer.push(o)}this.tokenBuffer.push(i)}this.tokenBuffer.push(n)}this.tokenBuffer.push(r)}return e}},Oa={allowIndefinite:!1,allowUndefined:!1,allowNaN:!1,allowInfinity:!1,allowBigInt:!0,strict:!0,useMaps:!1,rejectDuplicateMapKeys:!0,tags:{42:t=>E.parse(t())}};var sn=297;var an=t=>{let e=jf(t),r=Object.assign(Oa,{tokenizer:new Vo(e,Oa)});return Ho(e,r)};var g0=new TextDecoder;var w0=new TextEncoder;function _t(t){return t==null?!1:E.asCID(t)===t}function It(t,e){let r,n=0,i="";for(;n<e.length;){let o=e[n];if(n++,!Object.hasOwnProperty.call(t,o))throw new Et(`Object did not have key "${o}"`);if(i+=`/${o}`,r=t[o],t=r,_t(r))break}return{value:r,rest:e.slice(n),path:i.substring(1)}}async function*qo(t,e,r,n){let i=await _(r.get(t,n)),o=$e(i),s=It(o,e);yield{cid:_t(s.value)?s.value:t,name:s.path,rest:s.rest}}async function*za(t,e,r,n){let i=await _(r.get(t,n)),o=an(i),s=It(o,e);yield{cid:_t(s.value)?s.value:t,name:s.path,rest:s.rest}}function Ue(t,e){let r=t.lo+e.lo>>>0,n=t.hi+e.hi+(r<t.lo?1:0)>>>0;return{lo:r,hi:n}}function Gf(t,e){return t+e>>>0}function Z(t,e){let r=t.lo&65535,n=t.lo>>>16,i=e.lo&65535,o=e.lo>>>16,s=r*i,a=r*o,c=n*i,u=n*o,f=(s>>>16)+(a&65535)+(c&65535)>>>0,h=(f<<16|s&65535)>>>0,m=u+(a>>>16)+(c>>>16)+(f>>>16),g=Math.imul(t.lo,e.hi),v=Math.imul(t.hi,e.lo),b=m+g+v>>>0;return{lo:h,hi:b}}function Ge(t,e){return Math.imul(t,e)>>>0}function At(t,e){if(e===0)return t;if(e===32)return{lo:t.hi,hi:t.lo};if(e<32){let i=(t.lo<<e|t.hi>>>32-e)>>>0,o=(t.hi<<e|t.lo>>>32-e)>>>0;return{lo:i,hi:o}}e-=32;let r=(t.hi<<e|t.lo>>>32-e)>>>0,n=(t.lo<<e|t.hi>>>32-e)>>>0;return{lo:r,hi:n}}function A(t,e){return{lo:(t.lo^e.lo)>>>0,hi:(t.hi^e.hi)>>>0}}function jo(t,e){if(e===0)return t;if(e<32){let r=(t.lo>>>e|t.hi<<32-e)>>>0,n=t.hi>>>e;return{lo:r,hi:n}}return{lo:t.hi>>>e-32,hi:0}}function I(t,e){return{lo:t>>>0,hi:e>>>0}}function Go(t,e){return(t<<e|t>>>32-e)>>>0}function $a(t,e){let r=e*8,n=t[r]|t[r+1]<<8|t[r+2]<<16|t[r+3]<<24,i=t[r+4]|t[r+5]<<8|t[r+6]<<16|t[r+7]<<24;return{lo:n>>>0,hi:i>>>0}}function Wf(t,e){let r=e*4;return(t[r]|t[r+1]<<8|t[r+2]<<16|t[r+3]<<24)>>>0}function Ha(t){return t=A(t,jo(t,33)),t=Z(t,I(3981806797,4283543511)),t=A(t,jo(t,33)),t=Z(t,I(444984403,3301882366)),t=A(t,jo(t,33)),t}function Yf(t){return t^=t>>>16,t=Ge(t,2246822507),t^=t>>>13,t=Ge(t,3266489909),t^=t>>>16,t}function Wo(t,e=0){let r=I(e,0),n=I(e,0),i=t.length,o=Math.floor(i/16),s=I(289559509,2277735313),a=I(658871167,1291169091);for(let m=0;m<o;m++){let g=$a(t,m*2),v=$a(t,m*2+1);g=Z(g,s),g=At(g,31),g=Z(g,a),r=A(r,g),r=At(r,27),r=Ue(r,n),r=Ue(Z(r,I(5,0)),I(1390208809,0)),v=Z(v,a),v=At(v,33),v=Z(v,s),n=A(n,v),n=At(n,31),n=Ue(n,r),n=Ue(Z(n,I(5,0)),I(944331445,0))}let c=I(0,0),u=I(0,0),f=t.slice(o*16);switch(f.length){case 15:u=A(u,I(0,f[14]<<16));case 14:u=A(u,I(0,f[13]<<8));case 13:u=A(u,I(0,f[12]));case 12:u=A(u,I(f[11]<<24,0));case 11:u=A(u,I(f[10]<<16,0));case 10:u=A(u,I(f[9]<<8,0));case 9:u=A(u,I(f[8],0)),u=Z(u,a),u=At(u,33),u=Z(u,s),n=A(n,u);case 8:c=A(c,I(0,f[7]<<24));case 7:c=A(c,I(0,f[6]<<16));case 6:c=A(c,I(0,f[5]<<8));case 5:c=A(c,I(0,f[4]));case 4:c=A(c,I(f[3]<<24,0));case 3:c=A(c,I(f[2]<<16,0));case 2:c=A(c,I(f[1]<<8,0));case 1:c=A(c,I(f[0],0)),c=Z(c,s),c=At(c,31),c=Z(c,a),r=A(r,c)}let h=I(i,0);return r=A(r,h),n=A(n,h),r=Ue(r,n),n=Ue(n,r),r=Ha(r),n=Ha(n),r=Ue(r,n),n=Ue(n,r),new Uint8Array([r.hi>>>24&255,r.hi>>>16&255,r.hi>>>8&255,r.hi&255,r.lo>>>24&255,r.lo>>>16&255,r.lo>>>8&255,r.lo&255,n.hi>>>24&255,n.hi>>>16&255,n.hi>>>8&255,n.hi&255,n.lo>>>24&255,n.lo>>>16&255,n.lo>>>8&255,n.lo&255])}function Va(t,e=0){let r=e>>>0,n=t.length,i=Math.floor(n/4),o=3432918353,s=461845907;for(let u=0;u<i;u++){let f=Wf(t,u);f=Ge(f,o),f=Go(f,15),f=Ge(f,s),r^=f,r=Go(r,13),r=Gf(Ge(r,5),3864292196)}let a=t.slice(i*4),c=0;switch(a.length){case 3:c^=a[2]<<16;case 2:c^=a[1]<<8;case 1:c^=a[0],c=Ge(c,o),c=Go(c,15),c=Ge(c,s),r^=c}return r^=n,r=Yf(r),r}function Kf(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 F0=He({name:"murmur3-32",code:35,encode:t=>Kf(Va(t))}),qa=He({name:"murmur3-128",code:34,encode:t=>Wo(t)}),M0=He({name:"murmur3-x64-64",code:34,encode:t=>Wo(t).subarray(0,8)});var Ya=St(Wa(),1);var We=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 Ya.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((i,o,s)=>(o!=null&&(o instanceof t?i.push(o.serialize(e,r)):i.push(e(o,s))),i),n))}async asyncTransform(e,r){return Ja(this,e,r)}toJSON(){return this.serialize(th,rh)}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"?$r(e):e),n=await r.take(this._options.bits),i=this._children.get(n);return i instanceof t?i._findPlace(r):{bucket:this,pos:n,hash:r,existingChild:i}}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 i=await n._findPlace(r.existingChild.hash);return i.bucket._putAt(i,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(eh);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 eh(t){return!!t}function th(t,e){return t.key}function rh(t){return t}async function Ja(t,e,r){let n=[];for(let i of t._children.compactArray())if(i instanceof We)await Ja(i,e,r);else{let o=await e(i);n.push({bitField:t._children.bitField(),children:o})}return r(n)}var nh=[255,254,252,248,240,224,192,128],oh=[1,3,7,15,31,63,127,255],un=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 i=this._value[this._currentBytePos],o=this._currentBitPos+1,s=Math.min(o,r),a=ih(i,o-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 ih(t,e,r){let n=sh(e,r);return(t&n)>>>e}function sh(t,e){return nh[t]&oh[Math.min(e+t-1,7)]}function Ka(t){function e(r){return r instanceof ln?r:new ln(r,t)}return e}var ln=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 i=this._buffers[this._currentBufferIndex],o=Math.min(i.availableBits(),r),s=i.take(o);n=(n<<o)+s,r-=o,this._availableBits-=o,i.availableBits()===0&&this._currentBufferIndex++}return n}untake(e){let r=e;for(;r>0;){let n=this._buffers[this._currentBufferIndex],i=Math.min(n.totalBits()-n.availableBits(),r);n.untake(i),r-=i,this._availableBits+=i,this._currentBufferIndex>0&&n.totalBits()===n.availableBits()&&(this._depth--,this._currentBufferIndex--)}}async _produceMoreBits(){this._depth++;let e=this._depth>0?Gt([this._value,Uint8Array.from([this._depth])]):this._value,r=await this._hashFn(e),n=new un(r);this._buffers.push(n),this._availableBits+=n.availableBits()}};function Qa(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 We(e)}function fn(t){return t.type==="DIRECTORY"}function Yo(t){return t.type==="FILE"}function Jo(t){return t.type==="RAW"}function Ko(t){return t.type==="SYMLINK"}function Pe(t){return t.type==="HAMT_SHARD"&&t.data instanceof Uint8Array&&typeof t.fanOut=="bigint"&&typeof t.hashType=="bigint"}function ge(t){return typeof t.name=="string"&&E.asCID(t.hash)===t.hash}function*hn(t){let e={},r={};for(let n of gt.stream(t))switch(n.field){case".data":{if(n.type==="start"&&(r={}),n.type==="end"){if(fn(r)||Pe(r)||Yo(r)||Jo(r)||Ko(r)){yield r;return}throw new S("PBNode Data was not a valid UnixFS type")}break}case".data.type":{r.type=n.value;break}case".data.data":{r.data=n.value;break}case".data.fanOut":{r.fanOut=n.value;break}case".data.hashType":{r.hashType=n.value;break}case".links[]":{n.type==="start"&&(e={type:"LINK"}),n.type==="end"&&ge(e)&&(yield e);break}case".links[].name":{e.name=n.value;break}case".links[].hash":{e.hash=E.decode(n.value);break}default:}}var Xa=(t,e)=>t.toString(16).toUpperCase().padStart(e,"0").substring(0,e),ah=t=>{let e=t.bucket,r=[];for(;e._parent!=null;)r.push(e),e=e._parent;return r.push(e),r.reverse()};async function*dn(t,e,r,n,i,o,s){let a=(o.lastBucket.tableSize()-1).toString(16).length,c=[];for(let w of e){if(!ge(w))throw new S("Invalid link");if(c.push(w),w.name.length===a){let x=parseInt(w.name,16);o.lastBucket._putObjectAt(x,new We({hash:o.lastBucket._options.hash,bits:o.lastBucket._options.bits},o.lastBucket,x))}if(w.name.substring(a)===r){yield{cid:w.hash,name:r,rest:n};return}await o.rootBucket.put(w.name.substring(a),!0)}let u=await o.rootBucket._findNewBucketAndPos(r),f=Xa(u.pos,a),h=ah(u);h.length>o.hamtDepth&&(o.lastBucket=h[o.hamtDepth],f=Xa(o.lastBucket._posAtParent,a));let m=c.find(w=>w.name==null?!1:w.name===f);if(m==null)return;o.hamtDepth++;let g=await _(i.get(m.hash,s));s?.yieldSubShards===!0&&(yield{cid:m.hash,name:m.name,rest:[r,...n]});let v=hn(g),{value:b}=v.next();if(c=[],b!=null){if(Pe(b)){yield*dn(b,v,r,n,i,o,s);return}if(!ge(b))throw new S("Did not read Link or Data from dag-pb block");c.push(b);for(let w of v){if(Pe(w)){yield*dn(w,c,r,n,i,o,s);return}if(!ge(w))throw new S("Did not read Link or Data from dag-pb block");c.push(w)}}}function*Za(t,e,r){for(let n of t){if(!ge(n))throw new S("Invalid link");if(n.name===e[0]){yield{cid:n.hash,name:e[0],rest:e.slice(1)};return}}throw new q(`No link "${e[0]}" found under ${r}`)}var ch=async function(t){return(await qa.encode(t)).slice(0,8).reverse()};async function*ec(t,e,r,n,i,o){let s=Qa({hashFn:ch,bits:Math.log2(Number(t.fanOut))}),a={rootBucket:s,hamtDepth:1,lastBucket:s};for await(let c of dn(t,e,r[0],r.slice(1),i,a,o))if(yield c,c.name===r[0])return;throw new q(`No link "${r[0]}" found under ${n}`)}async function*tc(t,e,r,n){let i=await _(r.get(t,n)),o=[],s=hn(i),{value:a}=s.next(),c=!1,u=!1;if(a!=null){if(u=fn(a),c=Pe(a),Yo(a)||Jo(a)||Ko(a)){yield{cid:t,name:e[0],rest:e.slice(1)};return}if(u||c&&n?.translateHAMTPath===!1){yield*Za(s,e,t);return}if(c){yield*ec(a,s,e,t,r,n);return}if(!ge(a))throw new S("Did not read Link or Data from dag-pb block");o.push(a);for(let f of s){if(u=fn(f),c=Pe(f),u||c&&n?.translateHAMTPath===!1){yield*Za(o,e,t);return}if(Pe(f)){yield*ec(f,o,e,t,r,n);return}if(!ge(f))throw new S("Did not read Link or Data from dag-pb block");o.push(f)}}throw new q(`No link "${e[0]}" found under ${t}`)}async function*rc(t,e,r,n){if(e.length!==0)throw new Et(`Cannot load path /${e.join("/")} from identity block`)}async function*nc(t,e,r,n){let i=await _(r.get(t,n)),o=Or(i),s=It(o,e);yield{cid:t,name:s.path,rest:s.rest}}async function*oc(t,e,r,n){if(e.length!==0)throw new q(`Cannot load path /${e.join("/")} from raw block`)}var lh={[bt]:tc,[ft]:oc,[Cr]:qo,81:qo,[sn]:za,[jt.code]:rc,[Mr]:nc};async function*pn(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,...i]=t.split(/(?<!\\)\//g).filter(Boolean),o=E.parse(n),s=[o],a=`${o}`;for(yield{cid:o,name:a,path:a,roots:s,remainder:i};i.length>0;){let c=lh[o.code];if(c==null)throw new vt(`No resolver for code ${o.code}`);let u=!1;for await(let f of c(o,i,e,r)){if(o=f.cid,u=!s[s.length-1].equals(o),i=f.rest,!u)break;s=[...s,f.cid],a=`${a}/${f.name}`,yield{cid:f.cid,name:f.name,path:a,roots:s,remainder:f.rest}}if(!u)break}if(r?.signal?.throwIfAborted(),i.length!==0)throw new q(`Could not resolve path /${i.join("/")} under ${t}`)}function fh(t){return t[Symbol.asyncIterator]!=null}function hh(t){if(fh(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 ic=hh;async function Qo(t,e,r,n,i){let o=await _(n.get(t,i)),s=$e(o);return{type:"object",cid:t,name:e,path:r,object:s,node:o,size:BigInt(o.byteLength)}}async function sc(t,e,r,n,i){let o=await _(n.get(t,i)),s=an(o);return{type:"object",cid:t,name:e,path:r,object:s,node:o,size:BigInt(o.byteLength)}}var ee=class extends Event{type;detail;constructor(e,r){super(e),this.type=e,this.detail=r}};function sr(t,e,r,n){let i=BigInt(t.length),o=BigInt(e+i);return r>=o||n<e?new Uint8Array(0):(n>=e&&n<o&&(t=t.subarray(0,Number(n-e))),r>=e&&r<o&&(t=t.subarray(Number(r-e))),t)}var mn=(t,e=0,r=t)=>{let n=BigInt(t),i=BigInt(e??0),o=BigInt(r);if(o!==n&&(o=i+o),o>n&&(o=n),i<0n)throw new ye("Offset must be greater than or equal to 0");if(i>n)throw new ye("Offset must be less than the file size");if(o<0n)throw new ye("Length must be greater than or equal to 0");if(o>n)throw new ye("Length must be less than the file size");return{start:i,end:o}};function yn(t,e){async function*r(n={}){let{start:i,end:o}=mn(t.length,n.offset,n.length),s=sr(t,0n,i,o);n.onProgress?.(new ee(e,{bytesRead:BigInt(s.byteLength),totalBytes:o-i,fileSize:BigInt(t.byteLength)})),yield s}return r}async function ac(t,e,r,n,i){let o=ut(t.multihash.bytes);return{type:"identity",cid:t,name:e,path:r,content:yn(o.digest,"unixfs:exporter:progress:identity"),size:BigInt(o.bytes.byteLength),node:o.bytes}}async function cc(t,e,r,n,i){let o=await _(n.get(t,i)),s=Or(o);return{type:"object",cid:t,name:e,path:r,object:s,size:BigInt(o.byteLength),node:o}}async function uc(t,e,r,n,i){let o=await _(n.get(t,i));return{type:"raw",cid:t,name:e,path:r,content:yn(o,"unixfs:exporter:progress:raw"),size:BigInt(o.length),node:o}}function lc(t,e,r,n){async function*i(o={}){let s=o.offset??0,a=o.length??e.Links.length,c=e.Links.slice(s,s+a);o.onProgress?.(new ee("unixfs:exporter:walk:directory",{cid:t})),yield*c.map(u=>({cid:u.Hash,name:u.Name??"",path:`${n}/${u.Name??""}`,size:BigInt(u.Tsize??0)}))}return i}var gn=globalThis.CustomEvent??Event;async function*Xo(t,e={}){let r=e.concurrency??1/0;r<1&&(r=1/0);let n=e.ordered??!1,i=new EventTarget,o=[],s=M(),a=M(),c=!1,u,f=!1,h=!1;i.addEventListener("task-complete",()=>{a.resolve()}),Promise.resolve().then(async()=>{try{for await(let b of t){if(o.length===r&&(s=M(),await s.promise),f||h)break;let w={done:!1};o.push(w),b().then(x=>{w.done=!0,w.ok=!0,w.value=x,i.dispatchEvent(new gn("task-complete"))},x=>{w.done=!0,w.err=x,i.dispatchEvent(new gn("task-complete"))})}c=!0,i.dispatchEvent(new gn("task-complete"))}catch(b){u=b,i.dispatchEvent(new gn("task-complete"))}});function m(){return n?o[0]?.done:!!o.find(b=>b.done)}function*g(){for(;o.length>0&&o[0].done;){let b=o[0];if(o.shift(),b.ok)yield b.value;else throw f=!0,s.resolve(),b.err;s.resolve()}}function*v(){for(;m();)for(let b=0;b<o.length;b++)if(o[b].done){let w=o[b];if(o.splice(b,1),b--,w.ok)yield w.value;else throw f=!0,s.resolve(),w.err;s.resolve()}}try{for(;;){if(m()||(a=M(),await a.promise),u!=null||(n?yield*g():yield*v(),u!=null))throw u;if(c&&o.length===0)break}}finally{h=!0,s.resolve()}}var ei=St(hc(),1);function ti(t,e,r){let n=0,i=t.length;for(;i>0;){let o=Math.trunc(i/2),s=n+o;r(t[s],e)<=0?(n=++s,i-=o+1):i=o}return n}var mh=100,Tt=class{#e=[];#t=0;enqueue(e,r){let{priority:n=0,id:i}=r??{},{size:o}=this,s={priority:n,id:i,run:e};if(o===0){this.#e.length=0,this.#t=0,this.#e.push(s);return}if(this.#e.at(-1).priority>=n){this.#e.push(s);return}this.#i();let a=ti(this.#e,s,(c,u)=>u.priority-c.priority);this.#e.splice(a,0,s)}setPriority(e,r){let n=this.#e.findIndex((o,s)=>s>=this.#t&&o.id===e);if(n===-1)throw new ReferenceError(`No promise function with the id "${e}" exists in the queue.`);let[i]=this.#e.splice(n,1);this.enqueue(i.run,{priority:r,id:e})}remove(e){let r=this.#e.findIndex((n,i)=>i<this.#t?!1:typeof e=="string"?n.id===e:n.run===e);r!==-1&&this.#e.splice(r,1)}dequeue(){if(this.#t===this.#e.length)return;let e=this.#e[this.#t];return this.#t++,this.#t===this.#e.length?(this.#e.length=0,this.#t=0):this.#t>mh&&this.#t>this.#e.length/2&&this.#i(),e?.run}filter(e){let r=[];for(let n=this.#t;n<this.#e.length;n++){let i=this.#e[n];i.priority===e.priority&&r.push(i.run)}return r}get size(){return this.#e.length-this.#t}#i(){this.#t!==0&&(this.#e.splice(0,this.#t),this.#t=0)}};var cr=class extends ei.default{#e;#t;#i=0;#d;#m=!1;#x=!1;#u;#b=0;#c;#l;#a;#s=[];#o=0;#r;#A;#n=0;#y;#f;#N=1n;#g=new Map;#E=new Set;timeout;constructor(e){if(super(),e={carryoverIntervalCount:!1,intervalCap:Number.POSITIVE_INFINITY,interval:0,concurrency:Number.POSITIVE_INFINITY,autoStart:!0,queueClass:Tt,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.#t=e.intervalCap===Number.POSITIVE_INFINITY||e.interval===0,this.#d=e.intervalCap,this.#u=e.interval,this.#a=e.strict,this.#r=new e.queueClass,this.#A=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.#f=e.autoStart===!1,this.#z()}#v(e){for(;this.#o<this.#s.length;){let n=this.#s[this.#o];if(n!==void 0&&e-n>=this.#u)this.#o++;else break}(this.#o>100&&this.#o>this.#s.length/2||this.#o===this.#s.length)&&(this.#s=this.#s.slice(this.#o),this.#o=0)}#L(e){this.#a?this.#s.push(e):this.#i++}#U(){this.#a?this.#s.length>this.#o&&this.#s.pop():this.#i>0&&this.#i--}#k(){return this.#s.length-this.#o}get#P(){return this.#t?!0:this.#a?this.#k()<this.#d:this.#i<this.#d}get#R(){return this.#n<this.#y}#F(){this.#n--,this.#n===0&&this.emit("pendingZero"),this.#w(),this.emit("next")}#M(){this.#l=void 0,this.#C(),this.#B()}#O(e){if(this.#a){if(this.#v(e),this.#k()>=this.#d){let n=this.#s[this.#o],i=this.#u-(e-n);return this.#T(i),!0}return!1}if(this.#c===void 0){let r=this.#b-e;if(r<0)this.#i=this.#e?this.#n:0;else return this.#T(r),!0}return!1}#T(e){this.#l===void 0&&(this.#l=setTimeout(()=>{this.#M()},e))}#_(){this.#c&&(clearInterval(this.#c),this.#c=void 0)}#S(){this.#l&&(clearTimeout(this.#l),this.#l=void 0)}#w(){if(this.#r.size===0){if(this.#_(),this.emit("empty"),this.#n===0){if(this.#S(),this.#a&&this.#o>0){let r=Date.now();this.#v(r)}this.emit("idle")}return!1}let e=!1;if(!this.#f){let r=Date.now(),n=!this.#O(r);if(this.#P&&this.#R){let i=this.#r.dequeue();this.#t||(this.#L(r),this.#p()),n&&this.#B(),this.emit("active"),i(),e=!0}}return e}#B(){this.#t||this.#c!==void 0||this.#a||(this.#c=setInterval(()=>{this.#C()},this.#u),this.#b=Date.now()+this.#u)}#C(){this.#a||(this.#c!==void 0&&(this.#i===0&&this.#n===0?this.#_():this.#b=Date.now()+this.#u),this.#i=this.#e?this.#n:0),this.#I(),this.#p()}#I(){for(;this.#w(););}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.#r.setPriority(e,r)}async add(e,r={}){if(r={timeout:this.timeout,...r,id:r.id??(this.#N++).toString()},r.timeout!==void 0&&!(Number.isFinite(r.timeout)&&r.timeout>0))throw new TypeError(`Expected \`timeout\` to be a positive finite number, got \`${r.timeout}\` (${typeof r.timeout})`);return new Promise((n,i)=>{let o=Symbol(`task-${r.id}`),s=()=>{},a=async()=>{s(),this.#n++,this.#g.set(o,{id:r.id,priority:r.priority??0,startTime:Date.now(),timeout:r.timeout});let u;try{try{r.signal?.throwIfAborted()}catch(m){throw this.#$(),this.#g.delete(o),m}let f=e({signal:r.signal});if(r.timeout!==void 0&&(f=Xt(Promise.resolve(f),{milliseconds:r.timeout,message:`Task timed out after ${r.timeout}ms (queue has ${this.#n} running, ${this.#r.size} waiting)`})),r.signal){let{signal:m}=r;f=Promise.race([f,new Promise((g,v)=>{u=()=>{v(m.reason)},m.addEventListener("abort",u,{once:!0})})])}let h=await f;n(h),this.emit("completed",h)}catch(f){i(f),this.emit("error",f)}finally{u&&r.signal?.removeEventListener("abort",u),this.#g.delete(o),queueMicrotask(()=>{this.#F()})}};this.#r.enqueue(a,r);let c=()=>{if(this.#r instanceof Tt){this.#r.remove(a);return}this.#r.remove?.(r.id)};if(r.signal){let{signal:u}=r,f=()=>{s(),c(),i(u.reason),this.#w(),this.emit("next")};if(s=()=>{u.removeEventListener("abort",f),this.#E.delete(s)},u.aborted){f();return}u.addEventListener("abort",f,{once:!0}),this.#E.add(s)}this.emit("add"),this.#w()})}async addAll(e,r){return Promise.all(e.map(async n=>this.add(n,r)))}start(){return this.#f?(this.#f=!1,this.#I(),this):this}pause(){this.#f=!0}clear(){for(let e of this.#E)e();this.#r=new this.#A,this.#_(),this.#D(),this.emit("empty"),this.#n===0&&(this.#S(),this.emit("idle")),this.emit("next")}async onEmpty(){this.#r.size!==0&&await this.#h("empty")}async onSizeLessThan(e){this.#r.size<e||await this.#h(["next","active"],()=>this.#r.size<e)}async onIdle(){this.#n===0&&this.#r.size===0||await this.#h("idle")}async onPendingZero(){this.#n!==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=i=>{this.off("error",n),r(i)};this.on("error",n)})}async#h(e,r){let n=Array.isArray(e)?e:[e];return new Promise(i=>{let o=()=>{if(!(r&&!r())){for(let s of n)this.off(s,o);i()}};for(let s of n)this.on(s,o)})}get size(){return this.#r.size}sizeBy(e){return this.#r.filter(e).length}get pending(){return this.#n}get isPaused(){return this.#f}#z(){this.#t||(this.on("add",()=>{this.#r.size>0&&this.#p()}),this.on("next",()=>{this.#p()}))}#p(){this.#t||this.#x||(this.#x=!0,queueMicrotask(()=>{this.#x=!1,this.#D()}))}#$(){this.#t||(this.#U(),this.#p())}#D(){let e=this.#m;if(this.#t||this.#r.size===0){e&&(this.#m=!1,this.emit("rateLimitCleared"));return}let r;if(this.#a){let i=Date.now();this.#v(i),r=this.#k()}else r=this.#i;let n=r>=this.#d;n!==e&&(this.#m=n,this.emit(n?"rateLimit":"rateLimitCleared"))}get isRateLimited(){return this.#m}get isSaturated(){return this.#n===this.#y&&this.#r.size>0||this.isRateLimited&&this.#r.size>0}get runningTasks(){return[...this.#g.values()].map(e=>({...e,timeoutRemaining:e.timeout?Math.max(0,e.startTime+e.timeout-Date.now()):void 0}))}};async function dc(t,e,r,n,i,o,s){if(e instanceof Uint8Array){let u=sr(e,n,i,o);r.push(u);return}if(e.Data==null)throw new S("no data in PBNode");let a;try{a=he.unmarshal(e.Data)}catch(u){throw new S(u.message)}if(a.data!=null){let u=a.data,f=sr(u,n,i,o);r.push(f),n+=BigInt(f.byteLength)}let c=[];if(e.Links.length!==a.blockSizes.length)throw new S("Inconsistent block sizes and dag links");for(let u=0;u<e.Links.length;u++){let f=e.Links[u],h=n,m=h+a.blockSizes[u];if((i>=h&&i<m||o>=h&&o<=m||i<h&&o>m)&&c.push({link:f,blockStart:n}),n=m,n>o)break}await ma(c,u=>Pr(u,f=>async()=>{let h=await _(t.get(f.link.Hash,s));return{...f,block:h}}),u=>Xo(u,{ordered:!0,concurrency:s.blockReadConcurrency}),async u=>{for await(let{link:f,block:h,blockStart:m}of u){let g;switch(f.Hash.code){case bt:g=tn(h);break;case ft:g=h;break;default:r.end(new S(`Unsupported codec: ${f.Hash.code}`));return}let v=new cr({concurrency:1});v.on("error",b=>{r.end(b)}),v.add(async()=>{s.onProgress?.(new ee("unixfs:exporter:walk:file",{cid:f.Hash})),await dc(t,g,r,m,i,o,s)}),await v.onIdle()}}),n>=o&&r.end()}function ri(t,e,r,n,i){async function*o(s={}){let a=r.fileSize();if(a===void 0)throw new Error("File was a directory");let{start:c,end:u}=mn(a,s.offset,s.length);if(u===0n)return;let f=0n,h=u-c,m=dt();s.onProgress?.(new ee("unixfs:exporter:walk:file",{cid:t})),dc(i,e,m,0n,c,u,s).catch(g=>{m.end(g)});for await(let g of m)if(g!=null){if(f+=BigInt(g.byteLength),f>h)throw m.end(),new nn("Read too many bytes - the file size reported by the UnixFS data in the root node may be incorrect");f===h&&m.end(),s.onProgress?.(new ee("unixfs:exporter:progress:unixfs:file",{bytesRead:f,totalBytes:h,fileSize:a})),yield g}if(f<h)throw new on("Traversed entire DAG but did not read enough bytes")}return o}async function*yh(t,e,r,n){let i=-1,o=0;for await(let s of pc(t,e,r,n))if(i++,!(n.offset!=null&&n.offset<i)&&(yield s,o++,n.length!=null&&n.length===o))return}async function*pc(t,e,r,n){let i=await _(r.get(t,n)),o=gt.decode(i);if(o.data?.fanOut==null)throw new S("missing fanout");let s=(o.data.fanOut-1n).toString(16).length;for(let a of o.links){if(a.name==null||a.hash==null)continue;let c=E.decode(a.hash);if(a.name.length===s)yield*pc(c,e,r,n);else{let u=a.name.substring(s);yield{cid:c,name:a.name.substring(s),path:`${e}/${u}`,size:BigInt(a.tSize??0)}}}}function mc(t,e,r,n,i){function o(s={}){return s.onProgress?.(new ee("unixfs:exporter:walk:hamt-sharded-directory",{cid:t})),yh(t,n,i,s)}return o}var gh={raw:ri,file:ri,directory:lc,"hamt-sharded-directory":mc,metadata:(t,e,r,n)=>()=>[],symlink:(t,e,r,n)=>()=>[]};async function yc(t,e,r,n,i){let o=await _(n.get(t,i)),s;try{s=tn(o)}catch(u){throw new S(u.message)}if(s.Data==null)throw new S("no data in PBNode");let a;try{a=he.unmarshal(s.Data)}catch(u){throw new S(u.message)}let c=gh[a.type](t,s,a,r,n);if(c==null)throw new q("could not find content exporter");return a.isDirectory()?{type:"directory",cid:t,name:e,path:r,entries:c,unixfs:a,node:s,size:BigInt(o.byteLength)}:{type:"file",cid:t,name:e,path:r,content:c,unixfs:a,node:s,size:a.fileSize()}}var wh={[bt]:yc,[ft]:uc,[Cr]:Qo,81:Qo,[sn]:sc,[jt.code]:ac,[Mr]:cc};async function gc(t,e,r={}){let n,i;if(t instanceof String||typeof t=="string"){let s=await ic(pn(t,e,r));if(s==null)throw new q(`Could not walk path to ${t}`);n=s.cid,i=s.name,t=s.path}else if(E.asCID(t)===t||t instanceof E)n=t,i=t=n.toString();else throw new ye("Path must be string or CID");let o=wh[n.code];if(o==null)throw new vt(`No resolver for code ${n.code}`);return o(n,i,t,e,r)}var ni=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,i){for await(let o of pn(`${this.root??e}${this.path}`,r,i)){let s=await gc(o.cid,r,i);yield fe({cid:s.cid,bytes:s.node instanceof Uint8Array?s.node:Fa(s.node),codec:await n(o.cid.code)})}}};function xh(t){return new Xr(t)}return kc(bh);})();
3
3
  return HeliaCar}));
4
4
  //# sourceMappingURL=index.min.js.map