@ipld/car 5.2.3 → 5.2.4
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/api.d.ts +17 -17
- package/dist/src/api.d.ts.map +1 -1
- package/dist/src/buffer-decoder.d.ts.map +1 -1
- package/dist/src/coding.d.ts +13 -13
- package/dist/src/coding.d.ts.map +1 -1
- package/dist/src/decoder.d.ts.map +1 -1
- package/dist/src/header-validator.d.ts +4 -1
- package/dist/src/header-validator.d.ts.map +1 -1
- package/package.json +7 -3
- package/src/api.ts +15 -15
- package/src/buffer-decoder.js +9 -8
- package/src/coding.ts +13 -13
- package/src/decoder.js +9 -8
- package/src/header-validator.js +203 -63
- package/src/header.ipldsch +17 -5
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 Ei=Object.create;var et=Object.defineProperty;var ki=Object.getOwnPropertyDescriptor;var _i=Object.getOwnPropertyNames;var vi=Object.getPrototypeOf,Ai=Object.prototype.hasOwnProperty;var ze=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),_r=(e,t)=>{for(var r in t)et(e,r,{get:t[r],enumerable:!0})},vr=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of _i(t))!Ai.call(e,o)&&o!==r&&et(e,o,{get:()=>t[o],enumerable:!(n=ki(t,o))||n.enumerable});return e};var tt=(e,t,r)=>(r=e!=null?Ei(vi(e)):{},vr(t||!e||!e.__esModule?et(r,"default",{value:e,enumerable:!0}):r,e)),Ui=e=>vr(et({},"__esModule",{value:!0}),e);var Kn=ze((fu,Gn)=>{Gn.exports=or;var qn=128,zs=127,Os=~zs,Ls=Math.pow(2,31);function or(e,t,r){if(Number.MAX_SAFE_INTEGER&&e>Number.MAX_SAFE_INTEGER)throw or.bytes=0,new RangeError("Could not encode varint");t=t||[],r=r||0;for(var n=r;e>=Ls;)t[r++]=e&255|qn,e/=128;for(;e&Os;)t[r++]=e&255|qn,e>>>=7;return t[r]=e|0,or.bytes=r-n+1,t}});var Jn=ze((du,Xn)=>{Xn.exports=ir;var Fs=128,Wn=127;function ir(e,n){var r=0,n=n||0,o=0,i=n,s,u=e.length;do{if(i>=u||o>49)throw ir.bytes=0,new RangeError("Could not decode varint");s=e[i++],r+=o<28?(s&Wn)<<o:(s&Wn)*Math.pow(2,o),o+=7}while(s>=Fs);return ir.bytes=i-n,r}});var Yn=ze((lu,Qn)=>{var Vs=Math.pow(2,7),Ps=Math.pow(2,14),Hs=Math.pow(2,21),js=Math.pow(2,28),qs=Math.pow(2,35),Gs=Math.pow(2,42),Ks=Math.pow(2,49),Ws=Math.pow(2,56),Xs=Math.pow(2,63);Qn.exports=function(e){return e<Vs?1:e<Ps?2:e<Hs?3:e<js?4:e<qs?5:e<Gs?6:e<Ks?7:e<Ws?8:e<Xs?9:10}});var yt=ze((pu,Zn)=>{Zn.exports={encode:Kn(),decode:Jn(),encodingLength:Yn()}});var ui=ze(()=>{});var za={};_r(za,{CarBlockIterator:()=>Rt,CarBufferReader:()=>bt,CarBufferWriter:()=>xr,CarCIDIterator:()=>Dt,CarIndexedReader:()=>$t,CarIndexer:()=>ge,CarReader:()=>we,CarWriter:()=>Ot,contentType:()=>Da});var Ti=["string","number","bigint","symbol"],Bi=["Function","Generator","AsyncGenerator","GeneratorFunction","AsyncGeneratorFunction","AsyncFunction","Observable","Array","Buffer","Object","RegExp","Date","Error","Map","Set","WeakMap","WeakSet","ArrayBuffer","SharedArrayBuffer","DataView","Promise","URL","HTMLElement","Int8Array","Uint8Array","Uint8ClampedArray","Int16Array","Uint16Array","Int32Array","Uint32Array","Float32Array","Float64Array","BigInt64Array","BigUint64Array"];function Ar(e){if(e===null)return"null";if(e===void 0)return"undefined";if(e===!0||e===!1)return"boolean";let t=typeof e;if(Ti.includes(t))return t;if(t==="function")return"Function";if(Array.isArray(e))return"Array";if(Si(e))return"Buffer";let r=Ii(e);return r||"Object"}function Si(e){return e&&e.constructor&&e.constructor.isBuffer&&e.constructor.isBuffer.call(null,e)}function Ii(e){let t=Object.prototype.toString.call(e).slice(8,-1);if(Bi.includes(t))return t}var c=class{constructor(t,r,n){this.major=t,this.majorEncoded=t<<5,this.name=r,this.terminal=n}toString(){return`Type[${this.major}].${this.name}`}compare(t){return this.major<t.major?-1:this.major>t.major?1:0}};c.uint=new c(0,"uint",!0);c.negint=new c(1,"negint",!0);c.bytes=new c(2,"bytes",!0);c.string=new c(3,"string",!0);c.array=new c(4,"array",!1);c.map=new c(5,"map",!1);c.tag=new c(6,"tag",!1);c.float=new c(7,"float",!0);c.false=new c(7,"false",!0);c.true=new c(7,"true",!0);c.null=new c(7,"null",!0);c.undefined=new c(7,"undefined",!0);c.break=new c(7,"break",!0);var p=class{constructor(t,r,n){this.type=t,this.value=r,this.encodedLength=n,this.encodedBytes=void 0,this.byteValue=void 0}toString(){return`Token[${this.type}].${this.value}`}};var be=globalThis.process&&!globalThis.process.browser&&globalThis.Buffer&&typeof globalThis.Buffer.isBuffer=="function",Ci=new TextDecoder,Ni=new TextEncoder;function rt(e){return be&&globalThis.Buffer.isBuffer(e)}function Ft(e){return e instanceof Uint8Array?rt(e)?new Uint8Array(e.buffer,e.byteOffset,e.byteLength):e:Uint8Array.from(e)}var Sr=be?(e,t,r)=>r-t>64?globalThis.Buffer.from(e.subarray(t,r)).toString("utf8"):Tr(e,t,r):(e,t,r)=>r-t>64?Ci.decode(e.subarray(t,r)):Tr(e,t,r),Ir=be?e=>e.length>64?globalThis.Buffer.from(e):Ur(e):e=>e.length>64?Ni.encode(e):Ur(e),X=e=>Uint8Array.from(e),Ee=be?(e,t,r)=>rt(e)?new Uint8Array(e.subarray(t,r)):e.slice(t,r):(e,t,r)=>e.slice(t,r),Cr=be?(e,t)=>(e=e.map(r=>r instanceof Uint8Array?r:globalThis.Buffer.from(r)),Ft(globalThis.Buffer.concat(e,t))):(e,t)=>{let r=new Uint8Array(t),n=0;for(let o of e)n+o.length>r.length&&(o=o.subarray(0,r.length-n)),r.set(o,n),n+=o.length;return r},Nr=be?e=>globalThis.Buffer.allocUnsafe(e):e=>new Uint8Array(e);function $r(e,t){if(rt(e)&&rt(t))return e.compare(t);for(let r=0;r<e.length;r++)if(e[r]!==t[r])return e[r]<t[r]?-1:1;return 0}function Ur(e,t=1/0){let r,n=e.length,o=null,i=[];for(let s=0;s<n;++s){if(r=e.charCodeAt(s),r>55295&&r<57344){if(!o){if(r>56319){(t-=3)>-1&&i.push(239,191,189);continue}else if(s+1===n){(t-=3)>-1&&i.push(239,191,189);continue}o=r;continue}if(r<56320){(t-=3)>-1&&i.push(239,191,189),o=r;continue}r=(o-55296<<10|r-56320)+65536}else o&&(t-=3)>-1&&i.push(239,191,189);if(o=null,r<128){if((t-=1)<0)break;i.push(r)}else if(r<2048){if((t-=2)<0)break;i.push(r>>6|192,r&63|128)}else if(r<65536){if((t-=3)<0)break;i.push(r>>12|224,r>>6&63|128,r&63|128)}else if(r<1114112){if((t-=4)<0)break;i.push(r>>18|240,r>>12&63|128,r>>6&63|128,r&63|128)}else throw new Error("Invalid code point")}return i}function Tr(e,t,r){let n=[];for(;t<r;){let o=e[t],i=null,s=o>239?4:o>223?3:o>191?2:1;if(t+s<=r){let u,h,y,m;switch(s){case 1:o<128&&(i=o);break;case 2:u=e[t+1],(u&192)===128&&(m=(o&31)<<6|u&63,m>127&&(i=m));break;case 3:u=e[t+1],h=e[t+2],(u&192)===128&&(h&192)===128&&(m=(o&15)<<12|(u&63)<<6|h&63,m>2047&&(m<55296||m>57343)&&(i=m));break;case 4:u=e[t+1],h=e[t+2],y=e[t+3],(u&192)===128&&(h&192)===128&&(y&192)===128&&(m=(o&15)<<18|(u&63)<<12|(h&63)<<6|y&63,m>65535&&m<1114112&&(i=m))}}i===null?(i=65533,s=1):i>65535&&(i-=65536,n.push(i>>>10&1023|55296),i=56320|i&1023),n.push(i),t+=s}return $i(n)}var Br=4096;function $i(e){let t=e.length;if(t<=Br)return String.fromCharCode.apply(String,e);let r="",n=0;for(;n<t;)r+=String.fromCharCode.apply(String,e.slice(n,n+=Br));return r}var Mi=256,Oe=class{constructor(t=Mi){this.chunkSize=t,this.cursor=0,this.maxCursor=-1,this.chunks=[],this._initReuseChunk=null}reset(){this.cursor=0,this.maxCursor=-1,this.chunks.length&&(this.chunks=[]),this._initReuseChunk!==null&&(this.chunks.push(this._initReuseChunk),this.maxCursor=this._initReuseChunk.length-1)}push(t){let r=this.chunks[this.chunks.length-1];if(this.cursor+t.length<=this.maxCursor+1){let o=r.length-(this.maxCursor-this.cursor)-1;r.set(t,o)}else{if(r){let o=r.length-(this.maxCursor-this.cursor)-1;o<r.length&&(this.chunks[this.chunks.length-1]=r.subarray(0,o),this.maxCursor=this.cursor-1)}t.length<64&&t.length<this.chunkSize?(r=Nr(this.chunkSize),this.chunks.push(r),this.maxCursor+=r.length,this._initReuseChunk===null&&(this._initReuseChunk=r),r.set(t,0)):(this.chunks.push(t),this.maxCursor+=t.length)}this.cursor+=t.length}toBytes(t=!1){let r;if(this.chunks.length===1){let n=this.chunks[0];t&&this.cursor>n.length/2?(r=this.cursor===n.length?n:n.subarray(0,this.cursor),this._initReuseChunk=null,this.chunks=[]):r=Ee(n,0,this.cursor)}else r=Cr(this.chunks,this.cursor);return t&&this.reset(),r}};var g="CBOR decode error:",Vt="CBOR encode error:",Le=[];Le[23]=1;Le[24]=2;Le[25]=3;Le[26]=5;Le[27]=9;function te(e,t,r){if(e.length-t<r)throw new Error(`${g} not enough data for type`)}var k=[24,256,65536,4294967296,BigInt("18446744073709551616")];function B(e,t,r){te(e,t,1);let n=e[t];if(r.strict===!0&&n<k[0])throw new Error(`${g} integer encoded in more bytes than necessary (strict decode)`);return n}function S(e,t,r){te(e,t,2);let n=e[t]<<8|e[t+1];if(r.strict===!0&&n<k[1])throw new Error(`${g} integer encoded in more bytes than necessary (strict decode)`);return n}function I(e,t,r){te(e,t,4);let n=e[t]*16777216+(e[t+1]<<16)+(e[t+2]<<8)+e[t+3];if(r.strict===!0&&n<k[2])throw new Error(`${g} integer encoded in more bytes than necessary (strict decode)`);return n}function C(e,t,r){te(e,t,8);let n=e[t]*16777216+(e[t+1]<<16)+(e[t+2]<<8)+e[t+3],o=e[t+4]*16777216+(e[t+5]<<16)+(e[t+6]<<8)+e[t+7],i=(BigInt(n)<<BigInt(32))+BigInt(o);if(r.strict===!0&&i<k[3])throw new Error(`${g} integer encoded in more bytes than necessary (strict decode)`);if(i<=Number.MAX_SAFE_INTEGER)return Number(i);if(r.allowBigInt===!0)return i;throw new Error(`${g} integers outside of the safe integer range are not supported`)}function Mr(e,t,r,n){return new p(c.uint,B(e,t+1,n),2)}function Rr(e,t,r,n){return new p(c.uint,S(e,t+1,n),3)}function Dr(e,t,r,n){return new p(c.uint,I(e,t+1,n),5)}function zr(e,t,r,n){return new p(c.uint,C(e,t+1,n),9)}function z(e,t){return A(e,0,t.value)}function A(e,t,r){if(r<k[0]){let n=Number(r);e.push([t|n])}else if(r<k[1]){let n=Number(r);e.push([t|24,n])}else if(r<k[2]){let n=Number(r);e.push([t|25,n>>>8,n&255])}else if(r<k[3]){let n=Number(r);e.push([t|26,n>>>24&255,n>>>16&255,n>>>8&255,n&255])}else{let n=BigInt(r);if(n<k[4]){let o=[t|27,0,0,0,0,0,0,0],i=Number(n&BigInt(4294967295)),s=Number(n>>BigInt(32)&BigInt(4294967295));o[8]=i&255,i=i>>8,o[7]=i&255,i=i>>8,o[6]=i&255,i=i>>8,o[5]=i&255,o[4]=s&255,s=s>>8,o[3]=s&255,s=s>>8,o[2]=s&255,s=s>>8,o[1]=s&255,e.push(o)}else throw new Error(`${g} encountered BigInt larger than allowable range`)}}z.encodedSize=function(t){return A.encodedSize(t.value)};A.encodedSize=function(t){return t<k[0]?1:t<k[1]?2:t<k[2]?3:t<k[3]?5:9};z.compareTokens=function(t,r){return t.value<r.value?-1:t.value>r.value?1:0};function Or(e,t,r,n){return new p(c.negint,-1-B(e,t+1,n),2)}function Lr(e,t,r,n){return new p(c.negint,-1-S(e,t+1,n),3)}function Fr(e,t,r,n){return new p(c.negint,-1-I(e,t+1,n),5)}var Pt=BigInt(-1),Vr=BigInt(1);function Pr(e,t,r,n){let o=C(e,t+1,n);if(typeof o!="bigint"){let i=-1-o;if(i>=Number.MIN_SAFE_INTEGER)return new p(c.negint,i,9)}if(n.allowBigInt!==!0)throw new Error(`${g} integers outside of the safe integer range are not supported`);return new p(c.negint,Pt-BigInt(o),9)}function nt(e,t){let r=t.value,n=typeof r=="bigint"?r*Pt-Vr:r*-1-1;A(e,t.type.majorEncoded,n)}nt.encodedSize=function(t){let r=t.value,n=typeof r=="bigint"?r*Pt-Vr:r*-1-1;return n<k[0]?1:n<k[1]?2:n<k[2]?3:n<k[3]?5:9};nt.compareTokens=function(t,r){return t.value<r.value?1:t.value>r.value?-1:0};function Fe(e,t,r,n){te(e,t,r+n);let o=Ee(e,t+r,t+r+n);return new p(c.bytes,o,r+n)}function Hr(e,t,r,n){return Fe(e,t,1,r)}function jr(e,t,r,n){return Fe(e,t,2,B(e,t+1,n))}function qr(e,t,r,n){return Fe(e,t,3,S(e,t+1,n))}function Gr(e,t,r,n){return Fe(e,t,5,I(e,t+1,n))}function Kr(e,t,r,n){let o=C(e,t+1,n);if(typeof o=="bigint")throw new Error(`${g} 64-bit integer bytes lengths not supported`);return Fe(e,t,9,o)}function ot(e){return e.encodedBytes===void 0&&(e.encodedBytes=e.type===c.string?Ir(e.value):e.value),e.encodedBytes}function ke(e,t){let r=ot(t);A(e,t.type.majorEncoded,r.length),e.push(r)}ke.encodedSize=function(t){let r=ot(t);return A.encodedSize(r.length)+r.length};ke.compareTokens=function(t,r){return Di(ot(t),ot(r))};function Di(e,t){return e.length<t.length?-1:e.length>t.length?1:$r(e,t)}function Ve(e,t,r,n,o){let i=r+n;te(e,t,i);let s=new p(c.string,Sr(e,t+r,t+i),i);return o.retainStringBytes===!0&&(s.byteValue=Ee(e,t+r,t+i)),s}function Wr(e,t,r,n){return Ve(e,t,1,r,n)}function Xr(e,t,r,n){return Ve(e,t,2,B(e,t+1,n),n)}function Jr(e,t,r,n){return Ve(e,t,3,S(e,t+1,n),n)}function Qr(e,t,r,n){return Ve(e,t,5,I(e,t+1,n),n)}function Yr(e,t,r,n){let o=C(e,t+1,n);if(typeof o=="bigint")throw new Error(`${g} 64-bit integer string lengths not supported`);return Ve(e,t,9,o,n)}var Zr=ke;function _e(e,t,r,n){return new p(c.array,n,r)}function en(e,t,r,n){return _e(e,t,1,r)}function tn(e,t,r,n){return _e(e,t,2,B(e,t+1,n))}function rn(e,t,r,n){return _e(e,t,3,S(e,t+1,n))}function nn(e,t,r,n){return _e(e,t,5,I(e,t+1,n))}function on(e,t,r,n){let o=C(e,t+1,n);if(typeof o=="bigint")throw new Error(`${g} 64-bit integer array lengths not supported`);return _e(e,t,9,o)}function sn(e,t,r,n){if(n.allowIndefinite===!1)throw new Error(`${g} indefinite length items not allowed`);return _e(e,t,1,1/0)}function it(e,t){A(e,c.array.majorEncoded,t.value)}it.compareTokens=z.compareTokens;it.encodedSize=function(t){return A.encodedSize(t.value)};function ve(e,t,r,n){return new p(c.map,n,r)}function an(e,t,r,n){return ve(e,t,1,r)}function cn(e,t,r,n){return ve(e,t,2,B(e,t+1,n))}function un(e,t,r,n){return ve(e,t,3,S(e,t+1,n))}function fn(e,t,r,n){return ve(e,t,5,I(e,t+1,n))}function dn(e,t,r,n){let o=C(e,t+1,n);if(typeof o=="bigint")throw new Error(`${g} 64-bit integer map lengths not supported`);return ve(e,t,9,o)}function ln(e,t,r,n){if(n.allowIndefinite===!1)throw new Error(`${g} indefinite length items not allowed`);return ve(e,t,1,1/0)}function st(e,t){A(e,c.map.majorEncoded,t.value)}st.compareTokens=z.compareTokens;st.encodedSize=function(t){return A.encodedSize(t.value)};function pn(e,t,r,n){return new p(c.tag,r,1)}function hn(e,t,r,n){return new p(c.tag,B(e,t+1,n),2)}function yn(e,t,r,n){return new p(c.tag,S(e,t+1,n),3)}function mn(e,t,r,n){return new p(c.tag,I(e,t+1,n),5)}function gn(e,t,r,n){return new p(c.tag,C(e,t+1,n),9)}function at(e,t){A(e,c.tag.majorEncoded,t.value)}at.compareTokens=z.compareTokens;at.encodedSize=function(t){return A.encodedSize(t.value)};var Pi=20,Hi=21,ji=22,qi=23;function wn(e,t,r,n){if(n.allowUndefined===!1)throw new Error(`${g} undefined values are not supported`);return n.coerceUndefinedToNull===!0?new p(c.null,null,1):new p(c.undefined,void 0,1)}function xn(e,t,r,n){if(n.allowIndefinite===!1)throw new Error(`${g} indefinite length items not allowed`);return new p(c.break,void 0,1)}function Ht(e,t,r){if(r){if(r.allowNaN===!1&&Number.isNaN(e))throw new Error(`${g} NaN values are not supported`);if(r.allowInfinity===!1&&(e===1/0||e===-1/0))throw new Error(`${g} Infinity values are not supported`)}return new p(c.float,e,t)}function bn(e,t,r,n){return Ht(jt(e,t+1),3,n)}function En(e,t,r,n){return Ht(qt(e,t+1),5,n)}function kn(e,t,r,n){return Ht(Un(e,t+1),9,n)}function ct(e,t,r){let n=t.value;if(n===!1)e.push([c.float.majorEncoded|Pi]);else if(n===!0)e.push([c.float.majorEncoded|Hi]);else if(n===null)e.push([c.float.majorEncoded|ji]);else if(n===void 0)e.push([c.float.majorEncoded|qi]);else{let o,i=!1;(!r||r.float64!==!0)&&(vn(n),o=jt(H,1),n===o||Number.isNaN(n)?(H[0]=249,e.push(H.slice(0,3)),i=!0):(An(n),o=qt(H,1),n===o&&(H[0]=250,e.push(H.slice(0,5)),i=!0))),i||(Gi(n),o=Un(H,1),H[0]=251,e.push(H.slice(0,9)))}}ct.encodedSize=function(t,r){let n=t.value;if(n===!1||n===!0||n===null||n===void 0)return 1;if(!r||r.float64!==!0){vn(n);let o=jt(H,1);if(n===o||Number.isNaN(n))return 3;if(An(n),o=qt(H,1),n===o)return 5}return 9};var _n=new ArrayBuffer(9),O=new DataView(_n,1),H=new Uint8Array(_n,0);function vn(e){if(e===1/0)O.setUint16(0,31744,!1);else if(e===-1/0)O.setUint16(0,64512,!1);else if(Number.isNaN(e))O.setUint16(0,32256,!1);else{O.setFloat32(0,e);let t=O.getUint32(0),r=(t&2139095040)>>23,n=t&8388607;if(r===255)O.setUint16(0,31744,!1);else if(r===0)O.setUint16(0,(e&2147483648)>>16|n>>13,!1);else{let o=r-127;o<-24?O.setUint16(0,0):o<-14?O.setUint16(0,(t&2147483648)>>16|1<<24+o,!1):O.setUint16(0,(t&2147483648)>>16|o+15<<10|n>>13,!1)}}}function jt(e,t){if(e.length-t<2)throw new Error(`${g} not enough data for float16`);let r=(e[t]<<8)+e[t+1];if(r===31744)return 1/0;if(r===64512)return-1/0;if(r===32256)return NaN;let n=r>>10&31,o=r&1023,i;return n===0?i=o*2**-24:n!==31?i=(o+1024)*2**(n-25):i=o===0?1/0:NaN,r&32768?-i:i}function An(e){O.setFloat32(0,e,!1)}function qt(e,t){if(e.length-t<4)throw new Error(`${g} not enough data for float32`);let r=(e.byteOffset||0)+t;return new DataView(e.buffer,r,4).getFloat32(0,!1)}function Gi(e){O.setFloat64(0,e,!1)}function Un(e,t){if(e.length-t<8)throw new Error(`${g} not enough data for float64`);let r=(e.byteOffset||0)+t;return new DataView(e.buffer,r,8).getFloat64(0,!1)}ct.compareTokens=z.compareTokens;function w(e,t,r){throw new Error(`${g} encountered invalid minor (${r}) for major ${e[t]>>>5}`)}function ut(e){return()=>{throw new Error(`${g} ${e}`)}}var f=[];for(let e=0;e<=23;e++)f[e]=w;f[24]=Mr;f[25]=Rr;f[26]=Dr;f[27]=zr;f[28]=w;f[29]=w;f[30]=w;f[31]=w;for(let e=32;e<=55;e++)f[e]=w;f[56]=Or;f[57]=Lr;f[58]=Fr;f[59]=Pr;f[60]=w;f[61]=w;f[62]=w;f[63]=w;for(let e=64;e<=87;e++)f[e]=Hr;f[88]=jr;f[89]=qr;f[90]=Gr;f[91]=Kr;f[92]=w;f[93]=w;f[94]=w;f[95]=ut("indefinite length bytes/strings are not supported");for(let e=96;e<=119;e++)f[e]=Wr;f[120]=Xr;f[121]=Jr;f[122]=Qr;f[123]=Yr;f[124]=w;f[125]=w;f[126]=w;f[127]=ut("indefinite length bytes/strings are not supported");for(let e=128;e<=151;e++)f[e]=en;f[152]=tn;f[153]=rn;f[154]=nn;f[155]=on;f[156]=w;f[157]=w;f[158]=w;f[159]=sn;for(let e=160;e<=183;e++)f[e]=an;f[184]=cn;f[185]=un;f[186]=fn;f[187]=dn;f[188]=w;f[189]=w;f[190]=w;f[191]=ln;for(let e=192;e<=215;e++)f[e]=pn;f[216]=hn;f[217]=yn;f[218]=mn;f[219]=gn;f[220]=w;f[221]=w;f[222]=w;f[223]=w;for(let e=224;e<=243;e++)f[e]=ut("simple values are not supported");f[244]=w;f[245]=w;f[246]=w;f[247]=wn;f[248]=ut("simple values are not supported");f[249]=bn;f[250]=En;f[251]=kn;f[252]=w;f[253]=w;f[254]=w;f[255]=xn;var j=[];for(let e=0;e<24;e++)j[e]=new p(c.uint,e,1);for(let e=-1;e>=-24;e--)j[31-e]=new p(c.negint,e,1);j[64]=new p(c.bytes,new Uint8Array(0),1);j[96]=new p(c.string,"",1);j[128]=new p(c.array,0,1);j[160]=new p(c.map,0,1);j[244]=new p(c.false,!1,1);j[245]=new p(c.true,!0,1);j[246]=new p(c.null,null,1);function Tn(e){switch(e.type){case c.false:return X([244]);case c.true:return X([245]);case c.null:return X([246]);case c.bytes:return e.value.length?void 0:X([64]);case c.string:return e.value===""?X([96]):void 0;case c.array:return e.value===0?X([128]):void 0;case c.map:return e.value===0?X([160]):void 0;case c.uint:return e.value<24?X([Number(e.value)]):void 0;case c.negint:if(e.value>=-24)return X([31-Number(e.value)])}}var Wi={float64:!1,mapSorter:Qi,quickEncodeToken:Tn};function Xi(){let e=[];return e[c.uint.major]=z,e[c.negint.major]=nt,e[c.bytes.major]=ke,e[c.string.major]=Zr,e[c.array.major]=it,e[c.map.major]=st,e[c.tag.major]=at,e[c.float.major]=ct,e}var Bn=Xi(),Gt=new Oe,dt=class e{constructor(t,r){this.obj=t,this.parent=r}includes(t){let r=this;do if(r.obj===t)return!0;while(r=r.parent);return!1}static createCheck(t,r){if(t&&t.includes(r))throw new Error(`${Vt} object contains circular references`);return new e(r,t)}},ie={null:new p(c.null,null),undefined:new p(c.undefined,void 0),true:new p(c.true,!0),false:new p(c.false,!1),emptyArray:new p(c.array,0),emptyMap:new p(c.map,0)},se={number(e,t,r,n){return!Number.isInteger(e)||!Number.isSafeInteger(e)?new p(c.float,e):e>=0?new p(c.uint,e):new p(c.negint,e)},bigint(e,t,r,n){return e>=BigInt(0)?new p(c.uint,e):new p(c.negint,e)},Uint8Array(e,t,r,n){return new p(c.bytes,e)},string(e,t,r,n){return new p(c.string,e)},boolean(e,t,r,n){return e?ie.true:ie.false},null(e,t,r,n){return ie.null},undefined(e,t,r,n){return ie.undefined},ArrayBuffer(e,t,r,n){return new p(c.bytes,new Uint8Array(e))},DataView(e,t,r,n){return new p(c.bytes,new Uint8Array(e.buffer,e.byteOffset,e.byteLength))},Array(e,t,r,n){if(!e.length)return r.addBreakTokens===!0?[ie.emptyArray,new p(c.break)]:ie.emptyArray;n=dt.createCheck(n,e);let o=[],i=0;for(let s of e)o[i++]=ft(s,r,n);return r.addBreakTokens?[new p(c.array,e.length),o,new p(c.break)]:[new p(c.array,e.length),o]},Object(e,t,r,n){let o=t!=="Object",i=o?e.keys():Object.keys(e),s=o?e.size:i.length;if(!s)return r.addBreakTokens===!0?[ie.emptyMap,new p(c.break)]:ie.emptyMap;n=dt.createCheck(n,e);let u=[],h=0;for(let y of i)u[h++]=[ft(y,r,n),ft(o?e.get(y):e[y],r,n)];return Ji(u,r),r.addBreakTokens?[new p(c.map,s),u,new p(c.break)]:[new p(c.map,s),u]}};se.Map=se.Object;se.Buffer=se.Uint8Array;for(let e of"Uint8Clamped Uint16 Uint32 Int8 Int16 Int32 BigUint64 BigInt64 Float32 Float64".split(" "))se[`${e}Array`]=se.DataView;function ft(e,t={},r){let n=Ar(e),o=t&&t.typeEncoders&&t.typeEncoders[n]||se[n];if(typeof o=="function"){let s=o(e,n,t,r);if(s!=null)return s}let i=se[n];if(!i)throw new Error(`${Vt} unsupported type: ${n}`);return i(e,n,t,r)}function Ji(e,t){t.mapSorter&&e.sort(t.mapSorter)}function Qi(e,t){let r=Array.isArray(e[0])?e[0][0]:e[0],n=Array.isArray(t[0])?t[0][0]:t[0];if(r.type!==n.type)return r.type.compare(n.type);let o=r.type.major,i=Bn[o].compareTokens(r,n);return i===0&&console.warn("WARNING: complex key types used, CBOR key sorting guarantees are gone"),i}function Sn(e,t,r,n){if(Array.isArray(t))for(let o of t)Sn(e,o,r,n);else r[t.type.major](e,t,n)}function Yi(e,t,r){let n=ft(e,r);if(!Array.isArray(n)&&r.quickEncodeToken){let o=r.quickEncodeToken(n);if(o)return o;let i=t[n.type.major];if(i.encodedSize){let s=i.encodedSize(n,r),u=new Oe(s);if(i(u,n,r),u.chunks.length!==1)throw new Error(`Unexpected error: pre-calculated length for ${n} was wrong`);return Ft(u.chunks[0])}}return Gt.reset(),Sn(Gt,n,t,r),Gt.toBytes(!0)}function Kt(e,t){return t=Object.assign({},Wi,t),Yi(e,Bn,t)}var Zi={strict:!1,allowIndefinite:!0,allowUndefined:!0,allowBigInt:!0},Wt=class{constructor(t,r={}){this.pos=0,this.data=t,this.options=r}done(){return this.pos>=this.data.length}next(){let t=this.data[this.pos],r=j[t];if(r===void 0){let n=f[t];if(!n)throw new Error(`${g} no decoder for major type ${t>>>5} (byte 0x${t.toString(16).padStart(2,"0")})`);let o=t&31;r=n(this.data,this.pos,o,this.options)}return this.pos+=r.encodedLength,r}},Pe=Symbol.for("DONE"),lt=Symbol.for("BREAK");function es(e,t,r){let n=[];for(let o=0;o<e.value;o++){let i=He(t,r);if(i===lt){if(e.value===1/0)break;throw new Error(`${g} got unexpected break to lengthed array`)}if(i===Pe)throw new Error(`${g} found array but not enough entries (got ${o}, expected ${e.value})`);n[o]=i}return n}function ts(e,t,r){let n=r.useMaps===!0,o=n?void 0:{},i=n?new Map:void 0;for(let s=0;s<e.value;s++){let u=He(t,r);if(u===lt){if(e.value===1/0)break;throw new Error(`${g} got unexpected break to lengthed map`)}if(u===Pe)throw new Error(`${g} found map but not enough entries (got ${s} [no key], expected ${e.value})`);if(n!==!0&&typeof u!="string")throw new Error(`${g} non-string keys not supported (got ${typeof u})`);if(r.rejectDuplicateMapKeys===!0&&(n&&i.has(u)||!n&&u in o))throw new Error(`${g} found repeat map key "${u}"`);let h=He(t,r);if(h===Pe)throw new Error(`${g} found map but not enough entries (got ${s} [no value], expected ${e.value})`);n?i.set(u,h):o[u]=h}return n?i:o}function He(e,t){if(e.done())return Pe;let r=e.next();if(r.type===c.break)return lt;if(r.type.terminal)return r.value;if(r.type===c.array)return es(r,e,t);if(r.type===c.map)return ts(r,e,t);if(r.type===c.tag){if(t.tags&&typeof t.tags[r.value]=="function"){let n=He(e,t);return t.tags[r.value](n)}throw new Error(`${g} tag not supported (${r.value})`)}throw new Error("unsupported")}function Xt(e,t){if(!(e instanceof Uint8Array))throw new Error(`${g} data to decode must be a Uint8Array`);t=Object.assign({},Zi,t);let r=t.tokenizer||new Wt(e,t),n=He(r,t);if(n===Pe)throw new Error(`${g} did not find any content to decode`);if(n===lt)throw new Error(`${g} got unexpected break`);if(!r.done())throw new Error(`${g} too many terminals, data makes no sense`);return n}function ns(e,t){if(e.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),n=0;n<r.length;n++)r[n]=255;for(var o=0;o<e.length;o++){var i=e.charAt(o),s=i.charCodeAt(0);if(r[s]!==255)throw new TypeError(i+" is ambiguous");r[s]=o}var u=e.length,h=e.charAt(0),y=Math.log(u)/Math.log(256),m=Math.log(256)/Math.log(u);function xe(E){if(E instanceof Uint8Array||(ArrayBuffer.isView(E)?E=new Uint8Array(E.buffer,E.byteOffset,E.byteLength):Array.isArray(E)&&(E=Uint8Array.from(E))),!(E instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(E.length===0)return"";for(var T=0,he=0,V=0,G=E.length;V!==G&&E[V]===0;)V++,T++;for(var K=(G-V)*m+1>>>0,D=new Uint8Array(K);V!==G;){for(var W=E[V],oe=0,P=K-1;(W!==0||oe<he)&&P!==-1;P--,oe++)W+=256*D[P]>>>0,D[P]=W%u>>>0,W=W/u>>>0;if(W!==0)throw new Error("Non-zero carry");he=oe,V++}for(var ee=K-he;ee!==K&&D[ee]===0;)ee++;for(var Ze=h.repeat(T);ee<K;++ee)Ze+=e.charAt(D[ee]);return Ze}function Ye(E){if(typeof E!="string")throw new TypeError("Expected String");if(E.length===0)return new Uint8Array;var T=0;if(E[T]!==" "){for(var he=0,V=0;E[T]===h;)he++,T++;for(var G=(E.length-T)*y+1>>>0,K=new Uint8Array(G);E[T];){var D=r[E.charCodeAt(T)];if(D===255)return;for(var W=0,oe=G-1;(D!==0||W<V)&&oe!==-1;oe--,W++)D+=u*K[oe]>>>0,K[oe]=D%256>>>0,D=D/256>>>0;if(D!==0)throw new Error("Non-zero carry");V=W,T++}if(E[T]!==" "){for(var P=G-V;P!==G&&K[P]===0;)P++;for(var ee=new Uint8Array(he+(G-P)),Ze=he;P!==G;)ee[Ze++]=K[P++];return ee}}}function bi(E){var T=Ye(E);if(T)return T;throw new Error(`Non-${t} character`)}return{encode:xe,decodeUnsafe:Ye,decode:bi}}var os=ns,is=os,In=is;var zc=new Uint8Array(0);var Cn=(e,t)=>{if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0},Ae=e=>{if(e instanceof Uint8Array&&e.constructor.name==="Uint8Array")return e;if(e instanceof ArrayBuffer)return new Uint8Array(e);if(ArrayBuffer.isView(e))return new Uint8Array(e.buffer,e.byteOffset,e.byteLength);throw new Error("Unknown type, must be binary type")};var Jt=class{constructor(t,r,n){this.name=t,this.prefix=r,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},Qt=class{constructor(t,r,n){if(this.name=t,this.prefix=r,r.codePointAt(0)===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=r.codePointAt(0),this.baseDecode=n}decode(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return Nn(this,t)}},Yt=class{constructor(t){this.decoders=t}or(t){return Nn(this,t)}decode(t){let r=t[0],n=this.decoders[r];if(n)return n.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}},Nn=(e,t)=>new Yt({...e.decoders||{[e.prefix]:e},...t.decoders||{[t.prefix]:t}}),Zt=class{constructor(t,r,n,o){this.name=t,this.prefix=r,this.baseEncode=n,this.baseDecode=o,this.encoder=new Jt(t,r,n),this.decoder=new Qt(t,r,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}},$n=({name:e,prefix:t,encode:r,decode:n})=>new Zt(e,t,r,n),er=({prefix:e,name:t,alphabet:r})=>{let{encode:n,decode:o}=In(r,t);return $n({prefix:e,name:t,encode:n,decode:i=>Ae(o(i))})},ss=(e,t,r,n)=>{let o={};for(let m=0;m<t.length;++m)o[t[m]]=m;let i=e.length;for(;e[i-1]==="=";)--i;let s=new Uint8Array(i*r/8|0),u=0,h=0,y=0;for(let m=0;m<i;++m){let xe=o[e[m]];if(xe===void 0)throw new SyntaxError(`Non-${n} character`);h=h<<r|xe,u+=r,u>=8&&(u-=8,s[y++]=255&h>>u)}if(u>=r||255&h<<8-u)throw new SyntaxError("Unexpected end of data");return s},as=(e,t,r)=>{let n=t[t.length-1]==="=",o=(1<<r)-1,i="",s=0,u=0;for(let h=0;h<e.length;++h)for(u=u<<8|e[h],s+=8;s>r;)s-=r,i+=t[o&u>>s];if(s&&(i+=t[o&u<<r-s]),n)for(;i.length*r&7;)i+="=";return i},J=({name:e,prefix:t,bitsPerChar:r,alphabet:n})=>$n({prefix:t,name:e,encode(o){return as(o,n,r)},decode(o){return ss(o,n,r,e)}});var je=J({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Hc=J({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),jc=J({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),qc=J({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Gc=J({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Kc=J({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Wc=J({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Xc=J({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Jc=J({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var re=er({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Zc=er({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var cs=Dn,Mn=128,us=127,fs=~us,ds=Math.pow(2,31);function Dn(e,t,r){t=t||[],r=r||0;for(var n=r;e>=ds;)t[r++]=e&255|Mn,e/=128;for(;e&fs;)t[r++]=e&255|Mn,e>>>=7;return t[r]=e|0,Dn.bytes=r-n+1,t}var ls=tr,ps=128,Rn=127;function tr(e,n){var r=0,n=n||0,o=0,i=n,s,u=e.length;do{if(i>=u)throw tr.bytes=0,new RangeError("Could not decode varint");s=e[i++],r+=o<28?(s&Rn)<<o:(s&Rn)*Math.pow(2,o),o+=7}while(s>=ps);return tr.bytes=i-n,r}var hs=Math.pow(2,7),ys=Math.pow(2,14),ms=Math.pow(2,21),gs=Math.pow(2,28),ws=Math.pow(2,35),xs=Math.pow(2,42),bs=Math.pow(2,49),Es=Math.pow(2,56),ks=Math.pow(2,63),_s=function(e){return e<hs?1:e<ys?2:e<ms?3:e<gs?4:e<ws?5:e<xs?6:e<bs?7:e<Es?8:e<ks?9:10},vs={encode:cs,decode:ls,encodingLength:_s},As=vs,qe=As;var Ge=(e,t=0)=>[qe.decode(e,t),qe.decode.bytes],Ue=(e,t,r=0)=>(qe.encode(e,t,r),t),Te=e=>qe.encodingLength(e);var On=(e,t)=>{let r=t.byteLength,n=Te(e),o=n+Te(r),i=new Uint8Array(o+r);return Ue(e,i,0),Ue(r,i,n),i.set(t,o),new Be(e,r,t,i)},ae=e=>{let t=Ae(e),[r,n]=Ge(t),[o,i]=Ge(t.subarray(n)),s=t.subarray(n+i);if(s.byteLength!==o)throw new Error("Incorrect length");return new Be(r,o,s,t)},Ln=(e,t)=>{if(e===t)return!0;{let r=t;return e.code===r.code&&e.size===r.size&&r.bytes instanceof Uint8Array&&Cn(e.bytes,r.bytes)}},Be=class{constructor(t,r,n,o){this.code=t,this.size=r,this.digest=n,this.bytes=o}};var Fn=(e,t)=>{let{bytes:r,version:n}=e;switch(n){case 0:return Ts(r,nr(e),t||re.encoder);default:return Bs(r,nr(e),t||je.encoder)}};var Vn=new WeakMap,nr=e=>{let t=Vn.get(e);if(t==null){let r=new Map;return Vn.set(e,r),r}return t},_=class e{constructor(t,r,n,o){this.code=r,this.version=t,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:t,multihash:r}=this;if(t!==Ke)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==Ss)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return e.createV0(r)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:t,digest:r}=this.multihash,n=On(t,r);return e.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(t){return e.equals(this,t)}static equals(t,r){let n=r;return n&&t.code===n.code&&t.version===n.version&&Ln(t.multihash,n.multihash)}toString(t){return Fn(this,t)}toJSON(){return{"/":Fn(this)}}link(){return this}get[Symbol.toStringTag](){return"CID"}[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(t){if(t==null)return null;let r=t;if(r instanceof e)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:o,multihash:i,bytes:s}=r;return new e(n,o,i,s||Pn(n,o,i.bytes))}else if(r[Is]===!0){let{version:n,multihash:o,code:i}=r,s=ae(o);return e.create(n,i,s)}else return null}static create(t,r,n){if(typeof r!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(t){case 0:{if(r!==Ke)throw new Error(`Version 0 CID must use dag-pb (code: ${Ke}) block encoding`);return new e(t,r,n,n.bytes)}case 1:{let o=Pn(t,r,n.bytes);return new e(t,r,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return e.create(0,Ke,t)}static createV1(t,r){return e.create(1,t,r)}static decode(t){let[r,n]=e.decodeFirst(t);if(n.length)throw new Error("Incorrect length");return r}static decodeFirst(t){let r=e.inspectBytes(t),n=r.size-r.multihashSize,o=Ae(t.subarray(n,n+r.multihashSize));if(o.byteLength!==r.multihashSize)throw new Error("Incorrect length");let i=o.subarray(r.multihashSize-r.digestSize),s=new Be(r.multihashCode,r.digestSize,i,o);return[r.version===0?e.createV0(s):e.createV1(r.codec,s),t.subarray(r.size)]}static inspectBytes(t){let r=0,n=()=>{let[xe,Ye]=Ge(t.subarray(r));return r+=Ye,xe},o=n(),i=Ke;if(o===18?(o=0,r=0):i=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let s=r,u=n(),h=n(),y=r+h,m=y-s;return{version:o,codec:i,multihashCode:u,digestSize:h,multihashSize:m,size:y}}static parse(t,r){let[n,o]=Us(t,r),i=e.decode(o);if(i.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return nr(i).set(n,t),i}},Us=(e,t)=>{switch(e[0]){case"Q":{let r=t||re;return[re.prefix,r.decode(`${re.prefix}${e}`)]}case re.prefix:{let r=t||re;return[re.prefix,r.decode(e)]}case je.prefix:{let r=t||je;return[je.prefix,r.decode(e)]}default:{if(t==null)throw Error("To parse non base32 or base58btc encoded CID multibase decoder must be provided");return[e[0],t.decode(e)]}}},Ts=(e,t,r)=>{let{prefix:n}=r;if(n!==re.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let o=t.get(n);if(o==null){let i=r.encode(e).slice(1);return t.set(n,i),i}else return o},Bs=(e,t,r)=>{let{prefix:n}=r,o=t.get(n);if(o==null){let i=r.encode(e);return t.set(n,i),i}else return o},Ke=112,Ss=18,Pn=(e,t,r)=>{let n=Te(e),o=n+Te(t),i=new Uint8Array(o+r.byteLength);return Ue(e,i,0),Ue(t,i,n),i.set(r,o),i},Is=Symbol.for("@ipld/js-cid/CID");var Hn=42;function Cs(e){if(e.asCID!==e&&e["/"]!==e.bytes)return null;let t=_.asCID(e);if(!t)return null;let r=new Uint8Array(t.bytes.byteLength+1);return r.set(t.bytes,1),[new p(c.tag,Hn),new p(c.bytes,r)]}function Ns(){throw new Error("`undefined` is not supported by the IPLD Data Model and cannot be encoded")}function $s(e){if(Number.isNaN(e))throw new Error("`NaN` is not supported by the IPLD Data Model and cannot be encoded");if(e===1/0||e===-1/0)throw new Error("`Infinity` and `-Infinity` is not supported by the IPLD Data Model and cannot be encoded");return null}var Ms={float64:!0,typeEncoders:{Object:Cs,undefined:Ns,number:$s}};function Rs(e){if(e[0]!==0)throw new Error("Invalid CID for CBOR tag 42; expected leading 0x00");return _.decode(e.subarray(1))}var jn={allowIndefinite:!1,coerceUndefinedToNull:!0,allowNaN:!1,allowInfinity:!1,allowBigInt:!0,strict:!0,useMaps:!1,rejectDuplicateMapKeys:!0,tags:[]};jn.tags[Hn]=Rs;var pt=e=>Kt(e,Ms),ht=e=>Xt(e,jn);var ce=tt(yt(),1),ue={SHA2_256:18,LENGTH:32,DAG_PB:112},mt=16+8+8+8;function Q(e,t){if(!e.length)throw new Error("Unexpected end of data");let r=ce.default.decode(e);return t.seek(ce.default.decode.bytes),r}function gt(e){let t=new DataView(e.buffer,e.byteOffset,e.byteLength),r=0;return{version:2,characteristics:[t.getBigUint64(r,!0),t.getBigUint64(r+=8,!0)],dataOffset:Number(t.getBigUint64(r+=8,!0)),dataSize:Number(t.getBigUint64(r+=8,!0)),indexOffset:Number(t.getBigUint64(r+=8,!0))}}function wt(e){ce.default.decode(e);let t=ce.default.decode.bytes,r=ce.default.decode(e.subarray(ce.default.decode.bytes)),n=ce.default.decode.bytes;return t+n+r}var fe={Null:e=>e===null,Int:e=>Number.isInteger(e),Float:e=>typeof e=="number"&&Number.isFinite(e),String:e=>typeof e=="string",Bool:e=>typeof e=="boolean",Bytes:e=>e instanceof Uint8Array,Link:e=>!fe.Null(e)&&typeof e=="object"&&e.asCID===e,List:e=>Array.isArray(e),Map:e=>!fe.Null(e)&&typeof e=="object"&&e.asCID!==e&&!fe.List(e)&&!fe.Bytes(e)},Se={Int:fe.Int,"CarHeader > version":e=>Se.Int(e),"CarHeader > roots (anon) > valueType (anon)":fe.Link,"CarHeader > roots (anon)":e=>fe.List(e)&&Array.prototype.every.call(e,Se["CarHeader > roots (anon) > valueType (anon)"]),"CarHeader > roots":e=>Se["CarHeader > roots (anon)"](e),CarHeader:e=>{let t=e&&Object.keys(e);return fe.Map(e)&&["version"].every(r=>t.includes(r))&&Object.entries(e).every(([r,n])=>Se["CarHeader > "+r]&&Se["CarHeader > "+r](n))}},xt=Se.CarHeader;function eo(e,t){let r=Q(e.upTo(8),e);if(r===0)throw new Error("Invalid CAR header (zero length)");let n=e.exactly(r,!0),o=ht(n);if(!xt(o))throw new Error("Invalid CAR header format");if(o.version!==1&&o.version!==2||t!==void 0&&o.version!==t)throw new Error(`Invalid CAR version: ${o.version}${t!==void 0?` (expected ${t})`:""}`);let i=Array.isArray(o.roots);if(o.version===1&&!i||o.version===2&&i)throw new Error("Invalid CAR header format");if(o.version===1)return o;let s=gt(e.exactly(mt,!0));e.seek(s.dataOffset-e.pos);let u=eo(e,1);return Object.assign(u,s)}function Js(e){let t=e.exactly(2,!1);if(t[0]===ue.SHA2_256&&t[1]===ue.LENGTH){let s=e.exactly(34,!0),u=ae(s);return _.create(0,ue.DAG_PB,u)}let r=Q(e.upTo(8),e);if(r!==1)throw new Error(`Unexpected CID version (${r})`);let n=Q(e.upTo(8),e),o=e.exactly(wt(e.upTo(8)),!0),i=ae(o);return _.create(r,n,i)}function Qs(e){let t=e.pos,r=Q(e.upTo(8),e);if(r===0)throw new Error("Invalid CAR section (zero length)");r+=e.pos-t;let n=Js(e),o=r-Number(e.pos-t);return{cid:n,length:r,blockLength:o}}function to(e){let t=Ys(e),r=eo(t);if(r.version===2){let o=t.pos-r.dataOffset;t=Zs(t,r.dataSize-o)}let n=[];for(;t.upTo(8).length>0;){let{cid:o,blockLength:i}=Qs(t);n.push({cid:o,bytes:t.exactly(i,!0)})}return{header:r,blocks:n}}function Ys(e){let t=0;return{upTo(r){return e.subarray(t,t+Math.min(r,e.length-t))},exactly(r,n=!1){if(r>e.length-t)throw new Error("Unexpected end of data");let o=e.subarray(t,t+r);return n&&(t+=r),o},seek(r){t+=r},get pos(){return t}}}function Zs(e,t){let r=0;return{upTo(n){let o=e.upTo(n);return o.length+r>t&&(o=o.subarray(0,t-r)),o},exactly(n,o=!1){let i=e.exactly(n,o);if(i.length+r>t)throw new Error("Unexpected end of data");return o&&(r+=n),i},seek(n){r+=n,e.seek(n)},get pos(){return e.pos}}}var bt=class e{constructor(t,r){this._header=t,this._blocks=r,this._cids=void 0}get version(){return this._header.version}getRoots(){return this._header.roots}has(t){return this._blocks.some(r=>r.cid.equals(t))}get(t){return this._blocks.find(r=>r.cid.equals(t))}blocks(){return this._blocks}cids(){return this._cids||(this._cids=this._blocks.map(t=>t.cid)),this._cids}static fromBytes(t){if(!(t instanceof Uint8Array))throw new TypeError("fromBytes() requires a Uint8Array");let{header:r,blocks:n}=to(t);return new e(r,n)}};var xr={};_r(xr,{addBlock:()=>ai,addRoot:()=>si,blockLength:()=>Aa,calculateHeaderLength:()=>gr,close:()=>ci,createWriter:()=>Sa,estimateHeaderLength:()=>Ba,headerLength:()=>wr,resizeHeader:()=>mr});var ta=["string","number","bigint","symbol"],ra=["Function","Generator","AsyncGenerator","GeneratorFunction","AsyncGeneratorFunction","AsyncFunction","Observable","Array","Buffer","Object","RegExp","Date","Error","Map","Set","WeakMap","WeakSet","ArrayBuffer","SharedArrayBuffer","DataView","Promise","URL","HTMLElement","Int8Array","Uint8Array","Uint8ClampedArray","Int16Array","Uint16Array","Int32Array","Uint32Array","Float32Array","Float64Array","BigInt64Array","BigUint64Array"];function ro(e){if(e===null)return"null";if(e===void 0)return"undefined";if(e===!0||e===!1)return"boolean";let t=typeof e;if(ta.includes(t))return t;if(t==="function")return"Function";if(Array.isArray(e))return"Array";if(na(e))return"Buffer";let r=oa(e);return r||"Object"}function na(e){return e&&e.constructor&&e.constructor.isBuffer&&e.constructor.isBuffer.call(null,e)}function oa(e){let t=Object.prototype.toString.call(e).slice(8,-1);if(ra.includes(t))return t}var a=class{constructor(t,r,n){this.major=t,this.majorEncoded=t<<5,this.name=r,this.terminal=n}toString(){return`Type[${this.major}].${this.name}`}compare(t){return this.major<t.major?-1:this.major>t.major?1:0}};a.uint=new a(0,"uint",!0);a.negint=new a(1,"negint",!0);a.bytes=new a(2,"bytes",!0);a.string=new a(3,"string",!0);a.array=new a(4,"array",!1);a.map=new a(5,"map",!1);a.tag=new a(6,"tag",!1);a.float=new a(7,"float",!0);a.false=new a(7,"false",!0);a.true=new a(7,"true",!0);a.null=new a(7,"null",!0);a.undefined=new a(7,"undefined",!0);a.break=new a(7,"break",!0);var l=class{constructor(t,r,n){this.type=t,this.value=r,this.encodedLength=n,this.encodedBytes=void 0,this.byteValue=void 0}toString(){return`Token[${this.type}].${this.value}`}};var Ie=globalThis.process&&!globalThis.process.browser&&globalThis.Buffer&&typeof globalThis.Buffer.isBuffer=="function",ia=new TextDecoder,sa=new TextEncoder;function Et(e){return Ie&&globalThis.Buffer.isBuffer(e)}function so(e){return e instanceof Uint8Array?Et(e)?new Uint8Array(e.buffer,e.byteOffset,e.byteLength):e:Uint8Array.from(e)}var ao=Ie?(e,t,r)=>r-t>64?globalThis.Buffer.from(e.subarray(t,r)).toString("utf8"):oo(e,t,r):(e,t,r)=>r-t>64?ia.decode(e.subarray(t,r)):oo(e,t,r),co=Ie?e=>e.length>64?globalThis.Buffer.from(e):no(e):e=>e.length>64?sa.encode(e):no(e),Y=e=>Uint8Array.from(e),Ce=Ie?(e,t,r)=>Et(e)?new Uint8Array(e.subarray(t,r)):e.slice(t,r):(e,t,r)=>e.slice(t,r),uo=Ie?(e,t)=>(e=e.map(r=>r instanceof Uint8Array?r:globalThis.Buffer.from(r)),so(globalThis.Buffer.concat(e,t))):(e,t)=>{let r=new Uint8Array(t),n=0;for(let o of e)n+o.length>r.length&&(o=o.subarray(0,r.length-n)),r.set(o,n),n+=o.length;return r},fo=Ie?e=>globalThis.Buffer.allocUnsafe(e):e=>new Uint8Array(e);function lo(e,t){if(Et(e)&&Et(t))return e.compare(t);for(let r=0;r<e.length;r++)if(e[r]!==t[r])return e[r]<t[r]?-1:1;return 0}function no(e,t=1/0){let r,n=e.length,o=null,i=[];for(let s=0;s<n;++s){if(r=e.charCodeAt(s),r>55295&&r<57344){if(!o){if(r>56319){(t-=3)>-1&&i.push(239,191,189);continue}else if(s+1===n){(t-=3)>-1&&i.push(239,191,189);continue}o=r;continue}if(r<56320){(t-=3)>-1&&i.push(239,191,189),o=r;continue}r=(o-55296<<10|r-56320)+65536}else o&&(t-=3)>-1&&i.push(239,191,189);if(o=null,r<128){if((t-=1)<0)break;i.push(r)}else if(r<2048){if((t-=2)<0)break;i.push(r>>6|192,r&63|128)}else if(r<65536){if((t-=3)<0)break;i.push(r>>12|224,r>>6&63|128,r&63|128)}else if(r<1114112){if((t-=4)<0)break;i.push(r>>18|240,r>>12&63|128,r>>6&63|128,r&63|128)}else throw new Error("Invalid code point")}return i}function oo(e,t,r){let n=[];for(;t<r;){let o=e[t],i=null,s=o>239?4:o>223?3:o>191?2:1;if(t+s<=r){let u,h,y,m;switch(s){case 1:o<128&&(i=o);break;case 2:u=e[t+1],(u&192)===128&&(m=(o&31)<<6|u&63,m>127&&(i=m));break;case 3:u=e[t+1],h=e[t+2],(u&192)===128&&(h&192)===128&&(m=(o&15)<<12|(u&63)<<6|h&63,m>2047&&(m<55296||m>57343)&&(i=m));break;case 4:u=e[t+1],h=e[t+2],y=e[t+3],(u&192)===128&&(h&192)===128&&(y&192)===128&&(m=(o&15)<<18|(u&63)<<12|(h&63)<<6|y&63,m>65535&&m<1114112&&(i=m))}}i===null?(i=65533,s=1):i>65535&&(i-=65536,n.push(i>>>10&1023|55296),i=56320|i&1023),n.push(i),t+=s}return aa(n)}var io=4096;function aa(e){let t=e.length;if(t<=io)return String.fromCharCode.apply(String,e);let r="",n=0;for(;n<t;)r+=String.fromCharCode.apply(String,e.slice(n,n+=io));return r}var ca=256,kt=class{constructor(t=ca){this.chunkSize=t,this.cursor=0,this.maxCursor=-1,this.chunks=[],this._initReuseChunk=null}reset(){this.cursor=0,this.maxCursor=-1,this.chunks.length&&(this.chunks=[]),this._initReuseChunk!==null&&(this.chunks.push(this._initReuseChunk),this.maxCursor=this._initReuseChunk.length-1)}push(t){let r=this.chunks[this.chunks.length-1];if(this.cursor+t.length<=this.maxCursor+1){let o=r.length-(this.maxCursor-this.cursor)-1;r.set(t,o)}else{if(r){let o=r.length-(this.maxCursor-this.cursor)-1;o<r.length&&(this.chunks[this.chunks.length-1]=r.subarray(0,o),this.maxCursor=this.cursor-1)}t.length<64&&t.length<this.chunkSize?(r=fo(this.chunkSize),this.chunks.push(r),this.maxCursor+=r.length,this._initReuseChunk===null&&(this._initReuseChunk=r),r.set(t,0)):(this.chunks.push(t),this.maxCursor+=t.length)}this.cursor+=t.length}toBytes(t=!1){let r;if(this.chunks.length===1){let n=this.chunks[0];t&&this.cursor>n.length/2?(r=this.cursor===n.length?n:n.subarray(0,this.cursor),this._initReuseChunk=null,this.chunks=[]):r=Ce(n,0,this.cursor)}else r=uo(this.chunks,this.cursor);return t&&this.reset(),r}};var x="CBOR decode error:",sr="CBOR encode error:",We=[];We[23]=1;We[24]=2;We[25]=3;We[26]=5;We[27]=9;function ne(e,t,r){if(e.length-t<r)throw new Error(`${x} not enough data for type`)}var v=[24,256,65536,4294967296,BigInt("18446744073709551616")];function N(e,t,r){ne(e,t,1);let n=e[t];if(r.strict===!0&&n<v[0])throw new Error(`${x} integer encoded in more bytes than necessary (strict decode)`);return n}function $(e,t,r){ne(e,t,2);let n=e[t]<<8|e[t+1];if(r.strict===!0&&n<v[1])throw new Error(`${x} integer encoded in more bytes than necessary (strict decode)`);return n}function M(e,t,r){ne(e,t,4);let n=e[t]*16777216+(e[t+1]<<16)+(e[t+2]<<8)+e[t+3];if(r.strict===!0&&n<v[2])throw new Error(`${x} integer encoded in more bytes than necessary (strict decode)`);return n}function R(e,t,r){ne(e,t,8);let n=e[t]*16777216+(e[t+1]<<16)+(e[t+2]<<8)+e[t+3],o=e[t+4]*16777216+(e[t+5]<<16)+(e[t+6]<<8)+e[t+7],i=(BigInt(n)<<BigInt(32))+BigInt(o);if(r.strict===!0&&i<v[3])throw new Error(`${x} integer encoded in more bytes than necessary (strict decode)`);if(i<=Number.MAX_SAFE_INTEGER)return Number(i);if(r.allowBigInt===!0)return i;throw new Error(`${x} integers outside of the safe integer range are not supported`)}function po(e,t,r,n){return new l(a.uint,N(e,t+1,n),2)}function ho(e,t,r,n){return new l(a.uint,$(e,t+1,n),3)}function yo(e,t,r,n){return new l(a.uint,M(e,t+1,n),5)}function mo(e,t,r,n){return new l(a.uint,R(e,t+1,n),9)}function L(e,t){return U(e,0,t.value)}function U(e,t,r){if(r<v[0]){let n=Number(r);e.push([t|n])}else if(r<v[1]){let n=Number(r);e.push([t|24,n])}else if(r<v[2]){let n=Number(r);e.push([t|25,n>>>8,n&255])}else if(r<v[3]){let n=Number(r);e.push([t|26,n>>>24&255,n>>>16&255,n>>>8&255,n&255])}else{let n=BigInt(r);if(n<v[4]){let o=[t|27,0,0,0,0,0,0,0],i=Number(n&BigInt(4294967295)),s=Number(n>>BigInt(32)&BigInt(4294967295));o[8]=i&255,i=i>>8,o[7]=i&255,i=i>>8,o[6]=i&255,i=i>>8,o[5]=i&255,o[4]=s&255,s=s>>8,o[3]=s&255,s=s>>8,o[2]=s&255,s=s>>8,o[1]=s&255,e.push(o)}else throw new Error(`${x} encountered BigInt larger than allowable range`)}}L.encodedSize=function(t){return U.encodedSize(t.value)};U.encodedSize=function(t){return t<v[0]?1:t<v[1]?2:t<v[2]?3:t<v[3]?5:9};L.compareTokens=function(t,r){return t.value<r.value?-1:t.value>r.value?1:0};function go(e,t,r,n){return new l(a.negint,-1-N(e,t+1,n),2)}function wo(e,t,r,n){return new l(a.negint,-1-$(e,t+1,n),3)}function xo(e,t,r,n){return new l(a.negint,-1-M(e,t+1,n),5)}var ar=BigInt(-1),bo=BigInt(1);function Eo(e,t,r,n){let o=R(e,t+1,n);if(typeof o!="bigint"){let i=-1-o;if(i>=Number.MIN_SAFE_INTEGER)return new l(a.negint,i,9)}if(n.allowBigInt!==!0)throw new Error(`${x} integers outside of the safe integer range are not supported`);return new l(a.negint,ar-BigInt(o),9)}function _t(e,t){let r=t.value,n=typeof r=="bigint"?r*ar-bo:r*-1-1;U(e,t.type.majorEncoded,n)}_t.encodedSize=function(t){let r=t.value,n=typeof r=="bigint"?r*ar-bo:r*-1-1;return n<v[0]?1:n<v[1]?2:n<v[2]?3:n<v[3]?5:9};_t.compareTokens=function(t,r){return t.value<r.value?1:t.value>r.value?-1:0};function Xe(e,t,r,n){ne(e,t,r+n);let o=Ce(e,t+r,t+r+n);return new l(a.bytes,o,r+n)}function ko(e,t,r,n){return Xe(e,t,1,r)}function _o(e,t,r,n){return Xe(e,t,2,N(e,t+1,n))}function vo(e,t,r,n){return Xe(e,t,3,$(e,t+1,n))}function Ao(e,t,r,n){return Xe(e,t,5,M(e,t+1,n))}function Uo(e,t,r,n){let o=R(e,t+1,n);if(typeof o=="bigint")throw new Error(`${x} 64-bit integer bytes lengths not supported`);return Xe(e,t,9,o)}function vt(e){return e.encodedBytes===void 0&&(e.encodedBytes=e.type===a.string?co(e.value):e.value),e.encodedBytes}function Ne(e,t){let r=vt(t);U(e,t.type.majorEncoded,r.length),e.push(r)}Ne.encodedSize=function(t){let r=vt(t);return U.encodedSize(r.length)+r.length};Ne.compareTokens=function(t,r){return fa(vt(t),vt(r))};function fa(e,t){return e.length<t.length?-1:e.length>t.length?1:lo(e,t)}function Je(e,t,r,n,o){let i=r+n;ne(e,t,i);let s=new l(a.string,ao(e,t+r,t+i),i);return o.retainStringBytes===!0&&(s.byteValue=Ce(e,t+r,t+i)),s}function To(e,t,r,n){return Je(e,t,1,r,n)}function Bo(e,t,r,n){return Je(e,t,2,N(e,t+1,n),n)}function So(e,t,r,n){return Je(e,t,3,$(e,t+1,n),n)}function Io(e,t,r,n){return Je(e,t,5,M(e,t+1,n),n)}function Co(e,t,r,n){let o=R(e,t+1,n);if(typeof o=="bigint")throw new Error(`${x} 64-bit integer string lengths not supported`);return Je(e,t,9,o,n)}var No=Ne;function $e(e,t,r,n){return new l(a.array,n,r)}function $o(e,t,r,n){return $e(e,t,1,r)}function Mo(e,t,r,n){return $e(e,t,2,N(e,t+1,n))}function Ro(e,t,r,n){return $e(e,t,3,$(e,t+1,n))}function Do(e,t,r,n){return $e(e,t,5,M(e,t+1,n))}function zo(e,t,r,n){let o=R(e,t+1,n);if(typeof o=="bigint")throw new Error(`${x} 64-bit integer array lengths not supported`);return $e(e,t,9,o)}function Oo(e,t,r,n){if(n.allowIndefinite===!1)throw new Error(`${x} indefinite length items not allowed`);return $e(e,t,1,1/0)}function At(e,t){U(e,a.array.majorEncoded,t.value)}At.compareTokens=L.compareTokens;At.encodedSize=function(t){return U.encodedSize(t.value)};function Me(e,t,r,n){return new l(a.map,n,r)}function Lo(e,t,r,n){return Me(e,t,1,r)}function Fo(e,t,r,n){return Me(e,t,2,N(e,t+1,n))}function Vo(e,t,r,n){return Me(e,t,3,$(e,t+1,n))}function Po(e,t,r,n){return Me(e,t,5,M(e,t+1,n))}function Ho(e,t,r,n){let o=R(e,t+1,n);if(typeof o=="bigint")throw new Error(`${x} 64-bit integer map lengths not supported`);return Me(e,t,9,o)}function jo(e,t,r,n){if(n.allowIndefinite===!1)throw new Error(`${x} indefinite length items not allowed`);return Me(e,t,1,1/0)}function Ut(e,t){U(e,a.map.majorEncoded,t.value)}Ut.compareTokens=L.compareTokens;Ut.encodedSize=function(t){return U.encodedSize(t.value)};function qo(e,t,r,n){return new l(a.tag,r,1)}function Go(e,t,r,n){return new l(a.tag,N(e,t+1,n),2)}function Ko(e,t,r,n){return new l(a.tag,$(e,t+1,n),3)}function Wo(e,t,r,n){return new l(a.tag,M(e,t+1,n),5)}function Xo(e,t,r,n){return new l(a.tag,R(e,t+1,n),9)}function Tt(e,t){U(e,a.tag.majorEncoded,t.value)}Tt.compareTokens=L.compareTokens;Tt.encodedSize=function(t){return U.encodedSize(t.value)};var ma=20,ga=21,wa=22,xa=23;function Jo(e,t,r,n){if(n.allowUndefined===!1)throw new Error(`${x} undefined values are not supported`);return n.coerceUndefinedToNull===!0?new l(a.null,null,1):new l(a.undefined,void 0,1)}function Qo(e,t,r,n){if(n.allowIndefinite===!1)throw new Error(`${x} indefinite length items not allowed`);return new l(a.break,void 0,1)}function cr(e,t,r){if(r){if(r.allowNaN===!1&&Number.isNaN(e))throw new Error(`${x} NaN values are not supported`);if(r.allowInfinity===!1&&(e===1/0||e===-1/0))throw new Error(`${x} Infinity values are not supported`)}return new l(a.float,e,t)}function Yo(e,t,r,n){return cr(ur(e,t+1),3,n)}function Zo(e,t,r,n){return cr(fr(e,t+1),5,n)}function ei(e,t,r,n){return cr(oi(e,t+1),9,n)}function Bt(e,t,r){let n=t.value;if(n===!1)e.push([a.float.majorEncoded|ma]);else if(n===!0)e.push([a.float.majorEncoded|ga]);else if(n===null)e.push([a.float.majorEncoded|wa]);else if(n===void 0)e.push([a.float.majorEncoded|xa]);else{let o,i=!1;(!r||r.float64!==!0)&&(ri(n),o=ur(q,1),n===o||Number.isNaN(n)?(q[0]=249,e.push(q.slice(0,3)),i=!0):(ni(n),o=fr(q,1),n===o&&(q[0]=250,e.push(q.slice(0,5)),i=!0))),i||(ba(n),o=oi(q,1),q[0]=251,e.push(q.slice(0,9)))}}Bt.encodedSize=function(t,r){let n=t.value;if(n===!1||n===!0||n===null||n===void 0)return 1;if(!r||r.float64!==!0){ri(n);let o=ur(q,1);if(n===o||Number.isNaN(n))return 3;if(ni(n),o=fr(q,1),n===o)return 5}return 9};var ti=new ArrayBuffer(9),F=new DataView(ti,1),q=new Uint8Array(ti,0);function ri(e){if(e===1/0)F.setUint16(0,31744,!1);else if(e===-1/0)F.setUint16(0,64512,!1);else if(Number.isNaN(e))F.setUint16(0,32256,!1);else{F.setFloat32(0,e);let t=F.getUint32(0),r=(t&2139095040)>>23,n=t&8388607;if(r===255)F.setUint16(0,31744,!1);else if(r===0)F.setUint16(0,(e&2147483648)>>16|n>>13,!1);else{let o=r-127;o<-24?F.setUint16(0,0):o<-14?F.setUint16(0,(t&2147483648)>>16|1<<24+o,!1):F.setUint16(0,(t&2147483648)>>16|o+15<<10|n>>13,!1)}}}function ur(e,t){if(e.length-t<2)throw new Error(`${x} not enough data for float16`);let r=(e[t]<<8)+e[t+1];if(r===31744)return 1/0;if(r===64512)return-1/0;if(r===32256)return NaN;let n=r>>10&31,o=r&1023,i;return n===0?i=o*2**-24:n!==31?i=(o+1024)*2**(n-25):i=o===0?1/0:NaN,r&32768?-i:i}function ni(e){F.setFloat32(0,e,!1)}function fr(e,t){if(e.length-t<4)throw new Error(`${x} not enough data for float32`);let r=(e.byteOffset||0)+t;return new DataView(e.buffer,r,4).getFloat32(0,!1)}function ba(e){F.setFloat64(0,e,!1)}function oi(e,t){if(e.length-t<8)throw new Error(`${x} not enough data for float64`);let r=(e.byteOffset||0)+t;return new DataView(e.buffer,r,8).getFloat64(0,!1)}Bt.compareTokens=L.compareTokens;function b(e,t,r){throw new Error(`${x} encountered invalid minor (${r}) for major ${e[t]>>>5}`)}function St(e){return()=>{throw new Error(`${x} ${e}`)}}var d=[];for(let e=0;e<=23;e++)d[e]=b;d[24]=po;d[25]=ho;d[26]=yo;d[27]=mo;d[28]=b;d[29]=b;d[30]=b;d[31]=b;for(let e=32;e<=55;e++)d[e]=b;d[56]=go;d[57]=wo;d[58]=xo;d[59]=Eo;d[60]=b;d[61]=b;d[62]=b;d[63]=b;for(let e=64;e<=87;e++)d[e]=ko;d[88]=_o;d[89]=vo;d[90]=Ao;d[91]=Uo;d[92]=b;d[93]=b;d[94]=b;d[95]=St("indefinite length bytes/strings are not supported");for(let e=96;e<=119;e++)d[e]=To;d[120]=Bo;d[121]=So;d[122]=Io;d[123]=Co;d[124]=b;d[125]=b;d[126]=b;d[127]=St("indefinite length bytes/strings are not supported");for(let e=128;e<=151;e++)d[e]=$o;d[152]=Mo;d[153]=Ro;d[154]=Do;d[155]=zo;d[156]=b;d[157]=b;d[158]=b;d[159]=Oo;for(let e=160;e<=183;e++)d[e]=Lo;d[184]=Fo;d[185]=Vo;d[186]=Po;d[187]=Ho;d[188]=b;d[189]=b;d[190]=b;d[191]=jo;for(let e=192;e<=215;e++)d[e]=qo;d[216]=Go;d[217]=Ko;d[218]=Wo;d[219]=Xo;d[220]=b;d[221]=b;d[222]=b;d[223]=b;for(let e=224;e<=243;e++)d[e]=St("simple values are not supported");d[244]=b;d[245]=b;d[246]=b;d[247]=Jo;d[248]=St("simple values are not supported");d[249]=Yo;d[250]=Zo;d[251]=ei;d[252]=b;d[253]=b;d[254]=b;d[255]=Qo;var Z=[];for(let e=0;e<24;e++)Z[e]=new l(a.uint,e,1);for(let e=-1;e>=-24;e--)Z[31-e]=new l(a.negint,e,1);Z[64]=new l(a.bytes,new Uint8Array(0),1);Z[96]=new l(a.string,"",1);Z[128]=new l(a.array,0,1);Z[160]=new l(a.map,0,1);Z[244]=new l(a.false,!1,1);Z[245]=new l(a.true,!0,1);Z[246]=new l(a.null,null,1);function dr(e){switch(e.type){case a.false:return Y([244]);case a.true:return Y([245]);case a.null:return Y([246]);case a.bytes:return e.value.length?void 0:Y([64]);case a.string:return e.value===""?Y([96]):void 0;case a.array:return e.value===0?Y([128]):void 0;case a.map:return e.value===0?Y([160]):void 0;case a.uint:return e.value<24?Y([Number(e.value)]):void 0;case a.negint:if(e.value>=-24)return Y([31-Number(e.value)])}}function lr(){let e=[];return e[a.uint.major]=L,e[a.negint.major]=_t,e[a.bytes.major]=Ne,e[a.string.major]=No,e[a.array.major]=At,e[a.map.major]=Ut,e[a.tag.major]=Tt,e[a.float.major]=Bt,e}var df=lr(),lf=new kt,Ct=class e{constructor(t,r){this.obj=t,this.parent=r}includes(t){let r=this;do if(r.obj===t)return!0;while(r=r.parent);return!1}static createCheck(t,r){if(t&&t.includes(r))throw new Error(`${sr} object contains circular references`);return new e(r,t)}},de={null:new l(a.null,null),undefined:new l(a.undefined,void 0),true:new l(a.true,!0),false:new l(a.false,!1),emptyArray:new l(a.array,0),emptyMap:new l(a.map,0)},le={number(e,t,r,n){return!Number.isInteger(e)||!Number.isSafeInteger(e)?new l(a.float,e):e>=0?new l(a.uint,e):new l(a.negint,e)},bigint(e,t,r,n){return e>=BigInt(0)?new l(a.uint,e):new l(a.negint,e)},Uint8Array(e,t,r,n){return new l(a.bytes,e)},string(e,t,r,n){return new l(a.string,e)},boolean(e,t,r,n){return e?de.true:de.false},null(e,t,r,n){return de.null},undefined(e,t,r,n){return de.undefined},ArrayBuffer(e,t,r,n){return new l(a.bytes,new Uint8Array(e))},DataView(e,t,r,n){return new l(a.bytes,new Uint8Array(e.buffer,e.byteOffset,e.byteLength))},Array(e,t,r,n){if(!e.length)return r.addBreakTokens===!0?[de.emptyArray,new l(a.break)]:de.emptyArray;n=Ct.createCheck(n,e);let o=[],i=0;for(let s of e)o[i++]=It(s,r,n);return r.addBreakTokens?[new l(a.array,e.length),o,new l(a.break)]:[new l(a.array,e.length),o]},Object(e,t,r,n){let o=t!=="Object",i=o?e.keys():Object.keys(e),s=o?e.size:i.length;if(!s)return r.addBreakTokens===!0?[de.emptyMap,new l(a.break)]:de.emptyMap;n=Ct.createCheck(n,e);let u=[],h=0;for(let y of i)u[h++]=[It(y,r,n),It(o?e.get(y):e[y],r,n)];return ka(u,r),r.addBreakTokens?[new l(a.map,s),u,new l(a.break)]:[new l(a.map,s),u]}};le.Map=le.Object;le.Buffer=le.Uint8Array;for(let e of"Uint8Clamped Uint16 Uint32 Int8 Int16 Int32 BigUint64 BigInt64 Float32 Float64".split(" "))le[`${e}Array`]=le.DataView;function It(e,t={},r){let n=ro(e),o=t&&t.typeEncoders&&t.typeEncoders[n]||le[n];if(typeof o=="function"){let s=o(e,n,t,r);if(s!=null)return s}let i=le[n];if(!i)throw new Error(`${sr} unsupported type: ${n}`);return i(e,n,t,r)}function ka(e,t){t.mapSorter&&e.sort(t.mapSorter)}var gf=Symbol.for("DONE"),wf=Symbol.for("BREAK");var _a=lr(),va={float64:!1,quickEncodeToken:dr};function pr(e,t=_a,r=va){if(Array.isArray(e)){let n=0;for(let o of e)n+=pr(o,t,r);return n}else{let n=t[e.type.major];if(n.encodedSize===void 0||typeof n.encodedSize!="function")throw new Error(`Encoder for ${e.type.name} does not have an encodedSize()`);return n.encodedSize(e,r)}}var Qe=tt(yt(),1),yr=class{constructor(t,r){this.bytes=t,this.byteOffset=r,this.roots=[],this.headerSize=r}addRoot(t,r){return si(this,t,r),this}write(t){return ai(this,t),this}close(t){return ci(this,t)}},si=(e,t,r={})=>{let{resize:n=!1}=r,{bytes:o,headerSize:i,byteOffset:s,roots:u}=e;e.roots.push(t);let h=wr(e);if(h>i)if(h-i+s<o.byteLength)if(n)mr(e,h);else throw u.pop(),new RangeError(`Header of size ${i} has no capacity for new root ${t}.
|
|
3
|
-
However there is a space in the buffer and you could call addRoot(root, { resize: root }) to resize header to make a space for this root.`);else throw
|
|
4
|
-
You can use close({ resize: true }) to resize header`)},mr=(e,t)=>{let{bytes:r,headerSize:n}=e;r.set(r.subarray(n,e.byteOffset),t),e.byteOffset+=t-n,e.headerSize=t},hr=(e,t)=>{e.bytes.set(t,e.byteOffset),e.byteOffset+=t.length},ii=({bytes:e},t,r)=>{e.set(t),e.set(r,t.length)},Ua=[new l(a.map,2),new l(a.string,"version"),new l(a.uint,1),new l(a.string,"roots")],Ta=new l(a.tag,42),gr=e=>{let t=[...Ua];t.push(new l(a.array,e.length));for(let n of e)t.push(Ta),t.push(new l(a.bytes,{length:n+1}));let r=pr(t);return Qe.default.encodingLength(r)+r},wr=({roots:e})=>gr(e.map(t=>t.bytes.byteLength)),Ba=(e,t=36)=>gr(new Array(e).fill(t)),Sa=(e,t={})=>{let{roots:r=[],byteOffset:n=0,byteLength:o=e.byteLength,headerSize:i=wr({roots:r})}=t,s=new Uint8Array(e,n,o),u=new yr(s,i);for(let h of r)u.addRoot(h);return u};var br=tt(ui(),1);async function Nt(e,t){let r=Q(await e.upTo(8),e);if(r===0)throw new Error("Invalid CAR header (zero length)");let n=await e.exactly(r,!0),o=ht(n);if(!xt(o))throw new Error("Invalid CAR header format");if(o.version!==1&&o.version!==2||t!==void 0&&o.version!==t)throw new Error(`Invalid CAR version: ${o.version}${t!==void 0?` (expected ${t})`:""}`);let i=Array.isArray(o.roots);if(o.version===1&&!i||o.version===2&&i)throw new Error("Invalid CAR header format");if(o.version===1)return o;let s=gt(await e.exactly(mt,!0));e.seek(s.dataOffset-e.pos);let u=await Nt(e,1);return Object.assign(u,s)}async function Ia(e){let t=await e.exactly(2,!1);if(t[0]===ue.SHA2_256&&t[1]===ue.LENGTH){let s=await e.exactly(34,!0),u=ae(s);return _.create(0,ue.DAG_PB,u)}let r=Q(await e.upTo(8),e);if(r!==1)throw new Error(`Unexpected CID version (${r})`);let n=Q(await e.upTo(8),e),o=await e.exactly(wt(await e.upTo(8)),!0),i=ae(o);return _.create(r,n,i)}async function fi(e){let t=e.pos,r=Q(await e.upTo(8),e);if(r===0)throw new Error("Invalid CAR section (zero length)");r+=e.pos-t;let n=await Ia(e),o=r-Number(e.pos-t);return{cid:n,length:r,blockLength:o}}async function Ca(e){let{cid:t,blockLength:r}=await fi(e);return{bytes:await e.exactly(r,!0),cid:t}}async function Na(e){let t=e.pos,{cid:r,length:n,blockLength:o}=await fi(e),i={cid:r,length:n,blockLength:o,offset:t,blockOffset:e.pos};return e.seek(i.blockLength),i}function Re(e){let t=(async()=>{let r=await Nt(e);if(r.version===2){let n=e.pos-r.dataOffset;e=Ma(e,r.dataSize-n)}return r})();return{header:()=>t,async*blocks(){for(await t;(await e.upTo(8)).length>0;)yield await Ca(e)},async*blocksIndex(){for(await t;(await e.upTo(8)).length>0;)yield await Na(e)}}}function pe(e){let t=0;return{async upTo(r){return e.subarray(t,t+Math.min(r,e.length-t))},async exactly(r,n=!1){if(r>e.length-t)throw new Error("Unexpected end of data");let o=e.subarray(t,t+r);return n&&(t+=r),o},seek(r){t+=r},get pos(){return t}}}function $a(e){let t=0,r=0,n=0,o=new Uint8Array(0),i=async s=>{r=o.length-n;let u=[o.subarray(n)];for(;r<s;){let y=await e();if(y==null)break;r<0?y.length>r&&u.push(y.subarray(-r)):u.push(y),r+=y.length}o=new Uint8Array(u.reduce((y,m)=>y+m.length,0));let h=0;for(let y of u)o.set(y,h),h+=y.length;n=0};return{async upTo(s){return o.length-n<s&&await i(s),o.subarray(n,n+Math.min(o.length-n,s))},async exactly(s,u=!1){if(o.length-n<s&&await i(s),o.length-n<s)throw new Error("Unexpected end of data");let h=o.subarray(n,n+s);return u&&(t+=s,n+=s),h},seek(s){t+=s,n+=s},get pos(){return t}}}function De(e){let t=e[Symbol.asyncIterator]();async function r(){let n=await t.next();return n.done?null:n.value}return $a(r)}function Ma(e,t){let r=0;return{async upTo(n){let o=await e.upTo(n);return o.length+r>t&&(o=o.subarray(0,t-r)),o},async exactly(n,o=!1){let i=await e.exactly(n,o);if(i.length+r>t)throw new Error("Unexpected end of data");return o&&(r+=n),i},seek(n){r+=n,e.seek(n)},get pos(){return e.pos}}}var ge=class{constructor(t,r,n){this._version=t,this._roots=r,this._iterator=n}get version(){return this._version}async getRoots(){return this._roots}[Symbol.asyncIterator](){return this._iterator}static async fromBytes(t){if(!(t instanceof Uint8Array))throw new TypeError("fromBytes() requires a Uint8Array");return di(pe(t))}static async fromIterable(t){if(!t||typeof t[Symbol.asyncIterator]!="function")throw new TypeError("fromIterable() requires an async iterable");return di(De(t))}};async function di(e){let t=Re(e),{version:r,roots:n}=await t.header();return new ge(r,n,t.blocksIndex())}var we=class{constructor(t,r){this._header=t,this._blocks=r,this._keys=r.map(n=>n.cid.toString())}get version(){return this._header.version}async getRoots(){return this._header.roots}async has(t){return this._keys.indexOf(t.toString())>-1}async get(t){let r=this._keys.indexOf(t.toString());return r>-1?this._blocks[r]:void 0}async*blocks(){for(let t of this._blocks)yield t}async*cids(){for(let t of this._blocks)yield t.cid}static async fromBytes(t){if(!(t instanceof Uint8Array))throw new TypeError("fromBytes() requires a Uint8Array");return li(pe(t))}static async fromIterable(t){if(!t||typeof t[Symbol.asyncIterator]!="function")throw new TypeError("fromIterable() requires an async iterable");return li(De(t))}};async function li(e){let t=Re(e),r=await t.header(),n=[];for await(let o of t.blocks())n.push(o);return new we(r,n)}var $t=class e{constructor(t,r,n,o,i){this._version=t,this._path=r,this._roots=n,this._index=o,this._order=i,this._fd=null}get version(){return this._version}async getRoots(){return this._roots}async has(t){return this._index.has(t.toString())}async get(t){let r=this._index.get(t.toString());if(!r)return;this._fd||(this._fd=await br.default.promises.open(this._path,"r"));let n={cid:t,length:0,offset:0,blockLength:r.blockLength,blockOffset:r.blockOffset};return we.readRaw(this._fd,n)}async*blocks(){for(let t of this._order){let r=await this.get(_.parse(t));if(!r)throw new Error("Unexpected internal error");yield r}}async*cids(){for(let t of this._order)yield _.parse(t)}async close(){if(this._fd)return this._fd.close()}static async fromFile(t){if(typeof t!="string")throw new TypeError("fromFile() requires a file path string");let r=await ge.fromIterable((void 0).from(br.default.createReadStream(t))),n=new Map,o=[];for await(let{cid:i,blockLength:s,blockOffset:u}of r){let h=i.toString();n.set(h,{blockLength:s,blockOffset:u}),o.push(h)}return new e(r.version,t,await r.getRoots(),n,o)}};var Mt=class{constructor(t,r,n){this._version=t,this._roots=r,this._iterable=n,this._decoded=!1}get version(){return this._version}async getRoots(){return this._roots}},Rt=class e extends Mt{[Symbol.asyncIterator](){if(this._decoded)throw new Error("Cannot decode more than once");if(!this._iterable)throw new Error("Block iterable not found");return this._decoded=!0,this._iterable[Symbol.asyncIterator]()}static async fromBytes(t){let{version:r,roots:n,iterator:o}=await hi(t);return new e(r,n,o)}static async fromIterable(t){let{version:r,roots:n,iterator:o}=await yi(t);return new e(r,n,o)}},Dt=class e extends Mt{[Symbol.asyncIterator](){if(this._decoded)throw new Error("Cannot decode more than once");if(!this._iterable)throw new Error("Block iterable not found");this._decoded=!0;let t=this._iterable[Symbol.asyncIterator]();return{async next(){let r=await t.next();return r.done?r:{done:!1,value:r.value.cid}}}}static async fromBytes(t){let{version:r,roots:n,iterator:o}=await hi(t);return new e(r,n,o)}static async fromIterable(t){let{version:r,roots:n,iterator:o}=await yi(t);return new e(r,n,o)}};async function hi(e){if(!(e instanceof Uint8Array))throw new TypeError("fromBytes() requires a Uint8Array");return mi(pe(e))}async function yi(e){if(!e||typeof e[Symbol.asyncIterator]!="function")throw new TypeError("fromIterable() requires an async iterable");return mi(De(e))}async function mi(e){let t=Re(e),{version:r,roots:n}=await t.header();return{version:r,roots:n,iterator:t.blocks()}}var Er=tt(yt(),1);function kr(e){let t=pt({version:1,roots:e}),r=Er.default.encode(t.length),n=new Uint8Array(r.length+t.length);return n.set(r,0),n.set(t,r.length),n}function gi(e){return{async setRoots(t){let r=kr(t);await e.write(r)},async writeBlock(t){let{cid:r,bytes:n}=t;await e.write(new Uint8Array(Er.default.encode(r.bytes.length+n.length))),await e.write(r.bytes),n.length&&await e.write(n)},async close(){await e.end()}}}function zt(){}function wi(){let e=[],t=null,r=zt,n=!1,o=null,i=zt,s=()=>(t||(t=new Promise(y=>{r=()=>{t=null,r=zt,y()}})),t),u={write(y){e.push(y);let m=s();return i(),m},async end(){n=!0;let y=s();i(),await y}},h={async next(){let y=e.shift();return y?(e.length===0&&r(),{done:!1,value:y}):n?(r(),{done:!0,value:void 0}):(o||(o=new Promise(m=>{i=()=>(o=null,i=zt,m(h.next()))})),o)}};return{writer:u,iterator:h}}var Ot=class e{constructor(t,r){this._encoder=r,this._mutex=r.setRoots(t),this._ended=!1}async put(t){if(!(t.bytes instanceof Uint8Array)||!t.cid)throw new TypeError("Can only write {cid, bytes} objects");if(this._ended)throw new Error("Already closed");let r=_.asCID(t.cid);if(!r)throw new TypeError("Can only write {cid, bytes} objects");return this._mutex=this._mutex.then(()=>this._encoder.writeBlock({cid:r,bytes:t.bytes})),this._mutex}async close(){if(this._ended)throw new Error("Already closed");return await this._mutex,this._ended=!0,this._encoder.close()}static create(t){t=Ra(t);let{encoder:r,iterator:n}=xi(),o=new e(t,r),i=new Lt(n);return{writer:o,out:i}}static createAppender(){let{encoder:t,iterator:r}=xi();t.setRoots=()=>Promise.resolve();let n=new e([],t),o=new Lt(r);return{writer:n,out:o}}static async updateRootsInBytes(t,r){let n=pe(t);await Nt(n);let o=kr(r);if(Number(n.pos)!==o.length)throw new Error(`updateRoots() can only overwrite a header of the same length (old header is ${n.pos} bytes, new header is ${o.length} bytes)`);return t.set(o,0),t}},Lt=class{constructor(t){this._iterator=t}[Symbol.asyncIterator](){if(this._iterating)throw new Error("Multiple iterator not supported");return this._iterating=!0,this._iterator}};function xi(){let e=wi(),{writer:t,iterator:r}=e;return{encoder:gi(t),iterator:r}}function Ra(e){if(e===void 0)return[];if(!Array.isArray(e)){let r=_.asCID(e);if(!r)throw new TypeError("roots must be a single CID or an array of CIDs");return[r]}let t=[];for(let r of e){let n=_.asCID(r);if(!n)throw new TypeError("roots must be a single CID or an array of CIDs");t.push(n)}return t}var Da="application/vnd.ipld.car";return Ui(za);})();
|
|
2
|
+
"use strict";var IpldCar=(()=>{var Cn=Object.create;var Ie=Object.defineProperty;var Sn=Object.getOwnPropertyDescriptor;var Bn=Object.getOwnPropertyNames;var Nn=Object.getPrototypeOf,Dn=Object.prototype.hasOwnProperty;var de=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),Ot=(e,t)=>{for(var r in t)Ie(e,r,{get:t[r],enumerable:!0})},Rt=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Bn(t))!Dn.call(e,o)&&o!==r&&Ie(e,o,{get:()=>t[o],enumerable:!(n=Sn(t,o))||n.enumerable});return e};var Ce=(e,t,r)=>(r=e!=null?Cn(Nn(e)):{},Rt(t||!e||!e.__esModule?Ie(r,"default",{value:e,enumerable:!0}):r,e)),On=e=>Rt(Ie({},"__esModule",{value:!0}),e);var nn=de((Qs,rn)=>{rn.exports=Et;var tn=128,Go=127,Jo=~Go,Ko=Math.pow(2,31);function Et(e,t,r){if(Number.MAX_SAFE_INTEGER&&e>Number.MAX_SAFE_INTEGER)throw Et.bytes=0,new RangeError("Could not encode varint");t=t||[],r=r||0;for(var n=r;e>=Ko;)t[r++]=e&255|tn,e/=128;for(;e&Jo;)t[r++]=e&255|tn,e>>>=7;return t[r]=e|0,Et.bytes=r-n+1,t}});var an=de((Ys,sn)=>{sn.exports=kt;var Wo=128,on=127;function kt(e,n){var r=0,n=n||0,o=0,i=n,a,c=e.length;do{if(i>=c||o>49)throw kt.bytes=0,new RangeError("Could not decode varint");a=e[i++],r+=o<28?(a&on)<<o:(a&on)*Math.pow(2,o),o+=7}while(a>=Wo);return kt.bytes=i-n,r}});var fn=de((Zs,cn)=>{var Xo=Math.pow(2,7),Qo=Math.pow(2,14),Yo=Math.pow(2,21),Zo=Math.pow(2,28),jo=Math.pow(2,35),ei=Math.pow(2,42),ti=Math.pow(2,49),ri=Math.pow(2,56),ni=Math.pow(2,63);cn.exports=function(e){return e<Xo?1:e<Qo?2:e<Yo?3:e<Zo?4:e<jo?5:e<ei?6:e<ti?7:e<ri?8:e<ni?9:10}});var Pe=de((js,un)=>{un.exports={encode:nn(),decode:an(),encodingLength:fn()}});var gn=de(()=>{});var ki={};Ot(ki,{CarBlockIterator:()=>Ze,CarBufferReader:()=>We,CarBufferWriter:()=>St,CarCIDIterator:()=>je,CarIndexedReader:()=>Qe,CarIndexer:()=>Y,CarReader:()=>Z,CarWriter:()=>tt,contentType:()=>Ei});var Rn=["string","number","bigint","symbol"],Mn=["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(Rn.includes(t))return t;if(t==="function")return"Function";if(Array.isArray(e))return"Array";if($n(e))return"Buffer";let r=zn(e);return r||"Object"}function $n(e){return e&&e.constructor&&e.constructor.isBuffer&&e.constructor.isBuffer.call(null,e)}function zn(e){let t=Object.prototype.toString.call(e).slice(8,-1);if(Mn.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 f=class{constructor(t,r,n){this.type=t,this.value=r,this.encodedLength=n,this.encodedBytes=void 0,this.byteValue=void 0}toString(){return`Token[${this.type}].${this.value}`}};var ee=globalThis.process&&!globalThis.process.browser&&globalThis.Buffer&&typeof globalThis.Buffer.isBuffer=="function",Ln=new TextDecoder,Vn=new TextEncoder;function Se(e){return ee&&globalThis.Buffer.isBuffer(e)}function nt(e){return e instanceof Uint8Array?Se(e)?new Uint8Array(e.buffer,e.byteOffset,e.byteLength):e:Uint8Array.from(e)}var Vt=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?Ln.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?Vn.encode(e):$t(e),R=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)),nt(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},Pt=ee?e=>globalThis.Buffer.allocUnsafe(e):e=>new Uint8Array(e);function qt(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){let t=[],r=0;for(let n=0;n<e.length;n++){let o=e.charCodeAt(n);o<128?t[r++]=o:o<2048?(t[r++]=o>>6|192,t[r++]=o&63|128):(o&64512)===55296&&n+1<e.length&&(e.charCodeAt(n+1)&64512)===56320?(o=65536+((o&1023)<<10)+(e.charCodeAt(++n)&1023),t[r++]=o>>18|240,t[r++]=o>>12&63|128,t[r++]=o>>6&63|128,t[r++]=o&63|128):(t[r++]=o>>12|224,t[r++]=o>>6&63|128,t[r++]=o&63|128)}return t}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,d,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],d=e[t+2],(c&192)===128&&(d&192)===128&&(p=(o&15)<<12|(c&63)<<6|d&63,p>2047&&(p<55296||p>57343)&&(i=p));break;case 4:c=e[t+1],d=e[t+2],h=e[t+3],(c&192)===128&&(d&192)===128&&(h&192)===128&&(p=(o&15)<<18|(c&63)<<12|(d&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 Fn(n)}var Lt=4096;function Fn(e){let t=e.length;if(t<=Lt)return String.fromCharCode.apply(String,e);let r="",n=0;for(;n<t;)r+=String.fromCharCode.apply(String,e.slice(n,n+=Lt));return r}var Hn=256,le=class{constructor(t=Hn){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=Pt(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:",ot="CBOR encode error:",he=[];he[23]=1;he[24]=2;he[25]=3;he[26]=5;he[27]=9;function L(e,t,r){if(e.length-t<r)throw new Error(`${l} not enough data for type`)}var g=[24,256,65536,4294967296,BigInt("18446744073709551616")];function v(e,t,r){L(e,t,1);let n=e[t];if(r.strict===!0&&n<g[0])throw new Error(`${l} integer encoded in more bytes than necessary (strict decode)`);return n}function E(e,t,r){L(e,t,2);let n=e[t]<<8|e[t+1];if(r.strict===!0&&n<g[1])throw new Error(`${l} integer encoded in more bytes than necessary (strict decode)`);return n}function k(e,t,r){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<g[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<g[3])throw new Error(`${l} integer encoded in more bytes than necessary (strict decode)`);if(i<=Number.MAX_SAFE_INTEGER)return Number(i);if(r.allowBigInt===!0)return i;throw new Error(`${l} integers outside of the safe integer range are not supported`)}function Gt(e,t,r,n){return new f(s.uint,v(e,t+1,n),2)}function Jt(e,t,r,n){return new f(s.uint,E(e,t+1,n),3)}function Kt(e,t,r,n){return new f(s.uint,k(e,t+1,n),5)}function Wt(e,t,r,n){return new f(s.uint,A(e,t+1,n),9)}function T(e,t){return x(e,0,t.value)}function x(e,t,r){if(r<g[0]){let n=Number(r);e.push([t|n])}else if(r<g[1]){let n=Number(r);e.push([t|24,n])}else if(r<g[2]){let n=Number(r);e.push([t|25,n>>>8,n&255])}else if(r<g[3]){let n=Number(r);e.push([t|26,n>>>24&255,n>>>16&255,n>>>8&255,n&255])}else{let n=BigInt(r);if(n<g[4]){let o=[t|27,0,0,0,0,0,0,0],i=Number(n&BigInt(4294967295)),a=Number(n>>BigInt(32)&BigInt(4294967295));o[8]=i&255,i=i>>8,o[7]=i&255,i=i>>8,o[6]=i&255,i=i>>8,o[5]=i&255,o[4]=a&255,a=a>>8,o[3]=a&255,a=a>>8,o[2]=a&255,a=a>>8,o[1]=a&255,e.push(o)}else throw new Error(`${l} encountered BigInt larger than allowable range`)}}T.encodedSize=function(t){return x.encodedSize(t.value)};x.encodedSize=function(t){return t<g[0]?1:t<g[1]?2:t<g[2]?3:t<g[3]?5:9};T.compareTokens=function(t,r){return t.value<r.value?-1:t.value>r.value?1:0};function Xt(e,t,r,n){return new f(s.negint,-1-v(e,t+1,n),2)}function Qt(e,t,r,n){return new f(s.negint,-1-E(e,t+1,n),3)}function Yt(e,t,r,n){return new f(s.negint,-1-k(e,t+1,n),5)}var it=BigInt(-1),Zt=BigInt(1);function jt(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 f(s.negint,i,9)}if(n.allowBigInt!==!0)throw new Error(`${l} integers outside of the safe integer range are not supported`);return new f(s.negint,it-BigInt(o),9)}function Be(e,t){let r=t.value,n=typeof r=="bigint"?r*it-Zt:r*-1-1;x(e,t.type.majorEncoded,n)}Be.encodedSize=function(t){let r=t.value,n=typeof r=="bigint"?r*it-Zt:r*-1-1;return n<g[0]?1:n<g[1]?2:n<g[2]?3:n<g[3]?5:9};Be.compareTokens=function(t,r){return t.value<r.value?1:t.value>r.value?-1:0};function pe(e,t,r,n){L(e,t,r+n);let o=te(e,t+r,t+r+n);return new f(s.bytes,o,r+n)}function er(e,t,r,n){return pe(e,t,1,r)}function tr(e,t,r,n){return pe(e,t,2,v(e,t+1,n))}function rr(e,t,r,n){return pe(e,t,3,E(e,t+1,n))}function nr(e,t,r,n){return pe(e,t,5,k(e,t+1,n))}function or(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 pe(e,t,9,o)}function Ne(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=Ne(t);x(e,t.type.majorEncoded,r.length),e.push(r)}re.encodedSize=function(t){let r=Ne(t);return x.encodedSize(r.length)+r.length};re.compareTokens=function(t,r){return qn(Ne(t),Ne(r))};function qn(e,t){return e.length<t.length?-1:e.length>t.length?1:qt(e,t)}function ye(e,t,r,n,o){let i=r+n;L(e,t,i);let a=new f(s.string,Vt(e,t+r,t+i),i);return o.retainStringBytes===!0&&(a.byteValue=te(e,t+r,t+i)),a}function ir(e,t,r,n){return ye(e,t,1,r,n)}function sr(e,t,r,n){return ye(e,t,2,v(e,t+1,n),n)}function ar(e,t,r,n){return ye(e,t,3,E(e,t+1,n),n)}function cr(e,t,r,n){return ye(e,t,5,k(e,t+1,n),n)}function fr(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 ye(e,t,9,o,n)}var ur=re;function ne(e,t,r,n){return new f(s.array,n,r)}function dr(e,t,r,n){return ne(e,t,1,r)}function lr(e,t,r,n){return ne(e,t,2,v(e,t+1,n))}function hr(e,t,r,n){return ne(e,t,3,E(e,t+1,n))}function pr(e,t,r,n){return ne(e,t,5,k(e,t+1,n))}function yr(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 mr(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 De(e,t){x(e,s.array.majorEncoded,t.value)}De.compareTokens=T.compareTokens;De.encodedSize=function(t){return x.encodedSize(t.value)};function oe(e,t,r,n){return new f(s.map,n,r)}function gr(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 xr(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 vr(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 Er(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 Oe(e,t){x(e,s.map.majorEncoded,t.value)}Oe.compareTokens=T.compareTokens;Oe.encodedSize=function(t){return x.encodedSize(t.value)};function kr(e,t,r,n){return new f(s.tag,r,1)}function Ar(e,t,r,n){return new f(s.tag,v(e,t+1,n),2)}function _r(e,t,r,n){return new f(s.tag,E(e,t+1,n),3)}function Tr(e,t,r,n){return new f(s.tag,k(e,t+1,n),5)}function Ur(e,t,r,n){return new f(s.tag,A(e,t+1,n),9)}function Re(e,t){x(e,s.tag.majorEncoded,t.value)}Re.compareTokens=T.compareTokens;Re.encodedSize=function(t){return x.encodedSize(t.value)};var Qn=20,Yn=21,Zn=22,jn=23;function Ir(e,t,r,n){if(n.allowUndefined===!1)throw new Error(`${l} undefined values are not supported`);return n.coerceUndefinedToNull===!0?new f(s.null,null,1):new f(s.undefined,void 0,1)}function Cr(e,t,r,n){if(n.allowIndefinite===!1)throw new Error(`${l} indefinite length items not allowed`);return new f(s.break,void 0,1)}function st(e,t,r){if(r){if(r.allowNaN===!1&&Number.isNaN(e))throw new Error(`${l} NaN values are not supported`);if(r.allowInfinity===!1&&(e===1/0||e===-1/0))throw new Error(`${l} Infinity values are not supported`)}return new f(s.float,e,t)}function Sr(e,t,r,n){return st(at(e,t+1),3,n)}function Br(e,t,r,n){return st(ct(e,t+1),5,n)}function Nr(e,t,r,n){return st(Mr(e,t+1),9,n)}function Me(e,t,r){let n=t.value;if(n===!1)e.push([s.float.majorEncoded|Qn]);else if(n===!0)e.push([s.float.majorEncoded|Yn]);else if(n===null)e.push([s.float.majorEncoded|Zn]);else if(n===void 0)e.push([s.float.majorEncoded|jn]);else{let o,i=!1;(!r||r.float64!==!0)&&(Or(n),o=at(S,1),n===o||Number.isNaN(n)?(S[0]=249,e.push(S.slice(0,3)),i=!0):(Rr(n),o=ct(S,1),n===o&&(S[0]=250,e.push(S.slice(0,5)),i=!0))),i||(eo(n),o=Mr(S,1),S[0]=251,e.push(S.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){Or(n);let o=at(S,1);if(n===o||Number.isNaN(n))return 3;if(Rr(n),o=ct(S,1),n===o)return 5}return 9};var Dr=new ArrayBuffer(9),U=new DataView(Dr,1),S=new Uint8Array(Dr,0);function Or(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 at(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 ct(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 eo(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 u=[];for(let e=0;e<=23;e++)u[e]=y;u[24]=Gt;u[25]=Jt;u[26]=Kt;u[27]=Wt;u[28]=y;u[29]=y;u[30]=y;u[31]=y;for(let e=32;e<=55;e++)u[e]=y;u[56]=Xt;u[57]=Qt;u[58]=Yt;u[59]=jt;u[60]=y;u[61]=y;u[62]=y;u[63]=y;for(let e=64;e<=87;e++)u[e]=er;u[88]=tr;u[89]=rr;u[90]=nr;u[91]=or;u[92]=y;u[93]=y;u[94]=y;u[95]=$e("indefinite length bytes/strings are not supported");for(let e=96;e<=119;e++)u[e]=ir;u[120]=sr;u[121]=ar;u[122]=cr;u[123]=fr;u[124]=y;u[125]=y;u[126]=y;u[127]=$e("indefinite length bytes/strings are not supported");for(let e=128;e<=151;e++)u[e]=dr;u[152]=lr;u[153]=hr;u[154]=pr;u[155]=yr;u[156]=y;u[157]=y;u[158]=y;u[159]=mr;for(let e=160;e<=183;e++)u[e]=gr;u[184]=wr;u[185]=xr;u[186]=br;u[187]=vr;u[188]=y;u[189]=y;u[190]=y;u[191]=Er;for(let e=192;e<=215;e++)u[e]=kr;u[216]=Ar;u[217]=_r;u[218]=Tr;u[219]=Ur;u[220]=y;u[221]=y;u[222]=y;u[223]=y;for(let e=224;e<=243;e++)u[e]=$e("simple values are not supported");u[244]=y;u[245]=y;u[246]=y;u[247]=Ir;u[248]=$e("simple values are not supported");u[249]=Sr;u[250]=Br;u[251]=Nr;u[252]=y;u[253]=y;u[254]=y;u[255]=Cr;var B=[];for(let e=0;e<24;e++)B[e]=new f(s.uint,e,1);for(let e=-1;e>=-24;e--)B[31-e]=new f(s.negint,e,1);B[64]=new f(s.bytes,new Uint8Array(0),1);B[96]=new f(s.string,"",1);B[128]=new f(s.array,0,1);B[160]=new f(s.map,0,1);B[244]=new f(s.false,!1,1);B[245]=new f(s.true,!0,1);B[246]=new f(s.null,null,1);function ze(e){switch(e.type){case s.false:return R([244]);case s.true:return R([245]);case s.null:return R([246]);case s.bytes:return e.value.length?void 0:R([64]);case s.string:return e.value===""?R([96]):void 0;case s.array:return e.value===0?R([128]):void 0;case s.map:return e.value===0?R([160]):void 0;case s.uint:return e.value<24?R([Number(e.value)]):void 0;case s.negint:if(e.value>=-24)return R([31-Number(e.value)])}}var ro={float64:!1,mapSorter:oo,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]=De,e[s.map.major]=Oe,e[s.tag.major]=Re,e[s.float.major]=Me,e}var $r=ut(),ft=new le,Le=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(`${ot} object contains circular references`);return new e(r,t)}},H={null:new f(s.null,null),undefined:new f(s.undefined,void 0),true:new f(s.true,!0),false:new f(s.false,!1),emptyArray:new f(s.array,0),emptyMap:new f(s.map,0)},P={number(e,t,r,n){return!Number.isInteger(e)||!Number.isSafeInteger(e)?new f(s.float,e):e>=0?new f(s.uint,e):new f(s.negint,e)},bigint(e,t,r,n){return e>=BigInt(0)?new f(s.uint,e):new f(s.negint,e)},Uint8Array(e,t,r,n){return new f(s.bytes,e)},string(e,t,r,n){return new f(s.string,e)},boolean(e,t,r,n){return e?H.true:H.false},null(e,t,r,n){return H.null},undefined(e,t,r,n){return H.undefined},ArrayBuffer(e,t,r,n){return new f(s.bytes,new Uint8Array(e))},DataView(e,t,r,n){return new f(s.bytes,new Uint8Array(e.buffer,e.byteOffset,e.byteLength))},Array(e,t,r,n){if(!e.length)return r.addBreakTokens===!0?[H.emptyArray,new f(s.break)]:H.emptyArray;n=Le.createCheck(n,e);let o=[],i=0;for(let a of e)o[i++]=me(a,r,n);return r.addBreakTokens?[new f(s.array,e.length),o,new f(s.break)]:[new f(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?[H.emptyMap,new f(s.break)]:H.emptyMap;n=Le.createCheck(n,e);let c=[],d=0;for(let h of i)c[d++]=[me(h,r,n),me(o?e.get(h):e[h],r,n)];return no(c,r),r.addBreakTokens?[new f(s.map,a),c,new f(s.break)]:[new f(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 me(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(`${ot} unsupported type: ${n}`);return i(e,n,t,r)}function no(e,t){t.mapSorter&&e.sort(t.mapSorter)}function oo(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 io(e,t,r){let n=me(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 le(a);if(i(c,n,r),c.chunks.length!==1)throw new Error(`Unexpected error: pre-calculated length for ${n} was wrong`);return nt(c.chunks[0])}}return ft.reset(),zr(ft,n,t,r),ft.toBytes(!0)}function dt(e,t){return t=Object.assign({},ro,t),io(e,$r,t)}var so={strict:!1,allowIndefinite:!0,allowUndefined:!0,allowBigInt:!0},lt=class{constructor(t,r={}){this._pos=0,this.data=t,this.options=r}pos(){return this._pos}done(){return this._pos>=this.data.length}next(){let t=this.data[this._pos],r=B[t];if(r===void 0){let n=u[t];if(!n)throw new Error(`${l} no decoder for major type ${t>>>5} (byte 0x${t.toString(16).padStart(2,"0")})`);let o=t&31;r=n(this.data,this._pos,o,this.options)}return this._pos+=r.encodedLength,r}},ge=Symbol.for("DONE"),Ve=Symbol.for("BREAK");function ao(e,t,r){let n=[];for(let o=0;o<e.value;o++){let i=we(t,r);if(i===Ve){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 co(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=we(t,r);if(c===Ve){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 d=we(t,r);if(d===ge)throw new Error(`${l} found map but not enough entries (got ${a} [no value], expected ${e.value})`);n?i.set(c,d):o[c]=d}return n?i:o}function we(e,t){if(e.done())return ge;let r=e.next();if(r.type===s.break)return Ve;if(r.type.terminal)return r.value;if(r.type===s.array)return ao(r,e,t);if(r.type===s.map)return co(r,e,t);if(r.type===s.tag){if(t.tags&&typeof t.tags[r.value]=="function"){let n=we(e,t);return t.tags[r.value](n)}throw new Error(`${l} tag not supported (${r.value})`)}throw new Error("unsupported")}function Lr(e,t){if(!(e instanceof Uint8Array))throw new Error(`${l} data to decode must be a Uint8Array`);t=Object.assign({},so,t);let r=t.tokenizer||new lt(e,t),n=we(r,t);if(n===ge)throw new Error(`${l} did not find any content to decode`);if(n===Ve)throw new Error(`${l} got unexpected break`);return[n,e.subarray(r.pos())]}function ht(e,t){let[r,n]=Lr(e,t);if(n.length>0)throw new Error(`${l} too many terminals, data makes no sense`);return r}function uo(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,d=e.charAt(0),h=Math.log(c)/Math.log(256),p=Math.log(256)/Math.log(c);function j(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 b=0,X=0,I=0,N=m.length;I!==N&&m[I]===0;)I++,b++;for(var D=(N-I)*p+1>>>0,_=new Uint8Array(D);I!==N;){for(var O=m[I],F=0,C=D-1;(O!==0||F<X)&&C!==-1;C--,F++)O+=256*_[C]>>>0,_[C]=O%c>>>0,O=O/c>>>0;if(O!==0)throw new Error("Non-zero carry");X=F,I++}for(var z=D-X;z!==D&&_[z]===0;)z++;for(var Ue=d.repeat(b);z<D;++z)Ue+=e.charAt(_[z]);return Ue}function Te(m){if(typeof m!="string")throw new TypeError("Expected String");if(m.length===0)return new Uint8Array;var b=0;if(m[b]!==" "){for(var X=0,I=0;m[b]===d;)X++,b++;for(var N=(m.length-b)*h+1>>>0,D=new Uint8Array(N);m[b];){var _=r[m.charCodeAt(b)];if(_===255)return;for(var O=0,F=N-1;(_!==0||O<I)&&F!==-1;F--,O++)_+=c*D[F]>>>0,D[F]=_%256>>>0,_=_/256>>>0;if(_!==0)throw new Error("Non-zero carry");I=O,b++}if(m[b]!==" "){for(var C=N-I;C!==N&&D[C]===0;)C++;for(var z=new Uint8Array(X+(N-C)),Ue=X;C!==N;)z[Ue++]=D[C++];return z}}}function In(m){var b=Te(m);if(b)return b;throw new Error(`Non-${t} character`)}return{encode:j,decodeUnsafe:Te,decode:In}}var lo=uo,ho=lo,Vr=ho;var ks=new Uint8Array(0);var Fr=(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 pt=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")}},yt=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 Hr(this,t)}},mt=class{constructor(t){this.decoders=t}or(t){return Hr(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`)}},Hr=(e,t)=>new mt({...e.decoders||{[e.prefix]:e},...t.decoders||{[t.prefix]:t}}),gt=class{constructor(t,r,n,o){this.name=t,this.prefix=r,this.baseEncode=n,this.baseDecode=o,this.encoder=new pt(t,r,n),this.decoder=new yt(t,r,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}},Pr=({name:e,prefix:t,encode:r,decode:n})=>new gt(e,t,r,n),wt=({prefix:e,name:t,alphabet:r})=>{let{encode:n,decode:o}=Vr(r,t);return Pr({prefix:e,name:t,encode:n,decode:i=>ie(o(i))})},po=(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,d=0,h=0;for(let p=0;p<i;++p){let j=o[e[p]];if(j===void 0)throw new SyntaxError(`Non-${n} character`);d=d<<r|j,c+=r,c>=8&&(c-=8,a[h++]=255&d>>c)}if(c>=r||255&d<<8-c)throw new SyntaxError("Unexpected end of data");return a},yo=(e,t,r)=>{let n=t[t.length-1]==="=",o=(1<<r)-1,i="",a=0,c=0;for(let d=0;d<e.length;++d)for(c=c<<8|e[d],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},M=({name:e,prefix:t,bitsPerChar:r,alphabet:n})=>Pr({prefix:t,name:e,encode(o){return yo(o,n,r)},decode(o){return po(o,n,r,e)}});var xe=M({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Cs=M({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Ss=M({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Bs=M({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Ns=M({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Ds=M({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Os=M({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Rs=M({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Ms=M({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var V=wt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Ls=wt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var mo=Jr,qr=128,go=127,wo=~go,xo=Math.pow(2,31);function Jr(e,t,r){t=t||[],r=r||0;for(var n=r;e>=xo;)t[r++]=e&255|qr,e/=128;for(;e&wo;)t[r++]=e&255|qr,e>>>=7;return t[r]=e|0,Jr.bytes=r-n+1,t}var bo=xt,vo=128,Gr=127;function xt(e,n){var r=0,n=n||0,o=0,i=n,a,c=e.length;do{if(i>=c)throw xt.bytes=0,new RangeError("Could not decode varint");a=e[i++],r+=o<28?(a&Gr)<<o:(a&Gr)*Math.pow(2,o),o+=7}while(a>=vo);return xt.bytes=i-n,r}var Eo=Math.pow(2,7),ko=Math.pow(2,14),Ao=Math.pow(2,21),_o=Math.pow(2,28),To=Math.pow(2,35),Uo=Math.pow(2,42),Io=Math.pow(2,49),Co=Math.pow(2,56),So=Math.pow(2,63),Bo=function(e){return e<Eo?1:e<ko?2:e<Ao?3:e<_o?4:e<To?5:e<Uo?6:e<Io?7:e<Co?8:e<So?9:10},No={encode:mo,decode:bo,encodingLength:Bo},Do=No,be=Do;var ve=(e,t=0)=>[be.decode(e,t),be.decode.bytes],se=(e,t,r=0)=>(be.encode(e,t,r),t),ae=e=>be.encodingLength(e);var Wr=(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]=ve(t),[o,i]=ve(t.subarray(n)),a=t.subarray(n+i);if(a.byteLength!==o)throw new Error("Incorrect length");return new ce(r,o,a,t)},Xr=(e,t)=>{if(e===t)return!0;{let r=t;return e.code===r.code&&e.size===r.size&&r.bytes instanceof Uint8Array&&Fr(e.bytes,r.bytes)}},ce=class{constructor(t,r,n,o){this.code=t,this.size=r,this.digest=n,this.bytes=o}};var Qr=(e,t)=>{let{bytes:r,version:n}=e;switch(n){case 0:return Ro(r,vt(e),t||V.encoder);default:return Mo(r,vt(e),t||xe.encoder)}};var Yr=new WeakMap,vt=e=>{let t=Yr.get(e);if(t==null){let r=new Map;return Yr.set(e,r),r}return t},w=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!==Ee)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==$o)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=Wr(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&&Xr(t.multihash,n.multihash)}toString(t){return Qr(this,t)}toJSON(){return{"/":Qr(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||Zr(n,o,i.bytes))}else if(r[zo]===!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!==Ee)throw new Error(`Version 0 CID must use dag-pb (code: ${Ee}) block encoding`);return new e(t,r,n,n.bytes)}case 1:{let o=Zr(t,r,n.bytes);return new e(t,r,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return e.create(0,Ee,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[j,Te]=ve(t.subarray(r));return r+=Te,j},o=n(),i=Ee;if(o===18?(o=0,r=0):i=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let a=r,c=n(),d=n(),h=r+d,p=h-a;return{version:o,codec:i,multihashCode:c,digestSize:d,multihashSize:p,size:h}}static parse(t,r){let[n,o]=Oo(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 vt(i).set(n,t),i}},Oo=(e,t)=>{switch(e[0]){case"Q":{let r=t||V;return[V.prefix,r.decode(`${V.prefix}${e}`)]}case V.prefix:{let r=t||V;return[V.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)]}}},Ro=(e,t,r)=>{let{prefix:n}=r;if(n!==V.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},Mo=(e,t,r)=>{let{prefix:n}=r,o=t.get(n);if(o==null){let i=r.encode(e);return t.set(n,i),i}else return o},Ee=112,$o=18,Zr=(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},zo=Symbol.for("@ipld/js-cid/CID");var jr=42;function Lo(e){if(e.asCID!==e&&e["/"]!==e.bytes)return null;let t=w.asCID(e);if(!t)return null;let r=new Uint8Array(t.bytes.byteLength+1);return r.set(t.bytes,1),[new f(s.tag,jr),new f(s.bytes,r)]}function Vo(){throw new Error("`undefined` is not supported by the IPLD Data Model and cannot be encoded")}function Fo(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 Ho={float64:!0,typeEncoders:{Object:Lo,undefined:Vo,number:Fo}};function Po(e){if(e[0]!==0)throw new Error("Invalid CID for CBOR tag 42; expected leading 0x00");return w.decode(e.subarray(1))}var en={allowIndefinite:!1,coerceUndefinedToNull:!0,allowNaN:!1,allowInfinity:!1,allowBigInt:!0,strict:!0,useMaps:!1,rejectDuplicateMapKeys:!0,tags:[]};en.tags[jr]=Po;var Fe=e=>dt(e,Ho),He=e=>ht(e,en);var G=Ce(Pe(),1),J={SHA2_256:18,LENGTH:32,DAG_PB:112},qe=16+8+8+8;function $(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 Ge(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 Je(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 K={Null:e=>e===null?e:void 0,Int:e=>Number.isInteger(e)?e:void 0,Float:e=>typeof e=="number"&&Number.isFinite(e)?e:void 0,String:e=>typeof e=="string"?e:void 0,Bool:e=>typeof e=="boolean"?e:void 0,Bytes:e=>e instanceof Uint8Array?e:void 0,Link:e=>e!==null&&typeof e=="object"&&e.asCID===e?e:void 0,List:e=>Array.isArray(e)?e:void 0,Map:e=>e!==null&&typeof e=="object"&&e.asCID!==e&&!Array.isArray(e)&&!(e instanceof Uint8Array)?e:void 0},ke={"CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)":K.Link,"CarV1HeaderOrV2Pragma > roots (anon)":e=>{if(K.List(e)!==void 0){for(let t=0;t<e.length;t++){let r=e[t];if(r=ke["CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)"](r),r===void 0)return;if(r!==e[t]){let n=e.slice(0,t);for(let o=t;o<e.length;o++){let i=e[o];if(i=ke["CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)"](i),i===void 0)return;n.push(i)}return n}}return e}},Int:K.Int,CarV1HeaderOrV2Pragma:e=>{if(K.Map(e)===void 0)return;let t=Object.entries(e),r=e,n=1;for(let o=0;o<t.length;o++){let[i,a]=t[o];switch(i){case"roots":{let c=ke["CarV1HeaderOrV2Pragma > roots (anon)"](e[i]);if(c===void 0)return;if(c!==a||r!==e){if(r===e){r={};for(let d=0;d<o;d++)r[t[d][0]]=t[d][1]}r.roots=c}}break;case"version":{n--;let c=ke.Int(e[i]);if(c===void 0)return;if(c!==a||r!==e){if(r===e){r={};for(let d=0;d<o;d++)r[t[d][0]]=t[d][1]}r.version=c}}break;default:return}}if(!(n>0))return r}},Ae={"CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)":K.Link,"CarV1HeaderOrV2Pragma > roots (anon)":e=>{if(K.List(e)!==void 0){for(let t=0;t<e.length;t++){let r=e[t];if(r=Ae["CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)"](r),r===void 0)return;if(r!==e[t]){let n=e.slice(0,t);for(let o=t;o<e.length;o++){let i=e[o];if(i=Ae["CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)"](i),i===void 0)return;n.push(i)}return n}}return e}},Int:K.Int,CarV1HeaderOrV2Pragma:e=>{if(K.Map(e)===void 0)return;let t=Object.entries(e),r=e,n=1;for(let o=0;o<t.length;o++){let[i,a]=t[o];switch(i){case"roots":{let c=Ae["CarV1HeaderOrV2Pragma > roots (anon)"](a);if(c===void 0)return;if(c!==a||r!==e){if(r===e){r={};for(let d=0;d<o;d++)r[t[d][0]]=t[d][1]}r.roots=c}}break;case"version":{n--;let c=Ae.Int(a);if(c===void 0)return;if(c!==a||r!==e){if(r===e){r={};for(let d=0;d<o;d++)r[t[d][0]]=t[d][1]}r.version=c}}break;default:return}}if(!(n>0))return r}},Ke={toTyped:ke.CarV1HeaderOrV2Pragma,toRepresentation:Ae.CarV1HeaderOrV2Pragma};function dn(e,t){let r=$(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(Ke.toTyped(o)===void 0)throw new Error("Invalid CAR header format");if(o.version!==1&&o.version!==2||t!==void 0&&o.version!==t)throw new Error(`Invalid CAR version: ${o.version}${t!==void 0?` (expected ${t})`:""}`);if(o.version===1){if(!Array.isArray(o.roots))throw new Error("Invalid CAR header format");return o}if(o.roots!==void 0)throw new Error("Invalid CAR header format");let i=Ge(e.exactly(qe,!0));e.seek(i.dataOffset-e.pos);let a=dn(e,1);return Object.assign(a,i)}function oi(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 w.create(0,J.DAG_PB,c)}let r=$(e.upTo(8),e);if(r!==1)throw new Error(`Unexpected CID version (${r})`);let n=$(e.upTo(8),e),o=e.exactly(Je(e.upTo(8)),!0),i=q(o);return w.create(r,n,i)}function ii(e){let t=e.pos,r=$(e.upTo(8),e);if(r===0)throw new Error("Invalid CAR section (zero length)");r+=e.pos-t;let n=oi(e),o=r-Number(e.pos-t);return{cid:n,length:r,blockLength:o}}function ln(e){let t=si(e),r=dn(t);if(r.version===2){let o=t.pos-r.dataOffset;t=ai(t,r.dataSize-o)}let n=[];for(;t.upTo(8).length>0;){let{cid:o,blockLength:i}=ii(t);n.push({cid:o,bytes:t.exactly(i,!0)})}return{header:r,blocks:n}}function si(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 ai(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 We=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}=ln(t);return new e(r,n)}};var St={};Ot(St,{addBlock:()=>yn,addRoot:()=>pn,blockLength:()=>di,calculateHeaderLength:()=>It,close:()=>mn,createWriter:()=>yi,estimateHeaderLength:()=>pi,headerLength:()=>Ct,resizeHeader:()=>Ut});var fi=ut(),ui={float64:!1,quickEncodeToken:ze};function At(e,t=fi,r=ui){if(Array.isArray(e)){let n=0;for(let o of e)n+=At(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 _e=Ce(Pe(),1),Tt=class{constructor(t,r){this.bytes=t,this.byteOffset=r,this.roots=[],this.headerSize=r}addRoot(t,r){return pn(this,t,r),this}write(t){return yn(this,t),this}close(t){return mn(this,t)}},pn=(e,t,r={})=>{let{resize:n=!1}=r,{bytes:o,headerSize:i,byteOffset:a,roots:c}=e;e.roots.push(t);let d=Ct(e);if(d>i)if(d-i+a<o.byteLength)if(n)Ut(e,d);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}`)},di=({cid:e,bytes:t})=>{let r=e.bytes.byteLength+t.byteLength;return _e.default.encodingLength(r)+r},yn=(e,{cid:t,bytes:r})=>{let n=t.bytes.byteLength+r.byteLength,o=_e.default.encode(n);if(e.byteOffset+o.length+n>e.bytes.byteLength)throw new RangeError("Buffer has no capacity for this block");_t(e,o),_t(e,t.bytes),_t(e,r)},mn=(e,t={})=>{let{resize:r=!1}=t,{roots:n,bytes:o,byteOffset:i,headerSize:a}=e,c=Fe({version:1,roots:n}),d=_e.default.encode(c.length),h=d.length+c.byteLength;if(a-h===0)return hn(e,d,c),o.subarray(0,i);if(r)return Ut(e,h),hn(e,d,c),o.subarray(0,e.byteOffset);throw new RangeError(`Header size was overestimated.
|
|
4
|
+
You can use close({ resize: true }) to resize header`)},Ut=(e,t)=>{let{bytes:r,headerSize:n}=e;r.set(r.subarray(n,e.byteOffset),t),e.byteOffset+=t-n,e.headerSize=t},_t=(e,t)=>{e.bytes.set(t,e.byteOffset),e.byteOffset+=t.length},hn=({bytes:e},t,r)=>{e.set(t),e.set(r,t.length)},li=[new f(s.map,2),new f(s.string,"version"),new f(s.uint,1),new f(s.string,"roots")],hi=new f(s.tag,42),It=e=>{let t=[...li];t.push(new f(s.array,e.length));for(let n of e)t.push(hi),t.push(new f(s.bytes,{length:n+1}));let r=At(t);return _e.default.encodingLength(r)+r},Ct=({roots:e})=>It(e.map(t=>t.bytes.byteLength)),pi=(e,t=36)=>It(new Array(e).fill(t)),yi=(e,t={})=>{let{roots:r=[],byteOffset:n=0,byteLength:o=e.byteLength,headerSize:i=Ct({roots:r})}=t,a=new Uint8Array(e,n,o),c=new Tt(a,i);for(let d of r)c.addRoot(d);return c};var Bt=Ce(gn(),1);async function Xe(e,t){let r=$(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(Ke.toTyped(o)===void 0)throw new Error("Invalid CAR header format");if(o.version!==1&&o.version!==2||t!==void 0&&o.version!==t)throw new Error(`Invalid CAR version: ${o.version}${t!==void 0?` (expected ${t})`:""}`);if(o.version===1){if(!Array.isArray(o.roots))throw new Error("Invalid CAR header format");return o}if(o.roots!==void 0)throw new Error("Invalid CAR header format");let i=Ge(await e.exactly(qe,!0));e.seek(i.dataOffset-e.pos);let a=await Xe(e,1);return Object.assign(a,i)}async function mi(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 w.create(0,J.DAG_PB,c)}let r=$(await e.upTo(8),e);if(r!==1)throw new Error(`Unexpected CID version (${r})`);let n=$(await e.upTo(8),e),o=await e.exactly(Je(await e.upTo(8)),!0),i=q(o);return w.create(r,n,i)}async function wn(e){let t=e.pos,r=$(await e.upTo(8),e);if(r===0)throw new Error("Invalid CAR section (zero length)");r+=e.pos-t;let n=await mi(e),o=r-Number(e.pos-t);return{cid:n,length:r,blockLength:o}}async function gi(e){let{cid:t,blockLength:r}=await wn(e);return{bytes:await e.exactly(r,!0),cid:t}}async function wi(e){let t=e.pos,{cid:r,length:n,blockLength:o}=await wn(e),i={cid:r,length:n,blockLength:o,offset:t,blockOffset:e.pos};return e.seek(i.blockLength),i}function fe(e){let t=(async()=>{let r=await Xe(e);if(r.version===2){let n=e.pos-r.dataOffset;e=bi(e,r.dataSize-n)}return r})();return{header:()=>t,async*blocks(){for(await t;(await e.upTo(8)).length>0;)yield await gi(e)},async*blocksIndex(){for(await t;(await e.upTo(8)).length>0;)yield await wi(e)}}}function W(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 xi(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 d=0;for(let h of c)o.set(h,d),d+=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 d=o.subarray(n,n+a);return c&&(t+=a,n+=a),d},seek(a){t+=a,n+=a},get pos(){return t}}}function ue(e){let t=e[Symbol.asyncIterator]();async function r(){let n=await t.next();return n.done?null:n.value}return xi(r)}function bi(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 Y=class{constructor(t,r,n){this._version=t,this._roots=r,this._iterator=n}get version(){return this._version}async getRoots(){return this._roots}[Symbol.asyncIterator](){return this._iterator}static async fromBytes(t){if(!(t instanceof Uint8Array))throw new TypeError("fromBytes() requires a Uint8Array");return xn(W(t))}static async fromIterable(t){if(!t||typeof t[Symbol.asyncIterator]!="function")throw new TypeError("fromIterable() requires an async iterable");return xn(ue(t))}};async function xn(e){let t=fe(e),{version:r,roots:n}=await t.header();return new Y(r,n,t.blocksIndex())}var Z=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 bn(W(t))}static async fromIterable(t){if(!t||typeof t[Symbol.asyncIterator]!="function")throw new TypeError("fromIterable() requires an async iterable");return bn(ue(t))}};async function bn(e){let t=fe(e),r=await t.header(),n=[];for await(let o of t.blocks())n.push(o);return new Z(r,n)}var Qe=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 Z.readRaw(this._fd,n)}async*blocks(){for(let t of this._order){let r=await this.get(w.parse(t));if(!r)throw new Error("Unexpected internal error");yield r}}async*cids(){for(let t of this._order)yield w.parse(t)}async close(){if(this._fd)return this._fd.close()}static async fromFile(t){if(typeof t!="string")throw new TypeError("fromFile() requires a file path string");let r=await Y.fromIterable((void 0).from(Bt.default.createReadStream(t))),n=new Map,o=[];for await(let{cid:i,blockLength:a,blockOffset:c}of r){let d=i.toString();n.set(d,{blockLength:a,blockOffset:c}),o.push(d)}return new e(r.version,t,await r.getRoots(),n,o)}};var Ye=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}},Ze=class e extends Ye{[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 En(t);return new e(r,n,o)}static async fromIterable(t){let{version:r,roots:n,iterator:o}=await kn(t);return new e(r,n,o)}},je=class e extends Ye{[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 En(t);return new e(r,n,o)}static async fromIterable(t){let{version:r,roots:n,iterator:o}=await kn(t);return new e(r,n,o)}};async function En(e){if(!(e instanceof Uint8Array))throw new TypeError("fromBytes() requires a Uint8Array");return An(W(e))}async function kn(e){if(!e||typeof e[Symbol.asyncIterator]!="function")throw new TypeError("fromIterable() requires an async iterable");return An(ue(e))}async function An(e){let t=fe(e),{version:r,roots:n}=await t.header();return{version:r,roots:n,iterator:t.blocks()}}var Nt=Ce(Pe(),1);function Dt(e){let t=Fe({version:1,roots:e}),r=Nt.default.encode(t.length),n=new Uint8Array(r.length+t.length);return n.set(r,0),n.set(t,r.length),n}function _n(e){return{async setRoots(t){let r=Dt(t);await e.write(r)},async writeBlock(t){let{cid:r,bytes:n}=t;await e.write(new Uint8Array(Nt.default.encode(r.bytes.length+n.length))),await e.write(r.bytes),n.length&&await e.write(n)},async close(){await e.end()}}}function et(){}function Tn(){let e=[],t=null,r=et,n=!1,o=null,i=et,a=()=>(t||(t=new Promise(h=>{r=()=>{t=null,r=et,h()}})),t),c={write(h){e.push(h);let p=a();return i(),p},async end(){n=!0;let h=a();i(),await h}},d={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=et,p(d.next()))})),o)}};return{writer:c,iterator:d}}var tt=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=w.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=vi(t);let{encoder:r,iterator:n}=Un(),o=new e(t,r),i=new rt(n);return{writer:o,out:i}}static createAppender(){let{encoder:t,iterator:r}=Un();t.setRoots=()=>Promise.resolve();let n=new e([],t),o=new rt(r);return{writer:n,out:o}}static async updateRootsInBytes(t,r){let n=W(t);await Xe(n);let o=Dt(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}},rt=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 Un(){let e=Tn(),{writer:t,iterator:r}=e;return{encoder:_n(t),iterator:r}}function vi(e){if(e===void 0)return[];if(!Array.isArray(e)){let r=w.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=w.asCID(r);if(!n)throw new TypeError("roots must be a single CID or an array of CIDs");t.push(n)}return t}var Ei="application/vnd.ipld.car";return On(ki);})();
|
|
5
5
|
return IpldCar}));
|
package/dist/src/api.d.ts
CHANGED
|
@@ -19,40 +19,40 @@ export interface BlockIndex extends BlockHeader {
|
|
|
19
19
|
}
|
|
20
20
|
export interface RootsReader {
|
|
21
21
|
version: number;
|
|
22
|
-
getRoots
|
|
22
|
+
getRoots(): Promise<CID[]>;
|
|
23
23
|
}
|
|
24
24
|
export interface RootsBufferReader {
|
|
25
25
|
version: number;
|
|
26
|
-
getRoots
|
|
26
|
+
getRoots(): CID[];
|
|
27
27
|
}
|
|
28
28
|
export interface BlockIterator extends AsyncIterable<Block> {
|
|
29
29
|
}
|
|
30
30
|
export interface CIDIterator extends AsyncIterable<CID> {
|
|
31
31
|
}
|
|
32
32
|
export interface BlockReader {
|
|
33
|
-
has
|
|
34
|
-
get
|
|
35
|
-
blocks
|
|
36
|
-
cids
|
|
33
|
+
has(key: CID): Promise<boolean>;
|
|
34
|
+
get(key: CID): Promise<Block | undefined>;
|
|
35
|
+
blocks(): BlockIterator;
|
|
36
|
+
cids(): CIDIterator;
|
|
37
37
|
}
|
|
38
38
|
export interface BlockBufferReader {
|
|
39
|
-
has
|
|
40
|
-
get
|
|
41
|
-
blocks
|
|
42
|
-
cids
|
|
39
|
+
has(key: CID): boolean;
|
|
40
|
+
get(key: CID): Block | undefined;
|
|
41
|
+
blocks(): Iterable<Block>;
|
|
42
|
+
cids(): Iterable<CID>;
|
|
43
43
|
}
|
|
44
44
|
export interface BlockWriter {
|
|
45
|
-
put
|
|
46
|
-
close
|
|
45
|
+
put(block: Block): Promise<void>;
|
|
46
|
+
close(): Promise<void>;
|
|
47
47
|
}
|
|
48
48
|
export interface CarBufferWriter {
|
|
49
|
-
addRoot
|
|
49
|
+
addRoot(root: CID, options?: {
|
|
50
50
|
resize?: boolean;
|
|
51
|
-
})
|
|
52
|
-
write
|
|
53
|
-
close
|
|
51
|
+
}): CarBufferWriter;
|
|
52
|
+
write(block: Block): CarBufferWriter;
|
|
53
|
+
close(options?: {
|
|
54
54
|
resize?: boolean;
|
|
55
|
-
})
|
|
55
|
+
}): Uint8Array;
|
|
56
56
|
}
|
|
57
57
|
export interface CarBufferWriterOptions {
|
|
58
58
|
roots?: CID[];
|
package/dist/src/api.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../src/api.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAA;AAE3C;;GAEG;AACH,MAAM,MAAM,aAAa,CAAC,CAAC,IAAI,QAAQ,CAAC,CAAC,CAAC,GAAG,aAAa,CAAC,CAAC,CAAC,CAAA;AAE7D,YAAY,EAAE,GAAG,EAAE,CAAA;AAGnB,MAAM,WAAW,KAAK;IACpB,GAAG,EAAE,GAAG,CAAA;IACR,KAAK,EAAE,UAAU,CAAA;CAClB;AAED,MAAM,WAAW,WAAW;IAC1B,GAAG,EAAE,GAAG,CAAA;IACR,MAAM,EAAE,MAAM,CAAA;IACd,WAAW,EAAE,MAAM,CAAA;CACpB;AAED,MAAM,WAAW,UAAW,SAAQ,WAAW;IAC7C,MAAM,EAAE,MAAM,CAAA;IACd,WAAW,EAAE,MAAM,CAAA;CACpB;AAED,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,MAAM,CAAA;IACf,QAAQ,
|
|
1
|
+
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../src/api.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAA;AAE3C;;GAEG;AACH,MAAM,MAAM,aAAa,CAAC,CAAC,IAAI,QAAQ,CAAC,CAAC,CAAC,GAAG,aAAa,CAAC,CAAC,CAAC,CAAA;AAE7D,YAAY,EAAE,GAAG,EAAE,CAAA;AAGnB,MAAM,WAAW,KAAK;IACpB,GAAG,EAAE,GAAG,CAAA;IACR,KAAK,EAAE,UAAU,CAAA;CAClB;AAED,MAAM,WAAW,WAAW;IAC1B,GAAG,EAAE,GAAG,CAAA;IACR,MAAM,EAAE,MAAM,CAAA;IACd,WAAW,EAAE,MAAM,CAAA;CACpB;AAED,MAAM,WAAW,UAAW,SAAQ,WAAW;IAC7C,MAAM,EAAE,MAAM,CAAA;IACd,WAAW,EAAE,MAAM,CAAA;CACpB;AAED,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,MAAM,CAAA;IACf,QAAQ,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC,CAAA;CAC3B;AAED,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE,MAAM,CAAA;IACf,QAAQ,IAAI,GAAG,EAAE,CAAA;CAClB;AAED,MAAM,WAAW,aAAc,SAAQ,aAAa,CAAC,KAAK,CAAC;CAAG;AAE9D,MAAM,WAAW,WAAY,SAAQ,aAAa,CAAC,GAAG,CAAC;CAAG;AAE1D,MAAM,WAAW,WAAW;IAC1B,GAAG,CAAC,GAAG,EAAE,GAAG,GAAG,OAAO,CAAC,OAAO,CAAC,CAAA;IAC/B,GAAG,CAAC,GAAG,EAAE,GAAG,GAAG,OAAO,CAAC,KAAK,GAAG,SAAS,CAAC,CAAA;IACzC,MAAM,IAAI,aAAa,CAAA;IACvB,IAAI,IAAI,WAAW,CAAA;CACpB;AAED,MAAM,WAAW,iBAAiB;IAChC,GAAG,CAAC,GAAG,EAAE,GAAG,GAAG,OAAO,CAAA;IACtB,GAAG,CAAC,GAAG,EAAE,GAAG,GAAG,KAAK,GAAG,SAAS,CAAA;IAChC,MAAM,IAAI,QAAQ,CAAC,KAAK,CAAC,CAAA;IACzB,IAAI,IAAI,QAAQ,CAAC,GAAG,CAAC,CAAA;CACtB;AAED,MAAM,WAAW,WAAW;IAC1B,GAAG,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IAChC,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;CACvB;AAED,MAAM,WAAW,eAAe;IAC9B,OAAO,CAAC,IAAI,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,eAAe,CAAA;IACnE,KAAK,CAAC,KAAK,EAAE,KAAK,GAAG,eAAe,CAAA;IACpC,KAAK,CAAC,OAAO,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,UAAU,CAAA;CAClD;AAED,MAAM,WAAW,sBAAsB;IACrC,KAAK,CAAC,EAAE,GAAG,EAAE,CAAA;IACb,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,UAAU,CAAC,EAAE,MAAM,CAAA;IAEnB,UAAU,CAAC,EAAE,MAAM,CAAA;CACpB;AAED,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,WAAW,CAAA;IACnB,GAAG,EAAE,aAAa,CAAC,UAAU,CAAC,CAAA;CAC/B;AAED,MAAM,WAAW,SAAU,SAAQ,WAAW,EAAE,WAAW;CAAG;AAC9D,MAAM,WAAW,eAAgB,SAAQ,iBAAiB,EAAE,iBAAiB;CAAG"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buffer-decoder.d.ts","sourceRoot":"","sources":["../../src/buffer-decoder.js"],"names":[],"mappings":"AAMA;;;;;;;;GAQG;AAEH;;;;;;;;GAQG;AACH,mCAJW,iBAAiB,uCAEf,SAAS,GAAG,WAAW,
|
|
1
|
+
{"version":3,"file":"buffer-decoder.d.ts","sourceRoot":"","sources":["../../src/buffer-decoder.js"],"names":[],"mappings":"AAMA;;;;;;;;GAQG;AAEH;;;;;;;;GAQG;AACH,mCAJW,iBAAiB,uCAEf,SAAS,GAAG,WAAW,CA8BnC;AA2BD;;;;;;;;;GASG;AACH,sCAHW,iBAAiB,GACf,WAAW,CAevB;AAED;;;;;GAKG;AACH,iCAHW,UAAU;YACG,SAAS,GAAG,WAAW;YAAW,KAAK,EAAE;EAoBhE;AAED;;;;;;GAMG;AACH,mCAHW,UAAU,GACR,iBAAiB,CA+B7B;AAED;;;;;;;;;GASG;AACH,oCAJW,iBAAiB,aACjB,MAAM,GACJ,iBAAiB,CAmC7B;oBA7MY,OAAO,OAAO,EAAE,KAAK;0BACrB,OAAO,OAAO,EAAE,WAAW;yBAC3B,OAAO,OAAO,EAAE,UAAU;gCAC1B,OAAO,UAAU,EAAE,iBAAiB;wBACpC,OAAO,UAAU,EAAE,SAAS;0BAC5B,OAAO,UAAU,EAAE,WAAW;+BAC9B,OAAO,UAAU,EAAE,gBAAgB"}
|
package/dist/src/coding.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import type { Block, BlockIndex } from './api.js';
|
|
2
2
|
import type { CID } from 'multiformats/cid';
|
|
3
3
|
export interface CarEncoder {
|
|
4
|
-
setRoots
|
|
5
|
-
writeBlock
|
|
6
|
-
close
|
|
4
|
+
setRoots(roots: CID[]): Promise<void>;
|
|
5
|
+
writeBlock(block: Block): Promise<void>;
|
|
6
|
+
close(): Promise<void>;
|
|
7
7
|
}
|
|
8
8
|
export interface IteratorChannel_Writer<T> {
|
|
9
|
-
write
|
|
10
|
-
end
|
|
9
|
+
write(chunk: T): Promise<void>;
|
|
10
|
+
end(): Promise<void>;
|
|
11
11
|
}
|
|
12
12
|
export interface IteratorChannel<T> {
|
|
13
13
|
writer: IteratorChannel_Writer<T>;
|
|
@@ -28,21 +28,21 @@ export interface CarV2Header extends CarV2FixedHeader {
|
|
|
28
28
|
roots: CID[];
|
|
29
29
|
}
|
|
30
30
|
export interface CarDecoder {
|
|
31
|
-
header
|
|
32
|
-
blocks
|
|
33
|
-
blocksIndex
|
|
31
|
+
header(): Promise<CarHeader | CarV2Header>;
|
|
32
|
+
blocks(): AsyncGenerator<Block>;
|
|
33
|
+
blocksIndex(): AsyncGenerator<BlockIndex>;
|
|
34
34
|
}
|
|
35
35
|
export interface Seekable {
|
|
36
|
-
seek
|
|
36
|
+
seek(length: number): void;
|
|
37
37
|
}
|
|
38
38
|
export interface BytesReader extends Seekable {
|
|
39
|
-
upTo
|
|
40
|
-
exactly
|
|
39
|
+
upTo(length: number): Promise<Uint8Array>;
|
|
40
|
+
exactly(length: number, seek?: boolean): Promise<Uint8Array>;
|
|
41
41
|
pos: number;
|
|
42
42
|
}
|
|
43
43
|
export interface BytesBufferReader extends Seekable {
|
|
44
|
-
upTo
|
|
45
|
-
exactly
|
|
44
|
+
upTo(length: number): Uint8Array;
|
|
45
|
+
exactly(length: number, seek?: boolean): Uint8Array;
|
|
46
46
|
pos: number;
|
|
47
47
|
}
|
|
48
48
|
//# sourceMappingURL=coding.d.ts.map
|
package/dist/src/coding.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"coding.d.ts","sourceRoot":"","sources":["../../src/coding.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AACjD,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAA;AAE3C,MAAM,WAAW,UAAU;IACzB,QAAQ,
|
|
1
|
+
{"version":3,"file":"coding.d.ts","sourceRoot":"","sources":["../../src/coding.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AACjD,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAA;AAE3C,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,KAAK,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IAErC,UAAU,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IAEvC,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;CACvB;AAED,MAAM,WAAW,sBAAsB,CAAC,CAAC;IACvC,KAAK,CAAC,KAAK,EAAE,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IAC9B,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;CACrB;AAED,MAAM,WAAW,eAAe,CAAC,CAAC;IAChC,MAAM,EAAE,sBAAsB,CAAC,CAAC,CAAC,CAAA;IAEjC,QAAQ,EAAE,aAAa,CAAC,CAAC,CAAC,CAAA;CAC3B;AAED,MAAM,WAAW,SAAS;IACxB,OAAO,EAAE,CAAC,CAAA;IACV,KAAK,EAAE,GAAG,EAAE,CAAA;CACb;AAED,MAAM,WAAW,gBAAgB;IAC/B,eAAe,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IACjC,UAAU,EAAE,MAAM,CAAA;IAClB,QAAQ,EAAE,MAAM,CAAA;IAChB,WAAW,EAAE,MAAM,CAAA;CACpB;AAED,MAAM,WAAW,WAAY,SAAQ,gBAAgB;IACnD,OAAO,EAAE,CAAC,CAAA;IACV,KAAK,EAAE,GAAG,EAAE,CAAA;CACb;AAED,MAAM,WAAW,UAAU;IACzB,MAAM,IAAI,OAAO,CAAC,SAAS,GAAG,WAAW,CAAC,CAAA;IAE1C,MAAM,IAAI,cAAc,CAAC,KAAK,CAAC,CAAA;IAE/B,WAAW,IAAI,cAAc,CAAC,UAAU,CAAC,CAAA;CAC1C;AAED,MAAM,WAAW,QAAQ;IACvB,IAAI,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAA;CAC3B;AAED,MAAM,WAAW,WAAY,SAAQ,QAAQ;IAC3C,IAAI,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,CAAA;IAEzC,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,UAAU,CAAC,CAAA;IAE5D,GAAG,EAAE,MAAM,CAAA;CACZ;AAED,MAAM,WAAW,iBAAkB,SAAQ,QAAQ;IACjD,IAAI,CAAC,MAAM,EAAE,MAAM,GAAG,UAAU,CAAA;IAEhC,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,UAAU,CAAA;IAEnD,GAAG,EAAE,MAAM,CAAA;CACZ"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decoder.d.ts","sourceRoot":"","sources":["../../src/decoder.js"],"names":[],"mappings":"AAMA;;;;;;;;;GASG;AAEH;;;;;;;;GAQG;AACH,mCAJW,WAAW,uCAET,QAAQ,SAAS,GAAC,WAAW,CAAC,
|
|
1
|
+
{"version":3,"file":"decoder.d.ts","sourceRoot":"","sources":["../../src/decoder.js"],"names":[],"mappings":"AAMA;;;;;;;;;GASG;AAEH;;;;;;;;GAQG;AACH,mCAJW,WAAW,uCAET,QAAQ,SAAS,GAAC,WAAW,CAAC,CA8B1C;AAyBD;;;;;;;;;GASG;AACH,sCAHW,WAAW,GACT,QAAQ,WAAW,CAAC,CAehC;AAwBD;;;;;;;;GAQG;AACH,sCAHW,WAAW,GACT,UAAU,CA6BtB;AAED;;;;;;GAMG;AACH,mCAHW,UAAU,GACR,WAAW,CA+BvB;AAED;;;;;;;GAOG;AACH,uCAHW,MAAM,QAAQ,UAAU,GAAC,IAAI,CAAC,GAC5B,WAAW,CAuEvB;AAED;;;;;;;GAOG;AACH,mDAHW,cAAc,UAAU,CAAC,GACvB,WAAW,CAcvB;AAED;;;;;;;;;GASG;AACH,oCAJW,WAAW,aACX,MAAM,GACJ,WAAW,CAmCvB;oBAnVY,OAAO,OAAO,EAAE,KAAK;0BACrB,OAAO,OAAO,EAAE,WAAW;yBAC3B,OAAO,OAAO,EAAE,UAAU;0BAC1B,OAAO,UAAU,EAAE,WAAW;wBAC9B,OAAO,UAAU,EAAE,SAAS;0BAC5B,OAAO,UAAU,EAAE,WAAW;+BAC9B,OAAO,UAAU,EAAE,gBAAgB;yBACnC,OAAO,UAAU,EAAE,UAAU"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"header-validator.d.ts","sourceRoot":"","sources":["../../src/header-validator.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"header-validator.d.ts","sourceRoot":"","sources":["../../src/header-validator.js"],"names":[],"mappings":";IAkC4B,gCAAwB;IAwFxB,yCAAwB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ipld/car",
|
|
3
|
-
"version": "5.2.
|
|
3
|
+
"version": "5.2.4",
|
|
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",
|
|
@@ -184,6 +184,7 @@
|
|
|
184
184
|
"clean": "aegir clean",
|
|
185
185
|
"lint": "aegir lint",
|
|
186
186
|
"build": "aegir build",
|
|
187
|
+
"build:validator": "npx @ipld/schema to-js src/header.ipldsch > src/header-validator.js",
|
|
187
188
|
"release": "aegir release",
|
|
188
189
|
"test": "npm run lint && aegir test && npm run test:examples",
|
|
189
190
|
"test:node": "aegir test -t node --cov",
|
|
@@ -207,7 +208,7 @@
|
|
|
207
208
|
"@ipld/dag-pb": "^4.0.0",
|
|
208
209
|
"@ipld/garbage": "^6.0.0",
|
|
209
210
|
"@types/varint": "^6.0.0",
|
|
210
|
-
"aegir": "^
|
|
211
|
+
"aegir": "^41.0.0",
|
|
211
212
|
"jsdoc4readme": "^1.4.0"
|
|
212
213
|
},
|
|
213
214
|
"browser": {
|
|
@@ -227,5 +228,8 @@
|
|
|
227
228
|
"ignore": [
|
|
228
229
|
"dist"
|
|
229
230
|
]
|
|
230
|
-
}
|
|
231
|
+
},
|
|
232
|
+
"eslintIgnore": [
|
|
233
|
+
"src/header-validator.js"
|
|
234
|
+
]
|
|
231
235
|
}
|
package/src/api.ts
CHANGED
|
@@ -26,12 +26,12 @@ export interface BlockIndex extends BlockHeader {
|
|
|
26
26
|
|
|
27
27
|
export interface RootsReader {
|
|
28
28
|
version: number
|
|
29
|
-
getRoots
|
|
29
|
+
getRoots(): Promise<CID[]>
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
export interface RootsBufferReader {
|
|
33
33
|
version: number
|
|
34
|
-
getRoots
|
|
34
|
+
getRoots(): CID[]
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
export interface BlockIterator extends AsyncIterable<Block> {}
|
|
@@ -39,28 +39,28 @@ export interface BlockIterator extends AsyncIterable<Block> {}
|
|
|
39
39
|
export interface CIDIterator extends AsyncIterable<CID> {}
|
|
40
40
|
|
|
41
41
|
export interface BlockReader {
|
|
42
|
-
has
|
|
43
|
-
get
|
|
44
|
-
blocks
|
|
45
|
-
cids
|
|
42
|
+
has(key: CID): Promise<boolean>
|
|
43
|
+
get(key: CID): Promise<Block | undefined>
|
|
44
|
+
blocks(): BlockIterator
|
|
45
|
+
cids(): CIDIterator
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
export interface BlockBufferReader {
|
|
49
|
-
has
|
|
50
|
-
get
|
|
51
|
-
blocks
|
|
52
|
-
cids
|
|
49
|
+
has(key: CID): boolean
|
|
50
|
+
get(key: CID): Block | undefined
|
|
51
|
+
blocks(): Iterable<Block>
|
|
52
|
+
cids(): Iterable<CID>
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
export interface BlockWriter {
|
|
56
|
-
put
|
|
57
|
-
close
|
|
56
|
+
put(block: Block): Promise<void>
|
|
57
|
+
close(): Promise<void>
|
|
58
58
|
}
|
|
59
59
|
|
|
60
60
|
export interface CarBufferWriter {
|
|
61
|
-
addRoot
|
|
62
|
-
write
|
|
63
|
-
close
|
|
61
|
+
addRoot(root: CID, options?: { resize?: boolean }): CarBufferWriter
|
|
62
|
+
write(block: Block): CarBufferWriter
|
|
63
|
+
close(options?: { resize?: boolean }): Uint8Array
|
|
64
64
|
}
|
|
65
65
|
|
|
66
66
|
export interface CarBufferWriterOptions {
|
package/src/buffer-decoder.js
CHANGED
|
@@ -2,7 +2,7 @@ import { decode as decodeDagCbor } from '@ipld/dag-cbor'
|
|
|
2
2
|
import { CID } from 'multiformats/cid'
|
|
3
3
|
import * as Digest from 'multiformats/hashes/digest'
|
|
4
4
|
import { CIDV0_BYTES, decodeV2Header, decodeVarint, getMultihashLength, V2_HEADER_LENGTH } from './decoder-common.js'
|
|
5
|
-
import {
|
|
5
|
+
import { CarV1HeaderOrV2Pragma } from './header-validator.js'
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* @typedef {import('./api').Block} Block
|
|
@@ -30,22 +30,23 @@ export function readHeader (reader, strictVersion) {
|
|
|
30
30
|
}
|
|
31
31
|
const header = reader.exactly(length, true)
|
|
32
32
|
const block = decodeDagCbor(header)
|
|
33
|
-
if (
|
|
33
|
+
if (CarV1HeaderOrV2Pragma.toTyped(block) === undefined) {
|
|
34
34
|
throw new Error('Invalid CAR header format')
|
|
35
35
|
}
|
|
36
36
|
if ((block.version !== 1 && block.version !== 2) || (strictVersion !== undefined && block.version !== strictVersion)) {
|
|
37
37
|
throw new Error(`Invalid CAR version: ${block.version}${strictVersion !== undefined ? ` (expected ${strictVersion})` : ''}`)
|
|
38
38
|
}
|
|
39
|
-
// we've made 'roots' optional in the schema so we can do the version check
|
|
40
|
-
// before rejecting the block as invalid if there is no version
|
|
41
|
-
const hasRoots = Array.isArray(block.roots)
|
|
42
|
-
if ((block.version === 1 && !hasRoots) || (block.version === 2 && hasRoots)) {
|
|
43
|
-
throw new Error('Invalid CAR header format')
|
|
44
|
-
}
|
|
45
39
|
if (block.version === 1) {
|
|
40
|
+
// CarV1HeaderOrV2Pragma makes roots optional, let's make it mandatory
|
|
41
|
+
if (!Array.isArray(block.roots)) {
|
|
42
|
+
throw new Error('Invalid CAR header format')
|
|
43
|
+
}
|
|
46
44
|
return block
|
|
47
45
|
}
|
|
48
46
|
// version 2
|
|
47
|
+
if (block.roots !== undefined) {
|
|
48
|
+
throw new Error('Invalid CAR header format')
|
|
49
|
+
}
|
|
49
50
|
const v2Header = decodeV2Header(reader.exactly(V2_HEADER_LENGTH, true))
|
|
50
51
|
reader.seek(v2Header.dataOffset - reader.pos)
|
|
51
52
|
const v1Header = readHeader(reader, 1)
|
package/src/coding.ts
CHANGED
|
@@ -2,16 +2,16 @@ import type { Block, BlockIndex } from './api.js'
|
|
|
2
2
|
import type { CID } from 'multiformats/cid'
|
|
3
3
|
|
|
4
4
|
export interface CarEncoder {
|
|
5
|
-
setRoots
|
|
5
|
+
setRoots(roots: CID[]): Promise<void>
|
|
6
6
|
|
|
7
|
-
writeBlock
|
|
7
|
+
writeBlock(block: Block): Promise<void>
|
|
8
8
|
|
|
9
|
-
close
|
|
9
|
+
close(): Promise<void>
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
export interface IteratorChannel_Writer<T> {
|
|
13
|
-
write
|
|
14
|
-
end
|
|
13
|
+
write(chunk: T): Promise<void>
|
|
14
|
+
end(): Promise<void>
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
export interface IteratorChannel<T> {
|
|
@@ -38,29 +38,29 @@ export interface CarV2Header extends CarV2FixedHeader {
|
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
export interface CarDecoder {
|
|
41
|
-
header
|
|
41
|
+
header(): Promise<CarHeader | CarV2Header>
|
|
42
42
|
|
|
43
|
-
blocks
|
|
43
|
+
blocks(): AsyncGenerator<Block>
|
|
44
44
|
|
|
45
|
-
blocksIndex
|
|
45
|
+
blocksIndex(): AsyncGenerator<BlockIndex>
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
export interface Seekable {
|
|
49
|
-
seek
|
|
49
|
+
seek(length: number): void
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
export interface BytesReader extends Seekable {
|
|
53
|
-
upTo
|
|
53
|
+
upTo(length: number): Promise<Uint8Array>
|
|
54
54
|
|
|
55
|
-
exactly
|
|
55
|
+
exactly(length: number, seek?: boolean): Promise<Uint8Array>
|
|
56
56
|
|
|
57
57
|
pos: number
|
|
58
58
|
}
|
|
59
59
|
|
|
60
60
|
export interface BytesBufferReader extends Seekable {
|
|
61
|
-
upTo
|
|
61
|
+
upTo(length: number): Uint8Array
|
|
62
62
|
|
|
63
|
-
exactly
|
|
63
|
+
exactly(length: number, seek?: boolean): Uint8Array
|
|
64
64
|
|
|
65
65
|
pos: number
|
|
66
66
|
}
|
package/src/decoder.js
CHANGED
|
@@ -2,7 +2,7 @@ import { decode as decodeDagCbor } from '@ipld/dag-cbor'
|
|
|
2
2
|
import { CID } from 'multiformats/cid'
|
|
3
3
|
import * as Digest from 'multiformats/hashes/digest'
|
|
4
4
|
import { CIDV0_BYTES, decodeV2Header, decodeVarint, getMultihashLength, V2_HEADER_LENGTH } from './decoder-common.js'
|
|
5
|
-
import {
|
|
5
|
+
import { CarV1HeaderOrV2Pragma } from './header-validator.js'
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* @typedef {import('./api').Block} Block
|
|
@@ -31,22 +31,23 @@ export async function readHeader (reader, strictVersion) {
|
|
|
31
31
|
}
|
|
32
32
|
const header = await reader.exactly(length, true)
|
|
33
33
|
const block = decodeDagCbor(header)
|
|
34
|
-
if (
|
|
34
|
+
if (CarV1HeaderOrV2Pragma.toTyped(block) === undefined) {
|
|
35
35
|
throw new Error('Invalid CAR header format')
|
|
36
36
|
}
|
|
37
37
|
if ((block.version !== 1 && block.version !== 2) || (strictVersion !== undefined && block.version !== strictVersion)) {
|
|
38
38
|
throw new Error(`Invalid CAR version: ${block.version}${strictVersion !== undefined ? ` (expected ${strictVersion})` : ''}`)
|
|
39
39
|
}
|
|
40
|
-
// we've made 'roots' optional in the schema so we can do the version check
|
|
41
|
-
// before rejecting the block as invalid if there is no version
|
|
42
|
-
const hasRoots = Array.isArray(block.roots)
|
|
43
|
-
if ((block.version === 1 && !hasRoots) || (block.version === 2 && hasRoots)) {
|
|
44
|
-
throw new Error('Invalid CAR header format')
|
|
45
|
-
}
|
|
46
40
|
if (block.version === 1) {
|
|
41
|
+
// CarV1HeaderOrV2Pragma makes roots optional, let's make it mandatory
|
|
42
|
+
if (!Array.isArray(block.roots)) {
|
|
43
|
+
throw new Error('Invalid CAR header format')
|
|
44
|
+
}
|
|
47
45
|
return block
|
|
48
46
|
}
|
|
49
47
|
// version 2
|
|
48
|
+
if (block.roots !== undefined) {
|
|
49
|
+
throw new Error('Invalid CAR header format')
|
|
50
|
+
}
|
|
50
51
|
const v2Header = decodeV2Header(await reader.exactly(V2_HEADER_LENGTH, true))
|
|
51
52
|
reader.seek(v2Header.dataOffset - reader.pos)
|
|
52
53
|
const v1Header = await readHeader(reader, 1)
|
package/src/header-validator.js
CHANGED
|
@@ -1,74 +1,214 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
/** Auto-generated with @ipld/schema@v4.2.0 at Thu Sep 14 2023 from IPLD Schema:
|
|
2
|
+
*
|
|
3
|
+
* # CarV1HeaderOrV2Pragma is a more relaxed form, and can parse {version:x} where
|
|
4
|
+
* # roots are optional. This is typically useful for the {verison:2} CARv2
|
|
5
|
+
* # pragma.
|
|
4
6
|
*
|
|
5
|
-
* type
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
7
|
+
* type CarV1HeaderOrV2Pragma struct {
|
|
8
|
+
* roots optional [&Any]
|
|
9
|
+
* # roots is _not_ optional for CarV1 but we defer that check within code to
|
|
10
|
+
* # gracefully handle the V2 case where it's just {version:X}
|
|
11
|
+
* version Int
|
|
10
12
|
* }
|
|
11
13
|
*
|
|
14
|
+
* # CarV1Header is the strict form of the header, and requires roots to be
|
|
15
|
+
* # present. This is compatible with the CARv1 specification.
|
|
16
|
+
*
|
|
17
|
+
* # type CarV1Header struct {
|
|
18
|
+
* # roots [&Any]
|
|
19
|
+
* # version Int
|
|
20
|
+
* # }
|
|
21
|
+
*
|
|
12
22
|
*/
|
|
13
23
|
|
|
14
24
|
const Kinds = {
|
|
15
|
-
Null: /**
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
* @param {any} obj
|
|
25
|
-
* @returns {boolean}
|
|
26
|
-
*/ (/** @type {any} */ obj) => typeof obj === 'number' && Number.isFinite(obj),
|
|
27
|
-
String: /**
|
|
28
|
-
* @param {any} obj
|
|
29
|
-
* @returns {boolean}
|
|
30
|
-
*/ (/** @type {any} */ obj) => typeof obj === 'string',
|
|
31
|
-
Bool: /**
|
|
32
|
-
* @param {any} obj
|
|
33
|
-
* @returns {boolean}
|
|
34
|
-
*/ (/** @type {any} */ obj) => typeof obj === 'boolean',
|
|
35
|
-
Bytes: /**
|
|
36
|
-
* @param {any} obj
|
|
37
|
-
* @returns {boolean}
|
|
38
|
-
*/ (/** @type {any} */ obj) => obj instanceof Uint8Array,
|
|
39
|
-
Link: /**
|
|
40
|
-
* @param {any} obj
|
|
41
|
-
* @returns {boolean}
|
|
42
|
-
*/ (/** @type {any} */ obj) => !Kinds.Null(obj) && typeof obj === 'object' && obj.asCID === obj,
|
|
43
|
-
List: /**
|
|
44
|
-
* @param {any} obj
|
|
45
|
-
* @returns {boolean}
|
|
46
|
-
*/ (/** @type {any} */ obj) => Array.isArray(obj),
|
|
47
|
-
Map: /**
|
|
48
|
-
* @param {any} obj
|
|
49
|
-
* @returns {boolean}
|
|
50
|
-
*/ (/** @type {any} */ obj) => !Kinds.Null(obj) && typeof obj === 'object' && obj.asCID !== obj && !Kinds.List(obj) && !Kinds.Bytes(obj)
|
|
25
|
+
Null: /** @returns {undefined|null} */ (/** @type {any} */ obj) => obj === null ? obj : undefined,
|
|
26
|
+
Int: /** @returns {undefined|number} */ (/** @type {any} */ obj) => Number.isInteger(obj) ? obj : undefined,
|
|
27
|
+
Float: /** @returns {undefined|number} */ (/** @type {any} */ obj) => typeof obj === 'number' && Number.isFinite(obj) ? obj : undefined,
|
|
28
|
+
String: /** @returns {undefined|string} */ (/** @type {any} */ obj) => typeof obj === 'string' ? obj : undefined,
|
|
29
|
+
Bool: /** @returns {undefined|boolean} */ (/** @type {any} */ obj) => typeof obj === 'boolean' ? obj : undefined,
|
|
30
|
+
Bytes: /** @returns {undefined|Uint8Array} */ (/** @type {any} */ obj) => obj instanceof Uint8Array ? obj : undefined,
|
|
31
|
+
Link: /** @returns {undefined|object} */ (/** @type {any} */ obj) => obj !== null && typeof obj === 'object' && obj.asCID === obj ? obj : undefined,
|
|
32
|
+
List: /** @returns {undefined|Array<any>} */ (/** @type {any} */ obj) => Array.isArray(obj) ? obj : undefined,
|
|
33
|
+
Map: /** @returns {undefined|object} */ (/** @type {any} */ obj) => obj !== null && typeof obj === 'object' && obj.asCID !== obj && !Array.isArray(obj) && !(obj instanceof Uint8Array) ? obj : undefined
|
|
51
34
|
}
|
|
52
|
-
/** @type {{ [k in string]: (obj:any)=>
|
|
35
|
+
/** @type {{ [k in string]: (obj:any)=>undefined|any}} */
|
|
53
36
|
const Types = {
|
|
37
|
+
'CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)': Kinds.Link,
|
|
38
|
+
'CarV1HeaderOrV2Pragma > roots (anon)': /** @returns {undefined|any} */ (/** @type {any} */ obj) => {
|
|
39
|
+
if (Kinds.List(obj) === undefined) {
|
|
40
|
+
return undefined
|
|
41
|
+
}
|
|
42
|
+
for (let i = 0; i < obj.length; i++) {
|
|
43
|
+
let v = obj[i]
|
|
44
|
+
v = Types['CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)'](v)
|
|
45
|
+
if (v === undefined) {
|
|
46
|
+
return undefined
|
|
47
|
+
}
|
|
48
|
+
if (v !== obj[i]) {
|
|
49
|
+
const ret = obj.slice(0, i)
|
|
50
|
+
for (let j = i; j < obj.length; j++) {
|
|
51
|
+
let v = obj[j]
|
|
52
|
+
v = Types['CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)'](v)
|
|
53
|
+
if (v === undefined) {
|
|
54
|
+
return undefined
|
|
55
|
+
}
|
|
56
|
+
ret.push(v)
|
|
57
|
+
}
|
|
58
|
+
return ret
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return obj
|
|
62
|
+
},
|
|
54
63
|
Int: Kinds.Int,
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
64
|
+
CarV1HeaderOrV2Pragma: /** @returns {undefined|any} */ (/** @type {any} */ obj) => {
|
|
65
|
+
if (Kinds.Map(obj) === undefined) {
|
|
66
|
+
return undefined
|
|
67
|
+
}
|
|
68
|
+
const entries = Object.entries(obj)
|
|
69
|
+
/** @type {{[k in string]: any}} */
|
|
70
|
+
let ret = obj
|
|
71
|
+
let requiredCount = 1
|
|
72
|
+
for (let i = 0; i < entries.length; i++) {
|
|
73
|
+
const [key, value] = entries[i]
|
|
74
|
+
switch (key) {
|
|
75
|
+
case 'roots':
|
|
76
|
+
{
|
|
77
|
+
const v = Types['CarV1HeaderOrV2Pragma > roots (anon)'](obj[key])
|
|
78
|
+
if (v === undefined) {
|
|
79
|
+
return undefined
|
|
80
|
+
}
|
|
81
|
+
if (v !== value || ret !== obj) {
|
|
82
|
+
if (ret === obj) {
|
|
83
|
+
/** @type {{[k in string]: any}} */
|
|
84
|
+
ret = {}
|
|
85
|
+
for (let j = 0; j < i; j++) {
|
|
86
|
+
ret[entries[j][0]] = entries[j][1]
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
ret.roots = v
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
break
|
|
93
|
+
case 'version':
|
|
94
|
+
{
|
|
95
|
+
requiredCount--
|
|
96
|
+
const v = Types.Int(obj[key])
|
|
97
|
+
if (v === undefined) {
|
|
98
|
+
return undefined
|
|
99
|
+
}
|
|
100
|
+
if (v !== value || ret !== obj) {
|
|
101
|
+
if (ret === obj) {
|
|
102
|
+
/** @type {{[k in string]: any}} */
|
|
103
|
+
ret = {}
|
|
104
|
+
for (let j = 0; j < i; j++) {
|
|
105
|
+
ret[entries[j][0]] = entries[j][1]
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
ret.version = v
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
break
|
|
112
|
+
default:
|
|
113
|
+
return undefined
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
if (requiredCount > 0) {
|
|
118
|
+
return undefined
|
|
119
|
+
}
|
|
120
|
+
return ret
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
/** @type {{ [k in string]: (obj:any)=>undefined|any}} */
|
|
124
|
+
const Reprs = {
|
|
125
|
+
'CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)': Kinds.Link,
|
|
126
|
+
'CarV1HeaderOrV2Pragma > roots (anon)': /** @returns {undefined|any} */ (/** @type {any} */ obj) => {
|
|
127
|
+
if (Kinds.List(obj) === undefined) {
|
|
128
|
+
return undefined
|
|
129
|
+
}
|
|
130
|
+
for (let i = 0; i < obj.length; i++) {
|
|
131
|
+
let v = obj[i]
|
|
132
|
+
v = Reprs['CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)'](v)
|
|
133
|
+
if (v === undefined) {
|
|
134
|
+
return undefined
|
|
135
|
+
}
|
|
136
|
+
if (v !== obj[i]) {
|
|
137
|
+
const ret = obj.slice(0, i)
|
|
138
|
+
for (let j = i; j < obj.length; j++) {
|
|
139
|
+
let v = obj[j]
|
|
140
|
+
v = Reprs['CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)'](v)
|
|
141
|
+
if (v === undefined) {
|
|
142
|
+
return undefined
|
|
143
|
+
}
|
|
144
|
+
ret.push(v)
|
|
145
|
+
}
|
|
146
|
+
return ret
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
return obj
|
|
150
|
+
},
|
|
151
|
+
Int: Kinds.Int,
|
|
152
|
+
CarV1HeaderOrV2Pragma: /** @returns {undefined|any} */ (/** @type {any} */ obj) => {
|
|
153
|
+
if (Kinds.Map(obj) === undefined) {
|
|
154
|
+
return undefined
|
|
155
|
+
}
|
|
156
|
+
const entries = Object.entries(obj)
|
|
157
|
+
/** @type {{[k in string]: any}} */
|
|
158
|
+
let ret = obj
|
|
159
|
+
let requiredCount = 1
|
|
160
|
+
for (let i = 0; i < entries.length; i++) {
|
|
161
|
+
const [key, value] = entries[i]
|
|
162
|
+
switch (key) {
|
|
163
|
+
case 'roots':
|
|
164
|
+
{
|
|
165
|
+
const v = Reprs['CarV1HeaderOrV2Pragma > roots (anon)'](value)
|
|
166
|
+
if (v === undefined) {
|
|
167
|
+
return undefined
|
|
168
|
+
}
|
|
169
|
+
if (v !== value || ret !== obj) {
|
|
170
|
+
if (ret === obj) {
|
|
171
|
+
/** @type {{[k in string]: any}} */
|
|
172
|
+
ret = {}
|
|
173
|
+
for (let j = 0; j < i; j++) {
|
|
174
|
+
ret[entries[j][0]] = entries[j][1]
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
ret.roots = v
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
break
|
|
181
|
+
case 'version':
|
|
182
|
+
{
|
|
183
|
+
requiredCount--
|
|
184
|
+
const v = Reprs.Int(value)
|
|
185
|
+
if (v === undefined) {
|
|
186
|
+
return undefined
|
|
187
|
+
}
|
|
188
|
+
if (v !== value || ret !== obj) {
|
|
189
|
+
if (ret === obj) {
|
|
190
|
+
/** @type {{[k in string]: any}} */
|
|
191
|
+
ret = {}
|
|
192
|
+
for (let j = 0; j < i; j++) {
|
|
193
|
+
ret[entries[j][0]] = entries[j][1]
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
ret.version = v
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
break
|
|
200
|
+
default:
|
|
201
|
+
return undefined
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
if (requiredCount > 0) {
|
|
205
|
+
return undefined
|
|
206
|
+
}
|
|
207
|
+
return ret
|
|
208
|
+
}
|
|
72
209
|
}
|
|
73
210
|
|
|
74
|
-
export const
|
|
211
|
+
export const CarV1HeaderOrV2Pragma = {
|
|
212
|
+
toTyped: Types.CarV1HeaderOrV2Pragma,
|
|
213
|
+
toRepresentation: Reprs.CarV1HeaderOrV2Pragma
|
|
214
|
+
}
|
package/src/header.ipldsch
CHANGED
|
@@ -1,6 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
# CarV1HeaderOrV2Pragma is a more relaxed form, and can parse {version:x} where
|
|
2
|
+
# roots are optional. This is typically useful for the {verison:2} CARv2
|
|
3
|
+
# pragma.
|
|
4
|
+
|
|
5
|
+
type CarV1HeaderOrV2Pragma struct {
|
|
6
|
+
roots optional [&Any]
|
|
7
|
+
# roots is _not_ optional for CarV1 but we defer that check within code to
|
|
8
|
+
# gracefully handle the V2 case where it's just {version:X}
|
|
9
|
+
version Int
|
|
6
10
|
}
|
|
11
|
+
|
|
12
|
+
# CarV1Header is the strict form of the header, and requires roots to be
|
|
13
|
+
# present. This is compatible with the CARv1 specification.
|
|
14
|
+
|
|
15
|
+
# type CarV1Header struct {
|
|
16
|
+
# roots [&Any]
|
|
17
|
+
# version Int
|
|
18
|
+
# }
|