@helia/car 4.1.3 → 4.2.0-34d3ecd7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +4 -4
- package/dist/src/car.d.ts.map +1 -1
- package/dist/src/car.js +4 -3
- package/dist/src/car.js.map +1 -1
- package/dist/src/index.d.ts +3 -3
- package/dist/src/index.d.ts.map +1 -1
- package/package.json +24 -31
- package/src/car.ts +4 -3
- package/src/index.ts +3 -3
- package/dist/typedoc-urls.json +0 -20
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 mi=Object.create;var et=Object.defineProperty;var yi=Object.getOwnPropertyDescriptor;var gi=Object.getOwnPropertyNames;var xi=Object.getPrototypeOf,wi=Object.prototype.hasOwnProperty;var ve=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),N=(t,e)=>{for(var r in e)et(t,r,{get:e[r],enumerable:!0})},Kr=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of gi(e))!wi.call(t,o)&&o!==r&&et(t,o,{get:()=>e[o],enumerable:!(n=yi(e,o))||n.enumerable});return t};var tt=(t,e,r)=>(r=t!=null?mi(xi(t)):{},Kr(e||!t||!t.__esModule?et(r,"default",{value:t,enumerable:!0}):r,t)),bi=t=>Kr(et({},"__esModule",{value:!0}),t);var go=ve((Tu,yo)=>{yo.exports=Zt;var mo=128,$s=127,Hs=~$s,Vs=Math.pow(2,31);function Zt(t,e,r){if(Number.MAX_SAFE_INTEGER&&t>Number.MAX_SAFE_INTEGER)throw Zt.bytes=0,new RangeError("Could not encode varint");e=e||[],r=r||0;for(var n=r;t>=Vs;)e[r++]=t&255|mo,t/=128;for(;t&Hs;)e[r++]=t&255|mo,t>>>=7;return e[r]=t|0,Zt.bytes=r-n+1,e}});var bo=ve((ku,wo)=>{wo.exports=er;var Gs=128,xo=127;function er(t,n){var r=0,n=n||0,o=0,i=n,s,c=t.length;do{if(i>=c||o>49)throw er.bytes=0,new RangeError("Could not decode varint");s=t[i++],r+=o<28?(s&xo)<<o:(s&xo)*Math.pow(2,o),o+=7}while(s>=Gs);return er.bytes=i-n,r}});var To=ve((Au,Eo)=>{var qs=Math.pow(2,7),Xs=Math.pow(2,14),Ws=Math.pow(2,21),Js=Math.pow(2,28),Ks=Math.pow(2,35),js=Math.pow(2,42),Qs=Math.pow(2,49),Ys=Math.pow(2,56),Zs=Math.pow(2,63);Eo.exports=function(t){return t<qs?1:t<Xs?2:t<Ws?3:t<Js?4:t<Ks?5:t<js?6:t<Qs?7:t<Ys?8:t<Zs?9:10}});var yt=ve((vu,ko)=>{ko.exports={encode:go(),decode:bo(),encodingLength:To()}});var Lo=ve((Of,yr)=>{"use strict";var ya=Object.prototype.hasOwnProperty,_="~";function Pe(){}Object.create&&(Pe.prototype=Object.create(null),new Pe().__proto__||(_=!1));function ga(t,e,r){this.fn=t,this.context=e,this.once=r||!1}function zo(t,e,r,n,o){if(typeof r!="function")throw new TypeError("The listener must be a function");var i=new ga(r,n||t,o),s=_?_+e:e;return t._events[s]?t._events[s].fn?t._events[s]=[t._events[s],i]:t._events[s].push(i):(t._events[s]=i,t._eventsCount++),t}function bt(t,e){--t._eventsCount===0?t._events=new Pe:delete t._events[e]}function A(){this._events=new Pe,this._eventsCount=0}A.prototype.eventNames=function(){var e=[],r,n;if(this._eventsCount===0)return e;for(n in r=this._events)ya.call(r,n)&&e.push(_?n.slice(1):n);return Object.getOwnPropertySymbols?e.concat(Object.getOwnPropertySymbols(r)):e};A.prototype.listeners=function(e){var r=_?_+e:e,n=this._events[r];if(!n)return[];if(n.fn)return[n.fn];for(var o=0,i=n.length,s=new Array(i);o<i;o++)s[o]=n[o].fn;return s};A.prototype.listenerCount=function(e){var r=_?_+e:e,n=this._events[r];return n?n.fn?1:n.length:0};A.prototype.emit=function(e,r,n,o,i,s){var c=_?_+e:e;if(!this._events[c])return!1;var u=this._events[c],l=arguments.length,m,h;if(u.fn){switch(u.once&&this.removeListener(e,u.fn,void 0,!0),l){case 1:return u.fn.call(u.context),!0;case 2:return u.fn.call(u.context,r),!0;case 3:return u.fn.call(u.context,r,n),!0;case 4:return u.fn.call(u.context,r,n,o),!0;case 5:return u.fn.call(u.context,r,n,o,i),!0;case 6:return u.fn.call(u.context,r,n,o,i,s),!0}for(h=1,m=new Array(l-1);h<l;h++)m[h-1]=arguments[h];u.fn.apply(u.context,m)}else{var I=u.length,b;for(h=0;h<I;h++)switch(u[h].once&&this.removeListener(e,u[h].fn,void 0,!0),l){case 1:u[h].fn.call(u[h].context);break;case 2:u[h].fn.call(u[h].context,r);break;case 3:u[h].fn.call(u[h].context,r,n);break;case 4:u[h].fn.call(u[h].context,r,n,o);break;default:if(!m)for(b=1,m=new Array(l-1);b<l;b++)m[b-1]=arguments[b];u[h].fn.apply(u[h].context,m)}}return!0};A.prototype.on=function(e,r,n){return zo(this,e,r,n,!1)};A.prototype.once=function(e,r,n){return zo(this,e,r,n,!0)};A.prototype.removeListener=function(e,r,n,o){var i=_?_+e:e;if(!this._events[i])return this;if(!r)return bt(this,i),this;var s=this._events[i];if(s.fn)s.fn===r&&(!o||s.once)&&(!n||s.context===n)&&bt(this,i);else{for(var c=0,u=[],l=s.length;c<l;c++)(s[c].fn!==r||o&&!s[c].once||n&&s[c].context!==n)&&u.push(s[c]);u.length?this._events[i]=u.length===1?u[0]:u:bt(this,i)}return this};A.prototype.removeAllListeners=function(e){var r;return e?(r=_?_+e:e,this._events[r]&&bt(this,r)):(this._events=new Pe,this._eventsCount=0),this};A.prototype.off=A.prototype.removeListener;A.prototype.addListener=A.prototype.on;A.prefixed=_;A.EventEmitter=A;typeof yr<"u"&&(yr.exports=A)});var nc={};N(nc,{BlockExporter:()=>Er,CIDPath:()=>kr,GraphSearch:()=>qe,SubgraphExporter:()=>Ge,UnixFSExporter:()=>Tr,UnixFSPath:()=>Jr,car:()=>rc});var Ei=["string","number","bigint","symbol"],Ti=["Function","Generator","AsyncGenerator","GeneratorFunction","AsyncGeneratorFunction","AsyncFunction","Observable","Array","Buffer","Object","RegExp","Date","Error","Map","Set","WeakMap","WeakSet","ArrayBuffer","SharedArrayBuffer","DataView","Promise","URL","HTMLElement","Int8Array","Uint8Array","Uint8ClampedArray","Int16Array","Uint16Array","Int32Array","Uint32Array","Float32Array","Float64Array","BigInt64Array","BigUint64Array"];function jr(t){if(t===null)return"null";if(t===void 0)return"undefined";if(t===!0||t===!1)return"boolean";let e=typeof t;if(Ei.includes(e))return e;if(e==="function")return"Function";if(Array.isArray(t))return"Array";if(ki(t))return"Buffer";let r=Ai(t);return r||"Object"}function ki(t){return t&&t.constructor&&t.constructor.isBuffer&&t.constructor.isBuffer.call(null,t)}function Ai(t){let e=Object.prototype.toString.call(t).slice(8,-1);if(Ti.includes(e))return e}var a=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}};a.uint=new a(0,"uint",!0);a.negint=new a(1,"negint",!0);a.bytes=new a(2,"bytes",!0);a.string=new a(3,"string",!0);a.array=new a(4,"array",!1);a.map=new a(5,"map",!1);a.tag=new a(6,"tag",!1);a.float=new a(7,"float",!0);a.false=new a(7,"false",!0);a.true=new a(7,"true",!0);a.null=new a(7,"null",!0);a.undefined=new a(7,"undefined",!0);a.break=new a(7,"break",!0);var d=class{constructor(e,r,n){this.type=e,this.value=r,this.encodedLength=n,this.encodedBytes=void 0,this.byteValue=void 0}toString(){return`Token[${this.type}].${this.value}`}};var he=globalThis.process&&!globalThis.process.browser&&globalThis.Buffer&&typeof globalThis.Buffer.isBuffer=="function",vi=new TextDecoder,Ii=new TextEncoder;function rt(t){return he&&globalThis.Buffer.isBuffer(t)}function Nt(t){return t instanceof Uint8Array?rt(t)?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):t:Uint8Array.from(t)}var en=he?(t,e,r)=>r-e>64?globalThis.Buffer.from(t.subarray(e,r)).toString("utf8"):Yr(t,e,r):(t,e,r)=>r-e>64?vi.decode(t.subarray(e,r)):Yr(t,e,r),tn=he?t=>t.length>64?globalThis.Buffer.from(t):Qr(t):t=>t.length>64?Ii.encode(t):Qr(t),W=t=>Uint8Array.from(t),pe=he?(t,e,r)=>rt(t)?new Uint8Array(t.subarray(e,r)):t.slice(e,r):(t,e,r)=>t.slice(e,r),rn=he?(t,e)=>(t=t.map(r=>r instanceof Uint8Array?r:globalThis.Buffer.from(r)),Nt(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},nn=he?t=>globalThis.Buffer.allocUnsafe(t):t=>new Uint8Array(t);function on(t,e){if(rt(t)&&rt(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 Qr(t){let e=[],r=0;for(let n=0;n<t.length;n++){let o=t.charCodeAt(n);o<128?e[r++]=o:o<2048?(e[r++]=o>>6|192,e[r++]=o&63|128):(o&64512)===55296&&n+1<t.length&&(t.charCodeAt(n+1)&64512)===56320?(o=65536+((o&1023)<<10)+(t.charCodeAt(++n)&1023),e[r++]=o>>18|240,e[r++]=o>>12&63|128,e[r++]=o>>6&63|128,e[r++]=o&63|128):(e[r++]=o>>12|224,e[r++]=o>>6&63|128,e[r++]=o&63|128)}return e}function Yr(t,e,r){let n=[];for(;e<r;){let o=t[e],i=null,s=o>239?4:o>223?3:o>191?2:1;if(e+s<=r){let c,u,l,m;switch(s){case 1:o<128&&(i=o);break;case 2:c=t[e+1],(c&192)===128&&(m=(o&31)<<6|c&63,m>127&&(i=m));break;case 3:c=t[e+1],u=t[e+2],(c&192)===128&&(u&192)===128&&(m=(o&15)<<12|(c&63)<<6|u&63,m>2047&&(m<55296||m>57343)&&(i=m));break;case 4:c=t[e+1],u=t[e+2],l=t[e+3],(c&192)===128&&(u&192)===128&&(l&192)===128&&(m=(o&15)<<18|(c&63)<<12|(u&63)<<6|l&63,m>65535&&m<1114112&&(i=m))}}i===null?(i=65533,s=1):i>65535&&(i-=65536,n.push(i>>>10&1023|55296),i=56320|i&1023),n.push(i),e+=s}return _i(n)}var Zr=4096;function _i(t){let e=t.length;if(e<=Zr)return String.fromCharCode.apply(String,t);let r="",n=0;for(;n<e;)r+=String.fromCharCode.apply(String,t.slice(n,n+=Zr));return r}var Si=256,Ie=class{constructor(e=Si){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=nn(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=pe(n,0,this.cursor)}else r=rn(this.chunks,this.cursor);return e&&this.reset(),r}};var p="CBOR decode error:",Bt="CBOR encode error:",_e=[];_e[23]=1;_e[24]=2;_e[25]=3;_e[26]=5;_e[27]=9;function j(t,e,r){if(t.length-e<r)throw new Error(`${p} not enough data for type`)}var E=[24,256,65536,4294967296,BigInt("18446744073709551616")];function B(t,e,r){j(t,e,1);let n=t[e];if(r.strict===!0&&n<E[0])throw new Error(`${p} integer encoded in more bytes than necessary (strict decode)`);return n}function C(t,e,r){j(t,e,2);let n=t[e]<<8|t[e+1];if(r.strict===!0&&n<E[1])throw new Error(`${p} integer encoded in more bytes than necessary (strict decode)`);return n}function D(t,e,r){j(t,e,4);let n=t[e]*16777216+(t[e+1]<<16)+(t[e+2]<<8)+t[e+3];if(r.strict===!0&&n<E[2])throw new Error(`${p} integer encoded in more bytes than necessary (strict decode)`);return n}function U(t,e,r){j(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<E[3])throw new Error(`${p} 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(`${p} integers outside of the safe integer range are not supported`)}function sn(t,e,r,n){return new d(a.uint,B(t,e+1,n),2)}function an(t,e,r,n){return new d(a.uint,C(t,e+1,n),3)}function cn(t,e,r,n){return new d(a.uint,D(t,e+1,n),5)}function un(t,e,r,n){return new d(a.uint,U(t,e+1,n),9)}function F(t,e){return T(t,0,e.value)}function T(t,e,r){if(r<E[0]){let n=Number(r);t.push([e|n])}else if(r<E[1]){let n=Number(r);t.push([e|24,n])}else if(r<E[2]){let n=Number(r);t.push([e|25,n>>>8,n&255])}else if(r<E[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<E[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(`${p} encountered BigInt larger than allowable range`)}}F.encodedSize=function(e){return T.encodedSize(e.value)};T.encodedSize=function(e){return e<E[0]?1:e<E[1]?2:e<E[2]?3:e<E[3]?5:9};F.compareTokens=function(e,r){return e.value<r.value?-1:e.value>r.value?1:0};function fn(t,e,r,n){return new d(a.negint,-1-B(t,e+1,n),2)}function dn(t,e,r,n){return new d(a.negint,-1-C(t,e+1,n),3)}function ln(t,e,r,n){return new d(a.negint,-1-D(t,e+1,n),5)}var Ct=BigInt(-1),hn=BigInt(1);function pn(t,e,r,n){let o=U(t,e+1,n);if(typeof o!="bigint"){let i=-1-o;if(i>=Number.MIN_SAFE_INTEGER)return new d(a.negint,i,9)}if(n.allowBigInt!==!0)throw new Error(`${p} integers outside of the safe integer range are not supported`);return new d(a.negint,Ct-BigInt(o),9)}function nt(t,e){let r=e.value,n=typeof r=="bigint"?r*Ct-hn:r*-1-1;T(t,e.type.majorEncoded,n)}nt.encodedSize=function(e){let r=e.value,n=typeof r=="bigint"?r*Ct-hn:r*-1-1;return n<E[0]?1:n<E[1]?2:n<E[2]?3:n<E[3]?5:9};nt.compareTokens=function(e,r){return e.value<r.value?1:e.value>r.value?-1:0};function Se(t,e,r,n){j(t,e,r+n);let o=pe(t,e+r,e+r+n);return new d(a.bytes,o,r+n)}function mn(t,e,r,n){return Se(t,e,1,r)}function yn(t,e,r,n){return Se(t,e,2,B(t,e+1,n))}function gn(t,e,r,n){return Se(t,e,3,C(t,e+1,n))}function xn(t,e,r,n){return Se(t,e,5,D(t,e+1,n))}function wn(t,e,r,n){let o=U(t,e+1,n);if(typeof o=="bigint")throw new Error(`${p} 64-bit integer bytes lengths not supported`);return Se(t,e,9,o)}function ot(t){return t.encodedBytes===void 0&&(t.encodedBytes=t.type===a.string?tn(t.value):t.value),t.encodedBytes}function me(t,e){let r=ot(e);T(t,e.type.majorEncoded,r.length),t.push(r)}me.encodedSize=function(e){let r=ot(e);return T.encodedSize(r.length)+r.length};me.compareTokens=function(e,r){return Bi(ot(e),ot(r))};function Bi(t,e){return t.length<e.length?-1:t.length>e.length?1:on(t,e)}function Ne(t,e,r,n,o){let i=r+n;j(t,e,i);let s=new d(a.string,en(t,e+r,e+i),i);return o.retainStringBytes===!0&&(s.byteValue=pe(t,e+r,e+i)),s}function bn(t,e,r,n){return Ne(t,e,1,r,n)}function En(t,e,r,n){return Ne(t,e,2,B(t,e+1,n),n)}function Tn(t,e,r,n){return Ne(t,e,3,C(t,e+1,n),n)}function kn(t,e,r,n){return Ne(t,e,5,D(t,e+1,n),n)}function An(t,e,r,n){let o=U(t,e+1,n);if(typeof o=="bigint")throw new Error(`${p} 64-bit integer string lengths not supported`);return Ne(t,e,9,o,n)}var vn=me;function ye(t,e,r,n){return new d(a.array,n,r)}function In(t,e,r,n){return ye(t,e,1,r)}function _n(t,e,r,n){return ye(t,e,2,B(t,e+1,n))}function Sn(t,e,r,n){return ye(t,e,3,C(t,e+1,n))}function Nn(t,e,r,n){return ye(t,e,5,D(t,e+1,n))}function Bn(t,e,r,n){let o=U(t,e+1,n);if(typeof o=="bigint")throw new Error(`${p} 64-bit integer array lengths not supported`);return ye(t,e,9,o)}function Cn(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${p} indefinite length items not allowed`);return ye(t,e,1,1/0)}function it(t,e){T(t,a.array.majorEncoded,e.value)}it.compareTokens=F.compareTokens;it.encodedSize=function(e){return T.encodedSize(e.value)};function ge(t,e,r,n){return new d(a.map,n,r)}function Dn(t,e,r,n){return ge(t,e,1,r)}function Un(t,e,r,n){return ge(t,e,2,B(t,e+1,n))}function zn(t,e,r,n){return ge(t,e,3,C(t,e+1,n))}function Ln(t,e,r,n){return ge(t,e,5,D(t,e+1,n))}function Fn(t,e,r,n){let o=U(t,e+1,n);if(typeof o=="bigint")throw new Error(`${p} 64-bit integer map lengths not supported`);return ge(t,e,9,o)}function Rn(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${p} indefinite length items not allowed`);return ge(t,e,1,1/0)}function st(t,e){T(t,a.map.majorEncoded,e.value)}st.compareTokens=F.compareTokens;st.encodedSize=function(e){return T.encodedSize(e.value)};function Mn(t,e,r,n){return new d(a.tag,r,1)}function On(t,e,r,n){return new d(a.tag,B(t,e+1,n),2)}function Pn(t,e,r,n){return new d(a.tag,C(t,e+1,n),3)}function $n(t,e,r,n){return new d(a.tag,D(t,e+1,n),5)}function Hn(t,e,r,n){return new d(a.tag,U(t,e+1,n),9)}function at(t,e){T(t,a.tag.majorEncoded,e.value)}at.compareTokens=F.compareTokens;at.encodedSize=function(e){return T.encodedSize(e.value)};var Fi=20,Ri=21,Mi=22,Oi=23;function Vn(t,e,r,n){if(n.allowUndefined===!1)throw new Error(`${p} undefined values are not supported`);return n.coerceUndefinedToNull===!0?new d(a.null,null,1):new d(a.undefined,void 0,1)}function Gn(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${p} indefinite length items not allowed`);return new d(a.break,void 0,1)}function Dt(t,e,r){if(r){if(r.allowNaN===!1&&Number.isNaN(t))throw new Error(`${p} NaN values are not supported`);if(r.allowInfinity===!1&&(t===1/0||t===-1/0))throw new Error(`${p} Infinity values are not supported`)}return new d(a.float,t,e)}function qn(t,e,r,n){return Dt(Ut(t,e+1),3,n)}function Xn(t,e,r,n){return Dt(zt(t,e+1),5,n)}function Wn(t,e,r,n){return Dt(Qn(t,e+1),9,n)}function ct(t,e,r){let n=e.value;if(n===!1)t.push([a.float.majorEncoded|Fi]);else if(n===!0)t.push([a.float.majorEncoded|Ri]);else if(n===null)t.push([a.float.majorEncoded|Mi]);else if(n===void 0)t.push([a.float.majorEncoded|Oi]);else{let o,i=!1;(!r||r.float64!==!0)&&(Kn(n),o=Ut(P,1),n===o||Number.isNaN(n)?(P[0]=249,t.push(P.slice(0,3)),i=!0):(jn(n),o=zt(P,1),n===o&&(P[0]=250,t.push(P.slice(0,5)),i=!0))),i||(Pi(n),o=Qn(P,1),P[0]=251,t.push(P.slice(0,9)))}}ct.encodedSize=function(e,r){let n=e.value;if(n===!1||n===!0||n===null||n===void 0)return 1;if(!r||r.float64!==!0){Kn(n);let o=Ut(P,1);if(n===o||Number.isNaN(n))return 3;if(jn(n),o=zt(P,1),n===o)return 5}return 9};var Jn=new ArrayBuffer(9),R=new DataView(Jn,1),P=new Uint8Array(Jn,0);function Kn(t){if(t===1/0)R.setUint16(0,31744,!1);else if(t===-1/0)R.setUint16(0,64512,!1);else if(Number.isNaN(t))R.setUint16(0,32256,!1);else{R.setFloat32(0,t);let e=R.getUint32(0),r=(e&2139095040)>>23,n=e&8388607;if(r===255)R.setUint16(0,31744,!1);else if(r===0)R.setUint16(0,(t&2147483648)>>16|n>>13,!1);else{let o=r-127;o<-24?R.setUint16(0,0):o<-14?R.setUint16(0,(e&2147483648)>>16|1<<24+o,!1):R.setUint16(0,(e&2147483648)>>16|o+15<<10|n>>13,!1)}}}function Ut(t,e){if(t.length-e<2)throw new Error(`${p} 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 jn(t){R.setFloat32(0,t,!1)}function zt(t,e){if(t.length-e<4)throw new Error(`${p} not enough data for float32`);let r=(t.byteOffset||0)+e;return new DataView(t.buffer,r,4).getFloat32(0,!1)}function Pi(t){R.setFloat64(0,t,!1)}function Qn(t,e){if(t.length-e<8)throw new Error(`${p} not enough data for float64`);let r=(t.byteOffset||0)+e;return new DataView(t.buffer,r,8).getFloat64(0,!1)}ct.compareTokens=F.compareTokens;function y(t,e,r){throw new Error(`${p} encountered invalid minor (${r}) for major ${t[e]>>>5}`)}function ut(t){return()=>{throw new Error(`${p} ${t}`)}}var f=[];for(let t=0;t<=23;t++)f[t]=y;f[24]=sn;f[25]=an;f[26]=cn;f[27]=un;f[28]=y;f[29]=y;f[30]=y;f[31]=y;for(let t=32;t<=55;t++)f[t]=y;f[56]=fn;f[57]=dn;f[58]=ln;f[59]=pn;f[60]=y;f[61]=y;f[62]=y;f[63]=y;for(let t=64;t<=87;t++)f[t]=mn;f[88]=yn;f[89]=gn;f[90]=xn;f[91]=wn;f[92]=y;f[93]=y;f[94]=y;f[95]=ut("indefinite length bytes/strings are not supported");for(let t=96;t<=119;t++)f[t]=bn;f[120]=En;f[121]=Tn;f[122]=kn;f[123]=An;f[124]=y;f[125]=y;f[126]=y;f[127]=ut("indefinite length bytes/strings are not supported");for(let t=128;t<=151;t++)f[t]=In;f[152]=_n;f[153]=Sn;f[154]=Nn;f[155]=Bn;f[156]=y;f[157]=y;f[158]=y;f[159]=Cn;for(let t=160;t<=183;t++)f[t]=Dn;f[184]=Un;f[185]=zn;f[186]=Ln;f[187]=Fn;f[188]=y;f[189]=y;f[190]=y;f[191]=Rn;for(let t=192;t<=215;t++)f[t]=Mn;f[216]=On;f[217]=Pn;f[218]=$n;f[219]=Hn;f[220]=y;f[221]=y;f[222]=y;f[223]=y;for(let t=224;t<=243;t++)f[t]=ut("simple values are not supported");f[244]=y;f[245]=y;f[246]=y;f[247]=Vn;f[248]=ut("simple values are not supported");f[249]=qn;f[250]=Xn;f[251]=Wn;f[252]=y;f[253]=y;f[254]=y;f[255]=Gn;var $=[];for(let t=0;t<24;t++)$[t]=new d(a.uint,t,1);for(let t=-1;t>=-24;t--)$[31-t]=new d(a.negint,t,1);$[64]=new d(a.bytes,new Uint8Array(0),1);$[96]=new d(a.string,"",1);$[128]=new d(a.array,0,1);$[160]=new d(a.map,0,1);$[244]=new d(a.false,!1,1);$[245]=new d(a.true,!0,1);$[246]=new d(a.null,null,1);function Lt(t){switch(t.type){case a.false:return W([244]);case a.true:return W([245]);case a.null:return W([246]);case a.bytes:return t.value.length?void 0:W([64]);case a.string:return t.value===""?W([96]):void 0;case a.array:return t.value===0?W([128]):void 0;case a.map:return t.value===0?W([160]):void 0;case a.uint:return t.value<24?W([Number(t.value)]):void 0;case a.negint:if(t.value>=-24)return W([31-Number(t.value)])}}var Hi={float64:!1,mapSorter:Gi,quickEncodeToken:Lt};function Rt(){let t=[];return t[a.uint.major]=F,t[a.negint.major]=nt,t[a.bytes.major]=me,t[a.string.major]=vn,t[a.array.major]=it,t[a.map.major]=st,t[a.tag.major]=at,t[a.float.major]=ct,t}var Yn=Rt(),Ft=new Ie,ft=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(`${Bt} object contains circular references`);return new t(r,e)}},ee={null:new d(a.null,null),undefined:new d(a.undefined,void 0),true:new d(a.true,!0),false:new d(a.false,!1),emptyArray:new d(a.array,0),emptyMap:new d(a.map,0)},te={number(t,e,r,n){return!Number.isInteger(t)||!Number.isSafeInteger(t)?new d(a.float,t):t>=0?new d(a.uint,t):new d(a.negint,t)},bigint(t,e,r,n){return t>=BigInt(0)?new d(a.uint,t):new d(a.negint,t)},Uint8Array(t,e,r,n){return new d(a.bytes,t)},string(t,e,r,n){return new d(a.string,t)},boolean(t,e,r,n){return t?ee.true:ee.false},null(t,e,r,n){return ee.null},undefined(t,e,r,n){return ee.undefined},ArrayBuffer(t,e,r,n){return new d(a.bytes,new Uint8Array(t))},DataView(t,e,r,n){return new d(a.bytes,new Uint8Array(t.buffer,t.byteOffset,t.byteLength))},Array(t,e,r,n){if(!t.length)return r.addBreakTokens===!0?[ee.emptyArray,new d(a.break)]:ee.emptyArray;n=ft.createCheck(n,t);let o=[],i=0;for(let s of t)o[i++]=Be(s,r,n);return r.addBreakTokens?[new d(a.array,t.length),o,new d(a.break)]:[new d(a.array,t.length),o]},Object(t,e,r,n){let o=e!=="Object",i=o?t.keys():Object.keys(t),s=o?t.size:i.length;if(!s)return r.addBreakTokens===!0?[ee.emptyMap,new d(a.break)]:ee.emptyMap;n=ft.createCheck(n,t);let c=[],u=0;for(let l of i)c[u++]=[Be(l,r,n),Be(o?t.get(l):t[l],r,n)];return Vi(c,r),r.addBreakTokens?[new d(a.map,s),c,new d(a.break)]:[new d(a.map,s),c]}};te.Map=te.Object;te.Buffer=te.Uint8Array;for(let t of"Uint8Clamped Uint16 Uint32 Int8 Int16 Int32 BigUint64 BigInt64 Float32 Float64".split(" "))te[`${t}Array`]=te.DataView;function Be(t,e={},r){let n=jr(t),o=e&&e.typeEncoders&&e.typeEncoders[n]||te[n];if(typeof o=="function"){let s=o(t,n,e,r);if(s!=null)return s}let i=te[n];if(!i)throw new Error(`${Bt} unsupported type: ${n}`);return i(t,n,e,r)}function Vi(t,e){e.mapSorter&&t.sort(e.mapSorter)}function Gi(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=Yn[o].compareTokens(r,n);return i===0&&console.warn("WARNING: complex key types used, CBOR key sorting guarantees are gone"),i}function Zn(t,e,r,n){if(Array.isArray(e))for(let o of e)Zn(t,o,r,n);else r[e.type.major](t,e,n)}function qi(t,e,r){let n=Be(t,r);if(!Array.isArray(n)&&r.quickEncodeToken){let o=r.quickEncodeToken(n);if(o)return o;let i=e[n.type.major];if(i.encodedSize){let s=i.encodedSize(n,r),c=new Ie(s);if(i(c,n,r),c.chunks.length!==1)throw new Error(`Unexpected error: pre-calculated length for ${n} was wrong`);return Nt(c.chunks[0])}}return Ft.reset(),Zn(Ft,n,e,r),Ft.toBytes(!0)}function Mt(t,e){return e=Object.assign({},Hi,e),qi(t,Yn,e)}var Xi={strict:!1,allowIndefinite:!0,allowUndefined:!0,allowBigInt:!0},dt=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=$[e];if(r===void 0){let n=f[e];if(!n)throw new Error(`${p} 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}},Ce=Symbol.for("DONE"),lt=Symbol.for("BREAK");function Wi(t,e,r){let n=[];for(let o=0;o<t.value;o++){let i=xe(e,r);if(i===lt){if(t.value===1/0)break;throw new Error(`${p} got unexpected break to lengthed array`)}if(i===Ce)throw new Error(`${p} found array but not enough entries (got ${o}, expected ${t.value})`);n[o]=i}return n}function Ji(t,e,r){let n=r.useMaps===!0,o=n?void 0:{},i=n?new Map:void 0;for(let s=0;s<t.value;s++){let c=xe(e,r);if(c===lt){if(t.value===1/0)break;throw new Error(`${p} got unexpected break to lengthed map`)}if(c===Ce)throw new Error(`${p} found map but not enough entries (got ${s} [no key], expected ${t.value})`);if(n!==!0&&typeof c!="string")throw new Error(`${p} non-string keys not supported (got ${typeof c})`);if(r.rejectDuplicateMapKeys===!0&&(n&&i.has(c)||!n&&c in o))throw new Error(`${p} found repeat map key "${c}"`);let u=xe(e,r);if(u===Ce)throw new Error(`${p} found map but not enough entries (got ${s} [no value], expected ${t.value})`);n?i.set(c,u):o[c]=u}return n?i:o}function xe(t,e){if(t.done())return Ce;let r=t.next();if(r.type===a.break)return lt;if(r.type.terminal)return r.value;if(r.type===a.array)return Wi(r,t,e);if(r.type===a.map)return Ji(r,t,e);if(r.type===a.tag){if(e.tags&&typeof e.tags[r.value]=="function"){let n=xe(t,e);return e.tags[r.value](n)}throw new Error(`${p} tag not supported (${r.value})`)}throw new Error("unsupported")}function eo(t,e){if(!(t instanceof Uint8Array))throw new Error(`${p} data to decode must be a Uint8Array`);e=Object.assign({},Xi,e);let r=e.tokenizer||new dt(t,e),n=xe(r,e);if(n===Ce)throw new Error(`${p} did not find any content to decode`);if(n===lt)throw new Error(`${p} got unexpected break`);return[n,t.subarray(r.pos())]}function Ot(t,e){let[r,n]=eo(t,e);if(n.length>0)throw new Error(`${p} too many terminals, data makes no sense`);return r}var qt={};N(qt,{base32:()=>be,base32hex:()=>is,base32hexpad:()=>as,base32hexpadupper:()=>cs,base32hexupper:()=>ss,base32pad:()=>ns,base32padupper:()=>os,base32upper:()=>rs,base32z:()=>us});var ru=new Uint8Array(0);function to(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 Q(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 ro(t){return new TextEncoder().encode(t)}function no(t){return new TextDecoder().decode(t)}function ji(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 c=t.length,u=t.charAt(0),l=Math.log(c)/Math.log(256),m=Math.log(256)/Math.log(c);function h(g){if(g instanceof Uint8Array||(ArrayBuffer.isView(g)?g=new Uint8Array(g.buffer,g.byteOffset,g.byteLength):Array.isArray(g)&&(g=Uint8Array.from(g))),!(g instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(g.length===0)return"";for(var k=0,ae=0,M=0,G=g.length;M!==G&&g[M]===0;)M++,k++;for(var q=(G-M)*m+1>>>0,L=new Uint8Array(q);M!==G;){for(var X=g[M],Z=0,O=q-1;(X!==0||Z<ae)&&O!==-1;O--,Z++)X+=256*L[O]>>>0,L[O]=X%c>>>0,X=X/c>>>0;if(X!==0)throw new Error("Non-zero carry");ae=Z,M++}for(var K=q-ae;K!==q&&L[K]===0;)K++;for(var Ze=u.repeat(k);K<q;++K)Ze+=t.charAt(L[K]);return Ze}function I(g){if(typeof g!="string")throw new TypeError("Expected String");if(g.length===0)return new Uint8Array;var k=0;if(g[k]!==" "){for(var ae=0,M=0;g[k]===u;)ae++,k++;for(var G=(g.length-k)*l+1>>>0,q=new Uint8Array(G);g[k];){var L=r[g.charCodeAt(k)];if(L===255)return;for(var X=0,Z=G-1;(L!==0||X<M)&&Z!==-1;Z--,X++)L+=c*q[Z]>>>0,q[Z]=L%256>>>0,L=L/256>>>0;if(L!==0)throw new Error("Non-zero carry");M=X,k++}if(g[k]!==" "){for(var O=G-M;O!==G&&q[O]===0;)O++;for(var K=new Uint8Array(ae+(G-O)),Ze=ae;O!==G;)K[Ze++]=q[O++];return K}}}function b(g){var k=I(g);if(k)return k;throw new Error(`Non-${e} character`)}return{encode:h,decodeUnsafe:I,decode:b}}var Qi=ji,Yi=Qi,oo=Yi;var $t=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")}},Ht=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 io(this,e)}},Vt=class{decoders;constructor(e){this.decoders=e}or(e){return io(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 io(t,e){return new Vt({...t.decoders??{[t.prefix]:t},...e.decoders??{[e.prefix]:e}})}var Gt=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 $t(e,r,n),this.decoder=new Ht(e,r,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function we({name:t,prefix:e,encode:r,decode:n}){return new Gt(t,e,r,n)}function re({name:t,prefix:e,alphabet:r}){let{encode:n,decode:o}=oo(r,t);return we({prefix:e,name:t,encode:n,decode:i=>Q(o(i))})}function Zi(t,e,r,n){let o=t.length;for(;t[o-1]==="=";)--o;let i=new Uint8Array(o*r/8|0),s=0,c=0,u=0;for(let l=0;l<o;++l){let m=e[t[l]];if(m===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<r|m,s+=r,s>=8&&(s-=8,i[u++]=255&c>>s)}if(s>=r||(255&c<<8-s)!==0)throw new SyntaxError("Unexpected end of data");return i}function es(t,e,r){let n=e[e.length-1]==="=",o=(1<<r)-1,i="",s=0,c=0;for(let u=0;u<t.length;++u)for(c=c<<8|t[u],s+=8;s>r;)s-=r,i+=e[o&c>>s];if(s!==0&&(i+=e[o&c<<r-s]),n)for(;(i.length*r&7)!==0;)i+="=";return i}function ts(t){let e={};for(let r=0;r<t.length;++r)e[t[r]]=r;return e}function w({name:t,prefix:e,bitsPerChar:r,alphabet:n}){let o=ts(n);return we({prefix:e,name:t,encode(i){return es(i,n,r)},decode(i){return Zi(i,o,r,t)}})}var be=w({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),rs=w({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),ns=w({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),os=w({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),is=w({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),ss=w({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),as=w({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),cs=w({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),us=w({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Xt={};N(Xt,{base36:()=>De,base36upper:()=>fs});var De=re({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),fs=re({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Wt={};N(Wt,{base58btc:()=>J,base58flickr:()=>ds});var J=re({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),ds=re({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var ls=co,so=128,hs=127,ps=~hs,ms=Math.pow(2,31);function co(t,e,r){e=e||[],r=r||0;for(var n=r;t>=ms;)e[r++]=t&255|so,t/=128;for(;t&ps;)e[r++]=t&255|so,t>>>=7;return e[r]=t|0,co.bytes=r-n+1,e}var ys=Jt,gs=128,ao=127;function Jt(t,n){var r=0,n=n||0,o=0,i=n,s,c=t.length;do{if(i>=c)throw Jt.bytes=0,new RangeError("Could not decode varint");s=t[i++],r+=o<28?(s&ao)<<o:(s&ao)*Math.pow(2,o),o+=7}while(s>=gs);return Jt.bytes=i-n,r}var xs=Math.pow(2,7),ws=Math.pow(2,14),bs=Math.pow(2,21),Es=Math.pow(2,28),Ts=Math.pow(2,35),ks=Math.pow(2,42),As=Math.pow(2,49),vs=Math.pow(2,56),Is=Math.pow(2,63),_s=function(t){return t<xs?1:t<ws?2:t<bs?3:t<Es?4:t<Ts?5:t<ks?6:t<As?7:t<vs?8:t<Is?9:10},Ss={encode:ls,decode:ys,encodingLength:_s},Ns=Ss,Ue=Ns;function ze(t,e=0){return[Ue.decode(t,e),Ue.decode.bytes]}function Ee(t,e,r=0){return Ue.encode(t,e,r),e}function Te(t){return Ue.encodingLength(t)}function ue(t,e){let r=e.byteLength,n=Te(t),o=n+Te(r),i=new Uint8Array(o+r);return Ee(t,i,0),Ee(r,i,n),i.set(e,o),new ke(t,r,e,i)}function pt(t){let e=Q(t),[r,n]=ze(e),[o,i]=ze(e.subarray(n)),s=e.subarray(n+i);if(s.byteLength!==o)throw new Error("Incorrect length");return new ke(r,o,s,e)}function uo(t,e){if(t===e)return!0;{let r=e;return t.code===r.code&&t.size===r.size&&r.bytes instanceof Uint8Array&&to(t.bytes,r.bytes)}}var ke=class{code;size;digest;bytes;constructor(e,r,n,o){this.code=e,this.size=r,this.digest=n,this.bytes=o}};function fo(t,e){let{bytes:r,version:n}=t;switch(n){case 0:return Cs(r,Kt(t),e??J.encoder);default:return Ds(r,Kt(t),e??be.encoder)}}var lo=new WeakMap;function Kt(t){let e=lo.get(t);if(e==null){let r=new Map;return lo.set(t,r),r}return e}var x=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!==Le)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==Us)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=ue(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&&uo(e.multihash,n.multihash)}toString(e){return fo(this,e)}toJSON(){return{"/":fo(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??ho(n,o,i.bytes))}else if(r[zs]===!0){let{version:n,multihash:o,code:i}=r,s=pt(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!==Le)throw new Error(`Version 0 CID must use dag-pb (code: ${Le}) block encoding`);return new t(e,r,n,n.bytes)}case 1:{let o=ho(e,r,n.bytes);return new t(e,r,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return t.create(0,Le,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=Q(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 ke(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[h,I]=ze(e.subarray(r));return r+=I,h},o=n(),i=Le;if(o===18?(o=0,r=0):i=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let s=r,c=n(),u=n(),l=r+u,m=l-s;return{version:o,codec:i,multihashCode:c,digestSize:u,multihashSize:m,size:l}}static parse(e,r){let[n,o]=Bs(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 Kt(i).set(n,e),i}};function Bs(t,e){switch(t[0]){case"Q":{let r=e??J;return[J.prefix,r.decode(`${J.prefix}${t}`)]}case J.prefix:{let r=e??J;return[J.prefix,r.decode(t)]}case be.prefix:{let r=e??be;return[be.prefix,r.decode(t)]}case De.prefix:{let r=e??De;return[De.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 Cs(t,e,r){let{prefix:n}=r;if(n!==J.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 Ds(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 Le=112,Us=18;function ho(t,e,r){let n=Te(t),o=n+Te(e),i=new Uint8Array(o+r.byteLength);return Ee(t,i,0),Ee(e,i,n),i.set(r,o),i}var zs=Symbol.for("@ipld/js-cid/CID");var po=42;function Ls(t){return t instanceof ArrayBuffer?new Uint8Array(t,0,t.byteLength):t}function Fs(t){if(t.asCID!==t&&t["/"]!==t.bytes)return null;let e=x.asCID(t);if(!e)return null;let r=new Uint8Array(e.bytes.byteLength+1);return r.set(e.bytes,1),[new d(a.tag,po),new d(a.bytes,r)]}function Rs(){throw new Error("`undefined` is not supported by the IPLD Data Model and cannot be encoded")}function Ms(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}var jt={float64:!0,typeEncoders:{Object:Fs,undefined:Rs,number:Ms}},bu={...jt,typeEncoders:{...jt.typeEncoders}};function Os(t){if(t[0]!==0)throw new Error("Invalid CID for CBOR tag 42; expected leading 0x00");return x.decode(t.subarray(1))}var mt={allowIndefinite:!1,coerceUndefinedToNull:!0,allowNaN:!1,allowInfinity:!1,allowBigInt:!0,strict:!0,useMaps:!1,rejectDuplicateMapKeys:!0,tags:[]};mt.tags[po]=Os;var Eu={...mt,tags:mt.tags.slice()};var Qt=t=>Mt(t,jt),Yt=t=>Ot(Ls(t),mt);var tr=tt(yt(),1);var rr=40;function nr(t,e){if(!t.length)throw new Error("Unexpected end of data");let r=tr.default.decode(t);return e.seek(tr.default.decode.bytes),r}function or(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 ne={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},Fe={"CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)":ne.Link,"CarV1HeaderOrV2Pragma > roots (anon)":t=>{if(ne.List(t)!==void 0){for(let e=0;e<t.length;e++){let r=t[e];if(r=Fe["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=Fe["CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)"](i),i===void 0)return;n.push(i)}return n}}return t}},Int:ne.Int,CarV1HeaderOrV2Pragma:t=>{if(ne.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 c=Fe["CarV1HeaderOrV2Pragma > roots (anon)"](t[i]);if(c===void 0)return;if(c!==s||r!==t){if(r===t){r={};for(let u=0;u<o;u++)r[e[u][0]]=e[u][1]}r.roots=c}}break;case"version":{n--;let c=Fe.Int(t[i]);if(c===void 0)return;if(c!==s||r!==t){if(r===t){r={};for(let u=0;u<o;u++)r[e[u][0]]=e[u][1]}r.version=c}}break;default:return}}if(!(n>0))return r}},Re={"CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)":ne.Link,"CarV1HeaderOrV2Pragma > roots (anon)":t=>{if(ne.List(t)!==void 0){for(let e=0;e<t.length;e++){let r=t[e];if(r=Re["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=Re["CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)"](i),i===void 0)return;n.push(i)}return n}}return t}},Int:ne.Int,CarV1HeaderOrV2Pragma:t=>{if(ne.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 c=Re["CarV1HeaderOrV2Pragma > roots (anon)"](s);if(c===void 0)return;if(c!==s||r!==t){if(r===t){r={};for(let u=0;u<o;u++)r[e[u][0]]=e[u][1]}r.roots=c}}break;case"version":{n--;let c=Re.Int(s);if(c===void 0)return;if(c!==s||r!==t){if(r===t){r={};for(let u=0;u<o;u++)r[e[u][0]]=e[u][1]}r.version=c}}break;default:return}}if(!(n>0))return r}},ir={toTyped:Fe.CarV1HeaderOrV2Pragma,toRepresentation:Re.CarV1HeaderOrV2Pragma};var Fu=Rt();var na=tt(yt(),1);var $u=[new d(a.map,2),new d(a.string,"version"),new d(a.uint,1),new d(a.string,"roots")],Hu=new d(a.tag,42);async function sr(t,e){let r=nr(await t.upTo(8),t);if(r===0)throw new Error("Invalid CAR header (zero length)");let n=await t.exactly(r,!0),o=Yt(n);if(ir.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=or(await t.exactly(rr,!0));t.seek(i.dataOffset-t.pos);let s=await sr(t,1);return Object.assign(s,i)}function Me(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 ar=tt(yt(),1),Io=1;function cr(t){let e=Qt({version:Io,roots:t}),r=ar.default.encode(e.length),n=new Uint8Array(r.length+e.length);return n.set(r,0),n.set(e,r.length),n}function _o(t){return{async setRoots(e){let r=cr(e);await t.write(r)},async writeBlock(e){let{cid:r,bytes:n}=e;await t.write(new Uint8Array(ar.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 Io}}}function gt(){}function So(){let t=[],e=null,r=gt,n=!1,o=null,i=gt,s=()=>(e||(e=new Promise(l=>{r=()=>{e=null,r=gt,l()}})),e),c={write(l){t.push(l);let m=s();return i(),m},async end(){n=!0;let l=s();i(),await l}},u={async next(){let l=t.shift();return l?(t.length===0&&r(),{done:!1,value:l}):n?(r(),{done:!0,value:void 0}):(o||(o=new Promise(m=>{i=()=>(o=null,i=gt,m(u.next()))})),o)}};return{writer:c,iterator:u}}var Oe=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=x.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=aa(e);let{encoder:r,iterator:n}=No(),o=new t(e,r),i=new xt(n);return{writer:o,out:i}}static createAppender(){let{encoder:e,iterator:r}=No();e.setRoots=()=>Promise.resolve();let n=new t([],e),o=new xt(r);return{writer:n,out:o}}static async updateRootsInBytes(e,r){let n=Me(e);await sr(n);let o=cr(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}},xt=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 No(){let t=So(),{writer:e,iterator:r}=t;return{encoder:_o(e),iterator:r}}function aa(t){if(t===void 0)return[];if(!Array.isArray(t)){let r=x.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=x.asCID(r);if(!n)throw new TypeError("roots must be a single CID or an array of CIDs");e.push(n)}return e}function ca(t){return t[Symbol.asyncIterator]!=null}function ua(t){if(ca(t))return(async()=>{for await(let e of t);})();for(let e of t);}var Bo=ua;function fa(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 Co=fa;function da(t){return t[Symbol.asyncIterator]!=null}function la(t,e){let r=0;if(da(t))return async function*(){for await(let u of t)yield e(u,r++)}();let n=Co(t),{value:o,done:i}=n.next();if(i===!0)return function*(){}();let s=e(o,r++);if(typeof s.then=="function")return async function*(){yield await s;for(let u of n)yield e(u,r++)}();let c=e;return function*(){yield s;for(let u of n)yield c(u,r++)}()}var Do=la;function fr({name:t,code:e,encode:r}){return new ur(t,e,r)}var ur=class{name;code;encode;constructor(e,r,n){this.name=e,this.code=r,this.encode=n}digest(e){if(e instanceof Uint8Array){let r=this.encode(e);return r instanceof Uint8Array?ue(this.code,r):r.then(n=>ue(this.code,n))}else throw Error("Unknown type, must be binary type")}};function wt({enumerable:t=!0,configurable:e=!1}={}){return{enumerable:t,configurable:e,writable:!1}}function*ha(t,e){if(e!=null&&typeof e=="object")if(Array.isArray(e))for(let[r,n]of e.entries()){let o=[...t,r],i=x.asCID(n);i!=null?yield[o.join("/"),i]:typeof n=="object"&&(yield*dr(n,o))}else{let r=x.asCID(e);r!=null?yield[t.join("/"),r]:yield*dr(e,t)}}function*dr(t,e){if(t==null||t instanceof Uint8Array)return;let r=x.asCID(t);r!=null&&(yield[e.join("/"),r]);for(let[n,o]of Object.entries(t)){let i=[...e,n];yield*ha(i,o)}}function*pa(t,e){if(Array.isArray(e))for(let[r,n]of e.entries()){let o=[...t,r];yield o.join("/"),typeof n=="object"&&x.asCID(n)==null&&(yield*lr(n,o))}else yield*lr(e,t)}function*lr(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"&&x.asCID(n)==null&&(yield*pa(o,n))}}function ma(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=x.asCID(r);if(i!=null)return{value:i,remaining:e.slice(n+1).join("/")}}return{value:r}}var hr=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:wt(),bytes:wt(),value:wt(),asBlock:wt()})}links(){return dr(this.value,[])}tree(){return lr(this.value,[])}get(e="/"){return ma(this.value,e.split("/").filter(Boolean))}};function pr({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 hr({cid:e,bytes:t,value:o})}function mr(){let t={};return t.promise=new Promise((e,r)=>{t.resolve=e,t.reject=r}),t}var gr=tt(Lo(),1);var $e=class extends Error{constructor(e){super(e),this.name="TimeoutError"}},xr=class extends Error{constructor(e){super(),this.name="AbortError",this.message=e}},Fo=t=>globalThis.DOMException===void 0?new xr(t):new DOMException(t),Ro=t=>{let e=t.reason===void 0?Fo("This operation was aborted."):t.reason;return e instanceof Error?e:Fo(e)};function wr(t,e){let{milliseconds:r,fallback:n,message:o,customTimers:i={setTimeout,clearTimeout}}=e,s,c,l=new Promise((m,h)=>{if(typeof r!="number"||Math.sign(r)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${r}\``);if(e.signal){let{signal:b}=e;b.aborted&&h(Ro(b)),c=()=>{h(Ro(b))},b.addEventListener("abort",c,{once:!0})}if(r===Number.POSITIVE_INFINITY){t.then(m,h);return}let I=new $e;s=i.setTimeout.call(void 0,()=>{if(n){try{m(n())}catch(b){h(b)}return}typeof t.cancel=="function"&&t.cancel(),o===!1?m():o instanceof Error?h(o):(I.message=o??`Promise timed out after ${r} milliseconds`,h(I))},r),(async()=>{try{m(await t)}catch(b){h(b)}})()}).finally(()=>{l.clear(),c&&e.signal&&e.signal.removeEventListener("abort",c)});return l.clear=()=>{i.clearTimeout.call(void 0,s),s=void 0},l}function br(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 He=class{#e=[];enqueue(e,r){r={priority:0,...r};let n={priority:r.priority,id:r.id,run:e};if(this.size===0||this.#e[this.size-1].priority>=r.priority){this.#e.push(n);return}let o=br(this.#e,n,(i,s)=>s.priority-i.priority);this.#e.splice(o,0,n)}setPriority(e,r){let n=this.#e.findIndex(i=>i.id===e);if(n===-1)throw new ReferenceError(`No promise function with the id "${e}" exists in the queue.`);let[o]=this.#e.splice(n,1);this.enqueue(o.run,{priority:r,id:e})}dequeue(){return this.#e.shift()?.run}filter(e){return this.#e.filter(r=>r.priority===e.priority).map(r=>r.run)}get size(){return this.#e.length}};var Ve=class extends gr.default{#e;#o;#s=0;#h;#a;#p=0;#r;#c;#t;#m;#n=0;#u;#i;#y;#w=1n;timeout;constructor(e){if(super(),e={carryoverConcurrencyCount:!1,intervalCap:Number.POSITIVE_INFINITY,interval:0,concurrency:Number.POSITIVE_INFINITY,autoStart:!0,queueClass:He,...e},!(typeof e.intervalCap=="number"&&e.intervalCap>=1))throw new TypeError(`Expected \`intervalCap\` to be a number from 1 and up, got \`${e.intervalCap?.toString()??""}\` (${typeof e.intervalCap})`);if(e.interval===void 0||!(Number.isFinite(e.interval)&&e.interval>=0))throw new TypeError(`Expected \`interval\` to be a finite number >= 0, got \`${e.interval?.toString()??""}\` (${typeof e.interval})`);this.#e=e.carryoverConcurrencyCount,this.#o=e.intervalCap===Number.POSITIVE_INFINITY||e.interval===0,this.#h=e.intervalCap,this.#a=e.interval,this.#t=new e.queueClass,this.#m=e.queueClass,this.concurrency=e.concurrency,this.timeout=e.timeout,this.#y=e.throwOnTimeout===!0,this.#i=e.autoStart===!1}get#b(){return this.#o||this.#s<this.#h}get#E(){return this.#n<this.#u}#T(){this.#n--,this.#f(),this.emit("next")}#k(){this.#x(),this.#g(),this.#c=void 0}get#A(){let e=Date.now();if(this.#r===void 0){let r=this.#p-e;if(r<0)this.#s=this.#e?this.#n:0;else return this.#c===void 0&&(this.#c=setTimeout(()=>{this.#k()},r)),!0}return!1}#f(){if(this.#t.size===0)return this.#r&&clearInterval(this.#r),this.#r=void 0,this.emit("empty"),this.#n===0&&this.emit("idle"),!1;if(!this.#i){let e=!this.#A;if(this.#b&&this.#E){let r=this.#t.dequeue();return r?(this.emit("active"),r(),e&&this.#g(),!0):!1}}return!1}#g(){this.#o||this.#r!==void 0||(this.#r=setInterval(()=>{this.#x()},this.#a),this.#p=Date.now()+this.#a)}#x(){this.#s===0&&this.#n===0&&this.#r&&(clearInterval(this.#r),this.#r=void 0),this.#s=this.#e?this.#n:0,this.#d()}#d(){for(;this.#f(););}get concurrency(){return this.#u}set concurrency(e){if(!(typeof e=="number"&&e>=1))throw new TypeError(`Expected \`concurrency\` to be a number from 1 and up, got \`${e}\` (${typeof e})`);this.#u=e,this.#d()}async#v(e){return new Promise((r,n)=>{e.addEventListener("abort",()=>{n(e.reason)},{once:!0})})}setPriority(e,r){this.#t.setPriority(e,r)}async add(e,r={}){return r.id??=(this.#w++).toString(),r={timeout:this.timeout,throwOnTimeout:this.#y,...r},new Promise((n,o)=>{this.#t.enqueue(async()=>{this.#n++,this.#s++;try{r.signal?.throwIfAborted();let i=e({signal:r.signal});r.timeout&&(i=wr(Promise.resolve(i),{milliseconds:r.timeout})),r.signal&&(i=Promise.race([i,this.#v(r.signal)]));let s=await i;n(s),this.emit("completed",s)}catch(i){if(i instanceof $e&&!r.throwOnTimeout){n();return}o(i),this.emit("error",i)}finally{this.#T()}},r),this.emit("add"),this.#f()})}async addAll(e,r){return Promise.all(e.map(async n=>this.add(n,r)))}start(){return this.#i?(this.#i=!1,this.#d(),this):this}pause(){this.#i=!0}clear(){this.#t=new this.#m}async onEmpty(){this.#t.size!==0&&await this.#l("empty")}async onSizeLessThan(e){this.#t.size<e||await this.#l("next",()=>this.#t.size<e)}async onIdle(){this.#n===0&&this.#t.size===0||await this.#l("idle")}async#l(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.#n}get isPaused(){return this.#i}};var Ge=class{async*export(e,r){for(let[,n]of r.links())yield n}};var qe=class{target;constructor(e){this.target=e}isTarget(e){return this.target.equals(e)}async*traverse(e,r){for(let[,n]of r.links())yield n}};var Et=class{components;log;constructor(e,r){this.components=e,this.log=e.logger.forComponent("helia:car")}async import(e,r){await Bo(this.components.blockstore.putMany(Do(e.blocks(),({cid:n,bytes:o})=>({cid:n,block:o})),r))}async export(e,r,n){let o=mr(),i=Array.isArray(e)?e:[e],s={currentPath:[],pathsToTarget:null},c=n?.traversal,u=n?.exporter??new Ge,l=new Ve({concurrency:1}),m=!1;l.on("idle",()=>{if(m)o.resolve();else if(!m&&s.pathsToTarget?.length===i.length){this.log.trace("starting export of blocks to the car file"),m=!0;for(let h of s.pathsToTarget){let I=h.length-1,b=h[I];h.slice(0,-1).forEach(g=>{l.add(async()=>{await this.#o({cid:g,queue:l,writer:r,strategy:u,options:n,recursive:!1})}).catch(k=>{this.log.error("error during queue operation - %e",k)})}),l.add(async()=>{await this.#o({cid:b,queue:l,writer:r,strategy:u,options:n})}).catch(g=>{this.log.error("error during queue operation - %e",g)})}}else this.log.trace("no paths to target, skipping export"),o.reject(new Error("Could not traverse to target CID(s)"))}),l.on("error",h=>{l.clear(),o.reject(h)});for(let h of i)l.add(async()=>{this.log.trace("traversing dag from %c",h),await this.#e({cid:h,queue:l,strategy:c??new qe(h),traversalContext:s,parentPath:[],options:n})}).catch(I=>{this.log.error("error during queue operation - %e",I)});try{await o.promise}finally{await r.close()}}async*stream(e,r){let{writer:n,out:o}=Oe.create(e);this.export(e,n,r).catch(i=>{this.log.error("error during streaming export - %e",i)});for await(let i of o)yield i}async#e({cid:e,queue:r,strategy:n,traversalContext:o,parentPath:i,options:s}){let c=[...i,e];if(n.isTarget(e)){o.pathsToTarget=o.pathsToTarget??[],o.pathsToTarget.push([...c]),this.log.trace("found path to target %c",e);return}let u=await this.components.getCodec(e.code),l=await this.components.blockstore.get(e,s),m=pr({bytes:l,cid:e,codec:u});for await(let h of n.traverse(e,m))r.add(async()=>{await this.#e({cid:h,queue:r,strategy:n,traversalContext:o,parentPath:c??[],options:s})}).catch(I=>{this.log.error("error during traversal queue operation - %e",I)})}async#o({cid:e,queue:r,writer:n,strategy:o,options:i,recursive:s=!0}){if(i?.blockFilter?.has(e.multihash.bytes)===!0)return;let c=await this.components.getCodec(e.code),u=await this.components.blockstore.get(e,i);if(i?.blockFilter?.add(e.multihash.bytes),await n.put({cid:e,bytes:u}),s){let l=pr({bytes:u,cid:e,codec:c});for await(let m of o.export(e,l))r.add(async()=>{await this.#o({cid:m,queue:r,writer:n,strategy:o,options:i})}).catch(h=>{this.log.error("error during export queue operation - %e",h)})}}};var Er=class{async*export(e,r){}};var Y=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"};var Tr=class{async*export(e,r){if(e.code!==112&&e.code!==85)throw new Y("Target CID was not UnixFS - use the SubGraphExporter to export arbitrary graphs");for(let[,n]of r.links())yield n}};var kr=class{pathToTarget;target;constructor(e){this.pathToTarget=e,this.target=e[e.length-1]}isTarget(e){return this.target.equals(e)}async*traverse(e,r){let n=this.pathToTarget.indexOf(e);yield this.pathToTarget[n+1]}};var wa=new TextDecoder;function Ar(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 Tt(t,e){let r;[r,e]=Ar(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 Mo(t,e){let r;return[r,e]=Ar(t,e),[r&7,r>>3,e]}function ba(t){let e={},r=t.length,n=0;for(;n<r;){let o,i;if([o,i,n]=Mo(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]=Tt(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]=Tt(t,n),e.Name=wa.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]=Ar(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 Oo(t){let e=t.length,r=0,n,o=!1,i;for(;r<e;){let c,u;if([c,u,r]=Mo(t,r),c!==2)throw new Error(`protobuf: (PBNode) invalid wireType, expected 2, got ${c}`);if(u===1){if(i)throw new Error("protobuf: (PBNode) duplicate Data section");[i,r]=Tt(t,r),n&&(o=!0)}else if(u===2){if(o)throw new Error("protobuf: (PBNode) duplicate Links section");n||(n=[]);let l;[l,r]=Tt(t,r),n.push(ba(l))}else throw new Error(`protobuf: (PBNode) invalid fieldNumber, expected 1 or 2, got ${u}`)}if(r>e)throw new Error("protobuf: (PBNode) unexpected end of data");let s={};return i&&(s.Data=i),s.Links=n||[],s}var pd=new TextEncoder,md=2**32,yd=2**31;var wd=new TextEncoder;function Po(t){return t instanceof ArrayBuffer?new Uint8Array(t,0,t.byteLength):t}function $o(t){let e=Po(t),r=Oo(e),n={};return r.Data&&(n.Data=r.Data),r.Links&&(n.Links=r.Links.map(o=>{let i={};try{i.Hash=x.decode(o.Hash)}catch{}if(!i.Hash)throw new Error("Invalid Hash field found in link, expected CID");return o.Name!==void 0&&(i.Name=o.Name),o.Tsize!==void 0&&(i.Tsize=o.Tsize),i})),n}var Xe=class t extends Error{static name="InvalidTypeError";static code="ERR_INVALID_TYPE";name=t.name;code=t.code;constructor(e="Invalid type"){super(e)}},kt=class t extends Error{static name="InvalidUnixFSMessageError";static code="ERR_INVALID_MESSAGE";name=t.name;code=t.code;constructor(e="Invalid message"){super(e)}};function oe(t=0){return new Uint8Array(t)}var Ea=Math.pow(2,7),Ta=Math.pow(2,14),ka=Math.pow(2,21),Ho=Math.pow(2,28),Vo=Math.pow(2,35),Go=Math.pow(2,42),qo=Math.pow(2,49),S=128,ie=127;function We(t){if(t<Ea)return 1;if(t<Ta)return 2;if(t<ka)return 3;if(t<Ho)return 4;if(t<Vo)return 5;if(t<Go)return 6;if(t<qo)return 7;if(Number.MAX_SAFE_INTEGER!=null&&t>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Xo(t,e,r=0){switch(We(t)){case 8:e[r++]=t&255|S,t/=128;case 7:e[r++]=t&255|S,t/=128;case 6:e[r++]=t&255|S,t/=128;case 5:e[r++]=t&255|S,t/=128;case 4:e[r++]=t&255|S,t>>>=7;case 3:e[r++]=t&255|S,t>>>=7;case 2:e[r++]=t&255|S,t>>>=7;case 1:{e[r++]=t&255,t>>>=7;break}default:throw new Error("unreachable")}return e}function Wo(t,e){let r=t[e],n=0;if(n+=r&ie,r<S||(r=t[e+1],n+=(r&ie)<<7,r<S)||(r=t[e+2],n+=(r&ie)<<14,r<S)||(r=t[e+3],n+=(r&ie)<<21,r<S)||(r=t[e+4],n+=(r&ie)*Ho,r<S)||(r=t[e+5],n+=(r&ie)*Vo,r<S)||(r=t[e+6],n+=(r&ie)*Go,r<S)||(r=t[e+7],n+=(r&ie)*qo,r<S))return n;throw new RangeError("Could not decode varint")}var vr=new Float32Array([-0]),se=new Uint8Array(vr.buffer);function Jo(t,e,r){vr[0]=t,e[r]=se[0],e[r+1]=se[1],e[r+2]=se[2],e[r+3]=se[3]}function Ko(t,e){return se[0]=t[e],se[1]=t[e+1],se[2]=t[e+2],se[3]=t[e+3],vr[0]}var Ir=new Float64Array([-0]),v=new Uint8Array(Ir.buffer);function jo(t,e,r){Ir[0]=t,e[r]=v[0],e[r+1]=v[1],e[r+2]=v[2],e[r+3]=v[3],e[r+4]=v[4],e[r+5]=v[5],e[r+6]=v[6],e[r+7]=v[7]}function Qo(t,e){return v[0]=t[e],v[1]=t[e+1],v[2]=t[e+2],v[3]=t[e+3],v[4]=t[e+4],v[5]=t[e+5],v[6]=t[e+6],v[7]=t[e+7],Ir[0]}var Aa=BigInt(Number.MAX_SAFE_INTEGER),va=BigInt(Number.MIN_SAFE_INTEGER),z=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 de;if(e<Aa&&e>va)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>Yo&&(o=0n,++n>Yo&&(n=0n))),new t(Number(o),Number(n))}static fromNumber(e){if(e===0)return de;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):de}},de=new z(0,0);de.toBigInt=function(){return 0n};de.zzEncode=de.zzDecode=function(){return this};de.length=function(){return 1};var Yo=4294967296n;function Zo(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 ei(t,e,r){if(r-e<1)return"";let o,i=[],s=0,c;for(;e<r;)c=t[e++],c<128?i[s++]=c:c>191&&c<224?i[s++]=(c&31)<<6|t[e++]&63:c>239&&c<365?(c=((c&7)<<18|(t[e++]&63)<<12|(t[e++]&63)<<6|t[e++]&63)-65536,i[s++]=55296+(c>>10),i[s++]=56320+(c&1023)):i[s++]=(c&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 _r(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 H(t,e){return RangeError(`index out of range: ${t.pos} + ${e??1} > ${t.len}`)}function At(t,e){return(t[e-4]|t[e-3]<<8|t[e-2]<<16|t[e-1]<<24)>>>0}var Sr=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,H(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 H(this,4);return At(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw H(this,4);return At(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw H(this,4);let e=Ko(this.buf,this.pos);return this.pos+=4,e}double(){if(this.pos+8>this.len)throw H(this,4);let e=Qo(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 H(this,e);return this.pos+=e,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let e=this.bytes();return ei(e,0,e.length)}skip(e){if(typeof e=="number"){if(this.pos+e>this.len)throw H(this,e);this.pos+=e}else do if(this.pos>=this.len)throw H(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 z(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 H(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 H(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 H(this,8);let e=At(this.buf,this.pos+=4),r=At(this.buf,this.pos+=4);return new z(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=Wo(this.buf,this.pos);return this.pos+=We(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 Nr(t){return new Sr(t instanceof Uint8Array?t:t.subarray())}function Je(t,e,r){let n=Nr(t);return e.decode(n,void 0,r)}var Br={};N(Br,{base10:()=>Ia});var Ia=re({prefix:"9",name:"base10",alphabet:"0123456789"});var Cr={};N(Cr,{base16:()=>_a,base16upper:()=>Sa});var _a=w({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Sa=w({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Dr={};N(Dr,{base2:()=>Na});var Na=w({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Ur={};N(Ur,{base256emoji:()=>za});var ri=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}"),Ba=ri.reduce((t,e,r)=>(t[r]=e,t),[]),Ca=ri.reduce((t,e,r)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return t[n]=r,t},[]);function Da(t){return t.reduce((e,r)=>(e+=Ba[r],e),"")}function Ua(t){let e=[];for(let r of t){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=Ca[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);e.push(o)}return new Uint8Array(e)}var za=we({prefix:"\u{1F680}",name:"base256emoji",encode:Da,decode:Ua});var zr={};N(zr,{base64:()=>La,base64pad:()=>Fa,base64url:()=>Ra,base64urlpad:()=>Ma});var La=w({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Fa=w({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Ra=w({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Ma=w({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Lr={};N(Lr,{base8:()=>Oa});var Oa=w({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Fr={};N(Fr,{identity:()=>Pa});var Pa=we({prefix:"\0",name:"identity",encode:t=>no(t),decode:t=>ro(t)});var Qd=new TextEncoder,Yd=new TextDecoder;var Rr={};N(Rr,{identity:()=>qa});var ni=0,Va="identity",oi=Q;function Ga(t){return ue(ni,oi(t))}var qa={code:ni,name:Va,encode:oi,digest:Ga};var Mr={};N(Mr,{sha256:()=>Xa,sha512:()=>Wa});function ii(t){return async e=>new Uint8Array(await crypto.subtle.digest(t,e))}var Xa=fr({name:"sha2-256",code:18,encode:ii("SHA-256")}),Wa=fr({name:"sha2-512",code:19,encode:ii("SHA-512")});var Or={...Fr,...Dr,...Lr,...Br,...Cr,...qt,...Xt,...Wt,...zr,...Ur},nl={...Mr,...Rr};function ai(t,e,r,n){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:r},decoder:{decode:n}}}var si=ai("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),Pr=ai("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=oe(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}),Ja={utf8:si,"utf-8":si,hex:Or.base16,latin1:Pr,ascii:Pr,binary:Pr,...Or},ci=Ja;function ui(t,e="utf8"){let r=ci[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.decoder.decode(`${r.prefix}${t}`)}function $r(t){let e=t??8192,r=e>>>1,n,o=e;return function(s){if(s<1||s>r)return oe(s);o+s>e&&(n=oe(e),o=0);let c=n.subarray(o,o+=s);return(o&7)!==0&&(o=(o|7)+1),c}}var le=class{fn;len;next;val;constructor(e,r,n){this.fn=e,this.len=r,this.next=void 0,this.val=n}};function Hr(){}var Gr=class{head;tail;len;next;constructor(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}},Ka=$r();function ja(t){return globalThis.Buffer!=null?oe(t):Ka(t)}var je=class{len;head;tail;states;constructor(){this.len=0,this.head=new le(Hr,0,0),this.tail=this.head,this.states=null}_push(e,r,n){return this.tail=this.tail.next=new le(e,r,n),this.len+=r,this}uint32(e){return this.len+=(this.tail=this.tail.next=new qr((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(vt,10,z.fromNumber(e)):this.uint32(e)}sint32(e){return this.uint32((e<<1^e>>31)>>>0)}uint64(e){let r=z.fromBigInt(e);return this._push(vt,r.length(),r)}uint64Number(e){return this._push(Xo,We(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=z.fromBigInt(e).zzEncode();return this._push(vt,r.length(),r)}sint64Number(e){let r=z.fromNumber(e).zzEncode();return this._push(vt,r.length(),r)}sint64String(e){return this.sint64(BigInt(e))}bool(e){return this._push(Vr,1,e?1:0)}fixed32(e){return this._push(Ke,4,e>>>0)}sfixed32(e){return this.fixed32(e)}fixed64(e){let r=z.fromBigInt(e);return this._push(Ke,4,r.lo)._push(Ke,4,r.hi)}fixed64Number(e){let r=z.fromNumber(e);return this._push(Ke,4,r.lo)._push(Ke,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(Jo,4,e)}double(e){return this._push(jo,8,e)}bytes(e){let r=e.length>>>0;return r===0?this._push(Vr,1,0):this.uint32(r)._push(Ya,r,e)}string(e){let r=Zo(e);return r!==0?this.uint32(r)._push(_r,r,e):this._push(Vr,1,0)}fork(){return this.states=new Gr(this),this.head=this.tail=new le(Hr,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 le(Hr,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=ja(this.len),n=0;for(;e!=null;)e.fn(e.val,r,n),n+=e.len,e=e.next;return r}};function Vr(t,e,r){e[r]=t&255}function Qa(t,e,r){for(;t>127;)e[r++]=t&127|128,t>>>=7;e[r]=t}var qr=class extends le{next;constructor(e,r){super(Qa,e,r),this.next=void 0}};function vt(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 Ke(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 Ya(t,e,r){e.set(t,r)}globalThis.Buffer!=null&&(je.prototype.bytes=function(t){let e=t.length>>>0;return this.uint32(e),e>0&&this._push(Za,e,t),this},je.prototype.string=function(t){let e=globalThis.Buffer.byteLength(t);return this.uint32(e),e>0&&this._push(ec,e,t),this});function Za(t,e,r){e.set(t,r)}function ec(t,e,r){t.length<40?_r(t,e,r):e.utf8Write!=null?e.utf8Write(t,r):e.set(ui(t),r)}function Xr(){return new je}function Qe(t,e){let r=Xr();return e.encode(t,r,{lengthDelimited:!1}),r.finish()}var Ae;(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"})(Ae||(Ae={}));function It(t,e,r,n){return{name:t,type:e,encode:r,decode:n}}function Wr(t){function e(o){if(t[o.toString()]==null)throw new Error("Invalid enum value");return t[o]}let r=function(i,s){let c=e(i);s.int32(c)},n=function(i){let s=i.int32();return e(s)};return It("enum",Ae.VARINT,r,n)}function Ye(t,e){return It("message",Ae.LENGTH_DELIMITED,t,e)}var V;(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=()=>Wr(r)}(e=t.DataType||(t.DataType={}));let n;t.codec=()=>(n==null&&(n=Ye((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 c of o.blocksizes)i.uint32(32),i.uint64(c);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),_t.codec().encode(o.mtime,i)),s.lengthDelimited!==!1&&i.ldelim()},(o,i)=>{let s={blocksizes:[]},c=i==null?o.len:o.pos+i;for(;o.pos<c;){let u=o.uint32();switch(u>>>3){case 1:s.Type=t.DataType.codec().decode(o);break;case 2:s.Data=o.bytes();break;case 3:s.filesize=o.uint64();break;case 4:s.blocksizes.push(o.uint64());break;case 5:s.hashType=o.uint64();break;case 6:s.fanout=o.uint64();break;case 7:s.mode=o.uint32();break;case 8:s.mtime=_t.codec().decode(o,o.uint32());break;default:o.skipType(u&7);break}}return s})),n),t.encode=o=>Qe(o,t.codec()),t.decode=o=>Je(o,t.codec())})(V||(V={}));var _t;(function(t){let e;t.codec=()=>(e==null&&(e=Ye((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=>Qe(r,t.codec()),t.decode=r=>Je(r,t.codec())})(_t||(_t={}));var fi;(function(t){let e;t.codec=()=>(e==null&&(e=Ye((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=>Qe(r,t.codec()),t.decode=r=>Je(r,t.codec())})(fi||(fi={}));var di={Raw:"raw",Directory:"directory",File:"file",Metadata:"metadata",Symlink:"symlink",HAMTShard:"hamt-sharded-directory"},tc=["directory","hamt-sharded-directory"],li=parseInt("0644",8),hi=parseInt("0755",8),pi=BigInt(1024),St=class t{static unmarshal(e){let r=V.decode(e);if(r.fanout!=null&&r.fanout>pi)throw new kt(`Fanout size was too large - ${r.fanout} > ${pi}`);let n=new t({type:di[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:c,mode:u}=e;if(r!=null&&!Object.values(di).includes(r))throw new Xe("Type: "+r+" is not valid");this.type=r??"file",this.data=n,this.hashType=i,this.fanout=s,this.blockSizes=o??[],this._originalMode=0,this.mode=u,this.mtime=c}set mode(e){e==null?this._mode=this.isDirectory()?hi:li:this._mode=e&4095}get mode(){return this._mode}isDirectory(){return tc.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=V.DataType.Raw;break;case"directory":e=V.DataType.Directory;break;case"file":e=V.DataType.File;break;case"metadata":e=V.DataType.Metadata;break;case"symlink":e=V.DataType.Symlink;break;case"hamt-sharded-directory":e=V.DataType.HAMTShard;break;default:throw new Xe(`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===li&&!this.isDirectory()&&(n=void 0),n===hi&&this.isDirectory()&&(n=void 0));let o;return this.mtime!=null&&(o={Seconds:this.mtime.secs,FractionalNanoseconds:this.mtime.nsecs}),V.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 Jr=class{path;constructor(e){this.path=e.replace(/^\//,"").split("/")}isTarget(){return this.path.length===0}async*traverse(e,r){if(e.code!==112)throw new Y("Target CID is not UnixFS");let n=this.path.shift();if(n==null)return;let o=$o(r.bytes);if(o.Data==null)throw new Y("Target CID has no UnixFS data in decoded bytes");if(St.unmarshal(o.Data).type==="directory"){let s=o.Links.filter(c=>c.Name===n).pop();if(s==null)throw new Y(`Target CID directory has no link with name ${n}`);yield s.Hash;return}throw new Y("Target CID is not a UnixFS directory")}};function rc(t,e={}){return new Et(t,e)}return bi(nc);})();
|
|
2
|
+
"use strict";var HeliaCar=(()=>{var yi=Object.create;var Ye=Object.defineProperty;var gi=Object.getOwnPropertyDescriptor;var xi=Object.getOwnPropertyNames;var wi=Object.getPrototypeOf,bi=Object.prototype.hasOwnProperty;var Ie=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),_=(t,e)=>{for(var r in e)Ye(t,r,{get:e[r],enumerable:!0})},jr=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of xi(e))!bi.call(t,o)&&o!==r&&Ye(t,o,{get:()=>e[o],enumerable:!(n=gi(e,o))||n.enumerable});return t};var et=(t,e,r)=>(r=t!=null?yi(wi(t)):{},jr(e||!t||!t.__esModule?Ye(r,"default",{value:t,enumerable:!0}):r,t)),Ei=t=>jr(Ye({},"__esModule",{value:!0}),t);var xo=Ie((Su,go)=>{go.exports=Zt;var yo=128,Vs=127,qs=~Vs,Gs=Math.pow(2,31);function Zt(t,e,r){if(Number.MAX_SAFE_INTEGER&&t>Number.MAX_SAFE_INTEGER)throw Zt.bytes=0,new RangeError("Could not encode varint");e=e||[],r=r||0;for(var n=r;t>=Gs;)e[r++]=t&255|yo,t/=128;for(;t&qs;)e[r++]=t&255|yo,t>>>=7;return e[r]=t|0,Zt.bytes=r-n+1,e}});var Eo=Ie((_u,bo)=>{bo.exports=Yt;var Xs=128,wo=127;function Yt(t,n){var r=0,n=n||0,o=0,i=n,s,c=t.length;do{if(i>=c||o>49)throw Yt.bytes=0,new RangeError("Could not decode varint");s=t[i++],r+=o<28?(s&wo)<<o:(s&wo)*Math.pow(2,o),o+=7}while(s>=Xs);return Yt.bytes=i-n,r}});var ko=Ie((Nu,To)=>{var Ws=Math.pow(2,7),Js=Math.pow(2,14),Ks=Math.pow(2,21),js=Math.pow(2,28),Qs=Math.pow(2,35),Zs=Math.pow(2,42),Ys=Math.pow(2,49),ea=Math.pow(2,56),ta=Math.pow(2,63);To.exports=function(t){return t<Ws?1:t<Js?2:t<Ks?3:t<js?4:t<Qs?5:t<Zs?6:t<Ys?7:t<ea?8:t<ta?9:10}});var mt=Ie((Bu,vo)=>{vo.exports={encode:xo(),decode:Eo(),encodingLength:ko()}});var Ro=Ie((Zf,gr)=>{"use strict";var Ea=Object.prototype.hasOwnProperty,A="~";function Pe(){}Object.create&&(Pe.prototype=Object.create(null),new Pe().__proto__||(A=!1));function Ta(t,e,r){this.fn=t,this.context=e,this.once=r||!1}function Fo(t,e,r,n,o){if(typeof r!="function")throw new TypeError("The listener must be a function");var i=new Ta(r,n||t,o),s=A?A+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 wt(t,e){--t._eventsCount===0?t._events=new Pe:delete t._events[e]}function v(){this._events=new Pe,this._eventsCount=0}v.prototype.eventNames=function(){var e=[],r,n;if(this._eventsCount===0)return e;for(n in r=this._events)Ea.call(r,n)&&e.push(A?n.slice(1):n);return Object.getOwnPropertySymbols?e.concat(Object.getOwnPropertySymbols(r)):e};v.prototype.listeners=function(e){var r=A?A+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};v.prototype.listenerCount=function(e){var r=A?A+e:e,n=this._events[r];return n?n.fn?1:n.length:0};v.prototype.emit=function(e,r,n,o,i,s){var c=A?A+e:e;if(!this._events[c])return!1;var u=this._events[c],h=arguments.length,p,m;if(u.fn){switch(u.once&&this.removeListener(e,u.fn,void 0,!0),h){case 1:return u.fn.call(u.context),!0;case 2:return u.fn.call(u.context,r),!0;case 3:return u.fn.call(u.context,r,n),!0;case 4:return u.fn.call(u.context,r,n,o),!0;case 5:return u.fn.call(u.context,r,n,o,i),!0;case 6:return u.fn.call(u.context,r,n,o,i,s),!0}for(m=1,p=new Array(h-1);m<h;m++)p[m-1]=arguments[m];u.fn.apply(u.context,p)}else{var b=u.length,L;for(m=0;m<b;m++)switch(u[m].once&&this.removeListener(e,u[m].fn,void 0,!0),h){case 1:u[m].fn.call(u[m].context);break;case 2:u[m].fn.call(u[m].context,r);break;case 3:u[m].fn.call(u[m].context,r,n);break;case 4:u[m].fn.call(u[m].context,r,n,o);break;default:if(!p)for(L=1,p=new Array(h-1);L<h;L++)p[L-1]=arguments[L];u[m].fn.apply(u[m].context,p)}}return!0};v.prototype.on=function(e,r,n){return Fo(this,e,r,n,!1)};v.prototype.once=function(e,r,n){return Fo(this,e,r,n,!0)};v.prototype.removeListener=function(e,r,n,o){var i=A?A+e:e;if(!this._events[i])return this;if(!r)return wt(this,i),this;var s=this._events[i];if(s.fn)s.fn===r&&(!o||s.once)&&(!n||s.context===n)&&wt(this,i);else{for(var c=0,u=[],h=s.length;c<h;c++)(s[c].fn!==r||o&&!s[c].once||n&&s[c].context!==n)&&u.push(s[c]);u.length?this._events[i]=u.length===1?u[0]:u:wt(this,i)}return this};v.prototype.removeAllListeners=function(e){var r;return e?(r=A?A+e:e,this._events[r]&&wt(this,r)):(this._events=new Pe,this._eventsCount=0),this};v.prototype.off=v.prototype.removeListener;v.prototype.addListener=v.prototype.on;v.prefixed=A;v.EventEmitter=v;typeof gr<"u"&&(gr.exports=v)});var cc={};_(cc,{BlockExporter:()=>Tr,CIDPath:()=>vr,GraphSearch:()=>qe,SubgraphExporter:()=>Ve,UnixFSExporter:()=>kr,UnixFSPath:()=>Kr,car:()=>ac});var Ti=["string","number","bigint","symbol"],ki=["Function","Generator","AsyncGenerator","GeneratorFunction","AsyncGeneratorFunction","AsyncFunction","Observable","Array","Buffer","Object","RegExp","Date","Error","Map","Set","WeakMap","WeakSet","ArrayBuffer","SharedArrayBuffer","DataView","Promise","URL","HTMLElement","Int8Array","Uint8Array","Uint8ClampedArray","Int16Array","Uint16Array","Int32Array","Uint32Array","Float32Array","Float64Array","BigInt64Array","BigUint64Array"];function Qr(t){if(t===null)return"null";if(t===void 0)return"undefined";if(t===!0||t===!1)return"boolean";let e=typeof t;if(Ti.includes(e))return e;if(e==="function")return"Function";if(Array.isArray(t))return"Array";if(vi(t))return"Buffer";let r=Ii(t);return r||"Object"}function vi(t){return t&&t.constructor&&t.constructor.isBuffer&&t.constructor.isBuffer.call(null,t)}function Ii(t){let e=Object.prototype.toString.call(t).slice(8,-1);if(ki.includes(e))return e}var a=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}};a.uint=new a(0,"uint",!0);a.negint=new a(1,"negint",!0);a.bytes=new a(2,"bytes",!0);a.string=new a(3,"string",!0);a.array=new a(4,"array",!1);a.map=new a(5,"map",!1);a.tag=new a(6,"tag",!1);a.float=new a(7,"float",!0);a.false=new a(7,"false",!0);a.true=new a(7,"true",!0);a.null=new a(7,"null",!0);a.undefined=new a(7,"undefined",!0);a.break=new a(7,"break",!0);var d=class{constructor(e,r,n){this.type=e,this.value=r,this.encodedLength=n,this.encodedBytes=void 0,this.byteValue=void 0}toString(){return`Token[${this.type}].${this.value}`}};var he=globalThis.process&&!globalThis.process.browser&&globalThis.Buffer&&typeof globalThis.Buffer.isBuffer=="function",Ai=new TextDecoder,Si=new TextEncoder;function tt(t){return he&&globalThis.Buffer.isBuffer(t)}function _t(t){return t instanceof Uint8Array?tt(t)?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):t:Uint8Array.from(t)}var tn=he?(t,e,r)=>r-e>64?globalThis.Buffer.from(t.subarray(e,r)).toString("utf8"):Yr(t,e,r):(t,e,r)=>r-e>64?Ai.decode(t.subarray(e,r)):Yr(t,e,r),rn=he?t=>t.length>64?globalThis.Buffer.from(t):Zr(t):t=>t.length>64?Si.encode(t):Zr(t),W=t=>Uint8Array.from(t),le=he?(t,e,r)=>tt(t)?new Uint8Array(t.subarray(e,r)):t.slice(e,r):(t,e,r)=>t.slice(e,r),nn=he?(t,e)=>(t=t.map(r=>r instanceof Uint8Array?r:globalThis.Buffer.from(r)),_t(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},on=he?t=>globalThis.Buffer.allocUnsafe(t):t=>new Uint8Array(t);function sn(t,e){if(tt(t)&&tt(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 Zr(t){let e=[],r=0;for(let n=0;n<t.length;n++){let o=t.charCodeAt(n);o<128?e[r++]=o:o<2048?(e[r++]=o>>6|192,e[r++]=o&63|128):(o&64512)===55296&&n+1<t.length&&(t.charCodeAt(n+1)&64512)===56320?(o=65536+((o&1023)<<10)+(t.charCodeAt(++n)&1023),e[r++]=o>>18|240,e[r++]=o>>12&63|128,e[r++]=o>>6&63|128,e[r++]=o&63|128):(e[r++]=o>>12|224,e[r++]=o>>6&63|128,e[r++]=o&63|128)}return e}function Yr(t,e,r){let n=[];for(;e<r;){let o=t[e],i=null,s=o>239?4:o>223?3:o>191?2:1;if(e+s<=r){let c,u,h,p;switch(s){case 1:o<128&&(i=o);break;case 2:c=t[e+1],(c&192)===128&&(p=(o&31)<<6|c&63,p>127&&(i=p));break;case 3:c=t[e+1],u=t[e+2],(c&192)===128&&(u&192)===128&&(p=(o&15)<<12|(c&63)<<6|u&63,p>2047&&(p<55296||p>57343)&&(i=p));break;case 4:c=t[e+1],u=t[e+2],h=t[e+3],(c&192)===128&&(u&192)===128&&(h&192)===128&&(p=(o&15)<<18|(c&63)<<12|(u&63)<<6|h&63,p>65535&&p<1114112&&(i=p))}}i===null?(i=65533,s=1):i>65535&&(i-=65536,n.push(i>>>10&1023|55296),i=56320|i&1023),n.push(i),e+=s}return _i(n)}var en=4096;function _i(t){let e=t.length;if(e<=en)return String.fromCharCode.apply(String,t);let r="",n=0;for(;n<e;)r+=String.fromCharCode.apply(String,t.slice(n,n+=en));return r}var Ni=256,Ae=class{constructor(e=Ni){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=on(this.chunkSize),this.chunks.push(r),this.maxCursor+=r.length,this._initReuseChunk===null&&(this._initReuseChunk=r),r.set(e,0)):(this.chunks.push(e),this.maxCursor+=e.length)}this.cursor+=e.length}toBytes(e=!1){let r;if(this.chunks.length===1){let n=this.chunks[0];e&&this.cursor>n.length/2?(r=this.cursor===n.length?n:n.subarray(0,this.cursor),this._initReuseChunk=null,this.chunks=[]):r=le(n,0,this.cursor)}else r=nn(this.chunks,this.cursor);return e&&this.reset(),r}};var l="CBOR decode error:",Nt="CBOR encode error:",Se=[];Se[23]=1;Se[24]=2;Se[25]=3;Se[26]=5;Se[27]=9;function Q(t,e,r){if(t.length-e<r)throw new Error(`${l} not enough data for type`)}var E=[24,256,65536,4294967296,BigInt("18446744073709551616")];function N(t,e,r){Q(t,e,1);let n=t[e];if(r.strict===!0&&n<E[0])throw new Error(`${l} integer encoded in more bytes than necessary (strict decode)`);return n}function B(t,e,r){Q(t,e,2);let n=t[e]<<8|t[e+1];if(r.strict===!0&&n<E[1])throw new Error(`${l} integer encoded in more bytes than necessary (strict decode)`);return n}function C(t,e,r){Q(t,e,4);let n=t[e]*16777216+(t[e+1]<<16)+(t[e+2]<<8)+t[e+3];if(r.strict===!0&&n<E[2])throw new Error(`${l} integer encoded in more bytes than necessary (strict decode)`);return n}function D(t,e,r){Q(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<E[3])throw new Error(`${l} 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(`${l} integers outside of the safe integer range are not supported`)}function an(t,e,r,n){return new d(a.uint,N(t,e+1,n),2)}function cn(t,e,r,n){return new d(a.uint,B(t,e+1,n),3)}function un(t,e,r,n){return new d(a.uint,C(t,e+1,n),5)}function fn(t,e,r,n){return new d(a.uint,D(t,e+1,n),9)}function F(t,e){return T(t,0,e.value)}function T(t,e,r){if(r<E[0]){let n=Number(r);t.push([e|n])}else if(r<E[1]){let n=Number(r);t.push([e|24,n])}else if(r<E[2]){let n=Number(r);t.push([e|25,n>>>8,n&255])}else if(r<E[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<E[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(`${l} encountered BigInt larger than allowable range`)}}F.encodedSize=function(e){return T.encodedSize(e.value)};T.encodedSize=function(e){return e<E[0]?1:e<E[1]?2:e<E[2]?3:e<E[3]?5:9};F.compareTokens=function(e,r){return e.value<r.value?-1:e.value>r.value?1:0};function dn(t,e,r,n){return new d(a.negint,-1-N(t,e+1,n),2)}function hn(t,e,r,n){return new d(a.negint,-1-B(t,e+1,n),3)}function ln(t,e,r,n){return new d(a.negint,-1-C(t,e+1,n),5)}var Bt=BigInt(-1),pn=BigInt(1);function mn(t,e,r,n){let o=D(t,e+1,n);if(typeof o!="bigint"){let i=-1-o;if(i>=Number.MIN_SAFE_INTEGER)return new d(a.negint,i,9)}if(n.allowBigInt!==!0)throw new Error(`${l} integers outside of the safe integer range are not supported`);return new d(a.negint,Bt-BigInt(o),9)}function rt(t,e){let r=e.value,n=typeof r=="bigint"?r*Bt-pn:r*-1-1;T(t,e.type.majorEncoded,n)}rt.encodedSize=function(e){let r=e.value,n=typeof r=="bigint"?r*Bt-pn:r*-1-1;return n<E[0]?1:n<E[1]?2:n<E[2]?3:n<E[3]?5:9};rt.compareTokens=function(e,r){return e.value<r.value?1:e.value>r.value?-1:0};function _e(t,e,r,n){Q(t,e,r+n);let o=le(t,e+r,e+r+n);return new d(a.bytes,o,r+n)}function yn(t,e,r,n){return _e(t,e,1,r)}function gn(t,e,r,n){return _e(t,e,2,N(t,e+1,n))}function xn(t,e,r,n){return _e(t,e,3,B(t,e+1,n))}function wn(t,e,r,n){return _e(t,e,5,C(t,e+1,n))}function bn(t,e,r,n){let o=D(t,e+1,n);if(typeof o=="bigint")throw new Error(`${l} 64-bit integer bytes lengths not supported`);return _e(t,e,9,o)}function nt(t){return t.encodedBytes===void 0&&(t.encodedBytes=t.type===a.string?rn(t.value):t.value),t.encodedBytes}function pe(t,e){let r=nt(e);T(t,e.type.majorEncoded,r.length),t.push(r)}pe.encodedSize=function(e){let r=nt(e);return T.encodedSize(r.length)+r.length};pe.compareTokens=function(e,r){return Ci(nt(e),nt(r))};function Ci(t,e){return t.length<e.length?-1:t.length>e.length?1:sn(t,e)}function Ne(t,e,r,n,o){let i=r+n;Q(t,e,i);let s=new d(a.string,tn(t,e+r,e+i),i);return o.retainStringBytes===!0&&(s.byteValue=le(t,e+r,e+i)),s}function En(t,e,r,n){return Ne(t,e,1,r,n)}function Tn(t,e,r,n){return Ne(t,e,2,N(t,e+1,n),n)}function kn(t,e,r,n){return Ne(t,e,3,B(t,e+1,n),n)}function vn(t,e,r,n){return Ne(t,e,5,C(t,e+1,n),n)}function In(t,e,r,n){let o=D(t,e+1,n);if(typeof o=="bigint")throw new Error(`${l} 64-bit integer string lengths not supported`);return Ne(t,e,9,o,n)}var An=pe;function me(t,e,r,n){return new d(a.array,n,r)}function Sn(t,e,r,n){return me(t,e,1,r)}function _n(t,e,r,n){return me(t,e,2,N(t,e+1,n))}function Nn(t,e,r,n){return me(t,e,3,B(t,e+1,n))}function Bn(t,e,r,n){return me(t,e,5,C(t,e+1,n))}function Cn(t,e,r,n){let o=D(t,e+1,n);if(typeof o=="bigint")throw new Error(`${l} 64-bit integer array lengths not supported`);return me(t,e,9,o)}function Dn(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${l} indefinite length items not allowed`);return me(t,e,1,1/0)}function ot(t,e){T(t,a.array.majorEncoded,e.value)}ot.compareTokens=F.compareTokens;ot.encodedSize=function(e){return T.encodedSize(e.value)};function ye(t,e,r,n){return new d(a.map,n,r)}function Un(t,e,r,n){return ye(t,e,1,r)}function Ln(t,e,r,n){return ye(t,e,2,N(t,e+1,n))}function zn(t,e,r,n){return ye(t,e,3,B(t,e+1,n))}function Fn(t,e,r,n){return ye(t,e,5,C(t,e+1,n))}function Rn(t,e,r,n){let o=D(t,e+1,n);if(typeof o=="bigint")throw new Error(`${l} 64-bit integer map lengths not supported`);return ye(t,e,9,o)}function Mn(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${l} indefinite length items not allowed`);return ye(t,e,1,1/0)}function it(t,e){T(t,a.map.majorEncoded,e.value)}it.compareTokens=F.compareTokens;it.encodedSize=function(e){return T.encodedSize(e.value)};function On(t,e,r,n){return new d(a.tag,r,1)}function Pn(t,e,r,n){return new d(a.tag,N(t,e+1,n),2)}function $n(t,e,r,n){return new d(a.tag,B(t,e+1,n),3)}function Hn(t,e,r,n){return new d(a.tag,C(t,e+1,n),5)}function Vn(t,e,r,n){return new d(a.tag,D(t,e+1,n),9)}function st(t,e){T(t,a.tag.majorEncoded,e.value)}st.compareTokens=F.compareTokens;st.encodedSize=function(e){return T.encodedSize(e.value)};var Ri=20,Mi=21,Oi=22,Pi=23;function qn(t,e,r,n){if(n.allowUndefined===!1)throw new Error(`${l} undefined values are not supported`);return n.coerceUndefinedToNull===!0?new d(a.null,null,1):new d(a.undefined,void 0,1)}function Gn(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${l} indefinite length items not allowed`);return new d(a.break,void 0,1)}function Ct(t,e,r){if(r){if(r.allowNaN===!1&&Number.isNaN(t))throw new Error(`${l} NaN values are not supported`);if(r.allowInfinity===!1&&(t===1/0||t===-1/0))throw new Error(`${l} Infinity values are not supported`)}return new d(a.float,t,e)}function Xn(t,e,r,n){return Ct(Dt(t,e+1),3,n)}function Wn(t,e,r,n){return Ct(Ut(t,e+1),5,n)}function Jn(t,e,r,n){return Ct(Zn(t,e+1),9,n)}function at(t,e,r){let n=e.value;if(n===!1)t.push([a.float.majorEncoded|Ri]);else if(n===!0)t.push([a.float.majorEncoded|Mi]);else if(n===null)t.push([a.float.majorEncoded|Oi]);else if(n===void 0)t.push([a.float.majorEncoded|Pi]);else{let o,i=!1;(!r||r.float64!==!0)&&(jn(n),o=Dt(P,1),n===o||Number.isNaN(n)?(P[0]=249,t.push(P.slice(0,3)),i=!0):(Qn(n),o=Ut(P,1),n===o&&(P[0]=250,t.push(P.slice(0,5)),i=!0))),i||($i(n),o=Zn(P,1),P[0]=251,t.push(P.slice(0,9)))}}at.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){jn(n);let o=Dt(P,1);if(n===o||Number.isNaN(n))return 3;if(Qn(n),o=Ut(P,1),n===o)return 5}return 9};var Kn=new ArrayBuffer(9),R=new DataView(Kn,1),P=new Uint8Array(Kn,0);function jn(t){if(t===1/0)R.setUint16(0,31744,!1);else if(t===-1/0)R.setUint16(0,64512,!1);else if(Number.isNaN(t))R.setUint16(0,32256,!1);else{R.setFloat32(0,t);let e=R.getUint32(0),r=(e&2139095040)>>23,n=e&8388607;if(r===255)R.setUint16(0,31744,!1);else if(r===0)R.setUint16(0,(t&2147483648)>>16|n>>13,!1);else{let o=r-127;o<-24?R.setUint16(0,0):o<-14?R.setUint16(0,(e&2147483648)>>16|1<<24+o,!1):R.setUint16(0,(e&2147483648)>>16|o+15<<10|n>>13,!1)}}}function Dt(t,e){if(t.length-e<2)throw new Error(`${l} 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 Qn(t){R.setFloat32(0,t,!1)}function Ut(t,e){if(t.length-e<4)throw new Error(`${l} not enough data for float32`);let r=(t.byteOffset||0)+e;return new DataView(t.buffer,r,4).getFloat32(0,!1)}function $i(t){R.setFloat64(0,t,!1)}function Zn(t,e){if(t.length-e<8)throw new Error(`${l} not enough data for float64`);let r=(t.byteOffset||0)+e;return new DataView(t.buffer,r,8).getFloat64(0,!1)}at.compareTokens=F.compareTokens;function y(t,e,r){throw new Error(`${l} encountered invalid minor (${r}) for major ${t[e]>>>5}`)}function ct(t){return()=>{throw new Error(`${l} ${t}`)}}var f=[];for(let t=0;t<=23;t++)f[t]=y;f[24]=an;f[25]=cn;f[26]=un;f[27]=fn;f[28]=y;f[29]=y;f[30]=y;f[31]=y;for(let t=32;t<=55;t++)f[t]=y;f[56]=dn;f[57]=hn;f[58]=ln;f[59]=mn;f[60]=y;f[61]=y;f[62]=y;f[63]=y;for(let t=64;t<=87;t++)f[t]=yn;f[88]=gn;f[89]=xn;f[90]=wn;f[91]=bn;f[92]=y;f[93]=y;f[94]=y;f[95]=ct("indefinite length bytes/strings are not supported");for(let t=96;t<=119;t++)f[t]=En;f[120]=Tn;f[121]=kn;f[122]=vn;f[123]=In;f[124]=y;f[125]=y;f[126]=y;f[127]=ct("indefinite length bytes/strings are not supported");for(let t=128;t<=151;t++)f[t]=Sn;f[152]=_n;f[153]=Nn;f[154]=Bn;f[155]=Cn;f[156]=y;f[157]=y;f[158]=y;f[159]=Dn;for(let t=160;t<=183;t++)f[t]=Un;f[184]=Ln;f[185]=zn;f[186]=Fn;f[187]=Rn;f[188]=y;f[189]=y;f[190]=y;f[191]=Mn;for(let t=192;t<=215;t++)f[t]=On;f[216]=Pn;f[217]=$n;f[218]=Hn;f[219]=Vn;f[220]=y;f[221]=y;f[222]=y;f[223]=y;for(let t=224;t<=243;t++)f[t]=ct("simple values are not supported");f[244]=y;f[245]=y;f[246]=y;f[247]=qn;f[248]=ct("simple values are not supported");f[249]=Xn;f[250]=Wn;f[251]=Jn;f[252]=y;f[253]=y;f[254]=y;f[255]=Gn;var $=[];for(let t=0;t<24;t++)$[t]=new d(a.uint,t,1);for(let t=-1;t>=-24;t--)$[31-t]=new d(a.negint,t,1);$[64]=new d(a.bytes,new Uint8Array(0),1);$[96]=new d(a.string,"",1);$[128]=new d(a.array,0,1);$[160]=new d(a.map,0,1);$[244]=new d(a.false,!1,1);$[245]=new d(a.true,!0,1);$[246]=new d(a.null,null,1);function Lt(t){switch(t.type){case a.false:return W([244]);case a.true:return W([245]);case a.null:return W([246]);case a.bytes:return t.value.length?void 0:W([64]);case a.string:return t.value===""?W([96]):void 0;case a.array:return t.value===0?W([128]):void 0;case a.map:return t.value===0?W([160]):void 0;case a.uint:return t.value<24?W([Number(t.value)]):void 0;case a.negint:if(t.value>=-24)return W([31-Number(t.value)])}}var Vi={float64:!1,mapSorter:Gi,quickEncodeToken:Lt};function Ft(){let t=[];return t[a.uint.major]=F,t[a.negint.major]=rt,t[a.bytes.major]=pe,t[a.string.major]=An,t[a.array.major]=ot,t[a.map.major]=it,t[a.tag.major]=st,t[a.float.major]=at,t}var Yn=Ft(),zt=new Ae,ut=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(`${Nt} object contains circular references`);return new t(r,e)}},te={null:new d(a.null,null),undefined:new d(a.undefined,void 0),true:new d(a.true,!0),false:new d(a.false,!1),emptyArray:new d(a.array,0),emptyMap:new d(a.map,0)},re={number(t,e,r,n){return!Number.isInteger(t)||!Number.isSafeInteger(t)?new d(a.float,t):t>=0?new d(a.uint,t):new d(a.negint,t)},bigint(t,e,r,n){return t>=BigInt(0)?new d(a.uint,t):new d(a.negint,t)},Uint8Array(t,e,r,n){return new d(a.bytes,t)},string(t,e,r,n){return new d(a.string,t)},boolean(t,e,r,n){return t?te.true:te.false},null(t,e,r,n){return te.null},undefined(t,e,r,n){return te.undefined},ArrayBuffer(t,e,r,n){return new d(a.bytes,new Uint8Array(t))},DataView(t,e,r,n){return new d(a.bytes,new Uint8Array(t.buffer,t.byteOffset,t.byteLength))},Array(t,e,r,n){if(!t.length)return r.addBreakTokens===!0?[te.emptyArray,new d(a.break)]:te.emptyArray;n=ut.createCheck(n,t);let o=[],i=0;for(let s of t)o[i++]=Be(s,r,n);return r.addBreakTokens?[new d(a.array,t.length),o,new d(a.break)]:[new d(a.array,t.length),o]},Object(t,e,r,n){let o=e!=="Object",i=o?t.keys():Object.keys(t),s=o?t.size:i.length;if(!s)return r.addBreakTokens===!0?[te.emptyMap,new d(a.break)]:te.emptyMap;n=ut.createCheck(n,t);let c=[],u=0;for(let h of i)c[u++]=[Be(h,r,n),Be(o?t.get(h):t[h],r,n)];return qi(c,r),r.addBreakTokens?[new d(a.map,s),c,new d(a.break)]:[new d(a.map,s),c]}};re.Map=re.Object;re.Buffer=re.Uint8Array;for(let t of"Uint8Clamped Uint16 Uint32 Int8 Int16 Int32 BigUint64 BigInt64 Float32 Float64".split(" "))re[`${t}Array`]=re.DataView;function Be(t,e={},r){let n=Qr(t),o=e&&e.typeEncoders&&e.typeEncoders[n]||re[n];if(typeof o=="function"){let s=o(t,n,e,r);if(s!=null)return s}let i=re[n];if(!i)throw new Error(`${Nt} unsupported type: ${n}`);return i(t,n,e,r)}function qi(t,e){e.mapSorter&&t.sort(e.mapSorter)}function Gi(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=Yn[o].compareTokens(r,n);return i===0&&console.warn("WARNING: complex key types used, CBOR key sorting guarantees are gone"),i}function eo(t,e,r,n){if(Array.isArray(e))for(let o of e)eo(t,o,r,n);else r[e.type.major](t,e,n)}function Xi(t,e,r){let n=Be(t,r);if(!Array.isArray(n)&&r.quickEncodeToken){let o=r.quickEncodeToken(n);if(o)return o;let i=e[n.type.major];if(i.encodedSize){let s=i.encodedSize(n,r),c=new Ae(s);if(i(c,n,r),c.chunks.length!==1)throw new Error(`Unexpected error: pre-calculated length for ${n} was wrong`);return _t(c.chunks[0])}}return zt.reset(),eo(zt,n,e,r),zt.toBytes(!0)}function Rt(t,e){return e=Object.assign({},Vi,e),Xi(t,Yn,e)}var Wi={strict:!1,allowIndefinite:!0,allowUndefined:!0,allowBigInt:!0},ft=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=$[e];if(r===void 0){let n=f[e];if(!n)throw new Error(`${l} 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}},Ce=Symbol.for("DONE"),dt=Symbol.for("BREAK");function Ji(t,e,r){let n=[];for(let o=0;o<t.value;o++){let i=ge(e,r);if(i===dt){if(t.value===1/0)break;throw new Error(`${l} got unexpected break to lengthed array`)}if(i===Ce)throw new Error(`${l} found array but not enough entries (got ${o}, expected ${t.value})`);n[o]=i}return n}function Ki(t,e,r){let n=r.useMaps===!0,o=n?void 0:{},i=n?new Map:void 0;for(let s=0;s<t.value;s++){let c=ge(e,r);if(c===dt){if(t.value===1/0)break;throw new Error(`${l} got unexpected break to lengthed map`)}if(c===Ce)throw new Error(`${l} found map but not enough entries (got ${s} [no key], expected ${t.value})`);if(n!==!0&&typeof c!="string")throw new Error(`${l} non-string keys not supported (got ${typeof c})`);if(r.rejectDuplicateMapKeys===!0&&(n&&i.has(c)||!n&&c in o))throw new Error(`${l} found repeat map key "${c}"`);let u=ge(e,r);if(u===Ce)throw new Error(`${l} found map but not enough entries (got ${s} [no value], expected ${t.value})`);n?i.set(c,u):o[c]=u}return n?i:o}function ge(t,e){if(t.done())return Ce;let r=t.next();if(r.type===a.break)return dt;if(r.type.terminal)return r.value;if(r.type===a.array)return Ji(r,t,e);if(r.type===a.map)return Ki(r,t,e);if(r.type===a.tag){if(e.tags&&typeof e.tags[r.value]=="function"){let n=ge(t,e);return e.tags[r.value](n)}throw new Error(`${l} tag not supported (${r.value})`)}throw new Error("unsupported")}function to(t,e){if(!(t instanceof Uint8Array))throw new Error(`${l} data to decode must be a Uint8Array`);e=Object.assign({},Wi,e);let r=e.tokenizer||new ft(t,e),n=ge(r,e);if(n===Ce)throw new Error(`${l} did not find any content to decode`);if(n===dt)throw new Error(`${l} got unexpected break`);return[n,t.subarray(r.pos())]}function Mt(t,e){let[r,n]=to(t,e);if(n.length>0)throw new Error(`${l} too many terminals, data makes no sense`);return r}var qt={};_(qt,{base32:()=>we,base32hex:()=>ss,base32hexpad:()=>cs,base32hexpadupper:()=>us,base32hexupper:()=>as,base32pad:()=>os,base32padupper:()=>is,base32upper:()=>ns,base32z:()=>fs});var au=new Uint8Array(0);function ro(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 Z(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 no(t){return new TextEncoder().encode(t)}function oo(t){return new TextDecoder().decode(t)}function Qi(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 c=t.length,u=t.charAt(0),h=Math.log(c)/Math.log(256),p=Math.log(256)/Math.log(c);function m(g){if(g instanceof Uint8Array||(ArrayBuffer.isView(g)?g=new Uint8Array(g.buffer,g.byteOffset,g.byteLength):Array.isArray(g)&&(g=Uint8Array.from(g))),!(g instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(g.length===0)return"";for(var k=0,ae=0,M=0,q=g.length;M!==q&&g[M]===0;)M++,k++;for(var G=(q-M)*p+1>>>0,z=new Uint8Array(G);M!==q;){for(var X=g[M],ee=0,O=G-1;(X!==0||ee<ae)&&O!==-1;O--,ee++)X+=256*z[O]>>>0,z[O]=X%c>>>0,X=X/c>>>0;if(X!==0)throw new Error("Non-zero carry");ae=ee,M++}for(var j=G-ae;j!==G&&z[j]===0;)j++;for(var Ze=u.repeat(k);j<G;++j)Ze+=t.charAt(z[j]);return Ze}function b(g){if(typeof g!="string")throw new TypeError("Expected String");if(g.length===0)return new Uint8Array;var k=0;if(g[k]!==" "){for(var ae=0,M=0;g[k]===u;)ae++,k++;for(var q=(g.length-k)*h+1>>>0,G=new Uint8Array(q);g[k];){var z=r[g.charCodeAt(k)];if(z===255)return;for(var X=0,ee=q-1;(z!==0||X<M)&&ee!==-1;ee--,X++)z+=c*G[ee]>>>0,G[ee]=z%256>>>0,z=z/256>>>0;if(z!==0)throw new Error("Non-zero carry");M=X,k++}if(g[k]!==" "){for(var O=q-M;O!==q&&G[O]===0;)O++;for(var j=new Uint8Array(ae+(q-O)),Ze=ae;O!==q;)j[Ze++]=G[O++];return j}}}function L(g){var k=b(g);if(k)return k;throw new Error(`Non-${e} character`)}return{encode:m,decodeUnsafe:b,decode:L}}var Zi=Qi,Yi=Zi,io=Yi;var Pt=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")}},$t=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 so(this,e)}},Ht=class{decoders;constructor(e){this.decoders=e}or(e){return so(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 so(t,e){return new Ht({...t.decoders??{[t.prefix]:t},...e.decoders??{[e.prefix]:e}})}var Vt=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 Pt(e,r,n),this.decoder=new $t(e,r,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function xe({name:t,prefix:e,encode:r,decode:n}){return new Vt(t,e,r,n)}function ne({name:t,prefix:e,alphabet:r}){let{encode:n,decode:o}=io(r,t);return xe({prefix:e,name:t,encode:n,decode:i=>Z(o(i))})}function es(t,e,r,n){let o=t.length;for(;t[o-1]==="=";)--o;let i=new Uint8Array(o*r/8|0),s=0,c=0,u=0;for(let h=0;h<o;++h){let p=e[t[h]];if(p===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<r|p,s+=r,s>=8&&(s-=8,i[u++]=255&c>>s)}if(s>=r||(255&c<<8-s)!==0)throw new SyntaxError("Unexpected end of data");return i}function ts(t,e,r){let n=e[e.length-1]==="=",o=(1<<r)-1,i="",s=0,c=0;for(let u=0;u<t.length;++u)for(c=c<<8|t[u],s+=8;s>r;)s-=r,i+=e[o&c>>s];if(s!==0&&(i+=e[o&c<<r-s]),n)for(;(i.length*r&7)!==0;)i+="=";return i}function rs(t){let e={};for(let r=0;r<t.length;++r)e[t[r]]=r;return e}function w({name:t,prefix:e,bitsPerChar:r,alphabet:n}){let o=rs(n);return xe({prefix:e,name:t,encode(i){return ts(i,n,r)},decode(i){return es(i,o,r,t)}})}var we=w({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),ns=w({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),os=w({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),is=w({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),ss=w({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),as=w({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),cs=w({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),us=w({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),fs=w({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Gt={};_(Gt,{base36:()=>De,base36upper:()=>ds});var De=ne({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),ds=ne({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Xt={};_(Xt,{base58btc:()=>J,base58flickr:()=>hs});var J=ne({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),hs=ne({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var ls=uo,ao=128,ps=127,ms=~ps,ys=Math.pow(2,31);function uo(t,e,r){e=e||[],r=r||0;for(var n=r;t>=ys;)e[r++]=t&255|ao,t/=128;for(;t&ms;)e[r++]=t&255|ao,t>>>=7;return e[r]=t|0,uo.bytes=r-n+1,e}var gs=Wt,xs=128,co=127;function Wt(t,n){var r=0,n=n||0,o=0,i=n,s,c=t.length;do{if(i>=c)throw Wt.bytes=0,new RangeError("Could not decode varint");s=t[i++],r+=o<28?(s&co)<<o:(s&co)*Math.pow(2,o),o+=7}while(s>=xs);return Wt.bytes=i-n,r}var ws=Math.pow(2,7),bs=Math.pow(2,14),Es=Math.pow(2,21),Ts=Math.pow(2,28),ks=Math.pow(2,35),vs=Math.pow(2,42),Is=Math.pow(2,49),As=Math.pow(2,56),Ss=Math.pow(2,63),_s=function(t){return t<ws?1:t<bs?2:t<Es?3:t<Ts?4:t<ks?5:t<vs?6:t<Is?7:t<As?8:t<Ss?9:10},Ns={encode:ls,decode:gs,encodingLength:_s},Bs=Ns,Ue=Bs;function Le(t,e=0){return[Ue.decode(t,e),Ue.decode.bytes]}function be(t,e,r=0){return Ue.encode(t,e,r),e}function Ee(t){return Ue.encodingLength(t)}function ke(t,e){let r=e.byteLength,n=Ee(t),o=n+Ee(r),i=new Uint8Array(o+r);return be(t,i,0),be(r,i,n),i.set(e,o),new Te(t,r,e,i)}function lt(t){let e=Z(t),[r,n]=Le(e),[o,i]=Le(e.subarray(n)),s=e.subarray(n+i);if(s.byteLength!==o)throw new Error("Incorrect length");return new Te(r,o,s,e)}function fo(t,e){if(t===e)return!0;{let r=e;return t.code===r.code&&t.size===r.size&&r.bytes instanceof Uint8Array&&ro(t.bytes,r.bytes)}}var Te=class{code;size;digest;bytes;constructor(e,r,n,o){this.code=e,this.size=r,this.digest=n,this.bytes=o}};function ho(t,e){let{bytes:r,version:n}=t;switch(n){case 0:return Ds(r,Jt(t),e??J.encoder);default:return Us(r,Jt(t),e??we.encoder)}}var lo=new WeakMap;function Jt(t){let e=lo.get(t);if(e==null){let r=new Map;return lo.set(t,r),r}return e}var x=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!==ze)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==Ls)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=ke(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&&fo(e.multihash,n.multihash)}toString(e){return ho(this,e)}toJSON(){return{"/":ho(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??po(n,o,i.bytes))}else if(r[zs]===!0){let{version:n,multihash:o,code:i}=r,s=lt(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!==ze)throw new Error(`Version 0 CID must use dag-pb (code: ${ze}) block encoding`);return new t(e,r,n,n.bytes)}case 1:{let o=po(e,r,n.bytes);return new t(e,r,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return t.create(0,ze,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=Z(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 Te(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[m,b]=Le(e.subarray(r));return r+=b,m},o=n(),i=ze;if(o===18?(o=0,r=0):i=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let s=r,c=n(),u=n(),h=r+u,p=h-s;return{version:o,codec:i,multihashCode:c,digestSize:u,multihashSize:p,size:h}}static parse(e,r){let[n,o]=Cs(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 Jt(i).set(n,e),i}};function Cs(t,e){switch(t[0]){case"Q":{let r=e??J;return[J.prefix,r.decode(`${J.prefix}${t}`)]}case J.prefix:{let r=e??J;return[J.prefix,r.decode(t)]}case we.prefix:{let r=e??we;return[we.prefix,r.decode(t)]}case De.prefix:{let r=e??De;return[De.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 Ds(t,e,r){let{prefix:n}=r;if(n!==J.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 Us(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 ze=112,Ls=18;function po(t,e,r){let n=Ee(t),o=n+Ee(e),i=new Uint8Array(o+r.byteLength);return be(t,i,0),be(e,i,n),i.set(r,o),i}var zs=Symbol.for("@ipld/js-cid/CID");var mo=42;function Fs(t){return t instanceof ArrayBuffer?new Uint8Array(t,0,t.byteLength):t}function Rs(t){if(t.asCID!==t&&t["/"]!==t.bytes)return null;let e=x.asCID(t);if(!e)return null;let r=new Uint8Array(e.bytes.byteLength+1);return r.set(e.bytes,1),[new d(a.tag,mo),new d(a.bytes,r)]}function Ms(){throw new Error("`undefined` is not supported by the IPLD Data Model and cannot be encoded")}function Os(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 Ps(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 Kt={float64:!0,typeEncoders:{Map:Ps,Object:Rs,undefined:Ms,number:Os}},Iu={...Kt,typeEncoders:{...Kt.typeEncoders}};function $s(t){if(t[0]!==0)throw new Error("Invalid CID for CBOR tag 42; expected leading 0x00");return x.decode(t.subarray(1))}var pt={allowIndefinite:!1,coerceUndefinedToNull:!0,allowNaN:!1,allowInfinity:!1,allowBigInt:!0,strict:!0,useMaps:!1,rejectDuplicateMapKeys:!0,tags:[]};pt.tags[mo]=$s;var Au={...pt,tags:pt.tags.slice()};var jt=t=>Rt(t,Kt),Qt=t=>Mt(Fs(t),pt);var er=et(mt(),1);var tr=40;function rr(t,e){if(!t.length)throw new Error("Unexpected end of data");let r=er.default.decode(t);return e.seek(er.default.decode.bytes),r}function nr(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 oe={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},Fe={"CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)":oe.Link,"CarV1HeaderOrV2Pragma > roots (anon)":t=>{if(oe.List(t)!==void 0){for(let e=0;e<t.length;e++){let r=t[e];if(r=Fe["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=Fe["CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)"](i),i===void 0)return;n.push(i)}return n}}return t}},Int:oe.Int,CarV1HeaderOrV2Pragma:t=>{if(oe.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 c=Fe["CarV1HeaderOrV2Pragma > roots (anon)"](t[i]);if(c===void 0)return;if(c!==s||r!==t){if(r===t){r={};for(let u=0;u<o;u++)r[e[u][0]]=e[u][1]}r.roots=c}}break;case"version":{n--;let c=Fe.Int(t[i]);if(c===void 0)return;if(c!==s||r!==t){if(r===t){r={};for(let u=0;u<o;u++)r[e[u][0]]=e[u][1]}r.version=c}}break;default:return}}if(!(n>0))return r}},Re={"CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)":oe.Link,"CarV1HeaderOrV2Pragma > roots (anon)":t=>{if(oe.List(t)!==void 0){for(let e=0;e<t.length;e++){let r=t[e];if(r=Re["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=Re["CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)"](i),i===void 0)return;n.push(i)}return n}}return t}},Int:oe.Int,CarV1HeaderOrV2Pragma:t=>{if(oe.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 c=Re["CarV1HeaderOrV2Pragma > roots (anon)"](s);if(c===void 0)return;if(c!==s||r!==t){if(r===t){r={};for(let u=0;u<o;u++)r[e[u][0]]=e[u][1]}r.roots=c}}break;case"version":{n--;let c=Re.Int(s);if(c===void 0)return;if(c!==s||r!==t){if(r===t){r={};for(let u=0;u<o;u++)r[e[u][0]]=e[u][1]}r.version=c}}break;default:return}}if(!(n>0))return r}},or={toTyped:Fe.CarV1HeaderOrV2Pragma,toRepresentation:Re.CarV1HeaderOrV2Pragma};var $u=Ft();var ia=et(mt(),1);var Xu=[new d(a.map,2),new d(a.string,"version"),new d(a.uint,1),new d(a.string,"roots")],Wu=new d(a.tag,42);async function ir(t,e){let r=rr(await t.upTo(8),t);if(r===0)throw new Error("Invalid CAR header (zero length)");let n=await t.exactly(r,!0),o=Qt(n);if(or.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=nr(await t.exactly(tr,!0));t.seek(i.dataOffset-t.pos);let s=await ir(t,1);return Object.assign(s,i)}function Me(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 sr=et(mt(),1),So=1;function ar(t){let e=jt({version:So,roots:t}),r=sr.default.encode(e.length),n=new Uint8Array(r.length+e.length);return n.set(r,0),n.set(e,r.length),n}function _o(t){return{async setRoots(e){let r=ar(e);await t.write(r)},async writeBlock(e){let{cid:r,bytes:n}=e;await t.write(new Uint8Array(sr.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 So}}}function yt(){}function No(){let t=[],e=null,r=yt,n=!1,o=null,i=yt,s=()=>(e||(e=new Promise(h=>{r=()=>{e=null,r=yt,h()}})),e),c={write(h){t.push(h);let p=s();return i(),p},async end(){n=!0;let h=s();i(),await h}},u={async next(){let h=t.shift();return h?(t.length===0&&r(),{done:!1,value:h}):n?(r(),{done:!0,value:void 0}):(o||(o=new Promise(p=>{i=()=>(o=null,i=yt,p(u.next()))})),o)}};return{writer:c,iterator:u}}var Oe=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=x.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=ua(e);let{encoder:r,iterator:n}=Bo(),o=new t(e,r),i=new gt(n);return{writer:o,out:i}}static createAppender(){let{encoder:e,iterator:r}=Bo();e.setRoots=()=>Promise.resolve();let n=new t([],e),o=new gt(r);return{writer:n,out:o}}static async updateRootsInBytes(e,r){let n=Me(e);await ir(n);let o=ar(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}},gt=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 Bo(){let t=No(),{writer:e,iterator:r}=t;return{encoder:_o(e),iterator:r}}function ua(t){if(t===void 0)return[];if(!Array.isArray(t)){let r=x.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=x.asCID(r);if(!n)throw new TypeError("roots must be a single CID or an array of CIDs");e.push(n)}return e}function fa(t){return t[Symbol.asyncIterator]!=null}function da(t){if(fa(t))return(async()=>{for await(let e of t);})();for(let e of t);}var Co=da;function ha(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 Do=ha;function la(t){return t[Symbol.asyncIterator]!=null}function pa(t,e){let r=0;if(la(t))return(async function*(){for await(let u of t)yield e(u,r++)})();let n=Do(t),{value:o,done:i}=n.next();if(i===!0)return(function*(){})();let s=e(o,r++);if(typeof s.then=="function")return(async function*(){yield await s;for(let u of n)yield e(u,r++)})();let c=e;return(function*(){yield s;for(let u of n)yield c(u,r++)})()}var Uo=pa;function K(t=0){return new Uint8Array(t)}function cr(t,e){e==null&&(e=t.reduce((o,i)=>o+i.length,0));let r=K(e),n=0;for(let o of t)r.set(o,n),n+=o.length;return r}function ma(t){return t[Symbol.asyncIterator]!=null}function ya(t){if(ma(t))return(async()=>{let n=new Uint8Array(0);for await(let o of t)n=cr([n,o],n.length+o.length);return n})();let e=[],r=0;for(let n of t)e.push(n),r+=n.byteLength;return cr(e,r)}var ur=ya;var ga=20;function dr({name:t,code:e,encode:r,minDigestLength:n,maxDigestLength:o}){return new fr(t,e,r,n,o)}var fr=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,r,n,o,i){this.name=e,this.code=r,this.encode=n,this.minDigestLength=o??ga,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?Lo(n,this.code,r?.truncate):n.then(o=>Lo(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function Lo(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 ke(e,t)}function xt({enumerable:t=!0,configurable:e=!1}={}){return{enumerable:t,configurable:e,writable:!1}}function*xa(t,e){if(e!=null&&typeof e=="object")if(Array.isArray(e))for(let[r,n]of e.entries()){let o=[...t,r],i=x.asCID(n);i!=null?yield[o.join("/"),i]:typeof n=="object"&&(yield*hr(n,o))}else{let r=x.asCID(e);r!=null?yield[t.join("/"),r]:yield*hr(e,t)}}function*hr(t,e){if(t==null||t instanceof Uint8Array)return;let r=x.asCID(t);r!=null&&(yield[e.join("/"),r]);for(let[n,o]of Object.entries(t)){let i=[...e,n];yield*xa(i,o)}}function*wa(t,e){if(Array.isArray(e))for(let[r,n]of e.entries()){let o=[...t,r];yield o.join("/"),typeof n=="object"&&x.asCID(n)==null&&(yield*lr(n,o))}else yield*lr(e,t)}function*lr(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"&&x.asCID(n)==null&&(yield*wa(o,n))}}function ba(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=x.asCID(r);if(i!=null)return{value:i,remaining:e.slice(n+1).join("/")}}return{value:r}}var pr=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:xt(),bytes:xt(),value:xt(),asBlock:xt()})}links(){return hr(this.value,[])}tree(){return lr(this.value,[])}get(e="/"){return ba(this.value,e.split("/").filter(Boolean))}};function mr({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 pr({cid:e,bytes:t,value:o})}function yr(){let t={};return t.promise=new Promise((e,r)=>{t.resolve=e,t.reject=r}),t}var xr=et(Ro(),1);var wr=class t extends Error{name="TimeoutError";constructor(e,r){super(e,r),Error.captureStackTrace?.(this,t)}},Mo=t=>t.reason??new DOMException("This operation was aborted.","AbortError");function br(t,e){let{milliseconds:r,fallback:n,message:o,customTimers:i={setTimeout,clearTimeout},signal:s}=e,c,u,p=new Promise((m,b)=>{if(typeof r!="number"||Math.sign(r)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${r}\``);if(s?.aborted){b(Mo(s));return}if(s&&(u=()=>{b(Mo(s))},s.addEventListener("abort",u,{once:!0})),t.then(m,b),r===Number.POSITIVE_INFINITY)return;let L=new wr;c=i.setTimeout(()=>{if(n){try{m(n())}catch(g){b(g)}return}typeof t.cancel=="function"&&t.cancel(),o===!1?m():o instanceof Error?b(o):(L.message=o??`Promise timed out after ${r} milliseconds`,b(L))},r)}).finally(()=>{p.clear(),u&&s&&s.removeEventListener("abort",u)});return p.clear=()=>{i.clearTimeout(c),c=void 0},p}function Er(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 $e=class{#t=[];enqueue(e,r){let{priority:n=0,id:o}=r??{},i={priority:n,id:o,run:e};if(this.size===0||this.#t[this.size-1].priority>=n){this.#t.push(i);return}let s=Er(this.#t,i,(c,u)=>u.priority-c.priority);this.#t.splice(s,0,i)}setPriority(e,r){let n=this.#t.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.#t.splice(n,1);this.enqueue(o.run,{priority:r,id:e})}dequeue(){return this.#t.shift()?.run}filter(e){return this.#t.filter(r=>r.priority===e.priority).map(r=>r.run)}get size(){return this.#t.length}};var He=class extends xr.default{#t;#n;#o=0;#l;#p=!1;#m=!1;#u;#w=0;#y=0;#i;#s;#e;#b;#r=0;#f;#a;#A=1n;#d=new Map;timeout;constructor(e){if(super(),e={carryoverIntervalCount:!1,intervalCap:Number.POSITIVE_INFINITY,interval:0,concurrency:Number.POSITIVE_INFINITY,autoStart:!0,queueClass:$e,...e},!(typeof e.intervalCap=="number"&&e.intervalCap>=1))throw new TypeError(`Expected \`intervalCap\` to be a number from 1 and up, got \`${e.intervalCap?.toString()??""}\` (${typeof e.intervalCap})`);if(e.interval===void 0||!(Number.isFinite(e.interval)&&e.interval>=0))throw new TypeError(`Expected \`interval\` to be a finite number >= 0, got \`${e.interval?.toString()??""}\` (${typeof e.interval})`);if(this.#t=e.carryoverIntervalCount??e.carryoverConcurrencyCount??!1,this.#n=e.intervalCap===Number.POSITIVE_INFINITY||e.interval===0,this.#l=e.intervalCap,this.#u=e.interval,this.#e=new e.queueClass,this.#b=e.queueClass,this.concurrency=e.concurrency,e.timeout!==void 0&&!(Number.isFinite(e.timeout)&&e.timeout>0))throw new TypeError(`Expected \`timeout\` to be a positive finite number, got \`${e.timeout}\` (${typeof e.timeout})`);this.timeout=e.timeout,this.#a=e.autoStart===!1,this.#L()}get#S(){return this.#n||this.#o<this.#l}get#_(){return this.#r<this.#f}#N(){this.#r--,this.#r===0&&this.emit("pendingZero"),this.#g(),this.emit("next")}#B(){this.#v(),this.#k(),this.#s=void 0}get#C(){let e=Date.now();if(this.#i===void 0){let r=this.#w-e;if(r<0){if(this.#y>0){let n=e-this.#y;if(n<this.#u)return this.#E(this.#u-n),!0}this.#o=this.#t?this.#r:0}else return this.#E(r),!0}return!1}#E(e){this.#s===void 0&&(this.#s=setTimeout(()=>{this.#B()},e))}#T(){this.#i&&(clearInterval(this.#i),this.#i=void 0)}#D(){this.#s&&(clearTimeout(this.#s),this.#s=void 0)}#g(){if(this.#e.size===0)return this.#T(),this.emit("empty"),this.#r===0&&(this.#D(),this.emit("idle")),!1;let e=!1;if(!this.#a){let r=!this.#C;if(this.#S&&this.#_){let n=this.#e.dequeue();this.#n||(this.#o++,this.#h()),this.emit("active"),this.#y=Date.now(),n(),r&&this.#k(),e=!0}}return e}#k(){this.#n||this.#i!==void 0||(this.#i=setInterval(()=>{this.#v()},this.#u),this.#w=Date.now()+this.#u)}#v(){this.#o===0&&this.#r===0&&this.#i&&this.#T(),this.#o=this.#t?this.#r:0,this.#x(),this.#h()}#x(){for(;this.#g(););}get concurrency(){return this.#f}set concurrency(e){if(!(typeof e=="number"&&e>=1))throw new TypeError(`Expected \`concurrency\` to be a number from 1 and up, got \`${e}\` (${typeof e})`);this.#f=e,this.#x()}async#U(e){return new Promise((r,n)=>{e.addEventListener("abort",()=>{n(e.reason)},{once:!0})})}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.#e.setPriority(e,r)}async add(e,r={}){return r.id??=(this.#A++).toString(),r={timeout:this.timeout,...r},new Promise((n,o)=>{let i=Symbol(`task-${r.id}`);this.#e.enqueue(async()=>{this.#r++,this.#d.set(i,{id:r.id,priority:r.priority??0,startTime:Date.now(),timeout:r.timeout});try{try{r.signal?.throwIfAborted()}catch(u){throw this.#n||this.#o--,this.#d.delete(i),u}let s=e({signal:r.signal});r.timeout&&(s=br(Promise.resolve(s),{milliseconds:r.timeout,message:`Task timed out after ${r.timeout}ms (queue has ${this.#r} running, ${this.#e.size} waiting)`})),r.signal&&(s=Promise.race([s,this.#U(r.signal)]));let c=await s;n(c),this.emit("completed",c)}catch(s){o(s),this.emit("error",s)}finally{this.#d.delete(i),queueMicrotask(()=>{this.#N()})}},r),this.emit("add"),this.#g()})}async addAll(e,r){return Promise.all(e.map(async n=>this.add(n,r)))}start(){return this.#a?(this.#a=!1,this.#x(),this):this}pause(){this.#a=!0}clear(){this.#e=new this.#b,this.#I()}async onEmpty(){this.#e.size!==0&&await this.#c("empty")}async onSizeLessThan(e){this.#e.size<e||await this.#c("next",()=>this.#e.size<e)}async onIdle(){this.#r===0&&this.#e.size===0||await this.#c("idle")}async onPendingZero(){this.#r!==0&&await this.#c("pendingZero")}async onRateLimit(){this.isRateLimited||await this.#c("rateLimit")}async onRateLimitCleared(){this.isRateLimited&&await this.#c("rateLimitCleared")}async onError(){return new Promise((e,r)=>{let n=o=>{this.off("error",n),r(o)};this.on("error",n)})}async#c(e,r){return new Promise(n=>{let o=()=>{r&&!r()||(this.off(e,o),n())};this.on(e,o)})}get size(){return this.#e.size}sizeBy(e){return this.#e.filter(e).length}get pending(){return this.#r}get isPaused(){return this.#a}#L(){this.#n||(this.on("add",()=>{this.#e.size>0&&this.#h()}),this.on("next",()=>{this.#h()}))}#h(){this.#n||this.#m||(this.#m=!0,queueMicrotask(()=>{this.#m=!1,this.#I()}))}#I(){let e=this.#p,r=!this.#n&&this.#o>=this.#l&&this.#e.size>0;r!==e&&(this.#p=r,this.emit(r?"rateLimit":"rateLimitCleared"))}get isRateLimited(){return this.#p}get isSaturated(){return this.#r===this.#f&&this.#e.size>0||this.isRateLimited&&this.#e.size>0}get runningTasks(){return[...this.#d.values()].map(e=>({...e}))}};var Ve=class{async*export(e,r){for(let[,n]of r.links())yield n}};var qe=class{target;constructor(e){this.target=e}isTarget(e){return this.target.equals(e)}async*traverse(e,r){for(let[,n]of r.links())yield n}};var bt=class{components;log;constructor(e,r){this.components=e,this.log=e.logger.forComponent("helia:car")}async import(e,r){await Co(this.components.blockstore.putMany(Uo(e.blocks(),({cid:n,bytes:o})=>({cid:n,bytes:o})),r))}async export(e,r,n){let o=yr(),i=Array.isArray(e)?e:[e],s={currentPath:[],pathsToTarget:null},c=n?.traversal,u=n?.exporter??new Ve,h=new He({concurrency:1}),p=!1;h.on("idle",()=>{if(p)o.resolve();else if(!p&&s.pathsToTarget?.length===i.length){this.log.trace("starting export of blocks to the car file"),p=!0;for(let m of s.pathsToTarget){let b=m.length-1,L=m[b];m.slice(0,-1).forEach(g=>{h.add(async()=>{await this.#n({cid:g,queue:h,writer:r,strategy:u,options:n,recursive:!1})}).catch(k=>{this.log.error("error during queue operation - %e",k)})}),h.add(async()=>{await this.#n({cid:L,queue:h,writer:r,strategy:u,options:n})}).catch(g=>{this.log.error("error during queue operation - %e",g)})}}else this.log.trace("no paths to target, skipping export"),o.reject(new Error("Could not traverse to target CID(s)"))}),h.on("error",m=>{h.clear(),o.reject(m)});for(let m of i)h.add(async()=>{this.log.trace("traversing dag from %c",m),await this.#t({cid:m,queue:h,strategy:c??new qe(m),traversalContext:s,parentPath:[],options:n})}).catch(b=>{this.log.error("error during queue operation - %e",b)});try{await o.promise}finally{await r.close()}}async*stream(e,r){let{writer:n,out:o}=Oe.create(e);this.export(e,n,r).catch(i=>{this.log.error("error during streaming export - %e",i)});for await(let i of o)yield i}async#t({cid:e,queue:r,strategy:n,traversalContext:o,parentPath:i,options:s}){let c=[...i,e];if(n.isTarget(e)){o.pathsToTarget=o.pathsToTarget??[],o.pathsToTarget.push([...c]),this.log.trace("found path to target %c",e);return}let u=await this.components.getCodec(e.code),h=await ur(this.components.blockstore.get(e,s)),p=mr({bytes:h,cid:e,codec:u});for await(let m of n.traverse(e,p))r.add(async()=>{await this.#t({cid:m,queue:r,strategy:n,traversalContext:o,parentPath:c??[],options:s})}).catch(b=>{this.log.error("error during traversal queue operation - %e",b)})}async#n({cid:e,queue:r,writer:n,strategy:o,options:i,recursive:s=!0}){if(i?.blockFilter?.has(e.multihash.bytes)===!0)return;let c=await this.components.getCodec(e.code),u=await ur(this.components.blockstore.get(e,i));if(i?.blockFilter?.add(e.multihash.bytes),await n.put({cid:e,bytes:u}),s){let h=mr({bytes:u,cid:e,codec:c});for await(let p of o.export(e,h))r.add(async()=>{await this.#n({cid:p,queue:r,writer:n,strategy:o,options:i})}).catch(m=>{this.log.error("error during export queue operation - %e",m)})}}};var Tr=class{async*export(e,r){}};var Y=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"};var kr=class{async*export(e,r){if(e.code!==112&&e.code!==85)throw new Y("Target CID was not UnixFS - use the SubGraphExporter to export arbitrary graphs");for(let[,n]of r.links())yield n}};var vr=class{pathToTarget;target;constructor(e){this.pathToTarget=e,this.target=e[e.length-1]}isTarget(e){return this.target.equals(e)}async*traverse(e,r){let n=this.pathToTarget.indexOf(e);yield this.pathToTarget[n+1]}};var va=new TextDecoder;function Ir(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 Et(t,e){let r;[r,e]=Ir(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 Oo(t,e){let r;return[r,e]=Ir(t,e),[r&7,r>>3,e]}function Ia(t){let e={},r=t.length,n=0;for(;n<r;){let o,i;if([o,i,n]=Oo(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]=Et(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]=Et(t,n),e.Name=va.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]=Ir(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 Po(t){let e=t.length,r=0,n,o=!1,i;for(;r<e;){let c,u;if([c,u,r]=Oo(t,r),c!==2)throw new Error(`protobuf: (PBNode) invalid wireType, expected 2, got ${c}`);if(u===1){if(i)throw new Error("protobuf: (PBNode) duplicate Data section");[i,r]=Et(t,r),n&&(o=!0)}else if(u===2){if(o)throw new Error("protobuf: (PBNode) duplicate Links section");n||(n=[]);let h;[h,r]=Et(t,r),n.push(Ia(h))}else throw new Error(`protobuf: (PBNode) invalid fieldNumber, expected 1 or 2, got ${u}`)}if(r>e)throw new Error("protobuf: (PBNode) unexpected end of data");let s={};return i&&(s.Data=i),s.Links=n||[],s}var _d=new TextEncoder,Nd=2**32,Bd=2**31;var Ud=new TextEncoder;function $o(t){return t instanceof ArrayBuffer?new Uint8Array(t,0,t.byteLength):t}function Ho(t){let e=$o(t),r=Po(e),n={};return r.Data&&(n.Data=r.Data),r.Links&&(n.Links=r.Links.map(o=>{let i={};try{i.Hash=x.decode(o.Hash)}catch{}if(!i.Hash)throw new Error("Invalid Hash field found in link, expected CID");return o.Name!==void 0&&(i.Name=o.Name),o.Tsize!==void 0&&(i.Tsize=o.Tsize),i})),n}var Ge=class t extends Error{static name="InvalidTypeError";static code="ERR_INVALID_TYPE";name=t.name;code=t.code;constructor(e="Invalid type"){super(e)}},Tt=class t extends Error{static name="InvalidUnixFSMessageError";static code="ERR_INVALID_MESSAGE";name=t.name;code=t.code;constructor(e="Invalid message"){super(e)}};var Aa=Math.pow(2,7),Sa=Math.pow(2,14),_a=Math.pow(2,21),Vo=Math.pow(2,28),qo=Math.pow(2,35),Go=Math.pow(2,42),Xo=Math.pow(2,49),S=128,ie=127;function Xe(t){if(t<Aa)return 1;if(t<Sa)return 2;if(t<_a)return 3;if(t<Vo)return 4;if(t<qo)return 5;if(t<Go)return 6;if(t<Xo)return 7;if(Number.MAX_SAFE_INTEGER!=null&&t>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Wo(t,e,r=0){switch(Xe(t)){case 8:e[r++]=t&255|S,t/=128;case 7:e[r++]=t&255|S,t/=128;case 6:e[r++]=t&255|S,t/=128;case 5:e[r++]=t&255|S,t/=128;case 4:e[r++]=t&255|S,t>>>=7;case 3:e[r++]=t&255|S,t>>>=7;case 2:e[r++]=t&255|S,t>>>=7;case 1:{e[r++]=t&255,t>>>=7;break}default:throw new Error("unreachable")}return e}function Jo(t,e){let r=t[e],n=0;if(n+=r&ie,r<S||(r=t[e+1],n+=(r&ie)<<7,r<S)||(r=t[e+2],n+=(r&ie)<<14,r<S)||(r=t[e+3],n+=(r&ie)<<21,r<S)||(r=t[e+4],n+=(r&ie)*Vo,r<S)||(r=t[e+5],n+=(r&ie)*qo,r<S)||(r=t[e+6],n+=(r&ie)*Go,r<S)||(r=t[e+7],n+=(r&ie)*Xo,r<S))return n;throw new RangeError("Could not decode varint")}var Ar=new Float32Array([-0]),se=new Uint8Array(Ar.buffer);function Ko(t,e,r){Ar[0]=t,e[r]=se[0],e[r+1]=se[1],e[r+2]=se[2],e[r+3]=se[3]}function jo(t,e){return se[0]=t[e],se[1]=t[e+1],se[2]=t[e+2],se[3]=t[e+3],Ar[0]}var Sr=new Float64Array([-0]),I=new Uint8Array(Sr.buffer);function Qo(t,e,r){Sr[0]=t,e[r]=I[0],e[r+1]=I[1],e[r+2]=I[2],e[r+3]=I[3],e[r+4]=I[4],e[r+5]=I[5],e[r+6]=I[6],e[r+7]=I[7]}function Zo(t,e){return I[0]=t[e],I[1]=t[e+1],I[2]=t[e+2],I[3]=t[e+3],I[4]=t[e+4],I[5]=t[e+5],I[6]=t[e+6],I[7]=t[e+7],Sr[0]}var Na=BigInt(Number.MAX_SAFE_INTEGER),Ba=BigInt(Number.MIN_SAFE_INTEGER),U=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 fe;if(e<Na&&e>Ba)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>Yo&&(o=0n,++n>Yo&&(n=0n))),new t(Number(o),Number(n))}static fromNumber(e){if(e===0)return fe;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):fe}},fe=new U(0,0);fe.toBigInt=function(){return 0n};fe.zzEncode=fe.zzDecode=function(){return this};fe.length=function(){return 1};var Yo=4294967296n;function ei(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 ti(t,e,r){if(r-e<1)return"";let o,i=[],s=0,c;for(;e<r;)c=t[e++],c<128?i[s++]=c:c>191&&c<224?i[s++]=(c&31)<<6|t[e++]&63:c>239&&c<365?(c=((c&7)<<18|(t[e++]&63)<<12|(t[e++]&63)<<6|t[e++]&63)-65536,i[s++]=55296+(c>>10),i[s++]=56320+(c&1023)):i[s++]=(c&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 _r(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 H(t,e){return RangeError(`index out of range: ${t.pos} + ${e??1} > ${t.len}`)}function kt(t,e){return(t[e-4]|t[e-3]<<8|t[e-2]<<16|t[e-1]<<24)>>>0}var Nr=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,H(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 H(this,4);return kt(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw H(this,4);return kt(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw H(this,4);let e=jo(this.buf,this.pos);return this.pos+=4,e}double(){if(this.pos+8>this.len)throw H(this,4);let e=Zo(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 H(this,e);return this.pos+=e,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let e=this.bytes();return ti(e,0,e.length)}skip(e){if(typeof e=="number"){if(this.pos+e>this.len)throw H(this,e);this.pos+=e}else do if(this.pos>=this.len)throw H(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 U(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 H(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 H(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 H(this,8);let e=kt(this.buf,this.pos+=4),r=kt(this.buf,this.pos+=4);return new U(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=Jo(this.buf,this.pos);return this.pos+=Xe(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 Br(t){return new Nr(t instanceof Uint8Array?t:t.subarray())}function We(t,e,r){let n=Br(t);return e.decode(n,void 0,r)}var Cr={};_(Cr,{base10:()=>Ca});var Ca=ne({prefix:"9",name:"base10",alphabet:"0123456789"});var Dr={};_(Dr,{base16:()=>Da,base16upper:()=>Ua});var Da=w({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Ua=w({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Ur={};_(Ur,{base2:()=>La});var La=w({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Lr={};_(Lr,{base256emoji:()=>Oa});var ni=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}"),za=ni.reduce((t,e,r)=>(t[r]=e,t),[]),Fa=ni.reduce((t,e,r)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return t[n]=r,t},[]);function Ra(t){return t.reduce((e,r)=>(e+=za[r],e),"")}function Ma(t){let e=[];for(let r of t){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=Fa[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);e.push(o)}return new Uint8Array(e)}var Oa=xe({prefix:"\u{1F680}",name:"base256emoji",encode:Ra,decode:Ma});var zr={};_(zr,{base64:()=>Pa,base64pad:()=>$a,base64url:()=>Ha,base64urlpad:()=>Va});var Pa=w({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),$a=w({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Ha=w({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Va=w({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Fr={};_(Fr,{base8:()=>qa});var qa=w({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Rr={};_(Rr,{identity:()=>Ga});var Ga=xe({prefix:"\0",name:"identity",encode:t=>oo(t),decode:t=>no(t)});var fh=new TextEncoder,dh=new TextDecoder;var Mr={};_(Mr,{identity:()=>ja});var oi=0,Ja="identity",ii=Z;function Ka(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 ke(oi,ii(t))}var ja={code:oi,name:Ja,encode:ii,digest:Ka};var Or={};_(Or,{sha256:()=>Qa,sha512:()=>Za});function si(t){return async e=>new Uint8Array(await crypto.subtle.digest(t,e))}var Qa=dr({name:"sha2-256",code:18,encode:si("SHA-256")}),Za=dr({name:"sha2-512",code:19,encode:si("SHA-512")});var Pr={...Rr,...Ur,...Fr,...Cr,...Dr,...qt,...Gt,...Xt,...zr,...Lr},yh={...Or,...Mr};function ci(t,e,r,n){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:r},decoder:{decode:n}}}var ai=ci("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),$r=ci("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=K(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}),Ya={utf8:ai,"utf-8":ai,hex:Pr.base16,latin1:$r,ascii:$r,binary:$r,...Pr},ui=Ya;function fi(t,e="utf8"){let r=ui[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.decoder.decode(`${r.prefix}${t}`)}function Hr(t){let e=t??8192,r=e>>>1,n,o=e;return function(s){if(s<1||s>r)return K(s);o+s>e&&(n=K(e),o=0);let c=n.subarray(o,o+=s);return(o&7)!==0&&(o=(o|7)+1),c}}var de=class{fn;len;next;val;constructor(e,r,n){this.fn=e,this.len=r,this.next=void 0,this.val=n}};function Vr(){}var Gr=class{head;tail;len;next;constructor(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}},ec=Hr();function tc(t){return globalThis.Buffer!=null?K(t):ec(t)}var Ke=class{len;head;tail;states;constructor(){this.len=0,this.head=new de(Vr,0,0),this.tail=this.head,this.states=null}_push(e,r,n){return this.tail=this.tail.next=new de(e,r,n),this.len+=r,this}uint32(e){return this.len+=(this.tail=this.tail.next=new Xr((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(vt,10,U.fromNumber(e)):this.uint32(e)}sint32(e){return this.uint32((e<<1^e>>31)>>>0)}uint64(e){let r=U.fromBigInt(e);return this._push(vt,r.length(),r)}uint64Number(e){return this._push(Wo,Xe(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=U.fromBigInt(e).zzEncode();return this._push(vt,r.length(),r)}sint64Number(e){let r=U.fromNumber(e).zzEncode();return this._push(vt,r.length(),r)}sint64String(e){return this.sint64(BigInt(e))}bool(e){return this._push(qr,1,e?1:0)}fixed32(e){return this._push(Je,4,e>>>0)}sfixed32(e){return this.fixed32(e)}fixed64(e){let r=U.fromBigInt(e);return this._push(Je,4,r.lo)._push(Je,4,r.hi)}fixed64Number(e){let r=U.fromNumber(e);return this._push(Je,4,r.lo)._push(Je,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(Ko,4,e)}double(e){return this._push(Qo,8,e)}bytes(e){let r=e.length>>>0;return r===0?this._push(qr,1,0):this.uint32(r)._push(nc,r,e)}string(e){let r=ei(e);return r!==0?this.uint32(r)._push(_r,r,e):this._push(qr,1,0)}fork(){return this.states=new Gr(this),this.head=this.tail=new de(Vr,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 de(Vr,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=tc(this.len),n=0;for(;e!=null;)e.fn(e.val,r,n),n+=e.len,e=e.next;return r}};function qr(t,e,r){e[r]=t&255}function rc(t,e,r){for(;t>127;)e[r++]=t&127|128,t>>>=7;e[r]=t}var Xr=class extends de{next;constructor(e,r){super(rc,e,r),this.next=void 0}};function vt(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 Je(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 nc(t,e,r){e.set(t,r)}globalThis.Buffer!=null&&(Ke.prototype.bytes=function(t){let e=t.length>>>0;return this.uint32(e),e>0&&this._push(oc,e,t),this},Ke.prototype.string=function(t){let e=globalThis.Buffer.byteLength(t);return this.uint32(e),e>0&&this._push(ic,e,t),this});function oc(t,e,r){e.set(t,r)}function ic(t,e,r){t.length<40?_r(t,e,r):e.utf8Write!=null?e.utf8Write(t,r):e.set(fi(t),r)}function Wr(){return new Ke}function je(t,e){let r=Wr();return e.encode(t,r,{lengthDelimited:!1}),r.finish()}var ve;(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"})(ve||(ve={}));function It(t,e,r,n){return{name:t,type:e,encode:r,decode:n}}function Jr(t){function e(o){if(t[o.toString()]==null)throw new Error("Invalid enum value");return t[o]}let r=function(i,s){let c=e(i);s.int32(c)},n=function(i){let s=i.int32();return e(s)};return It("enum",ve.VARINT,r,n)}function Qe(t,e){return It("message",ve.LENGTH_DELIMITED,t,e)}var V;(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=()=>Jr(r)})(e=t.DataType||(t.DataType={}));let n;t.codec=()=>(n==null&&(n=Qe((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 c of o.blocksizes)i.uint32(32),i.uint64(c);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),At.codec().encode(o.mtime,i)),s.lengthDelimited!==!1&&i.ldelim()},(o,i)=>{let s={blocksizes:[]},c=i==null?o.len:o.pos+i;for(;o.pos<c;){let u=o.uint32();switch(u>>>3){case 1:s.Type=t.DataType.codec().decode(o);break;case 2:s.Data=o.bytes();break;case 3:s.filesize=o.uint64();break;case 4:s.blocksizes.push(o.uint64());break;case 5:s.hashType=o.uint64();break;case 6:s.fanout=o.uint64();break;case 7:s.mode=o.uint32();break;case 8:s.mtime=At.codec().decode(o,o.uint32());break;default:o.skipType(u&7);break}}return s})),n),t.encode=o=>je(o,t.codec()),t.decode=o=>We(o,t.codec())})(V||(V={}));var At;(function(t){let e;t.codec=()=>(e==null&&(e=Qe((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=>je(r,t.codec()),t.decode=r=>We(r,t.codec())})(At||(At={}));var di;(function(t){let e;t.codec=()=>(e==null&&(e=Qe((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=>je(r,t.codec()),t.decode=r=>We(r,t.codec())})(di||(di={}));var hi={Raw:"raw",Directory:"directory",File:"file",Metadata:"metadata",Symlink:"symlink",HAMTShard:"hamt-sharded-directory"},sc=["directory","hamt-sharded-directory"],li=parseInt("0644",8),pi=parseInt("0755",8),mi=BigInt(1024),St=class t{static unmarshal(e){let r=V.decode(e);if(r.fanout!=null&&r.fanout>mi)throw new Tt(`Fanout size was too large - ${r.fanout} > ${mi}`);let n=new t({type:hi[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:c,mode:u}=e;if(r!=null&&!Object.values(hi).includes(r))throw new Ge("Type: "+r+" is not valid");this.type=r??"file",this.data=n,this.hashType=i,this.fanout=s,this.blockSizes=o??[],this._originalMode=0,this.mode=u,this.mtime=c}set mode(e){e==null?this._mode=this.isDirectory()?pi:li:this._mode=e&4095}get mode(){return this._mode}isDirectory(){return sc.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=V.DataType.Raw;break;case"directory":e=V.DataType.Directory;break;case"file":e=V.DataType.File;break;case"metadata":e=V.DataType.Metadata;break;case"symlink":e=V.DataType.Symlink;break;case"hamt-sharded-directory":e=V.DataType.HAMTShard;break;default:throw new Ge(`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===li&&!this.isDirectory()&&(n=void 0),n===pi&&this.isDirectory()&&(n=void 0));let o;return this.mtime!=null&&(o={Seconds:this.mtime.secs,FractionalNanoseconds:this.mtime.nsecs}),V.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 Kr=class{path;constructor(e){this.path=e.replace(/^\//,"").split("/")}isTarget(){return this.path.length===0}async*traverse(e,r){if(e.code!==112)throw new Y("Target CID is not UnixFS");let n=this.path.shift();if(n==null)return;let o=Ho(r.bytes);if(o.Data==null)throw new Y("Target CID has no UnixFS data in decoded bytes");if(St.unmarshal(o.Data).type==="directory"){let s=o.Links.filter(c=>c.Name===n).pop();if(s==null)throw new Y(`Target CID directory has no link with name ${n}`);yield s.Hash;return}throw new Y("Target CID is not a UnixFS directory")}};function ac(t,e={}){return new bt(t,e)}return Ei(cc);})();
|
|
3
3
|
return HeliaCar}));
|
|
4
4
|
//# sourceMappingURL=index.min.js.map
|