@helia/dag-cbor 6.0.4 → 6.0.5-0873bb5f

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