ipfs-unixfs-importer
Version:
JavaScript implementation of the UnixFs importer used by IPFS
2 lines • 75.6 kB
JavaScript
(function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.IpfsUnixfsImporter = factory()}(typeof self !== 'undefined' ? self : this, function () {
"use strict";var IpfsUnixfsImporter=(()=>{var gn=Object.create;var Ft=Object.defineProperty;var wn=Object.getOwnPropertyDescriptor;var yn=Object.getOwnPropertyNames;var xn=Object.getPrototypeOf,bn=Object.prototype.hasOwnProperty;var Jt=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports),I=(r,t)=>{for(var e in t)Ft(r,e,{get:t[e],enumerable:!0})},qe=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of yn(t))!bn.call(r,i)&&i!==e&&Ft(r,i,{get:()=>t[i],enumerable:!(n=wn(t,i))||n.enumerable});return r};var Ke=(r,t,e)=>(e=r!=null?gn(xn(r)):{},qe(t||!r||!r.__esModule?Ft(e,"default",{value:r,enumerable:!0}):e,r)),_n=r=>qe(Ft({},"__esModule",{value:!0}),r);var Zr=Jt((Lt,qt)=>{(function(r,t){"use strict";var e={version:"3.0.0",x86:{},x64:{},inputValidation:!0};function n(s){if(!Array.isArray(s)&&!ArrayBuffer.isView(s))return!1;for(var h=0;h<s.length;h++)if(!Number.isInteger(s[h])||s[h]<0||s[h]>255)return!1;return!0}function i(s,h){return(s&65535)*h+(((s>>>16)*h&65535)<<16)}function o(s,h){return s<<h|s>>>32-h}function a(s){return s^=s>>>16,s=i(s,2246822507),s^=s>>>13,s=i(s,3266489909),s^=s>>>16,s}function c(s,h){s=[s[0]>>>16,s[0]&65535,s[1]>>>16,s[1]&65535],h=[h[0]>>>16,h[0]&65535,h[1]>>>16,h[1]&65535];var d=[0,0,0,0];return d[3]+=s[3]+h[3],d[2]+=d[3]>>>16,d[3]&=65535,d[2]+=s[2]+h[2],d[1]+=d[2]>>>16,d[2]&=65535,d[1]+=s[1]+h[1],d[0]+=d[1]>>>16,d[1]&=65535,d[0]+=s[0]+h[0],d[0]&=65535,[d[0]<<16|d[1],d[2]<<16|d[3]]}function l(s,h){s=[s[0]>>>16,s[0]&65535,s[1]>>>16,s[1]&65535],h=[h[0]>>>16,h[0]&65535,h[1]>>>16,h[1]&65535];var d=[0,0,0,0];return d[3]+=s[3]*h[3],d[2]+=d[3]>>>16,d[3]&=65535,d[2]+=s[2]*h[3],d[1]+=d[2]>>>16,d[2]&=65535,d[2]+=s[3]*h[2],d[1]+=d[2]>>>16,d[2]&=65535,d[1]+=s[1]*h[3],d[0]+=d[1]>>>16,d[1]&=65535,d[1]+=s[2]*h[2],d[0]+=d[1]>>>16,d[1]&=65535,d[1]+=s[3]*h[1],d[0]+=d[1]>>>16,d[1]&=65535,d[0]+=s[0]*h[3]+s[1]*h[2]+s[2]*h[1]+s[3]*h[0],d[0]&=65535,[d[0]<<16|d[1],d[2]<<16|d[3]]}function x(s,h){return h%=64,h===32?[s[1],s[0]]:h<32?[s[0]<<h|s[1]>>>32-h,s[1]<<h|s[0]>>>32-h]:(h-=32,[s[1]<<h|s[0]>>>32-h,s[0]<<h|s[1]>>>32-h])}function f(s,h){return h%=64,h===0?s:h<32?[s[0]<<h|s[1]>>>32-h,s[1]<<h]:[s[1]<<h-32,0]}function w(s,h){return[s[0]^h[0],s[1]^h[1]]}function S(s){return s=w(s,[0,s[0]>>>1]),s=l(s,[4283543511,3981806797]),s=w(s,[0,s[0]>>>1]),s=l(s,[3301882366,444984403]),s=w(s,[0,s[0]>>>1]),s}e.x86.hash32=function(s,h){if(e.inputValidation&&!n(s))return t;h=h||0;for(var d=s.length%4,E=s.length-d,u=h,p=0,m=3432918353,y=461845907,b=0;b<E;b=b+4)p=s[b]|s[b+1]<<8|s[b+2]<<16|s[b+3]<<24,p=i(p,m),p=o(p,15),p=i(p,y),u^=p,u=o(u,13),u=i(u,5)+3864292196;switch(p=0,d){case 3:p^=s[b+2]<<16;case 2:p^=s[b+1]<<8;case 1:p^=s[b],p=i(p,m),p=o(p,15),p=i(p,y),u^=p}return u^=s.length,u=a(u),u>>>0},e.x86.hash128=function(s,h){if(e.inputValidation&&!n(s))return t;h=h||0;for(var d=s.length%16,E=s.length-d,u=h,p=h,m=h,y=h,b=0,_=0,g=0,A=0,O=597399067,vt=2869860233,zt=951274213,Ct=2716044179,B=0;B<E;B=B+16)b=s[B]|s[B+1]<<8|s[B+2]<<16|s[B+3]<<24,_=s[B+4]|s[B+5]<<8|s[B+6]<<16|s[B+7]<<24,g=s[B+8]|s[B+9]<<8|s[B+10]<<16|s[B+11]<<24,A=s[B+12]|s[B+13]<<8|s[B+14]<<16|s[B+15]<<24,b=i(b,O),b=o(b,15),b=i(b,vt),u^=b,u=o(u,19),u+=p,u=i(u,5)+1444728091,_=i(_,vt),_=o(_,16),_=i(_,zt),p^=_,p=o(p,17),p+=m,p=i(p,5)+197830471,g=i(g,zt),g=o(g,17),g=i(g,Ct),m^=g,m=o(m,15),m+=y,m=i(m,5)+2530024501,A=i(A,Ct),A=o(A,18),A=i(A,O),y^=A,y=o(y,13),y+=u,y=i(y,5)+850148119;switch(b=0,_=0,g=0,A=0,d){case 15:A^=s[B+14]<<16;case 14:A^=s[B+13]<<8;case 13:A^=s[B+12],A=i(A,Ct),A=o(A,18),A=i(A,O),y^=A;case 12:g^=s[B+11]<<24;case 11:g^=s[B+10]<<16;case 10:g^=s[B+9]<<8;case 9:g^=s[B+8],g=i(g,zt),g=o(g,17),g=i(g,Ct),m^=g;case 8:_^=s[B+7]<<24;case 7:_^=s[B+6]<<16;case 6:_^=s[B+5]<<8;case 5:_^=s[B+4],_=i(_,vt),_=o(_,16),_=i(_,zt),p^=_;case 4:b^=s[B+3]<<24;case 3:b^=s[B+2]<<16;case 2:b^=s[B+1]<<8;case 1:b^=s[B],b=i(b,O),b=o(b,15),b=i(b,vt),u^=b}return u^=s.length,p^=s.length,m^=s.length,y^=s.length,u+=p,u+=m,u+=y,p+=u,m+=u,y+=u,u=a(u),p=a(p),m=a(m),y=a(y),u+=p,u+=m,u+=y,p+=u,m+=u,y+=u,("00000000"+(u>>>0).toString(16)).slice(-8)+("00000000"+(p>>>0).toString(16)).slice(-8)+("00000000"+(m>>>0).toString(16)).slice(-8)+("00000000"+(y>>>0).toString(16)).slice(-8)},e.x64.hash128=function(s,h){if(e.inputValidation&&!n(s))return t;h=h||0;for(var d=s.length%16,E=s.length-d,u=[0,h],p=[0,h],m=[0,0],y=[0,0],b=[2277735313,289559509],_=[1291169091,658871167],g=0;g<E;g=g+16)m=[s[g+4]|s[g+5]<<8|s[g+6]<<16|s[g+7]<<24,s[g]|s[g+1]<<8|s[g+2]<<16|s[g+3]<<24],y=[s[g+12]|s[g+13]<<8|s[g+14]<<16|s[g+15]<<24,s[g+8]|s[g+9]<<8|s[g+10]<<16|s[g+11]<<24],m=l(m,b),m=x(m,31),m=l(m,_),u=w(u,m),u=x(u,27),u=c(u,p),u=c(l(u,[0,5]),[0,1390208809]),y=l(y,_),y=x(y,33),y=l(y,b),p=w(p,y),p=x(p,31),p=c(p,u),p=c(l(p,[0,5]),[0,944331445]);switch(m=[0,0],y=[0,0],d){case 15:y=w(y,f([0,s[g+14]],48));case 14:y=w(y,f([0,s[g+13]],40));case 13:y=w(y,f([0,s[g+12]],32));case 12:y=w(y,f([0,s[g+11]],24));case 11:y=w(y,f([0,s[g+10]],16));case 10:y=w(y,f([0,s[g+9]],8));case 9:y=w(y,[0,s[g+8]]),y=l(y,_),y=x(y,33),y=l(y,b),p=w(p,y);case 8:m=w(m,f([0,s[g+7]],56));case 7:m=w(m,f([0,s[g+6]],48));case 6:m=w(m,f([0,s[g+5]],40));case 5:m=w(m,f([0,s[g+4]],32));case 4:m=w(m,f([0,s[g+3]],24));case 3:m=w(m,f([0,s[g+2]],16));case 2:m=w(m,f([0,s[g+1]],8));case 1:m=w(m,[0,s[g]]),m=l(m,b),m=x(m,31),m=l(m,_),u=w(u,m)}return u=w(u,[0,s.length]),p=w(p,[0,s.length]),u=c(u,p),p=c(p,u),u=S(u),p=S(p),u=c(u,p),p=c(p,u),("00000000"+(u[0]>>>0).toString(16)).slice(-8)+("00000000"+(u[1]>>>0).toString(16)).slice(-8)+("00000000"+(p[0]>>>0).toString(16)).slice(-8)+("00000000"+(p[1]>>>0).toString(16)).slice(-8)},typeof Lt<"u"?(typeof qt<"u"&&qt.exports&&(Lt=qt.exports=e),Lt.murmurHash3=e):typeof define=="function"&&define.amd?define([],function(){return e}):(e._murmurHash3=r.murmurHash3,e.noConflict=function(){return r.murmurHash3=e._murmurHash3,e._murmurHash3=t,e.noConflict=t,e},r.murmurHash3=e)})(Lt)});var Yr=Jt((Sc,Qr)=>{Qr.exports=Zr()});var nn=Jt((Lc,rn)=>{"use strict";rn.exports=class{constructor(){this._bitArrays=[],this._data=[],this._length=0,this._changedLength=!1,this._changedData=!1}set(t,e){let n=this._internalPositionFor(t,!1);if(e===void 0)n!==-1&&(this._unsetInternalPos(n),this._unsetBit(t),this._changedLength=!0,this._changedData=!0);else{let i=!1;n===-1?(n=this._data.length,this._setBit(t),this._changedData=!0):i=!0,this._setInternalPos(n,t,e,i),this._changedLength=!0}}unset(t){this.set(t,void 0)}get(t){this._sortData();let e=this._internalPositionFor(t,!0);if(e!==-1)return this._data[e][1]}push(t){return this.set(this.length,t),this.length}get length(){if(this._sortData(),this._changedLength){let t=this._data[this._data.length-1];this._length=t?t[0]+1:0,this._changedLength=!1}return this._length}forEach(t){let e=0;for(;e<this.length;)t(this.get(e),e,this),e++}map(t){let e=0,n=new Array(this.length);for(;e<this.length;)n[e]=t(this.get(e),e,this),e++;return n}reduce(t,e){let n=0,i=e;for(;n<this.length;){let o=this.get(n);i=t(i,o,n),n++}return i}find(t){let e=0,n,i;for(;e<this.length&&!n;)i=this.get(e),n=t(i),e++;return n?i:void 0}_internalPositionFor(t,e){let n=this._bytePosFor(t,e);if(n>=this._bitArrays.length)return-1;let i=this._bitArrays[n],o=t-n*7;if(!((i&1<<o)>0))return-1;let c=this._bitArrays.slice(0,n).reduce(yo,0),l=~(4294967295<<o+1),x=en(i&l);return c+x-1}_bytePosFor(t,e){let n=Math.floor(t/7),i=n+1;for(;!e&&this._bitArrays.length<i;)this._bitArrays.push(0);return n}_setBit(t){let e=this._bytePosFor(t,!1);this._bitArrays[e]|=1<<t-e*7}_unsetBit(t){let e=this._bytePosFor(t,!1);this._bitArrays[e]&=~(1<<t-e*7)}_setInternalPos(t,e,n,i){let o=this._data,a=[e,n];if(i)this._sortData(),o[t]=a;else{if(o.length)if(o[o.length-1][0]>=e)o.push(a);else if(o[0][0]<=e)o.unshift(a);else{let c=Math.round(o.length/2);this._data=o.slice(0,c).concat(a).concat(o.slice(c))}else this._data.push(a);this._changedData=!0,this._changedLength=!0}}_unsetInternalPos(t){this._data.splice(t,1)}_sortData(){this._changedData&&this._data.sort(xo),this._changedData=!1}bitField(){let t=[],e=8,n=0,i=0,o,a=this._bitArrays.slice();for(;a.length||n;){n===0&&(o=a.shift(),n=7);let l=Math.min(n,e),x=~(255<<l),f=o&x;i|=f<<8-e,o=o>>>l,n-=l,e-=l,(!e||!n&&!a.length)&&(t.push(i),i=0,e=8)}for(var c=t.length-1;c>0&&t[c]===0;c--)t.pop();return t}compactArray(){return this._sortData(),this._data.map(bo)}};function yo(r,t){return r+en(t)}function en(r){let t=r;return t=t-(t>>1&1431655765),t=(t&858993459)+(t>>2&858993459),(t+(t>>4)&252645135)*16843009>>24}function xo(r,t){return r[0]-t[0]}function bo(r){return r[1]}});var Po={};I(Po,{InvalidAvgChunkSizeError:()=>Ue,InvalidChunkSizeError:()=>Me,InvalidContentError:()=>q,InvalidMinChunkSizeError:()=>Ve,InvalidParametersError:()=>ut,importByteStream:()=>Fo,importBytes:()=>Co,importDirectory:()=>zo,importFile:()=>$e,importer:()=>Ge});function Bn(r){return r[Symbol.asyncIterator]!=null}function An(r){if(Bn(r))return(async()=>{for await(let t of r)return t})();for(let t of r)return t}var jt=An;function Sn(r){return r[Symbol.asyncIterator]!=null}function kn(r,t=1){return t=Number(t),Sn(r)?async function*(){let e=[];if(t<1&&(t=1),t!==Math.round(t))throw new Error("Batch size must be an integer");for await(let n of r)for(e.push(n);e.length>=t;)yield e.slice(0,t),e=e.slice(t);for(;e.length>0;)yield e.slice(0,t),e=e.slice(t)}():function*(){let e=[];if(t<1&&(t=1),t!==Math.round(t))throw new Error("Batch size must be an integer");for(let n of r)for(e.push(n);e.length>=t;)yield e.slice(0,t),e=e.slice(t);for(;e.length>0;)yield e.slice(0,t),e=e.slice(t)}()}var Pt=kn;async function*lt(r,t=1){for await(let e of Pt(r,t)){let n=e.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 G(r=0){return new Uint8Array(r)}function v(r=0){return new Uint8Array(r)}function dt(r,t){t==null&&(t=r.reduce((i,o)=>i+o.length,0));let e=v(t),n=0;for(let i of r)e.set(i,n),n+=i.length;return e}function Xe(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}var Je=Symbol.for("@achingbrain/uint8arraylist");function We(r,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let e=0;for(let n of r){let i=e+n.byteLength;if(t<i)return{buf:n,index:t-e};e=i}throw new RangeError("index is out of bounds")}function Ut(r){return!!r?.[Je]}var et=class r{bufs;length;[Je]=!0;constructor(...t){this.bufs=[],this.length=0,t.length>0&&this.appendAll(t)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...t){this.appendAll(t)}appendAll(t){let e=0;for(let n of t)if(n instanceof Uint8Array)e+=n.byteLength,this.bufs.push(n);else if(Ut(n))e+=n.byteLength,this.bufs.push(...n.bufs);else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}prepend(...t){this.prependAll(t)}prependAll(t){let e=0;for(let n of t.reverse())if(n instanceof Uint8Array)e+=n.byteLength,this.bufs.unshift(n);else if(Ut(n))e+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}get(t){let e=We(this.bufs,t);return e.buf[e.index]}set(t,e){let n=We(this.bufs,t);n.buf[n.index]=e}write(t,e=0){if(t instanceof Uint8Array)for(let n=0;n<t.length;n++)this.set(e+n,t[n]);else if(Ut(t))for(let n=0;n<t.length;n++)this.set(e+n,t.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(t){if(t=Math.trunc(t),!(Number.isNaN(t)||t<=0)){if(t===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(t>=this.bufs[0].byteLength)t-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(t),this.length-=t;break}}}slice(t,e){let{bufs:n,length:i}=this._subList(t,e);return dt(n,i)}subarray(t,e){let{bufs:n,length:i}=this._subList(t,e);return n.length===1?n[0]:dt(n,i)}sublist(t,e){let{bufs:n,length:i}=this._subList(t,e),o=new r;return o.length=i,o.bufs=[...n],o}_subList(t,e){if(t=t??0,e=e??this.length,t<0&&(t=this.length+t),e<0&&(e=this.length+e),t<0||e>this.length)throw new RangeError("index is out of bounds");if(t===e)return{bufs:[],length:0};if(t===0&&e===this.length)return{bufs:this.bufs,length:this.length};let n=[],i=0;for(let o=0;o<this.bufs.length;o++){let a=this.bufs[o],c=i,l=c+a.byteLength;if(i=l,t>=l)continue;let x=t>=c&&t<l,f=e>c&&e<=l;if(x&&f){if(t===c&&e===l){n.push(a);break}let w=t-c;n.push(a.subarray(w,w+(e-t)));break}if(x){if(t===0){n.push(a);continue}n.push(a.subarray(t-c));continue}if(f){if(e===l){n.push(a);break}n.push(a.subarray(0,e-c));break}n.push(a)}return{bufs:n,length:e-t}}indexOf(t,e=0){if(!Ut(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(e=Number(e??0),isNaN(e)&&(e=0),e<0&&(e=this.length+e),e<0&&(e=0),t.length===0)return e>this.length?this.length:e;let i=n.byteLength;if(i===0)throw new TypeError("search must be at least 1 byte long");let o=256,a=new Int32Array(o);for(let w=0;w<o;w++)a[w]=-1;for(let w=0;w<i;w++)a[n[w]]=w;let c=a,l=this.byteLength-n.byteLength,x=n.byteLength-1,f;for(let w=e;w<=l;w+=f){f=0;for(let S=x;S>=0;S--){let s=this.get(w+S);if(n[S]!==s){f=Math.max(1,S-c[s]);break}}if(f===0)return w}return-1}getInt8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getInt8(0)}setInt8(t,e){let n=v(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,e),this.write(n,t)}getInt16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,e)}setInt16(t,e,n){let i=G(2);new DataView(i.buffer,i.byteOffset,i.byteLength).setInt16(0,e,n),this.write(i,t)}getInt32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,e)}setInt32(t,e,n){let i=G(4);new DataView(i.buffer,i.byteOffset,i.byteLength).setInt32(0,e,n),this.write(i,t)}getBigInt64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,e)}setBigInt64(t,e,n){let i=G(8);new DataView(i.buffer,i.byteOffset,i.byteLength).setBigInt64(0,e,n),this.write(i,t)}getUint8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getUint8(0)}setUint8(t,e){let n=v(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,e),this.write(n,t)}getUint16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,e)}setUint16(t,e,n){let i=G(2);new DataView(i.buffer,i.byteOffset,i.byteLength).setUint16(0,e,n),this.write(i,t)}getUint32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,e)}setUint32(t,e,n){let i=G(4);new DataView(i.buffer,i.byteOffset,i.byteLength).setUint32(0,e,n),this.write(i,t)}getBigUint64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,e)}setBigUint64(t,e,n){let i=G(8);new DataView(i.buffer,i.byteOffset,i.byteLength).setBigUint64(0,e,n),this.write(i,t)}getFloat32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,e)}setFloat32(t,e,n){let i=G(4);new DataView(i.buffer,i.byteOffset,i.byteLength).setFloat32(0,e,n),this.write(i,t)}getFloat64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,e)}setFloat64(t,e,n){let i=G(8);new DataView(i.buffer,i.byteOffset,i.byteLength).setFloat64(0,e,n),this.write(i,t)}equals(t){if(t==null||!(t instanceof r)||t.bufs.length!==this.bufs.length)return!1;for(let e=0;e<this.bufs.length;e++)if(!Xe(this.bufs[e],t.bufs[e]))return!1;return!0}static fromUint8Arrays(t,e){let n=new r;return n.bufs=t,e==null&&(e=t.reduce((i,o)=>i+o.byteLength,0)),n.length=e,n}};var En=262144,je=(r={})=>{let t=r.chunkSize??En;return async function*(n){let i=new et,o=0,a=!1;for await(let c of n)for(i.append(c),o+=c.length;o>=t;)if(yield i.slice(0,t),a=!0,t===i.length)i=new et,o=0;else{let l=new et;l.append(i.sublist(t)),i=l,o-=t}(!a||o>0)&&(yield i.subarray(0,o))}};var bt={};I(bt,{code:()=>ki,createLink:()=>wr,createNode:()=>gr,decode:()=>Ei,encode:()=>C,name:()=>Si,prepare:()=>z,validate:()=>ue});var ie={};I(ie,{base32:()=>it,base32hex:()=>Mn,base32hexpad:()=>Rn,base32hexpadupper:()=>Hn,base32hexupper:()=>Vn,base32pad:()=>Pn,base32padupper:()=>Un,base32upper:()=>Fn,base32z:()=>On});var rt={};I(rt,{coerce:()=>P,empty:()=>Ze,equals:()=>Zt,fromHex:()=>Dn,fromString:()=>Qt,isBinary:()=>Nn,toHex:()=>In,toString:()=>Yt});var Ze=new Uint8Array(0);function In(r){return r.reduce((t,e)=>t+e.toString(16).padStart(2,"0"),"")}function Dn(r){let t=r.match(/../g);return t!=null?new Uint8Array(t.map(e=>parseInt(e,16))):Ze}function Zt(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}function P(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 Nn(r){return r instanceof ArrayBuffer||ArrayBuffer.isView(r)}function Qt(r){return new TextEncoder().encode(r)}function Yt(r){return new TextDecoder().decode(r)}function Tn(r,t){if(r.length>=255)throw new TypeError("Alphabet too long");for(var e=new Uint8Array(256),n=0;n<e.length;n++)e[n]=255;for(var i=0;i<r.length;i++){var o=r.charAt(i),a=o.charCodeAt(0);if(e[a]!==255)throw new TypeError(o+" is ambiguous");e[a]=i}var c=r.length,l=r.charAt(0),x=Math.log(c)/Math.log(256),f=Math.log(256)/Math.log(c);function w(h){if(h instanceof Uint8Array||(ArrayBuffer.isView(h)?h=new Uint8Array(h.buffer,h.byteOffset,h.byteLength):Array.isArray(h)&&(h=Uint8Array.from(h))),!(h instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(h.length===0)return"";for(var d=0,E=0,u=0,p=h.length;u!==p&&h[u]===0;)u++,d++;for(var m=(p-u)*f+1>>>0,y=new Uint8Array(m);u!==p;){for(var b=h[u],_=0,g=m-1;(b!==0||_<E)&&g!==-1;g--,_++)b+=256*y[g]>>>0,y[g]=b%c>>>0,b=b/c>>>0;if(b!==0)throw new Error("Non-zero carry");E=_,u++}for(var A=m-E;A!==m&&y[A]===0;)A++;for(var O=l.repeat(d);A<m;++A)O+=r.charAt(y[A]);return O}function S(h){if(typeof h!="string")throw new TypeError("Expected String");if(h.length===0)return new Uint8Array;var d=0;if(h[d]!==" "){for(var E=0,u=0;h[d]===l;)E++,d++;for(var p=(h.length-d)*x+1>>>0,m=new Uint8Array(p);h[d];){var y=e[h.charCodeAt(d)];if(y===255)return;for(var b=0,_=p-1;(y!==0||b<u)&&_!==-1;_--,b++)y+=c*m[_]>>>0,m[_]=y%256>>>0,y=y/256>>>0;if(y!==0)throw new Error("Non-zero carry");u=b,d++}if(h[d]!==" "){for(var g=p-u;g!==p&&m[g]===0;)g++;for(var A=new Uint8Array(E+(p-g)),O=E;g!==p;)A[O++]=m[g++];return A}}}function s(h){var d=S(h);if(d)return d;throw new Error(`Non-${t} character`)}return{encode:w,decodeUnsafe:S,decode:s}}var Ln=Tn,vn=Ln,Qe=vn;var te=class{name;prefix;baseEncode;constructor(t,e,n){this.name=t,this.prefix=e,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},ee=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,e,n){this.name=t,this.prefix=e;let i=e.codePointAt(0);if(i===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=i,this.baseDecode=n}decode(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return Ye(this,t)}},re=class{decoders;constructor(t){this.decoders=t}or(t){return Ye(this,t)}decode(t){let e=t[0],n=this.decoders[e];if(n!=null)return n.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function Ye(r,t){return new re({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var ne=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,e,n,i){this.name=t,this.prefix=e,this.baseEncode=n,this.baseDecode=i,this.encoder=new te(t,e,n),this.decoder=new ee(t,e,i)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function nt({name:r,prefix:t,encode:e,decode:n}){return new ne(r,t,e,n)}function K({name:r,prefix:t,alphabet:e}){let{encode:n,decode:i}=Qe(e,r);return nt({prefix:t,name:r,encode:n,decode:o=>P(i(o))})}function zn(r,t,e,n){let i={};for(let f=0;f<t.length;++f)i[t[f]]=f;let o=r.length;for(;r[o-1]==="=";)--o;let a=new Uint8Array(o*e/8|0),c=0,l=0,x=0;for(let f=0;f<o;++f){let w=i[r[f]];if(w===void 0)throw new SyntaxError(`Non-${n} character`);l=l<<e|w,c+=e,c>=8&&(c-=8,a[x++]=255&l>>c)}if(c>=e||(255&l<<8-c)!==0)throw new SyntaxError("Unexpected end of data");return a}function Cn(r,t,e){let n=t[t.length-1]==="=",i=(1<<e)-1,o="",a=0,c=0;for(let l=0;l<r.length;++l)for(c=c<<8|r[l],a+=8;a>e;)a-=e,o+=t[i&c>>a];if(a!==0&&(o+=t[i&c<<e-a]),n)for(;(o.length*e&7)!==0;)o+="=";return o}function k({name:r,prefix:t,bitsPerChar:e,alphabet:n}){return nt({prefix:t,name:r,encode(i){return Cn(i,n,e)},decode(i){return zn(i,n,e,r)}})}var it=k({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Fn=k({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Pn=k({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Un=k({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Mn=k({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Vn=k({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Rn=k({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Hn=k({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),On=k({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var oe={};I(oe,{base36:()=>pt,base36upper:()=>Gn});var pt=K({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Gn=K({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var se={};I(se,{base58btc:()=>R,base58flickr:()=>$n});var R=K({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),$n=K({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var qn=rr,tr=128,Kn=127,Xn=~Kn,Wn=Math.pow(2,31);function rr(r,t,e){t=t||[],e=e||0;for(var n=e;r>=Wn;)t[e++]=r&255|tr,r/=128;for(;r&Xn;)t[e++]=r&255|tr,r>>>=7;return t[e]=r|0,rr.bytes=e-n+1,t}var Jn=ae,jn=128,er=127;function ae(r,n){var e=0,n=n||0,i=0,o=n,a,c=r.length;do{if(o>=c)throw ae.bytes=0,new RangeError("Could not decode varint");a=r[o++],e+=i<28?(a&er)<<i:(a&er)*Math.pow(2,i),i+=7}while(a>=jn);return ae.bytes=o-n,e}var Zn=Math.pow(2,7),Qn=Math.pow(2,14),Yn=Math.pow(2,21),ti=Math.pow(2,28),ei=Math.pow(2,35),ri=Math.pow(2,42),ni=Math.pow(2,49),ii=Math.pow(2,56),oi=Math.pow(2,63),si=function(r){return r<Zn?1:r<Qn?2:r<Yn?3:r<ti?4:r<ei?5:r<ri?6:r<ni?7:r<ii?8:r<oi?9:10},ai={encode:qn,decode:Jn,encodingLength:si},ci=ai,mt=ci;function gt(r,t=0){return[mt.decode(r,t),mt.decode.bytes]}function ot(r,t,e=0){return mt.encode(r,t,e),t}function st(r){return mt.encodingLength(r)}function j(r,t){let e=t.byteLength,n=st(r),i=n+st(e),o=new Uint8Array(i+e);return ot(r,o,0),ot(e,o,n),o.set(t,i),new at(r,e,t,o)}function nr(r){let t=P(r),[e,n]=gt(t),[i,o]=gt(t.subarray(n)),a=t.subarray(n+o);if(a.byteLength!==i)throw new Error("Incorrect length");return new at(e,i,a,t)}function ir(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&Zt(r.bytes,e.bytes)}}var at=class{code;size;digest;bytes;constructor(t,e,n,i){this.code=t,this.size=e,this.digest=n,this.bytes=i}};function or(r,t){let{bytes:e,version:n}=r;switch(n){case 0:return fi(e,ce(r),t??R.encoder);default:return ui(e,ce(r),t??it.encoder)}}var sr=new WeakMap;function ce(r){let t=sr.get(r);if(t==null){let e=new Map;return sr.set(r,e),e}return t}var D=class r{code;version;multihash;bytes;"/";constructor(t,e,n,i){this.code=e,this.version=t,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:t,multihash:e}=this;if(t!==yt)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==li)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(e)}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:t,digest:e}=this.multihash,n=j(t,e);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(t){return r.equals(this,t)}static equals(t,e){let n=e;return n!=null&&t.code===n.code&&t.version===n.version&&ir(t.multihash,n.multihash)}toString(t){return or(this,t)}toJSON(){return{"/":or(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(t){if(t==null)return null;let e=t;if(e instanceof r)return e;if(e["/"]!=null&&e["/"]===e.bytes||e.asCID===e){let{version:n,code:i,multihash:o,bytes:a}=e;return new r(n,i,o,a??ar(n,i,o.bytes))}else if(e[di]===!0){let{version:n,multihash:i,code:o}=e,a=nr(i);return r.create(n,o,a)}else return null}static create(t,e,n){if(typeof e!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(t){case 0:{if(e!==yt)throw new Error(`Version 0 CID must use dag-pb (code: ${yt}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let i=ar(t,e,n.bytes);return new r(t,e,n,i)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,yt,t)}static createV1(t,e){return r.create(1,t,e)}static decode(t){let[e,n]=r.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return e}static decodeFirst(t){let e=r.inspectBytes(t),n=e.size-e.multihashSize,i=P(t.subarray(n,n+e.multihashSize));if(i.byteLength!==e.multihashSize)throw new Error("Incorrect length");let o=i.subarray(e.multihashSize-e.digestSize),a=new at(e.multihashCode,e.digestSize,o,i);return[e.version===0?r.createV0(a):r.createV1(e.codec,a),t.subarray(e.size)]}static inspectBytes(t){let e=0,n=()=>{let[w,S]=gt(t.subarray(e));return e+=S,w},i=n(),o=yt;if(i===18?(i=0,e=0):o=n(),i!==0&&i!==1)throw new RangeError(`Invalid CID version ${i}`);let a=e,c=n(),l=n(),x=e+l,f=x-a;return{version:i,codec:o,multihashCode:c,digestSize:l,multihashSize:f,size:x}}static parse(t,e){let[n,i]=hi(t,e),o=r.decode(i);if(o.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return ce(o).set(n,t),o}};function hi(r,t){switch(r[0]){case"Q":{let e=t??R;return[R.prefix,e.decode(`${R.prefix}${r}`)]}case R.prefix:{let e=t??R;return[R.prefix,e.decode(r)]}case it.prefix:{let e=t??it;return[it.prefix,e.decode(r)]}case pt.prefix:{let e=t??pt;return[pt.prefix,e.decode(r)]}default:{if(t==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[r[0],t.decode(r)]}}}function fi(r,t,e){let{prefix:n}=e;if(n!==R.prefix)throw Error(`Cannot string encode V0 in ${e.name} encoding`);let i=t.get(n);if(i==null){let o=e.encode(r).slice(1);return t.set(n,o),o}else return i}function ui(r,t,e){let{prefix:n}=e,i=t.get(n);if(i==null){let o=e.encode(r);return t.set(n,o),o}else return i}var yt=112,li=18;function ar(r,t,e){let n=st(r),i=n+st(t),o=new Uint8Array(i+e.byteLength);return ot(r,o,0),ot(t,o,n),o.set(e,i),o}var di=Symbol.for("@ipld/js-cid/CID");var pi=new TextDecoder;function he(r,t){let e=0;for(let n=0;;n+=7){if(n>=64)throw new Error("protobuf: varint overflow");if(t>=r.length)throw new Error("protobuf: unexpected end of data");let i=r[t++];if(e+=n<28?(i&127)<<n:(i&127)*2**n,i<128)break}return[e,t]}function Vt(r,t){let e;[e,t]=he(r,t);let n=t+e;if(e<0||n<0)throw new Error("protobuf: invalid length");if(n>r.length)throw new Error("protobuf: unexpected end of data");return[r.subarray(t,n),n]}function cr(r,t){let e;return[e,t]=he(r,t),[e&7,e>>3,t]}function mi(r){let t={},e=r.length,n=0;for(;n<e;){let i,o;if([i,o,n]=cr(r,n),o===1){if(t.Hash)throw new Error("protobuf: (PBLink) duplicate Hash section");if(i!==2)throw new Error(`protobuf: (PBLink) wrong wireType (${i}) for Hash`);if(t.Name!==void 0)throw new Error("protobuf: (PBLink) invalid order, found Name before Hash");if(t.Tsize!==void 0)throw new Error("protobuf: (PBLink) invalid order, found Tsize before Hash");[t.Hash,n]=Vt(r,n)}else if(o===2){if(t.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(t.Tsize!==void 0)throw new Error("protobuf: (PBLink) invalid order, found Tsize before Name");let a;[a,n]=Vt(r,n),t.Name=pi.decode(a)}else if(o===3){if(t.Tsize!==void 0)throw new Error("protobuf: (PBLink) duplicate Tsize section");if(i!==0)throw new Error(`protobuf: (PBLink) wrong wireType (${i}) for Tsize`);[t.Tsize,n]=he(r,n)}else throw new Error(`protobuf: (PBLink) invalid fieldNumber, expected 1, 2 or 3, got ${o}`)}if(n>e)throw new Error("protobuf: (PBLink) unexpected end of data");return t}function hr(r){let t=r.length,e=0,n,i=!1,o;for(;e<t;){let c,l;if([c,l,e]=cr(r,e),c!==2)throw new Error(`protobuf: (PBNode) invalid wireType, expected 2, got ${c}`);if(l===1){if(o)throw new Error("protobuf: (PBNode) duplicate Data section");[o,e]=Vt(r,e),n&&(i=!0)}else if(l===2){if(i)throw new Error("protobuf: (PBNode) duplicate Links section");n||(n=[]);let x;[x,e]=Vt(r,e),n.push(mi(x))}else throw new Error(`protobuf: (PBNode) invalid fieldNumber, expected 1 or 2, got ${l}`)}if(e>t)throw new Error("protobuf: (PBNode) unexpected end of data");let a={};return o&&(a.Data=o),a.Links=n||[],a}var ur=new TextEncoder,fr=2**32,gi=2**31;function wi(r,t){let e=t.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");e=xt(t,e,r.Tsize)-1,t[e]=24}if(typeof r.Name=="string"){let n=ur.encode(r.Name);e-=n.length,t.set(n,e),e=xt(t,e,n.length)-1,t[e]=18}return r.Hash&&(e-=r.Hash.length,t.set(r.Hash,e),e=xt(t,e,r.Hash.length)-1,t[e]=10),t.length-e}function lr(r){let t=xi(r),e=new Uint8Array(t),n=t;if(r.Data&&(n-=r.Data.length,e.set(r.Data,n),n=xt(e,n,r.Data.length)-1,e[n]=10),r.Links)for(let i=r.Links.length-1;i>=0;i--){let o=wi(r.Links[i],e.subarray(0,n));n-=o,n=xt(e,n,o)-1,e[n]=18}return e}function yi(r){let t=0;if(r.Hash){let e=r.Hash.length;t+=1+e+ct(e)}if(typeof r.Name=="string"){let e=ur.encode(r.Name).length;t+=1+e+ct(e)}return typeof r.Tsize=="number"&&(t+=1+ct(r.Tsize)),t}function xi(r){let t=0;if(r.Data){let e=r.Data.length;t+=1+e+ct(e)}if(r.Links)for(let e of r.Links){let n=yi(e);t+=1+n+ct(n)}return t}function xt(r,t,e){t-=ct(e);let n=t;for(;e>=gi;)r[t++]=e&127|128,e/=128;for(;e>=128;)r[t++]=e&127|128,e>>>=7;return r[t]=e,n}function ct(r){return r%2===0&&r++,Math.floor((bi(r)+6)/7)}function bi(r){let t=0;return r>=fr&&(r=Math.floor(r/fr),t=32),r>=65536&&(r>>>=16,t+=16),r>=256&&(r>>>=8,t+=8),t+_i[r]}var _i=[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 Bi=["Data","Links"],Ai=["Hash","Name","Tsize"],fe=new TextEncoder;function pr(r,t){if(r===t)return 0;let e=r.Name?fe.encode(r.Name):[],n=t.Name?fe.encode(t.Name):[],i=e.length,o=n.length;for(let a=0,c=Math.min(i,o);a<c;++a)if(e[a]!==n[a]){i=e[a],o=n[a];break}return i<o?-1:o<i?1:0}function dr(r,t){return!Object.keys(r).some(e=>!t.includes(e))}function mr(r){if(typeof r.asCID=="object"){let e=D.asCID(r);if(!e)throw new TypeError("Invalid DAG-PB form");return{Hash:e}}if(typeof r!="object"||Array.isArray(r))throw new TypeError("Invalid DAG-PB form");let t={};if(r.Hash){let e=D.asCID(r.Hash);try{e||(typeof r.Hash=="string"?e=D.parse(r.Hash):r.Hash instanceof Uint8Array&&(e=D.decode(r.Hash)))}catch(n){throw new TypeError(`Invalid DAG-PB form: ${n.message}`)}e&&(t.Hash=e)}if(!t.Hash)throw new TypeError("Invalid DAG-PB form");return typeof r.Name=="string"&&(t.Name=r.Name),typeof r.Tsize=="number"&&(t.Tsize=r.Tsize),t}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 t={};if(r.Data!==void 0)if(typeof r.Data=="string")t.Data=fe.encode(r.Data);else if(r.Data instanceof Uint8Array)t.Data=r.Data;else throw new TypeError("Invalid DAG-PB form");if(r.Links!==void 0)if(Array.isArray(r.Links))t.Links=r.Links.map(mr),t.Links.sort(pr);else throw new TypeError("Invalid DAG-PB form");else t.Links=[];return t}function ue(r){if(!r||typeof r!="object"||Array.isArray(r)||r instanceof Uint8Array||r["/"]&&r["/"]===r.bytes)throw new TypeError("Invalid DAG-PB form");if(!dr(r,Bi))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 t=0;t<r.Links.length;t++){let e=r.Links[t];if(!e||typeof e!="object"||Array.isArray(e)||e instanceof Uint8Array||e["/"]&&e["/"]===e.bytes)throw new TypeError("Invalid DAG-PB form (bad link)");if(!dr(e,Ai))throw new TypeError("Invalid DAG-PB form (extraneous properties on link)");if(e.Hash===void 0)throw new TypeError("Invalid DAG-PB form (link must have a Hash)");if(e.Hash==null||!e.Hash["/"]||e.Hash["/"]!==e.Hash.bytes)throw new TypeError("Invalid DAG-PB form (link Hash must be a CID)");if(e.Name!==void 0&&typeof e.Name!="string")throw new TypeError("Invalid DAG-PB form (link Name must be a string)");if(e.Tsize!==void 0){if(typeof e.Tsize!="number"||e.Tsize%1!==0)throw new TypeError("Invalid DAG-PB form (link Tsize must be an integer)");if(e.Tsize<0)throw new TypeError("Invalid DAG-PB form (link Tsize cannot be negative)")}if(t>0&&pr(e,r.Links[t-1])===-1)throw new TypeError("Invalid DAG-PB form (links must be sorted by Name bytes)")}}function gr(r,t=[]){return z({Data:r,Links:t})}function wr(r,t,e){return mr({Hash:e,Name:r,Tsize:t})}function yr(r){return r instanceof ArrayBuffer?new Uint8Array(r,0,r.byteLength):r}var Si="dag-pb",ki=112;function C(r){ue(r);let t={};return r.Links&&(t.Links=r.Links.map(e=>{let n={};return e.Hash&&(n.Hash=e.Hash.bytes),e.Name!==void 0&&(n.Name=e.Name),e.Tsize!==void 0&&(n.Tsize=e.Tsize),n})),r.Data&&(t.Data=r.Data),lr(t)}function Ei(r){let t=yr(r),e=hr(t),n={};return e.Data&&(n.Data=e.Data),e.Links&&(n.Links=e.Links.map(i=>{let o={};try{o.Hash=D.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 _t=class r extends Error{static name="InvalidTypeError";static code="ERR_INVALID_TYPE";name=r.name;code=r.code;constructor(t="Invalid type"){super(t)}};var Ii=Math.pow(2,7),Di=Math.pow(2,14),Ni=Math.pow(2,21),xr=Math.pow(2,28),br=Math.pow(2,35),_r=Math.pow(2,42),Br=Math.pow(2,49),T=128,X=127;function Bt(r){if(r<Ii)return 1;if(r<Di)return 2;if(r<Ni)return 3;if(r<xr)return 4;if(r<br)return 5;if(r<_r)return 6;if(r<Br)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Ar(r,t,e=0){switch(Bt(r)){case 8:t[e++]=r&255|T,r/=128;case 7:t[e++]=r&255|T,r/=128;case 6:t[e++]=r&255|T,r/=128;case 5:t[e++]=r&255|T,r/=128;case 4:t[e++]=r&255|T,r>>>=7;case 3:t[e++]=r&255|T,r>>>=7;case 2:t[e++]=r&255|T,r>>>=7;case 1:{t[e++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return t}function Sr(r,t){let e=r[t],n=0;if(n+=e&X,e<T||(e=r[t+1],n+=(e&X)<<7,e<T)||(e=r[t+2],n+=(e&X)<<14,e<T)||(e=r[t+3],n+=(e&X)<<21,e<T)||(e=r[t+4],n+=(e&X)*xr,e<T)||(e=r[t+5],n+=(e&X)*br,e<T)||(e=r[t+6],n+=(e&X)*_r,e<T)||(e=r[t+7],n+=(e&X)*Br,e<T))return n;throw new RangeError("Could not decode varint")}var le=new Float32Array([-0]),W=new Uint8Array(le.buffer);function kr(r,t,e){le[0]=r,t[e]=W[0],t[e+1]=W[1],t[e+2]=W[2],t[e+3]=W[3]}function Er(r,t){return W[0]=r[t],W[1]=r[t+1],W[2]=r[t+2],W[3]=r[t+3],le[0]}var de=new Float64Array([-0]),N=new Uint8Array(de.buffer);function Ir(r,t,e){de[0]=r,t[e]=N[0],t[e+1]=N[1],t[e+2]=N[2],t[e+3]=N[3],t[e+4]=N[4],t[e+5]=N[5],t[e+6]=N[6],t[e+7]=N[7]}function Dr(r,t){return N[0]=r[t],N[1]=r[t+1],N[2]=r[t+2],N[3]=r[t+3],N[4]=r[t+4],N[5]=r[t+5],N[6]=r[t+6],N[7]=r[t+7],de[0]}var Ti=BigInt(Number.MAX_SAFE_INTEGER),Li=BigInt(Number.MIN_SAFE_INTEGER),F=class r{lo;hi;constructor(t,e){this.lo=t|0,this.hi=e|0}toNumber(t=!1){if(!t&&this.hi>>>31>0){let e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(e+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(t=!1){if(t)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(BigInt(e)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(t=!1){return this.toBigInt(t).toString()}zzEncode(){let t=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^t)>>>0,this.lo=(this.lo<<1^t)>>>0,this}zzDecode(){let t=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^t)>>>0,this.hi=(this.hi>>>1^t)>>>0,this}length(){let t=this.lo,e=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?e===0?t<16384?t<128?1:2:t<2097152?3:4:e<16384?e<128?5:6:e<2097152?7:8:n<128?9:10}static fromBigInt(t){if(t===0n)return Z;if(t<Ti&&t>Li)return this.fromNumber(Number(t));let e=t<0n;e&&(t=-t);let n=t>>32n,i=t-(n<<32n);return e&&(n=~n|0n,i=~i|0n,++i>Nr&&(i=0n,++n>Nr&&(n=0n))),new r(Number(i),Number(n))}static fromNumber(t){if(t===0)return Z;let e=t<0;e&&(t=-t);let n=t>>>0,i=(t-n)/4294967296>>>0;return e&&(i=~i>>>0,n=~n>>>0,++n>4294967295&&(n=0,++i>4294967295&&(i=0))),new r(n,i)}static from(t){return typeof t=="number"?r.fromNumber(t):typeof t=="bigint"?r.fromBigInt(t):typeof t=="string"?r.fromBigInt(BigInt(t)):t.low!=null||t.high!=null?new r(t.low>>>0,t.high>>>0):Z}},Z=new F(0,0);Z.toBigInt=function(){return 0n};Z.zzEncode=Z.zzDecode=function(){return this};Z.length=function(){return 1};var Nr=4294967296n;function Tr(r){let t=0,e=0;for(let n=0;n<r.length;++n)e=r.charCodeAt(n),e<128?t+=1:e<2048?t+=2:(e&64512)===55296&&(r.charCodeAt(n+1)&64512)===56320?(++n,t+=4):t+=3;return t}function Lr(r,t,e){if(e-t<1)return"";let i,o=[],a=0,c;for(;t<e;)c=r[t++],c<128?o[a++]=c:c>191&&c<224?o[a++]=(c&31)<<6|r[t++]&63:c>239&&c<365?(c=((c&7)<<18|(r[t++]&63)<<12|(r[t++]&63)<<6|r[t++]&63)-65536,o[a++]=55296+(c>>10),o[a++]=56320+(c&1023)):o[a++]=(c&15)<<12|(r[t++]&63)<<6|r[t++]&63,a>8191&&((i??(i=[])).push(String.fromCharCode.apply(String,o)),a=0);return i!=null?(a>0&&i.push(String.fromCharCode.apply(String,o.slice(0,a))),i.join("")):String.fromCharCode.apply(String,o.slice(0,a))}function pe(r,t,e){let n=e,i,o;for(let a=0;a<r.length;++a)i=r.charCodeAt(a),i<128?t[e++]=i:i<2048?(t[e++]=i>>6|192,t[e++]=i&63|128):(i&64512)===55296&&((o=r.charCodeAt(a+1))&64512)===56320?(i=65536+((i&1023)<<10)+(o&1023),++a,t[e++]=i>>18|240,t[e++]=i>>12&63|128,t[e++]=i>>6&63|128,t[e++]=i&63|128):(t[e++]=i>>12|224,t[e++]=i>>6&63|128,t[e++]=i&63|128);return e-n}function U(r,t){return RangeError(`index out of range: ${r.pos} + ${t??1} > ${r.len}`)}function Rt(r,t){return(r[t-4]|r[t-3]<<8|r[t-2]<<16|r[t-1]<<24)>>>0}var me=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(t){this.buf=t,this.pos=0,this.len=t.length}uint32(){let t=4294967295;if(t=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(t=(t|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return t;if((this.pos+=5)>this.len)throw this.pos=this.len,U(this,10);return t}int32(){return this.uint32()|0}sint32(){let t=this.uint32();return t>>>1^-(t&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw U(this,4);return Rt(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw U(this,4);return Rt(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw U(this,4);let t=Er(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw U(this,4);let t=Dr(this.buf,this.pos);return this.pos+=8,t}bytes(){let t=this.uint32(),e=this.pos,n=this.pos+t;if(n>this.len)throw U(this,t);return this.pos+=t,e===n?new Uint8Array(0):this.buf.subarray(e,n)}string(){let t=this.bytes();return Lr(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw U(this,t);this.pos+=t}else do if(this.pos>=this.len)throw U(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(t){switch(t){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(t=this.uint32()&7)!==4;)this.skipType(t);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${t} at offset ${this.pos}`)}return this}readLongVarint(){let t=new F(0,0),e=0;if(this.len-this.pos>4){for(;e<4;++e)if(t.lo=(t.lo|(this.buf[this.pos]&127)<<e*7)>>>0,this.buf[this.pos++]<128)return t;if(t.lo=(t.lo|(this.buf[this.pos]&127)<<28)>>>0,t.hi=(t.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return t;e=0}else{for(;e<3;++e){if(this.pos>=this.len)throw U(this);if(t.lo=(t.lo|(this.buf[this.pos]&127)<<e*7)>>>0,this.buf[this.pos++]<128)return t}return t.lo=(t.lo|(this.buf[this.pos++]&127)<<e*7)>>>0,t}if(this.len-this.pos>4){for(;e<5;++e)if(t.hi=(t.hi|(this.buf[this.pos]&127)<<e*7+3)>>>0,this.buf[this.pos++]<128)return t}else for(;e<5;++e){if(this.pos>=this.len)throw U(this);if(t.hi=(t.hi|(this.buf[this.pos]&127)<<e*7+3)>>>0,this.buf[this.pos++]<128)return t}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw U(this,8);let t=Rt(this.buf,this.pos+=4),e=Rt(this.buf,this.pos+=4);return new F(t,e)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let t=Sr(this.buf,this.pos);return this.pos+=Bt(t),t}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 ge(r){return new me(r instanceof Uint8Array?r:r.subarray())}function At(r,t,e){let n=ge(r);return t.decode(n,void 0,e)}var we={};I(we,{base10:()=>vi});var vi=K({prefix:"9",name:"base10",alphabet:"0123456789"});var ye={};I(ye,{base16:()=>zi,base16upper:()=>Ci});var zi=k({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Ci=k({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var xe={};I(xe,{base2:()=>Fi});var Fi=k({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var be={};I(be,{base256emoji:()=>Ri});var zr=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}"),Pi=zr.reduce((r,t,e)=>(r[e]=t,r),[]),Ui=zr.reduce((r,t,e)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return r[n]=e,r},[]);function Mi(r){return r.reduce((t,e)=>(t+=Pi[e],t),"")}function Vi(r){let t=[];for(let e of r){let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);let i=Ui[n];if(i==null)throw new Error(`Non-base256emoji character: ${e}`);t.push(i)}return new Uint8Array(t)}var Ri=nt({prefix:"\u{1F680}",name:"base256emoji",encode:Mi,decode:Vi});var _e={};I(_e,{base64:()=>Hi,base64pad:()=>Oi,base64url:()=>Gi,base64urlpad:()=>$i});var Hi=k({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Oi=k({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Gi=k({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),$i=k({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Be={};I(Be,{base8:()=>qi});var qi=k({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Ae={};I(Ae,{identity:()=>Ki});var Ki=nt({prefix:"\0",name:"identity",encode:r=>Yt(r),decode:r=>Qt(r)});var $s=new TextEncoder,qs=new TextDecoder;var St={};I(St,{code:()=>Ht,decode:()=>ji,encode:()=>Ji,name:()=>Wi});var Wi="raw",Ht=85;function Ji(r){return P(r)}function ji(r){return P(r)}var Se={};I(Se,{identity:()=>Yi});var Cr=0,Zi="identity",Fr=P;function Qi(r){return j(Cr,Fr(r))}var Yi={code:Cr,name:Zi,encode:Fr,digest:Qi};var Ie={};I(Ie,{sha256:()=>Ee,sha512:()=>to});function Q({name:r,code:t,encode:e}){return new ke(r,t,e)}var ke=class{name;code;encode;constructor(t,e,n){this.name=t,this.code=e,this.encode=n}digest(t){if(t instanceof Uint8Array){let e=this.encode(t);return e instanceof Uint8Array?j(this.code,e):e.then(n=>j(this.code,n))}else throw Error("Unknown type, must be binary type")}};function Ur(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var Ee=Q({name:"sha2-256",code:18,encode:Ur("SHA-256")}),to=Q({name:"sha2-512",code:19,encode:Ur("SHA-512")});var De={...Ae,...xe,...Be,...we,...ye,...ie,...oe,...se,..._e,...be},ia={...Ie,...Se};function Vr(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var Mr=Vr("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Ne=Vr("ascii","a",r=>{let t="a";for(let e=0;e<r.length;e++)t+=String.fromCharCode(r[e]);return t},r=>{r=r.substring(1);let t=v(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),eo={utf8:Mr,"utf-8":Mr,hex:De.base16,latin1:Ne,ascii:Ne,binary:Ne,...De},Rr=eo;function ht(r,t="utf8"){let e=Rr[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.decoder.decode(`${e.prefix}${r}`)}function Te(r){let t=r??8192,e=t>>>1,n,i=t;return function(a){if(a<1||a>e)return v(a);i+a>t&&(n=v(t),i=0);let c=n.subarray(i,i+=a);return(i&7)!==0&&(i=(i|7)+1),c}}var Y=class{fn;len;next;val;constructor(t,e,n){this.fn=t,this.len=e,this.next=void 0,this.val=n}