@ipld/car 5.4.2 → 5.4.4

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