@helia/car 4.2.0 → 5.0.0
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/README.md +2 -2
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +4 -4
- package/dist/src/car.d.ts +2 -3
- package/dist/src/car.d.ts.map +1 -1
- package/dist/src/car.js +42 -25
- package/dist/src/car.js.map +1 -1
- package/dist/src/index.d.ts +6 -37
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +2 -2
- package/dist/src/index.js.map +1 -1
- package/package.json +25 -33
- package/src/car.ts +49 -29
- package/src/index.ts +6 -38
package/README.md
CHANGED
|
@@ -52,7 +52,7 @@ const cid = CID.parse('QmFoo...')
|
|
|
52
52
|
const c = car(helia)
|
|
53
53
|
const out = nodeFs.createWriteStream('example.car')
|
|
54
54
|
|
|
55
|
-
for await (const buf of c.
|
|
55
|
+
for await (const buf of c.export(cid)) {
|
|
56
56
|
out.write(buf)
|
|
57
57
|
}
|
|
58
58
|
|
|
@@ -73,7 +73,7 @@ const cid = CID.parse('QmFoo...')
|
|
|
73
73
|
const c = car(helia)
|
|
74
74
|
const out = nodeFs.createWriteStream('example.car')
|
|
75
75
|
|
|
76
|
-
for await (const buf of c.
|
|
76
|
+
for await (const buf of c.export(cid, {
|
|
77
77
|
traversal: new UnixFSPath('/foo/bar/baz.txt')
|
|
78
78
|
})) {
|
|
79
79
|
out.write(buf)
|
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 bi=Object.create;var Ke=Object.defineProperty;var Ei=Object.getOwnPropertyDescriptor;var Ti=Object.getOwnPropertyNames;var Ii=Object.getPrototypeOf,vi=Object.prototype.hasOwnProperty;var Je=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),C=(t,e)=>{for(var r in e)Ke(t,r,{get:e[r],enumerable:!0})},en=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Ti(e))!vi.call(t,o)&&o!==r&&Ke(t,o,{get:()=>e[o],enumerable:!(n=Ei(e,o))||n.enumerable});return t};var Ct=(t,e,r)=>(r=t!=null?bi(Ii(t)):{},en(e||!t||!t.__esModule?Ke(r,"default",{value:t,enumerable:!0}):r,t)),Ai=t=>en(Ke({},"__esModule",{value:!0}),t);var To=Je((Lu,Eo)=>{Eo.exports=nr;var bo=128,Xs=127,Ws=~Xs,Qs=Math.pow(2,31);function nr(t,e,r){if(Number.MAX_SAFE_INTEGER&&t>Number.MAX_SAFE_INTEGER)throw nr.bytes=0,new RangeError("Could not encode varint");e=e||[],r=r||0;for(var n=r;t>=Qs;)e[r++]=t&255|bo,t/=128;for(;t&Ws;)e[r++]=t&255|bo,t>>>=7;return e[r]=t|0,nr.bytes=r-n+1,e}});var Ao=Je((zu,vo)=>{vo.exports=or;var Ks=128,Io=127;function or(t,n){var r=0,n=n||0,o=0,i=n,s,c=t.length;do{if(i>=c||o>49)throw or.bytes=0,new RangeError("Could not decode varint");s=t[i++],r+=o<28?(s&Io)<<o:(s&Io)*Math.pow(2,o),o+=7}while(s>=Ks);return or.bytes=i-n,r}});var So=Je((Mu,ko)=>{var Js=Math.pow(2,7),Ys=Math.pow(2,14),Zs=Math.pow(2,21),ea=Math.pow(2,28),ta=Math.pow(2,35),ra=Math.pow(2,42),na=Math.pow(2,49),oa=Math.pow(2,56),ia=Math.pow(2,63);ko.exports=function(t){return t<Js?1:t<Ys?2:t<Zs?3:t<ea?4:t<ta?5:t<ra?6:t<na?7:t<oa?8:t<ia?9:10}});var lt=Je((Fu,No)=>{No.exports={encode:To(),decode:Ao(),encodingLength:So()}});var mc={};C(mc,{BlockExporter:()=>Qr,CIDPath:()=>Jr,GraphSearch:()=>Xe,SubgraphExporter:()=>je,UnixFSExporter:()=>Kr,UnixFSPath:()=>Zr,car:()=>pc});var ki=["string","number","bigint","symbol"],Si=["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 tn(t){if(t===null)return"null";if(t===void 0)return"undefined";if(t===!0||t===!1)return"boolean";let e=typeof t;if(ki.includes(e))return e;if(e==="function")return"Function";if(Array.isArray(t))return"Array";if(Ni(t))return"Buffer";let r=Di(t);return r||"Object"}function Ni(t){return t&&t.constructor&&t.constructor.isBuffer&&t.constructor.isBuffer.call(null,t)}function Di(t){let e=Object.prototype.toString.call(t).slice(8,-1);if(Si.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 de=globalThis.process&&!globalThis.process.browser&&globalThis.Buffer&&typeof globalThis.Buffer.isBuffer=="function",Bi=new TextDecoder,_i=new TextEncoder;function Ye(t){return de&&globalThis.Buffer.isBuffer(t)}function Ut(t){return t instanceof Uint8Array?Ye(t)?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):t:Uint8Array.from(t)}var sn=de?(t,e,r)=>r-e>64?globalThis.Buffer.from(t.subarray(e,r)).toString("utf8"):nn(t,e,r):(t,e,r)=>r-e>64?Bi.decode(t.subarray(e,r)):nn(t,e,r),an=de?t=>t.length>64?globalThis.Buffer.from(t):rn(t):t=>t.length>64?_i.encode(t):rn(t),j=t=>Uint8Array.from(t),le=de?(t,e,r)=>Ye(t)?new Uint8Array(t.subarray(e,r)):t.slice(e,r):(t,e,r)=>t.slice(e,r),cn=de?(t,e)=>(t=t.map(r=>r instanceof Uint8Array?r:globalThis.Buffer.from(r)),Ut(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},un=de?t=>globalThis.Buffer.allocUnsafe(t):t=>new Uint8Array(t);function fn(t,e){if(Ye(t)&&Ye(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 rn(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 nn(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,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],l=t[e+3],(c&192)===128&&(u&192)===128&&(l&192)===128&&(p=(o&15)<<18|(c&63)<<12|(u&63)<<6|l&63,p>65535&&p<1114112&&(i=p))}}i===null?(i=65533,s=1):i>65535&&(i-=65536,n.push(i>>>10&1023|55296),i=56320|i&1023),n.push(i),e+=s}return Ci(n)}var on=4096;function Ci(t){let e=t.length;if(e<=on)return String.fromCharCode.apply(String,t);let r="",n=0;for(;n<e;)r+=String.fromCharCode.apply(String,t.slice(n,n+=on));return r}var Ui=256,ke=class{constructor(e=Ui){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=un(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=cn(this.chunks,this.cursor);return e&&this.reset(),r}};var h="CBOR decode error:",Lt="CBOR encode error:",Se=[];Se[23]=1;Se[24]=2;Se[25]=3;Se[26]=5;Se[27]=9;function K(t,e,r){if(t.length-e<r)throw new Error(`${h} not enough data for type`)}var A=[24,256,65536,4294967296,BigInt("18446744073709551616")];function U(t,e,r){K(t,e,1);let n=t[e];if(r.strict===!0&&n<A[0])throw new Error(`${h} integer encoded in more bytes than necessary (strict decode)`);return n}function L(t,e,r){K(t,e,2);let n=t[e]<<8|t[e+1];if(r.strict===!0&&n<A[1])throw new Error(`${h} integer encoded in more bytes than necessary (strict decode)`);return n}function z(t,e,r){K(t,e,4);let n=t[e]*16777216+(t[e+1]<<16)+(t[e+2]<<8)+t[e+3];if(r.strict===!0&&n<A[2])throw new Error(`${h} integer encoded in more bytes than necessary (strict decode)`);return n}function M(t,e,r){K(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<A[3])throw new Error(`${h} 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(`${h} integers outside of the safe integer range are not supported`)}function dn(t,e,r,n){return new d(a.uint,U(t,e+1,n),2)}function ln(t,e,r,n){return new d(a.uint,L(t,e+1,n),3)}function hn(t,e,r,n){return new d(a.uint,z(t,e+1,n),5)}function pn(t,e,r,n){return new d(a.uint,M(t,e+1,n),9)}function P(t,e){return S(t,0,e.value)}function S(t,e,r){if(r<A[0]){let n=Number(r);t.push([e|n])}else if(r<A[1]){let n=Number(r);t.push([e|24,n])}else if(r<A[2]){let n=Number(r);t.push([e|25,n>>>8,n&255])}else if(r<A[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<A[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(`${h} encountered BigInt larger than allowable range`)}}P.encodedSize=function(e){return S.encodedSize(e.value)};S.encodedSize=function(e){return e<A[0]?1:e<A[1]?2:e<A[2]?3:e<A[3]?5:9};P.compareTokens=function(e,r){return e.value<r.value?-1:e.value>r.value?1:0};function mn(t,e,r,n){return new d(a.negint,-1-U(t,e+1,n),2)}function yn(t,e,r,n){return new d(a.negint,-1-L(t,e+1,n),3)}function gn(t,e,r,n){return new d(a.negint,-1-z(t,e+1,n),5)}var zt=BigInt(-1),xn=BigInt(1);function wn(t,e,r,n){let o=M(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(`${h} integers outside of the safe integer range are not supported`);return new d(a.negint,zt-BigInt(o),9)}function Ze(t,e){let r=e.value,n=typeof r=="bigint"?r*zt-xn:r*-1-1;S(t,e.type.majorEncoded,n)}Ze.encodedSize=function(e){let r=e.value,n=typeof r=="bigint"?r*zt-xn:r*-1-1;return n<A[0]?1:n<A[1]?2:n<A[2]?3:n<A[3]?5:9};Ze.compareTokens=function(e,r){return e.value<r.value?1:e.value>r.value?-1:0};function Ne(t,e,r,n){K(t,e,r+n);let o=le(t,e+r,e+r+n);return new d(a.bytes,o,r+n)}function bn(t,e,r,n){return Ne(t,e,1,r)}function En(t,e,r,n){return Ne(t,e,2,U(t,e+1,n))}function Tn(t,e,r,n){return Ne(t,e,3,L(t,e+1,n))}function In(t,e,r,n){return Ne(t,e,5,z(t,e+1,n))}function vn(t,e,r,n){let o=M(t,e+1,n);if(typeof o=="bigint")throw new Error(`${h} 64-bit integer bytes lengths not supported`);return Ne(t,e,9,o)}function et(t){return t.encodedBytes===void 0&&(t.encodedBytes=t.type===a.string?an(t.value):t.value),t.encodedBytes}function he(t,e){let r=et(e);S(t,e.type.majorEncoded,r.length),t.push(r)}he.encodedSize=function(e){let r=et(e);return S.encodedSize(r.length)+r.length};he.compareTokens=function(e,r){return zi(et(e),et(r))};function zi(t,e){return t.length<e.length?-1:t.length>e.length?1:fn(t,e)}function De(t,e,r,n,o){let i=r+n;K(t,e,i);let s=new d(a.string,sn(t,e+r,e+i),i);return o.retainStringBytes===!0&&(s.byteValue=le(t,e+r,e+i)),s}function An(t,e,r,n){return De(t,e,1,r,n)}function kn(t,e,r,n){return De(t,e,2,U(t,e+1,n),n)}function Sn(t,e,r,n){return De(t,e,3,L(t,e+1,n),n)}function Nn(t,e,r,n){return De(t,e,5,z(t,e+1,n),n)}function Dn(t,e,r,n){let o=M(t,e+1,n);if(typeof o=="bigint")throw new Error(`${h} 64-bit integer string lengths not supported`);return De(t,e,9,o,n)}var Bn=he;function pe(t,e,r,n){return new d(a.array,n,r)}function _n(t,e,r,n){return pe(t,e,1,r)}function Cn(t,e,r,n){return pe(t,e,2,U(t,e+1,n))}function Un(t,e,r,n){return pe(t,e,3,L(t,e+1,n))}function Ln(t,e,r,n){return pe(t,e,5,z(t,e+1,n))}function zn(t,e,r,n){let o=M(t,e+1,n);if(typeof o=="bigint")throw new Error(`${h} 64-bit integer array lengths not supported`);return pe(t,e,9,o)}function Mn(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${h} indefinite length items not allowed`);return pe(t,e,1,1/0)}function tt(t,e){S(t,a.array.majorEncoded,e.value)}tt.compareTokens=P.compareTokens;tt.encodedSize=function(e){return S.encodedSize(e.value)};function me(t,e,r,n){return new d(a.map,n,r)}function Fn(t,e,r,n){return me(t,e,1,r)}function Rn(t,e,r,n){return me(t,e,2,U(t,e+1,n))}function Pn(t,e,r,n){return me(t,e,3,L(t,e+1,n))}function On(t,e,r,n){return me(t,e,5,z(t,e+1,n))}function $n(t,e,r,n){let o=M(t,e+1,n);if(typeof o=="bigint")throw new Error(`${h} 64-bit integer map lengths not supported`);return me(t,e,9,o)}function Hn(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${h} indefinite length items not allowed`);return me(t,e,1,1/0)}function rt(t,e){S(t,a.map.majorEncoded,e.value)}rt.compareTokens=P.compareTokens;rt.encodedSize=function(e){return S.encodedSize(e.value)};function Vn(t,e,r,n){return new d(a.tag,r,1)}function qn(t,e,r,n){return new d(a.tag,U(t,e+1,n),2)}function Gn(t,e,r,n){return new d(a.tag,L(t,e+1,n),3)}function jn(t,e,r,n){return new d(a.tag,z(t,e+1,n),5)}function Xn(t,e,r,n){return new d(a.tag,M(t,e+1,n),9)}function nt(t,e){S(t,a.tag.majorEncoded,e.value)}nt.compareTokens=P.compareTokens;nt.encodedSize=function(e){return S.encodedSize(e.value)};var $i=20,Hi=21,Vi=22,qi=23;function Wn(t,e,r,n){if(n.allowUndefined===!1)throw new Error(`${h} undefined values are not supported`);return n.coerceUndefinedToNull===!0?new d(a.null,null,1):new d(a.undefined,void 0,1)}function Qn(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${h} indefinite length items not allowed`);return new d(a.break,void 0,1)}function Mt(t,e,r){if(r){if(r.allowNaN===!1&&Number.isNaN(t))throw new Error(`${h} NaN values are not supported`);if(r.allowInfinity===!1&&(t===1/0||t===-1/0))throw new Error(`${h} Infinity values are not supported`)}return new d(a.float,t,e)}function Kn(t,e,r,n){return Mt(Ft(t,e+1),3,n)}function Jn(t,e,r,n){return Mt(Rt(t,e+1),5,n)}function Yn(t,e,r,n){return Mt(ro(t,e+1),9,n)}function ot(t,e,r){let n=e.value;if(n===!1)t.push([a.float.majorEncoded|$i]);else if(n===!0)t.push([a.float.majorEncoded|Hi]);else if(n===null)t.push([a.float.majorEncoded|Vi]);else if(n===void 0)t.push([a.float.majorEncoded|qi]);else{let o,i=!1;(!r||r.float64!==!0)&&(eo(n),o=Ft(H,1),n===o||Number.isNaN(n)?(H[0]=249,t.push(H.slice(0,3)),i=!0):(to(n),o=Rt(H,1),n===o&&(H[0]=250,t.push(H.slice(0,5)),i=!0))),i||(Gi(n),o=ro(H,1),H[0]=251,t.push(H.slice(0,9)))}}ot.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){eo(n);let o=Ft(H,1);if(n===o||Number.isNaN(n))return 3;if(to(n),o=Rt(H,1),n===o)return 5}return 9};var Zn=new ArrayBuffer(9),O=new DataView(Zn,1),H=new Uint8Array(Zn,0);function eo(t){if(t===1/0)O.setUint16(0,31744,!1);else if(t===-1/0)O.setUint16(0,64512,!1);else if(Number.isNaN(t))O.setUint16(0,32256,!1);else{O.setFloat32(0,t);let e=O.getUint32(0),r=(e&2139095040)>>23,n=e&8388607;if(r===255)O.setUint16(0,31744,!1);else if(r===0)O.setUint16(0,(t&2147483648)>>16|n>>13,!1);else{let o=r-127;o<-24?O.setUint16(0,0):o<-14?O.setUint16(0,(e&2147483648)>>16|1<<24+o,!1):O.setUint16(0,(e&2147483648)>>16|o+15<<10|n>>13,!1)}}}function Ft(t,e){if(t.length-e<2)throw new Error(`${h} 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 to(t){O.setFloat32(0,t,!1)}function Rt(t,e){if(t.length-e<4)throw new Error(`${h} not enough data for float32`);let r=(t.byteOffset||0)+e;return new DataView(t.buffer,r,4).getFloat32(0,!1)}function Gi(t){O.setFloat64(0,t,!1)}function ro(t,e){if(t.length-e<8)throw new Error(`${h} not enough data for float64`);let r=(t.byteOffset||0)+e;return new DataView(t.buffer,r,8).getFloat64(0,!1)}ot.compareTokens=P.compareTokens;function g(t,e,r){throw new Error(`${h} encountered invalid minor (${r}) for major ${t[e]>>>5}`)}function it(t){return()=>{throw new Error(`${h} ${t}`)}}var f=[];for(let t=0;t<=23;t++)f[t]=g;f[24]=dn;f[25]=ln;f[26]=hn;f[27]=pn;f[28]=g;f[29]=g;f[30]=g;f[31]=g;for(let t=32;t<=55;t++)f[t]=g;f[56]=mn;f[57]=yn;f[58]=gn;f[59]=wn;f[60]=g;f[61]=g;f[62]=g;f[63]=g;for(let t=64;t<=87;t++)f[t]=bn;f[88]=En;f[89]=Tn;f[90]=In;f[91]=vn;f[92]=g;f[93]=g;f[94]=g;f[95]=it("indefinite length bytes/strings are not supported");for(let t=96;t<=119;t++)f[t]=An;f[120]=kn;f[121]=Sn;f[122]=Nn;f[123]=Dn;f[124]=g;f[125]=g;f[126]=g;f[127]=it("indefinite length bytes/strings are not supported");for(let t=128;t<=151;t++)f[t]=_n;f[152]=Cn;f[153]=Un;f[154]=Ln;f[155]=zn;f[156]=g;f[157]=g;f[158]=g;f[159]=Mn;for(let t=160;t<=183;t++)f[t]=Fn;f[184]=Rn;f[185]=Pn;f[186]=On;f[187]=$n;f[188]=g;f[189]=g;f[190]=g;f[191]=Hn;for(let t=192;t<=215;t++)f[t]=Vn;f[216]=qn;f[217]=Gn;f[218]=jn;f[219]=Xn;f[220]=g;f[221]=g;f[222]=g;f[223]=g;for(let t=224;t<=243;t++)f[t]=it("simple values are not supported");f[244]=g;f[245]=g;f[246]=g;f[247]=Wn;f[248]=it("simple values are not supported");f[249]=Kn;f[250]=Jn;f[251]=Yn;f[252]=g;f[253]=g;f[254]=g;f[255]=Qn;var V=[];for(let t=0;t<24;t++)V[t]=new d(a.uint,t,1);for(let t=-1;t>=-24;t--)V[31-t]=new d(a.negint,t,1);V[64]=new d(a.bytes,new Uint8Array(0),1);V[96]=new d(a.string,"",1);V[128]=new d(a.array,0,1);V[160]=new d(a.map,0,1);V[244]=new d(a.false,!1,1);V[245]=new d(a.true,!0,1);V[246]=new d(a.null,null,1);function Pt(t){switch(t.type){case a.false:return j([244]);case a.true:return j([245]);case a.null:return j([246]);case a.bytes:return t.value.length?void 0:j([64]);case a.string:return t.value===""?j([96]):void 0;case a.array:return t.value===0?j([128]):void 0;case a.map:return t.value===0?j([160]):void 0;case a.uint:return t.value<24?j([Number(t.value)]):void 0;case a.negint:if(t.value>=-24)return j([31-Number(t.value)])}}var Xi={float64:!1,mapSorter:Qi,quickEncodeToken:Pt};function $t(){let t=[];return t[a.uint.major]=P,t[a.negint.major]=Ze,t[a.bytes.major]=he,t[a.string.major]=Bn,t[a.array.major]=tt,t[a.map.major]=rt,t[a.tag.major]=nt,t[a.float.major]=ot,t}var no=$t(),Ot=new ke,st=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(`${Lt} 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=st.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=st.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 Wi(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=tn(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(`${Lt} unsupported type: ${n}`);return i(t,n,e,r)}function Wi(t,e){e.mapSorter&&t.sort(e.mapSorter)}function Qi(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=no[o].compareTokens(r,n);return i===0&&console.warn("WARNING: complex key types used, CBOR key sorting guarantees are gone"),i}function oo(t,e,r,n){if(Array.isArray(e))for(let o of e)oo(t,o,r,n);else r[e.type.major](t,e,n)}function Ki(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 ke(s);if(i(c,n,r),c.chunks.length!==1)throw new Error(`Unexpected error: pre-calculated length for ${n} was wrong`);return Ut(c.chunks[0])}}return Ot.reset(),oo(Ot,n,e,r),Ot.toBytes(!0)}function Ht(t,e){return e=Object.assign({},Xi,e),Ki(t,no,e)}var Ji={strict:!1,allowIndefinite:!0,allowUndefined:!0,allowBigInt:!0},at=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=V[e];if(r===void 0){let n=f[e];if(!n)throw new Error(`${h} 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}},_e=Symbol.for("DONE"),ct=Symbol.for("BREAK");function Yi(t,e,r){let n=[];for(let o=0;o<t.value;o++){let i=ye(e,r);if(i===ct){if(t.value===1/0)break;throw new Error(`${h} got unexpected break to lengthed array`)}if(i===_e)throw new Error(`${h} found array but not enough entries (got ${o}, expected ${t.value})`);n[o]=i}return n}function Zi(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=ye(e,r);if(c===ct){if(t.value===1/0)break;throw new Error(`${h} got unexpected break to lengthed map`)}if(c===_e)throw new Error(`${h} found map but not enough entries (got ${s} [no key], expected ${t.value})`);if(n!==!0&&typeof c!="string")throw new Error(`${h} non-string keys not supported (got ${typeof c})`);if(r.rejectDuplicateMapKeys===!0&&(n&&i.has(c)||!n&&c in o))throw new Error(`${h} found repeat map key "${c}"`);let u=ye(e,r);if(u===_e)throw new Error(`${h} 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 ye(t,e){if(t.done())return _e;let r=t.next();if(r.type===a.break)return ct;if(r.type.terminal)return r.value;if(r.type===a.array)return Yi(r,t,e);if(r.type===a.map)return Zi(r,t,e);if(r.type===a.tag){if(e.tags&&typeof e.tags[r.value]=="function"){let n=ye(t,e);return e.tags[r.value](n)}throw new Error(`${h} tag not supported (${r.value})`)}throw new Error("unsupported")}function io(t,e){if(!(t instanceof Uint8Array))throw new Error(`${h} data to decode must be a Uint8Array`);e=Object.assign({},Ji,e);let r=e.tokenizer||new at(t,e),n=ye(r,e);if(n===_e)throw new Error(`${h} did not find any content to decode`);if(n===ct)throw new Error(`${h} got unexpected break`);return[n,t.subarray(r.pos())]}function Vt(t,e){let[r,n]=io(t,e);if(n.length>0)throw new Error(`${h} too many terminals, data makes no sense`);return r}var Qt={};C(Qt,{base32:()=>xe,base32hex:()=>fs,base32hexpad:()=>ls,base32hexpadupper:()=>hs,base32hexupper:()=>ds,base32pad:()=>cs,base32padupper:()=>us,base32upper:()=>as,base32z:()=>ps});var pu=new Uint8Array(0);function so(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 J(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 ao(t){return new TextEncoder().encode(t)}function co(t){return new TextDecoder().decode(t)}function ts(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),p=Math.log(256)/Math.log(c);function x(m){if(m instanceof Uint8Array||(ArrayBuffer.isView(m)?m=new Uint8Array(m.buffer,m.byteOffset,m.byteLength):Array.isArray(m)&&(m=Uint8Array.from(m))),!(m instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(m.length===0)return"";for(var b=0,y=0,v=0,D=m.length;v!==D&&m[v]===0;)v++,b++;for(var k=(D-v)*p+1>>>0,_=new Uint8Array(k);v!==D;){for(var R=m[v],ee=0,$=k-1;(R!==0||ee<y)&&$!==-1;$--,ee++)R+=256*_[$]>>>0,_[$]=R%c>>>0,R=R/c>>>0;if(R!==0)throw new Error("Non-zero carry");y=ee,v++}for(var Q=k-y;Q!==k&&_[Q]===0;)Q++;for(var Qe=u.repeat(b);Q<k;++Q)Qe+=t.charAt(_[Q]);return Qe}function I(m){if(typeof m!="string")throw new TypeError("Expected String");if(m.length===0)return new Uint8Array;var b=0;if(m[b]!==" "){for(var y=0,v=0;m[b]===u;)y++,b++;for(var D=(m.length-b)*l+1>>>0,k=new Uint8Array(D);m[b];){var _=r[m.charCodeAt(b)];if(_===255)return;for(var R=0,ee=D-1;(_!==0||R<v)&&ee!==-1;ee--,R++)_+=c*k[ee]>>>0,k[ee]=_%256>>>0,_=_/256>>>0;if(_!==0)throw new Error("Non-zero carry");v=R,b++}if(m[b]!==" "){for(var $=D-v;$!==D&&k[$]===0;)$++;for(var Q=new Uint8Array(y+(D-$)),Qe=y;$!==D;)Q[Qe++]=k[$++];return Q}}}function w(m){var b=I(m);if(b)return b;throw new Error(`Non-${e} character`)}return{encode:x,decodeUnsafe:I,decode:w}}var rs=ts,ns=rs,uo=ns;var Gt=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")}},jt=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 fo(this,e)}},Xt=class{decoders;constructor(e){this.decoders=e}or(e){return fo(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 fo(t,e){return new Xt({...t.decoders??{[t.prefix]:t},...e.decoders??{[e.prefix]:e}})}var Wt=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 Gt(e,r,n),this.decoder=new jt(e,r,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function ge({name:t,prefix:e,encode:r,decode:n}){return new Wt(t,e,r,n)}function ne({name:t,prefix:e,alphabet:r}){let{encode:n,decode:o}=uo(r,t);return ge({prefix:e,name:t,encode:n,decode:i=>J(o(i))})}function os(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 p=e[t[l]];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 is(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 ss(t){let e={};for(let r=0;r<t.length;++r)e[t[r]]=r;return e}function T({name:t,prefix:e,bitsPerChar:r,alphabet:n}){let o=ss(n);return ge({prefix:e,name:t,encode(i){return is(i,n,r)},decode(i){return os(i,o,r,t)}})}var xe=T({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),as=T({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),cs=T({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),us=T({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),fs=T({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),ds=T({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),ls=T({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),hs=T({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),ps=T({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Kt={};C(Kt,{base36:()=>Ce,base36upper:()=>ms});var Ce=ne({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),ms=ne({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Jt={};C(Jt,{base58btc:()=>X,base58flickr:()=>ys});var X=ne({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),ys=ne({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var gs=po,lo=128,xs=127,ws=~xs,bs=Math.pow(2,31);function po(t,e,r){e=e||[],r=r||0;for(var n=r;t>=bs;)e[r++]=t&255|lo,t/=128;for(;t&ws;)e[r++]=t&255|lo,t>>>=7;return e[r]=t|0,po.bytes=r-n+1,e}var Es=Yt,Ts=128,ho=127;function Yt(t,n){var r=0,n=n||0,o=0,i=n,s,c=t.length;do{if(i>=c)throw Yt.bytes=0,new RangeError("Could not decode varint");s=t[i++],r+=o<28?(s&ho)<<o:(s&ho)*Math.pow(2,o),o+=7}while(s>=Ts);return Yt.bytes=i-n,r}var Is=Math.pow(2,7),vs=Math.pow(2,14),As=Math.pow(2,21),ks=Math.pow(2,28),Ss=Math.pow(2,35),Ns=Math.pow(2,42),Ds=Math.pow(2,49),Bs=Math.pow(2,56),_s=Math.pow(2,63),Cs=function(t){return t<Is?1:t<vs?2:t<As?3:t<ks?4:t<Ss?5:t<Ns?6:t<Ds?7:t<Bs?8:t<_s?9:10},Us={encode:gs,decode:Es,encodingLength:Cs},Ls=Us,Ue=Ls;function Le(t,e=0){return[Ue.decode(t,e),Ue.decode.bytes]}function we(t,e,r=0){return Ue.encode(t,e,r),e}function be(t){return Ue.encodingLength(t)}function Te(t,e){let r=e.byteLength,n=be(t),o=n+be(r),i=new Uint8Array(o+r);return we(t,i,0),we(r,i,n),i.set(e,o),new Ee(t,r,e,i)}function ft(t){let e=J(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 Ee(r,o,s,e)}function mo(t,e){if(t===e)return!0;{let r=e;return t.code===r.code&&t.size===r.size&&r.bytes instanceof Uint8Array&&so(t.bytes,r.bytes)}}var Ee=class{code;size;digest;bytes;constructor(e,r,n,o){this.code=e,this.size=r,this.digest=n,this.bytes=o}};function yo(t,e){let{bytes:r,version:n}=t;switch(n){case 0:return Ms(r,Zt(t),e??X.encoder);default:return Fs(r,Zt(t),e??xe.encoder)}}var go=new WeakMap;function Zt(t){let e=go.get(t);if(e==null){let r=new Map;return go.set(t,r),r}return e}var E=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!==Rs)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=Te(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&&mo(e.multihash,n.multihash)}toString(e){return yo(this,e)}toJSON(){return{"/":yo(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??xo(n,o,i.bytes))}else if(r[Ps]===!0){let{version:n,multihash:o,code:i}=r,s=ft(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=xo(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=J(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 Ee(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[x,I]=Le(e.subarray(r));return r+=I,x},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(),l=r+u,p=l-s;return{version:o,codec:i,multihashCode:c,digestSize:u,multihashSize:p,size:l}}static parse(e,r){let[n,o]=zs(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 Zt(i).set(n,e),i}};function zs(t,e){switch(t[0]){case"Q":{let r=e??X;return[X.prefix,r.decode(`${X.prefix}${t}`)]}case X.prefix:{let r=e??X;return[X.prefix,r.decode(t)]}case xe.prefix:{let r=e??xe;return[xe.prefix,r.decode(t)]}case Ce.prefix:{let r=e??Ce;return[Ce.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 Ms(t,e,r){let{prefix:n}=r;if(n!==X.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 Fs(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,Rs=18;function xo(t,e,r){let n=be(t),o=n+be(e),i=new Uint8Array(o+r.byteLength);return we(t,i,0),we(e,i,n),i.set(r,o),i}var Ps=Symbol.for("@ipld/js-cid/CID");var wo=42;function Os(t){return t instanceof ArrayBuffer?new Uint8Array(t,0,t.byteLength):t}function $s(t){if(t.asCID!==t&&t["/"]!==t.bytes)return null;let e=E.asCID(t);if(!e)return null;let r=new Uint8Array(e.bytes.byteLength+1);return r.set(e.bytes,1),[new d(a.tag,wo),new d(a.bytes,r)]}function Hs(){throw new Error("`undefined` is not supported by the IPLD Data Model and cannot be encoded")}function Vs(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 qs(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 er={float64:!0,typeEncoders:{Map:qs,Object:$s,undefined:Hs,number:Vs}},Cu={...er,typeEncoders:{...er.typeEncoders}};function Gs(t){if(t[0]!==0)throw new Error("Invalid CID for CBOR tag 42; expected leading 0x00");return E.decode(t.subarray(1))}var dt={allowIndefinite:!1,coerceUndefinedToNull:!0,allowNaN:!1,allowInfinity:!1,allowBigInt:!0,strict:!0,useMaps:!1,rejectDuplicateMapKeys:!0,tags:[]};dt.tags[wo]=Gs;var Uu={...dt,tags:dt.tags.slice()};var tr=t=>Ht(t,er),rr=t=>Vt(Os(t),dt);var ir=Ct(lt(),1);var sr=40;function ar(t,e){if(!t.length)throw new Error("Unexpected end of data");let r=ir.default.decode(t);return e.seek(ir.default.decode.bytes),r}function cr(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},Me={"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=Me["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=Me["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=Me["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=Me.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}},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)"](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=Fe.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}},ur={toTyped:Me.CarV1HeaderOrV2Pragma,toRepresentation:Fe.CarV1HeaderOrV2Pragma};var Wu=$t();var ua=Ct(lt(),1);var Zu=[new d(a.map,2),new d(a.string,"version"),new d(a.uint,1),new d(a.string,"roots")],ef=new d(a.tag,42);async function fr(t,e){let r=ar(await t.upTo(8),t);if(r===0)throw new Error("Invalid CAR header (zero length)");let n=await t.exactly(r,!0),o=rr(n);if(ur.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=cr(await t.exactly(sr,!0));t.seek(i.dataOffset-t.pos);let s=await fr(t,1);return Object.assign(s,i)}function Re(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 dr=Ct(lt(),1),_o=1;function lr(t){let e=tr({version:_o,roots:t}),r=dr.default.encode(e.length),n=new Uint8Array(r.length+e.length);return n.set(r,0),n.set(e,r.length),n}function Co(t){return{async setRoots(e){let r=lr(e);await t.write(r)},async writeBlock(e){let{cid:r,bytes:n}=e;await t.write(new Uint8Array(dr.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 _o}}}function ht(){}function Uo(){let t=[],e=null,r=ht,n=!1,o=null,i=ht,s=()=>(e||(e=new Promise(l=>{r=()=>{e=null,r=ht,l()}})),e),c={write(l){t.push(l);let p=s();return i(),p},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(p=>{i=()=>(o=null,i=ht,p(u.next()))})),o)}};return{writer:c,iterator:u}}var Pe=class t{constructor(e,r){this._encoder=r,this._mutex=r.setRoots(e),this._ended=!1}async put(e){if(!(e.bytes instanceof Uint8Array)||!e.cid)throw new TypeError("Can only write {cid, bytes} objects");if(this._ended)throw new Error("Already closed");let r=E.asCID(e.cid);if(!r)throw new TypeError("Can only write {cid, bytes} objects");return this._mutex=this._mutex.then(()=>this._encoder.writeBlock({cid:r,bytes:e.bytes})),this._mutex}async close(){if(this._ended)throw new Error("Already closed");return await this._mutex,this._ended=!0,this._encoder.close()}version(){return this._encoder.version()}static create(e){e=ha(e);let{encoder:r,iterator:n}=Lo(),o=new t(e,r),i=new pt(n);return{writer:o,out:i}}static createAppender(){let{encoder:e,iterator:r}=Lo();e.setRoots=()=>Promise.resolve();let n=new t([],e),o=new pt(r);return{writer:n,out:o}}static async updateRootsInBytes(e,r){let n=Re(e);await fr(n);let o=lr(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}},pt=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 Lo(){let t=Uo(),{writer:e,iterator:r}=t;return{encoder:Co(e),iterator:r}}function ha(t){if(t===void 0)return[];if(!Array.isArray(t)){let r=E.asCID(t);if(!r)throw new TypeError("roots must be a single CID or an array of CIDs");return[r]}let e=[];for(let r of t){let n=E.asCID(r);if(!n)throw new TypeError("roots must be a single CID or an array of CIDs");e.push(n)}return e}var Y=class extends Error{static name="AbortError";constructor(e="The operation was aborted"){super(e),this.name="AbortError"}};var mt=class extends EventTarget{#e=new Map;constructor(){super()}listenerCount(e){let r=this.#e.get(e);return r==null?0:r.length}addEventListener(e,r,n){super.addEventListener(e,r,n);let o=this.#e.get(e);o==null&&(o=[],this.#e.set(e,o)),o.push({callback:r,once:(n!==!0&&n!==!1&&n?.once)??!1})}removeEventListener(e,r,n){super.removeEventListener(e.toString(),r??null,n);let o=this.#e.get(e);o!=null&&(o=o.filter(({callback:i})=>i!==r),this.#e.set(e,o))}dispatchEvent(e){let r=super.dispatchEvent(e),n=this.#e.get(e.type);return n==null||(n=n.filter(({once:o})=>!o),this.#e.set(e.type,n)),r}safeDispatchEvent(e,r={}){return this.dispatchEvent(new CustomEvent(e,r))}};var hr={};C(hr,{identity:()=>ya});var zo=0,pa="identity",Mo=J;function ma(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 Te(zo,Mo(t))}var ya={code:zo,name:pa,encode:Mo,digest:ma};function W(t=0){return new Uint8Array(t)}function pr(t,e){e==null&&(e=t.reduce((o,i)=>o+i.length,0));let r=W(e),n=0;for(let o of t)r.set(o,n),n+=o.length;return r}var mr={};C(mr,{base10:()=>ga});var ga=ne({prefix:"9",name:"base10",alphabet:"0123456789"});var yr={};C(yr,{base16:()=>xa,base16upper:()=>wa});var xa=T({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),wa=T({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var gr={};C(gr,{base2:()=>ba});var ba=T({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var xr={};C(xr,{base256emoji:()=>Aa});var Fo=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}"),Ea=Fo.reduce((t,e,r)=>(t[r]=e,t),[]),Ta=Fo.reduce((t,e,r)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return t[n]=r,t},[]);function Ia(t){return t.reduce((e,r)=>(e+=Ea[r],e),"")}function va(t){let e=[];for(let r of t){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=Ta[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);e.push(o)}return new Uint8Array(e)}var Aa=ge({prefix:"\u{1F680}",name:"base256emoji",encode:Ia,decode:va});var wr={};C(wr,{base64:()=>ka,base64pad:()=>Sa,base64url:()=>Na,base64urlpad:()=>Da});var ka=T({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Sa=T({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Na=T({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Da=T({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var br={};C(br,{base8:()=>Ba});var Ba=T({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Er={};C(Er,{identity:()=>_a});var _a=ge({prefix:"\0",name:"identity",encode:t=>co(t),decode:t=>ao(t)});var Zf=new TextEncoder,ed=new TextDecoder;var vr={};C(vr,{sha256:()=>za,sha512:()=>Ma});var La=20;function Ir({name:t,code:e,encode:r,minDigestLength:n,maxDigestLength:o}){return new Tr(t,e,r,n,o)}var Tr=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,r,n,o,i){this.name=e,this.code=r,this.encode=n,this.minDigestLength=o??La,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?Ro(n,this.code,r?.truncate):n.then(o=>Ro(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function Ro(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 Te(e,t)}function Oo(t){return async e=>new Uint8Array(await crypto.subtle.digest(t,e))}var za=Ir({name:"sha2-256",code:18,encode:Oo("SHA-256")}),Ma=Ir({name:"sha2-512",code:19,encode:Oo("SHA-512")});var Ar={...Er,...gr,...br,...mr,...yr,...Qt,...Kt,...Jt,...wr,...xr},ld={...vr,...hr};function Ho(t,e,r,n){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:r},decoder:{decode:n}}}var $o=Ho("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),kr=Ho("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=W(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}),Fa={utf8:$o,"utf-8":$o,hex:Ar.base16,latin1:kr,ascii:kr,binary:kr,...Ar},Vo=Fa;function qo(t,e="utf8"){let r=Vo[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.decoder.decode(`${r.prefix}${t}`)}var Ra=Math.pow(2,7),Pa=Math.pow(2,14),Oa=Math.pow(2,21),Go=Math.pow(2,28),jo=Math.pow(2,35),Xo=Math.pow(2,42),Wo=Math.pow(2,49),B=128,ie=127;function Oe(t){if(t<Ra)return 1;if(t<Pa)return 2;if(t<Oa)return 3;if(t<Go)return 4;if(t<jo)return 5;if(t<Xo)return 6;if(t<Wo)return 7;if(Number.MAX_SAFE_INTEGER!=null&&t>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Qo(t,e,r=0){switch(Oe(t)){case 8:e[r++]=t&255|B,t/=128;case 7:e[r++]=t&255|B,t/=128;case 6:e[r++]=t&255|B,t/=128;case 5:e[r++]=t&255|B,t/=128;case 4:e[r++]=t&255|B,t>>>=7;case 3:e[r++]=t&255|B,t>>>=7;case 2:e[r++]=t&255|B,t>>>=7;case 1:{e[r++]=t&255,t>>>=7;break}default:throw new Error("unreachable")}return e}function Ko(t,e){let r=t[e],n=0;if(n+=r&ie,r<B||(r=t[e+1],n+=(r&ie)<<7,r<B)||(r=t[e+2],n+=(r&ie)<<14,r<B)||(r=t[e+3],n+=(r&ie)<<21,r<B)||(r=t[e+4],n+=(r&ie)*Go,r<B)||(r=t[e+5],n+=(r&ie)*jo,r<B)||(r=t[e+6],n+=(r&ie)*Xo,r<B)||(r=t[e+7],n+=(r&ie)*Wo,r<B))return n;throw new RangeError("Could not decode varint")}var Sr=new Float32Array([-0]),se=new Uint8Array(Sr.buffer);function Jo(t,e,r){Sr[0]=t,e[r]=se[0],e[r+1]=se[1],e[r+2]=se[2],e[r+3]=se[3]}function Yo(t,e){return se[0]=t[e],se[1]=t[e+1],se[2]=t[e+2],se[3]=t[e+3],Sr[0]}var Nr=new Float64Array([-0]),N=new Uint8Array(Nr.buffer);function Zo(t,e,r){Nr[0]=t,e[r]=N[0],e[r+1]=N[1],e[r+2]=N[2],e[r+3]=N[3],e[r+4]=N[4],e[r+5]=N[5],e[r+6]=N[6],e[r+7]=N[7]}function ei(t,e){return N[0]=t[e],N[1]=t[e+1],N[2]=t[e+2],N[3]=t[e+3],N[4]=t[e+4],N[5]=t[e+5],N[6]=t[e+6],N[7]=t[e+7],Nr[0]}var $a=BigInt(Number.MAX_SAFE_INTEGER),Ha=BigInt(Number.MIN_SAFE_INTEGER),F=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 ue;if(e<$a&&e>Ha)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>ti&&(o=0n,++n>ti&&(n=0n))),new t(Number(o),Number(n))}static fromNumber(e){if(e===0)return ue;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):ue}},ue=new F(0,0);ue.toBigInt=function(){return 0n};ue.zzEncode=ue.zzDecode=function(){return this};ue.length=function(){return 1};var ti=4294967296n;function ri(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 ni(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 Dr(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 q(t,e){return RangeError(`index out of range: ${t.pos} + ${e??1} > ${t.len}`)}function yt(t,e){return(t[e-4]|t[e-3]<<8|t[e-2]<<16|t[e-1]<<24)>>>0}var Br=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,q(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 q(this,4);return yt(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw q(this,4);return yt(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw q(this,4);let e=Yo(this.buf,this.pos);return this.pos+=4,e}double(){if(this.pos+8>this.len)throw q(this,4);let e=ei(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 q(this,e);return this.pos+=e,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let e=this.bytes();return ni(e,0,e.length)}skip(e){if(typeof e=="number"){if(this.pos+e>this.len)throw q(this,e);this.pos+=e}else do if(this.pos>=this.len)throw q(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 F(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 q(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 q(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 q(this,8);let e=yt(this.buf,this.pos+=4),r=yt(this.buf,this.pos+=4);return new F(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=Ko(this.buf,this.pos);return this.pos+=Oe(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 _r(t){return new Br(t instanceof Uint8Array?t:t.subarray())}function $e(t,e,r){let n=_r(t);return e.decode(n,void 0,r)}function Cr(t){let e=t??8192,r=e>>>1,n,o=e;return function(s){if(s<1||s>r)return W(s);o+s>e&&(n=W(e),o=0);let c=n.subarray(o,o+=s);return(o&7)!==0&&(o=(o|7)+1),c}}var fe=class{fn;len;next;val;constructor(e,r,n){this.fn=e,this.len=r,this.next=void 0,this.val=n}};function Ur(){}var zr=class{head;tail;len;next;constructor(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}},Va=Cr();function qa(t){return globalThis.Buffer!=null?W(t):Va(t)}var Ve=class{len;head;tail;states;constructor(){this.len=0,this.head=new fe(Ur,0,0),this.tail=this.head,this.states=null}_push(e,r,n){return this.tail=this.tail.next=new fe(e,r,n),this.len+=r,this}uint32(e){return this.len+=(this.tail=this.tail.next=new Mr((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(gt,10,F.fromNumber(e)):this.uint32(e)}sint32(e){return this.uint32((e<<1^e>>31)>>>0)}uint64(e){let r=F.fromBigInt(e);return this._push(gt,r.length(),r)}uint64Number(e){return this._push(Qo,Oe(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=F.fromBigInt(e).zzEncode();return this._push(gt,r.length(),r)}sint64Number(e){let r=F.fromNumber(e).zzEncode();return this._push(gt,r.length(),r)}sint64String(e){return this.sint64(BigInt(e))}bool(e){return this._push(Lr,1,e?1:0)}fixed32(e){return this._push(He,4,e>>>0)}sfixed32(e){return this.fixed32(e)}fixed64(e){let r=F.fromBigInt(e);return this._push(He,4,r.lo)._push(He,4,r.hi)}fixed64Number(e){let r=F.fromNumber(e);return this._push(He,4,r.lo)._push(He,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(Zo,8,e)}bytes(e){let r=e.length>>>0;return r===0?this._push(Lr,1,0):this.uint32(r)._push(ja,r,e)}string(e){let r=ri(e);return r!==0?this.uint32(r)._push(Dr,r,e):this._push(Lr,1,0)}fork(){return this.states=new zr(this),this.head=this.tail=new fe(Ur,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 fe(Ur,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=qa(this.len),n=0;for(;e!=null;)e.fn(e.val,r,n),n+=e.len,e=e.next;return r}};function Lr(t,e,r){e[r]=t&255}function Ga(t,e,r){for(;t>127;)e[r++]=t&127|128,t>>>=7;e[r]=t}var Mr=class extends fe{next;constructor(e,r){super(Ga,e,r),this.next=void 0}};function gt(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 He(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 ja(t,e,r){e.set(t,r)}globalThis.Buffer!=null&&(Ve.prototype.bytes=function(t){let e=t.length>>>0;return this.uint32(e),e>0&&this._push(Xa,e,t),this},Ve.prototype.string=function(t){let e=globalThis.Buffer.byteLength(t);return this.uint32(e),e>0&&this._push(Wa,e,t),this});function Xa(t,e,r){e.set(t,r)}function Wa(t,e,r){t.length<40?Dr(t,e,r):e.utf8Write!=null?e.utf8Write(t,r):e.set(qo(t),r)}function Fr(){return new Ve}function qe(t,e){let r=Fr();return e.encode(t,r,{lengthDelimited:!1}),r.finish()}var Ie;(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"})(Ie||(Ie={}));function xt(t,e,r,n){return{name:t,type:e,encode:r,decode:n}}function Rr(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 xt("enum",Ie.VARINT,r,n)}function Ge(t,e){return xt("message",Ie.LENGTH_DELIMITED,t,e)}function ve(){let t={};return t.promise=new Promise((e,r)=>{t.resolve=e,t.reject=r}),t}var wt=class{buffer;mask;top;btm;next;constructor(e){if(!(e>0)||(e-1&e)!==0)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(e),this.mask=e-1,this.top=0,this.btm=0,this.next=null}push(e){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=e,this.top=this.top+1&this.mask,!0)}shift(){let e=this.buffer[this.btm];if(e!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,e}isEmpty(){return this.buffer[this.btm]===void 0}},Ae=class{size;hwm;head;tail;constructor(e={}){this.hwm=e.splitLimit??16,this.head=new wt(this.hwm),this.tail=this.head,this.size=0}calculateSize(e){return e?.byteLength!=null?e.byteLength:1}push(e){if(e?.value!=null&&(this.size+=this.calculateSize(e.value)),!this.head.push(e)){let r=this.head;this.head=r.next=new wt(2*this.head.buffer.length),this.head.push(e)}}shift(){let e=this.tail.shift();if(e===void 0&&this.tail.next!=null){let r=this.tail.next;this.tail.next=null,this.tail=r,e=this.tail.shift()}return e?.value!=null&&(this.size-=this.calculateSize(e.value)),e}isEmpty(){return this.head.isEmpty()}};var Pr=class extends Error{type;code;constructor(e,r){super(e??"The operation was aborted"),this.type="aborted",this.code=r??"ABORT_ERR"}};function ii(t={}){return Qa(r=>{let n=r.shift();if(n==null)return{done:!0};if(n.error!=null)throw n.error;return{done:n.done===!0,value:n.value}},t)}function Qa(t,e){e=e??{};let r=e.onEnd,n=new Ae,o,i,s,c=ve(),u=async()=>{try{return n.isEmpty()?s?{done:!0}:await new Promise((y,v)=>{i=D=>{i=null,n.push(D);try{y(t(n))}catch(k){v(k)}return o}}):t(n)}finally{n.isEmpty()&&queueMicrotask(()=>{c.resolve(),c=ve()})}},l=y=>i!=null?i(y):(n.push(y),o),p=y=>(n=new Ae,i!=null?i({error:y}):(n.push({error:y}),o)),x=y=>{if(s)return o;if(e?.objectMode!==!0&&y?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return l({done:!1,value:y})},I=y=>s?o:(s=!0,y!=null?p(y):l({done:!0})),w=()=>(n=new Ae,I(),{done:!0}),m=y=>(I(y),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:u,return:w,throw:m,push:x,end:I,get readableLength(){return n.size},onEmpty:async y=>{let v=y?.signal;if(v?.throwIfAborted(),n.isEmpty())return;let D,k;v!=null&&(D=new Promise((_,R)=>{k=()=>{R(new Pr)},v.addEventListener("abort",k)}));try{await Promise.race([c.promise,D])}finally{k!=null&&v!=null&&v?.removeEventListener("abort",k)}}},r==null)return o;let b=o;return o={[Symbol.asyncIterator](){return this},next(){return b.next()},throw(y){return b.throw(y),r!=null&&(r(y),r=void 0),{done:!0}},return(){return b.return(),r!=null&&(r(),r=void 0),{done:!0}},push:x,end(y){return b.end(y),r!=null&&(r(y),r=void 0),o},get readableLength(){return b.readableLength},onEmpty:y=>b.onEmpty(y)},o}var Or=class extends Error{constructor(e){super(e),this.name="TimeoutError"}},$r=class extends Error{constructor(e){super(),this.name="AbortError",this.message=e}},si=t=>globalThis.DOMException===void 0?new $r(t):new DOMException(t),ai=t=>{let e=t.reason===void 0?si("This operation was aborted."):t.reason;return e instanceof Error?e:si(e)};function Hr(t,e){let{milliseconds:r,fallback:n,message:o,customTimers:i={setTimeout,clearTimeout}}=e,s,c,l=new Promise((p,x)=>{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:w}=e;w.aborted&&x(ai(w)),c=()=>{x(ai(w))},w.addEventListener("abort",c,{once:!0})}if(r===Number.POSITIVE_INFINITY){t.then(p,x);return}let I=new Or;s=i.setTimeout.call(void 0,()=>{if(n){try{p(n())}catch(w){x(w)}return}typeof t.cancel=="function"&&t.cancel(),o===!1?p():o instanceof Error?x(o):(I.message=o??`Promise timed out after ${r} milliseconds`,x(I))},r),(async()=>{try{p(await t)}catch(w){x(w)}})()}).finally(()=>{l.clear(),c&&e.signal&&e.signal.removeEventListener("abort",c)});return l.clear=()=>{i.clearTimeout.call(void 0,s),s=void 0},l}var Ka=t=>{let e=t.addEventListener||t.on||t.addListener,r=t.removeEventListener||t.off||t.removeListener;if(!e||!r)throw new TypeError("Emitter is not compatible");return{addListener:e.bind(t),removeListener:r.bind(t)}};function Ja(t,e,r){let n,o=new Promise((i,s)=>{if(r={rejectionEvents:["error"],multiArgs:!1,rejectionMultiArgs:!1,resolveImmediately:!1,...r},!(r.count>=0&&(r.count===Number.POSITIVE_INFINITY||Number.isInteger(r.count))))throw new TypeError("The `count` option should be at least 0 or more");r.signal?.throwIfAborted();let c=[e].flat(),u=[],{addListener:l,removeListener:p}=Ka(t),x=async(...w)=>{let m=r.multiArgs?w:w[0];if(r.filter)try{if(!await r.filter(m))return}catch(b){n(),s(b);return}u.push(m),r.count===u.length&&(n(),i(u))},I=(...w)=>{n(),s(r.rejectionMultiArgs?w:w[0])};n=()=>{for(let w of c)p(w,x);for(let w of r.rejectionEvents)c.includes(w)||p(w,I)};for(let w of c)l(w,x);for(let w of r.rejectionEvents)c.includes(w)||l(w,I);r.signal&&r.signal.addEventListener("abort",()=>{I(r.signal.reason)},{once:!0}),r.resolveImmediately&&i(u)});if(o.cancel=n,typeof r.timeout=="number"){let i=Hr(o,{milliseconds:r.timeout});return i.cancel=()=>{n(),i.clear()},i}return o}function bt(t,e,r){typeof r=="function"&&(r={filter:r}),r={...r,count:1,resolveImmediately:!1};let n=Ja(t,e,r),o=n.then(i=>i[0]);return o.cancel=n.cancel,o}function Vr(t,e){let r,n=function(){let o=function(){r=void 0,t()};clearTimeout(r),r=setTimeout(o,e)};return n.start=()=>{},n.stop=()=>{clearTimeout(r)},n}var Et=class extends Error{static name="QueueFullError";constructor(e="The queue was full"){super(e),this.name="QueueFullError"}};function Ya(t){return t.reason}async function Tt(t,e,r){if(e==null)return t;let n=r?.translateError??Ya;if(e.aborted)return t.catch(()=>{}),Promise.reject(n(e));let o;try{return await Promise.race([t,new Promise((i,s)=>{o=()=>{s(n(e))},e.addEventListener("abort",o)})])}finally{o!=null&&e.removeEventListener("abort",o)}}var It=class{deferred;signal;constructor(e){this.signal=e,this.deferred=ve(),this.onAbort=this.onAbort.bind(this),this.signal?.addEventListener("abort",this.onAbort)}onAbort(){this.deferred.reject(this.signal?.reason??new Y)}cleanup(){this.signal?.removeEventListener("abort",this.onAbort)}};function Za(){return`${parseInt(String(Math.random()*1e9),10).toString()}${Date.now()}`}var vt=class{id;fn;options;recipients;status;timeline;controller;constructor(e,r){this.id=Za(),this.status="queued",this.fn=e,this.options=r,this.recipients=[],this.timeline={created:Date.now()},this.controller=new AbortController,this.controller.signal,this.onAbort=this.onAbort.bind(this)}abort(e){this.controller.abort(e)}onAbort(){this.recipients.reduce((r,n)=>r&&n.signal?.aborted===!0,!0)&&(this.controller.abort(new Y),this.cleanup())}async join(e={}){let r=new It(e.signal);return this.recipients.push(r),e.signal?.addEventListener("abort",this.onAbort),r.deferred.promise}async run(){this.status="running",this.timeline.started=Date.now();try{this.controller.signal.throwIfAborted();let e=await Tt(this.fn({...this.options??{},signal:this.controller.signal}),this.controller.signal);this.recipients.forEach(r=>{r.deferred.resolve(e)}),this.status="complete"}catch(e){this.recipients.forEach(r=>{r.deferred.reject(e)}),this.status="errored"}finally{this.timeline.finished=Date.now(),this.cleanup()}}cleanup(){this.recipients.forEach(e=>{e.cleanup(),e.signal?.removeEventListener("abort",this.onAbort)})}};var At=class extends mt{concurrency;maxSize;queue;pending;sort;paused;constructor(e={}){super(),this.concurrency=e.concurrency??Number.POSITIVE_INFINITY,this.maxSize=e.maxSize??Number.POSITIVE_INFINITY,this.pending=0,this.paused=!1,e.metricName!=null&&e.metrics?.registerMetricGroup(e.metricName,{calculate:()=>({size:this.queue.length,running:this.pending,queued:this.queue.length-this.pending})}),this.sort=e.sort,this.queue=[],this.emitEmpty=Vr(this.emitEmpty.bind(this),1),this.emitIdle=Vr(this.emitIdle.bind(this),1)}emitEmpty(){this.size===0&&this.safeDispatchEvent("empty")}emitIdle(){this.running===0&&this.safeDispatchEvent("idle")}pause(){this.paused=!0}resume(){this.paused&&(this.paused=!1,this.tryToStartAnother())}tryToStartAnother(){if(this.paused)return!1;if(this.size===0)return this.emitEmpty(),this.running===0&&this.emitIdle(),!1;if(this.pending<this.concurrency){let e;for(let r of this.queue)if(r.status==="queued"){e=r;break}return e==null?!1:(this.safeDispatchEvent("active"),this.pending++,e.run().finally(()=>{for(let r=0;r<this.queue.length;r++)if(this.queue[r]===e){this.queue.splice(r,1);break}this.pending--,this.tryToStartAnother(),this.safeDispatchEvent("next")}),!0)}return!1}enqueue(e){this.queue.push(e),this.sort!=null&&this.queue.sort(this.sort)}async add(e,r){if(r?.signal?.throwIfAborted(),this.size===this.maxSize)throw new Et;let n=new vt(e,r);return this.enqueue(n),this.safeDispatchEvent("add"),this.tryToStartAnother(),n.join(r).then(o=>(this.safeDispatchEvent("completed",{detail:o}),this.safeDispatchEvent("success",{detail:{job:n,result:o}}),o)).catch(o=>{if(n.status==="queued"){for(let i=0;i<this.queue.length;i++)if(this.queue[i]===n){this.queue.splice(i,1);break}}throw this.safeDispatchEvent("failure",{detail:{job:n,error:o}}),o})}clear(){this.queue.splice(0,this.queue.length)}abort(){this.queue.forEach(e=>{e.abort(new Y)}),this.clear()}async onEmpty(e){this.size!==0&&await bt(this,"empty",e)}async onSizeLessThan(e,r){this.size<e||await bt(this,"next",{...r,filter:()=>this.size<e})}async onIdle(e){this.pending===0&&this.size===0||await bt(this,"idle",e)}get size(){return this.queue.length}get queued(){return this.queue.length-this.pending}get running(){return this.pending}async*toGenerator(e){e?.signal?.throwIfAborted();let r=ii({objectMode:!0}),n=u=>{u!=null?this.abort():this.clear(),r.end(u)},o=u=>{u.detail!=null&&r.push(u.detail)},i=u=>{n(u.detail.error)},s=()=>{n()},c=()=>{n(new Y("Queue aborted"))};this.addEventListener("completed",o),this.addEventListener("failure",i),this.addEventListener("idle",s),e?.signal?.addEventListener("abort",c);try{yield*r}finally{this.removeEventListener("completed",o),this.removeEventListener("failure",i),this.removeEventListener("idle",s),e?.signal?.removeEventListener("abort",c),n()}}};function ec(t){return t[Symbol.asyncIterator]!=null}function tc(t){if(ec(t))return(async()=>{for await(let e of t);})();for(let e of t);}var ci=tc;function rc(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 ui=rc;function nc(t){return t[Symbol.asyncIterator]!=null}function oc(t,e){let r=0;if(nc(t))return(async function*(){for await(let u of t)yield e(u,r++)})();let n=ui(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 fi=oc;function ic(t){return t[Symbol.asyncIterator]!=null}function sc(t){if(ic(t))return(async()=>{let n=new Uint8Array(0);for await(let o of t)n=pr([n,o],n.length+o.length);return n})();let e=[],r=0;for(let n of t)e.push(n),r+=n.byteLength;return pr(e,r)}var qr=sc;function kt({enumerable:t=!0,configurable:e=!1}={}){return{enumerable:t,configurable:e,writable:!1}}function*ac(t,e){if(e!=null&&typeof e=="object")if(Array.isArray(e))for(let[r,n]of e.entries()){let o=[...t,r],i=E.asCID(n);i!=null?yield[o.join("/"),i]:typeof n=="object"&&(yield*Gr(n,o))}else{let r=E.asCID(e);r!=null?yield[t.join("/"),r]:yield*Gr(e,t)}}function*Gr(t,e){if(t==null||t instanceof Uint8Array)return;let r=E.asCID(t);r!=null&&(yield[e.join("/"),r]);for(let[n,o]of Object.entries(t)){let i=[...e,n];yield*ac(i,o)}}function*cc(t,e){if(Array.isArray(e))for(let[r,n]of e.entries()){let o=[...t,r];yield o.join("/"),typeof n=="object"&&E.asCID(n)==null&&(yield*jr(n,o))}else yield*jr(e,t)}function*jr(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"&&E.asCID(n)==null&&(yield*cc(o,n))}}function uc(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=E.asCID(r);if(i!=null)return{value:i,remaining:e.slice(n+1).join("/")}}return{value:r}}var Xr=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:kt(),bytes:kt(),value:kt(),asBlock:kt()})}links(){return Gr(this.value,[])}tree(){return jr(this.value,[])}get(e="/"){return uc(this.value,e.split("/").filter(Boolean))}};function Wr({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 Xr({cid:e,bytes:t,value:o})}var je=class{async*export(e,r){for(let[,n]of r.links())yield n}};var Xe=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 St=class{components;log;constructor(e,r){this.components=e,this.log=e.logger.forComponent("helia:car")}async import(e,r){await ci(this.components.blockstore.putMany(fi(e.blocks(),({cid:n,bytes:o})=>({cid:n,bytes:o})),r))}async*export(e,r){let{writer:n,out:o}=Pe.create(e),i=o[Symbol.asyncIterator](),s=new AbortController;for(this._export(e,n,r).catch(c=>{this.log.error("error during streaming export - %e",c),s.abort(c)});;){let{done:c,value:u}=await Tt(i.next(),s.signal);if(s.signal.aborted)throw s.signal.reason;if(u!=null&&(yield u),c===!0)break}}async _export(e,r,n){let o=Promise.withResolvers(),i=Array.isArray(e)?e:[e],s={currentPath:[],pathsToTarget:null},c=n?.traversal,u=n?.exporter??new je,l=new At({concurrency:1}),p=!1;l.addEventListener("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 x of s.pathsToTarget){let I=x.length-1,w=x[I];x.slice(0,-1).forEach(m=>{l.add(async()=>{await this.#t({cid:m,queue:l,writer:r,strategy:u,options:n,recursive:!1})}).catch(b=>{this.log.error("error during queue operation - %e",b)})}),l.add(async()=>{await this.#t({cid:w,queue:l,writer:r,strategy:u,options:n})}).catch(m=>{this.log.error("error during queue operation - %e",m)})}}else this.log.trace("no paths to target, skipping export"),o.reject(new Error("Could not traverse to target CID(s)"))}),l.addEventListener("failure",x=>{l.clear(),o.reject(x.detail.error)});for(let x of i)l.add(async()=>{this.log.trace("traversing dag from %c",x),await this.#e({cid:x,queue:l,strategy:c??new Xe(x),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#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 qr(this.components.blockstore.get(e,s)),p=Wr({bytes:l,cid:e,codec:u});for await(let x of n.traverse(e,p))r.add(async()=>{await this.#e({cid:x,queue:r,strategy:n,traversalContext:o,parentPath:c??[],options:s})}).catch(I=>{this.log.error("error during traversal queue operation - %e",I)})}async#t({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 qr(this.components.blockstore.get(e,i));if(i?.blockFilter?.add(e.multihash.bytes),await n.put({cid:e,bytes:u}),s){let l=Wr({bytes:u,cid:e,codec:c});for await(let p of o.export(e,l))r.add(async()=>{await this.#t({cid:p,queue:r,writer:n,strategy:o,options:i})}).catch(x=>{this.log.error("error during export queue operation - %e",x)})}}};var Qr=class{async*export(e,r){}};var Z=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 Z("Target CID was not UnixFS - use the SubGraphExporter to export arbitrary graphs");for(let[,n]of r.links())yield n}};var Jr=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 dc=new TextDecoder;function Yr(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 Nt(t,e){let r;[r,e]=Yr(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 di(t,e){let r;return[r,e]=Yr(t,e),[r&7,r>>3,e]}function lc(t){let e={},r=t.length,n=0;for(;n<r;){let o,i;if([o,i,n]=di(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]=Nt(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]=Nt(t,n),e.Name=dc.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]=Yr(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 li(t){let e=t.length,r=0,n,o=!1,i;for(;r<e;){let c,u;if([c,u,r]=di(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]=Nt(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]=Nt(t,r),n.push(lc(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 Yl=new TextEncoder,Zl=2**32,eh=2**31;var nh=new TextEncoder;function hi(t){return t instanceof ArrayBuffer?new Uint8Array(t,0,t.byteLength):t}function pi(t){let e=hi(t),r=li(e),n={};return r.Data&&(n.Data=r.Data),r.Links&&(n.Links=r.Links.map(o=>{let i={};try{i.Hash=E.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 We=class t extends Error{static name="InvalidTypeError";static code="ERR_INVALID_TYPE";name=t.name;code=t.code;constructor(e="Invalid type"){super(e)}},Dt=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 G;(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=()=>Rr(r)})(e=t.DataType||(t.DataType={}));let n;t.codec=()=>(n==null&&(n=Ge((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),Bt.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=Bt.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=>$e(o,t.codec())})(G||(G={}));var Bt;(function(t){let e;t.codec=()=>(e==null&&(e=Ge((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=>$e(r,t.codec())})(Bt||(Bt={}));var mi;(function(t){let e;t.codec=()=>(e==null&&(e=Ge((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=>$e(r,t.codec())})(mi||(mi={}));var yi={Raw:"raw",Directory:"directory",File:"file",Metadata:"metadata",Symlink:"symlink",HAMTShard:"hamt-sharded-directory"},hc=["directory","hamt-sharded-directory"],gi=parseInt("0644",8),xi=parseInt("0755",8),wi=BigInt(1024),_t=class t{static unmarshal(e){let r=G.decode(e);if(r.fanout!=null&&r.fanout>wi)throw new Dt(`Fanout size was too large - ${r.fanout} > ${wi}`);let n=new t({type:yi[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(yi).includes(r))throw new We("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()?xi:gi:this._mode=e&4095}get mode(){return this._mode}isDirectory(){return hc.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=G.DataType.Raw;break;case"directory":e=G.DataType.Directory;break;case"file":e=G.DataType.File;break;case"metadata":e=G.DataType.Metadata;break;case"symlink":e=G.DataType.Symlink;break;case"hamt-sharded-directory":e=G.DataType.HAMTShard;break;default:throw new We(`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===gi&&!this.isDirectory()&&(n=void 0),n===xi&&this.isDirectory()&&(n=void 0));let o;return this.mtime!=null&&(o={Seconds:this.mtime.secs,FractionalNanoseconds:this.mtime.nsecs}),G.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 Zr=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 Z("Target CID is not UnixFS");let n=this.path.shift();if(n==null)return;let o=pi(r.bytes);if(o.Data==null)throw new Z("Target CID has no UnixFS data in decoded bytes");if(_t.unmarshal(o.Data).type==="directory"){let s=o.Links.filter(c=>c.Name===n).pop();if(s==null)throw new Z(`Target CID directory has no link with name ${n}`);yield s.Hash;return}throw new Z("Target CID is not a UnixFS directory")}};function pc(t,e={}){return new St(t,e)}return Ai(mc);})();
|
|
3
3
|
return HeliaCar}));
|
|
4
4
|
//# sourceMappingURL=index.min.js.map
|