@helia/car 4.2.0-34d3ecd7 → 4.2.0-93aa4645
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 +38 -22
- package/dist/src/car.js.map +1 -1
- package/dist/src/index.d.ts +5 -36
- 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 +6 -7
- package/src/car.ts +45 -26
- package/src/index.ts +5 -37
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 yi=Object.create;var Ye=Object.defineProperty;var gi=Object.getOwnPropertyDescriptor;var xi=Object.getOwnPropertyNames;var wi=Object.getPrototypeOf,bi=Object.prototype.hasOwnProperty;var Ie=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),_=(t,e)=>{for(var r in e)Ye(t,r,{get:e[r],enumerable:!0})},jr=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of xi(e))!bi.call(t,o)&&o!==r&&Ye(t,o,{get:()=>e[o],enumerable:!(n=gi(e,o))||n.enumerable});return t};var et=(t,e,r)=>(r=t!=null?yi(wi(t)):{},jr(e||!t||!t.__esModule?Ye(r,"default",{value:t,enumerable:!0}):r,t)),Ei=t=>jr(Ye({},"__esModule",{value:!0}),t);var xo=Ie((Su,go)=>{go.exports=Zt;var yo=128,Vs=127,qs=~Vs,Gs=Math.pow(2,31);function Zt(t,e,r){if(Number.MAX_SAFE_INTEGER&&t>Number.MAX_SAFE_INTEGER)throw Zt.bytes=0,new RangeError("Could not encode varint");e=e||[],r=r||0;for(var n=r;t>=Gs;)e[r++]=t&255|yo,t/=128;for(;t&qs;)e[r++]=t&255|yo,t>>>=7;return e[r]=t|0,Zt.bytes=r-n+1,e}});var Eo=Ie((_u,bo)=>{bo.exports=Yt;var Xs=128,wo=127;function Yt(t,n){var r=0,n=n||0,o=0,i=n,s,c=t.length;do{if(i>=c||o>49)throw Yt.bytes=0,new RangeError("Could not decode varint");s=t[i++],r+=o<28?(s&wo)<<o:(s&wo)*Math.pow(2,o),o+=7}while(s>=Xs);return Yt.bytes=i-n,r}});var ko=Ie((Nu,To)=>{var Ws=Math.pow(2,7),Js=Math.pow(2,14),Ks=Math.pow(2,21),js=Math.pow(2,28),Qs=Math.pow(2,35),Zs=Math.pow(2,42),Ys=Math.pow(2,49),ea=Math.pow(2,56),ta=Math.pow(2,63);To.exports=function(t){return t<Ws?1:t<Js?2:t<Ks?3:t<js?4:t<Qs?5:t<Zs?6:t<Ys?7:t<ea?8:t<ta?9:10}});var mt=Ie((Bu,vo)=>{vo.exports={encode:xo(),decode:Eo(),encodingLength:ko()}});var Ro=Ie((Zf,gr)=>{"use strict";var Ea=Object.prototype.hasOwnProperty,A="~";function Pe(){}Object.create&&(Pe.prototype=Object.create(null),new Pe().__proto__||(A=!1));function Ta(t,e,r){this.fn=t,this.context=e,this.once=r||!1}function Fo(t,e,r,n,o){if(typeof r!="function")throw new TypeError("The listener must be a function");var i=new Ta(r,n||t,o),s=A?A+e:e;return t._events[s]?t._events[s].fn?t._events[s]=[t._events[s],i]:t._events[s].push(i):(t._events[s]=i,t._eventsCount++),t}function wt(t,e){--t._eventsCount===0?t._events=new Pe:delete t._events[e]}function v(){this._events=new Pe,this._eventsCount=0}v.prototype.eventNames=function(){var e=[],r,n;if(this._eventsCount===0)return e;for(n in r=this._events)Ea.call(r,n)&&e.push(A?n.slice(1):n);return Object.getOwnPropertySymbols?e.concat(Object.getOwnPropertySymbols(r)):e};v.prototype.listeners=function(e){var r=A?A+e:e,n=this._events[r];if(!n)return[];if(n.fn)return[n.fn];for(var o=0,i=n.length,s=new Array(i);o<i;o++)s[o]=n[o].fn;return s};v.prototype.listenerCount=function(e){var r=A?A+e:e,n=this._events[r];return n?n.fn?1:n.length:0};v.prototype.emit=function(e,r,n,o,i,s){var c=A?A+e:e;if(!this._events[c])return!1;var u=this._events[c],h=arguments.length,p,m;if(u.fn){switch(u.once&&this.removeListener(e,u.fn,void 0,!0),h){case 1:return u.fn.call(u.context),!0;case 2:return u.fn.call(u.context,r),!0;case 3:return u.fn.call(u.context,r,n),!0;case 4:return u.fn.call(u.context,r,n,o),!0;case 5:return u.fn.call(u.context,r,n,o,i),!0;case 6:return u.fn.call(u.context,r,n,o,i,s),!0}for(m=1,p=new Array(h-1);m<h;m++)p[m-1]=arguments[m];u.fn.apply(u.context,p)}else{var b=u.length,L;for(m=0;m<b;m++)switch(u[m].once&&this.removeListener(e,u[m].fn,void 0,!0),h){case 1:u[m].fn.call(u[m].context);break;case 2:u[m].fn.call(u[m].context,r);break;case 3:u[m].fn.call(u[m].context,r,n);break;case 4:u[m].fn.call(u[m].context,r,n,o);break;default:if(!p)for(L=1,p=new Array(h-1);L<h;L++)p[L-1]=arguments[L];u[m].fn.apply(u[m].context,p)}}return!0};v.prototype.on=function(e,r,n){return Fo(this,e,r,n,!1)};v.prototype.once=function(e,r,n){return Fo(this,e,r,n,!0)};v.prototype.removeListener=function(e,r,n,o){var i=A?A+e:e;if(!this._events[i])return this;if(!r)return wt(this,i),this;var s=this._events[i];if(s.fn)s.fn===r&&(!o||s.once)&&(!n||s.context===n)&&wt(this,i);else{for(var c=0,u=[],h=s.length;c<h;c++)(s[c].fn!==r||o&&!s[c].once||n&&s[c].context!==n)&&u.push(s[c]);u.length?this._events[i]=u.length===1?u[0]:u:wt(this,i)}return this};v.prototype.removeAllListeners=function(e){var r;return e?(r=A?A+e:e,this._events[r]&&wt(this,r)):(this._events=new Pe,this._eventsCount=0),this};v.prototype.off=v.prototype.removeListener;v.prototype.addListener=v.prototype.on;v.prefixed=A;v.EventEmitter=v;typeof gr<"u"&&(gr.exports=v)});var cc={};_(cc,{BlockExporter:()=>Tr,CIDPath:()=>vr,GraphSearch:()=>qe,SubgraphExporter:()=>Ve,UnixFSExporter:()=>kr,UnixFSPath:()=>Kr,car:()=>ac});var Ti=["string","number","bigint","symbol"],ki=["Function","Generator","AsyncGenerator","GeneratorFunction","AsyncGeneratorFunction","AsyncFunction","Observable","Array","Buffer","Object","RegExp","Date","Error","Map","Set","WeakMap","WeakSet","ArrayBuffer","SharedArrayBuffer","DataView","Promise","URL","HTMLElement","Int8Array","Uint8Array","Uint8ClampedArray","Int16Array","Uint16Array","Int32Array","Uint32Array","Float32Array","Float64Array","BigInt64Array","BigUint64Array"];function Qr(t){if(t===null)return"null";if(t===void 0)return"undefined";if(t===!0||t===!1)return"boolean";let e=typeof t;if(Ti.includes(e))return e;if(e==="function")return"Function";if(Array.isArray(t))return"Array";if(vi(t))return"Buffer";let r=Ii(t);return r||"Object"}function vi(t){return t&&t.constructor&&t.constructor.isBuffer&&t.constructor.isBuffer.call(null,t)}function Ii(t){let e=Object.prototype.toString.call(t).slice(8,-1);if(ki.includes(e))return e}var a=class{constructor(e,r,n){this.major=e,this.majorEncoded=e<<5,this.name=r,this.terminal=n}toString(){return`Type[${this.major}].${this.name}`}compare(e){return this.major<e.major?-1:this.major>e.major?1:0}};a.uint=new a(0,"uint",!0);a.negint=new a(1,"negint",!0);a.bytes=new a(2,"bytes",!0);a.string=new a(3,"string",!0);a.array=new a(4,"array",!1);a.map=new a(5,"map",!1);a.tag=new a(6,"tag",!1);a.float=new a(7,"float",!0);a.false=new a(7,"false",!0);a.true=new a(7,"true",!0);a.null=new a(7,"null",!0);a.undefined=new a(7,"undefined",!0);a.break=new a(7,"break",!0);var d=class{constructor(e,r,n){this.type=e,this.value=r,this.encodedLength=n,this.encodedBytes=void 0,this.byteValue=void 0}toString(){return`Token[${this.type}].${this.value}`}};var he=globalThis.process&&!globalThis.process.browser&&globalThis.Buffer&&typeof globalThis.Buffer.isBuffer=="function",Ai=new TextDecoder,Si=new TextEncoder;function tt(t){return he&&globalThis.Buffer.isBuffer(t)}function _t(t){return t instanceof Uint8Array?tt(t)?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):t:Uint8Array.from(t)}var tn=he?(t,e,r)=>r-e>64?globalThis.Buffer.from(t.subarray(e,r)).toString("utf8"):Yr(t,e,r):(t,e,r)=>r-e>64?Ai.decode(t.subarray(e,r)):Yr(t,e,r),rn=he?t=>t.length>64?globalThis.Buffer.from(t):Zr(t):t=>t.length>64?Si.encode(t):Zr(t),W=t=>Uint8Array.from(t),le=he?(t,e,r)=>tt(t)?new Uint8Array(t.subarray(e,r)):t.slice(e,r):(t,e,r)=>t.slice(e,r),nn=he?(t,e)=>(t=t.map(r=>r instanceof Uint8Array?r:globalThis.Buffer.from(r)),_t(globalThis.Buffer.concat(t,e))):(t,e)=>{let r=new Uint8Array(e),n=0;for(let o of t)n+o.length>r.length&&(o=o.subarray(0,r.length-n)),r.set(o,n),n+=o.length;return r},on=he?t=>globalThis.Buffer.allocUnsafe(t):t=>new Uint8Array(t);function sn(t,e){if(tt(t)&&tt(e))return t.compare(e);for(let r=0;r<t.length;r++)if(t[r]!==e[r])return t[r]<e[r]?-1:1;return 0}function Zr(t){let e=[],r=0;for(let n=0;n<t.length;n++){let o=t.charCodeAt(n);o<128?e[r++]=o:o<2048?(e[r++]=o>>6|192,e[r++]=o&63|128):(o&64512)===55296&&n+1<t.length&&(t.charCodeAt(n+1)&64512)===56320?(o=65536+((o&1023)<<10)+(t.charCodeAt(++n)&1023),e[r++]=o>>18|240,e[r++]=o>>12&63|128,e[r++]=o>>6&63|128,e[r++]=o&63|128):(e[r++]=o>>12|224,e[r++]=o>>6&63|128,e[r++]=o&63|128)}return e}function Yr(t,e,r){let n=[];for(;e<r;){let o=t[e],i=null,s=o>239?4:o>223?3:o>191?2:1;if(e+s<=r){let c,u,h,p;switch(s){case 1:o<128&&(i=o);break;case 2:c=t[e+1],(c&192)===128&&(p=(o&31)<<6|c&63,p>127&&(i=p));break;case 3:c=t[e+1],u=t[e+2],(c&192)===128&&(u&192)===128&&(p=(o&15)<<12|(c&63)<<6|u&63,p>2047&&(p<55296||p>57343)&&(i=p));break;case 4:c=t[e+1],u=t[e+2],h=t[e+3],(c&192)===128&&(u&192)===128&&(h&192)===128&&(p=(o&15)<<18|(c&63)<<12|(u&63)<<6|h&63,p>65535&&p<1114112&&(i=p))}}i===null?(i=65533,s=1):i>65535&&(i-=65536,n.push(i>>>10&1023|55296),i=56320|i&1023),n.push(i),e+=s}return _i(n)}var en=4096;function _i(t){let e=t.length;if(e<=en)return String.fromCharCode.apply(String,t);let r="",n=0;for(;n<e;)r+=String.fromCharCode.apply(String,t.slice(n,n+=en));return r}var Ni=256,Ae=class{constructor(e=Ni){this.chunkSize=e,this.cursor=0,this.maxCursor=-1,this.chunks=[],this._initReuseChunk=null}reset(){this.cursor=0,this.maxCursor=-1,this.chunks.length&&(this.chunks=[]),this._initReuseChunk!==null&&(this.chunks.push(this._initReuseChunk),this.maxCursor=this._initReuseChunk.length-1)}push(e){let r=this.chunks[this.chunks.length-1];if(this.cursor+e.length<=this.maxCursor+1){let o=r.length-(this.maxCursor-this.cursor)-1;r.set(e,o)}else{if(r){let o=r.length-(this.maxCursor-this.cursor)-1;o<r.length&&(this.chunks[this.chunks.length-1]=r.subarray(0,o),this.maxCursor=this.cursor-1)}e.length<64&&e.length<this.chunkSize?(r=on(this.chunkSize),this.chunks.push(r),this.maxCursor+=r.length,this._initReuseChunk===null&&(this._initReuseChunk=r),r.set(e,0)):(this.chunks.push(e),this.maxCursor+=e.length)}this.cursor+=e.length}toBytes(e=!1){let r;if(this.chunks.length===1){let n=this.chunks[0];e&&this.cursor>n.length/2?(r=this.cursor===n.length?n:n.subarray(0,this.cursor),this._initReuseChunk=null,this.chunks=[]):r=le(n,0,this.cursor)}else r=nn(this.chunks,this.cursor);return e&&this.reset(),r}};var l="CBOR decode error:",Nt="CBOR encode error:",Se=[];Se[23]=1;Se[24]=2;Se[25]=3;Se[26]=5;Se[27]=9;function Q(t,e,r){if(t.length-e<r)throw new Error(`${l} not enough data for type`)}var E=[24,256,65536,4294967296,BigInt("18446744073709551616")];function N(t,e,r){Q(t,e,1);let n=t[e];if(r.strict===!0&&n<E[0])throw new Error(`${l} integer encoded in more bytes than necessary (strict decode)`);return n}function B(t,e,r){Q(t,e,2);let n=t[e]<<8|t[e+1];if(r.strict===!0&&n<E[1])throw new Error(`${l} integer encoded in more bytes than necessary (strict decode)`);return n}function C(t,e,r){Q(t,e,4);let n=t[e]*16777216+(t[e+1]<<16)+(t[e+2]<<8)+t[e+3];if(r.strict===!0&&n<E[2])throw new Error(`${l} integer encoded in more bytes than necessary (strict decode)`);return n}function D(t,e,r){Q(t,e,8);let n=t[e]*16777216+(t[e+1]<<16)+(t[e+2]<<8)+t[e+3],o=t[e+4]*16777216+(t[e+5]<<16)+(t[e+6]<<8)+t[e+7],i=(BigInt(n)<<BigInt(32))+BigInt(o);if(r.strict===!0&&i<E[3])throw new Error(`${l} integer encoded in more bytes than necessary (strict decode)`);if(i<=Number.MAX_SAFE_INTEGER)return Number(i);if(r.allowBigInt===!0)return i;throw new Error(`${l} integers outside of the safe integer range are not supported`)}function an(t,e,r,n){return new d(a.uint,N(t,e+1,n),2)}function cn(t,e,r,n){return new d(a.uint,B(t,e+1,n),3)}function un(t,e,r,n){return new d(a.uint,C(t,e+1,n),5)}function fn(t,e,r,n){return new d(a.uint,D(t,e+1,n),9)}function F(t,e){return T(t,0,e.value)}function T(t,e,r){if(r<E[0]){let n=Number(r);t.push([e|n])}else if(r<E[1]){let n=Number(r);t.push([e|24,n])}else if(r<E[2]){let n=Number(r);t.push([e|25,n>>>8,n&255])}else if(r<E[3]){let n=Number(r);t.push([e|26,n>>>24&255,n>>>16&255,n>>>8&255,n&255])}else{let n=BigInt(r);if(n<E[4]){let o=[e|27,0,0,0,0,0,0,0],i=Number(n&BigInt(4294967295)),s=Number(n>>BigInt(32)&BigInt(4294967295));o[8]=i&255,i=i>>8,o[7]=i&255,i=i>>8,o[6]=i&255,i=i>>8,o[5]=i&255,o[4]=s&255,s=s>>8,o[3]=s&255,s=s>>8,o[2]=s&255,s=s>>8,o[1]=s&255,t.push(o)}else throw new Error(`${l} encountered BigInt larger than allowable range`)}}F.encodedSize=function(e){return T.encodedSize(e.value)};T.encodedSize=function(e){return e<E[0]?1:e<E[1]?2:e<E[2]?3:e<E[3]?5:9};F.compareTokens=function(e,r){return e.value<r.value?-1:e.value>r.value?1:0};function dn(t,e,r,n){return new d(a.negint,-1-N(t,e+1,n),2)}function hn(t,e,r,n){return new d(a.negint,-1-B(t,e+1,n),3)}function ln(t,e,r,n){return new d(a.negint,-1-C(t,e+1,n),5)}var Bt=BigInt(-1),pn=BigInt(1);function mn(t,e,r,n){let o=D(t,e+1,n);if(typeof o!="bigint"){let i=-1-o;if(i>=Number.MIN_SAFE_INTEGER)return new d(a.negint,i,9)}if(n.allowBigInt!==!0)throw new Error(`${l} integers outside of the safe integer range are not supported`);return new d(a.negint,Bt-BigInt(o),9)}function rt(t,e){let r=e.value,n=typeof r=="bigint"?r*Bt-pn:r*-1-1;T(t,e.type.majorEncoded,n)}rt.encodedSize=function(e){let r=e.value,n=typeof r=="bigint"?r*Bt-pn:r*-1-1;return n<E[0]?1:n<E[1]?2:n<E[2]?3:n<E[3]?5:9};rt.compareTokens=function(e,r){return e.value<r.value?1:e.value>r.value?-1:0};function _e(t,e,r,n){Q(t,e,r+n);let o=le(t,e+r,e+r+n);return new d(a.bytes,o,r+n)}function yn(t,e,r,n){return _e(t,e,1,r)}function gn(t,e,r,n){return _e(t,e,2,N(t,e+1,n))}function xn(t,e,r,n){return _e(t,e,3,B(t,e+1,n))}function wn(t,e,r,n){return _e(t,e,5,C(t,e+1,n))}function bn(t,e,r,n){let o=D(t,e+1,n);if(typeof o=="bigint")throw new Error(`${l} 64-bit integer bytes lengths not supported`);return _e(t,e,9,o)}function nt(t){return t.encodedBytes===void 0&&(t.encodedBytes=t.type===a.string?rn(t.value):t.value),t.encodedBytes}function pe(t,e){let r=nt(e);T(t,e.type.majorEncoded,r.length),t.push(r)}pe.encodedSize=function(e){let r=nt(e);return T.encodedSize(r.length)+r.length};pe.compareTokens=function(e,r){return Ci(nt(e),nt(r))};function Ci(t,e){return t.length<e.length?-1:t.length>e.length?1:sn(t,e)}function Ne(t,e,r,n,o){let i=r+n;Q(t,e,i);let s=new d(a.string,tn(t,e+r,e+i),i);return o.retainStringBytes===!0&&(s.byteValue=le(t,e+r,e+i)),s}function En(t,e,r,n){return Ne(t,e,1,r,n)}function Tn(t,e,r,n){return Ne(t,e,2,N(t,e+1,n),n)}function kn(t,e,r,n){return Ne(t,e,3,B(t,e+1,n),n)}function vn(t,e,r,n){return Ne(t,e,5,C(t,e+1,n),n)}function In(t,e,r,n){let o=D(t,e+1,n);if(typeof o=="bigint")throw new Error(`${l} 64-bit integer string lengths not supported`);return Ne(t,e,9,o,n)}var An=pe;function me(t,e,r,n){return new d(a.array,n,r)}function Sn(t,e,r,n){return me(t,e,1,r)}function _n(t,e,r,n){return me(t,e,2,N(t,e+1,n))}function Nn(t,e,r,n){return me(t,e,3,B(t,e+1,n))}function Bn(t,e,r,n){return me(t,e,5,C(t,e+1,n))}function Cn(t,e,r,n){let o=D(t,e+1,n);if(typeof o=="bigint")throw new Error(`${l} 64-bit integer array lengths not supported`);return me(t,e,9,o)}function Dn(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${l} indefinite length items not allowed`);return me(t,e,1,1/0)}function ot(t,e){T(t,a.array.majorEncoded,e.value)}ot.compareTokens=F.compareTokens;ot.encodedSize=function(e){return T.encodedSize(e.value)};function ye(t,e,r,n){return new d(a.map,n,r)}function Un(t,e,r,n){return ye(t,e,1,r)}function Ln(t,e,r,n){return ye(t,e,2,N(t,e+1,n))}function zn(t,e,r,n){return ye(t,e,3,B(t,e+1,n))}function Fn(t,e,r,n){return ye(t,e,5,C(t,e+1,n))}function Rn(t,e,r,n){let o=D(t,e+1,n);if(typeof o=="bigint")throw new Error(`${l} 64-bit integer map lengths not supported`);return ye(t,e,9,o)}function Mn(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${l} indefinite length items not allowed`);return ye(t,e,1,1/0)}function it(t,e){T(t,a.map.majorEncoded,e.value)}it.compareTokens=F.compareTokens;it.encodedSize=function(e){return T.encodedSize(e.value)};function On(t,e,r,n){return new d(a.tag,r,1)}function Pn(t,e,r,n){return new d(a.tag,N(t,e+1,n),2)}function $n(t,e,r,n){return new d(a.tag,B(t,e+1,n),3)}function Hn(t,e,r,n){return new d(a.tag,C(t,e+1,n),5)}function Vn(t,e,r,n){return new d(a.tag,D(t,e+1,n),9)}function st(t,e){T(t,a.tag.majorEncoded,e.value)}st.compareTokens=F.compareTokens;st.encodedSize=function(e){return T.encodedSize(e.value)};var Ri=20,Mi=21,Oi=22,Pi=23;function qn(t,e,r,n){if(n.allowUndefined===!1)throw new Error(`${l} undefined values are not supported`);return n.coerceUndefinedToNull===!0?new d(a.null,null,1):new d(a.undefined,void 0,1)}function Gn(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${l} indefinite length items not allowed`);return new d(a.break,void 0,1)}function Ct(t,e,r){if(r){if(r.allowNaN===!1&&Number.isNaN(t))throw new Error(`${l} NaN values are not supported`);if(r.allowInfinity===!1&&(t===1/0||t===-1/0))throw new Error(`${l} Infinity values are not supported`)}return new d(a.float,t,e)}function Xn(t,e,r,n){return Ct(Dt(t,e+1),3,n)}function Wn(t,e,r,n){return Ct(Ut(t,e+1),5,n)}function Jn(t,e,r,n){return Ct(Zn(t,e+1),9,n)}function at(t,e,r){let n=e.value;if(n===!1)t.push([a.float.majorEncoded|Ri]);else if(n===!0)t.push([a.float.majorEncoded|Mi]);else if(n===null)t.push([a.float.majorEncoded|Oi]);else if(n===void 0)t.push([a.float.majorEncoded|Pi]);else{let o,i=!1;(!r||r.float64!==!0)&&(jn(n),o=Dt(P,1),n===o||Number.isNaN(n)?(P[0]=249,t.push(P.slice(0,3)),i=!0):(Qn(n),o=Ut(P,1),n===o&&(P[0]=250,t.push(P.slice(0,5)),i=!0))),i||($i(n),o=Zn(P,1),P[0]=251,t.push(P.slice(0,9)))}}at.encodedSize=function(e,r){let n=e.value;if(n===!1||n===!0||n===null||n===void 0)return 1;if(!r||r.float64!==!0){jn(n);let o=Dt(P,1);if(n===o||Number.isNaN(n))return 3;if(Qn(n),o=Ut(P,1),n===o)return 5}return 9};var Kn=new ArrayBuffer(9),R=new DataView(Kn,1),P=new Uint8Array(Kn,0);function jn(t){if(t===1/0)R.setUint16(0,31744,!1);else if(t===-1/0)R.setUint16(0,64512,!1);else if(Number.isNaN(t))R.setUint16(0,32256,!1);else{R.setFloat32(0,t);let e=R.getUint32(0),r=(e&2139095040)>>23,n=e&8388607;if(r===255)R.setUint16(0,31744,!1);else if(r===0)R.setUint16(0,(t&2147483648)>>16|n>>13,!1);else{let o=r-127;o<-24?R.setUint16(0,0):o<-14?R.setUint16(0,(e&2147483648)>>16|1<<24+o,!1):R.setUint16(0,(e&2147483648)>>16|o+15<<10|n>>13,!1)}}}function Dt(t,e){if(t.length-e<2)throw new Error(`${l} not enough data for float16`);let r=(t[e]<<8)+t[e+1];if(r===31744)return 1/0;if(r===64512)return-1/0;if(r===32256)return NaN;let n=r>>10&31,o=r&1023,i;return n===0?i=o*2**-24:n!==31?i=(o+1024)*2**(n-25):i=o===0?1/0:NaN,r&32768?-i:i}function Qn(t){R.setFloat32(0,t,!1)}function Ut(t,e){if(t.length-e<4)throw new Error(`${l} not enough data for float32`);let r=(t.byteOffset||0)+e;return new DataView(t.buffer,r,4).getFloat32(0,!1)}function $i(t){R.setFloat64(0,t,!1)}function Zn(t,e){if(t.length-e<8)throw new Error(`${l} not enough data for float64`);let r=(t.byteOffset||0)+e;return new DataView(t.buffer,r,8).getFloat64(0,!1)}at.compareTokens=F.compareTokens;function y(t,e,r){throw new Error(`${l} encountered invalid minor (${r}) for major ${t[e]>>>5}`)}function ct(t){return()=>{throw new Error(`${l} ${t}`)}}var f=[];for(let t=0;t<=23;t++)f[t]=y;f[24]=an;f[25]=cn;f[26]=un;f[27]=fn;f[28]=y;f[29]=y;f[30]=y;f[31]=y;for(let t=32;t<=55;t++)f[t]=y;f[56]=dn;f[57]=hn;f[58]=ln;f[59]=mn;f[60]=y;f[61]=y;f[62]=y;f[63]=y;for(let t=64;t<=87;t++)f[t]=yn;f[88]=gn;f[89]=xn;f[90]=wn;f[91]=bn;f[92]=y;f[93]=y;f[94]=y;f[95]=ct("indefinite length bytes/strings are not supported");for(let t=96;t<=119;t++)f[t]=En;f[120]=Tn;f[121]=kn;f[122]=vn;f[123]=In;f[124]=y;f[125]=y;f[126]=y;f[127]=ct("indefinite length bytes/strings are not supported");for(let t=128;t<=151;t++)f[t]=Sn;f[152]=_n;f[153]=Nn;f[154]=Bn;f[155]=Cn;f[156]=y;f[157]=y;f[158]=y;f[159]=Dn;for(let t=160;t<=183;t++)f[t]=Un;f[184]=Ln;f[185]=zn;f[186]=Fn;f[187]=Rn;f[188]=y;f[189]=y;f[190]=y;f[191]=Mn;for(let t=192;t<=215;t++)f[t]=On;f[216]=Pn;f[217]=$n;f[218]=Hn;f[219]=Vn;f[220]=y;f[221]=y;f[222]=y;f[223]=y;for(let t=224;t<=243;t++)f[t]=ct("simple values are not supported");f[244]=y;f[245]=y;f[246]=y;f[247]=qn;f[248]=ct("simple values are not supported");f[249]=Xn;f[250]=Wn;f[251]=Jn;f[252]=y;f[253]=y;f[254]=y;f[255]=Gn;var $=[];for(let t=0;t<24;t++)$[t]=new d(a.uint,t,1);for(let t=-1;t>=-24;t--)$[31-t]=new d(a.negint,t,1);$[64]=new d(a.bytes,new Uint8Array(0),1);$[96]=new d(a.string,"",1);$[128]=new d(a.array,0,1);$[160]=new d(a.map,0,1);$[244]=new d(a.false,!1,1);$[245]=new d(a.true,!0,1);$[246]=new d(a.null,null,1);function Lt(t){switch(t.type){case a.false:return W([244]);case a.true:return W([245]);case a.null:return W([246]);case a.bytes:return t.value.length?void 0:W([64]);case a.string:return t.value===""?W([96]):void 0;case a.array:return t.value===0?W([128]):void 0;case a.map:return t.value===0?W([160]):void 0;case a.uint:return t.value<24?W([Number(t.value)]):void 0;case a.negint:if(t.value>=-24)return W([31-Number(t.value)])}}var Vi={float64:!1,mapSorter:Gi,quickEncodeToken:Lt};function Ft(){let t=[];return t[a.uint.major]=F,t[a.negint.major]=rt,t[a.bytes.major]=pe,t[a.string.major]=An,t[a.array.major]=ot,t[a.map.major]=it,t[a.tag.major]=st,t[a.float.major]=at,t}var Yn=Ft(),zt=new Ae,ut=class t{constructor(e,r){this.obj=e,this.parent=r}includes(e){let r=this;do if(r.obj===e)return!0;while(r=r.parent);return!1}static createCheck(e,r){if(e&&e.includes(r))throw new Error(`${Nt} object contains circular references`);return new t(r,e)}},te={null:new d(a.null,null),undefined:new d(a.undefined,void 0),true:new d(a.true,!0),false:new d(a.false,!1),emptyArray:new d(a.array,0),emptyMap:new d(a.map,0)},re={number(t,e,r,n){return!Number.isInteger(t)||!Number.isSafeInteger(t)?new d(a.float,t):t>=0?new d(a.uint,t):new d(a.negint,t)},bigint(t,e,r,n){return t>=BigInt(0)?new d(a.uint,t):new d(a.negint,t)},Uint8Array(t,e,r,n){return new d(a.bytes,t)},string(t,e,r,n){return new d(a.string,t)},boolean(t,e,r,n){return t?te.true:te.false},null(t,e,r,n){return te.null},undefined(t,e,r,n){return te.undefined},ArrayBuffer(t,e,r,n){return new d(a.bytes,new Uint8Array(t))},DataView(t,e,r,n){return new d(a.bytes,new Uint8Array(t.buffer,t.byteOffset,t.byteLength))},Array(t,e,r,n){if(!t.length)return r.addBreakTokens===!0?[te.emptyArray,new d(a.break)]:te.emptyArray;n=ut.createCheck(n,t);let o=[],i=0;for(let s of t)o[i++]=Be(s,r,n);return r.addBreakTokens?[new d(a.array,t.length),o,new d(a.break)]:[new d(a.array,t.length),o]},Object(t,e,r,n){let o=e!=="Object",i=o?t.keys():Object.keys(t),s=o?t.size:i.length;if(!s)return r.addBreakTokens===!0?[te.emptyMap,new d(a.break)]:te.emptyMap;n=ut.createCheck(n,t);let c=[],u=0;for(let h of i)c[u++]=[Be(h,r,n),Be(o?t.get(h):t[h],r,n)];return qi(c,r),r.addBreakTokens?[new d(a.map,s),c,new d(a.break)]:[new d(a.map,s),c]}};re.Map=re.Object;re.Buffer=re.Uint8Array;for(let t of"Uint8Clamped Uint16 Uint32 Int8 Int16 Int32 BigUint64 BigInt64 Float32 Float64".split(" "))re[`${t}Array`]=re.DataView;function Be(t,e={},r){let n=Qr(t),o=e&&e.typeEncoders&&e.typeEncoders[n]||re[n];if(typeof o=="function"){let s=o(t,n,e,r);if(s!=null)return s}let i=re[n];if(!i)throw new Error(`${Nt} unsupported type: ${n}`);return i(t,n,e,r)}function qi(t,e){e.mapSorter&&t.sort(e.mapSorter)}function Gi(t,e){let r=Array.isArray(t[0])?t[0][0]:t[0],n=Array.isArray(e[0])?e[0][0]:e[0];if(r.type!==n.type)return r.type.compare(n.type);let o=r.type.major,i=Yn[o].compareTokens(r,n);return i===0&&console.warn("WARNING: complex key types used, CBOR key sorting guarantees are gone"),i}function eo(t,e,r,n){if(Array.isArray(e))for(let o of e)eo(t,o,r,n);else r[e.type.major](t,e,n)}function Xi(t,e,r){let n=Be(t,r);if(!Array.isArray(n)&&r.quickEncodeToken){let o=r.quickEncodeToken(n);if(o)return o;let i=e[n.type.major];if(i.encodedSize){let s=i.encodedSize(n,r),c=new Ae(s);if(i(c,n,r),c.chunks.length!==1)throw new Error(`Unexpected error: pre-calculated length for ${n} was wrong`);return _t(c.chunks[0])}}return zt.reset(),eo(zt,n,e,r),zt.toBytes(!0)}function Rt(t,e){return e=Object.assign({},Vi,e),Xi(t,Yn,e)}var Wi={strict:!1,allowIndefinite:!0,allowUndefined:!0,allowBigInt:!0},ft=class{constructor(e,r={}){this._pos=0,this.data=e,this.options=r}pos(){return this._pos}done(){return this._pos>=this.data.length}next(){let e=this.data[this._pos],r=$[e];if(r===void 0){let n=f[e];if(!n)throw new Error(`${l} no decoder for major type ${e>>>5} (byte 0x${e.toString(16).padStart(2,"0")})`);let o=e&31;r=n(this.data,this._pos,o,this.options)}return this._pos+=r.encodedLength,r}},Ce=Symbol.for("DONE"),dt=Symbol.for("BREAK");function Ji(t,e,r){let n=[];for(let o=0;o<t.value;o++){let i=ge(e,r);if(i===dt){if(t.value===1/0)break;throw new Error(`${l} got unexpected break to lengthed array`)}if(i===Ce)throw new Error(`${l} found array but not enough entries (got ${o}, expected ${t.value})`);n[o]=i}return n}function Ki(t,e,r){let n=r.useMaps===!0,o=n?void 0:{},i=n?new Map:void 0;for(let s=0;s<t.value;s++){let c=ge(e,r);if(c===dt){if(t.value===1/0)break;throw new Error(`${l} got unexpected break to lengthed map`)}if(c===Ce)throw new Error(`${l} found map but not enough entries (got ${s} [no key], expected ${t.value})`);if(n!==!0&&typeof c!="string")throw new Error(`${l} non-string keys not supported (got ${typeof c})`);if(r.rejectDuplicateMapKeys===!0&&(n&&i.has(c)||!n&&c in o))throw new Error(`${l} found repeat map key "${c}"`);let u=ge(e,r);if(u===Ce)throw new Error(`${l} found map but not enough entries (got ${s} [no value], expected ${t.value})`);n?i.set(c,u):o[c]=u}return n?i:o}function ge(t,e){if(t.done())return Ce;let r=t.next();if(r.type===a.break)return dt;if(r.type.terminal)return r.value;if(r.type===a.array)return Ji(r,t,e);if(r.type===a.map)return Ki(r,t,e);if(r.type===a.tag){if(e.tags&&typeof e.tags[r.value]=="function"){let n=ge(t,e);return e.tags[r.value](n)}throw new Error(`${l} tag not supported (${r.value})`)}throw new Error("unsupported")}function to(t,e){if(!(t instanceof Uint8Array))throw new Error(`${l} data to decode must be a Uint8Array`);e=Object.assign({},Wi,e);let r=e.tokenizer||new ft(t,e),n=ge(r,e);if(n===Ce)throw new Error(`${l} did not find any content to decode`);if(n===dt)throw new Error(`${l} got unexpected break`);return[n,t.subarray(r.pos())]}function Mt(t,e){let[r,n]=to(t,e);if(n.length>0)throw new Error(`${l} too many terminals, data makes no sense`);return r}var qt={};_(qt,{base32:()=>we,base32hex:()=>ss,base32hexpad:()=>cs,base32hexpadupper:()=>us,base32hexupper:()=>as,base32pad:()=>os,base32padupper:()=>is,base32upper:()=>ns,base32z:()=>fs});var au=new Uint8Array(0);function ro(t,e){if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;for(let r=0;r<t.byteLength;r++)if(t[r]!==e[r])return!1;return!0}function Z(t){if(t instanceof Uint8Array&&t.constructor.name==="Uint8Array")return t;if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.isView(t))return new Uint8Array(t.buffer,t.byteOffset,t.byteLength);throw new Error("Unknown type, must be binary type")}function no(t){return new TextEncoder().encode(t)}function oo(t){return new TextDecoder().decode(t)}function Qi(t,e){if(t.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),n=0;n<r.length;n++)r[n]=255;for(var o=0;o<t.length;o++){var i=t.charAt(o),s=i.charCodeAt(0);if(r[s]!==255)throw new TypeError(i+" is ambiguous");r[s]=o}var c=t.length,u=t.charAt(0),h=Math.log(c)/Math.log(256),p=Math.log(256)/Math.log(c);function m(g){if(g instanceof Uint8Array||(ArrayBuffer.isView(g)?g=new Uint8Array(g.buffer,g.byteOffset,g.byteLength):Array.isArray(g)&&(g=Uint8Array.from(g))),!(g instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(g.length===0)return"";for(var k=0,ae=0,M=0,q=g.length;M!==q&&g[M]===0;)M++,k++;for(var G=(q-M)*p+1>>>0,z=new Uint8Array(G);M!==q;){for(var X=g[M],ee=0,O=G-1;(X!==0||ee<ae)&&O!==-1;O--,ee++)X+=256*z[O]>>>0,z[O]=X%c>>>0,X=X/c>>>0;if(X!==0)throw new Error("Non-zero carry");ae=ee,M++}for(var j=G-ae;j!==G&&z[j]===0;)j++;for(var Ze=u.repeat(k);j<G;++j)Ze+=t.charAt(z[j]);return Ze}function b(g){if(typeof g!="string")throw new TypeError("Expected String");if(g.length===0)return new Uint8Array;var k=0;if(g[k]!==" "){for(var ae=0,M=0;g[k]===u;)ae++,k++;for(var q=(g.length-k)*h+1>>>0,G=new Uint8Array(q);g[k];){var z=r[g.charCodeAt(k)];if(z===255)return;for(var X=0,ee=q-1;(z!==0||X<M)&&ee!==-1;ee--,X++)z+=c*G[ee]>>>0,G[ee]=z%256>>>0,z=z/256>>>0;if(z!==0)throw new Error("Non-zero carry");M=X,k++}if(g[k]!==" "){for(var O=q-M;O!==q&&G[O]===0;)O++;for(var j=new Uint8Array(ae+(q-O)),Ze=ae;O!==q;)j[Ze++]=G[O++];return j}}}function L(g){var k=b(g);if(k)return k;throw new Error(`Non-${e} character`)}return{encode:m,decodeUnsafe:b,decode:L}}var Zi=Qi,Yi=Zi,io=Yi;var Pt=class{name;prefix;baseEncode;constructor(e,r,n){this.name=e,this.prefix=r,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},$t=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,r,n){this.name=e,this.prefix=r;let o=r.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(e){if(typeof e=="string"){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(e){return so(this,e)}},Ht=class{decoders;constructor(e){this.decoders=e}or(e){return so(this,e)}decode(e){let r=e[0],n=this.decoders[r];if(n!=null)return n.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function so(t,e){return new Ht({...t.decoders??{[t.prefix]:t},...e.decoders??{[e.prefix]:e}})}var Vt=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,r,n,o){this.name=e,this.prefix=r,this.baseEncode=n,this.baseDecode=o,this.encoder=new Pt(e,r,n),this.decoder=new $t(e,r,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function xe({name:t,prefix:e,encode:r,decode:n}){return new Vt(t,e,r,n)}function ne({name:t,prefix:e,alphabet:r}){let{encode:n,decode:o}=io(r,t);return xe({prefix:e,name:t,encode:n,decode:i=>Z(o(i))})}function es(t,e,r,n){let o=t.length;for(;t[o-1]==="=";)--o;let i=new Uint8Array(o*r/8|0),s=0,c=0,u=0;for(let h=0;h<o;++h){let p=e[t[h]];if(p===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<r|p,s+=r,s>=8&&(s-=8,i[u++]=255&c>>s)}if(s>=r||(255&c<<8-s)!==0)throw new SyntaxError("Unexpected end of data");return i}function ts(t,e,r){let n=e[e.length-1]==="=",o=(1<<r)-1,i="",s=0,c=0;for(let u=0;u<t.length;++u)for(c=c<<8|t[u],s+=8;s>r;)s-=r,i+=e[o&c>>s];if(s!==0&&(i+=e[o&c<<r-s]),n)for(;(i.length*r&7)!==0;)i+="=";return i}function rs(t){let e={};for(let r=0;r<t.length;++r)e[t[r]]=r;return e}function w({name:t,prefix:e,bitsPerChar:r,alphabet:n}){let o=rs(n);return xe({prefix:e,name:t,encode(i){return ts(i,n,r)},decode(i){return es(i,o,r,t)}})}var we=w({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),ns=w({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),os=w({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),is=w({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),ss=w({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),as=w({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),cs=w({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),us=w({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),fs=w({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Gt={};_(Gt,{base36:()=>De,base36upper:()=>ds});var De=ne({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),ds=ne({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Xt={};_(Xt,{base58btc:()=>J,base58flickr:()=>hs});var J=ne({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),hs=ne({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var ls=uo,ao=128,ps=127,ms=~ps,ys=Math.pow(2,31);function uo(t,e,r){e=e||[],r=r||0;for(var n=r;t>=ys;)e[r++]=t&255|ao,t/=128;for(;t&ms;)e[r++]=t&255|ao,t>>>=7;return e[r]=t|0,uo.bytes=r-n+1,e}var gs=Wt,xs=128,co=127;function Wt(t,n){var r=0,n=n||0,o=0,i=n,s,c=t.length;do{if(i>=c)throw Wt.bytes=0,new RangeError("Could not decode varint");s=t[i++],r+=o<28?(s&co)<<o:(s&co)*Math.pow(2,o),o+=7}while(s>=xs);return Wt.bytes=i-n,r}var ws=Math.pow(2,7),bs=Math.pow(2,14),Es=Math.pow(2,21),Ts=Math.pow(2,28),ks=Math.pow(2,35),vs=Math.pow(2,42),Is=Math.pow(2,49),As=Math.pow(2,56),Ss=Math.pow(2,63),_s=function(t){return t<ws?1:t<bs?2:t<Es?3:t<Ts?4:t<ks?5:t<vs?6:t<Is?7:t<As?8:t<Ss?9:10},Ns={encode:ls,decode:gs,encodingLength:_s},Bs=Ns,Ue=Bs;function Le(t,e=0){return[Ue.decode(t,e),Ue.decode.bytes]}function be(t,e,r=0){return Ue.encode(t,e,r),e}function Ee(t){return Ue.encodingLength(t)}function ke(t,e){let r=e.byteLength,n=Ee(t),o=n+Ee(r),i=new Uint8Array(o+r);return be(t,i,0),be(r,i,n),i.set(e,o),new Te(t,r,e,i)}function lt(t){let e=Z(t),[r,n]=Le(e),[o,i]=Le(e.subarray(n)),s=e.subarray(n+i);if(s.byteLength!==o)throw new Error("Incorrect length");return new Te(r,o,s,e)}function fo(t,e){if(t===e)return!0;{let r=e;return t.code===r.code&&t.size===r.size&&r.bytes instanceof Uint8Array&&ro(t.bytes,r.bytes)}}var Te=class{code;size;digest;bytes;constructor(e,r,n,o){this.code=e,this.size=r,this.digest=n,this.bytes=o}};function ho(t,e){let{bytes:r,version:n}=t;switch(n){case 0:return Ds(r,Jt(t),e??J.encoder);default:return Us(r,Jt(t),e??we.encoder)}}var lo=new WeakMap;function Jt(t){let e=lo.get(t);if(e==null){let r=new Map;return lo.set(t,r),r}return e}var x=class t{code;version;multihash;bytes;"/";constructor(e,r,n,o){this.code=r,this.version=e,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:e,multihash:r}=this;if(e!==ze)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==Ls)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return t.createV0(r)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:e,digest:r}=this.multihash,n=ke(e,r);return t.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(e){return t.equals(this,e)}static equals(e,r){let n=r;return n!=null&&e.code===n.code&&e.version===n.version&&fo(e.multihash,n.multihash)}toString(e){return ho(this,e)}toJSON(){return{"/":ho(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(e){if(e==null)return null;let r=e;if(r instanceof t)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:o,multihash:i,bytes:s}=r;return new t(n,o,i,s??po(n,o,i.bytes))}else if(r[zs]===!0){let{version:n,multihash:o,code:i}=r,s=lt(o);return t.create(n,i,s)}else return null}static create(e,r,n){if(typeof r!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(e){case 0:{if(r!==ze)throw new Error(`Version 0 CID must use dag-pb (code: ${ze}) block encoding`);return new t(e,r,n,n.bytes)}case 1:{let o=po(e,r,n.bytes);return new t(e,r,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return t.create(0,ze,e)}static createV1(e,r){return t.create(1,e,r)}static decode(e){let[r,n]=t.decodeFirst(e);if(n.length!==0)throw new Error("Incorrect length");return r}static decodeFirst(e){let r=t.inspectBytes(e),n=r.size-r.multihashSize,o=Z(e.subarray(n,n+r.multihashSize));if(o.byteLength!==r.multihashSize)throw new Error("Incorrect length");let i=o.subarray(r.multihashSize-r.digestSize),s=new Te(r.multihashCode,r.digestSize,i,o);return[r.version===0?t.createV0(s):t.createV1(r.codec,s),e.subarray(r.size)]}static inspectBytes(e){let r=0,n=()=>{let[m,b]=Le(e.subarray(r));return r+=b,m},o=n(),i=ze;if(o===18?(o=0,r=0):i=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let s=r,c=n(),u=n(),h=r+u,p=h-s;return{version:o,codec:i,multihashCode:c,digestSize:u,multihashSize:p,size:h}}static parse(e,r){let[n,o]=Cs(e,r),i=t.decode(o);if(i.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Jt(i).set(n,e),i}};function Cs(t,e){switch(t[0]){case"Q":{let r=e??J;return[J.prefix,r.decode(`${J.prefix}${t}`)]}case J.prefix:{let r=e??J;return[J.prefix,r.decode(t)]}case we.prefix:{let r=e??we;return[we.prefix,r.decode(t)]}case De.prefix:{let r=e??De;return[De.prefix,r.decode(t)]}default:{if(e==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[t[0],e.decode(t)]}}}function Ds(t,e,r){let{prefix:n}=r;if(n!==J.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let o=e.get(n);if(o==null){let i=r.encode(t).slice(1);return e.set(n,i),i}else return o}function Us(t,e,r){let{prefix:n}=r,o=e.get(n);if(o==null){let i=r.encode(t);return e.set(n,i),i}else return o}var ze=112,Ls=18;function po(t,e,r){let n=Ee(t),o=n+Ee(e),i=new Uint8Array(o+r.byteLength);return be(t,i,0),be(e,i,n),i.set(r,o),i}var zs=Symbol.for("@ipld/js-cid/CID");var mo=42;function Fs(t){return t instanceof ArrayBuffer?new Uint8Array(t,0,t.byteLength):t}function Rs(t){if(t.asCID!==t&&t["/"]!==t.bytes)return null;let e=x.asCID(t);if(!e)return null;let r=new Uint8Array(e.bytes.byteLength+1);return r.set(e.bytes,1),[new d(a.tag,mo),new d(a.bytes,r)]}function Ms(){throw new Error("`undefined` is not supported by the IPLD Data Model and cannot be encoded")}function Os(t){if(Number.isNaN(t))throw new Error("`NaN` is not supported by the IPLD Data Model and cannot be encoded");if(t===1/0||t===-1/0)throw new Error("`Infinity` and `-Infinity` is not supported by the IPLD Data Model and cannot be encoded");return null}function Ps(t){for(let e of t.keys())if(typeof e!="string"||e.length===0)throw new Error("Non-string Map keys are not supported by the IPLD Data Model and cannot be encoded");return null}var Kt={float64:!0,typeEncoders:{Map:Ps,Object:Rs,undefined:Ms,number:Os}},Iu={...Kt,typeEncoders:{...Kt.typeEncoders}};function $s(t){if(t[0]!==0)throw new Error("Invalid CID for CBOR tag 42; expected leading 0x00");return x.decode(t.subarray(1))}var pt={allowIndefinite:!1,coerceUndefinedToNull:!0,allowNaN:!1,allowInfinity:!1,allowBigInt:!0,strict:!0,useMaps:!1,rejectDuplicateMapKeys:!0,tags:[]};pt.tags[mo]=$s;var Au={...pt,tags:pt.tags.slice()};var jt=t=>Rt(t,Kt),Qt=t=>Mt(Fs(t),pt);var er=et(mt(),1);var tr=40;function rr(t,e){if(!t.length)throw new Error("Unexpected end of data");let r=er.default.decode(t);return e.seek(er.default.decode.bytes),r}function nr(t){let e=new DataView(t.buffer,t.byteOffset,t.byteLength),r=0;return{version:2,characteristics:[e.getBigUint64(r,!0),e.getBigUint64(r+=8,!0)],dataOffset:Number(e.getBigUint64(r+=8,!0)),dataSize:Number(e.getBigUint64(r+=8,!0)),indexOffset:Number(e.getBigUint64(r+=8,!0))}}var oe={Null:t=>t===null?t:void 0,Int:t=>Number.isInteger(t)?t:void 0,Float:t=>typeof t=="number"&&Number.isFinite(t)?t:void 0,String:t=>typeof t=="string"?t:void 0,Bool:t=>typeof t=="boolean"?t:void 0,Bytes:t=>t instanceof Uint8Array?t:void 0,Link:t=>t!==null&&typeof t=="object"&&t.asCID===t?t:void 0,List:t=>Array.isArray(t)?t:void 0,Map:t=>t!==null&&typeof t=="object"&&t.asCID!==t&&!Array.isArray(t)&&!(t instanceof Uint8Array)?t:void 0},Fe={"CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)":oe.Link,"CarV1HeaderOrV2Pragma > roots (anon)":t=>{if(oe.List(t)!==void 0){for(let e=0;e<t.length;e++){let r=t[e];if(r=Fe["CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)"](r),r===void 0)return;if(r!==t[e]){let n=t.slice(0,e);for(let o=e;o<t.length;o++){let i=t[o];if(i=Fe["CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)"](i),i===void 0)return;n.push(i)}return n}}return t}},Int:oe.Int,CarV1HeaderOrV2Pragma:t=>{if(oe.Map(t)===void 0)return;let e=Object.entries(t),r=t,n=1;for(let o=0;o<e.length;o++){let[i,s]=e[o];switch(i){case"roots":{let c=Fe["CarV1HeaderOrV2Pragma > roots (anon)"](t[i]);if(c===void 0)return;if(c!==s||r!==t){if(r===t){r={};for(let u=0;u<o;u++)r[e[u][0]]=e[u][1]}r.roots=c}}break;case"version":{n--;let c=Fe.Int(t[i]);if(c===void 0)return;if(c!==s||r!==t){if(r===t){r={};for(let u=0;u<o;u++)r[e[u][0]]=e[u][1]}r.version=c}}break;default:return}}if(!(n>0))return r}},Re={"CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)":oe.Link,"CarV1HeaderOrV2Pragma > roots (anon)":t=>{if(oe.List(t)!==void 0){for(let e=0;e<t.length;e++){let r=t[e];if(r=Re["CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)"](r),r===void 0)return;if(r!==t[e]){let n=t.slice(0,e);for(let o=e;o<t.length;o++){let i=t[o];if(i=Re["CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)"](i),i===void 0)return;n.push(i)}return n}}return t}},Int:oe.Int,CarV1HeaderOrV2Pragma:t=>{if(oe.Map(t)===void 0)return;let e=Object.entries(t),r=t,n=1;for(let o=0;o<e.length;o++){let[i,s]=e[o];switch(i){case"roots":{let c=Re["CarV1HeaderOrV2Pragma > roots (anon)"](s);if(c===void 0)return;if(c!==s||r!==t){if(r===t){r={};for(let u=0;u<o;u++)r[e[u][0]]=e[u][1]}r.roots=c}}break;case"version":{n--;let c=Re.Int(s);if(c===void 0)return;if(c!==s||r!==t){if(r===t){r={};for(let u=0;u<o;u++)r[e[u][0]]=e[u][1]}r.version=c}}break;default:return}}if(!(n>0))return r}},or={toTyped:Fe.CarV1HeaderOrV2Pragma,toRepresentation:Re.CarV1HeaderOrV2Pragma};var $u=Ft();var ia=et(mt(),1);var Xu=[new d(a.map,2),new d(a.string,"version"),new d(a.uint,1),new d(a.string,"roots")],Wu=new d(a.tag,42);async function ir(t,e){let r=rr(await t.upTo(8),t);if(r===0)throw new Error("Invalid CAR header (zero length)");let n=await t.exactly(r,!0),o=Qt(n);if(or.toTyped(o)===void 0)throw new Error("Invalid CAR header format");if(o.version!==1&&o.version!==2||e!==void 0&&o.version!==e)throw new Error(`Invalid CAR version: ${o.version}${e!==void 0?` (expected ${e})`:""}`);if(o.version===1){if(!Array.isArray(o.roots))throw new Error("Invalid CAR header format");return o}if(o.roots!==void 0)throw new Error("Invalid CAR header format");let i=nr(await t.exactly(tr,!0));t.seek(i.dataOffset-t.pos);let s=await ir(t,1);return Object.assign(s,i)}function Me(t){let e=0;return{async upTo(r){return t.subarray(e,e+Math.min(r,t.length-e))},async exactly(r,n=!1){if(r>t.length-e)throw new Error("Unexpected end of data");let o=t.subarray(e,e+r);return n&&(e+=r),o},seek(r){e+=r},get pos(){return e}}}var sr=et(mt(),1),So=1;function ar(t){let e=jt({version:So,roots:t}),r=sr.default.encode(e.length),n=new Uint8Array(r.length+e.length);return n.set(r,0),n.set(e,r.length),n}function _o(t){return{async setRoots(e){let r=ar(e);await t.write(r)},async writeBlock(e){let{cid:r,bytes:n}=e;await t.write(new Uint8Array(sr.default.encode(r.bytes.length+n.length))),await t.write(r.bytes),n.length&&await t.write(n)},async close(){await t.end()},version(){return So}}}function yt(){}function No(){let t=[],e=null,r=yt,n=!1,o=null,i=yt,s=()=>(e||(e=new Promise(h=>{r=()=>{e=null,r=yt,h()}})),e),c={write(h){t.push(h);let p=s();return i(),p},async end(){n=!0;let h=s();i(),await h}},u={async next(){let h=t.shift();return h?(t.length===0&&r(),{done:!1,value:h}):n?(r(),{done:!0,value:void 0}):(o||(o=new Promise(p=>{i=()=>(o=null,i=yt,p(u.next()))})),o)}};return{writer:c,iterator:u}}var Oe=class t{constructor(e,r){this._encoder=r,this._mutex=r.setRoots(e),this._ended=!1}async put(e){if(!(e.bytes instanceof Uint8Array)||!e.cid)throw new TypeError("Can only write {cid, bytes} objects");if(this._ended)throw new Error("Already closed");let r=x.asCID(e.cid);if(!r)throw new TypeError("Can only write {cid, bytes} objects");return this._mutex=this._mutex.then(()=>this._encoder.writeBlock({cid:r,bytes:e.bytes})),this._mutex}async close(){if(this._ended)throw new Error("Already closed");return await this._mutex,this._ended=!0,this._encoder.close()}version(){return this._encoder.version()}static create(e){e=ua(e);let{encoder:r,iterator:n}=Bo(),o=new t(e,r),i=new gt(n);return{writer:o,out:i}}static createAppender(){let{encoder:e,iterator:r}=Bo();e.setRoots=()=>Promise.resolve();let n=new t([],e),o=new gt(r);return{writer:n,out:o}}static async updateRootsInBytes(e,r){let n=Me(e);await ir(n);let o=ar(r);if(Number(n.pos)!==o.length)throw new Error(`updateRoots() can only overwrite a header of the same length (old header is ${n.pos} bytes, new header is ${o.length} bytes)`);return e.set(o,0),e}},gt=class{constructor(e){this._iterator=e}[Symbol.asyncIterator](){if(this._iterating)throw new Error("Multiple iterator not supported");return this._iterating=!0,this._iterator}};function Bo(){let t=No(),{writer:e,iterator:r}=t;return{encoder:_o(e),iterator:r}}function ua(t){if(t===void 0)return[];if(!Array.isArray(t)){let r=x.asCID(t);if(!r)throw new TypeError("roots must be a single CID or an array of CIDs");return[r]}let e=[];for(let r of t){let n=x.asCID(r);if(!n)throw new TypeError("roots must be a single CID or an array of CIDs");e.push(n)}return e}function fa(t){return t[Symbol.asyncIterator]!=null}function da(t){if(fa(t))return(async()=>{for await(let e of t);})();for(let e of t);}var Co=da;function ha(t){let[e,r]=t[Symbol.asyncIterator]!=null?[t[Symbol.asyncIterator](),Symbol.asyncIterator]:[t[Symbol.iterator](),Symbol.iterator],n=[];return{peek:()=>e.next(),push:o=>{n.push(o)},next:()=>n.length>0?{done:!1,value:n.shift()}:e.next(),[r](){return this}}}var Do=ha;function la(t){return t[Symbol.asyncIterator]!=null}function pa(t,e){let r=0;if(la(t))return(async function*(){for await(let u of t)yield e(u,r++)})();let n=Do(t),{value:o,done:i}=n.next();if(i===!0)return(function*(){})();let s=e(o,r++);if(typeof s.then=="function")return(async function*(){yield await s;for(let u of n)yield e(u,r++)})();let c=e;return(function*(){yield s;for(let u of n)yield c(u,r++)})()}var Uo=pa;function K(t=0){return new Uint8Array(t)}function cr(t,e){e==null&&(e=t.reduce((o,i)=>o+i.length,0));let r=K(e),n=0;for(let o of t)r.set(o,n),n+=o.length;return r}function ma(t){return t[Symbol.asyncIterator]!=null}function ya(t){if(ma(t))return(async()=>{let n=new Uint8Array(0);for await(let o of t)n=cr([n,o],n.length+o.length);return n})();let e=[],r=0;for(let n of t)e.push(n),r+=n.byteLength;return cr(e,r)}var ur=ya;var ga=20;function dr({name:t,code:e,encode:r,minDigestLength:n,maxDigestLength:o}){return new fr(t,e,r,n,o)}var fr=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,r,n,o,i){this.name=e,this.code=r,this.encode=n,this.minDigestLength=o??ga,this.maxDigestLength=i}digest(e,r){if(r?.truncate!=null){if(r.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&r.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(e instanceof Uint8Array){let n=this.encode(e);return n instanceof Uint8Array?Lo(n,this.code,r?.truncate):n.then(o=>Lo(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function Lo(t,e,r){if(r!=null&&r!==t.byteLength){if(r>t.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${t.byteLength}`);t=t.subarray(0,r)}return ke(e,t)}function xt({enumerable:t=!0,configurable:e=!1}={}){return{enumerable:t,configurable:e,writable:!1}}function*xa(t,e){if(e!=null&&typeof e=="object")if(Array.isArray(e))for(let[r,n]of e.entries()){let o=[...t,r],i=x.asCID(n);i!=null?yield[o.join("/"),i]:typeof n=="object"&&(yield*hr(n,o))}else{let r=x.asCID(e);r!=null?yield[t.join("/"),r]:yield*hr(e,t)}}function*hr(t,e){if(t==null||t instanceof Uint8Array)return;let r=x.asCID(t);r!=null&&(yield[e.join("/"),r]);for(let[n,o]of Object.entries(t)){let i=[...e,n];yield*xa(i,o)}}function*wa(t,e){if(Array.isArray(e))for(let[r,n]of e.entries()){let o=[...t,r];yield o.join("/"),typeof n=="object"&&x.asCID(n)==null&&(yield*lr(n,o))}else yield*lr(e,t)}function*lr(t,e){if(!(t==null||typeof t!="object"))for(let[r,n]of Object.entries(t)){let o=[...e,r];yield o.join("/"),n!=null&&!(n instanceof Uint8Array)&&typeof n=="object"&&x.asCID(n)==null&&(yield*wa(o,n))}}function ba(t,e){let r=t;for(let[n,o]of e.entries()){if(r=r[o],r==null)throw new Error(`Object has no property at ${e.slice(0,n+1).map(s=>`[${JSON.stringify(s)}]`).join("")}`);let i=x.asCID(r);if(i!=null)return{value:i,remaining:e.slice(n+1).join("/")}}return{value:r}}var pr=class{cid;bytes;value;asBlock;constructor({cid:e,bytes:r,value:n}){if(e==null||r==null||typeof n>"u")throw new Error("Missing required argument");this.cid=e,this.bytes=r,this.value=n,this.asBlock=this,Object.defineProperties(this,{cid:xt(),bytes:xt(),value:xt(),asBlock:xt()})}links(){return hr(this.value,[])}tree(){return lr(this.value,[])}get(e="/"){return ba(this.value,e.split("/").filter(Boolean))}};function mr({bytes:t,cid:e,value:r,codec:n}){let o=r!==void 0?r:n?.decode(t);if(o===void 0)throw new Error('Missing required argument, must either provide "value" or "codec"');return new pr({cid:e,bytes:t,value:o})}function yr(){let t={};return t.promise=new Promise((e,r)=>{t.resolve=e,t.reject=r}),t}var xr=et(Ro(),1);var wr=class t extends Error{name="TimeoutError";constructor(e,r){super(e,r),Error.captureStackTrace?.(this,t)}},Mo=t=>t.reason??new DOMException("This operation was aborted.","AbortError");function br(t,e){let{milliseconds:r,fallback:n,message:o,customTimers:i={setTimeout,clearTimeout},signal:s}=e,c,u,p=new Promise((m,b)=>{if(typeof r!="number"||Math.sign(r)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${r}\``);if(s?.aborted){b(Mo(s));return}if(s&&(u=()=>{b(Mo(s))},s.addEventListener("abort",u,{once:!0})),t.then(m,b),r===Number.POSITIVE_INFINITY)return;let L=new wr;c=i.setTimeout(()=>{if(n){try{m(n())}catch(g){b(g)}return}typeof t.cancel=="function"&&t.cancel(),o===!1?m():o instanceof Error?b(o):(L.message=o??`Promise timed out after ${r} milliseconds`,b(L))},r)}).finally(()=>{p.clear(),u&&s&&s.removeEventListener("abort",u)});return p.clear=()=>{i.clearTimeout(c),c=void 0},p}function Er(t,e,r){let n=0,o=t.length;for(;o>0;){let i=Math.trunc(o/2),s=n+i;r(t[s],e)<=0?(n=++s,o-=i+1):o=i}return n}var $e=class{#t=[];enqueue(e,r){let{priority:n=0,id:o}=r??{},i={priority:n,id:o,run:e};if(this.size===0||this.#t[this.size-1].priority>=n){this.#t.push(i);return}let s=Er(this.#t,i,(c,u)=>u.priority-c.priority);this.#t.splice(s,0,i)}setPriority(e,r){let n=this.#t.findIndex(i=>i.id===e);if(n===-1)throw new ReferenceError(`No promise function with the id "${e}" exists in the queue.`);let[o]=this.#t.splice(n,1);this.enqueue(o.run,{priority:r,id:e})}dequeue(){return this.#t.shift()?.run}filter(e){return this.#t.filter(r=>r.priority===e.priority).map(r=>r.run)}get size(){return this.#t.length}};var He=class extends xr.default{#t;#n;#o=0;#l;#p=!1;#m=!1;#u;#w=0;#y=0;#i;#s;#e;#b;#r=0;#f;#a;#A=1n;#d=new Map;timeout;constructor(e){if(super(),e={carryoverIntervalCount:!1,intervalCap:Number.POSITIVE_INFINITY,interval:0,concurrency:Number.POSITIVE_INFINITY,autoStart:!0,queueClass:$e,...e},!(typeof e.intervalCap=="number"&&e.intervalCap>=1))throw new TypeError(`Expected \`intervalCap\` to be a number from 1 and up, got \`${e.intervalCap?.toString()??""}\` (${typeof e.intervalCap})`);if(e.interval===void 0||!(Number.isFinite(e.interval)&&e.interval>=0))throw new TypeError(`Expected \`interval\` to be a finite number >= 0, got \`${e.interval?.toString()??""}\` (${typeof e.interval})`);if(this.#t=e.carryoverIntervalCount??e.carryoverConcurrencyCount??!1,this.#n=e.intervalCap===Number.POSITIVE_INFINITY||e.interval===0,this.#l=e.intervalCap,this.#u=e.interval,this.#e=new e.queueClass,this.#b=e.queueClass,this.concurrency=e.concurrency,e.timeout!==void 0&&!(Number.isFinite(e.timeout)&&e.timeout>0))throw new TypeError(`Expected \`timeout\` to be a positive finite number, got \`${e.timeout}\` (${typeof e.timeout})`);this.timeout=e.timeout,this.#a=e.autoStart===!1,this.#L()}get#S(){return this.#n||this.#o<this.#l}get#_(){return this.#r<this.#f}#N(){this.#r--,this.#r===0&&this.emit("pendingZero"),this.#g(),this.emit("next")}#B(){this.#v(),this.#k(),this.#s=void 0}get#C(){let e=Date.now();if(this.#i===void 0){let r=this.#w-e;if(r<0){if(this.#y>0){let n=e-this.#y;if(n<this.#u)return this.#E(this.#u-n),!0}this.#o=this.#t?this.#r:0}else return this.#E(r),!0}return!1}#E(e){this.#s===void 0&&(this.#s=setTimeout(()=>{this.#B()},e))}#T(){this.#i&&(clearInterval(this.#i),this.#i=void 0)}#D(){this.#s&&(clearTimeout(this.#s),this.#s=void 0)}#g(){if(this.#e.size===0)return this.#T(),this.emit("empty"),this.#r===0&&(this.#D(),this.emit("idle")),!1;let e=!1;if(!this.#a){let r=!this.#C;if(this.#S&&this.#_){let n=this.#e.dequeue();this.#n||(this.#o++,this.#h()),this.emit("active"),this.#y=Date.now(),n(),r&&this.#k(),e=!0}}return e}#k(){this.#n||this.#i!==void 0||(this.#i=setInterval(()=>{this.#v()},this.#u),this.#w=Date.now()+this.#u)}#v(){this.#o===0&&this.#r===0&&this.#i&&this.#T(),this.#o=this.#t?this.#r:0,this.#x(),this.#h()}#x(){for(;this.#g(););}get concurrency(){return this.#f}set concurrency(e){if(!(typeof e=="number"&&e>=1))throw new TypeError(`Expected \`concurrency\` to be a number from 1 and up, got \`${e}\` (${typeof e})`);this.#f=e,this.#x()}async#U(e){return new Promise((r,n)=>{e.addEventListener("abort",()=>{n(e.reason)},{once:!0})})}setPriority(e,r){if(typeof r!="number"||!Number.isFinite(r))throw new TypeError(`Expected \`priority\` to be a finite number, got \`${r}\` (${typeof r})`);this.#e.setPriority(e,r)}async add(e,r={}){return r.id??=(this.#A++).toString(),r={timeout:this.timeout,...r},new Promise((n,o)=>{let i=Symbol(`task-${r.id}`);this.#e.enqueue(async()=>{this.#r++,this.#d.set(i,{id:r.id,priority:r.priority??0,startTime:Date.now(),timeout:r.timeout});try{try{r.signal?.throwIfAborted()}catch(u){throw this.#n||this.#o--,this.#d.delete(i),u}let s=e({signal:r.signal});r.timeout&&(s=br(Promise.resolve(s),{milliseconds:r.timeout,message:`Task timed out after ${r.timeout}ms (queue has ${this.#r} running, ${this.#e.size} waiting)`})),r.signal&&(s=Promise.race([s,this.#U(r.signal)]));let c=await s;n(c),this.emit("completed",c)}catch(s){o(s),this.emit("error",s)}finally{this.#d.delete(i),queueMicrotask(()=>{this.#N()})}},r),this.emit("add"),this.#g()})}async addAll(e,r){return Promise.all(e.map(async n=>this.add(n,r)))}start(){return this.#a?(this.#a=!1,this.#x(),this):this}pause(){this.#a=!0}clear(){this.#e=new this.#b,this.#I()}async onEmpty(){this.#e.size!==0&&await this.#c("empty")}async onSizeLessThan(e){this.#e.size<e||await this.#c("next",()=>this.#e.size<e)}async onIdle(){this.#r===0&&this.#e.size===0||await this.#c("idle")}async onPendingZero(){this.#r!==0&&await this.#c("pendingZero")}async onRateLimit(){this.isRateLimited||await this.#c("rateLimit")}async onRateLimitCleared(){this.isRateLimited&&await this.#c("rateLimitCleared")}async onError(){return new Promise((e,r)=>{let n=o=>{this.off("error",n),r(o)};this.on("error",n)})}async#c(e,r){return new Promise(n=>{let o=()=>{r&&!r()||(this.off(e,o),n())};this.on(e,o)})}get size(){return this.#e.size}sizeBy(e){return this.#e.filter(e).length}get pending(){return this.#r}get isPaused(){return this.#a}#L(){this.#n||(this.on("add",()=>{this.#e.size>0&&this.#h()}),this.on("next",()=>{this.#h()}))}#h(){this.#n||this.#m||(this.#m=!0,queueMicrotask(()=>{this.#m=!1,this.#I()}))}#I(){let e=this.#p,r=!this.#n&&this.#o>=this.#l&&this.#e.size>0;r!==e&&(this.#p=r,this.emit(r?"rateLimit":"rateLimitCleared"))}get isRateLimited(){return this.#p}get isSaturated(){return this.#r===this.#f&&this.#e.size>0||this.isRateLimited&&this.#e.size>0}get runningTasks(){return[...this.#d.values()].map(e=>({...e}))}};var Ve=class{async*export(e,r){for(let[,n]of r.links())yield n}};var qe=class{target;constructor(e){this.target=e}isTarget(e){return this.target.equals(e)}async*traverse(e,r){for(let[,n]of r.links())yield n}};var bt=class{components;log;constructor(e,r){this.components=e,this.log=e.logger.forComponent("helia:car")}async import(e,r){await Co(this.components.blockstore.putMany(Uo(e.blocks(),({cid:n,bytes:o})=>({cid:n,bytes:o})),r))}async export(e,r,n){let o=yr(),i=Array.isArray(e)?e:[e],s={currentPath:[],pathsToTarget:null},c=n?.traversal,u=n?.exporter??new Ve,h=new He({concurrency:1}),p=!1;h.on("idle",()=>{if(p)o.resolve();else if(!p&&s.pathsToTarget?.length===i.length){this.log.trace("starting export of blocks to the car file"),p=!0;for(let m of s.pathsToTarget){let b=m.length-1,L=m[b];m.slice(0,-1).forEach(g=>{h.add(async()=>{await this.#n({cid:g,queue:h,writer:r,strategy:u,options:n,recursive:!1})}).catch(k=>{this.log.error("error during queue operation - %e",k)})}),h.add(async()=>{await this.#n({cid:L,queue:h,writer:r,strategy:u,options:n})}).catch(g=>{this.log.error("error during queue operation - %e",g)})}}else this.log.trace("no paths to target, skipping export"),o.reject(new Error("Could not traverse to target CID(s)"))}),h.on("error",m=>{h.clear(),o.reject(m)});for(let m of i)h.add(async()=>{this.log.trace("traversing dag from %c",m),await this.#t({cid:m,queue:h,strategy:c??new qe(m),traversalContext:s,parentPath:[],options:n})}).catch(b=>{this.log.error("error during queue operation - %e",b)});try{await o.promise}finally{await r.close()}}async*stream(e,r){let{writer:n,out:o}=Oe.create(e);this.export(e,n,r).catch(i=>{this.log.error("error during streaming export - %e",i)});for await(let i of o)yield i}async#t({cid:e,queue:r,strategy:n,traversalContext:o,parentPath:i,options:s}){let c=[...i,e];if(n.isTarget(e)){o.pathsToTarget=o.pathsToTarget??[],o.pathsToTarget.push([...c]),this.log.trace("found path to target %c",e);return}let u=await this.components.getCodec(e.code),h=await ur(this.components.blockstore.get(e,s)),p=mr({bytes:h,cid:e,codec:u});for await(let m of n.traverse(e,p))r.add(async()=>{await this.#t({cid:m,queue:r,strategy:n,traversalContext:o,parentPath:c??[],options:s})}).catch(b=>{this.log.error("error during traversal queue operation - %e",b)})}async#n({cid:e,queue:r,writer:n,strategy:o,options:i,recursive:s=!0}){if(i?.blockFilter?.has(e.multihash.bytes)===!0)return;let c=await this.components.getCodec(e.code),u=await ur(this.components.blockstore.get(e,i));if(i?.blockFilter?.add(e.multihash.bytes),await n.put({cid:e,bytes:u}),s){let h=mr({bytes:u,cid:e,codec:c});for await(let p of o.export(e,h))r.add(async()=>{await this.#n({cid:p,queue:r,writer:n,strategy:o,options:i})}).catch(m=>{this.log.error("error during export queue operation - %e",m)})}}};var Tr=class{async*export(e,r){}};var Y=class extends Error{static code="ERR_NOT_UNIXFS";static message="Not a UnixFS node";static name="NotUnixFSError";code="ERR_NOT_UNIXFS";message="Not a UnixFS node";name="NotUnixFSError"};var kr=class{async*export(e,r){if(e.code!==112&&e.code!==85)throw new Y("Target CID was not UnixFS - use the SubGraphExporter to export arbitrary graphs");for(let[,n]of r.links())yield n}};var vr=class{pathToTarget;target;constructor(e){this.pathToTarget=e,this.target=e[e.length-1]}isTarget(e){return this.target.equals(e)}async*traverse(e,r){let n=this.pathToTarget.indexOf(e);yield this.pathToTarget[n+1]}};var va=new TextDecoder;function Ir(t,e){let r=0;for(let n=0;;n+=7){if(n>=64)throw new Error("protobuf: varint overflow");if(e>=t.length)throw new Error("protobuf: unexpected end of data");let o=t[e++];if(r+=n<28?(o&127)<<n:(o&127)*2**n,o<128)break}return[r,e]}function Et(t,e){let r;[r,e]=Ir(t,e);let n=e+r;if(r<0||n<0)throw new Error("protobuf: invalid length");if(n>t.length)throw new Error("protobuf: unexpected end of data");return[t.subarray(e,n),n]}function Oo(t,e){let r;return[r,e]=Ir(t,e),[r&7,r>>3,e]}function Ia(t){let e={},r=t.length,n=0;for(;n<r;){let o,i;if([o,i,n]=Oo(t,n),i===1){if(e.Hash)throw new Error("protobuf: (PBLink) duplicate Hash section");if(o!==2)throw new Error(`protobuf: (PBLink) wrong wireType (${o}) for Hash`);if(e.Name!==void 0)throw new Error("protobuf: (PBLink) invalid order, found Name before Hash");if(e.Tsize!==void 0)throw new Error("protobuf: (PBLink) invalid order, found Tsize before Hash");[e.Hash,n]=Et(t,n)}else if(i===2){if(e.Name!==void 0)throw new Error("protobuf: (PBLink) duplicate Name section");if(o!==2)throw new Error(`protobuf: (PBLink) wrong wireType (${o}) for Name`);if(e.Tsize!==void 0)throw new Error("protobuf: (PBLink) invalid order, found Tsize before Name");let s;[s,n]=Et(t,n),e.Name=va.decode(s)}else if(i===3){if(e.Tsize!==void 0)throw new Error("protobuf: (PBLink) duplicate Tsize section");if(o!==0)throw new Error(`protobuf: (PBLink) wrong wireType (${o}) for Tsize`);[e.Tsize,n]=Ir(t,n)}else throw new Error(`protobuf: (PBLink) invalid fieldNumber, expected 1, 2 or 3, got ${i}`)}if(n>r)throw new Error("protobuf: (PBLink) unexpected end of data");return e}function Po(t){let e=t.length,r=0,n,o=!1,i;for(;r<e;){let c,u;if([c,u,r]=Oo(t,r),c!==2)throw new Error(`protobuf: (PBNode) invalid wireType, expected 2, got ${c}`);if(u===1){if(i)throw new Error("protobuf: (PBNode) duplicate Data section");[i,r]=Et(t,r),n&&(o=!0)}else if(u===2){if(o)throw new Error("protobuf: (PBNode) duplicate Links section");n||(n=[]);let h;[h,r]=Et(t,r),n.push(Ia(h))}else throw new Error(`protobuf: (PBNode) invalid fieldNumber, expected 1 or 2, got ${u}`)}if(r>e)throw new Error("protobuf: (PBNode) unexpected end of data");let s={};return i&&(s.Data=i),s.Links=n||[],s}var _d=new TextEncoder,Nd=2**32,Bd=2**31;var Ud=new TextEncoder;function $o(t){return t instanceof ArrayBuffer?new Uint8Array(t,0,t.byteLength):t}function Ho(t){let e=$o(t),r=Po(e),n={};return r.Data&&(n.Data=r.Data),r.Links&&(n.Links=r.Links.map(o=>{let i={};try{i.Hash=x.decode(o.Hash)}catch{}if(!i.Hash)throw new Error("Invalid Hash field found in link, expected CID");return o.Name!==void 0&&(i.Name=o.Name),o.Tsize!==void 0&&(i.Tsize=o.Tsize),i})),n}var Ge=class t extends Error{static name="InvalidTypeError";static code="ERR_INVALID_TYPE";name=t.name;code=t.code;constructor(e="Invalid type"){super(e)}},Tt=class t extends Error{static name="InvalidUnixFSMessageError";static code="ERR_INVALID_MESSAGE";name=t.name;code=t.code;constructor(e="Invalid message"){super(e)}};var Aa=Math.pow(2,7),Sa=Math.pow(2,14),_a=Math.pow(2,21),Vo=Math.pow(2,28),qo=Math.pow(2,35),Go=Math.pow(2,42),Xo=Math.pow(2,49),S=128,ie=127;function Xe(t){if(t<Aa)return 1;if(t<Sa)return 2;if(t<_a)return 3;if(t<Vo)return 4;if(t<qo)return 5;if(t<Go)return 6;if(t<Xo)return 7;if(Number.MAX_SAFE_INTEGER!=null&&t>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Wo(t,e,r=0){switch(Xe(t)){case 8:e[r++]=t&255|S,t/=128;case 7:e[r++]=t&255|S,t/=128;case 6:e[r++]=t&255|S,t/=128;case 5:e[r++]=t&255|S,t/=128;case 4:e[r++]=t&255|S,t>>>=7;case 3:e[r++]=t&255|S,t>>>=7;case 2:e[r++]=t&255|S,t>>>=7;case 1:{e[r++]=t&255,t>>>=7;break}default:throw new Error("unreachable")}return e}function Jo(t,e){let r=t[e],n=0;if(n+=r&ie,r<S||(r=t[e+1],n+=(r&ie)<<7,r<S)||(r=t[e+2],n+=(r&ie)<<14,r<S)||(r=t[e+3],n+=(r&ie)<<21,r<S)||(r=t[e+4],n+=(r&ie)*Vo,r<S)||(r=t[e+5],n+=(r&ie)*qo,r<S)||(r=t[e+6],n+=(r&ie)*Go,r<S)||(r=t[e+7],n+=(r&ie)*Xo,r<S))return n;throw new RangeError("Could not decode varint")}var Ar=new Float32Array([-0]),se=new Uint8Array(Ar.buffer);function Ko(t,e,r){Ar[0]=t,e[r]=se[0],e[r+1]=se[1],e[r+2]=se[2],e[r+3]=se[3]}function jo(t,e){return se[0]=t[e],se[1]=t[e+1],se[2]=t[e+2],se[3]=t[e+3],Ar[0]}var Sr=new Float64Array([-0]),I=new Uint8Array(Sr.buffer);function Qo(t,e,r){Sr[0]=t,e[r]=I[0],e[r+1]=I[1],e[r+2]=I[2],e[r+3]=I[3],e[r+4]=I[4],e[r+5]=I[5],e[r+6]=I[6],e[r+7]=I[7]}function Zo(t,e){return I[0]=t[e],I[1]=t[e+1],I[2]=t[e+2],I[3]=t[e+3],I[4]=t[e+4],I[5]=t[e+5],I[6]=t[e+6],I[7]=t[e+7],Sr[0]}var Na=BigInt(Number.MAX_SAFE_INTEGER),Ba=BigInt(Number.MIN_SAFE_INTEGER),U=class t{lo;hi;constructor(e,r){this.lo=e|0,this.hi=r|0}toNumber(e=!1){if(!e&&this.hi>>>31>0){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(r+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(e=!1){if(e)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(BigInt(r)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(e=!1){return this.toBigInt(e).toString()}zzEncode(){let e=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^e)>>>0,this.lo=(this.lo<<1^e)>>>0,this}zzDecode(){let e=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^e)>>>0,this.hi=(this.hi>>>1^e)>>>0,this}length(){let e=this.lo,r=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?r===0?e<16384?e<128?1:2:e<2097152?3:4:r<16384?r<128?5:6:r<2097152?7:8:n<128?9:10}static fromBigInt(e){if(e===0n)return fe;if(e<Na&&e>Ba)return this.fromNumber(Number(e));let r=e<0n;r&&(e=-e);let n=e>>32n,o=e-(n<<32n);return r&&(n=~n|0n,o=~o|0n,++o>Yo&&(o=0n,++n>Yo&&(n=0n))),new t(Number(o),Number(n))}static fromNumber(e){if(e===0)return fe;let r=e<0;r&&(e=-e);let n=e>>>0,o=(e-n)/4294967296>>>0;return r&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new t(n,o)}static from(e){return typeof e=="number"?t.fromNumber(e):typeof e=="bigint"?t.fromBigInt(e):typeof e=="string"?t.fromBigInt(BigInt(e)):e.low!=null||e.high!=null?new t(e.low>>>0,e.high>>>0):fe}},fe=new U(0,0);fe.toBigInt=function(){return 0n};fe.zzEncode=fe.zzDecode=function(){return this};fe.length=function(){return 1};var Yo=4294967296n;function ei(t){let e=0,r=0;for(let n=0;n<t.length;++n)r=t.charCodeAt(n),r<128?e+=1:r<2048?e+=2:(r&64512)===55296&&(t.charCodeAt(n+1)&64512)===56320?(++n,e+=4):e+=3;return e}function ti(t,e,r){if(r-e<1)return"";let o,i=[],s=0,c;for(;e<r;)c=t[e++],c<128?i[s++]=c:c>191&&c<224?i[s++]=(c&31)<<6|t[e++]&63:c>239&&c<365?(c=((c&7)<<18|(t[e++]&63)<<12|(t[e++]&63)<<6|t[e++]&63)-65536,i[s++]=55296+(c>>10),i[s++]=56320+(c&1023)):i[s++]=(c&15)<<12|(t[e++]&63)<<6|t[e++]&63,s>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,i)),s=0);return o!=null?(s>0&&o.push(String.fromCharCode.apply(String,i.slice(0,s))),o.join("")):String.fromCharCode.apply(String,i.slice(0,s))}function _r(t,e,r){let n=r,o,i;for(let s=0;s<t.length;++s)o=t.charCodeAt(s),o<128?e[r++]=o:o<2048?(e[r++]=o>>6|192,e[r++]=o&63|128):(o&64512)===55296&&((i=t.charCodeAt(s+1))&64512)===56320?(o=65536+((o&1023)<<10)+(i&1023),++s,e[r++]=o>>18|240,e[r++]=o>>12&63|128,e[r++]=o>>6&63|128,e[r++]=o&63|128):(e[r++]=o>>12|224,e[r++]=o>>6&63|128,e[r++]=o&63|128);return r-n}function H(t,e){return RangeError(`index out of range: ${t.pos} + ${e??1} > ${t.len}`)}function kt(t,e){return(t[e-4]|t[e-3]<<8|t[e-2]<<16|t[e-1]<<24)>>>0}var Nr=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(e){this.buf=e,this.pos=0,this.len=e.length}uint32(){let e=4294967295;if(e=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(e=(e|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return e;if((this.pos+=5)>this.len)throw this.pos=this.len,H(this,10);return e}int32(){return this.uint32()|0}sint32(){let e=this.uint32();return e>>>1^-(e&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw H(this,4);return kt(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw H(this,4);return kt(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw H(this,4);let e=jo(this.buf,this.pos);return this.pos+=4,e}double(){if(this.pos+8>this.len)throw H(this,4);let e=Zo(this.buf,this.pos);return this.pos+=8,e}bytes(){let e=this.uint32(),r=this.pos,n=this.pos+e;if(n>this.len)throw H(this,e);return this.pos+=e,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let e=this.bytes();return ti(e,0,e.length)}skip(e){if(typeof e=="number"){if(this.pos+e>this.len)throw H(this,e);this.pos+=e}else do if(this.pos>=this.len)throw H(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(e){switch(e){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(e=this.uint32()&7)!==4;)this.skipType(e);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${e} at offset ${this.pos}`)}return this}readLongVarint(){let e=new U(0,0),r=0;if(this.len-this.pos>4){for(;r<4;++r)if(e.lo=(e.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return e;if(e.lo=(e.lo|(this.buf[this.pos]&127)<<28)>>>0,e.hi=(e.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return e;r=0}else{for(;r<3;++r){if(this.pos>=this.len)throw H(this);if(e.lo=(e.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return e}return e.lo=(e.lo|(this.buf[this.pos++]&127)<<r*7)>>>0,e}if(this.len-this.pos>4){for(;r<5;++r)if(e.hi=(e.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return e}else for(;r<5;++r){if(this.pos>=this.len)throw H(this);if(e.hi=(e.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return e}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw H(this,8);let e=kt(this.buf,this.pos+=4),r=kt(this.buf,this.pos+=4);return new U(e,r)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let e=Jo(this.buf,this.pos);return this.pos+=Xe(e),e}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function Br(t){return new Nr(t instanceof Uint8Array?t:t.subarray())}function We(t,e,r){let n=Br(t);return e.decode(n,void 0,r)}var Cr={};_(Cr,{base10:()=>Ca});var Ca=ne({prefix:"9",name:"base10",alphabet:"0123456789"});var Dr={};_(Dr,{base16:()=>Da,base16upper:()=>Ua});var Da=w({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Ua=w({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Ur={};_(Ur,{base2:()=>La});var La=w({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Lr={};_(Lr,{base256emoji:()=>Oa});var ni=Array.from("\u{1F680}\u{1FA90}\u2604\u{1F6F0}\u{1F30C}\u{1F311}\u{1F312}\u{1F313}\u{1F314}\u{1F315}\u{1F316}\u{1F317}\u{1F318}\u{1F30D}\u{1F30F}\u{1F30E}\u{1F409}\u2600\u{1F4BB}\u{1F5A5}\u{1F4BE}\u{1F4BF}\u{1F602}\u2764\u{1F60D}\u{1F923}\u{1F60A}\u{1F64F}\u{1F495}\u{1F62D}\u{1F618}\u{1F44D}\u{1F605}\u{1F44F}\u{1F601}\u{1F525}\u{1F970}\u{1F494}\u{1F496}\u{1F499}\u{1F622}\u{1F914}\u{1F606}\u{1F644}\u{1F4AA}\u{1F609}\u263A\u{1F44C}\u{1F917}\u{1F49C}\u{1F614}\u{1F60E}\u{1F607}\u{1F339}\u{1F926}\u{1F389}\u{1F49E}\u270C\u2728\u{1F937}\u{1F631}\u{1F60C}\u{1F338}\u{1F64C}\u{1F60B}\u{1F497}\u{1F49A}\u{1F60F}\u{1F49B}\u{1F642}\u{1F493}\u{1F929}\u{1F604}\u{1F600}\u{1F5A4}\u{1F603}\u{1F4AF}\u{1F648}\u{1F447}\u{1F3B6}\u{1F612}\u{1F92D}\u2763\u{1F61C}\u{1F48B}\u{1F440}\u{1F62A}\u{1F611}\u{1F4A5}\u{1F64B}\u{1F61E}\u{1F629}\u{1F621}\u{1F92A}\u{1F44A}\u{1F973}\u{1F625}\u{1F924}\u{1F449}\u{1F483}\u{1F633}\u270B\u{1F61A}\u{1F61D}\u{1F634}\u{1F31F}\u{1F62C}\u{1F643}\u{1F340}\u{1F337}\u{1F63B}\u{1F613}\u2B50\u2705\u{1F97A}\u{1F308}\u{1F608}\u{1F918}\u{1F4A6}\u2714\u{1F623}\u{1F3C3}\u{1F490}\u2639\u{1F38A}\u{1F498}\u{1F620}\u261D\u{1F615}\u{1F33A}\u{1F382}\u{1F33B}\u{1F610}\u{1F595}\u{1F49D}\u{1F64A}\u{1F639}\u{1F5E3}\u{1F4AB}\u{1F480}\u{1F451}\u{1F3B5}\u{1F91E}\u{1F61B}\u{1F534}\u{1F624}\u{1F33C}\u{1F62B}\u26BD\u{1F919}\u2615\u{1F3C6}\u{1F92B}\u{1F448}\u{1F62E}\u{1F646}\u{1F37B}\u{1F343}\u{1F436}\u{1F481}\u{1F632}\u{1F33F}\u{1F9E1}\u{1F381}\u26A1\u{1F31E}\u{1F388}\u274C\u270A\u{1F44B}\u{1F630}\u{1F928}\u{1F636}\u{1F91D}\u{1F6B6}\u{1F4B0}\u{1F353}\u{1F4A2}\u{1F91F}\u{1F641}\u{1F6A8}\u{1F4A8}\u{1F92C}\u2708\u{1F380}\u{1F37A}\u{1F913}\u{1F619}\u{1F49F}\u{1F331}\u{1F616}\u{1F476}\u{1F974}\u25B6\u27A1\u2753\u{1F48E}\u{1F4B8}\u2B07\u{1F628}\u{1F31A}\u{1F98B}\u{1F637}\u{1F57A}\u26A0\u{1F645}\u{1F61F}\u{1F635}\u{1F44E}\u{1F932}\u{1F920}\u{1F927}\u{1F4CC}\u{1F535}\u{1F485}\u{1F9D0}\u{1F43E}\u{1F352}\u{1F617}\u{1F911}\u{1F30A}\u{1F92F}\u{1F437}\u260E\u{1F4A7}\u{1F62F}\u{1F486}\u{1F446}\u{1F3A4}\u{1F647}\u{1F351}\u2744\u{1F334}\u{1F4A3}\u{1F438}\u{1F48C}\u{1F4CD}\u{1F940}\u{1F922}\u{1F445}\u{1F4A1}\u{1F4A9}\u{1F450}\u{1F4F8}\u{1F47B}\u{1F910}\u{1F92E}\u{1F3BC}\u{1F975}\u{1F6A9}\u{1F34E}\u{1F34A}\u{1F47C}\u{1F48D}\u{1F4E3}\u{1F942}"),za=ni.reduce((t,e,r)=>(t[r]=e,t),[]),Fa=ni.reduce((t,e,r)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return t[n]=r,t},[]);function Ra(t){return t.reduce((e,r)=>(e+=za[r],e),"")}function Ma(t){let e=[];for(let r of t){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=Fa[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);e.push(o)}return new Uint8Array(e)}var Oa=xe({prefix:"\u{1F680}",name:"base256emoji",encode:Ra,decode:Ma});var zr={};_(zr,{base64:()=>Pa,base64pad:()=>$a,base64url:()=>Ha,base64urlpad:()=>Va});var Pa=w({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),$a=w({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Ha=w({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Va=w({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Fr={};_(Fr,{base8:()=>qa});var qa=w({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Rr={};_(Rr,{identity:()=>Ga});var Ga=xe({prefix:"\0",name:"identity",encode:t=>oo(t),decode:t=>no(t)});var fh=new TextEncoder,dh=new TextDecoder;var Mr={};_(Mr,{identity:()=>ja});var oi=0,Ja="identity",ii=Z;function Ka(t,e){if(e?.truncate!=null&&e.truncate!==t.byteLength){if(e.truncate<0||e.truncate>t.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${t.byteLength}`);t=t.subarray(0,e.truncate)}return ke(oi,ii(t))}var ja={code:oi,name:Ja,encode:ii,digest:Ka};var Or={};_(Or,{sha256:()=>Qa,sha512:()=>Za});function si(t){return async e=>new Uint8Array(await crypto.subtle.digest(t,e))}var Qa=dr({name:"sha2-256",code:18,encode:si("SHA-256")}),Za=dr({name:"sha2-512",code:19,encode:si("SHA-512")});var Pr={...Rr,...Ur,...Fr,...Cr,...Dr,...qt,...Gt,...Xt,...zr,...Lr},yh={...Or,...Mr};function ci(t,e,r,n){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:r},decoder:{decode:n}}}var ai=ci("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),$r=ci("ascii","a",t=>{let e="a";for(let r=0;r<t.length;r++)e+=String.fromCharCode(t[r]);return e},t=>{t=t.substring(1);let e=K(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}),Ya={utf8:ai,"utf-8":ai,hex:Pr.base16,latin1:$r,ascii:$r,binary:$r,...Pr},ui=Ya;function fi(t,e="utf8"){let r=ui[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.decoder.decode(`${r.prefix}${t}`)}function Hr(t){let e=t??8192,r=e>>>1,n,o=e;return function(s){if(s<1||s>r)return K(s);o+s>e&&(n=K(e),o=0);let c=n.subarray(o,o+=s);return(o&7)!==0&&(o=(o|7)+1),c}}var de=class{fn;len;next;val;constructor(e,r,n){this.fn=e,this.len=r,this.next=void 0,this.val=n}};function Vr(){}var Gr=class{head;tail;len;next;constructor(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}},ec=Hr();function tc(t){return globalThis.Buffer!=null?K(t):ec(t)}var Ke=class{len;head;tail;states;constructor(){this.len=0,this.head=new de(Vr,0,0),this.tail=this.head,this.states=null}_push(e,r,n){return this.tail=this.tail.next=new de(e,r,n),this.len+=r,this}uint32(e){return this.len+=(this.tail=this.tail.next=new Xr((e=e>>>0)<128?1:e<16384?2:e<2097152?3:e<268435456?4:5,e)).len,this}int32(e){return e<0?this._push(vt,10,U.fromNumber(e)):this.uint32(e)}sint32(e){return this.uint32((e<<1^e>>31)>>>0)}uint64(e){let r=U.fromBigInt(e);return this._push(vt,r.length(),r)}uint64Number(e){return this._push(Wo,Xe(e),e)}uint64String(e){return this.uint64(BigInt(e))}int64(e){return this.uint64(e)}int64Number(e){return this.uint64Number(e)}int64String(e){return this.uint64String(e)}sint64(e){let r=U.fromBigInt(e).zzEncode();return this._push(vt,r.length(),r)}sint64Number(e){let r=U.fromNumber(e).zzEncode();return this._push(vt,r.length(),r)}sint64String(e){return this.sint64(BigInt(e))}bool(e){return this._push(qr,1,e?1:0)}fixed32(e){return this._push(Je,4,e>>>0)}sfixed32(e){return this.fixed32(e)}fixed64(e){let r=U.fromBigInt(e);return this._push(Je,4,r.lo)._push(Je,4,r.hi)}fixed64Number(e){let r=U.fromNumber(e);return this._push(Je,4,r.lo)._push(Je,4,r.hi)}fixed64String(e){return this.fixed64(BigInt(e))}sfixed64(e){return this.fixed64(e)}sfixed64Number(e){return this.fixed64Number(e)}sfixed64String(e){return this.fixed64String(e)}float(e){return this._push(Ko,4,e)}double(e){return this._push(Qo,8,e)}bytes(e){let r=e.length>>>0;return r===0?this._push(qr,1,0):this.uint32(r)._push(nc,r,e)}string(e){let r=ei(e);return r!==0?this.uint32(r)._push(_r,r,e):this._push(qr,1,0)}fork(){return this.states=new Gr(this),this.head=this.tail=new de(Vr,0,0),this.len=0,this}reset(){return this.states!=null?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new de(Vr,0,0),this.len=0),this}ldelim(){let e=this.head,r=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=e.next,this.tail=r,this.len+=n),this}finish(){let e=this.head.next,r=tc(this.len),n=0;for(;e!=null;)e.fn(e.val,r,n),n+=e.len,e=e.next;return r}};function qr(t,e,r){e[r]=t&255}function rc(t,e,r){for(;t>127;)e[r++]=t&127|128,t>>>=7;e[r]=t}var Xr=class extends de{next;constructor(e,r){super(rc,e,r),this.next=void 0}};function vt(t,e,r){for(;t.hi!==0;)e[r++]=t.lo&127|128,t.lo=(t.lo>>>7|t.hi<<25)>>>0,t.hi>>>=7;for(;t.lo>127;)e[r++]=t.lo&127|128,t.lo=t.lo>>>7;e[r++]=t.lo}function Je(t,e,r){e[r]=t&255,e[r+1]=t>>>8&255,e[r+2]=t>>>16&255,e[r+3]=t>>>24}function nc(t,e,r){e.set(t,r)}globalThis.Buffer!=null&&(Ke.prototype.bytes=function(t){let e=t.length>>>0;return this.uint32(e),e>0&&this._push(oc,e,t),this},Ke.prototype.string=function(t){let e=globalThis.Buffer.byteLength(t);return this.uint32(e),e>0&&this._push(ic,e,t),this});function oc(t,e,r){e.set(t,r)}function ic(t,e,r){t.length<40?_r(t,e,r):e.utf8Write!=null?e.utf8Write(t,r):e.set(fi(t),r)}function Wr(){return new Ke}function je(t,e){let r=Wr();return e.encode(t,r,{lengthDelimited:!1}),r.finish()}var ve;(function(t){t[t.VARINT=0]="VARINT",t[t.BIT64=1]="BIT64",t[t.LENGTH_DELIMITED=2]="LENGTH_DELIMITED",t[t.START_GROUP=3]="START_GROUP",t[t.END_GROUP=4]="END_GROUP",t[t.BIT32=5]="BIT32"})(ve||(ve={}));function It(t,e,r,n){return{name:t,type:e,encode:r,decode:n}}function Jr(t){function e(o){if(t[o.toString()]==null)throw new Error("Invalid enum value");return t[o]}let r=function(i,s){let c=e(i);s.int32(c)},n=function(i){let s=i.int32();return e(s)};return It("enum",ve.VARINT,r,n)}function Qe(t,e){return It("message",ve.LENGTH_DELIMITED,t,e)}var V;(function(t){let e;(function(o){o.Raw="Raw",o.Directory="Directory",o.File="File",o.Metadata="Metadata",o.Symlink="Symlink",o.HAMTShard="HAMTShard"})(e=t.DataType||(t.DataType={}));let r;(function(o){o[o.Raw=0]="Raw",o[o.Directory=1]="Directory",o[o.File=2]="File",o[o.Metadata=3]="Metadata",o[o.Symlink=4]="Symlink",o[o.HAMTShard=5]="HAMTShard"})(r||(r={})),(function(o){o.codec=()=>Jr(r)})(e=t.DataType||(t.DataType={}));let n;t.codec=()=>(n==null&&(n=Qe((o,i,s={})=>{if(s.lengthDelimited!==!1&&i.fork(),o.Type!=null&&(i.uint32(8),t.DataType.codec().encode(o.Type,i)),o.Data!=null&&(i.uint32(18),i.bytes(o.Data)),o.filesize!=null&&(i.uint32(24),i.uint64(o.filesize)),o.blocksizes!=null)for(let c of o.blocksizes)i.uint32(32),i.uint64(c);o.hashType!=null&&(i.uint32(40),i.uint64(o.hashType)),o.fanout!=null&&(i.uint32(48),i.uint64(o.fanout)),o.mode!=null&&(i.uint32(56),i.uint32(o.mode)),o.mtime!=null&&(i.uint32(66),At.codec().encode(o.mtime,i)),s.lengthDelimited!==!1&&i.ldelim()},(o,i)=>{let s={blocksizes:[]},c=i==null?o.len:o.pos+i;for(;o.pos<c;){let u=o.uint32();switch(u>>>3){case 1:s.Type=t.DataType.codec().decode(o);break;case 2:s.Data=o.bytes();break;case 3:s.filesize=o.uint64();break;case 4:s.blocksizes.push(o.uint64());break;case 5:s.hashType=o.uint64();break;case 6:s.fanout=o.uint64();break;case 7:s.mode=o.uint32();break;case 8:s.mtime=At.codec().decode(o,o.uint32());break;default:o.skipType(u&7);break}}return s})),n),t.encode=o=>je(o,t.codec()),t.decode=o=>We(o,t.codec())})(V||(V={}));var At;(function(t){let e;t.codec=()=>(e==null&&(e=Qe((r,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),r.Seconds!=null&&(n.uint32(8),n.int64(r.Seconds)),r.FractionalNanoseconds!=null&&(n.uint32(21),n.fixed32(r.FractionalNanoseconds)),o.lengthDelimited!==!1&&n.ldelim()},(r,n)=>{let o={},i=n==null?r.len:r.pos+n;for(;r.pos<i;){let s=r.uint32();switch(s>>>3){case 1:o.Seconds=r.int64();break;case 2:o.FractionalNanoseconds=r.fixed32();break;default:r.skipType(s&7);break}}return o})),e),t.encode=r=>je(r,t.codec()),t.decode=r=>We(r,t.codec())})(At||(At={}));var di;(function(t){let e;t.codec=()=>(e==null&&(e=Qe((r,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),r.MimeType!=null&&(n.uint32(10),n.string(r.MimeType)),o.lengthDelimited!==!1&&n.ldelim()},(r,n)=>{let o={},i=n==null?r.len:r.pos+n;for(;r.pos<i;){let s=r.uint32();switch(s>>>3){case 1:o.MimeType=r.string();break;default:r.skipType(s&7);break}}return o})),e),t.encode=r=>je(r,t.codec()),t.decode=r=>We(r,t.codec())})(di||(di={}));var hi={Raw:"raw",Directory:"directory",File:"file",Metadata:"metadata",Symlink:"symlink",HAMTShard:"hamt-sharded-directory"},sc=["directory","hamt-sharded-directory"],li=parseInt("0644",8),pi=parseInt("0755",8),mi=BigInt(1024),St=class t{static unmarshal(e){let r=V.decode(e);if(r.fanout!=null&&r.fanout>mi)throw new Tt(`Fanout size was too large - ${r.fanout} > ${mi}`);let n=new t({type:hi[r.Type!=null?r.Type.toString():"File"],data:r.Data,blockSizes:r.blocksizes,mode:r.mode,mtime:r.mtime!=null?{secs:r.mtime.Seconds??0n,nsecs:r.mtime.FractionalNanoseconds}:void 0,fanout:r.fanout});return n._originalMode=r.mode??0,n}type;data;blockSizes;hashType;fanout;mtime;_mode;_originalMode;constructor(e={type:"file"}){let{type:r,data:n,blockSizes:o,hashType:i,fanout:s,mtime:c,mode:u}=e;if(r!=null&&!Object.values(hi).includes(r))throw new Ge("Type: "+r+" is not valid");this.type=r??"file",this.data=n,this.hashType=i,this.fanout=s,this.blockSizes=o??[],this._originalMode=0,this.mode=u,this.mtime=c}set mode(e){e==null?this._mode=this.isDirectory()?pi:li:this._mode=e&4095}get mode(){return this._mode}isDirectory(){return sc.includes(this.type)}addBlockSize(e){this.blockSizes.push(e)}removeBlockSize(e){this.blockSizes.splice(e,1)}fileSize(){if(this.isDirectory())return 0n;let e=0n;return this.blockSizes.forEach(r=>{e+=r}),this.data!=null&&(e+=BigInt(this.data.length)),e}marshal(){let e;switch(this.type){case"raw":e=V.DataType.Raw;break;case"directory":e=V.DataType.Directory;break;case"file":e=V.DataType.File;break;case"metadata":e=V.DataType.Metadata;break;case"symlink":e=V.DataType.Symlink;break;case"hamt-sharded-directory":e=V.DataType.HAMTShard;break;default:throw new Ge(`Type: ${e} is not valid`)}let r=this.data;(this.data==null||this.data.length===0)&&(r=void 0);let n;this.mode!=null&&(n=this._originalMode&4294963200|(this.mode??0),n===li&&!this.isDirectory()&&(n=void 0),n===pi&&this.isDirectory()&&(n=void 0));let o;return this.mtime!=null&&(o={Seconds:this.mtime.secs,FractionalNanoseconds:this.mtime.nsecs}),V.encode({Type:e,Data:r,filesize:this.isDirectory()?void 0:this.fileSize(),blocksizes:this.blockSizes,hashType:this.hashType,fanout:this.fanout,mode:n,mtime:o})}};var Kr=class{path;constructor(e){this.path=e.replace(/^\//,"").split("/")}isTarget(){return this.path.length===0}async*traverse(e,r){if(e.code!==112)throw new Y("Target CID is not UnixFS");let n=this.path.shift();if(n==null)return;let o=Ho(r.bytes);if(o.Data==null)throw new Y("Target CID has no UnixFS data in decoded bytes");if(St.unmarshal(o.Data).type==="directory"){let s=o.Links.filter(c=>c.Name===n).pop();if(s==null)throw new Y(`Target CID directory has no link with name ${n}`);yield s.Hash;return}throw new Y("Target CID is not a UnixFS directory")}};function ac(t,e={}){return new bt(t,e)}return Ei(cc);})();
|
|
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
|