@helia/mfs 7.0.4 → 7.0.5-11802dd6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.min.js CHANGED
@@ -1,14 +1,14 @@
1
1
  (function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.HeliaMfs = factory()}(typeof self !== 'undefined' ? self : this, function () {
2
- "use strict";var HeliaMfs=(()=>{var jc=Object.create;var Er=Object.defineProperty;var qc=Object.getOwnPropertyDescriptor;var Gc=Object.getOwnPropertyNames;var Wc=Object.getPrototypeOf,Jc=Object.prototype.hasOwnProperty;var ao=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),X=(r,e)=>{for(var t in e)Er(r,t,{get:e[t],enumerable:!0})},co=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of Gc(e))!Jc.call(r,i)&&i!==t&&Er(r,i,{get:()=>e[i],enumerable:!(n=qc(e,i))||n.enumerable});return r};var vr=(r,e,t)=>(t=r!=null?jc(Wc(r)):{},co(e||!r||!r.__esModule?Er(t,"default",{value:r,enumerable:!0}):t,r)),Kc=r=>co(Er({},"__esModule",{value:!0}),r);var Vr=ao((iy,bs)=>{"use strict";bs.exports=class{constructor(){this._bitArrays=[],this._data=[],this._length=0,this._changedLength=!1,this._changedData=!1}set(e,t){let n=this._internalPositionFor(e,!1);if(t===void 0)n!==-1&&(this._unsetInternalPos(n),this._unsetBit(e),this._changedLength=!0,this._changedData=!0);else{let i=!1;n===-1?(n=this._data.length,this._setBit(e),this._changedData=!0):i=!0,this._setInternalPos(n,e,t,i),this._changedLength=!0}}unset(e){this.set(e,void 0)}get(e){this._sortData();let t=this._internalPositionFor(e,!0);if(t!==-1)return this._data[t][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 t=0;for(;t<this.length;)e(this.get(t),t,this),t++}map(e){let t=0,n=new Array(this.length);for(;t<this.length;)n[t]=e(this.get(t),t,this),t++;return n}reduce(e,t){let n=0,i=t;for(;n<this.length;){let o=this.get(n);i=e(i,o,n),n++}return i}find(e){let t=0,n,i;for(;t<this.length&&!n;)i=this.get(t),n=e(i),t++;return n?i:void 0}_internalPositionFor(e,t){let n=this._bytePosFor(e,t);if(n>=this._bitArrays.length)return-1;let i=this._bitArrays[n],o=e-n*7;if(!((i&1<<o)>0))return-1;let a=this._bitArrays.slice(0,n).reduce(Wf,0),c=~(4294967295<<o+1),f=xs(i&c);return a+f-1}_bytePosFor(e,t){let n=Math.floor(e/7),i=n+1;for(;!t&&this._bitArrays.length<i;)this._bitArrays.push(0);return n}_setBit(e){let t=this._bytePosFor(e,!1);this._bitArrays[t]|=1<<e-t*7}_unsetBit(e){let t=this._bytePosFor(e,!1);this._bitArrays[t]&=~(1<<e-t*7)}_setInternalPos(e,t,n,i){let o=this._data,s=[t,n];if(i)this._sortData(),o[e]=s;else{if(o.length)if(o[o.length-1][0]>=t)o.push(s);else if(o[0][0]<=t)o.unshift(s);else{let a=Math.round(o.length/2);this._data=o.slice(0,a).concat(s).concat(o.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(Jf),this._changedData=!1}bitField(){let e=[],t=8,n=0,i=0,o,s=this._bitArrays.slice();for(;s.length||n;){n===0&&(o=s.shift(),n=7);let c=Math.min(n,t),f=~(255<<c),u=o&f;i|=u<<8-t,o=o>>>c,n-=c,t-=c,(!t||!n&&!s.length)&&(e.push(i),i=0,t=8)}for(var a=e.length-1;a>0&&e[a]===0;a--)e.pop();return e}compactArray(){return this._sortData(),this._data.map(Kf)}};function Wf(r,e){return r+xs(e)}function xs(r){let e=r;return e=e-(e>>1&1431655765),e=(e&858993459)+(e>>2&858993459),(e+(e>>4)&252645135)*16843009>>24}function Jf(r,e){return r[0]-e[0]}function Kf(r){return r[1]}});var fc=ao((fx,Ji)=>{"use strict";var lh=Object.prototype.hasOwnProperty,Z="~";function yr(){}Object.create&&(yr.prototype=Object.create(null),new yr().__proto__||(Z=!1));function hh(r,e,t){this.fn=r,this.context=e,this.once=t||!1}function uc(r,e,t,n,i){if(typeof t!="function")throw new TypeError("The listener must be a function");var o=new hh(t,n||r,i),s=Z?Z+e:e;return r._events[s]?r._events[s].fn?r._events[s]=[r._events[s],o]:r._events[s].push(o):(r._events[s]=o,r._eventsCount++),r}function En(r,e){--r._eventsCount===0?r._events=new yr:delete r._events[e]}function J(){this._events=new yr,this._eventsCount=0}J.prototype.eventNames=function(){var e=[],t,n;if(this._eventsCount===0)return e;for(n in t=this._events)lh.call(t,n)&&e.push(Z?n.slice(1):n);return Object.getOwnPropertySymbols?e.concat(Object.getOwnPropertySymbols(t)):e};J.prototype.listeners=function(e){var t=Z?Z+e:e,n=this._events[t];if(!n)return[];if(n.fn)return[n.fn];for(var i=0,o=n.length,s=new Array(o);i<o;i++)s[i]=n[i].fn;return s};J.prototype.listenerCount=function(e){var t=Z?Z+e:e,n=this._events[t];return n?n.fn?1:n.length:0};J.prototype.emit=function(e,t,n,i,o,s){var a=Z?Z+e:e;if(!this._events[a])return!1;var c=this._events[a],f=arguments.length,u,l;if(c.fn){switch(c.once&&this.removeListener(e,c.fn,void 0,!0),f){case 1:return c.fn.call(c.context),!0;case 2:return c.fn.call(c.context,t),!0;case 3:return c.fn.call(c.context,t,n),!0;case 4:return c.fn.call(c.context,t,n,i),!0;case 5:return c.fn.call(c.context,t,n,i,o),!0;case 6:return c.fn.call(c.context,t,n,i,o,s),!0}for(l=1,u=new Array(f-1);l<f;l++)u[l-1]=arguments[l];c.fn.apply(c.context,u)}else{var d=c.length,p;for(l=0;l<d;l++)switch(c[l].once&&this.removeListener(e,c[l].fn,void 0,!0),f){case 1:c[l].fn.call(c[l].context);break;case 2:c[l].fn.call(c[l].context,t);break;case 3:c[l].fn.call(c[l].context,t,n);break;case 4:c[l].fn.call(c[l].context,t,n,i);break;default:if(!u)for(p=1,u=new Array(f-1);p<f;p++)u[p-1]=arguments[p];c[l].fn.apply(c[l].context,u)}}return!0};J.prototype.on=function(e,t,n){return uc(this,e,t,n,!1)};J.prototype.once=function(e,t,n){return uc(this,e,t,n,!0)};J.prototype.removeListener=function(e,t,n,i){var o=Z?Z+e:e;if(!this._events[o])return this;if(!t)return En(this,o),this;var s=this._events[o];if(s.fn)s.fn===t&&(!i||s.once)&&(!n||s.context===n)&&En(this,o);else{for(var a=0,c=[],f=s.length;a<f;a++)(s[a].fn!==t||i&&!s[a].once||n&&s[a].context!==n)&&c.push(s[a]);c.length?this._events[o]=c.length===1?c[0]:c:En(this,o)}return this};J.prototype.removeAllListeners=function(e){var t;return e?(t=Z?Z+e:e,this._events[t]&&En(this,t)):(this._events=new yr,this._eventsCount=0),this};J.prototype.off=J.prototype.removeListener;J.prototype.addListener=J.prototype.on;J.prefixed=Z;J.EventEmitter=J;typeof Ji<"u"&&(Ji.exports=J)});var fd={};X(fd,{mfs:()=>ud});var Wn={};X(Wn,{base32:()=>Me,base32hex:()=>ou,base32hexpad:()=>au,base32hexpadupper:()=>cu,base32hexupper:()=>su,base32pad:()=>nu,base32padupper:()=>iu,base32upper:()=>ru,base32z:()=>uu});var hd=new Uint8Array(0);function uo(r,e){if(r===e)return!0;if(r.byteLength!==e.byteLength)return!1;for(let t=0;t<r.byteLength;t++)if(r[t]!==e[t])return!1;return!0}function ye(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return r;if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return new Uint8Array(r.buffer,r.byteOffset,r.byteLength);throw new Error("Unknown type, must be binary type")}function fo(r){return new TextEncoder().encode(r)}function lo(r){return new TextDecoder().decode(r)}function Xc(r,e){if(r.length>=255)throw new TypeError("Alphabet too long");for(var t=new Uint8Array(256),n=0;n<t.length;n++)t[n]=255;for(var i=0;i<r.length;i++){var o=r.charAt(i),s=o.charCodeAt(0);if(t[s]!==255)throw new TypeError(o+" is ambiguous");t[s]=i}var a=r.length,c=r.charAt(0),f=Math.log(a)/Math.log(256),u=Math.log(256)/Math.log(a);function l(m){if(m instanceof Uint8Array||(ArrayBuffer.isView(m)?m=new Uint8Array(m.buffer,m.byteOffset,m.byteLength):Array.isArray(m)&&(m=Uint8Array.from(m))),!(m instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(m.length===0)return"";for(var w=0,g=0,b=0,k=m.length;b!==k&&m[b]===0;)b++,w++;for(var v=(k-b)*u+1>>>0,U=new Uint8Array(v);b!==k;){for(var O=m[b],Fe=0,K=v-1;(O!==0||Fe<g)&&K!==-1;K--,Fe++)O+=256*U[K]>>>0,U[K]=O%a>>>0,O=O/a>>>0;if(O!==0)throw new Error("Non-zero carry");g=Fe,b++}for(var pe=v-g;pe!==v&&U[pe]===0;)pe++;for(var Ye=c.repeat(w);pe<v;++pe)Ye+=r.charAt(U[pe]);return Ye}function d(m){if(typeof m!="string")throw new TypeError("Expected String");if(m.length===0)return new Uint8Array;var w=0;if(m[w]!==" "){for(var g=0,b=0;m[w]===c;)g++,w++;for(var k=(m.length-w)*f+1>>>0,v=new Uint8Array(k);m[w];){var U=t[m.charCodeAt(w)];if(U===255)return;for(var O=0,Fe=k-1;(U!==0||O<b)&&Fe!==-1;Fe--,O++)U+=a*v[Fe]>>>0,v[Fe]=U%256>>>0,U=U/256>>>0;if(U!==0)throw new Error("Non-zero carry");b=O,w++}if(m[w]!==" "){for(var K=k-b;K!==k&&v[K]===0;)K++;for(var pe=new Uint8Array(g+(k-K)),Ye=g;K!==k;)pe[Ye++]=v[K++];return pe}}}function p(m){var w=d(m);if(w)return w;throw new Error(`Non-${e} character`)}return{encode:l,decodeUnsafe:d,decode:p}}var Yc=Xc,Zc=Yc,mo=Zc;var Hn=class{name;prefix;baseEncode;constructor(e,t,n){this.name=e,this.prefix=t,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},jn=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,t,n){this.name=e,this.prefix=t;let i=t.codePointAt(0);if(i===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=i,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 po(this,e)}},qn=class{decoders;constructor(e){this.decoders=e}or(e){return po(this,e)}decode(e){let t=e[0],n=this.decoders[t];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 po(r,e){return new qn({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}var Gn=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,t,n,i){this.name=e,this.prefix=t,this.baseEncode=n,this.baseDecode=i,this.encoder=new Hn(e,t,n),this.decoder=new jn(e,t,i)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function ht({name:r,prefix:e,encode:t,decode:n}){return new Gn(r,e,t,n)}function Re({name:r,prefix:e,alphabet:t}){let{encode:n,decode:i}=mo(t,r);return ht({prefix:e,name:r,encode:n,decode:o=>ye(i(o))})}function Qc(r,e,t,n){let i=r.length;for(;r[i-1]==="=";)--i;let o=new Uint8Array(i*t/8|0),s=0,a=0,c=0;for(let f=0;f<i;++f){let u=e[r[f]];if(u===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<t|u,s+=t,s>=8&&(s-=8,o[c++]=255&a>>s)}if(s>=t||(255&a<<8-s)!==0)throw new SyntaxError("Unexpected end of data");return o}function eu(r,e,t){let n=e[e.length-1]==="=",i=(1<<t)-1,o="",s=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],s+=8;s>t;)s-=t,o+=e[i&a>>s];if(s!==0&&(o+=e[i&a<<t-s]),n)for(;(o.length*t&7)!==0;)o+="=";return o}function tu(r){let e={};for(let t=0;t<r.length;++t)e[r[t]]=t;return e}function F({name:r,prefix:e,bitsPerChar:t,alphabet:n}){let i=tu(n);return ht({prefix:e,name:r,encode(o){return eu(o,n,t)},decode(o){return Qc(o,i,t,r)}})}var Me=F({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),ru=F({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),nu=F({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),iu=F({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),ou=F({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),su=F({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),au=F({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),cu=F({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),uu=F({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Jn={};X(Jn,{base36:()=>Rt,base36upper:()=>fu});var Rt=Re({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),fu=Re({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Kn={};X(Kn,{base58btc:()=>le,base58flickr:()=>lu});var le=Re({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),lu=Re({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var hu=wo,yo=128,du=127,mu=~du,pu=Math.pow(2,31);function wo(r,e,t){e=e||[],t=t||0;for(var n=t;r>=pu;)e[t++]=r&255|yo,r/=128;for(;r&mu;)e[t++]=r&255|yo,r>>>=7;return e[t]=r|0,wo.bytes=t-n+1,e}var yu=Xn,gu=128,go=127;function Xn(r,n){var t=0,n=n||0,i=0,o=n,s,a=r.length;do{if(o>=a)throw Xn.bytes=0,new RangeError("Could not decode varint");s=r[o++],t+=i<28?(s&go)<<i:(s&go)*Math.pow(2,i),i+=7}while(s>=gu);return Xn.bytes=o-n,t}var wu=Math.pow(2,7),xu=Math.pow(2,14),bu=Math.pow(2,21),_u=Math.pow(2,28),Su=Math.pow(2,35),ku=Math.pow(2,42),Eu=Math.pow(2,49),vu=Math.pow(2,56),Bu=Math.pow(2,63),Iu=function(r){return r<wu?1:r<xu?2:r<bu?3:r<_u?4:r<Su?5:r<ku?6:r<Eu?7:r<vu?8:r<Bu?9:10},Cu={encode:hu,decode:yu,encodingLength:Iu},Nu=Cu,Mt=Nu;function Ot(r,e=0){return[Mt.decode(r,e),Mt.decode.bytes]}function dt(r,e,t=0){return Mt.encode(r,e,t),e}function mt(r){return Mt.encodingLength(r)}function yt(r,e){let t=e.byteLength,n=mt(r),i=n+mt(t),o=new Uint8Array(i+t);return dt(r,o,0),dt(t,o,n),o.set(e,i),new pt(r,t,e,o)}function Ir(r){let e=ye(r),[t,n]=Ot(e),[i,o]=Ot(e.subarray(n)),s=e.subarray(n+o);if(s.byteLength!==i)throw new Error("Incorrect length");return new pt(t,i,s,e)}function xo(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&uo(r.bytes,t.bytes)}}var pt=class{code;size;digest;bytes;constructor(e,t,n,i){this.code=e,this.size=t,this.digest=n,this.bytes=i}};function bo(r,e){let{bytes:t,version:n}=r;switch(n){case 0:return Tu(t,Yn(r),e??le.encoder);default:return Du(t,Yn(r),e??Me.encoder)}}var _o=new WeakMap;function Yn(r){let e=_o.get(r);if(e==null){let t=new Map;return _o.set(r,t),t}return e}var E=class r{code;version;multihash;bytes;"/";constructor(e,t,n,i){this.code=t,this.version=e,this.multihash=n,this.bytes=i,this["/"]=i}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:t}=this;if(e!==Vt)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==Lu)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(t)}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:t}=this.multihash,n=yt(e,t);return r.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 r.equals(this,e)}static equals(e,t){let n=t;return n!=null&&e.code===n.code&&e.version===n.version&&xo(e.multihash,n.multihash)}toString(e){return bo(this,e)}toJSON(){return{"/":bo(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 t=e;if(t instanceof r)return t;if(t["/"]!=null&&t["/"]===t.bytes||t.asCID===t){let{version:n,code:i,multihash:o,bytes:s}=t;return new r(n,i,o,s??So(n,i,o.bytes))}else if(t[Fu]===!0){let{version:n,multihash:i,code:o}=t,s=Ir(i);return r.create(n,o,s)}else return null}static create(e,t,n){if(typeof t!="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(t!==Vt)throw new Error(`Version 0 CID must use dag-pb (code: ${Vt}) block encoding`);return new r(e,t,n,n.bytes)}case 1:{let i=So(e,t,n.bytes);return new r(e,t,n,i)}default:throw new Error("Invalid version")}}static createV0(e){return r.create(0,Vt,e)}static createV1(e,t){return r.create(1,e,t)}static decode(e){let[t,n]=r.decodeFirst(e);if(n.length!==0)throw new Error("Incorrect length");return t}static decodeFirst(e){let t=r.inspectBytes(e),n=t.size-t.multihashSize,i=ye(e.subarray(n,n+t.multihashSize));if(i.byteLength!==t.multihashSize)throw new Error("Incorrect length");let o=i.subarray(t.multihashSize-t.digestSize),s=new pt(t.multihashCode,t.digestSize,o,i);return[t.version===0?r.createV0(s):r.createV1(t.codec,s),e.subarray(t.size)]}static inspectBytes(e){let t=0,n=()=>{let[l,d]=Ot(e.subarray(t));return t+=d,l},i=n(),o=Vt;if(i===18?(i=0,t=0):o=n(),i!==0&&i!==1)throw new RangeError(`Invalid CID version ${i}`);let s=t,a=n(),c=n(),f=t+c,u=f-s;return{version:i,codec:o,multihashCode:a,digestSize:c,multihashSize:u,size:f}}static parse(e,t){let[n,i]=Au(e,t),o=r.decode(i);if(o.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Yn(o).set(n,e),o}};function Au(r,e){switch(r[0]){case"Q":{let t=e??le;return[le.prefix,t.decode(`${le.prefix}${r}`)]}case le.prefix:{let t=e??le;return[le.prefix,t.decode(r)]}case Me.prefix:{let t=e??Me;return[Me.prefix,t.decode(r)]}case Rt.prefix:{let t=e??Rt;return[Rt.prefix,t.decode(r)]}default:{if(e==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[r[0],e.decode(r)]}}}function Tu(r,e,t){let{prefix:n}=t;if(n!==le.prefix)throw Error(`Cannot string encode V0 in ${t.name} encoding`);let i=e.get(n);if(i==null){let o=t.encode(r).slice(1);return e.set(n,o),o}else return i}function Du(r,e,t){let{prefix:n}=t,i=e.get(n);if(i==null){let o=t.encode(r);return e.set(n,o),o}else return i}var Vt=112,Lu=18;function So(r,e,t){let n=mt(r),i=n+mt(e),o=new Uint8Array(i+t.byteLength);return dt(r,o,0),dt(e,o,n),o.set(t,i),o}var Fu=Symbol.for("@ipld/js-cid/CID");function zu(r){return r[Symbol.asyncIterator]!=null}function Pu(r){if(zu(r))return(async()=>{for await(let e of r)return e})();for(let e of r)return e}var Cr=Pu;function Uu(r){return r[Symbol.asyncIterator]!=null}function $u(r,e=1){return e=Number(e),Uu(r)?(async function*(){let t=[];if(e<1&&(e=1),e!==Math.round(e))throw new Error("Batch size must be an integer");for await(let n of r)for(t.push(n);t.length>=e;)yield t.slice(0,e),t=t.slice(e);for(;t.length>0;)yield t.slice(0,e),t=t.slice(e)})():(function*(){let t=[];if(e<1&&(e=1),e!==Math.round(e))throw new Error("Batch size must be an integer");for(let n of r)for(t.push(n);t.length>=e;)yield t.slice(0,e),t=t.slice(e);for(;t.length>0;)yield t.slice(0,e),t=t.slice(e)})()}var Nr=$u;async function*Ht(r,e=1){for await(let t of Nr(r,e)){let n=t.map(async i=>i().then(o=>({ok:!0,value:o}),o=>({ok:!1,err:o})));for(let i=0;i<n.length;i++){let o=await n[i];if(o.ok)yield o.value;else throw o.err}}}function ge(r=0){return new Uint8Array(r)}function re(r=0){return new Uint8Array(r)}function Ce(r,e){e==null&&(e=r.reduce((i,o)=>i+o.length,0));let t=re(e),n=0;for(let i of r)t.set(i,n),n+=i.length;return t}function Ar(r,e){if(r===e)return!0;if(r.byteLength!==e.byteLength)return!1;for(let t=0;t<r.byteLength;t++)if(r[t]!==e[t])return!1;return!0}var Eo=Symbol.for("@achingbrain/uint8arraylist");function ko(r,e){if(e==null||e<0)throw new RangeError("index is out of bounds");let t=0;for(let n of r){let i=t+n.byteLength;if(e<i)return{buf:n,index:e-t};t=i}throw new RangeError("index is out of bounds")}function Tr(r){return!!r?.[Eo]}var wt=class r{bufs;length;[Eo]=!0;constructor(...e){this.bufs=[],this.length=0,e.length>0&&this.appendAll(e)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...e){this.appendAll(e)}appendAll(e){let t=0;for(let n of e)if(n instanceof Uint8Array)t+=n.byteLength,this.bufs.push(n);else if(Tr(n))t+=n.byteLength,this.bufs.push(...n.bufs);else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=t}prepend(...e){this.prependAll(e)}prependAll(e){let t=0;for(let n of e.reverse())if(n instanceof Uint8Array)t+=n.byteLength,this.bufs.unshift(n);else if(Tr(n))t+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=t}get(e){let t=ko(this.bufs,e);return t.buf[t.index]}set(e,t){let n=ko(this.bufs,e);n.buf[n.index]=t}write(e,t=0){if(e instanceof Uint8Array)for(let n=0;n<e.length;n++)this.set(t+n,e[n]);else if(Tr(e))for(let n=0;n<e.length;n++)this.set(t+n,e.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(e){if(e=Math.trunc(e),!(Number.isNaN(e)||e<=0)){if(e===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(e>=this.bufs[0].byteLength)e-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(e),this.length-=e;break}}}slice(e,t){let{bufs:n,length:i}=this._subList(e,t);return Ce(n,i)}subarray(e,t){let{bufs:n,length:i}=this._subList(e,t);return n.length===1?n[0]:Ce(n,i)}sublist(e,t){let{bufs:n,length:i}=this._subList(e,t),o=new r;return o.length=i,o.bufs=[...n],o}_subList(e,t){if(e=e??0,t=t??this.length,e<0&&(e=this.length+e),t<0&&(t=this.length+t),e<0||t>this.length)throw new RangeError("index is out of bounds");if(e===t)return{bufs:[],length:0};if(e===0&&t===this.length)return{bufs:this.bufs,length:this.length};let n=[],i=0;for(let o=0;o<this.bufs.length;o++){let s=this.bufs[o],a=i,c=a+s.byteLength;if(i=c,e>=c)continue;let f=e>=a&&e<c,u=t>a&&t<=c;if(f&&u){if(e===a&&t===c){n.push(s);break}let l=e-a;n.push(s.subarray(l,l+(t-e)));break}if(f){if(e===0){n.push(s);continue}n.push(s.subarray(e-a));continue}if(u){if(t===c){n.push(s);break}n.push(s.subarray(0,t-a));break}n.push(s)}return{bufs:n,length:t-e}}indexOf(e,t=0){if(!Tr(e)&&!(e instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=e instanceof Uint8Array?e:e.subarray();if(t=Number(t??0),isNaN(t)&&(t=0),t<0&&(t=this.length+t),t<0&&(t=0),e.length===0)return t>this.length?this.length:t;let i=n.byteLength;if(i===0)throw new TypeError("search must be at least 1 byte long");let o=256,s=new Int32Array(o);for(let l=0;l<o;l++)s[l]=-1;for(let l=0;l<i;l++)s[n[l]]=l;let a=s,c=this.byteLength-n.byteLength,f=n.byteLength-1,u;for(let l=t;l<=c;l+=u){u=0;for(let d=f;d>=0;d--){let p=this.get(l+d);if(n[d]!==p){u=Math.max(1,d-a[p]);break}}if(u===0)return l}return-1}getInt8(e){let t=this.subarray(e,e+1);return new DataView(t.buffer,t.byteOffset,t.byteLength).getInt8(0)}setInt8(e,t){let n=re(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,t),this.write(n,e)}getInt16(e,t){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,t)}setInt16(e,t,n){let i=ge(2);new DataView(i.buffer,i.byteOffset,i.byteLength).setInt16(0,t,n),this.write(i,e)}getInt32(e,t){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,t)}setInt32(e,t,n){let i=ge(4);new DataView(i.buffer,i.byteOffset,i.byteLength).setInt32(0,t,n),this.write(i,e)}getBigInt64(e,t){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,t)}setBigInt64(e,t,n){let i=ge(8);new DataView(i.buffer,i.byteOffset,i.byteLength).setBigInt64(0,t,n),this.write(i,e)}getUint8(e){let t=this.subarray(e,e+1);return new DataView(t.buffer,t.byteOffset,t.byteLength).getUint8(0)}setUint8(e,t){let n=re(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,t),this.write(n,e)}getUint16(e,t){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,t)}setUint16(e,t,n){let i=ge(2);new DataView(i.buffer,i.byteOffset,i.byteLength).setUint16(0,t,n),this.write(i,e)}getUint32(e,t){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,t)}setUint32(e,t,n){let i=ge(4);new DataView(i.buffer,i.byteOffset,i.byteLength).setUint32(0,t,n),this.write(i,e)}getBigUint64(e,t){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,t)}setBigUint64(e,t,n){let i=ge(8);new DataView(i.buffer,i.byteOffset,i.byteLength).setBigUint64(0,t,n),this.write(i,e)}getFloat32(e,t){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,t)}setFloat32(e,t,n){let i=ge(4);new DataView(i.buffer,i.byteOffset,i.byteLength).setFloat32(0,t,n),this.write(i,e)}getFloat64(e,t){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,t)}setFloat64(e,t,n){let i=ge(8);new DataView(i.buffer,i.byteOffset,i.byteLength).setFloat64(0,t,n),this.write(i,e)}equals(e){if(e==null||!(e instanceof r)||e.bufs.length!==this.bufs.length)return!1;for(let t=0;t<this.bufs.length;t++)if(!Ar(this.bufs[t],e.bufs[t]))return!1;return!0}static fromUint8Arrays(e,t){let n=new r;return n.bufs=e,t==null&&(t=e.reduce((i,o)=>i+o.byteLength,0)),n.length=t,n}};var Ru=262144,jt=(r={})=>{let e=r.chunkSize??Ru;return async function*(n){let i=new wt,o=0,s=!1;for await(let a of n)for(i.append(a),o+=a.length;o>=e;)if(yield i.slice(0,e),s=!0,e===i.length)i=new wt,o=0;else{let c=new wt;c.append(i.sublist(e)),i=c,o-=e}(!s||o>0)&&(yield i.subarray(0,o))}};var $={};X($,{code:()=>H,createLink:()=>Fo,createNode:()=>Lo,decode:()=>D,encode:()=>I,name:()=>Xu,prepare:()=>z,validate:()=>ei});var Mu=new TextDecoder;function Zn(r,e){let t=0;for(let n=0;;n+=7){if(n>=64)throw new Error("protobuf: varint overflow");if(e>=r.length)throw new Error("protobuf: unexpected end of data");let i=r[e++];if(t+=n<28?(i&127)<<n:(i&127)*2**n,i<128)break}return[t,e]}function Dr(r,e){let t;[t,e]=Zn(r,e);let n=e+t;if(t<0||n<0)throw new Error("protobuf: invalid length");if(n>r.length)throw new Error("protobuf: unexpected end of data");return[r.subarray(e,n),n]}function vo(r,e){let t;return[t,e]=Zn(r,e),[t&7,t>>3,e]}function Ou(r){let e={},t=r.length,n=0;for(;n<t;){let i,o;if([i,o,n]=vo(r,n),o===1){if(e.Hash)throw new Error("protobuf: (PBLink) duplicate Hash section");if(i!==2)throw new Error(`protobuf: (PBLink) wrong wireType (${i}) 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]=Dr(r,n)}else if(o===2){if(e.Name!==void 0)throw new Error("protobuf: (PBLink) duplicate Name section");if(i!==2)throw new Error(`protobuf: (PBLink) wrong wireType (${i}) for Name`);if(e.Tsize!==void 0)throw new Error("protobuf: (PBLink) invalid order, found Tsize before Name");let s;[s,n]=Dr(r,n),e.Name=Mu.decode(s)}else if(o===3){if(e.Tsize!==void 0)throw new Error("protobuf: (PBLink) duplicate Tsize section");if(i!==0)throw new Error(`protobuf: (PBLink) wrong wireType (${i}) for Tsize`);[e.Tsize,n]=Zn(r,n)}else throw new Error(`protobuf: (PBLink) invalid fieldNumber, expected 1, 2 or 3, got ${o}`)}if(n>t)throw new Error("protobuf: (PBLink) unexpected end of data");return e}function Bo(r){let e=r.length,t=0,n,i=!1,o;for(;t<e;){let a,c;if([a,c,t]=vo(r,t),a!==2)throw new Error(`protobuf: (PBNode) invalid wireType, expected 2, got ${a}`);if(c===1){if(o)throw new Error("protobuf: (PBNode) duplicate Data section");[o,t]=Dr(r,t),n&&(i=!0)}else if(c===2){if(i)throw new Error("protobuf: (PBNode) duplicate Links section");n||(n=[]);let f;[f,t]=Dr(r,t),n.push(Ou(f))}else throw new Error(`protobuf: (PBNode) invalid fieldNumber, expected 1 or 2, got ${c}`)}if(t>e)throw new Error("protobuf: (PBNode) unexpected end of data");let s={};return o&&(s.Data=o),s.Links=n||[],s}var Co=new TextEncoder,Io=2**32,Vu=2**31;function Hu(r,e){let t=e.length;if(typeof r.Tsize=="number"){if(r.Tsize<0)throw new Error("Tsize cannot be negative");if(!Number.isSafeInteger(r.Tsize))throw new Error("Tsize too large for encoding");t=qt(e,t,r.Tsize)-1,e[t]=24}if(typeof r.Name=="string"){let n=Co.encode(r.Name);t-=n.length,e.set(n,t),t=qt(e,t,n.length)-1,e[t]=18}return r.Hash&&(t-=r.Hash.length,e.set(r.Hash,t),t=qt(e,t,r.Hash.length)-1,e[t]=10),e.length-t}function No(r){let e=qu(r),t=new Uint8Array(e),n=e;if(r.Data&&(n-=r.Data.length,t.set(r.Data,n),n=qt(t,n,r.Data.length)-1,t[n]=10),r.Links)for(let i=r.Links.length-1;i>=0;i--){let o=Hu(r.Links[i],t.subarray(0,n));n-=o,n=qt(t,n,o)-1,t[n]=18}return t}function ju(r){let e=0;if(r.Hash){let t=r.Hash.length;e+=1+t+xt(t)}if(typeof r.Name=="string"){let t=Co.encode(r.Name).length;e+=1+t+xt(t)}return typeof r.Tsize=="number"&&(e+=1+xt(r.Tsize)),e}function qu(r){let e=0;if(r.Data){let t=r.Data.length;e+=1+t+xt(t)}if(r.Links)for(let t of r.Links){let n=ju(t);e+=1+n+xt(n)}return e}function qt(r,e,t){e-=xt(t);let n=e;for(;t>=Vu;)r[e++]=t&127|128,t/=128;for(;t>=128;)r[e++]=t&127|128,t>>>=7;return r[e]=t,n}function xt(r){return r%2===0&&r++,Math.floor((Gu(r)+6)/7)}function Gu(r){let e=0;return r>=Io&&(r=Math.floor(r/Io),e=32),r>=65536&&(r>>>=16,e+=16),r>=256&&(r>>>=8,e+=8),e+Wu[r]}var Wu=[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 Ju=["Data","Links"],Ku=["Hash","Name","Tsize"],Qn=new TextEncoder;function To(r,e){if(r===e)return 0;let t=r.Name?Qn.encode(r.Name):[],n=e.Name?Qn.encode(e.Name):[],i=t.length,o=n.length;for(let s=0,a=Math.min(i,o);s<a;++s)if(t[s]!==n[s]){i=t[s],o=n[s];break}return i<o?-1:o<i?1:0}function Ao(r,e){return!Object.keys(r).some(t=>!e.includes(t))}function Do(r){if(typeof r.asCID=="object"){let t=E.asCID(r);if(!t)throw new TypeError("Invalid DAG-PB form");return{Hash:t}}if(typeof r!="object"||Array.isArray(r))throw new TypeError("Invalid DAG-PB form");let e={};if(r.Hash){let t=E.asCID(r.Hash);try{t||(typeof r.Hash=="string"?t=E.parse(r.Hash):r.Hash instanceof Uint8Array&&(t=E.decode(r.Hash)))}catch(n){throw new TypeError(`Invalid DAG-PB form: ${n.message}`)}t&&(e.Hash=t)}if(!e.Hash)throw new TypeError("Invalid DAG-PB form");return typeof r.Name=="string"&&(e.Name=r.Name),typeof r.Tsize=="number"&&(e.Tsize=r.Tsize),e}function z(r){if((r instanceof Uint8Array||typeof r=="string")&&(r={Data:r}),typeof r!="object"||Array.isArray(r))throw new TypeError("Invalid DAG-PB form");let e={};if(r.Data!==void 0)if(typeof r.Data=="string")e.Data=Qn.encode(r.Data);else if(r.Data instanceof Uint8Array)e.Data=r.Data;else throw new TypeError("Invalid DAG-PB form");if(r.Links!==void 0)if(Array.isArray(r.Links))e.Links=r.Links.map(Do),e.Links.sort(To);else throw new TypeError("Invalid DAG-PB form");else e.Links=[];return e}function ei(r){if(!r||typeof r!="object"||Array.isArray(r)||r instanceof Uint8Array||r["/"]&&r["/"]===r.bytes)throw new TypeError("Invalid DAG-PB form");if(!Ao(r,Ju))throw new TypeError("Invalid DAG-PB form (extraneous properties)");if(r.Data!==void 0&&!(r.Data instanceof Uint8Array))throw new TypeError("Invalid DAG-PB form (Data must be bytes)");if(!Array.isArray(r.Links))throw new TypeError("Invalid DAG-PB form (Links must be a list)");for(let e=0;e<r.Links.length;e++){let t=r.Links[e];if(!t||typeof t!="object"||Array.isArray(t)||t instanceof Uint8Array||t["/"]&&t["/"]===t.bytes)throw new TypeError("Invalid DAG-PB form (bad link)");if(!Ao(t,Ku))throw new TypeError("Invalid DAG-PB form (extraneous properties on link)");if(t.Hash===void 0)throw new TypeError("Invalid DAG-PB form (link must have a Hash)");if(t.Hash==null||!t.Hash["/"]||t.Hash["/"]!==t.Hash.bytes)throw new TypeError("Invalid DAG-PB form (link Hash must be a CID)");if(t.Name!==void 0&&typeof t.Name!="string")throw new TypeError("Invalid DAG-PB form (link Name must be a string)");if(t.Tsize!==void 0){if(typeof t.Tsize!="number"||t.Tsize%1!==0)throw new TypeError("Invalid DAG-PB form (link Tsize must be an integer)");if(t.Tsize<0)throw new TypeError("Invalid DAG-PB form (link Tsize cannot be negative)")}if(e>0&&To(t,r.Links[e-1])===-1)throw new TypeError("Invalid DAG-PB form (links must be sorted by Name bytes)")}}function Lo(r,e=[]){return z({Data:r,Links:e})}function Fo(r,e,t){return Do({Hash:t,Name:r,Tsize:e})}function zo(r){return r instanceof ArrayBuffer?new Uint8Array(r,0,r.byteLength):r}var Xu="dag-pb",H=112;function I(r){ei(r);let e={};return r.Links&&(e.Links=r.Links.map(t=>{let n={};return t.Hash&&(n.Hash=t.Hash.bytes),t.Name!==void 0&&(n.Name=t.Name),t.Tsize!==void 0&&(n.Tsize=t.Tsize),n})),r.Data&&(e.Data=r.Data),No(e)}function D(r){let e=zo(r),t=Bo(e),n={};return t.Data&&(n.Data=t.Data),t.Links&&(n.Links=t.Links.map(i=>{let o={};try{o.Hash=E.decode(i.Hash)}catch{}if(!o.Hash)throw new Error("Invalid Hash field found in link, expected CID");return i.Name!==void 0&&(o.Name=i.Name),i.Tsize!==void 0&&(o.Tsize=i.Tsize),o})),n}var Gt=class r extends Error{static name="InvalidTypeError";static code="ERR_INVALID_TYPE";name=r.name;code=r.code;constructor(e="Invalid type"){super(e)}},Lr=class r extends Error{static name="InvalidUnixFSMessageError";static code="ERR_INVALID_MESSAGE";name=r.name;code=r.code;constructor(e="Invalid message"){super(e)}};var Yu=Math.pow(2,7),Zu=Math.pow(2,14),Qu=Math.pow(2,21),Po=Math.pow(2,28),Uo=Math.pow(2,35),$o=Math.pow(2,42),Ro=Math.pow(2,49),Y=128,Oe=127;function Wt(r){if(r<Yu)return 1;if(r<Zu)return 2;if(r<Qu)return 3;if(r<Po)return 4;if(r<Uo)return 5;if(r<$o)return 6;if(r<Ro)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Mo(r,e,t=0){switch(Wt(r)){case 8:e[t++]=r&255|Y,r/=128;case 7:e[t++]=r&255|Y,r/=128;case 6:e[t++]=r&255|Y,r/=128;case 5:e[t++]=r&255|Y,r/=128;case 4:e[t++]=r&255|Y,r>>>=7;case 3:e[t++]=r&255|Y,r>>>=7;case 2:e[t++]=r&255|Y,r>>>=7;case 1:{e[t++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return e}function Oo(r,e){let t=r[e],n=0;if(n+=t&Oe,t<Y||(t=r[e+1],n+=(t&Oe)<<7,t<Y)||(t=r[e+2],n+=(t&Oe)<<14,t<Y)||(t=r[e+3],n+=(t&Oe)<<21,t<Y)||(t=r[e+4],n+=(t&Oe)*Po,t<Y)||(t=r[e+5],n+=(t&Oe)*Uo,t<Y)||(t=r[e+6],n+=(t&Oe)*$o,t<Y)||(t=r[e+7],n+=(t&Oe)*Ro,t<Y))return n;throw new RangeError("Could not decode varint")}var ti=new Float32Array([-0]),Ve=new Uint8Array(ti.buffer);function Vo(r,e,t){ti[0]=r,e[t]=Ve[0],e[t+1]=Ve[1],e[t+2]=Ve[2],e[t+3]=Ve[3]}function Ho(r,e){return Ve[0]=r[e],Ve[1]=r[e+1],Ve[2]=r[e+2],Ve[3]=r[e+3],ti[0]}var ri=new Float64Array([-0]),G=new Uint8Array(ri.buffer);function jo(r,e,t){ri[0]=r,e[t]=G[0],e[t+1]=G[1],e[t+2]=G[2],e[t+3]=G[3],e[t+4]=G[4],e[t+5]=G[5],e[t+6]=G[6],e[t+7]=G[7]}function qo(r,e){return G[0]=r[e],G[1]=r[e+1],G[2]=r[e+2],G[3]=r[e+3],G[4]=r[e+4],G[5]=r[e+5],G[6]=r[e+6],G[7]=r[e+7],ri[0]}var ef=BigInt(Number.MAX_SAFE_INTEGER),tf=BigInt(Number.MIN_SAFE_INTEGER),ne=class r{lo;hi;constructor(e,t){this.lo=e|0,this.hi=t|0}toNumber(e=!1){if(!e&&this.hi>>>31>0){let t=~this.lo+1>>>0,n=~this.hi>>>0;return t===0&&(n=n+1>>>0),-(t+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 t=~this.lo+1>>>0,n=~this.hi>>>0;return t===0&&(n=n+1>>>0),-(BigInt(t)+(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,t=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?t===0?e<16384?e<128?1:2:e<2097152?3:4:t<16384?t<128?5:6:t<2097152?7:8:n<128?9:10}static fromBigInt(e){if(e===0n)return Ze;if(e<ef&&e>tf)return this.fromNumber(Number(e));let t=e<0n;t&&(e=-e);let n=e>>32n,i=e-(n<<32n);return t&&(n=~n|0n,i=~i|0n,++i>Go&&(i=0n,++n>Go&&(n=0n))),new r(Number(i),Number(n))}static fromNumber(e){if(e===0)return Ze;let t=e<0;t&&(e=-e);let n=e>>>0,i=(e-n)/4294967296>>>0;return t&&(i=~i>>>0,n=~n>>>0,++n>4294967295&&(n=0,++i>4294967295&&(i=0))),new r(n,i)}static from(e){return typeof e=="number"?r.fromNumber(e):typeof e=="bigint"?r.fromBigInt(e):typeof e=="string"?r.fromBigInt(BigInt(e)):e.low!=null||e.high!=null?new r(e.low>>>0,e.high>>>0):Ze}},Ze=new ne(0,0);Ze.toBigInt=function(){return 0n};Ze.zzEncode=Ze.zzDecode=function(){return this};Ze.length=function(){return 1};var Go=4294967296n;function Wo(r){let e=0,t=0;for(let n=0;n<r.length;++n)t=r.charCodeAt(n),t<128?e+=1:t<2048?e+=2:(t&64512)===55296&&(r.charCodeAt(n+1)&64512)===56320?(++n,e+=4):e+=3;return e}function Jo(r,e,t){if(t-e<1)return"";let i,o=[],s=0,a;for(;e<t;)a=r[e++],a<128?o[s++]=a:a>191&&a<224?o[s++]=(a&31)<<6|r[e++]&63:a>239&&a<365?(a=((a&7)<<18|(r[e++]&63)<<12|(r[e++]&63)<<6|r[e++]&63)-65536,o[s++]=55296+(a>>10),o[s++]=56320+(a&1023)):o[s++]=(a&15)<<12|(r[e++]&63)<<6|r[e++]&63,s>8191&&((i??(i=[])).push(String.fromCharCode.apply(String,o)),s=0);return i!=null?(s>0&&i.push(String.fromCharCode.apply(String,o.slice(0,s))),i.join("")):String.fromCharCode.apply(String,o.slice(0,s))}function ni(r,e,t){let n=t,i,o;for(let s=0;s<r.length;++s)i=r.charCodeAt(s),i<128?e[t++]=i:i<2048?(e[t++]=i>>6|192,e[t++]=i&63|128):(i&64512)===55296&&((o=r.charCodeAt(s+1))&64512)===56320?(i=65536+((i&1023)<<10)+(o&1023),++s,e[t++]=i>>18|240,e[t++]=i>>12&63|128,e[t++]=i>>6&63|128,e[t++]=i&63|128):(e[t++]=i>>12|224,e[t++]=i>>6&63|128,e[t++]=i&63|128);return t-n}function we(r,e){return RangeError(`index out of range: ${r.pos} + ${e??1} > ${r.len}`)}function Fr(r,e){return(r[e-4]|r[e-3]<<8|r[e-2]<<16|r[e-1]<<24)>>>0}var ii=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(e){this.buf=e,this.pos=0,this.len=e.length}uint32(){let e=4294967295;if(e=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(e=(e|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return e;if((this.pos+=5)>this.len)throw this.pos=this.len,we(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 we(this,4);return Fr(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw we(this,4);return Fr(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw we(this,4);let e=Ho(this.buf,this.pos);return this.pos+=4,e}double(){if(this.pos+8>this.len)throw we(this,4);let e=qo(this.buf,this.pos);return this.pos+=8,e}bytes(){let e=this.uint32(),t=this.pos,n=this.pos+e;if(n>this.len)throw we(this,e);return this.pos+=e,t===n?new Uint8Array(0):this.buf.subarray(t,n)}string(){let e=this.bytes();return Jo(e,0,e.length)}skip(e){if(typeof e=="number"){if(this.pos+e>this.len)throw we(this,e);this.pos+=e}else do if(this.pos>=this.len)throw we(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 ne(0,0),t=0;if(this.len-this.pos>4){for(;t<4;++t)if(e.lo=(e.lo|(this.buf[this.pos]&127)<<t*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;t=0}else{for(;t<3;++t){if(this.pos>=this.len)throw we(this);if(e.lo=(e.lo|(this.buf[this.pos]&127)<<t*7)>>>0,this.buf[this.pos++]<128)return e}return e.lo=(e.lo|(this.buf[this.pos++]&127)<<t*7)>>>0,e}if(this.len-this.pos>4){for(;t<5;++t)if(e.hi=(e.hi|(this.buf[this.pos]&127)<<t*7+3)>>>0,this.buf[this.pos++]<128)return e}else for(;t<5;++t){if(this.pos>=this.len)throw we(this);if(e.hi=(e.hi|(this.buf[this.pos]&127)<<t*7+3)>>>0,this.buf[this.pos++]<128)return e}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw we(this,8);let e=Fr(this.buf,this.pos+=4),t=Fr(this.buf,this.pos+=4);return new ne(e,t)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let e=Oo(this.buf,this.pos);return this.pos+=Wt(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 oi(r){return new ii(r instanceof Uint8Array?r:r.subarray())}function Jt(r,e,t){let n=oi(r);return e.decode(n,void 0,t)}var si={};X(si,{base10:()=>rf});var rf=Re({prefix:"9",name:"base10",alphabet:"0123456789"});var ai={};X(ai,{base16:()=>nf,base16upper:()=>of});var nf=F({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),of=F({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var ci={};X(ci,{base2:()=>sf});var sf=F({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var ui={};X(ui,{base256emoji:()=>lf});var Xo=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}"),af=Xo.reduce((r,e,t)=>(r[t]=e,r),[]),cf=Xo.reduce((r,e,t)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return r[n]=t,r},[]);function uf(r){return r.reduce((e,t)=>(e+=af[t],e),"")}function ff(r){let e=[];for(let t of r){let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);let i=cf[n];if(i==null)throw new Error(`Non-base256emoji character: ${t}`);e.push(i)}return new Uint8Array(e)}var lf=ht({prefix:"\u{1F680}",name:"base256emoji",encode:uf,decode:ff});var fi={};X(fi,{base64:()=>Kt,base64pad:()=>hf,base64url:()=>df,base64urlpad:()=>mf});var Kt=F({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),hf=F({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),df=F({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),mf=F({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var li={};X(li,{base8:()=>pf});var pf=F({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var hi={};X(hi,{identity:()=>yf});var yf=ht({prefix:"\0",name:"identity",encode:r=>lo(r),decode:r=>fo(r)});var xm=new TextEncoder,gf=new TextDecoder;var zr=512;function Pr(r){return JSON.parse(gf.decode(r))}var xe={};X(xe,{code:()=>W,decode:()=>bf,encode:()=>xf,name:()=>wf});var wf="raw",W=85;function xf(r){return ye(r)}function bf(r){return ye(r)}var di={};X(di,{identity:()=>Yt});var Yo=0,_f="identity",Zo=ye;function Sf(r,e){if(e?.truncate!=null&&e.truncate!==r.byteLength){if(e.truncate<0||e.truncate>r.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${r.byteLength}`);r=r.subarray(0,e.truncate)}return yt(Yo,Zo(r))}var Yt={code:Yo,name:_f,encode:Zo,digest:Sf};var pi={};X(pi,{sha256:()=>ie,sha512:()=>Ef});var kf=20;function Qe({name:r,code:e,encode:t,minDigestLength:n,maxDigestLength:i}){return new mi(r,e,t,n,i)}var mi=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,t,n,i,o){this.name=e,this.code=t,this.encode=n,this.minDigestLength=i??kf,this.maxDigestLength=o}digest(e,t){if(t?.truncate!=null){if(t.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&t.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?Qo(n,this.code,t?.truncate):n.then(i=>Qo(i,this.code,t?.truncate))}else throw Error("Unknown type, must be binary type")}};function Qo(r,e,t){if(t!=null&&t!==r.byteLength){if(t>r.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${r.byteLength}`);r=r.subarray(0,t)}return yt(e,r)}function ts(r){return async e=>new Uint8Array(await crypto.subtle.digest(r,e))}var ie=Qe({name:"sha2-256",code:18,encode:ts("SHA-256")}),Ef=Qe({name:"sha2-512",code:19,encode:ts("SHA-512")});var yi={...hi,...ci,...li,...si,...ai,...Wn,...Jn,...Kn,...fi,...ui},Dm={...pi,...di};function ns(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}var rs=ns("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),gi=ns("ascii","a",r=>{let e="a";for(let t=0;t<r.length;t++)e+=String.fromCharCode(r[t]);return e},r=>{r=r.substring(1);let e=re(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),vf={utf8:rs,"utf-8":rs,hex:yi.base16,latin1:gi,ascii:gi,binary:gi,...yi},Ur=vf;function P(r,e="utf8"){let t=Ur[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.decoder.decode(`${t.prefix}${r}`)}function wi(r){let e=r??8192,t=e>>>1,n,i=e;return function(s){if(s<1||s>t)return re(s);i+s>e&&(n=re(e),i=0);let a=n.subarray(i,i+=s);return(i&7)!==0&&(i=(i|7)+1),a}}var et=class{fn;len;next;val;constructor(e,t,n){this.fn=e,this.len=t,this.next=void 0,this.val=n}};function xi(){}var _i=class{head;tail;len;next;constructor(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}},Bf=wi();function If(r){return globalThis.Buffer!=null?re(r):Bf(r)}var Qt=class{len;head;tail;states;constructor(){this.len=0,this.head=new et(xi,0,0),this.tail=this.head,this.states=null}_push(e,t,n){return this.tail=this.tail.next=new et(e,t,n),this.len+=t,this}uint32(e){return this.len+=(this.tail=this.tail.next=new Si((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($r,10,ne.fromNumber(e)):this.uint32(e)}sint32(e){return this.uint32((e<<1^e>>31)>>>0)}uint64(e){let t=ne.fromBigInt(e);return this._push($r,t.length(),t)}uint64Number(e){return this._push(Mo,Wt(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 t=ne.fromBigInt(e).zzEncode();return this._push($r,t.length(),t)}sint64Number(e){let t=ne.fromNumber(e).zzEncode();return this._push($r,t.length(),t)}sint64String(e){return this.sint64(BigInt(e))}bool(e){return this._push(bi,1,e?1:0)}fixed32(e){return this._push(Zt,4,e>>>0)}sfixed32(e){return this.fixed32(e)}fixed64(e){let t=ne.fromBigInt(e);return this._push(Zt,4,t.lo)._push(Zt,4,t.hi)}fixed64Number(e){let t=ne.fromNumber(e);return this._push(Zt,4,t.lo)._push(Zt,4,t.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(Vo,4,e)}double(e){return this._push(jo,8,e)}bytes(e){let t=e.length>>>0;return t===0?this._push(bi,1,0):this.uint32(t)._push(Nf,t,e)}string(e){let t=Wo(e);return t!==0?this.uint32(t)._push(ni,t,e):this._push(bi,1,0)}fork(){return this.states=new _i(this),this.head=this.tail=new et(xi,0,0),this.len=0,this}reset(){return this.states!=null?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new et(xi,0,0),this.len=0),this}ldelim(){let e=this.head,t=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=e.next,this.tail=t,this.len+=n),this}finish(){let e=this.head.next,t=If(this.len),n=0;for(;e!=null;)e.fn(e.val,t,n),n+=e.len,e=e.next;return t}};function bi(r,e,t){e[t]=r&255}function Cf(r,e,t){for(;r>127;)e[t++]=r&127|128,r>>>=7;e[t]=r}var Si=class extends et{next;constructor(e,t){super(Cf,e,t),this.next=void 0}};function $r(r,e,t){for(;r.hi!==0;)e[t++]=r.lo&127|128,r.lo=(r.lo>>>7|r.hi<<25)>>>0,r.hi>>>=7;for(;r.lo>127;)e[t++]=r.lo&127|128,r.lo=r.lo>>>7;e[t++]=r.lo}function Zt(r,e,t){e[t]=r&255,e[t+1]=r>>>8&255,e[t+2]=r>>>16&255,e[t+3]=r>>>24}function Nf(r,e,t){e.set(r,t)}globalThis.Buffer!=null&&(Qt.prototype.bytes=function(r){let e=r.length>>>0;return this.uint32(e),e>0&&this._push(Af,e,r),this},Qt.prototype.string=function(r){let e=globalThis.Buffer.byteLength(r);return this.uint32(e),e>0&&this._push(Tf,e,r),this});function Af(r,e,t){e.set(r,t)}function Tf(r,e,t){r.length<40?ni(r,e,t):e.utf8Write!=null?e.utf8Write(r,t):e.set(P(r),t)}function ki(){return new Qt}function er(r,e){let t=ki();return e.encode(r,t,{lengthDelimited:!1}),t.finish()}var bt;(function(r){r[r.VARINT=0]="VARINT",r[r.BIT64=1]="BIT64",r[r.LENGTH_DELIMITED=2]="LENGTH_DELIMITED",r[r.START_GROUP=3]="START_GROUP",r[r.END_GROUP=4]="END_GROUP",r[r.BIT32=5]="BIT32"})(bt||(bt={}));function Rr(r,e,t,n){return{name:r,type:e,encode:t,decode:n}}function Ei(r){function e(i){if(r[i.toString()]==null)throw new Error("Invalid enum value");return r[i]}let t=function(o,s){let a=e(o);s.int32(a)},n=function(o){let s=o.int32();return e(s)};return Rr("enum",bt.VARINT,t,n)}function tr(r,e){return Rr("message",bt.LENGTH_DELIMITED,r,e)}var be;(function(r){let e;(function(i){i.Raw="Raw",i.Directory="Directory",i.File="File",i.Metadata="Metadata",i.Symlink="Symlink",i.HAMTShard="HAMTShard"})(e=r.DataType||(r.DataType={}));let t;(function(i){i[i.Raw=0]="Raw",i[i.Directory=1]="Directory",i[i.File=2]="File",i[i.Metadata=3]="Metadata",i[i.Symlink=4]="Symlink",i[i.HAMTShard=5]="HAMTShard"})(t||(t={})),(function(i){i.codec=()=>Ei(t)})(e=r.DataType||(r.DataType={}));let n;r.codec=()=>(n==null&&(n=tr((i,o,s={})=>{if(s.lengthDelimited!==!1&&o.fork(),i.Type!=null&&(o.uint32(8),r.DataType.codec().encode(i.Type,o)),i.Data!=null&&(o.uint32(18),o.bytes(i.Data)),i.filesize!=null&&(o.uint32(24),o.uint64(i.filesize)),i.blocksizes!=null)for(let a of i.blocksizes)o.uint32(32),o.uint64(a);i.hashType!=null&&(o.uint32(40),o.uint64(i.hashType)),i.fanout!=null&&(o.uint32(48),o.uint64(i.fanout)),i.mode!=null&&(o.uint32(56),o.uint32(i.mode)),i.mtime!=null&&(o.uint32(66),Mr.codec().encode(i.mtime,o)),s.lengthDelimited!==!1&&o.ldelim()},(i,o)=>{let s={blocksizes:[]},a=o==null?i.len:i.pos+o;for(;i.pos<a;){let c=i.uint32();switch(c>>>3){case 1:s.Type=r.DataType.codec().decode(i);break;case 2:s.Data=i.bytes();break;case 3:s.filesize=i.uint64();break;case 4:s.blocksizes.push(i.uint64());break;case 5:s.hashType=i.uint64();break;case 6:s.fanout=i.uint64();break;case 7:s.mode=i.uint32();break;case 8:s.mtime=Mr.codec().decode(i,i.uint32());break;default:i.skipType(c&7);break}}return s})),n),r.encode=i=>er(i,r.codec()),r.decode=i=>Jt(i,r.codec())})(be||(be={}));var Mr;(function(r){let e;r.codec=()=>(e==null&&(e=tr((t,n,i={})=>{i.lengthDelimited!==!1&&n.fork(),t.Seconds!=null&&(n.uint32(8),n.int64(t.Seconds)),t.FractionalNanoseconds!=null&&(n.uint32(21),n.fixed32(t.FractionalNanoseconds)),i.lengthDelimited!==!1&&n.ldelim()},(t,n)=>{let i={},o=n==null?t.len:t.pos+n;for(;t.pos<o;){let s=t.uint32();switch(s>>>3){case 1:i.Seconds=t.int64();break;case 2:i.FractionalNanoseconds=t.fixed32();break;default:t.skipType(s&7);break}}return i})),e),r.encode=t=>er(t,r.codec()),r.decode=t=>Jt(t,r.codec())})(Mr||(Mr={}));var is;(function(r){let e;r.codec=()=>(e==null&&(e=tr((t,n,i={})=>{i.lengthDelimited!==!1&&n.fork(),t.MimeType!=null&&(n.uint32(10),n.string(t.MimeType)),i.lengthDelimited!==!1&&n.ldelim()},(t,n)=>{let i={},o=n==null?t.len:t.pos+n;for(;t.pos<o;){let s=t.uint32();switch(s>>>3){case 1:i.MimeType=t.string();break;default:t.skipType(s&7);break}}return i})),e),r.encode=t=>er(t,r.codec()),r.decode=t=>Jt(t,r.codec())})(is||(is={}));var os={Raw:"raw",Directory:"directory",File:"file",Metadata:"metadata",Symlink:"symlink",HAMTShard:"hamt-sharded-directory"},Df=["directory","hamt-sharded-directory"],ss=parseInt("0644",8),as=parseInt("0755",8),cs=BigInt(1024),S=class r{static unmarshal(e){let t=be.decode(e);if(t.fanout!=null&&t.fanout>cs)throw new Lr(`Fanout size was too large - ${t.fanout} > ${cs}`);let n=new r({type:os[t.Type!=null?t.Type.toString():"File"],data:t.Data,blockSizes:t.blocksizes,mode:t.mode,mtime:t.mtime!=null?{secs:t.mtime.Seconds??0n,nsecs:t.mtime.FractionalNanoseconds}:void 0,fanout:t.fanout});return n._originalMode=t.mode??0,n}type;data;blockSizes;hashType;fanout;mtime;_mode;_originalMode;constructor(e={type:"file"}){let{type:t,data:n,blockSizes:i,hashType:o,fanout:s,mtime:a,mode:c}=e;if(t!=null&&!Object.values(os).includes(t))throw new Gt("Type: "+t+" is not valid");this.type=t??"file",this.data=n,this.hashType=o,this.fanout=s,this.blockSizes=i??[],this._originalMode=0,this.mode=c,this.mtime=a}set mode(e){e==null?this._mode=this.isDirectory()?as:ss:this._mode=e&4095}get mode(){return this._mode}isDirectory(){return Df.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(t=>{e+=t}),this.data!=null&&(e+=BigInt(this.data.length)),e}marshal(){let e;switch(this.type){case"raw":e=be.DataType.Raw;break;case"directory":e=be.DataType.Directory;break;case"file":e=be.DataType.File;break;case"metadata":e=be.DataType.Metadata;break;case"symlink":e=be.DataType.Symlink;break;case"hamt-sharded-directory":e=be.DataType.HAMTShard;break;default:throw new Gt(`Type: ${e} is not valid`)}let t=this.data;(this.data==null||this.data.length===0)&&(t=void 0);let n;this.mode!=null&&(n=this._originalMode&4294963200|(this.mode??0),n===ss&&!this.isDirectory()&&(n=void 0),n===as&&this.isDirectory()&&(n=void 0));let i;return this.mtime!=null&&(i={Seconds:this.mtime.secs,FractionalNanoseconds:this.mtime.nsecs}),be.encode({Type:e,Data:t,filesize:this.isDirectory()?void 0:this.fileSize(),blocksizes:this.blockSizes,hashType:this.hashType,fanout:this.fanout,mode:n,mtime:i})}};var V=class extends Event{type;detail;constructor(e,t){super(e),this.type=e,this.detail=t}};var _e=async(r,e,t)=>{t.codec==null&&(t.codec=$);let n=await ie.digest(r),i=E.create(t.cidVersion,t.codec.code,n);return await e.put(i,r,t),i};function us(r){return async function*(t,n){let i=0n;for await(let o of t.content)yield async()=>{let s,a={codec:$,cidVersion:r.cidVersion,onProgress:r.onProgress};r.rawLeaves?(a.codec=xe,a.cidVersion=1):(s=new S({type:r.leafType,data:o}),o=I({Data:s.marshal(),Links:[]}));let c=await _e(o,n,a);return i+=BigInt(o.byteLength),r.onProgress?.(new V("unixfs:importer:progress:file:write",{bytesWritten:i,cid:c,path:t.path})),{cid:c,unixfs:s,size:BigInt(o.length),block:o}}}}var Or=class r extends Error{static name="InvalidParametersError";static code="ERR_INVALID_PARAMS";name=r.name;code=r.code;constructor(e="Invalid parameters"){super(e)}};var He=class r extends Error{static name="InvalidContentError";static code="ERR_INVALID_CONTENT";name=r.name;code=r.code;constructor(e="Invalid content"){super(e)}};var fs=async(r,e,t)=>{let n=new S({type:"directory",mtime:r.mtime,mode:r.mode}),i=I(z({Data:n.marshal()})),o=await _e(i,e,t),s=r.path;return{cid:o,path:s,unixfs:n,size:BigInt(i.length),originalPath:r.originalPath,block:i}};async function*Lf(r,e,t){let n=-1,i;for await(let o of Ht(t.bufferImporter(r,e),t.blockWriteConcurrency)){if(n++,n===0){i={...o,single:!0};continue}else n===1&&i!=null&&(yield{...i,block:void 0,single:void 0},i=void 0);yield{...o,block:void 0}}i!=null&&(yield i)}function ls(r){return r.single===!0}var Ff=(r,e,t)=>async function(i){if(i.length===1&&ls(i[0])&&t.reduceSingleLeafToSelf){let u=i[0],l=u.block;return ls(u)&&(r.mtime!==void 0||r.mode!==void 0)&&(u.unixfs=new S({type:"file",mtime:r.mtime,mode:r.mode,data:u.block}),l={Data:u.unixfs.marshal(),Links:[]},u.block=I(z(l)),u.cid=await _e(u.block,e,{...t,cidVersion:t.cidVersion}),u.size=BigInt(u.block.length)),t.onProgress?.(new V("unixfs:importer:progress:file:layout",{cid:u.cid,path:u.originalPath})),{cid:u.cid,path:r.path,unixfs:u.unixfs,size:u.size,originalPath:u.originalPath}}let o=new S({type:"file",mtime:r.mtime,mode:r.mode}),s=i.filter(u=>u.cid.code===W&&u.size>0||u.unixfs!=null&&u.unixfs.data==null&&u.unixfs.fileSize()>0n?!0:!!u.unixfs?.data?.length).map(u=>u.cid.code===W?(o.addBlockSize(u.size),{Name:"",Tsize:Number(u.size),Hash:u.cid}):(u.unixfs?.data==null?o.addBlockSize(u.unixfs?.fileSize()??0n):o.addBlockSize(BigInt(u.unixfs.data.length)),{Name:"",Tsize:Number(u.size),Hash:u.cid})),a={Data:o.marshal(),Links:s},c=I(z(a)),f=await _e(c,e,t);return t.onProgress?.(new V("unixfs:importer:progress:file:layout",{cid:f,path:r.originalPath})),{cid:f,path:r.path,unixfs:o,size:BigInt(c.length+a.Links.reduce((u,l)=>u+(l.Tsize??0),0)),originalPath:r.originalPath,block:c}},hs=async(r,e,t)=>t.layout(Lf(r,e,t),Ff(r,e,t));function zf(r){return Symbol.iterator in r}function Pf(r){return Symbol.asyncIterator in r}function Uf(r){try{if(r instanceof Uint8Array)return(async function*(){yield r})();if(zf(r))return(async function*(){yield*r})();if(Pf(r))return r}catch{throw new He("Content was invalid")}throw new He("Content was invalid")}function ds(r){return async function*(t,n){for await(let i of t){let o;if(i.path!=null&&(o=i.path,i.path=i.path.split("/").filter(s=>s!=null&&s!==".").join("/")),$f(i)){let s={path:i.path,mtime:i.mtime,mode:i.mode,content:(async function*(){let c=0n;for await(let f of r.chunker(r.chunkValidator(Uf(i.content)))){let u=BigInt(f.byteLength);c+=u,r.onProgress?.(new V("unixfs:importer:progress:file:read",{bytesRead:c,chunkSize:u,path:i.path})),yield f}})(),originalPath:o},a=r.fileBuilder??hs;yield async()=>a(s,n,r)}else if(i.path!=null){let s={path:i.path,mtime:i.mtime,mode:i.mode,originalPath:o},a=r.dirBuilder??fs;yield async()=>a(s,n,r)}else throw new Error("Import candidate must have content or path or both")}}}function $f(r){return r.content!=null}var ms=()=>async function*(e){for await(let t of e){if(t.length===void 0)throw new He("Content was invalid");if(typeof t=="string"||t instanceof String)yield P(t.toString());else if(Array.isArray(t))yield Uint8Array.from(t);else if(t instanceof Uint8Array)yield t;else throw new He("Content was invalid")}};var Rf=174;function rr(r){let e=r?.maxChildrenPerNode??Rf;return async function t(n,i){let o=[];for await(let s of Nr(n,e))o.push(await i(s));return o.length>1?t(o,i):o[0]}}function Mf(r){return r[Symbol.asyncIterator]!=null}function Of(r){if(Mf(r))return(async()=>{let t=[];for await(let n of r)t.push(n);return t})();let e=[];for(let t of r)e.push(t);return e}var ps=Of;var Ne=class{options;root;dir;path;dirty;flat;parent;parentKey;unixfs;mode;mtime;cid;size;nodeSize;constructor(e,t){this.options=t??{},this.root=e.root,this.dir=e.dir,this.path=e.path,this.dirty=e.dirty,this.flat=e.flat,this.parent=e.parent,this.parentKey=e.parentKey,this.unixfs=e.unixfs,this.mode=e.mode,this.mtime=e.mtime}},nr=E.parse("QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn"),ir=E.parse("zdj7WbTaiJT1fgatdet9Ei9iDB5hdCxkbVyhyh8YTUnXMiwYi");var tt=class extends Ne{_children;constructor(e,t){super(e,t),this._children=new Map}async put(e,t){this.cid=void 0,this.size=void 0,this.nodeSize=void 0,this._children.set(e,t)}async get(e){return Promise.resolve(this._children.get(e))}childCount(){return this._children.size}directChildrenCount(){return this.childCount()}onlyChild(){return this._children.values().next().value}*eachChildSeries(){for(let[e,t]of this._children.entries())yield{key:e,child:t}}estimateNodeSize(){if(this.nodeSize!==void 0)return this.nodeSize;this.nodeSize=0;for(let[e,t]of this._children.entries())t.size!=null&&t.cid!=null&&(this.nodeSize+=e.length+(this.options.cidVersion===1?ir.bytes.byteLength:nr.bytes.byteLength));return this.nodeSize}async*flush(e){let t=[];for(let[c,f]of this._children.entries()){let u=f;if(f instanceof Ne)for await(let l of f.flush(e))u=l,yield l;u.size!=null&&u.cid!=null&&t.push({Name:c,Tsize:Number(u.size),Hash:u.cid})}let n=new S({type:"directory",mtime:this.mtime,mode:this.mode}),i={Data:n.marshal(),Links:t},o=I(z(i)),s=await _e(o,e,this.options),a=o.length+i.Links.reduce((c,f)=>c+(f.Tsize??0),0);this.cid=s,this.size=a,yield{cid:s,unixfs:n,path:this.path,size:BigInt(a)}}};function je(r,e){let t=r.lo+e.lo>>>0,n=r.hi+e.hi+(t<r.lo?1:0)>>>0;return{lo:t,hi:n}}function Vf(r,e){return r+e>>>0}function he(r,e){let t=r.lo&65535,n=r.lo>>>16,i=e.lo&65535,o=e.lo>>>16,s=t*i,a=t*o,c=n*i,f=n*o,u=(s>>>16)+(a&65535)+(c&65535)>>>0,l=(u<<16|s&65535)>>>0,d=f+(a>>>16)+(c>>>16)+(u>>>16),p=Math.imul(r.lo,e.hi),m=Math.imul(r.hi,e.lo),w=d+p+m>>>0;return{lo:l,hi:w}}function rt(r,e){return Math.imul(r,e)>>>0}function _t(r,e){if(e===0)return r;if(e===32)return{lo:r.hi,hi:r.lo};if(e<32){let i=(r.lo<<e|r.hi>>>32-e)>>>0,o=(r.hi<<e|r.lo>>>32-e)>>>0;return{lo:i,hi:o}}e-=32;let t=(r.hi<<e|r.lo>>>32-e)>>>0,n=(r.lo<<e|r.hi>>>32-e)>>>0;return{lo:t,hi:n}}function A(r,e){return{lo:(r.lo^e.lo)>>>0,hi:(r.hi^e.hi)>>>0}}function vi(r,e){if(e===0)return r;if(e<32){let t=(r.lo>>>e|r.hi<<32-e)>>>0,n=r.hi>>>e;return{lo:t,hi:n}}return{lo:r.hi>>>e-32,hi:0}}function N(r,e){return{lo:r>>>0,hi:e>>>0}}function Bi(r,e){return(r<<e|r>>>32-e)>>>0}function ys(r,e){let t=e*8,n=r[t]|r[t+1]<<8|r[t+2]<<16|r[t+3]<<24,i=r[t+4]|r[t+5]<<8|r[t+6]<<16|r[t+7]<<24;return{lo:n>>>0,hi:i>>>0}}function Hf(r,e){let t=e*4;return(r[t]|r[t+1]<<8|r[t+2]<<16|r[t+3]<<24)>>>0}function gs(r){return r=A(r,vi(r,33)),r=he(r,N(3981806797,4283543511)),r=A(r,vi(r,33)),r=he(r,N(444984403,3301882366)),r=A(r,vi(r,33)),r}function jf(r){return r^=r>>>16,r=rt(r,2246822507),r^=r>>>13,r=rt(r,3266489909),r^=r>>>16,r}function Ii(r,e=0){let t=N(e,0),n=N(e,0),i=r.length,o=Math.floor(i/16),s=N(289559509,2277735313),a=N(658871167,1291169091);for(let d=0;d<o;d++){let p=ys(r,d*2),m=ys(r,d*2+1);p=he(p,s),p=_t(p,31),p=he(p,a),t=A(t,p),t=_t(t,27),t=je(t,n),t=je(he(t,N(5,0)),N(1390208809,0)),m=he(m,a),m=_t(m,33),m=he(m,s),n=A(n,m),n=_t(n,31),n=je(n,t),n=je(he(n,N(5,0)),N(944331445,0))}let c=N(0,0),f=N(0,0),u=r.slice(o*16);switch(u.length){case 15:f=A(f,N(0,u[14]<<16));case 14:f=A(f,N(0,u[13]<<8));case 13:f=A(f,N(0,u[12]));case 12:f=A(f,N(u[11]<<24,0));case 11:f=A(f,N(u[10]<<16,0));case 10:f=A(f,N(u[9]<<8,0));case 9:f=A(f,N(u[8],0)),f=he(f,a),f=_t(f,33),f=he(f,s),n=A(n,f);case 8:c=A(c,N(0,u[7]<<24));case 7:c=A(c,N(0,u[6]<<16));case 6:c=A(c,N(0,u[5]<<8));case 5:c=A(c,N(0,u[4]));case 4:c=A(c,N(u[3]<<24,0));case 3:c=A(c,N(u[2]<<16,0));case 2:c=A(c,N(u[1]<<8,0));case 1:c=A(c,N(u[0],0)),c=he(c,s),c=_t(c,31),c=he(c,a),t=A(t,c)}let l=N(i,0);return t=A(t,l),n=A(n,l),t=je(t,n),n=je(n,t),t=gs(t),n=gs(n),t=je(t,n),n=je(n,t),new Uint8Array([t.hi>>>24&255,t.hi>>>16&255,t.hi>>>8&255,t.hi&255,t.lo>>>24&255,t.lo>>>16&255,t.lo>>>8&255,t.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 ws(r,e=0){let t=e>>>0,n=r.length,i=Math.floor(n/4),o=3432918353,s=461845907;for(let f=0;f<i;f++){let u=Hf(r,f);u=rt(u,o),u=Bi(u,15),u=rt(u,s),t^=u,t=Bi(t,13),t=Vf(rt(t,5),3864292196)}let a=r.slice(i*4),c=0;switch(a.length){case 3:c^=a[2]<<16;case 2:c^=a[1]<<8;case 1:c^=a[0],c=rt(c,o),c=Bi(c,15),c=rt(c,s),t^=c}return t^=n,t=jf(t),t}function Gf(r){let e=new Array(4);for(let t=0;t<4;t++)e[t]=r&255,r=r>>8;return new Uint8Array(e)}var ey=Qe({name:"murmur3-32",code:35,encode:r=>Gf(ws(r))}),nt=Qe({name:"murmur3-128",code:34,encode:r=>Ii(r)}),ty=Qe({name:"murmur3-x64-64",code:34,encode:r=>Ii(r).subarray(0,8)});var _s=vr(Vr(),1);var oe=class r{_options;_popCount;_parent;_posAtParent;_children;key;constructor(e,t,n=0){this._options=e,this._popCount=0,this._parent=t,this._posAtParent=n,this._children=new _s.default,this.key=null}async put(e,t){let n=await this._findNewBucketAndPos(e);n.bucket._putAt(n,e,t)}async get(e){let t=await this._findChild(e);if(t!=null)return t.value}async del(e){let t=await this._findPlace(e),n=t.bucket._at(t.pos);n!=null&&n.key===e&&t.bucket._delAt(t.pos)}leafCount(){return this._children.compactArray().reduce((t,n)=>n instanceof r?t+n.leafCount():t+1,0)}childrenCount(){return this._children.length}onlyChild(){return this._children.get(0)}*eachLeafSeries(){let e=this._children.compactArray();for(let t of e)t instanceof r?yield*t.eachLeafSeries():yield t}serialize(e,t){let n=[];return t(this._children.reduce((i,o,s)=>(o!=null&&(o instanceof r?i.push(o.serialize(e,t)):i.push(e(o,s))),i),n))}async asyncTransform(e,t){return Ss(this,e,t)}toJSON(){return this.serialize(Yf,Zf)}prettyPrint(){return JSON.stringify(this.toJSON(),null," ")}tableSize(){return Math.pow(2,this._options.bits)}async _findChild(e){let t=await this._findPlace(e),n=t.bucket._at(t.pos);if(!(n instanceof r)&&n!=null&&n.key===e)return n}async _findPlace(e){let t=this._options.hash(typeof e=="string"?P(e):e),n=await t.take(this._options.bits),i=this._children.get(n);return i instanceof r?i._findPlace(t):{bucket:this,pos:n,hash:t,existingChild:i}}async _findNewBucketAndPos(e){let t=await this._findPlace(e);if(t.existingChild!=null&&t.existingChild.key!==e){let n=new r(this._options,t.bucket,t.pos);t.bucket._putObjectAt(t.pos,n);let i=await n._findPlace(t.existingChild.hash);return i.bucket._putAt(i,t.existingChild.key,t.existingChild.value),n._findNewBucketAndPos(t.hash)}return t}_putAt(e,t,n){this._putObjectAt(e.pos,{key:t,value:n,hash:e.hash})}_putObjectAt(e,t){this._children.get(e)==null&&this._popCount++,this._children.set(e,t)}_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(Xf);if(e!=null&&!(e instanceof r)){let t=e.hash;t.untake(this._options.bits);let n={pos:this._posAtParent,hash:t,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 Xf(r){return!!r}function Yf(r,e){return r.key}function Zf(r){return r}async function Ss(r,e,t){let n=[];for(let i of r._children.compactArray())if(i instanceof oe)await Ss(i,e,t);else{let o=await e(i);n.push({bitField:r._children.bitField(),children:o})}return t(n)}var Qf=[255,254,252,248,240,224,192,128],el=[1,3,7,15,31,63,127,255],Hr=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 t=e,n=0;for(;t>0&&this._haveBits();){let i=this._value[this._currentBytePos],o=this._currentBitPos+1,s=Math.min(o,t),a=tl(i,o-s,s);n=(n<<s)+a,t-=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 tl(r,e,t){let n=rl(e,t);return(r&n)>>>e}function rl(r,e){return Qf[r]&el[Math.min(e+r-1,7)]}function ks(r){function e(t){return t instanceof jr?t:new jr(t,r)}return e}var jr=class{_value;_hashFn;_depth;_availableBits;_currentBufferIndex;_buffers;constructor(e,t){if(!(e instanceof Uint8Array))throw new Error("can only hash Uint8Arrays");this._value=e,this._hashFn=t,this._depth=-1,this._availableBits=0,this._currentBufferIndex=0,this._buffers=[]}async take(e){let t=e;for(;this._availableBits<t;)await this._produceMoreBits();let n=0;for(;t>0;){let i=this._buffers[this._currentBufferIndex],o=Math.min(i.availableBits(),t),s=i.take(o);n=(n<<o)+s,t-=o,this._availableBits-=o,i.availableBits()===0&&this._currentBufferIndex++}return n}untake(e){let t=e;for(;t>0;){let n=this._buffers[this._currentBufferIndex],i=Math.min(n.totalBits()-n.availableBits(),t);n.untake(i),t-=i,this._availableBits+=i,this._currentBufferIndex>0&&n.totalBits()===n.availableBits()&&(this._depth--,this._currentBufferIndex--)}}async _produceMoreBits(){this._depth++;let e=this._depth>0?Ce([this._value,Uint8Array.from([this._depth])]):this._value,t=await this._hashFn(e),n=new Hr(t);this._buffers.push(n),this._availableBits+=n.availableBits()}};function St(r){if(r==null||r.hashFn==null)throw new Error("please define an options.hashFn");let e={bits:r.bits??8,hash:ks(r.hashFn)};return new oe(e)}async function nl(r){return(await nt.encode(r)).slice(0,8).reverse()}var Es=BigInt(34),il=8,Ci=class extends Ne{_bucket;constructor(e,t){super(e,t),this._bucket=St({hashFn:nl,bits:t.shardFanoutBits??il})}async put(e,t){this.cid=void 0,this.size=void 0,this.nodeSize=void 0,await this._bucket.put(e,t)}async get(e){return this._bucket.get(e)}childCount(){return this._bucket.leafCount()}directChildrenCount(){return this._bucket.childrenCount()}onlyChild(){return this._bucket.onlyChild()}*eachChildSeries(){for(let{key:e,value:t}of this._bucket.eachLeafSeries())yield{key:e,child:t}}estimateNodeSize(){return this.nodeSize!==void 0?this.nodeSize:(this.nodeSize=Is(this._bucket,this,this.options),this.nodeSize)}async*flush(e){for await(let t of Bs(this._bucket,e,this,this.options))yield{...t,path:this.path}}},vs=Ci;async function*Bs(r,e,t,n){let i=r._children,o=(r.tableSize()-1).toString(16).length,s=[],a=0n;for(let m=0;m<i.length;m++){let w=i.get(m);if(w==null)continue;let g=m.toString(16).toUpperCase().padStart(o,"0");if(w instanceof oe){let b;for await(let k of Bs(w,e,null,n))b=k;if(b==null)throw new Error("Could not flush sharded directory, no subshard found");s.push({Name:g,Tsize:Number(b.size),Hash:b.cid}),a+=b.size}else if(ol(w.value)){let b=w.value,k;for await(let U of b.flush(e))k=U,yield k;if(k==null)throw new Error("Did not flush dir");let v=g+w.key;s.push({Name:v,Tsize:Number(k.size),Hash:k.cid}),a+=k.size}else{let b=w.value;if(b.cid==null)continue;let k=g+w.key,v=b.size;s.push({Name:k,Tsize:Number(v),Hash:b.cid}),a+=BigInt(v??0)}}let c=Uint8Array.from(i.bitField().reverse()),f=new S({type:"hamt-sharded-directory",data:c,fanout:BigInt(r.tableSize()),hashType:Es,mtime:t?.mtime,mode:t?.mode}),u={Data:f.marshal(),Links:s},l=I(z(u)),d=await _e(l,e,n),p=BigInt(l.byteLength)+a;yield{cid:d,unixfs:f,size:p}}function ol(r){return typeof r.flush=="function"}function Is(r,e,t){let n=r._children,i=(r.tableSize()-1).toString(16).length,o=[];for(let f=0;f<n.length;f++){let u=n.get(f);if(u==null)continue;let l=f.toString(16).toUpperCase().padStart(i,"0");if(u instanceof oe){let d=Is(u,null,t);o.push({Name:l,Tsize:Number(d),Hash:t.cidVersion===0?nr:ir})}else if(typeof u.value.flush=="function"){let p=u.value.nodeSize();o.push({Name:l+u.key,Tsize:Number(p),Hash:t.cidVersion===0?nr:ir})}else{let d=u.value;if(d.cid==null)continue;let p=l+u.key,m=d.size;o.push({Name:p,Tsize:Number(m),Hash:d.cid})}}let s=Uint8Array.from(n.bitField().reverse()),a=new S({type:"hamt-sharded-directory",data:s,fanout:BigInt(r.tableSize()),hashType:Es,mtime:e?.mtime,mode:e?.mode});return I(z({Data:a.marshal(),Links:o})).length}async function Ni(r,e,t,n){let i=e;e instanceof tt&&e.estimateNodeSize()>t&&(i=await sl(e,n));let o=i.parent;if(o!=null){if(i!==e){if(r!=null&&(r.parent=i),i.parentKey==null)throw new Error("No parent key found");await o.put(i.parentKey,i)}return Ni(i,o,t,n)}return i}async function sl(r,e){let t=new vs({root:r.root,dir:!0,parent:r.parent,parentKey:r.parentKey,path:r.path,dirty:r.dirty,flat:!1,mtime:r.mtime,mode:r.mode},e);for(let{key:n,child:i}of r.eachChildSeries())await t.put(n,i);return t}var Cs=(r="")=>r.split(/(?<!\\)\//).filter(Boolean);async function al(r,e,t){let n=Cs(r.path??""),i=n.length-1,o=e,s="";for(let a=0;a<n.length;a++){let c=n[a];s+=`${s!==""?"/":""}${c}`;let f=a===i;if(o.dirty=!0,o.cid=void 0,o.size=void 0,f)await o.put(c,r),e=await Ni(null,o,t.shardSplitThresholdBytes,t);else{let u=await o.get(c);(u==null||!(u instanceof Ne))&&(u=new tt({root:!1,dir:!0,parent:o,parentKey:c,path:s,dirty:!0,flat:!0,mtime:u?.unixfs?.mtime,mode:u?.unixfs?.mode},t)),await o.put(c,u),o=u}}return e}async function*Ns(r,e){if(!(r instanceof Ne)){r.unixfs?.isDirectory()===!0&&(yield r);return}yield*r.flush(e)}function As(r){return async function*(t,n){let i=new tt({root:!0,dir:!0,path:"",dirty:!0,flat:!0},r),o,s=!1;for await(let a of t){if(a==null)continue;let c=`${a.originalPath??""}`.split("/")[0];c!=null&&c!==""&&(o==null?(o=c,s=!0):o!==c&&(s=!1)),i=await al(a,i,r),a.unixfs?.isDirectory()!==!0&&(yield a)}if(r.wrapWithDirectory||s&&i.childCount()>1)yield*Ns(i,n);else for(let a of i.eachChildSeries())a!=null&&(yield*Ns(a.child,n))}}async function*it(r,e,t={}){let n;Symbol.asyncIterator in r||Symbol.iterator in r?n=r:n=[r];let i=t.wrapWithDirectory??!1,o=t.shardSplitThresholdBytes??262144,s=t.shardFanoutBits??8,a=t.cidVersion??1,c=t.rawLeaves??!0,f=t.leafType??"file",u=t.fileImportConcurrency??50,l=t.blockWriteConcurrency??10,d=t.reduceSingleLeafToSelf??!0,p=t.chunker??jt(),m=t.chunkValidator??ms(),w=t.dagBuilder??ds({chunker:p,chunkValidator:m,wrapWithDirectory:i,layout:t.layout??rr(),bufferImporter:t.bufferImporter??us({cidVersion:a,rawLeaves:c,leafType:f,onProgress:t.onProgress}),blockWriteConcurrency:l,reduceSingleLeafToSelf:d,cidVersion:a,onProgress:t.onProgress,dirBuilder:t.dirBuilder,fileBuilder:t.fileBuilder}),g=t.treeBuilder??As({wrapWithDirectory:i,shardSplitThresholdBytes:o,shardFanoutBits:s,cidVersion:a,onProgress:t.onProgress});for await(let b of g(Ht(w(n,e),u),e))yield{cid:b.cid,path:b.path,unixfs:b.unixfs,size:b.size}}async function Ts(r,e,t={}){let n=await Cr(it([r],e,t));if(n==null)throw new Or("Nothing imported");return n}async function Ds(r,e,t={}){return Ts({content:r},e,t)}async function Ls(r,e,t={}){return Ts({content:r},e,t)}function cl(r){return r[Symbol.asyncIterator]!=null}function ul(r){if(cl(r))return(async()=>{let t;for await(let n of r)t=n;return t})();let e;for(let t of r)e=t;return e}var Se=ul;var ke=class extends Error{name;code;constructor(e,t,n){super(e),this.name=t,this.code=n}},Ae=class extends ke{constructor(e="not a Unixfs node"){super(e,"NotUnixFSError","ERR_NOT_UNIXFS")}},Q=class extends ke{constructor(e="invalid PBNode"){super(e,"InvalidPBNodeError","ERR_INVALID_PB_NODE")}},qe=class extends ke{constructor(e="unknown error"){super(e,"InvalidPBNodeError","ERR_UNKNOWN_ERROR")}},ot=class extends ke{constructor(e="path already exists"){super(e,"AlreadyExistsError","ERR_ALREADY_EXISTS")}},ze=class extends ke{constructor(e="path does not exist"){super(e,"DoesNotExistError","ERR_DOES_NOT_EXIST")}},qr=class extends ke{constructor(e="no content"){super(e,"NoContentError","ERR_NO_CONTENT")}},Gr=class extends ke{constructor(e="not a file"){super(e,"NotAFileError","ERR_NOT_A_FILE")}},Ge=class extends ke{constructor(e="not a directory"){super(e,"NotADirectoryError","ERR_NOT_A_DIRECTORY")}},L=class extends ke{constructor(e="invalid parameters"){super(e,"InvalidParametersError","ERR_INVALID_PARAMETERS")}};var or={cidVersion:1,rawLeaves:!0,layout:rr({maxChildrenPerNode:1024}),chunker:jt({chunkSize:1048576})};async function*Wr(r,e,t={}){yield*it(r,e,{...or,...t})}async function Fs(r,e,t={}){let{cid:n}=await Ds(r,e,{...or,...t});return n}async function zs(r,e,t={}){let{cid:n}=await Ls(r,e,{...or,...t});return n}async function Ps(r,e,t={}){if(r.path==null)throw new L("path is required");if(r.content==null)throw new L("content is required");let n=await Se(Wr([r],e,{...or,...t,wrapWithDirectory:!0}));if(n==null)throw new L("Nothing imported");return n.cid}async function Us(r,e,t={}){if(r.content!=null)throw new L("Directories cannot have content, use addFile instead");let i=await(r.path==null?Cr:Se)(Wr([{...r,path:r.path??"-"}],e,{...or,...t,wrapWithDirectory:r.path!=null}));if(i==null)throw new L("Nothing imported");return i.cid}var kt=class r extends Error{static name="BadPathError";static code="ERR_BAD_PATH";name=r.name;code=r.code;constructor(e="Bad path"){super(e)}},se=class r extends Error{static name="NotFoundError";static code="ERR_NOT_FOUND";name=r.name;code=r.code;constructor(e="Not found"){super(e)}},Et=class r extends Error{static name="NoResolverError";static code="ERR_NO_RESOLVER";name=r.name;code=r.code;constructor(e="No resolver"){super(e)}},T=class r extends Error{static name="NotUnixFSError";static code="ERR_NOT_UNIXFS";name=r.name;code=r.code;constructor(e="Not UnixFS"){super(e)}},Jr=class r extends Error{static name="OverReadError";static code="ERR_OVER_READ";name=r.name;code=r.code;constructor(e="Over read"){super(e)}},Kr=class r extends Error{static name="UnderReadError";static code="ERR_UNDER_READ";name=r.name;code=r.code;constructor(e="Under read"){super(e)}},Pe=class r extends Error{static name="InvalidParametersError";static code="ERR_INVALID_PARAMS";name=r.name;code=r.code;constructor(e="Invalid parameters"){super(e)}};var fl=["Object","RegExp","Date","Error","Map","Set","WeakMap","WeakSet","ArrayBuffer","SharedArrayBuffer","DataView","Promise","URL","HTMLElement","Int8Array","Uint8ClampedArray","Int16Array","Uint16Array","Int32Array","Uint32Array","Float32Array","Float64Array","BigInt64Array","BigUint64Array"];function $s(r){if(r===null)return"null";if(r===void 0)return"undefined";if(r===!0||r===!1)return"boolean";let e=typeof r;if(e==="string"||e==="number"||e==="bigint"||e==="symbol")return e;if(e==="function")return"Function";if(Array.isArray(r))return"Array";if(r instanceof Uint8Array)return"Uint8Array";if(r.constructor===Object)return"Object";let t=ll(r);return t||"Object"}function ll(r){let e=Object.prototype.toString.call(r).slice(8,-1);if(fl.includes(e))return e}var h=class{constructor(e,t,n){this.major=e,this.majorEncoded=e<<5,this.name=t,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,t){return e===t||e.major===t.major&&e.name===t.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 y=class{constructor(e,t,n){this.type=e,this.value=t,this.encodedLength=n,this.encodedBytes=void 0,this.byteValue=void 0}toString(){return`Token[${this.type}].${this.value}`}};var sr=globalThis.process&&!globalThis.process.browser&&globalThis.Buffer&&typeof globalThis.Buffer.isBuffer=="function",hl=new TextEncoder;function Xr(r){return sr&&globalThis.Buffer.isBuffer(r)}function st(r){return r instanceof Uint8Array?Xr(r)?new Uint8Array(r.buffer,r.byteOffset,r.byteLength):r:Uint8Array.from(r)}var dl=24,ml=200,ar=sr?r=>r.length>=dl?globalThis.Buffer.from(r):Rs(r):r=>r.length>=ml?hl.encode(r):Rs(r),Te=r=>Uint8Array.from(r),Os=sr?(r,e,t)=>Xr(r)?new Uint8Array(r.subarray(e,t)):r.slice(e,t):(r,e,t)=>r.slice(e,t),Vs=sr?(r,e)=>(r=r.map(t=>t instanceof Uint8Array?t:globalThis.Buffer.from(t)),st(globalThis.Buffer.concat(r,e))):(r,e)=>{let t=new Uint8Array(e),n=0;for(let i of r)n+i.length>t.length&&(i=i.subarray(0,t.length-n)),t.set(i,n),n+=i.length;return t},Hs=sr?r=>globalThis.Buffer.allocUnsafe(r):r=>new Uint8Array(r);function Yr(r,e){if(Xr(r)&&Xr(e))return r.compare(e);for(let t=0;t<r.length;t++)if(r[t]!==e[t])return r[t]<e[t]?-1:1;return 0}function Rs(r){let e=[],t=0;for(let n=0;n<r.length;n++){let i=r.charCodeAt(n);i<128?e[t++]=i:i<2048?(e[t++]=i>>6|192,e[t++]=i&63|128):(i&64512)===55296&&n+1<r.length&&(r.charCodeAt(n+1)&64512)===56320?(i=65536+((i&1023)<<10)+(r.charCodeAt(++n)&1023),e[t++]=i>>18|240,e[t++]=i>>12&63|128,e[t++]=i>>6&63|128,e[t++]=i&63|128):(i>=55296&&i<=57343&&(i=65533),e[t++]=i>>12|224,e[t++]=i>>6&63|128,e[t++]=i&63|128)}return e}var Ms=4096;function js(r){let e=r.length;if(e<=Ms)return String.fromCharCode.apply(String,r);let t="",n=0;for(;n<e;)t+=String.fromCharCode.apply(String,r.slice(n,n+=Ms));return t}var pl=256,cr=class{constructor(e=pl){this.chunkSize=e,this.cursor=0,this.maxCursor=-1,this.chunks=[],this._initReuseChunk=null}reset(){this.cursor=0,this.maxCursor=-1,this.chunks.length&&(this.chunks=[]),this._initReuseChunk!==null&&(this.chunks.push(this._initReuseChunk),this.maxCursor=this._initReuseChunk.length-1)}push(e){let t=this.chunks[this.chunks.length-1];if(this.cursor+e.length<=this.maxCursor+1){let i=t.length-(this.maxCursor-this.cursor)-1;t.set(e,i)}else{if(t){let i=t.length-(this.maxCursor-this.cursor)-1;i<t.length&&(this.chunks[this.chunks.length-1]=t.subarray(0,i),this.maxCursor=this.cursor-1)}e.length<64&&e.length<this.chunkSize?(t=Hs(this.chunkSize),this.chunks.push(t),this.maxCursor+=t.length,this._initReuseChunk===null&&(this._initReuseChunk=t),t.set(e,0)):(this.chunks.push(e),this.maxCursor+=e.length)}this.cursor+=e.length}toBytes(e=!1){let t;if(this.chunks.length===1){let n=this.chunks[0];e&&this.cursor>n.length/2?(t=this.cursor===n.length?n:n.subarray(0,this.cursor),this._initReuseChunk=null,this.chunks=[]):t=Os(n,0,this.cursor)}else t=Vs(this.chunks,this.cursor);return e&&this.reset(),t}},Zr=class{constructor(e){this.dest=e,this.cursor=0,this.chunks=[e]}reset(){this.cursor=0}push(e){if(this.cursor+e.length>this.dest.length)throw new Error("write out of bounds, destination buffer is too small");this.dest.set(e,this.cursor),this.cursor+=e.length}toBytes(e=!1){let t=this.dest.subarray(0,this.cursor);return e&&this.reset(),t}};var _="CBOR decode error:",vt="CBOR encode error:",ur=[];ur[23]=1;ur[24]=2;ur[25]=3;ur[26]=5;ur[27]=9;function Ue(r,e,t){if(r.length-e<t)throw new Error(`${_} not enough data for type`)}var j=[24,256,65536,4294967296,BigInt("18446744073709551616")];function ae(r,e,t){Ue(r,e,1);let n=r[e];if(t.strict===!0&&n<j[0])throw new Error(`${_} integer encoded in more bytes than necessary (strict decode)`);return n}function ce(r,e,t){Ue(r,e,2);let n=r[e]<<8|r[e+1];if(t.strict===!0&&n<j[1])throw new Error(`${_} integer encoded in more bytes than necessary (strict decode)`);return n}function ue(r,e,t){Ue(r,e,4);let n=r[e]*16777216+(r[e+1]<<16)+(r[e+2]<<8)+r[e+3];if(t.strict===!0&&n<j[2])throw new Error(`${_} integer encoded in more bytes than necessary (strict decode)`);return n}function fe(r,e,t){Ue(r,e,8);let n=r[e]*16777216+(r[e+1]<<16)+(r[e+2]<<8)+r[e+3],i=r[e+4]*16777216+(r[e+5]<<16)+(r[e+6]<<8)+r[e+7],o=(BigInt(n)<<BigInt(32))+BigInt(i);if(t.strict===!0&&o<j[3])throw new Error(`${_} integer encoded in more bytes than necessary (strict decode)`);if(o<=Number.MAX_SAFE_INTEGER)return Number(o);if(t.allowBigInt===!0)return o;throw new Error(`${_} integers outside of the safe integer range are not supported`)}function qs(r,e,t,n){return new y(h.uint,ae(r,e+1,n),2)}function Gs(r,e,t,n){return new y(h.uint,ce(r,e+1,n),3)}function Ws(r,e,t,n){return new y(h.uint,ue(r,e+1,n),5)}function Js(r,e,t,n){return new y(h.uint,fe(r,e+1,n),9)}function de(r,e){return q(r,0,e.value)}function q(r,e,t){if(t<j[0]){let n=Number(t);r.push([e|n])}else if(t<j[1]){let n=Number(t);r.push([e|24,n])}else if(t<j[2]){let n=Number(t);r.push([e|25,n>>>8,n&255])}else if(t<j[3]){let n=Number(t);r.push([e|26,n>>>24&255,n>>>16&255,n>>>8&255,n&255])}else{let n=BigInt(t);if(n<j[4]){let i=[e|27,0,0,0,0,0,0,0],o=Number(n&BigInt(4294967295)),s=Number(n>>BigInt(32)&BigInt(4294967295));i[8]=o&255,o=o>>8,i[7]=o&255,o=o>>8,i[6]=o&255,o=o>>8,i[5]=o&255,i[4]=s&255,s=s>>8,i[3]=s&255,s=s>>8,i[2]=s&255,s=s>>8,i[1]=s&255,r.push(i)}else throw new Error(`${_} encountered BigInt larger than allowable range`)}}de.encodedSize=function(e){return q.encodedSize(e.value)};q.encodedSize=function(e){return e<j[0]?1:e<j[1]?2:e<j[2]?3:e<j[3]?5:9};de.compareTokens=function(e,t){return e.value<t.value?-1:e.value>t.value?1:0};function Ks(r,e,t,n){return new y(h.negint,-1-ae(r,e+1,n),2)}function Xs(r,e,t,n){return new y(h.negint,-1-ce(r,e+1,n),3)}function Ys(r,e,t,n){return new y(h.negint,-1-ue(r,e+1,n),5)}var Ai=BigInt(-1),Zs=BigInt(1);function Qs(r,e,t,n){let i=fe(r,e+1,n);if(typeof i!="bigint"){let o=-1-i;if(o>=Number.MIN_SAFE_INTEGER)return new y(h.negint,o,9)}if(n.allowBigInt!==!0)throw new Error(`${_} integers outside of the safe integer range are not supported`);return new y(h.negint,Ai-BigInt(i),9)}function Qr(r,e){let t=e.value,n=typeof t=="bigint"?t*Ai-Zs:t*-1-1;q(r,e.type.majorEncoded,n)}Qr.encodedSize=function(e){let t=e.value,n=typeof t=="bigint"?t*Ai-Zs:t*-1-1;return n<j[0]?1:n<j[1]?2:n<j[2]?3:n<j[3]?5:9};Qr.compareTokens=function(e,t){return e.value<t.value?1:e.value>t.value?-1:0};function fr(r,e,t,n){Ue(r,e,t+n);let i=r.slice(e+t,e+t+n);return new y(h.bytes,i,t+n)}function ea(r,e,t,n){return fr(r,e,1,t)}function ta(r,e,t,n){return fr(r,e,2,ae(r,e+1,n))}function ra(r,e,t,n){return fr(r,e,3,ce(r,e+1,n))}function na(r,e,t,n){return fr(r,e,5,ue(r,e+1,n))}function ia(r,e,t,n){let i=fe(r,e+1,n);if(typeof i=="bigint")throw new Error(`${_} 64-bit integer bytes lengths not supported`);return fr(r,e,9,i)}function en(r){return r.encodedBytes===void 0&&(r.encodedBytes=h.equals(r.type,h.string)?ar(r.value):r.value),r.encodedBytes}function Bt(r,e){let t=en(e);q(r,e.type.majorEncoded,t.length),r.push(t)}Bt.encodedSize=function(e){let t=en(e);return q.encodedSize(t.length)+t.length};Bt.compareTokens=function(e,t){return gl(en(e),en(t))};function gl(r,e){return r.length<e.length?-1:r.length>e.length?1:Yr(r,e)}var oa=new TextDecoder,xl=32;function bl(r,e,t){if(t-e<xl){let i="";for(let o=e;o<t;o++){let s=r[o];if(s&128)return oa.decode(r.subarray(e,t));i+=String.fromCharCode(s)}return i}return oa.decode(r.subarray(e,t))}function lr(r,e,t,n,i){let o=t+n;Ue(r,e,o);let s=new y(h.string,bl(r,e+t,e+o),o);return i.retainStringBytes===!0&&(s.byteValue=r.slice(e+t,e+o)),s}function sa(r,e,t,n){return lr(r,e,1,t,n)}function aa(r,e,t,n){return lr(r,e,2,ae(r,e+1,n),n)}function ca(r,e,t,n){return lr(r,e,3,ce(r,e+1,n),n)}function ua(r,e,t,n){return lr(r,e,5,ue(r,e+1,n),n)}function fa(r,e,t,n){let i=fe(r,e+1,n);if(typeof i=="bigint")throw new Error(`${_} 64-bit integer string lengths not supported`);return lr(r,e,9,i,n)}var la=Bt;function It(r,e,t,n){return new y(h.array,n,t)}function ha(r,e,t,n){return It(r,e,1,t)}function da(r,e,t,n){return It(r,e,2,ae(r,e+1,n))}function ma(r,e,t,n){return It(r,e,3,ce(r,e+1,n))}function pa(r,e,t,n){return It(r,e,5,ue(r,e+1,n))}function ya(r,e,t,n){let i=fe(r,e+1,n);if(typeof i=="bigint")throw new Error(`${_} 64-bit integer array lengths not supported`);return It(r,e,9,i)}function ga(r,e,t,n){if(n.allowIndefinite===!1)throw new Error(`${_} indefinite length items not allowed`);return It(r,e,1,1/0)}function tn(r,e){q(r,h.array.majorEncoded,e.value)}tn.compareTokens=de.compareTokens;tn.encodedSize=function(e){return q.encodedSize(e.value)};function Ct(r,e,t,n){return new y(h.map,n,t)}function wa(r,e,t,n){return Ct(r,e,1,t)}function xa(r,e,t,n){return Ct(r,e,2,ae(r,e+1,n))}function ba(r,e,t,n){return Ct(r,e,3,ce(r,e+1,n))}function _a(r,e,t,n){return Ct(r,e,5,ue(r,e+1,n))}function Sa(r,e,t,n){let i=fe(r,e+1,n);if(typeof i=="bigint")throw new Error(`${_} 64-bit integer map lengths not supported`);return Ct(r,e,9,i)}function ka(r,e,t,n){if(n.allowIndefinite===!1)throw new Error(`${_} indefinite length items not allowed`);return Ct(r,e,1,1/0)}function rn(r,e){q(r,h.map.majorEncoded,e.value)}rn.compareTokens=de.compareTokens;rn.encodedSize=function(e){return q.encodedSize(e.value)};function Ea(r,e,t,n){return new y(h.tag,t,1)}function va(r,e,t,n){return new y(h.tag,ae(r,e+1,n),2)}function Ba(r,e,t,n){return new y(h.tag,ce(r,e+1,n),3)}function Ia(r,e,t,n){return new y(h.tag,ue(r,e+1,n),5)}function Ca(r,e,t,n){return new y(h.tag,fe(r,e+1,n),9)}function nn(r,e){q(r,h.tag.majorEncoded,e.value)}nn.compareTokens=de.compareTokens;nn.encodedSize=function(e){return q.encodedSize(e.value)};var Ti=20,Di=21,Li=22,Fi=23;function Na(r,e,t,n){if(n.allowUndefined===!1)throw new Error(`${_} undefined values are not supported`);return n.coerceUndefinedToNull===!0?new y(h.null,null,1):new y(h.undefined,void 0,1)}function Aa(r,e,t,n){if(n.allowIndefinite===!1)throw new Error(`${_} indefinite length items not allowed`);return new y(h.break,void 0,1)}function zi(r,e,t){if(t){if(t.allowNaN===!1&&Number.isNaN(r))throw new Error(`${_} NaN values are not supported`);if(t.allowInfinity===!1&&(r===1/0||r===-1/0))throw new Error(`${_} Infinity values are not supported`)}return new y(h.float,r,e)}function Ta(r,e,t,n){return zi(Pi(r,e+1),3,n)}function Da(r,e,t,n){return zi(Ui(r,e+1),5,n)}function La(r,e,t,n){return zi(Ua(r,e+1),9,n)}function on(r,e,t){let n=e.value;if(n===!1)r.push([h.float.majorEncoded|Ti]);else if(n===!0)r.push([h.float.majorEncoded|Di]);else if(n===null)r.push([h.float.majorEncoded|Li]);else if(n===void 0)r.push([h.float.majorEncoded|Fi]);else{let i,o=!1;(!t||t.float64!==!0)&&(za(n),i=Pi(Ee,1),n===i||Number.isNaN(n)?(Ee[0]=249,r.push(Ee.slice(0,3)),o=!0):(Pa(n),i=Ui(Ee,1),n===i&&(Ee[0]=250,r.push(Ee.slice(0,5)),o=!0))),o||(vl(n),i=Ua(Ee,1),Ee[0]=251,r.push(Ee.slice(0,9)))}}on.encodedSize=function(e,t){let n=e.value;if(n===!1||n===!0||n===null||n===void 0)return 1;if(!t||t.float64!==!0){za(n);let i=Pi(Ee,1);if(n===i||Number.isNaN(n))return 3;if(Pa(n),i=Ui(Ee,1),n===i)return 5}return 9};var Fa=new ArrayBuffer(9),me=new DataView(Fa,1),Ee=new Uint8Array(Fa,0);function za(r){if(r===1/0)me.setUint16(0,31744,!1);else if(r===-1/0)me.setUint16(0,64512,!1);else if(Number.isNaN(r))me.setUint16(0,32256,!1);else{me.setFloat32(0,r);let e=me.getUint32(0),t=(e&2139095040)>>23,n=e&8388607;if(t===255)me.setUint16(0,31744,!1);else if(t===0)me.setUint16(0,(r&2147483648)>>16|n>>13,!1);else{let i=t-127;i<-24?me.setUint16(0,0):i<-14?me.setUint16(0,(e&2147483648)>>16|1<<24+i,!1):me.setUint16(0,(e&2147483648)>>16|i+15<<10|n>>13,!1)}}}function Pi(r,e){if(r.length-e<2)throw new Error(`${_} not enough data for float16`);let t=(r[e]<<8)+r[e+1];if(t===31744)return 1/0;if(t===64512)return-1/0;if(t===32256)return NaN;let n=t>>10&31,i=t&1023,o;return n===0?o=i*2**-24:n!==31?o=(i+1024)*2**(n-25):o=i===0?1/0:NaN,t&32768?-o:o}function Pa(r){me.setFloat32(0,r,!1)}function Ui(r,e){if(r.length-e<4)throw new Error(`${_} not enough data for float32`);let t=(r.byteOffset||0)+e;return new DataView(r.buffer,t,4).getFloat32(0,!1)}function vl(r){me.setFloat64(0,r,!1)}function Ua(r,e){if(r.length-e<8)throw new Error(`${_} not enough data for float64`);let t=(r.byteOffset||0)+e;return new DataView(r.buffer,t,8).getFloat64(0,!1)}on.compareTokens=de.compareTokens;function C(r,e,t){throw new Error(`${_} encountered invalid minor (${t}) for major ${r[e]>>>5}`)}function sn(r){return()=>{throw new Error(`${_} ${r}`)}}var x=[];for(let r=0;r<=23;r++)x[r]=C;x[24]=qs;x[25]=Gs;x[26]=Ws;x[27]=Js;x[28]=C;x[29]=C;x[30]=C;x[31]=C;for(let r=32;r<=55;r++)x[r]=C;x[56]=Ks;x[57]=Xs;x[58]=Ys;x[59]=Qs;x[60]=C;x[61]=C;x[62]=C;x[63]=C;for(let r=64;r<=87;r++)x[r]=ea;x[88]=ta;x[89]=ra;x[90]=na;x[91]=ia;x[92]=C;x[93]=C;x[94]=C;x[95]=sn("indefinite length bytes/strings are not supported");for(let r=96;r<=119;r++)x[r]=sa;x[120]=aa;x[121]=ca;x[122]=ua;x[123]=fa;x[124]=C;x[125]=C;x[126]=C;x[127]=sn("indefinite length bytes/strings are not supported");for(let r=128;r<=151;r++)x[r]=ha;x[152]=da;x[153]=ma;x[154]=pa;x[155]=ya;x[156]=C;x[157]=C;x[158]=C;x[159]=ga;for(let r=160;r<=183;r++)x[r]=wa;x[184]=xa;x[185]=ba;x[186]=_a;x[187]=Sa;x[188]=C;x[189]=C;x[190]=C;x[191]=ka;for(let r=192;r<=215;r++)x[r]=Ea;x[216]=va;x[217]=Ba;x[218]=Ia;x[219]=Ca;x[220]=C;x[221]=C;x[222]=C;x[223]=C;for(let r=224;r<=243;r++)x[r]=sn("simple values are not supported");x[244]=C;x[245]=C;x[246]=C;x[247]=Na;x[248]=sn("simple values are not supported");x[249]=Ta;x[250]=Da;x[251]=La;x[252]=C;x[253]=C;x[254]=C;x[255]=Aa;var ve=[];for(let r=0;r<24;r++)ve[r]=new y(h.uint,r,1);for(let r=-1;r>=-24;r--)ve[31-r]=new y(h.negint,r,1);ve[64]=new y(h.bytes,new Uint8Array(0),1);ve[96]=new y(h.string,"",1);ve[128]=new y(h.array,0,1);ve[160]=new y(h.map,0,1);ve[244]=new y(h.false,!1,1);ve[245]=new y(h.true,!0,1);ve[246]=new y(h.null,null,1);function $a(r){switch(r.type){case h.false:return Te([244]);case h.true:return Te([245]);case h.null:return Te([246]);case h.bytes:return r.value.length?void 0:Te([64]);case h.string:return r.value===""?Te([96]):void 0;case h.array:return r.value===0?Te([128]):void 0;case h.map:return r.value===0?Te([160]):void 0;case h.uint:return r.value<24?Te([Number(r.value)]):void 0;case h.negint:if(r.value>=-24)return Te([31-Number(r.value)])}}var Ma=Object.freeze({float64:!0,mapSorter:Tl,quickEncodeToken:$a});function Il(){let r=[];return r[h.uint.major]=de,r[h.negint.major]=Qr,r[h.bytes.major]=Bt,r[h.string.major]=la,r[h.array.major]=tn,r[h.map.major]=rn,r[h.tag.major]=nn,r[h.float.major]=on,r}var Cl=Il(),Nl=new cr,cn=class r{constructor(e,t){this.obj=e,this.parent=t}includes(e){let t=this;do if(t.obj===e)return!0;while(t=t.parent);return!1}static createCheck(e,t){if(e&&e.includes(t))throw new Error(`${vt} object contains circular references`);return new r(t,e)}},We={null:new y(h.null,null),undefined:new y(h.undefined,void 0),true:new y(h.true,!0),false:new y(h.false,!1),emptyArray:new y(h.array,0),emptyMap:new y(h.map,0)},Je={number(r,e,t,n){return!Number.isInteger(r)||!Number.isSafeInteger(r)?new y(h.float,r):r>=0?new y(h.uint,r):new y(h.negint,r)},bigint(r,e,t,n){return r>=BigInt(0)?new y(h.uint,r):new y(h.negint,r)},Uint8Array(r,e,t,n){return new y(h.bytes,r)},string(r,e,t,n){return new y(h.string,r)},boolean(r,e,t,n){return r?We.true:We.false},null(r,e,t,n){return We.null},undefined(r,e,t,n){return We.undefined},ArrayBuffer(r,e,t,n){return new y(h.bytes,new Uint8Array(r))},DataView(r,e,t,n){return new y(h.bytes,new Uint8Array(r.buffer,r.byteOffset,r.byteLength))},Array(r,e,t,n){if(!r.length)return t.addBreakTokens===!0?[We.emptyArray,new y(h.break)]:We.emptyArray;n=cn.createCheck(n,r);let i=[],o=0;for(let s of r)i[o++]=an(s,t,n);return t.addBreakTokens?[new y(h.array,r.length),i,new y(h.break)]:[new y(h.array,r.length),i]},Object(r,e,t,n){let i=e!=="Object",o=i?r.keys():Object.keys(r),s=i?r.size:o.length,a;if(s){a=new Array(s),n=cn.createCheck(n,r);let c=!i&&t.ignoreUndefinedProperties,f=0;for(let u of o){let l=i?r.get(u):r[u];c&&l===void 0||(a[f++]=[an(u,t,n),an(l,t,n)])}f<s&&(a.length=f)}return a?.length?(Al(a,t),t.addBreakTokens?[new y(h.map,a.length),a,new y(h.break)]:[new y(h.map,a.length),a]):t.addBreakTokens===!0?[We.emptyMap,new y(h.break)]:We.emptyMap}};Je.Map=Je.Object;Je.Buffer=Je.Uint8Array;for(let r of"Uint8Clamped Uint16 Uint32 Int8 Int16 Int32 BigUint64 BigInt64 Float32 Float64".split(" "))Je[`${r}Array`]=Je.DataView;function an(r,e={},t){let n=$s(r),i=e&&e.typeEncoders&&e.typeEncoders[n]||Je[n];if(typeof i=="function"){let s=i(r,n,e,t);if(s!=null)return s}let o=Je[n];if(!o)throw new Error(`${vt} unsupported type: ${n}`);return o(r,n,e,t)}function Al(r,e){e.mapSorter&&r.sort(e.mapSorter)}function Tl(r,e){if(r[0]instanceof y&&e[0]instanceof y){let t=r[0],n=e[0];return t._keyBytes||(t._keyBytes=Ra(t.value)),n._keyBytes||(n._keyBytes=Ra(n.value)),Yr(t._keyBytes,n._keyBytes)}throw new Error("rfc8949MapSorter: complex key types are not supported yet")}function Ra(r){return Va(r,Cl,Ma)}function Oa(r,e,t,n){if(Array.isArray(e))for(let i of e)Oa(r,i,t,n);else t[e.type.major](r,e,n)}var O0=h.uint.majorEncoded,V0=h.negint.majorEncoded,H0=h.bytes.majorEncoded,j0=h.string.majorEncoded,q0=h.array.majorEncoded,G0=h.float.majorEncoded|Ti,W0=h.float.majorEncoded|Di,J0=h.float.majorEncoded|Li,K0=h.float.majorEncoded|Fi,X0=BigInt(-1),Y0=BigInt(1);function Va(r,e,t,n){let i=n instanceof Uint8Array,o=i?new Zr(n):Nl,s=an(r,t);if(!Array.isArray(s)&&t.quickEncodeToken){let a=t.quickEncodeToken(s);if(a)return i?(o.push(a),o.toBytes()):a;let c=e[s.type.major];if(c.encodedSize){let f=c.encodedSize(s,t);if(i||(o=new cr(f)),c(o,s,t),o.chunks.length!==1)throw new Error(`Unexpected error: pre-calculated length for ${s} was wrong`);return i?o.toBytes():st(o.chunks[0])}}return o.reset(),Oa(o,s,e,t),o.toBytes(!0)}var Dl={strict:!1,allowIndefinite:!0,allowUndefined:!0,allowBigInt:!0},un=class{constructor(e,t={}){this._pos=0,this.data=e,this.options=t}pos(){return this._pos}done(){return this._pos>=this.data.length}next(){let e=this.data[this._pos],t=ve[e];if(t===void 0){let n=x[e];if(!n)throw new Error(`${_} no decoder for major type ${e>>>5} (byte 0x${e.toString(16).padStart(2,"0")})`);let i=e&31;t=n(this.data,this._pos,i,this.options)}return this._pos+=t.encodedLength,t}},hr=Symbol.for("DONE"),fn=Symbol.for("BREAK");function Ll(r,e,t){let n=[];for(let i=0;i<r.value;i++){let o=Nt(e,t);if(o===fn){if(r.value===1/0)break;throw new Error(`${_} got unexpected break to lengthed array`)}if(o===hr)throw new Error(`${_} found array but not enough entries (got ${i}, expected ${r.value})`);n[i]=o}return n}function Fl(r,e,t){let n=t.useMaps===!0,i=t.rejectDuplicateMapKeys===!0,o=n?void 0:{},s=n?new Map:void 0;for(let a=0;a<r.value;a++){let c=Nt(e,t);if(c===fn){if(r.value===1/0)break;throw new Error(`${_} got unexpected break to lengthed map`)}if(c===hr)throw new Error(`${_} found map but not enough entries (got ${a} [no key], expected ${r.value})`);if(!n&&typeof c!="string")throw new Error(`${_} non-string keys not supported (got ${typeof c})`);if(i&&(n&&s.has(c)||!n&&Object.hasOwn(o,c)))throw new Error(`${_} found repeat map key "${c}"`);let f=Nt(e,t);if(f===hr)throw new Error(`${_} found map but not enough entries (got ${a} [no value], expected ${r.value})`);n?s.set(c,f):o[c]=f}return n?s:o}function Nt(r,e){if(r.done())return hr;let t=r.next();if(h.equals(t.type,h.break))return fn;if(t.type.terminal)return t.value;if(h.equals(t.type,h.array))return Ll(t,r,e);if(h.equals(t.type,h.map))return Fl(t,r,e);if(h.equals(t.type,h.tag)){if(e.tags&&typeof e.tags[t.value]=="function"){let n=Nt(r,e);return e.tags[t.value](n)}throw new Error(`${_} tag not supported (${t.value})`)}throw new Error("unsupported")}function $i(r,e){if(!(r instanceof Uint8Array))throw new Error(`${_} data to decode must be a Uint8Array`);e=Object.assign({},Dl,e);let t=st(r),n=e.tokenizer||new un(t,e),i=Nt(n,e);if(i===hr)throw new Error(`${_} did not find any content to decode`);if(i===fn)throw new Error(`${_} got unexpected break`);return[i,r.subarray(n.pos())]}function dr(r,e){let[t,n]=$i(r,e);if(n.length>0)throw new Error(`${_} too many terminals, data makes no sense`);return t}var ja=42;function Ul(r){return r instanceof ArrayBuffer?new Uint8Array(r,0,r.byteLength):r}function $l(r){if(r.asCID!==r&&r["/"]!==r.bytes)return null;let e=E.asCID(r);if(!e)return null;let t=new Uint8Array(e.bytes.byteLength+1);return t.set(e.bytes,1),[new y(h.tag,ja),new y(h.bytes,t)]}function Rl(){throw new Error("`undefined` is not supported by the IPLD Data Model and cannot be encoded")}function Ml(r){if(Number.isNaN(r))throw new Error("`NaN` is not supported by the IPLD Data Model and cannot be encoded");if(r===1/0||r===-1/0)throw new Error("`Infinity` and `-Infinity` is not supported by the IPLD Data Model and cannot be encoded");return null}function Ol(r){for(let e of r.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 Ha={float64:!0,typeEncoders:{Map:Ol,Object:$l,undefined:Rl,number:Ml}},ug={...Ha,typeEncoders:{...Ha.typeEncoders}};function Vl(r){if(r[0]!==0)throw new Error("Invalid CID for CBOR tag 42; expected leading 0x00");return E.decode(r.subarray(1))}var ln={allowIndefinite:!1,coerceUndefinedToNull:!0,allowNaN:!1,allowInfinity:!1,allowBigInt:!0,strict:!0,useMaps:!1,rejectDuplicateMapKeys:!0,tags:[]};ln.tags[ja]=Vl;var fg={...ln,tags:ln.tags.slice()};var hn=113;var dn=r=>dr(Ul(r),ln);var qa=class extends Array{constructor(){super(),this.inRecursive=[]}prefix(e){let t=this.inRecursive[this.inRecursive.length-1];t&&(h.equals(t.type,h.array)&&(t.elements++,t.elements!==1&&e.push([44])),h.equals(t.type,h.map)&&(t.elements++,t.elements!==1&&(t.elements%2===1?e.push([44]):e.push([58]))))}[h.uint.major](e,t){this.prefix(e);let n=String(t.value),i=[];for(let o=0;o<n.length;o++)i[o]=n.charCodeAt(o);e.push(i)}[h.negint.major](e,t){this[h.uint.major](e,t)}[h.bytes.major](e,t){throw new Error(`${vt} unsupported type: Uint8Array`)}[h.string.major](e,t){this.prefix(e);let n=ar(JSON.stringify(t.value));e.push(n.length>32?st(n):n)}[h.array.major](e,t){this.prefix(e),this.inRecursive.push({type:h.array,elements:0}),e.push([91])}[h.map.major](e,t){this.prefix(e),this.inRecursive.push({type:h.map,elements:0}),e.push([123])}[h.tag.major](e,t){}[h.float.major](e,t){if(t.type.name==="break"){let s=this.inRecursive.pop();if(s){if(h.equals(s.type,h.array))e.push([93]);else if(h.equals(s.type,h.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(t.value===void 0)throw new Error(`${vt} unsupported type: undefined`);if(this.prefix(e),t.type.name==="true"){e.push([116,114,117,101]);return}else if(t.type.name==="false"){e.push([102,97,108,115,101]);return}else if(t.type.name==="null"){e.push([110,117,108,108]);return}let n=String(t.value),i=[],o=!1;for(let s=0;s<n.length;s++)i[s]=n.charCodeAt(s),!o&&(i[s]===46||i[s]===101||i[s]===69)&&(o=!0);o||(i.push(46),i.push(48)),e.push(i)}};var At=class{constructor(e,t={}){this._pos=0,this.data=e,this.options=t,this.modeStack=["value"],this.lastToken=""}pos(){return this._pos}done(){return this._pos>=this.data.length}ch(){return this.data[this._pos]}currentMode(){return this.modeStack[this.modeStack.length-1]}skipWhitespace(){let e=this.ch();for(;e===32||e===9||e===13||e===10;)e=this.data[++this._pos]}expect(e){if(this.data.length-this._pos<e.length)throw new Error(`${_} unexpected end of input at position ${this._pos}`);for(let t=0;t<e.length;t++)if(this.data[this._pos++]!==e[t])throw new Error(`${_} unexpected token at position ${this._pos}, expected to find '${String.fromCharCode(...e)}'`)}parseNumber(){let e=this._pos,t=!1,n=!1,i=a=>{for(;!this.done();){let c=this.ch();if(a.includes(c))this._pos++;else break}};if(this.ch()===45&&(t=!0,this._pos++),this.ch()===48)if(this._pos++,this.ch()===46)this._pos++,n=!0;else return new y(h.uint,0,this._pos-e);if(i([48,49,50,51,52,53,54,55,56,57]),t&&this._pos===e+1)throw new Error(`${_} unexpected token at position ${this._pos}`);if(!this.done()&&this.ch()===46){if(n)throw new Error(`${_} unexpected token at position ${this._pos}`);n=!0,this._pos++,i([48,49,50,51,52,53,54,55,56,57])}!this.done()&&(this.ch()===101||this.ch()===69)&&(n=!0,this._pos++,!this.done()&&(this.ch()===43||this.ch()===45)&&this._pos++,i([48,49,50,51,52,53,54,55,56,57]));let o=String.fromCharCode.apply(null,this.data.subarray(e,this._pos)),s=parseFloat(o);return n?new y(h.float,s,this._pos-e):this.options.allowBigInt!==!0||Number.isSafeInteger(s)?new y(s>=0?h.uint:h.negint,s,this._pos-e):new y(s>=0?h.uint:h.negint,BigInt(o),this._pos-e)}parseString(){if(this.ch()!==34)throw new Error(`${_} unexpected character at position ${this._pos}; this shouldn't happen`);this._pos++;for(let o=this._pos,s=0;o<this.data.length&&s<65536;o++,s++){let a=this.data[o];if(a===92||a<32||a>=128)break;if(a===34){let c=String.fromCharCode.apply(null,this.data.subarray(this._pos,o));return this._pos=o+1,new y(h.string,c,s)}}let e=this._pos,t=[],n=()=>{if(this._pos+4>=this.data.length)throw new Error(`${_} unexpected end of unicode escape sequence at position ${this._pos}`);let o=0;for(let s=0;s<4;s++){let a=this.ch();if(a>=48&&a<=57)a-=48;else if(a>=97&&a<=102)a=a-97+10;else if(a>=65&&a<=70)a=a-65+10;else throw new Error(`${_} unexpected unicode escape character at position ${this._pos}`);o=o*16+a,this._pos++}return o},i=()=>{let o=this.ch(),s=null,a=o>239?4:o>223?3:o>191?2:1;if(this._pos+a>this.data.length)throw new Error(`${_} unexpected unicode sequence at position ${this._pos}`);let c,f,u,l;switch(a){case 1:o<128&&(s=o);break;case 2:c=this.data[this._pos+1],(c&192)===128&&(l=(o&31)<<6|c&63,l>127&&(s=l));break;case 3:c=this.data[this._pos+1],f=this.data[this._pos+2],(c&192)===128&&(f&192)===128&&(l=(o&15)<<12|(c&63)<<6|f&63,l>2047&&(l<55296||l>57343)&&(s=l));break;case 4:c=this.data[this._pos+1],f=this.data[this._pos+2],u=this.data[this._pos+3],(c&192)===128&&(f&192)===128&&(u&192)===128&&(l=(o&15)<<18|(c&63)<<12|(f&63)<<6|u&63,l>65535&&l<1114112&&(s=l))}s===null?(s=65533,a=1):s>65535&&(s-=65536,t.push(s>>>10&1023|55296),s=56320|s&1023),t.push(s),this._pos+=a};for(;!this.done();){let o=this.ch(),s;switch(o){case 92:if(this._pos++,this.done())throw new Error(`${_} unexpected string termination at position ${this._pos}`);switch(s=this.ch(),this._pos++,s){case 34:case 39:case 92:case 47:t.push(s);break;case 98:t.push(8);break;case 116:t.push(9);break;case 110:t.push(10);break;case 102:t.push(12);break;case 114:t.push(13);break;case 117:t.push(n());break;default:throw new Error(`${_} unexpected string escape character at position ${this._pos}`)}break;case 34:return this._pos++,new y(h.string,js(t),this._pos-e);default:if(o<32)throw new Error(`${_} invalid control character at position ${this._pos}`);o<128?(t.push(o),this._pos++):i()}}throw new Error(`${_} unexpected end of string at position ${this._pos}`)}parseValue(){switch(this.ch()){case 123:return this.modeStack.push("obj-start"),this._pos++,new y(h.map,1/0,1);case 91:return this.modeStack.push("array-start"),this._pos++,new y(h.array,1/0,1);case 34:return this.parseString();case 110:return this.expect([110,117,108,108]),new y(h.null,null,4);case 102:return this.expect([102,97,108,115,101]),new y(h.false,!1,5);case 116:return this.expect([116,114,117,101]),new y(h.true,!0,4);case 45:case 48:case 49:case 50:case 51:case 52:case 53:case 54:case 55:case 56:case 57:return this.parseNumber();default:throw new Error(`${_} unexpected character at position ${this._pos}`)}}next(){switch(this.skipWhitespace(),this.currentMode()){case"value":return this.modeStack.pop(),this.parseValue();case"array-value":{if(this.modeStack.pop(),this.ch()===93)return this._pos++,this.skipWhitespace(),new y(h.break,void 0,1);if(this.ch()!==44)throw new Error(`${_} unexpected character at position ${this._pos}, was expecting array delimiter but found '${String.fromCharCode(this.ch())}'`);return this._pos++,this.modeStack.push("array-value"),this.skipWhitespace(),this.parseValue()}case"array-start":return this.modeStack.pop(),this.ch()===93?(this._pos++,this.skipWhitespace(),new y(h.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(h.break,void 0,1);if(this.ch()!==44)throw new Error(`${_} unexpected character at position ${this._pos}, was expecting object delimiter but found '${String.fromCharCode(this.ch())}'`);this._pos++,this.skipWhitespace();case"obj-start":{if(this.modeStack.pop(),this.ch()===125)return this._pos++,this.skipWhitespace(),new y(h.break,void 0,1);let e=this.parseString();if(this.skipWhitespace(),this.ch()!==58)throw new Error(`${_} unexpected character at position ${this._pos}, was expecting key/value delimiter ':' but found '${String.fromCharCode(this.ch())}'`);return this._pos++,this.modeStack.push("obj-value"),e}case"obj-value":return this.modeStack.pop(),this.modeStack.push("obj-key"),this.skipWhitespace(),this.parseValue();default:throw new Error(`${_} unexpected parse state at position ${this._pos}; this shouldn't happen`)}}};function Ri(r,e){return e=Object.assign({tokenizer:new At(r,e)},e),dr(r,e)}function ql(r){return r instanceof ArrayBuffer?new Uint8Array(r,0,r.byteLength):r}var Mi=class extends At{constructor(e,t){super(e,t),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(h.equals(e.type,h.map)){let t=this._next();if(h.equals(t.type,h.string)&&t.value==="/"){let n=this._next();if(h.equals(n.type,h.string)){let i=this._next();if(!h.equals(i.type,h.break))throw new Error("Invalid encoded CID form");return this.tokenBuffer.push(n),new y(h.tag,42,0)}if(h.equals(n.type,h.map)){let i=this._next();if(h.equals(i.type,h.string)&&i.value==="bytes"){let o=this._next();if(h.equals(o.type,h.string)){for(let a=0;a<2;a++){let c=this._next();if(!h.equals(c.type,h.break))throw new Error("Invalid encoded Bytes form")}let s=Kt.decode(`m${o.value}`);return new y(h.bytes,s,o.value.length)}this.tokenBuffer.push(o)}this.tokenBuffer.push(i)}this.tokenBuffer.push(n)}this.tokenBuffer.push(t)}return e}},Oi={allowIndefinite:!1,allowUndefined:!1,allowNaN:!1,allowInfinity:!1,allowBigInt:!0,strict:!0,useMaps:!1,rejectDuplicateMapKeys:!0,tags:[]};Oi.tags[42]=E.parse;var pn=297;var yn=r=>{let e=ql(r),t=Object.assign(Oi,{tokenizer:new Mi(e,Oi)});return Ri(e,t)};var Ig=new TextDecoder;var Cg=new TextEncoder;function Gl(r){return r[Symbol.asyncIterator]!=null}function Wl(r){if(Gl(r))return(async()=>{let n=new Uint8Array(0);for await(let i of r)n=Ce([n,i],n.length+i.length);return n})();let e=[],t=0;for(let n of r)e.push(n),t+=n.byteLength;return Ce(e,t)}var B=Wl;function Tt(r){return r==null?!1:E.asCID(r)===r}function Dt(r,e){let t,n=0,i="";for(;n<e.length;){let o=e[n];if(n++,!Object.hasOwnProperty.call(r,o))throw new kt(`Object did not have key "${o}"`);if(i+=`/${o}`,t=r[o],r=t,Tt(t))break}return{value:t,rest:e.slice(n),path:i.substring(1)}}async function*Vi(r,e,t,n){let i=await B(t.get(r,n)),o=dn(i),s=Dt(o,e);yield{cid:Tt(s.value)?s.value:r,name:s.path,rest:s.rest}}async function*Ga(r,e,t,n){let i=await B(t.get(r,n)),o=yn(i),s=Dt(o,e);yield{cid:Tt(s.value)?s.value:r,name:s.path,rest:s.rest}}var Jl=async function(r){return(await nt.encode(r)).slice(0,8).reverse()},Kl=async(r,e,t)=>{let n=(e.tableSize()-1).toString(16).length;await Promise.all(r.map(async i=>{if(i.Name==null)throw new Error("Unexpected Link without a Name");if(i.Name.length===n){let o=parseInt(i.Name,16);e._putObjectAt(o,new oe({hash:t._options.hash,bits:t._options.bits},e,o));return}await t.put(i.Name.substring(2),!0)}))},Wa=(r,e)=>r.toString(16).toUpperCase().padStart(e,"0").substring(0,e),Xl=r=>{let e=r.bucket,t=[];for(;e._parent!=null;)t.push(e),e=e._parent;return t.push(e),t.reverse()};async function*Hi(r,e,t,n,i,o){if(i==null){if(r.Data==null)throw new T("No data in PBNode");let d;try{d=S.unmarshal(r.Data)}catch(m){throw new T(m.message)}if(d.type!=="hamt-sharded-directory")throw new T("Not a HAMT");if(d.fanout==null)throw new T("Missing fanout");let p=St({hashFn:Jl,bits:Math.log2(Number(d.fanout))});i={rootBucket:p,hamtDepth:1,lastBucket:p}}let s=(i.lastBucket.tableSize()-1).toString(16).length;await Kl(r.Links,i.lastBucket,i.rootBucket);let a=await i.rootBucket._findNewBucketAndPos(e),c=Wa(a.pos,s),f=Xl(a);f.length>i.hamtDepth&&(i.lastBucket=f[i.hamtDepth],c=Wa(i.lastBucket._posAtParent,s));let u=r.Links.find(d=>{if(d.Name==null)return!1;let p=d.Name.substring(0,s),m=d.Name.substring(s);return!(p!==c||m!==""&&m!==e)});if(u==null)return;if(u.Name!=null&&u.Name.substring(s)===e){yield{cid:u.Hash,name:u.Name.substring(s),rest:t};return}i.hamtDepth++;let l=await B(n.get(u.Hash,o));r=D(l),o?.yieldSubShards===!0&&(yield{cid:u.Hash,name:u.Name??"",rest:[e,...t]}),yield*Hi(r,e,t,n,i,o)}async function*Ja(r,e,t,n){let i=await B(t.get(r,n)),o;try{o=D(i)}catch(a){throw new T(a.message)}if(o.Data==null)throw new T("no data in PBNode");let s;try{s=S.unmarshal(o.Data)}catch(a){throw new T(a.message)}if(s.type==="directory"||s.type==="hamt-sharded-directory"&&n?.translateHamtPath===!1){let a=o.Links.find(c=>c.Name===e[0]);if(a==null)throw new se(`No link "${e[0]}" found under ${r}`);yield{cid:a.Hash,name:e[0],rest:e.slice(1)}}else if(s.type==="hamt-sharded-directory"){let a=!1;for await(let c of Hi(o,e[0],e.slice(1),t,void 0,n))c.name===e[0]&&(a=!0),yield c;if(!a)throw new se(`No link "${e[0]}" found under ${r}`)}}async function*Ka(r,e,t,n){if(e.length!==0)throw new kt(`Cannot load path /${e.join("/")} from identity block`)}async function*Xa(r,e,t,n){let i=await B(t.get(r,n)),o=Pr(i),s=Dt(o,e);yield{cid:r,name:s.path,rest:s.rest}}async function*Ya(r,e,t,n){if(e.length!==0)throw new se(`Cannot load path /${e.join("/")} from raw block`)}var Zl={[H]:Ja,[W]:Ya,[hn]:Vi,81:Vi,[pn]:Ga,[Yt.code]:Ka,[zr]:Xa};async function*wn(r,e,t={}){for(r=r.toString(),r.startsWith("/ipfs/")&&(r=r.substring(6));r.endsWith("/");)r=r.substring(0,r.length-1);let[n,...i]=r.split(/(?<!\\)\//g).filter(Boolean),o=E.parse(n),s=[o],a=`${o}`;for(yield{cid:o,name:a,path:a,roots:s,remainder:i};i.length>0;){let c=Zl[o.code];if(c==null)throw new Et(`No resolver for code ${o.code}`);let f=!1;for await(let u of c(o,i,e,t)){if(o=u.cid,f=!s[s.length-1].equals(o),i=u.rest,!f)break;s=[...s,u.cid],a=`${a}/${u.name}`,yield{cid:u.cid,name:u.name,path:a,roots:s,remainder:u.rest}}if(!f)break}if(t?.signal?.throwIfAborted(),i.length!==0)throw new se(`Could not resolve path /${i.join("/")} under ${r}`)}async function ji(r,e,t,n,i){let o=await B(n.get(r,i)),s=dn(o);return{type:"object",cid:r,name:e,path:t,object:s,node:o}}async function Za(r,e,t,n,i){let o=await B(n.get(r,i)),s=yn(o);return{type:"object",cid:r,name:e,path:t,object:s,node:o}}function mr(r,e,t,n){let i=BigInt(r.length),o=BigInt(e+i);return t>=o||n<e?new Uint8Array(0):(n>=e&&n<o&&(r=r.subarray(0,Number(n-e))),t>=e&&t<o&&(r=r.subarray(Number(t-e))),r)}var xn=(r,e=0,t=r)=>{let n=BigInt(r),i=BigInt(e??0),o=BigInt(t);if(o!==n&&(o=i+o),o>n&&(o=n),i<0n)throw new Pe("Offset must be greater than or equal to 0");if(i>n)throw new Pe("Offset must be less than the file size");if(o<0n)throw new Pe("Length must be greater than or equal to 0");if(o>n)throw new Pe("Length must be less than the file size");return{start:i,end:o}};function bn(r,e){async function*t(n={}){let{start:i,end:o}=xn(r.length,n.offset,n.length),s=mr(r,0n,i,o);n.onProgress?.(new V(e,{bytesRead:BigInt(s.byteLength),totalBytes:o-i,fileSize:BigInt(r.byteLength)})),yield s}return t}async function Qa(r,e,t,n,i){let o=Ir(r.multihash.bytes);return{type:"identity",cid:r,name:e,path:t,content:bn(o.digest,"unixfs:exporter:progress:identity"),size:BigInt(o.bytes.length),node:o.bytes}}async function ec(r,e,t,n,i){let o=await B(n.get(r,i)),s=Pr(o);return{type:"object",cid:r,name:e,path:t,object:s,node:o}}async function tc(r,e,t,n,i){let o=await B(n.get(r,i));return{type:"raw",cid:r,name:e,path:t,content:bn(o,"unixfs:exporter:progress:raw"),size:BigInt(o.length),node:o}}function rc(r,e,t,n){async function*i(o={}){let s=o.offset??0,a=o.length??e.Links.length,c=e.Links.slice(s,a);o.onProgress?.(new V("unixfs:exporter:walk:directory",{cid:r})),yield*c.map(f=>({cid:f.Hash,name:f.Name??"",path:`${n}/${f.Name??""}`}))}return i}function Ql(r){let[e,t]=r[Symbol.asyncIterator]!=null?[r[Symbol.asyncIterator](),Symbol.asyncIterator]:[r[Symbol.iterator](),Symbol.iterator],n=[];return{peek:()=>e.next(),push:i=>{n.push(i)},next:()=>n.length>0?{done:!1,value:n.shift()}:e.next(),[t](){return this}}}var nc=Ql;function eh(r){return r[Symbol.asyncIterator]!=null}function th(r,e){let t=0;if(eh(r))return(async function*(){for await(let c of r)yield e(c,t++)})();let n=nc(r),{value:i,done:o}=n.next();if(o===!0)return(function*(){})();let s=e(i,t++);if(typeof s.then=="function")return(async function*(){yield await s;for(let c of n)yield e(c,t++)})();let a=e;return(function*(){yield s;for(let c of n)yield a(c,t++)})()}var Lt=th;function ee(){let r={};return r.promise=new Promise((e,t)=>{r.resolve=e,r.reject=t}),r}var _n=globalThis.CustomEvent??Event;async function*pr(r,e={}){let t=e.concurrency??1/0;t<1&&(t=1/0);let n=e.ordered??!1,i=new EventTarget,o=[],s=ee(),a=ee(),c=!1,f,u=!1;i.addEventListener("task-complete",()=>{a.resolve()}),Promise.resolve().then(async()=>{try{for await(let m of r){if(o.length===t&&(s=ee(),await s.promise),u)break;let w={done:!1};o.push(w),m().then(g=>{w.done=!0,w.ok=!0,w.value=g,i.dispatchEvent(new _n("task-complete"))},g=>{w.done=!0,w.err=g,i.dispatchEvent(new _n("task-complete"))})}c=!0,i.dispatchEvent(new _n("task-complete"))}catch(m){f=m,i.dispatchEvent(new _n("task-complete"))}});function l(){return n?o[0]?.done:!!o.find(m=>m.done)}function*d(){for(;o.length>0&&o[0].done;){let m=o[0];if(o.shift(),m.ok)yield m.value;else throw u=!0,s.resolve(),m.err;s.resolve()}}function*p(){for(;l();)for(let m=0;m<o.length;m++)if(o[m].done){let w=o[m];if(o.splice(m,1),m--,w.ok)yield w.value;else throw u=!0,s.resolve(),w.err;s.resolve()}}for(;;){if(l()||(a=ee(),await a.promise),f!=null||(n?yield*d():yield*p(),f!=null))throw f;if(c&&o.length===0)break}}var Sn=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}},Ft=class{size;hwm;head;tail;constructor(e={}){this.hwm=e.splitLimit??16,this.head=new Sn(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 t=this.head;this.head=t.next=new Sn(2*this.head.buffer.length),this.head.push(e)}}shift(){let e=this.tail.shift();if(e===void 0&&this.tail.next!=null){let t=this.tail.next;this.tail.next=null,this.tail=t,e=this.tail.shift()}return e?.value!=null&&(this.size-=this.calculateSize(e.value)),e}isEmpty(){return this.head.isEmpty()}};var qi=class extends Error{type;code;constructor(e,t){super(e??"The operation was aborted"),this.type="aborted",this.code=t??"ABORT_ERR"}};function kn(r={}){return rh(t=>{let n=t.shift();if(n==null)return{done:!0};if(n.error!=null)throw n.error;return{done:n.done===!0,value:n.value}},r)}function rh(r,e){e=e??{};let t=e.onEnd,n=new Ft,i,o,s,a=ee(),c=async()=>{try{return n.isEmpty()?s?{done:!0}:await new Promise((g,b)=>{o=k=>{o=null,n.push(k);try{g(r(n))}catch(v){b(v)}return i}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=ee()})}},f=g=>o!=null?o(g):(n.push(g),i),u=g=>(n=new Ft,o!=null?o({error:g}):(n.push({error:g}),i)),l=g=>{if(s)return i;if(e?.objectMode!==!0&&g?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return f({done:!1,value:g})},d=g=>s?i:(s=!0,g!=null?u(g):f({done:!0})),p=()=>(n=new Ft,d(),{done:!0}),m=g=>(d(g),{done:!0});if(i={[Symbol.asyncIterator](){return this},next:c,return:p,throw:m,push:l,end:d,get readableLength(){return n.size},onEmpty:async g=>{let b=g?.signal;if(b?.throwIfAborted(),n.isEmpty())return;let k,v;b!=null&&(k=new Promise((U,O)=>{v=()=>{O(new qi)},b.addEventListener("abort",v)}));try{await Promise.race([a.promise,k])}finally{v!=null&&b!=null&&b?.removeEventListener("abort",v)}}},t==null)return i;let w=i;return i={[Symbol.asyncIterator](){return this},next(){return w.next()},throw(g){return w.throw(g),t!=null&&(t(g),t=void 0),{done:!0}},return(){return w.return(),t!=null&&(t(),t=void 0),{done:!0}},push:l,end(g){return w.end(g),t!=null&&(t(g),t=void 0),i},get readableLength(){return w.readableLength},onEmpty:g=>w.onEmpty(g)},i}function nh(r){return r.reason}async function ic(r,e,t){if(e==null)return r;let n=t?.translateError??nh;if(e.aborted)return r.catch(()=>{}),Promise.reject(n(e));let i;try{return await Promise.race([r,new Promise((o,s)=>{i=()=>{s(n(e))},e.addEventListener("abort",i)})])}finally{i!=null&&e.removeEventListener("abort",i)}}var Gi=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,t){await this._push(e,t)}async end(e,t){e!=null?await this.throw(e):await this._push(void 0,t)}async _push(e,t){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 ic(this.readNext.promise,t?.signal,t)}};function oc(){return new Gi}function ih(r){return r[Symbol.asyncIterator]!=null}async function oh(r,e,t){try{await Promise.all(r.map(async n=>{for await(let i of n)await e.push(i,{signal:t}),t.throwIfAborted()})),await e.end(void 0,{signal:t})}catch(n){await e.end(n,{signal:t}).catch(()=>{})}}async function*sh(r){let e=new AbortController,t=oc();oh(r,t,e.signal).catch(()=>{});try{yield*t}finally{e.abort()}}function*ah(r){for(let e of r)yield*e}function ch(...r){let e=[];for(let t of r)ih(t)||e.push(t);return e.length===r.length?ah(e):sh(r)}var sc=ch;function Ke(r,...e){if(r==null)throw new Error("Empty pipeline");if(Wi(r)){let n=r;r=()=>n.source}else if(cc(r)||ac(r)){let n=r;r=()=>n}let t=[r,...e];if(t.length>1&&Wi(t[t.length-1])&&(t[t.length-1]=t[t.length-1].sink),t.length>2)for(let n=1;n<t.length-1;n++)Wi(t[n])&&(t[n]=fh(t[n]));return uh(...t)}var uh=(...r)=>{let e;for(;r.length>0;)e=r.shift()(e);return e},ac=r=>r?.[Symbol.asyncIterator]!=null,cc=r=>r?.[Symbol.iterator]!=null,Wi=r=>r==null?!1:r.sink!=null&&r.source!=null,fh=r=>e=>{let t=r.sink(e);if(t?.then!=null){let n=kn({objectMode:!0});t.then(()=>{n.end()},s=>{n.end(s)});let i,o=r.source;if(ac(o))i=async function*(){yield*o,n.end()};else if(cc(o))i=function*(){yield*o,n.end()};else throw new Error("Unknown duplex source type - must be Iterable or AsyncIterable");return sc(n,i())}return r.source};var Ki=vr(fc(),1);var Xi=class r extends Error{name="TimeoutError";constructor(e,t){super(e,t),Error.captureStackTrace?.(this,r)}},lc=r=>r.reason??new DOMException("This operation was aborted.","AbortError");function Yi(r,e){let{milliseconds:t,fallback:n,message:i,customTimers:o={setTimeout,clearTimeout},signal:s}=e,a,c,u=new Promise((l,d)=>{if(typeof t!="number"||Math.sign(t)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${t}\``);if(s?.aborted){d(lc(s));return}if(s&&(c=()=>{d(lc(s))},s.addEventListener("abort",c,{once:!0})),r.then(l,d),t===Number.POSITIVE_INFINITY)return;let p=new Xi;a=o.setTimeout.call(void 0,()=>{if(n){try{l(n())}catch(m){d(m)}return}typeof r.cancel=="function"&&r.cancel(),i===!1?l():i instanceof Error?d(i):(p.message=i??`Promise timed out after ${t} milliseconds`,d(p))},t)}).finally(()=>{u.clear(),c&&s&&s.removeEventListener("abort",c)});return u.clear=()=>{o.clearTimeout.call(void 0,a),a=void 0},u}function Zi(r,e,t){let n=0,i=r.length;for(;i>0;){let o=Math.trunc(i/2),s=n+o;t(r[s],e)<=0?(n=++s,i-=o+1):i=o}return n}var gr=class{#e=[];enqueue(e,t){let{priority:n=0,id:i}=t??{},o={priority:n,id:i,run:e};if(this.size===0||this.#e[this.size-1].priority>=n){this.#e.push(o);return}let s=Zi(this.#e,o,(a,c)=>c.priority-a.priority);this.#e.splice(s,0,o)}setPriority(e,t){let n=this.#e.findIndex(o=>o.id===e);if(n===-1)throw new ReferenceError(`No promise function with the id "${e}" exists in the queue.`);let[i]=this.#e.splice(n,1);this.enqueue(i.run,{priority:t,id:e})}dequeue(){return this.#e.shift()?.run}filter(e){return this.#e.filter(t=>t.priority===e.priority).map(t=>t.run)}get size(){return this.#e.length}};var wr=class extends Ki.default{#e;#r;#i=0;#c;#u=!1;#h=!1;#f;#B=0;#x=0;#l;#d;#a;#s=[];#o=0;#t;#I;#n=0;#g;#m;#D=1n;#w=new Map;timeout;constructor(e){if(super(),e={carryoverIntervalCount:!1,intervalCap:Number.POSITIVE_INFINITY,interval:0,concurrency:Number.POSITIVE_INFINITY,autoStart:!0,queueClass:gr,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.#r=e.intervalCap===Number.POSITIVE_INFINITY||e.interval===0,this.#c=e.intervalCap,this.#f=e.interval,this.#a=e.strict,this.#t=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.#m=e.autoStart===!1,this.#M()}#b(e){for(;this.#o<this.#s.length;){let n=this.#s[this.#o];if(n!==void 0&&e-n>=this.#f)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)}#L(e){this.#a?this.#s.push(e):this.#i++}#F(){this.#a?this.#s.length>this.#o&&this.#s.pop():this.#i>0&&this.#i--}#_(){return this.#s.length-this.#o}get#z(){return this.#r?!0:this.#a?this.#_()<this.#c:this.#i<this.#c}get#P(){return this.#n<this.#g}#U(){this.#n--,this.#n===0&&this.emit("pendingZero"),this.#E(),this.emit("next")}#$(){this.#d=void 0,this.#A(),this.#N()}#R(e){if(this.#a){if(this.#b(e),this.#_()>=this.#c){let n=this.#s[this.#o],i=this.#f-(e-n);return this.#S(i),!0}return!1}if(this.#l===void 0){let t=this.#B-e;if(t<0){if(this.#x>0){let n=e-this.#x;if(n<this.#f)return this.#S(this.#f-n),!0}this.#i=this.#e?this.#n:0}else return this.#S(t),!0}return!1}#S(e){this.#d===void 0&&(this.#d=setTimeout(()=>{this.#$()},e))}#k(){this.#l&&(clearInterval(this.#l),this.#l=void 0)}#C(){this.#d&&(clearTimeout(this.#d),this.#d=void 0)}#E(){if(this.#t.size===0){if(this.#k(),this.emit("empty"),this.#n===0){if(this.#C(),this.#a&&this.#o>0){let t=Date.now();this.#b(t)}this.emit("idle")}return!1}let e=!1;if(!this.#m){let t=Date.now(),n=!this.#R(t);if(this.#z&&this.#P){let i=this.#t.dequeue();this.#r||(this.#L(t),this.#y()),this.emit("active"),i(),n&&this.#N(),e=!0}}return e}#N(){this.#r||this.#l!==void 0||this.#a||(this.#l=setInterval(()=>{this.#A()},this.#f),this.#B=Date.now()+this.#f)}#A(){this.#a||(this.#i===0&&this.#n===0&&this.#l&&this.#k(),this.#i=this.#e?this.#n:0),this.#v(),this.#y()}#v(){for(;this.#E(););}get concurrency(){return this.#g}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.#g=e,this.#v()}setPriority(e,t){if(typeof t!="number"||!Number.isFinite(t))throw new TypeError(`Expected \`priority\` to be a finite number, got \`${t}\` (${typeof t})`);this.#t.setPriority(e,t)}async add(e,t={}){return t={timeout:this.timeout,...t,id:t.id??(this.#D++).toString()},new Promise((n,i)=>{let o=Symbol(`task-${t.id}`);this.#t.enqueue(async()=>{this.#n++,this.#w.set(o,{id:t.id,priority:t.priority??0,startTime:Date.now(),timeout:t.timeout});let s;try{try{t.signal?.throwIfAborted()}catch(f){throw this.#O(),this.#w.delete(o),f}this.#x=Date.now();let a=e({signal:t.signal});if(t.timeout&&(a=Yi(Promise.resolve(a),{milliseconds:t.timeout,message:`Task timed out after ${t.timeout}ms (queue has ${this.#n} running, ${this.#t.size} waiting)`})),t.signal){let{signal:f}=t;a=Promise.race([a,new Promise((u,l)=>{s=()=>{l(f.reason)},f.addEventListener("abort",s,{once:!0})})])}let c=await a;n(c),this.emit("completed",c)}catch(a){i(a),this.emit("error",a)}finally{s&&t.signal?.removeEventListener("abort",s),this.#w.delete(o),queueMicrotask(()=>{this.#U()})}},t),this.emit("add"),this.#E()})}async addAll(e,t){return Promise.all(e.map(async n=>this.add(n,t)))}start(){return this.#m?(this.#m=!1,this.#v(),this):this}pause(){this.#m=!0}clear(){this.#t=new this.#I,this.#k(),this.#T(),this.emit("empty"),this.#n===0&&(this.#C(),this.emit("idle")),this.emit("next")}async onEmpty(){this.#t.size!==0&&await this.#p("empty")}async onSizeLessThan(e){this.#t.size<e||await this.#p("next",()=>this.#t.size<e)}async onIdle(){this.#n===0&&this.#t.size===0||await this.#p("idle")}async onPendingZero(){this.#n!==0&&await this.#p("pendingZero")}async onRateLimit(){this.isRateLimited||await this.#p("rateLimit")}async onRateLimitCleared(){this.isRateLimited&&await this.#p("rateLimitCleared")}onError(){return new Promise((e,t)=>{let n=i=>{this.off("error",n),t(i)};this.on("error",n)})}async#p(e,t){return new Promise(n=>{let i=()=>{t&&!t()||(this.off(e,i),n())};this.on(e,i)})}get size(){return this.#t.size}sizeBy(e){return this.#t.filter(e).length}get pending(){return this.#n}get isPaused(){return this.#m}#M(){this.#r||(this.on("add",()=>{this.#t.size>0&&this.#y()}),this.on("next",()=>{this.#y()}))}#y(){this.#r||this.#h||(this.#h=!0,queueMicrotask(()=>{this.#h=!1,this.#T()}))}#O(){this.#r||(this.#F(),this.#y())}#T(){let e=this.#u;if(this.#r||this.#t.size===0){e&&(this.#u=!1,this.emit("rateLimitCleared"));return}let t;if(this.#a){let i=Date.now();this.#b(i),t=this.#_()}else t=this.#i;let n=t>=this.#c;n!==e&&(this.#u=n,this.emit(n?"rateLimit":"rateLimitCleared"))}get isRateLimited(){return this.#u}get isSaturated(){return this.#n===this.#g&&this.#t.size>0||this.isRateLimited&&this.#t.size>0}get runningTasks(){return[...this.#w.values()].map(e=>({...e}))}};async function hc(r,e,t,n,i,o,s){if(e instanceof Uint8Array){let f=mr(e,n,i,o);t.push(f);return}if(e.Data==null)throw new T("no data in PBNode");let a;try{a=S.unmarshal(e.Data)}catch(f){throw new T(f.message)}if(a.data!=null){let f=a.data,u=mr(f,n,i,o);t.push(u),n+=BigInt(u.byteLength)}let c=[];if(e.Links.length!==a.blockSizes.length)throw new T("Inconsistent block sizes and dag links");for(let f=0;f<e.Links.length;f++){let u=e.Links[f],l=n,d=l+a.blockSizes[f];if((i>=l&&i<d||o>=l&&o<=d||i<l&&o>d)&&c.push({link:u,blockStart:n}),n=d,n>o)break}await Ke(c,f=>Lt(f,u=>async()=>{let l=await B(r.get(u.link.Hash,s));return{...u,block:l}}),f=>pr(f,{ordered:!0,concurrency:s.blockReadConcurrency}),async f=>{for await(let{link:u,block:l,blockStart:d}of f){let p;switch(u.Hash.code){case H:p=D(l);break;case W:p=l;break;default:t.end(new T(`Unsupported codec: ${u.Hash.code}`));return}let m=new wr({concurrency:1});m.on("error",w=>{t.end(w)}),m.add(async()=>{s.onProgress?.(new V("unixfs:exporter:walk:file",{cid:u.Hash})),await hc(r,p,t,d,i,o,s)}),await m.onIdle()}}),n>=o&&t.end()}function Qi(r,e,t,n,i){async function*o(s={}){let a=t.fileSize();if(a===void 0)throw new Error("File was a directory");let{start:c,end:f}=xn(a,s.offset,s.length);if(f===0n)return;let u=0n,l=f-c,d=kn();s.onProgress?.(new V("unixfs:exporter:walk:file",{cid:r})),hc(i,e,d,0n,c,f,s).catch(p=>{d.end(p)});for await(let p of d)if(p!=null){if(u+=BigInt(p.byteLength),u>l)throw d.end(),new Jr("Read too many bytes - the file size reported by the UnixFS data in the root node may be incorrect");u===l&&d.end(),s.onProgress?.(new V("unixfs:exporter:progress:unixfs:file",{bytesRead:u,totalBytes:l,fileSize:a})),yield p}if(u<l)throw new Kr("Traversed entire DAG but did not read enough bytes")}return o}async function*dc(r,e,t,n){let i=r.Links;if(r.Data==null)throw new T("no data in PBNode");let o;try{o=S.unmarshal(r.Data)}catch(c){throw new T(c.message)}if(o.fanout==null)throw new T("missing fanout");let s=(o.fanout-1n).toString(16).length,a=Ke(i,c=>Lt(c,f=>async()=>{let u=f.Name!=null?f.Name.substring(s):null;if(u!=null&&u!=="")return{entries:[{cid:f.Hash,name:u,path:`${e}/${u}`}]};{let l=await B(t.get(f.Hash,n));return r=D(l),n.onProgress?.(new V("unixfs:exporter:walk:hamt-sharded-directory",{cid:f.Hash})),{entries:dc(r,e,t,n)}}}),c=>pr(c,{ordered:!0,concurrency:n.blockReadConcurrency}));for await(let{entries:c}of a)yield*c}function mc(r,e,t,n,i){function o(s={}){return s.onProgress?.(new V("unixfs:exporter:walk:hamt-sharded-directory",{cid:r})),dc(e,n,i,s)}return o}var dh={raw:Qi,file:Qi,directory:rc,"hamt-sharded-directory":mc,metadata:(r,e,t,n)=>()=>[],symlink:(r,e,t,n)=>()=>[]};async function pc(r,e,t,n,i){let o=await B(n.get(r,i)),s;try{s=D(o)}catch(f){throw new T(f.message)}if(s.Data==null)throw new T("no data in PBNode");let a;try{a=S.unmarshal(s.Data)}catch(f){throw new T(f.message)}let c=dh[a.type](r,s,a,t,n);if(c==null)throw new se("could not find content exporter");return a.isDirectory()?{type:"directory",cid:r,name:e,path:t,entries:c,unixfs:a,node:s}:{type:"file",cid:r,name:e,path:t,content:c,unixfs:a,node:s,size:a.fileSize()}}var mh={[H]:pc,[W]:tc,[hn]:ji,81:ji,[pn]:Za,[Yt.code]:Qa,[zr]:ec};async function R(r,e,t={}){let n,i;if(r instanceof String||typeof r=="string"){let s=await Se(wn(r,e,t));if(s==null)throw new se(`Could not walk path to ${r}`);n=s.cid,i=s.name,r=s.path}else if(E.asCID(r)===r||r instanceof E)n=r,i=r=n.toString();else throw new Pe("Path must be string or CID");let o=mh[n.code];if(o==null)throw new Et(`No resolver for code ${n.code}`);return o(n,i,r,e,t)}async function*vn(r,e,t={}){let n=await R(r,e,t);if(n==null)return;if(yield{cid:n.cid,name:n.name,path:n.path,depth:0},n.type==="directory")for await(let o of i(n,0,`${r}`,t))yield o;async function*i(o,s,a,c){s++;for await(let f of o.entries(c)){let u=`${a}/${f.name}`;yield{...f,depth:s,path:u};let l=await R(f.cid,e,c);l.type==="directory"&&(yield*i(l,s,u,c))}}}function ph(r,e){if(typeof r=="string")return yh(r);if(typeof r=="number")return xh(r,e);throw Error(`Value provided to ms() must be a string or number. value=${JSON.stringify(r)}`)}var Bn=ph;function yh(r){if(typeof r!="string"||r.length===0||r.length>100)throw Error(`Value provided to ms.parse() must be a string with length between 1 and 99. value=${JSON.stringify(r)}`);let e=/^(?<value>-?\d*\.?\d+) *(?<unit>milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|months?|mo|years?|yrs?|y)?$/i.exec(r);if(!e?.groups)return NaN;let{value:t,unit:n="ms"}=e.groups,i=parseFloat(t),o=n.toLowerCase();switch(o){case"years":case"year":case"yrs":case"yr":case"y":return i*315576e5;case"months":case"month":case"mo":return i*26298e5;case"weeks":case"week":case"w":return i*6048e5;case"days":case"day":case"d":return i*864e5;case"hours":case"hour":case"hrs":case"hr":case"h":return i*36e5;case"minutes":case"minute":case"mins":case"min":case"m":return i*6e4;case"seconds":case"second":case"secs":case"sec":case"s":return i*1e3;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return i;default:throw Error(`Unknown unit "${o}" provided to ms.parse(). value=${JSON.stringify(r)}`)}}function gh(r){let e=Math.abs(r);return e>=315576e5?`${Math.round(r/315576e5)}y`:e>=26298e5?`${Math.round(r/26298e5)}mo`:e>=6048e5?`${Math.round(r/6048e5)}w`:e>=864e5?`${Math.round(r/864e5)}d`:e>=36e5?`${Math.round(r/36e5)}h`:e>=6e4?`${Math.round(r/6e4)}m`:e>=1e3?`${Math.round(r/1e3)}s`:`${r}ms`}function wh(r){let e=Math.abs(r);return e>=315576e5?ct(r,e,315576e5,"year"):e>=26298e5?ct(r,e,26298e5,"month"):e>=6048e5?ct(r,e,6048e5,"week"):e>=864e5?ct(r,e,864e5,"day"):e>=36e5?ct(r,e,36e5,"hour"):e>=6e4?ct(r,e,6e4,"minute"):e>=1e3?ct(r,e,1e3,"second"):`${r} ms`}function xh(r,e){if(typeof r!="number"||!Number.isFinite(r))throw Error("Value provided to ms.format() must be of type number.");return e?.long?wh(r):gh(r)}function ct(r,e,t,n){let i=e>=t*1.5;return`${Math.round(r/t)} ${n}${i?"s":""}`}function eo(r){t.debug=t,t.default=t,t.coerce=c,t.disable=o,t.enable=i,t.enabled=s,t.humanize=Bn,t.destroy=f,Object.keys(r).forEach(u=>{t[u]=r[u]}),t.names=[],t.skips=[],t.formatters={};function e(u){let l=0;for(let d=0;d<u.length;d++)l=(l<<5)-l+u.charCodeAt(d),l|=0;return t.colors[Math.abs(l)%t.colors.length]}t.selectColor=e;function t(u,l){let d,p=null,m,w;function g(...b){if(!g.enabled)return;let k=g,v=Number(new Date),U=v-(d||v);k.diff=U,k.prev=d,k.curr=v,d=v,b[0]=t.coerce(b[0]),typeof b[0]!="string"&&b.unshift("%O");let O=0;b[0]=b[0].replace(/%([a-zA-Z%])/g,(K,pe)=>{if(K==="%%")return"%";O++;let Ye=t.formatters[pe];if(typeof Ye=="function"){let Hc=b[O];K=Ye.call(k,Hc),b.splice(O,1),O--}return K}),t.formatArgs.call(k,b),l?.onLog!=null&&l.onLog(...b),(k.log||t.log).apply(k,b)}return g.namespace=u,g.useColors=t.useColors(),g.color=t.selectColor(u),g.extend=n,g.destroy=t.destroy,Object.defineProperty(g,"enabled",{enumerable:!0,configurable:!1,get:()=>p!==null?p:(m!==t.namespaces&&(m=t.namespaces,w=t.enabled(u)),w),set:b=>{p=b}}),typeof t.init=="function"&&t.init(g),g}function n(u,l){let d=t(this.namespace+(typeof l>"u"?":":l)+u);return d.log=this.log,d}function i(u){t.save(u),t.namespaces=u,t.names=[],t.skips=[];let l,d=(typeof u=="string"?u:"").split(/[\s,]+/),p=d.length;for(l=0;l<p;l++)d[l]&&(u=d[l].replace(/\*/g,".*?"),u[0]==="-"?t.skips.push(new RegExp("^"+u.substr(1)+"$")):t.names.push(new RegExp("^"+u+"$")))}function o(){let u=[...t.names.map(a),...t.skips.map(a).map(l=>"-"+l)].join(",");return t.enable(""),u}function s(u){if(u[u.length-1]==="*")return!0;let l,d;for(l=0,d=t.skips.length;l<d;l++)if(t.skips[l].test(u))return!1;for(l=0,d=t.names.length;l<d;l++)if(t.names[l].test(u))return!0;return!1}function a(u){return u.toString().substring(2,u.toString().length-2).replace(/\.\*\?$/,"*")}function c(u){return u instanceof Error?u.stack??u.message:u}function f(){console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.")}return t.setupFormatters(t.formatters),t.enable(t.load()),t}var In=Bh(),bh=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"];function _h(){return typeof window<"u"&&window.process&&(window.process.type==="renderer"||window.process.__nwjs)?!0:typeof navigator<"u"&&navigator.userAgent?.toLowerCase().match(/(edge|trident)\/(\d+)/)!=null?!1:typeof document<"u"&&document.documentElement?.style?.WebkitAppearance||typeof window<"u"&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||typeof navigator<"u"&&navigator.userAgent?.toLowerCase().match(/firefox\/(\d+)/)!=null&&parseInt(RegExp.$1,10)>=31||typeof navigator<"u"&&navigator.userAgent?.toLowerCase().match(/applewebkit\/(\d+)/)}function Sh(r){if(r[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+r[0]+(this.useColors?"%c ":" ")+"+"+Bn(this.diff),!this.useColors)return;let e="color: "+this.color;r.splice(1,0,e,"color: inherit");let t=0,n=0;r[0].replace(/%[a-zA-Z%]/g,i=>{i!=="%%"&&(t++,i==="%c"&&(n=t))}),r.splice(n,0,e)}var kh=console.debug??console.log??(()=>{});function Eh(r){try{r?In?.setItem("debug",r):In?.removeItem("debug")}catch{}}function vh(){let r;try{r=In?.getItem("debug")}catch{}return!r&&typeof globalThis.process<"u"&&"env"in globalThis.process&&(r=globalThis.process.env.DEBUG),r}function Bh(){try{return localStorage}catch{}}function Ih(r){r.j=function(e){try{return JSON.stringify(e)}catch(t){return"[UnexpectedJSONParseError]: "+t.message}}}var yc=eo({formatArgs:Sh,save:Eh,load:vh,useColors:_h,setupFormatters:Ih,colors:bh,storage:In,log:kh});var te=yc;te.formatters.b=r=>r==null?"undefined":le.baseEncode(r);te.formatters.t=r=>r==null?"undefined":Me.baseEncode(r);te.formatters.m=r=>r==null?"undefined":Kt.baseEncode(r);te.formatters.p=r=>r==null?"undefined":r.toString();te.formatters.c=r=>r==null?"undefined":r.toString();te.formatters.k=r=>r==null?"undefined":r.toString();te.formatters.a=r=>r==null?"undefined":r.toString();function gc(r,e=""){let t=wc(r.message),n=wc(r.stack);return t!=null&&n!=null?n.includes(t)?`${n.split(`
2
+ "use strict";var HeliaMfs=(()=>{var ul=Object.create;var nn=Object.defineProperty;var fl=Object.getOwnPropertyDescriptor;var ll=Object.getOwnPropertyNames;var dl=Object.getPrototypeOf,hl=Object.prototype.hasOwnProperty;var ws=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),ne=(t,e)=>{for(var r in e)nn(t,r,{get:e[r],enumerable:!0})},xs=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of ll(e))!hl.call(t,i)&&i!==r&&nn(t,i,{get:()=>e[i],enumerable:!(n=fl(e,i))||n.enumerable});return t};var on=(t,e,r)=>(r=t!=null?ul(dl(t)):{},xs(e||!t||!t.__esModule?nn(r,"default",{value:t,enumerable:!0}):r,t)),ml=t=>xs(nn({},"__esModule",{value:!0}),t);var vn=ws((fw,Ra)=>{"use strict";Ra.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 i=!1;n===-1?(n=this._data.length,this._setBit(e),this._changedData=!0):i=!0,this._setInternalPos(n,e,r,i),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,i=r;for(;n<this.length;){let o=this.get(n);i=e(i,o,n),n++}return i}find(e){let r=0,n,i;for(;r<this.length&&!n;)i=this.get(r),n=e(i),r++;return n?i:void 0}_internalPositionFor(e,r){let n=this._bytePosFor(e,r);if(n>=this._bitArrays.length)return-1;let i=this._bitArrays[n],o=e-n*7;if(!((i&1<<o)>0))return-1;let a=this._bitArrays.slice(0,n).reduce(hh,0),c=~(4294967295<<o+1),f=Pa(i&c);return a+f-1}_bytePosFor(e,r){let n=Math.floor(e/7),i=n+1;for(;!r&&this._bitArrays.length<i;)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,i){let o=this._data,s=[r,n];if(i)this._sortData(),o[e]=s;else{if(o.length)if(o[o.length-1][0]>=r)o.push(s);else if(o[0][0]<=r)o.unshift(s);else{let a=Math.round(o.length/2);this._data=o.slice(0,a).concat(s).concat(o.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(mh),this._changedData=!1}bitField(){let e=[],r=8,n=0,i=0,o,s=this._bitArrays.slice();for(;s.length||n;){n===0&&(o=s.shift(),n=7);let c=Math.min(n,r),f=~(255<<c),u=o&f;i|=u<<8-r,o=o>>>c,n-=c,r-=c,(!r||!n&&!s.length)&&(e.push(i),i=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(ph)}};function hh(t,e){return t+Pa(e)}function Pa(t){let e=t;return e=e-(e>>1&1431655765),e=(e&858993459)+(e>>2&858993459),(e+(e>>4)&252645135)*16843009>>24}function mh(t,e){return t[0]-e[0]}function ph(t){return t[1]}});var Tf=ws((CE,ss)=>{"use strict";var op=Object.prototype.hasOwnProperty,oe="~";function Yr(){}Object.create&&(Yr.prototype=Object.create(null),new Yr().__proto__||(oe=!1));function sp(t,e,r){this.fn=t,this.context=e,this.once=r||!1}function Af(t,e,r,n,i){if(typeof r!="function")throw new TypeError("The listener must be a function");var o=new sp(r,n||t,i),s=oe?oe+e:e;return t._events[s]?t._events[s].fn?t._events[s]=[t._events[s],o]:t._events[s].push(o):(t._events[s]=o,t._eventsCount++),t}function bi(t,e){--t._eventsCount===0?t._events=new Yr:delete t._events[e]}function re(){this._events=new Yr,this._eventsCount=0}re.prototype.eventNames=function(){var e=[],r,n;if(this._eventsCount===0)return e;for(n in r=this._events)op.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 i=0,o=n.length,s=new Array(o);i<o;i++)s[i]=n[i].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,i,o,s){var a=oe?oe+e:e;if(!this._events[a])return!1;var c=this._events[a],f=arguments.length,u,d;if(c.fn){switch(c.once&&this.removeListener(e,c.fn,void 0,!0),f){case 1:return c.fn.call(c.context),!0;case 2:return c.fn.call(c.context,r),!0;case 3:return c.fn.call(c.context,r,n),!0;case 4:return c.fn.call(c.context,r,n,i),!0;case 5:return c.fn.call(c.context,r,n,i,o),!0;case 6:return c.fn.call(c.context,r,n,i,o,s),!0}for(d=1,u=new Array(f-1);d<f;d++)u[d-1]=arguments[d];c.fn.apply(c.context,u)}else{var m=c.length,y;for(d=0;d<m;d++)switch(c[d].once&&this.removeListener(e,c[d].fn,void 0,!0),f){case 1:c[d].fn.call(c[d].context);break;case 2:c[d].fn.call(c[d].context,r);break;case 3:c[d].fn.call(c[d].context,r,n);break;case 4:c[d].fn.call(c[d].context,r,n,i);break;default:if(!u)for(y=1,u=new Array(f-1);y<f;y++)u[y-1]=arguments[y];c[d].fn.apply(c[d].context,u)}}return!0};re.prototype.on=function(e,r,n){return Af(this,e,r,n,!1)};re.prototype.once=function(e,r,n){return Af(this,e,r,n,!0)};re.prototype.removeListener=function(e,r,n,i){var o=oe?oe+e:e;if(!this._events[o])return this;if(!r)return bi(this,o),this;var s=this._events[o];if(s.fn)s.fn===r&&(!i||s.once)&&(!n||s.context===n)&&bi(this,o);else{for(var a=0,c=[],f=s.length;a<f;a++)(s[a].fn!==r||i&&!s[a].once||n&&s[a].context!==n)&&c.push(s[a]);c.length?this._events[o]=c.length===1?c[0]:c:bi(this,o)}return this};re.prototype.removeAllListeners=function(e){var r;return e?(r=oe?oe+e:e,this._events[r]&&bi(this,r)):(this._events=new Yr,this._eventsCount=0),this};re.prototype.off=re.prototype.removeListener;re.prototype.addListener=re.prototype.on;re.prefixed=oe;re.EventEmitter=re;typeof ss<"u"&&(ss.exports=re)});var ny={};ne(ny,{mfs:()=>ry});var Hi={};ne(Hi,{base32:()=>st,base32hex:()=>kl,base32hexpad:()=>Il,base32hexpadupper:()=>vl,base32hexupper:()=>Bl,base32pad:()=>El,base32padupper:()=>Sl,base32upper:()=>_l,base32z:()=>Al});var oy=new Uint8Array(0);function bs(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 Ne(t){if(t instanceof Uint8Array&&t.constructor.name==="Uint8Array")return t;if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.isView(t))return new Uint8Array(t.buffer,t.byteOffset,t.byteLength);throw new Error("Unknown type, must be binary type")}function _s(t){return new TextEncoder().encode(t)}function Es(t){return new TextDecoder().decode(t)}function pl(t,e){if(t.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),n=0;n<r.length;n++)r[n]=255;for(var i=0;i<t.length;i++){var o=t.charAt(i),s=o.charCodeAt(0);if(r[s]!==255)throw new TypeError(o+" is ambiguous");r[s]=i}var a=t.length,c=t.charAt(0),f=Math.log(a)/Math.log(256),u=Math.log(256)/Math.log(a);function d(p){if(p instanceof Uint8Array||(ArrayBuffer.isView(p)?p=new Uint8Array(p.buffer,p.byteOffset,p.byteLength):Array.isArray(p)&&(p=Uint8Array.from(p))),!(p instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(p.length===0)return"";for(var w=0,x=0,k=0,v=p.length;k!==v&&p[k]===0;)k++,w++;for(var N=(v-k)*u+1>>>0,F=new Uint8Array(N);k!==v;){for(var H=p[k],ue=0,J=N-1;(H!==0||ue<x)&&J!==-1;J--,ue++)H+=256*F[J]>>>0,F[J]=H%a>>>0,H=H/a>>>0;if(H!==0)throw new Error("Non-zero carry");x=ue,k++}for(var Te=N-x;Te!==N&&F[Te]===0;)Te++;for(var St=c.repeat(w);Te<N;++Te)St+=t.charAt(F[Te]);return St}function m(p){if(typeof p!="string")throw new TypeError("Expected String");if(p.length===0)return new Uint8Array;var w=0;if(p[w]!==" "){for(var x=0,k=0;p[w]===c;)x++,w++;for(var v=(p.length-w)*f+1>>>0,N=new Uint8Array(v);p[w];){var F=r[p.charCodeAt(w)];if(F===255)return;for(var H=0,ue=v-1;(F!==0||H<k)&&ue!==-1;ue--,H++)F+=a*N[ue]>>>0,N[ue]=F%256>>>0,F=F/256>>>0;if(F!==0)throw new Error("Non-zero carry");k=H,w++}if(p[w]!==" "){for(var J=v-k;J!==v&&N[J]===0;)J++;for(var Te=new Uint8Array(x+(v-J)),St=x;J!==v;)Te[St++]=N[J++];return Te}}}function y(p){var w=m(p);if(w)return w;throw new Error(`Non-${e} character`)}return{encode:d,decodeUnsafe:m,decode:y}}var yl=pl,gl=yl,ks=gl;var Ri=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")}},$i=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,r,n){this.name=e,this.prefix=r;let i=r.codePointAt(0);if(i===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=i,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 Bs(this,e)}},Mi=class{decoders;constructor(e){this.decoders=e}or(e){return Bs(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 Bs(t,e){return new Mi({...t.decoders??{[t.prefix]:t},...e.decoders??{[e.prefix]:e}})}var Oi=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,r,n,i){this.name=e,this.prefix=r,this.baseEncode=n,this.baseDecode=i,this.encoder=new Ri(e,r,n),this.decoder=new $i(e,r,i)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function Rt({name:t,prefix:e,encode:r,decode:n}){return new Oi(t,e,r,n)}function ot({name:t,prefix:e,alphabet:r}){let{encode:n,decode:i}=ks(r,t);return Rt({prefix:e,name:t,encode:n,decode:o=>Ne(i(o))})}function wl(t,e,r,n){let i=t.length;for(;t[i-1]==="=";)--i;let o=new Uint8Array(i*r/8|0),s=0,a=0,c=0;for(let f=0;f<i;++f){let u=e[t[f]];if(u===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|u,s+=r,s>=8&&(s-=8,o[c++]=255&a>>s)}if(s>=r||(255&a<<8-s)!==0)throw new SyntaxError("Unexpected end of data");return o}function xl(t,e,r){let n=e[e.length-1]==="=",i=(1<<r)-1,o="",s=0,a=0;for(let c=0;c<t.length;++c)for(a=a<<8|t[c],s+=8;s>r;)s-=r,o+=e[i&a>>s];if(s!==0&&(o+=e[i&a<<r-s]),n)for(;(o.length*r&7)!==0;)o+="=";return o}function bl(t){let e={};for(let r=0;r<t.length;++r)e[t[r]]=r;return e}function M({name:t,prefix:e,bitsPerChar:r,alphabet:n}){let i=bl(n);return Rt({prefix:e,name:t,encode(o){return xl(o,n,r)},decode(o){return wl(o,i,r,t)}})}var st=M({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),_l=M({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),El=M({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Sl=M({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),kl=M({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Bl=M({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Il=M({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),vl=M({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Al=M({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Vi={};ne(Vi,{base36:()=>mr,base36upper:()=>Tl});var mr=ot({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Tl=ot({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var ji={};ne(ji,{base58btc:()=>Ee,base58flickr:()=>Nl});var Ee=ot({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Nl=ot({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Cl=As,Is=128,Dl=127,Ll=~Dl,Ul=Math.pow(2,31);function As(t,e,r){e=e||[],r=r||0;for(var n=r;t>=Ul;)e[r++]=t&255|Is,t/=128;for(;t&Ll;)e[r++]=t&255|Is,t>>>=7;return e[r]=t|0,As.bytes=r-n+1,e}var Fl=qi,zl=128,vs=127;function qi(t,n){var r=0,n=n||0,i=0,o=n,s,a=t.length;do{if(o>=a)throw qi.bytes=0,new RangeError("Could not decode varint");s=t[o++],r+=i<28?(s&vs)<<i:(s&vs)*Math.pow(2,i),i+=7}while(s>=zl);return qi.bytes=o-n,r}var Pl=Math.pow(2,7),Rl=Math.pow(2,14),$l=Math.pow(2,21),Ml=Math.pow(2,28),Ol=Math.pow(2,35),Hl=Math.pow(2,42),Vl=Math.pow(2,49),jl=Math.pow(2,56),ql=Math.pow(2,63),Gl=function(t){return t<Pl?1:t<Rl?2:t<$l?3:t<Ml?4:t<Ol?5:t<Hl?6:t<Vl?7:t<jl?8:t<ql?9:10},Wl={encode:Cl,decode:Fl,encodingLength:Gl},Kl=Wl,pr=Kl;function yr(t,e=0){return[pr.decode(t,e),pr.decode.bytes]}function $t(t,e,r=0){return pr.encode(t,e,r),e}function Mt(t){return pr.encodingLength(t)}function Ht(t,e){let r=e.byteLength,n=Mt(t),i=n+Mt(r),o=new Uint8Array(i+r);return $t(t,o,0),$t(r,o,n),o.set(e,i),new Ot(t,r,e,o)}function an(t){let e=Ne(t),[r,n]=yr(e),[i,o]=yr(e.subarray(n)),s=e.subarray(n+o);if(s.byteLength!==i)throw new Error("Incorrect length");return new Ot(r,i,s,e)}function Ts(t,e){if(t===e)return!0;{let r=e;return t.code===r.code&&t.size===r.size&&r.bytes instanceof Uint8Array&&bs(t.bytes,r.bytes)}}var Ot=class{code;size;digest;bytes;constructor(e,r,n,i){this.code=e,this.size=r,this.digest=n,this.bytes=i}};function Ns(t,e){let{bytes:r,version:n}=t;switch(n){case 0:return Xl(r,Gi(t),e??Ee.encoder);default:return Yl(r,Gi(t),e??st.encoder)}}var Cs=new WeakMap;function Gi(t){let e=Cs.get(t);if(e==null){let r=new Map;return Cs.set(t,r),r}return e}var A=class t{code;version;multihash;bytes;"/";constructor(e,r,n,i){this.code=r,this.version=e,this.multihash=n,this.bytes=i,this["/"]=i}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!==gr)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==Zl)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=Ht(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&&Ts(e.multihash,n.multihash)}toString(e){return Ns(this,e)}toJSON(){return{"/":Ns(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:i,multihash:o,bytes:s}=r;return new t(n,i,o,s??Ds(n,i,o.bytes))}else if(r[Ql]===!0){let{version:n,multihash:i,code:o}=r,s=an(i);return t.create(n,o,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!==gr)throw new Error(`Version 0 CID must use dag-pb (code: ${gr}) block encoding`);return new t(e,r,n,n.bytes)}case 1:{let i=Ds(e,r,n.bytes);return new t(e,r,n,i)}default:throw new Error("Invalid version")}}static createV0(e){return t.create(0,gr,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,i=Ne(e.subarray(n,n+r.multihashSize));if(i.byteLength!==r.multihashSize)throw new Error("Incorrect length");let o=i.subarray(r.multihashSize-r.digestSize),s=new Ot(r.multihashCode,r.digestSize,o,i);return[r.version===0?t.createV0(s):t.createV1(r.codec,s),e.subarray(r.size)]}static inspectBytes(e){let r=0,n=()=>{let[d,m]=yr(e.subarray(r));return r+=m,d},i=n(),o=gr;if(i===18?(i=0,r=0):o=n(),i!==0&&i!==1)throw new RangeError(`Invalid CID version ${i}`);let s=r,a=n(),c=n(),f=r+c,u=f-s;return{version:i,codec:o,multihashCode:a,digestSize:c,multihashSize:u,size:f}}static parse(e,r){let[n,i]=Jl(e,r),o=t.decode(i);if(o.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Gi(o).set(n,e),o}};function Jl(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 st.prefix:{let r=e??st;return[st.prefix,r.decode(t)]}case mr.prefix:{let r=e??mr;return[mr.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 Xl(t,e,r){let{prefix:n}=r;if(n!==Ee.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let i=e.get(n);if(i==null){let o=r.encode(t).slice(1);return e.set(n,o),o}else return i}function Yl(t,e,r){let{prefix:n}=r,i=e.get(n);if(i==null){let o=r.encode(t);return e.set(n,o),o}else return i}var gr=112,Zl=18;function Ds(t,e,r){let n=Mt(t),i=n+Mt(e),o=new Uint8Array(i+r.byteLength);return $t(t,o,0),$t(e,o,n),o.set(r,i),o}var Ql=Symbol.for("@ipld/js-cid/CID");function ed(t){return t[Symbol.asyncIterator]!=null}function td(t){if(ed(t))return(async()=>{for await(let e of t)return e})();for(let e of t)return e}var cn=td;function rd(t){return t[Symbol.asyncIterator]!=null}function nd(t,e=1){return e=Number(e),rd(t)?(async function*(){let r=[];if(e<1&&(e=1),e!==Math.round(e))throw new Error("Batch size must be an integer");for await(let n of t)for(r.push(n);r.length>=e;)yield r.slice(0,e),r=r.slice(e);for(;r.length>0;)yield r.slice(0,e),r=r.slice(e)})():(function*(){let r=[];if(e<1&&(e=1),e!==Math.round(e))throw new Error("Batch size must be an integer");for(let n of t)for(r.push(n);r.length>=e;)yield r.slice(0,e),r=r.slice(e);for(;r.length>0;)yield r.slice(0,e),r=r.slice(e)})()}var un=nd;async function*wr(t,e=1){for await(let r of un(t,e)){let n=r.map(async i=>i().then(o=>({ok:!0,value:o}),o=>({ok:!1,err:o})));for(let i=0;i<n.length;i++){let o=await n[i];if(o.ok)yield o.value;else throw o.err}}}function Ce(t=0){return new Uint8Array(t)}function fe(t=0){return new Uint8Array(t)}function Ve(t,e){e==null&&(e=t.reduce((i,o)=>i+o.length,0));let r=fe(e),n=0;for(let i of t)r.set(i,n),n+=i.length;return r}function fn(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}var Us=Symbol.for("@achingbrain/uint8arraylist");function Ls(t,e){if(e==null||e<0)throw new RangeError("index is out of bounds");let r=0;for(let n of t){let i=r+n.byteLength;if(e<i)return{buf:n,index:e-r};r=i}throw new RangeError("index is out of bounds")}function ln(t){return!!t?.[Us]}var jt=class t{bufs;length;[Us]=!0;constructor(...e){this.bufs=[],this.length=0,e.length>0&&this.appendAll(e)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...e){this.appendAll(e)}appendAll(e){let r=0;for(let n of e)if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.push(n);else if(ln(n))r+=n.byteLength,this.bufs.push(...n.bufs);else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}prepend(...e){this.prependAll(e)}prependAll(e){let r=0;for(let n of e.reverse())if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.unshift(n);else if(ln(n))r+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}get(e){let r=Ls(this.bufs,e);return r.buf[r.index]}set(e,r){let n=Ls(this.bufs,e);n.buf[n.index]=r}write(e,r=0){if(e instanceof Uint8Array)for(let n=0;n<e.length;n++)this.set(r+n,e[n]);else if(ln(e))for(let n=0;n<e.length;n++)this.set(r+n,e.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(e){if(e=Math.trunc(e),!(Number.isNaN(e)||e<=0)){if(e===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(e>=this.bufs[0].byteLength)e-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(e),this.length-=e;break}}}slice(e,r){let{bufs:n,length:i}=this._subList(e,r);return Ve(n,i)}subarray(e,r){let{bufs:n,length:i}=this._subList(e,r);return n.length===1?n[0]:Ve(n,i)}sublist(e,r){let{bufs:n,length:i}=this._subList(e,r),o=new t;return o.length=i,o.bufs=[...n],o}_subList(e,r){if(e=e??0,r=r??this.length,e<0&&(e=this.length+e),r<0&&(r=this.length+r),e<0||r>this.length)throw new RangeError("index is out of bounds");if(e===r)return{bufs:[],length:0};if(e===0&&r===this.length)return{bufs:this.bufs,length:this.length};let n=[],i=0;for(let o=0;o<this.bufs.length;o++){let s=this.bufs[o],a=i,c=a+s.byteLength;if(i=c,e>=c)continue;let f=e>=a&&e<c,u=r>a&&r<=c;if(f&&u){if(e===a&&r===c){n.push(s);break}let d=e-a;n.push(s.subarray(d,d+(r-e)));break}if(f){if(e===0){n.push(s);continue}n.push(s.subarray(e-a));continue}if(u){if(r===c){n.push(s);break}n.push(s.subarray(0,r-a));break}n.push(s)}return{bufs:n,length:r-e}}indexOf(e,r=0){if(!ln(e)&&!(e instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=e instanceof Uint8Array?e:e.subarray();if(r=Number(r??0),isNaN(r)&&(r=0),r<0&&(r=this.length+r),r<0&&(r=0),e.length===0)return r>this.length?this.length:r;let i=n.byteLength;if(i===0)throw new TypeError("search must be at least 1 byte long");let o=256,s=new Int32Array(o);for(let d=0;d<o;d++)s[d]=-1;for(let d=0;d<i;d++)s[n[d]]=d;let a=s,c=this.byteLength-n.byteLength,f=n.byteLength-1,u;for(let d=r;d<=c;d+=u){u=0;for(let m=f;m>=0;m--){let y=this.get(d+m);if(n[m]!==y){u=Math.max(1,m-a[y]);break}}if(u===0)return d}return-1}getInt8(e){let r=this.subarray(e,e+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getInt8(0)}setInt8(e,r){let n=fe(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,r),this.write(n,e)}getInt16(e,r){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,r)}setInt16(e,r,n){let i=Ce(2);new DataView(i.buffer,i.byteOffset,i.byteLength).setInt16(0,r,n),this.write(i,e)}getInt32(e,r){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,r)}setInt32(e,r,n){let i=Ce(4);new DataView(i.buffer,i.byteOffset,i.byteLength).setInt32(0,r,n),this.write(i,e)}getBigInt64(e,r){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,r)}setBigInt64(e,r,n){let i=Ce(8);new DataView(i.buffer,i.byteOffset,i.byteLength).setBigInt64(0,r,n),this.write(i,e)}getUint8(e){let r=this.subarray(e,e+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getUint8(0)}setUint8(e,r){let n=fe(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,r),this.write(n,e)}getUint16(e,r){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,r)}setUint16(e,r,n){let i=Ce(2);new DataView(i.buffer,i.byteOffset,i.byteLength).setUint16(0,r,n),this.write(i,e)}getUint32(e,r){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,r)}setUint32(e,r,n){let i=Ce(4);new DataView(i.buffer,i.byteOffset,i.byteLength).setUint32(0,r,n),this.write(i,e)}getBigUint64(e,r){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,r)}setBigUint64(e,r,n){let i=Ce(8);new DataView(i.buffer,i.byteOffset,i.byteLength).setBigUint64(0,r,n),this.write(i,e)}getFloat32(e,r){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,r)}setFloat32(e,r,n){let i=Ce(4);new DataView(i.buffer,i.byteOffset,i.byteLength).setFloat32(0,r,n),this.write(i,e)}getFloat64(e,r){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,r)}setFloat64(e,r,n){let i=Ce(8);new DataView(i.buffer,i.byteOffset,i.byteLength).setFloat64(0,r,n),this.write(i,e)}equals(e){if(e==null||!(e instanceof t)||e.bufs.length!==this.bufs.length)return!1;for(let r=0;r<this.bufs.length;r++)if(!fn(this.bufs[r],e.bufs[r]))return!1;return!0}static fromUint8Arrays(e,r){let n=new t;return n.bufs=e,r==null&&(r=e.reduce((i,o)=>i+o.byteLength,0)),n.length=r,n}};var Wi=BigInt(34),dn=8,hn=262144,Fs="links-bytes",mn=262144,zs=1048576,Ps=50,Rs=10,$s=!0,Ms=!0,Os=!1,Hs="file";var xr=(t={})=>{let e=t.chunkSize??mn;return async function*(n){let i=new jt,o=0,s=!1;for await(let a of n)for(i.append(a),o+=a.length;o>=e;)if(yield i.subarray(0,e),s=!0,e===i.length)i=new jt,o=0;else{let f=new jt;f.append(i.sublist(e)),i=f,o-=e}(!s||o>0)&&(yield i.subarray(0,o))}};var V={};ne(V,{code:()=>W,createLink:()=>Zs,createNode:()=>Ys,decode:()=>z,encode:()=>C,name:()=>md,prepare:()=>G,validate:()=>Xi});var id=new TextDecoder;function Ki(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 i=t[e++];if(r+=n<28?(i&127)<<n:(i&127)*2**n,i<128)break}return[r,e]}function pn(t,e){let r;[r,e]=Ki(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 Vs(t,e){let r;return[r,e]=Ki(t,e),[r&7,r>>3,e]}function od(t){let e={},r=t.length,n=0;for(;n<r;){let i,o;if([i,o,n]=Vs(t,n),o===1){if(e.Hash)throw new Error("protobuf: (PBLink) duplicate Hash section");if(i!==2)throw new Error(`protobuf: (PBLink) wrong wireType (${i}) 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]=pn(t,n)}else if(o===2){if(e.Name!==void 0)throw new Error("protobuf: (PBLink) duplicate Name section");if(i!==2)throw new Error(`protobuf: (PBLink) wrong wireType (${i}) for Name`);if(e.Tsize!==void 0)throw new Error("protobuf: (PBLink) invalid order, found Tsize before Name");let s;[s,n]=pn(t,n),e.Name=id.decode(s)}else if(o===3){if(e.Tsize!==void 0)throw new Error("protobuf: (PBLink) duplicate Tsize section");if(i!==0)throw new Error(`protobuf: (PBLink) wrong wireType (${i}) for Tsize`);[e.Tsize,n]=Ki(t,n)}else throw new Error(`protobuf: (PBLink) invalid fieldNumber, expected 1, 2 or 3, got ${o}`)}if(n>r)throw new Error("protobuf: (PBLink) unexpected end of data");return e}function js(t){let e=t.length,r=0,n,i=!1,o;for(;r<e;){let a,c;if([a,c,r]=Vs(t,r),a!==2)throw new Error(`protobuf: (PBNode) invalid wireType, expected 2, got ${a}`);if(c===1){if(o)throw new Error("protobuf: (PBNode) duplicate Data section");[o,r]=pn(t,r),n&&(i=!0)}else if(c===2){if(i)throw new Error("protobuf: (PBNode) duplicate Links section");n||(n=[]);let f;[f,r]=pn(t,r),n.push(od(f))}else throw new Error(`protobuf: (PBNode) invalid fieldNumber, expected 1 or 2, got ${c}`)}if(r>e)throw new Error("protobuf: (PBNode) unexpected end of data");let s={};return o&&(s.Data=o),s.Links=n||[],s}var Gs=new TextEncoder,qs=2**32,sd=2**31;function ad(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=br(e,r,t.Tsize)-1,e[r]=24}if(typeof t.Name=="string"){let n=Gs.encode(t.Name);r-=n.length,e.set(n,r),r=br(e,r,n.length)-1,e[r]=18}return t.Hash&&(r-=t.Hash.length,e.set(t.Hash,r),r=br(e,r,t.Hash.length)-1,e[r]=10),e.length-r}function Ws(t){let e=ud(t),r=new Uint8Array(e),n=e;if(t.Data&&(n-=t.Data.length,r.set(t.Data,n),n=br(r,n,t.Data.length)-1,r[n]=10),t.Links)for(let i=t.Links.length-1;i>=0;i--){let o=ad(t.Links[i],r.subarray(0,n));n-=o,n=br(r,n,o)-1,r[n]=18}return r}function cd(t){let e=0;if(t.Hash){let r=t.Hash.length;e+=1+r+qt(r)}if(typeof t.Name=="string"){let r=Gs.encode(t.Name).length;e+=1+r+qt(r)}return typeof t.Tsize=="number"&&(e+=1+qt(t.Tsize)),e}function ud(t){let e=0;if(t.Data){let r=t.Data.length;e+=1+r+qt(r)}if(t.Links)for(let r of t.Links){let n=cd(r);e+=1+n+qt(n)}return e}function br(t,e,r){e-=qt(r);let n=e;for(;r>=sd;)t[e++]=r&127|128,r/=128;for(;r>=128;)t[e++]=r&127|128,r>>>=7;return t[e]=r,n}function qt(t){return t%2===0&&t++,Math.floor((fd(t)+6)/7)}function fd(t){let e=0;return t>=qs&&(t=Math.floor(t/qs),e=32),t>=65536&&(t>>>=16,e+=16),t>=256&&(t>>>=8,e+=8),e+ld[t]}var ld=[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 dd=["Data","Links"],hd=["Hash","Name","Tsize"],Ji=new TextEncoder;function Js(t,e){if(t===e)return 0;let r=t.Name?Ji.encode(t.Name):[],n=e.Name?Ji.encode(e.Name):[],i=r.length,o=n.length;for(let s=0,a=Math.min(i,o);s<a;++s)if(r[s]!==n[s]){i=r[s],o=n[s];break}return i<o?-1:o<i?1:0}function Ks(t,e){return!Object.keys(t).some(r=>!e.includes(r))}function Xs(t){if(typeof t.asCID=="object"){let r=A.asCID(t);if(!r)throw new TypeError("Invalid DAG-PB form");return{Hash:r}}if(typeof t!="object"||Array.isArray(t))throw new TypeError("Invalid DAG-PB form");let e={};if(t.Hash){let r=A.asCID(t.Hash);try{r||(typeof t.Hash=="string"?r=A.parse(t.Hash):t.Hash instanceof Uint8Array&&(r=A.decode(t.Hash)))}catch(n){throw new TypeError(`Invalid DAG-PB form: ${n.message}`)}r&&(e.Hash=r)}if(!e.Hash)throw new TypeError("Invalid DAG-PB form");return typeof t.Name=="string"&&(e.Name=t.Name),typeof t.Tsize=="number"&&(e.Tsize=t.Tsize),e}function G(t){if((t instanceof Uint8Array||typeof t=="string")&&(t={Data:t}),typeof t!="object"||Array.isArray(t))throw new TypeError("Invalid DAG-PB form");let e={};if(t.Data!==void 0)if(typeof t.Data=="string")e.Data=Ji.encode(t.Data);else if(t.Data instanceof Uint8Array)e.Data=t.Data;else throw new TypeError("Invalid DAG-PB form");if(t.Links!==void 0)if(Array.isArray(t.Links))e.Links=t.Links.map(Xs),e.Links.sort(Js);else throw new TypeError("Invalid DAG-PB form");else e.Links=[];return e}function Xi(t){if(!t||typeof t!="object"||Array.isArray(t)||t instanceof Uint8Array||t["/"]&&t["/"]===t.bytes)throw new TypeError("Invalid DAG-PB form");if(!Ks(t,dd))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(!Ks(r,hd))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&&Js(r,t.Links[e-1])===-1)throw new TypeError("Invalid DAG-PB form (links must be sorted by Name bytes)")}}function Ys(t,e=[]){return G({Data:t,Links:e})}function Zs(t,e,r){return Xs({Hash:r,Name:t,Tsize:e})}function Qs(t){return t instanceof ArrayBuffer?new Uint8Array(t,0,t.byteLength):t}var md="dag-pb",W=112;function C(t){Xi(t);let e={};return t.Links&&(e.Links=t.Links.map(r=>{let n={};return r.Hash&&(n.Hash=r.Hash.bytes),r.Name!==void 0&&(n.Name=r.Name),r.Tsize!==void 0&&(n.Tsize=r.Tsize),n})),t.Data&&(e.Data=t.Data),Ws(e)}function z(t){let e=Qs(t),r=js(e),n={};return r.Data&&(n.Data=r.Data),r.Links&&(n.Links=r.Links.map(i=>{let o={};try{o.Hash=A.decode(i.Hash)}catch{}if(!o.Hash)throw new Error("Invalid Hash field found in link, expected CID");return i.Name!==void 0&&(o.Name=i.Name),i.Tsize!==void 0&&(o.Tsize=i.Tsize),o})),n}var _r=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 pd=Math.pow(2,7),yd=Math.pow(2,14),gd=Math.pow(2,21),ea=Math.pow(2,28),ta=Math.pow(2,35),ra=Math.pow(2,42),na=Math.pow(2,49),ie=128,at=127;function Er(t){if(t<pd)return 1;if(t<yd)return 2;if(t<gd)return 3;if(t<ea)return 4;if(t<ta)return 5;if(t<ra)return 6;if(t<na)return 7;if(Number.MAX_SAFE_INTEGER!=null&&t>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function ia(t,e,r=0){switch(Er(t)){case 8:e[r++]=t&255|ie,t/=128;case 7:e[r++]=t&255|ie,t/=128;case 6:e[r++]=t&255|ie,t/=128;case 5:e[r++]=t&255|ie,t/=128;case 4:e[r++]=t&255|ie,t>>>=7;case 3:e[r++]=t&255|ie,t>>>=7;case 2:e[r++]=t&255|ie,t>>>=7;case 1:{e[r++]=t&255,t>>>=7;break}default:throw new Error("unreachable")}return e}function oa(t,e){let r=t[e],n=0;if(n+=r&at,r<ie||(r=t[e+1],n+=(r&at)<<7,r<ie)||(r=t[e+2],n+=(r&at)<<14,r<ie)||(r=t[e+3],n+=(r&at)<<21,r<ie)||(r=t[e+4],n+=(r&at)*ea,r<ie)||(r=t[e+5],n+=(r&at)*ta,r<ie)||(r=t[e+6],n+=(r&at)*ra,r<ie)||(r=t[e+7],n+=(r&at)*na,r<ie))return n;throw new RangeError("Could not decode varint")}var Yi=new Float32Array([-0]),ct=new Uint8Array(Yi.buffer);function sa(t,e,r){Yi[0]=t,e[r]=ct[0],e[r+1]=ct[1],e[r+2]=ct[2],e[r+3]=ct[3]}function aa(t,e){return ct[0]=t[e],ct[1]=t[e+1],ct[2]=t[e+2],ct[3]=t[e+3],Yi[0]}var Zi=new Float64Array([-0]),ee=new Uint8Array(Zi.buffer);function ca(t,e,r){Zi[0]=t,e[r]=ee[0],e[r+1]=ee[1],e[r+2]=ee[2],e[r+3]=ee[3],e[r+4]=ee[4],e[r+5]=ee[5],e[r+6]=ee[6],e[r+7]=ee[7]}function ua(t,e){return ee[0]=t[e],ee[1]=t[e+1],ee[2]=t[e+2],ee[3]=t[e+3],ee[4]=t[e+4],ee[5]=t[e+5],ee[6]=t[e+6],ee[7]=t[e+7],Zi[0]}var wd=BigInt(Number.MAX_SAFE_INTEGER),xd=BigInt(Number.MIN_SAFE_INTEGER),le=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 kt;if(e<wd&&e>xd)return this.fromNumber(Number(e));let r=e<0n;r&&(e=-e);let n=e>>32n,i=e-(n<<32n);return r&&(n=~n|0n,i=~i|0n,++i>fa&&(i=0n,++n>fa&&(n=0n))),new t(Number(i),Number(n))}static fromNumber(e){if(e===0)return kt;let r=e<0;r&&(e=-e);let n=e>>>0,i=(e-n)/4294967296>>>0;return r&&(i=~i>>>0,n=~n>>>0,++n>4294967295&&(n=0,++i>4294967295&&(i=0))),new t(n,i)}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):kt}},kt=new le(0,0);kt.toBigInt=function(){return 0n};kt.zzEncode=kt.zzDecode=function(){return this};kt.length=function(){return 1};var fa=4294967296n;function la(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 da(t,e,r){if(r-e<1)return"";let i,o=[],s=0,a;for(;e<r;)a=t[e++],a<128?o[s++]=a:a>191&&a<224?o[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,o[s++]=55296+(a>>10),o[s++]=56320+(a&1023)):o[s++]=(a&15)<<12|(t[e++]&63)<<6|t[e++]&63,s>8191&&((i??(i=[])).push(String.fromCharCode.apply(String,o)),s=0);return i!=null?(s>0&&i.push(String.fromCharCode.apply(String,o.slice(0,s))),i.join("")):String.fromCharCode.apply(String,o.slice(0,s))}function Qi(t,e,r){let n=r,i,o;for(let s=0;s<t.length;++s)i=t.charCodeAt(s),i<128?e[r++]=i:i<2048?(e[r++]=i>>6|192,e[r++]=i&63|128):(i&64512)===55296&&((o=t.charCodeAt(s+1))&64512)===56320?(i=65536+((i&1023)<<10)+(o&1023),++s,e[r++]=i>>18|240,e[r++]=i>>12&63|128,e[r++]=i>>6&63|128,e[r++]=i&63|128):(e[r++]=i>>12|224,e[r++]=i>>6&63|128,e[r++]=i&63|128);return r-n}function De(t,e){return RangeError(`index out of range: ${t.pos} + ${e??1} > ${t.len}`)}function yn(t,e){return(t[e-4]|t[e-3]<<8|t[e-2]<<16|t[e-1]<<24)>>>0}var eo=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(e){this.buf=e,this.pos=0,this.len=e.length}uint32(){let e=4294967295;if(e=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(e=(e|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return e;if((this.pos+=5)>this.len)throw this.pos=this.len,De(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 De(this,4);return yn(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw De(this,4);return yn(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw De(this,4);let e=aa(this.buf,this.pos);return this.pos+=4,e}double(){if(this.pos+8>this.len)throw De(this,4);let e=ua(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 De(this,e);return this.pos+=e,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let e=this.bytes();return da(e,0,e.length)}skip(e){if(typeof e=="number"){if(this.pos+e>this.len)throw De(this,e);this.pos+=e}else do if(this.pos>=this.len)throw De(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 le(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 De(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 De(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 De(this,8);let e=yn(this.buf,this.pos+=4),r=yn(this.buf,this.pos+=4);return new le(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=oa(this.buf,this.pos);return this.pos+=Er(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 to(t){return new eo(t instanceof Uint8Array?t:t.subarray())}function Sr(t,e,r){let n=to(t);return e.decode(n,void 0,r)}var ro={};ne(ro,{base10:()=>bd});var bd=ot({prefix:"9",name:"base10",alphabet:"0123456789"});var no={};ne(no,{base16:()=>_d,base16upper:()=>Ed});var _d=M({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Ed=M({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var io={};ne(io,{base2:()=>Sd});var Sd=M({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var oo={};ne(oo,{base256emoji:()=>Ad});var ma=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}"),kd=ma.reduce((t,e,r)=>(t[r]=e,t),[]),Bd=ma.reduce((t,e,r)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return t[n]=r,t},[]);function Id(t){return t.reduce((e,r)=>(e+=kd[r],e),"")}function vd(t){let e=[];for(let r of t){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let i=Bd[n];if(i==null)throw new Error(`Non-base256emoji character: ${r}`);e.push(i)}return new Uint8Array(e)}var Ad=Rt({prefix:"\u{1F680}",name:"base256emoji",encode:Id,decode:vd});var so={};ne(so,{base64:()=>kr,base64pad:()=>Td,base64url:()=>Nd,base64urlpad:()=>Cd});var kr=M({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Td=M({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Nd=M({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Cd=M({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var ao={};ne(ao,{base8:()=>Dd});var Dd=M({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var co={};ne(co,{identity:()=>Ld});var Ld=Rt({prefix:"\0",name:"identity",encode:t=>Es(t),decode:t=>_s(t)});var mg=new TextEncoder,Ud=new TextDecoder;var gn=512;function wn(t){return JSON.parse(Ud.decode(t))}var Le={};ne(Le,{code:()=>te,decode:()=>Pd,encode:()=>zd,name:()=>Fd});var Fd="raw",te=85;function zd(t){return Ne(t)}function Pd(t){return Ne(t)}var uo={};ne(uo,{identity:()=>Ir});var pa=0,Rd="identity",ya=Ne;function $d(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 Ht(pa,ya(t))}var Ir={code:pa,name:Rd,encode:ya,digest:$d};var lo={};ne(lo,{sha256:()=>de,sha512:()=>Od});var Md=20;function Bt({name:t,code:e,encode:r,minDigestLength:n,maxDigestLength:i}){return new fo(t,e,r,n,i)}var fo=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,r,n,i,o){this.name=e,this.code=r,this.encode=n,this.minDigestLength=i??Md,this.maxDigestLength=o}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?ga(n,this.code,r?.truncate):n.then(i=>ga(i,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function ga(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 Ht(e,t)}function xa(t){return async e=>new Uint8Array(await crypto.subtle.digest(t,e))}var de=Bt({name:"sha2-256",code:18,encode:xa("SHA-256")}),Od=Bt({name:"sha2-512",code:19,encode:xa("SHA-512")});var ho={...co,...io,...ao,...ro,...no,...Hi,...Vi,...ji,...so,...oo},vg={...lo,...uo};function _a(t,e,r,n){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:r},decoder:{decode:n}}}var ba=_a("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),mo=_a("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=fe(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}),Hd={utf8:ba,"utf-8":ba,hex:ho.base16,latin1:mo,ascii:mo,binary:mo,...ho},xn=Hd;function O(t,e="utf8"){let r=xn[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.decoder.decode(`${r.prefix}${t}`)}function po(t){let e=t??8192,r=e>>>1,n,i=e;return function(s){if(s<1||s>r)return fe(s);i+s>e&&(n=fe(e),i=0);let a=n.subarray(i,i+=s);return(i&7)!==0&&(i=(i|7)+1),a}}var It=class{fn;len;next;val;constructor(e,r,n){this.fn=e,this.len=r,this.next=void 0,this.val=n}};function yo(){}var wo=class{head;tail;len;next;constructor(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}},Vd=po();function jd(t){return globalThis.Buffer!=null?fe(t):Vd(t)}var Ar=class{len;head;tail;states;constructor(){this.len=0,this.head=new It(yo,0,0),this.tail=this.head,this.states=null}_push(e,r,n){return this.tail=this.tail.next=new It(e,r,n),this.len+=r,this}uint32(e){return this.len+=(this.tail=this.tail.next=new xo((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(bn,10,le.fromNumber(e)):this.uint32(e)}sint32(e){return this.uint32((e<<1^e>>31)>>>0)}uint64(e){let r=le.fromBigInt(e);return this._push(bn,r.length(),r)}uint64Number(e){return this._push(ia,Er(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=le.fromBigInt(e).zzEncode();return this._push(bn,r.length(),r)}sint64Number(e){let r=le.fromNumber(e).zzEncode();return this._push(bn,r.length(),r)}sint64String(e){return this.sint64(BigInt(e))}bool(e){return this._push(go,1,e?1:0)}fixed32(e){return this._push(vr,4,e>>>0)}sfixed32(e){return this.fixed32(e)}fixed64(e){let r=le.fromBigInt(e);return this._push(vr,4,r.lo)._push(vr,4,r.hi)}fixed64Number(e){let r=le.fromNumber(e);return this._push(vr,4,r.lo)._push(vr,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(sa,4,e)}double(e){return this._push(ca,8,e)}bytes(e){let r=e.length>>>0;return r===0?this._push(go,1,0):this.uint32(r)._push(Gd,r,e)}string(e){let r=la(e);return r!==0?this.uint32(r)._push(Qi,r,e):this._push(go,1,0)}fork(){return this.states=new wo(this),this.head=this.tail=new It(yo,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 It(yo,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=jd(this.len),n=0;for(;e!=null;)e.fn(e.val,r,n),n+=e.len,e=e.next;return r}};function go(t,e,r){e[r]=t&255}function qd(t,e,r){for(;t>127;)e[r++]=t&127|128,t>>>=7;e[r]=t}var xo=class extends It{next;constructor(e,r){super(qd,e,r),this.next=void 0}};function bn(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 vr(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 Gd(t,e,r){e.set(t,r)}globalThis.Buffer!=null&&(Ar.prototype.bytes=function(t){let e=t.length>>>0;return this.uint32(e),e>0&&this._push(Wd,e,t),this},Ar.prototype.string=function(t){let e=globalThis.Buffer.byteLength(t);return this.uint32(e),e>0&&this._push(Kd,e,t),this});function Wd(t,e,r){e.set(t,r)}function Kd(t,e,r){t.length<40?Qi(t,e,r):e.utf8Write!=null?e.utf8Write(t,r):e.set(O(t),r)}function bo(){return new Ar}function Tr(t,e){let r=bo();return e.encode(t,r,{lengthDelimited:!1}),r.finish()}var Gt;(function(t){t[t.VARINT=0]="VARINT",t[t.BIT64=1]="BIT64",t[t.LENGTH_DELIMITED=2]="LENGTH_DELIMITED",t[t.START_GROUP=3]="START_GROUP",t[t.END_GROUP=4]="END_GROUP",t[t.BIT32=5]="BIT32"})(Gt||(Gt={}));function _n(t,e,r,n){return{name:t,type:e,encode:r,decode:n}}function _o(t){function e(i){if(t[i.toString()]==null)throw new Error("Invalid enum value");return t[i]}let r=function(o,s){let a=e(o);s.int32(a)},n=function(o){let s=o.int32();return e(s)};return _n("enum",Gt.VARINT,r,n)}function Nr(t,e){return _n("message",Gt.LENGTH_DELIMITED,t,e)}var Ue;(function(t){let e;(function(i){i.Raw="Raw",i.Directory="Directory",i.File="File",i.Metadata="Metadata",i.Symlink="Symlink",i.HAMTShard="HAMTShard"})(e=t.DataType||(t.DataType={}));let r;(function(i){i[i.Raw=0]="Raw",i[i.Directory=1]="Directory",i[i.File=2]="File",i[i.Metadata=3]="Metadata",i[i.Symlink=4]="Symlink",i[i.HAMTShard=5]="HAMTShard"})(r||(r={})),(function(i){i.codec=()=>_o(r)})(e=t.DataType||(t.DataType={}));let n;t.codec=()=>(n==null&&(n=Nr((i,o,s={})=>{if(s.lengthDelimited!==!1&&o.fork(),i.Type!=null&&(o.uint32(8),t.DataType.codec().encode(i.Type,o)),i.Data!=null&&(o.uint32(18),o.bytes(i.Data)),i.filesize!=null&&(o.uint32(24),o.uint64(i.filesize)),i.blocksizes!=null)for(let a of i.blocksizes)o.uint32(32),o.uint64(a);i.hashType!=null&&(o.uint32(40),o.uint64(i.hashType)),i.fanout!=null&&(o.uint32(48),o.uint64(i.fanout)),i.mode!=null&&(o.uint32(56),o.uint32(i.mode)),i.mtime!=null&&(o.uint32(66),En.codec().encode(i.mtime,o)),s.lengthDelimited!==!1&&o.ldelim()},(i,o)=>{let s={blocksizes:[]},a=o==null?i.len:i.pos+o;for(;i.pos<a;){let c=i.uint32();switch(c>>>3){case 1:s.Type=t.DataType.codec().decode(i);break;case 2:s.Data=i.bytes();break;case 3:s.filesize=i.uint64();break;case 4:s.blocksizes.push(i.uint64());break;case 5:s.hashType=i.uint64();break;case 6:s.fanout=i.uint64();break;case 7:s.mode=i.uint32();break;case 8:s.mtime=En.codec().decode(i,i.uint32());break;default:i.skipType(c&7);break}}return s})),n),t.encode=i=>Tr(i,t.codec()),t.decode=i=>Sr(i,t.codec())})(Ue||(Ue={}));var En;(function(t){let e;t.codec=()=>(e==null&&(e=Nr((r,n,i={})=>{i.lengthDelimited!==!1&&n.fork(),r.Seconds!=null&&(n.uint32(8),n.int64(r.Seconds)),r.FractionalNanoseconds!=null&&(n.uint32(21),n.fixed32(r.FractionalNanoseconds)),i.lengthDelimited!==!1&&n.ldelim()},(r,n)=>{let i={},o=n==null?r.len:r.pos+n;for(;r.pos<o;){let s=r.uint32();switch(s>>>3){case 1:i.Seconds=r.int64();break;case 2:i.FractionalNanoseconds=r.fixed32();break;default:r.skipType(s&7);break}}return i})),e),t.encode=r=>Tr(r,t.codec()),t.decode=r=>Sr(r,t.codec())})(En||(En={}));var Ea;(function(t){let e;t.codec=()=>(e==null&&(e=Nr((r,n,i={})=>{i.lengthDelimited!==!1&&n.fork(),r.MimeType!=null&&(n.uint32(10),n.string(r.MimeType)),i.lengthDelimited!==!1&&n.ldelim()},(r,n)=>{let i={},o=n==null?r.len:r.pos+n;for(;r.pos<o;){let s=r.uint32();switch(s>>>3){case 1:i.MimeType=r.string();break;default:r.skipType(s&7);break}}return i})),e),t.encode=r=>Tr(r,t.codec()),t.decode=r=>Sr(r,t.codec())})(Ea||(Ea={}));var Sa={Raw:"raw",Directory:"directory",File:"file",Metadata:"metadata",Symlink:"symlink",HAMTShard:"hamt-sharded-directory"},Jd=["directory","hamt-sharded-directory"],ka=parseInt("0644",8),Ba=parseInt("0755",8),B=class t{static unmarshal(e){let r=Ue.decode(e),n=new t({type:Sa[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:i,hashType:o,fanout:s,mtime:a,mode:c}=e;if(r!=null&&!Object.values(Sa).includes(r))throw new _r("Type: "+r+" is not valid");this.type=r??"file",this.data=n,this.hashType=o,this.fanout=s,this.blockSizes=i??[],this._originalMode=0,this.mode=c,this.mtime=a}set mode(e){e==null?this._mode=this.isDirectory()?Ba:ka:this._mode=e&4095}get mode(){return this._mode}isDirectory(){return Jd.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=Ue.DataType.Raw;break;case"directory":e=Ue.DataType.Directory;break;case"file":e=Ue.DataType.File;break;case"metadata":e=Ue.DataType.Metadata;break;case"symlink":e=Ue.DataType.Symlink;break;case"hamt-sharded-directory":e=Ue.DataType.HAMTShard;break;default:throw new _r(`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===ka&&!this.isDirectory()&&(n=void 0),n===Ba&&this.isDirectory()&&(n=void 0));let i;return this.mtime!=null&&(i={Seconds:this.mtime.secs,FractionalNanoseconds:this.mtime.nsecs}),Ue.encode({Type:e,Data:r,filesize:this.isDirectory()?void 0:this.fileSize(),blocksizes:this.blockSizes,hashType:this.hashType,fanout:this.fanout,mode:n,mtime:i})}};var K=class extends Event{type;detail;constructor(e,r){super(e),this.type=e,this.detail=r}};var Se=async(t,e,r)=>{r.codec==null&&(r.codec=V);let n=await de.digest(t),i=A.create(r.cidVersion??1,r.codec.code,n);return await e.put(i,t,r),i};function va(t){return async function*(r,n){let i=0n;for await(let o of r.content)yield async()=>{let s,a={codec:V,cidVersion:t.cidVersion,onProgress:t.onProgress};t.rawLeaves?(a.codec=Le,a.cidVersion=1):(s=new B({type:t.leafType,data:o}),o=C({Data:s.marshal(),Links:[]}));let c=await Se(o,n,a);return i+=BigInt(o.byteLength),t.onProgress?.(new K("unixfs:importer:progress:file:write",{bytesWritten:i,cid:c,path:r.path})),{cid:c,unixfs:s,size:BigInt(o.length),block:o}}}}var Sn=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 je=class t extends Error{static name="InvalidContentError";static code="ERR_INVALID_CONTENT";name=t.name;code=t.code;constructor(e="Invalid content"){super(e)}},Cr=class extends Error{static name="InvalidShardingStrategyError";static code="ERR_SHARDING_STRATEGY";name=je.name;code=je.code};var Aa=async(t,e,r)=>{let n=new B({type:"directory",mtime:t.mtime,mode:t.mode}),i=C(G({Data:n.marshal()})),o=await Se(i,e,r),s=t.path;return{cid:o,path:s,unixfs:n,size:BigInt(i.length),originalPath:t.originalPath,block:i}};async function*Xd(t,e,r){let n=-1,i;for await(let o of wr(r.bufferImporter(t,e),r.blockWriteConcurrency)){if(n++,n===0){i={...o,single:!0};continue}else n===1&&i!=null&&(yield{...i,block:void 0,single:void 0},i=void 0);yield{...o,block:void 0}}i!=null&&(yield i)}function Ta(t){return t.single===!0}var Yd=(t,e,r)=>async function(i){if(i.length===1&&Ta(i[0])&&r.reduceSingleLeafToSelf){let u=i[0],d=u.block;return Ta(u)&&(t.mtime!==void 0||t.mode!==void 0)&&(u.unixfs=new B({type:"file",mtime:t.mtime,mode:t.mode,data:u.block}),d={Data:u.unixfs.marshal(),Links:[]},u.block=C(G(d)),u.cid=await Se(u.block,e,{...r,cidVersion:r.cidVersion}),u.size=BigInt(u.block.length)),r.onProgress?.(new K("unixfs:importer:progress:file:layout",{cid:u.cid,path:t.originalPath})),{cid:u.cid,path:t.path,unixfs:u.unixfs,size:u.size,originalPath:t.originalPath}}let o=new B({type:"file",mtime:t.mtime,mode:t.mode}),s=i.filter(u=>u.cid.code===te&&u.size>0||u.unixfs!=null&&u.unixfs.data==null&&u.unixfs.fileSize()>0n?!0:!!u.unixfs?.data?.length).map(u=>u.cid.code===te?(o.addBlockSize(u.size),{Name:"",Tsize:Number(u.size),Hash:u.cid}):(u.unixfs?.data==null?o.addBlockSize(u.unixfs?.fileSize()??0n):o.addBlockSize(BigInt(u.unixfs.data.length)),{Name:"",Tsize:Number(u.size),Hash:u.cid})),a={Data:o.marshal(),Links:s},c=C(G(a)),f=await Se(c,e,r);return r.onProgress?.(new K("unixfs:importer:progress:file:layout",{cid:f,path:t.originalPath})),{cid:f,path:t.path,unixfs:o,size:BigInt(c.length+a.Links.reduce((u,d)=>u+(d.Tsize??0),0)),originalPath:t.originalPath,block:c}},Na=async(t,e,r)=>r.layout(Xd(t,e,r),Yd(t,e,r));function Zd(t){return Symbol.iterator in t}function Qd(t){return Symbol.asyncIterator in t}function eh(t){try{if(t instanceof Uint8Array)return(async function*(){yield t})();if(Zd(t))return(async function*(){yield*t})();if(Qd(t))return t}catch{throw new je("Content was invalid")}throw new je("Content was invalid")}function Ca(t){return async function*(r,n){for await(let i of r){let o;if(i.path!=null&&(o=i.path,i.path=i.path.split("/").filter(s=>s!=null&&s!==".").join("/")),th(i)){let s={path:i.path,mtime:i.mtime,mode:i.mode,content:(async function*(){let c=0n;for await(let f of t.chunker(t.chunkValidator(eh(i.content)))){let u=BigInt(f.byteLength);c+=u,t.onProgress?.(new K("unixfs:importer:progress:file:read",{bytesRead:c,chunkSize:u,path:i.path})),yield f}})(),originalPath:o},a=t.fileBuilder??Na;yield async()=>a(s,n,t)}else if(i.path!=null){let s={path:i.path,mtime:i.mtime,mode:i.mode,originalPath:o},a=t.dirBuilder??Aa;yield async()=>a(s,n,t)}else throw new Error("Import candidate must have content or path or both")}}}function th(t){return t.content!=null}var Da=()=>async function*(e){for await(let r of e){if(r.length===void 0)throw new je("Content was invalid");if(typeof r=="string"||r instanceof String)yield O(r.toString());else if(Array.isArray(r))yield Uint8Array.from(r);else if(r instanceof Uint8Array)yield r;else throw new je("Content was invalid")}};var rh=174;function Dr(t){let e=t?.maxChildrenPerNode??rh;return async function r(n,i){let o=[];for await(let s of un(n,e))o.push(await i(s));return o.length>1?r(o,i):o[0]}}function nh(t){return t[Symbol.asyncIterator]!=null}function ih(t){if(nh(t))return(async()=>{let r=[];for await(let n of t)r.push(n);return r})();let e=[];for(let r of t)e.push(r);return e}var La=ih;var qe=class{options;root;dir;path;dirty;flat;parent;parentKey;unixfs;mode;mtime;cid;size;nodeSize;constructor(e,r){this.options=r??{},this.root=e.root,this.dir=e.dir,this.path=e.path,this.dirty=e.dirty,this.flat=e.flat,this.parent=e.parent,this.parentKey=e.parentKey,this.unixfs=e.unixfs,this.mode=e.mode,this.mtime=e.mtime}};var oh=[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];function sh(t){let e=0;return t>=4294967296&&(t=Math.floor(t/4294967296),e=32),t>=65536&&(t>>>=16,e+=16),t>=256&&(t>>>=8,e+=8),e+oh[t]}function ut(t){return t%2===0&&t++,Math.floor((sh(t)+6)/7)}function Ze(t){let e=0;for(let r=0;r<t.length;r++){let n=t.charCodeAt(r);n<128?e++:n<2048?e+=2:n>=55296&&n<=56319&&r+1<t.length?(r++,e+=4):e+=3}return e}function Lr(t,e,r){let n=1+ut(e)+e;return n+=1+ut(t)+t,n+=1+ut(r),1+ut(n)+n}var ah=493;function Ur(t,e){let r=2;if(t!==void 0&&t!==ah&&(r+=1+ut(t)),e!=null){let n=0,i=Number(e.secs);i<0?n+=11:n+=1+ut(i),e.nsecs!=null&&(n+=5),r+=1+ut(n)+n}return 1+ut(r)+r}function Eo(t,e){return e?.cid!=null&&e?.size!=null?t+e.cid.byteLength:0}function So(t,e){return e?.cid!=null&&e?.size!=null?Lr(t,e.cid.byteLength,Number(e.size)):0}var vt=class extends qe{_children;constructor(e,r){super(e,r),this._children=new Map}async put(e,r){if(this.nodeSize!==void 0){let n=this._children.get(e),i=Ze(e),o=this.options?.shardSplitStrategy;if(o==="links-bytes")this.nodeSize-=Eo(i,n),this.nodeSize+=Eo(i,r);else if(o==="block-bytes")this.nodeSize-=So(i,n),this.nodeSize+=So(i,r);else throw new Cr(`Invalid shardSplitStrategy: ${o}`);this.nodeSize<0&&(this.nodeSize=void 0)}this.cid=void 0,this.size=void 0,this._children.set(e,r)}async get(e){return Promise.resolve(this._children.get(e))}childCount(){return this._children.size}directChildrenCount(){return this.childCount()}onlyChild(){return this._children.values().next().value}*eachChildSeries(){for(let[e,r]of this._children.entries())yield{key:e,child:r}}marshal(){let e=new B({type:"directory",mtime:this.mtime,mode:this.mode}),r=[];for(let[i,o]of this._children.entries())if(!(o.size==null||o.cid==null)){if(o.cid==null)throw new Error("Directory contents must be flushed before marshaling");r.push({Hash:o.cid,Name:i,Tsize:o.size==null?void 0:Number(o.size)})}let n={Data:e.marshal(),Links:r};return C(G(n))}async estimateNodeSize(){if(this.nodeSize!==void 0)return this.nodeSize;let e=this.options?.shardSplitStrategy;if(e==="links-bytes"){this.nodeSize=0;for(let[r,n]of this._children.entries())this.nodeSize+=Eo(Ze(r),n)}else if(e==="block-bytes"){this.nodeSize=Ur(this.mode,this.mtime);for(let[r,n]of this._children.entries())this.nodeSize+=So(Ze(r),n)}else throw new Cr(`Invalid shardSplitStrategy: ${e}`);return this.nodeSize}async*flush(e){let r=[];for(let[c,f]of this._children.entries()){let u=f;if(f instanceof qe)for await(let d of f.flush(e))u=d,yield d;u.size!=null&&u.cid!=null&&r.push({Name:c,Tsize:Number(u.size),Hash:u.cid})}let n=new B({type:"directory",mtime:this.mtime,mode:this.mode}),i={Data:n.marshal(),Links:r},o=C(G(i)),s=await Se(o,e,this.options),a=o.length+i.Links.reduce((c,f)=>c+(f.Tsize??0),0);this.cid=s,this.size=a,yield{cid:s,unixfs:n,path:this.path,size:BigInt(a)}}};function ft(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 ch(t,e){return t+e>>>0}function ke(t,e){let r=t.lo&65535,n=t.lo>>>16,i=e.lo&65535,o=e.lo>>>16,s=r*i,a=r*o,c=n*i,f=n*o,u=(s>>>16)+(a&65535)+(c&65535)>>>0,d=(u<<16|s&65535)>>>0,m=f+(a>>>16)+(c>>>16)+(u>>>16),y=Math.imul(t.lo,e.hi),p=Math.imul(t.hi,e.lo),w=m+y+p>>>0;return{lo:d,hi:w}}function At(t,e){return Math.imul(t,e)>>>0}function Wt(t,e){if(e===0)return t;if(e===32)return{lo:t.hi,hi:t.lo};if(e<32){let i=(t.lo<<e|t.hi>>>32-e)>>>0,o=(t.hi<<e|t.lo>>>32-e)>>>0;return{lo:i,hi:o}}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 P(t,e){return{lo:(t.lo^e.lo)>>>0,hi:(t.hi^e.hi)>>>0}}function ko(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 U(t,e){return{lo:t>>>0,hi:e>>>0}}function Bo(t,e){return(t<<e|t>>>32-e)>>>0}function Ua(t,e){let r=e*8,n=t[r]|t[r+1]<<8|t[r+2]<<16|t[r+3]<<24,i=t[r+4]|t[r+5]<<8|t[r+6]<<16|t[r+7]<<24;return{lo:n>>>0,hi:i>>>0}}function uh(t,e){let r=e*4;return(t[r]|t[r+1]<<8|t[r+2]<<16|t[r+3]<<24)>>>0}function Fa(t){return t=P(t,ko(t,33)),t=ke(t,U(3981806797,4283543511)),t=P(t,ko(t,33)),t=ke(t,U(444984403,3301882366)),t=P(t,ko(t,33)),t}function fh(t){return t^=t>>>16,t=At(t,2246822507),t^=t>>>13,t=At(t,3266489909),t^=t>>>16,t}function Io(t,e=0){let r=U(e,0),n=U(e,0),i=t.length,o=Math.floor(i/16),s=U(289559509,2277735313),a=U(658871167,1291169091);for(let m=0;m<o;m++){let y=Ua(t,m*2),p=Ua(t,m*2+1);y=ke(y,s),y=Wt(y,31),y=ke(y,a),r=P(r,y),r=Wt(r,27),r=ft(r,n),r=ft(ke(r,U(5,0)),U(1390208809,0)),p=ke(p,a),p=Wt(p,33),p=ke(p,s),n=P(n,p),n=Wt(n,31),n=ft(n,r),n=ft(ke(n,U(5,0)),U(944331445,0))}let c=U(0,0),f=U(0,0),u=t.slice(o*16);switch(u.length){case 15:f=P(f,U(0,u[14]<<16));case 14:f=P(f,U(0,u[13]<<8));case 13:f=P(f,U(0,u[12]));case 12:f=P(f,U(u[11]<<24,0));case 11:f=P(f,U(u[10]<<16,0));case 10:f=P(f,U(u[9]<<8,0));case 9:f=P(f,U(u[8],0)),f=ke(f,a),f=Wt(f,33),f=ke(f,s),n=P(n,f);case 8:c=P(c,U(0,u[7]<<24));case 7:c=P(c,U(0,u[6]<<16));case 6:c=P(c,U(0,u[5]<<8));case 5:c=P(c,U(0,u[4]));case 4:c=P(c,U(u[3]<<24,0));case 3:c=P(c,U(u[2]<<16,0));case 2:c=P(c,U(u[1]<<8,0));case 1:c=P(c,U(u[0],0)),c=ke(c,s),c=Wt(c,31),c=ke(c,a),r=P(r,c)}let d=U(i,0);return r=P(r,d),n=P(n,d),r=ft(r,n),n=ft(n,r),r=Fa(r),n=Fa(n),r=ft(r,n),n=ft(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 za(t,e=0){let r=e>>>0,n=t.length,i=Math.floor(n/4),o=3432918353,s=461845907;for(let f=0;f<i;f++){let u=uh(t,f);u=At(u,o),u=Bo(u,15),u=At(u,s),r^=u,r=Bo(r,13),r=ch(At(r,5),3864292196)}let a=t.slice(i*4),c=0;switch(a.length){case 3:c^=a[2]<<16;case 2:c^=a[1]<<8;case 1:c^=a[0],c=At(c,o),c=Bo(c,15),c=At(c,s),r^=c}return r^=n,r=fh(r),r}function dh(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 Q0=Bt({name:"murmur3-32",code:35,encode:t=>dh(za(t))}),Tt=Bt({name:"murmur3-128",code:34,encode:t=>Io(t)}),ew=Bt({name:"murmur3-x64-64",code:34,encode:t=>Io(t).subarray(0,8)});var kn=class t extends Error{static name="NotFoundError";static code="ERR_NOT_FOUND";name=t.name;code=t.code;constructor(e="Not Found"){super(e)}};var Bn=class{has(e,r){return Promise.reject(new Error(".has is not implemented"))}put(e,r,n){return Promise.reject(new Error(".put is not implemented"))}async*putMany(e,r){for await(let{cid:n,bytes:i}of e)await this.put(n,i,r),yield n}get(e,r){throw new Error(".get is not implemented")}async*getMany(e,r){for await(let n of e)yield{cid:n,bytes:this.get(n,r)}}delete(e,r){return Promise.reject(new Error(".delete is not implemented"))}async*deleteMany(e,r){for await(let n of e)await this.delete(n,r),yield n}async*getAll(e){throw new Error(".getAll is not implemented")}};var In=class extends Bn{put(e,r,n){return n?.signal?.throwIfAborted(),e}get(e,r){throw r?.signal?.throwIfAborted(),new kn}has(e,r){return r?.signal?.throwIfAborted(),!1}async delete(e,r){r?.signal?.throwIfAborted()}async*getAll(e){e?.signal?.throwIfAborted()}};var $a=on(vn(),1);var Ge=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 $a.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((i,o,s)=>(o!=null&&(o instanceof t?i.push(o.serialize(e,r)):i.push(e(o,s))),i),n))}async asyncTransform(e,r){return Ma(this,e,r)}toJSON(){return this.serialize(gh,wh)}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"?O(e):e),n=await r.take(this._options.bits),i=this._children.get(n);return i instanceof t?i._findPlace(r):{bucket:this,pos:n,hash:r,existingChild:i}}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 i=await n._findPlace(r.existingChild.hash);return i.bucket._putAt(i,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(yh);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 yh(t){return!!t}function gh(t,e){return t.key}function wh(t){return t}async function Ma(t,e,r){let n=[];for(let i of t._children.compactArray())if(i instanceof Ge)await Ma(i,e,r);else{let o=await e(i);n.push({bitField:t._children.bitField(),children:o})}return r(n)}var xh=[255,254,252,248,240,224,192,128],bh=[1,3,7,15,31,63,127,255],An=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 i=this._value[this._currentBytePos],o=this._currentBitPos+1,s=Math.min(o,r),a=_h(i,o-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 _h(t,e,r){let n=Eh(e,r);return(t&n)>>>e}function Eh(t,e){return xh[t]&bh[Math.min(e+t-1,7)]}function Oa(t){function e(r){return r instanceof Tn?r:new Tn(r,t)}return e}var Tn=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 i=this._buffers[this._currentBufferIndex],o=Math.min(i.availableBits(),r),s=i.take(o);n=(n<<o)+s,r-=o,this._availableBits-=o,i.availableBits()===0&&this._currentBufferIndex++}return n}untake(e){let r=e;for(;r>0;){let n=this._buffers[this._currentBufferIndex],i=Math.min(n.totalBits()-n.availableBits(),r);n.untake(i),r-=i,this._availableBits+=i,this._currentBufferIndex>0&&n.totalBits()===n.availableBits()&&(this._depth--,this._currentBufferIndex--)}}async _produceMoreBits(){this._depth++;let e=this._depth>0?Ve([this._value,Uint8Array.from([this._depth])]):this._value,r=await this._hashFn(e),n=new An(r);this._buffers.push(n),this._availableBits+=n.availableBits()}};function Nn(t){if(t==null||t.hashFn==null)throw new Error("please define an options.hashFn");let e={bits:t.bits??8,hash:Oa(t.hashFn)};return new Ge(e)}async function Sh(t){return(await Tt.encode(t)).slice(0,8).reverse()}var vo=class extends qe{bucket;constructor(e,r){super(e,r),this.bucket=Nn({hashFn:Sh,bits:r.shardFanoutBits??dn})}async put(e,r){this.cid=void 0,this.size=void 0,this.nodeSize=void 0,await this.bucket.put(e,r)}async get(e){return this.bucket.get(e)}childCount(){return this.bucket.leafCount()}directChildrenCount(){return this.bucket.childrenCount()}onlyChild(){return this.bucket.onlyChild()}*eachChildSeries(){for(let{key:e,value:r}of this.bucket.eachLeafSeries())yield{key:e,child:r}}async estimateNodeSize(){if(this.nodeSize!==void 0)return this.nodeSize;let e=new In,r=await ja(this.bucket,this,e,this.options);return this.nodeSize=r.size,this.nodeSize}async*flush(e){for await(let r of Ha(this.bucket,e,this,this.options))yield{...r,path:this.path}}},Fr=vo;async function*Ha(t,e,r,n){let i=t._children,o=(t.tableSize()-1).toString(16).length,s=[],a=0n;for(let p=0;p<i.length;p++){let w=i.get(p);if(w==null)continue;let x=p.toString(16).toUpperCase().padStart(o,"0");if(w instanceof Ge){let k;for await(let v of Ha(w,e,null,n))k=v;if(k==null)throw new Error("Could not flush sharded directory, no sub-shard found");s.push({Name:x,Tsize:Number(k.size),Hash:k.cid}),a+=k.size}else if(Va(w.value)){let k=w.value,v;for await(let F of k.flush(e))v=F,yield v;if(v==null)throw new Error("Did not flush dir");let N=x+w.key;s.push({Name:N,Tsize:Number(v.size),Hash:v.cid}),a+=v.size}else{let k=w.value;if(k.cid==null)continue;let v=x+w.key,N=k.size;s.push({Name:v,Tsize:Number(N),Hash:k.cid}),a+=BigInt(N??0)}}let c=Uint8Array.from(i.bitField().reverse()),f=new B({type:"hamt-sharded-directory",data:c,fanout:BigInt(t.tableSize()),hashType:Wi,mtime:r?.mtime,mode:r?.mode}),u={Data:f.marshal(),Links:s},d=C(G(u)),m=await Se(d,e,n),y=BigInt(d.byteLength)+a;yield{cid:m,unixfs:f,size:y}}function Va(t){return typeof t.flush=="function"}async function ja(t,e,r,n){let i=t._children,o=(t.tableSize()-1).toString(16).length,s=[],a=0;for(let m=0;m<i.length;m++){let y=i.get(m);if(y==null)continue;let p=m.toString(16).toUpperCase().padStart(o,"0");if(y instanceof Ge){let{size:w,cid:x}=await ja(y,null,r,n);s.push({Name:p,Tsize:Number(w),Hash:x}),a+=p.length+x.byteLength}else if(Va(y.value)){let w=y.value,x=w.nodeSize;if(w.cid==null)throw new Error("Child directory has not been persisted");s.push({Name:p+y.key,Tsize:Number(x),Hash:w.cid}),a+=p.length+w.cid.byteLength}else{let w=y.value,x=p+y.key,k=w.size;s.push({Name:x,Tsize:Number(k),Hash:w.cid}),a+=p.length+w.cid.byteLength}}let c=Uint8Array.from(i.bitField().reverse()),f=new B({type:"hamt-sharded-directory",data:c,fanout:BigInt(t.tableSize()),hashType:Wi,mtime:e?.mtime,mode:e?.mode}),u=C(G({Data:f.marshal(),Links:s}));return{cid:await Se(u,r,n),size:n.shardSplitStrategy==="links-bytes"?a:u.length}}async function Ao(t,e){let r=e,n=e.options.shardSplitThresholdBytes??hn;e instanceof vt&&await e.estimateNodeSize()>n&&(r=await kh(e));let i=r.parent;if(i!=null){if(r!==e){if(t!=null&&(t.parent=r),r.parentKey==null)throw new Error("No parent key found");await i.put(r.parentKey,r)}return Ao(r,i)}return r}async function kh(t){let e=new Fr({root:t.root,dir:!0,parent:t.parent,parentKey:t.parentKey,path:t.path,dirty:t.dirty,flat:!1,mtime:t.mtime,mode:t.mode},t.options);for(let{key:r,child:n}of t.eachChildSeries())await e.put(r,n);return e}var qa=(t="")=>t.split(/(?<!\\)\//).filter(Boolean);async function Bh(t,e,r){let n=qa(t.path??""),i=n.length-1,o=e,s="";for(let a=0;a<n.length;a++){let c=n[a];s+=`${s!==""?"/":""}${c}`;let f=a===i;if(o.dirty=!0,o.cid=void 0,o.size=void 0,f)await o.put(c,t),e=await Ao(null,o);else{let u=await o.get(c);(u==null||!(u instanceof qe))&&(u=new vt({root:!1,dir:!0,parent:o,parentKey:c,path:s,dirty:!0,flat:!0,mtime:u?.unixfs?.mtime,mode:u?.unixfs?.mode},r)),await o.put(c,u),o=u}}return e}async function*Ga(t,e){if(!(t instanceof qe)){t.unixfs?.isDirectory()===!0&&(yield t);return}yield*t.flush(e)}function Wa(t){return async function*(r,n){let i=new vt({root:!0,dir:!0,path:"",dirty:!0,flat:!0},t),o,s=!1;for await(let a of r){if(a==null)continue;let c=`${a.originalPath??""}`.split("/")[0];c!=null&&c!==""&&(o==null?(o=c,s=!0):o!==c&&(s=!1)),i=await Bh(a,i,t),a.unixfs?.isDirectory()!==!0&&(yield a)}if(t.wrapWithDirectory||s&&i.childCount()>1)yield*Ga(i,n);else for(let a of i.eachChildSeries())a!=null&&(yield*Ga(a.child,n))}}async function*Nt(t,e,r={}){let n;Symbol.asyncIterator in t||Symbol.iterator in t?n=t:n=[t];let i,o;r.profile==="unixfs-v0-2015"?(r.shardSplitStrategy=r.shardSplitStrategy??"links-bytes",r.cidVersion=r.cidVersion??0,r.rawLeaves=r.rawLeaves??!1,i=mn,o=174):r.profile==="unixfs-v1-2025"&&(r.shardSplitStrategy=r.shardSplitStrategy??"block-bytes",r.cidVersion=r.cidVersion??1,r.rawLeaves=r.rawLeaves??!0,i=zs,o=1024);let s=r.wrapWithDirectory??Os,a=r.shardSplitThresholdBytes??hn,c=r.shardSplitStrategy??Fs,f=r.shardFanoutBits??dn,u=r.cidVersion??1,d=r.rawLeaves??Ms,m=r.leafType??Hs,y=r.fileImportConcurrency??Ps,p=r.blockWriteConcurrency??Rs,w=r.reduceSingleLeafToSelf??$s,x=r.chunker??xr({chunkSize:i}),k=r.chunkValidator??Da(),v=r.dagBuilder??Ca({chunker:x,chunkValidator:k,wrapWithDirectory:s,layout:r.layout??Dr({maxChildrenPerNode:o}),bufferImporter:r.bufferImporter??va({cidVersion:u,rawLeaves:d,leafType:m,onProgress:r.onProgress}),blockWriteConcurrency:p,reduceSingleLeafToSelf:w,cidVersion:u,onProgress:r.onProgress,dirBuilder:r.dirBuilder,fileBuilder:r.fileBuilder}),N=r.treeBuilder??Wa({wrapWithDirectory:s,shardSplitThresholdBytes:a,shardSplitStrategy:c,shardFanoutBits:f,cidVersion:u,onProgress:r.onProgress});for await(let F of N(wr(v(n,e),y),e))yield{cid:F.cid,path:F.path,unixfs:F.unixfs,size:F.size}}async function To(t,e,r={}){let n=await cn(Nt([t],e,r));if(n==null)throw new Sn("Nothing imported");return n}function Ih(t){return t[Symbol.asyncIterator]!=null}function vh(t){if(Ih(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 Fe=vh;var ze=class extends Error{name;code;constructor(e,r,n){super(e),this.name=r,this.code=n}},We=class extends ze{constructor(e="not a Unixfs node"){super(e,"NotUnixFSError","ERR_NOT_UNIXFS")}},se=class extends ze{constructor(e="invalid PBNode"){super(e,"InvalidPBNodeError","ERR_INVALID_PB_NODE")}},lt=class extends ze{constructor(e="unknown error"){super(e,"InvalidPBNodeError","ERR_UNKNOWN_ERROR")}},Ct=class extends ze{constructor(e="path already exists"){super(e,"AlreadyExistsError","ERR_ALREADY_EXISTS")}},Qe=class extends ze{constructor(e="path does not exist"){super(e,"DoesNotExistError","ERR_DOES_NOT_EXIST")}},Cn=class extends ze{constructor(e="no content"){super(e,"NoContentError","ERR_NO_CONTENT")}},Dn=class extends ze{constructor(e="not a file"){super(e,"NotAFileError","ERR_NOT_A_FILE")}},dt=class extends ze{constructor(e="not a directory"){super(e,"NotADirectoryError","ERR_NOT_A_DIRECTORY")}},$=class extends ze{constructor(e="invalid parameters"){super(e,"InvalidParametersError","ERR_INVALID_PARAMETERS")}};var zr={cidVersion:1,rawLeaves:!0,layout:Dr({maxChildrenPerNode:1024}),chunker:xr({chunkSize:1048576})};async function*Ln(t,e,r={}){yield*Nt(t,e,{...zr,...r})}async function Ka(t,e,r={}){let{cid:n}=await To({content:t,mode:r.mode,mtime:r.mtime},e,{...zr,...r});return n}async function Ja(t,e,r={}){let{cid:n}=await To({content:t,mode:r.mode,mtime:r.mtime},e,{...zr,...r});return n}async function Xa(t,e,r={}){if(t.path==null)throw new $("path is required");if(t.content==null)throw new $("content is required");let n=await Fe(Ln([t],e,{...zr,...r,wrapWithDirectory:!0}));if(n==null)throw new $("Nothing imported");return n.cid}async function Ya(t,e,r={}){if(t.content!=null)throw new $("Directories cannot have content, use addFile instead");let i=await(t.path==null?cn:Fe)(Ln([{...t,path:t.path??"-"}],e,{...zr,...r,wrapWithDirectory:t.path!=null}));if(i==null)throw new $("Nothing imported");return i.cid}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)}},he=class t extends Error{static name="NotFoundError";static code="ERR_NOT_FOUND";name=t.name;code=t.code;constructor(e="Not found"){super(e)}},Jt=class t extends Error{static name="NoResolverError";static code="ERR_NO_RESOLVER";name=t.name;code=t.code;constructor(e="No resolver"){super(e)}},R=class t extends Error{static name="NotUnixFSError";static code="ERR_NOT_UNIXFS";name=t.name;code=t.code;constructor(e="Not UnixFS"){super(e)}},Un=class t extends Error{static name="OverReadError";static code="ERR_OVER_READ";name=t.name;code=t.code;constructor(e="Over read"){super(e)}},Fn=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 Ah=["Object","RegExp","Date","Error","Map","Set","WeakMap","WeakSet","ArrayBuffer","SharedArrayBuffer","DataView","Promise","URL","HTMLElement","Int8Array","Uint8ClampedArray","Int16Array","Uint16Array","Int32Array","Uint32Array","Float32Array","Float64Array","BigInt64Array","BigUint64Array"];function Za(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=Th(t);return r||"Object"}function Th(t){let e=Object.prototype.toString.call(t).slice(8,-1);if(Ah.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 Pr=globalThis.process&&!globalThis.process.browser&&globalThis.Buffer&&typeof globalThis.Buffer.isBuffer=="function",Nh=new TextEncoder;function zn(t){return Pr&&globalThis.Buffer.isBuffer(t)}function Rr(t){return t instanceof Uint8Array?zn(t)?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):t:Uint8Array.from(t)}var Ch=24,Dh=200,No=Pr?t=>t.length>=Ch?globalThis.Buffer.from(t):Qa(t):t=>t.length>=Dh?Nh.encode(t):Qa(t),Ke=t=>Uint8Array.from(t),ec=Pr?(t,e,r)=>zn(t)?new Uint8Array(t.subarray(e,r)):t.slice(e,r):(t,e,r)=>t.slice(e,r),tc=Pr?(t,e)=>(t=t.map(r=>r instanceof Uint8Array?r:globalThis.Buffer.from(r)),Rr(globalThis.Buffer.concat(t,e))):(t,e)=>{let r=new Uint8Array(e),n=0;for(let i of t)n+i.length>r.length&&(i=i.subarray(0,r.length-n)),r.set(i,n),n+=i.length;return r},rc=Pr?t=>globalThis.Buffer.allocUnsafe(t):t=>new Uint8Array(t);function Pn(t,e){if(zn(t)&&zn(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 i=t.charCodeAt(n);i<128?e[r++]=i:i<2048?(e[r++]=i>>6|192,e[r++]=i&63|128):(i&64512)===55296&&n+1<t.length&&(t.charCodeAt(n+1)&64512)===56320?(i=65536+((i&1023)<<10)+(t.charCodeAt(++n)&1023),e[r++]=i>>18|240,e[r++]=i>>12&63|128,e[r++]=i>>6&63|128,e[r++]=i&63|128):(i>=55296&&i<=57343&&(i=65533),e[r++]=i>>12|224,e[r++]=i>>6&63|128,e[r++]=i&63|128)}return e}var Lh=256,$r=class{constructor(e=Lh){this.chunkSize=e,this.cursor=0,this.maxCursor=-1,this.chunks=[],this._initReuseChunk=null}reset(){this.cursor=0,this.maxCursor=-1,this.chunks.length&&(this.chunks=[]),this._initReuseChunk!==null&&(this.chunks.push(this._initReuseChunk),this.maxCursor=this._initReuseChunk.length-1)}push(e){let r=this.chunks[this.chunks.length-1];if(this.cursor+e.length<=this.maxCursor+1){let i=r.length-(this.maxCursor-this.cursor)-1;r.set(e,i)}else{if(r){let i=r.length-(this.maxCursor-this.cursor)-1;i<r.length&&(this.chunks[this.chunks.length-1]=r.subarray(0,i),this.maxCursor=this.cursor-1)}e.length<64&&e.length<this.chunkSize?(r=rc(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=ec(n,0,this.cursor)}else r=tc(this.chunks,this.cursor);return e&&this.reset(),r}},Rn=class{constructor(e){this.dest=e,this.cursor=0,this.chunks=[e]}reset(){this.cursor=0}push(e){if(this.cursor+e.length>this.dest.length)throw new Error("write out of bounds, destination buffer is too small");this.dest.set(e,this.cursor),this.cursor+=e.length}toBytes(e=!1){let r=this.dest.subarray(0,this.cursor);return e&&this.reset(),r}};var I="CBOR decode error:",Co="CBOR encode error:",Mr=[];Mr[23]=1;Mr[24]=2;Mr[25]=3;Mr[26]=5;Mr[27]=9;function tt(t,e,r){if(t.length-e<r)throw new Error(`${I} not enough data for type`)}var X=[24,256,65536,4294967296,BigInt("18446744073709551616")];function me(t,e,r){tt(t,e,1);let n=t[e];if(r.strict===!0&&n<X[0])throw new Error(`${I} integer encoded in more bytes than necessary (strict decode)`);return n}function pe(t,e,r){tt(t,e,2);let n=t[e]<<8|t[e+1];if(r.strict===!0&&n<X[1])throw new Error(`${I} integer encoded in more bytes than necessary (strict decode)`);return n}function ye(t,e,r){tt(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(`${I} integer encoded in more bytes than necessary (strict decode)`);return n}function ge(t,e,r){tt(t,e,8);let n=t[e]*16777216+(t[e+1]<<16)+(t[e+2]<<8)+t[e+3],i=t[e+4]*16777216+(t[e+5]<<16)+(t[e+6]<<8)+t[e+7],o=(BigInt(n)<<BigInt(32))+BigInt(i);if(r.strict===!0&&o<X[3])throw new Error(`${I} integer encoded in more bytes than necessary (strict decode)`);if(o<=Number.MAX_SAFE_INTEGER)return Number(o);if(r.allowBigInt===!0)return o;throw new Error(`${I} integers outside of the safe integer range are not supported`)}function nc(t,e,r,n){return new E(h.uint,me(t,e+1,n),2)}function ic(t,e,r,n){return new E(h.uint,pe(t,e+1,n),3)}function oc(t,e,r,n){return new E(h.uint,ye(t,e+1,n),5)}function sc(t,e,r,n){return new E(h.uint,ge(t,e+1,n),9)}function Be(t,e){return Y(t,0,e.value)}function Y(t,e,r){if(r<X[0]){let n=Number(r);t.push([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 i=[e|27,0,0,0,0,0,0,0],o=Number(n&BigInt(4294967295)),s=Number(n>>BigInt(32)&BigInt(4294967295));i[8]=o&255,o=o>>8,i[7]=o&255,o=o>>8,i[6]=o&255,o=o>>8,i[5]=o&255,i[4]=s&255,s=s>>8,i[3]=s&255,s=s>>8,i[2]=s&255,s=s>>8,i[1]=s&255,t.push(i)}else throw new Error(`${I} encountered BigInt larger than allowable range`)}}Be.encodedSize=function(e){return Y.encodedSize(e.value)};Y.encodedSize=function(e){return e<X[0]?1:e<X[1]?2:e<X[2]?3:e<X[3]?5:9};Be.compareTokens=function(e,r){return e.value<r.value?-1:e.value>r.value?1:0};function ac(t,e,r,n){return new E(h.negint,-1-me(t,e+1,n),2)}function cc(t,e,r,n){return new E(h.negint,-1-pe(t,e+1,n),3)}function uc(t,e,r,n){return new E(h.negint,-1-ye(t,e+1,n),5)}var Do=BigInt(-1),fc=BigInt(1);function lc(t,e,r,n){let i=ge(t,e+1,n);if(typeof i!="bigint"){let o=-1-i;if(o>=Number.MIN_SAFE_INTEGER)return new E(h.negint,o,9)}if(n.allowBigInt!==!0)throw new Error(`${I} integers outside of the safe integer range are not supported`);return new E(h.negint,Do-BigInt(i),9)}function $n(t,e){let r=e.value,n=typeof r=="bigint"?r*Do-fc:r*-1-1;Y(t,e.type.majorEncoded,n)}$n.encodedSize=function(e){let r=e.value,n=typeof r=="bigint"?r*Do-fc:r*-1-1;return n<X[0]?1:n<X[1]?2:n<X[2]?3:n<X[3]?5:9};$n.compareTokens=function(e,r){return e.value<r.value?1:e.value>r.value?-1:0};function Or(t,e,r,n){tt(t,e,r+n);let i=t.slice(e+r,e+r+n);return new E(h.bytes,i,r+n)}function dc(t,e,r,n){return Or(t,e,1,r)}function hc(t,e,r,n){return Or(t,e,2,me(t,e+1,n))}function mc(t,e,r,n){return Or(t,e,3,pe(t,e+1,n))}function pc(t,e,r,n){return Or(t,e,5,ye(t,e+1,n))}function yc(t,e,r,n){let i=ge(t,e+1,n);if(typeof i=="bigint")throw new Error(`${I} 64-bit integer bytes lengths not supported`);return Or(t,e,9,i)}function Mn(t){return t.encodedBytes===void 0&&(t.encodedBytes=h.equals(t.type,h.string)?No(t.value):t.value),t.encodedBytes}function Xt(t,e){let r=Mn(e);Y(t,e.type.majorEncoded,r.length),t.push(r)}Xt.encodedSize=function(e){let r=Mn(e);return Y.encodedSize(r.length)+r.length};Xt.compareTokens=function(e,r){return Fh(Mn(e),Mn(r))};function Fh(t,e){return t.length<e.length?-1:t.length>e.length?1:Pn(t,e)}var gc=new TextDecoder,Ph=32;function Rh(t,e,r){if(r-e<Ph){let i="";for(let o=e;o<r;o++){let s=t[o];if(s&128)return gc.decode(t.subarray(e,r));i+=String.fromCharCode(s)}return i}return gc.decode(t.subarray(e,r))}function Hr(t,e,r,n,i){let o=r+n;tt(t,e,o);let s=new E(h.string,Rh(t,e+r,e+o),o);return i.retainStringBytes===!0&&(s.byteValue=t.slice(e+r,e+o)),s}function wc(t,e,r,n){return Hr(t,e,1,r,n)}function xc(t,e,r,n){return Hr(t,e,2,me(t,e+1,n),n)}function bc(t,e,r,n){return Hr(t,e,3,pe(t,e+1,n),n)}function _c(t,e,r,n){return Hr(t,e,5,ye(t,e+1,n),n)}function Ec(t,e,r,n){let i=ge(t,e+1,n);if(typeof i=="bigint")throw new Error(`${I} 64-bit integer string lengths not supported`);return Hr(t,e,9,i,n)}var Sc=Xt;function Yt(t,e,r,n){return new E(h.array,n,r)}function kc(t,e,r,n){return Yt(t,e,1,r)}function Bc(t,e,r,n){return Yt(t,e,2,me(t,e+1,n))}function Ic(t,e,r,n){return Yt(t,e,3,pe(t,e+1,n))}function vc(t,e,r,n){return Yt(t,e,5,ye(t,e+1,n))}function Ac(t,e,r,n){let i=ge(t,e+1,n);if(typeof i=="bigint")throw new Error(`${I} 64-bit integer array lengths not supported`);return Yt(t,e,9,i)}function Tc(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${I} indefinite length items not allowed`);return Yt(t,e,1,1/0)}function On(t,e){Y(t,h.array.majorEncoded,e.value)}On.compareTokens=Be.compareTokens;On.encodedSize=function(e){return Y.encodedSize(e.value)};function Zt(t,e,r,n){return new E(h.map,n,r)}function Nc(t,e,r,n){return Zt(t,e,1,r)}function Cc(t,e,r,n){return Zt(t,e,2,me(t,e+1,n))}function Dc(t,e,r,n){return Zt(t,e,3,pe(t,e+1,n))}function Lc(t,e,r,n){return Zt(t,e,5,ye(t,e+1,n))}function Uc(t,e,r,n){let i=ge(t,e+1,n);if(typeof i=="bigint")throw new Error(`${I} 64-bit integer map lengths not supported`);return Zt(t,e,9,i)}function Fc(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${I} indefinite length items not allowed`);return Zt(t,e,1,1/0)}function Hn(t,e){Y(t,h.map.majorEncoded,e.value)}Hn.compareTokens=Be.compareTokens;Hn.encodedSize=function(e){return Y.encodedSize(e.value)};function zc(t,e,r,n){return new E(h.tag,r,1)}function Pc(t,e,r,n){return new E(h.tag,me(t,e+1,n),2)}function Rc(t,e,r,n){return new E(h.tag,pe(t,e+1,n),3)}function $c(t,e,r,n){return new E(h.tag,ye(t,e+1,n),5)}function Mc(t,e,r,n){return new E(h.tag,ge(t,e+1,n),9)}function Vn(t,e){Y(t,h.tag.majorEncoded,e.value)}Vn.compareTokens=Be.compareTokens;Vn.encodedSize=function(e){return Y.encodedSize(e.value)};var Lo=20,Uo=21,Fo=22,zo=23;function Oc(t,e,r,n){if(n.allowUndefined===!1)throw new Error(`${I} undefined values are not supported`);return n.coerceUndefinedToNull===!0?new E(h.null,null,1):new E(h.undefined,void 0,1)}function Hc(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${I} indefinite length items not allowed`);return new E(h.break,void 0,1)}function Po(t,e,r){if(r){if(r.allowNaN===!1&&Number.isNaN(t))throw new Error(`${I} NaN values are not supported`);if(r.allowInfinity===!1&&(t===1/0||t===-1/0))throw new Error(`${I} Infinity values are not supported`)}return new E(h.float,t,e)}function Vc(t,e,r,n){return Po(Ro(t,e+1),3,n)}function jc(t,e,r,n){return Po($o(t,e+1),5,n)}function qc(t,e,r,n){return Po(Jc(t,e+1),9,n)}function jn(t,e,r){let n=e.value;if(n===!1)t.push([h.float.majorEncoded|Lo]);else if(n===!0)t.push([h.float.majorEncoded|Uo]);else if(n===null)t.push([h.float.majorEncoded|Fo]);else if(n===void 0)t.push([h.float.majorEncoded|zo]);else{let i,o=!1;(!r||r.float64!==!0)&&(Wc(n),i=Ro(Pe,1),n===i||Number.isNaN(n)?(Pe[0]=249,t.push(Pe.slice(0,3)),o=!0):(Kc(n),i=$o(Pe,1),n===i&&(Pe[0]=250,t.push(Pe.slice(0,5)),o=!0))),o||(Vh(n),i=Jc(Pe,1),Pe[0]=251,t.push(Pe.slice(0,9)))}}jn.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){Wc(n);let i=Ro(Pe,1);if(n===i||Number.isNaN(n))return 3;if(Kc(n),i=$o(Pe,1),n===i)return 5}return 9};var Gc=new ArrayBuffer(9),Ie=new DataView(Gc,1),Pe=new Uint8Array(Gc,0);function Wc(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 i=r-127;i<-24?Ie.setUint16(0,0):i<-14?Ie.setUint16(0,(e&2147483648)>>16|1<<24+i,!1):Ie.setUint16(0,(e&2147483648)>>16|i+15<<10|n>>13,!1)}}}function Ro(t,e){if(t.length-e<2)throw new Error(`${I} 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,i=r&1023,o;return n===0?o=i*2**-24:n!==31?o=(i+1024)*2**(n-25):o=i===0?1/0:NaN,r&32768?-o:o}function Kc(t){Ie.setFloat32(0,t,!1)}function $o(t,e){if(t.length-e<4)throw new Error(`${I} not enough data for float32`);let r=(t.byteOffset||0)+e;return new DataView(t.buffer,r,4).getFloat32(0,!1)}function Vh(t){Ie.setFloat64(0,t,!1)}function Jc(t,e){if(t.length-e<8)throw new Error(`${I} not enough data for float64`);let r=(t.byteOffset||0)+e;return new DataView(t.buffer,r,8).getFloat64(0,!1)}jn.compareTokens=Be.compareTokens;function D(t,e,r){throw new Error(`${I} encountered invalid minor (${r}) for major ${t[e]>>>5}`)}function qn(t){return()=>{throw new Error(`${I} ${t}`)}}var b=[];for(let t=0;t<=23;t++)b[t]=D;b[24]=nc;b[25]=ic;b[26]=oc;b[27]=sc;b[28]=D;b[29]=D;b[30]=D;b[31]=D;for(let t=32;t<=55;t++)b[t]=D;b[56]=ac;b[57]=cc;b[58]=uc;b[59]=lc;b[60]=D;b[61]=D;b[62]=D;b[63]=D;for(let t=64;t<=87;t++)b[t]=dc;b[88]=hc;b[89]=mc;b[90]=pc;b[91]=yc;b[92]=D;b[93]=D;b[94]=D;b[95]=qn("indefinite length bytes/strings are not supported");for(let t=96;t<=119;t++)b[t]=wc;b[120]=xc;b[121]=bc;b[122]=_c;b[123]=Ec;b[124]=D;b[125]=D;b[126]=D;b[127]=qn("indefinite length bytes/strings are not supported");for(let t=128;t<=151;t++)b[t]=kc;b[152]=Bc;b[153]=Ic;b[154]=vc;b[155]=Ac;b[156]=D;b[157]=D;b[158]=D;b[159]=Tc;for(let t=160;t<=183;t++)b[t]=Nc;b[184]=Cc;b[185]=Dc;b[186]=Lc;b[187]=Uc;b[188]=D;b[189]=D;b[190]=D;b[191]=Fc;for(let t=192;t<=215;t++)b[t]=zc;b[216]=Pc;b[217]=Rc;b[218]=$c;b[219]=Mc;b[220]=D;b[221]=D;b[222]=D;b[223]=D;for(let t=224;t<=243;t++)b[t]=qn("simple values are not supported");b[244]=D;b[245]=D;b[246]=D;b[247]=Oc;b[248]=qn("simple values are not supported");b[249]=Vc;b[250]=jc;b[251]=qc;b[252]=D;b[253]=D;b[254]=D;b[255]=Hc;var Re=[];for(let t=0;t<24;t++)Re[t]=new E(h.uint,t,1);for(let t=-1;t>=-24;t--)Re[31-t]=new E(h.negint,t,1);Re[64]=new E(h.bytes,new Uint8Array(0),1);Re[96]=new E(h.string,"",1);Re[128]=new E(h.array,0,1);Re[160]=new E(h.map,0,1);Re[244]=new E(h.false,!1,1);Re[245]=new E(h.true,!0,1);Re[246]=new E(h.null,null,1);function Xc(t){switch(t.type){case h.false:return Ke([244]);case h.true:return Ke([245]);case h.null:return Ke([246]);case h.bytes:return t.value.length?void 0:Ke([64]);case h.string:return t.value===""?Ke([96]):void 0;case h.array:return t.value===0?Ke([128]):void 0;case h.map:return t.value===0?Ke([160]):void 0;case h.uint:return t.value<24?Ke([Number(t.value)]):void 0;case h.negint:if(t.value>=-24)return Ke([31-Number(t.value)])}}var Zc=Object.freeze({float64:!0,mapSorter:Jh,quickEncodeToken:Xc});function qh(){let t=[];return t[h.uint.major]=Be,t[h.negint.major]=$n,t[h.bytes.major]=Xt,t[h.string.major]=Sc,t[h.array.major]=On,t[h.map.major]=Hn,t[h.tag.major]=Vn,t[h.float.major]=jn,t}var Gh=qh(),Wh=new $r,Wn=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(`${Co} object contains circular references`);return new t(r,e)}},ht={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)},mt={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?ht.true:ht.false},null(t,e,r,n){return ht.null},undefined(t,e,r,n){return ht.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?[ht.emptyArray,new E(h.break)]:ht.emptyArray;n=Wn.createCheck(n,t);let i=[],o=0;for(let s of t)i[o++]=Gn(s,r,n);return r.addBreakTokens?[new E(h.array,t.length),i,new E(h.break)]:[new E(h.array,t.length),i]},Object(t,e,r,n){let i=e!=="Object",o=i?t.keys():Object.keys(t),s=i?t.size:o.length,a;if(s){a=new Array(s),n=Wn.createCheck(n,t);let c=!i&&r.ignoreUndefinedProperties,f=0;for(let u of o){let d=i?t.get(u):t[u];c&&d===void 0||(a[f++]=[Gn(u,r,n),Gn(d,r,n)])}f<s&&(a.length=f)}return a?.length?(Kh(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?[ht.emptyMap,new E(h.break)]:ht.emptyMap}};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 Gn(t,e={},r){let n=Za(t),i=e&&e.typeEncoders&&e.typeEncoders[n]||mt[n];if(typeof i=="function"){let s=i(t,n,e,r);if(s!=null)return s}let o=mt[n];if(!o)throw new Error(`${Co} unsupported type: ${n}`);return o(t,n,e,r)}function Kh(t,e){e.mapSorter&&t.sort(e.mapSorter)}function Jh(t,e){if(t[0]instanceof E&&e[0]instanceof E){let r=t[0],n=e[0];return r._keyBytes||(r._keyBytes=Yc(r.value)),n._keyBytes||(n._keyBytes=Yc(n.value)),Pn(r._keyBytes,n._keyBytes)}throw new Error("rfc8949MapSorter: complex key types are not supported yet")}function Yc(t){return Xh(t,Gh,Zc)}function Qc(t,e,r,n){if(Array.isArray(e))for(let i of e)Qc(t,i,r,n);else r[e.type.major](t,e,n)}var Yx=h.uint.majorEncoded,Zx=h.negint.majorEncoded,Qx=h.bytes.majorEncoded,eb=h.string.majorEncoded,tb=h.array.majorEncoded,rb=h.float.majorEncoded|Lo,nb=h.float.majorEncoded|Uo,ib=h.float.majorEncoded|Fo,ob=h.float.majorEncoded|zo,sb=BigInt(-1),ab=BigInt(1);function Xh(t,e,r,n){let i=n instanceof Uint8Array,o=i?new Rn(n):Wh,s=Gn(t,r);if(!Array.isArray(s)&&r.quickEncodeToken){let a=r.quickEncodeToken(s);if(a)return i?(o.push(a),o.toBytes()):a;let c=e[s.type.major];if(c.encodedSize){let f=c.encodedSize(s,r);if(i||(o=new $r(f)),c(o,s,r),o.chunks.length!==1)throw new Error(`Unexpected error: pre-calculated length for ${s} was wrong`);return i?o.toBytes():Rr(o.chunks[0])}}return o.reset(),Qc(o,s,e,r),o.toBytes(!0)}var Yh={strict:!1,allowIndefinite:!0,allowUndefined:!0,allowBigInt:!0},Kn=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=Re[e];if(r===void 0){let n=b[e];if(!n)throw new Error(`${I} no decoder for major type ${e>>>5} (byte 0x${e.toString(16).padStart(2,"0")})`);let i=e&31;r=n(this.data,this._pos,i,this.options)}return this._pos+=r.encodedLength,r}},pt=Symbol.for("DONE"),Qt=Symbol.for("BREAK");function Zh(t,e,r){let n=[];for(let i=0;i<t.value;i++){let o=yt(e,r);if(o===Qt){if(t.value===1/0)break;throw new Error(`${I} got unexpected break to lengthed array`)}if(o===pt)throw new Error(`${I} found array but not enough entries (got ${i}, expected ${t.value})`);n[i]=o}return n}function Qh(t,e,r){let n=r.useMaps===!0,i=r.rejectDuplicateMapKeys===!0,o=n?void 0:{},s=n?new Map:void 0;for(let a=0;a<t.value;a++){let c=yt(e,r);if(c===Qt){if(t.value===1/0)break;throw new Error(`${I} got unexpected break to lengthed map`)}if(c===pt)throw new Error(`${I} found map but not enough entries (got ${a} [no key], expected ${t.value})`);if(!n&&typeof c!="string")throw new Error(`${I} non-string keys not supported (got ${typeof c})`);if(i&&(n&&s.has(c)||!n&&Object.hasOwn(o,c)))throw new Error(`${I} found repeat map key "${c}"`);let f=yt(e,r);if(f===pt)throw new Error(`${I} found map but not enough entries (got ${a} [no value], expected ${t.value})`);n?s.set(c,f):o[c]=f}return n?s:o}function*em(t,e,r){for(let n=0;n<t.value;n++){let i=yt(e,r);if(i===Qt){if(t.value===1/0)break;throw new Error(`${I} got unexpected break to lengthed map`)}if(i===pt)throw new Error(`${I} found map but not enough entries (got ${n} [no key], expected ${t.value})`);let o=yt(e,r);if(o===pt)throw new Error(`${I} found map but not enough entries (got ${n} [no value], expected ${t.value})`);yield[i,o]}}function tm(t,e){let r=!1,n=function(){if(r)throw new Error(`${I} tag decode() may only be called once`);r=!0;let i=yt(t,e);if(i===pt)throw new Error(`${I} tag content missing`);if(i===Qt)throw new Error(`${I} got unexpected break in tag content`);return i};return n.entries=function(){if(r)throw new Error(`${I} tag decode() may only be called once`);r=!0;let i=t.next();if(!h.equals(i.type,h.map))throw new Error(`${I} entries() requires map content, got ${i.type.name}`);let o=[];for(let s of em(i,t,e))o.push(s);return o},Object.defineProperty(n,"_called",{get(){return r},enumerable:!1}),n}function yt(t,e){if(t.done())return pt;let r=t.next();if(h.equals(r.type,h.break))return Qt;if(r.type.terminal)return r.value;if(h.equals(r.type,h.array))return Zh(r,t,e);if(h.equals(r.type,h.map))return Qh(r,t,e);if(h.equals(r.type,h.tag)){if(e.tags&&typeof e.tags[r.value]=="function"){let n=tm(t,e),i=e.tags[r.value](n);if(!n._called)throw new Error(`${I} tag decoder must call decode() or entries()`);return i}throw new Error(`${I} tag not supported (${r.value})`)}throw new Error("unsupported")}function eu(t,e){if(!(t instanceof Uint8Array))throw new Error(`${I} data to decode must be a Uint8Array`);e=Object.assign({},Yh,e);let r=Rr(t),n=e.tokenizer||new Kn(r,e),i=yt(n,e);if(i===pt)throw new Error(`${I} did not find any content to decode`);if(i===Qt)throw new Error(`${I} got unexpected break`);return[i,t.subarray(n.pos())]}function Mo(t,e){let[r,n]=eu(t,e);if(n.length>0)throw new Error(`${I} too many terminals, data makes no sense`);return r}var ru=42;function im(t){return t instanceof ArrayBuffer?new Uint8Array(t,0,t.byteLength):t}function om(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 E(h.tag,ru),new E(h.bytes,r)]}function sm(){throw new Error("`undefined` is not supported by the IPLD Data Model and cannot be encoded")}function am(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 cm(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 tu={float64:!0,typeEncoders:{Map:cm,Object:om,undefined:sm,number:am}},xb={...tu,typeEncoders:{...tu.typeEncoders}};function um(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 Oo={allowIndefinite:!1,coerceUndefinedToNull:!0,allowNaN:!1,allowInfinity:!1,allowBigInt:!0,strict:!0,useMaps:!1,rejectDuplicateMapKeys:!0,tags:{[ru]:um}},bb={...Oo,tags:{...Oo.tags}};var Jn=113;var Xn=t=>Mo(im(t),Oo);var fm=["Object","RegExp","Date","Error","Map","Set","WeakMap","WeakSet","ArrayBuffer","SharedArrayBuffer","DataView","Promise","URL","HTMLElement","Int8Array","Uint8ClampedArray","Int16Array","Uint16Array","Int32Array","Uint32Array","Float32Array","Float64Array","BigInt64Array","BigUint64Array"];function nu(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=lm(t);return r||"Object"}function lm(t){let e=Object.prototype.toString.call(t).slice(8,-1);if(fm.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 g=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 Vr=globalThis.process&&!globalThis.process.browser&&globalThis.Buffer&&typeof globalThis.Buffer.isBuffer=="function",dm=new TextEncoder;function Zn(t){return Vr&&globalThis.Buffer.isBuffer(t)}function Lt(t){return t instanceof Uint8Array?Zn(t)?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):t:Uint8Array.from(t)}var hm=24,mm=200,jr=Vr?t=>t.length>=hm?globalThis.Buffer.from(t):iu(t):t=>t.length>=mm?dm.encode(t):iu(t),Je=t=>Uint8Array.from(t),su=Vr?(t,e,r)=>Zn(t)?new Uint8Array(t.subarray(e,r)):t.slice(e,r):(t,e,r)=>t.slice(e,r),au=Vr?(t,e)=>(t=t.map(r=>r instanceof Uint8Array?r:globalThis.Buffer.from(r)),Lt(globalThis.Buffer.concat(t,e))):(t,e)=>{let r=new Uint8Array(e),n=0;for(let i of t)n+i.length>r.length&&(i=i.subarray(0,r.length-n)),r.set(i,n),n+=i.length;return r},cu=Vr?t=>globalThis.Buffer.allocUnsafe(t):t=>new Uint8Array(t);function Qn(t,e){if(Zn(t)&&Zn(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 iu(t){let e=[],r=0;for(let n=0;n<t.length;n++){let i=t.charCodeAt(n);i<128?e[r++]=i:i<2048?(e[r++]=i>>6|192,e[r++]=i&63|128):(i&64512)===55296&&n+1<t.length&&(t.charCodeAt(n+1)&64512)===56320?(i=65536+((i&1023)<<10)+(t.charCodeAt(++n)&1023),e[r++]=i>>18|240,e[r++]=i>>12&63|128,e[r++]=i>>6&63|128,e[r++]=i&63|128):(i>=55296&&i<=57343&&(i=65533),e[r++]=i>>12|224,e[r++]=i>>6&63|128,e[r++]=i&63|128)}return e}var ou=4096;function uu(t){let e=t.length;if(e<=ou)return String.fromCharCode.apply(String,t);let r="",n=0;for(;n<e;)r+=String.fromCharCode.apply(String,t.slice(n,n+=ou));return r}var pm=256,qr=class{constructor(e=pm){this.chunkSize=e,this.cursor=0,this.maxCursor=-1,this.chunks=[],this._initReuseChunk=null}reset(){this.cursor=0,this.maxCursor=-1,this.chunks.length&&(this.chunks=[]),this._initReuseChunk!==null&&(this.chunks.push(this._initReuseChunk),this.maxCursor=this._initReuseChunk.length-1)}push(e){let r=this.chunks[this.chunks.length-1];if(this.cursor+e.length<=this.maxCursor+1){let i=r.length-(this.maxCursor-this.cursor)-1;r.set(e,i)}else{if(r){let i=r.length-(this.maxCursor-this.cursor)-1;i<r.length&&(this.chunks[this.chunks.length-1]=r.subarray(0,i),this.maxCursor=this.cursor-1)}e.length<64&&e.length<this.chunkSize?(r=cu(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=su(n,0,this.cursor)}else r=au(this.chunks,this.cursor);return e&&this.reset(),r}},ei=class{constructor(e){this.dest=e,this.cursor=0,this.chunks=[e]}reset(){this.cursor=0}push(e){if(this.cursor+e.length>this.dest.length)throw new Error("write out of bounds, destination buffer is too small");this.dest.set(e,this.cursor),this.cursor+=e.length}toBytes(e=!1){let r=this.dest.subarray(0,this.cursor);return e&&this.reset(),r}};var S="CBOR decode error:",er="CBOR encode error:",Gr=[];Gr[23]=1;Gr[24]=2;Gr[25]=3;Gr[26]=5;Gr[27]=9;function rt(t,e,r){if(t.length-e<r)throw new Error(`${S} not enough data for type`)}var Z=[24,256,65536,4294967296,BigInt("18446744073709551616")];function we(t,e,r){rt(t,e,1);let n=t[e];if(r.strict===!0&&n<Z[0])throw new Error(`${S} integer encoded in more bytes than necessary (strict decode)`);return n}function xe(t,e,r){rt(t,e,2);let n=t[e]<<8|t[e+1];if(r.strict===!0&&n<Z[1])throw new Error(`${S} integer encoded in more bytes than necessary (strict decode)`);return n}function be(t,e,r){rt(t,e,4);let n=t[e]*16777216+(t[e+1]<<16)+(t[e+2]<<8)+t[e+3];if(r.strict===!0&&n<Z[2])throw new Error(`${S} integer encoded in more bytes than necessary (strict decode)`);return n}function _e(t,e,r){rt(t,e,8);let n=t[e]*16777216+(t[e+1]<<16)+(t[e+2]<<8)+t[e+3],i=t[e+4]*16777216+(t[e+5]<<16)+(t[e+6]<<8)+t[e+7],o=(BigInt(n)<<BigInt(32))+BigInt(i);if(r.strict===!0&&o<Z[3])throw new Error(`${S} integer encoded in more bytes than necessary (strict decode)`);if(o<=Number.MAX_SAFE_INTEGER)return Number(o);if(r.allowBigInt===!0)return o;throw new Error(`${S} integers outside of the safe integer range are not supported`)}function fu(t,e,r,n){return new g(l.uint,we(t,e+1,n),2)}function lu(t,e,r,n){return new g(l.uint,xe(t,e+1,n),3)}function du(t,e,r,n){return new g(l.uint,be(t,e+1,n),5)}function hu(t,e,r,n){return new g(l.uint,_e(t,e+1,n),9)}function ve(t,e){return Q(t,0,e.value)}function Q(t,e,r){if(r<Z[0]){let n=Number(r);t.push([e|n])}else if(r<Z[1]){let n=Number(r);t.push([e|24,n])}else if(r<Z[2]){let n=Number(r);t.push([e|25,n>>>8,n&255])}else if(r<Z[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<Z[4]){let i=[e|27,0,0,0,0,0,0,0],o=Number(n&BigInt(4294967295)),s=Number(n>>BigInt(32)&BigInt(4294967295));i[8]=o&255,o=o>>8,i[7]=o&255,o=o>>8,i[6]=o&255,o=o>>8,i[5]=o&255,i[4]=s&255,s=s>>8,i[3]=s&255,s=s>>8,i[2]=s&255,s=s>>8,i[1]=s&255,t.push(i)}else throw new Error(`${S} encountered BigInt larger than allowable range`)}}ve.encodedSize=function(e){return Q.encodedSize(e.value)};Q.encodedSize=function(e){return e<Z[0]?1:e<Z[1]?2:e<Z[2]?3:e<Z[3]?5:9};ve.compareTokens=function(e,r){return e.value<r.value?-1:e.value>r.value?1:0};function mu(t,e,r,n){return new g(l.negint,-1-we(t,e+1,n),2)}function pu(t,e,r,n){return new g(l.negint,-1-xe(t,e+1,n),3)}function yu(t,e,r,n){return new g(l.negint,-1-be(t,e+1,n),5)}var Ho=BigInt(-1),gu=BigInt(1);function wu(t,e,r,n){let i=_e(t,e+1,n);if(typeof i!="bigint"){let o=-1-i;if(o>=Number.MIN_SAFE_INTEGER)return new g(l.negint,o,9)}if(n.allowBigInt!==!0)throw new Error(`${S} integers outside of the safe integer range are not supported`);return new g(l.negint,Ho-BigInt(i),9)}function ti(t,e){let r=e.value,n=typeof r=="bigint"?r*Ho-gu:r*-1-1;Q(t,e.type.majorEncoded,n)}ti.encodedSize=function(e){let r=e.value,n=typeof r=="bigint"?r*Ho-gu:r*-1-1;return n<Z[0]?1:n<Z[1]?2:n<Z[2]?3:n<Z[3]?5:9};ti.compareTokens=function(e,r){return e.value<r.value?1:e.value>r.value?-1:0};function Wr(t,e,r,n){rt(t,e,r+n);let i=t.slice(e+r,e+r+n);return new g(l.bytes,i,r+n)}function xu(t,e,r,n){return Wr(t,e,1,r)}function bu(t,e,r,n){return Wr(t,e,2,we(t,e+1,n))}function _u(t,e,r,n){return Wr(t,e,3,xe(t,e+1,n))}function Eu(t,e,r,n){return Wr(t,e,5,be(t,e+1,n))}function Su(t,e,r,n){let i=_e(t,e+1,n);if(typeof i=="bigint")throw new Error(`${S} 64-bit integer bytes lengths not supported`);return Wr(t,e,9,i)}function ri(t){return t.encodedBytes===void 0&&(t.encodedBytes=l.equals(t.type,l.string)?jr(t.value):t.value),t.encodedBytes}function tr(t,e){let r=ri(e);Q(t,e.type.majorEncoded,r.length),t.push(r)}tr.encodedSize=function(e){let r=ri(e);return Q.encodedSize(r.length)+r.length};tr.compareTokens=function(e,r){return gm(ri(e),ri(r))};function gm(t,e){return t.length<e.length?-1:t.length>e.length?1:Qn(t,e)}var ku=new TextDecoder,xm=32;function bm(t,e,r){if(r-e<xm){let i="";for(let o=e;o<r;o++){let s=t[o];if(s&128)return ku.decode(t.subarray(e,r));i+=String.fromCharCode(s)}return i}return ku.decode(t.subarray(e,r))}function Kr(t,e,r,n,i){let o=r+n;rt(t,e,o);let s=new g(l.string,bm(t,e+r,e+o),o);return i.retainStringBytes===!0&&(s.byteValue=t.slice(e+r,e+o)),s}function Bu(t,e,r,n){return Kr(t,e,1,r,n)}function Iu(t,e,r,n){return Kr(t,e,2,we(t,e+1,n),n)}function vu(t,e,r,n){return Kr(t,e,3,xe(t,e+1,n),n)}function Au(t,e,r,n){return Kr(t,e,5,be(t,e+1,n),n)}function Tu(t,e,r,n){let i=_e(t,e+1,n);if(typeof i=="bigint")throw new Error(`${S} 64-bit integer string lengths not supported`);return Kr(t,e,9,i,n)}var Nu=tr;function rr(t,e,r,n){return new g(l.array,n,r)}function Cu(t,e,r,n){return rr(t,e,1,r)}function Du(t,e,r,n){return rr(t,e,2,we(t,e+1,n))}function Lu(t,e,r,n){return rr(t,e,3,xe(t,e+1,n))}function Uu(t,e,r,n){return rr(t,e,5,be(t,e+1,n))}function Fu(t,e,r,n){let i=_e(t,e+1,n);if(typeof i=="bigint")throw new Error(`${S} 64-bit integer array lengths not supported`);return rr(t,e,9,i)}function zu(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${S} indefinite length items not allowed`);return rr(t,e,1,1/0)}function ni(t,e){Q(t,l.array.majorEncoded,e.value)}ni.compareTokens=ve.compareTokens;ni.encodedSize=function(e){return Q.encodedSize(e.value)};function nr(t,e,r,n){return new g(l.map,n,r)}function Pu(t,e,r,n){return nr(t,e,1,r)}function Ru(t,e,r,n){return nr(t,e,2,we(t,e+1,n))}function $u(t,e,r,n){return nr(t,e,3,xe(t,e+1,n))}function Mu(t,e,r,n){return nr(t,e,5,be(t,e+1,n))}function Ou(t,e,r,n){let i=_e(t,e+1,n);if(typeof i=="bigint")throw new Error(`${S} 64-bit integer map lengths not supported`);return nr(t,e,9,i)}function Hu(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${S} indefinite length items not allowed`);return nr(t,e,1,1/0)}function ii(t,e){Q(t,l.map.majorEncoded,e.value)}ii.compareTokens=ve.compareTokens;ii.encodedSize=function(e){return Q.encodedSize(e.value)};function Vu(t,e,r,n){return new g(l.tag,r,1)}function ju(t,e,r,n){return new g(l.tag,we(t,e+1,n),2)}function qu(t,e,r,n){return new g(l.tag,xe(t,e+1,n),3)}function Gu(t,e,r,n){return new g(l.tag,be(t,e+1,n),5)}function Wu(t,e,r,n){return new g(l.tag,_e(t,e+1,n),9)}function oi(t,e){Q(t,l.tag.majorEncoded,e.value)}oi.compareTokens=ve.compareTokens;oi.encodedSize=function(e){return Q.encodedSize(e.value)};var Vo=20,jo=21,qo=22,Go=23;function Ku(t,e,r,n){if(n.allowUndefined===!1)throw new Error(`${S} undefined values are not supported`);return n.coerceUndefinedToNull===!0?new g(l.null,null,1):new g(l.undefined,void 0,1)}function Ju(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${S} indefinite length items not allowed`);return new g(l.break,void 0,1)}function Wo(t,e,r){if(r){if(r.allowNaN===!1&&Number.isNaN(t))throw new Error(`${S} NaN values are not supported`);if(r.allowInfinity===!1&&(t===1/0||t===-1/0))throw new Error(`${S} Infinity values are not supported`)}return new g(l.float,t,e)}function Xu(t,e,r,n){return Wo(Ko(t,e+1),3,n)}function Yu(t,e,r,n){return Wo(Jo(t,e+1),5,n)}function Zu(t,e,r,n){return Wo(rf(t,e+1),9,n)}function si(t,e,r){let n=e.value;if(n===!1)t.push([l.float.majorEncoded|Vo]);else if(n===!0)t.push([l.float.majorEncoded|jo]);else if(n===null)t.push([l.float.majorEncoded|qo]);else if(n===void 0)t.push([l.float.majorEncoded|Go]);else{let i,o=!1;(!r||r.float64!==!0)&&(ef(n),i=Ko($e,1),n===i||Number.isNaN(n)?($e[0]=249,t.push($e.slice(0,3)),o=!0):(tf(n),i=Jo($e,1),n===i&&($e[0]=250,t.push($e.slice(0,5)),o=!0))),o||(Bm(n),i=rf($e,1),$e[0]=251,t.push($e.slice(0,9)))}}si.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){ef(n);let i=Ko($e,1);if(n===i||Number.isNaN(n))return 3;if(tf(n),i=Jo($e,1),n===i)return 5}return 9};var Qu=new ArrayBuffer(9),Ae=new DataView(Qu,1),$e=new Uint8Array(Qu,0);function ef(t){if(t===1/0)Ae.setUint16(0,31744,!1);else if(t===-1/0)Ae.setUint16(0,64512,!1);else if(Number.isNaN(t))Ae.setUint16(0,32256,!1);else{Ae.setFloat32(0,t);let e=Ae.getUint32(0),r=(e&2139095040)>>23,n=e&8388607;if(r===255)Ae.setUint16(0,31744,!1);else if(r===0)Ae.setUint16(0,(e&2147483648)>>16|n>>13,!1);else{let i=r-127;i<-24?Ae.setUint16(0,0):i<-14?Ae.setUint16(0,(e&2147483648)>>16|1<<24+i,!1):Ae.setUint16(0,(e&2147483648)>>16|i+15<<10|n>>13,!1)}}}function Ko(t,e){if(t.length-e<2)throw new Error(`${S} 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,i=r&1023,o;return n===0?o=i*2**-24:n!==31?o=(i+1024)*2**(n-25):o=i===0?1/0:NaN,r&32768?-o:o}function tf(t){Ae.setFloat32(0,t,!1)}function Jo(t,e){if(t.length-e<4)throw new Error(`${S} not enough data for float32`);let r=(t.byteOffset||0)+e;return new DataView(t.buffer,r,4).getFloat32(0,!1)}function Bm(t){Ae.setFloat64(0,t,!1)}function rf(t,e){if(t.length-e<8)throw new Error(`${S} not enough data for float64`);let r=(t.byteOffset||0)+e;return new DataView(t.buffer,r,8).getFloat64(0,!1)}si.compareTokens=ve.compareTokens;function L(t,e,r){throw new Error(`${S} encountered invalid minor (${r}) for major ${t[e]>>>5}`)}function ai(t){return()=>{throw new Error(`${S} ${t}`)}}var _=[];for(let t=0;t<=23;t++)_[t]=L;_[24]=fu;_[25]=lu;_[26]=du;_[27]=hu;_[28]=L;_[29]=L;_[30]=L;_[31]=L;for(let t=32;t<=55;t++)_[t]=L;_[56]=mu;_[57]=pu;_[58]=yu;_[59]=wu;_[60]=L;_[61]=L;_[62]=L;_[63]=L;for(let t=64;t<=87;t++)_[t]=xu;_[88]=bu;_[89]=_u;_[90]=Eu;_[91]=Su;_[92]=L;_[93]=L;_[94]=L;_[95]=ai("indefinite length bytes/strings are not supported");for(let t=96;t<=119;t++)_[t]=Bu;_[120]=Iu;_[121]=vu;_[122]=Au;_[123]=Tu;_[124]=L;_[125]=L;_[126]=L;_[127]=ai("indefinite length bytes/strings are not supported");for(let t=128;t<=151;t++)_[t]=Cu;_[152]=Du;_[153]=Lu;_[154]=Uu;_[155]=Fu;_[156]=L;_[157]=L;_[158]=L;_[159]=zu;for(let t=160;t<=183;t++)_[t]=Pu;_[184]=Ru;_[185]=$u;_[186]=Mu;_[187]=Ou;_[188]=L;_[189]=L;_[190]=L;_[191]=Hu;for(let t=192;t<=215;t++)_[t]=Vu;_[216]=ju;_[217]=qu;_[218]=Gu;_[219]=Wu;_[220]=L;_[221]=L;_[222]=L;_[223]=L;for(let t=224;t<=243;t++)_[t]=ai("simple values are not supported");_[244]=L;_[245]=L;_[246]=L;_[247]=Ku;_[248]=ai("simple values are not supported");_[249]=Xu;_[250]=Yu;_[251]=Zu;_[252]=L;_[253]=L;_[254]=L;_[255]=Ju;var Me=[];for(let t=0;t<24;t++)Me[t]=new g(l.uint,t,1);for(let t=-1;t>=-24;t--)Me[31-t]=new g(l.negint,t,1);Me[64]=new g(l.bytes,new Uint8Array(0),1);Me[96]=new g(l.string,"",1);Me[128]=new g(l.array,0,1);Me[160]=new g(l.map,0,1);Me[244]=new g(l.false,!1,1);Me[245]=new g(l.true,!0,1);Me[246]=new g(l.null,null,1);function nf(t){switch(t.type){case l.false:return Je([244]);case l.true:return Je([245]);case l.null:return Je([246]);case l.bytes:return t.value.length?void 0:Je([64]);case l.string:return t.value===""?Je([96]):void 0;case l.array:return t.value===0?Je([128]):void 0;case l.map:return t.value===0?Je([160]):void 0;case l.uint:return t.value<24?Je([Number(t.value)]):void 0;case l.negint:if(t.value>=-24)return Je([31-Number(t.value)])}}var sf=Object.freeze({float64:!0,mapSorter:Cm,quickEncodeToken:nf});function vm(){let t=[];return t[l.uint.major]=ve,t[l.negint.major]=ti,t[l.bytes.major]=tr,t[l.string.major]=Nu,t[l.array.major]=ni,t[l.map.major]=ii,t[l.tag.major]=oi,t[l.float.major]=si,t}var Am=vm(),Tm=new qr,ui=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(`${er} object contains circular references`);return new t(r,e)}},gt={null:new g(l.null,null),undefined:new g(l.undefined,void 0),true:new g(l.true,!0),false:new g(l.false,!1),emptyArray:new g(l.array,0),emptyMap:new g(l.map,0)},wt={number(t,e,r,n){return!Number.isInteger(t)||!Number.isSafeInteger(t)?new g(l.float,t):t>=0?new g(l.uint,t):new g(l.negint,t)},bigint(t,e,r,n){return t>=BigInt(0)?new g(l.uint,t):new g(l.negint,t)},Uint8Array(t,e,r,n){return new g(l.bytes,t)},string(t,e,r,n){return new g(l.string,t)},boolean(t,e,r,n){return t?gt.true:gt.false},null(t,e,r,n){return gt.null},undefined(t,e,r,n){return gt.undefined},ArrayBuffer(t,e,r,n){return new g(l.bytes,new Uint8Array(t))},DataView(t,e,r,n){return new g(l.bytes,new Uint8Array(t.buffer,t.byteOffset,t.byteLength))},Array(t,e,r,n){if(!t.length)return r.addBreakTokens===!0?[gt.emptyArray,new g(l.break)]:gt.emptyArray;n=ui.createCheck(n,t);let i=[],o=0;for(let s of t)i[o++]=ci(s,r,n);return r.addBreakTokens?[new g(l.array,t.length),i,new g(l.break)]:[new g(l.array,t.length),i]},Object(t,e,r,n){let i=e!=="Object",o=i?t.keys():Object.keys(t),s=i?t.size:o.length,a;if(s){a=new Array(s),n=ui.createCheck(n,t);let c=!i&&r.ignoreUndefinedProperties,f=0;for(let u of o){let d=i?t.get(u):t[u];c&&d===void 0||(a[f++]=[ci(u,r,n),ci(d,r,n)])}f<s&&(a.length=f)}return a?.length?(Nm(a,r),r.addBreakTokens?[new g(l.map,a.length),a,new g(l.break)]:[new g(l.map,a.length),a]):r.addBreakTokens===!0?[gt.emptyMap,new g(l.break)]:gt.emptyMap}};wt.Map=wt.Object;wt.Buffer=wt.Uint8Array;for(let t of"Uint8Clamped Uint16 Uint32 Int8 Int16 Int32 BigUint64 BigInt64 Float32 Float64".split(" "))wt[`${t}Array`]=wt.DataView;function ci(t,e={},r){let n=nu(t),i=e&&e.typeEncoders&&e.typeEncoders[n]||wt[n];if(typeof i=="function"){let s=i(t,n,e,r);if(s!=null)return s}let o=wt[n];if(!o)throw new Error(`${er} unsupported type: ${n}`);return o(t,n,e,r)}function Nm(t,e){e.mapSorter&&t.sort(e.mapSorter)}function Cm(t,e){if(t[0]instanceof g&&e[0]instanceof g){let r=t[0],n=e[0];return r._keyBytes||(r._keyBytes=of(r.value)),n._keyBytes||(n._keyBytes=of(n.value)),Qn(r._keyBytes,n._keyBytes)}throw new Error("rfc8949MapSorter: complex key types are not supported yet")}function of(t){return cf(t,Am,sf)}function af(t,e,r,n){if(Array.isArray(e))for(let i of e)af(t,i,r,n);else r[e.type.major](t,e,n)}var u1=l.uint.majorEncoded,f1=l.negint.majorEncoded,l1=l.bytes.majorEncoded,d1=l.string.majorEncoded,h1=l.array.majorEncoded,m1=l.float.majorEncoded|Vo,p1=l.float.majorEncoded|jo,y1=l.float.majorEncoded|qo,g1=l.float.majorEncoded|Go,w1=BigInt(-1),x1=BigInt(1);function cf(t,e,r,n){let i=n instanceof Uint8Array,o=i?new ei(n):Tm,s=ci(t,r);if(!Array.isArray(s)&&r.quickEncodeToken){let a=r.quickEncodeToken(s);if(a)return i?(o.push(a),o.toBytes()):a;let c=e[s.type.major];if(c.encodedSize){let f=c.encodedSize(s,r);if(i||(o=new qr(f)),c(o,s,r),o.chunks.length!==1)throw new Error(`Unexpected error: pre-calculated length for ${s} was wrong`);return i?o.toBytes():Lt(o.chunks[0])}}return o.reset(),af(o,s,e,r),o.toBytes(!0)}var Dm={strict:!1,allowIndefinite:!0,allowUndefined:!0,allowBigInt:!0},fi=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=Me[e];if(r===void 0){let n=_[e];if(!n)throw new Error(`${S} no decoder for major type ${e>>>5} (byte 0x${e.toString(16).padStart(2,"0")})`);let i=e&31;r=n(this.data,this._pos,i,this.options)}return this._pos+=r.encodedLength,r}},xt=Symbol.for("DONE"),ir=Symbol.for("BREAK");function Lm(t,e,r){let n=[];for(let i=0;i<t.value;i++){let o=bt(e,r);if(o===ir){if(t.value===1/0)break;throw new Error(`${S} got unexpected break to lengthed array`)}if(o===xt)throw new Error(`${S} found array but not enough entries (got ${i}, expected ${t.value})`);n[i]=o}return n}function Um(t,e,r){let n=r.useMaps===!0,i=r.rejectDuplicateMapKeys===!0,o=n?void 0:{},s=n?new Map:void 0;for(let a=0;a<t.value;a++){let c=bt(e,r);if(c===ir){if(t.value===1/0)break;throw new Error(`${S} got unexpected break to lengthed map`)}if(c===xt)throw new Error(`${S} found map but not enough entries (got ${a} [no key], expected ${t.value})`);if(!n&&typeof c!="string")throw new Error(`${S} non-string keys not supported (got ${typeof c})`);if(i&&(n&&s.has(c)||!n&&Object.hasOwn(o,c)))throw new Error(`${S} found repeat map key "${c}"`);let f=bt(e,r);if(f===xt)throw new Error(`${S} found map but not enough entries (got ${a} [no value], expected ${t.value})`);n?s.set(c,f):o[c]=f}return n?s:o}function*Fm(t,e,r){for(let n=0;n<t.value;n++){let i=bt(e,r);if(i===ir){if(t.value===1/0)break;throw new Error(`${S} got unexpected break to lengthed map`)}if(i===xt)throw new Error(`${S} found map but not enough entries (got ${n} [no key], expected ${t.value})`);let o=bt(e,r);if(o===xt)throw new Error(`${S} found map but not enough entries (got ${n} [no value], expected ${t.value})`);yield[i,o]}}function zm(t,e){let r=!1,n=function(){if(r)throw new Error(`${S} tag decode() may only be called once`);r=!0;let i=bt(t,e);if(i===xt)throw new Error(`${S} tag content missing`);if(i===ir)throw new Error(`${S} got unexpected break in tag content`);return i};return n.entries=function(){if(r)throw new Error(`${S} tag decode() may only be called once`);r=!0;let i=t.next();if(!l.equals(i.type,l.map))throw new Error(`${S} entries() requires map content, got ${i.type.name}`);let o=[];for(let s of Fm(i,t,e))o.push(s);return o},Object.defineProperty(n,"_called",{get(){return r},enumerable:!1}),n}function bt(t,e){if(t.done())return xt;let r=t.next();if(l.equals(r.type,l.break))return ir;if(r.type.terminal)return r.value;if(l.equals(r.type,l.array))return Lm(r,t,e);if(l.equals(r.type,l.map))return Um(r,t,e);if(l.equals(r.type,l.tag)){if(e.tags&&typeof e.tags[r.value]=="function"){let n=zm(t,e),i=e.tags[r.value](n);if(!n._called)throw new Error(`${S} tag decoder must call decode() or entries()`);return i}throw new Error(`${S} tag not supported (${r.value})`)}throw new Error("unsupported")}function Xo(t,e){if(!(t instanceof Uint8Array))throw new Error(`${S} data to decode must be a Uint8Array`);e=Object.assign({},Dm,e);let r=Lt(t),n=e.tokenizer||new fi(r,e),i=bt(n,e);if(i===xt)throw new Error(`${S} did not find any content to decode`);if(i===ir)throw new Error(`${S} got unexpected break`);return[i,t.subarray(n.pos())]}function Yo(t,e){let[r,n]=Xo(t,e);if(n.length>0)throw new Error(`${S} too many terminals, data makes no sense`);return r}var uf=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),i=[];for(let o=0;o<n.length;o++)i[o]=n.charCodeAt(o);e.push(i)}[l.negint.major](e,r){this[l.uint.major](e,r)}[l.bytes.major](e,r){throw new Error(`${er} unsupported type: Uint8Array`)}[l.string.major](e,r){this.prefix(e);let n=jr(JSON.stringify(r.value));e.push(n.length>32?Lt(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(`${er} unsupported type: undefined`);if(this.prefix(e),r.type.name==="true"){e.push([116,114,117,101]);return}else if(r.type.name==="false"){e.push([102,97,108,115,101]);return}else if(r.type.name==="null"){e.push([110,117,108,108]);return}let n=String(r.value),i=[],o=!1;for(let s=0;s<n.length;s++)i[s]=n.charCodeAt(s),!o&&(i[s]===46||i[s]===101||i[s]===69)&&(o=!0);o||(i.push(46),i.push(48)),e.push(i)}};var or=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(`${S} 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(`${S} unexpected token at position ${this._pos}, expected to find '${String.fromCharCode(...e)}'`)}parseNumber(){let e=this._pos,r=!1,n=!1,i=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 g(l.uint,0,this._pos-e);if(i([48,49,50,51,52,53,54,55,56,57]),r&&this._pos===e+1)throw new Error(`${S} unexpected token at position ${this._pos}`);if(!this.done()&&this.ch()===46){if(n)throw new Error(`${S} unexpected token at position ${this._pos}`);n=!0,this._pos++,i([48,49,50,51,52,53,54,55,56,57])}!this.done()&&(this.ch()===101||this.ch()===69)&&(n=!0,this._pos++,!this.done()&&(this.ch()===43||this.ch()===45)&&this._pos++,i([48,49,50,51,52,53,54,55,56,57]));let o=String.fromCharCode.apply(null,this.data.subarray(e,this._pos)),s=parseFloat(o);return n?new g(l.float,s,this._pos-e):this.options.allowBigInt!==!0||Number.isSafeInteger(s)?new g(s>=0?l.uint:l.negint,s,this._pos-e):new g(s>=0?l.uint:l.negint,BigInt(o),this._pos-e)}parseString(){if(this.ch()!==34)throw new Error(`${S} unexpected character at position ${this._pos}; this shouldn't happen`);this._pos++;for(let o=this._pos,s=0;o<this.data.length&&s<65536;o++,s++){let a=this.data[o];if(a===92||a<32||a>=128)break;if(a===34){let c=String.fromCharCode.apply(null,this.data.subarray(this._pos,o));return this._pos=o+1,new g(l.string,c,s)}}let e=this._pos,r=[],n=()=>{if(this._pos+4>=this.data.length)throw new Error(`${S} unexpected end of unicode escape sequence at position ${this._pos}`);let o=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(`${S} unexpected unicode escape character at position ${this._pos}`);o=o*16+a,this._pos++}return o},i=()=>{let o=this.ch(),s=null,a=o>239?4:o>223?3:o>191?2:1;if(this._pos+a>this.data.length)throw new Error(`${S} unexpected unicode sequence at position ${this._pos}`);let c,f,u,d;switch(a){case 1:o<128&&(s=o);break;case 2:c=this.data[this._pos+1],(c&192)===128&&(d=(o&31)<<6|c&63,d>127&&(s=d));break;case 3:c=this.data[this._pos+1],f=this.data[this._pos+2],(c&192)===128&&(f&192)===128&&(d=(o&15)<<12|(c&63)<<6|f&63,d>2047&&(d<55296||d>57343)&&(s=d));break;case 4:c=this.data[this._pos+1],f=this.data[this._pos+2],u=this.data[this._pos+3],(c&192)===128&&(f&192)===128&&(u&192)===128&&(d=(o&15)<<18|(c&63)<<12|(f&63)<<6|u&63,d>65535&&d<1114112&&(s=d))}s===null?(s=65533,a=1):s>65535&&(s-=65536,r.push(s>>>10&1023|55296),s=56320|s&1023),r.push(s),this._pos+=a};for(;!this.done();){let o=this.ch(),s;switch(o){case 92:if(this._pos++,this.done())throw new Error(`${S} 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(`${S} unexpected string escape character at position ${this._pos}`)}break;case 34:return this._pos++,new g(l.string,uu(r),this._pos-e);default:if(o<32)throw new Error(`${S} invalid control character at position ${this._pos}`);o<128?(r.push(o),this._pos++):i()}}throw new Error(`${S} unexpected end of string at position ${this._pos}`)}parseValue(){switch(this.ch()){case 123:return this.modeStack.push("obj-start"),this._pos++,new g(l.map,1/0,1);case 91:return this.modeStack.push("array-start"),this._pos++,new g(l.array,1/0,1);case 34:return this.parseString();case 110:return this.expect([110,117,108,108]),new g(l.null,null,4);case 102:return this.expect([102,97,108,115,101]),new g(l.false,!1,5);case 116:return this.expect([116,114,117,101]),new g(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(`${S} 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 g(l.break,void 0,1);if(this.ch()!==44)throw new Error(`${S} 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 g(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 g(l.break,void 0,1);if(this.ch()!==44)throw new Error(`${S} 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 g(l.break,void 0,1);let e=this.parseString();if(this.skipWhitespace(),this.ch()!==58)throw new Error(`${S} 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(`${S} unexpected parse state at position ${this._pos}; this shouldn't happen`)}}};function Zo(t,e){return e=Object.assign({tokenizer:new or(t,e)},e),Yo(t,e)}function $m(t){return t instanceof ArrayBuffer?new Uint8Array(t,0,t.byteLength):t}var Qo=class extends or{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 i=this._next();if(!l.equals(i.type,l.break))throw new Error("Invalid encoded CID form");return this.tokenBuffer.push(n),new g(l.tag,42,0)}if(l.equals(n.type,l.map)){let i=this._next();if(l.equals(i.type,l.string)&&i.value==="bytes"){let o=this._next();if(l.equals(o.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=kr.decode(`m${o.value}`);return new g(l.bytes,s,o.value.length)}this.tokenBuffer.push(o)}this.tokenBuffer.push(i)}this.tokenBuffer.push(n)}this.tokenBuffer.push(r)}return e}},ff={allowIndefinite:!1,allowUndefined:!1,allowNaN:!1,allowInfinity:!1,allowBigInt:!0,strict:!0,useMaps:!1,rejectDuplicateMapKeys:!0,tags:{42:t=>A.parse(t())}};var li=297;var di=t=>{let e=$m(t),r=Object.assign(ff,{tokenizer:new Qo(e,ff)});return Zo(e,r)};var K1=new TextDecoder;var J1=new TextEncoder;function Mm(t){return t[Symbol.asyncIterator]!=null}function Om(t){if(Mm(t))return(async()=>{let n=new Uint8Array(0);for await(let i of t)n=Ve([n,i],n.length+i.length);return n})();let e=[],r=0;for(let n of t)e.push(n),r+=n.byteLength;return Ve(e,r)}var T=Om;function sr(t){return t==null?!1:A.asCID(t)===t}function ar(t,e){let r,n=0,i="";for(;n<e.length;){let o=e[n];if(n++,!Object.hasOwnProperty.call(t,o))throw new Kt(`Object did not have key "${o}"`);if(i+=`/${o}`,r=t[o],t=r,sr(r))break}return{value:r,rest:e.slice(n),path:i.substring(1)}}async function*es(t,e,r,n){let i=await T(r.get(t,n)),o=Xn(i),s=ar(o,e);yield{cid:sr(s.value)?s.value:t,name:s.path,rest:s.rest}}async function*lf(t,e,r,n){let i=await T(r.get(t,n)),o=di(i),s=ar(o,e);yield{cid:sr(s.value)?s.value:t,name:s.path,rest:s.rest}}var Hm=async function(t){return(await Tt.encode(t)).slice(0,8).reverse()},Vm=async(t,e,r)=>{let n=(e.tableSize()-1).toString(16).length;await Promise.all(t.map(async i=>{if(i.Name==null)throw new Error("Unexpected Link without a Name");if(i.Name.length===n){let o=parseInt(i.Name,16);e._putObjectAt(o,new Ge({hash:r._options.hash,bits:r._options.bits},e,o));return}await r.put(i.Name.substring(2),!0)}))},df=(t,e)=>t.toString(16).toUpperCase().padStart(e,"0").substring(0,e),jm=t=>{let e=t.bucket,r=[];for(;e._parent!=null;)r.push(e),e=e._parent;return r.push(e),r.reverse()};async function*ts(t,e,r,n,i,o){if(i==null){if(t.Data==null)throw new R("No data in PBNode");let m;try{m=B.unmarshal(t.Data)}catch(p){throw new R(p.message)}if(m.type!=="hamt-sharded-directory")throw new R("Not a HAMT");if(m.fanout==null)throw new R("Missing fanout");let y=Nn({hashFn:Hm,bits:Math.log2(Number(m.fanout))});i={rootBucket:y,hamtDepth:1,lastBucket:y}}let s=(i.lastBucket.tableSize()-1).toString(16).length;await Vm(t.Links,i.lastBucket,i.rootBucket);let a=await i.rootBucket._findNewBucketAndPos(e),c=df(a.pos,s),f=jm(a);f.length>i.hamtDepth&&(i.lastBucket=f[i.hamtDepth],c=df(i.lastBucket._posAtParent,s));let u=t.Links.find(m=>{if(m.Name==null)return!1;let y=m.Name.substring(0,s),p=m.Name.substring(s);return!(y!==c||p!==""&&p!==e)});if(u==null)return;if(u.Name!=null&&u.Name.substring(s)===e){yield{cid:u.Hash,name:u.Name.substring(s),rest:r};return}i.hamtDepth++;let d=await T(n.get(u.Hash,o));t=z(d),o?.yieldSubShards===!0&&(yield{cid:u.Hash,name:u.Name??"",rest:[e,...r]}),yield*ts(t,e,r,n,i,o)}async function*hf(t,e,r,n){let i=await T(r.get(t,n)),o;try{o=z(i)}catch(a){throw new R(a.message)}if(o.Data==null)throw new R("no data in PBNode");let s;try{s=B.unmarshal(o.Data)}catch(a){throw new R(a.message)}if(s.type==="directory"||s.type==="hamt-sharded-directory"&&n?.translateHAMTPath===!1){let a=o.Links.find(c=>c.Name===e[0]);if(a==null)throw new he(`No link "${e[0]}" found under ${t}`);yield{cid:a.Hash,name:e[0],rest:e.slice(1)}}else if(s.type==="hamt-sharded-directory"){let a=!1;for await(let c of ts(o,e[0],e.slice(1),r,void 0,n))c.name===e[0]&&(a=!0),yield c;if(!a)throw new he(`No link "${e[0]}" found under ${t}`)}}async function*mf(t,e,r,n){if(e.length!==0)throw new Kt(`Cannot load path /${e.join("/")} from identity block`)}async function*pf(t,e,r,n){let i=await T(r.get(t,n)),o=wn(i),s=ar(o,e);yield{cid:t,name:s.path,rest:s.rest}}async function*yf(t,e,r,n){if(e.length!==0)throw new he(`Cannot load path /${e.join("/")} from raw block`)}var Gm={[W]:hf,[te]:yf,[Jn]:es,81:es,[li]:lf,[Ir.code]:mf,[gn]:pf};async function*mi(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,...i]=t.split(/(?<!\\)\//g).filter(Boolean),o=A.parse(n),s=[o],a=`${o}`;for(yield{cid:o,name:a,path:a,roots:s,remainder:i};i.length>0;){let c=Gm[o.code];if(c==null)throw new Jt(`No resolver for code ${o.code}`);let f=!1;for await(let u of c(o,i,e,r)){if(o=u.cid,f=!s[s.length-1].equals(o),i=u.rest,!f)break;s=[...s,u.cid],a=`${a}/${u.name}`,yield{cid:u.cid,name:u.name,path:a,roots:s,remainder:u.rest}}if(!f)break}if(r?.signal?.throwIfAborted(),i.length!==0)throw new he(`Could not resolve path /${i.join("/")} under ${t}`)}async function rs(t,e,r,n,i){let o=await T(n.get(t,i)),s=Xn(o);return{type:"object",cid:t,name:e,path:r,object:s,node:o}}async function gf(t,e,r,n,i){let o=await T(n.get(t,i)),s=di(o);return{type:"object",cid:t,name:e,path:r,object:s,node:o}}function Jr(t,e,r,n){let i=BigInt(t.length),o=BigInt(e+i);return r>=o||n<e?new Uint8Array(0):(n>=e&&n<o&&(t=t.subarray(0,Number(n-e))),r>=e&&r<o&&(t=t.subarray(Number(r-e))),t)}var pi=(t,e=0,r=t)=>{let n=BigInt(t),i=BigInt(e??0),o=BigInt(r);if(o!==n&&(o=i+o),o>n&&(o=n),i<0n)throw new et("Offset must be greater than or equal to 0");if(i>n)throw new et("Offset must be less than the file size");if(o<0n)throw new et("Length must be greater than or equal to 0");if(o>n)throw new et("Length must be less than the file size");return{start:i,end:o}};function yi(t,e){async function*r(n={}){let{start:i,end:o}=pi(t.length,n.offset,n.length),s=Jr(t,0n,i,o);n.onProgress?.(new K(e,{bytesRead:BigInt(s.byteLength),totalBytes:o-i,fileSize:BigInt(t.byteLength)})),yield s}return r}async function wf(t,e,r,n,i){let o=an(t.multihash.bytes);return{type:"identity",cid:t,name:e,path:r,content:yi(o.digest,"unixfs:exporter:progress:identity"),size:BigInt(o.bytes.length),node:o.bytes}}async function xf(t,e,r,n,i){let o=await T(n.get(t,i)),s=wn(o);return{type:"object",cid:t,name:e,path:r,object:s,node:o}}async function bf(t,e,r,n,i){let o=await T(n.get(t,i));return{type:"raw",cid:t,name:e,path:r,content:yi(o,"unixfs:exporter:progress:raw"),size:BigInt(o.length),node:o}}function _f(t,e,r,n){async function*i(o={}){let s=o.offset??0,a=o.length??e.Links.length,c=e.Links.slice(s,a);o.onProgress?.(new K("unixfs:exporter:walk:directory",{cid:t})),yield*c.map(f=>({cid:f.Hash,name:f.Name??"",path:`${n}/${f.Name??""}`}))}return i}function Wm(t){let[e,r]=t[Symbol.asyncIterator]!=null?[t[Symbol.asyncIterator](),Symbol.asyncIterator]:[t[Symbol.iterator](),Symbol.iterator],n=[];return{peek:()=>e.next(),push:i=>{n.push(i)},next:()=>n.length>0?{done:!1,value:n.shift()}:e.next(),[r](){return this}}}var Ef=Wm;function Km(t){return t[Symbol.asyncIterator]!=null}function Jm(t,e){let r=0;if(Km(t))return(async function*(){for await(let c of t)yield e(c,r++)})();let n=Ef(t),{value:i,done:o}=n.next();if(o===!0)return(function*(){})();let s=e(i,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 cr=Jm;function ae(){let t={};return t.promise=new Promise((e,r)=>{t.resolve=e,t.reject=r}),t}var gi=globalThis.CustomEvent??Event;async function*Xr(t,e={}){let r=e.concurrency??1/0;r<1&&(r=1/0);let n=e.ordered??!1,i=new EventTarget,o=[],s=ae(),a=ae(),c=!1,f,u=!1;i.addEventListener("task-complete",()=>{a.resolve()}),Promise.resolve().then(async()=>{try{for await(let p of t){if(o.length===r&&(s=ae(),await s.promise),u)break;let w={done:!1};o.push(w),p().then(x=>{w.done=!0,w.ok=!0,w.value=x,i.dispatchEvent(new gi("task-complete"))},x=>{w.done=!0,w.err=x,i.dispatchEvent(new gi("task-complete"))})}c=!0,i.dispatchEvent(new gi("task-complete"))}catch(p){f=p,i.dispatchEvent(new gi("task-complete"))}});function d(){return n?o[0]?.done:!!o.find(p=>p.done)}function*m(){for(;o.length>0&&o[0].done;){let p=o[0];if(o.shift(),p.ok)yield p.value;else throw u=!0,s.resolve(),p.err;s.resolve()}}function*y(){for(;d();)for(let p=0;p<o.length;p++)if(o[p].done){let w=o[p];if(o.splice(p,1),p--,w.ok)yield w.value;else throw u=!0,s.resolve(),w.err;s.resolve()}}for(;;){if(d()||(a=ae(),await a.promise),f!=null||(n?yield*m():yield*y(),f!=null))throw f;if(c&&o.length===0)break}}var wi=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}},ur=class{size;hwm;head;tail;constructor(e={}){this.hwm=e.splitLimit??16,this.head=new wi(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 wi(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 ns=class extends Error{type;code;constructor(e,r){super(e??"The operation was aborted"),this.type="aborted",this.code=r??"ABORT_ERR"}};function xi(t={}){return Xm(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 Xm(t,e){e=e??{};let r=e.onEnd,n=new ur,i,o,s,a=ae(),c=async()=>{try{return n.isEmpty()?s?{done:!0}:await new Promise((x,k)=>{o=v=>{o=null,n.push(v);try{x(t(n))}catch(N){k(N)}return i}}):t(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=ae()})}},f=x=>o!=null?o(x):(n.push(x),i),u=x=>(n=new ur,o!=null?o({error:x}):(n.push({error:x}),i)),d=x=>{if(s)return i;if(e?.objectMode!==!0&&x?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return f({done:!1,value:x})},m=x=>s?i:(s=!0,x!=null?u(x):f({done:!0})),y=()=>(n=new ur,m(),{done:!0}),p=x=>(m(x),{done:!0});if(i={[Symbol.asyncIterator](){return this},next:c,return:y,throw:p,push:d,end:m,get readableLength(){return n.size},onEmpty:async x=>{let k=x?.signal;if(k?.throwIfAborted(),n.isEmpty())return;let v,N;k!=null&&(v=new Promise((F,H)=>{N=()=>{H(new ns)},k.addEventListener("abort",N)}));try{await Promise.race([a.promise,v])}finally{N!=null&&k!=null&&k?.removeEventListener("abort",N)}}},r==null)return i;let w=i;return i={[Symbol.asyncIterator](){return this},next(){return w.next()},throw(x){return w.throw(x),r!=null&&(r(x),r=void 0),{done:!0}},return(){return w.return(),r!=null&&(r(),r=void 0),{done:!0}},push:d,end(x){return w.end(x),r!=null&&(r(x),r=void 0),i},get readableLength(){return w.readableLength},onEmpty:x=>w.onEmpty(x)},i}function Ym(t){return t.reason}async function Sf(t,e,r){if(e==null)return t;let n=r?.translateError??Ym;if(e.aborted)return t.catch(()=>{}),Promise.reject(n(e));let i;try{return await Promise.race([t,new Promise((o,s)=>{i=()=>{s(n(e))},e.addEventListener("abort",i)})])}finally{i!=null&&e.removeEventListener("abort",i)}}var is=class{readNext;haveNext;ended;nextResult;error;constructor(){this.ended=!1,this.readNext=ae(),this.haveNext=ae()}[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=ae(),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=ae(),await Sf(this.readNext.promise,r?.signal,r)}};function kf(){return new is}function Zm(t){return t[Symbol.asyncIterator]!=null}async function Qm(t,e,r){try{await Promise.all(t.map(async n=>{for await(let i of n)await e.push(i,{signal:r}),r.throwIfAborted()})),await e.end(void 0,{signal:r})}catch(n){await e.end(n,{signal:r}).catch(()=>{})}}async function*ep(t){let e=new AbortController,r=kf();Qm(t,r,e.signal).catch(()=>{});try{yield*r}finally{e.abort()}}function*tp(t){for(let e of t)yield*e}function rp(...t){let e=[];for(let r of t)Zm(r)||e.push(r);return e.length===t.length?tp(e):ep(t)}var Bf=rp;function _t(t,...e){if(t==null)throw new Error("Empty pipeline");if(os(t)){let n=t;t=()=>n.source}else if(vf(t)||If(t)){let n=t;t=()=>n}let r=[t,...e];if(r.length>1&&os(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++)os(r[n])&&(r[n]=ip(r[n]));return np(...r)}var np=(...t)=>{let e;for(;t.length>0;)e=t.shift()(e);return e},If=t=>t?.[Symbol.asyncIterator]!=null,vf=t=>t?.[Symbol.iterator]!=null,os=t=>t==null?!1:t.sink!=null&&t.source!=null,ip=t=>e=>{let r=t.sink(e);if(r?.then!=null){let n=xi({objectMode:!0});r.then(()=>{n.end()},s=>{n.end(s)});let i,o=t.source;if(If(o))i=async function*(){yield*o,n.end()};else if(vf(o))i=function*(){yield*o,n.end()};else throw new Error("Unknown duplex source type - must be Iterable or AsyncIterable");return Bf(n,i())}return t.source};var as=on(Tf(),1);var cs=class t extends Error{name="TimeoutError";constructor(e,r){super(e,r),Error.captureStackTrace?.(this,t)}},Nf=t=>t.reason??new DOMException("This operation was aborted.","AbortError");function us(t,e){let{milliseconds:r,fallback:n,message:i,customTimers:o={setTimeout,clearTimeout},signal:s}=e,a,c,u=new Promise((d,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(Nf(s));return}if(s&&(c=()=>{m(Nf(s))},s.addEventListener("abort",c,{once:!0})),t.then(d,m),r===Number.POSITIVE_INFINITY)return;let y=new cs;a=o.setTimeout.call(void 0,()=>{if(n){try{d(n())}catch(p){m(p)}return}typeof t.cancel=="function"&&t.cancel(),i===!1?d():i instanceof Error?m(i):(y.message=i??`Promise timed out after ${r} milliseconds`,m(y))},r)}).finally(()=>{u.clear(),c&&s&&s.removeEventListener("abort",c)});return u.clear=()=>{o.clearTimeout.call(void 0,a),a=void 0},u}function fs(t,e,r){let n=0,i=t.length;for(;i>0;){let o=Math.trunc(i/2),s=n+o;r(t[s],e)<=0?(n=++s,i-=o+1):i=o}return n}var fr=class{#e=[];enqueue(e,r){let{priority:n=0,id:i}=r??{},o={priority:n,id:i,run:e};if(this.size===0||this.#e[this.size-1].priority>=n){this.#e.push(o);return}let s=fs(this.#e,o,(a,c)=>c.priority-a.priority);this.#e.splice(s,0,o)}setPriority(e,r){let n=this.#e.findIndex(o=>o.id===e);if(n===-1)throw new ReferenceError(`No promise function with the id "${e}" exists in the queue.`);let[i]=this.#e.splice(n,1);this.enqueue(i.run,{priority:r,id:e})}remove(e){let r=this.#e.findIndex(n=>typeof e=="string"?n.id===e:n.run===e);r!==-1&&this.#e.splice(r,1)}dequeue(){return this.#e.shift()?.run}filter(e){return this.#e.filter(r=>r.priority===e.priority).map(r=>r.run)}get size(){return this.#e.length}};var Zr=class extends as.default{#e;#r;#i=0;#c;#u=!1;#d=!1;#f;#v=0;#b=0;#l;#h;#a;#s=[];#o=0;#t;#A;#n=0;#g;#m;#L=1n;#w=new Map;#_=new Set;timeout;constructor(e){if(super(),e={carryoverIntervalCount:!1,intervalCap:Number.POSITIVE_INFINITY,interval:0,concurrency:Number.POSITIVE_INFINITY,autoStart:!0,queueClass:fr,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.#r=e.intervalCap===Number.POSITIVE_INFINITY||e.interval===0,this.#c=e.intervalCap,this.#f=e.interval,this.#a=e.strict,this.#t=new e.queueClass,this.#A=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.#m=e.autoStart===!1,this.#O()}#E(e){for(;this.#o<this.#s.length;){let n=this.#s[this.#o];if(n!==void 0&&e-n>=this.#f)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++}#F(){this.#a?this.#s.length>this.#o&&this.#s.pop():this.#i>0&&this.#i--}#S(){return this.#s.length-this.#o}get#z(){return this.#r?!0:this.#a?this.#S()<this.#c:this.#i<this.#c}get#P(){return this.#n<this.#g}#R(){this.#n--,this.#n===0&&this.emit("pendingZero"),this.#x(),this.emit("next")}#$(){this.#h=void 0,this.#C(),this.#N()}#M(e){if(this.#a){if(this.#E(e),this.#S()>=this.#c){let n=this.#s[this.#o],i=this.#f-(e-n);return this.#k(i),!0}return!1}if(this.#l===void 0){let r=this.#v-e;if(r<0){if(this.#b>0){let n=e-this.#b;if(n<this.#f)return this.#k(this.#f-n),!0}this.#i=this.#e?this.#n:0}else return this.#k(r),!0}return!1}#k(e){this.#h===void 0&&(this.#h=setTimeout(()=>{this.#$()},e))}#B(){this.#l&&(clearInterval(this.#l),this.#l=void 0)}#T(){this.#h&&(clearTimeout(this.#h),this.#h=void 0)}#x(){if(this.#t.size===0){if(this.#B(),this.emit("empty"),this.#n===0){if(this.#T(),this.#a&&this.#o>0){let r=Date.now();this.#E(r)}this.emit("idle")}return!1}let e=!1;if(!this.#m){let r=Date.now(),n=!this.#M(r);if(this.#z&&this.#P){let i=this.#t.dequeue();this.#r||(this.#U(r),this.#y()),this.emit("active"),i(),n&&this.#N(),e=!0}}return e}#N(){this.#r||this.#l!==void 0||this.#a||(this.#l=setInterval(()=>{this.#C()},this.#f),this.#v=Date.now()+this.#f)}#C(){this.#a||(this.#i===0&&this.#n===0&&this.#l&&this.#B(),this.#i=this.#e?this.#n:0),this.#I(),this.#y()}#I(){for(;this.#x(););}get concurrency(){return this.#g}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.#g=e,this.#I()}setPriority(e,r){if(typeof r!="number"||!Number.isFinite(r))throw new TypeError(`Expected \`priority\` to be a finite number, got \`${r}\` (${typeof r})`);this.#t.setPriority(e,r)}async add(e,r={}){return r={timeout:this.timeout,...r,id:r.id??(this.#L++).toString()},new Promise((n,i)=>{let o=Symbol(`task-${r.id}`),s=()=>{},a=async()=>{s(),this.#n++,this.#w.set(o,{id:r.id,priority:r.priority??0,startTime:Date.now(),timeout:r.timeout});let f;try{try{r.signal?.throwIfAborted()}catch(m){throw this.#H(),this.#w.delete(o),m}this.#b=Date.now();let u=e({signal:r.signal});if(r.timeout&&(u=us(Promise.resolve(u),{milliseconds:r.timeout,message:`Task timed out after ${r.timeout}ms (queue has ${this.#n} running, ${this.#t.size} waiting)`})),r.signal){let{signal:m}=r;u=Promise.race([u,new Promise((y,p)=>{f=()=>{p(m.reason)},m.addEventListener("abort",f,{once:!0})})])}let d=await u;n(d),this.emit("completed",d)}catch(u){i(u),this.emit("error",u)}finally{f&&r.signal?.removeEventListener("abort",f),this.#w.delete(o),queueMicrotask(()=>{this.#R()})}};this.#t.enqueue(a,r);let c=()=>{if(this.#t instanceof fr){this.#t.remove(a);return}this.#t.remove?.(r.id)};if(r.signal){let{signal:f}=r,u=()=>{s(),c(),i(f.reason),this.#x(),this.emit("next")};if(s=()=>{f.removeEventListener("abort",u),this.#_.delete(s)},f.aborted){u();return}f.addEventListener("abort",u,{once:!0}),this.#_.add(s)}this.emit("add"),this.#x()})}async addAll(e,r){return Promise.all(e.map(async n=>this.add(n,r)))}start(){return this.#m?(this.#m=!1,this.#I(),this):this}pause(){this.#m=!0}clear(){for(let e of this.#_)e();this.#t=new this.#A,this.#B(),this.#D(),this.emit("empty"),this.#n===0&&(this.#T(),this.emit("idle")),this.emit("next")}async onEmpty(){this.#t.size!==0&&await this.#p("empty")}async onSizeLessThan(e){this.#t.size<e||await this.#p("next",()=>this.#t.size<e)}async onIdle(){this.#n===0&&this.#t.size===0||await this.#p("idle")}async onPendingZero(){this.#n!==0&&await this.#p("pendingZero")}async onRateLimit(){this.isRateLimited||await this.#p("rateLimit")}async onRateLimitCleared(){this.isRateLimited&&await this.#p("rateLimitCleared")}onError(){return new Promise((e,r)=>{let n=i=>{this.off("error",n),r(i)};this.on("error",n)})}async#p(e,r){return new Promise(n=>{let i=()=>{r&&!r()||(this.off(e,i),n())};this.on(e,i)})}get size(){return this.#t.size}sizeBy(e){return this.#t.filter(e).length}get pending(){return this.#n}get isPaused(){return this.#m}#O(){this.#r||(this.on("add",()=>{this.#t.size>0&&this.#y()}),this.on("next",()=>{this.#y()}))}#y(){this.#r||this.#d||(this.#d=!0,queueMicrotask(()=>{this.#d=!1,this.#D()}))}#H(){this.#r||(this.#F(),this.#y())}#D(){let e=this.#u;if(this.#r||this.#t.size===0){e&&(this.#u=!1,this.emit("rateLimitCleared"));return}let r;if(this.#a){let i=Date.now();this.#E(i),r=this.#S()}else r=this.#i;let n=r>=this.#c;n!==e&&(this.#u=n,this.emit(n?"rateLimit":"rateLimitCleared"))}get isRateLimited(){return this.#u}get isSaturated(){return this.#n===this.#g&&this.#t.size>0||this.isRateLimited&&this.#t.size>0}get runningTasks(){return[...this.#w.values()].map(e=>({...e}))}};async function Cf(t,e,r,n,i,o,s){if(e instanceof Uint8Array){let f=Jr(e,n,i,o);r.push(f);return}if(e.Data==null)throw new R("no data in PBNode");let a;try{a=B.unmarshal(e.Data)}catch(f){throw new R(f.message)}if(a.data!=null){let f=a.data,u=Jr(f,n,i,o);r.push(u),n+=BigInt(u.byteLength)}let c=[];if(e.Links.length!==a.blockSizes.length)throw new R("Inconsistent block sizes and dag links");for(let f=0;f<e.Links.length;f++){let u=e.Links[f],d=n,m=d+a.blockSizes[f];if((i>=d&&i<m||o>=d&&o<=m||i<d&&o>m)&&c.push({link:u,blockStart:n}),n=m,n>o)break}await _t(c,f=>cr(f,u=>async()=>{let d=await T(t.get(u.link.Hash,s));return{...u,block:d}}),f=>Xr(f,{ordered:!0,concurrency:s.blockReadConcurrency}),async f=>{for await(let{link:u,block:d,blockStart:m}of f){let y;switch(u.Hash.code){case W:y=z(d);break;case te:y=d;break;default:r.end(new R(`Unsupported codec: ${u.Hash.code}`));return}let p=new Zr({concurrency:1});p.on("error",w=>{r.end(w)}),p.add(async()=>{s.onProgress?.(new K("unixfs:exporter:walk:file",{cid:u.Hash})),await Cf(t,y,r,m,i,o,s)}),await p.onIdle()}}),n>=o&&r.end()}function ls(t,e,r,n,i){async function*o(s={}){let a=r.fileSize();if(a===void 0)throw new Error("File was a directory");let{start:c,end:f}=pi(a,s.offset,s.length);if(f===0n)return;let u=0n,d=f-c,m=xi();s.onProgress?.(new K("unixfs:exporter:walk:file",{cid:t})),Cf(i,e,m,0n,c,f,s).catch(y=>{m.end(y)});for await(let y of m)if(y!=null){if(u+=BigInt(y.byteLength),u>d)throw m.end(),new Un("Read too many bytes - the file size reported by the UnixFS data in the root node may be incorrect");u===d&&m.end(),s.onProgress?.(new K("unixfs:exporter:progress:unixfs:file",{bytesRead:u,totalBytes:d,fileSize:a})),yield y}if(u<d)throw new Fn("Traversed entire DAG but did not read enough bytes")}return o}async function*Df(t,e,r,n){let i=t.Links;if(t.Data==null)throw new R("no data in PBNode");let o;try{o=B.unmarshal(t.Data)}catch(c){throw new R(c.message)}if(o.fanout==null)throw new R("missing fanout");let s=(o.fanout-1n).toString(16).length,a=_t(i,c=>cr(c,f=>async()=>{let u=f.Name!=null?f.Name.substring(s):null;if(u!=null&&u!=="")return{entries:[{cid:f.Hash,name:u,path:`${e}/${u}`}]};{let d=await T(r.get(f.Hash,n));return t=z(d),n.onProgress?.(new K("unixfs:exporter:walk:hamt-sharded-directory",{cid:f.Hash})),{entries:Df(t,e,r,n)}}}),c=>Xr(c,{ordered:!0,concurrency:n.blockReadConcurrency}));for await(let{entries:c}of a)yield*c}function Lf(t,e,r,n,i){function o(s={}){return s.onProgress?.(new K("unixfs:exporter:walk:hamt-sharded-directory",{cid:t})),Df(e,n,i,s)}return o}var ap={raw:ls,file:ls,directory:_f,"hamt-sharded-directory":Lf,metadata:(t,e,r,n)=>()=>[],symlink:(t,e,r,n)=>()=>[]};async function Uf(t,e,r,n,i){let o=await T(n.get(t,i)),s;try{s=z(o)}catch(f){throw new R(f.message)}if(s.Data==null)throw new R("no data in PBNode");let a;try{a=B.unmarshal(s.Data)}catch(f){throw new R(f.message)}let c=ap[a.type](t,s,a,r,n);if(c==null)throw new he("could not find content exporter");return a.isDirectory()?{type:"directory",cid:t,name:e,path:r,entries:c,unixfs:a,node:s}:{type:"file",cid:t,name:e,path:r,content:c,unixfs:a,node:s,size:a.fileSize()}}var cp={[W]:Uf,[te]:bf,[Jn]:rs,81:rs,[li]:gf,[Ir.code]:wf,[gn]:xf};async function j(t,e,r={}){let n,i;if(t instanceof String||typeof t=="string"){let s=await Fe(mi(t,e,r));if(s==null)throw new he(`Could not walk path to ${t}`);n=s.cid,i=s.name,t=s.path}else if(A.asCID(t)===t||t instanceof A)n=t,i=t=n.toString();else throw new et("Path must be string or CID");let o=cp[n.code];if(o==null)throw new Jt(`No resolver for code ${n.code}`);return o(n,i,t,e,r)}async function*_i(t,e,r={}){let n=await j(t,e,r);if(n==null)return;if(yield{cid:n.cid,name:n.name,path:n.path,depth:0},n.type==="directory")for await(let o of i(n,0,`${t}`,r))yield o;async function*i(o,s,a,c){s++;for await(let f of o.entries(c)){let u=`${a}/${f.name}`;yield{...f,depth:s,path:u};let d=await j(f.cid,e,c);d.type==="directory"&&(yield*i(d,s,u,c))}}}function up(t,e){if(typeof t=="string")return fp(t);if(typeof t=="number")return hp(t,e);throw Error(`Value provided to ms() must be a string or number. value=${JSON.stringify(t)}`)}var Ei=up;function fp(t){if(typeof t!="string"||t.length===0||t.length>100)throw Error(`Value provided to ms.parse() must be a string with length between 1 and 99. value=${JSON.stringify(t)}`);let e=/^(?<value>-?\d*\.?\d+) *(?<unit>milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|months?|mo|years?|yrs?|y)?$/i.exec(t);if(!e?.groups)return NaN;let{value:r,unit:n="ms"}=e.groups,i=parseFloat(r),o=n.toLowerCase();switch(o){case"years":case"year":case"yrs":case"yr":case"y":return i*315576e5;case"months":case"month":case"mo":return i*26298e5;case"weeks":case"week":case"w":return i*6048e5;case"days":case"day":case"d":return i*864e5;case"hours":case"hour":case"hrs":case"hr":case"h":return i*36e5;case"minutes":case"minute":case"mins":case"min":case"m":return i*6e4;case"seconds":case"second":case"secs":case"sec":case"s":return i*1e3;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return i;default:throw Error(`Unknown unit "${o}" provided to ms.parse(). value=${JSON.stringify(t)}`)}}function lp(t){let e=Math.abs(t);return e>=315576e5?`${Math.round(t/315576e5)}y`:e>=26298e5?`${Math.round(t/26298e5)}mo`:e>=6048e5?`${Math.round(t/6048e5)}w`:e>=864e5?`${Math.round(t/864e5)}d`:e>=36e5?`${Math.round(t/36e5)}h`:e>=6e4?`${Math.round(t/6e4)}m`:e>=1e3?`${Math.round(t/1e3)}s`:`${t}ms`}function dp(t){let e=Math.abs(t);return e>=315576e5?Ft(t,e,315576e5,"year"):e>=26298e5?Ft(t,e,26298e5,"month"):e>=6048e5?Ft(t,e,6048e5,"week"):e>=864e5?Ft(t,e,864e5,"day"):e>=36e5?Ft(t,e,36e5,"hour"):e>=6e4?Ft(t,e,6e4,"minute"):e>=1e3?Ft(t,e,1e3,"second"):`${t} ms`}function hp(t,e){if(typeof t!="number"||!Number.isFinite(t))throw Error("Value provided to ms.format() must be of type number.");return e?.long?dp(t):lp(t)}function Ft(t,e,r,n){let i=e>=r*1.5;return`${Math.round(t/r)} ${n}${i?"s":""}`}function ds(t){r.debug=r,r.default=r,r.coerce=c,r.disable=o,r.enable=i,r.enabled=s,r.humanize=Ei,r.destroy=f,Object.keys(t).forEach(u=>{r[u]=t[u]}),r.names=[],r.skips=[],r.formatters={};function e(u){let d=0;for(let m=0;m<u.length;m++)d=(d<<5)-d+u.charCodeAt(m),d|=0;return r.colors[Math.abs(d)%r.colors.length]}r.selectColor=e;function r(u,d){let m,y=null,p,w;function x(...k){if(!x.enabled)return;let v=x,N=Number(new Date),F=N-(m||N);v.diff=F,v.prev=m,v.curr=N,m=N,k[0]=r.coerce(k[0]),typeof k[0]!="string"&&k.unshift("%O");let H=0;k[0]=k[0].replace(/%([a-zA-Z%])/g,(J,Te)=>{if(J==="%%")return"%";H++;let St=r.formatters[Te];if(typeof St=="function"){let cl=k[H];J=St.call(v,cl),k.splice(H,1),H--}return J}),r.formatArgs.call(v,k),d?.onLog!=null&&d.onLog(...k),(v.log||r.log).apply(v,k)}return x.namespace=u,x.useColors=r.useColors(),x.color=r.selectColor(u),x.extend=n,x.destroy=r.destroy,Object.defineProperty(x,"enabled",{enumerable:!0,configurable:!1,get:()=>y!==null?y:(p!==r.namespaces&&(p=r.namespaces,w=r.enabled(u)),w),set:k=>{y=k}}),typeof r.init=="function"&&r.init(x),x}function n(u,d){let m=r(this.namespace+(typeof d>"u"?":":d)+u);return m.log=this.log,m}function i(u){r.save(u),r.namespaces=u,r.names=[],r.skips=[];let d,m=(typeof u=="string"?u:"").split(/[\s,]+/),y=m.length;for(d=0;d<y;d++)m[d]&&(u=m[d].replace(/\*/g,".*?"),u[0]==="-"?r.skips.push(new RegExp("^"+u.substr(1)+"$")):r.names.push(new RegExp("^"+u+"$")))}function o(){let u=[...r.names.map(a),...r.skips.map(a).map(d=>"-"+d)].join(",");return r.enable(""),u}function s(u){if(u[u.length-1]==="*")return!0;let d,m;for(d=0,m=r.skips.length;d<m;d++)if(r.skips[d].test(u))return!1;for(d=0,m=r.names.length;d<m;d++)if(r.names[d].test(u))return!0;return!1}function a(u){return u.toString().substring(2,u.toString().length-2).replace(/\.\*\?$/,"*")}function c(u){return u instanceof Error?u.stack??u.message:u}function f(){console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.")}return r.setupFormatters(r.formatters),r.enable(r.load()),r}var Si=bp(),mp=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"];function pp(){return typeof window<"u"&&window.process&&(window.process.type==="renderer"||window.process.__nwjs)?!0:typeof navigator<"u"&&navigator.userAgent?.toLowerCase().match(/(edge|trident)\/(\d+)/)!=null?!1:typeof document<"u"&&document.documentElement?.style?.WebkitAppearance||typeof window<"u"&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||typeof navigator<"u"&&navigator.userAgent?.toLowerCase().match(/firefox\/(\d+)/)!=null&&parseInt(RegExp.$1,10)>=31||typeof navigator<"u"&&navigator.userAgent?.toLowerCase().match(/applewebkit\/(\d+)/)}function yp(t){if(t[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+t[0]+(this.useColors?"%c ":" ")+"+"+Ei(this.diff),!this.useColors)return;let e="color: "+this.color;t.splice(1,0,e,"color: inherit");let r=0,n=0;t[0].replace(/%[a-zA-Z%]/g,i=>{i!=="%%"&&(r++,i==="%c"&&(n=r))}),t.splice(n,0,e)}var gp=console.debug??console.log??(()=>{});function wp(t){try{t?Si?.setItem("debug",t):Si?.removeItem("debug")}catch{}}function xp(){let t;try{t=Si?.getItem("debug")}catch{}return!t&&typeof globalThis.process<"u"&&"env"in globalThis.process&&(t=globalThis.process.env.DEBUG),t}function bp(){try{return localStorage}catch{}}function _p(t){t.j=function(e){try{return JSON.stringify(e)}catch(r){return"[UnexpectedJSONParseError]: "+r.message}}}var Ff=ds({formatArgs:yp,save:wp,load:xp,useColors:pp,setupFormatters:_p,colors:mp,storage:Si,log:gp});var ce=Ff;ce.formatters.b=t=>t==null?"undefined":Ee.baseEncode(t);ce.formatters.t=t=>t==null?"undefined":st.baseEncode(t);ce.formatters.m=t=>t==null?"undefined":kr.baseEncode(t);ce.formatters.p=t=>t==null?"undefined":t.toString();ce.formatters.c=t=>t==null?"undefined":t.toString();ce.formatters.k=t=>t==null?"undefined":t.toString();ce.formatters.a=t=>t==null?"undefined":t.toString();function zf(t,e=""){let r=Pf(t.message),n=Pf(t.stack);return r!=null&&n!=null?n.includes(r)?`${n.split(`
3
3
  `).join(`
4
- ${e}`)}`:`${t}
4
+ ${e}`)}`:`${r}
5
5
  ${e}${n.split(`
6
6
  `).join(`
7
7
  ${e}`)}`:n!=null?`${n.split(`
8
8
  `).join(`
9
- ${e}`)}`:t!=null?`${t}`:`${r.toString()}`}function Ch(r){return r instanceof AggregateError||r?.name==="AggregateError"&&Array.isArray(r.errors)}function xc(r,e=""){if(Ch(r)){let t=gc(r,e);return r.errors.length>0?(e=`${e} `,t+=`
10
- ${e}${r.errors.map(n=>`${xc(n,`${e}`)}`).join(`
11
- ${e}`)}`):t+=`
12
- ${e}[Error list was empty]`,t.trim()}return gc(r,e)}te.formatters.e=r=>r==null?"undefined":xc(r);function Nh(r){let e=()=>{};return e.enabled=!1,e.color="",e.diff=0,e.log=()=>{},e.namespace=r,e.destroy=()=>!0,e.extend=()=>e,e}function M(r,e){let t=Nh(`${r}:trace`);return te.enabled(`${r}:trace`)&&te.names.map(n=>n.toString()).find(n=>n.includes(":trace"))!=null&&(t=te(`${r}:trace`,e)),Object.assign(te(r,e),{error:te(`${r}:error`,e),trace:t,newScope:n=>M(`${r}:${n}`,e)})}function wc(r){if(r!=null&&(r=r.trim(),r.length!==0))return r}var io=vr(Vr(),1);function Nn(r){function e(t){return t instanceof Cn?t:new Cn(t,r)}return e}var Cn=class{_value;_hashFn;_depth;_availableBits;_currentBufferIndex;_buffers;constructor(e,t){if(!(e instanceof Uint8Array))throw new Error("can only hash Uint8Arrays");this._value=e,this._hashFn=t,this._depth=-1,this._availableBits=0,this._currentBufferIndex=0,this._buffers=[]}async take(e){let t=e;for(;this._availableBits<t;)await this._produceMoreBits();let n=0;for(;t>0;){let i=this._buffers[this._currentBufferIndex],o=Math.min(i.availableBits(),t),s=i.take(o);n=(n<<o)+s,t-=o,this._availableBits-=o,i.availableBits()===0&&this._currentBufferIndex++}return n}untake(e){let t=e;for(;t>0;){let n=this._buffers[this._currentBufferIndex],i=Math.min(n.totalBits()-n.availableBits(),t);n.untake(i),t-=i,this._availableBits+=i,this._currentBufferIndex>0&&n.totalBits()===n.availableBits()&&(this._depth--,this._currentBufferIndex--)}}async _produceMoreBits(){this._depth++;let e=this._depth>0?Ce([this._value,Uint8Array.from([this._depth])]):this._value,t=await this._hashFn(e),n=new to(t);this._buffers.push(n),this._availableBits+=n.availableBits()}},Ah=[255,254,252,248,240,224,192,128],Th=[1,3,7,15,31,63,127,255],to=class{_value;_currentBytePos;_currentBitPos;constructor(e){this._value=e,this._currentBytePos=e.length-1,this._currentBitPos=7}availableBits(){return this._currentBitPos+1+this._currentBytePos*8}totalBits(){return this._value.length*8}take(e){let t=e,n=0;for(;t>0&&this._haveBits();){let i=this._value[this._currentBytePos],o=this._currentBitPos+1,s=Math.min(o,t),a=Dh(i,o-s,s);n=(n<<s)+a,t-=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 Dh(r,e,t){let n=Lh(e,t);return(r&n)>>>e}function Lh(r,e){return Ah[r]&Th[Math.min(e+r-1,7)]}var xr=BigInt(nt.code),ut=8;async function zt(r){return(await nt.encode(r)).subarray(0,8).reverse()}var Sc=vr(Vr(),1);var Be=async(r,e,t)=>{t.codec==null&&(t.codec=$);let n=await ie.digest(r),i=E.create(t.cidVersion??1,t.codec.code,n);return await e.put(i,r,{...t,signal:t.signal}),i};var ro=class{options;root;dir;path;dirty;flat;parent;parentKey;unixfs;mode;mtime;cid;size;nodeSize;constructor(e,t){this.options=t??{},this.root=e.root,this.dir=e.dir,this.path=e.path,this.dirty=e.dirty,this.flat=e.flat,this.parent=e.parent,this.parentKey=e.parentKey,this.unixfs=e.unixfs,this.mode=e.mode,this.mtime=e.mtime}},An=class extends ro{_bucket;constructor(e,t){super(e,t),this._bucket=St({hashFn:zt,bits:8})}async put(e,t){this.cid=void 0,this.size=void 0,this.nodeSize=void 0,await this._bucket.put(e,t)}async get(e){return this._bucket.get(e)}childCount(){return this._bucket.leafCount()}directChildrenCount(){return this._bucket.childrenCount()}onlyChild(){return this._bucket.onlyChild()}async*eachChildSeries(){for(let{key:e,value:t}of this._bucket.eachLeafSeries())yield{key:e,child:t}}estimateNodeSize(){return this.nodeSize!==void 0?this.nodeSize:(this.nodeSize=_c(this._bucket,this,this.options),this.nodeSize)}async*flush(e){for await(let t of bc(this._bucket,e,this,this.options))yield{...t,path:this.path}}};async function*bc(r,e,t,n){let i=r._children,o=[],s=0n;for(let p=0;p<i.length;p++){let m=i.get(p);if(m==null)continue;let w=p.toString(16).toUpperCase().padStart(2,"0");if(m instanceof oe){let g;for await(let b of bc(m,e,null,n))g=b;if(g==null)throw new Error("Could not flush sharded directory, no sub-shard found");o.push({Name:w,Tsize:Number(g.size),Hash:g.cid}),s+=g.size}else if(zh(m.value)){let g=m.value,b;for await(let v of g.flush(e))b=v,yield b;if(b==null)throw new Error("Did not flush dir");let k=w+m.key;o.push({Name:k,Tsize:Number(b.size),Hash:b.cid}),s+=b.size}else{let g=m.value;if(g.cid==null)continue;let b=w+m.key,k=g.size;o.push({Name:b,Tsize:Number(k),Hash:g.cid}),s+=BigInt(k??0)}}let a=Uint8Array.from(i.bitField().reverse()),c=new S({type:"hamt-sharded-directory",data:a,fanout:BigInt(r.tableSize()),hashType:xr,mtime:t?.mtime,mode:t?.mode}),f={Data:c.marshal(),Links:o},u=I(z(f)),l=await Be(u,e,n),d=BigInt(u.byteLength)+s;yield{cid:l,unixfs:c,size:d}}function zh(r){return typeof r.flush=="function"}function _c(r,e,t){let n=r._children,i=[];for(let c=0;c<n.length;c++){let f=n.get(c);if(f==null)continue;let u=c.toString(16).toUpperCase().padStart(2,"0");if(f instanceof oe){let l=_c(f,null,t);i.push({Name:u,Tsize:Number(l),Hash:t.cidVersion===0?Tn:Dn})}else if(typeof f.value.flush=="function"){let d=f.value.nodeSize();i.push({Name:u+f.key,Tsize:Number(d),Hash:t.cidVersion===0?Tn:Dn})}else{let l=f.value;if(l.cid==null)continue;let d=u+f.key,p=l.size;i.push({Name:d,Tsize:Number(p),Hash:l.cid})}}let o=Uint8Array.from(n.bitField().reverse()),s=new S({type:"hamt-sharded-directory",data:o,fanout:BigInt(r.tableSize()),hashType:xr,mtime:e?.mtime,mode:e?.mode});return I(z({Data:s.marshal(),Links:i})).length}var Tn=E.parse("QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn"),Dn=E.parse("zdj7WbTaiJT1fgatdet9Ei9iDB5hdCxkbVyhyh8YTUnXMiwYi");var no=M("helia:unixfs:commands:utils:hamt-utils"),Ln=r=>r.toString(16).toUpperCase().padStart(2,"0").substring(0,2),kc=async(r,e,t)=>{let n=new An({root:!0,dir:!0,parent:void 0,parentKey:void 0,path:"",dirty:!0,flat:!1,mtime:t.mtime,mode:t.mode},t);for(let o=0;o<e.length;o++)await n._bucket.put(e[o].name,{size:e[o].size,cid:e[o].cid});let i=await Se(n.flush(r));if(i==null)throw new Error("Flushing shard yielded no result");return i},Fn=async(r,e,t)=>{let n=S.unmarshal(r[0].node.Data??new Uint8Array(0)),i=BigInt(Math.pow(2,ut));r.reverse();let o,s;for(let a=0;a<r.length;a++){let c=a===r.length-1,f=r[a],u=Uint8Array.from(f.children.bitField().reverse()),l=new S({type:"hamt-sharded-directory",data:u,fanout:i,hashType:xr});c&&(l.mtime=n.mtime,l.mode=n.mode),s={Data:l.marshal(),Links:f.node.Links};let d=I(z(s));if(o=await Be(d,e,t),!c){let p=r[a+1];if(p==null)throw new Error("Was not operating on shard root but also had no parent?");no("updating link in parent sub-shard with prefix %s",p.prefix),p.node.Links=p.node.Links.filter(m=>m.Name!==p.prefix),p.node.Links.push({Name:p.prefix,Hash:o,Tsize:f.node.Links.reduce((m,w)=>m+(w.Tsize??0),d.byteLength)})}}if(o==null||s==null)throw new Error("Noting persisted");return{cid:o,node:s}},zn=async(r,e,t,n)=>{let o=Nn(zt)(P(e)),s=[];for(;;){let a=await B(t.get(r,n)),c=D(a),f=new Sc.default,u=await o.take(ut),l=Ln(u);s.push({prefix:l,children:f,node:c});let d;for(let m of c.Links){let w=m.Name??"";if(w.length<2)throw new Error("Invalid HAMT - link name was too short");let g=parseInt(w.substring(0,2),16);f.set(g,!0),w.startsWith(l)&&(d=m)}if(d==null){no("no link found with prefix %s for %s",l,e);break}let p=d.Name??"";if(p.length<2)throw new Error("Invalid HAMT - link name was too short");if(p.length===2){r=d.Hash,no("descend into sub-shard with prefix %s",p);continue}break}return{path:s,hash:o}};async function Pn(r,e,t,n){if(r.Data==null)throw new Error("DagPB node had no data");let i=S.unmarshal(r.Data),o;if(i.type==="directory")o=Ph(r);else if(i.type==="hamt-sharded-directory")o=await Ec(r,0,t,e,n);else throw new Error("Can only estimate the size of directories or shards");return o>t}function Ph(r){let e=0;for(let t of r.Links)e+=(t.Name??"").length,e+=t.Hash.version===1?Dn.bytes.byteLength:Tn.bytes.byteLength;return e}async function Ec(r,e,t,n,i){if(e>t)return t;if(r.Data==null||!S.unmarshal(r.Data).isDirectory())return e;for(let s of r.Links){let a=s.Name??"";if(a=a.substring(2),e+=a.length,e+=s.Hash.bytes.byteLength,s.Hash.code===H){let c=await B(n.get(s.Hash,i)),f=D(c);e+=await Ec(f,e,t,n,i)}}return e}var De=M("helia:unixfs:components:utils:add-link");async function Pt(r,e,t,n){if(r.node.Data==null)throw new L("Invalid parent passed to addLink");if(S.unmarshal(r.node.Data).type==="hamt-sharded-directory")return De("adding link to sharded directory"),Mh(r,e,t,n);De(`adding ${e.Name} (${e.Hash}) to regular directory`);let o=await Rh(r,e,t,n);if(await Pn(o.node,t,n.shardSplitThresholdBytes??262144,n)){De("converting directory to sharded directory");let s=await $h(o,t);o.cid=s.cid,o.node=D(await B(t.get(s.cid,n)))}return o}var $h=async(r,e)=>{if(r.node.Data==null)throw new L("Invalid parent passed to convertToShardedDirectory");let t=S.unmarshal(r.node.Data),n=await kc(e,r.node.Links.map(i=>({name:i.Name??"",size:BigInt(i.Tsize??0),cid:i.Hash})),{mode:t.mode,mtime:t.mtime,cidVersion:r.cid.version});return De(`converted directory to sharded directory ${n.cid}`),n},Rh=async(r,e,t,n)=>{let i=r.node.Links.filter(u=>{let l=u.Name===e.Name;if(l&&!n.allowOverwriting)throw new ot;return!l});if(i.push(e),r.node.Data==null)throw new Q("Parent node with no data passed to addToDirectory");let o=S.unmarshal(r.node.Data),s;if(o.mtime!=null){let u=Date.now(),l=Math.floor(u/1e3);o.mtime={secs:BigInt(l),nsecs:(u-l*1e3)*1e3},s=o.marshal()}else s=r.node.Data;r.node=z({Data:s,Links:i});let a=I(r.node),c=await ie.digest(a),f=E.create(r.cid.version,H,c);return await t.put(f,a),{node:r.node,cid:f}},Mh=async(r,e,t,n)=>{let{path:i,hash:o}=await zn(r.cid,e.Name,t,n),s=i[i.length-1];if(s==null)throw new Error("Invalid HAMT, could not generate path");let a=s.prefix,c=parseInt(a,16);De("next prefix for %s is %s",e.Name,a);let f=`${a}${e.Name}`,u=s.node.Links.find(l=>(l.Name??"").startsWith(a));if(u!=null)if(De("link %s was present in shard",f),u.Name===f){if(!n.allowOverwriting)throw new ot;De("overwriting %s in sub-shard",e.Name),s.node.Links=s.node.Links.filter(l=>l.Name!==f),s.node.Links.push({Name:f,Hash:e.Hash,Tsize:e.Tsize})}else{if(u.Name?.length===2)throw new Error("Existing link was sub-shard?!");{De("prefix %s already exists, creating new sub-shard",a);let l=s.node.Links.findIndex(g=>g.Name?.startsWith(a)),d=s.node.Links.splice(l,1)[0],p=(d.Name??"").substring(2),w=Nn(zt)(P(p));for(let g=0;g<i.length;g++)await w.take(ut);for(;;){let g=await w.take(ut),b=Ln(g);d.Name=`${b}${p}`;let k=await o.take(ut),v=Ln(k);if(b===v){let O=new io.default;O.set(k,!0),i.push({prefix:v,children:O,node:{Links:[]}});continue}let U=new io.default;U.set(k,!0),U.set(g,!0),i.push({prefix:a,children:U,node:{Links:[d,{Name:`${v}${e.Name}`,Hash:e.Hash,Tsize:e.Tsize}]}});break}}}else De("link %s was not present in sub-shard",f),e.Name=f,s.node.Links.push(e),s.children.set(c,!0),De("adding %s to existing sub-shard",f);return Fn(i,t,n)};async function Xe(r,e,t={}){let n=await R(r,e,t);if(n.type!=="directory")throw new Ge(`${r.toString()} was not a UnixFS directory`);return{cid:r,node:n.node}}async function Ut(r,e,t,n){let i=await R(r,t,n);if(i.type!=="directory"&&i.type!=="file"&&i.type!=="raw")throw new Ae(`${r.toString()} was not a UnixFS node`);return{Name:e,Tsize:i.node instanceof Uint8Array?i.node.byteLength:Oh(i.node),Hash:r}}function Oh(r){let e=r.Links.reduce((t,n)=>t+(n.Tsize??0),0);return I(r).byteLength+e}var Vh=M("helia:unixfs:components:utils:resolve");async function Le(r,e,t,n){if(e==null||e==="")return{cid:r};let i=`/ipfs/${r}${e==null?"":`/${e}`}`,o=await ps(wn(i,t,n));if(o.length===0)throw new ze("Could not find path in directory");return Vh("resolved %s to %c",e,r),{cid:o[o.length-1].cid,path:e,segments:o}}async function $t(r,e,t,n){if(e.segments==null||e.segments.length===0)return r;let i=e.segments.pop();if(i==null)throw new Error("Insufficient segments");i.cid=r,e.segments.reverse();for(let o of e.segments){let[s,a]=await Promise.all([Xe(o.cid,t,n),Ut(i.cid,i.name,t,n)]);r=(await Pt(s,a,t,{...n,allowOverwriting:!0,cidVersion:r.version})).cid,o.cid=r,i=o}return r}async function*vc(r,e,t={}){let n=await Le(r,t.path,e,t),i=await R(n.cid,e,t);if(i.type!=="file"&&i.type!=="raw")throw new Gr;if(i.content==null)throw new qr;yield*i.content(t)}var Hh=M("helia:unixfs:chmod");async function Bc(r,e,t,n={}){let i=await Le(r,n.path,t,n);if(Hh("chmod %c %d",i.cid,e),n.recursive===!0){let l=await Ke(async function*(){for await(let d of vn(i.cid,t,n)){let p,m=[],w=await R(d.cid,t,n);if(w.type==="raw")p=new S({type:"file",data:w.node});else if(w.type==="file"||w.type==="directory")p=w.unixfs,m=w.node.Links;else throw new Ae;p.mode=e;let g={Data:p.marshal(),Links:m};yield{path:d.path,content:g}}},d=>it(d,t,{...n,dagBuilder:async function*(p,m){for await(let w of p)yield async function(){let g=w.content,b=I(g),k=await Be(b,m,{...n,cidVersion:r.version});if(g.Data==null)throw new Q(`${k} had no data`);let v=S.unmarshal(g.Data);return{cid:k,size:BigInt(b.length),path:w.path,unixfs:v}}}}),async d=>Se(d));if(l==null)throw new qe(`Could not chmod ${i.cid.toString()}`);return $t(l.cid,i,t,n)}let o=await B(t.get(i.cid,n)),s,a=[];if(i.cid.code===W)s=new S({type:"file",data:o});else{let l=D(o);if(l.Data==null)throw new Q(`${i.cid.toString()} had no data`);a=l.Links,s=S.unmarshal(l.Data)}s.mode=e;let c=I({Data:s.marshal(),Links:a}),f=await ie.digest(c),u=E.create(i.cid.version,H,f);return await t.put(u,c),$t(u,i,t,n)}var jh=M("helia:unixfs:cp");async function Ic(r,e,t,n,i={}){if(t.includes("/"))throw new L("Name must not have slashes");let[o,s]=await Promise.all([Xe(e,n,i),Ut(r,t,n,i)]);return jh('Adding %c as "%s" to %c',r,t,e),(await Pt(o,s,n,{allowOverwriting:i.force,cidVersion:e.version,...i})).cid}async function*Cc(r,e,t={}){let n=await Le(r,t.path,e,t),i=await R(n.cid,e,t);if(i.type==="directory"){yield*i.entries(t);return}yield i}var Nc=M("helia:unixfs:mkdir");async function Ac(r,e,t,n={}){if(e.includes("/"))throw new L("Path must not have slashes");if((await R(r,t,n)).type!=="directory")throw new Ge(`${r.toString()} was not a UnixFS directory`);Nc("creating %s",e);let s={Data:new S({type:"directory",mode:n.mode,mtime:n.mtime}).marshal(),Links:[]},a=I(s),c=await ie.digest(a),f=E.create(n.cidVersion??1,H,c);await t.put(f,a);let[u,l]=await Promise.all([Xe(r,t,n),Ut(f,e,t,n)]);return Nc("adding empty dir called %s to %c",e,r),(await Pt(u,l,t,{...n,allowOverwriting:n.force})).cid}var Un=M("helia:unixfs:utils:remove-link");async function Tc(r,e,t,n){if(r.node.Data==null)throw new Q("Parent node had no data");if(S.unmarshal(r.node.Data).type==="hamt-sharded-directory"){Un(`removing ${e} from sharded directory`);let o=await Gh(r,e,t,n);return await Pn(o.node,t,n.shardSplitThresholdBytes??262144,n)?o:(Un("converting shard to flat directory %c",r.cid),Wh(o,t,n))}return Un(`removing link ${e} regular directory`),qh(r,e,t,n)}var qh=async(r,e,t,n)=>{r.node.Links=r.node.Links.filter(s=>s.Name!==e);let i=I(r.node),o=await Be(i,t,{...n,cidVersion:r.cid.version});return Un(`Updated regular directory ${o}`),{node:r.node,cid:o}},Gh=async(r,e,t,n)=>{let{path:i}=await zn(r.cid,e,t,n),o=i[i.length-1];if(o==null)throw new Error("Invalid HAMT, could not generate path");let s=o.node.Links.filter(f=>(f.Name??"").substring(2)===e).map(f=>f.Name).pop();if(s==null)throw new Error("File not found");let a=s.substring(0,2),c=parseInt(a,16);if(o.node.Links=o.node.Links.filter(f=>f.Name!==s),o.children.unset(c),o.node.Links.length===1)for(;i.length!==1;){let f=i[i.length-1];if(f==null||f.node.Links.length>1)break;i.pop();let u=i[i.length-1];if(u==null)break;let l=f.node.Links[0];u.node.Links=u.node.Links.filter(d=>!(d.Name??"").startsWith(u.prefix)),u.node.Links.push({Hash:l.Hash,Name:`${u.prefix}${(l.Name??"").substring(2)}`,Tsize:l.Tsize})}return Fn(i,t,n)},Wh=async(r,e,t)=>{if(r.node.Data==null)throw new L("Invalid parent passed to convertToFlatDirectory");let n={Links:[]},i=await R(r.cid,e,t);if(i.type!=="directory")throw new Error("Unexpected node type");for await(let c of i.entries()){let f=0,u=await R(c.cid,e,t);u.node instanceof Uint8Array?f=u.node.byteLength:f=I(u.node).length,n.Links.push({Hash:c.cid,Name:c.name,Tsize:f})}let o=S.unmarshal(r.node.Data);n.Data=new S({type:"directory",mode:o.mode,mtime:o.mtime}).marshal();let s=I(z(n));return{cid:await Be(s,e,{codec:$,cidVersion:r.cid.version,signal:t.signal}),node:n}};var Jh=M("helia:unixfs:rm");async function Dc(r,e,t,n={}){if(e.includes("/"))throw new L("Name must not have slashes");let i=await Xe(r,t,n);return Jh("Removing %s from %c",e,r),(await Tc(i,e,t,{...n,cidVersion:r.version})).cid}function Lc(r,e="utf8"){let t=Ur[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.encoder.encode(r).substring(1)}var oo={32:16777619n,64:1099511628211n,128:309485009821345068724781371n,256:374144419156711147060143317175368453031918731002211n,512:35835915874844867368919076489095108449946327955754392558399825615420669938882575126094039892345713852759n,1024:5016456510113118655434598811035278955030765345404790744303017523831112055108147451509157692220295382716162651878526895249385292291816524375083746691371804094271873160484737966720260389217684476157468082573n},Fc={32:2166136261n,64:14695981039346656037n,128:144066263297769815596495629667062367629n,256:100029257958052580907070968620625704837092796014241193945225284501741471925557n,512:9659303129496669498009435400716310466090418745672637896108374329434462657994582932197716438449813051892206539805784495328239340083876191928701583869517785n,1024:14197795064947621068722070641403218320880622795441933960878474914617582723252296732303717722150864096521202355549365628174669108571814760471015076148029755969804077320157692458563003215304957150157403644460363550505412711285966361610267868082893823963790439336411086884584107735010676915n},zc=new globalThis.TextEncoder;function Kh(r,e){let t=oo[e],n=Fc[e];for(let i=0;i<r.length;i++)n^=BigInt(r[i]),n=BigInt.asUintN(e,n*t);return n}function Xh(r,e,t){if(t.length===0)throw new Error("The `utf8Buffer` option must have a length greater than zero");let n=oo[e],i=Fc[e],o=r;for(;o.length>0;){let s=zc.encodeInto(o,t);o=o.slice(s.read);for(let a=0;a<s.written;a++)i^=BigInt(t[a]),i=BigInt.asUintN(e,i*n)}return i}function so(r,{size:e=32,utf8Buffer:t}={}){if(!oo[e])throw new Error("The `size` option must be one of 32, 64, 128, 256, 512, or 1024");if(typeof r=="string"){if(t)return Xh(r,e,t);r=zc.encode(r)}return Kh(r,e)}var br={hash:r=>Number(so(r,{size:32})),hashV:(r,e)=>Yh(br.hash(r,e))};function Yh(r){let e=r.toString(16);return e.length%2===1&&(e=`0${e}`),P(e,"base16")}var Pc=64,Ie=class{fp;h;seed;constructor(e,t,n,i=2){if(i>Pc)throw new TypeError("Invalid Fingerprint Size");let o=t.hashV(e,n),s=ge(i);for(let a=0;a<s.length;a++)s[a]=o[a];s.length===0&&(s[0]=7),this.fp=s,this.h=t,this.seed=n}hash(){return this.h.hash(this.fp,this.seed)}equals(e){return e?.fp instanceof Uint8Array?Ar(this.fp,e.fp):!1}};function ft(r,e){return Math.floor(Math.random()*(e-r))+r}var lt=class{contents;constructor(e){this.contents=new Array(e).fill(null)}has(e){if(!(e instanceof Ie))throw new TypeError("Invalid Fingerprint");return this.contents.some(t=>e.equals(t))}add(e){if(!(e instanceof Ie))throw new TypeError("Invalid Fingerprint");for(let t=0;t<this.contents.length;t++)if(this.contents[t]==null)return this.contents[t]=e,!0;return!0}swap(e){if(!(e instanceof Ie))throw new TypeError("Invalid Fingerprint");let t=ft(0,this.contents.length-1),n=this.contents[t];return this.contents[t]=e,n}remove(e){if(!(e instanceof Ie))throw new TypeError("Invalid Fingerprint");let t=this.contents.findIndex(n=>e.equals(n));return t>-1?(this.contents[t]=null,!0):!1}};var Zh=500,_r=class{bucketSize;filterSize;fingerprintSize;buckets;count;hash;seed;constructor(e){this.filterSize=e.filterSize,this.bucketSize=e.bucketSize??4,this.fingerprintSize=e.fingerprintSize??2,this.count=0,this.buckets=[],this.hash=e.hash??br,this.seed=e.seed??ft(0,Math.pow(2,10))}add(e){typeof e=="string"&&(e=P(e));let t=new Ie(e,this.hash,this.seed,this.fingerprintSize),n=this.hash.hash(e,this.seed)%this.filterSize,i=(n^t.hash())%this.filterSize;if(this.buckets[n]==null&&(this.buckets[n]=new lt(this.bucketSize)),this.buckets[i]==null&&(this.buckets[i]=new lt(this.bucketSize)),this.buckets[n].add(t)||this.buckets[i].add(t))return this.count++,!0;let o=[n,i],s=o[ft(0,o.length-1)];this.buckets[s]==null&&(this.buckets[s]=new lt(this.bucketSize));for(let a=0;a<Zh;a++){let c=this.buckets[s].swap(t);if(c!=null&&(s=(s^c.hash())%this.filterSize,this.buckets[s]==null&&(this.buckets[s]=new lt(this.bucketSize)),this.buckets[s].add(c)))return this.count++,!0}return!1}has(e){typeof e=="string"&&(e=P(e));let t=new Ie(e,this.hash,this.seed,this.fingerprintSize),n=this.hash.hash(e,this.seed)%this.filterSize,i=this.buckets[n]?.has(t)??!1;if(i)return i;let o=(n^t.hash())%this.filterSize;return this.buckets[o]?.has(t)??!1}remove(e){typeof e=="string"&&(e=P(e));let t=new Ie(e,this.hash,this.seed,this.fingerprintSize),n=this.hash.hash(e,this.seed)%this.filterSize,i=this.buckets[n]?.remove(t)??!1;if(i)return this.count--,i;let o=(n^t.hash())%this.filterSize,s=this.buckets[o]?.remove(t)??!1;return s&&this.count--,s}get reliable(){return Math.floor(100*(this.count/this.filterSize))<=90}};var Sr=class{filterSize;bucketSize;fingerprintSize;scale;filterSeries;hash;seed;constructor(e){this.bucketSize=e.bucketSize??4,this.filterSize=e.filterSize??(1<<18)/this.bucketSize,this.fingerprintSize=e.fingerprintSize??2,this.scale=e.scale??2,this.hash=e.hash??br,this.seed=e.seed??ft(0,Math.pow(2,10)),this.filterSeries=[new _r({filterSize:this.filterSize,bucketSize:this.bucketSize,fingerprintSize:this.fingerprintSize,hash:this.hash,seed:this.seed})]}add(e){if(typeof e=="string"&&(e=P(e)),this.has(e))return!0;let t=this.filterSeries.find(n=>n.reliable);if(t==null){let n=this.filterSize*Math.pow(this.scale,this.filterSeries.length);t=new _r({filterSize:n,bucketSize:this.bucketSize,fingerprintSize:this.fingerprintSize,hash:this.hash,seed:this.seed}),this.filterSeries.push(t)}return t.add(e)}has(e){typeof e=="string"&&(e=P(e));for(let t=0;t<this.filterSeries.length;t++)if(this.filterSeries[t].has(e))return!0;return!1}remove(e){typeof e=="string"&&(e=P(e));for(let t=0;t<this.filterSeries.length;t++)if(this.filterSeries[t].remove(e))return!0;return!1}get count(){return this.filterSeries.reduce((e,t)=>e+t.count,0)}};var Uc=1877,$n=1604,Qh=M("helia:unixfs:stat");async function $c(r,e,t={}){let n=await Le(r,t.path,e,t);Qh("stat %c",n.cid);let i=await R(n.cid,e,t);if(i.type==="raw")return t.extended===!0?nd(i):rd(i);if(i.type==="file"||i.type==="directory")return t.extended===!0?td(i,e,t.filter??new Sr({filterSize:1024}),t):ed(i);throw new Ae}function ed(r){return{type:r.type,cid:r.cid,unixfs:r.unixfs,mode:r.unixfs.mode??(r.unixfs.isDirectory()?Uc:$n),mtime:r.unixfs.mtime,size:r.unixfs.fileSize()}}async function td(r,e,t,n){let i=await Rc(r.cid,e,!1,t,n);return{type:r.type,cid:r.cid,unixfs:r.unixfs,size:r.unixfs.isDirectory()?i.dirSize:r.unixfs.fileSize(),mode:r.unixfs.mode??(r.unixfs.isDirectory()?Uc:$n),mtime:r.unixfs.mtime,localSize:i.localSize,dagSize:i.dagSize,deduplicatedDagSize:i.deduplicatedDagSize,blocks:i.blocks,uniqueBlocks:i.uniqueBlocks}}function rd(r){return{type:r.type,cid:r.cid,unixfs:void 0,mode:$n,mtime:void 0,size:BigInt(r.node.byteLength)}}function nd(r){return{type:r.type,cid:r.cid,unixfs:void 0,mode:$n,mtime:void 0,size:BigInt(r.node.byteLength),localSize:BigInt(r.node.byteLength),dagSize:BigInt(r.node.byteLength),deduplicatedDagSize:BigInt(r.node.byteLength),blocks:1n,uniqueBlocks:1n}}async function Rc(r,e,t,n,i){let o={dirSize:0n,localSize:0n,dagSize:0n,deduplicatedDagSize:0n,blocks:0n,uniqueBlocks:0n};try{let s=n.has(r.bytes);n.add(r.bytes);let a=await B(e.get(r,i));if(o.blocks++,o.dagSize+=BigInt(a.byteLength),s||(o.uniqueBlocks++,o.deduplicatedDagSize+=BigInt(a.byteLength)),r.code===W)o.localSize+=BigInt(a.byteLength),t&&(o.dirSize+=BigInt(a.byteLength));else if(r.code===H){let c=D(a),f;if(c.Data!=null&&(f=S.unmarshal(c.Data)),c.Links.length>0){for(let u of c.Links){let l=await Rc(u.Hash,e,id(u,f),n,i);o.localSize+=l.localSize,o.dagSize+=l.dagSize,o.deduplicatedDagSize+=l.deduplicatedDagSize,o.blocks+=l.blocks,o.uniqueBlocks+=l.uniqueBlocks,o.dirSize+=l.dirSize}t&&f!=null&&(o.dirSize+=f.fileSize())}else{if(f==null)throw new Q(`PBNode ${r.toString()} had no data`);f.data!=null&&(o.localSize+=BigInt(f.data.byteLength??0)),t&&(o.dirSize+=f.fileSize())}}else throw new qe(`${r.toString()} was neither DAG_PB nor RAW`)}catch(s){if(s.name!=="NotFoundError"&&s.name!=="BlockNotFoundWhileOfflineError"||i.offline!==!0)throw s}return o}function id(r,e){if(e==null)return!1;let t=r.Name;return t==null?!1:e.type==="directory"?!0:e.type==="hamt-sharded-directory"&&t.length>2}var od=M("helia:unixfs:touch");async function Mc(r,e,t={}){let n=await Le(r,t.path,e,t),i=t.mtime??{secs:BigInt(Math.round(Date.now()/1e3)),nsecs:0};if(od("touch %c %o",n.cid,i),t.recursive){let l=await Ke(async function*(){for await(let d of vn(n.cid,e)){let p,m,w=await R(d.cid,e,t);if(w.type==="raw")p=new S({data:w.node}),m=[];else if(w.type==="file"||w.type==="directory")p=w.unixfs,m=w.node.Links;else throw new Ae;p.mtime=i;let g={Data:p.marshal(),Links:m};yield{path:d.path,content:g}}},d=>it(d,e,{...t,dagBuilder:async function*(p,m){for await(let w of p)yield async function(){let g=w.content,b=I(g),k=await Be(b,m,{...t,cidVersion:r.version});if(g.Data==null)throw new Q(`${k} had no data`);let v=S.unmarshal(g.Data);return{cid:k,size:BigInt(b.length),path:w.path,unixfs:v}}}}),async d=>Se(d));if(l==null)throw new qe(`Could not chmod ${n.cid.toString()}`);return $t(l.cid,n,e,t)}let o=await B(e.get(n.cid,t)),s,a=[];if(n.cid.code===W)s=new S({data:o});else{let l=D(o);if(a=l.Links,l.Data==null)throw new Q(`${n.cid.toString()} had no data`);s=S.unmarshal(l.Data)}s.mtime=i;let c=I({Data:s.marshal(),Links:a}),f=await ie.digest(c),u=E.create(n.cid.version,H,f);return await e.put(u,c),$t(u,n,e,t)}var Rn=class{components;constructor(e){this.components=e}async*addAll(e,t={}){yield*Wr(e,this.components.blockstore,t)}async addBytes(e,t={}){return Fs(e,this.components.blockstore,t)}async addByteStream(e,t={}){return zs(e,this.components.blockstore,t)}async addFile(e,t={}){return Ps(e,this.components.blockstore,t)}async addDirectory(e={},t={}){return Us(e,this.components.blockstore,t)}async*cat(e,t={}){yield*vc(e,this.components.blockstore,t)}async chmod(e,t,n={}){return Bc(e,t,this.components.blockstore,n)}async cp(e,t,n,i={}){return Ic(e,t,n,this.components.blockstore,i)}async*ls(e,t={}){yield*Cc(e,this.components.blockstore,t)}async mkdir(e,t,n={}){return Ac(e,t,this.components.blockstore,n)}async rm(e,t,n={}){return Dc(e,t,this.components.blockstore,n)}async stat(e,t={}){return $c(e,this.components.blockstore,t)}async touch(e,t={}){return Mc(e,this.components.blockstore,t)}};function Oc(r){return new Rn(r)}var $e="/",Vc=new TextEncoder().encode($e),Mn=Vc[0],kr=class r{_buf;constructor(e,t){if(typeof e=="string")this._buf=P(e);else if(e instanceof Uint8Array)this._buf=e;else throw new Error("Invalid key, should be String of Uint8Array");if(t==null&&(t=!0),t&&this.clean(),this._buf.byteLength===0||this._buf[0]!==Mn)throw new Error("Invalid key")}toString(e="utf8"){return Lc(this._buf,e)}uint8Array(){return this._buf}get[Symbol.toStringTag](){return`Key(${this.toString()})`}static withNamespaces(e){return new r(e.join($e))}static random(){return new r(Math.random().toString().substring(2))}static asKey(e){return e instanceof Uint8Array||typeof e=="string"?new r(e):typeof e.uint8Array=="function"?new r(e.uint8Array()):null}clean(){if((this._buf==null||this._buf.byteLength===0)&&(this._buf=Vc),this._buf[0]!==Mn){let e=new Uint8Array(this._buf.byteLength+1);e.fill(Mn,0,1),e.set(this._buf,1),this._buf=e}for(;this._buf.byteLength>1&&this._buf[this._buf.byteLength-1]===Mn;)this._buf=this._buf.subarray(0,-1)}less(e){let t=this.list(),n=e.list();for(let i=0;i<t.length;i++){if(n.length<i+1)return!1;let o=t[i],s=n[i];if(o<s)return!0;if(o>s)return!1}return t.length<n.length}reverse(){return r.withNamespaces(this.list().slice().reverse())}namespaces(){return this.list()}baseNamespace(){let e=this.namespaces();return e[e.length-1]}list(){return this.toString().split($e).slice(1)}type(){return sd(this.baseNamespace())}name(){return ad(this.baseNamespace())}instance(e){return new r(this.toString()+":"+e)}path(){let e=this.parent().toString();return e.endsWith($e)||(e+=$e),e+=this.type(),new r(e)}parent(){let e=this.list();return e.length===1?new r($e):new r(e.slice(0,-1).join($e))}child(e){return this.toString()===$e?e:e.toString()===$e?this:new r(this.toString()+e.toString(),!1)}isAncestorOf(e){return e.toString()===this.toString()?!1:e.toString().startsWith(this.toString())}isDecendantOf(e){return e.toString()===this.toString()?!1:this.toString().startsWith(e.toString())}isTopLevel(){return this.list().length===1}concat(...e){return r.withNamespaces([...this.namespaces(),...cd(e.map(t=>t.namespaces()))])}};function sd(r){let e=r.split(":");return e.length<2?"":e.slice(0,-1).join(":")}function ad(r){let e=r.split(":");return e[e.length-1]}function cd(r){return[].concat(...r)}function On(r){return r.split("/").pop()??""}var Vn=class{components;unixfs;root;key;log;constructor(e,t={}){this.components=e,this.log=e.logger.forComponent("helia:mfs"),this.key=new kr(t.key??"/locals/filesroot"),this.unixfs=Oc(e)}async#e(){if(this.root==null)try{let e=await this.components.datastore.get(this.key);this.root=E.decode(e)}catch(e){if(e.name!=="NotFoundError")throw e;this.root=await this.unixfs.addDirectory()}return this.root}async writeBytes(e,t,n){let i=await this.unixfs.addBytes(e,n);await this.cp(i,t,n),n?.mode!=null&&await this.chmod(t,n.mode,n),n?.mtime!=null&&await this.touch(t,n)}async writeByteStream(e,t,n){let i=await this.unixfs.addByteStream(e,n);await this.cp(i,t,n),n?.mode!=null&&await this.chmod(t,n.mode,n),n?.mtime!=null&&await this.touch(t,n)}async*cat(e,t={}){let n=await this.#e(),i=await this.#r(n,e,{...t,createMissingDirectories:!1,finalSegmentMustBeDirectory:!1});yield*this.unixfs.cat(i[i.length-1].cid,t)}async chmod(e,t,n={}){let i=await this.#e();this.root=await this.unixfs.chmod(i,t,{...n,path:e})}async cp(e,t,n){let i=await this.#e(),o=n?.force??!1;typeof e=="string"&&(e=(await this.stat(e,n)).cid),o||await this.#u(t,n);let s=On(t),a=t.substring(0,t.length-`/${s}`.length),c=[{cid:i,name:""}];a!==""&&(c=await this.#r(i,a,{...n,createMissingDirectories:n?.force??!1,finalSegmentMustBeDirectory:!0})),c.push({cid:e,name:s}),this.root=await this.#i(c,n)}async*ls(e,t){let n=await this.#e();t?.path!=null&&(e=`${e}/${t.path}`);let i=n.toString();yield*Lt(this.unixfs.ls(n,{...t,path:e}),o=>{let s=o.path.split("/").slice(1).join("/");return s.startsWith(i)&&(s=s.substring(0,i.length)),{...o,path:`${e==="/"?"":e}/${s}`}})}async mkdir(e,t){let n=t?.force??!1;n||await this.#u(e,t);let i=On(e),o=e.substring(0,e.length-`/${i}`.length),s=await this.#e(),a=[{cid:s,name:""}];o!==""&&(a=await this.#r(s,o,{...t,createMissingDirectories:n,finalSegmentMustBeDirectory:!0})),a.push({cid:await this.unixfs.addDirectory({mode:t?.mode,mtime:t?.mtime},t),name:On(e)}),this.root=await this.#i(a,t)}async rm(e,t){(t?.force??!1)||await this.#c(e,t);let i=await this.#e(),o=await this.#r(i,e,{...t,createMissingDirectories:!1,finalSegmentMustBeDirectory:!1}),s=o.pop();if(s==null)throw new L("path was too short");let a=o[o.length-1];a.cid=await this.unixfs.rm(a.cid,s.name,t),this.root=await this.#i(o,t)}async stat(e,t){let n=await this.#e(),o=(await this.#r(n,e,{...t,createMissingDirectories:!1,finalSegmentMustBeDirectory:!1})).pop();if(o==null)throw new ze;return this.unixfs.stat(o.cid,t)}async touch(e,t){let n=await this.#e(),i=await this.#r(n,e,{...t,createMissingDirectories:!1,finalSegmentMustBeDirectory:!1}),o=i[i.length-1];if(o==null)throw new ze;o.cid=await this.unixfs.touch(o.cid,t),this.root=await this.#i(i,t)}async#r(e,t,n){if(!t.startsWith("/"))throw new L("path must be absolute");let i=await this.unixfs.stat(e,{...n,offline:!0}),o=[{cid:e,name:"",unixfs:i.unixfs}],s=e,a=t.split("/").filter(Boolean);for(let f=0;f<a.length;f++){let u=a[f];try{let l=await this.unixfs.stat(s,{...n,offline:!0,path:u});o.push({cid:l.cid,name:u,unixfs:l.unixfs}),s=l.cid}catch{if(this.log.error("could not resolve path segment %s of %s under %c",u,t,e),n.createMissingDirectories){let d=await this.unixfs.addDirectory();o.push({cid:d,name:u,unixfs:new S({type:"directory"})})}else throw new ze(`${t} does not exist`)}}let c=o[o.length-1];if(n.finalSegmentMustBeDirectory&&c.unixfs?.isDirectory()!==!0)throw new Ge(`${t} was not a directory`);return o}async#i(e,t={}){let n=e.pop();if(n==null)throw new L("path was too short");let i=n.cid;for(let o=e.length-1;o>-1;o--){let s=e[o];s.cid=await this.unixfs.cp(n.cid,s.cid,n.name,{...t,force:!0}),n=s,i=s.cid}return await this.components.datastore.put(this.key,i.bytes,t),i}async#c(e,t={}){if(!await this.#h(e,t))throw new ze}async#u(e,t={}){if(await this.#h(e,t))throw new ot}async#h(e,t={}){try{return await this.stat(e,{...t,offline:!0}),!0}catch{return!1}}};function ud(r,e={}){return new Vn(r,e)}return Kc(fd);})();
9
+ ${e}`)}`:r!=null?`${r}`:`${t.toString()}`}function Ep(t){return t instanceof AggregateError||t?.name==="AggregateError"&&Array.isArray(t.errors)}function Rf(t,e=""){if(Ep(t)){let r=zf(t,e);return t.errors.length>0?(e=`${e} `,r+=`
10
+ ${e}${t.errors.map(n=>`${Rf(n,`${e}`)}`).join(`
11
+ ${e}`)}`):r+=`
12
+ ${e}[Error list was empty]`,r.trim()}return zf(t,e)}ce.formatters.e=t=>t==null?"undefined":Rf(t);function Sp(t){let e=()=>{};return e.enabled=!1,e.color="",e.diff=0,e.log=()=>{},e.namespace=t,e.destroy=()=>!0,e.extend=()=>e,e}function q(t,e){let r=Sp(`${t}:trace`);return ce.enabled(`${t}:trace`)&&ce.names.map(n=>n.toString()).find(n=>n.includes(":trace"))!=null&&(r=ce(`${t}:trace`,e)),Object.assign(ce(t,e),{error:ce(`${t}:error`,e),trace:r,newScope:n=>q(`${t}:${n}`,e)})}function Pf(t){if(t!=null&&(t=t.trim(),t.length!==0))return t}var ps=on(vn(),1);function Bi(t){function e(r){return r instanceof ki?r:new ki(r,t)}return e}var ki=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 i=this._buffers[this._currentBufferIndex],o=Math.min(i.availableBits(),r),s=i.take(o);n=(n<<o)+s,r-=o,this._availableBits-=o,i.availableBits()===0&&this._currentBufferIndex++}return n}untake(e){let r=e;for(;r>0;){let n=this._buffers[this._currentBufferIndex],i=Math.min(n.totalBits()-n.availableBits(),r);n.untake(i),r-=i,this._availableBits+=i,this._currentBufferIndex>0&&n.totalBits()===n.availableBits()&&(this._depth--,this._currentBufferIndex--)}}async _produceMoreBits(){this._depth++;let e=this._depth>0?Ve([this._value,Uint8Array.from([this._depth])]):this._value,r=await this._hashFn(e),n=new hs(r);this._buffers.push(n),this._availableBits+=n.availableBits()}},kp=[255,254,252,248,240,224,192,128],Bp=[1,3,7,15,31,63,127,255],hs=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 i=this._value[this._currentBytePos],o=this._currentBitPos+1,s=Math.min(o,r),a=Ip(i,o-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 Ip(t,e,r){let n=vp(e,r);return(t&n)>>>e}function vp(t,e){return kp[t]&Bp[Math.min(e+t-1,7)]}var $f=BigInt(Tt.code),Oe=8;async function Ii(t){return(await Tt.encode(t)).subarray(0,8).reverse()}var Mf=on(vn(),1);var nt=async(t,e,r)=>{r.codec==null&&(r.codec=V);let n=await de.digest(t),i=A.create(r.cidVersion??1,r.codec.code,n);return await e.put(i,t,{...r,signal:r.signal}),i};var ms=q("helia:unixfs:commands:utils:hamt-utils"),vi=(t,e=Oe)=>{let r=(Math.pow(2,e)-1).toString(16).length;return t.toString(16).toUpperCase().padStart(r,"0").substring(0,r)},Of=async(t,e,r)=>{let n=new Fr({root:!0,dir:!0,parent:void 0,parentKey:void 0,path:"",dirty:!0,flat:!1,mtime:r.mtime,mode:r.mode},r);for(let o=0;o<e.length;o++)await n.bucket.put(e[o].name,{size:e[o].size,cid:e[o].cid});let i=await Fe(n.flush(t));if(i==null)throw new Error("Flushing shard yielded no result");return i},Ai=async(t,e,r)=>{let n=B.unmarshal(t[0].node.Data??new Uint8Array(0)),i=BigInt(Math.pow(2,r.shardFanoutBits??Oe));t.reverse();let o,s;for(let a=0;a<t.length;a++){let c=a===t.length-1,f=t[a],u=Uint8Array.from(f.children.bitField().reverse()),d=new B({type:"hamt-sharded-directory",data:u,fanout:i,hashType:$f});c&&(d.mtime=n.mtime,d.mode=n.mode),s={Data:d.marshal(),Links:f.node.Links};let m=C(G(s));if(o=await nt(m,e,r),!c){let y=t[a+1];if(y==null)throw new Error("Was not operating on shard root but also had no parent?");ms("updating link in parent sub-shard with prefix %s",y.prefix),y.node.Links=y.node.Links.filter(p=>p.Name!==y.prefix),y.node.Links.push({Name:y.prefix,Hash:o,Tsize:f.node.Links.reduce((p,w)=>p+(w.Tsize??0),m.byteLength)})}}if(o==null||s==null)throw new Error("Noting persisted");return{cid:o,node:s}},Ti=async(t,e,r,n)=>{let o=Bi(Ii)(O(e)),s=[],a=n.shardFanoutBits??Oe;for(;;){let c=await T(r.get(t,n)),f=z(c),u=new Mf.default,d=await o.take(a),m=vi(d,a);s.push({prefix:m,children:u,node:f});let y;for(let w of f.Links){let x=w.Name??"";if(x.length<m.length)throw new Error("Invalid HAMT - link name was too short");let k=parseInt(x.substring(0,m.length),16);u.set(k,!0),x.startsWith(m)&&(y=w)}if(y==null){ms("no link found with prefix %s for %s",m,e);break}let p=y.Name??"";if(p.length<m.length)throw new Error("Invalid HAMT - link name was too short");if(p.length===m.length){t=y.Hash,ms("descend into sub-shard with prefix %s",p);continue}break}return{path:s,hash:o}};var Ni=class extends Error{static name="InvalidParametersError";constructor(e="Invalid parameters"){super(e),this.name="InvalidParametersError"}};async function Ci(t,e,r){if(t.Data==null)throw new Error("DagPB node had no data");let n=r.shardSplitThresholdBytes??262144,i=r.shardSplitStrategy??"links-bytes";r.profile==="unixfs-v0-2015"&&(i="links-bytes");let o=B.unmarshal(t.Data);if(!o.isDirectory())throw new Error("Can only estimate the size of directories or shards");if(i!=="links-bytes"&&i!=="block-bytes")throw new Ni(`Invalid shard split threshold "${i}"`);let s=0;return o.type==="directory"?s=i==="links-bytes"?Tp(t):Np(o,t):o.type==="hamt-sharded-directory"&&(s=i==="links-bytes"?await Hf(t,0,n,e,r):await Vf(t,Ur(o.mode,o.mtime),n,e,r)),s>n}function Tp(t){let e=0;for(let r of t.Links)e+=Ze(r.Name??""),e+=r.Hash.byteLength;return e}function Np(t,e){let r=Ur(t.mode,t.mtime);for(let n of e.Links)r+=Lr(Ze(n.Name??""),n.Hash.byteLength,Number(n.Tsize??0));return r}async function Hf(t,e,r,n,i){if(e>r)return r;if(t.Data==null||!B.unmarshal(t.Data).isDirectory())return e;let s=(Math.pow(2,i.shardFanoutBits??Oe)-1).toString(16).length;for(let a of t.Links){let c=a.Name??"";if(c=c.substring(s),e+=Ze(c),e+=a.Hash.bytes.byteLength,a.Hash.code===W){let f=await T(n.get(a.Hash,i)),u=z(f);e+=await Hf(u,e,r,n,i)}}return e}async function Vf(t,e,r,n,i){if(e>r)return r;if(t.Data==null||!B.unmarshal(t.Data).isDirectory())return e;let s=(Math.pow(2,i.shardFanoutBits??Oe)-1).toString(16).length;for(let a of t.Links){let c=a.Name??"";if(c=c.substring(s),e+=Lr(Ze(c),a.Hash.byteLength,Number(a.Tsize??0)),a.Hash.code===W){let f=await T(n.get(a.Hash,i)),u=z(f);e+=await Vf(u,e,r,n,i)}}return e}var Xe=q("helia:unixfs:components:utils:add-link");async function lr(t,e,r,n){if(t.node.Data==null)throw new $("Invalid parent passed to addLink");if(B.unmarshal(t.node.Data).type==="hamt-sharded-directory")return Xe("adding link to sharded directory"),Lp(t,e,r,n);Xe(`adding ${e.Name} (${e.Hash}) to regular directory`);let o=await Dp(t,e,r,n);if(await Ci(o.node,r,n)){Xe("converting directory to sharded directory");let s=await Cp(o,r,n);o.cid=s.cid,o.node=z(await T(r.get(s.cid,n)))}return o}var Cp=async(t,e,r)=>{if(t.node.Data==null)throw new $("Invalid parent passed to convertToShardedDirectory");let n=B.unmarshal(t.node.Data),i=await Of(e,t.node.Links.map(o=>({name:o.Name??"",size:BigInt(o.Tsize??0),cid:o.Hash})),{...r,mode:n.mode,mtime:n.mtime,cidVersion:t.cid.version});return Xe(`converted directory to sharded directory ${i.cid}`),i},Dp=async(t,e,r,n)=>{let i=t.node.Links.filter(u=>{let d=u.Name===e.Name;if(d&&!n.allowOverwriting)throw new Ct;return!d});if(i.push(e),t.node.Data==null)throw new se("Parent node with no data passed to addToDirectory");let o=B.unmarshal(t.node.Data),s;if(o.mtime!=null){let u=Date.now(),d=Math.floor(u/1e3);o.mtime={secs:BigInt(d),nsecs:(u-d*1e3)*1e3},s=o.marshal()}else s=t.node.Data;t.node=G({Data:s,Links:i});let a=C(t.node),c=await de.digest(a);n?.signal?.throwIfAborted();let f=A.create(t.cid.version,W,c);return await r.put(f,a,n),{node:t.node,cid:f}},Lp=async(t,e,r,n)=>{let{path:i,hash:o}=await Ti(t.cid,e.Name,r,n),s=i[i.length-1];if(s==null)throw new Error("Invalid HAMT, could not generate path");let a=s.prefix,c=parseInt(a,16);Xe("next prefix for %s is %s",e.Name,a);let f=`${a}${e.Name}`,u=s.node.Links.find(m=>(m.Name??"").startsWith(a)),d=a.length;if(u!=null)if(Xe("link %s was present in shard",f),u.Name===f){if(!n.allowOverwriting)throw new Ct;Xe("overwriting %s in sub-shard",e.Name),s.node.Links=s.node.Links.filter(m=>m.Name!==f),s.node.Links.push({Name:f,Hash:e.Hash,Tsize:e.Tsize})}else{if(u.Name?.length===d)throw new Error("Existing link was sub-shard?!");{Xe("prefix %s already exists, creating new sub-shard",a);let m=s.node.Links.findIndex(v=>v.Name?.startsWith(a)),y=s.node.Links.splice(m,1)[0],p=(y.Name??"").substring(d),x=Bi(Ii)(O(p)),k=n.shardFanoutBits??Oe;for(let v=0;v<i.length;v++)await x.take(k),n?.signal?.throwIfAborted();for(;;){let v=await x.take(k);n?.signal?.throwIfAborted();let N=vi(v,k);y.Name=`${N}${p}`;let F=await o.take(k);n?.signal?.throwIfAborted();let H=vi(F,k);if(N===H){let J=new ps.default;J.set(F,!0),i.push({prefix:H,children:J,node:{Links:[]}});continue}let ue=new ps.default;ue.set(F,!0),ue.set(v,!0),i.push({prefix:a,children:ue,node:{Links:[y,{Name:`${H}${e.Name}`,Hash:e.Hash,Tsize:e.Tsize}]}});break}}}else Xe("link %s was not present in sub-shard",f),e.Name=f,s.node.Links.push(e),s.children.set(c,!0),Xe("adding %s to existing sub-shard",f);return Ai(i,r,n)};async function Et(t,e,r={}){let n=await j(t,e,r);if(n.type!=="directory")throw new dt(`${t.toString()} was not a UnixFS directory`);return{cid:t,node:n.node}}async function dr(t,e,r,n){let i=await j(t,r,n);if(i.type!=="directory"&&i.type!=="file"&&i.type!=="raw")throw new We(`${t.toString()} was not a UnixFS node`);return{Name:e,Tsize:i.node instanceof Uint8Array?i.node.byteLength:Up(i.node),Hash:t}}function Up(t){let e=t.Links.reduce((r,n)=>r+(n.Tsize??0),0);return C(t).byteLength+e}var Fp=q("helia:unixfs:components:utils:resolve");async function Ye(t,e,r,n){if(e==null||e==="")return{cid:t};let i=`/ipfs/${t}${e==null?"":`/${e}`}`,o=await La(mi(i,r,n));if(o.length===0)throw new Qe("Could not find path in directory");return Fp("resolved %s to %c",e,t),{cid:o[o.length-1].cid,path:e,segments:o}}async function hr(t,e,r,n){if(e.segments==null||e.segments.length===0)return t;let i=e.segments.pop();if(i==null)throw new Error("Insufficient segments");i.cid=t,e.segments.reverse();for(let o of e.segments){let[s,a]=await Promise.all([Et(o.cid,r,n),dr(i.cid,i.name,r,n)]);t=(await lr(s,a,r,{...n,allowOverwriting:!0,cidVersion:t.version})).cid,o.cid=t,i=o}return t}async function*jf(t,e,r={}){let n=await Ye(t,r.path,e,r),i=await j(n.cid,e,r);if(i.type!=="file"&&i.type!=="raw")throw new Dn;if(i.content==null)throw new Cn;yield*i.content(r)}var zp=q("helia:unixfs:chmod");async function qf(t,e,r,n={}){let i=await Ye(t,n.path,r,n);if(zp("chmod %c %d",i.cid,e),n.recursive===!0){let d=await _t(async function*(){for await(let m of _i(i.cid,r,n)){let y,p=[],w=await j(m.cid,r,n);if(w.type==="raw")y=new B({type:"file",data:w.node});else if(w.type==="file"||w.type==="directory")y=w.unixfs,p=w.node.Links;else throw new We;y.mode=e;let x={Data:y.marshal(),Links:p};yield{path:m.path,content:x}}},m=>Nt(m,r,{...n,dagBuilder:async function*(y,p){for await(let w of y)yield async function(){let x=w.content,k=C(x),v=await nt(k,p,{...n,cidVersion:t.version});if(x.Data==null)throw new se(`${v} had no data`);let N=B.unmarshal(x.Data);return{cid:v,size:BigInt(k.length),path:w.path,unixfs:N}}}}),async m=>Fe(m));if(d==null)throw new lt(`Could not chmod ${i.cid.toString()}`);return hr(d.cid,i,r,n)}let o=await T(r.get(i.cid,n)),s,a=[];if(i.cid.code===te)s=new B({type:"file",data:o});else{let d=z(o);if(d.Data==null)throw new se(`${i.cid.toString()} had no data`);a=d.Links,s=B.unmarshal(d.Data)}s.mode=e;let c=C({Data:s.marshal(),Links:a}),f=await de.digest(c),u=A.create(i.cid.version,W,f);return await r.put(u,c),hr(u,i,r,n)}var Pp=q("helia:unixfs:cp");async function Gf(t,e,r,n,i={}){if(r.includes("/"))throw new $("Name must not have slashes");let[o,s]=await Promise.all([Et(e,n,i),dr(t,r,n,i)]);return Pp('Adding %c as "%s" to %c',t,r,e),(await lr(o,s,n,{allowOverwriting:i.force,cidVersion:e.version,...i})).cid}async function*Wf(t,e,r={}){let n=await Ye(t,r.path,e,r),i=await j(n.cid,e,r);if(i.type==="directory"){yield*i.entries(r);return}yield i}var Kf=q("helia:unixfs:mkdir");async function Jf(t,e,r,n={}){if(e.includes("/"))throw new $("Path must not have slashes");if((await j(t,r,n)).type!=="directory")throw new dt(`${t.toString()} was not a UnixFS directory`);Kf("creating %s",e);let s={Data:new B({type:"directory",mode:n.mode,mtime:n.mtime}).marshal(),Links:[]},a=C(s),c=await de.digest(a),f=A.create(n.cidVersion??1,W,c);await r.put(f,a);let[u,d]=await Promise.all([Et(t,r,n),dr(f,e,r,n)]);return Kf("adding empty dir called %s to %c",e,t),(await lr(u,d,r,{...n,allowOverwriting:n.force})).cid}var Di=q("helia:unixfs:utils:remove-link");async function Xf(t,e,r,n){if(t.node.Data==null)throw new se("Parent node had no data");if(B.unmarshal(t.node.Data).type==="hamt-sharded-directory"){Di(`removing ${e} from sharded directory`);let o=await $p(t,e,r,n);return await Ci(o.node,r,n)?o:(Di("converting shard to flat directory %c",t.cid),Mp(o,r,n))}return Di(`removing link ${e} regular directory`),Rp(t,e,r,n)}var Rp=async(t,e,r,n)=>{t.node.Links=t.node.Links.filter(s=>s.Name!==e);let i=C(t.node),o=await nt(i,r,{...n,cidVersion:t.cid.version});return Di(`Updated regular directory ${o}`),{node:t.node,cid:o}},$p=async(t,e,r,n)=>{let{path:i}=await Ti(t.cid,e,r,n),o=i[i.length-1];if(o==null)throw new Error("Invalid HAMT, could not generate path");let s=(Math.pow(2,n.shardFanoutBits??Oe)-1).toString(16).length,a=o.node.Links.filter(u=>(u.Name??"").substring(s)===e).map(u=>u.Name).pop();if(a==null)throw new Error("File not found");let c=a.substring(0,s),f=parseInt(c,16);if(o.node.Links=o.node.Links.filter(u=>u.Name!==a),o.children.unset(f),o.node.Links.length===1)for(;i.length!==1;){let u=i[i.length-1];if(u==null||u.node.Links.length>1)break;i.pop();let d=i[i.length-1];if(d==null)break;let m=u.node.Links[0];d.node.Links=d.node.Links.filter(y=>!(y.Name??"").startsWith(d.prefix)),d.node.Links.push({Hash:m.Hash,Name:`${d.prefix}${(m.Name??"").substring(s)}`,Tsize:m.Tsize})}return Ai(i,r,n)},Mp=async(t,e,r)=>{if(t.node.Data==null)throw new $("Invalid parent passed to convertToFlatDirectory");let n={Links:[]},i=await j(t.cid,e,r);if(i.type!=="directory")throw new Error("Unexpected node type");for await(let c of i.entries()){let f=0,u=await j(c.cid,e,r);u.node instanceof Uint8Array?f=u.node.byteLength:f=C(u.node).length,n.Links.push({Hash:c.cid,Name:c.name,Tsize:f})}let o=B.unmarshal(t.node.Data);n.Data=new B({type:"directory",mode:o.mode,mtime:o.mtime}).marshal();let s=C(G(n));return{cid:await nt(s,e,{codec:V,cidVersion:t.cid.version,signal:r.signal}),node:n}};var Op=q("helia:unixfs:rm");async function Yf(t,e,r,n={}){if(e.includes("/"))throw new $("Name must not have slashes");let i=await Et(t,r,n);return Op("Removing %s from %c",e,t),(await Xf(i,e,r,{...n,cidVersion:t.version})).cid}function Zf(t,e="utf8"){let r=xn[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.encoder.encode(t).substring(1)}var ys={32:16777619n,64:1099511628211n,128:309485009821345068724781371n,256:374144419156711147060143317175368453031918731002211n,512:35835915874844867368919076489095108449946327955754392558399825615420669938882575126094039892345713852759n,1024:5016456510113118655434598811035278955030765345404790744303017523831112055108147451509157692220295382716162651878526895249385292291816524375083746691371804094271873160484737966720260389217684476157468082573n},Qf={32:2166136261n,64:14695981039346656037n,128:144066263297769815596495629667062367629n,256:100029257958052580907070968620625704837092796014241193945225284501741471925557n,512:9659303129496669498009435400716310466090418745672637896108374329434462657994582932197716438449813051892206539805784495328239340083876191928701583869517785n,1024:14197795064947621068722070641403218320880622795441933960878474914617582723252296732303717722150864096521202355549365628174669108571814760471015076148029755969804077320157692458563003215304957150157403644460363550505412711285966361610267868082893823963790439336411086884584107735010676915n},el=new globalThis.TextEncoder;function Hp(t,e){let r=ys[e],n=Qf[e];for(let i=0;i<t.length;i++)n^=BigInt(t[i]),n=BigInt.asUintN(e,n*r);return n}function Vp(t,e,r){if(r.length===0)throw new Error("The `utf8Buffer` option must have a length greater than zero");let n=ys[e],i=Qf[e],o=t;for(;o.length>0;){let s=el.encodeInto(o,r);o=o.slice(s.read);for(let a=0;a<s.written;a++)i^=BigInt(r[a]),i=BigInt.asUintN(e,i*n)}return i}function gs(t,{size:e=32,utf8Buffer:r}={}){if(!ys[e])throw new Error("The `size` option must be one of 32, 64, 128, 256, 512, or 1024");if(typeof t=="string"){if(r)return Vp(t,e,r);t=el.encode(t)}return Hp(t,e)}var Qr={hash:t=>Number(gs(t,{size:32})),hashV:(t,e)=>jp(Qr.hash(t,e))};function jp(t){let e=t.toString(16);return e.length%2===1&&(e=`0${e}`),O(e,"base16")}var tl=64,He=class{fp;h;seed;constructor(e,r,n,i=2){if(i>tl)throw new TypeError("Invalid Fingerprint Size");let o=r.hashV(e,n),s=Ce(i);for(let a=0;a<s.length;a++)s[a]=o[a];s.length===0&&(s[0]=7),this.fp=s,this.h=r,this.seed=n}hash(){return this.h.hash(this.fp,this.seed)}equals(e){return e?.fp instanceof Uint8Array?fn(this.fp,e.fp):!1}};function zt(t,e){return Math.floor(Math.random()*(e-t))+t}var Pt=class{contents;constructor(e){this.contents=new Array(e).fill(null)}has(e){if(!(e instanceof He))throw new TypeError("Invalid Fingerprint");return this.contents.some(r=>e.equals(r))}add(e){if(!(e instanceof He))throw new TypeError("Invalid Fingerprint");for(let r=0;r<this.contents.length;r++)if(this.contents[r]==null)return this.contents[r]=e,!0;return!0}swap(e){if(!(e instanceof He))throw new TypeError("Invalid Fingerprint");let r=zt(0,this.contents.length-1),n=this.contents[r];return this.contents[r]=e,n}remove(e){if(!(e instanceof He))throw new TypeError("Invalid Fingerprint");let r=this.contents.findIndex(n=>e.equals(n));return r>-1?(this.contents[r]=null,!0):!1}};var qp=500,en=class{bucketSize;filterSize;fingerprintSize;buckets;count;hash;seed;constructor(e){this.filterSize=e.filterSize,this.bucketSize=e.bucketSize??4,this.fingerprintSize=e.fingerprintSize??2,this.count=0,this.buckets=[],this.hash=e.hash??Qr,this.seed=e.seed??zt(0,Math.pow(2,10))}add(e){typeof e=="string"&&(e=O(e));let r=new He(e,this.hash,this.seed,this.fingerprintSize),n=this.hash.hash(e,this.seed)%this.filterSize,i=(n^r.hash())%this.filterSize;if(this.buckets[n]==null&&(this.buckets[n]=new Pt(this.bucketSize)),this.buckets[i]==null&&(this.buckets[i]=new Pt(this.bucketSize)),this.buckets[n].add(r)||this.buckets[i].add(r))return this.count++,!0;let o=[n,i],s=o[zt(0,o.length-1)];this.buckets[s]==null&&(this.buckets[s]=new Pt(this.bucketSize));for(let a=0;a<qp;a++){let c=this.buckets[s].swap(r);if(c!=null&&(s=(s^c.hash())%this.filterSize,this.buckets[s]==null&&(this.buckets[s]=new Pt(this.bucketSize)),this.buckets[s].add(c)))return this.count++,!0}return!1}has(e){typeof e=="string"&&(e=O(e));let r=new He(e,this.hash,this.seed,this.fingerprintSize),n=this.hash.hash(e,this.seed)%this.filterSize,i=this.buckets[n]?.has(r)??!1;if(i)return i;let o=(n^r.hash())%this.filterSize;return this.buckets[o]?.has(r)??!1}remove(e){typeof e=="string"&&(e=O(e));let r=new He(e,this.hash,this.seed,this.fingerprintSize),n=this.hash.hash(e,this.seed)%this.filterSize,i=this.buckets[n]?.remove(r)??!1;if(i)return this.count--,i;let o=(n^r.hash())%this.filterSize,s=this.buckets[o]?.remove(r)??!1;return s&&this.count--,s}get reliable(){return Math.floor(100*(this.count/this.filterSize))<=90}};var tn=class{filterSize;bucketSize;fingerprintSize;scale;filterSeries;hash;seed;constructor(e){this.bucketSize=e.bucketSize??4,this.filterSize=e.filterSize??(1<<18)/this.bucketSize,this.fingerprintSize=e.fingerprintSize??2,this.scale=e.scale??2,this.hash=e.hash??Qr,this.seed=e.seed??zt(0,Math.pow(2,10)),this.filterSeries=[new en({filterSize:this.filterSize,bucketSize:this.bucketSize,fingerprintSize:this.fingerprintSize,hash:this.hash,seed:this.seed})]}add(e){if(typeof e=="string"&&(e=O(e)),this.has(e))return!0;let r=this.filterSeries.find(n=>n.reliable);if(r==null){let n=this.filterSize*Math.pow(this.scale,this.filterSeries.length);r=new en({filterSize:n,bucketSize:this.bucketSize,fingerprintSize:this.fingerprintSize,hash:this.hash,seed:this.seed}),this.filterSeries.push(r)}return r.add(e)}has(e){typeof e=="string"&&(e=O(e));for(let r=0;r<this.filterSeries.length;r++)if(this.filterSeries[r].has(e))return!0;return!1}remove(e){typeof e=="string"&&(e=O(e));for(let r=0;r<this.filterSeries.length;r++)if(this.filterSeries[r].remove(e))return!0;return!1}get count(){return this.filterSeries.reduce((e,r)=>e+r.count,0)}};var rl=1877,Li=1604,Gp=q("helia:unixfs:stat");async function nl(t,e,r={}){let n=await Ye(t,r.path,e,r);Gp("stat %c",n.cid);let i=await j(n.cid,e,r);if(i.type==="raw")return r.extended===!0?Xp(i):Jp(i);if(i.type==="file"||i.type==="directory")return r.extended===!0?Kp(i,e,r.filter??new tn({filterSize:1024}),r):Wp(i);throw new We}function Wp(t){return{type:t.type,cid:t.cid,unixfs:t.unixfs,mode:t.unixfs.mode??(t.unixfs.isDirectory()?rl:Li),mtime:t.unixfs.mtime,size:t.unixfs.fileSize()}}async function Kp(t,e,r,n){let i=await il(t.cid,e,!1,r,n);return{type:t.type,cid:t.cid,unixfs:t.unixfs,size:t.unixfs.isDirectory()?i.dirSize:t.unixfs.fileSize(),mode:t.unixfs.mode??(t.unixfs.isDirectory()?rl:Li),mtime:t.unixfs.mtime,localSize:i.localSize,dagSize:i.dagSize,deduplicatedDagSize:i.deduplicatedDagSize,blocks:i.blocks,uniqueBlocks:i.uniqueBlocks}}function Jp(t){return{type:t.type,cid:t.cid,unixfs:void 0,mode:Li,mtime:void 0,size:BigInt(t.node.byteLength)}}function Xp(t){return{type:t.type,cid:t.cid,unixfs:void 0,mode:Li,mtime:void 0,size:BigInt(t.node.byteLength),localSize:BigInt(t.node.byteLength),dagSize:BigInt(t.node.byteLength),deduplicatedDagSize:BigInt(t.node.byteLength),blocks:1n,uniqueBlocks:1n}}async function il(t,e,r,n,i){let o={dirSize:0n,localSize:0n,dagSize:0n,deduplicatedDagSize:0n,blocks:0n,uniqueBlocks:0n};try{let s=n.has(t.bytes);n.add(t.bytes);let a=await T(e.get(t,i));if(o.blocks++,o.dagSize+=BigInt(a.byteLength),s||(o.uniqueBlocks++,o.deduplicatedDagSize+=BigInt(a.byteLength)),t.code===te)o.localSize+=BigInt(a.byteLength),r&&(o.dirSize+=BigInt(a.byteLength));else if(t.code===W){let c=z(a),f;if(c.Data!=null&&(f=B.unmarshal(c.Data)),c.Links.length>0){for(let u of c.Links){let d=await il(u.Hash,e,Yp(u,f),n,i);o.localSize+=d.localSize,o.dagSize+=d.dagSize,o.deduplicatedDagSize+=d.deduplicatedDagSize,o.blocks+=d.blocks,o.uniqueBlocks+=d.uniqueBlocks,o.dirSize+=d.dirSize}r&&f!=null&&(o.dirSize+=f.fileSize())}else{if(f==null)throw new se(`PBNode ${t.toString()} had no data`);f.data!=null&&(o.localSize+=BigInt(f.data.byteLength??0)),r&&(o.dirSize+=f.fileSize())}}else throw new lt(`${t.toString()} was neither DAG_PB nor RAW`)}catch(s){if(s.name!=="NotFoundError"&&s.name!=="BlockNotFoundWhileOfflineError"||i.offline!==!0)throw s}return o}function Yp(t,e){if(e==null)return!1;let r=t.Name;return r==null?!1:e.type==="directory"?!0:e.type==="hamt-sharded-directory"&&r.length>2}var Zp=q("helia:unixfs:touch");async function ol(t,e,r={}){let n=await Ye(t,r.path,e,r),i=r.mtime??{secs:BigInt(Math.round(Date.now()/1e3)),nsecs:0};if(Zp("touch %c %o",n.cid,i),r.recursive){let d=await _t(async function*(){for await(let m of _i(n.cid,e)){let y,p,w=await j(m.cid,e,r);if(w.type==="raw")y=new B({data:w.node}),p=[];else if(w.type==="file"||w.type==="directory")y=w.unixfs,p=w.node.Links;else throw new We;y.mtime=i;let x={Data:y.marshal(),Links:p};yield{path:m.path,content:x}}},m=>Nt(m,e,{...r,dagBuilder:async function*(y,p){for await(let w of y)yield async function(){let x=w.content,k=C(x),v=await nt(k,p,{...r,cidVersion:t.version});if(x.Data==null)throw new se(`${v} had no data`);let N=B.unmarshal(x.Data);return{cid:v,size:BigInt(k.length),path:w.path,unixfs:N}}}}),async m=>Fe(m));if(d==null)throw new lt(`Could not chmod ${n.cid.toString()}`);return hr(d.cid,n,e,r)}let o=await T(e.get(n.cid,r)),s,a=[];if(n.cid.code===te)s=new B({data:o});else{let d=z(o);if(a=d.Links,d.Data==null)throw new se(`${n.cid.toString()} had no data`);s=B.unmarshal(d.Data)}s.mtime=i;let c=C({Data:s.marshal(),Links:a}),f=await de.digest(c),u=A.create(n.cid.version,W,f);return await e.put(u,c),hr(u,n,e,r)}var Ui=class{components;constructor(e){this.components=e}async*addAll(e,r={}){yield*Ln(e,this.components.blockstore,r)}async addBytes(e,r={}){return Ka(e,this.components.blockstore,r)}async addByteStream(e,r={}){return Ja(e,this.components.blockstore,r)}async addFile(e,r={}){return Xa(e,this.components.blockstore,r)}async addDirectory(e={},r={}){return Ya(e,this.components.blockstore,r)}async*cat(e,r={}){yield*jf(e,this.components.blockstore,r)}async chmod(e,r,n={}){return qf(e,r,this.components.blockstore,n)}async cp(e,r,n,i={}){return Gf(e,r,n,this.components.blockstore,i)}async*ls(e,r={}){yield*Wf(e,this.components.blockstore,r)}async mkdir(e,r,n={}){return Jf(e,r,this.components.blockstore,n)}async rm(e,r,n={}){return Yf(e,r,this.components.blockstore,n)}async stat(e,r={}){return nl(e,this.components.blockstore,r)}async touch(e,r={}){return ol(e,this.components.blockstore,r)}};function sl(t){return new Ui(t)}var it="/",al=new TextEncoder().encode(it),Fi=al[0],rn=class t{_buf;constructor(e,r){if(typeof e=="string")this._buf=O(e);else if(e instanceof Uint8Array)this._buf=e;else throw new Error("Invalid key, should be String of Uint8Array");if(r==null&&(r=!0),r&&this.clean(),this._buf.byteLength===0||this._buf[0]!==Fi)throw new Error("Invalid key")}toString(e="utf8"){return Zf(this._buf,e)}uint8Array(){return this._buf}get[Symbol.toStringTag](){return`Key(${this.toString()})`}static withNamespaces(e){return new t(e.join(it))}static random(){return new t(Math.random().toString().substring(2))}static asKey(e){return e instanceof Uint8Array||typeof e=="string"?new t(e):typeof e.uint8Array=="function"?new t(e.uint8Array()):null}clean(){if((this._buf==null||this._buf.byteLength===0)&&(this._buf=al),this._buf[0]!==Fi){let e=new Uint8Array(this._buf.byteLength+1);e.fill(Fi,0,1),e.set(this._buf,1),this._buf=e}for(;this._buf.byteLength>1&&this._buf[this._buf.byteLength-1]===Fi;)this._buf=this._buf.subarray(0,-1)}less(e){let r=this.list(),n=e.list();for(let i=0;i<r.length;i++){if(n.length<i+1)return!1;let o=r[i],s=n[i];if(o<s)return!0;if(o>s)return!1}return r.length<n.length}reverse(){return t.withNamespaces(this.list().slice().reverse())}namespaces(){return this.list()}baseNamespace(){let e=this.namespaces();return e[e.length-1]}list(){return this.toString().split(it).slice(1)}type(){return Qp(this.baseNamespace())}name(){return ey(this.baseNamespace())}instance(e){return new t(this.toString()+":"+e)}path(){let e=this.parent().toString();return e.endsWith(it)||(e+=it),e+=this.type(),new t(e)}parent(){let e=this.list();return e.length===1?new t(it):new t(e.slice(0,-1).join(it))}child(e){return this.toString()===it?e:e.toString()===it?this:new t(this.toString()+e.toString(),!1)}isAncestorOf(e){return e.toString()===this.toString()?!1:e.toString().startsWith(this.toString())}isDecendantOf(e){return e.toString()===this.toString()?!1:this.toString().startsWith(e.toString())}isTopLevel(){return this.list().length===1}concat(...e){return t.withNamespaces([...this.namespaces(),...ty(e.map(r=>r.namespaces()))])}};function Qp(t){let e=t.split(":");return e.length<2?"":e.slice(0,-1).join(":")}function ey(t){let e=t.split(":");return e[e.length-1]}function ty(t){return[].concat(...t)}function zi(t){return t.split("/").pop()??""}var Pi=class{components;unixfs;root;key;log;constructor(e,r={}){this.components=e,this.log=e.logger.forComponent("helia:mfs"),this.key=new rn(r.key??"/locals/filesroot"),this.unixfs=sl(e)}async#e(){if(this.root==null)try{let e=await this.components.datastore.get(this.key);this.root=A.decode(e)}catch(e){if(e.name!=="NotFoundError")throw e;this.root=await this.unixfs.addDirectory()}return this.root}async writeBytes(e,r,n){let i=await this.unixfs.addBytes(e,n);await this.cp(i,r,n),n?.mode!=null&&await this.chmod(r,n.mode,n),n?.mtime!=null&&await this.touch(r,n)}async writeByteStream(e,r,n){let i=await this.unixfs.addByteStream(e,n);await this.cp(i,r,n),n?.mode!=null&&await this.chmod(r,n.mode,n),n?.mtime!=null&&await this.touch(r,n)}async*cat(e,r={}){let n=await this.#e(),i=await this.#r(n,e,{...r,createMissingDirectories:!1,finalSegmentMustBeDirectory:!1});yield*this.unixfs.cat(i[i.length-1].cid,r)}async chmod(e,r,n={}){let i=await this.#e();this.root=await this.unixfs.chmod(i,r,{...n,path:e})}async cp(e,r,n){let i=await this.#e(),o=n?.force??!1;typeof e=="string"&&(e=(await this.stat(e,n)).cid),o||await this.#u(r,n);let s=zi(r),a=r.substring(0,r.length-`/${s}`.length),c=[{cid:i,name:""}];a!==""&&(c=await this.#r(i,a,{...n,createMissingDirectories:n?.force??!1,finalSegmentMustBeDirectory:!0})),c.push({cid:e,name:s}),this.root=await this.#i(c,n)}async*ls(e,r){let n=await this.#e();r?.path!=null&&(e=`${e}/${r.path}`);let i=n.toString();yield*cr(this.unixfs.ls(n,{...r,path:e}),o=>{let s=o.path.split("/").slice(1).join("/");return s.startsWith(i)&&(s=s.substring(0,i.length)),{...o,path:`${e==="/"?"":e}/${s}`}})}async mkdir(e,r){let n=r?.force??!1;n||await this.#u(e,r);let i=zi(e),o=e.substring(0,e.length-`/${i}`.length),s=await this.#e(),a=[{cid:s,name:""}];o!==""&&(a=await this.#r(s,o,{...r,createMissingDirectories:n,finalSegmentMustBeDirectory:!0})),a.push({cid:await this.unixfs.addDirectory({mode:r?.mode,mtime:r?.mtime},r),name:zi(e)}),this.root=await this.#i(a,r)}async rm(e,r){(r?.force??!1)||await this.#c(e,r);let i=await this.#e(),o=await this.#r(i,e,{...r,createMissingDirectories:!1,finalSegmentMustBeDirectory:!1}),s=o.pop();if(s==null)throw new $("path was too short");let a=o[o.length-1];a.cid=await this.unixfs.rm(a.cid,s.name,r),this.root=await this.#i(o,r)}async stat(e,r){let n=await this.#e(),o=(await this.#r(n,e,{...r,createMissingDirectories:!1,finalSegmentMustBeDirectory:!1})).pop();if(o==null)throw new Qe;return this.unixfs.stat(o.cid,r)}async touch(e,r){let n=await this.#e(),i=await this.#r(n,e,{...r,createMissingDirectories:!1,finalSegmentMustBeDirectory:!1}),o=i[i.length-1];if(o==null)throw new Qe;o.cid=await this.unixfs.touch(o.cid,r),this.root=await this.#i(i,r)}async#r(e,r,n){if(!r.startsWith("/"))throw new $("path must be absolute");let i=await this.unixfs.stat(e,{...n,offline:!0}),o=[{cid:e,name:"",unixfs:i.unixfs}],s=e,a=r.split("/").filter(Boolean);for(let f=0;f<a.length;f++){let u=a[f];try{let d=await this.unixfs.stat(s,{...n,offline:!0,path:u});o.push({cid:d.cid,name:u,unixfs:d.unixfs}),s=d.cid}catch{if(this.log.error("could not resolve path segment %s of %s under %c",u,r,e),n.createMissingDirectories){let m=await this.unixfs.addDirectory();o.push({cid:m,name:u,unixfs:new B({type:"directory"})})}else throw new Qe(`${r} does not exist`)}}let c=o[o.length-1];if(n.finalSegmentMustBeDirectory&&c.unixfs?.isDirectory()!==!0)throw new dt(`${r} was not a directory`);return o}async#i(e,r={}){let n=e.pop();if(n==null)throw new $("path was too short");let i=n.cid;for(let o=e.length-1;o>-1;o--){let s=e[o];s.cid=await this.unixfs.cp(n.cid,s.cid,n.name,{...r,force:!0}),n=s,i=s.cid}return await this.components.datastore.put(this.key,i.bytes,r),i}async#c(e,r={}){if(!await this.#d(e,r))throw new Qe}async#u(e,r={}){if(await this.#d(e,r))throw new Ct}async#d(e,r={}){try{return await this.stat(e,{...r,offline:!0}),!0}catch{return!1}}};function ry(t,e={}){return new Pi(t,e)}return ml(ny);})();
13
13
  return HeliaMfs}));
14
14
  //# sourceMappingURL=index.min.js.map