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