@helia/dag-cbor 6.0.6-5a360554 → 6.0.6-87a42bd5

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 CHANGED
@@ -1,4 +1,4 @@
1
1
  (function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.HeliaDagCbor = factory()}(typeof self !== 'undefined' ? self : this, function () {
2
- "use strict";var HeliaDagCbor=(()=>{var Ke=Object.defineProperty;var Xr=Object.getOwnPropertyDescriptor;var Qr=Object.getOwnPropertyNames;var Yr=Object.prototype.hasOwnProperty;var Zr=(e,t)=>{for(var r in t)Ke(e,r,{get:t[r],enumerable:!0})},en=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Qr(t))!Yr.call(e,o)&&o!==r&&Ke(e,o,{get:()=>t[o],enumerable:!(n=Xr(t,o))||n.enumerable});return e};var tn=e=>en(Ke({},"__esModule",{value:!0}),e);var So={};Zr(So,{dagCbor:()=>_o});var No=new Uint8Array(0);function wt(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}function te(e){if(e instanceof Uint8Array&&e.constructor.name==="Uint8Array")return W(e);if(e instanceof ArrayBuffer)return new Uint8Array(e);if(ArrayBuffer.isView(e))return W(new Uint8Array(e.buffer,e.byteOffset,e.byteLength));throw new Error("Unknown type, must be binary type")}function rn(e){return e?.buffer instanceof ArrayBuffer}function W(e){return rn(e)?e:e.slice()}function nn(e,t,r){if(e.length>=255)throw new TypeError("Alphabet too long");for(var n=new Uint8Array(256),o=0;o<n.length;o++)n[o]=255;for(var i=0;i<e.length;i++){var c=e.charAt(i),d=c.charCodeAt(0);if(n[d]!==255)throw new TypeError(c+" is ambiguous");if(n[d]=i,r){var h=c.toLowerCase().charCodeAt(0),p=c.toUpperCase().charCodeAt(0);h!==d&&(n[h]=i),p!==d&&(n[p]=i)}}var y=e.length,b=e.charAt(0),C=Math.log(y)/Math.log(256),Hr=Math.log(256)/Math.log(y);function Jr(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 E=0,H=0,_=0,N=m.length;_!==N&&m[_]===0;)_++,E++;for(var D=(N-_)*Hr+1>>>0,J=new Uint8Array(D);_!==N;){for(var v=m[_],K=0,R=D-1;(v!==0||K<H)&&R!==-1;R--,K++)v+=256*J[R]>>>0,J[R]=v%y>>>0,v=v/y>>>0;if(v!==0)throw new Error("Non-zero carry");H=K,_++}for(var A=D-H;A!==D&&J[A]===0;)A++;for(var le=b.repeat(E);A<D;++A)le+=e.charAt(J[A]);return le}function xt(m){if(typeof m!="string")throw new TypeError("Expected String");if(m.length===0)return new Uint8Array;var E=0;if(m[E]!==" "){for(var H=0,_=0;m[E]===b;)H++,E++;for(var N=(m.length-E)*C+1>>>0,D=new Uint8Array(N);m[E];){var J=m.charCodeAt(E);if(J>255)return;var v=n[J];if(v===255)return;for(var K=0,R=N-1;(v!==0||K<_)&&R!==-1;R--,K++)v+=y*D[R]>>>0,D[R]=v%256>>>0,v=v/256>>>0;if(v!==0)throw new Error("Non-zero carry");_=K,E++}if(m[E]!==" "){for(var A=N-_;A!==N&&D[A]===0;)A++;for(var le=new Uint8Array(H+(N-A)),Wr=H;A!==N;)le[Wr++]=D[A++];return le}}}function Kr(m){var E=xt(m);if(E)return E;throw new Error(`Non-${t} character`)}return{encode:Jr,decodeUnsafe:xt,decode:Kr}}var on=nn,sn=on,bt=sn;var We=class{name;prefix;baseEncode;constructor(t,r,n){this.name=t,this.prefix=r,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},Xe=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,r,n){this.name=t,this.prefix=r;let o=r.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return Et(this,t)}},Qe=class{decoders;constructor(t){this.decoders=t}or(t){return Et(this,t)}decode(t){let r=t[0],n=this.decoders[r];if(n!=null)return n.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function Et(e,t){return new Qe({...e.decoders??{[e.prefix]:e},...t.decoders??{[t.prefix]:t}})}var Ye=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,r,n,o){this.name=t,this.prefix=r,this.baseEncode=n,this.baseDecode=o,this.encoder=new We(t,r,n),this.decoder=new Xe(t,r,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function vt({name:e,prefix:t,encode:r,decode:n}){return new Ye(e,t,r,n)}function re({name:e,prefix:t,alphabet:r,caseInsensitive:n=!1}){let{encode:o,decode:i}=bt(r,e,n);return vt({prefix:t,name:e,encode:o,decode:c=>te(i(c))})}function cn(e,t,r,n){let o=e.length;for(;e[o-1]==="=";)--o;let i=new Uint8Array(o*r/8|0),c=0,d=0,h=0;for(let p=0;p<o;++p){let y=t[e[p]];if(y===void 0)throw new SyntaxError(`Non-${n} character`);d=d<<r|y,c+=r,c>=8&&(c-=8,i[h++]=255&d>>c)}if(c>=r||(255&d<<8-c)!==0)throw new SyntaxError("Unexpected end of data");return i}function an(e,t,r){let n=t[t.length-1]==="=",o=(1<<r)-1,i="",c=0,d=0;for(let h=0;h<e.length;++h)for(d=d<<8|e[h],c+=8;c>r;)c-=r,i+=t[o&d>>c];if(c!==0&&(i+=t[o&d<<r-c]),n)for(;(i.length*r&7)!==0;)i+="=";return i}function un(e,t){let r={};for(let n=0;n<e.length;++n)if(e[n]!=="="&&(r[e[n]]=n,t)){let o=e[n].toLowerCase(),i=e[n].toUpperCase();o!==e[n]&&(r[o]=n),i!==e[n]&&(r[i]=n)}return r}function M({name:e,prefix:t,bitsPerChar:r,alphabet:n,caseInsensitive:o=!1}){let i=un(n,o);return vt({prefix:t,name:e,encode(c){return an(c,n,r)},decode(c){return cn(c,i,r,e)}})}var he=M({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5,caseInsensitive:!0}),zo=M({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5,caseInsensitive:!0}),Fo=M({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5,caseInsensitive:!0}),jo=M({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5,caseInsensitive:!0}),Vo=M({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5,caseInsensitive:!0}),Po=M({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5,caseInsensitive:!0}),qo=M({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5,caseInsensitive:!0}),Go=M({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5,caseInsensitive:!0}),Ho=M({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Ae=re({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz",caseInsensitive:!0}),Wo=re({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",caseInsensitive:!0});var z=re({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Yo=re({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var fn=Bt,At=128,dn=127,ln=~dn,hn=Math.pow(2,31);function Bt(e,t,r){t=t||[],r=r||0;for(var n=r;e>=hn;)t[r++]=e&255|At,e/=128;for(;e&ln;)t[r++]=e&255|At,e>>>=7;return t[r]=e|0,Bt.bytes=r-n+1,t}var pn=Ze,mn=128,Ut=127;function Ze(e,n){var r=0,n=n||0,o=0,i=n,c,d=e.length;do{if(i>=d)throw Ze.bytes=0,new RangeError("Could not decode varint");c=e[i++],r+=o<28?(c&Ut)<<o:(c&Ut)*Math.pow(2,o),o+=7}while(c>=mn);return Ze.bytes=i-n,r}var yn=Math.pow(2,7),gn=Math.pow(2,14),xn=Math.pow(2,21),wn=Math.pow(2,28),bn=Math.pow(2,35),En=Math.pow(2,42),vn=Math.pow(2,49),An=Math.pow(2,56),Un=Math.pow(2,63),Bn=function(e){return e<yn?1:e<gn?2:e<xn?3:e<wn?4:e<bn?5:e<En?6:e<vn?7:e<An?8:e<Un?9:10},kn={encode:fn,decode:pn,encodingLength:Bn},In=kn,pe=In;function me(e,t=0){let r=pe.decode(e,t),n=pe.decode.bytes;if(n>9)throw new RangeError("Invalid varint: too long");if(n>1&&e[t+n-1]===0)throw new RangeError("Invalid varint: not minimally encoded");return[r,n]}function ne(e,t,r=0){return pe.encode(e,t,r),t}function oe(e){return pe.encodingLength(e)}function Ue(e,t){let r=t.byteLength,n=oe(e),o=n+oe(r),i=new Uint8Array(o+r);return ne(e,i,0),ne(r,i,n),i.set(t,o),new ie(e,r,t,i)}function It(e){let t=te(e),[r,n]=me(t),[o,i]=me(t.subarray(n)),c=t.subarray(n+i);if(c.byteLength!==o)throw new Error("Incorrect length");return new ie(r,o,c,t)}function Tt(e,t){if(e===t)return!0;{let r=t;return e.code===r.code&&e.size===r.size&&r.bytes instanceof Uint8Array&&wt(e.bytes,r.bytes)}}var ie=class{code;size;digest;bytes;constructor(t,r,n,o){this.code=t,this.size=r,this.digest=W(n),this.bytes=W(o)}};function St(e,t){let{bytes:r,version:n}=e;return n===0?_n(r,et(e),t??z.encoder):Sn(r,et(e),t??he.encoder)}var Ct=new WeakMap;function et(e){let t=Ct.get(e);if(t==null){let r=new Map;return Ct.set(e,r),r}return t}var X=class e{code;version;multihash;bytes;"/";constructor(t,r,n,o){this.code=r,this.version=t,this.multihash=n,this.bytes=W(o),this["/"]=this.bytes}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:t,multihash:r}=this;if(t!==ye)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==Cn)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=Ue(t,r);return e.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(t){return e.equals(this,t)}static equals(t,r){let n=r;return n!=null&&t.code===n.code&&t.version===n.version&&Tt(t.multihash,n.multihash)}toString(t){return St(this,t)}toJSON(){return{"/":St(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(t){if(t==null)return null;let r=t;if(r instanceof e)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:o,multihash:i,bytes:c}=r;return new e(n,o,i,c??Nt(n,o,i.bytes))}else if(r[Nn]===!0){let{version:n,multihash:o,code:i}=r,c=It(o);return e.create(n,i,c)}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!==ye)throw new Error(`Version 0 CID must use dag-pb (code: ${ye}) block encoding`);return new e(t,r,n,n.bytes)}case 1:{let o=Nt(t,r,n.bytes);return new e(t,r,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return e.create(0,ye,t)}static createV1(t,r){return e.create(1,t,r)}static decode(t){let[r,n]=e.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return r}static decodeFirst(t){let r=e.inspectBytes(t),n=r.size-r.multihashSize,o=te(t.subarray(n,n+r.multihashSize));if(o.byteLength!==r.multihashSize)throw new Error("Incorrect length");let i=o.subarray(r.multihashSize-r.digestSize),c=new ie(r.multihashCode,r.digestSize,i,o);return[r.version===0?e.createV0(c):e.createV1(r.codec,c),t.subarray(r.size)]}static inspectBytes(t){let r=0,n=()=>{let[b,C]=me(t.subarray(r));return r+=C,b},o=n(),i=ye;if(o===18)o=0,r=0;else if(o===1)i=n();else throw o===0?new RangeError("Invalid CID version, v0 is always implicit"):new RangeError(`Invalid CID version ${o}`);let c=r,d=n(),h=n(),p=r+h,y=p-c;return{version:o,codec:i,multihashCode:d,digestSize:h,multihashSize:y,size:p}}static parse(t,r){let[n,o]=Tn(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 et(i).set(n,t),i}};function Tn(e,t){switch(e[0]){case"Q":{let r=t??z;return[z.prefix,r.decode(`${z.prefix}${e}`)]}case z.prefix:{let r=t??z;return[z.prefix,r.decode(e)]}case he.prefix:{let r=t??he;return[he.prefix,r.decode(e)]}case Ae.prefix:{let r=t??Ae;return[Ae.prefix,r.decode(e)]}default:{if(t==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[e[0],t.decode(e)]}}}function _n(e,t,r){let{prefix:n}=r;if(n!==z.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let o=t.get(n);if(o==null){let i=r.encode(e).slice(1);return t.set(n,i),i}else return o}function Sn(e,t,r){let{prefix:n}=r,o=t.get(n);if(o==null){let i=r.encode(e);return t.set(n,i),i}else return o}var ye=112,Cn=18;function Nt(e,t,r){let n=oe(e),o=n+oe(t),i=new Uint8Array(o+r.byteLength);return ne(e,i,0),ne(t,i,n),i.set(r,o),i}var Nn=Symbol.for("@ipld/js-cid/CID");var Dn=20;function rt({name:e,code:t,encode:r,minDigestLength:n,maxDigestLength:o}){return new tt(e,t,r,n,o)}var tt=class{name;code;encode;minDigestLength;maxDigestLength;constructor(t,r,n,o,i){this.name=t,this.code=r,this.encode=n,this.minDigestLength=o??Dn,this.maxDigestLength=i}digest(t,r){if(r?.truncate!=null){if(r.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&r.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(t instanceof Uint8Array){let n=this.encode(t);return n instanceof Uint8Array?Dt(n,this.code,r?.truncate):n.then(o=>Dt(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function Dt(e,t,r){if(r!=null&&r!==e.byteLength){if(r>e.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${e.byteLength}`);e=e.subarray(0,r)}return Ue(t,e)}function Mt(e=0){return new Uint8Array(e)}function Mn(e){return e?.buffer instanceof ArrayBuffer}function $t(e){if(Mn(e))return e;let t=e.slice();return new Uint8Array(t.buffer,0,t.byteLength)}function nt(e,t){t==null&&(t=e.reduce((o,i)=>o+i.length,0));let r=Mt(t),n=0;for(let o of e)r.set(o,n),n+=o.length;return $t(r)}function Ot(e){return async t=>new Uint8Array(await crypto.subtle.digest(e,t))}var Lt=rt({name:"sha2-256",code:18,encode:Ot("SHA-256")}),yi=rt({name:"sha2-512",code:19,encode:Ot("SHA-512")});var Be=class extends Error{static name="InvalidCodecError";constructor(t="Invalid codec"){super(t),this.name="InvalidCodecError"}};var $n=["Object","Uint8Array","RegExp","Date","Error","Map","Set","WeakMap","WeakSet","ArrayBuffer","SharedArrayBuffer","DataView","Promise","URL","HTMLElement","Int8Array","Uint8ClampedArray","Int16Array","Uint16Array","Int32Array","Uint32Array","Float32Array","Float64Array","BigInt64Array","BigUint64Array","Tagged"];function ot(e){if(e===null)return"null";if(e===void 0)return"undefined";if(e===!0||e===!1)return"boolean";let t=typeof e;if(t==="string"||t==="number"||t==="bigint"||t==="symbol")return t;if(t==="function")return"Function";if(Array.isArray(e))return"Array";if(e instanceof Uint8Array)return"Uint8Array";if(e.constructor===Object)return"Object";let r=On(e);return r||"Object"}function On(e){let t=Object.prototype.toString.call(e).slice(8,-1);if($n.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}static equals(t,r){return t===r||t.major===r.major&&t.name===r.name}};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 ge=globalThis.process&&!globalThis.process.browser&&globalThis.Buffer&&typeof globalThis.Buffer.isBuffer=="function",Ln=new TextEncoder;function ke(e){return ge&&globalThis.Buffer.isBuffer(e)}function xe(e){return e instanceof Uint8Array?ke(e)?new Uint8Array(e.buffer,e.byteOffset,e.byteLength):e:Uint8Array.from(e)}var Rn=24,zn=200,Ie=ge?e=>e.length>=Rn?globalThis.Buffer.from(e):Rt(e):e=>e.length>=zn?Ln.encode(e):Rt(e),$=e=>Uint8Array.from(e),zt=ge?(e,t,r)=>ke(e)?new Uint8Array(e.subarray(t,r)):e.slice(t,r):(e,t,r)=>e.slice(t,r),Ft=ge?(e,t)=>(e=e.map(r=>r instanceof Uint8Array?r:globalThis.Buffer.from(r)),xe(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},it=ge?e=>globalThis.Buffer.allocUnsafe(e):e=>new Uint8Array(e);function se(e,t){if(ke(e)&&ke(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 Rt(e){let t=[],r=0;for(let n=0;n<e.length;n++){let o=e.charCodeAt(n);o<128?t[r++]=o:o<2048?(t[r++]=o>>6|192,t[r++]=o&63|128):(o&64512)===55296&&n+1<e.length&&(e.charCodeAt(n+1)&64512)===56320?(o=65536+((o&1023)<<10)+(e.charCodeAt(++n)&1023),t[r++]=o>>18|240,t[r++]=o>>12&63|128,t[r++]=o>>6&63|128,t[r++]=o&63|128):(o>=55296&&o<=57343&&(o=65533),t[r++]=o>>12|224,t[r++]=o>>6&63|128,t[r++]=o&63|128)}return t}var Fn=256,Q=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)}pushByte(t){let r=this.chunks[this.chunks.length-1];this.cursor>this.maxCursor&&(r=it(this.chunkSize),this.chunks.push(r),this.maxCursor+=r.length,this._initReuseChunk===null&&(this._initReuseChunk=r));let n=r.length-(this.maxCursor-this.cursor)-1;r[n]=t,this.cursor++}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=it(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=zt(n,0,this.cursor)}else r=Ft(this.chunks,this.cursor);return t&&this.reset(),r}},Te=class{constructor(t){this.dest=t,this.cursor=0,this.chunks=[t]}reset(){this.cursor=0}pushByte(t){if(this.cursor>=this.dest.length)throw new Error("write out of bounds, destination buffer is too small");this.dest[this.cursor++]=t}push(t){if(this.cursor+t.length>this.dest.length)throw new Error("write out of bounds, destination buffer is too small");this.dest.set(t,this.cursor),this.cursor+=t.length}toBytes(t=!1){let r=this.dest.subarray(0,this.cursor);return t&&this.reset(),r}};var f="CBOR decode error:",_e="CBOR encode error:",we=[];we[23]=1;we[24]=2;we[25]=3;we[26]=5;we[27]=9;function F(e,t,r){if(e.length-t<r)throw new Error(`${f} not enough data for type`)}var w=[24,256,65536,4294967296,BigInt("18446744073709551616")];function U(e,t,r){F(e,t,1);let n=e[t];if(r.strict===!0&&n<w[0])throw new Error(`${f} integer encoded in more bytes than necessary (strict decode)`);return n}function B(e,t,r){F(e,t,2);let n=e[t]<<8|e[t+1];if(r.strict===!0&&n<w[1])throw new Error(`${f} integer encoded in more bytes than necessary (strict decode)`);return n}function k(e,t,r){F(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(`${f} integer encoded in more bytes than necessary (strict decode)`);return n}function I(e,t,r){F(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(`${f} 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(`${f} integers outside of the safe integer range are not supported`)}function jt(e,t,r,n){return new u(s.uint,U(e,t+1,n),2)}function Vt(e,t,r,n){return new u(s.uint,B(e,t+1,n),3)}function Pt(e,t,r,n){return new u(s.uint,k(e,t+1,n),5)}function qt(e,t,r,n){return new u(s.uint,I(e,t+1,n),9)}function O(e,t){return g(e,0,t.value)}function g(e,t,r){if(r<w[0]){let n=Number(r);e.pushByte(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)),c=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]=c&255,c=c>>8,o[3]=c&255,c=c>>8,o[2]=c&255,c=c>>8,o[1]=c&255,e.push(o)}else throw new Error(`${f} encountered BigInt larger than allowable range`)}}O.encodedSize=function(t){return g.encodedSize(t.value)};g.encodedSize=function(t){return t<w[0]?1:t<w[1]?2:t<w[2]?3:t<w[3]?5:9};O.compareTokens=function(t,r){return t.value<r.value?-1:t.value>r.value?1:0};function Gt(e,t,r,n){return new u(s.negint,-1-U(e,t+1,n),2)}function Ht(e,t,r,n){return new u(s.negint,-1-B(e,t+1,n),3)}function Jt(e,t,r,n){return new u(s.negint,-1-k(e,t+1,n),5)}var st=BigInt(-1),Kt=BigInt(1);function Wt(e,t,r,n){let o=I(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(`${f} integers outside of the safe integer range are not supported`);return new u(s.negint,st-BigInt(o),9)}function Se(e,t){let r=t.value,n=typeof r=="bigint"?r*st-Kt:r*-1-1;g(e,t.type.majorEncoded,n)}Se.encodedSize=function(t){let r=t.value,n=typeof r=="bigint"?r*st-Kt:r*-1-1;return n<w[0]?1:n<w[1]?2:n<w[2]?3:n<w[3]?5:9};Se.compareTokens=function(t,r){return t.value<r.value?1:t.value>r.value?-1:0};function be(e,t,r,n){F(e,t,r+n);let o=e.slice(t+r,t+r+n);return new u(s.bytes,o,r+n)}function Xt(e,t,r,n){return be(e,t,1,r)}function Qt(e,t,r,n){return be(e,t,2,U(e,t+1,n))}function Yt(e,t,r,n){return be(e,t,3,B(e,t+1,n))}function Zt(e,t,r,n){return be(e,t,5,k(e,t+1,n))}function er(e,t,r,n){let o=I(e,t+1,n);if(typeof o=="bigint")throw new Error(`${f} 64-bit integer bytes lengths not supported`);return be(e,t,9,o)}function Ce(e){return e.encodedBytes===void 0&&(e.encodedBytes=s.equals(e.type,s.string)?Ie(e.value):e.value),e.encodedBytes}function ce(e,t){let r=Ce(t);g(e,t.type.majorEncoded,r.length),e.push(r)}ce.encodedSize=function(t){let r=Ce(t);return g.encodedSize(r.length)+r.length};ce.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:se(e,t)}var tr=new TextDecoder("utf-8",{ignoreBOM:!0}),qn=new TextDecoder("utf-8",{ignoreBOM:!0,fatal:!0}),Gn=32;function Hn(e,t,r,n){if(r-t<Gn){let i="";for(let c=t;c<r;c++){let d=e[c];if(d&128)return n.strictUtf8===!0?rr(e,t,r):tr.decode(e.subarray(t,r));i+=String.fromCharCode(d)}return i}return n.strictUtf8===!0?rr(e,t,r):tr.decode(e.subarray(t,r))}function rr(e,t,r){try{return qn.decode(e.subarray(t,r))}catch{throw new Error(`${f} invalid UTF-8 in text string`)}}function Ee(e,t,r,n,o){let i=r+n;F(e,t,i);let c=new u(s.string,Hn(e,t+r,t+i,o),i);return o.retainStringBytes===!0&&(c.byteValue=e.slice(t+r,t+i)),c}function nr(e,t,r,n){return Ee(e,t,1,r,n)}function or(e,t,r,n){return Ee(e,t,2,U(e,t+1,n),n)}function ir(e,t,r,n){return Ee(e,t,3,B(e,t+1,n),n)}function sr(e,t,r,n){return Ee(e,t,5,k(e,t+1,n),n)}function cr(e,t,r,n){let o=I(e,t+1,n);if(typeof o=="bigint")throw new Error(`${f} 64-bit integer string lengths not supported`);return Ee(e,t,9,o,n)}var ar=ce;function ae(e,t,r,n){return new u(s.array,n,r)}function ur(e,t,r,n){return ae(e,t,1,r)}function fr(e,t,r,n){return ae(e,t,2,U(e,t+1,n))}function dr(e,t,r,n){return ae(e,t,3,B(e,t+1,n))}function lr(e,t,r,n){return ae(e,t,5,k(e,t+1,n))}function hr(e,t,r,n){let o=I(e,t+1,n);if(typeof o=="bigint")throw new Error(`${f} 64-bit integer array lengths not supported`);return ae(e,t,9,o)}function pr(e,t,r,n){if(n.allowIndefinite===!1)throw new Error(`${f} indefinite length items not allowed`);return ae(e,t,1,1/0)}function Ne(e,t){g(e,s.array.majorEncoded,t.value)}Ne.compareTokens=O.compareTokens;Ne.encodedSize=function(t){return g.encodedSize(t.value)};function ue(e,t,r,n){return new u(s.map,n,r)}function mr(e,t,r,n){return ue(e,t,1,r)}function yr(e,t,r,n){return ue(e,t,2,U(e,t+1,n))}function gr(e,t,r,n){return ue(e,t,3,B(e,t+1,n))}function xr(e,t,r,n){return ue(e,t,5,k(e,t+1,n))}function wr(e,t,r,n){let o=I(e,t+1,n);if(typeof o=="bigint")throw new Error(`${f} 64-bit integer map lengths not supported`);return ue(e,t,9,o)}function br(e,t,r,n){if(n.allowIndefinite===!1)throw new Error(`${f} indefinite length items not allowed`);return ue(e,t,1,1/0)}function De(e,t){g(e,s.map.majorEncoded,t.value)}De.compareTokens=O.compareTokens;De.encodedSize=function(t){return g.encodedSize(t.value)};function Er(e,t,r,n){return new u(s.tag,r,1)}function vr(e,t,r,n){return new u(s.tag,U(e,t+1,n),2)}function Ar(e,t,r,n){return new u(s.tag,B(e,t+1,n),3)}function Ur(e,t,r,n){return new u(s.tag,k(e,t+1,n),5)}function Br(e,t,r,n){return new u(s.tag,I(e,t+1,n),9)}function Me(e,t){g(e,s.tag.majorEncoded,t.value)}Me.compareTokens=O.compareTokens;Me.encodedSize=function(t){return g.encodedSize(t.value)};var $e=20,Oe=21,Le=22,Re=23;function Ir(e,t,r,n){if(n.allowUndefined===!1)throw new Error(`${f} undefined values are not supported`);return n.coerceUndefinedToNull===!0?new u(s.null,null,1):new u(s.undefined,void 0,1)}function Tr(e,t,r,n){if(n.allowIndefinite===!1)throw new Error(`${f} indefinite length items not allowed`);return new u(s.break,void 0,1)}function ct(e,t,r){if(r){if(r.allowNaN===!1&&Number.isNaN(e))throw new Error(`${f} NaN values are not supported`);if(r.allowInfinity===!1&&(e===1/0||e===-1/0))throw new Error(`${f} Infinity values are not supported`)}return new u(s.float,e,t)}function _r(e,t,r,n){return ct(ze(e,t+1),3,n)}function Sr(e,t,r,n){return ct(Fe(e,t+1),5,n)}function Cr(e,t,r,n){return ct(Mr(e,t+1),9,n)}function ve(e,t,r){let n=t.value;if(n===!1)e.pushByte(s.float.majorEncoded|$e);else if(n===!0)e.pushByte(s.float.majorEncoded|Oe);else if(n===null)e.pushByte(s.float.majorEncoded|Le);else if(n===void 0)e.pushByte(s.float.majorEncoded|Re);else{let o,i=!1;(!r||r.float64!==!0)&&(at(n),o=ze(x,1),n===o||Number.isNaN(n)?(x[0]=249,e.push(x.slice(0,3)),i=!0):(ut(n),o=Fe(x,1),n===o&&(x[0]=250,e.push(x.slice(0,5)),i=!0))),i||(Dr(n),o=Mr(x,1),x[0]=251,e.push(x.slice(0,9)))}}ve.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){at(n);let o=ze(x,1);if(n===o||Number.isNaN(n))return 3;if(ut(n),o=Fe(x,1),n===o)return 5}return 9};var Nr=new ArrayBuffer(9),T=new DataView(Nr,1),x=new Uint8Array(Nr,0);function at(e){if(e===1/0)T.setUint16(0,31744,!1);else if(e===-1/0)T.setUint16(0,64512,!1);else if(Number.isNaN(e))T.setUint16(0,32256,!1);else{T.setFloat32(0,e);let t=T.getUint32(0),r=(t&2139095040)>>23,n=t&8388607;if(r===255)T.setUint16(0,31744,!1);else if(r===0)T.setUint16(0,(t&2147483648)>>16|n>>13,!1);else{let o=r-127;o<-24?T.setUint16(0,0):o<-14?T.setUint16(0,(t&2147483648)>>16|1<<24+o,!1):T.setUint16(0,(t&2147483648)>>16|o+15<<10|n>>13,!1)}}}function ze(e,t){if(e.length-t<2)throw new Error(`${f} 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 ut(e){T.setFloat32(0,e,!1)}function Fe(e,t){if(e.length-t<4)throw new Error(`${f} not enough data for float32`);let r=(e.byteOffset||0)+t;return new DataView(e.buffer,r,4).getFloat32(0,!1)}function Dr(e){T.setFloat64(0,e,!1)}function Mr(e,t){if(e.length-t<8)throw new Error(`${f} not enough data for float64`);let r=(e.byteOffset||0)+t;return new DataView(e.buffer,r,8).getFloat64(0,!1)}function Qn(e,t){let r=e.value;if(r===!1)return Uint8Array.of(s.float.majorEncoded|$e);if(r===!0)return Uint8Array.of(s.float.majorEncoded|Oe);if(r===null)return Uint8Array.of(s.float.majorEncoded|Le);if(r===void 0)return Uint8Array.of(s.float.majorEncoded|Re);if(!t){if(at(r),r===ze(x,1)||Number.isNaN(r))return x[0]=249,x.slice(0,3);if(ut(r),r===Fe(x,1))return x[0]=250,x.slice(0,5)}return Dr(r),x[0]=251,x.slice(0,9)}function kr(e,t){let r=e,n=t?.float64===!0,o=n?r._keyBytesFloat64:r._keyBytes;if(o!==void 0)return o;let i=Qn(e,n);return n?r._keyBytesFloat64=i:r._keyBytes=i,i}ve.compareTokens=function(t,r,n){let o=kr(t,n),i=kr(r,n);return o.length!==i.length?o.length<i.length?-1:1:se(o,i)};function l(e,t,r){throw new Error(`${f} encountered invalid minor (${r}) for major ${e[t]>>>5}`)}function je(e){return()=>{throw new Error(`${f} ${e}`)}}var a=[];for(let e=0;e<=23;e++)a[e]=l;a[24]=jt;a[25]=Vt;a[26]=Pt;a[27]=qt;a[28]=l;a[29]=l;a[30]=l;a[31]=l;for(let e=32;e<=55;e++)a[e]=l;a[56]=Gt;a[57]=Ht;a[58]=Jt;a[59]=Wt;a[60]=l;a[61]=l;a[62]=l;a[63]=l;for(let e=64;e<=87;e++)a[e]=Xt;a[88]=Qt;a[89]=Yt;a[90]=Zt;a[91]=er;a[92]=l;a[93]=l;a[94]=l;a[95]=je("indefinite length bytes/strings are not supported");for(let e=96;e<=119;e++)a[e]=nr;a[120]=or;a[121]=ir;a[122]=sr;a[123]=cr;a[124]=l;a[125]=l;a[126]=l;a[127]=je("indefinite length bytes/strings are not supported");for(let e=128;e<=151;e++)a[e]=ur;a[152]=fr;a[153]=dr;a[154]=lr;a[155]=hr;a[156]=l;a[157]=l;a[158]=l;a[159]=pr;for(let e=160;e<=183;e++)a[e]=mr;a[184]=yr;a[185]=gr;a[186]=xr;a[187]=wr;a[188]=l;a[189]=l;a[190]=l;a[191]=br;for(let e=192;e<=215;e++)a[e]=Er;a[216]=vr;a[217]=Ar;a[218]=Ur;a[219]=Br;a[220]=l;a[221]=l;a[222]=l;a[223]=l;for(let e=224;e<=243;e++)a[e]=je("simple values are not supported");a[244]=l;a[245]=l;a[246]=l;a[247]=Ir;a[248]=je("simple values are not supported");a[249]=_r;a[250]=Sr;a[251]=Cr;a[252]=l;a[253]=l;a[254]=l;a[255]=Tr;var S=[];for(let e=0;e<24;e++)S[e]=new u(s.uint,e,1);for(let e=-1;e>=-24;e--)S[31-e]=new u(s.negint,e,1);S[64]=new u(s.bytes,new Uint8Array(0),1);S[96]=new u(s.string,"",1);S[128]=new u(s.array,0,1);S[160]=new u(s.map,0,1);S[244]=new u(s.false,!1,1);S[245]=new u(s.true,!0,1);S[246]=new u(s.null,null,1);function ft(e){switch(e.type){case s.false:return $([244]);case s.true:return $([245]);case s.null:return $([246]);case s.bytes:return e.value.length?void 0:$([64]);case s.string:return e.value===""?$([96]):void 0;case s.array:return e.value===0?$([128]):void 0;case s.map:return e.value===0?$([160]):void 0;case s.uint:return e.value<24?$([Number(e.value)]):void 0;case s.negint:if(e.value>=-24)return $([31-Number(e.value)])}}var Zn={float64:!1,mapSorter:lt,quickEncodeToken:ft},zr=Object.freeze({mapSorter:ro,quickEncodeToken:ft});function eo(){let e=[];return e[s.uint.major]=O,e[s.negint.major]=Se,e[s.bytes.major]=ce,e[s.string.major]=ar,e[s.array.major]=Ne,e[s.map.major]=De,e[s.tag.major]=Me,e[s.float.major]=ve,e}var ee=eo(),Ve=new Q,Pe=!1,de=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(`${_e} object contains circular references`);return new e(r,t)}},j={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)},L={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?j.true:j.false},null(e,t,r,n){return j.null},undefined(e,t,r,n){return j.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?[j.emptyArray,new u(s.break)]:j.emptyArray;n=de.createCheck(n,e);let o=[],i=0;for(let c of e)o[i++]=Z(c,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),c=o?e.size:i.length,d;if(c){d=new Array(c),n=de.createCheck(n,e);let h=!o&&r.ignoreUndefinedProperties,p=0;for(let y of i){let b=o?e.get(y):e[y];h&&b===void 0||(d[p++]=[Z(y,r,n),Z(b,r,n)])}p<c&&(d.length=p)}return d?.length?(to(d,r),r.addBreakTokens?[new u(s.map,d.length),d,new u(s.break)]:[new u(s.map,d.length),d]):r.addBreakTokens===!0?[j.emptyMap,new u(s.break)]:j.emptyMap},Tagged(e,t,r,n){return[new u(s.tag,e.tag),Z(e.value,r,n)]}};L.Map=L.Object;L.Buffer=L.Uint8Array;for(let e of"Uint8Clamped Uint16 Uint32 Int8 Int16 Int32 BigUint64 BigInt64 Float32 Float64".split(" "))L[`${e}Array`]=L.DataView;function Z(e,t={},r){let n=ot(e),o=t&&t.typeEncoders&&t.typeEncoders[n]||L[n];if(typeof o=="function"){let c=o(e,n,t,r);if(c!=null)return c}let i=L[n];if(!i)throw new Error(`${_e} unsupported type: ${n}`);return i(e,n,t,r)}function to(e,t){let r=t.mapSorter;r&&e.sort((n,o)=>r(n,o,t))}function lt(e,t,r){let n=Array.isArray(e[0])?e[0][0]:e[0],o=Array.isArray(t[0])?t[0][0]:t[0];if(n.type.major!==o.type.major)return n.type.compare(o.type);let i=n.type.major,c=ee[i].compareTokens(n,o,r);return c===0&&console.warn("WARNING: complex key types used, CBOR key sorting guarantees are gone"),c}function ro(e,t){if(e[0]instanceof u&&t[0]instanceof u){let r=e[0],n=t[0];return r._keyBytes||(r._keyBytes=$r(r.value)),n._keyBytes||(n._keyBytes=$r(n.value)),se(r._keyBytes,n._keyBytes)}throw new Error("rfc8949MapSorter: complex key types are not supported yet")}function $r(e){return Fr(e,ee,zr)}function fe(e,t,r,n){if(Array.isArray(t))for(let o of t)fe(e,o,r,n);else r[t.type.major](e,t,n)}var Or=s.uint.majorEncoded,Lr=s.negint.majorEncoded,no=s.bytes.majorEncoded,oo=s.string.majorEncoded,Rr=s.array.majorEncoded,dt=s.map.majorEncoded,io=s.float.majorEncoded|$e,so=s.float.majorEncoded|Oe,co=s.float.majorEncoded|Le,ao=s.float.majorEncoded|Re,uo=BigInt(-1),fo=BigInt(1);function V(e,t,r){r<24?e.pushByte(t|Number(r)):g(e,t,r)}function lo(e){return e.addBreakTokens!==!0}function ho(e,t,r,n,o){let i=r==="Map",c=i?t.keys():Object.keys(t),d=i?t.size:c.length;if(!d){e.pushByte(dt);return}o=de.createCheck(o,t);let h=!i&&n.ignoreUndefinedProperties,p=new Array(d),y=0;for(let b of c){let C=i?t.get(b):t[b];h&&C===void 0||(p[y++]=[Z(b,n,o),C])}if(y===0){e.pushByte(dt);return}y<d&&(p.length=y),p.sort((b,C)=>lt(b,C,n)),V(e,dt,y);for(let[b,C]of p)fe(e,b,ee,n),qe(e,C,n,o)}function qe(e,t,r,n){let o=ot(t),i=r.typeEncoders&&r.typeEncoders[o];if(i){let c=i(t,o,r,n);if(c!=null){fe(e,c,ee,r);return}}switch(o){case"null":e.pushByte(co);return;case"undefined":e.pushByte(ao);return;case"boolean":e.pushByte(t?so:io);return;case"number":!Number.isInteger(t)||!Number.isSafeInteger(t)?ve(e,new u(s.float,t),r):t>=0?V(e,Or,t):V(e,Lr,t*-1-1);return;case"bigint":t>=BigInt(0)?V(e,Or,t):V(e,Lr,t*uo-fo);return;case"string":{let c=Ie(t);V(e,oo,c.length),e.push(c);return}case"Uint8Array":V(e,no,t.length),e.push(t);return;case"Array":if(!t.length){e.pushByte(Rr);return}n=de.createCheck(n,t),V(e,Rr,t.length);for(let c of t)qe(e,c,r,n);return;case"Object":case"Map":if(r.mapSorter===lt)ho(e,t,o,r,n);else{let c=L.Object(t,o,r,n);fe(e,c,ee,r)}return;default:{let c=L[o];if(!c)throw new Error(`${_e} unsupported type: ${o}`);let d=c(t,o,r,n);fe(e,d,ee,r)}}}function Fr(e,t,r,n){let o=n instanceof Uint8Array,i=o?new Te(n):Pe?new Q:Ve,c=Z(e,r);if(!Array.isArray(c)&&r.quickEncodeToken){let d=r.quickEncodeToken(c);if(d)return o?(i.push(d),i.toBytes()):d;let h=t[c.type.major];if(h.encodedSize){let p=h.encodedSize(c,r);if(o||(i=new Q(p)),h(i,c,r),i.chunks.length!==1)throw new Error(`Unexpected error: pre-calculated length for ${c} was wrong`);return o?i.toBytes():xe(i.chunks[0])}}return i.reset(),fe(i,c,t,r),i.toBytes(!0)}function ht(e,t){if(t=Object.assign({},Zn,t),lo(t)){if(Pe){let r=new Q;return qe(r,e,t,void 0),r.toBytes()}Pe=!0;try{return Ve.reset(),qe(Ve,e,t,void 0),Ve.toBytes(!0)}finally{Pe=!1}}return Fr(e,ee,t)}var po={strict:!1,allowIndefinite:!0,allowUndefined:!0,allowBigInt:!0},Ge=class{constructor(t,r={}){this._pos=0,this.data=t,this.options=r}pos(){return this._pos}done(){return this._pos>=this.data.length}next(){let t=this.data[this._pos],r=S[t];if(r===void 0){let n=a[t];if(!n)throw t===void 0?new Error(`${f} not enough data`):new Error(`${f} 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}},P=Symbol.for("DONE"),q=Symbol.for("BREAK");function mo(e,t,r){let n=[];for(let o=0;o<e.value;o++){let i=G(t,r);if(i===q){if(e.value===1/0)break;throw new Error(`${f} got unexpected break to lengthed array`)}if(i===P)throw new Error(`${f} found array but not enough entries (got ${o}, expected ${e.value})`);n[o]=i}return n}function yo(e,t,r){let n=r.useMaps===!0,o=r.rejectDuplicateMapKeys===!0,i=n?void 0:{},c=n?new Map:void 0;for(let d=0;d<e.value;d++){let h=G(t,r);if(h===q){if(e.value===1/0)break;throw new Error(`${f} got unexpected break to lengthed map`)}if(h===P)throw new Error(`${f} found map but not enough entries (got ${d} [no key], expected ${e.value})`);if(!n&&typeof h!="string")throw new Error(`${f} non-string keys not supported (got ${typeof h})`);if(o&&(n&&c.has(h)||!n&&Object.hasOwn(i,h)))throw new Error(`${f} found repeat map key "${h}"`);let p=G(t,r);if(p===P)throw new Error(`${f} found map but not enough entries (got ${d} [no value], expected ${e.value})`);if(p===q)throw new Error(`${f} got unexpected break to map value`);n?c.set(h,p):h==="__proto__"?Object.defineProperty(i,h,{value:p,configurable:!0,enumerable:!0,writable:!0}):i[h]=p}return n?c:i}function*go(e,t,r){for(let n=0;n<e.value;n++){let o=G(t,r);if(o===q){if(e.value===1/0)break;throw new Error(`${f} got unexpected break to lengthed map`)}if(o===P)throw new Error(`${f} found map but not enough entries (got ${n} [no key], expected ${e.value})`);let i=G(t,r);if(i===P)throw new Error(`${f} found map but not enough entries (got ${n} [no value], expected ${e.value})`);if(i===q)throw new Error(`${f} got unexpected break to map value`);yield[o,i]}}function xo(e,t){let r=function(){if(r._called)throw new Error(`${f} tag decode() may only be called once`);r._called=!0;let n=G(e,t);if(n===P)throw new Error(`${f} tag content missing`);if(n===q)throw new Error(`${f} got unexpected break in tag content`);return n};return r.entries=function(){if(r._called)throw new Error(`${f} tag decode() may only be called once`);if(r._called=!0,e.done())throw new Error(`${f} tag content missing`);let n=e.next();if(!s.equals(n.type,s.map))throw new Error(`${f} entries() requires map content, got ${n.type.name}`);let o=[];for(let i of go(n,e,t))o.push(i);return o},r._called=!1,r}function G(e,t){if(e.done())return P;let r=e.next();if(s.equals(r.type,s.break))return q;if(r.type.terminal)return r.value;if(s.equals(r.type,s.array))return mo(r,e,t);if(s.equals(r.type,s.map))return yo(r,e,t);if(s.equals(r.type,s.tag)){if(t.tags&&typeof t.tags[r.value]=="function"){let n=xo(e,t),o=t.tags[r.value](n);if(!n._called)throw new Error(`${f} tag decoder must call decode() or entries()`);return o}throw new Error(`${f} tag not supported (${r.value})`)}throw new Error("unsupported")}function jr(e,t){if(!(e instanceof Uint8Array))throw new Error(`${f} data to decode must be a Uint8Array`);t=Object.assign({},po,t);let r=xe(e),n=t.tokenizer||new Ge(r,t),o=G(n,t);if(o===P)throw new Error(`${f} did not find any content to decode`);if(o===q)throw new Error(`${f} got unexpected break`);return[o,e.subarray(n.pos())]}function pt(e,t){let[r,n]=jr(e,t);if(n.length>0)throw new Error(`${f} too many terminals, data makes no sense`);return r}var He=class e{constructor(t,r){if(typeof t!="number"||!Number.isInteger(t)||t<0)throw new TypeError("Tagged: tag must be a non-negative integer");this.tag=t,this.value=r}static decoder(t){return r=>new e(t,r())}static preserve(...t){let r={};for(let n of t)r[n]=e.decoder(n);return r}};Object.defineProperty(He.prototype,Symbol.toStringTag,{value:"Tagged"});var Vr=42;function bo(e){return e instanceof ArrayBuffer?new Uint8Array(e,0,e.byteLength):e}function Eo(e){if(e.asCID!==e&&e["/"]!==e.bytes)return null;let t=X.asCID(e);if(!t)return null;let r=new Uint8Array(t.bytes.byteLength+1);return r.set(t.bytes,1),[new u(s.tag,Vr),new u(s.bytes,r)]}function vo(){throw new Error("`undefined` is not supported by the IPLD Data Model and cannot be encoded")}function Ao(e){if(Number.isNaN(e))throw new Error("`NaN` is not supported by the IPLD Data Model and cannot be encoded");if(e===1/0||e===-1/0)throw new Error("`Infinity` and `-Infinity` is not supported by the IPLD Data Model and cannot be encoded");return null}function Uo(e){for(let t of e.keys())if(typeof t!="string"||t.length===0)throw new Error("Non-string Map keys are not supported by the IPLD Data Model and cannot be encoded");return null}var mt={float64:!0,typeEncoders:{Map:Uo,Object:Eo,undefined:vo,number:Ao}},bs={...mt,typeEncoders:{...mt.typeEncoders}};function Bo(e){let t=e();if(t[0]!==0)throw new Error("Invalid CID for CBOR tag 42; expected leading 0x00");return X.decode(t.subarray(1))}var yt={allowIndefinite:!1,coerceUndefinedToNull:!0,allowNaN:!1,allowInfinity:!1,allowBigInt:!0,strict:!0,useMaps:!1,rejectDuplicateMapKeys:!0,tags:{[Vr]:Bo}},Es={...yt,tags:{...yt.tags}};var gt=113,Pr=e=>ht(e,mt),qr=e=>pt(bo(e),yt);function Io(e){return e[Symbol.asyncIterator]!=null}function To(e){if(Io(e))return(async()=>{let n=new Uint8Array(0);for await(let o of e)n=nt([n,o],n.length+o.length);return n})();let t=[],r=0;for(let n of e)t.push(n),r+=n.byteLength;return nt(t,r)}var Gr=To;var Je=class{components;constructor(t){this.components=t}async add(t,r={}){let n=Pr(t),o=await(r.hasher??Lt).digest(n),i=X.createV1(gt,o);return await this.components.blockstore.put(i,n,r),i}async get(t,r={}){if(t.code!==gt)throw new Be("The passed CID had an incorrect codec, it may correspond to a non-DAG-CBOR block");let n=await Gr(this.components.blockstore.get(t,r));return qr(n)}};function _o(e){return new Je(e)}return tn(So);})();
2
+ "use strict";var HeliaDagCbor=(()=>{var Ke=Object.defineProperty;var Yr=Object.getOwnPropertyDescriptor;var Zr=Object.getOwnPropertyNames;var en=Object.prototype.hasOwnProperty;var tn=(e,t)=>{for(var r in t)Ke(e,r,{get:t[r],enumerable:!0})},rn=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Zr(t))!en.call(e,o)&&o!==r&&Ke(e,o,{get:()=>t[o],enumerable:!(n=Yr(t,o))||n.enumerable});return e};var nn=e=>rn(Ke({},"__esModule",{value:!0}),e);var Mo={};tn(Mo,{dagCbor:()=>$o});var Oo=new Uint8Array(0);function wt(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}function ie(e){if(e instanceof Uint8Array&&e.constructor.name==="Uint8Array")return Z(e);if(e instanceof ArrayBuffer)return new Uint8Array(e);if(ArrayBuffer.isView(e))return Z(new Uint8Array(e.buffer,e.byteOffset,e.byteLength));throw new Error("Unknown type, must be binary type")}function on(e){return e?.buffer instanceof ArrayBuffer}function Z(e){return on(e)?e:e.slice()}function sn(e,t,r){if(e.length>=255)throw new TypeError("Alphabet too long");for(var n=new Uint8Array(256),o=0;o<n.length;o++)n[o]=255;for(var i=0;i<e.length;i++){var c=e.charAt(i),d=c.charCodeAt(0);if(n[d]!==255)throw new TypeError(c+" is ambiguous");if(n[d]=i,r){var l=c.toLowerCase().charCodeAt(0),p=c.toUpperCase().charCodeAt(0);l!==d&&(n[l]=i),p!==d&&(n[p]=i)}}var h=e.length,g=e.charAt(0),A=Math.log(h)/Math.log(256),E=Math.log(256)/Math.log(h);function Xr(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 v=0,W=0,$=0,O=m.length;$!==O&&m[$]===0;)$++,v++;for(var L=(O-$)*E+1>>>0,Q=new Uint8Array(L);$!==O;){for(var U=m[$],Y=0,R=L-1;(U!==0||Y<W)&&R!==-1;R--,Y++)U+=256*Q[R]>>>0,Q[R]=U%h>>>0,U=U/h>>>0;if(U!==0)throw new Error("Non-zero carry");W=Y,$++}for(var B=L-W;B!==L&&Q[B]===0;)B++;for(var me=g.repeat(v);B<L;++B)me+=e.charAt(Q[B]);return me}function gt(m){if(typeof m!="string")throw new TypeError("Expected String");if(m.length===0)return new Uint8Array;var v=0;if(m[v]!==" "){for(var W=0,$=0;m[v]===g;)W++,v++;for(var O=(m.length-v)*A+1>>>0,L=new Uint8Array(O);m[v];){var Q=m.charCodeAt(v);if(Q>255)return;var U=n[Q];if(U===255)return;for(var Y=0,R=O-1;(U!==0||Y<$)&&R!==-1;R--,Y++)U+=h*L[R]>>>0,L[R]=U%256>>>0,U=U/256>>>0;if(U!==0)throw new Error("Non-zero carry");$=Y,v++}if(m[v]!==" "){for(var B=O-$;B!==O&&L[B]===0;)B++;for(var me=new Uint8Array(W+(O-B)),Qr=W;B!==O;)me[Qr++]=L[B++];return me}}}function Wr(m){var v=gt(m);if(v)return v;throw new Error(`Non-${t} character`)}return{encode:Xr,decodeUnsafe:gt,decode:Wr}}var cn=sn,an=cn,xt=an;var Xe=class{name;prefix;baseEncode;constructor(t,r,n){this.name=t,this.prefix=r,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},We=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,r,n){this.name=t,this.prefix=r;let o=r.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return bt(this,t)}},Qe=class{decoders;constructor(t){this.decoders=t}or(t){return bt(this,t)}decode(t){let r=t[0],n=this.decoders[r];if(n!=null)return n.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function bt(e,t){return new Qe({...e.decoders??{[e.prefix]:e},...t.decoders??{[t.prefix]:t}})}var Ye=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,r,n,o){this.name=t,this.prefix=r,this.baseEncode=n,this.baseDecode=o,this.encoder=new Xe(t,r,n),this.decoder=new We(t,r,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function Et({name:e,prefix:t,encode:r,decode:n}){return new Ye(e,t,r,n)}function se({name:e,prefix:t,alphabet:r,caseInsensitive:n=!1}){let{encode:o,decode:i}=xt(r,e,n);return Et({prefix:t,name:e,encode:o,decode:c=>ie(i(c))})}function un(e,t,r,n){let o=e.length;for(;e[o-1]==="=";)--o;let i=new Uint8Array(o*r/8|0),c=0,d=0,l=0;for(let p=0;p<o;++p){let h=t[e[p]];if(h===void 0)throw new SyntaxError(`Non-${n} character`);d=d<<r|h,c+=r,c>=8&&(c-=8,i[l++]=255&d>>c)}if(c>=r||(255&d<<8-c)!==0)throw new SyntaxError("Unexpected end of data");return i}function fn(e,t,r){let n=t[t.length-1]==="=",o=(1<<r)-1,i="",c=0,d=0;for(let l=0;l<e.length;++l)for(d=d<<8|e[l],c+=8;c>r;)c-=r,i+=t[o&d>>c];if(c!==0&&(i+=t[o&d<<r-c]),n)for(;(i.length*r&7)!==0;)i+="=";return i}function dn(e,t){let r={};for(let n=0;n<e.length;++n)if(e[n]!=="="&&(r[e[n]]=n,t)){let o=e[n].toLowerCase(),i=e[n].toUpperCase();o!==e[n]&&(r[o]=n),i!==e[n]&&(r[i]=n)}return r}function F({name:e,prefix:t,bitsPerChar:r,alphabet:n,caseInsensitive:o=!1}){let i=dn(n,o);return Et({prefix:t,name:e,encode(c){return fn(c,n,r)},decode(c){return un(c,i,r,e)}})}var ge=F({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5,caseInsensitive:!0}),Po=F({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5,caseInsensitive:!0}),qo=F({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5,caseInsensitive:!0}),Go=F({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5,caseInsensitive:!0}),Ho=F({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5,caseInsensitive:!0}),Jo=F({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5,caseInsensitive:!0}),Ko=F({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5,caseInsensitive:!0}),Xo=F({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5,caseInsensitive:!0}),Wo=F({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Te=se({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz",caseInsensitive:!0}),Zo=se({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",caseInsensitive:!0});var V=se({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),ri=se({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var ln=Ut,At=128,pn=127,hn=~pn,yn=Math.pow(2,31);function Ut(e,t,r){t=t||[],r=r||0;for(var n=r;e>=yn;)t[r++]=e&255|At,e/=128;for(;e&hn;)t[r++]=e&255|At,e>>>=7;return t[r]=e|0,Ut.bytes=r-n+1,t}var mn=Ze,gn=128,vt=127;function Ze(e,n){var r=0,n=n||0,o=0,i=n,c,d=e.length;do{if(i>=d)throw Ze.bytes=0,new RangeError("Could not decode varint");c=e[i++],r+=o<28?(c&vt)<<o:(c&vt)*Math.pow(2,o),o+=7}while(c>=gn);return Ze.bytes=i-n,r}var wn=Math.pow(2,7),xn=Math.pow(2,14),bn=Math.pow(2,21),En=Math.pow(2,28),An=Math.pow(2,35),vn=Math.pow(2,42),Un=Math.pow(2,49),In=Math.pow(2,56),Bn=Math.pow(2,63),Tn=function(e){return e<wn?1:e<xn?2:e<bn?3:e<En?4:e<An?5:e<vn?6:e<Un?7:e<In?8:e<Bn?9:10},_n={encode:ln,decode:mn,encodingLength:Tn},Sn=_n,we=Sn;function xe(e,t=0){let r=we.decode(e,t),n=we.decode.bytes;if(n>9)throw new RangeError("Invalid varint: too long");if(n>1&&e[t+n-1]===0)throw new RangeError("Invalid varint: not minimally encoded");return[r,n]}function ce(e,t,r=0){return we.encode(e,t,r),t}function ae(e){return we.encodingLength(e)}function _e(e,t){let r=t.byteLength,n=ae(e),o=n+ae(r),i=new Uint8Array(o+r);return ce(e,i,0),ce(r,i,n),i.set(t,o),new ue(e,r,t,i)}function Bt(e){let t=ie(e),[r,n]=xe(t),[o,i]=xe(t.subarray(n)),c=t.subarray(n+i);if(c.byteLength!==o)throw new Error("Incorrect length");return new ue(r,o,c,t)}function Tt(e,t){if(e===t)return!0;{let r=t;return e.code===r.code&&e.size===r.size&&r.bytes instanceof Uint8Array&&wt(e.bytes,r.bytes)}}var ue=class{code;size;digest;bytes;constructor(t,r,n,o){this.code=t,this.size=r,this.digest=Z(n),this.bytes=Z(o)}};function St(e,t){let{bytes:r,version:n}=e;return n===0?kn(r,et(e),t??V.encoder):Cn(r,et(e),t??ge.encoder)}var Nt=new WeakMap;function et(e){let t=Nt.get(e);if(t==null){let r=new Map;return Nt.set(e,r),r}return t}var ee=class e{code;version;multihash;bytes;"/";constructor(t,r,n,o){this.code=r,this.version=t,this.multihash=n,this.bytes=Z(o),this["/"]=this.bytes}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:t,multihash:r}=this;if(t!==be)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==$n)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=_e(t,r);return e.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(t){return e.equals(this,t)}static equals(t,r){let n=r;return n!=null&&t.code===n.code&&t.version===n.version&&Tt(t.multihash,n.multihash)}toString(t){return St(this,t)}toJSON(){return{"/":St(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(t){if(t==null)return null;let r=t;if(r instanceof e)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:o,multihash:i,bytes:c}=r;return new e(n,o,i,c??kt(n,o,i.bytes))}else if(r[Mn]===!0){let{version:n,multihash:o,code:i}=r,c=Bt(o);return e.create(n,i,c)}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!==be)throw new Error(`Version 0 CID must use dag-pb (code: ${be}) block encoding`);return new e(t,r,n,n.bytes)}case 1:{let o=kt(t,r,n.bytes);return new e(t,r,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return e.create(0,be,t)}static createV1(t,r){return e.create(1,t,r)}static decode(t){let[r,n]=e.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return r}static decodeFirst(t){let r=e.inspectBytes(t),n=r.size-r.multihashSize,o=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),c=new ue(r.multihashCode,r.digestSize,i,o);return[r.version===0?e.createV0(c):e.createV1(r.codec,c),t.subarray(r.size)]}static inspectBytes(t){let r=0,n=()=>{let[g,A]=xe(t.subarray(r));return r+=A,g},o=n(),i=be;if(o===18)o=0,r=0;else if(o===1)i=n();else throw o===0?new RangeError("Invalid CID version, v0 is always implicit"):new RangeError(`Invalid CID version ${o}`);let c=r,d=n(),l=n(),p=r+l,h=p-c;return{version:o,codec:i,multihashCode:d,digestSize:l,multihashSize:h,size:p}}static parse(t,r){let[n,o]=Nn(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 et(i).set(n,t),i}};function Nn(e,t){switch(e[0]){case"Q":{let r=t??V;return[V.prefix,r.decode(`${V.prefix}${e}`)]}case V.prefix:{let r=t??V;return[V.prefix,r.decode(e)]}case ge.prefix:{let r=t??ge;return[ge.prefix,r.decode(e)]}case Te.prefix:{let r=t??Te;return[Te.prefix,r.decode(e)]}default:{if(t==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[e[0],t.decode(e)]}}}function kn(e,t,r){let{prefix:n}=r;if(n!==V.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let o=t.get(n);if(o==null){let i=r.encode(e).slice(1);return t.set(n,i),i}else return o}function Cn(e,t,r){let{prefix:n}=r,o=t.get(n);if(o==null){let i=r.encode(e);return t.set(n,i),i}else return o}var be=112,$n=18;function kt(e,t,r){let n=ae(e),o=n+ae(t),i=new Uint8Array(o+r.byteLength);return ce(e,i,0),ce(t,i,n),i.set(r,o),i}var Mn=Symbol.for("@ipld/js-cid/CID");var Dn=20;function rt({name:e,code:t,encode:r,minDigestLength:n,maxDigestLength:o}){return new tt(e,t,r,n,o)}var tt=class{name;code;encode;minDigestLength;maxDigestLength;constructor(t,r,n,o,i){this.name=t,this.code=r,this.encode=n,this.minDigestLength=o??Dn,this.maxDigestLength=i}digest(t,r){if(r?.truncate!=null){if(r.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&r.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(t instanceof Uint8Array){let n=this.encode(t);return n instanceof Uint8Array?Ct(n,this.code,r?.truncate):n.then(o=>Ct(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function Ct(e,t,r){if(r!=null&&r!==e.byteLength){if(r>e.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${e.byteLength}`);e=e.subarray(0,r)}return _e(t,e)}function $t(e=0){return new Uint8Array(e)}function On(e){return e?.buffer instanceof ArrayBuffer}function Mt(e){if(On(e))return e;let t=e.slice();return new Uint8Array(t.buffer,0,t.byteLength)}function nt(e,t){t==null&&(t=e.reduce((o,i)=>o+i.length,0));let r=$t(t),n=0;for(let o of e)r.set(o,n),n+=o.length;return Mt(r)}function Dt(e){return async t=>new Uint8Array(await crypto.subtle.digest(e,t))}var Ot=rt({name:"sha2-256",code:18,encode:Dt("SHA-256")}),bi=rt({name:"sha2-512",code:19,encode:Dt("SHA-512")});var Se=class extends Error{static name="InvalidCodecError";constructor(t="Invalid codec"){super(t),this.name="InvalidCodecError"}};var Ln=["Object","Uint8Array","RegExp","Date","Error","Map","Set","WeakMap","WeakSet","ArrayBuffer","SharedArrayBuffer","DataView","Promise","URL","HTMLElement","Int8Array","Uint8ClampedArray","Int16Array","Uint16Array","Int32Array","Uint32Array","Float32Array","Float64Array","BigInt64Array","BigUint64Array","Tagged","Number","String","Boolean","BigInt","Symbol"];function ot(e){if(e===null)return"null";if(e===void 0)return"undefined";if(e===!0||e===!1)return"boolean";let t=typeof e;if(t==="string"||t==="number"||t==="bigint"||t==="symbol")return t;if(t==="function")return"Function";if(Array.isArray(e))return"Array";if(e instanceof Uint8Array)return"Uint8Array";if(e.constructor===Object)return"Object";let r=Fn(e);return r||"Object"}function Fn(e){let t=Object.prototype.toString.call(e).slice(8,-1);if(Ln.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}static equals(t,r){return t===r||t.major===r.major&&t.name===r.name}};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 fe=class{constructor(){this.home=new Uint8Array(2048),this.buf=this.home,this.pos=0,this.start=0,this.segs=[],this.segLen=0}reset(){this.buf.length>this.home.length&&this.buf.length<=65536&&(this.home=this.buf),this.buf=this.home,this.pos=0,this.start=0,this.segs.length>0&&(this.segs=[],this.segLen=0)}grow(t){let r=this.pos-this.start;if(this.buf.length>=262144)r>0&&(this.segs.push(this.buf.subarray(this.start,this.pos)),this.segLen+=r),this.buf=new Uint8Array(t>262144?t:262144),this.pos=0,this.start=0;else{let n=this.buf.length*2;for(;n<r+t;)n*=2;let o=new Uint8Array(n);o.set(this.buf.subarray(this.start,this.pos)),this.buf=o,this.pos=r,this.start=0}}pushByte(t){this.pos>=this.buf.length&&this.grow(1),this.buf[this.pos++]=t}pushArr(t){let r=t.length;this.pos+r>this.buf.length&&this.grow(r);let n=this.buf,o=this.pos;for(let i=0;i<r;i++)n[o++]=t[i];this.pos=o}pushBytes(t){let r=t.length;if(r>=1024){this.pos>this.start&&(this.segs.push(this.buf.subarray(this.start,this.pos)),this.segLen+=this.pos-this.start),this.segs.push(t),this.segLen+=r,this.start=this.pos;return}this.pos+r>this.buf.length&&this.grow(r);let n=this.buf,o=this.pos;if(r<16)for(let i=0;i<r;i++)n[o++]=t[i];else n.set(t,o),o+=r;this.pos=o}push(t){Array.isArray(t)?this.pushArr(t):this.pushBytes(t)}toBytes(t=!1){let r;if(this.segs.length===0)r=new Uint8Array(this.buf.subarray(this.start,this.pos));else{r=new Uint8Array(this.segLen+(this.pos-this.start));let n=0;for(let o of this.segs)r.set(o,n),n+=o.length;r.set(this.buf.subarray(this.start,this.pos),n)}return t&&this.reset(),r}},te=class{constructor(t){this.dest=t,this.cursor=0}reset(){this.cursor=0}pushByte(t){if(this.cursor>=this.dest.length)throw new Error("write out of bounds, destination buffer is too small");this.dest[this.cursor++]=t}push(t){if(this.cursor+t.length>this.dest.length)throw new Error("write out of bounds, destination buffer is too small");this.dest.set(t,this.cursor),this.cursor+=t.length}pushArr(t){let r=t.length;if(this.cursor+r>this.dest.length)throw new Error("write out of bounds, destination buffer is too small");let n=this.dest,o=this.cursor;for(let i=0;i<r;i++)n[o++]=t[i];this.cursor=o}pushBytes(t){this.push(t)}toBytes(t=!1){let r=this.dest.subarray(0,this.cursor);return t&&this.reset(),r}};var f="CBOR decode error:",k="CBOR encode error:",Ee=[];Ee[23]=1;Ee[24]=2;Ee[25]=3;Ee[26]=5;Ee[27]=9;function P(e,t,r){if(e.length-t<r)throw new Error(`${f} not enough data for type`)}var w=[24,256,65536,4294967296,BigInt("18446744073709551616")];function T(e,t,r){P(e,t,1);let n=e[t];if(r.strict===!0&&n<w[0])throw new Error(`${f} integer encoded in more bytes than necessary (strict decode)`);return n}function _(e,t,r){P(e,t,2);let n=e[t]<<8|e[t+1];if(r.strict===!0&&n<w[1])throw new Error(`${f} integer encoded in more bytes than necessary (strict decode)`);return n}function S(e,t,r){P(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(`${f} integer encoded in more bytes than necessary (strict decode)`);return n}function N(e,t,r){P(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(`${f} 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(`${f} integers outside of the safe integer range are not supported`)}function Lt(e,t,r,n){return new u(s.uint,T(e,t+1,n),2)}function Ft(e,t,r,n){return new u(s.uint,_(e,t+1,n),3)}function jt(e,t,r,n){return new u(s.uint,S(e,t+1,n),5)}function zt(e,t,r,n){return new u(s.uint,N(e,t+1,n),9)}function j(e,t){return x(e,0,t.value)}function x(e,t,r){if(r<w[0]){let n=Number(r);e.pushByte(t|n)}else if(r<w[1]){let n=Number(r);e.pushArr([t|24,n])}else if(r<w[2]){let n=Number(r);e.pushArr([t|25,n>>>8,n&255])}else if(r<w[3]){let n=Number(r);e.pushArr([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)),c=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]=c&255,c=c>>8,o[3]=c&255,c=c>>8,o[2]=c&255,c=c>>8,o[1]=c&255,e.pushArr(o)}else throw new Error(`${k} encountered BigInt larger than allowable range`)}}j.encodedSize=function(t){return x.encodedSize(t.value)};x.encodedSize=function(t){if(t<w[0])return 1;if(t<w[1])return 2;if(t<w[2])return 3;if(t<w[3])return 5;if(t>=w[4])throw new Error(`${k} encountered BigInt larger than allowable range`);return 9};j.compareTokens=function(t,r){return t.value<r.value?-1:t.value>r.value?1:0};function Rt(e,t,r,n){return new u(s.negint,-1-T(e,t+1,n),2)}function Vt(e,t,r,n){return new u(s.negint,-1-_(e,t+1,n),3)}function Pt(e,t,r,n){return new u(s.negint,-1-S(e,t+1,n),5)}var it=BigInt(-1),qt=BigInt(1);function Gt(e,t,r,n){let o=N(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(`${f} integers outside of the safe integer range are not supported`);return new u(s.negint,it-BigInt(o),9)}function Ne(e,t){let r=t.value,n=typeof r=="bigint"?r*it-qt:r*-1-1;x(e,t.type.majorEncoded,n)}Ne.encodedSize=function(t){let r=t.value,n=typeof r=="bigint"?r*it-qt:r*-1-1;if(n<w[0])return 1;if(n<w[1])return 2;if(n<w[2])return 3;if(n<w[3])return 5;if(n>=w[4])throw new Error(`${k} encountered BigInt larger than allowable range`);return 9};Ne.compareTokens=function(t,r){return t.value<r.value?1:t.value>r.value?-1:0};var Jt=globalThis.process&&!globalThis.process.browser&&globalThis.Buffer&&typeof globalThis.Buffer.isBuffer=="function",zn=new TextEncoder;function st(e){return Jt&&globalThis.Buffer.isBuffer(e)}function Kt(e){return e instanceof Uint8Array?st(e)?new Uint8Array(e.buffer,e.byteOffset,e.byteLength):e:Uint8Array.from(e)}var Rn=24,Vn=200,Ae=Jt?e=>e.length>=Rn?globalThis.Buffer.from(e):Ht(e):e=>e.length>=Vn?zn.encode(e):Ht(e),z=e=>Uint8Array.from(e);function de(e,t){if(st(e)&&st(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 Ht(e){let t=[],r=0;for(let n=0;n<e.length;n++){let o=e.charCodeAt(n);o<128?t[r++]=o:o<2048?(t[r++]=o>>6|192,t[r++]=o&63|128):(o&64512)===55296&&n+1<e.length&&(e.charCodeAt(n+1)&64512)===56320?(o=65536+((o&1023)<<10)+(e.charCodeAt(++n)&1023),t[r++]=o>>18|240,t[r++]=o>>12&63|128,t[r++]=o>>6&63|128,t[r++]=o&63|128):(o>=55296&&o<=57343&&(o=65533),t[r++]=o>>12|224,t[r++]=o>>6&63|128,t[r++]=o&63|128)}return t}function ve(e,t,r,n){P(e,t,r+n);let o=e.slice(t+r,t+r+n);return new u(s.bytes,o,r+n)}function Xt(e,t,r,n){return ve(e,t,1,r)}function Wt(e,t,r,n){return ve(e,t,2,T(e,t+1,n))}function Qt(e,t,r,n){return ve(e,t,3,_(e,t+1,n))}function Yt(e,t,r,n){return ve(e,t,5,S(e,t+1,n))}function Zt(e,t,r,n){let o=N(e,t+1,n);if(typeof o=="bigint")throw new Error(`${f} 64-bit integer bytes lengths not supported`);return ve(e,t,9,o)}function ke(e){return e.encodedBytes===void 0&&(e.encodedBytes=s.equals(e.type,s.string)?Ae(e.value):e.value),e.encodedBytes}function le(e,t){let r=ke(t);x(e,t.type.majorEncoded,r.length),e.push(r)}le.encodedSize=function(t){let r=ke(t);return x.encodedSize(r.length)+r.length};le.compareTokens=function(t,r){return Pn(ke(t),ke(r))};function Pn(e,t){return e.length<t.length?-1:e.length>t.length?1:de(e,t)}var er=new TextDecoder("utf-8",{ignoreBOM:!0}),Gn=new TextDecoder("utf-8",{ignoreBOM:!0,fatal:!0}),Hn=32;function Jn(e,t,r,n){if(r-t<Hn){let i="";for(let c=t;c<r;c++){let d=e[c];if(d&128)return n.rejectInvalidUtf8===!0?tr(e,t,r):er.decode(e.subarray(t,r));i+=String.fromCharCode(d)}return i}return n.rejectInvalidUtf8===!0?tr(e,t,r):er.decode(e.subarray(t,r))}function tr(e,t,r){try{return Gn.decode(e.subarray(t,r))}catch{throw new Error(`${f} invalid UTF-8 in text string`)}}function Ue(e,t,r,n,o){let i=r+n;P(e,t,i);let c=new u(s.string,Jn(e,t+r,t+i,o),i);return o.retainStringBytes===!0&&(c.byteValue=e.slice(t+r,t+i)),c}function rr(e,t,r,n){return Ue(e,t,1,r,n)}function nr(e,t,r,n){return Ue(e,t,2,T(e,t+1,n),n)}function or(e,t,r,n){return Ue(e,t,3,_(e,t+1,n),n)}function ir(e,t,r,n){return Ue(e,t,5,S(e,t+1,n),n)}function sr(e,t,r,n){let o=N(e,t+1,n);if(typeof o=="bigint")throw new Error(`${f} 64-bit integer string lengths not supported`);return Ue(e,t,9,o,n)}var cr=le;function pe(e,t,r,n){return new u(s.array,n,r)}function ar(e,t,r,n){return pe(e,t,1,r)}function ur(e,t,r,n){return pe(e,t,2,T(e,t+1,n))}function fr(e,t,r,n){return pe(e,t,3,_(e,t+1,n))}function dr(e,t,r,n){return pe(e,t,5,S(e,t+1,n))}function lr(e,t,r,n){let o=N(e,t+1,n);if(typeof o=="bigint")throw new Error(`${f} 64-bit integer array lengths not supported`);return pe(e,t,9,o)}function pr(e,t,r,n){if(n.allowIndefinite===!1)throw new Error(`${f} indefinite length items not allowed`);return pe(e,t,1,1/0)}function Ce(e,t){x(e,s.array.majorEncoded,t.value)}Ce.compareTokens=j.compareTokens;Ce.encodedSize=function(t){return x.encodedSize(t.value)};function he(e,t,r,n){return new u(s.map,n,r)}function hr(e,t,r,n){return he(e,t,1,r)}function yr(e,t,r,n){return he(e,t,2,T(e,t+1,n))}function mr(e,t,r,n){return he(e,t,3,_(e,t+1,n))}function gr(e,t,r,n){return he(e,t,5,S(e,t+1,n))}function wr(e,t,r,n){let o=N(e,t+1,n);if(typeof o=="bigint")throw new Error(`${f} 64-bit integer map lengths not supported`);return he(e,t,9,o)}function xr(e,t,r,n){if(n.allowIndefinite===!1)throw new Error(`${f} indefinite length items not allowed`);return he(e,t,1,1/0)}function $e(e,t){x(e,s.map.majorEncoded,t.value)}$e.compareTokens=j.compareTokens;$e.encodedSize=function(t){return x.encodedSize(t.value)};function br(e,t,r,n){return new u(s.tag,r,1)}function Er(e,t,r,n){return new u(s.tag,T(e,t+1,n),2)}function Ar(e,t,r,n){return new u(s.tag,_(e,t+1,n),3)}function vr(e,t,r,n){return new u(s.tag,S(e,t+1,n),5)}function Ur(e,t,r,n){return new u(s.tag,N(e,t+1,n),9)}function Me(e,t){x(e,s.tag.majorEncoded,t.value)}Me.compareTokens=j.compareTokens;Me.encodedSize=function(t){return x.encodedSize(t.value)};var De=20,Oe=21,Le=22,Fe=23;function Br(e,t,r,n){if(n.allowUndefined===!1)throw new Error(`${f} undefined values are not supported`);return n.coerceUndefinedToNull===!0?new u(s.null,null,1):new u(s.undefined,void 0,1)}function Tr(e,t,r,n){if(n.allowIndefinite===!1)throw new Error(`${f} indefinite length items not allowed`);return new u(s.break,void 0,1)}function ct(e,t,r){if(r){if(r.allowNaN===!1&&Number.isNaN(e))throw new Error(`${f} NaN values are not supported`);if(r.allowInfinity===!1&&(e===1/0||e===-1/0))throw new Error(`${f} Infinity values are not supported`)}return new u(s.float,e,t)}function _r(e,t,r,n){return ct(je(e,t+1),3,n)}function Sr(e,t,r,n){return ct(ze(e,t+1),5,n)}function Nr(e,t,r,n){return ct($r(e,t+1),9,n)}function Ie(e,t,r){let n=t.value;if(n===!1)e.pushByte(s.float.majorEncoded|De);else if(n===!0)e.pushByte(s.float.majorEncoded|Oe);else if(n===null)e.pushByte(s.float.majorEncoded|Le);else if(n===void 0)s.equals(t.type,s.break)||e.pushByte(s.float.majorEncoded|Fe);else{let o,i=!1;(!r||r.float64!==!0)&&(at(n),o=je(b,1),n===o||Number.isNaN(n)?(b[0]=249,e.pushBytes(b.slice(0,3)),i=!0):(ut(n),o=ze(b,1),n===o&&(b[0]=250,e.pushBytes(b.slice(0,5)),i=!0))),i||(Cr(n),o=$r(b,1),b[0]=251,e.pushBytes(b.slice(0,9)))}}Ie.encodedSize=function(t,r){let n=t.value;if(n===void 0)return s.equals(t.type,s.break)?0:1;if(n===!1||n===!0||n===null)return 1;if(!r||r.float64!==!0){at(n);let o=je(b,1);if(n===o||Number.isNaN(n))return 3;if(ut(n),o=ze(b,1),n===o)return 5}return 9};var kr=new ArrayBuffer(9),C=new DataView(kr,1),b=new Uint8Array(kr,0);function at(e){if(e===1/0)C.setUint16(0,31744,!1);else if(e===-1/0)C.setUint16(0,64512,!1);else if(Number.isNaN(e))C.setUint16(0,32256,!1);else{C.setFloat32(0,e);let t=C.getUint32(0),r=(t&2139095040)>>23,n=t&8388607;if(r===255)C.setUint16(0,31744,!1);else if(r===0)C.setUint16(0,(t&2147483648)>>16|n>>13,!1);else{let o=r-127;o<-24?C.setUint16(0,0):o<-14?C.setUint16(0,(t&2147483648)>>16|(8388608|n)>>-1-o,!1):C.setUint16(0,(t&2147483648)>>16|o+15<<10|n>>13,!1)}}}function je(e,t){if(e.length-t<2)throw new Error(`${f} 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 ut(e){C.setFloat32(0,e,!1)}function ze(e,t){if(e.length-t<4)throw new Error(`${f} not enough data for float32`);let r=(e.byteOffset||0)+t;return new DataView(e.buffer,r,4).getFloat32(0,!1)}function Cr(e){C.setFloat64(0,e,!1)}function $r(e,t){if(e.length-t<8)throw new Error(`${f} not enough data for float64`);let r=(e.byteOffset||0)+t;return new DataView(e.buffer,r,8).getFloat64(0,!1)}function Yn(e,t){let r=e.value;if(r===!1)return Uint8Array.of(s.float.majorEncoded|De);if(r===!0)return Uint8Array.of(s.float.majorEncoded|Oe);if(r===null)return Uint8Array.of(s.float.majorEncoded|Le);if(r===void 0)return Uint8Array.of(s.float.majorEncoded|Fe);if(!t){if(at(r),r===je(b,1)||Number.isNaN(r))return b[0]=249,b.slice(0,3);if(ut(r),r===ze(b,1))return b[0]=250,b.slice(0,5)}return Cr(r),b[0]=251,b.slice(0,9)}function Ir(e,t){let r=e,n=t?.float64===!0,o=n?r._keyBytesFloat64:r._keyBytes;if(o!==void 0)return o;let i=Yn(e,n);return n?r._keyBytesFloat64=i:r._keyBytes=i,i}Ie.compareTokens=function(t,r,n){let o=Ir(t,n),i=Ir(r,n);return o.length!==i.length?o.length<i.length?-1:1:de(o,i)};function y(e,t,r){throw new Error(`${f} encountered invalid minor (${r}) for major ${e[t]>>>5}`)}function Re(e){return()=>{throw new Error(`${f} ${e}`)}}var a=[];for(let e=0;e<=23;e++)a[e]=y;a[24]=Lt;a[25]=Ft;a[26]=jt;a[27]=zt;a[28]=y;a[29]=y;a[30]=y;a[31]=y;for(let e=32;e<=55;e++)a[e]=y;a[56]=Rt;a[57]=Vt;a[58]=Pt;a[59]=Gt;a[60]=y;a[61]=y;a[62]=y;a[63]=y;for(let e=64;e<=87;e++)a[e]=Xt;a[88]=Wt;a[89]=Qt;a[90]=Yt;a[91]=Zt;a[92]=y;a[93]=y;a[94]=y;a[95]=Re("indefinite length bytes/strings are not supported");for(let e=96;e<=119;e++)a[e]=rr;a[120]=nr;a[121]=or;a[122]=ir;a[123]=sr;a[124]=y;a[125]=y;a[126]=y;a[127]=Re("indefinite length bytes/strings are not supported");for(let e=128;e<=151;e++)a[e]=ar;a[152]=ur;a[153]=fr;a[154]=dr;a[155]=lr;a[156]=y;a[157]=y;a[158]=y;a[159]=pr;for(let e=160;e<=183;e++)a[e]=hr;a[184]=yr;a[185]=mr;a[186]=gr;a[187]=wr;a[188]=y;a[189]=y;a[190]=y;a[191]=xr;for(let e=192;e<=215;e++)a[e]=br;a[216]=Er;a[217]=Ar;a[218]=vr;a[219]=Ur;a[220]=y;a[221]=y;a[222]=y;a[223]=y;for(let e=224;e<=243;e++)a[e]=Re("simple values are not supported");a[244]=y;a[245]=y;a[246]=y;a[247]=Br;a[248]=Re("simple values are not supported");a[249]=_r;a[250]=Sr;a[251]=Nr;a[252]=y;a[253]=y;a[254]=y;a[255]=Tr;var M=[];for(let e=0;e<24;e++)M[e]=new u(s.uint,e,1);for(let e=-1;e>=-24;e--)M[31-e]=new u(s.negint,e,1);M[64]=new u(s.bytes,new Uint8Array(0),1);M[96]=new u(s.string,"",1);M[128]=new u(s.array,0,1);M[160]=new u(s.map,0,1);M[244]=new u(s.false,!1,1);M[245]=new u(s.true,!0,1);M[246]=new u(s.null,null,1);function ft(e){switch(e.type){case s.false:return z([244]);case s.true:return z([245]);case s.null:return z([246]);case s.bytes:return e.value.length?void 0:z([64]);case s.string:return e.value===""?z([96]):void 0;case s.array:return e.value===0?z([128]):void 0;case s.map:return e.value===0?z([160]):void 0;case s.uint:return e.value<24?z([Number(e.value)]):void 0;case s.negint:if(e.value>=-24)return z([31-Number(e.value)])}}var eo={float64:!1,mapSorter:dt,quickEncodeToken:ft},zr=Object.freeze({mapSorter:no,quickEncodeToken:ft});function to(){let e=[];return e[s.uint.major]=j,e[s.negint.major]=Ne,e[s.bytes.major]=le,e[s.string.major]=cr,e[s.array.major]=Ce,e[s.map.major]=$e,e[s.tag.major]=Me,e[s.float.major]=Ie,e}var ne=to(),Ve=new fe,Pe=!1,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(`${k} object contains circular references`);return new e(r,t)}},q={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)},I={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?q.true:q.false},null(e,t,r,n){return q.null},undefined(e,t,r,n){return q.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?[q.emptyArray,new u(s.break)]:q.emptyArray;n=oe.createCheck(n,e);let o=[],i=0;for(let c of e)o[i++]=H(c,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),c=o?e.size:i.length,d;if(c){d=new Array(c),n=oe.createCheck(n,e);let l=!o&&r.ignoreUndefinedProperties,p=0;for(let h of i){let g=o?e.get(h):e[h];l&&g===void 0||(d[p++]=[H(h,r,n),H(g,r,n)])}p<c&&(d.length=p)}return d?.length?(ro(d,r),r.addBreakTokens?[new u(s.map,d.length),d,new u(s.break)]:[new u(s.map,d.length),d]):r.addBreakTokens===!0?[q.emptyMap,new u(s.break)]:q.emptyMap},Tagged(e,t,r,n){return[new u(s.tag,e.tag),H(e.value,r,n)]}};I.Map=I.Object;function qe(e){return(t,r,n,o)=>{let i;try{i=e.call(t)}catch{throw new Error(`${k} unsupported type: ${r} (object only claims the tag via Symbol.toStringTag)`)}return H(i,n,o)}}I.Number=qe(Number.prototype.valueOf);I.String=qe(String.prototype.valueOf);I.Boolean=qe(Boolean.prototype.valueOf);I.BigInt=qe(BigInt.prototype.valueOf);I.Buffer=I.Uint8Array;for(let e of"Uint8Clamped Uint16 Uint32 Int8 Int16 Int32 BigUint64 BigInt64 Float32 Float64".split(" "))I[`${e}Array`]=I.DataView;function H(e,t={},r){let n=ot(e),o=t&&t.typeEncoders&&t.typeEncoders[n]||I[n];if(typeof o=="function"){let c=o(e,n,t,r);if(c!=null)return c}let i=I[n];if(!i)throw new Error(`${k} unsupported type: ${n}`);return i(e,n,t,r)}function ro(e,t){let r=t.mapSorter;r&&e.sort((n,o)=>r(n,o,t))}var Mr=!1;function dt(e,t,r){let n=Array.isArray(e[0])?e[0][0]:e[0],o=Array.isArray(t[0])?t[0][0]:t[0];if(n.type.major!==o.type.major)return n.type.compare(o.type);let i=n.type.major,c=ne[i].compareTokens(n,o,r);if(c===0){if(i<=s.string.major)throw new Error(`${k} duplicate map key`);Mr||(Mr=!0,console.warn("WARNING: complex key types used, CBOR key sorting guarantees are gone"))}return c}function no(e,t){if(e[0]instanceof u&&t[0]instanceof u){let r=e[0],n=t[0];r._keyBytes||(r._keyBytes=Dr(r.value)),n._keyBytes||(n._keyBytes=Dr(n.value));let o=de(r._keyBytes,n._keyBytes);if(o===0)throw new Error(`${k} duplicate map key`);return o}throw new Error("rfc8949MapSorter: complex key types are not supported yet")}function Dr(e){return Pr(e,ne,zr)}function ye(e,t,r,n){if(Array.isArray(t))for(let o of t)ye(e,o,r,n);else r[t.type.major](e,t,n)}var Or=s.uint.majorEncoded,Lr=s.negint.majorEncoded,oo=s.bytes.majorEncoded,Rr=s.string.majorEncoded,Fr=s.array.majorEncoded,G=s.map.majorEncoded,io=s.float.majorEncoded|De,so=s.float.majorEncoded|Oe,co=s.float.majorEncoded|Le,ao=s.float.majorEncoded|Fe,uo=BigInt(-1),fo=BigInt(1);function D(e,t,r){r<24?e.pushByte(t|Number(r)):x(e,t,r)}function lo(e){return e.addBreakTokens!==!0}function Vr(e,t){return e.length-t.length||(e<t?-1:e>t?1:0)}function po(e,t){return Vr(e[0],t[0])}var ho=256,yo=16;function jr(e,t,r,n,o){let i=Ae(t);D(e,Rr,i.length),Array.isArray(i)?e.pushArr(i):e.pushBytes(i),Be(e,r,n,o)}function mo(e,t,r,n,o){let i=r.length;for(let l=0;l<i;l++){let p=r[l];if(p.length>ho)return!1;for(let h=0;h<p.length;h++)if(p.charCodeAt(h)>127)return!1}if(i===0)return e.pushByte(G),!0;o=oe.createCheck(o,t);let c=n.ignoreUndefinedProperties,d=0;if(i<=yo){let l=new Array(i),p=new Array(i);for(let h=0;h<i;h++){let g=r[h],A=t[g];if(c&&A===void 0)continue;let E=d++;for(;E>0&&Vr(l[E-1],g)>0;)l[E]=l[E-1],p[E]=p[E-1],E--;l[E]=g,p[E]=A}if(d===0)return e.pushByte(G),!0;D(e,G,d);for(let h=0;h<d;h++)jr(e,l[h],p[h],n,o)}else{let l=[];for(let p=0;p<i;p++){let h=r[p],g=t[h];c&&g===void 0||l.push([h,g])}if(l.sort(po),d=l.length,d===0)return e.pushByte(G),!0;D(e,G,d);for(let p=0;p<d;p++)jr(e,l[p][0],l[p][1],n,o)}return!0}function go(e,t,r,n,o,i){let c=r==="Map",d=c?t.keys():i||Object.keys(t),l=c?t.size:d.length;if(!l){e.pushByte(G);return}o=oe.createCheck(o,t);let p=!c&&n.ignoreUndefinedProperties,h=new Array(l),g=0;for(let A of d){let E=c?t.get(A):t[A];p&&E===void 0||(h[g++]=[H(A,n,o),E])}if(g===0){e.pushByte(G);return}g<l&&(h.length=g),h.sort((A,E)=>dt(A,E,n)),D(e,G,g);for(let[A,E]of h)ye(e,A,ne,n),Be(e,E,n,o)}function Be(e,t,r,n){let o=ot(t),i=r.typeEncoders&&r.typeEncoders[o];if(i){let c=i(t,o,r,n);if(c!=null){ye(e,c,ne,r);return}}switch(o){case"null":e.pushByte(co);return;case"undefined":e.pushByte(ao);return;case"boolean":e.pushByte(t?so:io);return;case"number":!Number.isInteger(t)||!Number.isSafeInteger(t)?Ie(e,new u(s.float,t),r):t>=0?D(e,Or,t):D(e,Lr,t*-1-1);return;case"bigint":t>=BigInt(0)?D(e,Or,t):D(e,Lr,t*uo-fo);return;case"string":{let c=Ae(t);D(e,Rr,c.length),Array.isArray(c)?e.pushArr(c):e.pushBytes(c);return}case"Uint8Array":D(e,oo,t.length),e.pushBytes(t);return;case"Array":if(!t.length){e.pushByte(Fr);return}n=oe.createCheck(n,t),D(e,Fr,t.length);for(let c of t)Be(e,c,r,n);return;case"Object":case"Map":if(r.mapSorter===dt){let c=o==="Object"?Object.keys(t):void 0;if(c!==void 0&&!(r.typeEncoders&&r.typeEncoders.string)&&mo(e,t,c,r,n))return;go(e,t,o,r,n,c)}else{let c=I.Object(t,o,r,n);ye(e,c,ne,r)}return;default:{let c=I[o];if(!c)throw new Error(`${k} unsupported type: ${o}`);let d=c(t,o,r,n);ye(e,d,ne,r)}}}function Pr(e,t,r,n){let o=n!==void 0,i=H(e,r);if(!Array.isArray(i)&&r.quickEncodeToken){let d=r.quickEncodeToken(i);if(d){if(o){let p=new te(n);return p.pushBytes(d),p.toBytes()}return d}let l=t[i.type.major];if(l.encodedSize){let p=l.encodedSize(i,r);if(o){let A=new te(n);return l(A,i,r),A.toBytes()}let h=new Uint8Array(p),g=new te(h);if(l(g,i,r),g.cursor!==p)throw new Error(`Unexpected error: pre-calculated length for ${i} was wrong`);return h}}let c=o?new te(n):Pe?new fe:Ve;return c.reset(),ye(c,i,t,r),c.toBytes(!0)}function lt(e,t){if(t=Object.assign({},eo,t),lo(t)){if(Pe){let r=new fe;return Be(r,e,t,void 0),r.toBytes()}Pe=!0;try{return Ve.reset(),Be(Ve,e,t,void 0),Ve.toBytes(!0)}finally{Pe=!1}}return Pr(e,ne,t)}var wo={strict:!1,allowIndefinite:!0,allowUndefined:!0,allowBigInt:!0},Ge=class{constructor(t,r={}){this._pos=0,this.data=t,this.options=r}pos(){return this._pos}done(){return this._pos>=this.data.length}next(){let t=this.data[this._pos],r=M[t];if(r===void 0){let n=a[t];if(!n)throw t===void 0?new Error(`${f} not enough data`):new Error(`${f} 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}},J=Symbol.for("DONE"),K=Symbol.for("BREAK");function xo(e,t,r){let n=[];for(let o=0;o<e.value;o++){let i=X(t,r);if(i===K){if(e.value===1/0)break;throw new Error(`${f} got unexpected break to lengthed array`)}if(i===J)throw new Error(`${f} found array but not enough entries (got ${o}, expected ${e.value})`);n[o]=i}return n}function bo(e,t,r){let n=r.useMaps===!0,o=r.rejectDuplicateMapKeys===!0,i=n?void 0:{},c=n?new Map:void 0;for(let d=0;d<e.value;d++){let l=X(t,r);if(l===K){if(e.value===1/0)break;throw new Error(`${f} got unexpected break to lengthed map`)}if(l===J)throw new Error(`${f} found map but not enough entries (got ${d} [no key], expected ${e.value})`);if(!n&&typeof l!="string")throw new Error(`${f} non-string keys not supported (got ${typeof l})`);if(o&&(n&&c.has(l)||!n&&Object.hasOwn(i,l)))throw new Error(`${f} found repeat map key "${l}"`);let p=X(t,r);if(p===J)throw new Error(`${f} found map but not enough entries (got ${d} [no value], expected ${e.value})`);if(p===K)throw new Error(`${f} got unexpected break to map value`);n?c.set(l,p):l==="__proto__"?Object.defineProperty(i,l,{value:p,configurable:!0,enumerable:!0,writable:!0}):i[l]=p}return n?c:i}function*Eo(e,t,r){let n=e.value>1&&r.rejectDuplicateMapKeys===!0?new Set:void 0;for(let o=0;o<e.value;o++){let i=X(t,r);if(i===K){if(e.value===1/0)break;throw new Error(`${f} got unexpected break to lengthed map`)}if(i===J)throw new Error(`${f} found map but not enough entries (got ${o} [no key], expected ${e.value})`);if(n&&n.add(i).size!==o+1)throw new Error(`${f} found repeat map key`);let c=X(t,r);if(c===J)throw new Error(`${f} found map but not enough entries (got ${o} [no value], expected ${e.value})`);if(c===K)throw new Error(`${f} got unexpected break to map value`);yield[i,c]}}function Ao(e,t){let r=function(){if(r._called)throw new Error(`${f} tag decode() may only be called once`);r._called=!0;let n=X(e,t);if(n===J)throw new Error(`${f} tag content missing`);if(n===K)throw new Error(`${f} got unexpected break in tag content`);return n};return r.entries=function(){if(r._called)throw new Error(`${f} tag decode() may only be called once`);if(r._called=!0,e.done())throw new Error(`${f} tag content missing`);let n=e.next();if(!s.equals(n.type,s.map))throw new Error(`${f} entries() requires map content, got ${n.type.name}`);let o=[];for(let i of Eo(n,e,t))o.push(i);return o},r._called=!1,r}function X(e,t){if(e.done())return J;let r=e.next();if(s.equals(r.type,s.break))return K;if(r.type.terminal)return r.value;if(s.equals(r.type,s.array))return xo(r,e,t);if(s.equals(r.type,s.map))return bo(r,e,t);if(s.equals(r.type,s.tag)){if(t.tags&&typeof t.tags[r.value]=="function"){let n=Ao(e,t),o=t.tags[r.value](n);if(!n._called)throw new Error(`${f} tag decoder must call decode() or entries()`);return o}throw new Error(`${f} tag not supported (${r.value})`)}throw new Error("unsupported")}function qr(e,t){if(!(e instanceof Uint8Array))throw new Error(`${f} data to decode must be a Uint8Array`);t=Object.assign({},wo,t);let r=Kt(e),n=t.tokenizer||new Ge(r,t),o=X(n,t);if(o===J)throw new Error(`${f} did not find any content to decode`);if(o===K)throw new Error(`${f} got unexpected break`);return[o,e.subarray(n.pos())]}function pt(e,t){let[r,n]=qr(e,t);if(n.length>0)throw new Error(`${f} too many terminals, data makes no sense`);return r}var He=class e{constructor(t,r){if(typeof t!="number"||!Number.isInteger(t)||t<0)throw new TypeError("Tagged: tag must be a non-negative integer");this.tag=t,this.value=r}static decoder(t){return r=>new e(t,r())}static preserve(...t){let r={};for(let n of t)r[n]=e.decoder(n);return r}};Object.defineProperty(He.prototype,Symbol.toStringTag,{value:"Tagged"});var Gr=42;function Uo(e){return e instanceof ArrayBuffer?new Uint8Array(e,0,e.byteLength):e}function Io(e){if(e.asCID!==e&&e["/"]!==e.bytes)return null;let t=ee.asCID(e);if(!t)return null;let r=new Uint8Array(t.bytes.byteLength+1);return r.set(t.bytes,1),[new u(s.tag,Gr),new u(s.bytes,r)]}function Bo(){throw new Error("`undefined` is not supported by the IPLD Data Model and cannot be encoded")}function To(e){if(Number.isNaN(e))throw new Error("`NaN` is not supported by the IPLD Data Model and cannot be encoded");if(e===1/0||e===-1/0)throw new Error("`Infinity` and `-Infinity` is not supported by the IPLD Data Model and cannot be encoded");return null}function _o(e){for(let t of e.keys())if(typeof t!="string"||t.length===0)throw new Error("Non-string Map keys are not supported by the IPLD Data Model and cannot be encoded");return null}var ht={float64:!0,typeEncoders:{Map:_o,Object:Io,undefined:Bo,number:To}},vs={...ht,typeEncoders:{...ht.typeEncoders}};function So(e){let t=e();if(t[0]!==0)throw new Error("Invalid CID for CBOR tag 42; expected leading 0x00");return ee.decode(t.subarray(1))}var yt={allowIndefinite:!1,coerceUndefinedToNull:!0,allowNaN:!1,allowInfinity:!1,allowBigInt:!0,strict:!0,useMaps:!1,rejectDuplicateMapKeys:!0,tags:{[Gr]:So}},Us={...yt,tags:{...yt.tags}};var mt=113,Hr=e=>lt(e,ht),Jr=e=>pt(Uo(e),yt);function ko(e){return e[Symbol.asyncIterator]!=null}function Co(e){if(ko(e))return(async()=>{let n=new Uint8Array(0);for await(let o of e)n=nt([n,o],n.length+o.length);return n})();let t=[],r=0;for(let n of e)t.push(n),r+=n.byteLength;return nt(t,r)}var Kr=Co;var Je=class{components;constructor(t){this.components=t}async add(t,r={}){let n=Hr(t),o=await(r.hasher??Ot).digest(n),i=ee.createV1(mt,o);return await this.components.blockstore.put(i,n,r),i}async get(t,r={}){if(t.code!==mt)throw new Se("The passed CID had an incorrect codec, it may correspond to a non-DAG-CBOR block");let n=await Kr(this.components.blockstore.get(t,r));return Jr(n)}};function $o(e){return new Je(e)}return nn(Mo);})();
3
3
  return HeliaDagCbor}));
4
4
  //# sourceMappingURL=index.min.js.map