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