@ipld/car
Version:
Content Addressable aRchive format reader and writer
4 lines • 56.5 kB
JavaScript
(function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.IpldCar = factory()}(typeof self !== 'undefined' ? self : this, function () {
"use strict";var IpldCar=(()=>{var qn=Object.create;var Me=Object.defineProperty;var Gn=Object.getOwnPropertyDescriptor;var jn=Object.getOwnPropertyNames;var Jn=Object.getPrototypeOf,Kn=Object.prototype.hasOwnProperty;var me=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),Kt=(e,t)=>{for(var r in t)Me(e,r,{get:t[r],enumerable:!0})},Wt=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of jn(t))!Kn.call(e,o)&&o!==r&&Me(e,o,{get:()=>t[o],enumerable:!(n=Gn(t,o))||n.enumerable});return e};var $e=(e,t,r)=>(r=e!=null?qn(Jn(e)):{},Wt(t||!e||!e.__esModule?Me(r,"default",{value:e,enumerable:!0}):r,e)),Wn=e=>Wt(Me({},"__esModule",{value:!0}),e);var wn=me((Sa,gn)=>{gn.exports=Mt;var mn=128,mi=127,gi=~mi,wi=Math.pow(2,31);function Mt(e,t,r){if(Number.MAX_SAFE_INTEGER&&e>Number.MAX_SAFE_INTEGER)throw Mt.bytes=0,new RangeError("Could not encode varint");t=t||[],r=r||0;for(var n=r;e>=wi;)t[r++]=e&255|mn,e/=128;for(;e&gi;)t[r++]=e&255|mn,e>>>=7;return t[r]=e|0,Mt.bytes=r-n+1,t}});var En=me((Ca,bn)=>{bn.exports=$t;var xi=128,xn=127;function $t(e,n){var r=0,n=n||0,o=0,i=n,a,c=e.length;do{if(i>=c||o>49)throw $t.bytes=0,new RangeError("Could not decode varint");a=e[i++],r+=o<28?(a&xn)<<o:(a&xn)*Math.pow(2,o),o+=7}while(a>=xi);return $t.bytes=i-n,r}});var _n=me((Na,vn)=>{var bi=Math.pow(2,7),Ei=Math.pow(2,14),vi=Math.pow(2,21),_i=Math.pow(2,28),Ai=Math.pow(2,35),ki=Math.pow(2,42),Ti=Math.pow(2,49),Ii=Math.pow(2,56),Ui=Math.pow(2,63);vn.exports=function(e){return e<bi?1:e<Ei?2:e<vi?3:e<_i?4:e<Ai?5:e<ki?6:e<Ti?7:e<Ii?8:e<Ui?9:10}});var tt=me((Oa,An)=>{An.exports={encode:wn(),decode:En(),encodingLength:_n()}});var Cn=me(()=>{});var Ki={};Kt(Ki,{CarBlockIterator:()=>ft,CarBufferReader:()=>st,CarBufferWriter:()=>qt,CarCIDIterator:()=>dt,CarIndexedReader:()=>ct,CarIndexer:()=>te,CarReader:()=>re,CarWriter:()=>ht,contentType:()=>Ji});var Xn=["Object","RegExp","Date","Error","Map","Set","WeakMap","WeakSet","ArrayBuffer","SharedArrayBuffer","DataView","Promise","URL","HTMLElement","Int8Array","Uint8ClampedArray","Int16Array","Uint16Array","Int32Array","Uint32Array","Float32Array","Float64Array","BigInt64Array","BigUint64Array","Tagged"];function yt(e){if(e===null)return"null";if(e===void 0)return"undefined";if(e===!0||e===!1)return"boolean";let t=typeof e;if(t==="string"||t==="number"||t==="bigint"||t==="symbol")return t;if(t==="function")return"Function";if(Array.isArray(e))return"Array";if(e instanceof Uint8Array)return"Uint8Array";if(e.constructor===Object)return"Object";let r=Yn(e);return r||"Object"}function Yn(e){let t=Object.prototype.toString.call(e).slice(8,-1);if(Xn.includes(t))return t}var s=class{constructor(t,r,n){this.major=t,this.majorEncoded=t<<5,this.name=r,this.terminal=n}toString(){return`Type[${this.major}].${this.name}`}compare(t){return this.major<t.major?-1:this.major>t.major?1:0}static equals(t,r){return t===r||t.major===r.major&&t.name===r.name}};s.uint=new s(0,"uint",!0);s.negint=new s(1,"negint",!0);s.bytes=new s(2,"bytes",!0);s.string=new s(3,"string",!0);s.array=new s(4,"array",!1);s.map=new s(5,"map",!1);s.tag=new s(6,"tag",!1);s.float=new s(7,"float",!0);s.false=new s(7,"false",!0);s.true=new s(7,"true",!0);s.null=new s(7,"null",!0);s.undefined=new s(7,"undefined",!0);s.break=new s(7,"break",!0);var u=class{constructor(t,r,n){this.type=t,this.value=r,this.encodedLength=n,this.encodedBytes=void 0,this.byteValue=void 0}toString(){return`Token[${this.type}].${this.value}`}};var ge=globalThis.process&&!globalThis.process.browser&&globalThis.Buffer&&typeof globalThis.Buffer.isBuffer=="function",Qn=new TextEncoder;function Le(e){return ge&&globalThis.Buffer.isBuffer(e)}function we(e){return e instanceof Uint8Array?Le(e)?new Uint8Array(e.buffer,e.byteOffset,e.byteLength):e:Uint8Array.from(e)}var Zn=24,eo=200,ze=ge?e=>e.length>=Zn?globalThis.Buffer.from(e):Xt(e):e=>e.length>=eo?Qn.encode(e):Xt(e),D=e=>Uint8Array.from(e),Yt=ge?(e,t,r)=>Le(e)?new Uint8Array(e.subarray(t,r)):e.slice(t,r):(e,t,r)=>e.slice(t,r),Qt=ge?(e,t)=>(e=e.map(r=>r instanceof Uint8Array?r:globalThis.Buffer.from(r)),we(globalThis.Buffer.concat(e,t))):(e,t)=>{let r=new Uint8Array(t),n=0;for(let o of e)n+o.length>r.length&&(o=o.subarray(0,r.length-n)),r.set(o,n),n+=o.length;return r},Zt=ge?e=>globalThis.Buffer.allocUnsafe(e):e=>new Uint8Array(e);function Ve(e,t){if(Le(e)&&Le(t))return e.compare(t);for(let r=0;r<e.length;r++)if(e[r]!==t[r])return e[r]<t[r]?-1:1;return 0}function Xt(e){let t=[],r=0;for(let n=0;n<e.length;n++){let o=e.charCodeAt(n);o<128?t[r++]=o:o<2048?(t[r++]=o>>6|192,t[r++]=o&63|128):(o&64512)===55296&&n+1<e.length&&(e.charCodeAt(n+1)&64512)===56320?(o=65536+((o&1023)<<10)+(e.charCodeAt(++n)&1023),t[r++]=o>>18|240,t[r++]=o>>12&63|128,t[r++]=o>>6&63|128,t[r++]=o&63|128):(o>=55296&&o<=57343&&(o=65533),t[r++]=o>>12|224,t[r++]=o>>6&63|128,t[r++]=o&63|128)}return t}var to=256,xe=class{constructor(t=to){this.chunkSize=t,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(t){let r=this.chunks[this.chunks.length-1];if(this.cursor+t.length<=this.maxCursor+1){let o=r.length-(this.maxCursor-this.cursor)-1;r.set(t,o)}else{if(r){let o=r.length-(this.maxCursor-this.cursor)-1;o<r.length&&(this.chunks[this.chunks.length-1]=r.subarray(0,o),this.maxCursor=this.cursor-1)}t.length<64&&t.length<this.chunkSize?(r=Zt(this.chunkSize),this.chunks.push(r),this.maxCursor+=r.length,this._initReuseChunk===null&&(this._initReuseChunk=r),r.set(t,0)):(this.chunks.push(t),this.maxCursor+=t.length)}this.cursor+=t.length}toBytes(t=!1){let r;if(this.chunks.length===1){let n=this.chunks[0];t&&this.cursor>n.length/2?(r=this.cursor===n.length?n:n.subarray(0,this.cursor),this._initReuseChunk=null,this.chunks=[]):r=Yt(n,0,this.cursor)}else r=Qt(this.chunks,this.cursor);return t&&this.reset(),r}},Fe=class{constructor(t){this.dest=t,this.cursor=0,this.chunks=[t]}reset(){this.cursor=0}push(t){if(this.cursor+t.length>this.dest.length)throw new Error("write out of bounds, destination buffer is too small");this.dest.set(t,this.cursor),this.cursor+=t.length}toBytes(t=!1){let r=this.dest.subarray(0,this.cursor);return t&&this.reset(),r}};var l="CBOR decode error:",He="CBOR encode error:",be=[];be[23]=1;be[24]=2;be[25]=3;be[26]=5;be[27]=9;function V(e,t,r){if(e.length-t<r)throw new Error(`${l} not enough data for type`)}var g=[24,256,65536,4294967296,BigInt("18446744073709551616")];function E(e,t,r){V(e,t,1);let n=e[t];if(r.strict===!0&&n<g[0])throw new Error(`${l} integer encoded in more bytes than necessary (strict decode)`);return n}function v(e,t,r){V(e,t,2);let n=e[t]<<8|e[t+1];if(r.strict===!0&&n<g[1])throw new Error(`${l} integer encoded in more bytes than necessary (strict decode)`);return n}function _(e,t,r){V(e,t,4);let n=e[t]*16777216+(e[t+1]<<16)+(e[t+2]<<8)+e[t+3];if(r.strict===!0&&n<g[2])throw new Error(`${l} integer encoded in more bytes than necessary (strict decode)`);return n}function A(e,t,r){V(e,t,8);let n=e[t]*16777216+(e[t+1]<<16)+(e[t+2]<<8)+e[t+3],o=e[t+4]*16777216+(e[t+5]<<16)+(e[t+6]<<8)+e[t+7],i=(BigInt(n)<<BigInt(32))+BigInt(o);if(r.strict===!0&&i<g[3])throw new Error(`${l} integer encoded in more bytes than necessary (strict decode)`);if(i<=Number.MAX_SAFE_INTEGER)return Number(i);if(r.allowBigInt===!0)return i;throw new Error(`${l} integers outside of the safe integer range are not supported`)}function er(e,t,r,n){return new u(s.uint,E(e,t+1,n),2)}function tr(e,t,r,n){return new u(s.uint,v(e,t+1,n),3)}function rr(e,t,r,n){return new u(s.uint,_(e,t+1,n),5)}function nr(e,t,r,n){return new u(s.uint,A(e,t+1,n),9)}function T(e,t){return m(e,0,t.value)}function m(e,t,r){if(r<g[0]){let n=Number(r);e.push([t|n])}else if(r<g[1]){let n=Number(r);e.push([t|24,n])}else if(r<g[2]){let n=Number(r);e.push([t|25,n>>>8,n&255])}else if(r<g[3]){let n=Number(r);e.push([t|26,n>>>24&255,n>>>16&255,n>>>8&255,n&255])}else{let n=BigInt(r);if(n<g[4]){let o=[t|27,0,0,0,0,0,0,0],i=Number(n&BigInt(4294967295)),a=Number(n>>BigInt(32)&BigInt(4294967295));o[8]=i&255,i=i>>8,o[7]=i&255,i=i>>8,o[6]=i&255,i=i>>8,o[5]=i&255,o[4]=a&255,a=a>>8,o[3]=a&255,a=a>>8,o[2]=a&255,a=a>>8,o[1]=a&255,e.push(o)}else throw new Error(`${l} encountered BigInt larger than allowable range`)}}T.encodedSize=function(t){return m.encodedSize(t.value)};m.encodedSize=function(t){return t<g[0]?1:t<g[1]?2:t<g[2]?3:t<g[3]?5:9};T.compareTokens=function(t,r){return t.value<r.value?-1:t.value>r.value?1:0};function or(e,t,r,n){return new u(s.negint,-1-E(e,t+1,n),2)}function ir(e,t,r,n){return new u(s.negint,-1-v(e,t+1,n),3)}function sr(e,t,r,n){return new u(s.negint,-1-_(e,t+1,n),5)}var mt=BigInt(-1),ar=BigInt(1);function cr(e,t,r,n){let o=A(e,t+1,n);if(typeof o!="bigint"){let i=-1-o;if(i>=Number.MIN_SAFE_INTEGER)return new u(s.negint,i,9)}if(n.allowBigInt!==!0)throw new Error(`${l} integers outside of the safe integer range are not supported`);return new u(s.negint,mt-BigInt(o),9)}function Pe(e,t){let r=t.value,n=typeof r=="bigint"?r*mt-ar:r*-1-1;m(e,t.type.majorEncoded,n)}Pe.encodedSize=function(t){let r=t.value,n=typeof r=="bigint"?r*mt-ar:r*-1-1;return n<g[0]?1:n<g[1]?2:n<g[2]?3:n<g[3]?5:9};Pe.compareTokens=function(t,r){return t.value<r.value?1:t.value>r.value?-1:0};function Ee(e,t,r,n){V(e,t,r+n);let o=e.slice(t+r,t+r+n);return new u(s.bytes,o,r+n)}function ur(e,t,r,n){return Ee(e,t,1,r)}function fr(e,t,r,n){return Ee(e,t,2,E(e,t+1,n))}function dr(e,t,r,n){return Ee(e,t,3,v(e,t+1,n))}function lr(e,t,r,n){return Ee(e,t,5,_(e,t+1,n))}function hr(e,t,r,n){let o=A(e,t+1,n);if(typeof o=="bigint")throw new Error(`${l} 64-bit integer bytes lengths not supported`);return Ee(e,t,9,o)}function qe(e){return e.encodedBytes===void 0&&(e.encodedBytes=s.equals(e.type,s.string)?ze(e.value):e.value),e.encodedBytes}function oe(e,t){let r=qe(t);m(e,t.type.majorEncoded,r.length),e.push(r)}oe.encodedSize=function(t){let r=qe(t);return m.encodedSize(r.length)+r.length};oe.compareTokens=function(t,r){return no(qe(t),qe(r))};function no(e,t){return e.length<t.length?-1:e.length>t.length?1:Ve(e,t)}var pr=new TextDecoder,io=32;function so(e,t,r){if(r-t<io){let o="";for(let i=t;i<r;i++){let a=e[i];if(a&128)return pr.decode(e.subarray(t,r));o+=String.fromCharCode(a)}return o}return pr.decode(e.subarray(t,r))}function ve(e,t,r,n,o){let i=r+n;V(e,t,i);let a=new u(s.string,so(e,t+r,t+i),i);return o.retainStringBytes===!0&&(a.byteValue=e.slice(t+r,t+i)),a}function yr(e,t,r,n){return ve(e,t,1,r,n)}function mr(e,t,r,n){return ve(e,t,2,E(e,t+1,n),n)}function gr(e,t,r,n){return ve(e,t,3,v(e,t+1,n),n)}function wr(e,t,r,n){return ve(e,t,5,_(e,t+1,n),n)}function xr(e,t,r,n){let o=A(e,t+1,n);if(typeof o=="bigint")throw new Error(`${l} 64-bit integer string lengths not supported`);return ve(e,t,9,o,n)}var br=oe;function ie(e,t,r,n){return new u(s.array,n,r)}function Er(e,t,r,n){return ie(e,t,1,r)}function vr(e,t,r,n){return ie(e,t,2,E(e,t+1,n))}function _r(e,t,r,n){return ie(e,t,3,v(e,t+1,n))}function Ar(e,t,r,n){return ie(e,t,5,_(e,t+1,n))}function kr(e,t,r,n){let o=A(e,t+1,n);if(typeof o=="bigint")throw new Error(`${l} 64-bit integer array lengths not supported`);return ie(e,t,9,o)}function Tr(e,t,r,n){if(n.allowIndefinite===!1)throw new Error(`${l} indefinite length items not allowed`);return ie(e,t,1,1/0)}function Ge(e,t){m(e,s.array.majorEncoded,t.value)}Ge.compareTokens=T.compareTokens;Ge.encodedSize=function(t){return m.encodedSize(t.value)};function se(e,t,r,n){return new u(s.map,n,r)}function Ir(e,t,r,n){return se(e,t,1,r)}function Ur(e,t,r,n){return se(e,t,2,E(e,t+1,n))}function Br(e,t,r,n){return se(e,t,3,v(e,t+1,n))}function Sr(e,t,r,n){return se(e,t,5,_(e,t+1,n))}function Cr(e,t,r,n){let o=A(e,t+1,n);if(typeof o=="bigint")throw new Error(`${l} 64-bit integer map lengths not supported`);return se(e,t,9,o)}function Nr(e,t,r,n){if(n.allowIndefinite===!1)throw new Error(`${l} indefinite length items not allowed`);return se(e,t,1,1/0)}function je(e,t){m(e,s.map.majorEncoded,t.value)}je.compareTokens=T.compareTokens;je.encodedSize=function(t){return m.encodedSize(t.value)};function Or(e,t,r,n){return new u(s.tag,r,1)}function Rr(e,t,r,n){return new u(s.tag,E(e,t+1,n),2)}function Dr(e,t,r,n){return new u(s.tag,v(e,t+1,n),3)}function Mr(e,t,r,n){return new u(s.tag,_(e,t+1,n),5)}function $r(e,t,r,n){return new u(s.tag,A(e,t+1,n),9)}function Je(e,t){m(e,s.tag.majorEncoded,t.value)}Je.compareTokens=T.compareTokens;Je.encodedSize=function(t){return m.encodedSize(t.value)};var gt=20,wt=21,xt=22,bt=23;function Lr(e,t,r,n){if(n.allowUndefined===!1)throw new Error(`${l} undefined values are not supported`);return n.coerceUndefinedToNull===!0?new u(s.null,null,1):new u(s.undefined,void 0,1)}function zr(e,t,r,n){if(n.allowIndefinite===!1)throw new Error(`${l} indefinite length items not allowed`);return new u(s.break,void 0,1)}function Et(e,t,r){if(r){if(r.allowNaN===!1&&Number.isNaN(e))throw new Error(`${l} NaN values are not supported`);if(r.allowInfinity===!1&&(e===1/0||e===-1/0))throw new Error(`${l} Infinity values are not supported`)}return new u(s.float,e,t)}function Vr(e,t,r,n){return Et(vt(e,t+1),3,n)}function Fr(e,t,r,n){return Et(_t(e,t+1),5,n)}function Hr(e,t,r,n){return Et(jr(e,t+1),9,n)}function _e(e,t,r){let n=t.value;if(n===!1)e.push([s.float.majorEncoded|gt]);else if(n===!0)e.push([s.float.majorEncoded|wt]);else if(n===null)e.push([s.float.majorEncoded|xt]);else if(n===void 0)e.push([s.float.majorEncoded|bt]);else{let o,i=!1;(!r||r.float64!==!0)&&(qr(n),o=vt(S,1),n===o||Number.isNaN(n)?(S[0]=249,e.push(S.slice(0,3)),i=!0):(Gr(n),o=_t(S,1),n===o&&(S[0]=250,e.push(S.slice(0,5)),i=!0))),i||(lo(n),o=jr(S,1),S[0]=251,e.push(S.slice(0,9)))}}_e.encodedSize=function(t,r){let n=t.value;if(n===!1||n===!0||n===null||n===void 0)return 1;if(!r||r.float64!==!0){qr(n);let o=vt(S,1);if(n===o||Number.isNaN(n))return 3;if(Gr(n),o=_t(S,1),n===o)return 5}return 9};var Pr=new ArrayBuffer(9),I=new DataView(Pr,1),S=new Uint8Array(Pr,0);function qr(e){if(e===1/0)I.setUint16(0,31744,!1);else if(e===-1/0)I.setUint16(0,64512,!1);else if(Number.isNaN(e))I.setUint16(0,32256,!1);else{I.setFloat32(0,e);let t=I.getUint32(0),r=(t&2139095040)>>23,n=t&8388607;if(r===255)I.setUint16(0,31744,!1);else if(r===0)I.setUint16(0,(t&2147483648)>>16|n>>13,!1);else{let o=r-127;o<-24?I.setUint16(0,0):o<-14?I.setUint16(0,(t&2147483648)>>16|1<<24+o,!1):I.setUint16(0,(t&2147483648)>>16|o+15<<10|n>>13,!1)}}}function vt(e,t){if(e.length-t<2)throw new Error(`${l} not enough data for float16`);let r=(e[t]<<8)+e[t+1];if(r===31744)return 1/0;if(r===64512)return-1/0;if(r===32256)return NaN;let n=r>>10&31,o=r&1023,i;return n===0?i=o*2**-24:n!==31?i=(o+1024)*2**(n-25):i=o===0?1/0:NaN,r&32768?-i:i}function Gr(e){I.setFloat32(0,e,!1)}function _t(e,t){if(e.length-t<4)throw new Error(`${l} not enough data for float32`);let r=(e.byteOffset||0)+t;return new DataView(e.buffer,r,4).getFloat32(0,!1)}function lo(e){I.setFloat64(0,e,!1)}function jr(e,t){if(e.length-t<8)throw new Error(`${l} not enough data for float64`);let r=(e.byteOffset||0)+t;return new DataView(e.buffer,r,8).getFloat64(0,!1)}_e.compareTokens=T.compareTokens;function p(e,t,r){throw new Error(`${l} encountered invalid minor (${r}) for major ${e[t]>>>5}`)}function Ke(e){return()=>{throw new Error(`${l} ${e}`)}}var f=[];for(let e=0;e<=23;e++)f[e]=p;f[24]=er;f[25]=tr;f[26]=rr;f[27]=nr;f[28]=p;f[29]=p;f[30]=p;f[31]=p;for(let e=32;e<=55;e++)f[e]=p;f[56]=or;f[57]=ir;f[58]=sr;f[59]=cr;f[60]=p;f[61]=p;f[62]=p;f[63]=p;for(let e=64;e<=87;e++)f[e]=ur;f[88]=fr;f[89]=dr;f[90]=lr;f[91]=hr;f[92]=p;f[93]=p;f[94]=p;f[95]=Ke("indefinite length bytes/strings are not supported");for(let e=96;e<=119;e++)f[e]=yr;f[120]=mr;f[121]=gr;f[122]=wr;f[123]=xr;f[124]=p;f[125]=p;f[126]=p;f[127]=Ke("indefinite length bytes/strings are not supported");for(let e=128;e<=151;e++)f[e]=Er;f[152]=vr;f[153]=_r;f[154]=Ar;f[155]=kr;f[156]=p;f[157]=p;f[158]=p;f[159]=Tr;for(let e=160;e<=183;e++)f[e]=Ir;f[184]=Ur;f[185]=Br;f[186]=Sr;f[187]=Cr;f[188]=p;f[189]=p;f[190]=p;f[191]=Nr;for(let e=192;e<=215;e++)f[e]=Or;f[216]=Rr;f[217]=Dr;f[218]=Mr;f[219]=$r;f[220]=p;f[221]=p;f[222]=p;f[223]=p;for(let e=224;e<=243;e++)f[e]=Ke("simple values are not supported");f[244]=p;f[245]=p;f[246]=p;f[247]=Lr;f[248]=Ke("simple values are not supported");f[249]=Vr;f[250]=Fr;f[251]=Hr;f[252]=p;f[253]=p;f[254]=p;f[255]=zr;var C=[];for(let e=0;e<24;e++)C[e]=new u(s.uint,e,1);for(let e=-1;e>=-24;e--)C[31-e]=new u(s.negint,e,1);C[64]=new u(s.bytes,new Uint8Array(0),1);C[96]=new u(s.string,"",1);C[128]=new u(s.array,0,1);C[160]=new u(s.map,0,1);C[244]=new u(s.false,!1,1);C[245]=new u(s.true,!0,1);C[246]=new u(s.null,null,1);function Ae(e){switch(e.type){case s.false:return D([244]);case s.true:return D([245]);case s.null:return D([246]);case s.bytes:return e.value.length?void 0:D([64]);case s.string:return e.value===""?D([96]):void 0;case s.array:return e.value===0?D([128]):void 0;case s.map:return e.value===0?D([160]):void 0;case s.uint:return e.value<24?D([Number(e.value)]):void 0;case s.negint:if(e.value>=-24)return D([31-Number(e.value)])}}var po={float64:!1,mapSorter:mo,quickEncodeToken:Ae},Yr=Object.freeze({float64:!0,mapSorter:go,quickEncodeToken:Ae});function At(){let e=[];return e[s.uint.major]=T,e[s.negint.major]=Pe,e[s.bytes.major]=oe,e[s.string.major]=br,e[s.array.major]=Ge,e[s.map.major]=je,e[s.tag.major]=Je,e[s.float.major]=_e,e}var ae=At(),We=new xe,Te=class e{constructor(t,r){this.obj=t,this.parent=r}includes(t){let r=this;do if(r.obj===t)return!0;while(r=r.parent);return!1}static createCheck(t,r){if(t&&t.includes(r))throw new Error(`${He} object contains circular references`);return new e(r,t)}},P={null:new u(s.null,null),undefined:new u(s.undefined,void 0),true:new u(s.true,!0),false:new u(s.false,!1),emptyArray:new u(s.array,0),emptyMap:new u(s.map,0)},M={number(e,t,r,n){return!Number.isInteger(e)||!Number.isSafeInteger(e)?new u(s.float,e):e>=0?new u(s.uint,e):new u(s.negint,e)},bigint(e,t,r,n){return e>=BigInt(0)?new u(s.uint,e):new u(s.negint,e)},Uint8Array(e,t,r,n){return new u(s.bytes,e)},string(e,t,r,n){return new u(s.string,e)},boolean(e,t,r,n){return e?P.true:P.false},null(e,t,r,n){return P.null},undefined(e,t,r,n){return P.undefined},ArrayBuffer(e,t,r,n){return new u(s.bytes,new Uint8Array(e))},DataView(e,t,r,n){return new u(s.bytes,new Uint8Array(e.buffer,e.byteOffset,e.byteLength))},Array(e,t,r,n){if(!e.length)return r.addBreakTokens===!0?[P.emptyArray,new u(s.break)]:P.emptyArray;n=Te.createCheck(n,e);let o=[],i=0;for(let a of e)o[i++]=Z(a,r,n);return r.addBreakTokens?[new u(s.array,e.length),o,new u(s.break)]:[new u(s.array,e.length),o]},Object(e,t,r,n){let o=t!=="Object",i=o?e.keys():Object.keys(e),a=o?e.size:i.length,c;if(a){c=new Array(a),n=Te.createCheck(n,e);let d=!o&&r.ignoreUndefinedProperties,h=0;for(let x of i){let ne=o?e.get(x):e[x];d&&ne===void 0||(c[h++]=[Z(x,r,n),Z(ne,r,n)])}h<a&&(c.length=h)}return c?.length?(yo(c,r),r.addBreakTokens?[new u(s.map,c.length),c,new u(s.break)]:[new u(s.map,c.length),c]):r.addBreakTokens===!0?[P.emptyMap,new u(s.break)]:P.emptyMap},Tagged(e,t,r,n){return[new u(s.tag,e.tag),Z(e.value,r,n)]}};M.Map=M.Object;M.Buffer=M.Uint8Array;for(let e of"Uint8Clamped Uint16 Uint32 Int8 Int16 Int32 BigUint64 BigInt64 Float32 Float64".split(" "))M[`${e}Array`]=M.DataView;function Z(e,t={},r){let n=yt(e),o=t&&t.typeEncoders&&t.typeEncoders[n]||M[n];if(typeof o=="function"){let a=o(e,n,t,r);if(a!=null)return a}let i=M[n];if(!i)throw new Error(`${He} unsupported type: ${n}`);return i(e,n,t,r)}function yo(e,t){t.mapSorter&&e.sort(t.mapSorter)}function mo(e,t){let r=Array.isArray(e[0])?e[0][0]:e[0],n=Array.isArray(t[0])?t[0][0]:t[0];if(r.type!==n.type)return r.type.compare(n.type);let o=r.type.major,i=ae[o].compareTokens(r,n);return i===0&&console.warn("WARNING: complex key types used, CBOR key sorting guarantees are gone"),i}function go(e,t){if(e[0]instanceof u&&t[0]instanceof u){let r=e[0],n=t[0];return r._keyBytes||(r._keyBytes=Jr(r.value)),n._keyBytes||(n._keyBytes=Jr(n.value)),Ve(r._keyBytes,n._keyBytes)}throw new Error("rfc8949MapSorter: complex key types are not supported yet")}function Jr(e){return Zr(e,ae,Yr)}function ke(e,t,r,n){if(Array.isArray(t))for(let o of t)ke(e,o,r,n);else r[t.type.major](e,t,n)}var Kr=s.uint.majorEncoded,Wr=s.negint.majorEncoded,wo=s.bytes.majorEncoded,xo=s.string.majorEncoded,Xr=s.array.majorEncoded,bo=s.float.majorEncoded|gt,Eo=s.float.majorEncoded|wt,vo=s.float.majorEncoded|xt,_o=s.float.majorEncoded|bt,Ao=BigInt(-1),ko=BigInt(1);function To(e){return e.addBreakTokens!==!0}function Qr(e,t,r,n){let o=yt(t),i=r.typeEncoders&&r.typeEncoders[o];if(i){let a=i(t,o,r,n);if(a!=null){ke(e,a,ae,r);return}}switch(o){case"null":e.push([vo]);return;case"undefined":e.push([_o]);return;case"boolean":e.push([t?Eo:bo]);return;case"number":!Number.isInteger(t)||!Number.isSafeInteger(t)?_e(e,new u(s.float,t),r):t>=0?m(e,Kr,t):m(e,Wr,t*-1-1);return;case"bigint":t>=BigInt(0)?m(e,Kr,t):m(e,Wr,t*Ao-ko);return;case"string":{let a=ze(t);m(e,xo,a.length),e.push(a);return}case"Uint8Array":m(e,wo,t.length),e.push(t);return;case"Array":if(!t.length){e.push([Xr]);return}n=Te.createCheck(n,t),m(e,Xr,t.length);for(let a of t)Qr(e,a,r,n);return;case"Object":case"Map":{let a=M.Object(t,o,r,n);ke(e,a,ae,r)}return;default:{let a=M[o];if(!a)throw new Error(`${He} unsupported type: ${o}`);let c=a(t,o,r,n);ke(e,c,ae,r)}}}function Zr(e,t,r,n){let o=n instanceof Uint8Array,i=o?new Fe(n):We,a=Z(e,r);if(!Array.isArray(a)&&r.quickEncodeToken){let c=r.quickEncodeToken(a);if(c)return o?(i.push(c),i.toBytes()):c;let d=t[a.type.major];if(d.encodedSize){let h=d.encodedSize(a,r);if(o||(i=new xe(h)),d(i,a,r),i.chunks.length!==1)throw new Error(`Unexpected error: pre-calculated length for ${a} was wrong`);return o?i.toBytes():we(i.chunks[0])}}return i.reset(),ke(i,a,t,r),i.toBytes(!0)}function kt(e,t){return t=Object.assign({},po,t),To(t)?(We.reset(),Qr(We,e,t,void 0),We.toBytes(!0)):Zr(e,ae,t)}var Io={strict:!1,allowIndefinite:!0,allowUndefined:!0,allowBigInt:!0},Xe=class{constructor(t,r={}){this._pos=0,this.data=t,this.options=r}pos(){return this._pos}done(){return this._pos>=this.data.length}next(){let t=this.data[this._pos],r=C[t];if(r===void 0){let n=f[t];if(!n)throw new Error(`${l} no decoder for major type ${t>>>5} (byte 0x${t.toString(16).padStart(2,"0")})`);let o=t&31;r=n(this.data,this._pos,o,this.options)}return this._pos+=r.encodedLength,r}},q=Symbol.for("DONE"),ce=Symbol.for("BREAK");function Uo(e,t,r){let n=[];for(let o=0;o<e.value;o++){let i=G(t,r);if(i===ce){if(e.value===1/0)break;throw new Error(`${l} got unexpected break to lengthed array`)}if(i===q)throw new Error(`${l} found array but not enough entries (got ${o}, expected ${e.value})`);n[o]=i}return n}function Bo(e,t,r){let n=r.useMaps===!0,o=r.rejectDuplicateMapKeys===!0,i=n?void 0:{},a=n?new Map:void 0;for(let c=0;c<e.value;c++){let d=G(t,r);if(d===ce){if(e.value===1/0)break;throw new Error(`${l} got unexpected break to lengthed map`)}if(d===q)throw new Error(`${l} found map but not enough entries (got ${c} [no key], expected ${e.value})`);if(!n&&typeof d!="string")throw new Error(`${l} non-string keys not supported (got ${typeof d})`);if(o&&(n&&a.has(d)||!n&&Object.hasOwn(i,d)))throw new Error(`${l} found repeat map key "${d}"`);let h=G(t,r);if(h===q)throw new Error(`${l} found map but not enough entries (got ${c} [no value], expected ${e.value})`);n?a.set(d,h):i[d]=h}return n?a:i}function*So(e,t,r){for(let n=0;n<e.value;n++){let o=G(t,r);if(o===ce){if(e.value===1/0)break;throw new Error(`${l} got unexpected break to lengthed map`)}if(o===q)throw new Error(`${l} found map but not enough entries (got ${n} [no key], expected ${e.value})`);let i=G(t,r);if(i===q)throw new Error(`${l} found map but not enough entries (got ${n} [no value], expected ${e.value})`);yield[o,i]}}function Co(e,t){let r=!1,n=function(){if(r)throw new Error(`${l} tag decode() may only be called once`);r=!0;let o=G(e,t);if(o===q)throw new Error(`${l} tag content missing`);if(o===ce)throw new Error(`${l} got unexpected break in tag content`);return o};return n.entries=function(){if(r)throw new Error(`${l} tag decode() may only be called once`);r=!0;let o=e.next();if(!s.equals(o.type,s.map))throw new Error(`${l} entries() requires map content, got ${o.type.name}`);let i=[];for(let a of So(o,e,t))i.push(a);return i},Object.defineProperty(n,"_called",{get(){return r},enumerable:!1}),n}function G(e,t){if(e.done())return q;let r=e.next();if(s.equals(r.type,s.break))return ce;if(r.type.terminal)return r.value;if(s.equals(r.type,s.array))return Uo(r,e,t);if(s.equals(r.type,s.map))return Bo(r,e,t);if(s.equals(r.type,s.tag)){if(t.tags&&typeof t.tags[r.value]=="function"){let n=Co(e,t),o=t.tags[r.value](n);if(!n._called)throw new Error(`${l} tag decoder must call decode() or entries()`);return o}throw new Error(`${l} tag not supported (${r.value})`)}throw new Error("unsupported")}function en(e,t){if(!(e instanceof Uint8Array))throw new Error(`${l} data to decode must be a Uint8Array`);t=Object.assign({},Io,t);let r=we(e),n=t.tokenizer||new Xe(r,t),o=G(n,t);if(o===q)throw new Error(`${l} did not find any content to decode`);if(o===ce)throw new Error(`${l} got unexpected break`);return[o,e.subarray(n.pos())]}function Tt(e,t){let[r,n]=en(e,t);if(n.length>0)throw new Error(`${l} too many terminals, data makes no sense`);return r}var Ye=class e{constructor(t,r){if(typeof t!="number"||!Number.isInteger(t)||t<0)throw new TypeError("Tagged: tag must be a non-negative integer");this.tag=t,this.value=r}static decoder(t){return r=>new e(t,r())}static preserve(...t){let r={};for(let n of t)r[n]=e.decoder(n);return r}};Object.defineProperty(Ye.prototype,Symbol.toStringTag,{value:"Tagged"});var Xs=new Uint8Array(0);function tn(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}function ue(e){if(e instanceof Uint8Array&&e.constructor.name==="Uint8Array")return ee(e);if(e instanceof ArrayBuffer)return new Uint8Array(e);if(ArrayBuffer.isView(e))return ee(new Uint8Array(e.buffer,e.byteOffset,e.byteLength));throw new Error("Unknown type, must be binary type")}function Oo(e){return e?.buffer instanceof ArrayBuffer}function ee(e){return Oo(e)?e:e.slice()}function Ro(e,t){if(e.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),n=0;n<r.length;n++)r[n]=255;for(var o=0;o<e.length;o++){var i=e.charAt(o),a=i.charCodeAt(0);if(r[a]!==255)throw new TypeError(i+" is ambiguous");r[a]=o}var c=e.length,d=e.charAt(0),h=Math.log(c)/Math.log(256),x=Math.log(256)/Math.log(c);function ne(y){if(y instanceof Uint8Array||(ArrayBuffer.isView(y)?y=new Uint8Array(y.buffer,y.byteOffset,y.byteLength):Array.isArray(y)&&(y=Uint8Array.from(y))),!(y instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(y.length===0)return"";for(var b=0,Y=0,U=0,N=y.length;U!==N&&y[U]===0;)U++,b++;for(var O=(N-U)*x+1>>>0,k=new Uint8Array(O);U!==N;){for(var R=y[U],H=0,B=O-1;(R!==0||H<Y)&&B!==-1;B--,H++)R+=256*k[B]>>>0,k[B]=R%c>>>0,R=R/c>>>0;if(R!==0)throw new Error("Non-zero carry");Y=H,U++}for(var z=O-Y;z!==O&&k[z]===0;)z++;for(var De=d.repeat(b);z<O;++z)De+=e.charAt(k[z]);return De}function Re(y){if(typeof y!="string")throw new TypeError("Expected String");if(y.length===0)return new Uint8Array;var b=0;if(y[b]!==" "){for(var Y=0,U=0;y[b]===d;)Y++,b++;for(var N=(y.length-b)*h+1>>>0,O=new Uint8Array(N);y[b];){var k=r[y.charCodeAt(b)];if(k===255)return;for(var R=0,H=N-1;(k!==0||R<U)&&H!==-1;H--,R++)k+=c*O[H]>>>0,O[H]=k%256>>>0,k=k/256>>>0;if(k!==0)throw new Error("Non-zero carry");U=R,b++}if(y[b]!==" "){for(var B=N-U;B!==N&&O[B]===0;)B++;for(var z=new Uint8Array(Y+(N-B)),De=Y;B!==N;)z[De++]=O[B++];return z}}}function Pn(y){var b=Re(y);if(b)return b;throw new Error(`Non-${t} character`)}return{encode:ne,decodeUnsafe:Re,decode:Pn}}var Do=Ro,Mo=Do,rn=Mo;var It=class{name;prefix;baseEncode;constructor(t,r,n){this.name=t,this.prefix=r,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},Ut=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,r,n){this.name=t,this.prefix=r;let o=r.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(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 nn(this,t)}},Bt=class{decoders;constructor(t){this.decoders=t}or(t){return nn(this,t)}decode(t){let r=t[0],n=this.decoders[r];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 nn(e,t){return new Bt({...e.decoders??{[e.prefix]:e},...t.decoders??{[t.prefix]:t}})}var St=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,r,n,o){this.name=t,this.prefix=r,this.baseEncode=n,this.baseDecode=o,this.encoder=new It(t,r,n),this.decoder=new Ut(t,r,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function on({name:e,prefix:t,encode:r,decode:n}){return new St(e,t,r,n)}function fe({name:e,prefix:t,alphabet:r}){let{encode:n,decode:o}=rn(r,e);return on({prefix:t,name:e,encode:n,decode:i=>ue(o(i))})}function $o(e,t,r,n){let o=e.length;for(;e[o-1]==="=";)--o;let i=new Uint8Array(o*r/8|0),a=0,c=0,d=0;for(let h=0;h<o;++h){let x=t[e[h]];if(x===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<r|x,a+=r,a>=8&&(a-=8,i[d++]=255&c>>a)}if(a>=r||(255&c<<8-a)!==0)throw new SyntaxError("Unexpected end of data");return i}function Lo(e,t,r){let n=t[t.length-1]==="=",o=(1<<r)-1,i="",a=0,c=0;for(let d=0;d<e.length;++d)for(c=c<<8|e[d],a+=8;a>r;)a-=r,i+=t[o&c>>a];if(a!==0&&(i+=t[o&c<<r-a]),n)for(;(i.length*r&7)!==0;)i+="=";return i}function zo(e){let t={};for(let r=0;r<e.length;++r)t[e[r]]=r;return t}function $({name:e,prefix:t,bitsPerChar:r,alphabet:n}){let o=zo(n);return on({prefix:t,name:e,encode(i){return Lo(i,n,r)},decode(i){return $o(i,o,r,e)}})}var Ie=$({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),na=$({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),oa=$({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),ia=$({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),sa=$({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),aa=$({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),ca=$({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),ua=$({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),fa=$({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Qe=fe({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),ha=fe({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var F=fe({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),ma=fe({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Vo=cn,sn=128,Fo=127,Ho=~Fo,Po=Math.pow(2,31);function cn(e,t,r){t=t||[],r=r||0;for(var n=r;e>=Po;)t[r++]=e&255|sn,e/=128;for(;e&Ho;)t[r++]=e&255|sn,e>>>=7;return t[r]=e|0,cn.bytes=r-n+1,t}var qo=Ct,Go=128,an=127;function Ct(e,n){var r=0,n=n||0,o=0,i=n,a,c=e.length;do{if(i>=c)throw Ct.bytes=0,new RangeError("Could not decode varint");a=e[i++],r+=o<28?(a&an)<<o:(a&an)*Math.pow(2,o),o+=7}while(a>=Go);return Ct.bytes=i-n,r}var jo=Math.pow(2,7),Jo=Math.pow(2,14),Ko=Math.pow(2,21),Wo=Math.pow(2,28),Xo=Math.pow(2,35),Yo=Math.pow(2,42),Qo=Math.pow(2,49),Zo=Math.pow(2,56),ei=Math.pow(2,63),ti=function(e){return e<jo?1:e<Jo?2:e<Ko?3:e<Wo?4:e<Xo?5:e<Yo?6:e<Qo?7:e<Zo?8:e<ei?9:10},ri={encode:Vo,decode:qo,encodingLength:ti},ni=ri,Ue=ni;function Be(e,t=0){return[Ue.decode(e,t),Ue.decode.bytes]}function de(e,t,r=0){return Ue.encode(e,t,r),t}function le(e){return Ue.encodingLength(e)}function fn(e,t){let r=t.byteLength,n=le(e),o=n+le(r),i=new Uint8Array(o+r);return de(e,i,0),de(r,i,n),i.set(t,o),new he(e,r,t,i)}function j(e){let t=ue(e),[r,n]=Be(t),[o,i]=Be(t.subarray(n)),a=t.subarray(n+i);if(a.byteLength!==o)throw new Error("Incorrect length");return new he(r,o,a,t)}function dn(e,t){if(e===t)return!0;{let r=t;return e.code===r.code&&e.size===r.size&&r.bytes instanceof Uint8Array&&tn(e.bytes,r.bytes)}}var he=class{code;size;digest;bytes;constructor(t,r,n,o){this.code=t,this.size=r,this.digest=ee(n),this.bytes=ee(o)}};function ln(e,t){let{bytes:r,version:n}=e;return n===0?ii(r,Ot(e),t??F.encoder):si(r,Ot(e),t??Ie.encoder)}var hn=new WeakMap;function Ot(e){let t=hn.get(e);if(t==null){let r=new Map;return hn.set(e,r),r}return t}var w=class e{code;version;multihash;bytes;"/";constructor(t,r,n,o){this.code=r,this.version=t,this.multihash=n,this.bytes=ee(o),this["/"]=this.bytes}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:t,multihash:r}=this;if(t!==Se)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==ai)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return e.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:t,digest:r}=this.multihash,n=fn(t,r);return e.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 e.equals(this,t)}static equals(t,r){let n=r;return n!=null&&t.code===n.code&&t.version===n.version&&dn(t.multihash,n.multihash)}toString(t){return ln(this,t)}toJSON(){return{"/":ln(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 r=t;if(r instanceof e)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:o,multihash:i,bytes:a}=r;return new e(n,o,i,a??pn(n,o,i.bytes))}else if(r[ci]===!0){let{version:n,multihash:o,code:i}=r,a=j(o);return e.create(n,i,a)}else return null}static create(t,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(t){case 0:{if(r!==Se)throw new Error(`Version 0 CID must use dag-pb (code: ${Se}) block encoding`);return new e(t,r,n,n.bytes)}case 1:{let o=pn(t,r,n.bytes);return new e(t,r,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return e.create(0,Se,t)}static createV1(t,r){return e.create(1,t,r)}static decode(t){let[r,n]=e.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return r}static decodeFirst(t){let r=e.inspectBytes(t),n=r.size-r.multihashSize,o=ue(t.subarray(n,n+r.multihashSize));if(o.byteLength!==r.multihashSize)throw new Error("Incorrect length");let i=o.subarray(r.multihashSize-r.digestSize),a=new he(r.multihashCode,r.digestSize,i,o);return[r.version===0?e.createV0(a):e.createV1(r.codec,a),t.subarray(r.size)]}static inspectBytes(t){let r=0,n=()=>{let[ne,Re]=Be(t.subarray(r));return r+=Re,ne},o=n(),i=Se;if(o===18?(o=0,r=0):i=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let a=r,c=n(),d=n(),h=r+d,x=h-a;return{version:o,codec:i,multihashCode:c,digestSize:d,multihashSize:x,size:h}}static parse(t,r){let[n,o]=oi(t,r),i=e.decode(o);if(i.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Ot(i).set(n,t),i}};function oi(e,t){switch(e[0]){case"Q":{let r=t??F;return[F.prefix,r.decode(`${F.prefix}${e}`)]}case F.prefix:{let r=t??F;return[F.prefix,r.decode(e)]}case Ie.prefix:{let r=t??Ie;return[Ie.prefix,r.decode(e)]}case Qe.prefix:{let r=t??Qe;return[Qe.prefix,r.decode(e)]}default:{if(t==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[e[0],t.decode(e)]}}}function ii(e,t,r){let{prefix:n}=r;if(n!==F.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let o=t.get(n);if(o==null){let i=r.encode(e).slice(1);return t.set(n,i),i}else return o}function si(e,t,r){let{prefix:n}=r,o=t.get(n);if(o==null){let i=r.encode(e);return t.set(n,i),i}else return o}var Se=112,ai=18;function pn(e,t,r){let n=le(e),o=n+le(t),i=new Uint8Array(o+r.byteLength);return de(e,i,0),de(t,i,n),i.set(r,o),i}var ci=Symbol.for("@ipld/js-cid/CID");var yn=42;function ui(e){return e instanceof ArrayBuffer?new Uint8Array(e,0,e.byteLength):e}function fi(e){if(e.asCID!==e&&e["/"]!==e.bytes)return null;let t=w.asCID(e);if(!t)return null;let r=new Uint8Array(t.bytes.byteLength+1);return r.set(t.bytes,1),[new u(s.tag,yn),new u(s.bytes,r)]}function di(){throw new Error("`undefined` is not supported by the IPLD Data Model and cannot be encoded")}function li(e){if(Number.isNaN(e))throw new Error("`NaN` is not supported by the IPLD Data Model and cannot be encoded");if(e===1/0||e===-1/0)throw new Error("`Infinity` and `-Infinity` is not supported by the IPLD Data Model and cannot be encoded");return null}function hi(e){for(let t of e.keys())if(typeof t!="string"||t.length===0)throw new Error("Non-string Map keys are not supported by the IPLD Data Model and cannot be encoded");return null}var Rt={float64:!0,typeEncoders:{Map:hi,Object:fi,undefined:di,number:li}},Ua={...Rt,typeEncoders:{...Rt.typeEncoders}};function pi(e){let t=e();if(t[0]!==0)throw new Error("Invalid CID for CBOR tag 42; expected leading 0x00");return w.decode(t.subarray(1))}var Dt={allowIndefinite:!1,coerceUndefinedToNull:!0,allowNaN:!1,allowInfinity:!1,allowBigInt:!0,strict:!0,useMaps:!1,rejectDuplicateMapKeys:!0,tags:{[yn]:pi}},Ba={...Dt,tags:{...Dt.tags}};var Ze=e=>kt(e,Rt),et=e=>Tt(ui(e),Dt);var J=$e(tt(),1),K={SHA2_256:18,LENGTH:32,DAG_PB:112},rt=40;function L(e,t){if(!e.length)throw new Error("Unexpected end of data");let r=J.default.decode(e);return t.seek(J.default.decode.bytes),r}function nt(e){let t=new DataView(e.buffer,e.byteOffset,e.byteLength),r=0;return{version:2,characteristics:[t.getBigUint64(r,!0),t.getBigUint64(r+=8,!0)],dataOffset:Number(t.getBigUint64(r+=8,!0)),dataSize:Number(t.getBigUint64(r+=8,!0)),indexOffset:Number(t.getBigUint64(r+=8,!0))}}function ot(e){J.default.decode(e);let t=J.default.decode.bytes,r=J.default.decode(e.subarray(J.default.decode.bytes)),n=J.default.decode.bytes;return t+n+r}var W={Null:e=>e===null?e:void 0,Int:e=>Number.isInteger(e)?e:void 0,Float:e=>typeof e=="number"&&Number.isFinite(e)?e:void 0,String:e=>typeof e=="string"?e:void 0,Bool:e=>typeof e=="boolean"?e:void 0,Bytes:e=>e instanceof Uint8Array?e:void 0,Link:e=>e!==null&&typeof e=="object"&&e.asCID===e?e:void 0,List:e=>Array.isArray(e)?e:void 0,Map:e=>e!==null&&typeof e=="object"&&e.asCID!==e&&!Array.isArray(e)&&!(e instanceof Uint8Array)?e:void 0},Ce={"CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)":W.Link,"CarV1HeaderOrV2Pragma > roots (anon)":e=>{if(W.List(e)!==void 0){for(let t=0;t<e.length;t++){let r=e[t];if(r=Ce["CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)"](r),r===void 0)return;if(r!==e[t]){let n=e.slice(0,t);for(let o=t;o<e.length;o++){let i=e[o];if(i=Ce["CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)"](i),i===void 0)return;n.push(i)}return n}}return e}},Int:W.Int,CarV1HeaderOrV2Pragma:e=>{if(W.Map(e)===void 0)return;let t=Object.entries(e),r=e,n=1;for(let o=0;o<t.length;o++){let[i,a]=t[o];switch(i){case"roots":{let c=Ce["CarV1HeaderOrV2Pragma > roots (anon)"](e[i]);if(c===void 0)return;if(c!==a||r!==e){if(r===e){r={};for(let d=0;d<o;d++)r[t[d][0]]=t[d][1]}r.roots=c}}break;case"version":{n--;let c=Ce.Int(e[i]);if(c===void 0)return;if(c!==a||r!==e){if(r===e){r={};for(let d=0;d<o;d++)r[t[d][0]]=t[d][1]}r.version=c}}break;default:return}}if(!(n>0))return r}},Ne={"CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)":W.Link,"CarV1HeaderOrV2Pragma > roots (anon)":e=>{if(W.List(e)!==void 0){for(let t=0;t<e.length;t++){let r=e[t];if(r=Ne["CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)"](r),r===void 0)return;if(r!==e[t]){let n=e.slice(0,t);for(let o=t;o<e.length;o++){let i=e[o];if(i=Ne["CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)"](i),i===void 0)return;n.push(i)}return n}}return e}},Int:W.Int,CarV1HeaderOrV2Pragma:e=>{if(W.Map(e)===void 0)return;let t=Object.entries(e),r=e,n=1;for(let o=0;o<t.length;o++){let[i,a]=t[o];switch(i){case"roots":{let c=Ne["CarV1HeaderOrV2Pragma > roots (anon)"](a);if(c===void 0)return;if(c!==a||r!==e){if(r===e){r={};for(let d=0;d<o;d++)r[t[d][0]]=t[d][1]}r.roots=c}}break;case"version":{n--;let c=Ne.Int(a);if(c===void 0)return;if(c!==a||r!==e){if(r===e){r={};for(let d=0;d<o;d++)r[t[d][0]]=t[d][1]}r.version=c}}break;default:return}}if(!(n>0))return r}},it={toTyped:Ce.CarV1HeaderOrV2Pragma,toRepresentation:Ne.CarV1HeaderOrV2Pragma};function kn(e,t){let r=L(e.upTo(8),e);if(r===0)throw new Error("Invalid CAR header (zero length)");let n=e.exactly(r,!0),o=et(n);if(it.toTyped(o)===void 0)throw new Error("Invalid CAR header format");if(o.version!==1&&o.version!==2||t!==void 0&&o.version!==t)throw new Error(`Invalid CAR version: ${o.version}${t!==void 0?` (expected ${t})`:""}`);if(o.version===1){if(!Array.isArray(o.roots))throw new Error("Invalid CAR header format");return o}if(o.roots!==void 0)throw new Error("Invalid CAR header format");let i=nt(e.exactly(rt,!0));e.seek(i.dataOffset-e.pos);let a=kn(e,1);return Object.assign(a,i)}function Bi(e){let t=e.exactly(2,!1);if(t[0]===K.SHA2_256&&t[1]===K.LENGTH){let a=e.exactly(34,!0),c=j(a);return w.create(0,K.DAG_PB,c)}let r=L(e.upTo(8),e);if(r!==1)throw new Error(`Unexpected CID version (${r})`);let n=L(e.upTo(8),e),o=e.exactly(ot(e.upTo(8)),!0),i=j(o);return w.create(r,n,i)}function Si(e){let t=e.pos,r=L(e.upTo(8),e);if(r===0)throw new Error("Invalid CAR section (zero length)");r+=e.pos-t;let n=Bi(e),o=r-Number(e.pos-t);return{cid:n,length:r,blockLength:o}}function Tn(e){let t=Ci(e),r=kn(t);if(r.version===2){let o=t.pos-r.dataOffset;t=Ni(t,r.dataSize-o)}let n=[];for(;t.upTo(8).length>0;){let{cid:o,blockLength:i}=Si(t);n.push({cid:o,bytes:t.exactly(i,!0)})}return{header:r,blocks:n}}function Ci(e){let t=0;return{upTo(r){return e.subarray(t,t+Math.min(r,e.length-t))},exactly(r,n=!1){if(r>e.length-t)throw new Error("Unexpected end of data");let o=e.subarray(t,t+r);return n&&(t+=r),o},seek(r){t+=r},get pos(){return t}}}function Ni(e,t){let r=0;return{upTo(n){let o=e.upTo(n);return o.length+r>t&&(o=o.subarray(0,t-r)),o},exactly(n,o=!1){let i=e.exactly(n,o);if(i.length+r>t)throw new Error("Unexpected end of data");return o&&(r+=n),i},seek(n){r+=n,e.seek(n)},get pos(){return e.pos}}}var st=class e{constructor(t,r){this._header=t,this._blocks=r,this._cids=void 0}get version(){return this._header.version}getRoots(){return this._header.roots}has(t){return this._blocks.some(r=>r.cid.equals(t))}get(t){return this._blocks.find(r=>r.cid.equals(t))}blocks(){return this._blocks}cids(){return this._cids||(this._cids=this._blocks.map(t=>t.cid)),this._cids}static fromBytes(t){if(!(t instanceof Uint8Array))throw new TypeError("fromBytes() requires a Uint8Array");let{header:r,blocks:n}=Tn(t);return new e(r,n)}};var qt={};Kt(qt,{addBlock:()=>Bn,addRoot:()=>Un,blockLength:()=>Mi,calculateHeaderLength:()=>Ht,close:()=>Sn,createWriter:()=>Vi,estimateHeaderLength:()=>zi,headerLength:()=>Pt,resizeHeader:()=>Ft});var Ri=At(),Di={float64:!1,quickEncodeToken:Ae};function Lt(e,t=Ri,r=Di){if(Array.isArray(e)){let n=0;for(let o of e)n+=Lt(o,t,r);return n}else{let n=t[e.type.major];if(n.encodedSize===void 0||typeof n.encodedSize!="function")throw new Error(`Encoder for ${e.type.name} does not have an encodedSize()`);return n.encodedSize(e,r)}}var Oe=$e(tt(),1),Vt=class{constructor(t,r){this.bytes=t,this.byteOffset=r,this.roots=[],this.headerSize=r}addRoot(t,r){return Un(this,t,r),this}write(t){return Bn(this,t),this}close(t){return Sn(this,t)}},Un=(e,t,r={})=>{let{resize:n=!1}=r,{bytes:o,headerSize:i,byteOffset:a,roots:c}=e;e.roots.push(t);let d=Pt(e);if(d>i)if(d-i+a<o.byteLength)if(n)Ft(e,d);else throw c.pop(),new RangeError(`Header of size ${i} has no capacity for new root ${t}.
However there is a space in the buffer and you could call addRoot(root, { resize: root }) to resize header to make a space for this root.`);else throw c.pop(),new RangeError(`Buffer has no capacity for a new root ${t}`)},Mi=({cid:e,bytes:t})=>{let r=e.bytes.byteLength+t.byteLength;return Oe.default.encodingLength(r)+r},Bn=(e,{cid:t,bytes:r})=>{let n=t.bytes.byteLength+r.byteLength,o=Oe.default.encode(n);if(e.byteOffset+o.length+n>e.bytes.byteLength)throw new RangeError("Buffer has no capacity for this block");zt(e,o),zt(e,t.bytes),zt(e,r)},Sn=(e,t={})=>{let{resize:r=!1}=t,{roots:n,bytes:o,byteOffset:i,headerSize:a}=e,c=Ze({version:1,roots:n}),d=Oe.default.encode(c.length),h=d.length+c.byteLength;if(a-h===0)return In(e,d,c),o.subarray(0,i);if(r)return Ft(e,h),In(e,d,c),o.subarray(0,e.byteOffset);throw new RangeError(`Header size was overestimated.
You can use close({ resize: true }) to resize header`)},Ft=(e,t)=>{let{bytes:r,headerSize:n}=e;r.set(r.subarray(n,e.byteOffset),t),e.byteOffset+=t-n,e.headerSize=t},zt=(e,t)=>{e.bytes.set(t,e.byteOffset),e.byteOffset+=t.length},In=({bytes:e},t,r)=>{e.set(t),e.set(r,t.length)},$i=[new u(s.map,2),new u(s.string,"version"),new u(s.uint,1),new u(s.string,"roots")],Li=new u(s.tag,42),Ht=e=>{let t=[...$i];t.push(new u(s.array,e.length));for(let n of e)t.push(Li),t.push(new u(s.bytes,{length:n+1}));let r=Lt(t);return Oe.default.encodingLength(r)+r},Pt=({roots:e})=>Ht(e.map(t=>t.bytes.byteLength)),zi=(e,t=36)=>Ht(new Array(e).fill(t)),Vi=(e,t={})=>{let{roots:r=[],byteOffset:n=0,byteLength:o=e.byteLength,headerSize:i=Pt({roots:r})}=t,a=new Uint8Array(e,n,o),c=new Vt(a,i);for(let d of r)c.addRoot(d);return c};var Gt=$e(Cn(),1);async function at(e,t){let r=L(await e.upTo(8),e);if(r===0)throw new Error("Invalid CAR header (zero length)");let n=await e.exactly(r,!0),o=et(n);if(it.toTyped(o)===void 0)throw new Error("Invalid CAR header format");if(o.version!==1&&o.version!==2||t!==void 0&&o.version!==t)throw new Error(`Invalid CAR version: ${o.version}${t!==void 0?` (expected ${t})`:""}`);if(o.version===1){if(!Array.isArray(o.roots))throw new Error("Invalid CAR header format");return o}if(o.roots!==void 0)throw new Error("Invalid CAR header format");let i=nt(await e.exactly(rt,!0));e.seek(i.dataOffset-e.pos);let a=await at(e,1);return Object.assign(a,i)}async function Fi(e){let t=await e.exactly(2,!1);if(t[0]===K.SHA2_256&&t[1]===K.LENGTH){let a=await e.exactly(34,!0),c=j(a);return w.create(0,K.DAG_PB,c)}let r=L(await e.upTo(8),e);if(r!==1)throw new Error(`Unexpected CID version (${r})`);let n=L(await e.upTo(8),e),o=await e.exactly(ot(await e.upTo(8)),!0),i=j(o);return w.create(r,n,i)}async function Nn(e){let t=e.pos,r=L(await e.upTo(8),e);if(r===0)throw new Error("Invalid CAR section (zero length)");r+=e.pos-t;let n=await Fi(e),o=r-Number(e.pos-t);return{cid:n,length:r,blockLength:o}}async function Hi(e){let{cid:t,blockLength:r}=await Nn(e);return{bytes:await e.exactly(r,!0),cid:t}}async function Pi(e){let t=e.pos,{cid:r,length:n,blockLength:o}=await Nn(e),i={cid:r,length:n,blockLength:o,offset:t,blockOffset:e.pos};return e.seek(i.blockLength),i}function pe(e){let t=(async()=>{let r=await at(e);if(r.version===2){let n=e.pos-r.dataOffset;e=Gi(e,r.dataSize-n)}return r})();return{header:()=>t,async*blocks(){for(await t;(await e.upTo(8)).length>0;)yield await Hi(e)},async*blocksIndex(){for(await t;(await e.upTo(8)).length>0;)yield await Pi(e)}}}function X(e){let t=0;return{async upTo(r){return e.subarray(t,t+Math.min(r,e.length-t))},async exactly(r,n=!1){if(r>e.length-t)throw new Error("Unexpected end of data");let o=e.subarray(t,t+r);return n&&(t+=r),o},seek(r){t+=r},get pos(){return t}}}function qi(e){let t=0,r=0,n=0,o=new Uint8Array(0),i=async a=>{r=o.length-n;let c=[o.subarray(n)];for(;r<a;){let h=await e();if(h==null)break;r<0?h.length>r&&c.push(h.subarray(-r)):c.push(h),r+=h.length}o=new Uint8Array(c.reduce((h,x)=>h+x.length,0));let d=0;for(let h of c)o.set(h,d),d+=h.length;n=0};return{async upTo(a){return o.length-n<a&&await i(a),o.subarray(n,n+Math.min(o.length-n,a))},async exactly(a,c=!1){if(o.length-n<a&&await i(a),o.length-n<a)throw new Error("Unexpected end of data");let d=o.subarray(n,n+a);return c&&(t+=a,n+=a),d},seek(a){t+=a,n+=a},get pos(){return t}}}function ye(e){let t=e[Symbol.asyncIterator]();async function r(){let n=await t.next();return n.done?null:n.value}return qi(r)}function Gi(e,t){let r=0;return{async upTo(n){let o=await e.upTo(n);return o.length+r>t&&(o=o.subarray(0,t-r)),o},async exactly(n,o=!1){let i=await e.exactly(n,o);if(i.length+r>t)throw new Error("Unexpected end of data");return o&&(r+=n),i},seek(n){r+=n,e.seek(n)},get pos(){return e.pos}}}var te=class{constructor(t,r,n){this._version=t,this._roots=r,this._iterator=n}get version(){return this._version}async getRoots(){return this._roots}[Symbol.asyncIterator](){return this._iterator}static async f