@helia/car 6.0.9-05d3e4cc → 6.0.9-87a42bd5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +4 -4
- package/package.json +7 -7
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 Sf=Object.create;var Or=Object.defineProperty;var Cf=Object.getOwnPropertyDescriptor;var Nf=Object.getOwnPropertyNames;var Df=Object.getPrototypeOf,Uf=Object.prototype.hasOwnProperty;var xt=(t,e)=>()=>{try{return e||t((e={exports:{}}).exports,e),e.exports}catch(r){throw e=0,r}},ee=(t,e)=>{for(var r in e)Or(t,r,{get:e[r],enumerable:!0})},ss=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Nf(e))!Uf.call(t,o)&&o!==r&&Or(t,o,{get:()=>e[o],enumerable:!(n=Cf(e,o))||n.enumerable});return t};var or=(t,e,r)=>(r=t!=null?Sf(Df(t)):{},ss(e||!t||!t.__esModule?Or(r,"default",{value:t,enumerable:!0}):r,t)),Lf=t=>ss(Or({},"__esModule",{value:!0}),t);var Ta=xt((Dy,Ia)=>{Ia.exports=Po;var Aa=128,ld=127,dd=~ld,hd=Math.pow(2,31);function Po(t,e,r){if(Number.MAX_SAFE_INTEGER&&t>Number.MAX_SAFE_INTEGER)throw Po.bytes=0,new RangeError("Could not encode varint");e=e||[],r=r||0;for(var n=r;t>=hd;)e[r++]=t&255|Aa,t/=128;for(;tⅆ)e[r++]=t&255|Aa,t>>>=7;return e[r]=t|0,Po.bytes=r-n+1,e}});var Ca=xt((Uy,Sa)=>{Sa.exports=Fo;var pd=128,Ba=127;function Fo(t,n){var r=0,n=n||0,o=0,i=n,s,a=t.length;do{if(i>=a||o>49)throw Fo.bytes=0,new RangeError("Could not decode varint");s=t[i++],r+=o<28?(s&Ba)<<o:(s&Ba)*Math.pow(2,o),o+=7}while(s>=pd);return Fo.bytes=i-n,r}});var Da=xt((Ly,Na)=>{var md=Math.pow(2,7),yd=Math.pow(2,14),gd=Math.pow(2,21),wd=Math.pow(2,28),xd=Math.pow(2,35),bd=Math.pow(2,42),Ed=Math.pow(2,49),vd=Math.pow(2,56),kd=Math.pow(2,63);Na.exports=function(t){return t<md?1:t<yd?2:t<gd?3:t<wd?4:t<xd?5:t<bd?6:t<Ed?7:t<vd?8:t<kd?9:10}});var un=xt((Ry,Ua)=>{Ua.exports={encode:Ta(),decode:Ca(),encodingLength:Da()}});var tf=xt((oE,ef)=>{"use strict";ef.exports=class{constructor(){this._bitArrays=[],this._data=[],this._length=0,this._changedLength=!1,this._changedData=!1}set(e,r){let n=this._internalPositionFor(e,!1);if(r===void 0)n!==-1&&(this._unsetInternalPos(n),this._unsetBit(e),this._changedLength=!0,this._changedData=!0);else{let o=!1;n===-1?(n=this._data.length,this._setBit(e),this._changedData=!0):o=!0,this._setInternalPos(n,e,r,o),this._changedLength=!0}}unset(e){this.set(e,void 0)}get(e){this._sortData();let r=this._internalPositionFor(e,!0);if(r!==-1)return this._data[r][1]}push(e){return this.set(this.length,e),this.length}get length(){if(this._sortData(),this._changedLength){let e=this._data[this._data.length-1];this._length=e?e[0]+1:0,this._changedLength=!1}return this._length}forEach(e){let r=0;for(;r<this.length;)e(this.get(r),r,this),r++}map(e){let r=0,n=new Array(this.length);for(;r<this.length;)n[r]=e(this.get(r),r,this),r++;return n}reduce(e,r){let n=0,o=r;for(;n<this.length;){let i=this.get(n);o=e(o,i,n),n++}return o}find(e){let r=0,n,o;for(;r<this.length&&!n;)o=this.get(r),n=e(o),r++;return n?o:void 0}_internalPositionFor(e,r){let n=this._bytePosFor(e,r);if(n>=this._bitArrays.length)return-1;let o=this._bitArrays[n],i=e-n*7;if(!((o&1<<i)>0))return-1;let a=this._bitArrays.slice(0,n).reduce(zp,0),c=~(4294967295<<i+1),u=Zu(o&c);return a+u-1}_bytePosFor(e,r){let n=Math.floor(e/7),o=n+1;for(;!r&&this._bitArrays.length<o;)this._bitArrays.push(0);return n}_setBit(e){let r=this._bytePosFor(e,!1);this._bitArrays[r]|=1<<e-r*7}_unsetBit(e){let r=this._bytePosFor(e,!1);this._bitArrays[r]&=~(1<<e-r*7)}_setInternalPos(e,r,n,o){let i=this._data,s=[r,n];if(o)this._sortData(),i[e]=s;else{if(i.length)if(i[i.length-1][0]>=r)i.push(s);else if(i[0][0]<=r)i.unshift(s);else{let a=Math.round(i.length/2);this._data=i.slice(0,a).concat(s).concat(i.slice(a))}else this._data.push(s);this._changedData=!0,this._changedLength=!0}}_unsetInternalPos(e){this._data.splice(e,1)}_sortData(){this._changedData&&this._data.sort(Hp),this._changedData=!1}bitField(){let e=[],r=8,n=0,o=0,i,s=this._bitArrays.slice();for(;s.length||n;){n===0&&(i=s.shift(),n=7);let c=Math.min(n,r),u=~(255<<c),l=i&u;o|=l<<8-r,i=i>>>c,n-=c,r-=c,(!r||!n&&!s.length)&&(e.push(o),o=0,r=8)}for(var a=e.length-1;a>0&&e[a]===0;a--)e.pop();return e}compactArray(){return this._sortData(),this._data.map(Vp)}};function zp(t,e){return t+Zu(e)}function Zu(t){let e=t;return e=e-(e>>1&1431655765),e=(e&858993459)+(e>>2&858993459),(e+(e>>4)&252645135)*16843009>>24}function Hp(t,e){return t[0]-e[0]}function Vp(t){return t[1]}});var Ef=xt((xv,Zi)=>{"use strict";var nm=Object.prototype.hasOwnProperty,K="~";function Pr(){}Object.create&&(Pr.prototype=Object.create(null),new Pr().__proto__||(K=!1));function om(t,e,r){this.fn=t,this.context=e,this.once=r||!1}function bf(t,e,r,n,o){if(typeof r!="function")throw new TypeError("The listener must be a function");var i=new om(r,n||t,o),s=K?K+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 lo(t,e){--t._eventsCount===0?t._events=new Pr:delete t._events[e]}function Y(){this._events=new Pr,this._eventsCount=0}Y.prototype.eventNames=function(){var e=[],r,n;if(this._eventsCount===0)return e;for(n in r=this._events)nm.call(r,n)&&e.push(K?n.slice(1):n);return Object.getOwnPropertySymbols?e.concat(Object.getOwnPropertySymbols(r)):e};Y.prototype.listeners=function(e){var r=K?K+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};Y.prototype.listenerCount=function(e){var r=K?K+e:e,n=this._events[r];return n?n.fn?1:n.length:0};Y.prototype.emit=function(e,r,n,o,i,s){var a=K?K+e:e;if(!this._events[a])return!1;var c=this._events[a],u=arguments.length,l,h;if(c.fn){switch(c.once&&this.removeListener(e,c.fn,void 0,!0),u){case 1:return c.fn.call(c.context),!0;case 2:return c.fn.call(c.context,r),!0;case 3:return c.fn.call(c.context,r,n),!0;case 4:return c.fn.call(c.context,r,n,o),!0;case 5:return c.fn.call(c.context,r,n,o,i),!0;case 6:return c.fn.call(c.context,r,n,o,i,s),!0}for(h=1,l=new Array(u-1);h<u;h++)l[h-1]=arguments[h];c.fn.apply(c.context,l)}else{var m=c.length,E;for(h=0;h<m;h++)switch(c[h].once&&this.removeListener(e,c[h].fn,void 0,!0),u){case 1:c[h].fn.call(c[h].context);break;case 2:c[h].fn.call(c[h].context,r);break;case 3:c[h].fn.call(c[h].context,r,n);break;case 4:c[h].fn.call(c[h].context,r,n,o);break;default:if(!l)for(E=1,l=new Array(u-1);E<u;E++)l[E-1]=arguments[E];c[h].fn.apply(c[h].context,l)}}return!0};Y.prototype.on=function(e,r,n){return bf(this,e,r,n,!1)};Y.prototype.once=function(e,r,n){return bf(this,e,r,n,!0)};Y.prototype.removeListener=function(e,r,n,o){var i=K?K+e:e;if(!this._events[i])return this;if(!r)return lo(this,i),this;var s=this._events[i];if(s.fn)s.fn===r&&(!o||s.once)&&(!n||s.context===n)&&lo(this,i);else{for(var a=0,c=[],u=s.length;a<u;a++)(s[a].fn!==r||o&&!s[a].once||n&&s[a].context!==n)&&c.push(s[a]);c.length?this._events[i]=c.length===1?c[0]:c:lo(this,i)}return this};Y.prototype.removeAllListeners=function(e){var r;return e?(r=K?K+e:e,this._events[r]&&lo(this,r)):(this._events=new Pr,this._eventsCount=0),this};Y.prototype.off=Y.prototype.removeListener;Y.prototype.addListener=Y.prototype.on;Y.prefixed=K;Y.EventEmitter=Y;typeof Zi<"u"&&(Zi.exports=Y)});var fm={};ee(fm,{BlockExporter:()=>Ti,CIDPath:()=>Oi,GraphSearch:()=>Fi,SubgraphExporter:()=>Br,UnixFSExporter:()=>Sr,UnixFSPath:()=>is,breadthFirstWalker:()=>qt,car:()=>um,depthFirstWalker:()=>jt,naturalOrderWalker:()=>wu});var Rf=["Object","Uint8Array","RegExp","Date","Error","Map","Set","WeakMap","WeakSet","ArrayBuffer","SharedArrayBuffer","DataView","Promise","URL","HTMLElement","Int8Array","Uint8ClampedArray","Int16Array","Uint16Array","Int32Array","Uint32Array","Float32Array","Float64Array","BigInt64Array","BigUint64Array","Tagged"];function ho(t){if(t===null)return"null";if(t===void 0)return"undefined";if(t===!0||t===!1)return"boolean";let e=typeof t;if(e==="string"||e==="number"||e==="bigint"||e==="symbol")return e;if(e==="function")return"Function";if(Array.isArray(t))return"Array";if(t instanceof Uint8Array)return"Uint8Array";if(t.constructor===Object)return"Object";let r=$f(t);return r||"Object"}function $f(t){let e=Object.prototype.toString.call(t).slice(8,-1);if(Rf.includes(e))return e}var f=class{constructor(e,r,n){this.major=e,this.majorEncoded=e<<5,this.name=r,this.terminal=n}toString(){return`Type[${this.major}].${this.name}`}compare(e){return this.major<e.major?-1:this.major>e.major?1:0}static equals(e,r){return e===r||e.major===r.major&&e.name===r.name}};f.uint=new f(0,"uint",!0);f.negint=new f(1,"negint",!0);f.bytes=new f(2,"bytes",!0);f.string=new f(3,"string",!0);f.array=new f(4,"array",!1);f.map=new f(5,"map",!1);f.tag=new f(6,"tag",!1);f.float=new f(7,"float",!0);f.false=new f(7,"false",!0);f.true=new f(7,"true",!0);f.null=new f(7,"null",!0);f.undefined=new f(7,"undefined",!0);f.break=new f(7,"break",!0);var p=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 ir=globalThis.process&&!globalThis.process.browser&&globalThis.Buffer&&typeof globalThis.Buffer.isBuffer=="function",Mf=new TextEncoder;function zr(t){return ir&&globalThis.Buffer.isBuffer(t)}function ot(t){return t instanceof Uint8Array?zr(t)?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):t:Uint8Array.from(t)}var Pf=24,Ff=200,bt=ir?t=>t.length>=Pf?globalThis.Buffer.from(t):as(t):t=>t.length>=Ff?Mf.encode(t):as(t),we=t=>Uint8Array.from(t),us=ir?(t,e,r)=>zr(t)?new Uint8Array(t.subarray(e,r)):t.slice(e,r):(t,e,r)=>t.slice(e,r),fs=ir?(t,e)=>(t=t.map(r=>r instanceof Uint8Array?r:globalThis.Buffer.from(r)),ot(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},po=ir?t=>globalThis.Buffer.allocUnsafe(t):t=>new Uint8Array(t);function Et(t,e){if(zr(t)&&zr(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 as(t){let e=[],r=0;for(let n=0;n<t.length;n++){let o=t.charCodeAt(n);o<128?e[r++]=o:o<2048?(e[r++]=o>>6|192,e[r++]=o&63|128):(o&64512)===55296&&n+1<t.length&&(t.charCodeAt(n+1)&64512)===56320?(o=65536+((o&1023)<<10)+(t.charCodeAt(++n)&1023),e[r++]=o>>18|240,e[r++]=o>>12&63|128,e[r++]=o>>6&63|128,e[r++]=o&63|128):(o>=55296&&o<=57343&&(o=65533),e[r++]=o>>12|224,e[r++]=o>>6&63|128,e[r++]=o&63|128)}return e}var cs=4096;function ls(t){let e=t.length;if(e<=cs)return String.fromCharCode.apply(String,t);let r="",n=0;for(;n<e;)r+=String.fromCharCode.apply(String,t.slice(n,n+=cs));return r}var Of=256,it=class{constructor(e=Of){this.chunkSize=e,this.cursor=0,this.maxCursor=-1,this.chunks=[],this._initReuseChunk=null}reset(){this.cursor=0,this.maxCursor=-1,this.chunks.length&&(this.chunks=[]),this._initReuseChunk!==null&&(this.chunks.push(this._initReuseChunk),this.maxCursor=this._initReuseChunk.length-1)}pushByte(e){let r=this.chunks[this.chunks.length-1];this.cursor>this.maxCursor&&(r=po(this.chunkSize),this.chunks.push(r),this.maxCursor+=r.length,this._initReuseChunk===null&&(this._initReuseChunk=r));let n=r.length-(this.maxCursor-this.cursor)-1;r[n]=e,this.cursor++}push(e){let r=this.chunks[this.chunks.length-1];if(this.cursor+e.length<=this.maxCursor+1){let 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=po(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=us(n,0,this.cursor)}else r=fs(this.chunks,this.cursor);return e&&this.reset(),r}},Hr=class{constructor(e){this.dest=e,this.cursor=0,this.chunks=[e]}reset(){this.cursor=0}pushByte(e){if(this.cursor>=this.dest.length)throw new Error("write out of bounds, destination buffer is too small");this.dest[this.cursor++]=e}push(e){if(this.cursor+e.length>this.dest.length)throw new Error("write out of bounds, destination buffer is too small");this.dest.set(e,this.cursor),this.cursor+=e.length}toBytes(e=!1){let r=this.dest.subarray(0,this.cursor);return e&&this.reset(),r}};var y="CBOR decode error:",Me="CBOR encode error:",sr=[];sr[23]=1;sr[24]=2;sr[25]=3;sr[26]=5;sr[27]=9;function De(t,e,r){if(t.length-e<r)throw new Error(`${y} not enough data for type`)}var H=[24,256,65536,4294967296,BigInt("18446744073709551616")];function te(t,e,r){De(t,e,1);let n=t[e];if(r.strict===!0&&n<H[0])throw new Error(`${y} integer encoded in more bytes than necessary (strict decode)`);return n}function re(t,e,r){De(t,e,2);let n=t[e]<<8|t[e+1];if(r.strict===!0&&n<H[1])throw new Error(`${y} integer encoded in more bytes than necessary (strict decode)`);return n}function ne(t,e,r){De(t,e,4);let n=t[e]*16777216+(t[e+1]<<16)+(t[e+2]<<8)+t[e+3];if(r.strict===!0&&n<H[2])throw new Error(`${y} integer encoded in more bytes than necessary (strict decode)`);return n}function oe(t,e,r){De(t,e,8);let n=t[e]*16777216+(t[e+1]<<16)+(t[e+2]<<8)+t[e+3],o=t[e+4]*16777216+(t[e+5]<<16)+(t[e+6]<<8)+t[e+7],i=(BigInt(n)<<BigInt(32))+BigInt(o);if(r.strict===!0&&i<H[3])throw new Error(`${y} 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(`${y} integers outside of the safe integer range are not supported`)}function ds(t,e,r,n){return new p(f.uint,te(t,e+1,n),2)}function hs(t,e,r,n){return new p(f.uint,re(t,e+1,n),3)}function ps(t,e,r,n){return new p(f.uint,ne(t,e+1,n),5)}function ms(t,e,r,n){return new p(f.uint,oe(t,e+1,n),9)}function xe(t,e){return F(t,0,e.value)}function F(t,e,r){if(r<H[0]){let n=Number(r);t.pushByte(e|n)}else if(r<H[1]){let n=Number(r);t.push([e|24,n])}else if(r<H[2]){let n=Number(r);t.push([e|25,n>>>8,n&255])}else if(r<H[3]){let n=Number(r);t.push([e|26,n>>>24&255,n>>>16&255,n>>>8&255,n&255])}else{let n=BigInt(r);if(n<H[4]){let o=[e|27,0,0,0,0,0,0,0],i=Number(n&BigInt(4294967295)),s=Number(n>>BigInt(32)&BigInt(4294967295));o[8]=i&255,i=i>>8,o[7]=i&255,i=i>>8,o[6]=i&255,i=i>>8,o[5]=i&255,o[4]=s&255,s=s>>8,o[3]=s&255,s=s>>8,o[2]=s&255,s=s>>8,o[1]=s&255,t.push(o)}else throw new Error(`${y} encountered BigInt larger than allowable range`)}}xe.encodedSize=function(e){return F.encodedSize(e.value)};F.encodedSize=function(e){return e<H[0]?1:e<H[1]?2:e<H[2]?3:e<H[3]?5:9};xe.compareTokens=function(e,r){return e.value<r.value?-1:e.value>r.value?1:0};function ys(t,e,r,n){return new p(f.negint,-1-te(t,e+1,n),2)}function gs(t,e,r,n){return new p(f.negint,-1-re(t,e+1,n),3)}function ws(t,e,r,n){return new p(f.negint,-1-ne(t,e+1,n),5)}var mo=BigInt(-1),xs=BigInt(1);function bs(t,e,r,n){let o=oe(t,e+1,n);if(typeof o!="bigint"){let i=-1-o;if(i>=Number.MIN_SAFE_INTEGER)return new p(f.negint,i,9)}if(n.allowBigInt!==!0)throw new Error(`${y} integers outside of the safe integer range are not supported`);return new p(f.negint,mo-BigInt(o),9)}function Vr(t,e){let r=e.value,n=typeof r=="bigint"?r*mo-xs:r*-1-1;F(t,e.type.majorEncoded,n)}Vr.encodedSize=function(e){let r=e.value,n=typeof r=="bigint"?r*mo-xs:r*-1-1;return n<H[0]?1:n<H[1]?2:n<H[2]?3:n<H[3]?5:9};Vr.compareTokens=function(e,r){return e.value<r.value?1:e.value>r.value?-1:0};function ar(t,e,r,n){De(t,e,r+n);let o=t.slice(e+r,e+r+n);return new p(f.bytes,o,r+n)}function Es(t,e,r,n){return ar(t,e,1,r)}function vs(t,e,r,n){return ar(t,e,2,te(t,e+1,n))}function ks(t,e,r,n){return ar(t,e,3,re(t,e+1,n))}function _s(t,e,r,n){return ar(t,e,5,ne(t,e+1,n))}function As(t,e,r,n){let o=oe(t,e+1,n);if(typeof o=="bigint")throw new Error(`${y} 64-bit integer bytes lengths not supported`);return ar(t,e,9,o)}function jr(t){return t.encodedBytes===void 0&&(t.encodedBytes=f.equals(t.type,f.string)?bt(t.value):t.value),t.encodedBytes}function vt(t,e){let r=jr(e);F(t,e.type.majorEncoded,r.length),t.push(r)}vt.encodedSize=function(e){let r=jr(e);return F.encodedSize(r.length)+r.length};vt.compareTokens=function(e,r){return Hf(jr(e),jr(r))};function Hf(t,e){return t.length<e.length?-1:t.length>e.length?1:Et(t,e)}var Is=new TextDecoder("utf-8",{ignoreBOM:!0}),jf=new TextDecoder("utf-8",{ignoreBOM:!0,fatal:!0}),qf=32;function Gf(t,e,r,n){if(r-e<qf){let i="";for(let s=e;s<r;s++){let a=t[s];if(a&128)return n.strictUtf8===!0?Ts(t,e,r):Is.decode(t.subarray(e,r));i+=String.fromCharCode(a)}return i}return n.strictUtf8===!0?Ts(t,e,r):Is.decode(t.subarray(e,r))}function Ts(t,e,r){try{return jf.decode(t.subarray(e,r))}catch{throw new Error(`${y} invalid UTF-8 in text string`)}}function cr(t,e,r,n,o){let i=r+n;De(t,e,i);let s=new p(f.string,Gf(t,e+r,e+i,o),i);return o.retainStringBytes===!0&&(s.byteValue=t.slice(e+r,e+i)),s}function Bs(t,e,r,n){return cr(t,e,1,r,n)}function Ss(t,e,r,n){return cr(t,e,2,te(t,e+1,n),n)}function Cs(t,e,r,n){return cr(t,e,3,re(t,e+1,n),n)}function Ns(t,e,r,n){return cr(t,e,5,ne(t,e+1,n),n)}function Ds(t,e,r,n){let o=oe(t,e+1,n);if(typeof o=="bigint")throw new Error(`${y} 64-bit integer string lengths not supported`);return cr(t,e,9,o,n)}var Us=vt;function kt(t,e,r,n){return new p(f.array,n,r)}function Ls(t,e,r,n){return kt(t,e,1,r)}function Rs(t,e,r,n){return kt(t,e,2,te(t,e+1,n))}function $s(t,e,r,n){return kt(t,e,3,re(t,e+1,n))}function Ms(t,e,r,n){return kt(t,e,5,ne(t,e+1,n))}function Ps(t,e,r,n){let o=oe(t,e+1,n);if(typeof o=="bigint")throw new Error(`${y} 64-bit integer array lengths not supported`);return kt(t,e,9,o)}function Fs(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${y} indefinite length items not allowed`);return kt(t,e,1,1/0)}function qr(t,e){F(t,f.array.majorEncoded,e.value)}qr.compareTokens=xe.compareTokens;qr.encodedSize=function(e){return F.encodedSize(e.value)};function _t(t,e,r,n){return new p(f.map,n,r)}function Os(t,e,r,n){return _t(t,e,1,r)}function zs(t,e,r,n){return _t(t,e,2,te(t,e+1,n))}function Hs(t,e,r,n){return _t(t,e,3,re(t,e+1,n))}function Vs(t,e,r,n){return _t(t,e,5,ne(t,e+1,n))}function js(t,e,r,n){let o=oe(t,e+1,n);if(typeof o=="bigint")throw new Error(`${y} 64-bit integer map lengths not supported`);return _t(t,e,9,o)}function qs(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${y} indefinite length items not allowed`);return _t(t,e,1,1/0)}function Gr(t,e){F(t,f.map.majorEncoded,e.value)}Gr.compareTokens=xe.compareTokens;Gr.encodedSize=function(e){return F.encodedSize(e.value)};function Gs(t,e,r,n){return new p(f.tag,r,1)}function Ws(t,e,r,n){return new p(f.tag,te(t,e+1,n),2)}function Ys(t,e,r,n){return new p(f.tag,re(t,e+1,n),3)}function Js(t,e,r,n){return new p(f.tag,ne(t,e+1,n),5)}function Ks(t,e,r,n){return new p(f.tag,oe(t,e+1,n),9)}function Wr(t,e){F(t,f.tag.majorEncoded,e.value)}Wr.compareTokens=xe.compareTokens;Wr.encodedSize=function(e){return F.encodedSize(e.value)};var Yr=20,Jr=21,Kr=22,Xr=23;function Qs(t,e,r,n){if(n.allowUndefined===!1)throw new Error(`${y} undefined values are not supported`);return n.coerceUndefinedToNull===!0?new p(f.null,null,1):new p(f.undefined,void 0,1)}function Zs(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${y} indefinite length items not allowed`);return new p(f.break,void 0,1)}function yo(t,e,r){if(r){if(r.allowNaN===!1&&Number.isNaN(t))throw new Error(`${y} NaN values are not supported`);if(r.allowInfinity===!1&&(t===1/0||t===-1/0))throw new Error(`${y} Infinity values are not supported`)}return new p(f.float,t,e)}function ea(t,e,r,n){return yo(Qr(t,e+1),3,n)}function ta(t,e,r,n){return yo(Zr(t,e+1),5,n)}function ra(t,e,r,n){return yo(ia(t,e+1),9,n)}function ur(t,e,r){let n=e.value;if(n===!1)t.pushByte(f.float.majorEncoded|Yr);else if(n===!0)t.pushByte(f.float.majorEncoded|Jr);else if(n===null)t.pushByte(f.float.majorEncoded|Kr);else if(n===void 0)t.pushByte(f.float.majorEncoded|Xr);else{let o,i=!1;(!r||r.float64!==!0)&&(go(n),o=Qr(O,1),n===o||Number.isNaN(n)?(O[0]=249,t.push(O.slice(0,3)),i=!0):(wo(n),o=Zr(O,1),n===o&&(O[0]=250,t.push(O.slice(0,5)),i=!0))),i||(oa(n),o=ia(O,1),O[0]=251,t.push(O.slice(0,9)))}}ur.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){go(n);let o=Qr(O,1);if(n===o||Number.isNaN(n))return 3;if(wo(n),o=Zr(O,1),n===o)return 5}return 9};var na=new ArrayBuffer(9),fe=new DataView(na,1),O=new Uint8Array(na,0);function go(t){if(t===1/0)fe.setUint16(0,31744,!1);else if(t===-1/0)fe.setUint16(0,64512,!1);else if(Number.isNaN(t))fe.setUint16(0,32256,!1);else{fe.setFloat32(0,t);let e=fe.getUint32(0),r=(e&2139095040)>>23,n=e&8388607;if(r===255)fe.setUint16(0,31744,!1);else if(r===0)fe.setUint16(0,(e&2147483648)>>16|n>>13,!1);else{let o=r-127;o<-24?fe.setUint16(0,0):o<-14?fe.setUint16(0,(e&2147483648)>>16|1<<24+o,!1):fe.setUint16(0,(e&2147483648)>>16|o+15<<10|n>>13,!1)}}}function Qr(t,e){if(t.length-e<2)throw new Error(`${y} not enough data for float16`);let r=(t[e]<<8)+t[e+1];if(r===31744)return 1/0;if(r===64512)return-1/0;if(r===32256)return NaN;let n=r>>10&31,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 wo(t){fe.setFloat32(0,t,!1)}function Zr(t,e){if(t.length-e<4)throw new Error(`${y} not enough data for float32`);let r=(t.byteOffset||0)+e;return new DataView(t.buffer,r,4).getFloat32(0,!1)}function oa(t){fe.setFloat64(0,t,!1)}function ia(t,e){if(t.length-e<8)throw new Error(`${y} not enough data for float64`);let r=(t.byteOffset||0)+e;return new DataView(t.buffer,r,8).getFloat64(0,!1)}function Xf(t,e){let r=t.value;if(r===!1)return Uint8Array.of(f.float.majorEncoded|Yr);if(r===!0)return Uint8Array.of(f.float.majorEncoded|Jr);if(r===null)return Uint8Array.of(f.float.majorEncoded|Kr);if(r===void 0)return Uint8Array.of(f.float.majorEncoded|Xr);if(!e){if(go(r),r===Qr(O,1)||Number.isNaN(r))return O[0]=249,O.slice(0,3);if(wo(r),r===Zr(O,1))return O[0]=250,O.slice(0,5)}return oa(r),O[0]=251,O.slice(0,9)}function Xs(t,e){let r=t,n=e?.float64===!0,o=n?r._keyBytesFloat64:r._keyBytes;if(o!==void 0)return o;let i=Xf(t,n);return n?r._keyBytesFloat64=i:r._keyBytes=i,i}ur.compareTokens=function(e,r,n){let o=Xs(e,n),i=Xs(r,n);return o.length!==i.length?o.length<i.length?-1:1:Et(o,i)};function I(t,e,r){throw new Error(`${y} encountered invalid minor (${r}) for major ${t[e]>>>5}`)}function en(t){return()=>{throw new Error(`${y} ${t}`)}}var g=[];for(let t=0;t<=23;t++)g[t]=I;g[24]=ds;g[25]=hs;g[26]=ps;g[27]=ms;g[28]=I;g[29]=I;g[30]=I;g[31]=I;for(let t=32;t<=55;t++)g[t]=I;g[56]=ys;g[57]=gs;g[58]=ws;g[59]=bs;g[60]=I;g[61]=I;g[62]=I;g[63]=I;for(let t=64;t<=87;t++)g[t]=Es;g[88]=vs;g[89]=ks;g[90]=_s;g[91]=As;g[92]=I;g[93]=I;g[94]=I;g[95]=en("indefinite length bytes/strings are not supported");for(let t=96;t<=119;t++)g[t]=Bs;g[120]=Ss;g[121]=Cs;g[122]=Ns;g[123]=Ds;g[124]=I;g[125]=I;g[126]=I;g[127]=en("indefinite length bytes/strings are not supported");for(let t=128;t<=151;t++)g[t]=Ls;g[152]=Rs;g[153]=$s;g[154]=Ms;g[155]=Ps;g[156]=I;g[157]=I;g[158]=I;g[159]=Fs;for(let t=160;t<=183;t++)g[t]=Os;g[184]=zs;g[185]=Hs;g[186]=Vs;g[187]=js;g[188]=I;g[189]=I;g[190]=I;g[191]=qs;for(let t=192;t<=215;t++)g[t]=Gs;g[216]=Ws;g[217]=Ys;g[218]=Js;g[219]=Ks;g[220]=I;g[221]=I;g[222]=I;g[223]=I;for(let t=224;t<=243;t++)g[t]=en("simple values are not supported");g[244]=I;g[245]=I;g[246]=I;g[247]=Qs;g[248]=en("simple values are not supported");g[249]=ea;g[250]=ta;g[251]=ra;g[252]=I;g[253]=I;g[254]=I;g[255]=Zs;var ye=[];for(let t=0;t<24;t++)ye[t]=new p(f.uint,t,1);for(let t=-1;t>=-24;t--)ye[31-t]=new p(f.negint,t,1);ye[64]=new p(f.bytes,new Uint8Array(0),1);ye[96]=new p(f.string,"",1);ye[128]=new p(f.array,0,1);ye[160]=new p(f.map,0,1);ye[244]=new p(f.false,!1,1);ye[245]=new p(f.true,!0,1);ye[246]=new p(f.null,null,1);function xo(t){switch(t.type){case f.false:return we([244]);case f.true:return we([245]);case f.null:return we([246]);case f.bytes:return t.value.length?void 0:we([64]);case f.string:return t.value===""?we([96]):void 0;case f.array:return t.value===0?we([128]):void 0;case f.map:return t.value===0?we([160]):void 0;case f.uint:return t.value<24?we([Number(t.value)]):void 0;case f.negint:if(t.value>=-24)return we([31-Number(t.value)])}}var Zf={float64:!1,mapSorter:Eo,quickEncodeToken:xo},fa=Object.freeze({mapSorter:rl,quickEncodeToken:xo});function el(){let t=[];return t[f.uint.major]=xe,t[f.negint.major]=Vr,t[f.bytes.major]=vt,t[f.string.major]=Us,t[f.array.major]=qr,t[f.map.major]=Gr,t[f.tag.major]=Wr,t[f.float.major]=ur,t}var ct=el(),tn=new it,rn=!1,It=class t{constructor(e,r){this.obj=e,this.parent=r}includes(e){let r=this;do if(r.obj===e)return!0;while(r=r.parent);return!1}static createCheck(e,r){if(e&&e.includes(r))throw new Error(`${Me} object contains circular references`);return new t(r,e)}},Pe={null:new p(f.null,null),undefined:new p(f.undefined,void 0),true:new p(f.true,!0),false:new p(f.false,!1),emptyArray:new p(f.array,0),emptyMap:new p(f.map,0)},be={number(t,e,r,n){return!Number.isInteger(t)||!Number.isSafeInteger(t)?new p(f.float,t):t>=0?new p(f.uint,t):new p(f.negint,t)},bigint(t,e,r,n){return t>=BigInt(0)?new p(f.uint,t):new p(f.negint,t)},Uint8Array(t,e,r,n){return new p(f.bytes,t)},string(t,e,r,n){return new p(f.string,t)},boolean(t,e,r,n){return t?Pe.true:Pe.false},null(t,e,r,n){return Pe.null},undefined(t,e,r,n){return Pe.undefined},ArrayBuffer(t,e,r,n){return new p(f.bytes,new Uint8Array(t))},DataView(t,e,r,n){return new p(f.bytes,new Uint8Array(t.buffer,t.byteOffset,t.byteLength))},Array(t,e,r,n){if(!t.length)return r.addBreakTokens===!0?[Pe.emptyArray,new p(f.break)]:Pe.emptyArray;n=It.createCheck(n,t);let o=[],i=0;for(let s of t)o[i++]=at(s,r,n);return r.addBreakTokens?[new p(f.array,t.length),o,new p(f.break)]:[new p(f.array,t.length),o]},Object(t,e,r,n){let o=e!=="Object",i=o?t.keys():Object.keys(t),s=o?t.size:i.length,a;if(s){a=new Array(s),n=It.createCheck(n,t);let c=!o&&r.ignoreUndefinedProperties,u=0;for(let l of i){let h=o?t.get(l):t[l];c&&h===void 0||(a[u++]=[at(l,r,n),at(h,r,n)])}u<s&&(a.length=u)}return a?.length?(tl(a,r),r.addBreakTokens?[new p(f.map,a.length),a,new p(f.break)]:[new p(f.map,a.length),a]):r.addBreakTokens===!0?[Pe.emptyMap,new p(f.break)]:Pe.emptyMap},Tagged(t,e,r,n){return[new p(f.tag,t.tag),at(t.value,r,n)]}};be.Map=be.Object;be.Buffer=be.Uint8Array;for(let t of"Uint8Clamped Uint16 Uint32 Int8 Int16 Int32 BigUint64 BigInt64 Float32 Float64".split(" "))be[`${t}Array`]=be.DataView;function at(t,e={},r){let n=ho(t),o=e&&e.typeEncoders&&e.typeEncoders[n]||be[n];if(typeof o=="function"){let s=o(t,n,e,r);if(s!=null)return s}let i=be[n];if(!i)throw new Error(`${Me} unsupported type: ${n}`);return i(t,n,e,r)}function tl(t,e){let r=e.mapSorter;r&&t.sort((n,o)=>r(n,o,e))}function Eo(t,e,r){let n=Array.isArray(t[0])?t[0][0]:t[0],o=Array.isArray(e[0])?e[0][0]:e[0];if(n.type.major!==o.type.major)return n.type.compare(o.type);let i=n.type.major,s=ct[i].compareTokens(n,o,r);return s===0&&console.warn("WARNING: complex key types used, CBOR key sorting guarantees are gone"),s}function rl(t,e){if(t[0]instanceof p&&e[0]instanceof p){let r=t[0],n=e[0];return r._keyBytes||(r._keyBytes=sa(r.value)),n._keyBytes||(n._keyBytes=sa(n.value)),Et(r._keyBytes,n._keyBytes)}throw new Error("rfc8949MapSorter: complex key types are not supported yet")}function sa(t){return vo(t,ct,fa)}function At(t,e,r,n){if(Array.isArray(e))for(let o of e)At(t,o,r,n);else r[e.type.major](t,e,n)}var aa=f.uint.majorEncoded,ca=f.negint.majorEncoded,nl=f.bytes.majorEncoded,ol=f.string.majorEncoded,ua=f.array.majorEncoded,bo=f.map.majorEncoded,il=f.float.majorEncoded|Yr,sl=f.float.majorEncoded|Jr,al=f.float.majorEncoded|Kr,cl=f.float.majorEncoded|Xr,ul=BigInt(-1),fl=BigInt(1);function Fe(t,e,r){r<24?t.pushByte(e|Number(r)):F(t,e,r)}function ll(t){return t.addBreakTokens!==!0}function dl(t,e,r,n,o){let i=r==="Map",s=i?e.keys():Object.keys(e),a=i?e.size:s.length;if(!a){t.pushByte(bo);return}o=It.createCheck(o,e);let c=!i&&n.ignoreUndefinedProperties,u=new Array(a),l=0;for(let h of s){let m=i?e.get(h):e[h];c&&m===void 0||(u[l++]=[at(h,n,o),m])}if(l===0){t.pushByte(bo);return}l<a&&(u.length=l),u.sort((h,m)=>Eo(h,m,n)),Fe(t,bo,l);for(let[h,m]of u)At(t,h,ct,n),nn(t,m,n,o)}function nn(t,e,r,n){let o=ho(e),i=r.typeEncoders&&r.typeEncoders[o];if(i){let s=i(e,o,r,n);if(s!=null){At(t,s,ct,r);return}}switch(o){case"null":t.pushByte(al);return;case"undefined":t.pushByte(cl);return;case"boolean":t.pushByte(e?sl:il);return;case"number":!Number.isInteger(e)||!Number.isSafeInteger(e)?ur(t,new p(f.float,e),r):e>=0?Fe(t,aa,e):Fe(t,ca,e*-1-1);return;case"bigint":e>=BigInt(0)?Fe(t,aa,e):Fe(t,ca,e*ul-fl);return;case"string":{let s=bt(e);Fe(t,ol,s.length),t.push(s);return}case"Uint8Array":Fe(t,nl,e.length),t.push(e);return;case"Array":if(!e.length){t.pushByte(ua);return}n=It.createCheck(n,e),Fe(t,ua,e.length);for(let s of e)nn(t,s,r,n);return;case"Object":case"Map":if(r.mapSorter===Eo)dl(t,e,o,r,n);else{let s=be.Object(e,o,r,n);At(t,s,ct,r)}return;default:{let s=be[o];if(!s)throw new Error(`${Me} unsupported type: ${o}`);let a=s(e,o,r,n);At(t,a,ct,r)}}}function vo(t,e,r,n){let o=n instanceof Uint8Array,i=o?new Hr(n):rn?new it:tn,s=at(t,r);if(!Array.isArray(s)&&r.quickEncodeToken){let a=r.quickEncodeToken(s);if(a)return o?(i.push(a),i.toBytes()):a;let c=e[s.type.major];if(c.encodedSize){let u=c.encodedSize(s,r);if(o||(i=new it(u)),c(i,s,r),i.chunks.length!==1)throw new Error(`Unexpected error: pre-calculated length for ${s} was wrong`);return o?i.toBytes():ot(i.chunks[0])}}return i.reset(),At(i,s,e,r),i.toBytes(!0)}function ko(t,e){if(e=Object.assign({},Zf,e),ll(e)){if(rn){let r=new it;return nn(r,t,e,void 0),r.toBytes()}rn=!0;try{return tn.reset(),nn(tn,t,e,void 0),tn.toBytes(!0)}finally{rn=!1}}return vo(t,ct,e)}var hl={strict:!1,allowIndefinite:!0,allowUndefined:!0,allowBigInt:!0},on=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=ye[e];if(r===void 0){let n=g[e];if(!n)throw e===void 0?new Error(`${y} not enough data`):new Error(`${y} 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}},Oe=Symbol.for("DONE"),ze=Symbol.for("BREAK");function pl(t,e,r){let n=[];for(let o=0;o<t.value;o++){let i=He(e,r);if(i===ze){if(t.value===1/0)break;throw new Error(`${y} got unexpected break to lengthed array`)}if(i===Oe)throw new Error(`${y} found array but not enough entries (got ${o}, expected ${t.value})`);n[o]=i}return n}function ml(t,e,r){let n=r.useMaps===!0,o=r.rejectDuplicateMapKeys===!0,i=n?void 0:{},s=n?new Map:void 0;for(let a=0;a<t.value;a++){let c=He(e,r);if(c===ze){if(t.value===1/0)break;throw new Error(`${y} got unexpected break to lengthed map`)}if(c===Oe)throw new Error(`${y} found map but not enough entries (got ${a} [no key], expected ${t.value})`);if(!n&&typeof c!="string")throw new Error(`${y} non-string keys not supported (got ${typeof c})`);if(o&&(n&&s.has(c)||!n&&Object.hasOwn(i,c)))throw new Error(`${y} found repeat map key "${c}"`);let u=He(e,r);if(u===Oe)throw new Error(`${y} found map but not enough entries (got ${a} [no value], expected ${t.value})`);if(u===ze)throw new Error(`${y} got unexpected break to map value`);n?s.set(c,u):c==="__proto__"?Object.defineProperty(i,c,{value:u,configurable:!0,enumerable:!0,writable:!0}):i[c]=u}return n?s:i}function*yl(t,e,r){for(let n=0;n<t.value;n++){let o=He(e,r);if(o===ze){if(t.value===1/0)break;throw new Error(`${y} got unexpected break to lengthed map`)}if(o===Oe)throw new Error(`${y} found map but not enough entries (got ${n} [no key], expected ${t.value})`);let i=He(e,r);if(i===Oe)throw new Error(`${y} found map but not enough entries (got ${n} [no value], expected ${t.value})`);if(i===ze)throw new Error(`${y} got unexpected break to map value`);yield[o,i]}}function gl(t,e){let r=function(){if(r._called)throw new Error(`${y} tag decode() may only be called once`);r._called=!0;let n=He(t,e);if(n===Oe)throw new Error(`${y} tag content missing`);if(n===ze)throw new Error(`${y} got unexpected break in tag content`);return n};return r.entries=function(){if(r._called)throw new Error(`${y} tag decode() may only be called once`);if(r._called=!0,t.done())throw new Error(`${y} tag content missing`);let n=t.next();if(!f.equals(n.type,f.map))throw new Error(`${y} entries() requires map content, got ${n.type.name}`);let o=[];for(let i of yl(n,t,e))o.push(i);return o},r._called=!1,r}function He(t,e){if(t.done())return Oe;let r=t.next();if(f.equals(r.type,f.break))return ze;if(r.type.terminal)return r.value;if(f.equals(r.type,f.array))return pl(r,t,e);if(f.equals(r.type,f.map))return ml(r,t,e);if(f.equals(r.type,f.tag)){if(e.tags&&typeof e.tags[r.value]=="function"){let n=gl(t,e),o=e.tags[r.value](n);if(!n._called)throw new Error(`${y} tag decoder must call decode() or entries()`);return o}throw new Error(`${y} tag not supported (${r.value})`)}throw new Error("unsupported")}function _o(t,e){if(!(t instanceof Uint8Array))throw new Error(`${y} data to decode must be a Uint8Array`);e=Object.assign({},hl,e);let r=ot(t),n=e.tokenizer||new on(r,e),o=He(n,e);if(o===Oe)throw new Error(`${y} did not find any content to decode`);if(o===ze)throw new Error(`${y} got unexpected break`);return[o,t.subarray(n.pos())]}function fr(t,e){let[r,n]=_o(t,e);if(n.length>0)throw new Error(`${y} too many terminals, data makes no sense`);return r}var sn=class t{constructor(e,r){if(typeof e!="number"||!Number.isInteger(e)||e<0)throw new TypeError("Tagged: tag must be a non-negative integer");this.tag=e,this.value=r}static decoder(e){return r=>new t(e,r())}static preserve(...e){let r={};for(let n of e)r[n]=t.decoder(n);return r}};Object.defineProperty(sn.prototype,Symbol.toStringTag,{value:"Tagged"});var Co={};ee(Co,{base32:()=>Bt,base32hex:()=>Sl,base32hexpad:()=>Nl,base32hexpadupper:()=>Dl,base32hexupper:()=>Cl,base32pad:()=>Tl,base32padupper:()=>Bl,base32upper:()=>Il,base32z:()=>Ul});var dy=new Uint8Array(0);function da(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 le(t){if(t instanceof Uint8Array&&t.constructor.name==="Uint8Array")return ut(t);if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.isView(t))return ut(new Uint8Array(t.buffer,t.byteOffset,t.byteLength));throw new Error("Unknown type, must be binary type")}function ha(t){let e=new Uint8Array(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}var la=4096;function pa(t){let e=t.length;if(e<=la)return String.fromCharCode.apply(String,t);let r="",n=0;for(;n<e;)r+=String.fromCharCode.apply(String,t.subarray(n,n+=la));return r}function xl(t){return t?.buffer instanceof ArrayBuffer}function ut(t){return xl(t)?t:t.slice()}function bl(t,e,r){if(t.length>=255)throw new TypeError("Alphabet too long");for(var n=new Uint8Array(256),o=0;o<n.length;o++)n[o]=255;for(var i=0;i<t.length;i++){var s=t.charAt(i),a=s.charCodeAt(0);if(n[a]!==255)throw new TypeError(s+" is ambiguous");if(n[a]=i,r){var c=s.toLowerCase().charCodeAt(0),u=s.toUpperCase().charCodeAt(0);c!==a&&(n[c]=i),u!==a&&(n[u]=i)}}var l=t.length,h=t.charAt(0),m=Math.log(l)/Math.log(256),E=Math.log(256)/Math.log(l);function _(v){if(v instanceof Uint8Array||(ArrayBuffer.isView(v)?v=new Uint8Array(v.buffer,v.byteOffset,v.byteLength):Array.isArray(v)&&(v=Uint8Array.from(v))),!(v instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(v.length===0)return"";for(var D=0,R=0,N=0,$=v.length;N!==$&&v[N]===0;)N++,D++;for(var j=($-N)*E+1>>>0,Ce=new Uint8Array(j);N!==$;){for(var X=v[N],nt=0,Ne=j-1;(X!==0||nt<R)&&Ne!==-1;Ne--,nt++)X+=256*Ce[Ne]>>>0,Ce[Ne]=X%l>>>0,X=X/l>>>0;if(X!==0)throw new Error("Non-zero carry");R=nt,N++}for(var Z=j-R;Z!==j&&Ce[Z]===0;)Z++;for(var nr=h.repeat(D);Z<j;++Z)nr+=t.charAt(Ce[Z]);return nr}function k(v){if(typeof v!="string")throw new TypeError("Expected String");if(v.length===0)return new Uint8Array;var D=0;if(v[D]!==" "){for(var R=0,N=0;v[D]===h;)R++,D++;for(var $=(v.length-D)*m+1>>>0,j=new Uint8Array($);v[D];){var Ce=v.charCodeAt(D);if(Ce>255)return;var X=n[Ce];if(X===255)return;for(var nt=0,Ne=$-1;(X!==0||nt<N)&&Ne!==-1;Ne--,nt++)X+=l*j[Ne]>>>0,j[Ne]=X%256>>>0,X=X/256>>>0;if(X!==0)throw new Error("Non-zero carry");N=nt,D++}if(v[D]!==" "){for(var Z=$-N;Z!==$&&j[Z]===0;)Z++;for(var nr=new Uint8Array(R+($-Z)),Bf=R;Z!==$;)nr[Bf++]=j[Z++];return nr}}}function b(v){var D=k(v);if(D)return D;throw new Error(`Non-${e} character`)}return{encode:_,decodeUnsafe:k,decode:b}}var El=bl,vl=El,ma=vl;var Io=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")}},To=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 ya(this,e)}},Bo=class{decoders;constructor(e){this.decoders=e}or(e){return ya(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 ya(t,e){return new Bo({...t.decoders??{[t.prefix]:t},...e.decoders??{[e.prefix]:e}})}var So=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 Io(e,r,n),this.decoder=new To(e,r,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function Tt({name:t,prefix:e,encode:r,decode:n}){return new So(t,e,r,n)}function Ve({name:t,prefix:e,alphabet:r,caseInsensitive:n=!1}){let{encode:o,decode:i}=ma(r,t,n);return Tt({prefix:e,name:t,encode:o,decode:s=>le(i(s))})}function kl(t,e,r,n){let o=t.length;for(;t[o-1]==="=";)--o;let i=new Uint8Array(o*r/8|0),s=0,a=0,c=0;for(let u=0;u<o;++u){let l=e[t[u]];if(l===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|l,s+=r,s>=8&&(s-=8,i[c++]=255&a>>s)}if(s>=r||(255&a<<8-s)!==0)throw new SyntaxError("Unexpected end of data");return i}function _l(t,e,r){let n=e[e.length-1]==="=",o=(1<<r)-1,i="",s=0,a=0;for(let c=0;c<t.length;++c)for(a=a<<8|t[c],s+=8;s>r;)s-=r,i+=e[o&a>>s];if(s!==0&&(i+=e[o&a<<r-s]),n)for(;(i.length*r&7)!==0;)i+="=";return i}function Al(t,e){let r={};for(let n=0;n<t.length;++n)if(t[n]!=="="&&(r[t[n]]=n,e)){let o=t[n].toLowerCase(),i=t[n].toUpperCase();o!==t[n]&&(r[o]=n),i!==t[n]&&(r[i]=n)}return r}function M({name:t,prefix:e,bitsPerChar:r,alphabet:n,caseInsensitive:o=!1}){let i=Al(n,o);return Tt({prefix:e,name:t,encode(s){return _l(s,n,r)},decode(s){return kl(s,i,r,t)}})}var Bt=M({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5,caseInsensitive:!0}),Il=M({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5,caseInsensitive:!0}),Tl=M({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5,caseInsensitive:!0}),Bl=M({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5,caseInsensitive:!0}),Sl=M({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5,caseInsensitive:!0}),Cl=M({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5,caseInsensitive:!0}),Nl=M({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5,caseInsensitive:!0}),Dl=M({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5,caseInsensitive:!0}),Ul=M({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var No={};ee(No,{base36:()=>lr,base36upper:()=>Ll});var lr=Ve({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz",caseInsensitive:!0}),Ll=Ve({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",caseInsensitive:!0});var Do={};ee(Do,{base58btc:()=>Ee,base58flickr:()=>Rl});var Ee=Ve({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Rl=Ve({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var $l=xa,ga=128,Ml=127,Pl=~Ml,Fl=Math.pow(2,31);function xa(t,e,r){e=e||[],r=r||0;for(var n=r;t>=Fl;)e[r++]=t&255|ga,t/=128;for(;t&Pl;)e[r++]=t&255|ga,t>>>=7;return e[r]=t|0,xa.bytes=r-n+1,e}var Ol=Uo,zl=128,wa=127;function Uo(t,n){var r=0,n=n||0,o=0,i=n,s,a=t.length;do{if(i>=a)throw Uo.bytes=0,new RangeError("Could not decode varint");s=t[i++],r+=o<28?(s&wa)<<o:(s&wa)*Math.pow(2,o),o+=7}while(s>=zl);return Uo.bytes=i-n,r}var Hl=Math.pow(2,7),Vl=Math.pow(2,14),jl=Math.pow(2,21),ql=Math.pow(2,28),Gl=Math.pow(2,35),Wl=Math.pow(2,42),Yl=Math.pow(2,49),Jl=Math.pow(2,56),Kl=Math.pow(2,63),Xl=function(t){return t<Hl?1:t<Vl?2:t<jl?3:t<ql?4:t<Gl?5:t<Wl?6:t<Yl?7:t<Jl?8:t<Kl?9:10},Ql={encode:$l,decode:Ol,encodingLength:Xl},Zl=Ql,dr=Zl;function hr(t,e=0){let r=dr.decode(t,e),n=dr.decode.bytes;if(n>9)throw new RangeError("Invalid varint: too long");if(n>1&&t[e+n-1]===0)throw new RangeError("Invalid varint: not minimally encoded");return[r,n]}function St(t,e,r=0){return dr.encode(t,e,r),e}function Ct(t){return dr.encodingLength(t)}function Dt(t,e){let r=e.byteLength,n=Ct(t),o=n+Ct(r),i=new Uint8Array(o+r);return St(t,i,0),St(r,i,n),i.set(e,o),new Nt(t,r,e,i)}function Ut(t){let e=le(t),[r,n]=hr(e),[o,i]=hr(e.subarray(n)),s=e.subarray(n+i);if(s.byteLength!==o)throw new Error("Incorrect length");return new Nt(r,o,s,e)}function ba(t,e){if(t===e)return!0;{let r=e;return t.code===r.code&&t.size===r.size&&r.bytes instanceof Uint8Array&&da(t.bytes,r.bytes)}}var Nt=class{code;size;digest;bytes;constructor(e,r,n,o){this.code=e,this.size=r,this.digest=ut(n),this.bytes=ut(o)}};function Ea(t,e){let{bytes:r,version:n}=t;return n===0?td(r,Lo(t),e??Ee.encoder):rd(r,Lo(t),e??Bt.encoder)}var va=new WeakMap;function Lo(t){let e=va.get(t);if(e==null){let r=new Map;return va.set(t,r),r}return e}var A=class t{code;version;multihash;bytes;"/";constructor(e,r,n,o){this.code=r,this.version=e,this.multihash=n,this.bytes=ut(o),this["/"]=this.bytes}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:e,multihash:r}=this;if(e!==pr)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==nd)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=Dt(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&&ba(e.multihash,n.multihash)}toString(e){return Ea(this,e)}toJSON(){return{"/":Ea(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??ka(n,o,i.bytes))}else if(r[od]===!0){let{version:n,multihash:o,code:i}=r,s=Ut(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!==pr)throw new Error(`Version 0 CID must use dag-pb (code: ${pr}) block encoding`);return new t(e,r,n,n.bytes)}case 1:{let o=ka(e,r,n.bytes);return new t(e,r,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return t.create(0,pr,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=le(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 Nt(r.multihashCode,r.digestSize,i,o);return[r.version===0?t.createV0(s):t.createV1(r.codec,s),e.subarray(r.size)]}static inspectBytes(e){let r=0,n=()=>{let[h,m]=hr(e.subarray(r));return r+=m,h},o=n(),i=pr;if(o===18)o=0,r=0;else if(o===1)i=n();else throw o===0?new RangeError("Invalid CID version, v0 is always implicit"):new RangeError(`Invalid CID version ${o}`);let s=r,a=n(),c=n(),u=r+c,l=u-s;return{version:o,codec:i,multihashCode:a,digestSize:c,multihashSize:l,size:u}}static parse(e,r){let[n,o]=ed(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 Lo(i).set(n,e),i}};function ed(t,e){switch(t[0]){case"Q":{let r=e??Ee;return[Ee.prefix,r.decode(`${Ee.prefix}${t}`)]}case Ee.prefix:{let r=e??Ee;return[Ee.prefix,r.decode(t)]}case Bt.prefix:{let r=e??Bt;return[Bt.prefix,r.decode(t)]}case lr.prefix:{let r=e??lr;return[lr.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 td(t,e,r){let{prefix:n}=r;if(n!==Ee.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 rd(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 pr=112,nd=18;function ka(t,e,r){let n=Ct(t),o=n+Ct(e),i=new Uint8Array(o+r.byteLength);return St(t,i,0),St(e,i,n),i.set(r,o),i}var od=Symbol.for("@ipld/js-cid/CID");var _a=42;function id(t){return t instanceof ArrayBuffer?new Uint8Array(t,0,t.byteLength):t}function sd(t){if(t.asCID!==t&&t["/"]!==t.bytes)return null;let e=A.asCID(t);if(!e)return null;let r=new Uint8Array(e.bytes.byteLength+1);return r.set(e.bytes,1),[new p(f.tag,_a),new p(f.bytes,r)]}function ad(){throw new Error("`undefined` is not supported by the IPLD Data Model and cannot be encoded")}function cd(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 ud(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 Ro={float64:!0,typeEncoders:{Map:ud,Object:sd,undefined:ad,number:cd}},Cy={...Ro,typeEncoders:{...Ro.typeEncoders}};function fd(t){let e=t();if(e[0]!==0)throw new Error("Invalid CID for CBOR tag 42; expected leading 0x00");return A.decode(e.subarray(1))}var $o={allowIndefinite:!1,coerceUndefinedToNull:!0,allowNaN:!1,allowInfinity:!1,allowBigInt:!0,strict:!0,useMaps:!1,rejectDuplicateMapKeys:!0,tags:{[_a]:fd}},Ny={...$o,tags:{...$o.tags}};var cn=113,Mo=t=>ko(t,Ro),ft=t=>fr(id(t),$o);var Oo=or(un(),1);var zo=40;function Ho(t,e){if(!t.length)throw new Error("Unexpected end of data");let r=Oo.default.decode(t);return e.seek(Oo.default.decode.bytes),r}function Vo(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 qe={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},yr={"CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)":qe.Link,"CarV1HeaderOrV2Pragma > roots (anon)":t=>{if(qe.List(t)!==void 0){for(let e=0;e<t.length;e++){let r=t[e];if(r=yr["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=yr["CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)"](i),i===void 0)return;n.push(i)}return n}}return t}},Int:qe.Int,CarV1HeaderOrV2Pragma:t=>{if(qe.Map(t)===void 0)return;let e=Object.entries(t),r=t,n=1;for(let o=0;o<e.length;o++){let[i,s]=e[o];switch(i){case"roots":{let a=yr["CarV1HeaderOrV2Pragma > roots (anon)"](t[i]);if(a===void 0)return;if(a!==s||r!==t){if(r===t){r={};for(let c=0;c<o;c++)r[e[c][0]]=e[c][1]}r.roots=a}}break;case"version":{n--;let a=yr.Int(t[i]);if(a===void 0)return;if(a!==s||r!==t){if(r===t){r={};for(let c=0;c<o;c++)r[e[c][0]]=e[c][1]}r.version=a}}break;default:return}}if(!(n>0))return r}},gr={"CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)":qe.Link,"CarV1HeaderOrV2Pragma > roots (anon)":t=>{if(qe.List(t)!==void 0){for(let e=0;e<t.length;e++){let r=t[e];if(r=gr["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=gr["CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)"](i),i===void 0)return;n.push(i)}return n}}return t}},Int:qe.Int,CarV1HeaderOrV2Pragma:t=>{if(qe.Map(t)===void 0)return;let e=Object.entries(t),r=t,n=1;for(let o=0;o<e.length;o++){let[i,s]=e[o];switch(i){case"roots":{let a=gr["CarV1HeaderOrV2Pragma > roots (anon)"](s);if(a===void 0)return;if(a!==s||r!==t){if(r===t){r={};for(let c=0;c<o;c++)r[e[c][0]]=e[c][1]}r.roots=a}}break;case"version":{n--;let a=gr.Int(s);if(a===void 0)return;if(a!==s||r!==t){if(r===t){r={};for(let c=0;c<o;c++)r[e[c][0]]=e[c][1]}r.version=a}}break;default:return}}if(!(n>0))return r}},jo={toTyped:yr.CarV1HeaderOrV2Pragma,toRepresentation:gr.CarV1HeaderOrV2Pragma};var Td=["Object","Uint8Array","RegExp","Date","Error","Map","Set","WeakMap","WeakSet","ArrayBuffer","SharedArrayBuffer","DataView","Promise","URL","HTMLElement","Int8Array","Uint8ClampedArray","Int16Array","Uint16Array","Int32Array","Uint32Array","Float32Array","Float64Array","BigInt64Array","BigUint64Array","Tagged","Number","String","Boolean","BigInt","Symbol"];function La(t){if(t===null)return"null";if(t===void 0)return"undefined";if(t===!0||t===!1)return"boolean";let e=typeof t;if(e==="string"||e==="number"||e==="bigint"||e==="symbol")return e;if(e==="function")return"Function";if(Array.isArray(t))return"Array";if(t instanceof Uint8Array)return"Uint8Array";if(t.constructor===Object)return"Object";let r=Bd(t);return r||"Object"}function Bd(t){let e=Object.prototype.toString.call(t).slice(8,-1);if(Td.includes(e))return e}var d=class{constructor(e,r,n){this.major=e,this.majorEncoded=e<<5,this.name=r,this.terminal=n}toString(){return`Type[${this.major}].${this.name}`}compare(e){return this.major<e.major?-1:this.major>e.major?1:0}static equals(e,r){return e===r||e.major===r.major&&e.name===r.name}};d.uint=new d(0,"uint",!0);d.negint=new d(1,"negint",!0);d.bytes=new d(2,"bytes",!0);d.string=new d(3,"string",!0);d.array=new d(4,"array",!1);d.map=new d(5,"map",!1);d.tag=new d(6,"tag",!1);d.float=new d(7,"float",!0);d.false=new d(7,"false",!0);d.true=new d(7,"true",!0);d.null=new d(7,"null",!0);d.undefined=new d(7,"undefined",!0);d.break=new d(7,"break",!0);var x=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 wr=class{constructor(){this.home=new Uint8Array(2048),this.buf=this.home,this.pos=0,this.start=0,this.segs=[],this.segLen=0}reset(){this.buf.length>this.home.length&&this.buf.length<=65536&&(this.home=this.buf),this.buf=this.home,this.pos=0,this.start=0,this.segs.length>0&&(this.segs=[],this.segLen=0)}grow(e){let r=this.pos-this.start;if(this.buf.length>=262144)r>0&&(this.segs.push(this.buf.subarray(this.start,this.pos)),this.segLen+=r),this.buf=new Uint8Array(e>262144?e:262144),this.pos=0,this.start=0;else{let n=this.buf.length*2;for(;n<r+e;)n*=2;let o=new Uint8Array(n);o.set(this.buf.subarray(this.start,this.pos)),this.buf=o,this.pos=r,this.start=0}}pushByte(e){this.pos>=this.buf.length&&this.grow(1),this.buf[this.pos++]=e}pushArr(e){let r=e.length;this.pos+r>this.buf.length&&this.grow(r);let n=this.buf,o=this.pos;for(let i=0;i<r;i++)n[o++]=e[i];this.pos=o}pushBytes(e){let r=e.length;if(r>=1024){this.pos>this.start&&(this.segs.push(this.buf.subarray(this.start,this.pos)),this.segLen+=this.pos-this.start),this.segs.push(e),this.segLen+=r,this.start=this.pos;return}this.pos+r>this.buf.length&&this.grow(r);let n=this.buf,o=this.pos;if(r<16)for(let i=0;i<r;i++)n[o++]=e[i];else n.set(e,o),o+=r;this.pos=o}push(e){Array.isArray(e)?this.pushArr(e):this.pushBytes(e)}toBytes(e=!1){let r;if(this.segs.length===0)r=new Uint8Array(this.buf.subarray(this.start,this.pos));else{r=new Uint8Array(this.segLen+(this.pos-this.start));let n=0;for(let o of this.segs)r.set(o,n),n+=o.length;r.set(this.buf.subarray(this.start,this.pos),n)}return e&&this.reset(),r}},lt=class{constructor(e){this.dest=e,this.cursor=0}reset(){this.cursor=0}pushByte(e){if(this.cursor>=this.dest.length)throw new Error("write out of bounds, destination buffer is too small");this.dest[this.cursor++]=e}push(e){if(this.cursor+e.length>this.dest.length)throw new Error("write out of bounds, destination buffer is too small");this.dest.set(e,this.cursor),this.cursor+=e.length}pushArr(e){let r=e.length;if(this.cursor+r>this.dest.length)throw new Error("write out of bounds, destination buffer is too small");let n=this.dest,o=this.cursor;for(let i=0;i<r;i++)n[o++]=e[i];this.cursor=o}pushBytes(e){this.push(e)}toBytes(e=!1){let r=this.dest.subarray(0,this.cursor);return e&&this.reset(),r}};var T="CBOR decode error:",ve="CBOR encode error:",xr=[];xr[23]=1;xr[24]=2;xr[25]=3;xr[26]=5;xr[27]=9;function Ue(t,e,r){if(t.length-e<r)throw new Error(`${T} not enough data for type`)}var P=[24,256,65536,4294967296,BigInt("18446744073709551616")];function ie(t,e,r){Ue(t,e,1);let n=t[e];if(r.strict===!0&&n<P[0])throw new Error(`${T} integer encoded in more bytes than necessary (strict decode)`);return n}function se(t,e,r){Ue(t,e,2);let n=t[e]<<8|t[e+1];if(r.strict===!0&&n<P[1])throw new Error(`${T} integer encoded in more bytes than necessary (strict decode)`);return n}function ae(t,e,r){Ue(t,e,4);let n=t[e]*16777216+(t[e+1]<<16)+(t[e+2]<<8)+t[e+3];if(r.strict===!0&&n<P[2])throw new Error(`${T} integer encoded in more bytes than necessary (strict decode)`);return n}function ce(t,e,r){Ue(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<P[3])throw new Error(`${T} integer encoded in more bytes than necessary (strict decode)`);if(i<=Number.MAX_SAFE_INTEGER)return Number(i);if(r.allowBigInt===!0)return i;throw new Error(`${T} integers outside of the safe integer range are not supported`)}function Ra(t,e,r,n){return new x(d.uint,ie(t,e+1,n),2)}function $a(t,e,r,n){return new x(d.uint,se(t,e+1,n),3)}function Ma(t,e,r,n){return new x(d.uint,ae(t,e+1,n),5)}function Pa(t,e,r,n){return new x(d.uint,ce(t,e+1,n),9)}function ke(t,e){return V(t,0,e.value)}function V(t,e,r){if(r<P[0]){let n=Number(r);t.pushByte(e|n)}else if(r<P[1]){let n=Number(r);t.pushArr([e|24,n])}else if(r<P[2]){let n=Number(r);t.pushArr([e|25,n>>>8,n&255])}else if(r<P[3]){let n=Number(r);t.pushArr([e|26,n>>>24&255,n>>>16&255,n>>>8&255,n&255])}else{let n=BigInt(r);if(n<P[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.pushArr(o)}else throw new Error(`${ve} encountered BigInt larger than allowable range`)}}ke.encodedSize=function(e){return V.encodedSize(e.value)};V.encodedSize=function(e){if(e<P[0])return 1;if(e<P[1])return 2;if(e<P[2])return 3;if(e<P[3])return 5;if(e>=P[4])throw new Error(`${ve} encountered BigInt larger than allowable range`);return 9};ke.compareTokens=function(e,r){return e.value<r.value?-1:e.value>r.value?1:0};function Fa(t,e,r,n){return new x(d.negint,-1-ie(t,e+1,n),2)}function Oa(t,e,r,n){return new x(d.negint,-1-se(t,e+1,n),3)}function za(t,e,r,n){return new x(d.negint,-1-ae(t,e+1,n),5)}var qo=BigInt(-1),Ha=BigInt(1);function Va(t,e,r,n){let o=ce(t,e+1,n);if(typeof o!="bigint"){let i=-1-o;if(i>=Number.MIN_SAFE_INTEGER)return new x(d.negint,i,9)}if(n.allowBigInt!==!0)throw new Error(`${T} integers outside of the safe integer range are not supported`);return new x(d.negint,qo-BigInt(o),9)}function fn(t,e){let r=e.value,n=typeof r=="bigint"?r*qo-Ha:r*-1-1;V(t,e.type.majorEncoded,n)}fn.encodedSize=function(e){let r=e.value,n=typeof r=="bigint"?r*qo-Ha:r*-1-1;if(n<P[0])return 1;if(n<P[1])return 2;if(n<P[2])return 3;if(n<P[3])return 5;if(n>=P[4])throw new Error(`${ve} encountered BigInt larger than allowable range`);return 9};fn.compareTokens=function(e,r){return e.value<r.value?1:e.value>r.value?-1:0};var Ga=globalThis.process&&!globalThis.process.browser&&globalThis.Buffer&&typeof globalThis.Buffer.isBuffer=="function",Cd=new TextEncoder;function ja(t){return Ga&&globalThis.Buffer.isBuffer(t)}var Nd=24,Dd=200,Go=Ga?t=>t.length>=Nd?globalThis.Buffer.from(t):qa(t):t=>t.length>=Dd?Cd.encode(t):qa(t),_e=t=>Uint8Array.from(t);function Lt(t,e){if(ja(t)&&ja(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 qa(t){let e=[],r=0;for(let n=0;n<t.length;n++){let o=t.charCodeAt(n);o<128?e[r++]=o:o<2048?(e[r++]=o>>6|192,e[r++]=o&63|128):(o&64512)===55296&&n+1<t.length&&(t.charCodeAt(n+1)&64512)===56320?(o=65536+((o&1023)<<10)+(t.charCodeAt(++n)&1023),e[r++]=o>>18|240,e[r++]=o>>12&63|128,e[r++]=o>>6&63|128,e[r++]=o&63|128):(o>=55296&&o<=57343&&(o=65533),e[r++]=o>>12|224,e[r++]=o>>6&63|128,e[r++]=o&63|128)}return e}function br(t,e,r,n){Ue(t,e,r+n);let o=t.slice(e+r,e+r+n);return new x(d.bytes,o,r+n)}function Wa(t,e,r,n){return br(t,e,1,r)}function Ya(t,e,r,n){return br(t,e,2,ie(t,e+1,n))}function Ja(t,e,r,n){return br(t,e,3,se(t,e+1,n))}function Ka(t,e,r,n){return br(t,e,5,ae(t,e+1,n))}function Xa(t,e,r,n){let o=ce(t,e+1,n);if(typeof o=="bigint")throw new Error(`${T} 64-bit integer bytes lengths not supported`);return br(t,e,9,o)}function ln(t){return t.encodedBytes===void 0&&(t.encodedBytes=d.equals(t.type,d.string)?Go(t.value):t.value),t.encodedBytes}function Rt(t,e){let r=ln(e);V(t,e.type.majorEncoded,r.length),t.push(r)}Rt.encodedSize=function(e){let r=ln(e);return V.encodedSize(r.length)+r.length};Rt.compareTokens=function(e,r){return Ud(ln(e),ln(r))};function Ud(t,e){return t.length<e.length?-1:t.length>e.length?1:Lt(t,e)}var Qa=new TextDecoder("utf-8",{ignoreBOM:!0}),Rd=new TextDecoder("utf-8",{ignoreBOM:!0,fatal:!0}),$d=32;function Md(t,e,r,n){if(r-e<$d){let i="";for(let s=e;s<r;s++){let a=t[s];if(a&128)return n.rejectInvalidUtf8===!0?Za(t,e,r):Qa.decode(t.subarray(e,r));i+=String.fromCharCode(a)}return i}return n.rejectInvalidUtf8===!0?Za(t,e,r):Qa.decode(t.subarray(e,r))}function Za(t,e,r){try{return Rd.decode(t.subarray(e,r))}catch{throw new Error(`${T} invalid UTF-8 in text string`)}}function Er(t,e,r,n,o){let i=r+n;Ue(t,e,i);let s=new x(d.string,Md(t,e+r,e+i,o),i);return o.retainStringBytes===!0&&(s.byteValue=t.slice(e+r,e+i)),s}function ec(t,e,r,n){return Er(t,e,1,r,n)}function tc(t,e,r,n){return Er(t,e,2,ie(t,e+1,n),n)}function rc(t,e,r,n){return Er(t,e,3,se(t,e+1,n),n)}function nc(t,e,r,n){return Er(t,e,5,ae(t,e+1,n),n)}function oc(t,e,r,n){let o=ce(t,e+1,n);if(typeof o=="bigint")throw new Error(`${T} 64-bit integer string lengths not supported`);return Er(t,e,9,o,n)}var ic=Rt;function $t(t,e,r,n){return new x(d.array,n,r)}function sc(t,e,r,n){return $t(t,e,1,r)}function ac(t,e,r,n){return $t(t,e,2,ie(t,e+1,n))}function cc(t,e,r,n){return $t(t,e,3,se(t,e+1,n))}function uc(t,e,r,n){return $t(t,e,5,ae(t,e+1,n))}function fc(t,e,r,n){let o=ce(t,e+1,n);if(typeof o=="bigint")throw new Error(`${T} 64-bit integer array lengths not supported`);return $t(t,e,9,o)}function lc(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${T} indefinite length items not allowed`);return $t(t,e,1,1/0)}function dn(t,e){V(t,d.array.majorEncoded,e.value)}dn.compareTokens=ke.compareTokens;dn.encodedSize=function(e){return V.encodedSize(e.value)};function Mt(t,e,r,n){return new x(d.map,n,r)}function dc(t,e,r,n){return Mt(t,e,1,r)}function hc(t,e,r,n){return Mt(t,e,2,ie(t,e+1,n))}function pc(t,e,r,n){return Mt(t,e,3,se(t,e+1,n))}function mc(t,e,r,n){return Mt(t,e,5,ae(t,e+1,n))}function yc(t,e,r,n){let o=ce(t,e+1,n);if(typeof o=="bigint")throw new Error(`${T} 64-bit integer map lengths not supported`);return Mt(t,e,9,o)}function gc(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${T} indefinite length items not allowed`);return Mt(t,e,1,1/0)}function hn(t,e){V(t,d.map.majorEncoded,e.value)}hn.compareTokens=ke.compareTokens;hn.encodedSize=function(e){return V.encodedSize(e.value)};function wc(t,e,r,n){return new x(d.tag,r,1)}function xc(t,e,r,n){return new x(d.tag,ie(t,e+1,n),2)}function bc(t,e,r,n){return new x(d.tag,se(t,e+1,n),3)}function Ec(t,e,r,n){return new x(d.tag,ae(t,e+1,n),5)}function vc(t,e,r,n){return new x(d.tag,ce(t,e+1,n),9)}function pn(t,e){V(t,d.tag.majorEncoded,e.value)}pn.compareTokens=ke.compareTokens;pn.encodedSize=function(e){return V.encodedSize(e.value)};var mn=20,yn=21,gn=22,wn=23;function _c(t,e,r,n){if(n.allowUndefined===!1)throw new Error(`${T} undefined values are not supported`);return n.coerceUndefinedToNull===!0?new x(d.null,null,1):new x(d.undefined,void 0,1)}function Ac(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${T} indefinite length items not allowed`);return new x(d.break,void 0,1)}function Wo(t,e,r){if(r){if(r.allowNaN===!1&&Number.isNaN(t))throw new Error(`${T} NaN values are not supported`);if(r.allowInfinity===!1&&(t===1/0||t===-1/0))throw new Error(`${T} Infinity values are not supported`)}return new x(d.float,t,e)}function Ic(t,e,r,n){return Wo(bn(t,e+1),3,n)}function Tc(t,e,r,n){return Wo(En(t,e+1),5,n)}function Bc(t,e,r,n){return Wo(Nc(t,e+1),9,n)}function xn(t,e,r){let n=e.value;if(n===!1)t.pushByte(d.float.majorEncoded|mn);else if(n===!0)t.pushByte(d.float.majorEncoded|yn);else if(n===null)t.pushByte(d.float.majorEncoded|gn);else if(n===void 0)d.equals(e.type,d.break)||t.pushByte(d.float.majorEncoded|wn);else{let o,i=!1;(!r||r.float64!==!0)&&(Yo(n),o=bn(z,1),n===o||Number.isNaN(n)?(z[0]=249,t.pushBytes(z.slice(0,3)),i=!0):(Jo(n),o=En(z,1),n===o&&(z[0]=250,t.pushBytes(z.slice(0,5)),i=!0))),i||(Cc(n),o=Nc(z,1),z[0]=251,t.pushBytes(z.slice(0,9)))}}xn.encodedSize=function(e,r){let n=e.value;if(n===void 0)return d.equals(e.type,d.break)?0:1;if(n===!1||n===!0||n===null)return 1;if(!r||r.float64!==!0){Yo(n);let o=bn(z,1);if(n===o||Number.isNaN(n))return 3;if(Jo(n),o=En(z,1),n===o)return 5}return 9};var Sc=new ArrayBuffer(9),de=new DataView(Sc,1),z=new Uint8Array(Sc,0);function Yo(t){if(t===1/0)de.setUint16(0,31744,!1);else if(t===-1/0)de.setUint16(0,64512,!1);else if(Number.isNaN(t))de.setUint16(0,32256,!1);else{de.setFloat32(0,t);let e=de.getUint32(0),r=(e&2139095040)>>23,n=e&8388607;if(r===255)de.setUint16(0,31744,!1);else if(r===0)de.setUint16(0,(e&2147483648)>>16|n>>13,!1);else{let o=r-127;o<-24?de.setUint16(0,0):o<-14?de.setUint16(0,(e&2147483648)>>16|(8388608|n)>>-1-o,!1):de.setUint16(0,(e&2147483648)>>16|o+15<<10|n>>13,!1)}}}function bn(t,e){if(t.length-e<2)throw new Error(`${T} not enough data for float16`);let r=(t[e]<<8)+t[e+1];if(r===31744)return 1/0;if(r===64512)return-1/0;if(r===32256)return NaN;let n=r>>10&31,o=r&1023,i;return n===0?i=o*2**-24:n!==31?i=(o+1024)*2**(n-25):i=o===0?1/0:NaN,r&32768?-i:i}function Jo(t){de.setFloat32(0,t,!1)}function En(t,e){if(t.length-e<4)throw new Error(`${T} not enough data for float32`);let r=(t.byteOffset||0)+e;return new DataView(t.buffer,r,4).getFloat32(0,!1)}function Cc(t){de.setFloat64(0,t,!1)}function Nc(t,e){if(t.length-e<8)throw new Error(`${T} not enough data for float64`);let r=(t.byteOffset||0)+e;return new DataView(t.buffer,r,8).getFloat64(0,!1)}function Hd(t,e){let r=t.value;if(r===!1)return Uint8Array.of(d.float.majorEncoded|mn);if(r===!0)return Uint8Array.of(d.float.majorEncoded|yn);if(r===null)return Uint8Array.of(d.float.majorEncoded|gn);if(r===void 0)return Uint8Array.of(d.float.majorEncoded|wn);if(!e){if(Yo(r),r===bn(z,1)||Number.isNaN(r))return z[0]=249,z.slice(0,3);if(Jo(r),r===En(z,1))return z[0]=250,z.slice(0,5)}return Cc(r),z[0]=251,z.slice(0,9)}function kc(t,e){let r=t,n=e?.float64===!0,o=n?r._keyBytesFloat64:r._keyBytes;if(o!==void 0)return o;let i=Hd(t,n);return n?r._keyBytesFloat64=i:r._keyBytes=i,i}xn.compareTokens=function(e,r,n){let o=kc(e,n),i=kc(r,n);return o.length!==i.length?o.length<i.length?-1:1:Lt(o,i)};function B(t,e,r){throw new Error(`${T} encountered invalid minor (${r}) for major ${t[e]>>>5}`)}function vn(t){return()=>{throw new Error(`${T} ${t}`)}}var w=[];for(let t=0;t<=23;t++)w[t]=B;w[24]=Ra;w[25]=$a;w[26]=Ma;w[27]=Pa;w[28]=B;w[29]=B;w[30]=B;w[31]=B;for(let t=32;t<=55;t++)w[t]=B;w[56]=Fa;w[57]=Oa;w[58]=za;w[59]=Va;w[60]=B;w[61]=B;w[62]=B;w[63]=B;for(let t=64;t<=87;t++)w[t]=Wa;w[88]=Ya;w[89]=Ja;w[90]=Ka;w[91]=Xa;w[92]=B;w[93]=B;w[94]=B;w[95]=vn("indefinite length bytes/strings are not supported");for(let t=96;t<=119;t++)w[t]=ec;w[120]=tc;w[121]=rc;w[122]=nc;w[123]=oc;w[124]=B;w[125]=B;w[126]=B;w[127]=vn("indefinite length bytes/strings are not supported");for(let t=128;t<=151;t++)w[t]=sc;w[152]=ac;w[153]=cc;w[154]=uc;w[155]=fc;w[156]=B;w[157]=B;w[158]=B;w[159]=lc;for(let t=160;t<=183;t++)w[t]=dc;w[184]=hc;w[185]=pc;w[186]=mc;w[187]=yc;w[188]=B;w[189]=B;w[190]=B;w[191]=gc;for(let t=192;t<=215;t++)w[t]=wc;w[216]=xc;w[217]=bc;w[218]=Ec;w[219]=vc;w[220]=B;w[221]=B;w[222]=B;w[223]=B;for(let t=224;t<=243;t++)w[t]=vn("simple values are not supported");w[244]=B;w[245]=B;w[246]=B;w[247]=_c;w[248]=vn("simple values are not supported");w[249]=Ic;w[250]=Tc;w[251]=Bc;w[252]=B;w[253]=B;w[254]=B;w[255]=Ac;var Ae=[];for(let t=0;t<24;t++)Ae[t]=new x(d.uint,t,1);for(let t=-1;t>=-24;t--)Ae[31-t]=new x(d.negint,t,1);Ae[64]=new x(d.bytes,new Uint8Array(0),1);Ae[96]=new x(d.string,"",1);Ae[128]=new x(d.array,0,1);Ae[160]=new x(d.map,0,1);Ae[244]=new x(d.false,!1,1);Ae[245]=new x(d.true,!0,1);Ae[246]=new x(d.null,null,1);function Ko(t){switch(t.type){case d.false:return _e([244]);case d.true:return _e([245]);case d.null:return _e([246]);case d.bytes:return t.value.length?void 0:_e([64]);case d.string:return t.value===""?_e([96]):void 0;case d.array:return t.value===0?_e([128]):void 0;case d.map:return t.value===0?_e([160]):void 0;case d.uint:return t.value<24?_e([Number(t.value)]):void 0;case d.negint:if(t.value>=-24)return _e([31-Number(t.value)])}}var Uc=Object.freeze({mapSorter:Yd,quickEncodeToken:Ko});function Xo(){let t=[];return t[d.uint.major]=ke,t[d.negint.major]=fn,t[d.bytes.major]=Rt,t[d.string.major]=ic,t[d.array.major]=dn,t[d.map.major]=hn,t[d.tag.major]=pn,t[d.float.major]=xn,t}var jd=Xo(),qd=new wr,Gd=!1,kn=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(`${ve} object contains circular references`);return new t(r,e)}},Ge={null:new x(d.null,null),undefined:new x(d.undefined,void 0),true:new x(d.true,!0),false:new x(d.false,!1),emptyArray:new x(d.array,0),emptyMap:new x(d.map,0)},he={number(t,e,r,n){return!Number.isInteger(t)||!Number.isSafeInteger(t)?new x(d.float,t):t>=0?new x(d.uint,t):new x(d.negint,t)},bigint(t,e,r,n){return t>=BigInt(0)?new x(d.uint,t):new x(d.negint,t)},Uint8Array(t,e,r,n){return new x(d.bytes,t)},string(t,e,r,n){return new x(d.string,t)},boolean(t,e,r,n){return t?Ge.true:Ge.false},null(t,e,r,n){return Ge.null},undefined(t,e,r,n){return Ge.undefined},ArrayBuffer(t,e,r,n){return new x(d.bytes,new Uint8Array(t))},DataView(t,e,r,n){return new x(d.bytes,new Uint8Array(t.buffer,t.byteOffset,t.byteLength))},Array(t,e,r,n){if(!t.length)return r.addBreakTokens===!0?[Ge.emptyArray,new x(d.break)]:Ge.emptyArray;n=kn.createCheck(n,t);let o=[],i=0;for(let s of t)o[i++]=We(s,r,n);return r.addBreakTokens?[new x(d.array,t.length),o,new x(d.break)]:[new x(d.array,t.length),o]},Object(t,e,r,n){let o=e!=="Object",i=o?t.keys():Object.keys(t),s=o?t.size:i.length,a;if(s){a=new Array(s),n=kn.createCheck(n,t);let c=!o&&r.ignoreUndefinedProperties,u=0;for(let l of i){let h=o?t.get(l):t[l];c&&h===void 0||(a[u++]=[We(l,r,n),We(h,r,n)])}u<s&&(a.length=u)}return a?.length?(Wd(a,r),r.addBreakTokens?[new x(d.map,a.length),a,new x(d.break)]:[new x(d.map,a.length),a]):r.addBreakTokens===!0?[Ge.emptyMap,new x(d.break)]:Ge.emptyMap},Tagged(t,e,r,n){return[new x(d.tag,t.tag),We(t.value,r,n)]}};he.Map=he.Object;function _n(t){return(e,r,n,o)=>{let i;try{i=t.call(e)}catch{throw new Error(`${ve} unsupported type: ${r} (object only claims the tag via Symbol.toStringTag)`)}return We(i,n,o)}}he.Number=_n(Number.prototype.valueOf);he.String=_n(String.prototype.valueOf);he.Boolean=_n(Boolean.prototype.valueOf);he.BigInt=_n(BigInt.prototype.valueOf);he.Buffer=he.Uint8Array;for(let t of"Uint8Clamped Uint16 Uint32 Int8 Int16 Int32 BigUint64 BigInt64 Float32 Float64".split(" "))he[`${t}Array`]=he.DataView;function We(t,e={},r){let n=La(t),o=e&&e.typeEncoders&&e.typeEncoders[n]||he[n];if(typeof o=="function"){let s=o(t,n,e,r);if(s!=null)return s}let i=he[n];if(!i)throw new Error(`${ve} unsupported type: ${n}`);return i(t,n,e,r)}function Wd(t,e){let r=e.mapSorter;r&&t.sort((n,o)=>r(n,o,e))}function Yd(t,e){if(t[0]instanceof x&&e[0]instanceof x){let r=t[0],n=e[0];r._keyBytes||(r._keyBytes=Dc(r.value)),n._keyBytes||(n._keyBytes=Dc(n.value));let o=Lt(r._keyBytes,n._keyBytes);if(o===0)throw new Error(`${ve} duplicate map key`);return o}throw new Error("rfc8949MapSorter: complex key types are not supported yet")}function Dc(t){return Jd(t,jd,Uc)}function Lc(t,e,r,n){if(Array.isArray(e))for(let o of e)Lc(t,o,r,n);else r[e.type.major](t,e,n)}var Ng=d.uint.majorEncoded,Dg=d.negint.majorEncoded,Ug=d.bytes.majorEncoded,Lg=d.string.majorEncoded,Rg=d.array.majorEncoded,$g=d.map.majorEncoded,Mg=d.float.majorEncoded|mn,Pg=d.float.majorEncoded|yn,Fg=d.float.majorEncoded|gn,Og=d.float.majorEncoded|wn,zg=BigInt(-1),Hg=BigInt(1);function Jd(t,e,r,n){let o=n!==void 0,i=We(t,r);if(!Array.isArray(i)&&r.quickEncodeToken){let a=r.quickEncodeToken(i);if(a){if(o){let u=new lt(n);return u.pushBytes(a),u.toBytes()}return a}let c=e[i.type.major];if(c.encodedSize){let u=c.encodedSize(i,r);if(o){let m=new lt(n);return c(m,i,r),m.toBytes()}let l=new Uint8Array(u),h=new lt(l);if(c(h,i,r),h.cursor!==u)throw new Error(`Unexpected error: pre-calculated length for ${i} was wrong`);return l}}let s=o?new lt(n):Gd?new wr:qd;return s.reset(),Lc(s,i,e,r),s.toBytes(!0)}var An=class t{constructor(e,r){if(typeof e!="number"||!Number.isInteger(e)||e<0)throw new TypeError("Tagged: tag must be a non-negative integer");this.tag=e,this.value=r}static decoder(e){return r=>new t(e,r())}static preserve(...e){let r={};for(let n of e)r[n]=t.decoder(n);return r}};Object.defineProperty(An.prototype,Symbol.toStringTag,{value:"Tagged"});var f0=Xo();var Kd=or(un(),1);var m0=[new x(d.map,2),new x(d.string,"version"),new x(d.uint,1),new x(d.string,"roots")],y0=new x(d.tag,42);async function Qo(t,e){let r=Ho(await t.upTo(8),t);if(r===0)throw new Error("Invalid CAR header (zero length)");let n=await t.exactly(r,!0),o=ft(n);if(jo.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=Vo(await t.exactly(zo,!0));t.seek(i.dataOffset-t.pos);let s=await Qo(t,1);return Object.assign(s,i)}function vr(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 Zo=or(un(),1),Oc=1;function ei(t){let e=Mo({version:Oc,roots:t}),r=Zo.default.encode(e.length),n=new Uint8Array(r.length+e.length);return n.set(r,0),n.set(e,r.length),n}function zc(t){return{async setRoots(e){let r=ei(e);await t.write(r)},async writeBlock(e){let{cid:r,bytes:n}=e;await t.write(new Uint8Array(Zo.default.encode(r.bytes.length+n.length))),await t.write(r.bytes),n.length&&await t.write(n)},async close(){await t.end()},error(e){t.error(e)},version(){return Oc}}}function In(){}function Hc(){let t=[],e=null,r=In,n=!1,o=null,i=null,s=In,a=()=>(e||(e=new Promise(l=>{r=()=>{e=null,r=In,l()}})),e),c={write(l){t.push(l);let h=a();return s(),h},async end(){n=!0;let l=a();s(),await l},error(l){o??=l,r(),s()}},u={async next(){let l=t.shift();if(l)return t.length===0&&r(),{done:!1,value:l};if(o)throw o;return n?(r(),{done:!0,value:void 0}):(i||(i=new Promise(h=>{s=()=>(i=null,s=In,h(u.next()))})),i)}};return{writer:c,iterator:u}}var Pt=class t{constructor(e,r){this._encoder=r,this._mutex=this._guard(r.setRoots(e)),this._ended=!1}_guard(e){return e.catch(r=>this._encoder.error(r instanceof Error?r:new Error(String(r)))),e}put(e){let r=e?.bytes instanceof Uint8Array&&e.cid?A.asCID(e.cid):null;return r?this._ended?Promise.reject(new Error("Already closed")):(this._mutex=this._guard(this._mutex.then(()=>this._encoder.writeBlock({cid:r,bytes:e.bytes}))),this._mutex):Promise.reject(new TypeError("Can only write {cid, bytes} objects"))}close(){return this._ended?Promise.reject(new Error("Already closed")):(this._ended=!0,this._guard(this._mutex.then(()=>this._encoder.close())))}version(){return this._encoder.version()}static create(e){e=Xd(e);let{encoder:r,iterator:n}=Vc(),o=new t(e,r),i=new Tn(n);return{writer:o,out:i}}static createAppender(){let{encoder:e,iterator:r}=Vc();e.setRoots=()=>Promise.resolve();let n=new t([],e),o=new Tn(r);return{writer:n,out:o}}static async updateRootsInBytes(e,r){let n=vr(e);await Qo(n);let o=ei(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}},Tn=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 Vc(){let t=Hc(),{writer:e,iterator:r}=t;return{encoder:zc(e),iterator:r}}function Xd(t){if(t===void 0)return[];if(!Array.isArray(t)){let r=A.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=A.asCID(r);if(!n)throw new TypeError("roots must be a single CID or an array of CIDs");e.push(n)}return e}function th(t){return t[Symbol.asyncIterator]!=null}function rh(t){if(th(t))return(async()=>{for await(let e of t);})();for(let e of t);}var jc=rh;function nh(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 Bn=nh;function oh(t){return t[Symbol.asyncIterator]!=null}function ih(t,e){let r=0;if(oh(t))return(async function*(){for await(let c of t)yield e(c,r++)})();let n=Bn(t),{value:o,done:i}=n.next();if(i===!0)return(function*(){})();let s=e(o,r++);if(typeof s.then=="function")return(async function*(){yield await s;for(let c of n)yield e(c,r++)})();let a=e;return(function*(){yield s;for(let c of n)yield a(c,r++)})()}var Sn=ih;function sh(t){return t.reason}function Ft(t,e,r){if(e==null||t==null)return t;let n=r?.translateError??sh;if(e.aborted)return t.catch(()=>{}),Promise.reject(n(e));let o;return Promise.race([t,new Promise((i,s)=>{o=()=>{s(n(e))},e.addEventListener("abort",o)})]).finally(()=>{o!=null&&e.removeEventListener("abort",o)})}var ah=20;function ht({name:t,code:e,encode:r,minDigestLength:n,maxDigestLength:o}){return new ti(t,e,r,n,o)}var ti=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,r,n,o,i){this.name=e,this.code=r,this.encode=n,this.minDigestLength=o??ah,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?qc(n,this.code,r?.truncate):n.then(o=>qc(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function qc(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 Dt(e,t)}var ni={};ee(ni,{base64:()=>ri,base64pad:()=>ch,base64url:()=>uh,base64urlpad:()=>fh});var ri=M({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),ch=M({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),uh=M({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),fh=M({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var oi={};ee(oi,{identity:()=>kr});var Wc=0,lh="identity",Yc=le;function dh(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 Dt(Wc,Yc(t))}var kr={code:Wc,name:lh,encode:Yc,digest:dh};function Ie(t=0){return new Uint8Array(t)}function hh(t){return t?.buffer instanceof ArrayBuffer}function Jc(t){if(hh(t))return t;let e=t.slice();return new Uint8Array(e.buffer,0,e.byteLength)}function _r(t,e){e==null&&(e=t.reduce((o,i)=>o+i.length,0));let r=Ie(e),n=0;for(let o of t)r.set(o,n),n+=o.length;return Jc(r)}function ph(t){return t.buffer instanceof ArrayBuffer}function Cn(t){return ph(t)?t:t.slice()}var mh=Math.pow(2,7),yh=Math.pow(2,14),gh=Math.pow(2,21),Kc=Math.pow(2,28),Xc=Math.pow(2,35),Qc=Math.pow(2,42),Zc=Math.pow(2,49),J=128,Ye=127;function Ar(t){if(t<mh)return 1;if(t<yh)return 2;if(t<gh)return 3;if(t<Kc)return 4;if(t<Xc)return 5;if(t<Qc)return 6;if(t<Zc)return 7;if(Number.MAX_SAFE_INTEGER!=null&&t>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function eu(t,e,r=0){switch(Ar(t)){case 8:e[r++]=t&255|J,t/=128;case 7:e[r++]=t&255|J,t/=128;case 6:e[r++]=t&255|J,t/=128;case 5:e[r++]=t&255|J,t/=128;case 4:e[r++]=t&255|J,t>>>=7;case 3:e[r++]=t&255|J,t>>>=7;case 2:e[r++]=t&255|J,t>>>=7;case 1:{e[r++]=t&255,t>>>=7;break}default:throw new Error("unreachable")}return e}function tu(t,e){let r=t[e],n=0;if(n+=r&Ye,r<J||(r=t[e+1],n+=(r&Ye)<<7,r<J)||(r=t[e+2],n+=(r&Ye)<<14,r<J)||(r=t[e+3],n+=(r&Ye)<<21,r<J)||(r=t[e+4],n+=(r&Ye)*Kc,r<J)||(r=t[e+5],n+=(r&Ye)*Xc,r<J)||(r=t[e+6],n+=(r&Ye)*Qc,r<J)||(r=t[e+7],n+=(r&Ye)*Zc,r<J))return n;throw new RangeError("Could not decode varint")}var ii={};ee(ii,{base10:()=>wh});var wh=Ve({prefix:"9",name:"base10",alphabet:"0123456789"});var si={};ee(si,{base16:()=>xh,base16upper:()=>bh});var xh=M({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4,caseInsensitive:!0}),bh=M({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4,caseInsensitive:!0});var ai={};ee(ai,{base2:()=>Eh});var Eh=M({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var ci={};ee(ci,{base256emoji:()=>Ih});var ru=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}"),vh=ru.reduce((t,e,r)=>(t[r]=e,t),[]),kh=ru.reduce((t,e,r)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return t[n]=r,t},[]);function _h(t){return t.reduce((e,r)=>(e+=vh[r],e),"")}function Ah(t){let e=[];for(let r of t){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=kh[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);e.push(o)}return new Uint8Array(e)}var Ih=Tt({prefix:"\u{1F680}",name:"base256emoji",encode:_h,decode:Ah});var ui={};ee(ui,{base8:()=>Th});var Th=M({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var fi={};ee(fi,{identity:()=>Bh});var Bh=Tt({prefix:"\0",name:"identity",encode:t=>pa(le(t)),decode:t=>le(ha(t))});var $w=new TextEncoder,Sh=new TextDecoder;var Nn=512;function Dn(t){return JSON.parse(Sh.decode(t))}var Ot=85;var li={};ee(li,{sha256:()=>Ch,sha512:()=>Nh});function nu(t){return async e=>new Uint8Array(await crypto.subtle.digest(t,e))}var Ch=ht({name:"sha2-256",code:18,encode:nu("SHA-256")}),Nh=ht({name:"sha2-512",code:19,encode:nu("SHA-512")});var di={...fi,...ai,...ui,...ii,...si,...Co,...No,...Do,...ni,...ci},Ow={...li,...oi};function iu(t,e,r,n){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:r},decoder:{decode:n}}}var ou=iu("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),hi=iu("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=Ie(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}),Dh={utf8:ou,"utf-8":ou,hex:di.base16,latin1:hi,ascii:hi,binary:hi,...di},su=Dh;function Ln(t,e="utf8"){let r=su[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.decoder.decode(`${r.prefix}${t}`)}var Te=class extends Error{static name="AbortError";constructor(e="The operation was aborted"){super(e),this.name="AbortError"}};var pt=class extends Error{static name="InvalidParametersError";constructor(e="Invalid parameters"){super(e),this.name="InvalidParametersError"}};function Uh(t){return typeof t?.handleEvent=="function"}function Lh(t){return t===!0||t===!1}function Rh(t){return Lh(t)?t:t?.capture??!1}function pi(t){let e={capture:Rh(t),once:!!t?.once};return t?.passive!=null&&(e.passive=t?.passive),t?.signal!=null&&(e.signal=t?.signal),e}function au(t,e){return pi(t).capture===pi(e).capture}var Rn=class extends EventTarget{#e=new Map;constructor(){super()}listenerCount(e){let r=this.#e.get(e);return r==null?0:r.length}addEventListener(e,r,n){let o=pi(n);if(o?.signal?.aborted===!0)return;let i=u=>{o.once&&this.removeEventListener(e,r,o),Uh(r)?r.handleEvent(u):r(u)},s=this.#e.get(e);if(s==null&&(s=[],this.#e.set(e,s)),s.some(u=>u.callback!==r?!1:au(u.options,o)))return;super.addEventListener(e,i,o);let c=()=>{this.removeEventListener(e,r,o)};o.signal?.addEventListener("abort",c),s.push({callback:r,wrapper:i,options:o,onAbort:c})}removeEventListener(e,r,n){let o=this.#e.get(e);if(o==null){super.removeEventListener(e,r??null,n);return}this.#e.set(e,o.filter(i=>i.callback===r&&au(i.options,n)?(super.removeEventListener(e,i.wrapper,n),i.options?.signal?.removeEventListener("abort",i.onAbort),!1):!0))}safeDispatchEvent(e,r={}){return this.dispatchEvent(new CustomEvent(e,r))}};function G(){let t={};return t.promise=new Promise((e,r)=>{t.resolve=e,t.reject=r}),t}var $n=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}},zt=class{size;hwm;head;tail;constructor(e={}){this.hwm=e.splitLimit??16,this.head=new $n(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 $n(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 mi=class extends Error{type;code;constructor(e,r){super(e??"The operation was aborted"),this.type="aborted",this.code=r??"ABORT_ERR"}};function Ht(t={}){return $h(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 $h(t,e){e=e??{};let r=e.onEnd,n=new zt,o,i,s,a=G(),c=async()=>{try{return n.isEmpty()?s?{done:!0}:await new Promise((b,v)=>{i=D=>{i=null,n.push(D);try{b(t(n))}catch(R){v(R)}return o}}):t(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=G()})}},u=b=>i!=null?i(b):(n.push(b),o),l=b=>(n=new zt,i!=null?i({error:b}):(n.push({error:b}),o)),h=b=>{if(s)return o;if(e?.objectMode!==!0&&b?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return u({done:!1,value:b})},m=b=>s?o:(s=!0,b!=null?l(b):u({done:!0})),E=()=>(n=new zt,m(),{done:!0}),_=b=>(m(b),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:c,return:E,throw:_,push:h,end:m,get readableLength(){return n.size},onEmpty:async b=>{let v=b?.signal;if(v?.throwIfAborted(),n.isEmpty())return;let D,R;v!=null&&(D=new Promise((N,$)=>{R=()=>{$(new mi)},v.addEventListener("abort",R)}));try{await Promise.race([a.promise,D])}finally{R!=null&&v!=null&&v?.removeEventListener("abort",R)}}},r==null)return o;let k=o;return o={[Symbol.asyncIterator](){return this},next(){return k.next()},throw(b){return k.throw(b),r!=null&&(r(b),r=void 0),{done:!0}},return(){return k.return(),r!=null&&(r(),r=void 0),{done:!0}},push:h,end(b){return k.end(b),r!=null&&(r(b),r=void 0),o},get readableLength(){return k.readableLength},onEmpty:b=>k.onEmpty(b)},o}var yi=class t extends Error{name="TimeoutError";constructor(e,r){super(e,r),Error.captureStackTrace?.(this,t)}},Mh=t=>"reason"in t?t.reason:new DOMException("This operation was aborted.","AbortError"),Ph=2**31-1,Fh=(t,e)=>{if(typeof t!="number"||Math.sign(t)!==1)return new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${t}\``);if(typeof e?.setTimeout!="function"||typeof e?.clearTimeout!="function")return new TypeError("Expected `customTimers` to have a `setTimeout` and a `clearTimeout` function")};function gi(t,e){let{milliseconds:r,fallback:n,message:o,customTimers:i={setTimeout,clearTimeout},signal:s}=e,a,c,u=()=>{try{t.cancel?.()}catch{}},h=new Promise((m,E)=>{let _=()=>{E(Mh(s)),u()},k=Fh(r,i);try{k?E(k):s?.aborted?_():s&&(c=_,s.addEventListener("abort",c,{once:!0}))}finally{t.then(m,E)}if(k||s?.aborted||r>Ph)return;let b=n||o===!1||o instanceof Error?void 0:new yi(o??`Promise timed out after ${r} milliseconds`);a=i.setTimeout.call(void 0,()=>{if(n)try{m(n())}catch(v){E(v)}else o===!1?m():E(o instanceof Error?o:b);u()},r)}).finally(()=>{try{h.clear()}catch{}try{c&&s.removeEventListener("abort",c)}catch{}});return h.clear=()=>{a!==void 0&&(i.clearTimeout.call(void 0,a),a=void 0)},h}var cu=t=>typeof t=="function"?{filter:t}:{...t},Oh=t=>t===1/0||Number.isSafeInteger(t)&&t>=0,zh=[["addEventListener","removeEventListener"],["on","off"],["addListener","removeListener"]],Hh=t=>{for(let[e,r]of zh){let n=t?.[e],o=t?.[r];if(typeof n=="function"&&typeof o=="function")return{addListener:n.bind(t),removeListener:o.bind(t)}}throw new TypeError("Emitter is not compatible")},Vh=t=>{let e=new Map;for(let[r,n]of t)for(let o of Array.isArray(r)?r:[r])e.has(o)||e.set(o,n);return e},jh=({addListener:t,removeListener:e,handlers:r,signal:n,abortHandler:o,isDone:i})=>{n?.addEventListener("abort",o,{once:!0});for(let[s,a]of r)if(t(s,a),i()){e(s,a);return}},qh=({removeListener:t,handlers:e,signal:r,abortHandler:n})=>{for(let[o,i]of e)t(o,i);r?.removeEventListener("abort",n)},Gh=(t,e,r)=>{let n=Promise.resolve();return(o,i)=>{n=n.then(async()=>{if(e())return;let s;try{s=t?await t(o):!0}catch(a){e()||r(a);return}e()||i(s)})}};function Wh(t,e,r){let n=()=>{},o=!1,i,s=new Promise((a,c)=>{r=cu(r);let{filter:u}=r;if(!Oh(r.count))throw new TypeError("The `count` option should be at least 0 or more");if(typeof r.timeout=="number"&&!(r.timeout>0))throw new TypeError(`Expected the \`timeout\` option to be a positive number, got \`${r.timeout}\``);r.signal?.throwIfAborted();let{addListener:l,removeListener:h}=Hh(t);if(r.count===0){a([]);return}let m=[],E=N=>{n(),c(N)},_=Gh(u,()=>o,E),k=N=>{m.push(N),r.count===m.length&&(n(),a(m))},b=(...N)=>{if(o)return;let $=r.multiArgs?N:N[0];if(!u){k($);return}_($,j=>{j&&k($)})},v=(...N)=>{E(r.rejectionMultiArgs?N:N[0])},D=()=>{E(r.signal.reason)},R={addListener:l,removeListener:h,handlers:Vh([[e,b],[r.rejectionEvents??["error"],v]]),signal:r.signal,abortHandler:D,isDone:()=>o};n=()=>{o=!0,clearTimeout(i),qh(R)},jh(R),!(o||!r.resolveImmediately)&&(Number.isFinite(r.timeout)&&r.timeout<=2**31-1&&(i=setTimeout(n,r.timeout)),a(m))});if(s.cancel=n,typeof r.timeout=="number"&&r.timeout>0&&!r.resolveImmediately){let a=gi(s,{milliseconds:r.timeout});return a.cancel=()=>{n(),a.clear()},a}return s}function Mn(t,e,r){let n=Wh(t,e,{...cu(r),count:1,resolveImmediately:!1}),o=n.then(i=>i[0]);return o.cancel=n.cancel,o}function wi(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 Pn=class extends Error{static name="QueueFullError";constructor(e="The queue was full"){super(e),this.name="QueueFullError"}};var Fn=class{deferred;signal;onProgress;constructor(e){this.signal=e?.signal,this.onProgress=e?.onProgress,this.deferred=G(),this.onAbort=this.onAbort.bind(this),this.signal?.addEventListener("abort",this.onAbort)}onAbort(){this.deferred.reject(this.signal?.reason??new Te)}cleanup(){this.signal?.removeEventListener("abort",this.onAbort)}};function Yh(){return`${parseInt(String(Math.random()*1e9),10).toString()}${Date.now()}`}var uu=new WeakMap,On=class{id;fn;options;recipients;status;timeline;controller;dispatchingProgress;constructor(e,r){this.id=Yh(),this.status="queued",this.fn=e,this.options=r,this.recipients=[],this.timeline={created:Date.now()},this.controller=new AbortController,this.controller.signal,this.dispatchingProgress=!1,this.onAbort=this.onAbort.bind(this)}abort(e){this.controller.abort(e)}onAbort(){this.recipients.reduce((r,n)=>r&&n.signal?.aborted===!0,!0)&&(this.controller.abort(new Te),this.cleanup())}async join(e){let r=new Fn(e);return this.recipients.push(r),e?.signal?.addEventListener("abort",this.onAbort),r.deferred.promise}async run(){this.status="running",this.timeline.started=Date.now();try{this.controller.signal.throwIfAborted();let e=await Ft(this.fn({...this.options??{},signal:this.controller.signal,onProgress:r=>{if(this.recipients.length!==0&&!this.dispatchingProgress){if(typeof r=="object"&&r!==null){let n=uu.get(r);if(n==null&&(n=new WeakSet,uu.set(r,n)),n.has(this))return;n.add(this)}this.dispatchingProgress=!0;try{this.recipients.forEach(n=>{n.onProgress?.(r)})}finally{this.dispatchingProgress=!1}}}}),this.controller.signal);this.recipients.forEach(r=>{r.deferred.resolve(e)}),this.status="complete"}catch(e){this.recipients.forEach(r=>{r.deferred.reject(e)}),this.status="errored"}finally{this.timeline.finished=Date.now(),this.cleanup()}}cleanup(){this.recipients.forEach(e=>{e.deferred.reject(e.signal?.reason??new Te),e.cleanup(),e.signal?.removeEventListener("abort",this.onAbort)}),this.recipients.splice(0,this.recipients.length)}};var Vt=class extends Rn{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=wi(this.emitEmpty.bind(this),1),this.emitIdle=wi(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 Pn;let n=new On(e,r);this.enqueue(n),this.safeDispatchEvent("add");let o=n.join(r).then(i=>(this.safeDispatchEvent("completed",{detail:i}),this.safeDispatchEvent("success",{detail:{job:n,result:i}}),i)).catch(i=>{if(n.status==="queued"){for(let s=0;s<this.queue.length;s++)if(this.queue[s]===n){this.queue.splice(s,1);break}}throw this.safeDispatchEvent("failure",{detail:{job:n,error:i}}),i});return this.tryToStartAnother(),o}clear(){this.queue.splice(0,this.queue.length)}abort(){this.queue.forEach(e=>{e.abort(new Te)}),this.clear()}async onEmpty(e){this.size!==0&&await Mn(this,"empty",e)}async onSizeLessThan(e,r){this.size<e||await Mn(this,"next",{...r,filter:()=>this.size<e})}async onIdle(e){this.pending===0&&this.size===0||await Mn(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=Ht({objectMode:!0}),n=c=>{c!=null?this.abort():this.clear(),r.end(c)},o=c=>{c.detail!=null&&r.push(c.detail)},i=c=>{n(c.detail.error)},s=()=>{n()},a=()=>{n(new Te("Queue aborted"))};this.addEventListener("completed",o),this.addEventListener("failure",i),this.addEventListener("idle",s),e?.signal?.addEventListener("abort",a);try{yield*r}finally{this.removeEventListener("completed",o),this.removeEventListener("failure",i),this.removeEventListener("idle",s),e?.signal?.removeEventListener("abort",a),n()}}};function fu(t){let e=new globalThis.AbortController;function r(){let i=t.filter(s=>s?.aborted===!0).map(s=>s?.reason).pop();e.abort(i);for(let s of t)s?.removeEventListener!=null&&s.removeEventListener("abort",r)}for(let i of t){if(i?.aborted===!0){r();break}i?.addEventListener!=null&&i.addEventListener("abort",r)}function n(){for(let i of t)i?.removeEventListener!=null&&i.removeEventListener("abort",r)}let o=e.signal;return o.clear=n,o}var xi=class{readNext;haveNext;ended;nextResult;error;constructor(){this.ended=!1,this.readNext=G(),this.haveNext=G()}[Symbol.asyncIterator](){return this}async next(){if(this.nextResult==null&&await this.haveNext.promise,this.nextResult==null)throw new Error("HaveNext promise resolved but nextResult was undefined");let e=this.nextResult;return this.nextResult=void 0,this.readNext.resolve(),this.readNext=G(),e}async throw(e){return this.ended=!0,this.error=e,e!=null&&(this.haveNext.promise.catch(()=>{}),this.haveNext.reject(e)),{done:!0,value:void 0}}async return(){let e={done:!0,value:void 0};return this.ended=!0,this.nextResult=e,this.haveNext.resolve(),e}async push(e,r){await this._push(e,r)}async end(e,r){e!=null?await this.throw(e):await this._push(void 0,r)}async _push(e,r){if(e!=null&&this.ended)throw this.error??new Error("Cannot push value onto an ended pushable");for(;this.nextResult!=null;)await this.readNext.promise;e!=null?this.nextResult={done:!1,value:e}:(this.ended=!0,this.nextResult={done:!0,value:void 0}),this.haveNext.resolve(),this.haveNext=G(),await Ft(this.readNext.promise,r?.signal,r)}};function lu(){return new xi}function du(t){return t[Symbol.asyncIterator]!=null}async function Jh(t,e,r){try{await Promise.all(t.map(async n=>{for(;;){let{value:o,done:i}=await n.next();if(i===!0)break;await e.push(o,{signal:r}),r.throwIfAborted()}})),await e.end(void 0,{signal:r})}catch(n){await e.end(n,{signal:r}).catch(()=>{})}}async function*Kh(t){let e=new AbortController,r=lu(),n=t.map(o=>du(o)?o[Symbol.asyncIterator]():o[Symbol.iterator]());Jh(n,r,e.signal).catch(()=>{});try{yield*r}finally{e.abort();for(let o of n)try{Promise.resolve(o.return?.()).catch(()=>{})}catch{}}}function*Xh(t){for(let e of t)yield*e}function Qh(...t){let e=[];for(let r of t)du(r)||e.push(r);return e.length===t.length?Xh(e):Kh(t)}var hu=Qh;function pu(t,...e){if(t==null)throw new Error("Empty pipeline");if(bi(t)){let n=t;t=()=>n.source}else if(yu(t)||mu(t)){let n=t;t=()=>n}let r=[t,...e];if(r.length>1&&bi(r[r.length-1])&&(r[r.length-1]=r[r.length-1].sink),r.length>2)for(let n=1;n<r.length-1;n++)bi(r[n])&&(r[n]=ep(r[n]));return Zh(...r)}var Zh=(...t)=>{let e;for(;t.length>0;)e=t.shift()(e);return e},mu=t=>t?.[Symbol.asyncIterator]!=null,yu=t=>t?.[Symbol.iterator]!=null,bi=t=>t==null?!1:t.sink!=null&&t.source!=null,ep=t=>e=>{let r=t.sink(e);if(r?.then!=null){let n=Ht({objectMode:!0});r.then(()=>{n.end()},s=>{n.end(s)});let o,i=t.source;if(mu(i))o=async function*(){yield*i,n.end()};else if(yu(i))o=function*(){yield*i,n.end()};else throw new Error("Unknown duplex source type - must be Iterable or AsyncIterable");return hu(n,o())}return t.source};function tp(t){return t[Symbol.asyncIterator]!=null}function rp(t,e){let r=0;if(tp(t))return(async function*(){for await(let c of t)await e(c,r++)&&(yield c)})();let n=Bn(t),{value:o,done:i}=n.next();if(i===!0)return(function*(){})();let s=e(o,r++);if(typeof s.then=="function")return(async function*(){await s&&(yield o);for(let c of n)await e(c,r++)&&(yield c)})();let a=e;return(function*(){s===!0&&(yield o);for(let c of n)a(c,r++)&&(yield c)})()}var gu=rp;function np(t){return t[Symbol.asyncIterator]!=null}function op(t){if(np(t))return(async()=>{let n=new Uint8Array(0);for await(let o of t)n=_r([n,o],n.length+o.length);return n})();let e=[],r=0;for(let n of t)e.push(n),r+=n.byteLength;return _r(e,r)}var S=op;function zn({enumerable:t=!0,configurable:e=!1}={}){return{enumerable:t,configurable:e,writable:!1}}function*ip(t,e){if(e!=null&&typeof e=="object")if(Array.isArray(e))for(let[r,n]of e.entries()){let o=[...t,r],i=A.asCID(n);i!=null?yield[o.join("/"),i]:typeof n=="object"&&(yield*Ei(n,o))}else{let r=A.asCID(e);r!=null?yield[t.join("/"),r]:yield*Ei(e,t)}}function*Ei(t,e){if(t==null||t instanceof Uint8Array)return;let r=A.asCID(t);r!=null&&(yield[e.join("/"),r]);for(let[n,o]of Object.entries(t)){let i=[...e,n];yield*ip(i,o)}}function*sp(t,e){if(Array.isArray(e))for(let[r,n]of e.entries()){let o=[...t,r];yield o.join("/"),typeof n=="object"&&A.asCID(n)==null&&(yield*vi(n,o))}else yield*vi(e,t)}function*vi(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"&&A.asCID(n)==null&&(yield*sp(o,n))}}function ap(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=A.asCID(r);if(i!=null)return{value:i,remaining:e.slice(n+1).join("/")}}return{value:r}}var ki=class{cid;bytes;value;asBlock;constructor({cid:e,bytes:r,value:n}){if(e==null||r==null||typeof n>"u")throw new Error("Missing required argument");this.cid=e,this.bytes=r,this.value=n,this.asBlock=this,Object.defineProperties(this,{cid:zn(),bytes:zn(),value:zn(),asBlock:zn()})}links(){return Ei(this.value,[])}tree(){return vi(this.value,[])}get(e="/"){return ap(this.value,e.split("/").filter(Boolean))}};function Be({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 ki({cid:e,bytes:t,value:o})}function jt(t){return e=>new _i(e,t)}function qt(t){return e=>new Ai(e,t)}function wu(t){return e=>new Ii(e,t)}var Tr=class{components;constructor(e,r={}){this.components=e}async*walk(e,r){let n=this.getQueue(),o=gu(n.toGenerator(r),c=>c!=null),i=!1,s=r?.depth??1/0,a=async c=>{let u=c.cid,l=await S(this.components.blockstore.get(u,c)),h=Be({cid:u,bytes:l,codec:await this.components.getCodec(u.code)});if(c.depth<s)for(let[,m]of h.links())r?.includeChild?.(m,h)!==!1&&n.add(a,{...c,cid:m,depth:c.depth+1,path:[...c.path,m]}).catch(E=>{i||o.throw(E)});return{block:h,depth:c.depth,path:c.path}};n.add(a,{...r,cid:e,depth:0,path:[e]}).catch(c=>{i||o.throw(c)});try{yield*o}finally{i=!0,n.abort()}}},_i=class extends Tr{getQueue(){return new Vt({concurrency:1,sort:(e,r)=>e.options.depth===r.options.depth?0:e.options.depth<r.options.depth?1:-1})}},Ai=class extends Tr{getQueue(){return new Vt({concurrency:1,sort:(e,r)=>e.options.depth===r.options.depth?0:e.options.depth<r.options.depth?-1:1})}},Ii=class extends Tr{getQueue(){return new Vt({concurrency:1})}};var Br=class{walker;constructor(e){this.walker=e?.walker}async*export(e,r,n,o){let i,s={blockstore:r,getCodec:n};this.walker!=null?i=this.walker(s):i=qt()(s);for await(let a of i.walk(e,o))yield a.block}};var Hn=class{components;log;constructor(e){this.components=e,this.log=e.logger.forComponent("helia:car")}async import(e,r){await jc(this.components.blockstore.putMany(Sn(e.blocks(),({cid:n,bytes:o})=>({cid:n,bytes:o})),r))}async*export(e,r){let n=Array.isArray(e)?e:[e],{writer:o,out:i}=Pt.create(n),s=i[Symbol.asyncIterator](),a=new AbortController;for(this._export(n,o,r).catch(c=>{this.log.error("error during streaming export - %e",c),a.abort(c)});;){let{done:c,value:u}=await Ft(s.next(),a.signal);if(a.signal.aborted)throw a.signal.reason;if(u!=null&&(yield u),c===!0)break}}async _export(e,r,n){let o=n?.traversal;for(let i of e){if(i.multihash.code===0)continue;let s=n?.exporter??(i.code===112?new Sr:new Br),a=i,c=!1;if(o!=null){for await(let{cid:u,bytes:l}of o.traverse(a,this.components.blockstore,this.components.getCodec,n))if(this.log.trace("next CID on path to %c is %c",i,u),a=u,i.equals(u)&&(c=!0),c||n?.includeTraversalBlocks===!0){if(n?.blockFilter?.has(u.multihash.bytes)===!0)continue;n?.blockFilter?.add(u.multihash.bytes),await r.put({cid:u,bytes:l})}}for await(let{cid:u,bytes:l}of s.export(a,this.components.blockstore,this.components.getCodec,n))n?.blockFilter?.has(u.multihash.bytes)!==!0&&u.multihash.code!==0&&(c&&u.equals(a)||(n?.blockFilter?.add(u.multihash.bytes),await r.put({cid:u,bytes:l})))}await r.close()}};var Ti=class{async*export(e,r,n,o){let i=await S(r.get(e,o));yield Be({cid:e,bytes:i,codec:await n(e.code)})}};var Cr=class t extends Error{static name="InvalidTypeError";static code="ERR_INVALID_TYPE";name=t.name;code=t.code;constructor(e="Invalid type"){super(e)}};var Bi=new Float32Array([-0]),Je=new Uint8Array(Bi.buffer);function bu(t,e,r){Bi[0]=t,e[r]=Je[0],e[r+1]=Je[1],e[r+2]=Je[2],e[r+3]=Je[3]}function Eu(t,e){return Je[0]=t[e],Je[1]=t[e+1],Je[2]=t[e+2],Je[3]=t[e+3],Bi[0]}var Si=new Float64Array([-0]),W=new Uint8Array(Si.buffer);function vu(t,e,r){Si[0]=t,e[r]=W[0],e[r+1]=W[1],e[r+2]=W[2],e[r+3]=W[3],e[r+4]=W[4],e[r+5]=W[5],e[r+6]=W[6],e[r+7]=W[7]}function ku(t,e){return W[0]=t[e],W[1]=t[e+1],W[2]=t[e+2],W[3]=t[e+3],W[4]=t[e+4],W[5]=t[e+5],W[6]=t[e+6],W[7]=t[e+7],Si[0]}var up=BigInt(Number.MAX_SAFE_INTEGER),fp=BigInt(Number.MIN_SAFE_INTEGER),ue=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 mt;if(e<up&&e>fp)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>_u&&(o=0n,++n>_u&&(n=0n))),new t(Number(o),Number(n))}static fromNumber(e){if(e===0)return mt;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):mt}},mt=new ue(0,0);mt.toBigInt=function(){return 0n};mt.zzEncode=mt.zzDecode=function(){return this};mt.length=function(){return 1};var _u=4294967296n;function Au(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 Iu(t,e,r){if(r-e<1)return"";let o,i=[],s=0,a;for(;e<r;)a=t[e++],a<128?i[s++]=a:a>191&&a<224?i[s++]=(a&31)<<6|t[e++]&63:a>239&&a<365?(a=((a&7)<<18|(t[e++]&63)<<12|(t[e++]&63)<<6|t[e++]&63)-65536,i[s++]=55296+(a>>10),i[s++]=56320+(a&1023)):i[s++]=(a&15)<<12|(t[e++]&63)<<6|t[e++]&63,s>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,i)),s=0);return o!=null?(s>0&&o.push(String.fromCharCode.apply(String,i.slice(0,s))),o.join("")):String.fromCharCode.apply(String,i.slice(0,s))}function Ci(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 ge(t,e){return RangeError(`index out of range: ${t.pos} + ${e??1} > ${t.len}`)}function Vn(t,e){return(t[e-4]|t[e-3]<<8|t[e-2]<<16|t[e-1]<<24)>>>0}var Ni=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(e){this.buf=Cn(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,ge(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 ge(this,4);return Vn(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw ge(this,4);return Vn(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw ge(this,4);let e=Eu(this.buf,this.pos);return this.pos+=4,e}double(){if(this.pos+8>this.len)throw ge(this,4);let e=ku(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 ge(this,e);return this.pos+=e,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let e=this.bytes();return Iu(e,0,e.length)}skip(e){if(typeof e=="number"){if(this.pos+e>this.len)throw ge(this,e);this.pos+=e}else do if(this.pos>=this.len)throw ge(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 ue(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 ge(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 ge(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 ge(this,8);let e=Vn(this.buf,this.pos+=4),r=Vn(this.buf,this.pos+=4);return new ue(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=tu(this.buf,this.pos);return this.pos+=Ar(e),e}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function Nr(t){return new Ni(t instanceof Uint8Array?t:t.subarray())}function Ke(t,e,r){let n=Nr(t);return e.decode(n,void 0,r)}function Di(t){let e=t??8192,r=e>>>1,n,o=e;return function(s){if(s<1||s>r)return Ie(s);o+s>e&&(n=Ie(e),o=0);let a=n.subarray(o,o+=s);return(o&7)!==0&&(o=(o|7)+1),a}}var yt=class{fn;len;next;val;constructor(e,r,n){this.fn=e,this.len=r,this.next=void 0,this.val=n}};function Ui(){}var Ri=class{head;tail;len;next;constructor(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}},lp=Di();function dp(t){return globalThis.Buffer!=null?Ie(t):lp(t)}var Ur=class{len;head;tail;states;constructor(){this.len=0,this.head=new yt(Ui,0,0),this.tail=this.head,this.states=null}_push(e,r,n){return this.tail=this.tail.next=new yt(e,r,n),this.len+=r,this}uint32(e){return this.len+=(this.tail=this.tail.next=new $i((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(jn,10,ue.fromNumber(e)):this.uint32(e)}sint32(e){return this.uint32((e<<1^e>>31)>>>0)}uint64(e){let r=ue.fromBigInt(e);return this._push(jn,r.length(),r)}uint64Number(e){return this._push(eu,Ar(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=ue.fromBigInt(e).zzEncode();return this._push(jn,r.length(),r)}sint64Number(e){let r=ue.fromNumber(e).zzEncode();return this._push(jn,r.length(),r)}sint64String(e){return this.sint64(BigInt(e))}bool(e){return this._push(Li,1,e?1:0)}fixed32(e){return this._push(Dr,4,e>>>0)}sfixed32(e){return this.fixed32(e)}fixed64(e){let r=ue.fromBigInt(e);return this._push(Dr,4,r.lo)._push(Dr,4,r.hi)}fixed64Number(e){let r=ue.fromNumber(e);return this._push(Dr,4,r.lo)._push(Dr,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(bu,4,e)}double(e){return this._push(vu,8,e)}bytes(e){let r=e.length>>>0;return r===0?this._push(Li,1,0):this.uint32(r)._push(pp,r,e)}string(e){let r=Au(e);return r!==0?this.uint32(r)._push(Ci,r,e):this._push(Li,1,0)}fork(){return this.states=new Ri(this),this.head=this.tail=new yt(Ui,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 yt(Ui,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=dp(this.len),n=0;for(;e!=null;)e.fn(e.val,r,n),n+=e.len,e=e.next;return r}};function Li(t,e,r){e[r]=t&255}function hp(t,e,r){for(;t>127;)e[r++]=t&127|128,t>>>=7;e[r]=t}var $i=class extends yt{next;constructor(e,r){super(hp,e,r),this.next=void 0}};function jn(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 Dr(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 pp(t,e,r){e.set(t,r)}globalThis.Buffer!=null&&(Ur.prototype.bytes=function(t){let e=t.length>>>0;return this.uint32(e),e>0&&this._push(mp,e,t),this},Ur.prototype.string=function(t){let e=globalThis.Buffer.byteLength(t);return this.uint32(e),e>0&&this._push(yp,e,t),this});function mp(t,e,r){e.set(t,r)}function yp(t,e,r){t.length<40?Ci(t,e,r):e.utf8Write!=null?e.utf8Write(t,r):e.set(Ln(t),r)}function Mi(){return new Ur}function Xe(t,e){let r=Mi();return e.encode(t,r,{lengthDelimited:!1}),r.finish()}function*Qe(t,e,r){let n=Nr(t);yield*e.stream(n,void 0,".",r)}var qn={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function Gn(t,e,r,n,o){return{name:t,type:e,encode:r,decode:n,stream:o}}function Pi(t){function e(i){if(t[i.toString()]==null)throw new Error("Invalid enum value");return t[i]}let r=function(s,a){let c=e(s);a.int32(c)},n=function(s){let a=s.int32();return e(a)},o=function*(s,a){};return Gn("enum",qn.VARINT,r,n,o)}function Ze(t,e,r){return Gn("message",qn.LENGTH_DELIMITED,t,e,r)}var Le=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var q;(function(t){let e;(function(a){a.RAW="RAW",a.DIRECTORY="DIRECTORY",a.FILE="FILE",a.METADATA="METADATA",a.SYMLINK="SYMLINK",a.HAMT_SHARD="HAMT_SHARD"})(e=t.Type||(t.Type={}));let r;(function(a){a[a.RAW=0]="RAW",a[a.DIRECTORY=1]="DIRECTORY",a[a.FILE=2]="FILE",a[a.METADATA=3]="METADATA",a[a.SYMLINK=4]="SYMLINK",a[a.HAMT_SHARD=5]="HAMT_SHARD"})(r||(r={})),(function(a){a.codec=()=>Pi(r)})(e=t.Type||(t.Type={}));let n;t.codec=()=>(n==null&&(n=Ze((a,c,u={})=>{if(u.lengthDelimited!==!1&&c.fork(),a.type!=null&&(c.uint32(8),t.Type.codec().encode(a.type,c)),a.data!=null&&(c.uint32(18),c.bytes(a.data)),a.fileSize!=null&&(c.uint32(24),c.uint64(a.fileSize)),a.blockSizes!=null&&a.blockSizes.length>0)for(let l of a.blockSizes)c.uint32(32),c.uint64(l);a.hashType!=null&&(c.uint32(40),c.uint64(a.hashType)),a.fanOut!=null&&(c.uint32(48),c.uint64(a.fanOut)),a.mode!=null&&(c.uint32(56),c.uint32(a.mode)),a.mtime!=null&&(c.uint32(66),Lr.codec().encode(a.mtime,c)),u.lengthDelimited!==!1&&c.ldelim()},(a,c,u={})=>{let l={blockSizes:[]},h=c==null?a.len:a.pos+c;for(;a.pos<h;){let m=a.uint32();switch(m>>>3){case 1:{l.type=t.Type.codec().decode(a);break}case 2:{l.data=a.bytes();break}case 3:{l.fileSize=a.uint64();break}case 4:{if(u.limits?.blockSizes!=null&&l.blockSizes.length===u.limits.blockSizes)throw new Le('Decode error - repeated field "blockSizes" had too many elements');l.blockSizes.push(a.uint64());break}case 5:{l.hashType=a.uint64();break}case 6:{l.fanOut=a.uint64();break}case 7:{l.mode=a.uint32();break}case 8:{l.mtime=Lr.codec().decode(a,a.uint32(),{limits:u.limits?.mtime});break}default:{a.skipType(m&7);break}}}return l},function*(a,c,u,l={}){let h={blockSizes:0},m=c==null?a.len:a.pos+c;for(u!=="."&&(yield{field:u.endsWith(".")?u.substring(0,u.length-1):u,type:"start",message:"UnixFS"});a.pos<m;){let E=a.uint32();switch(E>>>3){case 1:{yield{field:`${u}type`,value:t.Type.codec().decode(a)};break}case 2:{yield{field:`${u}data`,value:a.bytes()};break}case 3:{yield{field:`${u}fileSize`,value:a.uint64()};break}case 4:{if(l.limits?.blockSizes!=null&&h.blockSizes===l.limits.blockSizes)throw new Le('Streaming decode error - repeated field "blockSizes" had too many elements');yield{field:`${u}blockSizes[]`,index:h.blockSizes,value:a.uint64()},h.blockSizes++;break}case 5:{yield{field:`${u}hashType`,value:a.uint64()};break}case 6:{yield{field:`${u}fanOut`,value:a.uint64()};break}case 7:{yield{field:`${u}mode`,value:a.uint32()};break}case 8:{yield*Lr.codec().stream(a,a.uint32(),`${u}mtime.`,{limits:l.limits?.mtime});break}default:{a.skipType(E&7);break}}}u!=="."&&(yield{field:u.endsWith(".")?u.substring(0,u.length-1):u,type:"end",message:"UnixFS"})})),n);function o(a){return Xe(a,t.codec())}t.encode=o;function i(a,c){return Ke(a,t.codec(),c)}t.decode=i;function s(a,c){return Qe(a,t.codec(),c)}t.stream=s})(q||(q={}));var Lr;(function(t){let e;t.codec=()=>(e==null&&(e=Ze((i,s,a={})=>{a.lengthDelimited!==!1&&s.fork(),i.seconds!=null&&(s.uint32(8),s.int64(i.seconds)),i.fractionalNanoseconds!=null&&(s.uint32(21),s.fixed32(i.fractionalNanoseconds)),a.lengthDelimited!==!1&&s.ldelim()},(i,s)=>{let a={},c=s==null?i.len:i.pos+s;for(;i.pos<c;){let u=i.uint32();switch(u>>>3){case 1:{a.seconds=i.int64();break}case 2:{a.fractionalNanoseconds=i.fixed32();break}default:{i.skipType(u&7);break}}}return a},function*(i,s,a){let c=s==null?i.len:i.pos+s;for(a!=="."&&(yield{field:a.endsWith(".")?a.substring(0,a.length-1):a,type:"start",message:"UnixTime"});i.pos<c;){let u=i.uint32();switch(u>>>3){case 1:{yield{field:`${a}seconds`,value:i.int64()};break}case 2:{yield{field:`${a}fractionalNanoseconds`,value:i.fixed32()};break}default:{i.skipType(u&7);break}}}a!=="."&&(yield{field:a.endsWith(".")?a.substring(0,a.length-1):a,type:"end",message:"UnixTime"})})),e);function r(i){return Xe(i,t.codec())}t.encode=r;function n(i,s){return Ke(i,t.codec(),s)}t.decode=n;function o(i,s){return Qe(i,t.codec(),s)}t.stream=o})(Lr||(Lr={}));var Bu;(function(t){let e;t.codec=()=>(e==null&&(e=Ze((i,s,a={})=>{a.lengthDelimited!==!1&&s.fork(),i.mimeType!=null&&(s.uint32(10),s.string(i.mimeType)),a.lengthDelimited!==!1&&s.ldelim()},(i,s)=>{let a={},c=s==null?i.len:i.pos+s;for(;i.pos<c;){let u=i.uint32();u>>>3===1?a.mimeType=i.string():i.skipType(u&7)}return a},function*(i,s,a){let c=s==null?i.len:i.pos+s;for(a!=="."&&(yield{field:a.endsWith(".")?a.substring(0,a.length-1):a,type:"start",message:"Metadata"});i.pos<c;){let u=i.uint32();u>>>3===1?yield{field:`${a}mimeType`,value:i.string()}:i.skipType(u&7)}a!=="."&&(yield{field:a.endsWith(".")?a.substring(0,a.length-1):a,type:"end",message:"Metadata"})})),e);function r(i){return Xe(i,t.codec())}t.encode=r;function n(i,s){return Ke(i,t.codec(),s)}t.decode=n;function o(i,s){return Qe(i,t.codec(),s)}t.stream=o})(Bu||(Bu={}));var et;(function(t){let e;t.codec=()=>(e==null&&(e=Ze((i,s,a={})=>{a.lengthDelimited!==!1&&s.fork(),i.hash!=null&&(s.uint32(10),s.bytes(i.hash)),i.name!=null&&(s.uint32(18),s.string(i.name)),i.tSize!=null&&(s.uint32(24),s.uint64(i.tSize)),a.lengthDelimited!==!1&&s.ldelim()},(i,s)=>{let a={},c=s==null?i.len:i.pos+s;for(;i.pos<c;){let u=i.uint32();switch(u>>>3){case 1:{a.hash=i.bytes();break}case 2:{a.name=i.string();break}case 3:{a.tSize=i.uint64();break}default:{i.skipType(u&7);break}}}return a},function*(i,s,a){let c=s==null?i.len:i.pos+s;for(a!=="."&&(yield{field:a.endsWith(".")?a.substring(0,a.length-1):a,type:"start",message:"Link"});i.pos<c;){let u=i.uint32();switch(u>>>3){case 1:{yield{field:`${a}hash`,value:i.bytes()};break}case 2:{yield{field:`${a}name`,value:i.string()};break}case 3:{yield{field:`${a}tSize`,value:i.uint64()};break}default:{i.skipType(u&7);break}}}a!=="."&&(yield{field:a.endsWith(".")?a.substring(0,a.length-1):a,type:"end",message:"Link"})})),e);function r(i){return Xe(i,t.codec())}t.encode=r;function n(i,s){return Ke(i,t.codec(),s)}t.decode=n;function o(i,s){return Qe(i,t.codec(),s)}t.stream=o})(et||(et={}));var Gt;(function(t){let e;t.codec=()=>(e==null&&(e=Ze((i,s,a={})=>{if(a.lengthDelimited!==!1&&s.fork(),i.data!=null&&(s.uint32(10),q.codec().encode(i.data,s)),i.links!=null&&i.links.length>0)for(let c of i.links)s.uint32(18),et.codec().encode(c,s);a.lengthDelimited!==!1&&s.ldelim()},(i,s,a={})=>{let c={links:[]},u=s==null?i.len:i.pos+s;for(;i.pos<u;){let l=i.uint32();switch(l>>>3){case 1:{c.data=q.codec().decode(i,i.uint32(),{limits:a.limits?.data});break}case 2:{if(a.limits?.links!=null&&c.links.length===a.limits.links)throw new Le('Decode error - repeated field "links" had too many elements');c.links.push(et.codec().decode(i,i.uint32(),{limits:a.limits?.links$}));break}default:{i.skipType(l&7);break}}}return c},function*(i,s,a,c={}){let u={links:0},l=s==null?i.len:i.pos+s;for(a!=="."&&(yield{field:a.endsWith(".")?a.substring(0,a.length-1):a,type:"start",message:"Node"});i.pos<l;){let h=i.uint32();switch(h>>>3){case 1:{yield*q.codec().stream(i,i.uint32(),`${a}data.`,{limits:c.limits?.data});break}case 2:{if(c.limits?.links!=null&&u.links===c.limits.links)throw new Le('Streaming decode error - repeated field "links" had too many elements');for(let m of et.codec().stream(i,i.uint32(),`${a}links[].`,{limits:c.limits?.links$}))yield{...m,index:u.links};u.links++;break}default:{i.skipType(h&7);break}}}a!=="."&&(yield{field:a.endsWith(".")?a.substring(0,a.length-1):a,type:"end",message:"Node"})})),e);function r(i){return Xe(i,t.codec())}t.encode=r;function n(i,s){return Ke(i,t.codec(),s)}t.decode=n;function o(i,s){return Qe(i,t.codec(),s)}t.stream=o})(Gt||(Gt={}));var Su;(function(t){let e;t.codec=()=>(e==null&&(e=Ze((i,s,a={})=>{if(a.lengthDelimited!==!1&&s.fork(),i.links!=null&&i.links.length>0)for(let c of i.links)s.uint32(18),et.codec().encode(c,s);i.data!=null&&(s.uint32(10),q.codec().encode(i.data,s)),a.lengthDelimited!==!1&&s.ldelim()},(i,s,a={})=>{let c={links:[]},u=s==null?i.len:i.pos+s;for(;i.pos<u;){let l=i.uint32();switch(l>>>3){case 2:{if(a.limits?.links!=null&&c.links.length===a.limits.links)throw new Le('Decode error - repeated field "links" had too many elements');c.links.push(et.codec().decode(i,i.uint32(),{limits:a.limits?.links$}));break}case 1:{c.data=q.codec().decode(i,i.uint32(),{limits:a.limits?.data});break}default:{i.skipType(l&7);break}}}return c},function*(i,s,a,c={}){let u={links:0},l=s==null?i.len:i.pos+s;for(a!=="."&&(yield{field:a.endsWith(".")?a.substring(0,a.length-1):a,type:"start",message:"LegacyNode"});i.pos<l;){let h=i.uint32();switch(h>>>3){case 2:{if(c.limits?.links!=null&&u.links===c.limits.links)throw new Le('Streaming decode error - repeated field "links" had too many elements');for(let m of et.codec().stream(i,i.uint32(),`${a}links[].`,{limits:c.limits?.links$}))yield{...m,index:u.links};u.links++;break}case 1:{yield*q.codec().stream(i,i.uint32(),`${a}data.`,{limits:c.limits?.data});break}default:{i.skipType(h&7);break}}}a!=="."&&(yield{field:a.endsWith(".")?a.substring(0,a.length-1):a,type:"end",message:"LegacyNode"})})),e);function r(i){return Xe(i,t.codec())}t.encode=r;function n(i,s){return Ke(i,t.codec(),s)}t.decode=n;function o(i,s){return Qe(i,t.codec(),s)}t.stream=o})(Su||(Su={}));var Cu={RAW:"raw",DIRECTORY:"directory",FILE:"file",METADATA:"metadata",SYMLINK:"symlink",HAMT_SHARD:"hamt-sharded-directory"},gp=["directory","hamt-sharded-directory"],Nu=parseInt("0644",8),Du=parseInt("0755",8),Se=class t{static unmarshal(e){let r=q.decode(e),n=new t({type:Cu[r.type!=null?r.type.toString():"FILE"],data:r.data,blockSizes:r.blockSizes,mode:r.mode,mtime:r.mtime!=null?{secs:r.mtime.seconds??0n,nsecs:r.mtime.fractionalNanoseconds}:void 0,fanout:r.fanOut});return n._originalMode=r.mode??0,n}type;data;blockSizes;hashType;fanout;mtime;_mode;_originalMode;constructor(e={type:"file"}){let{type:r,data:n,blockSizes:o,hashType:i,fanout:s,mtime:a,mode:c}=e;if(r!=null&&!Object.values(Cu).includes(r))throw new Cr("Type: "+r+" is not valid");this.type=r??"file",this.hashType=i,this.fanout=s,this.blockSizes=o??[],this._originalMode=0,this.mode=c,this.mtime=a,n!=null&&(this.data=Cn(n))}set mode(e){e==null?this._mode=this.isDirectory()?Du:Nu:this._mode=e&4095}get mode(){return this._mode}isDirectory(){return gp.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=q.Type.RAW;break;case"directory":e=q.Type.DIRECTORY;break;case"file":e=q.Type.FILE;break;case"metadata":e=q.Type.METADATA;break;case"symlink":e=q.Type.SYMLINK;break;case"hamt-sharded-directory":e=q.Type.HAMT_SHARD;break;default:throw new Cr(`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===Nu&&!this.isDirectory()&&(n=void 0),n===Du&&this.isDirectory()&&(n=void 0));let o;return this.mtime!=null&&(o={seconds:this.mtime.secs,fractionalNanoseconds:this.mtime.nsecs}),q.encode({type:e,data:r,fileSize:this.type==="file"||this.type==="raw"?this.fileSize():void 0,blockSizes:this.blockSizes,hashType:this.hashType,fanOut:this.fanout,mode:n,mtime:o})}};var Rr=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"},Wn=class extends Error{static name="NotDescendantError";name="NotDescendantError"},Wt=class extends Error{static name="InvalidTraversalError";name="InvalidTraversalError"};function xp(t){return t.cid.code===85}function bp(t){return t.cid.code===112}function Ep(t){if(xp(t))return!0;if(bp(t)&&t.value.Data!=null){let e=Se.unmarshal(t.value.Data);return e.type==="file"||e.type==="raw"}else throw new Rr("Encountered non raw/dag-pb CID in UnixFS DAG")}var Sr=class{options;constructor(e){this.options=e}async*export(e,r,n,o){if(e.code!==112&&e.code!==85)throw new Rr("Target CID was not UnixFS - use the SubGraphExporter to export arbitrary graphs");let i=jt()({blockstore:r,getCodec:n}),s=this.options?.offset??0,a=this.options?.length??1/0,c=this.options?.listingOnly??!1;if(s<0)throw new pt("Offset cannot be negative");if(a<0)throw new pt("Length cannot be negative");let u,l=new AbortController,h=fu([l.signal,o?.signal]);l.signal;function m(E,_){if(u==null&&(u=Ep(_)),!u){let $=_.value.Links.find(Ce=>Ce.Hash.equals(E)),j=Se.unmarshal(_.value.Data??new Uint8Array);return j.type==="directory"?!c:j.type==="hamt-sharded-directory"&&c?$?.Name?.length===2:!0}let k=_.value.Links.findIndex($=>$.Hash.equals(E)),b=Se.unmarshal(_.value.Data??new Uint8Array),v=s,D=v+a,R=Number([...b.blockSizes].slice(0,k).reduce(($,j)=>$+j,0n)),N=R+Number(b.blockSizes[k]);return v>=R&&v<N||D>=R&&D<N||v<=R&&D>=N}try{for await(let E of i.walk(e,{...o,includeChild:m,signal:h}))yield E.block}finally{l.abort(),h.clear()}}};function Uu(t){return t!=null&&t?.asCID===t}var Fi=class{haystack;needle;options;walker;constructor(...e){if(Uu(e[0]))Uu(e[1])?(this.haystack=e[0],this.needle=e[1],this.options=e[2]):(this.needle=e[0],this.options=e[1]);else throw new pt("needle must be specified");this.walker=this.options?.walker}async*traverse(e,r,n,o){let i=this.haystack??e,s,a={blockstore:r,getCodec:n};this.walker!=null?s=this.walker(a):this.options?.strategy==="breadth-first"?s=qt()(a):s=jt()(a);for await(let c of s.walk(i,o))if(c.block.cid.equals(this.needle)){for(let u of c.path){let l=await S(r.get(u,o));yield Be({cid:u,bytes:l,codec:await n(u.code)})}return}throw new Wt(`${this.needle} was not a child of ${i}`)}};var Oi=class{path;constructor(e){this.path=e}async*traverse(e,r,n,o){if(!this.path.some(s=>s.equals(e)))throw new Wt(`CIDPath traversal must include ${e}`);let i;for(let s of this.path){if(i!=null){let u=!1;for(let[,l]of i.links())if(l.equals(s)){u=!0;break}if(!u)throw new Wn(`${s} is not a child of ${i.cid}`)}let a=await S(r.get(s,o)),c=Be({cid:s,bytes:a,codec:await n(s.code)});i=c,yield c}}};var vp=new TextDecoder;function zi(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 Yn(t,e){let r;[r,e]=zi(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 Lu(t,e){let r;return[r,e]=zi(t,e),[r&7,r>>3,e]}function kp(t){let e={},r=t.length,n=0;for(;n<r;){let o,i;if([o,i,n]=Lu(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]=Yn(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]=Yn(t,n),e.Name=vp.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]=zi(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 Ru(t){let e=t.length,r=0,n,o=!1,i;for(;r<e;){let a,c;if([a,c,r]=Lu(t,r),a!==2)throw new Error(`protobuf: (PBNode) invalid wireType, expected 2, got ${a}`);if(c===1){if(i)throw new Error("protobuf: (PBNode) duplicate Data section");[i,r]=Yn(t,r),n&&(o=!0)}else if(c===2){if(o)throw new Error("protobuf: (PBNode) duplicate Links section");n||(n=[]);let u;[u,r]=Yn(t,r),n.push(kp(u))}else throw new Error(`protobuf: (PBNode) invalid fieldNumber, expected 1 or 2, got ${c}`)}if(r>e)throw new Error("protobuf: (PBNode) unexpected end of data");let s={};return i&&(s.Data=i),s.Links=n||[],s}var Pu=new TextEncoder,$u=2**32,_p=2**31;function Ap(t,e){let r=e.length;if(typeof t.Tsize=="number"){if(t.Tsize<0)throw new Error("Tsize cannot be negative");if(!Number.isSafeInteger(t.Tsize))throw new Error("Tsize too large for encoding");r=$r(e,r,t.Tsize)-1,e[r]=24}if(typeof t.Name=="string"){let n=Pu.encode(t.Name);r-=n.length,e.set(n,r),r=$r(e,r,n.length)-1,e[r]=18}return t.Hash&&(r-=t.Hash.length,e.set(t.Hash,r),r=$r(e,r,t.Hash.length)-1,e[r]=10),e.length-r}function Mu(t,e,r){return t-=e.Data.length,r.set(e.Data,t),t=$r(r,t,e.Data.length)-1,r[t]=10,t}function Fu(t,e){let r=Tp(t),n=new Uint8Array(r),o=r,i=e?.fieldOrder==="data-first"?e.fieldOrder:"links-first";if(t.Data&&i==="links-first"&&(o=Mu(o,t,n)),t.Links)for(let s=t.Links.length-1;s>=0;s--){let a=Ap(t.Links[s],n.subarray(0,o));o-=a,o=$r(n,o,a)-1,n[o]=18}return t.Data&&i==="data-first"&&(o=Mu(o,t,n)),n}function Ip(t){let e=0;if(t.Hash){let r=t.Hash.length;e+=1+r+Yt(r)}if(typeof t.Name=="string"){let r=Pu.encode(t.Name).length;e+=1+r+Yt(r)}return typeof t.Tsize=="number"&&(e+=1+Yt(t.Tsize)),e}function Tp(t){let e=0;if(t.Data){let r=t.Data.length;e+=1+r+Yt(r)}if(t.Links)for(let r of t.Links){let n=Ip(r);e+=1+n+Yt(n)}return e}function $r(t,e,r){e-=Yt(r);let n=e;for(;r>=_p;)t[e++]=r&127|128,r/=128;for(;r>=128;)t[e++]=r&127|128,r>>>=7;return t[e]=r,n}function Yt(t){return t%2===0&&t++,Math.floor((Bp(t)+6)/7)}function Bp(t){let e=0;return t>=$u&&(t=Math.floor(t/$u),e=32),t>=65536&&(t>>>=16,e+=16),t>=256&&(t>>>=8,e+=8),e+Sp[t]}var Sp=[0,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8];var Cp=["Data","Links"],Np=["Hash","Name","Tsize"],Ou=new TextEncoder;function Dp(t,e){if(t===e)return 0;let r=t.Name?Ou.encode(t.Name):[],n=e.Name?Ou.encode(e.Name):[],o=r.length,i=n.length;for(let s=0,a=Math.min(o,i);s<a;++s)if(r[s]!==n[s]){o=r[s],i=n[s];break}return o<i?-1:i<o?1:0}function zu(t,e){return!Object.keys(t).some(r=>!e.includes(r))}function Hu(t){if(!t||typeof t!="object"||Array.isArray(t)||t instanceof Uint8Array||t["/"]&&t["/"]===t.bytes)throw new TypeError("Invalid DAG-PB form");if(!zu(t,Cp))throw new TypeError("Invalid DAG-PB form (extraneous properties)");if(t.Data!==void 0&&!(t.Data instanceof Uint8Array))throw new TypeError("Invalid DAG-PB form (Data must be bytes)");if(!Array.isArray(t.Links))throw new TypeError("Invalid DAG-PB form (Links must be a list)");for(let e=0;e<t.Links.length;e++){let r=t.Links[e];if(!r||typeof r!="object"||Array.isArray(r)||r instanceof Uint8Array||r["/"]&&r["/"]===r.bytes)throw new TypeError("Invalid DAG-PB form (bad link)");if(!zu(r,Np))throw new TypeError("Invalid DAG-PB form (extraneous properties on link)");if(r.Hash===void 0)throw new TypeError("Invalid DAG-PB form (link must have a Hash)");if(r.Hash==null||!r.Hash["/"]||r.Hash["/"]!==r.Hash.bytes)throw new TypeError("Invalid DAG-PB form (link Hash must be a CID)");if(r.Name!==void 0&&typeof r.Name!="string")throw new TypeError("Invalid DAG-PB form (link Name must be a string)");if(r.Tsize!==void 0){if(typeof r.Tsize!="number"||r.Tsize%1!==0)throw new TypeError("Invalid DAG-PB form (link Tsize must be an integer)");if(r.Tsize<0)throw new TypeError("Invalid DAG-PB form (link Tsize cannot be negative)")}if(e>0&&Dp(r,t.Links[e-1])===-1)throw new TypeError("Invalid DAG-PB form (links must be sorted by Name bytes)")}}function Vu(t){return t instanceof ArrayBuffer?new Uint8Array(t,0,t.byteLength):t}var Jt=112;function ju(t,e){Hu(t);let r={};return t.Links&&(r.Links=t.Links.map(n=>{let o={};return n.Hash&&(o.Hash=n.Hash.bytes),n.Name!==void 0&&(o.Name=n.Name),n.Tsize!==void 0&&(o.Tsize=n.Tsize),o})),t.Data&&(r.Data=t.Data),Fu(r,e)}function Jn(t){let e=Vu(t),r=Ru(e),n={};return r.Data&&(n.Data=r.Data),r.Links&&(n.Links=r.Links.map(o=>{let i={};try{i.Hash=A.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 Kt=class t extends Error{static name="BadPathError";static code="ERR_BAD_PATH";name=t.name;code=t.code;constructor(e="Bad path"){super(e)}},Q=class t extends Error{static name="NotFoundError";static code="ERR_NOT_FOUND";name=t.name;code=t.code;constructor(e="Not found"){super(e)}},Xt=class t extends Error{static name="NoResolverError";static code="ERR_NO_RESOLVER";name=t.name;code=t.code;constructor(e="No resolver"){super(e)}},L=class t extends Error{static name="NotUnixFSError";static code="ERR_NOT_UNIXFS";name=t.name;code=t.code;constructor(e="Not UnixFS"){super(e)}},Xn=class t extends Error{static name="OverReadError";static code="ERR_OVER_READ";name=t.name;code=t.code;constructor(e="Over read"){super(e)}},Qn=class t extends Error{static name="UnderReadError";static code="ERR_UNDER_READ";name=t.name;code=t.code;constructor(e="Under read"){super(e)}},Re=class t extends Error{static name="InvalidParametersError";static code="ERR_INVALID_PARAMS";name=t.name;code=t.code;constructor(e="Invalid parameters"){super(e)}};var qu=class extends Array{constructor(){super(),this.inRecursive=[]}prefix(e){let r=this.inRecursive[this.inRecursive.length-1];r&&(f.equals(r.type,f.array)&&(r.elements++,r.elements!==1&&e.push([44])),f.equals(r.type,f.map)&&(r.elements++,r.elements!==1&&(r.elements%2===1?e.push([44]):e.push([58]))))}[f.uint.major](e,r){this.prefix(e);let n=String(r.value),o=[];for(let i=0;i<n.length;i++)o[i]=n.charCodeAt(i);e.push(o)}[f.negint.major](e,r){this[f.uint.major](e,r)}[f.bytes.major](e,r){throw new Error(`${Me} unsupported type: Uint8Array`)}[f.string.major](e,r){this.prefix(e);let n=bt(JSON.stringify(r.value));e.push(n.length>32?ot(n):n)}[f.array.major](e,r){this.prefix(e),this.inRecursive.push({type:f.array,elements:0}),e.push([91])}[f.map.major](e,r){this.prefix(e),this.inRecursive.push({type:f.map,elements:0}),e.push([123])}[f.tag.major](e,r){}[f.float.major](e,r){if(r.type.name==="break"){let s=this.inRecursive.pop();if(s){if(f.equals(s.type,f.array))e.push([93]);else if(f.equals(s.type,f.map))e.push([125]);else throw new Error("Unexpected recursive type; this should not happen!");return}throw new Error("Unexpected break; this should not happen!")}if(r.value===void 0)throw new Error(`${Me} unsupported type: undefined`);if(this.prefix(e),r.type.name==="true"){e.push([116,114,117,101]);return}else if(r.type.name==="false"){e.push([102,97,108,115,101]);return}else if(r.type.name==="null"){e.push([110,117,108,108]);return}if(typeof r.value=="number"&&!Number.isFinite(r.value))throw new Error(`${Me} unsupported type: ${r.value}`);let n=String(r.value),o=[],i=!1;for(let s=0;s<n.length;s++)o[s]=n.charCodeAt(s),!i&&(o[s]===46||o[s]===101||o[s]===69)&&(i=!0);i||(o.push(46),o.push(48)),e.push(o)}};var Gu=1e3,Qt=class{constructor(e,r={}){this._pos=0,this.data=e,this.options=r,this.modeStack=["value"],this.lastToken=""}pos(){return this._pos}done(){return this._pos>=this.data.length}ch(){return this.data[this._pos]}currentMode(){return this.modeStack[this.modeStack.length-1]}skipWhitespace(){let e=this.ch();for(;e===32||e===9||e===13||e===10;)e=this.data[++this._pos]}expect(e){if(this.data.length-this._pos<e.length)throw new Error(`${y} unexpected end of input at position ${this._pos}`);for(let r=0;r<e.length;r++)if(this.data[this._pos++]!==e[r])throw new Error(`${y} unexpected token at position ${this._pos}, expected to find '${String.fromCharCode(...e)}'`)}parseNumber(){let e=this._pos,r=!1,n=!1,o=a=>{for(;!this.done();){let c=this.ch();if(a.includes(c))this._pos++;else break}};if(this.ch()===45&&(r=!0,this._pos++),this.ch()===48)if(this._pos++,this.ch()===46)this._pos++,n=!0;else return new p(f.uint,0,this._pos-e);if(o([48,49,50,51,52,53,54,55,56,57]),r&&this._pos===e+1)throw new Error(`${y} unexpected token at position ${this._pos}`);if(!this.done()&&this.ch()===46){if(n)throw new Error(`${y} unexpected token at position ${this._pos}`);n=!0,this._pos++,o([48,49,50,51,52,53,54,55,56,57])}if(!this.done()&&(this.ch()===101||this.ch()===69)&&(n=!0,this._pos++,!this.done()&&(this.ch()===43||this.ch()===45)&&this._pos++,o([48,49,50,51,52,53,54,55,56,57])),this._pos-e>Gu)throw new Error(`${y} number at position ${e} exceeds ${Gu} characters`);let i=String.fromCharCode.apply(null,this.data.subarray(e,this._pos)),s=parseFloat(i);if(n){if(this.options.allowInfinity===!1&&!Number.isFinite(s))throw new Error(`${y} Infinity values are not supported`);return new p(f.float,s,this._pos-e)}if(this.options.allowBigInt!==!0||Number.isSafeInteger(s)){if(!Number.isFinite(s))throw new Error(`${y} integer at position ${e} is too large for a Number, use allowBigInt`);return new p(s>=0?f.uint:f.negint,s,this._pos-e)}return new p(s>=0?f.uint:f.negint,BigInt(i),this._pos-e)}parseString(){if(this.ch()!==34)throw new Error(`${y} unexpected character at position ${this._pos}; this shouldn't happen`);this._pos++;for(let i=this._pos,s=0;i<this.data.length&&s<65536;i++,s++){let a=this.data[i];if(a===92||a<32||a>=128)break;if(a===34){let c=String.fromCharCode.apply(null,this.data.subarray(this._pos,i));return this._pos=i+1,new p(f.string,c,s)}}let e=this._pos,r=[],n=()=>{if(this._pos+4>=this.data.length)throw new Error(`${y} unexpected end of unicode escape sequence at position ${this._pos}`);let i=0;for(let s=0;s<4;s++){let a=this.ch();if(a>=48&&a<=57)a-=48;else if(a>=97&&a<=102)a=a-97+10;else if(a>=65&&a<=70)a=a-65+10;else throw new Error(`${y} unexpected unicode escape character at position ${this._pos}`);i=i*16+a,this._pos++}return i},o=()=>{let i=this.ch(),s=null,a=i>239?4:i>223?3:i>191?2:1;if(this._pos+a>this.data.length)throw new Error(`${y} unexpected unicode sequence at position ${this._pos}`);let c,u,l,h;switch(a){case 1:i<128&&(s=i);break;case 2:c=this.data[this._pos+1],(c&192)===128&&(h=(i&31)<<6|c&63,h>127&&(s=h));break;case 3:c=this.data[this._pos+1],u=this.data[this._pos+2],(c&192)===128&&(u&192)===128&&(h=(i&15)<<12|(c&63)<<6|u&63,h>2047&&(h<55296||h>57343)&&(s=h));break;case 4:c=this.data[this._pos+1],u=this.data[this._pos+2],l=this.data[this._pos+3],(c&192)===128&&(u&192)===128&&(l&192)===128&&(h=(i&15)<<18|(c&63)<<12|(u&63)<<6|l&63,h>65535&&h<1114112&&(s=h))}if(s===null){if(this.options.strictUtf8===!0)throw new Error(`${y} invalid UTF-8 in text string at position ${this._pos}`);s=65533,a=1}else s>65535&&(s-=65536,r.push(s>>>10&1023|55296),s=56320|s&1023);r.push(s),this._pos+=a};for(;!this.done();){let i=this.ch(),s;switch(i){case 92:if(this._pos++,this.done())throw new Error(`${y} unexpected string termination at position ${this._pos}`);switch(s=this.ch(),this._pos++,s){case 34:case 39:case 92:case 47:r.push(s);break;case 98:r.push(8);break;case 116:r.push(9);break;case 110:r.push(10);break;case 102:r.push(12);break;case 114:r.push(13);break;case 117:r.push(n());break;default:throw new Error(`${y} unexpected string escape character at position ${this._pos}`)}break;case 34:return this._pos++,new p(f.string,ls(r),this._pos-e);default:if(i<32)throw new Error(`${y} invalid control character at position ${this._pos}`);i<128?(r.push(i),this._pos++):o()}}throw new Error(`${y} unexpected end of string at position ${this._pos}`)}parseValue(){switch(this.ch()){case 123:return this.modeStack.push("obj-start"),this._pos++,new p(f.map,1/0,1);case 91:return this.modeStack.push("array-start"),this._pos++,new p(f.array,1/0,1);case 34:return this.parseString();case 110:return this.expect([110,117,108,108]),new p(f.null,null,4);case 102:return this.expect([102,97,108,115,101]),new p(f.false,!1,5);case 116:return this.expect([116,114,117,101]),new p(f.true,!0,4);case 45:case 48:case 49:case 50:case 51:case 52:case 53:case 54:case 55:case 56:case 57:return this.parseNumber();default:throw new Error(`${y} unexpected character at position ${this._pos}`)}}next(){switch(this.skipWhitespace(),this.currentMode()){case"value":return this.modeStack.pop(),this.parseValue();case"array-value":{if(this.modeStack.pop(),this.ch()===93)return this._pos++,this.skipWhitespace(),new p(f.break,void 0,1);if(this.ch()!==44)throw new Error(`${y} unexpected character at position ${this._pos}, was expecting array delimiter but found '${String.fromCharCode(this.ch())}'`);return this._pos++,this.modeStack.push("array-value"),this.skipWhitespace(),this.parseValue()}case"array-start":return this.modeStack.pop(),this.ch()===93?(this._pos++,this.skipWhitespace(),new p(f.break,void 0,1)):(this.modeStack.push("array-value"),this.skipWhitespace(),this.parseValue());case"obj-key":if(this.ch()===125)return this.modeStack.pop(),this._pos++,this.skipWhitespace(),new p(f.break,void 0,1);if(this.ch()!==44)throw new Error(`${y} unexpected character at position ${this._pos}, was expecting object delimiter but found '${String.fromCharCode(this.ch())}'`);this._pos++,this.skipWhitespace();case"obj-start":{if(this.modeStack.pop(),this.ch()===125)return this._pos++,this.skipWhitespace(),new p(f.break,void 0,1);let e=this.parseString();if(this.skipWhitespace(),this.ch()!==58)throw new Error(`${y} unexpected character at position ${this._pos}, was expecting key/value delimiter ':' but found '${String.fromCharCode(this.ch())}'`);return this._pos++,this.modeStack.push("obj-value"),e}case"obj-value":return this.modeStack.pop(),this.modeStack.push("obj-key"),this.skipWhitespace(),this.parseValue();default:throw new Error(`${y} unexpected parse state at position ${this._pos}; this shouldn't happen`)}}};function Hi(t,e){return e=Object.assign({tokenizer:new Qt(t,e)},e),fr(t,e)}function Rp(t){return t instanceof ArrayBuffer?new Uint8Array(t,0,t.byteLength):t}var Vi=class extends Qt{constructor(e,r){super(e,r),this.tokenBuffer=[]}done(){return this.tokenBuffer.length===0&&super.done()}_next(){return this.tokenBuffer.length>0?this.tokenBuffer.pop():super.next()}next(){let e=this._next();if(f.equals(e.type,f.map)){let r=this._next();if(f.equals(r.type,f.string)&&r.value==="/"){let n=this._next();if(f.equals(n.type,f.string)){let o=this._next();if(!f.equals(o.type,f.break))throw new Error("Invalid encoded CID form");return this.tokenBuffer.push(n),new p(f.tag,42,0)}if(f.equals(n.type,f.map)){let o=this._next();if(f.equals(o.type,f.string)&&o.value==="bytes"){let i=this._next();if(f.equals(i.type,f.string)){for(let a=0;a<2;a++){let c=this._next();if(!f.equals(c.type,f.break))throw new Error("Invalid encoded Bytes form")}let s=ri.decode(`m${i.value}`);return new p(f.bytes,s,i.value.length)}this.tokenBuffer.push(i)}this.tokenBuffer.push(o)}this.tokenBuffer.push(n)}this.tokenBuffer.push(r)}return e}},Wu={allowIndefinite:!1,allowUndefined:!1,allowNaN:!1,allowInfinity:!1,allowBigInt:!0,strict:!0,useMaps:!1,rejectDuplicateMapKeys:!0,tags:{42:t=>A.parse(t())}};var Zn=297;var eo=t=>{let e=Rp(t),r=Object.assign(Wu,{tokenizer:new Vi(e,Wu)});return Hi(e,r)};var L1=new TextDecoder;var R1=new TextEncoder;function Zt(t){return t==null?!1:A.asCID(t)===t}function er(t,e){let r,n=0,o="";for(;n<e.length;){let i=e[n];if(n++,!Object.hasOwnProperty.call(t,i))throw new Kt(`Object did not have key "${i}"`);if(o+=`/${i}`,r=t[i],t=r,Zt(r))break}return{value:r,rest:e.slice(n),path:o.substring(1)}}async function*ji(t,e,r,n){let o=await S(r.get(t,n)),i=ft(o),s=er(i,e);yield{cid:Zt(s.value)?s.value:t,name:s.path,rest:s.rest}}async function*Yu(t,e,r,n){let o=await S(r.get(t,n)),i=eo(o),s=er(i,e);yield{cid:Zt(s.value)?s.value:t,name:s.path,rest:s.rest}}function tt(t,e){let r=t.lo+e.lo>>>0,n=t.hi+e.hi+(r<t.lo?1:0)>>>0;return{lo:r,hi:n}}function $p(t,e){return t+e>>>0}function pe(t,e){let r=t.lo&65535,n=t.lo>>>16,o=e.lo&65535,i=e.lo>>>16,s=r*o,a=r*i,c=n*o,u=n*i,l=(s>>>16)+(a&65535)+(c&65535)>>>0,h=(l<<16|s&65535)>>>0,m=u+(a>>>16)+(c>>>16)+(l>>>16),E=Math.imul(t.lo,e.hi),_=Math.imul(t.hi,e.lo),k=m+E+_>>>0;return{lo:h,hi:k}}function gt(t,e){return Math.imul(t,e)>>>0}function tr(t,e){if(e===0)return t;if(e===32)return{lo:t.hi,hi:t.lo};if(e<32){let o=(t.lo<<e|t.hi>>>32-e)>>>0,i=(t.hi<<e|t.lo>>>32-e)>>>0;return{lo:o,hi:i}}e-=32;let r=(t.hi<<e|t.lo>>>32-e)>>>0,n=(t.lo<<e|t.hi>>>32-e)>>>0;return{lo:r,hi:n}}function U(t,e){return{lo:(t.lo^e.lo)>>>0,hi:(t.hi^e.hi)>>>0}}function qi(t,e){if(e===0)return t;if(e<32){let r=(t.lo>>>e|t.hi<<32-e)>>>0,n=t.hi>>>e;return{lo:r,hi:n}}return{lo:t.hi>>>e-32,hi:0}}function C(t,e){return{lo:t>>>0,hi:e>>>0}}function Gi(t,e){return(t<<e|t>>>32-e)>>>0}function Ju(t,e){let r=e*8,n=t[r]|t[r+1]<<8|t[r+2]<<16|t[r+3]<<24,o=t[r+4]|t[r+5]<<8|t[r+6]<<16|t[r+7]<<24;return{lo:n>>>0,hi:o>>>0}}function Mp(t,e){let r=e*4;return(t[r]|t[r+1]<<8|t[r+2]<<16|t[r+3]<<24)>>>0}function Ku(t){return t=U(t,qi(t,33)),t=pe(t,C(3981806797,4283543511)),t=U(t,qi(t,33)),t=pe(t,C(444984403,3301882366)),t=U(t,qi(t,33)),t}function Pp(t){return t^=t>>>16,t=gt(t,2246822507),t^=t>>>13,t=gt(t,3266489909),t^=t>>>16,t}function Wi(t,e=0){let r=C(e,0),n=C(e,0),o=t.length,i=Math.floor(o/16),s=C(289559509,2277735313),a=C(658871167,1291169091);for(let m=0;m<i;m++){let E=Ju(t,m*2),_=Ju(t,m*2+1);E=pe(E,s),E=tr(E,31),E=pe(E,a),r=U(r,E),r=tr(r,27),r=tt(r,n),r=tt(pe(r,C(5,0)),C(1390208809,0)),_=pe(_,a),_=tr(_,33),_=pe(_,s),n=U(n,_),n=tr(n,31),n=tt(n,r),n=tt(pe(n,C(5,0)),C(944331445,0))}let c=C(0,0),u=C(0,0),l=t.slice(i*16);switch(l.length){case 15:u=U(u,C(0,l[14]<<16));case 14:u=U(u,C(0,l[13]<<8));case 13:u=U(u,C(0,l[12]));case 12:u=U(u,C(l[11]<<24,0));case 11:u=U(u,C(l[10]<<16,0));case 10:u=U(u,C(l[9]<<8,0));case 9:u=U(u,C(l[8],0)),u=pe(u,a),u=tr(u,33),u=pe(u,s),n=U(n,u);case 8:c=U(c,C(0,l[7]<<24));case 7:c=U(c,C(0,l[6]<<16));case 6:c=U(c,C(0,l[5]<<8));case 5:c=U(c,C(0,l[4]));case 4:c=U(c,C(l[3]<<24,0));case 3:c=U(c,C(l[2]<<16,0));case 2:c=U(c,C(l[1]<<8,0));case 1:c=U(c,C(l[0],0)),c=pe(c,s),c=tr(c,31),c=pe(c,a),r=U(r,c)}let h=C(o,0);return r=U(r,h),n=U(n,h),r=tt(r,n),n=tt(n,r),r=Ku(r),n=Ku(n),r=tt(r,n),n=tt(n,r),new Uint8Array([r.hi>>>24&255,r.hi>>>16&255,r.hi>>>8&255,r.hi&255,r.lo>>>24&255,r.lo>>>16&255,r.lo>>>8&255,r.lo&255,n.hi>>>24&255,n.hi>>>16&255,n.hi>>>8&255,n.hi&255,n.lo>>>24&255,n.lo>>>16&255,n.lo>>>8&255,n.lo&255])}function Xu(t,e=0){let r=e>>>0,n=t.length,o=Math.floor(n/4),i=3432918353,s=461845907;for(let u=0;u<o;u++){let l=Mp(t,u);l=gt(l,i),l=Gi(l,15),l=gt(l,s),r^=l,r=Gi(r,13),r=$p(gt(r,5),3864292196)}let a=t.slice(o*4),c=0;switch(a.length){case 3:c^=a[2]<<16;case 2:c^=a[1]<<8;case 1:c^=a[0],c=gt(c,i),c=Gi(c,15),c=gt(c,s),r^=c}return r^=n,r=Pp(r),r}function Op(t){let e=new Array(4);for(let r=0;r<4;r++)e[r]=t&255,t=t>>8;return new Uint8Array(e)}var eE=ht({name:"murmur3-32",code:35,encode:t=>Op(Xu(t))}),Qu=ht({name:"murmur3-128",code:34,encode:t=>Wi(t)}),tE=ht({name:"murmur3-x64-64",code:34,encode:t=>Wi(t).subarray(0,8)});var rf=or(tf(),1);var wt=class t{_options;_popCount;_parent;_posAtParent;_children;key;constructor(e,r,n=0){this._options=e,this._popCount=0,this._parent=r,this._posAtParent=n,this._children=new rf.default,this.key=null}async put(e,r){let n=await this._findNewBucketAndPos(e);n.bucket._putAt(n,e,r)}async get(e){let r=await this._findChild(e);if(r!=null)return r.value}async del(e){let r=await this._findPlace(e),n=r.bucket._at(r.pos);n!=null&&n.key===e&&r.bucket._delAt(r.pos)}leafCount(){return this._children.compactArray().reduce((r,n)=>n instanceof t?r+n.leafCount():r+1,0)}childrenCount(){return this._children.length}onlyChild(){return this._children.get(0)}*eachLeafSeries(){let e=this._children.compactArray();for(let r of e)r instanceof t?yield*r.eachLeafSeries():yield r}serialize(e,r){let n=[];return r(this._children.reduce((o,i,s)=>(i!=null&&(i instanceof t?o.push(i.serialize(e,r)):o.push(e(i,s))),o),n))}async asyncTransform(e,r){return nf(this,e,r)}toJSON(){return this.serialize(qp,Gp)}prettyPrint(){return JSON.stringify(this.toJSON(),null," ")}tableSize(){return Math.pow(2,this._options.bits)}async _findChild(e){let r=await this._findPlace(e),n=r.bucket._at(r.pos);if(!(n instanceof t)&&n!=null&&n.key===e)return n}async _findPlace(e){let r=this._options.hash(typeof e=="string"?Ln(e):e),n=await r.take(this._options.bits),o=this._children.get(n);return o instanceof t?o._findPlace(r):{bucket:this,pos:n,hash:r,existingChild:o}}async _findNewBucketAndPos(e){let r=await this._findPlace(e);if(r.existingChild!=null&&r.existingChild.key!==e){let n=new t(this._options,r.bucket,r.pos);r.bucket._putObjectAt(r.pos,n);let o=await n._findPlace(r.existingChild.hash);return o.bucket._putAt(o,r.existingChild.key,r.existingChild.value),n._findNewBucketAndPos(r.hash)}return r}_putAt(e,r,n){this._putObjectAt(e.pos,{key:r,value:n,hash:e.hash})}_putObjectAt(e,r){this._children.get(e)==null&&this._popCount++,this._children.set(e,r)}_delAt(e){if(e===-1)throw new Error("Invalid position");this._children.get(e)!=null&&this._popCount--,this._children.unset(e),this._level()}_level(){if(this._parent!=null&&this._popCount<=1)if(this._popCount===1){let e=this._children.find(jp);if(e!=null&&!(e instanceof t)){let r=e.hash;r.untake(this._options.bits);let n={pos:this._posAtParent,hash:r,bucket:this._parent};this._parent._putAt(n,e.key,e.value)}}else this._parent._delAt(this._posAtParent)}_at(e){return this._children.get(e)}};function jp(t){return!!t}function qp(t,e){return t.key}function Gp(t){return t}async function nf(t,e,r){let n=[];for(let o of t._children.compactArray())if(o instanceof wt)await nf(o,e,r);else{let i=await e(o);n.push({bitField:t._children.bitField(),children:i})}return r(n)}var Wp=[255,254,252,248,240,224,192,128],Yp=[1,3,7,15,31,63,127,255],ro=class{_value;_currentBytePos;_currentBitPos;constructor(e){this._value=e,this._currentBytePos=e.length-1,this._currentBitPos=7}availableBits(){return this._currentBitPos+1+this._currentBytePos*8}totalBits(){return this._value.length*8}take(e){let r=e,n=0;for(;r>0&&this._haveBits();){let o=this._value[this._currentBytePos],i=this._currentBitPos+1,s=Math.min(i,r),a=Jp(o,i-s,s);n=(n<<s)+a,r-=s,this._currentBitPos-=s,this._currentBitPos<0&&(this._currentBitPos=7,this._currentBytePos--)}return n}untake(e){for(this._currentBitPos+=e;this._currentBitPos>7;)this._currentBitPos-=8,this._currentBytePos+=1}_haveBits(){return this._currentBytePos>=0}};function Jp(t,e,r){let n=Kp(e,r);return(t&n)>>>e}function Kp(t,e){return Wp[t]&Yp[Math.min(e+t-1,7)]}function of(t){function e(r){return r instanceof no?r:new no(r,t)}return e}var no=class{_value;_hashFn;_depth;_availableBits;_currentBufferIndex;_buffers;constructor(e,r){if(!(e instanceof Uint8Array))throw new Error("can only hash Uint8Arrays");this._value=e,this._hashFn=r,this._depth=-1,this._availableBits=0,this._currentBufferIndex=0,this._buffers=[]}async take(e){let r=e;for(;this._availableBits<r;)await this._produceMoreBits();let n=0;for(;r>0;){let o=this._buffers[this._currentBufferIndex],i=Math.min(o.availableBits(),r),s=o.take(i);n=(n<<i)+s,r-=i,this._availableBits-=i,o.availableBits()===0&&this._currentBufferIndex++}return n}untake(e){let r=e;for(;r>0;){let n=this._buffers[this._currentBufferIndex],o=Math.min(n.totalBits()-n.availableBits(),r);n.untake(o),r-=o,this._availableBits+=o,this._currentBufferIndex>0&&n.totalBits()===n.availableBits()&&(this._depth--,this._currentBufferIndex--)}}async _produceMoreBits(){this._depth++;let e=this._depth>0?_r([this._value,Uint8Array.from([this._depth])]):this._value,r=await this._hashFn(e),n=new ro(r);this._buffers.push(n),this._availableBits+=n.availableBits()}};function sf(t){if(t==null||t.hashFn==null)throw new Error("please define an options.hashFn");let e={bits:t.bits??8,hash:of(t.hashFn)};return new wt(e)}function oo(t){return t.type==="DIRECTORY"}function Yi(t){return t.type==="FILE"}function Ji(t){return t.type==="RAW"}function Ki(t){return t.type==="SYMLINK"}function rt(t){return t.type==="HAMT_SHARD"&&t.data instanceof Uint8Array&&typeof t.fanOut=="bigint"&&typeof t.hashType=="bigint"}function $e(t){return typeof t.name=="string"&&A.asCID(t.hash)===t.hash}function*io(t){let e={},r={};for(let n of Gt.stream(t))switch(n.field){case".data":{if(n.type==="start"&&(r={}),n.type==="end"){if(oo(r)||rt(r)||Yi(r)||Ji(r)||Ki(r)){yield r;return}throw new L("PBNode Data was not a valid UnixFS type")}break}case".data.type":{r.type=n.value;break}case".data.data":{r.data=n.value;break}case".data.fanOut":{r.fanOut=n.value;break}case".data.hashType":{r.hashType=n.value;break}case".links[]":{n.type==="start"&&(e={type:"LINK"}),n.type==="end"&&$e(e)&&(yield e);break}case".links[].name":{e.name=n.value;break}case".links[].hash":{e.hash=A.decode(n.value);break}default:}}var af=(t,e)=>t.toString(16).toUpperCase().padStart(e,"0").substring(0,e),Xp=t=>{let e=t.bucket,r=[];for(;e._parent!=null;)r.push(e),e=e._parent;return r.push(e),r.reverse()};async function*so(t,e,r,n,o,i,s){let a=(i.lastBucket.tableSize()-1).toString(16).length,c=[];for(let b of e){if(!$e(b))throw new L("Invalid link");if(c.push(b),b.name.length===a){let v=parseInt(b.name,16);i.lastBucket._putObjectAt(v,new wt({hash:i.lastBucket._options.hash,bits:i.lastBucket._options.bits},i.lastBucket,v))}if(b.name.substring(a)===r){yield{cid:b.hash,name:r,rest:n};return}await i.rootBucket.put(b.name.substring(a),!0)}let u=await i.rootBucket._findNewBucketAndPos(r),l=af(u.pos,a),h=Xp(u);h.length>i.hamtDepth&&(i.lastBucket=h[i.hamtDepth],l=af(i.lastBucket._posAtParent,a));let m=c.find(b=>b.name==null?!1:b.name===l);if(m==null)return;i.hamtDepth++;let E=await S(o.get(m.hash,s));s?.yieldSubShards===!0&&(yield{cid:m.hash,name:m.name,rest:[r,...n]});let _=io(E),{value:k}=_.next();if(c=[],k!=null){if(rt(k)){yield*so(k,_,r,n,o,i,s);return}if(!$e(k))throw new L("Did not read Link or Data from dag-pb block");c.push(k);for(let b of _){if(rt(b)){yield*so(b,c,r,n,o,i,s);return}if(!$e(b))throw new L("Did not read Link or Data from dag-pb block");c.push(b)}}}function*cf(t,e,r){for(let n of t){if(!$e(n))throw new L("Invalid link");if(n.name===e[0]){yield{cid:n.hash,name:e[0],rest:e.slice(1)};return}}throw new Q(`No link "${e[0]}" found under ${r}`)}var Qp=async function(t){return(await Qu.encode(t)).slice(0,8).reverse()};async function*uf(t,e,r,n,o,i){let s=sf({hashFn:Qp,bits:Math.log2(Number(t.fanOut))}),a={rootBucket:s,hamtDepth:1,lastBucket:s};for await(let c of so(t,e,r[0],r.slice(1),o,a,i))if(yield c,c.name===r[0])return;throw new Q(`No link "${r[0]}" found under ${n}`)}async function*ff(t,e,r,n){let o=await S(r.get(t,n)),i=[],s=io(o),{value:a}=s.next(),c=!1,u=!1;if(a!=null){if(u=oo(a),c=rt(a),Yi(a)||Ji(a)||Ki(a)){yield{cid:t,name:e[0],rest:e.slice(1)};return}if(u||c&&n?.translateHAMTPath===!1){yield*cf(s,e,t);return}if(c){yield*uf(a,s,e,t,r,n);return}if(!$e(a))throw new L("Did not read Link or Data from dag-pb block");i.push(a);for(let l of s){if(u=oo(l),c=rt(l),u||c&&n?.translateHAMTPath===!1){yield*cf(i,e,t);return}if(rt(l)){yield*uf(l,i,e,t,r,n);return}if(!$e(l))throw new L("Did not read Link or Data from dag-pb block");i.push(l)}}throw new Q(`No link "${e[0]}" found under ${t}`)}async function*lf(t,e,r,n){if(e.length!==0)throw new Kt(`Cannot load path /${e.join("/")} from identity block`)}async function*df(t,e,r,n){let o=await S(r.get(t,n)),i=Dn(o),s=er(i,e);yield{cid:t,name:s.path,rest:s.rest}}async function*hf(t,e,r,n){if(e.length!==0)throw new Q(`Cannot load path /${e.join("/")} from raw block`)}var em={[Jt]:ff,[Ot]:hf,[cn]:ji,81:ji,[Zn]:Yu,[kr.code]:lf,[Nn]:df};async function*ao(t,e,r={}){for(t=t.toString(),t.startsWith("/ipfs/")&&(t=t.substring(6));t.endsWith("/");)t=t.substring(0,t.length-1);let[n,...o]=t.split(/(?<!\\)\//g).filter(Boolean),i=A.parse(n),s=[i],a=`${i}`;for(yield{cid:i,name:a,path:a,roots:s,remainder:o};o.length>0;){let c=em[i.code];if(c==null)throw new Xt(`No resolver for code ${i.code}`);let u=!1;for await(let l of c(i,o,e,r)){if(i=l.cid,u=!s[s.length-1].equals(i),o=l.rest,!u)break;s=[...s,l.cid],a=`${a}/${l.name}`,yield{cid:l.cid,name:l.name,path:a,roots:s,remainder:l.rest}}if(!u)break}if(r?.signal?.throwIfAborted(),o.length!==0)throw new Q(`Could not resolve path /${o.join("/")} under ${t}`)}function tm(t){return t[Symbol.asyncIterator]!=null}function rm(t){if(tm(t))return(async()=>{let r;for await(let n of t)r=n;return r})();let e;for(let r of t)e=r;return e}var pf=rm;async function Xi(t,e,r,n,o){let i=await S(n.get(t,o)),s=ft(i);return{type:"object",cid:t,name:e,path:r,object:s,node:i,size:BigInt(i.byteLength)}}async function mf(t,e,r,n,o){let i=await S(n.get(t,o)),s=eo(i);return{type:"object",cid:t,name:e,path:r,object:s,node:i,size:BigInt(i.byteLength)}}var me=class extends Event{type;detail;constructor(e,r){super(e),this.type=e,this.detail=r}};function Mr(t,e,r,n){let o=BigInt(t.length),i=BigInt(e+o);return r>=i||n<e?new Uint8Array(0):(n>=e&&n<i&&(t=t.subarray(0,Number(n-e))),r>=e&&r<i&&(t=t.subarray(Number(r-e))),t)}var co=(t,e=0,r=t)=>{let n=BigInt(t),o=BigInt(e??0),i=BigInt(r);if(i!==n&&(i=o+i),i>n&&(i=n),o<0n)throw new Re("Offset must be greater than or equal to 0");if(o>n)throw new Re("Offset must be less than the file size");if(i<0n)throw new Re("Length must be greater than or equal to 0");if(i>n)throw new Re("Length must be less than the file size");return{start:o,end:i}};function uo(t,e){async function*r(n={}){let{start:o,end:i}=co(t.length,n.offset,n.length),s=Mr(t,0n,o,i);n.onProgress?.(new me(e,{bytesRead:BigInt(s.byteLength),totalBytes:i-o,fileSize:BigInt(t.byteLength)})),yield s}return r}async function yf(t,e,r,n,o){let i=Ut(t.multihash.bytes);return{type:"identity",cid:t,name:e,path:r,content:uo(i.digest,"unixfs:exporter:progress:identity"),size:BigInt(i.bytes.byteLength),node:i.bytes}}async function gf(t,e,r,n,o){let i=await S(n.get(t,o)),s=Dn(i);return{type:"object",cid:t,name:e,path:r,object:s,size:BigInt(i.byteLength),node:i}}async function wf(t,e,r,n,o){let i=await S(n.get(t,o));return{type:"raw",cid:t,name:e,path:r,content:uo(i,"unixfs:exporter:progress:raw"),size:BigInt(i.length),node:i}}function xf(t,e,r,n){async function*o(i={}){let s=i.offset??0,a=i.length??e.Links.length,c=e.Links.slice(s,s+a);i.onProgress?.(new me("unixfs:exporter:walk:directory",{cid:t})),yield*c.map(u=>({cid:u.Hash,name:u.Name??"",path:`${n}/${u.Name??""}`,size:BigInt(u.Tsize??0)}))}return o}var fo=globalThis.CustomEvent??Event;async function*Qi(t,e={}){let r=e.concurrency??1/0;r<1&&(r=1/0);let n=e.ordered??!1,o=new EventTarget,i=[],s=G(),a=G(),c=!1,u,l=!1,h=!1;o.addEventListener("task-complete",()=>{a.resolve()}),Promise.resolve().then(async()=>{try{for await(let k of t){if(i.length===r&&(s=G(),await s.promise),l||h)break;let b={done:!1};i.push(b),k().then(v=>{b.done=!0,b.ok=!0,b.value=v,o.dispatchEvent(new fo("task-complete"))},v=>{b.done=!0,b.err=v,o.dispatchEvent(new fo("task-complete"))})}c=!0,o.dispatchEvent(new fo("task-complete"))}catch(k){u=k,o.dispatchEvent(new fo("task-complete"))}});function m(){return n?i[0]?.done:!!i.find(k=>k.done)}function*E(){for(;i.length>0&&i[0].done;){let k=i[0];if(i.shift(),k.ok)yield k.value;else throw l=!0,s.resolve(),k.err;s.resolve()}}function*_(){for(;m();)for(let k=0;k<i.length;k++)if(i[k].done){let b=i[k];if(i.splice(k,1),k--,b.ok)yield b.value;else throw l=!0,s.resolve(),b.err;s.resolve()}}try{for(;;){if(m()||(a=G(),await a.promise),u!=null||(n?yield*E():yield*_(),u!=null))throw u;if(c&&i.length===0)break}}finally{h=!0,s.resolve()}}var es=or(Ef(),1);var ts=class t extends Error{name="TimeoutError";constructor(e,r){super(e,r),Error.captureStackTrace?.(this,t)}},vf=t=>t.reason??new DOMException("This operation was aborted.","AbortError");function rs(t,e){let{milliseconds:r,fallback:n,message:o,customTimers:i={setTimeout,clearTimeout},signal:s}=e,a,c,l=new Promise((h,m)=>{if(typeof r!="number"||Math.sign(r)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${r}\``);if(s?.aborted){m(vf(s)),t.then(h,m);return}if(s&&(c=()=>{m(vf(s))},s.addEventListener("abort",c,{once:!0})),t.then(h,m),r===Number.POSITIVE_INFINITY)return;let E=new ts;a=i.setTimeout.call(void 0,()=>{if(n){try{h(n())}catch(_){m(_)}return}typeof t.cancel=="function"&&t.cancel(),o===!1?h():o instanceof Error?m(o):(E.message=o??`Promise timed out after ${r} milliseconds`,m(E))},r)}).finally(()=>{l.clear(),c&&s&&s.removeEventListener("abort",c)});return l.clear=()=>{i.clearTimeout.call(void 0,a),a=void 0},l}function ns(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 im=100,rr=class{#e=[];#t=0;enqueue(e,r){let{priority:n=0,id:o}=r??{},{size:i}=this,s={priority:n,id:o,run:e};if(i===0){this.#e.length=0,this.#t=0,this.#e.push(s);return}if(this.#e.at(-1).priority>=n){this.#e.push(s);return}this.#i();let a=ns(this.#e,s,(c,u)=>u.priority-c.priority);this.#e.splice(a,0,s)}setPriority(e,r){let n=this.#e.findIndex((i,s)=>s>=this.#t&&i.id===e);if(n===-1)throw new ReferenceError(`No promise function with the id "${e}" exists in the queue.`);let[o]=this.#e.splice(n,1);this.enqueue(o.run,{priority:r,id:e})}remove(e){let r=this.#e.findIndex((n,o)=>o<this.#t?!1:typeof e=="string"?n.id===e:n.run===e);r!==-1&&this.#e.splice(r,1)}dequeue(){if(this.#t===this.#e.length)return;let e=this.#e[this.#t];return this.#t++,this.#t===this.#e.length?(this.#e.length=0,this.#t=0):this.#t>im&&this.#t>this.#e.length/2&&this.#i(),e?.run}filter(e){let r=[];for(let n=this.#t;n<this.#e.length;n++){let o=this.#e[n];o.priority===e.priority&&r.push(o.run)}return r}get size(){return this.#e.length-this.#t}#i(){this.#t!==0&&(this.#e.splice(0,this.#t),this.#t=0)}};var Fr=class extends es.default{#e;#t;#i=0;#h;#m=!1;#x=!1;#u;#b=0;#c;#f;#a;#s=[];#o=0;#r;#I;#n=0;#y;#l;#D=1n;#g=new Map;#E=new Set;timeout;constructor(e){if(super(),e={carryoverIntervalCount:!1,intervalCap:Number.POSITIVE_INFINITY,interval:0,concurrency:Number.POSITIVE_INFINITY,autoStart:!0,queueClass:rr,strict:!1,...e},!(typeof e.intervalCap=="number"&&e.intervalCap>=1))throw new TypeError(`Expected \`intervalCap\` to be a number from 1 and up, got \`${e.intervalCap?.toString()??""}\` (${typeof e.intervalCap})`);if(e.interval===void 0||!(Number.isFinite(e.interval)&&e.interval>=0))throw new TypeError(`Expected \`interval\` to be a finite number >= 0, got \`${e.interval?.toString()??""}\` (${typeof e.interval})`);if(e.strict&&e.interval===0)throw new TypeError("The `strict` option requires a non-zero `interval`");if(e.strict&&e.intervalCap===Number.POSITIVE_INFINITY)throw new TypeError("The `strict` option requires a finite `intervalCap`");if(this.#e=e.carryoverIntervalCount??e.carryoverConcurrencyCount??!1,this.#t=e.intervalCap===Number.POSITIVE_INFINITY||e.interval===0,this.#h=e.intervalCap,this.#u=e.interval,this.#a=e.strict,this.#r=new e.queueClass,this.#I=e.queueClass,this.concurrency=e.concurrency,e.timeout!==void 0&&!(Number.isFinite(e.timeout)&&e.timeout>0))throw new TypeError(`Expected \`timeout\` to be a positive finite number, got \`${e.timeout}\` (${typeof e.timeout})`);this.timeout=e.timeout,this.#l=e.autoStart===!1,this.#O()}#v(e){for(;this.#o<this.#s.length;){let n=this.#s[this.#o];if(n!==void 0&&e-n>=this.#u)this.#o++;else break}(this.#o>100&&this.#o>this.#s.length/2||this.#o===this.#s.length)&&(this.#s=this.#s.slice(this.#o),this.#o=0)}#U(e){this.#a?this.#s.push(e):this.#i++}#L(){this.#a?this.#s.length>this.#o&&this.#s.pop():this.#i>0&&this.#i--}#k(){return this.#s.length-this.#o}get#R(){return this.#t?!0:this.#a?this.#k()<this.#h:this.#i<this.#h}get#$(){return this.#n<this.#y}#M(){this.#n--,this.#n===0&&this.emit("pendingZero"),this.#w(),this.emit("next")}#P(){this.#f=void 0,this.#C(),this.#S()}#F(e){if(this.#a){if(this.#v(e),this.#k()>=this.#h){let n=this.#s[this.#o],o=this.#u-(e-n);return this.#T(o),!0}return!1}if(this.#c===void 0){let r=this.#b-e;if(r<0)this.#i=this.#e?this.#n:0;else return this.#T(r),!0}return!1}#T(e){this.#f===void 0&&(this.#f=setTimeout(()=>{this.#P()},e))}#_(){this.#c&&(clearInterval(this.#c),this.#c=void 0)}#B(){this.#f&&(clearTimeout(this.#f),this.#f=void 0)}#w(){if(this.#r.size===0){if(this.#_(),this.emit("empty"),this.#n===0){if(this.#B(),this.#a&&this.#o>0){let r=Date.now();this.#v(r)}this.emit("idle")}return!1}let e=!1;if(!this.#l){let r=Date.now(),n=!this.#F(r);if(this.#R&&this.#$){let o=this.#r.dequeue();this.#t||(this.#U(r),this.#p()),n&&this.#S(),o(),this.emit("active"),e=!0}}return e}#S(){this.#t||this.#c!==void 0||this.#a||(this.#c=setInterval(()=>{this.#C()},this.#u),this.#b=Date.now()+this.#u)}#C(){this.#a||(this.#c!==void 0&&(this.#i===0&&this.#n===0?this.#_():this.#b=Date.now()+this.#u),this.#i=this.#e?this.#n:0),this.#A(),this.#p()}#A(){for(;this.#w(););}get concurrency(){return this.#y}set concurrency(e){if(!(typeof e=="number"&&e>=1))throw new TypeError(`Expected \`concurrency\` to be a number from 1 and up, got \`${e}\` (${typeof e})`);this.#y=e,this.#A()}setPriority(e,r){if(typeof r!="number"||!Number.isFinite(r))throw new TypeError(`Expected \`priority\` to be a finite number, got \`${r}\` (${typeof r})`);this.#r.setPriority(e,r)}async add(e,r={}){if(r={timeout:this.timeout,...r,id:r.id??(this.#D++).toString()},r.timeout!==void 0&&!(Number.isFinite(r.timeout)&&r.timeout>0))throw new TypeError(`Expected \`timeout\` to be a positive finite number, got \`${r.timeout}\` (${typeof r.timeout})`);return new Promise((n,o)=>{let i=Symbol(`task-${r.id}`),s=()=>{},a=async()=>{s(),this.#n++,this.#g.set(i,{id:r.id,priority:r.priority??0,startTime:Date.now(),timeout:r.timeout});let u;try{try{r.signal?.throwIfAborted()}catch(m){throw this.#z(),this.#g.delete(i),m}let l=e({signal:r.signal});if(r.timeout!==void 0&&(l=rs(Promise.resolve(l),{milliseconds:r.timeout,message:`Task timed out after ${r.timeout}ms (queue has ${this.#n} running, ${this.#r.size} waiting)`})),r.signal){let{signal:m}=r;l=Promise.race([l,new Promise((E,_)=>{u=()=>{_(m.reason)},m.addEventListener("abort",u,{once:!0}),m.aborted&&u()})])}let h=await l;n(h),this.emit("completed",h)}catch(l){o(l),this.emit("error",l)}finally{u&&r.signal?.removeEventListener("abort",u),this.#g.delete(i),queueMicrotask(()=>{this.#M()})}};this.#r.enqueue(a,r);let c=()=>{if(this.#r instanceof rr){this.#r.remove(a);return}this.#r.remove?.(r.id)};if(r.signal){let{signal:u}=r,l=()=>{s(),c(),o(u.reason),this.#w(),this.emit("next")};if(s=()=>{u.removeEventListener("abort",l),this.#E.delete(s)},u.aborted){l();return}u.addEventListener("abort",l,{once:!0}),this.#E.add(s)}this.emit("add"),this.#w()})}async addAll(e,r){return Promise.all(e.map(async n=>this.add(n,r)))}start(){return this.#l?(this.#l=!1,this.#A(),this):this}pause(){this.#l=!0}clear(){for(let e of this.#E)e();this.#r=new this.#I,this.#_(),this.#N(),this.emit("empty"),this.#n===0&&(this.#B(),this.emit("idle")),this.emit("next")}async onEmpty(){this.#r.size!==0&&await this.#d("empty")}async onSizeLessThan(e){this.#r.size<e||await this.#d(["next","active"],()=>this.#r.size<e)}async onIdle(){this.#n===0&&this.#r.size===0||await this.#d("idle")}async onPendingZero(){this.#n!==0&&await this.#d("pendingZero")}async onRateLimit(){this.isRateLimited||await this.#d("rateLimit")}async onRateLimitCleared(){this.isRateLimited&&await this.#d("rateLimitCleared")}onError(){return new Promise((e,r)=>{let n=o=>{this.off("error",n),r(o)};this.on("error",n)})}async#d(e,r){let n=Array.isArray(e)?e:[e];return new Promise(o=>{let i=()=>{if(!(r&&!r())){for(let s of n)this.off(s,i);o()}};for(let s of n)this.on(s,i)})}get size(){return this.#r.size}sizeBy(e){return this.#r.filter(e).length}get pending(){return this.#n}get isPaused(){return this.#l}#O(){this.#t||(this.on("add",()=>{this.#r.size>0&&this.#p()}),this.on("next",()=>{this.#p()}))}#p(){this.#t||this.#x||(this.#x=!0,queueMicrotask(()=>{this.#x=!1,this.#N()}))}#z(){this.#t||(this.#L(),this.#p())}#N(){let e=this.#m;if(this.#t||this.#r.size===0){e&&(this.#m=!1,this.emit("rateLimitCleared"));return}let r;if(this.#a){let o=Date.now();this.#v(o),r=this.#k()}else r=this.#i;let n=r>=this.#h;n!==e&&(this.#m=n,this.emit(n?"rateLimit":"rateLimitCleared"))}get isRateLimited(){return this.#m}get isSaturated(){return this.#n===this.#y&&this.#r.size>0||this.isRateLimited&&this.#r.size>0}get runningTasks(){return[...this.#g.values()].map(e=>({...e,timeoutRemaining:e.timeout?Math.max(0,e.startTime+e.timeout-Date.now()):void 0}))}};async function kf(t,e,r,n,o,i,s){if(e instanceof Uint8Array){let u=Mr(e,n,o,i);r.push(u);return}if(e.Data==null)throw new L("no data in PBNode");let a;try{a=Se.unmarshal(e.Data)}catch(u){throw new L(u.message)}if(a.data!=null){let u=a.data,l=Mr(u,n,o,i);r.push(l),n+=BigInt(l.byteLength)}let c=[];if(e.Links.length!==a.blockSizes.length)throw new L("Inconsistent block sizes and dag links");for(let u=0;u<e.Links.length;u++){let l=e.Links[u],h=n,m=h+a.blockSizes[u];if((o>=h&&o<m||i>=h&&i<=m||o<h&&i>m)&&c.push({link:l,blockStart:n}),n=m,n>i)break}await pu(c,u=>Sn(u,l=>async()=>{let h=await S(t.get(l.link.Hash,s));return{...l,block:h}}),u=>Qi(u,{ordered:!0,concurrency:s.blockReadConcurrency??10}),async u=>{for await(let{link:l,block:h,blockStart:m}of u){let E;switch(l.Hash.code){case Jt:E=Jn(h);break;case Ot:E=h;break;default:r.end(new L(`Unsupported codec: ${l.Hash.code}`));return}let _=new Fr({concurrency:1});_.on("error",k=>{r.end(k)}),_.add(async()=>{s.onProgress?.(new me("unixfs:exporter:walk:file",{cid:l.Hash})),await kf(t,E,r,m,o,i,s)}),await _.onIdle()}}),n>=i&&r.end()}function os(t,e,r,n,o){async function*i(s={}){let a=r.fileSize();if(a===void 0)throw new Error("File was a directory");let{start:c,end:u}=co(a,s.offset,s.length);if(u===0n)return;let l=0n,h=u-c,m=Ht();s.onProgress?.(new me("unixfs:exporter:walk:file",{cid:t})),kf(o,e,m,0n,c,u,s).catch(E=>{m.end(E)});for await(let E of m)if(E!=null){if(l+=BigInt(E.byteLength),l>h)throw m.end(),new Xn("Read too many bytes - the file size reported by the UnixFS data in the root node may be incorrect");l===h&&m.end(),s.onProgress?.(new me("unixfs:exporter:progress:unixfs:file",{bytesRead:l,totalBytes:h,fileSize:a})),yield E}if(l<h)throw new Qn("Traversed entire DAG but did not read enough bytes")}return i}async function*sm(t,e,r,n){let o=-1,i=0;for await(let s of _f(t,e,r,n))if(o++,!(n.offset!=null&&n.offset<o)&&(yield s,i++,n.length!=null&&n.length===i))return}async function*_f(t,e,r,n){let o=await S(r.get(t,n)),i=Gt.decode(o);if(i.data?.fanOut==null)throw new L("missing fanout");let s=(i.data.fanOut-1n).toString(16).length;for(let a of i.links){if(a.name==null||a.hash==null)continue;let c=A.decode(a.hash);if(a.name.length===s)yield*_f(c,e,r,n);else{let u=a.name.substring(s);yield{cid:c,name:a.name.substring(s),path:`${e}/${u}`,size:BigInt(a.tSize??0)}}}}function Af(t,e,r,n,o){function i(s={}){return s.onProgress?.(new me("unixfs:exporter:walk:hamt-sharded-directory",{cid:t})),sm(t,n,o,s)}return i}var am={raw:os,file:os,directory:xf,"hamt-sharded-directory":Af,metadata:(t,e,r,n)=>()=>[],symlink:(t,e,r,n)=>()=>[]};async function If(t,e,r,n,o){let i=await S(n.get(t,o)),s;try{s=Jn(i)}catch(u){throw new L(u.message)}if(s.Data==null)throw new L("no data in PBNode");let a;try{a=Se.unmarshal(s.Data)}catch(u){throw new L(u.message)}let c=am[a.type](t,s,a,r,n);if(c==null)throw new Q("could not find content exporter");return a.isDirectory()?{type:"directory",cid:t,name:e,path:r,entries:c,unixfs:a,node:s,size:BigInt(i.byteLength)}:{type:"file",cid:t,name:e,path:r,content:c,unixfs:a,node:s,size:a.fileSize()}}var cm={[Jt]:If,[Ot]:wf,[cn]:Xi,81:Xi,[Zn]:mf,[kr.code]:yf,[Nn]:gf};async function Tf(t,e,r={}){let n,o;if(t instanceof String||typeof t=="string"){let s=await pf(ao(t,e,r));if(s==null)throw new Q(`Could not walk path to ${t}`);n=s.cid,o=s.name,t=s.path}else if(A.asCID(t)===t||t instanceof A)n=t,o=t=n.toString();else throw new Re("Path must be string or CID");let i=cm[n.code];if(i==null)throw new Xt(`No resolver for code ${n.code}`);return i(n,o,t,e,r)}var is=class{root;path;constructor(...e){let r=e[0],n=e[1];if(typeof r=="string")n=r,r=void 0;else if(e.length<2)throw new Error("path or CID and path must be specified");n.startsWith("/")||(n=`/${n}`),this.root=r,this.path=n}async*traverse(e,r,n,o){for await(let i of ao(`${this.root??e}${this.path}`,r,o)){let s=await Tf(i.cid,r,o);yield Be({cid:s.cid,bytes:s.node instanceof Uint8Array?s.node:ju(s.node),codec:await n(i.cid.code)})}}};function um(t){return new Hn(t)}return Lf(fm);})();
|
|
2
|
+
"use strict";var HeliaCar=(()=>{var ih=Object.create;var In=Object.defineProperty;var sh=Object.getOwnPropertyDescriptor;var ah=Object.getOwnPropertyNames;var ch=Object.getPrototypeOf,uh=Object.prototype.hasOwnProperty;var qt=(t,e)=>()=>{try{return e||t((e={exports:{}}).exports,e),e.exports}catch(r){throw e=0,r}},ue=(t,e)=>{for(var r in e)In(t,r,{get:e[r],enumerable:!0})},xa=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of ah(e))!uh.call(t,o)&&o!==r&&In(t,o,{get:()=>e[o],enumerable:!(n=sh(e,o))||n.enumerable});return t};var Or=(t,e,r)=>(r=t!=null?ih(ch(t)):{},xa(e||!t||!t.__esModule?In(r,"default",{value:t,enumerable:!0}):r,t)),fh=t=>xa(In({},"__esModule",{value:!0}),t);var Yc=qt((ex,Jc)=>{Jc.exports=Gi;var Wc=128,Jp=127,Yp=~Jp,Xp=Math.pow(2,31);function Gi(t,e,r){if(Number.MAX_SAFE_INTEGER&&t>Number.MAX_SAFE_INTEGER)throw Gi.bytes=0,new RangeError("Could not encode varint");e=e||[],r=r||0;for(var n=r;t>=Xp;)e[r++]=t&255|Wc,t/=128;for(;t&Yp;)e[r++]=t&255|Wc,t>>>=7;return e[r]=t|0,Gi.bytes=r-n+1,e}});var Qc=qt((tx,Kc)=>{Kc.exports=Wi;var Kp=128,Xc=127;function Wi(t,n){var r=0,n=n||0,o=0,i=n,s,a=t.length;do{if(i>=a||o>49)throw Wi.bytes=0,new RangeError("Could not decode varint");s=t[i++],r+=o<28?(s&Xc)<<o:(s&Xc)*Math.pow(2,o),o+=7}while(s>=Kp);return Wi.bytes=i-n,r}});var eu=qt((rx,Zc)=>{var Qp=Math.pow(2,7),Zp=Math.pow(2,14),em=Math.pow(2,21),tm=Math.pow(2,28),rm=Math.pow(2,35),nm=Math.pow(2,42),om=Math.pow(2,49),im=Math.pow(2,56),sm=Math.pow(2,63);Zc.exports=function(t){return t<Qp?1:t<Zp?2:t<em?3:t<tm?4:t<rm?5:t<nm?6:t<om?7:t<im?8:t<sm?9:10}});var qn=qt((nx,tu)=>{tu.exports={encode:Yc(),decode:Qc(),encodingLength:eu()}});var Cd=qt((n2,Nd)=>{"use strict";Nd.exports=class{constructor(){this._bitArrays=[],this._data=[],this._length=0,this._changedLength=!1,this._changedData=!1}set(e,r){let n=this._internalPositionFor(e,!1);if(r===void 0)n!==-1&&(this._unsetInternalPos(n),this._unsetBit(e),this._changedLength=!0,this._changedData=!0);else{let o=!1;n===-1?(n=this._data.length,this._setBit(e),this._changedData=!0):o=!0,this._setInternalPos(n,e,r,o),this._changedLength=!0}}unset(e){this.set(e,void 0)}get(e){this._sortData();let r=this._internalPositionFor(e,!0);if(r!==-1)return this._data[r][1]}push(e){return this.set(this.length,e),this.length}get length(){if(this._sortData(),this._changedLength){let e=this._data[this._data.length-1];this._length=e?e[0]+1:0,this._changedLength=!1}return this._length}forEach(e){let r=0;for(;r<this.length;)e(this.get(r),r,this),r++}map(e){let r=0,n=new Array(this.length);for(;r<this.length;)n[r]=e(this.get(r),r,this),r++;return n}reduce(e,r){let n=0,o=r;for(;n<this.length;){let i=this.get(n);o=e(o,i,n),n++}return o}find(e){let r=0,n,o;for(;r<this.length&&!n;)o=this.get(r),n=e(o),r++;return n?o:void 0}_internalPositionFor(e,r){let n=this._bytePosFor(e,r);if(n>=this._bitArrays.length)return-1;let o=this._bitArrays[n],i=e-n*7;if(!((o&1<<i)>0))return-1;let a=this._bitArrays.slice(0,n).reduce(o0,0),c=~(4294967295<<i+1),u=Ud(o&c);return a+u-1}_bytePosFor(e,r){let n=Math.floor(e/7),o=n+1;for(;!r&&this._bitArrays.length<o;)this._bitArrays.push(0);return n}_setBit(e){let r=this._bytePosFor(e,!1);this._bitArrays[r]|=1<<e-r*7}_unsetBit(e){let r=this._bytePosFor(e,!1);this._bitArrays[r]&=~(1<<e-r*7)}_setInternalPos(e,r,n,o){let i=this._data,s=[r,n];if(o)this._sortData(),i[e]=s;else{if(i.length)if(i[i.length-1][0]>=r)i.push(s);else if(i[0][0]<=r)i.unshift(s);else{let a=Math.round(i.length/2);this._data=i.slice(0,a).concat(s).concat(i.slice(a))}else this._data.push(s);this._changedData=!0,this._changedLength=!0}}_unsetInternalPos(e){this._data.splice(e,1)}_sortData(){this._changedData&&this._data.sort(i0),this._changedData=!1}bitField(){let e=[],r=8,n=0,o=0,i,s=this._bitArrays.slice();for(;s.length||n;){n===0&&(i=s.shift(),n=7);let c=Math.min(n,r),u=~(255<<c),f=i&u;o|=f<<8-r,i=i>>>c,n-=c,r-=c,(!r||!n&&!s.length)&&(e.push(o),o=0,r=8)}for(var a=e.length-1;a>0&&e[a]===0;a--)e.pop();return e}compactArray(){return this._sortData(),this._data.map(s0)}};function o0(t,e){return t+Ud(e)}function Ud(t){let e=t;return e=e-(e>>1&1431655765),e=(e&858993459)+(e>>2&858993459),(e+(e>>4)&252645135)*16843009>>24}function i0(t,e){return t[0]-e[0]}function s0(t){return t[1]}});var Kd=qt((wI,da)=>{"use strict";var b0=Object.prototype.hasOwnProperty,oe="~";function vn(){}Object.create&&(vn.prototype=Object.create(null),new vn().__proto__||(oe=!1));function E0(t,e,r){this.fn=t,this.context=e,this.once=r||!1}function Xd(t,e,r,n,o){if(typeof r!="function")throw new TypeError("The listener must be a function");var i=new E0(r,n||t,o),s=oe?oe+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 gi(t,e){--t._eventsCount===0?t._events=new vn:delete t._events[e]}function re(){this._events=new vn,this._eventsCount=0}re.prototype.eventNames=function(){var e=[],r,n;if(this._eventsCount===0)return e;for(n in r=this._events)b0.call(r,n)&&e.push(oe?n.slice(1):n);return Object.getOwnPropertySymbols?e.concat(Object.getOwnPropertySymbols(r)):e};re.prototype.listeners=function(e){var r=oe?oe+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};re.prototype.listenerCount=function(e){var r=oe?oe+e:e,n=this._events[r];return n?n.fn?1:n.length:0};re.prototype.emit=function(e,r,n,o,i,s){var a=oe?oe+e:e;if(!this._events[a])return!1;var c=this._events[a],u=arguments.length,f,p;if(c.fn){switch(c.once&&this.removeListener(e,c.fn,void 0,!0),u){case 1:return c.fn.call(c.context),!0;case 2:return c.fn.call(c.context,r),!0;case 3:return c.fn.call(c.context,r,n),!0;case 4:return c.fn.call(c.context,r,n,o),!0;case 5:return c.fn.call(c.context,r,n,o,i),!0;case 6:return c.fn.call(c.context,r,n,o,i,s),!0}for(p=1,f=new Array(u-1);p<u;p++)f[p-1]=arguments[p];c.fn.apply(c.context,f)}else{var m=c.length,_;for(p=0;p<m;p++)switch(c[p].once&&this.removeListener(e,c[p].fn,void 0,!0),u){case 1:c[p].fn.call(c[p].context);break;case 2:c[p].fn.call(c[p].context,r);break;case 3:c[p].fn.call(c[p].context,r,n);break;case 4:c[p].fn.call(c[p].context,r,n,o);break;default:if(!f)for(_=1,f=new Array(u-1);_<u;_++)f[_-1]=arguments[_];c[p].fn.apply(c[p].context,f)}}return!0};re.prototype.on=function(e,r,n){return Xd(this,e,r,n,!1)};re.prototype.once=function(e,r,n){return Xd(this,e,r,n,!0)};re.prototype.removeListener=function(e,r,n,o){var i=oe?oe+e:e;if(!this._events[i])return this;if(!r)return gi(this,i),this;var s=this._events[i];if(s.fn)s.fn===r&&(!o||s.once)&&(!n||s.context===n)&&gi(this,i);else{for(var a=0,c=[],u=s.length;a<u;a++)(s[a].fn!==r||o&&!s[a].once||n&&s[a].context!==n)&&c.push(s[a]);c.length?this._events[i]=c.length===1?c[0]:c:gi(this,i)}return this};re.prototype.removeAllListeners=function(e){var r;return e?(r=oe?oe+e:e,this._events[r]&&gi(this,r)):(this._events=new vn,this._eventsCount=0),this};re.prototype.off=re.prototype.removeListener;re.prototype.addListener=re.prototype.on;re.prefixed=oe;re.EventEmitter=re;typeof da<"u"&&(da.exports=re)});var T0={};ue(T0,{BlockExporter:()=>Fs,CIDPath:()=>Qs,GraphSearch:()=>Ks,SubgraphExporter:()=>pn,UnixFSExporter:()=>mn,UnixFSPath:()=>wa,breadthFirstWalker:()=>vr,car:()=>I0,depthFirstWalker:()=>Ar,naturalOrderWalker:()=>Wl});var lh=["Object","Uint8Array","RegExp","Date","Error","Map","Set","WeakMap","WeakSet","ArrayBuffer","SharedArrayBuffer","DataView","Promise","URL","HTMLElement","Int8Array","Uint8ClampedArray","Int16Array","Uint16Array","Int32Array","Uint32Array","Float32Array","Float64Array","BigInt64Array","BigUint64Array","Tagged","Number","String","Boolean","BigInt","Symbol"];function wi(t){if(t===null)return"null";if(t===void 0)return"undefined";if(t===!0||t===!1)return"boolean";let e=typeof t;if(e==="string"||e==="number"||e==="bigint"||e==="symbol")return e;if(e==="function")return"Function";if(Array.isArray(t))return"Array";if(t instanceof Uint8Array)return"Uint8Array";if(t.constructor===Object)return"Object";let r=dh(t);return r||"Object"}function dh(t){let e=Object.prototype.toString.call(t).slice(8,-1);if(lh.includes(e))return e}var d=class{constructor(e,r,n){this.major=e,this.majorEncoded=e<<5,this.name=r,this.terminal=n}toString(){return`Type[${this.major}].${this.name}`}compare(e){return this.major<e.major?-1:this.major>e.major?1:0}static equals(e,r){return e===r||e.major===r.major&&e.name===r.name}};d.uint=new d(0,"uint",!0);d.negint=new d(1,"negint",!0);d.bytes=new d(2,"bytes",!0);d.string=new d(3,"string",!0);d.array=new d(4,"array",!1);d.map=new d(5,"map",!1);d.tag=new d(6,"tag",!1);d.float=new d(7,"float",!0);d.false=new d(7,"false",!0);d.true=new d(7,"true",!0);d.null=new d(7,"null",!0);d.undefined=new d(7,"undefined",!0);d.break=new d(7,"break",!0);var A=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 Gt=class{constructor(){this.home=new Uint8Array(2048),this.buf=this.home,this.pos=0,this.start=0,this.segs=[],this.segLen=0}reset(){this.buf.length>this.home.length&&this.buf.length<=65536&&(this.home=this.buf),this.buf=this.home,this.pos=0,this.start=0,this.segs.length>0&&(this.segs=[],this.segLen=0)}grow(e){let r=this.pos-this.start;if(this.buf.length>=262144)r>0&&(this.segs.push(this.buf.subarray(this.start,this.pos)),this.segLen+=r),this.buf=new Uint8Array(e>262144?e:262144),this.pos=0,this.start=0;else{let n=this.buf.length*2;for(;n<r+e;)n*=2;let o=new Uint8Array(n);o.set(this.buf.subarray(this.start,this.pos)),this.buf=o,this.pos=r,this.start=0}}pushByte(e){this.pos>=this.buf.length&&this.grow(1),this.buf[this.pos++]=e}pushArr(e){let r=e.length;this.pos+r>this.buf.length&&this.grow(r);let n=this.buf,o=this.pos;for(let i=0;i<r;i++)n[o++]=e[i];this.pos=o}pushBytes(e){let r=e.length;if(r>=1024){this.pos>this.start&&(this.segs.push(this.buf.subarray(this.start,this.pos)),this.segLen+=this.pos-this.start),this.segs.push(e),this.segLen+=r,this.start=this.pos;return}this.pos+r>this.buf.length&&this.grow(r);let n=this.buf,o=this.pos;if(r<16)for(let i=0;i<r;i++)n[o++]=e[i];else n.set(e,o),o+=r;this.pos=o}push(e){Array.isArray(e)?this.pushArr(e):this.pushBytes(e)}toBytes(e=!1){let r;if(this.segs.length===0)r=new Uint8Array(this.buf.subarray(this.start,this.pos));else{r=new Uint8Array(this.segLen+(this.pos-this.start));let n=0;for(let o of this.segs)r.set(o,n),n+=o.length;r.set(this.buf.subarray(this.start,this.pos),n)}return e&&this.reset(),r}},Bt=class{constructor(e){this.dest=e,this.cursor=0}reset(){this.cursor=0}pushByte(e){if(this.cursor>=this.dest.length)throw new Error("write out of bounds, destination buffer is too small");this.dest[this.cursor++]=e}push(e){if(this.cursor+e.length>this.dest.length)throw new Error("write out of bounds, destination buffer is too small");this.dest.set(e,this.cursor),this.cursor+=e.length}pushArr(e){let r=e.length;if(this.cursor+r>this.dest.length)throw new Error("write out of bounds, destination buffer is too small");let n=this.dest,o=this.cursor;for(let i=0;i<r;i++)n[o++]=e[i];this.cursor=o}pushBytes(e){this.push(e)}toBytes(e=!1){let r=this.dest.subarray(0,this.cursor);return e&&this.reset(),r}};var k="CBOR decode error:",Ae="CBOR encode error:",Rr=[];Rr[23]=1;Rr[24]=2;Rr[25]=3;Rr[26]=5;Rr[27]=9;function Xe(t,e,r){if(t.length-e<r)throw new Error(`${k} not enough data for type`)}var H=[24,256,65536,4294967296,BigInt("18446744073709551616")];function fe(t,e,r){Xe(t,e,1);let n=t[e];if(r.strict===!0&&n<H[0])throw new Error(`${k} integer encoded in more bytes than necessary (strict decode)`);return n}function le(t,e,r){Xe(t,e,2);let n=t[e]<<8|t[e+1];if(r.strict===!0&&n<H[1])throw new Error(`${k} integer encoded in more bytes than necessary (strict decode)`);return n}function de(t,e,r){Xe(t,e,4);let n=t[e]*16777216+(t[e+1]<<16)+(t[e+2]<<8)+t[e+3];if(r.strict===!0&&n<H[2])throw new Error(`${k} integer encoded in more bytes than necessary (strict decode)`);return n}function he(t,e,r){Xe(t,e,8);let n=t[e]*16777216+(t[e+1]<<16)+(t[e+2]<<8)+t[e+3],o=t[e+4]*16777216+(t[e+5]<<16)+(t[e+6]<<8)+t[e+7],i=(BigInt(n)<<BigInt(32))+BigInt(o);if(r.strict===!0&&i<H[3])throw new Error(`${k} 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(`${k} integers outside of the safe integer range are not supported`)}function ba(t,e,r,n){return new A(d.uint,fe(t,e+1,n),2)}function Ea(t,e,r,n){return new A(d.uint,le(t,e+1,n),3)}function _a(t,e,r,n){return new A(d.uint,de(t,e+1,n),5)}function Aa(t,e,r,n){return new A(d.uint,he(t,e+1,n),9)}function $e(t,e){return q(t,0,e.value)}function q(t,e,r){if(r<H[0]){let n=Number(r);t.pushByte(e|n)}else if(r<H[1]){let n=Number(r);t.pushArr([e|24,n])}else if(r<H[2]){let n=Number(r);t.pushArr([e|25,n>>>8,n&255])}else if(r<H[3]){let n=Number(r);t.pushArr([e|26,n>>>24&255,n>>>16&255,n>>>8&255,n&255])}else{let n=BigInt(r);if(n<H[4]){let o=[e|27,0,0,0,0,0,0,0],i=Number(n&BigInt(4294967295)),s=Number(n>>BigInt(32)&BigInt(4294967295));o[8]=i&255,i=i>>8,o[7]=i&255,i=i>>8,o[6]=i&255,i=i>>8,o[5]=i&255,o[4]=s&255,s=s>>8,o[3]=s&255,s=s>>8,o[2]=s&255,s=s>>8,o[1]=s&255,t.pushArr(o)}else throw new Error(`${Ae} encountered BigInt larger than allowable range`)}}$e.encodedSize=function(e){return q.encodedSize(e.value)};q.encodedSize=function(e){if(e<H[0])return 1;if(e<H[1])return 2;if(e<H[2])return 3;if(e<H[3])return 5;if(e>=H[4])throw new Error(`${Ae} encountered BigInt larger than allowable range`);return 9};$e.compareTokens=function(e,r){return e.value<r.value?-1:e.value>r.value?1:0};function va(t,e,r,n){return new A(d.negint,-1-fe(t,e+1,n),2)}function ka(t,e,r,n){return new A(d.negint,-1-le(t,e+1,n),3)}function Ia(t,e,r,n){return new A(d.negint,-1-de(t,e+1,n),5)}var xi=BigInt(-1),Ta=BigInt(1);function Ba(t,e,r,n){let o=he(t,e+1,n);if(typeof o!="bigint"){let i=-1-o;if(i>=Number.MIN_SAFE_INTEGER)return new A(d.negint,i,9)}if(n.allowBigInt!==!0)throw new Error(`${k} integers outside of the safe integer range are not supported`);return new A(d.negint,xi-BigInt(o),9)}function Tn(t,e){let r=e.value,n=typeof r=="bigint"?r*xi-Ta:r*-1-1;q(t,e.type.majorEncoded,n)}Tn.encodedSize=function(e){let r=e.value,n=typeof r=="bigint"?r*xi-Ta:r*-1-1;if(n<H[0])return 1;if(n<H[1])return 2;if(n<H[2])return 3;if(n<H[3])return 5;if(n>=H[4])throw new Error(`${Ae} encountered BigInt larger than allowable range`);return 9};Tn.compareTokens=function(e,r){return e.value<r.value?1:e.value>r.value?-1:0};var Ua=globalThis.process&&!globalThis.process.browser&&globalThis.Buffer&&typeof globalThis.Buffer.isBuffer=="function",ph=new TextEncoder;function bi(t){return Ua&&globalThis.Buffer.isBuffer(t)}function Na(t){return t instanceof Uint8Array?bi(t)?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):t:Uint8Array.from(t)}var mh=24,yh=200,Fr=Ua?t=>t.length>=mh?globalThis.Buffer.from(t):Sa(t):t=>t.length>=yh?ph.encode(t):Sa(t),Me=t=>Uint8Array.from(t);function Wt(t,e){if(bi(t)&&bi(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 Sa(t){let e=[],r=0;for(let n=0;n<t.length;n++){let o=t.charCodeAt(n);o<128?e[r++]=o:o<2048?(e[r++]=o>>6|192,e[r++]=o&63|128):(o&64512)===55296&&n+1<t.length&&(t.charCodeAt(n+1)&64512)===56320?(o=65536+((o&1023)<<10)+(t.charCodeAt(++n)&1023),e[r++]=o>>18|240,e[r++]=o>>12&63|128,e[r++]=o>>6&63|128,e[r++]=o&63|128):(o>=55296&&o<=57343&&(o=65533),e[r++]=o>>12|224,e[r++]=o>>6&63|128,e[r++]=o&63|128)}return e}function Pr(t,e,r,n){Xe(t,e,r+n);let o=t.slice(e+r,e+r+n);return new A(d.bytes,o,r+n)}function Ca(t,e,r,n){return Pr(t,e,1,r)}function Da(t,e,r,n){return Pr(t,e,2,fe(t,e+1,n))}function La(t,e,r,n){return Pr(t,e,3,le(t,e+1,n))}function $a(t,e,r,n){return Pr(t,e,5,de(t,e+1,n))}function Ma(t,e,r,n){let o=he(t,e+1,n);if(typeof o=="bigint")throw new Error(`${k} 64-bit integer bytes lengths not supported`);return Pr(t,e,9,o)}function Bn(t){return t.encodedBytes===void 0&&(t.encodedBytes=d.equals(t.type,d.string)?Fr(t.value):t.value),t.encodedBytes}function Jt(t,e){let r=Bn(e);q(t,e.type.majorEncoded,r.length),t.push(r)}Jt.encodedSize=function(e){let r=Bn(e);return q.encodedSize(r.length)+r.length};Jt.compareTokens=function(e,r){return gh(Bn(e),Bn(r))};function gh(t,e){return t.length<e.length?-1:t.length>e.length?1:Wt(t,e)}var Oa=new TextDecoder("utf-8",{ignoreBOM:!0}),xh=new TextDecoder("utf-8",{ignoreBOM:!0,fatal:!0}),bh=32;function Eh(t,e,r,n){if(r-e<bh){let i="";for(let s=e;s<r;s++){let a=t[s];if(a&128)return n.rejectInvalidUtf8===!0?Ra(t,e,r):Oa.decode(t.subarray(e,r));i+=String.fromCharCode(a)}return i}return n.rejectInvalidUtf8===!0?Ra(t,e,r):Oa.decode(t.subarray(e,r))}function Ra(t,e,r){try{return xh.decode(t.subarray(e,r))}catch{throw new Error(`${k} invalid UTF-8 in text string`)}}function zr(t,e,r,n,o){let i=r+n;Xe(t,e,i);let s=new A(d.string,Eh(t,e+r,e+i,o),i);return o.retainStringBytes===!0&&(s.byteValue=t.slice(e+r,e+i)),s}function Fa(t,e,r,n){return zr(t,e,1,r,n)}function Pa(t,e,r,n){return zr(t,e,2,fe(t,e+1,n),n)}function za(t,e,r,n){return zr(t,e,3,le(t,e+1,n),n)}function ja(t,e,r,n){return zr(t,e,5,de(t,e+1,n),n)}function Ha(t,e,r,n){let o=he(t,e+1,n);if(typeof o=="bigint")throw new Error(`${k} 64-bit integer string lengths not supported`);return zr(t,e,9,o,n)}var Va=Jt;function Yt(t,e,r,n){return new A(d.array,n,r)}function qa(t,e,r,n){return Yt(t,e,1,r)}function Ga(t,e,r,n){return Yt(t,e,2,fe(t,e+1,n))}function Wa(t,e,r,n){return Yt(t,e,3,le(t,e+1,n))}function Ja(t,e,r,n){return Yt(t,e,5,de(t,e+1,n))}function Ya(t,e,r,n){let o=he(t,e+1,n);if(typeof o=="bigint")throw new Error(`${k} 64-bit integer array lengths not supported`);return Yt(t,e,9,o)}function Xa(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${k} indefinite length items not allowed`);return Yt(t,e,1,1/0)}function Sn(t,e){q(t,d.array.majorEncoded,e.value)}Sn.compareTokens=$e.compareTokens;Sn.encodedSize=function(e){return q.encodedSize(e.value)};function Xt(t,e,r,n){return new A(d.map,n,r)}function Ka(t,e,r,n){return Xt(t,e,1,r)}function Qa(t,e,r,n){return Xt(t,e,2,fe(t,e+1,n))}function Za(t,e,r,n){return Xt(t,e,3,le(t,e+1,n))}function ec(t,e,r,n){return Xt(t,e,5,de(t,e+1,n))}function tc(t,e,r,n){let o=he(t,e+1,n);if(typeof o=="bigint")throw new Error(`${k} 64-bit integer map lengths not supported`);return Xt(t,e,9,o)}function rc(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${k} indefinite length items not allowed`);return Xt(t,e,1,1/0)}function Un(t,e){q(t,d.map.majorEncoded,e.value)}Un.compareTokens=$e.compareTokens;Un.encodedSize=function(e){return q.encodedSize(e.value)};function nc(t,e,r,n){return new A(d.tag,r,1)}function oc(t,e,r,n){return new A(d.tag,fe(t,e+1,n),2)}function ic(t,e,r,n){return new A(d.tag,le(t,e+1,n),3)}function sc(t,e,r,n){return new A(d.tag,de(t,e+1,n),5)}function ac(t,e,r,n){return new A(d.tag,he(t,e+1,n),9)}function Nn(t,e){q(t,d.tag.majorEncoded,e.value)}Nn.compareTokens=$e.compareTokens;Nn.encodedSize=function(e){return q.encodedSize(e.value)};var Cn=20,Dn=21,Ln=22,$n=23;function uc(t,e,r,n){if(n.allowUndefined===!1)throw new Error(`${k} undefined values are not supported`);return n.coerceUndefinedToNull===!0?new A(d.null,null,1):new A(d.undefined,void 0,1)}function fc(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${k} indefinite length items not allowed`);return new A(d.break,void 0,1)}function Ei(t,e,r){if(r){if(r.allowNaN===!1&&Number.isNaN(t))throw new Error(`${k} NaN values are not supported`);if(r.allowInfinity===!1&&(t===1/0||t===-1/0))throw new Error(`${k} Infinity values are not supported`)}return new A(d.float,t,e)}function lc(t,e,r,n){return Ei(Mn(t,e+1),3,n)}function dc(t,e,r,n){return Ei(On(t,e+1),5,n)}function hc(t,e,r,n){return Ei(yc(t,e+1),9,n)}function jr(t,e,r){let n=e.value;if(n===!1)t.pushByte(d.float.majorEncoded|Cn);else if(n===!0)t.pushByte(d.float.majorEncoded|Dn);else if(n===null)t.pushByte(d.float.majorEncoded|Ln);else if(n===void 0)d.equals(e.type,d.break)||t.pushByte(d.float.majorEncoded|$n);else{let o,i=!1;(!r||r.float64!==!0)&&(_i(n),o=Mn(G,1),n===o||Number.isNaN(n)?(G[0]=249,t.pushBytes(G.slice(0,3)),i=!0):(Ai(n),o=On(G,1),n===o&&(G[0]=250,t.pushBytes(G.slice(0,5)),i=!0))),i||(mc(n),o=yc(G,1),G[0]=251,t.pushBytes(G.slice(0,9)))}}jr.encodedSize=function(e,r){let n=e.value;if(n===void 0)return d.equals(e.type,d.break)?0:1;if(n===!1||n===!0||n===null)return 1;if(!r||r.float64!==!0){_i(n);let o=Mn(G,1);if(n===o||Number.isNaN(n))return 3;if(Ai(n),o=On(G,1),n===o)return 5}return 9};var pc=new ArrayBuffer(9),ve=new DataView(pc,1),G=new Uint8Array(pc,0);function _i(t){if(t===1/0)ve.setUint16(0,31744,!1);else if(t===-1/0)ve.setUint16(0,64512,!1);else if(Number.isNaN(t))ve.setUint16(0,32256,!1);else{ve.setFloat32(0,t);let e=ve.getUint32(0),r=(e&2139095040)>>23,n=e&8388607;if(r===255)ve.setUint16(0,31744,!1);else if(r===0)ve.setUint16(0,(e&2147483648)>>16|n>>13,!1);else{let o=r-127;o<-24?ve.setUint16(0,0):o<-14?ve.setUint16(0,(e&2147483648)>>16|(8388608|n)>>-1-o,!1):ve.setUint16(0,(e&2147483648)>>16|o+15<<10|n>>13,!1)}}}function Mn(t,e){if(t.length-e<2)throw new Error(`${k} 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 Ai(t){ve.setFloat32(0,t,!1)}function On(t,e){if(t.length-e<4)throw new Error(`${k} not enough data for float32`);let r=(t.byteOffset||0)+e;return new DataView(t.buffer,r,4).getFloat32(0,!1)}function mc(t){ve.setFloat64(0,t,!1)}function yc(t,e){if(t.length-e<8)throw new Error(`${k} not enough data for float64`);let r=(t.byteOffset||0)+e;return new DataView(t.buffer,r,8).getFloat64(0,!1)}function Ih(t,e){let r=t.value;if(r===!1)return Uint8Array.of(d.float.majorEncoded|Cn);if(r===!0)return Uint8Array.of(d.float.majorEncoded|Dn);if(r===null)return Uint8Array.of(d.float.majorEncoded|Ln);if(r===void 0)return Uint8Array.of(d.float.majorEncoded|$n);if(!e){if(_i(r),r===Mn(G,1)||Number.isNaN(r))return G[0]=249,G.slice(0,3);if(Ai(r),r===On(G,1))return G[0]=250,G.slice(0,5)}return mc(r),G[0]=251,G.slice(0,9)}function cc(t,e){let r=t,n=e?.float64===!0,o=n?r._keyBytesFloat64:r._keyBytes;if(o!==void 0)return o;let i=Ih(t,n);return n?r._keyBytesFloat64=i:r._keyBytes=i,i}jr.compareTokens=function(e,r,n){let o=cc(e,n),i=cc(r,n);return o.length!==i.length?o.length<i.length?-1:1:Wt(o,i)};function U(t,e,r){throw new Error(`${k} encountered invalid minor (${r}) for major ${t[e]>>>5}`)}function Rn(t){return()=>{throw new Error(`${k} ${t}`)}}var w=[];for(let t=0;t<=23;t++)w[t]=U;w[24]=ba;w[25]=Ea;w[26]=_a;w[27]=Aa;w[28]=U;w[29]=U;w[30]=U;w[31]=U;for(let t=32;t<=55;t++)w[t]=U;w[56]=va;w[57]=ka;w[58]=Ia;w[59]=Ba;w[60]=U;w[61]=U;w[62]=U;w[63]=U;for(let t=64;t<=87;t++)w[t]=Ca;w[88]=Da;w[89]=La;w[90]=$a;w[91]=Ma;w[92]=U;w[93]=U;w[94]=U;w[95]=Rn("indefinite length bytes/strings are not supported");for(let t=96;t<=119;t++)w[t]=Fa;w[120]=Pa;w[121]=za;w[122]=ja;w[123]=Ha;w[124]=U;w[125]=U;w[126]=U;w[127]=Rn("indefinite length bytes/strings are not supported");for(let t=128;t<=151;t++)w[t]=qa;w[152]=Ga;w[153]=Wa;w[154]=Ja;w[155]=Ya;w[156]=U;w[157]=U;w[158]=U;w[159]=Xa;for(let t=160;t<=183;t++)w[t]=Ka;w[184]=Qa;w[185]=Za;w[186]=ec;w[187]=tc;w[188]=U;w[189]=U;w[190]=U;w[191]=rc;for(let t=192;t<=215;t++)w[t]=nc;w[216]=oc;w[217]=ic;w[218]=sc;w[219]=ac;w[220]=U;w[221]=U;w[222]=U;w[223]=U;for(let t=224;t<=243;t++)w[t]=Rn("simple values are not supported");w[244]=U;w[245]=U;w[246]=U;w[247]=uc;w[248]=Rn("simple values are not supported");w[249]=lc;w[250]=dc;w[251]=hc;w[252]=U;w[253]=U;w[254]=U;w[255]=fc;var Ne=[];for(let t=0;t<24;t++)Ne[t]=new A(d.uint,t,1);for(let t=-1;t>=-24;t--)Ne[31-t]=new A(d.negint,t,1);Ne[64]=new A(d.bytes,new Uint8Array(0),1);Ne[96]=new A(d.string,"",1);Ne[128]=new A(d.array,0,1);Ne[160]=new A(d.map,0,1);Ne[244]=new A(d.false,!1,1);Ne[245]=new A(d.true,!0,1);Ne[246]=new A(d.null,null,1);function vi(t){switch(t.type){case d.false:return Me([244]);case d.true:return Me([245]);case d.null:return Me([246]);case d.bytes:return t.value.length?void 0:Me([64]);case d.string:return t.value===""?Me([96]):void 0;case d.array:return t.value===0?Me([128]):void 0;case d.map:return t.value===0?Me([160]):void 0;case d.uint:return t.value<24?Me([Number(t.value)]):void 0;case d.negint:if(t.value>=-24)return Me([31-Number(t.value)])}}var Bh={float64:!1,mapSorter:ki,quickEncodeToken:vi},Ac=Object.freeze({mapSorter:Nh,quickEncodeToken:vi});function Sh(){let t=[];return t[d.uint.major]=$e,t[d.negint.major]=Tn,t[d.bytes.major]=Jt,t[d.string.major]=Va,t[d.array.major]=Sn,t[d.map.major]=Un,t[d.tag.major]=Nn,t[d.float.major]=jr,t}var Ut=Sh(),Fn=new Gt,Pn=!1,Nt=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(`${Ae} object contains circular references`);return new t(r,e)}},rt={null:new A(d.null,null),undefined:new A(d.undefined,void 0),true:new A(d.true,!0),false:new A(d.false,!1),emptyArray:new A(d.array,0),emptyMap:new A(d.map,0)},se={number(t,e,r,n){return!Number.isInteger(t)||!Number.isSafeInteger(t)?new A(d.float,t):t>=0?new A(d.uint,t):new A(d.negint,t)},bigint(t,e,r,n){return t>=BigInt(0)?new A(d.uint,t):new A(d.negint,t)},Uint8Array(t,e,r,n){return new A(d.bytes,t)},string(t,e,r,n){return new A(d.string,t)},boolean(t,e,r,n){return t?rt.true:rt.false},null(t,e,r,n){return rt.null},undefined(t,e,r,n){return rt.undefined},ArrayBuffer(t,e,r,n){return new A(d.bytes,new Uint8Array(t))},DataView(t,e,r,n){return new A(d.bytes,new Uint8Array(t.buffer,t.byteOffset,t.byteLength))},Array(t,e,r,n){if(!t.length)return r.addBreakTokens===!0?[rt.emptyArray,new A(d.break)]:rt.emptyArray;n=Nt.createCheck(n,t);let o=[],i=0;for(let s of t)o[i++]=ot(s,r,n);return r.addBreakTokens?[new A(d.array,t.length),o,new A(d.break)]:[new A(d.array,t.length),o]},Object(t,e,r,n){let o=e!=="Object",i=o?t.keys():Object.keys(t),s=o?t.size:i.length,a;if(s){a=new Array(s),n=Nt.createCheck(n,t);let c=!o&&r.ignoreUndefinedProperties,u=0;for(let f of i){let p=o?t.get(f):t[f];c&&p===void 0||(a[u++]=[ot(f,r,n),ot(p,r,n)])}u<s&&(a.length=u)}return a?.length?(Uh(a,r),r.addBreakTokens?[new A(d.map,a.length),a,new A(d.break)]:[new A(d.map,a.length),a]):r.addBreakTokens===!0?[rt.emptyMap,new A(d.break)]:rt.emptyMap},Tagged(t,e,r,n){return[new A(d.tag,t.tag),ot(t.value,r,n)]}};se.Map=se.Object;function zn(t){return(e,r,n,o)=>{let i;try{i=t.call(e)}catch{throw new Error(`${Ae} unsupported type: ${r} (object only claims the tag via Symbol.toStringTag)`)}return ot(i,n,o)}}se.Number=zn(Number.prototype.valueOf);se.String=zn(String.prototype.valueOf);se.Boolean=zn(Boolean.prototype.valueOf);se.BigInt=zn(BigInt.prototype.valueOf);se.Buffer=se.Uint8Array;for(let t of"Uint8Clamped Uint16 Uint32 Int8 Int16 Int32 BigUint64 BigInt64 Float32 Float64".split(" "))se[`${t}Array`]=se.DataView;function ot(t,e={},r){let n=wi(t),o=e&&e.typeEncoders&&e.typeEncoders[n]||se[n];if(typeof o=="function"){let s=o(t,n,e,r);if(s!=null)return s}let i=se[n];if(!i)throw new Error(`${Ae} unsupported type: ${n}`);return i(t,n,e,r)}function Uh(t,e){let r=e.mapSorter;r&&t.sort((n,o)=>r(n,o,e))}var gc=!1;function ki(t,e,r){let n=Array.isArray(t[0])?t[0][0]:t[0],o=Array.isArray(e[0])?e[0][0]:e[0];if(n.type.major!==o.type.major)return n.type.compare(o.type);let i=n.type.major,s=Ut[i].compareTokens(n,o,r);if(s===0){if(i<=d.string.major)throw new Error(`${Ae} duplicate map key`);gc||(gc=!0,console.warn("WARNING: complex key types used, CBOR key sorting guarantees are gone"))}return s}function Nh(t,e){if(t[0]instanceof A&&e[0]instanceof A){let r=t[0],n=e[0];r._keyBytes||(r._keyBytes=wc(r.value)),n._keyBytes||(n._keyBytes=wc(n.value));let o=Wt(r._keyBytes,n._keyBytes);if(o===0)throw new Error(`${Ae} duplicate map key`);return o}throw new Error("rfc8949MapSorter: complex key types are not supported yet")}function wc(t){return Ic(t,Ut,Ac)}function Kt(t,e,r,n){if(Array.isArray(e))for(let o of e)Kt(t,o,r,n);else r[e.type.major](t,e,n)}var xc=d.uint.majorEncoded,bc=d.negint.majorEncoded,Ch=d.bytes.majorEncoded,vc=d.string.majorEncoded,Ec=d.array.majorEncoded,nt=d.map.majorEncoded,Dh=d.float.majorEncoded|Cn,Lh=d.float.majorEncoded|Dn,$h=d.float.majorEncoded|Ln,Mh=d.float.majorEncoded|$n,Oh=BigInt(-1),Rh=BigInt(1);function Ce(t,e,r){r<24?t.pushByte(e|Number(r)):q(t,e,r)}function Fh(t){return t.addBreakTokens!==!0}function kc(t,e){return t.length-e.length||(t<e?-1:t>e?1:0)}function Ph(t,e){return kc(t[0],e[0])}var zh=256,jh=16;function _c(t,e,r,n,o){let i=Fr(e);Ce(t,vc,i.length),Array.isArray(i)?t.pushArr(i):t.pushBytes(i),Hr(t,r,n,o)}function Hh(t,e,r,n,o){let i=r.length;for(let c=0;c<i;c++){let u=r[c];if(u.length>zh)return!1;for(let f=0;f<u.length;f++)if(u.charCodeAt(f)>127)return!1}if(i===0)return t.pushByte(nt),!0;o=Nt.createCheck(o,e);let s=n.ignoreUndefinedProperties,a=0;if(i<=jh){let c=new Array(i),u=new Array(i);for(let f=0;f<i;f++){let p=r[f],m=e[p];if(s&&m===void 0)continue;let _=a++;for(;_>0&&kc(c[_-1],p)>0;)c[_]=c[_-1],u[_]=u[_-1],_--;c[_]=p,u[_]=m}if(a===0)return t.pushByte(nt),!0;Ce(t,nt,a);for(let f=0;f<a;f++)_c(t,c[f],u[f],n,o)}else{let c=[];for(let u=0;u<i;u++){let f=r[u],p=e[f];s&&p===void 0||c.push([f,p])}if(c.sort(Ph),a=c.length,a===0)return t.pushByte(nt),!0;Ce(t,nt,a);for(let u=0;u<a;u++)_c(t,c[u][0],c[u][1],n,o)}return!0}function Vh(t,e,r,n,o,i){let s=r==="Map",a=s?e.keys():i||Object.keys(e),c=s?e.size:a.length;if(!c){t.pushByte(nt);return}o=Nt.createCheck(o,e);let u=!s&&n.ignoreUndefinedProperties,f=new Array(c),p=0;for(let m of a){let _=s?e.get(m):e[m];u&&_===void 0||(f[p++]=[ot(m,n,o),_])}if(p===0){t.pushByte(nt);return}p<c&&(f.length=p),f.sort((m,_)=>ki(m,_,n)),Ce(t,nt,p);for(let[m,_]of f)Kt(t,m,Ut,n),Hr(t,_,n,o)}function Hr(t,e,r,n){let o=wi(e),i=r.typeEncoders&&r.typeEncoders[o];if(i){let s=i(e,o,r,n);if(s!=null){Kt(t,s,Ut,r);return}}switch(o){case"null":t.pushByte($h);return;case"undefined":t.pushByte(Mh);return;case"boolean":t.pushByte(e?Lh:Dh);return;case"number":!Number.isInteger(e)||!Number.isSafeInteger(e)?jr(t,new A(d.float,e),r):e>=0?Ce(t,xc,e):Ce(t,bc,e*-1-1);return;case"bigint":e>=BigInt(0)?Ce(t,xc,e):Ce(t,bc,e*Oh-Rh);return;case"string":{let s=Fr(e);Ce(t,vc,s.length),Array.isArray(s)?t.pushArr(s):t.pushBytes(s);return}case"Uint8Array":Ce(t,Ch,e.length),t.pushBytes(e);return;case"Array":if(!e.length){t.pushByte(Ec);return}n=Nt.createCheck(n,e),Ce(t,Ec,e.length);for(let s of e)Hr(t,s,r,n);return;case"Object":case"Map":if(r.mapSorter===ki){let s=o==="Object"?Object.keys(e):void 0;if(s!==void 0&&!(r.typeEncoders&&r.typeEncoders.string)&&Hh(t,e,s,r,n))return;Vh(t,e,o,r,n,s)}else{let s=se.Object(e,o,r,n);Kt(t,s,Ut,r)}return;default:{let s=se[o];if(!s)throw new Error(`${Ae} unsupported type: ${o}`);let a=s(e,o,r,n);Kt(t,a,Ut,r)}}}function Ic(t,e,r,n){let o=n!==void 0,i=ot(t,r);if(!Array.isArray(i)&&r.quickEncodeToken){let a=r.quickEncodeToken(i);if(a){if(o){let u=new Bt(n);return u.pushBytes(a),u.toBytes()}return a}let c=e[i.type.major];if(c.encodedSize){let u=c.encodedSize(i,r);if(o){let m=new Bt(n);return c(m,i,r),m.toBytes()}let f=new Uint8Array(u),p=new Bt(f);if(c(p,i,r),p.cursor!==u)throw new Error(`Unexpected error: pre-calculated length for ${i} was wrong`);return f}}let s=o?new Bt(n):Pn?new Gt:Fn;return s.reset(),Kt(s,i,e,r),s.toBytes(!0)}function Ii(t,e){if(e=Object.assign({},Bh,e),Fh(e)){if(Pn){let r=new Gt;return Hr(r,t,e,void 0),r.toBytes()}Pn=!0;try{return Fn.reset(),Hr(Fn,t,e,void 0),Fn.toBytes(!0)}finally{Pn=!1}}return Ic(t,Ut,e)}var qh={strict:!1,allowIndefinite:!0,allowUndefined:!0,allowBigInt:!0},jn=class{constructor(e,r={}){this._pos=0,this.data=e,this.options=r}pos(){return this._pos}done(){return this._pos>=this.data.length}next(){let e=this.data[this._pos],r=Ne[e];if(r===void 0){let n=w[e];if(!n)throw e===void 0?new Error(`${k} not enough data`):new Error(`${k} 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}},it=Symbol.for("DONE"),st=Symbol.for("BREAK");function Gh(t,e,r){let n=[];for(let o=0;o<t.value;o++){let i=at(e,r);if(i===st){if(t.value===1/0)break;throw new Error(`${k} got unexpected break to lengthed array`)}if(i===it)throw new Error(`${k} found array but not enough entries (got ${o}, expected ${t.value})`);n[o]=i}return n}function Wh(t,e,r){let n=r.useMaps===!0,o=r.rejectDuplicateMapKeys===!0,i=n?void 0:{},s=n?new Map:void 0;for(let a=0;a<t.value;a++){let c=at(e,r);if(c===st){if(t.value===1/0)break;throw new Error(`${k} got unexpected break to lengthed map`)}if(c===it)throw new Error(`${k} found map but not enough entries (got ${a} [no key], expected ${t.value})`);if(!n&&typeof c!="string")throw new Error(`${k} non-string keys not supported (got ${typeof c})`);if(o&&(n&&s.has(c)||!n&&Object.hasOwn(i,c)))throw new Error(`${k} found repeat map key "${c}"`);let u=at(e,r);if(u===it)throw new Error(`${k} found map but not enough entries (got ${a} [no value], expected ${t.value})`);if(u===st)throw new Error(`${k} got unexpected break to map value`);n?s.set(c,u):c==="__proto__"?Object.defineProperty(i,c,{value:u,configurable:!0,enumerable:!0,writable:!0}):i[c]=u}return n?s:i}function*Jh(t,e,r){let n=t.value>1&&r.rejectDuplicateMapKeys===!0?new Set:void 0;for(let o=0;o<t.value;o++){let i=at(e,r);if(i===st){if(t.value===1/0)break;throw new Error(`${k} got unexpected break to lengthed map`)}if(i===it)throw new Error(`${k} found map but not enough entries (got ${o} [no key], expected ${t.value})`);if(n&&n.add(i).size!==o+1)throw new Error(`${k} found repeat map key`);let s=at(e,r);if(s===it)throw new Error(`${k} found map but not enough entries (got ${o} [no value], expected ${t.value})`);if(s===st)throw new Error(`${k} got unexpected break to map value`);yield[i,s]}}function Yh(t,e){let r=function(){if(r._called)throw new Error(`${k} tag decode() may only be called once`);r._called=!0;let n=at(t,e);if(n===it)throw new Error(`${k} tag content missing`);if(n===st)throw new Error(`${k} got unexpected break in tag content`);return n};return r.entries=function(){if(r._called)throw new Error(`${k} tag decode() may only be called once`);if(r._called=!0,t.done())throw new Error(`${k} tag content missing`);let n=t.next();if(!d.equals(n.type,d.map))throw new Error(`${k} entries() requires map content, got ${n.type.name}`);let o=[];for(let i of Jh(n,t,e))o.push(i);return o},r._called=!1,r}function at(t,e){if(t.done())return it;let r=t.next();if(d.equals(r.type,d.break))return st;if(r.type.terminal)return r.value;if(d.equals(r.type,d.array))return Gh(r,t,e);if(d.equals(r.type,d.map))return Wh(r,t,e);if(d.equals(r.type,d.tag)){if(e.tags&&typeof e.tags[r.value]=="function"){let n=Yh(t,e),o=e.tags[r.value](n);if(!n._called)throw new Error(`${k} tag decoder must call decode() or entries()`);return o}throw new Error(`${k} tag not supported (${r.value})`)}throw new Error("unsupported")}function Tc(t,e){if(!(t instanceof Uint8Array))throw new Error(`${k} data to decode must be a Uint8Array`);e=Object.assign({},qh,e);let r=Na(t),n=e.tokenizer||new jn(r,e),o=at(n,e);if(o===it)throw new Error(`${k} did not find any content to decode`);if(o===st)throw new Error(`${k} got unexpected break`);return[o,t.subarray(n.pos())]}function Ti(t,e){let[r,n]=Tc(t,e);if(n.length>0)throw new Error(`${k} too many terminals, data makes no sense`);return r}var Hn=class t{constructor(e,r){if(typeof e!="number"||!Number.isInteger(e)||e<0)throw new TypeError("Tagged: tag must be a non-negative integer");this.tag=e,this.value=r}static decoder(e){return r=>new t(e,r())}static preserve(...e){let r={};for(let n of e)r[n]=t.decoder(n);return r}};Object.defineProperty(Hn.prototype,Symbol.toStringTag,{value:"Tagged"});var Li={};ue(Li,{base32:()=>Zt,base32hex:()=>ap,base32hexpad:()=>up,base32hexpadupper:()=>fp,base32hexupper:()=>cp,base32pad:()=>ip,base32padupper:()=>sp,base32upper:()=>op,base32z:()=>lp});var Bw=new Uint8Array(0);function Bi(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 ke(t){if(t instanceof Uint8Array&&t.constructor.name==="Uint8Array")return Ct(t);if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.isView(t))return Ct(new Uint8Array(t.buffer,t.byteOffset,t.byteLength));throw new Error("Unknown type, must be binary type")}function Sc(t){let e=new Uint8Array(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}var Bc=4096;function Uc(t){let e=t.length;if(e<=Bc)return String.fromCharCode.apply(String,t);let r="",n=0;for(;n<e;)r+=String.fromCharCode.apply(String,t.subarray(n,n+=Bc));return r}function Kh(t){return t?.buffer instanceof ArrayBuffer}function Ct(t){return Kh(t)?t:t.slice()}function Qh(t,e,r){if(t.length>=255)throw new TypeError("Alphabet too long");for(var n=new Uint8Array(256),o=0;o<n.length;o++)n[o]=255;for(var i=0;i<t.length;i++){var s=t.charAt(i),a=s.charCodeAt(0);if(n[a]!==255)throw new TypeError(s+" is ambiguous");if(n[a]=i,r){var c=s.toLowerCase().charCodeAt(0),u=s.toUpperCase().charCodeAt(0);c!==a&&(n[c]=i),u!==a&&(n[u]=i)}}var f=t.length,p=t.charAt(0),m=Math.log(f)/Math.log(256),_=Math.log(256)/Math.log(f);function S(I){if(I instanceof Uint8Array||(ArrayBuffer.isView(I)?I=new Uint8Array(I.buffer,I.byteOffset,I.byteLength):Array.isArray(I)&&(I=Uint8Array.from(I))),!(I instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(I.length===0)return"";for(var O=0,P=0,M=0,z=I.length;M!==z&&I[M]===0;)M++,O++;for(var Q=(z-M)*_+1>>>0,Je=new Uint8Array(Q);M!==z;){for(var ie=I[M],Tt=0,Ye=Q-1;(ie!==0||Tt<P)&&Ye!==-1;Ye--,Tt++)ie+=256*Je[Ye]>>>0,Je[Ye]=ie%f>>>0,ie=ie/f>>>0;if(ie!==0)throw new Error("Non-zero carry");P=Tt,M++}for(var ce=Q-P;ce!==Q&&Je[ce]===0;)ce++;for(var Mr=p.repeat(O);ce<Q;++ce)Mr+=t.charAt(Je[ce]);return Mr}function T(I){if(typeof I!="string")throw new TypeError("Expected String");if(I.length===0)return new Uint8Array;var O=0;if(I[O]!==" "){for(var P=0,M=0;I[O]===p;)P++,O++;for(var z=(I.length-O)*m+1>>>0,Q=new Uint8Array(z);I[O];){var Je=I.charCodeAt(O);if(Je>255)return;var ie=n[Je];if(ie===255)return;for(var Tt=0,Ye=z-1;(ie!==0||Tt<M)&&Ye!==-1;Ye--,Tt++)ie+=f*Q[Ye]>>>0,Q[Ye]=ie%256>>>0,ie=ie/256>>>0;if(ie!==0)throw new Error("Non-zero carry");M=Tt,O++}if(I[O]!==" "){for(var ce=z-M;ce!==z&&Q[ce]===0;)ce++;for(var Mr=new Uint8Array(P+(z-ce)),oh=P;ce!==z;)Mr[oh++]=Q[ce++];return Mr}}}function v(I){var O=T(I);if(O)return O;throw new Error(`Non-${e} character`)}return{encode:S,decodeUnsafe:T,decode:v}}var Zh=Qh,ep=Zh,Nc=ep;var Ui=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")}},Ni=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 Cc(this,e)}},Ci=class{decoders;constructor(e){this.decoders=e}or(e){return Cc(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 Cc(t,e){return new Ci({...t.decoders??{[t.prefix]:t},...e.decoders??{[e.prefix]:e}})}var Di=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 Ui(e,r,n),this.decoder=new Ni(e,r,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function Qt({name:t,prefix:e,encode:r,decode:n}){return new Di(t,e,r,n)}function ct({name:t,prefix:e,alphabet:r,caseInsensitive:n=!1}){let{encode:o,decode:i}=Nc(r,t,n);return Qt({prefix:e,name:t,encode:o,decode:s=>ke(i(s))})}function tp(t,e,r,n){let o=t.length;for(;t[o-1]==="=";)--o;let i=new Uint8Array(o*r/8|0),s=0,a=0,c=0;for(let u=0;u<o;++u){let f=e[t[u]];if(f===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|f,s+=r,s>=8&&(s-=8,i[c++]=255&a>>s)}if(s>=r||(255&a<<8-s)!==0)throw new SyntaxError("Unexpected end of data");return i}function rp(t,e,r){let n=e[e.length-1]==="=",o=(1<<r)-1,i="",s=0,a=0;for(let c=0;c<t.length;++c)for(a=a<<8|t[c],s+=8;s>r;)s-=r,i+=e[o&a>>s];if(s!==0&&(i+=e[o&a<<r-s]),n)for(;(i.length*r&7)!==0;)i+="=";return i}function np(t,e){let r={};for(let n=0;n<t.length;++n)if(t[n]!=="="&&(r[t[n]]=n,e)){let o=t[n].toLowerCase(),i=t[n].toUpperCase();o!==t[n]&&(r[o]=n),i!==t[n]&&(r[i]=n)}return r}function j({name:t,prefix:e,bitsPerChar:r,alphabet:n,caseInsensitive:o=!1}){let i=np(n,o);return Qt({prefix:e,name:t,encode(s){return rp(s,n,r)},decode(s){return tp(s,i,r,t)}})}var Zt=j({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5,caseInsensitive:!0}),op=j({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5,caseInsensitive:!0}),ip=j({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5,caseInsensitive:!0}),sp=j({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5,caseInsensitive:!0}),ap=j({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5,caseInsensitive:!0}),cp=j({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5,caseInsensitive:!0}),up=j({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5,caseInsensitive:!0}),fp=j({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5,caseInsensitive:!0}),lp=j({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var $i={};ue($i,{base36:()=>Vr,base36upper:()=>dp});var Vr=ct({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz",caseInsensitive:!0}),dp=ct({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",caseInsensitive:!0});var Mi={};ue(Mi,{base58btc:()=>Oe,base58flickr:()=>hp});var Oe=ct({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),hp=ct({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var pp=$c,Dc=128,mp=127,yp=~mp,gp=Math.pow(2,31);function $c(t,e,r){e=e||[],r=r||0;for(var n=r;t>=gp;)e[r++]=t&255|Dc,t/=128;for(;t&yp;)e[r++]=t&255|Dc,t>>>=7;return e[r]=t|0,$c.bytes=r-n+1,e}var wp=Oi,xp=128,Lc=127;function Oi(t,n){var r=0,n=n||0,o=0,i=n,s,a=t.length;do{if(i>=a)throw Oi.bytes=0,new RangeError("Could not decode varint");s=t[i++],r+=o<28?(s&Lc)<<o:(s&Lc)*Math.pow(2,o),o+=7}while(s>=xp);return Oi.bytes=i-n,r}var bp=Math.pow(2,7),Ep=Math.pow(2,14),_p=Math.pow(2,21),Ap=Math.pow(2,28),vp=Math.pow(2,35),kp=Math.pow(2,42),Ip=Math.pow(2,49),Tp=Math.pow(2,56),Bp=Math.pow(2,63),Sp=function(t){return t<bp?1:t<Ep?2:t<_p?3:t<Ap?4:t<vp?5:t<kp?6:t<Ip?7:t<Tp?8:t<Bp?9:10},Up={encode:pp,decode:wp,encodingLength:Sp},Np=Up,qr=Np;function Gr(t,e=0){let r=qr.decode(t,e),n=qr.decode.bytes;if(n>9)throw new RangeError("Invalid varint: too long");if(n>1&&t[e+n-1]===0)throw new RangeError("Invalid varint: not minimally encoded");return[r,n]}function er(t,e,r=0){return qr.encode(t,e,r),e}function tr(t){return qr.encodingLength(t)}function nr(t,e){let r=e.byteLength,n=tr(t),o=n+tr(r),i=new Uint8Array(o+r);return er(t,i,0),er(r,i,n),i.set(e,o),new rr(t,r,e,i)}function or(t){let e=ke(t),[r,n]=Gr(e),[o,i]=Gr(e.subarray(n)),s=e.subarray(n+i);if(s.byteLength!==o)throw new Error("Incorrect length");return new rr(r,o,s,e)}function Mc(t,e){if(t===e)return!0;{let r=e;return t.code===r.code&&t.size===r.size&&r.bytes instanceof Uint8Array&&Bi(t.bytes,r.bytes)}}var rr=class{code;size;digest;bytes;constructor(e,r,n,o){this.code=e,this.size=r,this.digest=Ct(n),this.bytes=Ct(o)}};function Oc(t,e){let{bytes:r,version:n}=t;return n===0?Dp(r,Ri(t),e??Oe.encoder):Lp(r,Ri(t),e??Zt.encoder)}var Rc=new WeakMap;function Ri(t){let e=Rc.get(t);if(e==null){let r=new Map;return Rc.set(t,r),r}return e}var B=class t{code;version;multihash;bytes;"/";constructor(e,r,n,o){this.code=r,this.version=e,this.multihash=n,this.bytes=Ct(o),this["/"]=this.bytes}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:e,multihash:r}=this;if(e!==Wr)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==$p)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=nr(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&&Mc(e.multihash,n.multihash)}toString(e){return Oc(this,e)}toJSON(){return{"/":Oc(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??Fc(n,o,i.bytes))}else if(r[Mp]===!0){let{version:n,multihash:o,code:i}=r,s=or(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!==Wr)throw new Error(`Version 0 CID must use dag-pb (code: ${Wr}) block encoding`);return new t(e,r,n,n.bytes)}case 1:{let o=Fc(e,r,n.bytes);return new t(e,r,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return t.create(0,Wr,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=ke(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 rr(r.multihashCode,r.digestSize,i,o);return[r.version===0?t.createV0(s):t.createV1(r.codec,s),e.subarray(r.size)]}static inspectBytes(e){let r=0,n=()=>{let[p,m]=Gr(e.subarray(r));return r+=m,p},o=n(),i=Wr;if(o===18)o=0,r=0;else if(o===1)i=n();else throw o===0?new RangeError("Invalid CID version, v0 is always implicit"):new RangeError(`Invalid CID version ${o}`);let s=r,a=n(),c=n(),u=r+c,f=u-s;return{version:o,codec:i,multihashCode:a,digestSize:c,multihashSize:f,size:u}}static parse(e,r){let[n,o]=Cp(e,r),i=t.decode(o);if(i.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Ri(i).set(n,e),i}};function Cp(t,e){switch(t[0]){case"Q":{let r=e??Oe;return[Oe.prefix,r.decode(`${Oe.prefix}${t}`)]}case Oe.prefix:{let r=e??Oe;return[Oe.prefix,r.decode(t)]}case Zt.prefix:{let r=e??Zt;return[Zt.prefix,r.decode(t)]}case Vr.prefix:{let r=e??Vr;return[Vr.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 Dp(t,e,r){let{prefix:n}=r;if(n!==Oe.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 Lp(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 Wr=112,$p=18;function Fc(t,e,r){let n=tr(t),o=n+tr(e),i=new Uint8Array(o+r.byteLength);return er(t,i,0),er(e,i,n),i.set(r,o),i}var Mp=Symbol.for("@ipld/js-cid/CID");var Pc=42;function Op(t){return t instanceof ArrayBuffer?new Uint8Array(t,0,t.byteLength):t}function Rp(t){if(t.asCID!==t&&t["/"]!==t.bytes)return null;let e=B.asCID(t);if(!e)return null;let r=new Uint8Array(e.bytes.byteLength+1);return r.set(e.bytes,1),[new A(d.tag,Pc),new A(d.bytes,r)]}function Fp(){throw new Error("`undefined` is not supported by the IPLD Data Model and cannot be encoded")}function Pp(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 zp(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 Fi={float64:!0,typeEncoders:{Map:zp,Object:Rp,undefined:Fp,number:Pp}},Gw={...Fi,typeEncoders:{...Fi.typeEncoders}};function jp(t){let e=t();if(e[0]!==0)throw new Error("Invalid CID for CBOR tag 42; expected leading 0x00");return B.decode(e.subarray(1))}var Pi={allowIndefinite:!1,coerceUndefinedToNull:!0,allowNaN:!1,allowInfinity:!1,allowBigInt:!0,strict:!0,useMaps:!1,rejectDuplicateMapKeys:!0,tags:{[Pc]:jp}},Ww={...Pi,tags:{...Pi.tags}};var zi=t=>Ii(t,Fi),ji=t=>Ti(Op(t),Pi);var Hi={};ue(Hi,{identity:()=>ir});var zc=0,Vp="identity",jc=ke;function qp(t,e){if(e?.truncate!=null&&e.truncate!==t.byteLength){if(e.truncate<0||e.truncate>t.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${t.byteLength}`);t=t.subarray(0,e.truncate)}return nr(zc,jc(t))}var ir={code:zc,name:Vp,encode:jc,digest:qp};var qi={};ue(qi,{sha256:()=>Gc,sha512:()=>Wp});var Gp=20;function Dt({name:t,code:e,encode:r,minDigestLength:n,maxDigestLength:o}){return new Vi(t,e,r,n,o)}var Vi=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,r,n,o,i){this.name=e,this.code=r,this.encode=n,this.minDigestLength=o??Gp,this.maxDigestLength=i}digest(e,r){if(r?.truncate!=null){if(r.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&r.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(e instanceof Uint8Array){let n=this.encode(e);return n instanceof Uint8Array?Hc(n,this.code,r?.truncate):n.then(o=>Hc(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function Hc(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 nr(e,t)}function qc(t){return async e=>new Uint8Array(await crypto.subtle.digest(t,e))}var Gc=Dt({name:"sha2-256",code:18,encode:qc("SHA-256")}),Wp=Dt({name:"sha2-512",code:19,encode:qc("SHA-512")});var Ji=Or(qn(),1);function ru(t,e,r){if(e===void 0)return r;if(typeof e!="number"||!(Number.isSafeInteger(e)||e===1/0))throw new TypeError(`${t} must be a non-negative integer or Infinity, got ${String(e)}`);if(e<0)throw new RangeError(`${t} must be a non-negative integer or Infinity, got ${e}`);return e}function Lt(t){return{maxAllowedHeaderSize:ru("maxAllowedHeaderSize",t?.maxAllowedHeaderSize,33554432),maxAllowedSectionSize:ru("maxAllowedSectionSize",t?.maxAllowedSectionSize,8388608)}}function sr(t,e){if(t>e)throw new RangeError(`CAR header of length ${t} exceeds maxAllowedHeaderSize of ${e}`)}function Jr(t,e){if(t>e)throw new RangeError(`CAR section of length ${t} exceeds maxAllowedSectionSize of ${e}`)}function Gn(t){if(t>33554432)throw new RangeError(`CID digest of length ${t} exceeds maximum of 33554432`)}var Yi=40;function Xi(t,e){if(!t.length)throw new Error("Unexpected end of data");let r=Ji.default.decode(t);return e.seek(Ji.default.decode.bytes),r}function Ki(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 ft={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},Yr={"CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)":ft.Link,"CarV1HeaderOrV2Pragma > roots (anon)":t=>{if(ft.List(t)!==void 0){for(let e=0;e<t.length;e++){let r=t[e];if(r=Yr["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=Yr["CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)"](i),i===void 0)return;n.push(i)}return n}}return t}},Int:ft.Int,CarV1HeaderOrV2Pragma:t=>{if(ft.Map(t)===void 0)return;let e=Object.entries(t),r=t,n=1;for(let o=0;o<e.length;o++){let[i,s]=e[o];switch(i){case"roots":{let a=Yr["CarV1HeaderOrV2Pragma > roots (anon)"](t[i]);if(a===void 0)return;if(a!==s||r!==t){if(r===t){r={};for(let c=0;c<o;c++)r[e[c][0]]=e[c][1]}r.roots=a}}break;case"version":{n--;let a=Yr.Int(t[i]);if(a===void 0)return;if(a!==s||r!==t){if(r===t){r={};for(let c=0;c<o;c++)r[e[c][0]]=e[c][1]}r.version=a}}break;default:return}}if(!(n>0))return r}},Xr={"CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)":ft.Link,"CarV1HeaderOrV2Pragma > roots (anon)":t=>{if(ft.List(t)!==void 0){for(let e=0;e<t.length;e++){let r=t[e];if(r=Xr["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=Xr["CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)"](i),i===void 0)return;n.push(i)}return n}}return t}},Int:ft.Int,CarV1HeaderOrV2Pragma:t=>{if(ft.Map(t)===void 0)return;let e=Object.entries(t),r=t,n=1;for(let o=0;o<e.length;o++){let[i,s]=e[o];switch(i){case"roots":{let a=Xr["CarV1HeaderOrV2Pragma > roots (anon)"](s);if(a===void 0)return;if(a!==s||r!==t){if(r===t){r={};for(let c=0;c<o;c++)r[e[c][0]]=e[c][1]}r.roots=a}}break;case"version":{n--;let a=Xr.Int(s);if(a===void 0)return;if(a!==s||r!==t){if(r===t){r={};for(let c=0;c<o;c++)r[e[c][0]]=e[c][1]}r.version=a}}break;default:return}}if(!(n>0))return r}},Qi={toTyped:Yr.CarV1HeaderOrV2Pragma,toRepresentation:Xr.CarV1HeaderOrV2Pragma};var lm=["Object","Uint8Array","RegExp","Date","Error","Map","Set","WeakMap","WeakSet","ArrayBuffer","SharedArrayBuffer","DataView","Promise","URL","HTMLElement","Int8Array","Uint8ClampedArray","Int16Array","Uint16Array","Int32Array","Uint32Array","Float32Array","Float64Array","BigInt64Array","BigUint64Array","Tagged","Number","String","Boolean","BigInt","Symbol"];function ou(t){if(t===null)return"null";if(t===void 0)return"undefined";if(t===!0||t===!1)return"boolean";let e=typeof t;if(e==="string"||e==="number"||e==="bigint"||e==="symbol")return e;if(e==="function")return"Function";if(Array.isArray(t))return"Array";if(t instanceof Uint8Array)return"Uint8Array";if(t.constructor===Object)return"Object";let r=dm(t);return r||"Object"}function dm(t){let e=Object.prototype.toString.call(t).slice(8,-1);if(lm.includes(e))return e}var h=class{constructor(e,r,n){this.major=e,this.majorEncoded=e<<5,this.name=r,this.terminal=n}toString(){return`Type[${this.major}].${this.name}`}compare(e){return this.major<e.major?-1:this.major>e.major?1:0}static equals(e,r){return e===r||e.major===r.major&&e.name===r.name}};h.uint=new h(0,"uint",!0);h.negint=new h(1,"negint",!0);h.bytes=new h(2,"bytes",!0);h.string=new h(3,"string",!0);h.array=new h(4,"array",!1);h.map=new h(5,"map",!1);h.tag=new h(6,"tag",!1);h.float=new h(7,"float",!0);h.false=new h(7,"false",!0);h.true=new h(7,"true",!0);h.null=new h(7,"null",!0);h.undefined=new h(7,"undefined",!0);h.break=new h(7,"break",!0);var E=class{constructor(e,r,n){this.type=e,this.value=r,this.encodedLength=n,this.encodedBytes=void 0,this.byteValue=void 0}toString(){return`Token[${this.type}].${this.value}`}};var Kr=class{constructor(){this.home=new Uint8Array(2048),this.buf=this.home,this.pos=0,this.start=0,this.segs=[],this.segLen=0}reset(){this.buf.length>this.home.length&&this.buf.length<=65536&&(this.home=this.buf),this.buf=this.home,this.pos=0,this.start=0,this.segs.length>0&&(this.segs=[],this.segLen=0)}grow(e){let r=this.pos-this.start;if(this.buf.length>=262144)r>0&&(this.segs.push(this.buf.subarray(this.start,this.pos)),this.segLen+=r),this.buf=new Uint8Array(e>262144?e:262144),this.pos=0,this.start=0;else{let n=this.buf.length*2;for(;n<r+e;)n*=2;let o=new Uint8Array(n);o.set(this.buf.subarray(this.start,this.pos)),this.buf=o,this.pos=r,this.start=0}}pushByte(e){this.pos>=this.buf.length&&this.grow(1),this.buf[this.pos++]=e}pushArr(e){let r=e.length;this.pos+r>this.buf.length&&this.grow(r);let n=this.buf,o=this.pos;for(let i=0;i<r;i++)n[o++]=e[i];this.pos=o}pushBytes(e){let r=e.length;if(r>=1024){this.pos>this.start&&(this.segs.push(this.buf.subarray(this.start,this.pos)),this.segLen+=this.pos-this.start),this.segs.push(e),this.segLen+=r,this.start=this.pos;return}this.pos+r>this.buf.length&&this.grow(r);let n=this.buf,o=this.pos;if(r<16)for(let i=0;i<r;i++)n[o++]=e[i];else n.set(e,o),o+=r;this.pos=o}push(e){Array.isArray(e)?this.pushArr(e):this.pushBytes(e)}toBytes(e=!1){let r;if(this.segs.length===0)r=new Uint8Array(this.buf.subarray(this.start,this.pos));else{r=new Uint8Array(this.segLen+(this.pos-this.start));let n=0;for(let o of this.segs)r.set(o,n),n+=o.length;r.set(this.buf.subarray(this.start,this.pos),n)}return e&&this.reset(),r}},$t=class{constructor(e){this.dest=e,this.cursor=0}reset(){this.cursor=0}pushByte(e){if(this.cursor>=this.dest.length)throw new Error("write out of bounds, destination buffer is too small");this.dest[this.cursor++]=e}push(e){if(this.cursor+e.length>this.dest.length)throw new Error("write out of bounds, destination buffer is too small");this.dest.set(e,this.cursor),this.cursor+=e.length}pushArr(e){let r=e.length;if(this.cursor+r>this.dest.length)throw new Error("write out of bounds, destination buffer is too small");let n=this.dest,o=this.cursor;for(let i=0;i<r;i++)n[o++]=e[i];this.cursor=o}pushBytes(e){this.push(e)}toBytes(e=!1){let r=this.dest.subarray(0,this.cursor);return e&&this.reset(),r}};var N="CBOR decode error:",Re="CBOR encode error:",Qr=[];Qr[23]=1;Qr[24]=2;Qr[25]=3;Qr[26]=5;Qr[27]=9;function Ke(t,e,r){if(t.length-e<r)throw new Error(`${N} not enough data for type`)}var V=[24,256,65536,4294967296,BigInt("18446744073709551616")];function pe(t,e,r){Ke(t,e,1);let n=t[e];if(r.strict===!0&&n<V[0])throw new Error(`${N} integer encoded in more bytes than necessary (strict decode)`);return n}function me(t,e,r){Ke(t,e,2);let n=t[e]<<8|t[e+1];if(r.strict===!0&&n<V[1])throw new Error(`${N} integer encoded in more bytes than necessary (strict decode)`);return n}function ye(t,e,r){Ke(t,e,4);let n=t[e]*16777216+(t[e+1]<<16)+(t[e+2]<<8)+t[e+3];if(r.strict===!0&&n<V[2])throw new Error(`${N} integer encoded in more bytes than necessary (strict decode)`);return n}function ge(t,e,r){Ke(t,e,8);let n=t[e]*16777216+(t[e+1]<<16)+(t[e+2]<<8)+t[e+3],o=t[e+4]*16777216+(t[e+5]<<16)+(t[e+6]<<8)+t[e+7],i=(BigInt(n)<<BigInt(32))+BigInt(o);if(r.strict===!0&&i<V[3])throw new Error(`${N} integer encoded in more bytes than necessary (strict decode)`);if(i<=Number.MAX_SAFE_INTEGER)return Number(i);if(r.allowBigInt===!0)return i;throw new Error(`${N} integers outside of the safe integer range are not supported`)}function iu(t,e,r,n){return new E(h.uint,pe(t,e+1,n),2)}function su(t,e,r,n){return new E(h.uint,me(t,e+1,n),3)}function au(t,e,r,n){return new E(h.uint,ye(t,e+1,n),5)}function cu(t,e,r,n){return new E(h.uint,ge(t,e+1,n),9)}function Fe(t,e){return Y(t,0,e.value)}function Y(t,e,r){if(r<V[0]){let n=Number(r);t.pushByte(e|n)}else if(r<V[1]){let n=Number(r);t.pushArr([e|24,n])}else if(r<V[2]){let n=Number(r);t.pushArr([e|25,n>>>8,n&255])}else if(r<V[3]){let n=Number(r);t.pushArr([e|26,n>>>24&255,n>>>16&255,n>>>8&255,n&255])}else{let n=BigInt(r);if(n<V[4]){let o=[e|27,0,0,0,0,0,0,0],i=Number(n&BigInt(4294967295)),s=Number(n>>BigInt(32)&BigInt(4294967295));o[8]=i&255,i=i>>8,o[7]=i&255,i=i>>8,o[6]=i&255,i=i>>8,o[5]=i&255,o[4]=s&255,s=s>>8,o[3]=s&255,s=s>>8,o[2]=s&255,s=s>>8,o[1]=s&255,t.pushArr(o)}else throw new Error(`${Re} encountered BigInt larger than allowable range`)}}Fe.encodedSize=function(e){return Y.encodedSize(e.value)};Y.encodedSize=function(e){if(e<V[0])return 1;if(e<V[1])return 2;if(e<V[2])return 3;if(e<V[3])return 5;if(e>=V[4])throw new Error(`${Re} encountered BigInt larger than allowable range`);return 9};Fe.compareTokens=function(e,r){return e.value<r.value?-1:e.value>r.value?1:0};function uu(t,e,r,n){return new E(h.negint,-1-pe(t,e+1,n),2)}function fu(t,e,r,n){return new E(h.negint,-1-me(t,e+1,n),3)}function lu(t,e,r,n){return new E(h.negint,-1-ye(t,e+1,n),5)}var Zi=BigInt(-1),du=BigInt(1);function hu(t,e,r,n){let o=ge(t,e+1,n);if(typeof o!="bigint"){let i=-1-o;if(i>=Number.MIN_SAFE_INTEGER)return new E(h.negint,i,9)}if(n.allowBigInt!==!0)throw new Error(`${N} integers outside of the safe integer range are not supported`);return new E(h.negint,Zi-BigInt(o),9)}function Jn(t,e){let r=e.value,n=typeof r=="bigint"?r*Zi-du:r*-1-1;Y(t,e.type.majorEncoded,n)}Jn.encodedSize=function(e){let r=e.value,n=typeof r=="bigint"?r*Zi-du:r*-1-1;if(n<V[0])return 1;if(n<V[1])return 2;if(n<V[2])return 3;if(n<V[3])return 5;if(n>=V[4])throw new Error(`${Re} encountered BigInt larger than allowable range`);return 9};Jn.compareTokens=function(e,r){return e.value<r.value?1:e.value>r.value?-1:0};var yu=globalThis.process&&!globalThis.process.browser&&globalThis.Buffer&&typeof globalThis.Buffer.isBuffer=="function",pm=new TextEncoder;function pu(t){return yu&&globalThis.Buffer.isBuffer(t)}var mm=24,ym=200,es=yu?t=>t.length>=mm?globalThis.Buffer.from(t):mu(t):t=>t.length>=ym?pm.encode(t):mu(t),Pe=t=>Uint8Array.from(t);function ar(t,e){if(pu(t)&&pu(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 mu(t){let e=[],r=0;for(let n=0;n<t.length;n++){let o=t.charCodeAt(n);o<128?e[r++]=o:o<2048?(e[r++]=o>>6|192,e[r++]=o&63|128):(o&64512)===55296&&n+1<t.length&&(t.charCodeAt(n+1)&64512)===56320?(o=65536+((o&1023)<<10)+(t.charCodeAt(++n)&1023),e[r++]=o>>18|240,e[r++]=o>>12&63|128,e[r++]=o>>6&63|128,e[r++]=o&63|128):(o>=55296&&o<=57343&&(o=65533),e[r++]=o>>12|224,e[r++]=o>>6&63|128,e[r++]=o&63|128)}return e}function Zr(t,e,r,n){Ke(t,e,r+n);let o=t.slice(e+r,e+r+n);return new E(h.bytes,o,r+n)}function gu(t,e,r,n){return Zr(t,e,1,r)}function wu(t,e,r,n){return Zr(t,e,2,pe(t,e+1,n))}function xu(t,e,r,n){return Zr(t,e,3,me(t,e+1,n))}function bu(t,e,r,n){return Zr(t,e,5,ye(t,e+1,n))}function Eu(t,e,r,n){let o=ge(t,e+1,n);if(typeof o=="bigint")throw new Error(`${N} 64-bit integer bytes lengths not supported`);return Zr(t,e,9,o)}function Yn(t){return t.encodedBytes===void 0&&(t.encodedBytes=h.equals(t.type,h.string)?es(t.value):t.value),t.encodedBytes}function cr(t,e){let r=Yn(e);Y(t,e.type.majorEncoded,r.length),t.push(r)}cr.encodedSize=function(e){let r=Yn(e);return Y.encodedSize(r.length)+r.length};cr.compareTokens=function(e,r){return gm(Yn(e),Yn(r))};function gm(t,e){return t.length<e.length?-1:t.length>e.length?1:ar(t,e)}var _u=new TextDecoder("utf-8",{ignoreBOM:!0}),xm=new TextDecoder("utf-8",{ignoreBOM:!0,fatal:!0}),bm=32;function Em(t,e,r,n){if(r-e<bm){let i="";for(let s=e;s<r;s++){let a=t[s];if(a&128)return n.rejectInvalidUtf8===!0?Au(t,e,r):_u.decode(t.subarray(e,r));i+=String.fromCharCode(a)}return i}return n.rejectInvalidUtf8===!0?Au(t,e,r):_u.decode(t.subarray(e,r))}function Au(t,e,r){try{return xm.decode(t.subarray(e,r))}catch{throw new Error(`${N} invalid UTF-8 in text string`)}}function en(t,e,r,n,o){let i=r+n;Ke(t,e,i);let s=new E(h.string,Em(t,e+r,e+i,o),i);return o.retainStringBytes===!0&&(s.byteValue=t.slice(e+r,e+i)),s}function vu(t,e,r,n){return en(t,e,1,r,n)}function ku(t,e,r,n){return en(t,e,2,pe(t,e+1,n),n)}function Iu(t,e,r,n){return en(t,e,3,me(t,e+1,n),n)}function Tu(t,e,r,n){return en(t,e,5,ye(t,e+1,n),n)}function Bu(t,e,r,n){let o=ge(t,e+1,n);if(typeof o=="bigint")throw new Error(`${N} 64-bit integer string lengths not supported`);return en(t,e,9,o,n)}var Su=cr;function ur(t,e,r,n){return new E(h.array,n,r)}function Uu(t,e,r,n){return ur(t,e,1,r)}function Nu(t,e,r,n){return ur(t,e,2,pe(t,e+1,n))}function Cu(t,e,r,n){return ur(t,e,3,me(t,e+1,n))}function Du(t,e,r,n){return ur(t,e,5,ye(t,e+1,n))}function Lu(t,e,r,n){let o=ge(t,e+1,n);if(typeof o=="bigint")throw new Error(`${N} 64-bit integer array lengths not supported`);return ur(t,e,9,o)}function $u(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${N} indefinite length items not allowed`);return ur(t,e,1,1/0)}function Xn(t,e){Y(t,h.array.majorEncoded,e.value)}Xn.compareTokens=Fe.compareTokens;Xn.encodedSize=function(e){return Y.encodedSize(e.value)};function fr(t,e,r,n){return new E(h.map,n,r)}function Mu(t,e,r,n){return fr(t,e,1,r)}function Ou(t,e,r,n){return fr(t,e,2,pe(t,e+1,n))}function Ru(t,e,r,n){return fr(t,e,3,me(t,e+1,n))}function Fu(t,e,r,n){return fr(t,e,5,ye(t,e+1,n))}function Pu(t,e,r,n){let o=ge(t,e+1,n);if(typeof o=="bigint")throw new Error(`${N} 64-bit integer map lengths not supported`);return fr(t,e,9,o)}function zu(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${N} indefinite length items not allowed`);return fr(t,e,1,1/0)}function Kn(t,e){Y(t,h.map.majorEncoded,e.value)}Kn.compareTokens=Fe.compareTokens;Kn.encodedSize=function(e){return Y.encodedSize(e.value)};function ju(t,e,r,n){return new E(h.tag,r,1)}function Hu(t,e,r,n){return new E(h.tag,pe(t,e+1,n),2)}function Vu(t,e,r,n){return new E(h.tag,me(t,e+1,n),3)}function qu(t,e,r,n){return new E(h.tag,ye(t,e+1,n),5)}function Gu(t,e,r,n){return new E(h.tag,ge(t,e+1,n),9)}function Qn(t,e){Y(t,h.tag.majorEncoded,e.value)}Qn.compareTokens=Fe.compareTokens;Qn.encodedSize=function(e){return Y.encodedSize(e.value)};var Zn=20,eo=21,to=22,ro=23;function Ju(t,e,r,n){if(n.allowUndefined===!1)throw new Error(`${N} undefined values are not supported`);return n.coerceUndefinedToNull===!0?new E(h.null,null,1):new E(h.undefined,void 0,1)}function Yu(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${N} indefinite length items not allowed`);return new E(h.break,void 0,1)}function ts(t,e,r){if(r){if(r.allowNaN===!1&&Number.isNaN(t))throw new Error(`${N} NaN values are not supported`);if(r.allowInfinity===!1&&(t===1/0||t===-1/0))throw new Error(`${N} Infinity values are not supported`)}return new E(h.float,t,e)}function Xu(t,e,r,n){return ts(oo(t,e+1),3,n)}function Ku(t,e,r,n){return ts(io(t,e+1),5,n)}function Qu(t,e,r,n){return ts(tf(t,e+1),9,n)}function no(t,e,r){let n=e.value;if(n===!1)t.pushByte(h.float.majorEncoded|Zn);else if(n===!0)t.pushByte(h.float.majorEncoded|eo);else if(n===null)t.pushByte(h.float.majorEncoded|to);else if(n===void 0)h.equals(e.type,h.break)||t.pushByte(h.float.majorEncoded|ro);else{let o,i=!1;(!r||r.float64!==!0)&&(rs(n),o=oo(W,1),n===o||Number.isNaN(n)?(W[0]=249,t.pushBytes(W.slice(0,3)),i=!0):(ns(n),o=io(W,1),n===o&&(W[0]=250,t.pushBytes(W.slice(0,5)),i=!0))),i||(ef(n),o=tf(W,1),W[0]=251,t.pushBytes(W.slice(0,9)))}}no.encodedSize=function(e,r){let n=e.value;if(n===void 0)return h.equals(e.type,h.break)?0:1;if(n===!1||n===!0||n===null)return 1;if(!r||r.float64!==!0){rs(n);let o=oo(W,1);if(n===o||Number.isNaN(n))return 3;if(ns(n),o=io(W,1),n===o)return 5}return 9};var Zu=new ArrayBuffer(9),Ie=new DataView(Zu,1),W=new Uint8Array(Zu,0);function rs(t){if(t===1/0)Ie.setUint16(0,31744,!1);else if(t===-1/0)Ie.setUint16(0,64512,!1);else if(Number.isNaN(t))Ie.setUint16(0,32256,!1);else{Ie.setFloat32(0,t);let e=Ie.getUint32(0),r=(e&2139095040)>>23,n=e&8388607;if(r===255)Ie.setUint16(0,31744,!1);else if(r===0)Ie.setUint16(0,(e&2147483648)>>16|n>>13,!1);else{let o=r-127;o<-24?Ie.setUint16(0,0):o<-14?Ie.setUint16(0,(e&2147483648)>>16|(8388608|n)>>-1-o,!1):Ie.setUint16(0,(e&2147483648)>>16|o+15<<10|n>>13,!1)}}}function oo(t,e){if(t.length-e<2)throw new Error(`${N} not enough data for float16`);let r=(t[e]<<8)+t[e+1];if(r===31744)return 1/0;if(r===64512)return-1/0;if(r===32256)return NaN;let n=r>>10&31,o=r&1023,i;return n===0?i=o*2**-24:n!==31?i=(o+1024)*2**(n-25):i=o===0?1/0:NaN,r&32768?-i:i}function ns(t){Ie.setFloat32(0,t,!1)}function io(t,e){if(t.length-e<4)throw new Error(`${N} not enough data for float32`);let r=(t.byteOffset||0)+e;return new DataView(t.buffer,r,4).getFloat32(0,!1)}function ef(t){Ie.setFloat64(0,t,!1)}function tf(t,e){if(t.length-e<8)throw new Error(`${N} not enough data for float64`);let r=(t.byteOffset||0)+e;return new DataView(t.buffer,r,8).getFloat64(0,!1)}function Im(t,e){let r=t.value;if(r===!1)return Uint8Array.of(h.float.majorEncoded|Zn);if(r===!0)return Uint8Array.of(h.float.majorEncoded|eo);if(r===null)return Uint8Array.of(h.float.majorEncoded|to);if(r===void 0)return Uint8Array.of(h.float.majorEncoded|ro);if(!e){if(rs(r),r===oo(W,1)||Number.isNaN(r))return W[0]=249,W.slice(0,3);if(ns(r),r===io(W,1))return W[0]=250,W.slice(0,5)}return ef(r),W[0]=251,W.slice(0,9)}function Wu(t,e){let r=t,n=e?.float64===!0,o=n?r._keyBytesFloat64:r._keyBytes;if(o!==void 0)return o;let i=Im(t,n);return n?r._keyBytesFloat64=i:r._keyBytes=i,i}no.compareTokens=function(e,r,n){let o=Wu(e,n),i=Wu(r,n);return o.length!==i.length?o.length<i.length?-1:1:ar(o,i)};function C(t,e,r){throw new Error(`${N} encountered invalid minor (${r}) for major ${t[e]>>>5}`)}function so(t){return()=>{throw new Error(`${N} ${t}`)}}var b=[];for(let t=0;t<=23;t++)b[t]=C;b[24]=iu;b[25]=su;b[26]=au;b[27]=cu;b[28]=C;b[29]=C;b[30]=C;b[31]=C;for(let t=32;t<=55;t++)b[t]=C;b[56]=uu;b[57]=fu;b[58]=lu;b[59]=hu;b[60]=C;b[61]=C;b[62]=C;b[63]=C;for(let t=64;t<=87;t++)b[t]=gu;b[88]=wu;b[89]=xu;b[90]=bu;b[91]=Eu;b[92]=C;b[93]=C;b[94]=C;b[95]=so("indefinite length bytes/strings are not supported");for(let t=96;t<=119;t++)b[t]=vu;b[120]=ku;b[121]=Iu;b[122]=Tu;b[123]=Bu;b[124]=C;b[125]=C;b[126]=C;b[127]=so("indefinite length bytes/strings are not supported");for(let t=128;t<=151;t++)b[t]=Uu;b[152]=Nu;b[153]=Cu;b[154]=Du;b[155]=Lu;b[156]=C;b[157]=C;b[158]=C;b[159]=$u;for(let t=160;t<=183;t++)b[t]=Mu;b[184]=Ou;b[185]=Ru;b[186]=Fu;b[187]=Pu;b[188]=C;b[189]=C;b[190]=C;b[191]=zu;for(let t=192;t<=215;t++)b[t]=ju;b[216]=Hu;b[217]=Vu;b[218]=qu;b[219]=Gu;b[220]=C;b[221]=C;b[222]=C;b[223]=C;for(let t=224;t<=243;t++)b[t]=so("simple values are not supported");b[244]=C;b[245]=C;b[246]=C;b[247]=Ju;b[248]=so("simple values are not supported");b[249]=Xu;b[250]=Ku;b[251]=Qu;b[252]=C;b[253]=C;b[254]=C;b[255]=Yu;var ze=[];for(let t=0;t<24;t++)ze[t]=new E(h.uint,t,1);for(let t=-1;t>=-24;t--)ze[31-t]=new E(h.negint,t,1);ze[64]=new E(h.bytes,new Uint8Array(0),1);ze[96]=new E(h.string,"",1);ze[128]=new E(h.array,0,1);ze[160]=new E(h.map,0,1);ze[244]=new E(h.false,!1,1);ze[245]=new E(h.true,!0,1);ze[246]=new E(h.null,null,1);function os(t){switch(t.type){case h.false:return Pe([244]);case h.true:return Pe([245]);case h.null:return Pe([246]);case h.bytes:return t.value.length?void 0:Pe([64]);case h.string:return t.value===""?Pe([96]):void 0;case h.array:return t.value===0?Pe([128]):void 0;case h.map:return t.value===0?Pe([160]):void 0;case h.uint:return t.value<24?Pe([Number(t.value)]):void 0;case h.negint:if(t.value>=-24)return Pe([31-Number(t.value)])}}var nf=Object.freeze({mapSorter:Cm,quickEncodeToken:os});function is(){let t=[];return t[h.uint.major]=Fe,t[h.negint.major]=Jn,t[h.bytes.major]=cr,t[h.string.major]=Su,t[h.array.major]=Xn,t[h.map.major]=Kn,t[h.tag.major]=Qn,t[h.float.major]=no,t}var Bm=is(),Sm=new Kr,Um=!1,ao=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(`${Re} object contains circular references`);return new t(r,e)}},lt={null:new E(h.null,null),undefined:new E(h.undefined,void 0),true:new E(h.true,!0),false:new E(h.false,!1),emptyArray:new E(h.array,0),emptyMap:new E(h.map,0)},Te={number(t,e,r,n){return!Number.isInteger(t)||!Number.isSafeInteger(t)?new E(h.float,t):t>=0?new E(h.uint,t):new E(h.negint,t)},bigint(t,e,r,n){return t>=BigInt(0)?new E(h.uint,t):new E(h.negint,t)},Uint8Array(t,e,r,n){return new E(h.bytes,t)},string(t,e,r,n){return new E(h.string,t)},boolean(t,e,r,n){return t?lt.true:lt.false},null(t,e,r,n){return lt.null},undefined(t,e,r,n){return lt.undefined},ArrayBuffer(t,e,r,n){return new E(h.bytes,new Uint8Array(t))},DataView(t,e,r,n){return new E(h.bytes,new Uint8Array(t.buffer,t.byteOffset,t.byteLength))},Array(t,e,r,n){if(!t.length)return r.addBreakTokens===!0?[lt.emptyArray,new E(h.break)]:lt.emptyArray;n=ao.createCheck(n,t);let o=[],i=0;for(let s of t)o[i++]=dt(s,r,n);return r.addBreakTokens?[new E(h.array,t.length),o,new E(h.break)]:[new E(h.array,t.length),o]},Object(t,e,r,n){let o=e!=="Object",i=o?t.keys():Object.keys(t),s=o?t.size:i.length,a;if(s){a=new Array(s),n=ao.createCheck(n,t);let c=!o&&r.ignoreUndefinedProperties,u=0;for(let f of i){let p=o?t.get(f):t[f];c&&p===void 0||(a[u++]=[dt(f,r,n),dt(p,r,n)])}u<s&&(a.length=u)}return a?.length?(Nm(a,r),r.addBreakTokens?[new E(h.map,a.length),a,new E(h.break)]:[new E(h.map,a.length),a]):r.addBreakTokens===!0?[lt.emptyMap,new E(h.break)]:lt.emptyMap},Tagged(t,e,r,n){return[new E(h.tag,t.tag),dt(t.value,r,n)]}};Te.Map=Te.Object;function co(t){return(e,r,n,o)=>{let i;try{i=t.call(e)}catch{throw new Error(`${Re} unsupported type: ${r} (object only claims the tag via Symbol.toStringTag)`)}return dt(i,n,o)}}Te.Number=co(Number.prototype.valueOf);Te.String=co(String.prototype.valueOf);Te.Boolean=co(Boolean.prototype.valueOf);Te.BigInt=co(BigInt.prototype.valueOf);Te.Buffer=Te.Uint8Array;for(let t of"Uint8Clamped Uint16 Uint32 Int8 Int16 Int32 BigUint64 BigInt64 Float32 Float64".split(" "))Te[`${t}Array`]=Te.DataView;function dt(t,e={},r){let n=ou(t),o=e&&e.typeEncoders&&e.typeEncoders[n]||Te[n];if(typeof o=="function"){let s=o(t,n,e,r);if(s!=null)return s}let i=Te[n];if(!i)throw new Error(`${Re} unsupported type: ${n}`);return i(t,n,e,r)}function Nm(t,e){let r=e.mapSorter;r&&t.sort((n,o)=>r(n,o,e))}function Cm(t,e){if(t[0]instanceof E&&e[0]instanceof E){let r=t[0],n=e[0];r._keyBytes||(r._keyBytes=rf(r.value)),n._keyBytes||(n._keyBytes=rf(n.value));let o=ar(r._keyBytes,n._keyBytes);if(o===0)throw new Error(`${Re} duplicate map key`);return o}throw new Error("rfc8949MapSorter: complex key types are not supported yet")}function rf(t){return Dm(t,Bm,nf)}function of(t,e,r,n){if(Array.isArray(e))for(let o of e)of(t,o,r,n);else r[e.type.major](t,e,n)}var ob=h.uint.majorEncoded,ib=h.negint.majorEncoded,sb=h.bytes.majorEncoded,ab=h.string.majorEncoded,cb=h.array.majorEncoded,ub=h.map.majorEncoded,fb=h.float.majorEncoded|Zn,lb=h.float.majorEncoded|eo,db=h.float.majorEncoded|to,hb=h.float.majorEncoded|ro,pb=BigInt(-1),mb=BigInt(1);function Dm(t,e,r,n){let o=n!==void 0,i=dt(t,r);if(!Array.isArray(i)&&r.quickEncodeToken){let a=r.quickEncodeToken(i);if(a){if(o){let u=new $t(n);return u.pushBytes(a),u.toBytes()}return a}let c=e[i.type.major];if(c.encodedSize){let u=c.encodedSize(i,r);if(o){let m=new $t(n);return c(m,i,r),m.toBytes()}let f=new Uint8Array(u),p=new $t(f);if(c(p,i,r),p.cursor!==u)throw new Error(`Unexpected error: pre-calculated length for ${i} was wrong`);return f}}let s=o?new $t(n):Um?new Kr:Sm;return s.reset(),of(s,i,e,r),s.toBytes(!0)}var uo=class t{constructor(e,r){if(typeof e!="number"||!Number.isInteger(e)||e<0)throw new TypeError("Tagged: tag must be a non-negative integer");this.tag=e,this.value=r}static decoder(e){return r=>new t(e,r())}static preserve(...e){let r={};for(let n of e)r[n]=t.decoder(n);return r}};Object.defineProperty(uo.prototype,Symbol.toStringTag,{value:"Tagged"});var Ob=is();var Lm=Or(qn(),1);var Hb=[new E(h.map,2),new E(h.string,"version"),new E(h.uint,1),new E(h.string,"roots")],Vb=new E(h.tag,42);async function ss(t,e,r=33554432){let n=Xi(await t.upTo(8),t);if(n===0)throw new Error("Invalid CAR header (zero length)");sr(n,r);let o=await t.exactly(n,!0),i=ji(o);if(Qi.toTyped(i)===void 0)throw new Error("Invalid CAR header format");if(i.version!==1&&i.version!==2||e!==void 0&&i.version!==e)throw new Error(`Invalid CAR version: ${i.version}${e!==void 0?` (expected ${e})`:""}`);if(i.version===1){if(!Array.isArray(i.roots))throw new Error("Invalid CAR header format");return i}if(i.roots!==void 0)throw new Error("Invalid CAR header format");let s=Ki(await t.exactly(Yi,!0));t.seek(s.dataOffset-t.pos);let a=await ss(t,1,r);return Object.assign(a,s)}function tn(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 as=Or(qn(),1);var lf=1;function fo(t,e=33554432){let r=zi({version:lf,roots:t});sr(r.length,e);let n=as.default.encode(r.length),o=new Uint8Array(n.length+r.length);return o.set(n,0),o.set(r,n.length),o}function cs({cid:t,bytes:e},r){let n=t.bytes.length+e.length;Jr(n,r),Gn(t.multihash.size);let o=[new Uint8Array(as.default.encode(n)),t.bytes];return e.length&&o.push(e),o}function df(t,e){let{maxAllowedHeaderSize:r,maxAllowedSectionSize:n}=Lt(e);return{async setRoots(o){let i=fo(o,r);await t.write(i)},async writeBlock(o){for(let i of cs(o,n))await t.write(i)},async close(){await t.end()},error(o){t.error(o)},version(){return lf}}}function lo(){}function hf(){let t=[],e=null,r=lo,n=!1,o=null,i=null,s=lo,a=()=>(e||(e=new Promise(f=>{r=()=>{e=null,r=lo,f()}})),e),c={write(f){t.push(f);let p=a();return s(),p},async end(){n=!0;let f=a();s(),await f},error(f){o??=f,r(),s()}},u={async next(){let f=t.shift();if(f)return t.length===0&&r(),{done:!1,value:f};if(o)throw o;return n?(r(),{done:!0,value:void 0}):(i||(i=new Promise(p=>{s=()=>(i=null,s=lo,p(u.next()))})),i)}};return{writer:c,iterator:u}}var lr=class t{constructor(e,r){this._encoder=r,this._mutex=us(r,r.setRoots(e)),this._ended=!1}put(e){let r=mf(e);return r?this._ended?Promise.reject(new Error("Already closed")):(this._mutex=us(this._encoder,this._mutex.then(()=>this._encoder.writeBlock(r))),this._mutex):Promise.reject(new TypeError("Can only write {cid, bytes} objects"))}close(){return this._ended?Promise.reject(new Error("Already closed")):(this._ended=!0,us(this._encoder,this._mutex.then(()=>this._encoder.close())))}version(){return this._encoder.version()}static create(e,r){e=yf(e);let{encoder:n,iterator:o}=pf(r),i=new t(e,n),s=new rn(o);return{writer:i,out:s}}static createAppender(e){let{encoder:r,iterator:n}=pf(e);r.setRoots=()=>Promise.resolve();let o=new t([],r),i=new rn(n);return{writer:o,out:i}}static encode(e,r,n){if(!$m(r))throw new TypeError("encode() requires an Iterable or AsyncIterable of blocks");let{maxAllowedHeaderSize:o,maxAllowedSectionSize:i}=Lt(n),s=fo(yf(e),o);return new rn((async function*(){yield s;for await(let a of r){let c=mf(a);if(!c)throw new TypeError("Can only write {cid, bytes} objects");for(let u of cs(c,i))yield u}})())}static async updateRootsInBytes(e,r){let n=tn(e);await ss(n);let o=fo(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}},rn=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 pf(t){let e=hf(),{writer:r,iterator:n}=e;return{encoder:df(r,t),iterator:n}}function mf(t){if(!(t?.bytes instanceof Uint8Array)||!t.cid)return null;let e=B.asCID(t.cid);return e&&{cid:e,bytes:t.bytes}}function $m(t){return typeof t?.[Symbol.iterator]=="function"||typeof t?.[Symbol.asyncIterator]=="function"}function us(t,e){return e.catch(r=>t.error(r instanceof Error?r:new Error(String(r)))),e}function yf(t){if(t===void 0)return[];if(!Array.isArray(t)){let r=B.asCID(t);if(!r)throw new TypeError("roots must be a single CID or an array of CIDs");return[r]}let e=[];for(let r of t){let n=B.asCID(r);if(!n)throw new TypeError("roots must be a single CID or an array of CIDs");e.push(n)}return e}function Pm(t){return t[Symbol.asyncIterator]!=null}function zm(t){if(Pm(t))return(async()=>{for await(let e of t);})();for(let e of t);}var xf=zm;function jm(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 ho=jm;function Hm(t){return t[Symbol.asyncIterator]!=null}function Vm(t,e){let r=0;if(Hm(t))return(async function*(){for await(let c of t)yield e(c,r++)})();let n=ho(t),{value:o,done:i}=n.next();if(i===!0)return(function*(){})();let s=e(o,r++);if(typeof s.then=="function")return(async function*(){yield await s;for(let c of n)yield e(c,r++)})();let a=e;return(function*(){yield s;for(let c of n)yield a(c,r++)})()}var po=Vm;function qm(t){return t.reason}function dr(t,e,r){if(e==null||t==null)return t;let n=r?.translateError??qm;if(e.aborted)return t.catch(()=>{}),Promise.reject(n(e));let o;return Promise.race([t,new Promise((i,s)=>{o=()=>{s(n(e))},e.addEventListener("abort",o)})]).finally(()=>{o!=null&&e.removeEventListener("abort",o)})}var ls={};ue(ls,{base64:()=>fs,base64pad:()=>Gm,base64url:()=>Wm,base64urlpad:()=>Jm});var fs=j({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Gm=j({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Wm=j({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Jm=j({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});function je(t=0){return new Uint8Array(t)}function Ym(t){return t?.buffer instanceof ArrayBuffer}function bf(t){if(Ym(t))return t;let e=t.slice();return new Uint8Array(e.buffer,0,e.byteLength)}function nn(t,e){e==null&&(e=t.reduce((o,i)=>o+i.length,0));let r=je(e),n=0;for(let o of t)r.set(o,n),n+=o.length;return bf(r)}function Xm(t){return t.buffer instanceof ArrayBuffer}function mo(t){return Xm(t)?t:t.slice()}var Km=Math.pow(2,7),Qm=Math.pow(2,14),Zm=Math.pow(2,21),Ef=Math.pow(2,28),_f=Math.pow(2,35),Af=Math.pow(2,42),vf=Math.pow(2,49),ne=128,ht=127;function on(t){if(t<Km)return 1;if(t<Qm)return 2;if(t<Zm)return 3;if(t<Ef)return 4;if(t<_f)return 5;if(t<Af)return 6;if(t<vf)return 7;if(Number.MAX_SAFE_INTEGER!=null&&t>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function kf(t,e,r=0){switch(on(t)){case 8:e[r++]=t&255|ne,t/=128;case 7:e[r++]=t&255|ne,t/=128;case 6:e[r++]=t&255|ne,t/=128;case 5:e[r++]=t&255|ne,t/=128;case 4:e[r++]=t&255|ne,t>>>=7;case 3:e[r++]=t&255|ne,t>>>=7;case 2:e[r++]=t&255|ne,t>>>=7;case 1:{e[r++]=t&255,t>>>=7;break}default:throw new Error("unreachable")}return e}function If(t,e){let r=t[e],n=0;if(n+=r&ht,r<ne||(r=t[e+1],n+=(r&ht)<<7,r<ne)||(r=t[e+2],n+=(r&ht)<<14,r<ne)||(r=t[e+3],n+=(r&ht)<<21,r<ne)||(r=t[e+4],n+=(r&ht)*Ef,r<ne)||(r=t[e+5],n+=(r&ht)*_f,r<ne)||(r=t[e+6],n+=(r&ht)*Af,r<ne)||(r=t[e+7],n+=(r&ht)*vf,r<ne))return n;throw new RangeError("Could not decode varint")}var ds={};ue(ds,{base10:()=>ey});var ey=ct({prefix:"9",name:"base10",alphabet:"0123456789"});var hs={};ue(hs,{base16:()=>ty,base16upper:()=>ry});var ty=j({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4,caseInsensitive:!0}),ry=j({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4,caseInsensitive:!0});var ps={};ue(ps,{base2:()=>ny});var ny=j({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var ms={};ue(ms,{base256emoji:()=>cy});var Tf=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}"),oy=Tf.reduce((t,e,r)=>(t[r]=e,t),[]),iy=Tf.reduce((t,e,r)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return t[n]=r,t},[]);function sy(t){return t.reduce((e,r)=>(e+=oy[r],e),"")}function ay(t){let e=[];for(let r of t){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=iy[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);e.push(o)}return new Uint8Array(e)}var cy=Qt({prefix:"\u{1F680}",name:"base256emoji",encode:sy,decode:ay});var ys={};ue(ys,{base8:()=>uy});var uy=j({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var gs={};ue(gs,{identity:()=>fy});var fy=Qt({prefix:"\0",name:"identity",encode:t=>Uc(ke(t)),decode:t=>ke(Sc(t))});var EE=new TextEncoder,ly=new TextDecoder;var yo=512;function go(t){return JSON.parse(ly.decode(t))}var hr=85;var ws={...gs,...ps,...ys,...ds,...hs,...Li,...$i,...Mi,...ls,...ms},vE={...qi,...Hi};function Sf(t,e,r,n){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:r},decoder:{decode:n}}}var Bf=Sf("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),xs=Sf("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=je(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}),dy={utf8:Bf,"utf-8":Bf,hex:ws.base16,latin1:xs,ascii:xs,binary:xs,...ws},Uf=dy;function xo(t,e="utf8"){let r=Uf[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.decoder.decode(`${r.prefix}${t}`)}var He=class extends Error{static name="AbortError";constructor(e="The operation was aborted"){super(e),this.name="AbortError"}};var Ot=class extends Error{static name="InvalidParametersError";constructor(e="Invalid parameters"){super(e),this.name="InvalidParametersError"}};function hy(t){return typeof t?.handleEvent=="function"}function py(t){return t===!0||t===!1}function my(t){return py(t)?t:t?.capture??!1}function bs(t){let e={capture:my(t),once:!!t?.once};return t?.passive!=null&&(e.passive=t?.passive),t?.signal!=null&&(e.signal=t?.signal),e}function Nf(t,e){return bs(t).capture===bs(e).capture}var bo=class extends EventTarget{#e=new Map;constructor(){super()}listenerCount(e){let r=this.#e.get(e);return r==null?0:r.length}addEventListener(e,r,n){let o=bs(n);if(o?.signal?.aborted===!0)return;let i=u=>{o.once&&this.removeEventListener(e,r,o),hy(r)?r.handleEvent(u):r(u)},s=this.#e.get(e);if(s==null&&(s=[],this.#e.set(e,s)),s.some(u=>u.callback!==r?!1:Nf(u.options,o)))return;super.addEventListener(e,i,o);let c=()=>{this.removeEventListener(e,r,o)};o.signal?.addEventListener("abort",c),s.push({callback:r,wrapper:i,options:o,onAbort:c})}removeEventListener(e,r,n){let o=this.#e.get(e);if(o==null){super.removeEventListener(e,r??null,n);return}this.#e.set(e,o.filter(i=>i.callback===r&&Nf(i.options,n)?(super.removeEventListener(e,i.wrapper,n),i.options?.signal?.removeEventListener("abort",i.onAbort),!1):!0))}safeDispatchEvent(e,r={}){return this.dispatchEvent(new CustomEvent(e,r))}};function ee(){let t={};return t.promise=new Promise((e,r)=>{t.resolve=e,t.reject=r}),t}var Eo=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}},pr=class{size;hwm;head;tail;constructor(e={}){this.hwm=e.splitLimit??16,this.head=new Eo(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 Eo(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 Es=class extends Error{type;code;constructor(e,r){super(e??"The operation was aborted"),this.type="aborted",this.code=r??"ABORT_ERR"}};function mr(t={}){return yy(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 yy(t,e){e=e??{};let r=e.onEnd,n=new pr,o,i,s,a=ee(),c=async()=>{try{return n.isEmpty()?s?{done:!0}:await new Promise((v,I)=>{i=O=>{i=null,n.push(O);try{v(t(n))}catch(P){I(P)}return o}}):t(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=ee()})}},u=v=>i!=null?i(v):(n.push(v),o),f=v=>(n=new pr,i!=null?i({error:v}):(n.push({error:v}),o)),p=v=>{if(s)return o;if(e?.objectMode!==!0&&v?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return u({done:!1,value:v})},m=v=>s?o:(s=!0,v!=null?f(v):u({done:!0})),_=()=>(n=new pr,m(),{done:!0}),S=v=>(m(v),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:c,return:_,throw:S,push:p,end:m,get readableLength(){return n.size},onEmpty:async v=>{let I=v?.signal;if(I?.throwIfAborted(),n.isEmpty())return;let O,P;I!=null&&(O=new Promise((M,z)=>{P=()=>{z(new Es)},I.addEventListener("abort",P)}));try{await Promise.race([a.promise,O])}finally{P!=null&&I!=null&&I?.removeEventListener("abort",P)}}},r==null)return o;let T=o;return o={[Symbol.asyncIterator](){return this},next(){return T.next()},throw(v){return T.throw(v),r!=null&&(r(v),r=void 0),{done:!0}},return(){return T.return(),r!=null&&(r(),r=void 0),{done:!0}},push:p,end(v){return T.end(v),r!=null&&(r(v),r=void 0),o},get readableLength(){return T.readableLength},onEmpty:v=>T.onEmpty(v)},o}var _s=class t extends Error{name="TimeoutError";constructor(e,r){super(e,r),Error.captureStackTrace?.(this,t)}},gy=t=>"reason"in t?t.reason:new DOMException("This operation was aborted.","AbortError"),wy=2**31-1,xy=(t,e)=>{if(typeof t!="number"||Math.sign(t)!==1)return new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${t}\``);if(typeof e?.setTimeout!="function"||typeof e?.clearTimeout!="function")return new TypeError("Expected `customTimers` to have a `setTimeout` and a `clearTimeout` function")};function As(t,e){let{milliseconds:r,fallback:n,message:o,customTimers:i={setTimeout,clearTimeout},signal:s}=e,a,c,u=()=>{try{t.cancel?.()}catch{}},p=new Promise((m,_)=>{let S=()=>{_(gy(s)),u()},T=xy(r,i);try{T?_(T):s?.aborted?S():s&&(c=S,s.addEventListener("abort",c,{once:!0}))}finally{t.then(m,_)}if(T||s?.aborted||r>wy)return;let v=n||o===!1||o instanceof Error?void 0:new _s(o??`Promise timed out after ${r} milliseconds`);a=i.setTimeout.call(void 0,()=>{if(n)try{m(n())}catch(I){_(I)}else o===!1?m():_(o instanceof Error?o:v);u()},r)}).finally(()=>{try{p.clear()}catch{}try{c&&s.removeEventListener("abort",c)}catch{}});return p.clear=()=>{a!==void 0&&(i.clearTimeout.call(void 0,a),a=void 0)},p}var Cf=t=>typeof t=="function"?{filter:t}:{...t},by=t=>t===1/0||Number.isSafeInteger(t)&&t>=0,Ey=[["addEventListener","removeEventListener"],["on","off"],["addListener","removeListener"]],_y=t=>{for(let[e,r]of Ey){let n=t?.[e],o=t?.[r];if(typeof n=="function"&&typeof o=="function")return{addListener:n.bind(t),removeListener:o.bind(t)}}throw new TypeError("Emitter is not compatible")},Ay=t=>{let e=new Map;for(let[r,n]of t)for(let o of Array.isArray(r)?r:[r])e.has(o)||e.set(o,n);return e},vy=({addListener:t,removeListener:e,handlers:r,signal:n,abortHandler:o,isDone:i})=>{n?.addEventListener("abort",o,{once:!0});for(let[s,a]of r)if(t(s,a),i()){e(s,a);return}},ky=({removeListener:t,handlers:e,signal:r,abortHandler:n})=>{for(let[o,i]of e)t(o,i);r?.removeEventListener("abort",n)},Iy=(t,e,r)=>{let n=Promise.resolve();return(o,i)=>{n=n.then(async()=>{if(e())return;let s;try{s=t?await t(o):!0}catch(a){e()||r(a);return}e()||i(s)})}};function Ty(t,e,r){let n=()=>{},o=!1,i,s=new Promise((a,c)=>{r=Cf(r);let{filter:u}=r;if(!by(r.count))throw new TypeError("The `count` option should be at least 0 or more");if(typeof r.timeout=="number"&&!(r.timeout>0))throw new TypeError(`Expected the \`timeout\` option to be a positive number, got \`${r.timeout}\``);r.signal?.throwIfAborted();let{addListener:f,removeListener:p}=_y(t);if(r.count===0){a([]);return}let m=[],_=M=>{n(),c(M)},S=Iy(u,()=>o,_),T=M=>{m.push(M),r.count===m.length&&(n(),a(m))},v=(...M)=>{if(o)return;let z=r.multiArgs?M:M[0];if(!u){T(z);return}S(z,Q=>{Q&&T(z)})},I=(...M)=>{_(r.rejectionMultiArgs?M:M[0])},O=()=>{_(r.signal.reason)},P={addListener:f,removeListener:p,handlers:Ay([[e,v],[r.rejectionEvents??["error"],I]]),signal:r.signal,abortHandler:O,isDone:()=>o};n=()=>{o=!0,clearTimeout(i),ky(P)},vy(P),!(o||!r.resolveImmediately)&&(Number.isFinite(r.timeout)&&r.timeout<=2**31-1&&(i=setTimeout(n,r.timeout)),a(m))});if(s.cancel=n,typeof r.timeout=="number"&&r.timeout>0&&!r.resolveImmediately){let a=As(s,{milliseconds:r.timeout});return a.cancel=()=>{n(),a.clear()},a}return s}function _o(t,e,r){let n=Ty(t,e,{...Cf(r),count:1,resolveImmediately:!1}),o=n.then(i=>i[0]);return o.cancel=n.cancel,o}function vs(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 Ao=class extends Error{static name="QueueFullError";constructor(e="The queue was full"){super(e),this.name="QueueFullError"}};var vo=class{deferred;signal;onProgress;constructor(e){this.signal=e?.signal,this.onProgress=e?.onProgress,this.deferred=ee(),this.onAbort=this.onAbort.bind(this),this.signal?.addEventListener("abort",this.onAbort)}onAbort(){this.deferred.reject(this.signal?.reason??new He)}cleanup(){this.signal?.removeEventListener("abort",this.onAbort)}};function By(){return`${parseInt(String(Math.random()*1e9),10).toString()}${Date.now()}`}var Df=new WeakMap,ko=class{id;fn;options;recipients;status;timeline;controller;dispatchingProgress;constructor(e,r){this.id=By(),this.status="queued",this.fn=e,this.options=r,this.recipients=[],this.timeline={created:Date.now()},this.controller=new AbortController,this.controller.signal,this.dispatchingProgress=!1,this.onAbort=this.onAbort.bind(this)}abort(e){this.controller.abort(e)}onAbort(){this.recipients.reduce((r,n)=>r&&n.signal?.aborted===!0,!0)&&(this.controller.abort(new He),this.cleanup())}async join(e){let r=new vo(e);return this.recipients.push(r),e?.signal?.addEventListener("abort",this.onAbort),r.deferred.promise}async run(){this.status="running",this.timeline.started=Date.now();try{this.controller.signal.throwIfAborted();let e=await dr(this.fn({...this.options??{},signal:this.controller.signal,onProgress:r=>{if(this.recipients.length!==0&&!this.dispatchingProgress){if(typeof r=="object"&&r!==null){let n=Df.get(r);if(n==null&&(n=new WeakSet,Df.set(r,n)),n.has(this))return;n.add(this)}this.dispatchingProgress=!0;try{this.recipients.forEach(n=>{n.onProgress?.(r)})}finally{this.dispatchingProgress=!1}}}}),this.controller.signal);this.recipients.forEach(r=>{r.deferred.resolve(e)}),this.status="complete"}catch(e){this.recipients.forEach(r=>{r.deferred.reject(e)}),this.status="errored"}finally{this.timeline.finished=Date.now(),this.cleanup()}}cleanup(){this.recipients.forEach(e=>{e.deferred.reject(e.signal?.reason??new He),e.cleanup(),e.signal?.removeEventListener("abort",this.onAbort)}),this.recipients.splice(0,this.recipients.length)}};var yr=class extends bo{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=vs(this.emitEmpty.bind(this),1),this.emitIdle=vs(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 Ao;let n=new ko(e,r);this.enqueue(n),this.safeDispatchEvent("add");let o=n.join(r).then(i=>(this.safeDispatchEvent("completed",{detail:i}),this.safeDispatchEvent("success",{detail:{job:n,result:i}}),i)).catch(i=>{if(n.status==="queued"){for(let s=0;s<this.queue.length;s++)if(this.queue[s]===n){this.queue.splice(s,1);break}}throw this.safeDispatchEvent("failure",{detail:{job:n,error:i}}),i});return this.tryToStartAnother(),o}clear(){this.queue.splice(0,this.queue.length)}abort(){this.queue.forEach(e=>{e.abort(new He)}),this.clear()}async onEmpty(e){this.size!==0&&await _o(this,"empty",e)}async onSizeLessThan(e,r){this.size<e||await _o(this,"next",{...r,filter:()=>this.size<e})}async onIdle(e){this.pending===0&&this.size===0||await _o(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=mr({objectMode:!0}),n=c=>{c!=null?this.abort():this.clear(),r.end(c)},o=c=>{c.detail!=null&&r.push(c.detail)},i=c=>{n(c.detail.error)},s=()=>{n()},a=()=>{n(new He("Queue aborted"))};this.addEventListener("completed",o),this.addEventListener("failure",i),this.addEventListener("idle",s),e?.signal?.addEventListener("abort",a);try{yield*r}finally{this.removeEventListener("completed",o),this.removeEventListener("failure",i),this.removeEventListener("idle",s),e?.signal?.removeEventListener("abort",a),n()}}};function Lf(t){let e=new globalThis.AbortController;function r(){let i=t.filter(s=>s?.aborted===!0).map(s=>s?.reason).pop();e.abort(i);for(let s of t)s?.removeEventListener!=null&&s.removeEventListener("abort",r)}for(let i of t){if(i?.aborted===!0){r();break}i?.addEventListener!=null&&i.addEventListener("abort",r)}function n(){for(let i of t)i?.removeEventListener!=null&&i.removeEventListener("abort",r)}let o=e.signal;return o.clear=n,o}var ks=class{readNext;haveNext;ended;nextResult;error;constructor(){this.ended=!1,this.readNext=ee(),this.haveNext=ee()}[Symbol.asyncIterator](){return this}async next(){if(this.nextResult==null&&await this.haveNext.promise,this.nextResult==null)throw new Error("HaveNext promise resolved but nextResult was undefined");let e=this.nextResult;return this.nextResult=void 0,this.readNext.resolve(),this.readNext=ee(),e}async throw(e){return this.ended=!0,this.error=e,e!=null&&(this.haveNext.promise.catch(()=>{}),this.haveNext.reject(e)),{done:!0,value:void 0}}async return(){let e={done:!0,value:void 0};return this.ended=!0,this.nextResult=e,this.haveNext.resolve(),e}async push(e,r){await this._push(e,r)}async end(e,r){e!=null?await this.throw(e):await this._push(void 0,r)}async _push(e,r){if(e!=null&&this.ended)throw this.error??new Error("Cannot push value onto an ended pushable");for(;this.nextResult!=null;)await this.readNext.promise;e!=null?this.nextResult={done:!1,value:e}:(this.ended=!0,this.nextResult={done:!0,value:void 0}),this.haveNext.resolve(),this.haveNext=ee(),await dr(this.readNext.promise,r?.signal,r)}};function $f(){return new ks}function Mf(t){return t[Symbol.asyncIterator]!=null}async function Sy(t,e,r){try{await Promise.all(t.map(async n=>{for(;;){let{value:o,done:i}=await n.next();if(i===!0)break;await e.push(o,{signal:r}),r.throwIfAborted()}})),await e.end(void 0,{signal:r})}catch(n){await e.end(n,{signal:r}).catch(()=>{})}}async function*Uy(t){let e=new AbortController,r=$f(),n=t.map(o=>Mf(o)?o[Symbol.asyncIterator]():o[Symbol.iterator]());Sy(n,r,e.signal).catch(()=>{});try{yield*r}finally{e.abort();for(let o of n)try{Promise.resolve(o.return?.()).catch(()=>{})}catch{}}}function*Ny(t){for(let e of t)yield*e}function Cy(...t){let e=[];for(let r of t)Mf(r)||e.push(r);return e.length===t.length?Ny(e):Uy(t)}var Of=Cy;function Rf(t,...e){if(t==null)throw new Error("Empty pipeline");if(Is(t)){let n=t;t=()=>n.source}else if(Pf(t)||Ff(t)){let n=t;t=()=>n}let r=[t,...e];if(r.length>1&&Is(r[r.length-1])&&(r[r.length-1]=r[r.length-1].sink),r.length>2)for(let n=1;n<r.length-1;n++)Is(r[n])&&(r[n]=Ly(r[n]));return Dy(...r)}var Dy=(...t)=>{let e;for(;t.length>0;)e=t.shift()(e);return e},Ff=t=>t?.[Symbol.asyncIterator]!=null,Pf=t=>t?.[Symbol.iterator]!=null,Is=t=>t==null?!1:t.sink!=null&&t.source!=null,Ly=t=>e=>{let r=t.sink(e);if(r?.then!=null){let n=mr({objectMode:!0});r.then(()=>{n.end()},s=>{n.end(s)});let o,i=t.source;if(Ff(i))o=async function*(){yield*i,n.end()};else if(Pf(i))o=function*(){yield*i,n.end()};else throw new Error("Unknown duplex source type - must be Iterable or AsyncIterable");return Of(n,o())}return t.source};var $y=["Object","Uint8Array","RegExp","Date","Error","Map","Set","WeakMap","WeakSet","ArrayBuffer","SharedArrayBuffer","DataView","Promise","URL","HTMLElement","Int8Array","Uint8ClampedArray","Int16Array","Uint16Array","Int32Array","Uint32Array","Float32Array","Float64Array","BigInt64Array","BigUint64Array","Tagged"];function zf(t){if(t===null)return"null";if(t===void 0)return"undefined";if(t===!0||t===!1)return"boolean";let e=typeof t;if(e==="string"||e==="number"||e==="bigint"||e==="symbol")return e;if(e==="function")return"Function";if(Array.isArray(t))return"Array";if(t instanceof Uint8Array)return"Uint8Array";if(t.constructor===Object)return"Object";let r=My(t);return r||"Object"}function My(t){let e=Object.prototype.toString.call(t).slice(8,-1);if($y.includes(e))return e}var l=class{constructor(e,r,n){this.major=e,this.majorEncoded=e<<5,this.name=r,this.terminal=n}toString(){return`Type[${this.major}].${this.name}`}compare(e){return this.major<e.major?-1:this.major>e.major?1:0}static equals(e,r){return e===r||e.major===r.major&&e.name===r.name}};l.uint=new l(0,"uint",!0);l.negint=new l(1,"negint",!0);l.bytes=new l(2,"bytes",!0);l.string=new l(3,"string",!0);l.array=new l(4,"array",!1);l.map=new l(5,"map",!1);l.tag=new l(6,"tag",!1);l.float=new l(7,"float",!0);l.false=new l(7,"false",!0);l.true=new l(7,"true",!0);l.null=new l(7,"null",!0);l.undefined=new l(7,"undefined",!0);l.break=new l(7,"break",!0);var y=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 an=globalThis.process&&!globalThis.process.browser&&globalThis.Buffer&&typeof globalThis.Buffer.isBuffer=="function",Oy=new TextEncoder;function Io(t){return an&&globalThis.Buffer.isBuffer(t)}function Rt(t){return t instanceof Uint8Array?Io(t)?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):t:Uint8Array.from(t)}var Ry=24,Fy=200,cn=an?t=>t.length>=Ry?globalThis.Buffer.from(t):jf(t):t=>t.length>=Fy?Oy.encode(t):jf(t),Ve=t=>Uint8Array.from(t),Vf=an?(t,e,r)=>Io(t)?new Uint8Array(t.subarray(e,r)):t.slice(e,r):(t,e,r)=>t.slice(e,r),qf=an?(t,e)=>(t=t.map(r=>r instanceof Uint8Array?r:globalThis.Buffer.from(r)),Rt(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},Ts=an?t=>globalThis.Buffer.allocUnsafe(t):t=>new Uint8Array(t);function gr(t,e){if(Io(t)&&Io(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 jf(t){let e=[],r=0;for(let n=0;n<t.length;n++){let o=t.charCodeAt(n);o<128?e[r++]=o:o<2048?(e[r++]=o>>6|192,e[r++]=o&63|128):(o&64512)===55296&&n+1<t.length&&(t.charCodeAt(n+1)&64512)===56320?(o=65536+((o&1023)<<10)+(t.charCodeAt(++n)&1023),e[r++]=o>>18|240,e[r++]=o>>12&63|128,e[r++]=o>>6&63|128,e[r++]=o&63|128):(o>=55296&&o<=57343&&(o=65533),e[r++]=o>>12|224,e[r++]=o>>6&63|128,e[r++]=o&63|128)}return e}var Hf=4096;function Gf(t){let e=t.length;if(e<=Hf)return String.fromCharCode.apply(String,t);let r="",n=0;for(;n<e;)r+=String.fromCharCode.apply(String,t.slice(n,n+=Hf));return r}var Py=256,wr=class{constructor(e=Py){this.chunkSize=e,this.cursor=0,this.maxCursor=-1,this.chunks=[],this._initReuseChunk=null}reset(){this.cursor=0,this.maxCursor=-1,this.chunks.length&&(this.chunks=[]),this._initReuseChunk!==null&&(this.chunks.push(this._initReuseChunk),this.maxCursor=this._initReuseChunk.length-1)}pushByte(e){let r=this.chunks[this.chunks.length-1];this.cursor>this.maxCursor&&(r=Ts(this.chunkSize),this.chunks.push(r),this.maxCursor+=r.length,this._initReuseChunk===null&&(this._initReuseChunk=r));let n=r.length-(this.maxCursor-this.cursor)-1;r[n]=e,this.cursor++}push(e){let r=this.chunks[this.chunks.length-1];if(this.cursor+e.length<=this.maxCursor+1){let 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=Ts(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=Vf(n,0,this.cursor)}else r=qf(this.chunks,this.cursor);return e&&this.reset(),r}},To=class{constructor(e){this.dest=e,this.cursor=0,this.chunks=[e]}reset(){this.cursor=0}pushByte(e){if(this.cursor>=this.dest.length)throw new Error("write out of bounds, destination buffer is too small");this.dest[this.cursor++]=e}push(e){if(this.cursor+e.length>this.dest.length)throw new Error("write out of bounds, destination buffer is too small");this.dest.set(e,this.cursor),this.cursor+=e.length}toBytes(e=!1){let r=this.dest.subarray(0,this.cursor);return e&&this.reset(),r}};var g="CBOR decode error:",Ft="CBOR encode error:",un=[];un[23]=1;un[24]=2;un[25]=3;un[26]=5;un[27]=9;function Qe(t,e,r){if(t.length-e<r)throw new Error(`${g} not enough data for type`)}var X=[24,256,65536,4294967296,BigInt("18446744073709551616")];function we(t,e,r){Qe(t,e,1);let n=t[e];if(r.strict===!0&&n<X[0])throw new Error(`${g} integer encoded in more bytes than necessary (strict decode)`);return n}function xe(t,e,r){Qe(t,e,2);let n=t[e]<<8|t[e+1];if(r.strict===!0&&n<X[1])throw new Error(`${g} integer encoded in more bytes than necessary (strict decode)`);return n}function be(t,e,r){Qe(t,e,4);let n=t[e]*16777216+(t[e+1]<<16)+(t[e+2]<<8)+t[e+3];if(r.strict===!0&&n<X[2])throw new Error(`${g} integer encoded in more bytes than necessary (strict decode)`);return n}function Ee(t,e,r){Qe(t,e,8);let n=t[e]*16777216+(t[e+1]<<16)+(t[e+2]<<8)+t[e+3],o=t[e+4]*16777216+(t[e+5]<<16)+(t[e+6]<<8)+t[e+7],i=(BigInt(n)<<BigInt(32))+BigInt(o);if(r.strict===!0&&i<X[3])throw new Error(`${g} 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(`${g} integers outside of the safe integer range are not supported`)}function Wf(t,e,r,n){return new y(l.uint,we(t,e+1,n),2)}function Jf(t,e,r,n){return new y(l.uint,xe(t,e+1,n),3)}function Yf(t,e,r,n){return new y(l.uint,be(t,e+1,n),5)}function Xf(t,e,r,n){return new y(l.uint,Ee(t,e+1,n),9)}function qe(t,e){return K(t,0,e.value)}function K(t,e,r){if(r<X[0]){let n=Number(r);t.pushByte(e|n)}else if(r<X[1]){let n=Number(r);t.push([e|24,n])}else if(r<X[2]){let n=Number(r);t.push([e|25,n>>>8,n&255])}else if(r<X[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<X[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(`${g} encountered BigInt larger than allowable range`)}}qe.encodedSize=function(e){return K.encodedSize(e.value)};K.encodedSize=function(e){return e<X[0]?1:e<X[1]?2:e<X[2]?3:e<X[3]?5:9};qe.compareTokens=function(e,r){return e.value<r.value?-1:e.value>r.value?1:0};function Kf(t,e,r,n){return new y(l.negint,-1-we(t,e+1,n),2)}function Qf(t,e,r,n){return new y(l.negint,-1-xe(t,e+1,n),3)}function Zf(t,e,r,n){return new y(l.negint,-1-be(t,e+1,n),5)}var Bs=BigInt(-1),el=BigInt(1);function tl(t,e,r,n){let o=Ee(t,e+1,n);if(typeof o!="bigint"){let i=-1-o;if(i>=Number.MIN_SAFE_INTEGER)return new y(l.negint,i,9)}if(n.allowBigInt!==!0)throw new Error(`${g} integers outside of the safe integer range are not supported`);return new y(l.negint,Bs-BigInt(o),9)}function Bo(t,e){let r=e.value,n=typeof r=="bigint"?r*Bs-el:r*-1-1;K(t,e.type.majorEncoded,n)}Bo.encodedSize=function(e){let r=e.value,n=typeof r=="bigint"?r*Bs-el:r*-1-1;return n<X[0]?1:n<X[1]?2:n<X[2]?3:n<X[3]?5:9};Bo.compareTokens=function(e,r){return e.value<r.value?1:e.value>r.value?-1:0};function fn(t,e,r,n){Qe(t,e,r+n);let o=t.slice(e+r,e+r+n);return new y(l.bytes,o,r+n)}function rl(t,e,r,n){return fn(t,e,1,r)}function nl(t,e,r,n){return fn(t,e,2,we(t,e+1,n))}function ol(t,e,r,n){return fn(t,e,3,xe(t,e+1,n))}function il(t,e,r,n){return fn(t,e,5,be(t,e+1,n))}function sl(t,e,r,n){let o=Ee(t,e+1,n);if(typeof o=="bigint")throw new Error(`${g} 64-bit integer bytes lengths not supported`);return fn(t,e,9,o)}function So(t){return t.encodedBytes===void 0&&(t.encodedBytes=l.equals(t.type,l.string)?cn(t.value):t.value),t.encodedBytes}function xr(t,e){let r=So(e);K(t,e.type.majorEncoded,r.length),t.push(r)}xr.encodedSize=function(e){let r=So(e);return K.encodedSize(r.length)+r.length};xr.compareTokens=function(e,r){return jy(So(e),So(r))};function jy(t,e){return t.length<e.length?-1:t.length>e.length?1:gr(t,e)}var al=new TextDecoder("utf-8",{ignoreBOM:!0}),Vy=new TextDecoder("utf-8",{ignoreBOM:!0,fatal:!0}),qy=32;function Gy(t,e,r,n){if(r-e<qy){let i="";for(let s=e;s<r;s++){let a=t[s];if(a&128)return n.strictUtf8===!0?cl(t,e,r):al.decode(t.subarray(e,r));i+=String.fromCharCode(a)}return i}return n.strictUtf8===!0?cl(t,e,r):al.decode(t.subarray(e,r))}function cl(t,e,r){try{return Vy.decode(t.subarray(e,r))}catch{throw new Error(`${g} invalid UTF-8 in text string`)}}function ln(t,e,r,n,o){let i=r+n;Qe(t,e,i);let s=new y(l.string,Gy(t,e+r,e+i,o),i);return o.retainStringBytes===!0&&(s.byteValue=t.slice(e+r,e+i)),s}function ul(t,e,r,n){return ln(t,e,1,r,n)}function fl(t,e,r,n){return ln(t,e,2,we(t,e+1,n),n)}function ll(t,e,r,n){return ln(t,e,3,xe(t,e+1,n),n)}function dl(t,e,r,n){return ln(t,e,5,be(t,e+1,n),n)}function hl(t,e,r,n){let o=Ee(t,e+1,n);if(typeof o=="bigint")throw new Error(`${g} 64-bit integer string lengths not supported`);return ln(t,e,9,o,n)}var pl=xr;function br(t,e,r,n){return new y(l.array,n,r)}function ml(t,e,r,n){return br(t,e,1,r)}function yl(t,e,r,n){return br(t,e,2,we(t,e+1,n))}function gl(t,e,r,n){return br(t,e,3,xe(t,e+1,n))}function wl(t,e,r,n){return br(t,e,5,be(t,e+1,n))}function xl(t,e,r,n){let o=Ee(t,e+1,n);if(typeof o=="bigint")throw new Error(`${g} 64-bit integer array lengths not supported`);return br(t,e,9,o)}function bl(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${g} indefinite length items not allowed`);return br(t,e,1,1/0)}function Uo(t,e){K(t,l.array.majorEncoded,e.value)}Uo.compareTokens=qe.compareTokens;Uo.encodedSize=function(e){return K.encodedSize(e.value)};function Er(t,e,r,n){return new y(l.map,n,r)}function El(t,e,r,n){return Er(t,e,1,r)}function _l(t,e,r,n){return Er(t,e,2,we(t,e+1,n))}function Al(t,e,r,n){return Er(t,e,3,xe(t,e+1,n))}function vl(t,e,r,n){return Er(t,e,5,be(t,e+1,n))}function kl(t,e,r,n){let o=Ee(t,e+1,n);if(typeof o=="bigint")throw new Error(`${g} 64-bit integer map lengths not supported`);return Er(t,e,9,o)}function Il(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${g} indefinite length items not allowed`);return Er(t,e,1,1/0)}function No(t,e){K(t,l.map.majorEncoded,e.value)}No.compareTokens=qe.compareTokens;No.encodedSize=function(e){return K.encodedSize(e.value)};function Tl(t,e,r,n){return new y(l.tag,r,1)}function Bl(t,e,r,n){return new y(l.tag,we(t,e+1,n),2)}function Sl(t,e,r,n){return new y(l.tag,xe(t,e+1,n),3)}function Ul(t,e,r,n){return new y(l.tag,be(t,e+1,n),5)}function Nl(t,e,r,n){return new y(l.tag,Ee(t,e+1,n),9)}function Co(t,e){K(t,l.tag.majorEncoded,e.value)}Co.compareTokens=qe.compareTokens;Co.encodedSize=function(e){return K.encodedSize(e.value)};var Do=20,Lo=21,$o=22,Mo=23;function Dl(t,e,r,n){if(n.allowUndefined===!1)throw new Error(`${g} undefined values are not supported`);return n.coerceUndefinedToNull===!0?new y(l.null,null,1):new y(l.undefined,void 0,1)}function Ll(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${g} indefinite length items not allowed`);return new y(l.break,void 0,1)}function Ss(t,e,r){if(r){if(r.allowNaN===!1&&Number.isNaN(t))throw new Error(`${g} NaN values are not supported`);if(r.allowInfinity===!1&&(t===1/0||t===-1/0))throw new Error(`${g} Infinity values are not supported`)}return new y(l.float,t,e)}function $l(t,e,r,n){return Ss(Ro(t,e+1),3,n)}function Ml(t,e,r,n){return Ss(Fo(t,e+1),5,n)}function Ol(t,e,r,n){return Ss(Pl(t,e+1),9,n)}function Oo(t,e,r){let n=e.value;if(n===!1)t.pushByte(l.float.majorEncoded|Do);else if(n===!0)t.pushByte(l.float.majorEncoded|Lo);else if(n===null)t.pushByte(l.float.majorEncoded|$o);else if(n===void 0)t.pushByte(l.float.majorEncoded|Mo);else{let o,i=!1;(!r||r.float64!==!0)&&(Us(n),o=Ro(J,1),n===o||Number.isNaN(n)?(J[0]=249,t.push(J.slice(0,3)),i=!0):(Ns(n),o=Fo(J,1),n===o&&(J[0]=250,t.push(J.slice(0,5)),i=!0))),i||(Fl(n),o=Pl(J,1),J[0]=251,t.push(J.slice(0,9)))}}Oo.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){Us(n);let o=Ro(J,1);if(n===o||Number.isNaN(n))return 3;if(Ns(n),o=Fo(J,1),n===o)return 5}return 9};var Rl=new ArrayBuffer(9),Be=new DataView(Rl,1),J=new Uint8Array(Rl,0);function Us(t){if(t===1/0)Be.setUint16(0,31744,!1);else if(t===-1/0)Be.setUint16(0,64512,!1);else if(Number.isNaN(t))Be.setUint16(0,32256,!1);else{Be.setFloat32(0,t);let e=Be.getUint32(0),r=(e&2139095040)>>23,n=e&8388607;if(r===255)Be.setUint16(0,31744,!1);else if(r===0)Be.setUint16(0,(e&2147483648)>>16|n>>13,!1);else{let o=r-127;o<-24?Be.setUint16(0,0):o<-14?Be.setUint16(0,(e&2147483648)>>16|1<<24+o,!1):Be.setUint16(0,(e&2147483648)>>16|o+15<<10|n>>13,!1)}}}function Ro(t,e){if(t.length-e<2)throw new Error(`${g} 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 Ns(t){Be.setFloat32(0,t,!1)}function Fo(t,e){if(t.length-e<4)throw new Error(`${g} not enough data for float32`);let r=(t.byteOffset||0)+e;return new DataView(t.buffer,r,4).getFloat32(0,!1)}function Fl(t){Be.setFloat64(0,t,!1)}function Pl(t,e){if(t.length-e<8)throw new Error(`${g} not enough data for float64`);let r=(t.byteOffset||0)+e;return new DataView(t.buffer,r,8).getFloat64(0,!1)}function Ky(t,e){let r=t.value;if(r===!1)return Uint8Array.of(l.float.majorEncoded|Do);if(r===!0)return Uint8Array.of(l.float.majorEncoded|Lo);if(r===null)return Uint8Array.of(l.float.majorEncoded|$o);if(r===void 0)return Uint8Array.of(l.float.majorEncoded|Mo);if(!e){if(Us(r),r===Ro(J,1)||Number.isNaN(r))return J[0]=249,J.slice(0,3);if(Ns(r),r===Fo(J,1))return J[0]=250,J.slice(0,5)}return Fl(r),J[0]=251,J.slice(0,9)}function Cl(t,e){let r=t,n=e?.float64===!0,o=n?r._keyBytesFloat64:r._keyBytes;if(o!==void 0)return o;let i=Ky(t,n);return n?r._keyBytesFloat64=i:r._keyBytes=i,i}Oo.compareTokens=function(e,r,n){let o=Cl(e,n),i=Cl(r,n);return o.length!==i.length?o.length<i.length?-1:1:gr(o,i)};function D(t,e,r){throw new Error(`${g} encountered invalid minor (${r}) for major ${t[e]>>>5}`)}function Po(t){return()=>{throw new Error(`${g} ${t}`)}}var x=[];for(let t=0;t<=23;t++)x[t]=D;x[24]=Wf;x[25]=Jf;x[26]=Yf;x[27]=Xf;x[28]=D;x[29]=D;x[30]=D;x[31]=D;for(let t=32;t<=55;t++)x[t]=D;x[56]=Kf;x[57]=Qf;x[58]=Zf;x[59]=tl;x[60]=D;x[61]=D;x[62]=D;x[63]=D;for(let t=64;t<=87;t++)x[t]=rl;x[88]=nl;x[89]=ol;x[90]=il;x[91]=sl;x[92]=D;x[93]=D;x[94]=D;x[95]=Po("indefinite length bytes/strings are not supported");for(let t=96;t<=119;t++)x[t]=ul;x[120]=fl;x[121]=ll;x[122]=dl;x[123]=hl;x[124]=D;x[125]=D;x[126]=D;x[127]=Po("indefinite length bytes/strings are not supported");for(let t=128;t<=151;t++)x[t]=ml;x[152]=yl;x[153]=gl;x[154]=wl;x[155]=xl;x[156]=D;x[157]=D;x[158]=D;x[159]=bl;for(let t=160;t<=183;t++)x[t]=El;x[184]=_l;x[185]=Al;x[186]=vl;x[187]=kl;x[188]=D;x[189]=D;x[190]=D;x[191]=Il;for(let t=192;t<=215;t++)x[t]=Tl;x[216]=Bl;x[217]=Sl;x[218]=Ul;x[219]=Nl;x[220]=D;x[221]=D;x[222]=D;x[223]=D;for(let t=224;t<=243;t++)x[t]=Po("simple values are not supported");x[244]=D;x[245]=D;x[246]=D;x[247]=Dl;x[248]=Po("simple values are not supported");x[249]=$l;x[250]=Ml;x[251]=Ol;x[252]=D;x[253]=D;x[254]=D;x[255]=Ll;var De=[];for(let t=0;t<24;t++)De[t]=new y(l.uint,t,1);for(let t=-1;t>=-24;t--)De[31-t]=new y(l.negint,t,1);De[64]=new y(l.bytes,new Uint8Array(0),1);De[96]=new y(l.string,"",1);De[128]=new y(l.array,0,1);De[160]=new y(l.map,0,1);De[244]=new y(l.false,!1,1);De[245]=new y(l.true,!0,1);De[246]=new y(l.null,null,1);function zl(t){switch(t.type){case l.false:return Ve([244]);case l.true:return Ve([245]);case l.null:return Ve([246]);case l.bytes:return t.value.length?void 0:Ve([64]);case l.string:return t.value===""?Ve([96]):void 0;case l.array:return t.value===0?Ve([128]):void 0;case l.map:return t.value===0?Ve([160]):void 0;case l.uint:return t.value<24?Ve([Number(t.value)]):void 0;case l.negint:if(t.value>=-24)return Ve([31-Number(t.value)])}}var Hl=Object.freeze({mapSorter:og,quickEncodeToken:zl});function Zy(){let t=[];return t[l.uint.major]=qe,t[l.negint.major]=Bo,t[l.bytes.major]=xr,t[l.string.major]=pl,t[l.array.major]=Uo,t[l.map.major]=No,t[l.tag.major]=Co,t[l.float.major]=Oo,t}var eg=Zy(),tg=new wr,rg=!1,zo=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(`${Ft} object contains circular references`);return new t(r,e)}},pt={null:new y(l.null,null),undefined:new y(l.undefined,void 0),true:new y(l.true,!0),false:new y(l.false,!1),emptyArray:new y(l.array,0),emptyMap:new y(l.map,0)},mt={number(t,e,r,n){return!Number.isInteger(t)||!Number.isSafeInteger(t)?new y(l.float,t):t>=0?new y(l.uint,t):new y(l.negint,t)},bigint(t,e,r,n){return t>=BigInt(0)?new y(l.uint,t):new y(l.negint,t)},Uint8Array(t,e,r,n){return new y(l.bytes,t)},string(t,e,r,n){return new y(l.string,t)},boolean(t,e,r,n){return t?pt.true:pt.false},null(t,e,r,n){return pt.null},undefined(t,e,r,n){return pt.undefined},ArrayBuffer(t,e,r,n){return new y(l.bytes,new Uint8Array(t))},DataView(t,e,r,n){return new y(l.bytes,new Uint8Array(t.buffer,t.byteOffset,t.byteLength))},Array(t,e,r,n){if(!t.length)return r.addBreakTokens===!0?[pt.emptyArray,new y(l.break)]:pt.emptyArray;n=zo.createCheck(n,t);let o=[],i=0;for(let s of t)o[i++]=_r(s,r,n);return r.addBreakTokens?[new y(l.array,t.length),o,new y(l.break)]:[new y(l.array,t.length),o]},Object(t,e,r,n){let o=e!=="Object",i=o?t.keys():Object.keys(t),s=o?t.size:i.length,a;if(s){a=new Array(s),n=zo.createCheck(n,t);let c=!o&&r.ignoreUndefinedProperties,u=0;for(let f of i){let p=o?t.get(f):t[f];c&&p===void 0||(a[u++]=[_r(f,r,n),_r(p,r,n)])}u<s&&(a.length=u)}return a?.length?(ng(a,r),r.addBreakTokens?[new y(l.map,a.length),a,new y(l.break)]:[new y(l.map,a.length),a]):r.addBreakTokens===!0?[pt.emptyMap,new y(l.break)]:pt.emptyMap},Tagged(t,e,r,n){return[new y(l.tag,t.tag),_r(t.value,r,n)]}};mt.Map=mt.Object;mt.Buffer=mt.Uint8Array;for(let t of"Uint8Clamped Uint16 Uint32 Int8 Int16 Int32 BigUint64 BigInt64 Float32 Float64".split(" "))mt[`${t}Array`]=mt.DataView;function _r(t,e={},r){let n=zf(t),o=e&&e.typeEncoders&&e.typeEncoders[n]||mt[n];if(typeof o=="function"){let s=o(t,n,e,r);if(s!=null)return s}let i=mt[n];if(!i)throw new Error(`${Ft} unsupported type: ${n}`);return i(t,n,e,r)}function ng(t,e){let r=e.mapSorter;r&&t.sort((n,o)=>r(n,o,e))}function og(t,e){if(t[0]instanceof y&&e[0]instanceof y){let r=t[0],n=e[0];return r._keyBytes||(r._keyBytes=jl(r.value)),n._keyBytes||(n._keyBytes=jl(n.value)),gr(r._keyBytes,n._keyBytes)}throw new Error("rfc8949MapSorter: complex key types are not supported yet")}function jl(t){return ql(t,eg,Hl)}function Vl(t,e,r,n){if(Array.isArray(e))for(let o of e)Vl(t,o,r,n);else r[e.type.major](t,e,n)}var tA=l.uint.majorEncoded,rA=l.negint.majorEncoded,nA=l.bytes.majorEncoded,oA=l.string.majorEncoded,iA=l.array.majorEncoded,sA=l.map.majorEncoded,aA=l.float.majorEncoded|Do,cA=l.float.majorEncoded|Lo,uA=l.float.majorEncoded|$o,fA=l.float.majorEncoded|Mo,lA=BigInt(-1),dA=BigInt(1);function ql(t,e,r,n){let o=n instanceof Uint8Array,i=o?new To(n):rg?new wr:tg,s=_r(t,r);if(!Array.isArray(s)&&r.quickEncodeToken){let a=r.quickEncodeToken(s);if(a)return o?(i.push(a),i.toBytes()):a;let c=e[s.type.major];if(c.encodedSize){let u=c.encodedSize(s,r);if(o||(i=new wr(u)),c(i,s,r),i.chunks.length!==1)throw new Error(`Unexpected error: pre-calculated length for ${s} was wrong`);return o?i.toBytes():Rt(i.chunks[0])}}return i.reset(),Vl(i,s,e,r),i.toBytes(!0)}var ig={strict:!1,allowIndefinite:!0,allowUndefined:!0,allowBigInt:!0},jo=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=De[e];if(r===void 0){let n=x[e];if(!n)throw e===void 0?new Error(`${g} not enough data`):new Error(`${g} 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}},yt=Symbol.for("DONE"),gt=Symbol.for("BREAK");function sg(t,e,r){let n=[];for(let o=0;o<t.value;o++){let i=wt(e,r);if(i===gt){if(t.value===1/0)break;throw new Error(`${g} got unexpected break to lengthed array`)}if(i===yt)throw new Error(`${g} found array but not enough entries (got ${o}, expected ${t.value})`);n[o]=i}return n}function ag(t,e,r){let n=r.useMaps===!0,o=r.rejectDuplicateMapKeys===!0,i=n?void 0:{},s=n?new Map:void 0;for(let a=0;a<t.value;a++){let c=wt(e,r);if(c===gt){if(t.value===1/0)break;throw new Error(`${g} got unexpected break to lengthed map`)}if(c===yt)throw new Error(`${g} found map but not enough entries (got ${a} [no key], expected ${t.value})`);if(!n&&typeof c!="string")throw new Error(`${g} non-string keys not supported (got ${typeof c})`);if(o&&(n&&s.has(c)||!n&&Object.hasOwn(i,c)))throw new Error(`${g} found repeat map key "${c}"`);let u=wt(e,r);if(u===yt)throw new Error(`${g} found map but not enough entries (got ${a} [no value], expected ${t.value})`);if(u===gt)throw new Error(`${g} got unexpected break to map value`);n?s.set(c,u):c==="__proto__"?Object.defineProperty(i,c,{value:u,configurable:!0,enumerable:!0,writable:!0}):i[c]=u}return n?s:i}function*cg(t,e,r){for(let n=0;n<t.value;n++){let o=wt(e,r);if(o===gt){if(t.value===1/0)break;throw new Error(`${g} got unexpected break to lengthed map`)}if(o===yt)throw new Error(`${g} found map but not enough entries (got ${n} [no key], expected ${t.value})`);let i=wt(e,r);if(i===yt)throw new Error(`${g} found map but not enough entries (got ${n} [no value], expected ${t.value})`);if(i===gt)throw new Error(`${g} got unexpected break to map value`);yield[o,i]}}function ug(t,e){let r=function(){if(r._called)throw new Error(`${g} tag decode() may only be called once`);r._called=!0;let n=wt(t,e);if(n===yt)throw new Error(`${g} tag content missing`);if(n===gt)throw new Error(`${g} got unexpected break in tag content`);return n};return r.entries=function(){if(r._called)throw new Error(`${g} tag decode() may only be called once`);if(r._called=!0,t.done())throw new Error(`${g} tag content missing`);let n=t.next();if(!l.equals(n.type,l.map))throw new Error(`${g} entries() requires map content, got ${n.type.name}`);let o=[];for(let i of cg(n,t,e))o.push(i);return o},r._called=!1,r}function wt(t,e){if(t.done())return yt;let r=t.next();if(l.equals(r.type,l.break))return gt;if(r.type.terminal)return r.value;if(l.equals(r.type,l.array))return sg(r,t,e);if(l.equals(r.type,l.map))return ag(r,t,e);if(l.equals(r.type,l.tag)){if(e.tags&&typeof e.tags[r.value]=="function"){let n=ug(t,e),o=e.tags[r.value](n);if(!n._called)throw new Error(`${g} tag decoder must call decode() or entries()`);return o}throw new Error(`${g} tag not supported (${r.value})`)}throw new Error("unsupported")}function Cs(t,e){if(!(t instanceof Uint8Array))throw new Error(`${g} data to decode must be a Uint8Array`);e=Object.assign({},ig,e);let r=Rt(t),n=e.tokenizer||new jo(r,e),o=wt(n,e);if(o===yt)throw new Error(`${g} did not find any content to decode`);if(o===gt)throw new Error(`${g} got unexpected break`);return[o,t.subarray(n.pos())]}function dn(t,e){let[r,n]=Cs(t,e);if(n.length>0)throw new Error(`${g} too many terminals, data makes no sense`);return r}var Ho=class t{constructor(e,r){if(typeof e!="number"||!Number.isInteger(e)||e<0)throw new TypeError("Tagged: tag must be a non-negative integer");this.tag=e,this.value=r}static decoder(e){return r=>new t(e,r())}static preserve(...e){let r={};for(let n of e)r[n]=t.decoder(n);return r}};Object.defineProperty(Ho.prototype,Symbol.toStringTag,{value:"Tagged"});function dg(t){return t[Symbol.asyncIterator]!=null}function hg(t,e){let r=0;if(dg(t))return(async function*(){for await(let c of t)await e(c,r++)&&(yield c)})();let n=ho(t),{value:o,done:i}=n.next();if(i===!0)return(function*(){})();let s=e(o,r++);if(typeof s.then=="function")return(async function*(){await s&&(yield o);for(let c of n)await e(c,r++)&&(yield c)})();let a=e;return(function*(){s===!0&&(yield o);for(let c of n)a(c,r++)&&(yield c)})()}var Gl=hg;function pg(t){return t[Symbol.asyncIterator]!=null}function mg(t){if(pg(t))return(async()=>{let n=new Uint8Array(0);for await(let o of t)n=nn([n,o],n.length+o.length);return n})();let e=[],r=0;for(let n of t)e.push(n),r+=n.byteLength;return nn(e,r)}var L=mg;function Vo({enumerable:t=!0,configurable:e=!1}={}){return{enumerable:t,configurable:e,writable:!1}}function*yg(t,e){if(e!=null&&typeof e=="object")if(Array.isArray(e))for(let[r,n]of e.entries()){let o=[...t,r],i=B.asCID(n);i!=null?yield[o.join("/"),i]:typeof n=="object"&&(yield*Ds(n,o))}else{let r=B.asCID(e);r!=null?yield[t.join("/"),r]:yield*Ds(e,t)}}function*Ds(t,e){if(t==null||t instanceof Uint8Array)return;let r=B.asCID(t);r!=null&&(yield[e.join("/"),r]);for(let[n,o]of Object.entries(t)){let i=[...e,n];yield*yg(i,o)}}function*gg(t,e){if(Array.isArray(e))for(let[r,n]of e.entries()){let o=[...t,r];yield o.join("/"),typeof n=="object"&&B.asCID(n)==null&&(yield*Ls(n,o))}else yield*Ls(e,t)}function*Ls(t,e){if(!(t==null||typeof t!="object"))for(let[r,n]of Object.entries(t)){let o=[...e,r];yield o.join("/"),n!=null&&!(n instanceof Uint8Array)&&typeof n=="object"&&B.asCID(n)==null&&(yield*gg(o,n))}}function wg(t,e){let r=t;for(let[n,o]of e.entries()){if(r=r[o],r==null)throw new Error(`Object has no property at ${e.slice(0,n+1).map(s=>`[${JSON.stringify(s)}]`).join("")}`);let i=B.asCID(r);if(i!=null)return{value:i,remaining:e.slice(n+1).join("/")}}return{value:r}}var $s=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:Vo(),bytes:Vo(),value:Vo(),asBlock:Vo()})}links(){return Ds(this.value,[])}tree(){return Ls(this.value,[])}get(e="/"){return wg(this.value,e.split("/").filter(Boolean))}};function Ge({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 $s({cid:e,bytes:t,value:o})}function Ar(t){return e=>new Ms(e,t)}function vr(t){return e=>new Os(e,t)}function Wl(t){return e=>new Rs(e,t)}var hn=class{components;constructor(e,r={}){this.components=e}async*walk(e,r){let n=this.getQueue(),o=Gl(n.toGenerator(r),c=>c!=null),i=!1,s=r?.depth??1/0,a=async c=>{let u=c.cid,f=await L(this.components.blockstore.get(u,c)),p=Ge({cid:u,bytes:f,codec:await this.components.getCodec(u.code)});if(c.depth<s)for(let[,m]of p.links())r?.includeChild?.(m,p)!==!1&&n.add(a,{...c,cid:m,depth:c.depth+1,path:[...c.path,m]}).catch(_=>{i||o.throw(_)});return{block:p,depth:c.depth,path:c.path}};n.add(a,{...r,cid:e,depth:0,path:[e]}).catch(c=>{i||o.throw(c)});try{yield*o}finally{i=!0,n.abort()}}},Ms=class extends hn{getQueue(){return new yr({concurrency:1,sort:(e,r)=>e.options.depth===r.options.depth?0:e.options.depth<r.options.depth?1:-1})}},Os=class extends hn{getQueue(){return new yr({concurrency:1,sort:(e,r)=>e.options.depth===r.options.depth?0:e.options.depth<r.options.depth?-1:1})}},Rs=class extends hn{getQueue(){return new yr({concurrency:1})}};var pn=class{walker;constructor(e){this.walker=e?.walker}async*export(e,r,n,o){let i,s={blockstore:r,getCodec:n};this.walker!=null?i=this.walker(s):i=vr()(s);for await(let a of i.walk(e,o))yield a.block}};var qo=class{components;log;constructor(e){this.components=e,this.log=e.logger.forComponent("helia:car")}async import(e,r){await xf(this.components.blockstore.putMany(po(e.blocks(),({cid:n,bytes:o})=>({cid:n,bytes:o})),r))}async*export(e,r){let n=Array.isArray(e)?e:[e],{writer:o,out:i}=lr.create(n),s=i[Symbol.asyncIterator](),a=new AbortController;for(this._export(n,o,r).catch(c=>{this.log.error("error during streaming export - %e",c),a.abort(c)});;){let{done:c,value:u}=await dr(s.next(),a.signal);if(a.signal.aborted)throw a.signal.reason;if(u!=null&&(yield u),c===!0)break}}async _export(e,r,n){let o=n?.traversal;for(let i of e){if(i.multihash.code===0)continue;let s=n?.exporter??(i.code===112?new mn:new pn),a=i,c=!1;if(o!=null){for await(let{cid:u,bytes:f}of o.traverse(a,this.components.blockstore,this.components.getCodec,n))if(this.log.trace("next CID on path to %c is %c",i,u),a=u,i.equals(u)&&(c=!0),c||n?.includeTraversalBlocks===!0){if(n?.blockFilter?.has(u.multihash.bytes)===!0)continue;n?.blockFilter?.add(u.multihash.bytes),await r.put({cid:u,bytes:f})}}for await(let{cid:u,bytes:f}of s.export(a,this.components.blockstore,this.components.getCodec,n))n?.blockFilter?.has(u.multihash.bytes)!==!0&&u.multihash.code!==0&&(c&&u.equals(a)||(n?.blockFilter?.add(u.multihash.bytes),await r.put({cid:u,bytes:f})))}await r.close()}};var Fs=class{async*export(e,r,n,o){let i=await L(r.get(e,o));yield Ge({cid:e,bytes:i,codec:await n(e.code)})}};var yn=class t extends Error{static name="InvalidTypeError";static code="ERR_INVALID_TYPE";name=t.name;code=t.code;constructor(e="Invalid type"){super(e)}};var Ps=new Float32Array([-0]),xt=new Uint8Array(Ps.buffer);function Yl(t,e,r){Ps[0]=t,e[r]=xt[0],e[r+1]=xt[1],e[r+2]=xt[2],e[r+3]=xt[3]}function Xl(t,e){return xt[0]=t[e],xt[1]=t[e+1],xt[2]=t[e+2],xt[3]=t[e+3],Ps[0]}var zs=new Float64Array([-0]),te=new Uint8Array(zs.buffer);function Kl(t,e,r){zs[0]=t,e[r]=te[0],e[r+1]=te[1],e[r+2]=te[2],e[r+3]=te[3],e[r+4]=te[4],e[r+5]=te[5],e[r+6]=te[6],e[r+7]=te[7]}function Ql(t,e){return te[0]=t[e],te[1]=t[e+1],te[2]=t[e+2],te[3]=t[e+3],te[4]=t[e+4],te[5]=t[e+5],te[6]=t[e+6],te[7]=t[e+7],zs[0]}var bg=BigInt(Number.MAX_SAFE_INTEGER),Eg=BigInt(Number.MIN_SAFE_INTEGER),_e=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 zt;if(e<bg&&e>Eg)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>Zl&&(o=0n,++n>Zl&&(n=0n))),new t(Number(o),Number(n))}static fromNumber(e){if(e===0)return zt;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):zt}},zt=new _e(0,0);zt.toBigInt=function(){return 0n};zt.zzEncode=zt.zzDecode=function(){return this};zt.length=function(){return 1};var Zl=4294967296n;function ed(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 td(t,e,r){if(r-e<1)return"";let o,i=[],s=0,a;for(;e<r;)a=t[e++],a<128?i[s++]=a:a>191&&a<224?i[s++]=(a&31)<<6|t[e++]&63:a>239&&a<365?(a=((a&7)<<18|(t[e++]&63)<<12|(t[e++]&63)<<6|t[e++]&63)-65536,i[s++]=55296+(a>>10),i[s++]=56320+(a&1023)):i[s++]=(a&15)<<12|(t[e++]&63)<<6|t[e++]&63,s>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,i)),s=0);return o!=null?(s>0&&o.push(String.fromCharCode.apply(String,i.slice(0,s))),o.join("")):String.fromCharCode.apply(String,i.slice(0,s))}function js(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 Le(t,e){return RangeError(`index out of range: ${t.pos} + ${e??1} > ${t.len}`)}function Go(t,e){return(t[e-4]|t[e-3]<<8|t[e-2]<<16|t[e-1]<<24)>>>0}var Hs=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(e){this.buf=mo(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,Le(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 Le(this,4);return Go(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Le(this,4);return Go(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Le(this,4);let e=Xl(this.buf,this.pos);return this.pos+=4,e}double(){if(this.pos+8>this.len)throw Le(this,4);let e=Ql(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 Le(this,e);return this.pos+=e,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let e=this.bytes();return td(e,0,e.length)}skip(e){if(typeof e=="number"){if(this.pos+e>this.len)throw Le(this,e);this.pos+=e}else do if(this.pos>=this.len)throw Le(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 _e(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 Le(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 Le(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 Le(this,8);let e=Go(this.buf,this.pos+=4),r=Go(this.buf,this.pos+=4);return new _e(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=If(this.buf,this.pos);return this.pos+=on(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 gn(t){return new Hs(t instanceof Uint8Array?t:t.subarray())}function bt(t,e,r){let n=gn(t);return e.decode(n,void 0,r)}function Vs(t){let e=t??8192,r=e>>>1,n,o=e;return function(s){if(s<1||s>r)return je(s);o+s>e&&(n=je(e),o=0);let a=n.subarray(o,o+=s);return(o&7)!==0&&(o=(o|7)+1),a}}var jt=class{fn;len;next;val;constructor(e,r,n){this.fn=e,this.len=r,this.next=void 0,this.val=n}};function qs(){}var Ws=class{head;tail;len;next;constructor(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}},_g=Vs();function Ag(t){return globalThis.Buffer!=null?je(t):_g(t)}var xn=class{len;head;tail;states;constructor(){this.len=0,this.head=new jt(qs,0,0),this.tail=this.head,this.states=null}_push(e,r,n){return this.tail=this.tail.next=new jt(e,r,n),this.len+=r,this}uint32(e){return this.len+=(this.tail=this.tail.next=new Js((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(Wo,10,_e.fromNumber(e)):this.uint32(e)}sint32(e){return this.uint32((e<<1^e>>31)>>>0)}uint64(e){let r=_e.fromBigInt(e);return this._push(Wo,r.length(),r)}uint64Number(e){return this._push(kf,on(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=_e.fromBigInt(e).zzEncode();return this._push(Wo,r.length(),r)}sint64Number(e){let r=_e.fromNumber(e).zzEncode();return this._push(Wo,r.length(),r)}sint64String(e){return this.sint64(BigInt(e))}bool(e){return this._push(Gs,1,e?1:0)}fixed32(e){return this._push(wn,4,e>>>0)}sfixed32(e){return this.fixed32(e)}fixed64(e){let r=_e.fromBigInt(e);return this._push(wn,4,r.lo)._push(wn,4,r.hi)}fixed64Number(e){let r=_e.fromNumber(e);return this._push(wn,4,r.lo)._push(wn,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(Yl,4,e)}double(e){return this._push(Kl,8,e)}bytes(e){let r=e.length>>>0;return r===0?this._push(Gs,1,0):this.uint32(r)._push(kg,r,e)}string(e){let r=ed(e);return r!==0?this.uint32(r)._push(js,r,e):this._push(Gs,1,0)}fork(){return this.states=new Ws(this),this.head=this.tail=new jt(qs,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 jt(qs,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=Ag(this.len),n=0;for(;e!=null;)e.fn(e.val,r,n),n+=e.len,e=e.next;return r}};function Gs(t,e,r){e[r]=t&255}function vg(t,e,r){for(;t>127;)e[r++]=t&127|128,t>>>=7;e[r]=t}var Js=class extends jt{next;constructor(e,r){super(vg,e,r),this.next=void 0}};function Wo(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 wn(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 kg(t,e,r){e.set(t,r)}globalThis.Buffer!=null&&(xn.prototype.bytes=function(t){let e=t.length>>>0;return this.uint32(e),e>0&&this._push(Ig,e,t),this},xn.prototype.string=function(t){let e=globalThis.Buffer.byteLength(t);return this.uint32(e),e>0&&this._push(Tg,e,t),this});function Ig(t,e,r){e.set(t,r)}function Tg(t,e,r){t.length<40?js(t,e,r):e.utf8Write!=null?e.utf8Write(t,r):e.set(xo(t),r)}function Ys(){return new xn}function Et(t,e){let r=Ys();return e.encode(t,r,{lengthDelimited:!1}),r.finish()}function*_t(t,e,r){let n=gn(t);yield*e.stream(n,void 0,".",r)}var Jo={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function Yo(t,e,r,n,o){return{name:t,type:e,encode:r,decode:n,stream:o}}function Xs(t){function e(i){if(t[i.toString()]==null)throw new Error("Invalid enum value");return t[i]}let r=function(s,a){let c=e(s);a.int32(c)},n=function(s){let a=s.int32();return e(a)},o=function*(s,a){};return Yo("enum",Jo.VARINT,r,n,o)}function At(t,e,r){return Yo("message",Jo.LENGTH_DELIMITED,t,e,r)}var Ze=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var Z;(function(t){let e;(function(a){a.RAW="RAW",a.DIRECTORY="DIRECTORY",a.FILE="FILE",a.METADATA="METADATA",a.SYMLINK="SYMLINK",a.HAMT_SHARD="HAMT_SHARD"})(e=t.Type||(t.Type={}));let r;(function(a){a[a.RAW=0]="RAW",a[a.DIRECTORY=1]="DIRECTORY",a[a.FILE=2]="FILE",a[a.METADATA=3]="METADATA",a[a.SYMLINK=4]="SYMLINK",a[a.HAMT_SHARD=5]="HAMT_SHARD"})(r||(r={})),(function(a){a.codec=()=>Xs(r)})(e=t.Type||(t.Type={}));let n;t.codec=()=>(n==null&&(n=At((a,c,u={})=>{if(u.lengthDelimited!==!1&&c.fork(),a.type!=null&&(c.uint32(8),t.Type.codec().encode(a.type,c)),a.data!=null&&(c.uint32(18),c.bytes(a.data)),a.fileSize!=null&&(c.uint32(24),c.uint64(a.fileSize)),a.blockSizes!=null&&a.blockSizes.length>0)for(let f of a.blockSizes)c.uint32(32),c.uint64(f);a.hashType!=null&&(c.uint32(40),c.uint64(a.hashType)),a.fanOut!=null&&(c.uint32(48),c.uint64(a.fanOut)),a.mode!=null&&(c.uint32(56),c.uint32(a.mode)),a.mtime!=null&&(c.uint32(66),bn.codec().encode(a.mtime,c)),u.lengthDelimited!==!1&&c.ldelim()},(a,c,u={})=>{let f={blockSizes:[]},p=c==null?a.len:a.pos+c;for(;a.pos<p;){let m=a.uint32();switch(m>>>3){case 1:{f.type=t.Type.codec().decode(a);break}case 2:{f.data=a.bytes();break}case 3:{f.fileSize=a.uint64();break}case 4:{if(u.limits?.blockSizes!=null&&f.blockSizes.length===u.limits.blockSizes)throw new Ze('Decode error - repeated field "blockSizes" had too many elements');f.blockSizes.push(a.uint64());break}case 5:{f.hashType=a.uint64();break}case 6:{f.fanOut=a.uint64();break}case 7:{f.mode=a.uint32();break}case 8:{f.mtime=bn.codec().decode(a,a.uint32(),{limits:u.limits?.mtime});break}default:{a.skipType(m&7);break}}}return f},function*(a,c,u,f={}){let p={blockSizes:0},m=c==null?a.len:a.pos+c;for(u!=="."&&(yield{field:u.endsWith(".")?u.substring(0,u.length-1):u,type:"start",message:"UnixFS"});a.pos<m;){let _=a.uint32();switch(_>>>3){case 1:{yield{field:`${u}type`,value:t.Type.codec().decode(a)};break}case 2:{yield{field:`${u}data`,value:a.bytes()};break}case 3:{yield{field:`${u}fileSize`,value:a.uint64()};break}case 4:{if(f.limits?.blockSizes!=null&&p.blockSizes===f.limits.blockSizes)throw new Ze('Streaming decode error - repeated field "blockSizes" had too many elements');yield{field:`${u}blockSizes[]`,index:p.blockSizes,value:a.uint64()},p.blockSizes++;break}case 5:{yield{field:`${u}hashType`,value:a.uint64()};break}case 6:{yield{field:`${u}fanOut`,value:a.uint64()};break}case 7:{yield{field:`${u}mode`,value:a.uint32()};break}case 8:{yield*bn.codec().stream(a,a.uint32(),`${u}mtime.`,{limits:f.limits?.mtime});break}default:{a.skipType(_&7);break}}}u!=="."&&(yield{field:u.endsWith(".")?u.substring(0,u.length-1):u,type:"end",message:"UnixFS"})})),n);function o(a){return Et(a,t.codec())}t.encode=o;function i(a,c){return bt(a,t.codec(),c)}t.decode=i;function s(a,c){return _t(a,t.codec(),c)}t.stream=s})(Z||(Z={}));var bn;(function(t){let e;t.codec=()=>(e==null&&(e=At((i,s,a={})=>{a.lengthDelimited!==!1&&s.fork(),i.seconds!=null&&(s.uint32(8),s.int64(i.seconds)),i.fractionalNanoseconds!=null&&(s.uint32(21),s.fixed32(i.fractionalNanoseconds)),a.lengthDelimited!==!1&&s.ldelim()},(i,s)=>{let a={},c=s==null?i.len:i.pos+s;for(;i.pos<c;){let u=i.uint32();switch(u>>>3){case 1:{a.seconds=i.int64();break}case 2:{a.fractionalNanoseconds=i.fixed32();break}default:{i.skipType(u&7);break}}}return a},function*(i,s,a){let c=s==null?i.len:i.pos+s;for(a!=="."&&(yield{field:a.endsWith(".")?a.substring(0,a.length-1):a,type:"start",message:"UnixTime"});i.pos<c;){let u=i.uint32();switch(u>>>3){case 1:{yield{field:`${a}seconds`,value:i.int64()};break}case 2:{yield{field:`${a}fractionalNanoseconds`,value:i.fixed32()};break}default:{i.skipType(u&7);break}}}a!=="."&&(yield{field:a.endsWith(".")?a.substring(0,a.length-1):a,type:"end",message:"UnixTime"})})),e);function r(i){return Et(i,t.codec())}t.encode=r;function n(i,s){return bt(i,t.codec(),s)}t.decode=n;function o(i,s){return _t(i,t.codec(),s)}t.stream=o})(bn||(bn={}));var nd;(function(t){let e;t.codec=()=>(e==null&&(e=At((i,s,a={})=>{a.lengthDelimited!==!1&&s.fork(),i.mimeType!=null&&(s.uint32(10),s.string(i.mimeType)),a.lengthDelimited!==!1&&s.ldelim()},(i,s)=>{let a={},c=s==null?i.len:i.pos+s;for(;i.pos<c;){let u=i.uint32();u>>>3===1?a.mimeType=i.string():i.skipType(u&7)}return a},function*(i,s,a){let c=s==null?i.len:i.pos+s;for(a!=="."&&(yield{field:a.endsWith(".")?a.substring(0,a.length-1):a,type:"start",message:"Metadata"});i.pos<c;){let u=i.uint32();u>>>3===1?yield{field:`${a}mimeType`,value:i.string()}:i.skipType(u&7)}a!=="."&&(yield{field:a.endsWith(".")?a.substring(0,a.length-1):a,type:"end",message:"Metadata"})})),e);function r(i){return Et(i,t.codec())}t.encode=r;function n(i,s){return bt(i,t.codec(),s)}t.decode=n;function o(i,s){return _t(i,t.codec(),s)}t.stream=o})(nd||(nd={}));var vt;(function(t){let e;t.codec=()=>(e==null&&(e=At((i,s,a={})=>{a.lengthDelimited!==!1&&s.fork(),i.hash!=null&&(s.uint32(10),s.bytes(i.hash)),i.name!=null&&(s.uint32(18),s.string(i.name)),i.tSize!=null&&(s.uint32(24),s.uint64(i.tSize)),a.lengthDelimited!==!1&&s.ldelim()},(i,s)=>{let a={},c=s==null?i.len:i.pos+s;for(;i.pos<c;){let u=i.uint32();switch(u>>>3){case 1:{a.hash=i.bytes();break}case 2:{a.name=i.string();break}case 3:{a.tSize=i.uint64();break}default:{i.skipType(u&7);break}}}return a},function*(i,s,a){let c=s==null?i.len:i.pos+s;for(a!=="."&&(yield{field:a.endsWith(".")?a.substring(0,a.length-1):a,type:"start",message:"Link"});i.pos<c;){let u=i.uint32();switch(u>>>3){case 1:{yield{field:`${a}hash`,value:i.bytes()};break}case 2:{yield{field:`${a}name`,value:i.string()};break}case 3:{yield{field:`${a}tSize`,value:i.uint64()};break}default:{i.skipType(u&7);break}}}a!=="."&&(yield{field:a.endsWith(".")?a.substring(0,a.length-1):a,type:"end",message:"Link"})})),e);function r(i){return Et(i,t.codec())}t.encode=r;function n(i,s){return bt(i,t.codec(),s)}t.decode=n;function o(i,s){return _t(i,t.codec(),s)}t.stream=o})(vt||(vt={}));var kr;(function(t){let e;t.codec=()=>(e==null&&(e=At((i,s,a={})=>{if(a.lengthDelimited!==!1&&s.fork(),i.data!=null&&(s.uint32(10),Z.codec().encode(i.data,s)),i.links!=null&&i.links.length>0)for(let c of i.links)s.uint32(18),vt.codec().encode(c,s);a.lengthDelimited!==!1&&s.ldelim()},(i,s,a={})=>{let c={links:[]},u=s==null?i.len:i.pos+s;for(;i.pos<u;){let f=i.uint32();switch(f>>>3){case 1:{c.data=Z.codec().decode(i,i.uint32(),{limits:a.limits?.data});break}case 2:{if(a.limits?.links!=null&&c.links.length===a.limits.links)throw new Ze('Decode error - repeated field "links" had too many elements');c.links.push(vt.codec().decode(i,i.uint32(),{limits:a.limits?.links$}));break}default:{i.skipType(f&7);break}}}return c},function*(i,s,a,c={}){let u={links:0},f=s==null?i.len:i.pos+s;for(a!=="."&&(yield{field:a.endsWith(".")?a.substring(0,a.length-1):a,type:"start",message:"Node"});i.pos<f;){let p=i.uint32();switch(p>>>3){case 1:{yield*Z.codec().stream(i,i.uint32(),`${a}data.`,{limits:c.limits?.data});break}case 2:{if(c.limits?.links!=null&&u.links===c.limits.links)throw new Ze('Streaming decode error - repeated field "links" had too many elements');for(let m of vt.codec().stream(i,i.uint32(),`${a}links[].`,{limits:c.limits?.links$}))yield{...m,index:u.links};u.links++;break}default:{i.skipType(p&7);break}}}a!=="."&&(yield{field:a.endsWith(".")?a.substring(0,a.length-1):a,type:"end",message:"Node"})})),e);function r(i){return Et(i,t.codec())}t.encode=r;function n(i,s){return bt(i,t.codec(),s)}t.decode=n;function o(i,s){return _t(i,t.codec(),s)}t.stream=o})(kr||(kr={}));var od;(function(t){let e;t.codec=()=>(e==null&&(e=At((i,s,a={})=>{if(a.lengthDelimited!==!1&&s.fork(),i.links!=null&&i.links.length>0)for(let c of i.links)s.uint32(18),vt.codec().encode(c,s);i.data!=null&&(s.uint32(10),Z.codec().encode(i.data,s)),a.lengthDelimited!==!1&&s.ldelim()},(i,s,a={})=>{let c={links:[]},u=s==null?i.len:i.pos+s;for(;i.pos<u;){let f=i.uint32();switch(f>>>3){case 2:{if(a.limits?.links!=null&&c.links.length===a.limits.links)throw new Ze('Decode error - repeated field "links" had too many elements');c.links.push(vt.codec().decode(i,i.uint32(),{limits:a.limits?.links$}));break}case 1:{c.data=Z.codec().decode(i,i.uint32(),{limits:a.limits?.data});break}default:{i.skipType(f&7);break}}}return c},function*(i,s,a,c={}){let u={links:0},f=s==null?i.len:i.pos+s;for(a!=="."&&(yield{field:a.endsWith(".")?a.substring(0,a.length-1):a,type:"start",message:"LegacyNode"});i.pos<f;){let p=i.uint32();switch(p>>>3){case 2:{if(c.limits?.links!=null&&u.links===c.limits.links)throw new Ze('Streaming decode error - repeated field "links" had too many elements');for(let m of vt.codec().stream(i,i.uint32(),`${a}links[].`,{limits:c.limits?.links$}))yield{...m,index:u.links};u.links++;break}case 1:{yield*Z.codec().stream(i,i.uint32(),`${a}data.`,{limits:c.limits?.data});break}default:{i.skipType(p&7);break}}}a!=="."&&(yield{field:a.endsWith(".")?a.substring(0,a.length-1):a,type:"end",message:"LegacyNode"})})),e);function r(i){return Et(i,t.codec())}t.encode=r;function n(i,s){return bt(i,t.codec(),s)}t.decode=n;function o(i,s){return _t(i,t.codec(),s)}t.stream=o})(od||(od={}));var id={RAW:"raw",DIRECTORY:"directory",FILE:"file",METADATA:"metadata",SYMLINK:"symlink",HAMT_SHARD:"hamt-sharded-directory"},Bg=["directory","hamt-sharded-directory"],sd=parseInt("0644",8),ad=parseInt("0755",8),We=class t{static unmarshal(e){let r=Z.decode(e),n=new t({type:id[r.type!=null?r.type.toString():"FILE"],data:r.data,blockSizes:r.blockSizes,mode:r.mode,mtime:r.mtime!=null?{secs:r.mtime.seconds??0n,nsecs:r.mtime.fractionalNanoseconds}:void 0,fanout:r.fanOut});return n._originalMode=r.mode??0,n}type;data;blockSizes;hashType;fanout;mtime;_mode;_originalMode;constructor(e={type:"file"}){let{type:r,data:n,blockSizes:o,hashType:i,fanout:s,mtime:a,mode:c}=e;if(r!=null&&!Object.values(id).includes(r))throw new yn("Type: "+r+" is not valid");this.type=r??"file",this.hashType=i,this.fanout=s,this.blockSizes=o??[],this._originalMode=0,this.mode=c,this.mtime=a,n!=null&&(this.data=mo(n))}set mode(e){e==null?this._mode=this.isDirectory()?ad:sd:this._mode=e&4095}get mode(){return this._mode}isDirectory(){return Bg.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=Z.Type.RAW;break;case"directory":e=Z.Type.DIRECTORY;break;case"file":e=Z.Type.FILE;break;case"metadata":e=Z.Type.METADATA;break;case"symlink":e=Z.Type.SYMLINK;break;case"hamt-sharded-directory":e=Z.Type.HAMT_SHARD;break;default:throw new yn(`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===sd&&!this.isDirectory()&&(n=void 0),n===ad&&this.isDirectory()&&(n=void 0));let o;return this.mtime!=null&&(o={seconds:this.mtime.secs,fractionalNanoseconds:this.mtime.nsecs}),Z.encode({type:e,data:r,fileSize:this.type==="file"||this.type==="raw"?this.fileSize():void 0,blockSizes:this.blockSizes,hashType:this.hashType,fanOut:this.fanout,mode:n,mtime:o})}};var En=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"},Xo=class extends Error{static name="NotDescendantError";name="NotDescendantError"},Ir=class extends Error{static name="InvalidTraversalError";name="InvalidTraversalError"};function Ug(t){return t.cid.code===85}function Ng(t){return t.cid.code===112}function Cg(t){if(Ug(t))return!0;if(Ng(t)&&t.value.Data!=null){let e=We.unmarshal(t.value.Data);return e.type==="file"||e.type==="raw"}else throw new En("Encountered non raw/dag-pb CID in UnixFS DAG")}var mn=class{options;constructor(e){this.options=e}async*export(e,r,n,o){if(e.code!==112&&e.code!==85)throw new En("Target CID was not UnixFS - use the SubGraphExporter to export arbitrary graphs");let i=Ar()({blockstore:r,getCodec:n}),s=this.options?.offset??0,a=this.options?.length??1/0,c=this.options?.listingOnly??!1;if(s<0)throw new Ot("Offset cannot be negative");if(a<0)throw new Ot("Length cannot be negative");let u,f=new AbortController,p=Lf([f.signal,o?.signal]);f.signal;function m(_,S){if(u==null&&(u=Cg(S)),!u){let z=S.value.Links.find(Je=>Je.Hash.equals(_)),Q=We.unmarshal(S.value.Data??new Uint8Array);return Q.type==="directory"?!c:Q.type==="hamt-sharded-directory"&&c?z?.Name?.length===2:!0}let T=S.value.Links.findIndex(z=>z.Hash.equals(_)),v=We.unmarshal(S.value.Data??new Uint8Array),I=s,O=I+a,P=Number([...v.blockSizes].slice(0,T).reduce((z,Q)=>z+Q,0n)),M=P+Number(v.blockSizes[T]);return I>=P&&I<M||O>=P&&O<M||I<=P&&O>=M}try{for await(let _ of i.walk(e,{...o,includeChild:m,signal:p}))yield _.block}finally{f.abort(),p.clear()}}};function cd(t){return t!=null&&t?.asCID===t}var Ks=class{haystack;needle;options;walker;constructor(...e){if(cd(e[0]))cd(e[1])?(this.haystack=e[0],this.needle=e[1],this.options=e[2]):(this.needle=e[0],this.options=e[1]);else throw new Ot("needle must be specified");this.walker=this.options?.walker}async*traverse(e,r,n,o){let i=this.haystack??e,s,a={blockstore:r,getCodec:n};this.walker!=null?s=this.walker(a):this.options?.strategy==="breadth-first"?s=vr()(a):s=Ar()(a);for await(let c of s.walk(i,o))if(c.block.cid.equals(this.needle)){for(let u of c.path){let f=await L(r.get(u,o));yield Ge({cid:u,bytes:f,codec:await n(u.code)})}return}throw new Ir(`${this.needle} was not a child of ${i}`)}};var Qs=class{path;constructor(e){this.path=e}async*traverse(e,r,n,o){if(!this.path.some(s=>s.equals(e)))throw new Ir(`CIDPath traversal must include ${e}`);let i;for(let s of this.path){if(i!=null){let u=!1;for(let[,f]of i.links())if(f.equals(s)){u=!0;break}if(!u)throw new Xo(`${s} is not a child of ${i.cid}`)}let a=await L(r.get(s,o)),c=Ge({cid:s,bytes:a,codec:await n(s.code)});i=c,yield c}}};var Dg=new TextDecoder;function Zs(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 Ko(t,e){let r;[r,e]=Zs(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 ud(t,e){let r;return[r,e]=Zs(t,e),[r&7,r>>3,e]}function Lg(t){let e={},r=t.length,n=0;for(;n<r;){let o,i;if([o,i,n]=ud(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]=Ko(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]=Ko(t,n),e.Name=Dg.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]=Zs(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 fd(t){let e=t.length,r=0,n,o=!1,i;for(;r<e;){let a,c;if([a,c,r]=ud(t,r),a!==2)throw new Error(`protobuf: (PBNode) invalid wireType, expected 2, got ${a}`);if(c===1){if(i)throw new Error("protobuf: (PBNode) duplicate Data section");[i,r]=Ko(t,r),n&&(o=!0)}else if(c===2){if(o)throw new Error("protobuf: (PBNode) duplicate Links section");n||(n=[]);let u;[u,r]=Ko(t,r),n.push(Lg(u))}else throw new Error(`protobuf: (PBNode) invalid fieldNumber, expected 1 or 2, got ${c}`)}if(r>e)throw new Error("protobuf: (PBNode) unexpected end of data");let s={};return i&&(s.Data=i),s.Links=n||[],s}var hd=new TextEncoder,ld=2**32,$g=2**31;function Mg(t,e){let r=e.length;if(typeof t.Tsize=="number"){if(t.Tsize<0)throw new Error("Tsize cannot be negative");if(!Number.isSafeInteger(t.Tsize))throw new Error("Tsize too large for encoding");r=_n(e,r,t.Tsize)-1,e[r]=24}if(typeof t.Name=="string"){let n=hd.encode(t.Name);r-=n.length,e.set(n,r),r=_n(e,r,n.length)-1,e[r]=18}return t.Hash&&(r-=t.Hash.length,e.set(t.Hash,r),r=_n(e,r,t.Hash.length)-1,e[r]=10),e.length-r}function dd(t,e,r){return t-=e.Data.length,r.set(e.Data,t),t=_n(r,t,e.Data.length)-1,r[t]=10,t}function pd(t,e){let r=Rg(t),n=new Uint8Array(r),o=r,i=e?.fieldOrder==="data-first"?e.fieldOrder:"links-first";if(t.Data&&i==="links-first"&&(o=dd(o,t,n)),t.Links)for(let s=t.Links.length-1;s>=0;s--){let a=Mg(t.Links[s],n.subarray(0,o));o-=a,o=_n(n,o,a)-1,n[o]=18}return t.Data&&i==="data-first"&&(o=dd(o,t,n)),n}function Og(t){let e=0;if(t.Hash){let r=t.Hash.length;e+=1+r+Tr(r)}if(typeof t.Name=="string"){let r=hd.encode(t.Name).length;e+=1+r+Tr(r)}return typeof t.Tsize=="number"&&(e+=1+Tr(t.Tsize)),e}function Rg(t){let e=0;if(t.Data){let r=t.Data.length;e+=1+r+Tr(r)}if(t.Links)for(let r of t.Links){let n=Og(r);e+=1+n+Tr(n)}return e}function _n(t,e,r){e-=Tr(r);let n=e;for(;r>=$g;)t[e++]=r&127|128,r/=128;for(;r>=128;)t[e++]=r&127|128,r>>>=7;return t[e]=r,n}function Tr(t){return t%2===0&&t++,Math.floor((Fg(t)+6)/7)}function Fg(t){let e=0;return t>=ld&&(t=Math.floor(t/ld),e=32),t>=65536&&(t>>>=16,e+=16),t>=256&&(t>>>=8,e+=8),e+Pg[t]}var Pg=[0,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8];var zg=["Data","Links"],jg=["Hash","Name","Tsize"],md=new TextEncoder;function Hg(t,e){if(t===e)return 0;let r=t.Name?md.encode(t.Name):[],n=e.Name?md.encode(e.Name):[],o=r.length,i=n.length;for(let s=0,a=Math.min(o,i);s<a;++s)if(r[s]!==n[s]){o=r[s],i=n[s];break}return o<i?-1:i<o?1:0}function yd(t,e){return!Object.keys(t).some(r=>!e.includes(r))}function gd(t){if(!t||typeof t!="object"||Array.isArray(t)||t instanceof Uint8Array||t["/"]&&t["/"]===t.bytes)throw new TypeError("Invalid DAG-PB form");if(!yd(t,zg))throw new TypeError("Invalid DAG-PB form (extraneous properties)");if(t.Data!==void 0&&!(t.Data instanceof Uint8Array))throw new TypeError("Invalid DAG-PB form (Data must be bytes)");if(!Array.isArray(t.Links))throw new TypeError("Invalid DAG-PB form (Links must be a list)");for(let e=0;e<t.Links.length;e++){let r=t.Links[e];if(!r||typeof r!="object"||Array.isArray(r)||r instanceof Uint8Array||r["/"]&&r["/"]===r.bytes)throw new TypeError("Invalid DAG-PB form (bad link)");if(!yd(r,jg))throw new TypeError("Invalid DAG-PB form (extraneous properties on link)");if(r.Hash===void 0)throw new TypeError("Invalid DAG-PB form (link must have a Hash)");if(r.Hash==null||!r.Hash["/"]||r.Hash["/"]!==r.Hash.bytes)throw new TypeError("Invalid DAG-PB form (link Hash must be a CID)");if(r.Name!==void 0&&typeof r.Name!="string")throw new TypeError("Invalid DAG-PB form (link Name must be a string)");if(r.Tsize!==void 0){if(typeof r.Tsize!="number"||r.Tsize%1!==0)throw new TypeError("Invalid DAG-PB form (link Tsize must be an integer)");if(r.Tsize<0)throw new TypeError("Invalid DAG-PB form (link Tsize cannot be negative)")}if(e>0&&Hg(r,t.Links[e-1])===-1)throw new TypeError("Invalid DAG-PB form (links must be sorted by Name bytes)")}}function wd(t){return t instanceof ArrayBuffer?new Uint8Array(t,0,t.byteLength):t}var Br=112;function xd(t,e){gd(t);let r={};return t.Links&&(r.Links=t.Links.map(n=>{let o={};return n.Hash&&(o.Hash=n.Hash.bytes),n.Name!==void 0&&(o.Name=n.Name),n.Tsize!==void 0&&(o.Tsize=n.Tsize),o})),t.Data&&(r.Data=t.Data),pd(r,e)}function Qo(t){let e=wd(t),r=fd(e),n={};return r.Data&&(n.Data=r.Data),r.Links&&(n.Links=r.Links.map(o=>{let i={};try{i.Hash=B.decode(o.Hash)}catch{}if(!i.Hash)throw new Error("Invalid Hash field found in link, expected CID");return o.Name!==void 0&&(i.Name=o.Name),o.Tsize!==void 0&&(i.Tsize=o.Tsize),i})),n}var Sr=class t extends Error{static name="BadPathError";static code="ERR_BAD_PATH";name=t.name;code=t.code;constructor(e="Bad path"){super(e)}},ae=class t extends Error{static name="NotFoundError";static code="ERR_NOT_FOUND";name=t.name;code=t.code;constructor(e="Not found"){super(e)}},Ur=class t extends Error{static name="NoResolverError";static code="ERR_NO_RESOLVER";name=t.name;code=t.code;constructor(e="No resolver"){super(e)}},F=class t extends Error{static name="NotUnixFSError";static code="ERR_NOT_UNIXFS";name=t.name;code=t.code;constructor(e="Not UnixFS"){super(e)}},ei=class t extends Error{static name="OverReadError";static code="ERR_OVER_READ";name=t.name;code=t.code;constructor(e="Over read"){super(e)}},ti=class t extends Error{static name="UnderReadError";static code="ERR_UNDER_READ";name=t.name;code=t.code;constructor(e="Under read"){super(e)}},et=class t extends Error{static name="InvalidParametersError";static code="ERR_INVALID_PARAMS";name=t.name;code=t.code;constructor(e="Invalid parameters"){super(e)}};var Ed=42;function Vg(t){return t instanceof ArrayBuffer?new Uint8Array(t,0,t.byteLength):t}function qg(t){if(t.asCID!==t&&t["/"]!==t.bytes)return null;let e=B.asCID(t);if(!e)return null;let r=new Uint8Array(e.bytes.byteLength+1);return r.set(e.bytes,1),[new y(l.tag,Ed),new y(l.bytes,r)]}function Gg(){throw new Error("`undefined` is not supported by the IPLD Data Model and cannot be encoded")}function Wg(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 Jg(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 bd={float64:!0,typeEncoders:{Map:Jg,Object:qg,undefined:Gg,number:Wg}},mk={...bd,typeEncoders:{...bd.typeEncoders}};function Yg(t){let e=t();if(e[0]!==0)throw new Error("Invalid CID for CBOR tag 42; expected leading 0x00");return B.decode(e.subarray(1))}var ea={allowIndefinite:!1,coerceUndefinedToNull:!0,allowNaN:!1,allowInfinity:!1,allowBigInt:!0,strict:!0,useMaps:!1,rejectDuplicateMapKeys:!0,tags:{[Ed]:Yg}},yk={...ea,tags:{...ea.tags}};var ri=113;var ni=t=>dn(Vg(t),ea);var _d=class extends Array{constructor(){super(),this.inRecursive=[]}prefix(e){let r=this.inRecursive[this.inRecursive.length-1];r&&(l.equals(r.type,l.array)&&(r.elements++,r.elements!==1&&e.push([44])),l.equals(r.type,l.map)&&(r.elements++,r.elements!==1&&(r.elements%2===1?e.push([44]):e.push([58]))))}[l.uint.major](e,r){this.prefix(e);let n=String(r.value),o=[];for(let i=0;i<n.length;i++)o[i]=n.charCodeAt(i);e.push(o)}[l.negint.major](e,r){this[l.uint.major](e,r)}[l.bytes.major](e,r){throw new Error(`${Ft} unsupported type: Uint8Array`)}[l.string.major](e,r){this.prefix(e);let n=cn(JSON.stringify(r.value));e.push(n.length>32?Rt(n):n)}[l.array.major](e,r){this.prefix(e),this.inRecursive.push({type:l.array,elements:0}),e.push([91])}[l.map.major](e,r){this.prefix(e),this.inRecursive.push({type:l.map,elements:0}),e.push([123])}[l.tag.major](e,r){}[l.float.major](e,r){if(r.type.name==="break"){let s=this.inRecursive.pop();if(s){if(l.equals(s.type,l.array))e.push([93]);else if(l.equals(s.type,l.map))e.push([125]);else throw new Error("Unexpected recursive type; this should not happen!");return}throw new Error("Unexpected break; this should not happen!")}if(r.value===void 0)throw new Error(`${Ft} unsupported type: undefined`);if(this.prefix(e),r.type.name==="true"){e.push([116,114,117,101]);return}else if(r.type.name==="false"){e.push([102,97,108,115,101]);return}else if(r.type.name==="null"){e.push([110,117,108,108]);return}if(typeof r.value=="number"&&!Number.isFinite(r.value))throw new Error(`${Ft} unsupported type: ${r.value}`);let n=String(r.value),o=[],i=!1;for(let s=0;s<n.length;s++)o[s]=n.charCodeAt(s),!i&&(o[s]===46||o[s]===101||o[s]===69)&&(i=!0);i||(o.push(46),o.push(48)),e.push(o)}};var Ad=1e3,Nr=class{constructor(e,r={}){this._pos=0,this.data=e,this.options=r,this.modeStack=["value"],this.lastToken=""}pos(){return this._pos}done(){return this._pos>=this.data.length}ch(){return this.data[this._pos]}currentMode(){return this.modeStack[this.modeStack.length-1]}skipWhitespace(){let e=this.ch();for(;e===32||e===9||e===13||e===10;)e=this.data[++this._pos]}expect(e){if(this.data.length-this._pos<e.length)throw new Error(`${g} unexpected end of input at position ${this._pos}`);for(let r=0;r<e.length;r++)if(this.data[this._pos++]!==e[r])throw new Error(`${g} unexpected token at position ${this._pos}, expected to find '${String.fromCharCode(...e)}'`)}parseNumber(){let e=this._pos,r=!1,n=!1,o=a=>{for(;!this.done();){let c=this.ch();if(a.includes(c))this._pos++;else break}};if(this.ch()===45&&(r=!0,this._pos++),this.ch()===48)if(this._pos++,this.ch()===46)this._pos++,n=!0;else return new y(l.uint,0,this._pos-e);if(o([48,49,50,51,52,53,54,55,56,57]),r&&this._pos===e+1)throw new Error(`${g} unexpected token at position ${this._pos}`);if(!this.done()&&this.ch()===46){if(n)throw new Error(`${g} unexpected token at position ${this._pos}`);n=!0,this._pos++,o([48,49,50,51,52,53,54,55,56,57])}if(!this.done()&&(this.ch()===101||this.ch()===69)&&(n=!0,this._pos++,!this.done()&&(this.ch()===43||this.ch()===45)&&this._pos++,o([48,49,50,51,52,53,54,55,56,57])),this._pos-e>Ad)throw new Error(`${g} number at position ${e} exceeds ${Ad} characters`);let i=String.fromCharCode.apply(null,this.data.subarray(e,this._pos)),s=parseFloat(i);if(n){if(this.options.allowInfinity===!1&&!Number.isFinite(s))throw new Error(`${g} Infinity values are not supported`);return new y(l.float,s,this._pos-e)}if(this.options.allowBigInt!==!0||Number.isSafeInteger(s)){if(!Number.isFinite(s))throw new Error(`${g} integer at position ${e} is too large for a Number, use allowBigInt`);return new y(s>=0?l.uint:l.negint,s,this._pos-e)}return new y(s>=0?l.uint:l.negint,BigInt(i),this._pos-e)}parseString(){if(this.ch()!==34)throw new Error(`${g} unexpected character at position ${this._pos}; this shouldn't happen`);this._pos++;for(let i=this._pos,s=0;i<this.data.length&&s<65536;i++,s++){let a=this.data[i];if(a===92||a<32||a>=128)break;if(a===34){let c=String.fromCharCode.apply(null,this.data.subarray(this._pos,i));return this._pos=i+1,new y(l.string,c,s)}}let e=this._pos,r=[],n=()=>{if(this._pos+4>=this.data.length)throw new Error(`${g} unexpected end of unicode escape sequence at position ${this._pos}`);let i=0;for(let s=0;s<4;s++){let a=this.ch();if(a>=48&&a<=57)a-=48;else if(a>=97&&a<=102)a=a-97+10;else if(a>=65&&a<=70)a=a-65+10;else throw new Error(`${g} unexpected unicode escape character at position ${this._pos}`);i=i*16+a,this._pos++}return i},o=()=>{let i=this.ch(),s=null,a=i>239?4:i>223?3:i>191?2:1;if(this._pos+a>this.data.length)throw new Error(`${g} unexpected unicode sequence at position ${this._pos}`);let c,u,f,p;switch(a){case 1:i<128&&(s=i);break;case 2:c=this.data[this._pos+1],(c&192)===128&&(p=(i&31)<<6|c&63,p>127&&(s=p));break;case 3:c=this.data[this._pos+1],u=this.data[this._pos+2],(c&192)===128&&(u&192)===128&&(p=(i&15)<<12|(c&63)<<6|u&63,p>2047&&(p<55296||p>57343)&&(s=p));break;case 4:c=this.data[this._pos+1],u=this.data[this._pos+2],f=this.data[this._pos+3],(c&192)===128&&(u&192)===128&&(f&192)===128&&(p=(i&15)<<18|(c&63)<<12|(u&63)<<6|f&63,p>65535&&p<1114112&&(s=p))}if(s===null){if(this.options.strictUtf8===!0)throw new Error(`${g} invalid UTF-8 in text string at position ${this._pos}`);s=65533,a=1}else s>65535&&(s-=65536,r.push(s>>>10&1023|55296),s=56320|s&1023);r.push(s),this._pos+=a};for(;!this.done();){let i=this.ch(),s;switch(i){case 92:if(this._pos++,this.done())throw new Error(`${g} unexpected string termination at position ${this._pos}`);switch(s=this.ch(),this._pos++,s){case 34:case 39:case 92:case 47:r.push(s);break;case 98:r.push(8);break;case 116:r.push(9);break;case 110:r.push(10);break;case 102:r.push(12);break;case 114:r.push(13);break;case 117:r.push(n());break;default:throw new Error(`${g} unexpected string escape character at position ${this._pos}`)}break;case 34:return this._pos++,new y(l.string,Gf(r),this._pos-e);default:if(i<32)throw new Error(`${g} invalid control character at position ${this._pos}`);i<128?(r.push(i),this._pos++):o()}}throw new Error(`${g} unexpected end of string at position ${this._pos}`)}parseValue(){switch(this.ch()){case 123:return this.modeStack.push("obj-start"),this._pos++,new y(l.map,1/0,1);case 91:return this.modeStack.push("array-start"),this._pos++,new y(l.array,1/0,1);case 34:return this.parseString();case 110:return this.expect([110,117,108,108]),new y(l.null,null,4);case 102:return this.expect([102,97,108,115,101]),new y(l.false,!1,5);case 116:return this.expect([116,114,117,101]),new y(l.true,!0,4);case 45:case 48:case 49:case 50:case 51:case 52:case 53:case 54:case 55:case 56:case 57:return this.parseNumber();default:throw new Error(`${g} unexpected character at position ${this._pos}`)}}next(){switch(this.skipWhitespace(),this.currentMode()){case"value":return this.modeStack.pop(),this.parseValue();case"array-value":{if(this.modeStack.pop(),this.ch()===93)return this._pos++,this.skipWhitespace(),new y(l.break,void 0,1);if(this.ch()!==44)throw new Error(`${g} unexpected character at position ${this._pos}, was expecting array delimiter but found '${String.fromCharCode(this.ch())}'`);return this._pos++,this.modeStack.push("array-value"),this.skipWhitespace(),this.parseValue()}case"array-start":return this.modeStack.pop(),this.ch()===93?(this._pos++,this.skipWhitespace(),new y(l.break,void 0,1)):(this.modeStack.push("array-value"),this.skipWhitespace(),this.parseValue());case"obj-key":if(this.ch()===125)return this.modeStack.pop(),this._pos++,this.skipWhitespace(),new y(l.break,void 0,1);if(this.ch()!==44)throw new Error(`${g} unexpected character at position ${this._pos}, was expecting object delimiter but found '${String.fromCharCode(this.ch())}'`);this._pos++,this.skipWhitespace();case"obj-start":{if(this.modeStack.pop(),this.ch()===125)return this._pos++,this.skipWhitespace(),new y(l.break,void 0,1);let e=this.parseString();if(this.skipWhitespace(),this.ch()!==58)throw new Error(`${g} unexpected character at position ${this._pos}, was expecting key/value delimiter ':' but found '${String.fromCharCode(this.ch())}'`);return this._pos++,this.modeStack.push("obj-value"),e}case"obj-value":return this.modeStack.pop(),this.modeStack.push("obj-key"),this.skipWhitespace(),this.parseValue();default:throw new Error(`${g} unexpected parse state at position ${this._pos}; this shouldn't happen`)}}};function ta(t,e){return e=Object.assign({tokenizer:new Nr(t,e)},e),dn(t,e)}function Qg(t){return t instanceof ArrayBuffer?new Uint8Array(t,0,t.byteLength):t}var ra=class extends Nr{constructor(e,r){super(e,r),this.tokenBuffer=[]}done(){return this.tokenBuffer.length===0&&super.done()}_next(){return this.tokenBuffer.length>0?this.tokenBuffer.pop():super.next()}next(){let e=this._next();if(l.equals(e.type,l.map)){let r=this._next();if(l.equals(r.type,l.string)&&r.value==="/"){let n=this._next();if(l.equals(n.type,l.string)){let o=this._next();if(!l.equals(o.type,l.break))throw new Error("Invalid encoded CID form");return this.tokenBuffer.push(n),new y(l.tag,42,0)}if(l.equals(n.type,l.map)){let o=this._next();if(l.equals(o.type,l.string)&&o.value==="bytes"){let i=this._next();if(l.equals(i.type,l.string)){for(let a=0;a<2;a++){let c=this._next();if(!l.equals(c.type,l.break))throw new Error("Invalid encoded Bytes form")}let s=fs.decode(`m${i.value}`);return new y(l.bytes,s,i.value.length)}this.tokenBuffer.push(i)}this.tokenBuffer.push(o)}this.tokenBuffer.push(n)}this.tokenBuffer.push(r)}return e}},vd={allowIndefinite:!1,allowUndefined:!1,allowNaN:!1,allowInfinity:!1,allowBigInt:!0,strict:!0,useMaps:!1,rejectDuplicateMapKeys:!0,tags:{42:t=>B.parse(t())}};var ii=297;var si=t=>{let e=Qg(t),r=Object.assign(vd,{tokenizer:new ra(e,vd)});return ta(e,r)};var Dk=new TextDecoder;var Lk=new TextEncoder;function Cr(t){return t==null?!1:B.asCID(t)===t}function Dr(t,e){let r,n=0,o="";for(;n<e.length;){let i=e[n];if(n++,!Object.hasOwnProperty.call(t,i))throw new Sr(`Object did not have key "${i}"`);if(o+=`/${i}`,r=t[i],t=r,Cr(r))break}return{value:r,rest:e.slice(n),path:o.substring(1)}}async function*na(t,e,r,n){let o=await L(r.get(t,n)),i=ni(o),s=Dr(i,e);yield{cid:Cr(s.value)?s.value:t,name:s.path,rest:s.rest}}async function*kd(t,e,r,n){let o=await L(r.get(t,n)),i=si(o),s=Dr(i,e);yield{cid:Cr(s.value)?s.value:t,name:s.path,rest:s.rest}}function kt(t,e){let r=t.lo+e.lo>>>0,n=t.hi+e.hi+(r<t.lo?1:0)>>>0;return{lo:r,hi:n}}function Zg(t,e){return t+e>>>0}function Se(t,e){let r=t.lo&65535,n=t.lo>>>16,o=e.lo&65535,i=e.lo>>>16,s=r*o,a=r*i,c=n*o,u=n*i,f=(s>>>16)+(a&65535)+(c&65535)>>>0,p=(f<<16|s&65535)>>>0,m=u+(a>>>16)+(c>>>16)+(f>>>16),_=Math.imul(t.lo,e.hi),S=Math.imul(t.hi,e.lo),T=m+_+S>>>0;return{lo:p,hi:T}}function Ht(t,e){return Math.imul(t,e)>>>0}function Lr(t,e){if(e===0)return t;if(e===32)return{lo:t.hi,hi:t.lo};if(e<32){let o=(t.lo<<e|t.hi>>>32-e)>>>0,i=(t.hi<<e|t.lo>>>32-e)>>>0;return{lo:o,hi:i}}e-=32;let r=(t.hi<<e|t.lo>>>32-e)>>>0,n=(t.lo<<e|t.hi>>>32-e)>>>0;return{lo:r,hi:n}}function R(t,e){return{lo:(t.lo^e.lo)>>>0,hi:(t.hi^e.hi)>>>0}}function oa(t,e){if(e===0)return t;if(e<32){let r=(t.lo>>>e|t.hi<<32-e)>>>0,n=t.hi>>>e;return{lo:r,hi:n}}return{lo:t.hi>>>e-32,hi:0}}function $(t,e){return{lo:t>>>0,hi:e>>>0}}function ia(t,e){return(t<<e|t>>>32-e)>>>0}function Id(t,e){let r=e*8,n=t[r]|t[r+1]<<8|t[r+2]<<16|t[r+3]<<24,o=t[r+4]|t[r+5]<<8|t[r+6]<<16|t[r+7]<<24;return{lo:n>>>0,hi:o>>>0}}function e0(t,e){let r=e*4;return(t[r]|t[r+1]<<8|t[r+2]<<16|t[r+3]<<24)>>>0}function Td(t){return t=R(t,oa(t,33)),t=Se(t,$(3981806797,4283543511)),t=R(t,oa(t,33)),t=Se(t,$(444984403,3301882366)),t=R(t,oa(t,33)),t}function t0(t){return t^=t>>>16,t=Ht(t,2246822507),t^=t>>>13,t=Ht(t,3266489909),t^=t>>>16,t}function sa(t,e=0){let r=$(e,0),n=$(e,0),o=t.length,i=Math.floor(o/16),s=$(289559509,2277735313),a=$(658871167,1291169091);for(let m=0;m<i;m++){let _=Id(t,m*2),S=Id(t,m*2+1);_=Se(_,s),_=Lr(_,31),_=Se(_,a),r=R(r,_),r=Lr(r,27),r=kt(r,n),r=kt(Se(r,$(5,0)),$(1390208809,0)),S=Se(S,a),S=Lr(S,33),S=Se(S,s),n=R(n,S),n=Lr(n,31),n=kt(n,r),n=kt(Se(n,$(5,0)),$(944331445,0))}let c=$(0,0),u=$(0,0),f=t.slice(i*16);switch(f.length){case 15:u=R(u,$(0,f[14]<<16));case 14:u=R(u,$(0,f[13]<<8));case 13:u=R(u,$(0,f[12]));case 12:u=R(u,$(f[11]<<24,0));case 11:u=R(u,$(f[10]<<16,0));case 10:u=R(u,$(f[9]<<8,0));case 9:u=R(u,$(f[8],0)),u=Se(u,a),u=Lr(u,33),u=Se(u,s),n=R(n,u);case 8:c=R(c,$(0,f[7]<<24));case 7:c=R(c,$(0,f[6]<<16));case 6:c=R(c,$(0,f[5]<<8));case 5:c=R(c,$(0,f[4]));case 4:c=R(c,$(f[3]<<24,0));case 3:c=R(c,$(f[2]<<16,0));case 2:c=R(c,$(f[1]<<8,0));case 1:c=R(c,$(f[0],0)),c=Se(c,s),c=Lr(c,31),c=Se(c,a),r=R(r,c)}let p=$(o,0);return r=R(r,p),n=R(n,p),r=kt(r,n),n=kt(n,r),r=Td(r),n=Td(n),r=kt(r,n),n=kt(n,r),new Uint8Array([r.hi>>>24&255,r.hi>>>16&255,r.hi>>>8&255,r.hi&255,r.lo>>>24&255,r.lo>>>16&255,r.lo>>>8&255,r.lo&255,n.hi>>>24&255,n.hi>>>16&255,n.hi>>>8&255,n.hi&255,n.lo>>>24&255,n.lo>>>16&255,n.lo>>>8&255,n.lo&255])}function Bd(t,e=0){let r=e>>>0,n=t.length,o=Math.floor(n/4),i=3432918353,s=461845907;for(let u=0;u<o;u++){let f=e0(t,u);f=Ht(f,i),f=ia(f,15),f=Ht(f,s),r^=f,r=ia(r,13),r=Zg(Ht(r,5),3864292196)}let a=t.slice(o*4),c=0;switch(a.length){case 3:c^=a[2]<<16;case 2:c^=a[1]<<8;case 1:c^=a[0],c=Ht(c,i),c=ia(c,15),c=Ht(c,s),r^=c}return r^=n,r=t0(r),r}function n0(t){let e=new Array(4);for(let r=0;r<4;r++)e[r]=t&255,t=t>>8;return new Uint8Array(e)}var Zk=Dt({name:"murmur3-32",code:35,encode:t=>n0(Bd(t))}),Sd=Dt({name:"murmur3-128",code:34,encode:t=>sa(t)}),e2=Dt({name:"murmur3-x64-64",code:34,encode:t=>sa(t).subarray(0,8)});var Dd=Or(Cd(),1);var Vt=class t{_options;_popCount;_parent;_posAtParent;_children;key;constructor(e,r,n=0){this._options=e,this._popCount=0,this._parent=r,this._posAtParent=n,this._children=new Dd.default,this.key=null}async put(e,r){let n=await this._findNewBucketAndPos(e);n.bucket._putAt(n,e,r)}async get(e){let r=await this._findChild(e);if(r!=null)return r.value}async del(e){let r=await this._findPlace(e),n=r.bucket._at(r.pos);n!=null&&n.key===e&&r.bucket._delAt(r.pos)}leafCount(){return this._children.compactArray().reduce((r,n)=>n instanceof t?r+n.leafCount():r+1,0)}childrenCount(){return this._children.length}onlyChild(){return this._children.get(0)}*eachLeafSeries(){let e=this._children.compactArray();for(let r of e)r instanceof t?yield*r.eachLeafSeries():yield r}serialize(e,r){let n=[];return r(this._children.reduce((o,i,s)=>(i!=null&&(i instanceof t?o.push(i.serialize(e,r)):o.push(e(i,s))),o),n))}async asyncTransform(e,r){return Ld(this,e,r)}toJSON(){return this.serialize(c0,u0)}prettyPrint(){return JSON.stringify(this.toJSON(),null," ")}tableSize(){return Math.pow(2,this._options.bits)}async _findChild(e){let r=await this._findPlace(e),n=r.bucket._at(r.pos);if(!(n instanceof t)&&n!=null&&n.key===e)return n}async _findPlace(e){let r=this._options.hash(typeof e=="string"?xo(e):e),n=await r.take(this._options.bits),o=this._children.get(n);return o instanceof t?o._findPlace(r):{bucket:this,pos:n,hash:r,existingChild:o}}async _findNewBucketAndPos(e){let r=await this._findPlace(e);if(r.existingChild!=null&&r.existingChild.key!==e){let n=new t(this._options,r.bucket,r.pos);r.bucket._putObjectAt(r.pos,n);let o=await n._findPlace(r.existingChild.hash);return o.bucket._putAt(o,r.existingChild.key,r.existingChild.value),n._findNewBucketAndPos(r.hash)}return r}_putAt(e,r,n){this._putObjectAt(e.pos,{key:r,value:n,hash:e.hash})}_putObjectAt(e,r){this._children.get(e)==null&&this._popCount++,this._children.set(e,r)}_delAt(e){if(e===-1)throw new Error("Invalid position");this._children.get(e)!=null&&this._popCount--,this._children.unset(e),this._level()}_level(){if(this._parent!=null&&this._popCount<=1)if(this._popCount===1){let e=this._children.find(a0);if(e!=null&&!(e instanceof t)){let r=e.hash;r.untake(this._options.bits);let n={pos:this._posAtParent,hash:r,bucket:this._parent};this._parent._putAt(n,e.key,e.value)}}else this._parent._delAt(this._posAtParent)}_at(e){return this._children.get(e)}};function a0(t){return!!t}function c0(t,e){return t.key}function u0(t){return t}async function Ld(t,e,r){let n=[];for(let o of t._children.compactArray())if(o instanceof Vt)await Ld(o,e,r);else{let i=await e(o);n.push({bitField:t._children.bitField(),children:i})}return r(n)}var f0=[255,254,252,248,240,224,192,128],l0=[1,3,7,15,31,63,127,255],ci=class{_value;_currentBytePos;_currentBitPos;constructor(e){this._value=e,this._currentBytePos=e.length-1,this._currentBitPos=7}availableBits(){return this._currentBitPos+1+this._currentBytePos*8}totalBits(){return this._value.length*8}take(e){let r=e,n=0;for(;r>0&&this._haveBits();){let o=this._value[this._currentBytePos],i=this._currentBitPos+1,s=Math.min(i,r),a=d0(o,i-s,s);n=(n<<s)+a,r-=s,this._currentBitPos-=s,this._currentBitPos<0&&(this._currentBitPos=7,this._currentBytePos--)}return n}untake(e){for(this._currentBitPos+=e;this._currentBitPos>7;)this._currentBitPos-=8,this._currentBytePos+=1}_haveBits(){return this._currentBytePos>=0}};function d0(t,e,r){let n=h0(e,r);return(t&n)>>>e}function h0(t,e){return f0[t]&l0[Math.min(e+t-1,7)]}function $d(t){function e(r){return r instanceof ui?r:new ui(r,t)}return e}var ui=class{_value;_hashFn;_depth;_availableBits;_currentBufferIndex;_buffers;constructor(e,r){if(!(e instanceof Uint8Array))throw new Error("can only hash Uint8Arrays");this._value=e,this._hashFn=r,this._depth=-1,this._availableBits=0,this._currentBufferIndex=0,this._buffers=[]}async take(e){let r=e;for(;this._availableBits<r;)await this._produceMoreBits();let n=0;for(;r>0;){let o=this._buffers[this._currentBufferIndex],i=Math.min(o.availableBits(),r),s=o.take(i);n=(n<<i)+s,r-=i,this._availableBits-=i,o.availableBits()===0&&this._currentBufferIndex++}return n}untake(e){let r=e;for(;r>0;){let n=this._buffers[this._currentBufferIndex],o=Math.min(n.totalBits()-n.availableBits(),r);n.untake(o),r-=o,this._availableBits+=o,this._currentBufferIndex>0&&n.totalBits()===n.availableBits()&&(this._depth--,this._currentBufferIndex--)}}async _produceMoreBits(){this._depth++;let e=this._depth>0?nn([this._value,Uint8Array.from([this._depth])]):this._value,r=await this._hashFn(e),n=new ci(r);this._buffers.push(n),this._availableBits+=n.availableBits()}};function Md(t){if(t==null||t.hashFn==null)throw new Error("please define an options.hashFn");let e={bits:t.bits??8,hash:$d(t.hashFn)};return new Vt(e)}function fi(t){return t.type==="DIRECTORY"}function aa(t){return t.type==="FILE"}function ca(t){return t.type==="RAW"}function ua(t){return t.type==="SYMLINK"}function It(t){return t.type==="HAMT_SHARD"&&t.data instanceof Uint8Array&&typeof t.fanOut=="bigint"&&typeof t.hashType=="bigint"}function tt(t){return typeof t.name=="string"&&B.asCID(t.hash)===t.hash}function*li(t){let e={},r={};for(let n of kr.stream(t))switch(n.field){case".data":{if(n.type==="start"&&(r={}),n.type==="end"){if(fi(r)||It(r)||aa(r)||ca(r)||ua(r)){yield r;return}throw new F("PBNode Data was not a valid UnixFS type")}break}case".data.type":{r.type=n.value;break}case".data.data":{r.data=n.value;break}case".data.fanOut":{r.fanOut=n.value;break}case".data.hashType":{r.hashType=n.value;break}case".links[]":{n.type==="start"&&(e={type:"LINK"}),n.type==="end"&&tt(e)&&(yield e);break}case".links[].name":{e.name=n.value;break}case".links[].hash":{e.hash=B.decode(n.value);break}default:}}var Od=(t,e)=>t.toString(16).toUpperCase().padStart(e,"0").substring(0,e),p0=t=>{let e=t.bucket,r=[];for(;e._parent!=null;)r.push(e),e=e._parent;return r.push(e),r.reverse()};async function*di(t,e,r,n,o,i,s){let a=(i.lastBucket.tableSize()-1).toString(16).length,c=[];for(let v of e){if(!tt(v))throw new F("Invalid link");if(c.push(v),v.name.length===a){let I=parseInt(v.name,16);i.lastBucket._putObjectAt(I,new Vt({hash:i.lastBucket._options.hash,bits:i.lastBucket._options.bits},i.lastBucket,I))}if(v.name.substring(a)===r){yield{cid:v.hash,name:r,rest:n};return}await i.rootBucket.put(v.name.substring(a),!0)}let u=await i.rootBucket._findNewBucketAndPos(r),f=Od(u.pos,a),p=p0(u);p.length>i.hamtDepth&&(i.lastBucket=p[i.hamtDepth],f=Od(i.lastBucket._posAtParent,a));let m=c.find(v=>v.name==null?!1:v.name===f);if(m==null)return;i.hamtDepth++;let _=await L(o.get(m.hash,s));s?.yieldSubShards===!0&&(yield{cid:m.hash,name:m.name,rest:[r,...n]});let S=li(_),{value:T}=S.next();if(c=[],T!=null){if(It(T)){yield*di(T,S,r,n,o,i,s);return}if(!tt(T))throw new F("Did not read Link or Data from dag-pb block");c.push(T);for(let v of S){if(It(v)){yield*di(v,c,r,n,o,i,s);return}if(!tt(v))throw new F("Did not read Link or Data from dag-pb block");c.push(v)}}}function*Rd(t,e,r){for(let n of t){if(!tt(n))throw new F("Invalid link");if(n.name===e[0]){yield{cid:n.hash,name:e[0],rest:e.slice(1)};return}}throw new ae(`No link "${e[0]}" found under ${r}`)}var m0=async function(t){return(await Sd.encode(t)).slice(0,8).reverse()};async function*Fd(t,e,r,n,o,i){let s=Md({hashFn:m0,bits:Math.log2(Number(t.fanOut))}),a={rootBucket:s,hamtDepth:1,lastBucket:s};for await(let c of di(t,e,r[0],r.slice(1),o,a,i))if(yield c,c.name===r[0])return;throw new ae(`No link "${r[0]}" found under ${n}`)}async function*Pd(t,e,r,n){let o=await L(r.get(t,n)),i=[],s=li(o),{value:a}=s.next(),c=!1,u=!1;if(a!=null){if(u=fi(a),c=It(a),aa(a)||ca(a)||ua(a)){yield{cid:t,name:e[0],rest:e.slice(1)};return}if(u||c&&n?.translateHAMTPath===!1){yield*Rd(s,e,t);return}if(c){yield*Fd(a,s,e,t,r,n);return}if(!tt(a))throw new F("Did not read Link or Data from dag-pb block");i.push(a);for(let f of s){if(u=fi(f),c=It(f),u||c&&n?.translateHAMTPath===!1){yield*Rd(i,e,t);return}if(It(f)){yield*Fd(f,i,e,t,r,n);return}if(!tt(f))throw new F("Did not read Link or Data from dag-pb block");i.push(f)}}throw new ae(`No link "${e[0]}" found under ${t}`)}async function*zd(t,e,r,n){if(e.length!==0)throw new Sr(`Cannot load path /${e.join("/")} from identity block`)}async function*jd(t,e,r,n){let o=await L(r.get(t,n)),i=go(o),s=Dr(i,e);yield{cid:t,name:s.path,rest:s.rest}}async function*Hd(t,e,r,n){if(e.length!==0)throw new ae(`Cannot load path /${e.join("/")} from raw block`)}var g0={[Br]:Pd,[hr]:Hd,[ri]:na,81:na,[ii]:kd,[ir.code]:zd,[yo]:jd};async function*hi(t,e,r={}){for(t=t.toString(),t.startsWith("/ipfs/")&&(t=t.substring(6));t.endsWith("/");)t=t.substring(0,t.length-1);let[n,...o]=t.split(/(?<!\\)\//g).filter(Boolean),i=B.parse(n),s=[i],a=`${i}`;for(yield{cid:i,name:a,path:a,roots:s,remainder:o};o.length>0;){let c=g0[i.code];if(c==null)throw new Ur(`No resolver for code ${i.code}`);let u=!1;for await(let f of c(i,o,e,r)){if(i=f.cid,u=!s[s.length-1].equals(i),o=f.rest,!u)break;s=[...s,f.cid],a=`${a}/${f.name}`,yield{cid:f.cid,name:f.name,path:a,roots:s,remainder:f.rest}}if(!u)break}if(r?.signal?.throwIfAborted(),o.length!==0)throw new ae(`Could not resolve path /${o.join("/")} under ${t}`)}function w0(t){return t[Symbol.asyncIterator]!=null}function x0(t){if(w0(t))return(async()=>{let r;for await(let n of t)r=n;return r})();let e;for(let r of t)e=r;return e}var Vd=x0;async function fa(t,e,r,n,o){let i=await L(n.get(t,o)),s=ni(i);return{type:"object",cid:t,name:e,path:r,object:s,node:i,size:BigInt(i.byteLength)}}async function qd(t,e,r,n,o){let i=await L(n.get(t,o)),s=si(i);return{type:"object",cid:t,name:e,path:r,object:s,node:i,size:BigInt(i.byteLength)}}var Ue=class extends Event{type;detail;constructor(e,r){super(e),this.type=e,this.detail=r}};function An(t,e,r,n){let o=BigInt(t.length),i=BigInt(e+o);return r>=i||n<e?new Uint8Array(0):(n>=e&&n<i&&(t=t.subarray(0,Number(n-e))),r>=e&&r<i&&(t=t.subarray(Number(r-e))),t)}var pi=(t,e=0,r=t)=>{let n=BigInt(t),o=BigInt(e??0),i=BigInt(r);if(i!==n&&(i=o+i),i>n&&(i=n),o<0n)throw new et("Offset must be greater than or equal to 0");if(o>n)throw new et("Offset must be less than the file size");if(i<0n)throw new et("Length must be greater than or equal to 0");if(i>n)throw new et("Length must be less than the file size");return{start:o,end:i}};function mi(t,e){async function*r(n={}){let{start:o,end:i}=pi(t.length,n.offset,n.length),s=An(t,0n,o,i);n.onProgress?.(new Ue(e,{bytesRead:BigInt(s.byteLength),totalBytes:i-o,fileSize:BigInt(t.byteLength)})),yield s}return r}async function Gd(t,e,r,n,o){let i=or(t.multihash.bytes);return{type:"identity",cid:t,name:e,path:r,content:mi(i.digest,"unixfs:exporter:progress:identity"),size:BigInt(i.bytes.byteLength),node:i.bytes}}async function Wd(t,e,r,n,o){let i=await L(n.get(t,o)),s=go(i);return{type:"object",cid:t,name:e,path:r,object:s,size:BigInt(i.byteLength),node:i}}async function Jd(t,e,r,n,o){let i=await L(n.get(t,o));return{type:"raw",cid:t,name:e,path:r,content:mi(i,"unixfs:exporter:progress:raw"),size:BigInt(i.length),node:i}}function Yd(t,e,r,n){async function*o(i={}){let s=i.offset??0,a=i.length??e.Links.length,c=e.Links.slice(s,s+a);i.onProgress?.(new Ue("unixfs:exporter:walk:directory",{cid:t})),yield*c.map(u=>({cid:u.Hash,name:u.Name??"",path:`${n}/${u.Name??""}`,size:BigInt(u.Tsize??0)}))}return o}var yi=globalThis.CustomEvent??Event;async function*la(t,e={}){let r=e.concurrency??1/0;r<1&&(r=1/0);let n=e.ordered??!1,o=new EventTarget,i=[],s=ee(),a=ee(),c=!1,u,f=!1,p=!1;o.addEventListener("task-complete",()=>{a.resolve()}),Promise.resolve().then(async()=>{try{for await(let T of t){if(i.length===r&&(s=ee(),await s.promise),f||p)break;let v={done:!1};i.push(v),T().then(I=>{v.done=!0,v.ok=!0,v.value=I,o.dispatchEvent(new yi("task-complete"))},I=>{v.done=!0,v.err=I,o.dispatchEvent(new yi("task-complete"))})}c=!0,o.dispatchEvent(new yi("task-complete"))}catch(T){u=T,o.dispatchEvent(new yi("task-complete"))}});function m(){return n?i[0]?.done:!!i.find(T=>T.done)}function*_(){for(;i.length>0&&i[0].done;){let T=i[0];if(i.shift(),T.ok)yield T.value;else throw f=!0,s.resolve(),T.err;s.resolve()}}function*S(){for(;m();)for(let T=0;T<i.length;T++)if(i[T].done){let v=i[T];if(i.splice(T,1),T--,v.ok)yield v.value;else throw f=!0,s.resolve(),v.err;s.resolve()}}try{for(;;){if(m()||(a=ee(),await a.promise),u!=null||(n?yield*_():yield*S(),u!=null))throw u;if(c&&i.length===0)break}}finally{p=!0,s.resolve()}}var ha=Or(Kd(),1);var pa=class t extends Error{name="TimeoutError";constructor(e,r){super(e,r),Error.captureStackTrace?.(this,t)}},Qd=t=>t.reason??new DOMException("This operation was aborted.","AbortError");function ma(t,e){let{milliseconds:r,fallback:n,message:o,customTimers:i={setTimeout,clearTimeout},signal:s}=e,a,c,f=new Promise((p,m)=>{if(typeof r!="number"||Math.sign(r)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${r}\``);if(s?.aborted){m(Qd(s)),t.then(p,m);return}if(s&&(c=()=>{m(Qd(s))},s.addEventListener("abort",c,{once:!0})),t.then(p,m),r===Number.POSITIVE_INFINITY)return;let _=new pa;a=i.setTimeout.call(void 0,()=>{if(n){try{p(n())}catch(S){m(S)}return}typeof t.cancel=="function"&&t.cancel(),o===!1?p():o instanceof Error?m(o):(_.message=o??`Promise timed out after ${r} milliseconds`,m(_))},r)}).finally(()=>{f.clear(),c&&s&&s.removeEventListener("abort",c)});return f.clear=()=>{i.clearTimeout.call(void 0,a),a=void 0},f}function ya(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 _0=100,$r=class{#e=[];#t=0;enqueue(e,r){let{priority:n=0,id:o}=r??{},{size:i}=this,s={priority:n,id:o,run:e};if(i===0){this.#e.length=0,this.#t=0,this.#e.push(s);return}if(this.#e.at(-1).priority>=n){this.#e.push(s);return}this.#i();let a=ya(this.#e,s,(c,u)=>u.priority-c.priority);this.#e.splice(a,0,s)}setPriority(e,r){let n=this.#e.findIndex((i,s)=>s>=this.#t&&i.id===e);if(n===-1)throw new ReferenceError(`No promise function with the id "${e}" exists in the queue.`);let[o]=this.#e.splice(n,1);this.enqueue(o.run,{priority:r,id:e})}remove(e){let r=this.#e.findIndex((n,o)=>o<this.#t?!1:typeof e=="string"?n.id===e:n.run===e);r!==-1&&this.#e.splice(r,1)}dequeue(){if(this.#t===this.#e.length)return;let e=this.#e[this.#t];return this.#t++,this.#t===this.#e.length?(this.#e.length=0,this.#t=0):this.#t>_0&&this.#t>this.#e.length/2&&this.#i(),e?.run}filter(e){let r=[];for(let n=this.#t;n<this.#e.length;n++){let o=this.#e[n];o.priority===e.priority&&r.push(o.run)}return r}get size(){return this.#e.length-this.#t}#i(){this.#t!==0&&(this.#e.splice(0,this.#t),this.#t=0)}};var kn=class extends ha.default{#e;#t;#i=0;#h;#m=!1;#x=!1;#u;#b=0;#c;#f;#a;#s=[];#o=0;#r;#I;#n=0;#y;#l;#C=1n;#g=new Map;#E=new Set;timeout;constructor(e){if(super(),e={carryoverIntervalCount:!1,intervalCap:Number.POSITIVE_INFINITY,interval:0,concurrency:Number.POSITIVE_INFINITY,autoStart:!0,queueClass:$r,strict:!1,...e},!(typeof e.intervalCap=="number"&&e.intervalCap>=1))throw new TypeError(`Expected \`intervalCap\` to be a number from 1 and up, got \`${e.intervalCap?.toString()??""}\` (${typeof e.intervalCap})`);if(e.interval===void 0||!(Number.isFinite(e.interval)&&e.interval>=0))throw new TypeError(`Expected \`interval\` to be a finite number >= 0, got \`${e.interval?.toString()??""}\` (${typeof e.interval})`);if(e.strict&&e.interval===0)throw new TypeError("The `strict` option requires a non-zero `interval`");if(e.strict&&e.intervalCap===Number.POSITIVE_INFINITY)throw new TypeError("The `strict` option requires a finite `intervalCap`");if(this.#e=e.carryoverIntervalCount??e.carryoverConcurrencyCount??!1,this.#t=e.intervalCap===Number.POSITIVE_INFINITY||e.interval===0,this.#h=e.intervalCap,this.#u=e.interval,this.#a=e.strict,this.#r=new e.queueClass,this.#I=e.queueClass,this.concurrency=e.concurrency,e.timeout!==void 0&&!(Number.isFinite(e.timeout)&&e.timeout>0))throw new TypeError(`Expected \`timeout\` to be a positive finite number, got \`${e.timeout}\` (${typeof e.timeout})`);this.timeout=e.timeout,this.#l=e.autoStart===!1,this.#P()}#_(e){for(;this.#o<this.#s.length;){let n=this.#s[this.#o];if(n!==void 0&&e-n>=this.#u)this.#o++;else break}(this.#o>100&&this.#o>this.#s.length/2||this.#o===this.#s.length)&&(this.#s=this.#s.slice(this.#o),this.#o=0)}#D(e){this.#a?this.#s.push(e):this.#i++}#L(){this.#a?this.#s.length>this.#o&&this.#s.pop():this.#i>0&&this.#i--}#A(){return this.#s.length-this.#o}get#$(){return this.#t?!0:this.#a?this.#A()<this.#h:this.#i<this.#h}get#M(){return this.#n<this.#y}#O(){this.#n--,this.#n===0&&this.emit("pendingZero"),this.#w(),this.emit("next")}#R(){this.#f=void 0,this.#U(),this.#S()}#F(e){if(this.#a){if(this.#_(e),this.#A()>=this.#h){let n=this.#s[this.#o],o=this.#u-(e-n);return this.#T(o),!0}return!1}if(this.#c===void 0){let r=this.#b-e;if(r<0)this.#i=this.#e?this.#n:0;else return this.#T(r),!0}return!1}#T(e){this.#f===void 0&&(this.#f=setTimeout(()=>{this.#R()},e))}#v(){this.#c&&(clearInterval(this.#c),this.#c=void 0)}#B(){this.#f&&(clearTimeout(this.#f),this.#f=void 0)}#w(){if(this.#r.size===0){if(this.#v(),this.emit("empty"),this.#n===0){if(this.#B(),this.#a&&this.#o>0){let r=Date.now();this.#_(r)}this.emit("idle")}return!1}let e=!1;if(!this.#l){let r=Date.now(),n=!this.#F(r);if(this.#$&&this.#M){let o=this.#r.dequeue();this.#t||(this.#D(r),this.#p()),n&&this.#S(),o(),this.emit("active"),e=!0}}return e}#S(){this.#t||this.#c!==void 0||this.#a||(this.#c=setInterval(()=>{this.#U()},this.#u),this.#b=Date.now()+this.#u)}#U(){this.#a||(this.#c!==void 0&&(this.#i===0&&this.#n===0?this.#v():this.#b=Date.now()+this.#u),this.#i=this.#e?this.#n:0),this.#k(),this.#p()}#k(){for(;this.#w(););}get concurrency(){return this.#y}set concurrency(e){if(!(typeof e=="number"&&e>=1))throw new TypeError(`Expected \`concurrency\` to be a number from 1 and up, got \`${e}\` (${typeof e})`);this.#y=e,this.#k()}setPriority(e,r){if(typeof r!="number"||!Number.isFinite(r))throw new TypeError(`Expected \`priority\` to be a finite number, got \`${r}\` (${typeof r})`);this.#r.setPriority(e,r)}async add(e,r={}){if(r={timeout:this.timeout,...r,id:r.id??(this.#C++).toString()},r.timeout!==void 0&&!(Number.isFinite(r.timeout)&&r.timeout>0))throw new TypeError(`Expected \`timeout\` to be a positive finite number, got \`${r.timeout}\` (${typeof r.timeout})`);return new Promise((n,o)=>{let i=Symbol(`task-${r.id}`),s=()=>{},a=async()=>{s(),this.#n++,this.#g.set(i,{id:r.id,priority:r.priority??0,startTime:Date.now(),timeout:r.timeout});let u;try{try{r.signal?.throwIfAborted()}catch(m){throw this.#z(),this.#g.delete(i),m}let f=e({signal:r.signal});if(r.timeout!==void 0&&(f=ma(Promise.resolve(f),{milliseconds:r.timeout,message:`Task timed out after ${r.timeout}ms (queue has ${this.#n} running, ${this.#r.size} waiting)`})),r.signal){let{signal:m}=r;f=Promise.race([f,new Promise((_,S)=>{u=()=>{S(m.reason)},m.addEventListener("abort",u,{once:!0}),m.aborted&&u()})])}let p=await f;n(p),this.emit("completed",p)}catch(f){o(f),this.emit("error",f)}finally{u&&r.signal?.removeEventListener("abort",u),this.#g.delete(i),queueMicrotask(()=>{this.#O()})}};this.#r.enqueue(a,r);let c=()=>{if(this.#r instanceof $r){this.#r.remove(a);return}this.#r.remove?.(r.id)};if(r.signal){let{signal:u}=r,f=()=>{s(),c(),o(u.reason),this.#w(),this.emit("next")};if(s=()=>{u.removeEventListener("abort",f),this.#E.delete(s)},u.aborted){f();return}u.addEventListener("abort",f,{once:!0}),this.#E.add(s)}this.emit("add"),this.#w()})}async addAll(e,r){return Promise.all(e.map(async n=>this.add(n,r)))}start(){return this.#l?(this.#l=!1,this.#k(),this):this}pause(){this.#l=!0}clear(){for(let e of this.#E)e();this.#r=new this.#I,this.#v(),this.#N(),this.emit("empty"),this.#n===0&&(this.#B(),this.emit("idle")),this.emit("next")}async onEmpty(){this.#r.size!==0&&await this.#d("empty")}async onSizeLessThan(e){this.#r.size<e||await this.#d(["next","active"],()=>this.#r.size<e)}async onIdle(){this.#n===0&&this.#r.size===0||await this.#d("idle")}async onPendingZero(){this.#n!==0&&await this.#d("pendingZero")}async onRateLimit(){this.isRateLimited||await this.#d("rateLimit")}async onRateLimitCleared(){this.isRateLimited&&await this.#d("rateLimitCleared")}onError(){return new Promise((e,r)=>{let n=o=>{this.off("error",n),r(o)};this.on("error",n)})}async#d(e,r){let n=Array.isArray(e)?e:[e];return new Promise(o=>{let i=()=>{if(!(r&&!r())){for(let s of n)this.off(s,i);o()}};for(let s of n)this.on(s,i)})}get size(){return this.#r.size}sizeBy(e){return this.#r.filter(e).length}get pending(){return this.#n}get isPaused(){return this.#l}#P(){this.#t||(this.on("add",()=>{this.#r.size>0&&this.#p()}),this.on("next",()=>{this.#p()}))}#p(){this.#t||this.#x||(this.#x=!0,queueMicrotask(()=>{this.#x=!1,this.#N()}))}#z(){this.#t||(this.#L(),this.#p())}#N(){let e=this.#m;if(this.#t||this.#r.size===0){e&&(this.#m=!1,this.emit("rateLimitCleared"));return}let r;if(this.#a){let o=Date.now();this.#_(o),r=this.#A()}else r=this.#i;let n=r>=this.#h;n!==e&&(this.#m=n,this.emit(n?"rateLimit":"rateLimitCleared"))}get isRateLimited(){return this.#m}get isSaturated(){return this.#n===this.#y&&this.#r.size>0||this.isRateLimited&&this.#r.size>0}get runningTasks(){return[...this.#g.values()].map(e=>({...e,timeoutRemaining:e.timeout?Math.max(0,e.startTime+e.timeout-Date.now()):void 0}))}};async function Zd(t,e,r,n,o,i,s){if(e instanceof Uint8Array){let u=An(e,n,o,i);r.push(u);return}if(e.Data==null)throw new F("no data in PBNode");let a;try{a=We.unmarshal(e.Data)}catch(u){throw new F(u.message)}if(a.data!=null){let u=a.data,f=An(u,n,o,i);r.push(f),n+=BigInt(f.byteLength)}let c=[];if(e.Links.length!==a.blockSizes.length)throw new F("Inconsistent block sizes and dag links");for(let u=0;u<e.Links.length;u++){let f=e.Links[u],p=n,m=p+a.blockSizes[u];if((o>=p&&o<m||i>=p&&i<=m||o<p&&i>m)&&c.push({link:f,blockStart:n}),n=m,n>i)break}await Rf(c,u=>po(u,f=>async()=>{let p=await L(t.get(f.link.Hash,s));return{...f,block:p}}),u=>la(u,{ordered:!0,concurrency:s.blockReadConcurrency??10}),async u=>{for await(let{link:f,block:p,blockStart:m}of u){let _;switch(f.Hash.code){case Br:_=Qo(p);break;case hr:_=p;break;default:r.end(new F(`Unsupported codec: ${f.Hash.code}`));return}let S=new kn({concurrency:1});S.on("error",T=>{r.end(T)}),S.add(async()=>{s.onProgress?.(new Ue("unixfs:exporter:walk:file",{cid:f.Hash})),await Zd(t,_,r,m,o,i,s)}),await S.onIdle()}}),n>=i&&r.end()}function ga(t,e,r,n,o){async function*i(s={}){let a=r.fileSize();if(a===void 0)throw new Error("File was a directory");let{start:c,end:u}=pi(a,s.offset,s.length);if(u===0n)return;let f=0n,p=u-c,m=mr();s.onProgress?.(new Ue("unixfs:exporter:walk:file",{cid:t})),Zd(o,e,m,0n,c,u,s).catch(_=>{m.end(_)});for await(let _ of m)if(_!=null){if(f+=BigInt(_.byteLength),f>p)throw m.end(),new ei("Read too many bytes - the file size reported by the UnixFS data in the root node may be incorrect");f===p&&m.end(),s.onProgress?.(new Ue("unixfs:exporter:progress:unixfs:file",{bytesRead:f,totalBytes:p,fileSize:a})),yield _}if(f<p)throw new ti("Traversed entire DAG but did not read enough bytes")}return i}async function*A0(t,e,r,n){let o=-1,i=0;for await(let s of eh(t,e,r,n))if(o++,!(n.offset!=null&&n.offset<o)&&(yield s,i++,n.length!=null&&n.length===i))return}async function*eh(t,e,r,n){let o=await L(r.get(t,n)),i=kr.decode(o);if(i.data?.fanOut==null)throw new F("missing fanout");let s=(i.data.fanOut-1n).toString(16).length;for(let a of i.links){if(a.name==null||a.hash==null)continue;let c=B.decode(a.hash);if(a.name.length===s)yield*eh(c,e,r,n);else{let u=a.name.substring(s);yield{cid:c,name:a.name.substring(s),path:`${e}/${u}`,size:BigInt(a.tSize??0)}}}}function th(t,e,r,n,o){function i(s={}){return s.onProgress?.(new Ue("unixfs:exporter:walk:hamt-sharded-directory",{cid:t})),A0(t,n,o,s)}return i}var v0={raw:ga,file:ga,directory:Yd,"hamt-sharded-directory":th,metadata:(t,e,r,n)=>()=>[],symlink:(t,e,r,n)=>()=>[]};async function rh(t,e,r,n,o){let i=await L(n.get(t,o)),s;try{s=Qo(i)}catch(u){throw new F(u.message)}if(s.Data==null)throw new F("no data in PBNode");let a;try{a=We.unmarshal(s.Data)}catch(u){throw new F(u.message)}let c=v0[a.type](t,s,a,r,n);if(c==null)throw new ae("could not find content exporter");return a.isDirectory()?{type:"directory",cid:t,name:e,path:r,entries:c,unixfs:a,node:s,size:BigInt(i.byteLength)}:{type:"file",cid:t,name:e,path:r,content:c,unixfs:a,node:s,size:a.fileSize()}}var k0={[Br]:rh,[hr]:Jd,[ri]:fa,81:fa,[ii]:qd,[ir.code]:Gd,[yo]:Wd};async function nh(t,e,r={}){let n,o;if(t instanceof String||typeof t=="string"){let s=await Vd(hi(t,e,r));if(s==null)throw new ae(`Could not walk path to ${t}`);n=s.cid,o=s.name,t=s.path}else if(B.asCID(t)===t||t instanceof B)n=t,o=t=n.toString();else throw new et("Path must be string or CID");let i=k0[n.code];if(i==null)throw new Ur(`No resolver for code ${n.code}`);return i(n,o,t,e,r)}var wa=class{root;path;constructor(...e){let r=e[0],n=e[1];if(typeof r=="string")n=r,r=void 0;else if(e.length<2)throw new Error("path or CID and path must be specified");n.startsWith("/")||(n=`/${n}`),this.root=r,this.path=n}async*traverse(e,r,n,o){for await(let i of hi(`${this.root??e}${this.path}`,r,o)){let s=await nh(i.cid,r,o);yield Ge({cid:s.cid,bytes:s.node instanceof Uint8Array?s.node:xd(s.node),codec:await n(i.cid.code)})}}};function I0(t){return new qo(t)}return fh(T0);})();
|
|
3
3
|
return HeliaCar}));
|
|
4
4
|
//# sourceMappingURL=index.min.js.map
|