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