@helia/utils 2.4.2-11802dd6 → 2.4.2-1a2ebead

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.HeliaUtils = factory()}(typeof self !== 'undefined' ? self : this, function () {
2
- "use strict";var HeliaUtils=(()=>{var xl=Object.create;var Rr=Object.defineProperty;var bl=Object.getOwnPropertyDescriptor;var El=Object.getOwnPropertyNames;var _l=Object.getPrototypeOf,vl=Object.prototype.hasOwnProperty;var Ds=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),M=(t,e)=>{for(var r in e)Rr(t,r,{get:e[r],enumerable:!0})},Ps=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of El(e))!vl.call(t,o)&&o!==r&&Rr(t,o,{get:()=>e[o],enumerable:!(n=bl(e,o))||n.enumerable});return t};var $s=(t,e,r)=>(r=t!=null?xl(_l(t)):{},Ps(e||!t||!t.__esModule?Rr(r,"default",{value:t,enumerable:!0}):r,t)),kl=t=>Ps(Rr({},"__esModule",{value:!0}),t);var js=Ds((hg,Oo)=>{"use strict";var Al=Object.prototype.hasOwnProperty,K="~";function Kt(){}Object.create&&(Kt.prototype=Object.create(null),new Kt().__proto__||(K=!1));function Tl(t,e,r){this.fn=t,this.context=e,this.once=r||!1}function zs(t,e,r,n,o){if(typeof r!="function")throw new TypeError("The listener must be a function");var i=new Tl(r,n||t,o),s=K?K+e:e;return t._events[s]?t._events[s].fn?t._events[s]=[t._events[s],i]:t._events[s].push(i):(t._events[s]=i,t._eventsCount++),t}function Mr(t,e){--t._eventsCount===0?t._events=new Kt:delete t._events[e]}function V(){this._events=new Kt,this._eventsCount=0}V.prototype.eventNames=function(){var e=[],r,n;if(this._eventsCount===0)return e;for(n in r=this._events)Al.call(r,n)&&e.push(K?n.slice(1):n);return Object.getOwnPropertySymbols?e.concat(Object.getOwnPropertySymbols(r)):e};V.prototype.listeners=function(e){var r=K?K+e:e,n=this._events[r];if(!n)return[];if(n.fn)return[n.fn];for(var o=0,i=n.length,s=new Array(i);o<i;o++)s[o]=n[o].fn;return s};V.prototype.listenerCount=function(e){var r=K?K+e:e,n=this._events[r];return n?n.fn?1:n.length:0};V.prototype.emit=function(e,r,n,o,i,s){var a=K?K+e:e;if(!this._events[a])return!1;var c=this._events[a],l=arguments.length,p,m;if(c.fn){switch(c.once&&this.removeListener(e,c.fn,void 0,!0),l){case 1:return c.fn.call(c.context),!0;case 2:return c.fn.call(c.context,r),!0;case 3:return c.fn.call(c.context,r,n),!0;case 4:return c.fn.call(c.context,r,n,o),!0;case 5:return c.fn.call(c.context,r,n,o,i),!0;case 6:return c.fn.call(c.context,r,n,o,i,s),!0}for(m=1,p=new Array(l-1);m<l;m++)p[m-1]=arguments[m];c.fn.apply(c.context,p)}else{var x=c.length,k;for(m=0;m<x;m++)switch(c[m].once&&this.removeListener(e,c[m].fn,void 0,!0),l){case 1:c[m].fn.call(c[m].context);break;case 2:c[m].fn.call(c[m].context,r);break;case 3:c[m].fn.call(c[m].context,r,n);break;case 4:c[m].fn.call(c[m].context,r,n,o);break;default:if(!p)for(k=1,p=new Array(l-1);k<l;k++)p[k-1]=arguments[k];c[m].fn.apply(c[m].context,p)}}return!0};V.prototype.on=function(e,r,n){return zs(this,e,r,n,!1)};V.prototype.once=function(e,r,n){return zs(this,e,r,n,!0)};V.prototype.removeListener=function(e,r,n,o){var i=K?K+e:e;if(!this._events[i])return this;if(!r)return Mr(this,i),this;var s=this._events[i];if(s.fn)s.fn===r&&(!o||s.once)&&(!n||s.context===n)&&Mr(this,i);else{for(var a=0,c=[],l=s.length;a<l;a++)(s[a].fn!==r||o&&!s[a].once||n&&s[a].context!==n)&&c.push(s[a]);c.length?this._events[i]=c.length===1?c[0]:c:Mr(this,i)}return this};V.prototype.removeAllListeners=function(e){var r;return e?(r=K?K+e:e,this._events[r]&&Mr(this,r)):(this._events=new Kt,this._eventsCount=0),this};V.prototype.off=V.prototype.removeListener;V.prototype.addListener=V.prototype.on;V.prefixed=K;V.EventEmitter=V;typeof Oo<"u"&&(Oo.exports=V)});var pa=Ds((Iy,ha)=>{ha.exports=function(t){if(!t)throw Error("hashlru must have a max value, of type number, greater than 0");var e=0,r=Object.create(null),n=Object.create(null);function o(i,s){r[i]=s,e++,e>=t&&(e=0,n=r,r=Object.create(null))}return{has:function(i){return r[i]!==void 0||n[i]!==void 0},remove:function(i){r[i]!==void 0&&(r[i]=void 0),n[i]!==void 0&&(n[i]=void 0)},get:function(i){var s=r[i];if(s!==void 0)return s;if((s=n[i])!==void 0)return o(i,s),s},set:function(i,s){r[i]!==void 0?r[i]=s:o(i,s)},clear:function(){r=Object.create(null),n=Object.create(null)}}}});var og={};M(og,{AbstractSession:()=>Mo,Helia:()=>Rs,breadthFirstWalker:()=>yl,depthFirstWalker:()=>gl,naturalOrderWalker:()=>wl});var Ms=Symbol.for("@libp2p/content-routing");var xe=class extends Error{static name="AbortError";constructor(e="The operation was aborted"){super(e),this.name="AbortError"}};var yt=class extends Error{static name="InvalidParametersError";constructor(e="Invalid parameters"){super(e),this.name="InvalidParametersError"}};var Dr=class extends Error{static name="NotFoundError";constructor(e="Not found"){super(e),this.name="NotFoundError"}};var Pr=class extends Error{static name="InvalidMultihashError";constructor(e="Invalid Multihash"){super(e),this.name="InvalidMultihashError"}};var Os=Symbol.for("@libp2p/peer-routing");function Fs(t){return t!=null&&typeof t.start=="function"&&typeof t.stop=="function"}async function We(...t){let e=[];for(let r of t)Fs(r)&&e.push(r);await Promise.all(e.map(async r=>{r.beforeStart!=null&&await r.beforeStart()})),await Promise.all(e.map(async r=>{await r.start()})),await Promise.all(e.map(async r=>{r.afterStart!=null&&await r.afterStart()}))}async function Ge(...t){let e=[];for(let r of t)Fs(r)&&e.push(r);await Promise.all(e.map(async r=>{r.beforeStop!=null&&await r.beforeStop()})),await Promise.all(e.map(async r=>{await r.stop()})),await Promise.all(e.map(async r=>{r.afterStop!=null&&await r.afterStop()}))}var le=class extends EventTarget{#e=new Map;constructor(){super()}listenerCount(e){let r=this.#e.get(e);return r==null?0:r.length}addEventListener(e,r,n){super.addEventListener(e,r,n);let o=this.#e.get(e);o==null&&(o=[],this.#e.set(e,o)),o.push({callback:r,once:(n!==!0&&n!==!1&&n?.once)??!1})}removeEventListener(e,r,n){super.removeEventListener(e.toString(),r??null,n);let o=this.#e.get(e);o!=null&&(o=o.filter(({callback:i})=>i!==r),this.#e.set(e,o))}dispatchEvent(e){let r=super.dispatchEvent(e),n=this.#e.get(e.type);return n==null||(n=n.filter(({once:o})=>!o),this.#e.set(e.type,n)),r}safeDispatchEvent(e,r={}){return this.dispatchEvent(new CustomEvent(e,r))}};var A=class extends Event{type;detail;constructor(e,r){super(e),this.type=e,this.detail=r}};var $r=class extends AggregateError{static name="DNSQueryFailedError";name="DNSQueryFailedError"};var Fo=$s(js(),1);var zo=class t extends Error{name="TimeoutError";constructor(e,r){super(e,r),Error.captureStackTrace?.(this,t)}},qs=t=>t.reason??new DOMException("This operation was aborted.","AbortError");function Wt(t,e){let{milliseconds:r,fallback:n,message:o,customTimers:i={setTimeout,clearTimeout},signal:s}=e,a,c,p=new Promise((m,x)=>{if(typeof r!="number"||Math.sign(r)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${r}\``);if(s?.aborted){x(qs(s));return}if(s&&(c=()=>{x(qs(s))},s.addEventListener("abort",c,{once:!0})),t.then(m,x),r===Number.POSITIVE_INFINITY)return;let k=new zo;a=i.setTimeout.call(void 0,()=>{if(n){try{m(n())}catch(I){x(I)}return}typeof t.cancel=="function"&&t.cancel(),o===!1?m():o instanceof Error?x(o):(k.message=o??`Promise timed out after ${r} milliseconds`,x(k))},r)}).finally(()=>{p.clear(),c&&s&&s.removeEventListener("abort",c)});return p.clear=()=>{i.clearTimeout.call(void 0,a),a=void 0},p}function jo(t,e,r){let n=0,o=t.length;for(;o>0;){let i=Math.trunc(o/2),s=n+i;r(t[s],e)<=0?(n=++s,o-=i+1):o=i}return n}var wt=class{#e=[];enqueue(e,r){let{priority:n=0,id:o}=r??{},i={priority:n,id:o,run:e};if(this.size===0||this.#e[this.size-1].priority>=n){this.#e.push(i);return}let s=jo(this.#e,i,(a,c)=>c.priority-a.priority);this.#e.splice(s,0,i)}setPriority(e,r){let n=this.#e.findIndex(i=>i.id===e);if(n===-1)throw new ReferenceError(`No promise function with the id "${e}" exists in the queue.`);let[o]=this.#e.splice(n,1);this.enqueue(o.run,{priority:r,id:e})}remove(e){let r=this.#e.findIndex(n=>typeof e=="string"?n.id===e:n.run===e);r!==-1&&this.#e.splice(r,1)}dequeue(){return this.#e.shift()?.run}filter(e){return this.#e.filter(r=>r.priority===e.priority).map(r=>r.run)}get size(){return this.#e.length}};var Gt=class extends Fo.default{#e;#o;#a=0;#h;#m=!1;#x=!1;#c;#I=0;#b=0;#u;#f;#s;#i=[];#n=0;#t;#S;#r=0;#g;#l;#B=1n;#y=new Map;#E=new Set;timeout;constructor(e){if(super(),e={carryoverIntervalCount:!1,intervalCap:Number.POSITIVE_INFINITY,interval:0,concurrency:Number.POSITIVE_INFINITY,autoStart:!0,queueClass:wt,strict:!1,...e},!(typeof e.intervalCap=="number"&&e.intervalCap>=1))throw new TypeError(`Expected \`intervalCap\` to be a number from 1 and up, got \`${e.intervalCap?.toString()??""}\` (${typeof e.intervalCap})`);if(e.interval===void 0||!(Number.isFinite(e.interval)&&e.interval>=0))throw new TypeError(`Expected \`interval\` to be a finite number >= 0, got \`${e.interval?.toString()??""}\` (${typeof e.interval})`);if(e.strict&&e.interval===0)throw new TypeError("The `strict` option requires a non-zero `interval`");if(e.strict&&e.intervalCap===Number.POSITIVE_INFINITY)throw new TypeError("The `strict` option requires a finite `intervalCap`");if(this.#e=e.carryoverIntervalCount??e.carryoverConcurrencyCount??!1,this.#o=e.intervalCap===Number.POSITIVE_INFINITY||e.interval===0,this.#h=e.intervalCap,this.#c=e.interval,this.#s=e.strict,this.#t=new e.queueClass,this.#S=e.queueClass,this.concurrency=e.concurrency,e.timeout!==void 0&&!(Number.isFinite(e.timeout)&&e.timeout>0))throw new TypeError(`Expected \`timeout\` to be a positive finite number, got \`${e.timeout}\` (${typeof e.timeout})`);this.timeout=e.timeout,this.#l=e.autoStart===!1,this.#z()}#_(e){for(;this.#n<this.#i.length;){let n=this.#i[this.#n];if(n!==void 0&&e-n>=this.#c)this.#n++;else break}(this.#n>100&&this.#n>this.#i.length/2||this.#n===this.#i.length)&&(this.#i=this.#i.slice(this.#n),this.#n=0)}#R(e){this.#s?this.#i.push(e):this.#a++}#D(){this.#s?this.#i.length>this.#n&&this.#i.pop():this.#a>0&&this.#a--}#v(){return this.#i.length-this.#n}get#P(){return this.#o?!0:this.#s?this.#v()<this.#h:this.#a<this.#h}get#$(){return this.#r<this.#g}#M(){this.#r--,this.#r===0&&this.emit("pendingZero"),this.#w(),this.emit("next")}#O(){this.#f=void 0,this.#C(),this.#N()}#F(e){if(this.#s){if(this.#_(e),this.#v()>=this.#h){let n=this.#i[this.#n],o=this.#c-(e-n);return this.#k(o),!0}return!1}if(this.#u===void 0){let r=this.#I-e;if(r<0){if(this.#b>0){let n=e-this.#b;if(n<this.#c)return this.#k(this.#c-n),!0}this.#a=this.#e?this.#r:0}else return this.#k(r),!0}return!1}#k(e){this.#f===void 0&&(this.#f=setTimeout(()=>{this.#O()},e))}#A(){this.#u&&(clearInterval(this.#u),this.#u=void 0)}#U(){this.#f&&(clearTimeout(this.#f),this.#f=void 0)}#w(){if(this.#t.size===0){if(this.#A(),this.emit("empty"),this.#r===0){if(this.#U(),this.#s&&this.#n>0){let r=Date.now();this.#_(r)}this.emit("idle")}return!1}let e=!1;if(!this.#l){let r=Date.now(),n=!this.#F(r);if(this.#P&&this.#$){let o=this.#t.dequeue();this.#o||(this.#R(r),this.#p()),this.emit("active"),o(),n&&this.#N(),e=!0}}return e}#N(){this.#o||this.#u!==void 0||this.#s||(this.#u=setInterval(()=>{this.#C()},this.#c),this.#I=Date.now()+this.#c)}#C(){this.#s||(this.#a===0&&this.#r===0&&this.#u&&this.#A(),this.#a=this.#e?this.#r:0),this.#T(),this.#p()}#T(){for(;this.#w(););}get concurrency(){return this.#g}set concurrency(e){if(!(typeof e=="number"&&e>=1))throw new TypeError(`Expected \`concurrency\` to be a number from 1 and up, got \`${e}\` (${typeof e})`);this.#g=e,this.#T()}setPriority(e,r){if(typeof r!="number"||!Number.isFinite(r))throw new TypeError(`Expected \`priority\` to be a finite number, got \`${r}\` (${typeof r})`);this.#t.setPriority(e,r)}async add(e,r={}){return r={timeout:this.timeout,...r,id:r.id??(this.#B++).toString()},new Promise((n,o)=>{let i=Symbol(`task-${r.id}`),s=()=>{},a=async()=>{s(),this.#r++,this.#y.set(i,{id:r.id,priority:r.priority??0,startTime:Date.now(),timeout:r.timeout});let l;try{try{r.signal?.throwIfAborted()}catch(x){throw this.#j(),this.#y.delete(i),x}this.#b=Date.now();let p=e({signal:r.signal});if(r.timeout&&(p=Wt(Promise.resolve(p),{milliseconds:r.timeout,message:`Task timed out after ${r.timeout}ms (queue has ${this.#r} running, ${this.#t.size} waiting)`})),r.signal){let{signal:x}=r;p=Promise.race([p,new Promise((k,I)=>{l=()=>{I(x.reason)},x.addEventListener("abort",l,{once:!0})})])}let m=await p;n(m),this.emit("completed",m)}catch(p){o(p),this.emit("error",p)}finally{l&&r.signal?.removeEventListener("abort",l),this.#y.delete(i),queueMicrotask(()=>{this.#M()})}};this.#t.enqueue(a,r);let c=()=>{if(this.#t instanceof wt){this.#t.remove(a);return}this.#t.remove?.(r.id)};if(r.signal){let{signal:l}=r,p=()=>{s(),c(),o(l.reason),this.#w(),this.emit("next")};if(s=()=>{l.removeEventListener("abort",p),this.#E.delete(s)},l.aborted){p();return}l.addEventListener("abort",p,{once:!0}),this.#E.add(s)}this.emit("add"),this.#w()})}async addAll(e,r){return Promise.all(e.map(async n=>this.add(n,r)))}start(){return this.#l?(this.#l=!1,this.#T(),this):this}pause(){this.#l=!0}clear(){for(let e of this.#E)e();this.#t=new this.#S,this.#A(),this.#L(),this.emit("empty"),this.#r===0&&(this.#U(),this.emit("idle")),this.emit("next")}async onEmpty(){this.#t.size!==0&&await this.#d("empty")}async onSizeLessThan(e){this.#t.size<e||await this.#d("next",()=>this.#t.size<e)}async onIdle(){this.#r===0&&this.#t.size===0||await this.#d("idle")}async onPendingZero(){this.#r!==0&&await this.#d("pendingZero")}async onRateLimit(){this.isRateLimited||await this.#d("rateLimit")}async onRateLimitCleared(){this.isRateLimited&&await this.#d("rateLimitCleared")}onError(){return new Promise((e,r)=>{let n=o=>{this.off("error",n),r(o)};this.on("error",n)})}async#d(e,r){return new Promise(n=>{let o=()=>{r&&!r()||(this.off(e,o),n())};this.on(e,o)})}get size(){return this.#t.size}sizeBy(e){return this.#t.filter(e).length}get pending(){return this.#r}get isPaused(){return this.#l}#z(){this.#o||(this.on("add",()=>{this.#t.size>0&&this.#p()}),this.on("next",()=>{this.#p()}))}#p(){this.#o||this.#x||(this.#x=!0,queueMicrotask(()=>{this.#x=!1,this.#L()}))}#j(){this.#o||(this.#D(),this.#p())}#L(){let e=this.#m;if(this.#o||this.#t.size===0){e&&(this.#m=!1,this.emit("rateLimitCleared"));return}let r;if(this.#s){let o=Date.now();this.#_(o),r=this.#v()}else r=this.#a;let n=r>=this.#h;n!==e&&(this.#m=n,this.emit(n?"rateLimit":"rateLimitCleared"))}get isRateLimited(){return this.#m}get isSaturated(){return this.#r===this.#g&&this.#t.size>0||this.isRateLimited&&this.#t.size>0}get runningTasks(){return[...this.#y.values()].map(e=>({...e}))}};function Or(t){let e=[be.A];return t==null?e:Array.isArray(t)?t.length===0?e:t:[t]}var Go={};M(Go,{base10:()=>Bl});var Ag=new Uint8Array(0);function Vs(t,e){if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;for(let r=0;r<t.byteLength;r++)if(t[r]!==e[r])return!1;return!0}function Ee(t){if(t instanceof Uint8Array&&t.constructor.name==="Uint8Array")return t;if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.isView(t))return new Uint8Array(t.buffer,t.byteOffset,t.byteLength);throw new Error("Unknown type, must be binary type")}function Hs(t){return new TextEncoder().encode(t)}function Ks(t){return new TextDecoder().decode(t)}function Il(t,e){if(t.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),n=0;n<r.length;n++)r[n]=255;for(var o=0;o<t.length;o++){var i=t.charAt(o),s=i.charCodeAt(0);if(r[s]!==255)throw new TypeError(i+" is ambiguous");r[s]=o}var a=t.length,c=t.charAt(0),l=Math.log(a)/Math.log(256),p=Math.log(256)/Math.log(a);function m(I){if(I instanceof Uint8Array||(ArrayBuffer.isView(I)?I=new Uint8Array(I.buffer,I.byteOffset,I.byteLength):Array.isArray(I)&&(I=Uint8Array.from(I))),!(I instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(I.length===0)return"";for(var D=0,S=0,$=0,H=I.length;$!==H&&I[$]===0;)$++,D++;for(var q=(H-$)*p+1>>>0,Q=new Uint8Array(q);$!==H;){for(var fe=I[$],Ke=0,we=q-1;(fe!==0||Ke<S)&&we!==-1;we--,Ke++)fe+=256*Q[we]>>>0,Q[we]=fe%a>>>0,fe=fe/a>>>0;if(fe!==0)throw new Error("Non-zero carry");S=Ke,$++}for(var $e=q-S;$e!==q&&Q[$e]===0;)$e++;for(var Br=c.repeat(D);$e<q;++$e)Br+=t.charAt(Q[$e]);return Br}function x(I){if(typeof I!="string")throw new TypeError("Expected String");if(I.length===0)return new Uint8Array;var D=0;if(I[D]!==" "){for(var S=0,$=0;I[D]===c;)S++,D++;for(var H=(I.length-D)*l+1>>>0,q=new Uint8Array(H);I[D];){var Q=r[I.charCodeAt(D)];if(Q===255)return;for(var fe=0,Ke=H-1;(Q!==0||fe<$)&&Ke!==-1;Ke--,fe++)Q+=a*q[Ke]>>>0,q[Ke]=Q%256>>>0,Q=Q/256>>>0;if(Q!==0)throw new Error("Non-zero carry");$=fe,D++}if(I[D]!==" "){for(var we=H-$;we!==H&&q[we]===0;)we++;for(var $e=new Uint8Array(S+(H-we)),Br=S;we!==H;)$e[Br++]=q[we++];return $e}}}function k(I){var D=x(I);if(D)return D;throw new Error(`Non-${e} character`)}return{encode:m,decodeUnsafe:x,decode:k}}var Sl=Il,Ul=Sl,Ws=Ul;var Vo=class{name;prefix;baseEncode;constructor(e,r,n){this.name=e,this.prefix=r,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},Ho=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,r,n){this.name=e,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(e){if(typeof e=="string"){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(e){return Gs(this,e)}},Ko=class{decoders;constructor(e){this.decoders=e}or(e){return Gs(this,e)}decode(e){let r=e[0],n=this.decoders[r];if(n!=null)return n.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function Gs(t,e){return new Ko({...t.decoders??{[t.prefix]:t},...e.decoders??{[e.prefix]:e}})}var Wo=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,r,n,o){this.name=e,this.prefix=r,this.baseEncode=n,this.baseDecode=o,this.encoder=new Vo(e,r,n),this.decoder=new Ho(e,r,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function xt({name:t,prefix:e,encode:r,decode:n}){return new Wo(t,e,r,n)}function Qe({name:t,prefix:e,alphabet:r}){let{encode:n,decode:o}=Ws(r,t);return xt({prefix:e,name:t,encode:n,decode:i=>Ee(o(i))})}function Nl(t,e,r,n){let o=t.length;for(;t[o-1]==="=";)--o;let i=new Uint8Array(o*r/8|0),s=0,a=0,c=0;for(let l=0;l<o;++l){let p=e[t[l]];if(p===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|p,s+=r,s>=8&&(s-=8,i[c++]=255&a>>s)}if(s>=r||(255&a<<8-s)!==0)throw new SyntaxError("Unexpected end of data");return i}function Cl(t,e,r){let n=e[e.length-1]==="=",o=(1<<r)-1,i="",s=0,a=0;for(let c=0;c<t.length;++c)for(a=a<<8|t[c],s+=8;s>r;)s-=r,i+=e[o&a>>s];if(s!==0&&(i+=e[o&a<<r-s]),n)for(;(i.length*r&7)!==0;)i+="=";return i}function Ll(t){let e={};for(let r=0;r<t.length;++r)e[t[r]]=r;return e}function P({name:t,prefix:e,bitsPerChar:r,alphabet:n}){let o=Ll(n);return xt({prefix:e,name:t,encode(i){return Cl(i,n,r)},decode(i){return Nl(i,o,r,t)}})}var Bl=Qe({prefix:"9",name:"base10",alphabet:"0123456789"});var Qo={};M(Qo,{base16:()=>Rl,base16upper:()=>Dl});var Rl=P({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Dl=P({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Jo={};M(Jo,{base2:()=>Pl});var Pl=P({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Yo={};M(Yo,{base256emoji:()=>zl});var Qs=Array.from("\u{1F680}\u{1FA90}\u2604\u{1F6F0}\u{1F30C}\u{1F311}\u{1F312}\u{1F313}\u{1F314}\u{1F315}\u{1F316}\u{1F317}\u{1F318}\u{1F30D}\u{1F30F}\u{1F30E}\u{1F409}\u2600\u{1F4BB}\u{1F5A5}\u{1F4BE}\u{1F4BF}\u{1F602}\u2764\u{1F60D}\u{1F923}\u{1F60A}\u{1F64F}\u{1F495}\u{1F62D}\u{1F618}\u{1F44D}\u{1F605}\u{1F44F}\u{1F601}\u{1F525}\u{1F970}\u{1F494}\u{1F496}\u{1F499}\u{1F622}\u{1F914}\u{1F606}\u{1F644}\u{1F4AA}\u{1F609}\u263A\u{1F44C}\u{1F917}\u{1F49C}\u{1F614}\u{1F60E}\u{1F607}\u{1F339}\u{1F926}\u{1F389}\u{1F49E}\u270C\u2728\u{1F937}\u{1F631}\u{1F60C}\u{1F338}\u{1F64C}\u{1F60B}\u{1F497}\u{1F49A}\u{1F60F}\u{1F49B}\u{1F642}\u{1F493}\u{1F929}\u{1F604}\u{1F600}\u{1F5A4}\u{1F603}\u{1F4AF}\u{1F648}\u{1F447}\u{1F3B6}\u{1F612}\u{1F92D}\u2763\u{1F61C}\u{1F48B}\u{1F440}\u{1F62A}\u{1F611}\u{1F4A5}\u{1F64B}\u{1F61E}\u{1F629}\u{1F621}\u{1F92A}\u{1F44A}\u{1F973}\u{1F625}\u{1F924}\u{1F449}\u{1F483}\u{1F633}\u270B\u{1F61A}\u{1F61D}\u{1F634}\u{1F31F}\u{1F62C}\u{1F643}\u{1F340}\u{1F337}\u{1F63B}\u{1F613}\u2B50\u2705\u{1F97A}\u{1F308}\u{1F608}\u{1F918}\u{1F4A6}\u2714\u{1F623}\u{1F3C3}\u{1F490}\u2639\u{1F38A}\u{1F498}\u{1F620}\u261D\u{1F615}\u{1F33A}\u{1F382}\u{1F33B}\u{1F610}\u{1F595}\u{1F49D}\u{1F64A}\u{1F639}\u{1F5E3}\u{1F4AB}\u{1F480}\u{1F451}\u{1F3B5}\u{1F91E}\u{1F61B}\u{1F534}\u{1F624}\u{1F33C}\u{1F62B}\u26BD\u{1F919}\u2615\u{1F3C6}\u{1F92B}\u{1F448}\u{1F62E}\u{1F646}\u{1F37B}\u{1F343}\u{1F436}\u{1F481}\u{1F632}\u{1F33F}\u{1F9E1}\u{1F381}\u26A1\u{1F31E}\u{1F388}\u274C\u270A\u{1F44B}\u{1F630}\u{1F928}\u{1F636}\u{1F91D}\u{1F6B6}\u{1F4B0}\u{1F353}\u{1F4A2}\u{1F91F}\u{1F641}\u{1F6A8}\u{1F4A8}\u{1F92C}\u2708\u{1F380}\u{1F37A}\u{1F913}\u{1F619}\u{1F49F}\u{1F331}\u{1F616}\u{1F476}\u{1F974}\u25B6\u27A1\u2753\u{1F48E}\u{1F4B8}\u2B07\u{1F628}\u{1F31A}\u{1F98B}\u{1F637}\u{1F57A}\u26A0\u{1F645}\u{1F61F}\u{1F635}\u{1F44E}\u{1F932}\u{1F920}\u{1F927}\u{1F4CC}\u{1F535}\u{1F485}\u{1F9D0}\u{1F43E}\u{1F352}\u{1F617}\u{1F911}\u{1F30A}\u{1F92F}\u{1F437}\u260E\u{1F4A7}\u{1F62F}\u{1F486}\u{1F446}\u{1F3A4}\u{1F647}\u{1F351}\u2744\u{1F334}\u{1F4A3}\u{1F438}\u{1F48C}\u{1F4CD}\u{1F940}\u{1F922}\u{1F445}\u{1F4A1}\u{1F4A9}\u{1F450}\u{1F4F8}\u{1F47B}\u{1F910}\u{1F92E}\u{1F3BC}\u{1F975}\u{1F6A9}\u{1F34E}\u{1F34A}\u{1F47C}\u{1F48D}\u{1F4E3}\u{1F942}"),$l=Qs.reduce((t,e,r)=>(t[r]=e,t),[]),Ml=Qs.reduce((t,e,r)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return t[n]=r,t},[]);function Ol(t){return t.reduce((e,r)=>(e+=$l[r],e),"")}function Fl(t){let e=[];for(let r of t){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=Ml[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);e.push(o)}return new Uint8Array(e)}var zl=xt({prefix:"\u{1F680}",name:"base256emoji",encode:Ol,decode:Fl});var Xo={};M(Xo,{base32:()=>bt,base32hex:()=>Hl,base32hexpad:()=>Wl,base32hexpadupper:()=>Gl,base32hexupper:()=>Kl,base32pad:()=>ql,base32padupper:()=>Vl,base32upper:()=>jl,base32z:()=>Ql});var bt=P({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),jl=P({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),ql=P({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Vl=P({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Hl=P({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Kl=P({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Wl=P({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Gl=P({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Ql=P({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Zo={};M(Zo,{base36:()=>Me,base36upper:()=>Jl});var Me=Qe({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Jl=Qe({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var ei={};M(ei,{base58btc:()=>Ce,base58flickr:()=>Yl});var Ce=Qe({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Yl=Qe({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var ti={};M(ti,{base64:()=>Et,base64pad:()=>Xl,base64url:()=>Zl,base64urlpad:()=>ed});var Et=P({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Xl=P({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Zl=P({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),ed=P({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var ri={};M(ri,{base8:()=>td});var td=P({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var ni={};M(ni,{identity:()=>rd});var rd=xt({prefix:"\0",name:"identity",encode:t=>Ks(t),decode:t=>Hs(t)});var Fr={};M(Fr,{code:()=>oi,decode:()=>ad,encode:()=>sd,name:()=>id});var nd=new TextEncoder,od=new TextDecoder,id="json",oi=512;function sd(t){return nd.encode(JSON.stringify(t))}function ad(t){return JSON.parse(od.decode(t))}var zr={};M(zr,{code:()=>ii,decode:()=>fd,encode:()=>ud,name:()=>cd});var cd="raw",ii=85;function ud(t){return Ee(t)}function fd(t){return Ee(t)}var ai={};M(ai,{identity:()=>qr});var ld=Xs,Js=128,dd=127,hd=~dd,pd=Math.pow(2,31);function Xs(t,e,r){e=e||[],r=r||0;for(var n=r;t>=pd;)e[r++]=t&255|Js,t/=128;for(;t&hd;)e[r++]=t&255|Js,t>>>=7;return e[r]=t|0,Xs.bytes=r-n+1,e}var md=si,gd=128,Ys=127;function si(t,n){var r=0,n=n||0,o=0,i=n,s,a=t.length;do{if(i>=a)throw si.bytes=0,new RangeError("Could not decode varint");s=t[i++],r+=o<28?(s&Ys)<<o:(s&Ys)*Math.pow(2,o),o+=7}while(s>=gd);return si.bytes=i-n,r}var yd=Math.pow(2,7),wd=Math.pow(2,14),xd=Math.pow(2,21),bd=Math.pow(2,28),Ed=Math.pow(2,35),_d=Math.pow(2,42),vd=Math.pow(2,49),kd=Math.pow(2,56),Ad=Math.pow(2,63),Td=function(t){return t<yd?1:t<wd?2:t<xd?3:t<bd?4:t<Ed?5:t<_d?6:t<vd?7:t<kd?8:t<Ad?9:10},Id={encode:ld,decode:md,encodingLength:Td},Sd=Id,Qt=Sd;function Jt(t,e=0){return[Qt.decode(t,e),Qt.decode.bytes]}function _t(t,e,r=0){return Qt.encode(t,e,r),e}function vt(t){return Qt.encodingLength(t)}function At(t,e){let r=e.byteLength,n=vt(t),o=n+vt(r),i=new Uint8Array(o+r);return _t(t,i,0),_t(r,i,n),i.set(e,o),new kt(t,r,e,i)}function Zs(t){let e=Ee(t),[r,n]=Jt(e),[o,i]=Jt(e.subarray(n)),s=e.subarray(n+i);if(s.byteLength!==o)throw new Error("Incorrect length");return new kt(r,o,s,e)}function ea(t,e){if(t===e)return!0;{let r=e;return t.code===r.code&&t.size===r.size&&r.bytes instanceof Uint8Array&&Vs(t.bytes,r.bytes)}}var kt=class{code;size;digest;bytes;constructor(e,r,n,o){this.code=e,this.size=r,this.digest=n,this.bytes=o}};var ta=0,Ud="identity",ra=Ee;function Nd(t,e){if(e?.truncate!=null&&e.truncate!==t.byteLength){if(e.truncate<0||e.truncate>t.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${t.byteLength}`);t=t.subarray(0,e.truncate)}return At(ta,ra(t))}var qr={code:ta,name:Ud,encode:ra,digest:Nd};var fi={};M(fi,{sha256:()=>Vr,sha512:()=>Hr});var Cd=20;function ui({name:t,code:e,encode:r,minDigestLength:n,maxDigestLength:o}){return new ci(t,e,r,n,o)}var ci=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,r,n,o,i){this.name=e,this.code=r,this.encode=n,this.minDigestLength=o??Cd,this.maxDigestLength=i}digest(e,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(e instanceof Uint8Array){let n=this.encode(e);return n instanceof Uint8Array?na(n,this.code,r?.truncate):n.then(o=>na(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function na(t,e,r){if(r!=null&&r!==t.byteLength){if(r>t.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${t.byteLength}`);t=t.subarray(0,r)}return At(e,t)}function ia(t){return async e=>new Uint8Array(await crypto.subtle.digest(t,e))}var Vr=ui({name:"sha2-256",code:18,encode:ia("SHA-256")}),Hr=ui({name:"sha2-512",code:19,encode:ia("SHA-512")});function sa(t,e){let{bytes:r,version:n}=t;switch(n){case 0:return Bd(r,li(t),e??Ce.encoder);default:return Rd(r,li(t),e??bt.encoder)}}var aa=new WeakMap;function li(t){let e=aa.get(t);if(e==null){let r=new Map;return aa.set(t,r),r}return e}var L=class t{code;version;multihash;bytes;"/";constructor(e,r,n,o){this.code=r,this.version=e,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:e,multihash:r}=this;if(e!==Xt)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==Dd)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return t.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:e,digest:r}=this.multihash,n=At(e,r);return t.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(e){return t.equals(this,e)}static equals(e,r){let n=r;return n!=null&&e.code===n.code&&e.version===n.version&&ea(e.multihash,n.multihash)}toString(e){return sa(this,e)}toJSON(){return{"/":sa(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(e){if(e==null)return null;let r=e;if(r instanceof t)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:o,multihash:i,bytes:s}=r;return new t(n,o,i,s??ca(n,o,i.bytes))}else if(r[Pd]===!0){let{version:n,multihash:o,code:i}=r,s=Zs(o);return t.create(n,i,s)}else return null}static create(e,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(e){case 0:{if(r!==Xt)throw new Error(`Version 0 CID must use dag-pb (code: ${Xt}) block encoding`);return new t(e,r,n,n.bytes)}case 1:{let o=ca(e,r,n.bytes);return new t(e,r,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return t.create(0,Xt,e)}static createV1(e,r){return t.create(1,e,r)}static decode(e){let[r,n]=t.decodeFirst(e);if(n.length!==0)throw new Error("Incorrect length");return r}static decodeFirst(e){let r=t.inspectBytes(e),n=r.size-r.multihashSize,o=Ee(e.subarray(n,n+r.multihashSize));if(o.byteLength!==r.multihashSize)throw new Error("Incorrect length");let i=o.subarray(r.multihashSize-r.digestSize),s=new kt(r.multihashCode,r.digestSize,i,o);return[r.version===0?t.createV0(s):t.createV1(r.codec,s),e.subarray(r.size)]}static inspectBytes(e){let r=0,n=()=>{let[m,x]=Jt(e.subarray(r));return r+=x,m},o=n(),i=Xt;if(o===18?(o=0,r=0):i=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let s=r,a=n(),c=n(),l=r+c,p=l-s;return{version:o,codec:i,multihashCode:a,digestSize:c,multihashSize:p,size:l}}static parse(e,r){let[n,o]=Ld(e,r),i=t.decode(o);if(i.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return li(i).set(n,e),i}};function Ld(t,e){switch(t[0]){case"Q":{let r=e??Ce;return[Ce.prefix,r.decode(`${Ce.prefix}${t}`)]}case Ce.prefix:{let r=e??Ce;return[Ce.prefix,r.decode(t)]}case bt.prefix:{let r=e??bt;return[bt.prefix,r.decode(t)]}case Me.prefix:{let r=e??Me;return[Me.prefix,r.decode(t)]}default:{if(e==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[t[0],e.decode(t)]}}}function Bd(t,e,r){let{prefix:n}=r;if(n!==Ce.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let o=e.get(n);if(o==null){let i=r.encode(t).slice(1);return e.set(n,i),i}else return o}function Rd(t,e,r){let{prefix:n}=r,o=e.get(n);if(o==null){let i=r.encode(t);return e.set(n,i),i}else return o}var Xt=112,Dd=18;function ca(t,e,r){let n=vt(t),o=n+vt(e),i=new Uint8Array(o+r.byteLength);return _t(t,i,0),_t(e,i,n),i.set(r,o),i}var Pd=Symbol.for("@ipld/js-cid/CID");var di={...ni,...Jo,...ri,...Go,...Qo,...Xo,...Zo,...ei,...ti,...Yo},cy={...fi,...ai};function ua(t=0){return new Uint8Array(t)}function Kr(t=0){return new Uint8Array(t)}function la(t,e,r,n){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:r},decoder:{decode:n}}}var fa=la("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),hi=la("ascii","a",t=>{let e="a";for(let r=0;r<t.length;r++)e+=String.fromCharCode(t[r]);return e},t=>{t=t.substring(1);let e=Kr(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}),$d={utf8:fa,"utf-8":fa,hex:di.base16,latin1:hi,ascii:hi,binary:hi,...di},Wr=$d;function Je(t,e="utf8"){let r=Wr[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.encoder.encode(t).substring(1)}var pi=60;function Gr(t){return{Status:t.Status??0,TC:t.TC??t.flag_tc??!1,RD:t.RD??t.flag_rd??!1,RA:t.RA??t.flag_ra??!1,AD:t.AD??t.flag_ad??!1,CD:t.CD??t.flag_cd??!1,Question:(t.Question??t.questions??[]).map(e=>({name:e.name,type:be[e.type]})),Answer:(t.Answer??t.answers??[]).map(e=>({name:e.name,type:be[e.type],TTL:e.TTL??e.ttl??pi,data:e.data instanceof Uint8Array?Je(e.data):e.data}))}}var Md=4;function mi(t,e={}){let r=new Gt({concurrency:e.queryConcurrency??Md});return async(n,o={})=>{let i=o?.logger?.forComponent("dns:dns-json-over-https"),s=new URLSearchParams;s.set("name",n),Or(o.types).forEach(c=>{s.append("type",be[c])}),o.onProgress?.(new A("dns:query",n)),i?.("GET %s",`${t}?${s}`);let a=await r.add(async()=>{let c=await fetch(`${t}?${s}`,{headers:{accept:"application/dns-json"},signal:o?.signal});if(i?.("GET %s %d",c.url,c.status),c.status!==200)throw new Error(`Unexpected HTTP status: ${c.status} - ${c.statusText}`);let l=Gr(await c.json());return o.onProgress?.(new A("dns:response",l)),l},{signal:o.signal});if(a==null)throw new Error("No DNS response received");return a}}function da(){return[mi("https://cloudflare-dns.com/dns-query"),mi("https://dns.google/resolve")]}var ma=$s(pa(),1);var gi=class{lru;constructor(e){this.lru=(0,ma.default)(e)}get(e,r){let n=!0,o=[];for(let i of r){let s=this.getAnswers(e,i);if(s.length===0){n=!1;break}o.push(...s)}if(n)return Gr({answers:o})}getAnswers(e,r){let n=`${e.toLowerCase()}-${r}`,o=this.lru.get(n);if(o!=null){let i=o.filter(s=>s.expires>Date.now()).map(({expires:s,value:a})=>({...a,TTL:Math.round((s-Date.now())/1e3),type:be[a.type]}));return i.length===0&&this.lru.remove(n),i}return[]}add(e,r){let n=`${e.toLowerCase()}-${r.type}`,o=this.lru.get(n)??[];o.push({expires:Date.now()+(r.TTL??pi)*1e3,value:r}),this.lru.set(n,o)}remove(e,r){let n=`${e.toLowerCase()}-${r}`;this.lru.remove(n)}clear(){this.lru.clear()}};function ga(t){return new gi(t)}var Od=1e3,Qr=class{resolvers;cache;logger;constructor(e){this.resolvers={},this.cache=ga(e.cacheSize??Od),this.logger=e.logger,Object.entries(e.resolvers??{}).forEach(([r,n])=>{Array.isArray(n)||(n=[n]),r.endsWith(".")||(r=`${r}.`),this.resolvers[r]=n}),this.resolvers["."]==null&&(this.resolvers["."]=da())}async query(e,r={}){let n=Or(r.types),o=r.cached!==!1?this.cache.get(e,n):void 0;if(o!=null)return r.onProgress?.(new A("dns:cache",o)),o;let i=`${e.split(".").pop()}.`,s=(this.resolvers[i]??this.resolvers["."]).sort(()=>Math.random()>.5?-1:1),a=[];for(let c of s){if(r.signal?.aborted===!0)break;try{let l=await c(e,{...r,logger:this.logger,types:n});for(let p of l.Answer)this.cache.add(e,p);return l}catch(l){a.push(l),r.onProgress?.(new A("dns:error",l))}}throw new $r(a,`DNS lookup of ${e} ${n} failed`)}};var be;(function(t){t[t.A=1]="A",t[t.CNAME=5]="CNAME",t[t.TXT=16]="TXT",t[t.AAAA=28]="AAAA"})(be||(be={}));function ya(t={}){return new Qr(t)}function Fd(t){return t[Symbol.asyncIterator]!=null}function zd(t){if(Fd(t))return(async()=>{for await(let e of t);})();for(let e of t);}var wa=zd;function it(t,e){if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;for(let r=0;r<t.byteLength;r++)if(t[r]!==e[r])return!1;return!0}function yi(t,e){e==null&&(e=t.reduce((o,i)=>o+i.length,0));let r=Kr(e),n=0;for(let o of t)r.set(o,n),n+=o.length;return r}function W(t,e="utf8"){let r=Wr[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.decoder.decode(`${r.prefix}${t}`)}var wi={32:16777619n,64:1099511628211n,128:309485009821345068724781371n,256:374144419156711147060143317175368453031918731002211n,512:35835915874844867368919076489095108449946327955754392558399825615420669938882575126094039892345713852759n,1024:5016456510113118655434598811035278955030765345404790744303017523831112055108147451509157692220295382716162651878526895249385292291816524375083746691371804094271873160484737966720260389217684476157468082573n},xa={32:2166136261n,64:14695981039346656037n,128:144066263297769815596495629667062367629n,256:100029257958052580907070968620625704837092796014241193945225284501741471925557n,512:9659303129496669498009435400716310466090418745672637896108374329434462657994582932197716438449813051892206539805784495328239340083876191928701583869517785n,1024:14197795064947621068722070641403218320880622795441933960878474914617582723252296732303717722150864096521202355549365628174669108571814760471015076148029755969804077320157692458563003215304957150157403644460363550505412711285966361610267868082893823963790439336411086884584107735010676915n},ba=new globalThis.TextEncoder;function jd(t,e){let r=wi[e],n=xa[e];for(let o=0;o<t.length;o++)n^=BigInt(t[o]),n=BigInt.asUintN(e,n*r);return n}function qd(t,e,r){if(r.length===0)throw new Error("The `utf8Buffer` option must have a length greater than zero");let n=wi[e],o=xa[e],i=t;for(;i.length>0;){let s=ba.encodeInto(i,r);i=i.slice(s.read);for(let a=0;a<s.written;a++)o^=BigInt(r[a]),o=BigInt.asUintN(e,o*n)}return o}function xi(t,{size:e=32,utf8Buffer:r}={}){if(!wi[e])throw new Error("The `size` option must be one of 32, 64, 128, 256, 512, or 1024");if(typeof t=="string"){if(r)return qd(t,e,r);t=ba.encode(t)}return jd(t,e)}var Zt={hash:t=>Number(xi(t,{size:32})),hashV:(t,e)=>Vd(Zt.hash(t,e))};function Vd(t){let e=t.toString(16);return e.length%2===1&&(e=`0${e}`),W(e,"base16")}var bi=64,_e=class{fp;h;seed;constructor(e,r,n,o=2){if(o>bi)throw new TypeError("Invalid Fingerprint Size");let i=r.hashV(e,n),s=ua(o);for(let a=0;a<s.length;a++)s[a]=i[a];s.length===0&&(s[0]=7),this.fp=s,this.h=r,this.seed=n}hash(){return this.h.hash(this.fp,this.seed)}equals(e){return e?.fp instanceof Uint8Array?it(this.fp,e.fp):!1}};function st(t,e){return Math.floor(Math.random()*(e-t))+t}var at=class{contents;constructor(e){this.contents=new Array(e).fill(null)}has(e){if(!(e instanceof _e))throw new TypeError("Invalid Fingerprint");return this.contents.some(r=>e.equals(r))}add(e){if(!(e instanceof _e))throw new TypeError("Invalid Fingerprint");for(let r=0;r<this.contents.length;r++)if(this.contents[r]==null)return this.contents[r]=e,!0;return!0}swap(e){if(!(e instanceof _e))throw new TypeError("Invalid Fingerprint");let r=st(0,this.contents.length-1),n=this.contents[r];return this.contents[r]=e,n}remove(e){if(!(e instanceof _e))throw new TypeError("Invalid Fingerprint");let r=this.contents.findIndex(n=>e.equals(n));return r>-1?(this.contents[r]=null,!0):!1}};var Hd=500,er=class{bucketSize;filterSize;fingerprintSize;buckets;count;hash;seed;constructor(e){this.filterSize=e.filterSize,this.bucketSize=e.bucketSize??4,this.fingerprintSize=e.fingerprintSize??2,this.count=0,this.buckets=[],this.hash=e.hash??Zt,this.seed=e.seed??st(0,Math.pow(2,10))}add(e){typeof e=="string"&&(e=W(e));let r=new _e(e,this.hash,this.seed,this.fingerprintSize),n=this.hash.hash(e,this.seed)%this.filterSize,o=(n^r.hash())%this.filterSize;if(this.buckets[n]==null&&(this.buckets[n]=new at(this.bucketSize)),this.buckets[o]==null&&(this.buckets[o]=new at(this.bucketSize)),this.buckets[n].add(r)||this.buckets[o].add(r))return this.count++,!0;let i=[n,o],s=i[st(0,i.length-1)];this.buckets[s]==null&&(this.buckets[s]=new at(this.bucketSize));for(let a=0;a<Hd;a++){let c=this.buckets[s].swap(r);if(c!=null&&(s=(s^c.hash())%this.filterSize,this.buckets[s]==null&&(this.buckets[s]=new at(this.bucketSize)),this.buckets[s].add(c)))return this.count++,!0}return!1}has(e){typeof e=="string"&&(e=W(e));let r=new _e(e,this.hash,this.seed,this.fingerprintSize),n=this.hash.hash(e,this.seed)%this.filterSize,o=this.buckets[n]?.has(r)??!1;if(o)return o;let i=(n^r.hash())%this.filterSize;return this.buckets[i]?.has(r)??!1}remove(e){typeof e=="string"&&(e=W(e));let r=new _e(e,this.hash,this.seed,this.fingerprintSize),n=this.hash.hash(e,this.seed)%this.filterSize,o=this.buckets[n]?.remove(r)??!1;if(o)return this.count--,o;let i=(n^r.hash())%this.filterSize,s=this.buckets[i]?.remove(r)??!1;return s&&this.count--,s}get reliable(){return Math.floor(100*(this.count/this.filterSize))<=90}},Kd={1:.5,2:.84,4:.95,8:.98};function Wd(t=.001){return t>.002?2:t>1e-5?4:8}function Ea(t,e=.001){let r=Wd(e),n=Kd[r],o=Math.round(t/n),i=Math.min(Math.ceil(Math.log2(1/e)+Math.log2(2*r)),bi);return{filterSize:o,bucketSize:r,fingerprintSize:i}}var Jr=class{filterSize;bucketSize;fingerprintSize;scale;filterSeries;hash;seed;constructor(e){this.bucketSize=e.bucketSize??4,this.filterSize=e.filterSize??(1<<18)/this.bucketSize,this.fingerprintSize=e.fingerprintSize??2,this.scale=e.scale??2,this.hash=e.hash??Zt,this.seed=e.seed??st(0,Math.pow(2,10)),this.filterSeries=[new er({filterSize:this.filterSize,bucketSize:this.bucketSize,fingerprintSize:this.fingerprintSize,hash:this.hash,seed:this.seed})]}add(e){if(typeof e=="string"&&(e=W(e)),this.has(e))return!0;let r=this.filterSeries.find(n=>n.reliable);if(r==null){let n=this.filterSize*Math.pow(this.scale,this.filterSeries.length);r=new er({filterSize:n,bucketSize:this.bucketSize,fingerprintSize:this.fingerprintSize,hash:this.hash,seed:this.seed}),this.filterSeries.push(r)}return r.add(e)}has(e){typeof e=="string"&&(e=W(e));for(let r=0;r<this.filterSeries.length;r++)if(this.filterSeries[r].has(e))return!0;return!1}remove(e){typeof e=="string"&&(e=W(e));for(let r=0;r<this.filterSeries.length;r++)if(this.filterSeries[r].remove(e))return!0;return!1}get count(){return this.filterSeries.reduce((e,r)=>e+r.count,0)}};function Yr(t,e=.001,r){return new Jr({...Ea(t,e),...r??{}})}function G(){let t={};return t.promise=new Promise((e,r)=>{t.resolve=e,t.reject=r}),t}var Xr=class{buffer;mask;top;btm;next;constructor(e){if(!(e>0)||(e-1&e)!==0)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(e),this.mask=e-1,this.top=0,this.btm=0,this.next=null}push(e){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=e,this.top=this.top+1&this.mask,!0)}shift(){let e=this.buffer[this.btm];if(e!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,e}isEmpty(){return this.buffer[this.btm]===void 0}},Tt=class{size;hwm;head;tail;constructor(e={}){this.hwm=e.splitLimit??16,this.head=new Xr(this.hwm),this.tail=this.head,this.size=0}calculateSize(e){return e?.byteLength!=null?e.byteLength:1}push(e){if(e?.value!=null&&(this.size+=this.calculateSize(e.value)),!this.head.push(e)){let r=this.head;this.head=r.next=new Xr(2*this.head.buffer.length),this.head.push(e)}}shift(){let e=this.tail.shift();if(e===void 0&&this.tail.next!=null){let r=this.tail.next;this.tail.next=null,this.tail=r,e=this.tail.shift()}return e?.value!=null&&(this.size-=this.calculateSize(e.value)),e}isEmpty(){return this.head.isEmpty()}};var Ei=class extends Error{type;code;constructor(e,r){super(e??"The operation was aborted"),this.type="aborted",this.code=r??"ABORT_ERR"}};function Zr(t={}){return Gd(r=>{let n=r.shift();if(n==null)return{done:!0};if(n.error!=null)throw n.error;return{done:n.done===!0,value:n.value}},t)}function Gd(t,e){e=e??{};let r=e.onEnd,n=new Tt,o,i,s,a=G(),c=async()=>{try{return n.isEmpty()?s?{done:!0}:await new Promise((S,$)=>{i=H=>{i=null,n.push(H);try{S(t(n))}catch(q){$(q)}return o}}):t(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=G()})}},l=S=>i!=null?i(S):(n.push(S),o),p=S=>(n=new Tt,i!=null?i({error:S}):(n.push({error:S}),o)),m=S=>{if(s)return o;if(e?.objectMode!==!0&&S?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return l({done:!1,value:S})},x=S=>s?o:(s=!0,S!=null?p(S):l({done:!0})),k=()=>(n=new Tt,x(),{done:!0}),I=S=>(x(S),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:c,return:k,throw:I,push:m,end:x,get readableLength(){return n.size},onEmpty:async S=>{let $=S?.signal;if($?.throwIfAborted(),n.isEmpty())return;let H,q;$!=null&&(H=new Promise((Q,fe)=>{q=()=>{fe(new Ei)},$.addEventListener("abort",q)}));try{await Promise.race([a.promise,H])}finally{q!=null&&$!=null&&$?.removeEventListener("abort",q)}}},r==null)return o;let D=o;return o={[Symbol.asyncIterator](){return this},next(){return D.next()},throw(S){return D.throw(S),r!=null&&(r(S),r=void 0),{done:!0}},return(){return D.return(),r!=null&&(r(),r=void 0),{done:!0}},push:m,end(S){return D.end(S),r!=null&&(r(S),r=void 0),o},get readableLength(){return D.readableLength},onEmpty:S=>D.onEmpty(S)},o}var Qd=t=>{let e=t.addEventListener||t.on||t.addListener,r=t.removeEventListener||t.off||t.removeListener;if(!e||!r)throw new TypeError("Emitter is not compatible");return{addListener:e.bind(t),removeListener:r.bind(t)}};function Jd(t,e,r){let n,o=new Promise((i,s)=>{if(r={rejectionEvents:["error"],multiArgs:!1,rejectionMultiArgs:!1,resolveImmediately:!1,...r},!(r.count>=0&&(r.count===Number.POSITIVE_INFINITY||Number.isInteger(r.count))))throw new TypeError("The `count` option should be at least 0 or more");r.signal?.throwIfAborted();let a=[e].flat(),c=[],{addListener:l,removeListener:p}=Qd(t),m=async(...k)=>{let I=r.multiArgs?k:k[0];if(r.filter)try{if(!await r.filter(I))return}catch(D){n(),s(D);return}c.push(I),r.count===c.length&&(n(),i(c))},x=(...k)=>{n(),s(r.rejectionMultiArgs?k:k[0])};n=()=>{for(let k of a)p(k,m);for(let k of r.rejectionEvents)a.includes(k)||p(k,x)};for(let k of a)l(k,m);for(let k of r.rejectionEvents)a.includes(k)||l(k,x);r.signal&&r.signal.addEventListener("abort",()=>{x(r.signal.reason)},{once:!0}),r.resolveImmediately&&i(c)});if(o.cancel=n,typeof r.timeout=="number"){let i=Wt(o,{milliseconds:r.timeout});return i.cancel=()=>{n(),i.clear()},i}return o}function en(t,e,r){typeof r=="function"&&(r={filter:r}),r={...r,count:1,resolveImmediately:!1};let n=Jd(t,e,r),o=n.then(i=>i[0]);return o.cancel=n.cancel,o}function _i(t,e){let r,n=function(){let o=function(){r=void 0,t()};clearTimeout(r),r=setTimeout(o,e)};return n.start=()=>{},n.stop=()=>{clearTimeout(r)},n}var tn=class extends Error{static name="QueueFullError";constructor(e="The queue was full"){super(e),this.name="QueueFullError"}};function Yd(t){return t.reason}async function Oe(t,e,r){if(e==null)return t;let n=r?.translateError??Yd;if(e.aborted)return t.catch(()=>{}),Promise.reject(n(e));let o;try{return await Promise.race([t,new Promise((i,s)=>{o=()=>{s(n(e))},e.addEventListener("abort",o)})])}finally{o!=null&&e.removeEventListener("abort",o)}}var rn=class{deferred;signal;constructor(e){this.signal=e,this.deferred=G(),this.onAbort=this.onAbort.bind(this),this.signal?.addEventListener("abort",this.onAbort)}onAbort(){this.deferred.reject(this.signal?.reason??new xe)}cleanup(){this.signal?.removeEventListener("abort",this.onAbort)}};function Xd(){return`${parseInt(String(Math.random()*1e9),10).toString()}${Date.now()}`}var nn=class{id;fn;options;recipients;status;timeline;controller;constructor(e,r){this.id=Xd(),this.status="queued",this.fn=e,this.options=r,this.recipients=[],this.timeline={created:Date.now()},this.controller=new AbortController,this.controller.signal,this.onAbort=this.onAbort.bind(this)}abort(e){this.controller.abort(e)}onAbort(){this.recipients.reduce((r,n)=>r&&n.signal?.aborted===!0,!0)&&(this.controller.abort(new xe),this.cleanup())}async join(e={}){let r=new rn(e.signal);return this.recipients.push(r),e.signal?.addEventListener("abort",this.onAbort),r.deferred.promise}async run(){this.status="running",this.timeline.started=Date.now();try{this.controller.signal.throwIfAborted();let e=await Oe(this.fn({...this.options??{},signal:this.controller.signal}),this.controller.signal);this.recipients.forEach(r=>{r.deferred.resolve(e)}),this.status="complete"}catch(e){this.recipients.forEach(r=>{r.deferred.reject(e)}),this.status="errored"}finally{this.timeline.finished=Date.now(),this.cleanup()}}cleanup(){this.recipients.forEach(e=>{e.cleanup(),e.signal?.removeEventListener("abort",this.onAbort)})}};var J=class extends le{concurrency;maxSize;queue;pending;sort;paused;constructor(e={}){super(),this.concurrency=e.concurrency??Number.POSITIVE_INFINITY,this.maxSize=e.maxSize??Number.POSITIVE_INFINITY,this.pending=0,this.paused=!1,e.metricName!=null&&e.metrics?.registerMetricGroup(e.metricName,{calculate:()=>({size:this.queue.length,running:this.pending,queued:this.queue.length-this.pending})}),this.sort=e.sort,this.queue=[],this.emitEmpty=_i(this.emitEmpty.bind(this),1),this.emitIdle=_i(this.emitIdle.bind(this),1)}emitEmpty(){this.size===0&&this.safeDispatchEvent("empty")}emitIdle(){this.running===0&&this.safeDispatchEvent("idle")}pause(){this.paused=!0}resume(){this.paused&&(this.paused=!1,this.tryToStartAnother())}tryToStartAnother(){if(this.paused)return!1;if(this.size===0)return this.emitEmpty(),this.running===0&&this.emitIdle(),!1;if(this.pending<this.concurrency){let e;for(let r of this.queue)if(r.status==="queued"){e=r;break}return e==null?!1:(this.safeDispatchEvent("active"),this.pending++,e.run().finally(()=>{for(let r=0;r<this.queue.length;r++)if(this.queue[r]===e){this.queue.splice(r,1);break}this.pending--,this.tryToStartAnother(),this.safeDispatchEvent("next")}),!0)}return!1}enqueue(e){this.queue.push(e),this.sort!=null&&this.queue.sort(this.sort)}async add(e,r){if(r?.signal?.throwIfAborted(),this.size===this.maxSize)throw new tn;let n=new nn(e,r);return this.enqueue(n),this.safeDispatchEvent("add"),this.tryToStartAnother(),n.join(r).then(o=>(this.safeDispatchEvent("completed",{detail:o}),this.safeDispatchEvent("success",{detail:{job:n,result:o}}),o)).catch(o=>{if(n.status==="queued"){for(let i=0;i<this.queue.length;i++)if(this.queue[i]===n){this.queue.splice(i,1);break}}throw this.safeDispatchEvent("failure",{detail:{job:n,error:o}}),o})}clear(){this.queue.splice(0,this.queue.length)}abort(){this.queue.forEach(e=>{e.abort(new xe)}),this.clear()}async onEmpty(e){this.size!==0&&await en(this,"empty",e)}async onSizeLessThan(e,r){this.size<e||await en(this,"next",{...r,filter:()=>this.size<e})}async onIdle(e){this.pending===0&&this.size===0||await en(this,"idle",e)}get size(){return this.queue.length}get queued(){return this.queue.length-this.pending}get running(){return this.pending}async*toGenerator(e){e?.signal?.throwIfAborted();let r=Zr({objectMode:!0}),n=c=>{c!=null?this.abort():this.clear(),r.end(c)},o=c=>{c.detail!=null&&r.push(c.detail)},i=c=>{n(c.detail.error)},s=()=>{n()},a=()=>{n(new xe("Queue aborted"))};this.addEventListener("completed",o),this.addEventListener("failure",i),this.addEventListener("idle",s),e?.signal?.addEventListener("abort",a);try{yield*r}finally{this.removeEventListener("completed",o),this.removeEventListener("failure",i),this.removeEventListener("idle",s),e?.signal?.removeEventListener("abort",a),n()}}};function ve(t){let e=new globalThis.AbortController;function r(){let i=t.filter(s=>s?.aborted===!0).map(s=>s?.reason).pop();e.abort(i);for(let s of t)s?.removeEventListener!=null&&s.removeEventListener("abort",r)}for(let i of t){if(i?.aborted===!0){r();break}i?.addEventListener!=null&&i.addEventListener("abort",r)}function n(){for(let i of t)i?.removeEventListener!=null&&i.removeEventListener("abort",r)}let o=e.signal;return o.clear=n,o}var vi=class{readNext;haveNext;ended;nextResult;error;constructor(){this.ended=!1,this.readNext=G(),this.haveNext=G()}[Symbol.asyncIterator](){return this}async next(){if(this.nextResult==null&&await this.haveNext.promise,this.nextResult==null)throw new Error("HaveNext promise resolved but nextResult was undefined");let e=this.nextResult;return this.nextResult=void 0,this.readNext.resolve(),this.readNext=G(),e}async throw(e){return this.ended=!0,this.error=e,e!=null&&(this.haveNext.promise.catch(()=>{}),this.haveNext.reject(e)),{done:!0,value:void 0}}async return(){let e={done:!0,value:void 0};return this.ended=!0,this.nextResult=e,this.haveNext.resolve(),e}async push(e,r){await this._push(e,r)}async end(e,r){e!=null?await this.throw(e):await this._push(void 0,r)}async _push(e,r){if(e!=null&&this.ended)throw this.error??new Error("Cannot push value onto an ended pushable");for(;this.nextResult!=null;)await this.readNext.promise;e!=null?this.nextResult={done:!1,value:e}:(this.ended=!0,this.nextResult={done:!0,value:void 0}),this.haveNext.resolve(),this.haveNext=G(),await Oe(this.readNext.promise,r?.signal,r)}};function _a(){return new vi}function Zd(t){return t[Symbol.asyncIterator]!=null}async function eh(t,e,r){try{await Promise.all(t.map(async n=>{for await(let o of n)await e.push(o,{signal:r}),r.throwIfAborted()})),await e.end(void 0,{signal:r})}catch(n){await e.end(n,{signal:r}).catch(()=>{})}}async function*th(t){let e=new AbortController,r=_a();eh(t,r,e.signal).catch(()=>{});try{yield*r}finally{e.abort()}}function*rh(t){for(let e of t)yield*e}function nh(...t){let e=[];for(let r of t)Zd(r)||e.push(r);return e.length===t.length?rh(e):th(t)}var on=nh;var oh=["Object","RegExp","Date","Error","Map","Set","WeakMap","WeakSet","ArrayBuffer","SharedArrayBuffer","DataView","Promise","URL","HTMLElement","Int8Array","Uint8ClampedArray","Int16Array","Uint16Array","Int32Array","Uint32Array","Float32Array","Float64Array","BigInt64Array","BigUint64Array"];function ki(t){if(t===null)return"null";if(t===void 0)return"undefined";if(t===!0||t===!1)return"boolean";let e=typeof t;if(e==="string"||e==="number"||e==="bigint"||e==="symbol")return e;if(e==="function")return"Function";if(Array.isArray(t))return"Array";if(t instanceof Uint8Array)return"Uint8Array";if(t.constructor===Object)return"Object";let r=ih(t);return r||"Object"}function ih(t){let e=Object.prototype.toString.call(t).slice(8,-1);if(oh.includes(e))return e}var d=class{constructor(e,r,n){this.major=e,this.majorEncoded=e<<5,this.name=r,this.terminal=n}toString(){return`Type[${this.major}].${this.name}`}compare(e){return this.major<e.major?-1:this.major>e.major?1:0}static equals(e,r){return e===r||e.major===r.major&&e.name===r.name}};d.uint=new d(0,"uint",!0);d.negint=new d(1,"negint",!0);d.bytes=new d(2,"bytes",!0);d.string=new d(3,"string",!0);d.array=new d(4,"array",!1);d.map=new d(5,"map",!1);d.tag=new d(6,"tag",!1);d.float=new d(7,"float",!0);d.false=new d(7,"false",!0);d.true=new d(7,"true",!0);d.null=new d(7,"null",!0);d.undefined=new d(7,"undefined",!0);d.break=new d(7,"break",!0);var _=class{constructor(e,r,n){this.type=e,this.value=r,this.encodedLength=n,this.encodedBytes=void 0,this.byteValue=void 0}toString(){return`Token[${this.type}].${this.value}`}};var tr=globalThis.process&&!globalThis.process.browser&&globalThis.Buffer&&typeof globalThis.Buffer.isBuffer=="function",sh=new TextEncoder;function sn(t){return tr&&globalThis.Buffer.isBuffer(t)}function rr(t){return t instanceof Uint8Array?sn(t)?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):t:Uint8Array.from(t)}var ah=24,ch=200,an=tr?t=>t.length>=ah?globalThis.Buffer.from(t):va(t):t=>t.length>=ch?sh.encode(t):va(t),Le=t=>Uint8Array.from(t),ka=tr?(t,e,r)=>sn(t)?new Uint8Array(t.subarray(e,r)):t.slice(e,r):(t,e,r)=>t.slice(e,r),Aa=tr?(t,e)=>(t=t.map(r=>r instanceof Uint8Array?r:globalThis.Buffer.from(r)),rr(globalThis.Buffer.concat(t,e))):(t,e)=>{let r=new Uint8Array(e),n=0;for(let o of t)n+o.length>r.length&&(o=o.subarray(0,r.length-n)),r.set(o,n),n+=o.length;return r},Ta=tr?t=>globalThis.Buffer.allocUnsafe(t):t=>new Uint8Array(t);function cn(t,e){if(sn(t)&&sn(e))return t.compare(e);for(let r=0;r<t.length;r++)if(t[r]!==e[r])return t[r]<e[r]?-1:1;return 0}function va(t){let e=[],r=0;for(let n=0;n<t.length;n++){let o=t.charCodeAt(n);o<128?e[r++]=o:o<2048?(e[r++]=o>>6|192,e[r++]=o&63|128):(o&64512)===55296&&n+1<t.length&&(t.charCodeAt(n+1)&64512)===56320?(o=65536+((o&1023)<<10)+(t.charCodeAt(++n)&1023),e[r++]=o>>18|240,e[r++]=o>>12&63|128,e[r++]=o>>6&63|128,e[r++]=o&63|128):(o>=55296&&o<=57343&&(o=65533),e[r++]=o>>12|224,e[r++]=o>>6&63|128,e[r++]=o&63|128)}return e}var uh=256,nr=class{constructor(e=uh){this.chunkSize=e,this.cursor=0,this.maxCursor=-1,this.chunks=[],this._initReuseChunk=null}reset(){this.cursor=0,this.maxCursor=-1,this.chunks.length&&(this.chunks=[]),this._initReuseChunk!==null&&(this.chunks.push(this._initReuseChunk),this.maxCursor=this._initReuseChunk.length-1)}push(e){let r=this.chunks[this.chunks.length-1];if(this.cursor+e.length<=this.maxCursor+1){let o=r.length-(this.maxCursor-this.cursor)-1;r.set(e,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)}e.length<64&&e.length<this.chunkSize?(r=Ta(this.chunkSize),this.chunks.push(r),this.maxCursor+=r.length,this._initReuseChunk===null&&(this._initReuseChunk=r),r.set(e,0)):(this.chunks.push(e),this.maxCursor+=e.length)}this.cursor+=e.length}toBytes(e=!1){let r;if(this.chunks.length===1){let n=this.chunks[0];e&&this.cursor>n.length/2?(r=this.cursor===n.length?n:n.subarray(0,this.cursor),this._initReuseChunk=null,this.chunks=[]):r=ka(n,0,this.cursor)}else r=Aa(this.chunks,this.cursor);return e&&this.reset(),r}},un=class{constructor(e){this.dest=e,this.cursor=0,this.chunks=[e]}reset(){this.cursor=0}push(e){if(this.cursor+e.length>this.dest.length)throw new Error("write out of bounds, destination buffer is too small");this.dest.set(e,this.cursor),this.cursor+=e.length}toBytes(e=!1){let r=this.dest.subarray(0,this.cursor);return e&&this.reset(),r}};var T="CBOR decode error:",fn="CBOR encode error:",or=[];or[23]=1;or[24]=2;or[25]=3;or[26]=5;or[27]=9;function Fe(t,e,r){if(t.length-e<r)throw new Error(`${T} not enough data for type`)}var O=[24,256,65536,4294967296,BigInt("18446744073709551616")];function Y(t,e,r){Fe(t,e,1);let n=t[e];if(r.strict===!0&&n<O[0])throw new Error(`${T} integer encoded in more bytes than necessary (strict decode)`);return n}function X(t,e,r){Fe(t,e,2);let n=t[e]<<8|t[e+1];if(r.strict===!0&&n<O[1])throw new Error(`${T} integer encoded in more bytes than necessary (strict decode)`);return n}function Z(t,e,r){Fe(t,e,4);let n=t[e]*16777216+(t[e+1]<<16)+(t[e+2]<<8)+t[e+3];if(r.strict===!0&&n<O[2])throw new Error(`${T} integer encoded in more bytes than necessary (strict decode)`);return n}function ee(t,e,r){Fe(t,e,8);let n=t[e]*16777216+(t[e+1]<<16)+(t[e+2]<<8)+t[e+3],o=t[e+4]*16777216+(t[e+5]<<16)+(t[e+6]<<8)+t[e+7],i=(BigInt(n)<<BigInt(32))+BigInt(o);if(r.strict===!0&&i<O[3])throw new Error(`${T} integer encoded in more bytes than necessary (strict decode)`);if(i<=Number.MAX_SAFE_INTEGER)return Number(i);if(r.allowBigInt===!0)return i;throw new Error(`${T} integers outside of the safe integer range are not supported`)}function Ia(t,e,r,n){return new _(d.uint,Y(t,e+1,n),2)}function Sa(t,e,r,n){return new _(d.uint,X(t,e+1,n),3)}function Ua(t,e,r,n){return new _(d.uint,Z(t,e+1,n),5)}function Na(t,e,r,n){return new _(d.uint,ee(t,e+1,n),9)}function de(t,e){return B(t,0,e.value)}function B(t,e,r){if(r<O[0]){let n=Number(r);t.push([e|n])}else if(r<O[1]){let n=Number(r);t.push([e|24,n])}else if(r<O[2]){let n=Number(r);t.push([e|25,n>>>8,n&255])}else if(r<O[3]){let n=Number(r);t.push([e|26,n>>>24&255,n>>>16&255,n>>>8&255,n&255])}else{let n=BigInt(r);if(n<O[4]){let o=[e|27,0,0,0,0,0,0,0],i=Number(n&BigInt(4294967295)),s=Number(n>>BigInt(32)&BigInt(4294967295));o[8]=i&255,i=i>>8,o[7]=i&255,i=i>>8,o[6]=i&255,i=i>>8,o[5]=i&255,o[4]=s&255,s=s>>8,o[3]=s&255,s=s>>8,o[2]=s&255,s=s>>8,o[1]=s&255,t.push(o)}else throw new Error(`${T} encountered BigInt larger than allowable range`)}}de.encodedSize=function(e){return B.encodedSize(e.value)};B.encodedSize=function(e){return e<O[0]?1:e<O[1]?2:e<O[2]?3:e<O[3]?5:9};de.compareTokens=function(e,r){return e.value<r.value?-1:e.value>r.value?1:0};function Ca(t,e,r,n){return new _(d.negint,-1-Y(t,e+1,n),2)}function La(t,e,r,n){return new _(d.negint,-1-X(t,e+1,n),3)}function Ba(t,e,r,n){return new _(d.negint,-1-Z(t,e+1,n),5)}var Ai=BigInt(-1),Ra=BigInt(1);function Da(t,e,r,n){let o=ee(t,e+1,n);if(typeof o!="bigint"){let i=-1-o;if(i>=Number.MIN_SAFE_INTEGER)return new _(d.negint,i,9)}if(n.allowBigInt!==!0)throw new Error(`${T} integers outside of the safe integer range are not supported`);return new _(d.negint,Ai-BigInt(o),9)}function ln(t,e){let r=e.value,n=typeof r=="bigint"?r*Ai-Ra:r*-1-1;B(t,e.type.majorEncoded,n)}ln.encodedSize=function(e){let r=e.value,n=typeof r=="bigint"?r*Ai-Ra:r*-1-1;return n<O[0]?1:n<O[1]?2:n<O[2]?3:n<O[3]?5:9};ln.compareTokens=function(e,r){return e.value<r.value?1:e.value>r.value?-1:0};function ir(t,e,r,n){Fe(t,e,r+n);let o=t.slice(e+r,e+r+n);return new _(d.bytes,o,r+n)}function Pa(t,e,r,n){return ir(t,e,1,r)}function $a(t,e,r,n){return ir(t,e,2,Y(t,e+1,n))}function Ma(t,e,r,n){return ir(t,e,3,X(t,e+1,n))}function Oa(t,e,r,n){return ir(t,e,5,Z(t,e+1,n))}function Fa(t,e,r,n){let o=ee(t,e+1,n);if(typeof o=="bigint")throw new Error(`${T} 64-bit integer bytes lengths not supported`);return ir(t,e,9,o)}function dn(t){return t.encodedBytes===void 0&&(t.encodedBytes=d.equals(t.type,d.string)?an(t.value):t.value),t.encodedBytes}function It(t,e){let r=dn(e);B(t,e.type.majorEncoded,r.length),t.push(r)}It.encodedSize=function(e){let r=dn(e);return B.encodedSize(r.length)+r.length};It.compareTokens=function(e,r){return lh(dn(e),dn(r))};function lh(t,e){return t.length<e.length?-1:t.length>e.length?1:cn(t,e)}var za=new TextDecoder,hh=32;function ph(t,e,r){if(r-e<hh){let o="";for(let i=e;i<r;i++){let s=t[i];if(s&128)return za.decode(t.subarray(e,r));o+=String.fromCharCode(s)}return o}return za.decode(t.subarray(e,r))}function sr(t,e,r,n,o){let i=r+n;Fe(t,e,i);let s=new _(d.string,ph(t,e+r,e+i),i);return o.retainStringBytes===!0&&(s.byteValue=t.slice(e+r,e+i)),s}function ja(t,e,r,n){return sr(t,e,1,r,n)}function qa(t,e,r,n){return sr(t,e,2,Y(t,e+1,n),n)}function Va(t,e,r,n){return sr(t,e,3,X(t,e+1,n),n)}function Ha(t,e,r,n){return sr(t,e,5,Z(t,e+1,n),n)}function Ka(t,e,r,n){let o=ee(t,e+1,n);if(typeof o=="bigint")throw new Error(`${T} 64-bit integer string lengths not supported`);return sr(t,e,9,o,n)}var Wa=It;function St(t,e,r,n){return new _(d.array,n,r)}function Ga(t,e,r,n){return St(t,e,1,r)}function Qa(t,e,r,n){return St(t,e,2,Y(t,e+1,n))}function Ja(t,e,r,n){return St(t,e,3,X(t,e+1,n))}function Ya(t,e,r,n){return St(t,e,5,Z(t,e+1,n))}function Xa(t,e,r,n){let o=ee(t,e+1,n);if(typeof o=="bigint")throw new Error(`${T} 64-bit integer array lengths not supported`);return St(t,e,9,o)}function Za(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${T} indefinite length items not allowed`);return St(t,e,1,1/0)}function hn(t,e){B(t,d.array.majorEncoded,e.value)}hn.compareTokens=de.compareTokens;hn.encodedSize=function(e){return B.encodedSize(e.value)};function Ut(t,e,r,n){return new _(d.map,n,r)}function ec(t,e,r,n){return Ut(t,e,1,r)}function tc(t,e,r,n){return Ut(t,e,2,Y(t,e+1,n))}function rc(t,e,r,n){return Ut(t,e,3,X(t,e+1,n))}function nc(t,e,r,n){return Ut(t,e,5,Z(t,e+1,n))}function oc(t,e,r,n){let o=ee(t,e+1,n);if(typeof o=="bigint")throw new Error(`${T} 64-bit integer map lengths not supported`);return Ut(t,e,9,o)}function ic(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${T} indefinite length items not allowed`);return Ut(t,e,1,1/0)}function pn(t,e){B(t,d.map.majorEncoded,e.value)}pn.compareTokens=de.compareTokens;pn.encodedSize=function(e){return B.encodedSize(e.value)};function sc(t,e,r,n){return new _(d.tag,r,1)}function ac(t,e,r,n){return new _(d.tag,Y(t,e+1,n),2)}function cc(t,e,r,n){return new _(d.tag,X(t,e+1,n),3)}function uc(t,e,r,n){return new _(d.tag,Z(t,e+1,n),5)}function fc(t,e,r,n){return new _(d.tag,ee(t,e+1,n),9)}function mn(t,e){B(t,d.tag.majorEncoded,e.value)}mn.compareTokens=de.compareTokens;mn.encodedSize=function(e){return B.encodedSize(e.value)};var Ti=20,Ii=21,Si=22,Ui=23;function lc(t,e,r,n){if(n.allowUndefined===!1)throw new Error(`${T} undefined values are not supported`);return n.coerceUndefinedToNull===!0?new _(d.null,null,1):new _(d.undefined,void 0,1)}function dc(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${T} indefinite length items not allowed`);return new _(d.break,void 0,1)}function Ni(t,e,r){if(r){if(r.allowNaN===!1&&Number.isNaN(t))throw new Error(`${T} NaN values are not supported`);if(r.allowInfinity===!1&&(t===1/0||t===-1/0))throw new Error(`${T} Infinity values are not supported`)}return new _(d.float,t,e)}function hc(t,e,r,n){return Ni(Ci(t,e+1),3,n)}function pc(t,e,r,n){return Ni(Li(t,e+1),5,n)}function mc(t,e,r,n){return Ni(xc(t,e+1),9,n)}function ar(t,e,r){let n=e.value;if(n===!1)t.push([d.float.majorEncoded|Ti]);else if(n===!0)t.push([d.float.majorEncoded|Ii]);else if(n===null)t.push([d.float.majorEncoded|Si]);else if(n===void 0)t.push([d.float.majorEncoded|Ui]);else{let o,i=!1;(!r||r.float64!==!0)&&(yc(n),o=Ci(ke,1),n===o||Number.isNaN(n)?(ke[0]=249,t.push(ke.slice(0,3)),i=!0):(wc(n),o=Li(ke,1),n===o&&(ke[0]=250,t.push(ke.slice(0,5)),i=!0))),i||(xh(n),o=xc(ke,1),ke[0]=251,t.push(ke.slice(0,9)))}}ar.encodedSize=function(e,r){let n=e.value;if(n===!1||n===!0||n===null||n===void 0)return 1;if(!r||r.float64!==!0){yc(n);let o=Ci(ke,1);if(n===o||Number.isNaN(n))return 3;if(wc(n),o=Li(ke,1),n===o)return 5}return 9};var gc=new ArrayBuffer(9),he=new DataView(gc,1),ke=new Uint8Array(gc,0);function yc(t){if(t===1/0)he.setUint16(0,31744,!1);else if(t===-1/0)he.setUint16(0,64512,!1);else if(Number.isNaN(t))he.setUint16(0,32256,!1);else{he.setFloat32(0,t);let e=he.getUint32(0),r=(e&2139095040)>>23,n=e&8388607;if(r===255)he.setUint16(0,31744,!1);else if(r===0)he.setUint16(0,(t&2147483648)>>16|n>>13,!1);else{let o=r-127;o<-24?he.setUint16(0,0):o<-14?he.setUint16(0,(e&2147483648)>>16|1<<24+o,!1):he.setUint16(0,(e&2147483648)>>16|o+15<<10|n>>13,!1)}}}function Ci(t,e){if(t.length-e<2)throw new Error(`${T} not enough data for float16`);let r=(t[e]<<8)+t[e+1];if(r===31744)return 1/0;if(r===64512)return-1/0;if(r===32256)return NaN;let n=r>>10&31,o=r&1023,i;return n===0?i=o*2**-24:n!==31?i=(o+1024)*2**(n-25):i=o===0?1/0:NaN,r&32768?-i:i}function wc(t){he.setFloat32(0,t,!1)}function Li(t,e){if(t.length-e<4)throw new Error(`${T} not enough data for float32`);let r=(t.byteOffset||0)+e;return new DataView(t.buffer,r,4).getFloat32(0,!1)}function xh(t){he.setFloat64(0,t,!1)}function xc(t,e){if(t.length-e<8)throw new Error(`${T} not enough data for float64`);let r=(t.byteOffset||0)+e;return new DataView(t.buffer,r,8).getFloat64(0,!1)}ar.compareTokens=de.compareTokens;function U(t,e,r){throw new Error(`${T} encountered invalid minor (${r}) for major ${t[e]>>>5}`)}function gn(t){return()=>{throw new Error(`${T} ${t}`)}}var g=[];for(let t=0;t<=23;t++)g[t]=U;g[24]=Ia;g[25]=Sa;g[26]=Ua;g[27]=Na;g[28]=U;g[29]=U;g[30]=U;g[31]=U;for(let t=32;t<=55;t++)g[t]=U;g[56]=Ca;g[57]=La;g[58]=Ba;g[59]=Da;g[60]=U;g[61]=U;g[62]=U;g[63]=U;for(let t=64;t<=87;t++)g[t]=Pa;g[88]=$a;g[89]=Ma;g[90]=Oa;g[91]=Fa;g[92]=U;g[93]=U;g[94]=U;g[95]=gn("indefinite length bytes/strings are not supported");for(let t=96;t<=119;t++)g[t]=ja;g[120]=qa;g[121]=Va;g[122]=Ha;g[123]=Ka;g[124]=U;g[125]=U;g[126]=U;g[127]=gn("indefinite length bytes/strings are not supported");for(let t=128;t<=151;t++)g[t]=Ga;g[152]=Qa;g[153]=Ja;g[154]=Ya;g[155]=Xa;g[156]=U;g[157]=U;g[158]=U;g[159]=Za;for(let t=160;t<=183;t++)g[t]=ec;g[184]=tc;g[185]=rc;g[186]=nc;g[187]=oc;g[188]=U;g[189]=U;g[190]=U;g[191]=ic;for(let t=192;t<=215;t++)g[t]=sc;g[216]=ac;g[217]=cc;g[218]=uc;g[219]=fc;g[220]=U;g[221]=U;g[222]=U;g[223]=U;for(let t=224;t<=243;t++)g[t]=gn("simple values are not supported");g[244]=U;g[245]=U;g[246]=U;g[247]=lc;g[248]=gn("simple values are not supported");g[249]=hc;g[250]=pc;g[251]=mc;g[252]=U;g[253]=U;g[254]=U;g[255]=dc;var Ae=[];for(let t=0;t<24;t++)Ae[t]=new _(d.uint,t,1);for(let t=-1;t>=-24;t--)Ae[31-t]=new _(d.negint,t,1);Ae[64]=new _(d.bytes,new Uint8Array(0),1);Ae[96]=new _(d.string,"",1);Ae[128]=new _(d.array,0,1);Ae[160]=new _(d.map,0,1);Ae[244]=new _(d.false,!1,1);Ae[245]=new _(d.true,!0,1);Ae[246]=new _(d.null,null,1);function Bi(t){switch(t.type){case d.false:return Le([244]);case d.true:return Le([245]);case d.null:return Le([246]);case d.bytes:return t.value.length?void 0:Le([64]);case d.string:return t.value===""?Le([96]):void 0;case d.array:return t.value===0?Le([128]):void 0;case d.map:return t.value===0?Le([160]):void 0;case d.uint:return t.value<24?Le([Number(t.value)]):void 0;case d.negint:if(t.value>=-24)return Le([31-Number(t.value)])}}var Eh={float64:!1,mapSorter:kh,quickEncodeToken:Bi},kc=Object.freeze({float64:!0,mapSorter:Ah,quickEncodeToken:Bi});function _h(){let t=[];return t[d.uint.major]=de,t[d.negint.major]=ln,t[d.bytes.major]=It,t[d.string.major]=Wa,t[d.array.major]=hn,t[d.map.major]=pn,t[d.tag.major]=mn,t[d.float.major]=ar,t}var Nt=_h(),yn=new nr,ur=class t{constructor(e,r){this.obj=e,this.parent=r}includes(e){let r=this;do if(r.obj===e)return!0;while(r=r.parent);return!1}static createCheck(e,r){if(e&&e.includes(r))throw new Error(`${fn} object contains circular references`);return new t(r,e)}},Ye={null:new _(d.null,null),undefined:new _(d.undefined,void 0),true:new _(d.true,!0),false:new _(d.false,!1),emptyArray:new _(d.array,0),emptyMap:new _(d.map,0)},Be={number(t,e,r,n){return!Number.isInteger(t)||!Number.isSafeInteger(t)?new _(d.float,t):t>=0?new _(d.uint,t):new _(d.negint,t)},bigint(t,e,r,n){return t>=BigInt(0)?new _(d.uint,t):new _(d.negint,t)},Uint8Array(t,e,r,n){return new _(d.bytes,t)},string(t,e,r,n){return new _(d.string,t)},boolean(t,e,r,n){return t?Ye.true:Ye.false},null(t,e,r,n){return Ye.null},undefined(t,e,r,n){return Ye.undefined},ArrayBuffer(t,e,r,n){return new _(d.bytes,new Uint8Array(t))},DataView(t,e,r,n){return new _(d.bytes,new Uint8Array(t.buffer,t.byteOffset,t.byteLength))},Array(t,e,r,n){if(!t.length)return r.addBreakTokens===!0?[Ye.emptyArray,new _(d.break)]:Ye.emptyArray;n=ur.createCheck(n,t);let o=[],i=0;for(let s of t)o[i++]=wn(s,r,n);return r.addBreakTokens?[new _(d.array,t.length),o,new _(d.break)]:[new _(d.array,t.length),o]},Object(t,e,r,n){let o=e!=="Object",i=o?t.keys():Object.keys(t),s=o?t.size:i.length,a;if(s){a=new Array(s),n=ur.createCheck(n,t);let c=!o&&r.ignoreUndefinedProperties,l=0;for(let p of i){let m=o?t.get(p):t[p];c&&m===void 0||(a[l++]=[wn(p,r,n),wn(m,r,n)])}l<s&&(a.length=l)}return a?.length?(vh(a,r),r.addBreakTokens?[new _(d.map,a.length),a,new _(d.break)]:[new _(d.map,a.length),a]):r.addBreakTokens===!0?[Ye.emptyMap,new _(d.break)]:Ye.emptyMap}};Be.Map=Be.Object;Be.Buffer=Be.Uint8Array;for(let t of"Uint8Clamped Uint16 Uint32 Int8 Int16 Int32 BigUint64 BigInt64 Float32 Float64".split(" "))Be[`${t}Array`]=Be.DataView;function wn(t,e={},r){let n=ki(t),o=e&&e.typeEncoders&&e.typeEncoders[n]||Be[n];if(typeof o=="function"){let s=o(t,n,e,r);if(s!=null)return s}let i=Be[n];if(!i)throw new Error(`${fn} unsupported type: ${n}`);return i(t,n,e,r)}function vh(t,e){e.mapSorter&&t.sort(e.mapSorter)}function kh(t,e){let r=Array.isArray(t[0])?t[0][0]:t[0],n=Array.isArray(e[0])?e[0][0]:e[0];if(r.type!==n.type)return r.type.compare(n.type);let o=r.type.major,i=Nt[o].compareTokens(r,n);return i===0&&console.warn("WARNING: complex key types used, CBOR key sorting guarantees are gone"),i}function Ah(t,e){if(t[0]instanceof _&&e[0]instanceof _){let r=t[0],n=e[0];return r._keyBytes||(r._keyBytes=bc(r.value)),n._keyBytes||(n._keyBytes=bc(n.value)),cn(r._keyBytes,n._keyBytes)}throw new Error("rfc8949MapSorter: complex key types are not supported yet")}function bc(t){return Tc(t,Nt,kc)}function cr(t,e,r,n){if(Array.isArray(e))for(let o of e)cr(t,o,r,n);else r[e.type.major](t,e,n)}var Ec=d.uint.majorEncoded,_c=d.negint.majorEncoded,Th=d.bytes.majorEncoded,Ih=d.string.majorEncoded,vc=d.array.majorEncoded,Sh=d.float.majorEncoded|Ti,Uh=d.float.majorEncoded|Ii,Nh=d.float.majorEncoded|Si,Ch=d.float.majorEncoded|Ui,Lh=BigInt(-1),Bh=BigInt(1);function Rh(t){return t.addBreakTokens!==!0}function Ac(t,e,r,n){let o=ki(e),i=r.typeEncoders&&r.typeEncoders[o];if(i){let s=i(e,o,r,n);if(s!=null){cr(t,s,Nt,r);return}}switch(o){case"null":t.push([Nh]);return;case"undefined":t.push([Ch]);return;case"boolean":t.push([e?Uh:Sh]);return;case"number":!Number.isInteger(e)||!Number.isSafeInteger(e)?ar(t,new _(d.float,e),r):e>=0?B(t,Ec,e):B(t,_c,e*-1-1);return;case"bigint":e>=BigInt(0)?B(t,Ec,e):B(t,_c,e*Lh-Bh);return;case"string":{let s=an(e);B(t,Ih,s.length),t.push(s);return}case"Uint8Array":B(t,Th,e.length),t.push(e);return;case"Array":if(!e.length){t.push([vc]);return}n=ur.createCheck(n,e),B(t,vc,e.length);for(let s of e)Ac(t,s,r,n);return;case"Object":case"Map":{let s=Be.Object(e,o,r,n);cr(t,s,Nt,r)}return;default:{let s=Be[o];if(!s)throw new Error(`${fn} unsupported type: ${o}`);let a=s(e,o,r,n);cr(t,a,Nt,r)}}}function Tc(t,e,r,n){let o=n instanceof Uint8Array,i=o?new un(n):yn,s=wn(t,r);if(!Array.isArray(s)&&r.quickEncodeToken){let a=r.quickEncodeToken(s);if(a)return o?(i.push(a),i.toBytes()):a;let c=e[s.type.major];if(c.encodedSize){let l=c.encodedSize(s,r);if(o||(i=new nr(l)),c(i,s,r),i.chunks.length!==1)throw new Error(`Unexpected error: pre-calculated length for ${s} was wrong`);return o?i.toBytes():rr(i.chunks[0])}}return i.reset(),cr(i,s,e,r),i.toBytes(!0)}function fr(t,e){return e=Object.assign({},Eh,e),Rh(e)?(yn.reset(),Ac(yn,t,e,void 0),yn.toBytes(!0)):Tc(t,Nt,e)}var Dh={strict:!1,allowIndefinite:!0,allowUndefined:!0,allowBigInt:!0},xn=class{constructor(e,r={}){this._pos=0,this.data=e,this.options=r}pos(){return this._pos}done(){return this._pos>=this.data.length}next(){let e=this.data[this._pos],r=Ae[e];if(r===void 0){let n=g[e];if(!n)throw new Error(`${T} no decoder for major type ${e>>>5} (byte 0x${e.toString(16).padStart(2,"0")})`);let o=e&31;r=n(this.data,this._pos,o,this.options)}return this._pos+=r.encodedLength,r}},lr=Symbol.for("DONE"),bn=Symbol.for("BREAK");function Ph(t,e,r){let n=[];for(let o=0;o<t.value;o++){let i=Ct(e,r);if(i===bn){if(t.value===1/0)break;throw new Error(`${T} got unexpected break to lengthed array`)}if(i===lr)throw new Error(`${T} found array but not enough entries (got ${o}, expected ${t.value})`);n[o]=i}return n}function $h(t,e,r){let n=r.useMaps===!0,o=r.rejectDuplicateMapKeys===!0,i=n?void 0:{},s=n?new Map:void 0;for(let a=0;a<t.value;a++){let c=Ct(e,r);if(c===bn){if(t.value===1/0)break;throw new Error(`${T} got unexpected break to lengthed map`)}if(c===lr)throw new Error(`${T} found map but not enough entries (got ${a} [no key], expected ${t.value})`);if(!n&&typeof c!="string")throw new Error(`${T} non-string keys not supported (got ${typeof c})`);if(o&&(n&&s.has(c)||!n&&Object.hasOwn(i,c)))throw new Error(`${T} found repeat map key "${c}"`);let l=Ct(e,r);if(l===lr)throw new Error(`${T} found map but not enough entries (got ${a} [no value], expected ${t.value})`);n?s.set(c,l):i[c]=l}return n?s:i}function Ct(t,e){if(t.done())return lr;let r=t.next();if(d.equals(r.type,d.break))return bn;if(r.type.terminal)return r.value;if(d.equals(r.type,d.array))return Ph(r,t,e);if(d.equals(r.type,d.map))return $h(r,t,e);if(d.equals(r.type,d.tag)){if(e.tags&&typeof e.tags[r.value]=="function"){let n=Ct(t,e);return e.tags[r.value](n)}throw new Error(`${T} tag not supported (${r.value})`)}throw new Error("unsupported")}function Ic(t,e){if(!(t instanceof Uint8Array))throw new Error(`${T} data to decode must be a Uint8Array`);e=Object.assign({},Dh,e);let r=rr(t),n=e.tokenizer||new xn(r,e),o=Ct(n,e);if(o===lr)throw new Error(`${T} did not find any content to decode`);if(o===bn)throw new Error(`${T} got unexpected break`);return[o,t.subarray(n.pos())]}function ut(t,e){let[r,n]=Ic(t,e);if(n.length>0)throw new Error(`${T} too many terminals, data makes no sense`);return r}var En=class extends J{has(e){return this.find(e)!=null}find(e){return this.queue.find(r=>e.equals(r.options.peerId))}};var ze="/",Sc=new TextEncoder().encode(ze),_n=Sc[0],je=class t{_buf;constructor(e,r){if(typeof e=="string")this._buf=W(e);else if(e instanceof Uint8Array)this._buf=e;else throw new Error("Invalid key, should be String of Uint8Array");if(r==null&&(r=!0),r&&this.clean(),this._buf.byteLength===0||this._buf[0]!==_n)throw new Error("Invalid key")}toString(e="utf8"){return Je(this._buf,e)}uint8Array(){return this._buf}get[Symbol.toStringTag](){return`Key(${this.toString()})`}static withNamespaces(e){return new t(e.join(ze))}static random(){return new t(Math.random().toString().substring(2))}static asKey(e){return e instanceof Uint8Array||typeof e=="string"?new t(e):typeof e.uint8Array=="function"?new t(e.uint8Array()):null}clean(){if((this._buf==null||this._buf.byteLength===0)&&(this._buf=Sc),this._buf[0]!==_n){let e=new Uint8Array(this._buf.byteLength+1);e.fill(_n,0,1),e.set(this._buf,1),this._buf=e}for(;this._buf.byteLength>1&&this._buf[this._buf.byteLength-1]===_n;)this._buf=this._buf.subarray(0,-1)}less(e){let r=this.list(),n=e.list();for(let o=0;o<r.length;o++){if(n.length<o+1)return!1;let i=r[o],s=n[o];if(i<s)return!0;if(i>s)return!1}return r.length<n.length}reverse(){return t.withNamespaces(this.list().slice().reverse())}namespaces(){return this.list()}baseNamespace(){let e=this.namespaces();return e[e.length-1]}list(){return this.toString().split(ze).slice(1)}type(){return Oh(this.baseNamespace())}name(){return Fh(this.baseNamespace())}instance(e){return new t(this.toString()+":"+e)}path(){let e=this.parent().toString();return e.endsWith(ze)||(e+=ze),e+=this.type(),new t(e)}parent(){let e=this.list();return e.length===1?new t(ze):new t(e.slice(0,-1).join(ze))}child(e){return this.toString()===ze?e:e.toString()===ze?this:new t(this.toString()+e.toString(),!1)}isAncestorOf(e){return e.toString()===this.toString()?!1:e.toString().startsWith(this.toString())}isDecendantOf(e){return e.toString()===this.toString()?!1:this.toString().startsWith(e.toString())}isTopLevel(){return this.list().length===1}concat(...e){return t.withNamespaces([...this.namespaces(),...zh(e.map(r=>r.namespaces()))])}};function Oh(t){let e=t.split(":");return e.length<2?"":e.slice(0,-1).join(":")}function Fh(t){let e=t.split(":");return e[e.length-1]}function zh(t){return[].concat(...t)}function jh(t){return t[Symbol.asyncIterator]!=null}function qh(t){if(jh(t))return(async()=>{let n=new Uint8Array(0);for await(let o of t)n=yi([n,o],n.length+o.length);return n})();let e=[],r=0;for(let n of t)e.push(n),r+=n.byteLength;return yi(e,r)}var vn=qh;function kn({enumerable:t=!0,configurable:e=!1}={}){return{enumerable:t,configurable:e,writable:!1}}function*Vh(t,e){if(e!=null&&typeof e=="object")if(Array.isArray(e))for(let[r,n]of e.entries()){let o=[...t,r],i=L.asCID(n);i!=null?yield[o.join("/"),i]:typeof n=="object"&&(yield*Ri(n,o))}else{let r=L.asCID(e);r!=null?yield[t.join("/"),r]:yield*Ri(e,t)}}function*Ri(t,e){if(t==null||t instanceof Uint8Array)return;let r=L.asCID(t);r!=null&&(yield[e.join("/"),r]);for(let[n,o]of Object.entries(t)){let i=[...e,n];yield*Vh(i,o)}}function*Hh(t,e){if(Array.isArray(e))for(let[r,n]of e.entries()){let o=[...t,r];yield o.join("/"),typeof n=="object"&&L.asCID(n)==null&&(yield*Di(n,o))}else yield*Di(e,t)}function*Di(t,e){if(!(t==null||typeof t!="object"))for(let[r,n]of Object.entries(t)){let o=[...e,r];yield o.join("/"),n!=null&&!(n instanceof Uint8Array)&&typeof n=="object"&&L.asCID(n)==null&&(yield*Hh(o,n))}}function Kh(t,e){let r=t;for(let[n,o]of e.entries()){if(r=r[o],r==null)throw new Error(`Object has no property at ${e.slice(0,n+1).map(s=>`[${JSON.stringify(s)}]`).join("")}`);let i=L.asCID(r);if(i!=null)return{value:i,remaining:e.slice(n+1).join("/")}}return{value:r}}var Pi=class{cid;bytes;value;asBlock;constructor({cid:e,bytes:r,value:n}){if(e==null||r==null||typeof n>"u")throw new Error("Missing required argument");this.cid=e,this.bytes=r,this.value=n,this.asBlock=this,Object.defineProperties(this,{cid:kn(),bytes:kn(),value:kn(),asBlock:kn()})}links(){return Ri(this.value,[])}tree(){return Di(this.value,[])}get(e="/"){return Kh(this.value,e.split("/").filter(Boolean))}};function An({bytes:t,cid:e,value:r,codec:n}){let o=r!==void 0?r:n?.decode(t);if(o===void 0)throw new Error('Missing required argument, must either provide "value" or "codec"');return new Pi({cid:e,bytes:t,value:o})}var Tn=class extends Error{static name="AlreadyPinnedError";name="AlreadyPinnedError"},dr=class extends Error{static name="BlockPinnedError";name="BlockPinnedError"},In=class extends Error{static name="InvalidDatastoreVersionError";name="InvalidDatastoreVersionError"},ft=class extends Error{static name="InvalidConfigurationError";name="InvalidConfigurationError"},Sn=class extends AggregateError{static name="GetFailedError";name="GetFailedError"},Un=class extends AggregateError{static name="LoadBlockFailedError";name="LoadBlockFailedError"},hr=class extends Error{static name="BlockNotFoundWhileOfflineError";name="BlockNotFoundWhileOfflineError"};var Cc="/pin/",Uc="/pinned-block/",$i=Me,Nc=1;function Nn(t){return t.version===0&&(t=t.toV1()),new je(`${Cc}${t.toString($i)}`)}var Cn=class{datastore;blockstore;getCodec;constructor(e,r,n){this.datastore=e,this.blockstore=r,this.getCodec=n}async*add(e,r={}){let n=Nn(e);if(await this.datastore.has(n))throw new Tn("Already pinned");let o=Math.round(r.depth??1/0);if(o<0)throw new yt("Depth must be greater than or equal to 0");let i=new J({concurrency:Nc});for await(let a of this.#e(e,i,{...r,depth:o}))await this.#o(a,c=>c.pinnedBy.find(l=>it(l,e.bytes))!=null?!1:(c.pinCount++,c.pinnedBy.push(e.bytes),!0),r),yield a;let s={depth:o,metadata:r.metadata??{}};await this.datastore.put(n,fr(s),r)}async*#e(e,r,n){if(n.depth===-1)return;let o=await this.getCodec(e.code),i=await vn(this.blockstore.get(e,n)),s=An({bytes:i,cid:e,codec:o});yield e;for(let[,a]of s.links())yield*await r.add(async()=>this.#e(a,r,{...n,depth:n.depth-1}))}async#o(e,r,n){let o=new je(`${Uc}${$i.encode(e.multihash.bytes)}`),i={pinCount:0,pinnedBy:[]};try{i=ut(await this.datastore.get(o,n))}catch(a){if(a.name!=="NotFoundError")throw a}if(r(i)){if(i.pinCount===0&&await this.datastore.has(o)){await this.datastore.delete(o);return}await this.datastore.put(o,fr(i),n),n.onProgress?.(new A("helia:pin:add",e))}}async*rm(e,r={}){let n=Nn(e),o=await this.datastore.get(n,r),i=ut(o);await this.datastore.delete(n,r);let s=new J({concurrency:Nc});for await(let a of this.#e(e,s,{...r,depth:i.depth}))await this.#o(a,c=>(c.pinCount--,c.pinnedBy=c.pinnedBy.filter(l=>it(l,e.bytes)),!0),{...r,depth:i.depth}),yield a}async*ls(e={}){for await(let{key:r,value:n}of this.datastore.query({prefix:Cc+(e.cid!=null?`${e.cid.toString(Me)}`:"")},e)){let o=L.parse(r.toString().substring(5),Me),i=ut(n);yield{cid:o,...i}}}async isPinned(e,r={}){let n=new je(`${Uc}${$i.encode(e.multihash.bytes)}`);return this.datastore.has(n,r)}async get(e,r){let n=Nn(e),o=await this.datastore.get(n,r);return ut(o)}async setMetadata(e,r,n){let o=Nn(e),i=await this.datastore.get(o,n),s=ut(i);s.metadata=r??{},await this.datastore.put(o,fr(s),n)}};var Ln=class extends Error{static name="InsufficientProvidersError";constructor(e="Insufficient providers found"){super(e),this.name="InsufficientProvidersError"}},lt=class extends Error{static name="NoRoutersAvailableError";constructor(e="No routers available"){super(e),this.name="NoRoutersAvailableError"}},Bn=class extends Error{static name="UnknownHashAlgorithmError";constructor(e="Unknown hash algorithm"){super(e),this.name="UnknownHashAlgorithmError"}},Rn=class extends Error{static name="UnknownCodecError";constructor(e="Unknown codec"){super(e),this.name="UnknownCodecError"}};var Wh=5,Dn=class{name;log;routers;providerLookupConcurrency;constructor(e,r){this.name="helia",this.log=e.logger.forComponent("helia:routing"),this.routers=r.routers??[],this.providerLookupConcurrency=r.providerLookupConcurrency??Wh,this.findProviders=e.metrics?.traceFunction("helia.routing.findProviders",this.findProviders.bind(this),{optionsIndex:1})??this.findProviders,this.provide=e.metrics?.traceFunction("helia.routing.provide",this.provide.bind(this),{optionsIndex:1})??this.provide,this.cancelReprovide=e.metrics?.traceFunction("helia.routing.cancelReprovide",this.cancelReprovide.bind(this),{optionsIndex:1})??this.cancelReprovide,this.put=e.metrics?.traceFunction("helia.routing.put",this.put.bind(this),{optionsIndex:2})??this.put,this.get=e.metrics?.traceFunction("helia.routing.get",this.get.bind(this),{optionsIndex:1})??this.get,this.findPeer=e.metrics?.traceFunction("helia.routing.findPeer",this.findPeer.bind(this),{optionsIndex:1})??this.findPeer,this.getClosestPeers=e.metrics?.traceFunction("helia.routing.getClosestPeers",this.getClosestPeers.bind(this),{optionsIndex:1})??this.getClosestPeers}async start(){await We(...this.routers)}async stop(){await Ge(...this.routers)}async*findProviders(e,r={}){if(this.routers.length===0)throw new lt("No content routers available");let n=new En({concurrency:this.providerLookupConcurrency}),o=0,i=[],s=this,a=0;this.log("findProviders for %c start using routers %s",e,this.routers.map(l=>l.toString()).join(", "));let c=dt(this.routers,"findProviders").map(async function*(l){let p=0;r?.onProgress?.(new A("helia:routing:find-providers:start",{routing:l.name,cid:e}));try{for await(let m of l.findProviders(e,r))p++,r?.onProgress?.(new A("helia:routing:find-providers:provider",{routing:l.name,cid:e,provider:m})),yield m}catch(m){i.push(m)}finally{s.log("router %s found %d providers for %c",l,p,e),r?.onProgress?.(new A("helia:routing:find-providers:end",{routing:l.name,cid:e,found:p})),a++,a===c.length&&n.size===0&&n.emitIdle()}});for await(let l of on(n.toGenerator(),...c))if(l!=null){if(l.multiaddrs.length===0){if(n.find(l.id)!=null)continue;n.add(async()=>{try{let p=await this.findPeer(l.id,r);return p.multiaddrs.length===0?null:{...p,protocols:l.protocols,routing:l.routing}}catch(p){return this.log.error("could not load multiaddrs for peer %p - %e",l.id,p),null}},{peerId:l.id,signal:r.signal}).catch(p=>{this.log.error("could not load multiaddrs for peer %p - %e",l.id,p)});continue}o++,yield l}this.log("findProviders finished, found %d providers for %c",o,e)}async provide(e,r={}){if(this.routers.length===0)throw new lt("No content routers available");await Promise.all(dt(this.routers,"provide").map(async n=>{r?.onProgress?.(new A("helia:routing:provide:start",{routing:n.name,cid:e})),await n.provide(e,r),r?.onProgress?.(new A("helia:routing:provide:end",{routing:n.name,cid:e}))}))}async cancelReprovide(e,r={}){await Promise.all(dt(this.routers,"cancelReprovide").map(async n=>{r?.onProgress?.(new A("helia:routing:cancel-reprovide:start",{routing:n.name,cid:e})),await n.cancelReprovide(e,r),r?.onProgress?.(new A("helia:routing:cancel-reprovide:end",{routing:n.name,cid:e}))}))}async put(e,r,n){await Promise.all(dt(this.routers,"put").map(async o=>{n?.onProgress?.(new A("helia:routing:put:start",{routing:o.name,key:e,value:r})),await o.put(e,r,n),n?.onProgress?.(new A("helia:routing:put:end",{routing:o.name,key:e,value:r}))}))}async get(e,r){let n=[],o;try{o=await Promise.any(dt(this.routers,"get").map(async i=>{r?.onProgress?.(new A("helia:routing:get:start",{routing:i.name,key:e}));try{return await i.get(e,r)}catch(s){this.log("router %s failed with %e",i,s),n.push(s)}finally{r?.onProgress?.(new A("helia:routing:get:end",{routing:i.name,key:e}))}}))}catch{}if(o==null)throw new Sn(n,`Failed to get value key ${Je(e,"base58btc")}`);return o}async findPeer(e,r){if(this.routers.length===0)throw new lt("No peer routers available");let n=this,o=on(...dt(this.routers,"findPeer").map(i=>(async function*(){r?.onProgress?.(new A("helia:routing:find-peer:start",{routing:i.name,peerId:e}));try{yield await i.findPeer(e,r)}catch(s){n.log.error(s)}finally{r?.onProgress?.(new A("helia:routing:find-peer:end",{routing:i.name,peerId:e}))}})()));for await(let i of o)if(i!=null)return i;throw new Dr("Could not find peer in routing")}async*getClosestPeers(e,r={}){if(this.routers.length===0)throw new lt("No peer routers available");for await(let n of on(...dt(this.routers,"getClosestPeers").map(async function*(o){r?.onProgress?.(new A("helia:routing:get-closest-peers:start",{routing:o.name,key:e}));try{yield*o.getClosestPeers(e,r)}finally{r?.onProgress?.(new A("helia:routing:get-closest-peers:end",{routing:o.name,key:e}))}})))n!=null&&(yield n)}};function dt(t,e){return t.filter(r=>r[e]!=null)}var te=class extends Error{static name="AbortError";name="AbortError";constructor(e="The operation was aborted",...r){super(e,...r)}};async function Pn(t,e,r,n){let o=new te(n?.errorMessage);n?.errorCode!=null&&(o.code=n.errorCode);let i=n?.errorEvent??"error";return r?.aborted===!0?Promise.reject(o):new Promise((s,a)=>{function c(){Oi(r,"abort",m),Oi(t,e,l),Oi(t,i,p)}let l=x=>{try{if(n?.filter?.(x)===!1)return}catch(k){c(),a(k);return}c(),s(x)},p=x=>{if(c(),x instanceof Error){a(x);return}a(x.detail??n?.error??new Error(`The "${n?.errorEvent}" event was emitted but the event had no '.detail' field. Pass an 'error' option to race-event to change this message.`))},m=()=>{c(),a(o)};Mi(r,"abort",m),Mi(t,e,l),Mi(t,i,p)})}function Mi(t,e,r){t!=null&&(Lc(t)?t.addEventListener(e,r):t.addListener(e,r))}function Oi(t,e,r){t!=null&&(Lc(t)?t.removeEventListener(e,r):t.removeListener(e,r))}function Lc(t){return typeof t.addEventListener=="function"&&typeof t.removeEventListener=="function"}var $n=class extends Error{static name="QueueFullError";constructor(e="The queue was full"){super(e),this.name="QueueFullError"}};var Mn=class{deferred;signal;constructor(e){this.signal=e,this.deferred=Promise.withResolvers(),this.onAbort=this.onAbort.bind(this),this.signal?.addEventListener("abort",this.onAbort)}onAbort(){this.deferred.reject(this.signal?.reason??new te)}cleanup(){this.signal?.removeEventListener("abort",this.onAbort)}};function Gh(){return`${parseInt(String(Math.random()*1e9),10).toString()}${Date.now()}`}var On=class{id;fn;options;recipients;status;timeline;controller;constructor(e,r){this.id=Gh(),this.status="queued",this.fn=e,this.options=r,this.recipients=[],this.timeline={created:Date.now()},this.controller=new AbortController,this.controller.signal,this.onAbort=this.onAbort.bind(this)}abort(e){this.controller.abort(e)}onAbort(){this.recipients.reduce((r,n)=>r&&n.signal?.aborted===!0,!0)&&(this.controller.abort(new te),this.cleanup())}async join(e={}){let r=new Mn(e.signal);return this.recipients.push(r),e.signal?.addEventListener("abort",this.onAbort),r.deferred.promise}async run(){this.status="running",this.timeline.started=Date.now();try{this.controller.signal.throwIfAborted();let e=await Oe(this.fn({...this.options??{},signal:this.controller.signal}),this.controller.signal);this.recipients.forEach(r=>{r.deferred.resolve(e)}),this.status="complete"}catch(e){this.recipients.forEach(r=>{r.deferred.reject(e)}),this.status="errored"}finally{this.timeline.finished=Date.now(),this.cleanup()}}cleanup(){this.recipients.forEach(e=>{e.cleanup(),e.signal?.removeEventListener("abort",this.onAbort)})}};function Fi(t,e){let r,n=function(){let o=function(){r=void 0,t()};clearTimeout(r),r=setTimeout(o,e)};return n.start=()=>{},n.stop=()=>{clearTimeout(r)},n}var pr=class extends le{concurrency;maxSize;queue;pending;sort;autoStart;constructor(e={}){super(),this.concurrency=e.concurrency??Number.POSITIVE_INFINITY,this.maxSize=e.maxSize??Number.POSITIVE_INFINITY,this.pending=0,this.autoStart=e.autoStart??!0,this.sort=e.sort,this.queue=[],this.emitEmpty=Fi(this.emitEmpty.bind(this),1),this.emitIdle=Fi(this.emitIdle.bind(this),1)}[Symbol.asyncIterator](){return this.toGenerator()}emitEmpty(){this.size===0&&this.safeDispatchEvent("empty")}emitIdle(){this.running===0&&this.safeDispatchEvent("idle")}tryToStartAnother(){if(this.size===0)return this.emitEmpty(),this.running===0&&this.emitIdle(),!1;if(this.pending<this.concurrency){let e;for(let r of this.queue)if(r.status==="queued"){e=r;break}return e==null?!1:(this.safeDispatchEvent("active"),this.pending++,e.run().finally(()=>{for(let r=0;r<this.queue.length;r++)if(this.queue[r]===e){this.queue.splice(r,1);break}this.pending--,this.safeDispatchEvent("next"),this.autoStart&&this.tryToStartAnother()}),!0)}return!1}enqueue(e){this.queue.push(e),this.sort!=null&&this.queue.sort(this.sort)}start(){this.autoStart===!1&&(this.autoStart=!0,this.tryToStartAnother())}pause(){this.autoStart=!1}async add(e,r){if(r?.signal?.throwIfAborted(),this.size===this.maxSize)throw new $n;let n=new On(e,r);return this.enqueue(n),this.safeDispatchEvent("add"),this.autoStart&&this.tryToStartAnother(),n.join(r).then(o=>(this.safeDispatchEvent("success",{detail:{job:n,result:o}}),o)).catch(o=>{if(n.status==="queued"){for(let i=0;i<this.queue.length;i++)if(this.queue[i]===n){this.queue.splice(i,1);break}}throw this.safeDispatchEvent("failure",{detail:{job:n,error:o}}),o})}clear(){this.queue.splice(0,this.queue.length)}abort(){this.queue.forEach(e=>{e.abort(new te)}),this.clear()}async onEmpty(e){this.size!==0&&await Pn(this,"empty",e?.signal)}async onSizeLessThan(e,r){this.size<e||await Pn(this,"next",r?.signal,{filter:()=>this.size<e})}async onIdle(e){this.pending===0&&this.size===0||await Pn(this,"idle",e?.signal)}get size(){return this.queue.length}get queued(){return this.queue.length-this.pending}get running(){return this.pending}async*toGenerator(e){e?.signal?.throwIfAborted();let r=Zr({objectMode:!0}),n=c=>{c!=null?this.abort():this.clear(),r.end(c)},o=c=>{c.detail!=null&&r.push(c.detail.result)},i=c=>{n(c.detail.error)},s=()=>{n()},a=()=>{n(new te("Queue aborted"))};this.addEventListener("success",o),this.addEventListener("failure",i),this.addEventListener("idle",s),e?.signal?.addEventListener("abort",a);try{yield*r}finally{this.removeEventListener("success",o),this.removeEventListener("failure",i),this.removeEventListener("idle",s),e?.signal?.removeEventListener("abort",a),n()}}};var Fn="lock:worker:request-read",zn="lock:worker:abort-read-request",jn="lock:worker:release-read",qn="lock:master:grant-read",Vn="lock:master:error-read",Hn="lock:worker:request-write",Kn="lock:worker:abort-write-request",Wn="lock:worker:release-write",Gn="lock:master:grant-write",Qn="lock:master:error-write",Jn="lock:worker:finalize",Yn="mortice",Bc={singleProcess:!1};var zi=(t,e,r,n,o,i,s,a,c)=>l=>{if(l.data==null)return;let p={type:l.data.type,name:l.data.name,identifier:l.data.identifier};p.type===o&&t.safeDispatchEvent(r,{detail:{name:p.name,identifier:p.identifier,handler:async()=>{e.postMessage({type:c,name:p.name,identifier:p.identifier}),await new Promise(m=>{let x=k=>{if(k?.data==null)return;let I={type:k.data.type,name:k.data.name,identifier:k.data.identifier};I.type===a&&I.identifier===p.identifier&&(e.removeEventListener("message",x),m())};e.addEventListener("message",x)})},onError:m=>{e.postMessage({type:s,name:p.name,identifier:p.identifier,error:{message:m.message,name:m.name,stack:m.stack}})}}}),p.type===i&&t.safeDispatchEvent(n,{detail:{name:p.name,identifier:p.identifier}}),p.type===Jn&&t.safeDispatchEvent("finalizeRequest",{detail:{name:p.name}})};var Rc=(t=10)=>Math.random().toString().substring(2,t+2);var Xn=class{name;channel;constructor(e){this.name=e,this.channel=new BroadcastChannel(Yn)}readLock(e){return this.sendRequest(Fn,zn,qn,Vn,jn,e)}writeLock(e){return this.sendRequest(Hn,Kn,Gn,Qn,Wn,e)}finalize(){this.channel.postMessage({type:Jn,name:this.name}),this.channel.close()}async sendRequest(e,r,n,o,i,s){s?.signal?.throwIfAborted();let a=Rc();return this.channel.postMessage({type:e,identifier:a,name:this.name}),new Promise((c,l)=>{let p=()=>{this.channel.postMessage({type:r,identifier:a,name:this.name})};s?.signal?.addEventListener("abort",p,{once:!0});let m=x=>{if(x.data?.identifier===a&&(x.data?.type===n&&(this.channel.removeEventListener("message",m),s?.signal?.removeEventListener("abort",p),c(()=>{this.channel.postMessage({type:i,identifier:a,name:this.name})})),x.data.type===o)){this.channel.removeEventListener("message",m),s?.signal?.removeEventListener("abort",p);let k=new Error;x.data.error!=null&&(k.message=x.data.error.message,k.name=x.data.error.name,k.stack=x.data.error.stack),l(k)}};this.channel.addEventListener("message",m)})}};var Dc=t=>{if(t=Object.assign({},Bc,t),!!globalThis.document||t.singleProcess){let r=new BroadcastChannel(Yn),n=new le;return r.addEventListener("message",zi(n,r,"requestReadLock","abortReadLockRequest",Fn,zn,Vn,jn,qn)),r.addEventListener("message",zi(n,r,"requestWriteLock","abortWriteLockRequest",Hn,Kn,Qn,Wn,Gn)),n}return new Xn(t.name)};var ht=new Map,mr;function Pc(t){return typeof t?.readLock=="function"&&typeof t?.writeLock=="function"}function Qh(t){if(mr==null&&(mr=Dc(t),!Pc(mr))){let e=mr;e.addEventListener("requestReadLock",r=>{let n=r.detail.name,o=r.detail.identifier,i=ht.get(n);if(i==null)return;let s=new AbortController,a=c=>{c.detail.name!==n||c.detail.identifier!==o||s.abort()};e.addEventListener("abortReadLockRequest",a),i.readLock({signal:s.signal}).then(async c=>{await r.detail.handler().finally(()=>{c()})}).catch(c=>{r.detail.onError(c)}).finally(()=>{e.removeEventListener("abortReadLockRequest",a)})}),e.addEventListener("requestWriteLock",r=>{let n=r.detail.name,o=r.detail.identifier,i=ht.get(n);if(i==null)return;let s=new AbortController,a=c=>{c.detail.name!==n||c.detail.identifier!==o||s.abort()};e.addEventListener("abortWriteLockRequest",a),i.writeLock({signal:s.signal}).then(async c=>{await r.detail.handler().finally(()=>{c()})}).catch(c=>{r.detail.onError(c)}).finally(()=>{e.removeEventListener("abortWriteLockRequest",a)})}),e.addEventListener("finalizeRequest",r=>{let n=r.detail.name,o=ht.get(n);o?.finalize()})}return mr}async function ji(t,e){let r,n,o=new Promise((s,a)=>{r=s,n=a}),i=()=>{n(new te)};return e?.signal?.addEventListener("abort",i,{once:!0}),t.add(async()=>{await new Promise(s=>{r(()=>{e?.signal?.removeEventListener("abort",i),s()})})},{signal:e?.signal}).catch(s=>{n(s)}),o}var $c=(t,e)=>{let r=ht.get(t);if(r!=null)return r;let n=Qh(e);if(Pc(n))return r=n,ht.set(t,r),r;let o=new pr({concurrency:1}),i;return r={async readLock(s){if(i!=null)return ji(i,s);i=new pr({concurrency:e.concurrency,autoStart:!1});let a=i,c=ji(i,s);return o.add(async()=>{a.start(),await a.onIdle().then(()=>{i===a&&(i=null)})}),c},async writeLock(s){return i=null,ji(o,s)},finalize:()=>{ht.delete(t)},queue:o},ht.set(t,r),e.autoFinalize===!0&&o.addEventListener("idle",()=>{r.finalize()},{once:!0}),r};var Jh={name:"lock",concurrency:1/0,singleProcess:!1,autoFinalize:!1};function qi(t){let e=Object.assign({},Jh,t);return $c(e.name,e)}var Zn=class{lock;child;pins;started;constructor(e,r,n={}){this.child=e,this.pins=r,this.lock=qi({singleProcess:n.holdGcLock}),this.started=!1}isStarted(){return this.started}async start(){await We(this.child),this.started=!0}async stop(){await Ge(this.child),this.started=!1}unwrap(){return this.child}async put(e,r,n={}){n?.signal?.throwIfAborted();let o=await this.lock.readLock();try{return await this.child.put(e,r,n)}finally{o()}}async*putMany(e,r={}){r?.signal?.throwIfAborted();let n=await this.lock.readLock();try{yield*this.child.putMany(e,r)}finally{n()}}async*get(e,r={}){r?.signal?.throwIfAborted();let n=await this.lock.readLock();try{yield*this.child.get(e,r)}finally{n()}}async*getMany(e,r={}){r?.signal?.throwIfAborted();let n=await this.lock.readLock();try{yield*this.child.getMany(e,r)}finally{n()}}async delete(e,r={}){r?.signal?.throwIfAborted();let n=await this.lock.writeLock();try{if(await this.pins.isPinned(e))throw new dr("Block was pinned - please unpin and try again");await this.child.delete(e,r)}finally{n()}}async*deleteMany(e,r={}){r?.signal?.throwIfAborted();let n=await this.lock.writeLock();try{let o=this;yield*this.child.deleteMany((async function*(){for await(let i of e){if(await o.pins.isPinned(i))throw new dr("Block was pinned - please unpin and try again");yield i}})(),r)}finally{n()}}async has(e,r={}){r?.signal?.throwIfAborted();let n=await this.lock.readLock();try{return await this.child.has(e,r)}finally{n()}}async*getAll(e={}){e?.signal?.throwIfAborted();let r=await this.lock.readLock();try{yield*this.child.getAll(e)}finally{r()}}createSession(e,r){return r?.signal?.throwIfAborted(),this.child.createSession(e,r)}};var Vi=new je("/version"),Mc=1;async function Oc(t){if(!await t.has(Vi)){await t.put(Vi,W(`${Mc}`));return}let e=await t.get(Vi),r=Je(e);if(parseInt(r,10)!==Mc)throw new In("Invalid datastore version, a datastore migration may be required")}var ss={};M(ss,{code:()=>is,decode:()=>qp,decodeOptions:()=>Fp,encode:()=>jp,encodeOptions:()=>Mp,name:()=>zp,toByteView:()=>Ku});var Yh=["Object","RegExp","Date","Error","Map","Set","WeakMap","WeakSet","ArrayBuffer","SharedArrayBuffer","DataView","Promise","URL","HTMLElement","Int8Array","Uint8ClampedArray","Int16Array","Uint16Array","Int32Array","Uint32Array","Float32Array","Float64Array","BigInt64Array","BigUint64Array"];function Hi(t){if(t===null)return"null";if(t===void 0)return"undefined";if(t===!0||t===!1)return"boolean";let e=typeof t;if(e==="string"||e==="number"||e==="bigint"||e==="symbol")return e;if(e==="function")return"Function";if(Array.isArray(t))return"Array";if(t instanceof Uint8Array)return"Uint8Array";if(t.constructor===Object)return"Object";let r=Xh(t);return r||"Object"}function Xh(t){let e=Object.prototype.toString.call(t).slice(8,-1);if(Yh.includes(e))return e}var f=class{constructor(e,r,n){this.major=e,this.majorEncoded=e<<5,this.name=r,this.terminal=n}toString(){return`Type[${this.major}].${this.name}`}compare(e){return this.major<e.major?-1:this.major>e.major?1:0}static equals(e,r){return e===r||e.major===r.major&&e.name===r.name}};f.uint=new f(0,"uint",!0);f.negint=new f(1,"negint",!0);f.bytes=new f(2,"bytes",!0);f.string=new f(3,"string",!0);f.array=new f(4,"array",!1);f.map=new f(5,"map",!1);f.tag=new f(6,"tag",!1);f.float=new f(7,"float",!0);f.false=new f(7,"false",!0);f.true=new f(7,"true",!0);f.null=new f(7,"null",!0);f.undefined=new f(7,"undefined",!0);f.break=new f(7,"break",!0);var b=class{constructor(e,r,n){this.type=e,this.value=r,this.encodedLength=n,this.encodedBytes=void 0,this.byteValue=void 0}toString(){return`Token[${this.type}].${this.value}`}};var gr=globalThis.process&&!globalThis.process.browser&&globalThis.Buffer&&typeof globalThis.Buffer.isBuffer=="function",Zh=new TextEncoder;function eo(t){return gr&&globalThis.Buffer.isBuffer(t)}function yr(t){return t instanceof Uint8Array?eo(t)?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):t:Uint8Array.from(t)}var ep=24,tp=200,to=gr?t=>t.length>=ep?globalThis.Buffer.from(t):Fc(t):t=>t.length>=tp?Zh.encode(t):Fc(t),Re=t=>Uint8Array.from(t),zc=gr?(t,e,r)=>eo(t)?new Uint8Array(t.subarray(e,r)):t.slice(e,r):(t,e,r)=>t.slice(e,r),jc=gr?(t,e)=>(t=t.map(r=>r instanceof Uint8Array?r:globalThis.Buffer.from(r)),yr(globalThis.Buffer.concat(t,e))):(t,e)=>{let r=new Uint8Array(e),n=0;for(let o of t)n+o.length>r.length&&(o=o.subarray(0,r.length-n)),r.set(o,n),n+=o.length;return r},qc=gr?t=>globalThis.Buffer.allocUnsafe(t):t=>new Uint8Array(t);function ro(t,e){if(eo(t)&&eo(e))return t.compare(e);for(let r=0;r<t.length;r++)if(t[r]!==e[r])return t[r]<e[r]?-1:1;return 0}function Fc(t){let e=[],r=0;for(let n=0;n<t.length;n++){let o=t.charCodeAt(n);o<128?e[r++]=o:o<2048?(e[r++]=o>>6|192,e[r++]=o&63|128):(o&64512)===55296&&n+1<t.length&&(t.charCodeAt(n+1)&64512)===56320?(o=65536+((o&1023)<<10)+(t.charCodeAt(++n)&1023),e[r++]=o>>18|240,e[r++]=o>>12&63|128,e[r++]=o>>6&63|128,e[r++]=o&63|128):(o>=55296&&o<=57343&&(o=65533),e[r++]=o>>12|224,e[r++]=o>>6&63|128,e[r++]=o&63|128)}return e}var rp=256,wr=class{constructor(e=rp){this.chunkSize=e,this.cursor=0,this.maxCursor=-1,this.chunks=[],this._initReuseChunk=null}reset(){this.cursor=0,this.maxCursor=-1,this.chunks.length&&(this.chunks=[]),this._initReuseChunk!==null&&(this.chunks.push(this._initReuseChunk),this.maxCursor=this._initReuseChunk.length-1)}push(e){let r=this.chunks[this.chunks.length-1];if(this.cursor+e.length<=this.maxCursor+1){let o=r.length-(this.maxCursor-this.cursor)-1;r.set(e,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)}e.length<64&&e.length<this.chunkSize?(r=qc(this.chunkSize),this.chunks.push(r),this.maxCursor+=r.length,this._initReuseChunk===null&&(this._initReuseChunk=r),r.set(e,0)):(this.chunks.push(e),this.maxCursor+=e.length)}this.cursor+=e.length}toBytes(e=!1){let r;if(this.chunks.length===1){let n=this.chunks[0];e&&this.cursor>n.length/2?(r=this.cursor===n.length?n:n.subarray(0,this.cursor),this._initReuseChunk=null,this.chunks=[]):r=zc(n,0,this.cursor)}else r=jc(this.chunks,this.cursor);return e&&this.reset(),r}},no=class{constructor(e){this.dest=e,this.cursor=0,this.chunks=[e]}reset(){this.cursor=0}push(e){if(this.cursor+e.length>this.dest.length)throw new Error("write out of bounds, destination buffer is too small");this.dest.set(e,this.cursor),this.cursor+=e.length}toBytes(e=!1){let r=this.dest.subarray(0,this.cursor);return e&&this.reset(),r}};var v="CBOR decode error:",oo="CBOR encode error:",xr=[];xr[23]=1;xr[24]=2;xr[25]=3;xr[26]=5;xr[27]=9;function qe(t,e,r){if(t.length-e<r)throw new Error(`${v} not enough data for type`)}var F=[24,256,65536,4294967296,BigInt("18446744073709551616")];function re(t,e,r){qe(t,e,1);let n=t[e];if(r.strict===!0&&n<F[0])throw new Error(`${v} integer encoded in more bytes than necessary (strict decode)`);return n}function ne(t,e,r){qe(t,e,2);let n=t[e]<<8|t[e+1];if(r.strict===!0&&n<F[1])throw new Error(`${v} integer encoded in more bytes than necessary (strict decode)`);return n}function oe(t,e,r){qe(t,e,4);let n=t[e]*16777216+(t[e+1]<<16)+(t[e+2]<<8)+t[e+3];if(r.strict===!0&&n<F[2])throw new Error(`${v} integer encoded in more bytes than necessary (strict decode)`);return n}function ie(t,e,r){qe(t,e,8);let n=t[e]*16777216+(t[e+1]<<16)+(t[e+2]<<8)+t[e+3],o=t[e+4]*16777216+(t[e+5]<<16)+(t[e+6]<<8)+t[e+7],i=(BigInt(n)<<BigInt(32))+BigInt(o);if(r.strict===!0&&i<F[3])throw new Error(`${v} integer encoded in more bytes than necessary (strict decode)`);if(i<=Number.MAX_SAFE_INTEGER)return Number(i);if(r.allowBigInt===!0)return i;throw new Error(`${v} integers outside of the safe integer range are not supported`)}function Vc(t,e,r,n){return new b(f.uint,re(t,e+1,n),2)}function Hc(t,e,r,n){return new b(f.uint,ne(t,e+1,n),3)}function Kc(t,e,r,n){return new b(f.uint,oe(t,e+1,n),5)}function Wc(t,e,r,n){return new b(f.uint,ie(t,e+1,n),9)}function pe(t,e){return R(t,0,e.value)}function R(t,e,r){if(r<F[0]){let n=Number(r);t.push([e|n])}else if(r<F[1]){let n=Number(r);t.push([e|24,n])}else if(r<F[2]){let n=Number(r);t.push([e|25,n>>>8,n&255])}else if(r<F[3]){let n=Number(r);t.push([e|26,n>>>24&255,n>>>16&255,n>>>8&255,n&255])}else{let n=BigInt(r);if(n<F[4]){let o=[e|27,0,0,0,0,0,0,0],i=Number(n&BigInt(4294967295)),s=Number(n>>BigInt(32)&BigInt(4294967295));o[8]=i&255,i=i>>8,o[7]=i&255,i=i>>8,o[6]=i&255,i=i>>8,o[5]=i&255,o[4]=s&255,s=s>>8,o[3]=s&255,s=s>>8,o[2]=s&255,s=s>>8,o[1]=s&255,t.push(o)}else throw new Error(`${v} encountered BigInt larger than allowable range`)}}pe.encodedSize=function(e){return R.encodedSize(e.value)};R.encodedSize=function(e){return e<F[0]?1:e<F[1]?2:e<F[2]?3:e<F[3]?5:9};pe.compareTokens=function(e,r){return e.value<r.value?-1:e.value>r.value?1:0};function Gc(t,e,r,n){return new b(f.negint,-1-re(t,e+1,n),2)}function Qc(t,e,r,n){return new b(f.negint,-1-ne(t,e+1,n),3)}function Jc(t,e,r,n){return new b(f.negint,-1-oe(t,e+1,n),5)}var Ki=BigInt(-1),Yc=BigInt(1);function Xc(t,e,r,n){let o=ie(t,e+1,n);if(typeof o!="bigint"){let i=-1-o;if(i>=Number.MIN_SAFE_INTEGER)return new b(f.negint,i,9)}if(n.allowBigInt!==!0)throw new Error(`${v} integers outside of the safe integer range are not supported`);return new b(f.negint,Ki-BigInt(o),9)}function io(t,e){let r=e.value,n=typeof r=="bigint"?r*Ki-Yc:r*-1-1;R(t,e.type.majorEncoded,n)}io.encodedSize=function(e){let r=e.value,n=typeof r=="bigint"?r*Ki-Yc:r*-1-1;return n<F[0]?1:n<F[1]?2:n<F[2]?3:n<F[3]?5:9};io.compareTokens=function(e,r){return e.value<r.value?1:e.value>r.value?-1:0};function br(t,e,r,n){qe(t,e,r+n);let o=t.slice(e+r,e+r+n);return new b(f.bytes,o,r+n)}function Zc(t,e,r,n){return br(t,e,1,r)}function eu(t,e,r,n){return br(t,e,2,re(t,e+1,n))}function tu(t,e,r,n){return br(t,e,3,ne(t,e+1,n))}function ru(t,e,r,n){return br(t,e,5,oe(t,e+1,n))}function nu(t,e,r,n){let o=ie(t,e+1,n);if(typeof o=="bigint")throw new Error(`${v} 64-bit integer bytes lengths not supported`);return br(t,e,9,o)}function so(t){return t.encodedBytes===void 0&&(t.encodedBytes=f.equals(t.type,f.string)?to(t.value):t.value),t.encodedBytes}function Lt(t,e){let r=so(e);R(t,e.type.majorEncoded,r.length),t.push(r)}Lt.encodedSize=function(e){let r=so(e);return R.encodedSize(r.length)+r.length};Lt.compareTokens=function(e,r){return op(so(e),so(r))};function op(t,e){return t.length<e.length?-1:t.length>e.length?1:ro(t,e)}var ou=new TextDecoder,sp=32;function ap(t,e,r){if(r-e<sp){let o="";for(let i=e;i<r;i++){let s=t[i];if(s&128)return ou.decode(t.subarray(e,r));o+=String.fromCharCode(s)}return o}return ou.decode(t.subarray(e,r))}function Er(t,e,r,n,o){let i=r+n;qe(t,e,i);let s=new b(f.string,ap(t,e+r,e+i),i);return o.retainStringBytes===!0&&(s.byteValue=t.slice(e+r,e+i)),s}function iu(t,e,r,n){return Er(t,e,1,r,n)}function su(t,e,r,n){return Er(t,e,2,re(t,e+1,n),n)}function au(t,e,r,n){return Er(t,e,3,ne(t,e+1,n),n)}function cu(t,e,r,n){return Er(t,e,5,oe(t,e+1,n),n)}function uu(t,e,r,n){let o=ie(t,e+1,n);if(typeof o=="bigint")throw new Error(`${v} 64-bit integer string lengths not supported`);return Er(t,e,9,o,n)}var fu=Lt;function Bt(t,e,r,n){return new b(f.array,n,r)}function lu(t,e,r,n){return Bt(t,e,1,r)}function du(t,e,r,n){return Bt(t,e,2,re(t,e+1,n))}function hu(t,e,r,n){return Bt(t,e,3,ne(t,e+1,n))}function pu(t,e,r,n){return Bt(t,e,5,oe(t,e+1,n))}function mu(t,e,r,n){let o=ie(t,e+1,n);if(typeof o=="bigint")throw new Error(`${v} 64-bit integer array lengths not supported`);return Bt(t,e,9,o)}function gu(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${v} indefinite length items not allowed`);return Bt(t,e,1,1/0)}function ao(t,e){R(t,f.array.majorEncoded,e.value)}ao.compareTokens=pe.compareTokens;ao.encodedSize=function(e){return R.encodedSize(e.value)};function Rt(t,e,r,n){return new b(f.map,n,r)}function yu(t,e,r,n){return Rt(t,e,1,r)}function wu(t,e,r,n){return Rt(t,e,2,re(t,e+1,n))}function xu(t,e,r,n){return Rt(t,e,3,ne(t,e+1,n))}function bu(t,e,r,n){return Rt(t,e,5,oe(t,e+1,n))}function Eu(t,e,r,n){let o=ie(t,e+1,n);if(typeof o=="bigint")throw new Error(`${v} 64-bit integer map lengths not supported`);return Rt(t,e,9,o)}function _u(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${v} indefinite length items not allowed`);return Rt(t,e,1,1/0)}function co(t,e){R(t,f.map.majorEncoded,e.value)}co.compareTokens=pe.compareTokens;co.encodedSize=function(e){return R.encodedSize(e.value)};function vu(t,e,r,n){return new b(f.tag,r,1)}function ku(t,e,r,n){return new b(f.tag,re(t,e+1,n),2)}function Au(t,e,r,n){return new b(f.tag,ne(t,e+1,n),3)}function Tu(t,e,r,n){return new b(f.tag,oe(t,e+1,n),5)}function Iu(t,e,r,n){return new b(f.tag,ie(t,e+1,n),9)}function uo(t,e){R(t,f.tag.majorEncoded,e.value)}uo.compareTokens=pe.compareTokens;uo.encodedSize=function(e){return R.encodedSize(e.value)};var Wi=20,Gi=21,Qi=22,Ji=23;function Su(t,e,r,n){if(n.allowUndefined===!1)throw new Error(`${v} undefined values are not supported`);return n.coerceUndefinedToNull===!0?new b(f.null,null,1):new b(f.undefined,void 0,1)}function Uu(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${v} indefinite length items not allowed`);return new b(f.break,void 0,1)}function Yi(t,e,r){if(r){if(r.allowNaN===!1&&Number.isNaN(t))throw new Error(`${v} NaN values are not supported`);if(r.allowInfinity===!1&&(t===1/0||t===-1/0))throw new Error(`${v} Infinity values are not supported`)}return new b(f.float,t,e)}function Nu(t,e,r,n){return Yi(Xi(t,e+1),3,n)}function Cu(t,e,r,n){return Yi(Zi(t,e+1),5,n)}function Lu(t,e,r,n){return Yi(Pu(t,e+1),9,n)}function _r(t,e,r){let n=e.value;if(n===!1)t.push([f.float.majorEncoded|Wi]);else if(n===!0)t.push([f.float.majorEncoded|Gi]);else if(n===null)t.push([f.float.majorEncoded|Qi]);else if(n===void 0)t.push([f.float.majorEncoded|Ji]);else{let o,i=!1;(!r||r.float64!==!0)&&(Ru(n),o=Xi(Te,1),n===o||Number.isNaN(n)?(Te[0]=249,t.push(Te.slice(0,3)),i=!0):(Du(n),o=Zi(Te,1),n===o&&(Te[0]=250,t.push(Te.slice(0,5)),i=!0))),i||(dp(n),o=Pu(Te,1),Te[0]=251,t.push(Te.slice(0,9)))}}_r.encodedSize=function(e,r){let n=e.value;if(n===!1||n===!0||n===null||n===void 0)return 1;if(!r||r.float64!==!0){Ru(n);let o=Xi(Te,1);if(n===o||Number.isNaN(n))return 3;if(Du(n),o=Zi(Te,1),n===o)return 5}return 9};var Bu=new ArrayBuffer(9),me=new DataView(Bu,1),Te=new Uint8Array(Bu,0);function Ru(t){if(t===1/0)me.setUint16(0,31744,!1);else if(t===-1/0)me.setUint16(0,64512,!1);else if(Number.isNaN(t))me.setUint16(0,32256,!1);else{me.setFloat32(0,t);let e=me.getUint32(0),r=(e&2139095040)>>23,n=e&8388607;if(r===255)me.setUint16(0,31744,!1);else if(r===0)me.setUint16(0,(e&2147483648)>>16|n>>13,!1);else{let o=r-127;o<-24?me.setUint16(0,0):o<-14?me.setUint16(0,(e&2147483648)>>16|1<<24+o,!1):me.setUint16(0,(e&2147483648)>>16|o+15<<10|n>>13,!1)}}}function Xi(t,e){if(t.length-e<2)throw new Error(`${v} not enough data for float16`);let r=(t[e]<<8)+t[e+1];if(r===31744)return 1/0;if(r===64512)return-1/0;if(r===32256)return NaN;let n=r>>10&31,o=r&1023,i;return n===0?i=o*2**-24:n!==31?i=(o+1024)*2**(n-25):i=o===0?1/0:NaN,r&32768?-i:i}function Du(t){me.setFloat32(0,t,!1)}function Zi(t,e){if(t.length-e<4)throw new Error(`${v} not enough data for float32`);let r=(t.byteOffset||0)+e;return new DataView(t.buffer,r,4).getFloat32(0,!1)}function dp(t){me.setFloat64(0,t,!1)}function Pu(t,e){if(t.length-e<8)throw new Error(`${v} not enough data for float64`);let r=(t.byteOffset||0)+e;return new DataView(t.buffer,r,8).getFloat64(0,!1)}_r.compareTokens=pe.compareTokens;function N(t,e,r){throw new Error(`${v} encountered invalid minor (${r}) for major ${t[e]>>>5}`)}function fo(t){return()=>{throw new Error(`${v} ${t}`)}}var y=[];for(let t=0;t<=23;t++)y[t]=N;y[24]=Vc;y[25]=Hc;y[26]=Kc;y[27]=Wc;y[28]=N;y[29]=N;y[30]=N;y[31]=N;for(let t=32;t<=55;t++)y[t]=N;y[56]=Gc;y[57]=Qc;y[58]=Jc;y[59]=Xc;y[60]=N;y[61]=N;y[62]=N;y[63]=N;for(let t=64;t<=87;t++)y[t]=Zc;y[88]=eu;y[89]=tu;y[90]=ru;y[91]=nu;y[92]=N;y[93]=N;y[94]=N;y[95]=fo("indefinite length bytes/strings are not supported");for(let t=96;t<=119;t++)y[t]=iu;y[120]=su;y[121]=au;y[122]=cu;y[123]=uu;y[124]=N;y[125]=N;y[126]=N;y[127]=fo("indefinite length bytes/strings are not supported");for(let t=128;t<=151;t++)y[t]=lu;y[152]=du;y[153]=hu;y[154]=pu;y[155]=mu;y[156]=N;y[157]=N;y[158]=N;y[159]=gu;for(let t=160;t<=183;t++)y[t]=yu;y[184]=wu;y[185]=xu;y[186]=bu;y[187]=Eu;y[188]=N;y[189]=N;y[190]=N;y[191]=_u;for(let t=192;t<=215;t++)y[t]=vu;y[216]=ku;y[217]=Au;y[218]=Tu;y[219]=Iu;y[220]=N;y[221]=N;y[222]=N;y[223]=N;for(let t=224;t<=243;t++)y[t]=fo("simple values are not supported");y[244]=N;y[245]=N;y[246]=N;y[247]=Su;y[248]=fo("simple values are not supported");y[249]=Nu;y[250]=Cu;y[251]=Lu;y[252]=N;y[253]=N;y[254]=N;y[255]=Uu;var Ie=[];for(let t=0;t<24;t++)Ie[t]=new b(f.uint,t,1);for(let t=-1;t>=-24;t--)Ie[31-t]=new b(f.negint,t,1);Ie[64]=new b(f.bytes,new Uint8Array(0),1);Ie[96]=new b(f.string,"",1);Ie[128]=new b(f.array,0,1);Ie[160]=new b(f.map,0,1);Ie[244]=new b(f.false,!1,1);Ie[245]=new b(f.true,!0,1);Ie[246]=new b(f.null,null,1);function es(t){switch(t.type){case f.false:return Re([244]);case f.true:return Re([245]);case f.null:return Re([246]);case f.bytes:return t.value.length?void 0:Re([64]);case f.string:return t.value===""?Re([96]):void 0;case f.array:return t.value===0?Re([128]):void 0;case f.map:return t.value===0?Re([160]):void 0;case f.uint:return t.value<24?Re([Number(t.value)]):void 0;case f.negint:if(t.value>=-24)return Re([31-Number(t.value)])}}var pp={float64:!1,mapSorter:yp,quickEncodeToken:es},zu=Object.freeze({float64:!0,mapSorter:wp,quickEncodeToken:es});function mp(){let t=[];return t[f.uint.major]=pe,t[f.negint.major]=io,t[f.bytes.major]=Lt,t[f.string.major]=fu,t[f.array.major]=ao,t[f.map.major]=co,t[f.tag.major]=uo,t[f.float.major]=_r,t}var Dt=mp(),lo=new wr,kr=class t{constructor(e,r){this.obj=e,this.parent=r}includes(e){let r=this;do if(r.obj===e)return!0;while(r=r.parent);return!1}static createCheck(e,r){if(e&&e.includes(r))throw new Error(`${oo} object contains circular references`);return new t(r,e)}},Xe={null:new b(f.null,null),undefined:new b(f.undefined,void 0),true:new b(f.true,!0),false:new b(f.false,!1),emptyArray:new b(f.array,0),emptyMap:new b(f.map,0)},De={number(t,e,r,n){return!Number.isInteger(t)||!Number.isSafeInteger(t)?new b(f.float,t):t>=0?new b(f.uint,t):new b(f.negint,t)},bigint(t,e,r,n){return t>=BigInt(0)?new b(f.uint,t):new b(f.negint,t)},Uint8Array(t,e,r,n){return new b(f.bytes,t)},string(t,e,r,n){return new b(f.string,t)},boolean(t,e,r,n){return t?Xe.true:Xe.false},null(t,e,r,n){return Xe.null},undefined(t,e,r,n){return Xe.undefined},ArrayBuffer(t,e,r,n){return new b(f.bytes,new Uint8Array(t))},DataView(t,e,r,n){return new b(f.bytes,new Uint8Array(t.buffer,t.byteOffset,t.byteLength))},Array(t,e,r,n){if(!t.length)return r.addBreakTokens===!0?[Xe.emptyArray,new b(f.break)]:Xe.emptyArray;n=kr.createCheck(n,t);let o=[],i=0;for(let s of t)o[i++]=ho(s,r,n);return r.addBreakTokens?[new b(f.array,t.length),o,new b(f.break)]:[new b(f.array,t.length),o]},Object(t,e,r,n){let o=e!=="Object",i=o?t.keys():Object.keys(t),s=o?t.size:i.length,a;if(s){a=new Array(s),n=kr.createCheck(n,t);let c=!o&&r.ignoreUndefinedProperties,l=0;for(let p of i){let m=o?t.get(p):t[p];c&&m===void 0||(a[l++]=[ho(p,r,n),ho(m,r,n)])}l<s&&(a.length=l)}return a?.length?(gp(a,r),r.addBreakTokens?[new b(f.map,a.length),a,new b(f.break)]:[new b(f.map,a.length),a]):r.addBreakTokens===!0?[Xe.emptyMap,new b(f.break)]:Xe.emptyMap}};De.Map=De.Object;De.Buffer=De.Uint8Array;for(let t of"Uint8Clamped Uint16 Uint32 Int8 Int16 Int32 BigUint64 BigInt64 Float32 Float64".split(" "))De[`${t}Array`]=De.DataView;function ho(t,e={},r){let n=Hi(t),o=e&&e.typeEncoders&&e.typeEncoders[n]||De[n];if(typeof o=="function"){let s=o(t,n,e,r);if(s!=null)return s}let i=De[n];if(!i)throw new Error(`${oo} unsupported type: ${n}`);return i(t,n,e,r)}function gp(t,e){e.mapSorter&&t.sort(e.mapSorter)}function yp(t,e){let r=Array.isArray(t[0])?t[0][0]:t[0],n=Array.isArray(e[0])?e[0][0]:e[0];if(r.type!==n.type)return r.type.compare(n.type);let o=r.type.major,i=Dt[o].compareTokens(r,n);return i===0&&console.warn("WARNING: complex key types used, CBOR key sorting guarantees are gone"),i}function wp(t,e){if(t[0]instanceof b&&e[0]instanceof b){let r=t[0],n=e[0];return r._keyBytes||(r._keyBytes=$u(r.value)),n._keyBytes||(n._keyBytes=$u(n.value)),ro(r._keyBytes,n._keyBytes)}throw new Error("rfc8949MapSorter: complex key types are not supported yet")}function $u(t){return qu(t,Dt,zu)}function vr(t,e,r,n){if(Array.isArray(e))for(let o of e)vr(t,o,r,n);else r[e.type.major](t,e,n)}var Mu=f.uint.majorEncoded,Ou=f.negint.majorEncoded,xp=f.bytes.majorEncoded,bp=f.string.majorEncoded,Fu=f.array.majorEncoded,Ep=f.float.majorEncoded|Wi,_p=f.float.majorEncoded|Gi,vp=f.float.majorEncoded|Qi,kp=f.float.majorEncoded|Ji,Ap=BigInt(-1),Tp=BigInt(1);function Ip(t){return t.addBreakTokens!==!0}function ju(t,e,r,n){let o=Hi(e),i=r.typeEncoders&&r.typeEncoders[o];if(i){let s=i(e,o,r,n);if(s!=null){vr(t,s,Dt,r);return}}switch(o){case"null":t.push([vp]);return;case"undefined":t.push([kp]);return;case"boolean":t.push([e?_p:Ep]);return;case"number":!Number.isInteger(e)||!Number.isSafeInteger(e)?_r(t,new b(f.float,e),r):e>=0?R(t,Mu,e):R(t,Ou,e*-1-1);return;case"bigint":e>=BigInt(0)?R(t,Mu,e):R(t,Ou,e*Ap-Tp);return;case"string":{let s=to(e);R(t,bp,s.length),t.push(s);return}case"Uint8Array":R(t,xp,e.length),t.push(e);return;case"Array":if(!e.length){t.push([Fu]);return}n=kr.createCheck(n,e),R(t,Fu,e.length);for(let s of e)ju(t,s,r,n);return;case"Object":case"Map":{let s=De.Object(e,o,r,n);vr(t,s,Dt,r)}return;default:{let s=De[o];if(!s)throw new Error(`${oo} unsupported type: ${o}`);let a=s(e,o,r,n);vr(t,a,Dt,r)}}}function qu(t,e,r,n){let o=n instanceof Uint8Array,i=o?new no(n):lo,s=ho(t,r);if(!Array.isArray(s)&&r.quickEncodeToken){let a=r.quickEncodeToken(s);if(a)return o?(i.push(a),i.toBytes()):a;let c=e[s.type.major];if(c.encodedSize){let l=c.encodedSize(s,r);if(o||(i=new wr(l)),c(i,s,r),i.chunks.length!==1)throw new Error(`Unexpected error: pre-calculated length for ${s} was wrong`);return o?i.toBytes():yr(i.chunks[0])}}return i.reset(),vr(i,s,e,r),i.toBytes(!0)}function ts(t,e){return e=Object.assign({},pp,e),Ip(e)?(lo.reset(),ju(lo,t,e,void 0),lo.toBytes(!0)):qu(t,Dt,e)}var Sp={strict:!1,allowIndefinite:!0,allowUndefined:!0,allowBigInt:!0},po=class{constructor(e,r={}){this._pos=0,this.data=e,this.options=r}pos(){return this._pos}done(){return this._pos>=this.data.length}next(){let e=this.data[this._pos],r=Ie[e];if(r===void 0){let n=y[e];if(!n)throw new Error(`${v} no decoder for major type ${e>>>5} (byte 0x${e.toString(16).padStart(2,"0")})`);let o=e&31;r=n(this.data,this._pos,o,this.options)}return this._pos+=r.encodedLength,r}},Ze=Symbol.for("DONE"),Pt=Symbol.for("BREAK");function Up(t,e,r){let n=[];for(let o=0;o<t.value;o++){let i=et(e,r);if(i===Pt){if(t.value===1/0)break;throw new Error(`${v} got unexpected break to lengthed array`)}if(i===Ze)throw new Error(`${v} found array but not enough entries (got ${o}, expected ${t.value})`);n[o]=i}return n}function Np(t,e,r){let n=r.useMaps===!0,o=r.rejectDuplicateMapKeys===!0,i=n?void 0:{},s=n?new Map:void 0;for(let a=0;a<t.value;a++){let c=et(e,r);if(c===Pt){if(t.value===1/0)break;throw new Error(`${v} got unexpected break to lengthed map`)}if(c===Ze)throw new Error(`${v} found map but not enough entries (got ${a} [no key], expected ${t.value})`);if(!n&&typeof c!="string")throw new Error(`${v} non-string keys not supported (got ${typeof c})`);if(o&&(n&&s.has(c)||!n&&Object.hasOwn(i,c)))throw new Error(`${v} found repeat map key "${c}"`);let l=et(e,r);if(l===Ze)throw new Error(`${v} found map but not enough entries (got ${a} [no value], expected ${t.value})`);n?s.set(c,l):i[c]=l}return n?s:i}function*Cp(t,e,r){for(let n=0;n<t.value;n++){let o=et(e,r);if(o===Pt){if(t.value===1/0)break;throw new Error(`${v} got unexpected break to lengthed map`)}if(o===Ze)throw new Error(`${v} found map but not enough entries (got ${n} [no key], expected ${t.value})`);let i=et(e,r);if(i===Ze)throw new Error(`${v} found map but not enough entries (got ${n} [no value], expected ${t.value})`);yield[o,i]}}function Lp(t,e){let r=!1,n=function(){if(r)throw new Error(`${v} tag decode() may only be called once`);r=!0;let o=et(t,e);if(o===Ze)throw new Error(`${v} tag content missing`);if(o===Pt)throw new Error(`${v} got unexpected break in tag content`);return o};return n.entries=function(){if(r)throw new Error(`${v} tag decode() may only be called once`);r=!0;let o=t.next();if(!f.equals(o.type,f.map))throw new Error(`${v} entries() requires map content, got ${o.type.name}`);let i=[];for(let s of Cp(o,t,e))i.push(s);return i},Object.defineProperty(n,"_called",{get(){return r},enumerable:!1}),n}function et(t,e){if(t.done())return Ze;let r=t.next();if(f.equals(r.type,f.break))return Pt;if(r.type.terminal)return r.value;if(f.equals(r.type,f.array))return Up(r,t,e);if(f.equals(r.type,f.map))return Np(r,t,e);if(f.equals(r.type,f.tag)){if(e.tags&&typeof e.tags[r.value]=="function"){let n=Lp(t,e),o=e.tags[r.value](n);if(!n._called)throw new Error(`${v} tag decoder must call decode() or entries()`);return o}throw new Error(`${v} tag not supported (${r.value})`)}throw new Error("unsupported")}function Vu(t,e){if(!(t instanceof Uint8Array))throw new Error(`${v} data to decode must be a Uint8Array`);e=Object.assign({},Sp,e);let r=yr(t),n=e.tokenizer||new po(r,e),o=et(n,e);if(o===Ze)throw new Error(`${v} did not find any content to decode`);if(o===Pt)throw new Error(`${v} got unexpected break`);return[o,t.subarray(n.pos())]}function rs(t,e){let[r,n]=Vu(t,e);if(n.length>0)throw new Error(`${v} too many terminals, data makes no sense`);return r}var Hu=42;function Ku(t){return t instanceof ArrayBuffer?new Uint8Array(t,0,t.byteLength):t}function Rp(t){if(t.asCID!==t&&t["/"]!==t.bytes)return null;let e=L.asCID(t);if(!e)return null;let r=new Uint8Array(e.bytes.byteLength+1);return r.set(e.bytes,1),[new b(f.tag,Hu),new b(f.bytes,r)]}function Dp(){throw new Error("`undefined` is not supported by the IPLD Data Model and cannot be encoded")}function Pp(t){if(Number.isNaN(t))throw new Error("`NaN` is not supported by the IPLD Data Model and cannot be encoded");if(t===1/0||t===-1/0)throw new Error("`Infinity` and `-Infinity` is not supported by the IPLD Data Model and cannot be encoded");return null}function $p(t){for(let e of t.keys())if(typeof e!="string"||e.length===0)throw new Error("Non-string Map keys are not supported by the IPLD Data Model and cannot be encoded");return null}var ns={float64:!0,typeEncoders:{Map:$p,Object:Rp,undefined:Dp,number:Pp}},Mp={...ns,typeEncoders:{...ns.typeEncoders}};function Op(t){let e=t();if(e[0]!==0)throw new Error("Invalid CID for CBOR tag 42; expected leading 0x00");return L.decode(e.subarray(1))}var os={allowIndefinite:!1,coerceUndefinedToNull:!0,allowNaN:!1,allowInfinity:!1,allowBigInt:!0,strict:!0,useMaps:!1,rejectDuplicateMapKeys:!0,tags:{[Hu]:Op}},Fp={...os,tags:{...os.tags}},zp="dag-cbor",is=113,jp=t=>ts(t,ns),qp=t=>rs(Ku(t),os);var vs={};M(vs,{code:()=>_s,decode:()=>el,encode:()=>Zf,format:()=>Im,name:()=>Tm,parse:()=>Um,stringify:()=>Im});var Vp=["Object","RegExp","Date","Error","Map","Set","WeakMap","WeakSet","ArrayBuffer","SharedArrayBuffer","DataView","Promise","URL","HTMLElement","Int8Array","Uint8ClampedArray","Int16Array","Uint16Array","Int32Array","Uint32Array","Float32Array","Float64Array","BigInt64Array","BigUint64Array"];function Wu(t){if(t===null)return"null";if(t===void 0)return"undefined";if(t===!0||t===!1)return"boolean";let e=typeof t;if(e==="string"||e==="number"||e==="bigint"||e==="symbol")return e;if(e==="function")return"Function";if(Array.isArray(t))return"Array";if(t instanceof Uint8Array)return"Uint8Array";if(t.constructor===Object)return"Object";let r=Hp(t);return r||"Object"}function Hp(t){let e=Object.prototype.toString.call(t).slice(8,-1);if(Vp.includes(e))return e}var u=class{constructor(e,r,n){this.major=e,this.majorEncoded=e<<5,this.name=r,this.terminal=n}toString(){return`Type[${this.major}].${this.name}`}compare(e){return this.major<e.major?-1:this.major>e.major?1:0}static equals(e,r){return e===r||e.major===r.major&&e.name===r.name}};u.uint=new u(0,"uint",!0);u.negint=new u(1,"negint",!0);u.bytes=new u(2,"bytes",!0);u.string=new u(3,"string",!0);u.array=new u(4,"array",!1);u.map=new u(5,"map",!1);u.tag=new u(6,"tag",!1);u.float=new u(7,"float",!0);u.false=new u(7,"false",!0);u.true=new u(7,"true",!0);u.null=new u(7,"null",!0);u.undefined=new u(7,"undefined",!0);u.break=new u(7,"break",!0);var h=class{constructor(e,r,n){this.type=e,this.value=r,this.encodedLength=n,this.encodedBytes=void 0,this.byteValue=void 0}toString(){return`Token[${this.type}].${this.value}`}};var Ar=globalThis.process&&!globalThis.process.browser&&globalThis.Buffer&&typeof globalThis.Buffer.isBuffer=="function",Kp=new TextEncoder;function mo(t){return Ar&&globalThis.Buffer.isBuffer(t)}function mt(t){return t instanceof Uint8Array?mo(t)?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):t:Uint8Array.from(t)}var Wp=24,Gp=200,Tr=Ar?t=>t.length>=Wp?globalThis.Buffer.from(t):Gu(t):t=>t.length>=Gp?Kp.encode(t):Gu(t),Pe=t=>Uint8Array.from(t),Ju=Ar?(t,e,r)=>mo(t)?new Uint8Array(t.subarray(e,r)):t.slice(e,r):(t,e,r)=>t.slice(e,r),Yu=Ar?(t,e)=>(t=t.map(r=>r instanceof Uint8Array?r:globalThis.Buffer.from(r)),mt(globalThis.Buffer.concat(t,e))):(t,e)=>{let r=new Uint8Array(e),n=0;for(let o of t)n+o.length>r.length&&(o=o.subarray(0,r.length-n)),r.set(o,n),n+=o.length;return r},Xu=Ar?t=>globalThis.Buffer.allocUnsafe(t):t=>new Uint8Array(t);function go(t,e){if(mo(t)&&mo(e))return t.compare(e);for(let r=0;r<t.length;r++)if(t[r]!==e[r])return t[r]<e[r]?-1:1;return 0}function Gu(t){let e=[],r=0;for(let n=0;n<t.length;n++){let o=t.charCodeAt(n);o<128?e[r++]=o:o<2048?(e[r++]=o>>6|192,e[r++]=o&63|128):(o&64512)===55296&&n+1<t.length&&(t.charCodeAt(n+1)&64512)===56320?(o=65536+((o&1023)<<10)+(t.charCodeAt(++n)&1023),e[r++]=o>>18|240,e[r++]=o>>12&63|128,e[r++]=o>>6&63|128,e[r++]=o&63|128):(o>=55296&&o<=57343&&(o=65533),e[r++]=o>>12|224,e[r++]=o>>6&63|128,e[r++]=o&63|128)}return e}var Qu=4096;function Zu(t){let e=t.length;if(e<=Qu)return String.fromCharCode.apply(String,t);let r="",n=0;for(;n<e;)r+=String.fromCharCode.apply(String,t.slice(n,n+=Qu));return r}var Qp=256,Ir=class{constructor(e=Qp){this.chunkSize=e,this.cursor=0,this.maxCursor=-1,this.chunks=[],this._initReuseChunk=null}reset(){this.cursor=0,this.maxCursor=-1,this.chunks.length&&(this.chunks=[]),this._initReuseChunk!==null&&(this.chunks.push(this._initReuseChunk),this.maxCursor=this._initReuseChunk.length-1)}push(e){let r=this.chunks[this.chunks.length-1];if(this.cursor+e.length<=this.maxCursor+1){let o=r.length-(this.maxCursor-this.cursor)-1;r.set(e,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)}e.length<64&&e.length<this.chunkSize?(r=Xu(this.chunkSize),this.chunks.push(r),this.maxCursor+=r.length,this._initReuseChunk===null&&(this._initReuseChunk=r),r.set(e,0)):(this.chunks.push(e),this.maxCursor+=e.length)}this.cursor+=e.length}toBytes(e=!1){let r;if(this.chunks.length===1){let n=this.chunks[0];e&&this.cursor>n.length/2?(r=this.cursor===n.length?n:n.subarray(0,this.cursor),this._initReuseChunk=null,this.chunks=[]):r=Ju(n,0,this.cursor)}else r=Yu(this.chunks,this.cursor);return e&&this.reset(),r}},yo=class{constructor(e){this.dest=e,this.cursor=0,this.chunks=[e]}reset(){this.cursor=0}push(e){if(this.cursor+e.length>this.dest.length)throw new Error("write out of bounds, destination buffer is too small");this.dest.set(e,this.cursor),this.cursor+=e.length}toBytes(e=!1){let r=this.dest.subarray(0,this.cursor);return e&&this.reset(),r}};var E="CBOR decode error:",Ve="CBOR encode error:",Sr=[];Sr[23]=1;Sr[24]=2;Sr[25]=3;Sr[26]=5;Sr[27]=9;function He(t,e,r){if(t.length-e<r)throw new Error(`${E} not enough data for type`)}var z=[24,256,65536,4294967296,BigInt("18446744073709551616")];function se(t,e,r){He(t,e,1);let n=t[e];if(r.strict===!0&&n<z[0])throw new Error(`${E} integer encoded in more bytes than necessary (strict decode)`);return n}function ae(t,e,r){He(t,e,2);let n=t[e]<<8|t[e+1];if(r.strict===!0&&n<z[1])throw new Error(`${E} integer encoded in more bytes than necessary (strict decode)`);return n}function ce(t,e,r){He(t,e,4);let n=t[e]*16777216+(t[e+1]<<16)+(t[e+2]<<8)+t[e+3];if(r.strict===!0&&n<z[2])throw new Error(`${E} integer encoded in more bytes than necessary (strict decode)`);return n}function ue(t,e,r){He(t,e,8);let n=t[e]*16777216+(t[e+1]<<16)+(t[e+2]<<8)+t[e+3],o=t[e+4]*16777216+(t[e+5]<<16)+(t[e+6]<<8)+t[e+7],i=(BigInt(n)<<BigInt(32))+BigInt(o);if(r.strict===!0&&i<z[3])throw new Error(`${E} integer encoded in more bytes than necessary (strict decode)`);if(i<=Number.MAX_SAFE_INTEGER)return Number(i);if(r.allowBigInt===!0)return i;throw new Error(`${E} integers outside of the safe integer range are not supported`)}function ef(t,e,r,n){return new h(u.uint,se(t,e+1,n),2)}function tf(t,e,r,n){return new h(u.uint,ae(t,e+1,n),3)}function rf(t,e,r,n){return new h(u.uint,ce(t,e+1,n),5)}function nf(t,e,r,n){return new h(u.uint,ue(t,e+1,n),9)}function ge(t,e){return j(t,0,e.value)}function j(t,e,r){if(r<z[0]){let n=Number(r);t.push([e|n])}else if(r<z[1]){let n=Number(r);t.push([e|24,n])}else if(r<z[2]){let n=Number(r);t.push([e|25,n>>>8,n&255])}else if(r<z[3]){let n=Number(r);t.push([e|26,n>>>24&255,n>>>16&255,n>>>8&255,n&255])}else{let n=BigInt(r);if(n<z[4]){let o=[e|27,0,0,0,0,0,0,0],i=Number(n&BigInt(4294967295)),s=Number(n>>BigInt(32)&BigInt(4294967295));o[8]=i&255,i=i>>8,o[7]=i&255,i=i>>8,o[6]=i&255,i=i>>8,o[5]=i&255,o[4]=s&255,s=s>>8,o[3]=s&255,s=s>>8,o[2]=s&255,s=s>>8,o[1]=s&255,t.push(o)}else throw new Error(`${E} encountered BigInt larger than allowable range`)}}ge.encodedSize=function(e){return j.encodedSize(e.value)};j.encodedSize=function(e){return e<z[0]?1:e<z[1]?2:e<z[2]?3:e<z[3]?5:9};ge.compareTokens=function(e,r){return e.value<r.value?-1:e.value>r.value?1:0};function of(t,e,r,n){return new h(u.negint,-1-se(t,e+1,n),2)}function sf(t,e,r,n){return new h(u.negint,-1-ae(t,e+1,n),3)}function af(t,e,r,n){return new h(u.negint,-1-ce(t,e+1,n),5)}var as=BigInt(-1),cf=BigInt(1);function uf(t,e,r,n){let o=ue(t,e+1,n);if(typeof o!="bigint"){let i=-1-o;if(i>=Number.MIN_SAFE_INTEGER)return new h(u.negint,i,9)}if(n.allowBigInt!==!0)throw new Error(`${E} integers outside of the safe integer range are not supported`);return new h(u.negint,as-BigInt(o),9)}function wo(t,e){let r=e.value,n=typeof r=="bigint"?r*as-cf:r*-1-1;j(t,e.type.majorEncoded,n)}wo.encodedSize=function(e){let r=e.value,n=typeof r=="bigint"?r*as-cf:r*-1-1;return n<z[0]?1:n<z[1]?2:n<z[2]?3:n<z[3]?5:9};wo.compareTokens=function(e,r){return e.value<r.value?1:e.value>r.value?-1:0};function Ur(t,e,r,n){He(t,e,r+n);let o=t.slice(e+r,e+r+n);return new h(u.bytes,o,r+n)}function ff(t,e,r,n){return Ur(t,e,1,r)}function lf(t,e,r,n){return Ur(t,e,2,se(t,e+1,n))}function df(t,e,r,n){return Ur(t,e,3,ae(t,e+1,n))}function hf(t,e,r,n){return Ur(t,e,5,ce(t,e+1,n))}function pf(t,e,r,n){let o=ue(t,e+1,n);if(typeof o=="bigint")throw new Error(`${E} 64-bit integer bytes lengths not supported`);return Ur(t,e,9,o)}function xo(t){return t.encodedBytes===void 0&&(t.encodedBytes=u.equals(t.type,u.string)?Tr(t.value):t.value),t.encodedBytes}function $t(t,e){let r=xo(e);j(t,e.type.majorEncoded,r.length),t.push(r)}$t.encodedSize=function(e){let r=xo(e);return j.encodedSize(r.length)+r.length};$t.compareTokens=function(e,r){return Yp(xo(e),xo(r))};function Yp(t,e){return t.length<e.length?-1:t.length>e.length?1:go(t,e)}var mf=new TextDecoder,Zp=32;function em(t,e,r){if(r-e<Zp){let o="";for(let i=e;i<r;i++){let s=t[i];if(s&128)return mf.decode(t.subarray(e,r));o+=String.fromCharCode(s)}return o}return mf.decode(t.subarray(e,r))}function Nr(t,e,r,n,o){let i=r+n;He(t,e,i);let s=new h(u.string,em(t,e+r,e+i),i);return o.retainStringBytes===!0&&(s.byteValue=t.slice(e+r,e+i)),s}function gf(t,e,r,n){return Nr(t,e,1,r,n)}function yf(t,e,r,n){return Nr(t,e,2,se(t,e+1,n),n)}function wf(t,e,r,n){return Nr(t,e,3,ae(t,e+1,n),n)}function xf(t,e,r,n){return Nr(t,e,5,ce(t,e+1,n),n)}function bf(t,e,r,n){let o=ue(t,e+1,n);if(typeof o=="bigint")throw new Error(`${E} 64-bit integer string lengths not supported`);return Nr(t,e,9,o,n)}var Ef=$t;function Mt(t,e,r,n){return new h(u.array,n,r)}function _f(t,e,r,n){return Mt(t,e,1,r)}function vf(t,e,r,n){return Mt(t,e,2,se(t,e+1,n))}function kf(t,e,r,n){return Mt(t,e,3,ae(t,e+1,n))}function Af(t,e,r,n){return Mt(t,e,5,ce(t,e+1,n))}function Tf(t,e,r,n){let o=ue(t,e+1,n);if(typeof o=="bigint")throw new Error(`${E} 64-bit integer array lengths not supported`);return Mt(t,e,9,o)}function If(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${E} indefinite length items not allowed`);return Mt(t,e,1,1/0)}function bo(t,e){j(t,u.array.majorEncoded,e.value)}bo.compareTokens=ge.compareTokens;bo.encodedSize=function(e){return j.encodedSize(e.value)};function Ot(t,e,r,n){return new h(u.map,n,r)}function Sf(t,e,r,n){return Ot(t,e,1,r)}function Uf(t,e,r,n){return Ot(t,e,2,se(t,e+1,n))}function Nf(t,e,r,n){return Ot(t,e,3,ae(t,e+1,n))}function Cf(t,e,r,n){return Ot(t,e,5,ce(t,e+1,n))}function Lf(t,e,r,n){let o=ue(t,e+1,n);if(typeof o=="bigint")throw new Error(`${E} 64-bit integer map lengths not supported`);return Ot(t,e,9,o)}function Bf(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${E} indefinite length items not allowed`);return Ot(t,e,1,1/0)}function Eo(t,e){j(t,u.map.majorEncoded,e.value)}Eo.compareTokens=ge.compareTokens;Eo.encodedSize=function(e){return j.encodedSize(e.value)};function Rf(t,e,r,n){return new h(u.tag,r,1)}function Df(t,e,r,n){return new h(u.tag,se(t,e+1,n),2)}function Pf(t,e,r,n){return new h(u.tag,ae(t,e+1,n),3)}function $f(t,e,r,n){return new h(u.tag,ce(t,e+1,n),5)}function Mf(t,e,r,n){return new h(u.tag,ue(t,e+1,n),9)}function _o(t,e){j(t,u.tag.majorEncoded,e.value)}_o.compareTokens=ge.compareTokens;_o.encodedSize=function(e){return j.encodedSize(e.value)};var cs=20,us=21,fs=22,ls=23;function Of(t,e,r,n){if(n.allowUndefined===!1)throw new Error(`${E} undefined values are not supported`);return n.coerceUndefinedToNull===!0?new h(u.null,null,1):new h(u.undefined,void 0,1)}function Ff(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${E} indefinite length items not allowed`);return new h(u.break,void 0,1)}function ds(t,e,r){if(r){if(r.allowNaN===!1&&Number.isNaN(t))throw new Error(`${E} NaN values are not supported`);if(r.allowInfinity===!1&&(t===1/0||t===-1/0))throw new Error(`${E} Infinity values are not supported`)}return new h(u.float,t,e)}function zf(t,e,r,n){return ds(hs(t,e+1),3,n)}function jf(t,e,r,n){return ds(ps(t,e+1),5,n)}function qf(t,e,r,n){return ds(Wf(t,e+1),9,n)}function vo(t,e,r){let n=e.value;if(n===!1)t.push([u.float.majorEncoded|cs]);else if(n===!0)t.push([u.float.majorEncoded|us]);else if(n===null)t.push([u.float.majorEncoded|fs]);else if(n===void 0)t.push([u.float.majorEncoded|ls]);else{let o,i=!1;(!r||r.float64!==!0)&&(Hf(n),o=hs(Se,1),n===o||Number.isNaN(n)?(Se[0]=249,t.push(Se.slice(0,3)),i=!0):(Kf(n),o=ps(Se,1),n===o&&(Se[0]=250,t.push(Se.slice(0,5)),i=!0))),i||(im(n),o=Wf(Se,1),Se[0]=251,t.push(Se.slice(0,9)))}}vo.encodedSize=function(e,r){let n=e.value;if(n===!1||n===!0||n===null||n===void 0)return 1;if(!r||r.float64!==!0){Hf(n);let o=hs(Se,1);if(n===o||Number.isNaN(n))return 3;if(Kf(n),o=ps(Se,1),n===o)return 5}return 9};var Vf=new ArrayBuffer(9),ye=new DataView(Vf,1),Se=new Uint8Array(Vf,0);function Hf(t){if(t===1/0)ye.setUint16(0,31744,!1);else if(t===-1/0)ye.setUint16(0,64512,!1);else if(Number.isNaN(t))ye.setUint16(0,32256,!1);else{ye.setFloat32(0,t);let e=ye.getUint32(0),r=(e&2139095040)>>23,n=e&8388607;if(r===255)ye.setUint16(0,31744,!1);else if(r===0)ye.setUint16(0,(e&2147483648)>>16|n>>13,!1);else{let o=r-127;o<-24?ye.setUint16(0,0):o<-14?ye.setUint16(0,(e&2147483648)>>16|1<<24+o,!1):ye.setUint16(0,(e&2147483648)>>16|o+15<<10|n>>13,!1)}}}function hs(t,e){if(t.length-e<2)throw new Error(`${E} not enough data for float16`);let r=(t[e]<<8)+t[e+1];if(r===31744)return 1/0;if(r===64512)return-1/0;if(r===32256)return NaN;let n=r>>10&31,o=r&1023,i;return n===0?i=o*2**-24:n!==31?i=(o+1024)*2**(n-25):i=o===0?1/0:NaN,r&32768?-i:i}function Kf(t){ye.setFloat32(0,t,!1)}function ps(t,e){if(t.length-e<4)throw new Error(`${E} not enough data for float32`);let r=(t.byteOffset||0)+e;return new DataView(t.buffer,r,4).getFloat32(0,!1)}function im(t){ye.setFloat64(0,t,!1)}function Wf(t,e){if(t.length-e<8)throw new Error(`${E} not enough data for float64`);let r=(t.byteOffset||0)+e;return new DataView(t.buffer,r,8).getFloat64(0,!1)}vo.compareTokens=ge.compareTokens;function C(t,e,r){throw new Error(`${E} encountered invalid minor (${r}) for major ${t[e]>>>5}`)}function ko(t){return()=>{throw new Error(`${E} ${t}`)}}var w=[];for(let t=0;t<=23;t++)w[t]=C;w[24]=ef;w[25]=tf;w[26]=rf;w[27]=nf;w[28]=C;w[29]=C;w[30]=C;w[31]=C;for(let t=32;t<=55;t++)w[t]=C;w[56]=of;w[57]=sf;w[58]=af;w[59]=uf;w[60]=C;w[61]=C;w[62]=C;w[63]=C;for(let t=64;t<=87;t++)w[t]=ff;w[88]=lf;w[89]=df;w[90]=hf;w[91]=pf;w[92]=C;w[93]=C;w[94]=C;w[95]=ko("indefinite length bytes/strings are not supported");for(let t=96;t<=119;t++)w[t]=gf;w[120]=yf;w[121]=wf;w[122]=xf;w[123]=bf;w[124]=C;w[125]=C;w[126]=C;w[127]=ko("indefinite length bytes/strings are not supported");for(let t=128;t<=151;t++)w[t]=_f;w[152]=vf;w[153]=kf;w[154]=Af;w[155]=Tf;w[156]=C;w[157]=C;w[158]=C;w[159]=If;for(let t=160;t<=183;t++)w[t]=Sf;w[184]=Uf;w[185]=Nf;w[186]=Cf;w[187]=Lf;w[188]=C;w[189]=C;w[190]=C;w[191]=Bf;for(let t=192;t<=215;t++)w[t]=Rf;w[216]=Df;w[217]=Pf;w[218]=$f;w[219]=Mf;w[220]=C;w[221]=C;w[222]=C;w[223]=C;for(let t=224;t<=243;t++)w[t]=ko("simple values are not supported");w[244]=C;w[245]=C;w[246]=C;w[247]=Of;w[248]=ko("simple values are not supported");w[249]=zf;w[250]=jf;w[251]=qf;w[252]=C;w[253]=C;w[254]=C;w[255]=Ff;var Ue=[];for(let t=0;t<24;t++)Ue[t]=new h(u.uint,t,1);for(let t=-1;t>=-24;t--)Ue[31-t]=new h(u.negint,t,1);Ue[64]=new h(u.bytes,new Uint8Array(0),1);Ue[96]=new h(u.string,"",1);Ue[128]=new h(u.array,0,1);Ue[160]=new h(u.map,0,1);Ue[244]=new h(u.false,!1,1);Ue[245]=new h(u.true,!0,1);Ue[246]=new h(u.null,null,1);function Gf(t){switch(t.type){case u.false:return Pe([244]);case u.true:return Pe([245]);case u.null:return Pe([246]);case u.bytes:return t.value.length?void 0:Pe([64]);case u.string:return t.value===""?Pe([96]):void 0;case u.array:return t.value===0?Pe([128]):void 0;case u.map:return t.value===0?Pe([160]):void 0;case u.uint:return t.value<24?Pe([Number(t.value)]):void 0;case u.negint:if(t.value>=-24)return Pe([31-Number(t.value)])}}var Jf=Object.freeze({float64:!0,mapSorter:lm,quickEncodeToken:Gf});function am(){let t=[];return t[u.uint.major]=ge,t[u.negint.major]=wo,t[u.bytes.major]=$t,t[u.string.major]=Ef,t[u.array.major]=bo,t[u.map.major]=Eo,t[u.tag.major]=_o,t[u.float.major]=vo,t}var cm=am(),um=new Ir,To=class t{constructor(e,r){this.obj=e,this.parent=r}includes(e){let r=this;do if(r.obj===e)return!0;while(r=r.parent);return!1}static createCheck(e,r){if(e&&e.includes(r))throw new Error(`${Ve} object contains circular references`);return new t(r,e)}},tt={null:new h(u.null,null),undefined:new h(u.undefined,void 0),true:new h(u.true,!0),false:new h(u.false,!1),emptyArray:new h(u.array,0),emptyMap:new h(u.map,0)},rt={number(t,e,r,n){return!Number.isInteger(t)||!Number.isSafeInteger(t)?new h(u.float,t):t>=0?new h(u.uint,t):new h(u.negint,t)},bigint(t,e,r,n){return t>=BigInt(0)?new h(u.uint,t):new h(u.negint,t)},Uint8Array(t,e,r,n){return new h(u.bytes,t)},string(t,e,r,n){return new h(u.string,t)},boolean(t,e,r,n){return t?tt.true:tt.false},null(t,e,r,n){return tt.null},undefined(t,e,r,n){return tt.undefined},ArrayBuffer(t,e,r,n){return new h(u.bytes,new Uint8Array(t))},DataView(t,e,r,n){return new h(u.bytes,new Uint8Array(t.buffer,t.byteOffset,t.byteLength))},Array(t,e,r,n){if(!t.length)return r.addBreakTokens===!0?[tt.emptyArray,new h(u.break)]:tt.emptyArray;n=To.createCheck(n,t);let o=[],i=0;for(let s of t)o[i++]=Ao(s,r,n);return r.addBreakTokens?[new h(u.array,t.length),o,new h(u.break)]:[new h(u.array,t.length),o]},Object(t,e,r,n){let o=e!=="Object",i=o?t.keys():Object.keys(t),s=o?t.size:i.length,a;if(s){a=new Array(s),n=To.createCheck(n,t);let c=!o&&r.ignoreUndefinedProperties,l=0;for(let p of i){let m=o?t.get(p):t[p];c&&m===void 0||(a[l++]=[Ao(p,r,n),Ao(m,r,n)])}l<s&&(a.length=l)}return a?.length?(fm(a,r),r.addBreakTokens?[new h(u.map,a.length),a,new h(u.break)]:[new h(u.map,a.length),a]):r.addBreakTokens===!0?[tt.emptyMap,new h(u.break)]:tt.emptyMap}};rt.Map=rt.Object;rt.Buffer=rt.Uint8Array;for(let t of"Uint8Clamped Uint16 Uint32 Int8 Int16 Int32 BigUint64 BigInt64 Float32 Float64".split(" "))rt[`${t}Array`]=rt.DataView;function Ao(t,e={},r){let n=Wu(t),o=e&&e.typeEncoders&&e.typeEncoders[n]||rt[n];if(typeof o=="function"){let s=o(t,n,e,r);if(s!=null)return s}let i=rt[n];if(!i)throw new Error(`${Ve} unsupported type: ${n}`);return i(t,n,e,r)}function fm(t,e){e.mapSorter&&t.sort(e.mapSorter)}function lm(t,e){if(t[0]instanceof h&&e[0]instanceof h){let r=t[0],n=e[0];return r._keyBytes||(r._keyBytes=Qf(r.value)),n._keyBytes||(n._keyBytes=Qf(n.value)),go(r._keyBytes,n._keyBytes)}throw new Error("rfc8949MapSorter: complex key types are not supported yet")}function Qf(t){return ms(t,cm,Jf)}function Yf(t,e,r,n){if(Array.isArray(e))for(let o of e)Yf(t,o,r,n);else r[e.type.major](t,e,n)}var s1=u.uint.majorEncoded,a1=u.negint.majorEncoded,c1=u.bytes.majorEncoded,u1=u.string.majorEncoded,f1=u.array.majorEncoded,l1=u.float.majorEncoded|cs,d1=u.float.majorEncoded|us,h1=u.float.majorEncoded|fs,p1=u.float.majorEncoded|ls,m1=BigInt(-1),g1=BigInt(1);function ms(t,e,r,n){let o=n instanceof Uint8Array,i=o?new yo(n):um,s=Ao(t,r);if(!Array.isArray(s)&&r.quickEncodeToken){let a=r.quickEncodeToken(s);if(a)return o?(i.push(a),i.toBytes()):a;let c=e[s.type.major];if(c.encodedSize){let l=c.encodedSize(s,r);if(o||(i=new Ir(l)),c(i,s,r),i.chunks.length!==1)throw new Error(`Unexpected error: pre-calculated length for ${s} was wrong`);return o?i.toBytes():mt(i.chunks[0])}}return i.reset(),Yf(i,s,e,r),i.toBytes(!0)}var dm={strict:!1,allowIndefinite:!0,allowUndefined:!0,allowBigInt:!0},Io=class{constructor(e,r={}){this._pos=0,this.data=e,this.options=r}pos(){return this._pos}done(){return this._pos>=this.data.length}next(){let e=this.data[this._pos],r=Ue[e];if(r===void 0){let n=w[e];if(!n)throw new Error(`${E} no decoder for major type ${e>>>5} (byte 0x${e.toString(16).padStart(2,"0")})`);let o=e&31;r=n(this.data,this._pos,o,this.options)}return this._pos+=r.encodedLength,r}},nt=Symbol.for("DONE"),Ft=Symbol.for("BREAK");function hm(t,e,r){let n=[];for(let o=0;o<t.value;o++){let i=ot(e,r);if(i===Ft){if(t.value===1/0)break;throw new Error(`${E} got unexpected break to lengthed array`)}if(i===nt)throw new Error(`${E} found array but not enough entries (got ${o}, expected ${t.value})`);n[o]=i}return n}function pm(t,e,r){let n=r.useMaps===!0,o=r.rejectDuplicateMapKeys===!0,i=n?void 0:{},s=n?new Map:void 0;for(let a=0;a<t.value;a++){let c=ot(e,r);if(c===Ft){if(t.value===1/0)break;throw new Error(`${E} got unexpected break to lengthed map`)}if(c===nt)throw new Error(`${E} found map but not enough entries (got ${a} [no key], expected ${t.value})`);if(!n&&typeof c!="string")throw new Error(`${E} non-string keys not supported (got ${typeof c})`);if(o&&(n&&s.has(c)||!n&&Object.hasOwn(i,c)))throw new Error(`${E} found repeat map key "${c}"`);let l=ot(e,r);if(l===nt)throw new Error(`${E} found map but not enough entries (got ${a} [no value], expected ${t.value})`);n?s.set(c,l):i[c]=l}return n?s:i}function*mm(t,e,r){for(let n=0;n<t.value;n++){let o=ot(e,r);if(o===Ft){if(t.value===1/0)break;throw new Error(`${E} got unexpected break to lengthed map`)}if(o===nt)throw new Error(`${E} found map but not enough entries (got ${n} [no key], expected ${t.value})`);let i=ot(e,r);if(i===nt)throw new Error(`${E} found map but not enough entries (got ${n} [no value], expected ${t.value})`);yield[o,i]}}function gm(t,e){let r=!1,n=function(){if(r)throw new Error(`${E} tag decode() may only be called once`);r=!0;let o=ot(t,e);if(o===nt)throw new Error(`${E} tag content missing`);if(o===Ft)throw new Error(`${E} got unexpected break in tag content`);return o};return n.entries=function(){if(r)throw new Error(`${E} tag decode() may only be called once`);r=!0;let o=t.next();if(!u.equals(o.type,u.map))throw new Error(`${E} entries() requires map content, got ${o.type.name}`);let i=[];for(let s of mm(o,t,e))i.push(s);return i},Object.defineProperty(n,"_called",{get(){return r},enumerable:!1}),n}function ot(t,e){if(t.done())return nt;let r=t.next();if(u.equals(r.type,u.break))return Ft;if(r.type.terminal)return r.value;if(u.equals(r.type,u.array))return hm(r,t,e);if(u.equals(r.type,u.map))return pm(r,t,e);if(u.equals(r.type,u.tag)){if(e.tags&&typeof e.tags[r.value]=="function"){let n=gm(t,e),o=e.tags[r.value](n);if(!n._called)throw new Error(`${E} tag decoder must call decode() or entries()`);return o}throw new Error(`${E} tag not supported (${r.value})`)}throw new Error("unsupported")}function gs(t,e){if(!(t instanceof Uint8Array))throw new Error(`${E} data to decode must be a Uint8Array`);e=Object.assign({},dm,e);let r=mt(t),n=e.tokenizer||new Io(r,e),o=ot(n,e);if(o===nt)throw new Error(`${E} did not find any content to decode`);if(o===Ft)throw new Error(`${E} got unexpected break`);return[o,t.subarray(n.pos())]}function ys(t,e){let[r,n]=gs(t,e);if(n.length>0)throw new Error(`${E} too many terminals, data makes no sense`);return r}var ws=class extends Array{constructor(){super(),this.inRecursive=[]}prefix(e){let r=this.inRecursive[this.inRecursive.length-1];r&&(u.equals(r.type,u.array)&&(r.elements++,r.elements!==1&&e.push([44])),u.equals(r.type,u.map)&&(r.elements++,r.elements!==1&&(r.elements%2===1?e.push([44]):e.push([58]))))}[u.uint.major](e,r){this.prefix(e);let n=String(r.value),o=[];for(let i=0;i<n.length;i++)o[i]=n.charCodeAt(i);e.push(o)}[u.negint.major](e,r){this[u.uint.major](e,r)}[u.bytes.major](e,r){throw new Error(`${Ve} unsupported type: Uint8Array`)}[u.string.major](e,r){this.prefix(e);let n=Tr(JSON.stringify(r.value));e.push(n.length>32?mt(n):n)}[u.array.major](e,r){this.prefix(e),this.inRecursive.push({type:u.array,elements:0}),e.push([91])}[u.map.major](e,r){this.prefix(e),this.inRecursive.push({type:u.map,elements:0}),e.push([123])}[u.tag.major](e,r){}[u.float.major](e,r){if(r.type.name==="break"){let s=this.inRecursive.pop();if(s){if(u.equals(s.type,u.array))e.push([93]);else if(u.equals(s.type,u.map))e.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(`${Ve} unsupported type: undefined`);if(this.prefix(e),r.type.name==="true"){e.push([116,114,117,101]);return}else if(r.type.name==="false"){e.push([102,97,108,115,101]);return}else if(r.type.name==="null"){e.push([110,117,108,108]);return}let n=String(r.value),o=[],i=!1;for(let s=0;s<n.length;s++)o[s]=n.charCodeAt(s),!i&&(o[s]===46||o[s]===101||o[s]===69)&&(i=!0);i||(o.push(46),o.push(48)),e.push(o)}};function ym(t,e){if(Array.isArray(t[0])||Array.isArray(e[0]))throw new Error(`${Ve} complex map keys are not supported`);let r=t[0],n=e[0];if(r.type!==u.string||n.type!==u.string)throw new Error(`${Ve} non-string map keys are not supported`);if(r<n)return-1;if(r>n)return 1;throw new Error(`${Ve} unexpected duplicate map keys, this is not supported`)}var wm={addBreakTokens:!0,mapSorter:ym};function xs(t,e){return e=Object.assign({},wm,e),ms(t,new ws,e)}var zt=class{constructor(e,r={}){this._pos=0,this.data=e,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 e=this.ch();for(;e===32||e===9||e===13||e===10;)e=this.data[++this._pos]}expect(e){if(this.data.length-this._pos<e.length)throw new Error(`${E} unexpected end of input at position ${this._pos}`);for(let r=0;r<e.length;r++)if(this.data[this._pos++]!==e[r])throw new Error(`${E} unexpected token at position ${this._pos}, expected to find '${String.fromCharCode(...e)}'`)}parseNumber(){let e=this._pos,r=!1,n=!1,o=a=>{for(;!this.done();){let c=this.ch();if(a.includes(c))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 h(u.uint,0,this._pos-e);if(o([48,49,50,51,52,53,54,55,56,57]),r&&this._pos===e+1)throw new Error(`${E} unexpected token at position ${this._pos}`);if(!this.done()&&this.ch()===46){if(n)throw new Error(`${E} 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 i=String.fromCharCode.apply(null,this.data.subarray(e,this._pos)),s=parseFloat(i);return n?new h(u.float,s,this._pos-e):this.options.allowBigInt!==!0||Number.isSafeInteger(s)?new h(s>=0?u.uint:u.negint,s,this._pos-e):new h(s>=0?u.uint:u.negint,BigInt(i),this._pos-e)}parseString(){if(this.ch()!==34)throw new Error(`${E} unexpected character at position ${this._pos}; this shouldn't happen`);this._pos++;for(let i=this._pos,s=0;i<this.data.length&&s<65536;i++,s++){let a=this.data[i];if(a===92||a<32||a>=128)break;if(a===34){let c=String.fromCharCode.apply(null,this.data.subarray(this._pos,i));return this._pos=i+1,new h(u.string,c,s)}}let e=this._pos,r=[],n=()=>{if(this._pos+4>=this.data.length)throw new Error(`${E} unexpected end of unicode escape sequence at position ${this._pos}`);let i=0;for(let s=0;s<4;s++){let a=this.ch();if(a>=48&&a<=57)a-=48;else if(a>=97&&a<=102)a=a-97+10;else if(a>=65&&a<=70)a=a-65+10;else throw new Error(`${E} unexpected unicode escape character at position ${this._pos}`);i=i*16+a,this._pos++}return i},o=()=>{let i=this.ch(),s=null,a=i>239?4:i>223?3:i>191?2:1;if(this._pos+a>this.data.length)throw new Error(`${E} unexpected unicode sequence at position ${this._pos}`);let c,l,p,m;switch(a){case 1:i<128&&(s=i);break;case 2:c=this.data[this._pos+1],(c&192)===128&&(m=(i&31)<<6|c&63,m>127&&(s=m));break;case 3:c=this.data[this._pos+1],l=this.data[this._pos+2],(c&192)===128&&(l&192)===128&&(m=(i&15)<<12|(c&63)<<6|l&63,m>2047&&(m<55296||m>57343)&&(s=m));break;case 4:c=this.data[this._pos+1],l=this.data[this._pos+2],p=this.data[this._pos+3],(c&192)===128&&(l&192)===128&&(p&192)===128&&(m=(i&15)<<18|(c&63)<<12|(l&63)<<6|p&63,m>65535&&m<1114112&&(s=m))}s===null?(s=65533,a=1):s>65535&&(s-=65536,r.push(s>>>10&1023|55296),s=56320|s&1023),r.push(s),this._pos+=a};for(;!this.done();){let i=this.ch(),s;switch(i){case 92:if(this._pos++,this.done())throw new Error(`${E} unexpected string termination at position ${this._pos}`);switch(s=this.ch(),this._pos++,s){case 34:case 39:case 92:case 47:r.push(s);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(`${E} unexpected string escape character at position ${this._pos}`)}break;case 34:return this._pos++,new h(u.string,Zu(r),this._pos-e);default:if(i<32)throw new Error(`${E} invalid control character at position ${this._pos}`);i<128?(r.push(i),this._pos++):o()}}throw new Error(`${E} unexpected end of string at position ${this._pos}`)}parseValue(){switch(this.ch()){case 123:return this.modeStack.push("obj-start"),this._pos++,new h(u.map,1/0,1);case 91:return this.modeStack.push("array-start"),this._pos++,new h(u.array,1/0,1);case 34:return this.parseString();case 110:return this.expect([110,117,108,108]),new h(u.null,null,4);case 102:return this.expect([102,97,108,115,101]),new h(u.false,!1,5);case 116:return this.expect([116,114,117,101]),new h(u.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(`${E} 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 h(u.break,void 0,1);if(this.ch()!==44)throw new Error(`${E} 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 h(u.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 h(u.break,void 0,1);if(this.ch()!==44)throw new Error(`${E} 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 h(u.break,void 0,1);let e=this.parseString();if(this.skipWhitespace(),this.ch()!==58)throw new Error(`${E} 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"),e}case"obj-value":return this.modeStack.pop(),this.modeStack.push("obj-key"),this.skipWhitespace(),this.parseValue();default:throw new Error(`${E} unexpected parse state at position ${this._pos}; this shouldn't happen`)}}};function bs(t,e){return e=Object.assign({tokenizer:new zt(t,e)},e),ys(t,e)}function bm(t){return t instanceof ArrayBuffer?new Uint8Array(t,0,t.byteLength):t}function Em(t){if(t.asCID!==t&&t["/"]!==t.bytes)return null;let e=L.asCID(t);if(!e)return null;let r=e.toString();return[new h(u.map,1/0,1),new h(u.string,"/",1),new h(u.string,r,r.length),new h(u.break,void 0,1)]}function So(t){let e=Et.encode(t).slice(1);return[new h(u.map,1/0,1),new h(u.string,"/",1),new h(u.map,1/0,1),new h(u.string,"bytes",5),new h(u.string,e,e.length),new h(u.break,void 0,1),new h(u.break,void 0,1)]}function Ne(t){return So(new Uint8Array(t.buffer,t.byteOffset,t.byteLength))}function _m(t){return So(new Uint8Array(t))}function vm(){throw new Error("`undefined` is not supported by the IPLD Data Model and cannot be encoded")}function km(t){if(Number.isNaN(t))throw new Error("`NaN` is not supported by the IPLD Data Model and cannot be encoded");if(t===1/0||t===-1/0)throw new Error("`Infinity` and `-Infinity` is not supported by the IPLD Data Model and cannot be encoded");return null}var Am={typeEncoders:{Object:Em,Buffer:So,Uint8Array:So,Int8Array:Ne,Uint16Array:Ne,Int16Array:Ne,Uint32Array:Ne,Int32Array:Ne,Float32Array:Ne,Float64Array:Ne,Uint8ClampedArray:Ne,BigInt64Array:Ne,BigUint64Array:Ne,DataView:Ne,ArrayBuffer:_m,undefined:vm,number:km}},Es=class extends zt{constructor(e,r){super(e,r),this.tokenBuffer=[]}done(){return this.tokenBuffer.length===0&&super.done()}_next(){return this.tokenBuffer.length>0?this.tokenBuffer.pop():super.next()}next(){let e=this._next();if(u.equals(e.type,u.map)){let r=this._next();if(u.equals(r.type,u.string)&&r.value==="/"){let n=this._next();if(u.equals(n.type,u.string)){let o=this._next();if(!u.equals(o.type,u.break))throw new Error("Invalid encoded CID form");return this.tokenBuffer.push(n),new h(u.tag,42,0)}if(u.equals(n.type,u.map)){let o=this._next();if(u.equals(o.type,u.string)&&o.value==="bytes"){let i=this._next();if(u.equals(i.type,u.string)){for(let a=0;a<2;a++){let c=this._next();if(!u.equals(c.type,u.break))throw new Error("Invalid encoded Bytes form")}let s=Et.decode(`m${i.value}`);return new h(u.bytes,s,i.value.length)}this.tokenBuffer.push(i)}this.tokenBuffer.push(o)}this.tokenBuffer.push(n)}this.tokenBuffer.push(r)}return e}},Xf={allowIndefinite:!1,allowUndefined:!1,allowNaN:!1,allowInfinity:!1,allowBigInt:!0,strict:!0,useMaps:!1,rejectDuplicateMapKeys:!0,tags:{42:t=>L.parse(t())}},Tm="dag-json",_s=297,Zf=t=>xs(t,Am),el=t=>{let e=bm(t),r=Object.assign(Xf,{tokenizer:new Es(e,Xf)});return bs(e,r)},Im=t=>Sm.decode(Zf(t));var Sm=new TextDecoder,Um=t=>el(Nm.encode(t)),Nm=new TextEncoder;var Us={};M(Us,{code:()=>Ss,createLink:()=>fl,createNode:()=>ul,decode:()=>qm,encode:()=>jm,name:()=>zm,prepare:()=>Ts,validate:()=>Is});var Cm=new TextDecoder;function ks(t,e){let r=0;for(let n=0;;n+=7){if(n>=64)throw new Error("protobuf: varint overflow");if(e>=t.length)throw new Error("protobuf: unexpected end of data");let o=t[e++];if(r+=n<28?(o&127)<<n:(o&127)*2**n,o<128)break}return[r,e]}function Uo(t,e){let r;[r,e]=ks(t,e);let n=e+r;if(r<0||n<0)throw new Error("protobuf: invalid length");if(n>t.length)throw new Error("protobuf: unexpected end of data");return[t.subarray(e,n),n]}function tl(t,e){let r;return[r,e]=ks(t,e),[r&7,r>>3,e]}function Lm(t){let e={},r=t.length,n=0;for(;n<r;){let o,i;if([o,i,n]=tl(t,n),i===1){if(e.Hash)throw new Error("protobuf: (PBLink) duplicate Hash section");if(o!==2)throw new Error(`protobuf: (PBLink) wrong wireType (${o}) for Hash`);if(e.Name!==void 0)throw new Error("protobuf: (PBLink) invalid order, found Name before Hash");if(e.Tsize!==void 0)throw new Error("protobuf: (PBLink) invalid order, found Tsize before Hash");[e.Hash,n]=Uo(t,n)}else if(i===2){if(e.Name!==void 0)throw new Error("protobuf: (PBLink) duplicate Name section");if(o!==2)throw new Error(`protobuf: (PBLink) wrong wireType (${o}) for Name`);if(e.Tsize!==void 0)throw new Error("protobuf: (PBLink) invalid order, found Tsize before Name");let s;[s,n]=Uo(t,n),e.Name=Cm.decode(s)}else if(i===3){if(e.Tsize!==void 0)throw new Error("protobuf: (PBLink) duplicate Tsize section");if(o!==0)throw new Error(`protobuf: (PBLink) wrong wireType (${o}) for Tsize`);[e.Tsize,n]=ks(t,n)}else throw new Error(`protobuf: (PBLink) invalid fieldNumber, expected 1, 2 or 3, got ${i}`)}if(n>r)throw new Error("protobuf: (PBLink) unexpected end of data");return e}function rl(t){let e=t.length,r=0,n,o=!1,i;for(;r<e;){let a,c;if([a,c,r]=tl(t,r),a!==2)throw new Error(`protobuf: (PBNode) invalid wireType, expected 2, got ${a}`);if(c===1){if(i)throw new Error("protobuf: (PBNode) duplicate Data section");[i,r]=Uo(t,r),n&&(o=!0)}else if(c===2){if(o)throw new Error("protobuf: (PBNode) duplicate Links section");n||(n=[]);let l;[l,r]=Uo(t,r),n.push(Lm(l))}else throw new Error(`protobuf: (PBNode) invalid fieldNumber, expected 1 or 2, got ${c}`)}if(r>e)throw new Error("protobuf: (PBNode) unexpected end of data");let s={};return i&&(s.Data=i),s.Links=n||[],s}var ol=new TextEncoder,nl=2**32,Bm=2**31;function Rm(t,e){let r=e.length;if(typeof t.Tsize=="number"){if(t.Tsize<0)throw new Error("Tsize cannot be negative");if(!Number.isSafeInteger(t.Tsize))throw new Error("Tsize too large for encoding");r=Cr(e,r,t.Tsize)-1,e[r]=24}if(typeof t.Name=="string"){let n=ol.encode(t.Name);r-=n.length,e.set(n,r),r=Cr(e,r,n.length)-1,e[r]=18}return t.Hash&&(r-=t.Hash.length,e.set(t.Hash,r),r=Cr(e,r,t.Hash.length)-1,e[r]=10),e.length-r}function il(t){let e=Pm(t),r=new Uint8Array(e),n=e;if(t.Data&&(n-=t.Data.length,r.set(t.Data,n),n=Cr(r,n,t.Data.length)-1,r[n]=10),t.Links)for(let o=t.Links.length-1;o>=0;o--){let i=Rm(t.Links[o],r.subarray(0,n));n-=i,n=Cr(r,n,i)-1,r[n]=18}return r}function Dm(t){let e=0;if(t.Hash){let r=t.Hash.length;e+=1+r+jt(r)}if(typeof t.Name=="string"){let r=ol.encode(t.Name).length;e+=1+r+jt(r)}return typeof t.Tsize=="number"&&(e+=1+jt(t.Tsize)),e}function Pm(t){let e=0;if(t.Data){let r=t.Data.length;e+=1+r+jt(r)}if(t.Links)for(let r of t.Links){let n=Dm(r);e+=1+n+jt(n)}return e}function Cr(t,e,r){e-=jt(r);let n=e;for(;r>=Bm;)t[e++]=r&127|128,r/=128;for(;r>=128;)t[e++]=r&127|128,r>>>=7;return t[e]=r,n}function jt(t){return t%2===0&&t++,Math.floor(($m(t)+6)/7)}function $m(t){let e=0;return t>=nl&&(t=Math.floor(t/nl),e=32),t>=65536&&(t>>>=16,e+=16),t>=256&&(t>>>=8,e+=8),e+Mm[t]}var Mm=[0,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8];var Om=["Data","Links"],Fm=["Hash","Name","Tsize"],As=new TextEncoder;function al(t,e){if(t===e)return 0;let r=t.Name?As.encode(t.Name):[],n=e.Name?As.encode(e.Name):[],o=r.length,i=n.length;for(let s=0,a=Math.min(o,i);s<a;++s)if(r[s]!==n[s]){o=r[s],i=n[s];break}return o<i?-1:i<o?1:0}function sl(t,e){return!Object.keys(t).some(r=>!e.includes(r))}function cl(t){if(typeof t.asCID=="object"){let r=L.asCID(t);if(!r)throw new TypeError("Invalid DAG-PB form");return{Hash:r}}if(typeof t!="object"||Array.isArray(t))throw new TypeError("Invalid DAG-PB form");let e={};if(t.Hash){let r=L.asCID(t.Hash);try{r||(typeof t.Hash=="string"?r=L.parse(t.Hash):t.Hash instanceof Uint8Array&&(r=L.decode(t.Hash)))}catch(n){throw new TypeError(`Invalid DAG-PB form: ${n.message}`)}r&&(e.Hash=r)}if(!e.Hash)throw new TypeError("Invalid DAG-PB form");return typeof t.Name=="string"&&(e.Name=t.Name),typeof t.Tsize=="number"&&(e.Tsize=t.Tsize),e}function Ts(t){if((t instanceof Uint8Array||typeof t=="string")&&(t={Data:t}),typeof t!="object"||Array.isArray(t))throw new TypeError("Invalid DAG-PB form");let e={};if(t.Data!==void 0)if(typeof t.Data=="string")e.Data=As.encode(t.Data);else if(t.Data instanceof Uint8Array)e.Data=t.Data;else throw new TypeError("Invalid DAG-PB form");if(t.Links!==void 0)if(Array.isArray(t.Links))e.Links=t.Links.map(cl),e.Links.sort(al);else throw new TypeError("Invalid DAG-PB form");else e.Links=[];return e}function Is(t){if(!t||typeof t!="object"||Array.isArray(t)||t instanceof Uint8Array||t["/"]&&t["/"]===t.bytes)throw new TypeError("Invalid DAG-PB form");if(!sl(t,Om))throw new TypeError("Invalid DAG-PB form (extraneous properties)");if(t.Data!==void 0&&!(t.Data instanceof Uint8Array))throw new TypeError("Invalid DAG-PB form (Data must be bytes)");if(!Array.isArray(t.Links))throw new TypeError("Invalid DAG-PB form (Links must be a list)");for(let e=0;e<t.Links.length;e++){let r=t.Links[e];if(!r||typeof r!="object"||Array.isArray(r)||r instanceof Uint8Array||r["/"]&&r["/"]===r.bytes)throw new TypeError("Invalid DAG-PB form (bad link)");if(!sl(r,Fm))throw new TypeError("Invalid DAG-PB form (extraneous properties on link)");if(r.Hash===void 0)throw new TypeError("Invalid DAG-PB form (link must have a Hash)");if(r.Hash==null||!r.Hash["/"]||r.Hash["/"]!==r.Hash.bytes)throw new TypeError("Invalid DAG-PB form (link Hash must be a CID)");if(r.Name!==void 0&&typeof r.Name!="string")throw new TypeError("Invalid DAG-PB form (link Name must be a string)");if(r.Tsize!==void 0){if(typeof r.Tsize!="number"||r.Tsize%1!==0)throw new TypeError("Invalid DAG-PB form (link Tsize must be an integer)");if(r.Tsize<0)throw new TypeError("Invalid DAG-PB form (link Tsize cannot be negative)")}if(e>0&&al(r,t.Links[e-1])===-1)throw new TypeError("Invalid DAG-PB form (links must be sorted by Name bytes)")}}function ul(t,e=[]){return Ts({Data:t,Links:e})}function fl(t,e,r){return cl({Hash:r,Name:t,Tsize:e})}function ll(t){return t instanceof ArrayBuffer?new Uint8Array(t,0,t.byteLength):t}var zm="dag-pb",Ss=112;function jm(t){Is(t);let e={};return t.Links&&(e.Links=t.Links.map(r=>{let n={};return r.Hash&&(n.Hash=r.Hash.bytes),r.Name!==void 0&&(n.Name=r.Name),r.Tsize!==void 0&&(n.Tsize=r.Tsize),n})),t.Data&&(e.Data=t.Data),il(e)}function qm(t){let e=ll(t),r=rl(e),n={};return r.Data&&(n.Data=r.Data),r.Links&&(n.Links=r.Links.map(o=>{let i={};try{i.Hash=L.decode(o.Hash)}catch{}if(!i.Hash)throw new Error("Invalid Hash field found in link, expected CID");return o.Name!==void 0&&(i.Name=o.Name),o.Tsize!==void 0&&(i.Tsize=o.Tsize),i})),n}function qt(t){return t?.then!=null}function dl(t=[],e){let r={[Ss]:Us,[ii]:zr,[is]:ss,[_s]:vs,[oi]:Fr};return t.forEach(n=>{r[n.code]=n}),async n=>{let o=r[n];if(o==null&&e!=null){let i=e(n);qt(i)?o=await i:o=i,r[o.code]=o}if(o!=null)return o;throw new Rn(`Could not load codec for ${n}`)}}function hl(t=[],e){let r={[Vr.code]:Vr,[Hr.code]:Hr,[qr.code]:qr};return t.forEach(n=>{r[n.code]=n}),async n=>{let o=r[n];if(o==null&&e!=null){let i=e(n);qt(i)?o=await i:o=i,r[o.code]=o}if(o!=null)return o;throw new Bn(`No hasher configured for multihash code 0x${n.toString(16)}, please configure one. You can look up which hash this is at https://github.com/multiformats/multicodec/blob/master/table.csv`)}}var No=class t extends Error{static name="NotFoundError";static code="ERR_NOT_FOUND";name=t.name;code=t.code;constructor(e="Not Found"){super(e)}};var Co=class{has(e,r){return Promise.reject(new Error(".has is not implemented"))}put(e,r,n){return Promise.reject(new Error(".put is not implemented"))}async*putMany(e,r){for await(let{cid:n,bytes:o}of e)await this.put(n,o,r),yield n}get(e,r){throw new Error(".get is not implemented")}async*getMany(e,r){for await(let n of e)yield{cid:n,bytes:this.get(n,r)}}delete(e,r){return Promise.reject(new Error(".delete is not implemented"))}async*deleteMany(e,r){for await(let n of e)await this.delete(n,r),yield n}async*getAll(e){throw new Error(".getAll is not implemented")}};var Lo=0,Vt=class extends Error{static name="IdentityHashDigestTooLongError";name="IdentityHashDigestTooLongError"},Bo=class extends Co{child;maxDigestLength;constructor(e,r){super(),this.child=e,this.maxDigestLength=r?.maxDigestLength}put(e,r,n){if(e.multihash.code===Lo){if(this.maxDigestLength!=null&&e.multihash.digest.byteLength>this.maxDigestLength)throw new Vt(`Identity digest too long - ${e.multihash.digest.byteLength} > this.maxDigestLength`);return n?.signal?.throwIfAborted(),e}return this.child==null?(n?.signal?.throwIfAborted(),e):this.child.put(e,r,n)}async*get(e,r){if(e.multihash.code===Lo){if(this.maxDigestLength!=null&&e.multihash.digest.byteLength>this.maxDigestLength)throw new Vt(`Identity digest too long - ${e.multihash.digest.byteLength} > this.maxDigestLength`);r?.signal?.throwIfAborted(),yield e.multihash.digest;return}if(this.child==null)throw r?.signal?.throwIfAborted(),new No;yield*this.child.get(e,r)}has(e,r){if(e.multihash.code===Lo){if(this.maxDigestLength!=null&&e.multihash.digest.byteLength>this.maxDigestLength)throw new Vt(`Identity digest too long - ${e.multihash.digest.byteLength} > this.maxDigestLength`);return r?.signal?.throwIfAborted(),!0}return this.child==null?(r?.signal?.throwIfAborted(),!1):this.child.has(e,r)}delete(e,r){if(e.code===Lo){if(this.maxDigestLength!=null&&e.multihash.digest.byteLength>this.maxDigestLength)throw new Vt(`Identity digest too long - ${e.multihash.digest.byteLength} > this.maxDigestLength`);r?.signal?.throwIfAborted();return}if(this.child!=null)return this.child.delete(e,r)}async*getAll(e){this.child!=null&&(yield*this.child.getAll(e)),e?.signal?.throwIfAborted()}};function Vm(t){let[e,r]=t[Symbol.asyncIterator]!=null?[t[Symbol.asyncIterator](),Symbol.asyncIterator]:[t[Symbol.iterator](),Symbol.iterator],n=[];return{peek:()=>e.next(),push:o=>{n.push(o)},next:()=>n.length>0?{done:!1,value:n.shift()}:e.next(),[r](){return this}}}var Ro=Vm;function Hm(t){return t[Symbol.asyncIterator]!=null}function Km(t,e){let r=0;if(Hm(t))return(async function*(){for await(let c of t)await e(c,r++)&&(yield c)})();let n=Ro(t),{value:o,done:i}=n.next();if(i===!0)return(function*(){})();let s=e(o,r++);if(typeof s.then=="function")return(async function*(){await s&&(yield o);for(let c of n)await e(c,r++)&&(yield c)})();let a=e;return(function*(){s===!0&&(yield o);for(let c of n)a(c,r++)&&(yield c)})()}var Do=Km;function Wm(t){return t[Symbol.asyncIterator]!=null}function pl(t){return t?.then!=null}function Gm(t,e){let r=0;if(Wm(t))return(async function*(){for await(let c of t){let l=e(c,r++);pl(l)&&await l,yield c}})();let n=Ro(t),{value:o,done:i}=n.next();if(i===!0)return(function*(){})();let s=e(o,r++);if(typeof s?.then=="function")return(async function*(){await s,yield o;for(let c of n){let l=e(c,r++);pl(l)&&await l,yield c}})();let a=e;return(function*(){yield o;for(let c of n)a(c,r++),yield c})()}var Ns=Gm;var Jm=128,Ht=class{child;getHasher;log;logger;blockBrokers;constructor(e,r={}){this.log=e.logger.forComponent("helia:networked-storage"),this.logger=e.logger,this.blockBrokers=e.blockBrokers,this.child=new Bo(e.blockstore,{maxDigestLength:r.maxIdentityHashDigestLength??Jm}),this.getHasher=e.getHasher}async put(e,r,n={}){return await this.child.has(e,n)?(n.onProgress?.(new A("blocks:put:duplicate",e)),e):(n.onProgress?.(new A("blocks:put:providers:notify",e)),await Promise.all(this.blockBrokers.map(async o=>o.announce?.(e,n))),n.onProgress?.(new A("blocks:put:blockstore:put",e)),this.child.put(e,r,n))}async*putMany(e,r={}){let n=Do(e,async({cid:i})=>{let s=await this.child.has(i,r);return s&&r.onProgress?.(new A("blocks:put-many:duplicate",i)),!s}),o=Ns(n,async({cid:i})=>{r.onProgress?.(new A("blocks:put-many:providers:notify",i)),await Promise.all(this.blockBrokers.map(async s=>s.announce?.(i,r)))});r.onProgress?.(new A("blocks:put-many:blockstore:put-many")),yield*this.child.putMany(o,r)}async*get(e,r={}){let n=await this.child.has(e,r),o=r.offline===!0;if(!n){if(o)throw new hr("The block was present in the blockstore and the node is running offline so cannot fetch it");let i=await this.getHasher(e.multihash.code);r?.signal?.throwIfAborted(),r.onProgress?.(new A("blocks:get:providers:get",e));let s=await ml(e,this.blockBrokers,i,{...r,log:this.log});r.onProgress?.(new A("blocks:get:blockstore:put",e)),await this.child.put(e,s,r),r.onProgress?.(new A("blocks:get:providers:notify",e)),await Promise.all(this.blockBrokers.map(async a=>a.announce?.(e,r))),yield s;return}r.onProgress?.(new A("blocks:get:blockstore:get",e)),yield*this.child.get(e,r)}async*getMany(e,r={}){r.onProgress?.(new A("blocks:get-many:blockstore:get-many")),yield*this.child.getMany(Ns(e,async n=>{let o=await this.child.has(n,r),i=r.offline===!0;if(!o){if(i)throw new hr("The block was present in the blockstore and the node is running offline so cannot fetch it");let s=await this.getHasher(n.multihash.code);r?.signal?.throwIfAborted(),r.onProgress?.(new A("blocks:get-many:providers:get",n));let a=await ml(n,this.blockBrokers,s,{...r,log:this.log});r.onProgress?.(new A("blocks:get-many:blockstore:put",n)),await this.child.put(n,a,r),r.onProgress?.(new A("blocks:get-many:providers:notify",n)),await Promise.all(this.blockBrokers.map(async c=>c.announce?.(n,r)))}}))}async delete(e,r={}){r.onProgress?.(new A("blocks:delete:blockstore:delete",e)),await this.child.delete(e,r)}async*deleteMany(e,r={}){r.onProgress?.(new A("blocks:delete-many:blockstore:delete-many")),yield*this.child.deleteMany((async function*(){for await(let n of e)yield n})(),r)}async has(e,r={}){return this.child.has(e,r)}async*getAll(e={}){e.onProgress?.(new A("blocks:get-all:blockstore:get-many")),yield*this.child.getAll(e)}};async function ml(t,e,r,n){let o=Xm(t,r),i=new AbortController,s=ve([i.signal,n.signal]);i.signal;let a=[];for(let c of e)Ym(c)&&a.push(c);if(a.length===0)throw new ft(`No block brokers capable of retrieving blocks are configured, the CID ${t} cannot be fetched from the network`);try{return await Promise.any(a.map(async c=>{try{let l=!1,p=await c.retrieve(t,{...n,signal:s,validateFn:async m=>{await o(m),n.signal?.throwIfAborted(),l=!0}});return l||(await o(p),n.signal?.throwIfAborted()),p}catch(l){throw n.log.error("could not retrieve verified block for %c from %s - %e",t,c.name,l),l}}))}catch(c){throw new Un(c.errors,`Failed to load block for ${t}`)}finally{i.abort(),s.clear()}}function Ym(t){return typeof t.retrieve=="function"}var Xm=(t,e)=>{if(e==null)throw new yt(`No hasher configured for multihash code 0x${t.multihash.code.toString(16)}, please configure one. You can look up which hash this is at https://github.com/multiformats/multicodec/blob/master/table.csv`);return async r=>{let n,o=e.digest(r,{truncate:t.multihash.digest.byteLength});if(qt(o)?n=await o:n=o,!it(n.digest,t.multihash.digest))throw new Pr("Hash of downloaded block did not match multihash from passed CID")}};var Po=class extends Ht{closeController;constructor(e,r){super(e),this.closeController=new AbortController,this.closeController.signal,this.log=e.logger.forComponent(`helia:session-storage:${r.root}`)}close(){this.closeController.abort()}async addPeer(e,r){await Promise.all(this.blockBrokers.map(n=>n.addPeer(e,r)))}async put(e,r,n={}){let o=ve([this.closeController.signal,n.signal]);try{return await super.put(e,r,{...n,signal:o})}finally{o.clear()}}async*putMany(e,r={}){let n=ve([this.closeController.signal,r.signal]);try{yield*super.putMany(e,{...r,signal:n})}finally{n.clear()}}async*get(e,r={}){let n=ve([this.closeController.signal,r.signal]);try{yield*super.get(e,{...r,signal:n})}finally{n.clear()}}async*getMany(e,r={}){let n=ve([this.closeController.signal,r.signal]);try{yield*super.getMany(e,{...r,signal:n})}finally{n.clear()}}async delete(e,r={}){let n=ve([this.closeController.signal,r.signal]);try{await super.delete(e,{...r,signal:n})}finally{n.clear()}}async*deleteMany(e,r={}){let n=ve([this.closeController.signal,r.signal]);try{yield*super.deleteMany(e,{...r,signal:n})}finally{n.clear()}}async has(e,r={}){let n=ve([this.closeController.signal,r.signal]);try{return await super.has(e,{...r,signal:n})}finally{n.clear()}}async*getAll(e={}){let r=ve([this.closeController.signal,e.signal]);try{yield*super.getAll({...e,signal:r})}finally{r.clear()}}};var $o=class extends Ht{started;constructor(e,r={}){super(e,r),this.started=!1}isStarted(){return this.started}async start(){await We(this.child,...this.blockBrokers),this.started=!0}async stop(){await Ge(this.child,...this.blockBrokers),this.started=!1}unwrap(){return this.child}createSession(e,r){if(this.blockBrokers.length===0)throw new ft("No block brokers configured");let n=this.blockBrokers.map(o=>o.createSession?.(r)).filter(o=>o!=null);if(n.length===0)throw new ft(`No configured block brokers support sessions - tried ${this.blockBrokers.map(o=>o.name).join(", ")}`);return new Po({blockstore:this.child,blockBrokers:n,getHasher:this.getHasher,logger:this.logger},{root:e})}};var Mo=class extends le{initialPeerSearchComplete;requests;logName;log;logger;minProviders;maxProviders;providers;evictionFilter;initialProviders;cidPeerFilterSize;constructor(e,r){super(),this.logName=r.name,this.logger=e.logger,this.log=e.logger.forComponent(this.logName),this.requests=new Map,this.minProviders=r.minProviders??1,this.maxProviders=r.maxProviders??5,this.cidPeerFilterSize=r.cidPeerFilterSize??100,this.providers=[],this.evictionFilter=Yr(this.maxProviders),this.initialProviders=[...r.providers??[]]}async retrieve(e,r={}){let n=Et.encode(e.multihash.bytes),o=this.requests.get(n);if(o!=null)return this.log("join existing request for %c",e),o.observers++,o.promise;let i=G(),s={promise:i.promise,observers:1,queryFilter:Yr(this.cidPeerFilterSize)};this.requests.set(n,s);let a=!1;this.initialPeerSearchComplete==null&&(a=!0,this.log=this.logger.forComponent(`${this.logName}:${e}`),this.initialPeerSearchComplete=this.findProviders(e,this.minProviders,r));let c=!1,l=new J({concurrency:this.maxProviders});l.addEventListener("failure",x=>{this.log.error("error querying provider %s, evicting from session - %e",x.detail.job.options.provider,x.detail.error),this.evict(x.detail.job.options.provider)}),l.addEventListener("success",x=>{c=!0,i.resolve(x.detail.result)}),l.addEventListener("idle",()=>{if(c){this.log.trace("session idle, found block");return}if(r.signal?.aborted===!0){this.log.trace("session idle, signal aborted");return}Promise.resolve().then(async()=>{this.log("no session peers had block for for %c, finding new providers",e);for(let x=0;x<this.minProviders&&this.providers.length!==0;x++){let k=this.providers[Math.floor(Math.random()*this.providers.length)];this.evict(k)}await this.findProviders(e,this.minProviders,r),this.log("found new providers re-retrieving %c",e),this.requests.delete(n),i.resolve(await this.retrieve(e,r))}).catch(x=>{this.log.error("could not find new providers for %c - %e",e,x),i.reject(x)})});let p=x=>{let k=this.toFilterKey(x.detail);s.queryFilter.has(k)||(s.queryFilter.add(k),this.emitFoundProviderProgressEvent(e,x.detail,r),l.add(async()=>this.queryProvider(e,x.detail,r),{provider:x.detail}).catch(I=>{r.signal?.aborted!==!0&&this.log.error("error retrieving session block for %c - %e",e,I)}))};if(this.addEventListener("provider",p),a)try{await Oe(this.initialPeerSearchComplete,r.signal),a&&this.log("found initial session peers for %c",e)}catch(x){throw a&&this.log("failed to find initial session peers for %c - %e",e,x),this.requests.delete(n),s.observers>1&&i.reject(x),x}Promise.all([...this.providers].filter(x=>{let k=this.toFilterKey(x),I=s.queryFilter.has(k);return I||s.queryFilter.add(this.toFilterKey(x)),!I}).map(async x=>l.add(async()=>this.queryProvider(e,x,r),{provider:x}))).catch(x=>{r.signal?.aborted!==!0&&this.log.error("error retrieving session block for %c - %e",e,x)});let m=()=>{i.reject(new xe(r.signal?.reason??"Session aborted")),l.abort()};r.signal?.addEventListener("abort",m);try{return await Oe(i.promise,r.signal)}finally{this.removeEventListener("provider",p),r.signal?.removeEventListener("abort",m),l.clear(),this.requests.delete(n)}}evict(e){this.evictionFilter.add(this.toFilterKey(e));let r=this.providers.findIndex(n=>this.equals(n,e));r!==-1&&this.providers.splice(r,1)}isEvicted(e){return this.evictionFilter.has(this.toFilterKey(e))}hasProvider(e){return!!(this.providers.find(r=>this.equals(r,e))!=null||this.isEvicted(e))}async addPeer(e,r){let n=await this.convertToProvider(e,"manually-added",r);n==null||this.hasProvider(n)||(this.providers.push(n),this.safeDispatchEvent("provider",{detail:n}))}async findProviders(e,r,n){let o=G(),i=0;return Promise.resolve().then(async()=>{if(this.log("finding %d-%d new provider(s) for %c - %d initial providers",r,this.maxProviders,e,this.initialProviders.length),this.initialProviders.length>0)for(;i<r&&this.initialProviders.length>0;){let s=this.initialProviders.pop();if(s==null)break;let a=await this.convertToProvider(s,"manual",n);if(n.signal?.aborted===!0)break;if(a!=null&&!this.hasProvider(a)&&(this.log("found %d/%d new providers",i,this.maxProviders),this.providers.push(a),this.safeDispatchEvent("provider",{detail:a}),i++,i===r&&(this.log("session is ready with %d peer(s), only initial peers present",r),o.resolve()),this.providers.length===this.maxProviders)){this.log("found max session peers",i);break}}if(i<this.maxProviders)for await(let s of this.findNewProviders(e,n)){if(i===this.maxProviders||n.signal?.aborted===!0)break;if(!this.hasProvider(s)&&(this.log("found %d/%d new providers",i,this.maxProviders),this.providers.push(s),this.safeDispatchEvent("provider",{detail:s}),i++,i===r&&(this.log("session is ready with %d peer(s), new peers present",r),o.resolve()),this.providers.length===this.maxProviders)){this.log("found max session peers",i);break}}if(this.log("found %d/%d new session peers",i,this.maxProviders),i<r)throw new Ln(`Found ${i} of ${r} ${this.name} providers for ${e}`)}).catch(s=>{this.log.error("error searching routing for potential session peers for %c - %e",e,s),o.reject(s)}),o.promise}};function gl(t){return e=>new Cs(e,t)}function yl(t){return e=>new Ls(e,t)}function wl(t){return e=>new Bs(e,t)}var Lr=class{components;constructor(e,r={}){this.components=e}async*walk(e,r){let n=this.getQueue(),o=Do(n.toGenerator(r),a=>a!=null),i=!1,s=async a=>{let c=a.cid,l=await vn(this.components.blockstore.get(c,a)),p=An({cid:c,bytes:l,codec:await this.components.getCodec(c.code)});for(let[,m]of p.links())r?.includeChild?.(m,p)!==!1&&n.add(s,{...a,cid:m,depth:a.depth+1,path:[...a.path,m]}).catch(x=>{i||o.throw(x)});return{block:p,depth:a.depth,path:a.path}};n.add(s,{...r,cid:e,depth:0,path:[e]}).catch(a=>{i||o.throw(a)});try{yield*o}finally{i=!0,n.abort()}}},Cs=class extends Lr{getQueue(){return new J({concurrency:1,sort:(e,r)=>e.options.depth===r.options.depth?0:e.options.depth<r.options.depth?1:-1})}},Ls=class extends Lr{getQueue(){return new J({concurrency:1,sort:(e,r)=>e.options.depth===r.options.depth?0:e.options.depth<r.options.depth?-1:1})}},Bs=class extends Lr{getQueue(){return new J({concurrency:1})}};var Rs=class{libp2p;blockstore;datastore;events;pins;logger;routing;getCodec;getHasher;dns;metrics;log;constructor(e){this.logger=e.logger??e.libp2p.logger,this.log=this.logger.forComponent("helia"),this.getHasher=hl(e.hashers,e.loadHasher),this.getCodec=dl(e.codecs,e.loadCodec),this.dns=e.dns??ya(),this.metrics=e.metrics,this.libp2p=e.libp2p,this.events=new le;let r={blockstore:e.blockstore,datastore:e.datastore,logger:this.logger,libp2p:this.libp2p,blockBrokers:[],getHasher:this.getHasher,getCodec:this.getCodec,dns:this.dns,metrics:this.metrics,...e.components??{}};this.routing=r.routing=new Dn(r,{routers:(e.routers??[]).flatMap(o=>{typeof o=="function"&&(o=o(r));let i=[o],s=rg(o);s!=null&&i.push(s);let a=ng(o);return a!=null&&i.push(a),i}),providerLookupConcurrency:e.providerLookupConcurrency}),r.blockBrokers=e.blockBrokers.map(o=>o(r));let n=new $o(r,e);this.pins=new Cn(e.datastore,n,this.getCodec),this.blockstore=new Zn(n,this.pins,{holdGcLock:e.holdGcLock??!0}),this.datastore=e.datastore}async start(){await Oc(this.datastore),await We(this.blockstore,this.datastore,this.routing,this.libp2p),this.events.dispatchEvent(new CustomEvent("start",{detail:this}))}async stop(){await Ge(this.blockstore,this.datastore,this.routing,this.libp2p),this.events.dispatchEvent(new CustomEvent("stop",{detail:this}))}async gc(e={}){let r=await this.blockstore.lock.writeLock();try{let n=this,o=this.blockstore.unwrap();this.log("gc start"),await wa(o.deleteMany((async function*(){for await(let{cid:i}of o.getAll())try{if(await n.pins.isPinned(i,e))continue;yield i,e.onProgress?.(new A("helia:gc:deleted",i))}catch(s){n.log.error("error during gc - %e",s),e.onProgress?.(new A("helia:gc:error",s))}})()))}finally{r()}this.log("gc finished")}};function rg(t){return t?.[Ms]}function ng(t){return t?.[Os]}return kl(og);})();
2
+ "use strict";var HeliaUtils=(()=>{var El=Object.create;var Dr=Object.defineProperty;var _l=Object.getOwnPropertyDescriptor;var vl=Object.getOwnPropertyNames;var kl=Object.getPrototypeOf,Al=Object.prototype.hasOwnProperty;var $s=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),M=(t,e)=>{for(var r in e)Dr(t,r,{get:e[r],enumerable:!0})},Ms=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of vl(e))!Al.call(t,o)&&o!==r&&Dr(t,o,{get:()=>e[o],enumerable:!(n=_l(e,o))||n.enumerable});return t};var Os=(t,e,r)=>(r=t!=null?El(kl(t)):{},Ms(e||!t||!t.__esModule?Dr(r,"default",{value:t,enumerable:!0}):r,t)),Tl=t=>Ms(Dr({},"__esModule",{value:!0}),t);var Vs=$s((mg,zo)=>{"use strict";var Il=Object.prototype.hasOwnProperty,K="~";function Gt(){}Object.create&&(Gt.prototype=Object.create(null),new Gt().__proto__||(K=!1));function Sl(t,e,r){this.fn=t,this.context=e,this.once=r||!1}function qs(t,e,r,n,o){if(typeof r!="function")throw new TypeError("The listener must be a function");var i=new Sl(r,n||t,o),s=K?K+e:e;return t._events[s]?t._events[s].fn?t._events[s]=[t._events[s],i]:t._events[s].push(i):(t._events[s]=i,t._eventsCount++),t}function Fr(t,e){--t._eventsCount===0?t._events=new Gt:delete t._events[e]}function V(){this._events=new Gt,this._eventsCount=0}V.prototype.eventNames=function(){var e=[],r,n;if(this._eventsCount===0)return e;for(n in r=this._events)Il.call(r,n)&&e.push(K?n.slice(1):n);return Object.getOwnPropertySymbols?e.concat(Object.getOwnPropertySymbols(r)):e};V.prototype.listeners=function(e){var r=K?K+e:e,n=this._events[r];if(!n)return[];if(n.fn)return[n.fn];for(var o=0,i=n.length,s=new Array(i);o<i;o++)s[o]=n[o].fn;return s};V.prototype.listenerCount=function(e){var r=K?K+e:e,n=this._events[r];return n?n.fn?1:n.length:0};V.prototype.emit=function(e,r,n,o,i,s){var a=K?K+e:e;if(!this._events[a])return!1;var c=this._events[a],l=arguments.length,p,m;if(c.fn){switch(c.once&&this.removeListener(e,c.fn,void 0,!0),l){case 1:return c.fn.call(c.context),!0;case 2:return c.fn.call(c.context,r),!0;case 3:return c.fn.call(c.context,r,n),!0;case 4:return c.fn.call(c.context,r,n,o),!0;case 5:return c.fn.call(c.context,r,n,o,i),!0;case 6:return c.fn.call(c.context,r,n,o,i,s),!0}for(m=1,p=new Array(l-1);m<l;m++)p[m-1]=arguments[m];c.fn.apply(c.context,p)}else{var x=c.length,k;for(m=0;m<x;m++)switch(c[m].once&&this.removeListener(e,c[m].fn,void 0,!0),l){case 1:c[m].fn.call(c[m].context);break;case 2:c[m].fn.call(c[m].context,r);break;case 3:c[m].fn.call(c[m].context,r,n);break;case 4:c[m].fn.call(c[m].context,r,n,o);break;default:if(!p)for(k=1,p=new Array(l-1);k<l;k++)p[k-1]=arguments[k];c[m].fn.apply(c[m].context,p)}}return!0};V.prototype.on=function(e,r,n){return qs(this,e,r,n,!1)};V.prototype.once=function(e,r,n){return qs(this,e,r,n,!0)};V.prototype.removeListener=function(e,r,n,o){var i=K?K+e:e;if(!this._events[i])return this;if(!r)return Fr(this,i),this;var s=this._events[i];if(s.fn)s.fn===r&&(!o||s.once)&&(!n||s.context===n)&&Fr(this,i);else{for(var a=0,c=[],l=s.length;a<l;a++)(s[a].fn!==r||o&&!s[a].once||n&&s[a].context!==n)&&c.push(s[a]);c.length?this._events[i]=c.length===1?c[0]:c:Fr(this,i)}return this};V.prototype.removeAllListeners=function(e){var r;return e?(r=K?K+e:e,this._events[r]&&Fr(this,r)):(this._events=new Gt,this._eventsCount=0),this};V.prototype.off=V.prototype.removeListener;V.prototype.addListener=V.prototype.on;V.prefixed=K;V.EventEmitter=V;typeof zo<"u"&&(zo.exports=V)});var ga=$s((Uy,ma)=>{ma.exports=function(t){if(!t)throw Error("hashlru must have a max value, of type number, greater than 0");var e=0,r=Object.create(null),n=Object.create(null);function o(i,s){r[i]=s,e++,e>=t&&(e=0,n=r,r=Object.create(null))}return{has:function(i){return r[i]!==void 0||n[i]!==void 0},remove:function(i){r[i]!==void 0&&(r[i]=void 0),n[i]!==void 0&&(n[i]=void 0)},get:function(i){var s=r[i];if(s!==void 0)return s;if((s=n[i])!==void 0)return o(i,s),s},set:function(i,s){r[i]!==void 0?r[i]=s:o(i,s)},clear:function(){r=Object.create(null),n=Object.create(null)}}}});var sg={};M(sg,{AbstractSession:()=>Fo,Helia:()=>Ds,breadthFirstWalker:()=>xl,depthFirstWalker:()=>wl,naturalOrderWalker:()=>bl});var Fs=Symbol.for("@libp2p/content-routing");var xe=class extends Error{static name="AbortError";constructor(e="The operation was aborted"){super(e),this.name="AbortError"}};var yt=class extends Error{static name="InvalidParametersError";constructor(e="Invalid parameters"){super(e),this.name="InvalidParametersError"}};var $r=class extends Error{static name="NotFoundError";constructor(e="Not found"){super(e),this.name="NotFoundError"}};var Mr=class extends Error{static name="InvalidMultihashError";constructor(e="Invalid Multihash"){super(e),this.name="InvalidMultihashError"}};var zs=Symbol.for("@libp2p/peer-routing");function js(t){return t!=null&&typeof t.start=="function"&&typeof t.stop=="function"}async function We(...t){let e=[];for(let r of t)js(r)&&e.push(r);await Promise.all(e.map(async r=>{r.beforeStart!=null&&await r.beforeStart()})),await Promise.all(e.map(async r=>{await r.start()})),await Promise.all(e.map(async r=>{r.afterStart!=null&&await r.afterStart()}))}async function Ge(...t){let e=[];for(let r of t)js(r)&&e.push(r);await Promise.all(e.map(async r=>{r.beforeStop!=null&&await r.beforeStop()})),await Promise.all(e.map(async r=>{await r.stop()})),await Promise.all(e.map(async r=>{r.afterStop!=null&&await r.afterStop()}))}var le=class extends EventTarget{#e=new Map;constructor(){super()}listenerCount(e){let r=this.#e.get(e);return r==null?0:r.length}addEventListener(e,r,n){super.addEventListener(e,r,n);let o=this.#e.get(e);o==null&&(o=[],this.#e.set(e,o)),o.push({callback:r,once:(n!==!0&&n!==!1&&n?.once)??!1})}removeEventListener(e,r,n){super.removeEventListener(e.toString(),r??null,n);let o=this.#e.get(e);o!=null&&(o=o.filter(({callback:i})=>i!==r),this.#e.set(e,o))}dispatchEvent(e){let r=super.dispatchEvent(e),n=this.#e.get(e.type);return n==null||(n=n.filter(({once:o})=>!o),this.#e.set(e.type,n)),r}safeDispatchEvent(e,r={}){return this.dispatchEvent(new CustomEvent(e,r))}};var A=class extends Event{type;detail;constructor(e,r){super(e),this.type=e,this.detail=r}};var Or=class extends AggregateError{static name="DNSQueryFailedError";name="DNSQueryFailedError"};var jo=Os(Vs(),1);var qo=class t extends Error{name="TimeoutError";constructor(e,r){super(e,r),Error.captureStackTrace?.(this,t)}},Hs=t=>t.reason??new DOMException("This operation was aborted.","AbortError");function Qt(t,e){let{milliseconds:r,fallback:n,message:o,customTimers:i={setTimeout,clearTimeout},signal:s}=e,a,c,p=new Promise((m,x)=>{if(typeof r!="number"||Math.sign(r)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${r}\``);if(s?.aborted){x(Hs(s));return}if(s&&(c=()=>{x(Hs(s))},s.addEventListener("abort",c,{once:!0})),t.then(m,x),r===Number.POSITIVE_INFINITY)return;let k=new qo;a=i.setTimeout.call(void 0,()=>{if(n){try{m(n())}catch(I){x(I)}return}typeof t.cancel=="function"&&t.cancel(),o===!1?m():o instanceof Error?x(o):(k.message=o??`Promise timed out after ${r} milliseconds`,x(k))},r)}).finally(()=>{p.clear(),c&&s&&s.removeEventListener("abort",c)});return p.clear=()=>{i.clearTimeout.call(void 0,a),a=void 0},p}function Vo(t,e,r){let n=0,o=t.length;for(;o>0;){let i=Math.trunc(o/2),s=n+i;r(t[s],e)<=0?(n=++s,o-=i+1):o=i}return n}var wt=class{#e=[];enqueue(e,r){let{priority:n=0,id:o}=r??{},i={priority:n,id:o,run:e};if(this.size===0||this.#e[this.size-1].priority>=n){this.#e.push(i);return}let s=Vo(this.#e,i,(a,c)=>c.priority-a.priority);this.#e.splice(s,0,i)}setPriority(e,r){let n=this.#e.findIndex(i=>i.id===e);if(n===-1)throw new ReferenceError(`No promise function with the id "${e}" exists in the queue.`);let[o]=this.#e.splice(n,1);this.enqueue(o.run,{priority:r,id:e})}remove(e){let r=this.#e.findIndex(n=>typeof e=="string"?n.id===e:n.run===e);r!==-1&&this.#e.splice(r,1)}dequeue(){return this.#e.shift()?.run}filter(e){return this.#e.filter(r=>r.priority===e.priority).map(r=>r.run)}get size(){return this.#e.length}};var Jt=class extends jo.default{#e;#o;#a=0;#h;#m=!1;#x=!1;#c;#I=0;#b=0;#u;#f;#s;#i=[];#n=0;#t;#S;#r=0;#g;#l;#B=1n;#y=new Map;#E=new Set;timeout;constructor(e){if(super(),e={carryoverIntervalCount:!1,intervalCap:Number.POSITIVE_INFINITY,interval:0,concurrency:Number.POSITIVE_INFINITY,autoStart:!0,queueClass:wt,strict:!1,...e},!(typeof e.intervalCap=="number"&&e.intervalCap>=1))throw new TypeError(`Expected \`intervalCap\` to be a number from 1 and up, got \`${e.intervalCap?.toString()??""}\` (${typeof e.intervalCap})`);if(e.interval===void 0||!(Number.isFinite(e.interval)&&e.interval>=0))throw new TypeError(`Expected \`interval\` to be a finite number >= 0, got \`${e.interval?.toString()??""}\` (${typeof e.interval})`);if(e.strict&&e.interval===0)throw new TypeError("The `strict` option requires a non-zero `interval`");if(e.strict&&e.intervalCap===Number.POSITIVE_INFINITY)throw new TypeError("The `strict` option requires a finite `intervalCap`");if(this.#e=e.carryoverIntervalCount??e.carryoverConcurrencyCount??!1,this.#o=e.intervalCap===Number.POSITIVE_INFINITY||e.interval===0,this.#h=e.intervalCap,this.#c=e.interval,this.#s=e.strict,this.#t=new e.queueClass,this.#S=e.queueClass,this.concurrency=e.concurrency,e.timeout!==void 0&&!(Number.isFinite(e.timeout)&&e.timeout>0))throw new TypeError(`Expected \`timeout\` to be a positive finite number, got \`${e.timeout}\` (${typeof e.timeout})`);this.timeout=e.timeout,this.#l=e.autoStart===!1,this.#z()}#_(e){for(;this.#n<this.#i.length;){let n=this.#i[this.#n];if(n!==void 0&&e-n>=this.#c)this.#n++;else break}(this.#n>100&&this.#n>this.#i.length/2||this.#n===this.#i.length)&&(this.#i=this.#i.slice(this.#n),this.#n=0)}#R(e){this.#s?this.#i.push(e):this.#a++}#P(){this.#s?this.#i.length>this.#n&&this.#i.pop():this.#a>0&&this.#a--}#v(){return this.#i.length-this.#n}get#D(){return this.#o?!0:this.#s?this.#v()<this.#h:this.#a<this.#h}get#$(){return this.#r<this.#g}#M(){this.#r--,this.#r===0&&this.emit("pendingZero"),this.#w(),this.emit("next")}#O(){this.#f=void 0,this.#C(),this.#N()}#F(e){if(this.#s){if(this.#_(e),this.#v()>=this.#h){let n=this.#i[this.#n],o=this.#c-(e-n);return this.#k(o),!0}return!1}if(this.#u===void 0){let r=this.#I-e;if(r<0){if(this.#b>0){let n=e-this.#b;if(n<this.#c)return this.#k(this.#c-n),!0}this.#a=this.#e?this.#r:0}else return this.#k(r),!0}return!1}#k(e){this.#f===void 0&&(this.#f=setTimeout(()=>{this.#O()},e))}#A(){this.#u&&(clearInterval(this.#u),this.#u=void 0)}#U(){this.#f&&(clearTimeout(this.#f),this.#f=void 0)}#w(){if(this.#t.size===0){if(this.#A(),this.emit("empty"),this.#r===0){if(this.#U(),this.#s&&this.#n>0){let r=Date.now();this.#_(r)}this.emit("idle")}return!1}let e=!1;if(!this.#l){let r=Date.now(),n=!this.#F(r);if(this.#D&&this.#$){let o=this.#t.dequeue();this.#o||(this.#R(r),this.#p()),this.emit("active"),o(),n&&this.#N(),e=!0}}return e}#N(){this.#o||this.#u!==void 0||this.#s||(this.#u=setInterval(()=>{this.#C()},this.#c),this.#I=Date.now()+this.#c)}#C(){this.#s||(this.#a===0&&this.#r===0&&this.#u&&this.#A(),this.#a=this.#e?this.#r:0),this.#T(),this.#p()}#T(){for(;this.#w(););}get concurrency(){return this.#g}set concurrency(e){if(!(typeof e=="number"&&e>=1))throw new TypeError(`Expected \`concurrency\` to be a number from 1 and up, got \`${e}\` (${typeof e})`);this.#g=e,this.#T()}setPriority(e,r){if(typeof r!="number"||!Number.isFinite(r))throw new TypeError(`Expected \`priority\` to be a finite number, got \`${r}\` (${typeof r})`);this.#t.setPriority(e,r)}async add(e,r={}){return r={timeout:this.timeout,...r,id:r.id??(this.#B++).toString()},new Promise((n,o)=>{let i=Symbol(`task-${r.id}`),s=()=>{},a=async()=>{s(),this.#r++,this.#y.set(i,{id:r.id,priority:r.priority??0,startTime:Date.now(),timeout:r.timeout});let l;try{try{r.signal?.throwIfAborted()}catch(x){throw this.#j(),this.#y.delete(i),x}this.#b=Date.now();let p=e({signal:r.signal});if(r.timeout&&(p=Qt(Promise.resolve(p),{milliseconds:r.timeout,message:`Task timed out after ${r.timeout}ms (queue has ${this.#r} running, ${this.#t.size} waiting)`})),r.signal){let{signal:x}=r;p=Promise.race([p,new Promise((k,I)=>{l=()=>{I(x.reason)},x.addEventListener("abort",l,{once:!0})})])}let m=await p;n(m),this.emit("completed",m)}catch(p){o(p),this.emit("error",p)}finally{l&&r.signal?.removeEventListener("abort",l),this.#y.delete(i),queueMicrotask(()=>{this.#M()})}};this.#t.enqueue(a,r);let c=()=>{if(this.#t instanceof wt){this.#t.remove(a);return}this.#t.remove?.(r.id)};if(r.signal){let{signal:l}=r,p=()=>{s(),c(),o(l.reason),this.#w(),this.emit("next")};if(s=()=>{l.removeEventListener("abort",p),this.#E.delete(s)},l.aborted){p();return}l.addEventListener("abort",p,{once:!0}),this.#E.add(s)}this.emit("add"),this.#w()})}async addAll(e,r){return Promise.all(e.map(async n=>this.add(n,r)))}start(){return this.#l?(this.#l=!1,this.#T(),this):this}pause(){this.#l=!0}clear(){for(let e of this.#E)e();this.#t=new this.#S,this.#A(),this.#L(),this.emit("empty"),this.#r===0&&(this.#U(),this.emit("idle")),this.emit("next")}async onEmpty(){this.#t.size!==0&&await this.#d("empty")}async onSizeLessThan(e){this.#t.size<e||await this.#d("next",()=>this.#t.size<e)}async onIdle(){this.#r===0&&this.#t.size===0||await this.#d("idle")}async onPendingZero(){this.#r!==0&&await this.#d("pendingZero")}async onRateLimit(){this.isRateLimited||await this.#d("rateLimit")}async onRateLimitCleared(){this.isRateLimited&&await this.#d("rateLimitCleared")}onError(){return new Promise((e,r)=>{let n=o=>{this.off("error",n),r(o)};this.on("error",n)})}async#d(e,r){return new Promise(n=>{let o=()=>{r&&!r()||(this.off(e,o),n())};this.on(e,o)})}get size(){return this.#t.size}sizeBy(e){return this.#t.filter(e).length}get pending(){return this.#r}get isPaused(){return this.#l}#z(){this.#o||(this.on("add",()=>{this.#t.size>0&&this.#p()}),this.on("next",()=>{this.#p()}))}#p(){this.#o||this.#x||(this.#x=!0,queueMicrotask(()=>{this.#x=!1,this.#L()}))}#j(){this.#o||(this.#P(),this.#p())}#L(){let e=this.#m;if(this.#o||this.#t.size===0){e&&(this.#m=!1,this.emit("rateLimitCleared"));return}let r;if(this.#s){let o=Date.now();this.#_(o),r=this.#v()}else r=this.#a;let n=r>=this.#h;n!==e&&(this.#m=n,this.emit(n?"rateLimit":"rateLimitCleared"))}get isRateLimited(){return this.#m}get isSaturated(){return this.#r===this.#g&&this.#t.size>0||this.isRateLimited&&this.#t.size>0}get runningTasks(){return[...this.#y.values()].map(e=>({...e}))}};function zr(t){let e=[be.A];return t==null?e:Array.isArray(t)?t.length===0?e:t:[t]}var Jo={};M(Jo,{base10:()=>Pl});var Ig=new Uint8Array(0);function Ks(t,e){if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;for(let r=0;r<t.byteLength;r++)if(t[r]!==e[r])return!1;return!0}function Ee(t){if(t instanceof Uint8Array&&t.constructor.name==="Uint8Array")return t;if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.isView(t))return new Uint8Array(t.buffer,t.byteOffset,t.byteLength);throw new Error("Unknown type, must be binary type")}function Ws(t){return new TextEncoder().encode(t)}function Gs(t){return new TextDecoder().decode(t)}function Ul(t,e){if(t.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),n=0;n<r.length;n++)r[n]=255;for(var o=0;o<t.length;o++){var i=t.charAt(o),s=i.charCodeAt(0);if(r[s]!==255)throw new TypeError(i+" is ambiguous");r[s]=o}var a=t.length,c=t.charAt(0),l=Math.log(a)/Math.log(256),p=Math.log(256)/Math.log(a);function m(I){if(I instanceof Uint8Array||(ArrayBuffer.isView(I)?I=new Uint8Array(I.buffer,I.byteOffset,I.byteLength):Array.isArray(I)&&(I=Uint8Array.from(I))),!(I instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(I.length===0)return"";for(var P=0,S=0,$=0,H=I.length;$!==H&&I[$]===0;)$++,P++;for(var q=(H-$)*p+1>>>0,Q=new Uint8Array(q);$!==H;){for(var fe=I[$],Ke=0,we=q-1;(fe!==0||Ke<S)&&we!==-1;we--,Ke++)fe+=256*Q[we]>>>0,Q[we]=fe%a>>>0,fe=fe/a>>>0;if(fe!==0)throw new Error("Non-zero carry");S=Ke,$++}for(var $e=q-S;$e!==q&&Q[$e]===0;)$e++;for(var Pr=c.repeat(P);$e<q;++$e)Pr+=t.charAt(Q[$e]);return Pr}function x(I){if(typeof I!="string")throw new TypeError("Expected String");if(I.length===0)return new Uint8Array;var P=0;if(I[P]!==" "){for(var S=0,$=0;I[P]===c;)S++,P++;for(var H=(I.length-P)*l+1>>>0,q=new Uint8Array(H);I[P];){var Q=r[I.charCodeAt(P)];if(Q===255)return;for(var fe=0,Ke=H-1;(Q!==0||fe<$)&&Ke!==-1;Ke--,fe++)Q+=a*q[Ke]>>>0,q[Ke]=Q%256>>>0,Q=Q/256>>>0;if(Q!==0)throw new Error("Non-zero carry");$=fe,P++}if(I[P]!==" "){for(var we=H-$;we!==H&&q[we]===0;)we++;for(var $e=new Uint8Array(S+(H-we)),Pr=S;we!==H;)$e[Pr++]=q[we++];return $e}}}function k(I){var P=x(I);if(P)return P;throw new Error(`Non-${e} character`)}return{encode:m,decodeUnsafe:x,decode:k}}var Nl=Ul,Cl=Nl,Qs=Cl;var Ko=class{name;prefix;baseEncode;constructor(e,r,n){this.name=e,this.prefix=r,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},Wo=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,r,n){this.name=e,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(e){if(typeof e=="string"){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(e){return Js(this,e)}},Go=class{decoders;constructor(e){this.decoders=e}or(e){return Js(this,e)}decode(e){let r=e[0],n=this.decoders[r];if(n!=null)return n.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function Js(t,e){return new Go({...t.decoders??{[t.prefix]:t},...e.decoders??{[e.prefix]:e}})}var Qo=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,r,n,o){this.name=e,this.prefix=r,this.baseEncode=n,this.baseDecode=o,this.encoder=new Ko(e,r,n),this.decoder=new Wo(e,r,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function xt({name:t,prefix:e,encode:r,decode:n}){return new Qo(t,e,r,n)}function Qe({name:t,prefix:e,alphabet:r}){let{encode:n,decode:o}=Qs(r,t);return xt({prefix:e,name:t,encode:n,decode:i=>Ee(o(i))})}function Ll(t,e,r,n){let o=t.length;for(;t[o-1]==="=";)--o;let i=new Uint8Array(o*r/8|0),s=0,a=0,c=0;for(let l=0;l<o;++l){let p=e[t[l]];if(p===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|p,s+=r,s>=8&&(s-=8,i[c++]=255&a>>s)}if(s>=r||(255&a<<8-s)!==0)throw new SyntaxError("Unexpected end of data");return i}function Bl(t,e,r){let n=e[e.length-1]==="=",o=(1<<r)-1,i="",s=0,a=0;for(let c=0;c<t.length;++c)for(a=a<<8|t[c],s+=8;s>r;)s-=r,i+=e[o&a>>s];if(s!==0&&(i+=e[o&a<<r-s]),n)for(;(i.length*r&7)!==0;)i+="=";return i}function Rl(t){let e={};for(let r=0;r<t.length;++r)e[t[r]]=r;return e}function D({name:t,prefix:e,bitsPerChar:r,alphabet:n}){let o=Rl(n);return xt({prefix:e,name:t,encode(i){return Bl(i,n,r)},decode(i){return Ll(i,o,r,t)}})}var Pl=Qe({prefix:"9",name:"base10",alphabet:"0123456789"});var Yo={};M(Yo,{base16:()=>Dl,base16upper:()=>$l});var Dl=D({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),$l=D({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Xo={};M(Xo,{base2:()=>Ml});var Ml=D({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Zo={};M(Zo,{base256emoji:()=>ql});var Ys=Array.from("\u{1F680}\u{1FA90}\u2604\u{1F6F0}\u{1F30C}\u{1F311}\u{1F312}\u{1F313}\u{1F314}\u{1F315}\u{1F316}\u{1F317}\u{1F318}\u{1F30D}\u{1F30F}\u{1F30E}\u{1F409}\u2600\u{1F4BB}\u{1F5A5}\u{1F4BE}\u{1F4BF}\u{1F602}\u2764\u{1F60D}\u{1F923}\u{1F60A}\u{1F64F}\u{1F495}\u{1F62D}\u{1F618}\u{1F44D}\u{1F605}\u{1F44F}\u{1F601}\u{1F525}\u{1F970}\u{1F494}\u{1F496}\u{1F499}\u{1F622}\u{1F914}\u{1F606}\u{1F644}\u{1F4AA}\u{1F609}\u263A\u{1F44C}\u{1F917}\u{1F49C}\u{1F614}\u{1F60E}\u{1F607}\u{1F339}\u{1F926}\u{1F389}\u{1F49E}\u270C\u2728\u{1F937}\u{1F631}\u{1F60C}\u{1F338}\u{1F64C}\u{1F60B}\u{1F497}\u{1F49A}\u{1F60F}\u{1F49B}\u{1F642}\u{1F493}\u{1F929}\u{1F604}\u{1F600}\u{1F5A4}\u{1F603}\u{1F4AF}\u{1F648}\u{1F447}\u{1F3B6}\u{1F612}\u{1F92D}\u2763\u{1F61C}\u{1F48B}\u{1F440}\u{1F62A}\u{1F611}\u{1F4A5}\u{1F64B}\u{1F61E}\u{1F629}\u{1F621}\u{1F92A}\u{1F44A}\u{1F973}\u{1F625}\u{1F924}\u{1F449}\u{1F483}\u{1F633}\u270B\u{1F61A}\u{1F61D}\u{1F634}\u{1F31F}\u{1F62C}\u{1F643}\u{1F340}\u{1F337}\u{1F63B}\u{1F613}\u2B50\u2705\u{1F97A}\u{1F308}\u{1F608}\u{1F918}\u{1F4A6}\u2714\u{1F623}\u{1F3C3}\u{1F490}\u2639\u{1F38A}\u{1F498}\u{1F620}\u261D\u{1F615}\u{1F33A}\u{1F382}\u{1F33B}\u{1F610}\u{1F595}\u{1F49D}\u{1F64A}\u{1F639}\u{1F5E3}\u{1F4AB}\u{1F480}\u{1F451}\u{1F3B5}\u{1F91E}\u{1F61B}\u{1F534}\u{1F624}\u{1F33C}\u{1F62B}\u26BD\u{1F919}\u2615\u{1F3C6}\u{1F92B}\u{1F448}\u{1F62E}\u{1F646}\u{1F37B}\u{1F343}\u{1F436}\u{1F481}\u{1F632}\u{1F33F}\u{1F9E1}\u{1F381}\u26A1\u{1F31E}\u{1F388}\u274C\u270A\u{1F44B}\u{1F630}\u{1F928}\u{1F636}\u{1F91D}\u{1F6B6}\u{1F4B0}\u{1F353}\u{1F4A2}\u{1F91F}\u{1F641}\u{1F6A8}\u{1F4A8}\u{1F92C}\u2708\u{1F380}\u{1F37A}\u{1F913}\u{1F619}\u{1F49F}\u{1F331}\u{1F616}\u{1F476}\u{1F974}\u25B6\u27A1\u2753\u{1F48E}\u{1F4B8}\u2B07\u{1F628}\u{1F31A}\u{1F98B}\u{1F637}\u{1F57A}\u26A0\u{1F645}\u{1F61F}\u{1F635}\u{1F44E}\u{1F932}\u{1F920}\u{1F927}\u{1F4CC}\u{1F535}\u{1F485}\u{1F9D0}\u{1F43E}\u{1F352}\u{1F617}\u{1F911}\u{1F30A}\u{1F92F}\u{1F437}\u260E\u{1F4A7}\u{1F62F}\u{1F486}\u{1F446}\u{1F3A4}\u{1F647}\u{1F351}\u2744\u{1F334}\u{1F4A3}\u{1F438}\u{1F48C}\u{1F4CD}\u{1F940}\u{1F922}\u{1F445}\u{1F4A1}\u{1F4A9}\u{1F450}\u{1F4F8}\u{1F47B}\u{1F910}\u{1F92E}\u{1F3BC}\u{1F975}\u{1F6A9}\u{1F34E}\u{1F34A}\u{1F47C}\u{1F48D}\u{1F4E3}\u{1F942}"),Ol=Ys.reduce((t,e,r)=>(t[r]=e,t),[]),Fl=Ys.reduce((t,e,r)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return t[n]=r,t},[]);function zl(t){return t.reduce((e,r)=>(e+=Ol[r],e),"")}function jl(t){let e=[];for(let r of t){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=Fl[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);e.push(o)}return new Uint8Array(e)}var ql=xt({prefix:"\u{1F680}",name:"base256emoji",encode:zl,decode:jl});var ei={};M(ei,{base32:()=>bt,base32hex:()=>Wl,base32hexpad:()=>Ql,base32hexpadupper:()=>Jl,base32hexupper:()=>Gl,base32pad:()=>Hl,base32padupper:()=>Kl,base32upper:()=>Vl,base32z:()=>Yl});var bt=D({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Vl=D({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Hl=D({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Kl=D({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Wl=D({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Gl=D({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Ql=D({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Jl=D({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Yl=D({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var ti={};M(ti,{base36:()=>Me,base36upper:()=>Xl});var Me=Qe({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Xl=Qe({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var ri={};M(ri,{base58btc:()=>Ce,base58flickr:()=>Zl});var Ce=Qe({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Zl=Qe({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var ni={};M(ni,{base64:()=>Et,base64pad:()=>ed,base64url:()=>td,base64urlpad:()=>rd});var Et=D({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),ed=D({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),td=D({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),rd=D({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var oi={};M(oi,{base8:()=>nd});var nd=D({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var ii={};M(ii,{identity:()=>od});var od=xt({prefix:"\0",name:"identity",encode:t=>Gs(t),decode:t=>Ws(t)});var jr={};M(jr,{code:()=>si,decode:()=>ud,encode:()=>cd,name:()=>ad});var id=new TextEncoder,sd=new TextDecoder,ad="json",si=512;function cd(t){return id.encode(JSON.stringify(t))}function ud(t){return JSON.parse(sd.decode(t))}var qr={};M(qr,{code:()=>ai,decode:()=>dd,encode:()=>ld,name:()=>fd});var fd="raw",ai=85;function ld(t){return Ee(t)}function dd(t){return Ee(t)}var ui={};M(ui,{identity:()=>Hr});var hd=ea,Xs=128,pd=127,md=~pd,gd=Math.pow(2,31);function ea(t,e,r){e=e||[],r=r||0;for(var n=r;t>=gd;)e[r++]=t&255|Xs,t/=128;for(;t&md;)e[r++]=t&255|Xs,t>>>=7;return e[r]=t|0,ea.bytes=r-n+1,e}var yd=ci,wd=128,Zs=127;function ci(t,n){var r=0,n=n||0,o=0,i=n,s,a=t.length;do{if(i>=a)throw ci.bytes=0,new RangeError("Could not decode varint");s=t[i++],r+=o<28?(s&Zs)<<o:(s&Zs)*Math.pow(2,o),o+=7}while(s>=wd);return ci.bytes=i-n,r}var xd=Math.pow(2,7),bd=Math.pow(2,14),Ed=Math.pow(2,21),_d=Math.pow(2,28),vd=Math.pow(2,35),kd=Math.pow(2,42),Ad=Math.pow(2,49),Td=Math.pow(2,56),Id=Math.pow(2,63),Sd=function(t){return t<xd?1:t<bd?2:t<Ed?3:t<_d?4:t<vd?5:t<kd?6:t<Ad?7:t<Td?8:t<Id?9:10},Ud={encode:hd,decode:yd,encodingLength:Sd},Nd=Ud,Yt=Nd;function Xt(t,e=0){return[Yt.decode(t,e),Yt.decode.bytes]}function _t(t,e,r=0){return Yt.encode(t,e,r),e}function vt(t){return Yt.encodingLength(t)}function At(t,e){let r=e.byteLength,n=vt(t),o=n+vt(r),i=new Uint8Array(o+r);return _t(t,i,0),_t(r,i,n),i.set(e,o),new kt(t,r,e,i)}function ta(t){let e=Ee(t),[r,n]=Xt(e),[o,i]=Xt(e.subarray(n)),s=e.subarray(n+i);if(s.byteLength!==o)throw new Error("Incorrect length");return new kt(r,o,s,e)}function ra(t,e){if(t===e)return!0;{let r=e;return t.code===r.code&&t.size===r.size&&r.bytes instanceof Uint8Array&&Ks(t.bytes,r.bytes)}}var kt=class{code;size;digest;bytes;constructor(e,r,n,o){this.code=e,this.size=r,this.digest=n,this.bytes=o}};var na=0,Cd="identity",oa=Ee;function Ld(t,e){if(e?.truncate!=null&&e.truncate!==t.byteLength){if(e.truncate<0||e.truncate>t.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${t.byteLength}`);t=t.subarray(0,e.truncate)}return At(na,oa(t))}var Hr={code:na,name:Cd,encode:oa,digest:Ld};var di={};M(di,{sha256:()=>Kr,sha512:()=>Wr});var Bd=20;function li({name:t,code:e,encode:r,minDigestLength:n,maxDigestLength:o}){return new fi(t,e,r,n,o)}var fi=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,r,n,o,i){this.name=e,this.code=r,this.encode=n,this.minDigestLength=o??Bd,this.maxDigestLength=i}digest(e,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(e instanceof Uint8Array){let n=this.encode(e);return n instanceof Uint8Array?ia(n,this.code,r?.truncate):n.then(o=>ia(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function ia(t,e,r){if(r!=null&&r!==t.byteLength){if(r>t.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${t.byteLength}`);t=t.subarray(0,r)}return At(e,t)}function aa(t){return async e=>new Uint8Array(await crypto.subtle.digest(t,e))}var Kr=li({name:"sha2-256",code:18,encode:aa("SHA-256")}),Wr=li({name:"sha2-512",code:19,encode:aa("SHA-512")});function ca(t,e){let{bytes:r,version:n}=t;switch(n){case 0:return Pd(r,hi(t),e??Ce.encoder);default:return Dd(r,hi(t),e??bt.encoder)}}var ua=new WeakMap;function hi(t){let e=ua.get(t);if(e==null){let r=new Map;return ua.set(t,r),r}return e}var L=class t{code;version;multihash;bytes;"/";constructor(e,r,n,o){this.code=r,this.version=e,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:e,multihash:r}=this;if(e!==er)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==$d)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return t.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:e,digest:r}=this.multihash,n=At(e,r);return t.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(e){return t.equals(this,e)}static equals(e,r){let n=r;return n!=null&&e.code===n.code&&e.version===n.version&&ra(e.multihash,n.multihash)}toString(e){return ca(this,e)}toJSON(){return{"/":ca(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(e){if(e==null)return null;let r=e;if(r instanceof t)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:o,multihash:i,bytes:s}=r;return new t(n,o,i,s??fa(n,o,i.bytes))}else if(r[Md]===!0){let{version:n,multihash:o,code:i}=r,s=ta(o);return t.create(n,i,s)}else return null}static create(e,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(e){case 0:{if(r!==er)throw new Error(`Version 0 CID must use dag-pb (code: ${er}) block encoding`);return new t(e,r,n,n.bytes)}case 1:{let o=fa(e,r,n.bytes);return new t(e,r,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return t.create(0,er,e)}static createV1(e,r){return t.create(1,e,r)}static decode(e){let[r,n]=t.decodeFirst(e);if(n.length!==0)throw new Error("Incorrect length");return r}static decodeFirst(e){let r=t.inspectBytes(e),n=r.size-r.multihashSize,o=Ee(e.subarray(n,n+r.multihashSize));if(o.byteLength!==r.multihashSize)throw new Error("Incorrect length");let i=o.subarray(r.multihashSize-r.digestSize),s=new kt(r.multihashCode,r.digestSize,i,o);return[r.version===0?t.createV0(s):t.createV1(r.codec,s),e.subarray(r.size)]}static inspectBytes(e){let r=0,n=()=>{let[m,x]=Xt(e.subarray(r));return r+=x,m},o=n(),i=er;if(o===18?(o=0,r=0):i=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let s=r,a=n(),c=n(),l=r+c,p=l-s;return{version:o,codec:i,multihashCode:a,digestSize:c,multihashSize:p,size:l}}static parse(e,r){let[n,o]=Rd(e,r),i=t.decode(o);if(i.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return hi(i).set(n,e),i}};function Rd(t,e){switch(t[0]){case"Q":{let r=e??Ce;return[Ce.prefix,r.decode(`${Ce.prefix}${t}`)]}case Ce.prefix:{let r=e??Ce;return[Ce.prefix,r.decode(t)]}case bt.prefix:{let r=e??bt;return[bt.prefix,r.decode(t)]}case Me.prefix:{let r=e??Me;return[Me.prefix,r.decode(t)]}default:{if(e==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[t[0],e.decode(t)]}}}function Pd(t,e,r){let{prefix:n}=r;if(n!==Ce.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let o=e.get(n);if(o==null){let i=r.encode(t).slice(1);return e.set(n,i),i}else return o}function Dd(t,e,r){let{prefix:n}=r,o=e.get(n);if(o==null){let i=r.encode(t);return e.set(n,i),i}else return o}var er=112,$d=18;function fa(t,e,r){let n=vt(t),o=n+vt(e),i=new Uint8Array(o+r.byteLength);return _t(t,i,0),_t(e,i,n),i.set(r,o),i}var Md=Symbol.for("@ipld/js-cid/CID");var pi={...ii,...Xo,...oi,...Jo,...Yo,...ei,...ti,...ri,...ni,...Zo},fy={...di,...ui};function la(t=0){return new Uint8Array(t)}function Gr(t=0){return new Uint8Array(t)}function ha(t,e,r,n){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:r},decoder:{decode:n}}}var da=ha("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),mi=ha("ascii","a",t=>{let e="a";for(let r=0;r<t.length;r++)e+=String.fromCharCode(t[r]);return e},t=>{t=t.substring(1);let e=Gr(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}),Od={utf8:da,"utf-8":da,hex:pi.base16,latin1:mi,ascii:mi,binary:mi,...pi},Qr=Od;function Je(t,e="utf8"){let r=Qr[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.encoder.encode(t).substring(1)}var gi=60;function Jr(t){return{Status:t.Status??0,TC:t.TC??t.flag_tc??!1,RD:t.RD??t.flag_rd??!1,RA:t.RA??t.flag_ra??!1,AD:t.AD??t.flag_ad??!1,CD:t.CD??t.flag_cd??!1,Question:(t.Question??t.questions??[]).map(e=>({name:e.name,type:be[e.type]})),Answer:(t.Answer??t.answers??[]).map(e=>({name:e.name,type:be[e.type],TTL:e.TTL??e.ttl??gi,data:e.data instanceof Uint8Array?Je(e.data):e.data}))}}var Fd=4;function yi(t,e={}){let r=new Jt({concurrency:e.queryConcurrency??Fd});return async(n,o={})=>{let i=o?.logger?.forComponent("dns:dns-json-over-https"),s=new URLSearchParams;s.set("name",n),zr(o.types).forEach(c=>{s.append("type",be[c])}),o.onProgress?.(new A("dns:query",n)),i?.("GET %s",`${t}?${s}`);let a=await r.add(async()=>{let c=await fetch(`${t}?${s}`,{headers:{accept:"application/dns-json"},signal:o?.signal});if(i?.("GET %s %d",c.url,c.status),c.status!==200)throw new Error(`Unexpected HTTP status: ${c.status} - ${c.statusText}`);let l=Jr(await c.json());return o.onProgress?.(new A("dns:response",l)),l},{signal:o.signal});if(a==null)throw new Error("No DNS response received");return a}}function pa(){return[yi("https://cloudflare-dns.com/dns-query"),yi("https://dns.google/resolve")]}var ya=Os(ga(),1);var wi=class{lru;constructor(e){this.lru=(0,ya.default)(e)}get(e,r){let n=!0,o=[];for(let i of r){let s=this.getAnswers(e,i);if(s.length===0){n=!1;break}o.push(...s)}if(n)return Jr({answers:o})}getAnswers(e,r){let n=`${e.toLowerCase()}-${r}`,o=this.lru.get(n);if(o!=null){let i=o.filter(s=>s.expires>Date.now()).map(({expires:s,value:a})=>({...a,TTL:Math.round((s-Date.now())/1e3),type:be[a.type]}));return i.length===0&&this.lru.remove(n),i}return[]}add(e,r){let n=`${e.toLowerCase()}-${r.type}`,o=this.lru.get(n)??[];o.push({expires:Date.now()+(r.TTL??gi)*1e3,value:r}),this.lru.set(n,o)}remove(e,r){let n=`${e.toLowerCase()}-${r}`;this.lru.remove(n)}clear(){this.lru.clear()}};function wa(t){return new wi(t)}var zd=1e3,Yr=class{resolvers;cache;logger;constructor(e){this.resolvers={},this.cache=wa(e.cacheSize??zd),this.logger=e.logger,Object.entries(e.resolvers??{}).forEach(([r,n])=>{Array.isArray(n)||(n=[n]),r.endsWith(".")||(r=`${r}.`),this.resolvers[r]=n}),this.resolvers["."]==null&&(this.resolvers["."]=pa())}async query(e,r={}){let n=zr(r.types),o=r.cached!==!1?this.cache.get(e,n):void 0;if(o!=null)return r.onProgress?.(new A("dns:cache",o)),o;let i=`${e.split(".").pop()}.`,s=(this.resolvers[i]??this.resolvers["."]).sort(()=>Math.random()>.5?-1:1),a=[];for(let c of s){if(r.signal?.aborted===!0)break;try{let l=await c(e,{...r,logger:this.logger,types:n});for(let p of l.Answer)this.cache.add(e,p);return l}catch(l){a.push(l),r.onProgress?.(new A("dns:error",l))}}throw new Or(a,`DNS lookup of ${e} ${n} failed`)}};var be;(function(t){t[t.A=1]="A",t[t.CNAME=5]="CNAME",t[t.TXT=16]="TXT",t[t.AAAA=28]="AAAA"})(be||(be={}));function xa(t={}){return new Yr(t)}function jd(t){return t[Symbol.asyncIterator]!=null}function qd(t){if(jd(t))return(async()=>{for await(let e of t);})();for(let e of t);}var ba=qd;function it(t,e){if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;for(let r=0;r<t.byteLength;r++)if(t[r]!==e[r])return!1;return!0}function xi(t,e){e==null&&(e=t.reduce((o,i)=>o+i.length,0));let r=Gr(e),n=0;for(let o of t)r.set(o,n),n+=o.length;return r}function W(t,e="utf8"){let r=Qr[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.decoder.decode(`${r.prefix}${t}`)}var bi={32:16777619n,64:1099511628211n,128:309485009821345068724781371n,256:374144419156711147060143317175368453031918731002211n,512:35835915874844867368919076489095108449946327955754392558399825615420669938882575126094039892345713852759n,1024:5016456510113118655434598811035278955030765345404790744303017523831112055108147451509157692220295382716162651878526895249385292291816524375083746691371804094271873160484737966720260389217684476157468082573n},Ea={32:2166136261n,64:14695981039346656037n,128:144066263297769815596495629667062367629n,256:100029257958052580907070968620625704837092796014241193945225284501741471925557n,512:9659303129496669498009435400716310466090418745672637896108374329434462657994582932197716438449813051892206539805784495328239340083876191928701583869517785n,1024:14197795064947621068722070641403218320880622795441933960878474914617582723252296732303717722150864096521202355549365628174669108571814760471015076148029755969804077320157692458563003215304957150157403644460363550505412711285966361610267868082893823963790439336411086884584107735010676915n},_a=new globalThis.TextEncoder;function Vd(t,e){let r=bi[e],n=Ea[e];for(let o=0;o<t.length;o++)n^=BigInt(t[o]),n=BigInt.asUintN(e,n*r);return n}function Hd(t,e,r){if(r.length===0)throw new Error("The `utf8Buffer` option must have a length greater than zero");let n=bi[e],o=Ea[e],i=t;for(;i.length>0;){let s=_a.encodeInto(i,r);i=i.slice(s.read);for(let a=0;a<s.written;a++)o^=BigInt(r[a]),o=BigInt.asUintN(e,o*n)}return o}function Ei(t,{size:e=32,utf8Buffer:r}={}){if(!bi[e])throw new Error("The `size` option must be one of 32, 64, 128, 256, 512, or 1024");if(typeof t=="string"){if(r)return Hd(t,e,r);t=_a.encode(t)}return Vd(t,e)}var tr={hash:t=>Number(Ei(t,{size:32})),hashV:(t,e)=>Kd(tr.hash(t,e))};function Kd(t){let e=t.toString(16);return e.length%2===1&&(e=`0${e}`),W(e,"base16")}var _i=64,_e=class{fp;h;seed;constructor(e,r,n,o=2){if(o>_i)throw new TypeError("Invalid Fingerprint Size");let i=r.hashV(e,n),s=la(o);for(let a=0;a<s.length;a++)s[a]=i[a];s.length===0&&(s[0]=7),this.fp=s,this.h=r,this.seed=n}hash(){return this.h.hash(this.fp,this.seed)}equals(e){return e?.fp instanceof Uint8Array?it(this.fp,e.fp):!1}};function st(t,e){return Math.floor(Math.random()*(e-t))+t}var at=class{contents;constructor(e){this.contents=new Array(e).fill(null)}has(e){if(!(e instanceof _e))throw new TypeError("Invalid Fingerprint");return this.contents.some(r=>e.equals(r))}add(e){if(!(e instanceof _e))throw new TypeError("Invalid Fingerprint");for(let r=0;r<this.contents.length;r++)if(this.contents[r]==null)return this.contents[r]=e,!0;return!0}swap(e){if(!(e instanceof _e))throw new TypeError("Invalid Fingerprint");let r=st(0,this.contents.length-1),n=this.contents[r];return this.contents[r]=e,n}remove(e){if(!(e instanceof _e))throw new TypeError("Invalid Fingerprint");let r=this.contents.findIndex(n=>e.equals(n));return r>-1?(this.contents[r]=null,!0):!1}};var Wd=500,rr=class{bucketSize;filterSize;fingerprintSize;buckets;count;hash;seed;constructor(e){this.filterSize=e.filterSize,this.bucketSize=e.bucketSize??4,this.fingerprintSize=e.fingerprintSize??2,this.count=0,this.buckets=[],this.hash=e.hash??tr,this.seed=e.seed??st(0,Math.pow(2,10))}add(e){typeof e=="string"&&(e=W(e));let r=new _e(e,this.hash,this.seed,this.fingerprintSize),n=this.hash.hash(e,this.seed)%this.filterSize,o=(n^r.hash())%this.filterSize;if(this.buckets[n]==null&&(this.buckets[n]=new at(this.bucketSize)),this.buckets[o]==null&&(this.buckets[o]=new at(this.bucketSize)),this.buckets[n].add(r)||this.buckets[o].add(r))return this.count++,!0;let i=[n,o],s=i[st(0,i.length-1)];this.buckets[s]==null&&(this.buckets[s]=new at(this.bucketSize));for(let a=0;a<Wd;a++){let c=this.buckets[s].swap(r);if(c!=null&&(s=(s^c.hash())%this.filterSize,this.buckets[s]==null&&(this.buckets[s]=new at(this.bucketSize)),this.buckets[s].add(c)))return this.count++,!0}return!1}has(e){typeof e=="string"&&(e=W(e));let r=new _e(e,this.hash,this.seed,this.fingerprintSize),n=this.hash.hash(e,this.seed)%this.filterSize,o=this.buckets[n]?.has(r)??!1;if(o)return o;let i=(n^r.hash())%this.filterSize;return this.buckets[i]?.has(r)??!1}remove(e){typeof e=="string"&&(e=W(e));let r=new _e(e,this.hash,this.seed,this.fingerprintSize),n=this.hash.hash(e,this.seed)%this.filterSize,o=this.buckets[n]?.remove(r)??!1;if(o)return this.count--,o;let i=(n^r.hash())%this.filterSize,s=this.buckets[i]?.remove(r)??!1;return s&&this.count--,s}get reliable(){return Math.floor(100*(this.count/this.filterSize))<=90}},Gd={1:.5,2:.84,4:.95,8:.98};function Qd(t=.001){return t>.002?2:t>1e-5?4:8}function va(t,e=.001){let r=Qd(e),n=Gd[r],o=Math.round(t/n),i=Math.min(Math.ceil(Math.log2(1/e)+Math.log2(2*r)),_i);return{filterSize:o,bucketSize:r,fingerprintSize:i}}var Xr=class{filterSize;bucketSize;fingerprintSize;scale;filterSeries;hash;seed;constructor(e){this.bucketSize=e.bucketSize??4,this.filterSize=e.filterSize??(1<<18)/this.bucketSize,this.fingerprintSize=e.fingerprintSize??2,this.scale=e.scale??2,this.hash=e.hash??tr,this.seed=e.seed??st(0,Math.pow(2,10)),this.filterSeries=[new rr({filterSize:this.filterSize,bucketSize:this.bucketSize,fingerprintSize:this.fingerprintSize,hash:this.hash,seed:this.seed})]}add(e){if(typeof e=="string"&&(e=W(e)),this.has(e))return!0;let r=this.filterSeries.find(n=>n.reliable);if(r==null){let n=this.filterSize*Math.pow(this.scale,this.filterSeries.length);r=new rr({filterSize:n,bucketSize:this.bucketSize,fingerprintSize:this.fingerprintSize,hash:this.hash,seed:this.seed}),this.filterSeries.push(r)}return r.add(e)}has(e){typeof e=="string"&&(e=W(e));for(let r=0;r<this.filterSeries.length;r++)if(this.filterSeries[r].has(e))return!0;return!1}remove(e){typeof e=="string"&&(e=W(e));for(let r=0;r<this.filterSeries.length;r++)if(this.filterSeries[r].remove(e))return!0;return!1}get count(){return this.filterSeries.reduce((e,r)=>e+r.count,0)}};function Zr(t,e=.001,r){return new Xr({...va(t,e),...r??{}})}function G(){let t={};return t.promise=new Promise((e,r)=>{t.resolve=e,t.reject=r}),t}var en=class{buffer;mask;top;btm;next;constructor(e){if(!(e>0)||(e-1&e)!==0)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(e),this.mask=e-1,this.top=0,this.btm=0,this.next=null}push(e){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=e,this.top=this.top+1&this.mask,!0)}shift(){let e=this.buffer[this.btm];if(e!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,e}isEmpty(){return this.buffer[this.btm]===void 0}},Tt=class{size;hwm;head;tail;constructor(e={}){this.hwm=e.splitLimit??16,this.head=new en(this.hwm),this.tail=this.head,this.size=0}calculateSize(e){return e?.byteLength!=null?e.byteLength:1}push(e){if(e?.value!=null&&(this.size+=this.calculateSize(e.value)),!this.head.push(e)){let r=this.head;this.head=r.next=new en(2*this.head.buffer.length),this.head.push(e)}}shift(){let e=this.tail.shift();if(e===void 0&&this.tail.next!=null){let r=this.tail.next;this.tail.next=null,this.tail=r,e=this.tail.shift()}return e?.value!=null&&(this.size-=this.calculateSize(e.value)),e}isEmpty(){return this.head.isEmpty()}};var vi=class extends Error{type;code;constructor(e,r){super(e??"The operation was aborted"),this.type="aborted",this.code=r??"ABORT_ERR"}};function tn(t={}){return Jd(r=>{let n=r.shift();if(n==null)return{done:!0};if(n.error!=null)throw n.error;return{done:n.done===!0,value:n.value}},t)}function Jd(t,e){e=e??{};let r=e.onEnd,n=new Tt,o,i,s,a=G(),c=async()=>{try{return n.isEmpty()?s?{done:!0}:await new Promise((S,$)=>{i=H=>{i=null,n.push(H);try{S(t(n))}catch(q){$(q)}return o}}):t(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=G()})}},l=S=>i!=null?i(S):(n.push(S),o),p=S=>(n=new Tt,i!=null?i({error:S}):(n.push({error:S}),o)),m=S=>{if(s)return o;if(e?.objectMode!==!0&&S?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return l({done:!1,value:S})},x=S=>s?o:(s=!0,S!=null?p(S):l({done:!0})),k=()=>(n=new Tt,x(),{done:!0}),I=S=>(x(S),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:c,return:k,throw:I,push:m,end:x,get readableLength(){return n.size},onEmpty:async S=>{let $=S?.signal;if($?.throwIfAborted(),n.isEmpty())return;let H,q;$!=null&&(H=new Promise((Q,fe)=>{q=()=>{fe(new vi)},$.addEventListener("abort",q)}));try{await Promise.race([a.promise,H])}finally{q!=null&&$!=null&&$?.removeEventListener("abort",q)}}},r==null)return o;let P=o;return o={[Symbol.asyncIterator](){return this},next(){return P.next()},throw(S){return P.throw(S),r!=null&&(r(S),r=void 0),{done:!0}},return(){return P.return(),r!=null&&(r(),r=void 0),{done:!0}},push:m,end(S){return P.end(S),r!=null&&(r(S),r=void 0),o},get readableLength(){return P.readableLength},onEmpty:S=>P.onEmpty(S)},o}var Yd=t=>{let e=t.addEventListener||t.on||t.addListener,r=t.removeEventListener||t.off||t.removeListener;if(!e||!r)throw new TypeError("Emitter is not compatible");return{addListener:e.bind(t),removeListener:r.bind(t)}};function Xd(t,e,r){let n,o=new Promise((i,s)=>{if(r={rejectionEvents:["error"],multiArgs:!1,rejectionMultiArgs:!1,resolveImmediately:!1,...r},!(r.count>=0&&(r.count===Number.POSITIVE_INFINITY||Number.isInteger(r.count))))throw new TypeError("The `count` option should be at least 0 or more");r.signal?.throwIfAborted();let a=[e].flat(),c=[],{addListener:l,removeListener:p}=Yd(t),m=async(...k)=>{let I=r.multiArgs?k:k[0];if(r.filter)try{if(!await r.filter(I))return}catch(P){n(),s(P);return}c.push(I),r.count===c.length&&(n(),i(c))},x=(...k)=>{n(),s(r.rejectionMultiArgs?k:k[0])};n=()=>{for(let k of a)p(k,m);for(let k of r.rejectionEvents)a.includes(k)||p(k,x)};for(let k of a)l(k,m);for(let k of r.rejectionEvents)a.includes(k)||l(k,x);r.signal&&r.signal.addEventListener("abort",()=>{x(r.signal.reason)},{once:!0}),r.resolveImmediately&&i(c)});if(o.cancel=n,typeof r.timeout=="number"){let i=Qt(o,{milliseconds:r.timeout});return i.cancel=()=>{n(),i.clear()},i}return o}function rn(t,e,r){typeof r=="function"&&(r={filter:r}),r={...r,count:1,resolveImmediately:!1};let n=Xd(t,e,r),o=n.then(i=>i[0]);return o.cancel=n.cancel,o}function ki(t,e){let r,n=function(){let o=function(){r=void 0,t()};clearTimeout(r),r=setTimeout(o,e)};return n.start=()=>{},n.stop=()=>{clearTimeout(r)},n}var nn=class extends Error{static name="QueueFullError";constructor(e="The queue was full"){super(e),this.name="QueueFullError"}};function Zd(t){return t.reason}async function Oe(t,e,r){if(e==null)return t;let n=r?.translateError??Zd;if(e.aborted)return t.catch(()=>{}),Promise.reject(n(e));let o;try{return await Promise.race([t,new Promise((i,s)=>{o=()=>{s(n(e))},e.addEventListener("abort",o)})])}finally{o!=null&&e.removeEventListener("abort",o)}}var on=class{deferred;signal;constructor(e){this.signal=e,this.deferred=G(),this.onAbort=this.onAbort.bind(this),this.signal?.addEventListener("abort",this.onAbort)}onAbort(){this.deferred.reject(this.signal?.reason??new xe)}cleanup(){this.signal?.removeEventListener("abort",this.onAbort)}};function eh(){return`${parseInt(String(Math.random()*1e9),10).toString()}${Date.now()}`}var sn=class{id;fn;options;recipients;status;timeline;controller;constructor(e,r){this.id=eh(),this.status="queued",this.fn=e,this.options=r,this.recipients=[],this.timeline={created:Date.now()},this.controller=new AbortController,this.controller.signal,this.onAbort=this.onAbort.bind(this)}abort(e){this.controller.abort(e)}onAbort(){this.recipients.reduce((r,n)=>r&&n.signal?.aborted===!0,!0)&&(this.controller.abort(new xe),this.cleanup())}async join(e={}){let r=new on(e.signal);return this.recipients.push(r),e.signal?.addEventListener("abort",this.onAbort),r.deferred.promise}async run(){this.status="running",this.timeline.started=Date.now();try{this.controller.signal.throwIfAborted();let e=await Oe(this.fn({...this.options??{},signal:this.controller.signal}),this.controller.signal);this.recipients.forEach(r=>{r.deferred.resolve(e)}),this.status="complete"}catch(e){this.recipients.forEach(r=>{r.deferred.reject(e)}),this.status="errored"}finally{this.timeline.finished=Date.now(),this.cleanup()}}cleanup(){this.recipients.forEach(e=>{e.cleanup(),e.signal?.removeEventListener("abort",this.onAbort)})}};var J=class extends le{concurrency;maxSize;queue;pending;sort;paused;constructor(e={}){super(),this.concurrency=e.concurrency??Number.POSITIVE_INFINITY,this.maxSize=e.maxSize??Number.POSITIVE_INFINITY,this.pending=0,this.paused=!1,e.metricName!=null&&e.metrics?.registerMetricGroup(e.metricName,{calculate:()=>({size:this.queue.length,running:this.pending,queued:this.queue.length-this.pending})}),this.sort=e.sort,this.queue=[],this.emitEmpty=ki(this.emitEmpty.bind(this),1),this.emitIdle=ki(this.emitIdle.bind(this),1)}emitEmpty(){this.size===0&&this.safeDispatchEvent("empty")}emitIdle(){this.running===0&&this.safeDispatchEvent("idle")}pause(){this.paused=!0}resume(){this.paused&&(this.paused=!1,this.tryToStartAnother())}tryToStartAnother(){if(this.paused)return!1;if(this.size===0)return this.emitEmpty(),this.running===0&&this.emitIdle(),!1;if(this.pending<this.concurrency){let e;for(let r of this.queue)if(r.status==="queued"){e=r;break}return e==null?!1:(this.safeDispatchEvent("active"),this.pending++,e.run().finally(()=>{for(let r=0;r<this.queue.length;r++)if(this.queue[r]===e){this.queue.splice(r,1);break}this.pending--,this.tryToStartAnother(),this.safeDispatchEvent("next")}),!0)}return!1}enqueue(e){this.queue.push(e),this.sort!=null&&this.queue.sort(this.sort)}async add(e,r){if(r?.signal?.throwIfAborted(),this.size===this.maxSize)throw new nn;let n=new sn(e,r);return this.enqueue(n),this.safeDispatchEvent("add"),this.tryToStartAnother(),n.join(r).then(o=>(this.safeDispatchEvent("completed",{detail:o}),this.safeDispatchEvent("success",{detail:{job:n,result:o}}),o)).catch(o=>{if(n.status==="queued"){for(let i=0;i<this.queue.length;i++)if(this.queue[i]===n){this.queue.splice(i,1);break}}throw this.safeDispatchEvent("failure",{detail:{job:n,error:o}}),o})}clear(){this.queue.splice(0,this.queue.length)}abort(){this.queue.forEach(e=>{e.abort(new xe)}),this.clear()}async onEmpty(e){this.size!==0&&await rn(this,"empty",e)}async onSizeLessThan(e,r){this.size<e||await rn(this,"next",{...r,filter:()=>this.size<e})}async onIdle(e){this.pending===0&&this.size===0||await rn(this,"idle",e)}get size(){return this.queue.length}get queued(){return this.queue.length-this.pending}get running(){return this.pending}async*toGenerator(e){e?.signal?.throwIfAborted();let r=tn({objectMode:!0}),n=c=>{c!=null?this.abort():this.clear(),r.end(c)},o=c=>{c.detail!=null&&r.push(c.detail)},i=c=>{n(c.detail.error)},s=()=>{n()},a=()=>{n(new xe("Queue aborted"))};this.addEventListener("completed",o),this.addEventListener("failure",i),this.addEventListener("idle",s),e?.signal?.addEventListener("abort",a);try{yield*r}finally{this.removeEventListener("completed",o),this.removeEventListener("failure",i),this.removeEventListener("idle",s),e?.signal?.removeEventListener("abort",a),n()}}};function ve(t){let e=new globalThis.AbortController;function r(){let i=t.filter(s=>s?.aborted===!0).map(s=>s?.reason).pop();e.abort(i);for(let s of t)s?.removeEventListener!=null&&s.removeEventListener("abort",r)}for(let i of t){if(i?.aborted===!0){r();break}i?.addEventListener!=null&&i.addEventListener("abort",r)}function n(){for(let i of t)i?.removeEventListener!=null&&i.removeEventListener("abort",r)}let o=e.signal;return o.clear=n,o}var Ai=class{readNext;haveNext;ended;nextResult;error;constructor(){this.ended=!1,this.readNext=G(),this.haveNext=G()}[Symbol.asyncIterator](){return this}async next(){if(this.nextResult==null&&await this.haveNext.promise,this.nextResult==null)throw new Error("HaveNext promise resolved but nextResult was undefined");let e=this.nextResult;return this.nextResult=void 0,this.readNext.resolve(),this.readNext=G(),e}async throw(e){return this.ended=!0,this.error=e,e!=null&&(this.haveNext.promise.catch(()=>{}),this.haveNext.reject(e)),{done:!0,value:void 0}}async return(){let e={done:!0,value:void 0};return this.ended=!0,this.nextResult=e,this.haveNext.resolve(),e}async push(e,r){await this._push(e,r)}async end(e,r){e!=null?await this.throw(e):await this._push(void 0,r)}async _push(e,r){if(e!=null&&this.ended)throw this.error??new Error("Cannot push value onto an ended pushable");for(;this.nextResult!=null;)await this.readNext.promise;e!=null?this.nextResult={done:!1,value:e}:(this.ended=!0,this.nextResult={done:!0,value:void 0}),this.haveNext.resolve(),this.haveNext=G(),await Oe(this.readNext.promise,r?.signal,r)}};function ka(){return new Ai}function th(t){return t[Symbol.asyncIterator]!=null}async function rh(t,e,r){try{await Promise.all(t.map(async n=>{for await(let o of n)await e.push(o,{signal:r}),r.throwIfAborted()})),await e.end(void 0,{signal:r})}catch(n){await e.end(n,{signal:r}).catch(()=>{})}}async function*nh(t){let e=new AbortController,r=ka();rh(t,r,e.signal).catch(()=>{});try{yield*r}finally{e.abort()}}function*oh(t){for(let e of t)yield*e}function ih(...t){let e=[];for(let r of t)th(r)||e.push(r);return e.length===t.length?oh(e):nh(t)}var an=ih;var sh=["Object","RegExp","Date","Error","Map","Set","WeakMap","WeakSet","ArrayBuffer","SharedArrayBuffer","DataView","Promise","URL","HTMLElement","Int8Array","Uint8ClampedArray","Int16Array","Uint16Array","Int32Array","Uint32Array","Float32Array","Float64Array","BigInt64Array","BigUint64Array"];function Ti(t){if(t===null)return"null";if(t===void 0)return"undefined";if(t===!0||t===!1)return"boolean";let e=typeof t;if(e==="string"||e==="number"||e==="bigint"||e==="symbol")return e;if(e==="function")return"Function";if(Array.isArray(t))return"Array";if(t instanceof Uint8Array)return"Uint8Array";if(t.constructor===Object)return"Object";let r=ah(t);return r||"Object"}function ah(t){let e=Object.prototype.toString.call(t).slice(8,-1);if(sh.includes(e))return e}var d=class{constructor(e,r,n){this.major=e,this.majorEncoded=e<<5,this.name=r,this.terminal=n}toString(){return`Type[${this.major}].${this.name}`}compare(e){return this.major<e.major?-1:this.major>e.major?1:0}static equals(e,r){return e===r||e.major===r.major&&e.name===r.name}};d.uint=new d(0,"uint",!0);d.negint=new d(1,"negint",!0);d.bytes=new d(2,"bytes",!0);d.string=new d(3,"string",!0);d.array=new d(4,"array",!1);d.map=new d(5,"map",!1);d.tag=new d(6,"tag",!1);d.float=new d(7,"float",!0);d.false=new d(7,"false",!0);d.true=new d(7,"true",!0);d.null=new d(7,"null",!0);d.undefined=new d(7,"undefined",!0);d.break=new d(7,"break",!0);var _=class{constructor(e,r,n){this.type=e,this.value=r,this.encodedLength=n,this.encodedBytes=void 0,this.byteValue=void 0}toString(){return`Token[${this.type}].${this.value}`}};var nr=globalThis.process&&!globalThis.process.browser&&globalThis.Buffer&&typeof globalThis.Buffer.isBuffer=="function",ch=new TextEncoder;function cn(t){return nr&&globalThis.Buffer.isBuffer(t)}function or(t){return t instanceof Uint8Array?cn(t)?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):t:Uint8Array.from(t)}var uh=24,fh=200,un=nr?t=>t.length>=uh?globalThis.Buffer.from(t):Aa(t):t=>t.length>=fh?ch.encode(t):Aa(t),Le=t=>Uint8Array.from(t),Ta=nr?(t,e,r)=>cn(t)?new Uint8Array(t.subarray(e,r)):t.slice(e,r):(t,e,r)=>t.slice(e,r),Ia=nr?(t,e)=>(t=t.map(r=>r instanceof Uint8Array?r:globalThis.Buffer.from(r)),or(globalThis.Buffer.concat(t,e))):(t,e)=>{let r=new Uint8Array(e),n=0;for(let o of t)n+o.length>r.length&&(o=o.subarray(0,r.length-n)),r.set(o,n),n+=o.length;return r},Sa=nr?t=>globalThis.Buffer.allocUnsafe(t):t=>new Uint8Array(t);function fn(t,e){if(cn(t)&&cn(e))return t.compare(e);for(let r=0;r<t.length;r++)if(t[r]!==e[r])return t[r]<e[r]?-1:1;return 0}function Aa(t){let e=[],r=0;for(let n=0;n<t.length;n++){let o=t.charCodeAt(n);o<128?e[r++]=o:o<2048?(e[r++]=o>>6|192,e[r++]=o&63|128):(o&64512)===55296&&n+1<t.length&&(t.charCodeAt(n+1)&64512)===56320?(o=65536+((o&1023)<<10)+(t.charCodeAt(++n)&1023),e[r++]=o>>18|240,e[r++]=o>>12&63|128,e[r++]=o>>6&63|128,e[r++]=o&63|128):(o>=55296&&o<=57343&&(o=65533),e[r++]=o>>12|224,e[r++]=o>>6&63|128,e[r++]=o&63|128)}return e}var lh=256,ir=class{constructor(e=lh){this.chunkSize=e,this.cursor=0,this.maxCursor=-1,this.chunks=[],this._initReuseChunk=null}reset(){this.cursor=0,this.maxCursor=-1,this.chunks.length&&(this.chunks=[]),this._initReuseChunk!==null&&(this.chunks.push(this._initReuseChunk),this.maxCursor=this._initReuseChunk.length-1)}push(e){let r=this.chunks[this.chunks.length-1];if(this.cursor+e.length<=this.maxCursor+1){let o=r.length-(this.maxCursor-this.cursor)-1;r.set(e,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)}e.length<64&&e.length<this.chunkSize?(r=Sa(this.chunkSize),this.chunks.push(r),this.maxCursor+=r.length,this._initReuseChunk===null&&(this._initReuseChunk=r),r.set(e,0)):(this.chunks.push(e),this.maxCursor+=e.length)}this.cursor+=e.length}toBytes(e=!1){let r;if(this.chunks.length===1){let n=this.chunks[0];e&&this.cursor>n.length/2?(r=this.cursor===n.length?n:n.subarray(0,this.cursor),this._initReuseChunk=null,this.chunks=[]):r=Ta(n,0,this.cursor)}else r=Ia(this.chunks,this.cursor);return e&&this.reset(),r}},ln=class{constructor(e){this.dest=e,this.cursor=0,this.chunks=[e]}reset(){this.cursor=0}push(e){if(this.cursor+e.length>this.dest.length)throw new Error("write out of bounds, destination buffer is too small");this.dest.set(e,this.cursor),this.cursor+=e.length}toBytes(e=!1){let r=this.dest.subarray(0,this.cursor);return e&&this.reset(),r}};var T="CBOR decode error:",dn="CBOR encode error:",sr=[];sr[23]=1;sr[24]=2;sr[25]=3;sr[26]=5;sr[27]=9;function Fe(t,e,r){if(t.length-e<r)throw new Error(`${T} not enough data for type`)}var O=[24,256,65536,4294967296,BigInt("18446744073709551616")];function Y(t,e,r){Fe(t,e,1);let n=t[e];if(r.strict===!0&&n<O[0])throw new Error(`${T} integer encoded in more bytes than necessary (strict decode)`);return n}function X(t,e,r){Fe(t,e,2);let n=t[e]<<8|t[e+1];if(r.strict===!0&&n<O[1])throw new Error(`${T} integer encoded in more bytes than necessary (strict decode)`);return n}function Z(t,e,r){Fe(t,e,4);let n=t[e]*16777216+(t[e+1]<<16)+(t[e+2]<<8)+t[e+3];if(r.strict===!0&&n<O[2])throw new Error(`${T} integer encoded in more bytes than necessary (strict decode)`);return n}function ee(t,e,r){Fe(t,e,8);let n=t[e]*16777216+(t[e+1]<<16)+(t[e+2]<<8)+t[e+3],o=t[e+4]*16777216+(t[e+5]<<16)+(t[e+6]<<8)+t[e+7],i=(BigInt(n)<<BigInt(32))+BigInt(o);if(r.strict===!0&&i<O[3])throw new Error(`${T} integer encoded in more bytes than necessary (strict decode)`);if(i<=Number.MAX_SAFE_INTEGER)return Number(i);if(r.allowBigInt===!0)return i;throw new Error(`${T} integers outside of the safe integer range are not supported`)}function Ua(t,e,r,n){return new _(d.uint,Y(t,e+1,n),2)}function Na(t,e,r,n){return new _(d.uint,X(t,e+1,n),3)}function Ca(t,e,r,n){return new _(d.uint,Z(t,e+1,n),5)}function La(t,e,r,n){return new _(d.uint,ee(t,e+1,n),9)}function de(t,e){return B(t,0,e.value)}function B(t,e,r){if(r<O[0]){let n=Number(r);t.push([e|n])}else if(r<O[1]){let n=Number(r);t.push([e|24,n])}else if(r<O[2]){let n=Number(r);t.push([e|25,n>>>8,n&255])}else if(r<O[3]){let n=Number(r);t.push([e|26,n>>>24&255,n>>>16&255,n>>>8&255,n&255])}else{let n=BigInt(r);if(n<O[4]){let o=[e|27,0,0,0,0,0,0,0],i=Number(n&BigInt(4294967295)),s=Number(n>>BigInt(32)&BigInt(4294967295));o[8]=i&255,i=i>>8,o[7]=i&255,i=i>>8,o[6]=i&255,i=i>>8,o[5]=i&255,o[4]=s&255,s=s>>8,o[3]=s&255,s=s>>8,o[2]=s&255,s=s>>8,o[1]=s&255,t.push(o)}else throw new Error(`${T} encountered BigInt larger than allowable range`)}}de.encodedSize=function(e){return B.encodedSize(e.value)};B.encodedSize=function(e){return e<O[0]?1:e<O[1]?2:e<O[2]?3:e<O[3]?5:9};de.compareTokens=function(e,r){return e.value<r.value?-1:e.value>r.value?1:0};function Ba(t,e,r,n){return new _(d.negint,-1-Y(t,e+1,n),2)}function Ra(t,e,r,n){return new _(d.negint,-1-X(t,e+1,n),3)}function Pa(t,e,r,n){return new _(d.negint,-1-Z(t,e+1,n),5)}var Ii=BigInt(-1),Da=BigInt(1);function $a(t,e,r,n){let o=ee(t,e+1,n);if(typeof o!="bigint"){let i=-1-o;if(i>=Number.MIN_SAFE_INTEGER)return new _(d.negint,i,9)}if(n.allowBigInt!==!0)throw new Error(`${T} integers outside of the safe integer range are not supported`);return new _(d.negint,Ii-BigInt(o),9)}function hn(t,e){let r=e.value,n=typeof r=="bigint"?r*Ii-Da:r*-1-1;B(t,e.type.majorEncoded,n)}hn.encodedSize=function(e){let r=e.value,n=typeof r=="bigint"?r*Ii-Da:r*-1-1;return n<O[0]?1:n<O[1]?2:n<O[2]?3:n<O[3]?5:9};hn.compareTokens=function(e,r){return e.value<r.value?1:e.value>r.value?-1:0};function ar(t,e,r,n){Fe(t,e,r+n);let o=t.slice(e+r,e+r+n);return new _(d.bytes,o,r+n)}function Ma(t,e,r,n){return ar(t,e,1,r)}function Oa(t,e,r,n){return ar(t,e,2,Y(t,e+1,n))}function Fa(t,e,r,n){return ar(t,e,3,X(t,e+1,n))}function za(t,e,r,n){return ar(t,e,5,Z(t,e+1,n))}function ja(t,e,r,n){let o=ee(t,e+1,n);if(typeof o=="bigint")throw new Error(`${T} 64-bit integer bytes lengths not supported`);return ar(t,e,9,o)}function pn(t){return t.encodedBytes===void 0&&(t.encodedBytes=d.equals(t.type,d.string)?un(t.value):t.value),t.encodedBytes}function It(t,e){let r=pn(e);B(t,e.type.majorEncoded,r.length),t.push(r)}It.encodedSize=function(e){let r=pn(e);return B.encodedSize(r.length)+r.length};It.compareTokens=function(e,r){return hh(pn(e),pn(r))};function hh(t,e){return t.length<e.length?-1:t.length>e.length?1:fn(t,e)}var qa=new TextDecoder,mh=32;function gh(t,e,r){if(r-e<mh){let o="";for(let i=e;i<r;i++){let s=t[i];if(s&128)return qa.decode(t.subarray(e,r));o+=String.fromCharCode(s)}return o}return qa.decode(t.subarray(e,r))}function cr(t,e,r,n,o){let i=r+n;Fe(t,e,i);let s=new _(d.string,gh(t,e+r,e+i),i);return o.retainStringBytes===!0&&(s.byteValue=t.slice(e+r,e+i)),s}function Va(t,e,r,n){return cr(t,e,1,r,n)}function Ha(t,e,r,n){return cr(t,e,2,Y(t,e+1,n),n)}function Ka(t,e,r,n){return cr(t,e,3,X(t,e+1,n),n)}function Wa(t,e,r,n){return cr(t,e,5,Z(t,e+1,n),n)}function Ga(t,e,r,n){let o=ee(t,e+1,n);if(typeof o=="bigint")throw new Error(`${T} 64-bit integer string lengths not supported`);return cr(t,e,9,o,n)}var Qa=It;function St(t,e,r,n){return new _(d.array,n,r)}function Ja(t,e,r,n){return St(t,e,1,r)}function Ya(t,e,r,n){return St(t,e,2,Y(t,e+1,n))}function Xa(t,e,r,n){return St(t,e,3,X(t,e+1,n))}function Za(t,e,r,n){return St(t,e,5,Z(t,e+1,n))}function ec(t,e,r,n){let o=ee(t,e+1,n);if(typeof o=="bigint")throw new Error(`${T} 64-bit integer array lengths not supported`);return St(t,e,9,o)}function tc(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${T} indefinite length items not allowed`);return St(t,e,1,1/0)}function mn(t,e){B(t,d.array.majorEncoded,e.value)}mn.compareTokens=de.compareTokens;mn.encodedSize=function(e){return B.encodedSize(e.value)};function Ut(t,e,r,n){return new _(d.map,n,r)}function rc(t,e,r,n){return Ut(t,e,1,r)}function nc(t,e,r,n){return Ut(t,e,2,Y(t,e+1,n))}function oc(t,e,r,n){return Ut(t,e,3,X(t,e+1,n))}function ic(t,e,r,n){return Ut(t,e,5,Z(t,e+1,n))}function sc(t,e,r,n){let o=ee(t,e+1,n);if(typeof o=="bigint")throw new Error(`${T} 64-bit integer map lengths not supported`);return Ut(t,e,9,o)}function ac(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${T} indefinite length items not allowed`);return Ut(t,e,1,1/0)}function gn(t,e){B(t,d.map.majorEncoded,e.value)}gn.compareTokens=de.compareTokens;gn.encodedSize=function(e){return B.encodedSize(e.value)};function cc(t,e,r,n){return new _(d.tag,r,1)}function uc(t,e,r,n){return new _(d.tag,Y(t,e+1,n),2)}function fc(t,e,r,n){return new _(d.tag,X(t,e+1,n),3)}function lc(t,e,r,n){return new _(d.tag,Z(t,e+1,n),5)}function dc(t,e,r,n){return new _(d.tag,ee(t,e+1,n),9)}function yn(t,e){B(t,d.tag.majorEncoded,e.value)}yn.compareTokens=de.compareTokens;yn.encodedSize=function(e){return B.encodedSize(e.value)};var Si=20,Ui=21,Ni=22,Ci=23;function hc(t,e,r,n){if(n.allowUndefined===!1)throw new Error(`${T} undefined values are not supported`);return n.coerceUndefinedToNull===!0?new _(d.null,null,1):new _(d.undefined,void 0,1)}function pc(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${T} indefinite length items not allowed`);return new _(d.break,void 0,1)}function Li(t,e,r){if(r){if(r.allowNaN===!1&&Number.isNaN(t))throw new Error(`${T} NaN values are not supported`);if(r.allowInfinity===!1&&(t===1/0||t===-1/0))throw new Error(`${T} Infinity values are not supported`)}return new _(d.float,t,e)}function mc(t,e,r,n){return Li(Bi(t,e+1),3,n)}function gc(t,e,r,n){return Li(Ri(t,e+1),5,n)}function yc(t,e,r,n){return Li(Ec(t,e+1),9,n)}function ur(t,e,r){let n=e.value;if(n===!1)t.push([d.float.majorEncoded|Si]);else if(n===!0)t.push([d.float.majorEncoded|Ui]);else if(n===null)t.push([d.float.majorEncoded|Ni]);else if(n===void 0)t.push([d.float.majorEncoded|Ci]);else{let o,i=!1;(!r||r.float64!==!0)&&(xc(n),o=Bi(ke,1),n===o||Number.isNaN(n)?(ke[0]=249,t.push(ke.slice(0,3)),i=!0):(bc(n),o=Ri(ke,1),n===o&&(ke[0]=250,t.push(ke.slice(0,5)),i=!0))),i||(Eh(n),o=Ec(ke,1),ke[0]=251,t.push(ke.slice(0,9)))}}ur.encodedSize=function(e,r){let n=e.value;if(n===!1||n===!0||n===null||n===void 0)return 1;if(!r||r.float64!==!0){xc(n);let o=Bi(ke,1);if(n===o||Number.isNaN(n))return 3;if(bc(n),o=Ri(ke,1),n===o)return 5}return 9};var wc=new ArrayBuffer(9),he=new DataView(wc,1),ke=new Uint8Array(wc,0);function xc(t){if(t===1/0)he.setUint16(0,31744,!1);else if(t===-1/0)he.setUint16(0,64512,!1);else if(Number.isNaN(t))he.setUint16(0,32256,!1);else{he.setFloat32(0,t);let e=he.getUint32(0),r=(e&2139095040)>>23,n=e&8388607;if(r===255)he.setUint16(0,31744,!1);else if(r===0)he.setUint16(0,(t&2147483648)>>16|n>>13,!1);else{let o=r-127;o<-24?he.setUint16(0,0):o<-14?he.setUint16(0,(e&2147483648)>>16|1<<24+o,!1):he.setUint16(0,(e&2147483648)>>16|o+15<<10|n>>13,!1)}}}function Bi(t,e){if(t.length-e<2)throw new Error(`${T} not enough data for float16`);let r=(t[e]<<8)+t[e+1];if(r===31744)return 1/0;if(r===64512)return-1/0;if(r===32256)return NaN;let n=r>>10&31,o=r&1023,i;return n===0?i=o*2**-24:n!==31?i=(o+1024)*2**(n-25):i=o===0?1/0:NaN,r&32768?-i:i}function bc(t){he.setFloat32(0,t,!1)}function Ri(t,e){if(t.length-e<4)throw new Error(`${T} not enough data for float32`);let r=(t.byteOffset||0)+e;return new DataView(t.buffer,r,4).getFloat32(0,!1)}function Eh(t){he.setFloat64(0,t,!1)}function Ec(t,e){if(t.length-e<8)throw new Error(`${T} not enough data for float64`);let r=(t.byteOffset||0)+e;return new DataView(t.buffer,r,8).getFloat64(0,!1)}ur.compareTokens=de.compareTokens;function U(t,e,r){throw new Error(`${T} encountered invalid minor (${r}) for major ${t[e]>>>5}`)}function wn(t){return()=>{throw new Error(`${T} ${t}`)}}var g=[];for(let t=0;t<=23;t++)g[t]=U;g[24]=Ua;g[25]=Na;g[26]=Ca;g[27]=La;g[28]=U;g[29]=U;g[30]=U;g[31]=U;for(let t=32;t<=55;t++)g[t]=U;g[56]=Ba;g[57]=Ra;g[58]=Pa;g[59]=$a;g[60]=U;g[61]=U;g[62]=U;g[63]=U;for(let t=64;t<=87;t++)g[t]=Ma;g[88]=Oa;g[89]=Fa;g[90]=za;g[91]=ja;g[92]=U;g[93]=U;g[94]=U;g[95]=wn("indefinite length bytes/strings are not supported");for(let t=96;t<=119;t++)g[t]=Va;g[120]=Ha;g[121]=Ka;g[122]=Wa;g[123]=Ga;g[124]=U;g[125]=U;g[126]=U;g[127]=wn("indefinite length bytes/strings are not supported");for(let t=128;t<=151;t++)g[t]=Ja;g[152]=Ya;g[153]=Xa;g[154]=Za;g[155]=ec;g[156]=U;g[157]=U;g[158]=U;g[159]=tc;for(let t=160;t<=183;t++)g[t]=rc;g[184]=nc;g[185]=oc;g[186]=ic;g[187]=sc;g[188]=U;g[189]=U;g[190]=U;g[191]=ac;for(let t=192;t<=215;t++)g[t]=cc;g[216]=uc;g[217]=fc;g[218]=lc;g[219]=dc;g[220]=U;g[221]=U;g[222]=U;g[223]=U;for(let t=224;t<=243;t++)g[t]=wn("simple values are not supported");g[244]=U;g[245]=U;g[246]=U;g[247]=hc;g[248]=wn("simple values are not supported");g[249]=mc;g[250]=gc;g[251]=yc;g[252]=U;g[253]=U;g[254]=U;g[255]=pc;var Ae=[];for(let t=0;t<24;t++)Ae[t]=new _(d.uint,t,1);for(let t=-1;t>=-24;t--)Ae[31-t]=new _(d.negint,t,1);Ae[64]=new _(d.bytes,new Uint8Array(0),1);Ae[96]=new _(d.string,"",1);Ae[128]=new _(d.array,0,1);Ae[160]=new _(d.map,0,1);Ae[244]=new _(d.false,!1,1);Ae[245]=new _(d.true,!0,1);Ae[246]=new _(d.null,null,1);function Pi(t){switch(t.type){case d.false:return Le([244]);case d.true:return Le([245]);case d.null:return Le([246]);case d.bytes:return t.value.length?void 0:Le([64]);case d.string:return t.value===""?Le([96]):void 0;case d.array:return t.value===0?Le([128]):void 0;case d.map:return t.value===0?Le([160]):void 0;case d.uint:return t.value<24?Le([Number(t.value)]):void 0;case d.negint:if(t.value>=-24)return Le([31-Number(t.value)])}}var vh={float64:!1,mapSorter:Th,quickEncodeToken:Pi},Tc=Object.freeze({float64:!0,mapSorter:Ih,quickEncodeToken:Pi});function kh(){let t=[];return t[d.uint.major]=de,t[d.negint.major]=hn,t[d.bytes.major]=It,t[d.string.major]=Qa,t[d.array.major]=mn,t[d.map.major]=gn,t[d.tag.major]=yn,t[d.float.major]=ur,t}var Nt=kh(),xn=new ir,lr=class t{constructor(e,r){this.obj=e,this.parent=r}includes(e){let r=this;do if(r.obj===e)return!0;while(r=r.parent);return!1}static createCheck(e,r){if(e&&e.includes(r))throw new Error(`${dn} object contains circular references`);return new t(r,e)}},Ye={null:new _(d.null,null),undefined:new _(d.undefined,void 0),true:new _(d.true,!0),false:new _(d.false,!1),emptyArray:new _(d.array,0),emptyMap:new _(d.map,0)},Be={number(t,e,r,n){return!Number.isInteger(t)||!Number.isSafeInteger(t)?new _(d.float,t):t>=0?new _(d.uint,t):new _(d.negint,t)},bigint(t,e,r,n){return t>=BigInt(0)?new _(d.uint,t):new _(d.negint,t)},Uint8Array(t,e,r,n){return new _(d.bytes,t)},string(t,e,r,n){return new _(d.string,t)},boolean(t,e,r,n){return t?Ye.true:Ye.false},null(t,e,r,n){return Ye.null},undefined(t,e,r,n){return Ye.undefined},ArrayBuffer(t,e,r,n){return new _(d.bytes,new Uint8Array(t))},DataView(t,e,r,n){return new _(d.bytes,new Uint8Array(t.buffer,t.byteOffset,t.byteLength))},Array(t,e,r,n){if(!t.length)return r.addBreakTokens===!0?[Ye.emptyArray,new _(d.break)]:Ye.emptyArray;n=lr.createCheck(n,t);let o=[],i=0;for(let s of t)o[i++]=bn(s,r,n);return r.addBreakTokens?[new _(d.array,t.length),o,new _(d.break)]:[new _(d.array,t.length),o]},Object(t,e,r,n){let o=e!=="Object",i=o?t.keys():Object.keys(t),s=o?t.size:i.length,a;if(s){a=new Array(s),n=lr.createCheck(n,t);let c=!o&&r.ignoreUndefinedProperties,l=0;for(let p of i){let m=o?t.get(p):t[p];c&&m===void 0||(a[l++]=[bn(p,r,n),bn(m,r,n)])}l<s&&(a.length=l)}return a?.length?(Ah(a,r),r.addBreakTokens?[new _(d.map,a.length),a,new _(d.break)]:[new _(d.map,a.length),a]):r.addBreakTokens===!0?[Ye.emptyMap,new _(d.break)]:Ye.emptyMap}};Be.Map=Be.Object;Be.Buffer=Be.Uint8Array;for(let t of"Uint8Clamped Uint16 Uint32 Int8 Int16 Int32 BigUint64 BigInt64 Float32 Float64".split(" "))Be[`${t}Array`]=Be.DataView;function bn(t,e={},r){let n=Ti(t),o=e&&e.typeEncoders&&e.typeEncoders[n]||Be[n];if(typeof o=="function"){let s=o(t,n,e,r);if(s!=null)return s}let i=Be[n];if(!i)throw new Error(`${dn} unsupported type: ${n}`);return i(t,n,e,r)}function Ah(t,e){e.mapSorter&&t.sort(e.mapSorter)}function Th(t,e){let r=Array.isArray(t[0])?t[0][0]:t[0],n=Array.isArray(e[0])?e[0][0]:e[0];if(r.type!==n.type)return r.type.compare(n.type);let o=r.type.major,i=Nt[o].compareTokens(r,n);return i===0&&console.warn("WARNING: complex key types used, CBOR key sorting guarantees are gone"),i}function Ih(t,e){if(t[0]instanceof _&&e[0]instanceof _){let r=t[0],n=e[0];return r._keyBytes||(r._keyBytes=_c(r.value)),n._keyBytes||(n._keyBytes=_c(n.value)),fn(r._keyBytes,n._keyBytes)}throw new Error("rfc8949MapSorter: complex key types are not supported yet")}function _c(t){return Sc(t,Nt,Tc)}function fr(t,e,r,n){if(Array.isArray(e))for(let o of e)fr(t,o,r,n);else r[e.type.major](t,e,n)}var vc=d.uint.majorEncoded,kc=d.negint.majorEncoded,Sh=d.bytes.majorEncoded,Uh=d.string.majorEncoded,Ac=d.array.majorEncoded,Nh=d.float.majorEncoded|Si,Ch=d.float.majorEncoded|Ui,Lh=d.float.majorEncoded|Ni,Bh=d.float.majorEncoded|Ci,Rh=BigInt(-1),Ph=BigInt(1);function Dh(t){return t.addBreakTokens!==!0}function Ic(t,e,r,n){let o=Ti(e),i=r.typeEncoders&&r.typeEncoders[o];if(i){let s=i(e,o,r,n);if(s!=null){fr(t,s,Nt,r);return}}switch(o){case"null":t.push([Lh]);return;case"undefined":t.push([Bh]);return;case"boolean":t.push([e?Ch:Nh]);return;case"number":!Number.isInteger(e)||!Number.isSafeInteger(e)?ur(t,new _(d.float,e),r):e>=0?B(t,vc,e):B(t,kc,e*-1-1);return;case"bigint":e>=BigInt(0)?B(t,vc,e):B(t,kc,e*Rh-Ph);return;case"string":{let s=un(e);B(t,Uh,s.length),t.push(s);return}case"Uint8Array":B(t,Sh,e.length),t.push(e);return;case"Array":if(!e.length){t.push([Ac]);return}n=lr.createCheck(n,e),B(t,Ac,e.length);for(let s of e)Ic(t,s,r,n);return;case"Object":case"Map":{let s=Be.Object(e,o,r,n);fr(t,s,Nt,r)}return;default:{let s=Be[o];if(!s)throw new Error(`${dn} unsupported type: ${o}`);let a=s(e,o,r,n);fr(t,a,Nt,r)}}}function Sc(t,e,r,n){let o=n instanceof Uint8Array,i=o?new ln(n):xn,s=bn(t,r);if(!Array.isArray(s)&&r.quickEncodeToken){let a=r.quickEncodeToken(s);if(a)return o?(i.push(a),i.toBytes()):a;let c=e[s.type.major];if(c.encodedSize){let l=c.encodedSize(s,r);if(o||(i=new ir(l)),c(i,s,r),i.chunks.length!==1)throw new Error(`Unexpected error: pre-calculated length for ${s} was wrong`);return o?i.toBytes():or(i.chunks[0])}}return i.reset(),fr(i,s,e,r),i.toBytes(!0)}function dr(t,e){return e=Object.assign({},vh,e),Dh(e)?(xn.reset(),Ic(xn,t,e,void 0),xn.toBytes(!0)):Sc(t,Nt,e)}var $h={strict:!1,allowIndefinite:!0,allowUndefined:!0,allowBigInt:!0},En=class{constructor(e,r={}){this._pos=0,this.data=e,this.options=r}pos(){return this._pos}done(){return this._pos>=this.data.length}next(){let e=this.data[this._pos],r=Ae[e];if(r===void 0){let n=g[e];if(!n)throw new Error(`${T} no decoder for major type ${e>>>5} (byte 0x${e.toString(16).padStart(2,"0")})`);let o=e&31;r=n(this.data,this._pos,o,this.options)}return this._pos+=r.encodedLength,r}},hr=Symbol.for("DONE"),_n=Symbol.for("BREAK");function Mh(t,e,r){let n=[];for(let o=0;o<t.value;o++){let i=Ct(e,r);if(i===_n){if(t.value===1/0)break;throw new Error(`${T} got unexpected break to lengthed array`)}if(i===hr)throw new Error(`${T} found array but not enough entries (got ${o}, expected ${t.value})`);n[o]=i}return n}function Oh(t,e,r){let n=r.useMaps===!0,o=r.rejectDuplicateMapKeys===!0,i=n?void 0:{},s=n?new Map:void 0;for(let a=0;a<t.value;a++){let c=Ct(e,r);if(c===_n){if(t.value===1/0)break;throw new Error(`${T} got unexpected break to lengthed map`)}if(c===hr)throw new Error(`${T} found map but not enough entries (got ${a} [no key], expected ${t.value})`);if(!n&&typeof c!="string")throw new Error(`${T} non-string keys not supported (got ${typeof c})`);if(o&&(n&&s.has(c)||!n&&Object.hasOwn(i,c)))throw new Error(`${T} found repeat map key "${c}"`);let l=Ct(e,r);if(l===hr)throw new Error(`${T} found map but not enough entries (got ${a} [no value], expected ${t.value})`);n?s.set(c,l):i[c]=l}return n?s:i}function Ct(t,e){if(t.done())return hr;let r=t.next();if(d.equals(r.type,d.break))return _n;if(r.type.terminal)return r.value;if(d.equals(r.type,d.array))return Mh(r,t,e);if(d.equals(r.type,d.map))return Oh(r,t,e);if(d.equals(r.type,d.tag)){if(e.tags&&typeof e.tags[r.value]=="function"){let n=Ct(t,e);return e.tags[r.value](n)}throw new Error(`${T} tag not supported (${r.value})`)}throw new Error("unsupported")}function Uc(t,e){if(!(t instanceof Uint8Array))throw new Error(`${T} data to decode must be a Uint8Array`);e=Object.assign({},$h,e);let r=or(t),n=e.tokenizer||new En(r,e),o=Ct(n,e);if(o===hr)throw new Error(`${T} did not find any content to decode`);if(o===_n)throw new Error(`${T} got unexpected break`);return[o,t.subarray(n.pos())]}function ut(t,e){let[r,n]=Uc(t,e);if(n.length>0)throw new Error(`${T} too many terminals, data makes no sense`);return r}var vn=class extends J{has(e){return this.find(e)!=null}find(e){return this.queue.find(r=>e.equals(r.options.peerId))}};var ze="/",Nc=new TextEncoder().encode(ze),kn=Nc[0],je=class t{_buf;constructor(e,r){if(typeof e=="string")this._buf=W(e);else if(e instanceof Uint8Array)this._buf=e;else throw new Error("Invalid key, should be String of Uint8Array");if(r==null&&(r=!0),r&&this.clean(),this._buf.byteLength===0||this._buf[0]!==kn)throw new Error("Invalid key")}toString(e="utf8"){return Je(this._buf,e)}uint8Array(){return this._buf}get[Symbol.toStringTag](){return`Key(${this.toString()})`}static withNamespaces(e){return new t(e.join(ze))}static random(){return new t(Math.random().toString().substring(2))}static asKey(e){return e instanceof Uint8Array||typeof e=="string"?new t(e):typeof e.uint8Array=="function"?new t(e.uint8Array()):null}clean(){if((this._buf==null||this._buf.byteLength===0)&&(this._buf=Nc),this._buf[0]!==kn){let e=new Uint8Array(this._buf.byteLength+1);e.fill(kn,0,1),e.set(this._buf,1),this._buf=e}for(;this._buf.byteLength>1&&this._buf[this._buf.byteLength-1]===kn;)this._buf=this._buf.subarray(0,-1)}less(e){let r=this.list(),n=e.list();for(let o=0;o<r.length;o++){if(n.length<o+1)return!1;let i=r[o],s=n[o];if(i<s)return!0;if(i>s)return!1}return r.length<n.length}reverse(){return t.withNamespaces(this.list().slice().reverse())}namespaces(){return this.list()}baseNamespace(){let e=this.namespaces();return e[e.length-1]}list(){return this.toString().split(ze).slice(1)}type(){return zh(this.baseNamespace())}name(){return jh(this.baseNamespace())}instance(e){return new t(this.toString()+":"+e)}path(){let e=this.parent().toString();return e.endsWith(ze)||(e+=ze),e+=this.type(),new t(e)}parent(){let e=this.list();return e.length===1?new t(ze):new t(e.slice(0,-1).join(ze))}child(e){return this.toString()===ze?e:e.toString()===ze?this:new t(this.toString()+e.toString(),!1)}isAncestorOf(e){return e.toString()===this.toString()?!1:e.toString().startsWith(this.toString())}isDecendantOf(e){return e.toString()===this.toString()?!1:this.toString().startsWith(e.toString())}isTopLevel(){return this.list().length===1}concat(...e){return t.withNamespaces([...this.namespaces(),...qh(e.map(r=>r.namespaces()))])}};function zh(t){let e=t.split(":");return e.length<2?"":e.slice(0,-1).join(":")}function jh(t){let e=t.split(":");return e[e.length-1]}function qh(t){return[].concat(...t)}function Vh(t){return t[Symbol.asyncIterator]!=null}function Hh(t){if(Vh(t))return(async()=>{let n=new Uint8Array(0);for await(let o of t)n=xi([n,o],n.length+o.length);return n})();let e=[],r=0;for(let n of t)e.push(n),r+=n.byteLength;return xi(e,r)}var An=Hh;function Tn({enumerable:t=!0,configurable:e=!1}={}){return{enumerable:t,configurable:e,writable:!1}}function*Kh(t,e){if(e!=null&&typeof e=="object")if(Array.isArray(e))for(let[r,n]of e.entries()){let o=[...t,r],i=L.asCID(n);i!=null?yield[o.join("/"),i]:typeof n=="object"&&(yield*Di(n,o))}else{let r=L.asCID(e);r!=null?yield[t.join("/"),r]:yield*Di(e,t)}}function*Di(t,e){if(t==null||t instanceof Uint8Array)return;let r=L.asCID(t);r!=null&&(yield[e.join("/"),r]);for(let[n,o]of Object.entries(t)){let i=[...e,n];yield*Kh(i,o)}}function*Wh(t,e){if(Array.isArray(e))for(let[r,n]of e.entries()){let o=[...t,r];yield o.join("/"),typeof n=="object"&&L.asCID(n)==null&&(yield*$i(n,o))}else yield*$i(e,t)}function*$i(t,e){if(!(t==null||typeof t!="object"))for(let[r,n]of Object.entries(t)){let o=[...e,r];yield o.join("/"),n!=null&&!(n instanceof Uint8Array)&&typeof n=="object"&&L.asCID(n)==null&&(yield*Wh(o,n))}}function Gh(t,e){let r=t;for(let[n,o]of e.entries()){if(r=r[o],r==null)throw new Error(`Object has no property at ${e.slice(0,n+1).map(s=>`[${JSON.stringify(s)}]`).join("")}`);let i=L.asCID(r);if(i!=null)return{value:i,remaining:e.slice(n+1).join("/")}}return{value:r}}var Mi=class{cid;bytes;value;asBlock;constructor({cid:e,bytes:r,value:n}){if(e==null||r==null||typeof n>"u")throw new Error("Missing required argument");this.cid=e,this.bytes=r,this.value=n,this.asBlock=this,Object.defineProperties(this,{cid:Tn(),bytes:Tn(),value:Tn(),asBlock:Tn()})}links(){return Di(this.value,[])}tree(){return $i(this.value,[])}get(e="/"){return Gh(this.value,e.split("/").filter(Boolean))}};function In({bytes:t,cid:e,value:r,codec:n}){let o=r!==void 0?r:n?.decode(t);if(o===void 0)throw new Error('Missing required argument, must either provide "value" or "codec"');return new Mi({cid:e,bytes:t,value:o})}var Sn=class extends Error{static name="AlreadyPinnedError";name="AlreadyPinnedError"},pr=class extends Error{static name="BlockPinnedError";name="BlockPinnedError"},Un=class extends Error{static name="InvalidDatastoreVersionError";name="InvalidDatastoreVersionError"},ft=class extends Error{static name="InvalidConfigurationError";name="InvalidConfigurationError"},Nn=class extends AggregateError{static name="GetFailedError";name="GetFailedError"},Cn=class extends AggregateError{static name="LoadBlockFailedError";name="LoadBlockFailedError"},mr=class extends Error{static name="BlockNotFoundWhileOfflineError";name="BlockNotFoundWhileOfflineError"};var Bc="/pin/",Cc="/pinned-block/",Oi=Me,Lc=1;function Ln(t){return t.version===0&&(t=t.toV1()),new je(`${Bc}${t.toString(Oi)}`)}var Bn=class{datastore;blockstore;getCodec;constructor(e,r,n){this.datastore=e,this.blockstore=r,this.getCodec=n}async*add(e,r={}){let n=Ln(e);if(await this.datastore.has(n))throw new Sn("Already pinned");let o=Math.round(r.depth??1/0);if(o<0)throw new yt("Depth must be greater than or equal to 0");let i=new J({concurrency:Lc});for await(let a of this.#e(e,i,{...r,depth:o}))await this.#o(a,c=>c.pinnedBy.find(l=>it(l,e.bytes))!=null?!1:(c.pinCount++,c.pinnedBy.push(e.bytes),!0),r),yield a;let s={depth:o,metadata:r.metadata??{}};await this.datastore.put(n,dr(s),r)}async*#e(e,r,n){if(n.depth===-1)return;let o=await this.getCodec(e.code),i=await An(this.blockstore.get(e,n)),s=In({bytes:i,cid:e,codec:o});yield e;for(let[,a]of s.links())yield*await r.add(async()=>this.#e(a,r,{...n,depth:n.depth-1}))}async#o(e,r,n){let o=new je(`${Cc}${Oi.encode(e.multihash.bytes)}`),i={pinCount:0,pinnedBy:[]};try{i=ut(await this.datastore.get(o,n))}catch(a){if(a.name!=="NotFoundError")throw a}if(r(i)){if(i.pinCount===0&&await this.datastore.has(o)){await this.datastore.delete(o);return}await this.datastore.put(o,dr(i),n),n.onProgress?.(new A("helia:pin:add",e))}}async*rm(e,r={}){let n=Ln(e),o=await this.datastore.get(n,r),i=ut(o);await this.datastore.delete(n,r);let s=new J({concurrency:Lc});for await(let a of this.#e(e,s,{...r,depth:i.depth}))await this.#o(a,c=>(c.pinCount--,c.pinnedBy=c.pinnedBy.filter(l=>it(l,e.bytes)),!0),{...r,depth:i.depth}),yield a}async*ls(e={}){for await(let{key:r,value:n}of this.datastore.query({prefix:Bc+(e.cid!=null?`${e.cid.toString(Me)}`:"")},e)){let o=L.parse(r.toString().substring(5),Me),i=ut(n);yield{cid:o,...i}}}async isPinned(e,r={}){let n=new je(`${Cc}${Oi.encode(e.multihash.bytes)}`);return this.datastore.has(n,r)}async get(e,r){let n=Ln(e),o=await this.datastore.get(n,r);return ut(o)}async setMetadata(e,r,n){let o=Ln(e),i=await this.datastore.get(o,n),s=ut(i);s.metadata=r??{},await this.datastore.put(o,dr(s),n)}};var Rn=class extends Error{static name="InsufficientProvidersError";constructor(e="Insufficient providers found"){super(e),this.name="InsufficientProvidersError"}},lt=class extends Error{static name="NoRoutersAvailableError";constructor(e="No routers available"){super(e),this.name="NoRoutersAvailableError"}},Pn=class extends Error{static name="UnknownHashAlgorithmError";constructor(e="Unknown hash algorithm"){super(e),this.name="UnknownHashAlgorithmError"}},Dn=class extends Error{static name="UnknownCodecError";constructor(e="Unknown codec"){super(e),this.name="UnknownCodecError"}};var Qh=5,$n=class{name;log;routers;providerLookupConcurrency;constructor(e,r){this.name="helia",this.log=e.logger.forComponent("helia:routing"),this.routers=r.routers??[],this.providerLookupConcurrency=r.providerLookupConcurrency??Qh,this.findProviders=e.metrics?.traceFunction("helia.routing.findProviders",this.findProviders.bind(this),{optionsIndex:1})??this.findProviders,this.provide=e.metrics?.traceFunction("helia.routing.provide",this.provide.bind(this),{optionsIndex:1})??this.provide,this.cancelReprovide=e.metrics?.traceFunction("helia.routing.cancelReprovide",this.cancelReprovide.bind(this),{optionsIndex:1})??this.cancelReprovide,this.put=e.metrics?.traceFunction("helia.routing.put",this.put.bind(this),{optionsIndex:2})??this.put,this.get=e.metrics?.traceFunction("helia.routing.get",this.get.bind(this),{optionsIndex:1})??this.get,this.findPeer=e.metrics?.traceFunction("helia.routing.findPeer",this.findPeer.bind(this),{optionsIndex:1})??this.findPeer,this.getClosestPeers=e.metrics?.traceFunction("helia.routing.getClosestPeers",this.getClosestPeers.bind(this),{optionsIndex:1})??this.getClosestPeers}async start(){await We(...this.routers)}async stop(){await Ge(...this.routers)}async*findProviders(e,r={}){if(this.routers.length===0)throw new lt("No content routers available");let n=new vn({concurrency:this.providerLookupConcurrency}),o=0,i=[],s=this,a=0;this.log("findProviders for %c start using routers %s",e,this.routers.map(l=>l.toString()).join(", "));let c=dt(this.routers,"findProviders").map(async function*(l){let p=0;r?.onProgress?.(new A("helia:routing:find-providers:start",{routing:l.name,cid:e}));try{for await(let m of l.findProviders(e,r))p++,r?.onProgress?.(new A("helia:routing:find-providers:provider",{routing:l.name,cid:e,provider:m})),yield m}catch(m){i.push(m)}finally{s.log("router %s found %d providers for %c",l,p,e),r?.onProgress?.(new A("helia:routing:find-providers:end",{routing:l.name,cid:e,found:p})),a++,a===c.length&&n.size===0&&n.emitIdle()}});for await(let l of an(n.toGenerator(),...c))if(l!=null){if(l.multiaddrs.length===0){if(n.find(l.id)!=null)continue;n.add(async()=>{try{let p=await this.findPeer(l.id,r);return p.multiaddrs.length===0?null:{...p,protocols:l.protocols,routing:l.routing}}catch(p){return this.log.error("could not load multiaddrs for peer %p - %e",l.id,p),null}},{peerId:l.id,signal:r.signal}).catch(p=>{this.log.error("could not load multiaddrs for peer %p - %e",l.id,p)});continue}o++,yield l}this.log("findProviders finished, found %d providers for %c",o,e)}async provide(e,r={}){if(this.routers.length===0)throw new lt("No content routers available");await Promise.all(dt(this.routers,"provide").map(async n=>{r?.onProgress?.(new A("helia:routing:provide:start",{routing:n.name,cid:e})),await n.provide(e,r),r?.onProgress?.(new A("helia:routing:provide:end",{routing:n.name,cid:e}))}))}async cancelReprovide(e,r={}){await Promise.all(dt(this.routers,"cancelReprovide").map(async n=>{r?.onProgress?.(new A("helia:routing:cancel-reprovide:start",{routing:n.name,cid:e})),await n.cancelReprovide(e,r),r?.onProgress?.(new A("helia:routing:cancel-reprovide:end",{routing:n.name,cid:e}))}))}async put(e,r,n){await Promise.all(dt(this.routers,"put").map(async o=>{n?.onProgress?.(new A("helia:routing:put:start",{routing:o.name,key:e,value:r})),await o.put(e,r,n),n?.onProgress?.(new A("helia:routing:put:end",{routing:o.name,key:e,value:r}))}))}async get(e,r){let n=[],o;try{o=await Promise.any(dt(this.routers,"get").map(async i=>{r?.onProgress?.(new A("helia:routing:get:start",{routing:i.name,key:e}));try{return await i.get(e,r)}catch(s){this.log("router %s failed with %e",i,s),n.push(s)}finally{r?.onProgress?.(new A("helia:routing:get:end",{routing:i.name,key:e}))}}))}catch{}if(o==null)throw new Nn(n,`Failed to get value key ${Je(e,"base58btc")}`);return o}async findPeer(e,r){if(this.routers.length===0)throw new lt("No peer routers available");let n=this,o=an(...dt(this.routers,"findPeer").map(i=>(async function*(){r?.onProgress?.(new A("helia:routing:find-peer:start",{routing:i.name,peerId:e}));try{yield await i.findPeer(e,r)}catch(s){n.log.error(s)}finally{r?.onProgress?.(new A("helia:routing:find-peer:end",{routing:i.name,peerId:e}))}})()));for await(let i of o)if(i!=null)return i;throw new $r("Could not find peer in routing")}async*getClosestPeers(e,r={}){if(this.routers.length===0)throw new lt("No peer routers available");for await(let n of an(...dt(this.routers,"getClosestPeers").map(async function*(o){r?.onProgress?.(new A("helia:routing:get-closest-peers:start",{routing:o.name,key:e}));try{yield*o.getClosestPeers(e,r)}finally{r?.onProgress?.(new A("helia:routing:get-closest-peers:end",{routing:o.name,key:e}))}})))n!=null&&(yield n)}};function dt(t,e){return t.filter(r=>r[e]!=null)}var te=class extends Error{static name="AbortError";name="AbortError";constructor(e="The operation was aborted",...r){super(e,...r)}};async function Mn(t,e,r,n){let o=new te(n?.errorMessage);n?.errorCode!=null&&(o.code=n.errorCode);let i=n?.errorEvent??"error";return r?.aborted===!0?Promise.reject(o):new Promise((s,a)=>{function c(){zi(r,"abort",m),zi(t,e,l),zi(t,i,p)}let l=x=>{try{if(n?.filter?.(x)===!1)return}catch(k){c(),a(k);return}c(),s(x)},p=x=>{if(c(),x instanceof Error){a(x);return}a(x.detail??n?.error??new Error(`The "${n?.errorEvent}" event was emitted but the event had no '.detail' field. Pass an 'error' option to race-event to change this message.`))},m=()=>{c(),a(o)};Fi(r,"abort",m),Fi(t,e,l),Fi(t,i,p)})}function Fi(t,e,r){t!=null&&(Rc(t)?t.addEventListener(e,r):t.addListener(e,r))}function zi(t,e,r){t!=null&&(Rc(t)?t.removeEventListener(e,r):t.removeListener(e,r))}function Rc(t){return typeof t.addEventListener=="function"&&typeof t.removeEventListener=="function"}var On=class extends Error{static name="QueueFullError";constructor(e="The queue was full"){super(e),this.name="QueueFullError"}};var Fn=class{deferred;signal;constructor(e){this.signal=e,this.deferred=Promise.withResolvers(),this.onAbort=this.onAbort.bind(this),this.signal?.addEventListener("abort",this.onAbort)}onAbort(){this.deferred.reject(this.signal?.reason??new te)}cleanup(){this.signal?.removeEventListener("abort",this.onAbort)}};function Jh(){return`${parseInt(String(Math.random()*1e9),10).toString()}${Date.now()}`}var zn=class{id;fn;options;recipients;status;timeline;controller;constructor(e,r){this.id=Jh(),this.status="queued",this.fn=e,this.options=r,this.recipients=[],this.timeline={created:Date.now()},this.controller=new AbortController,this.controller.signal,this.onAbort=this.onAbort.bind(this)}abort(e){this.controller.abort(e)}onAbort(){this.recipients.reduce((r,n)=>r&&n.signal?.aborted===!0,!0)&&(this.controller.abort(new te),this.cleanup())}async join(e={}){let r=new Fn(e.signal);return this.recipients.push(r),e.signal?.addEventListener("abort",this.onAbort),r.deferred.promise}async run(){this.status="running",this.timeline.started=Date.now();try{this.controller.signal.throwIfAborted();let e=await Oe(this.fn({...this.options??{},signal:this.controller.signal}),this.controller.signal);this.recipients.forEach(r=>{r.deferred.resolve(e)}),this.status="complete"}catch(e){this.recipients.forEach(r=>{r.deferred.reject(e)}),this.status="errored"}finally{this.timeline.finished=Date.now(),this.cleanup()}}cleanup(){this.recipients.forEach(e=>{e.cleanup(),e.signal?.removeEventListener("abort",this.onAbort)})}};function ji(t,e){let r,n=function(){let o=function(){r=void 0,t()};clearTimeout(r),r=setTimeout(o,e)};return n.start=()=>{},n.stop=()=>{clearTimeout(r)},n}var gr=class extends le{concurrency;maxSize;queue;pending;sort;autoStart;constructor(e={}){super(),this.concurrency=e.concurrency??Number.POSITIVE_INFINITY,this.maxSize=e.maxSize??Number.POSITIVE_INFINITY,this.pending=0,this.autoStart=e.autoStart??!0,this.sort=e.sort,this.queue=[],this.emitEmpty=ji(this.emitEmpty.bind(this),1),this.emitIdle=ji(this.emitIdle.bind(this),1)}[Symbol.asyncIterator](){return this.toGenerator()}emitEmpty(){this.size===0&&this.safeDispatchEvent("empty")}emitIdle(){this.running===0&&this.safeDispatchEvent("idle")}tryToStartAnother(){if(this.size===0)return this.emitEmpty(),this.running===0&&this.emitIdle(),!1;if(this.pending<this.concurrency){let e;for(let r of this.queue)if(r.status==="queued"){e=r;break}return e==null?!1:(this.safeDispatchEvent("active"),this.pending++,e.run().finally(()=>{for(let r=0;r<this.queue.length;r++)if(this.queue[r]===e){this.queue.splice(r,1);break}this.pending--,this.safeDispatchEvent("next"),this.autoStart&&this.tryToStartAnother()}),!0)}return!1}enqueue(e){this.queue.push(e),this.sort!=null&&this.queue.sort(this.sort)}start(){this.autoStart===!1&&(this.autoStart=!0,this.tryToStartAnother())}pause(){this.autoStart=!1}async add(e,r){if(r?.signal?.throwIfAborted(),this.size===this.maxSize)throw new On;let n=new zn(e,r);return this.enqueue(n),this.safeDispatchEvent("add"),this.autoStart&&this.tryToStartAnother(),n.join(r).then(o=>(this.safeDispatchEvent("success",{detail:{job:n,result:o}}),o)).catch(o=>{if(n.status==="queued"){for(let i=0;i<this.queue.length;i++)if(this.queue[i]===n){this.queue.splice(i,1);break}}throw this.safeDispatchEvent("failure",{detail:{job:n,error:o}}),o})}clear(){this.queue.splice(0,this.queue.length)}abort(){this.queue.forEach(e=>{e.abort(new te)}),this.clear()}async onEmpty(e){this.size!==0&&await Mn(this,"empty",e?.signal)}async onSizeLessThan(e,r){this.size<e||await Mn(this,"next",r?.signal,{filter:()=>this.size<e})}async onIdle(e){this.pending===0&&this.size===0||await Mn(this,"idle",e?.signal)}get size(){return this.queue.length}get queued(){return this.queue.length-this.pending}get running(){return this.pending}async*toGenerator(e){e?.signal?.throwIfAborted();let r=tn({objectMode:!0}),n=c=>{c!=null?this.abort():this.clear(),r.end(c)},o=c=>{c.detail!=null&&r.push(c.detail.result)},i=c=>{n(c.detail.error)},s=()=>{n()},a=()=>{n(new te("Queue aborted"))};this.addEventListener("success",o),this.addEventListener("failure",i),this.addEventListener("idle",s),e?.signal?.addEventListener("abort",a);try{yield*r}finally{this.removeEventListener("success",o),this.removeEventListener("failure",i),this.removeEventListener("idle",s),e?.signal?.removeEventListener("abort",a),n()}}};var jn="lock:worker:request-read",qn="lock:worker:abort-read-request",Vn="lock:worker:release-read",Hn="lock:master:grant-read",Kn="lock:master:error-read",Wn="lock:worker:request-write",Gn="lock:worker:abort-write-request",Qn="lock:worker:release-write",Jn="lock:master:grant-write",Yn="lock:master:error-write",Xn="lock:worker:finalize",Zn="mortice",Pc={singleProcess:!1};var qi=(t,e,r,n,o,i,s,a,c)=>l=>{if(l.data==null)return;let p={type:l.data.type,name:l.data.name,identifier:l.data.identifier};p.type===o&&t.safeDispatchEvent(r,{detail:{name:p.name,identifier:p.identifier,handler:async()=>{e.postMessage({type:c,name:p.name,identifier:p.identifier}),await new Promise(m=>{let x=k=>{if(k?.data==null)return;let I={type:k.data.type,name:k.data.name,identifier:k.data.identifier};I.type===a&&I.identifier===p.identifier&&(e.removeEventListener("message",x),m())};e.addEventListener("message",x)})},onError:m=>{e.postMessage({type:s,name:p.name,identifier:p.identifier,error:{message:m.message,name:m.name,stack:m.stack}})}}}),p.type===i&&t.safeDispatchEvent(n,{detail:{name:p.name,identifier:p.identifier}}),p.type===Xn&&t.safeDispatchEvent("finalizeRequest",{detail:{name:p.name}})};var Dc=(t=10)=>Math.random().toString().substring(2,t+2);var eo=class{name;channel;constructor(e){this.name=e,this.channel=new BroadcastChannel(Zn)}readLock(e){return this.sendRequest(jn,qn,Hn,Kn,Vn,e)}writeLock(e){return this.sendRequest(Wn,Gn,Jn,Yn,Qn,e)}finalize(){this.channel.postMessage({type:Xn,name:this.name}),this.channel.close()}async sendRequest(e,r,n,o,i,s){s?.signal?.throwIfAborted();let a=Dc();return this.channel.postMessage({type:e,identifier:a,name:this.name}),new Promise((c,l)=>{let p=()=>{this.channel.postMessage({type:r,identifier:a,name:this.name})};s?.signal?.addEventListener("abort",p,{once:!0});let m=x=>{if(x.data?.identifier===a&&(x.data?.type===n&&(this.channel.removeEventListener("message",m),s?.signal?.removeEventListener("abort",p),c(()=>{this.channel.postMessage({type:i,identifier:a,name:this.name})})),x.data.type===o)){this.channel.removeEventListener("message",m),s?.signal?.removeEventListener("abort",p);let k=new Error;x.data.error!=null&&(k.message=x.data.error.message,k.name=x.data.error.name,k.stack=x.data.error.stack),l(k)}};this.channel.addEventListener("message",m)})}};var $c=t=>{if(t=Object.assign({},Pc,t),!!globalThis.document||t.singleProcess){let r=new BroadcastChannel(Zn),n=new le;return r.addEventListener("message",qi(n,r,"requestReadLock","abortReadLockRequest",jn,qn,Kn,Vn,Hn)),r.addEventListener("message",qi(n,r,"requestWriteLock","abortWriteLockRequest",Wn,Gn,Yn,Qn,Jn)),n}return new eo(t.name)};var ht=new Map,yr;function Mc(t){return typeof t?.readLock=="function"&&typeof t?.writeLock=="function"}function Yh(t){if(yr==null&&(yr=$c(t),!Mc(yr))){let e=yr;e.addEventListener("requestReadLock",r=>{let n=r.detail.name,o=r.detail.identifier,i=ht.get(n);if(i==null)return;let s=new AbortController,a=c=>{c.detail.name!==n||c.detail.identifier!==o||s.abort()};e.addEventListener("abortReadLockRequest",a),i.readLock({signal:s.signal}).then(async c=>{await r.detail.handler().finally(()=>{c()})}).catch(c=>{r.detail.onError(c)}).finally(()=>{e.removeEventListener("abortReadLockRequest",a)})}),e.addEventListener("requestWriteLock",r=>{let n=r.detail.name,o=r.detail.identifier,i=ht.get(n);if(i==null)return;let s=new AbortController,a=c=>{c.detail.name!==n||c.detail.identifier!==o||s.abort()};e.addEventListener("abortWriteLockRequest",a),i.writeLock({signal:s.signal}).then(async c=>{await r.detail.handler().finally(()=>{c()})}).catch(c=>{r.detail.onError(c)}).finally(()=>{e.removeEventListener("abortWriteLockRequest",a)})}),e.addEventListener("finalizeRequest",r=>{let n=r.detail.name,o=ht.get(n);o?.finalize()})}return yr}async function Vi(t,e){let r,n,o=new Promise((s,a)=>{r=s,n=a}),i=()=>{n(new te)};return e?.signal?.addEventListener("abort",i,{once:!0}),t.add(async()=>{await new Promise(s=>{r(()=>{e?.signal?.removeEventListener("abort",i),s()})})},{signal:e?.signal}).catch(s=>{n(s)}),o}var Oc=(t,e)=>{let r=ht.get(t);if(r!=null)return r;let n=Yh(e);if(Mc(n))return r=n,ht.set(t,r),r;let o=new gr({concurrency:1}),i;return r={async readLock(s){if(i!=null)return Vi(i,s);i=new gr({concurrency:e.concurrency,autoStart:!1});let a=i,c=Vi(i,s);return o.add(async()=>{a.start(),await a.onIdle().then(()=>{i===a&&(i=null)})}),c},async writeLock(s){return i=null,Vi(o,s)},finalize:()=>{ht.delete(t)},queue:o},ht.set(t,r),e.autoFinalize===!0&&o.addEventListener("idle",()=>{r.finalize()},{once:!0}),r};var Xh={name:"lock",concurrency:1/0,singleProcess:!1,autoFinalize:!1};function Hi(t){let e=Object.assign({},Xh,t);return Oc(e.name,e)}var to=class{lock;child;pins;started;constructor(e,r,n={}){this.child=e,this.pins=r,this.lock=Hi({singleProcess:n.holdGcLock}),this.started=!1}isStarted(){return this.started}async start(){await We(this.child),this.started=!0}async stop(){await Ge(this.child),this.started=!1}unwrap(){return this.child}async put(e,r,n={}){n?.signal?.throwIfAborted();let o=await this.lock.readLock();try{return await this.child.put(e,r,n)}finally{o()}}async*putMany(e,r={}){r?.signal?.throwIfAborted();let n=await this.lock.readLock();try{yield*this.child.putMany(e,r)}finally{n()}}async*get(e,r={}){r?.signal?.throwIfAborted();let n=await this.lock.readLock();try{yield*this.child.get(e,r)}finally{n()}}async*getMany(e,r={}){r?.signal?.throwIfAborted();let n=await this.lock.readLock();try{yield*this.child.getMany(e,r)}finally{n()}}async delete(e,r={}){r?.signal?.throwIfAborted();let n=await this.lock.writeLock();try{if(await this.pins.isPinned(e))throw new pr("Block was pinned - please unpin and try again");await this.child.delete(e,r)}finally{n()}}async*deleteMany(e,r={}){r?.signal?.throwIfAborted();let n=await this.lock.writeLock();try{let o=this;yield*this.child.deleteMany((async function*(){for await(let i of e){if(await o.pins.isPinned(i))throw new pr("Block was pinned - please unpin and try again");yield i}})(),r)}finally{n()}}async has(e,r={}){r?.signal?.throwIfAborted();let n=await this.lock.readLock();try{return await this.child.has(e,r)}finally{n()}}async*getAll(e={}){e?.signal?.throwIfAborted();let r=await this.lock.readLock();try{yield*this.child.getAll(e)}finally{r()}}createSession(e,r){return r?.signal?.throwIfAborted(),this.child.createSession(e,r)}};var Ki=new je("/version"),Fc=1;async function zc(t){if(!await t.has(Ki)){await t.put(Ki,W(`${Fc}`));return}let e=await t.get(Ki),r=Je(e);if(parseInt(r,10)!==Fc)throw new Un("Invalid datastore version, a datastore migration may be required")}var cs={};M(cs,{code:()=>as,decode:()=>Hp,decodeOptions:()=>jp,encode:()=>Vp,encodeOptions:()=>Fp,name:()=>qp,toByteView:()=>Gu});var Zh=["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 Wi(t){if(t===null)return"null";if(t===void 0)return"undefined";if(t===!0||t===!1)return"boolean";let e=typeof t;if(e==="string"||e==="number"||e==="bigint"||e==="symbol")return e;if(e==="function")return"Function";if(Array.isArray(t))return"Array";if(t instanceof Uint8Array)return"Uint8Array";if(t.constructor===Object)return"Object";let r=ep(t);return r||"Object"}function ep(t){let e=Object.prototype.toString.call(t).slice(8,-1);if(Zh.includes(e))return e}var f=class{constructor(e,r,n){this.major=e,this.majorEncoded=e<<5,this.name=r,this.terminal=n}toString(){return`Type[${this.major}].${this.name}`}compare(e){return this.major<e.major?-1:this.major>e.major?1:0}static equals(e,r){return e===r||e.major===r.major&&e.name===r.name}};f.uint=new f(0,"uint",!0);f.negint=new f(1,"negint",!0);f.bytes=new f(2,"bytes",!0);f.string=new f(3,"string",!0);f.array=new f(4,"array",!1);f.map=new f(5,"map",!1);f.tag=new f(6,"tag",!1);f.float=new f(7,"float",!0);f.false=new f(7,"false",!0);f.true=new f(7,"true",!0);f.null=new f(7,"null",!0);f.undefined=new f(7,"undefined",!0);f.break=new f(7,"break",!0);var b=class{constructor(e,r,n){this.type=e,this.value=r,this.encodedLength=n,this.encodedBytes=void 0,this.byteValue=void 0}toString(){return`Token[${this.type}].${this.value}`}};var wr=globalThis.process&&!globalThis.process.browser&&globalThis.Buffer&&typeof globalThis.Buffer.isBuffer=="function",tp=new TextEncoder;function ro(t){return wr&&globalThis.Buffer.isBuffer(t)}function xr(t){return t instanceof Uint8Array?ro(t)?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):t:Uint8Array.from(t)}var rp=24,np=200,no=wr?t=>t.length>=rp?globalThis.Buffer.from(t):jc(t):t=>t.length>=np?tp.encode(t):jc(t),Re=t=>Uint8Array.from(t),qc=wr?(t,e,r)=>ro(t)?new Uint8Array(t.subarray(e,r)):t.slice(e,r):(t,e,r)=>t.slice(e,r),Vc=wr?(t,e)=>(t=t.map(r=>r instanceof Uint8Array?r:globalThis.Buffer.from(r)),xr(globalThis.Buffer.concat(t,e))):(t,e)=>{let r=new Uint8Array(e),n=0;for(let o of t)n+o.length>r.length&&(o=o.subarray(0,r.length-n)),r.set(o,n),n+=o.length;return r},Hc=wr?t=>globalThis.Buffer.allocUnsafe(t):t=>new Uint8Array(t);function oo(t,e){if(ro(t)&&ro(e))return t.compare(e);for(let r=0;r<t.length;r++)if(t[r]!==e[r])return t[r]<e[r]?-1:1;return 0}function jc(t){let e=[],r=0;for(let n=0;n<t.length;n++){let o=t.charCodeAt(n);o<128?e[r++]=o:o<2048?(e[r++]=o>>6|192,e[r++]=o&63|128):(o&64512)===55296&&n+1<t.length&&(t.charCodeAt(n+1)&64512)===56320?(o=65536+((o&1023)<<10)+(t.charCodeAt(++n)&1023),e[r++]=o>>18|240,e[r++]=o>>12&63|128,e[r++]=o>>6&63|128,e[r++]=o&63|128):(o>=55296&&o<=57343&&(o=65533),e[r++]=o>>12|224,e[r++]=o>>6&63|128,e[r++]=o&63|128)}return e}var op=256,br=class{constructor(e=op){this.chunkSize=e,this.cursor=0,this.maxCursor=-1,this.chunks=[],this._initReuseChunk=null}reset(){this.cursor=0,this.maxCursor=-1,this.chunks.length&&(this.chunks=[]),this._initReuseChunk!==null&&(this.chunks.push(this._initReuseChunk),this.maxCursor=this._initReuseChunk.length-1)}push(e){let r=this.chunks[this.chunks.length-1];if(this.cursor+e.length<=this.maxCursor+1){let o=r.length-(this.maxCursor-this.cursor)-1;r.set(e,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)}e.length<64&&e.length<this.chunkSize?(r=Hc(this.chunkSize),this.chunks.push(r),this.maxCursor+=r.length,this._initReuseChunk===null&&(this._initReuseChunk=r),r.set(e,0)):(this.chunks.push(e),this.maxCursor+=e.length)}this.cursor+=e.length}toBytes(e=!1){let r;if(this.chunks.length===1){let n=this.chunks[0];e&&this.cursor>n.length/2?(r=this.cursor===n.length?n:n.subarray(0,this.cursor),this._initReuseChunk=null,this.chunks=[]):r=qc(n,0,this.cursor)}else r=Vc(this.chunks,this.cursor);return e&&this.reset(),r}},io=class{constructor(e){this.dest=e,this.cursor=0,this.chunks=[e]}reset(){this.cursor=0}push(e){if(this.cursor+e.length>this.dest.length)throw new Error("write out of bounds, destination buffer is too small");this.dest.set(e,this.cursor),this.cursor+=e.length}toBytes(e=!1){let r=this.dest.subarray(0,this.cursor);return e&&this.reset(),r}};var v="CBOR decode error:",so="CBOR encode error:",Er=[];Er[23]=1;Er[24]=2;Er[25]=3;Er[26]=5;Er[27]=9;function qe(t,e,r){if(t.length-e<r)throw new Error(`${v} not enough data for type`)}var F=[24,256,65536,4294967296,BigInt("18446744073709551616")];function re(t,e,r){qe(t,e,1);let n=t[e];if(r.strict===!0&&n<F[0])throw new Error(`${v} integer encoded in more bytes than necessary (strict decode)`);return n}function ne(t,e,r){qe(t,e,2);let n=t[e]<<8|t[e+1];if(r.strict===!0&&n<F[1])throw new Error(`${v} integer encoded in more bytes than necessary (strict decode)`);return n}function oe(t,e,r){qe(t,e,4);let n=t[e]*16777216+(t[e+1]<<16)+(t[e+2]<<8)+t[e+3];if(r.strict===!0&&n<F[2])throw new Error(`${v} integer encoded in more bytes than necessary (strict decode)`);return n}function ie(t,e,r){qe(t,e,8);let n=t[e]*16777216+(t[e+1]<<16)+(t[e+2]<<8)+t[e+3],o=t[e+4]*16777216+(t[e+5]<<16)+(t[e+6]<<8)+t[e+7],i=(BigInt(n)<<BigInt(32))+BigInt(o);if(r.strict===!0&&i<F[3])throw new Error(`${v} integer encoded in more bytes than necessary (strict decode)`);if(i<=Number.MAX_SAFE_INTEGER)return Number(i);if(r.allowBigInt===!0)return i;throw new Error(`${v} integers outside of the safe integer range are not supported`)}function Kc(t,e,r,n){return new b(f.uint,re(t,e+1,n),2)}function Wc(t,e,r,n){return new b(f.uint,ne(t,e+1,n),3)}function Gc(t,e,r,n){return new b(f.uint,oe(t,e+1,n),5)}function Qc(t,e,r,n){return new b(f.uint,ie(t,e+1,n),9)}function pe(t,e){return R(t,0,e.value)}function R(t,e,r){if(r<F[0]){let n=Number(r);t.push([e|n])}else if(r<F[1]){let n=Number(r);t.push([e|24,n])}else if(r<F[2]){let n=Number(r);t.push([e|25,n>>>8,n&255])}else if(r<F[3]){let n=Number(r);t.push([e|26,n>>>24&255,n>>>16&255,n>>>8&255,n&255])}else{let n=BigInt(r);if(n<F[4]){let o=[e|27,0,0,0,0,0,0,0],i=Number(n&BigInt(4294967295)),s=Number(n>>BigInt(32)&BigInt(4294967295));o[8]=i&255,i=i>>8,o[7]=i&255,i=i>>8,o[6]=i&255,i=i>>8,o[5]=i&255,o[4]=s&255,s=s>>8,o[3]=s&255,s=s>>8,o[2]=s&255,s=s>>8,o[1]=s&255,t.push(o)}else throw new Error(`${v} encountered BigInt larger than allowable range`)}}pe.encodedSize=function(e){return R.encodedSize(e.value)};R.encodedSize=function(e){return e<F[0]?1:e<F[1]?2:e<F[2]?3:e<F[3]?5:9};pe.compareTokens=function(e,r){return e.value<r.value?-1:e.value>r.value?1:0};function Jc(t,e,r,n){return new b(f.negint,-1-re(t,e+1,n),2)}function Yc(t,e,r,n){return new b(f.negint,-1-ne(t,e+1,n),3)}function Xc(t,e,r,n){return new b(f.negint,-1-oe(t,e+1,n),5)}var Gi=BigInt(-1),Zc=BigInt(1);function eu(t,e,r,n){let o=ie(t,e+1,n);if(typeof o!="bigint"){let i=-1-o;if(i>=Number.MIN_SAFE_INTEGER)return new b(f.negint,i,9)}if(n.allowBigInt!==!0)throw new Error(`${v} integers outside of the safe integer range are not supported`);return new b(f.negint,Gi-BigInt(o),9)}function ao(t,e){let r=e.value,n=typeof r=="bigint"?r*Gi-Zc:r*-1-1;R(t,e.type.majorEncoded,n)}ao.encodedSize=function(e){let r=e.value,n=typeof r=="bigint"?r*Gi-Zc:r*-1-1;return n<F[0]?1:n<F[1]?2:n<F[2]?3:n<F[3]?5:9};ao.compareTokens=function(e,r){return e.value<r.value?1:e.value>r.value?-1:0};function _r(t,e,r,n){qe(t,e,r+n);let o=t.slice(e+r,e+r+n);return new b(f.bytes,o,r+n)}function tu(t,e,r,n){return _r(t,e,1,r)}function ru(t,e,r,n){return _r(t,e,2,re(t,e+1,n))}function nu(t,e,r,n){return _r(t,e,3,ne(t,e+1,n))}function ou(t,e,r,n){return _r(t,e,5,oe(t,e+1,n))}function iu(t,e,r,n){let o=ie(t,e+1,n);if(typeof o=="bigint")throw new Error(`${v} 64-bit integer bytes lengths not supported`);return _r(t,e,9,o)}function co(t){return t.encodedBytes===void 0&&(t.encodedBytes=f.equals(t.type,f.string)?no(t.value):t.value),t.encodedBytes}function Lt(t,e){let r=co(e);R(t,e.type.majorEncoded,r.length),t.push(r)}Lt.encodedSize=function(e){let r=co(e);return R.encodedSize(r.length)+r.length};Lt.compareTokens=function(e,r){return sp(co(e),co(r))};function sp(t,e){return t.length<e.length?-1:t.length>e.length?1:oo(t,e)}var su=new TextDecoder,cp=32;function up(t,e,r){if(r-e<cp){let o="";for(let i=e;i<r;i++){let s=t[i];if(s&128)return su.decode(t.subarray(e,r));o+=String.fromCharCode(s)}return o}return su.decode(t.subarray(e,r))}function vr(t,e,r,n,o){let i=r+n;qe(t,e,i);let s=new b(f.string,up(t,e+r,e+i),i);return o.retainStringBytes===!0&&(s.byteValue=t.slice(e+r,e+i)),s}function au(t,e,r,n){return vr(t,e,1,r,n)}function cu(t,e,r,n){return vr(t,e,2,re(t,e+1,n),n)}function uu(t,e,r,n){return vr(t,e,3,ne(t,e+1,n),n)}function fu(t,e,r,n){return vr(t,e,5,oe(t,e+1,n),n)}function lu(t,e,r,n){let o=ie(t,e+1,n);if(typeof o=="bigint")throw new Error(`${v} 64-bit integer string lengths not supported`);return vr(t,e,9,o,n)}var du=Lt;function Bt(t,e,r,n){return new b(f.array,n,r)}function hu(t,e,r,n){return Bt(t,e,1,r)}function pu(t,e,r,n){return Bt(t,e,2,re(t,e+1,n))}function mu(t,e,r,n){return Bt(t,e,3,ne(t,e+1,n))}function gu(t,e,r,n){return Bt(t,e,5,oe(t,e+1,n))}function yu(t,e,r,n){let o=ie(t,e+1,n);if(typeof o=="bigint")throw new Error(`${v} 64-bit integer array lengths not supported`);return Bt(t,e,9,o)}function wu(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${v} indefinite length items not allowed`);return Bt(t,e,1,1/0)}function uo(t,e){R(t,f.array.majorEncoded,e.value)}uo.compareTokens=pe.compareTokens;uo.encodedSize=function(e){return R.encodedSize(e.value)};function Rt(t,e,r,n){return new b(f.map,n,r)}function xu(t,e,r,n){return Rt(t,e,1,r)}function bu(t,e,r,n){return Rt(t,e,2,re(t,e+1,n))}function Eu(t,e,r,n){return Rt(t,e,3,ne(t,e+1,n))}function _u(t,e,r,n){return Rt(t,e,5,oe(t,e+1,n))}function vu(t,e,r,n){let o=ie(t,e+1,n);if(typeof o=="bigint")throw new Error(`${v} 64-bit integer map lengths not supported`);return Rt(t,e,9,o)}function ku(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${v} indefinite length items not allowed`);return Rt(t,e,1,1/0)}function fo(t,e){R(t,f.map.majorEncoded,e.value)}fo.compareTokens=pe.compareTokens;fo.encodedSize=function(e){return R.encodedSize(e.value)};function Au(t,e,r,n){return new b(f.tag,r,1)}function Tu(t,e,r,n){return new b(f.tag,re(t,e+1,n),2)}function Iu(t,e,r,n){return new b(f.tag,ne(t,e+1,n),3)}function Su(t,e,r,n){return new b(f.tag,oe(t,e+1,n),5)}function Uu(t,e,r,n){return new b(f.tag,ie(t,e+1,n),9)}function lo(t,e){R(t,f.tag.majorEncoded,e.value)}lo.compareTokens=pe.compareTokens;lo.encodedSize=function(e){return R.encodedSize(e.value)};var Qi=20,Ji=21,Yi=22,Xi=23;function Nu(t,e,r,n){if(n.allowUndefined===!1)throw new Error(`${v} undefined values are not supported`);return n.coerceUndefinedToNull===!0?new b(f.null,null,1):new b(f.undefined,void 0,1)}function Cu(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${v} indefinite length items not allowed`);return new b(f.break,void 0,1)}function Zi(t,e,r){if(r){if(r.allowNaN===!1&&Number.isNaN(t))throw new Error(`${v} NaN values are not supported`);if(r.allowInfinity===!1&&(t===1/0||t===-1/0))throw new Error(`${v} Infinity values are not supported`)}return new b(f.float,t,e)}function Lu(t,e,r,n){return Zi(es(t,e+1),3,n)}function Bu(t,e,r,n){return Zi(ts(t,e+1),5,n)}function Ru(t,e,r,n){return Zi(Mu(t,e+1),9,n)}function kr(t,e,r){let n=e.value;if(n===!1)t.push([f.float.majorEncoded|Qi]);else if(n===!0)t.push([f.float.majorEncoded|Ji]);else if(n===null)t.push([f.float.majorEncoded|Yi]);else if(n===void 0)t.push([f.float.majorEncoded|Xi]);else{let o,i=!1;(!r||r.float64!==!0)&&(Du(n),o=es(Te,1),n===o||Number.isNaN(n)?(Te[0]=249,t.push(Te.slice(0,3)),i=!0):($u(n),o=ts(Te,1),n===o&&(Te[0]=250,t.push(Te.slice(0,5)),i=!0))),i||(pp(n),o=Mu(Te,1),Te[0]=251,t.push(Te.slice(0,9)))}}kr.encodedSize=function(e,r){let n=e.value;if(n===!1||n===!0||n===null||n===void 0)return 1;if(!r||r.float64!==!0){Du(n);let o=es(Te,1);if(n===o||Number.isNaN(n))return 3;if($u(n),o=ts(Te,1),n===o)return 5}return 9};var Pu=new ArrayBuffer(9),me=new DataView(Pu,1),Te=new Uint8Array(Pu,0);function Du(t){if(t===1/0)me.setUint16(0,31744,!1);else if(t===-1/0)me.setUint16(0,64512,!1);else if(Number.isNaN(t))me.setUint16(0,32256,!1);else{me.setFloat32(0,t);let e=me.getUint32(0),r=(e&2139095040)>>23,n=e&8388607;if(r===255)me.setUint16(0,31744,!1);else if(r===0)me.setUint16(0,(e&2147483648)>>16|n>>13,!1);else{let o=r-127;o<-24?me.setUint16(0,0):o<-14?me.setUint16(0,(e&2147483648)>>16|1<<24+o,!1):me.setUint16(0,(e&2147483648)>>16|o+15<<10|n>>13,!1)}}}function es(t,e){if(t.length-e<2)throw new Error(`${v} not enough data for float16`);let r=(t[e]<<8)+t[e+1];if(r===31744)return 1/0;if(r===64512)return-1/0;if(r===32256)return NaN;let n=r>>10&31,o=r&1023,i;return n===0?i=o*2**-24:n!==31?i=(o+1024)*2**(n-25):i=o===0?1/0:NaN,r&32768?-i:i}function $u(t){me.setFloat32(0,t,!1)}function ts(t,e){if(t.length-e<4)throw new Error(`${v} not enough data for float32`);let r=(t.byteOffset||0)+e;return new DataView(t.buffer,r,4).getFloat32(0,!1)}function pp(t){me.setFloat64(0,t,!1)}function Mu(t,e){if(t.length-e<8)throw new Error(`${v} not enough data for float64`);let r=(t.byteOffset||0)+e;return new DataView(t.buffer,r,8).getFloat64(0,!1)}kr.compareTokens=pe.compareTokens;function N(t,e,r){throw new Error(`${v} encountered invalid minor (${r}) for major ${t[e]>>>5}`)}function ho(t){return()=>{throw new Error(`${v} ${t}`)}}var y=[];for(let t=0;t<=23;t++)y[t]=N;y[24]=Kc;y[25]=Wc;y[26]=Gc;y[27]=Qc;y[28]=N;y[29]=N;y[30]=N;y[31]=N;for(let t=32;t<=55;t++)y[t]=N;y[56]=Jc;y[57]=Yc;y[58]=Xc;y[59]=eu;y[60]=N;y[61]=N;y[62]=N;y[63]=N;for(let t=64;t<=87;t++)y[t]=tu;y[88]=ru;y[89]=nu;y[90]=ou;y[91]=iu;y[92]=N;y[93]=N;y[94]=N;y[95]=ho("indefinite length bytes/strings are not supported");for(let t=96;t<=119;t++)y[t]=au;y[120]=cu;y[121]=uu;y[122]=fu;y[123]=lu;y[124]=N;y[125]=N;y[126]=N;y[127]=ho("indefinite length bytes/strings are not supported");for(let t=128;t<=151;t++)y[t]=hu;y[152]=pu;y[153]=mu;y[154]=gu;y[155]=yu;y[156]=N;y[157]=N;y[158]=N;y[159]=wu;for(let t=160;t<=183;t++)y[t]=xu;y[184]=bu;y[185]=Eu;y[186]=_u;y[187]=vu;y[188]=N;y[189]=N;y[190]=N;y[191]=ku;for(let t=192;t<=215;t++)y[t]=Au;y[216]=Tu;y[217]=Iu;y[218]=Su;y[219]=Uu;y[220]=N;y[221]=N;y[222]=N;y[223]=N;for(let t=224;t<=243;t++)y[t]=ho("simple values are not supported");y[244]=N;y[245]=N;y[246]=N;y[247]=Nu;y[248]=ho("simple values are not supported");y[249]=Lu;y[250]=Bu;y[251]=Ru;y[252]=N;y[253]=N;y[254]=N;y[255]=Cu;var Ie=[];for(let t=0;t<24;t++)Ie[t]=new b(f.uint,t,1);for(let t=-1;t>=-24;t--)Ie[31-t]=new b(f.negint,t,1);Ie[64]=new b(f.bytes,new Uint8Array(0),1);Ie[96]=new b(f.string,"",1);Ie[128]=new b(f.array,0,1);Ie[160]=new b(f.map,0,1);Ie[244]=new b(f.false,!1,1);Ie[245]=new b(f.true,!0,1);Ie[246]=new b(f.null,null,1);function rs(t){switch(t.type){case f.false:return Re([244]);case f.true:return Re([245]);case f.null:return Re([246]);case f.bytes:return t.value.length?void 0:Re([64]);case f.string:return t.value===""?Re([96]):void 0;case f.array:return t.value===0?Re([128]):void 0;case f.map:return t.value===0?Re([160]):void 0;case f.uint:return t.value<24?Re([Number(t.value)]):void 0;case f.negint:if(t.value>=-24)return Re([31-Number(t.value)])}}var gp={float64:!1,mapSorter:xp,quickEncodeToken:rs},qu=Object.freeze({float64:!0,mapSorter:bp,quickEncodeToken:rs});function yp(){let t=[];return t[f.uint.major]=pe,t[f.negint.major]=ao,t[f.bytes.major]=Lt,t[f.string.major]=du,t[f.array.major]=uo,t[f.map.major]=fo,t[f.tag.major]=lo,t[f.float.major]=kr,t}var Dt=yp(),po=new br,Tr=class t{constructor(e,r){this.obj=e,this.parent=r}includes(e){let r=this;do if(r.obj===e)return!0;while(r=r.parent);return!1}static createCheck(e,r){if(e&&e.includes(r))throw new Error(`${so} object contains circular references`);return new t(r,e)}},Xe={null:new b(f.null,null),undefined:new b(f.undefined,void 0),true:new b(f.true,!0),false:new b(f.false,!1),emptyArray:new b(f.array,0),emptyMap:new b(f.map,0)},Pe={number(t,e,r,n){return!Number.isInteger(t)||!Number.isSafeInteger(t)?new b(f.float,t):t>=0?new b(f.uint,t):new b(f.negint,t)},bigint(t,e,r,n){return t>=BigInt(0)?new b(f.uint,t):new b(f.negint,t)},Uint8Array(t,e,r,n){return new b(f.bytes,t)},string(t,e,r,n){return new b(f.string,t)},boolean(t,e,r,n){return t?Xe.true:Xe.false},null(t,e,r,n){return Xe.null},undefined(t,e,r,n){return Xe.undefined},ArrayBuffer(t,e,r,n){return new b(f.bytes,new Uint8Array(t))},DataView(t,e,r,n){return new b(f.bytes,new Uint8Array(t.buffer,t.byteOffset,t.byteLength))},Array(t,e,r,n){if(!t.length)return r.addBreakTokens===!0?[Xe.emptyArray,new b(f.break)]:Xe.emptyArray;n=Tr.createCheck(n,t);let o=[],i=0;for(let s of t)o[i++]=Pt(s,r,n);return r.addBreakTokens?[new b(f.array,t.length),o,new b(f.break)]:[new b(f.array,t.length),o]},Object(t,e,r,n){let o=e!=="Object",i=o?t.keys():Object.keys(t),s=o?t.size:i.length,a;if(s){a=new Array(s),n=Tr.createCheck(n,t);let c=!o&&r.ignoreUndefinedProperties,l=0;for(let p of i){let m=o?t.get(p):t[p];c&&m===void 0||(a[l++]=[Pt(p,r,n),Pt(m,r,n)])}l<s&&(a.length=l)}return a?.length?(wp(a,r),r.addBreakTokens?[new b(f.map,a.length),a,new b(f.break)]:[new b(f.map,a.length),a]):r.addBreakTokens===!0?[Xe.emptyMap,new b(f.break)]:Xe.emptyMap},Tagged(t,e,r,n){return[new b(f.tag,t.tag),Pt(t.value,r,n)]}};Pe.Map=Pe.Object;Pe.Buffer=Pe.Uint8Array;for(let t of"Uint8Clamped Uint16 Uint32 Int8 Int16 Int32 BigUint64 BigInt64 Float32 Float64".split(" "))Pe[`${t}Array`]=Pe.DataView;function Pt(t,e={},r){let n=Wi(t),o=e&&e.typeEncoders&&e.typeEncoders[n]||Pe[n];if(typeof o=="function"){let s=o(t,n,e,r);if(s!=null)return s}let i=Pe[n];if(!i)throw new Error(`${so} unsupported type: ${n}`);return i(t,n,e,r)}function wp(t,e){e.mapSorter&&t.sort(e.mapSorter)}function xp(t,e){let r=Array.isArray(t[0])?t[0][0]:t[0],n=Array.isArray(e[0])?e[0][0]:e[0];if(r.type!==n.type)return r.type.compare(n.type);let o=r.type.major,i=Dt[o].compareTokens(r,n);return i===0&&console.warn("WARNING: complex key types used, CBOR key sorting guarantees are gone"),i}function bp(t,e){if(t[0]instanceof b&&e[0]instanceof b){let r=t[0],n=e[0];return r._keyBytes||(r._keyBytes=Ou(r.value)),n._keyBytes||(n._keyBytes=Ou(n.value)),oo(r._keyBytes,n._keyBytes)}throw new Error("rfc8949MapSorter: complex key types are not supported yet")}function Ou(t){return Hu(t,Dt,qu)}function Ar(t,e,r,n){if(Array.isArray(e))for(let o of e)Ar(t,o,r,n);else r[e.type.major](t,e,n)}var Fu=f.uint.majorEncoded,zu=f.negint.majorEncoded,Ep=f.bytes.majorEncoded,_p=f.string.majorEncoded,ju=f.array.majorEncoded,vp=f.float.majorEncoded|Qi,kp=f.float.majorEncoded|Ji,Ap=f.float.majorEncoded|Yi,Tp=f.float.majorEncoded|Xi,Ip=BigInt(-1),Sp=BigInt(1);function Up(t){return t.addBreakTokens!==!0}function Vu(t,e,r,n){let o=Wi(e),i=r.typeEncoders&&r.typeEncoders[o];if(i){let s=i(e,o,r,n);if(s!=null){Ar(t,s,Dt,r);return}}switch(o){case"null":t.push([Ap]);return;case"undefined":t.push([Tp]);return;case"boolean":t.push([e?kp:vp]);return;case"number":!Number.isInteger(e)||!Number.isSafeInteger(e)?kr(t,new b(f.float,e),r):e>=0?R(t,Fu,e):R(t,zu,e*-1-1);return;case"bigint":e>=BigInt(0)?R(t,Fu,e):R(t,zu,e*Ip-Sp);return;case"string":{let s=no(e);R(t,_p,s.length),t.push(s);return}case"Uint8Array":R(t,Ep,e.length),t.push(e);return;case"Array":if(!e.length){t.push([ju]);return}n=Tr.createCheck(n,e),R(t,ju,e.length);for(let s of e)Vu(t,s,r,n);return;case"Object":case"Map":{let s=Pe.Object(e,o,r,n);Ar(t,s,Dt,r)}return;default:{let s=Pe[o];if(!s)throw new Error(`${so} unsupported type: ${o}`);let a=s(e,o,r,n);Ar(t,a,Dt,r)}}}function Hu(t,e,r,n){let o=n instanceof Uint8Array,i=o?new io(n):po,s=Pt(t,r);if(!Array.isArray(s)&&r.quickEncodeToken){let a=r.quickEncodeToken(s);if(a)return o?(i.push(a),i.toBytes()):a;let c=e[s.type.major];if(c.encodedSize){let l=c.encodedSize(s,r);if(o||(i=new br(l)),c(i,s,r),i.chunks.length!==1)throw new Error(`Unexpected error: pre-calculated length for ${s} was wrong`);return o?i.toBytes():xr(i.chunks[0])}}return i.reset(),Ar(i,s,e,r),i.toBytes(!0)}function ns(t,e){return e=Object.assign({},gp,e),Up(e)?(po.reset(),Vu(po,t,e,void 0),po.toBytes(!0)):Hu(t,Dt,e)}var Np={strict:!1,allowIndefinite:!0,allowUndefined:!0,allowBigInt:!0},mo=class{constructor(e,r={}){this._pos=0,this.data=e,this.options=r}pos(){return this._pos}done(){return this._pos>=this.data.length}next(){let e=this.data[this._pos],r=Ie[e];if(r===void 0){let n=y[e];if(!n)throw new Error(`${v} no decoder for major type ${e>>>5} (byte 0x${e.toString(16).padStart(2,"0")})`);let o=e&31;r=n(this.data,this._pos,o,this.options)}return this._pos+=r.encodedLength,r}},Ze=Symbol.for("DONE"),$t=Symbol.for("BREAK");function Cp(t,e,r){let n=[];for(let o=0;o<t.value;o++){let i=et(e,r);if(i===$t){if(t.value===1/0)break;throw new Error(`${v} got unexpected break to lengthed array`)}if(i===Ze)throw new Error(`${v} found array but not enough entries (got ${o}, expected ${t.value})`);n[o]=i}return n}function Lp(t,e,r){let n=r.useMaps===!0,o=r.rejectDuplicateMapKeys===!0,i=n?void 0:{},s=n?new Map:void 0;for(let a=0;a<t.value;a++){let c=et(e,r);if(c===$t){if(t.value===1/0)break;throw new Error(`${v} got unexpected break to lengthed map`)}if(c===Ze)throw new Error(`${v} found map but not enough entries (got ${a} [no key], expected ${t.value})`);if(!n&&typeof c!="string")throw new Error(`${v} non-string keys not supported (got ${typeof c})`);if(o&&(n&&s.has(c)||!n&&Object.hasOwn(i,c)))throw new Error(`${v} found repeat map key "${c}"`);let l=et(e,r);if(l===Ze)throw new Error(`${v} found map but not enough entries (got ${a} [no value], expected ${t.value})`);n?s.set(c,l):i[c]=l}return n?s:i}function*Bp(t,e,r){for(let n=0;n<t.value;n++){let o=et(e,r);if(o===$t){if(t.value===1/0)break;throw new Error(`${v} got unexpected break to lengthed map`)}if(o===Ze)throw new Error(`${v} found map but not enough entries (got ${n} [no key], expected ${t.value})`);let i=et(e,r);if(i===Ze)throw new Error(`${v} found map but not enough entries (got ${n} [no value], expected ${t.value})`);yield[o,i]}}function Rp(t,e){let r=!1,n=function(){if(r)throw new Error(`${v} tag decode() may only be called once`);r=!0;let o=et(t,e);if(o===Ze)throw new Error(`${v} tag content missing`);if(o===$t)throw new Error(`${v} got unexpected break in tag content`);return o};return n.entries=function(){if(r)throw new Error(`${v} tag decode() may only be called once`);r=!0;let o=t.next();if(!f.equals(o.type,f.map))throw new Error(`${v} entries() requires map content, got ${o.type.name}`);let i=[];for(let s of Bp(o,t,e))i.push(s);return i},Object.defineProperty(n,"_called",{get(){return r},enumerable:!1}),n}function et(t,e){if(t.done())return Ze;let r=t.next();if(f.equals(r.type,f.break))return $t;if(r.type.terminal)return r.value;if(f.equals(r.type,f.array))return Cp(r,t,e);if(f.equals(r.type,f.map))return Lp(r,t,e);if(f.equals(r.type,f.tag)){if(e.tags&&typeof e.tags[r.value]=="function"){let n=Rp(t,e),o=e.tags[r.value](n);if(!n._called)throw new Error(`${v} tag decoder must call decode() or entries()`);return o}throw new Error(`${v} tag not supported (${r.value})`)}throw new Error("unsupported")}function Ku(t,e){if(!(t instanceof Uint8Array))throw new Error(`${v} data to decode must be a Uint8Array`);e=Object.assign({},Np,e);let r=xr(t),n=e.tokenizer||new mo(r,e),o=et(n,e);if(o===Ze)throw new Error(`${v} did not find any content to decode`);if(o===$t)throw new Error(`${v} got unexpected break`);return[o,t.subarray(n.pos())]}function os(t,e){let[r,n]=Ku(t,e);if(n.length>0)throw new Error(`${v} too many terminals, data makes no sense`);return r}var go=class t{constructor(e,r){if(typeof e!="number"||!Number.isInteger(e)||e<0)throw new TypeError("Tagged: tag must be a non-negative integer");this.tag=e,this.value=r}static decoder(e){return r=>new t(e,r())}static preserve(...e){let r={};for(let n of e)r[n]=t.decoder(n);return r}};Object.defineProperty(go.prototype,Symbol.toStringTag,{value:"Tagged"});var Wu=42;function Gu(t){return t instanceof ArrayBuffer?new Uint8Array(t,0,t.byteLength):t}function Dp(t){if(t.asCID!==t&&t["/"]!==t.bytes)return null;let e=L.asCID(t);if(!e)return null;let r=new Uint8Array(e.bytes.byteLength+1);return r.set(e.bytes,1),[new b(f.tag,Wu),new b(f.bytes,r)]}function $p(){throw new Error("`undefined` is not supported by the IPLD Data Model and cannot be encoded")}function Mp(t){if(Number.isNaN(t))throw new Error("`NaN` is not supported by the IPLD Data Model and cannot be encoded");if(t===1/0||t===-1/0)throw new Error("`Infinity` and `-Infinity` is not supported by the IPLD Data Model and cannot be encoded");return null}function Op(t){for(let e of t.keys())if(typeof e!="string"||e.length===0)throw new Error("Non-string Map keys are not supported by the IPLD Data Model and cannot be encoded");return null}var is={float64:!0,typeEncoders:{Map:Op,Object:Dp,undefined:$p,number:Mp}},Fp={...is,typeEncoders:{...is.typeEncoders}};function zp(t){let e=t();if(e[0]!==0)throw new Error("Invalid CID for CBOR tag 42; expected leading 0x00");return L.decode(e.subarray(1))}var ss={allowIndefinite:!1,coerceUndefinedToNull:!0,allowNaN:!1,allowInfinity:!1,allowBigInt:!0,strict:!0,useMaps:!1,rejectDuplicateMapKeys:!0,tags:{[Wu]:zp}},jp={...ss,tags:{...ss.tags}},qp="dag-cbor",as=113,Vp=t=>ns(t,is),Hp=t=>os(Gu(t),ss);var As={};M(As,{code:()=>ks,decode:()=>rl,encode:()=>tl,format:()=>Um,name:()=>Sm,parse:()=>Cm,stringify:()=>Um});var Kp=["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 Qu(t){if(t===null)return"null";if(t===void 0)return"undefined";if(t===!0||t===!1)return"boolean";let e=typeof t;if(e==="string"||e==="number"||e==="bigint"||e==="symbol")return e;if(e==="function")return"Function";if(Array.isArray(t))return"Array";if(t instanceof Uint8Array)return"Uint8Array";if(t.constructor===Object)return"Object";let r=Wp(t);return r||"Object"}function Wp(t){let e=Object.prototype.toString.call(t).slice(8,-1);if(Kp.includes(e))return e}var u=class{constructor(e,r,n){this.major=e,this.majorEncoded=e<<5,this.name=r,this.terminal=n}toString(){return`Type[${this.major}].${this.name}`}compare(e){return this.major<e.major?-1:this.major>e.major?1:0}static equals(e,r){return e===r||e.major===r.major&&e.name===r.name}};u.uint=new u(0,"uint",!0);u.negint=new u(1,"negint",!0);u.bytes=new u(2,"bytes",!0);u.string=new u(3,"string",!0);u.array=new u(4,"array",!1);u.map=new u(5,"map",!1);u.tag=new u(6,"tag",!1);u.float=new u(7,"float",!0);u.false=new u(7,"false",!0);u.true=new u(7,"true",!0);u.null=new u(7,"null",!0);u.undefined=new u(7,"undefined",!0);u.break=new u(7,"break",!0);var h=class{constructor(e,r,n){this.type=e,this.value=r,this.encodedLength=n,this.encodedBytes=void 0,this.byteValue=void 0}toString(){return`Token[${this.type}].${this.value}`}};var Ir=globalThis.process&&!globalThis.process.browser&&globalThis.Buffer&&typeof globalThis.Buffer.isBuffer=="function",Gp=new TextEncoder;function yo(t){return Ir&&globalThis.Buffer.isBuffer(t)}function mt(t){return t instanceof Uint8Array?yo(t)?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):t:Uint8Array.from(t)}var Qp=24,Jp=200,Sr=Ir?t=>t.length>=Qp?globalThis.Buffer.from(t):Ju(t):t=>t.length>=Jp?Gp.encode(t):Ju(t),De=t=>Uint8Array.from(t),Xu=Ir?(t,e,r)=>yo(t)?new Uint8Array(t.subarray(e,r)):t.slice(e,r):(t,e,r)=>t.slice(e,r),Zu=Ir?(t,e)=>(t=t.map(r=>r instanceof Uint8Array?r:globalThis.Buffer.from(r)),mt(globalThis.Buffer.concat(t,e))):(t,e)=>{let r=new Uint8Array(e),n=0;for(let o of t)n+o.length>r.length&&(o=o.subarray(0,r.length-n)),r.set(o,n),n+=o.length;return r},ef=Ir?t=>globalThis.Buffer.allocUnsafe(t):t=>new Uint8Array(t);function wo(t,e){if(yo(t)&&yo(e))return t.compare(e);for(let r=0;r<t.length;r++)if(t[r]!==e[r])return t[r]<e[r]?-1:1;return 0}function Ju(t){let e=[],r=0;for(let n=0;n<t.length;n++){let o=t.charCodeAt(n);o<128?e[r++]=o:o<2048?(e[r++]=o>>6|192,e[r++]=o&63|128):(o&64512)===55296&&n+1<t.length&&(t.charCodeAt(n+1)&64512)===56320?(o=65536+((o&1023)<<10)+(t.charCodeAt(++n)&1023),e[r++]=o>>18|240,e[r++]=o>>12&63|128,e[r++]=o>>6&63|128,e[r++]=o&63|128):(o>=55296&&o<=57343&&(o=65533),e[r++]=o>>12|224,e[r++]=o>>6&63|128,e[r++]=o&63|128)}return e}var Yu=4096;function tf(t){let e=t.length;if(e<=Yu)return String.fromCharCode.apply(String,t);let r="",n=0;for(;n<e;)r+=String.fromCharCode.apply(String,t.slice(n,n+=Yu));return r}var Yp=256,Ur=class{constructor(e=Yp){this.chunkSize=e,this.cursor=0,this.maxCursor=-1,this.chunks=[],this._initReuseChunk=null}reset(){this.cursor=0,this.maxCursor=-1,this.chunks.length&&(this.chunks=[]),this._initReuseChunk!==null&&(this.chunks.push(this._initReuseChunk),this.maxCursor=this._initReuseChunk.length-1)}push(e){let r=this.chunks[this.chunks.length-1];if(this.cursor+e.length<=this.maxCursor+1){let o=r.length-(this.maxCursor-this.cursor)-1;r.set(e,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)}e.length<64&&e.length<this.chunkSize?(r=ef(this.chunkSize),this.chunks.push(r),this.maxCursor+=r.length,this._initReuseChunk===null&&(this._initReuseChunk=r),r.set(e,0)):(this.chunks.push(e),this.maxCursor+=e.length)}this.cursor+=e.length}toBytes(e=!1){let r;if(this.chunks.length===1){let n=this.chunks[0];e&&this.cursor>n.length/2?(r=this.cursor===n.length?n:n.subarray(0,this.cursor),this._initReuseChunk=null,this.chunks=[]):r=Xu(n,0,this.cursor)}else r=Zu(this.chunks,this.cursor);return e&&this.reset(),r}},xo=class{constructor(e){this.dest=e,this.cursor=0,this.chunks=[e]}reset(){this.cursor=0}push(e){if(this.cursor+e.length>this.dest.length)throw new Error("write out of bounds, destination buffer is too small");this.dest.set(e,this.cursor),this.cursor+=e.length}toBytes(e=!1){let r=this.dest.subarray(0,this.cursor);return e&&this.reset(),r}};var E="CBOR decode error:",Ve="CBOR encode error:",Nr=[];Nr[23]=1;Nr[24]=2;Nr[25]=3;Nr[26]=5;Nr[27]=9;function He(t,e,r){if(t.length-e<r)throw new Error(`${E} not enough data for type`)}var z=[24,256,65536,4294967296,BigInt("18446744073709551616")];function se(t,e,r){He(t,e,1);let n=t[e];if(r.strict===!0&&n<z[0])throw new Error(`${E} integer encoded in more bytes than necessary (strict decode)`);return n}function ae(t,e,r){He(t,e,2);let n=t[e]<<8|t[e+1];if(r.strict===!0&&n<z[1])throw new Error(`${E} integer encoded in more bytes than necessary (strict decode)`);return n}function ce(t,e,r){He(t,e,4);let n=t[e]*16777216+(t[e+1]<<16)+(t[e+2]<<8)+t[e+3];if(r.strict===!0&&n<z[2])throw new Error(`${E} integer encoded in more bytes than necessary (strict decode)`);return n}function ue(t,e,r){He(t,e,8);let n=t[e]*16777216+(t[e+1]<<16)+(t[e+2]<<8)+t[e+3],o=t[e+4]*16777216+(t[e+5]<<16)+(t[e+6]<<8)+t[e+7],i=(BigInt(n)<<BigInt(32))+BigInt(o);if(r.strict===!0&&i<z[3])throw new Error(`${E} integer encoded in more bytes than necessary (strict decode)`);if(i<=Number.MAX_SAFE_INTEGER)return Number(i);if(r.allowBigInt===!0)return i;throw new Error(`${E} integers outside of the safe integer range are not supported`)}function rf(t,e,r,n){return new h(u.uint,se(t,e+1,n),2)}function nf(t,e,r,n){return new h(u.uint,ae(t,e+1,n),3)}function of(t,e,r,n){return new h(u.uint,ce(t,e+1,n),5)}function sf(t,e,r,n){return new h(u.uint,ue(t,e+1,n),9)}function ge(t,e){return j(t,0,e.value)}function j(t,e,r){if(r<z[0]){let n=Number(r);t.push([e|n])}else if(r<z[1]){let n=Number(r);t.push([e|24,n])}else if(r<z[2]){let n=Number(r);t.push([e|25,n>>>8,n&255])}else if(r<z[3]){let n=Number(r);t.push([e|26,n>>>24&255,n>>>16&255,n>>>8&255,n&255])}else{let n=BigInt(r);if(n<z[4]){let o=[e|27,0,0,0,0,0,0,0],i=Number(n&BigInt(4294967295)),s=Number(n>>BigInt(32)&BigInt(4294967295));o[8]=i&255,i=i>>8,o[7]=i&255,i=i>>8,o[6]=i&255,i=i>>8,o[5]=i&255,o[4]=s&255,s=s>>8,o[3]=s&255,s=s>>8,o[2]=s&255,s=s>>8,o[1]=s&255,t.push(o)}else throw new Error(`${E} encountered BigInt larger than allowable range`)}}ge.encodedSize=function(e){return j.encodedSize(e.value)};j.encodedSize=function(e){return e<z[0]?1:e<z[1]?2:e<z[2]?3:e<z[3]?5:9};ge.compareTokens=function(e,r){return e.value<r.value?-1:e.value>r.value?1:0};function af(t,e,r,n){return new h(u.negint,-1-se(t,e+1,n),2)}function cf(t,e,r,n){return new h(u.negint,-1-ae(t,e+1,n),3)}function uf(t,e,r,n){return new h(u.negint,-1-ce(t,e+1,n),5)}var us=BigInt(-1),ff=BigInt(1);function lf(t,e,r,n){let o=ue(t,e+1,n);if(typeof o!="bigint"){let i=-1-o;if(i>=Number.MIN_SAFE_INTEGER)return new h(u.negint,i,9)}if(n.allowBigInt!==!0)throw new Error(`${E} integers outside of the safe integer range are not supported`);return new h(u.negint,us-BigInt(o),9)}function bo(t,e){let r=e.value,n=typeof r=="bigint"?r*us-ff:r*-1-1;j(t,e.type.majorEncoded,n)}bo.encodedSize=function(e){let r=e.value,n=typeof r=="bigint"?r*us-ff:r*-1-1;return n<z[0]?1:n<z[1]?2:n<z[2]?3:n<z[3]?5:9};bo.compareTokens=function(e,r){return e.value<r.value?1:e.value>r.value?-1:0};function Cr(t,e,r,n){He(t,e,r+n);let o=t.slice(e+r,e+r+n);return new h(u.bytes,o,r+n)}function df(t,e,r,n){return Cr(t,e,1,r)}function hf(t,e,r,n){return Cr(t,e,2,se(t,e+1,n))}function pf(t,e,r,n){return Cr(t,e,3,ae(t,e+1,n))}function mf(t,e,r,n){return Cr(t,e,5,ce(t,e+1,n))}function gf(t,e,r,n){let o=ue(t,e+1,n);if(typeof o=="bigint")throw new Error(`${E} 64-bit integer bytes lengths not supported`);return Cr(t,e,9,o)}function Eo(t){return t.encodedBytes===void 0&&(t.encodedBytes=u.equals(t.type,u.string)?Sr(t.value):t.value),t.encodedBytes}function Mt(t,e){let r=Eo(e);j(t,e.type.majorEncoded,r.length),t.push(r)}Mt.encodedSize=function(e){let r=Eo(e);return j.encodedSize(r.length)+r.length};Mt.compareTokens=function(e,r){return Zp(Eo(e),Eo(r))};function Zp(t,e){return t.length<e.length?-1:t.length>e.length?1:wo(t,e)}var yf=new TextDecoder,tm=32;function rm(t,e,r){if(r-e<tm){let o="";for(let i=e;i<r;i++){let s=t[i];if(s&128)return yf.decode(t.subarray(e,r));o+=String.fromCharCode(s)}return o}return yf.decode(t.subarray(e,r))}function Lr(t,e,r,n,o){let i=r+n;He(t,e,i);let s=new h(u.string,rm(t,e+r,e+i),i);return o.retainStringBytes===!0&&(s.byteValue=t.slice(e+r,e+i)),s}function wf(t,e,r,n){return Lr(t,e,1,r,n)}function xf(t,e,r,n){return Lr(t,e,2,se(t,e+1,n),n)}function bf(t,e,r,n){return Lr(t,e,3,ae(t,e+1,n),n)}function Ef(t,e,r,n){return Lr(t,e,5,ce(t,e+1,n),n)}function _f(t,e,r,n){let o=ue(t,e+1,n);if(typeof o=="bigint")throw new Error(`${E} 64-bit integer string lengths not supported`);return Lr(t,e,9,o,n)}var vf=Mt;function Ot(t,e,r,n){return new h(u.array,n,r)}function kf(t,e,r,n){return Ot(t,e,1,r)}function Af(t,e,r,n){return Ot(t,e,2,se(t,e+1,n))}function Tf(t,e,r,n){return Ot(t,e,3,ae(t,e+1,n))}function If(t,e,r,n){return Ot(t,e,5,ce(t,e+1,n))}function Sf(t,e,r,n){let o=ue(t,e+1,n);if(typeof o=="bigint")throw new Error(`${E} 64-bit integer array lengths not supported`);return Ot(t,e,9,o)}function Uf(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${E} indefinite length items not allowed`);return Ot(t,e,1,1/0)}function _o(t,e){j(t,u.array.majorEncoded,e.value)}_o.compareTokens=ge.compareTokens;_o.encodedSize=function(e){return j.encodedSize(e.value)};function Ft(t,e,r,n){return new h(u.map,n,r)}function Nf(t,e,r,n){return Ft(t,e,1,r)}function Cf(t,e,r,n){return Ft(t,e,2,se(t,e+1,n))}function Lf(t,e,r,n){return Ft(t,e,3,ae(t,e+1,n))}function Bf(t,e,r,n){return Ft(t,e,5,ce(t,e+1,n))}function Rf(t,e,r,n){let o=ue(t,e+1,n);if(typeof o=="bigint")throw new Error(`${E} 64-bit integer map lengths not supported`);return Ft(t,e,9,o)}function Pf(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${E} indefinite length items not allowed`);return Ft(t,e,1,1/0)}function vo(t,e){j(t,u.map.majorEncoded,e.value)}vo.compareTokens=ge.compareTokens;vo.encodedSize=function(e){return j.encodedSize(e.value)};function Df(t,e,r,n){return new h(u.tag,r,1)}function $f(t,e,r,n){return new h(u.tag,se(t,e+1,n),2)}function Mf(t,e,r,n){return new h(u.tag,ae(t,e+1,n),3)}function Of(t,e,r,n){return new h(u.tag,ce(t,e+1,n),5)}function Ff(t,e,r,n){return new h(u.tag,ue(t,e+1,n),9)}function ko(t,e){j(t,u.tag.majorEncoded,e.value)}ko.compareTokens=ge.compareTokens;ko.encodedSize=function(e){return j.encodedSize(e.value)};var fs=20,ls=21,ds=22,hs=23;function zf(t,e,r,n){if(n.allowUndefined===!1)throw new Error(`${E} undefined values are not supported`);return n.coerceUndefinedToNull===!0?new h(u.null,null,1):new h(u.undefined,void 0,1)}function jf(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${E} indefinite length items not allowed`);return new h(u.break,void 0,1)}function ps(t,e,r){if(r){if(r.allowNaN===!1&&Number.isNaN(t))throw new Error(`${E} NaN values are not supported`);if(r.allowInfinity===!1&&(t===1/0||t===-1/0))throw new Error(`${E} Infinity values are not supported`)}return new h(u.float,t,e)}function qf(t,e,r,n){return ps(ms(t,e+1),3,n)}function Vf(t,e,r,n){return ps(gs(t,e+1),5,n)}function Hf(t,e,r,n){return ps(Qf(t,e+1),9,n)}function Ao(t,e,r){let n=e.value;if(n===!1)t.push([u.float.majorEncoded|fs]);else if(n===!0)t.push([u.float.majorEncoded|ls]);else if(n===null)t.push([u.float.majorEncoded|ds]);else if(n===void 0)t.push([u.float.majorEncoded|hs]);else{let o,i=!1;(!r||r.float64!==!0)&&(Wf(n),o=ms(Se,1),n===o||Number.isNaN(n)?(Se[0]=249,t.push(Se.slice(0,3)),i=!0):(Gf(n),o=gs(Se,1),n===o&&(Se[0]=250,t.push(Se.slice(0,5)),i=!0))),i||(am(n),o=Qf(Se,1),Se[0]=251,t.push(Se.slice(0,9)))}}Ao.encodedSize=function(e,r){let n=e.value;if(n===!1||n===!0||n===null||n===void 0)return 1;if(!r||r.float64!==!0){Wf(n);let o=ms(Se,1);if(n===o||Number.isNaN(n))return 3;if(Gf(n),o=gs(Se,1),n===o)return 5}return 9};var Kf=new ArrayBuffer(9),ye=new DataView(Kf,1),Se=new Uint8Array(Kf,0);function Wf(t){if(t===1/0)ye.setUint16(0,31744,!1);else if(t===-1/0)ye.setUint16(0,64512,!1);else if(Number.isNaN(t))ye.setUint16(0,32256,!1);else{ye.setFloat32(0,t);let e=ye.getUint32(0),r=(e&2139095040)>>23,n=e&8388607;if(r===255)ye.setUint16(0,31744,!1);else if(r===0)ye.setUint16(0,(e&2147483648)>>16|n>>13,!1);else{let o=r-127;o<-24?ye.setUint16(0,0):o<-14?ye.setUint16(0,(e&2147483648)>>16|1<<24+o,!1):ye.setUint16(0,(e&2147483648)>>16|o+15<<10|n>>13,!1)}}}function ms(t,e){if(t.length-e<2)throw new Error(`${E} not enough data for float16`);let r=(t[e]<<8)+t[e+1];if(r===31744)return 1/0;if(r===64512)return-1/0;if(r===32256)return NaN;let n=r>>10&31,o=r&1023,i;return n===0?i=o*2**-24:n!==31?i=(o+1024)*2**(n-25):i=o===0?1/0:NaN,r&32768?-i:i}function Gf(t){ye.setFloat32(0,t,!1)}function gs(t,e){if(t.length-e<4)throw new Error(`${E} not enough data for float32`);let r=(t.byteOffset||0)+e;return new DataView(t.buffer,r,4).getFloat32(0,!1)}function am(t){ye.setFloat64(0,t,!1)}function Qf(t,e){if(t.length-e<8)throw new Error(`${E} not enough data for float64`);let r=(t.byteOffset||0)+e;return new DataView(t.buffer,r,8).getFloat64(0,!1)}Ao.compareTokens=ge.compareTokens;function C(t,e,r){throw new Error(`${E} encountered invalid minor (${r}) for major ${t[e]>>>5}`)}function To(t){return()=>{throw new Error(`${E} ${t}`)}}var w=[];for(let t=0;t<=23;t++)w[t]=C;w[24]=rf;w[25]=nf;w[26]=of;w[27]=sf;w[28]=C;w[29]=C;w[30]=C;w[31]=C;for(let t=32;t<=55;t++)w[t]=C;w[56]=af;w[57]=cf;w[58]=uf;w[59]=lf;w[60]=C;w[61]=C;w[62]=C;w[63]=C;for(let t=64;t<=87;t++)w[t]=df;w[88]=hf;w[89]=pf;w[90]=mf;w[91]=gf;w[92]=C;w[93]=C;w[94]=C;w[95]=To("indefinite length bytes/strings are not supported");for(let t=96;t<=119;t++)w[t]=wf;w[120]=xf;w[121]=bf;w[122]=Ef;w[123]=_f;w[124]=C;w[125]=C;w[126]=C;w[127]=To("indefinite length bytes/strings are not supported");for(let t=128;t<=151;t++)w[t]=kf;w[152]=Af;w[153]=Tf;w[154]=If;w[155]=Sf;w[156]=C;w[157]=C;w[158]=C;w[159]=Uf;for(let t=160;t<=183;t++)w[t]=Nf;w[184]=Cf;w[185]=Lf;w[186]=Bf;w[187]=Rf;w[188]=C;w[189]=C;w[190]=C;w[191]=Pf;for(let t=192;t<=215;t++)w[t]=Df;w[216]=$f;w[217]=Mf;w[218]=Of;w[219]=Ff;w[220]=C;w[221]=C;w[222]=C;w[223]=C;for(let t=224;t<=243;t++)w[t]=To("simple values are not supported");w[244]=C;w[245]=C;w[246]=C;w[247]=zf;w[248]=To("simple values are not supported");w[249]=qf;w[250]=Vf;w[251]=Hf;w[252]=C;w[253]=C;w[254]=C;w[255]=jf;var Ue=[];for(let t=0;t<24;t++)Ue[t]=new h(u.uint,t,1);for(let t=-1;t>=-24;t--)Ue[31-t]=new h(u.negint,t,1);Ue[64]=new h(u.bytes,new Uint8Array(0),1);Ue[96]=new h(u.string,"",1);Ue[128]=new h(u.array,0,1);Ue[160]=new h(u.map,0,1);Ue[244]=new h(u.false,!1,1);Ue[245]=new h(u.true,!0,1);Ue[246]=new h(u.null,null,1);function Jf(t){switch(t.type){case u.false:return De([244]);case u.true:return De([245]);case u.null:return De([246]);case u.bytes:return t.value.length?void 0:De([64]);case u.string:return t.value===""?De([96]):void 0;case u.array:return t.value===0?De([128]):void 0;case u.map:return t.value===0?De([160]):void 0;case u.uint:return t.value<24?De([Number(t.value)]):void 0;case u.negint:if(t.value>=-24)return De([31-Number(t.value)])}}var Xf=Object.freeze({float64:!0,mapSorter:hm,quickEncodeToken:Jf});function um(){let t=[];return t[u.uint.major]=ge,t[u.negint.major]=bo,t[u.bytes.major]=Mt,t[u.string.major]=vf,t[u.array.major]=_o,t[u.map.major]=vo,t[u.tag.major]=ko,t[u.float.major]=Ao,t}var fm=um(),lm=new Ur,Io=class t{constructor(e,r){this.obj=e,this.parent=r}includes(e){let r=this;do if(r.obj===e)return!0;while(r=r.parent);return!1}static createCheck(e,r){if(e&&e.includes(r))throw new Error(`${Ve} object contains circular references`);return new t(r,e)}},tt={null:new h(u.null,null),undefined:new h(u.undefined,void 0),true:new h(u.true,!0),false:new h(u.false,!1),emptyArray:new h(u.array,0),emptyMap:new h(u.map,0)},rt={number(t,e,r,n){return!Number.isInteger(t)||!Number.isSafeInteger(t)?new h(u.float,t):t>=0?new h(u.uint,t):new h(u.negint,t)},bigint(t,e,r,n){return t>=BigInt(0)?new h(u.uint,t):new h(u.negint,t)},Uint8Array(t,e,r,n){return new h(u.bytes,t)},string(t,e,r,n){return new h(u.string,t)},boolean(t,e,r,n){return t?tt.true:tt.false},null(t,e,r,n){return tt.null},undefined(t,e,r,n){return tt.undefined},ArrayBuffer(t,e,r,n){return new h(u.bytes,new Uint8Array(t))},DataView(t,e,r,n){return new h(u.bytes,new Uint8Array(t.buffer,t.byteOffset,t.byteLength))},Array(t,e,r,n){if(!t.length)return r.addBreakTokens===!0?[tt.emptyArray,new h(u.break)]:tt.emptyArray;n=Io.createCheck(n,t);let o=[],i=0;for(let s of t)o[i++]=zt(s,r,n);return r.addBreakTokens?[new h(u.array,t.length),o,new h(u.break)]:[new h(u.array,t.length),o]},Object(t,e,r,n){let o=e!=="Object",i=o?t.keys():Object.keys(t),s=o?t.size:i.length,a;if(s){a=new Array(s),n=Io.createCheck(n,t);let c=!o&&r.ignoreUndefinedProperties,l=0;for(let p of i){let m=o?t.get(p):t[p];c&&m===void 0||(a[l++]=[zt(p,r,n),zt(m,r,n)])}l<s&&(a.length=l)}return a?.length?(dm(a,r),r.addBreakTokens?[new h(u.map,a.length),a,new h(u.break)]:[new h(u.map,a.length),a]):r.addBreakTokens===!0?[tt.emptyMap,new h(u.break)]:tt.emptyMap},Tagged(t,e,r,n){return[new h(u.tag,t.tag),zt(t.value,r,n)]}};rt.Map=rt.Object;rt.Buffer=rt.Uint8Array;for(let t of"Uint8Clamped Uint16 Uint32 Int8 Int16 Int32 BigUint64 BigInt64 Float32 Float64".split(" "))rt[`${t}Array`]=rt.DataView;function zt(t,e={},r){let n=Qu(t),o=e&&e.typeEncoders&&e.typeEncoders[n]||rt[n];if(typeof o=="function"){let s=o(t,n,e,r);if(s!=null)return s}let i=rt[n];if(!i)throw new Error(`${Ve} unsupported type: ${n}`);return i(t,n,e,r)}function dm(t,e){e.mapSorter&&t.sort(e.mapSorter)}function hm(t,e){if(t[0]instanceof h&&e[0]instanceof h){let r=t[0],n=e[0];return r._keyBytes||(r._keyBytes=Yf(r.value)),n._keyBytes||(n._keyBytes=Yf(n.value)),wo(r._keyBytes,n._keyBytes)}throw new Error("rfc8949MapSorter: complex key types are not supported yet")}function Yf(t){return ys(t,fm,Xf)}function Zf(t,e,r,n){if(Array.isArray(e))for(let o of e)Zf(t,o,r,n);else r[e.type.major](t,e,n)}var f1=u.uint.majorEncoded,l1=u.negint.majorEncoded,d1=u.bytes.majorEncoded,h1=u.string.majorEncoded,p1=u.array.majorEncoded,m1=u.float.majorEncoded|fs,g1=u.float.majorEncoded|ls,y1=u.float.majorEncoded|ds,w1=u.float.majorEncoded|hs,x1=BigInt(-1),b1=BigInt(1);function ys(t,e,r,n){let o=n instanceof Uint8Array,i=o?new xo(n):lm,s=zt(t,r);if(!Array.isArray(s)&&r.quickEncodeToken){let a=r.quickEncodeToken(s);if(a)return o?(i.push(a),i.toBytes()):a;let c=e[s.type.major];if(c.encodedSize){let l=c.encodedSize(s,r);if(o||(i=new Ur(l)),c(i,s,r),i.chunks.length!==1)throw new Error(`Unexpected error: pre-calculated length for ${s} was wrong`);return o?i.toBytes():mt(i.chunks[0])}}return i.reset(),Zf(i,s,e,r),i.toBytes(!0)}var pm={strict:!1,allowIndefinite:!0,allowUndefined:!0,allowBigInt:!0},So=class{constructor(e,r={}){this._pos=0,this.data=e,this.options=r}pos(){return this._pos}done(){return this._pos>=this.data.length}next(){let e=this.data[this._pos],r=Ue[e];if(r===void 0){let n=w[e];if(!n)throw new Error(`${E} no decoder for major type ${e>>>5} (byte 0x${e.toString(16).padStart(2,"0")})`);let o=e&31;r=n(this.data,this._pos,o,this.options)}return this._pos+=r.encodedLength,r}},nt=Symbol.for("DONE"),jt=Symbol.for("BREAK");function mm(t,e,r){let n=[];for(let o=0;o<t.value;o++){let i=ot(e,r);if(i===jt){if(t.value===1/0)break;throw new Error(`${E} got unexpected break to lengthed array`)}if(i===nt)throw new Error(`${E} found array but not enough entries (got ${o}, expected ${t.value})`);n[o]=i}return n}function gm(t,e,r){let n=r.useMaps===!0,o=r.rejectDuplicateMapKeys===!0,i=n?void 0:{},s=n?new Map:void 0;for(let a=0;a<t.value;a++){let c=ot(e,r);if(c===jt){if(t.value===1/0)break;throw new Error(`${E} got unexpected break to lengthed map`)}if(c===nt)throw new Error(`${E} found map but not enough entries (got ${a} [no key], expected ${t.value})`);if(!n&&typeof c!="string")throw new Error(`${E} non-string keys not supported (got ${typeof c})`);if(o&&(n&&s.has(c)||!n&&Object.hasOwn(i,c)))throw new Error(`${E} found repeat map key "${c}"`);let l=ot(e,r);if(l===nt)throw new Error(`${E} found map but not enough entries (got ${a} [no value], expected ${t.value})`);n?s.set(c,l):i[c]=l}return n?s:i}function*ym(t,e,r){for(let n=0;n<t.value;n++){let o=ot(e,r);if(o===jt){if(t.value===1/0)break;throw new Error(`${E} got unexpected break to lengthed map`)}if(o===nt)throw new Error(`${E} found map but not enough entries (got ${n} [no key], expected ${t.value})`);let i=ot(e,r);if(i===nt)throw new Error(`${E} found map but not enough entries (got ${n} [no value], expected ${t.value})`);yield[o,i]}}function wm(t,e){let r=!1,n=function(){if(r)throw new Error(`${E} tag decode() may only be called once`);r=!0;let o=ot(t,e);if(o===nt)throw new Error(`${E} tag content missing`);if(o===jt)throw new Error(`${E} got unexpected break in tag content`);return o};return n.entries=function(){if(r)throw new Error(`${E} tag decode() may only be called once`);r=!0;let o=t.next();if(!u.equals(o.type,u.map))throw new Error(`${E} entries() requires map content, got ${o.type.name}`);let i=[];for(let s of ym(o,t,e))i.push(s);return i},Object.defineProperty(n,"_called",{get(){return r},enumerable:!1}),n}function ot(t,e){if(t.done())return nt;let r=t.next();if(u.equals(r.type,u.break))return jt;if(r.type.terminal)return r.value;if(u.equals(r.type,u.array))return mm(r,t,e);if(u.equals(r.type,u.map))return gm(r,t,e);if(u.equals(r.type,u.tag)){if(e.tags&&typeof e.tags[r.value]=="function"){let n=wm(t,e),o=e.tags[r.value](n);if(!n._called)throw new Error(`${E} tag decoder must call decode() or entries()`);return o}throw new Error(`${E} tag not supported (${r.value})`)}throw new Error("unsupported")}function ws(t,e){if(!(t instanceof Uint8Array))throw new Error(`${E} data to decode must be a Uint8Array`);e=Object.assign({},pm,e);let r=mt(t),n=e.tokenizer||new So(r,e),o=ot(n,e);if(o===nt)throw new Error(`${E} did not find any content to decode`);if(o===jt)throw new Error(`${E} got unexpected break`);return[o,t.subarray(n.pos())]}function xs(t,e){let[r,n]=ws(t,e);if(n.length>0)throw new Error(`${E} too many terminals, data makes no sense`);return r}var Uo=class t{constructor(e,r){if(typeof e!="number"||!Number.isInteger(e)||e<0)throw new TypeError("Tagged: tag must be a non-negative integer");this.tag=e,this.value=r}static decoder(e){return r=>new t(e,r())}static preserve(...e){let r={};for(let n of e)r[n]=t.decoder(n);return r}};Object.defineProperty(Uo.prototype,Symbol.toStringTag,{value:"Tagged"});var bs=class extends Array{constructor(){super(),this.inRecursive=[]}prefix(e){let r=this.inRecursive[this.inRecursive.length-1];r&&(u.equals(r.type,u.array)&&(r.elements++,r.elements!==1&&e.push([44])),u.equals(r.type,u.map)&&(r.elements++,r.elements!==1&&(r.elements%2===1?e.push([44]):e.push([58]))))}[u.uint.major](e,r){this.prefix(e);let n=String(r.value),o=[];for(let i=0;i<n.length;i++)o[i]=n.charCodeAt(i);e.push(o)}[u.negint.major](e,r){this[u.uint.major](e,r)}[u.bytes.major](e,r){throw new Error(`${Ve} unsupported type: Uint8Array`)}[u.string.major](e,r){this.prefix(e);let n=Sr(JSON.stringify(r.value));e.push(n.length>32?mt(n):n)}[u.array.major](e,r){this.prefix(e),this.inRecursive.push({type:u.array,elements:0}),e.push([91])}[u.map.major](e,r){this.prefix(e),this.inRecursive.push({type:u.map,elements:0}),e.push([123])}[u.tag.major](e,r){}[u.float.major](e,r){if(r.type.name==="break"){let s=this.inRecursive.pop();if(s){if(u.equals(s.type,u.array))e.push([93]);else if(u.equals(s.type,u.map))e.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(`${Ve} unsupported type: undefined`);if(this.prefix(e),r.type.name==="true"){e.push([116,114,117,101]);return}else if(r.type.name==="false"){e.push([102,97,108,115,101]);return}else if(r.type.name==="null"){e.push([110,117,108,108]);return}let n=String(r.value),o=[],i=!1;for(let s=0;s<n.length;s++)o[s]=n.charCodeAt(s),!i&&(o[s]===46||o[s]===101||o[s]===69)&&(i=!0);i||(o.push(46),o.push(48)),e.push(o)}};function xm(t,e){if(Array.isArray(t[0])||Array.isArray(e[0]))throw new Error(`${Ve} complex map keys are not supported`);let r=t[0],n=e[0];if(r.type!==u.string||n.type!==u.string)throw new Error(`${Ve} non-string map keys are not supported`);if(r<n)return-1;if(r>n)return 1;throw new Error(`${Ve} unexpected duplicate map keys, this is not supported`)}var bm={addBreakTokens:!0,mapSorter:xm};function Es(t,e){return e=Object.assign({},bm,e),ys(t,new bs,e)}var qt=class{constructor(e,r={}){this._pos=0,this.data=e,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 e=this.ch();for(;e===32||e===9||e===13||e===10;)e=this.data[++this._pos]}expect(e){if(this.data.length-this._pos<e.length)throw new Error(`${E} unexpected end of input at position ${this._pos}`);for(let r=0;r<e.length;r++)if(this.data[this._pos++]!==e[r])throw new Error(`${E} unexpected token at position ${this._pos}, expected to find '${String.fromCharCode(...e)}'`)}parseNumber(){let e=this._pos,r=!1,n=!1,o=a=>{for(;!this.done();){let c=this.ch();if(a.includes(c))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 h(u.uint,0,this._pos-e);if(o([48,49,50,51,52,53,54,55,56,57]),r&&this._pos===e+1)throw new Error(`${E} unexpected token at position ${this._pos}`);if(!this.done()&&this.ch()===46){if(n)throw new Error(`${E} 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 i=String.fromCharCode.apply(null,this.data.subarray(e,this._pos)),s=parseFloat(i);return n?new h(u.float,s,this._pos-e):this.options.allowBigInt!==!0||Number.isSafeInteger(s)?new h(s>=0?u.uint:u.negint,s,this._pos-e):new h(s>=0?u.uint:u.negint,BigInt(i),this._pos-e)}parseString(){if(this.ch()!==34)throw new Error(`${E} unexpected character at position ${this._pos}; this shouldn't happen`);this._pos++;for(let i=this._pos,s=0;i<this.data.length&&s<65536;i++,s++){let a=this.data[i];if(a===92||a<32||a>=128)break;if(a===34){let c=String.fromCharCode.apply(null,this.data.subarray(this._pos,i));return this._pos=i+1,new h(u.string,c,s)}}let e=this._pos,r=[],n=()=>{if(this._pos+4>=this.data.length)throw new Error(`${E} unexpected end of unicode escape sequence at position ${this._pos}`);let i=0;for(let s=0;s<4;s++){let a=this.ch();if(a>=48&&a<=57)a-=48;else if(a>=97&&a<=102)a=a-97+10;else if(a>=65&&a<=70)a=a-65+10;else throw new Error(`${E} unexpected unicode escape character at position ${this._pos}`);i=i*16+a,this._pos++}return i},o=()=>{let i=this.ch(),s=null,a=i>239?4:i>223?3:i>191?2:1;if(this._pos+a>this.data.length)throw new Error(`${E} unexpected unicode sequence at position ${this._pos}`);let c,l,p,m;switch(a){case 1:i<128&&(s=i);break;case 2:c=this.data[this._pos+1],(c&192)===128&&(m=(i&31)<<6|c&63,m>127&&(s=m));break;case 3:c=this.data[this._pos+1],l=this.data[this._pos+2],(c&192)===128&&(l&192)===128&&(m=(i&15)<<12|(c&63)<<6|l&63,m>2047&&(m<55296||m>57343)&&(s=m));break;case 4:c=this.data[this._pos+1],l=this.data[this._pos+2],p=this.data[this._pos+3],(c&192)===128&&(l&192)===128&&(p&192)===128&&(m=(i&15)<<18|(c&63)<<12|(l&63)<<6|p&63,m>65535&&m<1114112&&(s=m))}s===null?(s=65533,a=1):s>65535&&(s-=65536,r.push(s>>>10&1023|55296),s=56320|s&1023),r.push(s),this._pos+=a};for(;!this.done();){let i=this.ch(),s;switch(i){case 92:if(this._pos++,this.done())throw new Error(`${E} unexpected string termination at position ${this._pos}`);switch(s=this.ch(),this._pos++,s){case 34:case 39:case 92:case 47:r.push(s);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(`${E} unexpected string escape character at position ${this._pos}`)}break;case 34:return this._pos++,new h(u.string,tf(r),this._pos-e);default:if(i<32)throw new Error(`${E} invalid control character at position ${this._pos}`);i<128?(r.push(i),this._pos++):o()}}throw new Error(`${E} unexpected end of string at position ${this._pos}`)}parseValue(){switch(this.ch()){case 123:return this.modeStack.push("obj-start"),this._pos++,new h(u.map,1/0,1);case 91:return this.modeStack.push("array-start"),this._pos++,new h(u.array,1/0,1);case 34:return this.parseString();case 110:return this.expect([110,117,108,108]),new h(u.null,null,4);case 102:return this.expect([102,97,108,115,101]),new h(u.false,!1,5);case 116:return this.expect([116,114,117,101]),new h(u.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(`${E} 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 h(u.break,void 0,1);if(this.ch()!==44)throw new Error(`${E} 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 h(u.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 h(u.break,void 0,1);if(this.ch()!==44)throw new Error(`${E} 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 h(u.break,void 0,1);let e=this.parseString();if(this.skipWhitespace(),this.ch()!==58)throw new Error(`${E} 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"),e}case"obj-value":return this.modeStack.pop(),this.modeStack.push("obj-key"),this.skipWhitespace(),this.parseValue();default:throw new Error(`${E} unexpected parse state at position ${this._pos}; this shouldn't happen`)}}};function _s(t,e){return e=Object.assign({tokenizer:new qt(t,e)},e),xs(t,e)}function _m(t){return t instanceof ArrayBuffer?new Uint8Array(t,0,t.byteLength):t}function vm(t){if(t.asCID!==t&&t["/"]!==t.bytes)return null;let e=L.asCID(t);if(!e)return null;let r=e.toString();return[new h(u.map,1/0,1),new h(u.string,"/",1),new h(u.string,r,r.length),new h(u.break,void 0,1)]}function No(t){let e=Et.encode(t).slice(1);return[new h(u.map,1/0,1),new h(u.string,"/",1),new h(u.map,1/0,1),new h(u.string,"bytes",5),new h(u.string,e,e.length),new h(u.break,void 0,1),new h(u.break,void 0,1)]}function Ne(t){return No(new Uint8Array(t.buffer,t.byteOffset,t.byteLength))}function km(t){return No(new Uint8Array(t))}function Am(){throw new Error("`undefined` is not supported by the IPLD Data Model and cannot be encoded")}function Tm(t){if(Number.isNaN(t))throw new Error("`NaN` is not supported by the IPLD Data Model and cannot be encoded");if(t===1/0||t===-1/0)throw new Error("`Infinity` and `-Infinity` is not supported by the IPLD Data Model and cannot be encoded");return null}var Im={typeEncoders:{Object:vm,Buffer:No,Uint8Array:No,Int8Array:Ne,Uint16Array:Ne,Int16Array:Ne,Uint32Array:Ne,Int32Array:Ne,Float32Array:Ne,Float64Array:Ne,Uint8ClampedArray:Ne,BigInt64Array:Ne,BigUint64Array:Ne,DataView:Ne,ArrayBuffer:km,undefined:Am,number:Tm}},vs=class extends qt{constructor(e,r){super(e,r),this.tokenBuffer=[]}done(){return this.tokenBuffer.length===0&&super.done()}_next(){return this.tokenBuffer.length>0?this.tokenBuffer.pop():super.next()}next(){let e=this._next();if(u.equals(e.type,u.map)){let r=this._next();if(u.equals(r.type,u.string)&&r.value==="/"){let n=this._next();if(u.equals(n.type,u.string)){let o=this._next();if(!u.equals(o.type,u.break))throw new Error("Invalid encoded CID form");return this.tokenBuffer.push(n),new h(u.tag,42,0)}if(u.equals(n.type,u.map)){let o=this._next();if(u.equals(o.type,u.string)&&o.value==="bytes"){let i=this._next();if(u.equals(i.type,u.string)){for(let a=0;a<2;a++){let c=this._next();if(!u.equals(c.type,u.break))throw new Error("Invalid encoded Bytes form")}let s=Et.decode(`m${i.value}`);return new h(u.bytes,s,i.value.length)}this.tokenBuffer.push(i)}this.tokenBuffer.push(o)}this.tokenBuffer.push(n)}this.tokenBuffer.push(r)}return e}},el={allowIndefinite:!1,allowUndefined:!1,allowNaN:!1,allowInfinity:!1,allowBigInt:!0,strict:!0,useMaps:!1,rejectDuplicateMapKeys:!0,tags:{42:t=>L.parse(t())}},Sm="dag-json",ks=297,tl=t=>Es(t,Im),rl=t=>{let e=_m(t),r=Object.assign(el,{tokenizer:new vs(e,el)});return _s(e,r)},Um=t=>Nm.decode(tl(t));var Nm=new TextDecoder,Cm=t=>rl(Lm.encode(t)),Lm=new TextEncoder;var Cs={};M(Cs,{code:()=>Ns,createLink:()=>dl,createNode:()=>ll,decode:()=>Hm,encode:()=>Vm,name:()=>qm,prepare:()=>Ss,validate:()=>Us});var Bm=new TextDecoder;function Ts(t,e){let r=0;for(let n=0;;n+=7){if(n>=64)throw new Error("protobuf: varint overflow");if(e>=t.length)throw new Error("protobuf: unexpected end of data");let o=t[e++];if(r+=n<28?(o&127)<<n:(o&127)*2**n,o<128)break}return[r,e]}function Co(t,e){let r;[r,e]=Ts(t,e);let n=e+r;if(r<0||n<0)throw new Error("protobuf: invalid length");if(n>t.length)throw new Error("protobuf: unexpected end of data");return[t.subarray(e,n),n]}function nl(t,e){let r;return[r,e]=Ts(t,e),[r&7,r>>3,e]}function Rm(t){let e={},r=t.length,n=0;for(;n<r;){let o,i;if([o,i,n]=nl(t,n),i===1){if(e.Hash)throw new Error("protobuf: (PBLink) duplicate Hash section");if(o!==2)throw new Error(`protobuf: (PBLink) wrong wireType (${o}) for Hash`);if(e.Name!==void 0)throw new Error("protobuf: (PBLink) invalid order, found Name before Hash");if(e.Tsize!==void 0)throw new Error("protobuf: (PBLink) invalid order, found Tsize before Hash");[e.Hash,n]=Co(t,n)}else if(i===2){if(e.Name!==void 0)throw new Error("protobuf: (PBLink) duplicate Name section");if(o!==2)throw new Error(`protobuf: (PBLink) wrong wireType (${o}) for Name`);if(e.Tsize!==void 0)throw new Error("protobuf: (PBLink) invalid order, found Tsize before Name");let s;[s,n]=Co(t,n),e.Name=Bm.decode(s)}else if(i===3){if(e.Tsize!==void 0)throw new Error("protobuf: (PBLink) duplicate Tsize section");if(o!==0)throw new Error(`protobuf: (PBLink) wrong wireType (${o}) for Tsize`);[e.Tsize,n]=Ts(t,n)}else throw new Error(`protobuf: (PBLink) invalid fieldNumber, expected 1, 2 or 3, got ${i}`)}if(n>r)throw new Error("protobuf: (PBLink) unexpected end of data");return e}function ol(t){let e=t.length,r=0,n,o=!1,i;for(;r<e;){let a,c;if([a,c,r]=nl(t,r),a!==2)throw new Error(`protobuf: (PBNode) invalid wireType, expected 2, got ${a}`);if(c===1){if(i)throw new Error("protobuf: (PBNode) duplicate Data section");[i,r]=Co(t,r),n&&(o=!0)}else if(c===2){if(o)throw new Error("protobuf: (PBNode) duplicate Links section");n||(n=[]);let l;[l,r]=Co(t,r),n.push(Rm(l))}else throw new Error(`protobuf: (PBNode) invalid fieldNumber, expected 1 or 2, got ${c}`)}if(r>e)throw new Error("protobuf: (PBNode) unexpected end of data");let s={};return i&&(s.Data=i),s.Links=n||[],s}var sl=new TextEncoder,il=2**32,Pm=2**31;function Dm(t,e){let r=e.length;if(typeof t.Tsize=="number"){if(t.Tsize<0)throw new Error("Tsize cannot be negative");if(!Number.isSafeInteger(t.Tsize))throw new Error("Tsize too large for encoding");r=Br(e,r,t.Tsize)-1,e[r]=24}if(typeof t.Name=="string"){let n=sl.encode(t.Name);r-=n.length,e.set(n,r),r=Br(e,r,n.length)-1,e[r]=18}return t.Hash&&(r-=t.Hash.length,e.set(t.Hash,r),r=Br(e,r,t.Hash.length)-1,e[r]=10),e.length-r}function al(t){let e=Mm(t),r=new Uint8Array(e),n=e;if(t.Data&&(n-=t.Data.length,r.set(t.Data,n),n=Br(r,n,t.Data.length)-1,r[n]=10),t.Links)for(let o=t.Links.length-1;o>=0;o--){let i=Dm(t.Links[o],r.subarray(0,n));n-=i,n=Br(r,n,i)-1,r[n]=18}return r}function $m(t){let e=0;if(t.Hash){let r=t.Hash.length;e+=1+r+Vt(r)}if(typeof t.Name=="string"){let r=sl.encode(t.Name).length;e+=1+r+Vt(r)}return typeof t.Tsize=="number"&&(e+=1+Vt(t.Tsize)),e}function Mm(t){let e=0;if(t.Data){let r=t.Data.length;e+=1+r+Vt(r)}if(t.Links)for(let r of t.Links){let n=$m(r);e+=1+n+Vt(n)}return e}function Br(t,e,r){e-=Vt(r);let n=e;for(;r>=Pm;)t[e++]=r&127|128,r/=128;for(;r>=128;)t[e++]=r&127|128,r>>>=7;return t[e]=r,n}function Vt(t){return t%2===0&&t++,Math.floor((Om(t)+6)/7)}function Om(t){let e=0;return t>=il&&(t=Math.floor(t/il),e=32),t>=65536&&(t>>>=16,e+=16),t>=256&&(t>>>=8,e+=8),e+Fm[t]}var Fm=[0,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8];var zm=["Data","Links"],jm=["Hash","Name","Tsize"],Is=new TextEncoder;function ul(t,e){if(t===e)return 0;let r=t.Name?Is.encode(t.Name):[],n=e.Name?Is.encode(e.Name):[],o=r.length,i=n.length;for(let s=0,a=Math.min(o,i);s<a;++s)if(r[s]!==n[s]){o=r[s],i=n[s];break}return o<i?-1:i<o?1:0}function cl(t,e){return!Object.keys(t).some(r=>!e.includes(r))}function fl(t){if(typeof t.asCID=="object"){let r=L.asCID(t);if(!r)throw new TypeError("Invalid DAG-PB form");return{Hash:r}}if(typeof t!="object"||Array.isArray(t))throw new TypeError("Invalid DAG-PB form");let e={};if(t.Hash){let r=L.asCID(t.Hash);try{r||(typeof t.Hash=="string"?r=L.parse(t.Hash):t.Hash instanceof Uint8Array&&(r=L.decode(t.Hash)))}catch(n){throw new TypeError(`Invalid DAG-PB form: ${n.message}`)}r&&(e.Hash=r)}if(!e.Hash)throw new TypeError("Invalid DAG-PB form");return typeof t.Name=="string"&&(e.Name=t.Name),typeof t.Tsize=="number"&&(e.Tsize=t.Tsize),e}function Ss(t){if((t instanceof Uint8Array||typeof t=="string")&&(t={Data:t}),typeof t!="object"||Array.isArray(t))throw new TypeError("Invalid DAG-PB form");let e={};if(t.Data!==void 0)if(typeof t.Data=="string")e.Data=Is.encode(t.Data);else if(t.Data instanceof Uint8Array)e.Data=t.Data;else throw new TypeError("Invalid DAG-PB form");if(t.Links!==void 0)if(Array.isArray(t.Links))e.Links=t.Links.map(fl),e.Links.sort(ul);else throw new TypeError("Invalid DAG-PB form");else e.Links=[];return e}function Us(t){if(!t||typeof t!="object"||Array.isArray(t)||t instanceof Uint8Array||t["/"]&&t["/"]===t.bytes)throw new TypeError("Invalid DAG-PB form");if(!cl(t,zm))throw new TypeError("Invalid DAG-PB form (extraneous properties)");if(t.Data!==void 0&&!(t.Data instanceof Uint8Array))throw new TypeError("Invalid DAG-PB form (Data must be bytes)");if(!Array.isArray(t.Links))throw new TypeError("Invalid DAG-PB form (Links must be a list)");for(let e=0;e<t.Links.length;e++){let r=t.Links[e];if(!r||typeof r!="object"||Array.isArray(r)||r instanceof Uint8Array||r["/"]&&r["/"]===r.bytes)throw new TypeError("Invalid DAG-PB form (bad link)");if(!cl(r,jm))throw new TypeError("Invalid DAG-PB form (extraneous properties on link)");if(r.Hash===void 0)throw new TypeError("Invalid DAG-PB form (link must have a Hash)");if(r.Hash==null||!r.Hash["/"]||r.Hash["/"]!==r.Hash.bytes)throw new TypeError("Invalid DAG-PB form (link Hash must be a CID)");if(r.Name!==void 0&&typeof r.Name!="string")throw new TypeError("Invalid DAG-PB form (link Name must be a string)");if(r.Tsize!==void 0){if(typeof r.Tsize!="number"||r.Tsize%1!==0)throw new TypeError("Invalid DAG-PB form (link Tsize must be an integer)");if(r.Tsize<0)throw new TypeError("Invalid DAG-PB form (link Tsize cannot be negative)")}if(e>0&&ul(r,t.Links[e-1])===-1)throw new TypeError("Invalid DAG-PB form (links must be sorted by Name bytes)")}}function ll(t,e=[]){return Ss({Data:t,Links:e})}function dl(t,e,r){return fl({Hash:r,Name:t,Tsize:e})}function hl(t){return t instanceof ArrayBuffer?new Uint8Array(t,0,t.byteLength):t}var qm="dag-pb",Ns=112;function Vm(t){Us(t);let e={};return t.Links&&(e.Links=t.Links.map(r=>{let n={};return r.Hash&&(n.Hash=r.Hash.bytes),r.Name!==void 0&&(n.Name=r.Name),r.Tsize!==void 0&&(n.Tsize=r.Tsize),n})),t.Data&&(e.Data=t.Data),al(e)}function Hm(t){let e=hl(t),r=ol(e),n={};return r.Data&&(n.Data=r.Data),r.Links&&(n.Links=r.Links.map(o=>{let i={};try{i.Hash=L.decode(o.Hash)}catch{}if(!i.Hash)throw new Error("Invalid Hash field found in link, expected CID");return o.Name!==void 0&&(i.Name=o.Name),o.Tsize!==void 0&&(i.Tsize=o.Tsize),i})),n}function Ht(t){return t?.then!=null}function pl(t=[],e){let r={[Ns]:Cs,[ai]:qr,[as]:cs,[ks]:As,[si]:jr};return t.forEach(n=>{r[n.code]=n}),async n=>{let o=r[n];if(o==null&&e!=null){let i=e(n);Ht(i)?o=await i:o=i,r[o.code]=o}if(o!=null)return o;throw new Dn(`Could not load codec for ${n}`)}}function ml(t=[],e){let r={[Kr.code]:Kr,[Wr.code]:Wr,[Hr.code]:Hr};return t.forEach(n=>{r[n.code]=n}),async n=>{let o=r[n];if(o==null&&e!=null){let i=e(n);Ht(i)?o=await i:o=i,r[o.code]=o}if(o!=null)return o;throw new Pn(`No hasher configured for multihash code 0x${n.toString(16)}, please configure one. You can look up which hash this is at https://github.com/multiformats/multicodec/blob/master/table.csv`)}}var Lo=class t extends Error{static name="NotFoundError";static code="ERR_NOT_FOUND";name=t.name;code=t.code;constructor(e="Not Found"){super(e)}};var Bo=class{has(e,r){return Promise.reject(new Error(".has is not implemented"))}put(e,r,n){return Promise.reject(new Error(".put is not implemented"))}async*putMany(e,r){for await(let{cid:n,bytes:o}of e)await this.put(n,o,r),yield n}get(e,r){throw new Error(".get is not implemented")}async*getMany(e,r){for await(let n of e)yield{cid:n,bytes:this.get(n,r)}}delete(e,r){return Promise.reject(new Error(".delete is not implemented"))}async*deleteMany(e,r){for await(let n of e)await this.delete(n,r),yield n}async*getAll(e){throw new Error(".getAll is not implemented")}};var Ro=0,Kt=class extends Error{static name="IdentityHashDigestTooLongError";name="IdentityHashDigestTooLongError"},Po=class extends Bo{child;maxDigestLength;constructor(e,r){super(),this.child=e,this.maxDigestLength=r?.maxDigestLength}put(e,r,n){if(e.multihash.code===Ro){if(this.maxDigestLength!=null&&e.multihash.digest.byteLength>this.maxDigestLength)throw new Kt(`Identity digest too long - ${e.multihash.digest.byteLength} > this.maxDigestLength`);return n?.signal?.throwIfAborted(),e}return this.child==null?(n?.signal?.throwIfAborted(),e):this.child.put(e,r,n)}async*get(e,r){if(e.multihash.code===Ro){if(this.maxDigestLength!=null&&e.multihash.digest.byteLength>this.maxDigestLength)throw new Kt(`Identity digest too long - ${e.multihash.digest.byteLength} > this.maxDigestLength`);r?.signal?.throwIfAborted(),yield e.multihash.digest;return}if(this.child==null)throw r?.signal?.throwIfAborted(),new Lo;yield*this.child.get(e,r)}has(e,r){if(e.multihash.code===Ro){if(this.maxDigestLength!=null&&e.multihash.digest.byteLength>this.maxDigestLength)throw new Kt(`Identity digest too long - ${e.multihash.digest.byteLength} > this.maxDigestLength`);return r?.signal?.throwIfAborted(),!0}return this.child==null?(r?.signal?.throwIfAborted(),!1):this.child.has(e,r)}delete(e,r){if(e.code===Ro){if(this.maxDigestLength!=null&&e.multihash.digest.byteLength>this.maxDigestLength)throw new Kt(`Identity digest too long - ${e.multihash.digest.byteLength} > this.maxDigestLength`);r?.signal?.throwIfAborted();return}if(this.child!=null)return this.child.delete(e,r)}async*getAll(e){this.child!=null&&(yield*this.child.getAll(e)),e?.signal?.throwIfAborted()}};function Km(t){let[e,r]=t[Symbol.asyncIterator]!=null?[t[Symbol.asyncIterator](),Symbol.asyncIterator]:[t[Symbol.iterator](),Symbol.iterator],n=[];return{peek:()=>e.next(),push:o=>{n.push(o)},next:()=>n.length>0?{done:!1,value:n.shift()}:e.next(),[r](){return this}}}var Do=Km;function Wm(t){return t[Symbol.asyncIterator]!=null}function Gm(t,e){let r=0;if(Wm(t))return(async function*(){for await(let c of t)await e(c,r++)&&(yield c)})();let n=Do(t),{value:o,done:i}=n.next();if(i===!0)return(function*(){})();let s=e(o,r++);if(typeof s.then=="function")return(async function*(){await s&&(yield o);for(let c of n)await e(c,r++)&&(yield c)})();let a=e;return(function*(){s===!0&&(yield o);for(let c of n)a(c,r++)&&(yield c)})()}var $o=Gm;function Qm(t){return t[Symbol.asyncIterator]!=null}function gl(t){return t?.then!=null}function Jm(t,e){let r=0;if(Qm(t))return(async function*(){for await(let c of t){let l=e(c,r++);gl(l)&&await l,yield c}})();let n=Do(t),{value:o,done:i}=n.next();if(i===!0)return(function*(){})();let s=e(o,r++);if(typeof s?.then=="function")return(async function*(){await s,yield o;for(let c of n){let l=e(c,r++);gl(l)&&await l,yield c}})();let a=e;return(function*(){yield o;for(let c of n)a(c,r++),yield c})()}var Ls=Jm;var Xm=128,Wt=class{child;getHasher;log;logger;blockBrokers;constructor(e,r={}){this.log=e.logger.forComponent("helia:networked-storage"),this.logger=e.logger,this.blockBrokers=e.blockBrokers,this.child=new Po(e.blockstore,{maxDigestLength:r.maxIdentityHashDigestLength??Xm}),this.getHasher=e.getHasher}async put(e,r,n={}){return await this.child.has(e,n)?(n.onProgress?.(new A("blocks:put:duplicate",e)),e):(n.onProgress?.(new A("blocks:put:providers:notify",e)),await Promise.all(this.blockBrokers.map(async o=>o.announce?.(e,n))),n.onProgress?.(new A("blocks:put:blockstore:put",e)),this.child.put(e,r,n))}async*putMany(e,r={}){let n=$o(e,async({cid:i})=>{let s=await this.child.has(i,r);return s&&r.onProgress?.(new A("blocks:put-many:duplicate",i)),!s}),o=Ls(n,async({cid:i})=>{r.onProgress?.(new A("blocks:put-many:providers:notify",i)),await Promise.all(this.blockBrokers.map(async s=>s.announce?.(i,r)))});r.onProgress?.(new A("blocks:put-many:blockstore:put-many")),yield*this.child.putMany(o,r)}async*get(e,r={}){let n=await this.child.has(e,r),o=r.offline===!0;if(!n){if(o)throw new mr("The block was present in the blockstore and the node is running offline so cannot fetch it");let i=await this.getHasher(e.multihash.code);r?.signal?.throwIfAborted(),r.onProgress?.(new A("blocks:get:providers:get",e));let s=await yl(e,this.blockBrokers,i,{...r,log:this.log});r.onProgress?.(new A("blocks:get:blockstore:put",e)),await this.child.put(e,s,r),r.onProgress?.(new A("blocks:get:providers:notify",e)),await Promise.all(this.blockBrokers.map(async a=>a.announce?.(e,r))),yield s;return}r.onProgress?.(new A("blocks:get:blockstore:get",e)),yield*this.child.get(e,r)}async*getMany(e,r={}){r.onProgress?.(new A("blocks:get-many:blockstore:get-many")),yield*this.child.getMany(Ls(e,async n=>{let o=await this.child.has(n,r),i=r.offline===!0;if(!o){if(i)throw new mr("The block was present in the blockstore and the node is running offline so cannot fetch it");let s=await this.getHasher(n.multihash.code);r?.signal?.throwIfAborted(),r.onProgress?.(new A("blocks:get-many:providers:get",n));let a=await yl(n,this.blockBrokers,s,{...r,log:this.log});r.onProgress?.(new A("blocks:get-many:blockstore:put",n)),await this.child.put(n,a,r),r.onProgress?.(new A("blocks:get-many:providers:notify",n)),await Promise.all(this.blockBrokers.map(async c=>c.announce?.(n,r)))}}))}async delete(e,r={}){r.onProgress?.(new A("blocks:delete:blockstore:delete",e)),await this.child.delete(e,r)}async*deleteMany(e,r={}){r.onProgress?.(new A("blocks:delete-many:blockstore:delete-many")),yield*this.child.deleteMany((async function*(){for await(let n of e)yield n})(),r)}async has(e,r={}){return this.child.has(e,r)}async*getAll(e={}){e.onProgress?.(new A("blocks:get-all:blockstore:get-many")),yield*this.child.getAll(e)}};async function yl(t,e,r,n){let o=eg(t,r),i=new AbortController,s=ve([i.signal,n.signal]);i.signal;let a=[];for(let c of e)Zm(c)&&a.push(c);if(a.length===0)throw new ft(`No block brokers capable of retrieving blocks are configured, the CID ${t} cannot be fetched from the network`);try{return await Promise.any(a.map(async c=>{try{let l=!1,p=await c.retrieve(t,{...n,signal:s,validateFn:async m=>{await o(m),n.signal?.throwIfAborted(),l=!0}});return l||(await o(p),n.signal?.throwIfAborted()),p}catch(l){throw n.log.error("could not retrieve verified block for %c from %s - %e",t,c.name,l),l}}))}catch(c){throw new Cn(c.errors,`Failed to load block for ${t}`)}finally{i.abort(),s.clear()}}function Zm(t){return typeof t.retrieve=="function"}var eg=(t,e)=>{if(e==null)throw new yt(`No hasher configured for multihash code 0x${t.multihash.code.toString(16)}, please configure one. You can look up which hash this is at https://github.com/multiformats/multicodec/blob/master/table.csv`);return async r=>{let n,o=e.digest(r,{truncate:t.multihash.digest.byteLength});if(Ht(o)?n=await o:n=o,!it(n.digest,t.multihash.digest))throw new Mr("Hash of downloaded block did not match multihash from passed CID")}};var Mo=class extends Wt{closeController;constructor(e,r){super(e),this.closeController=new AbortController,this.closeController.signal,this.log=e.logger.forComponent(`helia:session-storage:${r.root}`)}close(){this.closeController.abort()}async addPeer(e,r){await Promise.all(this.blockBrokers.map(n=>n.addPeer(e,r)))}async put(e,r,n={}){let o=ve([this.closeController.signal,n.signal]);try{return await super.put(e,r,{...n,signal:o})}finally{o.clear()}}async*putMany(e,r={}){let n=ve([this.closeController.signal,r.signal]);try{yield*super.putMany(e,{...r,signal:n})}finally{n.clear()}}async*get(e,r={}){let n=ve([this.closeController.signal,r.signal]);try{yield*super.get(e,{...r,signal:n})}finally{n.clear()}}async*getMany(e,r={}){let n=ve([this.closeController.signal,r.signal]);try{yield*super.getMany(e,{...r,signal:n})}finally{n.clear()}}async delete(e,r={}){let n=ve([this.closeController.signal,r.signal]);try{await super.delete(e,{...r,signal:n})}finally{n.clear()}}async*deleteMany(e,r={}){let n=ve([this.closeController.signal,r.signal]);try{yield*super.deleteMany(e,{...r,signal:n})}finally{n.clear()}}async has(e,r={}){let n=ve([this.closeController.signal,r.signal]);try{return await super.has(e,{...r,signal:n})}finally{n.clear()}}async*getAll(e={}){let r=ve([this.closeController.signal,e.signal]);try{yield*super.getAll({...e,signal:r})}finally{r.clear()}}};var Oo=class extends Wt{started;constructor(e,r={}){super(e,r),this.started=!1}isStarted(){return this.started}async start(){await We(this.child,...this.blockBrokers),this.started=!0}async stop(){await Ge(this.child,...this.blockBrokers),this.started=!1}unwrap(){return this.child}createSession(e,r){if(this.blockBrokers.length===0)throw new ft("No block brokers configured");let n=this.blockBrokers.map(o=>o.createSession?.(r)).filter(o=>o!=null);if(n.length===0)throw new ft(`No configured block brokers support sessions - tried ${this.blockBrokers.map(o=>o.name).join(", ")}`);return new Mo({blockstore:this.child,blockBrokers:n,getHasher:this.getHasher,logger:this.logger},{root:e})}};var Fo=class extends le{initialPeerSearchComplete;requests;logName;log;logger;minProviders;maxProviders;providers;evictionFilter;initialProviders;cidPeerFilterSize;constructor(e,r){super(),this.logName=r.name,this.logger=e.logger,this.log=e.logger.forComponent(this.logName),this.requests=new Map,this.minProviders=r.minProviders??1,this.maxProviders=r.maxProviders??5,this.cidPeerFilterSize=r.cidPeerFilterSize??100,this.providers=[],this.evictionFilter=Zr(this.maxProviders),this.initialProviders=[...r.providers??[]]}async retrieve(e,r={}){let n=Et.encode(e.multihash.bytes),o=this.requests.get(n);if(o!=null)return this.log("join existing request for %c",e),o.observers++,o.promise;let i=G(),s={promise:i.promise,observers:1,queryFilter:Zr(this.cidPeerFilterSize)};this.requests.set(n,s);let a=!1;this.initialPeerSearchComplete==null&&(a=!0,this.log=this.logger.forComponent(`${this.logName}:${e}`),this.initialPeerSearchComplete=this.findProviders(e,this.minProviders,r));let c=!1,l=new J({concurrency:this.maxProviders});l.addEventListener("failure",x=>{this.log.error("error querying provider %s, evicting from session - %e",x.detail.job.options.provider,x.detail.error),this.evict(x.detail.job.options.provider)}),l.addEventListener("success",x=>{c=!0,i.resolve(x.detail.result)}),l.addEventListener("idle",()=>{if(c){this.log.trace("session idle, found block");return}if(r.signal?.aborted===!0){this.log.trace("session idle, signal aborted");return}Promise.resolve().then(async()=>{this.log("no session peers had block for for %c, finding new providers",e);for(let x=0;x<this.minProviders&&this.providers.length!==0;x++){let k=this.providers[Math.floor(Math.random()*this.providers.length)];this.evict(k)}await this.findProviders(e,this.minProviders,r),this.log("found new providers re-retrieving %c",e),this.requests.delete(n),i.resolve(await this.retrieve(e,r))}).catch(x=>{this.log.error("could not find new providers for %c - %e",e,x),i.reject(x)})});let p=x=>{let k=this.toFilterKey(x.detail);s.queryFilter.has(k)||(s.queryFilter.add(k),this.emitFoundProviderProgressEvent(e,x.detail,r),l.add(async()=>this.queryProvider(e,x.detail,r),{provider:x.detail}).catch(I=>{r.signal?.aborted!==!0&&this.log.error("error retrieving session block for %c - %e",e,I)}))};if(this.addEventListener("provider",p),a)try{await Oe(this.initialPeerSearchComplete,r.signal),a&&this.log("found initial session peers for %c",e)}catch(x){throw a&&this.log("failed to find initial session peers for %c - %e",e,x),this.requests.delete(n),s.observers>1&&i.reject(x),x}Promise.all([...this.providers].filter(x=>{let k=this.toFilterKey(x),I=s.queryFilter.has(k);return I||s.queryFilter.add(this.toFilterKey(x)),!I}).map(async x=>l.add(async()=>this.queryProvider(e,x,r),{provider:x}))).catch(x=>{r.signal?.aborted!==!0&&this.log.error("error retrieving session block for %c - %e",e,x)});let m=()=>{i.reject(new xe(r.signal?.reason??"Session aborted")),l.abort()};r.signal?.addEventListener("abort",m);try{return await Oe(i.promise,r.signal)}finally{this.removeEventListener("provider",p),r.signal?.removeEventListener("abort",m),l.clear(),this.requests.delete(n)}}evict(e){this.evictionFilter.add(this.toFilterKey(e));let r=this.providers.findIndex(n=>this.equals(n,e));r!==-1&&this.providers.splice(r,1)}isEvicted(e){return this.evictionFilter.has(this.toFilterKey(e))}hasProvider(e){return!!(this.providers.find(r=>this.equals(r,e))!=null||this.isEvicted(e))}async addPeer(e,r){let n=await this.convertToProvider(e,"manually-added",r);n==null||this.hasProvider(n)||(this.providers.push(n),this.safeDispatchEvent("provider",{detail:n}))}async findProviders(e,r,n){let o=G(),i=0;return Promise.resolve().then(async()=>{if(this.log("finding %d-%d new provider(s) for %c - %d initial providers",r,this.maxProviders,e,this.initialProviders.length),this.initialProviders.length>0)for(;i<r&&this.initialProviders.length>0;){let s=this.initialProviders.pop();if(s==null)break;let a=await this.convertToProvider(s,"manual",n);if(n.signal?.aborted===!0)break;if(a!=null&&!this.hasProvider(a)&&(this.log("found %d/%d new providers",i,this.maxProviders),this.providers.push(a),this.safeDispatchEvent("provider",{detail:a}),i++,i===r&&(this.log("session is ready with %d peer(s), only initial peers present",r),o.resolve()),this.providers.length===this.maxProviders)){this.log("found max session peers",i);break}}if(i<this.maxProviders)for await(let s of this.findNewProviders(e,n)){if(i===this.maxProviders||n.signal?.aborted===!0)break;if(!this.hasProvider(s)&&(this.log("found %d/%d new providers",i,this.maxProviders),this.providers.push(s),this.safeDispatchEvent("provider",{detail:s}),i++,i===r&&(this.log("session is ready with %d peer(s), new peers present",r),o.resolve()),this.providers.length===this.maxProviders)){this.log("found max session peers",i);break}}if(this.log("found %d/%d new session peers",i,this.maxProviders),i<r)throw new Rn(`Found ${i} of ${r} ${this.name} providers for ${e}`)}).catch(s=>{this.log.error("error searching routing for potential session peers for %c - %e",e,s),o.reject(s)}),o.promise}};function wl(t){return e=>new Bs(e,t)}function xl(t){return e=>new Rs(e,t)}function bl(t){return e=>new Ps(e,t)}var Rr=class{components;constructor(e,r={}){this.components=e}async*walk(e,r){let n=this.getQueue(),o=$o(n.toGenerator(r),a=>a!=null),i=!1,s=async a=>{let c=a.cid,l=await An(this.components.blockstore.get(c,a)),p=In({cid:c,bytes:l,codec:await this.components.getCodec(c.code)});for(let[,m]of p.links())r?.includeChild?.(m,p)!==!1&&n.add(s,{...a,cid:m,depth:a.depth+1,path:[...a.path,m]}).catch(x=>{i||o.throw(x)});return{block:p,depth:a.depth,path:a.path}};n.add(s,{...r,cid:e,depth:0,path:[e]}).catch(a=>{i||o.throw(a)});try{yield*o}finally{i=!0,n.abort()}}},Bs=class extends Rr{getQueue(){return new J({concurrency:1,sort:(e,r)=>e.options.depth===r.options.depth?0:e.options.depth<r.options.depth?1:-1})}},Rs=class extends Rr{getQueue(){return new J({concurrency:1,sort:(e,r)=>e.options.depth===r.options.depth?0:e.options.depth<r.options.depth?-1:1})}},Ps=class extends Rr{getQueue(){return new J({concurrency:1})}};var Ds=class{libp2p;blockstore;datastore;events;pins;logger;routing;getCodec;getHasher;dns;metrics;log;constructor(e){this.logger=e.logger??e.libp2p.logger,this.log=this.logger.forComponent("helia"),this.getHasher=ml(e.hashers,e.loadHasher),this.getCodec=pl(e.codecs,e.loadCodec),this.dns=e.dns??xa(),this.metrics=e.metrics,this.libp2p=e.libp2p,this.events=new le;let r={blockstore:e.blockstore,datastore:e.datastore,logger:this.logger,libp2p:this.libp2p,blockBrokers:[],getHasher:this.getHasher,getCodec:this.getCodec,dns:this.dns,metrics:this.metrics,...e.components??{}};this.routing=r.routing=new $n(r,{routers:(e.routers??[]).flatMap(o=>{typeof o=="function"&&(o=o(r));let i=[o],s=og(o);s!=null&&i.push(s);let a=ig(o);return a!=null&&i.push(a),i}),providerLookupConcurrency:e.providerLookupConcurrency}),r.blockBrokers=e.blockBrokers.map(o=>o(r));let n=new Oo(r,e);this.pins=new Bn(e.datastore,n,this.getCodec),this.blockstore=new to(n,this.pins,{holdGcLock:e.holdGcLock??!0}),this.datastore=e.datastore}async start(){await zc(this.datastore),await We(this.blockstore,this.datastore,this.routing,this.libp2p),this.events.dispatchEvent(new CustomEvent("start",{detail:this}))}async stop(){await Ge(this.blockstore,this.datastore,this.routing,this.libp2p),this.events.dispatchEvent(new CustomEvent("stop",{detail:this}))}async gc(e={}){let r=await this.blockstore.lock.writeLock();try{let n=this,o=this.blockstore.unwrap();this.log("gc start"),await ba(o.deleteMany((async function*(){for await(let{cid:i}of o.getAll())try{if(await n.pins.isPinned(i,e))continue;yield i,e.onProgress?.(new A("helia:gc:deleted",i))}catch(s){n.log.error("error during gc - %e",s),e.onProgress?.(new A("helia:gc:error",s))}})()))}finally{r()}this.log("gc finished")}};function og(t){return t?.[Fs]}function ig(t){return t?.[zs]}return Tl(sg);})();
3
3
  return HeliaUtils}));
4
4
  //# sourceMappingURL=index.min.js.map