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