@helia/car 5.3.10-11802dd6 → 5.3.10-1a2ebead

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 Xl=Object.create;var cn=Object.defineProperty;var Ql=Object.getOwnPropertyDescriptor;var Kl=Object.getOwnPropertyNames;var Yl=Object.getPrototypeOf,Zl=Object.prototype.hasOwnProperty;var ft=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),oe=(t,e)=>{for(var r in e)cn(t,r,{get:e[r],enumerable:!0})},Fs=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Kl(e))!Zl.call(t,o)&&o!==r&&cn(t,o,{get:()=>e[o],enumerable:!(n=Ql(e,o))||n.enumerable});return t};var vt=(t,e,r)=>(r=t!=null?Xl(Yl(t)):{},Fs(e||!t||!t.__esModule?cn(r,"default",{value:t,enumerable:!0}):r,t)),ed=t=>Fs(cn({},"__esModule",{value:!0}),t);var oc=ft((u0,nc)=>{nc.exports=ni;var rc=128,Sh=127,Nh=~Sh,Uh=Math.pow(2,31);function ni(t,e,r){if(Number.MAX_SAFE_INTEGER&&t>Number.MAX_SAFE_INTEGER)throw ni.bytes=0,new RangeError("Could not encode varint");e=e||[],r=r||0;for(var n=r;t>=Uh;)e[r++]=t&255|rc,t/=128;for(;t&Nh;)e[r++]=t&255|rc,t>>>=7;return e[r]=t|0,ni.bytes=r-n+1,e}});var ac=ft((f0,sc)=>{sc.exports=oi;var Ch=128,ic=127;function oi(t,n){var r=0,n=n||0,o=0,i=n,s,a=t.length;do{if(i>=a||o>49)throw oi.bytes=0,new RangeError("Could not decode varint");s=t[i++],r+=o<28?(s&ic)<<o:(s&ic)*Math.pow(2,o),o+=7}while(s>=Ch);return oi.bytes=i-n,r}});var uc=ft((l0,cc)=>{var Dh=Math.pow(2,7),Lh=Math.pow(2,14),$h=Math.pow(2,21),Rh=Math.pow(2,28),Fh=Math.pow(2,35),Mh=Math.pow(2,42),Ph=Math.pow(2,49),Oh=Math.pow(2,56),zh=Math.pow(2,63);cc.exports=function(t){return t<Dh?1:t<Lh?2:t<$h?3:t<Rh?4:t<Fh?5:t<Mh?6:t<Ph?7:t<Oh?8:t<zh?9:10}});var An=ft((d0,fc)=>{fc.exports={encode:oc(),decode:ac(),encodingLength:uc()}});var wu=ft((Rw,Ti)=>{"use strict";var vp=Object.prototype.hasOwnProperty,ee="~";function Dr(){}Object.create&&(Dr.prototype=Object.create(null),new Dr().__proto__||(ee=!1));function Ap(t,e,r){this.fn=t,this.context=e,this.once=r||!1}function xu(t,e,r,n,o){if(typeof r!="function")throw new TypeError("The listener must be a function");var i=new Ap(r,n||t,o),s=ee?ee+e:e;return t._events[s]?t._events[s].fn?t._events[s]=[t._events[s],i]:t._events[s].push(i):(t._events[s]=i,t._eventsCount++),t}function Hn(t,e){--t._eventsCount===0?t._events=new Dr:delete t._events[e]}function Q(){this._events=new Dr,this._eventsCount=0}Q.prototype.eventNames=function(){var e=[],r,n;if(this._eventsCount===0)return e;for(n in r=this._events)vp.call(r,n)&&e.push(ee?n.slice(1):n);return Object.getOwnPropertySymbols?e.concat(Object.getOwnPropertySymbols(r)):e};Q.prototype.listeners=function(e){var r=ee?ee+e:e,n=this._events[r];if(!n)return[];if(n.fn)return[n.fn];for(var o=0,i=n.length,s=new Array(i);o<i;o++)s[o]=n[o].fn;return s};Q.prototype.listenerCount=function(e){var r=ee?ee+e:e,n=this._events[r];return n?n.fn?1:n.length:0};Q.prototype.emit=function(e,r,n,o,i,s){var a=ee?ee+e:e;if(!this._events[a])return!1;var c=this._events[a],f=arguments.length,l,p;if(c.fn){switch(c.once&&this.removeListener(e,c.fn,void 0,!0),f){case 1:return c.fn.call(c.context),!0;case 2:return c.fn.call(c.context,r),!0;case 3:return c.fn.call(c.context,r,n),!0;case 4:return c.fn.call(c.context,r,n,o),!0;case 5:return c.fn.call(c.context,r,n,o,i),!0;case 6:return c.fn.call(c.context,r,n,o,i,s),!0}for(p=1,l=new Array(f-1);p<f;p++)l[p-1]=arguments[p];c.fn.apply(c.context,l)}else{var k=c.length,v;for(p=0;p<k;p++)switch(c[p].once&&this.removeListener(e,c[p].fn,void 0,!0),f){case 1:c[p].fn.call(c[p].context);break;case 2:c[p].fn.call(c[p].context,r);break;case 3:c[p].fn.call(c[p].context,r,n);break;case 4:c[p].fn.call(c[p].context,r,n,o);break;default:if(!l)for(v=1,l=new Array(f-1);v<f;v++)l[v-1]=arguments[v];c[p].fn.apply(c[p].context,l)}}return!0};Q.prototype.on=function(e,r,n){return xu(this,e,r,n,!1)};Q.prototype.once=function(e,r,n){return xu(this,e,r,n,!0)};Q.prototype.removeListener=function(e,r,n,o){var i=ee?ee+e:e;if(!this._events[i])return this;if(!r)return Hn(this,i),this;var s=this._events[i];if(s.fn)s.fn===r&&(!o||s.once)&&(!n||s.context===n)&&Hn(this,i);else{for(var a=0,c=[],f=s.length;a<f;a++)(s[a].fn!==r||o&&!s[a].once||n&&s[a].context!==n)&&c.push(s[a]);c.length?this._events[i]=c.length===1?c[0]:c:Hn(this,i)}return this};Q.prototype.removeAllListeners=function(e){var r;return e?(r=ee?ee+e:e,this._events[r]&&Hn(this,r)):(this._events=new Dr,this._eventsCount=0),this};Q.prototype.off=Q.prototype.removeListener;Q.prototype.addListener=Q.prototype.on;Q.prefixed=ee;Q.EventEmitter=Q;typeof Ti<"u"&&(Ti.exports=Q)});var Nu=ft(($b,Su)=>{Su.exports=function(t){if(!t)throw Error("hashlru must have a max value, of type number, greater than 0");var e=0,r=Object.create(null),n=Object.create(null);function o(i,s){r[i]=s,e++,e>=t&&(e=0,n=r,r=Object.create(null))}return{has:function(i){return r[i]!==void 0||n[i]!==void 0},remove:function(i){r[i]!==void 0&&(r[i]=void 0),n[i]!==void 0&&(n[i]=void 0)},get:function(i){var s=r[i];if(s!==void 0)return s;if((s=n[i])!==void 0)return o(i,s),s},set:function(i,s){r[i]!==void 0?r[i]=s:o(i,s)},clear:function(){r=Object.create(null),n=Object.create(null)}}}});var Bl=ft((Tv,Il)=>{"use strict";Il.exports=class{constructor(){this._bitArrays=[],this._data=[],this._length=0,this._changedLength=!1,this._changedData=!1}set(e,r){let n=this._internalPositionFor(e,!1);if(r===void 0)n!==-1&&(this._unsetInternalPos(n),this._unsetBit(e),this._changedLength=!0,this._changedData=!0);else{let o=!1;n===-1?(n=this._data.length,this._setBit(e),this._changedData=!0):o=!0,this._setInternalPos(n,e,r,o),this._changedLength=!0}}unset(e){this.set(e,void 0)}get(e){this._sortData();let r=this._internalPositionFor(e,!0);if(r!==-1)return this._data[r][1]}push(e){return this.set(this.length,e),this.length}get length(){if(this._sortData(),this._changedLength){let e=this._data[this._data.length-1];this._length=e?e[0]+1:0,this._changedLength=!1}return this._length}forEach(e){let r=0;for(;r<this.length;)e(this.get(r),r,this),r++}map(e){let r=0,n=new Array(this.length);for(;r<this.length;)n[r]=e(this.get(r),r,this),r++;return n}reduce(e,r){let n=0,o=r;for(;n<this.length;){let i=this.get(n);o=e(o,i,n),n++}return o}find(e){let r=0,n,o;for(;r<this.length&&!n;)o=this.get(r),n=e(o),r++;return n?o:void 0}_internalPositionFor(e,r){let n=this._bytePosFor(e,r);if(n>=this._bitArrays.length)return-1;let o=this._bitArrays[n],i=e-n*7;if(!((o&1<<i)>0))return-1;let a=this._bitArrays.slice(0,n).reduce(ky,0),c=~(4294967295<<i+1),f=Tl(o&c);return a+f-1}_bytePosFor(e,r){let n=Math.floor(e/7),o=n+1;for(;!r&&this._bitArrays.length<o;)this._bitArrays.push(0);return n}_setBit(e){let r=this._bytePosFor(e,!1);this._bitArrays[r]|=1<<e-r*7}_unsetBit(e){let r=this._bytePosFor(e,!1);this._bitArrays[r]&=~(1<<e-r*7)}_setInternalPos(e,r,n,o){let i=this._data,s=[r,n];if(o)this._sortData(),i[e]=s;else{if(i.length)if(i[i.length-1][0]>=r)i.push(s);else if(i[0][0]<=r)i.unshift(s);else{let a=Math.round(i.length/2);this._data=i.slice(0,a).concat(s).concat(i.slice(a))}else this._data.push(s);this._changedData=!0,this._changedLength=!0}}_unsetInternalPos(e){this._data.splice(e,1)}_sortData(){this._changedData&&this._data.sort(vy),this._changedData=!1}bitField(){let e=[],r=8,n=0,o=0,i,s=this._bitArrays.slice();for(;s.length||n;){n===0&&(i=s.shift(),n=7);let c=Math.min(n,r),f=~(255<<c),l=i&f;o|=l<<8-r,i=i>>>c,n-=c,r-=c,(!r||!n&&!s.length)&&(e.push(o),o=0,r=8)}for(var a=e.length-1;a>0&&e[a]===0;a--)e.pop();return e}compactArray(){return this._sortData(),this._data.map(Ay)}};function ky(t,e){return t+Tl(e)}function Tl(t){let e=t;return e=e-(e>>1&1431655765),e=(e&858993459)+(e>>2&858993459),(e+(e>>4)&252645135)*16843009>>24}function vy(t,e){return t[0]-e[0]}function Ay(t){return t[1]}});var jy={};oe(jy,{BlockExporter:()=>ps,CIDPath:()=>Bs,GraphSearch:()=>Is,SubgraphExporter:()=>Xr,UnixFSExporter:()=>Qr,UnixFSPath:()=>Rs,breadthFirstWalker:()=>wt,car:()=>Hy,depthFirstWalker:()=>xt,naturalOrderWalker:()=>hs});var td=["Object","RegExp","Date","Error","Map","Set","WeakMap","WeakSet","ArrayBuffer","SharedArrayBuffer","DataView","Promise","URL","HTMLElement","Int8Array","Uint8ClampedArray","Int16Array","Uint16Array","Int32Array","Uint32Array","Float32Array","Float64Array","BigInt64Array","BigUint64Array"];function Co(t){if(t===null)return"null";if(t===void 0)return"undefined";if(t===!0||t===!1)return"boolean";let e=typeof t;if(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=rd(t);return r||"Object"}function rd(t){let e=Object.prototype.toString.call(t).slice(8,-1);if(td.includes(e))return e}var d=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}};d.uint=new d(0,"uint",!0);d.negint=new d(1,"negint",!0);d.bytes=new d(2,"bytes",!0);d.string=new d(3,"string",!0);d.array=new d(4,"array",!1);d.map=new d(5,"map",!1);d.tag=new d(6,"tag",!1);d.float=new d(7,"float",!0);d.false=new d(7,"false",!0);d.true=new d(7,"true",!0);d.null=new d(7,"null",!0);d.undefined=new d(7,"undefined",!0);d.break=new d(7,"break",!0);var E=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 ur=globalThis.process&&!globalThis.process.browser&&globalThis.Buffer&&typeof globalThis.Buffer.isBuffer=="function",nd=new TextEncoder;function un(t){return ur&&globalThis.Buffer.isBuffer(t)}function fr(t){return t instanceof Uint8Array?un(t)?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):t:Uint8Array.from(t)}var od=24,id=200,fn=ur?t=>t.length>=od?globalThis.Buffer.from(t):Ms(t):t=>t.length>=id?nd.encode(t):Ms(t),De=t=>Uint8Array.from(t),Ps=ur?(t,e,r)=>un(t)?new Uint8Array(t.subarray(e,r)):t.slice(e,r):(t,e,r)=>t.slice(e,r),Os=ur?(t,e)=>(t=t.map(r=>r instanceof Uint8Array?r:globalThis.Buffer.from(r)),fr(globalThis.Buffer.concat(t,e))):(t,e)=>{let r=new Uint8Array(e),n=0;for(let o of t)n+o.length>r.length&&(o=o.subarray(0,r.length-n)),r.set(o,n),n+=o.length;return r},zs=ur?t=>globalThis.Buffer.allocUnsafe(t):t=>new Uint8Array(t);function ln(t,e){if(un(t)&&un(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 Ms(t){let e=[],r=0;for(let n=0;n<t.length;n++){let o=t.charCodeAt(n);o<128?e[r++]=o:o<2048?(e[r++]=o>>6|192,e[r++]=o&63|128):(o&64512)===55296&&n+1<t.length&&(t.charCodeAt(n+1)&64512)===56320?(o=65536+((o&1023)<<10)+(t.charCodeAt(++n)&1023),e[r++]=o>>18|240,e[r++]=o>>12&63|128,e[r++]=o>>6&63|128,e[r++]=o&63|128):(o>=55296&&o<=57343&&(o=65533),e[r++]=o>>12|224,e[r++]=o>>6&63|128,e[r++]=o&63|128)}return e}var sd=256,lr=class{constructor(e=sd){this.chunkSize=e,this.cursor=0,this.maxCursor=-1,this.chunks=[],this._initReuseChunk=null}reset(){this.cursor=0,this.maxCursor=-1,this.chunks.length&&(this.chunks=[]),this._initReuseChunk!==null&&(this.chunks.push(this._initReuseChunk),this.maxCursor=this._initReuseChunk.length-1)}push(e){let r=this.chunks[this.chunks.length-1];if(this.cursor+e.length<=this.maxCursor+1){let o=r.length-(this.maxCursor-this.cursor)-1;r.set(e,o)}else{if(r){let o=r.length-(this.maxCursor-this.cursor)-1;o<r.length&&(this.chunks[this.chunks.length-1]=r.subarray(0,o),this.maxCursor=this.cursor-1)}e.length<64&&e.length<this.chunkSize?(r=zs(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=Ps(n,0,this.cursor)}else r=Os(this.chunks,this.cursor);return e&&this.reset(),r}},dn=class{constructor(e){this.dest=e,this.cursor=0,this.chunks=[e]}reset(){this.cursor=0}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 A="CBOR decode error:",hn="CBOR encode error:",dr=[];dr[23]=1;dr[24]=2;dr[25]=3;dr[26]=5;dr[27]=9;function je(t,e,r){if(t.length-e<r)throw new Error(`${A} not enough data for type`)}var j=[24,256,65536,4294967296,BigInt("18446744073709551616")];function ie(t,e,r){je(t,e,1);let n=t[e];if(r.strict===!0&&n<j[0])throw new Error(`${A} integer encoded in more bytes than necessary (strict decode)`);return n}function se(t,e,r){je(t,e,2);let n=t[e]<<8|t[e+1];if(r.strict===!0&&n<j[1])throw new Error(`${A} integer encoded in more bytes than necessary (strict decode)`);return n}function ae(t,e,r){je(t,e,4);let n=t[e]*16777216+(t[e+1]<<16)+(t[e+2]<<8)+t[e+3];if(r.strict===!0&&n<j[2])throw new Error(`${A} integer encoded in more bytes than necessary (strict decode)`);return n}function ce(t,e,r){je(t,e,8);let n=t[e]*16777216+(t[e+1]<<16)+(t[e+2]<<8)+t[e+3],o=t[e+4]*16777216+(t[e+5]<<16)+(t[e+6]<<8)+t[e+7],i=(BigInt(n)<<BigInt(32))+BigInt(o);if(r.strict===!0&&i<j[3])throw new Error(`${A} integer encoded in more bytes than necessary (strict decode)`);if(i<=Number.MAX_SAFE_INTEGER)return Number(i);if(r.allowBigInt===!0)return i;throw new Error(`${A} integers outside of the safe integer range are not supported`)}function Hs(t,e,r,n){return new E(d.uint,ie(t,e+1,n),2)}function js(t,e,r,n){return new E(d.uint,se(t,e+1,n),3)}function Vs(t,e,r,n){return new E(d.uint,ae(t,e+1,n),5)}function qs(t,e,r,n){return new E(d.uint,ce(t,e+1,n),9)}function we(t,e){return $(t,0,e.value)}function $(t,e,r){if(r<j[0]){let n=Number(r);t.push([e|n])}else if(r<j[1]){let n=Number(r);t.push([e|24,n])}else if(r<j[2]){let n=Number(r);t.push([e|25,n>>>8,n&255])}else if(r<j[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<j[4]){let o=[e|27,0,0,0,0,0,0,0],i=Number(n&BigInt(4294967295)),s=Number(n>>BigInt(32)&BigInt(4294967295));o[8]=i&255,i=i>>8,o[7]=i&255,i=i>>8,o[6]=i&255,i=i>>8,o[5]=i&255,o[4]=s&255,s=s>>8,o[3]=s&255,s=s>>8,o[2]=s&255,s=s>>8,o[1]=s&255,t.push(o)}else throw new Error(`${A} encountered BigInt larger than allowable range`)}}we.encodedSize=function(e){return $.encodedSize(e.value)};$.encodedSize=function(e){return e<j[0]?1:e<j[1]?2:e<j[2]?3:e<j[3]?5:9};we.compareTokens=function(e,r){return e.value<r.value?-1:e.value>r.value?1:0};function Gs(t,e,r,n){return new E(d.negint,-1-ie(t,e+1,n),2)}function Ws(t,e,r,n){return new E(d.negint,-1-se(t,e+1,n),3)}function Js(t,e,r,n){return new E(d.negint,-1-ae(t,e+1,n),5)}var Do=BigInt(-1),Xs=BigInt(1);function Qs(t,e,r,n){let o=ce(t,e+1,n);if(typeof o!="bigint"){let i=-1-o;if(i>=Number.MIN_SAFE_INTEGER)return new E(d.negint,i,9)}if(n.allowBigInt!==!0)throw new Error(`${A} integers outside of the safe integer range are not supported`);return new E(d.negint,Do-BigInt(o),9)}function pn(t,e){let r=e.value,n=typeof r=="bigint"?r*Do-Xs:r*-1-1;$(t,e.type.majorEncoded,n)}pn.encodedSize=function(e){let r=e.value,n=typeof r=="bigint"?r*Do-Xs:r*-1-1;return n<j[0]?1:n<j[1]?2:n<j[2]?3:n<j[3]?5:9};pn.compareTokens=function(e,r){return e.value<r.value?1:e.value>r.value?-1:0};function hr(t,e,r,n){je(t,e,r+n);let o=t.slice(e+r,e+r+n);return new E(d.bytes,o,r+n)}function Ks(t,e,r,n){return hr(t,e,1,r)}function Ys(t,e,r,n){return hr(t,e,2,ie(t,e+1,n))}function Zs(t,e,r,n){return hr(t,e,3,se(t,e+1,n))}function ea(t,e,r,n){return hr(t,e,5,ae(t,e+1,n))}function ta(t,e,r,n){let o=ce(t,e+1,n);if(typeof o=="bigint")throw new Error(`${A} 64-bit integer bytes lengths not supported`);return hr(t,e,9,o)}function mn(t){return t.encodedBytes===void 0&&(t.encodedBytes=d.equals(t.type,d.string)?fn(t.value):t.value),t.encodedBytes}function At(t,e){let r=mn(e);$(t,e.type.majorEncoded,r.length),t.push(r)}At.encodedSize=function(e){let r=mn(e);return $.encodedSize(r.length)+r.length};At.compareTokens=function(e,r){return cd(mn(e),mn(r))};function cd(t,e){return t.length<e.length?-1:t.length>e.length?1:ln(t,e)}var ra=new TextDecoder,fd=32;function ld(t,e,r){if(r-e<fd){let o="";for(let i=e;i<r;i++){let s=t[i];if(s&128)return ra.decode(t.subarray(e,r));o+=String.fromCharCode(s)}return o}return ra.decode(t.subarray(e,r))}function pr(t,e,r,n,o){let i=r+n;je(t,e,i);let s=new E(d.string,ld(t,e+r,e+i),i);return o.retainStringBytes===!0&&(s.byteValue=t.slice(e+r,e+i)),s}function na(t,e,r,n){return pr(t,e,1,r,n)}function oa(t,e,r,n){return pr(t,e,2,ie(t,e+1,n),n)}function ia(t,e,r,n){return pr(t,e,3,se(t,e+1,n),n)}function sa(t,e,r,n){return pr(t,e,5,ae(t,e+1,n),n)}function aa(t,e,r,n){let o=ce(t,e+1,n);if(typeof o=="bigint")throw new Error(`${A} 64-bit integer string lengths not supported`);return pr(t,e,9,o,n)}var ca=At;function Tt(t,e,r,n){return new E(d.array,n,r)}function ua(t,e,r,n){return Tt(t,e,1,r)}function fa(t,e,r,n){return Tt(t,e,2,ie(t,e+1,n))}function la(t,e,r,n){return Tt(t,e,3,se(t,e+1,n))}function da(t,e,r,n){return Tt(t,e,5,ae(t,e+1,n))}function ha(t,e,r,n){let o=ce(t,e+1,n);if(typeof o=="bigint")throw new Error(`${A} 64-bit integer array lengths not supported`);return Tt(t,e,9,o)}function pa(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${A} indefinite length items not allowed`);return Tt(t,e,1,1/0)}function yn(t,e){$(t,d.array.majorEncoded,e.value)}yn.compareTokens=we.compareTokens;yn.encodedSize=function(e){return $.encodedSize(e.value)};function It(t,e,r,n){return new E(d.map,n,r)}function ma(t,e,r,n){return It(t,e,1,r)}function ya(t,e,r,n){return It(t,e,2,ie(t,e+1,n))}function ga(t,e,r,n){return It(t,e,3,se(t,e+1,n))}function xa(t,e,r,n){return It(t,e,5,ae(t,e+1,n))}function wa(t,e,r,n){let o=ce(t,e+1,n);if(typeof o=="bigint")throw new Error(`${A} 64-bit integer map lengths not supported`);return It(t,e,9,o)}function ba(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${A} indefinite length items not allowed`);return It(t,e,1,1/0)}function gn(t,e){$(t,d.map.majorEncoded,e.value)}gn.compareTokens=we.compareTokens;gn.encodedSize=function(e){return $.encodedSize(e.value)};function Ea(t,e,r,n){return new E(d.tag,r,1)}function _a(t,e,r,n){return new E(d.tag,ie(t,e+1,n),2)}function ka(t,e,r,n){return new E(d.tag,se(t,e+1,n),3)}function va(t,e,r,n){return new E(d.tag,ae(t,e+1,n),5)}function Aa(t,e,r,n){return new E(d.tag,ce(t,e+1,n),9)}function xn(t,e){$(t,d.tag.majorEncoded,e.value)}xn.compareTokens=we.compareTokens;xn.encodedSize=function(e){return $.encodedSize(e.value)};var Lo=20,$o=21,Ro=22,Fo=23;function Ta(t,e,r,n){if(n.allowUndefined===!1)throw new Error(`${A} undefined values are not supported`);return n.coerceUndefinedToNull===!0?new E(d.null,null,1):new E(d.undefined,void 0,1)}function Ia(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${A} indefinite length items not allowed`);return new E(d.break,void 0,1)}function Mo(t,e,r){if(r){if(r.allowNaN===!1&&Number.isNaN(t))throw new Error(`${A} NaN values are not supported`);if(r.allowInfinity===!1&&(t===1/0||t===-1/0))throw new Error(`${A} Infinity values are not supported`)}return new E(d.float,t,e)}function Ba(t,e,r,n){return Mo(Po(t,e+1),3,n)}function Sa(t,e,r,n){return Mo(Oo(t,e+1),5,n)}function Na(t,e,r,n){return Mo(La(t,e+1),9,n)}function mr(t,e,r){let n=e.value;if(n===!1)t.push([d.float.majorEncoded|Lo]);else if(n===!0)t.push([d.float.majorEncoded|$o]);else if(n===null)t.push([d.float.majorEncoded|Ro]);else if(n===void 0)t.push([d.float.majorEncoded|Fo]);else{let o,i=!1;(!r||r.float64!==!0)&&(Ca(n),o=Po(Te,1),n===o||Number.isNaN(n)?(Te[0]=249,t.push(Te.slice(0,3)),i=!0):(Da(n),o=Oo(Te,1),n===o&&(Te[0]=250,t.push(Te.slice(0,5)),i=!0))),i||(yd(n),o=La(Te,1),Te[0]=251,t.push(Te.slice(0,9)))}}mr.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){Ca(n);let o=Po(Te,1);if(n===o||Number.isNaN(n))return 3;if(Da(n),o=Oo(Te,1),n===o)return 5}return 9};var Ua=new ArrayBuffer(9),be=new DataView(Ua,1),Te=new Uint8Array(Ua,0);function Ca(t){if(t===1/0)be.setUint16(0,31744,!1);else if(t===-1/0)be.setUint16(0,64512,!1);else if(Number.isNaN(t))be.setUint16(0,32256,!1);else{be.setFloat32(0,t);let e=be.getUint32(0),r=(e&2139095040)>>23,n=e&8388607;if(r===255)be.setUint16(0,31744,!1);else if(r===0)be.setUint16(0,(e&2147483648)>>16|n>>13,!1);else{let o=r-127;o<-24?be.setUint16(0,0):o<-14?be.setUint16(0,(e&2147483648)>>16|1<<24+o,!1):be.setUint16(0,(e&2147483648)>>16|o+15<<10|n>>13,!1)}}}function Po(t,e){if(t.length-e<2)throw new Error(`${A} not enough data for float16`);let r=(t[e]<<8)+t[e+1];if(r===31744)return 1/0;if(r===64512)return-1/0;if(r===32256)return NaN;let n=r>>10&31,o=r&1023,i;return n===0?i=o*2**-24:n!==31?i=(o+1024)*2**(n-25):i=o===0?1/0:NaN,r&32768?-i:i}function Da(t){be.setFloat32(0,t,!1)}function Oo(t,e){if(t.length-e<4)throw new Error(`${A} not enough data for float32`);let r=(t.byteOffset||0)+e;return new DataView(t.buffer,r,4).getFloat32(0,!1)}function yd(t){be.setFloat64(0,t,!1)}function La(t,e){if(t.length-e<8)throw new Error(`${A} not enough data for float64`);let r=(t.byteOffset||0)+e;return new DataView(t.buffer,r,8).getFloat64(0,!1)}mr.compareTokens=we.compareTokens;function S(t,e,r){throw new Error(`${A} encountered invalid minor (${r}) for major ${t[e]>>>5}`)}function wn(t){return()=>{throw new Error(`${A} ${t}`)}}var y=[];for(let t=0;t<=23;t++)y[t]=S;y[24]=Hs;y[25]=js;y[26]=Vs;y[27]=qs;y[28]=S;y[29]=S;y[30]=S;y[31]=S;for(let t=32;t<=55;t++)y[t]=S;y[56]=Gs;y[57]=Ws;y[58]=Js;y[59]=Qs;y[60]=S;y[61]=S;y[62]=S;y[63]=S;for(let t=64;t<=87;t++)y[t]=Ks;y[88]=Ys;y[89]=Zs;y[90]=ea;y[91]=ta;y[92]=S;y[93]=S;y[94]=S;y[95]=wn("indefinite length bytes/strings are not supported");for(let t=96;t<=119;t++)y[t]=na;y[120]=oa;y[121]=ia;y[122]=sa;y[123]=aa;y[124]=S;y[125]=S;y[126]=S;y[127]=wn("indefinite length bytes/strings are not supported");for(let t=128;t<=151;t++)y[t]=ua;y[152]=fa;y[153]=la;y[154]=da;y[155]=ha;y[156]=S;y[157]=S;y[158]=S;y[159]=pa;for(let t=160;t<=183;t++)y[t]=ma;y[184]=ya;y[185]=ga;y[186]=xa;y[187]=wa;y[188]=S;y[189]=S;y[190]=S;y[191]=ba;for(let t=192;t<=215;t++)y[t]=Ea;y[216]=_a;y[217]=ka;y[218]=va;y[219]=Aa;y[220]=S;y[221]=S;y[222]=S;y[223]=S;for(let t=224;t<=243;t++)y[t]=wn("simple values are not supported");y[244]=S;y[245]=S;y[246]=S;y[247]=Ta;y[248]=wn("simple values are not supported");y[249]=Ba;y[250]=Sa;y[251]=Na;y[252]=S;y[253]=S;y[254]=S;y[255]=Ia;var Ie=[];for(let t=0;t<24;t++)Ie[t]=new E(d.uint,t,1);for(let t=-1;t>=-24;t--)Ie[31-t]=new E(d.negint,t,1);Ie[64]=new E(d.bytes,new Uint8Array(0),1);Ie[96]=new E(d.string,"",1);Ie[128]=new E(d.array,0,1);Ie[160]=new E(d.map,0,1);Ie[244]=new E(d.false,!1,1);Ie[245]=new E(d.true,!0,1);Ie[246]=new E(d.null,null,1);function zo(t){switch(t.type){case d.false:return De([244]);case d.true:return De([245]);case d.null:return De([246]);case d.bytes:return t.value.length?void 0:De([64]);case d.string:return t.value===""?De([96]):void 0;case d.array:return t.value===0?De([128]):void 0;case d.map:return t.value===0?De([160]):void 0;case d.uint:return t.value<24?De([Number(t.value)]):void 0;case d.negint:if(t.value>=-24)return De([31-Number(t.value)])}}var xd={float64:!1,mapSorter:Ed,quickEncodeToken:zo},Pa=Object.freeze({float64:!0,mapSorter:_d,quickEncodeToken:zo});function wd(){let t=[];return t[d.uint.major]=we,t[d.negint.major]=pn,t[d.bytes.major]=At,t[d.string.major]=ca,t[d.array.major]=yn,t[d.map.major]=gn,t[d.tag.major]=xn,t[d.float.major]=mr,t}var Bt=wd(),bn=new lr,gr=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(`${hn} object contains circular references`);return new t(r,e)}},Xe={null:new E(d.null,null),undefined:new E(d.undefined,void 0),true:new E(d.true,!0),false:new E(d.false,!1),emptyArray:new E(d.array,0),emptyMap:new E(d.map,0)},Le={number(t,e,r,n){return!Number.isInteger(t)||!Number.isSafeInteger(t)?new E(d.float,t):t>=0?new E(d.uint,t):new E(d.negint,t)},bigint(t,e,r,n){return t>=BigInt(0)?new E(d.uint,t):new E(d.negint,t)},Uint8Array(t,e,r,n){return new E(d.bytes,t)},string(t,e,r,n){return new E(d.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 E(d.bytes,new Uint8Array(t))},DataView(t,e,r,n){return new E(d.bytes,new Uint8Array(t.buffer,t.byteOffset,t.byteLength))},Array(t,e,r,n){if(!t.length)return r.addBreakTokens===!0?[Xe.emptyArray,new E(d.break)]:Xe.emptyArray;n=gr.createCheck(n,t);let o=[],i=0;for(let s of t)o[i++]=En(s,r,n);return r.addBreakTokens?[new E(d.array,t.length),o,new E(d.break)]:[new E(d.array,t.length),o]},Object(t,e,r,n){let o=e!=="Object",i=o?t.keys():Object.keys(t),s=o?t.size:i.length,a;if(s){a=new Array(s),n=gr.createCheck(n,t);let c=!o&&r.ignoreUndefinedProperties,f=0;for(let l of i){let p=o?t.get(l):t[l];c&&p===void 0||(a[f++]=[En(l,r,n),En(p,r,n)])}f<s&&(a.length=f)}return a?.length?(bd(a,r),r.addBreakTokens?[new E(d.map,a.length),a,new E(d.break)]:[new E(d.map,a.length),a]):r.addBreakTokens===!0?[Xe.emptyMap,new E(d.break)]:Xe.emptyMap}};Le.Map=Le.Object;Le.Buffer=Le.Uint8Array;for(let t of"Uint8Clamped Uint16 Uint32 Int8 Int16 Int32 BigUint64 BigInt64 Float32 Float64".split(" "))Le[`${t}Array`]=Le.DataView;function En(t,e={},r){let n=Co(t),o=e&&e.typeEncoders&&e.typeEncoders[n]||Le[n];if(typeof o=="function"){let s=o(t,n,e,r);if(s!=null)return s}let i=Le[n];if(!i)throw new Error(`${hn} unsupported type: ${n}`);return i(t,n,e,r)}function bd(t,e){e.mapSorter&&t.sort(e.mapSorter)}function Ed(t,e){let r=Array.isArray(t[0])?t[0][0]:t[0],n=Array.isArray(e[0])?e[0][0]:e[0];if(r.type!==n.type)return r.type.compare(n.type);let o=r.type.major,i=Bt[o].compareTokens(r,n);return i===0&&console.warn("WARNING: complex key types used, CBOR key sorting guarantees are gone"),i}function _d(t,e){if(t[0]instanceof E&&e[0]instanceof E){let r=t[0],n=e[0];return r._keyBytes||(r._keyBytes=$a(r.value)),n._keyBytes||(n._keyBytes=$a(n.value)),ln(r._keyBytes,n._keyBytes)}throw new Error("rfc8949MapSorter: complex key types are not supported yet")}function $a(t){return za(t,Bt,Pa)}function yr(t,e,r,n){if(Array.isArray(e))for(let o of e)yr(t,o,r,n);else r[e.type.major](t,e,n)}var Ra=d.uint.majorEncoded,Fa=d.negint.majorEncoded,kd=d.bytes.majorEncoded,vd=d.string.majorEncoded,Ma=d.array.majorEncoded,Ad=d.float.majorEncoded|Lo,Td=d.float.majorEncoded|$o,Id=d.float.majorEncoded|Ro,Bd=d.float.majorEncoded|Fo,Sd=BigInt(-1),Nd=BigInt(1);function Ud(t){return t.addBreakTokens!==!0}function Oa(t,e,r,n){let o=Co(e),i=r.typeEncoders&&r.typeEncoders[o];if(i){let s=i(e,o,r,n);if(s!=null){yr(t,s,Bt,r);return}}switch(o){case"null":t.push([Id]);return;case"undefined":t.push([Bd]);return;case"boolean":t.push([e?Td:Ad]);return;case"number":!Number.isInteger(e)||!Number.isSafeInteger(e)?mr(t,new E(d.float,e),r):e>=0?$(t,Ra,e):$(t,Fa,e*-1-1);return;case"bigint":e>=BigInt(0)?$(t,Ra,e):$(t,Fa,e*Sd-Nd);return;case"string":{let s=fn(e);$(t,vd,s.length),t.push(s);return}case"Uint8Array":$(t,kd,e.length),t.push(e);return;case"Array":if(!e.length){t.push([Ma]);return}n=gr.createCheck(n,e),$(t,Ma,e.length);for(let s of e)Oa(t,s,r,n);return;case"Object":case"Map":{let s=Le.Object(e,o,r,n);yr(t,s,Bt,r)}return;default:{let s=Le[o];if(!s)throw new Error(`${hn} unsupported type: ${o}`);let a=s(e,o,r,n);yr(t,a,Bt,r)}}}function za(t,e,r,n){let o=n instanceof Uint8Array,i=o?new dn(n):bn,s=En(t,r);if(!Array.isArray(s)&&r.quickEncodeToken){let a=r.quickEncodeToken(s);if(a)return o?(i.push(a),i.toBytes()):a;let c=e[s.type.major];if(c.encodedSize){let f=c.encodedSize(s,r);if(o||(i=new lr(f)),c(i,s,r),i.chunks.length!==1)throw new Error(`Unexpected error: pre-calculated length for ${s} was wrong`);return o?i.toBytes():fr(i.chunks[0])}}return i.reset(),yr(i,s,e,r),i.toBytes(!0)}function Ho(t,e){return e=Object.assign({},xd,e),Ud(e)?(bn.reset(),Oa(bn,t,e,void 0),bn.toBytes(!0)):za(t,Bt,e)}var Cd={strict:!1,allowIndefinite:!0,allowUndefined:!0,allowBigInt:!0},_n=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=Ie[e];if(r===void 0){let n=y[e];if(!n)throw new Error(`${A} no decoder for major type ${e>>>5} (byte 0x${e.toString(16).padStart(2,"0")})`);let o=e&31;r=n(this.data,this._pos,o,this.options)}return this._pos+=r.encodedLength,r}},Qe=Symbol.for("DONE"),St=Symbol.for("BREAK");function Dd(t,e,r){let n=[];for(let o=0;o<t.value;o++){let i=Ke(e,r);if(i===St){if(t.value===1/0)break;throw new Error(`${A} got unexpected break to lengthed array`)}if(i===Qe)throw new Error(`${A} found array but not enough entries (got ${o}, expected ${t.value})`);n[o]=i}return n}function Ld(t,e,r){let n=r.useMaps===!0,o=r.rejectDuplicateMapKeys===!0,i=n?void 0:{},s=n?new Map:void 0;for(let a=0;a<t.value;a++){let c=Ke(e,r);if(c===St){if(t.value===1/0)break;throw new Error(`${A} got unexpected break to lengthed map`)}if(c===Qe)throw new Error(`${A} found map but not enough entries (got ${a} [no key], expected ${t.value})`);if(!n&&typeof c!="string")throw new Error(`${A} non-string keys not supported (got ${typeof c})`);if(o&&(n&&s.has(c)||!n&&Object.hasOwn(i,c)))throw new Error(`${A} found repeat map key "${c}"`);let f=Ke(e,r);if(f===Qe)throw new Error(`${A} found map but not enough entries (got ${a} [no value], expected ${t.value})`);n?s.set(c,f):i[c]=f}return n?s:i}function*$d(t,e,r){for(let n=0;n<t.value;n++){let o=Ke(e,r);if(o===St){if(t.value===1/0)break;throw new Error(`${A} got unexpected break to lengthed map`)}if(o===Qe)throw new Error(`${A} found map but not enough entries (got ${n} [no key], expected ${t.value})`);let i=Ke(e,r);if(i===Qe)throw new Error(`${A} found map but not enough entries (got ${n} [no value], expected ${t.value})`);yield[o,i]}}function Rd(t,e){let r=!1,n=function(){if(r)throw new Error(`${A} tag decode() may only be called once`);r=!0;let o=Ke(t,e);if(o===Qe)throw new Error(`${A} tag content missing`);if(o===St)throw new Error(`${A} got unexpected break in tag content`);return o};return n.entries=function(){if(r)throw new Error(`${A} tag decode() may only be called once`);r=!0;let o=t.next();if(!d.equals(o.type,d.map))throw new Error(`${A} entries() requires map content, got ${o.type.name}`);let i=[];for(let s of $d(o,t,e))i.push(s);return i},Object.defineProperty(n,"_called",{get(){return r},enumerable:!1}),n}function Ke(t,e){if(t.done())return Qe;let r=t.next();if(d.equals(r.type,d.break))return St;if(r.type.terminal)return r.value;if(d.equals(r.type,d.array))return Dd(r,t,e);if(d.equals(r.type,d.map))return Ld(r,t,e);if(d.equals(r.type,d.tag)){if(e.tags&&typeof e.tags[r.value]=="function"){let n=Rd(t,e),o=e.tags[r.value](n);if(!n._called)throw new Error(`${A} tag decoder must call decode() or entries()`);return o}throw new Error(`${A} tag not supported (${r.value})`)}throw new Error("unsupported")}function Ha(t,e){if(!(t instanceof Uint8Array))throw new Error(`${A} data to decode must be a Uint8Array`);e=Object.assign({},Cd,e);let r=fr(t),n=e.tokenizer||new _n(r,e),o=Ke(n,e);if(o===Qe)throw new Error(`${A} did not find any content to decode`);if(o===St)throw new Error(`${A} got unexpected break`);return[o,t.subarray(n.pos())]}function jo(t,e){let[r,n]=Ha(t,e);if(n.length>0)throw new Error(`${A} too many terminals, data makes no sense`);return r}var Xo={};oe(Xo,{base32:()=>Ut,base32hex:()=>Wd,base32hexpad:()=>Xd,base32hexpadupper:()=>Qd,base32hexupper:()=>Jd,base32pad:()=>qd,base32padupper:()=>Gd,base32upper:()=>Vd,base32z:()=>Kd});var jg=new Uint8Array(0);function ja(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 Ve(t){if(t instanceof Uint8Array&&t.constructor.name==="Uint8Array")return t;if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.isView(t))return new Uint8Array(t.buffer,t.byteOffset,t.byteLength);throw new Error("Unknown type, must be binary type")}function Va(t){return new TextEncoder().encode(t)}function qa(t){return new TextDecoder().decode(t)}function Md(t,e){if(t.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),n=0;n<r.length;n++)r[n]=255;for(var o=0;o<t.length;o++){var i=t.charAt(o),s=i.charCodeAt(0);if(r[s]!==255)throw new TypeError(i+" is ambiguous");r[s]=o}var a=t.length,c=t.charAt(0),f=Math.log(a)/Math.log(256),l=Math.log(256)/Math.log(a);function p(w){if(w instanceof Uint8Array||(ArrayBuffer.isView(w)?w=new Uint8Array(w.buffer,w.byteOffset,w.byteLength):Array.isArray(w)&&(w=Uint8Array.from(w))),!(w instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(w.length===0)return"";for(var T=0,I=0,R=0,z=w.length;R!==z&&w[R]===0;)R++,T++;for(var P=(z-R)*l+1>>>0,J=new Uint8Array(P);R!==z;){for(var H=w[R],re=0,ne=P-1;(H!==0||re<I)&&ne!==-1;ne--,re++)H+=256*J[ne]>>>0,J[ne]=H%a>>>0,H=H/a>>>0;if(H!==0)throw new Error("Non-zero carry");I=re,R++}for(var He=P-I;He!==P&&J[He]===0;)He++;for(var an=c.repeat(T);He<P;++He)an+=t.charAt(J[He]);return an}function k(w){if(typeof w!="string")throw new TypeError("Expected String");if(w.length===0)return new Uint8Array;var T=0;if(w[T]!==" "){for(var I=0,R=0;w[T]===c;)I++,T++;for(var z=(w.length-T)*f+1>>>0,P=new Uint8Array(z);w[T];){var J=r[w.charCodeAt(T)];if(J===255)return;for(var H=0,re=z-1;(J!==0||H<R)&&re!==-1;re--,H++)J+=a*P[re]>>>0,P[re]=J%256>>>0,J=J/256>>>0;if(J!==0)throw new Error("Non-zero carry");R=H,T++}if(w[T]!==" "){for(var ne=z-R;ne!==z&&P[ne]===0;)ne++;for(var He=new Uint8Array(I+(z-ne)),an=I;ne!==z;)He[an++]=P[ne++];return He}}}function v(w){var T=k(w);if(T)return T;throw new Error(`Non-${e} character`)}return{encode:p,decodeUnsafe:k,decode:v}}var Pd=Md,Od=Pd,Ga=Od;var qo=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")}},Go=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,r,n){this.name=e,this.prefix=r;let o=r.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(e){if(typeof e=="string"){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(e){return Wa(this,e)}},Wo=class{decoders;constructor(e){this.decoders=e}or(e){return Wa(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 Wa(t,e){return new Wo({...t.decoders??{[t.prefix]:t},...e.decoders??{[e.prefix]:e}})}var Jo=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,r,n,o){this.name=e,this.prefix=r,this.baseEncode=n,this.baseDecode=o,this.encoder=new qo(e,r,n),this.decoder=new Go(e,r,o)}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 Jo(t,e,r,n)}function Ye({name:t,prefix:e,alphabet:r}){let{encode:n,decode:o}=Ga(r,t);return Nt({prefix:e,name:t,encode:n,decode:i=>Ve(o(i))})}function zd(t,e,r,n){let o=t.length;for(;t[o-1]==="=";)--o;let i=new Uint8Array(o*r/8|0),s=0,a=0,c=0;for(let f=0;f<o;++f){let l=e[t[f]];if(l===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|l,s+=r,s>=8&&(s-=8,i[c++]=255&a>>s)}if(s>=r||(255&a<<8-s)!==0)throw new SyntaxError("Unexpected end of data");return i}function Hd(t,e,r){let n=e[e.length-1]==="=",o=(1<<r)-1,i="",s=0,a=0;for(let c=0;c<t.length;++c)for(a=a<<8|t[c],s+=8;s>r;)s-=r,i+=e[o&a>>s];if(s!==0&&(i+=e[o&a<<r-s]),n)for(;(i.length*r&7)!==0;)i+="=";return i}function jd(t){let e={};for(let r=0;r<t.length;++r)e[t[r]]=r;return e}function O({name:t,prefix:e,bitsPerChar:r,alphabet:n}){let o=jd(n);return Nt({prefix:e,name:t,encode(i){return Hd(i,n,r)},decode(i){return zd(i,o,r,t)}})}var Ut=O({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Vd=O({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),qd=O({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Gd=O({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Wd=O({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Jd=O({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Xd=O({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Qd=O({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Kd=O({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Qo={};oe(Qo,{base36:()=>xr,base36upper:()=>Yd});var xr=Ye({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Yd=Ye({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Ko={};oe(Ko,{base58btc:()=>$e,base58flickr:()=>Zd});var $e=Ye({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Zd=Ye({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var eh=Qa,Ja=128,th=127,rh=~th,nh=Math.pow(2,31);function Qa(t,e,r){e=e||[],r=r||0;for(var n=r;t>=nh;)e[r++]=t&255|Ja,t/=128;for(;t&rh;)e[r++]=t&255|Ja,t>>>=7;return e[r]=t|0,Qa.bytes=r-n+1,e}var oh=Yo,ih=128,Xa=127;function Yo(t,n){var r=0,n=n||0,o=0,i=n,s,a=t.length;do{if(i>=a)throw Yo.bytes=0,new RangeError("Could not decode varint");s=t[i++],r+=o<28?(s&Xa)<<o:(s&Xa)*Math.pow(2,o),o+=7}while(s>=ih);return Yo.bytes=i-n,r}var sh=Math.pow(2,7),ah=Math.pow(2,14),ch=Math.pow(2,21),uh=Math.pow(2,28),fh=Math.pow(2,35),lh=Math.pow(2,42),dh=Math.pow(2,49),hh=Math.pow(2,56),ph=Math.pow(2,63),mh=function(t){return t<sh?1:t<ah?2:t<ch?3:t<uh?4:t<fh?5:t<lh?6:t<dh?7:t<hh?8:t<ph?9:10},yh={encode:eh,decode:oh,encodingLength:mh},gh=yh,wr=gh;function br(t,e=0){return[wr.decode(t,e),wr.decode.bytes]}function Ct(t,e,r=0){return wr.encode(t,e,r),e}function Dt(t){return wr.encodingLength(t)}function $t(t,e){let r=e.byteLength,n=Dt(t),o=n+Dt(r),i=new Uint8Array(o+r);return Ct(t,i,0),Ct(r,i,n),i.set(e,o),new Lt(t,r,e,i)}function Rt(t){let e=Ve(t),[r,n]=br(e),[o,i]=br(e.subarray(n)),s=e.subarray(n+i);if(s.byteLength!==o)throw new Error("Incorrect length");return new Lt(r,o,s,e)}function Ka(t,e){if(t===e)return!0;{let r=e;return t.code===r.code&&t.size===r.size&&r.bytes instanceof Uint8Array&&ja(t.bytes,r.bytes)}}var Lt=class{code;size;digest;bytes;constructor(e,r,n,o){this.code=e,this.size=r,this.digest=n,this.bytes=o}};function Ya(t,e){let{bytes:r,version:n}=t;switch(n){case 0:return wh(r,Zo(t),e??$e.encoder);default:return bh(r,Zo(t),e??Ut.encoder)}}var Za=new WeakMap;function Zo(t){let e=Za.get(t);if(e==null){let r=new Map;return Za.set(t,r),r}return e}var B=class t{code;version;multihash;bytes;"/";constructor(e,r,n,o){this.code=r,this.version=e,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:e,multihash:r}=this;if(e!==Er)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==Eh)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=$t(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&&Ka(e.multihash,n.multihash)}toString(e){return Ya(this,e)}toJSON(){return{"/":Ya(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(e){if(e==null)return null;let r=e;if(r instanceof t)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:o,multihash:i,bytes:s}=r;return new t(n,o,i,s??ec(n,o,i.bytes))}else if(r[_h]===!0){let{version:n,multihash:o,code:i}=r,s=Rt(o);return t.create(n,i,s)}else return null}static create(e,r,n){if(typeof r!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(e){case 0:{if(r!==Er)throw new Error(`Version 0 CID must use dag-pb (code: ${Er}) block encoding`);return new t(e,r,n,n.bytes)}case 1:{let o=ec(e,r,n.bytes);return new t(e,r,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return t.create(0,Er,e)}static createV1(e,r){return t.create(1,e,r)}static decode(e){let[r,n]=t.decodeFirst(e);if(n.length!==0)throw new Error("Incorrect length");return r}static decodeFirst(e){let r=t.inspectBytes(e),n=r.size-r.multihashSize,o=Ve(e.subarray(n,n+r.multihashSize));if(o.byteLength!==r.multihashSize)throw new Error("Incorrect length");let i=o.subarray(r.multihashSize-r.digestSize),s=new Lt(r.multihashCode,r.digestSize,i,o);return[r.version===0?t.createV0(s):t.createV1(r.codec,s),e.subarray(r.size)]}static inspectBytes(e){let r=0,n=()=>{let[p,k]=br(e.subarray(r));return r+=k,p},o=n(),i=Er;if(o===18?(o=0,r=0):i=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let s=r,a=n(),c=n(),f=r+c,l=f-s;return{version:o,codec:i,multihashCode:a,digestSize:c,multihashSize:l,size:f}}static parse(e,r){let[n,o]=xh(e,r),i=t.decode(o);if(i.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Zo(i).set(n,e),i}};function xh(t,e){switch(t[0]){case"Q":{let r=e??$e;return[$e.prefix,r.decode(`${$e.prefix}${t}`)]}case $e.prefix:{let r=e??$e;return[$e.prefix,r.decode(t)]}case Ut.prefix:{let r=e??Ut;return[Ut.prefix,r.decode(t)]}case xr.prefix:{let r=e??xr;return[xr.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 wh(t,e,r){let{prefix:n}=r;if(n!==$e.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let o=e.get(n);if(o==null){let i=r.encode(t).slice(1);return e.set(n,i),i}else return o}function bh(t,e,r){let{prefix:n}=r,o=e.get(n);if(o==null){let i=r.encode(t);return e.set(n,i),i}else return o}var Er=112,Eh=18;function ec(t,e,r){let n=Dt(t),o=n+Dt(e),i=new Uint8Array(o+r.byteLength);return Ct(t,i,0),Ct(e,i,n),i.set(r,o),i}var _h=Symbol.for("@ipld/js-cid/CID");var tc=42;function kh(t){return t instanceof ArrayBuffer?new Uint8Array(t,0,t.byteLength):t}function vh(t){if(t.asCID!==t&&t["/"]!==t.bytes)return null;let e=B.asCID(t);if(!e)return null;let r=new Uint8Array(e.bytes.byteLength+1);return r.set(e.bytes,1),[new E(d.tag,tc),new E(d.bytes,r)]}function Ah(){throw new Error("`undefined` is not supported by the IPLD Data Model and cannot be encoded")}function Th(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 Ih(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 ei={float64:!0,typeEncoders:{Map:Ih,Object:vh,undefined:Ah,number:Th}},a0={...ei,typeEncoders:{...ei.typeEncoders}};function Bh(t){let e=t();if(e[0]!==0)throw new Error("Invalid CID for CBOR tag 42; expected leading 0x00");return B.decode(e.subarray(1))}var ti={allowIndefinite:!1,coerceUndefinedToNull:!0,allowNaN:!1,allowInfinity:!1,allowBigInt:!0,strict:!0,useMaps:!1,rejectDuplicateMapKeys:!0,tags:{[tc]:Bh}},c0={...ti,tags:{...ti.tags}};var vn=113,ri=t=>Ho(t,ei),dt=t=>jo(kh(t),ti);var ii=vt(An(),1);var si=40;function ai(t,e){if(!t.length)throw new Error("Unexpected end of data");let r=ii.default.decode(t);return e.seek(ii.default.decode.bytes),r}function ci(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 et={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},kr={"CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)":et.Link,"CarV1HeaderOrV2Pragma > roots (anon)":t=>{if(et.List(t)!==void 0){for(let e=0;e<t.length;e++){let r=t[e];if(r=kr["CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)"](r),r===void 0)return;if(r!==t[e]){let n=t.slice(0,e);for(let o=e;o<t.length;o++){let i=t[o];if(i=kr["CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)"](i),i===void 0)return;n.push(i)}return n}}return t}},Int:et.Int,CarV1HeaderOrV2Pragma:t=>{if(et.Map(t)===void 0)return;let e=Object.entries(t),r=t,n=1;for(let o=0;o<e.length;o++){let[i,s]=e[o];switch(i){case"roots":{let a=kr["CarV1HeaderOrV2Pragma > roots (anon)"](t[i]);if(a===void 0)return;if(a!==s||r!==t){if(r===t){r={};for(let c=0;c<o;c++)r[e[c][0]]=e[c][1]}r.roots=a}}break;case"version":{n--;let a=kr.Int(t[i]);if(a===void 0)return;if(a!==s||r!==t){if(r===t){r={};for(let c=0;c<o;c++)r[e[c][0]]=e[c][1]}r.version=a}}break;default:return}}if(!(n>0))return r}},vr={"CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)":et.Link,"CarV1HeaderOrV2Pragma > roots (anon)":t=>{if(et.List(t)!==void 0){for(let e=0;e<t.length;e++){let r=t[e];if(r=vr["CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)"](r),r===void 0)return;if(r!==t[e]){let n=t.slice(0,e);for(let o=e;o<t.length;o++){let i=t[o];if(i=vr["CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)"](i),i===void 0)return;n.push(i)}return n}}return t}},Int:et.Int,CarV1HeaderOrV2Pragma:t=>{if(et.Map(t)===void 0)return;let e=Object.entries(t),r=t,n=1;for(let o=0;o<e.length;o++){let[i,s]=e[o];switch(i){case"roots":{let a=vr["CarV1HeaderOrV2Pragma > roots (anon)"](s);if(a===void 0)return;if(a!==s||r!==t){if(r===t){r={};for(let c=0;c<o;c++)r[e[c][0]]=e[c][1]}r.roots=a}}break;case"version":{n--;let a=vr.Int(s);if(a===void 0)return;if(a!==s||r!==t){if(r===t){r={};for(let c=0;c<o;c++)r[e[c][0]]=e[c][1]}r.version=a}}break;default:return}}if(!(n>0))return r}},ui={toTyped:kr.CarV1HeaderOrV2Pragma,toRepresentation:vr.CarV1HeaderOrV2Pragma};var qh=["Object","RegExp","Date","Error","Map","Set","WeakMap","WeakSet","ArrayBuffer","SharedArrayBuffer","DataView","Promise","URL","HTMLElement","Int8Array","Uint8ClampedArray","Int16Array","Uint16Array","Int32Array","Uint32Array","Float32Array","Float64Array","BigInt64Array","BigUint64Array"];function lc(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=Gh(t);return r||"Object"}function Gh(t){let e=Object.prototype.toString.call(t).slice(8,-1);if(qh.includes(e))return e}var h=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}};h.uint=new h(0,"uint",!0);h.negint=new h(1,"negint",!0);h.bytes=new h(2,"bytes",!0);h.string=new h(3,"string",!0);h.array=new h(4,"array",!1);h.map=new h(5,"map",!1);h.tag=new h(6,"tag",!1);h.float=new h(7,"float",!0);h.false=new h(7,"false",!0);h.true=new h(7,"true",!0);h.null=new h(7,"null",!0);h.undefined=new h(7,"undefined",!0);h.break=new h(7,"break",!0);var b=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 Ar=globalThis.process&&!globalThis.process.browser&&globalThis.Buffer&&typeof globalThis.Buffer.isBuffer=="function",Wh=new TextEncoder;function Tn(t){return Ar&&globalThis.Buffer.isBuffer(t)}function In(t){return t instanceof Uint8Array?Tn(t)?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):t:Uint8Array.from(t)}var Jh=24,Xh=200,fi=Ar?t=>t.length>=Jh?globalThis.Buffer.from(t):dc(t):t=>t.length>=Xh?Wh.encode(t):dc(t),Re=t=>Uint8Array.from(t),hc=Ar?(t,e,r)=>Tn(t)?new Uint8Array(t.subarray(e,r)):t.slice(e,r):(t,e,r)=>t.slice(e,r),pc=Ar?(t,e)=>(t=t.map(r=>r instanceof Uint8Array?r:globalThis.Buffer.from(r)),In(globalThis.Buffer.concat(t,e))):(t,e)=>{let r=new Uint8Array(e),n=0;for(let o of t)n+o.length>r.length&&(o=o.subarray(0,r.length-n)),r.set(o,n),n+=o.length;return r},mc=Ar?t=>globalThis.Buffer.allocUnsafe(t):t=>new Uint8Array(t);function Bn(t,e){if(Tn(t)&&Tn(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 dc(t){let e=[],r=0;for(let n=0;n<t.length;n++){let o=t.charCodeAt(n);o<128?e[r++]=o:o<2048?(e[r++]=o>>6|192,e[r++]=o&63|128):(o&64512)===55296&&n+1<t.length&&(t.charCodeAt(n+1)&64512)===56320?(o=65536+((o&1023)<<10)+(t.charCodeAt(++n)&1023),e[r++]=o>>18|240,e[r++]=o>>12&63|128,e[r++]=o>>6&63|128,e[r++]=o&63|128):(o>=55296&&o<=57343&&(o=65533),e[r++]=o>>12|224,e[r++]=o>>6&63|128,e[r++]=o&63|128)}return e}var Qh=256,Tr=class{constructor(e=Qh){this.chunkSize=e,this.cursor=0,this.maxCursor=-1,this.chunks=[],this._initReuseChunk=null}reset(){this.cursor=0,this.maxCursor=-1,this.chunks.length&&(this.chunks=[]),this._initReuseChunk!==null&&(this.chunks.push(this._initReuseChunk),this.maxCursor=this._initReuseChunk.length-1)}push(e){let r=this.chunks[this.chunks.length-1];if(this.cursor+e.length<=this.maxCursor+1){let o=r.length-(this.maxCursor-this.cursor)-1;r.set(e,o)}else{if(r){let o=r.length-(this.maxCursor-this.cursor)-1;o<r.length&&(this.chunks[this.chunks.length-1]=r.subarray(0,o),this.maxCursor=this.cursor-1)}e.length<64&&e.length<this.chunkSize?(r=mc(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=hc(n,0,this.cursor)}else r=pc(this.chunks,this.cursor);return e&&this.reset(),r}},Sn=class{constructor(e){this.dest=e,this.cursor=0,this.chunks=[e]}reset(){this.cursor=0}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 N="CBOR decode error:",li="CBOR encode error:",Ir=[];Ir[23]=1;Ir[24]=2;Ir[25]=3;Ir[26]=5;Ir[27]=9;function qe(t,e,r){if(t.length-e<r)throw new Error(`${N} not enough data for type`)}var V=[24,256,65536,4294967296,BigInt("18446744073709551616")];function ue(t,e,r){qe(t,e,1);let n=t[e];if(r.strict===!0&&n<V[0])throw new Error(`${N} integer encoded in more bytes than necessary (strict decode)`);return n}function fe(t,e,r){qe(t,e,2);let n=t[e]<<8|t[e+1];if(r.strict===!0&&n<V[1])throw new Error(`${N} integer encoded in more bytes than necessary (strict decode)`);return n}function le(t,e,r){qe(t,e,4);let n=t[e]*16777216+(t[e+1]<<16)+(t[e+2]<<8)+t[e+3];if(r.strict===!0&&n<V[2])throw new Error(`${N} integer encoded in more bytes than necessary (strict decode)`);return n}function de(t,e,r){qe(t,e,8);let n=t[e]*16777216+(t[e+1]<<16)+(t[e+2]<<8)+t[e+3],o=t[e+4]*16777216+(t[e+5]<<16)+(t[e+6]<<8)+t[e+7],i=(BigInt(n)<<BigInt(32))+BigInt(o);if(r.strict===!0&&i<V[3])throw new Error(`${N} integer encoded in more bytes than necessary (strict decode)`);if(i<=Number.MAX_SAFE_INTEGER)return Number(i);if(r.allowBigInt===!0)return i;throw new Error(`${N} integers outside of the safe integer range are not supported`)}function yc(t,e,r,n){return new b(h.uint,ue(t,e+1,n),2)}function gc(t,e,r,n){return new b(h.uint,fe(t,e+1,n),3)}function xc(t,e,r,n){return new b(h.uint,le(t,e+1,n),5)}function wc(t,e,r,n){return new b(h.uint,de(t,e+1,n),9)}function Ee(t,e){return q(t,0,e.value)}function q(t,e,r){if(r<V[0]){let n=Number(r);t.push([e|n])}else if(r<V[1]){let n=Number(r);t.push([e|24,n])}else if(r<V[2]){let n=Number(r);t.push([e|25,n>>>8,n&255])}else if(r<V[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<V[4]){let o=[e|27,0,0,0,0,0,0,0],i=Number(n&BigInt(4294967295)),s=Number(n>>BigInt(32)&BigInt(4294967295));o[8]=i&255,i=i>>8,o[7]=i&255,i=i>>8,o[6]=i&255,i=i>>8,o[5]=i&255,o[4]=s&255,s=s>>8,o[3]=s&255,s=s>>8,o[2]=s&255,s=s>>8,o[1]=s&255,t.push(o)}else throw new Error(`${N} encountered BigInt larger than allowable range`)}}Ee.encodedSize=function(e){return q.encodedSize(e.value)};q.encodedSize=function(e){return e<V[0]?1:e<V[1]?2:e<V[2]?3:e<V[3]?5:9};Ee.compareTokens=function(e,r){return e.value<r.value?-1:e.value>r.value?1:0};function bc(t,e,r,n){return new b(h.negint,-1-ue(t,e+1,n),2)}function Ec(t,e,r,n){return new b(h.negint,-1-fe(t,e+1,n),3)}function _c(t,e,r,n){return new b(h.negint,-1-le(t,e+1,n),5)}var di=BigInt(-1),kc=BigInt(1);function vc(t,e,r,n){let o=de(t,e+1,n);if(typeof o!="bigint"){let i=-1-o;if(i>=Number.MIN_SAFE_INTEGER)return new b(h.negint,i,9)}if(n.allowBigInt!==!0)throw new Error(`${N} integers outside of the safe integer range are not supported`);return new b(h.negint,di-BigInt(o),9)}function Nn(t,e){let r=e.value,n=typeof r=="bigint"?r*di-kc:r*-1-1;q(t,e.type.majorEncoded,n)}Nn.encodedSize=function(e){let r=e.value,n=typeof r=="bigint"?r*di-kc:r*-1-1;return n<V[0]?1:n<V[1]?2:n<V[2]?3:n<V[3]?5:9};Nn.compareTokens=function(e,r){return e.value<r.value?1:e.value>r.value?-1:0};function Br(t,e,r,n){qe(t,e,r+n);let o=t.slice(e+r,e+r+n);return new b(h.bytes,o,r+n)}function Ac(t,e,r,n){return Br(t,e,1,r)}function Tc(t,e,r,n){return Br(t,e,2,ue(t,e+1,n))}function Ic(t,e,r,n){return Br(t,e,3,fe(t,e+1,n))}function Bc(t,e,r,n){return Br(t,e,5,le(t,e+1,n))}function Sc(t,e,r,n){let o=de(t,e+1,n);if(typeof o=="bigint")throw new Error(`${N} 64-bit integer bytes lengths not supported`);return Br(t,e,9,o)}function Un(t){return t.encodedBytes===void 0&&(t.encodedBytes=h.equals(t.type,h.string)?fi(t.value):t.value),t.encodedBytes}function Ft(t,e){let r=Un(e);q(t,e.type.majorEncoded,r.length),t.push(r)}Ft.encodedSize=function(e){let r=Un(e);return q.encodedSize(r.length)+r.length};Ft.compareTokens=function(e,r){return Yh(Un(e),Un(r))};function Yh(t,e){return t.length<e.length?-1:t.length>e.length?1:Bn(t,e)}var Nc=new TextDecoder,ep=32;function tp(t,e,r){if(r-e<ep){let o="";for(let i=e;i<r;i++){let s=t[i];if(s&128)return Nc.decode(t.subarray(e,r));o+=String.fromCharCode(s)}return o}return Nc.decode(t.subarray(e,r))}function Sr(t,e,r,n,o){let i=r+n;qe(t,e,i);let s=new b(h.string,tp(t,e+r,e+i),i);return o.retainStringBytes===!0&&(s.byteValue=t.slice(e+r,e+i)),s}function Uc(t,e,r,n){return Sr(t,e,1,r,n)}function Cc(t,e,r,n){return Sr(t,e,2,ue(t,e+1,n),n)}function Dc(t,e,r,n){return Sr(t,e,3,fe(t,e+1,n),n)}function Lc(t,e,r,n){return Sr(t,e,5,le(t,e+1,n),n)}function $c(t,e,r,n){let o=de(t,e+1,n);if(typeof o=="bigint")throw new Error(`${N} 64-bit integer string lengths not supported`);return Sr(t,e,9,o,n)}var Rc=Ft;function Mt(t,e,r,n){return new b(h.array,n,r)}function Fc(t,e,r,n){return Mt(t,e,1,r)}function Mc(t,e,r,n){return Mt(t,e,2,ue(t,e+1,n))}function Pc(t,e,r,n){return Mt(t,e,3,fe(t,e+1,n))}function Oc(t,e,r,n){return Mt(t,e,5,le(t,e+1,n))}function zc(t,e,r,n){let o=de(t,e+1,n);if(typeof o=="bigint")throw new Error(`${N} 64-bit integer array lengths not supported`);return Mt(t,e,9,o)}function Hc(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${N} indefinite length items not allowed`);return Mt(t,e,1,1/0)}function Cn(t,e){q(t,h.array.majorEncoded,e.value)}Cn.compareTokens=Ee.compareTokens;Cn.encodedSize=function(e){return q.encodedSize(e.value)};function Pt(t,e,r,n){return new b(h.map,n,r)}function jc(t,e,r,n){return Pt(t,e,1,r)}function Vc(t,e,r,n){return Pt(t,e,2,ue(t,e+1,n))}function qc(t,e,r,n){return Pt(t,e,3,fe(t,e+1,n))}function Gc(t,e,r,n){return Pt(t,e,5,le(t,e+1,n))}function Wc(t,e,r,n){let o=de(t,e+1,n);if(typeof o=="bigint")throw new Error(`${N} 64-bit integer map lengths not supported`);return Pt(t,e,9,o)}function Jc(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${N} indefinite length items not allowed`);return Pt(t,e,1,1/0)}function Dn(t,e){q(t,h.map.majorEncoded,e.value)}Dn.compareTokens=Ee.compareTokens;Dn.encodedSize=function(e){return q.encodedSize(e.value)};function Xc(t,e,r,n){return new b(h.tag,r,1)}function Qc(t,e,r,n){return new b(h.tag,ue(t,e+1,n),2)}function Kc(t,e,r,n){return new b(h.tag,fe(t,e+1,n),3)}function Yc(t,e,r,n){return new b(h.tag,le(t,e+1,n),5)}function Zc(t,e,r,n){return new b(h.tag,de(t,e+1,n),9)}function Ln(t,e){q(t,h.tag.majorEncoded,e.value)}Ln.compareTokens=Ee.compareTokens;Ln.encodedSize=function(e){return q.encodedSize(e.value)};var hi=20,pi=21,mi=22,yi=23;function eu(t,e,r,n){if(n.allowUndefined===!1)throw new Error(`${N} undefined values are not supported`);return n.coerceUndefinedToNull===!0?new b(h.null,null,1):new b(h.undefined,void 0,1)}function tu(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${N} indefinite length items not allowed`);return new b(h.break,void 0,1)}function gi(t,e,r){if(r){if(r.allowNaN===!1&&Number.isNaN(t))throw new Error(`${N} NaN values are not supported`);if(r.allowInfinity===!1&&(t===1/0||t===-1/0))throw new Error(`${N} Infinity values are not supported`)}return new b(h.float,t,e)}function ru(t,e,r,n){return gi(xi(t,e+1),3,n)}function nu(t,e,r,n){return gi(wi(t,e+1),5,n)}function ou(t,e,r,n){return gi(cu(t,e+1),9,n)}function $n(t,e,r){let n=e.value;if(n===!1)t.push([h.float.majorEncoded|hi]);else if(n===!0)t.push([h.float.majorEncoded|pi]);else if(n===null)t.push([h.float.majorEncoded|mi]);else if(n===void 0)t.push([h.float.majorEncoded|yi]);else{let o,i=!1;(!r||r.float64!==!0)&&(su(n),o=xi(Be,1),n===o||Number.isNaN(n)?(Be[0]=249,t.push(Be.slice(0,3)),i=!0):(au(n),o=wi(Be,1),n===o&&(Be[0]=250,t.push(Be.slice(0,5)),i=!0))),i||(sp(n),o=cu(Be,1),Be[0]=251,t.push(Be.slice(0,9)))}}$n.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){su(n);let o=xi(Be,1);if(n===o||Number.isNaN(n))return 3;if(au(n),o=wi(Be,1),n===o)return 5}return 9};var iu=new ArrayBuffer(9),_e=new DataView(iu,1),Be=new Uint8Array(iu,0);function su(t){if(t===1/0)_e.setUint16(0,31744,!1);else if(t===-1/0)_e.setUint16(0,64512,!1);else if(Number.isNaN(t))_e.setUint16(0,32256,!1);else{_e.setFloat32(0,t);let e=_e.getUint32(0),r=(e&2139095040)>>23,n=e&8388607;if(r===255)_e.setUint16(0,31744,!1);else if(r===0)_e.setUint16(0,(e&2147483648)>>16|n>>13,!1);else{let o=r-127;o<-24?_e.setUint16(0,0):o<-14?_e.setUint16(0,(e&2147483648)>>16|1<<24+o,!1):_e.setUint16(0,(e&2147483648)>>16|o+15<<10|n>>13,!1)}}}function xi(t,e){if(t.length-e<2)throw new Error(`${N} not enough data for float16`);let r=(t[e]<<8)+t[e+1];if(r===31744)return 1/0;if(r===64512)return-1/0;if(r===32256)return NaN;let n=r>>10&31,o=r&1023,i;return n===0?i=o*2**-24:n!==31?i=(o+1024)*2**(n-25):i=o===0?1/0:NaN,r&32768?-i:i}function au(t){_e.setFloat32(0,t,!1)}function wi(t,e){if(t.length-e<4)throw new Error(`${N} not enough data for float32`);let r=(t.byteOffset||0)+e;return new DataView(t.buffer,r,4).getFloat32(0,!1)}function sp(t){_e.setFloat64(0,t,!1)}function cu(t,e){if(t.length-e<8)throw new Error(`${N} not enough data for float64`);let r=(t.byteOffset||0)+e;return new DataView(t.buffer,r,8).getFloat64(0,!1)}$n.compareTokens=Ee.compareTokens;function U(t,e,r){throw new Error(`${N} encountered invalid minor (${r}) for major ${t[e]>>>5}`)}function Rn(t){return()=>{throw new Error(`${N} ${t}`)}}var x=[];for(let t=0;t<=23;t++)x[t]=U;x[24]=yc;x[25]=gc;x[26]=xc;x[27]=wc;x[28]=U;x[29]=U;x[30]=U;x[31]=U;for(let t=32;t<=55;t++)x[t]=U;x[56]=bc;x[57]=Ec;x[58]=_c;x[59]=vc;x[60]=U;x[61]=U;x[62]=U;x[63]=U;for(let t=64;t<=87;t++)x[t]=Ac;x[88]=Tc;x[89]=Ic;x[90]=Bc;x[91]=Sc;x[92]=U;x[93]=U;x[94]=U;x[95]=Rn("indefinite length bytes/strings are not supported");for(let t=96;t<=119;t++)x[t]=Uc;x[120]=Cc;x[121]=Dc;x[122]=Lc;x[123]=$c;x[124]=U;x[125]=U;x[126]=U;x[127]=Rn("indefinite length bytes/strings are not supported");for(let t=128;t<=151;t++)x[t]=Fc;x[152]=Mc;x[153]=Pc;x[154]=Oc;x[155]=zc;x[156]=U;x[157]=U;x[158]=U;x[159]=Hc;for(let t=160;t<=183;t++)x[t]=jc;x[184]=Vc;x[185]=qc;x[186]=Gc;x[187]=Wc;x[188]=U;x[189]=U;x[190]=U;x[191]=Jc;for(let t=192;t<=215;t++)x[t]=Xc;x[216]=Qc;x[217]=Kc;x[218]=Yc;x[219]=Zc;x[220]=U;x[221]=U;x[222]=U;x[223]=U;for(let t=224;t<=243;t++)x[t]=Rn("simple values are not supported");x[244]=U;x[245]=U;x[246]=U;x[247]=eu;x[248]=Rn("simple values are not supported");x[249]=ru;x[250]=nu;x[251]=ou;x[252]=U;x[253]=U;x[254]=U;x[255]=tu;var Fe=[];for(let t=0;t<24;t++)Fe[t]=new b(h.uint,t,1);for(let t=-1;t>=-24;t--)Fe[31-t]=new b(h.negint,t,1);Fe[64]=new b(h.bytes,new Uint8Array(0),1);Fe[96]=new b(h.string,"",1);Fe[128]=new b(h.array,0,1);Fe[160]=new b(h.map,0,1);Fe[244]=new b(h.false,!1,1);Fe[245]=new b(h.true,!0,1);Fe[246]=new b(h.null,null,1);function bi(t){switch(t.type){case h.false:return Re([244]);case h.true:return Re([245]);case h.null:return Re([246]);case h.bytes:return t.value.length?void 0:Re([64]);case h.string:return t.value===""?Re([96]):void 0;case h.array:return t.value===0?Re([128]):void 0;case h.map:return t.value===0?Re([160]):void 0;case h.uint:return t.value<24?Re([Number(t.value)]):void 0;case h.negint:if(t.value>=-24)return Re([31-Number(t.value)])}}var fu=Object.freeze({float64:!0,mapSorter:lp,quickEncodeToken:bi});function Ei(){let t=[];return t[h.uint.major]=Ee,t[h.negint.major]=Nn,t[h.bytes.major]=Ft,t[h.string.major]=Rc,t[h.array.major]=Cn,t[h.map.major]=Dn,t[h.tag.major]=Ln,t[h.float.major]=$n,t}var cp=Ei(),up=new Tr,Fn=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(`${li} object contains circular references`);return new t(r,e)}},tt={null:new b(h.null,null),undefined:new b(h.undefined,void 0),true:new b(h.true,!0),false:new b(h.false,!1),emptyArray:new b(h.array,0),emptyMap:new b(h.map,0)},rt={number(t,e,r,n){return!Number.isInteger(t)||!Number.isSafeInteger(t)?new b(h.float,t):t>=0?new b(h.uint,t):new b(h.negint,t)},bigint(t,e,r,n){return t>=BigInt(0)?new b(h.uint,t):new b(h.negint,t)},Uint8Array(t,e,r,n){return new b(h.bytes,t)},string(t,e,r,n){return new b(h.string,t)},boolean(t,e,r,n){return t?tt.true:tt.false},null(t,e,r,n){return tt.null},undefined(t,e,r,n){return tt.undefined},ArrayBuffer(t,e,r,n){return new b(h.bytes,new Uint8Array(t))},DataView(t,e,r,n){return new b(h.bytes,new Uint8Array(t.buffer,t.byteOffset,t.byteLength))},Array(t,e,r,n){if(!t.length)return r.addBreakTokens===!0?[tt.emptyArray,new b(h.break)]:tt.emptyArray;n=Fn.createCheck(n,t);let o=[],i=0;for(let s of t)o[i++]=Nr(s,r,n);return r.addBreakTokens?[new b(h.array,t.length),o,new b(h.break)]:[new b(h.array,t.length),o]},Object(t,e,r,n){let o=e!=="Object",i=o?t.keys():Object.keys(t),s=o?t.size:i.length,a;if(s){a=new Array(s),n=Fn.createCheck(n,t);let c=!o&&r.ignoreUndefinedProperties,f=0;for(let l of i){let p=o?t.get(l):t[l];c&&p===void 0||(a[f++]=[Nr(l,r,n),Nr(p,r,n)])}f<s&&(a.length=f)}return a?.length?(fp(a,r),r.addBreakTokens?[new b(h.map,a.length),a,new b(h.break)]:[new b(h.map,a.length),a]):r.addBreakTokens===!0?[tt.emptyMap,new b(h.break)]:tt.emptyMap}};rt.Map=rt.Object;rt.Buffer=rt.Uint8Array;for(let t of"Uint8Clamped Uint16 Uint32 Int8 Int16 Int32 BigUint64 BigInt64 Float32 Float64".split(" "))rt[`${t}Array`]=rt.DataView;function Nr(t,e={},r){let n=lc(t),o=e&&e.typeEncoders&&e.typeEncoders[n]||rt[n];if(typeof o=="function"){let s=o(t,n,e,r);if(s!=null)return s}let i=rt[n];if(!i)throw new Error(`${li} unsupported type: ${n}`);return i(t,n,e,r)}function fp(t,e){e.mapSorter&&t.sort(e.mapSorter)}function lp(t,e){if(t[0]instanceof b&&e[0]instanceof b){let r=t[0],n=e[0];return r._keyBytes||(r._keyBytes=uu(r.value)),n._keyBytes||(n._keyBytes=uu(n.value)),Bn(r._keyBytes,n._keyBytes)}throw new Error("rfc8949MapSorter: complex key types are not supported yet")}function uu(t){return dp(t,cp,fu)}function lu(t,e,r,n){if(Array.isArray(e))for(let o of e)lu(t,o,r,n);else r[e.type.major](t,e,n)}var ux=h.uint.majorEncoded,fx=h.negint.majorEncoded,lx=h.bytes.majorEncoded,dx=h.string.majorEncoded,hx=h.array.majorEncoded,px=h.float.majorEncoded|hi,mx=h.float.majorEncoded|pi,yx=h.float.majorEncoded|mi,gx=h.float.majorEncoded|yi,xx=BigInt(-1),wx=BigInt(1);function dp(t,e,r,n){let o=n instanceof Uint8Array,i=o?new Sn(n):up,s=Nr(t,r);if(!Array.isArray(s)&&r.quickEncodeToken){let a=r.quickEncodeToken(s);if(a)return o?(i.push(a),i.toBytes()):a;let c=e[s.type.major];if(c.encodedSize){let f=c.encodedSize(s,r);if(o||(i=new Tr(f)),c(i,s,r),i.chunks.length!==1)throw new Error(`Unexpected error: pre-calculated length for ${s} was wrong`);return o?i.toBytes():In(i.chunks[0])}}return i.reset(),lu(i,s,e,r),i.toBytes(!0)}var Ax=Symbol.for("DONE"),Tx=Symbol.for("BREAK");var Ox=Ei();var hp=vt(An(),1);var qx=[new b(h.map,2),new b(h.string,"version"),new b(h.uint,1),new b(h.string,"roots")],Gx=new b(h.tag,42);async function _i(t,e){let r=ai(await t.upTo(8),t);if(r===0)throw new Error("Invalid CAR header (zero length)");let n=await t.exactly(r,!0),o=dt(n);if(ui.toTyped(o)===void 0)throw new Error("Invalid CAR header format");if(o.version!==1&&o.version!==2||e!==void 0&&o.version!==e)throw new Error(`Invalid CAR version: ${o.version}${e!==void 0?` (expected ${e})`:""}`);if(o.version===1){if(!Array.isArray(o.roots))throw new Error("Invalid CAR header format");return o}if(o.roots!==void 0)throw new Error("Invalid CAR header format");let i=ci(await t.exactly(si,!0));t.seek(i.dataOffset-t.pos);let s=await _i(t,1);return Object.assign(s,i)}function Ur(t){let e=0;return{async upTo(r){return t.subarray(e,e+Math.min(r,t.length-e))},async exactly(r,n=!1){if(r>t.length-e)throw new Error("Unexpected end of data");let o=t.subarray(e,e+r);return n&&(e+=r),o},seek(r){e+=r},get pos(){return e}}}var ki=vt(An(),1),pu=1;function vi(t){let e=ri({version:pu,roots:t}),r=ki.default.encode(e.length),n=new Uint8Array(r.length+e.length);return n.set(r,0),n.set(e,r.length),n}function mu(t){return{async setRoots(e){let r=vi(e);await t.write(r)},async writeBlock(e){let{cid:r,bytes:n}=e;await t.write(new Uint8Array(ki.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 pu}}}function Mn(){}function yu(){let t=[],e=null,r=Mn,n=!1,o=null,i=Mn,s=()=>(e||(e=new Promise(f=>{r=()=>{e=null,r=Mn,f()}})),e),a={write(f){t.push(f);let l=s();return i(),l},async end(){n=!0;let f=s();i(),await f}},c={async next(){let f=t.shift();return f?(t.length===0&&r(),{done:!1,value:f}):n?(r(),{done:!0,value:void 0}):(o||(o=new Promise(l=>{i=()=>(o=null,i=Mn,l(c.next()))})),o)}};return{writer:a,iterator:c}}var Cr=class t{constructor(e,r){this._encoder=r,this._mutex=r.setRoots(e),this._ended=!1}async put(e){if(!(e.bytes instanceof Uint8Array)||!e.cid)throw new TypeError("Can only write {cid, bytes} objects");if(this._ended)throw new Error("Already closed");let r=B.asCID(e.cid);if(!r)throw new TypeError("Can only write {cid, bytes} objects");return this._mutex=this._mutex.then(()=>this._encoder.writeBlock({cid:r,bytes:e.bytes})),this._mutex}async close(){if(this._ended)throw new Error("Already closed");return await this._mutex,this._ended=!0,this._encoder.close()}version(){return this._encoder.version()}static create(e){e=gp(e);let{encoder:r,iterator:n}=gu(),o=new t(e,r),i=new Pn(n);return{writer:o,out:i}}static createAppender(){let{encoder:e,iterator:r}=gu();e.setRoots=()=>Promise.resolve();let n=new t([],e),o=new Pn(r);return{writer:n,out:o}}static async updateRootsInBytes(e,r){let n=Ur(e);await _i(n);let o=vi(r);if(Number(n.pos)!==o.length)throw new Error(`updateRoots() can only overwrite a header of the same length (old header is ${n.pos} bytes, new header is ${o.length} bytes)`);return e.set(o,0),e}},Pn=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 gu(){let t=yu(),{writer:e,iterator:r}=t;return{encoder:mu(e),iterator:r}}function gp(t){if(t===void 0)return[];if(!Array.isArray(t)){let r=B.asCID(t);if(!r)throw new TypeError("roots must be a single CID or an array of CIDs");return[r]}let e=[];for(let r of t){let n=B.asCID(r);if(!n)throw new TypeError("roots must be a single CID or an array of CIDs");e.push(n)}return e}function xp(t){return t[Symbol.asyncIterator]!=null}function wp(t){if(xp(t))return(async()=>{for await(let e of t);})();for(let e of t);}var Ai=wp;function bp(t){let[e,r]=t[Symbol.asyncIterator]!=null?[t[Symbol.asyncIterator](),Symbol.asyncIterator]:[t[Symbol.iterator](),Symbol.iterator],n=[];return{peek:()=>e.next(),push:o=>{n.push(o)},next:()=>n.length>0?{done:!1,value:n.shift()}:e.next(),[r](){return this}}}var On=bp;function Ep(t){return t[Symbol.asyncIterator]!=null}function _p(t,e){let r=0;if(Ep(t))return(async function*(){for await(let c of t)yield e(c,r++)})();let n=On(t),{value:o,done:i}=n.next();if(i===!0)return(function*(){})();let s=e(o,r++);if(typeof s.then=="function")return(async function*(){yield await s;for(let c of n)yield e(c,r++)})();let a=e;return(function*(){yield s;for(let c of n)yield a(c,r++)})()}var Ot=_p;function kp(t){return t.reason}async function zt(t,e,r){if(e==null)return t;let n=r?.translateError??kp;if(e.aborted)return t.catch(()=>{}),Promise.reject(n(e));let o;try{return await Promise.race([t,new Promise((i,s)=>{o=()=>{s(n(e))},e.addEventListener("abort",o)})])}finally{o!=null&&e.removeEventListener("abort",o)}}var Ge=class extends Error{static name="AbortError";constructor(e="The operation was aborted"){super(e),this.name="AbortError"}};var pt=class extends Error{static name="InvalidParametersError";constructor(e="Invalid parameters"){super(e),this.name="InvalidParametersError"}};var zn=class extends EventTarget{#e=new Map;constructor(){super()}listenerCount(e){let r=this.#e.get(e);return r==null?0:r.length}addEventListener(e,r,n){super.addEventListener(e,r,n);let o=this.#e.get(e);o==null&&(o=[],this.#e.set(e,o)),o.push({callback:r,once:(n!==!0&&n!==!1&&n?.once)??!1})}removeEventListener(e,r,n){super.removeEventListener(e.toString(),r??null,n);let o=this.#e.get(e);o!=null&&(o=o.filter(({callback:i})=>i!==r),this.#e.set(e,o))}dispatchEvent(e){let r=super.dispatchEvent(e),n=this.#e.get(e.type);return n==null||(n=n.filter(({once:o})=>!o),this.#e.set(e.type,n)),r}safeDispatchEvent(e,r={}){return this.dispatchEvent(new CustomEvent(e,r))}};var X=class extends Event{type;detail;constructor(e,r){super(e),this.type=e,this.detail=r}};var Ii=vt(wu(),1);var Bi=class t extends Error{name="TimeoutError";constructor(e,r){super(e,r),Error.captureStackTrace?.(this,t)}},bu=t=>t.reason??new DOMException("This operation was aborted.","AbortError");function Lr(t,e){let{milliseconds:r,fallback:n,message:o,customTimers:i={setTimeout,clearTimeout},signal:s}=e,a,c,l=new Promise((p,k)=>{if(typeof r!="number"||Math.sign(r)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${r}\``);if(s?.aborted){k(bu(s));return}if(s&&(c=()=>{k(bu(s))},s.addEventListener("abort",c,{once:!0})),t.then(p,k),r===Number.POSITIVE_INFINITY)return;let v=new Bi;a=i.setTimeout.call(void 0,()=>{if(n){try{p(n())}catch(w){k(w)}return}typeof t.cancel=="function"&&t.cancel(),o===!1?p():o instanceof Error?k(o):(v.message=o??`Promise timed out after ${r} milliseconds`,k(v))},r)}).finally(()=>{l.clear(),c&&s&&s.removeEventListener("abort",c)});return l.clear=()=>{i.clearTimeout.call(void 0,a),a=void 0},l}function Si(t,e,r){let n=0,o=t.length;for(;o>0;){let i=Math.trunc(o/2),s=n+i;r(t[s],e)<=0?(n=++s,o-=i+1):o=i}return n}var Ht=class{#e=[];enqueue(e,r){let{priority:n=0,id:o}=r??{},i={priority:n,id:o,run:e};if(this.size===0||this.#e[this.size-1].priority>=n){this.#e.push(i);return}let s=Si(this.#e,i,(a,c)=>c.priority-a.priority);this.#e.splice(s,0,i)}setPriority(e,r){let n=this.#e.findIndex(i=>i.id===e);if(n===-1)throw new ReferenceError(`No promise function with the id "${e}" exists in the queue.`);let[o]=this.#e.splice(n,1);this.enqueue(o.run,{priority:r,id:e})}remove(e){let r=this.#e.findIndex(n=>typeof e=="string"?n.id===e:n.run===e);r!==-1&&this.#e.splice(r,1)}dequeue(){return this.#e.shift()?.run}filter(e){return this.#e.filter(r=>r.priority===e.priority).map(r=>r.run)}get size(){return this.#e.length}};var $r=class extends Ii.default{#e;#s;#a=0;#h;#m=!1;#w=!1;#c;#I=0;#b=0;#u;#f;#i;#o=[];#n=0;#t;#B;#r=0;#y;#l;#D=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:Ht,strict:!1,...e},!(typeof e.intervalCap=="number"&&e.intervalCap>=1))throw new TypeError(`Expected \`intervalCap\` to be a number from 1 and up, got \`${e.intervalCap?.toString()??""}\` (${typeof e.intervalCap})`);if(e.interval===void 0||!(Number.isFinite(e.interval)&&e.interval>=0))throw new TypeError(`Expected \`interval\` to be a finite number >= 0, got \`${e.interval?.toString()??""}\` (${typeof e.interval})`);if(e.strict&&e.interval===0)throw new TypeError("The `strict` option requires a non-zero `interval`");if(e.strict&&e.intervalCap===Number.POSITIVE_INFINITY)throw new TypeError("The `strict` option requires a finite `intervalCap`");if(this.#e=e.carryoverIntervalCount??e.carryoverConcurrencyCount??!1,this.#s=e.intervalCap===Number.POSITIVE_INFINITY||e.interval===0,this.#h=e.intervalCap,this.#c=e.interval,this.#i=e.strict,this.#t=new e.queueClass,this.#B=e.queueClass,this.concurrency=e.concurrency,e.timeout!==void 0&&!(Number.isFinite(e.timeout)&&e.timeout>0))throw new TypeError(`Expected \`timeout\` to be a positive finite number, got \`${e.timeout}\` (${typeof e.timeout})`);this.timeout=e.timeout,this.#l=e.autoStart===!1,this.#z()}#_(e){for(;this.#n<this.#o.length;){let n=this.#o[this.#n];if(n!==void 0&&e-n>=this.#c)this.#n++;else break}(this.#n>100&&this.#n>this.#o.length/2||this.#n===this.#o.length)&&(this.#o=this.#o.slice(this.#n),this.#n=0)}#L(e){this.#i?this.#o.push(e):this.#a++}#$(){this.#i?this.#o.length>this.#n&&this.#o.pop():this.#a>0&&this.#a--}#k(){return this.#o.length-this.#n}get#R(){return this.#s?!0:this.#i?this.#k()<this.#h:this.#a<this.#h}get#F(){return this.#r<this.#y}#M(){this.#r--,this.#r===0&&this.emit("pendingZero"),this.#x(),this.emit("next")}#P(){this.#f=void 0,this.#U(),this.#N()}#O(e){if(this.#i){if(this.#_(e),this.#k()>=this.#h){let n=this.#o[this.#n],o=this.#c-(e-n);return this.#v(o),!0}return!1}if(this.#u===void 0){let r=this.#I-e;if(r<0){if(this.#b>0){let n=e-this.#b;if(n<this.#c)return this.#v(this.#c-n),!0}this.#a=this.#e?this.#r:0}else return this.#v(r),!0}return!1}#v(e){this.#f===void 0&&(this.#f=setTimeout(()=>{this.#P()},e))}#A(){this.#u&&(clearInterval(this.#u),this.#u=void 0)}#S(){this.#f&&(clearTimeout(this.#f),this.#f=void 0)}#x(){if(this.#t.size===0){if(this.#A(),this.emit("empty"),this.#r===0){if(this.#S(),this.#i&&this.#n>0){let r=Date.now();this.#_(r)}this.emit("idle")}return!1}let e=!1;if(!this.#l){let r=Date.now(),n=!this.#O(r);if(this.#R&&this.#F){let o=this.#t.dequeue();this.#s||(this.#L(r),this.#p()),this.emit("active"),o(),n&&this.#N(),e=!0}}return e}#N(){this.#s||this.#u!==void 0||this.#i||(this.#u=setInterval(()=>{this.#U()},this.#c),this.#I=Date.now()+this.#c)}#U(){this.#i||(this.#a===0&&this.#r===0&&this.#u&&this.#A(),this.#a=this.#e?this.#r:0),this.#T(),this.#p()}#T(){for(;this.#x(););}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.#T()}setPriority(e,r){if(typeof r!="number"||!Number.isFinite(r))throw new TypeError(`Expected \`priority\` to be a finite number, got \`${r}\` (${typeof r})`);this.#t.setPriority(e,r)}async add(e,r={}){return r={timeout:this.timeout,...r,id:r.id??(this.#D++).toString()},new Promise((n,o)=>{let i=Symbol(`task-${r.id}`),s=()=>{},a=async()=>{s(),this.#r++,this.#g.set(i,{id:r.id,priority:r.priority??0,startTime:Date.now(),timeout:r.timeout});let f;try{try{r.signal?.throwIfAborted()}catch(k){throw this.#H(),this.#g.delete(i),k}this.#b=Date.now();let l=e({signal:r.signal});if(r.timeout&&(l=Lr(Promise.resolve(l),{milliseconds:r.timeout,message:`Task timed out after ${r.timeout}ms (queue has ${this.#r} running, ${this.#t.size} waiting)`})),r.signal){let{signal:k}=r;l=Promise.race([l,new Promise((v,w)=>{f=()=>{w(k.reason)},k.addEventListener("abort",f,{once:!0})})])}let p=await l;n(p),this.emit("completed",p)}catch(l){o(l),this.emit("error",l)}finally{f&&r.signal?.removeEventListener("abort",f),this.#g.delete(i),queueMicrotask(()=>{this.#M()})}};this.#t.enqueue(a,r);let c=()=>{if(this.#t instanceof Ht){this.#t.remove(a);return}this.#t.remove?.(r.id)};if(r.signal){let{signal:f}=r,l=()=>{s(),c(),o(f.reason),this.#x(),this.emit("next")};if(s=()=>{f.removeEventListener("abort",l),this.#E.delete(s)},f.aborted){l();return}f.addEventListener("abort",l,{once:!0}),this.#E.add(s)}this.emit("add"),this.#x()})}async addAll(e,r){return Promise.all(e.map(async n=>this.add(n,r)))}start(){return this.#l?(this.#l=!1,this.#T(),this):this}pause(){this.#l=!0}clear(){for(let e of this.#E)e();this.#t=new this.#B,this.#A(),this.#C(),this.emit("empty"),this.#r===0&&(this.#S(),this.emit("idle")),this.emit("next")}async onEmpty(){this.#t.size!==0&&await this.#d("empty")}async onSizeLessThan(e){this.#t.size<e||await this.#d("next",()=>this.#t.size<e)}async onIdle(){this.#r===0&&this.#t.size===0||await this.#d("idle")}async onPendingZero(){this.#r!==0&&await this.#d("pendingZero")}async onRateLimit(){this.isRateLimited||await this.#d("rateLimit")}async onRateLimitCleared(){this.isRateLimited&&await this.#d("rateLimitCleared")}onError(){return new Promise((e,r)=>{let n=o=>{this.off("error",n),r(o)};this.on("error",n)})}async#d(e,r){return new Promise(n=>{let o=()=>{r&&!r()||(this.off(e,o),n())};this.on(e,o)})}get size(){return this.#t.size}sizeBy(e){return this.#t.filter(e).length}get pending(){return this.#r}get isPaused(){return this.#l}#z(){this.#s||(this.on("add",()=>{this.#t.size>0&&this.#p()}),this.on("next",()=>{this.#p()}))}#p(){this.#s||this.#w||(this.#w=!0,queueMicrotask(()=>{this.#w=!1,this.#C()}))}#H(){this.#s||(this.#$(),this.#p())}#C(){let e=this.#m;if(this.#s||this.#t.size===0){e&&(this.#m=!1,this.emit("rateLimitCleared"));return}let r;if(this.#i){let o=Date.now();this.#_(o),r=this.#k()}else r=this.#a;let n=r>=this.#h;n!==e&&(this.#m=n,this.emit(n?"rateLimit":"rateLimitCleared"))}get isRateLimited(){return this.#m}get isSaturated(){return this.#r===this.#y&&this.#t.size>0||this.isRateLimited&&this.#t.size>0}get runningTasks(){return[...this.#g.values()].map(e=>({...e}))}};var Ni={};oe(Ni,{base10:()=>Tp});var Tp=Ye({prefix:"9",name:"base10",alphabet:"0123456789"});var Ui={};oe(Ui,{base16:()=>Ip,base16upper:()=>Bp});var Ip=O({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Bp=O({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Ci={};oe(Ci,{base2:()=>Sp});var Sp=O({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Di={};oe(Di,{base256emoji:()=>Lp});var Eu=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}"),Np=Eu.reduce((t,e,r)=>(t[r]=e,t),[]),Up=Eu.reduce((t,e,r)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return t[n]=r,t},[]);function Cp(t){return t.reduce((e,r)=>(e+=Np[r],e),"")}function Dp(t){let e=[];for(let r of t){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=Up[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);e.push(o)}return new Uint8Array(e)}var Lp=Nt({prefix:"\u{1F680}",name:"base256emoji",encode:Cp,decode:Dp});var $i={};oe($i,{base64:()=>Li,base64pad:()=>$p,base64url:()=>Rp,base64urlpad:()=>Fp});var Li=O({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),$p=O({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Rp=O({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Fp=O({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Ri={};oe(Ri,{base8:()=>Mp});var Mp=O({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Fi={};oe(Fi,{identity:()=>Pp});var Pp=Nt({prefix:"\0",name:"identity",encode:t=>qa(t),decode:t=>Va(t)});var rb=new TextEncoder,Op=new TextDecoder;var jn=512;function Vn(t){return JSON.parse(Op.decode(t))}var Vt=85;var Mi={};oe(Mi,{identity:()=>Fr});var _u=0,zp="identity",ku=Ve;function Hp(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 $t(_u,ku(t))}var Fr={code:_u,name:zp,encode:ku,digest:Hp};var Oi={};oe(Oi,{sha256:()=>Vp,sha512:()=>qp});var jp=20;function mt({name:t,code:e,encode:r,minDigestLength:n,maxDigestLength:o}){return new Pi(t,e,r,n,o)}var Pi=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,r,n,o,i){this.name=e,this.code=r,this.encode=n,this.minDigestLength=o??jp,this.maxDigestLength=i}digest(e,r){if(r?.truncate!=null){if(r.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&r.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(e instanceof Uint8Array){let n=this.encode(e);return n instanceof Uint8Array?vu(n,this.code,r?.truncate):n.then(o=>vu(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function vu(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 $t(e,t)}function Tu(t){return async e=>new Uint8Array(await crypto.subtle.digest(t,e))}var Vp=mt({name:"sha2-256",code:18,encode:Tu("SHA-256")}),qp=mt({name:"sha2-512",code:19,encode:Tu("SHA-512")});var zi={...Fi,...Ci,...Ri,...Ni,...Ui,...Xo,...Qo,...Ko,...$i,...Di},mb={...Oi,...Mi};function Me(t=0){return new Uint8Array(t)}function Bu(t,e,r,n){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:r},decoder:{decode:n}}}var Iu=Bu("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),Hi=Bu("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=Me(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}),Gp={utf8:Iu,"utf-8":Iu,hex:zi.base16,latin1:Hi,ascii:Hi,binary:Hi,...zi},ji=Gp;var Xp=vt(Nu(),1);var jt;(function(t){t[t.A=1]="A",t[t.CNAME=5]="CNAME",t[t.TXT=16]="TXT",t[t.AAAA=28]="AAAA"})(jt||(jt={}));function Mr(t,e){e==null&&(e=t.reduce((o,i)=>o+i.length,0));let r=Me(e),n=0;for(let o of t)r.set(o,n),n+=o.length;return r}function Gn(t,e="utf8"){let r=ji[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.decoder.decode(`${r.prefix}${t}`)}var Qp=Math.pow(2,7),Kp=Math.pow(2,14),Yp=Math.pow(2,21),Uu=Math.pow(2,28),Cu=Math.pow(2,35),Du=Math.pow(2,42),Lu=Math.pow(2,49),te=128,nt=127;function Pr(t){if(t<Qp)return 1;if(t<Kp)return 2;if(t<Yp)return 3;if(t<Uu)return 4;if(t<Cu)return 5;if(t<Du)return 6;if(t<Lu)return 7;if(Number.MAX_SAFE_INTEGER!=null&&t>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function $u(t,e,r=0){switch(Pr(t)){case 8:e[r++]=t&255|te,t/=128;case 7:e[r++]=t&255|te,t/=128;case 6:e[r++]=t&255|te,t/=128;case 5:e[r++]=t&255|te,t/=128;case 4:e[r++]=t&255|te,t>>>=7;case 3:e[r++]=t&255|te,t>>>=7;case 2:e[r++]=t&255|te,t>>>=7;case 1:{e[r++]=t&255,t>>>=7;break}default:throw new Error("unreachable")}return e}function Ru(t,e){let r=t[e],n=0;if(n+=r&nt,r<te||(r=t[e+1],n+=(r&nt)<<7,r<te)||(r=t[e+2],n+=(r&nt)<<14,r<te)||(r=t[e+3],n+=(r&nt)<<21,r<te)||(r=t[e+4],n+=(r&nt)*Uu,r<te)||(r=t[e+5],n+=(r&nt)*Cu,r<te)||(r=t[e+6],n+=(r&nt)*Du,r<te)||(r=t[e+7],n+=(r&nt)*Lu,r<te))return n;throw new RangeError("Could not decode varint")}function K(){let t={};return t.promise=new Promise((e,r)=>{t.resolve=e,t.reject=r}),t}var Wn=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}},qt=class{size;hwm;head;tail;constructor(e={}){this.hwm=e.splitLimit??16,this.head=new Wn(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 Wn(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 Vi=class extends Error{type;code;constructor(e,r){super(e??"The operation was aborted"),this.type="aborted",this.code=r??"ABORT_ERR"}};function Gt(t={}){return Zp(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 Zp(t,e){e=e??{};let r=e.onEnd,n=new qt,o,i,s,a=K(),c=async()=>{try{return n.isEmpty()?s?{done:!0}:await new Promise((I,R)=>{i=z=>{i=null,n.push(z);try{I(t(n))}catch(P){R(P)}return o}}):t(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=K()})}},f=I=>i!=null?i(I):(n.push(I),o),l=I=>(n=new qt,i!=null?i({error:I}):(n.push({error:I}),o)),p=I=>{if(s)return o;if(e?.objectMode!==!0&&I?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return f({done:!1,value:I})},k=I=>s?o:(s=!0,I!=null?l(I):f({done:!0})),v=()=>(n=new qt,k(),{done:!0}),w=I=>(k(I),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:c,return:v,throw:w,push:p,end:k,get readableLength(){return n.size},onEmpty:async I=>{let R=I?.signal;if(R?.throwIfAborted(),n.isEmpty())return;let z,P;R!=null&&(z=new Promise((J,H)=>{P=()=>{H(new Vi)},R.addEventListener("abort",P)}));try{await Promise.race([a.promise,z])}finally{P!=null&&R!=null&&R?.removeEventListener("abort",P)}}},r==null)return o;let T=o;return o={[Symbol.asyncIterator](){return this},next(){return T.next()},throw(I){return T.throw(I),r!=null&&(r(I),r=void 0),{done:!0}},return(){return T.return(),r!=null&&(r(),r=void 0),{done:!0}},push:p,end(I){return T.end(I),r!=null&&(r(I),r=void 0),o},get readableLength(){return T.readableLength},onEmpty:I=>T.onEmpty(I)},o}var em=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 tm(t,e,r){let n,o=new Promise((i,s)=>{if(r={rejectionEvents:["error"],multiArgs:!1,rejectionMultiArgs:!1,resolveImmediately:!1,...r},!(r.count>=0&&(r.count===Number.POSITIVE_INFINITY||Number.isInteger(r.count))))throw new TypeError("The `count` option should be at least 0 or more");r.signal?.throwIfAborted();let a=[e].flat(),c=[],{addListener:f,removeListener:l}=em(t),p=async(...v)=>{let w=r.multiArgs?v:v[0];if(r.filter)try{if(!await r.filter(w))return}catch(T){n(),s(T);return}c.push(w),r.count===c.length&&(n(),i(c))},k=(...v)=>{n(),s(r.rejectionMultiArgs?v:v[0])};n=()=>{for(let v of a)l(v,p);for(let v of r.rejectionEvents)a.includes(v)||l(v,k)};for(let v of a)f(v,p);for(let v of r.rejectionEvents)a.includes(v)||f(v,k);r.signal&&r.signal.addEventListener("abort",()=>{k(r.signal.reason)},{once:!0}),r.resolveImmediately&&i(c)});if(o.cancel=n,typeof r.timeout=="number"){let i=Lr(o,{milliseconds:r.timeout});return i.cancel=()=>{n(),i.clear()},i}return o}function Jn(t,e,r){typeof r=="function"&&(r={filter:r}),r={...r,count:1,resolveImmediately:!1};let n=tm(t,e,r),o=n.then(i=>i[0]);return o.cancel=n.cancel,o}function qi(t,e){let r,n=function(){let o=function(){r=void 0,t()};clearTimeout(r),r=setTimeout(o,e)};return n.start=()=>{},n.stop=()=>{clearTimeout(r)},n}var Xn=class extends Error{static name="QueueFullError";constructor(e="The queue was full"){super(e),this.name="QueueFullError"}};var Qn=class{deferred;signal;constructor(e){this.signal=e,this.deferred=K(),this.onAbort=this.onAbort.bind(this),this.signal?.addEventListener("abort",this.onAbort)}onAbort(){this.deferred.reject(this.signal?.reason??new Ge)}cleanup(){this.signal?.removeEventListener("abort",this.onAbort)}};function rm(){return`${parseInt(String(Math.random()*1e9),10).toString()}${Date.now()}`}var Kn=class{id;fn;options;recipients;status;timeline;controller;constructor(e,r){this.id=rm(),this.status="queued",this.fn=e,this.options=r,this.recipients=[],this.timeline={created:Date.now()},this.controller=new AbortController,this.controller.signal,this.onAbort=this.onAbort.bind(this)}abort(e){this.controller.abort(e)}onAbort(){this.recipients.reduce((r,n)=>r&&n.signal?.aborted===!0,!0)&&(this.controller.abort(new Ge),this.cleanup())}async join(e={}){let r=new Qn(e.signal);return this.recipients.push(r),e.signal?.addEventListener("abort",this.onAbort),r.deferred.promise}async run(){this.status="running",this.timeline.started=Date.now();try{this.controller.signal.throwIfAborted();let e=await zt(this.fn({...this.options??{},signal:this.controller.signal}),this.controller.signal);this.recipients.forEach(r=>{r.deferred.resolve(e)}),this.status="complete"}catch(e){this.recipients.forEach(r=>{r.deferred.reject(e)}),this.status="errored"}finally{this.timeline.finished=Date.now(),this.cleanup()}}cleanup(){this.recipients.forEach(e=>{e.cleanup(),e.signal?.removeEventListener("abort",this.onAbort)})}};var Wt=class extends zn{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=qi(this.emitEmpty.bind(this),1),this.emitIdle=qi(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 Xn;let n=new Kn(e,r);return this.enqueue(n),this.safeDispatchEvent("add"),this.tryToStartAnother(),n.join(r).then(o=>(this.safeDispatchEvent("completed",{detail:o}),this.safeDispatchEvent("success",{detail:{job:n,result:o}}),o)).catch(o=>{if(n.status==="queued"){for(let i=0;i<this.queue.length;i++)if(this.queue[i]===n){this.queue.splice(i,1);break}}throw this.safeDispatchEvent("failure",{detail:{job:n,error:o}}),o})}clear(){this.queue.splice(0,this.queue.length)}abort(){this.queue.forEach(e=>{e.abort(new Ge)}),this.clear()}async onEmpty(e){this.size!==0&&await Jn(this,"empty",e)}async onSizeLessThan(e,r){this.size<e||await Jn(this,"next",{...r,filter:()=>this.size<e})}async onIdle(e){this.pending===0&&this.size===0||await Jn(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=Gt({objectMode:!0}),n=c=>{c!=null?this.abort():this.clear(),r.end(c)},o=c=>{c.detail!=null&&r.push(c.detail)},i=c=>{n(c.detail.error)},s=()=>{n()},a=()=>{n(new Ge("Queue aborted"))};this.addEventListener("completed",o),this.addEventListener("failure",i),this.addEventListener("idle",s),e?.signal?.addEventListener("abort",a);try{yield*r}finally{this.removeEventListener("completed",o),this.removeEventListener("failure",i),this.removeEventListener("idle",s),e?.signal?.removeEventListener("abort",a),n()}}};function Fu(t){let e=new globalThis.AbortController;function r(){let i=t.filter(s=>s?.aborted===!0).map(s=>s?.reason).pop();e.abort(i);for(let s of t)s?.removeEventListener!=null&&s.removeEventListener("abort",r)}for(let i of t){if(i?.aborted===!0){r();break}i?.addEventListener!=null&&i.addEventListener("abort",r)}function n(){for(let i of t)i?.removeEventListener!=null&&i.removeEventListener("abort",r)}let o=e.signal;return o.clear=n,o}var Gi=class{readNext;haveNext;ended;nextResult;error;constructor(){this.ended=!1,this.readNext=K(),this.haveNext=K()}[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=K(),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=K(),await zt(this.readNext.promise,r?.signal,r)}};function Mu(){return new Gi}function nm(t){return t[Symbol.asyncIterator]!=null}async function om(t,e,r){try{await Promise.all(t.map(async n=>{for await(let o of n)await e.push(o,{signal:r}),r.throwIfAborted()})),await e.end(void 0,{signal:r})}catch(n){await e.end(n,{signal:r}).catch(()=>{})}}async function*im(t){let e=new AbortController,r=Mu();om(t,r,e.signal).catch(()=>{});try{yield*r}finally{e.abort()}}function*sm(t){for(let e of t)yield*e}function am(...t){let e=[];for(let r of t)nm(r)||e.push(r);return e.length===t.length?sm(e):im(t)}var Pu=am;function Yn(t,...e){if(t==null)throw new Error("Empty pipeline");if(Wi(t)){let n=t;t=()=>n.source}else if(zu(t)||Ou(t)){let n=t;t=()=>n}let r=[t,...e];if(r.length>1&&Wi(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++)Wi(r[n])&&(r[n]=um(r[n]));return cm(...r)}var cm=(...t)=>{let e;for(;t.length>0;)e=t.shift()(e);return e},Ou=t=>t?.[Symbol.asyncIterator]!=null,zu=t=>t?.[Symbol.iterator]!=null,Wi=t=>t==null?!1:t.sink!=null&&t.source!=null,um=t=>e=>{let r=t.sink(e);if(r?.then!=null){let n=Gt({objectMode:!0});r.then(()=>{n.end()},s=>{n.end(s)});let o,i=t.source;if(Ou(i))o=async function*(){yield*i,n.end()};else if(zu(i))o=function*(){yield*i,n.end()};else throw new Error("Unknown duplex source type - must be Iterable or AsyncIterable");return Pu(n,o())}return t.source};function fm(t){return t[Symbol.asyncIterator]!=null}function lm(t){if(fm(t))return(async()=>{let n=new Uint8Array(0);for await(let o of t)n=Mr([n,o],n.length+o.length);return n})();let e=[],r=0;for(let n of t)e.push(n),r+=n.byteLength;return Mr(e,r)}var C=lm;function Zn({enumerable:t=!0,configurable:e=!1}={}){return{enumerable:t,configurable:e,writable:!1}}function*dm(t,e){if(e!=null&&typeof e=="object")if(Array.isArray(e))for(let[r,n]of e.entries()){let o=[...t,r],i=B.asCID(n);i!=null?yield[o.join("/"),i]:typeof n=="object"&&(yield*Ji(n,o))}else{let r=B.asCID(e);r!=null?yield[t.join("/"),r]:yield*Ji(e,t)}}function*Ji(t,e){if(t==null||t instanceof Uint8Array)return;let r=B.asCID(t);r!=null&&(yield[e.join("/"),r]);for(let[n,o]of Object.entries(t)){let i=[...e,n];yield*dm(i,o)}}function*hm(t,e){if(Array.isArray(e))for(let[r,n]of e.entries()){let o=[...t,r];yield o.join("/"),typeof n=="object"&&B.asCID(n)==null&&(yield*Xi(n,o))}else yield*Xi(e,t)}function*Xi(t,e){if(!(t==null||typeof t!="object"))for(let[r,n]of Object.entries(t)){let o=[...e,r];yield o.join("/"),n!=null&&!(n instanceof Uint8Array)&&typeof n=="object"&&B.asCID(n)==null&&(yield*hm(o,n))}}function pm(t,e){let r=t;for(let[n,o]of e.entries()){if(r=r[o],r==null)throw new Error(`Object has no property at ${e.slice(0,n+1).map(s=>`[${JSON.stringify(s)}]`).join("")}`);let i=B.asCID(r);if(i!=null)return{value:i,remaining:e.slice(n+1).join("/")}}return{value:r}}var Qi=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:Zn(),bytes:Zn(),value:Zn(),asBlock:Zn()})}links(){return Ji(this.value,[])}tree(){return Xi(this.value,[])}get(e="/"){return pm(this.value,e.split("/").filter(Boolean))}};function Pe({bytes:t,cid:e,value:r,codec:n}){let o=r!==void 0?r:n?.decode(t);if(o===void 0)throw new Error('Missing required argument, must either provide "value" or "codec"');return new Qi({cid:e,bytes:t,value:o})}var mm=["Object","RegExp","Date","Error","Map","Set","WeakMap","WeakSet","ArrayBuffer","SharedArrayBuffer","DataView","Promise","URL","HTMLElement","Int8Array","Uint8ClampedArray","Int16Array","Uint16Array","Int32Array","Uint32Array","Float32Array","Float64Array","BigInt64Array","BigUint64Array"];function Hu(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=ym(t);return r||"Object"}function ym(t){let e=Object.prototype.toString.call(t).slice(8,-1);if(mm.includes(e))return e}var u=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}};u.uint=new u(0,"uint",!0);u.negint=new u(1,"negint",!0);u.bytes=new u(2,"bytes",!0);u.string=new u(3,"string",!0);u.array=new u(4,"array",!1);u.map=new u(5,"map",!1);u.tag=new u(6,"tag",!1);u.float=new u(7,"float",!0);u.false=new u(7,"false",!0);u.true=new u(7,"true",!0);u.null=new u(7,"null",!0);u.undefined=new u(7,"undefined",!0);u.break=new u(7,"break",!0);var m=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 Or=globalThis.process&&!globalThis.process.browser&&globalThis.Buffer&&typeof globalThis.Buffer.isBuffer=="function",gm=new TextEncoder;function eo(t){return Or&&globalThis.Buffer.isBuffer(t)}function yt(t){return t instanceof Uint8Array?eo(t)?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):t:Uint8Array.from(t)}var xm=24,wm=200,zr=Or?t=>t.length>=xm?globalThis.Buffer.from(t):ju(t):t=>t.length>=wm?gm.encode(t):ju(t),Oe=t=>Uint8Array.from(t),qu=Or?(t,e,r)=>eo(t)?new Uint8Array(t.subarray(e,r)):t.slice(e,r):(t,e,r)=>t.slice(e,r),Gu=Or?(t,e)=>(t=t.map(r=>r instanceof Uint8Array?r:globalThis.Buffer.from(r)),yt(globalThis.Buffer.concat(t,e))):(t,e)=>{let r=new Uint8Array(e),n=0;for(let o of t)n+o.length>r.length&&(o=o.subarray(0,r.length-n)),r.set(o,n),n+=o.length;return r},Wu=Or?t=>globalThis.Buffer.allocUnsafe(t):t=>new Uint8Array(t);function to(t,e){if(eo(t)&&eo(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 ju(t){let e=[],r=0;for(let n=0;n<t.length;n++){let o=t.charCodeAt(n);o<128?e[r++]=o:o<2048?(e[r++]=o>>6|192,e[r++]=o&63|128):(o&64512)===55296&&n+1<t.length&&(t.charCodeAt(n+1)&64512)===56320?(o=65536+((o&1023)<<10)+(t.charCodeAt(++n)&1023),e[r++]=o>>18|240,e[r++]=o>>12&63|128,e[r++]=o>>6&63|128,e[r++]=o&63|128):(o>=55296&&o<=57343&&(o=65533),e[r++]=o>>12|224,e[r++]=o>>6&63|128,e[r++]=o&63|128)}return e}var Vu=4096;function Ju(t){let e=t.length;if(e<=Vu)return String.fromCharCode.apply(String,t);let r="",n=0;for(;n<e;)r+=String.fromCharCode.apply(String,t.slice(n,n+=Vu));return r}var bm=256,Hr=class{constructor(e=bm){this.chunkSize=e,this.cursor=0,this.maxCursor=-1,this.chunks=[],this._initReuseChunk=null}reset(){this.cursor=0,this.maxCursor=-1,this.chunks.length&&(this.chunks=[]),this._initReuseChunk!==null&&(this.chunks.push(this._initReuseChunk),this.maxCursor=this._initReuseChunk.length-1)}push(e){let r=this.chunks[this.chunks.length-1];if(this.cursor+e.length<=this.maxCursor+1){let o=r.length-(this.maxCursor-this.cursor)-1;r.set(e,o)}else{if(r){let o=r.length-(this.maxCursor-this.cursor)-1;o<r.length&&(this.chunks[this.chunks.length-1]=r.subarray(0,o),this.maxCursor=this.cursor-1)}e.length<64&&e.length<this.chunkSize?(r=Wu(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=qu(n,0,this.cursor)}else r=Gu(this.chunks,this.cursor);return e&&this.reset(),r}},ro=class{constructor(e){this.dest=e,this.cursor=0,this.chunks=[e]}reset(){this.cursor=0}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 _="CBOR decode error:",Jt="CBOR encode error:",jr=[];jr[23]=1;jr[24]=2;jr[25]=3;jr[26]=5;jr[27]=9;function We(t,e,r){if(t.length-e<r)throw new Error(`${_} not enough data for type`)}var G=[24,256,65536,4294967296,BigInt("18446744073709551616")];function he(t,e,r){We(t,e,1);let n=t[e];if(r.strict===!0&&n<G[0])throw new Error(`${_} integer encoded in more bytes than necessary (strict decode)`);return n}function pe(t,e,r){We(t,e,2);let n=t[e]<<8|t[e+1];if(r.strict===!0&&n<G[1])throw new Error(`${_} integer encoded in more bytes than necessary (strict decode)`);return n}function me(t,e,r){We(t,e,4);let n=t[e]*16777216+(t[e+1]<<16)+(t[e+2]<<8)+t[e+3];if(r.strict===!0&&n<G[2])throw new Error(`${_} integer encoded in more bytes than necessary (strict decode)`);return n}function ye(t,e,r){We(t,e,8);let n=t[e]*16777216+(t[e+1]<<16)+(t[e+2]<<8)+t[e+3],o=t[e+4]*16777216+(t[e+5]<<16)+(t[e+6]<<8)+t[e+7],i=(BigInt(n)<<BigInt(32))+BigInt(o);if(r.strict===!0&&i<G[3])throw new Error(`${_} integer encoded in more bytes than necessary (strict decode)`);if(i<=Number.MAX_SAFE_INTEGER)return Number(i);if(r.allowBigInt===!0)return i;throw new Error(`${_} integers outside of the safe integer range are not supported`)}function Xu(t,e,r,n){return new m(u.uint,he(t,e+1,n),2)}function Qu(t,e,r,n){return new m(u.uint,pe(t,e+1,n),3)}function Ku(t,e,r,n){return new m(u.uint,me(t,e+1,n),5)}function Yu(t,e,r,n){return new m(u.uint,ye(t,e+1,n),9)}function ke(t,e){return W(t,0,e.value)}function W(t,e,r){if(r<G[0]){let n=Number(r);t.push([e|n])}else if(r<G[1]){let n=Number(r);t.push([e|24,n])}else if(r<G[2]){let n=Number(r);t.push([e|25,n>>>8,n&255])}else if(r<G[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<G[4]){let o=[e|27,0,0,0,0,0,0,0],i=Number(n&BigInt(4294967295)),s=Number(n>>BigInt(32)&BigInt(4294967295));o[8]=i&255,i=i>>8,o[7]=i&255,i=i>>8,o[6]=i&255,i=i>>8,o[5]=i&255,o[4]=s&255,s=s>>8,o[3]=s&255,s=s>>8,o[2]=s&255,s=s>>8,o[1]=s&255,t.push(o)}else throw new Error(`${_} encountered BigInt larger than allowable range`)}}ke.encodedSize=function(e){return W.encodedSize(e.value)};W.encodedSize=function(e){return e<G[0]?1:e<G[1]?2:e<G[2]?3:e<G[3]?5:9};ke.compareTokens=function(e,r){return e.value<r.value?-1:e.value>r.value?1:0};function Zu(t,e,r,n){return new m(u.negint,-1-he(t,e+1,n),2)}function ef(t,e,r,n){return new m(u.negint,-1-pe(t,e+1,n),3)}function tf(t,e,r,n){return new m(u.negint,-1-me(t,e+1,n),5)}var Ki=BigInt(-1),rf=BigInt(1);function nf(t,e,r,n){let o=ye(t,e+1,n);if(typeof o!="bigint"){let i=-1-o;if(i>=Number.MIN_SAFE_INTEGER)return new m(u.negint,i,9)}if(n.allowBigInt!==!0)throw new Error(`${_} integers outside of the safe integer range are not supported`);return new m(u.negint,Ki-BigInt(o),9)}function no(t,e){let r=e.value,n=typeof r=="bigint"?r*Ki-rf:r*-1-1;W(t,e.type.majorEncoded,n)}no.encodedSize=function(e){let r=e.value,n=typeof r=="bigint"?r*Ki-rf:r*-1-1;return n<G[0]?1:n<G[1]?2:n<G[2]?3:n<G[3]?5:9};no.compareTokens=function(e,r){return e.value<r.value?1:e.value>r.value?-1:0};function Vr(t,e,r,n){We(t,e,r+n);let o=t.slice(e+r,e+r+n);return new m(u.bytes,o,r+n)}function of(t,e,r,n){return Vr(t,e,1,r)}function sf(t,e,r,n){return Vr(t,e,2,he(t,e+1,n))}function af(t,e,r,n){return Vr(t,e,3,pe(t,e+1,n))}function cf(t,e,r,n){return Vr(t,e,5,me(t,e+1,n))}function uf(t,e,r,n){let o=ye(t,e+1,n);if(typeof o=="bigint")throw new Error(`${_} 64-bit integer bytes lengths not supported`);return Vr(t,e,9,o)}function oo(t){return t.encodedBytes===void 0&&(t.encodedBytes=u.equals(t.type,u.string)?zr(t.value):t.value),t.encodedBytes}function Xt(t,e){let r=oo(e);W(t,e.type.majorEncoded,r.length),t.push(r)}Xt.encodedSize=function(e){let r=oo(e);return W.encodedSize(r.length)+r.length};Xt.compareTokens=function(e,r){return _m(oo(e),oo(r))};function _m(t,e){return t.length<e.length?-1:t.length>e.length?1:to(t,e)}var ff=new TextDecoder,vm=32;function Am(t,e,r){if(r-e<vm){let o="";for(let i=e;i<r;i++){let s=t[i];if(s&128)return ff.decode(t.subarray(e,r));o+=String.fromCharCode(s)}return o}return ff.decode(t.subarray(e,r))}function qr(t,e,r,n,o){let i=r+n;We(t,e,i);let s=new m(u.string,Am(t,e+r,e+i),i);return o.retainStringBytes===!0&&(s.byteValue=t.slice(e+r,e+i)),s}function lf(t,e,r,n){return qr(t,e,1,r,n)}function df(t,e,r,n){return qr(t,e,2,he(t,e+1,n),n)}function hf(t,e,r,n){return qr(t,e,3,pe(t,e+1,n),n)}function pf(t,e,r,n){return qr(t,e,5,me(t,e+1,n),n)}function mf(t,e,r,n){let o=ye(t,e+1,n);if(typeof o=="bigint")throw new Error(`${_} 64-bit integer string lengths not supported`);return qr(t,e,9,o,n)}var yf=Xt;function Qt(t,e,r,n){return new m(u.array,n,r)}function gf(t,e,r,n){return Qt(t,e,1,r)}function xf(t,e,r,n){return Qt(t,e,2,he(t,e+1,n))}function wf(t,e,r,n){return Qt(t,e,3,pe(t,e+1,n))}function bf(t,e,r,n){return Qt(t,e,5,me(t,e+1,n))}function Ef(t,e,r,n){let o=ye(t,e+1,n);if(typeof o=="bigint")throw new Error(`${_} 64-bit integer array lengths not supported`);return Qt(t,e,9,o)}function _f(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${_} indefinite length items not allowed`);return Qt(t,e,1,1/0)}function io(t,e){W(t,u.array.majorEncoded,e.value)}io.compareTokens=ke.compareTokens;io.encodedSize=function(e){return W.encodedSize(e.value)};function Kt(t,e,r,n){return new m(u.map,n,r)}function kf(t,e,r,n){return Kt(t,e,1,r)}function vf(t,e,r,n){return Kt(t,e,2,he(t,e+1,n))}function Af(t,e,r,n){return Kt(t,e,3,pe(t,e+1,n))}function Tf(t,e,r,n){return Kt(t,e,5,me(t,e+1,n))}function If(t,e,r,n){let o=ye(t,e+1,n);if(typeof o=="bigint")throw new Error(`${_} 64-bit integer map lengths not supported`);return Kt(t,e,9,o)}function Bf(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${_} indefinite length items not allowed`);return Kt(t,e,1,1/0)}function so(t,e){W(t,u.map.majorEncoded,e.value)}so.compareTokens=ke.compareTokens;so.encodedSize=function(e){return W.encodedSize(e.value)};function Sf(t,e,r,n){return new m(u.tag,r,1)}function Nf(t,e,r,n){return new m(u.tag,he(t,e+1,n),2)}function Uf(t,e,r,n){return new m(u.tag,pe(t,e+1,n),3)}function Cf(t,e,r,n){return new m(u.tag,me(t,e+1,n),5)}function Df(t,e,r,n){return new m(u.tag,ye(t,e+1,n),9)}function ao(t,e){W(t,u.tag.majorEncoded,e.value)}ao.compareTokens=ke.compareTokens;ao.encodedSize=function(e){return W.encodedSize(e.value)};var Yi=20,Zi=21,es=22,ts=23;function Lf(t,e,r,n){if(n.allowUndefined===!1)throw new Error(`${_} undefined values are not supported`);return n.coerceUndefinedToNull===!0?new m(u.null,null,1):new m(u.undefined,void 0,1)}function $f(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${_} indefinite length items not allowed`);return new m(u.break,void 0,1)}function rs(t,e,r){if(r){if(r.allowNaN===!1&&Number.isNaN(t))throw new Error(`${_} NaN values are not supported`);if(r.allowInfinity===!1&&(t===1/0||t===-1/0))throw new Error(`${_} Infinity values are not supported`)}return new m(u.float,t,e)}function Rf(t,e,r,n){return rs(ns(t,e+1),3,n)}function Ff(t,e,r,n){return rs(os(t,e+1),5,n)}function Mf(t,e,r,n){return rs(Hf(t,e+1),9,n)}function co(t,e,r){let n=e.value;if(n===!1)t.push([u.float.majorEncoded|Yi]);else if(n===!0)t.push([u.float.majorEncoded|Zi]);else if(n===null)t.push([u.float.majorEncoded|es]);else if(n===void 0)t.push([u.float.majorEncoded|ts]);else{let o,i=!1;(!r||r.float64!==!0)&&(Of(n),o=ns(Se,1),n===o||Number.isNaN(n)?(Se[0]=249,t.push(Se.slice(0,3)),i=!0):(zf(n),o=os(Se,1),n===o&&(Se[0]=250,t.push(Se.slice(0,5)),i=!0))),i||(Nm(n),o=Hf(Se,1),Se[0]=251,t.push(Se.slice(0,9)))}}co.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){Of(n);let o=ns(Se,1);if(n===o||Number.isNaN(n))return 3;if(zf(n),o=os(Se,1),n===o)return 5}return 9};var Pf=new ArrayBuffer(9),ve=new DataView(Pf,1),Se=new Uint8Array(Pf,0);function Of(t){if(t===1/0)ve.setUint16(0,31744,!1);else if(t===-1/0)ve.setUint16(0,64512,!1);else if(Number.isNaN(t))ve.setUint16(0,32256,!1);else{ve.setFloat32(0,t);let e=ve.getUint32(0),r=(e&2139095040)>>23,n=e&8388607;if(r===255)ve.setUint16(0,31744,!1);else if(r===0)ve.setUint16(0,(e&2147483648)>>16|n>>13,!1);else{let o=r-127;o<-24?ve.setUint16(0,0):o<-14?ve.setUint16(0,(e&2147483648)>>16|1<<24+o,!1):ve.setUint16(0,(e&2147483648)>>16|o+15<<10|n>>13,!1)}}}function ns(t,e){if(t.length-e<2)throw new Error(`${_} not enough data for float16`);let r=(t[e]<<8)+t[e+1];if(r===31744)return 1/0;if(r===64512)return-1/0;if(r===32256)return NaN;let n=r>>10&31,o=r&1023,i;return n===0?i=o*2**-24:n!==31?i=(o+1024)*2**(n-25):i=o===0?1/0:NaN,r&32768?-i:i}function zf(t){ve.setFloat32(0,t,!1)}function os(t,e){if(t.length-e<4)throw new Error(`${_} not enough data for float32`);let r=(t.byteOffset||0)+e;return new DataView(t.buffer,r,4).getFloat32(0,!1)}function Nm(t){ve.setFloat64(0,t,!1)}function Hf(t,e){if(t.length-e<8)throw new Error(`${_} not enough data for float64`);let r=(t.byteOffset||0)+e;return new DataView(t.buffer,r,8).getFloat64(0,!1)}co.compareTokens=ke.compareTokens;function D(t,e,r){throw new Error(`${_} encountered invalid minor (${r}) for major ${t[e]>>>5}`)}function uo(t){return()=>{throw new Error(`${_} ${t}`)}}var g=[];for(let t=0;t<=23;t++)g[t]=D;g[24]=Xu;g[25]=Qu;g[26]=Ku;g[27]=Yu;g[28]=D;g[29]=D;g[30]=D;g[31]=D;for(let t=32;t<=55;t++)g[t]=D;g[56]=Zu;g[57]=ef;g[58]=tf;g[59]=nf;g[60]=D;g[61]=D;g[62]=D;g[63]=D;for(let t=64;t<=87;t++)g[t]=of;g[88]=sf;g[89]=af;g[90]=cf;g[91]=uf;g[92]=D;g[93]=D;g[94]=D;g[95]=uo("indefinite length bytes/strings are not supported");for(let t=96;t<=119;t++)g[t]=lf;g[120]=df;g[121]=hf;g[122]=pf;g[123]=mf;g[124]=D;g[125]=D;g[126]=D;g[127]=uo("indefinite length bytes/strings are not supported");for(let t=128;t<=151;t++)g[t]=gf;g[152]=xf;g[153]=wf;g[154]=bf;g[155]=Ef;g[156]=D;g[157]=D;g[158]=D;g[159]=_f;for(let t=160;t<=183;t++)g[t]=kf;g[184]=vf;g[185]=Af;g[186]=Tf;g[187]=If;g[188]=D;g[189]=D;g[190]=D;g[191]=Bf;for(let t=192;t<=215;t++)g[t]=Sf;g[216]=Nf;g[217]=Uf;g[218]=Cf;g[219]=Df;g[220]=D;g[221]=D;g[222]=D;g[223]=D;for(let t=224;t<=243;t++)g[t]=uo("simple values are not supported");g[244]=D;g[245]=D;g[246]=D;g[247]=Lf;g[248]=uo("simple values are not supported");g[249]=Rf;g[250]=Ff;g[251]=Mf;g[252]=D;g[253]=D;g[254]=D;g[255]=$f;var Ne=[];for(let t=0;t<24;t++)Ne[t]=new m(u.uint,t,1);for(let t=-1;t>=-24;t--)Ne[31-t]=new m(u.negint,t,1);Ne[64]=new m(u.bytes,new Uint8Array(0),1);Ne[96]=new m(u.string,"",1);Ne[128]=new m(u.array,0,1);Ne[160]=new m(u.map,0,1);Ne[244]=new m(u.false,!1,1);Ne[245]=new m(u.true,!0,1);Ne[246]=new m(u.null,null,1);function jf(t){switch(t.type){case u.false:return Oe([244]);case u.true:return Oe([245]);case u.null:return Oe([246]);case u.bytes:return t.value.length?void 0:Oe([64]);case u.string:return t.value===""?Oe([96]):void 0;case u.array:return t.value===0?Oe([128]):void 0;case u.map:return t.value===0?Oe([160]):void 0;case u.uint:return t.value<24?Oe([Number(t.value)]):void 0;case u.negint:if(t.value>=-24)return Oe([31-Number(t.value)])}}var qf=Object.freeze({float64:!0,mapSorter:Rm,quickEncodeToken:jf});function Cm(){let t=[];return t[u.uint.major]=ke,t[u.negint.major]=no,t[u.bytes.major]=Xt,t[u.string.major]=yf,t[u.array.major]=io,t[u.map.major]=so,t[u.tag.major]=ao,t[u.float.major]=co,t}var Dm=Cm(),Lm=new Hr,lo=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(`${Jt} object contains circular references`);return new t(r,e)}},ot={null:new m(u.null,null),undefined:new m(u.undefined,void 0),true:new m(u.true,!0),false:new m(u.false,!1),emptyArray:new m(u.array,0),emptyMap:new m(u.map,0)},it={number(t,e,r,n){return!Number.isInteger(t)||!Number.isSafeInteger(t)?new m(u.float,t):t>=0?new m(u.uint,t):new m(u.negint,t)},bigint(t,e,r,n){return t>=BigInt(0)?new m(u.uint,t):new m(u.negint,t)},Uint8Array(t,e,r,n){return new m(u.bytes,t)},string(t,e,r,n){return new m(u.string,t)},boolean(t,e,r,n){return t?ot.true:ot.false},null(t,e,r,n){return ot.null},undefined(t,e,r,n){return ot.undefined},ArrayBuffer(t,e,r,n){return new m(u.bytes,new Uint8Array(t))},DataView(t,e,r,n){return new m(u.bytes,new Uint8Array(t.buffer,t.byteOffset,t.byteLength))},Array(t,e,r,n){if(!t.length)return r.addBreakTokens===!0?[ot.emptyArray,new m(u.break)]:ot.emptyArray;n=lo.createCheck(n,t);let o=[],i=0;for(let s of t)o[i++]=fo(s,r,n);return r.addBreakTokens?[new m(u.array,t.length),o,new m(u.break)]:[new m(u.array,t.length),o]},Object(t,e,r,n){let o=e!=="Object",i=o?t.keys():Object.keys(t),s=o?t.size:i.length,a;if(s){a=new Array(s),n=lo.createCheck(n,t);let c=!o&&r.ignoreUndefinedProperties,f=0;for(let l of i){let p=o?t.get(l):t[l];c&&p===void 0||(a[f++]=[fo(l,r,n),fo(p,r,n)])}f<s&&(a.length=f)}return a?.length?($m(a,r),r.addBreakTokens?[new m(u.map,a.length),a,new m(u.break)]:[new m(u.map,a.length),a]):r.addBreakTokens===!0?[ot.emptyMap,new m(u.break)]:ot.emptyMap}};it.Map=it.Object;it.Buffer=it.Uint8Array;for(let t of"Uint8Clamped Uint16 Uint32 Int8 Int16 Int32 BigUint64 BigInt64 Float32 Float64".split(" "))it[`${t}Array`]=it.DataView;function fo(t,e={},r){let n=Hu(t),o=e&&e.typeEncoders&&e.typeEncoders[n]||it[n];if(typeof o=="function"){let s=o(t,n,e,r);if(s!=null)return s}let i=it[n];if(!i)throw new Error(`${Jt} unsupported type: ${n}`);return i(t,n,e,r)}function $m(t,e){e.mapSorter&&t.sort(e.mapSorter)}function Rm(t,e){if(t[0]instanceof m&&e[0]instanceof m){let r=t[0],n=e[0];return r._keyBytes||(r._keyBytes=Vf(r.value)),n._keyBytes||(n._keyBytes=Vf(n.value)),to(r._keyBytes,n._keyBytes)}throw new Error("rfc8949MapSorter: complex key types are not supported yet")}function Vf(t){return Wf(t,Dm,qf)}function Gf(t,e,r,n){if(Array.isArray(e))for(let o of e)Gf(t,o,r,n);else r[e.type.major](t,e,n)}var CE=u.uint.majorEncoded,DE=u.negint.majorEncoded,LE=u.bytes.majorEncoded,$E=u.string.majorEncoded,RE=u.array.majorEncoded,FE=u.float.majorEncoded|Yi,ME=u.float.majorEncoded|Zi,PE=u.float.majorEncoded|es,OE=u.float.majorEncoded|ts,zE=BigInt(-1),HE=BigInt(1);function Wf(t,e,r,n){let o=n instanceof Uint8Array,i=o?new ro(n):Lm,s=fo(t,r);if(!Array.isArray(s)&&r.quickEncodeToken){let a=r.quickEncodeToken(s);if(a)return o?(i.push(a),i.toBytes()):a;let c=e[s.type.major];if(c.encodedSize){let f=c.encodedSize(s,r);if(o||(i=new Hr(f)),c(i,s,r),i.chunks.length!==1)throw new Error(`Unexpected error: pre-calculated length for ${s} was wrong`);return o?i.toBytes():yt(i.chunks[0])}}return i.reset(),Gf(i,s,e,r),i.toBytes(!0)}var Fm={strict:!1,allowIndefinite:!0,allowUndefined:!0,allowBigInt:!0},ho=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=Ne[e];if(r===void 0){let n=g[e];if(!n)throw new Error(`${_} no decoder for major type ${e>>>5} (byte 0x${e.toString(16).padStart(2,"0")})`);let o=e&31;r=n(this.data,this._pos,o,this.options)}return this._pos+=r.encodedLength,r}},st=Symbol.for("DONE"),Yt=Symbol.for("BREAK");function Mm(t,e,r){let n=[];for(let o=0;o<t.value;o++){let i=at(e,r);if(i===Yt){if(t.value===1/0)break;throw new Error(`${_} got unexpected break to lengthed array`)}if(i===st)throw new Error(`${_} found array but not enough entries (got ${o}, expected ${t.value})`);n[o]=i}return n}function Pm(t,e,r){let n=r.useMaps===!0,o=r.rejectDuplicateMapKeys===!0,i=n?void 0:{},s=n?new Map:void 0;for(let a=0;a<t.value;a++){let c=at(e,r);if(c===Yt){if(t.value===1/0)break;throw new Error(`${_} got unexpected break to lengthed map`)}if(c===st)throw new Error(`${_} found map but not enough entries (got ${a} [no key], expected ${t.value})`);if(!n&&typeof c!="string")throw new Error(`${_} non-string keys not supported (got ${typeof c})`);if(o&&(n&&s.has(c)||!n&&Object.hasOwn(i,c)))throw new Error(`${_} found repeat map key "${c}"`);let f=at(e,r);if(f===st)throw new Error(`${_} found map but not enough entries (got ${a} [no value], expected ${t.value})`);n?s.set(c,f):i[c]=f}return n?s:i}function*Om(t,e,r){for(let n=0;n<t.value;n++){let o=at(e,r);if(o===Yt){if(t.value===1/0)break;throw new Error(`${_} got unexpected break to lengthed map`)}if(o===st)throw new Error(`${_} found map but not enough entries (got ${n} [no key], expected ${t.value})`);let i=at(e,r);if(i===st)throw new Error(`${_} found map but not enough entries (got ${n} [no value], expected ${t.value})`);yield[o,i]}}function zm(t,e){let r=!1,n=function(){if(r)throw new Error(`${_} tag decode() may only be called once`);r=!0;let o=at(t,e);if(o===st)throw new Error(`${_} tag content missing`);if(o===Yt)throw new Error(`${_} got unexpected break in tag content`);return o};return n.entries=function(){if(r)throw new Error(`${_} tag decode() may only be called once`);r=!0;let o=t.next();if(!u.equals(o.type,u.map))throw new Error(`${_} entries() requires map content, got ${o.type.name}`);let i=[];for(let s of Om(o,t,e))i.push(s);return i},Object.defineProperty(n,"_called",{get(){return r},enumerable:!1}),n}function at(t,e){if(t.done())return st;let r=t.next();if(u.equals(r.type,u.break))return Yt;if(r.type.terminal)return r.value;if(u.equals(r.type,u.array))return Mm(r,t,e);if(u.equals(r.type,u.map))return Pm(r,t,e);if(u.equals(r.type,u.tag)){if(e.tags&&typeof e.tags[r.value]=="function"){let n=zm(t,e),o=e.tags[r.value](n);if(!n._called)throw new Error(`${_} tag decoder must call decode() or entries()`);return o}throw new Error(`${_} tag not supported (${r.value})`)}throw new Error("unsupported")}function is(t,e){if(!(t instanceof Uint8Array))throw new Error(`${_} data to decode must be a Uint8Array`);e=Object.assign({},Fm,e);let r=yt(t),n=e.tokenizer||new ho(r,e),o=at(n,e);if(o===st)throw new Error(`${_} did not find any content to decode`);if(o===Yt)throw new Error(`${_} got unexpected break`);return[o,t.subarray(n.pos())]}function ss(t,e){let[r,n]=is(t,e);if(n.length>0)throw new Error(`${_} too many terminals, data makes no sense`);return r}var Jf=class extends Array{constructor(){super(),this.inRecursive=[]}prefix(e){let r=this.inRecursive[this.inRecursive.length-1];r&&(u.equals(r.type,u.array)&&(r.elements++,r.elements!==1&&e.push([44])),u.equals(r.type,u.map)&&(r.elements++,r.elements!==1&&(r.elements%2===1?e.push([44]):e.push([58]))))}[u.uint.major](e,r){this.prefix(e);let n=String(r.value),o=[];for(let i=0;i<n.length;i++)o[i]=n.charCodeAt(i);e.push(o)}[u.negint.major](e,r){this[u.uint.major](e,r)}[u.bytes.major](e,r){throw new Error(`${Jt} unsupported type: Uint8Array`)}[u.string.major](e,r){this.prefix(e);let n=zr(JSON.stringify(r.value));e.push(n.length>32?yt(n):n)}[u.array.major](e,r){this.prefix(e),this.inRecursive.push({type:u.array,elements:0}),e.push([91])}[u.map.major](e,r){this.prefix(e),this.inRecursive.push({type:u.map,elements:0}),e.push([123])}[u.tag.major](e,r){}[u.float.major](e,r){if(r.type.name==="break"){let s=this.inRecursive.pop();if(s){if(u.equals(s.type,u.array))e.push([93]);else if(u.equals(s.type,u.map))e.push([125]);else throw new Error("Unexpected recursive type; this should not happen!");return}throw new Error("Unexpected break; this should not happen!")}if(r.value===void 0)throw new Error(`${Jt} unsupported type: undefined`);if(this.prefix(e),r.type.name==="true"){e.push([116,114,117,101]);return}else if(r.type.name==="false"){e.push([102,97,108,115,101]);return}else if(r.type.name==="null"){e.push([110,117,108,108]);return}let n=String(r.value),o=[],i=!1;for(let s=0;s<n.length;s++)o[s]=n.charCodeAt(s),!i&&(o[s]===46||o[s]===101||o[s]===69)&&(i=!0);i||(o.push(46),o.push(48)),e.push(o)}};var Zt=class{constructor(e,r={}){this._pos=0,this.data=e,this.options=r,this.modeStack=["value"],this.lastToken=""}pos(){return this._pos}done(){return this._pos>=this.data.length}ch(){return this.data[this._pos]}currentMode(){return this.modeStack[this.modeStack.length-1]}skipWhitespace(){let e=this.ch();for(;e===32||e===9||e===13||e===10;)e=this.data[++this._pos]}expect(e){if(this.data.length-this._pos<e.length)throw new Error(`${_} unexpected end of input at position ${this._pos}`);for(let r=0;r<e.length;r++)if(this.data[this._pos++]!==e[r])throw new Error(`${_} unexpected token at position ${this._pos}, expected to find '${String.fromCharCode(...e)}'`)}parseNumber(){let e=this._pos,r=!1,n=!1,o=a=>{for(;!this.done();){let c=this.ch();if(a.includes(c))this._pos++;else break}};if(this.ch()===45&&(r=!0,this._pos++),this.ch()===48)if(this._pos++,this.ch()===46)this._pos++,n=!0;else return new m(u.uint,0,this._pos-e);if(o([48,49,50,51,52,53,54,55,56,57]),r&&this._pos===e+1)throw new Error(`${_} unexpected token at position ${this._pos}`);if(!this.done()&&this.ch()===46){if(n)throw new Error(`${_} unexpected token at position ${this._pos}`);n=!0,this._pos++,o([48,49,50,51,52,53,54,55,56,57])}!this.done()&&(this.ch()===101||this.ch()===69)&&(n=!0,this._pos++,!this.done()&&(this.ch()===43||this.ch()===45)&&this._pos++,o([48,49,50,51,52,53,54,55,56,57]));let i=String.fromCharCode.apply(null,this.data.subarray(e,this._pos)),s=parseFloat(i);return n?new m(u.float,s,this._pos-e):this.options.allowBigInt!==!0||Number.isSafeInteger(s)?new m(s>=0?u.uint:u.negint,s,this._pos-e):new m(s>=0?u.uint:u.negint,BigInt(i),this._pos-e)}parseString(){if(this.ch()!==34)throw new Error(`${_} unexpected character at position ${this._pos}; this shouldn't happen`);this._pos++;for(let i=this._pos,s=0;i<this.data.length&&s<65536;i++,s++){let a=this.data[i];if(a===92||a<32||a>=128)break;if(a===34){let c=String.fromCharCode.apply(null,this.data.subarray(this._pos,i));return this._pos=i+1,new m(u.string,c,s)}}let e=this._pos,r=[],n=()=>{if(this._pos+4>=this.data.length)throw new Error(`${_} unexpected end of unicode escape sequence at position ${this._pos}`);let i=0;for(let s=0;s<4;s++){let a=this.ch();if(a>=48&&a<=57)a-=48;else if(a>=97&&a<=102)a=a-97+10;else if(a>=65&&a<=70)a=a-65+10;else throw new Error(`${_} unexpected unicode escape character at position ${this._pos}`);i=i*16+a,this._pos++}return i},o=()=>{let i=this.ch(),s=null,a=i>239?4:i>223?3:i>191?2:1;if(this._pos+a>this.data.length)throw new Error(`${_} unexpected unicode sequence at position ${this._pos}`);let c,f,l,p;switch(a){case 1:i<128&&(s=i);break;case 2:c=this.data[this._pos+1],(c&192)===128&&(p=(i&31)<<6|c&63,p>127&&(s=p));break;case 3:c=this.data[this._pos+1],f=this.data[this._pos+2],(c&192)===128&&(f&192)===128&&(p=(i&15)<<12|(c&63)<<6|f&63,p>2047&&(p<55296||p>57343)&&(s=p));break;case 4:c=this.data[this._pos+1],f=this.data[this._pos+2],l=this.data[this._pos+3],(c&192)===128&&(f&192)===128&&(l&192)===128&&(p=(i&15)<<18|(c&63)<<12|(f&63)<<6|l&63,p>65535&&p<1114112&&(s=p))}s===null?(s=65533,a=1):s>65535&&(s-=65536,r.push(s>>>10&1023|55296),s=56320|s&1023),r.push(s),this._pos+=a};for(;!this.done();){let i=this.ch(),s;switch(i){case 92:if(this._pos++,this.done())throw new Error(`${_} unexpected string termination at position ${this._pos}`);switch(s=this.ch(),this._pos++,s){case 34:case 39:case 92:case 47:r.push(s);break;case 98:r.push(8);break;case 116:r.push(9);break;case 110:r.push(10);break;case 102:r.push(12);break;case 114:r.push(13);break;case 117:r.push(n());break;default:throw new Error(`${_} unexpected string escape character at position ${this._pos}`)}break;case 34:return this._pos++,new m(u.string,Ju(r),this._pos-e);default:if(i<32)throw new Error(`${_} invalid control character at position ${this._pos}`);i<128?(r.push(i),this._pos++):o()}}throw new Error(`${_} unexpected end of string at position ${this._pos}`)}parseValue(){switch(this.ch()){case 123:return this.modeStack.push("obj-start"),this._pos++,new m(u.map,1/0,1);case 91:return this.modeStack.push("array-start"),this._pos++,new m(u.array,1/0,1);case 34:return this.parseString();case 110:return this.expect([110,117,108,108]),new m(u.null,null,4);case 102:return this.expect([102,97,108,115,101]),new m(u.false,!1,5);case 116:return this.expect([116,114,117,101]),new m(u.true,!0,4);case 45:case 48:case 49:case 50:case 51:case 52:case 53:case 54:case 55:case 56:case 57:return this.parseNumber();default:throw new Error(`${_} unexpected character at position ${this._pos}`)}}next(){switch(this.skipWhitespace(),this.currentMode()){case"value":return this.modeStack.pop(),this.parseValue();case"array-value":{if(this.modeStack.pop(),this.ch()===93)return this._pos++,this.skipWhitespace(),new m(u.break,void 0,1);if(this.ch()!==44)throw new Error(`${_} unexpected character at position ${this._pos}, was expecting array delimiter but found '${String.fromCharCode(this.ch())}'`);return this._pos++,this.modeStack.push("array-value"),this.skipWhitespace(),this.parseValue()}case"array-start":return this.modeStack.pop(),this.ch()===93?(this._pos++,this.skipWhitespace(),new m(u.break,void 0,1)):(this.modeStack.push("array-value"),this.skipWhitespace(),this.parseValue());case"obj-key":if(this.ch()===125)return this.modeStack.pop(),this._pos++,this.skipWhitespace(),new m(u.break,void 0,1);if(this.ch()!==44)throw new Error(`${_} unexpected character at position ${this._pos}, was expecting object delimiter but found '${String.fromCharCode(this.ch())}'`);this._pos++,this.skipWhitespace();case"obj-start":{if(this.modeStack.pop(),this.ch()===125)return this._pos++,this.skipWhitespace(),new m(u.break,void 0,1);let e=this.parseString();if(this.skipWhitespace(),this.ch()!==58)throw new Error(`${_} unexpected character at position ${this._pos}, was expecting key/value delimiter ':' but found '${String.fromCharCode(this.ch())}'`);return this._pos++,this.modeStack.push("obj-value"),e}case"obj-value":return this.modeStack.pop(),this.modeStack.push("obj-key"),this.skipWhitespace(),this.parseValue();default:throw new Error(`${_} unexpected parse state at position ${this._pos}; this shouldn't happen`)}}};function as(t,e){return e=Object.assign({tokenizer:new Zt(t,e)},e),ss(t,e)}function Vm(t){return t instanceof ArrayBuffer?new Uint8Array(t,0,t.byteLength):t}var cs=class extends Zt{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(u.equals(e.type,u.map)){let r=this._next();if(u.equals(r.type,u.string)&&r.value==="/"){let n=this._next();if(u.equals(n.type,u.string)){let o=this._next();if(!u.equals(o.type,u.break))throw new Error("Invalid encoded CID form");return this.tokenBuffer.push(n),new m(u.tag,42,0)}if(u.equals(n.type,u.map)){let o=this._next();if(u.equals(o.type,u.string)&&o.value==="bytes"){let i=this._next();if(u.equals(i.type,u.string)){for(let a=0;a<2;a++){let c=this._next();if(!u.equals(c.type,u.break))throw new Error("Invalid encoded Bytes form")}let s=Li.decode(`m${i.value}`);return new m(u.bytes,s,i.value.length)}this.tokenBuffer.push(i)}this.tokenBuffer.push(o)}this.tokenBuffer.push(n)}this.tokenBuffer.push(r)}return e}},Xf={allowIndefinite:!1,allowUndefined:!1,allowNaN:!1,allowInfinity:!1,allowBigInt:!0,strict:!0,useMaps:!1,rejectDuplicateMapKeys:!0,tags:{42:t=>B.parse(t())}};var po=297;var mo=t=>{let e=Vm(t),r=Object.assign(Xf,{tokenizer:new cs(e,Xf)});return as(e,r)};var g_=new TextDecoder;var x_=new TextEncoder;var qm=new TextDecoder;function us(t,e){let r=0;for(let n=0;;n+=7){if(n>=64)throw new Error("protobuf: varint overflow");if(e>=t.length)throw new Error("protobuf: unexpected end of data");let o=t[e++];if(r+=n<28?(o&127)<<n:(o&127)*2**n,o<128)break}return[r,e]}function go(t,e){let r;[r,e]=us(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 Qf(t,e){let r;return[r,e]=us(t,e),[r&7,r>>3,e]}function Gm(t){let e={},r=t.length,n=0;for(;n<r;){let o,i;if([o,i,n]=Qf(t,n),i===1){if(e.Hash)throw new Error("protobuf: (PBLink) duplicate Hash section");if(o!==2)throw new Error(`protobuf: (PBLink) wrong wireType (${o}) for Hash`);if(e.Name!==void 0)throw new Error("protobuf: (PBLink) invalid order, found Name before Hash");if(e.Tsize!==void 0)throw new Error("protobuf: (PBLink) invalid order, found Tsize before Hash");[e.Hash,n]=go(t,n)}else if(i===2){if(e.Name!==void 0)throw new Error("protobuf: (PBLink) duplicate Name section");if(o!==2)throw new Error(`protobuf: (PBLink) wrong wireType (${o}) for Name`);if(e.Tsize!==void 0)throw new Error("protobuf: (PBLink) invalid order, found Tsize before Name");let s;[s,n]=go(t,n),e.Name=qm.decode(s)}else if(i===3){if(e.Tsize!==void 0)throw new Error("protobuf: (PBLink) duplicate Tsize section");if(o!==0)throw new Error(`protobuf: (PBLink) wrong wireType (${o}) for Tsize`);[e.Tsize,n]=us(t,n)}else throw new Error(`protobuf: (PBLink) invalid fieldNumber, expected 1, 2 or 3, got ${i}`)}if(n>r)throw new Error("protobuf: (PBLink) unexpected end of data");return e}function Kf(t){let e=t.length,r=0,n,o=!1,i;for(;r<e;){let a,c;if([a,c,r]=Qf(t,r),a!==2)throw new Error(`protobuf: (PBNode) invalid wireType, expected 2, got ${a}`);if(c===1){if(i)throw new Error("protobuf: (PBNode) duplicate Data section");[i,r]=go(t,r),n&&(o=!0)}else if(c===2){if(o)throw new Error("protobuf: (PBNode) duplicate Links section");n||(n=[]);let f;[f,r]=go(t,r),n.push(Gm(f))}else throw new Error(`protobuf: (PBNode) invalid fieldNumber, expected 1 or 2, got ${c}`)}if(r>e)throw new Error("protobuf: (PBNode) unexpected end of data");let s={};return i&&(s.Data=i),s.Links=n||[],s}var Zf=new TextEncoder,Yf=2**32,Wm=2**31;function Jm(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=Gr(e,r,t.Tsize)-1,e[r]=24}if(typeof t.Name=="string"){let n=Zf.encode(t.Name);r-=n.length,e.set(n,r),r=Gr(e,r,n.length)-1,e[r]=18}return t.Hash&&(r-=t.Hash.length,e.set(t.Hash,r),r=Gr(e,r,t.Hash.length)-1,e[r]=10),e.length-r}function el(t){let e=Qm(t),r=new Uint8Array(e),n=e;if(t.Data&&(n-=t.Data.length,r.set(t.Data,n),n=Gr(r,n,t.Data.length)-1,r[n]=10),t.Links)for(let o=t.Links.length-1;o>=0;o--){let i=Jm(t.Links[o],r.subarray(0,n));n-=i,n=Gr(r,n,i)-1,r[n]=18}return r}function Xm(t){let e=0;if(t.Hash){let r=t.Hash.length;e+=1+r+er(r)}if(typeof t.Name=="string"){let r=Zf.encode(t.Name).length;e+=1+r+er(r)}return typeof t.Tsize=="number"&&(e+=1+er(t.Tsize)),e}function Qm(t){let e=0;if(t.Data){let r=t.Data.length;e+=1+r+er(r)}if(t.Links)for(let r of t.Links){let n=Xm(r);e+=1+n+er(n)}return e}function Gr(t,e,r){e-=er(r);let n=e;for(;r>=Wm;)t[e++]=r&127|128,r/=128;for(;r>=128;)t[e++]=r&127|128,r>>>=7;return t[e]=r,n}function er(t){return t%2===0&&t++,Math.floor((Km(t)+6)/7)}function Km(t){let e=0;return t>=Yf&&(t=Math.floor(t/Yf),e=32),t>=65536&&(t>>>=16,e+=16),t>=256&&(t>>>=8,e+=8),e+Ym[t]}var Ym=[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 Zm=["Data","Links"],ey=["Hash","Name","Tsize"],tl=new TextEncoder;function ty(t,e){if(t===e)return 0;let r=t.Name?tl.encode(t.Name):[],n=e.Name?tl.encode(e.Name):[],o=r.length,i=n.length;for(let s=0,a=Math.min(o,i);s<a;++s)if(r[s]!==n[s]){o=r[s],i=n[s];break}return o<i?-1:i<o?1:0}function rl(t,e){return!Object.keys(t).some(r=>!e.includes(r))}function nl(t){if(!t||typeof t!="object"||Array.isArray(t)||t instanceof Uint8Array||t["/"]&&t["/"]===t.bytes)throw new TypeError("Invalid DAG-PB form");if(!rl(t,Zm))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(!rl(r,ey))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&&ty(r,t.Links[e-1])===-1)throw new TypeError("Invalid DAG-PB form (links must be sorted by Name bytes)")}}function ol(t){return t instanceof ArrayBuffer?new Uint8Array(t,0,t.byteLength):t}var tr=112;function il(t){nl(t);let e={};return t.Links&&(e.Links=t.Links.map(r=>{let n={};return r.Hash&&(n.Hash=r.Hash.bytes),r.Name!==void 0&&(n.Name=r.Name),r.Tsize!==void 0&&(n.Tsize=r.Tsize),n})),t.Data&&(e.Data=t.Data),el(e)}function ze(t){let e=ol(t),r=Kf(e),n={};return r.Data&&(n.Data=r.Data),r.Links&&(n.Links=r.Links.map(o=>{let i={};try{i.Hash=B.decode(o.Hash)}catch{}if(!i.Hash)throw new Error("Invalid Hash field found in link, expected CID");return o.Name!==void 0&&(i.Name=o.Name),o.Tsize!==void 0&&(i.Tsize=o.Tsize),i})),n}function ry(t){return t[Symbol.asyncIterator]!=null}function ny(t,e){let r=0;if(ry(t))return(async function*(){for await(let c of t)await e(c,r++)&&(yield c)})();let n=On(t),{value:o,done:i}=n.next();if(i===!0)return(function*(){})();let s=e(o,r++);if(typeof s.then=="function")return(async function*(){await s&&(yield o);for(let c of n)await e(c,r++)&&(yield c)})();let a=e;return(function*(){s===!0&&(yield o);for(let c of n)a(c,r++)&&(yield c)})()}var sl=ny;function xt(t){return e=>new fs(e,t)}function wt(t){return e=>new ls(e,t)}function hs(t){return e=>new ds(e,t)}var Jr=class{components;constructor(e,r={}){this.components=e}async*walk(e,r){let n=this.getQueue(),o=sl(n.toGenerator(r),a=>a!=null),i=!1,s=async a=>{let c=a.cid,f=await C(this.components.blockstore.get(c,a)),l=Pe({cid:c,bytes:f,codec:await this.components.getCodec(c.code)});for(let[,p]of l.links())r?.includeChild?.(p,l)!==!1&&n.add(s,{...a,cid:p,depth:a.depth+1,path:[...a.path,p]}).catch(k=>{i||o.throw(k)});return{block:l,depth:a.depth,path:a.path}};n.add(s,{...r,cid:e,depth:0,path:[e]}).catch(a=>{i||o.throw(a)});try{yield*o}finally{i=!0,n.abort()}}},fs=class extends Jr{getQueue(){return new Wt({concurrency:1,sort:(e,r)=>e.options.depth===r.options.depth?0:e.options.depth<r.options.depth?1:-1})}},ls=class extends Jr{getQueue(){return new Wt({concurrency:1,sort:(e,r)=>e.options.depth===r.options.depth?0:e.options.depth<r.options.depth?-1:1})}},ds=class extends Jr{getQueue(){return new Wt({concurrency:1})}};var Xr=class{walker;constructor(e){this.walker=e?.walker}async*export(e,r,n,o){let i,s={blockstore:r,getCodec:n};this.walker!=null?i=this.walker(s):i=wt()(s);for await(let a of i.walk(e,o))yield a.block}};var xo=class{components;log;constructor(e){this.components=e,this.log=e.logger.forComponent("helia:car")}async import(e,r){await Ai(this.components.blockstore.putMany(Ot(e.blocks(),({cid:n,bytes:o})=>({cid:n,bytes:o})),r))}async*export(e,r){let n=Array.isArray(e)?e:[e],{writer:o,out:i}=Cr.create(n),s=i[Symbol.asyncIterator](),a=new AbortController;for(this._export(n,o,r).catch(c=>{this.log.error("error during streaming export - %e",c),a.abort(c)});;){let{done:c,value:f}=await zt(s.next(),a.signal);if(a.signal.aborted)throw a.signal.reason;if(f!=null&&(yield f),c===!0)break}}async _export(e,r,n){let o=n?.traversal;for(let i of e){if(i.multihash.code===0)continue;let s=n?.exporter??(i.code===112?new Qr:new Xr),a=i,c=!1;if(o!=null){for await(let{cid:f,bytes:l}of o.traverse(a,this.components.blockstore,this.components.getCodec,n))if(this.log.trace("next CID on path to %c is %c",i,f),a=f,i.equals(f)&&(c=!0),c||n?.includeTraversalBlocks===!0){if(n?.blockFilter?.has(f.multihash.bytes)===!0)continue;n?.blockFilter?.add(f.multihash.bytes),await r.put({cid:f,bytes:l})}}for await(let{cid:f,bytes:l}of s.export(a,this.components.blockstore,this.components.getCodec,n))n?.blockFilter?.has(f.multihash.bytes)!==!0&&f.multihash.code!==0&&(c&&f.equals(a)||(n?.blockFilter?.add(f.multihash.bytes),await r.put({cid:f,bytes:l})))}await r.close()}};var ps=class{async*export(e,r,n,o){let i=await C(r.get(e,o));yield Pe({cid:e,bytes:i,codec:await n(e.code)})}};var Kr=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 ms=new Float32Array([-0]),ct=new Uint8Array(ms.buffer);function cl(t,e,r){ms[0]=t,e[r]=ct[0],e[r+1]=ct[1],e[r+2]=ct[2],e[r+3]=ct[3]}function ul(t,e){return ct[0]=t[e],ct[1]=t[e+1],ct[2]=t[e+2],ct[3]=t[e+3],ms[0]}var ys=new Float64Array([-0]),Y=new Uint8Array(ys.buffer);function fl(t,e,r){ys[0]=t,e[r]=Y[0],e[r+1]=Y[1],e[r+2]=Y[2],e[r+3]=Y[3],e[r+4]=Y[4],e[r+5]=Y[5],e[r+6]=Y[6],e[r+7]=Y[7]}function ll(t,e){return Y[0]=t[e],Y[1]=t[e+1],Y[2]=t[e+2],Y[3]=t[e+3],Y[4]=t[e+4],Y[5]=t[e+5],Y[6]=t[e+6],Y[7]=t[e+7],ys[0]}var iy=BigInt(Number.MAX_SAFE_INTEGER),sy=BigInt(Number.MIN_SAFE_INTEGER),ge=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 bt;if(e<iy&&e>sy)return this.fromNumber(Number(e));let r=e<0n;r&&(e=-e);let n=e>>32n,o=e-(n<<32n);return r&&(n=~n|0n,o=~o|0n,++o>dl&&(o=0n,++n>dl&&(n=0n))),new t(Number(o),Number(n))}static fromNumber(e){if(e===0)return bt;let r=e<0;r&&(e=-e);let n=e>>>0,o=(e-n)/4294967296>>>0;return r&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new t(n,o)}static from(e){return typeof e=="number"?t.fromNumber(e):typeof e=="bigint"?t.fromBigInt(e):typeof e=="string"?t.fromBigInt(BigInt(e)):e.low!=null||e.high!=null?new t(e.low>>>0,e.high>>>0):bt}},bt=new ge(0,0);bt.toBigInt=function(){return 0n};bt.zzEncode=bt.zzDecode=function(){return this};bt.length=function(){return 1};var dl=4294967296n;function hl(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 pl(t,e,r){if(r-e<1)return"";let o,i=[],s=0,a;for(;e<r;)a=t[e++],a<128?i[s++]=a:a>191&&a<224?i[s++]=(a&31)<<6|t[e++]&63:a>239&&a<365?(a=((a&7)<<18|(t[e++]&63)<<12|(t[e++]&63)<<6|t[e++]&63)-65536,i[s++]=55296+(a>>10),i[s++]=56320+(a&1023)):i[s++]=(a&15)<<12|(t[e++]&63)<<6|t[e++]&63,s>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,i)),s=0);return o!=null?(s>0&&o.push(String.fromCharCode.apply(String,i.slice(0,s))),o.join("")):String.fromCharCode.apply(String,i.slice(0,s))}function gs(t,e,r){let n=r,o,i;for(let s=0;s<t.length;++s)o=t.charCodeAt(s),o<128?e[r++]=o:o<2048?(e[r++]=o>>6|192,e[r++]=o&63|128):(o&64512)===55296&&((i=t.charCodeAt(s+1))&64512)===56320?(o=65536+((o&1023)<<10)+(i&1023),++s,e[r++]=o>>18|240,e[r++]=o>>12&63|128,e[r++]=o>>6&63|128,e[r++]=o&63|128):(e[r++]=o>>12|224,e[r++]=o>>6&63|128,e[r++]=o&63|128);return r-n}function Ue(t,e){return RangeError(`index out of range: ${t.pos} + ${e??1} > ${t.len}`)}function wo(t,e){return(t[e-4]|t[e-3]<<8|t[e-2]<<16|t[e-1]<<24)>>>0}var xs=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(e){this.buf=e,this.pos=0,this.len=e.length}uint32(){let e=4294967295;if(e=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(e=(e|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return e;if((this.pos+=5)>this.len)throw this.pos=this.len,Ue(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 Ue(this,4);return wo(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Ue(this,4);return wo(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Ue(this,4);let e=ul(this.buf,this.pos);return this.pos+=4,e}double(){if(this.pos+8>this.len)throw Ue(this,4);let e=ll(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 Ue(this,e);return this.pos+=e,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let e=this.bytes();return pl(e,0,e.length)}skip(e){if(typeof e=="number"){if(this.pos+e>this.len)throw Ue(this,e);this.pos+=e}else do if(this.pos>=this.len)throw Ue(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 ge(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 Ue(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 Ue(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 Ue(this,8);let e=wo(this.buf,this.pos+=4),r=wo(this.buf,this.pos+=4);return new ge(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=Ru(this.buf,this.pos);return this.pos+=Pr(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 ws(t){return new xs(t instanceof Uint8Array?t:t.subarray())}function Yr(t,e,r){let n=ws(t);return e.decode(n,void 0,r)}function bs(t){let e=t??8192,r=e>>>1,n,o=e;return function(s){if(s<1||s>r)return Me(s);o+s>e&&(n=Me(e),o=0);let a=n.subarray(o,o+=s);return(o&7)!==0&&(o=(o|7)+1),a}}var Et=class{fn;len;next;val;constructor(e,r,n){this.fn=e,this.len=r,this.next=void 0,this.val=n}};function Es(){}var ks=class{head;tail;len;next;constructor(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}},ay=bs();function cy(t){return globalThis.Buffer!=null?Me(t):ay(t)}var en=class{len;head;tail;states;constructor(){this.len=0,this.head=new Et(Es,0,0),this.tail=this.head,this.states=null}_push(e,r,n){return this.tail=this.tail.next=new Et(e,r,n),this.len+=r,this}uint32(e){return this.len+=(this.tail=this.tail.next=new vs((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(bo,10,ge.fromNumber(e)):this.uint32(e)}sint32(e){return this.uint32((e<<1^e>>31)>>>0)}uint64(e){let r=ge.fromBigInt(e);return this._push(bo,r.length(),r)}uint64Number(e){return this._push($u,Pr(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=ge.fromBigInt(e).zzEncode();return this._push(bo,r.length(),r)}sint64Number(e){let r=ge.fromNumber(e).zzEncode();return this._push(bo,r.length(),r)}sint64String(e){return this.sint64(BigInt(e))}bool(e){return this._push(_s,1,e?1:0)}fixed32(e){return this._push(Zr,4,e>>>0)}sfixed32(e){return this.fixed32(e)}fixed64(e){let r=ge.fromBigInt(e);return this._push(Zr,4,r.lo)._push(Zr,4,r.hi)}fixed64Number(e){let r=ge.fromNumber(e);return this._push(Zr,4,r.lo)._push(Zr,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(cl,4,e)}double(e){return this._push(fl,8,e)}bytes(e){let r=e.length>>>0;return r===0?this._push(_s,1,0):this.uint32(r)._push(fy,r,e)}string(e){let r=hl(e);return r!==0?this.uint32(r)._push(gs,r,e):this._push(_s,1,0)}fork(){return this.states=new ks(this),this.head=this.tail=new Et(Es,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 Et(Es,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=cy(this.len),n=0;for(;e!=null;)e.fn(e.val,r,n),n+=e.len,e=e.next;return r}};function _s(t,e,r){e[r]=t&255}function uy(t,e,r){for(;t>127;)e[r++]=t&127|128,t>>>=7;e[r]=t}var vs=class extends Et{next;constructor(e,r){super(uy,e,r),this.next=void 0}};function bo(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 Zr(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 fy(t,e,r){e.set(t,r)}globalThis.Buffer!=null&&(en.prototype.bytes=function(t){let e=t.length>>>0;return this.uint32(e),e>0&&this._push(ly,e,t),this},en.prototype.string=function(t){let e=globalThis.Buffer.byteLength(t);return this.uint32(e),e>0&&this._push(dy,e,t),this});function ly(t,e,r){e.set(t,r)}function dy(t,e,r){t.length<40?gs(t,e,r):e.utf8Write!=null?e.utf8Write(t,r):e.set(Gn(t),r)}function As(){return new en}function tn(t,e){let r=As();return e.encode(t,r,{lengthDelimited:!1}),r.finish()}var rr;(function(t){t[t.VARINT=0]="VARINT",t[t.BIT64=1]="BIT64",t[t.LENGTH_DELIMITED=2]="LENGTH_DELIMITED",t[t.START_GROUP=3]="START_GROUP",t[t.END_GROUP=4]="END_GROUP",t[t.BIT32=5]="BIT32"})(rr||(rr={}));function Eo(t,e,r,n){return{name:t,type:e,encode:r,decode:n}}function Ts(t){function e(o){if(t[o.toString()]==null)throw new Error("Invalid enum value");return t[o]}let r=function(i,s){let a=e(i);s.int32(a)},n=function(i){let s=i.int32();return e(s)};return Eo("enum",rr.VARINT,r,n)}function rn(t,e){return Eo("message",rr.LENGTH_DELIMITED,t,e)}var Ce;(function(t){let e;(function(o){o.Raw="Raw",o.Directory="Directory",o.File="File",o.Metadata="Metadata",o.Symlink="Symlink",o.HAMTShard="HAMTShard"})(e=t.DataType||(t.DataType={}));let r;(function(o){o[o.Raw=0]="Raw",o[o.Directory=1]="Directory",o[o.File=2]="File",o[o.Metadata=3]="Metadata",o[o.Symlink=4]="Symlink",o[o.HAMTShard=5]="HAMTShard"})(r||(r={})),(function(o){o.codec=()=>Ts(r)})(e=t.DataType||(t.DataType={}));let n;t.codec=()=>(n==null&&(n=rn((o,i,s={})=>{if(s.lengthDelimited!==!1&&i.fork(),o.Type!=null&&(i.uint32(8),t.DataType.codec().encode(o.Type,i)),o.Data!=null&&(i.uint32(18),i.bytes(o.Data)),o.filesize!=null&&(i.uint32(24),i.uint64(o.filesize)),o.blocksizes!=null)for(let a of o.blocksizes)i.uint32(32),i.uint64(a);o.hashType!=null&&(i.uint32(40),i.uint64(o.hashType)),o.fanout!=null&&(i.uint32(48),i.uint64(o.fanout)),o.mode!=null&&(i.uint32(56),i.uint32(o.mode)),o.mtime!=null&&(i.uint32(66),_o.codec().encode(o.mtime,i)),s.lengthDelimited!==!1&&i.ldelim()},(o,i)=>{let s={blocksizes:[]},a=i==null?o.len:o.pos+i;for(;o.pos<a;){let c=o.uint32();switch(c>>>3){case 1:s.Type=t.DataType.codec().decode(o);break;case 2:s.Data=o.bytes();break;case 3:s.filesize=o.uint64();break;case 4:s.blocksizes.push(o.uint64());break;case 5:s.hashType=o.uint64();break;case 6:s.fanout=o.uint64();break;case 7:s.mode=o.uint32();break;case 8:s.mtime=_o.codec().decode(o,o.uint32());break;default:o.skipType(c&7);break}}return s})),n),t.encode=o=>tn(o,t.codec()),t.decode=o=>Yr(o,t.codec())})(Ce||(Ce={}));var _o;(function(t){let e;t.codec=()=>(e==null&&(e=rn((r,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),r.Seconds!=null&&(n.uint32(8),n.int64(r.Seconds)),r.FractionalNanoseconds!=null&&(n.uint32(21),n.fixed32(r.FractionalNanoseconds)),o.lengthDelimited!==!1&&n.ldelim()},(r,n)=>{let o={},i=n==null?r.len:r.pos+n;for(;r.pos<i;){let s=r.uint32();switch(s>>>3){case 1:o.Seconds=r.int64();break;case 2:o.FractionalNanoseconds=r.fixed32();break;default:r.skipType(s&7);break}}return o})),e),t.encode=r=>tn(r,t.codec()),t.decode=r=>Yr(r,t.codec())})(_o||(_o={}));var yl;(function(t){let e;t.codec=()=>(e==null&&(e=rn((r,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),r.MimeType!=null&&(n.uint32(10),n.string(r.MimeType)),o.lengthDelimited!==!1&&n.ldelim()},(r,n)=>{let o={},i=n==null?r.len:r.pos+n;for(;r.pos<i;){let s=r.uint32();switch(s>>>3){case 1:o.MimeType=r.string();break;default:r.skipType(s&7);break}}return o})),e),t.encode=r=>tn(r,t.codec()),t.decode=r=>Yr(r,t.codec())})(yl||(yl={}));var gl={Raw:"raw",Directory:"directory",File:"file",Metadata:"metadata",Symlink:"symlink",HAMTShard:"hamt-sharded-directory"},hy=["directory","hamt-sharded-directory"],xl=parseInt("0644",8),wl=parseInt("0755",8),Z=class t{static unmarshal(e){let r=Ce.decode(e),n=new t({type:gl[r.Type!=null?r.Type.toString():"File"],data:r.Data,blockSizes:r.blocksizes,mode:r.mode,mtime:r.mtime!=null?{secs:r.mtime.Seconds??0n,nsecs:r.mtime.FractionalNanoseconds}:void 0,fanout:r.fanout});return n._originalMode=r.mode??0,n}type;data;blockSizes;hashType;fanout;mtime;_mode;_originalMode;constructor(e={type:"file"}){let{type:r,data:n,blockSizes:o,hashType:i,fanout:s,mtime:a,mode:c}=e;if(r!=null&&!Object.values(gl).includes(r))throw new Kr("Type: "+r+" is not valid");this.type=r??"file",this.data=n,this.hashType=i,this.fanout=s,this.blockSizes=o??[],this._originalMode=0,this.mode=c,this.mtime=a}set mode(e){e==null?this._mode=this.isDirectory()?wl:xl:this._mode=e&4095}get mode(){return this._mode}isDirectory(){return hy.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=Ce.DataType.Raw;break;case"directory":e=Ce.DataType.Directory;break;case"file":e=Ce.DataType.File;break;case"metadata":e=Ce.DataType.Metadata;break;case"symlink":e=Ce.DataType.Symlink;break;case"hamt-sharded-directory":e=Ce.DataType.HAMTShard;break;default:throw new Kr(`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===xl&&!this.isDirectory()&&(n=void 0),n===wl&&this.isDirectory()&&(n=void 0));let o;return this.mtime!=null&&(o={Seconds:this.mtime.secs,FractionalNanoseconds:this.mtime.nsecs}),Ce.encode({Type:e,Data:r,filesize:this.isDirectory()?void 0:this.fileSize(),blocksizes:this.blockSizes,hashType:this.hashType,fanout:this.fanout,mode:n,mtime:o})}};var nn=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"},ko=class extends Error{static name="NotDescendantError";name="NotDescendantError"},nr=class extends Error{static name="InvalidTraversalError";name="InvalidTraversalError"};function my(t){return t.cid.code===85}function yy(t){return t.cid.code===112}function gy(t){if(my(t))return!0;if(yy(t)&&t.value.Data!=null){let e=Z.unmarshal(t.value.Data);return e.type==="file"||e.type==="raw"}else throw new nn("Encountered non raw/dag-pb CID in UnixFS DAG")}var Qr=class{options;constructor(e){this.options=e}async*export(e,r,n,o){if(e.code!==112&&e.code!==85)throw new nn("Target CID was not UnixFS - use the SubGraphExporter to export arbitrary graphs");let i=xt()({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 pt("Offset cannot be negative");if(a<0)throw new pt("Length cannot be negative");let f,l=new AbortController,p=Fu([l.signal,o?.signal]);l.signal;function k(v,w){if(f==null&&(f=gy(w)),!f){let H=w.value.Links.find(ne=>ne.Hash.equals(v)),re=Z.unmarshal(w.value.Data??new Uint8Array);return re.type==="directory"?!c:re.type==="hamt-sharded-directory"&&c?H?.Name?.length===2:!0}let T=w.value.Links.findIndex(H=>H.Hash.equals(v)),I=Z.unmarshal(w.value.Data??new Uint8Array),R=s,z=R+a,P=Number([...I.blockSizes].slice(0,T).reduce((H,re)=>H+re,0n)),J=P+Number(I.blockSizes[T]);return R>=P&&R<J||z>=P&&z<J||R<=P&&z>=J}try{for await(let v of i.walk(e,{...o,includeChild:k,signal:p}))yield v.block}finally{l.abort(),p.clear()}}};function bl(t){return t!=null&&t?.asCID===t}var Is=class{haystack;needle;options;walker;constructor(...e){if(bl(e[0]))bl(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 pt("needle must be specified");this.walker=this.options?.walker}async*traverse(e,r,n,o){let i=this.haystack??e,s,a={blockstore:r,getCodec:n};this.walker!=null?s=this.walker(a):this.options?.strategy==="breadth-first"?s=wt()(a):s=xt()(a);for await(let c of s.walk(i,o))if(c.block.cid.equals(this.needle)){for(let f of c.path){let l=await C(r.get(f,o));yield Pe({cid:f,bytes:l,codec:await n(f.code)})}return}throw new nr(`${this.needle} was not a child of ${i}`)}};var Bs=class{path;constructor(e){this.path=e}async*traverse(e,r,n,o){if(!this.path.some(s=>s.equals(e)))throw new nr(`CIDPath traversal must include ${e}`);let i;for(let s of this.path){if(i!=null){let f=!1;for(let[,l]of i.links())if(l.equals(s)){f=!0;break}if(!f)throw new ko(`${s} is not a child of ${i.cid}`)}let a=await C(r.get(s,o)),c=Pe({cid:s,bytes:a,codec:await n(s.code)});i=c,yield c}}};var or=class t extends Error{static name="BadPathError";static code="ERR_BAD_PATH";name=t.name;code=t.code;constructor(e="Bad path"){super(e)}},xe=class t extends Error{static name="NotFoundError";static code="ERR_NOT_FOUND";name=t.name;code=t.code;constructor(e="Not found"){super(e)}},ir=class t extends Error{static name="NoResolverError";static code="ERR_NO_RESOLVER";name=t.name;code=t.code;constructor(e="No resolver"){super(e)}},F=class t extends Error{static name="NotUnixFSError";static code="ERR_NOT_UNIXFS";name=t.name;code=t.code;constructor(e="Not UnixFS"){super(e)}},vo=class t extends Error{static name="OverReadError";static code="ERR_OVER_READ";name=t.name;code=t.code;constructor(e="Over read"){super(e)}},Ao=class t extends Error{static name="UnderReadError";static code="ERR_UNDER_READ";name=t.name;code=t.code;constructor(e="Under read"){super(e)}},Je=class t extends Error{static name="InvalidParametersError";static code="ERR_INVALID_PARAMS";name=t.name;code=t.code;constructor(e="Invalid parameters"){super(e)}};function sr(t){return t==null?!1:B.asCID(t)===t}function ar(t,e){let r,n=0,o="";for(;n<e.length;){let i=e[n];if(n++,!Object.hasOwnProperty.call(t,i))throw new or(`Object did not have key "${i}"`);if(o+=`/${i}`,r=t[i],t=r,sr(r))break}return{value:r,rest:e.slice(n),path:o.substring(1)}}async function*Ss(t,e,r,n){let o=await C(r.get(t,n)),i=dt(o),s=ar(i,e);yield{cid:sr(s.value)?s.value:t,name:s.path,rest:s.rest}}async function*El(t,e,r,n){let o=await C(r.get(t,n)),i=mo(o),s=ar(i,e);yield{cid:sr(s.value)?s.value:t,name:s.path,rest:s.rest}}function ut(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 xy(t,e){return t+e>>>0}function Ae(t,e){let r=t.lo&65535,n=t.lo>>>16,o=e.lo&65535,i=e.lo>>>16,s=r*o,a=r*i,c=n*o,f=n*i,l=(s>>>16)+(a&65535)+(c&65535)>>>0,p=(l<<16|s&65535)>>>0,k=f+(a>>>16)+(c>>>16)+(l>>>16),v=Math.imul(t.lo,e.hi),w=Math.imul(t.hi,e.lo),T=k+v+w>>>0;return{lo:p,hi:T}}function _t(t,e){return Math.imul(t,e)>>>0}function cr(t,e){if(e===0)return t;if(e===32)return{lo:t.hi,hi:t.lo};if(e<32){let o=(t.lo<<e|t.hi>>>32-e)>>>0,i=(t.hi<<e|t.lo>>>32-e)>>>0;return{lo:o,hi:i}}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 M(t,e){return{lo:(t.lo^e.lo)>>>0,hi:(t.hi^e.hi)>>>0}}function Ns(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 L(t,e){return{lo:t>>>0,hi:e>>>0}}function Us(t,e){return(t<<e|t>>>32-e)>>>0}function _l(t,e){let r=e*8,n=t[r]|t[r+1]<<8|t[r+2]<<16|t[r+3]<<24,o=t[r+4]|t[r+5]<<8|t[r+6]<<16|t[r+7]<<24;return{lo:n>>>0,hi:o>>>0}}function wy(t,e){let r=e*4;return(t[r]|t[r+1]<<8|t[r+2]<<16|t[r+3]<<24)>>>0}function kl(t){return t=M(t,Ns(t,33)),t=Ae(t,L(3981806797,4283543511)),t=M(t,Ns(t,33)),t=Ae(t,L(444984403,3301882366)),t=M(t,Ns(t,33)),t}function by(t){return t^=t>>>16,t=_t(t,2246822507),t^=t>>>13,t=_t(t,3266489909),t^=t>>>16,t}function Cs(t,e=0){let r=L(e,0),n=L(e,0),o=t.length,i=Math.floor(o/16),s=L(289559509,2277735313),a=L(658871167,1291169091);for(let k=0;k<i;k++){let v=_l(t,k*2),w=_l(t,k*2+1);v=Ae(v,s),v=cr(v,31),v=Ae(v,a),r=M(r,v),r=cr(r,27),r=ut(r,n),r=ut(Ae(r,L(5,0)),L(1390208809,0)),w=Ae(w,a),w=cr(w,33),w=Ae(w,s),n=M(n,w),n=cr(n,31),n=ut(n,r),n=ut(Ae(n,L(5,0)),L(944331445,0))}let c=L(0,0),f=L(0,0),l=t.slice(i*16);switch(l.length){case 15:f=M(f,L(0,l[14]<<16));case 14:f=M(f,L(0,l[13]<<8));case 13:f=M(f,L(0,l[12]));case 12:f=M(f,L(l[11]<<24,0));case 11:f=M(f,L(l[10]<<16,0));case 10:f=M(f,L(l[9]<<8,0));case 9:f=M(f,L(l[8],0)),f=Ae(f,a),f=cr(f,33),f=Ae(f,s),n=M(n,f);case 8:c=M(c,L(0,l[7]<<24));case 7:c=M(c,L(0,l[6]<<16));case 6:c=M(c,L(0,l[5]<<8));case 5:c=M(c,L(0,l[4]));case 4:c=M(c,L(l[3]<<24,0));case 3:c=M(c,L(l[2]<<16,0));case 2:c=M(c,L(l[1]<<8,0));case 1:c=M(c,L(l[0],0)),c=Ae(c,s),c=cr(c,31),c=Ae(c,a),r=M(r,c)}let p=L(o,0);return r=M(r,p),n=M(n,p),r=ut(r,n),n=ut(n,r),r=kl(r),n=kl(n),r=ut(r,n),n=ut(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 vl(t,e=0){let r=e>>>0,n=t.length,o=Math.floor(n/4),i=3432918353,s=461845907;for(let f=0;f<o;f++){let l=wy(t,f);l=_t(l,i),l=Us(l,15),l=_t(l,s),r^=l,r=Us(r,13),r=xy(_t(r,5),3864292196)}let a=t.slice(o*4),c=0;switch(a.length){case 3:c^=a[2]<<16;case 2:c^=a[1]<<8;case 1:c^=a[0],c=_t(c,i),c=Us(c,15),c=_t(c,s),r^=c}return r^=n,r=by(r),r}function _y(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 _v=mt({name:"murmur3-32",code:35,encode:t=>_y(vl(t))}),Al=mt({name:"murmur3-128",code:34,encode:t=>Cs(t)}),kv=mt({name:"murmur3-x64-64",code:34,encode:t=>Cs(t).subarray(0,8)});var Sl=vt(Bl(),1);var kt=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 Sl.default,this.key=null}async put(e,r){let n=await this._findNewBucketAndPos(e);n.bucket._putAt(n,e,r)}async get(e){let r=await this._findChild(e);if(r!=null)return r.value}async del(e){let r=await this._findPlace(e),n=r.bucket._at(r.pos);n!=null&&n.key===e&&r.bucket._delAt(r.pos)}leafCount(){return this._children.compactArray().reduce((r,n)=>n instanceof t?r+n.leafCount():r+1,0)}childrenCount(){return this._children.length}onlyChild(){return this._children.get(0)}*eachLeafSeries(){let e=this._children.compactArray();for(let r of e)r instanceof t?yield*r.eachLeafSeries():yield r}serialize(e,r){let n=[];return r(this._children.reduce((o,i,s)=>(i!=null&&(i instanceof t?o.push(i.serialize(e,r)):o.push(e(i,s))),o),n))}async asyncTransform(e,r){return Nl(this,e,r)}toJSON(){return this.serialize(Iy,By)}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"?Gn(e):e),n=await r.take(this._options.bits),o=this._children.get(n);return o instanceof t?o._findPlace(r):{bucket:this,pos:n,hash:r,existingChild:o}}async _findNewBucketAndPos(e){let r=await this._findPlace(e);if(r.existingChild!=null&&r.existingChild.key!==e){let n=new t(this._options,r.bucket,r.pos);r.bucket._putObjectAt(r.pos,n);let o=await n._findPlace(r.existingChild.hash);return o.bucket._putAt(o,r.existingChild.key,r.existingChild.value),n._findNewBucketAndPos(r.hash)}return r}_putAt(e,r,n){this._putObjectAt(e.pos,{key:r,value:n,hash:e.hash})}_putObjectAt(e,r){this._children.get(e)==null&&this._popCount++,this._children.set(e,r)}_delAt(e){if(e===-1)throw new Error("Invalid position");this._children.get(e)!=null&&this._popCount--,this._children.unset(e),this._level()}_level(){if(this._parent!=null&&this._popCount<=1)if(this._popCount===1){let e=this._children.find(Ty);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 Ty(t){return!!t}function Iy(t,e){return t.key}function By(t){return t}async function Nl(t,e,r){let n=[];for(let o of t._children.compactArray())if(o instanceof kt)await Nl(o,e,r);else{let i=await e(o);n.push({bitField:t._children.bitField(),children:i})}return r(n)}var Sy=[255,254,252,248,240,224,192,128],Ny=[1,3,7,15,31,63,127,255],To=class{_value;_currentBytePos;_currentBitPos;constructor(e){this._value=e,this._currentBytePos=e.length-1,this._currentBitPos=7}availableBits(){return this._currentBitPos+1+this._currentBytePos*8}totalBits(){return this._value.length*8}take(e){let r=e,n=0;for(;r>0&&this._haveBits();){let o=this._value[this._currentBytePos],i=this._currentBitPos+1,s=Math.min(i,r),a=Uy(o,i-s,s);n=(n<<s)+a,r-=s,this._currentBitPos-=s,this._currentBitPos<0&&(this._currentBitPos=7,this._currentBytePos--)}return n}untake(e){for(this._currentBitPos+=e;this._currentBitPos>7;)this._currentBitPos-=8,this._currentBytePos+=1}_haveBits(){return this._currentBytePos>=0}};function Uy(t,e,r){let n=Cy(e,r);return(t&n)>>>e}function Cy(t,e){return Sy[t]&Ny[Math.min(e+t-1,7)]}function Ul(t){function e(r){return r instanceof Io?r:new Io(r,t)}return e}var Io=class{_value;_hashFn;_depth;_availableBits;_currentBufferIndex;_buffers;constructor(e,r){if(!(e instanceof Uint8Array))throw new Error("can only hash Uint8Arrays");this._value=e,this._hashFn=r,this._depth=-1,this._availableBits=0,this._currentBufferIndex=0,this._buffers=[]}async take(e){let r=e;for(;this._availableBits<r;)await this._produceMoreBits();let n=0;for(;r>0;){let o=this._buffers[this._currentBufferIndex],i=Math.min(o.availableBits(),r),s=o.take(i);n=(n<<i)+s,r-=i,this._availableBits-=i,o.availableBits()===0&&this._currentBufferIndex++}return n}untake(e){let r=e;for(;r>0;){let n=this._buffers[this._currentBufferIndex],o=Math.min(n.totalBits()-n.availableBits(),r);n.untake(o),r-=o,this._availableBits+=o,this._currentBufferIndex>0&&n.totalBits()===n.availableBits()&&(this._depth--,this._currentBufferIndex--)}}async _produceMoreBits(){this._depth++;let e=this._depth>0?Mr([this._value,Uint8Array.from([this._depth])]):this._value,r=await this._hashFn(e),n=new To(r);this._buffers.push(n),this._availableBits+=n.availableBits()}};function Cl(t){if(t==null||t.hashFn==null)throw new Error("please define an options.hashFn");let e={bits:t.bits??8,hash:Ul(t.hashFn)};return new kt(e)}var Dy=async function(t){return(await Al.encode(t)).slice(0,8).reverse()},Ly=async(t,e,r)=>{let n=(e.tableSize()-1).toString(16).length;await Promise.all(t.map(async o=>{if(o.Name==null)throw new Error("Unexpected Link without a Name");if(o.Name.length===n){let i=parseInt(o.Name,16);e._putObjectAt(i,new kt({hash:r._options.hash,bits:r._options.bits},e,i));return}await r.put(o.Name.substring(2),!0)}))},Dl=(t,e)=>t.toString(16).toUpperCase().padStart(e,"0").substring(0,e),$y=t=>{let e=t.bucket,r=[];for(;e._parent!=null;)r.push(e),e=e._parent;return r.push(e),r.reverse()};async function*Ds(t,e,r,n,o,i){if(o==null){if(t.Data==null)throw new F("No data in PBNode");let k;try{k=Z.unmarshal(t.Data)}catch(w){throw new F(w.message)}if(k.type!=="hamt-sharded-directory")throw new F("Not a HAMT");if(k.fanout==null)throw new F("Missing fanout");let v=Cl({hashFn:Dy,bits:Math.log2(Number(k.fanout))});o={rootBucket:v,hamtDepth:1,lastBucket:v}}let s=(o.lastBucket.tableSize()-1).toString(16).length;await Ly(t.Links,o.lastBucket,o.rootBucket);let a=await o.rootBucket._findNewBucketAndPos(e),c=Dl(a.pos,s),f=$y(a);f.length>o.hamtDepth&&(o.lastBucket=f[o.hamtDepth],c=Dl(o.lastBucket._posAtParent,s));let l=t.Links.find(k=>{if(k.Name==null)return!1;let v=k.Name.substring(0,s),w=k.Name.substring(s);return!(v!==c||w!==""&&w!==e)});if(l==null)return;if(l.Name!=null&&l.Name.substring(s)===e){yield{cid:l.Hash,name:l.Name.substring(s),rest:r};return}o.hamtDepth++;let p=await C(n.get(l.Hash,i));t=ze(p),i?.yieldSubShards===!0&&(yield{cid:l.Hash,name:l.Name??"",rest:[e,...r]}),yield*Ds(t,e,r,n,o,i)}async function*Ll(t,e,r,n){let o=await C(r.get(t,n)),i;try{i=ze(o)}catch(a){throw new F(a.message)}if(i.Data==null)throw new F("no data in PBNode");let s;try{s=Z.unmarshal(i.Data)}catch(a){throw new F(a.message)}if(s.type==="directory"||s.type==="hamt-sharded-directory"&&n?.translateHAMTPath===!1){let a=i.Links.find(c=>c.Name===e[0]);if(a==null)throw new xe(`No link "${e[0]}" found under ${t}`);yield{cid:a.Hash,name:e[0],rest:e.slice(1)}}else if(s.type==="hamt-sharded-directory"){let a=!1;for await(let c of Ds(i,e[0],e.slice(1),r,void 0,n))c.name===e[0]&&(a=!0),yield c;if(!a)throw new xe(`No link "${e[0]}" found under ${t}`)}}async function*$l(t,e,r,n){if(e.length!==0)throw new or(`Cannot load path /${e.join("/")} from identity block`)}async function*Rl(t,e,r,n){let o=await C(r.get(t,n)),i=Vn(o),s=ar(i,e);yield{cid:t,name:s.path,rest:s.rest}}async function*Fl(t,e,r,n){if(e.length!==0)throw new xe(`Cannot load path /${e.join("/")} from raw block`)}var Fy={[tr]:Ll,[Vt]:Fl,[vn]:Ss,81:Ss,[po]:El,[Fr.code]:$l,[jn]:Rl};async function*Bo(t,e,r={}){for(t=t.toString(),t.startsWith("/ipfs/")&&(t=t.substring(6));t.endsWith("/");)t=t.substring(0,t.length-1);let[n,...o]=t.split(/(?<!\\)\//g).filter(Boolean),i=B.parse(n),s=[i],a=`${i}`;for(yield{cid:i,name:a,path:a,roots:s,remainder:o};o.length>0;){let c=Fy[i.code];if(c==null)throw new ir(`No resolver for code ${i.code}`);let f=!1;for await(let l of c(i,o,e,r)){if(i=l.cid,f=!s[s.length-1].equals(i),o=l.rest,!f)break;s=[...s,l.cid],a=`${a}/${l.name}`,yield{cid:l.cid,name:l.name,path:a,roots:s,remainder:l.rest}}if(!f)break}if(r?.signal?.throwIfAborted(),o.length!==0)throw new xe(`Could not resolve path /${o.join("/")} under ${t}`)}function My(t){return t[Symbol.asyncIterator]!=null}function Py(t){if(My(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 Ml=Py;async function Ls(t,e,r,n,o){let i=await C(n.get(t,o)),s=dt(i);return{type:"object",cid:t,name:e,path:r,object:s,node:i}}async function Pl(t,e,r,n,o){let i=await C(n.get(t,o)),s=mo(i);return{type:"object",cid:t,name:e,path:r,object:s,node:i}}function on(t,e,r,n){let o=BigInt(t.length),i=BigInt(e+o);return r>=i||n<e?new Uint8Array(0):(n>=e&&n<i&&(t=t.subarray(0,Number(n-e))),r>=e&&r<i&&(t=t.subarray(Number(r-e))),t)}var So=(t,e=0,r=t)=>{let n=BigInt(t),o=BigInt(e??0),i=BigInt(r);if(i!==n&&(i=o+i),i>n&&(i=n),o<0n)throw new Je("Offset must be greater than or equal to 0");if(o>n)throw new Je("Offset must be less than the file size");if(i<0n)throw new Je("Length must be greater than or equal to 0");if(i>n)throw new Je("Length must be less than the file size");return{start:o,end:i}};function No(t,e){async function*r(n={}){let{start:o,end:i}=So(t.length,n.offset,n.length),s=on(t,0n,o,i);n.onProgress?.(new X(e,{bytesRead:BigInt(s.byteLength),totalBytes:i-o,fileSize:BigInt(t.byteLength)})),yield s}return r}async function Ol(t,e,r,n,o){let i=Rt(t.multihash.bytes);return{type:"identity",cid:t,name:e,path:r,content:No(i.digest,"unixfs:exporter:progress:identity"),size:BigInt(i.bytes.length),node:i.bytes}}async function zl(t,e,r,n,o){let i=await C(n.get(t,o)),s=Vn(i);return{type:"object",cid:t,name:e,path:r,object:s,node:i}}async function Hl(t,e,r,n,o){let i=await C(n.get(t,o));return{type:"raw",cid:t,name:e,path:r,content:No(i,"unixfs:exporter:progress:raw"),size:BigInt(i.length),node:i}}function jl(t,e,r,n){async function*o(i={}){let s=i.offset??0,a=i.length??e.Links.length,c=e.Links.slice(s,a);i.onProgress?.(new X("unixfs:exporter:walk:directory",{cid:t})),yield*c.map(f=>({cid:f.Hash,name:f.Name??"",path:`${n}/${f.Name??""}`}))}return o}var Uo=globalThis.CustomEvent??Event;async function*sn(t,e={}){let r=e.concurrency??1/0;r<1&&(r=1/0);let n=e.ordered??!1,o=new EventTarget,i=[],s=K(),a=K(),c=!1,f,l=!1;o.addEventListener("task-complete",()=>{a.resolve()}),Promise.resolve().then(async()=>{try{for await(let w of t){if(i.length===r&&(s=K(),await s.promise),l)break;let T={done:!1};i.push(T),w().then(I=>{T.done=!0,T.ok=!0,T.value=I,o.dispatchEvent(new Uo("task-complete"))},I=>{T.done=!0,T.err=I,o.dispatchEvent(new Uo("task-complete"))})}c=!0,o.dispatchEvent(new Uo("task-complete"))}catch(w){f=w,o.dispatchEvent(new Uo("task-complete"))}});function p(){return n?i[0]?.done:!!i.find(w=>w.done)}function*k(){for(;i.length>0&&i[0].done;){let w=i[0];if(i.shift(),w.ok)yield w.value;else throw l=!0,s.resolve(),w.err;s.resolve()}}function*v(){for(;p();)for(let w=0;w<i.length;w++)if(i[w].done){let T=i[w];if(i.splice(w,1),w--,T.ok)yield T.value;else throw l=!0,s.resolve(),T.err;s.resolve()}}for(;;){if(p()||(a=K(),await a.promise),f!=null||(n?yield*k():yield*v(),f!=null))throw f;if(c&&i.length===0)break}}async function Vl(t,e,r,n,o,i,s){if(e instanceof Uint8Array){let f=on(e,n,o,i);r.push(f);return}if(e.Data==null)throw new F("no data in PBNode");let a;try{a=Z.unmarshal(e.Data)}catch(f){throw new F(f.message)}if(a.data!=null){let f=a.data,l=on(f,n,o,i);r.push(l),n+=BigInt(l.byteLength)}let c=[];if(e.Links.length!==a.blockSizes.length)throw new F("Inconsistent block sizes and dag links");for(let f=0;f<e.Links.length;f++){let l=e.Links[f],p=n,k=p+a.blockSizes[f];if((o>=p&&o<k||i>=p&&i<=k||o<p&&i>k)&&c.push({link:l,blockStart:n}),n=k,n>i)break}await Yn(c,f=>Ot(f,l=>async()=>{let p=await C(t.get(l.link.Hash,s));return{...l,block:p}}),f=>sn(f,{ordered:!0,concurrency:s.blockReadConcurrency}),async f=>{for await(let{link:l,block:p,blockStart:k}of f){let v;switch(l.Hash.code){case tr:v=ze(p);break;case Vt:v=p;break;default:r.end(new F(`Unsupported codec: ${l.Hash.code}`));return}let w=new $r({concurrency:1});w.on("error",T=>{r.end(T)}),w.add(async()=>{s.onProgress?.(new X("unixfs:exporter:walk:file",{cid:l.Hash})),await Vl(t,v,r,k,o,i,s)}),await w.onIdle()}}),n>=i&&r.end()}function $s(t,e,r,n,o){async function*i(s={}){let a=r.fileSize();if(a===void 0)throw new Error("File was a directory");let{start:c,end:f}=So(a,s.offset,s.length);if(f===0n)return;let l=0n,p=f-c,k=Gt();s.onProgress?.(new X("unixfs:exporter:walk:file",{cid:t})),Vl(o,e,k,0n,c,f,s).catch(v=>{k.end(v)});for await(let v of k)if(v!=null){if(l+=BigInt(v.byteLength),l>p)throw k.end(),new vo("Read too many bytes - the file size reported by the UnixFS data in the root node may be incorrect");l===p&&k.end(),s.onProgress?.(new X("unixfs:exporter:progress:unixfs:file",{bytesRead:l,totalBytes:p,fileSize:a})),yield v}if(l<p)throw new Ao("Traversed entire DAG but did not read enough bytes")}return i}async function*ql(t,e,r,n){let o=t.Links;if(t.Data==null)throw new F("no data in PBNode");let i;try{i=Z.unmarshal(t.Data)}catch(c){throw new F(c.message)}if(i.fanout==null)throw new F("missing fanout");let s=(i.fanout-1n).toString(16).length,a=Yn(o,c=>Ot(c,f=>async()=>{let l=f.Name!=null?f.Name.substring(s):null;if(l!=null&&l!=="")return{entries:[{cid:f.Hash,name:l,path:`${e}/${l}`}]};{let p=await C(r.get(f.Hash,n));return t=ze(p),n.onProgress?.(new X("unixfs:exporter:walk:hamt-sharded-directory",{cid:f.Hash})),{entries:ql(t,e,r,n)}}}),c=>sn(c,{ordered:!0,concurrency:n.blockReadConcurrency}));for await(let{entries:c}of a)yield*c}function Gl(t,e,r,n,o){function i(s={}){return s.onProgress?.(new X("unixfs:exporter:walk:hamt-sharded-directory",{cid:t})),ql(e,n,o,s)}return i}var Oy={raw:$s,file:$s,directory:jl,"hamt-sharded-directory":Gl,metadata:(t,e,r,n)=>()=>[],symlink:(t,e,r,n)=>()=>[]};async function Wl(t,e,r,n,o){let i=await C(n.get(t,o)),s;try{s=ze(i)}catch(f){throw new F(f.message)}if(s.Data==null)throw new F("no data in PBNode");let a;try{a=Z.unmarshal(s.Data)}catch(f){throw new F(f.message)}let c=Oy[a.type](t,s,a,r,n);if(c==null)throw new xe("could not find content exporter");return a.isDirectory()?{type:"directory",cid:t,name:e,path:r,entries:c,unixfs:a,node:s}:{type:"file",cid:t,name:e,path:r,content:c,unixfs:a,node:s,size:a.fileSize()}}var zy={[tr]:Wl,[Vt]:Hl,[vn]:Ls,81:Ls,[po]:Pl,[Fr.code]:Ol,[jn]:zl};async function Jl(t,e,r={}){let n,o;if(t instanceof String||typeof t=="string"){let s=await Ml(Bo(t,e,r));if(s==null)throw new xe(`Could not walk path to ${t}`);n=s.cid,o=s.name,t=s.path}else if(B.asCID(t)===t||t instanceof B)n=t,o=t=n.toString();else throw new Je("Path must be string or CID");let i=zy[n.code];if(i==null)throw new ir(`No resolver for code ${n.code}`);return i(n,o,t,e,r)}var Rs=class{root;path;constructor(...e){let r=e[0],n=e[1];if(typeof r=="string")n=r,r=void 0;else if(e.length<2)throw new Error("path or CID and path must be specified");n.startsWith("/")||(n=`/${n}`),this.root=r,this.path=n}async*traverse(e,r,n,o){for await(let i of Bo(`${this.root??e}${this.path}`,r,o)){let s=await Jl(i.cid,r,o);yield Pe({cid:s.cid,bytes:s.node instanceof Uint8Array?s.node:il(s.node),codec:await n(i.cid.code)})}}};function Hy(t){return new xo(t)}return ed(jy);})();
2
+ "use strict";var HeliaCar=(()=>{var Yl=Object.create;var fn=Object.defineProperty;var Zl=Object.getOwnPropertyDescriptor;var ed=Object.getOwnPropertyNames;var td=Object.getPrototypeOf,rd=Object.prototype.hasOwnProperty;var ft=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),oe=(t,e)=>{for(var r in e)fn(t,r,{get:e[r],enumerable:!0})},Os=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of ed(e))!rd.call(t,o)&&o!==r&&fn(t,o,{get:()=>e[o],enumerable:!(n=Zl(e,o))||n.enumerable});return t};var Tt=(t,e,r)=>(r=t!=null?Yl(td(t)):{},Os(e||!t||!t.__esModule?fn(r,"default",{value:t,enumerable:!0}):r,t)),nd=t=>Os(fn({},"__esModule",{value:!0}),t);var ac=ft((p0,sc)=>{sc.exports=si;var ic=128,Ch=127,Dh=~Ch,Lh=Math.pow(2,31);function si(t,e,r){if(Number.MAX_SAFE_INTEGER&&t>Number.MAX_SAFE_INTEGER)throw si.bytes=0,new RangeError("Could not encode varint");e=e||[],r=r||0;for(var n=r;t>=Lh;)e[r++]=t&255|ic,t/=128;for(;t&Dh;)e[r++]=t&255|ic,t>>>=7;return e[r]=t|0,si.bytes=r-n+1,e}});var fc=ft((m0,uc)=>{uc.exports=ai;var $h=128,cc=127;function ai(t,n){var r=0,n=n||0,o=0,i=n,s,a=t.length;do{if(i>=a||o>49)throw ai.bytes=0,new RangeError("Could not decode varint");s=t[i++],r+=o<28?(s&cc)<<o:(s&cc)*Math.pow(2,o),o+=7}while(s>=$h);return ai.bytes=i-n,r}});var dc=ft((y0,lc)=>{var Rh=Math.pow(2,7),Fh=Math.pow(2,14),Mh=Math.pow(2,21),Ph=Math.pow(2,28),Oh=Math.pow(2,35),zh=Math.pow(2,42),jh=Math.pow(2,49),Hh=Math.pow(2,56),Vh=Math.pow(2,63);lc.exports=function(t){return t<Rh?1:t<Fh?2:t<Mh?3:t<Ph?4:t<Oh?5:t<zh?6:t<jh?7:t<Hh?8:t<Vh?9:10}});var In=ft((g0,hc)=>{hc.exports={encode:ac(),decode:fc(),encodingLength:dc()}});var _u=ft((Hw,Si)=>{"use strict";var Ip=Object.prototype.hasOwnProperty,ee="~";function $r(){}Object.create&&($r.prototype=Object.create(null),new $r().__proto__||(ee=!1));function Bp(t,e,r){this.fn=t,this.context=e,this.once=r||!1}function Eu(t,e,r,n,o){if(typeof r!="function")throw new TypeError("The listener must be a function");var i=new Bp(r,n||t,o),s=ee?ee+e:e;return t._events[s]?t._events[s].fn?t._events[s]=[t._events[s],i]:t._events[s].push(i):(t._events[s]=i,t._eventsCount++),t}function qn(t,e){--t._eventsCount===0?t._events=new $r:delete t._events[e]}function X(){this._events=new $r,this._eventsCount=0}X.prototype.eventNames=function(){var e=[],r,n;if(this._eventsCount===0)return e;for(n in r=this._events)Ip.call(r,n)&&e.push(ee?n.slice(1):n);return Object.getOwnPropertySymbols?e.concat(Object.getOwnPropertySymbols(r)):e};X.prototype.listeners=function(e){var r=ee?ee+e:e,n=this._events[r];if(!n)return[];if(n.fn)return[n.fn];for(var o=0,i=n.length,s=new Array(i);o<i;o++)s[o]=n[o].fn;return s};X.prototype.listenerCount=function(e){var r=ee?ee+e:e,n=this._events[r];return n?n.fn?1:n.length:0};X.prototype.emit=function(e,r,n,o,i,s){var a=ee?ee+e:e;if(!this._events[a])return!1;var c=this._events[a],f=arguments.length,l,p;if(c.fn){switch(c.once&&this.removeListener(e,c.fn,void 0,!0),f){case 1:return c.fn.call(c.context),!0;case 2:return c.fn.call(c.context,r),!0;case 3:return c.fn.call(c.context,r,n),!0;case 4:return c.fn.call(c.context,r,n,o),!0;case 5:return c.fn.call(c.context,r,n,o,i),!0;case 6:return c.fn.call(c.context,r,n,o,i,s),!0}for(p=1,l=new Array(f-1);p<f;p++)l[p-1]=arguments[p];c.fn.apply(c.context,l)}else{var v=c.length,k;for(p=0;p<v;p++)switch(c[p].once&&this.removeListener(e,c[p].fn,void 0,!0),f){case 1:c[p].fn.call(c[p].context);break;case 2:c[p].fn.call(c[p].context,r);break;case 3:c[p].fn.call(c[p].context,r,n);break;case 4:c[p].fn.call(c[p].context,r,n,o);break;default:if(!l)for(k=1,l=new Array(f-1);k<f;k++)l[k-1]=arguments[k];c[p].fn.apply(c[p].context,l)}}return!0};X.prototype.on=function(e,r,n){return Eu(this,e,r,n,!1)};X.prototype.once=function(e,r,n){return Eu(this,e,r,n,!0)};X.prototype.removeListener=function(e,r,n,o){var i=ee?ee+e:e;if(!this._events[i])return this;if(!r)return qn(this,i),this;var s=this._events[i];if(s.fn)s.fn===r&&(!o||s.once)&&(!n||s.context===n)&&qn(this,i);else{for(var a=0,c=[],f=s.length;a<f;a++)(s[a].fn!==r||o&&!s[a].once||n&&s[a].context!==n)&&c.push(s[a]);c.length?this._events[i]=c.length===1?c[0]:c:qn(this,i)}return this};X.prototype.removeAllListeners=function(e){var r;return e?(r=ee?ee+e:e,this._events[r]&&qn(this,r)):(this._events=new $r,this._eventsCount=0),this};X.prototype.off=X.prototype.removeListener;X.prototype.addListener=X.prototype.on;X.prefixed=ee;X.EventEmitter=X;typeof Si<"u"&&(Si.exports=X)});var Du=ft((jb,Cu)=>{Cu.exports=function(t){if(!t)throw Error("hashlru must have a max value, of type number, greater than 0");var e=0,r=Object.create(null),n=Object.create(null);function o(i,s){r[i]=s,e++,e>=t&&(e=0,n=r,r=Object.create(null))}return{has:function(i){return r[i]!==void 0||n[i]!==void 0},remove:function(i){r[i]!==void 0&&(r[i]=void 0),n[i]!==void 0&&(n[i]=void 0)},get:function(i){var s=r[i];if(s!==void 0)return s;if((s=n[i])!==void 0)return o(i,s),s},set:function(i,s){r[i]!==void 0?r[i]=s:o(i,s)},clear:function(){r=Object.create(null),n=Object.create(null)}}}});var Ul=ft(($k,Nl)=>{"use strict";Nl.exports=class{constructor(){this._bitArrays=[],this._data=[],this._length=0,this._changedLength=!1,this._changedData=!1}set(e,r){let n=this._internalPositionFor(e,!1);if(r===void 0)n!==-1&&(this._unsetInternalPos(n),this._unsetBit(e),this._changedLength=!0,this._changedData=!0);else{let o=!1;n===-1?(n=this._data.length,this._setBit(e),this._changedData=!0):o=!0,this._setInternalPos(n,e,r,o),this._changedLength=!0}}unset(e){this.set(e,void 0)}get(e){this._sortData();let r=this._internalPositionFor(e,!0);if(r!==-1)return this._data[r][1]}push(e){return this.set(this.length,e),this.length}get length(){if(this._sortData(),this._changedLength){let e=this._data[this._data.length-1];this._length=e?e[0]+1:0,this._changedLength=!1}return this._length}forEach(e){let r=0;for(;r<this.length;)e(this.get(r),r,this),r++}map(e){let r=0,n=new Array(this.length);for(;r<this.length;)n[r]=e(this.get(r),r,this),r++;return n}reduce(e,r){let n=0,o=r;for(;n<this.length;){let i=this.get(n);o=e(o,i,n),n++}return o}find(e){let r=0,n,o;for(;r<this.length&&!n;)o=this.get(r),n=e(o),r++;return n?o:void 0}_internalPositionFor(e,r){let n=this._bytePosFor(e,r);if(n>=this._bitArrays.length)return-1;let o=this._bitArrays[n],i=e-n*7;if(!((o&1<<i)>0))return-1;let a=this._bitArrays.slice(0,n).reduce(Ay,0),c=~(4294967295<<i+1),f=Sl(o&c);return a+f-1}_bytePosFor(e,r){let n=Math.floor(e/7),o=n+1;for(;!r&&this._bitArrays.length<o;)this._bitArrays.push(0);return n}_setBit(e){let r=this._bytePosFor(e,!1);this._bitArrays[r]|=1<<e-r*7}_unsetBit(e){let r=this._bytePosFor(e,!1);this._bitArrays[r]&=~(1<<e-r*7)}_setInternalPos(e,r,n,o){let i=this._data,s=[r,n];if(o)this._sortData(),i[e]=s;else{if(i.length)if(i[i.length-1][0]>=r)i.push(s);else if(i[0][0]<=r)i.unshift(s);else{let a=Math.round(i.length/2);this._data=i.slice(0,a).concat(s).concat(i.slice(a))}else this._data.push(s);this._changedData=!0,this._changedLength=!0}}_unsetInternalPos(e){this._data.splice(e,1)}_sortData(){this._changedData&&this._data.sort(Iy),this._changedData=!1}bitField(){let e=[],r=8,n=0,o=0,i,s=this._bitArrays.slice();for(;s.length||n;){n===0&&(i=s.shift(),n=7);let c=Math.min(n,r),f=~(255<<c),l=i&f;o|=l<<8-r,i=i>>>c,n-=c,r-=c,(!r||!n&&!s.length)&&(e.push(o),o=0,r=8)}for(var a=e.length-1;a>0&&e[a]===0;a--)e.pop();return e}compactArray(){return this._sortData(),this._data.map(By)}};function Ay(t,e){return t+Sl(e)}function Sl(t){let e=t;return e=e-(e>>1&1431655765),e=(e&858993459)+(e>>2&858993459),(e+(e>>4)&252645135)*16843009>>24}function Iy(t,e){return t[0]-e[0]}function By(t){return t[1]}});var Gy={};oe(Gy,{BlockExporter:()=>gs,CIDPath:()=>Us,GraphSearch:()=>Ns,SubgraphExporter:()=>Kr,UnixFSExporter:()=>Yr,UnixFSPath:()=>Ps,breadthFirstWalker:()=>bt,car:()=>qy,depthFirstWalker:()=>wt,naturalOrderWalker:()=>ys});var od=["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 $o(t){if(t===null)return"null";if(t===void 0)return"undefined";if(t===!0||t===!1)return"boolean";let e=typeof t;if(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=id(t);return r||"Object"}function id(t){let e=Object.prototype.toString.call(t).slice(8,-1);if(od.includes(e))return e}var d=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}};d.uint=new d(0,"uint",!0);d.negint=new d(1,"negint",!0);d.bytes=new d(2,"bytes",!0);d.string=new d(3,"string",!0);d.array=new d(4,"array",!1);d.map=new d(5,"map",!1);d.tag=new d(6,"tag",!1);d.float=new d(7,"float",!0);d.false=new d(7,"false",!0);d.true=new d(7,"true",!0);d.null=new d(7,"null",!0);d.undefined=new d(7,"undefined",!0);d.break=new d(7,"break",!0);var E=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 dr=globalThis.process&&!globalThis.process.browser&&globalThis.Buffer&&typeof globalThis.Buffer.isBuffer=="function",sd=new TextEncoder;function ln(t){return dr&&globalThis.Buffer.isBuffer(t)}function hr(t){return t instanceof Uint8Array?ln(t)?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):t:Uint8Array.from(t)}var ad=24,cd=200,dn=dr?t=>t.length>=ad?globalThis.Buffer.from(t):zs(t):t=>t.length>=cd?sd.encode(t):zs(t),De=t=>Uint8Array.from(t),js=dr?(t,e,r)=>ln(t)?new Uint8Array(t.subarray(e,r)):t.slice(e,r):(t,e,r)=>t.slice(e,r),Hs=dr?(t,e)=>(t=t.map(r=>r instanceof Uint8Array?r:globalThis.Buffer.from(r)),hr(globalThis.Buffer.concat(t,e))):(t,e)=>{let r=new Uint8Array(e),n=0;for(let o of t)n+o.length>r.length&&(o=o.subarray(0,r.length-n)),r.set(o,n),n+=o.length;return r},Vs=dr?t=>globalThis.Buffer.allocUnsafe(t):t=>new Uint8Array(t);function hn(t,e){if(ln(t)&&ln(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 zs(t){let e=[],r=0;for(let n=0;n<t.length;n++){let o=t.charCodeAt(n);o<128?e[r++]=o:o<2048?(e[r++]=o>>6|192,e[r++]=o&63|128):(o&64512)===55296&&n+1<t.length&&(t.charCodeAt(n+1)&64512)===56320?(o=65536+((o&1023)<<10)+(t.charCodeAt(++n)&1023),e[r++]=o>>18|240,e[r++]=o>>12&63|128,e[r++]=o>>6&63|128,e[r++]=o&63|128):(o>=55296&&o<=57343&&(o=65533),e[r++]=o>>12|224,e[r++]=o>>6&63|128,e[r++]=o&63|128)}return e}var ud=256,pr=class{constructor(e=ud){this.chunkSize=e,this.cursor=0,this.maxCursor=-1,this.chunks=[],this._initReuseChunk=null}reset(){this.cursor=0,this.maxCursor=-1,this.chunks.length&&(this.chunks=[]),this._initReuseChunk!==null&&(this.chunks.push(this._initReuseChunk),this.maxCursor=this._initReuseChunk.length-1)}push(e){let r=this.chunks[this.chunks.length-1];if(this.cursor+e.length<=this.maxCursor+1){let o=r.length-(this.maxCursor-this.cursor)-1;r.set(e,o)}else{if(r){let o=r.length-(this.maxCursor-this.cursor)-1;o<r.length&&(this.chunks[this.chunks.length-1]=r.subarray(0,o),this.maxCursor=this.cursor-1)}e.length<64&&e.length<this.chunkSize?(r=Vs(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=js(n,0,this.cursor)}else r=Hs(this.chunks,this.cursor);return e&&this.reset(),r}},pn=class{constructor(e){this.dest=e,this.cursor=0,this.chunks=[e]}reset(){this.cursor=0}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 T="CBOR decode error:",mn="CBOR encode error:",mr=[];mr[23]=1;mr[24]=2;mr[25]=3;mr[26]=5;mr[27]=9;function He(t,e,r){if(t.length-e<r)throw new Error(`${T} not enough data for type`)}var H=[24,256,65536,4294967296,BigInt("18446744073709551616")];function ie(t,e,r){He(t,e,1);let n=t[e];if(r.strict===!0&&n<H[0])throw new Error(`${T} integer encoded in more bytes than necessary (strict decode)`);return n}function se(t,e,r){He(t,e,2);let n=t[e]<<8|t[e+1];if(r.strict===!0&&n<H[1])throw new Error(`${T} integer encoded in more bytes than necessary (strict decode)`);return n}function ae(t,e,r){He(t,e,4);let n=t[e]*16777216+(t[e+1]<<16)+(t[e+2]<<8)+t[e+3];if(r.strict===!0&&n<H[2])throw new Error(`${T} integer encoded in more bytes than necessary (strict decode)`);return n}function ce(t,e,r){He(t,e,8);let n=t[e]*16777216+(t[e+1]<<16)+(t[e+2]<<8)+t[e+3],o=t[e+4]*16777216+(t[e+5]<<16)+(t[e+6]<<8)+t[e+7],i=(BigInt(n)<<BigInt(32))+BigInt(o);if(r.strict===!0&&i<H[3])throw new Error(`${T} integer encoded in more bytes than necessary (strict decode)`);if(i<=Number.MAX_SAFE_INTEGER)return Number(i);if(r.allowBigInt===!0)return i;throw new Error(`${T} integers outside of the safe integer range are not supported`)}function qs(t,e,r,n){return new E(d.uint,ie(t,e+1,n),2)}function Gs(t,e,r,n){return new E(d.uint,se(t,e+1,n),3)}function Ws(t,e,r,n){return new E(d.uint,ae(t,e+1,n),5)}function Js(t,e,r,n){return new E(d.uint,ce(t,e+1,n),9)}function we(t,e){return $(t,0,e.value)}function $(t,e,r){if(r<H[0]){let n=Number(r);t.push([e|n])}else if(r<H[1]){let n=Number(r);t.push([e|24,n])}else if(r<H[2]){let n=Number(r);t.push([e|25,n>>>8,n&255])}else if(r<H[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<H[4]){let o=[e|27,0,0,0,0,0,0,0],i=Number(n&BigInt(4294967295)),s=Number(n>>BigInt(32)&BigInt(4294967295));o[8]=i&255,i=i>>8,o[7]=i&255,i=i>>8,o[6]=i&255,i=i>>8,o[5]=i&255,o[4]=s&255,s=s>>8,o[3]=s&255,s=s>>8,o[2]=s&255,s=s>>8,o[1]=s&255,t.push(o)}else throw new Error(`${T} encountered BigInt larger than allowable range`)}}we.encodedSize=function(e){return $.encodedSize(e.value)};$.encodedSize=function(e){return e<H[0]?1:e<H[1]?2:e<H[2]?3:e<H[3]?5:9};we.compareTokens=function(e,r){return e.value<r.value?-1:e.value>r.value?1:0};function Qs(t,e,r,n){return new E(d.negint,-1-ie(t,e+1,n),2)}function Xs(t,e,r,n){return new E(d.negint,-1-se(t,e+1,n),3)}function Ks(t,e,r,n){return new E(d.negint,-1-ae(t,e+1,n),5)}var Ro=BigInt(-1),Ys=BigInt(1);function Zs(t,e,r,n){let o=ce(t,e+1,n);if(typeof o!="bigint"){let i=-1-o;if(i>=Number.MIN_SAFE_INTEGER)return new E(d.negint,i,9)}if(n.allowBigInt!==!0)throw new Error(`${T} integers outside of the safe integer range are not supported`);return new E(d.negint,Ro-BigInt(o),9)}function yn(t,e){let r=e.value,n=typeof r=="bigint"?r*Ro-Ys:r*-1-1;$(t,e.type.majorEncoded,n)}yn.encodedSize=function(e){let r=e.value,n=typeof r=="bigint"?r*Ro-Ys:r*-1-1;return n<H[0]?1:n<H[1]?2:n<H[2]?3:n<H[3]?5:9};yn.compareTokens=function(e,r){return e.value<r.value?1:e.value>r.value?-1:0};function yr(t,e,r,n){He(t,e,r+n);let o=t.slice(e+r,e+r+n);return new E(d.bytes,o,r+n)}function ea(t,e,r,n){return yr(t,e,1,r)}function ta(t,e,r,n){return yr(t,e,2,ie(t,e+1,n))}function ra(t,e,r,n){return yr(t,e,3,se(t,e+1,n))}function na(t,e,r,n){return yr(t,e,5,ae(t,e+1,n))}function oa(t,e,r,n){let o=ce(t,e+1,n);if(typeof o=="bigint")throw new Error(`${T} 64-bit integer bytes lengths not supported`);return yr(t,e,9,o)}function gn(t){return t.encodedBytes===void 0&&(t.encodedBytes=d.equals(t.type,d.string)?dn(t.value):t.value),t.encodedBytes}function At(t,e){let r=gn(e);$(t,e.type.majorEncoded,r.length),t.push(r)}At.encodedSize=function(e){let r=gn(e);return $.encodedSize(r.length)+r.length};At.compareTokens=function(e,r){return ld(gn(e),gn(r))};function ld(t,e){return t.length<e.length?-1:t.length>e.length?1:hn(t,e)}var ia=new TextDecoder,hd=32;function pd(t,e,r){if(r-e<hd){let o="";for(let i=e;i<r;i++){let s=t[i];if(s&128)return ia.decode(t.subarray(e,r));o+=String.fromCharCode(s)}return o}return ia.decode(t.subarray(e,r))}function gr(t,e,r,n,o){let i=r+n;He(t,e,i);let s=new E(d.string,pd(t,e+r,e+i),i);return o.retainStringBytes===!0&&(s.byteValue=t.slice(e+r,e+i)),s}function sa(t,e,r,n){return gr(t,e,1,r,n)}function aa(t,e,r,n){return gr(t,e,2,ie(t,e+1,n),n)}function ca(t,e,r,n){return gr(t,e,3,se(t,e+1,n),n)}function ua(t,e,r,n){return gr(t,e,5,ae(t,e+1,n),n)}function fa(t,e,r,n){let o=ce(t,e+1,n);if(typeof o=="bigint")throw new Error(`${T} 64-bit integer string lengths not supported`);return gr(t,e,9,o,n)}var la=At;function It(t,e,r,n){return new E(d.array,n,r)}function da(t,e,r,n){return It(t,e,1,r)}function ha(t,e,r,n){return It(t,e,2,ie(t,e+1,n))}function pa(t,e,r,n){return It(t,e,3,se(t,e+1,n))}function ma(t,e,r,n){return It(t,e,5,ae(t,e+1,n))}function ya(t,e,r,n){let o=ce(t,e+1,n);if(typeof o=="bigint")throw new Error(`${T} 64-bit integer array lengths not supported`);return It(t,e,9,o)}function ga(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${T} indefinite length items not allowed`);return It(t,e,1,1/0)}function xn(t,e){$(t,d.array.majorEncoded,e.value)}xn.compareTokens=we.compareTokens;xn.encodedSize=function(e){return $.encodedSize(e.value)};function Bt(t,e,r,n){return new E(d.map,n,r)}function xa(t,e,r,n){return Bt(t,e,1,r)}function wa(t,e,r,n){return Bt(t,e,2,ie(t,e+1,n))}function ba(t,e,r,n){return Bt(t,e,3,se(t,e+1,n))}function Ea(t,e,r,n){return Bt(t,e,5,ae(t,e+1,n))}function _a(t,e,r,n){let o=ce(t,e+1,n);if(typeof o=="bigint")throw new Error(`${T} 64-bit integer map lengths not supported`);return Bt(t,e,9,o)}function va(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${T} indefinite length items not allowed`);return Bt(t,e,1,1/0)}function wn(t,e){$(t,d.map.majorEncoded,e.value)}wn.compareTokens=we.compareTokens;wn.encodedSize=function(e){return $.encodedSize(e.value)};function ka(t,e,r,n){return new E(d.tag,r,1)}function Ta(t,e,r,n){return new E(d.tag,ie(t,e+1,n),2)}function Aa(t,e,r,n){return new E(d.tag,se(t,e+1,n),3)}function Ia(t,e,r,n){return new E(d.tag,ae(t,e+1,n),5)}function Ba(t,e,r,n){return new E(d.tag,ce(t,e+1,n),9)}function bn(t,e){$(t,d.tag.majorEncoded,e.value)}bn.compareTokens=we.compareTokens;bn.encodedSize=function(e){return $.encodedSize(e.value)};var Fo=20,Mo=21,Po=22,Oo=23;function Sa(t,e,r,n){if(n.allowUndefined===!1)throw new Error(`${T} undefined values are not supported`);return n.coerceUndefinedToNull===!0?new E(d.null,null,1):new E(d.undefined,void 0,1)}function Na(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${T} indefinite length items not allowed`);return new E(d.break,void 0,1)}function zo(t,e,r){if(r){if(r.allowNaN===!1&&Number.isNaN(t))throw new Error(`${T} NaN values are not supported`);if(r.allowInfinity===!1&&(t===1/0||t===-1/0))throw new Error(`${T} Infinity values are not supported`)}return new E(d.float,t,e)}function Ua(t,e,r,n){return zo(jo(t,e+1),3,n)}function Ca(t,e,r,n){return zo(Ho(t,e+1),5,n)}function Da(t,e,r,n){return zo(Fa(t,e+1),9,n)}function xr(t,e,r){let n=e.value;if(n===!1)t.push([d.float.majorEncoded|Fo]);else if(n===!0)t.push([d.float.majorEncoded|Mo]);else if(n===null)t.push([d.float.majorEncoded|Po]);else if(n===void 0)t.push([d.float.majorEncoded|Oo]);else{let o,i=!1;(!r||r.float64!==!0)&&($a(n),o=jo(Ae,1),n===o||Number.isNaN(n)?(Ae[0]=249,t.push(Ae.slice(0,3)),i=!0):(Ra(n),o=Ho(Ae,1),n===o&&(Ae[0]=250,t.push(Ae.slice(0,5)),i=!0))),i||(wd(n),o=Fa(Ae,1),Ae[0]=251,t.push(Ae.slice(0,9)))}}xr.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){$a(n);let o=jo(Ae,1);if(n===o||Number.isNaN(n))return 3;if(Ra(n),o=Ho(Ae,1),n===o)return 5}return 9};var La=new ArrayBuffer(9),be=new DataView(La,1),Ae=new Uint8Array(La,0);function $a(t){if(t===1/0)be.setUint16(0,31744,!1);else if(t===-1/0)be.setUint16(0,64512,!1);else if(Number.isNaN(t))be.setUint16(0,32256,!1);else{be.setFloat32(0,t);let e=be.getUint32(0),r=(e&2139095040)>>23,n=e&8388607;if(r===255)be.setUint16(0,31744,!1);else if(r===0)be.setUint16(0,(e&2147483648)>>16|n>>13,!1);else{let o=r-127;o<-24?be.setUint16(0,0):o<-14?be.setUint16(0,(e&2147483648)>>16|1<<24+o,!1):be.setUint16(0,(e&2147483648)>>16|o+15<<10|n>>13,!1)}}}function jo(t,e){if(t.length-e<2)throw new Error(`${T} not enough data for float16`);let r=(t[e]<<8)+t[e+1];if(r===31744)return 1/0;if(r===64512)return-1/0;if(r===32256)return NaN;let n=r>>10&31,o=r&1023,i;return n===0?i=o*2**-24:n!==31?i=(o+1024)*2**(n-25):i=o===0?1/0:NaN,r&32768?-i:i}function Ra(t){be.setFloat32(0,t,!1)}function Ho(t,e){if(t.length-e<4)throw new Error(`${T} not enough data for float32`);let r=(t.byteOffset||0)+e;return new DataView(t.buffer,r,4).getFloat32(0,!1)}function wd(t){be.setFloat64(0,t,!1)}function Fa(t,e){if(t.length-e<8)throw new Error(`${T} not enough data for float64`);let r=(t.byteOffset||0)+e;return new DataView(t.buffer,r,8).getFloat64(0,!1)}xr.compareTokens=we.compareTokens;function S(t,e,r){throw new Error(`${T} encountered invalid minor (${r}) for major ${t[e]>>>5}`)}function En(t){return()=>{throw new Error(`${T} ${t}`)}}var y=[];for(let t=0;t<=23;t++)y[t]=S;y[24]=qs;y[25]=Gs;y[26]=Ws;y[27]=Js;y[28]=S;y[29]=S;y[30]=S;y[31]=S;for(let t=32;t<=55;t++)y[t]=S;y[56]=Qs;y[57]=Xs;y[58]=Ks;y[59]=Zs;y[60]=S;y[61]=S;y[62]=S;y[63]=S;for(let t=64;t<=87;t++)y[t]=ea;y[88]=ta;y[89]=ra;y[90]=na;y[91]=oa;y[92]=S;y[93]=S;y[94]=S;y[95]=En("indefinite length bytes/strings are not supported");for(let t=96;t<=119;t++)y[t]=sa;y[120]=aa;y[121]=ca;y[122]=ua;y[123]=fa;y[124]=S;y[125]=S;y[126]=S;y[127]=En("indefinite length bytes/strings are not supported");for(let t=128;t<=151;t++)y[t]=da;y[152]=ha;y[153]=pa;y[154]=ma;y[155]=ya;y[156]=S;y[157]=S;y[158]=S;y[159]=ga;for(let t=160;t<=183;t++)y[t]=xa;y[184]=wa;y[185]=ba;y[186]=Ea;y[187]=_a;y[188]=S;y[189]=S;y[190]=S;y[191]=va;for(let t=192;t<=215;t++)y[t]=ka;y[216]=Ta;y[217]=Aa;y[218]=Ia;y[219]=Ba;y[220]=S;y[221]=S;y[222]=S;y[223]=S;for(let t=224;t<=243;t++)y[t]=En("simple values are not supported");y[244]=S;y[245]=S;y[246]=S;y[247]=Sa;y[248]=En("simple values are not supported");y[249]=Ua;y[250]=Ca;y[251]=Da;y[252]=S;y[253]=S;y[254]=S;y[255]=Na;var Ie=[];for(let t=0;t<24;t++)Ie[t]=new E(d.uint,t,1);for(let t=-1;t>=-24;t--)Ie[31-t]=new E(d.negint,t,1);Ie[64]=new E(d.bytes,new Uint8Array(0),1);Ie[96]=new E(d.string,"",1);Ie[128]=new E(d.array,0,1);Ie[160]=new E(d.map,0,1);Ie[244]=new E(d.false,!1,1);Ie[245]=new E(d.true,!0,1);Ie[246]=new E(d.null,null,1);function Vo(t){switch(t.type){case d.false:return De([244]);case d.true:return De([245]);case d.null:return De([246]);case d.bytes:return t.value.length?void 0:De([64]);case d.string:return t.value===""?De([96]):void 0;case d.array:return t.value===0?De([128]):void 0;case d.map:return t.value===0?De([160]):void 0;case d.uint:return t.value<24?De([Number(t.value)]):void 0;case d.negint:if(t.value>=-24)return De([31-Number(t.value)])}}var Ed={float64:!1,mapSorter:kd,quickEncodeToken:Vo},ja=Object.freeze({float64:!0,mapSorter:Td,quickEncodeToken:Vo});function _d(){let t=[];return t[d.uint.major]=we,t[d.negint.major]=yn,t[d.bytes.major]=At,t[d.string.major]=la,t[d.array.major]=xn,t[d.map.major]=wn,t[d.tag.major]=bn,t[d.float.major]=xr,t}var Nt=_d(),_n=new pr,br=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(`${mn} object contains circular references`);return new t(r,e)}},Qe={null:new E(d.null,null),undefined:new E(d.undefined,void 0),true:new E(d.true,!0),false:new E(d.false,!1),emptyArray:new E(d.array,0),emptyMap:new E(d.map,0)},Le={number(t,e,r,n){return!Number.isInteger(t)||!Number.isSafeInteger(t)?new E(d.float,t):t>=0?new E(d.uint,t):new E(d.negint,t)},bigint(t,e,r,n){return t>=BigInt(0)?new E(d.uint,t):new E(d.negint,t)},Uint8Array(t,e,r,n){return new E(d.bytes,t)},string(t,e,r,n){return new E(d.string,t)},boolean(t,e,r,n){return t?Qe.true:Qe.false},null(t,e,r,n){return Qe.null},undefined(t,e,r,n){return Qe.undefined},ArrayBuffer(t,e,r,n){return new E(d.bytes,new Uint8Array(t))},DataView(t,e,r,n){return new E(d.bytes,new Uint8Array(t.buffer,t.byteOffset,t.byteLength))},Array(t,e,r,n){if(!t.length)return r.addBreakTokens===!0?[Qe.emptyArray,new E(d.break)]:Qe.emptyArray;n=br.createCheck(n,t);let o=[],i=0;for(let s of t)o[i++]=St(s,r,n);return r.addBreakTokens?[new E(d.array,t.length),o,new E(d.break)]:[new E(d.array,t.length),o]},Object(t,e,r,n){let o=e!=="Object",i=o?t.keys():Object.keys(t),s=o?t.size:i.length,a;if(s){a=new Array(s),n=br.createCheck(n,t);let c=!o&&r.ignoreUndefinedProperties,f=0;for(let l of i){let p=o?t.get(l):t[l];c&&p===void 0||(a[f++]=[St(l,r,n),St(p,r,n)])}f<s&&(a.length=f)}return a?.length?(vd(a,r),r.addBreakTokens?[new E(d.map,a.length),a,new E(d.break)]:[new E(d.map,a.length),a]):r.addBreakTokens===!0?[Qe.emptyMap,new E(d.break)]:Qe.emptyMap},Tagged(t,e,r,n){return[new E(d.tag,t.tag),St(t.value,r,n)]}};Le.Map=Le.Object;Le.Buffer=Le.Uint8Array;for(let t of"Uint8Clamped Uint16 Uint32 Int8 Int16 Int32 BigUint64 BigInt64 Float32 Float64".split(" "))Le[`${t}Array`]=Le.DataView;function St(t,e={},r){let n=$o(t),o=e&&e.typeEncoders&&e.typeEncoders[n]||Le[n];if(typeof o=="function"){let s=o(t,n,e,r);if(s!=null)return s}let i=Le[n];if(!i)throw new Error(`${mn} unsupported type: ${n}`);return i(t,n,e,r)}function vd(t,e){e.mapSorter&&t.sort(e.mapSorter)}function kd(t,e){let r=Array.isArray(t[0])?t[0][0]:t[0],n=Array.isArray(e[0])?e[0][0]:e[0];if(r.type!==n.type)return r.type.compare(n.type);let o=r.type.major,i=Nt[o].compareTokens(r,n);return i===0&&console.warn("WARNING: complex key types used, CBOR key sorting guarantees are gone"),i}function Td(t,e){if(t[0]instanceof E&&e[0]instanceof E){let r=t[0],n=e[0];return r._keyBytes||(r._keyBytes=Ma(r.value)),n._keyBytes||(n._keyBytes=Ma(n.value)),hn(r._keyBytes,n._keyBytes)}throw new Error("rfc8949MapSorter: complex key types are not supported yet")}function Ma(t){return Va(t,Nt,ja)}function wr(t,e,r,n){if(Array.isArray(e))for(let o of e)wr(t,o,r,n);else r[e.type.major](t,e,n)}var Pa=d.uint.majorEncoded,Oa=d.negint.majorEncoded,Ad=d.bytes.majorEncoded,Id=d.string.majorEncoded,za=d.array.majorEncoded,Bd=d.float.majorEncoded|Fo,Sd=d.float.majorEncoded|Mo,Nd=d.float.majorEncoded|Po,Ud=d.float.majorEncoded|Oo,Cd=BigInt(-1),Dd=BigInt(1);function Ld(t){return t.addBreakTokens!==!0}function Ha(t,e,r,n){let o=$o(e),i=r.typeEncoders&&r.typeEncoders[o];if(i){let s=i(e,o,r,n);if(s!=null){wr(t,s,Nt,r);return}}switch(o){case"null":t.push([Nd]);return;case"undefined":t.push([Ud]);return;case"boolean":t.push([e?Sd:Bd]);return;case"number":!Number.isInteger(e)||!Number.isSafeInteger(e)?xr(t,new E(d.float,e),r):e>=0?$(t,Pa,e):$(t,Oa,e*-1-1);return;case"bigint":e>=BigInt(0)?$(t,Pa,e):$(t,Oa,e*Cd-Dd);return;case"string":{let s=dn(e);$(t,Id,s.length),t.push(s);return}case"Uint8Array":$(t,Ad,e.length),t.push(e);return;case"Array":if(!e.length){t.push([za]);return}n=br.createCheck(n,e),$(t,za,e.length);for(let s of e)Ha(t,s,r,n);return;case"Object":case"Map":{let s=Le.Object(e,o,r,n);wr(t,s,Nt,r)}return;default:{let s=Le[o];if(!s)throw new Error(`${mn} unsupported type: ${o}`);let a=s(e,o,r,n);wr(t,a,Nt,r)}}}function Va(t,e,r,n){let o=n instanceof Uint8Array,i=o?new pn(n):_n,s=St(t,r);if(!Array.isArray(s)&&r.quickEncodeToken){let a=r.quickEncodeToken(s);if(a)return o?(i.push(a),i.toBytes()):a;let c=e[s.type.major];if(c.encodedSize){let f=c.encodedSize(s,r);if(o||(i=new pr(f)),c(i,s,r),i.chunks.length!==1)throw new Error(`Unexpected error: pre-calculated length for ${s} was wrong`);return o?i.toBytes():hr(i.chunks[0])}}return i.reset(),wr(i,s,e,r),i.toBytes(!0)}function qo(t,e){return e=Object.assign({},Ed,e),Ld(e)?(_n.reset(),Ha(_n,t,e,void 0),_n.toBytes(!0)):Va(t,Nt,e)}var $d={strict:!1,allowIndefinite:!0,allowUndefined:!0,allowBigInt:!0},vn=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=Ie[e];if(r===void 0){let n=y[e];if(!n)throw new Error(`${T} no decoder for major type ${e>>>5} (byte 0x${e.toString(16).padStart(2,"0")})`);let o=e&31;r=n(this.data,this._pos,o,this.options)}return this._pos+=r.encodedLength,r}},Xe=Symbol.for("DONE"),Ut=Symbol.for("BREAK");function Rd(t,e,r){let n=[];for(let o=0;o<t.value;o++){let i=Ke(e,r);if(i===Ut){if(t.value===1/0)break;throw new Error(`${T} got unexpected break to lengthed array`)}if(i===Xe)throw new Error(`${T} found array but not enough entries (got ${o}, expected ${t.value})`);n[o]=i}return n}function Fd(t,e,r){let n=r.useMaps===!0,o=r.rejectDuplicateMapKeys===!0,i=n?void 0:{},s=n?new Map:void 0;for(let a=0;a<t.value;a++){let c=Ke(e,r);if(c===Ut){if(t.value===1/0)break;throw new Error(`${T} got unexpected break to lengthed map`)}if(c===Xe)throw new Error(`${T} found map but not enough entries (got ${a} [no key], expected ${t.value})`);if(!n&&typeof c!="string")throw new Error(`${T} non-string keys not supported (got ${typeof c})`);if(o&&(n&&s.has(c)||!n&&Object.hasOwn(i,c)))throw new Error(`${T} found repeat map key "${c}"`);let f=Ke(e,r);if(f===Xe)throw new Error(`${T} found map but not enough entries (got ${a} [no value], expected ${t.value})`);n?s.set(c,f):i[c]=f}return n?s:i}function*Md(t,e,r){for(let n=0;n<t.value;n++){let o=Ke(e,r);if(o===Ut){if(t.value===1/0)break;throw new Error(`${T} got unexpected break to lengthed map`)}if(o===Xe)throw new Error(`${T} found map but not enough entries (got ${n} [no key], expected ${t.value})`);let i=Ke(e,r);if(i===Xe)throw new Error(`${T} found map but not enough entries (got ${n} [no value], expected ${t.value})`);yield[o,i]}}function Pd(t,e){let r=!1,n=function(){if(r)throw new Error(`${T} tag decode() may only be called once`);r=!0;let o=Ke(t,e);if(o===Xe)throw new Error(`${T} tag content missing`);if(o===Ut)throw new Error(`${T} got unexpected break in tag content`);return o};return n.entries=function(){if(r)throw new Error(`${T} tag decode() may only be called once`);r=!0;let o=t.next();if(!d.equals(o.type,d.map))throw new Error(`${T} entries() requires map content, got ${o.type.name}`);let i=[];for(let s of Md(o,t,e))i.push(s);return i},Object.defineProperty(n,"_called",{get(){return r},enumerable:!1}),n}function Ke(t,e){if(t.done())return Xe;let r=t.next();if(d.equals(r.type,d.break))return Ut;if(r.type.terminal)return r.value;if(d.equals(r.type,d.array))return Rd(r,t,e);if(d.equals(r.type,d.map))return Fd(r,t,e);if(d.equals(r.type,d.tag)){if(e.tags&&typeof e.tags[r.value]=="function"){let n=Pd(t,e),o=e.tags[r.value](n);if(!n._called)throw new Error(`${T} tag decoder must call decode() or entries()`);return o}throw new Error(`${T} tag not supported (${r.value})`)}throw new Error("unsupported")}function qa(t,e){if(!(t instanceof Uint8Array))throw new Error(`${T} data to decode must be a Uint8Array`);e=Object.assign({},$d,e);let r=hr(t),n=e.tokenizer||new vn(r,e),o=Ke(n,e);if(o===Xe)throw new Error(`${T} did not find any content to decode`);if(o===Ut)throw new Error(`${T} got unexpected break`);return[o,t.subarray(n.pos())]}function Go(t,e){let[r,n]=qa(t,e);if(n.length>0)throw new Error(`${T} too many terminals, data makes no sense`);return r}var kn=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(kn.prototype,Symbol.toStringTag,{value:"Tagged"});var Yo={};oe(Yo,{base32:()=>Dt,base32hex:()=>Xd,base32hexpad:()=>Yd,base32hexpadupper:()=>Zd,base32hexupper:()=>Kd,base32pad:()=>Jd,base32padupper:()=>Qd,base32upper:()=>Wd,base32z:()=>eh});var Jg=new Uint8Array(0);function Ga(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 Ve(t){if(t instanceof Uint8Array&&t.constructor.name==="Uint8Array")return t;if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.isView(t))return new Uint8Array(t.buffer,t.byteOffset,t.byteLength);throw new Error("Unknown type, must be binary type")}function Wa(t){return new TextEncoder().encode(t)}function Ja(t){return new TextDecoder().decode(t)}function zd(t,e){if(t.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),n=0;n<r.length;n++)r[n]=255;for(var o=0;o<t.length;o++){var i=t.charAt(o),s=i.charCodeAt(0);if(r[s]!==255)throw new TypeError(i+" is ambiguous");r[s]=o}var a=t.length,c=t.charAt(0),f=Math.log(a)/Math.log(256),l=Math.log(256)/Math.log(a);function p(w){if(w instanceof Uint8Array||(ArrayBuffer.isView(w)?w=new Uint8Array(w.buffer,w.byteOffset,w.byteLength):Array.isArray(w)&&(w=Uint8Array.from(w))),!(w instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(w.length===0)return"";for(var A=0,I=0,R=0,z=w.length;R!==z&&w[R]===0;)R++,A++;for(var P=(z-R)*l+1>>>0,J=new Uint8Array(P);R!==z;){for(var j=w[R],re=0,ne=P-1;(j!==0||re<I)&&ne!==-1;ne--,re++)j+=256*J[ne]>>>0,J[ne]=j%a>>>0,j=j/a>>>0;if(j!==0)throw new Error("Non-zero carry");I=re,R++}for(var je=P-I;je!==P&&J[je]===0;)je++;for(var un=c.repeat(A);je<P;++je)un+=t.charAt(J[je]);return un}function v(w){if(typeof w!="string")throw new TypeError("Expected String");if(w.length===0)return new Uint8Array;var A=0;if(w[A]!==" "){for(var I=0,R=0;w[A]===c;)I++,A++;for(var z=(w.length-A)*f+1>>>0,P=new Uint8Array(z);w[A];){var J=r[w.charCodeAt(A)];if(J===255)return;for(var j=0,re=z-1;(J!==0||j<R)&&re!==-1;re--,j++)J+=a*P[re]>>>0,P[re]=J%256>>>0,J=J/256>>>0;if(J!==0)throw new Error("Non-zero carry");R=j,A++}if(w[A]!==" "){for(var ne=z-R;ne!==z&&P[ne]===0;)ne++;for(var je=new Uint8Array(I+(z-ne)),un=I;ne!==z;)je[un++]=P[ne++];return je}}}function k(w){var A=v(w);if(A)return A;throw new Error(`Non-${e} character`)}return{encode:p,decodeUnsafe:v,decode:k}}var jd=zd,Hd=jd,Qa=Hd;var Jo=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")}},Qo=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,r,n){this.name=e,this.prefix=r;let o=r.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(e){if(typeof e=="string"){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(e){return Xa(this,e)}},Xo=class{decoders;constructor(e){this.decoders=e}or(e){return Xa(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 Xa(t,e){return new Xo({...t.decoders??{[t.prefix]:t},...e.decoders??{[e.prefix]:e}})}var Ko=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,r,n,o){this.name=e,this.prefix=r,this.baseEncode=n,this.baseDecode=o,this.encoder=new Jo(e,r,n),this.decoder=new Qo(e,r,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function Ct({name:t,prefix:e,encode:r,decode:n}){return new Ko(t,e,r,n)}function Ye({name:t,prefix:e,alphabet:r}){let{encode:n,decode:o}=Qa(r,t);return Ct({prefix:e,name:t,encode:n,decode:i=>Ve(o(i))})}function Vd(t,e,r,n){let o=t.length;for(;t[o-1]==="=";)--o;let i=new Uint8Array(o*r/8|0),s=0,a=0,c=0;for(let f=0;f<o;++f){let l=e[t[f]];if(l===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|l,s+=r,s>=8&&(s-=8,i[c++]=255&a>>s)}if(s>=r||(255&a<<8-s)!==0)throw new SyntaxError("Unexpected end of data");return i}function qd(t,e,r){let n=e[e.length-1]==="=",o=(1<<r)-1,i="",s=0,a=0;for(let c=0;c<t.length;++c)for(a=a<<8|t[c],s+=8;s>r;)s-=r,i+=e[o&a>>s];if(s!==0&&(i+=e[o&a<<r-s]),n)for(;(i.length*r&7)!==0;)i+="=";return i}function Gd(t){let e={};for(let r=0;r<t.length;++r)e[t[r]]=r;return e}function O({name:t,prefix:e,bitsPerChar:r,alphabet:n}){let o=Gd(n);return Ct({prefix:e,name:t,encode(i){return qd(i,n,r)},decode(i){return Vd(i,o,r,t)}})}var Dt=O({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Wd=O({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Jd=O({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Qd=O({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Xd=O({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Kd=O({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Yd=O({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Zd=O({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),eh=O({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Zo={};oe(Zo,{base36:()=>Er,base36upper:()=>th});var Er=Ye({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),th=Ye({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var ei={};oe(ei,{base58btc:()=>$e,base58flickr:()=>rh});var $e=Ye({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),rh=Ye({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var nh=Za,Ka=128,oh=127,ih=~oh,sh=Math.pow(2,31);function Za(t,e,r){e=e||[],r=r||0;for(var n=r;t>=sh;)e[r++]=t&255|Ka,t/=128;for(;t&ih;)e[r++]=t&255|Ka,t>>>=7;return e[r]=t|0,Za.bytes=r-n+1,e}var ah=ti,ch=128,Ya=127;function ti(t,n){var r=0,n=n||0,o=0,i=n,s,a=t.length;do{if(i>=a)throw ti.bytes=0,new RangeError("Could not decode varint");s=t[i++],r+=o<28?(s&Ya)<<o:(s&Ya)*Math.pow(2,o),o+=7}while(s>=ch);return ti.bytes=i-n,r}var uh=Math.pow(2,7),fh=Math.pow(2,14),lh=Math.pow(2,21),dh=Math.pow(2,28),hh=Math.pow(2,35),ph=Math.pow(2,42),mh=Math.pow(2,49),yh=Math.pow(2,56),gh=Math.pow(2,63),xh=function(t){return t<uh?1:t<fh?2:t<lh?3:t<dh?4:t<hh?5:t<ph?6:t<mh?7:t<yh?8:t<gh?9:10},wh={encode:nh,decode:ah,encodingLength:xh},bh=wh,_r=bh;function vr(t,e=0){return[_r.decode(t,e),_r.decode.bytes]}function Lt(t,e,r=0){return _r.encode(t,e,r),e}function $t(t){return _r.encodingLength(t)}function Ft(t,e){let r=e.byteLength,n=$t(t),o=n+$t(r),i=new Uint8Array(o+r);return Lt(t,i,0),Lt(r,i,n),i.set(e,o),new Rt(t,r,e,i)}function Mt(t){let e=Ve(t),[r,n]=vr(e),[o,i]=vr(e.subarray(n)),s=e.subarray(n+i);if(s.byteLength!==o)throw new Error("Incorrect length");return new Rt(r,o,s,e)}function ec(t,e){if(t===e)return!0;{let r=e;return t.code===r.code&&t.size===r.size&&r.bytes instanceof Uint8Array&&Ga(t.bytes,r.bytes)}}var Rt=class{code;size;digest;bytes;constructor(e,r,n,o){this.code=e,this.size=r,this.digest=n,this.bytes=o}};function tc(t,e){let{bytes:r,version:n}=t;switch(n){case 0:return _h(r,ri(t),e??$e.encoder);default:return vh(r,ri(t),e??Dt.encoder)}}var rc=new WeakMap;function ri(t){let e=rc.get(t);if(e==null){let r=new Map;return rc.set(t,r),r}return e}var B=class t{code;version;multihash;bytes;"/";constructor(e,r,n,o){this.code=r,this.version=e,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:e,multihash:r}=this;if(e!==kr)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==kh)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=Ft(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&&ec(e.multihash,n.multihash)}toString(e){return tc(this,e)}toJSON(){return{"/":tc(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(e){if(e==null)return null;let r=e;if(r instanceof t)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:o,multihash:i,bytes:s}=r;return new t(n,o,i,s??nc(n,o,i.bytes))}else if(r[Th]===!0){let{version:n,multihash:o,code:i}=r,s=Mt(o);return t.create(n,i,s)}else return null}static create(e,r,n){if(typeof r!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(e){case 0:{if(r!==kr)throw new Error(`Version 0 CID must use dag-pb (code: ${kr}) block encoding`);return new t(e,r,n,n.bytes)}case 1:{let o=nc(e,r,n.bytes);return new t(e,r,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return t.create(0,kr,e)}static createV1(e,r){return t.create(1,e,r)}static decode(e){let[r,n]=t.decodeFirst(e);if(n.length!==0)throw new Error("Incorrect length");return r}static decodeFirst(e){let r=t.inspectBytes(e),n=r.size-r.multihashSize,o=Ve(e.subarray(n,n+r.multihashSize));if(o.byteLength!==r.multihashSize)throw new Error("Incorrect length");let i=o.subarray(r.multihashSize-r.digestSize),s=new Rt(r.multihashCode,r.digestSize,i,o);return[r.version===0?t.createV0(s):t.createV1(r.codec,s),e.subarray(r.size)]}static inspectBytes(e){let r=0,n=()=>{let[p,v]=vr(e.subarray(r));return r+=v,p},o=n(),i=kr;if(o===18?(o=0,r=0):i=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let s=r,a=n(),c=n(),f=r+c,l=f-s;return{version:o,codec:i,multihashCode:a,digestSize:c,multihashSize:l,size:f}}static parse(e,r){let[n,o]=Eh(e,r),i=t.decode(o);if(i.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return ri(i).set(n,e),i}};function Eh(t,e){switch(t[0]){case"Q":{let r=e??$e;return[$e.prefix,r.decode(`${$e.prefix}${t}`)]}case $e.prefix:{let r=e??$e;return[$e.prefix,r.decode(t)]}case Dt.prefix:{let r=e??Dt;return[Dt.prefix,r.decode(t)]}case Er.prefix:{let r=e??Er;return[Er.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 _h(t,e,r){let{prefix:n}=r;if(n!==$e.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let o=e.get(n);if(o==null){let i=r.encode(t).slice(1);return e.set(n,i),i}else return o}function vh(t,e,r){let{prefix:n}=r,o=e.get(n);if(o==null){let i=r.encode(t);return e.set(n,i),i}else return o}var kr=112,kh=18;function nc(t,e,r){let n=$t(t),o=n+$t(e),i=new Uint8Array(o+r.byteLength);return Lt(t,i,0),Lt(e,i,n),i.set(r,o),i}var Th=Symbol.for("@ipld/js-cid/CID");var oc=42;function Ah(t){return t instanceof ArrayBuffer?new Uint8Array(t,0,t.byteLength):t}function Ih(t){if(t.asCID!==t&&t["/"]!==t.bytes)return null;let e=B.asCID(t);if(!e)return null;let r=new Uint8Array(e.bytes.byteLength+1);return r.set(e.bytes,1),[new E(d.tag,oc),new E(d.bytes,r)]}function Bh(){throw new Error("`undefined` is not supported by the IPLD Data Model and cannot be encoded")}function Sh(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 Nh(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 ni={float64:!0,typeEncoders:{Map:Nh,Object:Ih,undefined:Bh,number:Sh}},d0={...ni,typeEncoders:{...ni.typeEncoders}};function Uh(t){let e=t();if(e[0]!==0)throw new Error("Invalid CID for CBOR tag 42; expected leading 0x00");return B.decode(e.subarray(1))}var oi={allowIndefinite:!1,coerceUndefinedToNull:!0,allowNaN:!1,allowInfinity:!1,allowBigInt:!0,strict:!0,useMaps:!1,rejectDuplicateMapKeys:!0,tags:{[oc]:Uh}},h0={...oi,tags:{...oi.tags}};var An=113,ii=t=>qo(t,ni),dt=t=>Go(Ah(t),oi);var ci=Tt(In(),1);var ui=40;function fi(t,e){if(!t.length)throw new Error("Unexpected end of data");let r=ci.default.decode(t);return e.seek(ci.default.decode.bytes),r}function li(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 et={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},Ar={"CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)":et.Link,"CarV1HeaderOrV2Pragma > roots (anon)":t=>{if(et.List(t)!==void 0){for(let e=0;e<t.length;e++){let r=t[e];if(r=Ar["CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)"](r),r===void 0)return;if(r!==t[e]){let n=t.slice(0,e);for(let o=e;o<t.length;o++){let i=t[o];if(i=Ar["CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)"](i),i===void 0)return;n.push(i)}return n}}return t}},Int:et.Int,CarV1HeaderOrV2Pragma:t=>{if(et.Map(t)===void 0)return;let e=Object.entries(t),r=t,n=1;for(let o=0;o<e.length;o++){let[i,s]=e[o];switch(i){case"roots":{let a=Ar["CarV1HeaderOrV2Pragma > roots (anon)"](t[i]);if(a===void 0)return;if(a!==s||r!==t){if(r===t){r={};for(let c=0;c<o;c++)r[e[c][0]]=e[c][1]}r.roots=a}}break;case"version":{n--;let a=Ar.Int(t[i]);if(a===void 0)return;if(a!==s||r!==t){if(r===t){r={};for(let c=0;c<o;c++)r[e[c][0]]=e[c][1]}r.version=a}}break;default:return}}if(!(n>0))return r}},Ir={"CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)":et.Link,"CarV1HeaderOrV2Pragma > roots (anon)":t=>{if(et.List(t)!==void 0){for(let e=0;e<t.length;e++){let r=t[e];if(r=Ir["CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)"](r),r===void 0)return;if(r!==t[e]){let n=t.slice(0,e);for(let o=e;o<t.length;o++){let i=t[o];if(i=Ir["CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)"](i),i===void 0)return;n.push(i)}return n}}return t}},Int:et.Int,CarV1HeaderOrV2Pragma:t=>{if(et.Map(t)===void 0)return;let e=Object.entries(t),r=t,n=1;for(let o=0;o<e.length;o++){let[i,s]=e[o];switch(i){case"roots":{let a=Ir["CarV1HeaderOrV2Pragma > roots (anon)"](s);if(a===void 0)return;if(a!==s||r!==t){if(r===t){r={};for(let c=0;c<o;c++)r[e[c][0]]=e[c][1]}r.roots=a}}break;case"version":{n--;let a=Ir.Int(s);if(a===void 0)return;if(a!==s||r!==t){if(r===t){r={};for(let c=0;c<o;c++)r[e[c][0]]=e[c][1]}r.version=a}}break;default:return}}if(!(n>0))return r}},di={toTyped:Ar.CarV1HeaderOrV2Pragma,toRepresentation:Ir.CarV1HeaderOrV2Pragma};var Jh=["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 pc(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=Qh(t);return r||"Object"}function Qh(t){let e=Object.prototype.toString.call(t).slice(8,-1);if(Jh.includes(e))return e}var h=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}};h.uint=new h(0,"uint",!0);h.negint=new h(1,"negint",!0);h.bytes=new h(2,"bytes",!0);h.string=new h(3,"string",!0);h.array=new h(4,"array",!1);h.map=new h(5,"map",!1);h.tag=new h(6,"tag",!1);h.float=new h(7,"float",!0);h.false=new h(7,"false",!0);h.true=new h(7,"true",!0);h.null=new h(7,"null",!0);h.undefined=new h(7,"undefined",!0);h.break=new h(7,"break",!0);var b=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 Br=globalThis.process&&!globalThis.process.browser&&globalThis.Buffer&&typeof globalThis.Buffer.isBuffer=="function",Xh=new TextEncoder;function Bn(t){return Br&&globalThis.Buffer.isBuffer(t)}function Sn(t){return t instanceof Uint8Array?Bn(t)?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):t:Uint8Array.from(t)}var Kh=24,Yh=200,hi=Br?t=>t.length>=Kh?globalThis.Buffer.from(t):mc(t):t=>t.length>=Yh?Xh.encode(t):mc(t),Re=t=>Uint8Array.from(t),yc=Br?(t,e,r)=>Bn(t)?new Uint8Array(t.subarray(e,r)):t.slice(e,r):(t,e,r)=>t.slice(e,r),gc=Br?(t,e)=>(t=t.map(r=>r instanceof Uint8Array?r:globalThis.Buffer.from(r)),Sn(globalThis.Buffer.concat(t,e))):(t,e)=>{let r=new Uint8Array(e),n=0;for(let o of t)n+o.length>r.length&&(o=o.subarray(0,r.length-n)),r.set(o,n),n+=o.length;return r},xc=Br?t=>globalThis.Buffer.allocUnsafe(t):t=>new Uint8Array(t);function Nn(t,e){if(Bn(t)&&Bn(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 mc(t){let e=[],r=0;for(let n=0;n<t.length;n++){let o=t.charCodeAt(n);o<128?e[r++]=o:o<2048?(e[r++]=o>>6|192,e[r++]=o&63|128):(o&64512)===55296&&n+1<t.length&&(t.charCodeAt(n+1)&64512)===56320?(o=65536+((o&1023)<<10)+(t.charCodeAt(++n)&1023),e[r++]=o>>18|240,e[r++]=o>>12&63|128,e[r++]=o>>6&63|128,e[r++]=o&63|128):(o>=55296&&o<=57343&&(o=65533),e[r++]=o>>12|224,e[r++]=o>>6&63|128,e[r++]=o&63|128)}return e}var Zh=256,Sr=class{constructor(e=Zh){this.chunkSize=e,this.cursor=0,this.maxCursor=-1,this.chunks=[],this._initReuseChunk=null}reset(){this.cursor=0,this.maxCursor=-1,this.chunks.length&&(this.chunks=[]),this._initReuseChunk!==null&&(this.chunks.push(this._initReuseChunk),this.maxCursor=this._initReuseChunk.length-1)}push(e){let r=this.chunks[this.chunks.length-1];if(this.cursor+e.length<=this.maxCursor+1){let o=r.length-(this.maxCursor-this.cursor)-1;r.set(e,o)}else{if(r){let o=r.length-(this.maxCursor-this.cursor)-1;o<r.length&&(this.chunks[this.chunks.length-1]=r.subarray(0,o),this.maxCursor=this.cursor-1)}e.length<64&&e.length<this.chunkSize?(r=xc(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=yc(n,0,this.cursor)}else r=gc(this.chunks,this.cursor);return e&&this.reset(),r}},Un=class{constructor(e){this.dest=e,this.cursor=0,this.chunks=[e]}reset(){this.cursor=0}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 N="CBOR decode error:",pi="CBOR encode error:",Nr=[];Nr[23]=1;Nr[24]=2;Nr[25]=3;Nr[26]=5;Nr[27]=9;function qe(t,e,r){if(t.length-e<r)throw new Error(`${N} not enough data for type`)}var V=[24,256,65536,4294967296,BigInt("18446744073709551616")];function ue(t,e,r){qe(t,e,1);let n=t[e];if(r.strict===!0&&n<V[0])throw new Error(`${N} integer encoded in more bytes than necessary (strict decode)`);return n}function fe(t,e,r){qe(t,e,2);let n=t[e]<<8|t[e+1];if(r.strict===!0&&n<V[1])throw new Error(`${N} integer encoded in more bytes than necessary (strict decode)`);return n}function le(t,e,r){qe(t,e,4);let n=t[e]*16777216+(t[e+1]<<16)+(t[e+2]<<8)+t[e+3];if(r.strict===!0&&n<V[2])throw new Error(`${N} integer encoded in more bytes than necessary (strict decode)`);return n}function de(t,e,r){qe(t,e,8);let n=t[e]*16777216+(t[e+1]<<16)+(t[e+2]<<8)+t[e+3],o=t[e+4]*16777216+(t[e+5]<<16)+(t[e+6]<<8)+t[e+7],i=(BigInt(n)<<BigInt(32))+BigInt(o);if(r.strict===!0&&i<V[3])throw new Error(`${N} integer encoded in more bytes than necessary (strict decode)`);if(i<=Number.MAX_SAFE_INTEGER)return Number(i);if(r.allowBigInt===!0)return i;throw new Error(`${N} integers outside of the safe integer range are not supported`)}function wc(t,e,r,n){return new b(h.uint,ue(t,e+1,n),2)}function bc(t,e,r,n){return new b(h.uint,fe(t,e+1,n),3)}function Ec(t,e,r,n){return new b(h.uint,le(t,e+1,n),5)}function _c(t,e,r,n){return new b(h.uint,de(t,e+1,n),9)}function Ee(t,e){return q(t,0,e.value)}function q(t,e,r){if(r<V[0]){let n=Number(r);t.push([e|n])}else if(r<V[1]){let n=Number(r);t.push([e|24,n])}else if(r<V[2]){let n=Number(r);t.push([e|25,n>>>8,n&255])}else if(r<V[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<V[4]){let o=[e|27,0,0,0,0,0,0,0],i=Number(n&BigInt(4294967295)),s=Number(n>>BigInt(32)&BigInt(4294967295));o[8]=i&255,i=i>>8,o[7]=i&255,i=i>>8,o[6]=i&255,i=i>>8,o[5]=i&255,o[4]=s&255,s=s>>8,o[3]=s&255,s=s>>8,o[2]=s&255,s=s>>8,o[1]=s&255,t.push(o)}else throw new Error(`${N} encountered BigInt larger than allowable range`)}}Ee.encodedSize=function(e){return q.encodedSize(e.value)};q.encodedSize=function(e){return e<V[0]?1:e<V[1]?2:e<V[2]?3:e<V[3]?5:9};Ee.compareTokens=function(e,r){return e.value<r.value?-1:e.value>r.value?1:0};function vc(t,e,r,n){return new b(h.negint,-1-ue(t,e+1,n),2)}function kc(t,e,r,n){return new b(h.negint,-1-fe(t,e+1,n),3)}function Tc(t,e,r,n){return new b(h.negint,-1-le(t,e+1,n),5)}var mi=BigInt(-1),Ac=BigInt(1);function Ic(t,e,r,n){let o=de(t,e+1,n);if(typeof o!="bigint"){let i=-1-o;if(i>=Number.MIN_SAFE_INTEGER)return new b(h.negint,i,9)}if(n.allowBigInt!==!0)throw new Error(`${N} integers outside of the safe integer range are not supported`);return new b(h.negint,mi-BigInt(o),9)}function Cn(t,e){let r=e.value,n=typeof r=="bigint"?r*mi-Ac:r*-1-1;q(t,e.type.majorEncoded,n)}Cn.encodedSize=function(e){let r=e.value,n=typeof r=="bigint"?r*mi-Ac:r*-1-1;return n<V[0]?1:n<V[1]?2:n<V[2]?3:n<V[3]?5:9};Cn.compareTokens=function(e,r){return e.value<r.value?1:e.value>r.value?-1:0};function Ur(t,e,r,n){qe(t,e,r+n);let o=t.slice(e+r,e+r+n);return new b(h.bytes,o,r+n)}function Bc(t,e,r,n){return Ur(t,e,1,r)}function Sc(t,e,r,n){return Ur(t,e,2,ue(t,e+1,n))}function Nc(t,e,r,n){return Ur(t,e,3,fe(t,e+1,n))}function Uc(t,e,r,n){return Ur(t,e,5,le(t,e+1,n))}function Cc(t,e,r,n){let o=de(t,e+1,n);if(typeof o=="bigint")throw new Error(`${N} 64-bit integer bytes lengths not supported`);return Ur(t,e,9,o)}function Dn(t){return t.encodedBytes===void 0&&(t.encodedBytes=h.equals(t.type,h.string)?hi(t.value):t.value),t.encodedBytes}function Pt(t,e){let r=Dn(e);q(t,e.type.majorEncoded,r.length),t.push(r)}Pt.encodedSize=function(e){let r=Dn(e);return q.encodedSize(r.length)+r.length};Pt.compareTokens=function(e,r){return tp(Dn(e),Dn(r))};function tp(t,e){return t.length<e.length?-1:t.length>e.length?1:Nn(t,e)}var Dc=new TextDecoder,np=32;function op(t,e,r){if(r-e<np){let o="";for(let i=e;i<r;i++){let s=t[i];if(s&128)return Dc.decode(t.subarray(e,r));o+=String.fromCharCode(s)}return o}return Dc.decode(t.subarray(e,r))}function Cr(t,e,r,n,o){let i=r+n;qe(t,e,i);let s=new b(h.string,op(t,e+r,e+i),i);return o.retainStringBytes===!0&&(s.byteValue=t.slice(e+r,e+i)),s}function Lc(t,e,r,n){return Cr(t,e,1,r,n)}function $c(t,e,r,n){return Cr(t,e,2,ue(t,e+1,n),n)}function Rc(t,e,r,n){return Cr(t,e,3,fe(t,e+1,n),n)}function Fc(t,e,r,n){return Cr(t,e,5,le(t,e+1,n),n)}function Mc(t,e,r,n){let o=de(t,e+1,n);if(typeof o=="bigint")throw new Error(`${N} 64-bit integer string lengths not supported`);return Cr(t,e,9,o,n)}var Pc=Pt;function Ot(t,e,r,n){return new b(h.array,n,r)}function Oc(t,e,r,n){return Ot(t,e,1,r)}function zc(t,e,r,n){return Ot(t,e,2,ue(t,e+1,n))}function jc(t,e,r,n){return Ot(t,e,3,fe(t,e+1,n))}function Hc(t,e,r,n){return Ot(t,e,5,le(t,e+1,n))}function Vc(t,e,r,n){let o=de(t,e+1,n);if(typeof o=="bigint")throw new Error(`${N} 64-bit integer array lengths not supported`);return Ot(t,e,9,o)}function qc(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${N} indefinite length items not allowed`);return Ot(t,e,1,1/0)}function Ln(t,e){q(t,h.array.majorEncoded,e.value)}Ln.compareTokens=Ee.compareTokens;Ln.encodedSize=function(e){return q.encodedSize(e.value)};function zt(t,e,r,n){return new b(h.map,n,r)}function Gc(t,e,r,n){return zt(t,e,1,r)}function Wc(t,e,r,n){return zt(t,e,2,ue(t,e+1,n))}function Jc(t,e,r,n){return zt(t,e,3,fe(t,e+1,n))}function Qc(t,e,r,n){return zt(t,e,5,le(t,e+1,n))}function Xc(t,e,r,n){let o=de(t,e+1,n);if(typeof o=="bigint")throw new Error(`${N} 64-bit integer map lengths not supported`);return zt(t,e,9,o)}function Kc(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${N} indefinite length items not allowed`);return zt(t,e,1,1/0)}function $n(t,e){q(t,h.map.majorEncoded,e.value)}$n.compareTokens=Ee.compareTokens;$n.encodedSize=function(e){return q.encodedSize(e.value)};function Yc(t,e,r,n){return new b(h.tag,r,1)}function Zc(t,e,r,n){return new b(h.tag,ue(t,e+1,n),2)}function eu(t,e,r,n){return new b(h.tag,fe(t,e+1,n),3)}function tu(t,e,r,n){return new b(h.tag,le(t,e+1,n),5)}function ru(t,e,r,n){return new b(h.tag,de(t,e+1,n),9)}function Rn(t,e){q(t,h.tag.majorEncoded,e.value)}Rn.compareTokens=Ee.compareTokens;Rn.encodedSize=function(e){return q.encodedSize(e.value)};var yi=20,gi=21,xi=22,wi=23;function nu(t,e,r,n){if(n.allowUndefined===!1)throw new Error(`${N} undefined values are not supported`);return n.coerceUndefinedToNull===!0?new b(h.null,null,1):new b(h.undefined,void 0,1)}function ou(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${N} indefinite length items not allowed`);return new b(h.break,void 0,1)}function bi(t,e,r){if(r){if(r.allowNaN===!1&&Number.isNaN(t))throw new Error(`${N} NaN values are not supported`);if(r.allowInfinity===!1&&(t===1/0||t===-1/0))throw new Error(`${N} Infinity values are not supported`)}return new b(h.float,t,e)}function iu(t,e,r,n){return bi(Ei(t,e+1),3,n)}function su(t,e,r,n){return bi(_i(t,e+1),5,n)}function au(t,e,r,n){return bi(lu(t,e+1),9,n)}function Fn(t,e,r){let n=e.value;if(n===!1)t.push([h.float.majorEncoded|yi]);else if(n===!0)t.push([h.float.majorEncoded|gi]);else if(n===null)t.push([h.float.majorEncoded|xi]);else if(n===void 0)t.push([h.float.majorEncoded|wi]);else{let o,i=!1;(!r||r.float64!==!0)&&(uu(n),o=Ei(Be,1),n===o||Number.isNaN(n)?(Be[0]=249,t.push(Be.slice(0,3)),i=!0):(fu(n),o=_i(Be,1),n===o&&(Be[0]=250,t.push(Be.slice(0,5)),i=!0))),i||(up(n),o=lu(Be,1),Be[0]=251,t.push(Be.slice(0,9)))}}Fn.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){uu(n);let o=Ei(Be,1);if(n===o||Number.isNaN(n))return 3;if(fu(n),o=_i(Be,1),n===o)return 5}return 9};var cu=new ArrayBuffer(9),_e=new DataView(cu,1),Be=new Uint8Array(cu,0);function uu(t){if(t===1/0)_e.setUint16(0,31744,!1);else if(t===-1/0)_e.setUint16(0,64512,!1);else if(Number.isNaN(t))_e.setUint16(0,32256,!1);else{_e.setFloat32(0,t);let e=_e.getUint32(0),r=(e&2139095040)>>23,n=e&8388607;if(r===255)_e.setUint16(0,31744,!1);else if(r===0)_e.setUint16(0,(e&2147483648)>>16|n>>13,!1);else{let o=r-127;o<-24?_e.setUint16(0,0):o<-14?_e.setUint16(0,(e&2147483648)>>16|1<<24+o,!1):_e.setUint16(0,(e&2147483648)>>16|o+15<<10|n>>13,!1)}}}function Ei(t,e){if(t.length-e<2)throw new Error(`${N} not enough data for float16`);let r=(t[e]<<8)+t[e+1];if(r===31744)return 1/0;if(r===64512)return-1/0;if(r===32256)return NaN;let n=r>>10&31,o=r&1023,i;return n===0?i=o*2**-24:n!==31?i=(o+1024)*2**(n-25):i=o===0?1/0:NaN,r&32768?-i:i}function fu(t){_e.setFloat32(0,t,!1)}function _i(t,e){if(t.length-e<4)throw new Error(`${N} not enough data for float32`);let r=(t.byteOffset||0)+e;return new DataView(t.buffer,r,4).getFloat32(0,!1)}function up(t){_e.setFloat64(0,t,!1)}function lu(t,e){if(t.length-e<8)throw new Error(`${N} not enough data for float64`);let r=(t.byteOffset||0)+e;return new DataView(t.buffer,r,8).getFloat64(0,!1)}Fn.compareTokens=Ee.compareTokens;function U(t,e,r){throw new Error(`${N} encountered invalid minor (${r}) for major ${t[e]>>>5}`)}function Mn(t){return()=>{throw new Error(`${N} ${t}`)}}var x=[];for(let t=0;t<=23;t++)x[t]=U;x[24]=wc;x[25]=bc;x[26]=Ec;x[27]=_c;x[28]=U;x[29]=U;x[30]=U;x[31]=U;for(let t=32;t<=55;t++)x[t]=U;x[56]=vc;x[57]=kc;x[58]=Tc;x[59]=Ic;x[60]=U;x[61]=U;x[62]=U;x[63]=U;for(let t=64;t<=87;t++)x[t]=Bc;x[88]=Sc;x[89]=Nc;x[90]=Uc;x[91]=Cc;x[92]=U;x[93]=U;x[94]=U;x[95]=Mn("indefinite length bytes/strings are not supported");for(let t=96;t<=119;t++)x[t]=Lc;x[120]=$c;x[121]=Rc;x[122]=Fc;x[123]=Mc;x[124]=U;x[125]=U;x[126]=U;x[127]=Mn("indefinite length bytes/strings are not supported");for(let t=128;t<=151;t++)x[t]=Oc;x[152]=zc;x[153]=jc;x[154]=Hc;x[155]=Vc;x[156]=U;x[157]=U;x[158]=U;x[159]=qc;for(let t=160;t<=183;t++)x[t]=Gc;x[184]=Wc;x[185]=Jc;x[186]=Qc;x[187]=Xc;x[188]=U;x[189]=U;x[190]=U;x[191]=Kc;for(let t=192;t<=215;t++)x[t]=Yc;x[216]=Zc;x[217]=eu;x[218]=tu;x[219]=ru;x[220]=U;x[221]=U;x[222]=U;x[223]=U;for(let t=224;t<=243;t++)x[t]=Mn("simple values are not supported");x[244]=U;x[245]=U;x[246]=U;x[247]=nu;x[248]=Mn("simple values are not supported");x[249]=iu;x[250]=su;x[251]=au;x[252]=U;x[253]=U;x[254]=U;x[255]=ou;var Fe=[];for(let t=0;t<24;t++)Fe[t]=new b(h.uint,t,1);for(let t=-1;t>=-24;t--)Fe[31-t]=new b(h.negint,t,1);Fe[64]=new b(h.bytes,new Uint8Array(0),1);Fe[96]=new b(h.string,"",1);Fe[128]=new b(h.array,0,1);Fe[160]=new b(h.map,0,1);Fe[244]=new b(h.false,!1,1);Fe[245]=new b(h.true,!0,1);Fe[246]=new b(h.null,null,1);function vi(t){switch(t.type){case h.false:return Re([244]);case h.true:return Re([245]);case h.null:return Re([246]);case h.bytes:return t.value.length?void 0:Re([64]);case h.string:return t.value===""?Re([96]):void 0;case h.array:return t.value===0?Re([128]):void 0;case h.map:return t.value===0?Re([160]):void 0;case h.uint:return t.value<24?Re([Number(t.value)]):void 0;case h.negint:if(t.value>=-24)return Re([31-Number(t.value)])}}var hu=Object.freeze({float64:!0,mapSorter:pp,quickEncodeToken:vi});function ki(){let t=[];return t[h.uint.major]=Ee,t[h.negint.major]=Cn,t[h.bytes.major]=Pt,t[h.string.major]=Pc,t[h.array.major]=Ln,t[h.map.major]=$n,t[h.tag.major]=Rn,t[h.float.major]=Fn,t}var lp=ki(),dp=new Sr,Pn=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(`${pi} object contains circular references`);return new t(r,e)}},tt={null:new b(h.null,null),undefined:new b(h.undefined,void 0),true:new b(h.true,!0),false:new b(h.false,!1),emptyArray:new b(h.array,0),emptyMap:new b(h.map,0)},rt={number(t,e,r,n){return!Number.isInteger(t)||!Number.isSafeInteger(t)?new b(h.float,t):t>=0?new b(h.uint,t):new b(h.negint,t)},bigint(t,e,r,n){return t>=BigInt(0)?new b(h.uint,t):new b(h.negint,t)},Uint8Array(t,e,r,n){return new b(h.bytes,t)},string(t,e,r,n){return new b(h.string,t)},boolean(t,e,r,n){return t?tt.true:tt.false},null(t,e,r,n){return tt.null},undefined(t,e,r,n){return tt.undefined},ArrayBuffer(t,e,r,n){return new b(h.bytes,new Uint8Array(t))},DataView(t,e,r,n){return new b(h.bytes,new Uint8Array(t.buffer,t.byteOffset,t.byteLength))},Array(t,e,r,n){if(!t.length)return r.addBreakTokens===!0?[tt.emptyArray,new b(h.break)]:tt.emptyArray;n=Pn.createCheck(n,t);let o=[],i=0;for(let s of t)o[i++]=pt(s,r,n);return r.addBreakTokens?[new b(h.array,t.length),o,new b(h.break)]:[new b(h.array,t.length),o]},Object(t,e,r,n){let o=e!=="Object",i=o?t.keys():Object.keys(t),s=o?t.size:i.length,a;if(s){a=new Array(s),n=Pn.createCheck(n,t);let c=!o&&r.ignoreUndefinedProperties,f=0;for(let l of i){let p=o?t.get(l):t[l];c&&p===void 0||(a[f++]=[pt(l,r,n),pt(p,r,n)])}f<s&&(a.length=f)}return a?.length?(hp(a,r),r.addBreakTokens?[new b(h.map,a.length),a,new b(h.break)]:[new b(h.map,a.length),a]):r.addBreakTokens===!0?[tt.emptyMap,new b(h.break)]:tt.emptyMap},Tagged(t,e,r,n){return[new b(h.tag,t.tag),pt(t.value,r,n)]}};rt.Map=rt.Object;rt.Buffer=rt.Uint8Array;for(let t of"Uint8Clamped Uint16 Uint32 Int8 Int16 Int32 BigUint64 BigInt64 Float32 Float64".split(" "))rt[`${t}Array`]=rt.DataView;function pt(t,e={},r){let n=pc(t),o=e&&e.typeEncoders&&e.typeEncoders[n]||rt[n];if(typeof o=="function"){let s=o(t,n,e,r);if(s!=null)return s}let i=rt[n];if(!i)throw new Error(`${pi} unsupported type: ${n}`);return i(t,n,e,r)}function hp(t,e){e.mapSorter&&t.sort(e.mapSorter)}function pp(t,e){if(t[0]instanceof b&&e[0]instanceof b){let r=t[0],n=e[0];return r._keyBytes||(r._keyBytes=du(r.value)),n._keyBytes||(n._keyBytes=du(n.value)),Nn(r._keyBytes,n._keyBytes)}throw new Error("rfc8949MapSorter: complex key types are not supported yet")}function du(t){return mp(t,lp,hu)}function pu(t,e,r,n){if(Array.isArray(e))for(let o of e)pu(t,o,r,n);else r[e.type.major](t,e,n)}var px=h.uint.majorEncoded,mx=h.negint.majorEncoded,yx=h.bytes.majorEncoded,gx=h.string.majorEncoded,xx=h.array.majorEncoded,wx=h.float.majorEncoded|yi,bx=h.float.majorEncoded|gi,Ex=h.float.majorEncoded|xi,_x=h.float.majorEncoded|wi,vx=BigInt(-1),kx=BigInt(1);function mp(t,e,r,n){let o=n instanceof Uint8Array,i=o?new Un(n):dp,s=pt(t,r);if(!Array.isArray(s)&&r.quickEncodeToken){let a=r.quickEncodeToken(s);if(a)return o?(i.push(a),i.toBytes()):a;let c=e[s.type.major];if(c.encodedSize){let f=c.encodedSize(s,r);if(o||(i=new Sr(f)),c(i,s,r),i.chunks.length!==1)throw new Error(`Unexpected error: pre-calculated length for ${s} was wrong`);return o?i.toBytes():Sn(i.chunks[0])}}return i.reset(),pu(i,s,e,r),i.toBytes(!0)}var Nx=Symbol.for("DONE"),Ux=Symbol.for("BREAK");var On=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(On.prototype,Symbol.toStringTag,{value:"Tagged"});var Wx=ki();var yp=Tt(In(),1);var Yx=[new b(h.map,2),new b(h.string,"version"),new b(h.uint,1),new b(h.string,"roots")],Zx=new b(h.tag,42);async function Ti(t,e){let r=fi(await t.upTo(8),t);if(r===0)throw new Error("Invalid CAR header (zero length)");let n=await t.exactly(r,!0),o=dt(n);if(di.toTyped(o)===void 0)throw new Error("Invalid CAR header format");if(o.version!==1&&o.version!==2||e!==void 0&&o.version!==e)throw new Error(`Invalid CAR version: ${o.version}${e!==void 0?` (expected ${e})`:""}`);if(o.version===1){if(!Array.isArray(o.roots))throw new Error("Invalid CAR header format");return o}if(o.roots!==void 0)throw new Error("Invalid CAR header format");let i=li(await t.exactly(ui,!0));t.seek(i.dataOffset-t.pos);let s=await Ti(t,1);return Object.assign(s,i)}function Dr(t){let e=0;return{async upTo(r){return t.subarray(e,e+Math.min(r,t.length-e))},async exactly(r,n=!1){if(r>t.length-e)throw new Error("Unexpected end of data");let o=t.subarray(e,e+r);return n&&(e+=r),o},seek(r){e+=r},get pos(){return e}}}var Ai=Tt(In(),1),gu=1;function Ii(t){let e=ii({version:gu,roots:t}),r=Ai.default.encode(e.length),n=new Uint8Array(r.length+e.length);return n.set(r,0),n.set(e,r.length),n}function xu(t){return{async setRoots(e){let r=Ii(e);await t.write(r)},async writeBlock(e){let{cid:r,bytes:n}=e;await t.write(new Uint8Array(Ai.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 gu}}}function zn(){}function wu(){let t=[],e=null,r=zn,n=!1,o=null,i=zn,s=()=>(e||(e=new Promise(f=>{r=()=>{e=null,r=zn,f()}})),e),a={write(f){t.push(f);let l=s();return i(),l},async end(){n=!0;let f=s();i(),await f}},c={async next(){let f=t.shift();return f?(t.length===0&&r(),{done:!1,value:f}):n?(r(),{done:!0,value:void 0}):(o||(o=new Promise(l=>{i=()=>(o=null,i=zn,l(c.next()))})),o)}};return{writer:a,iterator:c}}var Lr=class t{constructor(e,r){this._encoder=r,this._mutex=r.setRoots(e),this._ended=!1}async put(e){if(!(e.bytes instanceof Uint8Array)||!e.cid)throw new TypeError("Can only write {cid, bytes} objects");if(this._ended)throw new Error("Already closed");let r=B.asCID(e.cid);if(!r)throw new TypeError("Can only write {cid, bytes} objects");return this._mutex=this._mutex.then(()=>this._encoder.writeBlock({cid:r,bytes:e.bytes})),this._mutex}async close(){if(this._ended)throw new Error("Already closed");return await this._mutex,this._ended=!0,this._encoder.close()}version(){return this._encoder.version()}static create(e){e=bp(e);let{encoder:r,iterator:n}=bu(),o=new t(e,r),i=new jn(n);return{writer:o,out:i}}static createAppender(){let{encoder:e,iterator:r}=bu();e.setRoots=()=>Promise.resolve();let n=new t([],e),o=new jn(r);return{writer:n,out:o}}static async updateRootsInBytes(e,r){let n=Dr(e);await Ti(n);let o=Ii(r);if(Number(n.pos)!==o.length)throw new Error(`updateRoots() can only overwrite a header of the same length (old header is ${n.pos} bytes, new header is ${o.length} bytes)`);return e.set(o,0),e}},jn=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 bu(){let t=wu(),{writer:e,iterator:r}=t;return{encoder:xu(e),iterator:r}}function bp(t){if(t===void 0)return[];if(!Array.isArray(t)){let r=B.asCID(t);if(!r)throw new TypeError("roots must be a single CID or an array of CIDs");return[r]}let e=[];for(let r of t){let n=B.asCID(r);if(!n)throw new TypeError("roots must be a single CID or an array of CIDs");e.push(n)}return e}function Ep(t){return t[Symbol.asyncIterator]!=null}function _p(t){if(Ep(t))return(async()=>{for await(let e of t);})();for(let e of t);}var Bi=_p;function vp(t){let[e,r]=t[Symbol.asyncIterator]!=null?[t[Symbol.asyncIterator](),Symbol.asyncIterator]:[t[Symbol.iterator](),Symbol.iterator],n=[];return{peek:()=>e.next(),push:o=>{n.push(o)},next:()=>n.length>0?{done:!1,value:n.shift()}:e.next(),[r](){return this}}}var Hn=vp;function kp(t){return t[Symbol.asyncIterator]!=null}function Tp(t,e){let r=0;if(kp(t))return(async function*(){for await(let c of t)yield e(c,r++)})();let n=Hn(t),{value:o,done:i}=n.next();if(i===!0)return(function*(){})();let s=e(o,r++);if(typeof s.then=="function")return(async function*(){yield await s;for(let c of n)yield e(c,r++)})();let a=e;return(function*(){yield s;for(let c of n)yield a(c,r++)})()}var jt=Tp;function Ap(t){return t.reason}async function Ht(t,e,r){if(e==null)return t;let n=r?.translateError??Ap;if(e.aborted)return t.catch(()=>{}),Promise.reject(n(e));let o;try{return await Promise.race([t,new Promise((i,s)=>{o=()=>{s(n(e))},e.addEventListener("abort",o)})])}finally{o!=null&&e.removeEventListener("abort",o)}}var Ge=class extends Error{static name="AbortError";constructor(e="The operation was aborted"){super(e),this.name="AbortError"}};var mt=class extends Error{static name="InvalidParametersError";constructor(e="Invalid parameters"){super(e),this.name="InvalidParametersError"}};var Vn=class extends EventTarget{#e=new Map;constructor(){super()}listenerCount(e){let r=this.#e.get(e);return r==null?0:r.length}addEventListener(e,r,n){super.addEventListener(e,r,n);let o=this.#e.get(e);o==null&&(o=[],this.#e.set(e,o)),o.push({callback:r,once:(n!==!0&&n!==!1&&n?.once)??!1})}removeEventListener(e,r,n){super.removeEventListener(e.toString(),r??null,n);let o=this.#e.get(e);o!=null&&(o=o.filter(({callback:i})=>i!==r),this.#e.set(e,o))}dispatchEvent(e){let r=super.dispatchEvent(e),n=this.#e.get(e.type);return n==null||(n=n.filter(({once:o})=>!o),this.#e.set(e.type,n)),r}safeDispatchEvent(e,r={}){return this.dispatchEvent(new CustomEvent(e,r))}};var Q=class extends Event{type;detail;constructor(e,r){super(e),this.type=e,this.detail=r}};var Ni=Tt(_u(),1);var Ui=class t extends Error{name="TimeoutError";constructor(e,r){super(e,r),Error.captureStackTrace?.(this,t)}},vu=t=>t.reason??new DOMException("This operation was aborted.","AbortError");function Rr(t,e){let{milliseconds:r,fallback:n,message:o,customTimers:i={setTimeout,clearTimeout},signal:s}=e,a,c,l=new Promise((p,v)=>{if(typeof r!="number"||Math.sign(r)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${r}\``);if(s?.aborted){v(vu(s));return}if(s&&(c=()=>{v(vu(s))},s.addEventListener("abort",c,{once:!0})),t.then(p,v),r===Number.POSITIVE_INFINITY)return;let k=new Ui;a=i.setTimeout.call(void 0,()=>{if(n){try{p(n())}catch(w){v(w)}return}typeof t.cancel=="function"&&t.cancel(),o===!1?p():o instanceof Error?v(o):(k.message=o??`Promise timed out after ${r} milliseconds`,v(k))},r)}).finally(()=>{l.clear(),c&&s&&s.removeEventListener("abort",c)});return l.clear=()=>{i.clearTimeout.call(void 0,a),a=void 0},l}function Ci(t,e,r){let n=0,o=t.length;for(;o>0;){let i=Math.trunc(o/2),s=n+i;r(t[s],e)<=0?(n=++s,o-=i+1):o=i}return n}var Vt=class{#e=[];enqueue(e,r){let{priority:n=0,id:o}=r??{},i={priority:n,id:o,run:e};if(this.size===0||this.#e[this.size-1].priority>=n){this.#e.push(i);return}let s=Ci(this.#e,i,(a,c)=>c.priority-a.priority);this.#e.splice(s,0,i)}setPriority(e,r){let n=this.#e.findIndex(i=>i.id===e);if(n===-1)throw new ReferenceError(`No promise function with the id "${e}" exists in the queue.`);let[o]=this.#e.splice(n,1);this.enqueue(o.run,{priority:r,id:e})}remove(e){let r=this.#e.findIndex(n=>typeof e=="string"?n.id===e:n.run===e);r!==-1&&this.#e.splice(r,1)}dequeue(){return this.#e.shift()?.run}filter(e){return this.#e.filter(r=>r.priority===e.priority).map(r=>r.run)}get size(){return this.#e.length}};var Fr=class extends Ni.default{#e;#s;#a=0;#h;#m=!1;#w=!1;#c;#I=0;#b=0;#u;#f;#i;#o=[];#n=0;#t;#B;#r=0;#y;#l;#D=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:Vt,strict:!1,...e},!(typeof e.intervalCap=="number"&&e.intervalCap>=1))throw new TypeError(`Expected \`intervalCap\` to be a number from 1 and up, got \`${e.intervalCap?.toString()??""}\` (${typeof e.intervalCap})`);if(e.interval===void 0||!(Number.isFinite(e.interval)&&e.interval>=0))throw new TypeError(`Expected \`interval\` to be a finite number >= 0, got \`${e.interval?.toString()??""}\` (${typeof e.interval})`);if(e.strict&&e.interval===0)throw new TypeError("The `strict` option requires a non-zero `interval`");if(e.strict&&e.intervalCap===Number.POSITIVE_INFINITY)throw new TypeError("The `strict` option requires a finite `intervalCap`");if(this.#e=e.carryoverIntervalCount??e.carryoverConcurrencyCount??!1,this.#s=e.intervalCap===Number.POSITIVE_INFINITY||e.interval===0,this.#h=e.intervalCap,this.#c=e.interval,this.#i=e.strict,this.#t=new e.queueClass,this.#B=e.queueClass,this.concurrency=e.concurrency,e.timeout!==void 0&&!(Number.isFinite(e.timeout)&&e.timeout>0))throw new TypeError(`Expected \`timeout\` to be a positive finite number, got \`${e.timeout}\` (${typeof e.timeout})`);this.timeout=e.timeout,this.#l=e.autoStart===!1,this.#z()}#_(e){for(;this.#n<this.#o.length;){let n=this.#o[this.#n];if(n!==void 0&&e-n>=this.#c)this.#n++;else break}(this.#n>100&&this.#n>this.#o.length/2||this.#n===this.#o.length)&&(this.#o=this.#o.slice(this.#n),this.#n=0)}#L(e){this.#i?this.#o.push(e):this.#a++}#$(){this.#i?this.#o.length>this.#n&&this.#o.pop():this.#a>0&&this.#a--}#v(){return this.#o.length-this.#n}get#R(){return this.#s?!0:this.#i?this.#v()<this.#h:this.#a<this.#h}get#F(){return this.#r<this.#y}#M(){this.#r--,this.#r===0&&this.emit("pendingZero"),this.#x(),this.emit("next")}#P(){this.#f=void 0,this.#U(),this.#N()}#O(e){if(this.#i){if(this.#_(e),this.#v()>=this.#h){let n=this.#o[this.#n],o=this.#c-(e-n);return this.#k(o),!0}return!1}if(this.#u===void 0){let r=this.#I-e;if(r<0){if(this.#b>0){let n=e-this.#b;if(n<this.#c)return this.#k(this.#c-n),!0}this.#a=this.#e?this.#r:0}else return this.#k(r),!0}return!1}#k(e){this.#f===void 0&&(this.#f=setTimeout(()=>{this.#P()},e))}#T(){this.#u&&(clearInterval(this.#u),this.#u=void 0)}#S(){this.#f&&(clearTimeout(this.#f),this.#f=void 0)}#x(){if(this.#t.size===0){if(this.#T(),this.emit("empty"),this.#r===0){if(this.#S(),this.#i&&this.#n>0){let r=Date.now();this.#_(r)}this.emit("idle")}return!1}let e=!1;if(!this.#l){let r=Date.now(),n=!this.#O(r);if(this.#R&&this.#F){let o=this.#t.dequeue();this.#s||(this.#L(r),this.#p()),this.emit("active"),o(),n&&this.#N(),e=!0}}return e}#N(){this.#s||this.#u!==void 0||this.#i||(this.#u=setInterval(()=>{this.#U()},this.#c),this.#I=Date.now()+this.#c)}#U(){this.#i||(this.#a===0&&this.#r===0&&this.#u&&this.#T(),this.#a=this.#e?this.#r:0),this.#A(),this.#p()}#A(){for(;this.#x(););}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.#A()}setPriority(e,r){if(typeof r!="number"||!Number.isFinite(r))throw new TypeError(`Expected \`priority\` to be a finite number, got \`${r}\` (${typeof r})`);this.#t.setPriority(e,r)}async add(e,r={}){return r={timeout:this.timeout,...r,id:r.id??(this.#D++).toString()},new Promise((n,o)=>{let i=Symbol(`task-${r.id}`),s=()=>{},a=async()=>{s(),this.#r++,this.#g.set(i,{id:r.id,priority:r.priority??0,startTime:Date.now(),timeout:r.timeout});let f;try{try{r.signal?.throwIfAborted()}catch(v){throw this.#j(),this.#g.delete(i),v}this.#b=Date.now();let l=e({signal:r.signal});if(r.timeout&&(l=Rr(Promise.resolve(l),{milliseconds:r.timeout,message:`Task timed out after ${r.timeout}ms (queue has ${this.#r} running, ${this.#t.size} waiting)`})),r.signal){let{signal:v}=r;l=Promise.race([l,new Promise((k,w)=>{f=()=>{w(v.reason)},v.addEventListener("abort",f,{once:!0})})])}let p=await l;n(p),this.emit("completed",p)}catch(l){o(l),this.emit("error",l)}finally{f&&r.signal?.removeEventListener("abort",f),this.#g.delete(i),queueMicrotask(()=>{this.#M()})}};this.#t.enqueue(a,r);let c=()=>{if(this.#t instanceof Vt){this.#t.remove(a);return}this.#t.remove?.(r.id)};if(r.signal){let{signal:f}=r,l=()=>{s(),c(),o(f.reason),this.#x(),this.emit("next")};if(s=()=>{f.removeEventListener("abort",l),this.#E.delete(s)},f.aborted){l();return}f.addEventListener("abort",l,{once:!0}),this.#E.add(s)}this.emit("add"),this.#x()})}async addAll(e,r){return Promise.all(e.map(async n=>this.add(n,r)))}start(){return this.#l?(this.#l=!1,this.#A(),this):this}pause(){this.#l=!0}clear(){for(let e of this.#E)e();this.#t=new this.#B,this.#T(),this.#C(),this.emit("empty"),this.#r===0&&(this.#S(),this.emit("idle")),this.emit("next")}async onEmpty(){this.#t.size!==0&&await this.#d("empty")}async onSizeLessThan(e){this.#t.size<e||await this.#d("next",()=>this.#t.size<e)}async onIdle(){this.#r===0&&this.#t.size===0||await this.#d("idle")}async onPendingZero(){this.#r!==0&&await this.#d("pendingZero")}async onRateLimit(){this.isRateLimited||await this.#d("rateLimit")}async onRateLimitCleared(){this.isRateLimited&&await this.#d("rateLimitCleared")}onError(){return new Promise((e,r)=>{let n=o=>{this.off("error",n),r(o)};this.on("error",n)})}async#d(e,r){return new Promise(n=>{let o=()=>{r&&!r()||(this.off(e,o),n())};this.on(e,o)})}get size(){return this.#t.size}sizeBy(e){return this.#t.filter(e).length}get pending(){return this.#r}get isPaused(){return this.#l}#z(){this.#s||(this.on("add",()=>{this.#t.size>0&&this.#p()}),this.on("next",()=>{this.#p()}))}#p(){this.#s||this.#w||(this.#w=!0,queueMicrotask(()=>{this.#w=!1,this.#C()}))}#j(){this.#s||(this.#$(),this.#p())}#C(){let e=this.#m;if(this.#s||this.#t.size===0){e&&(this.#m=!1,this.emit("rateLimitCleared"));return}let r;if(this.#i){let o=Date.now();this.#_(o),r=this.#v()}else r=this.#a;let n=r>=this.#h;n!==e&&(this.#m=n,this.emit(n?"rateLimit":"rateLimitCleared"))}get isRateLimited(){return this.#m}get isSaturated(){return this.#r===this.#y&&this.#t.size>0||this.isRateLimited&&this.#t.size>0}get runningTasks(){return[...this.#g.values()].map(e=>({...e}))}};var Di={};oe(Di,{base10:()=>Sp});var Sp=Ye({prefix:"9",name:"base10",alphabet:"0123456789"});var Li={};oe(Li,{base16:()=>Np,base16upper:()=>Up});var Np=O({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Up=O({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var $i={};oe($i,{base2:()=>Cp});var Cp=O({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Ri={};oe(Ri,{base256emoji:()=>Fp});var ku=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}"),Dp=ku.reduce((t,e,r)=>(t[r]=e,t),[]),Lp=ku.reduce((t,e,r)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return t[n]=r,t},[]);function $p(t){return t.reduce((e,r)=>(e+=Dp[r],e),"")}function Rp(t){let e=[];for(let r of t){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=Lp[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);e.push(o)}return new Uint8Array(e)}var Fp=Ct({prefix:"\u{1F680}",name:"base256emoji",encode:$p,decode:Rp});var Mi={};oe(Mi,{base64:()=>Fi,base64pad:()=>Mp,base64url:()=>Pp,base64urlpad:()=>Op});var Fi=O({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Mp=O({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Pp=O({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Op=O({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Pi={};oe(Pi,{base8:()=>zp});var zp=O({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Oi={};oe(Oi,{identity:()=>jp});var jp=Ct({prefix:"\0",name:"identity",encode:t=>Ja(t),decode:t=>Wa(t)});var ub=new TextEncoder,Hp=new TextDecoder;var Gn=512;function Wn(t){return JSON.parse(Hp.decode(t))}var Gt=85;var zi={};oe(zi,{identity:()=>Pr});var Tu=0,Vp="identity",Au=Ve;function qp(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 Ft(Tu,Au(t))}var Pr={code:Tu,name:Vp,encode:Au,digest:qp};var Hi={};oe(Hi,{sha256:()=>Wp,sha512:()=>Jp});var Gp=20;function yt({name:t,code:e,encode:r,minDigestLength:n,maxDigestLength:o}){return new ji(t,e,r,n,o)}var ji=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,r,n,o,i){this.name=e,this.code=r,this.encode=n,this.minDigestLength=o??Gp,this.maxDigestLength=i}digest(e,r){if(r?.truncate!=null){if(r.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&r.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(e instanceof Uint8Array){let n=this.encode(e);return n instanceof Uint8Array?Iu(n,this.code,r?.truncate):n.then(o=>Iu(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function Iu(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 Ft(e,t)}function Su(t){return async e=>new Uint8Array(await crypto.subtle.digest(t,e))}var Wp=yt({name:"sha2-256",code:18,encode:Su("SHA-256")}),Jp=yt({name:"sha2-512",code:19,encode:Su("SHA-512")});var Vi={...Oi,...$i,...Pi,...Di,...Li,...Yo,...Zo,...ei,...Mi,...Ri},_b={...Hi,...zi};function Me(t=0){return new Uint8Array(t)}function Uu(t,e,r,n){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:r},decoder:{decode:n}}}var Nu=Uu("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),qi=Uu("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=Me(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}),Qp={utf8:Nu,"utf-8":Nu,hex:Vi.base16,latin1:qi,ascii:qi,binary:qi,...Vi},Gi=Qp;var Yp=Tt(Du(),1);var qt;(function(t){t[t.A=1]="A",t[t.CNAME=5]="CNAME",t[t.TXT=16]="TXT",t[t.AAAA=28]="AAAA"})(qt||(qt={}));function Or(t,e){e==null&&(e=t.reduce((o,i)=>o+i.length,0));let r=Me(e),n=0;for(let o of t)r.set(o,n),n+=o.length;return r}function Qn(t,e="utf8"){let r=Gi[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.decoder.decode(`${r.prefix}${t}`)}var Zp=Math.pow(2,7),em=Math.pow(2,14),tm=Math.pow(2,21),Lu=Math.pow(2,28),$u=Math.pow(2,35),Ru=Math.pow(2,42),Fu=Math.pow(2,49),te=128,nt=127;function zr(t){if(t<Zp)return 1;if(t<em)return 2;if(t<tm)return 3;if(t<Lu)return 4;if(t<$u)return 5;if(t<Ru)return 6;if(t<Fu)return 7;if(Number.MAX_SAFE_INTEGER!=null&&t>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Mu(t,e,r=0){switch(zr(t)){case 8:e[r++]=t&255|te,t/=128;case 7:e[r++]=t&255|te,t/=128;case 6:e[r++]=t&255|te,t/=128;case 5:e[r++]=t&255|te,t/=128;case 4:e[r++]=t&255|te,t>>>=7;case 3:e[r++]=t&255|te,t>>>=7;case 2:e[r++]=t&255|te,t>>>=7;case 1:{e[r++]=t&255,t>>>=7;break}default:throw new Error("unreachable")}return e}function Pu(t,e){let r=t[e],n=0;if(n+=r&nt,r<te||(r=t[e+1],n+=(r&nt)<<7,r<te)||(r=t[e+2],n+=(r&nt)<<14,r<te)||(r=t[e+3],n+=(r&nt)<<21,r<te)||(r=t[e+4],n+=(r&nt)*Lu,r<te)||(r=t[e+5],n+=(r&nt)*$u,r<te)||(r=t[e+6],n+=(r&nt)*Ru,r<te)||(r=t[e+7],n+=(r&nt)*Fu,r<te))return n;throw new RangeError("Could not decode varint")}function K(){let t={};return t.promise=new Promise((e,r)=>{t.resolve=e,t.reject=r}),t}var Xn=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}},Wt=class{size;hwm;head;tail;constructor(e={}){this.hwm=e.splitLimit??16,this.head=new Xn(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 Xn(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 Wi=class extends Error{type;code;constructor(e,r){super(e??"The operation was aborted"),this.type="aborted",this.code=r??"ABORT_ERR"}};function Jt(t={}){return rm(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 rm(t,e){e=e??{};let r=e.onEnd,n=new Wt,o,i,s,a=K(),c=async()=>{try{return n.isEmpty()?s?{done:!0}:await new Promise((I,R)=>{i=z=>{i=null,n.push(z);try{I(t(n))}catch(P){R(P)}return o}}):t(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=K()})}},f=I=>i!=null?i(I):(n.push(I),o),l=I=>(n=new Wt,i!=null?i({error:I}):(n.push({error:I}),o)),p=I=>{if(s)return o;if(e?.objectMode!==!0&&I?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return f({done:!1,value:I})},v=I=>s?o:(s=!0,I!=null?l(I):f({done:!0})),k=()=>(n=new Wt,v(),{done:!0}),w=I=>(v(I),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:c,return:k,throw:w,push:p,end:v,get readableLength(){return n.size},onEmpty:async I=>{let R=I?.signal;if(R?.throwIfAborted(),n.isEmpty())return;let z,P;R!=null&&(z=new Promise((J,j)=>{P=()=>{j(new Wi)},R.addEventListener("abort",P)}));try{await Promise.race([a.promise,z])}finally{P!=null&&R!=null&&R?.removeEventListener("abort",P)}}},r==null)return o;let A=o;return o={[Symbol.asyncIterator](){return this},next(){return A.next()},throw(I){return A.throw(I),r!=null&&(r(I),r=void 0),{done:!0}},return(){return A.return(),r!=null&&(r(),r=void 0),{done:!0}},push:p,end(I){return A.end(I),r!=null&&(r(I),r=void 0),o},get readableLength(){return A.readableLength},onEmpty:I=>A.onEmpty(I)},o}var nm=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 om(t,e,r){let n,o=new Promise((i,s)=>{if(r={rejectionEvents:["error"],multiArgs:!1,rejectionMultiArgs:!1,resolveImmediately:!1,...r},!(r.count>=0&&(r.count===Number.POSITIVE_INFINITY||Number.isInteger(r.count))))throw new TypeError("The `count` option should be at least 0 or more");r.signal?.throwIfAborted();let a=[e].flat(),c=[],{addListener:f,removeListener:l}=nm(t),p=async(...k)=>{let w=r.multiArgs?k:k[0];if(r.filter)try{if(!await r.filter(w))return}catch(A){n(),s(A);return}c.push(w),r.count===c.length&&(n(),i(c))},v=(...k)=>{n(),s(r.rejectionMultiArgs?k:k[0])};n=()=>{for(let k of a)l(k,p);for(let k of r.rejectionEvents)a.includes(k)||l(k,v)};for(let k of a)f(k,p);for(let k of r.rejectionEvents)a.includes(k)||f(k,v);r.signal&&r.signal.addEventListener("abort",()=>{v(r.signal.reason)},{once:!0}),r.resolveImmediately&&i(c)});if(o.cancel=n,typeof r.timeout=="number"){let i=Rr(o,{milliseconds:r.timeout});return i.cancel=()=>{n(),i.clear()},i}return o}function Kn(t,e,r){typeof r=="function"&&(r={filter:r}),r={...r,count:1,resolveImmediately:!1};let n=om(t,e,r),o=n.then(i=>i[0]);return o.cancel=n.cancel,o}function Ji(t,e){let r,n=function(){let o=function(){r=void 0,t()};clearTimeout(r),r=setTimeout(o,e)};return n.start=()=>{},n.stop=()=>{clearTimeout(r)},n}var Yn=class extends Error{static name="QueueFullError";constructor(e="The queue was full"){super(e),this.name="QueueFullError"}};var Zn=class{deferred;signal;constructor(e){this.signal=e,this.deferred=K(),this.onAbort=this.onAbort.bind(this),this.signal?.addEventListener("abort",this.onAbort)}onAbort(){this.deferred.reject(this.signal?.reason??new Ge)}cleanup(){this.signal?.removeEventListener("abort",this.onAbort)}};function im(){return`${parseInt(String(Math.random()*1e9),10).toString()}${Date.now()}`}var eo=class{id;fn;options;recipients;status;timeline;controller;constructor(e,r){this.id=im(),this.status="queued",this.fn=e,this.options=r,this.recipients=[],this.timeline={created:Date.now()},this.controller=new AbortController,this.controller.signal,this.onAbort=this.onAbort.bind(this)}abort(e){this.controller.abort(e)}onAbort(){this.recipients.reduce((r,n)=>r&&n.signal?.aborted===!0,!0)&&(this.controller.abort(new Ge),this.cleanup())}async join(e={}){let r=new Zn(e.signal);return this.recipients.push(r),e.signal?.addEventListener("abort",this.onAbort),r.deferred.promise}async run(){this.status="running",this.timeline.started=Date.now();try{this.controller.signal.throwIfAborted();let e=await Ht(this.fn({...this.options??{},signal:this.controller.signal}),this.controller.signal);this.recipients.forEach(r=>{r.deferred.resolve(e)}),this.status="complete"}catch(e){this.recipients.forEach(r=>{r.deferred.reject(e)}),this.status="errored"}finally{this.timeline.finished=Date.now(),this.cleanup()}}cleanup(){this.recipients.forEach(e=>{e.cleanup(),e.signal?.removeEventListener("abort",this.onAbort)})}};var Qt=class extends Vn{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=Ji(this.emitEmpty.bind(this),1),this.emitIdle=Ji(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 Yn;let n=new eo(e,r);return this.enqueue(n),this.safeDispatchEvent("add"),this.tryToStartAnother(),n.join(r).then(o=>(this.safeDispatchEvent("completed",{detail:o}),this.safeDispatchEvent("success",{detail:{job:n,result:o}}),o)).catch(o=>{if(n.status==="queued"){for(let i=0;i<this.queue.length;i++)if(this.queue[i]===n){this.queue.splice(i,1);break}}throw this.safeDispatchEvent("failure",{detail:{job:n,error:o}}),o})}clear(){this.queue.splice(0,this.queue.length)}abort(){this.queue.forEach(e=>{e.abort(new Ge)}),this.clear()}async onEmpty(e){this.size!==0&&await Kn(this,"empty",e)}async onSizeLessThan(e,r){this.size<e||await Kn(this,"next",{...r,filter:()=>this.size<e})}async onIdle(e){this.pending===0&&this.size===0||await Kn(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=Jt({objectMode:!0}),n=c=>{c!=null?this.abort():this.clear(),r.end(c)},o=c=>{c.detail!=null&&r.push(c.detail)},i=c=>{n(c.detail.error)},s=()=>{n()},a=()=>{n(new Ge("Queue aborted"))};this.addEventListener("completed",o),this.addEventListener("failure",i),this.addEventListener("idle",s),e?.signal?.addEventListener("abort",a);try{yield*r}finally{this.removeEventListener("completed",o),this.removeEventListener("failure",i),this.removeEventListener("idle",s),e?.signal?.removeEventListener("abort",a),n()}}};function Ou(t){let e=new globalThis.AbortController;function r(){let i=t.filter(s=>s?.aborted===!0).map(s=>s?.reason).pop();e.abort(i);for(let s of t)s?.removeEventListener!=null&&s.removeEventListener("abort",r)}for(let i of t){if(i?.aborted===!0){r();break}i?.addEventListener!=null&&i.addEventListener("abort",r)}function n(){for(let i of t)i?.removeEventListener!=null&&i.removeEventListener("abort",r)}let o=e.signal;return o.clear=n,o}var Qi=class{readNext;haveNext;ended;nextResult;error;constructor(){this.ended=!1,this.readNext=K(),this.haveNext=K()}[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=K(),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=K(),await Ht(this.readNext.promise,r?.signal,r)}};function zu(){return new Qi}function sm(t){return t[Symbol.asyncIterator]!=null}async function am(t,e,r){try{await Promise.all(t.map(async n=>{for await(let o of n)await e.push(o,{signal:r}),r.throwIfAborted()})),await e.end(void 0,{signal:r})}catch(n){await e.end(n,{signal:r}).catch(()=>{})}}async function*cm(t){let e=new AbortController,r=zu();am(t,r,e.signal).catch(()=>{});try{yield*r}finally{e.abort()}}function*um(t){for(let e of t)yield*e}function fm(...t){let e=[];for(let r of t)sm(r)||e.push(r);return e.length===t.length?um(e):cm(t)}var ju=fm;function to(t,...e){if(t==null)throw new Error("Empty pipeline");if(Xi(t)){let n=t;t=()=>n.source}else if(Vu(t)||Hu(t)){let n=t;t=()=>n}let r=[t,...e];if(r.length>1&&Xi(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++)Xi(r[n])&&(r[n]=dm(r[n]));return lm(...r)}var lm=(...t)=>{let e;for(;t.length>0;)e=t.shift()(e);return e},Hu=t=>t?.[Symbol.asyncIterator]!=null,Vu=t=>t?.[Symbol.iterator]!=null,Xi=t=>t==null?!1:t.sink!=null&&t.source!=null,dm=t=>e=>{let r=t.sink(e);if(r?.then!=null){let n=Jt({objectMode:!0});r.then(()=>{n.end()},s=>{n.end(s)});let o,i=t.source;if(Hu(i))o=async function*(){yield*i,n.end()};else if(Vu(i))o=function*(){yield*i,n.end()};else throw new Error("Unknown duplex source type - must be Iterable or AsyncIterable");return ju(n,o())}return t.source};function hm(t){return t[Symbol.asyncIterator]!=null}function pm(t){if(hm(t))return(async()=>{let n=new Uint8Array(0);for await(let o of t)n=Or([n,o],n.length+o.length);return n})();let e=[],r=0;for(let n of t)e.push(n),r+=n.byteLength;return Or(e,r)}var C=pm;function ro({enumerable:t=!0,configurable:e=!1}={}){return{enumerable:t,configurable:e,writable:!1}}function*mm(t,e){if(e!=null&&typeof e=="object")if(Array.isArray(e))for(let[r,n]of e.entries()){let o=[...t,r],i=B.asCID(n);i!=null?yield[o.join("/"),i]:typeof n=="object"&&(yield*Ki(n,o))}else{let r=B.asCID(e);r!=null?yield[t.join("/"),r]:yield*Ki(e,t)}}function*Ki(t,e){if(t==null||t instanceof Uint8Array)return;let r=B.asCID(t);r!=null&&(yield[e.join("/"),r]);for(let[n,o]of Object.entries(t)){let i=[...e,n];yield*mm(i,o)}}function*ym(t,e){if(Array.isArray(e))for(let[r,n]of e.entries()){let o=[...t,r];yield o.join("/"),typeof n=="object"&&B.asCID(n)==null&&(yield*Yi(n,o))}else yield*Yi(e,t)}function*Yi(t,e){if(!(t==null||typeof t!="object"))for(let[r,n]of Object.entries(t)){let o=[...e,r];yield o.join("/"),n!=null&&!(n instanceof Uint8Array)&&typeof n=="object"&&B.asCID(n)==null&&(yield*ym(o,n))}}function gm(t,e){let r=t;for(let[n,o]of e.entries()){if(r=r[o],r==null)throw new Error(`Object has no property at ${e.slice(0,n+1).map(s=>`[${JSON.stringify(s)}]`).join("")}`);let i=B.asCID(r);if(i!=null)return{value:i,remaining:e.slice(n+1).join("/")}}return{value:r}}var Zi=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:ro(),bytes:ro(),value:ro(),asBlock:ro()})}links(){return Ki(this.value,[])}tree(){return Yi(this.value,[])}get(e="/"){return gm(this.value,e.split("/").filter(Boolean))}};function Pe({bytes:t,cid:e,value:r,codec:n}){let o=r!==void 0?r:n?.decode(t);if(o===void 0)throw new Error('Missing required argument, must either provide "value" or "codec"');return new Zi({cid:e,bytes:t,value:o})}var xm=["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 qu(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=wm(t);return r||"Object"}function wm(t){let e=Object.prototype.toString.call(t).slice(8,-1);if(xm.includes(e))return e}var u=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}};u.uint=new u(0,"uint",!0);u.negint=new u(1,"negint",!0);u.bytes=new u(2,"bytes",!0);u.string=new u(3,"string",!0);u.array=new u(4,"array",!1);u.map=new u(5,"map",!1);u.tag=new u(6,"tag",!1);u.float=new u(7,"float",!0);u.false=new u(7,"false",!0);u.true=new u(7,"true",!0);u.null=new u(7,"null",!0);u.undefined=new u(7,"undefined",!0);u.break=new u(7,"break",!0);var m=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 jr=globalThis.process&&!globalThis.process.browser&&globalThis.Buffer&&typeof globalThis.Buffer.isBuffer=="function",bm=new TextEncoder;function no(t){return jr&&globalThis.Buffer.isBuffer(t)}function gt(t){return t instanceof Uint8Array?no(t)?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):t:Uint8Array.from(t)}var Em=24,_m=200,Hr=jr?t=>t.length>=Em?globalThis.Buffer.from(t):Gu(t):t=>t.length>=_m?bm.encode(t):Gu(t),Oe=t=>Uint8Array.from(t),Ju=jr?(t,e,r)=>no(t)?new Uint8Array(t.subarray(e,r)):t.slice(e,r):(t,e,r)=>t.slice(e,r),Qu=jr?(t,e)=>(t=t.map(r=>r instanceof Uint8Array?r:globalThis.Buffer.from(r)),gt(globalThis.Buffer.concat(t,e))):(t,e)=>{let r=new Uint8Array(e),n=0;for(let o of t)n+o.length>r.length&&(o=o.subarray(0,r.length-n)),r.set(o,n),n+=o.length;return r},Xu=jr?t=>globalThis.Buffer.allocUnsafe(t):t=>new Uint8Array(t);function oo(t,e){if(no(t)&&no(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 Gu(t){let e=[],r=0;for(let n=0;n<t.length;n++){let o=t.charCodeAt(n);o<128?e[r++]=o:o<2048?(e[r++]=o>>6|192,e[r++]=o&63|128):(o&64512)===55296&&n+1<t.length&&(t.charCodeAt(n+1)&64512)===56320?(o=65536+((o&1023)<<10)+(t.charCodeAt(++n)&1023),e[r++]=o>>18|240,e[r++]=o>>12&63|128,e[r++]=o>>6&63|128,e[r++]=o&63|128):(o>=55296&&o<=57343&&(o=65533),e[r++]=o>>12|224,e[r++]=o>>6&63|128,e[r++]=o&63|128)}return e}var Wu=4096;function Ku(t){let e=t.length;if(e<=Wu)return String.fromCharCode.apply(String,t);let r="",n=0;for(;n<e;)r+=String.fromCharCode.apply(String,t.slice(n,n+=Wu));return r}var vm=256,Vr=class{constructor(e=vm){this.chunkSize=e,this.cursor=0,this.maxCursor=-1,this.chunks=[],this._initReuseChunk=null}reset(){this.cursor=0,this.maxCursor=-1,this.chunks.length&&(this.chunks=[]),this._initReuseChunk!==null&&(this.chunks.push(this._initReuseChunk),this.maxCursor=this._initReuseChunk.length-1)}push(e){let r=this.chunks[this.chunks.length-1];if(this.cursor+e.length<=this.maxCursor+1){let o=r.length-(this.maxCursor-this.cursor)-1;r.set(e,o)}else{if(r){let o=r.length-(this.maxCursor-this.cursor)-1;o<r.length&&(this.chunks[this.chunks.length-1]=r.subarray(0,o),this.maxCursor=this.cursor-1)}e.length<64&&e.length<this.chunkSize?(r=Xu(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=Ju(n,0,this.cursor)}else r=Qu(this.chunks,this.cursor);return e&&this.reset(),r}},io=class{constructor(e){this.dest=e,this.cursor=0,this.chunks=[e]}reset(){this.cursor=0}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 _="CBOR decode error:",Xt="CBOR encode error:",qr=[];qr[23]=1;qr[24]=2;qr[25]=3;qr[26]=5;qr[27]=9;function We(t,e,r){if(t.length-e<r)throw new Error(`${_} not enough data for type`)}var G=[24,256,65536,4294967296,BigInt("18446744073709551616")];function he(t,e,r){We(t,e,1);let n=t[e];if(r.strict===!0&&n<G[0])throw new Error(`${_} integer encoded in more bytes than necessary (strict decode)`);return n}function pe(t,e,r){We(t,e,2);let n=t[e]<<8|t[e+1];if(r.strict===!0&&n<G[1])throw new Error(`${_} integer encoded in more bytes than necessary (strict decode)`);return n}function me(t,e,r){We(t,e,4);let n=t[e]*16777216+(t[e+1]<<16)+(t[e+2]<<8)+t[e+3];if(r.strict===!0&&n<G[2])throw new Error(`${_} integer encoded in more bytes than necessary (strict decode)`);return n}function ye(t,e,r){We(t,e,8);let n=t[e]*16777216+(t[e+1]<<16)+(t[e+2]<<8)+t[e+3],o=t[e+4]*16777216+(t[e+5]<<16)+(t[e+6]<<8)+t[e+7],i=(BigInt(n)<<BigInt(32))+BigInt(o);if(r.strict===!0&&i<G[3])throw new Error(`${_} integer encoded in more bytes than necessary (strict decode)`);if(i<=Number.MAX_SAFE_INTEGER)return Number(i);if(r.allowBigInt===!0)return i;throw new Error(`${_} integers outside of the safe integer range are not supported`)}function Yu(t,e,r,n){return new m(u.uint,he(t,e+1,n),2)}function Zu(t,e,r,n){return new m(u.uint,pe(t,e+1,n),3)}function ef(t,e,r,n){return new m(u.uint,me(t,e+1,n),5)}function tf(t,e,r,n){return new m(u.uint,ye(t,e+1,n),9)}function ve(t,e){return W(t,0,e.value)}function W(t,e,r){if(r<G[0]){let n=Number(r);t.push([e|n])}else if(r<G[1]){let n=Number(r);t.push([e|24,n])}else if(r<G[2]){let n=Number(r);t.push([e|25,n>>>8,n&255])}else if(r<G[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<G[4]){let o=[e|27,0,0,0,0,0,0,0],i=Number(n&BigInt(4294967295)),s=Number(n>>BigInt(32)&BigInt(4294967295));o[8]=i&255,i=i>>8,o[7]=i&255,i=i>>8,o[6]=i&255,i=i>>8,o[5]=i&255,o[4]=s&255,s=s>>8,o[3]=s&255,s=s>>8,o[2]=s&255,s=s>>8,o[1]=s&255,t.push(o)}else throw new Error(`${_} encountered BigInt larger than allowable range`)}}ve.encodedSize=function(e){return W.encodedSize(e.value)};W.encodedSize=function(e){return e<G[0]?1:e<G[1]?2:e<G[2]?3:e<G[3]?5:9};ve.compareTokens=function(e,r){return e.value<r.value?-1:e.value>r.value?1:0};function rf(t,e,r,n){return new m(u.negint,-1-he(t,e+1,n),2)}function nf(t,e,r,n){return new m(u.negint,-1-pe(t,e+1,n),3)}function of(t,e,r,n){return new m(u.negint,-1-me(t,e+1,n),5)}var es=BigInt(-1),sf=BigInt(1);function af(t,e,r,n){let o=ye(t,e+1,n);if(typeof o!="bigint"){let i=-1-o;if(i>=Number.MIN_SAFE_INTEGER)return new m(u.negint,i,9)}if(n.allowBigInt!==!0)throw new Error(`${_} integers outside of the safe integer range are not supported`);return new m(u.negint,es-BigInt(o),9)}function so(t,e){let r=e.value,n=typeof r=="bigint"?r*es-sf:r*-1-1;W(t,e.type.majorEncoded,n)}so.encodedSize=function(e){let r=e.value,n=typeof r=="bigint"?r*es-sf:r*-1-1;return n<G[0]?1:n<G[1]?2:n<G[2]?3:n<G[3]?5:9};so.compareTokens=function(e,r){return e.value<r.value?1:e.value>r.value?-1:0};function Gr(t,e,r,n){We(t,e,r+n);let o=t.slice(e+r,e+r+n);return new m(u.bytes,o,r+n)}function cf(t,e,r,n){return Gr(t,e,1,r)}function uf(t,e,r,n){return Gr(t,e,2,he(t,e+1,n))}function ff(t,e,r,n){return Gr(t,e,3,pe(t,e+1,n))}function lf(t,e,r,n){return Gr(t,e,5,me(t,e+1,n))}function df(t,e,r,n){let o=ye(t,e+1,n);if(typeof o=="bigint")throw new Error(`${_} 64-bit integer bytes lengths not supported`);return Gr(t,e,9,o)}function ao(t){return t.encodedBytes===void 0&&(t.encodedBytes=u.equals(t.type,u.string)?Hr(t.value):t.value),t.encodedBytes}function Kt(t,e){let r=ao(e);W(t,e.type.majorEncoded,r.length),t.push(r)}Kt.encodedSize=function(e){let r=ao(e);return W.encodedSize(r.length)+r.length};Kt.compareTokens=function(e,r){return Tm(ao(e),ao(r))};function Tm(t,e){return t.length<e.length?-1:t.length>e.length?1:oo(t,e)}var hf=new TextDecoder,Im=32;function Bm(t,e,r){if(r-e<Im){let o="";for(let i=e;i<r;i++){let s=t[i];if(s&128)return hf.decode(t.subarray(e,r));o+=String.fromCharCode(s)}return o}return hf.decode(t.subarray(e,r))}function Wr(t,e,r,n,o){let i=r+n;We(t,e,i);let s=new m(u.string,Bm(t,e+r,e+i),i);return o.retainStringBytes===!0&&(s.byteValue=t.slice(e+r,e+i)),s}function pf(t,e,r,n){return Wr(t,e,1,r,n)}function mf(t,e,r,n){return Wr(t,e,2,he(t,e+1,n),n)}function yf(t,e,r,n){return Wr(t,e,3,pe(t,e+1,n),n)}function gf(t,e,r,n){return Wr(t,e,5,me(t,e+1,n),n)}function xf(t,e,r,n){let o=ye(t,e+1,n);if(typeof o=="bigint")throw new Error(`${_} 64-bit integer string lengths not supported`);return Wr(t,e,9,o,n)}var wf=Kt;function Yt(t,e,r,n){return new m(u.array,n,r)}function bf(t,e,r,n){return Yt(t,e,1,r)}function Ef(t,e,r,n){return Yt(t,e,2,he(t,e+1,n))}function _f(t,e,r,n){return Yt(t,e,3,pe(t,e+1,n))}function vf(t,e,r,n){return Yt(t,e,5,me(t,e+1,n))}function kf(t,e,r,n){let o=ye(t,e+1,n);if(typeof o=="bigint")throw new Error(`${_} 64-bit integer array lengths not supported`);return Yt(t,e,9,o)}function Tf(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${_} indefinite length items not allowed`);return Yt(t,e,1,1/0)}function co(t,e){W(t,u.array.majorEncoded,e.value)}co.compareTokens=ve.compareTokens;co.encodedSize=function(e){return W.encodedSize(e.value)};function Zt(t,e,r,n){return new m(u.map,n,r)}function Af(t,e,r,n){return Zt(t,e,1,r)}function If(t,e,r,n){return Zt(t,e,2,he(t,e+1,n))}function Bf(t,e,r,n){return Zt(t,e,3,pe(t,e+1,n))}function Sf(t,e,r,n){return Zt(t,e,5,me(t,e+1,n))}function Nf(t,e,r,n){let o=ye(t,e+1,n);if(typeof o=="bigint")throw new Error(`${_} 64-bit integer map lengths not supported`);return Zt(t,e,9,o)}function Uf(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${_} indefinite length items not allowed`);return Zt(t,e,1,1/0)}function uo(t,e){W(t,u.map.majorEncoded,e.value)}uo.compareTokens=ve.compareTokens;uo.encodedSize=function(e){return W.encodedSize(e.value)};function Cf(t,e,r,n){return new m(u.tag,r,1)}function Df(t,e,r,n){return new m(u.tag,he(t,e+1,n),2)}function Lf(t,e,r,n){return new m(u.tag,pe(t,e+1,n),3)}function $f(t,e,r,n){return new m(u.tag,me(t,e+1,n),5)}function Rf(t,e,r,n){return new m(u.tag,ye(t,e+1,n),9)}function fo(t,e){W(t,u.tag.majorEncoded,e.value)}fo.compareTokens=ve.compareTokens;fo.encodedSize=function(e){return W.encodedSize(e.value)};var ts=20,rs=21,ns=22,os=23;function Ff(t,e,r,n){if(n.allowUndefined===!1)throw new Error(`${_} undefined values are not supported`);return n.coerceUndefinedToNull===!0?new m(u.null,null,1):new m(u.undefined,void 0,1)}function Mf(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${_} indefinite length items not allowed`);return new m(u.break,void 0,1)}function is(t,e,r){if(r){if(r.allowNaN===!1&&Number.isNaN(t))throw new Error(`${_} NaN values are not supported`);if(r.allowInfinity===!1&&(t===1/0||t===-1/0))throw new Error(`${_} Infinity values are not supported`)}return new m(u.float,t,e)}function Pf(t,e,r,n){return is(ss(t,e+1),3,n)}function Of(t,e,r,n){return is(as(t,e+1),5,n)}function zf(t,e,r,n){return is(qf(t,e+1),9,n)}function lo(t,e,r){let n=e.value;if(n===!1)t.push([u.float.majorEncoded|ts]);else if(n===!0)t.push([u.float.majorEncoded|rs]);else if(n===null)t.push([u.float.majorEncoded|ns]);else if(n===void 0)t.push([u.float.majorEncoded|os]);else{let o,i=!1;(!r||r.float64!==!0)&&(Hf(n),o=ss(Se,1),n===o||Number.isNaN(n)?(Se[0]=249,t.push(Se.slice(0,3)),i=!0):(Vf(n),o=as(Se,1),n===o&&(Se[0]=250,t.push(Se.slice(0,5)),i=!0))),i||(Dm(n),o=qf(Se,1),Se[0]=251,t.push(Se.slice(0,9)))}}lo.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){Hf(n);let o=ss(Se,1);if(n===o||Number.isNaN(n))return 3;if(Vf(n),o=as(Se,1),n===o)return 5}return 9};var jf=new ArrayBuffer(9),ke=new DataView(jf,1),Se=new Uint8Array(jf,0);function Hf(t){if(t===1/0)ke.setUint16(0,31744,!1);else if(t===-1/0)ke.setUint16(0,64512,!1);else if(Number.isNaN(t))ke.setUint16(0,32256,!1);else{ke.setFloat32(0,t);let e=ke.getUint32(0),r=(e&2139095040)>>23,n=e&8388607;if(r===255)ke.setUint16(0,31744,!1);else if(r===0)ke.setUint16(0,(e&2147483648)>>16|n>>13,!1);else{let o=r-127;o<-24?ke.setUint16(0,0):o<-14?ke.setUint16(0,(e&2147483648)>>16|1<<24+o,!1):ke.setUint16(0,(e&2147483648)>>16|o+15<<10|n>>13,!1)}}}function ss(t,e){if(t.length-e<2)throw new Error(`${_} not enough data for float16`);let r=(t[e]<<8)+t[e+1];if(r===31744)return 1/0;if(r===64512)return-1/0;if(r===32256)return NaN;let n=r>>10&31,o=r&1023,i;return n===0?i=o*2**-24:n!==31?i=(o+1024)*2**(n-25):i=o===0?1/0:NaN,r&32768?-i:i}function Vf(t){ke.setFloat32(0,t,!1)}function as(t,e){if(t.length-e<4)throw new Error(`${_} not enough data for float32`);let r=(t.byteOffset||0)+e;return new DataView(t.buffer,r,4).getFloat32(0,!1)}function Dm(t){ke.setFloat64(0,t,!1)}function qf(t,e){if(t.length-e<8)throw new Error(`${_} not enough data for float64`);let r=(t.byteOffset||0)+e;return new DataView(t.buffer,r,8).getFloat64(0,!1)}lo.compareTokens=ve.compareTokens;function D(t,e,r){throw new Error(`${_} encountered invalid minor (${r}) for major ${t[e]>>>5}`)}function ho(t){return()=>{throw new Error(`${_} ${t}`)}}var g=[];for(let t=0;t<=23;t++)g[t]=D;g[24]=Yu;g[25]=Zu;g[26]=ef;g[27]=tf;g[28]=D;g[29]=D;g[30]=D;g[31]=D;for(let t=32;t<=55;t++)g[t]=D;g[56]=rf;g[57]=nf;g[58]=of;g[59]=af;g[60]=D;g[61]=D;g[62]=D;g[63]=D;for(let t=64;t<=87;t++)g[t]=cf;g[88]=uf;g[89]=ff;g[90]=lf;g[91]=df;g[92]=D;g[93]=D;g[94]=D;g[95]=ho("indefinite length bytes/strings are not supported");for(let t=96;t<=119;t++)g[t]=pf;g[120]=mf;g[121]=yf;g[122]=gf;g[123]=xf;g[124]=D;g[125]=D;g[126]=D;g[127]=ho("indefinite length bytes/strings are not supported");for(let t=128;t<=151;t++)g[t]=bf;g[152]=Ef;g[153]=_f;g[154]=vf;g[155]=kf;g[156]=D;g[157]=D;g[158]=D;g[159]=Tf;for(let t=160;t<=183;t++)g[t]=Af;g[184]=If;g[185]=Bf;g[186]=Sf;g[187]=Nf;g[188]=D;g[189]=D;g[190]=D;g[191]=Uf;for(let t=192;t<=215;t++)g[t]=Cf;g[216]=Df;g[217]=Lf;g[218]=$f;g[219]=Rf;g[220]=D;g[221]=D;g[222]=D;g[223]=D;for(let t=224;t<=243;t++)g[t]=ho("simple values are not supported");g[244]=D;g[245]=D;g[246]=D;g[247]=Ff;g[248]=ho("simple values are not supported");g[249]=Pf;g[250]=Of;g[251]=zf;g[252]=D;g[253]=D;g[254]=D;g[255]=Mf;var Ne=[];for(let t=0;t<24;t++)Ne[t]=new m(u.uint,t,1);for(let t=-1;t>=-24;t--)Ne[31-t]=new m(u.negint,t,1);Ne[64]=new m(u.bytes,new Uint8Array(0),1);Ne[96]=new m(u.string,"",1);Ne[128]=new m(u.array,0,1);Ne[160]=new m(u.map,0,1);Ne[244]=new m(u.false,!1,1);Ne[245]=new m(u.true,!0,1);Ne[246]=new m(u.null,null,1);function Gf(t){switch(t.type){case u.false:return Oe([244]);case u.true:return Oe([245]);case u.null:return Oe([246]);case u.bytes:return t.value.length?void 0:Oe([64]);case u.string:return t.value===""?Oe([96]):void 0;case u.array:return t.value===0?Oe([128]):void 0;case u.map:return t.value===0?Oe([160]):void 0;case u.uint:return t.value<24?Oe([Number(t.value)]):void 0;case u.negint:if(t.value>=-24)return Oe([31-Number(t.value)])}}var Jf=Object.freeze({float64:!0,mapSorter:Pm,quickEncodeToken:Gf});function $m(){let t=[];return t[u.uint.major]=ve,t[u.negint.major]=so,t[u.bytes.major]=Kt,t[u.string.major]=wf,t[u.array.major]=co,t[u.map.major]=uo,t[u.tag.major]=fo,t[u.float.major]=lo,t}var Rm=$m(),Fm=new Vr,po=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(`${Xt} object contains circular references`);return new t(r,e)}},ot={null:new m(u.null,null),undefined:new m(u.undefined,void 0),true:new m(u.true,!0),false:new m(u.false,!1),emptyArray:new m(u.array,0),emptyMap:new m(u.map,0)},it={number(t,e,r,n){return!Number.isInteger(t)||!Number.isSafeInteger(t)?new m(u.float,t):t>=0?new m(u.uint,t):new m(u.negint,t)},bigint(t,e,r,n){return t>=BigInt(0)?new m(u.uint,t):new m(u.negint,t)},Uint8Array(t,e,r,n){return new m(u.bytes,t)},string(t,e,r,n){return new m(u.string,t)},boolean(t,e,r,n){return t?ot.true:ot.false},null(t,e,r,n){return ot.null},undefined(t,e,r,n){return ot.undefined},ArrayBuffer(t,e,r,n){return new m(u.bytes,new Uint8Array(t))},DataView(t,e,r,n){return new m(u.bytes,new Uint8Array(t.buffer,t.byteOffset,t.byteLength))},Array(t,e,r,n){if(!t.length)return r.addBreakTokens===!0?[ot.emptyArray,new m(u.break)]:ot.emptyArray;n=po.createCheck(n,t);let o=[],i=0;for(let s of t)o[i++]=er(s,r,n);return r.addBreakTokens?[new m(u.array,t.length),o,new m(u.break)]:[new m(u.array,t.length),o]},Object(t,e,r,n){let o=e!=="Object",i=o?t.keys():Object.keys(t),s=o?t.size:i.length,a;if(s){a=new Array(s),n=po.createCheck(n,t);let c=!o&&r.ignoreUndefinedProperties,f=0;for(let l of i){let p=o?t.get(l):t[l];c&&p===void 0||(a[f++]=[er(l,r,n),er(p,r,n)])}f<s&&(a.length=f)}return a?.length?(Mm(a,r),r.addBreakTokens?[new m(u.map,a.length),a,new m(u.break)]:[new m(u.map,a.length),a]):r.addBreakTokens===!0?[ot.emptyMap,new m(u.break)]:ot.emptyMap},Tagged(t,e,r,n){return[new m(u.tag,t.tag),er(t.value,r,n)]}};it.Map=it.Object;it.Buffer=it.Uint8Array;for(let t of"Uint8Clamped Uint16 Uint32 Int8 Int16 Int32 BigUint64 BigInt64 Float32 Float64".split(" "))it[`${t}Array`]=it.DataView;function er(t,e={},r){let n=qu(t),o=e&&e.typeEncoders&&e.typeEncoders[n]||it[n];if(typeof o=="function"){let s=o(t,n,e,r);if(s!=null)return s}let i=it[n];if(!i)throw new Error(`${Xt} unsupported type: ${n}`);return i(t,n,e,r)}function Mm(t,e){e.mapSorter&&t.sort(e.mapSorter)}function Pm(t,e){if(t[0]instanceof m&&e[0]instanceof m){let r=t[0],n=e[0];return r._keyBytes||(r._keyBytes=Wf(r.value)),n._keyBytes||(n._keyBytes=Wf(n.value)),oo(r._keyBytes,n._keyBytes)}throw new Error("rfc8949MapSorter: complex key types are not supported yet")}function Wf(t){return Xf(t,Rm,Jf)}function Qf(t,e,r,n){if(Array.isArray(e))for(let o of e)Qf(t,o,r,n);else r[e.type.major](t,e,n)}var PE=u.uint.majorEncoded,OE=u.negint.majorEncoded,zE=u.bytes.majorEncoded,jE=u.string.majorEncoded,HE=u.array.majorEncoded,VE=u.float.majorEncoded|ts,qE=u.float.majorEncoded|rs,GE=u.float.majorEncoded|ns,WE=u.float.majorEncoded|os,JE=BigInt(-1),QE=BigInt(1);function Xf(t,e,r,n){let o=n instanceof Uint8Array,i=o?new io(n):Fm,s=er(t,r);if(!Array.isArray(s)&&r.quickEncodeToken){let a=r.quickEncodeToken(s);if(a)return o?(i.push(a),i.toBytes()):a;let c=e[s.type.major];if(c.encodedSize){let f=c.encodedSize(s,r);if(o||(i=new Vr(f)),c(i,s,r),i.chunks.length!==1)throw new Error(`Unexpected error: pre-calculated length for ${s} was wrong`);return o?i.toBytes():gt(i.chunks[0])}}return i.reset(),Qf(i,s,e,r),i.toBytes(!0)}var Om={strict:!1,allowIndefinite:!0,allowUndefined:!0,allowBigInt:!0},mo=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=Ne[e];if(r===void 0){let n=g[e];if(!n)throw new Error(`${_} no decoder for major type ${e>>>5} (byte 0x${e.toString(16).padStart(2,"0")})`);let o=e&31;r=n(this.data,this._pos,o,this.options)}return this._pos+=r.encodedLength,r}},st=Symbol.for("DONE"),tr=Symbol.for("BREAK");function zm(t,e,r){let n=[];for(let o=0;o<t.value;o++){let i=at(e,r);if(i===tr){if(t.value===1/0)break;throw new Error(`${_} got unexpected break to lengthed array`)}if(i===st)throw new Error(`${_} found array but not enough entries (got ${o}, expected ${t.value})`);n[o]=i}return n}function jm(t,e,r){let n=r.useMaps===!0,o=r.rejectDuplicateMapKeys===!0,i=n?void 0:{},s=n?new Map:void 0;for(let a=0;a<t.value;a++){let c=at(e,r);if(c===tr){if(t.value===1/0)break;throw new Error(`${_} got unexpected break to lengthed map`)}if(c===st)throw new Error(`${_} found map but not enough entries (got ${a} [no key], expected ${t.value})`);if(!n&&typeof c!="string")throw new Error(`${_} non-string keys not supported (got ${typeof c})`);if(o&&(n&&s.has(c)||!n&&Object.hasOwn(i,c)))throw new Error(`${_} found repeat map key "${c}"`);let f=at(e,r);if(f===st)throw new Error(`${_} found map but not enough entries (got ${a} [no value], expected ${t.value})`);n?s.set(c,f):i[c]=f}return n?s:i}function*Hm(t,e,r){for(let n=0;n<t.value;n++){let o=at(e,r);if(o===tr){if(t.value===1/0)break;throw new Error(`${_} got unexpected break to lengthed map`)}if(o===st)throw new Error(`${_} found map but not enough entries (got ${n} [no key], expected ${t.value})`);let i=at(e,r);if(i===st)throw new Error(`${_} found map but not enough entries (got ${n} [no value], expected ${t.value})`);yield[o,i]}}function Vm(t,e){let r=!1,n=function(){if(r)throw new Error(`${_} tag decode() may only be called once`);r=!0;let o=at(t,e);if(o===st)throw new Error(`${_} tag content missing`);if(o===tr)throw new Error(`${_} got unexpected break in tag content`);return o};return n.entries=function(){if(r)throw new Error(`${_} tag decode() may only be called once`);r=!0;let o=t.next();if(!u.equals(o.type,u.map))throw new Error(`${_} entries() requires map content, got ${o.type.name}`);let i=[];for(let s of Hm(o,t,e))i.push(s);return i},Object.defineProperty(n,"_called",{get(){return r},enumerable:!1}),n}function at(t,e){if(t.done())return st;let r=t.next();if(u.equals(r.type,u.break))return tr;if(r.type.terminal)return r.value;if(u.equals(r.type,u.array))return zm(r,t,e);if(u.equals(r.type,u.map))return jm(r,t,e);if(u.equals(r.type,u.tag)){if(e.tags&&typeof e.tags[r.value]=="function"){let n=Vm(t,e),o=e.tags[r.value](n);if(!n._called)throw new Error(`${_} tag decoder must call decode() or entries()`);return o}throw new Error(`${_} tag not supported (${r.value})`)}throw new Error("unsupported")}function cs(t,e){if(!(t instanceof Uint8Array))throw new Error(`${_} data to decode must be a Uint8Array`);e=Object.assign({},Om,e);let r=gt(t),n=e.tokenizer||new mo(r,e),o=at(n,e);if(o===st)throw new Error(`${_} did not find any content to decode`);if(o===tr)throw new Error(`${_} got unexpected break`);return[o,t.subarray(n.pos())]}function us(t,e){let[r,n]=cs(t,e);if(n.length>0)throw new Error(`${_} too many terminals, data makes no sense`);return r}var yo=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(yo.prototype,Symbol.toStringTag,{value:"Tagged"});var Kf=class extends Array{constructor(){super(),this.inRecursive=[]}prefix(e){let r=this.inRecursive[this.inRecursive.length-1];r&&(u.equals(r.type,u.array)&&(r.elements++,r.elements!==1&&e.push([44])),u.equals(r.type,u.map)&&(r.elements++,r.elements!==1&&(r.elements%2===1?e.push([44]):e.push([58]))))}[u.uint.major](e,r){this.prefix(e);let n=String(r.value),o=[];for(let i=0;i<n.length;i++)o[i]=n.charCodeAt(i);e.push(o)}[u.negint.major](e,r){this[u.uint.major](e,r)}[u.bytes.major](e,r){throw new Error(`${Xt} unsupported type: Uint8Array`)}[u.string.major](e,r){this.prefix(e);let n=Hr(JSON.stringify(r.value));e.push(n.length>32?gt(n):n)}[u.array.major](e,r){this.prefix(e),this.inRecursive.push({type:u.array,elements:0}),e.push([91])}[u.map.major](e,r){this.prefix(e),this.inRecursive.push({type:u.map,elements:0}),e.push([123])}[u.tag.major](e,r){}[u.float.major](e,r){if(r.type.name==="break"){let s=this.inRecursive.pop();if(s){if(u.equals(s.type,u.array))e.push([93]);else if(u.equals(s.type,u.map))e.push([125]);else throw new Error("Unexpected recursive type; this should not happen!");return}throw new Error("Unexpected break; this should not happen!")}if(r.value===void 0)throw new Error(`${Xt} unsupported type: undefined`);if(this.prefix(e),r.type.name==="true"){e.push([116,114,117,101]);return}else if(r.type.name==="false"){e.push([102,97,108,115,101]);return}else if(r.type.name==="null"){e.push([110,117,108,108]);return}let n=String(r.value),o=[],i=!1;for(let s=0;s<n.length;s++)o[s]=n.charCodeAt(s),!i&&(o[s]===46||o[s]===101||o[s]===69)&&(i=!0);i||(o.push(46),o.push(48)),e.push(o)}};var rr=class{constructor(e,r={}){this._pos=0,this.data=e,this.options=r,this.modeStack=["value"],this.lastToken=""}pos(){return this._pos}done(){return this._pos>=this.data.length}ch(){return this.data[this._pos]}currentMode(){return this.modeStack[this.modeStack.length-1]}skipWhitespace(){let e=this.ch();for(;e===32||e===9||e===13||e===10;)e=this.data[++this._pos]}expect(e){if(this.data.length-this._pos<e.length)throw new Error(`${_} unexpected end of input at position ${this._pos}`);for(let r=0;r<e.length;r++)if(this.data[this._pos++]!==e[r])throw new Error(`${_} unexpected token at position ${this._pos}, expected to find '${String.fromCharCode(...e)}'`)}parseNumber(){let e=this._pos,r=!1,n=!1,o=a=>{for(;!this.done();){let c=this.ch();if(a.includes(c))this._pos++;else break}};if(this.ch()===45&&(r=!0,this._pos++),this.ch()===48)if(this._pos++,this.ch()===46)this._pos++,n=!0;else return new m(u.uint,0,this._pos-e);if(o([48,49,50,51,52,53,54,55,56,57]),r&&this._pos===e+1)throw new Error(`${_} unexpected token at position ${this._pos}`);if(!this.done()&&this.ch()===46){if(n)throw new Error(`${_} unexpected token at position ${this._pos}`);n=!0,this._pos++,o([48,49,50,51,52,53,54,55,56,57])}!this.done()&&(this.ch()===101||this.ch()===69)&&(n=!0,this._pos++,!this.done()&&(this.ch()===43||this.ch()===45)&&this._pos++,o([48,49,50,51,52,53,54,55,56,57]));let i=String.fromCharCode.apply(null,this.data.subarray(e,this._pos)),s=parseFloat(i);return n?new m(u.float,s,this._pos-e):this.options.allowBigInt!==!0||Number.isSafeInteger(s)?new m(s>=0?u.uint:u.negint,s,this._pos-e):new m(s>=0?u.uint:u.negint,BigInt(i),this._pos-e)}parseString(){if(this.ch()!==34)throw new Error(`${_} unexpected character at position ${this._pos}; this shouldn't happen`);this._pos++;for(let i=this._pos,s=0;i<this.data.length&&s<65536;i++,s++){let a=this.data[i];if(a===92||a<32||a>=128)break;if(a===34){let c=String.fromCharCode.apply(null,this.data.subarray(this._pos,i));return this._pos=i+1,new m(u.string,c,s)}}let e=this._pos,r=[],n=()=>{if(this._pos+4>=this.data.length)throw new Error(`${_} unexpected end of unicode escape sequence at position ${this._pos}`);let i=0;for(let s=0;s<4;s++){let a=this.ch();if(a>=48&&a<=57)a-=48;else if(a>=97&&a<=102)a=a-97+10;else if(a>=65&&a<=70)a=a-65+10;else throw new Error(`${_} unexpected unicode escape character at position ${this._pos}`);i=i*16+a,this._pos++}return i},o=()=>{let i=this.ch(),s=null,a=i>239?4:i>223?3:i>191?2:1;if(this._pos+a>this.data.length)throw new Error(`${_} unexpected unicode sequence at position ${this._pos}`);let c,f,l,p;switch(a){case 1:i<128&&(s=i);break;case 2:c=this.data[this._pos+1],(c&192)===128&&(p=(i&31)<<6|c&63,p>127&&(s=p));break;case 3:c=this.data[this._pos+1],f=this.data[this._pos+2],(c&192)===128&&(f&192)===128&&(p=(i&15)<<12|(c&63)<<6|f&63,p>2047&&(p<55296||p>57343)&&(s=p));break;case 4:c=this.data[this._pos+1],f=this.data[this._pos+2],l=this.data[this._pos+3],(c&192)===128&&(f&192)===128&&(l&192)===128&&(p=(i&15)<<18|(c&63)<<12|(f&63)<<6|l&63,p>65535&&p<1114112&&(s=p))}s===null?(s=65533,a=1):s>65535&&(s-=65536,r.push(s>>>10&1023|55296),s=56320|s&1023),r.push(s),this._pos+=a};for(;!this.done();){let i=this.ch(),s;switch(i){case 92:if(this._pos++,this.done())throw new Error(`${_} unexpected string termination at position ${this._pos}`);switch(s=this.ch(),this._pos++,s){case 34:case 39:case 92:case 47:r.push(s);break;case 98:r.push(8);break;case 116:r.push(9);break;case 110:r.push(10);break;case 102:r.push(12);break;case 114:r.push(13);break;case 117:r.push(n());break;default:throw new Error(`${_} unexpected string escape character at position ${this._pos}`)}break;case 34:return this._pos++,new m(u.string,Ku(r),this._pos-e);default:if(i<32)throw new Error(`${_} invalid control character at position ${this._pos}`);i<128?(r.push(i),this._pos++):o()}}throw new Error(`${_} unexpected end of string at position ${this._pos}`)}parseValue(){switch(this.ch()){case 123:return this.modeStack.push("obj-start"),this._pos++,new m(u.map,1/0,1);case 91:return this.modeStack.push("array-start"),this._pos++,new m(u.array,1/0,1);case 34:return this.parseString();case 110:return this.expect([110,117,108,108]),new m(u.null,null,4);case 102:return this.expect([102,97,108,115,101]),new m(u.false,!1,5);case 116:return this.expect([116,114,117,101]),new m(u.true,!0,4);case 45:case 48:case 49:case 50:case 51:case 52:case 53:case 54:case 55:case 56:case 57:return this.parseNumber();default:throw new Error(`${_} unexpected character at position ${this._pos}`)}}next(){switch(this.skipWhitespace(),this.currentMode()){case"value":return this.modeStack.pop(),this.parseValue();case"array-value":{if(this.modeStack.pop(),this.ch()===93)return this._pos++,this.skipWhitespace(),new m(u.break,void 0,1);if(this.ch()!==44)throw new Error(`${_} unexpected character at position ${this._pos}, was expecting array delimiter but found '${String.fromCharCode(this.ch())}'`);return this._pos++,this.modeStack.push("array-value"),this.skipWhitespace(),this.parseValue()}case"array-start":return this.modeStack.pop(),this.ch()===93?(this._pos++,this.skipWhitespace(),new m(u.break,void 0,1)):(this.modeStack.push("array-value"),this.skipWhitespace(),this.parseValue());case"obj-key":if(this.ch()===125)return this.modeStack.pop(),this._pos++,this.skipWhitespace(),new m(u.break,void 0,1);if(this.ch()!==44)throw new Error(`${_} unexpected character at position ${this._pos}, was expecting object delimiter but found '${String.fromCharCode(this.ch())}'`);this._pos++,this.skipWhitespace();case"obj-start":{if(this.modeStack.pop(),this.ch()===125)return this._pos++,this.skipWhitespace(),new m(u.break,void 0,1);let e=this.parseString();if(this.skipWhitespace(),this.ch()!==58)throw new Error(`${_} unexpected character at position ${this._pos}, was expecting key/value delimiter ':' but found '${String.fromCharCode(this.ch())}'`);return this._pos++,this.modeStack.push("obj-value"),e}case"obj-value":return this.modeStack.pop(),this.modeStack.push("obj-key"),this.skipWhitespace(),this.parseValue();default:throw new Error(`${_} unexpected parse state at position ${this._pos}; this shouldn't happen`)}}};function fs(t,e){return e=Object.assign({tokenizer:new rr(t,e)},e),us(t,e)}function Wm(t){return t instanceof ArrayBuffer?new Uint8Array(t,0,t.byteLength):t}var ls=class extends rr{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(u.equals(e.type,u.map)){let r=this._next();if(u.equals(r.type,u.string)&&r.value==="/"){let n=this._next();if(u.equals(n.type,u.string)){let o=this._next();if(!u.equals(o.type,u.break))throw new Error("Invalid encoded CID form");return this.tokenBuffer.push(n),new m(u.tag,42,0)}if(u.equals(n.type,u.map)){let o=this._next();if(u.equals(o.type,u.string)&&o.value==="bytes"){let i=this._next();if(u.equals(i.type,u.string)){for(let a=0;a<2;a++){let c=this._next();if(!u.equals(c.type,u.break))throw new Error("Invalid encoded Bytes form")}let s=Fi.decode(`m${i.value}`);return new m(u.bytes,s,i.value.length)}this.tokenBuffer.push(i)}this.tokenBuffer.push(o)}this.tokenBuffer.push(n)}this.tokenBuffer.push(r)}return e}},Yf={allowIndefinite:!1,allowUndefined:!1,allowNaN:!1,allowInfinity:!1,allowBigInt:!0,strict:!0,useMaps:!1,rejectDuplicateMapKeys:!0,tags:{42:t=>B.parse(t())}};var go=297;var xo=t=>{let e=Wm(t),r=Object.assign(Yf,{tokenizer:new ls(e,Yf)});return fs(e,r)};var A_=new TextDecoder;var I_=new TextEncoder;var Jm=new TextDecoder;function ds(t,e){let r=0;for(let n=0;;n+=7){if(n>=64)throw new Error("protobuf: varint overflow");if(e>=t.length)throw new Error("protobuf: unexpected end of data");let o=t[e++];if(r+=n<28?(o&127)<<n:(o&127)*2**n,o<128)break}return[r,e]}function bo(t,e){let r;[r,e]=ds(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 Zf(t,e){let r;return[r,e]=ds(t,e),[r&7,r>>3,e]}function Qm(t){let e={},r=t.length,n=0;for(;n<r;){let o,i;if([o,i,n]=Zf(t,n),i===1){if(e.Hash)throw new Error("protobuf: (PBLink) duplicate Hash section");if(o!==2)throw new Error(`protobuf: (PBLink) wrong wireType (${o}) for Hash`);if(e.Name!==void 0)throw new Error("protobuf: (PBLink) invalid order, found Name before Hash");if(e.Tsize!==void 0)throw new Error("protobuf: (PBLink) invalid order, found Tsize before Hash");[e.Hash,n]=bo(t,n)}else if(i===2){if(e.Name!==void 0)throw new Error("protobuf: (PBLink) duplicate Name section");if(o!==2)throw new Error(`protobuf: (PBLink) wrong wireType (${o}) for Name`);if(e.Tsize!==void 0)throw new Error("protobuf: (PBLink) invalid order, found Tsize before Name");let s;[s,n]=bo(t,n),e.Name=Jm.decode(s)}else if(i===3){if(e.Tsize!==void 0)throw new Error("protobuf: (PBLink) duplicate Tsize section");if(o!==0)throw new Error(`protobuf: (PBLink) wrong wireType (${o}) for Tsize`);[e.Tsize,n]=ds(t,n)}else throw new Error(`protobuf: (PBLink) invalid fieldNumber, expected 1, 2 or 3, got ${i}`)}if(n>r)throw new Error("protobuf: (PBLink) unexpected end of data");return e}function el(t){let e=t.length,r=0,n,o=!1,i;for(;r<e;){let a,c;if([a,c,r]=Zf(t,r),a!==2)throw new Error(`protobuf: (PBNode) invalid wireType, expected 2, got ${a}`);if(c===1){if(i)throw new Error("protobuf: (PBNode) duplicate Data section");[i,r]=bo(t,r),n&&(o=!0)}else if(c===2){if(o)throw new Error("protobuf: (PBNode) duplicate Links section");n||(n=[]);let f;[f,r]=bo(t,r),n.push(Qm(f))}else throw new Error(`protobuf: (PBNode) invalid fieldNumber, expected 1 or 2, got ${c}`)}if(r>e)throw new Error("protobuf: (PBNode) unexpected end of data");let s={};return i&&(s.Data=i),s.Links=n||[],s}var rl=new TextEncoder,tl=2**32,Xm=2**31;function Km(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=Jr(e,r,t.Tsize)-1,e[r]=24}if(typeof t.Name=="string"){let n=rl.encode(t.Name);r-=n.length,e.set(n,r),r=Jr(e,r,n.length)-1,e[r]=18}return t.Hash&&(r-=t.Hash.length,e.set(t.Hash,r),r=Jr(e,r,t.Hash.length)-1,e[r]=10),e.length-r}function nl(t){let e=Zm(t),r=new Uint8Array(e),n=e;if(t.Data&&(n-=t.Data.length,r.set(t.Data,n),n=Jr(r,n,t.Data.length)-1,r[n]=10),t.Links)for(let o=t.Links.length-1;o>=0;o--){let i=Km(t.Links[o],r.subarray(0,n));n-=i,n=Jr(r,n,i)-1,r[n]=18}return r}function Ym(t){let e=0;if(t.Hash){let r=t.Hash.length;e+=1+r+nr(r)}if(typeof t.Name=="string"){let r=rl.encode(t.Name).length;e+=1+r+nr(r)}return typeof t.Tsize=="number"&&(e+=1+nr(t.Tsize)),e}function Zm(t){let e=0;if(t.Data){let r=t.Data.length;e+=1+r+nr(r)}if(t.Links)for(let r of t.Links){let n=Ym(r);e+=1+n+nr(n)}return e}function Jr(t,e,r){e-=nr(r);let n=e;for(;r>=Xm;)t[e++]=r&127|128,r/=128;for(;r>=128;)t[e++]=r&127|128,r>>>=7;return t[e]=r,n}function nr(t){return t%2===0&&t++,Math.floor((ey(t)+6)/7)}function ey(t){let e=0;return t>=tl&&(t=Math.floor(t/tl),e=32),t>=65536&&(t>>>=16,e+=16),t>=256&&(t>>>=8,e+=8),e+ty[t]}var ty=[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 ry=["Data","Links"],ny=["Hash","Name","Tsize"],ol=new TextEncoder;function oy(t,e){if(t===e)return 0;let r=t.Name?ol.encode(t.Name):[],n=e.Name?ol.encode(e.Name):[],o=r.length,i=n.length;for(let s=0,a=Math.min(o,i);s<a;++s)if(r[s]!==n[s]){o=r[s],i=n[s];break}return o<i?-1:i<o?1:0}function il(t,e){return!Object.keys(t).some(r=>!e.includes(r))}function sl(t){if(!t||typeof t!="object"||Array.isArray(t)||t instanceof Uint8Array||t["/"]&&t["/"]===t.bytes)throw new TypeError("Invalid DAG-PB form");if(!il(t,ry))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(!il(r,ny))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&&oy(r,t.Links[e-1])===-1)throw new TypeError("Invalid DAG-PB form (links must be sorted by Name bytes)")}}function al(t){return t instanceof ArrayBuffer?new Uint8Array(t,0,t.byteLength):t}var or=112;function cl(t){sl(t);let e={};return t.Links&&(e.Links=t.Links.map(r=>{let n={};return r.Hash&&(n.Hash=r.Hash.bytes),r.Name!==void 0&&(n.Name=r.Name),r.Tsize!==void 0&&(n.Tsize=r.Tsize),n})),t.Data&&(e.Data=t.Data),nl(e)}function ze(t){let e=al(t),r=el(e),n={};return r.Data&&(n.Data=r.Data),r.Links&&(n.Links=r.Links.map(o=>{let i={};try{i.Hash=B.decode(o.Hash)}catch{}if(!i.Hash)throw new Error("Invalid Hash field found in link, expected CID");return o.Name!==void 0&&(i.Name=o.Name),o.Tsize!==void 0&&(i.Tsize=o.Tsize),i})),n}function iy(t){return t[Symbol.asyncIterator]!=null}function sy(t,e){let r=0;if(iy(t))return(async function*(){for await(let c of t)await e(c,r++)&&(yield c)})();let n=Hn(t),{value:o,done:i}=n.next();if(i===!0)return(function*(){})();let s=e(o,r++);if(typeof s.then=="function")return(async function*(){await s&&(yield o);for(let c of n)await e(c,r++)&&(yield c)})();let a=e;return(function*(){s===!0&&(yield o);for(let c of n)a(c,r++)&&(yield c)})()}var ul=sy;function wt(t){return e=>new hs(e,t)}function bt(t){return e=>new ps(e,t)}function ys(t){return e=>new ms(e,t)}var Xr=class{components;constructor(e,r={}){this.components=e}async*walk(e,r){let n=this.getQueue(),o=ul(n.toGenerator(r),a=>a!=null),i=!1,s=async a=>{let c=a.cid,f=await C(this.components.blockstore.get(c,a)),l=Pe({cid:c,bytes:f,codec:await this.components.getCodec(c.code)});for(let[,p]of l.links())r?.includeChild?.(p,l)!==!1&&n.add(s,{...a,cid:p,depth:a.depth+1,path:[...a.path,p]}).catch(v=>{i||o.throw(v)});return{block:l,depth:a.depth,path:a.path}};n.add(s,{...r,cid:e,depth:0,path:[e]}).catch(a=>{i||o.throw(a)});try{yield*o}finally{i=!0,n.abort()}}},hs=class extends Xr{getQueue(){return new Qt({concurrency:1,sort:(e,r)=>e.options.depth===r.options.depth?0:e.options.depth<r.options.depth?1:-1})}},ps=class extends Xr{getQueue(){return new Qt({concurrency:1,sort:(e,r)=>e.options.depth===r.options.depth?0:e.options.depth<r.options.depth?-1:1})}},ms=class extends Xr{getQueue(){return new Qt({concurrency:1})}};var Kr=class{walker;constructor(e){this.walker=e?.walker}async*export(e,r,n,o){let i,s={blockstore:r,getCodec:n};this.walker!=null?i=this.walker(s):i=bt()(s);for await(let a of i.walk(e,o))yield a.block}};var Eo=class{components;log;constructor(e){this.components=e,this.log=e.logger.forComponent("helia:car")}async import(e,r){await Bi(this.components.blockstore.putMany(jt(e.blocks(),({cid:n,bytes:o})=>({cid:n,bytes:o})),r))}async*export(e,r){let n=Array.isArray(e)?e:[e],{writer:o,out:i}=Lr.create(n),s=i[Symbol.asyncIterator](),a=new AbortController;for(this._export(n,o,r).catch(c=>{this.log.error("error during streaming export - %e",c),a.abort(c)});;){let{done:c,value:f}=await Ht(s.next(),a.signal);if(a.signal.aborted)throw a.signal.reason;if(f!=null&&(yield f),c===!0)break}}async _export(e,r,n){let o=n?.traversal;for(let i of e){if(i.multihash.code===0)continue;let s=n?.exporter??(i.code===112?new Yr:new Kr),a=i,c=!1;if(o!=null){for await(let{cid:f,bytes:l}of o.traverse(a,this.components.blockstore,this.components.getCodec,n))if(this.log.trace("next CID on path to %c is %c",i,f),a=f,i.equals(f)&&(c=!0),c||n?.includeTraversalBlocks===!0){if(n?.blockFilter?.has(f.multihash.bytes)===!0)continue;n?.blockFilter?.add(f.multihash.bytes),await r.put({cid:f,bytes:l})}}for await(let{cid:f,bytes:l}of s.export(a,this.components.blockstore,this.components.getCodec,n))n?.blockFilter?.has(f.multihash.bytes)!==!0&&f.multihash.code!==0&&(c&&f.equals(a)||(n?.blockFilter?.add(f.multihash.bytes),await r.put({cid:f,bytes:l})))}await r.close()}};var gs=class{async*export(e,r,n,o){let i=await C(r.get(e,o));yield Pe({cid:e,bytes:i,codec:await n(e.code)})}};var Zr=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 xs=new Float32Array([-0]),ct=new Uint8Array(xs.buffer);function ll(t,e,r){xs[0]=t,e[r]=ct[0],e[r+1]=ct[1],e[r+2]=ct[2],e[r+3]=ct[3]}function dl(t,e){return ct[0]=t[e],ct[1]=t[e+1],ct[2]=t[e+2],ct[3]=t[e+3],xs[0]}var ws=new Float64Array([-0]),Y=new Uint8Array(ws.buffer);function hl(t,e,r){ws[0]=t,e[r]=Y[0],e[r+1]=Y[1],e[r+2]=Y[2],e[r+3]=Y[3],e[r+4]=Y[4],e[r+5]=Y[5],e[r+6]=Y[6],e[r+7]=Y[7]}function pl(t,e){return Y[0]=t[e],Y[1]=t[e+1],Y[2]=t[e+2],Y[3]=t[e+3],Y[4]=t[e+4],Y[5]=t[e+5],Y[6]=t[e+6],Y[7]=t[e+7],ws[0]}var cy=BigInt(Number.MAX_SAFE_INTEGER),uy=BigInt(Number.MIN_SAFE_INTEGER),ge=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 Et;if(e<cy&&e>uy)return this.fromNumber(Number(e));let r=e<0n;r&&(e=-e);let n=e>>32n,o=e-(n<<32n);return r&&(n=~n|0n,o=~o|0n,++o>ml&&(o=0n,++n>ml&&(n=0n))),new t(Number(o),Number(n))}static fromNumber(e){if(e===0)return Et;let r=e<0;r&&(e=-e);let n=e>>>0,o=(e-n)/4294967296>>>0;return r&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new t(n,o)}static from(e){return typeof e=="number"?t.fromNumber(e):typeof e=="bigint"?t.fromBigInt(e):typeof e=="string"?t.fromBigInt(BigInt(e)):e.low!=null||e.high!=null?new t(e.low>>>0,e.high>>>0):Et}},Et=new ge(0,0);Et.toBigInt=function(){return 0n};Et.zzEncode=Et.zzDecode=function(){return this};Et.length=function(){return 1};var ml=4294967296n;function yl(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 gl(t,e,r){if(r-e<1)return"";let o,i=[],s=0,a;for(;e<r;)a=t[e++],a<128?i[s++]=a:a>191&&a<224?i[s++]=(a&31)<<6|t[e++]&63:a>239&&a<365?(a=((a&7)<<18|(t[e++]&63)<<12|(t[e++]&63)<<6|t[e++]&63)-65536,i[s++]=55296+(a>>10),i[s++]=56320+(a&1023)):i[s++]=(a&15)<<12|(t[e++]&63)<<6|t[e++]&63,s>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,i)),s=0);return o!=null?(s>0&&o.push(String.fromCharCode.apply(String,i.slice(0,s))),o.join("")):String.fromCharCode.apply(String,i.slice(0,s))}function bs(t,e,r){let n=r,o,i;for(let s=0;s<t.length;++s)o=t.charCodeAt(s),o<128?e[r++]=o:o<2048?(e[r++]=o>>6|192,e[r++]=o&63|128):(o&64512)===55296&&((i=t.charCodeAt(s+1))&64512)===56320?(o=65536+((o&1023)<<10)+(i&1023),++s,e[r++]=o>>18|240,e[r++]=o>>12&63|128,e[r++]=o>>6&63|128,e[r++]=o&63|128):(e[r++]=o>>12|224,e[r++]=o>>6&63|128,e[r++]=o&63|128);return r-n}function Ue(t,e){return RangeError(`index out of range: ${t.pos} + ${e??1} > ${t.len}`)}function _o(t,e){return(t[e-4]|t[e-3]<<8|t[e-2]<<16|t[e-1]<<24)>>>0}var Es=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(e){this.buf=e,this.pos=0,this.len=e.length}uint32(){let e=4294967295;if(e=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(e=(e|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return e;if((this.pos+=5)>this.len)throw this.pos=this.len,Ue(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 Ue(this,4);return _o(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Ue(this,4);return _o(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Ue(this,4);let e=dl(this.buf,this.pos);return this.pos+=4,e}double(){if(this.pos+8>this.len)throw Ue(this,4);let e=pl(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 Ue(this,e);return this.pos+=e,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let e=this.bytes();return gl(e,0,e.length)}skip(e){if(typeof e=="number"){if(this.pos+e>this.len)throw Ue(this,e);this.pos+=e}else do if(this.pos>=this.len)throw Ue(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 ge(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 Ue(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 Ue(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 Ue(this,8);let e=_o(this.buf,this.pos+=4),r=_o(this.buf,this.pos+=4);return new ge(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=Pu(this.buf,this.pos);return this.pos+=zr(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 _s(t){return new Es(t instanceof Uint8Array?t:t.subarray())}function en(t,e,r){let n=_s(t);return e.decode(n,void 0,r)}function vs(t){let e=t??8192,r=e>>>1,n,o=e;return function(s){if(s<1||s>r)return Me(s);o+s>e&&(n=Me(e),o=0);let a=n.subarray(o,o+=s);return(o&7)!==0&&(o=(o|7)+1),a}}var _t=class{fn;len;next;val;constructor(e,r,n){this.fn=e,this.len=r,this.next=void 0,this.val=n}};function ks(){}var As=class{head;tail;len;next;constructor(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}},fy=vs();function ly(t){return globalThis.Buffer!=null?Me(t):fy(t)}var rn=class{len;head;tail;states;constructor(){this.len=0,this.head=new _t(ks,0,0),this.tail=this.head,this.states=null}_push(e,r,n){return this.tail=this.tail.next=new _t(e,r,n),this.len+=r,this}uint32(e){return this.len+=(this.tail=this.tail.next=new Is((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(vo,10,ge.fromNumber(e)):this.uint32(e)}sint32(e){return this.uint32((e<<1^e>>31)>>>0)}uint64(e){let r=ge.fromBigInt(e);return this._push(vo,r.length(),r)}uint64Number(e){return this._push(Mu,zr(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=ge.fromBigInt(e).zzEncode();return this._push(vo,r.length(),r)}sint64Number(e){let r=ge.fromNumber(e).zzEncode();return this._push(vo,r.length(),r)}sint64String(e){return this.sint64(BigInt(e))}bool(e){return this._push(Ts,1,e?1:0)}fixed32(e){return this._push(tn,4,e>>>0)}sfixed32(e){return this.fixed32(e)}fixed64(e){let r=ge.fromBigInt(e);return this._push(tn,4,r.lo)._push(tn,4,r.hi)}fixed64Number(e){let r=ge.fromNumber(e);return this._push(tn,4,r.lo)._push(tn,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(ll,4,e)}double(e){return this._push(hl,8,e)}bytes(e){let r=e.length>>>0;return r===0?this._push(Ts,1,0):this.uint32(r)._push(hy,r,e)}string(e){let r=yl(e);return r!==0?this.uint32(r)._push(bs,r,e):this._push(Ts,1,0)}fork(){return this.states=new As(this),this.head=this.tail=new _t(ks,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 _t(ks,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=ly(this.len),n=0;for(;e!=null;)e.fn(e.val,r,n),n+=e.len,e=e.next;return r}};function Ts(t,e,r){e[r]=t&255}function dy(t,e,r){for(;t>127;)e[r++]=t&127|128,t>>>=7;e[r]=t}var Is=class extends _t{next;constructor(e,r){super(dy,e,r),this.next=void 0}};function vo(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 tn(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 hy(t,e,r){e.set(t,r)}globalThis.Buffer!=null&&(rn.prototype.bytes=function(t){let e=t.length>>>0;return this.uint32(e),e>0&&this._push(py,e,t),this},rn.prototype.string=function(t){let e=globalThis.Buffer.byteLength(t);return this.uint32(e),e>0&&this._push(my,e,t),this});function py(t,e,r){e.set(t,r)}function my(t,e,r){t.length<40?bs(t,e,r):e.utf8Write!=null?e.utf8Write(t,r):e.set(Qn(t),r)}function Bs(){return new rn}function nn(t,e){let r=Bs();return e.encode(t,r,{lengthDelimited:!1}),r.finish()}var ir;(function(t){t[t.VARINT=0]="VARINT",t[t.BIT64=1]="BIT64",t[t.LENGTH_DELIMITED=2]="LENGTH_DELIMITED",t[t.START_GROUP=3]="START_GROUP",t[t.END_GROUP=4]="END_GROUP",t[t.BIT32=5]="BIT32"})(ir||(ir={}));function ko(t,e,r,n){return{name:t,type:e,encode:r,decode:n}}function Ss(t){function e(o){if(t[o.toString()]==null)throw new Error("Invalid enum value");return t[o]}let r=function(i,s){let a=e(i);s.int32(a)},n=function(i){let s=i.int32();return e(s)};return ko("enum",ir.VARINT,r,n)}function on(t,e){return ko("message",ir.LENGTH_DELIMITED,t,e)}var Ce;(function(t){let e;(function(o){o.Raw="Raw",o.Directory="Directory",o.File="File",o.Metadata="Metadata",o.Symlink="Symlink",o.HAMTShard="HAMTShard"})(e=t.DataType||(t.DataType={}));let r;(function(o){o[o.Raw=0]="Raw",o[o.Directory=1]="Directory",o[o.File=2]="File",o[o.Metadata=3]="Metadata",o[o.Symlink=4]="Symlink",o[o.HAMTShard=5]="HAMTShard"})(r||(r={})),(function(o){o.codec=()=>Ss(r)})(e=t.DataType||(t.DataType={}));let n;t.codec=()=>(n==null&&(n=on((o,i,s={})=>{if(s.lengthDelimited!==!1&&i.fork(),o.Type!=null&&(i.uint32(8),t.DataType.codec().encode(o.Type,i)),o.Data!=null&&(i.uint32(18),i.bytes(o.Data)),o.filesize!=null&&(i.uint32(24),i.uint64(o.filesize)),o.blocksizes!=null)for(let a of o.blocksizes)i.uint32(32),i.uint64(a);o.hashType!=null&&(i.uint32(40),i.uint64(o.hashType)),o.fanout!=null&&(i.uint32(48),i.uint64(o.fanout)),o.mode!=null&&(i.uint32(56),i.uint32(o.mode)),o.mtime!=null&&(i.uint32(66),To.codec().encode(o.mtime,i)),s.lengthDelimited!==!1&&i.ldelim()},(o,i)=>{let s={blocksizes:[]},a=i==null?o.len:o.pos+i;for(;o.pos<a;){let c=o.uint32();switch(c>>>3){case 1:s.Type=t.DataType.codec().decode(o);break;case 2:s.Data=o.bytes();break;case 3:s.filesize=o.uint64();break;case 4:s.blocksizes.push(o.uint64());break;case 5:s.hashType=o.uint64();break;case 6:s.fanout=o.uint64();break;case 7:s.mode=o.uint32();break;case 8:s.mtime=To.codec().decode(o,o.uint32());break;default:o.skipType(c&7);break}}return s})),n),t.encode=o=>nn(o,t.codec()),t.decode=o=>en(o,t.codec())})(Ce||(Ce={}));var To;(function(t){let e;t.codec=()=>(e==null&&(e=on((r,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),r.Seconds!=null&&(n.uint32(8),n.int64(r.Seconds)),r.FractionalNanoseconds!=null&&(n.uint32(21),n.fixed32(r.FractionalNanoseconds)),o.lengthDelimited!==!1&&n.ldelim()},(r,n)=>{let o={},i=n==null?r.len:r.pos+n;for(;r.pos<i;){let s=r.uint32();switch(s>>>3){case 1:o.Seconds=r.int64();break;case 2:o.FractionalNanoseconds=r.fixed32();break;default:r.skipType(s&7);break}}return o})),e),t.encode=r=>nn(r,t.codec()),t.decode=r=>en(r,t.codec())})(To||(To={}));var wl;(function(t){let e;t.codec=()=>(e==null&&(e=on((r,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),r.MimeType!=null&&(n.uint32(10),n.string(r.MimeType)),o.lengthDelimited!==!1&&n.ldelim()},(r,n)=>{let o={},i=n==null?r.len:r.pos+n;for(;r.pos<i;){let s=r.uint32();switch(s>>>3){case 1:o.MimeType=r.string();break;default:r.skipType(s&7);break}}return o})),e),t.encode=r=>nn(r,t.codec()),t.decode=r=>en(r,t.codec())})(wl||(wl={}));var bl={Raw:"raw",Directory:"directory",File:"file",Metadata:"metadata",Symlink:"symlink",HAMTShard:"hamt-sharded-directory"},yy=["directory","hamt-sharded-directory"],El=parseInt("0644",8),_l=parseInt("0755",8),Z=class t{static unmarshal(e){let r=Ce.decode(e),n=new t({type:bl[r.Type!=null?r.Type.toString():"File"],data:r.Data,blockSizes:r.blocksizes,mode:r.mode,mtime:r.mtime!=null?{secs:r.mtime.Seconds??0n,nsecs:r.mtime.FractionalNanoseconds}:void 0,fanout:r.fanout});return n._originalMode=r.mode??0,n}type;data;blockSizes;hashType;fanout;mtime;_mode;_originalMode;constructor(e={type:"file"}){let{type:r,data:n,blockSizes:o,hashType:i,fanout:s,mtime:a,mode:c}=e;if(r!=null&&!Object.values(bl).includes(r))throw new Zr("Type: "+r+" is not valid");this.type=r??"file",this.data=n,this.hashType=i,this.fanout=s,this.blockSizes=o??[],this._originalMode=0,this.mode=c,this.mtime=a}set mode(e){e==null?this._mode=this.isDirectory()?_l:El:this._mode=e&4095}get mode(){return this._mode}isDirectory(){return yy.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=Ce.DataType.Raw;break;case"directory":e=Ce.DataType.Directory;break;case"file":e=Ce.DataType.File;break;case"metadata":e=Ce.DataType.Metadata;break;case"symlink":e=Ce.DataType.Symlink;break;case"hamt-sharded-directory":e=Ce.DataType.HAMTShard;break;default:throw new Zr(`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===El&&!this.isDirectory()&&(n=void 0),n===_l&&this.isDirectory()&&(n=void 0));let o;return this.mtime!=null&&(o={Seconds:this.mtime.secs,FractionalNanoseconds:this.mtime.nsecs}),Ce.encode({Type:e,Data:r,filesize:this.isDirectory()?void 0:this.fileSize(),blocksizes:this.blockSizes,hashType:this.hashType,fanout:this.fanout,mode:n,mtime:o})}};var sn=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"},Ao=class extends Error{static name="NotDescendantError";name="NotDescendantError"},sr=class extends Error{static name="InvalidTraversalError";name="InvalidTraversalError"};function xy(t){return t.cid.code===85}function wy(t){return t.cid.code===112}function by(t){if(xy(t))return!0;if(wy(t)&&t.value.Data!=null){let e=Z.unmarshal(t.value.Data);return e.type==="file"||e.type==="raw"}else throw new sn("Encountered non raw/dag-pb CID in UnixFS DAG")}var Yr=class{options;constructor(e){this.options=e}async*export(e,r,n,o){if(e.code!==112&&e.code!==85)throw new sn("Target CID was not UnixFS - use the SubGraphExporter to export arbitrary graphs");let i=wt()({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 mt("Offset cannot be negative");if(a<0)throw new mt("Length cannot be negative");let f,l=new AbortController,p=Ou([l.signal,o?.signal]);l.signal;function v(k,w){if(f==null&&(f=by(w)),!f){let j=w.value.Links.find(ne=>ne.Hash.equals(k)),re=Z.unmarshal(w.value.Data??new Uint8Array);return re.type==="directory"?!c:re.type==="hamt-sharded-directory"&&c?j?.Name?.length===2:!0}let A=w.value.Links.findIndex(j=>j.Hash.equals(k)),I=Z.unmarshal(w.value.Data??new Uint8Array),R=s,z=R+a,P=Number([...I.blockSizes].slice(0,A).reduce((j,re)=>j+re,0n)),J=P+Number(I.blockSizes[A]);return R>=P&&R<J||z>=P&&z<J||R<=P&&z>=J}try{for await(let k of i.walk(e,{...o,includeChild:v,signal:p}))yield k.block}finally{l.abort(),p.clear()}}};function vl(t){return t!=null&&t?.asCID===t}var Ns=class{haystack;needle;options;walker;constructor(...e){if(vl(e[0]))vl(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 mt("needle must be specified");this.walker=this.options?.walker}async*traverse(e,r,n,o){let i=this.haystack??e,s,a={blockstore:r,getCodec:n};this.walker!=null?s=this.walker(a):this.options?.strategy==="breadth-first"?s=bt()(a):s=wt()(a);for await(let c of s.walk(i,o))if(c.block.cid.equals(this.needle)){for(let f of c.path){let l=await C(r.get(f,o));yield Pe({cid:f,bytes:l,codec:await n(f.code)})}return}throw new sr(`${this.needle} was not a child of ${i}`)}};var Us=class{path;constructor(e){this.path=e}async*traverse(e,r,n,o){if(!this.path.some(s=>s.equals(e)))throw new sr(`CIDPath traversal must include ${e}`);let i;for(let s of this.path){if(i!=null){let f=!1;for(let[,l]of i.links())if(l.equals(s)){f=!0;break}if(!f)throw new Ao(`${s} is not a child of ${i.cid}`)}let a=await C(r.get(s,o)),c=Pe({cid:s,bytes:a,codec:await n(s.code)});i=c,yield c}}};var ar=class t extends Error{static name="BadPathError";static code="ERR_BAD_PATH";name=t.name;code=t.code;constructor(e="Bad path"){super(e)}},xe=class t extends Error{static name="NotFoundError";static code="ERR_NOT_FOUND";name=t.name;code=t.code;constructor(e="Not found"){super(e)}},cr=class t extends Error{static name="NoResolverError";static code="ERR_NO_RESOLVER";name=t.name;code=t.code;constructor(e="No resolver"){super(e)}},F=class t extends Error{static name="NotUnixFSError";static code="ERR_NOT_UNIXFS";name=t.name;code=t.code;constructor(e="Not UnixFS"){super(e)}},Io=class t extends Error{static name="OverReadError";static code="ERR_OVER_READ";name=t.name;code=t.code;constructor(e="Over read"){super(e)}},Bo=class t extends Error{static name="UnderReadError";static code="ERR_UNDER_READ";name=t.name;code=t.code;constructor(e="Under read"){super(e)}},Je=class t extends Error{static name="InvalidParametersError";static code="ERR_INVALID_PARAMS";name=t.name;code=t.code;constructor(e="Invalid parameters"){super(e)}};function ur(t){return t==null?!1:B.asCID(t)===t}function fr(t,e){let r,n=0,o="";for(;n<e.length;){let i=e[n];if(n++,!Object.hasOwnProperty.call(t,i))throw new ar(`Object did not have key "${i}"`);if(o+=`/${i}`,r=t[i],t=r,ur(r))break}return{value:r,rest:e.slice(n),path:o.substring(1)}}async function*Cs(t,e,r,n){let o=await C(r.get(t,n)),i=dt(o),s=fr(i,e);yield{cid:ur(s.value)?s.value:t,name:s.path,rest:s.rest}}async function*kl(t,e,r,n){let o=await C(r.get(t,n)),i=xo(o),s=fr(i,e);yield{cid:ur(s.value)?s.value:t,name:s.path,rest:s.rest}}function ut(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 Ey(t,e){return t+e>>>0}function Te(t,e){let r=t.lo&65535,n=t.lo>>>16,o=e.lo&65535,i=e.lo>>>16,s=r*o,a=r*i,c=n*o,f=n*i,l=(s>>>16)+(a&65535)+(c&65535)>>>0,p=(l<<16|s&65535)>>>0,v=f+(a>>>16)+(c>>>16)+(l>>>16),k=Math.imul(t.lo,e.hi),w=Math.imul(t.hi,e.lo),A=v+k+w>>>0;return{lo:p,hi:A}}function vt(t,e){return Math.imul(t,e)>>>0}function lr(t,e){if(e===0)return t;if(e===32)return{lo:t.hi,hi:t.lo};if(e<32){let o=(t.lo<<e|t.hi>>>32-e)>>>0,i=(t.hi<<e|t.lo>>>32-e)>>>0;return{lo:o,hi:i}}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 M(t,e){return{lo:(t.lo^e.lo)>>>0,hi:(t.hi^e.hi)>>>0}}function Ds(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 L(t,e){return{lo:t>>>0,hi:e>>>0}}function Ls(t,e){return(t<<e|t>>>32-e)>>>0}function Tl(t,e){let r=e*8,n=t[r]|t[r+1]<<8|t[r+2]<<16|t[r+3]<<24,o=t[r+4]|t[r+5]<<8|t[r+6]<<16|t[r+7]<<24;return{lo:n>>>0,hi:o>>>0}}function _y(t,e){let r=e*4;return(t[r]|t[r+1]<<8|t[r+2]<<16|t[r+3]<<24)>>>0}function Al(t){return t=M(t,Ds(t,33)),t=Te(t,L(3981806797,4283543511)),t=M(t,Ds(t,33)),t=Te(t,L(444984403,3301882366)),t=M(t,Ds(t,33)),t}function vy(t){return t^=t>>>16,t=vt(t,2246822507),t^=t>>>13,t=vt(t,3266489909),t^=t>>>16,t}function $s(t,e=0){let r=L(e,0),n=L(e,0),o=t.length,i=Math.floor(o/16),s=L(289559509,2277735313),a=L(658871167,1291169091);for(let v=0;v<i;v++){let k=Tl(t,v*2),w=Tl(t,v*2+1);k=Te(k,s),k=lr(k,31),k=Te(k,a),r=M(r,k),r=lr(r,27),r=ut(r,n),r=ut(Te(r,L(5,0)),L(1390208809,0)),w=Te(w,a),w=lr(w,33),w=Te(w,s),n=M(n,w),n=lr(n,31),n=ut(n,r),n=ut(Te(n,L(5,0)),L(944331445,0))}let c=L(0,0),f=L(0,0),l=t.slice(i*16);switch(l.length){case 15:f=M(f,L(0,l[14]<<16));case 14:f=M(f,L(0,l[13]<<8));case 13:f=M(f,L(0,l[12]));case 12:f=M(f,L(l[11]<<24,0));case 11:f=M(f,L(l[10]<<16,0));case 10:f=M(f,L(l[9]<<8,0));case 9:f=M(f,L(l[8],0)),f=Te(f,a),f=lr(f,33),f=Te(f,s),n=M(n,f);case 8:c=M(c,L(0,l[7]<<24));case 7:c=M(c,L(0,l[6]<<16));case 6:c=M(c,L(0,l[5]<<8));case 5:c=M(c,L(0,l[4]));case 4:c=M(c,L(l[3]<<24,0));case 3:c=M(c,L(l[2]<<16,0));case 2:c=M(c,L(l[1]<<8,0));case 1:c=M(c,L(l[0],0)),c=Te(c,s),c=lr(c,31),c=Te(c,a),r=M(r,c)}let p=L(o,0);return r=M(r,p),n=M(n,p),r=ut(r,n),n=ut(n,r),r=Al(r),n=Al(n),r=ut(r,n),n=ut(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 Il(t,e=0){let r=e>>>0,n=t.length,o=Math.floor(n/4),i=3432918353,s=461845907;for(let f=0;f<o;f++){let l=_y(t,f);l=vt(l,i),l=Ls(l,15),l=vt(l,s),r^=l,r=Ls(r,13),r=Ey(vt(r,5),3864292196)}let a=t.slice(o*4),c=0;switch(a.length){case 3:c^=a[2]<<16;case 2:c^=a[1]<<8;case 1:c^=a[0],c=vt(c,i),c=Ls(c,15),c=vt(c,s),r^=c}return r^=n,r=vy(r),r}function Ty(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 Uk=yt({name:"murmur3-32",code:35,encode:t=>Ty(Il(t))}),Bl=yt({name:"murmur3-128",code:34,encode:t=>$s(t)}),Ck=yt({name:"murmur3-x64-64",code:34,encode:t=>$s(t).subarray(0,8)});var Cl=Tt(Ul(),1);var kt=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 Cl.default,this.key=null}async put(e,r){let n=await this._findNewBucketAndPos(e);n.bucket._putAt(n,e,r)}async get(e){let r=await this._findChild(e);if(r!=null)return r.value}async del(e){let r=await this._findPlace(e),n=r.bucket._at(r.pos);n!=null&&n.key===e&&r.bucket._delAt(r.pos)}leafCount(){return this._children.compactArray().reduce((r,n)=>n instanceof t?r+n.leafCount():r+1,0)}childrenCount(){return this._children.length}onlyChild(){return this._children.get(0)}*eachLeafSeries(){let e=this._children.compactArray();for(let r of e)r instanceof t?yield*r.eachLeafSeries():yield r}serialize(e,r){let n=[];return r(this._children.reduce((o,i,s)=>(i!=null&&(i instanceof t?o.push(i.serialize(e,r)):o.push(e(i,s))),o),n))}async asyncTransform(e,r){return Dl(this,e,r)}toJSON(){return this.serialize(Ny,Uy)}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"?Qn(e):e),n=await r.take(this._options.bits),o=this._children.get(n);return o instanceof t?o._findPlace(r):{bucket:this,pos:n,hash:r,existingChild:o}}async _findNewBucketAndPos(e){let r=await this._findPlace(e);if(r.existingChild!=null&&r.existingChild.key!==e){let n=new t(this._options,r.bucket,r.pos);r.bucket._putObjectAt(r.pos,n);let o=await n._findPlace(r.existingChild.hash);return o.bucket._putAt(o,r.existingChild.key,r.existingChild.value),n._findNewBucketAndPos(r.hash)}return r}_putAt(e,r,n){this._putObjectAt(e.pos,{key:r,value:n,hash:e.hash})}_putObjectAt(e,r){this._children.get(e)==null&&this._popCount++,this._children.set(e,r)}_delAt(e){if(e===-1)throw new Error("Invalid position");this._children.get(e)!=null&&this._popCount--,this._children.unset(e),this._level()}_level(){if(this._parent!=null&&this._popCount<=1)if(this._popCount===1){let e=this._children.find(Sy);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 Sy(t){return!!t}function Ny(t,e){return t.key}function Uy(t){return t}async function Dl(t,e,r){let n=[];for(let o of t._children.compactArray())if(o instanceof kt)await Dl(o,e,r);else{let i=await e(o);n.push({bitField:t._children.bitField(),children:i})}return r(n)}var Cy=[255,254,252,248,240,224,192,128],Dy=[1,3,7,15,31,63,127,255],So=class{_value;_currentBytePos;_currentBitPos;constructor(e){this._value=e,this._currentBytePos=e.length-1,this._currentBitPos=7}availableBits(){return this._currentBitPos+1+this._currentBytePos*8}totalBits(){return this._value.length*8}take(e){let r=e,n=0;for(;r>0&&this._haveBits();){let o=this._value[this._currentBytePos],i=this._currentBitPos+1,s=Math.min(i,r),a=Ly(o,i-s,s);n=(n<<s)+a,r-=s,this._currentBitPos-=s,this._currentBitPos<0&&(this._currentBitPos=7,this._currentBytePos--)}return n}untake(e){for(this._currentBitPos+=e;this._currentBitPos>7;)this._currentBitPos-=8,this._currentBytePos+=1}_haveBits(){return this._currentBytePos>=0}};function Ly(t,e,r){let n=$y(e,r);return(t&n)>>>e}function $y(t,e){return Cy[t]&Dy[Math.min(e+t-1,7)]}function Ll(t){function e(r){return r instanceof No?r:new No(r,t)}return e}var No=class{_value;_hashFn;_depth;_availableBits;_currentBufferIndex;_buffers;constructor(e,r){if(!(e instanceof Uint8Array))throw new Error("can only hash Uint8Arrays");this._value=e,this._hashFn=r,this._depth=-1,this._availableBits=0,this._currentBufferIndex=0,this._buffers=[]}async take(e){let r=e;for(;this._availableBits<r;)await this._produceMoreBits();let n=0;for(;r>0;){let o=this._buffers[this._currentBufferIndex],i=Math.min(o.availableBits(),r),s=o.take(i);n=(n<<i)+s,r-=i,this._availableBits-=i,o.availableBits()===0&&this._currentBufferIndex++}return n}untake(e){let r=e;for(;r>0;){let n=this._buffers[this._currentBufferIndex],o=Math.min(n.totalBits()-n.availableBits(),r);n.untake(o),r-=o,this._availableBits+=o,this._currentBufferIndex>0&&n.totalBits()===n.availableBits()&&(this._depth--,this._currentBufferIndex--)}}async _produceMoreBits(){this._depth++;let e=this._depth>0?Or([this._value,Uint8Array.from([this._depth])]):this._value,r=await this._hashFn(e),n=new So(r);this._buffers.push(n),this._availableBits+=n.availableBits()}};function $l(t){if(t==null||t.hashFn==null)throw new Error("please define an options.hashFn");let e={bits:t.bits??8,hash:Ll(t.hashFn)};return new kt(e)}var Ry=async function(t){return(await Bl.encode(t)).slice(0,8).reverse()},Fy=async(t,e,r)=>{let n=(e.tableSize()-1).toString(16).length;await Promise.all(t.map(async o=>{if(o.Name==null)throw new Error("Unexpected Link without a Name");if(o.Name.length===n){let i=parseInt(o.Name,16);e._putObjectAt(i,new kt({hash:r._options.hash,bits:r._options.bits},e,i));return}await r.put(o.Name.substring(2),!0)}))},Rl=(t,e)=>t.toString(16).toUpperCase().padStart(e,"0").substring(0,e),My=t=>{let e=t.bucket,r=[];for(;e._parent!=null;)r.push(e),e=e._parent;return r.push(e),r.reverse()};async function*Rs(t,e,r,n,o,i){if(o==null){if(t.Data==null)throw new F("No data in PBNode");let v;try{v=Z.unmarshal(t.Data)}catch(w){throw new F(w.message)}if(v.type!=="hamt-sharded-directory")throw new F("Not a HAMT");if(v.fanout==null)throw new F("Missing fanout");let k=$l({hashFn:Ry,bits:Math.log2(Number(v.fanout))});o={rootBucket:k,hamtDepth:1,lastBucket:k}}let s=(o.lastBucket.tableSize()-1).toString(16).length;await Fy(t.Links,o.lastBucket,o.rootBucket);let a=await o.rootBucket._findNewBucketAndPos(e),c=Rl(a.pos,s),f=My(a);f.length>o.hamtDepth&&(o.lastBucket=f[o.hamtDepth],c=Rl(o.lastBucket._posAtParent,s));let l=t.Links.find(v=>{if(v.Name==null)return!1;let k=v.Name.substring(0,s),w=v.Name.substring(s);return!(k!==c||w!==""&&w!==e)});if(l==null)return;if(l.Name!=null&&l.Name.substring(s)===e){yield{cid:l.Hash,name:l.Name.substring(s),rest:r};return}o.hamtDepth++;let p=await C(n.get(l.Hash,i));t=ze(p),i?.yieldSubShards===!0&&(yield{cid:l.Hash,name:l.Name??"",rest:[e,...r]}),yield*Rs(t,e,r,n,o,i)}async function*Fl(t,e,r,n){let o=await C(r.get(t,n)),i;try{i=ze(o)}catch(a){throw new F(a.message)}if(i.Data==null)throw new F("no data in PBNode");let s;try{s=Z.unmarshal(i.Data)}catch(a){throw new F(a.message)}if(s.type==="directory"||s.type==="hamt-sharded-directory"&&n?.translateHAMTPath===!1){let a=i.Links.find(c=>c.Name===e[0]);if(a==null)throw new xe(`No link "${e[0]}" found under ${t}`);yield{cid:a.Hash,name:e[0],rest:e.slice(1)}}else if(s.type==="hamt-sharded-directory"){let a=!1;for await(let c of Rs(i,e[0],e.slice(1),r,void 0,n))c.name===e[0]&&(a=!0),yield c;if(!a)throw new xe(`No link "${e[0]}" found under ${t}`)}}async function*Ml(t,e,r,n){if(e.length!==0)throw new ar(`Cannot load path /${e.join("/")} from identity block`)}async function*Pl(t,e,r,n){let o=await C(r.get(t,n)),i=Wn(o),s=fr(i,e);yield{cid:t,name:s.path,rest:s.rest}}async function*Ol(t,e,r,n){if(e.length!==0)throw new xe(`Cannot load path /${e.join("/")} from raw block`)}var Oy={[or]:Fl,[Gt]:Ol,[An]:Cs,81:Cs,[go]:kl,[Pr.code]:Ml,[Gn]:Pl};async function*Uo(t,e,r={}){for(t=t.toString(),t.startsWith("/ipfs/")&&(t=t.substring(6));t.endsWith("/");)t=t.substring(0,t.length-1);let[n,...o]=t.split(/(?<!\\)\//g).filter(Boolean),i=B.parse(n),s=[i],a=`${i}`;for(yield{cid:i,name:a,path:a,roots:s,remainder:o};o.length>0;){let c=Oy[i.code];if(c==null)throw new cr(`No resolver for code ${i.code}`);let f=!1;for await(let l of c(i,o,e,r)){if(i=l.cid,f=!s[s.length-1].equals(i),o=l.rest,!f)break;s=[...s,l.cid],a=`${a}/${l.name}`,yield{cid:l.cid,name:l.name,path:a,roots:s,remainder:l.rest}}if(!f)break}if(r?.signal?.throwIfAborted(),o.length!==0)throw new xe(`Could not resolve path /${o.join("/")} under ${t}`)}function zy(t){return t[Symbol.asyncIterator]!=null}function jy(t){if(zy(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 zl=jy;async function Fs(t,e,r,n,o){let i=await C(n.get(t,o)),s=dt(i);return{type:"object",cid:t,name:e,path:r,object:s,node:i}}async function jl(t,e,r,n,o){let i=await C(n.get(t,o)),s=xo(i);return{type:"object",cid:t,name:e,path:r,object:s,node:i}}function an(t,e,r,n){let o=BigInt(t.length),i=BigInt(e+o);return r>=i||n<e?new Uint8Array(0):(n>=e&&n<i&&(t=t.subarray(0,Number(n-e))),r>=e&&r<i&&(t=t.subarray(Number(r-e))),t)}var Co=(t,e=0,r=t)=>{let n=BigInt(t),o=BigInt(e??0),i=BigInt(r);if(i!==n&&(i=o+i),i>n&&(i=n),o<0n)throw new Je("Offset must be greater than or equal to 0");if(o>n)throw new Je("Offset must be less than the file size");if(i<0n)throw new Je("Length must be greater than or equal to 0");if(i>n)throw new Je("Length must be less than the file size");return{start:o,end:i}};function Do(t,e){async function*r(n={}){let{start:o,end:i}=Co(t.length,n.offset,n.length),s=an(t,0n,o,i);n.onProgress?.(new Q(e,{bytesRead:BigInt(s.byteLength),totalBytes:i-o,fileSize:BigInt(t.byteLength)})),yield s}return r}async function Hl(t,e,r,n,o){let i=Mt(t.multihash.bytes);return{type:"identity",cid:t,name:e,path:r,content:Do(i.digest,"unixfs:exporter:progress:identity"),size:BigInt(i.bytes.length),node:i.bytes}}async function Vl(t,e,r,n,o){let i=await C(n.get(t,o)),s=Wn(i);return{type:"object",cid:t,name:e,path:r,object:s,node:i}}async function ql(t,e,r,n,o){let i=await C(n.get(t,o));return{type:"raw",cid:t,name:e,path:r,content:Do(i,"unixfs:exporter:progress:raw"),size:BigInt(i.length),node:i}}function Gl(t,e,r,n){async function*o(i={}){let s=i.offset??0,a=i.length??e.Links.length,c=e.Links.slice(s,a);i.onProgress?.(new Q("unixfs:exporter:walk:directory",{cid:t})),yield*c.map(f=>({cid:f.Hash,name:f.Name??"",path:`${n}/${f.Name??""}`}))}return o}var Lo=globalThis.CustomEvent??Event;async function*cn(t,e={}){let r=e.concurrency??1/0;r<1&&(r=1/0);let n=e.ordered??!1,o=new EventTarget,i=[],s=K(),a=K(),c=!1,f,l=!1;o.addEventListener("task-complete",()=>{a.resolve()}),Promise.resolve().then(async()=>{try{for await(let w of t){if(i.length===r&&(s=K(),await s.promise),l)break;let A={done:!1};i.push(A),w().then(I=>{A.done=!0,A.ok=!0,A.value=I,o.dispatchEvent(new Lo("task-complete"))},I=>{A.done=!0,A.err=I,o.dispatchEvent(new Lo("task-complete"))})}c=!0,o.dispatchEvent(new Lo("task-complete"))}catch(w){f=w,o.dispatchEvent(new Lo("task-complete"))}});function p(){return n?i[0]?.done:!!i.find(w=>w.done)}function*v(){for(;i.length>0&&i[0].done;){let w=i[0];if(i.shift(),w.ok)yield w.value;else throw l=!0,s.resolve(),w.err;s.resolve()}}function*k(){for(;p();)for(let w=0;w<i.length;w++)if(i[w].done){let A=i[w];if(i.splice(w,1),w--,A.ok)yield A.value;else throw l=!0,s.resolve(),A.err;s.resolve()}}for(;;){if(p()||(a=K(),await a.promise),f!=null||(n?yield*v():yield*k(),f!=null))throw f;if(c&&i.length===0)break}}async function Wl(t,e,r,n,o,i,s){if(e instanceof Uint8Array){let f=an(e,n,o,i);r.push(f);return}if(e.Data==null)throw new F("no data in PBNode");let a;try{a=Z.unmarshal(e.Data)}catch(f){throw new F(f.message)}if(a.data!=null){let f=a.data,l=an(f,n,o,i);r.push(l),n+=BigInt(l.byteLength)}let c=[];if(e.Links.length!==a.blockSizes.length)throw new F("Inconsistent block sizes and dag links");for(let f=0;f<e.Links.length;f++){let l=e.Links[f],p=n,v=p+a.blockSizes[f];if((o>=p&&o<v||i>=p&&i<=v||o<p&&i>v)&&c.push({link:l,blockStart:n}),n=v,n>i)break}await to(c,f=>jt(f,l=>async()=>{let p=await C(t.get(l.link.Hash,s));return{...l,block:p}}),f=>cn(f,{ordered:!0,concurrency:s.blockReadConcurrency}),async f=>{for await(let{link:l,block:p,blockStart:v}of f){let k;switch(l.Hash.code){case or:k=ze(p);break;case Gt:k=p;break;default:r.end(new F(`Unsupported codec: ${l.Hash.code}`));return}let w=new Fr({concurrency:1});w.on("error",A=>{r.end(A)}),w.add(async()=>{s.onProgress?.(new Q("unixfs:exporter:walk:file",{cid:l.Hash})),await Wl(t,k,r,v,o,i,s)}),await w.onIdle()}}),n>=i&&r.end()}function Ms(t,e,r,n,o){async function*i(s={}){let a=r.fileSize();if(a===void 0)throw new Error("File was a directory");let{start:c,end:f}=Co(a,s.offset,s.length);if(f===0n)return;let l=0n,p=f-c,v=Jt();s.onProgress?.(new Q("unixfs:exporter:walk:file",{cid:t})),Wl(o,e,v,0n,c,f,s).catch(k=>{v.end(k)});for await(let k of v)if(k!=null){if(l+=BigInt(k.byteLength),l>p)throw v.end(),new Io("Read too many bytes - the file size reported by the UnixFS data in the root node may be incorrect");l===p&&v.end(),s.onProgress?.(new Q("unixfs:exporter:progress:unixfs:file",{bytesRead:l,totalBytes:p,fileSize:a})),yield k}if(l<p)throw new Bo("Traversed entire DAG but did not read enough bytes")}return i}async function*Jl(t,e,r,n){let o=t.Links;if(t.Data==null)throw new F("no data in PBNode");let i;try{i=Z.unmarshal(t.Data)}catch(c){throw new F(c.message)}if(i.fanout==null)throw new F("missing fanout");let s=(i.fanout-1n).toString(16).length,a=to(o,c=>jt(c,f=>async()=>{let l=f.Name!=null?f.Name.substring(s):null;if(l!=null&&l!=="")return{entries:[{cid:f.Hash,name:l,path:`${e}/${l}`}]};{let p=await C(r.get(f.Hash,n));return t=ze(p),n.onProgress?.(new Q("unixfs:exporter:walk:hamt-sharded-directory",{cid:f.Hash})),{entries:Jl(t,e,r,n)}}}),c=>cn(c,{ordered:!0,concurrency:n.blockReadConcurrency}));for await(let{entries:c}of a)yield*c}function Ql(t,e,r,n,o){function i(s={}){return s.onProgress?.(new Q("unixfs:exporter:walk:hamt-sharded-directory",{cid:t})),Jl(e,n,o,s)}return i}var Hy={raw:Ms,file:Ms,directory:Gl,"hamt-sharded-directory":Ql,metadata:(t,e,r,n)=>()=>[],symlink:(t,e,r,n)=>()=>[]};async function Xl(t,e,r,n,o){let i=await C(n.get(t,o)),s;try{s=ze(i)}catch(f){throw new F(f.message)}if(s.Data==null)throw new F("no data in PBNode");let a;try{a=Z.unmarshal(s.Data)}catch(f){throw new F(f.message)}let c=Hy[a.type](t,s,a,r,n);if(c==null)throw new xe("could not find content exporter");return a.isDirectory()?{type:"directory",cid:t,name:e,path:r,entries:c,unixfs:a,node:s}:{type:"file",cid:t,name:e,path:r,content:c,unixfs:a,node:s,size:a.fileSize()}}var Vy={[or]:Xl,[Gt]:ql,[An]:Fs,81:Fs,[go]:jl,[Pr.code]:Hl,[Gn]:Vl};async function Kl(t,e,r={}){let n,o;if(t instanceof String||typeof t=="string"){let s=await zl(Uo(t,e,r));if(s==null)throw new xe(`Could not walk path to ${t}`);n=s.cid,o=s.name,t=s.path}else if(B.asCID(t)===t||t instanceof B)n=t,o=t=n.toString();else throw new Je("Path must be string or CID");let i=Vy[n.code];if(i==null)throw new cr(`No resolver for code ${n.code}`);return i(n,o,t,e,r)}var Ps=class{root;path;constructor(...e){let r=e[0],n=e[1];if(typeof r=="string")n=r,r=void 0;else if(e.length<2)throw new Error("path or CID and path must be specified");n.startsWith("/")||(n=`/${n}`),this.root=r,this.path=n}async*traverse(e,r,n,o){for await(let i of Uo(`${this.root??e}${this.path}`,r,o)){let s=await Kl(i.cid,r,o);yield Pe({cid:s.cid,bytes:s.node instanceof Uint8Array?s.node:cl(s.node),codec:await n(i.cid.code)})}}};function qy(t){return new Eo(t)}return nd(Gy);})();
3
3
  return HeliaCar}));
4
4
  //# sourceMappingURL=index.min.js.map