@ipld/car 5.1.0 → 5.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.min.js CHANGED
@@ -1,5 +1,5 @@
1
1
  (function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.IpldCar = factory()}(typeof self !== 'undefined' ? self : this, function () {
2
- "use strict";var IpldCar=(()=>{var Un=Object.create;var Re=Object.defineProperty;var Sn=Object.getOwnPropertyDescriptor;var Bn=Object.getOwnPropertyNames;var In=Object.getPrototypeOf,Cn=Object.prototype.hasOwnProperty;var ge=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),Rt=(e,t)=>{for(var r in t)Re(e,r,{get:t[r],enumerable:!0})},Mt=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Bn(t))!Cn.call(e,o)&&o!==r&&Re(e,o,{get:()=>t[o],enumerable:!(n=Sn(t,o))||n.enumerable});return e};var Me=(e,t,r)=>(r=e!=null?Un(In(e)):{},Mt(t||!e||!e.__esModule?Re(r,"default",{value:e,enumerable:!0}):r,e)),Nn=e=>Mt(Re({},"__esModule",{value:!0}),e);var tn=ge((Ks,en)=>{en.exports=vt;var Zr=128,Po=127,qo=~Po,Go=Math.pow(2,31);function vt(e,t,r){if(Number.MAX_SAFE_INTEGER&&e>Number.MAX_SAFE_INTEGER)throw vt.bytes=0,new RangeError("Could not encode varint");t=t||[],r=r||0;for(var n=r;e>=Go;)t[r++]=e&255|Zr,e/=128;for(;e&qo;)t[r++]=e&255|Zr,e>>>=7;return t[r]=e|0,vt.bytes=r-n+1,t}});var on=ge((Xs,nn)=>{nn.exports=Et;var jo=128,rn=127;function Et(e,n){var r=0,n=n||0,o=0,i=n,a,c=e.length;do{if(i>=c||o>49)throw Et.bytes=0,new RangeError("Could not decode varint");a=e[i++],r+=o<28?(a&rn)<<o:(a&rn)*Math.pow(2,o),o+=7}while(a>=jo);return Et.bytes=i-n,r}});var an=ge((Qs,sn)=>{var Jo=Math.pow(2,7),Ko=Math.pow(2,14),Xo=Math.pow(2,21),Qo=Math.pow(2,28),Wo=Math.pow(2,35),Yo=Math.pow(2,42),Zo=Math.pow(2,49),ei=Math.pow(2,56),ti=Math.pow(2,63);sn.exports=function(e){return e<Jo?1:e<Ko?2:e<Xo?3:e<Qo?4:e<Wo?5:e<Yo?6:e<Zo?7:e<ei?8:e<ti?9:10}});var Ke=ge((Ws,cn)=>{cn.exports={encode:tn(),decode:on(),encodingLength:an()}});var xn=ge(()=>{});var xi={};Rt(xi,{CarBlockIterator:()=>Z,CarBufferReader:()=>me,CarBufferWriter:()=>Nt,CarCIDIterator:()=>ee,CarIndexedReader:()=>we,CarIndexer:()=>Y,CarReader:()=>W,CarWriter:()=>te});var Rn=Ot,$t=128,Mn=127,$n=~Mn,zn=Math.pow(2,31);function Ot(e,t,r){t=t||[],r=r||0;for(var n=r;e>=zn;)t[r++]=e&255|$t,e/=128;for(;e&$n;)t[r++]=e&255|$t,e>>>=7;return t[r]=e|0,Ot.bytes=r-n+1,t}var On=rt,Dn=128,zt=127;function rt(e,n){var r=0,n=n||0,o=0,i=n,a,c=e.length;do{if(i>=c)throw rt.bytes=0,new RangeError("Could not decode varint");a=e[i++],r+=o<28?(a&zt)<<o:(a&zt)*Math.pow(2,o),o+=7}while(a>=Dn);return rt.bytes=i-n,r}var Ln=Math.pow(2,7),Fn=Math.pow(2,14),Hn=Math.pow(2,21),Vn=Math.pow(2,28),Pn=Math.pow(2,35),qn=Math.pow(2,42),Gn=Math.pow(2,49),jn=Math.pow(2,56),Jn=Math.pow(2,63),Kn=function(e){return e<Ln?1:e<Fn?2:e<Hn?3:e<Vn?4:e<Pn?5:e<qn?6:e<Gn?7:e<jn?8:e<Jn?9:10},Xn={encode:Rn,decode:On,encodingLength:Kn},Qn=Xn,be=Qn;var xe=(e,t=0)=>[be.decode(e,t),be.decode.bytes],ne=(e,t,r=0)=>(be.encode(e,t,r),t),oe=e=>be.encodingLength(e);var Ai=new Uint8Array(0);var Lt=(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},ie=e=>{if(e instanceof Uint8Array&&e.constructor.name==="Uint8Array")return e;if(e instanceof ArrayBuffer)return new Uint8Array(e);if(ArrayBuffer.isView(e))return new Uint8Array(e.buffer,e.byteOffset,e.byteLength);throw new Error("Unknown type, must be binary type")};var Ft=(e,t)=>{let r=t.byteLength,n=oe(e),o=n+oe(r),i=new Uint8Array(o+r);return ne(e,i,0),ne(r,i,n),i.set(t,o),new se(e,r,t,i)},V=e=>{let t=ie(e),[r,n]=xe(t),[o,i]=xe(t.subarray(n)),a=t.subarray(n+i);if(a.byteLength!==o)throw new Error("Incorrect length");return new se(r,o,a,t)},Ht=(e,t)=>{if(e===t)return!0;{let r=t;return e.code===r.code&&e.size===r.size&&r.bytes instanceof Uint8Array&&Lt(e.bytes,r.bytes)}},se=class{constructor(t,r,n,o){this.code=t,this.size=r,this.digest=n,this.bytes=o}};function Wn(e,t){if(e.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),n=0;n<r.length;n++)r[n]=255;for(var o=0;o<e.length;o++){var i=e.charAt(o),a=i.charCodeAt(0);if(r[a]!==255)throw new TypeError(i+" is ambiguous");r[a]=o}var c=e.length,f=e.charAt(0),h=Math.log(c)/Math.log(256),y=Math.log(256)/Math.log(c);function re(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,X=0,S=0,N=w.length;S!==N&&w[S]===0;)S++,x++;for(var R=(N-S)*y+1>>>0,_=new Uint8Array(R);S!==N;){for(var M=w[S],H=0,B=R-1;(M!==0||H<X)&&B!==-1;B--,H++)M+=256*_[B]>>>0,_[B]=M%c>>>0,M=M/c>>>0;if(M!==0)throw new Error("Non-zero carry");X=H,S++}for(var D=R-X;D!==R&&_[D]===0;)D++;for(var Ne=f.repeat(x);D<R;++D)Ne+=e.charAt(_[D]);return Ne}function Ce(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 X=0,S=0;w[x]===f;)X++,x++;for(var N=(w.length-x)*h+1>>>0,R=new Uint8Array(N);w[x];){var _=r[w.charCodeAt(x)];if(_===255)return;for(var M=0,H=N-1;(_!==0||M<S)&&H!==-1;H--,M++)_+=c*R[H]>>>0,R[H]=_%256>>>0,_=_/256>>>0;if(_!==0)throw new Error("Non-zero carry");S=M,x++}if(w[x]!==" "){for(var B=N-S;B!==N&&R[B]===0;)B++;for(var D=new Uint8Array(X+(N-B)),Ne=X;B!==N;)D[Ne++]=R[B++];return D}}}function Tn(w){var x=Ce(w);if(x)return x;throw new Error(`Non-${t} character`)}return{encode:re,decodeUnsafe:Ce,decode:Tn}}var Yn=Wn,Zn=Yn,Vt=Zn;var ot=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")}},it=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 Pt(this,t)}},st=class{constructor(t){this.decoders=t}or(t){return Pt(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`)}},Pt=(e,t)=>new st({...e.decoders||{[e.prefix]:e},...t.decoders||{[t.prefix]:t}}),at=class{constructor(t,r,n,o){this.name=t,this.prefix=r,this.baseEncode=n,this.baseDecode=o,this.encoder=new ot(t,r,n),this.decoder=new it(t,r,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}},qt=({name:e,prefix:t,encode:r,decode:n})=>new at(e,t,r,n),ct=({prefix:e,name:t,alphabet:r})=>{let{encode:n,decode:o}=Vt(r,t);return qt({prefix:e,name:t,encode:n,decode:i=>ie(o(i))})},eo=(e,t,r,n)=>{let o={};for(let y=0;y<t.length;++y)o[t[y]]=y;let i=e.length;for(;e[i-1]==="=";)--i;let a=new Uint8Array(i*r/8|0),c=0,f=0,h=0;for(let y=0;y<i;++y){let re=o[e[y]];if(re===void 0)throw new SyntaxError(`Non-${n} character`);f=f<<r|re,c+=r,c>=8&&(c-=8,a[h++]=255&f>>c)}if(c>=r||255&f<<8-c)throw new SyntaxError("Unexpected end of data");return a},to=(e,t,r)=>{let n=t[t.length-1]==="=",o=(1<<r)-1,i="",a=0,c=0;for(let f=0;f<e.length;++f)for(c=c<<8|e[f],a+=8;a>r;)a-=r,i+=t[o&c>>a];if(a&&(i+=t[o&c<<r-a]),n)for(;i.length*r&7;)i+="=";return i},$=({name:e,prefix:t,bitsPerChar:r,alphabet:n})=>qt({prefix:t,name:e,encode(o){return to(o,n,r)},decode(o){return eo(o,n,r,e)}});var L=ct({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Ni=ct({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var ve=$({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),$i=$({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),zi=$({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Oi=$({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Di=$({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Li=$({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Fi=$({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Hi=$({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Vi=$({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Gt=(e,t)=>{let{bytes:r,version:n}=e;switch(n){case 0:return no(r,ut(e),t||L.encoder);default:return oo(r,ut(e),t||ve.encoder)}};var jt=new WeakMap,ut=e=>{let t=jt.get(e);if(t==null){let r=new Map;return jt.set(e,r),r}return t},p=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!==Ee)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==io)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return p.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=Ft(t,r);return p.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 p.equals(this,t)}static equals(t,r){let n=r;return n&&t.code===n.code&&t.version===n.version&&Ht(t.multihash,n.multihash)}toString(t){return Gt(this,t)}toJSON(){return{"/":Gt(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 p)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:o,multihash:i,bytes:a}=r;return new p(n,o,i,a||Jt(n,o,i.bytes))}else if(r[so]===!0){let{version:n,multihash:o,code:i}=r,a=V(o);return p.create(n,i,a)}else return null}static create(t,r,n){if(typeof r!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(t){case 0:{if(r!==Ee)throw new Error(`Version 0 CID must use dag-pb (code: ${Ee}) block encoding`);return new p(t,r,n,n.bytes)}case 1:{let o=Jt(t,r,n.bytes);return new p(t,r,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return p.create(0,Ee,t)}static createV1(t,r){return p.create(1,t,r)}static decode(t){let[r,n]=p.decodeFirst(t);if(n.length)throw new Error("Incorrect length");return r}static decodeFirst(t){let r=p.inspectBytes(t),n=r.size-r.multihashSize,o=ie(t.subarray(n,n+r.multihashSize));if(o.byteLength!==r.multihashSize)throw new Error("Incorrect length");let i=o.subarray(r.multihashSize-r.digestSize),a=new se(r.multihashCode,r.digestSize,i,o);return[r.version===0?p.createV0(a):p.createV1(r.codec,a),t.subarray(r.size)]}static inspectBytes(t){let r=0,n=()=>{let[re,Ce]=xe(t.subarray(r));return r+=Ce,re},o=n(),i=Ee;if(o===18?(o=0,r=0):i=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let a=r,c=n(),f=n(),h=r+f,y=h-a;return{version:o,codec:i,multihashCode:c,digestSize:f,multihashSize:y,size:h}}static parse(t,r){let[n,o]=ro(t,r),i=p.decode(o);if(i.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return ut(i).set(n,t),i}},ro=(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 ve.prefix:{let r=t||ve;return[ve.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)]}}},no=(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},oo=(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},Ee=112,io=18,Jt=(e,t,r)=>{let n=oe(e),o=n+oe(t),i=new Uint8Array(o+r.byteLength);return ne(e,i,0),ne(t,i,n),i.set(r,o),i},so=Symbol.for("@ipld/js-cid/CID");var ao=["string","number","bigint","symbol"],co=["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 Kt(e){if(e===null)return"null";if(e===void 0)return"undefined";if(e===!0||e===!1)return"boolean";let t=typeof e;if(ao.includes(t))return t;if(t==="function")return"Function";if(Array.isArray(e))return"Array";if(uo(e))return"Buffer";let r=fo(e);return r||"Object"}function uo(e){return e&&e.constructor&&e.constructor.isBuffer&&e.constructor.isBuffer.call(null,e)}function fo(e){let t=Object.prototype.toString.call(e).slice(8,-1);if(co.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 u=class{constructor(t,r,n){this.type=t,this.value=r,this.encodedLength=n,this.encodedBytes=void 0,this.byteValue=void 0}toString(){return`Token[${this.type}].${this.value}`}};var ae=globalThis.process&&!globalThis.process.browser&&globalThis.Buffer&&typeof globalThis.Buffer.isBuffer=="function",lo=new TextDecoder,ho=new TextEncoder;function $e(e){return ae&&globalThis.Buffer.isBuffer(e)}function dt(e){return e instanceof Uint8Array?$e(e)?new Uint8Array(e.buffer,e.byteOffset,e.byteLength):e:Uint8Array.from(e)}var Yt=ae?(e,t,r)=>r-t>64?globalThis.Buffer.from(e.subarray(t,r)).toString("utf8"):Qt(e,t,r):(e,t,r)=>r-t>64?lo.decode(e.subarray(t,r)):Qt(e,t,r),Zt=ae?e=>e.length>64?globalThis.Buffer.from(e):Xt(e):e=>e.length>64?ho.encode(e):Xt(e),z=e=>Uint8Array.from(e),ce=ae?(e,t,r)=>$e(e)?new Uint8Array(e.subarray(t,r)):e.slice(t,r):(e,t,r)=>e.slice(t,r),er=ae?(e,t)=>(e=e.map(r=>r instanceof Uint8Array?r:globalThis.Buffer.from(r)),dt(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},tr=ae?e=>globalThis.Buffer.allocUnsafe(e):e=>new Uint8Array(e);function rr(e,t){if($e(e)&&$e(t))return e.compare(t);for(let r=0;r<e.length;r++)if(e[r]!==t[r])return e[r]<t[r]?-1:1;return 0}function Xt(e,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 Qt(e,t,r){let n=[];for(;t<r;){let o=e[t],i=null,a=o>239?4:o>223?3:o>191?2:1;if(t+a<=r){let c,f,h,y;switch(a){case 1:o<128&&(i=o);break;case 2:c=e[t+1],(c&192)===128&&(y=(o&31)<<6|c&63,y>127&&(i=y));break;case 3:c=e[t+1],f=e[t+2],(c&192)===128&&(f&192)===128&&(y=(o&15)<<12|(c&63)<<6|f&63,y>2047&&(y<55296||y>57343)&&(i=y));break;case 4:c=e[t+1],f=e[t+2],h=e[t+3],(c&192)===128&&(f&192)===128&&(h&192)===128&&(y=(o&15)<<18|(c&63)<<12|(f&63)<<6|h&63,y>65535&&y<1114112&&(i=y))}}i===null?(i=65533,a=1):i>65535&&(i-=65536,n.push(i>>>10&1023|55296),i=56320|i&1023),n.push(i),t+=a}return po(n)}var Wt=4096;function po(e){let t=e.length;if(t<=Wt)return String.fromCharCode.apply(String,e);let r="",n=0;for(;n<t;)r+=String.fromCharCode.apply(String,e.slice(n,n+=Wt));return r}var yo=256,ke=class{constructor(t=yo){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=tr(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=ce(n,0,this.cursor)}else r=er(this.chunks,this.cursor);return t&&this.reset(),r}};var l="CBOR decode error:",ft="CBOR encode error:",Ae=[];Ae[23]=1;Ae[24]=2;Ae[25]=3;Ae[26]=5;Ae[27]=9;function F(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){F(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){F(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){F(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){F(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 nr(e,t,r,n){return new u(s.uint,v(e,t+1,n),2)}function or(e,t,r,n){return new u(s.uint,E(e,t+1,n),3)}function ir(e,t,r,n){return new u(s.uint,k(e,t+1,n),5)}function sr(e,t,r,n){return new u(s.uint,A(e,t+1,n),9)}function T(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`)}}T.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};T.compareTokens=function(t,r){return t.value<r.value?-1:t.value>r.value?1:0};function ar(e,t,r,n){return new u(s.negint,-1-v(e,t+1,n),2)}function cr(e,t,r,n){return new u(s.negint,-1-E(e,t+1,n),3)}function ur(e,t,r,n){return new u(s.negint,-1-k(e,t+1,n),5)}var lt=BigInt(-1),dr=BigInt(1);function fr(e,t,r,n){let o=A(e,t+1,n);if(typeof o!="bigint"){let i=-1-o;if(i>=Number.MIN_SAFE_INTEGER)return new u(s.negint,i,9)}if(n.allowBigInt!==!0)throw new Error(`${l} integers outside of the safe integer range are not supported`);return new u(s.negint,lt-BigInt(o),9)}function ze(e,t){let r=t.value,n=typeof r=="bigint"?r*lt-dr:r*-1-1;b(e,t.type.majorEncoded,n)}ze.encodedSize=function(t){let r=t.value,n=typeof r=="bigint"?r*lt-dr: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 _e(e,t,r,n){F(e,t,r+n);let o=ce(e,t+r,t+r+n);return new u(s.bytes,o,r+n)}function lr(e,t,r,n){return _e(e,t,1,r)}function hr(e,t,r,n){return _e(e,t,2,v(e,t+1,n))}function pr(e,t,r,n){return _e(e,t,3,E(e,t+1,n))}function yr(e,t,r,n){return _e(e,t,5,k(e,t+1,n))}function mr(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 _e(e,t,9,o)}function Oe(e){return e.encodedBytes===void 0&&(e.encodedBytes=e.type===s.string?Zt(e.value):e.value),e.encodedBytes}function ue(e,t){let r=Oe(t);b(e,t.type.majorEncoded,r.length),e.push(r)}ue.encodedSize=function(t){let r=Oe(t);return b.encodedSize(r.length)+r.length};ue.compareTokens=function(t,r){return wo(Oe(t),Oe(r))};function wo(e,t){return e.length<t.length?-1:e.length>t.length?1:rr(e,t)}function Te(e,t,r,n,o){let i=r+n;F(e,t,i);let a=new u(s.string,Yt(e,t+r,t+i),i);return o.retainStringBytes===!0&&(a.byteValue=ce(e,t+r,t+i)),a}function wr(e,t,r,n){return Te(e,t,1,r,n)}function gr(e,t,r,n){return Te(e,t,2,v(e,t+1,n),n)}function br(e,t,r,n){return Te(e,t,3,E(e,t+1,n),n)}function xr(e,t,r,n){return Te(e,t,5,k(e,t+1,n),n)}function vr(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 Te(e,t,9,o,n)}var Er=ue;function de(e,t,r,n){return new u(s.array,n,r)}function kr(e,t,r,n){return de(e,t,1,r)}function Ar(e,t,r,n){return de(e,t,2,v(e,t+1,n))}function _r(e,t,r,n){return de(e,t,3,E(e,t+1,n))}function Tr(e,t,r,n){return de(e,t,5,k(e,t+1,n))}function Ur(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 de(e,t,9,o)}function Sr(e,t,r,n){if(n.allowIndefinite===!1)throw new Error(`${l} indefinite length items not allowed`);return de(e,t,1,1/0)}function De(e,t){b(e,s.array.majorEncoded,t.value)}De.compareTokens=T.compareTokens;De.encodedSize=function(t){return b.encodedSize(t.value)};function fe(e,t,r,n){return new u(s.map,n,r)}function Br(e,t,r,n){return fe(e,t,1,r)}function Ir(e,t,r,n){return fe(e,t,2,v(e,t+1,n))}function Cr(e,t,r,n){return fe(e,t,3,E(e,t+1,n))}function Nr(e,t,r,n){return fe(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 fe(e,t,9,o)}function Mr(e,t,r,n){if(n.allowIndefinite===!1)throw new Error(`${l} indefinite length items not allowed`);return fe(e,t,1,1/0)}function Le(e,t){b(e,s.map.majorEncoded,t.value)}Le.compareTokens=T.compareTokens;Le.encodedSize=function(t){return b.encodedSize(t.value)};function $r(e,t,r,n){return new u(s.tag,r,1)}function zr(e,t,r,n){return new u(s.tag,v(e,t+1,n),2)}function Or(e,t,r,n){return new u(s.tag,E(e,t+1,n),3)}function Dr(e,t,r,n){return new u(s.tag,k(e,t+1,n),5)}function Lr(e,t,r,n){return new u(s.tag,A(e,t+1,n),9)}function Fe(e,t){b(e,s.tag.majorEncoded,t.value)}Fe.compareTokens=T.compareTokens;Fe.encodedSize=function(t){return b.encodedSize(t.value)};var ko=20,Ao=21,_o=22,To=23;function Fr(e,t,r,n){if(n.allowUndefined===!1)throw new Error(`${l} undefined values are not supported`);return n.coerceUndefinedToNull===!0?new u(s.null,null,1):new u(s.undefined,void 0,1)}function Hr(e,t,r,n){if(n.allowIndefinite===!1)throw new Error(`${l} indefinite length items not allowed`);return new u(s.break,void 0,1)}function ht(e,t,r){if(r){if(r.allowNaN===!1&&Number.isNaN(e))throw new Error(`${l} NaN values are not supported`);if(r.allowInfinity===!1&&(e===1/0||e===-1/0))throw new Error(`${l} Infinity values are not supported`)}return new u(s.float,e,t)}function Vr(e,t,r,n){return ht(pt(e,t+1),3,n)}function Pr(e,t,r,n){return ht(yt(e,t+1),5,n)}function qr(e,t,r,n){return ht(Kr(e,t+1),9,n)}function He(e,t,r){let n=t.value;if(n===!1)e.push([s.float.majorEncoded|ko]);else if(n===!0)e.push([s.float.majorEncoded|Ao]);else if(n===null)e.push([s.float.majorEncoded|_o]);else if(n===void 0)e.push([s.float.majorEncoded|To]);else{let o,i=!1;(!r||r.float64!==!0)&&(jr(n),o=pt(I,1),n===o||Number.isNaN(n)?(I[0]=249,e.push(I.slice(0,3)),i=!0):(Jr(n),o=yt(I,1),n===o&&(I[0]=250,e.push(I.slice(0,5)),i=!0))),i||(Uo(n),o=Kr(I,1),I[0]=251,e.push(I.slice(0,9)))}}He.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=pt(I,1);if(n===o||Number.isNaN(n))return 3;if(Jr(n),o=yt(I,1),n===o)return 5}return 9};var Gr=new ArrayBuffer(9),U=new DataView(Gr,1),I=new Uint8Array(Gr,0);function jr(e){if(e===1/0)U.setUint16(0,31744,!1);else if(e===-1/0)U.setUint16(0,64512,!1);else if(Number.isNaN(e))U.setUint16(0,32256,!1);else{U.setFloat32(0,e);let t=U.getUint32(0),r=(t&2139095040)>>23,n=t&8388607;if(r===255)U.setUint16(0,31744,!1);else if(r===0)U.setUint16(0,(e&2147483648)>>16|n>>13,!1);else{let o=r-127;o<-24?U.setUint16(0,0):o<-14?U.setUint16(0,(t&2147483648)>>16|1<<24+o,!1):U.setUint16(0,(t&2147483648)>>16|o+15<<10|n>>13,!1)}}}function pt(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 Jr(e){U.setFloat32(0,e,!1)}function yt(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 Uo(e){U.setFloat64(0,e,!1)}function Kr(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)}He.compareTokens=T.compareTokens;function m(e,t,r){throw new Error(`${l} encountered invalid minor (${r}) for major ${e[t]>>>5}`)}function Ve(e){return()=>{throw new Error(`${l} ${e}`)}}var d=[];for(let e=0;e<=23;e++)d[e]=m;d[24]=nr;d[25]=or;d[26]=ir;d[27]=sr;d[28]=m;d[29]=m;d[30]=m;d[31]=m;for(let e=32;e<=55;e++)d[e]=m;d[56]=ar;d[57]=cr;d[58]=ur;d[59]=fr;d[60]=m;d[61]=m;d[62]=m;d[63]=m;for(let e=64;e<=87;e++)d[e]=lr;d[88]=hr;d[89]=pr;d[90]=yr;d[91]=mr;d[92]=m;d[93]=m;d[94]=m;d[95]=Ve("indefinite length bytes/strings are not supported");for(let e=96;e<=119;e++)d[e]=wr;d[120]=gr;d[121]=br;d[122]=xr;d[123]=vr;d[124]=m;d[125]=m;d[126]=m;d[127]=Ve("indefinite length bytes/strings are not supported");for(let e=128;e<=151;e++)d[e]=kr;d[152]=Ar;d[153]=_r;d[154]=Tr;d[155]=Ur;d[156]=m;d[157]=m;d[158]=m;d[159]=Sr;for(let e=160;e<=183;e++)d[e]=Br;d[184]=Ir;d[185]=Cr;d[186]=Nr;d[187]=Rr;d[188]=m;d[189]=m;d[190]=m;d[191]=Mr;for(let e=192;e<=215;e++)d[e]=$r;d[216]=zr;d[217]=Or;d[218]=Dr;d[219]=Lr;d[220]=m;d[221]=m;d[222]=m;d[223]=m;for(let e=224;e<=243;e++)d[e]=Ve("simple values are not supported");d[244]=m;d[245]=m;d[246]=m;d[247]=Fr;d[248]=Ve("simple values are not supported");d[249]=Vr;d[250]=Pr;d[251]=qr;d[252]=m;d[253]=m;d[254]=m;d[255]=Hr;var C=[];for(let e=0;e<24;e++)C[e]=new u(s.uint,e,1);for(let e=-1;e>=-24;e--)C[31-e]=new u(s.negint,e,1);C[64]=new u(s.bytes,new Uint8Array(0),1);C[96]=new u(s.string,"",1);C[128]=new u(s.array,0,1);C[160]=new u(s.map,0,1);C[244]=new u(s.false,!1,1);C[245]=new u(s.true,!0,1);C[246]=new u(s.null,null,1);function Pe(e){switch(e.type){case s.false:return z([244]);case s.true:return z([245]);case s.null:return z([246]);case s.bytes:return e.value.length?void 0:z([64]);case s.string:return e.value===""?z([96]):void 0;case s.array:return e.value===0?z([128]):void 0;case s.map:return e.value===0?z([160]):void 0;case s.uint:return e.value<24?z([Number(e.value)]):void 0;case s.negint:if(e.value>=-24)return z([31-Number(e.value)])}}var Bo={float64:!1,mapSorter:Co,quickEncodeToken:Pe};function wt(){let e=[];return e[s.uint.major]=T,e[s.negint.major]=ze,e[s.bytes.major]=ue,e[s.string.major]=Er,e[s.array.major]=De,e[s.map.major]=Le,e[s.tag.major]=Fe,e[s.float.major]=He,e}var Xr=wt(),mt=new ke,le=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(`${ft} object contains circular references`);return new le(r,t)}},P={null:new u(s.null,null),undefined:new u(s.undefined,void 0),true:new u(s.true,!0),false:new u(s.false,!1),emptyArray:new u(s.array,0),emptyMap:new u(s.map,0)},q={number(e,t,r,n){return!Number.isInteger(e)||!Number.isSafeInteger(e)?new u(s.float,e):e>=0?new u(s.uint,e):new u(s.negint,e)},bigint(e,t,r,n){return e>=BigInt(0)?new u(s.uint,e):new u(s.negint,e)},Uint8Array(e,t,r,n){return new u(s.bytes,e)},string(e,t,r,n){return new u(s.string,e)},boolean(e,t,r,n){return e?P.true:P.false},null(e,t,r,n){return P.null},undefined(e,t,r,n){return P.undefined},ArrayBuffer(e,t,r,n){return new u(s.bytes,new Uint8Array(e))},DataView(e,t,r,n){return new u(s.bytes,new Uint8Array(e.buffer,e.byteOffset,e.byteLength))},Array(e,t,r,n){if(!e.length)return r.addBreakTokens===!0?[P.emptyArray,new u(s.break)]:P.emptyArray;n=le.createCheck(n,e);let o=[],i=0;for(let a of e)o[i++]=Ue(a,r,n);return r.addBreakTokens?[new u(s.array,e.length),o,new u(s.break)]:[new u(s.array,e.length),o]},Object(e,t,r,n){let o=t!=="Object",i=o?e.keys():Object.keys(e),a=o?e.size:i.length;if(!a)return r.addBreakTokens===!0?[P.emptyMap,new u(s.break)]:P.emptyMap;n=le.createCheck(n,e);let c=[],f=0;for(let h of i)c[f++]=[Ue(h,r,n),Ue(o?e.get(h):e[h],r,n)];return Io(c,r),r.addBreakTokens?[new u(s.map,a),c,new u(s.break)]:[new u(s.map,a),c]}};q.Map=q.Object;q.Buffer=q.Uint8Array;for(let e of"Uint8Clamped Uint16 Uint32 Int8 Int16 Int32 BigUint64 BigInt64 Float32 Float64".split(" "))q[`${e}Array`]=q.DataView;function Ue(e,t={},r){let n=Kt(e),o=t&&t.typeEncoders&&t.typeEncoders[n]||q[n];if(typeof o=="function"){let a=o(e,n,t,r);if(a!=null)return a}let i=q[n];if(!i)throw new Error(`${ft} unsupported type: ${n}`);return i(e,n,t,r)}function Io(e,t){t.mapSorter&&e.sort(t.mapSorter)}function Co(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=Xr[o].compareTokens(r,n);return i===0&&console.warn("WARNING: complex key types used, CBOR key sorting guarantees are gone"),i}function Qr(e,t,r,n){if(Array.isArray(t))for(let o of t)Qr(e,o,r,n);else r[t.type.major](e,t,n)}function No(e,t,r){let n=Ue(e,r);if(!Array.isArray(n)&&r.quickEncodeToken){let o=r.quickEncodeToken(n);if(o)return o;let i=t[n.type.major];if(i.encodedSize){let a=i.encodedSize(n,r),c=new ke(a);if(i(c,n,r),c.chunks.length!==1)throw new Error(`Unexpected error: pre-calculated length for ${n} was wrong`);return dt(c.chunks[0])}}return mt.reset(),Qr(mt,n,t,r),mt.toBytes(!0)}function gt(e,t){return t=Object.assign({},Bo,t),No(e,Xr,t)}var Ro={strict:!1,allowIndefinite:!0,allowUndefined:!0,allowBigInt:!0},bt=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=C[t];if(r===void 0){let n=d[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}},Se=Symbol.for("DONE"),qe=Symbol.for("BREAK");function Mo(e,t,r){let n=[];for(let o=0;o<e.value;o++){let i=Be(t,r);if(i===qe){if(e.value===1/0)break;throw new Error(`${l} got unexpected break to lengthed array`)}if(i===Se)throw new Error(`${l} found array but not enough entries (got ${o}, expected ${e.value})`);n[o]=i}return n}function $o(e,t,r){let n=r.useMaps===!0,o=n?void 0:{},i=n?new Map:void 0;for(let a=0;a<e.value;a++){let c=Be(t,r);if(c===qe){if(e.value===1/0)break;throw new Error(`${l} got unexpected break to lengthed map`)}if(c===Se)throw new Error(`${l} found map but not enough entries (got ${a} [no key], expected ${e.value})`);if(n!==!0&&typeof c!="string")throw new Error(`${l} non-string keys not supported (got ${typeof c})`);if(r.rejectDuplicateMapKeys===!0&&(n&&i.has(c)||!n&&c in o))throw new Error(`${l} found repeat map key "${c}"`);let f=Be(t,r);if(f===Se)throw new Error(`${l} found map but not enough entries (got ${a} [no value], expected ${e.value})`);n?i.set(c,f):o[c]=f}return n?i:o}function Be(e,t){if(e.done())return Se;let r=e.next();if(r.type===s.break)return qe;if(r.type.terminal)return r.value;if(r.type===s.array)return Mo(r,e,t);if(r.type===s.map)return $o(r,e,t);if(r.type===s.tag){if(t.tags&&typeof t.tags[r.value]=="function"){let n=Be(e,t);return t.tags[r.value](n)}throw new Error(`${l} tag not supported (${r.value})`)}throw new Error("unsupported")}function xt(e,t){if(!(e instanceof Uint8Array))throw new Error(`${l} data to decode must be a Uint8Array`);t=Object.assign({},Ro,t);let r=t.tokenizer||new bt(e,t),n=Be(r,t);if(n===Se)throw new Error(`${l} did not find any content to decode`);if(n===qe)throw new Error(`${l} got unexpected break`);if(!r.done())throw new Error(`${l} too many terminals, data makes no sense`);return n}var Wr=42;function Oo(e){if(e.asCID!==e&&e["/"]!==e.bytes)return null;let t=p.asCID(e);if(!t)return null;let r=new Uint8Array(t.bytes.byteLength+1);return r.set(t.bytes,1),[new u(s.tag,Wr),new u(s.bytes,r)]}function Do(){throw new Error("`undefined` is not supported by the IPLD Data Model and cannot be encoded")}function Lo(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 Fo={float64:!0,typeEncoders:{Object:Oo,undefined:Do,number:Lo}};function Ho(e){if(e[0]!==0)throw new Error("Invalid CID for CBOR tag 42; expected leading 0x00");return p.decode(e.subarray(1))}var Yr={allowIndefinite:!1,coerceUndefinedToNull:!0,allowNaN:!1,allowInfinity:!1,allowBigInt:!0,strict:!0,useMaps:!1,rejectDuplicateMapKeys:!0,tags:[]};Yr.tags[Wr]=Ho;var Ge=e=>gt(e,Fo),je=e=>xt(e,Yr);var G={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=>!G.Null(e)&&typeof e=="object"&&e.asCID===e,List:e=>Array.isArray(e),Map:e=>!G.Null(e)&&typeof e=="object"&&e.asCID!==e&&!G.List(e)&&!G.Bytes(e)},he={Int:G.Int,"CarHeader > version":e=>he.Int(e),"CarHeader > roots (anon) > valueType (anon)":G.Link,"CarHeader > roots (anon)":e=>G.List(e)&&Array.prototype.every.call(e,he["CarHeader > roots (anon) > valueType (anon)"]),"CarHeader > roots":e=>he["CarHeader > roots (anon)"](e),CarHeader:e=>{let t=e&&Object.keys(e);return G.Map(e)&&["version"].every(r=>t.includes(r))&&Object.entries(e).every(([r,n])=>he["CarHeader > "+r]&&he["CarHeader > "+r](n))}},Je=he.CarHeader;var j=Me(Ke(),1),J={SHA2_256:18,LENGTH:32,DAG_PB:112},Xe=16+8+8+8;function O(e,t){if(!e.length)throw new Error("Unexpected end of data");let r=j.default.decode(e);return t.seek(j.default.decode.bytes),r}function Qe(e){let t=new DataView(e.buffer,e.byteOffset,e.byteLength),r=0;return{version:2,characteristics:[t.getBigUint64(r,!0),t.getBigUint64(r+=8,!0)],dataOffset:Number(t.getBigUint64(r+=8,!0)),dataSize:Number(t.getBigUint64(r+=8,!0)),indexOffset:Number(t.getBigUint64(r+=8,!0))}}function We(e){j.default.decode(e);let t=j.default.decode.bytes,r=j.default.decode(e.subarray(j.default.decode.bytes)),n=j.default.decode.bytes;return t+n+r}async function Ye(e,t){let r=O(await e.upTo(8),e);if(r===0)throw new Error("Invalid CAR header (zero length)");let n=await e.exactly(r,!0),o=je(n);if(!Je(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=Qe(await e.exactly(Xe,!0));e.seek(a.dataOffset-e.pos);let c=await Ye(e,1);return Object.assign(c,a)}async function ri(e){let t=await e.exactly(2,!1);if(t[0]===J.SHA2_256&&t[1]===J.LENGTH){let a=await e.exactly(34,!0),c=V(a);return p.create(0,J.DAG_PB,c)}let r=O(await e.upTo(8),e);if(r!==1)throw new Error(`Unexpected CID version (${r})`);let n=O(await e.upTo(8),e),o=await e.exactly(We(await e.upTo(8)),!0),i=V(o);return p.create(r,n,i)}async function un(e){let t=e.pos,r=O(await e.upTo(8),e);if(r===0)throw new Error("Invalid CAR section (zero length)");r+=e.pos-t;let n=await ri(e),o=r-Number(e.pos-t);return{cid:n,length:r,blockLength:o}}async function ni(e){let{cid:t,blockLength:r}=await un(e);return{bytes:await e.exactly(r,!0),cid:t}}async function oi(e){let t=e.pos,{cid:r,length:n,blockLength:o}=await un(e),i={cid:r,length:n,blockLength:o,offset:t,blockOffset:e.pos};return e.seek(i.blockLength),i}function pe(e){let t=(async()=>{let r=await Ye(e);if(r.version===2){let n=e.pos-r.dataOffset;e=si(e,r.dataSize-n)}return r})();return{header:()=>t,async*blocks(){for(await t;(await e.upTo(8)).length>0;)yield await ni(e)},async*blocksIndex(){for(await t;(await e.upTo(8)).length>0;)yield await oi(e)}}}function K(e){let t=0;return{async upTo(r){return e.subarray(t,t+Math.min(r,e.length-t))},async exactly(r,n=!1){if(r>e.length-t)throw new Error("Unexpected end of data");let o=e.subarray(t,t+r);return n&&(t+=r),o},seek(r){t+=r},get pos(){return t}}}function ii(e){let t=0,r=0,n=0,o=new Uint8Array(0),i=async a=>{r=o.length-n;let c=[o.subarray(n)];for(;r<a;){let h=await e();if(h==null)break;r<0?h.length>r&&c.push(h.subarray(-r)):c.push(h),r+=h.length}o=new Uint8Array(c.reduce((h,y)=>h+y.length,0));let f=0;for(let h of c)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,c=!1){if(o.length-n<a&&await i(a),o.length-n<a)throw new Error("Unexpected end of data");let f=o.subarray(n,n+a);return c&&(t+=a,n+=a),f},seek(a){t+=a,n+=a},get pos(){return t}}}function ye(e){let t=e[Symbol.asyncIterator]();async function r(){let n=await t.next();return n.done?null:n.value}return ii(r)}function si(e,t){let r=0;return{async upTo(n){let o=await e.upTo(n);return o.length+r>t&&(o=o.subarray(0,t-r)),o},async exactly(n,o=!1){let i=await e.exactly(n,o);if(i.length+r>t)throw new Error("Unexpected end of data");return o&&(r+=n),i},seek(n){r+=n,e.seek(n)},get pos(){return e.pos}}}var W=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 dn(K(t))}static async fromIterable(t){if(!t||typeof t[Symbol.asyncIterator]!="function")throw new TypeError("fromIterable() requires an async iterable");return dn(ye(t))}};async function dn(e){let t=pe(e),r=await t.header(),n=[];for await(let o of t.blocks())n.push(o);return new W(r,n)}function fn(e,t){let r=O(e.upTo(8),e);if(r===0)throw new Error("Invalid CAR header (zero length)");let n=e.exactly(r,!0),o=je(n);if(!Je(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=Qe(e.exactly(Xe,!0));e.seek(a.dataOffset-e.pos);let c=fn(e,1);return Object.assign(c,a)}function ai(e){let t=e.exactly(2,!1);if(t[0]===J.SHA2_256&&t[1]===J.LENGTH){let a=e.exactly(34,!0),c=V(a);return p.create(0,J.DAG_PB,c)}let r=O(e.upTo(8),e);if(r!==1)throw new Error(`Unexpected CID version (${r})`);let n=O(e.upTo(8),e),o=e.exactly(We(e.upTo(8)),!0),i=V(o);return p.create(r,n,i)}function ci(e){let t=e.pos,r=O(e.upTo(8),e);if(r===0)throw new Error("Invalid CAR section (zero length)");r+=e.pos-t;let n=ai(e),o=r-Number(e.pos-t);return{cid:n,length:r,blockLength:o}}function ln(e){let t=ui(e),r=fn(t);if(r.version===2){let o=t.pos-r.dataOffset;t=di(t,r.dataSize-o)}let n=[];for(;t.upTo(8).length>0;){let{cid:o,blockLength:i}=ci(t);n.push({cid:o,bytes:t.exactly(i,!0)})}return{header:r,blocks:n}}function ui(e){let t=0;return{upTo(r){return e.subarray(t,t+Math.min(r,e.length-t))},exactly(r,n=!1){if(r>e.length-t)throw new Error("Unexpected end of data");let o=e.subarray(t,t+r);return n&&(t+=r),o},seek(r){t+=r},get pos(){return t}}}function di(e,t){let r=0;return{upTo(n){let o=e.upTo(n);return o.length+r>t&&(o=o.subarray(0,t-r)),o},exactly(n,o=!1){let i=e.exactly(n,o);if(i.length+r>t)throw new Error("Unexpected end of data");return o&&(r+=n),i},seek(n){r+=n,e.seek(n)},get pos(){return e.pos}}}var me=class{constructor(t,r){this._header=t,this._blocks=r,this._cids=void 0}get version(){return this._header.version}getRoots(){return this._header.roots}has(t){return this._blocks.some(r=>r.cid.equals(t))}get(t){return this._blocks.find(r=>r.cid.equals(t))}blocks(){return this._blocks}cids(){return this._cids||(this._cids=this._blocks.map(t=>t.cid)),this._cids}static fromBytes(t){if(!(t instanceof Uint8Array))throw new TypeError("fromBytes() requires a Uint8Array");let{header:r,blocks:n}=ln(t);return new me(r,n)}};var Y=class{constructor(t,r,n){this._version=t,this._roots=r,this._iterator=n}get version(){return this._version}async getRoots(){return this._roots}[Symbol.asyncIterator](){return this._iterator}static async fromBytes(t){if(!(t instanceof Uint8Array))throw new TypeError("fromBytes() requires a Uint8Array");return hn(K(t))}static async fromIterable(t){if(!t||typeof t[Symbol.asyncIterator]!="function")throw new TypeError("fromIterable() requires an async iterable");return hn(ye(t))}};async function hn(e){let t=pe(e),{version:r,roots:n}=await t.header();return new Y(r,n,t.blocksIndex())}var Ze=class{constructor(t,r,n){this._version=t,this._roots=r,this._iterable=n,this._decoded=!1}get version(){return this._version}async getRoots(){return this._roots}},Z=class extends Ze{[Symbol.asyncIterator](){if(this._decoded)throw new Error("Cannot decode more than once");if(!this._iterable)throw new Error("Block iterable not found");return this._decoded=!0,this._iterable[Symbol.asyncIterator]()}static async fromBytes(t){let{version:r,roots:n,iterator:o}=await pn(t);return new Z(r,n,o)}static async fromIterable(t){let{version:r,roots:n,iterator:o}=await yn(t);return new Z(r,n,o)}},ee=class extends Ze{[Symbol.asyncIterator](){if(this._decoded)throw new Error("Cannot decode more than once");if(!this._iterable)throw new Error("Block iterable not found");this._decoded=!0;let t=this._iterable[Symbol.asyncIterator]();return{async next(){let r=await t.next();return r.done?r:{done:!1,value:r.value.cid}}}}static async fromBytes(t){let{version:r,roots:n,iterator:o}=await pn(t);return new ee(r,n,o)}static async fromIterable(t){let{version:r,roots:n,iterator:o}=await yn(t);return new ee(r,n,o)}};async function pn(e){if(!(e instanceof Uint8Array))throw new TypeError("fromBytes() requires a Uint8Array");return mn(K(e))}async function yn(e){if(!e||typeof e[Symbol.asyncIterator]!="function")throw new TypeError("fromIterable() requires an async iterable");return mn(ye(e))}async function mn(e){let t=pe(e),{version:r,roots:n}=await t.header();return{version:r,roots:n,iterator:t.blocks()}}var kt=Me(Ke(),1);function At(e){let t=Ge({version:1,roots:e}),r=kt.default.encode(t.length),n=new Uint8Array(r.length+t.length);return n.set(r,0),n.set(t,r.length),n}function wn(e){return{async setRoots(t){let r=At(t);await e.write(r)},async writeBlock(t){let{cid:r,bytes:n}=t;await e.write(new Uint8Array(kt.default.encode(r.bytes.length+n.length))),await e.write(r.bytes),n.length&&await e.write(n)},async close(){await e.end()}}}function et(){}function gn(){let e=[],t=null,r=et,n=!1,o=null,i=et,a=()=>(t||(t=new Promise(h=>{r=()=>{t=null,r=et,h()}})),t),c={write(h){e.push(h);let y=a();return i(),y},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(y=>{i=()=>(o=null,i=et,y(f.next()))})),o)}};return{writer:c,iterator:f}}var te=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=p.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=li(t);let{encoder:r,iterator:n}=bn(),o=new te(t,r),i=new tt(n);return{writer:o,out:i}}static createAppender(){let{encoder:t,iterator:r}=bn();t.setRoots=()=>Promise.resolve();let n=new te([],t),o=new tt(r);return{writer:n,out:o}}static async updateRootsInBytes(t,r){let n=K(t);await Ye(n);let o=At(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}},tt=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 bn(){let e=gn(),{writer:t,iterator:r}=e;return{encoder:wn(t),iterator:r}}function li(e){if(e===void 0)return[];if(!Array.isArray(e)){let r=p.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=p.asCID(r);if(!n)throw new TypeError("roots must be a single CID or an array of CIDs");t.push(n)}return t}var _t=Me(xn(),1);var we=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 _t.default.promises.open(this._path,"r"));let n={cid:t,length:0,offset:0,blockLength:r.blockLength,blockOffset:r.blockOffset};return W.readRaw(this._fd,n)}async*blocks(){for(let t of this._order){let r=await this.get(p.parse(t));if(!r)throw new Error("Unexpected internal error");yield r}}async*cids(){for(let t of this._order)yield p.parse(t)}async close(){if(this._fd)return this._fd.close()}static async fromFile(t){if(typeof t!="string")throw new TypeError("fromFile() requires a file path string");let r=await Y.fromIterable((void 0).from(_t.default.createReadStream(t))),n=new Map,o=[];for await(let{cid:i,blockLength:a,blockOffset:c}of r){let f=i.toString();n.set(f,{blockLength:a,blockOffset:c}),o.push(f)}return new we(r.version,t,await r.getRoots(),n,o)}};var Nt={};Rt(Nt,{addBlock:()=>An,addRoot:()=>kn,blockLength:()=>yi,calculateHeaderLength:()=>It,close:()=>_n,createWriter:()=>bi,estimateHeaderLength:()=>gi,headerLength:()=>Ct,resizeHeader:()=>Bt});var Ie=Me(Ke(),1);var hi=wt(),pi={float64:!1,quickEncodeToken:Pe};function Tt(e,t=hi,r=pi){if(Array.isArray(e)){let n=0;for(let o of e)n+=Tt(o,t,r);return n}else{let n=t[e.type.major];if(n.encodedSize===void 0||typeof n.encodedSize!="function")throw new Error(`Encoder for ${e.type.name} does not have an encodedSize()`);return n.encodedSize(e,r)}}var St=class{constructor(t,r){this.bytes=t,this.byteOffset=r,this.roots=[],this.headerSize=r}addRoot(t,r){return kn(this,t,r),this}write(t){return An(this,t),this}close(t){return _n(this,t)}},kn=(e,t,r={})=>{let{resize:n=!1}=r,{bytes:o,headerSize:i,byteOffset:a,roots:c}=e;e.roots.push(t);let f=Ct(e);if(f>i)if(f-i+a<o.byteLength)if(n)Bt(e,f);else throw c.pop(),new RangeError(`Header of size ${i} has no capacity for new root ${t}.
3
- However there is a space in the buffer and you could call addRoot(root, { resize: root }) to resize header to make a space for this root.`);else throw c.pop(),new RangeError(`Buffer has no capacity for a new root ${t}`)},yi=({cid:e,bytes:t})=>{let r=e.bytes.byteLength+t.byteLength;return Ie.default.encodingLength(r)+r},An=(e,{cid:t,bytes:r})=>{let n=t.bytes.byteLength+r.byteLength,o=Ie.default.encode(n);if(e.byteOffset+o.length+n>e.bytes.byteLength)throw new RangeError("Buffer has no capacity for this block");Ut(e,o),Ut(e,t.bytes),Ut(e,r)},_n=(e,t={})=>{let{resize:r=!1}=t,{roots:n,bytes:o,byteOffset:i,headerSize:a}=e,c=Ge({version:1,roots:n}),f=Ie.default.encode(c.length),h=f.length+c.byteLength;if(a-h===0)return En(e,f,c),o.subarray(0,i);if(r)return Bt(e,h),En(e,f,c),o.subarray(0,e.byteOffset);throw new RangeError(`Header size was overestimated.
4
- You can use close({ resize: true }) to resize header`)},Bt=(e,t)=>{let{bytes:r,headerSize:n}=e;r.set(r.subarray(n,e.byteOffset),t),e.byteOffset+=t-n,e.headerSize=t},Ut=(e,t)=>{e.bytes.set(t,e.byteOffset),e.byteOffset+=t.length},En=({bytes:e},t,r)=>{e.set(t),e.set(r,t.length)},mi=[new u(s.map,2),new u(s.string,"version"),new u(s.uint,1),new u(s.string,"roots")],wi=new u(s.tag,42),It=e=>{let t=[...mi];t.push(new u(s.array,e.length));for(let n of e)t.push(wi),t.push(new u(s.bytes,{length:n+1}));let r=Tt(t);return Ie.default.encodingLength(r)+r},Ct=({roots:e})=>It(e.map(t=>t.bytes.byteLength)),gi=(e,t=36)=>It(new Array(e).fill(t)),bi=(e,t={})=>{let{roots:r=[],byteOffset:n=0,byteLength:o=e.byteLength,headerSize:i=Ct({roots:r})}=t,a=new Uint8Array(e,n,o),c=new St(a,i);for(let f of r)c.addRoot(f);return c};return Nn(xi);})();
2
+ "use strict";var IpldCar=(()=>{var Zi=Object.create;var wt=Object.defineProperty;var es=Object.getOwnPropertyDescriptor;var ts=Object.getOwnPropertyNames;var rs=Object.getPrototypeOf,ns=Object.prototype.hasOwnProperty;var Ze=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),Pr=(e,t)=>{for(var r in t)wt(e,r,{get:t[r],enumerable:!0})},Hr=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of ts(t))!ns.call(e,o)&&o!==r&&wt(e,o,{get:()=>t[o],enumerable:!(n=es(t,o))||n.enumerable});return e};var bt=(e,t,r)=>(r=e!=null?Zi(rs(e)):{},Hr(t||!e||!e.__esModule?wt(r,"default",{value:e,enumerable:!0}):r,e)),os=e=>Hr(wt({},"__esModule",{value:!0}),e);var So=Ze((jd,To)=>{To.exports=Ar;var Uo=128,qa=127,ja=~qa,Ga=Math.pow(2,31);function Ar(e,t,r){if(Number.MAX_SAFE_INTEGER&&e>Number.MAX_SAFE_INTEGER)throw Ar.bytes=0,new RangeError("Could not encode varint");t=t||[],r=r||0;for(var n=r;e>=Ga;)t[r++]=e&255|Uo,e/=128;for(;e&ja;)t[r++]=e&255|Uo,e>>>=7;return t[r]=e|0,Ar.bytes=r-n+1,t}});var Io=Ze((Gd,Bo)=>{Bo.exports=kr;var Ja=128,_o=127;function kr(e,n){var r=0,n=n||0,o=0,i=n,s,u=e.length;do{if(i>=u||o>49)throw kr.bytes=0,new RangeError("Could not decode varint");s=e[i++],r+=o<28?(s&_o)<<o:(s&_o)*Math.pow(2,o),o+=7}while(s>=Ja);return kr.bytes=i-n,r}});var Co=Ze((Jd,No)=>{var Ka=Math.pow(2,7),Xa=Math.pow(2,14),Qa=Math.pow(2,21),Wa=Math.pow(2,28),Ya=Math.pow(2,35),Za=Math.pow(2,42),ec=Math.pow(2,49),tc=Math.pow(2,56),rc=Math.pow(2,63);No.exports=function(e){return e<Ka?1:e<Xa?2:e<Qa?3:e<Wa?4:e<Ya?5:e<Za?6:e<ec?7:e<tc?8:e<rc?9:10}});var $t=Ze((Kd,$o)=>{$o.exports={encode:So(),decode:Io(),encodingLength:Co()}});var jo=Ze(()=>{});var qc={};Pr(qc,{CarBlockIterator:()=>ke,CarBufferReader:()=>je,CarBufferWriter:()=>Vr,CarCIDIterator:()=>Ue,CarIndexedReader:()=>Ge,CarIndexer:()=>Ae,CarReader:()=>Ee,CarWriter:()=>Te,contentType:()=>Hc});var is=Gr,qr=128,ss=127,as=~ss,cs=Math.pow(2,31);function Gr(e,t,r){t=t||[],r=r||0;for(var n=r;e>=cs;)t[r++]=e&255|qr,e/=128;for(;e&as;)t[r++]=e&255|qr,e>>>=7;return t[r]=e|0,Gr.bytes=r-n+1,t}var us=Yt,ds=128,jr=127;function Yt(e,n){var r=0,n=n||0,o=0,i=n,s,u=e.length;do{if(i>=u)throw Yt.bytes=0,new RangeError("Could not decode varint");s=e[i++],r+=o<28?(s&jr)<<o:(s&jr)*Math.pow(2,o),o+=7}while(s>=ds);return Yt.bytes=i-n,r}var fs=Math.pow(2,7),ls=Math.pow(2,14),hs=Math.pow(2,21),ps=Math.pow(2,28),ys=Math.pow(2,35),ms=Math.pow(2,42),gs=Math.pow(2,49),ws=Math.pow(2,56),bs=Math.pow(2,63),xs=function(e){return e<fs?1:e<ls?2:e<hs?3:e<ps?4:e<ys?5:e<ms?6:e<gs?7:e<ws?8:e<bs?9:10},vs={encode:is,decode:us,encodingLength:xs},Es=vs,et=Es;var tt=(e,t=0)=>[et.decode(e,t),et.decode.bytes],_e=(e,t,r=0)=>(et.encode(e,t,r),t),Be=e=>et.encodingLength(e);var Kc=new Uint8Array(0);var Kr=(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},Ie=e=>{if(e instanceof Uint8Array&&e.constructor.name==="Uint8Array")return e;if(e instanceof ArrayBuffer)return new Uint8Array(e);if(ArrayBuffer.isView(e))return new Uint8Array(e.buffer,e.byteOffset,e.byteLength);throw new Error("Unknown type, must be binary type")};var Xr=(e,t)=>{let r=t.byteLength,n=Be(e),o=n+Be(r),i=new Uint8Array(o+r);return _e(e,i,0),_e(r,i,n),i.set(t,o),new Ne(e,r,t,i)},le=e=>{let t=Ie(e),[r,n]=tt(t),[o,i]=tt(t.subarray(n)),s=t.subarray(n+i);if(s.byteLength!==o)throw new Error("Incorrect length");return new Ne(r,o,s,t)},Qr=(e,t)=>{if(e===t)return!0;{let r=t;return e.code===r.code&&e.size===r.size&&r.bytes instanceof Uint8Array&&Kr(e.bytes,r.bytes)}},Ne=class{constructor(t,r,n,o){this.code=t,this.size=r,this.digest=n,this.bytes=o}};function As(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),s=i.charCodeAt(0);if(r[s]!==255)throw new TypeError(i+" is ambiguous");r[s]=o}var u=e.length,h=e.charAt(0),m=Math.log(u)/Math.log(256),y=Math.log(256)/Math.log(u);function D(g){if(g instanceof Uint8Array||(ArrayBuffer.isView(g)?g=new Uint8Array(g.buffer,g.byteOffset,g.byteLength):Array.isArray(g)&&(g=Uint8Array.from(g))),!(g instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(g.length===0)return"";for(var A=0,R=0,U=0,S=g.length;U!==S&&g[U]===0;)U++,A++;for(var _=(S-U)*y+1>>>0,k=new Uint8Array(_);U!==S;){for(var B=g[U],M=0,T=_-1;(B!==0||M<R)&&T!==-1;T--,M++)B+=256*k[T]>>>0,k[T]=B%u>>>0,B=B/u>>>0;if(B!==0)throw new Error("Non-zero carry");R=M,U++}for(var N=_-R;N!==_&&k[N]===0;)N++;for(var ae=h.repeat(A);N<_;++N)ae+=e.charAt(k[N]);return ae}function se(g){if(typeof g!="string")throw new TypeError("Expected String");if(g.length===0)return new Uint8Array;var A=0;if(g[A]!==" "){for(var R=0,U=0;g[A]===h;)R++,A++;for(var S=(g.length-A)*m+1>>>0,_=new Uint8Array(S);g[A];){var k=r[g.charCodeAt(A)];if(k===255)return;for(var B=0,M=S-1;(k!==0||B<U)&&M!==-1;M--,B++)k+=u*_[M]>>>0,_[M]=k%256>>>0,k=k/256>>>0;if(k!==0)throw new Error("Non-zero carry");U=B,A++}if(g[A]!==" "){for(var T=S-U;T!==S&&_[T]===0;)T++;for(var N=new Uint8Array(R+(S-T)),ae=R;T!==S;)N[ae++]=_[T++];return N}}}function Wt(g){var A=se(g);if(A)return A;throw new Error(`Non-${t} character`)}return{encode:D,decodeUnsafe:se,decode:Wt}}var ks=As,Us=ks,Wr=Us;var er=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")}},tr=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 Yr(this,t)}},rr=class{constructor(t){this.decoders=t}or(t){return Yr(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`)}},Yr=(e,t)=>new rr({...e.decoders||{[e.prefix]:e},...t.decoders||{[t.prefix]:t}}),nr=class{constructor(t,r,n,o){this.name=t,this.prefix=r,this.baseEncode=n,this.baseDecode=o,this.encoder=new er(t,r,n),this.decoder=new tr(t,r,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}},Zr=({name:e,prefix:t,encode:r,decode:n})=>new nr(e,t,r,n),or=({prefix:e,name:t,alphabet:r})=>{let{encode:n,decode:o}=Wr(r,t);return Zr({prefix:e,name:t,encode:n,decode:i=>Ie(o(i))})},Ts=(e,t,r,n)=>{let o={};for(let y=0;y<t.length;++y)o[t[y]]=y;let i=e.length;for(;e[i-1]==="=";)--i;let s=new Uint8Array(i*r/8|0),u=0,h=0,m=0;for(let y=0;y<i;++y){let D=o[e[y]];if(D===void 0)throw new SyntaxError(`Non-${n} character`);h=h<<r|D,u+=r,u>=8&&(u-=8,s[m++]=255&h>>u)}if(u>=r||255&h<<8-u)throw new SyntaxError("Unexpected end of data");return s},Ss=(e,t,r)=>{let n=t[t.length-1]==="=",o=(1<<r)-1,i="",s=0,u=0;for(let h=0;h<e.length;++h)for(u=u<<8|e[h],s+=8;s>r;)s-=r,i+=t[o&u>>s];if(s&&(i+=t[o&u<<r-s]),n)for(;i.length*r&7;)i+="=";return i},ee=({name:e,prefix:t,bitsPerChar:r,alphabet:n})=>Zr({prefix:t,name:e,encode(o){return Ss(o,n,r)},decode(o){return Ts(o,n,r,e)}});var ce=or({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),ru=or({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var rt=ee({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),iu=ee({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),su=ee({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),au=ee({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),cu=ee({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),uu=ee({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),du=ee({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),fu=ee({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),lu=ee({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var en=(e,t)=>{let{bytes:r,version:n}=e;switch(n){case 0:return Bs(r,ir(e),t||ce.encoder);default:return Is(r,ir(e),t||rt.encoder)}};var tn=new WeakMap,ir=e=>{let t=tn.get(e);if(t==null){let r=new Map;return tn.set(e,r),r}return t},E=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!==nt)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==Ns)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return E.createV0(r)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:t,digest:r}=this.multihash,n=Xr(t,r);return E.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(t){return E.equals(this,t)}static equals(t,r){let n=r;return n&&t.code===n.code&&t.version===n.version&&Qr(t.multihash,n.multihash)}toString(t){return en(this,t)}toJSON(){return{"/":en(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 E)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:o,multihash:i,bytes:s}=r;return new E(n,o,i,s||rn(n,o,i.bytes))}else if(r[Cs]===!0){let{version:n,multihash:o,code:i}=r,s=le(o);return E.create(n,i,s)}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!==nt)throw new Error(`Version 0 CID must use dag-pb (code: ${nt}) block encoding`);return new E(t,r,n,n.bytes)}case 1:{let o=rn(t,r,n.bytes);return new E(t,r,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return E.create(0,nt,t)}static createV1(t,r){return E.create(1,t,r)}static decode(t){let[r,n]=E.decodeFirst(t);if(n.length)throw new Error("Incorrect length");return r}static decodeFirst(t){let r=E.inspectBytes(t),n=r.size-r.multihashSize,o=Ie(t.subarray(n,n+r.multihashSize));if(o.byteLength!==r.multihashSize)throw new Error("Incorrect length");let i=o.subarray(r.multihashSize-r.digestSize),s=new Ne(r.multihashCode,r.digestSize,i,o);return[r.version===0?E.createV0(s):E.createV1(r.codec,s),t.subarray(r.size)]}static inspectBytes(t){let r=0,n=()=>{let[D,se]=tt(t.subarray(r));return r+=se,D},o=n(),i=nt;if(o===18?(o=0,r=0):i=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let s=r,u=n(),h=n(),m=r+h,y=m-s;return{version:o,codec:i,multihashCode:u,digestSize:h,multihashSize:y,size:m}}static parse(t,r){let[n,o]=_s(t,r),i=E.decode(o);if(i.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return ir(i).set(n,t),i}},_s=(e,t)=>{switch(e[0]){case"Q":{let r=t||ce;return[ce.prefix,r.decode(`${ce.prefix}${e}`)]}case ce.prefix:{let r=t||ce;return[ce.prefix,r.decode(e)]}case rt.prefix:{let r=t||rt;return[rt.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)]}}},Bs=(e,t,r)=>{let{prefix:n}=r;if(n!==ce.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},Is=(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},nt=112,Ns=18,rn=(e,t,r)=>{let n=Be(e),o=n+Be(t),i=new Uint8Array(o+r.byteLength);return _e(e,i,0),_e(t,i,n),i.set(r,o),i},Cs=Symbol.for("@ipld/js-cid/CID");var $s=["string","number","bigint","symbol"],Ms=["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 nn(e){if(e===null)return"null";if(e===void 0)return"undefined";if(e===!0||e===!1)return"boolean";let t=typeof e;if($s.includes(t))return t;if(t==="function")return"Function";if(Array.isArray(e))return"Array";if(zs(e))return"Buffer";let r=Os(e);return r||"Object"}function zs(e){return e&&e.constructor&&e.constructor.isBuffer&&e.constructor.isBuffer.call(null,e)}function Os(e){let t=Object.prototype.toString.call(e).slice(8,-1);if(Ms.includes(t))return t}var c=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}};c.uint=new c(0,"uint",!0);c.negint=new c(1,"negint",!0);c.bytes=new c(2,"bytes",!0);c.string=new c(3,"string",!0);c.array=new c(4,"array",!1);c.map=new c(5,"map",!1);c.tag=new c(6,"tag",!1);c.float=new c(7,"float",!0);c.false=new c(7,"false",!0);c.true=new c(7,"true",!0);c.null=new c(7,"null",!0);c.undefined=new c(7,"undefined",!0);c.break=new c(7,"break",!0);var p=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 Ce=globalThis.process&&!globalThis.process.browser&&globalThis.Buffer&&typeof globalThis.Buffer.isBuffer=="function",Rs=new TextDecoder,Ds=new TextEncoder;function xt(e){return Ce&&globalThis.Buffer.isBuffer(e)}function sr(e){return e instanceof Uint8Array?xt(e)?new Uint8Array(e.buffer,e.byteOffset,e.byteLength):e:Uint8Array.from(e)}var cn=Ce?(e,t,r)=>r-t>64?globalThis.Buffer.from(e.subarray(t,r)).toString("utf8"):sn(e,t,r):(e,t,r)=>r-t>64?Rs.decode(e.subarray(t,r)):sn(e,t,r),un=Ce?e=>e.length>64?globalThis.Buffer.from(e):on(e):e=>e.length>64?Ds.encode(e):on(e),te=e=>Uint8Array.from(e),$e=Ce?(e,t,r)=>xt(e)?new Uint8Array(e.subarray(t,r)):e.slice(t,r):(e,t,r)=>e.slice(t,r),dn=Ce?(e,t)=>(e=e.map(r=>r instanceof Uint8Array?r:globalThis.Buffer.from(r)),sr(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},fn=Ce?e=>globalThis.Buffer.allocUnsafe(e):e=>new Uint8Array(e);function ln(e,t){if(xt(e)&&xt(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 on(e,t=1/0){let r,n=e.length,o=null,i=[];for(let s=0;s<n;++s){if(r=e.charCodeAt(s),r>55295&&r<57344){if(!o){if(r>56319){(t-=3)>-1&&i.push(239,191,189);continue}else if(s+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 sn(e,t,r){let n=[];for(;t<r;){let o=e[t],i=null,s=o>239?4:o>223?3:o>191?2:1;if(t+s<=r){let u,h,m,y;switch(s){case 1:o<128&&(i=o);break;case 2:u=e[t+1],(u&192)===128&&(y=(o&31)<<6|u&63,y>127&&(i=y));break;case 3:u=e[t+1],h=e[t+2],(u&192)===128&&(h&192)===128&&(y=(o&15)<<12|(u&63)<<6|h&63,y>2047&&(y<55296||y>57343)&&(i=y));break;case 4:u=e[t+1],h=e[t+2],m=e[t+3],(u&192)===128&&(h&192)===128&&(m&192)===128&&(y=(o&15)<<18|(u&63)<<12|(h&63)<<6|m&63,y>65535&&y<1114112&&(i=y))}}i===null?(i=65533,s=1):i>65535&&(i-=65536,n.push(i>>>10&1023|55296),i=56320|i&1023),n.push(i),t+=s}return Ls(n)}var an=4096;function Ls(e){let t=e.length;if(t<=an)return String.fromCharCode.apply(String,e);let r="",n=0;for(;n<t;)r+=String.fromCharCode.apply(String,e.slice(n,n+=an));return r}var Fs=256,ot=class{constructor(t=Fs){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=fn(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=$e(n,0,this.cursor)}else r=dn(this.chunks,this.cursor);return t&&this.reset(),r}};var w="CBOR decode error:",ar="CBOR encode error:",it=[];it[23]=1;it[24]=2;it[25]=3;it[26]=5;it[27]=9;function ue(e,t,r){if(e.length-t<r)throw new Error(`${w} not enough data for type`)}var C=[24,256,65536,4294967296,BigInt("18446744073709551616")];function L(e,t,r){ue(e,t,1);let n=e[t];if(r.strict===!0&&n<C[0])throw new Error(`${w} integer encoded in more bytes than necessary (strict decode)`);return n}function F(e,t,r){ue(e,t,2);let n=e[t]<<8|e[t+1];if(r.strict===!0&&n<C[1])throw new Error(`${w} integer encoded in more bytes than necessary (strict decode)`);return n}function V(e,t,r){ue(e,t,4);let n=e[t]*16777216+(e[t+1]<<16)+(e[t+2]<<8)+e[t+3];if(r.strict===!0&&n<C[2])throw new Error(`${w} integer encoded in more bytes than necessary (strict decode)`);return n}function P(e,t,r){ue(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<C[3])throw new Error(`${w} 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(`${w} integers outside of the safe integer range are not supported`)}function hn(e,t,r,n){return new p(c.uint,L(e,t+1,n),2)}function pn(e,t,r,n){return new p(c.uint,F(e,t+1,n),3)}function yn(e,t,r,n){return new p(c.uint,V(e,t+1,n),5)}function mn(e,t,r,n){return new p(c.uint,P(e,t+1,n),9)}function J(e,t){return z(e,0,t.value)}function z(e,t,r){if(r<C[0]){let n=Number(r);e.push([t|n])}else if(r<C[1]){let n=Number(r);e.push([t|24,n])}else if(r<C[2]){let n=Number(r);e.push([t|25,n>>>8,n&255])}else if(r<C[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<C[4]){let o=[t|27,0,0,0,0,0,0,0],i=Number(n&BigInt(4294967295)),s=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]=s&255,s=s>>8,o[3]=s&255,s=s>>8,o[2]=s&255,s=s>>8,o[1]=s&255,e.push(o)}else throw new Error(`${w} encountered BigInt larger than allowable range`)}}J.encodedSize=function(t){return z.encodedSize(t.value)};z.encodedSize=function(t){return t<C[0]?1:t<C[1]?2:t<C[2]?3:t<C[3]?5:9};J.compareTokens=function(t,r){return t.value<r.value?-1:t.value>r.value?1:0};function gn(e,t,r,n){return new p(c.negint,-1-L(e,t+1,n),2)}function wn(e,t,r,n){return new p(c.negint,-1-F(e,t+1,n),3)}function bn(e,t,r,n){return new p(c.negint,-1-V(e,t+1,n),5)}var cr=BigInt(-1),xn=BigInt(1);function vn(e,t,r,n){let o=P(e,t+1,n);if(typeof o!="bigint"){let i=-1-o;if(i>=Number.MIN_SAFE_INTEGER)return new p(c.negint,i,9)}if(n.allowBigInt!==!0)throw new Error(`${w} integers outside of the safe integer range are not supported`);return new p(c.negint,cr-BigInt(o),9)}function vt(e,t){let r=t.value,n=typeof r=="bigint"?r*cr-xn:r*-1-1;z(e,t.type.majorEncoded,n)}vt.encodedSize=function(t){let r=t.value,n=typeof r=="bigint"?r*cr-xn:r*-1-1;return n<C[0]?1:n<C[1]?2:n<C[2]?3:n<C[3]?5:9};vt.compareTokens=function(t,r){return t.value<r.value?1:t.value>r.value?-1:0};function st(e,t,r,n){ue(e,t,r+n);let o=$e(e,t+r,t+r+n);return new p(c.bytes,o,r+n)}function En(e,t,r,n){return st(e,t,1,r)}function An(e,t,r,n){return st(e,t,2,L(e,t+1,n))}function kn(e,t,r,n){return st(e,t,3,F(e,t+1,n))}function Un(e,t,r,n){return st(e,t,5,V(e,t+1,n))}function Tn(e,t,r,n){let o=P(e,t+1,n);if(typeof o=="bigint")throw new Error(`${w} 64-bit integer bytes lengths not supported`);return st(e,t,9,o)}function Et(e){return e.encodedBytes===void 0&&(e.encodedBytes=e.type===c.string?un(e.value):e.value),e.encodedBytes}function Me(e,t){let r=Et(t);z(e,t.type.majorEncoded,r.length),e.push(r)}Me.encodedSize=function(t){let r=Et(t);return z.encodedSize(r.length)+r.length};Me.compareTokens=function(t,r){return Ps(Et(t),Et(r))};function Ps(e,t){return e.length<t.length?-1:e.length>t.length?1:ln(e,t)}function at(e,t,r,n,o){let i=r+n;ue(e,t,i);let s=new p(c.string,cn(e,t+r,t+i),i);return o.retainStringBytes===!0&&(s.byteValue=$e(e,t+r,t+i)),s}function Sn(e,t,r,n){return at(e,t,1,r,n)}function _n(e,t,r,n){return at(e,t,2,L(e,t+1,n),n)}function Bn(e,t,r,n){return at(e,t,3,F(e,t+1,n),n)}function In(e,t,r,n){return at(e,t,5,V(e,t+1,n),n)}function Nn(e,t,r,n){let o=P(e,t+1,n);if(typeof o=="bigint")throw new Error(`${w} 64-bit integer string lengths not supported`);return at(e,t,9,o,n)}var Cn=Me;function ze(e,t,r,n){return new p(c.array,n,r)}function $n(e,t,r,n){return ze(e,t,1,r)}function Mn(e,t,r,n){return ze(e,t,2,L(e,t+1,n))}function zn(e,t,r,n){return ze(e,t,3,F(e,t+1,n))}function On(e,t,r,n){return ze(e,t,5,V(e,t+1,n))}function Rn(e,t,r,n){let o=P(e,t+1,n);if(typeof o=="bigint")throw new Error(`${w} 64-bit integer array lengths not supported`);return ze(e,t,9,o)}function Dn(e,t,r,n){if(n.allowIndefinite===!1)throw new Error(`${w} indefinite length items not allowed`);return ze(e,t,1,1/0)}function At(e,t){z(e,c.array.majorEncoded,t.value)}At.compareTokens=J.compareTokens;At.encodedSize=function(t){return z.encodedSize(t.value)};function Oe(e,t,r,n){return new p(c.map,n,r)}function Ln(e,t,r,n){return Oe(e,t,1,r)}function Fn(e,t,r,n){return Oe(e,t,2,L(e,t+1,n))}function Vn(e,t,r,n){return Oe(e,t,3,F(e,t+1,n))}function Pn(e,t,r,n){return Oe(e,t,5,V(e,t+1,n))}function Hn(e,t,r,n){let o=P(e,t+1,n);if(typeof o=="bigint")throw new Error(`${w} 64-bit integer map lengths not supported`);return Oe(e,t,9,o)}function qn(e,t,r,n){if(n.allowIndefinite===!1)throw new Error(`${w} indefinite length items not allowed`);return Oe(e,t,1,1/0)}function kt(e,t){z(e,c.map.majorEncoded,t.value)}kt.compareTokens=J.compareTokens;kt.encodedSize=function(t){return z.encodedSize(t.value)};function jn(e,t,r,n){return new p(c.tag,r,1)}function Gn(e,t,r,n){return new p(c.tag,L(e,t+1,n),2)}function Jn(e,t,r,n){return new p(c.tag,F(e,t+1,n),3)}function Kn(e,t,r,n){return new p(c.tag,V(e,t+1,n),5)}function Xn(e,t,r,n){return new p(c.tag,P(e,t+1,n),9)}function Ut(e,t){z(e,c.tag.majorEncoded,t.value)}Ut.compareTokens=J.compareTokens;Ut.encodedSize=function(t){return z.encodedSize(t.value)};var Ks=20,Xs=21,Qs=22,Ws=23;function Qn(e,t,r,n){if(n.allowUndefined===!1)throw new Error(`${w} undefined values are not supported`);return n.coerceUndefinedToNull===!0?new p(c.null,null,1):new p(c.undefined,void 0,1)}function Wn(e,t,r,n){if(n.allowIndefinite===!1)throw new Error(`${w} indefinite length items not allowed`);return new p(c.break,void 0,1)}function ur(e,t,r){if(r){if(r.allowNaN===!1&&Number.isNaN(e))throw new Error(`${w} NaN values are not supported`);if(r.allowInfinity===!1&&(e===1/0||e===-1/0))throw new Error(`${w} Infinity values are not supported`)}return new p(c.float,e,t)}function Yn(e,t,r,n){return ur(dr(e,t+1),3,n)}function Zn(e,t,r,n){return ur(fr(e,t+1),5,n)}function eo(e,t,r,n){return ur(oo(e,t+1),9,n)}function Tt(e,t,r){let n=t.value;if(n===!1)e.push([c.float.majorEncoded|Ks]);else if(n===!0)e.push([c.float.majorEncoded|Xs]);else if(n===null)e.push([c.float.majorEncoded|Qs]);else if(n===void 0)e.push([c.float.majorEncoded|Ws]);else{let o,i=!1;(!r||r.float64!==!0)&&(ro(n),o=dr(W,1),n===o||Number.isNaN(n)?(W[0]=249,e.push(W.slice(0,3)),i=!0):(no(n),o=fr(W,1),n===o&&(W[0]=250,e.push(W.slice(0,5)),i=!0))),i||(Ys(n),o=oo(W,1),W[0]=251,e.push(W.slice(0,9)))}}Tt.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){ro(n);let o=dr(W,1);if(n===o||Number.isNaN(n))return 3;if(no(n),o=fr(W,1),n===o)return 5}return 9};var to=new ArrayBuffer(9),K=new DataView(to,1),W=new Uint8Array(to,0);function ro(e){if(e===1/0)K.setUint16(0,31744,!1);else if(e===-1/0)K.setUint16(0,64512,!1);else if(Number.isNaN(e))K.setUint16(0,32256,!1);else{K.setFloat32(0,e);let t=K.getUint32(0),r=(t&2139095040)>>23,n=t&8388607;if(r===255)K.setUint16(0,31744,!1);else if(r===0)K.setUint16(0,(e&2147483648)>>16|n>>13,!1);else{let o=r-127;o<-24?K.setUint16(0,0):o<-14?K.setUint16(0,(t&2147483648)>>16|1<<24+o,!1):K.setUint16(0,(t&2147483648)>>16|o+15<<10|n>>13,!1)}}}function dr(e,t){if(e.length-t<2)throw new Error(`${w} 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 no(e){K.setFloat32(0,e,!1)}function fr(e,t){if(e.length-t<4)throw new Error(`${w} not enough data for float32`);let r=(e.byteOffset||0)+t;return new DataView(e.buffer,r,4).getFloat32(0,!1)}function Ys(e){K.setFloat64(0,e,!1)}function oo(e,t){if(e.length-t<8)throw new Error(`${w} not enough data for float64`);let r=(e.byteOffset||0)+t;return new DataView(e.buffer,r,8).getFloat64(0,!1)}Tt.compareTokens=J.compareTokens;function b(e,t,r){throw new Error(`${w} encountered invalid minor (${r}) for major ${e[t]>>>5}`)}function St(e){return()=>{throw new Error(`${w} ${e}`)}}var d=[];for(let e=0;e<=23;e++)d[e]=b;d[24]=hn;d[25]=pn;d[26]=yn;d[27]=mn;d[28]=b;d[29]=b;d[30]=b;d[31]=b;for(let e=32;e<=55;e++)d[e]=b;d[56]=gn;d[57]=wn;d[58]=bn;d[59]=vn;d[60]=b;d[61]=b;d[62]=b;d[63]=b;for(let e=64;e<=87;e++)d[e]=En;d[88]=An;d[89]=kn;d[90]=Un;d[91]=Tn;d[92]=b;d[93]=b;d[94]=b;d[95]=St("indefinite length bytes/strings are not supported");for(let e=96;e<=119;e++)d[e]=Sn;d[120]=_n;d[121]=Bn;d[122]=In;d[123]=Nn;d[124]=b;d[125]=b;d[126]=b;d[127]=St("indefinite length bytes/strings are not supported");for(let e=128;e<=151;e++)d[e]=$n;d[152]=Mn;d[153]=zn;d[154]=On;d[155]=Rn;d[156]=b;d[157]=b;d[158]=b;d[159]=Dn;for(let e=160;e<=183;e++)d[e]=Ln;d[184]=Fn;d[185]=Vn;d[186]=Pn;d[187]=Hn;d[188]=b;d[189]=b;d[190]=b;d[191]=qn;for(let e=192;e<=215;e++)d[e]=jn;d[216]=Gn;d[217]=Jn;d[218]=Kn;d[219]=Xn;d[220]=b;d[221]=b;d[222]=b;d[223]=b;for(let e=224;e<=243;e++)d[e]=St("simple values are not supported");d[244]=b;d[245]=b;d[246]=b;d[247]=Qn;d[248]=St("simple values are not supported");d[249]=Yn;d[250]=Zn;d[251]=eo;d[252]=b;d[253]=b;d[254]=b;d[255]=Wn;var Y=[];for(let e=0;e<24;e++)Y[e]=new p(c.uint,e,1);for(let e=-1;e>=-24;e--)Y[31-e]=new p(c.negint,e,1);Y[64]=new p(c.bytes,new Uint8Array(0),1);Y[96]=new p(c.string,"",1);Y[128]=new p(c.array,0,1);Y[160]=new p(c.map,0,1);Y[244]=new p(c.false,!1,1);Y[245]=new p(c.true,!0,1);Y[246]=new p(c.null,null,1);function io(e){switch(e.type){case c.false:return te([244]);case c.true:return te([245]);case c.null:return te([246]);case c.bytes:return e.value.length?void 0:te([64]);case c.string:return e.value===""?te([96]):void 0;case c.array:return e.value===0?te([128]):void 0;case c.map:return e.value===0?te([160]):void 0;case c.uint:return e.value<24?te([Number(e.value)]):void 0;case c.negint:if(e.value>=-24)return te([31-Number(e.value)])}}var ea={float64:!1,mapSorter:na,quickEncodeToken:io};function ta(){let e=[];return e[c.uint.major]=J,e[c.negint.major]=vt,e[c.bytes.major]=Me,e[c.string.major]=Cn,e[c.array.major]=At,e[c.map.major]=kt,e[c.tag.major]=Ut,e[c.float.major]=Tt,e}var so=ta(),lr=new ot,Re=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(`${ar} object contains circular references`);return new Re(r,t)}},he={null:new p(c.null,null),undefined:new p(c.undefined,void 0),true:new p(c.true,!0),false:new p(c.false,!1),emptyArray:new p(c.array,0),emptyMap:new p(c.map,0)},pe={number(e,t,r,n){return!Number.isInteger(e)||!Number.isSafeInteger(e)?new p(c.float,e):e>=0?new p(c.uint,e):new p(c.negint,e)},bigint(e,t,r,n){return e>=BigInt(0)?new p(c.uint,e):new p(c.negint,e)},Uint8Array(e,t,r,n){return new p(c.bytes,e)},string(e,t,r,n){return new p(c.string,e)},boolean(e,t,r,n){return e?he.true:he.false},null(e,t,r,n){return he.null},undefined(e,t,r,n){return he.undefined},ArrayBuffer(e,t,r,n){return new p(c.bytes,new Uint8Array(e))},DataView(e,t,r,n){return new p(c.bytes,new Uint8Array(e.buffer,e.byteOffset,e.byteLength))},Array(e,t,r,n){if(!e.length)return r.addBreakTokens===!0?[he.emptyArray,new p(c.break)]:he.emptyArray;n=Re.createCheck(n,e);let o=[],i=0;for(let s of e)o[i++]=_t(s,r,n);return r.addBreakTokens?[new p(c.array,e.length),o,new p(c.break)]:[new p(c.array,e.length),o]},Object(e,t,r,n){let o=t!=="Object",i=o?e.keys():Object.keys(e),s=o?e.size:i.length;if(!s)return r.addBreakTokens===!0?[he.emptyMap,new p(c.break)]:he.emptyMap;n=Re.createCheck(n,e);let u=[],h=0;for(let m of i)u[h++]=[_t(m,r,n),_t(o?e.get(m):e[m],r,n)];return ra(u,r),r.addBreakTokens?[new p(c.map,s),u,new p(c.break)]:[new p(c.map,s),u]}};pe.Map=pe.Object;pe.Buffer=pe.Uint8Array;for(let e of"Uint8Clamped Uint16 Uint32 Int8 Int16 Int32 BigUint64 BigInt64 Float32 Float64".split(" "))pe[`${e}Array`]=pe.DataView;function _t(e,t={},r){let n=nn(e),o=t&&t.typeEncoders&&t.typeEncoders[n]||pe[n];if(typeof o=="function"){let s=o(e,n,t,r);if(s!=null)return s}let i=pe[n];if(!i)throw new Error(`${ar} unsupported type: ${n}`);return i(e,n,t,r)}function ra(e,t){t.mapSorter&&e.sort(t.mapSorter)}function na(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=so[o].compareTokens(r,n);return i===0&&console.warn("WARNING: complex key types used, CBOR key sorting guarantees are gone"),i}function ao(e,t,r,n){if(Array.isArray(t))for(let o of t)ao(e,o,r,n);else r[t.type.major](e,t,n)}function oa(e,t,r){let n=_t(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 s=i.encodedSize(n,r),u=new ot(s);if(i(u,n,r),u.chunks.length!==1)throw new Error(`Unexpected error: pre-calculated length for ${n} was wrong`);return sr(u.chunks[0])}}return lr.reset(),ao(lr,n,t,r),lr.toBytes(!0)}function hr(e,t){return t=Object.assign({},ea,t),oa(e,so,t)}var ia={strict:!1,allowIndefinite:!0,allowUndefined:!0,allowBigInt:!0},pr=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=Y[t];if(r===void 0){let n=d[t];if(!n)throw new Error(`${w} 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}},ct=Symbol.for("DONE"),Bt=Symbol.for("BREAK");function sa(e,t,r){let n=[];for(let o=0;o<e.value;o++){let i=ut(t,r);if(i===Bt){if(e.value===1/0)break;throw new Error(`${w} got unexpected break to lengthed array`)}if(i===ct)throw new Error(`${w} found array but not enough entries (got ${o}, expected ${e.value})`);n[o]=i}return n}function aa(e,t,r){let n=r.useMaps===!0,o=n?void 0:{},i=n?new Map:void 0;for(let s=0;s<e.value;s++){let u=ut(t,r);if(u===Bt){if(e.value===1/0)break;throw new Error(`${w} got unexpected break to lengthed map`)}if(u===ct)throw new Error(`${w} found map but not enough entries (got ${s} [no key], expected ${e.value})`);if(n!==!0&&typeof u!="string")throw new Error(`${w} non-string keys not supported (got ${typeof u})`);if(r.rejectDuplicateMapKeys===!0&&(n&&i.has(u)||!n&&u in o))throw new Error(`${w} found repeat map key "${u}"`);let h=ut(t,r);if(h===ct)throw new Error(`${w} found map but not enough entries (got ${s} [no value], expected ${e.value})`);n?i.set(u,h):o[u]=h}return n?i:o}function ut(e,t){if(e.done())return ct;let r=e.next();if(r.type===c.break)return Bt;if(r.type.terminal)return r.value;if(r.type===c.array)return sa(r,e,t);if(r.type===c.map)return aa(r,e,t);if(r.type===c.tag){if(t.tags&&typeof t.tags[r.value]=="function"){let n=ut(e,t);return t.tags[r.value](n)}throw new Error(`${w} tag not supported (${r.value})`)}throw new Error("unsupported")}function yr(e,t){if(!(e instanceof Uint8Array))throw new Error(`${w} data to decode must be a Uint8Array`);t=Object.assign({},ia,t);let r=t.tokenizer||new pr(e,t),n=ut(r,t);if(n===ct)throw new Error(`${w} did not find any content to decode`);if(n===Bt)throw new Error(`${w} got unexpected break`);if(!r.done())throw new Error(`${w} too many terminals, data makes no sense`);return n}var ua=fo,co=128,da=127,fa=~da,la=Math.pow(2,31);function fo(e,t,r){t=t||[],r=r||0;for(var n=r;e>=la;)t[r++]=e&255|co,e/=128;for(;e&fa;)t[r++]=e&255|co,e>>>=7;return t[r]=e|0,fo.bytes=r-n+1,t}var ha=mr,pa=128,uo=127;function mr(e,n){var r=0,n=n||0,o=0,i=n,s,u=e.length;do{if(i>=u)throw mr.bytes=0,new RangeError("Could not decode varint");s=e[i++],r+=o<28?(s&uo)<<o:(s&uo)*Math.pow(2,o),o+=7}while(s>=pa);return mr.bytes=i-n,r}var ya=Math.pow(2,7),ma=Math.pow(2,14),ga=Math.pow(2,21),wa=Math.pow(2,28),ba=Math.pow(2,35),xa=Math.pow(2,42),va=Math.pow(2,49),Ea=Math.pow(2,56),Aa=Math.pow(2,63),ka=function(e){return e<ya?1:e<ma?2:e<ga?3:e<wa?4:e<ba?5:e<xa?6:e<va?7:e<Ea?8:e<Aa?9:10},Ua={encode:ua,decode:ha,encodingLength:ka},Ta=Ua,dt=Ta;var ft=(e,t=0)=>[dt.decode(e,t),dt.decode.bytes],De=(e,t,r=0)=>(dt.encode(e,t,r),t),Le=e=>dt.encodingLength(e);var wd=new Uint8Array(0);var ho=(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},Fe=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 po=(e,t)=>{let r=t.byteLength,n=Le(e),o=n+Le(r),i=new Uint8Array(o+r);return De(e,i,0),De(r,i,n),i.set(t,o),new Ve(e,r,t,i)},yo=e=>{let t=Fe(e),[r,n]=ft(t),[o,i]=ft(t.subarray(n)),s=t.subarray(n+i);if(s.byteLength!==o)throw new Error("Incorrect length");return new Ve(r,o,s,t)},mo=(e,t)=>{if(e===t)return!0;{let r=t;return e.code===r.code&&e.size===r.size&&r.bytes instanceof Uint8Array&&ho(e.bytes,r.bytes)}},Ve=class{constructor(t,r,n,o){this.code=t,this.size=r,this.digest=n,this.bytes=o}};function _a(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),s=i.charCodeAt(0);if(r[s]!==255)throw new TypeError(i+" is ambiguous");r[s]=o}var u=e.length,h=e.charAt(0),m=Math.log(u)/Math.log(256),y=Math.log(256)/Math.log(u);function D(g){if(g instanceof Uint8Array||(ArrayBuffer.isView(g)?g=new Uint8Array(g.buffer,g.byteOffset,g.byteLength):Array.isArray(g)&&(g=Uint8Array.from(g))),!(g instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(g.length===0)return"";for(var A=0,R=0,U=0,S=g.length;U!==S&&g[U]===0;)U++,A++;for(var _=(S-U)*y+1>>>0,k=new Uint8Array(_);U!==S;){for(var B=g[U],M=0,T=_-1;(B!==0||M<R)&&T!==-1;T--,M++)B+=256*k[T]>>>0,k[T]=B%u>>>0,B=B/u>>>0;if(B!==0)throw new Error("Non-zero carry");R=M,U++}for(var N=_-R;N!==_&&k[N]===0;)N++;for(var ae=h.repeat(A);N<_;++N)ae+=e.charAt(k[N]);return ae}function se(g){if(typeof g!="string")throw new TypeError("Expected String");if(g.length===0)return new Uint8Array;var A=0;if(g[A]!==" "){for(var R=0,U=0;g[A]===h;)R++,A++;for(var S=(g.length-A)*m+1>>>0,_=new Uint8Array(S);g[A];){var k=r[g.charCodeAt(A)];if(k===255)return;for(var B=0,M=S-1;(k!==0||B<U)&&M!==-1;M--,B++)k+=u*_[M]>>>0,_[M]=k%256>>>0,k=k/256>>>0;if(k!==0)throw new Error("Non-zero carry");U=B,A++}if(g[A]!==" "){for(var T=S-U;T!==S&&_[T]===0;)T++;for(var N=new Uint8Array(R+(S-T)),ae=R;T!==S;)N[ae++]=_[T++];return N}}}function Wt(g){var A=se(g);if(A)return A;throw new Error(`Non-${t} character`)}return{encode:D,decodeUnsafe:se,decode:Wt}}var Ba=_a,Ia=Ba,go=Ia;var gr=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")}},wr=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 wo(this,t)}},br=class{constructor(t){this.decoders=t}or(t){return wo(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`)}},wo=(e,t)=>new br({...e.decoders||{[e.prefix]:e},...t.decoders||{[t.prefix]:t}}),xr=class{constructor(t,r,n,o){this.name=t,this.prefix=r,this.baseEncode=n,this.baseDecode=o,this.encoder=new gr(t,r,n),this.decoder=new wr(t,r,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}},bo=({name:e,prefix:t,encode:r,decode:n})=>new xr(e,t,r,n),vr=({prefix:e,name:t,alphabet:r})=>{let{encode:n,decode:o}=go(r,t);return bo({prefix:e,name:t,encode:n,decode:i=>Fe(o(i))})},Na=(e,t,r,n)=>{let o={};for(let y=0;y<t.length;++y)o[t[y]]=y;let i=e.length;for(;e[i-1]==="=";)--i;let s=new Uint8Array(i*r/8|0),u=0,h=0,m=0;for(let y=0;y<i;++y){let D=o[e[y]];if(D===void 0)throw new SyntaxError(`Non-${n} character`);h=h<<r|D,u+=r,u>=8&&(u-=8,s[m++]=255&h>>u)}if(u>=r||255&h<<8-u)throw new SyntaxError("Unexpected end of data");return s},Ca=(e,t,r)=>{let n=t[t.length-1]==="=",o=(1<<r)-1,i="",s=0,u=0;for(let h=0;h<e.length;++h)for(u=u<<8|e[h],s+=8;s>r;)s-=r,i+=t[o&u>>s];if(s&&(i+=t[o&u<<r-s]),n)for(;i.length*r&7;)i+="=";return i},re=({name:e,prefix:t,bitsPerChar:r,alphabet:n})=>bo({prefix:t,name:e,encode(o){return Ca(o,n,r)},decode(o){return Na(o,n,r,e)}});var de=vr({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Td=vr({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var lt=re({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Bd=re({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Id=re({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Nd=re({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Cd=re({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),$d=re({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Md=re({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),zd=re({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Od=re({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var xo=(e,t)=>{let{bytes:r,version:n}=e;switch(n){case 0:return Ma(r,Er(e),t||de.encoder);default:return za(r,Er(e),t||lt.encoder)}};var vo=new WeakMap,Er=e=>{let t=vo.get(e);if(t==null){let r=new Map;return vo.set(e,r),r}return t},I=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!==ht)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==Oa)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return I.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=po(t,r);return I.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 I.equals(this,t)}static equals(t,r){let n=r;return n&&t.code===n.code&&t.version===n.version&&mo(t.multihash,n.multihash)}toString(t){return xo(this,t)}toJSON(){return{"/":xo(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 I)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:o,multihash:i,bytes:s}=r;return new I(n,o,i,s||Eo(n,o,i.bytes))}else if(r[Ra]===!0){let{version:n,multihash:o,code:i}=r,s=yo(o);return I.create(n,i,s)}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!==ht)throw new Error(`Version 0 CID must use dag-pb (code: ${ht}) block encoding`);return new I(t,r,n,n.bytes)}case 1:{let o=Eo(t,r,n.bytes);return new I(t,r,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return I.create(0,ht,t)}static createV1(t,r){return I.create(1,t,r)}static decode(t){let[r,n]=I.decodeFirst(t);if(n.length)throw new Error("Incorrect length");return r}static decodeFirst(t){let r=I.inspectBytes(t),n=r.size-r.multihashSize,o=Fe(t.subarray(n,n+r.multihashSize));if(o.byteLength!==r.multihashSize)throw new Error("Incorrect length");let i=o.subarray(r.multihashSize-r.digestSize),s=new Ve(r.multihashCode,r.digestSize,i,o);return[r.version===0?I.createV0(s):I.createV1(r.codec,s),t.subarray(r.size)]}static inspectBytes(t){let r=0,n=()=>{let[D,se]=ft(t.subarray(r));return r+=se,D},o=n(),i=ht;if(o===18?(o=0,r=0):i=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let s=r,u=n(),h=n(),m=r+h,y=m-s;return{version:o,codec:i,multihashCode:u,digestSize:h,multihashSize:y,size:m}}static parse(t,r){let[n,o]=$a(t,r),i=I.decode(o);if(i.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Er(i).set(n,t),i}},$a=(e,t)=>{switch(e[0]){case"Q":{let r=t||de;return[de.prefix,r.decode(`${de.prefix}${e}`)]}case de.prefix:{let r=t||de;return[de.prefix,r.decode(e)]}case lt.prefix:{let r=t||lt;return[lt.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)]}}},Ma=(e,t,r)=>{let{prefix:n}=r;if(n!==de.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},za=(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},ht=112,Oa=18,Eo=(e,t,r)=>{let n=Le(e),o=n+Le(t),i=new Uint8Array(o+r.byteLength);return De(e,i,0),De(t,i,n),i.set(r,o),i},Ra=Symbol.for("@ipld/js-cid/CID");var Ao=42;function Da(e){if(e.asCID!==e&&e["/"]!==e.bytes)return null;let t=I.asCID(e);if(!t)return null;let r=new Uint8Array(t.bytes.byteLength+1);return r.set(t.bytes,1),[new p(c.tag,Ao),new p(c.bytes,r)]}function La(){throw new Error("`undefined` is not supported by the IPLD Data Model and cannot be encoded")}function Fa(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 Va={float64:!0,typeEncoders:{Object:Da,undefined:La,number:Fa}};function Pa(e){if(e[0]!==0)throw new Error("Invalid CID for CBOR tag 42; expected leading 0x00");return I.decode(e.subarray(1))}var ko={allowIndefinite:!1,coerceUndefinedToNull:!0,allowNaN:!1,allowInfinity:!1,allowBigInt:!0,strict:!0,useMaps:!1,rejectDuplicateMapKeys:!0,tags:[]};ko.tags[Ao]=Pa;var It=e=>hr(e,Va),Nt=e=>yr(e,ko);var ye={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=>!ye.Null(e)&&typeof e=="object"&&e.asCID===e,List:e=>Array.isArray(e),Map:e=>!ye.Null(e)&&typeof e=="object"&&e.asCID!==e&&!ye.List(e)&&!ye.Bytes(e)},Pe={Int:ye.Int,"CarHeader > version":e=>Pe.Int(e),"CarHeader > roots (anon) > valueType (anon)":ye.Link,"CarHeader > roots (anon)":e=>ye.List(e)&&Array.prototype.every.call(e,Pe["CarHeader > roots (anon) > valueType (anon)"]),"CarHeader > roots":e=>Pe["CarHeader > roots (anon)"](e),CarHeader:e=>{let t=e&&Object.keys(e);return ye.Map(e)&&["version"].every(r=>t.includes(r))&&Object.entries(e).every(([r,n])=>Pe["CarHeader > "+r]&&Pe["CarHeader > "+r](n))}},Ct=Pe.CarHeader;var me=bt($t(),1),ge={SHA2_256:18,LENGTH:32,DAG_PB:112},Mt=16+8+8+8;function ne(e,t){if(!e.length)throw new Error("Unexpected end of data");let r=me.default.decode(e);return t.seek(me.default.decode.bytes),r}function zt(e){let t=new DataView(e.buffer,e.byteOffset,e.byteLength),r=0;return{version:2,characteristics:[t.getBigUint64(r,!0),t.getBigUint64(r+=8,!0)],dataOffset:Number(t.getBigUint64(r+=8,!0)),dataSize:Number(t.getBigUint64(r+=8,!0)),indexOffset:Number(t.getBigUint64(r+=8,!0))}}function Ot(e){me.default.decode(e);let t=me.default.decode.bytes,r=me.default.decode(e.subarray(me.default.decode.bytes)),n=me.default.decode.bytes;return t+n+r}async function Rt(e,t){let r=ne(await e.upTo(8),e);if(r===0)throw new Error("Invalid CAR header (zero length)");let n=await e.exactly(r,!0),o=Nt(n);if(!Ct(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 s=zt(await e.exactly(Mt,!0));e.seek(s.dataOffset-e.pos);let u=await Rt(e,1);return Object.assign(u,s)}async function nc(e){let t=await e.exactly(2,!1);if(t[0]===ge.SHA2_256&&t[1]===ge.LENGTH){let s=await e.exactly(34,!0),u=le(s);return E.create(0,ge.DAG_PB,u)}let r=ne(await e.upTo(8),e);if(r!==1)throw new Error(`Unexpected CID version (${r})`);let n=ne(await e.upTo(8),e),o=await e.exactly(Ot(await e.upTo(8)),!0),i=le(o);return E.create(r,n,i)}async function Mo(e){let t=e.pos,r=ne(await e.upTo(8),e);if(r===0)throw new Error("Invalid CAR section (zero length)");r+=e.pos-t;let n=await nc(e),o=r-Number(e.pos-t);return{cid:n,length:r,blockLength:o}}async function oc(e){let{cid:t,blockLength:r}=await Mo(e);return{bytes:await e.exactly(r,!0),cid:t}}async function ic(e){let t=e.pos,{cid:r,length:n,blockLength:o}=await Mo(e),i={cid:r,length:n,blockLength:o,offset:t,blockOffset:e.pos};return e.seek(i.blockLength),i}function He(e){let t=(async()=>{let r=await Rt(e);if(r.version===2){let n=e.pos-r.dataOffset;e=ac(e,r.dataSize-n)}return r})();return{header:()=>t,async*blocks(){for(await t;(await e.upTo(8)).length>0;)yield await oc(e)},async*blocksIndex(){for(await t;(await e.upTo(8)).length>0;)yield await ic(e)}}}function we(e){let t=0;return{async upTo(r){return e.subarray(t,t+Math.min(r,e.length-t))},async exactly(r,n=!1){if(r>e.length-t)throw new Error("Unexpected end of data");let o=e.subarray(t,t+r);return n&&(t+=r),o},seek(r){t+=r},get pos(){return t}}}function sc(e){let t=0,r=0,n=0,o=new Uint8Array(0),i=async s=>{r=o.length-n;let u=[o.subarray(n)];for(;r<s;){let m=await e();if(m==null)break;r<0?m.length>r&&u.push(m.subarray(-r)):u.push(m),r+=m.length}o=new Uint8Array(u.reduce((m,y)=>m+y.length,0));let h=0;for(let m of u)o.set(m,h),h+=m.length;n=0};return{async upTo(s){return o.length-n<s&&await i(s),o.subarray(n,n+Math.min(o.length-n,s))},async exactly(s,u=!1){if(o.length-n<s&&await i(s),o.length-n<s)throw new Error("Unexpected end of data");let h=o.subarray(n,n+s);return u&&(t+=s,n+=s),h},seek(s){t+=s,n+=s},get pos(){return t}}}function qe(e){let t=e[Symbol.asyncIterator]();async function r(){let n=await t.next();return n.done?null:n.value}return sc(r)}function ac(e,t){let r=0;return{async upTo(n){let o=await e.upTo(n);return o.length+r>t&&(o=o.subarray(0,t-r)),o},async exactly(n,o=!1){let i=await e.exactly(n,o);if(i.length+r>t)throw new Error("Unexpected end of data");return o&&(r+=n),i},seek(n){r+=n,e.seek(n)},get pos(){return e.pos}}}var Ee=class{constructor(t,r){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 zo(we(t))}static async fromIterable(t){if(!t||typeof t[Symbol.asyncIterator]!="function")throw new TypeError("fromIterable() requires an async iterable");return zo(qe(t))}};async function zo(e){let t=He(e),r=await t.header(),n=[];for await(let o of t.blocks())n.push(o);return new Ee(r,n)}function Oo(e,t){let r=ne(e.upTo(8),e);if(r===0)throw new Error("Invalid CAR header (zero length)");let n=e.exactly(r,!0),o=Nt(n);if(!Ct(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 s=zt(e.exactly(Mt,!0));e.seek(s.dataOffset-e.pos);let u=Oo(e,1);return Object.assign(u,s)}function cc(e){let t=e.exactly(2,!1);if(t[0]===ge.SHA2_256&&t[1]===ge.LENGTH){let s=e.exactly(34,!0),u=le(s);return E.create(0,ge.DAG_PB,u)}let r=ne(e.upTo(8),e);if(r!==1)throw new Error(`Unexpected CID version (${r})`);let n=ne(e.upTo(8),e),o=e.exactly(Ot(e.upTo(8)),!0),i=le(o);return E.create(r,n,i)}function uc(e){let t=e.pos,r=ne(e.upTo(8),e);if(r===0)throw new Error("Invalid CAR section (zero length)");r+=e.pos-t;let n=cc(e),o=r-Number(e.pos-t);return{cid:n,length:r,blockLength:o}}function Ro(e){let t=dc(e),r=Oo(t);if(r.version===2){let o=t.pos-r.dataOffset;t=fc(t,r.dataSize-o)}let n=[];for(;t.upTo(8).length>0;){let{cid:o,blockLength:i}=uc(t);n.push({cid:o,bytes:t.exactly(i,!0)})}return{header:r,blocks:n}}function dc(e){let t=0;return{upTo(r){return e.subarray(t,t+Math.min(r,e.length-t))},exactly(r,n=!1){if(r>e.length-t)throw new Error("Unexpected end of data");let o=e.subarray(t,t+r);return n&&(t+=r),o},seek(r){t+=r},get pos(){return t}}}function fc(e,t){let r=0;return{upTo(n){let o=e.upTo(n);return o.length+r>t&&(o=o.subarray(0,t-r)),o},exactly(n,o=!1){let i=e.exactly(n,o);if(i.length+r>t)throw new Error("Unexpected end of data");return o&&(r+=n),i},seek(n){r+=n,e.seek(n)},get pos(){return e.pos}}}var je=class{constructor(t,r){this._header=t,this._blocks=r,this._cids=void 0}get version(){return this._header.version}getRoots(){return this._header.roots}has(t){return this._blocks.some(r=>r.cid.equals(t))}get(t){return this._blocks.find(r=>r.cid.equals(t))}blocks(){return this._blocks}cids(){return this._cids||(this._cids=this._blocks.map(t=>t.cid)),this._cids}static fromBytes(t){if(!(t instanceof Uint8Array))throw new TypeError("fromBytes() requires a Uint8Array");let{header:r,blocks:n}=Ro(t);return new je(r,n)}};var Ae=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 Do(we(t))}static async fromIterable(t){if(!t||typeof t[Symbol.asyncIterator]!="function")throw new TypeError("fromIterable() requires an async iterable");return Do(qe(t))}};async function Do(e){let t=He(e),{version:r,roots:n}=await t.header();return new Ae(r,n,t.blocksIndex())}var Dt=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}},ke=class extends Dt{[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 Lo(t);return new ke(r,n,o)}static async fromIterable(t){let{version:r,roots:n,iterator:o}=await Fo(t);return new ke(r,n,o)}},Ue=class extends Dt{[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 Lo(t);return new Ue(r,n,o)}static async fromIterable(t){let{version:r,roots:n,iterator:o}=await Fo(t);return new Ue(r,n,o)}};async function Lo(e){if(!(e instanceof Uint8Array))throw new TypeError("fromBytes() requires a Uint8Array");return Vo(we(e))}async function Fo(e){if(!e||typeof e[Symbol.asyncIterator]!="function")throw new TypeError("fromIterable() requires an async iterable");return Vo(qe(e))}async function Vo(e){let t=He(e),{version:r,roots:n}=await t.header();return{version:r,roots:n,iterator:t.blocks()}}var Ur=bt($t(),1);function Tr(e){let t=It({version:1,roots:e}),r=Ur.default.encode(t.length),n=new Uint8Array(r.length+t.length);return n.set(r,0),n.set(t,r.length),n}function Po(e){return{async setRoots(t){let r=Tr(t);await e.write(r)},async writeBlock(t){let{cid:r,bytes:n}=t;await e.write(new Uint8Array(Ur.default.encode(r.bytes.length+n.length))),await e.write(r.bytes),n.length&&await e.write(n)},async close(){await e.end()}}}function Lt(){}function Ho(){let e=[],t=null,r=Lt,n=!1,o=null,i=Lt,s=()=>(t||(t=new Promise(m=>{r=()=>{t=null,r=Lt,m()}})),t),u={write(m){e.push(m);let y=s();return i(),y},async end(){n=!0;let m=s();i(),await m}},h={async next(){let m=e.shift();return m?(e.length===0&&r(),{done:!1,value:m}):n?(r(),{done:!0,value:void 0}):(o||(o=new Promise(y=>{i=()=>(o=null,i=Lt,y(h.next()))})),o)}};return{writer:u,iterator:h}}var Te=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=E.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=hc(t);let{encoder:r,iterator:n}=qo(),o=new Te(t,r),i=new Ft(n);return{writer:o,out:i}}static createAppender(){let{encoder:t,iterator:r}=qo();t.setRoots=()=>Promise.resolve();let n=new Te([],t),o=new Ft(r);return{writer:n,out:o}}static async updateRootsInBytes(t,r){let n=we(t);await Rt(n);let o=Tr(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}},Ft=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 qo(){let e=Ho(),{writer:t,iterator:r}=e;return{encoder:Po(t),iterator:r}}function hc(e){if(e===void 0)return[];if(!Array.isArray(e)){let r=E.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=E.asCID(r);if(!n)throw new TypeError("roots must be a single CID or an array of CIDs");t.push(n)}return t}var Sr=bt(jo(),1);var Ge=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 Sr.default.promises.open(this._path,"r"));let n={cid:t,length:0,offset:0,blockLength:r.blockLength,blockOffset:r.blockOffset};return Ee.readRaw(this._fd,n)}async*blocks(){for(let t of this._order){let r=await this.get(E.parse(t));if(!r)throw new Error("Unexpected internal error");yield r}}async*cids(){for(let t of this._order)yield E.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 Ae.fromIterable((void 0).from(Sr.default.createReadStream(t))),n=new Map,o=[];for await(let{cid:i,blockLength:s,blockOffset:u}of r){let h=i.toString();n.set(h,{blockLength:s,blockOffset:u}),o.push(h)}return new Ge(r.version,t,await r.getRoots(),n,o)}};var Vr={};Pr(Vr,{addBlock:()=>Wi,addRoot:()=>Qi,blockLength:()=>Dc,calculateHeaderLength:()=>Lr,close:()=>Yi,createWriter:()=>Pc,estimateHeaderLength:()=>Vc,headerLength:()=>Fr,resizeHeader:()=>Dr});var gt=bt($t(),1);var pc=["string","number","bigint","symbol"],yc=["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 Jo(e){if(e===null)return"null";if(e===void 0)return"undefined";if(e===!0||e===!1)return"boolean";let t=typeof e;if(pc.includes(t))return t;if(t==="function")return"Function";if(Array.isArray(e))return"Array";if(mc(e))return"Buffer";let r=gc(e);return r||"Object"}function mc(e){return e&&e.constructor&&e.constructor.isBuffer&&e.constructor.isBuffer.call(null,e)}function gc(e){let t=Object.prototype.toString.call(e).slice(8,-1);if(yc.includes(t))return t}var a=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}};a.uint=new a(0,"uint",!0);a.negint=new a(1,"negint",!0);a.bytes=new a(2,"bytes",!0);a.string=new a(3,"string",!0);a.array=new a(4,"array",!1);a.map=new a(5,"map",!1);a.tag=new a(6,"tag",!1);a.float=new a(7,"float",!0);a.false=new a(7,"false",!0);a.true=new a(7,"true",!0);a.null=new a(7,"null",!0);a.undefined=new a(7,"undefined",!0);a.break=new a(7,"break",!0);var l=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 Je=globalThis.process&&!globalThis.process.browser&&globalThis.Buffer&&typeof globalThis.Buffer.isBuffer=="function",wc=new TextDecoder,bc=new TextEncoder;function Vt(e){return Je&&globalThis.Buffer.isBuffer(e)}function Wo(e){return e instanceof Uint8Array?Vt(e)?new Uint8Array(e.buffer,e.byteOffset,e.byteLength):e:Uint8Array.from(e)}var Yo=Je?(e,t,r)=>r-t>64?globalThis.Buffer.from(e.subarray(t,r)).toString("utf8"):Xo(e,t,r):(e,t,r)=>r-t>64?wc.decode(e.subarray(t,r)):Xo(e,t,r),Zo=Je?e=>e.length>64?globalThis.Buffer.from(e):Ko(e):e=>e.length>64?bc.encode(e):Ko(e),oe=e=>Uint8Array.from(e),Ke=Je?(e,t,r)=>Vt(e)?new Uint8Array(e.subarray(t,r)):e.slice(t,r):(e,t,r)=>e.slice(t,r),ei=Je?(e,t)=>(e=e.map(r=>r instanceof Uint8Array?r:globalThis.Buffer.from(r)),Wo(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},ti=Je?e=>globalThis.Buffer.allocUnsafe(e):e=>new Uint8Array(e);function ri(e,t){if(Vt(e)&&Vt(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 Ko(e,t=1/0){let r,n=e.length,o=null,i=[];for(let s=0;s<n;++s){if(r=e.charCodeAt(s),r>55295&&r<57344){if(!o){if(r>56319){(t-=3)>-1&&i.push(239,191,189);continue}else if(s+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 Xo(e,t,r){let n=[];for(;t<r;){let o=e[t],i=null,s=o>239?4:o>223?3:o>191?2:1;if(t+s<=r){let u,h,m,y;switch(s){case 1:o<128&&(i=o);break;case 2:u=e[t+1],(u&192)===128&&(y=(o&31)<<6|u&63,y>127&&(i=y));break;case 3:u=e[t+1],h=e[t+2],(u&192)===128&&(h&192)===128&&(y=(o&15)<<12|(u&63)<<6|h&63,y>2047&&(y<55296||y>57343)&&(i=y));break;case 4:u=e[t+1],h=e[t+2],m=e[t+3],(u&192)===128&&(h&192)===128&&(m&192)===128&&(y=(o&15)<<18|(u&63)<<12|(h&63)<<6|m&63,y>65535&&y<1114112&&(i=y))}}i===null?(i=65533,s=1):i>65535&&(i-=65536,n.push(i>>>10&1023|55296),i=56320|i&1023),n.push(i),t+=s}return xc(n)}var Qo=4096;function xc(e){let t=e.length;if(t<=Qo)return String.fromCharCode.apply(String,e);let r="",n=0;for(;n<t;)r+=String.fromCharCode.apply(String,e.slice(n,n+=Qo));return r}var vc=256,Pt=class{constructor(t=vc){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=ti(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=Ke(n,0,this.cursor)}else r=ei(this.chunks,this.cursor);return t&&this.reset(),r}};var x="CBOR decode error:",_r="CBOR encode error:",pt=[];pt[23]=1;pt[24]=2;pt[25]=3;pt[26]=5;pt[27]=9;function fe(e,t,r){if(e.length-t<r)throw new Error(`${x} not enough data for type`)}var $=[24,256,65536,4294967296,BigInt("18446744073709551616")];function H(e,t,r){fe(e,t,1);let n=e[t];if(r.strict===!0&&n<$[0])throw new Error(`${x} integer encoded in more bytes than necessary (strict decode)`);return n}function q(e,t,r){fe(e,t,2);let n=e[t]<<8|e[t+1];if(r.strict===!0&&n<$[1])throw new Error(`${x} integer encoded in more bytes than necessary (strict decode)`);return n}function j(e,t,r){fe(e,t,4);let n=e[t]*16777216+(e[t+1]<<16)+(e[t+2]<<8)+e[t+3];if(r.strict===!0&&n<$[2])throw new Error(`${x} integer encoded in more bytes than necessary (strict decode)`);return n}function G(e,t,r){fe(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<$[3])throw new Error(`${x} 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(`${x} integers outside of the safe integer range are not supported`)}function ni(e,t,r,n){return new l(a.uint,H(e,t+1,n),2)}function oi(e,t,r,n){return new l(a.uint,q(e,t+1,n),3)}function ii(e,t,r,n){return new l(a.uint,j(e,t+1,n),5)}function si(e,t,r,n){return new l(a.uint,G(e,t+1,n),9)}function X(e,t){return O(e,0,t.value)}function O(e,t,r){if(r<$[0]){let n=Number(r);e.push([t|n])}else if(r<$[1]){let n=Number(r);e.push([t|24,n])}else if(r<$[2]){let n=Number(r);e.push([t|25,n>>>8,n&255])}else if(r<$[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<$[4]){let o=[t|27,0,0,0,0,0,0,0],i=Number(n&BigInt(4294967295)),s=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]=s&255,s=s>>8,o[3]=s&255,s=s>>8,o[2]=s&255,s=s>>8,o[1]=s&255,e.push(o)}else throw new Error(`${x} encountered BigInt larger than allowable range`)}}X.encodedSize=function(t){return O.encodedSize(t.value)};O.encodedSize=function(t){return t<$[0]?1:t<$[1]?2:t<$[2]?3:t<$[3]?5:9};X.compareTokens=function(t,r){return t.value<r.value?-1:t.value>r.value?1:0};function ai(e,t,r,n){return new l(a.negint,-1-H(e,t+1,n),2)}function ci(e,t,r,n){return new l(a.negint,-1-q(e,t+1,n),3)}function ui(e,t,r,n){return new l(a.negint,-1-j(e,t+1,n),5)}var Br=BigInt(-1),di=BigInt(1);function fi(e,t,r,n){let o=G(e,t+1,n);if(typeof o!="bigint"){let i=-1-o;if(i>=Number.MIN_SAFE_INTEGER)return new l(a.negint,i,9)}if(n.allowBigInt!==!0)throw new Error(`${x} integers outside of the safe integer range are not supported`);return new l(a.negint,Br-BigInt(o),9)}function Ht(e,t){let r=t.value,n=typeof r=="bigint"?r*Br-di:r*-1-1;O(e,t.type.majorEncoded,n)}Ht.encodedSize=function(t){let r=t.value,n=typeof r=="bigint"?r*Br-di:r*-1-1;return n<$[0]?1:n<$[1]?2:n<$[2]?3:n<$[3]?5:9};Ht.compareTokens=function(t,r){return t.value<r.value?1:t.value>r.value?-1:0};function yt(e,t,r,n){fe(e,t,r+n);let o=Ke(e,t+r,t+r+n);return new l(a.bytes,o,r+n)}function li(e,t,r,n){return yt(e,t,1,r)}function hi(e,t,r,n){return yt(e,t,2,H(e,t+1,n))}function pi(e,t,r,n){return yt(e,t,3,q(e,t+1,n))}function yi(e,t,r,n){return yt(e,t,5,j(e,t+1,n))}function mi(e,t,r,n){let o=G(e,t+1,n);if(typeof o=="bigint")throw new Error(`${x} 64-bit integer bytes lengths not supported`);return yt(e,t,9,o)}function qt(e){return e.encodedBytes===void 0&&(e.encodedBytes=e.type===a.string?Zo(e.value):e.value),e.encodedBytes}function Xe(e,t){let r=qt(t);O(e,t.type.majorEncoded,r.length),e.push(r)}Xe.encodedSize=function(t){let r=qt(t);return O.encodedSize(r.length)+r.length};Xe.compareTokens=function(t,r){return Ac(qt(t),qt(r))};function Ac(e,t){return e.length<t.length?-1:e.length>t.length?1:ri(e,t)}function mt(e,t,r,n,o){let i=r+n;fe(e,t,i);let s=new l(a.string,Yo(e,t+r,t+i),i);return o.retainStringBytes===!0&&(s.byteValue=Ke(e,t+r,t+i)),s}function gi(e,t,r,n){return mt(e,t,1,r,n)}function wi(e,t,r,n){return mt(e,t,2,H(e,t+1,n),n)}function bi(e,t,r,n){return mt(e,t,3,q(e,t+1,n),n)}function xi(e,t,r,n){return mt(e,t,5,j(e,t+1,n),n)}function vi(e,t,r,n){let o=G(e,t+1,n);if(typeof o=="bigint")throw new Error(`${x} 64-bit integer string lengths not supported`);return mt(e,t,9,o,n)}var Ei=Xe;function Qe(e,t,r,n){return new l(a.array,n,r)}function Ai(e,t,r,n){return Qe(e,t,1,r)}function ki(e,t,r,n){return Qe(e,t,2,H(e,t+1,n))}function Ui(e,t,r,n){return Qe(e,t,3,q(e,t+1,n))}function Ti(e,t,r,n){return Qe(e,t,5,j(e,t+1,n))}function Si(e,t,r,n){let o=G(e,t+1,n);if(typeof o=="bigint")throw new Error(`${x} 64-bit integer array lengths not supported`);return Qe(e,t,9,o)}function _i(e,t,r,n){if(n.allowIndefinite===!1)throw new Error(`${x} indefinite length items not allowed`);return Qe(e,t,1,1/0)}function jt(e,t){O(e,a.array.majorEncoded,t.value)}jt.compareTokens=X.compareTokens;jt.encodedSize=function(t){return O.encodedSize(t.value)};function We(e,t,r,n){return new l(a.map,n,r)}function Bi(e,t,r,n){return We(e,t,1,r)}function Ii(e,t,r,n){return We(e,t,2,H(e,t+1,n))}function Ni(e,t,r,n){return We(e,t,3,q(e,t+1,n))}function Ci(e,t,r,n){return We(e,t,5,j(e,t+1,n))}function $i(e,t,r,n){let o=G(e,t+1,n);if(typeof o=="bigint")throw new Error(`${x} 64-bit integer map lengths not supported`);return We(e,t,9,o)}function Mi(e,t,r,n){if(n.allowIndefinite===!1)throw new Error(`${x} indefinite length items not allowed`);return We(e,t,1,1/0)}function Gt(e,t){O(e,a.map.majorEncoded,t.value)}Gt.compareTokens=X.compareTokens;Gt.encodedSize=function(t){return O.encodedSize(t.value)};function zi(e,t,r,n){return new l(a.tag,r,1)}function Oi(e,t,r,n){return new l(a.tag,H(e,t+1,n),2)}function Ri(e,t,r,n){return new l(a.tag,q(e,t+1,n),3)}function Di(e,t,r,n){return new l(a.tag,j(e,t+1,n),5)}function Li(e,t,r,n){return new l(a.tag,G(e,t+1,n),9)}function Jt(e,t){O(e,a.tag.majorEncoded,t.value)}Jt.compareTokens=X.compareTokens;Jt.encodedSize=function(t){return O.encodedSize(t.value)};var Bc=20,Ic=21,Nc=22,Cc=23;function Fi(e,t,r,n){if(n.allowUndefined===!1)throw new Error(`${x} undefined values are not supported`);return n.coerceUndefinedToNull===!0?new l(a.null,null,1):new l(a.undefined,void 0,1)}function Vi(e,t,r,n){if(n.allowIndefinite===!1)throw new Error(`${x} indefinite length items not allowed`);return new l(a.break,void 0,1)}function Ir(e,t,r){if(r){if(r.allowNaN===!1&&Number.isNaN(e))throw new Error(`${x} NaN values are not supported`);if(r.allowInfinity===!1&&(e===1/0||e===-1/0))throw new Error(`${x} Infinity values are not supported`)}return new l(a.float,e,t)}function Pi(e,t,r,n){return Ir(Nr(e,t+1),3,n)}function Hi(e,t,r,n){return Ir(Cr(e,t+1),5,n)}function qi(e,t,r,n){return Ir(Ki(e,t+1),9,n)}function Kt(e,t,r){let n=t.value;if(n===!1)e.push([a.float.majorEncoded|Bc]);else if(n===!0)e.push([a.float.majorEncoded|Ic]);else if(n===null)e.push([a.float.majorEncoded|Nc]);else if(n===void 0)e.push([a.float.majorEncoded|Cc]);else{let o,i=!1;(!r||r.float64!==!0)&&(Gi(n),o=Nr(Z,1),n===o||Number.isNaN(n)?(Z[0]=249,e.push(Z.slice(0,3)),i=!0):(Ji(n),o=Cr(Z,1),n===o&&(Z[0]=250,e.push(Z.slice(0,5)),i=!0))),i||($c(n),o=Ki(Z,1),Z[0]=251,e.push(Z.slice(0,9)))}}Kt.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){Gi(n);let o=Nr(Z,1);if(n===o||Number.isNaN(n))return 3;if(Ji(n),o=Cr(Z,1),n===o)return 5}return 9};var ji=new ArrayBuffer(9),Q=new DataView(ji,1),Z=new Uint8Array(ji,0);function Gi(e){if(e===1/0)Q.setUint16(0,31744,!1);else if(e===-1/0)Q.setUint16(0,64512,!1);else if(Number.isNaN(e))Q.setUint16(0,32256,!1);else{Q.setFloat32(0,e);let t=Q.getUint32(0),r=(t&2139095040)>>23,n=t&8388607;if(r===255)Q.setUint16(0,31744,!1);else if(r===0)Q.setUint16(0,(e&2147483648)>>16|n>>13,!1);else{let o=r-127;o<-24?Q.setUint16(0,0):o<-14?Q.setUint16(0,(t&2147483648)>>16|1<<24+o,!1):Q.setUint16(0,(t&2147483648)>>16|o+15<<10|n>>13,!1)}}}function Nr(e,t){if(e.length-t<2)throw new Error(`${x} 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 Ji(e){Q.setFloat32(0,e,!1)}function Cr(e,t){if(e.length-t<4)throw new Error(`${x} not enough data for float32`);let r=(e.byteOffset||0)+t;return new DataView(e.buffer,r,4).getFloat32(0,!1)}function $c(e){Q.setFloat64(0,e,!1)}function Ki(e,t){if(e.length-t<8)throw new Error(`${x} not enough data for float64`);let r=(e.byteOffset||0)+t;return new DataView(e.buffer,r,8).getFloat64(0,!1)}Kt.compareTokens=X.compareTokens;function v(e,t,r){throw new Error(`${x} encountered invalid minor (${r}) for major ${e[t]>>>5}`)}function Xt(e){return()=>{throw new Error(`${x} ${e}`)}}var f=[];for(let e=0;e<=23;e++)f[e]=v;f[24]=ni;f[25]=oi;f[26]=ii;f[27]=si;f[28]=v;f[29]=v;f[30]=v;f[31]=v;for(let e=32;e<=55;e++)f[e]=v;f[56]=ai;f[57]=ci;f[58]=ui;f[59]=fi;f[60]=v;f[61]=v;f[62]=v;f[63]=v;for(let e=64;e<=87;e++)f[e]=li;f[88]=hi;f[89]=pi;f[90]=yi;f[91]=mi;f[92]=v;f[93]=v;f[94]=v;f[95]=Xt("indefinite length bytes/strings are not supported");for(let e=96;e<=119;e++)f[e]=gi;f[120]=wi;f[121]=bi;f[122]=xi;f[123]=vi;f[124]=v;f[125]=v;f[126]=v;f[127]=Xt("indefinite length bytes/strings are not supported");for(let e=128;e<=151;e++)f[e]=Ai;f[152]=ki;f[153]=Ui;f[154]=Ti;f[155]=Si;f[156]=v;f[157]=v;f[158]=v;f[159]=_i;for(let e=160;e<=183;e++)f[e]=Bi;f[184]=Ii;f[185]=Ni;f[186]=Ci;f[187]=$i;f[188]=v;f[189]=v;f[190]=v;f[191]=Mi;for(let e=192;e<=215;e++)f[e]=zi;f[216]=Oi;f[217]=Ri;f[218]=Di;f[219]=Li;f[220]=v;f[221]=v;f[222]=v;f[223]=v;for(let e=224;e<=243;e++)f[e]=Xt("simple values are not supported");f[244]=v;f[245]=v;f[246]=v;f[247]=Fi;f[248]=Xt("simple values are not supported");f[249]=Pi;f[250]=Hi;f[251]=qi;f[252]=v;f[253]=v;f[254]=v;f[255]=Vi;var ie=[];for(let e=0;e<24;e++)ie[e]=new l(a.uint,e,1);for(let e=-1;e>=-24;e--)ie[31-e]=new l(a.negint,e,1);ie[64]=new l(a.bytes,new Uint8Array(0),1);ie[96]=new l(a.string,"",1);ie[128]=new l(a.array,0,1);ie[160]=new l(a.map,0,1);ie[244]=new l(a.false,!1,1);ie[245]=new l(a.true,!0,1);ie[246]=new l(a.null,null,1);function $r(e){switch(e.type){case a.false:return oe([244]);case a.true:return oe([245]);case a.null:return oe([246]);case a.bytes:return e.value.length?void 0:oe([64]);case a.string:return e.value===""?oe([96]):void 0;case a.array:return e.value===0?oe([128]):void 0;case a.map:return e.value===0?oe([160]):void 0;case a.uint:return e.value<24?oe([Number(e.value)]):void 0;case a.negint:if(e.value>=-24)return oe([31-Number(e.value)])}}function Mr(){let e=[];return e[a.uint.major]=X,e[a.negint.major]=Ht,e[a.bytes.major]=Xe,e[a.string.major]=Ei,e[a.array.major]=jt,e[a.map.major]=Gt,e[a.tag.major]=Jt,e[a.float.major]=Kt,e}var ml=Mr(),gl=new Pt,Ye=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(`${_r} object contains circular references`);return new Ye(r,t)}},be={null:new l(a.null,null),undefined:new l(a.undefined,void 0),true:new l(a.true,!0),false:new l(a.false,!1),emptyArray:new l(a.array,0),emptyMap:new l(a.map,0)},xe={number(e,t,r,n){return!Number.isInteger(e)||!Number.isSafeInteger(e)?new l(a.float,e):e>=0?new l(a.uint,e):new l(a.negint,e)},bigint(e,t,r,n){return e>=BigInt(0)?new l(a.uint,e):new l(a.negint,e)},Uint8Array(e,t,r,n){return new l(a.bytes,e)},string(e,t,r,n){return new l(a.string,e)},boolean(e,t,r,n){return e?be.true:be.false},null(e,t,r,n){return be.null},undefined(e,t,r,n){return be.undefined},ArrayBuffer(e,t,r,n){return new l(a.bytes,new Uint8Array(e))},DataView(e,t,r,n){return new l(a.bytes,new Uint8Array(e.buffer,e.byteOffset,e.byteLength))},Array(e,t,r,n){if(!e.length)return r.addBreakTokens===!0?[be.emptyArray,new l(a.break)]:be.emptyArray;n=Ye.createCheck(n,e);let o=[],i=0;for(let s of e)o[i++]=Qt(s,r,n);return r.addBreakTokens?[new l(a.array,e.length),o,new l(a.break)]:[new l(a.array,e.length),o]},Object(e,t,r,n){let o=t!=="Object",i=o?e.keys():Object.keys(e),s=o?e.size:i.length;if(!s)return r.addBreakTokens===!0?[be.emptyMap,new l(a.break)]:be.emptyMap;n=Ye.createCheck(n,e);let u=[],h=0;for(let m of i)u[h++]=[Qt(m,r,n),Qt(o?e.get(m):e[m],r,n)];return zc(u,r),r.addBreakTokens?[new l(a.map,s),u,new l(a.break)]:[new l(a.map,s),u]}};xe.Map=xe.Object;xe.Buffer=xe.Uint8Array;for(let e of"Uint8Clamped Uint16 Uint32 Int8 Int16 Int32 BigUint64 BigInt64 Float32 Float64".split(" "))xe[`${e}Array`]=xe.DataView;function Qt(e,t={},r){let n=Jo(e),o=t&&t.typeEncoders&&t.typeEncoders[n]||xe[n];if(typeof o=="function"){let s=o(e,n,t,r);if(s!=null)return s}let i=xe[n];if(!i)throw new Error(`${_r} unsupported type: ${n}`);return i(e,n,t,r)}function zc(e,t){t.mapSorter&&e.sort(t.mapSorter)}var El=Symbol.for("DONE"),Al=Symbol.for("BREAK");var Oc=Mr(),Rc={float64:!1,quickEncodeToken:$r};function zr(e,t=Oc,r=Rc){if(Array.isArray(e)){let n=0;for(let o of e)n+=zr(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 Rr=class{constructor(t,r){this.bytes=t,this.byteOffset=r,this.roots=[],this.headerSize=r}addRoot(t,r){return Qi(this,t,r),this}write(t){return Wi(this,t),this}close(t){return Yi(this,t)}},Qi=(e,t,r={})=>{let{resize:n=!1}=r,{bytes:o,headerSize:i,byteOffset:s,roots:u}=e;e.roots.push(t);let h=Fr(e);if(h>i)if(h-i+s<o.byteLength)if(n)Dr(e,h);else throw u.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 u.pop(),new RangeError(`Buffer has no capacity for a new root ${t}`)},Dc=({cid:e,bytes:t})=>{let r=e.bytes.byteLength+t.byteLength;return gt.default.encodingLength(r)+r},Wi=(e,{cid:t,bytes:r})=>{let n=t.bytes.byteLength+r.byteLength,o=gt.default.encode(n);if(e.byteOffset+o.length+n>e.bytes.byteLength)throw new RangeError("Buffer has no capacity for this block");Or(e,o),Or(e,t.bytes),Or(e,r)},Yi=(e,t={})=>{let{resize:r=!1}=t,{roots:n,bytes:o,byteOffset:i,headerSize:s}=e,u=It({version:1,roots:n}),h=gt.default.encode(u.length),m=h.length+u.byteLength;if(s-m===0)return Xi(e,h,u),o.subarray(0,i);if(r)return Dr(e,m),Xi(e,h,u),o.subarray(0,e.byteOffset);throw new RangeError(`Header size was overestimated.
4
+ You can use close({ resize: true }) to resize header`)},Dr=(e,t)=>{let{bytes:r,headerSize:n}=e;r.set(r.subarray(n,e.byteOffset),t),e.byteOffset+=t-n,e.headerSize=t},Or=(e,t)=>{e.bytes.set(t,e.byteOffset),e.byteOffset+=t.length},Xi=({bytes:e},t,r)=>{e.set(t),e.set(r,t.length)},Lc=[new l(a.map,2),new l(a.string,"version"),new l(a.uint,1),new l(a.string,"roots")],Fc=new l(a.tag,42),Lr=e=>{let t=[...Lc];t.push(new l(a.array,e.length));for(let n of e)t.push(Fc),t.push(new l(a.bytes,{length:n+1}));let r=zr(t);return gt.default.encodingLength(r)+r},Fr=({roots:e})=>Lr(e.map(t=>t.bytes.byteLength)),Vc=(e,t=36)=>Lr(new Array(e).fill(t)),Pc=(e,t={})=>{let{roots:r=[],byteOffset:n=0,byteLength:o=e.byteLength,headerSize:i=Fr({roots:r})}=t,s=new Uint8Array(e,n,o),u=new Rr(s,i);for(let h of r)u.addRoot(h);return u};var Hc="application/vnd.ipld.car";return os(qc);})();
5
5
  return IpldCar}));
@@ -4,5 +4,7 @@ import { CarBlockIterator } from "./iterator.js";
4
4
  import { CarCIDIterator } from "./iterator.js";
5
5
  import { CarWriter } from "./writer-browser.js";
6
6
  import { CarIndexedReader } from "./indexed-reader-browser.js";
7
- export { CarReader, CarIndexer, CarBlockIterator, CarCIDIterator, CarWriter, CarIndexedReader };
7
+ import { CarBufferReader } from "./buffer-reader.js";
8
+ import * as CarBufferWriter from "./buffer-writer.js";
9
+ export { CarReader, CarIndexer, CarBlockIterator, CarCIDIterator, CarWriter, CarIndexedReader, CarBufferReader, CarBufferWriter };
8
10
  //# sourceMappingURL=index-browser.d.ts.map
@@ -1,3 +1,4 @@
1
+ export const contentType: "application/vnd.ipld.car";
1
2
  import { CarReader } from "./reader.js";
2
3
  import { CarBufferReader } from "./buffer-reader.js";
3
4
  import { CarIndexer } from "./indexer.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.js"],"names":[],"mappings":""}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.js"],"names":[],"mappings":"AASA,qDAAqD"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ipld/car",
3
- "version": "5.1.0",
3
+ "version": "5.2.0",
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",
@@ -3,6 +3,8 @@ import { CarIndexer } from './indexer.js'
3
3
  import { CarBlockIterator, CarCIDIterator } from './iterator.js'
4
4
  import { CarWriter } from './writer-browser.js'
5
5
  import { CarIndexedReader } from './indexed-reader-browser.js'
6
+ import { CarBufferReader } from './buffer-reader.js'
7
+ import * as CarBufferWriter from './buffer-writer.js'
6
8
 
7
9
  export {
8
10
  CarReader,
@@ -10,5 +12,7 @@ export {
10
12
  CarBlockIterator,
11
13
  CarCIDIterator,
12
14
  CarWriter,
13
- CarIndexedReader
15
+ CarIndexedReader,
16
+ CarBufferReader,
17
+ CarBufferWriter
14
18
  }
package/src/index.js CHANGED
@@ -6,6 +6,9 @@ import { CarWriter } from './writer.js'
6
6
  import { CarIndexedReader } from './indexed-reader.js'
7
7
  import * as CarBufferWriter from './buffer-writer.js'
8
8
 
9
+ // @see https://www.iana.org/assignments/media-types/application/vnd.ipld.car
10
+ export const contentType = 'application/vnd.ipld.car'
11
+
9
12
  export {
10
13
  CarReader,
11
14
  CarBufferReader,