@ipld/car 5.3.0 → 5.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.min.js CHANGED
@@ -1,5 +1,5 @@
1
1
  (function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.IpldCar = factory()}(typeof self !== 'undefined' ? self : this, function () {
2
- "use strict";var IpldCar=(()=>{var Bn=Object.create;var Ce=Object.defineProperty;var Nn=Object.getOwnPropertyDescriptor;var Dn=Object.getOwnPropertyNames;var On=Object.getPrototypeOf,Rn=Object.prototype.hasOwnProperty;var de=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),Mt=(e,t)=>{for(var r in t)Ce(e,r,{get:t[r],enumerable:!0})},$t=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Dn(t))!Rn.call(e,o)&&o!==r&&Ce(e,o,{get:()=>t[o],enumerable:!(n=Nn(t,o))||n.enumerable});return e};var Ie=(e,t,r)=>(r=e!=null?Bn(On(e)):{},$t(t||!e||!e.__esModule?Ce(r,"default",{value:e,enumerable:!0}):r,e)),Mn=e=>$t(Ce({},"__esModule",{value:!0}),e);var on=de((ea,nn)=>{nn.exports=kt;var rn=128,Ko=127,Wo=~Ko,Xo=Math.pow(2,31);function kt(e,t,r){if(Number.MAX_SAFE_INTEGER&&e>Number.MAX_SAFE_INTEGER)throw kt.bytes=0,new RangeError("Could not encode varint");t=t||[],r=r||0;for(var n=r;e>=Xo;)t[r++]=e&255|rn,e/=128;for(;e&Wo;)t[r++]=e&255|rn,e>>>=7;return t[r]=e|0,kt.bytes=r-n+1,t}});var cn=de((ta,an)=>{an.exports=At;var Qo=128,sn=127;function At(e,n){var r=0,n=n||0,o=0,i=n,a,c=e.length;do{if(i>=c||o>49)throw At.bytes=0,new RangeError("Could not decode varint");a=e[i++],r+=o<28?(a&sn)<<o:(a&sn)*Math.pow(2,o),o+=7}while(a>=Qo);return At.bytes=i-n,r}});var un=de((ra,fn)=>{var Yo=Math.pow(2,7),Zo=Math.pow(2,14),jo=Math.pow(2,21),ei=Math.pow(2,28),ti=Math.pow(2,35),ri=Math.pow(2,42),ni=Math.pow(2,49),oi=Math.pow(2,56),ii=Math.pow(2,63);fn.exports=function(e){return e<Yo?1:e<Zo?2:e<jo?3:e<ei?4:e<ti?5:e<ri?6:e<ni?7:e<oi?8:e<ii?9:10}});var qe=de((na,dn)=>{dn.exports={encode:on(),decode:cn(),encodingLength:un()}});var wn=de(()=>{});var Ai={};Mt(Ai,{CarBlockIterator:()=>je,CarBufferReader:()=>Xe,CarBufferWriter:()=>Nt,CarCIDIterator:()=>et,CarIndexedReader:()=>Ye,CarIndexer:()=>Y,CarReader:()=>Z,CarWriter:()=>rt,contentType:()=>ki});var $n=["string","number","bigint","symbol"],zn=["Function","Generator","AsyncGenerator","GeneratorFunction","AsyncGeneratorFunction","AsyncFunction","Observable","Array","Buffer","Object","RegExp","Date","Error","Map","Set","WeakMap","WeakSet","ArrayBuffer","SharedArrayBuffer","DataView","Promise","URL","HTMLElement","Int8Array","Uint8Array","Uint8ClampedArray","Int16Array","Uint16Array","Int32Array","Uint32Array","Float32Array","Float64Array","BigInt64Array","BigUint64Array"];function zt(e){if(e===null)return"null";if(e===void 0)return"undefined";if(e===!0||e===!1)return"boolean";let t=typeof e;if($n.includes(t))return t;if(t==="function")return"Function";if(Array.isArray(e))return"Array";if(Vn(e))return"Buffer";let r=Ln(e);return r||"Object"}function Vn(e){return e&&e.constructor&&e.constructor.isBuffer&&e.constructor.isBuffer.call(null,e)}function Ln(e){let t=Object.prototype.toString.call(e).slice(8,-1);if(zn.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}};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 f=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 ee=globalThis.process&&!globalThis.process.browser&&globalThis.Buffer&&typeof globalThis.Buffer.isBuffer=="function",Fn=new TextDecoder,Hn=new TextEncoder;function Se(e){return ee&&globalThis.Buffer.isBuffer(e)}function ot(e){return e instanceof Uint8Array?Se(e)?new Uint8Array(e.buffer,e.byteOffset,e.byteLength):e:Uint8Array.from(e)}var Ht=ee?(e,t,r)=>r-t>64?globalThis.Buffer.from(e.subarray(t,r)).toString("utf8"):Lt(e,t,r):(e,t,r)=>r-t>64?Fn.decode(e.subarray(t,r)):Lt(e,t,r),Pt=ee?e=>e.length>64?globalThis.Buffer.from(e):Vt(e):e=>e.length>64?Hn.encode(e):Vt(e),R=e=>Uint8Array.from(e),te=ee?(e,t,r)=>Se(e)?new Uint8Array(e.subarray(t,r)):e.slice(t,r):(e,t,r)=>e.slice(t,r),qt=ee?(e,t)=>(e=e.map(r=>r instanceof Uint8Array?r:globalThis.Buffer.from(r)),ot(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},Gt=ee?e=>globalThis.Buffer.allocUnsafe(e):e=>new Uint8Array(e);function Jt(e,t){if(Se(e)&&Se(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 Vt(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):(t[r++]=o>>12|224,t[r++]=o>>6&63|128,t[r++]=o&63|128)}return t}function Lt(e,t,r){let n=[];for(;t<r;){let o=e[t],i=null,a=o>239?4:o>223?3:o>191?2:1;if(t+a<=r){let c,d,h,p;switch(a){case 1:o<128&&(i=o);break;case 2:c=e[t+1],(c&192)===128&&(p=(o&31)<<6|c&63,p>127&&(i=p));break;case 3:c=e[t+1],d=e[t+2],(c&192)===128&&(d&192)===128&&(p=(o&15)<<12|(c&63)<<6|d&63,p>2047&&(p<55296||p>57343)&&(i=p));break;case 4:c=e[t+1],d=e[t+2],h=e[t+3],(c&192)===128&&(d&192)===128&&(h&192)===128&&(p=(o&15)<<18|(c&63)<<12|(d&63)<<6|h&63,p>65535&&p<1114112&&(i=p))}}i===null?(i=65533,a=1):i>65535&&(i-=65536,n.push(i>>>10&1023|55296),i=56320|i&1023),n.push(i),t+=a}return Pn(n)}var Ft=4096;function Pn(e){let t=e.length;if(t<=Ft)return String.fromCharCode.apply(String,e);let r="",n=0;for(;n<t;)r+=String.fromCharCode.apply(String,e.slice(n,n+=Ft));return r}var qn=256,le=class{constructor(t=qn){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=Gt(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=te(n,0,this.cursor)}else r=qt(this.chunks,this.cursor);return t&&this.reset(),r}};var l="CBOR decode error:",it="CBOR encode error:",he=[];he[23]=1;he[24]=2;he[25]=3;he[26]=5;he[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 v(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 E(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 k(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 Kt(e,t,r,n){return new f(s.uint,v(e,t+1,n),2)}function Wt(e,t,r,n){return new f(s.uint,E(e,t+1,n),3)}function Xt(e,t,r,n){return new f(s.uint,_(e,t+1,n),5)}function Qt(e,t,r,n){return new f(s.uint,k(e,t+1,n),9)}function T(e,t){return x(e,0,t.value)}function x(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 x.encodedSize(t.value)};x.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 Yt(e,t,r,n){return new f(s.negint,-1-v(e,t+1,n),2)}function Zt(e,t,r,n){return new f(s.negint,-1-E(e,t+1,n),3)}function jt(e,t,r,n){return new f(s.negint,-1-_(e,t+1,n),5)}var st=BigInt(-1),er=BigInt(1);function tr(e,t,r,n){let o=k(e,t+1,n);if(typeof o!="bigint"){let i=-1-o;if(i>=Number.MIN_SAFE_INTEGER)return new f(s.negint,i,9)}if(n.allowBigInt!==!0)throw new Error(`${l} integers outside of the safe integer range are not supported`);return new f(s.negint,st-BigInt(o),9)}function Be(e,t){let r=t.value,n=typeof r=="bigint"?r*st-er:r*-1-1;x(e,t.type.majorEncoded,n)}Be.encodedSize=function(t){let r=t.value,n=typeof r=="bigint"?r*st-er:r*-1-1;return n<g[0]?1:n<g[1]?2:n<g[2]?3:n<g[3]?5:9};Be.compareTokens=function(t,r){return t.value<r.value?1:t.value>r.value?-1:0};function pe(e,t,r,n){V(e,t,r+n);let o=te(e,t+r,t+r+n);return new f(s.bytes,o,r+n)}function rr(e,t,r,n){return pe(e,t,1,r)}function nr(e,t,r,n){return pe(e,t,2,v(e,t+1,n))}function or(e,t,r,n){return pe(e,t,3,E(e,t+1,n))}function ir(e,t,r,n){return pe(e,t,5,_(e,t+1,n))}function sr(e,t,r,n){let o=k(e,t+1,n);if(typeof o=="bigint")throw new Error(`${l} 64-bit integer bytes lengths not supported`);return pe(e,t,9,o)}function Ne(e){return e.encodedBytes===void 0&&(e.encodedBytes=e.type===s.string?Pt(e.value):e.value),e.encodedBytes}function re(e,t){let r=Ne(t);x(e,t.type.majorEncoded,r.length),e.push(r)}re.encodedSize=function(t){let r=Ne(t);return x.encodedSize(r.length)+r.length};re.compareTokens=function(t,r){return Jn(Ne(t),Ne(r))};function Jn(e,t){return e.length<t.length?-1:e.length>t.length?1:Jt(e,t)}function ye(e,t,r,n,o){let i=r+n;V(e,t,i);let a=new f(s.string,Ht(e,t+r,t+i),i);return o.retainStringBytes===!0&&(a.byteValue=te(e,t+r,t+i)),a}function ar(e,t,r,n){return ye(e,t,1,r,n)}function cr(e,t,r,n){return ye(e,t,2,v(e,t+1,n),n)}function fr(e,t,r,n){return ye(e,t,3,E(e,t+1,n),n)}function ur(e,t,r,n){return ye(e,t,5,_(e,t+1,n),n)}function dr(e,t,r,n){let o=k(e,t+1,n);if(typeof o=="bigint")throw new Error(`${l} 64-bit integer string lengths not supported`);return ye(e,t,9,o,n)}var lr=re;function ne(e,t,r,n){return new f(s.array,n,r)}function hr(e,t,r,n){return ne(e,t,1,r)}function pr(e,t,r,n){return ne(e,t,2,v(e,t+1,n))}function yr(e,t,r,n){return ne(e,t,3,E(e,t+1,n))}function mr(e,t,r,n){return ne(e,t,5,_(e,t+1,n))}function gr(e,t,r,n){let o=k(e,t+1,n);if(typeof o=="bigint")throw new Error(`${l} 64-bit integer array lengths not supported`);return ne(e,t,9,o)}function wr(e,t,r,n){if(n.allowIndefinite===!1)throw new Error(`${l} indefinite length items not allowed`);return ne(e,t,1,1/0)}function De(e,t){x(e,s.array.majorEncoded,t.value)}De.compareTokens=T.compareTokens;De.encodedSize=function(t){return x.encodedSize(t.value)};function oe(e,t,r,n){return new f(s.map,n,r)}function xr(e,t,r,n){return oe(e,t,1,r)}function br(e,t,r,n){return oe(e,t,2,v(e,t+1,n))}function vr(e,t,r,n){return oe(e,t,3,E(e,t+1,n))}function Er(e,t,r,n){return oe(e,t,5,_(e,t+1,n))}function _r(e,t,r,n){let o=k(e,t+1,n);if(typeof o=="bigint")throw new Error(`${l} 64-bit integer map lengths not supported`);return oe(e,t,9,o)}function kr(e,t,r,n){if(n.allowIndefinite===!1)throw new Error(`${l} indefinite length items not allowed`);return oe(e,t,1,1/0)}function Oe(e,t){x(e,s.map.majorEncoded,t.value)}Oe.compareTokens=T.compareTokens;Oe.encodedSize=function(t){return x.encodedSize(t.value)};function Ar(e,t,r,n){return new f(s.tag,r,1)}function Tr(e,t,r,n){return new f(s.tag,v(e,t+1,n),2)}function Ur(e,t,r,n){return new f(s.tag,E(e,t+1,n),3)}function Cr(e,t,r,n){return new f(s.tag,_(e,t+1,n),5)}function Ir(e,t,r,n){return new f(s.tag,k(e,t+1,n),9)}function Re(e,t){x(e,s.tag.majorEncoded,t.value)}Re.compareTokens=T.compareTokens;Re.encodedSize=function(t){return x.encodedSize(t.value)};var Zn=20,jn=21,eo=22,to=23;function Sr(e,t,r,n){if(n.allowUndefined===!1)throw new Error(`${l} undefined values are not supported`);return n.coerceUndefinedToNull===!0?new f(s.null,null,1):new f(s.undefined,void 0,1)}function Br(e,t,r,n){if(n.allowIndefinite===!1)throw new Error(`${l} indefinite length items not allowed`);return new f(s.break,void 0,1)}function at(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 f(s.float,e,t)}function Nr(e,t,r,n){return at(ct(e,t+1),3,n)}function Dr(e,t,r,n){return at(ft(e,t+1),5,n)}function Or(e,t,r,n){return at(zr(e,t+1),9,n)}function Me(e,t,r){let n=t.value;if(n===!1)e.push([s.float.majorEncoded|Zn]);else if(n===!0)e.push([s.float.majorEncoded|jn]);else if(n===null)e.push([s.float.majorEncoded|eo]);else if(n===void 0)e.push([s.float.majorEncoded|to]);else{let o,i=!1;(!r||r.float64!==!0)&&(Mr(n),o=ct(S,1),n===o||Number.isNaN(n)?(S[0]=249,e.push(S.slice(0,3)),i=!0):($r(n),o=ft(S,1),n===o&&(S[0]=250,e.push(S.slice(0,5)),i=!0))),i||(ro(n),o=zr(S,1),S[0]=251,e.push(S.slice(0,9)))}}Me.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){Mr(n);let o=ct(S,1);if(n===o||Number.isNaN(n))return 3;if($r(n),o=ft(S,1),n===o)return 5}return 9};var Rr=new ArrayBuffer(9),U=new DataView(Rr,1),S=new Uint8Array(Rr,0);function Mr(e){if(e===1/0)U.setUint16(0,31744,!1);else if(e===-1/0)U.setUint16(0,64512,!1);else if(Number.isNaN(e))U.setUint16(0,32256,!1);else{U.setFloat32(0,e);let t=U.getUint32(0),r=(t&2139095040)>>23,n=t&8388607;if(r===255)U.setUint16(0,31744,!1);else if(r===0)U.setUint16(0,(e&2147483648)>>16|n>>13,!1);else{let o=r-127;o<-24?U.setUint16(0,0):o<-14?U.setUint16(0,(t&2147483648)>>16|1<<24+o,!1):U.setUint16(0,(t&2147483648)>>16|o+15<<10|n>>13,!1)}}}function ct(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 $r(e){U.setFloat32(0,e,!1)}function ft(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 ro(e){U.setFloat64(0,e,!1)}function zr(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)}Me.compareTokens=T.compareTokens;function y(e,t,r){throw new Error(`${l} encountered invalid minor (${r}) for major ${e[t]>>>5}`)}function $e(e){return()=>{throw new Error(`${l} ${e}`)}}var u=[];for(let e=0;e<=23;e++)u[e]=y;u[24]=Kt;u[25]=Wt;u[26]=Xt;u[27]=Qt;u[28]=y;u[29]=y;u[30]=y;u[31]=y;for(let e=32;e<=55;e++)u[e]=y;u[56]=Yt;u[57]=Zt;u[58]=jt;u[59]=tr;u[60]=y;u[61]=y;u[62]=y;u[63]=y;for(let e=64;e<=87;e++)u[e]=rr;u[88]=nr;u[89]=or;u[90]=ir;u[91]=sr;u[92]=y;u[93]=y;u[94]=y;u[95]=$e("indefinite length bytes/strings are not supported");for(let e=96;e<=119;e++)u[e]=ar;u[120]=cr;u[121]=fr;u[122]=ur;u[123]=dr;u[124]=y;u[125]=y;u[126]=y;u[127]=$e("indefinite length bytes/strings are not supported");for(let e=128;e<=151;e++)u[e]=hr;u[152]=pr;u[153]=yr;u[154]=mr;u[155]=gr;u[156]=y;u[157]=y;u[158]=y;u[159]=wr;for(let e=160;e<=183;e++)u[e]=xr;u[184]=br;u[185]=vr;u[186]=Er;u[187]=_r;u[188]=y;u[189]=y;u[190]=y;u[191]=kr;for(let e=192;e<=215;e++)u[e]=Ar;u[216]=Tr;u[217]=Ur;u[218]=Cr;u[219]=Ir;u[220]=y;u[221]=y;u[222]=y;u[223]=y;for(let e=224;e<=243;e++)u[e]=$e("simple values are not supported");u[244]=y;u[245]=y;u[246]=y;u[247]=Sr;u[248]=$e("simple values are not supported");u[249]=Nr;u[250]=Dr;u[251]=Or;u[252]=y;u[253]=y;u[254]=y;u[255]=Br;var B=[];for(let e=0;e<24;e++)B[e]=new f(s.uint,e,1);for(let e=-1;e>=-24;e--)B[31-e]=new f(s.negint,e,1);B[64]=new f(s.bytes,new Uint8Array(0),1);B[96]=new f(s.string,"",1);B[128]=new f(s.array,0,1);B[160]=new f(s.map,0,1);B[244]=new f(s.false,!1,1);B[245]=new f(s.true,!0,1);B[246]=new f(s.null,null,1);function ze(e){switch(e.type){case s.false:return R([244]);case s.true:return R([245]);case s.null:return R([246]);case s.bytes:return e.value.length?void 0:R([64]);case s.string:return e.value===""?R([96]):void 0;case s.array:return e.value===0?R([128]):void 0;case s.map:return e.value===0?R([160]):void 0;case s.uint:return e.value<24?R([Number(e.value)]):void 0;case s.negint:if(e.value>=-24)return R([31-Number(e.value)])}}var oo={float64:!1,mapSorter:so,quickEncodeToken:ze};function dt(){let e=[];return e[s.uint.major]=T,e[s.negint.major]=Be,e[s.bytes.major]=re,e[s.string.major]=lr,e[s.array.major]=De,e[s.map.major]=Oe,e[s.tag.major]=Re,e[s.float.major]=Me,e}var Vr=dt(),ut=new le,Ve=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(`${it} object contains circular references`);return new e(r,t)}},H={null:new f(s.null,null),undefined:new f(s.undefined,void 0),true:new f(s.true,!0),false:new f(s.false,!1),emptyArray:new f(s.array,0),emptyMap:new f(s.map,0)},P={number(e,t,r,n){return!Number.isInteger(e)||!Number.isSafeInteger(e)?new f(s.float,e):e>=0?new f(s.uint,e):new f(s.negint,e)},bigint(e,t,r,n){return e>=BigInt(0)?new f(s.uint,e):new f(s.negint,e)},Uint8Array(e,t,r,n){return new f(s.bytes,e)},string(e,t,r,n){return new f(s.string,e)},boolean(e,t,r,n){return e?H.true:H.false},null(e,t,r,n){return H.null},undefined(e,t,r,n){return H.undefined},ArrayBuffer(e,t,r,n){return new f(s.bytes,new Uint8Array(e))},DataView(e,t,r,n){return new f(s.bytes,new Uint8Array(e.buffer,e.byteOffset,e.byteLength))},Array(e,t,r,n){if(!e.length)return r.addBreakTokens===!0?[H.emptyArray,new f(s.break)]:H.emptyArray;n=Ve.createCheck(n,e);let o=[],i=0;for(let a of e)o[i++]=me(a,r,n);return r.addBreakTokens?[new f(s.array,e.length),o,new f(s.break)]:[new f(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;if(!a)return r.addBreakTokens===!0?[H.emptyMap,new f(s.break)]:H.emptyMap;n=Ve.createCheck(n,e);let c=[],d=0;for(let h of i)c[d++]=[me(h,r,n),me(o?e.get(h):e[h],r,n)];return io(c,r),r.addBreakTokens?[new f(s.map,a),c,new f(s.break)]:[new f(s.map,a),c]}};P.Map=P.Object;P.Buffer=P.Uint8Array;for(let e of"Uint8Clamped Uint16 Uint32 Int8 Int16 Int32 BigUint64 BigInt64 Float32 Float64".split(" "))P[`${e}Array`]=P.DataView;function me(e,t={},r){let n=zt(e),o=t&&t.typeEncoders&&t.typeEncoders[n]||P[n];if(typeof o=="function"){let a=o(e,n,t,r);if(a!=null)return a}let i=P[n];if(!i)throw new Error(`${it} unsupported type: ${n}`);return i(e,n,t,r)}function io(e,t){t.mapSorter&&e.sort(t.mapSorter)}function so(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=Vr[o].compareTokens(r,n);return i===0&&console.warn("WARNING: complex key types used, CBOR key sorting guarantees are gone"),i}function Lr(e,t,r,n){if(Array.isArray(t))for(let o of t)Lr(e,o,r,n);else r[t.type.major](e,t,n)}function ao(e,t,r){let n=me(e,r);if(!Array.isArray(n)&&r.quickEncodeToken){let o=r.quickEncodeToken(n);if(o)return o;let i=t[n.type.major];if(i.encodedSize){let a=i.encodedSize(n,r),c=new le(a);if(i(c,n,r),c.chunks.length!==1)throw new Error(`Unexpected error: pre-calculated length for ${n} was wrong`);return ot(c.chunks[0])}}return ut.reset(),Lr(ut,n,t,r),ut.toBytes(!0)}function lt(e,t){return t=Object.assign({},oo,t),ao(e,Vr,t)}var co={strict:!1,allowIndefinite:!0,allowUndefined:!0,allowBigInt:!0},ht=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=B[t];if(r===void 0){let n=u[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}},ge=Symbol.for("DONE"),Le=Symbol.for("BREAK");function fo(e,t,r){let n=[];for(let o=0;o<e.value;o++){let i=we(t,r);if(i===Le){if(e.value===1/0)break;throw new Error(`${l} got unexpected break to lengthed array`)}if(i===ge)throw new Error(`${l} found array but not enough entries (got ${o}, expected ${e.value})`);n[o]=i}return n}function uo(e,t,r){let n=r.useMaps===!0,o=n?void 0:{},i=n?new Map:void 0;for(let a=0;a<e.value;a++){let c=we(t,r);if(c===Le){if(e.value===1/0)break;throw new Error(`${l} got unexpected break to lengthed map`)}if(c===ge)throw new Error(`${l} found map but not enough entries (got ${a} [no key], expected ${e.value})`);if(n!==!0&&typeof c!="string")throw new Error(`${l} non-string keys not supported (got ${typeof c})`);if(r.rejectDuplicateMapKeys===!0&&(n&&i.has(c)||!n&&c in o))throw new Error(`${l} found repeat map key "${c}"`);let d=we(t,r);if(d===ge)throw new Error(`${l} found map but not enough entries (got ${a} [no value], expected ${e.value})`);n?i.set(c,d):o[c]=d}return n?i:o}function we(e,t){if(e.done())return ge;let r=e.next();if(r.type===s.break)return Le;if(r.type.terminal)return r.value;if(r.type===s.array)return fo(r,e,t);if(r.type===s.map)return uo(r,e,t);if(r.type===s.tag){if(t.tags&&typeof t.tags[r.value]=="function"){let n=we(e,t);return t.tags[r.value](n)}throw new Error(`${l} tag not supported (${r.value})`)}throw new Error("unsupported")}function Fr(e,t){if(!(e instanceof Uint8Array))throw new Error(`${l} data to decode must be a Uint8Array`);t=Object.assign({},co,t);let r=t.tokenizer||new ht(e,t),n=we(r,t);if(n===ge)throw new Error(`${l} did not find any content to decode`);if(n===Le)throw new Error(`${l} got unexpected break`);return[n,e.subarray(r.pos())]}function pt(e,t){let[r,n]=Fr(e,t);if(n.length>0)throw new Error(`${l} too many terminals, data makes no sense`);return r}var ks=new Uint8Array(0);function Hr(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 ie(e){if(e instanceof Uint8Array&&e.constructor.name==="Uint8Array")return e;if(e instanceof ArrayBuffer)return new Uint8Array(e);if(ArrayBuffer.isView(e))return new Uint8Array(e.buffer,e.byteOffset,e.byteLength);throw new Error("Unknown type, must be binary type")}function ho(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),p=Math.log(256)/Math.log(c);function j(m){if(m instanceof Uint8Array||(ArrayBuffer.isView(m)?m=new Uint8Array(m.buffer,m.byteOffset,m.byteLength):Array.isArray(m)&&(m=Uint8Array.from(m))),!(m instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(m.length===0)return"";for(var b=0,X=0,C=0,N=m.length;C!==N&&m[C]===0;)C++,b++;for(var D=(N-C)*p+1>>>0,A=new Uint8Array(D);C!==N;){for(var O=m[C],F=0,I=D-1;(O!==0||F<X)&&I!==-1;I--,F++)O+=256*A[I]>>>0,A[I]=O%c>>>0,O=O/c>>>0;if(O!==0)throw new Error("Non-zero carry");X=F,C++}for(var z=D-X;z!==D&&A[z]===0;)z++;for(var Ue=d.repeat(b);z<D;++z)Ue+=e.charAt(A[z]);return Ue}function Te(m){if(typeof m!="string")throw new TypeError("Expected String");if(m.length===0)return new Uint8Array;var b=0;if(m[b]!==" "){for(var X=0,C=0;m[b]===d;)X++,b++;for(var N=(m.length-b)*h+1>>>0,D=new Uint8Array(N);m[b];){var A=r[m.charCodeAt(b)];if(A===255)return;for(var O=0,F=N-1;(A!==0||O<C)&&F!==-1;F--,O++)A+=c*D[F]>>>0,D[F]=A%256>>>0,A=A/256>>>0;if(A!==0)throw new Error("Non-zero carry");C=O,b++}if(m[b]!==" "){for(var I=N-C;I!==N&&D[I]===0;)I++;for(var z=new Uint8Array(X+(N-I)),Ue=X;I!==N;)z[Ue++]=D[I++];return z}}}function Sn(m){var b=Te(m);if(b)return b;throw new Error(`Non-${t} character`)}return{encode:j,decodeUnsafe:Te,decode:Sn}}var po=ho,yo=po,Pr=yo;var yt=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")}},mt=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,r,n){if(this.name=t,this.prefix=r,r.codePointAt(0)===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=r.codePointAt(0),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 qr(this,t)}},gt=class{decoders;constructor(t){this.decoders=t}or(t){return qr(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 qr(e,t){return new gt({...e.decoders??{[e.prefix]:e},...t.decoders??{[t.prefix]:t}})}var wt=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 yt(t,r,n),this.decoder=new mt(t,r,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function Gr({name:e,prefix:t,encode:r,decode:n}){return new wt(e,t,r,n)}function xt({name:e,prefix:t,alphabet:r}){let{encode:n,decode:o}=Pr(r,e);return Gr({prefix:t,name:e,encode:n,decode:i=>ie(o(i))})}function mo(e,t,r,n){let o={};for(let p=0;p<t.length;++p)o[t[p]]=p;let i=e.length;for(;e[i-1]==="=";)--i;let a=new Uint8Array(i*r/8|0),c=0,d=0,h=0;for(let p=0;p<i;++p){let j=o[e[p]];if(j===void 0)throw new SyntaxError(`Non-${n} character`);d=d<<r|j,c+=r,c>=8&&(c-=8,a[h++]=255&d>>c)}if(c>=r||255&d<<8-c)throw new SyntaxError("Unexpected end of data");return a}function go(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;)i+="=";return i}function M({name:e,prefix:t,bitsPerChar:r,alphabet:n}){return Gr({prefix:t,name:e,encode(o){return go(o,n,r)},decode(o){return mo(o,n,r,e)}})}var xe=M({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Bs=M({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Ns=M({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Ds=M({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Os=M({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Rs=M({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Ms=M({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),$s=M({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),zs=M({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var L=xt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Fs=xt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var wo=Wr,Jr=128,xo=127,bo=~xo,vo=Math.pow(2,31);function Wr(e,t,r){t=t||[],r=r||0;for(var n=r;e>=vo;)t[r++]=e&255|Jr,e/=128;for(;e&bo;)t[r++]=e&255|Jr,e>>>=7;return t[r]=e|0,Wr.bytes=r-n+1,t}var Eo=bt,_o=128,Kr=127;function bt(e,n){var r=0,n=n||0,o=0,i=n,a,c=e.length;do{if(i>=c)throw bt.bytes=0,new RangeError("Could not decode varint");a=e[i++],r+=o<28?(a&Kr)<<o:(a&Kr)*Math.pow(2,o),o+=7}while(a>=_o);return bt.bytes=i-n,r}var ko=Math.pow(2,7),Ao=Math.pow(2,14),To=Math.pow(2,21),Uo=Math.pow(2,28),Co=Math.pow(2,35),Io=Math.pow(2,42),So=Math.pow(2,49),Bo=Math.pow(2,56),No=Math.pow(2,63),Do=function(e){return e<ko?1:e<Ao?2:e<To?3:e<Uo?4:e<Co?5:e<Io?6:e<So?7:e<Bo?8:e<No?9:10},Oo={encode:wo,decode:Eo,encodingLength:Do},Ro=Oo,be=Ro;function ve(e,t=0){return[be.decode(e,t),be.decode.bytes]}function se(e,t,r=0){return be.encode(e,t,r),t}function ae(e){return be.encodingLength(e)}function Qr(e,t){let r=t.byteLength,n=ae(e),o=n+ae(r),i=new Uint8Array(o+r);return se(e,i,0),se(r,i,n),i.set(t,o),new ce(e,r,t,i)}function q(e){let t=ie(e),[r,n]=ve(t),[o,i]=ve(t.subarray(n)),a=t.subarray(n+i);if(a.byteLength!==o)throw new Error("Incorrect length");return new ce(r,o,a,t)}function Yr(e,t){if(e===t)return!0;{let r=t;return e.code===r.code&&e.size===r.size&&r.bytes instanceof Uint8Array&&Hr(e.bytes,r.bytes)}}var ce=class{code;size;digest;bytes;constructor(t,r,n,o){this.code=t,this.size=r,this.digest=n,this.bytes=o}};function Zr(e,t){let{bytes:r,version:n}=e;switch(n){case 0:return $o(r,Et(e),t??L.encoder);default:return zo(r,Et(e),t??xe.encoder)}}var jr=new WeakMap;function Et(e){let t=jr.get(e);if(t==null){let r=new Map;return jr.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=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:t,multihash:r}=this;if(t!==Ee)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==Vo)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=Qr(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&&Yr(t.multihash,n.multihash)}toString(t){return Zr(this,t)}toJSON(){return{"/":Zr(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??en(n,o,i.bytes))}else if(r[Lo]===!0){let{version:n,multihash:o,code:i}=r,a=q(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!==Ee)throw new Error(`Version 0 CID must use dag-pb (code: ${Ee}) block encoding`);return new e(t,r,n,n.bytes)}case 1:{let o=en(t,r,n.bytes);return new e(t,r,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return e.create(0,Ee,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=ie(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 ce(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[j,Te]=ve(t.subarray(r));return r+=Te,j},o=n(),i=Ee;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,p=h-a;return{version:o,codec:i,multihashCode:c,digestSize:d,multihashSize:p,size:h}}static parse(t,r){let[n,o]=Mo(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 Et(i).set(n,t),i}};function Mo(e,t){switch(e[0]){case"Q":{let r=t??L;return[L.prefix,r.decode(`${L.prefix}${e}`)]}case L.prefix:{let r=t??L;return[L.prefix,r.decode(e)]}case xe.prefix:{let r=t??xe;return[xe.prefix,r.decode(e)]}default:{if(t==null)throw Error("To parse non base32 or base58btc encoded CID multibase decoder must be provided");return[e[0],t.decode(e)]}}}function $o(e,t,r){let{prefix:n}=r;if(n!==L.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 zo(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 Ee=112,Vo=18;function en(e,t,r){let n=ae(e),o=n+ae(t),i=new Uint8Array(o+r.byteLength);return se(e,i,0),se(t,i,n),i.set(r,o),i}var Lo=Symbol.for("@ipld/js-cid/CID");var tn=42;function Fo(e){return e instanceof ArrayBuffer?new Uint8Array(e,0,e.byteLength):e}function Ho(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 f(s.tag,tn),new f(s.bytes,r)]}function Po(){throw new Error("`undefined` is not supported by the IPLD Data Model and cannot be encoded")}function qo(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}var _t={float64:!0,typeEncoders:{Object:Ho,undefined:Po,number:qo}},Zs={..._t,typeEncoders:{..._t.typeEncoders}};function Go(e){if(e[0]!==0)throw new Error("Invalid CID for CBOR tag 42; expected leading 0x00");return w.decode(e.subarray(1))}var Fe={allowIndefinite:!1,coerceUndefinedToNull:!0,allowNaN:!1,allowInfinity:!1,allowBigInt:!0,strict:!0,useMaps:!1,rejectDuplicateMapKeys:!0,tags:[]};Fe.tags[tn]=Go;var js={...Fe,tags:Fe.tags.slice()};var He=e=>lt(e,_t),Pe=e=>pt(Fo(e),Fe);var G=Ie(qe(),1),J={SHA2_256:18,LENGTH:32,DAG_PB:112},Ge=40;function $(e,t){if(!e.length)throw new Error("Unexpected end of data");let r=G.default.decode(e);return t.seek(G.default.decode.bytes),r}function Je(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 Ke(e){G.default.decode(e);let t=G.default.decode.bytes,r=G.default.decode(e.subarray(G.default.decode.bytes)),n=G.default.decode.bytes;return t+n+r}var K={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},_e={"CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)":K.Link,"CarV1HeaderOrV2Pragma > roots (anon)":e=>{if(K.List(e)!==void 0){for(let t=0;t<e.length;t++){let r=e[t];if(r=_e["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=_e["CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)"](i),i===void 0)return;n.push(i)}return n}}return e}},Int:K.Int,CarV1HeaderOrV2Pragma:e=>{if(K.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=_e["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=_e.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}},ke={"CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)":K.Link,"CarV1HeaderOrV2Pragma > roots (anon)":e=>{if(K.List(e)!==void 0){for(let t=0;t<e.length;t++){let r=e[t];if(r=ke["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=ke["CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)"](i),i===void 0)return;n.push(i)}return n}}return e}},Int:K.Int,CarV1HeaderOrV2Pragma:e=>{if(K.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=ke["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=ke.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}},We={toTyped:_e.CarV1HeaderOrV2Pragma,toRepresentation:ke.CarV1HeaderOrV2Pragma};function ln(e,t){let r=$(e.upTo(8),e);if(r===0)throw new Error("Invalid CAR header (zero length)");let n=e.exactly(r,!0),o=Pe(n);if(We.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=Je(e.exactly(Ge,!0));e.seek(i.dataOffset-e.pos);let a=ln(e,1);return Object.assign(a,i)}function si(e){let t=e.exactly(2,!1);if(t[0]===J.SHA2_256&&t[1]===J.LENGTH){let a=e.exactly(34,!0),c=q(a);return w.create(0,J.DAG_PB,c)}let r=$(e.upTo(8),e);if(r!==1)throw new Error(`Unexpected CID version (${r})`);let n=$(e.upTo(8),e),o=e.exactly(Ke(e.upTo(8)),!0),i=q(o);return w.create(r,n,i)}function ai(e){let t=e.pos,r=$(e.upTo(8),e);if(r===0)throw new Error("Invalid CAR section (zero length)");r+=e.pos-t;let n=si(e),o=r-Number(e.pos-t);return{cid:n,length:r,blockLength:o}}function hn(e){let t=ci(e),r=ln(t);if(r.version===2){let o=t.pos-r.dataOffset;t=fi(t,r.dataSize-o)}let n=[];for(;t.upTo(8).length>0;){let{cid:o,blockLength:i}=ai(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 fi(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 Xe=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}=hn(t);return new e(r,n)}};var Nt={};Mt(Nt,{addBlock:()=>mn,addRoot:()=>yn,blockLength:()=>hi,calculateHeaderLength:()=>St,close:()=>gn,createWriter:()=>gi,estimateHeaderLength:()=>mi,headerLength:()=>Bt,resizeHeader:()=>It});var di=dt(),li={float64:!1,quickEncodeToken:ze};function Tt(e,t=di,r=li){if(Array.isArray(e)){let n=0;for(let o of e)n+=Tt(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 Ae=Ie(qe(),1),Ct=class{constructor(t,r){this.bytes=t,this.byteOffset=r,this.roots=[],this.headerSize=r}addRoot(t,r){return yn(this,t,r),this}write(t){return mn(this,t),this}close(t){return gn(this,t)}},yn=(e,t,r={})=>{let{resize:n=!1}=r,{bytes:o,headerSize:i,byteOffset:a,roots:c}=e;e.roots.push(t);let d=Bt(e);if(d>i)if(d-i+a<o.byteLength)if(n)It(e,d);else throw c.pop(),new RangeError(`Header of size ${i} has no capacity for new root ${t}.
3
- 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}`)},hi=({cid:e,bytes:t})=>{let r=e.bytes.byteLength+t.byteLength;return Ae.default.encodingLength(r)+r},mn=(e,{cid:t,bytes:r})=>{let n=t.bytes.byteLength+r.byteLength,o=Ae.default.encode(n);if(e.byteOffset+o.length+n>e.bytes.byteLength)throw new RangeError("Buffer has no capacity for this block");Ut(e,o),Ut(e,t.bytes),Ut(e,r)},gn=(e,t={})=>{let{resize:r=!1}=t,{roots:n,bytes:o,byteOffset:i,headerSize:a}=e,c=He({version:1,roots:n}),d=Ae.default.encode(c.length),h=d.length+c.byteLength;if(a-h===0)return pn(e,d,c),o.subarray(0,i);if(r)return It(e,h),pn(e,d,c),o.subarray(0,e.byteOffset);throw new RangeError(`Header size was overestimated.
4
- You can use close({ resize: true }) to resize header`)},It=(e,t)=>{let{bytes:r,headerSize:n}=e;r.set(r.subarray(n,e.byteOffset),t),e.byteOffset+=t-n,e.headerSize=t},Ut=(e,t)=>{e.bytes.set(t,e.byteOffset),e.byteOffset+=t.length},pn=({bytes:e},t,r)=>{e.set(t),e.set(r,t.length)},pi=[new f(s.map,2),new f(s.string,"version"),new f(s.uint,1),new f(s.string,"roots")],yi=new f(s.tag,42),St=e=>{let t=[...pi];t.push(new f(s.array,e.length));for(let n of e)t.push(yi),t.push(new f(s.bytes,{length:n+1}));let r=Tt(t);return Ae.default.encodingLength(r)+r},Bt=({roots:e})=>St(e.map(t=>t.bytes.byteLength)),mi=(e,t=36)=>St(new Array(e).fill(t)),gi=(e,t={})=>{let{roots:r=[],byteOffset:n=0,byteLength:o=e.byteLength,headerSize:i=Bt({roots:r})}=t,a=new Uint8Array(e,n,o),c=new Ct(a,i);for(let d of r)c.addRoot(d);return c};var Dt=Ie(wn(),1);async function Qe(e,t){let r=$(await e.upTo(8),e);if(r===0)throw new Error("Invalid CAR header (zero length)");let n=await e.exactly(r,!0),o=Pe(n);if(We.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=Je(await e.exactly(Ge,!0));e.seek(i.dataOffset-e.pos);let a=await Qe(e,1);return Object.assign(a,i)}async function wi(e){let t=await e.exactly(2,!1);if(t[0]===J.SHA2_256&&t[1]===J.LENGTH){let a=await e.exactly(34,!0),c=q(a);return w.create(0,J.DAG_PB,c)}let r=$(await e.upTo(8),e);if(r!==1)throw new Error(`Unexpected CID version (${r})`);let n=$(await e.upTo(8),e),o=await e.exactly(Ke(await e.upTo(8)),!0),i=q(o);return w.create(r,n,i)}async function xn(e){let t=e.pos,r=$(await e.upTo(8),e);if(r===0)throw new Error("Invalid CAR section (zero length)");r+=e.pos-t;let n=await wi(e),o=r-Number(e.pos-t);return{cid:n,length:r,blockLength:o}}async function xi(e){let{cid:t,blockLength:r}=await xn(e);return{bytes:await e.exactly(r,!0),cid:t}}async function bi(e){let t=e.pos,{cid:r,length:n,blockLength:o}=await xn(e),i={cid:r,length:n,blockLength:o,offset:t,blockOffset:e.pos};return e.seek(i.blockLength),i}function fe(e){let t=(async()=>{let r=await Qe(e);if(r.version===2){let n=e.pos-r.dataOffset;e=Ei(e,r.dataSize-n)}return r})();return{header:()=>t,async*blocks(){for(await t;(await e.upTo(8)).length>0;)yield await xi(e)},async*blocksIndex(){for(await t;(await e.upTo(8)).length>0;)yield await bi(e)}}}function W(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 vi(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,p)=>h+p.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 ue(e){let t=e[Symbol.asyncIterator]();async function r(){let n=await t.next();return n.done?null:n.value}return vi(r)}function Ei(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 Y=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 fromBytes(t){if(!(t instanceof Uint8Array))throw new TypeError("fromBytes() requires a Uint8Array");return bn(W(t))}static async fromIterable(t){if(!t||typeof t[Symbol.asyncIterator]!="function")throw new TypeError("fromIterable() requires an async iterable");return bn(ue(t))}};async function bn(e){let t=fe(e),{version:r,roots:n}=await t.header();return new Y(r,n,t.blocksIndex())}var Z=class{constructor(t,r){this._header=t,this._blocks=r,this._keys=r.map(n=>n.cid.toString())}get version(){return this._header.version}async getRoots(){return this._header.roots}async has(t){return this._keys.indexOf(t.toString())>-1}async get(t){let r=this._keys.indexOf(t.toString());return r>-1?this._blocks[r]:void 0}async*blocks(){for(let t of this._blocks)yield t}async*cids(){for(let t of this._blocks)yield t.cid}static async fromBytes(t){if(!(t instanceof Uint8Array))throw new TypeError("fromBytes() requires a Uint8Array");return vn(W(t))}static async fromIterable(t){if(!t||typeof t[Symbol.asyncIterator]!="function")throw new TypeError("fromIterable() requires an async iterable");return vn(ue(t))}};async function vn(e){let t=fe(e),r=await t.header(),n=[];for await(let o of t.blocks())n.push(o);return new Z(r,n)}var Ye=class e{constructor(t,r,n,o,i){this._version=t,this._path=r,this._roots=n,this._index=o,this._order=i,this._fd=null}get version(){return this._version}async getRoots(){return this._roots}async has(t){return this._index.has(t.toString())}async get(t){let r=this._index.get(t.toString());if(!r)return;this._fd||(this._fd=await Dt.default.promises.open(this._path,"r"));let n={cid:t,length:0,offset:0,blockLength:r.blockLength,blockOffset:r.blockOffset};return Z.readRaw(this._fd,n)}async*blocks(){for(let t of this._order){let r=await this.get(w.parse(t));if(!r)throw new Error("Unexpected internal error");yield r}}async*cids(){for(let t of this._order)yield w.parse(t)}async close(){if(this._fd)return this._fd.close()}static async fromFile(t){if(typeof t!="string")throw new TypeError("fromFile() requires a file path string");let r=await Y.fromIterable((void 0).from(Dt.default.createReadStream(t))),n=new Map,o=[];for await(let{cid:i,blockLength:a,blockOffset:c}of r){let d=i.toString();n.set(d,{blockLength:a,blockOffset:c}),o.push(d)}return new e(r.version,t,await r.getRoots(),n,o)}};var Ze=class{constructor(t,r,n){this._version=t,this._roots=r,this._iterable=n,this._decoded=!1}get version(){return this._version}async getRoots(){return this._roots}},je=class e extends Ze{[Symbol.asyncIterator](){if(this._decoded)throw new Error("Cannot decode more than once");if(!this._iterable)throw new Error("Block iterable not found");return this._decoded=!0,this._iterable[Symbol.asyncIterator]()}static async fromBytes(t){let{version:r,roots:n,iterator:o}=await _n(t);return new e(r,n,o)}static async fromIterable(t){let{version:r,roots:n,iterator:o}=await kn(t);return new e(r,n,o)}},et=class e extends Ze{[Symbol.asyncIterator](){if(this._decoded)throw new Error("Cannot decode more than once");if(!this._iterable)throw new Error("Block iterable not found");this._decoded=!0;let t=this._iterable[Symbol.asyncIterator]();return{async next(){let r=await t.next();return r.done?r:{done:!1,value:r.value.cid}}}}static async fromBytes(t){let{version:r,roots:n,iterator:o}=await _n(t);return new e(r,n,o)}static async fromIterable(t){let{version:r,roots:n,iterator:o}=await kn(t);return new e(r,n,o)}};async function _n(e){if(!(e instanceof Uint8Array))throw new TypeError("fromBytes() requires a Uint8Array");return An(W(e))}async function kn(e){if(!e||typeof e[Symbol.asyncIterator]!="function")throw new TypeError("fromIterable() requires an async iterable");return An(ue(e))}async function An(e){let t=fe(e),{version:r,roots:n}=await t.header();return{version:r,roots:n,iterator:t.blocks()}}var Ot=Ie(qe(),1),Tn=1;function Rt(e){let t=He({version:Tn,roots:e}),r=Ot.default.encode(t.length),n=new Uint8Array(r.length+t.length);return n.set(r,0),n.set(t,r.length),n}function Un(e){return{async setRoots(t){let r=Rt(t);await e.write(r)},async writeBlock(t){let{cid:r,bytes:n}=t;await e.write(new Uint8Array(Ot.default.encode(r.bytes.length+n.length))),await e.write(r.bytes),n.length&&await e.write(n)},async close(){await e.end()},version(){return Tn}}}function tt(){}function Cn(){let e=[],t=null,r=tt,n=!1,o=null,i=tt,a=()=>(t||(t=new Promise(h=>{r=()=>{t=null,r=tt,h()}})),t),c={write(h){e.push(h);let p=a();return i(),p},async end(){n=!0;let h=a();i(),await h}},d={async next(){let h=e.shift();return h?(e.length===0&&r(),{done:!1,value:h}):n?(r(),{done:!0,value:void 0}):(o||(o=new Promise(p=>{i=()=>(o=null,i=tt,p(d.next()))})),o)}};return{writer:c,iterator:d}}var rt=class e{constructor(t,r){this._encoder=r,this._mutex=r.setRoots(t),this._ended=!1}async put(t){if(!(t.bytes instanceof Uint8Array)||!t.cid)throw new TypeError("Can only write {cid, bytes} objects");if(this._ended)throw new Error("Already closed");let r=w.asCID(t.cid);if(!r)throw new TypeError("Can only write {cid, bytes} objects");return this._mutex=this._mutex.then(()=>this._encoder.writeBlock({cid:r,bytes:t.bytes})),this._mutex}async close(){if(this._ended)throw new Error("Already closed");return await this._mutex,this._ended=!0,this._encoder.close()}version(){return this._encoder.version()}static create(t){t=_i(t);let{encoder:r,iterator:n}=In(),o=new e(t,r),i=new nt(n);return{writer:o,out:i}}static createAppender(){let{encoder:t,iterator:r}=In();t.setRoots=()=>Promise.resolve();let n=new e([],t),o=new nt(r);return{writer:n,out:o}}static async updateRootsInBytes(t,r){let n=W(t);await Qe(n);let o=Rt(r);if(Number(n.pos)!==o.length)throw new Error(`updateRoots() can only overwrite a header of the same length (old header is ${n.pos} bytes, new header is ${o.length} bytes)`);return t.set(o,0),t}},nt=class{constructor(t){this._iterator=t}[Symbol.asyncIterator](){if(this._iterating)throw new Error("Multiple iterator not supported");return this._iterating=!0,this._iterator}};function In(){let e=Cn(),{writer:t,iterator:r}=e;return{encoder:Un(t),iterator:r}}function _i(e){if(e===void 0)return[];if(!Array.isArray(e)){let r=w.asCID(e);if(!r)throw new TypeError("roots must be a single CID or an array of CIDs");return[r]}let t=[];for(let r of e){let n=w.asCID(r);if(!n)throw new TypeError("roots must be a single CID or an array of CIDs");t.push(n)}return t}var ki="application/vnd.ipld.car";return Mn(Ai);})();
2
+ "use strict";var IpldCar=(()=>{var Bn=Object.create;var Ce=Object.defineProperty;var Nn=Object.getOwnPropertyDescriptor;var On=Object.getOwnPropertyNames;var Dn=Object.getPrototypeOf,Rn=Object.prototype.hasOwnProperty;var le=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),Mt=(e,t)=>{for(var r in t)Ce(e,r,{get:t[r],enumerable:!0})},zt=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of On(t))!Rn.call(e,o)&&o!==r&&Ce(e,o,{get:()=>t[o],enumerable:!(n=Nn(t,o))||n.enumerable});return e};var Ie=(e,t,r)=>(r=e!=null?Bn(Dn(e)):{},zt(t||!e||!e.__esModule?Ce(r,"default",{value:e,enumerable:!0}):r,e)),Mn=e=>zt(Ce({},"__esModule",{value:!0}),e);var on=le((ea,nn)=>{nn.exports=_t;var rn=128,Ko=127,Wo=~Ko,Xo=Math.pow(2,31);function _t(e,t,r){if(Number.MAX_SAFE_INTEGER&&e>Number.MAX_SAFE_INTEGER)throw _t.bytes=0,new RangeError("Could not encode varint");t=t||[],r=r||0;for(var n=r;e>=Xo;)t[r++]=e&255|rn,e/=128;for(;e&Wo;)t[r++]=e&255|rn,e>>>=7;return t[r]=e|0,_t.bytes=r-n+1,t}});var cn=le((ta,an)=>{an.exports=At;var Qo=128,sn=127;function At(e,n){var r=0,n=n||0,o=0,i=n,a,c=e.length;do{if(i>=c||o>49)throw At.bytes=0,new RangeError("Could not decode varint");a=e[i++],r+=o<28?(a&sn)<<o:(a&sn)*Math.pow(2,o),o+=7}while(a>=Qo);return At.bytes=i-n,r}});var un=le((ra,fn)=>{var Yo=Math.pow(2,7),Zo=Math.pow(2,14),jo=Math.pow(2,21),ei=Math.pow(2,28),ti=Math.pow(2,35),ri=Math.pow(2,42),ni=Math.pow(2,49),oi=Math.pow(2,56),ii=Math.pow(2,63);fn.exports=function(e){return e<Yo?1:e<Zo?2:e<jo?3:e<ei?4:e<ti?5:e<ri?6:e<ni?7:e<oi?8:e<ii?9:10}});var Ge=le((na,dn)=>{dn.exports={encode:on(),decode:cn(),encodingLength:un()}});var wn=le(()=>{});var Ai={};Mt(Ai,{CarBlockIterator:()=>et,CarBufferReader:()=>Qe,CarBufferWriter:()=>Nt,CarCIDIterator:()=>tt,CarIndexedReader:()=>Ze,CarIndexer:()=>Y,CarReader:()=>Z,CarWriter:()=>nt,contentType:()=>_i});var zn=["string","number","bigint","symbol"],$n=["Function","Generator","AsyncGenerator","GeneratorFunction","AsyncGeneratorFunction","AsyncFunction","Observable","Array","Buffer","Object","RegExp","Date","Error","Map","Set","WeakMap","WeakSet","ArrayBuffer","SharedArrayBuffer","DataView","Promise","URL","HTMLElement","Int8Array","Uint8Array","Uint8ClampedArray","Int16Array","Uint16Array","Int32Array","Uint32Array","Float32Array","Float64Array","BigInt64Array","BigUint64Array"];function $t(e){if(e===null)return"null";if(e===void 0)return"undefined";if(e===!0||e===!1)return"boolean";let t=typeof e;if(zn.includes(t))return t;if(t==="function")return"Function";if(Array.isArray(e))return"Array";if(Vn(e))return"Buffer";let r=Ln(e);return r||"Object"}function Vn(e){return e&&e.constructor&&e.constructor.isBuffer&&e.constructor.isBuffer.call(null,e)}function Ln(e){let t=Object.prototype.toString.call(e).slice(8,-1);if($n.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}};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 f=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 ee=globalThis.process&&!globalThis.process.browser&&globalThis.Buffer&&typeof globalThis.Buffer.isBuffer=="function",Fn=new TextDecoder,Hn=new TextEncoder;function Se(e){return ee&&globalThis.Buffer.isBuffer(e)}function it(e){return e instanceof Uint8Array?Se(e)?new Uint8Array(e.buffer,e.byteOffset,e.byteLength):e:Uint8Array.from(e)}var Ht=ee?(e,t,r)=>r-t>64?globalThis.Buffer.from(e.subarray(t,r)).toString("utf8"):Lt(e,t,r):(e,t,r)=>r-t>64?Fn.decode(e.subarray(t,r)):Lt(e,t,r),Pt=ee?e=>e.length>64?globalThis.Buffer.from(e):Vt(e):e=>e.length>64?Hn.encode(e):Vt(e),R=e=>Uint8Array.from(e),te=ee?(e,t,r)=>Se(e)?new Uint8Array(e.subarray(t,r)):e.slice(t,r):(e,t,r)=>e.slice(t,r),qt=ee?(e,t)=>(e=e.map(r=>r instanceof Uint8Array?r:globalThis.Buffer.from(r)),it(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},Gt=ee?e=>globalThis.Buffer.allocUnsafe(e):e=>new Uint8Array(e);function Jt(e,t){if(Se(e)&&Se(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 Vt(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):(t[r++]=o>>12|224,t[r++]=o>>6&63|128,t[r++]=o&63|128)}return t}function Lt(e,t,r){let n=[];for(;t<r;){let o=e[t],i=null,a=o>239?4:o>223?3:o>191?2:1;if(t+a<=r){let c,d,h,p;switch(a){case 1:o<128&&(i=o);break;case 2:c=e[t+1],(c&192)===128&&(p=(o&31)<<6|c&63,p>127&&(i=p));break;case 3:c=e[t+1],d=e[t+2],(c&192)===128&&(d&192)===128&&(p=(o&15)<<12|(c&63)<<6|d&63,p>2047&&(p<55296||p>57343)&&(i=p));break;case 4:c=e[t+1],d=e[t+2],h=e[t+3],(c&192)===128&&(d&192)===128&&(h&192)===128&&(p=(o&15)<<18|(c&63)<<12|(d&63)<<6|h&63,p>65535&&p<1114112&&(i=p))}}i===null?(i=65533,a=1):i>65535&&(i-=65536,n.push(i>>>10&1023|55296),i=56320|i&1023),n.push(i),t+=a}return Pn(n)}var Ft=4096;function Pn(e){let t=e.length;if(t<=Ft)return String.fromCharCode.apply(String,e);let r="",n=0;for(;n<t;)r+=String.fromCharCode.apply(String,e.slice(n,n+=Ft));return r}var qn=256,he=class{constructor(t=qn){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=Gt(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=te(n,0,this.cursor)}else r=qt(this.chunks,this.cursor);return t&&this.reset(),r}};var l="CBOR decode error:",st="CBOR encode error:",pe=[];pe[23]=1;pe[24]=2;pe[25]=3;pe[26]=5;pe[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 v(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 E(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 k(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 _(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 Kt(e,t,r,n){return new f(s.uint,v(e,t+1,n),2)}function Wt(e,t,r,n){return new f(s.uint,E(e,t+1,n),3)}function Xt(e,t,r,n){return new f(s.uint,k(e,t+1,n),5)}function Qt(e,t,r,n){return new f(s.uint,_(e,t+1,n),9)}function T(e,t){return x(e,0,t.value)}function x(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 x.encodedSize(t.value)};x.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 Yt(e,t,r,n){return new f(s.negint,-1-v(e,t+1,n),2)}function Zt(e,t,r,n){return new f(s.negint,-1-E(e,t+1,n),3)}function jt(e,t,r,n){return new f(s.negint,-1-k(e,t+1,n),5)}var at=BigInt(-1),er=BigInt(1);function tr(e,t,r,n){let o=_(e,t+1,n);if(typeof o!="bigint"){let i=-1-o;if(i>=Number.MIN_SAFE_INTEGER)return new f(s.negint,i,9)}if(n.allowBigInt!==!0)throw new Error(`${l} integers outside of the safe integer range are not supported`);return new f(s.negint,at-BigInt(o),9)}function Be(e,t){let r=t.value,n=typeof r=="bigint"?r*at-er:r*-1-1;x(e,t.type.majorEncoded,n)}Be.encodedSize=function(t){let r=t.value,n=typeof r=="bigint"?r*at-er:r*-1-1;return n<g[0]?1:n<g[1]?2:n<g[2]?3:n<g[3]?5:9};Be.compareTokens=function(t,r){return t.value<r.value?1:t.value>r.value?-1:0};function ye(e,t,r,n){V(e,t,r+n);let o=te(e,t+r,t+r+n);return new f(s.bytes,o,r+n)}function rr(e,t,r,n){return ye(e,t,1,r)}function nr(e,t,r,n){return ye(e,t,2,v(e,t+1,n))}function or(e,t,r,n){return ye(e,t,3,E(e,t+1,n))}function ir(e,t,r,n){return ye(e,t,5,k(e,t+1,n))}function sr(e,t,r,n){let o=_(e,t+1,n);if(typeof o=="bigint")throw new Error(`${l} 64-bit integer bytes lengths not supported`);return ye(e,t,9,o)}function Ne(e){return e.encodedBytes===void 0&&(e.encodedBytes=e.type===s.string?Pt(e.value):e.value),e.encodedBytes}function re(e,t){let r=Ne(t);x(e,t.type.majorEncoded,r.length),e.push(r)}re.encodedSize=function(t){let r=Ne(t);return x.encodedSize(r.length)+r.length};re.compareTokens=function(t,r){return Jn(Ne(t),Ne(r))};function Jn(e,t){return e.length<t.length?-1:e.length>t.length?1:Jt(e,t)}function me(e,t,r,n,o){let i=r+n;V(e,t,i);let a=new f(s.string,Ht(e,t+r,t+i),i);return o.retainStringBytes===!0&&(a.byteValue=te(e,t+r,t+i)),a}function ar(e,t,r,n){return me(e,t,1,r,n)}function cr(e,t,r,n){return me(e,t,2,v(e,t+1,n),n)}function fr(e,t,r,n){return me(e,t,3,E(e,t+1,n),n)}function ur(e,t,r,n){return me(e,t,5,k(e,t+1,n),n)}function dr(e,t,r,n){let o=_(e,t+1,n);if(typeof o=="bigint")throw new Error(`${l} 64-bit integer string lengths not supported`);return me(e,t,9,o,n)}var lr=re;function ne(e,t,r,n){return new f(s.array,n,r)}function hr(e,t,r,n){return ne(e,t,1,r)}function pr(e,t,r,n){return ne(e,t,2,v(e,t+1,n))}function yr(e,t,r,n){return ne(e,t,3,E(e,t+1,n))}function mr(e,t,r,n){return ne(e,t,5,k(e,t+1,n))}function gr(e,t,r,n){let o=_(e,t+1,n);if(typeof o=="bigint")throw new Error(`${l} 64-bit integer array lengths not supported`);return ne(e,t,9,o)}function wr(e,t,r,n){if(n.allowIndefinite===!1)throw new Error(`${l} indefinite length items not allowed`);return ne(e,t,1,1/0)}function Oe(e,t){x(e,s.array.majorEncoded,t.value)}Oe.compareTokens=T.compareTokens;Oe.encodedSize=function(t){return x.encodedSize(t.value)};function oe(e,t,r,n){return new f(s.map,n,r)}function xr(e,t,r,n){return oe(e,t,1,r)}function br(e,t,r,n){return oe(e,t,2,v(e,t+1,n))}function vr(e,t,r,n){return oe(e,t,3,E(e,t+1,n))}function Er(e,t,r,n){return oe(e,t,5,k(e,t+1,n))}function kr(e,t,r,n){let o=_(e,t+1,n);if(typeof o=="bigint")throw new Error(`${l} 64-bit integer map lengths not supported`);return oe(e,t,9,o)}function _r(e,t,r,n){if(n.allowIndefinite===!1)throw new Error(`${l} indefinite length items not allowed`);return oe(e,t,1,1/0)}function De(e,t){x(e,s.map.majorEncoded,t.value)}De.compareTokens=T.compareTokens;De.encodedSize=function(t){return x.encodedSize(t.value)};function Ar(e,t,r,n){return new f(s.tag,r,1)}function Tr(e,t,r,n){return new f(s.tag,v(e,t+1,n),2)}function Ur(e,t,r,n){return new f(s.tag,E(e,t+1,n),3)}function Cr(e,t,r,n){return new f(s.tag,k(e,t+1,n),5)}function Ir(e,t,r,n){return new f(s.tag,_(e,t+1,n),9)}function Re(e,t){x(e,s.tag.majorEncoded,t.value)}Re.compareTokens=T.compareTokens;Re.encodedSize=function(t){return x.encodedSize(t.value)};var Zn=20,jn=21,eo=22,to=23;function Sr(e,t,r,n){if(n.allowUndefined===!1)throw new Error(`${l} undefined values are not supported`);return n.coerceUndefinedToNull===!0?new f(s.null,null,1):new f(s.undefined,void 0,1)}function Br(e,t,r,n){if(n.allowIndefinite===!1)throw new Error(`${l} indefinite length items not allowed`);return new f(s.break,void 0,1)}function ct(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 f(s.float,e,t)}function Nr(e,t,r,n){return ct(ft(e,t+1),3,n)}function Or(e,t,r,n){return ct(ut(e,t+1),5,n)}function Dr(e,t,r,n){return ct($r(e,t+1),9,n)}function Me(e,t,r){let n=t.value;if(n===!1)e.push([s.float.majorEncoded|Zn]);else if(n===!0)e.push([s.float.majorEncoded|jn]);else if(n===null)e.push([s.float.majorEncoded|eo]);else if(n===void 0)e.push([s.float.majorEncoded|to]);else{let o,i=!1;(!r||r.float64!==!0)&&(Mr(n),o=ft(S,1),n===o||Number.isNaN(n)?(S[0]=249,e.push(S.slice(0,3)),i=!0):(zr(n),o=ut(S,1),n===o&&(S[0]=250,e.push(S.slice(0,5)),i=!0))),i||(ro(n),o=$r(S,1),S[0]=251,e.push(S.slice(0,9)))}}Me.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){Mr(n);let o=ft(S,1);if(n===o||Number.isNaN(n))return 3;if(zr(n),o=ut(S,1),n===o)return 5}return 9};var Rr=new ArrayBuffer(9),U=new DataView(Rr,1),S=new Uint8Array(Rr,0);function Mr(e){if(e===1/0)U.setUint16(0,31744,!1);else if(e===-1/0)U.setUint16(0,64512,!1);else if(Number.isNaN(e))U.setUint16(0,32256,!1);else{U.setFloat32(0,e);let t=U.getUint32(0),r=(t&2139095040)>>23,n=t&8388607;if(r===255)U.setUint16(0,31744,!1);else if(r===0)U.setUint16(0,(e&2147483648)>>16|n>>13,!1);else{let o=r-127;o<-24?U.setUint16(0,0):o<-14?U.setUint16(0,(t&2147483648)>>16|1<<24+o,!1):U.setUint16(0,(t&2147483648)>>16|o+15<<10|n>>13,!1)}}}function ft(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 zr(e){U.setFloat32(0,e,!1)}function ut(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 ro(e){U.setFloat64(0,e,!1)}function $r(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)}Me.compareTokens=T.compareTokens;function y(e,t,r){throw new Error(`${l} encountered invalid minor (${r}) for major ${e[t]>>>5}`)}function ze(e){return()=>{throw new Error(`${l} ${e}`)}}var u=[];for(let e=0;e<=23;e++)u[e]=y;u[24]=Kt;u[25]=Wt;u[26]=Xt;u[27]=Qt;u[28]=y;u[29]=y;u[30]=y;u[31]=y;for(let e=32;e<=55;e++)u[e]=y;u[56]=Yt;u[57]=Zt;u[58]=jt;u[59]=tr;u[60]=y;u[61]=y;u[62]=y;u[63]=y;for(let e=64;e<=87;e++)u[e]=rr;u[88]=nr;u[89]=or;u[90]=ir;u[91]=sr;u[92]=y;u[93]=y;u[94]=y;u[95]=ze("indefinite length bytes/strings are not supported");for(let e=96;e<=119;e++)u[e]=ar;u[120]=cr;u[121]=fr;u[122]=ur;u[123]=dr;u[124]=y;u[125]=y;u[126]=y;u[127]=ze("indefinite length bytes/strings are not supported");for(let e=128;e<=151;e++)u[e]=hr;u[152]=pr;u[153]=yr;u[154]=mr;u[155]=gr;u[156]=y;u[157]=y;u[158]=y;u[159]=wr;for(let e=160;e<=183;e++)u[e]=xr;u[184]=br;u[185]=vr;u[186]=Er;u[187]=kr;u[188]=y;u[189]=y;u[190]=y;u[191]=_r;for(let e=192;e<=215;e++)u[e]=Ar;u[216]=Tr;u[217]=Ur;u[218]=Cr;u[219]=Ir;u[220]=y;u[221]=y;u[222]=y;u[223]=y;for(let e=224;e<=243;e++)u[e]=ze("simple values are not supported");u[244]=y;u[245]=y;u[246]=y;u[247]=Sr;u[248]=ze("simple values are not supported");u[249]=Nr;u[250]=Or;u[251]=Dr;u[252]=y;u[253]=y;u[254]=y;u[255]=Br;var B=[];for(let e=0;e<24;e++)B[e]=new f(s.uint,e,1);for(let e=-1;e>=-24;e--)B[31-e]=new f(s.negint,e,1);B[64]=new f(s.bytes,new Uint8Array(0),1);B[96]=new f(s.string,"",1);B[128]=new f(s.array,0,1);B[160]=new f(s.map,0,1);B[244]=new f(s.false,!1,1);B[245]=new f(s.true,!0,1);B[246]=new f(s.null,null,1);function $e(e){switch(e.type){case s.false:return R([244]);case s.true:return R([245]);case s.null:return R([246]);case s.bytes:return e.value.length?void 0:R([64]);case s.string:return e.value===""?R([96]):void 0;case s.array:return e.value===0?R([128]):void 0;case s.map:return e.value===0?R([160]):void 0;case s.uint:return e.value<24?R([Number(e.value)]):void 0;case s.negint:if(e.value>=-24)return R([31-Number(e.value)])}}var oo={float64:!1,mapSorter:so,quickEncodeToken:$e};function lt(){let e=[];return e[s.uint.major]=T,e[s.negint.major]=Be,e[s.bytes.major]=re,e[s.string.major]=lr,e[s.array.major]=Oe,e[s.map.major]=De,e[s.tag.major]=Re,e[s.float.major]=Me,e}var Vr=lt(),dt=new he,Ve=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(`${st} object contains circular references`);return new e(r,t)}},H={null:new f(s.null,null),undefined:new f(s.undefined,void 0),true:new f(s.true,!0),false:new f(s.false,!1),emptyArray:new f(s.array,0),emptyMap:new f(s.map,0)},P={number(e,t,r,n){return!Number.isInteger(e)||!Number.isSafeInteger(e)?new f(s.float,e):e>=0?new f(s.uint,e):new f(s.negint,e)},bigint(e,t,r,n){return e>=BigInt(0)?new f(s.uint,e):new f(s.negint,e)},Uint8Array(e,t,r,n){return new f(s.bytes,e)},string(e,t,r,n){return new f(s.string,e)},boolean(e,t,r,n){return e?H.true:H.false},null(e,t,r,n){return H.null},undefined(e,t,r,n){return H.undefined},ArrayBuffer(e,t,r,n){return new f(s.bytes,new Uint8Array(e))},DataView(e,t,r,n){return new f(s.bytes,new Uint8Array(e.buffer,e.byteOffset,e.byteLength))},Array(e,t,r,n){if(!e.length)return r.addBreakTokens===!0?[H.emptyArray,new f(s.break)]:H.emptyArray;n=Ve.createCheck(n,e);let o=[],i=0;for(let a of e)o[i++]=ge(a,r,n);return r.addBreakTokens?[new f(s.array,e.length),o,new f(s.break)]:[new f(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;if(!a)return r.addBreakTokens===!0?[H.emptyMap,new f(s.break)]:H.emptyMap;n=Ve.createCheck(n,e);let c=[],d=0;for(let h of i)c[d++]=[ge(h,r,n),ge(o?e.get(h):e[h],r,n)];return io(c,r),r.addBreakTokens?[new f(s.map,a),c,new f(s.break)]:[new f(s.map,a),c]}};P.Map=P.Object;P.Buffer=P.Uint8Array;for(let e of"Uint8Clamped Uint16 Uint32 Int8 Int16 Int32 BigUint64 BigInt64 Float32 Float64".split(" "))P[`${e}Array`]=P.DataView;function ge(e,t={},r){let n=$t(e),o=t&&t.typeEncoders&&t.typeEncoders[n]||P[n];if(typeof o=="function"){let a=o(e,n,t,r);if(a!=null)return a}let i=P[n];if(!i)throw new Error(`${st} unsupported type: ${n}`);return i(e,n,t,r)}function io(e,t){t.mapSorter&&e.sort(t.mapSorter)}function so(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=Vr[o].compareTokens(r,n);return i===0&&console.warn("WARNING: complex key types used, CBOR key sorting guarantees are gone"),i}function Lr(e,t,r,n){if(Array.isArray(t))for(let o of t)Lr(e,o,r,n);else r[t.type.major](e,t,n)}function ao(e,t,r){let n=ge(e,r);if(!Array.isArray(n)&&r.quickEncodeToken){let o=r.quickEncodeToken(n);if(o)return o;let i=t[n.type.major];if(i.encodedSize){let a=i.encodedSize(n,r),c=new he(a);if(i(c,n,r),c.chunks.length!==1)throw new Error(`Unexpected error: pre-calculated length for ${n} was wrong`);return it(c.chunks[0])}}return dt.reset(),Lr(dt,n,t,r),dt.toBytes(!0)}function ht(e,t){return t=Object.assign({},oo,t),ao(e,Vr,t)}var co={strict:!1,allowIndefinite:!0,allowUndefined:!0,allowBigInt:!0},Le=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=B[t];if(r===void 0){let n=u[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}},we=Symbol.for("DONE"),Fe=Symbol.for("BREAK");function fo(e,t,r){let n=[];for(let o=0;o<e.value;o++){let i=ie(t,r);if(i===Fe){if(e.value===1/0)break;throw new Error(`${l} got unexpected break to lengthed array`)}if(i===we)throw new Error(`${l} found array but not enough entries (got ${o}, expected ${e.value})`);n[o]=i}return n}function uo(e,t,r){let n=r.useMaps===!0,o=n?void 0:{},i=n?new Map:void 0;for(let a=0;a<e.value;a++){let c=ie(t,r);if(c===Fe){if(e.value===1/0)break;throw new Error(`${l} got unexpected break to lengthed map`)}if(c===we)throw new Error(`${l} found map but not enough entries (got ${a} [no key], expected ${e.value})`);if(n!==!0&&typeof c!="string")throw new Error(`${l} non-string keys not supported (got ${typeof c})`);if(r.rejectDuplicateMapKeys===!0&&(n&&i.has(c)||!n&&c in o))throw new Error(`${l} found repeat map key "${c}"`);let d=ie(t,r);if(d===we)throw new Error(`${l} found map but not enough entries (got ${a} [no value], expected ${e.value})`);n?i.set(c,d):o[c]=d}return n?i:o}function ie(e,t){if(e.done())return we;let r=e.next();if(r.type===s.break)return Fe;if(r.type.terminal)return r.value;if(r.type===s.array)return fo(r,e,t);if(r.type===s.map)return uo(r,e,t);if(r.type===s.tag){if(t.tags&&typeof t.tags[r.value]=="function"){let n=ie(e,t);return t.tags[r.value](n)}throw new Error(`${l} tag not supported (${r.value})`)}throw new Error("unsupported")}function Fr(e,t){if(!(e instanceof Uint8Array))throw new Error(`${l} data to decode must be a Uint8Array`);t=Object.assign({},co,t);let r=t.tokenizer||new Le(e,t),n=ie(r,t);if(n===we)throw new Error(`${l} did not find any content to decode`);if(n===Fe)throw new Error(`${l} got unexpected break`);return[n,e.subarray(r.pos())]}function pt(e,t){let[r,n]=Fr(e,t);if(n.length>0)throw new Error(`${l} too many terminals, data makes no sense`);return r}var _s=new Uint8Array(0);function Hr(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 se(e){if(e instanceof Uint8Array&&e.constructor.name==="Uint8Array")return e;if(e instanceof ArrayBuffer)return new Uint8Array(e);if(ArrayBuffer.isView(e))return new Uint8Array(e.buffer,e.byteOffset,e.byteLength);throw new Error("Unknown type, must be binary type")}function ho(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),p=Math.log(256)/Math.log(c);function j(m){if(m instanceof Uint8Array||(ArrayBuffer.isView(m)?m=new Uint8Array(m.buffer,m.byteOffset,m.byteLength):Array.isArray(m)&&(m=Uint8Array.from(m))),!(m instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(m.length===0)return"";for(var b=0,X=0,C=0,N=m.length;C!==N&&m[C]===0;)C++,b++;for(var O=(N-C)*p+1>>>0,A=new Uint8Array(O);C!==N;){for(var D=m[C],F=0,I=O-1;(D!==0||F<X)&&I!==-1;I--,F++)D+=256*A[I]>>>0,A[I]=D%c>>>0,D=D/c>>>0;if(D!==0)throw new Error("Non-zero carry");X=F,C++}for(var $=O-X;$!==O&&A[$]===0;)$++;for(var Ue=d.repeat(b);$<O;++$)Ue+=e.charAt(A[$]);return Ue}function Te(m){if(typeof m!="string")throw new TypeError("Expected String");if(m.length===0)return new Uint8Array;var b=0;if(m[b]!==" "){for(var X=0,C=0;m[b]===d;)X++,b++;for(var N=(m.length-b)*h+1>>>0,O=new Uint8Array(N);m[b];){var A=r[m.charCodeAt(b)];if(A===255)return;for(var D=0,F=N-1;(A!==0||D<C)&&F!==-1;F--,D++)A+=c*O[F]>>>0,O[F]=A%256>>>0,A=A/256>>>0;if(A!==0)throw new Error("Non-zero carry");C=D,b++}if(m[b]!==" "){for(var I=N-C;I!==N&&O[I]===0;)I++;for(var $=new Uint8Array(X+(N-I)),Ue=X;I!==N;)$[Ue++]=O[I++];return $}}}function Sn(m){var b=Te(m);if(b)return b;throw new Error(`Non-${t} character`)}return{encode:j,decodeUnsafe:Te,decode:Sn}}var po=ho,yo=po,Pr=yo;var yt=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")}},mt=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,r,n){if(this.name=t,this.prefix=r,r.codePointAt(0)===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=r.codePointAt(0),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 qr(this,t)}},gt=class{decoders;constructor(t){this.decoders=t}or(t){return qr(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 qr(e,t){return new gt({...e.decoders??{[e.prefix]:e},...t.decoders??{[t.prefix]:t}})}var wt=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 yt(t,r,n),this.decoder=new mt(t,r,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function Gr({name:e,prefix:t,encode:r,decode:n}){return new wt(e,t,r,n)}function xt({name:e,prefix:t,alphabet:r}){let{encode:n,decode:o}=Pr(r,e);return Gr({prefix:t,name:e,encode:n,decode:i=>se(o(i))})}function mo(e,t,r,n){let o={};for(let p=0;p<t.length;++p)o[t[p]]=p;let i=e.length;for(;e[i-1]==="=";)--i;let a=new Uint8Array(i*r/8|0),c=0,d=0,h=0;for(let p=0;p<i;++p){let j=o[e[p]];if(j===void 0)throw new SyntaxError(`Non-${n} character`);d=d<<r|j,c+=r,c>=8&&(c-=8,a[h++]=255&d>>c)}if(c>=r||255&d<<8-c)throw new SyntaxError("Unexpected end of data");return a}function go(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;)i+="=";return i}function M({name:e,prefix:t,bitsPerChar:r,alphabet:n}){return Gr({prefix:t,name:e,encode(o){return go(o,n,r)},decode(o){return mo(o,n,r,e)}})}var xe=M({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Bs=M({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Ns=M({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Os=M({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Ds=M({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Rs=M({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Ms=M({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),zs=M({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),$s=M({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var L=xt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Fs=xt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var wo=Wr,Jr=128,xo=127,bo=~xo,vo=Math.pow(2,31);function Wr(e,t,r){t=t||[],r=r||0;for(var n=r;e>=vo;)t[r++]=e&255|Jr,e/=128;for(;e&bo;)t[r++]=e&255|Jr,e>>>=7;return t[r]=e|0,Wr.bytes=r-n+1,t}var Eo=bt,ko=128,Kr=127;function bt(e,n){var r=0,n=n||0,o=0,i=n,a,c=e.length;do{if(i>=c)throw bt.bytes=0,new RangeError("Could not decode varint");a=e[i++],r+=o<28?(a&Kr)<<o:(a&Kr)*Math.pow(2,o),o+=7}while(a>=ko);return bt.bytes=i-n,r}var _o=Math.pow(2,7),Ao=Math.pow(2,14),To=Math.pow(2,21),Uo=Math.pow(2,28),Co=Math.pow(2,35),Io=Math.pow(2,42),So=Math.pow(2,49),Bo=Math.pow(2,56),No=Math.pow(2,63),Oo=function(e){return e<_o?1:e<Ao?2:e<To?3:e<Uo?4:e<Co?5:e<Io?6:e<So?7:e<Bo?8:e<No?9:10},Do={encode:wo,decode:Eo,encodingLength:Oo},Ro=Do,be=Ro;function ve(e,t=0){return[be.decode(e,t),be.decode.bytes]}function ae(e,t,r=0){return be.encode(e,t,r),t}function ce(e){return be.encodingLength(e)}function Qr(e,t){let r=t.byteLength,n=ce(e),o=n+ce(r),i=new Uint8Array(o+r);return ae(e,i,0),ae(r,i,n),i.set(t,o),new fe(e,r,t,i)}function q(e){let t=se(e),[r,n]=ve(t),[o,i]=ve(t.subarray(n)),a=t.subarray(n+i);if(a.byteLength!==o)throw new Error("Incorrect length");return new fe(r,o,a,t)}function Yr(e,t){if(e===t)return!0;{let r=t;return e.code===r.code&&e.size===r.size&&r.bytes instanceof Uint8Array&&Hr(e.bytes,r.bytes)}}var fe=class{code;size;digest;bytes;constructor(t,r,n,o){this.code=t,this.size=r,this.digest=n,this.bytes=o}};function Zr(e,t){let{bytes:r,version:n}=e;switch(n){case 0:return zo(r,Et(e),t??L.encoder);default:return $o(r,Et(e),t??xe.encoder)}}var jr=new WeakMap;function Et(e){let t=jr.get(e);if(t==null){let r=new Map;return jr.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=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:t,multihash:r}=this;if(t!==Ee)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==Vo)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=Qr(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&&Yr(t.multihash,n.multihash)}toString(t){return Zr(this,t)}toJSON(){return{"/":Zr(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??en(n,o,i.bytes))}else if(r[Lo]===!0){let{version:n,multihash:o,code:i}=r,a=q(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!==Ee)throw new Error(`Version 0 CID must use dag-pb (code: ${Ee}) block encoding`);return new e(t,r,n,n.bytes)}case 1:{let o=en(t,r,n.bytes);return new e(t,r,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return e.create(0,Ee,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=se(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 fe(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[j,Te]=ve(t.subarray(r));return r+=Te,j},o=n(),i=Ee;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,p=h-a;return{version:o,codec:i,multihashCode:c,digestSize:d,multihashSize:p,size:h}}static parse(t,r){let[n,o]=Mo(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 Et(i).set(n,t),i}};function Mo(e,t){switch(e[0]){case"Q":{let r=t??L;return[L.prefix,r.decode(`${L.prefix}${e}`)]}case L.prefix:{let r=t??L;return[L.prefix,r.decode(e)]}case xe.prefix:{let r=t??xe;return[xe.prefix,r.decode(e)]}default:{if(t==null)throw Error("To parse non base32 or base58btc encoded CID multibase decoder must be provided");return[e[0],t.decode(e)]}}}function zo(e,t,r){let{prefix:n}=r;if(n!==L.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 $o(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 Ee=112,Vo=18;function en(e,t,r){let n=ce(e),o=n+ce(t),i=new Uint8Array(o+r.byteLength);return ae(e,i,0),ae(t,i,n),i.set(r,o),i}var Lo=Symbol.for("@ipld/js-cid/CID");var tn=42;function Fo(e){return e instanceof ArrayBuffer?new Uint8Array(e,0,e.byteLength):e}function Ho(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 f(s.tag,tn),new f(s.bytes,r)]}function Po(){throw new Error("`undefined` is not supported by the IPLD Data Model and cannot be encoded")}function qo(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}var kt={float64:!0,typeEncoders:{Object:Ho,undefined:Po,number:qo}},Zs={...kt,typeEncoders:{...kt.typeEncoders}};function Go(e){if(e[0]!==0)throw new Error("Invalid CID for CBOR tag 42; expected leading 0x00");return w.decode(e.subarray(1))}var He={allowIndefinite:!1,coerceUndefinedToNull:!0,allowNaN:!1,allowInfinity:!1,allowBigInt:!0,strict:!0,useMaps:!1,rejectDuplicateMapKeys:!0,tags:[]};He.tags[tn]=Go;var js={...He,tags:He.tags.slice()};var Pe=e=>ht(e,kt),qe=e=>pt(Fo(e),He);var G=Ie(Ge(),1),J={SHA2_256:18,LENGTH:32,DAG_PB:112},Je=40;function z(e,t){if(!e.length)throw new Error("Unexpected end of data");let r=G.default.decode(e);return t.seek(G.default.decode.bytes),r}function Ke(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 We(e){G.default.decode(e);let t=G.default.decode.bytes,r=G.default.decode(e.subarray(G.default.decode.bytes)),n=G.default.decode.bytes;return t+n+r}var K={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},ke={"CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)":K.Link,"CarV1HeaderOrV2Pragma > roots (anon)":e=>{if(K.List(e)!==void 0){for(let t=0;t<e.length;t++){let r=e[t];if(r=ke["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=ke["CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)"](i),i===void 0)return;n.push(i)}return n}}return e}},Int:K.Int,CarV1HeaderOrV2Pragma:e=>{if(K.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=ke["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=ke.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}},_e={"CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)":K.Link,"CarV1HeaderOrV2Pragma > roots (anon)":e=>{if(K.List(e)!==void 0){for(let t=0;t<e.length;t++){let r=e[t];if(r=_e["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=_e["CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)"](i),i===void 0)return;n.push(i)}return n}}return e}},Int:K.Int,CarV1HeaderOrV2Pragma:e=>{if(K.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=_e["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=_e.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}},Xe={toTyped:ke.CarV1HeaderOrV2Pragma,toRepresentation:_e.CarV1HeaderOrV2Pragma};function ln(e,t){let r=z(e.upTo(8),e);if(r===0)throw new Error("Invalid CAR header (zero length)");let n=e.exactly(r,!0),o=qe(n);if(Xe.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=Ke(e.exactly(Je,!0));e.seek(i.dataOffset-e.pos);let a=ln(e,1);return Object.assign(a,i)}function si(e){let t=e.exactly(2,!1);if(t[0]===J.SHA2_256&&t[1]===J.LENGTH){let a=e.exactly(34,!0),c=q(a);return w.create(0,J.DAG_PB,c)}let r=z(e.upTo(8),e);if(r!==1)throw new Error(`Unexpected CID version (${r})`);let n=z(e.upTo(8),e),o=e.exactly(We(e.upTo(8)),!0),i=q(o);return w.create(r,n,i)}function ai(e){let t=e.pos,r=z(e.upTo(8),e);if(r===0)throw new Error("Invalid CAR section (zero length)");r+=e.pos-t;let n=si(e),o=r-Number(e.pos-t);return{cid:n,length:r,blockLength:o}}function hn(e){let t=ci(e),r=ln(t);if(r.version===2){let o=t.pos-r.dataOffset;t=fi(t,r.dataSize-o)}let n=[];for(;t.upTo(8).length>0;){let{cid:o,blockLength:i}=ai(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 fi(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 Qe=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}=hn(t);return new e(r,n)}};var Nt={};Mt(Nt,{addBlock:()=>mn,addRoot:()=>yn,blockLength:()=>hi,calculateHeaderLength:()=>St,close:()=>gn,createWriter:()=>gi,estimateHeaderLength:()=>mi,headerLength:()=>Bt,resizeHeader:()=>It});var di=lt(),li={float64:!1,quickEncodeToken:$e};function Tt(e,t=di,r=li){if(Array.isArray(e)){let n=0;for(let o of e)n+=Tt(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 Ae=Ie(Ge(),1),Ct=class{constructor(t,r){this.bytes=t,this.byteOffset=r,this.roots=[],this.headerSize=r}addRoot(t,r){return yn(this,t,r),this}write(t){return mn(this,t),this}close(t){return gn(this,t)}},yn=(e,t,r={})=>{let{resize:n=!1}=r,{bytes:o,headerSize:i,byteOffset:a,roots:c}=e;e.roots.push(t);let d=Bt(e);if(d>i)if(d-i+a<o.byteLength)if(n)It(e,d);else throw c.pop(),new RangeError(`Header of size ${i} has no capacity for new root ${t}.
3
+ 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}`)},hi=({cid:e,bytes:t})=>{let r=e.bytes.byteLength+t.byteLength;return Ae.default.encodingLength(r)+r},mn=(e,{cid:t,bytes:r})=>{let n=t.bytes.byteLength+r.byteLength,o=Ae.default.encode(n);if(e.byteOffset+o.length+n>e.bytes.byteLength)throw new RangeError("Buffer has no capacity for this block");Ut(e,o),Ut(e,t.bytes),Ut(e,r)},gn=(e,t={})=>{let{resize:r=!1}=t,{roots:n,bytes:o,byteOffset:i,headerSize:a}=e,c=Pe({version:1,roots:n}),d=Ae.default.encode(c.length),h=d.length+c.byteLength;if(a-h===0)return pn(e,d,c),o.subarray(0,i);if(r)return It(e,h),pn(e,d,c),o.subarray(0,e.byteOffset);throw new RangeError(`Header size was overestimated.
4
+ You can use close({ resize: true }) to resize header`)},It=(e,t)=>{let{bytes:r,headerSize:n}=e;r.set(r.subarray(n,e.byteOffset),t),e.byteOffset+=t-n,e.headerSize=t},Ut=(e,t)=>{e.bytes.set(t,e.byteOffset),e.byteOffset+=t.length},pn=({bytes:e},t,r)=>{e.set(t),e.set(r,t.length)},pi=[new f(s.map,2),new f(s.string,"version"),new f(s.uint,1),new f(s.string,"roots")],yi=new f(s.tag,42),St=e=>{let t=[...pi];t.push(new f(s.array,e.length));for(let n of e)t.push(yi),t.push(new f(s.bytes,{length:n+1}));let r=Tt(t);return Ae.default.encodingLength(r)+r},Bt=({roots:e})=>St(e.map(t=>t.bytes.byteLength)),mi=(e,t=36)=>St(new Array(e).fill(t)),gi=(e,t={})=>{let{roots:r=[],byteOffset:n=0,byteLength:o=e.byteLength,headerSize:i=Bt({roots:r})}=t,a=new Uint8Array(e,n,o),c=new Ct(a,i);for(let d of r)c.addRoot(d);return c};var Ot=Ie(wn(),1);async function Ye(e,t){let r=z(await e.upTo(8),e);if(r===0)throw new Error("Invalid CAR header (zero length)");let n=await e.exactly(r,!0),o=qe(n);if(Xe.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=Ke(await e.exactly(Je,!0));e.seek(i.dataOffset-e.pos);let a=await Ye(e,1);return Object.assign(a,i)}async function wi(e){let t=await e.exactly(2,!1);if(t[0]===J.SHA2_256&&t[1]===J.LENGTH){let a=await e.exactly(34,!0),c=q(a);return w.create(0,J.DAG_PB,c)}let r=z(await e.upTo(8),e);if(r!==1)throw new Error(`Unexpected CID version (${r})`);let n=z(await e.upTo(8),e),o=await e.exactly(We(await e.upTo(8)),!0),i=q(o);return w.create(r,n,i)}async function xn(e){let t=e.pos,r=z(await e.upTo(8),e);if(r===0)throw new Error("Invalid CAR section (zero length)");r+=e.pos-t;let n=await wi(e),o=r-Number(e.pos-t);return{cid:n,length:r,blockLength:o}}async function xi(e){let{cid:t,blockLength:r}=await xn(e);return{bytes:await e.exactly(r,!0),cid:t}}async function bi(e){let t=e.pos,{cid:r,length:n,blockLength:o}=await xn(e),i={cid:r,length:n,blockLength:o,offset:t,blockOffset:e.pos};return e.seek(i.blockLength),i}function ue(e){let t=(async()=>{let r=await Ye(e);if(r.version===2){let n=e.pos-r.dataOffset;e=Ei(e,r.dataSize-n)}return r})();return{header:()=>t,async*blocks(){for(await t;(await e.upTo(8)).length>0;)yield await xi(e)},async*blocksIndex(){for(await t;(await e.upTo(8)).length>0;)yield await bi(e)}}}function W(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 vi(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,p)=>h+p.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 de(e){let t=e[Symbol.asyncIterator]();async function r(){let n=await t.next();return n.done?null:n.value}return vi(r)}function Ei(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 Y=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 fromBytes(t){if(!(t instanceof Uint8Array))throw new TypeError("fromBytes() requires a Uint8Array");return bn(W(t))}static async fromIterable(t){if(!t||typeof t[Symbol.asyncIterator]!="function")throw new TypeError("fromIterable() requires an async iterable");return bn(de(t))}};async function bn(e){let t=ue(e),{version:r,roots:n}=await t.header();return new Y(r,n,t.blocksIndex())}var Z=class{constructor(t,r){this._header=t,this._blocks=r,this._keys=r.map(n=>n.cid.toString())}get version(){return this._header.version}async getRoots(){return this._header.roots}async has(t){return this._keys.indexOf(t.toString())>-1}async get(t){let r=this._keys.indexOf(t.toString());return r>-1?this._blocks[r]:void 0}async*blocks(){for(let t of this._blocks)yield t}async*cids(){for(let t of this._blocks)yield t.cid}static async fromBytes(t){if(!(t instanceof Uint8Array))throw new TypeError("fromBytes() requires a Uint8Array");return vn(W(t))}static async fromIterable(t){if(!t||typeof t[Symbol.asyncIterator]!="function")throw new TypeError("fromIterable() requires an async iterable");return vn(de(t))}};async function vn(e){let t=ue(e),r=await t.header(),n=[];for await(let o of t.blocks())n.push(o);return new Z(r,n)}var Ze=class e{constructor(t,r,n,o,i){this._version=t,this._path=r,this._roots=n,this._index=o,this._order=i,this._fd=null}get version(){return this._version}async getRoots(){return this._roots}async has(t){return this._index.has(t.toString())}async get(t){let r=this._index.get(t.toString());if(!r)return;this._fd||(this._fd=await Ot.default.promises.open(this._path,"r"));let n={cid:t,length:0,offset:0,blockLength:r.blockLength,blockOffset:r.blockOffset};return Z.readRaw(this._fd,n)}async*blocks(){for(let t of this._order){let r=await this.get(w.parse(t));if(!r)throw new Error("Unexpected internal error");yield r}}async*cids(){for(let t of this._order)yield w.parse(t)}async close(){if(this._fd)return this._fd.close()}static async fromFile(t){if(typeof t!="string")throw new TypeError("fromFile() requires a file path string");let r=await Y.fromIterable((void 0).from(Ot.default.createReadStream(t))),n=new Map,o=[];for await(let{cid:i,blockLength:a,blockOffset:c}of r){let d=i.toString();n.set(d,{blockLength:a,blockOffset:c}),o.push(d)}return new e(r.version,t,await r.getRoots(),n,o)}};var je=class{constructor(t,r,n){this._version=t,this._roots=r,this._iterable=n,this._decoded=!1}get version(){return this._version}async getRoots(){return this._roots}},et=class e extends je{[Symbol.asyncIterator](){if(this._decoded)throw new Error("Cannot decode more than once");if(!this._iterable)throw new Error("Block iterable not found");return this._decoded=!0,this._iterable[Symbol.asyncIterator]()}static async fromBytes(t){let{version:r,roots:n,iterator:o}=await kn(t);return new e(r,n,o)}static async fromIterable(t){let{version:r,roots:n,iterator:o}=await _n(t);return new e(r,n,o)}},tt=class e extends je{[Symbol.asyncIterator](){if(this._decoded)throw new Error("Cannot decode more than once");if(!this._iterable)throw new Error("Block iterable not found");this._decoded=!0;let t=this._iterable[Symbol.asyncIterator]();return{async next(){let r=await t.next();return r.done?r:{done:!1,value:r.value.cid}}}}static async fromBytes(t){let{version:r,roots:n,iterator:o}=await kn(t);return new e(r,n,o)}static async fromIterable(t){let{version:r,roots:n,iterator:o}=await _n(t);return new e(r,n,o)}};async function kn(e){if(!(e instanceof Uint8Array))throw new TypeError("fromBytes() requires a Uint8Array");return An(W(e))}async function _n(e){if(!e||typeof e[Symbol.asyncIterator]!="function")throw new TypeError("fromIterable() requires an async iterable");return An(de(e))}async function An(e){let t=ue(e),{version:r,roots:n}=await t.header();return{version:r,roots:n,iterator:t.blocks()}}var Dt=Ie(Ge(),1),Tn=1;function Rt(e){let t=Pe({version:Tn,roots:e}),r=Dt.default.encode(t.length),n=new Uint8Array(r.length+t.length);return n.set(r,0),n.set(t,r.length),n}function Un(e){return{async setRoots(t){let r=Rt(t);await e.write(r)},async writeBlock(t){let{cid:r,bytes:n}=t;await e.write(new Uint8Array(Dt.default.encode(r.bytes.length+n.length))),await e.write(r.bytes),n.length&&await e.write(n)},async close(){await e.end()},version(){return Tn}}}function rt(){}function Cn(){let e=[],t=null,r=rt,n=!1,o=null,i=rt,a=()=>(t||(t=new Promise(h=>{r=()=>{t=null,r=rt,h()}})),t),c={write(h){e.push(h);let p=a();return i(),p},async end(){n=!0;let h=a();i(),await h}},d={async next(){let h=e.shift();return h?(e.length===0&&r(),{done:!1,value:h}):n?(r(),{done:!0,value:void 0}):(o||(o=new Promise(p=>{i=()=>(o=null,i=rt,p(d.next()))})),o)}};return{writer:c,iterator:d}}var nt=class e{constructor(t,r){this._encoder=r,this._mutex=r.setRoots(t),this._ended=!1}async put(t){if(!(t.bytes instanceof Uint8Array)||!t.cid)throw new TypeError("Can only write {cid, bytes} objects");if(this._ended)throw new Error("Already closed");let r=w.asCID(t.cid);if(!r)throw new TypeError("Can only write {cid, bytes} objects");return this._mutex=this._mutex.then(()=>this._encoder.writeBlock({cid:r,bytes:t.bytes})),this._mutex}async close(){if(this._ended)throw new Error("Already closed");return await this._mutex,this._ended=!0,this._encoder.close()}version(){return this._encoder.version()}static create(t){t=ki(t);let{encoder:r,iterator:n}=In(),o=new e(t,r),i=new ot(n);return{writer:o,out:i}}static createAppender(){let{encoder:t,iterator:r}=In();t.setRoots=()=>Promise.resolve();let n=new e([],t),o=new ot(r);return{writer:n,out:o}}static async updateRootsInBytes(t,r){let n=W(t);await Ye(n);let o=Rt(r);if(Number(n.pos)!==o.length)throw new Error(`updateRoots() can only overwrite a header of the same length (old header is ${n.pos} bytes, new header is ${o.length} bytes)`);return t.set(o,0),t}},ot=class{constructor(t){this._iterator=t}[Symbol.asyncIterator](){if(this._iterating)throw new Error("Multiple iterator not supported");return this._iterating=!0,this._iterator}};function In(){let e=Cn(),{writer:t,iterator:r}=e;return{encoder:Un(t),iterator:r}}function ki(e){if(e===void 0)return[];if(!Array.isArray(e)){let r=w.asCID(e);if(!r)throw new TypeError("roots must be a single CID or an array of CIDs");return[r]}let t=[];for(let r of e){let n=w.asCID(r);if(!n)throw new TypeError("roots must be a single CID or an array of CIDs");t.push(n)}return t}var _i="application/vnd.ipld.car";return Mn(Ai);})();
5
5
  return IpldCar}));
@@ -1 +1 @@
1
- {"version":3,"file":"buffer-decoder.d.ts","sourceRoot":"","sources":["../../src/buffer-decoder.js"],"names":[],"mappings":"AAMA;;;;;;;;GAQG;AAEH;;;;;;;;GAQG;AACH,mCAJW,iBAAiB,uCAEf,SAAS,GAAG,WAAW,CA8BnC;AA2BD;;;;;;;;;GASG;AACH,sCAHW,iBAAiB,GACf,WAAW,CAevB;AAED;;;;;GAKG;AACH,iCAHW,UAAU;YACG,SAAS,GAAG,WAAW;YAAW,KAAK,EAAE;EAoBhE;AAED;;;;;;GAMG;AACH,mCAHW,UAAU,GACR,iBAAiB,CA+B7B;AAED;;;;;;;;;GASG;AACH,oCAJW,iBAAiB,aACjB,MAAM,GACJ,iBAAiB,CAmC7B;oBA7MY,OAAO,OAAO,EAAE,KAAK;0BACrB,OAAO,OAAO,EAAE,WAAW;yBAC3B,OAAO,OAAO,EAAE,UAAU;gCAC1B,OAAO,UAAU,EAAE,iBAAiB;wBACpC,OAAO,UAAU,EAAE,SAAS;0BAC5B,OAAO,UAAU,EAAE,WAAW;+BAC9B,OAAO,UAAU,EAAE,gBAAgB"}
1
+ {"version":3,"file":"buffer-decoder.d.ts","sourceRoot":"","sources":["../../src/buffer-decoder.js"],"names":[],"mappings":"AAMA;;;;;;;;GAQG;AAEH;;;;;;;;GAQG;AACH,mCAJW,iBAAiB,uCAEf,SAAS,GAAG,WAAW,CA8BnC;AA2BD;;;;;;;;;GASG;AACH,sCAHW,iBAAiB,GACf,WAAW,CAevB;AAED;;;;;GAKG;AACH,iCAHW,UAAU,GACR;IAAE,MAAM,EAAG,SAAS,GAAG,WAAW,CAAE;IAAC,MAAM,EAAE,KAAK,EAAE,CAAA;CAAC,CAoBjE;AAED;;;;;;GAMG;AACH,mCAHW,UAAU,GACR,iBAAiB,CA+B7B;AAED;;;;;;;;;GASG;AACH,oCAJW,iBAAiB,aACjB,MAAM,GACJ,iBAAiB,CAmC7B;oBA7MY,OAAO,OAAO,EAAE,KAAK;0BACrB,OAAO,OAAO,EAAE,WAAW;yBAC3B,OAAO,OAAO,EAAE,UAAU;gCAC1B,OAAO,UAAU,EAAE,iBAAiB;wBACpC,OAAO,UAAU,EAAE,SAAS;0BAC5B,OAAO,UAAU,EAAE,WAAW;+BAC9B,OAAO,UAAU,EAAE,gBAAgB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ipld/car",
3
- "version": "5.3.0",
3
+ "version": "5.3.2",
4
4
  "description": "Content Addressable aRchive format reader and writer",
5
5
  "author": "Rod <rod@vagg.org> (http://r.va.gg/)",
6
6
  "license": "Apache-2.0 OR MIT",
@@ -208,7 +208,7 @@
208
208
  "@ipld/dag-pb": "^4.0.7",
209
209
  "@ipld/garbage": "^6.0.5",
210
210
  "@types/varint": "^6.0.3",
211
- "aegir": "^42.1.0",
211
+ "aegir": "^44.0.0",
212
212
  "jsdoc4readme": "^1.4.0"
213
213
  },
214
214
  "browser": {