@ipld/car 5.0.1 → 5.0.3

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/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # @ipld/car
2
2
 
3
3
  [![codecov](https://img.shields.io/codecov/c/github/ipld/js-car.svg?style=flat-square)](https://codecov.io/gh/ipld/js-car)
4
- [![CI](https://img.shields.io/github/workflow/status/ipld/js-car/test%20&%20maybe%20release/master?style=flat-square)](https://github.com/ipld/js-car/actions/workflows/js-test-and-release.yml)
4
+ [![CI](https://img.shields.io/github/actions/workflow/status/ipld/js-car/js-test-and-release.yml?branch=master\&style=flat-square)](https://github.com/ipld/js-car/actions/workflows/js-test-and-release.yml?query=branch%3Amaster)
5
5
 
6
6
  > Content Addressable aRchive format reader and writer
7
7
 
@@ -338,7 +338,7 @@ the `CID`s contained within the CAR referenced by this reader.
338
338
 
339
339
  * `bytes` `(Uint8Array)`
340
340
 
341
- * Returns: `Promise<CarReader>`: blip blop
341
+ * Returns: `Promise<CarReader>`
342
342
 
343
343
  Instantiate a [`CarReader`](#CarReader) from a `Uint8Array` blob. This performs a
344
344
  decode fully in memory and maintains the decoded state in memory for full
package/dist/index.min.js CHANGED
@@ -1,5 +1,5 @@
1
1
  (function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.IpldCar = factory()}(typeof self !== 'undefined' ? self : this, function () {
2
- "use strict";var IpldCar=(()=>{var vn=Object.create;var Ie=Object.defineProperty;var En=Object.getOwnPropertyDescriptor;var kn=Object.getOwnPropertyNames;var An=Object.getPrototypeOf,_n=Object.prototype.hasOwnProperty;var pe=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),Ut=(e,t)=>{for(var r in t)Ie(e,r,{get:t[r],enumerable:!0})},Tt=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of kn(t))!_n.call(e,o)&&o!==r&&Ie(e,o,{get:()=>t[o],enumerable:!(n=En(t,o))||n.enumerable});return e};var Ne=(e,t,r)=>(r=e!=null?vn(An(e)):{},Tt(t||!e||!e.__esModule?Ie(r,"default",{value:e,enumerable:!0}):r,e)),Un=e=>Tt(Ie({},"__esModule",{value:!0}),e);var It=pe((pi,Bt)=>{Bt.exports=Ke;var St=128,Tn=127,Sn=~Tn,Bn=Math.pow(2,31);function Ke(e,t,r){if(Number.MAX_SAFE_INTEGER&&e>Number.MAX_SAFE_INTEGER)throw Ke.bytes=0,new RangeError("Could not encode varint");t=t||[],r=r||0;for(var n=r;e>=Bn;)t[r++]=e&255|St,e/=128;for(;e&Sn;)t[r++]=e&255|St,e>>>=7;return t[r]=e|0,Ke.bytes=r-n+1,t}});var Mt=pe((yi,Ct)=>{Ct.exports=We;var In=128,Nt=127;function We(e,n){var r=0,n=n||0,o=0,i=n,a,d=e.length;do{if(i>=d||o>49)throw We.bytes=0,new RangeError("Could not decode varint");a=e[i++],r+=o<28?(a&Nt)<<o:(a&Nt)*Math.pow(2,o),o+=7}while(a>=In);return We.bytes=i-n,r}});var Rt=pe((mi,zt)=>{var Nn=Math.pow(2,7),Cn=Math.pow(2,14),Mn=Math.pow(2,21),zn=Math.pow(2,28),Rn=Math.pow(2,35),$n=Math.pow(2,42),On=Math.pow(2,49),Ln=Math.pow(2,56),Dn=Math.pow(2,63);zt.exports=function(e){return e<Nn?1:e<Cn?2:e<Mn?3:e<zn?4:e<Rn?5:e<$n?6:e<On?7:e<Ln?8:e<Dn?9:10}});var Ce=pe((wi,$t)=>{$t.exports={encode:It(),decode:Mt(),encodingLength:Rt()}});var pn=pe(()=>{});var li={};Ut(li,{CarBlockIterator:()=>W,CarBufferWriter:()=>_t,CarCIDIterator:()=>Q,CarIndexedReader:()=>he,CarIndexer:()=>K,CarReader:()=>J,CarWriter:()=>Y});var q=Ne(Ce(),1);var Fn=Dt,Ot=128,Vn=127,Hn=~Vn,Pn=Math.pow(2,31);function Dt(e,t,r){t=t||[],r=r||0;for(var n=r;e>=Pn;)t[r++]=e&255|Ot,e/=128;for(;e&Hn;)t[r++]=e&255|Ot,e>>>=7;return t[r]=e|0,Dt.bytes=r-n+1,t}var qn=Qe,Gn=128,Lt=127;function Qe(e,n){var r=0,n=n||0,o=0,i=n,a,d=e.length;do{if(i>=d)throw Qe.bytes=0,new RangeError("Could not decode varint");a=e[i++],r+=o<28?(a&Lt)<<o:(a&Lt)*Math.pow(2,o),o+=7}while(a>=Gn);return Qe.bytes=i-n,r}var jn=Math.pow(2,7),Xn=Math.pow(2,14),Jn=Math.pow(2,21),Kn=Math.pow(2,28),Wn=Math.pow(2,35),Qn=Math.pow(2,42),Yn=Math.pow(2,49),Zn=Math.pow(2,56),eo=Math.pow(2,63),to=function(e){return e<jn?1:e<Xn?2:e<Jn?3:e<Kn?4:e<Wn?5:e<Qn?6:e<Yn?7:e<Zn?8:e<eo?9:10},ro={encode:Fn,decode:qn,encodingLength:to},no=ro,ye=no;var me=(e,t=0)=>[ye.decode(e,t),ye.decode.bytes],ee=(e,t,r=0)=>(ye.encode(e,t,r),t),te=e=>ye.encodingLength(e);var xi=new Uint8Array(0);var Vt=(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},re=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")};var Ht=(e,t)=>{let r=t.byteLength,n=te(e),o=n+te(r),i=new Uint8Array(o+r);return ee(e,i,0),ee(r,i,n),i.set(t,o),new ne(e,r,t,i)},we=e=>{let t=re(e),[r,n]=me(t),[o,i]=me(t.subarray(n)),a=t.subarray(n+i);if(a.byteLength!==o)throw new Error("Incorrect length");return new ne(r,o,a,t)},Pt=(e,t)=>{if(e===t)return!0;{let r=t;return e.code===r.code&&e.size===r.size&&r.bytes instanceof Uint8Array&&Vt(e.bytes,r.bytes)}},ne=class{constructor(t,r,n,o){this.code=t,this.size=r,this.digest=n,this.bytes=o}};function oo(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 d=e.length,f=e.charAt(0),h=Math.log(d)/Math.log(256),p=Math.log(256)/Math.log(d);function Z(w){if(w instanceof Uint8Array||(ArrayBuffer.isView(w)?w=new Uint8Array(w.buffer,w.byteOffset,w.byteLength):Array.isArray(w)&&(w=Uint8Array.from(w))),!(w instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(w.length===0)return"";for(var x=0,j=0,S=0,C=w.length;S!==C&&w[S]===0;)S++,x++;for(var M=(C-S)*p+1>>>0,_=new Uint8Array(M);S!==C;){for(var z=w[S],F=0,B=M-1;(z!==0||F<j)&&B!==-1;B--,F++)z+=256*_[B]>>>0,_[B]=z%d>>>0,z=z/d>>>0;if(z!==0)throw new Error("Non-zero carry");j=F,S++}for(var O=M-j;O!==M&&_[O]===0;)O++;for(var Be=f.repeat(x);O<M;++O)Be+=e.charAt(_[O]);return Be}function Se(w){if(typeof w!="string")throw new TypeError("Expected String");if(w.length===0)return new Uint8Array;var x=0;if(w[x]!==" "){for(var j=0,S=0;w[x]===f;)j++,x++;for(var C=(w.length-x)*h+1>>>0,M=new Uint8Array(C);w[x];){var _=r[w.charCodeAt(x)];if(_===255)return;for(var z=0,F=C-1;(_!==0||z<S)&&F!==-1;F--,z++)_+=d*M[F]>>>0,M[F]=_%256>>>0,_=_/256>>>0;if(_!==0)throw new Error("Non-zero carry");S=z,x++}if(w[x]!==" "){for(var B=C-S;B!==C&&M[B]===0;)B++;for(var O=new Uint8Array(j+(C-B)),Be=j;B!==C;)O[Be++]=M[B++];return O}}}function xn(w){var x=Se(w);if(x)return x;throw new Error(`Non-${t} character`)}return{encode:Z,decodeUnsafe:Se,decode:xn}}var io=oo,so=io,Gt=so;var Ye=class{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")}},Ze=class{constructor(t,r,n){if(this.name=t,this.prefix=r,r.codePointAt(0)===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=r.codePointAt(0),this.baseDecode=n}decode(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return jt(this,t)}},et=class{constructor(t){this.decoders=t}or(t){return jt(this,t)}decode(t){let r=t[0],n=this.decoders[r];if(n)return n.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}},jt=(e,t)=>new et({...e.decoders||{[e.prefix]:e},...t.decoders||{[t.prefix]:t}}),tt=class{constructor(t,r,n,o){this.name=t,this.prefix=r,this.baseEncode=n,this.baseDecode=o,this.encoder=new Ye(t,r,n),this.decoder=new Ze(t,r,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}},Xt=({name:e,prefix:t,encode:r,decode:n})=>new tt(e,t,r,n),rt=({prefix:e,name:t,alphabet:r})=>{let{encode:n,decode:o}=Gt(r,t);return Xt({prefix:e,name:t,encode:n,decode:i=>re(o(i))})},ao=(e,t,r,n)=>{let o={};for(let p=0;p<t.length;++p)o[t[p]]=p;let i=e.length;for(;e[i-1]==="=";)--i;let a=new Uint8Array(i*r/8|0),d=0,f=0,h=0;for(let p=0;p<i;++p){let Z=o[e[p]];if(Z===void 0)throw new SyntaxError(`Non-${n} character`);f=f<<r|Z,d+=r,d>=8&&(d-=8,a[h++]=255&f>>d)}if(d>=r||255&f<<8-d)throw new SyntaxError("Unexpected end of data");return a},co=(e,t,r)=>{let n=t[t.length-1]==="=",o=(1<<r)-1,i="",a=0,d=0;for(let f=0;f<e.length;++f)for(d=d<<8|e[f],a+=8;a>r;)a-=r,i+=t[o&d>>a];if(a&&(i+=t[o&d<<r-a]),n)for(;i.length*r&7;)i+="=";return i},R=({name:e,prefix:t,bitsPerChar:r,alphabet:n})=>Xt({prefix:t,name:e,encode(o){return co(o,n,r)},decode(o){return ao(o,n,r,e)}});var L=rt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Si=rt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var ge=R({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Ni=R({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Ci=R({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Mi=R({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),zi=R({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Ri=R({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),$i=R({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Oi=R({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Li=R({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var uo=(e,t)=>{let{bytes:r,version:n}=e;switch(n){case 0:return lo(r,nt(e),t||L.encoder);default:return ho(r,nt(e),t||ge.encoder)}},Jt=new WeakMap,nt=e=>{let t=Jt.get(e);if(t==null){let r=new Map;return Jt.set(e,r),r}return t},m=class{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!==be)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==po)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return m.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=Ht(t,r);return m.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 m.equals(this,t)}static equals(t,r){let n=r;return n&&t.code===n.code&&t.version===n.version&&Pt(t.multihash,n.multihash)}toString(t){return uo(this,t)}toJSON(){return{code:this.code,version:this.version,hash:this.multihash.bytes}}link(){return this}get[Symbol.toStringTag](){return"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 m)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:o,multihash:i,bytes:a}=r;return new m(n,o,i,a||Kt(n,o,i.bytes))}else if(r[yo]===!0){let{version:n,multihash:o,code:i}=r,a=we(o);return m.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!==be)throw new Error(`Version 0 CID must use dag-pb (code: ${be}) block encoding`);return new m(t,r,n,n.bytes)}case 1:{let o=Kt(t,r,n.bytes);return new m(t,r,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return m.create(0,be,t)}static createV1(t,r){return m.create(1,t,r)}static decode(t){let[r,n]=m.decodeFirst(t);if(n.length)throw new Error("Incorrect length");return r}static decodeFirst(t){let r=m.inspectBytes(t),n=r.size-r.multihashSize,o=re(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 ne(r.multihashCode,r.digestSize,i,o);return[r.version===0?m.createV0(a):m.createV1(r.codec,a),t.subarray(r.size)]}static inspectBytes(t){let r=0,n=()=>{let[Z,Se]=me(t.subarray(r));return r+=Se,Z},o=n(),i=be;if(o===18?(o=0,r=0):i=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let a=r,d=n(),f=n(),h=r+f,p=h-a;return{version:o,codec:i,multihashCode:d,digestSize:f,multihashSize:p,size:h}}static parse(t,r){let[n,o]=fo(t,r),i=m.decode(o);return nt(i).set(n,t),i}},fo=(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 ge.prefix:{let r=t||ge;return[ge.prefix,r.decode(e)]}default:{if(t==null)throw Error("To parse non base32 or base58btc encoded CID multibase decoder must be provided");return[e[0],t.decode(e)]}}},lo=(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},ho=(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},be=112,po=18,Kt=(e,t,r)=>{let n=te(e),o=n+te(t),i=new Uint8Array(o+r.byteLength);return ee(e,i,0),ee(t,i,n),i.set(r,o),i},yo=Symbol.for("@ipld/js-cid/CID");var mo=["string","number","bigint","symbol"],wo=["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 Wt(e){if(e===null)return"null";if(e===void 0)return"undefined";if(e===!0||e===!1)return"boolean";let t=typeof e;if(mo.includes(t))return t;if(t==="function")return"Function";if(Array.isArray(e))return"Array";if(go(e))return"Buffer";let r=bo(e);return r||"Object"}function go(e){return e&&e.constructor&&e.constructor.isBuffer&&e.constructor.isBuffer.call(null,e)}function bo(e){let t=Object.prototype.toString.call(e).slice(8,-1);if(wo.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 c=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 oe=globalThis.process&&!globalThis.process.browser&&globalThis.Buffer&&typeof globalThis.Buffer.isBuffer=="function",xo=new TextDecoder,vo=new TextEncoder;function Me(e){return oe&&globalThis.Buffer.isBuffer(e)}function ot(e){return e instanceof Uint8Array?Me(e)?new Uint8Array(e.buffer,e.byteOffset,e.byteLength):e:Uint8Array.from(e)}var er=oe?(e,t,r)=>r-t>64?globalThis.Buffer.from(e.subarray(t,r)).toString("utf8"):Yt(e,t,r):(e,t,r)=>r-t>64?xo.decode(e.subarray(t,r)):Yt(e,t,r),tr=oe?e=>e.length>64?globalThis.Buffer.from(e):Qt(e):e=>e.length>64?vo.encode(e):Qt(e),$=e=>Uint8Array.from(e),ie=oe?(e,t,r)=>Me(e)?new Uint8Array(e.subarray(t,r)):e.slice(t,r):(e,t,r)=>e.slice(t,r),rr=oe?(e,t)=>(e=e.map(r=>r instanceof Uint8Array?r:globalThis.Buffer.from(r)),ot(globalThis.Buffer.concat(e,t))):(e,t)=>{let r=new Uint8Array(t),n=0;for(let o of e)n+o.length>r.length&&(o=o.subarray(0,r.length-n)),r.set(o,n),n+=o.length;return r},nr=oe?e=>globalThis.Buffer.allocUnsafe(e):e=>new Uint8Array(e);function or(e,t){if(Me(e)&&Me(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 Qt(e,t=1/0){let r,n=e.length,o=null,i=[];for(let a=0;a<n;++a){if(r=e.charCodeAt(a),r>55295&&r<57344){if(!o){if(r>56319){(t-=3)>-1&&i.push(239,191,189);continue}else if(a+1===n){(t-=3)>-1&&i.push(239,191,189);continue}o=r;continue}if(r<56320){(t-=3)>-1&&i.push(239,191,189),o=r;continue}r=(o-55296<<10|r-56320)+65536}else o&&(t-=3)>-1&&i.push(239,191,189);if(o=null,r<128){if((t-=1)<0)break;i.push(r)}else if(r<2048){if((t-=2)<0)break;i.push(r>>6|192,r&63|128)}else if(r<65536){if((t-=3)<0)break;i.push(r>>12|224,r>>6&63|128,r&63|128)}else if(r<1114112){if((t-=4)<0)break;i.push(r>>18|240,r>>12&63|128,r>>6&63|128,r&63|128)}else throw new Error("Invalid code point")}return i}function Yt(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 d,f,h,p;switch(a){case 1:o<128&&(i=o);break;case 2:d=e[t+1],(d&192)===128&&(p=(o&31)<<6|d&63,p>127&&(i=p));break;case 3:d=e[t+1],f=e[t+2],(d&192)===128&&(f&192)===128&&(p=(o&15)<<12|(d&63)<<6|f&63,p>2047&&(p<55296||p>57343)&&(i=p));break;case 4:d=e[t+1],f=e[t+2],h=e[t+3],(d&192)===128&&(f&192)===128&&(h&192)===128&&(p=(o&15)<<18|(d&63)<<12|(f&63)<<6|h&63,p>65535&&p<1114112&&(i=p))}}i===null?(i=65533,a=1):i>65535&&(i-=65536,n.push(i>>>10&1023|55296),i=56320|i&1023),n.push(i),t+=a}return Eo(n)}var Zt=4096;function Eo(e){let t=e.length;if(t<=Zt)return String.fromCharCode.apply(String,e);let r="",n=0;for(;n<t;)r+=String.fromCharCode.apply(String,e.slice(n,n+=Zt));return r}var ko=256,xe=class{constructor(t=ko){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=nr(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=ie(n,0,this.cursor)}else r=rr(this.chunks,this.cursor);return t&&this.reset(),r}};var l="CBOR decode error:",it="CBOR encode error:",ve=[];ve[23]=1;ve[24]=2;ve[25]=3;ve[26]=5;ve[27]=9;function D(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){D(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){D(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){D(e,t,4);let n=e[t]*16777216+(e[t+1]<<16)+(e[t+2]<<8)+e[t+3];if(r.strict===!0&&n<g[2])throw new Error(`${l} integer encoded in more bytes than necessary (strict decode)`);return n}function A(e,t,r){D(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 ir(e,t,r,n){return new c(s.uint,v(e,t+1,n),2)}function sr(e,t,r,n){return new c(s.uint,E(e,t+1,n),3)}function ar(e,t,r,n){return new c(s.uint,k(e,t+1,n),5)}function cr(e,t,r,n){return new c(s.uint,A(e,t+1,n),9)}function U(e,t){return b(e,0,t.value)}function b(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`)}}U.encodedSize=function(t){return b.encodedSize(t.value)};b.encodedSize=function(t){return t<g[0]?1:t<g[1]?2:t<g[2]?3:t<g[3]?5:9};U.compareTokens=function(t,r){return t.value<r.value?-1:t.value>r.value?1:0};function ur(e,t,r,n){return new c(s.negint,-1-v(e,t+1,n),2)}function dr(e,t,r,n){return new c(s.negint,-1-E(e,t+1,n),3)}function fr(e,t,r,n){return new c(s.negint,-1-k(e,t+1,n),5)}var st=BigInt(-1),lr=BigInt(1);function hr(e,t,r,n){let o=A(e,t+1,n);if(typeof o!="bigint"){let i=-1-o;if(i>=Number.MIN_SAFE_INTEGER)return new c(s.negint,i,9)}if(n.allowBigInt!==!0)throw new Error(`${l} integers outside of the safe integer range are not supported`);return new c(s.negint,st-BigInt(o),9)}function ze(e,t){let r=t.value,n=typeof r=="bigint"?r*st-lr:r*-1-1;b(e,t.type.majorEncoded,n)}ze.encodedSize=function(t){let r=t.value,n=typeof r=="bigint"?r*st-lr:r*-1-1;return n<g[0]?1:n<g[1]?2:n<g[2]?3:n<g[3]?5:9};ze.compareTokens=function(t,r){return t.value<r.value?1:t.value>r.value?-1:0};function Ee(e,t,r,n){D(e,t,r+n);let o=ie(e,t+r,t+r+n);return new c(s.bytes,o,r+n)}function pr(e,t,r,n){return Ee(e,t,1,r)}function yr(e,t,r,n){return Ee(e,t,2,v(e,t+1,n))}function mr(e,t,r,n){return Ee(e,t,3,E(e,t+1,n))}function wr(e,t,r,n){return Ee(e,t,5,k(e,t+1,n))}function gr(e,t,r,n){let o=A(e,t+1,n);if(typeof o=="bigint")throw new Error(`${l} 64-bit integer bytes lengths not supported`);return Ee(e,t,9,o)}function Re(e){return e.encodedBytes===void 0&&(e.encodedBytes=e.type===s.string?tr(e.value):e.value),e.encodedBytes}function se(e,t){let r=Re(t);b(e,t.type.majorEncoded,r.length),e.push(r)}se.encodedSize=function(t){let r=Re(t);return b.encodedSize(r.length)+r.length};se.compareTokens=function(t,r){return _o(Re(t),Re(r))};function _o(e,t){return e.length<t.length?-1:e.length>t.length?1:or(e,t)}function ke(e,t,r,n,o){let i=r+n;D(e,t,i);let a=new c(s.string,er(e,t+r,t+i),i);return o.retainStringBytes===!0&&(a.byteValue=ie(e,t+r,t+i)),a}function br(e,t,r,n){return ke(e,t,1,r,n)}function xr(e,t,r,n){return ke(e,t,2,v(e,t+1,n),n)}function vr(e,t,r,n){return ke(e,t,3,E(e,t+1,n),n)}function Er(e,t,r,n){return ke(e,t,5,k(e,t+1,n),n)}function kr(e,t,r,n){let o=A(e,t+1,n);if(typeof o=="bigint")throw new Error(`${l} 64-bit integer string lengths not supported`);return ke(e,t,9,o,n)}var Ar=se;function ae(e,t,r,n){return new c(s.array,n,r)}function _r(e,t,r,n){return ae(e,t,1,r)}function Ur(e,t,r,n){return ae(e,t,2,v(e,t+1,n))}function Tr(e,t,r,n){return ae(e,t,3,E(e,t+1,n))}function Sr(e,t,r,n){return ae(e,t,5,k(e,t+1,n))}function Br(e,t,r,n){let o=A(e,t+1,n);if(typeof o=="bigint")throw new Error(`${l} 64-bit integer array lengths not supported`);return ae(e,t,9,o)}function Ir(e,t,r,n){if(n.allowIndefinite===!1)throw new Error(`${l} indefinite length items not allowed`);return ae(e,t,1,1/0)}function $e(e,t){b(e,s.array.majorEncoded,t.value)}$e.compareTokens=U.compareTokens;$e.encodedSize=function(t){return b.encodedSize(t.value)};function ce(e,t,r,n){return new c(s.map,n,r)}function Nr(e,t,r,n){return ce(e,t,1,r)}function Cr(e,t,r,n){return ce(e,t,2,v(e,t+1,n))}function Mr(e,t,r,n){return ce(e,t,3,E(e,t+1,n))}function zr(e,t,r,n){return ce(e,t,5,k(e,t+1,n))}function Rr(e,t,r,n){let o=A(e,t+1,n);if(typeof o=="bigint")throw new Error(`${l} 64-bit integer map lengths not supported`);return ce(e,t,9,o)}function $r(e,t,r,n){if(n.allowIndefinite===!1)throw new Error(`${l} indefinite length items not allowed`);return ce(e,t,1,1/0)}function Oe(e,t){b(e,s.map.majorEncoded,t.value)}Oe.compareTokens=U.compareTokens;Oe.encodedSize=function(t){return b.encodedSize(t.value)};function Or(e,t,r,n){return new c(s.tag,r,1)}function Lr(e,t,r,n){return new c(s.tag,v(e,t+1,n),2)}function Dr(e,t,r,n){return new c(s.tag,E(e,t+1,n),3)}function Fr(e,t,r,n){return new c(s.tag,k(e,t+1,n),5)}function Vr(e,t,r,n){return new c(s.tag,A(e,t+1,n),9)}function Le(e,t){b(e,s.tag.majorEncoded,t.value)}Le.compareTokens=U.compareTokens;Le.encodedSize=function(t){return b.encodedSize(t.value)};var No=20,Co=21,Mo=22,zo=23;function Hr(e,t,r,n){if(n.allowUndefined===!1)throw new Error(`${l} undefined values are not supported`);return n.coerceUndefinedToNull===!0?new c(s.null,null,1):new c(s.undefined,void 0,1)}function Pr(e,t,r,n){if(n.allowIndefinite===!1)throw new Error(`${l} indefinite length items not allowed`);return new c(s.break,void 0,1)}function at(e,t,r){if(r){if(r.allowNaN===!1&&Number.isNaN(e))throw new Error(`${l} NaN values are not supported`);if(r.allowInfinity===!1&&(e===1/0||e===-1/0))throw new Error(`${l} Infinity values are not supported`)}return new c(s.float,e,t)}function qr(e,t,r,n){return at(ct(e,t+1),3,n)}function Gr(e,t,r,n){return at(ut(e,t+1),5,n)}function jr(e,t,r,n){return at(Wr(e,t+1),9,n)}function De(e,t,r){let n=t.value;if(n===!1)e.push([s.float.majorEncoded|No]);else if(n===!0)e.push([s.float.majorEncoded|Co]);else if(n===null)e.push([s.float.majorEncoded|Mo]);else if(n===void 0)e.push([s.float.majorEncoded|zo]);else{let o,i=!1;(!r||r.float64!==!0)&&(Jr(n),o=ct(I,1),n===o||Number.isNaN(n)?(I[0]=249,e.push(I.slice(0,3)),i=!0):(Kr(n),o=ut(I,1),n===o&&(I[0]=250,e.push(I.slice(0,5)),i=!0))),i||(Ro(n),o=Wr(I,1),I[0]=251,e.push(I.slice(0,9)))}}De.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){Jr(n);let o=ct(I,1);if(n===o||Number.isNaN(n))return 3;if(Kr(n),o=ut(I,1),n===o)return 5}return 9};var Xr=new ArrayBuffer(9),T=new DataView(Xr,1),I=new Uint8Array(Xr,0);function Jr(e){if(e===1/0)T.setUint16(0,31744,!1);else if(e===-1/0)T.setUint16(0,64512,!1);else if(Number.isNaN(e))T.setUint16(0,32256,!1);else{T.setFloat32(0,e);let t=T.getUint32(0),r=(t&2139095040)>>23,n=t&8388607;if(r===255)T.setUint16(0,31744,!1);else if(r===0)T.setUint16(0,(e&2147483648)>>16|n>>13,!1);else{let o=r-127;o<-24?T.setUint16(0,0):o<-14?T.setUint16(0,(t&2147483648)>>16|1<<24+o,!1):T.setUint16(0,(t&2147483648)>>16|o+15<<10|n>>13,!1)}}}function ct(e,t){if(e.length-t<2)throw new Error(`${l} not enough data for float16`);let r=(e[t]<<8)+e[t+1];if(r===31744)return 1/0;if(r===64512)return-1/0;if(r===32256)return NaN;let n=r>>10&31,o=r&1023,i;return n===0?i=o*2**-24:n!==31?i=(o+1024)*2**(n-25):i=o===0?1/0:NaN,r&32768?-i:i}function Kr(e){T.setFloat32(0,e,!1)}function ut(e,t){if(e.length-t<4)throw new Error(`${l} not enough data for float32`);let r=(e.byteOffset||0)+t;return new DataView(e.buffer,r,4).getFloat32(0,!1)}function Ro(e){T.setFloat64(0,e,!1)}function Wr(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)}De.compareTokens=U.compareTokens;function y(e,t,r){throw new Error(`${l} encountered invalid minor (${r}) for major ${e[t]>>>5}`)}function Fe(e){return()=>{throw new Error(`${l} ${e}`)}}var u=[];for(let e=0;e<=23;e++)u[e]=y;u[24]=ir;u[25]=sr;u[26]=ar;u[27]=cr;u[28]=y;u[29]=y;u[30]=y;u[31]=y;for(let e=32;e<=55;e++)u[e]=y;u[56]=ur;u[57]=dr;u[58]=fr;u[59]=hr;u[60]=y;u[61]=y;u[62]=y;u[63]=y;for(let e=64;e<=87;e++)u[e]=pr;u[88]=yr;u[89]=mr;u[90]=wr;u[91]=gr;u[92]=y;u[93]=y;u[94]=y;u[95]=Fe("indefinite length bytes/strings are not supported");for(let e=96;e<=119;e++)u[e]=br;u[120]=xr;u[121]=vr;u[122]=Er;u[123]=kr;u[124]=y;u[125]=y;u[126]=y;u[127]=Fe("indefinite length bytes/strings are not supported");for(let e=128;e<=151;e++)u[e]=_r;u[152]=Ur;u[153]=Tr;u[154]=Sr;u[155]=Br;u[156]=y;u[157]=y;u[158]=y;u[159]=Ir;for(let e=160;e<=183;e++)u[e]=Nr;u[184]=Cr;u[185]=Mr;u[186]=zr;u[187]=Rr;u[188]=y;u[189]=y;u[190]=y;u[191]=$r;for(let e=192;e<=215;e++)u[e]=Or;u[216]=Lr;u[217]=Dr;u[218]=Fr;u[219]=Vr;u[220]=y;u[221]=y;u[222]=y;u[223]=y;for(let e=224;e<=243;e++)u[e]=Fe("simple values are not supported");u[244]=y;u[245]=y;u[246]=y;u[247]=Hr;u[248]=Fe("simple values are not supported");u[249]=qr;u[250]=Gr;u[251]=jr;u[252]=y;u[253]=y;u[254]=y;u[255]=Pr;var N=[];for(let e=0;e<24;e++)N[e]=new c(s.uint,e,1);for(let e=-1;e>=-24;e--)N[31-e]=new c(s.negint,e,1);N[64]=new c(s.bytes,new Uint8Array(0),1);N[96]=new c(s.string,"",1);N[128]=new c(s.array,0,1);N[160]=new c(s.map,0,1);N[244]=new c(s.false,!1,1);N[245]=new c(s.true,!0,1);N[246]=new c(s.null,null,1);function Ve(e){switch(e.type){case s.false:return $([244]);case s.true:return $([245]);case s.null:return $([246]);case s.bytes:return e.value.length?void 0:$([64]);case s.string:return e.value===""?$([96]):void 0;case s.array:return e.value===0?$([128]):void 0;case s.map:return e.value===0?$([160]):void 0;case s.uint:return e.value<24?$([Number(e.value)]):void 0;case s.negint:if(e.value>=-24)return $([31-Number(e.value)])}}var Oo={float64:!1,mapSorter:Do,quickEncodeToken:Ve};function ft(){let e=[];return e[s.uint.major]=U,e[s.negint.major]=ze,e[s.bytes.major]=se,e[s.string.major]=Ar,e[s.array.major]=$e,e[s.map.major]=Oe,e[s.tag.major]=Le,e[s.float.major]=De,e}var Qr=ft(),dt=new xe,ue=class{constructor(t,r){this.obj=t,this.parent=r}includes(t){let r=this;do if(r.obj===t)return!0;while(r=r.parent);return!1}static createCheck(t,r){if(t&&t.includes(r))throw new Error(`${it} object contains circular references`);return new ue(r,t)}},V={null:new c(s.null,null),undefined:new c(s.undefined,void 0),true:new c(s.true,!0),false:new c(s.false,!1),emptyArray:new c(s.array,0),emptyMap:new c(s.map,0)},H={number(e,t,r,n){return!Number.isInteger(e)||!Number.isSafeInteger(e)?new c(s.float,e):e>=0?new c(s.uint,e):new c(s.negint,e)},bigint(e,t,r,n){return e>=BigInt(0)?new c(s.uint,e):new c(s.negint,e)},Uint8Array(e,t,r,n){return new c(s.bytes,e)},string(e,t,r,n){return new c(s.string,e)},boolean(e,t,r,n){return e?V.true:V.false},null(e,t,r,n){return V.null},undefined(e,t,r,n){return V.undefined},ArrayBuffer(e,t,r,n){return new c(s.bytes,new Uint8Array(e))},DataView(e,t,r,n){return new c(s.bytes,new Uint8Array(e.buffer,e.byteOffset,e.byteLength))},Array(e,t,r,n){if(!e.length)return r.addBreakTokens===!0?[V.emptyArray,new c(s.break)]:V.emptyArray;n=ue.createCheck(n,e);let o=[],i=0;for(let a of e)o[i++]=Ae(a,r,n);return r.addBreakTokens?[new c(s.array,e.length),o,new c(s.break)]:[new c(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?[V.emptyMap,new c(s.break)]:V.emptyMap;n=ue.createCheck(n,e);let d=[],f=0;for(let h of i)d[f++]=[Ae(h,r,n),Ae(o?e.get(h):e[h],r,n)];return Lo(d,r),r.addBreakTokens?[new c(s.map,a),d,new c(s.break)]:[new c(s.map,a),d]}};H.Map=H.Object;H.Buffer=H.Uint8Array;for(let e of"Uint8Clamped Uint16 Uint32 Int8 Int16 Int32 BigUint64 BigInt64 Float32 Float64".split(" "))H[`${e}Array`]=H.DataView;function Ae(e,t={},r){let n=Wt(e),o=t&&t.typeEncoders&&t.typeEncoders[n]||H[n];if(typeof o=="function"){let a=o(e,n,t,r);if(a!=null)return a}let i=H[n];if(!i)throw new Error(`${it} unsupported type: ${n}`);return i(e,n,t,r)}function Lo(e,t){t.mapSorter&&e.sort(t.mapSorter)}function Do(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=Qr[o].compareTokens(r,n);return i===0&&console.warn("WARNING: complex key types used, CBOR key sorting guarantees are gone"),i}function Yr(e,t,r,n){if(Array.isArray(t))for(let o of t)Yr(e,o,r,n);else r[t.type.major](e,t,n)}function Fo(e,t,r){let n=Ae(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),d=new xe(a);if(i(d,n,r),d.chunks.length!==1)throw new Error(`Unexpected error: pre-calculated length for ${n} was wrong`);return ot(d.chunks[0])}}return dt.reset(),Yr(dt,n,t,r),dt.toBytes(!0)}function lt(e,t){return t=Object.assign({},Oo,t),Fo(e,Qr,t)}var Vo={strict:!1,allowIndefinite:!0,allowUndefined:!0,allowBigInt:!0},ht=class{constructor(t,r={}){this.pos=0,this.data=t,this.options=r}done(){return this.pos>=this.data.length}next(){let t=this.data[this.pos],r=N[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}},_e=Symbol.for("DONE"),He=Symbol.for("BREAK");function Ho(e,t,r){let n=[];for(let o=0;o<e.value;o++){let i=Ue(t,r);if(i===He){if(e.value===1/0)break;throw new Error(`${l} got unexpected break to lengthed array`)}if(i===_e)throw new Error(`${l} found array but not enough entries (got ${o}, expected ${e.value})`);n[o]=i}return n}function Po(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 d=Ue(t,r);if(d===He){if(e.value===1/0)break;throw new Error(`${l} got unexpected break to lengthed map`)}if(d===_e)throw new Error(`${l} found map but not enough entries (got ${a} [no key], expected ${e.value})`);if(n!==!0&&typeof d!="string")throw new Error(`${l} non-string keys not supported (got ${typeof d})`);let f=Ue(t,r);if(f===_e)throw new Error(`${l} found map but not enough entries (got ${a} [no value], expected ${e.value})`);n?i.set(d,f):o[d]=f}return n?i:o}function Ue(e,t){if(e.done())return _e;let r=e.next();if(r.type===s.break)return He;if(r.type.terminal)return r.value;if(r.type===s.array)return Ho(r,e,t);if(r.type===s.map)return Po(r,e,t);if(r.type===s.tag){if(t.tags&&typeof t.tags[r.value]=="function"){let n=Ue(e,t);return t.tags[r.value](n)}throw new Error(`${l} tag not supported (${r.value})`)}throw new Error("unsupported")}function pt(e,t){if(!(e instanceof Uint8Array))throw new Error(`${l} data to decode must be a Uint8Array`);t=Object.assign({},Vo,t);let r=t.tokenizer||new ht(e,t),n=Ue(r,t);if(n===_e)throw new Error(`${l} did not find any content to decode`);if(n===He)throw new Error(`${l} got unexpected break`);if(!r.done())throw new Error(`${l} too many terminals, data makes no sense`);return n}var Zr=42;function Go(e){if(e.asCID!==e&&e["/"]!==e.bytes)return null;let t=m.asCID(e);if(!t)return null;let r=new Uint8Array(t.bytes.byteLength+1);return r.set(t.bytes,1),[new c(s.tag,Zr),new c(s.bytes,r)]}function jo(){throw new Error("`undefined` is not supported by the IPLD Data Model and cannot be encoded")}function Xo(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 Jo={float64:!0,typeEncoders:{Object:Go,undefined:jo,number:Xo}};function Ko(e){if(e[0]!==0)throw new Error("Invalid CID for CBOR tag 42; expected leading 0x00");return m.decode(e.subarray(1))}var en={allowIndefinite:!1,coerceUndefinedToNull:!0,allowNaN:!1,allowInfinity:!1,allowBigInt:!0,strict:!0,useMaps:!1,tags:[]};en.tags[Zr]=Ko;var Pe=e=>lt(e,Jo),tn=e=>pt(e,en);var P={Null:e=>e===null,Int:e=>Number.isInteger(e),Float:e=>typeof e=="number"&&Number.isFinite(e),String:e=>typeof e=="string",Bool:e=>typeof e=="boolean",Bytes:e=>e instanceof Uint8Array,Link:e=>!P.Null(e)&&typeof e=="object"&&e.asCID===e,List:e=>Array.isArray(e),Map:e=>!P.Null(e)&&typeof e=="object"&&e.asCID!==e&&!P.List(e)&&!P.Bytes(e)},de={Int:P.Int,"CarHeader > version":e=>de.Int(e),"CarHeader > roots (anon) > valueType (anon)":P.Link,"CarHeader > roots (anon)":e=>P.List(e)&&Array.prototype.every.call(e,de["CarHeader > roots (anon) > valueType (anon)"]),"CarHeader > roots":e=>de["CarHeader > roots (anon)"](e),CarHeader:e=>{let t=e&&Object.keys(e);return P.Map(e)&&["version"].every(r=>t.includes(r))&&Object.entries(e).every(([r,n])=>de["CarHeader > "+r]&&de["CarHeader > "+r](n))}},rn=de.CarHeader;var yt={SHA2_256:18,LENGTH:32,DAG_PB:112},nn=16+8+8+8;async function qe(e){let t=await e.upTo(8);if(!t.length)throw new Error("Unexpected end of data");let r=q.default.decode(t);return e.seek(q.default.decode.bytes),r}async function Qo(e){let t=await e.exactly(nn),r=new DataView(t.buffer,t.byteOffset,t.byteLength),n=0,o={version:2,characteristics:[r.getBigUint64(n,!0),r.getBigUint64(n+=8,!0)],dataOffset:Number(r.getBigUint64(n+=8,!0)),dataSize:Number(r.getBigUint64(n+=8,!0)),indexOffset:Number(r.getBigUint64(n+=8,!0))};return e.seek(nn),o}async function Ge(e,t){let r=await qe(e);if(r===0)throw new Error("Invalid CAR header (zero length)");let n=await e.exactly(r);e.seek(r);let o=tn(n);if(!rn(o))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})`:""}`);let i=Array.isArray(o.roots);if(o.version===1&&!i||o.version===2&&i)throw new Error("Invalid CAR header format");if(o.version===1)return o;let a=await Qo(e);e.seek(a.dataOffset-e.pos);let d=await Ge(e,1);return Object.assign(d,a)}async function Yo(e){let t=await e.upTo(8);q.default.decode(t);let r=q.default.decode.bytes,n=q.default.decode(t.subarray(q.default.decode.bytes)),o=q.default.decode.bytes,i=r+o+n,a=await e.exactly(i);return e.seek(i),a}async function Zo(e){let t=await e.exactly(2);if(t[0]===yt.SHA2_256&&t[1]===yt.LENGTH){let a=await e.exactly(34);e.seek(34);let d=we(a);return m.create(0,yt.DAG_PB,d)}let r=await qe(e);if(r!==1)throw new Error(`Unexpected CID version (${r})`);let n=await qe(e),o=await Yo(e),i=we(o);return m.create(r,n,i)}async function on(e){let t=e.pos,r=await qe(e);if(r===0)throw new Error("Invalid CAR section (zero length)");r+=e.pos-t;let n=await Zo(e),o=r-Number(e.pos-t);return{cid:n,length:r,blockLength:o}}async function ei(e){let{cid:t,blockLength:r}=await on(e),n=await e.exactly(r);return e.seek(r),{bytes:n,cid:t}}async function ti(e){let t=e.pos,{cid:r,length:n,blockLength:o}=await on(e),i={cid:r,length:n,blockLength:o,offset:t,blockOffset:e.pos};return e.seek(i.blockLength),i}function fe(e){let t=(async()=>{let r=await Ge(e);if(r.version===2){let n=e.pos-r.dataOffset;e=ni(e,r.dataSize-n)}return r})();return{header:()=>t,async*blocks(){for(await t;(await e.upTo(8)).length>0;)yield await ei(e)},async*blocksIndex(){for(await t;(await e.upTo(8)).length>0;)yield await ti(e)}}}function G(e){let t=0;return{async upTo(r){return e.subarray(t,t+Math.min(r,e.length-t))},async exactly(r){if(r>e.length-t)throw new Error("Unexpected end of data");return e.subarray(t,t+r)},seek(r){t+=r},get pos(){return t}}}function ri(e){let t=0,r=0,n=0,o=new Uint8Array(0),i=async a=>{r=o.length-n;let d=[o.subarray(n)];for(;r<a;){let h=await e();if(h==null)break;r<0?h.length>r&&d.push(h.subarray(-r)):d.push(h),r+=h.length}o=new Uint8Array(d.reduce((h,p)=>h+p.length,0));let f=0;for(let h of d)o.set(h,f),f+=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){if(o.length-n<a&&await i(a),o.length-n<a)throw new Error("Unexpected end of data");return o.subarray(n,n+a)},seek(a){t+=a,n+=a},get pos(){return t}}}function le(e){let t=e[Symbol.asyncIterator]();async function r(){let n=await t.next();return n.done?null:n.value}return ri(r)}function ni(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){let o=await e.exactly(n);if(o.length+r>t)throw new Error("Unexpected end of data");return o},seek(n){r+=n,e.seek(n)},get pos(){return e.pos}}}var J=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 sn(G(t))}static async fromIterable(t){if(!t||typeof t[Symbol.asyncIterator]!="function")throw new TypeError("fromIterable() requires an async iterable");return sn(le(t))}};async function sn(e){let t=fe(e),r=await t.header(),n=[];for await(let o of t.blocks())n.push(o);return new J(r,n)}var K=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 an(G(t))}static async fromIterable(t){if(!t||typeof t[Symbol.asyncIterator]!="function")throw new TypeError("fromIterable() requires an async iterable");return an(le(t))}};async function an(e){let t=fe(e),{version:r,roots:n}=await t.header();return new K(r,n,t.blocksIndex())}var je=class{constructor(t,r,n){this._version=t,this._roots=r,this._iterable=n,this._decoded=!1}get version(){return this._version}async getRoots(){return this._roots}},W=class extends je{[Symbol.asyncIterator](){if(this._decoded)throw new Error("Cannot decode more than once");if(!this._iterable)throw new Error("Block iterable not found");return this._decoded=!0,this._iterable[Symbol.asyncIterator]()}static async fromBytes(t){let{version:r,roots:n,iterator:o}=await cn(t);return new W(r,n,o)}static async fromIterable(t){let{version:r,roots:n,iterator:o}=await un(t);return new W(r,n,o)}},Q=class extends je{[Symbol.asyncIterator](){if(this._decoded)throw new Error("Cannot decode more than once");if(!this._iterable)throw new Error("Block iterable not found");this._decoded=!0;let t=this._iterable[Symbol.asyncIterator]();return{async next(){let r=await t.next();return r.done?r:{done:!1,value:r.value.cid}}}}static async fromBytes(t){let{version:r,roots:n,iterator:o}=await cn(t);return new Q(r,n,o)}static async fromIterable(t){let{version:r,roots:n,iterator:o}=await un(t);return new Q(r,n,o)}};async function cn(e){if(!(e instanceof Uint8Array))throw new TypeError("fromBytes() requires a Uint8Array");return dn(G(e))}async function un(e){if(!e||typeof e[Symbol.asyncIterator]!="function")throw new TypeError("fromIterable() requires an async iterable");return dn(le(e))}async function dn(e){let t=fe(e),{version:r,roots:n}=await t.header();return{version:r,roots:n,iterator:t.blocks()}}var mt=Ne(Ce(),1);function wt(e){let t=Pe({version:1,roots:e}),r=mt.default.encode(t.length),n=new Uint8Array(r.length+t.length);return n.set(r,0),n.set(t,r.length),n}function fn(e){return{async setRoots(t){let r=wt(t);await e.write(r)},async writeBlock(t){let{cid:r,bytes:n}=t;await e.write(new Uint8Array(mt.default.encode(r.bytes.length+n.length))),await e.write(r.bytes),n.length&&await e.write(n)},async close(){await e.end()}}}function Xe(){}function ln(){let e=[],t=null,r=Xe,n=!1,o=null,i=Xe,a=()=>(t||(t=new Promise(h=>{r=()=>{t=null,r=Xe,h()}})),t),d={write(h){e.push(h);let p=a();return i(),p},async end(){n=!0;let h=a();i(),await h}},f={async next(){let h=e.shift();return h?(e.length===0&&r(),{done:!1,value:h}):n?(r(),{done:!0,value:void 0}):(o||(o=new Promise(p=>{i=()=>(o=null,i=Xe,p(f.next()))})),o)}};return{writer:d,iterator:f}}var Y=class{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=m.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()}static create(t){t=oi(t);let{encoder:r,iterator:n}=hn(),o=new Y(t,r),i=new Je(n);return{writer:o,out:i}}static createAppender(){let{encoder:t,iterator:r}=hn();t.setRoots=()=>Promise.resolve();let n=new Y([],t),o=new Je(r);return{writer:n,out:o}}static async updateRootsInBytes(t,r){let n=G(t);await Ge(n);let o=wt(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}},Je=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 hn(){let e=ln(),{writer:t,iterator:r}=e;return{encoder:fn(t),iterator:r}}function oi(e){if(e===void 0)return[];if(!Array.isArray(e)){let r=m.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=m.asCID(r);if(!n)throw new TypeError("roots must be a single CID or an array of CIDs");t.push(n)}return t}var gt=Ne(pn(),1);var he=class{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 gt.default.promises.open(this._path,"r"));let n={cid:t,length:0,offset:0,blockLength:r.blockLength,blockOffset:r.blockOffset};return J.readRaw(this._fd,n)}async*blocks(){for(let t of this._order){let r=await this.get(m.parse(t));if(!r)throw new Error("Unexpected internal error");yield r}}async*cids(){for(let t of this._order)yield m.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 K.fromIterable(yn.Readable.from(gt.default.createReadStream(t))),n=new Map,o=[];for await(let{cid:i,blockLength:a,blockOffset:d}of r){let f=i.toString();n.set(f,{blockLength:a,blockOffset:d}),o.push(f)}return new he(r.version,t,await r.getRoots(),n,o)}};var _t={};Ut(_t,{addBlock:()=>gn,addRoot:()=>wn,blockLength:()=>ai,calculateHeaderLength:()=>kt,close:()=>bn,createWriter:()=>fi,estimateHeaderLength:()=>di,headerLength:()=>At,resizeHeader:()=>Et});var Te=Ne(Ce(),1);var ii=ft(),si={float64:!1,quickEncodeToken:Ve};function bt(e,t=ii,r=si){if(Array.isArray(e)){let n=0;for(let o of e)n+=bt(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 vt=class{constructor(t,r){this.bytes=t,this.byteOffset=r,this.roots=[],this.headerSize=r}addRoot(t,r){return wn(this,t,r),this}write(t){return gn(this,t),this}close(t){return bn(this,t)}},wn=(e,t,r={})=>{let{resize:n=!1}=r,{bytes:o,headerSize:i,byteOffset:a,roots:d}=e;e.roots.push(t);let f=At(e);if(f>i)if(f-i+a<o.byteLength)if(n)Et(e,f);else throw d.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 d.pop(),new RangeError(`Buffer has no capacity for a new root ${t}`)},ai=({cid:e,bytes:t})=>{let r=e.bytes.byteLength+t.byteLength;return Te.default.encodingLength(r)+r},gn=(e,{cid:t,bytes:r})=>{let n=t.bytes.byteLength+r.byteLength,o=Te.default.encode(n);if(e.byteOffset+o.length+n>e.bytes.byteLength)throw new RangeError("Buffer has no capacity for this block");xt(e,o),xt(e,t.bytes),xt(e,r)},bn=(e,t={})=>{let{resize:r=!1}=t,{roots:n,bytes:o,byteOffset:i,headerSize:a}=e,d=Pe({version:1,roots:n}),f=Te.default.encode(d.length),h=f.length+d.byteLength;if(a-h===0)return mn(e,f,d),o.subarray(0,i);if(r)return Et(e,h),mn(e,f,d),o.subarray(0,e.byteOffset);throw new RangeError(`Header size was overestimated.
4
- You can use close({ resize: true }) to resize header`)},Et=(e,t)=>{let{bytes:r,headerSize:n}=e;r.set(r.subarray(n,e.byteOffset),t),e.byteOffset+=t-n,e.headerSize=t},xt=(e,t)=>{e.bytes.set(t,e.byteOffset),e.byteOffset+=t.length},mn=({bytes:e},t,r)=>{e.set(t),e.set(r,t.length)},ci=[new c(s.map,2),new c(s.string,"version"),new c(s.uint,1),new c(s.string,"roots")],ui=new c(s.tag,42),kt=e=>{let t=[...ci];t.push(new c(s.array,e.length));for(let n of e)t.push(ui),t.push(new c(s.bytes,{length:n+1}));let r=bt(t);return Te.default.encodingLength(r)+r},At=({roots:e})=>kt(e.map(t=>t.bytes.byteLength)),di=(e,t=36)=>kt(new Array(e).fill(t)),fi=(e,t={})=>{let{roots:r=[],byteOffset:n=0,byteLength:o=e.byteLength,headerSize:i=At({roots:r})}=t,a=new Uint8Array(e,n,o),d=new vt(a,i);for(let f of r)d.addRoot(f);return d};return Un(li);})();
2
+ "use strict";var IpldCar=(()=>{var En=Object.create;var Ie=Object.defineProperty;var kn=Object.getOwnPropertyDescriptor;var An=Object.getOwnPropertyNames;var _n=Object.getPrototypeOf,Un=Object.prototype.hasOwnProperty;var pe=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),Ut=(e,t)=>{for(var r in t)Ie(e,r,{get:t[r],enumerable:!0})},Tt=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of An(t))!Un.call(e,o)&&o!==r&&Ie(e,o,{get:()=>t[o],enumerable:!(n=kn(t,o))||n.enumerable});return e};var Ne=(e,t,r)=>(r=e!=null?En(_n(e)):{},Tt(t||!e||!e.__esModule?Ie(r,"default",{value:e,enumerable:!0}):r,e)),Tn=e=>Tt(Ie({},"__esModule",{value:!0}),e);var It=pe((pi,Bt)=>{Bt.exports=Xe;var St=128,Sn=127,Bn=~Sn,In=Math.pow(2,31);function Xe(e,t,r){if(Number.MAX_SAFE_INTEGER&&e>Number.MAX_SAFE_INTEGER)throw Xe.bytes=0,new RangeError("Could not encode varint");t=t||[],r=r||0;for(var n=r;e>=In;)t[r++]=e&255|St,e/=128;for(;e&Bn;)t[r++]=e&255|St,e>>>=7;return t[r]=e|0,Xe.bytes=r-n+1,t}});var Mt=pe((yi,Ct)=>{Ct.exports=We;var Nn=128,Nt=127;function We(e,n){var r=0,n=n||0,o=0,i=n,a,d=e.length;do{if(i>=d||o>49)throw We.bytes=0,new RangeError("Could not decode varint");a=e[i++],r+=o<28?(a&Nt)<<o:(a&Nt)*Math.pow(2,o),o+=7}while(a>=Nn);return We.bytes=i-n,r}});var zt=pe((mi,$t)=>{var Cn=Math.pow(2,7),Mn=Math.pow(2,14),$n=Math.pow(2,21),zn=Math.pow(2,28),Rn=Math.pow(2,35),On=Math.pow(2,42),Ln=Math.pow(2,49),Dn=Math.pow(2,56),Fn=Math.pow(2,63);$t.exports=function(e){return e<Cn?1:e<Mn?2:e<$n?3:e<zn?4:e<Rn?5:e<On?6:e<Ln?7:e<Dn?8:e<Fn?9:10}});var Ce=pe((wi,Rt)=>{Rt.exports={encode:It(),decode:Mt(),encodingLength:zt()}});var yn=pe(()=>{});var li={};Ut(li,{CarBlockIterator:()=>W,CarBufferWriter:()=>_t,CarCIDIterator:()=>Q,CarIndexedReader:()=>he,CarIndexer:()=>X,CarReader:()=>K,CarWriter:()=>Y});var q=Ne(Ce(),1);var Vn=Dt,Ot=128,Hn=127,Pn=~Hn,qn=Math.pow(2,31);function Dt(e,t,r){t=t||[],r=r||0;for(var n=r;e>=qn;)t[r++]=e&255|Ot,e/=128;for(;e&Pn;)t[r++]=e&255|Ot,e>>>=7;return t[r]=e|0,Dt.bytes=r-n+1,t}var Gn=Qe,jn=128,Lt=127;function Qe(e,n){var r=0,n=n||0,o=0,i=n,a,d=e.length;do{if(i>=d)throw Qe.bytes=0,new RangeError("Could not decode varint");a=e[i++],r+=o<28?(a&Lt)<<o:(a&Lt)*Math.pow(2,o),o+=7}while(a>=jn);return Qe.bytes=i-n,r}var Jn=Math.pow(2,7),Kn=Math.pow(2,14),Xn=Math.pow(2,21),Wn=Math.pow(2,28),Qn=Math.pow(2,35),Yn=Math.pow(2,42),Zn=Math.pow(2,49),eo=Math.pow(2,56),to=Math.pow(2,63),ro=function(e){return e<Jn?1:e<Kn?2:e<Xn?3:e<Wn?4:e<Qn?5:e<Yn?6:e<Zn?7:e<eo?8:e<to?9:10},no={encode:Vn,decode:Gn,encodingLength:ro},oo=no,ye=oo;var me=(e,t=0)=>[ye.decode(e,t),ye.decode.bytes],ee=(e,t,r=0)=>(ye.encode(e,t,r),t),te=e=>ye.encodingLength(e);var xi=new Uint8Array(0);var Vt=(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},re=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")};var Ht=(e,t)=>{let r=t.byteLength,n=te(e),o=n+te(r),i=new Uint8Array(o+r);return ee(e,i,0),ee(r,i,n),i.set(t,o),new ne(e,r,t,i)},we=e=>{let t=re(e),[r,n]=me(t),[o,i]=me(t.subarray(n)),a=t.subarray(n+i);if(a.byteLength!==o)throw new Error("Incorrect length");return new ne(r,o,a,t)},Pt=(e,t)=>{if(e===t)return!0;{let r=t;return e.code===r.code&&e.size===r.size&&r.bytes instanceof Uint8Array&&Vt(e.bytes,r.bytes)}},ne=class{constructor(t,r,n,o){this.code=t,this.size=r,this.digest=n,this.bytes=o}};function io(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 d=e.length,f=e.charAt(0),h=Math.log(d)/Math.log(256),p=Math.log(256)/Math.log(d);function Z(w){if(w instanceof Uint8Array||(ArrayBuffer.isView(w)?w=new Uint8Array(w.buffer,w.byteOffset,w.byteLength):Array.isArray(w)&&(w=Uint8Array.from(w))),!(w instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(w.length===0)return"";for(var x=0,j=0,S=0,C=w.length;S!==C&&w[S]===0;)S++,x++;for(var M=(C-S)*p+1>>>0,_=new Uint8Array(M);S!==C;){for(var $=w[S],F=0,B=M-1;($!==0||F<j)&&B!==-1;B--,F++)$+=256*_[B]>>>0,_[B]=$%d>>>0,$=$/d>>>0;if($!==0)throw new Error("Non-zero carry");j=F,S++}for(var O=M-j;O!==M&&_[O]===0;)O++;for(var Be=f.repeat(x);O<M;++O)Be+=e.charAt(_[O]);return Be}function Se(w){if(typeof w!="string")throw new TypeError("Expected String");if(w.length===0)return new Uint8Array;var x=0;if(w[x]!==" "){for(var j=0,S=0;w[x]===f;)j++,x++;for(var C=(w.length-x)*h+1>>>0,M=new Uint8Array(C);w[x];){var _=r[w.charCodeAt(x)];if(_===255)return;for(var $=0,F=C-1;(_!==0||$<S)&&F!==-1;F--,$++)_+=d*M[F]>>>0,M[F]=_%256>>>0,_=_/256>>>0;if(_!==0)throw new Error("Non-zero carry");S=$,x++}if(w[x]!==" "){for(var B=C-S;B!==C&&M[B]===0;)B++;for(var O=new Uint8Array(j+(C-B)),Be=j;B!==C;)O[Be++]=M[B++];return O}}}function vn(w){var x=Se(w);if(x)return x;throw new Error(`Non-${t} character`)}return{encode:Z,decodeUnsafe:Se,decode:vn}}var so=io,ao=so,Gt=ao;var Ye=class{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")}},Ze=class{constructor(t,r,n){if(this.name=t,this.prefix=r,r.codePointAt(0)===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=r.codePointAt(0),this.baseDecode=n}decode(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return jt(this,t)}},et=class{constructor(t){this.decoders=t}or(t){return jt(this,t)}decode(t){let r=t[0],n=this.decoders[r];if(n)return n.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}},jt=(e,t)=>new et({...e.decoders||{[e.prefix]:e},...t.decoders||{[t.prefix]:t}}),tt=class{constructor(t,r,n,o){this.name=t,this.prefix=r,this.baseEncode=n,this.baseDecode=o,this.encoder=new Ye(t,r,n),this.decoder=new Ze(t,r,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}},Jt=({name:e,prefix:t,encode:r,decode:n})=>new tt(e,t,r,n),rt=({prefix:e,name:t,alphabet:r})=>{let{encode:n,decode:o}=Gt(r,t);return Jt({prefix:e,name:t,encode:n,decode:i=>re(o(i))})},co=(e,t,r,n)=>{let o={};for(let p=0;p<t.length;++p)o[t[p]]=p;let i=e.length;for(;e[i-1]==="=";)--i;let a=new Uint8Array(i*r/8|0),d=0,f=0,h=0;for(let p=0;p<i;++p){let Z=o[e[p]];if(Z===void 0)throw new SyntaxError(`Non-${n} character`);f=f<<r|Z,d+=r,d>=8&&(d-=8,a[h++]=255&f>>d)}if(d>=r||255&f<<8-d)throw new SyntaxError("Unexpected end of data");return a},uo=(e,t,r)=>{let n=t[t.length-1]==="=",o=(1<<r)-1,i="",a=0,d=0;for(let f=0;f<e.length;++f)for(d=d<<8|e[f],a+=8;a>r;)a-=r,i+=t[o&d>>a];if(a&&(i+=t[o&d<<r-a]),n)for(;i.length*r&7;)i+="=";return i},z=({name:e,prefix:t,bitsPerChar:r,alphabet:n})=>Jt({prefix:t,name:e,encode(o){return uo(o,n,r)},decode(o){return co(o,n,r,e)}});var L=rt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Si=rt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var ge=z({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Ni=z({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Ci=z({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Mi=z({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),$i=z({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),zi=z({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Ri=z({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Oi=z({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Li=z({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Kt=(e,t)=>{let{bytes:r,version:n}=e;switch(n){case 0:return lo(r,nt(e),t||L.encoder);default:return ho(r,nt(e),t||ge.encoder)}};var Xt=new WeakMap,nt=e=>{let t=Xt.get(e);if(t==null){let r=new Map;return Xt.set(e,r),r}return t},m=class{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!==be)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==po)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return m.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=Ht(t,r);return m.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 m.equals(this,t)}static equals(t,r){let n=r;return n&&t.code===n.code&&t.version===n.version&&Pt(t.multihash,n.multihash)}toString(t){return Kt(this,t)}toJSON(){return{"/":Kt(this)}}link(){return this}get[Symbol.toStringTag](){return"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 m)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:o,multihash:i,bytes:a}=r;return new m(n,o,i,a||Wt(n,o,i.bytes))}else if(r[yo]===!0){let{version:n,multihash:o,code:i}=r,a=we(o);return m.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!==be)throw new Error(`Version 0 CID must use dag-pb (code: ${be}) block encoding`);return new m(t,r,n,n.bytes)}case 1:{let o=Wt(t,r,n.bytes);return new m(t,r,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return m.create(0,be,t)}static createV1(t,r){return m.create(1,t,r)}static decode(t){let[r,n]=m.decodeFirst(t);if(n.length)throw new Error("Incorrect length");return r}static decodeFirst(t){let r=m.inspectBytes(t),n=r.size-r.multihashSize,o=re(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 ne(r.multihashCode,r.digestSize,i,o);return[r.version===0?m.createV0(a):m.createV1(r.codec,a),t.subarray(r.size)]}static inspectBytes(t){let r=0,n=()=>{let[Z,Se]=me(t.subarray(r));return r+=Se,Z},o=n(),i=be;if(o===18?(o=0,r=0):i=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let a=r,d=n(),f=n(),h=r+f,p=h-a;return{version:o,codec:i,multihashCode:d,digestSize:f,multihashSize:p,size:h}}static parse(t,r){let[n,o]=fo(t,r),i=m.decode(o);return nt(i).set(n,t),i}},fo=(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 ge.prefix:{let r=t||ge;return[ge.prefix,r.decode(e)]}default:{if(t==null)throw Error("To parse non base32 or base58btc encoded CID multibase decoder must be provided");return[e[0],t.decode(e)]}}},lo=(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},ho=(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},be=112,po=18,Wt=(e,t,r)=>{let n=te(e),o=n+te(t),i=new Uint8Array(o+r.byteLength);return ee(e,i,0),ee(t,i,n),i.set(r,o),i},yo=Symbol.for("@ipld/js-cid/CID");var mo=["string","number","bigint","symbol"],wo=["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 Qt(e){if(e===null)return"null";if(e===void 0)return"undefined";if(e===!0||e===!1)return"boolean";let t=typeof e;if(mo.includes(t))return t;if(t==="function")return"Function";if(Array.isArray(e))return"Array";if(go(e))return"Buffer";let r=bo(e);return r||"Object"}function go(e){return e&&e.constructor&&e.constructor.isBuffer&&e.constructor.isBuffer.call(null,e)}function bo(e){let t=Object.prototype.toString.call(e).slice(8,-1);if(wo.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 c=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 oe=globalThis.process&&!globalThis.process.browser&&globalThis.Buffer&&typeof globalThis.Buffer.isBuffer=="function",xo=new TextDecoder,vo=new TextEncoder;function Me(e){return oe&&globalThis.Buffer.isBuffer(e)}function ot(e){return e instanceof Uint8Array?Me(e)?new Uint8Array(e.buffer,e.byteOffset,e.byteLength):e:Uint8Array.from(e)}var tr=oe?(e,t,r)=>r-t>64?globalThis.Buffer.from(e.subarray(t,r)).toString("utf8"):Zt(e,t,r):(e,t,r)=>r-t>64?xo.decode(e.subarray(t,r)):Zt(e,t,r),rr=oe?e=>e.length>64?globalThis.Buffer.from(e):Yt(e):e=>e.length>64?vo.encode(e):Yt(e),R=e=>Uint8Array.from(e),ie=oe?(e,t,r)=>Me(e)?new Uint8Array(e.subarray(t,r)):e.slice(t,r):(e,t,r)=>e.slice(t,r),nr=oe?(e,t)=>(e=e.map(r=>r instanceof Uint8Array?r:globalThis.Buffer.from(r)),ot(globalThis.Buffer.concat(e,t))):(e,t)=>{let r=new Uint8Array(t),n=0;for(let o of e)n+o.length>r.length&&(o=o.subarray(0,r.length-n)),r.set(o,n),n+=o.length;return r},or=oe?e=>globalThis.Buffer.allocUnsafe(e):e=>new Uint8Array(e);function ir(e,t){if(Me(e)&&Me(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 Yt(e,t=1/0){let r,n=e.length,o=null,i=[];for(let a=0;a<n;++a){if(r=e.charCodeAt(a),r>55295&&r<57344){if(!o){if(r>56319){(t-=3)>-1&&i.push(239,191,189);continue}else if(a+1===n){(t-=3)>-1&&i.push(239,191,189);continue}o=r;continue}if(r<56320){(t-=3)>-1&&i.push(239,191,189),o=r;continue}r=(o-55296<<10|r-56320)+65536}else o&&(t-=3)>-1&&i.push(239,191,189);if(o=null,r<128){if((t-=1)<0)break;i.push(r)}else if(r<2048){if((t-=2)<0)break;i.push(r>>6|192,r&63|128)}else if(r<65536){if((t-=3)<0)break;i.push(r>>12|224,r>>6&63|128,r&63|128)}else if(r<1114112){if((t-=4)<0)break;i.push(r>>18|240,r>>12&63|128,r>>6&63|128,r&63|128)}else throw new Error("Invalid code point")}return i}function Zt(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 d,f,h,p;switch(a){case 1:o<128&&(i=o);break;case 2:d=e[t+1],(d&192)===128&&(p=(o&31)<<6|d&63,p>127&&(i=p));break;case 3:d=e[t+1],f=e[t+2],(d&192)===128&&(f&192)===128&&(p=(o&15)<<12|(d&63)<<6|f&63,p>2047&&(p<55296||p>57343)&&(i=p));break;case 4:d=e[t+1],f=e[t+2],h=e[t+3],(d&192)===128&&(f&192)===128&&(h&192)===128&&(p=(o&15)<<18|(d&63)<<12|(f&63)<<6|h&63,p>65535&&p<1114112&&(i=p))}}i===null?(i=65533,a=1):i>65535&&(i-=65536,n.push(i>>>10&1023|55296),i=56320|i&1023),n.push(i),t+=a}return Eo(n)}var er=4096;function Eo(e){let t=e.length;if(t<=er)return String.fromCharCode.apply(String,e);let r="",n=0;for(;n<t;)r+=String.fromCharCode.apply(String,e.slice(n,n+=er));return r}var ko=256,xe=class{constructor(t=ko){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=or(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=ie(n,0,this.cursor)}else r=nr(this.chunks,this.cursor);return t&&this.reset(),r}};var l="CBOR decode error:",it="CBOR encode error:",ve=[];ve[23]=1;ve[24]=2;ve[25]=3;ve[26]=5;ve[27]=9;function D(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){D(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){D(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){D(e,t,4);let n=e[t]*16777216+(e[t+1]<<16)+(e[t+2]<<8)+e[t+3];if(r.strict===!0&&n<g[2])throw new Error(`${l} integer encoded in more bytes than necessary (strict decode)`);return n}function A(e,t,r){D(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 sr(e,t,r,n){return new c(s.uint,v(e,t+1,n),2)}function ar(e,t,r,n){return new c(s.uint,E(e,t+1,n),3)}function cr(e,t,r,n){return new c(s.uint,k(e,t+1,n),5)}function ur(e,t,r,n){return new c(s.uint,A(e,t+1,n),9)}function U(e,t){return b(e,0,t.value)}function b(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`)}}U.encodedSize=function(t){return b.encodedSize(t.value)};b.encodedSize=function(t){return t<g[0]?1:t<g[1]?2:t<g[2]?3:t<g[3]?5:9};U.compareTokens=function(t,r){return t.value<r.value?-1:t.value>r.value?1:0};function dr(e,t,r,n){return new c(s.negint,-1-v(e,t+1,n),2)}function fr(e,t,r,n){return new c(s.negint,-1-E(e,t+1,n),3)}function lr(e,t,r,n){return new c(s.negint,-1-k(e,t+1,n),5)}var st=BigInt(-1),hr=BigInt(1);function pr(e,t,r,n){let o=A(e,t+1,n);if(typeof o!="bigint"){let i=-1-o;if(i>=Number.MIN_SAFE_INTEGER)return new c(s.negint,i,9)}if(n.allowBigInt!==!0)throw new Error(`${l} integers outside of the safe integer range are not supported`);return new c(s.negint,st-BigInt(o),9)}function $e(e,t){let r=t.value,n=typeof r=="bigint"?r*st-hr:r*-1-1;b(e,t.type.majorEncoded,n)}$e.encodedSize=function(t){let r=t.value,n=typeof r=="bigint"?r*st-hr:r*-1-1;return n<g[0]?1:n<g[1]?2:n<g[2]?3:n<g[3]?5:9};$e.compareTokens=function(t,r){return t.value<r.value?1:t.value>r.value?-1:0};function Ee(e,t,r,n){D(e,t,r+n);let o=ie(e,t+r,t+r+n);return new c(s.bytes,o,r+n)}function yr(e,t,r,n){return Ee(e,t,1,r)}function mr(e,t,r,n){return Ee(e,t,2,v(e,t+1,n))}function wr(e,t,r,n){return Ee(e,t,3,E(e,t+1,n))}function gr(e,t,r,n){return Ee(e,t,5,k(e,t+1,n))}function br(e,t,r,n){let o=A(e,t+1,n);if(typeof o=="bigint")throw new Error(`${l} 64-bit integer bytes lengths not supported`);return Ee(e,t,9,o)}function ze(e){return e.encodedBytes===void 0&&(e.encodedBytes=e.type===s.string?rr(e.value):e.value),e.encodedBytes}function se(e,t){let r=ze(t);b(e,t.type.majorEncoded,r.length),e.push(r)}se.encodedSize=function(t){let r=ze(t);return b.encodedSize(r.length)+r.length};se.compareTokens=function(t,r){return _o(ze(t),ze(r))};function _o(e,t){return e.length<t.length?-1:e.length>t.length?1:ir(e,t)}function ke(e,t,r,n,o){let i=r+n;D(e,t,i);let a=new c(s.string,tr(e,t+r,t+i),i);return o.retainStringBytes===!0&&(a.byteValue=ie(e,t+r,t+i)),a}function xr(e,t,r,n){return ke(e,t,1,r,n)}function vr(e,t,r,n){return ke(e,t,2,v(e,t+1,n),n)}function Er(e,t,r,n){return ke(e,t,3,E(e,t+1,n),n)}function kr(e,t,r,n){return ke(e,t,5,k(e,t+1,n),n)}function Ar(e,t,r,n){let o=A(e,t+1,n);if(typeof o=="bigint")throw new Error(`${l} 64-bit integer string lengths not supported`);return ke(e,t,9,o,n)}var _r=se;function ae(e,t,r,n){return new c(s.array,n,r)}function Ur(e,t,r,n){return ae(e,t,1,r)}function Tr(e,t,r,n){return ae(e,t,2,v(e,t+1,n))}function Sr(e,t,r,n){return ae(e,t,3,E(e,t+1,n))}function Br(e,t,r,n){return ae(e,t,5,k(e,t+1,n))}function Ir(e,t,r,n){let o=A(e,t+1,n);if(typeof o=="bigint")throw new Error(`${l} 64-bit integer array lengths not supported`);return ae(e,t,9,o)}function Nr(e,t,r,n){if(n.allowIndefinite===!1)throw new Error(`${l} indefinite length items not allowed`);return ae(e,t,1,1/0)}function Re(e,t){b(e,s.array.majorEncoded,t.value)}Re.compareTokens=U.compareTokens;Re.encodedSize=function(t){return b.encodedSize(t.value)};function ce(e,t,r,n){return new c(s.map,n,r)}function Cr(e,t,r,n){return ce(e,t,1,r)}function Mr(e,t,r,n){return ce(e,t,2,v(e,t+1,n))}function $r(e,t,r,n){return ce(e,t,3,E(e,t+1,n))}function zr(e,t,r,n){return ce(e,t,5,k(e,t+1,n))}function Rr(e,t,r,n){let o=A(e,t+1,n);if(typeof o=="bigint")throw new Error(`${l} 64-bit integer map lengths not supported`);return ce(e,t,9,o)}function Or(e,t,r,n){if(n.allowIndefinite===!1)throw new Error(`${l} indefinite length items not allowed`);return ce(e,t,1,1/0)}function Oe(e,t){b(e,s.map.majorEncoded,t.value)}Oe.compareTokens=U.compareTokens;Oe.encodedSize=function(t){return b.encodedSize(t.value)};function Lr(e,t,r,n){return new c(s.tag,r,1)}function Dr(e,t,r,n){return new c(s.tag,v(e,t+1,n),2)}function Fr(e,t,r,n){return new c(s.tag,E(e,t+1,n),3)}function Vr(e,t,r,n){return new c(s.tag,k(e,t+1,n),5)}function Hr(e,t,r,n){return new c(s.tag,A(e,t+1,n),9)}function Le(e,t){b(e,s.tag.majorEncoded,t.value)}Le.compareTokens=U.compareTokens;Le.encodedSize=function(t){return b.encodedSize(t.value)};var No=20,Co=21,Mo=22,$o=23;function Pr(e,t,r,n){if(n.allowUndefined===!1)throw new Error(`${l} undefined values are not supported`);return n.coerceUndefinedToNull===!0?new c(s.null,null,1):new c(s.undefined,void 0,1)}function qr(e,t,r,n){if(n.allowIndefinite===!1)throw new Error(`${l} indefinite length items not allowed`);return new c(s.break,void 0,1)}function at(e,t,r){if(r){if(r.allowNaN===!1&&Number.isNaN(e))throw new Error(`${l} NaN values are not supported`);if(r.allowInfinity===!1&&(e===1/0||e===-1/0))throw new Error(`${l} Infinity values are not supported`)}return new c(s.float,e,t)}function Gr(e,t,r,n){return at(ct(e,t+1),3,n)}function jr(e,t,r,n){return at(ut(e,t+1),5,n)}function Jr(e,t,r,n){return at(Qr(e,t+1),9,n)}function De(e,t,r){let n=t.value;if(n===!1)e.push([s.float.majorEncoded|No]);else if(n===!0)e.push([s.float.majorEncoded|Co]);else if(n===null)e.push([s.float.majorEncoded|Mo]);else if(n===void 0)e.push([s.float.majorEncoded|$o]);else{let o,i=!1;(!r||r.float64!==!0)&&(Xr(n),o=ct(I,1),n===o||Number.isNaN(n)?(I[0]=249,e.push(I.slice(0,3)),i=!0):(Wr(n),o=ut(I,1),n===o&&(I[0]=250,e.push(I.slice(0,5)),i=!0))),i||(zo(n),o=Qr(I,1),I[0]=251,e.push(I.slice(0,9)))}}De.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){Xr(n);let o=ct(I,1);if(n===o||Number.isNaN(n))return 3;if(Wr(n),o=ut(I,1),n===o)return 5}return 9};var Kr=new ArrayBuffer(9),T=new DataView(Kr,1),I=new Uint8Array(Kr,0);function Xr(e){if(e===1/0)T.setUint16(0,31744,!1);else if(e===-1/0)T.setUint16(0,64512,!1);else if(Number.isNaN(e))T.setUint16(0,32256,!1);else{T.setFloat32(0,e);let t=T.getUint32(0),r=(t&2139095040)>>23,n=t&8388607;if(r===255)T.setUint16(0,31744,!1);else if(r===0)T.setUint16(0,(e&2147483648)>>16|n>>13,!1);else{let o=r-127;o<-24?T.setUint16(0,0):o<-14?T.setUint16(0,(t&2147483648)>>16|1<<24+o,!1):T.setUint16(0,(t&2147483648)>>16|o+15<<10|n>>13,!1)}}}function ct(e,t){if(e.length-t<2)throw new Error(`${l} not enough data for float16`);let r=(e[t]<<8)+e[t+1];if(r===31744)return 1/0;if(r===64512)return-1/0;if(r===32256)return NaN;let n=r>>10&31,o=r&1023,i;return n===0?i=o*2**-24:n!==31?i=(o+1024)*2**(n-25):i=o===0?1/0:NaN,r&32768?-i:i}function Wr(e){T.setFloat32(0,e,!1)}function ut(e,t){if(e.length-t<4)throw new Error(`${l} not enough data for float32`);let r=(e.byteOffset||0)+t;return new DataView(e.buffer,r,4).getFloat32(0,!1)}function zo(e){T.setFloat64(0,e,!1)}function Qr(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)}De.compareTokens=U.compareTokens;function y(e,t,r){throw new Error(`${l} encountered invalid minor (${r}) for major ${e[t]>>>5}`)}function Fe(e){return()=>{throw new Error(`${l} ${e}`)}}var u=[];for(let e=0;e<=23;e++)u[e]=y;u[24]=sr;u[25]=ar;u[26]=cr;u[27]=ur;u[28]=y;u[29]=y;u[30]=y;u[31]=y;for(let e=32;e<=55;e++)u[e]=y;u[56]=dr;u[57]=fr;u[58]=lr;u[59]=pr;u[60]=y;u[61]=y;u[62]=y;u[63]=y;for(let e=64;e<=87;e++)u[e]=yr;u[88]=mr;u[89]=wr;u[90]=gr;u[91]=br;u[92]=y;u[93]=y;u[94]=y;u[95]=Fe("indefinite length bytes/strings are not supported");for(let e=96;e<=119;e++)u[e]=xr;u[120]=vr;u[121]=Er;u[122]=kr;u[123]=Ar;u[124]=y;u[125]=y;u[126]=y;u[127]=Fe("indefinite length bytes/strings are not supported");for(let e=128;e<=151;e++)u[e]=Ur;u[152]=Tr;u[153]=Sr;u[154]=Br;u[155]=Ir;u[156]=y;u[157]=y;u[158]=y;u[159]=Nr;for(let e=160;e<=183;e++)u[e]=Cr;u[184]=Mr;u[185]=$r;u[186]=zr;u[187]=Rr;u[188]=y;u[189]=y;u[190]=y;u[191]=Or;for(let e=192;e<=215;e++)u[e]=Lr;u[216]=Dr;u[217]=Fr;u[218]=Vr;u[219]=Hr;u[220]=y;u[221]=y;u[222]=y;u[223]=y;for(let e=224;e<=243;e++)u[e]=Fe("simple values are not supported");u[244]=y;u[245]=y;u[246]=y;u[247]=Pr;u[248]=Fe("simple values are not supported");u[249]=Gr;u[250]=jr;u[251]=Jr;u[252]=y;u[253]=y;u[254]=y;u[255]=qr;var N=[];for(let e=0;e<24;e++)N[e]=new c(s.uint,e,1);for(let e=-1;e>=-24;e--)N[31-e]=new c(s.negint,e,1);N[64]=new c(s.bytes,new Uint8Array(0),1);N[96]=new c(s.string,"",1);N[128]=new c(s.array,0,1);N[160]=new c(s.map,0,1);N[244]=new c(s.false,!1,1);N[245]=new c(s.true,!0,1);N[246]=new c(s.null,null,1);function Ve(e){switch(e.type){case s.false:return R([244]);case s.true:return R([245]);case s.null:return R([246]);case s.bytes:return e.value.length?void 0:R([64]);case s.string:return e.value===""?R([96]):void 0;case s.array:return e.value===0?R([128]):void 0;case s.map:return e.value===0?R([160]):void 0;case s.uint:return e.value<24?R([Number(e.value)]):void 0;case s.negint:if(e.value>=-24)return R([31-Number(e.value)])}}var Oo={float64:!1,mapSorter:Do,quickEncodeToken:Ve};function ft(){let e=[];return e[s.uint.major]=U,e[s.negint.major]=$e,e[s.bytes.major]=se,e[s.string.major]=_r,e[s.array.major]=Re,e[s.map.major]=Oe,e[s.tag.major]=Le,e[s.float.major]=De,e}var Yr=ft(),dt=new xe,ue=class{constructor(t,r){this.obj=t,this.parent=r}includes(t){let r=this;do if(r.obj===t)return!0;while(r=r.parent);return!1}static createCheck(t,r){if(t&&t.includes(r))throw new Error(`${it} object contains circular references`);return new ue(r,t)}},V={null:new c(s.null,null),undefined:new c(s.undefined,void 0),true:new c(s.true,!0),false:new c(s.false,!1),emptyArray:new c(s.array,0),emptyMap:new c(s.map,0)},H={number(e,t,r,n){return!Number.isInteger(e)||!Number.isSafeInteger(e)?new c(s.float,e):e>=0?new c(s.uint,e):new c(s.negint,e)},bigint(e,t,r,n){return e>=BigInt(0)?new c(s.uint,e):new c(s.negint,e)},Uint8Array(e,t,r,n){return new c(s.bytes,e)},string(e,t,r,n){return new c(s.string,e)},boolean(e,t,r,n){return e?V.true:V.false},null(e,t,r,n){return V.null},undefined(e,t,r,n){return V.undefined},ArrayBuffer(e,t,r,n){return new c(s.bytes,new Uint8Array(e))},DataView(e,t,r,n){return new c(s.bytes,new Uint8Array(e.buffer,e.byteOffset,e.byteLength))},Array(e,t,r,n){if(!e.length)return r.addBreakTokens===!0?[V.emptyArray,new c(s.break)]:V.emptyArray;n=ue.createCheck(n,e);let o=[],i=0;for(let a of e)o[i++]=Ae(a,r,n);return r.addBreakTokens?[new c(s.array,e.length),o,new c(s.break)]:[new c(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?[V.emptyMap,new c(s.break)]:V.emptyMap;n=ue.createCheck(n,e);let d=[],f=0;for(let h of i)d[f++]=[Ae(h,r,n),Ae(o?e.get(h):e[h],r,n)];return Lo(d,r),r.addBreakTokens?[new c(s.map,a),d,new c(s.break)]:[new c(s.map,a),d]}};H.Map=H.Object;H.Buffer=H.Uint8Array;for(let e of"Uint8Clamped Uint16 Uint32 Int8 Int16 Int32 BigUint64 BigInt64 Float32 Float64".split(" "))H[`${e}Array`]=H.DataView;function Ae(e,t={},r){let n=Qt(e),o=t&&t.typeEncoders&&t.typeEncoders[n]||H[n];if(typeof o=="function"){let a=o(e,n,t,r);if(a!=null)return a}let i=H[n];if(!i)throw new Error(`${it} unsupported type: ${n}`);return i(e,n,t,r)}function Lo(e,t){t.mapSorter&&e.sort(t.mapSorter)}function Do(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=Yr[o].compareTokens(r,n);return i===0&&console.warn("WARNING: complex key types used, CBOR key sorting guarantees are gone"),i}function Zr(e,t,r,n){if(Array.isArray(t))for(let o of t)Zr(e,o,r,n);else r[t.type.major](e,t,n)}function Fo(e,t,r){let n=Ae(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),d=new xe(a);if(i(d,n,r),d.chunks.length!==1)throw new Error(`Unexpected error: pre-calculated length for ${n} was wrong`);return ot(d.chunks[0])}}return dt.reset(),Zr(dt,n,t,r),dt.toBytes(!0)}function lt(e,t){return t=Object.assign({},Oo,t),Fo(e,Yr,t)}var Vo={strict:!1,allowIndefinite:!0,allowUndefined:!0,allowBigInt:!0},ht=class{constructor(t,r={}){this.pos=0,this.data=t,this.options=r}done(){return this.pos>=this.data.length}next(){let t=this.data[this.pos],r=N[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}},_e=Symbol.for("DONE"),He=Symbol.for("BREAK");function Ho(e,t,r){let n=[];for(let o=0;o<e.value;o++){let i=Ue(t,r);if(i===He){if(e.value===1/0)break;throw new Error(`${l} got unexpected break to lengthed array`)}if(i===_e)throw new Error(`${l} found array but not enough entries (got ${o}, expected ${e.value})`);n[o]=i}return n}function Po(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 d=Ue(t,r);if(d===He){if(e.value===1/0)break;throw new Error(`${l} got unexpected break to lengthed map`)}if(d===_e)throw new Error(`${l} found map but not enough entries (got ${a} [no key], expected ${e.value})`);if(n!==!0&&typeof d!="string")throw new Error(`${l} non-string keys not supported (got ${typeof d})`);if(r.rejectDuplicateMapKeys===!0&&(n&&i.has(d)||!n&&d in o))throw new Error(`${l} found repeat map key "${d}"`);let f=Ue(t,r);if(f===_e)throw new Error(`${l} found map but not enough entries (got ${a} [no value], expected ${e.value})`);n?i.set(d,f):o[d]=f}return n?i:o}function Ue(e,t){if(e.done())return _e;let r=e.next();if(r.type===s.break)return He;if(r.type.terminal)return r.value;if(r.type===s.array)return Ho(r,e,t);if(r.type===s.map)return Po(r,e,t);if(r.type===s.tag){if(t.tags&&typeof t.tags[r.value]=="function"){let n=Ue(e,t);return t.tags[r.value](n)}throw new Error(`${l} tag not supported (${r.value})`)}throw new Error("unsupported")}function pt(e,t){if(!(e instanceof Uint8Array))throw new Error(`${l} data to decode must be a Uint8Array`);t=Object.assign({},Vo,t);let r=t.tokenizer||new ht(e,t),n=Ue(r,t);if(n===_e)throw new Error(`${l} did not find any content to decode`);if(n===He)throw new Error(`${l} got unexpected break`);if(!r.done())throw new Error(`${l} too many terminals, data makes no sense`);return n}var en=42;function Go(e){if(e.asCID!==e&&e["/"]!==e.bytes)return null;let t=m.asCID(e);if(!t)return null;let r=new Uint8Array(t.bytes.byteLength+1);return r.set(t.bytes,1),[new c(s.tag,en),new c(s.bytes,r)]}function jo(){throw new Error("`undefined` is not supported by the IPLD Data Model and cannot be encoded")}function Jo(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 Ko={float64:!0,typeEncoders:{Object:Go,undefined:jo,number:Jo}};function Xo(e){if(e[0]!==0)throw new Error("Invalid CID for CBOR tag 42; expected leading 0x00");return m.decode(e.subarray(1))}var tn={allowIndefinite:!1,coerceUndefinedToNull:!0,allowNaN:!1,allowInfinity:!1,allowBigInt:!0,strict:!0,useMaps:!1,rejectDuplicateMapKeys:!0,tags:[]};tn.tags[en]=Xo;var Pe=e=>lt(e,Ko),rn=e=>pt(e,tn);var P={Null:e=>e===null,Int:e=>Number.isInteger(e),Float:e=>typeof e=="number"&&Number.isFinite(e),String:e=>typeof e=="string",Bool:e=>typeof e=="boolean",Bytes:e=>e instanceof Uint8Array,Link:e=>!P.Null(e)&&typeof e=="object"&&e.asCID===e,List:e=>Array.isArray(e),Map:e=>!P.Null(e)&&typeof e=="object"&&e.asCID!==e&&!P.List(e)&&!P.Bytes(e)},de={Int:P.Int,"CarHeader > version":e=>de.Int(e),"CarHeader > roots (anon) > valueType (anon)":P.Link,"CarHeader > roots (anon)":e=>P.List(e)&&Array.prototype.every.call(e,de["CarHeader > roots (anon) > valueType (anon)"]),"CarHeader > roots":e=>de["CarHeader > roots (anon)"](e),CarHeader:e=>{let t=e&&Object.keys(e);return P.Map(e)&&["version"].every(r=>t.includes(r))&&Object.entries(e).every(([r,n])=>de["CarHeader > "+r]&&de["CarHeader > "+r](n))}},nn=de.CarHeader;var yt={SHA2_256:18,LENGTH:32,DAG_PB:112},on=16+8+8+8;async function qe(e){let t=await e.upTo(8);if(!t.length)throw new Error("Unexpected end of data");let r=q.default.decode(t);return e.seek(q.default.decode.bytes),r}async function Qo(e){let t=await e.exactly(on),r=new DataView(t.buffer,t.byteOffset,t.byteLength),n=0,o={version:2,characteristics:[r.getBigUint64(n,!0),r.getBigUint64(n+=8,!0)],dataOffset:Number(r.getBigUint64(n+=8,!0)),dataSize:Number(r.getBigUint64(n+=8,!0)),indexOffset:Number(r.getBigUint64(n+=8,!0))};return e.seek(on),o}async function Ge(e,t){let r=await qe(e);if(r===0)throw new Error("Invalid CAR header (zero length)");let n=await e.exactly(r);e.seek(r);let o=rn(n);if(!nn(o))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})`:""}`);let i=Array.isArray(o.roots);if(o.version===1&&!i||o.version===2&&i)throw new Error("Invalid CAR header format");if(o.version===1)return o;let a=await Qo(e);e.seek(a.dataOffset-e.pos);let d=await Ge(e,1);return Object.assign(d,a)}async function Yo(e){let t=await e.upTo(8);q.default.decode(t);let r=q.default.decode.bytes,n=q.default.decode(t.subarray(q.default.decode.bytes)),o=q.default.decode.bytes,i=r+o+n,a=await e.exactly(i);return e.seek(i),a}async function Zo(e){let t=await e.exactly(2);if(t[0]===yt.SHA2_256&&t[1]===yt.LENGTH){let a=await e.exactly(34);e.seek(34);let d=we(a);return m.create(0,yt.DAG_PB,d)}let r=await qe(e);if(r!==1)throw new Error(`Unexpected CID version (${r})`);let n=await qe(e),o=await Yo(e),i=we(o);return m.create(r,n,i)}async function sn(e){let t=e.pos,r=await qe(e);if(r===0)throw new Error("Invalid CAR section (zero length)");r+=e.pos-t;let n=await Zo(e),o=r-Number(e.pos-t);return{cid:n,length:r,blockLength:o}}async function ei(e){let{cid:t,blockLength:r}=await sn(e),n=await e.exactly(r);return e.seek(r),{bytes:n,cid:t}}async function ti(e){let t=e.pos,{cid:r,length:n,blockLength:o}=await sn(e),i={cid:r,length:n,blockLength:o,offset:t,blockOffset:e.pos};return e.seek(i.blockLength),i}function fe(e){let t=(async()=>{let r=await Ge(e);if(r.version===2){let n=e.pos-r.dataOffset;e=ni(e,r.dataSize-n)}return r})();return{header:()=>t,async*blocks(){for(await t;(await e.upTo(8)).length>0;)yield await ei(e)},async*blocksIndex(){for(await t;(await e.upTo(8)).length>0;)yield await ti(e)}}}function G(e){let t=0;return{async upTo(r){return e.subarray(t,t+Math.min(r,e.length-t))},async exactly(r){if(r>e.length-t)throw new Error("Unexpected end of data");return e.subarray(t,t+r)},seek(r){t+=r},get pos(){return t}}}function ri(e){let t=0,r=0,n=0,o=new Uint8Array(0),i=async a=>{r=o.length-n;let d=[o.subarray(n)];for(;r<a;){let h=await e();if(h==null)break;r<0?h.length>r&&d.push(h.subarray(-r)):d.push(h),r+=h.length}o=new Uint8Array(d.reduce((h,p)=>h+p.length,0));let f=0;for(let h of d)o.set(h,f),f+=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){if(o.length-n<a&&await i(a),o.length-n<a)throw new Error("Unexpected end of data");return o.subarray(n,n+a)},seek(a){t+=a,n+=a},get pos(){return t}}}function le(e){let t=e[Symbol.asyncIterator]();async function r(){let n=await t.next();return n.done?null:n.value}return ri(r)}function ni(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){let o=await e.exactly(n);if(o.length+r>t)throw new Error("Unexpected end of data");return o},seek(n){r+=n,e.seek(n)},get pos(){return e.pos}}}var K=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 an(G(t))}static async fromIterable(t){if(!t||typeof t[Symbol.asyncIterator]!="function")throw new TypeError("fromIterable() requires an async iterable");return an(le(t))}};async function an(e){let t=fe(e),r=await t.header(),n=[];for await(let o of t.blocks())n.push(o);return new K(r,n)}var X=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 cn(G(t))}static async fromIterable(t){if(!t||typeof t[Symbol.asyncIterator]!="function")throw new TypeError("fromIterable() requires an async iterable");return cn(le(t))}};async function cn(e){let t=fe(e),{version:r,roots:n}=await t.header();return new X(r,n,t.blocksIndex())}var je=class{constructor(t,r,n){this._version=t,this._roots=r,this._iterable=n,this._decoded=!1}get version(){return this._version}async getRoots(){return this._roots}},W=class extends je{[Symbol.asyncIterator](){if(this._decoded)throw new Error("Cannot decode more than once");if(!this._iterable)throw new Error("Block iterable not found");return this._decoded=!0,this._iterable[Symbol.asyncIterator]()}static async fromBytes(t){let{version:r,roots:n,iterator:o}=await un(t);return new W(r,n,o)}static async fromIterable(t){let{version:r,roots:n,iterator:o}=await dn(t);return new W(r,n,o)}},Q=class extends je{[Symbol.asyncIterator](){if(this._decoded)throw new Error("Cannot decode more than once");if(!this._iterable)throw new Error("Block iterable not found");this._decoded=!0;let t=this._iterable[Symbol.asyncIterator]();return{async next(){let r=await t.next();return r.done?r:{done:!1,value:r.value.cid}}}}static async fromBytes(t){let{version:r,roots:n,iterator:o}=await un(t);return new Q(r,n,o)}static async fromIterable(t){let{version:r,roots:n,iterator:o}=await dn(t);return new Q(r,n,o)}};async function un(e){if(!(e instanceof Uint8Array))throw new TypeError("fromBytes() requires a Uint8Array");return fn(G(e))}async function dn(e){if(!e||typeof e[Symbol.asyncIterator]!="function")throw new TypeError("fromIterable() requires an async iterable");return fn(le(e))}async function fn(e){let t=fe(e),{version:r,roots:n}=await t.header();return{version:r,roots:n,iterator:t.blocks()}}var mt=Ne(Ce(),1);function wt(e){let t=Pe({version:1,roots:e}),r=mt.default.encode(t.length),n=new Uint8Array(r.length+t.length);return n.set(r,0),n.set(t,r.length),n}function ln(e){return{async setRoots(t){let r=wt(t);await e.write(r)},async writeBlock(t){let{cid:r,bytes:n}=t;await e.write(new Uint8Array(mt.default.encode(r.bytes.length+n.length))),await e.write(r.bytes),n.length&&await e.write(n)},async close(){await e.end()}}}function Je(){}function hn(){let e=[],t=null,r=Je,n=!1,o=null,i=Je,a=()=>(t||(t=new Promise(h=>{r=()=>{t=null,r=Je,h()}})),t),d={write(h){e.push(h);let p=a();return i(),p},async end(){n=!0;let h=a();i(),await h}},f={async next(){let h=e.shift();return h?(e.length===0&&r(),{done:!1,value:h}):n?(r(),{done:!0,value:void 0}):(o||(o=new Promise(p=>{i=()=>(o=null,i=Je,p(f.next()))})),o)}};return{writer:d,iterator:f}}var Y=class{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=m.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()}static create(t){t=oi(t);let{encoder:r,iterator:n}=pn(),o=new Y(t,r),i=new Ke(n);return{writer:o,out:i}}static createAppender(){let{encoder:t,iterator:r}=pn();t.setRoots=()=>Promise.resolve();let n=new Y([],t),o=new Ke(r);return{writer:n,out:o}}static async updateRootsInBytes(t,r){let n=G(t);await Ge(n);let o=wt(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}},Ke=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 pn(){let e=hn(),{writer:t,iterator:r}=e;return{encoder:ln(t),iterator:r}}function oi(e){if(e===void 0)return[];if(!Array.isArray(e)){let r=m.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=m.asCID(r);if(!n)throw new TypeError("roots must be a single CID or an array of CIDs");t.push(n)}return t}var gt=Ne(yn(),1);var he=class{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 gt.default.promises.open(this._path,"r"));let n={cid:t,length:0,offset:0,blockLength:r.blockLength,blockOffset:r.blockOffset};return K.readRaw(this._fd,n)}async*blocks(){for(let t of this._order){let r=await this.get(m.parse(t));if(!r)throw new Error("Unexpected internal error");yield r}}async*cids(){for(let t of this._order)yield m.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 X.fromIterable((void 0).from(gt.default.createReadStream(t))),n=new Map,o=[];for await(let{cid:i,blockLength:a,blockOffset:d}of r){let f=i.toString();n.set(f,{blockLength:a,blockOffset:d}),o.push(f)}return new he(r.version,t,await r.getRoots(),n,o)}};var _t={};Ut(_t,{addBlock:()=>bn,addRoot:()=>gn,blockLength:()=>ai,calculateHeaderLength:()=>kt,close:()=>xn,createWriter:()=>fi,estimateHeaderLength:()=>di,headerLength:()=>At,resizeHeader:()=>Et});var Te=Ne(Ce(),1);var ii=ft(),si={float64:!1,quickEncodeToken:Ve};function bt(e,t=ii,r=si){if(Array.isArray(e)){let n=0;for(let o of e)n+=bt(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 vt=class{constructor(t,r){this.bytes=t,this.byteOffset=r,this.roots=[],this.headerSize=r}addRoot(t,r){return gn(this,t,r),this}write(t){return bn(this,t),this}close(t){return xn(this,t)}},gn=(e,t,r={})=>{let{resize:n=!1}=r,{bytes:o,headerSize:i,byteOffset:a,roots:d}=e;e.roots.push(t);let f=At(e);if(f>i)if(f-i+a<o.byteLength)if(n)Et(e,f);else throw d.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 d.pop(),new RangeError(`Buffer has no capacity for a new root ${t}`)},ai=({cid:e,bytes:t})=>{let r=e.bytes.byteLength+t.byteLength;return Te.default.encodingLength(r)+r},bn=(e,{cid:t,bytes:r})=>{let n=t.bytes.byteLength+r.byteLength,o=Te.default.encode(n);if(e.byteOffset+o.length+n>e.bytes.byteLength)throw new RangeError("Buffer has no capacity for this block");xt(e,o),xt(e,t.bytes),xt(e,r)},xn=(e,t={})=>{let{resize:r=!1}=t,{roots:n,bytes:o,byteOffset:i,headerSize:a}=e,d=Pe({version:1,roots:n}),f=Te.default.encode(d.length),h=f.length+d.byteLength;if(a-h===0)return wn(e,f,d),o.subarray(0,i);if(r)return Et(e,h),wn(e,f,d),o.subarray(0,e.byteOffset);throw new RangeError(`Header size was overestimated.
4
+ You can use close({ resize: true }) to resize header`)},Et=(e,t)=>{let{bytes:r,headerSize:n}=e;r.set(r.subarray(n,e.byteOffset),t),e.byteOffset+=t-n,e.headerSize=t},xt=(e,t)=>{e.bytes.set(t,e.byteOffset),e.byteOffset+=t.length},wn=({bytes:e},t,r)=>{e.set(t),e.set(r,t.length)},ci=[new c(s.map,2),new c(s.string,"version"),new c(s.uint,1),new c(s.string,"roots")],ui=new c(s.tag,42),kt=e=>{let t=[...ci];t.push(new c(s.array,e.length));for(let n of e)t.push(ui),t.push(new c(s.bytes,{length:n+1}));let r=bt(t);return Te.default.encodingLength(r)+r},At=({roots:e})=>kt(e.map(t=>t.bytes.byteLength)),di=(e,t=36)=>kt(new Array(e).fill(t)),fi=(e,t={})=>{let{roots:r=[],byteOffset:n=0,byteLength:o=e.byteLength,headerSize:i=At({roots:r})}=t,a=new Uint8Array(e,n,o),d=new vt(a,i);for(let f of r)d.addRoot(f);return d};return Tn(li);})();
5
5
  return IpldCar}));
@@ -43,7 +43,7 @@ export class CarReader implements CarReaderIface {
43
43
  * @static
44
44
  * @memberof CarReader
45
45
  * @param {Uint8Array} bytes
46
- * @returns {Promise<CarReader>} blip blop
46
+ * @returns {Promise<CarReader>}
47
47
  */
48
48
  static fromBytes(bytes: Uint8Array): Promise<CarReader>;
49
49
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ipld/car",
3
- "version": "5.0.1",
3
+ "version": "5.0.3",
4
4
  "description": "Content Addressable aRchive format reader and writer",
5
5
  "author": "Rod <rod@vagg.org> (http://r.va.gg/)",
6
6
  "license": "Apache-2.0 OR MIT",
@@ -90,6 +90,91 @@
90
90
  "sourceType": "module"
91
91
  }
92
92
  },
93
+ "release": {
94
+ "branches": [
95
+ "master"
96
+ ],
97
+ "plugins": [
98
+ [
99
+ "@semantic-release/commit-analyzer",
100
+ {
101
+ "preset": "conventionalcommits",
102
+ "releaseRules": [
103
+ {
104
+ "breaking": true,
105
+ "release": "major"
106
+ },
107
+ {
108
+ "revert": true,
109
+ "release": "patch"
110
+ },
111
+ {
112
+ "type": "feat",
113
+ "release": "minor"
114
+ },
115
+ {
116
+ "type": "fix",
117
+ "release": "patch"
118
+ },
119
+ {
120
+ "type": "docs",
121
+ "release": "patch"
122
+ },
123
+ {
124
+ "type": "test",
125
+ "release": "patch"
126
+ },
127
+ {
128
+ "type": "deps",
129
+ "release": "patch"
130
+ },
131
+ {
132
+ "scope": "no-release",
133
+ "release": false
134
+ }
135
+ ]
136
+ }
137
+ ],
138
+ [
139
+ "@semantic-release/release-notes-generator",
140
+ {
141
+ "preset": "conventionalcommits",
142
+ "presetConfig": {
143
+ "types": [
144
+ {
145
+ "type": "feat",
146
+ "section": "Features"
147
+ },
148
+ {
149
+ "type": "fix",
150
+ "section": "Bug Fixes"
151
+ },
152
+ {
153
+ "type": "chore",
154
+ "section": "Trivial Changes"
155
+ },
156
+ {
157
+ "type": "docs",
158
+ "section": "Documentation"
159
+ },
160
+ {
161
+ "type": "deps",
162
+ "section": "Dependencies"
163
+ },
164
+ {
165
+ "type": "test",
166
+ "section": "Tests"
167
+ }
168
+ ]
169
+ }
170
+ }
171
+ ],
172
+ "@semantic-release/changelog",
173
+ "@semantic-release/npm",
174
+ "@semantic-release/github",
175
+ "@semantic-release/git"
176
+ ]
177
+ },
93
178
  "scripts": {
94
179
  "clean": "aegir clean",
95
180
  "lint": "aegir lint",
@@ -108,13 +193,13 @@
108
193
  "docs": "jsdoc4readme --readme --description-only src/reader*.js src/indexed-reader.js src/iterator.js src/indexer.js src/writer*.js src/buffer-writer.js src/decoder.js"
109
194
  },
110
195
  "dependencies": {
111
- "@ipld/dag-cbor": "^8.0.0",
196
+ "@ipld/dag-cbor": "^9.0.0",
112
197
  "cborg": "^1.9.0",
113
- "multiformats": "^10.0.2",
198
+ "multiformats": "^11.0.0",
114
199
  "varint": "^6.0.0"
115
200
  },
116
201
  "devDependencies": {
117
- "@ipld/dag-pb": "^3.0.0",
202
+ "@ipld/dag-pb": "^4.0.0",
118
203
  "@ipld/garbage": "^6.0.0",
119
204
  "@types/node": "^18.0.0",
120
205
  "@types/varint": "^6.0.0",
@@ -123,14 +208,6 @@
123
208
  "aegir": "^37.5.6",
124
209
  "jsdoc4readme": "^1.4.0"
125
210
  },
126
- "directories": {
127
- "test": "test"
128
- },
129
- "standard": {
130
- "ignore": [
131
- "dist"
132
- ]
133
- },
134
211
  "browser": {
135
212
  "./src/index.js": "./src/index-browser.js",
136
213
  "./src/index-reader.js": "./src/index-reader-browser.js",
@@ -139,5 +216,13 @@
139
216
  "fs": false,
140
217
  "util": false,
141
218
  "stream": false
219
+ },
220
+ "directories": {
221
+ "test": "test"
222
+ },
223
+ "standard": {
224
+ "ignore": [
225
+ "dist"
226
+ ]
142
227
  }
143
228
  }
@@ -148,7 +148,7 @@ export class CarReader {
148
148
  * @static
149
149
  * @memberof CarReader
150
150
  * @param {Uint8Array} bytes
151
- * @returns {Promise<CarReader>} blip blop
151
+ * @returns {Promise<CarReader>}
152
152
  */
153
153
  static async fromBytes (bytes) {
154
154
  if (!(bytes instanceof Uint8Array)) {