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