@helia/utils 0.0.1-8a5bc6f → 0.0.1-8db7792
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,3 +1,3 @@
|
|
|
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 Ai=Object.create;var lt=Object.defineProperty;var Ci=Object.getOwnPropertyDescriptor;var Si=Object.getOwnPropertyNames;var Ti=Object.getPrototypeOf,_i=Object.prototype.hasOwnProperty;var dt=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),R=(r,e)=>{for(var t in e)lt(r,t,{get:e[t],enumerable:!0})},Xr=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Si(e))!_i.call(r,o)&&o!==t&<(r,o,{get:()=>e[o],enumerable:!(n=Ci(e,o))||n.enumerable});return r};var Zr=(r,e,t)=>(t=r!=null?Ai(Ti(r)):{},Xr(e||!r||!r.__esModule?lt(t,"default",{value:r,enumerable:!0}):t,r)),Ii=r=>Xr(lt({},"__esModule",{value:!0}),r);var on=dt((yc,nn)=>{var we=1e3,be=we*60,xe=be*60,he=xe*24,Bi=he*7,Ni=he*365.25;nn.exports=function(r,e){e=e||{};var t=typeof r;if(t==="string"&&r.length>0)return Di(r);if(t==="number"&&isFinite(r))return e.long?Pi(r):Ui(r);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(r))};function Di(r){if(r=String(r),!(r.length>100)){var e=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(r);if(e){var t=parseFloat(e[1]),n=(e[2]||"ms").toLowerCase();switch(n){case"years":case"year":case"yrs":case"yr":case"y":return t*Ni;case"weeks":case"week":case"w":return t*Bi;case"days":case"day":case"d":return t*he;case"hours":case"hour":case"hrs":case"hr":case"h":return t*xe;case"minutes":case"minute":case"mins":case"min":case"m":return t*be;case"seconds":case"second":case"secs":case"sec":case"s":return t*we;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return t;default:return}}}}function Ui(r){var e=Math.abs(r);return e>=he?Math.round(r/he)+"d":e>=xe?Math.round(r/xe)+"h":e>=be?Math.round(r/be)+"m":e>=we?Math.round(r/we)+"s":r+"ms"}function Pi(r){var e=Math.abs(r);return e>=he?pt(r,e,he,"day"):e>=xe?pt(r,e,xe,"hour"):e>=be?pt(r,e,be,"minute"):e>=we?pt(r,e,we,"second"):r+" ms"}function pt(r,e,t,n){var o=e>=t*1.5;return Math.round(r/t)+" "+n+(o?"s":"")}});var an=dt((gc,sn)=>{function Ri(r){t.debug=t,t.default=t,t.coerce=u,t.disable=i,t.enable=o,t.enabled=s,t.humanize=on(),t.destroy=m,Object.keys(r).forEach(f=>{t[f]=r[f]}),t.names=[],t.skips=[],t.formatters={};function e(f){let d=0;for(let g=0;g<f.length;g++)d=(d<<5)-d+f.charCodeAt(g),d|=0;return t.colors[Math.abs(d)%t.colors.length]}t.selectColor=e;function t(f){let d,g=null,D,x;function w(...y){if(!w.enabled)return;let E=w,A=Number(new Date),S=A-(d||A);E.diff=S,E.prev=d,E.curr=A,d=A,y[0]=t.coerce(y[0]),typeof y[0]!="string"&&y.unshift("%O");let T=0;y[0]=y[0].replace(/%([a-zA-Z%])/g,(V,P)=>{if(V==="%%")return"%";T++;let W=t.formatters[P];if(typeof W=="function"){let ge=y[T];V=W.call(E,ge),y.splice(T,1),T--}return V}),t.formatArgs.call(E,y),(E.log||t.log).apply(E,y)}return w.namespace=f,w.useColors=t.useColors(),w.color=t.selectColor(f),w.extend=n,w.destroy=t.destroy,Object.defineProperty(w,"enabled",{enumerable:!0,configurable:!1,get:()=>g!==null?g:(D!==t.namespaces&&(D=t.namespaces,x=t.enabled(f)),x),set:y=>{g=y}}),typeof t.init=="function"&&t.init(w),w}function n(f,d){let g=t(this.namespace+(typeof d>"u"?":":d)+f);return g.log=this.log,g}function o(f){t.save(f),t.namespaces=f,t.names=[],t.skips=[];let d,g=(typeof f=="string"?f:"").split(/[\s,]+/),D=g.length;for(d=0;d<D;d++)g[d]&&(f=g[d].replace(/\*/g,".*?"),f[0]==="-"?t.skips.push(new RegExp("^"+f.slice(1)+"$")):t.names.push(new RegExp("^"+f+"$")))}function i(){let f=[...t.names.map(c),...t.skips.map(c).map(d=>"-"+d)].join(",");return t.enable(""),f}function s(f){if(f[f.length-1]==="*")return!0;let d,g;for(d=0,g=t.skips.length;d<g;d++)if(t.skips[d].test(f))return!1;for(d=0,g=t.names.length;d<g;d++)if(t.names[d].test(f))return!0;return!1}function c(f){return f.toString().substring(2,f.toString().length-2).replace(/\.\*\?$/,"*")}function u(f){return f instanceof Error?f.stack||f.message:f}function m(){console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.")}return t.enable(t.load()),t}sn.exports=Ri});var cn=dt(($,mt)=>{$.formatArgs=$i;$.save=Fi;$.load=Mi;$.useColors=Oi;$.storage=zi();$.destroy=(()=>{let r=!1;return()=>{r||(r=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})();$.colors=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"];function Oi(){return typeof window<"u"&&window.process&&(window.process.type==="renderer"||window.process.__nwjs)?!0:typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)?!1:typeof document<"u"&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||typeof window<"u"&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)&&parseInt(RegExp.$1,10)>=31||typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)}function $i(r){if(r[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+r[0]+(this.useColors?"%c ":" ")+"+"+mt.exports.humanize(this.diff),!this.useColors)return;let e="color: "+this.color;r.splice(1,0,e,"color: inherit");let t=0,n=0;r[0].replace(/%[a-zA-Z%]/g,o=>{o!=="%%"&&(t++,o==="%c"&&(n=t))}),r.splice(n,0,e)}$.log=console.debug||console.log||(()=>{});function Fi(r){try{r?$.storage.setItem("debug",r):$.storage.removeItem("debug")}catch{}}function Mi(){let r;try{r=$.storage.getItem("debug")}catch{}return!r&&typeof process<"u"&&"env"in process&&(r=process.env.DEBUG),r}function zi(){try{return localStorage}catch{}}mt.exports=an()($);var{formatters:qi}=mt.exports;qi.j=function(r){try{return JSON.stringify(r)}catch(e){return"[UnexpectedJSONParseError]: "+e.message}}});var Xo=dt((wl,Dr)=>{"use strict";var Na=Object.prototype.hasOwnProperty,N="~";function at(){}Object.create&&(at.prototype=Object.create(null),new at().__proto__||(N=!1));function Da(r,e,t){this.fn=r,this.context=e,this.once=t||!1}function Yo(r,e,t,n,o){if(typeof t!="function")throw new TypeError("The listener must be a function");var i=new Da(t,n||r,o),s=N?N+e:e;return r._events[s]?r._events[s].fn?r._events[s]=[r._events[s],i]:r._events[s].push(i):(r._events[s]=i,r._eventsCount++),r}function jt(r,e){--r._eventsCount===0?r._events=new at:delete r._events[e]}function L(){this._events=new at,this._eventsCount=0}L.prototype.eventNames=function(){var e=[],t,n;if(this._eventsCount===0)return e;for(n in t=this._events)Na.call(t,n)&&e.push(N?n.slice(1):n);return Object.getOwnPropertySymbols?e.concat(Object.getOwnPropertySymbols(t)):e};L.prototype.listeners=function(e){var t=N?N+e:e,n=this._events[t];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};L.prototype.listenerCount=function(e){var t=N?N+e:e,n=this._events[t];return n?n.fn?1:n.length:0};L.prototype.emit=function(e,t,n,o,i,s){var c=N?N+e:e;if(!this._events[c])return!1;var u=this._events[c],m=arguments.length,f,d;if(u.fn){switch(u.once&&this.removeListener(e,u.fn,void 0,!0),m){case 1:return u.fn.call(u.context),!0;case 2:return u.fn.call(u.context,t),!0;case 3:return u.fn.call(u.context,t,n),!0;case 4:return u.fn.call(u.context,t,n,o),!0;case 5:return u.fn.call(u.context,t,n,o,i),!0;case 6:return u.fn.call(u.context,t,n,o,i,s),!0}for(d=1,f=new Array(m-1);d<m;d++)f[d-1]=arguments[d];u.fn.apply(u.context,f)}else{var g=u.length,D;for(d=0;d<g;d++)switch(u[d].once&&this.removeListener(e,u[d].fn,void 0,!0),m){case 1:u[d].fn.call(u[d].context);break;case 2:u[d].fn.call(u[d].context,t);break;case 3:u[d].fn.call(u[d].context,t,n);break;case 4:u[d].fn.call(u[d].context,t,n,o);break;default:if(!f)for(D=1,f=new Array(m-1);D<m;D++)f[D-1]=arguments[D];u[d].fn.apply(u[d].context,f)}}return!0};L.prototype.on=function(e,t,n){return Yo(this,e,t,n,!1)};L.prototype.once=function(e,t,n){return Yo(this,e,t,n,!0)};L.prototype.removeListener=function(e,t,n,o){var i=N?N+e:e;if(!this._events[i])return this;if(!t)return jt(this,i),this;var s=this._events[i];if(s.fn)s.fn===t&&(!o||s.once)&&(!n||s.context===n)&&jt(this,i);else{for(var c=0,u=[],m=s.length;c<m;c++)(s[c].fn!==t||o&&!s[c].once||n&&s[c].context!==n)&&u.push(s[c]);u.length?this._events[i]=u.length===1?u[0]:u:jt(this,i)}return this};L.prototype.removeAllListeners=function(e){var t;return e?(t=N?N+e:e,this._events[t]&&jt(this,t)):(this._events=new at,this._eventsCount=0),this};L.prototype.off=L.prototype.removeListener;L.prototype.addListener=L.prototype.on;L.prefixed=N;L.EventEmitter=L;typeof Dr<"u"&&(Dr.exports=L)});var ac={};R(ac,{Helia:()=>Yr});var Jt=Symbol.for("@libp2p/content-routing");var en=Symbol.for("@libp2p/peer-id");var Qt=Symbol.for("@libp2p/peer-routing");var re=class r extends Error{code;type;constructor(e="The operation was aborted"){super(e),this.code=r.code,this.type=r.type}static code="ABORT_ERR";static type="aborted"},O=class extends Error{code;props;constructor(e,t,n){super(e),this.code=t,this.name=n?.name??"CodeError",this.props=n??{}}};var ht=class extends EventTarget{#e=new Map;listenerCount(e){let t=this.#e.get(e);return t==null?0:t.length}addEventListener(e,t,n){super.addEventListener(e,t,n);let o=this.#e.get(e);o==null&&(o=[],this.#e.set(e,o)),o.push({callback:t,once:(n!==!0&&n!==!1&&n?.once)??!1})}removeEventListener(e,t,n){super.removeEventListener(e.toString(),t??null,n);let o=this.#e.get(e);o!=null&&(o=o.filter(({callback:i})=>i!==t),this.#e.set(e,o))}dispatchEvent(e){let t=super.dispatchEvent(e),n=this.#e.get(e.type);return n==null||(n=n.filter(({once:o})=>!o),this.#e.set(e.type,n)),t}safeDispatchEvent(e,t={}){return this.dispatchEvent(new Li(e,t))}},Yt=class extends Event{detail;constructor(e,t){super(e,t),this.detail=t?.detail}},Li=globalThis.CustomEvent??Yt;var tn=(r,...e)=>{try{[...e]}catch{}};function rn(r){return r!=null&&typeof r.start=="function"&&typeof r.stop=="function"}async function ne(...r){let e=[];for(let t of r)rn(t)&&e.push(t);await Promise.all(e.map(async t=>{t.beforeStart!=null&&await t.beforeStart()})),await Promise.all(e.map(async t=>{await t.start()})),await Promise.all(e.map(async t=>{t.afterStart!=null&&await t.afterStart()}))}async function oe(...r){let e=[];for(let t of r)rn(t)&&e.push(t);await Promise.all(e.map(async t=>{t.beforeStop!=null&&await t.beforeStop()})),await Promise.all(e.map(async t=>{await t.stop()})),await Promise.all(e.map(async t=>{t.afterStop!=null&&await t.afterStop()}))}var F=Zr(cn(),1);var rr={};R(rr,{base32:()=>se,base32hex:()=>Yi,base32hexpad:()=>Zi,base32hexpadupper:()=>es,base32hexupper:()=>Xi,base32pad:()=>Ji,base32padupper:()=>Qi,base32upper:()=>Gi,base32z:()=>ts});var wc=new Uint8Array(0);function un(r,e){if(r===e)return!0;if(r.byteLength!==e.byteLength)return!1;for(let t=0;t<r.byteLength;t++)if(r[t]!==e[t])return!1;return!0}function X(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return r;if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return new Uint8Array(r.buffer,r.byteOffset,r.byteLength);throw new Error("Unknown type, must be binary type")}function fn(r){return new TextEncoder().encode(r)}function ln(r){return new TextDecoder().decode(r)}function ji(r,e){if(r.length>=255)throw new TypeError("Alphabet too long");for(var t=new Uint8Array(256),n=0;n<t.length;n++)t[n]=255;for(var o=0;o<r.length;o++){var i=r.charAt(o),s=i.charCodeAt(0);if(t[s]!==255)throw new TypeError(i+" is ambiguous");t[s]=o}var c=r.length,u=r.charAt(0),m=Math.log(c)/Math.log(256),f=Math.log(256)/Math.log(c);function d(x){if(x instanceof Uint8Array||(ArrayBuffer.isView(x)?x=new Uint8Array(x.buffer,x.byteOffset,x.byteLength):Array.isArray(x)&&(x=Uint8Array.from(x))),!(x instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(x.length===0)return"";for(var w=0,y=0,E=0,A=x.length;E!==A&&x[E]===0;)E++,w++;for(var S=(A-E)*f+1>>>0,T=new Uint8Array(S);E!==A;){for(var U=x[E],V=0,P=S-1;(U!==0||V<y)&&P!==-1;P--,V++)U+=256*T[P]>>>0,T[P]=U%c>>>0,U=U/c>>>0;if(U!==0)throw new Error("Non-zero carry");y=V,E++}for(var W=S-y;W!==S&&T[W]===0;)W++;for(var ge=u.repeat(w);W<S;++W)ge+=r.charAt(T[W]);return ge}function g(x){if(typeof x!="string")throw new TypeError("Expected String");if(x.length===0)return new Uint8Array;var w=0;if(x[w]!==" "){for(var y=0,E=0;x[w]===u;)y++,w++;for(var A=(x.length-w)*m+1>>>0,S=new Uint8Array(A);x[w];){var T=t[x.charCodeAt(w)];if(T===255)return;for(var U=0,V=A-1;(T!==0||U<E)&&V!==-1;V--,U++)T+=c*S[V]>>>0,S[V]=T%256>>>0,T=T/256>>>0;if(T!==0)throw new Error("Non-zero carry");E=U,w++}if(x[w]!==" "){for(var P=A-E;P!==A&&S[P]===0;)P++;for(var W=new Uint8Array(y+(A-P)),ge=y;P!==A;)W[ge++]=S[P++];return W}}}function D(x){var w=g(x);if(w)return w;throw new Error(`Non-${e} character`)}return{encode:d,decodeUnsafe:g,decode:D}}var Vi=ji,Wi=Vi,hn=Wi;var Xt=class{name;prefix;baseEncode;constructor(e,t,n){this.name=e,this.prefix=t,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},Zt=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,t,n){if(this.name=e,this.prefix=t,t.codePointAt(0)===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=t.codePointAt(0),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 pn(this,e)}},er=class{decoders;constructor(e){this.decoders=e}or(e){return pn(this,e)}decode(e){let t=e[0],n=this.decoders[t];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 pn(r,e){return new er({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}var tr=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,t,n,o){this.name=e,this.prefix=t,this.baseEncode=n,this.baseDecode=o,this.encoder=new Xt(e,t,n),this.decoder=new Zt(e,t,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function Ee({name:r,prefix:e,encode:t,decode:n}){return new tr(r,e,t,n)}function ie({name:r,prefix:e,alphabet:t}){let{encode:n,decode:o}=hn(t,r);return Ee({prefix:e,name:r,encode:n,decode:i=>X(o(i))})}function Hi(r,e,t,n){let o={};for(let f=0;f<e.length;++f)o[e[f]]=f;let i=r.length;for(;r[i-1]==="=";)--i;let s=new Uint8Array(i*t/8|0),c=0,u=0,m=0;for(let f=0;f<i;++f){let d=o[r[f]];if(d===void 0)throw new SyntaxError(`Non-${n} character`);u=u<<t|d,c+=t,c>=8&&(c-=8,s[m++]=255&u>>c)}if(c>=t||255&u<<8-c)throw new SyntaxError("Unexpected end of data");return s}function Ki(r,e,t){let n=e[e.length-1]==="=",o=(1<<t)-1,i="",s=0,c=0;for(let u=0;u<r.length;++u)for(c=c<<8|r[u],s+=8;s>t;)s-=t,i+=e[o&c>>s];if(s!==0&&(i+=e[o&c<<t-s]),n)for(;i.length*t&7;)i+="=";return i}function v({name:r,prefix:e,bitsPerChar:t,alphabet:n}){return Ee({prefix:e,name:r,encode(o){return Ki(o,n,t)},decode(o){return Hi(o,n,t,r)}})}var se=v({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Gi=v({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Ji=v({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Qi=v({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Yi=v({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Xi=v({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Zi=v({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),es=v({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),ts=v({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var nr={};R(nr,{base58btc:()=>B,base58flickr:()=>rs});var B=ie({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),rs=ie({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var or={};R(or,{base64:()=>ke,base64pad:()=>ns,base64url:()=>os,base64urlpad:()=>is});var ke=v({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),ns=v({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),os=v({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),is=v({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});F.default.formatters.b=r=>r==null?"undefined":B.baseEncode(r);F.default.formatters.t=r=>r==null?"undefined":se.baseEncode(r);F.default.formatters.m=r=>r==null?"undefined":ke.baseEncode(r);F.default.formatters.p=r=>r==null?"undefined":r.toString();F.default.formatters.c=r=>r==null?"undefined":r.toString();F.default.formatters.k=r=>r==null?"undefined":r.toString();F.default.formatters.a=r=>r==null?"undefined":r.toString();function ss(r){let e=()=>{};return e.enabled=!1,e.color="",e.diff=0,e.log=()=>{},e.namespace=r,e.destroy=()=>!0,e.extend=()=>e,e}function mn(){return{forComponent(r){return as(r)}}}function as(r){let e=ss(`${r}:trace`);return F.default.enabled(`${r}:trace`)&&F.default.names.map(t=>t.toString()).find(t=>t.includes(":trace"))!=null&&(e=(0,F.default)(`${r}:trace`)),Object.assign((0,F.default)(r),{error:(0,F.default)(`${r}:error`),trace:e})}function cs(r){return r[Symbol.asyncIterator]!=null}function us(r){if(cs(r))return(async()=>{for await(let e of r);})();for(let e of r);}var yn=us;var k=class extends Event{constructor(e,t){super(e),this.detail=t}};function ve(){let r={};return r.promise=new Promise((e,t)=>{r.resolve=e,r.reject=t}),r}var yt=class{buffer;mask;top;btm;next;constructor(e){if(!(e>0)||e-1&e)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}},Ae=class{size;hwm;head;tail;constructor(e={}){this.hwm=e.splitLimit??16,this.head=new yt(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 t=this.head;this.head=t.next=new yt(2*this.head.buffer.length),this.head.push(e)}}shift(){let e=this.tail.shift();if(e===void 0&&this.tail.next!=null){let t=this.tail.next;this.tail.next=null,this.tail=t,e=this.tail.shift()}return e?.value!=null&&(this.size-=this.calculateSize(e.value)),e}isEmpty(){return this.head.isEmpty()}};var ir=class extends Error{type;code;constructor(e,t){super(e??"The operation was aborted"),this.type="aborted",this.code=t??"ABORT_ERR"}};function gt(r={}){return fs(t=>{let n=t.shift();if(n==null)return{done:!0};if(n.error!=null)throw n.error;return{done:n.done===!0,value:n.value}},r)}function fs(r,e){e=e??{};let t=e.onEnd,n=new Ae,o,i,s,c=ve(),u=async()=>{try{return n.isEmpty()?s?{done:!0}:await new Promise((y,E)=>{i=A=>{i=null,n.push(A);try{y(r(n))}catch(S){E(S)}return o}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{c.resolve(),c=ve()})}},m=y=>i!=null?i(y):(n.push(y),o),f=y=>(n=new Ae,i!=null?i({error:y}):(n.push({error:y}),o)),d=y=>{if(s)return o;if(e?.objectMode!==!0&&y?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return m({done:!1,value:y})},g=y=>s?o:(s=!0,y!=null?f(y):m({done:!0})),D=()=>(n=new Ae,g(),{done:!0}),x=y=>(g(y),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:u,return:D,throw:x,push:d,end:g,get readableLength(){return n.size},onEmpty:async y=>{let E=y?.signal;if(E?.throwIfAborted(),n.isEmpty())return;let A,S;E!=null&&(A=new Promise((T,U)=>{S=()=>{U(new ir)},E.addEventListener("abort",S)}));try{await Promise.race([c.promise,A])}finally{S!=null&&E!=null&&E?.removeEventListener("abort",S)}}},t==null)return o;let w=o;return o={[Symbol.asyncIterator](){return this},next(){return w.next()},throw(y){return w.throw(y),t!=null&&(t(y),t=void 0),{done:!0}},return(){return w.return(),t!=null&&(t(),t=void 0),{done:!0}},push:d,end(y){return w.end(y),t!=null&&(t(y),t=void 0),o},get readableLength(){return w.readableLength},onEmpty:y=>w.onEmpty(y)},o}var sr=class extends Error{type;code;constructor(e,t){super(e??"The operation was aborted"),this.type="aborted",this.name="AbortError",this.code=t??"ABORT_ERR"}};async function wt(r,e,t,n){let o=new sr(n?.errorMessage,n?.errorCode);return t?.aborted===!0?Promise.reject(o):new Promise((i,s)=>{let c=m=>{n?.filter?.(m)!==!1&&(r.removeEventListener(e,c),t?.removeEventListener("abort",u),i(m))},u=()=>{r.removeEventListener(e,c),t?.removeEventListener("abort",u),s(o)};r.addEventListener(e,c),t?.addEventListener("abort",u)})}var bt=class extends Error{type;code;constructor(e,t){super(e??"The operation was aborted"),this.type="aborted",this.name="AbortError",this.code=t??"ABORT_ERR"}};async function gn(r,e,t){if(e==null)return r;if(e.aborted)return Promise.reject(new bt(t?.errorMessage,t?.errorCode));let n,o=new bt(t?.errorMessage,t?.errorCode);try{return await Promise.race([r,new Promise((i,s)=>{n=()=>{s(o)},e.addEventListener("abort",n)})])}finally{n!=null&&e.removeEventListener("abort",n)}}var xt=class{deferred;signal;where;constructor(e,t){this.signal=t,this.deferred=ve(),this.where=e,this.onAbort=this.onAbort.bind(this),this.signal?.addEventListener("abort",this.onAbort)}onAbort(){this.deferred.reject(new re)}cleanup(){this.signal?.removeEventListener("abort",this.onAbort)}};function ls(){return`${parseInt(String(Math.random()*1e9),10).toString()}${Date.now()}`}var Et=class{id;fn;options;priority;recipients;status;timeline;controller;constructor(e,t,n=0){this.id=ls(),this.status="queued",this.fn=e,this.priority=n,this.options=t,this.recipients=[],this.timeline={created:Date.now()},this.controller=new AbortController,tn(1/0,this.controller.signal),this.onAbort=this.onAbort.bind(this)}abort(e){this.controller.abort(e)}onAbort(){this.recipients.reduce((t,n)=>t&&n.signal?.aborted===!0,!0)&&this.controller.abort(new re)}async join(e={}){let t=new xt(new Error("where").stack,e.signal);return this.recipients.push(t),e.signal?.addEventListener("abort",this.onAbort),t.deferred.promise}async run(){this.status="running",this.timeline.started=Date.now();try{this.controller.signal.throwIfAborted();let e=await gn(this.fn({...this.options??{},signal:this.controller.signal}),this.controller.signal);this.recipients.forEach(t=>{t.deferred.resolve(e)}),this.status="complete"}catch(e){this.recipients.forEach(t=>{t.deferred.reject(e)}),this.status="errored"}finally{this.timeline.finished=Date.now(),this.cleanup()}}cleanup(){this.recipients.forEach(e=>{e.signal?.removeEventListener("abort",this.onAbort)})}};function ds(r,e,t){let n=0,o=r.length;for(;o>0;){let i=Math.trunc(o/2),s=n+i;t(r[s],e)<=0?(n=++s,o-=i+1):o=i}return n}var qe=class extends ht{concurrency;queue;pending;constructor(e={}){super(),this.concurrency=e.concurrency??Number.POSITIVE_INFINITY,this.pending=0,e.metricName!=null&&e.metrics?.registerMetricGroup(e.metricName,{calculate:()=>({size:this.queue.length,running:this.pending,queued:this.queue.length-this.pending})}),this.queue=[]}tryToStartAnother(){if(this.size===0)return queueMicrotask(()=>{this.safeDispatchEvent("empty")}),this.running===0&&queueMicrotask(()=>{this.safeDispatchEvent("idle")}),!1;if(this.pending<this.concurrency){let e;for(let t of this.queue)if(t.status==="queued"){e=t;break}return e==null?!1:(this.safeDispatchEvent("active"),this.pending++,e.run().finally(()=>{for(let t=0;t<this.queue.length;t++)if(this.queue[t]===e){this.queue.splice(t,1);break}this.pending--,this.tryToStartAnother(),this.safeDispatchEvent("next")}),!0)}return!1}enqueue(e){if(this.queue[this.size-1]?.priority>=e.priority){this.queue.push(e);return}let t=ds(this.queue,e,(n,o)=>o.priority-n.priority);this.queue.splice(t,0,e)}async add(e,t){t?.signal?.throwIfAborted();let n=new Et(e,t,t?.priority),o=n.join(t).then(i=>(this.safeDispatchEvent("completed",{detail:i}),i)).catch(i=>{throw this.safeDispatchEvent("error",{detail:i}),i});return this.enqueue(n),this.safeDispatchEvent("add"),this.tryToStartAnother(),o}clear(){this.queue.splice(0,this.queue.length)}abort(){this.queue.forEach(e=>{e.abort(new re)}),this.clear()}async onEmpty(e){this.size!==0&&await wt(this,"empty",e?.signal)}async onSizeLessThan(e,t){this.size<e||await wt(this,"next",t?.signal,{filter:()=>this.size<e})}async onIdle(e){this.pending===0&&this.size===0||await wt(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 t=gt({objectMode:!0}),n=u=>{u!=null?this.abort():this.clear(),t.end(u)},o=u=>{u.detail!=null&&t.push(u.detail)},i=u=>{n(u.detail)},s=()=>{n()},c=()=>{n(new O("Queue aborted","ERR_QUEUE_ABORTED"))};this.addEventListener("completed",o),this.addEventListener("error",i),this.addEventListener("idle",s),e?.signal?.addEventListener("abort",c);try{yield*t}finally{this.removeEventListener("completed",o),this.removeEventListener("error",i),this.removeEventListener("idle",s),e?.signal?.removeEventListener("abort",c),n()}}};var hs=["string","number","bigint","symbol"],ps=["Function","Generator","AsyncGenerator","GeneratorFunction","AsyncGeneratorFunction","AsyncFunction","Observable","Array","Buffer","Object","RegExp","Date","Error","Map","Set","WeakMap","WeakSet","ArrayBuffer","SharedArrayBuffer","DataView","Promise","URL","HTMLElement","Int8Array","Uint8Array","Uint8ClampedArray","Int16Array","Uint16Array","Int32Array","Uint32Array","Float32Array","Float64Array","BigInt64Array","BigUint64Array"];function wn(r){if(r===null)return"null";if(r===void 0)return"undefined";if(r===!0||r===!1)return"boolean";let e=typeof r;if(hs.includes(e))return e;if(e==="function")return"Function";if(Array.isArray(r))return"Array";if(ms(r))return"Buffer";let t=ys(r);return t||"Object"}function ms(r){return r&&r.constructor&&r.constructor.isBuffer&&r.constructor.isBuffer.call(null,r)}function ys(r){let e=Object.prototype.toString.call(r).slice(8,-1);if(ps.includes(e))return e}var a=class{constructor(e,t,n){this.major=e,this.majorEncoded=e<<5,this.name=t,this.terminal=n}toString(){return`Type[${this.major}].${this.name}`}compare(e){return this.major<e.major?-1:this.major>e.major?1:0}};a.uint=new a(0,"uint",!0);a.negint=new a(1,"negint",!0);a.bytes=new a(2,"bytes",!0);a.string=new a(3,"string",!0);a.array=new a(4,"array",!1);a.map=new a(5,"map",!1);a.tag=new a(6,"tag",!1);a.float=new a(7,"float",!0);a.false=new a(7,"false",!0);a.true=new a(7,"true",!0);a.null=new a(7,"null",!0);a.undefined=new a(7,"undefined",!0);a.break=new a(7,"break",!0);var l=class{constructor(e,t,n){this.type=e,this.value=t,this.encodedLength=n,this.encodedBytes=void 0,this.byteValue=void 0}toString(){return`Token[${this.type}].${this.value}`}};var Ce=globalThis.process&&!globalThis.process.browser&&globalThis.Buffer&&typeof globalThis.Buffer.isBuffer=="function",gs=new TextDecoder,ws=new TextEncoder;function kt(r){return Ce&&globalThis.Buffer.isBuffer(r)}function je(r){return r instanceof Uint8Array?kt(r)?new Uint8Array(r.buffer,r.byteOffset,r.byteLength):r:Uint8Array.from(r)}var kn=Ce?(r,e,t)=>t-e>64?globalThis.Buffer.from(r.subarray(e,t)).toString("utf8"):xn(r,e,t):(r,e,t)=>t-e>64?gs.decode(r.subarray(e,t)):xn(r,e,t),vt=Ce?r=>r.length>64?globalThis.Buffer.from(r):bn(r):r=>r.length>64?ws.encode(r):bn(r),Q=r=>Uint8Array.from(r),Se=Ce?(r,e,t)=>kt(r)?new Uint8Array(r.subarray(e,t)):r.slice(e,t):(r,e,t)=>r.slice(e,t),vn=Ce?(r,e)=>(r=r.map(t=>t instanceof Uint8Array?t:globalThis.Buffer.from(t)),je(globalThis.Buffer.concat(r,e))):(r,e)=>{let t=new Uint8Array(e),n=0;for(let o of r)n+o.length>t.length&&(o=o.subarray(0,t.length-n)),t.set(o,n),n+=o.length;return t},An=Ce?r=>globalThis.Buffer.allocUnsafe(r):r=>new Uint8Array(r);function Cn(r,e){if(kt(r)&&kt(e))return r.compare(e);for(let t=0;t<r.length;t++)if(r[t]!==e[t])return r[t]<e[t]?-1:1;return 0}function bn(r){let e=[],t=0;for(let n=0;n<r.length;n++){let o=r.charCodeAt(n);o<128?e[t++]=o:o<2048?(e[t++]=o>>6|192,e[t++]=o&63|128):(o&64512)===55296&&n+1<r.length&&(r.charCodeAt(n+1)&64512)===56320?(o=65536+((o&1023)<<10)+(r.charCodeAt(++n)&1023),e[t++]=o>>18|240,e[t++]=o>>12&63|128,e[t++]=o>>6&63|128,e[t++]=o&63|128):(e[t++]=o>>12|224,e[t++]=o>>6&63|128,e[t++]=o&63|128)}return e}function xn(r,e,t){let n=[];for(;e<t;){let o=r[e],i=null,s=o>239?4:o>223?3:o>191?2:1;if(e+s<=t){let c,u,m,f;switch(s){case 1:o<128&&(i=o);break;case 2:c=r[e+1],(c&192)===128&&(f=(o&31)<<6|c&63,f>127&&(i=f));break;case 3:c=r[e+1],u=r[e+2],(c&192)===128&&(u&192)===128&&(f=(o&15)<<12|(c&63)<<6|u&63,f>2047&&(f<55296||f>57343)&&(i=f));break;case 4:c=r[e+1],u=r[e+2],m=r[e+3],(c&192)===128&&(u&192)===128&&(m&192)===128&&(f=(o&15)<<18|(c&63)<<12|(u&63)<<6|m&63,f>65535&&f<1114112&&(i=f))}}i===null?(i=65533,s=1):i>65535&&(i-=65536,n.push(i>>>10&1023|55296),i=56320|i&1023),n.push(i),e+=s}return ar(n)}var En=4096;function ar(r){let e=r.length;if(e<=En)return String.fromCharCode.apply(String,r);let t="",n=0;for(;n<e;)t+=String.fromCharCode.apply(String,r.slice(n,n+=En));return t}var bs=256,Ve=class{constructor(e=bs){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 t=this.chunks[this.chunks.length-1];if(this.cursor+e.length<=this.maxCursor+1){let o=t.length-(this.maxCursor-this.cursor)-1;t.set(e,o)}else{if(t){let o=t.length-(this.maxCursor-this.cursor)-1;o<t.length&&(this.chunks[this.chunks.length-1]=t.subarray(0,o),this.maxCursor=this.cursor-1)}e.length<64&&e.length<this.chunkSize?(t=An(this.chunkSize),this.chunks.push(t),this.maxCursor+=t.length,this._initReuseChunk===null&&(this._initReuseChunk=t),t.set(e,0)):(this.chunks.push(e),this.maxCursor+=e.length)}this.cursor+=e.length}toBytes(e=!1){let t;if(this.chunks.length===1){let n=this.chunks[0];e&&this.cursor>n.length/2?(t=this.cursor===n.length?n:n.subarray(0,this.cursor),this._initReuseChunk=null,this.chunks=[]):t=Se(n,0,this.cursor)}else t=vn(this.chunks,this.cursor);return e&&this.reset(),t}};var p="CBOR decode error:",Te="CBOR encode error:",We=[];We[23]=1;We[24]=2;We[25]=3;We[26]=5;We[27]=9;function Z(r,e,t){if(r.length-e<t)throw new Error(`${p} not enough data for type`)}var _=[24,256,65536,4294967296,BigInt("18446744073709551616")];function M(r,e,t){Z(r,e,1);let n=r[e];if(t.strict===!0&&n<_[0])throw new Error(`${p} integer encoded in more bytes than necessary (strict decode)`);return n}function z(r,e,t){Z(r,e,2);let n=r[e]<<8|r[e+1];if(t.strict===!0&&n<_[1])throw new Error(`${p} integer encoded in more bytes than necessary (strict decode)`);return n}function q(r,e,t){Z(r,e,4);let n=r[e]*16777216+(r[e+1]<<16)+(r[e+2]<<8)+r[e+3];if(t.strict===!0&&n<_[2])throw new Error(`${p} integer encoded in more bytes than necessary (strict decode)`);return n}function j(r,e,t){Z(r,e,8);let n=r[e]*16777216+(r[e+1]<<16)+(r[e+2]<<8)+r[e+3],o=r[e+4]*16777216+(r[e+5]<<16)+(r[e+6]<<8)+r[e+7],i=(BigInt(n)<<BigInt(32))+BigInt(o);if(t.strict===!0&&i<_[3])throw new Error(`${p} integer encoded in more bytes than necessary (strict decode)`);if(i<=Number.MAX_SAFE_INTEGER)return Number(i);if(t.allowBigInt===!0)return i;throw new Error(`${p} integers outside of the safe integer range are not supported`)}function Sn(r,e,t,n){return new l(a.uint,M(r,e+1,n),2)}function Tn(r,e,t,n){return new l(a.uint,z(r,e+1,n),3)}function _n(r,e,t,n){return new l(a.uint,q(r,e+1,n),5)}function In(r,e,t,n){return new l(a.uint,j(r,e+1,n),9)}function H(r,e){return I(r,0,e.value)}function I(r,e,t){if(t<_[0]){let n=Number(t);r.push([e|n])}else if(t<_[1]){let n=Number(t);r.push([e|24,n])}else if(t<_[2]){let n=Number(t);r.push([e|25,n>>>8,n&255])}else if(t<_[3]){let n=Number(t);r.push([e|26,n>>>24&255,n>>>16&255,n>>>8&255,n&255])}else{let n=BigInt(t);if(n<_[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,r.push(o)}else throw new Error(`${p} encountered BigInt larger than allowable range`)}}H.encodedSize=function(e){return I.encodedSize(e.value)};I.encodedSize=function(e){return e<_[0]?1:e<_[1]?2:e<_[2]?3:e<_[3]?5:9};H.compareTokens=function(e,t){return e.value<t.value?-1:e.value>t.value?1:0};function Ln(r,e,t,n){return new l(a.negint,-1-M(r,e+1,n),2)}function Bn(r,e,t,n){return new l(a.negint,-1-z(r,e+1,n),3)}function Nn(r,e,t,n){return new l(a.negint,-1-q(r,e+1,n),5)}var cr=BigInt(-1),Dn=BigInt(1);function Un(r,e,t,n){let o=j(r,e+1,n);if(typeof o!="bigint"){let i=-1-o;if(i>=Number.MIN_SAFE_INTEGER)return new l(a.negint,i,9)}if(n.allowBigInt!==!0)throw new Error(`${p} integers outside of the safe integer range are not supported`);return new l(a.negint,cr-BigInt(o),9)}function At(r,e){let t=e.value,n=typeof t=="bigint"?t*cr-Dn:t*-1-1;I(r,e.type.majorEncoded,n)}At.encodedSize=function(e){let t=e.value,n=typeof t=="bigint"?t*cr-Dn:t*-1-1;return n<_[0]?1:n<_[1]?2:n<_[2]?3:n<_[3]?5:9};At.compareTokens=function(e,t){return e.value<t.value?1:e.value>t.value?-1:0};function He(r,e,t,n){Z(r,e,t+n);let o=Se(r,e+t,e+t+n);return new l(a.bytes,o,t+n)}function Pn(r,e,t,n){return He(r,e,1,t)}function Rn(r,e,t,n){return He(r,e,2,M(r,e+1,n))}function On(r,e,t,n){return He(r,e,3,z(r,e+1,n))}function $n(r,e,t,n){return He(r,e,5,q(r,e+1,n))}function Fn(r,e,t,n){let o=j(r,e+1,n);if(typeof o=="bigint")throw new Error(`${p} 64-bit integer bytes lengths not supported`);return He(r,e,9,o)}function Ct(r){return r.encodedBytes===void 0&&(r.encodedBytes=r.type===a.string?vt(r.value):r.value),r.encodedBytes}function _e(r,e){let t=Ct(e);I(r,e.type.majorEncoded,t.length),r.push(t)}_e.encodedSize=function(e){let t=Ct(e);return I.encodedSize(t.length)+t.length};_e.compareTokens=function(e,t){return Es(Ct(e),Ct(t))};function Es(r,e){return r.length<e.length?-1:r.length>e.length?1:Cn(r,e)}function Ke(r,e,t,n,o){let i=t+n;Z(r,e,i);let s=new l(a.string,kn(r,e+t,e+i),i);return o.retainStringBytes===!0&&(s.byteValue=Se(r,e+t,e+i)),s}function Mn(r,e,t,n){return Ke(r,e,1,t,n)}function zn(r,e,t,n){return Ke(r,e,2,M(r,e+1,n),n)}function qn(r,e,t,n){return Ke(r,e,3,z(r,e+1,n),n)}function jn(r,e,t,n){return Ke(r,e,5,q(r,e+1,n),n)}function Vn(r,e,t,n){let o=j(r,e+1,n);if(typeof o=="bigint")throw new Error(`${p} 64-bit integer string lengths not supported`);return Ke(r,e,9,o,n)}var Wn=_e;function Ie(r,e,t,n){return new l(a.array,n,t)}function Hn(r,e,t,n){return Ie(r,e,1,t)}function Kn(r,e,t,n){return Ie(r,e,2,M(r,e+1,n))}function Gn(r,e,t,n){return Ie(r,e,3,z(r,e+1,n))}function Jn(r,e,t,n){return Ie(r,e,5,q(r,e+1,n))}function Qn(r,e,t,n){let o=j(r,e+1,n);if(typeof o=="bigint")throw new Error(`${p} 64-bit integer array lengths not supported`);return Ie(r,e,9,o)}function Yn(r,e,t,n){if(n.allowIndefinite===!1)throw new Error(`${p} indefinite length items not allowed`);return Ie(r,e,1,1/0)}function St(r,e){I(r,a.array.majorEncoded,e.value)}St.compareTokens=H.compareTokens;St.encodedSize=function(e){return I.encodedSize(e.value)};function Le(r,e,t,n){return new l(a.map,n,t)}function Xn(r,e,t,n){return Le(r,e,1,t)}function Zn(r,e,t,n){return Le(r,e,2,M(r,e+1,n))}function eo(r,e,t,n){return Le(r,e,3,z(r,e+1,n))}function to(r,e,t,n){return Le(r,e,5,q(r,e+1,n))}function ro(r,e,t,n){let o=j(r,e+1,n);if(typeof o=="bigint")throw new Error(`${p} 64-bit integer map lengths not supported`);return Le(r,e,9,o)}function no(r,e,t,n){if(n.allowIndefinite===!1)throw new Error(`${p} indefinite length items not allowed`);return Le(r,e,1,1/0)}function Tt(r,e){I(r,a.map.majorEncoded,e.value)}Tt.compareTokens=H.compareTokens;Tt.encodedSize=function(e){return I.encodedSize(e.value)};function oo(r,e,t,n){return new l(a.tag,t,1)}function io(r,e,t,n){return new l(a.tag,M(r,e+1,n),2)}function so(r,e,t,n){return new l(a.tag,z(r,e+1,n),3)}function ao(r,e,t,n){return new l(a.tag,q(r,e+1,n),5)}function co(r,e,t,n){return new l(a.tag,j(r,e+1,n),9)}function _t(r,e){I(r,a.tag.majorEncoded,e.value)}_t.compareTokens=H.compareTokens;_t.encodedSize=function(e){return I.encodedSize(e.value)};var Ts=20,_s=21,Is=22,Ls=23;function uo(r,e,t,n){if(n.allowUndefined===!1)throw new Error(`${p} undefined values are not supported`);return n.coerceUndefinedToNull===!0?new l(a.null,null,1):new l(a.undefined,void 0,1)}function fo(r,e,t,n){if(n.allowIndefinite===!1)throw new Error(`${p} indefinite length items not allowed`);return new l(a.break,void 0,1)}function ur(r,e,t){if(t){if(t.allowNaN===!1&&Number.isNaN(r))throw new Error(`${p} NaN values are not supported`);if(t.allowInfinity===!1&&(r===1/0||r===-1/0))throw new Error(`${p} Infinity values are not supported`)}return new l(a.float,r,e)}function lo(r,e,t,n){return ur(fr(r,e+1),3,n)}function ho(r,e,t,n){return ur(lr(r,e+1),5,n)}function po(r,e,t,n){return ur(wo(r,e+1),9,n)}function It(r,e,t){let n=e.value;if(n===!1)r.push([a.float.majorEncoded|Ts]);else if(n===!0)r.push([a.float.majorEncoded|_s]);else if(n===null)r.push([a.float.majorEncoded|Is]);else if(n===void 0)r.push([a.float.majorEncoded|Ls]);else{let o,i=!1;(!t||t.float64!==!0)&&(yo(n),o=fr(G,1),n===o||Number.isNaN(n)?(G[0]=249,r.push(G.slice(0,3)),i=!0):(go(n),o=lr(G,1),n===o&&(G[0]=250,r.push(G.slice(0,5)),i=!0))),i||(Bs(n),o=wo(G,1),G[0]=251,r.push(G.slice(0,9)))}}It.encodedSize=function(e,t){let n=e.value;if(n===!1||n===!0||n===null||n===void 0)return 1;if(!t||t.float64!==!0){yo(n);let o=fr(G,1);if(n===o||Number.isNaN(n))return 3;if(go(n),o=lr(G,1),n===o)return 5}return 9};var mo=new ArrayBuffer(9),K=new DataView(mo,1),G=new Uint8Array(mo,0);function yo(r){if(r===1/0)K.setUint16(0,31744,!1);else if(r===-1/0)K.setUint16(0,64512,!1);else if(Number.isNaN(r))K.setUint16(0,32256,!1);else{K.setFloat32(0,r);let e=K.getUint32(0),t=(e&2139095040)>>23,n=e&8388607;if(t===255)K.setUint16(0,31744,!1);else if(t===0)K.setUint16(0,(r&2147483648)>>16|n>>13,!1);else{let o=t-127;o<-24?K.setUint16(0,0):o<-14?K.setUint16(0,(e&2147483648)>>16|1<<24+o,!1):K.setUint16(0,(e&2147483648)>>16|o+15<<10|n>>13,!1)}}}function fr(r,e){if(r.length-e<2)throw new Error(`${p} not enough data for float16`);let t=(r[e]<<8)+r[e+1];if(t===31744)return 1/0;if(t===64512)return-1/0;if(t===32256)return NaN;let n=t>>10&31,o=t&1023,i;return n===0?i=o*2**-24:n!==31?i=(o+1024)*2**(n-25):i=o===0?1/0:NaN,t&32768?-i:i}function go(r){K.setFloat32(0,r,!1)}function lr(r,e){if(r.length-e<4)throw new Error(`${p} not enough data for float32`);let t=(r.byteOffset||0)+e;return new DataView(r.buffer,t,4).getFloat32(0,!1)}function Bs(r){K.setFloat64(0,r,!1)}function wo(r,e){if(r.length-e<8)throw new Error(`${p} not enough data for float64`);let t=(r.byteOffset||0)+e;return new DataView(r.buffer,t,8).getFloat64(0,!1)}It.compareTokens=H.compareTokens;function b(r,e,t){throw new Error(`${p} encountered invalid minor (${t}) for major ${r[e]>>>5}`)}function Lt(r){return()=>{throw new Error(`${p} ${r}`)}}var h=[];for(let r=0;r<=23;r++)h[r]=b;h[24]=Sn;h[25]=Tn;h[26]=_n;h[27]=In;h[28]=b;h[29]=b;h[30]=b;h[31]=b;for(let r=32;r<=55;r++)h[r]=b;h[56]=Ln;h[57]=Bn;h[58]=Nn;h[59]=Un;h[60]=b;h[61]=b;h[62]=b;h[63]=b;for(let r=64;r<=87;r++)h[r]=Pn;h[88]=Rn;h[89]=On;h[90]=$n;h[91]=Fn;h[92]=b;h[93]=b;h[94]=b;h[95]=Lt("indefinite length bytes/strings are not supported");for(let r=96;r<=119;r++)h[r]=Mn;h[120]=zn;h[121]=qn;h[122]=jn;h[123]=Vn;h[124]=b;h[125]=b;h[126]=b;h[127]=Lt("indefinite length bytes/strings are not supported");for(let r=128;r<=151;r++)h[r]=Hn;h[152]=Kn;h[153]=Gn;h[154]=Jn;h[155]=Qn;h[156]=b;h[157]=b;h[158]=b;h[159]=Yn;for(let r=160;r<=183;r++)h[r]=Xn;h[184]=Zn;h[185]=eo;h[186]=to;h[187]=ro;h[188]=b;h[189]=b;h[190]=b;h[191]=no;for(let r=192;r<=215;r++)h[r]=oo;h[216]=io;h[217]=so;h[218]=ao;h[219]=co;h[220]=b;h[221]=b;h[222]=b;h[223]=b;for(let r=224;r<=243;r++)h[r]=Lt("simple values are not supported");h[244]=b;h[245]=b;h[246]=b;h[247]=uo;h[248]=Lt("simple values are not supported");h[249]=lo;h[250]=ho;h[251]=po;h[252]=b;h[253]=b;h[254]=b;h[255]=fo;var J=[];for(let r=0;r<24;r++)J[r]=new l(a.uint,r,1);for(let r=-1;r>=-24;r--)J[31-r]=new l(a.negint,r,1);J[64]=new l(a.bytes,new Uint8Array(0),1);J[96]=new l(a.string,"",1);J[128]=new l(a.array,0,1);J[160]=new l(a.map,0,1);J[244]=new l(a.false,!1,1);J[245]=new l(a.true,!0,1);J[246]=new l(a.null,null,1);function bo(r){switch(r.type){case a.false:return Q([244]);case a.true:return Q([245]);case a.null:return Q([246]);case a.bytes:return r.value.length?void 0:Q([64]);case a.string:return r.value===""?Q([96]):void 0;case a.array:return r.value===0?Q([128]):void 0;case a.map:return r.value===0?Q([160]):void 0;case a.uint:return r.value<24?Q([Number(r.value)]):void 0;case a.negint:if(r.value>=-24)return Q([31-Number(r.value)])}}var Ds={float64:!1,mapSorter:Rs,quickEncodeToken:bo};function Us(){let r=[];return r[a.uint.major]=H,r[a.negint.major]=At,r[a.bytes.major]=_e,r[a.string.major]=Wn,r[a.array.major]=St,r[a.map.major]=Tt,r[a.tag.major]=_t,r[a.float.major]=It,r}var xo=Us(),dr=new Ve,Nt=class r{constructor(e,t){this.obj=e,this.parent=t}includes(e){let t=this;do if(t.obj===e)return!0;while(t=t.parent);return!1}static createCheck(e,t){if(e&&e.includes(t))throw new Error(`${Te} object contains circular references`);return new r(t,e)}},ae={null:new l(a.null,null),undefined:new l(a.undefined,void 0),true:new l(a.true,!0),false:new l(a.false,!1),emptyArray:new l(a.array,0),emptyMap:new l(a.map,0)},ce={number(r,e,t,n){return!Number.isInteger(r)||!Number.isSafeInteger(r)?new l(a.float,r):r>=0?new l(a.uint,r):new l(a.negint,r)},bigint(r,e,t,n){return r>=BigInt(0)?new l(a.uint,r):new l(a.negint,r)},Uint8Array(r,e,t,n){return new l(a.bytes,r)},string(r,e,t,n){return new l(a.string,r)},boolean(r,e,t,n){return r?ae.true:ae.false},null(r,e,t,n){return ae.null},undefined(r,e,t,n){return ae.undefined},ArrayBuffer(r,e,t,n){return new l(a.bytes,new Uint8Array(r))},DataView(r,e,t,n){return new l(a.bytes,new Uint8Array(r.buffer,r.byteOffset,r.byteLength))},Array(r,e,t,n){if(!r.length)return t.addBreakTokens===!0?[ae.emptyArray,new l(a.break)]:ae.emptyArray;n=Nt.createCheck(n,r);let o=[],i=0;for(let s of r)o[i++]=Bt(s,t,n);return t.addBreakTokens?[new l(a.array,r.length),o,new l(a.break)]:[new l(a.array,r.length),o]},Object(r,e,t,n){let o=e!=="Object",i=o?r.keys():Object.keys(r),s=o?r.size:i.length;if(!s)return t.addBreakTokens===!0?[ae.emptyMap,new l(a.break)]:ae.emptyMap;n=Nt.createCheck(n,r);let c=[],u=0;for(let m of i)c[u++]=[Bt(m,t,n),Bt(o?r.get(m):r[m],t,n)];return Ps(c,t),t.addBreakTokens?[new l(a.map,s),c,new l(a.break)]:[new l(a.map,s),c]}};ce.Map=ce.Object;ce.Buffer=ce.Uint8Array;for(let r of"Uint8Clamped Uint16 Uint32 Int8 Int16 Int32 BigUint64 BigInt64 Float32 Float64".split(" "))ce[`${r}Array`]=ce.DataView;function Bt(r,e={},t){let n=wn(r),o=e&&e.typeEncoders&&e.typeEncoders[n]||ce[n];if(typeof o=="function"){let s=o(r,n,e,t);if(s!=null)return s}let i=ce[n];if(!i)throw new Error(`${Te} unsupported type: ${n}`);return i(r,n,e,t)}function Ps(r,e){e.mapSorter&&r.sort(e.mapSorter)}function Rs(r,e){let t=Array.isArray(r[0])?r[0][0]:r[0],n=Array.isArray(e[0])?e[0][0]:e[0];if(t.type!==n.type)return t.type.compare(n.type);let o=t.type.major,i=xo[o].compareTokens(t,n);return i===0&&console.warn("WARNING: complex key types used, CBOR key sorting guarantees are gone"),i}function Eo(r,e,t,n){if(Array.isArray(e))for(let o of e)Eo(r,o,t,n);else t[e.type.major](r,e,n)}function ko(r,e,t){let n=Bt(r,t);if(!Array.isArray(n)&&t.quickEncodeToken){let o=t.quickEncodeToken(n);if(o)return o;let i=e[n.type.major];if(i.encodedSize){let s=i.encodedSize(n,t),c=new Ve(s);if(i(c,n,t),c.chunks.length!==1)throw new Error(`Unexpected error: pre-calculated length for ${n} was wrong`);return je(c.chunks[0])}}return dr.reset(),Eo(dr,n,e,t),dr.toBytes(!0)}function Ge(r,e){return e=Object.assign({},Ds,e),ko(r,xo,e)}var Os={strict:!1,allowIndefinite:!0,allowUndefined:!0,allowBigInt:!0},hr=class{constructor(e,t={}){this._pos=0,this.data=e,this.options=t}pos(){return this._pos}done(){return this._pos>=this.data.length}next(){let e=this.data[this._pos],t=J[e];if(t===void 0){let n=h[e];if(!n)throw new Error(`${p} no decoder for major type ${e>>>5} (byte 0x${e.toString(16).padStart(2,"0")})`);let o=e&31;t=n(this.data,this._pos,o,this.options)}return this._pos+=t.encodedLength,t}},Je=Symbol.for("DONE"),Dt=Symbol.for("BREAK");function $s(r,e,t){let n=[];for(let o=0;o<r.value;o++){let i=Qe(e,t);if(i===Dt){if(r.value===1/0)break;throw new Error(`${p} got unexpected break to lengthed array`)}if(i===Je)throw new Error(`${p} found array but not enough entries (got ${o}, expected ${r.value})`);n[o]=i}return n}function Fs(r,e,t){let n=t.useMaps===!0,o=n?void 0:{},i=n?new Map:void 0;for(let s=0;s<r.value;s++){let c=Qe(e,t);if(c===Dt){if(r.value===1/0)break;throw new Error(`${p} got unexpected break to lengthed map`)}if(c===Je)throw new Error(`${p} found map but not enough entries (got ${s} [no key], expected ${r.value})`);if(n!==!0&&typeof c!="string")throw new Error(`${p} non-string keys not supported (got ${typeof c})`);if(t.rejectDuplicateMapKeys===!0&&(n&&i.has(c)||!n&&c in o))throw new Error(`${p} found repeat map key "${c}"`);let u=Qe(e,t);if(u===Je)throw new Error(`${p} found map but not enough entries (got ${s} [no value], expected ${r.value})`);n?i.set(c,u):o[c]=u}return n?i:o}function Qe(r,e){if(r.done())return Je;let t=r.next();if(t.type===a.break)return Dt;if(t.type.terminal)return t.value;if(t.type===a.array)return $s(t,r,e);if(t.type===a.map)return Fs(t,r,e);if(t.type===a.tag){if(e.tags&&typeof e.tags[t.value]=="function"){let n=Qe(r,e);return e.tags[t.value](n)}throw new Error(`${p} tag not supported (${t.value})`)}throw new Error("unsupported")}function pr(r,e){if(!(r instanceof Uint8Array))throw new Error(`${p} data to decode must be a Uint8Array`);e=Object.assign({},Os,e);let t=e.tokenizer||new hr(r,e),n=Qe(t,e);if(n===Je)throw new Error(`${p} did not find any content to decode`);if(n===Dt)throw new Error(`${p} got unexpected break`);return[n,r.subarray(t.pos())]}function Y(r,e){let[t,n]=pr(r,e);if(n.length>0)throw new Error(`${p} too many terminals, data makes no sense`);return t}function Ut(r){return globalThis.Buffer!=null?new Uint8Array(r.buffer,r.byteOffset,r.byteLength):r}var yr={};R(yr,{base10:()=>Ms});var Ms=ie({prefix:"9",name:"base10",alphabet:"0123456789"});var gr={};R(gr,{base16:()=>zs,base16upper:()=>qs});var zs=v({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),qs=v({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var wr={};R(wr,{base2:()=>js});var js=v({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var br={};R(br,{base256emoji:()=>Gs});var vo=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}"),Vs=vo.reduce((r,e,t)=>(r[t]=e,r),[]),Ws=vo.reduce((r,e,t)=>(r[e.codePointAt(0)]=t,r),[]);function Hs(r){return r.reduce((e,t)=>(e+=Vs[t],e),"")}function Ks(r){let e=[];for(let t of r){let n=Ws[t.codePointAt(0)];if(n===void 0)throw new Error(`Non-base256emoji character: ${t}`);e.push(n)}return new Uint8Array(e)}var Gs=Ee({prefix:"\u{1F680}",name:"base256emoji",encode:Hs,decode:Ks});var xr={};R(xr,{base36:()=>Ye,base36upper:()=>Js});var Ye=ie({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Js=ie({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Er={};R(Er,{base8:()=>Qs});var Qs=v({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var kr={};R(kr,{identity:()=>Ys});var Ys=Ee({prefix:"\0",name:"identity",encode:r=>ln(r),decode:r=>fn(r)});var nf=new TextEncoder,of=new TextDecoder;var Ao=512;var So=85;var Ar={};R(Ar,{identity:()=>Pe});var Xs=Lo,_o=128,Zs=127,ea=~Zs,ta=Math.pow(2,31);function Lo(r,e,t){e=e||[],t=t||0;for(var n=t;r>=ta;)e[t++]=r&255|_o,r/=128;for(;r&ea;)e[t++]=r&255|_o,r>>>=7;return e[t]=r|0,Lo.bytes=t-n+1,e}var ra=vr,na=128,Io=127;function vr(r,n){var t=0,n=n||0,o=0,i=n,s,c=r.length;do{if(i>=c)throw vr.bytes=0,new RangeError("Could not decode varint");s=r[i++],t+=o<28?(s&Io)<<o:(s&Io)*Math.pow(2,o),o+=7}while(s>=na);return vr.bytes=i-n,t}var oa=Math.pow(2,7),ia=Math.pow(2,14),sa=Math.pow(2,21),aa=Math.pow(2,28),ca=Math.pow(2,35),ua=Math.pow(2,42),fa=Math.pow(2,49),la=Math.pow(2,56),da=Math.pow(2,63),ha=function(r){return r<oa?1:r<ia?2:r<sa?3:r<aa?4:r<ca?5:r<ua?6:r<fa?7:r<la?8:r<da?9:10},pa={encode:Xs,decode:ra,encodingLength:ha},ma=pa,Xe=ma;function Ze(r,e=0){return[Xe.decode(r,e),Xe.decode.bytes]}function Be(r,e,t=0){return Xe.encode(r,e,t),e}function Ne(r){return Xe.encodingLength(r)}function ue(r,e){let t=e.byteLength,n=Ne(r),o=n+Ne(t),i=new Uint8Array(o+t);return Be(r,i,0),Be(t,i,n),i.set(e,o),new De(r,t,e,i)}function et(r){let e=X(r),[t,n]=Ze(e),[o,i]=Ze(e.subarray(n)),s=e.subarray(n+i);if(s.byteLength!==o)throw new Error("Incorrect length");return new De(t,o,s,e)}function Bo(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&un(r.bytes,t.bytes)}}var De=class{code;size;digest;bytes;constructor(e,t,n,o){this.code=e,this.size=t,this.digest=n,this.bytes=o}};var No=0,ya="identity",Do=X;function ga(r){return ue(No,Do(r))}var Pe={code:No,name:ya,encode:Do,digest:ga};var _r={};R(_r,{sha256:()=>Re,sha512:()=>Tr});function Sr({name:r,code:e,encode:t}){return new Cr(r,e,t)}var Cr=class{name;code;encode;constructor(e,t,n){this.name=e,this.code=t,this.encode=n}digest(e){if(e instanceof Uint8Array){let t=this.encode(e);return t instanceof Uint8Array?ue(this.code,t):t.then(n=>ue(this.code,n))}else throw Error("Unknown type, must be binary type")}};function Po(r){return async e=>new Uint8Array(await crypto.subtle.digest(r,e))}var Re=Sr({name:"sha2-256",code:18,encode:Po("SHA-256")}),Tr=Sr({name:"sha2-512",code:19,encode:Po("SHA-512")});function Ro(r,e){let{bytes:t,version:n}=r;switch(n){case 0:return ba(t,Ir(r),e??B.encoder);default:return xa(t,Ir(r),e??se.encoder)}}var Oo=new WeakMap;function Ir(r){let e=Oo.get(r);if(e==null){let t=new Map;return Oo.set(r,t),t}return e}var C=class r{code;version;multihash;bytes;"/";constructor(e,t,n,o){this.code=t,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:t}=this;if(e!==tt)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==Ea)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(t)}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:t}=this.multihash,n=ue(e,t);return r.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 r.equals(this,e)}static equals(e,t){let n=t;return n!=null&&e.code===n.code&&e.version===n.version&&Bo(e.multihash,n.multihash)}toString(e){return Ro(this,e)}toJSON(){return{"/":Ro(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 t=e;if(t instanceof r)return t;if(t["/"]!=null&&t["/"]===t.bytes||t.asCID===t){let{version:n,code:o,multihash:i,bytes:s}=t;return new r(n,o,i,s??$o(n,o,i.bytes))}else if(t[ka]===!0){let{version:n,multihash:o,code:i}=t,s=et(o);return r.create(n,i,s)}else return null}static create(e,t,n){if(typeof t!="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(t!==tt)throw new Error(`Version 0 CID must use dag-pb (code: ${tt}) block encoding`);return new r(e,t,n,n.bytes)}case 1:{let o=$o(e,t,n.bytes);return new r(e,t,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return r.create(0,tt,e)}static createV1(e,t){return r.create(1,e,t)}static decode(e){let[t,n]=r.decodeFirst(e);if(n.length!==0)throw new Error("Incorrect length");return t}static decodeFirst(e){let t=r.inspectBytes(e),n=t.size-t.multihashSize,o=X(e.subarray(n,n+t.multihashSize));if(o.byteLength!==t.multihashSize)throw new Error("Incorrect length");let i=o.subarray(t.multihashSize-t.digestSize),s=new De(t.multihashCode,t.digestSize,i,o);return[t.version===0?r.createV0(s):r.createV1(t.codec,s),e.subarray(t.size)]}static inspectBytes(e){let t=0,n=()=>{let[d,g]=Ze(e.subarray(t));return t+=g,d},o=n(),i=tt;if(o===18?(o=0,t=0):i=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let s=t,c=n(),u=n(),m=t+u,f=m-s;return{version:o,codec:i,multihashCode:c,digestSize:u,multihashSize:f,size:m}}static parse(e,t){let[n,o]=wa(e,t),i=r.decode(o);if(i.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Ir(i).set(n,e),i}};function wa(r,e){switch(r[0]){case"Q":{let t=e??B;return[B.prefix,t.decode(`${B.prefix}${r}`)]}case B.prefix:{let t=e??B;return[B.prefix,t.decode(r)]}case se.prefix:{let t=e??se;return[se.prefix,t.decode(r)]}default:{if(e==null)throw Error("To parse non base32 or base58btc encoded CID multibase decoder must be provided");return[r[0],e.decode(r)]}}}function ba(r,e,t){let{prefix:n}=t;if(n!==B.prefix)throw Error(`Cannot string encode V0 in ${t.name} encoding`);let o=e.get(n);if(o==null){let i=t.encode(r).slice(1);return e.set(n,i),i}else return o}function xa(r,e,t){let{prefix:n}=t,o=e.get(n);if(o==null){let i=t.encode(r);return e.set(n,i),i}else return o}var tt=112,Ea=18;function $o(r,e,t){let n=Ne(r),o=n+Ne(e),i=new Uint8Array(o+t.byteLength);return Be(r,i,0),Be(e,i,n),i.set(t,o),i}var ka=Symbol.for("@ipld/js-cid/CID");var Oe={...kr,...wr,...Er,...yr,...gr,...rr,...xr,...nr,...or,...br},Sf={..._r,...Ar};function Fo(r=0){return globalThis.Buffer?.allocUnsafe!=null?Ut(globalThis.Buffer.allocUnsafe(r)):new Uint8Array(r)}function zo(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}var Mo=zo("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Lr=zo("ascii","a",r=>{let e="a";for(let t=0;t<r.length;t++)e+=String.fromCharCode(r[t]);return e},r=>{r=r.substring(1);let e=Fo(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),va={utf8:Mo,"utf-8":Mo,hex:Oe.base16,latin1:Lr,ascii:Lr,binary:Lr,...Oe},Rt=va;function Ot(r,e="utf8"){let t=Rt[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return(e==="utf8"||e==="utf-8")&&globalThis.Buffer!=null&&globalThis.Buffer.from!=null?Ut(globalThis.Buffer.from(r,"utf-8")):t.decoder.decode(`${t.prefix}${r}`)}function $t(r,e="utf8"){let t=Rt[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return(e==="utf8"||e==="utf-8")&&globalThis.Buffer!=null&&globalThis.Buffer.from!=null?globalThis.Buffer.from(r.buffer,r.byteOffset,r.byteLength).toString("utf8"):t.encoder.encode(r).substring(1)}var ee="/",qo=new TextEncoder().encode(ee),Ft=qo[0],te=class r{_buf;constructor(e,t){if(typeof e=="string")this._buf=Ot(e);else if(e instanceof Uint8Array)this._buf=e;else throw new Error("Invalid key, should be String of Uint8Array");if(t==null&&(t=!0),t&&this.clean(),this._buf.byteLength===0||this._buf[0]!==Ft)throw new Error("Invalid key")}toString(e="utf8"){return $t(this._buf,e)}uint8Array(){return this._buf}get[Symbol.toStringTag](){return`Key(${this.toString()})`}static withNamespaces(e){return new r(e.join(ee))}static random(){return new r(Math.random().toString().substring(2))}static asKey(e){return e instanceof Uint8Array||typeof e=="string"?new r(e):typeof e.uint8Array=="function"?new r(e.uint8Array()):null}clean(){if((this._buf==null||this._buf.byteLength===0)&&(this._buf=qo),this._buf[0]!==Ft){let e=new Uint8Array(this._buf.byteLength+1);e.fill(Ft,0,1),e.set(this._buf,1),this._buf=e}for(;this._buf.byteLength>1&&this._buf[this._buf.byteLength-1]===Ft;)this._buf=this._buf.subarray(0,-1)}less(e){let t=this.list(),n=e.list();for(let o=0;o<t.length;o++){if(n.length<o+1)return!1;let i=t[o],s=n[o];if(i<s)return!0;if(i>s)return!1}return t.length<n.length}reverse(){return r.withNamespaces(this.list().slice().reverse())}namespaces(){return this.list()}baseNamespace(){let e=this.namespaces();return e[e.length-1]}list(){return this.toString().split(ee).slice(1)}type(){return Aa(this.baseNamespace())}name(){return Ca(this.baseNamespace())}instance(e){return new r(this.toString()+":"+e)}path(){let e=this.parent().toString();return e.endsWith(ee)||(e+=ee),e+=this.type(),new r(e)}parent(){let e=this.list();return e.length===1?new r(ee):new r(e.slice(0,-1).join(ee))}child(e){return this.toString()===ee?e:e.toString()===ee?this:new r(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 r.withNamespaces([...this.namespaces(),...Sa(e.map(t=>t.namespaces()))])}};function Aa(r){let e=r.split(":");return e.length<2?"":e.slice(0,-1).join(":")}function Ca(r){let e=r.split(":");return e[e.length-1]}function Sa(r){return[].concat(...r)}function fe(r,e){if(r===e)return!0;if(r.byteLength!==e.byteLength)return!1;for(let t=0;t<r.byteLength;t++)if(r[t]!==e[t])return!1;return!0}var Ho="/pin/",jo="/pinned-block/",Br=Ye,Vo=1;function Wo(r){return r.version===0&&(r=r.toV1()),new te(`${Ho}${r.toString(Br)}`)}var Mt=class{datastore;blockstore;dagWalkers;constructor(e,t,n){this.datastore=e,this.blockstore=t,this.dagWalkers=n}async*add(e,t={}){let n=Wo(e);if(await this.datastore.has(n))throw new Error("Already pinned");let o=Math.round(t.depth??1/0);if(o<0)throw new Error("Depth must be greater than or equal to 0");let i=new qe({concurrency:Vo});for await(let c of this.#e(e,i,{...t,depth:o}))await this.#o(c,u=>u.pinnedBy.find(m=>fe(m,e.bytes))!=null?!1:(u.pinCount++,u.pinnedBy.push(e.bytes),!0),t),yield c;let s={depth:o,metadata:t.metadata??{}};await this.datastore.put(n,Ge(s),t)}async*#e(e,t,n){if(n.depth===-1)return;let o=this.dagWalkers[e.code];if(o==null)throw new Error(`No dag walker found for cid codec ${e.code}`);let i=await this.blockstore.get(e,n);yield e;for await(let s of o.walk(i))yield*await t.add(async()=>this.#e(s,t,{...n,depth:n.depth-1}))}async#o(e,t,n){let o=new te(`${jo}${Br.encode(e.multihash.bytes)}`),i={pinCount:0,pinnedBy:[]};try{i=Y(await this.datastore.get(o,n))}catch(c){if(c.code!=="ERR_NOT_FOUND")throw c}if(t(i)){if(i.pinCount===0&&await this.datastore.has(o)){await this.datastore.delete(o);return}await this.datastore.put(o,Ge(i),n),n.onProgress?.(new k("helia:pin:add",e))}}async*rm(e,t={}){let n=Wo(e),o=await this.datastore.get(n,t),i=Y(o);await this.datastore.delete(n,t);let s=new qe({concurrency:Vo});for await(let c of this.#e(e,s,{...t,depth:i.depth}))await this.#o(c,u=>(u.pinCount--,u.pinnedBy=u.pinnedBy.filter(m=>fe(m,e.bytes)),!0),{...t,depth:i.depth}),yield c}async*ls(e={}){for await(let{key:t,value:n}of this.datastore.query({prefix:Ho+(e.cid!=null?`${e.cid.toString(Ye)}`:"")},e)){let o=C.parse(t.toString().substring(5),Ye),i=Y(n);yield{cid:o,...i}}}async isPinned(e,t={}){let n=new te(`${jo}${Br.encode(e.multihash.bytes)}`);return this.datastore.has(n,t)}};var Ta=Symbol.for("nodejs.util.inspect.custom"),Ko=Object.values(Oe).map(r=>r.decoder).reduce((r,e)=>r.or(e),Oe.identity.decoder),Go=114,Jo=36,Qo=37,rt=class{type;multihash;privateKey;publicKey;string;constructor(e){this.type=e.type,this.multihash=e.multihash,this.privateKey=e.privateKey,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[en]=!0;toString(){return this.string==null&&(this.string=B.encode(this.multihash.bytes).slice(1)),this.string}toCID(){return C.createV1(Go,this.multihash)}toBytes(){return this.multihash.bytes}toJSON(){return this.toString()}equals(e){if(e==null)return!1;if(e instanceof Uint8Array)return fe(this.multihash.bytes,e);if(typeof e=="string")return st(e).equals(this);if(e?.multihash?.bytes!=null)return fe(this.multihash.bytes,e.multihash.bytes);throw new Error("not valid Id")}[Ta](){return`PeerId(${this.toString()})`}},nt=class extends rt{type="RSA";publicKey;constructor(e){super({...e,type:"RSA"}),this.publicKey=e.publicKey}},ot=class extends rt{type="Ed25519";publicKey;constructor(e){super({...e,type:"Ed25519"}),this.publicKey=e.multihash.digest}},it=class extends rt{type="secp256k1";publicKey;constructor(e){super({...e,type:"secp256k1"}),this.publicKey=e.multihash.digest}};function st(r,e){if(e=e??Ko,r.charAt(0)==="1"||r.charAt(0)==="Q"){let t=et(B.decode(`z${r}`));return r.startsWith("12D")?new ot({multihash:t}):r.startsWith("16U")?new it({multihash:t}):new nt({multihash:t})}return _a(Ko.decode(r))}function _a(r){try{let e=et(r);if(e.code===Pe.code){if(e.digest.length===Jo)return new ot({multihash:e});if(e.digest.length===Qo)return new it({multihash:e})}if(e.code===Re.code)return new nt({multihash:e})}catch{return Ia(C.decode(r))}throw new Error("Supplied PeerID CID is invalid")}function Ia(r){if(r==null||r.multihash==null||r.version==null||r.version===1&&r.code!==Go)throw new Error("Supplied PeerID CID is invalid");let e=r.multihash;if(e.code===Re.code)return new nt({multihash:r.multihash});if(e.code===Pe.code){if(e.digest.length===Jo)return new ot({multihash:r.multihash});if(e.digest.length===Qo)return new it({multihash:r.multihash})}throw new Error("Supplied PeerID CID is invalid")}function Nr(r,e){let t={[Symbol.iterator]:()=>t,next:()=>{let n=r.next(),o=n.value;return n.done===!0||o==null?{done:!0,value:void 0}:{done:!1,value:e(o)}}};return t}var $e=class r{set;constructor(e){if(this.set=new Set,e!=null)for(let t of e)this.set.add(t.toString())}get size(){return this.set.size}[Symbol.iterator](){return this.values()}add(e){this.set.add(e.toString())}clear(){this.set.clear()}delete(e){this.set.delete(e.toString())}entries(){return Nr(this.set.entries(),e=>{let t=st(e[0]);return[t,t]})}forEach(e){this.set.forEach(t=>{let n=st(t);e(n,n,this)})}has(e){return this.set.has(e.toString())}values(){return Nr(this.set.values(),e=>st(e))}intersection(e){let t=new r;for(let n of e)this.has(n)&&t.add(n);return t}difference(e){let t=new r;for(let n of this)e.has(n)||t.add(n);return t}union(e){let t=new r;for(let n of e)t.add(n);for(let n of this)t.add(n);return t}};function La(r){return r[Symbol.asyncIterator]!=null}function Ba(...r){let e=[];for(let t of r)La(t)||e.push(t);return e.length===r.length?function*(){for(let t of e)yield*t}():async function*(){let t=gt({objectMode:!0});Promise.resolve().then(async()=>{try{await Promise.all(r.map(async n=>{for await(let o of n)t.push(o)})),t.end()}catch(n){t.end(n)}}),yield*t}()}var zt=Ba;var qt=class{log;routers;constructor(e,t){this.log=e.logger.forComponent("helia:routing"),this.routers=t.routers??[]}async start(){await ne(...this.routers)}async stop(){await oe(...this.routers)}async*findProviders(e,t={}){if(this.routers.length===0)throw new O("No content routers available","ERR_NO_ROUTERS_AVAILABLE");let n=new $e;for await(let o of zt(...Fe(this.routers,"findProviders").map(i=>i.findProviders(e,t))))o!=null&&(n.has(o.id)||(n.add(o.id),yield o))}async provide(e,t={}){if(this.routers.length===0)throw new O("No content routers available","ERR_NO_ROUTERS_AVAILABLE");await Promise.all(Fe(this.routers,"provide").map(async n=>{await n.provide(e,t)}))}async put(e,t,n){await Promise.all(Fe(this.routers,"put").map(async o=>{await o.put(e,t,n)}))}async get(e,t){return Promise.any(Fe(this.routers,"get").map(async n=>n.get(e,t)))}async findPeer(e,t){if(this.routers.length===0)throw new O("No peer routers available","ERR_NO_ROUTERS_AVAILABLE");let n=this,o=zt(...Fe(this.routers,"findPeer").map(i=>async function*(){try{yield await i.findPeer(e,t)}catch(s){n.log.error(s)}}()));for await(let i of o)if(i!=null)return i;throw new O("Could not find peer in routing","ERR_NOT_FOUND")}async*getClosestPeers(e,t={}){if(this.routers.length===0)throw new O("No peer routers available","ERR_NO_ROUTERS_AVAILABLE");let n=new $e;for await(let o of zt(...Fe(this.routers,"getClosestPeers").map(i=>i.getClosestPeers(e,t))))o!=null&&(n.has(o.id)||(n.add(o.id),yield o))}};function Fe(r,e){return r.filter(t=>t[e]!=null)}var Ur=Zr(Xo(),1);var ct=class extends Error{constructor(e){super(e),this.name="TimeoutError"}},Pr=class extends Error{constructor(e){super(),this.name="AbortError",this.message=e}},Zo=r=>globalThis.DOMException===void 0?new Pr(r):new DOMException(r),ei=r=>{let e=r.reason===void 0?Zo("This operation was aborted."):r.reason;return e instanceof Error?e:Zo(e)};function ut(r,e){let{milliseconds:t,fallback:n,message:o,customTimers:i={setTimeout,clearTimeout}}=e,s,u=new Promise((m,f)=>{if(typeof t!="number"||Math.sign(t)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${t}\``);if(e.signal){let{signal:g}=e;g.aborted&&f(ei(g)),g.addEventListener("abort",()=>{f(ei(g))})}if(t===Number.POSITIVE_INFINITY){r.then(m,f);return}let d=new ct;s=i.setTimeout.call(void 0,()=>{if(n){try{m(n())}catch(g){f(g)}return}typeof r.cancel=="function"&&r.cancel(),o===!1?m():o instanceof Error?f(o):(d.message=o??`Promise timed out after ${t} milliseconds`,f(d))},t),(async()=>{try{m(await r)}catch(g){f(g)}})()}).finally(()=>{u.clear()});return u.clear=()=>{i.clearTimeout.call(void 0,s),s=void 0},u}function Rr(r,e,t){let n=0,o=r.length;for(;o>0;){let i=Math.trunc(o/2),s=n+i;t(r[s],e)<=0?(n=++s,o-=i+1):o=i}return n}var ft=class{#e=[];enqueue(e,t){t={priority:0,...t};let n={priority:t.priority,run:e};if(this.size&&this.#e[this.size-1].priority>=t.priority){this.#e.push(n);return}let o=Rr(this.#e,n,(i,s)=>s.priority-i.priority);this.#e.splice(o,0,n)}dequeue(){return this.#e.shift()?.run}filter(e){return this.#e.filter(t=>t.priority===e.priority).map(t=>t.run)}get size(){return this.#e.length}};var Me=class extends Ur.default{#e;#o;#s=0;#h;#a;#p=0;#r;#c;#t;#m;#n=0;#u;#i;#y;timeout;constructor(e){if(super(),e={carryoverConcurrencyCount:!1,intervalCap:Number.POSITIVE_INFINITY,interval:0,concurrency:Number.POSITIVE_INFINITY,autoStart:!0,queueClass:ft,...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})`);this.#e=e.carryoverConcurrencyCount,this.#o=e.intervalCap===Number.POSITIVE_INFINITY||e.interval===0,this.#h=e.intervalCap,this.#a=e.interval,this.#t=new e.queueClass,this.#m=e.queueClass,this.concurrency=e.concurrency,this.timeout=e.timeout,this.#y=e.throwOnTimeout===!0,this.#i=e.autoStart===!1}get#b(){return this.#o||this.#s<this.#h}get#x(){return this.#n<this.#u}#E(){this.#n--,this.#f(),this.emit("next")}#k(){this.#w(),this.#g(),this.#c=void 0}get#v(){let e=Date.now();if(this.#r===void 0){let t=this.#p-e;if(t<0)this.#s=this.#e?this.#n:0;else return this.#c===void 0&&(this.#c=setTimeout(()=>{this.#k()},t)),!0}return!1}#f(){if(this.#t.size===0)return this.#r&&clearInterval(this.#r),this.#r=void 0,this.emit("empty"),this.#n===0&&this.emit("idle"),!1;if(!this.#i){let e=!this.#v;if(this.#b&&this.#x){let t=this.#t.dequeue();return t?(this.emit("active"),t(),e&&this.#g(),!0):!1}}return!1}#g(){this.#o||this.#r!==void 0||(this.#r=setInterval(()=>{this.#w()},this.#a),this.#p=Date.now()+this.#a)}#w(){this.#s===0&&this.#n===0&&this.#r&&(clearInterval(this.#r),this.#r=void 0),this.#s=this.#e?this.#n:0,this.#l()}#l(){for(;this.#f(););}get concurrency(){return this.#u}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.#u=e,this.#l()}async#A(e){return new Promise((t,n)=>{e.addEventListener("abort",()=>{n(e.reason)},{once:!0})})}async add(e,t={}){return t={timeout:this.timeout,throwOnTimeout:this.#y,...t},new Promise((n,o)=>{this.#t.enqueue(async()=>{this.#n++,this.#s++;try{t.signal?.throwIfAborted();let i=e({signal:t.signal});t.timeout&&(i=ut(Promise.resolve(i),{milliseconds:t.timeout})),t.signal&&(i=Promise.race([i,this.#A(t.signal)]));let s=await i;n(s),this.emit("completed",s)}catch(i){if(i instanceof ct&&!t.throwOnTimeout){n();return}o(i),this.emit("error",i)}finally{this.#E()}},t),this.emit("add"),this.#f()})}async addAll(e,t){return Promise.all(e.map(async n=>this.add(n,t)))}start(){return this.#i?(this.#i=!1,this.#l(),this):this}pause(){this.#i=!0}clear(){this.#t=new this.#m}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.#n===0&&this.#t.size===0||await this.#d("idle")}async#d(e,t){return new Promise(n=>{let o=()=>{t&&!t()||(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.#n}get isPaused(){return this.#i}};var le={},ze=r=>{r.addEventListener("message",e=>{ze.dispatchEvent("message",r,e)}),r.port!=null&&r.port.addEventListener("message",e=>{ze.dispatchEvent("message",r,e)})};ze.addEventListener=(r,e)=>{le[r]==null&&(le[r]=[]),le[r].push(e)};ze.removeEventListener=(r,e)=>{le[r]!=null&&(le[r]=le[r].filter(t=>t===e))};ze.dispatchEvent=function(r,e,t){le[r]!=null&&le[r].forEach(n=>n(e,t))};var Or=ze;var $r="lock:worker:request-read",Fr="lock:worker:release-read",Mr="lock:master:grant-read",zr="lock:worker:request-write",qr="lock:worker:release-write",jr="lock:master:grant-write";var ti=(r=21)=>Math.random().toString().substring(2);var ri=(r,e,t,n,o)=>(i,s)=>{if(s.data.type!==t)return;let c={type:s.data.type,name:s.data.name,identifier:s.data.identifier};r.dispatchEvent(new MessageEvent(e,{data:{name:c.name,handler:async()=>{i.postMessage({type:o,name:c.name,identifier:c.identifier}),await new Promise(u=>{let m=f=>{if(f==null||f.data==null)return;let d={type:f.data.type,name:f.data.name,identifier:f.data.identifier};d.type===n&&d.identifier===c.identifier&&(i.removeEventListener("message",m),u())};i.addEventListener("message",m)})}}}))},ni=(r,e,t,n)=>async()=>{let o=ti();return globalThis.postMessage({type:e,identifier:o,name:r}),new Promise(i=>{let s=c=>{if(c==null||c.data==null)return;let u={type:c.data.type,identifier:c.data.identifier};u.type===t&&u.identifier===o&&(globalThis.removeEventListener("message",s),i(()=>{globalThis.postMessage({type:n,identifier:o,name:r})}))};globalThis.addEventListener("message",s)})},Ua={singleProcess:!1},oi=r=>{if(r=Object.assign({},Ua,r),!!globalThis.document||r.singleProcess){let t=new EventTarget;return Or.addEventListener("message",ri(t,"requestReadLock",$r,Fr,Mr)),Or.addEventListener("message",ri(t,"requestWriteLock",zr,qr,jr)),t}return{isWorker:!0,readLock:t=>ni(t,$r,Mr,Fr),writeLock:t=>ni(t,zr,jr,qr)}};var me={},de;async function Vr(r,e){let t,n=new Promise(o=>{t=o});return r.add(async()=>ut((async()=>{await new Promise(o=>{t(()=>{o()})})})(),{milliseconds:e.timeout})),n}var Pa=(r,e)=>{if(de.isWorker===!0)return{readLock:de.readLock(r,e),writeLock:de.writeLock(r,e)};let t=new Me({concurrency:1}),n;return{async readLock(){if(n!=null)return Vr(n,e);n=new Me({concurrency:e.concurrency,autoStart:!1});let o=n,i=Vr(n,e);return t.add(async()=>{o.start(),await o.onIdle().then(()=>{n===o&&(n=null)})}),i},async writeLock(){return n=null,Vr(t,e)}}},Ra={name:"lock",concurrency:1/0,timeout:846e5,singleProcess:!1};function Wr(r){let e=Object.assign({},Ra,r);return de==null&&(de=oi(e),de.isWorker!==!0&&(de.addEventListener("requestReadLock",t=>{me[t.data.name]!=null&&me[t.data.name].readLock().then(async n=>t.data.handler().finally(()=>{n()}))}),de.addEventListener("requestWriteLock",async t=>{me[t.data.name]!=null&&me[t.data.name].writeLock().then(async n=>t.data.handler().finally(()=>{n()}))}))),me[e.name]==null&&(me[e.name]=Pa(e.name,e)),me[e.name]}var Vt=class{lock;child;pins;started;constructor(e,t,n={}){this.child=e,this.pins=t,this.lock=Wr({singleProcess:n.holdGcLock}),this.started=!1}isStarted(){return this.started}async start(){await ne(this.child),this.started=!0}async stop(){await oe(this.child),this.started=!1}unwrap(){return this.child}async put(e,t,n={}){let o=await this.lock.readLock();try{return await this.child.put(e,t,n)}finally{o()}}async*putMany(e,t={}){let n=await this.lock.readLock();try{yield*this.child.putMany(e,t)}finally{n()}}async get(e,t={}){let n=await this.lock.readLock();try{return await this.child.get(e,t)}finally{n()}}async*getMany(e,t={}){let n=await this.lock.readLock();try{yield*this.child.getMany(e,t)}finally{n()}}async delete(e,t={}){let n=await this.lock.writeLock();try{if(await this.pins.isPinned(e))throw new Error("CID was pinned");await this.child.delete(e,t)}finally{n()}}async*deleteMany(e,t={}){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 Error("CID was pinned");yield i}}(),t)}finally{n()}}async has(e,t={}){let n=await this.lock.readLock();try{return await this.child.has(e,t)}finally{n()}}async*getAll(e={}){let t=await this.lock.readLock();try{yield*this.child.getAll(e)}finally{t()}}};var si=42;function Oa(r){if(r.asCID!==r&&r["/"]!==r.bytes)return null;let e=C.asCID(r);if(!e)return null;let t=new Uint8Array(e.bytes.byteLength+1);return t.set(e.bytes,1),[new l(a.tag,si),new l(a.bytes,t)]}function $a(){throw new Error("`undefined` is not supported by the IPLD Data Model and cannot be encoded")}function Fa(r){if(Number.isNaN(r))throw new Error("`NaN` is not supported by the IPLD Data Model and cannot be encoded");if(r===1/0||r===-1/0)throw new Error("`Infinity` and `-Infinity` is not supported by the IPLD Data Model and cannot be encoded");return null}var ii={float64:!0,typeEncoders:{Object:Oa,undefined:$a,number:Fa}},jl={...ii,typeEncoders:{...ii.typeEncoders}};function Ma(r){if(r[0]!==0)throw new Error("Invalid CID for CBOR tag 42; expected leading 0x00");return C.decode(r.subarray(1))}var Hr={allowIndefinite:!1,coerceUndefinedToNull:!0,allowNaN:!1,allowInfinity:!1,allowBigInt:!0,strict:!0,useMaps:!1,rejectDuplicateMapKeys:!0,tags:[]};Hr.tags[si]=Ma;var Vl={...Hr,tags:Hr.tags.slice()};var ai=113;var ci=class extends Array{constructor(){super(),this.inRecursive=[]}prefix(e){let t=this.inRecursive[this.inRecursive.length-1];t&&(t.type===a.array&&(t.elements++,t.elements!==1&&e.push([44])),t.type===a.map&&(t.elements++,t.elements!==1&&(t.elements%2===1?e.push([44]):e.push([58]))))}[a.uint.major](e,t){this.prefix(e);let n=String(t.value),o=[];for(let i=0;i<n.length;i++)o[i]=n.charCodeAt(i);e.push(o)}[a.negint.major](e,t){this[a.uint.major](e,t)}[a.bytes.major](e,t){throw new Error(`${Te} unsupported type: Uint8Array`)}[a.string.major](e,t){this.prefix(e);let n=vt(JSON.stringify(t.value));e.push(n.length>32?je(n):n)}[a.array.major](e,t){this.prefix(e),this.inRecursive.push({type:a.array,elements:0}),e.push([91])}[a.map.major](e,t){this.prefix(e),this.inRecursive.push({type:a.map,elements:0}),e.push([123])}[a.tag.major](e,t){}[a.float.major](e,t){if(t.type.name==="break"){let s=this.inRecursive.pop();if(s){if(s.type===a.array)e.push([93]);else if(s.type===a.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(t.value===void 0)throw new Error(`${Te} unsupported type: undefined`);if(this.prefix(e),t.type.name==="true"){e.push([116,114,117,101]);return}else if(t.type.name==="false"){e.push([102,97,108,115,101]);return}else if(t.type.name==="null"){e.push([110,117,108,108]);return}let n=String(t.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)}};var ye=class{constructor(e,t={}){this._pos=0,this.data=e,this.options=t,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(`${p} unexpected end of input at position ${this._pos}`);for(let t=0;t<e.length;t++)if(this.data[this._pos++]!==e[t])throw new Error(`${p} unexpected token at position ${this._pos}, expected to find '${String.fromCharCode(...e)}'`)}parseNumber(){let e=this._pos,t=!1,n=!1,o=c=>{for(;!this.done();){let u=this.ch();if(c.includes(u))this._pos++;else break}};if(this.ch()===45&&(t=!0,this._pos++),this.ch()===48)if(this._pos++,this.ch()===46)this._pos++,n=!0;else return new l(a.uint,0,this._pos-e);if(o([48,49,50,51,52,53,54,55,56,57]),t&&this._pos===e+1)throw new Error(`${p} unexpected token at position ${this._pos}`);if(!this.done()&&this.ch()===46){if(n)throw new Error(`${p} 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 l(a.float,s,this._pos-e):this.options.allowBigInt!==!0||Number.isSafeInteger(s)?new l(s>=0?a.uint:a.negint,s,this._pos-e):new l(s>=0?a.uint:a.negint,BigInt(i),this._pos-e)}parseString(){if(this.ch()!==34)throw new Error(`${p} 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 c=this.data[i];if(c===92||c<32||c>=128)break;if(c===34){let u=String.fromCharCode.apply(null,this.data.subarray(this._pos,i));return this._pos=i+1,new l(a.string,u,s)}}let e=this._pos,t=[],n=()=>{if(this._pos+4>=this.data.length)throw new Error(`${p} unexpected end of unicode escape sequence at position ${this._pos}`);let i=0;for(let s=0;s<4;s++){let c=this.ch();if(c>=48&&c<=57)c-=48;else if(c>=97&&c<=102)c=c-97+10;else if(c>=65&&c<=70)c=c-65+10;else throw new Error(`${p} unexpected unicode escape character at position ${this._pos}`);i=i*16+c,this._pos++}return i},o=()=>{let i=this.ch(),s=null,c=i>239?4:i>223?3:i>191?2:1;if(this._pos+c>this.data.length)throw new Error(`${p} unexpected unicode sequence at position ${this._pos}`);let u,m,f,d;switch(c){case 1:i<128&&(s=i);break;case 2:u=this.data[this._pos+1],(u&192)===128&&(d=(i&31)<<6|u&63,d>127&&(s=d));break;case 3:u=this.data[this._pos+1],m=this.data[this._pos+2],(u&192)===128&&(m&192)===128&&(d=(i&15)<<12|(u&63)<<6|m&63,d>2047&&(d<55296||d>57343)&&(s=d));break;case 4:u=this.data[this._pos+1],m=this.data[this._pos+2],f=this.data[this._pos+3],(u&192)===128&&(m&192)===128&&(f&192)===128&&(d=(i&15)<<18|(u&63)<<12|(m&63)<<6|f&63,d>65535&&d<1114112&&(s=d))}s===null?(s=65533,c=1):s>65535&&(s-=65536,t.push(s>>>10&1023|55296),s=56320|s&1023),t.push(s),this._pos+=c};for(;!this.done();){let i=this.ch(),s;switch(i){case 92:if(this._pos++,this.done())throw new Error(`${p} unexpected string termination at position ${this._pos}`);switch(s=this.ch(),this._pos++,s){case 34:case 39:case 92:case 47:t.push(s);break;case 98:t.push(8);break;case 116:t.push(9);break;case 110:t.push(10);break;case 102:t.push(12);break;case 114:t.push(13);break;case 117:t.push(n());break;default:throw new Error(`${p} unexpected string escape character at position ${this._pos}`)}break;case 34:return this._pos++,new l(a.string,ar(t),this._pos-e);default:if(i<32)throw new Error(`${p} invalid control character at position ${this._pos}`);i<128?(t.push(i),this._pos++):o()}}throw new Error(`${p} unexpected end of string at position ${this._pos}`)}parseValue(){switch(this.ch()){case 123:return this.modeStack.push("obj-start"),this._pos++,new l(a.map,1/0,1);case 91:return this.modeStack.push("array-start"),this._pos++,new l(a.array,1/0,1);case 34:return this.parseString();case 110:return this.expect([110,117,108,108]),new l(a.null,null,4);case 102:return this.expect([102,97,108,115,101]),new l(a.false,!1,5);case 116:return this.expect([116,114,117,101]),new l(a.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(`${p} 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 l(a.break,void 0,1);if(this.ch()!==44)throw new Error(`${p} 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 l(a.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 l(a.break,void 0,1);if(this.ch()!==44)throw new Error(`${p} 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 l(a.break,void 0,1);let e=this.parseString();if(this.skipWhitespace(),this.ch()!==58)throw new Error(`${p} 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(`${p} unexpected parse state at position ${this._pos}; this shouldn't happen`)}}};function Wt(r,e){return e=Object.assign({tokenizer:new ye(r,e)},e),Y(r,e)}var ja={allowIndefinite:!1,allowUndefined:!1,allowNaN:!1,allowInfinity:!1,allowBigInt:!0,strict:!0,useMaps:!1,rejectDuplicateMapKeys:!0,tags:[]};ja.tags[42]=C.parse;var fi=297;var ad=new TextDecoder;var cd=new TextEncoder;var Wa=new TextDecoder;function Kr(r,e){let t=0;for(let n=0;;n+=7){if(n>=64)throw new Error("protobuf: varint overflow");if(e>=r.length)throw new Error("protobuf: unexpected end of data");let o=r[e++];if(t+=n<28?(o&127)<<n:(o&127)*2**n,o<128)break}return[t,e]}function Ht(r,e){let t;[t,e]=Kr(r,e);let n=e+t;if(t<0||n<0)throw new Error("protobuf: invalid length");if(n>r.length)throw new Error("protobuf: unexpected end of data");return[r.subarray(e,n),n]}function li(r,e){let t;return[t,e]=Kr(r,e),[t&7,t>>3,e]}function Ha(r){let e={},t=r.length,n=0;for(;n<t;){let o,i;if([o,i,n]=li(r,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]=Ht(r,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]=Ht(r,n),e.Name=Wa.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]=Kr(r,n)}else throw new Error(`protobuf: (PBLink) invalid fieldNumber, expected 1, 2 or 3, got ${i}`)}if(n>t)throw new Error("protobuf: (PBLink) unexpected end of data");return e}function di(r){let e=r.length,t=0,n,o=!1,i;for(;t<e;){let c,u;if([c,u,t]=li(r,t),c!==2)throw new Error(`protobuf: (PBNode) invalid wireType, expected 2, got ${c}`);if(u===1){if(i)throw new Error("protobuf: (PBNode) duplicate Data section");[i,t]=Ht(r,t),n&&(o=!0)}else if(u===2){if(o)throw new Error("protobuf: (PBNode) duplicate Links section");n||(n=[]);let m;[m,t]=Ht(r,t),n.push(Ha(m))}else throw new Error(`protobuf: (PBNode) invalid fieldNumber, expected 1 or 2, got ${u}`)}if(t>e)throw new Error("protobuf: (PBNode) unexpected end of data");let s={};return i&&(s.Data=i),s.Links=n||[],s}var fd=new TextEncoder,ld=2**32,dd=2**31;var md=new TextEncoder;var hi=112;function pi(r){let e=di(r),t={};return e.Data&&(t.Data=e.Data),e.Links&&(t.Links=e.Links.map(n=>{let o={};try{o.Hash=C.decode(n.Hash)}catch{}if(!o.Hash)throw new Error("Invalid Hash field found in link, expected CID");return n.Name!==void 0&&(o.Name=n.Name),n.Tsize!==void 0&&(o.Tsize=n.Tsize),o})),t}var Ga={codec:hi,*walk(r){yield*pi(r).Links.map(t=>t.Hash)}},Ja={codec:So,*walk(){}},mi=42,Qa={codec:ai,*walk(r){let e=[],t=[];t[mi]=n=>{if(n[0]!==0)throw new Error("Invalid CID for CBOR tag 42; expected leading 0x00");let o=C.decode(n.subarray(1));return e.push(o),o},Y(r,{tags:t}),yield*e}},Gr=class extends ye{tokenBuffer;constructor(e,t){super(e,t),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(e.type===a.map){let t=this._next();if(t.type===a.string&&t.value==="/"){let n=this._next();if(n.type===a.string){if(this._next().type!==a.break)throw new Error("Invalid encoded CID form");return this.tokenBuffer.push(n),new l(a.tag,42,0)}if(n.type===a.map){let o=this._next();if(o.type===a.string&&o.value==="bytes"){let i=this._next();if(i.type===a.string){for(let c=0;c<2;c++)if(this._next().type!==a.break)throw new Error("Invalid encoded Bytes form");let s=ke.decode(`m${i.value}`);return new l(a.bytes,s,i.value.length)}this.tokenBuffer.push(i)}this.tokenBuffer.push(o)}this.tokenBuffer.push(n)}this.tokenBuffer.push(t)}return e}},Ya={codec:fi,*walk(r){let e=[],t=[];t[mi]=n=>{let o=C.parse(n);return e.push(o),o},Wt(r,{tags:t,tokenizer:new Gr(r,{tags:t,allowIndefinite:!0,allowUndefined:!0,allowNaN:!0,allowInfinity:!0,allowBigInt:!0,strict:!1,rejectDuplicateMapKeys:!1})}),yield*e}},Xa={codec:Ao,*walk(){}};function yi(r=[]){let e={};return[Ga,Ja,Qa,Ya,Xa,...r].forEach(t=>{e[t.codec]=t}),e}var Jr=new te("/version"),gi=1;async function wi(r){if(!await r.has(Jr)){await r.put(Jr,Ot(`${gi}`));return}let e=await r.get(Jr),t=$t(e);if(parseInt(t,10)!==gi)throw new Error("Unknown datastore version, a datastore migration may be required")}function bi(r=[]){let e={};return[Re,Tr,Pe,...r].forEach(t=>{e[t.code]=t}),e}function xi(r){let e=new globalThis.AbortController;function t(){e.abort();for(let i of r)i?.removeEventListener!=null&&i.removeEventListener("abort",t)}for(let i of r){if(i?.aborted===!0){t();break}i?.addEventListener!=null&&i.addEventListener("abort",t)}function n(){for(let i of r)i?.removeEventListener!=null&&i.removeEventListener("abort",t)}let o=e.signal;return o.clear=n,o}function Za(r){let[e,t]=r[Symbol.asyncIterator]!=null?[r[Symbol.asyncIterator](),Symbol.asyncIterator]:[r[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(),[t](){return this}}}var Kt=Za;function ec(r){return r[Symbol.asyncIterator]!=null}function tc(r,e){if(ec(r))return async function*(){for await(let c of r)await e(c)&&(yield c)}();let t=Kt(r),{value:n,done:o}=t.next();if(o===!0)return function*(){}();let i=e(n);if(typeof i.then=="function")return async function*(){await i&&(yield n);for await(let c of t)await e(c)&&(yield c)}();let s=e;return function*(){i===!0&&(yield n);for(let c of t)s(c)&&(yield c)}()}var Ei=tc;function rc(r){return r[Symbol.asyncIterator]!=null}function ki(r){return r?.then!=null}function nc(r,e){if(rc(r))return async function*(){for await(let c of r){let u=e(c);ki(u)&&await u,yield c}}();let t=Kt(r),{value:n,done:o}=t.next();if(o===!0)return function*(){}();if(typeof e(n)?.then=="function")return async function*(){yield n;for await(let c of t){let u=e(c);ki(u)&&await u,yield c}}();let s=e;return function*(){yield n;for(let c of t)s(c),yield c}()}var Qr=nc;function oc(r){return typeof r.retrieve=="function"}function ic(r){return typeof r.announce=="function"}var Gt=class{child;blockRetrievers;blockAnnouncers;hashers;started;log;constructor(e){this.log=e.logger.forComponent("helia:networked-storage"),this.child=e.blockstore,this.blockRetrievers=(e.blockBrokers??[]).filter(oc),this.blockAnnouncers=(e.blockBrokers??[]).filter(ic),this.hashers=e.hashers??{},this.started=!1}isStarted(){return this.started}async start(){await ne(this.child,...new Set([...this.blockRetrievers,...this.blockAnnouncers])),this.started=!0}async stop(){await oe(this.child,...new Set([...this.blockRetrievers,...this.blockAnnouncers])),this.started=!1}unwrap(){return this.child}async put(e,t,n={}){return await this.child.has(e)?(n.onProgress?.(new k("blocks:put:duplicate",e)),e):(n.onProgress?.(new k("blocks:put:providers:notify",e)),this.blockAnnouncers.forEach(o=>{o.announce(e,t,n)}),n.onProgress?.(new k("blocks:put:blockstore:put",e)),this.child.put(e,t,n))}async*putMany(e,t={}){let n=Ei(e,async({cid:i})=>{let s=await this.child.has(i);return s&&t.onProgress?.(new k("blocks:put-many:duplicate",i)),!s}),o=Qr(n,({cid:i,block:s})=>{t.onProgress?.(new k("blocks:put-many:providers:notify",i)),this.blockAnnouncers.forEach(c=>{c.announce(i,s,t)})});t.onProgress?.(new k("blocks:put-many:blockstore:put-many")),yield*this.child.putMany(o,t)}async get(e,t={}){if(t.offline!==!0&&!await this.child.has(e)){t.onProgress?.(new k("blocks:get:providers:get",e));let n=await vi(e,this.blockRetrievers,this.hashers[e.multihash.code],{...t,log:this.log});return t.onProgress?.(new k("blocks:get:blockstore:put",e)),await this.child.put(e,n,t),t.onProgress?.(new k("blocks:get:providers:notify",e)),this.blockAnnouncers.forEach(o=>{o.announce(e,n,t)}),n}return t.onProgress?.(new k("blocks:get:blockstore:get",e)),this.child.get(e,t)}async*getMany(e,t={}){t.onProgress?.(new k("blocks:get-many:blockstore:get-many")),yield*this.child.getMany(Qr(e,async n=>{if(t.offline!==!0&&!await this.child.has(n)){t.onProgress?.(new k("blocks:get-many:providers:get",n));let o=await vi(n,this.blockRetrievers,this.hashers[n.multihash.code],{...t,log:this.log});t.onProgress?.(new k("blocks:get-many:blockstore:put",n)),await this.child.put(n,o,t),t.onProgress?.(new k("blocks:get-many:providers:notify",n)),this.blockAnnouncers.forEach(i=>{i.announce(n,o,t)})}}))}async delete(e,t={}){t.onProgress?.(new k("blocks:delete:blockstore:delete",e)),await this.child.delete(e,t)}async*deleteMany(e,t={}){t.onProgress?.(new k("blocks:delete-many:blockstore:delete-many")),yield*this.child.deleteMany(async function*(){for await(let n of e)yield n}(),t)}async has(e,t={}){return this.child.has(e,t)}async*getAll(e={}){e.onProgress?.(new k("blocks:get-all:blockstore:get-many")),yield*this.child.getAll(e)}},sc=(r,e)=>{if(e==null)throw new O(`No hasher configured for multihash code 0x${r.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`,"ERR_UNKNOWN_HASH_ALG");return async t=>{let n=await e.digest(t);if(!fe(n.digest,r.multihash.digest))throw new O("Hash of downloaded block did not match multihash from passed CID","ERR_HASH_MISMATCH")}};async function vi(r,e,t,n){let o=sc(r,t),i=new AbortController,s=xi([i.signal,n.signal]);try{return await Promise.any(e.map(async c=>{try{let u=!1,m=await c.retrieve(r,{...n,signal:s,validateFn:async f=>{await o(f),u=!0}});return u||await o(m),m}catch(u){throw n.log.error("could not retrieve verified block for %c",r,u),u}}))}finally{s.clear()}}var Yr=class{blockstore;datastore;pins;logger;routing;dagWalkers;hashers;log;constructor(e){this.logger=e.logger??mn(),this.log=this.logger.forComponent("helia"),this.hashers=bi(e.hashers),this.dagWalkers=yi(e.dagWalkers);let t={blockstore:e.blockstore,datastore:e.datastore,hashers:this.hashers,dagWalkers:this.dagWalkers,logger:this.logger,blockBrokers:[],...e.components??{}};t.blockBrokers=e.blockBrokers.map(o=>o(t));let n=new Gt(t);this.pins=new Mt(e.datastore,n,this.dagWalkers),this.blockstore=new Vt(n,this.pins,{holdGcLock:e.holdGcLock??!0}),this.datastore=e.datastore,this.routing=new qt(t,{routers:(e.routers??[]).flatMap(o=>{let i=[o];return o[Jt]!=null&&i.push(o[Jt]),o[Qt]!=null&&i.push(o[Qt]),i})})}async start(){await wi(this.datastore),await ne(this.blockstore,this.datastore,this.routing)}async stop(){await oe(this.blockstore,this.datastore,this.routing)}async gc(e={}){let t=await this.blockstore.lock.writeLock();try{let n=this,o=this.blockstore.unwrap();this.log("gc start"),await yn(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 k("helia:gc:deleted",i))}catch(s){n.log.error("Error during gc",s),e.onProgress?.(new k("helia:gc:error",s))}}()))}finally{t()}this.log("gc finished")}};return Ii(ac);})();
|
|
2
|
+
"use strict";var HeliaUtils=(()=>{var Oi=Object.create;var yt=Object.defineProperty;var $i=Object.getOwnPropertyDescriptor;var Mi=Object.getOwnPropertyNames;var zi=Object.getPrototypeOf,ji=Object.prototype.hasOwnProperty;var We=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),R=(r,e)=>{for(var t in e)yt(r,t,{get:e[t],enumerable:!0})},cn=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Mi(e))!ji.call(r,o)&&o!==t&&yt(r,o,{get:()=>e[o],enumerable:!(n=$i(e,o))||n.enumerable});return r};var rr=(r,e,t)=>(t=r!=null?Oi(zi(r)):{},cn(e||!r||!r.__esModule?yt(t,"default",{value:r,enumerable:!0}):t,r)),qi=r=>cn(yt({},"__esModule",{value:!0}),r);var hn=We((Bc,dn)=>{var be=1e3,xe=be*60,Ee=xe*60,he=Ee*24,Wi=he*7,Hi=he*365.25;dn.exports=function(r,e){e=e||{};var t=typeof r;if(t==="string"&&r.length>0)return Ki(r);if(t==="number"&&isFinite(r))return e.long?Ji(r):Gi(r);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(r))};function Ki(r){if(r=String(r),!(r.length>100)){var e=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(r);if(e){var t=parseFloat(e[1]),n=(e[2]||"ms").toLowerCase();switch(n){case"years":case"year":case"yrs":case"yr":case"y":return t*Hi;case"weeks":case"week":case"w":return t*Wi;case"days":case"day":case"d":return t*he;case"hours":case"hour":case"hrs":case"hr":case"h":return t*Ee;case"minutes":case"minute":case"mins":case"min":case"m":return t*xe;case"seconds":case"second":case"secs":case"sec":case"s":return t*be;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return t;default:return}}}}function Gi(r){var e=Math.abs(r);return e>=he?Math.round(r/he)+"d":e>=Ee?Math.round(r/Ee)+"h":e>=xe?Math.round(r/xe)+"m":e>=be?Math.round(r/be)+"s":r+"ms"}function Ji(r){var e=Math.abs(r);return e>=he?wt(r,e,he,"day"):e>=Ee?wt(r,e,Ee,"hour"):e>=xe?wt(r,e,xe,"minute"):e>=be?wt(r,e,be,"second"):r+" ms"}function wt(r,e,t,n){var o=e>=t*1.5;return Math.round(r/t)+" "+n+(o?"s":"")}});var mn=We((Dc,pn)=>{function Qi(r){t.debug=t,t.default=t,t.coerce=u,t.disable=i,t.enable=o,t.enabled=s,t.humanize=hn(),t.destroy=m,Object.keys(r).forEach(f=>{t[f]=r[f]}),t.names=[],t.skips=[],t.formatters={};function e(f){let d=0;for(let g=0;g<f.length;g++)d=(d<<5)-d+f.charCodeAt(g),d|=0;return t.colors[Math.abs(d)%t.colors.length]}t.selectColor=e;function t(f){let d,g=null,N,x;function w(...y){if(!w.enabled)return;let E=w,A=Number(new Date),_=A-(d||A);E.diff=_,E.prev=d,E.curr=A,d=A,y[0]=t.coerce(y[0]),typeof y[0]!="string"&&y.unshift("%O");let S=0;y[0]=y[0].replace(/%([a-zA-Z%])/g,(V,U)=>{if(V==="%%")return"%";S++;let W=t.formatters[U];if(typeof W=="function"){let we=y[S];V=W.call(E,we),y.splice(S,1),S--}return V}),t.formatArgs.call(E,y),(E.log||t.log).apply(E,y)}return w.namespace=f,w.useColors=t.useColors(),w.color=t.selectColor(f),w.extend=n,w.destroy=t.destroy,Object.defineProperty(w,"enabled",{enumerable:!0,configurable:!1,get:()=>g!==null?g:(N!==t.namespaces&&(N=t.namespaces,x=t.enabled(f)),x),set:y=>{g=y}}),typeof t.init=="function"&&t.init(w),w}function n(f,d){let g=t(this.namespace+(typeof d>"u"?":":d)+f);return g.log=this.log,g}function o(f){t.save(f),t.namespaces=f,t.names=[],t.skips=[];let d,g=(typeof f=="string"?f:"").split(/[\s,]+/),N=g.length;for(d=0;d<N;d++)g[d]&&(f=g[d].replace(/\*/g,".*?"),f[0]==="-"?t.skips.push(new RegExp("^"+f.slice(1)+"$")):t.names.push(new RegExp("^"+f+"$")))}function i(){let f=[...t.names.map(c),...t.skips.map(c).map(d=>"-"+d)].join(",");return t.enable(""),f}function s(f){if(f[f.length-1]==="*")return!0;let d,g;for(d=0,g=t.skips.length;d<g;d++)if(t.skips[d].test(f))return!1;for(d=0,g=t.names.length;d<g;d++)if(t.names[d].test(f))return!0;return!1}function c(f){return f.toString().substring(2,f.toString().length-2).replace(/\.\*\?$/,"*")}function u(f){return f instanceof Error?f.stack||f.message:f}function m(){console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.")}return t.enable(t.load()),t}pn.exports=Qi});var yn=We((O,bt)=>{O.formatArgs=Xi;O.save=Zi;O.load=es;O.useColors=Yi;O.storage=ts();O.destroy=(()=>{let r=!1;return()=>{r||(r=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})();O.colors=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"];function Yi(){return typeof window<"u"&&window.process&&(window.process.type==="renderer"||window.process.__nwjs)?!0:typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)?!1:typeof document<"u"&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||typeof window<"u"&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)&&parseInt(RegExp.$1,10)>=31||typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)}function Xi(r){if(r[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+r[0]+(this.useColors?"%c ":" ")+"+"+bt.exports.humanize(this.diff),!this.useColors)return;let e="color: "+this.color;r.splice(1,0,e,"color: inherit");let t=0,n=0;r[0].replace(/%[a-zA-Z%]/g,o=>{o!=="%%"&&(t++,o==="%c"&&(n=t))}),r.splice(n,0,e)}O.log=console.debug||console.log||(()=>{});function Zi(r){try{r?O.storage.setItem("debug",r):O.storage.removeItem("debug")}catch{}}function es(){let r;try{r=O.storage.getItem("debug")}catch{}return!r&&typeof process<"u"&&"env"in process&&(r=process.env.DEBUG),r}function ts(){try{return localStorage}catch{}}bt.exports=mn()(O);var{formatters:rs}=bt.exports;rs.j=function(r){try{return JSON.stringify(r)}catch(e){return"[UnexpectedJSONParseError]: "+e.message}}});var ii=We((Nl,jr)=>{"use strict";var Wa=Object.prototype.hasOwnProperty,D="~";function dt(){}Object.create&&(dt.prototype=Object.create(null),new dt().__proto__||(D=!1));function Ha(r,e,t){this.fn=r,this.context=e,this.once=t||!1}function oi(r,e,t,n,o){if(typeof t!="function")throw new TypeError("The listener must be a function");var i=new Ha(t,n||r,o),s=D?D+e:e;return r._events[s]?r._events[s].fn?r._events[s]=[r._events[s],i]:r._events[s].push(i):(r._events[s]=i,r._eventsCount++),r}function Wt(r,e){--r._eventsCount===0?r._events=new dt:delete r._events[e]}function L(){this._events=new dt,this._eventsCount=0}L.prototype.eventNames=function(){var e=[],t,n;if(this._eventsCount===0)return e;for(n in t=this._events)Wa.call(t,n)&&e.push(D?n.slice(1):n);return Object.getOwnPropertySymbols?e.concat(Object.getOwnPropertySymbols(t)):e};L.prototype.listeners=function(e){var t=D?D+e:e,n=this._events[t];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};L.prototype.listenerCount=function(e){var t=D?D+e:e,n=this._events[t];return n?n.fn?1:n.length:0};L.prototype.emit=function(e,t,n,o,i,s){var c=D?D+e:e;if(!this._events[c])return!1;var u=this._events[c],m=arguments.length,f,d;if(u.fn){switch(u.once&&this.removeListener(e,u.fn,void 0,!0),m){case 1:return u.fn.call(u.context),!0;case 2:return u.fn.call(u.context,t),!0;case 3:return u.fn.call(u.context,t,n),!0;case 4:return u.fn.call(u.context,t,n,o),!0;case 5:return u.fn.call(u.context,t,n,o,i),!0;case 6:return u.fn.call(u.context,t,n,o,i,s),!0}for(d=1,f=new Array(m-1);d<m;d++)f[d-1]=arguments[d];u.fn.apply(u.context,f)}else{var g=u.length,N;for(d=0;d<g;d++)switch(u[d].once&&this.removeListener(e,u[d].fn,void 0,!0),m){case 1:u[d].fn.call(u[d].context);break;case 2:u[d].fn.call(u[d].context,t);break;case 3:u[d].fn.call(u[d].context,t,n);break;case 4:u[d].fn.call(u[d].context,t,n,o);break;default:if(!f)for(N=1,f=new Array(m-1);N<m;N++)f[N-1]=arguments[N];u[d].fn.apply(u[d].context,f)}}return!0};L.prototype.on=function(e,t,n){return oi(this,e,t,n,!1)};L.prototype.once=function(e,t,n){return oi(this,e,t,n,!0)};L.prototype.removeListener=function(e,t,n,o){var i=D?D+e:e;if(!this._events[i])return this;if(!t)return Wt(this,i),this;var s=this._events[i];if(s.fn)s.fn===t&&(!o||s.once)&&(!n||s.context===n)&&Wt(this,i);else{for(var c=0,u=[],m=s.length;c<m;c++)(s[c].fn!==t||o&&!s[c].once||n&&s[c].context!==n)&&u.push(s[c]);u.length?this._events[i]=u.length===1?u[0]:u:Wt(this,i)}return this};L.prototype.removeAllListeners=function(e){var t;return e?(t=D?D+e:e,this._events[t]&&Wt(this,t)):(this._events=new dt,this._eventsCount=0),this};L.prototype.off=L.prototype.removeListener;L.prototype.addListener=L.prototype.on;L.prefixed=D;L.EventEmitter=L;typeof jr<"u"&&(jr.exports=L)});var Bi=We((eh,Li)=>{"use strict";function Ii(r,e){for(let t in e)Object.defineProperty(r,t,{value:e[t],enumerable:!0,configurable:!0});return r}function dc(r,e,t){if(!r||typeof r=="string")throw new TypeError("Please pass an Error to err-code");t||(t={}),typeof e=="object"&&(t=e,e=""),e&&(t.code=e);try{return Ii(r,t)}catch{t.message=r.message,t.stack=r.stack;let o=function(){};return o.prototype=Object.create(Object.getPrototypeOf(r)),Ii(new o,t)}}Li.exports=dc});var kc={};R(kc,{Helia:()=>an});var nr=Symbol.for("@libp2p/content-routing");var un=Symbol.for("@libp2p/peer-id");var or=Symbol.for("@libp2p/peer-routing");var re=class r extends Error{code;type;constructor(e="The operation was aborted"){super(e),this.code=r.code,this.type=r.type}static code="ABORT_ERR";static type="aborted"},F=class extends Error{code;props;constructor(e,t,n){super(e),this.code=t,this.name=n?.name??"CodeError",this.props=n??{}}};var gt=class extends EventTarget{#e=new Map;listenerCount(e){let t=this.#e.get(e);return t==null?0:t.length}addEventListener(e,t,n){super.addEventListener(e,t,n);let o=this.#e.get(e);o==null&&(o=[],this.#e.set(e,o)),o.push({callback:t,once:(n!==!0&&n!==!1&&n?.once)??!1})}removeEventListener(e,t,n){super.removeEventListener(e.toString(),t??null,n);let o=this.#e.get(e);o!=null&&(o=o.filter(({callback:i})=>i!==t),this.#e.set(e,o))}dispatchEvent(e){let t=super.dispatchEvent(e),n=this.#e.get(e.type);return n==null||(n=n.filter(({once:o})=>!o),this.#e.set(e.type,n)),t}safeDispatchEvent(e,t={}){return this.dispatchEvent(new Vi(e,t))}},ir=class extends Event{detail;constructor(e,t){super(e,t),this.detail=t?.detail}},Vi=globalThis.CustomEvent??ir;var fn=(r,...e)=>{try{[...e]}catch{}};function ln(r){return r!=null&&typeof r.start=="function"&&typeof r.stop=="function"}async function ne(...r){let e=[];for(let t of r)ln(t)&&e.push(t);await Promise.all(e.map(async t=>{t.beforeStart!=null&&await t.beforeStart()})),await Promise.all(e.map(async t=>{await t.start()})),await Promise.all(e.map(async t=>{t.afterStart!=null&&await t.afterStart()}))}async function oe(...r){let e=[];for(let t of r)ln(t)&&e.push(t);await Promise.all(e.map(async t=>{t.beforeStop!=null&&await t.beforeStop()})),await Promise.all(e.map(async t=>{await t.stop()})),await Promise.all(e.map(async t=>{t.afterStop!=null&&await t.afterStop()}))}var $=rr(yn(),1);var fr={};R(fr,{base32:()=>se,base32hex:()=>ls,base32hexpad:()=>hs,base32hexpadupper:()=>ps,base32hexupper:()=>ds,base32pad:()=>us,base32padupper:()=>fs,base32upper:()=>cs,base32z:()=>ms});var Nc=new Uint8Array(0);function gn(r,e){if(r===e)return!0;if(r.byteLength!==e.byteLength)return!1;for(let t=0;t<r.byteLength;t++)if(r[t]!==e[t])return!1;return!0}function X(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return r;if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return new Uint8Array(r.buffer,r.byteOffset,r.byteLength);throw new Error("Unknown type, must be binary type")}function wn(r){return new TextEncoder().encode(r)}function bn(r){return new TextDecoder().decode(r)}function ns(r,e){if(r.length>=255)throw new TypeError("Alphabet too long");for(var t=new Uint8Array(256),n=0;n<t.length;n++)t[n]=255;for(var o=0;o<r.length;o++){var i=r.charAt(o),s=i.charCodeAt(0);if(t[s]!==255)throw new TypeError(i+" is ambiguous");t[s]=o}var c=r.length,u=r.charAt(0),m=Math.log(c)/Math.log(256),f=Math.log(256)/Math.log(c);function d(x){if(x instanceof Uint8Array||(ArrayBuffer.isView(x)?x=new Uint8Array(x.buffer,x.byteOffset,x.byteLength):Array.isArray(x)&&(x=Uint8Array.from(x))),!(x instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(x.length===0)return"";for(var w=0,y=0,E=0,A=x.length;E!==A&&x[E]===0;)E++,w++;for(var _=(A-E)*f+1>>>0,S=new Uint8Array(_);E!==A;){for(var P=x[E],V=0,U=_-1;(P!==0||V<y)&&U!==-1;U--,V++)P+=256*S[U]>>>0,S[U]=P%c>>>0,P=P/c>>>0;if(P!==0)throw new Error("Non-zero carry");y=V,E++}for(var W=_-y;W!==_&&S[W]===0;)W++;for(var we=u.repeat(w);W<_;++W)we+=r.charAt(S[W]);return we}function g(x){if(typeof x!="string")throw new TypeError("Expected String");if(x.length===0)return new Uint8Array;var w=0;if(x[w]!==" "){for(var y=0,E=0;x[w]===u;)y++,w++;for(var A=(x.length-w)*m+1>>>0,_=new Uint8Array(A);x[w];){var S=t[x.charCodeAt(w)];if(S===255)return;for(var P=0,V=A-1;(S!==0||P<E)&&V!==-1;V--,P++)S+=c*_[V]>>>0,_[V]=S%256>>>0,S=S/256>>>0;if(S!==0)throw new Error("Non-zero carry");E=P,w++}if(x[w]!==" "){for(var U=A-E;U!==A&&_[U]===0;)U++;for(var W=new Uint8Array(y+(A-U)),we=y;U!==A;)W[we++]=_[U++];return W}}}function N(x){var w=g(x);if(w)return w;throw new Error(`Non-${e} character`)}return{encode:d,decodeUnsafe:g,decode:N}}var os=ns,is=os,En=is;var sr=class{name;prefix;baseEncode;constructor(e,t,n){this.name=e,this.prefix=t,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},ar=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,t,n){if(this.name=e,this.prefix=t,t.codePointAt(0)===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=t.codePointAt(0),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 kn(this,e)}},cr=class{decoders;constructor(e){this.decoders=e}or(e){return kn(this,e)}decode(e){let t=e[0],n=this.decoders[t];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 kn(r,e){return new cr({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}var ur=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,t,n,o){this.name=e,this.prefix=t,this.baseEncode=n,this.baseDecode=o,this.encoder=new sr(e,t,n),this.decoder=new ar(e,t,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function ke({name:r,prefix:e,encode:t,decode:n}){return new ur(r,e,t,n)}function ie({name:r,prefix:e,alphabet:t}){let{encode:n,decode:o}=En(t,r);return ke({prefix:e,name:r,encode:n,decode:i=>X(o(i))})}function ss(r,e,t,n){let o={};for(let f=0;f<e.length;++f)o[e[f]]=f;let i=r.length;for(;r[i-1]==="=";)--i;let s=new Uint8Array(i*t/8|0),c=0,u=0,m=0;for(let f=0;f<i;++f){let d=o[r[f]];if(d===void 0)throw new SyntaxError(`Non-${n} character`);u=u<<t|d,c+=t,c>=8&&(c-=8,s[m++]=255&u>>c)}if(c>=t||255&u<<8-c)throw new SyntaxError("Unexpected end of data");return s}function as(r,e,t){let n=e[e.length-1]==="=",o=(1<<t)-1,i="",s=0,c=0;for(let u=0;u<r.length;++u)for(c=c<<8|r[u],s+=8;s>t;)s-=t,i+=e[o&c>>s];if(s!==0&&(i+=e[o&c<<t-s]),n)for(;i.length*t&7;)i+="=";return i}function v({name:r,prefix:e,bitsPerChar:t,alphabet:n}){return ke({prefix:e,name:r,encode(o){return as(o,n,t)},decode(o){return ss(o,n,t,r)}})}var se=v({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),cs=v({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),us=v({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),fs=v({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),ls=v({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),ds=v({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),hs=v({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),ps=v({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),ms=v({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var lr={};R(lr,{base58btc:()=>B,base58flickr:()=>ys});var B=ie({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),ys=ie({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var dr={};R(dr,{base64:()=>ve,base64pad:()=>gs,base64url:()=>ws,base64urlpad:()=>bs});var ve=v({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),gs=v({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),ws=v({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),bs=v({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});$.default.formatters.b=r=>r==null?"undefined":B.baseEncode(r);$.default.formatters.t=r=>r==null?"undefined":se.baseEncode(r);$.default.formatters.m=r=>r==null?"undefined":ve.baseEncode(r);$.default.formatters.p=r=>r==null?"undefined":r.toString();$.default.formatters.c=r=>r==null?"undefined":r.toString();$.default.formatters.k=r=>r==null?"undefined":r.toString();$.default.formatters.a=r=>r==null?"undefined":r.toString();function xs(r){let e=()=>{};return e.enabled=!1,e.color="",e.diff=0,e.log=()=>{},e.namespace=r,e.destroy=()=>!0,e.extend=()=>e,e}function vn(){return{forComponent(r){return hr(r)}}}function hr(r){let e=xs(`${r}:trace`);return $.default.enabled(`${r}:trace`)&&$.default.names.map(t=>t.toString()).find(t=>t.includes(":trace"))!=null&&(e=(0,$.default)(`${r}:trace`)),Object.assign((0,$.default)(r),{error:(0,$.default)(`${r}:error`),trace:e})}function Es(r){return r[Symbol.asyncIterator]!=null}function ks(r){if(Es(r))return(async()=>{for await(let e of r);})();for(let e of r);}var He=ks;var k=class extends Event{constructor(e,t){super(e),this.detail=t}};function Ae(){let r={};return r.promise=new Promise((e,t)=>{r.resolve=e,r.reject=t}),r}var xt=class{buffer;mask;top;btm;next;constructor(e){if(!(e>0)||e-1&e)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}},Ce=class{size;hwm;head;tail;constructor(e={}){this.hwm=e.splitLimit??16,this.head=new xt(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 t=this.head;this.head=t.next=new xt(2*this.head.buffer.length),this.head.push(e)}}shift(){let e=this.tail.shift();if(e===void 0&&this.tail.next!=null){let t=this.tail.next;this.tail.next=null,this.tail=t,e=this.tail.shift()}return e?.value!=null&&(this.size-=this.calculateSize(e.value)),e}isEmpty(){return this.head.isEmpty()}};var pr=class extends Error{type;code;constructor(e,t){super(e??"The operation was aborted"),this.type="aborted",this.code=t??"ABORT_ERR"}};function pe(r={}){return vs(t=>{let n=t.shift();if(n==null)return{done:!0};if(n.error!=null)throw n.error;return{done:n.done===!0,value:n.value}},r)}function vs(r,e){e=e??{};let t=e.onEnd,n=new Ce,o,i,s,c=Ae(),u=async()=>{try{return n.isEmpty()?s?{done:!0}:await new Promise((y,E)=>{i=A=>{i=null,n.push(A);try{y(r(n))}catch(_){E(_)}return o}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{c.resolve(),c=Ae()})}},m=y=>i!=null?i(y):(n.push(y),o),f=y=>(n=new Ce,i!=null?i({error:y}):(n.push({error:y}),o)),d=y=>{if(s)return o;if(e?.objectMode!==!0&&y?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return m({done:!1,value:y})},g=y=>s?o:(s=!0,y!=null?f(y):m({done:!0})),N=()=>(n=new Ce,g(),{done:!0}),x=y=>(g(y),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:u,return:N,throw:x,push:d,end:g,get readableLength(){return n.size},onEmpty:async y=>{let E=y?.signal;if(E?.throwIfAborted(),n.isEmpty())return;let A,_;E!=null&&(A=new Promise((S,P)=>{_=()=>{P(new pr)},E.addEventListener("abort",_)}));try{await Promise.race([c.promise,A])}finally{_!=null&&E!=null&&E?.removeEventListener("abort",_)}}},t==null)return o;let w=o;return o={[Symbol.asyncIterator](){return this},next(){return w.next()},throw(y){return w.throw(y),t!=null&&(t(y),t=void 0),{done:!0}},return(){return w.return(),t!=null&&(t(),t=void 0),{done:!0}},push:d,end(y){return w.end(y),t!=null&&(t(y),t=void 0),o},get readableLength(){return w.readableLength},onEmpty:y=>w.onEmpty(y)},o}var mr=class extends Error{type;code;constructor(e,t){super(e??"The operation was aborted"),this.type="aborted",this.name="AbortError",this.code=t??"ABORT_ERR"}};async function Et(r,e,t,n){let o=new mr(n?.errorMessage,n?.errorCode);return t?.aborted===!0?Promise.reject(o):new Promise((i,s)=>{let c=m=>{try{if(n?.filter?.(m)===!1)return}catch(f){r.removeEventListener(e,c),t?.removeEventListener("abort",u),s(f);return}r.removeEventListener(e,c),t?.removeEventListener("abort",u),i(m)},u=()=>{r.removeEventListener(e,c),t?.removeEventListener("abort",u),s(o)};r.addEventListener(e,c),t?.addEventListener("abort",u)})}var kt=class extends Error{type;code;constructor(e,t){super(e??"The operation was aborted"),this.type="aborted",this.name="AbortError",this.code=t??"ABORT_ERR"}};async function An(r,e,t){if(e==null)return r;if(e.aborted)return Promise.reject(new kt(t?.errorMessage,t?.errorCode));let n,o=new kt(t?.errorMessage,t?.errorCode);try{return await Promise.race([r,new Promise((i,s)=>{n=()=>{s(o)},e.addEventListener("abort",n)})])}finally{n!=null&&e.removeEventListener("abort",n)}}var vt=class{deferred;signal;where;constructor(e,t){this.signal=t,this.deferred=Ae(),this.where=e,this.onAbort=this.onAbort.bind(this),this.signal?.addEventListener("abort",this.onAbort)}onAbort(){this.deferred.reject(new re)}cleanup(){this.signal?.removeEventListener("abort",this.onAbort)}};function As(){return`${parseInt(String(Math.random()*1e9),10).toString()}${Date.now()}`}var At=class{id;fn;options;priority;recipients;status;timeline;controller;constructor(e,t,n=0){this.id=As(),this.status="queued",this.fn=e,this.priority=n,this.options=t,this.recipients=[],this.timeline={created:Date.now()},this.controller=new AbortController,fn(1/0,this.controller.signal),this.onAbort=this.onAbort.bind(this)}abort(e){this.controller.abort(e)}onAbort(){this.recipients.reduce((t,n)=>t&&n.signal?.aborted===!0,!0)&&this.controller.abort(new re)}async join(e={}){let t=new vt(new Error("where").stack,e.signal);return this.recipients.push(t),e.signal?.addEventListener("abort",this.onAbort),t.deferred.promise}async run(){this.status="running",this.timeline.started=Date.now();try{this.controller.signal.throwIfAborted();let e=await An(this.fn({...this.options??{},signal:this.controller.signal}),this.controller.signal);this.recipients.forEach(t=>{t.deferred.resolve(e)}),this.status="complete"}catch(e){this.recipients.forEach(t=>{t.deferred.reject(e)}),this.status="errored"}finally{this.timeline.finished=Date.now(),this.cleanup()}}cleanup(){this.recipients.forEach(e=>{e.signal?.removeEventListener("abort",this.onAbort)})}};function Cs(r,e,t){let n=0,o=r.length;for(;o>0;){let i=Math.trunc(o/2),s=n+i;t(r[s],e)<=0?(n=++s,o-=i+1):o=i}return n}var Ke=class extends gt{concurrency;queue;pending;constructor(e={}){super(),this.concurrency=e.concurrency??Number.POSITIVE_INFINITY,this.pending=0,e.metricName!=null&&e.metrics?.registerMetricGroup(e.metricName,{calculate:()=>({size:this.queue.length,running:this.pending,queued:this.queue.length-this.pending})}),this.queue=[]}tryToStartAnother(){if(this.size===0)return queueMicrotask(()=>{this.safeDispatchEvent("empty")}),this.running===0&&queueMicrotask(()=>{this.safeDispatchEvent("idle")}),!1;if(this.pending<this.concurrency){let e;for(let t of this.queue)if(t.status==="queued"){e=t;break}return e==null?!1:(this.safeDispatchEvent("active"),this.pending++,e.run().finally(()=>{for(let t=0;t<this.queue.length;t++)if(this.queue[t]===e){this.queue.splice(t,1);break}this.pending--,this.tryToStartAnother(),this.safeDispatchEvent("next")}),!0)}return!1}enqueue(e){if(this.queue[this.size-1]?.priority>=e.priority){this.queue.push(e);return}let t=Cs(this.queue,e,(n,o)=>o.priority-n.priority);this.queue.splice(t,0,e)}async add(e,t){t?.signal?.throwIfAborted();let n=new At(e,t,t?.priority),o=n.join(t).then(i=>(this.safeDispatchEvent("completed",{detail:i}),i)).catch(i=>{throw this.safeDispatchEvent("error",{detail:i}),i});return this.enqueue(n),this.safeDispatchEvent("add"),this.tryToStartAnother(),o}clear(){this.queue.splice(0,this.queue.length)}abort(){this.queue.forEach(e=>{e.abort(new re)}),this.clear()}async onEmpty(e){this.size!==0&&await Et(this,"empty",e?.signal)}async onSizeLessThan(e,t){this.size<e||await Et(this,"next",t?.signal,{filter:()=>this.size<e})}async onIdle(e){this.pending===0&&this.size===0||await Et(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 t=pe({objectMode:!0}),n=u=>{u!=null?this.abort():this.clear(),t.end(u)},o=u=>{u.detail!=null&&t.push(u.detail)},i=u=>{n(u.detail)},s=()=>{n()},c=()=>{n(new F("Queue aborted","ERR_QUEUE_ABORTED"))};this.addEventListener("completed",o),this.addEventListener("error",i),this.addEventListener("idle",s),e?.signal?.addEventListener("abort",c);try{yield*t}finally{this.removeEventListener("completed",o),this.removeEventListener("error",i),this.removeEventListener("idle",s),e?.signal?.removeEventListener("abort",c),n()}}};var _s=["string","number","bigint","symbol"],Ss=["Function","Generator","AsyncGenerator","GeneratorFunction","AsyncGeneratorFunction","AsyncFunction","Observable","Array","Buffer","Object","RegExp","Date","Error","Map","Set","WeakMap","WeakSet","ArrayBuffer","SharedArrayBuffer","DataView","Promise","URL","HTMLElement","Int8Array","Uint8Array","Uint8ClampedArray","Int16Array","Uint16Array","Int32Array","Uint32Array","Float32Array","Float64Array","BigInt64Array","BigUint64Array"];function Cn(r){if(r===null)return"null";if(r===void 0)return"undefined";if(r===!0||r===!1)return"boolean";let e=typeof r;if(_s.includes(e))return e;if(e==="function")return"Function";if(Array.isArray(r))return"Array";if(Ts(r))return"Buffer";let t=Is(r);return t||"Object"}function Ts(r){return r&&r.constructor&&r.constructor.isBuffer&&r.constructor.isBuffer.call(null,r)}function Is(r){let e=Object.prototype.toString.call(r).slice(8,-1);if(Ss.includes(e))return e}var a=class{constructor(e,t,n){this.major=e,this.majorEncoded=e<<5,this.name=t,this.terminal=n}toString(){return`Type[${this.major}].${this.name}`}compare(e){return this.major<e.major?-1:this.major>e.major?1:0}};a.uint=new a(0,"uint",!0);a.negint=new a(1,"negint",!0);a.bytes=new a(2,"bytes",!0);a.string=new a(3,"string",!0);a.array=new a(4,"array",!1);a.map=new a(5,"map",!1);a.tag=new a(6,"tag",!1);a.float=new a(7,"float",!0);a.false=new a(7,"false",!0);a.true=new a(7,"true",!0);a.null=new a(7,"null",!0);a.undefined=new a(7,"undefined",!0);a.break=new a(7,"break",!0);var l=class{constructor(e,t,n){this.type=e,this.value=t,this.encodedLength=n,this.encodedBytes=void 0,this.byteValue=void 0}toString(){return`Token[${this.type}].${this.value}`}};var _e=globalThis.process&&!globalThis.process.browser&&globalThis.Buffer&&typeof globalThis.Buffer.isBuffer=="function",Ls=new TextDecoder,Bs=new TextEncoder;function Ct(r){return _e&&globalThis.Buffer.isBuffer(r)}function Ge(r){return r instanceof Uint8Array?Ct(r)?new Uint8Array(r.buffer,r.byteOffset,r.byteLength):r:Uint8Array.from(r)}var In=_e?(r,e,t)=>t-e>64?globalThis.Buffer.from(r.subarray(e,t)).toString("utf8"):Sn(r,e,t):(r,e,t)=>t-e>64?Ls.decode(r.subarray(e,t)):Sn(r,e,t),_t=_e?r=>r.length>64?globalThis.Buffer.from(r):_n(r):r=>r.length>64?Bs.encode(r):_n(r),Q=r=>Uint8Array.from(r),Se=_e?(r,e,t)=>Ct(r)?new Uint8Array(r.subarray(e,t)):r.slice(e,t):(r,e,t)=>r.slice(e,t),Ln=_e?(r,e)=>(r=r.map(t=>t instanceof Uint8Array?t:globalThis.Buffer.from(t)),Ge(globalThis.Buffer.concat(r,e))):(r,e)=>{let t=new Uint8Array(e),n=0;for(let o of r)n+o.length>t.length&&(o=o.subarray(0,t.length-n)),t.set(o,n),n+=o.length;return t},Bn=_e?r=>globalThis.Buffer.allocUnsafe(r):r=>new Uint8Array(r);function Dn(r,e){if(Ct(r)&&Ct(e))return r.compare(e);for(let t=0;t<r.length;t++)if(r[t]!==e[t])return r[t]<e[t]?-1:1;return 0}function _n(r){let e=[],t=0;for(let n=0;n<r.length;n++){let o=r.charCodeAt(n);o<128?e[t++]=o:o<2048?(e[t++]=o>>6|192,e[t++]=o&63|128):(o&64512)===55296&&n+1<r.length&&(r.charCodeAt(n+1)&64512)===56320?(o=65536+((o&1023)<<10)+(r.charCodeAt(++n)&1023),e[t++]=o>>18|240,e[t++]=o>>12&63|128,e[t++]=o>>6&63|128,e[t++]=o&63|128):(e[t++]=o>>12|224,e[t++]=o>>6&63|128,e[t++]=o&63|128)}return e}function Sn(r,e,t){let n=[];for(;e<t;){let o=r[e],i=null,s=o>239?4:o>223?3:o>191?2:1;if(e+s<=t){let c,u,m,f;switch(s){case 1:o<128&&(i=o);break;case 2:c=r[e+1],(c&192)===128&&(f=(o&31)<<6|c&63,f>127&&(i=f));break;case 3:c=r[e+1],u=r[e+2],(c&192)===128&&(u&192)===128&&(f=(o&15)<<12|(c&63)<<6|u&63,f>2047&&(f<55296||f>57343)&&(i=f));break;case 4:c=r[e+1],u=r[e+2],m=r[e+3],(c&192)===128&&(u&192)===128&&(m&192)===128&&(f=(o&15)<<18|(c&63)<<12|(u&63)<<6|m&63,f>65535&&f<1114112&&(i=f))}}i===null?(i=65533,s=1):i>65535&&(i-=65536,n.push(i>>>10&1023|55296),i=56320|i&1023),n.push(i),e+=s}return yr(n)}var Tn=4096;function yr(r){let e=r.length;if(e<=Tn)return String.fromCharCode.apply(String,r);let t="",n=0;for(;n<e;)t+=String.fromCharCode.apply(String,r.slice(n,n+=Tn));return t}var Ds=256,Je=class{constructor(e=Ds){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 t=this.chunks[this.chunks.length-1];if(this.cursor+e.length<=this.maxCursor+1){let o=t.length-(this.maxCursor-this.cursor)-1;t.set(e,o)}else{if(t){let o=t.length-(this.maxCursor-this.cursor)-1;o<t.length&&(this.chunks[this.chunks.length-1]=t.subarray(0,o),this.maxCursor=this.cursor-1)}e.length<64&&e.length<this.chunkSize?(t=Bn(this.chunkSize),this.chunks.push(t),this.maxCursor+=t.length,this._initReuseChunk===null&&(this._initReuseChunk=t),t.set(e,0)):(this.chunks.push(e),this.maxCursor+=e.length)}this.cursor+=e.length}toBytes(e=!1){let t;if(this.chunks.length===1){let n=this.chunks[0];e&&this.cursor>n.length/2?(t=this.cursor===n.length?n:n.subarray(0,this.cursor),this._initReuseChunk=null,this.chunks=[]):t=Se(n,0,this.cursor)}else t=Ln(this.chunks,this.cursor);return e&&this.reset(),t}};var p="CBOR decode error:",Te="CBOR encode error:",Qe=[];Qe[23]=1;Qe[24]=2;Qe[25]=3;Qe[26]=5;Qe[27]=9;function Z(r,e,t){if(r.length-e<t)throw new Error(`${p} not enough data for type`)}var T=[24,256,65536,4294967296,BigInt("18446744073709551616")];function M(r,e,t){Z(r,e,1);let n=r[e];if(t.strict===!0&&n<T[0])throw new Error(`${p} integer encoded in more bytes than necessary (strict decode)`);return n}function z(r,e,t){Z(r,e,2);let n=r[e]<<8|r[e+1];if(t.strict===!0&&n<T[1])throw new Error(`${p} integer encoded in more bytes than necessary (strict decode)`);return n}function j(r,e,t){Z(r,e,4);let n=r[e]*16777216+(r[e+1]<<16)+(r[e+2]<<8)+r[e+3];if(t.strict===!0&&n<T[2])throw new Error(`${p} integer encoded in more bytes than necessary (strict decode)`);return n}function q(r,e,t){Z(r,e,8);let n=r[e]*16777216+(r[e+1]<<16)+(r[e+2]<<8)+r[e+3],o=r[e+4]*16777216+(r[e+5]<<16)+(r[e+6]<<8)+r[e+7],i=(BigInt(n)<<BigInt(32))+BigInt(o);if(t.strict===!0&&i<T[3])throw new Error(`${p} integer encoded in more bytes than necessary (strict decode)`);if(i<=Number.MAX_SAFE_INTEGER)return Number(i);if(t.allowBigInt===!0)return i;throw new Error(`${p} integers outside of the safe integer range are not supported`)}function Nn(r,e,t,n){return new l(a.uint,M(r,e+1,n),2)}function Pn(r,e,t,n){return new l(a.uint,z(r,e+1,n),3)}function Un(r,e,t,n){return new l(a.uint,j(r,e+1,n),5)}function Rn(r,e,t,n){return new l(a.uint,q(r,e+1,n),9)}function H(r,e){return I(r,0,e.value)}function I(r,e,t){if(t<T[0]){let n=Number(t);r.push([e|n])}else if(t<T[1]){let n=Number(t);r.push([e|24,n])}else if(t<T[2]){let n=Number(t);r.push([e|25,n>>>8,n&255])}else if(t<T[3]){let n=Number(t);r.push([e|26,n>>>24&255,n>>>16&255,n>>>8&255,n&255])}else{let n=BigInt(t);if(n<T[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,r.push(o)}else throw new Error(`${p} encountered BigInt larger than allowable range`)}}H.encodedSize=function(e){return I.encodedSize(e.value)};I.encodedSize=function(e){return e<T[0]?1:e<T[1]?2:e<T[2]?3:e<T[3]?5:9};H.compareTokens=function(e,t){return e.value<t.value?-1:e.value>t.value?1:0};function Fn(r,e,t,n){return new l(a.negint,-1-M(r,e+1,n),2)}function On(r,e,t,n){return new l(a.negint,-1-z(r,e+1,n),3)}function $n(r,e,t,n){return new l(a.negint,-1-j(r,e+1,n),5)}var gr=BigInt(-1),Mn=BigInt(1);function zn(r,e,t,n){let o=q(r,e+1,n);if(typeof o!="bigint"){let i=-1-o;if(i>=Number.MIN_SAFE_INTEGER)return new l(a.negint,i,9)}if(n.allowBigInt!==!0)throw new Error(`${p} integers outside of the safe integer range are not supported`);return new l(a.negint,gr-BigInt(o),9)}function St(r,e){let t=e.value,n=typeof t=="bigint"?t*gr-Mn:t*-1-1;I(r,e.type.majorEncoded,n)}St.encodedSize=function(e){let t=e.value,n=typeof t=="bigint"?t*gr-Mn:t*-1-1;return n<T[0]?1:n<T[1]?2:n<T[2]?3:n<T[3]?5:9};St.compareTokens=function(e,t){return e.value<t.value?1:e.value>t.value?-1:0};function Ye(r,e,t,n){Z(r,e,t+n);let o=Se(r,e+t,e+t+n);return new l(a.bytes,o,t+n)}function jn(r,e,t,n){return Ye(r,e,1,t)}function qn(r,e,t,n){return Ye(r,e,2,M(r,e+1,n))}function Vn(r,e,t,n){return Ye(r,e,3,z(r,e+1,n))}function Wn(r,e,t,n){return Ye(r,e,5,j(r,e+1,n))}function Hn(r,e,t,n){let o=q(r,e+1,n);if(typeof o=="bigint")throw new Error(`${p} 64-bit integer bytes lengths not supported`);return Ye(r,e,9,o)}function Tt(r){return r.encodedBytes===void 0&&(r.encodedBytes=r.type===a.string?_t(r.value):r.value),r.encodedBytes}function Ie(r,e){let t=Tt(e);I(r,e.type.majorEncoded,t.length),r.push(t)}Ie.encodedSize=function(e){let t=Tt(e);return I.encodedSize(t.length)+t.length};Ie.compareTokens=function(e,t){return Ps(Tt(e),Tt(t))};function Ps(r,e){return r.length<e.length?-1:r.length>e.length?1:Dn(r,e)}function Xe(r,e,t,n,o){let i=t+n;Z(r,e,i);let s=new l(a.string,In(r,e+t,e+i),i);return o.retainStringBytes===!0&&(s.byteValue=Se(r,e+t,e+i)),s}function Kn(r,e,t,n){return Xe(r,e,1,t,n)}function Gn(r,e,t,n){return Xe(r,e,2,M(r,e+1,n),n)}function Jn(r,e,t,n){return Xe(r,e,3,z(r,e+1,n),n)}function Qn(r,e,t,n){return Xe(r,e,5,j(r,e+1,n),n)}function Yn(r,e,t,n){let o=q(r,e+1,n);if(typeof o=="bigint")throw new Error(`${p} 64-bit integer string lengths not supported`);return Xe(r,e,9,o,n)}var Xn=Ie;function Le(r,e,t,n){return new l(a.array,n,t)}function Zn(r,e,t,n){return Le(r,e,1,t)}function eo(r,e,t,n){return Le(r,e,2,M(r,e+1,n))}function to(r,e,t,n){return Le(r,e,3,z(r,e+1,n))}function ro(r,e,t,n){return Le(r,e,5,j(r,e+1,n))}function no(r,e,t,n){let o=q(r,e+1,n);if(typeof o=="bigint")throw new Error(`${p} 64-bit integer array lengths not supported`);return Le(r,e,9,o)}function oo(r,e,t,n){if(n.allowIndefinite===!1)throw new Error(`${p} indefinite length items not allowed`);return Le(r,e,1,1/0)}function It(r,e){I(r,a.array.majorEncoded,e.value)}It.compareTokens=H.compareTokens;It.encodedSize=function(e){return I.encodedSize(e.value)};function Be(r,e,t,n){return new l(a.map,n,t)}function io(r,e,t,n){return Be(r,e,1,t)}function so(r,e,t,n){return Be(r,e,2,M(r,e+1,n))}function ao(r,e,t,n){return Be(r,e,3,z(r,e+1,n))}function co(r,e,t,n){return Be(r,e,5,j(r,e+1,n))}function uo(r,e,t,n){let o=q(r,e+1,n);if(typeof o=="bigint")throw new Error(`${p} 64-bit integer map lengths not supported`);return Be(r,e,9,o)}function fo(r,e,t,n){if(n.allowIndefinite===!1)throw new Error(`${p} indefinite length items not allowed`);return Be(r,e,1,1/0)}function Lt(r,e){I(r,a.map.majorEncoded,e.value)}Lt.compareTokens=H.compareTokens;Lt.encodedSize=function(e){return I.encodedSize(e.value)};function lo(r,e,t,n){return new l(a.tag,t,1)}function ho(r,e,t,n){return new l(a.tag,M(r,e+1,n),2)}function po(r,e,t,n){return new l(a.tag,z(r,e+1,n),3)}function mo(r,e,t,n){return new l(a.tag,j(r,e+1,n),5)}function yo(r,e,t,n){return new l(a.tag,q(r,e+1,n),9)}function Bt(r,e){I(r,a.tag.majorEncoded,e.value)}Bt.compareTokens=H.compareTokens;Bt.encodedSize=function(e){return I.encodedSize(e.value)};var Ms=20,zs=21,js=22,qs=23;function go(r,e,t,n){if(n.allowUndefined===!1)throw new Error(`${p} undefined values are not supported`);return n.coerceUndefinedToNull===!0?new l(a.null,null,1):new l(a.undefined,void 0,1)}function wo(r,e,t,n){if(n.allowIndefinite===!1)throw new Error(`${p} indefinite length items not allowed`);return new l(a.break,void 0,1)}function wr(r,e,t){if(t){if(t.allowNaN===!1&&Number.isNaN(r))throw new Error(`${p} NaN values are not supported`);if(t.allowInfinity===!1&&(r===1/0||r===-1/0))throw new Error(`${p} Infinity values are not supported`)}return new l(a.float,r,e)}function bo(r,e,t,n){return wr(br(r,e+1),3,n)}function xo(r,e,t,n){return wr(xr(r,e+1),5,n)}function Eo(r,e,t,n){return wr(Co(r,e+1),9,n)}function Dt(r,e,t){let n=e.value;if(n===!1)r.push([a.float.majorEncoded|Ms]);else if(n===!0)r.push([a.float.majorEncoded|zs]);else if(n===null)r.push([a.float.majorEncoded|js]);else if(n===void 0)r.push([a.float.majorEncoded|qs]);else{let o,i=!1;(!t||t.float64!==!0)&&(vo(n),o=br(G,1),n===o||Number.isNaN(n)?(G[0]=249,r.push(G.slice(0,3)),i=!0):(Ao(n),o=xr(G,1),n===o&&(G[0]=250,r.push(G.slice(0,5)),i=!0))),i||(Vs(n),o=Co(G,1),G[0]=251,r.push(G.slice(0,9)))}}Dt.encodedSize=function(e,t){let n=e.value;if(n===!1||n===!0||n===null||n===void 0)return 1;if(!t||t.float64!==!0){vo(n);let o=br(G,1);if(n===o||Number.isNaN(n))return 3;if(Ao(n),o=xr(G,1),n===o)return 5}return 9};var ko=new ArrayBuffer(9),K=new DataView(ko,1),G=new Uint8Array(ko,0);function vo(r){if(r===1/0)K.setUint16(0,31744,!1);else if(r===-1/0)K.setUint16(0,64512,!1);else if(Number.isNaN(r))K.setUint16(0,32256,!1);else{K.setFloat32(0,r);let e=K.getUint32(0),t=(e&2139095040)>>23,n=e&8388607;if(t===255)K.setUint16(0,31744,!1);else if(t===0)K.setUint16(0,(r&2147483648)>>16|n>>13,!1);else{let o=t-127;o<-24?K.setUint16(0,0):o<-14?K.setUint16(0,(e&2147483648)>>16|1<<24+o,!1):K.setUint16(0,(e&2147483648)>>16|o+15<<10|n>>13,!1)}}}function br(r,e){if(r.length-e<2)throw new Error(`${p} not enough data for float16`);let t=(r[e]<<8)+r[e+1];if(t===31744)return 1/0;if(t===64512)return-1/0;if(t===32256)return NaN;let n=t>>10&31,o=t&1023,i;return n===0?i=o*2**-24:n!==31?i=(o+1024)*2**(n-25):i=o===0?1/0:NaN,t&32768?-i:i}function Ao(r){K.setFloat32(0,r,!1)}function xr(r,e){if(r.length-e<4)throw new Error(`${p} not enough data for float32`);let t=(r.byteOffset||0)+e;return new DataView(r.buffer,t,4).getFloat32(0,!1)}function Vs(r){K.setFloat64(0,r,!1)}function Co(r,e){if(r.length-e<8)throw new Error(`${p} not enough data for float64`);let t=(r.byteOffset||0)+e;return new DataView(r.buffer,t,8).getFloat64(0,!1)}Dt.compareTokens=H.compareTokens;function b(r,e,t){throw new Error(`${p} encountered invalid minor (${t}) for major ${r[e]>>>5}`)}function Nt(r){return()=>{throw new Error(`${p} ${r}`)}}var h=[];for(let r=0;r<=23;r++)h[r]=b;h[24]=Nn;h[25]=Pn;h[26]=Un;h[27]=Rn;h[28]=b;h[29]=b;h[30]=b;h[31]=b;for(let r=32;r<=55;r++)h[r]=b;h[56]=Fn;h[57]=On;h[58]=$n;h[59]=zn;h[60]=b;h[61]=b;h[62]=b;h[63]=b;for(let r=64;r<=87;r++)h[r]=jn;h[88]=qn;h[89]=Vn;h[90]=Wn;h[91]=Hn;h[92]=b;h[93]=b;h[94]=b;h[95]=Nt("indefinite length bytes/strings are not supported");for(let r=96;r<=119;r++)h[r]=Kn;h[120]=Gn;h[121]=Jn;h[122]=Qn;h[123]=Yn;h[124]=b;h[125]=b;h[126]=b;h[127]=Nt("indefinite length bytes/strings are not supported");for(let r=128;r<=151;r++)h[r]=Zn;h[152]=eo;h[153]=to;h[154]=ro;h[155]=no;h[156]=b;h[157]=b;h[158]=b;h[159]=oo;for(let r=160;r<=183;r++)h[r]=io;h[184]=so;h[185]=ao;h[186]=co;h[187]=uo;h[188]=b;h[189]=b;h[190]=b;h[191]=fo;for(let r=192;r<=215;r++)h[r]=lo;h[216]=ho;h[217]=po;h[218]=mo;h[219]=yo;h[220]=b;h[221]=b;h[222]=b;h[223]=b;for(let r=224;r<=243;r++)h[r]=Nt("simple values are not supported");h[244]=b;h[245]=b;h[246]=b;h[247]=go;h[248]=Nt("simple values are not supported");h[249]=bo;h[250]=xo;h[251]=Eo;h[252]=b;h[253]=b;h[254]=b;h[255]=wo;var J=[];for(let r=0;r<24;r++)J[r]=new l(a.uint,r,1);for(let r=-1;r>=-24;r--)J[31-r]=new l(a.negint,r,1);J[64]=new l(a.bytes,new Uint8Array(0),1);J[96]=new l(a.string,"",1);J[128]=new l(a.array,0,1);J[160]=new l(a.map,0,1);J[244]=new l(a.false,!1,1);J[245]=new l(a.true,!0,1);J[246]=new l(a.null,null,1);function _o(r){switch(r.type){case a.false:return Q([244]);case a.true:return Q([245]);case a.null:return Q([246]);case a.bytes:return r.value.length?void 0:Q([64]);case a.string:return r.value===""?Q([96]):void 0;case a.array:return r.value===0?Q([128]):void 0;case a.map:return r.value===0?Q([160]):void 0;case a.uint:return r.value<24?Q([Number(r.value)]):void 0;case a.negint:if(r.value>=-24)return Q([31-Number(r.value)])}}var Hs={float64:!1,mapSorter:Js,quickEncodeToken:_o};function Ks(){let r=[];return r[a.uint.major]=H,r[a.negint.major]=St,r[a.bytes.major]=Ie,r[a.string.major]=Xn,r[a.array.major]=It,r[a.map.major]=Lt,r[a.tag.major]=Bt,r[a.float.major]=Dt,r}var So=Ks(),Er=new Je,Ut=class r{constructor(e,t){this.obj=e,this.parent=t}includes(e){let t=this;do if(t.obj===e)return!0;while(t=t.parent);return!1}static createCheck(e,t){if(e&&e.includes(t))throw new Error(`${Te} object contains circular references`);return new r(t,e)}},ae={null:new l(a.null,null),undefined:new l(a.undefined,void 0),true:new l(a.true,!0),false:new l(a.false,!1),emptyArray:new l(a.array,0),emptyMap:new l(a.map,0)},ce={number(r,e,t,n){return!Number.isInteger(r)||!Number.isSafeInteger(r)?new l(a.float,r):r>=0?new l(a.uint,r):new l(a.negint,r)},bigint(r,e,t,n){return r>=BigInt(0)?new l(a.uint,r):new l(a.negint,r)},Uint8Array(r,e,t,n){return new l(a.bytes,r)},string(r,e,t,n){return new l(a.string,r)},boolean(r,e,t,n){return r?ae.true:ae.false},null(r,e,t,n){return ae.null},undefined(r,e,t,n){return ae.undefined},ArrayBuffer(r,e,t,n){return new l(a.bytes,new Uint8Array(r))},DataView(r,e,t,n){return new l(a.bytes,new Uint8Array(r.buffer,r.byteOffset,r.byteLength))},Array(r,e,t,n){if(!r.length)return t.addBreakTokens===!0?[ae.emptyArray,new l(a.break)]:ae.emptyArray;n=Ut.createCheck(n,r);let o=[],i=0;for(let s of r)o[i++]=Pt(s,t,n);return t.addBreakTokens?[new l(a.array,r.length),o,new l(a.break)]:[new l(a.array,r.length),o]},Object(r,e,t,n){let o=e!=="Object",i=o?r.keys():Object.keys(r),s=o?r.size:i.length;if(!s)return t.addBreakTokens===!0?[ae.emptyMap,new l(a.break)]:ae.emptyMap;n=Ut.createCheck(n,r);let c=[],u=0;for(let m of i)c[u++]=[Pt(m,t,n),Pt(o?r.get(m):r[m],t,n)];return Gs(c,t),t.addBreakTokens?[new l(a.map,s),c,new l(a.break)]:[new l(a.map,s),c]}};ce.Map=ce.Object;ce.Buffer=ce.Uint8Array;for(let r of"Uint8Clamped Uint16 Uint32 Int8 Int16 Int32 BigUint64 BigInt64 Float32 Float64".split(" "))ce[`${r}Array`]=ce.DataView;function Pt(r,e={},t){let n=Cn(r),o=e&&e.typeEncoders&&e.typeEncoders[n]||ce[n];if(typeof o=="function"){let s=o(r,n,e,t);if(s!=null)return s}let i=ce[n];if(!i)throw new Error(`${Te} unsupported type: ${n}`);return i(r,n,e,t)}function Gs(r,e){e.mapSorter&&r.sort(e.mapSorter)}function Js(r,e){let t=Array.isArray(r[0])?r[0][0]:r[0],n=Array.isArray(e[0])?e[0][0]:e[0];if(t.type!==n.type)return t.type.compare(n.type);let o=t.type.major,i=So[o].compareTokens(t,n);return i===0&&console.warn("WARNING: complex key types used, CBOR key sorting guarantees are gone"),i}function To(r,e,t,n){if(Array.isArray(e))for(let o of e)To(r,o,t,n);else t[e.type.major](r,e,n)}function Io(r,e,t){let n=Pt(r,t);if(!Array.isArray(n)&&t.quickEncodeToken){let o=t.quickEncodeToken(n);if(o)return o;let i=e[n.type.major];if(i.encodedSize){let s=i.encodedSize(n,t),c=new Je(s);if(i(c,n,t),c.chunks.length!==1)throw new Error(`Unexpected error: pre-calculated length for ${n} was wrong`);return Ge(c.chunks[0])}}return Er.reset(),To(Er,n,e,t),Er.toBytes(!0)}function Ze(r,e){return e=Object.assign({},Hs,e),Io(r,So,e)}var Qs={strict:!1,allowIndefinite:!0,allowUndefined:!0,allowBigInt:!0},kr=class{constructor(e,t={}){this._pos=0,this.data=e,this.options=t}pos(){return this._pos}done(){return this._pos>=this.data.length}next(){let e=this.data[this._pos],t=J[e];if(t===void 0){let n=h[e];if(!n)throw new Error(`${p} no decoder for major type ${e>>>5} (byte 0x${e.toString(16).padStart(2,"0")})`);let o=e&31;t=n(this.data,this._pos,o,this.options)}return this._pos+=t.encodedLength,t}},et=Symbol.for("DONE"),Rt=Symbol.for("BREAK");function Ys(r,e,t){let n=[];for(let o=0;o<r.value;o++){let i=tt(e,t);if(i===Rt){if(r.value===1/0)break;throw new Error(`${p} got unexpected break to lengthed array`)}if(i===et)throw new Error(`${p} found array but not enough entries (got ${o}, expected ${r.value})`);n[o]=i}return n}function Xs(r,e,t){let n=t.useMaps===!0,o=n?void 0:{},i=n?new Map:void 0;for(let s=0;s<r.value;s++){let c=tt(e,t);if(c===Rt){if(r.value===1/0)break;throw new Error(`${p} got unexpected break to lengthed map`)}if(c===et)throw new Error(`${p} found map but not enough entries (got ${s} [no key], expected ${r.value})`);if(n!==!0&&typeof c!="string")throw new Error(`${p} non-string keys not supported (got ${typeof c})`);if(t.rejectDuplicateMapKeys===!0&&(n&&i.has(c)||!n&&c in o))throw new Error(`${p} found repeat map key "${c}"`);let u=tt(e,t);if(u===et)throw new Error(`${p} found map but not enough entries (got ${s} [no value], expected ${r.value})`);n?i.set(c,u):o[c]=u}return n?i:o}function tt(r,e){if(r.done())return et;let t=r.next();if(t.type===a.break)return Rt;if(t.type.terminal)return t.value;if(t.type===a.array)return Ys(t,r,e);if(t.type===a.map)return Xs(t,r,e);if(t.type===a.tag){if(e.tags&&typeof e.tags[t.value]=="function"){let n=tt(r,e);return e.tags[t.value](n)}throw new Error(`${p} tag not supported (${t.value})`)}throw new Error("unsupported")}function vr(r,e){if(!(r instanceof Uint8Array))throw new Error(`${p} data to decode must be a Uint8Array`);e=Object.assign({},Qs,e);let t=e.tokenizer||new kr(r,e),n=tt(t,e);if(n===et)throw new Error(`${p} did not find any content to decode`);if(n===Rt)throw new Error(`${p} got unexpected break`);return[n,r.subarray(t.pos())]}function Y(r,e){let[t,n]=vr(r,e);if(n.length>0)throw new Error(`${p} too many terminals, data makes no sense`);return t}function Ft(r){return globalThis.Buffer!=null?new Uint8Array(r.buffer,r.byteOffset,r.byteLength):r}var Cr={};R(Cr,{base10:()=>Zs});var Zs=ie({prefix:"9",name:"base10",alphabet:"0123456789"});var _r={};R(_r,{base16:()=>ea,base16upper:()=>ta});var ea=v({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),ta=v({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Sr={};R(Sr,{base2:()=>ra});var ra=v({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Tr={};R(Tr,{base256emoji:()=>aa});var Lo=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}"),na=Lo.reduce((r,e,t)=>(r[t]=e,r),[]),oa=Lo.reduce((r,e,t)=>(r[e.codePointAt(0)]=t,r),[]);function ia(r){return r.reduce((e,t)=>(e+=na[t],e),"")}function sa(r){let e=[];for(let t of r){let n=oa[t.codePointAt(0)];if(n===void 0)throw new Error(`Non-base256emoji character: ${t}`);e.push(n)}return new Uint8Array(e)}var aa=ke({prefix:"\u{1F680}",name:"base256emoji",encode:ia,decode:sa});var Ir={};R(Ir,{base36:()=>rt,base36upper:()=>ca});var rt=ie({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),ca=ie({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Lr={};R(Lr,{base8:()=>ua});var ua=v({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Br={};R(Br,{identity:()=>fa});var fa=ke({prefix:"\0",name:"identity",encode:r=>bn(r),decode:r=>wn(r)});var bf=new TextEncoder,xf=new TextDecoder;var Bo=512;var No=85;var Nr={};R(Nr,{identity:()=>Re});var la=Fo,Uo=128,da=127,ha=~da,pa=Math.pow(2,31);function Fo(r,e,t){e=e||[],t=t||0;for(var n=t;r>=pa;)e[t++]=r&255|Uo,r/=128;for(;r&ha;)e[t++]=r&255|Uo,r>>>=7;return e[t]=r|0,Fo.bytes=t-n+1,e}var ma=Dr,ya=128,Ro=127;function Dr(r,n){var t=0,n=n||0,o=0,i=n,s,c=r.length;do{if(i>=c)throw Dr.bytes=0,new RangeError("Could not decode varint");s=r[i++],t+=o<28?(s&Ro)<<o:(s&Ro)*Math.pow(2,o),o+=7}while(s>=ya);return Dr.bytes=i-n,t}var ga=Math.pow(2,7),wa=Math.pow(2,14),ba=Math.pow(2,21),xa=Math.pow(2,28),Ea=Math.pow(2,35),ka=Math.pow(2,42),va=Math.pow(2,49),Aa=Math.pow(2,56),Ca=Math.pow(2,63),_a=function(r){return r<ga?1:r<wa?2:r<ba?3:r<xa?4:r<Ea?5:r<ka?6:r<va?7:r<Aa?8:r<Ca?9:10},Sa={encode:la,decode:ma,encodingLength:_a},Ta=Sa,nt=Ta;function ot(r,e=0){return[nt.decode(r,e),nt.decode.bytes]}function De(r,e,t=0){return nt.encode(r,e,t),e}function Ne(r){return nt.encodingLength(r)}function ue(r,e){let t=e.byteLength,n=Ne(r),o=n+Ne(t),i=new Uint8Array(o+t);return De(r,i,0),De(t,i,n),i.set(e,o),new Pe(r,t,e,i)}function it(r){let e=X(r),[t,n]=ot(e),[o,i]=ot(e.subarray(n)),s=e.subarray(n+i);if(s.byteLength!==o)throw new Error("Incorrect length");return new Pe(t,o,s,e)}function Oo(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&gn(r.bytes,t.bytes)}}var Pe=class{code;size;digest;bytes;constructor(e,t,n,o){this.code=e,this.size=t,this.digest=n,this.bytes=o}};var $o=0,Ia="identity",Mo=X;function La(r){return ue($o,Mo(r))}var Re={code:$o,name:Ia,encode:Mo,digest:La};var Fr={};R(Fr,{sha256:()=>Fe,sha512:()=>Rr});function Ur({name:r,code:e,encode:t}){return new Pr(r,e,t)}var Pr=class{name;code;encode;constructor(e,t,n){this.name=e,this.code=t,this.encode=n}digest(e){if(e instanceof Uint8Array){let t=this.encode(e);return t instanceof Uint8Array?ue(this.code,t):t.then(n=>ue(this.code,n))}else throw Error("Unknown type, must be binary type")}};function jo(r){return async e=>new Uint8Array(await crypto.subtle.digest(r,e))}var Fe=Ur({name:"sha2-256",code:18,encode:jo("SHA-256")}),Rr=Ur({name:"sha2-512",code:19,encode:jo("SHA-512")});function qo(r,e){let{bytes:t,version:n}=r;switch(n){case 0:return Da(t,Or(r),e??B.encoder);default:return Na(t,Or(r),e??se.encoder)}}var Vo=new WeakMap;function Or(r){let e=Vo.get(r);if(e==null){let t=new Map;return Vo.set(r,t),t}return e}var C=class r{code;version;multihash;bytes;"/";constructor(e,t,n,o){this.code=t,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:t}=this;if(e!==st)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==Pa)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(t)}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:t}=this.multihash,n=ue(e,t);return r.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 r.equals(this,e)}static equals(e,t){let n=t;return n!=null&&e.code===n.code&&e.version===n.version&&Oo(e.multihash,n.multihash)}toString(e){return qo(this,e)}toJSON(){return{"/":qo(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 t=e;if(t instanceof r)return t;if(t["/"]!=null&&t["/"]===t.bytes||t.asCID===t){let{version:n,code:o,multihash:i,bytes:s}=t;return new r(n,o,i,s??Wo(n,o,i.bytes))}else if(t[Ua]===!0){let{version:n,multihash:o,code:i}=t,s=it(o);return r.create(n,i,s)}else return null}static create(e,t,n){if(typeof t!="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(t!==st)throw new Error(`Version 0 CID must use dag-pb (code: ${st}) block encoding`);return new r(e,t,n,n.bytes)}case 1:{let o=Wo(e,t,n.bytes);return new r(e,t,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return r.create(0,st,e)}static createV1(e,t){return r.create(1,e,t)}static decode(e){let[t,n]=r.decodeFirst(e);if(n.length!==0)throw new Error("Incorrect length");return t}static decodeFirst(e){let t=r.inspectBytes(e),n=t.size-t.multihashSize,o=X(e.subarray(n,n+t.multihashSize));if(o.byteLength!==t.multihashSize)throw new Error("Incorrect length");let i=o.subarray(t.multihashSize-t.digestSize),s=new Pe(t.multihashCode,t.digestSize,i,o);return[t.version===0?r.createV0(s):r.createV1(t.codec,s),e.subarray(t.size)]}static inspectBytes(e){let t=0,n=()=>{let[d,g]=ot(e.subarray(t));return t+=g,d},o=n(),i=st;if(o===18?(o=0,t=0):i=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let s=t,c=n(),u=n(),m=t+u,f=m-s;return{version:o,codec:i,multihashCode:c,digestSize:u,multihashSize:f,size:m}}static parse(e,t){let[n,o]=Ba(e,t),i=r.decode(o);if(i.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Or(i).set(n,e),i}};function Ba(r,e){switch(r[0]){case"Q":{let t=e??B;return[B.prefix,t.decode(`${B.prefix}${r}`)]}case B.prefix:{let t=e??B;return[B.prefix,t.decode(r)]}case se.prefix:{let t=e??se;return[se.prefix,t.decode(r)]}default:{if(e==null)throw Error("To parse non base32 or base58btc encoded CID multibase decoder must be provided");return[r[0],e.decode(r)]}}}function Da(r,e,t){let{prefix:n}=t;if(n!==B.prefix)throw Error(`Cannot string encode V0 in ${t.name} encoding`);let o=e.get(n);if(o==null){let i=t.encode(r).slice(1);return e.set(n,i),i}else return o}function Na(r,e,t){let{prefix:n}=t,o=e.get(n);if(o==null){let i=t.encode(r);return e.set(n,i),i}else return o}var st=112,Pa=18;function Wo(r,e,t){let n=Ne(r),o=n+Ne(e),i=new Uint8Array(o+t.byteLength);return De(r,i,0),De(e,i,n),i.set(t,o),i}var Ua=Symbol.for("@ipld/js-cid/CID");var Oe={...Br,...Sr,...Lr,...Cr,..._r,...fr,...Ir,...lr,...dr,...Tr},zf={...Fr,...Nr};function Ho(r=0){return globalThis.Buffer?.allocUnsafe!=null?Ft(globalThis.Buffer.allocUnsafe(r)):new Uint8Array(r)}function Go(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}var Ko=Go("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),$r=Go("ascii","a",r=>{let e="a";for(let t=0;t<r.length;t++)e+=String.fromCharCode(r[t]);return e},r=>{r=r.substring(1);let e=Ho(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),Ra={utf8:Ko,"utf-8":Ko,hex:Oe.base16,latin1:$r,ascii:$r,binary:$r,...Oe},$t=Ra;function Mt(r,e="utf8"){let t=$t[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return(e==="utf8"||e==="utf-8")&&globalThis.Buffer!=null&&globalThis.Buffer.from!=null?Ft(globalThis.Buffer.from(r,"utf-8")):t.decoder.decode(`${t.prefix}${r}`)}function zt(r,e="utf8"){let t=$t[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return(e==="utf8"||e==="utf-8")&&globalThis.Buffer!=null&&globalThis.Buffer.from!=null?globalThis.Buffer.from(r.buffer,r.byteOffset,r.byteLength).toString("utf8"):t.encoder.encode(r).substring(1)}var ee="/",Jo=new TextEncoder().encode(ee),jt=Jo[0],te=class r{_buf;constructor(e,t){if(typeof e=="string")this._buf=Mt(e);else if(e instanceof Uint8Array)this._buf=e;else throw new Error("Invalid key, should be String of Uint8Array");if(t==null&&(t=!0),t&&this.clean(),this._buf.byteLength===0||this._buf[0]!==jt)throw new Error("Invalid key")}toString(e="utf8"){return zt(this._buf,e)}uint8Array(){return this._buf}get[Symbol.toStringTag](){return`Key(${this.toString()})`}static withNamespaces(e){return new r(e.join(ee))}static random(){return new r(Math.random().toString().substring(2))}static asKey(e){return e instanceof Uint8Array||typeof e=="string"?new r(e):typeof e.uint8Array=="function"?new r(e.uint8Array()):null}clean(){if((this._buf==null||this._buf.byteLength===0)&&(this._buf=Jo),this._buf[0]!==jt){let e=new Uint8Array(this._buf.byteLength+1);e.fill(jt,0,1),e.set(this._buf,1),this._buf=e}for(;this._buf.byteLength>1&&this._buf[this._buf.byteLength-1]===jt;)this._buf=this._buf.subarray(0,-1)}less(e){let t=this.list(),n=e.list();for(let o=0;o<t.length;o++){if(n.length<o+1)return!1;let i=t[o],s=n[o];if(i<s)return!0;if(i>s)return!1}return t.length<n.length}reverse(){return r.withNamespaces(this.list().slice().reverse())}namespaces(){return this.list()}baseNamespace(){let e=this.namespaces();return e[e.length-1]}list(){return this.toString().split(ee).slice(1)}type(){return Fa(this.baseNamespace())}name(){return Oa(this.baseNamespace())}instance(e){return new r(this.toString()+":"+e)}path(){let e=this.parent().toString();return e.endsWith(ee)||(e+=ee),e+=this.type(),new r(e)}parent(){let e=this.list();return e.length===1?new r(ee):new r(e.slice(0,-1).join(ee))}child(e){return this.toString()===ee?e:e.toString()===ee?this:new r(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 r.withNamespaces([...this.namespaces(),...$a(e.map(t=>t.namespaces()))])}};function Fa(r){let e=r.split(":");return e.length<2?"":e.slice(0,-1).join(":")}function Oa(r){let e=r.split(":");return e[e.length-1]}function $a(r){return[].concat(...r)}function fe(r,e){if(r===e)return!0;if(r.byteLength!==e.byteLength)return!1;for(let t=0;t<r.byteLength;t++)if(r[t]!==e[t])return!1;return!0}var Zo="/pin/",Qo="/pinned-block/",Mr=rt,Yo=1;function Xo(r){return r.version===0&&(r=r.toV1()),new te(`${Zo}${r.toString(Mr)}`)}var qt=class{datastore;blockstore;dagWalkers;constructor(e,t,n){this.datastore=e,this.blockstore=t,this.dagWalkers=n}async*add(e,t={}){let n=Xo(e);if(await this.datastore.has(n))throw new Error("Already pinned");let o=Math.round(t.depth??1/0);if(o<0)throw new Error("Depth must be greater than or equal to 0");let i=new Ke({concurrency:Yo});for await(let c of this.#e(e,i,{...t,depth:o}))await this.#o(c,u=>u.pinnedBy.find(m=>fe(m,e.bytes))!=null?!1:(u.pinCount++,u.pinnedBy.push(e.bytes),!0),t),yield c;let s={depth:o,metadata:t.metadata??{}};await this.datastore.put(n,Ze(s),t)}async*#e(e,t,n){if(n.depth===-1)return;let o=this.dagWalkers[e.code];if(o==null)throw new Error(`No dag walker found for cid codec ${e.code}`);let i=await this.blockstore.get(e,n);yield e;for await(let s of o.walk(i))yield*await t.add(async()=>this.#e(s,t,{...n,depth:n.depth-1}))}async#o(e,t,n){let o=new te(`${Qo}${Mr.encode(e.multihash.bytes)}`),i={pinCount:0,pinnedBy:[]};try{i=Y(await this.datastore.get(o,n))}catch(c){if(c.code!=="ERR_NOT_FOUND")throw c}if(t(i)){if(i.pinCount===0&&await this.datastore.has(o)){await this.datastore.delete(o);return}await this.datastore.put(o,Ze(i),n),n.onProgress?.(new k("helia:pin:add",e))}}async*rm(e,t={}){let n=Xo(e),o=await this.datastore.get(n,t),i=Y(o);await this.datastore.delete(n,t);let s=new Ke({concurrency:Yo});for await(let c of this.#e(e,s,{...t,depth:i.depth}))await this.#o(c,u=>(u.pinCount--,u.pinnedBy=u.pinnedBy.filter(m=>fe(m,e.bytes)),!0),{...t,depth:i.depth}),yield c}async*ls(e={}){for await(let{key:t,value:n}of this.datastore.query({prefix:Zo+(e.cid!=null?`${e.cid.toString(rt)}`:"")},e)){let o=C.parse(t.toString().substring(5),rt),i=Y(n);yield{cid:o,...i}}}async isPinned(e,t={}){let n=new te(`${Qo}${Mr.encode(e.multihash.bytes)}`);return this.datastore.has(n,t)}};var Ma=Symbol.for("nodejs.util.inspect.custom"),ei=Object.values(Oe).map(r=>r.decoder).reduce((r,e)=>r.or(e),Oe.identity.decoder),ti=114,ri=36,ni=37,at=class{type;multihash;privateKey;publicKey;string;constructor(e){this.type=e.type,this.multihash=e.multihash,this.privateKey=e.privateKey,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[un]=!0;toString(){return this.string==null&&(this.string=B.encode(this.multihash.bytes).slice(1)),this.string}toCID(){return C.createV1(ti,this.multihash)}toBytes(){return this.multihash.bytes}toJSON(){return this.toString()}equals(e){if(e==null)return!1;if(e instanceof Uint8Array)return fe(this.multihash.bytes,e);if(typeof e=="string")return lt(e).equals(this);if(e?.multihash?.bytes!=null)return fe(this.multihash.bytes,e.multihash.bytes);throw new Error("not valid Id")}[Ma](){return`PeerId(${this.toString()})`}},ct=class extends at{type="RSA";publicKey;constructor(e){super({...e,type:"RSA"}),this.publicKey=e.publicKey}},ut=class extends at{type="Ed25519";publicKey;constructor(e){super({...e,type:"Ed25519"}),this.publicKey=e.multihash.digest}},ft=class extends at{type="secp256k1";publicKey;constructor(e){super({...e,type:"secp256k1"}),this.publicKey=e.multihash.digest}};function lt(r,e){if(e=e??ei,r.charAt(0)==="1"||r.charAt(0)==="Q"){let t=it(B.decode(`z${r}`));return r.startsWith("12D")?new ut({multihash:t}):r.startsWith("16U")?new ft({multihash:t}):new ct({multihash:t})}return za(ei.decode(r))}function za(r){try{let e=it(r);if(e.code===Re.code){if(e.digest.length===ri)return new ut({multihash:e});if(e.digest.length===ni)return new ft({multihash:e})}if(e.code===Fe.code)return new ct({multihash:e})}catch{return ja(C.decode(r))}throw new Error("Supplied PeerID CID is invalid")}function ja(r){if(r==null||r.multihash==null||r.version==null||r.version===1&&r.code!==ti)throw new Error("Supplied PeerID CID is invalid");let e=r.multihash;if(e.code===Fe.code)return new ct({multihash:r.multihash});if(e.code===Re.code){if(e.digest.length===ri)return new ut({multihash:r.multihash});if(e.digest.length===ni)return new ft({multihash:r.multihash})}throw new Error("Supplied PeerID CID is invalid")}function zr(r,e){let t={[Symbol.iterator]:()=>t,next:()=>{let n=r.next(),o=n.value;return n.done===!0||o==null?{done:!0,value:void 0}:{done:!1,value:e(o)}}};return t}var $e=class r{set;constructor(e){if(this.set=new Set,e!=null)for(let t of e)this.set.add(t.toString())}get size(){return this.set.size}[Symbol.iterator](){return this.values()}add(e){this.set.add(e.toString())}clear(){this.set.clear()}delete(e){this.set.delete(e.toString())}entries(){return zr(this.set.entries(),e=>{let t=lt(e[0]);return[t,t]})}forEach(e){this.set.forEach(t=>{let n=lt(t);e(n,n,this)})}has(e){return this.set.has(e.toString())}values(){return zr(this.set.values(),e=>lt(e))}intersection(e){let t=new r;for(let n of e)this.has(n)&&t.add(n);return t}difference(e){let t=new r;for(let n of this)e.has(n)||t.add(n);return t}union(e){let t=new r;for(let n of e)t.add(n);for(let n of this)t.add(n);return t}};function qa(r){return r[Symbol.asyncIterator]!=null}function Va(...r){let e=[];for(let t of r)qa(t)||e.push(t);return e.length===r.length?function*(){for(let t of e)yield*t}():async function*(){let t=pe({objectMode:!0});Promise.resolve().then(async()=>{try{await Promise.all(r.map(async n=>{for await(let o of n)t.push(o)})),t.end()}catch(n){t.end(n)}}),yield*t}()}var Me=Va;var Vt=class{log;routers;constructor(e,t){this.log=e.logger.forComponent("helia:routing"),this.routers=t.routers??[]}async start(){await ne(...this.routers)}async stop(){await oe(...this.routers)}async*findProviders(e,t={}){if(this.routers.length===0)throw new F("No content routers available","ERR_NO_ROUTERS_AVAILABLE");let n=new $e;for await(let o of Me(...ze(this.routers,"findProviders").map(i=>i.findProviders(e,t))))o!=null&&(n.has(o.id)||(n.add(o.id),yield o))}async provide(e,t={}){if(this.routers.length===0)throw new F("No content routers available","ERR_NO_ROUTERS_AVAILABLE");await Promise.all(ze(this.routers,"provide").map(async n=>{await n.provide(e,t)}))}async put(e,t,n){await Promise.all(ze(this.routers,"put").map(async o=>{await o.put(e,t,n)}))}async get(e,t){return Promise.any(ze(this.routers,"get").map(async n=>n.get(e,t)))}async findPeer(e,t){if(this.routers.length===0)throw new F("No peer routers available","ERR_NO_ROUTERS_AVAILABLE");let n=this,o=Me(...ze(this.routers,"findPeer").map(i=>async function*(){try{yield await i.findPeer(e,t)}catch(s){n.log.error(s)}}()));for await(let i of o)if(i!=null)return i;throw new F("Could not find peer in routing","ERR_NOT_FOUND")}async*getClosestPeers(e,t={}){if(this.routers.length===0)throw new F("No peer routers available","ERR_NO_ROUTERS_AVAILABLE");let n=new $e;for await(let o of Me(...ze(this.routers,"getClosestPeers").map(i=>i.getClosestPeers(e,t))))o!=null&&(n.has(o.id)||(n.add(o.id),yield o))}};function ze(r,e){return r.filter(t=>t[e]!=null)}var qr=rr(ii(),1);var ht=class extends Error{constructor(e){super(e),this.name="TimeoutError"}},Vr=class extends Error{constructor(e){super(),this.name="AbortError",this.message=e}},si=r=>globalThis.DOMException===void 0?new Vr(r):new DOMException(r),ai=r=>{let e=r.reason===void 0?si("This operation was aborted."):r.reason;return e instanceof Error?e:si(e)};function pt(r,e){let{milliseconds:t,fallback:n,message:o,customTimers:i={setTimeout,clearTimeout}}=e,s,u=new Promise((m,f)=>{if(typeof t!="number"||Math.sign(t)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${t}\``);if(e.signal){let{signal:g}=e;g.aborted&&f(ai(g)),g.addEventListener("abort",()=>{f(ai(g))})}if(t===Number.POSITIVE_INFINITY){r.then(m,f);return}let d=new ht;s=i.setTimeout.call(void 0,()=>{if(n){try{m(n())}catch(g){f(g)}return}typeof r.cancel=="function"&&r.cancel(),o===!1?m():o instanceof Error?f(o):(d.message=o??`Promise timed out after ${t} milliseconds`,f(d))},t),(async()=>{try{m(await r)}catch(g){f(g)}})()}).finally(()=>{u.clear()});return u.clear=()=>{i.clearTimeout.call(void 0,s),s=void 0},u}function Wr(r,e,t){let n=0,o=r.length;for(;o>0;){let i=Math.trunc(o/2),s=n+i;t(r[s],e)<=0?(n=++s,o-=i+1):o=i}return n}var mt=class{#e=[];enqueue(e,t){t={priority:0,...t};let n={priority:t.priority,run:e};if(this.size&&this.#e[this.size-1].priority>=t.priority){this.#e.push(n);return}let o=Wr(this.#e,n,(i,s)=>s.priority-i.priority);this.#e.splice(o,0,n)}dequeue(){return this.#e.shift()?.run}filter(e){return this.#e.filter(t=>t.priority===e.priority).map(t=>t.run)}get size(){return this.#e.length}};var je=class extends qr.default{#e;#o;#s=0;#h;#a;#p=0;#r;#c;#t;#m;#n=0;#u;#i;#y;timeout;constructor(e){if(super(),e={carryoverConcurrencyCount:!1,intervalCap:Number.POSITIVE_INFINITY,interval:0,concurrency:Number.POSITIVE_INFINITY,autoStart:!0,queueClass:mt,...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})`);this.#e=e.carryoverConcurrencyCount,this.#o=e.intervalCap===Number.POSITIVE_INFINITY||e.interval===0,this.#h=e.intervalCap,this.#a=e.interval,this.#t=new e.queueClass,this.#m=e.queueClass,this.concurrency=e.concurrency,this.timeout=e.timeout,this.#y=e.throwOnTimeout===!0,this.#i=e.autoStart===!1}get#b(){return this.#o||this.#s<this.#h}get#x(){return this.#n<this.#u}#E(){this.#n--,this.#f(),this.emit("next")}#k(){this.#w(),this.#g(),this.#c=void 0}get#v(){let e=Date.now();if(this.#r===void 0){let t=this.#p-e;if(t<0)this.#s=this.#e?this.#n:0;else return this.#c===void 0&&(this.#c=setTimeout(()=>{this.#k()},t)),!0}return!1}#f(){if(this.#t.size===0)return this.#r&&clearInterval(this.#r),this.#r=void 0,this.emit("empty"),this.#n===0&&this.emit("idle"),!1;if(!this.#i){let e=!this.#v;if(this.#b&&this.#x){let t=this.#t.dequeue();return t?(this.emit("active"),t(),e&&this.#g(),!0):!1}}return!1}#g(){this.#o||this.#r!==void 0||(this.#r=setInterval(()=>{this.#w()},this.#a),this.#p=Date.now()+this.#a)}#w(){this.#s===0&&this.#n===0&&this.#r&&(clearInterval(this.#r),this.#r=void 0),this.#s=this.#e?this.#n:0,this.#l()}#l(){for(;this.#f(););}get concurrency(){return this.#u}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.#u=e,this.#l()}async#A(e){return new Promise((t,n)=>{e.addEventListener("abort",()=>{n(e.reason)},{once:!0})})}async add(e,t={}){return t={timeout:this.timeout,throwOnTimeout:this.#y,...t},new Promise((n,o)=>{this.#t.enqueue(async()=>{this.#n++,this.#s++;try{t.signal?.throwIfAborted();let i=e({signal:t.signal});t.timeout&&(i=pt(Promise.resolve(i),{milliseconds:t.timeout})),t.signal&&(i=Promise.race([i,this.#A(t.signal)]));let s=await i;n(s),this.emit("completed",s)}catch(i){if(i instanceof ht&&!t.throwOnTimeout){n();return}o(i),this.emit("error",i)}finally{this.#E()}},t),this.emit("add"),this.#f()})}async addAll(e,t){return Promise.all(e.map(async n=>this.add(n,t)))}start(){return this.#i?(this.#i=!1,this.#l(),this):this}pause(){this.#i=!0}clear(){this.#t=new this.#m}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.#n===0&&this.#t.size===0||await this.#d("idle")}async#d(e,t){return new Promise(n=>{let o=()=>{t&&!t()||(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.#n}get isPaused(){return this.#i}};var le={},qe=r=>{r.addEventListener("message",e=>{qe.dispatchEvent("message",r,e)}),r.port!=null&&r.port.addEventListener("message",e=>{qe.dispatchEvent("message",r,e)})};qe.addEventListener=(r,e)=>{le[r]==null&&(le[r]=[]),le[r].push(e)};qe.removeEventListener=(r,e)=>{le[r]!=null&&(le[r]=le[r].filter(t=>t===e))};qe.dispatchEvent=function(r,e,t){le[r]!=null&&le[r].forEach(n=>n(e,t))};var Hr=qe;var Kr="lock:worker:request-read",Gr="lock:worker:release-read",Jr="lock:master:grant-read",Qr="lock:worker:request-write",Yr="lock:worker:release-write",Xr="lock:master:grant-write";var ci=(r=21)=>Math.random().toString().substring(2);var ui=(r,e,t,n,o)=>(i,s)=>{if(s.data.type!==t)return;let c={type:s.data.type,name:s.data.name,identifier:s.data.identifier};r.dispatchEvent(new MessageEvent(e,{data:{name:c.name,handler:async()=>{i.postMessage({type:o,name:c.name,identifier:c.identifier}),await new Promise(u=>{let m=f=>{if(f==null||f.data==null)return;let d={type:f.data.type,name:f.data.name,identifier:f.data.identifier};d.type===n&&d.identifier===c.identifier&&(i.removeEventListener("message",m),u())};i.addEventListener("message",m)})}}}))},fi=(r,e,t,n)=>async()=>{let o=ci();return globalThis.postMessage({type:e,identifier:o,name:r}),new Promise(i=>{let s=c=>{if(c==null||c.data==null)return;let u={type:c.data.type,identifier:c.data.identifier};u.type===t&&u.identifier===o&&(globalThis.removeEventListener("message",s),i(()=>{globalThis.postMessage({type:n,identifier:o,name:r})}))};globalThis.addEventListener("message",s)})},Ka={singleProcess:!1},li=r=>{if(r=Object.assign({},Ka,r),!!globalThis.document||r.singleProcess){let t=new EventTarget;return Hr.addEventListener("message",ui(t,"requestReadLock",Kr,Gr,Jr)),Hr.addEventListener("message",ui(t,"requestWriteLock",Qr,Yr,Xr)),t}return{isWorker:!0,readLock:t=>fi(t,Kr,Jr,Gr),writeLock:t=>fi(t,Qr,Xr,Yr)}};var ye={},de;async function Zr(r,e){let t,n=new Promise(o=>{t=o});return r.add(async()=>pt((async()=>{await new Promise(o=>{t(()=>{o()})})})(),{milliseconds:e.timeout})),n}var Ga=(r,e)=>{if(de.isWorker===!0)return{readLock:de.readLock(r,e),writeLock:de.writeLock(r,e)};let t=new je({concurrency:1}),n;return{async readLock(){if(n!=null)return Zr(n,e);n=new je({concurrency:e.concurrency,autoStart:!1});let o=n,i=Zr(n,e);return t.add(async()=>{o.start(),await o.onIdle().then(()=>{n===o&&(n=null)})}),i},async writeLock(){return n=null,Zr(t,e)}}},Ja={name:"lock",concurrency:1/0,timeout:846e5,singleProcess:!1};function en(r){let e=Object.assign({},Ja,r);return de==null&&(de=li(e),de.isWorker!==!0&&(de.addEventListener("requestReadLock",t=>{ye[t.data.name]!=null&&ye[t.data.name].readLock().then(async n=>t.data.handler().finally(()=>{n()}))}),de.addEventListener("requestWriteLock",async t=>{ye[t.data.name]!=null&&ye[t.data.name].writeLock().then(async n=>t.data.handler().finally(()=>{n()}))}))),ye[e.name]==null&&(ye[e.name]=Ga(e.name,e)),ye[e.name]}var Ht=class{lock;child;pins;started;constructor(e,t,n={}){this.child=e,this.pins=t,this.lock=en({singleProcess:n.holdGcLock}),this.started=!1}isStarted(){return this.started}async start(){await ne(this.child),this.started=!0}async stop(){await oe(this.child),this.started=!1}unwrap(){return this.child}async put(e,t,n={}){let o=await this.lock.readLock();try{return await this.child.put(e,t,n)}finally{o()}}async*putMany(e,t={}){let n=await this.lock.readLock();try{yield*this.child.putMany(e,t)}finally{n()}}async get(e,t={}){let n=await this.lock.readLock();try{return await this.child.get(e,t)}finally{n()}}async*getMany(e,t={}){let n=await this.lock.readLock();try{yield*this.child.getMany(e,t)}finally{n()}}async delete(e,t={}){let n=await this.lock.writeLock();try{if(await this.pins.isPinned(e))throw new Error("CID was pinned");await this.child.delete(e,t)}finally{n()}}async*deleteMany(e,t={}){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 Error("CID was pinned");yield i}}(),t)}finally{n()}}async has(e,t={}){let n=await this.lock.readLock();try{return await this.child.has(e,t)}finally{n()}}async*getAll(e={}){let t=await this.lock.readLock();try{yield*this.child.getAll(e)}finally{t()}}};var hi=42;function Qa(r){if(r.asCID!==r&&r["/"]!==r.bytes)return null;let e=C.asCID(r);if(!e)return null;let t=new Uint8Array(e.bytes.byteLength+1);return t.set(e.bytes,1),[new l(a.tag,hi),new l(a.bytes,t)]}function Ya(){throw new Error("`undefined` is not supported by the IPLD Data Model and cannot be encoded")}function Xa(r){if(Number.isNaN(r))throw new Error("`NaN` is not supported by the IPLD Data Model and cannot be encoded");if(r===1/0||r===-1/0)throw new Error("`Infinity` and `-Infinity` is not supported by the IPLD Data Model and cannot be encoded");return null}var di={float64:!0,typeEncoders:{Object:Qa,undefined:Ya,number:Xa}},od={...di,typeEncoders:{...di.typeEncoders}};function Za(r){if(r[0]!==0)throw new Error("Invalid CID for CBOR tag 42; expected leading 0x00");return C.decode(r.subarray(1))}var tn={allowIndefinite:!1,coerceUndefinedToNull:!0,allowNaN:!1,allowInfinity:!1,allowBigInt:!0,strict:!0,useMaps:!1,rejectDuplicateMapKeys:!0,tags:[]};tn.tags[hi]=Za;var id={...tn,tags:tn.tags.slice()};var pi=113;var mi=class extends Array{constructor(){super(),this.inRecursive=[]}prefix(e){let t=this.inRecursive[this.inRecursive.length-1];t&&(t.type===a.array&&(t.elements++,t.elements!==1&&e.push([44])),t.type===a.map&&(t.elements++,t.elements!==1&&(t.elements%2===1?e.push([44]):e.push([58]))))}[a.uint.major](e,t){this.prefix(e);let n=String(t.value),o=[];for(let i=0;i<n.length;i++)o[i]=n.charCodeAt(i);e.push(o)}[a.negint.major](e,t){this[a.uint.major](e,t)}[a.bytes.major](e,t){throw new Error(`${Te} unsupported type: Uint8Array`)}[a.string.major](e,t){this.prefix(e);let n=_t(JSON.stringify(t.value));e.push(n.length>32?Ge(n):n)}[a.array.major](e,t){this.prefix(e),this.inRecursive.push({type:a.array,elements:0}),e.push([91])}[a.map.major](e,t){this.prefix(e),this.inRecursive.push({type:a.map,elements:0}),e.push([123])}[a.tag.major](e,t){}[a.float.major](e,t){if(t.type.name==="break"){let s=this.inRecursive.pop();if(s){if(s.type===a.array)e.push([93]);else if(s.type===a.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(t.value===void 0)throw new Error(`${Te} unsupported type: undefined`);if(this.prefix(e),t.type.name==="true"){e.push([116,114,117,101]);return}else if(t.type.name==="false"){e.push([102,97,108,115,101]);return}else if(t.type.name==="null"){e.push([110,117,108,108]);return}let n=String(t.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)}};var ge=class{constructor(e,t={}){this._pos=0,this.data=e,this.options=t,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(`${p} unexpected end of input at position ${this._pos}`);for(let t=0;t<e.length;t++)if(this.data[this._pos++]!==e[t])throw new Error(`${p} unexpected token at position ${this._pos}, expected to find '${String.fromCharCode(...e)}'`)}parseNumber(){let e=this._pos,t=!1,n=!1,o=c=>{for(;!this.done();){let u=this.ch();if(c.includes(u))this._pos++;else break}};if(this.ch()===45&&(t=!0,this._pos++),this.ch()===48)if(this._pos++,this.ch()===46)this._pos++,n=!0;else return new l(a.uint,0,this._pos-e);if(o([48,49,50,51,52,53,54,55,56,57]),t&&this._pos===e+1)throw new Error(`${p} unexpected token at position ${this._pos}`);if(!this.done()&&this.ch()===46){if(n)throw new Error(`${p} 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 l(a.float,s,this._pos-e):this.options.allowBigInt!==!0||Number.isSafeInteger(s)?new l(s>=0?a.uint:a.negint,s,this._pos-e):new l(s>=0?a.uint:a.negint,BigInt(i),this._pos-e)}parseString(){if(this.ch()!==34)throw new Error(`${p} 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 c=this.data[i];if(c===92||c<32||c>=128)break;if(c===34){let u=String.fromCharCode.apply(null,this.data.subarray(this._pos,i));return this._pos=i+1,new l(a.string,u,s)}}let e=this._pos,t=[],n=()=>{if(this._pos+4>=this.data.length)throw new Error(`${p} unexpected end of unicode escape sequence at position ${this._pos}`);let i=0;for(let s=0;s<4;s++){let c=this.ch();if(c>=48&&c<=57)c-=48;else if(c>=97&&c<=102)c=c-97+10;else if(c>=65&&c<=70)c=c-65+10;else throw new Error(`${p} unexpected unicode escape character at position ${this._pos}`);i=i*16+c,this._pos++}return i},o=()=>{let i=this.ch(),s=null,c=i>239?4:i>223?3:i>191?2:1;if(this._pos+c>this.data.length)throw new Error(`${p} unexpected unicode sequence at position ${this._pos}`);let u,m,f,d;switch(c){case 1:i<128&&(s=i);break;case 2:u=this.data[this._pos+1],(u&192)===128&&(d=(i&31)<<6|u&63,d>127&&(s=d));break;case 3:u=this.data[this._pos+1],m=this.data[this._pos+2],(u&192)===128&&(m&192)===128&&(d=(i&15)<<12|(u&63)<<6|m&63,d>2047&&(d<55296||d>57343)&&(s=d));break;case 4:u=this.data[this._pos+1],m=this.data[this._pos+2],f=this.data[this._pos+3],(u&192)===128&&(m&192)===128&&(f&192)===128&&(d=(i&15)<<18|(u&63)<<12|(m&63)<<6|f&63,d>65535&&d<1114112&&(s=d))}s===null?(s=65533,c=1):s>65535&&(s-=65536,t.push(s>>>10&1023|55296),s=56320|s&1023),t.push(s),this._pos+=c};for(;!this.done();){let i=this.ch(),s;switch(i){case 92:if(this._pos++,this.done())throw new Error(`${p} unexpected string termination at position ${this._pos}`);switch(s=this.ch(),this._pos++,s){case 34:case 39:case 92:case 47:t.push(s);break;case 98:t.push(8);break;case 116:t.push(9);break;case 110:t.push(10);break;case 102:t.push(12);break;case 114:t.push(13);break;case 117:t.push(n());break;default:throw new Error(`${p} unexpected string escape character at position ${this._pos}`)}break;case 34:return this._pos++,new l(a.string,yr(t),this._pos-e);default:if(i<32)throw new Error(`${p} invalid control character at position ${this._pos}`);i<128?(t.push(i),this._pos++):o()}}throw new Error(`${p} unexpected end of string at position ${this._pos}`)}parseValue(){switch(this.ch()){case 123:return this.modeStack.push("obj-start"),this._pos++,new l(a.map,1/0,1);case 91:return this.modeStack.push("array-start"),this._pos++,new l(a.array,1/0,1);case 34:return this.parseString();case 110:return this.expect([110,117,108,108]),new l(a.null,null,4);case 102:return this.expect([102,97,108,115,101]),new l(a.false,!1,5);case 116:return this.expect([116,114,117,101]),new l(a.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(`${p} 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 l(a.break,void 0,1);if(this.ch()!==44)throw new Error(`${p} 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 l(a.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 l(a.break,void 0,1);if(this.ch()!==44)throw new Error(`${p} 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 l(a.break,void 0,1);let e=this.parseString();if(this.skipWhitespace(),this.ch()!==58)throw new Error(`${p} 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(`${p} unexpected parse state at position ${this._pos}; this shouldn't happen`)}}};function Kt(r,e){return e=Object.assign({tokenizer:new ge(r,e)},e),Y(r,e)}var rc={allowIndefinite:!1,allowUndefined:!1,allowNaN:!1,allowInfinity:!1,allowBigInt:!0,strict:!0,useMaps:!1,rejectDuplicateMapKeys:!0,tags:[]};rc.tags[42]=C.parse;var gi=297;var kd=new TextDecoder;var vd=new TextEncoder;var oc=new TextDecoder;function rn(r,e){let t=0;for(let n=0;;n+=7){if(n>=64)throw new Error("protobuf: varint overflow");if(e>=r.length)throw new Error("protobuf: unexpected end of data");let o=r[e++];if(t+=n<28?(o&127)<<n:(o&127)*2**n,o<128)break}return[t,e]}function Gt(r,e){let t;[t,e]=rn(r,e);let n=e+t;if(t<0||n<0)throw new Error("protobuf: invalid length");if(n>r.length)throw new Error("protobuf: unexpected end of data");return[r.subarray(e,n),n]}function wi(r,e){let t;return[t,e]=rn(r,e),[t&7,t>>3,e]}function ic(r){let e={},t=r.length,n=0;for(;n<t;){let o,i;if([o,i,n]=wi(r,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]=Gt(r,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]=Gt(r,n),e.Name=oc.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]=rn(r,n)}else throw new Error(`protobuf: (PBLink) invalid fieldNumber, expected 1, 2 or 3, got ${i}`)}if(n>t)throw new Error("protobuf: (PBLink) unexpected end of data");return e}function bi(r){let e=r.length,t=0,n,o=!1,i;for(;t<e;){let c,u;if([c,u,t]=wi(r,t),c!==2)throw new Error(`protobuf: (PBNode) invalid wireType, expected 2, got ${c}`);if(u===1){if(i)throw new Error("protobuf: (PBNode) duplicate Data section");[i,t]=Gt(r,t),n&&(o=!0)}else if(u===2){if(o)throw new Error("protobuf: (PBNode) duplicate Links section");n||(n=[]);let m;[m,t]=Gt(r,t),n.push(ic(m))}else throw new Error(`protobuf: (PBNode) invalid fieldNumber, expected 1 or 2, got ${u}`)}if(t>e)throw new Error("protobuf: (PBNode) unexpected end of data");let s={};return i&&(s.Data=i),s.Links=n||[],s}var Cd=new TextEncoder,_d=2**32,Sd=2**31;var Ld=new TextEncoder;function xi(r){return r instanceof ArrayBuffer?new Uint8Array(r,0,r.byteLength):r}var Ei=112;function ki(r){let e=xi(r),t=bi(e),n={};return t.Data&&(n.Data=t.Data),t.Links&&(n.Links=t.Links.map(o=>{let i={};try{i.Hash=C.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}var ac={codec:Ei,*walk(r){yield*ki(r).Links.map(t=>t.Hash)}},cc={codec:No,*walk(){}},vi=42,uc={codec:pi,*walk(r){let e=[],t=[];t[vi]=n=>{if(n[0]!==0)throw new Error("Invalid CID for CBOR tag 42; expected leading 0x00");let o=C.decode(n.subarray(1));return e.push(o),o},Y(r,{tags:t}),yield*e}},nn=class extends ge{tokenBuffer;constructor(e,t){super(e,t),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(e.type===a.map){let t=this._next();if(t.type===a.string&&t.value==="/"){let n=this._next();if(n.type===a.string){if(this._next().type!==a.break)throw new Error("Invalid encoded CID form");return this.tokenBuffer.push(n),new l(a.tag,42,0)}if(n.type===a.map){let o=this._next();if(o.type===a.string&&o.value==="bytes"){let i=this._next();if(i.type===a.string){for(let c=0;c<2;c++)if(this._next().type!==a.break)throw new Error("Invalid encoded Bytes form");let s=ve.decode(`m${i.value}`);return new l(a.bytes,s,i.value.length)}this.tokenBuffer.push(i)}this.tokenBuffer.push(o)}this.tokenBuffer.push(n)}this.tokenBuffer.push(t)}return e}},fc={codec:gi,*walk(r){let e=[],t=[];t[vi]=n=>{let o=C.parse(n);return e.push(o),o},Kt(r,{tags:t,tokenizer:new nn(r,{tags:t,allowIndefinite:!0,allowUndefined:!0,allowNaN:!0,allowInfinity:!0,allowBigInt:!0,strict:!1,rejectDuplicateMapKeys:!1})}),yield*e}},lc={codec:Bo,*walk(){}};function Ai(r=[]){let e={};return[ac,cc,uc,fc,lc,...r].forEach(t=>{e[t.codec]=t}),e}var on=new te("/version"),Ci=1;async function _i(r){if(!await r.has(on)){await r.put(on,Mt(`${Ci}`));return}let e=await r.get(on),t=zt(e);if(parseInt(t,10)!==Ci)throw new Error("Unknown datastore version, a datastore migration may be required")}function Si(r=[]){let e={};return[Fe,Rr,Re,...r].forEach(t=>{e[t.code]=t}),e}function Ti(r){let e=new globalThis.AbortController;function t(){e.abort();for(let i of r)i?.removeEventListener!=null&&i.removeEventListener("abort",t)}for(let i of r){if(i?.aborted===!0){t();break}i?.addEventListener!=null&&i.addEventListener("abort",t)}function n(){for(let i of r)i?.removeEventListener!=null&&i.removeEventListener("abort",t)}let o=e.signal;return o.clear=n,o}var Ve=class{has(e,t){return Promise.reject(new Error(".has is not implemented"))}put(e,t,n){return Promise.reject(new Error(".put is not implemented"))}async*putMany(e,t){for await(let{cid:n,block:o}of e)await this.put(n,o,t),yield n}get(e,t){return Promise.reject(new Error(".get is not implemented"))}async*getMany(e,t){for await(let n of e)yield{cid:n,block:await this.get(n,t)}}delete(e,t){return Promise.reject(new Error(".delete is not implemented"))}async*deleteMany(e,t){for await(let n of e)await this.delete(n,t),yield n}async*getAll(e){throw new Error(".getAll is not implemented")}};var Jt=rr(Bi(),1);function Di(r){return r=r??new Error("Put failed"),(0,Jt.default)(r,"ERR_PUT_FAILED")}function Ni(r){return r=r??new Error("Delete failed"),(0,Jt.default)(r,"ERR_DELETE_FAILED")}function Qt(r){return r=r??new Error("Not Found"),(0,Jt.default)(r,"ERR_NOT_FOUND")}var Ui=0,Yt=class extends Ve{put(e){return e}get(e){if(e.code===Ui)return e.multihash.digest;throw Qt()}has(e){return e.code===Ui}delete(){}*getAll(){}};function hc(r){let[e,t]=r[Symbol.asyncIterator]!=null?[r[Symbol.asyncIterator](),Symbol.asyncIterator]:[r[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(),[t](){return this}}}var Xt=hc;function pc(r){return r[Symbol.asyncIterator]!=null}function mc(r,e){if(pc(r))return async function*(){for await(let c of r)await e(c)&&(yield c)}();let t=Xt(r),{value:n,done:o}=t.next();if(o===!0)return function*(){}();let i=e(n);if(typeof i.then=="function")return async function*(){await i&&(yield n);for await(let c of t)await e(c)&&(yield c)}();let s=e;return function*(){i===!0&&(yield n);for(let c of t)s(c)&&(yield c)}()}var Zt=mc;var yc=hr("blockstore:core:tiered"),er=class extends Ve{stores;constructor(e){super(),this.stores=e.slice()}async put(e,t,n){try{return await Promise.all(this.stores.map(async o=>{await o.put(e,t,n)})),e}catch(o){throw Di(o)}}async get(e,t){for(let n of this.stores)try{let o=await n.get(e,t);if(o!=null)return o}catch(o){yc.error(o)}throw Qt()}async has(e,t){for(let n of this.stores)if(await n.has(e,t))return!0;return!1}async delete(e,t){try{await Promise.all(this.stores.map(async n=>{await n.delete(e,t)}))}catch(n){throw Ni(n)}}async*putMany(e,t={}){let n,o=this.stores.map(i=>{let s=pe({objectMode:!0});return He(i.putMany(s,t)).catch(c=>{n=c}),s});try{for await(let i of e){if(n!=null)throw n;o.forEach(s=>s.push(i)),yield i.cid}}finally{o.forEach(i=>i.end())}}async*deleteMany(e,t={}){let n,o=this.stores.map(i=>{let s=pe({objectMode:!0});return He(i.deleteMany(s,t)).catch(c=>{n=c}),s});try{for await(let i of e){if(n!=null)throw n;o.forEach(s=>s.push(i)),yield i}}finally{o.forEach(i=>i.end())}}async*getAll(e){let t=new Set;yield*Zt(Me(...this.stores.map(n=>n.getAll(e))),n=>{let o=n.cid.toString();return t.has(o)?!1:(t.add(o),!0)})}};function gc(r){return r[Symbol.asyncIterator]!=null}function Ri(r){return r?.then!=null}function wc(r,e){if(gc(r))return async function*(){for await(let c of r){let u=e(c);Ri(u)&&await u,yield c}}();let t=Xt(r),{value:n,done:o}=t.next();if(o===!0)return function*(){}();if(typeof e(n)?.then=="function")return async function*(){yield n;for await(let c of t){let u=e(c);Ri(u)&&await u,yield c}}();let s=e;return function*(){yield n;for(let c of t)s(c),yield c}()}var sn=wc;function bc(r){return typeof r.retrieve=="function"}function xc(r){return typeof r.announce=="function"}var tr=class{child;blockRetrievers;blockAnnouncers;hashers;started;log;constructor(e){this.log=e.logger.forComponent("helia:networked-storage"),this.child=new er([new Yt,e.blockstore]),this.blockRetrievers=(e.blockBrokers??[]).filter(bc),this.blockAnnouncers=(e.blockBrokers??[]).filter(xc),this.hashers=e.hashers??{},this.started=!1}isStarted(){return this.started}async start(){await ne(this.child,...new Set([...this.blockRetrievers,...this.blockAnnouncers])),this.started=!0}async stop(){await oe(this.child,...new Set([...this.blockRetrievers,...this.blockAnnouncers])),this.started=!1}unwrap(){return this.child}async put(e,t,n={}){return await this.child.has(e)?(n.onProgress?.(new k("blocks:put:duplicate",e)),e):(n.onProgress?.(new k("blocks:put:providers:notify",e)),this.blockAnnouncers.forEach(o=>{o.announce(e,t,n)}),n.onProgress?.(new k("blocks:put:blockstore:put",e)),this.child.put(e,t,n))}async*putMany(e,t={}){let n=Zt(e,async({cid:i})=>{let s=await this.child.has(i);return s&&t.onProgress?.(new k("blocks:put-many:duplicate",i)),!s}),o=sn(n,({cid:i,block:s})=>{t.onProgress?.(new k("blocks:put-many:providers:notify",i)),this.blockAnnouncers.forEach(c=>{c.announce(i,s,t)})});t.onProgress?.(new k("blocks:put-many:blockstore:put-many")),yield*this.child.putMany(o,t)}async get(e,t={}){if(t.offline!==!0&&!await this.child.has(e)){t.onProgress?.(new k("blocks:get:providers:get",e));let n=await Fi(e,this.blockRetrievers,this.hashers[e.multihash.code],{...t,log:this.log});return t.onProgress?.(new k("blocks:get:blockstore:put",e)),await this.child.put(e,n,t),t.onProgress?.(new k("blocks:get:providers:notify",e)),this.blockAnnouncers.forEach(o=>{o.announce(e,n,t)}),n}return t.onProgress?.(new k("blocks:get:blockstore:get",e)),this.child.get(e,t)}async*getMany(e,t={}){t.onProgress?.(new k("blocks:get-many:blockstore:get-many")),yield*this.child.getMany(sn(e,async n=>{if(t.offline!==!0&&!await this.child.has(n)){t.onProgress?.(new k("blocks:get-many:providers:get",n));let o=await Fi(n,this.blockRetrievers,this.hashers[n.multihash.code],{...t,log:this.log});t.onProgress?.(new k("blocks:get-many:blockstore:put",n)),await this.child.put(n,o,t),t.onProgress?.(new k("blocks:get-many:providers:notify",n)),this.blockAnnouncers.forEach(i=>{i.announce(n,o,t)})}}))}async delete(e,t={}){t.onProgress?.(new k("blocks:delete:blockstore:delete",e)),await this.child.delete(e,t)}async*deleteMany(e,t={}){t.onProgress?.(new k("blocks:delete-many:blockstore:delete-many")),yield*this.child.deleteMany(async function*(){for await(let n of e)yield n}(),t)}async has(e,t={}){return this.child.has(e,t)}async*getAll(e={}){e.onProgress?.(new k("blocks:get-all:blockstore:get-many")),yield*this.child.getAll(e)}},Ec=(r,e)=>{if(e==null)throw new F(`No hasher configured for multihash code 0x${r.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`,"ERR_UNKNOWN_HASH_ALG");return async t=>{let n=await e.digest(t);if(!fe(n.digest,r.multihash.digest))throw new F("Hash of downloaded block did not match multihash from passed CID","ERR_HASH_MISMATCH")}};async function Fi(r,e,t,n){let o=Ec(r,t),i=new AbortController,s=Ti([i.signal,n.signal]);try{return await Promise.any(e.map(async c=>{try{let u=!1,m=await c.retrieve(r,{...n,signal:s,validateFn:async f=>{await o(f),u=!0}});return u||await o(m),m}catch(u){throw n.log.error("could not retrieve verified block for %c",r,u),u}}))}finally{s.clear()}}var an=class{blockstore;datastore;pins;logger;routing;dagWalkers;hashers;log;constructor(e){this.logger=e.logger??vn(),this.log=this.logger.forComponent("helia"),this.hashers=Si(e.hashers),this.dagWalkers=Ai(e.dagWalkers);let t={blockstore:e.blockstore,datastore:e.datastore,hashers:this.hashers,dagWalkers:this.dagWalkers,logger:this.logger,blockBrokers:[],...e.components??{}};t.blockBrokers=e.blockBrokers.map(o=>o(t));let n=new tr(t);this.pins=new qt(e.datastore,n,this.dagWalkers),this.blockstore=new Ht(n,this.pins,{holdGcLock:e.holdGcLock??!0}),this.datastore=e.datastore,this.routing=new Vt(t,{routers:(e.routers??[]).flatMap(o=>{let i=[o];return o[nr]!=null&&i.push(o[nr]),o[or]!=null&&i.push(o[or]),i})})}async start(){await _i(this.datastore),await ne(this.blockstore,this.datastore,this.routing)}async stop(){await oe(this.blockstore,this.datastore,this.routing)}async gc(e={}){let t=await this.blockstore.lock.writeLock();try{let n=this,o=this.blockstore.unwrap();this.log("gc start"),await He(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 k("helia:gc:deleted",i))}catch(s){n.log.error("Error during gc",s),e.onProgress?.(new k("helia:gc:error",s))}}()))}finally{t()}this.log("gc finished")}};return qi(kc);})();
|
|
3
3
|
return HeliaUtils}));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"networked-storage.d.ts","sourceRoot":"","sources":["../../../src/utils/networked-storage.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"networked-storage.d.ts","sourceRoot":"","sources":["../../../src/utils/networked-storage.ts"],"names":[],"mappings":"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"}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { CodeError, start, stop } from '@libp2p/interface';
|
|
2
2
|
import { anySignal } from 'any-signal';
|
|
3
|
+
import { IdentityBlockstore } from 'blockstore-core/identity';
|
|
4
|
+
import { TieredBlockstore } from 'blockstore-core/tiered';
|
|
3
5
|
import filter from 'it-filter';
|
|
4
6
|
import forEach from 'it-foreach';
|
|
5
7
|
import { CustomProgressEvent } from 'progress-events';
|
|
@@ -26,7 +28,10 @@ export class NetworkedStorage {
|
|
|
26
28
|
*/
|
|
27
29
|
constructor(components) {
|
|
28
30
|
this.log = components.logger.forComponent('helia:networked-storage');
|
|
29
|
-
this.child =
|
|
31
|
+
this.child = new TieredBlockstore([
|
|
32
|
+
new IdentityBlockstore(),
|
|
33
|
+
components.blockstore
|
|
34
|
+
]);
|
|
30
35
|
this.blockRetrievers = (components.blockBrokers ?? []).filter(isBlockRetriever);
|
|
31
36
|
this.blockAnnouncers = (components.blockBrokers ?? []).filter(isBlockAnnouncer);
|
|
32
37
|
this.hashers = components.hashers ?? {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"networked-storage.js","sourceRoot":"","sources":["../../../src/utils/networked-storage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAA;AAC1D,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AACtC,OAAO,MAAM,MAAM,WAAW,CAAA;AAC9B,OAAO,OAAO,MAAM,YAAY,CAAA;AAChC,OAAO,EAAE,mBAAmB,EAAwB,MAAM,iBAAiB,CAAA;AAC3E,OAAO,EAAE,MAAM,IAAI,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AAY/D,SAAS,gBAAgB,CAAE,CAAM;IAC/B,OAAO,OAAO,CAAC,CAAC,QAAQ,KAAK,UAAU,CAAA;AACzC,CAAC;AAED,SAAS,gBAAgB,CAAE,CAAM;IAC/B,OAAO,OAAO,CAAC,CAAC,QAAQ,KAAK,UAAU,CAAA;AACzC,CAAC;AASD;;;GAGG;AACH,MAAM,OAAO,gBAAgB;IACV,KAAK,CAAY;IACjB,eAAe,CAAkB;IACjC,eAAe,CAAkB;IACjC,OAAO,CAAiC;IACjD,OAAO,CAAS;IACP,GAAG,CAAQ;IAE5B;;OAEG;IACH,YAAa,UAAsC;QACjD,IAAI,CAAC,GAAG,GAAG,UAAU,CAAC,MAAM,CAAC,YAAY,CAAC,yBAAyB,CAAC,CAAA;QACpE,IAAI,CAAC,KAAK,GAAG,UAAU,CAAC,UAAU,CAAA;
|
|
1
|
+
{"version":3,"file":"networked-storage.js","sourceRoot":"","sources":["../../../src/utils/networked-storage.ts"],"names":[],"mappings":"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"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@helia/utils",
|
|
3
|
-
"version": "0.0.1-
|
|
3
|
+
"version": "0.0.1-8db7792",
|
|
4
4
|
"description": "Shared code that implements the Helia API",
|
|
5
5
|
"license": "Apache-2.0 OR MIT",
|
|
6
6
|
"homepage": "https://github.com/ipfs/helia/tree/main/packages/utils#readme",
|
|
@@ -53,32 +53,32 @@
|
|
|
53
53
|
"test:electron-main": "aegir test -t electron-main"
|
|
54
54
|
},
|
|
55
55
|
"dependencies": {
|
|
56
|
-
"@helia/interface": "4.0.0-
|
|
57
|
-
"@ipld/dag-cbor": "^9.0
|
|
58
|
-
"@ipld/dag-json": "^10.1.
|
|
59
|
-
"@ipld/dag-pb": "^4.0.
|
|
60
|
-
"@libp2p/interface": "^1.1.
|
|
61
|
-
"@libp2p/logger": "^4.0.
|
|
62
|
-
"@libp2p/peer-collections": "^5.1.
|
|
63
|
-
"@libp2p/utils": "^5.2.
|
|
56
|
+
"@helia/interface": "4.0.0-8db7792",
|
|
57
|
+
"@ipld/dag-cbor": "^9.1.0",
|
|
58
|
+
"@ipld/dag-json": "^10.1.7",
|
|
59
|
+
"@ipld/dag-pb": "^4.0.8",
|
|
60
|
+
"@libp2p/interface": "^1.1.2",
|
|
61
|
+
"@libp2p/logger": "^4.0.5",
|
|
62
|
+
"@libp2p/peer-collections": "^5.1.5",
|
|
63
|
+
"@libp2p/utils": "^5.2.3",
|
|
64
64
|
"any-signal": "^4.1.1",
|
|
65
|
-
"
|
|
66
|
-
"
|
|
67
|
-
"interface-
|
|
68
|
-
"interface-
|
|
65
|
+
"blockstore-core": "^4.4.0",
|
|
66
|
+
"cborg": "^4.0.8",
|
|
67
|
+
"interface-blockstore": "^5.2.9",
|
|
68
|
+
"interface-datastore": "^8.2.10",
|
|
69
|
+
"interface-store": "^5.1.7",
|
|
69
70
|
"it-drain": "^3.0.5",
|
|
70
71
|
"it-filter": "^3.0.4",
|
|
71
72
|
"it-foreach": "^2.0.6",
|
|
72
73
|
"it-merge": "^3.0.3",
|
|
73
|
-
"mortice": "^3.0.
|
|
74
|
-
"multiformats": "^13.0.
|
|
74
|
+
"mortice": "^3.0.4",
|
|
75
|
+
"multiformats": "^13.0.1",
|
|
75
76
|
"progress-events": "^1.0.0",
|
|
76
77
|
"uint8arrays": "^5.0.1"
|
|
77
78
|
},
|
|
78
79
|
"devDependencies": {
|
|
79
|
-
"@types/sinon": "^17.0.
|
|
80
|
-
"aegir": "^42.
|
|
81
|
-
"blockstore-core": "^4.3.10",
|
|
80
|
+
"@types/sinon": "^17.0.3",
|
|
81
|
+
"aegir": "^42.2.2",
|
|
82
82
|
"datastore-core": "^9.2.7",
|
|
83
83
|
"delay": "^6.0.0",
|
|
84
84
|
"it-all": "^3.0.4",
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { CodeError, start, stop } from '@libp2p/interface'
|
|
2
2
|
import { anySignal } from 'any-signal'
|
|
3
|
+
import { IdentityBlockstore } from 'blockstore-core/identity'
|
|
4
|
+
import { TieredBlockstore } from 'blockstore-core/tiered'
|
|
3
5
|
import filter from 'it-filter'
|
|
4
6
|
import forEach from 'it-foreach'
|
|
5
7
|
import { CustomProgressEvent, type ProgressOptions } from 'progress-events'
|
|
@@ -47,7 +49,10 @@ export class NetworkedStorage implements Blocks, Startable {
|
|
|
47
49
|
*/
|
|
48
50
|
constructor (components: NetworkedStorageComponents) {
|
|
49
51
|
this.log = components.logger.forComponent('helia:networked-storage')
|
|
50
|
-
this.child =
|
|
52
|
+
this.child = new TieredBlockstore([
|
|
53
|
+
new IdentityBlockstore(),
|
|
54
|
+
components.blockstore
|
|
55
|
+
])
|
|
51
56
|
this.blockRetrievers = (components.blockBrokers ?? []).filter(isBlockRetriever)
|
|
52
57
|
this.blockAnnouncers = (components.blockBrokers ?? []).filter(isBlockAnnouncer)
|
|
53
58
|
this.hashers = components.hashers ?? {}
|