@helia/block-brokers 2.0.0 → 2.0.1
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.HeliaBlockBrokers = factory()}(typeof self !== 'undefined' ? self : this, function () {
|
|
2
|
-
"use strict";var HeliaBlockBrokers=(()=>{var Bs=Object.create;var Mt=Object.defineProperty;var Fs=Object.getOwnPropertyDescriptor;var Ds=Object.getOwnPropertyNames;var Is=Object.getPrototypeOf,Ns=Object.prototype.hasOwnProperty;var S=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports),M=(r,t)=>{for(var e in t)Mt(r,e,{get:t[e],enumerable:!0})},yr=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of Ds(t))!Ns.call(r,s)&&s!==e&&Mt(r,s,{get:()=>t[s],enumerable:!(n=Fs(t,s))||n.enumerable});return r};var q=(r,t,e)=>(e=r!=null?Bs(Is(r)):{},yr(t||!r||!r.__esModule?Mt(e,"default",{value:r,enumerable:!0}):e,r)),Ms=r=>yr(Mt({},"__esModule",{value:!0}),r);var Hr=S((Za,zr)=>{zr.exports=Or;var Ur=128,ki=127,Ei=~ki,Si=Math.pow(2,31);function Or(r,t,e){t=t||[],e=e||0;for(var n=e;r>=Si;)t[e++]=r&255|Ur,r/=128;for(;r&Ei;)t[e++]=r&255|Ur,r>>>=7;return t[e]=r|0,Or.bytes=e-n+1,t}});var Vr=S((Ya,qr)=>{qr.exports=Ce;var Ti=128,Wr=127;function Ce(r,n){var e=0,n=n||0,s=0,i=n,o,a=r.length;do{if(i>=a)throw Ce.bytes=0,new RangeError("Could not decode varint");o=r[i++],e+=s<28?(o&Wr)<<s:(o&Wr)*Math.pow(2,s),s+=7}while(o>=Ti);return Ce.bytes=i-n,e}});var Gr=S((tc,$r)=>{var Ci=Math.pow(2,7),Ai=Math.pow(2,14),Li=Math.pow(2,21),Bi=Math.pow(2,28),Fi=Math.pow(2,35),Di=Math.pow(2,42),Ii=Math.pow(2,49),Ni=Math.pow(2,56),Mi=Math.pow(2,63);$r.exports=function(r){return r<Ci?1:r<Ai?2:r<Li?3:r<Bi?4:r<Fi?5:r<Di?6:r<Ii?7:r<Ni?8:r<Mi?9:10}});var Qr=S((ec,Xr)=>{Xr.exports={encode:Hr(),decode:Vr(),encodingLength:Gr()}});var Kr=S((rc,Jr)=>{"use strict";var jr=Qr();Jr.exports=r=>{if(!(r instanceof Uint8Array))throw new Error("arg needs to be a Uint8Array");let t=[];for(;r.length>0;){let e=jr.decode(r);t.push(e),r=r.slice(jr.decode.bytes)}return t}});var Yr=S((nc,Zr)=>{var gt=1e3,mt=gt*60,bt=mt*60,tt=bt*24,Ri=tt*7,Pi=tt*365.25;Zr.exports=function(r,t){t=t||{};var e=typeof r;if(e==="string"&&r.length>0)return Ui(r);if(e==="number"&&isFinite(r))return t.long?zi(r):Oi(r);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(r))};function Ui(r){if(r=String(r),!(r.length>100)){var t=/^(-?(?:\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(t){var e=parseFloat(t[1]),n=(t[2]||"ms").toLowerCase();switch(n){case"years":case"year":case"yrs":case"yr":case"y":return e*Pi;case"weeks":case"week":case"w":return e*Ri;case"days":case"day":case"d":return e*tt;case"hours":case"hour":case"hrs":case"hr":case"h":return e*bt;case"minutes":case"minute":case"mins":case"min":case"m":return e*mt;case"seconds":case"second":case"secs":case"sec":case"s":return e*gt;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return e;default:return}}}}function Oi(r){var t=Math.abs(r);return t>=tt?Math.round(r/tt)+"d":t>=bt?Math.round(r/bt)+"h":t>=mt?Math.round(r/mt)+"m":t>=gt?Math.round(r/gt)+"s":r+"ms"}function zi(r){var t=Math.abs(r);return t>=tt?Ut(r,t,tt,"day"):t>=bt?Ut(r,t,bt,"hour"):t>=mt?Ut(r,t,mt,"minute"):t>=gt?Ut(r,t,gt,"second"):r+" ms"}function Ut(r,t,e,n){var s=t>=e*1.5;return Math.round(r/e)+" "+n+(s?"s":"")}});var en=S((sc,tn)=>{function Hi(r){e.debug=e,e.default=e,e.coerce=c,e.disable=i,e.enable=s,e.enabled=o,e.humanize=Yr(),e.destroy=l,Object.keys(r).forEach(u=>{e[u]=r[u]}),e.names=[],e.skips=[],e.formatters={};function t(u){let h=0;for(let f=0;f<u.length;f++)h=(h<<5)-h+u.charCodeAt(f),h|=0;return e.colors[Math.abs(h)%e.colors.length]}e.selectColor=t;function e(u){let h,f=null,m,d;function g(...p){if(!g.enabled)return;let w=g,x=Number(new Date),k=x-(h||x);w.diff=k,w.prev=h,w.curr=x,h=x,p[0]=e.coerce(p[0]),typeof p[0]!="string"&&p.unshift("%O");let E=0;p[0]=p[0].replace(/%([a-zA-Z%])/g,(U,N)=>{if(U==="%%")return"%";E++;let O=e.formatters[N];if(typeof O=="function"){let lt=p[E];U=O.call(w,lt),p.splice(E,1),E--}return U}),e.formatArgs.call(w,p),(w.log||e.log).apply(w,p)}return g.namespace=u,g.useColors=e.useColors(),g.color=e.selectColor(u),g.extend=n,g.destroy=e.destroy,Object.defineProperty(g,"enabled",{enumerable:!0,configurable:!1,get:()=>f!==null?f:(m!==e.namespaces&&(m=e.namespaces,d=e.enabled(u)),d),set:p=>{f=p}}),typeof e.init=="function"&&e.init(g),g}function n(u,h){let f=e(this.namespace+(typeof h>"u"?":":h)+u);return f.log=this.log,f}function s(u){e.save(u),e.namespaces=u,e.names=[],e.skips=[];let h,f=(typeof u=="string"?u:"").split(/[\s,]+/),m=f.length;for(h=0;h<m;h++)f[h]&&(u=f[h].replace(/\*/g,".*?"),u[0]==="-"?e.skips.push(new RegExp("^"+u.slice(1)+"$")):e.names.push(new RegExp("^"+u+"$")))}function i(){let u=[...e.names.map(a),...e.skips.map(a).map(h=>"-"+h)].join(",");return e.enable(""),u}function o(u){if(u[u.length-1]==="*")return!0;let h,f;for(h=0,f=e.skips.length;h<f;h++)if(e.skips[h].test(u))return!1;for(h=0,f=e.names.length;h<f;h++)if(e.names[h].test(u))return!0;return!1}function a(u){return u.toString().substring(2,u.toString().length-2).replace(/\.\*\?$/,"*")}function c(u){return u instanceof Error?u.stack||u.message:u}function l(){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 e.enable(e.load()),e}tn.exports=Hi});var rn=S((R,Ot)=>{R.formatArgs=qi;R.save=Vi;R.load=$i;R.useColors=Wi;R.storage=Gi();R.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`."))}})();R.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 Wi(){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 qi(r){if(r[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+r[0]+(this.useColors?"%c ":" ")+"+"+Ot.exports.humanize(this.diff),!this.useColors)return;let t="color: "+this.color;r.splice(1,0,t,"color: inherit");let e=0,n=0;r[0].replace(/%[a-zA-Z%]/g,s=>{s!=="%%"&&(e++,s==="%c"&&(n=e))}),r.splice(n,0,t)}R.log=console.debug||console.log||(()=>{});function Vi(r){try{r?R.storage.setItem("debug",r):R.storage.removeItem("debug")}catch{}}function $i(){let r;try{r=R.storage.getItem("debug")}catch{}return!r&&typeof process<"u"&&"env"in process&&(r=process.env.DEBUG),r}function Gi(){try{return localStorage}catch{}}Ot.exports=en()(R);var{formatters:Xi}=Ot.exports;Xi.j=function(r){try{return JSON.stringify(r)}catch(t){return"[UnexpectedJSONParseError]: "+t.message}}});var an=S((_c,on)=>{on.exports=Be;var sn=128,Zi=127,Yi=~Zi,to=Math.pow(2,31);function Be(r,t,e){if(Number.MAX_SAFE_INTEGER&&r>Number.MAX_SAFE_INTEGER)throw Be.bytes=0,new RangeError("Could not encode varint");t=t||[],e=e||0;for(var n=e;r>=to;)t[e++]=r&255|sn,r/=128;for(;r&Yi;)t[e++]=r&255|sn,r>>>=7;return t[e]=r|0,Be.bytes=e-n+1,t}});var un=S((xc,ln)=>{ln.exports=Fe;var eo=128,cn=127;function Fe(r,n){var e=0,n=n||0,s=0,i=n,o,a=r.length;do{if(i>=a||s>49)throw Fe.bytes=0,new RangeError("Could not decode varint");o=r[i++],e+=s<28?(o&cn)<<s:(o&cn)*Math.pow(2,s),s+=7}while(o>=eo);return Fe.bytes=i-n,e}});var fn=S((vc,hn)=>{var ro=Math.pow(2,7),no=Math.pow(2,14),so=Math.pow(2,21),io=Math.pow(2,28),oo=Math.pow(2,35),ao=Math.pow(2,42),co=Math.pow(2,49),lo=Math.pow(2,56),uo=Math.pow(2,63);hn.exports=function(r){return r<ro?1:r<no?2:r<so?3:r<io?4:r<oo?5:r<ao?6:r<co?7:r<lo?8:r<uo?9:10}});var pn=S((kc,dn)=>{dn.exports={encode:an(),decode:un(),encodingLength:fn()}});var Wn=S((Eu,Hn)=>{"use strict";function zn(r,t){for(let e in t)Object.defineProperty(r,e,{value:t[e],enumerable:!0,configurable:!0});return r}function Yo(r,t,e){if(!r||typeof r=="string")throw new TypeError("Please pass an Error to err-code");e||(e={}),typeof t=="object"&&(e=t,t=""),t&&(e.code=t);try{return zn(r,e)}catch{e.message=r.message,e.stack=r.stack;let s=function(){};return s.prototype=Object.create(Object.getPrototypeOf(r)),zn(new s,e)}}Hn.exports=Yo});var jn=S((Vu,Qn)=>{"use strict";Qn.exports=function(){return Date.now()}});var Kn=S(($u,Jn)=>{"use strict";var ne=jn(),lr=class{constructor(t,e,n){let s=this;this._started=ne(),this._rescheduled=0,this._scheduled=e,this._args=n,this._triggered=!1,this._timerWrapper=()=>{s._rescheduled>0?(s._scheduled=s._rescheduled-(ne()-s._started),s._schedule(s._scheduled)):(s._triggered=!0,t.apply(null,s._args))},this._timer=setTimeout(this._timerWrapper,e)}reschedule(t){t||(t=this._scheduled);let e=ne();e+t-(this._started+this._scheduled)<0?(clearTimeout(this._timer),this._schedule(t)):this._triggered?this._schedule(t):(this._started=e,this._rescheduled=t)}_schedule(t){this._triggered=!1,this._started=ne(),this._rescheduled=0,this._scheduled=t,this._timer=setTimeout(this._timerWrapper,t)}clear(){clearTimeout(this._timer)}};function fa(){if(typeof arguments[0]!="function")throw new Error("callback needed");if(typeof arguments[1]!="number")throw new Error("timeout needed");let r;if(arguments.length>0){r=new Array(arguments.length-2);for(var t=0;t<r.length;t++)r[t]=arguments[t+2]}return new lr(arguments[0],arguments[1],r)}Jn.exports=fa});var ts=S((Gu,Yn)=>{"use strict";var{AbortController:da}=globalThis,Zn=Kn(),ur=class r extends da{constructor(t){super(),this._ms=t,this._timer=Zn(()=>this.abort(),t),Object.setPrototypeOf(this,r.prototype)}abort(){return this._timer.clear(),super.abort()}clear(){this._timer.clear()}reset(){this._timer.clear(),this._timer=Zn(()=>this.abort(),this._ms)}};Yn.exports={TimeoutController:ur}});var ae=S((nh,pr)=>{"use strict";var vt=typeof Reflect=="object"?Reflect:null,os=vt&&typeof vt.apply=="function"?vt.apply:function(t,e,n){return Function.prototype.apply.call(t,e,n)},ie;vt&&typeof vt.ownKeys=="function"?ie=vt.ownKeys:Object.getOwnPropertySymbols?ie=function(t){return Object.getOwnPropertyNames(t).concat(Object.getOwnPropertySymbols(t))}:ie=function(t){return Object.getOwnPropertyNames(t)};function ba(r){console&&console.warn&&console.warn(r)}var cs=Number.isNaN||function(t){return t!==t};function _(){_.init.call(this)}pr.exports=_;pr.exports.once=xa;_.EventEmitter=_;_.prototype._events=void 0;_.prototype._eventsCount=0;_.prototype._maxListeners=void 0;var as=10;function oe(r){if(typeof r!="function")throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof r)}Object.defineProperty(_,"defaultMaxListeners",{enumerable:!0,get:function(){return as},set:function(r){if(typeof r!="number"||r<0||cs(r))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+r+".");as=r}});_.init=function(){(this._events===void 0||this._events===Object.getPrototypeOf(this)._events)&&(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0};_.prototype.setMaxListeners=function(t){if(typeof t!="number"||t<0||cs(t))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+t+".");return this._maxListeners=t,this};function ls(r){return r._maxListeners===void 0?_.defaultMaxListeners:r._maxListeners}_.prototype.getMaxListeners=function(){return ls(this)};_.prototype.emit=function(t){for(var e=[],n=1;n<arguments.length;n++)e.push(arguments[n]);var s=t==="error",i=this._events;if(i!==void 0)s=s&&i.error===void 0;else if(!s)return!1;if(s){var o;if(e.length>0&&(o=e[0]),o instanceof Error)throw o;var a=new Error("Unhandled error."+(o?" ("+o.message+")":""));throw a.context=o,a}var c=i[t];if(c===void 0)return!1;if(typeof c=="function")os(c,this,e);else for(var l=c.length,u=ps(c,l),n=0;n<l;++n)os(u[n],this,e);return!0};function us(r,t,e,n){var s,i,o;if(oe(e),i=r._events,i===void 0?(i=r._events=Object.create(null),r._eventsCount=0):(i.newListener!==void 0&&(r.emit("newListener",t,e.listener?e.listener:e),i=r._events),o=i[t]),o===void 0)o=i[t]=e,++r._eventsCount;else if(typeof o=="function"?o=i[t]=n?[e,o]:[o,e]:n?o.unshift(e):o.push(e),s=ls(r),s>0&&o.length>s&&!o.warned){o.warned=!0;var a=new Error("Possible EventEmitter memory leak detected. "+o.length+" "+String(t)+" listeners added. Use emitter.setMaxListeners() to increase limit");a.name="MaxListenersExceededWarning",a.emitter=r,a.type=t,a.count=o.length,ba(a)}return r}_.prototype.addListener=function(t,e){return us(this,t,e,!1)};_.prototype.on=_.prototype.addListener;_.prototype.prependListener=function(t,e){return us(this,t,e,!0)};function ya(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,arguments.length===0?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function hs(r,t,e){var n={fired:!1,wrapFn:void 0,target:r,type:t,listener:e},s=ya.bind(n);return s.listener=e,n.wrapFn=s,s}_.prototype.once=function(t,e){return oe(e),this.on(t,hs(this,t,e)),this};_.prototype.prependOnceListener=function(t,e){return oe(e),this.prependListener(t,hs(this,t,e)),this};_.prototype.removeListener=function(t,e){var n,s,i,o,a;if(oe(e),s=this._events,s===void 0)return this;if(n=s[t],n===void 0)return this;if(n===e||n.listener===e)--this._eventsCount===0?this._events=Object.create(null):(delete s[t],s.removeListener&&this.emit("removeListener",t,n.listener||e));else if(typeof n!="function"){for(i=-1,o=n.length-1;o>=0;o--)if(n[o]===e||n[o].listener===e){a=n[o].listener,i=o;break}if(i<0)return this;i===0?n.shift():wa(n,i),n.length===1&&(s[t]=n[0]),s.removeListener!==void 0&&this.emit("removeListener",t,a||e)}return this};_.prototype.off=_.prototype.removeListener;_.prototype.removeAllListeners=function(t){var e,n,s;if(n=this._events,n===void 0)return this;if(n.removeListener===void 0)return arguments.length===0?(this._events=Object.create(null),this._eventsCount=0):n[t]!==void 0&&(--this._eventsCount===0?this._events=Object.create(null):delete n[t]),this;if(arguments.length===0){var i=Object.keys(n),o;for(s=0;s<i.length;++s)o=i[s],o!=="removeListener"&&this.removeAllListeners(o);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if(e=n[t],typeof e=="function")this.removeListener(t,e);else if(e!==void 0)for(s=e.length-1;s>=0;s--)this.removeListener(t,e[s]);return this};function fs(r,t,e){var n=r._events;if(n===void 0)return[];var s=n[t];return s===void 0?[]:typeof s=="function"?e?[s.listener||s]:[s]:e?_a(s):ps(s,s.length)}_.prototype.listeners=function(t){return fs(this,t,!0)};_.prototype.rawListeners=function(t){return fs(this,t,!1)};_.listenerCount=function(r,t){return typeof r.listenerCount=="function"?r.listenerCount(t):ds.call(r,t)};_.prototype.listenerCount=ds;function ds(r){var t=this._events;if(t!==void 0){var e=t[r];if(typeof e=="function")return 1;if(e!==void 0)return e.length}return 0}_.prototype.eventNames=function(){return this._eventsCount>0?ie(this._events):[]};function ps(r,t){for(var e=new Array(t),n=0;n<t;++n)e[n]=r[n];return e}function wa(r,t){for(;t+1<r.length;t++)r[t]=r[t+1];r.pop()}function _a(r){for(var t=new Array(r.length),e=0;e<t.length;++e)t[e]=r[e].listener||r[e];return t}function xa(r,t){return new Promise(function(e,n){function s(o){r.removeListener(t,i),n(o)}function i(){typeof r.removeListener=="function"&&r.removeListener("error",s),e([].slice.call(arguments))}gs(r,t,i,{once:!0}),t!=="error"&&va(r,s,{once:!0})})}function va(r,t,e){typeof r.on=="function"&&gs(r,"error",t,e)}function gs(r,t,e,n){if(typeof r.on=="function")n.once?r.once(t,e):r.on(t,e);else if(typeof r.addEventListener=="function")r.addEventListener(t,function s(i){n.once&&r.removeEventListener(t,s),e(i)});else throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type '+typeof r)}});var xs=S((ws,_s)=>{"use strict";var ka=Math.exp;ws=_s.exports=function(t){if(typeof t!="number")throw new Error("must provide a timespan to the moving average constructor");if(t<=0)throw new Error("must provide a timespan > 0 to the moving average constructor");let e,n=0,s=0,i=0,o,a={};function c(l,u){return 1-ka(-(l-u)/t)}return a.push=function(u,h){if(o){let f=c(u,o),m=h-e,d=f*m;e=f*h+(1-f)*e,n=(1-f)*(n+m*d),s=Math.sqrt(n),i=e+f*m}else e=h;o=u},a.movingAverage=function(){return e},a.variance=function(){return n},a.deviation=function(){return s},a.forecast=function(){return i},a}});var Aa={};M(Aa,{bitswap:()=>Cs,trustlessGateway:()=>Ls});function wr(r){let t=new globalThis.AbortController;function e(){t.abort();for(let i of r)i?.removeEventListener!=null&&i.removeEventListener("abort",e)}for(let i of r){if(i?.aborted===!0){e();break}i?.addEventListener!=null&&i.addEventListener("abort",e)}function n(){for(let i of r)i?.removeEventListener!=null&&i.removeEventListener("abort",e)}let s=t.signal;return s.clear=n,s}function Rs(r){let[t,e]=r[Symbol.asyncIterator]!=null?[r[Symbol.asyncIterator](),Symbol.asyncIterator]:[r[Symbol.iterator](),Symbol.iterator],n=[];return{peek:()=>t.next(),push:s=>{n.push(s)},next:()=>n.length>0?{done:!1,value:n.shift()}:t.next(),[e](){return this}}}var Rt=Rs;function Ps(r){return r[Symbol.asyncIterator]!=null}function _r(r){return r?.then!=null}function Us(r,t){if(Ps(r))return async function*(){for await(let a of r){let c=t(a);_r(c)&&await c,yield a}}();let e=Rt(r),{value:n,done:s}=e.next();if(s===!0)return function*(){}();if(typeof t(n)?.then=="function")return async function*(){yield n;for await(let a of e){let c=t(a);_r(c)&&await c,yield a}}();let o=t;return function*(){yield n;for(let a of e)o(a),yield a}()}var xr=Us;var we={};M(we,{base32:()=>X,base32hex:()=>Xs,base32hexpad:()=>js,base32hexpadupper:()=>Js,base32hexupper:()=>Qs,base32pad:()=>$s,base32padupper:()=>Gs,base32upper:()=>Vs,base32z:()=>Ks});var Na=new Uint8Array(0);function vr(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}function V(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 kr(r){return new TextEncoder().encode(r)}function Er(r){return new TextDecoder().decode(r)}function Os(r,t){if(r.length>=255)throw new TypeError("Alphabet too long");for(var e=new Uint8Array(256),n=0;n<e.length;n++)e[n]=255;for(var s=0;s<r.length;s++){var i=r.charAt(s),o=i.charCodeAt(0);if(e[o]!==255)throw new TypeError(i+" is ambiguous");e[o]=s}var a=r.length,c=r.charAt(0),l=Math.log(a)/Math.log(256),u=Math.log(256)/Math.log(a);function h(d){if(d instanceof Uint8Array||(ArrayBuffer.isView(d)?d=new Uint8Array(d.buffer,d.byteOffset,d.byteLength):Array.isArray(d)&&(d=Uint8Array.from(d))),!(d instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(d.length===0)return"";for(var g=0,p=0,w=0,x=d.length;w!==x&&d[w]===0;)w++,g++;for(var k=(x-w)*u+1>>>0,E=new Uint8Array(k);w!==x;){for(var I=d[w],U=0,N=k-1;(I!==0||U<p)&&N!==-1;N--,U++)I+=256*E[N]>>>0,E[N]=I%a>>>0,I=I/a>>>0;if(I!==0)throw new Error("Non-zero carry");p=U,w++}for(var O=k-p;O!==k&&E[O]===0;)O++;for(var lt=c.repeat(g);O<k;++O)lt+=r.charAt(E[O]);return lt}function f(d){if(typeof d!="string")throw new TypeError("Expected String");if(d.length===0)return new Uint8Array;var g=0;if(d[g]!==" "){for(var p=0,w=0;d[g]===c;)p++,g++;for(var x=(d.length-g)*l+1>>>0,k=new Uint8Array(x);d[g];){var E=e[d.charCodeAt(g)];if(E===255)return;for(var I=0,U=x-1;(E!==0||I<w)&&U!==-1;U--,I++)E+=a*k[U]>>>0,k[U]=E%256>>>0,E=E/256>>>0;if(E!==0)throw new Error("Non-zero carry");w=I,g++}if(d[g]!==" "){for(var N=x-w;N!==x&&k[N]===0;)N++;for(var O=new Uint8Array(p+(x-N)),lt=p;N!==x;)O[lt++]=k[N++];return O}}}function m(d){var g=f(d);if(g)return g;throw new Error(`Non-${t} character`)}return{encode:h,decodeUnsafe:f,decode:m}}var zs=Os,Hs=zs,Tr=Hs;var ge=class{name;prefix;baseEncode;constructor(t,e,n){this.name=t,this.prefix=e,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},me=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,e,n){if(this.name=t,this.prefix=e,e.codePointAt(0)===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=e.codePointAt(0),this.baseDecode=n}decode(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return Cr(this,t)}},be=class{decoders;constructor(t){this.decoders=t}or(t){return Cr(this,t)}decode(t){let e=t[0],n=this.decoders[e];if(n!=null)return n.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function Cr(r,t){return new be({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var ye=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,e,n,s){this.name=t,this.prefix=e,this.baseEncode=n,this.baseDecode=s,this.encoder=new ge(t,e,n),this.decoder=new me(t,e,s)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function ut({name:r,prefix:t,encode:e,decode:n}){return new ye(r,t,e,n)}function G({name:r,prefix:t,alphabet:e}){let{encode:n,decode:s}=Tr(e,r);return ut({prefix:t,name:r,encode:n,decode:i=>V(s(i))})}function Ws(r,t,e,n){let s={};for(let u=0;u<t.length;++u)s[t[u]]=u;let i=r.length;for(;r[i-1]==="=";)--i;let o=new Uint8Array(i*e/8|0),a=0,c=0,l=0;for(let u=0;u<i;++u){let h=s[r[u]];if(h===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<e|h,a+=e,a>=8&&(a-=8,o[l++]=255&c>>a)}if(a>=e||255&c<<8-a)throw new SyntaxError("Unexpected end of data");return o}function qs(r,t,e){let n=t[t.length-1]==="=",s=(1<<e)-1,i="",o=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],o+=8;o>e;)o-=e,i+=t[s&a>>o];if(o!==0&&(i+=t[s&a<<e-o]),n)for(;i.length*e&7;)i+="=";return i}function v({name:r,prefix:t,bitsPerChar:e,alphabet:n}){return ut({prefix:t,name:r,encode(s){return qs(s,n,e)},decode(s){return Ws(s,n,e,r)}})}var X=v({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Vs=v({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),$s=v({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Gs=v({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Xs=v({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Qs=v({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),js=v({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Js=v({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Ks=v({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var _e={};M(_e,{base58btc:()=>b,base58flickr:()=>Zs});var b=G({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Zs=G({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Ys=Br,Ar=128,ti=127,ei=~ti,ri=Math.pow(2,31);function Br(r,t,e){t=t||[],e=e||0;for(var n=e;r>=ri;)t[e++]=r&255|Ar,r/=128;for(;r&ei;)t[e++]=r&255|Ar,r>>>=7;return t[e]=r|0,Br.bytes=e-n+1,t}var ni=xe,si=128,Lr=127;function xe(r,n){var e=0,n=n||0,s=0,i=n,o,a=r.length;do{if(i>=a)throw xe.bytes=0,new RangeError("Could not decode varint");o=r[i++],e+=s<28?(o&Lr)<<s:(o&Lr)*Math.pow(2,s),s+=7}while(o>=si);return xe.bytes=i-n,e}var ii=Math.pow(2,7),oi=Math.pow(2,14),ai=Math.pow(2,21),ci=Math.pow(2,28),li=Math.pow(2,35),ui=Math.pow(2,42),hi=Math.pow(2,49),fi=Math.pow(2,56),di=Math.pow(2,63),pi=function(r){return r<ii?1:r<oi?2:r<ai?3:r<ci?4:r<li?5:r<ui?6:r<hi?7:r<fi?8:r<di?9:10},gi={encode:Ys,decode:ni,encodingLength:pi},mi=gi,kt=mi;function Et(r,t=0){return[kt.decode(r,t),kt.decode.bytes]}function ht(r,t,e=0){return kt.encode(r,t,e),t}function ft(r){return kt.encodingLength(r)}function Y(r,t){let e=t.byteLength,n=ft(r),s=n+ft(e),i=new Uint8Array(s+e);return ht(r,i,0),ht(e,i,n),i.set(t,s),new dt(r,e,t,i)}function Fr(r){let t=V(r),[e,n]=Et(t),[s,i]=Et(t.subarray(n)),o=t.subarray(n+i);if(o.byteLength!==s)throw new Error("Incorrect length");return new dt(e,s,o,t)}function Dr(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&vr(r.bytes,e.bytes)}}var dt=class{code;size;digest;bytes;constructor(t,e,n,s){this.code=t,this.size=e,this.digest=n,this.bytes=s}};function Ir(r,t){let{bytes:e,version:n}=r;switch(n){case 0:return yi(e,ve(r),t??b.encoder);default:return wi(e,ve(r),t??X.encoder)}}var Nr=new WeakMap;function ve(r){let t=Nr.get(r);if(t==null){let e=new Map;return Nr.set(r,e),e}return t}var T=class r{code;version;multihash;bytes;"/";constructor(t,e,n,s){this.code=e,this.version=t,this.multihash=n,this.bytes=s,this["/"]=s}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:t,multihash:e}=this;if(t!==Tt)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==_i)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(e)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:t,digest:e}=this.multihash,n=Y(t,e);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(t){return r.equals(this,t)}static equals(t,e){let n=e;return n!=null&&t.code===n.code&&t.version===n.version&&Dr(t.multihash,n.multihash)}toString(t){return Ir(this,t)}toJSON(){return{"/":Ir(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(t){if(t==null)return null;let e=t;if(e instanceof r)return e;if(e["/"]!=null&&e["/"]===e.bytes||e.asCID===e){let{version:n,code:s,multihash:i,bytes:o}=e;return new r(n,s,i,o??Mr(n,s,i.bytes))}else if(e[xi]===!0){let{version:n,multihash:s,code:i}=e,o=Fr(s);return r.create(n,i,o)}else return null}static create(t,e,n){if(typeof e!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(t){case 0:{if(e!==Tt)throw new Error(`Version 0 CID must use dag-pb (code: ${Tt}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let s=Mr(t,e,n.bytes);return new r(t,e,n,s)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,Tt,t)}static createV1(t,e){return r.create(1,t,e)}static decode(t){let[e,n]=r.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return e}static decodeFirst(t){let e=r.inspectBytes(t),n=e.size-e.multihashSize,s=V(t.subarray(n,n+e.multihashSize));if(s.byteLength!==e.multihashSize)throw new Error("Incorrect length");let i=s.subarray(e.multihashSize-e.digestSize),o=new dt(e.multihashCode,e.digestSize,i,s);return[e.version===0?r.createV0(o):r.createV1(e.codec,o),t.subarray(e.size)]}static inspectBytes(t){let e=0,n=()=>{let[h,f]=Et(t.subarray(e));return e+=f,h},s=n(),i=Tt;if(s===18?(s=0,e=0):i=n(),s!==0&&s!==1)throw new RangeError(`Invalid CID version ${s}`);let o=e,a=n(),c=n(),l=e+c,u=l-o;return{version:s,codec:i,multihashCode:a,digestSize:c,multihashSize:u,size:l}}static parse(t,e){let[n,s]=bi(t,e),i=r.decode(s);if(i.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return ve(i).set(n,t),i}};function bi(r,t){switch(r[0]){case"Q":{let e=t??b;return[b.prefix,e.decode(`${b.prefix}${r}`)]}case b.prefix:{let e=t??b;return[b.prefix,e.decode(r)]}case X.prefix:{let e=t??X;return[X.prefix,e.decode(r)]}default:{if(t==null)throw Error("To parse non base32 or base58btc encoded CID multibase decoder must be provided");return[r[0],t.decode(r)]}}}function yi(r,t,e){let{prefix:n}=e;if(n!==b.prefix)throw Error(`Cannot string encode V0 in ${e.name} encoding`);let s=t.get(n);if(s==null){let i=e.encode(r).slice(1);return t.set(n,i),i}else return s}function wi(r,t,e){let{prefix:n}=e,s=t.get(n);if(s==null){let i=e.encode(r);return t.set(n,i),i}else return s}var Tt=112,_i=18;function Mr(r,t,e){let n=ft(r),s=n+ft(t),i=new Uint8Array(s+e.byteLength);return ht(r,i,0),ht(t,i,n),i.set(e,s),i}var xi=Symbol.for("@ipld/js-cid/CID");var ke=class extends Map{metric;constructor(t){super();let{name:e,metrics:n}=t;this.metric=n.registerMetric(e),this.updateComponentMetric()}set(t,e){return super.set(t,e),this.updateComponentMetric(),this}delete(t){let e=super.delete(t);return this.updateComponentMetric(),e}clear(){super.clear(),this.updateComponentMetric()}updateComponentMetric(){this.metric.update(this.size)}};function Q(r){let{name:t,metrics:e}=r,n;return e!=null?n=new ke({name:t,metrics:e}):n=new Map,n}var pt=class extends Error{code;props;constructor(t,e,n){super(t),this.code=e,this.name=n?.name??"CodeError",this.props=n??{}}};var Te={};M(Te,{sha256:()=>Ct,sha512:()=>vi});function Se({name:r,code:t,encode:e}){return new Ee(r,t,e)}var Ee=class{name;code;encode;constructor(t,e,n){this.name=t,this.code=e,this.encode=n}digest(t){if(t instanceof Uint8Array){let e=this.encode(t);return e instanceof Uint8Array?Y(this.code,e):e.then(n=>Y(this.code,n))}else throw Error("Unknown type, must be binary type")}};function Pr(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var Ct=Se({name:"sha2-256",code:18,encode:Pr("SHA-256")}),vi=Se({name:"sha2-512",code:19,encode:Pr("SHA-512")});var Bn=q(Kr(),1);var P=q(rn(),1);var Le={};M(Le,{base64:()=>Ae,base64pad:()=>Qi,base64url:()=>ji,base64urlpad:()=>Ji});var Ae=v({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Qi=v({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),ji=v({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Ji=v({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});P.default.formatters.b=r=>r==null?"undefined":b.baseEncode(r);P.default.formatters.t=r=>r==null?"undefined":X.baseEncode(r);P.default.formatters.m=r=>r==null?"undefined":Ae.baseEncode(r);P.default.formatters.p=r=>r==null?"undefined":r.toString();P.default.formatters.c=r=>r==null?"undefined":r.toString();P.default.formatters.k=r=>r==null?"undefined":r.toString();P.default.formatters.a=r=>r==null?"undefined":r.toString();function Ki(r){let t=()=>{};return t.enabled=!1,t.color="",t.diff=0,t.log=()=>{},t.namespace=r,t.destroy=()=>!0,t.extend=()=>t,t}function nn(r){let t=Ki(`${r}:trace`);return P.default.enabled(`${r}:trace`)&&P.default.names.map(e=>e.toString()).find(e=>e.includes(":trace"))!=null&&(t=(0,P.default)(`${r}:trace`)),Object.assign((0,P.default)(r),{error:(0,P.default)(`${r}:error`),trace:t})}function zt(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}var et=class{_refCounter;cid;priority;wantType;constructor(t,e,n){this._refCounter=1,this.cid=t,this.priority=e??1,this.wantType=n}inc(){this._refCounter+=1}dec(){this._refCounter=Math.max(0,this._refCounter-1)}hasRefs(){return this._refCounter>0}get[Symbol.toStringTag](){return`WantlistEntry <key: ${this.cid.toString(b)}, priority: ${this.priority}, refs: ${this._refCounter}>`}equals(t){return this._refCounter===t._refCounter&&this.cid.equals(t.cid)&&this.priority===t.priority&&this.wantType===t.wantType}};var j=class{entry;cancel;sendDontHave;constructor(t,e,n,s,i){this.entry=new et(t,e,n),this.cancel=!!s,this.sendDontHave=!!i}get cid(){return this.entry.cid}set cid(t){this.entry.cid=t}get priority(){return this.entry.priority}set priority(t){this.entry.priority=t}get wantType(){return this.entry.wantType}set wantType(t){this.entry.wantType=t}get[Symbol.toStringTag](){return`BitswapMessageEntry ${this.cid.toString(b)} <cancel: ${this.cancel}, priority: ${this.priority}>`}equals(t){return this.cancel===t.cancel&&this.sendDontHave===t.sendDontHave&&this.wantType===t.wantType&&this.entry.equals(t.entry)}};var z=(r,t)=>{let e=["bitswap"];return t!=null&&e.push(t),r!=null&&e.push(`${r.toString().slice(0,8)}`),nn(e.join(":"))};var Ht=(r,t)=>{if(r.size!==t.size)return!1;for(let[e,n]of r){let s=t.get(e);if(s===void 0||n instanceof Uint8Array&&s instanceof Uint8Array&&!zt(n,s)||n instanceof j&&s instanceof j&&!n.equals(s))return!1}return!0};var At=q(pn(),1);function ho(r){let t=new Uint8Array(r.reduce((n,s)=>n+At.default.encodingLength(s),0)),e=0;for(let n of r)t=At.encode(n,t,e),e+=At.default.encodingLength(n);return t}var gn=ho;var De=new Float32Array([-0]),J=new Uint8Array(De.buffer);function mn(r,t,e){De[0]=r,t[e]=J[0],t[e+1]=J[1],t[e+2]=J[2],t[e+3]=J[3]}function bn(r,t){return J[0]=r[t],J[1]=r[t+1],J[2]=r[t+2],J[3]=r[t+3],De[0]}var Ie=new Float64Array([-0]),C=new Uint8Array(Ie.buffer);function yn(r,t,e){Ie[0]=r,t[e]=C[0],t[e+1]=C[1],t[e+2]=C[2],t[e+3]=C[3],t[e+4]=C[4],t[e+5]=C[5],t[e+6]=C[6],t[e+7]=C[7]}function wn(r,t){return C[0]=r[t],C[1]=r[t+1],C[2]=r[t+2],C[3]=r[t+3],C[4]=r[t+4],C[5]=r[t+5],C[6]=r[t+6],C[7]=r[t+7],Ie[0]}var fo=BigInt(Number.MAX_SAFE_INTEGER),po=BigInt(Number.MIN_SAFE_INTEGER),F=class r{lo;hi;constructor(t,e){this.lo=t|0,this.hi=e|0}toNumber(t=!1){if(!t&&this.hi>>>31>0){let e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(e+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(t=!1){if(t)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(BigInt(e)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(t=!1){return this.toBigInt(t).toString()}zzEncode(){let t=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^t)>>>0,this.lo=(this.lo<<1^t)>>>0,this}zzDecode(){let t=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^t)>>>0,this.hi=(this.hi>>>1^t)>>>0,this}length(){let t=this.lo,e=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?e===0?t<16384?t<128?1:2:t<2097152?3:4:e<16384?e<128?5:6:e<2097152?7:8:n<128?9:10}static fromBigInt(t){if(t===0n)return rt;if(t<fo&&t>po)return this.fromNumber(Number(t));let e=t<0n;e&&(t=-t);let n=t>>32n,s=t-(n<<32n);return e&&(n=~n|0n,s=~s|0n,++s>_n&&(s=0n,++n>_n&&(n=0n))),new r(Number(s),Number(n))}static fromNumber(t){if(t===0)return rt;let e=t<0;e&&(t=-t);let n=t>>>0,s=(t-n)/4294967296>>>0;return e&&(s=~s>>>0,n=~n>>>0,++n>4294967295&&(n=0,++s>4294967295&&(s=0))),new r(n,s)}static from(t){return typeof t=="number"?r.fromNumber(t):typeof t=="bigint"?r.fromBigInt(t):typeof t=="string"?r.fromBigInt(BigInt(t)):t.low!=null||t.high!=null?new r(t.low>>>0,t.high>>>0):rt}},rt=new F(0,0);rt.toBigInt=function(){return 0n};rt.zzEncode=rt.zzDecode=function(){return this};rt.length=function(){return 1};var _n=4294967296n;function xn(r){let t=0,e=0;for(let n=0;n<r.length;++n)e=r.charCodeAt(n),e<128?t+=1:e<2048?t+=2:(e&64512)===55296&&(r.charCodeAt(n+1)&64512)===56320?(++n,t+=4):t+=3;return t}function vn(r,t,e){if(e-t<1)return"";let s,i=[],o=0,a;for(;t<e;)a=r[t++],a<128?i[o++]=a:a>191&&a<224?i[o++]=(a&31)<<6|r[t++]&63:a>239&&a<365?(a=((a&7)<<18|(r[t++]&63)<<12|(r[t++]&63)<<6|r[t++]&63)-65536,i[o++]=55296+(a>>10),i[o++]=56320+(a&1023)):i[o++]=(a&15)<<12|(r[t++]&63)<<6|r[t++]&63,o>8191&&((s??(s=[])).push(String.fromCharCode.apply(String,i)),o=0);return s!=null?(o>0&&s.push(String.fromCharCode.apply(String,i.slice(0,o))),s.join("")):String.fromCharCode.apply(String,i.slice(0,o))}function Ne(r,t,e){let n=e,s,i;for(let o=0;o<r.length;++o)s=r.charCodeAt(o),s<128?t[e++]=s:s<2048?(t[e++]=s>>6|192,t[e++]=s&63|128):(s&64512)===55296&&((i=r.charCodeAt(o+1))&64512)===56320?(s=65536+((s&1023)<<10)+(i&1023),++o,t[e++]=s>>18|240,t[e++]=s>>12&63|128,t[e++]=s>>6&63|128,t[e++]=s&63|128):(t[e++]=s>>12|224,t[e++]=s>>6&63|128,t[e++]=s&63|128);return e-n}function H(r,t){return RangeError(`index out of range: ${r.pos} + ${t??1} > ${r.len}`)}function Wt(r,t){return(r[t-4]|r[t-3]<<8|r[t-2]<<16|r[t-1]<<24)>>>0}var Me=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(t){this.buf=t,this.pos=0,this.len=t.length}uint32(){let t=4294967295;if(t=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(t=(t|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return t;if((this.pos+=5)>this.len)throw this.pos=this.len,H(this,10);return t}int32(){return this.uint32()|0}sint32(){let t=this.uint32();return t>>>1^-(t&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw H(this,4);return Wt(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw H(this,4);return Wt(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw H(this,4);let t=bn(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw H(this,4);let t=wn(this.buf,this.pos);return this.pos+=8,t}bytes(){let t=this.uint32(),e=this.pos,n=this.pos+t;if(n>this.len)throw H(this,t);return this.pos+=t,e===n?new Uint8Array(0):this.buf.subarray(e,n)}string(){let t=this.bytes();return vn(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw H(this,t);this.pos+=t}else do if(this.pos>=this.len)throw H(this);while(this.buf[this.pos++]&128);return this}skipType(t){switch(t){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(t=this.uint32()&7)!==4;)this.skipType(t);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${t} at offset ${this.pos}`)}return this}readLongVarint(){let t=new F(0,0),e=0;if(this.len-this.pos>4){for(;e<4;++e)if(t.lo=(t.lo|(this.buf[this.pos]&127)<<e*7)>>>0,this.buf[this.pos++]<128)return t;if(t.lo=(t.lo|(this.buf[this.pos]&127)<<28)>>>0,t.hi=(t.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return t;e=0}else{for(;e<3;++e){if(this.pos>=this.len)throw H(this);if(t.lo=(t.lo|(this.buf[this.pos]&127)<<e*7)>>>0,this.buf[this.pos++]<128)return t}return t.lo=(t.lo|(this.buf[this.pos++]&127)<<e*7)>>>0,t}if(this.len-this.pos>4){for(;e<5;++e)if(t.hi=(t.hi|(this.buf[this.pos]&127)<<e*7+3)>>>0,this.buf[this.pos++]<128)return t}else for(;e<5;++e){if(this.pos>=this.len)throw H(this);if(t.hi=(t.hi|(this.buf[this.pos]&127)<<e*7+3)>>>0,this.buf[this.pos++]<128)return t}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw H(this,8);let t=Wt(this.buf,this.pos+=4),e=Wt(this.buf,this.pos+=4);return new F(t,e)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){return this.readLongVarint().toNumber(!0)}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function Re(r){return new Me(r instanceof Uint8Array?r:r.subarray())}function nt(r,t){let e=Re(r);return t.decode(e)}function K(r){return globalThis.Buffer!=null?new Uint8Array(r.buffer,r.byteOffset,r.byteLength):r}function $(r=0){return globalThis.Buffer?.alloc!=null?K(globalThis.Buffer.alloc(r)):new Uint8Array(r)}function A(r=0){return globalThis.Buffer?.allocUnsafe!=null?K(globalThis.Buffer.allocUnsafe(r)):new Uint8Array(r)}var Pe={};M(Pe,{base10:()=>go});var go=G({prefix:"9",name:"base10",alphabet:"0123456789"});var Ue={};M(Ue,{base16:()=>mo,base16upper:()=>bo});var mo=v({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),bo=v({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Oe={};M(Oe,{base2:()=>yo});var yo=v({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var ze={};M(ze,{base256emoji:()=>ko});var En=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}"),wo=En.reduce((r,t,e)=>(r[e]=t,r),[]),_o=En.reduce((r,t,e)=>(r[t.codePointAt(0)]=e,r),[]);function xo(r){return r.reduce((t,e)=>(t+=wo[e],t),"")}function vo(r){let t=[];for(let e of r){let n=_o[e.codePointAt(0)];if(n===void 0)throw new Error(`Non-base256emoji character: ${e}`);t.push(n)}return new Uint8Array(t)}var ko=ut({prefix:"\u{1F680}",name:"base256emoji",encode:xo,decode:vo});var He={};M(He,{base36:()=>Eo,base36upper:()=>So});var Eo=G({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),So=G({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var We={};M(We,{base8:()=>To});var To=v({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var qe={};M(qe,{identity:()=>Co});var Co=ut({prefix:"\0",name:"identity",encode:r=>Er(r),decode:r=>kr(r)});var qc=new TextEncoder,Vc=new TextDecoder;var Ve={};M(Ve,{identity:()=>Do});var Sn=0,Bo="identity",Tn=V;function Fo(r){return Y(Sn,Tn(r))}var Do={code:Sn,name:Bo,encode:Tn,digest:Fo};var $e={...qe,...Oe,...We,...Pe,...Ue,...we,...He,..._e,...Le,...ze},rl={...Te,...Ve};function An(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var Cn=An("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Ge=An("ascii","a",r=>{let t="a";for(let e=0;e<r.length;e++)t+=String.fromCharCode(r[e]);return t},r=>{r=r.substring(1);let t=A(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),Io={utf8:Cn,"utf-8":Cn,hex:$e.base16,latin1:Ge,ascii:Ge,binary:Ge,...$e},qt=Io;function Ln(r,t="utf8"){let e=qt[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return(t==="utf8"||t==="utf-8")&&globalThis.Buffer!=null&&globalThis.Buffer.from!=null?K(globalThis.Buffer.from(r,"utf-8")):e.decoder.decode(`${e.prefix}${r}`)}function Xe(r){let t=r??8192,e=t>>>1,n,s=t;return function(o){if(o<1||o>e)return A(o);s+o>t&&(n=A(t),s=0);let a=n.subarray(s,s+=o);return s&7&&(s=(s|7)+1),a}}var st=class{fn;len;next;val;constructor(t,e,n){this.fn=t,this.len=e,this.next=void 0,this.val=n}};function Qe(){}var Je=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},No=Xe();function Mo(r){return globalThis.Buffer!=null?A(r):No(r)}var Ft=class{len;head;tail;states;constructor(){this.len=0,this.head=new st(Qe,0,0),this.tail=this.head,this.states=null}_push(t,e,n){return this.tail=this.tail.next=new st(t,e,n),this.len+=e,this}uint32(t){return this.len+=(this.tail=this.tail.next=new Ke((t=t>>>0)<128?1:t<16384?2:t<2097152?3:t<268435456?4:5,t)).len,this}int32(t){return t<0?this._push(Lt,10,F.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let e=F.fromBigInt(t);return this._push(Lt,e.length(),e)}uint64Number(t){let e=F.fromNumber(t);return this._push(Lt,e.length(),e)}uint64String(t){return this.uint64(BigInt(t))}int64(t){return this.uint64(t)}int64Number(t){return this.uint64Number(t)}int64String(t){return this.uint64String(t)}sint64(t){let e=F.fromBigInt(t).zzEncode();return this._push(Lt,e.length(),e)}sint64Number(t){let e=F.fromNumber(t).zzEncode();return this._push(Lt,e.length(),e)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(je,1,t?1:0)}fixed32(t){return this._push(Bt,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=F.fromBigInt(t);return this._push(Bt,4,e.lo)._push(Bt,4,e.hi)}fixed64Number(t){let e=F.fromNumber(t);return this._push(Bt,4,e.lo)._push(Bt,4,e.hi)}fixed64String(t){return this.fixed64(BigInt(t))}sfixed64(t){return this.fixed64(t)}sfixed64Number(t){return this.fixed64Number(t)}sfixed64String(t){return this.fixed64String(t)}float(t){return this._push(mn,4,t)}double(t){return this._push(yn,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(je,1,0):this.uint32(e)._push(Po,e,t)}string(t){let e=xn(t);return e!==0?this.uint32(e)._push(Ne,e,t):this._push(je,1,0)}fork(){return this.states=new Je(this),this.head=this.tail=new st(Qe,0,0),this.len=0,this}reset(){return this.states!=null?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new st(Qe,0,0),this.len=0),this}ldelim(){let t=this.head,e=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=t.next,this.tail=e,this.len+=n),this}finish(){let t=this.head.next,e=Mo(this.len),n=0;for(;t!=null;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e}};function je(r,t,e){t[e]=r&255}function Ro(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var Ke=class extends st{next;constructor(t,e){super(Ro,t,e),this.next=void 0}};function Lt(r,t,e){for(;r.hi!==0;)t[e++]=r.lo&127|128,r.lo=(r.lo>>>7|r.hi<<25)>>>0,r.hi>>>=7;for(;r.lo>127;)t[e++]=r.lo&127|128,r.lo=r.lo>>>7;t[e++]=r.lo}function Bt(r,t,e){t[e]=r&255,t[e+1]=r>>>8&255,t[e+2]=r>>>16&255,t[e+3]=r>>>24}function Po(r,t,e){t.set(r,e)}globalThis.Buffer!=null&&(Ft.prototype.bytes=function(r){let t=r.length>>>0;return this.uint32(t),t>0&&this._push(Uo,t,r),this},Ft.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(Oo,t,r),this});function Uo(r,t,e){t.set(r,e)}function Oo(r,t,e){r.length<40?Ne(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set(Ln(r),e)}function Ze(){return new Ft}function it(r,t){let e=Ze();return t.encode(r,e,{lengthDelimited:!1}),e.finish()}var yt;(function(r){r[r.VARINT=0]="VARINT",r[r.BIT64=1]="BIT64",r[r.LENGTH_DELIMITED=2]="LENGTH_DELIMITED",r[r.START_GROUP=3]="START_GROUP",r[r.END_GROUP=4]="END_GROUP",r[r.BIT32=5]="BIT32"})(yt||(yt={}));function Vt(r,t,e,n){return{name:r,type:t,encode:e,decode:n}}function $t(r){function t(s){if(r[s.toString()]==null)throw new Error("Invalid enum value");return r[s]}let e=function(i,o){let a=t(i);o.int32(a)},n=function(i){let o=i.int32();return t(o)};return Vt("enum",yt.VARINT,e,n)}function ot(r,t){return Vt("message",yt.LENGTH_DELIMITED,r,t)}var D;(function(r){let t;(function(a){let c;(function(f){f.Block="Block",f.Have="Have"})(c=a.WantType||(a.WantType={}));let l;(function(f){f[f.Block=0]="Block",f[f.Have=1]="Have"})(l||(l={})),function(f){f.codec=()=>$t(l)}(c=a.WantType||(a.WantType={}));let u;(function(f){let m;f.codec=()=>(m==null&&(m=ot((d,g,p={})=>{p.lengthDelimited!==!1&&g.fork(),d.block!=null&&d.block.byteLength>0&&(g.uint32(10),g.bytes(d.block)),d.priority!=null&&d.priority!==0&&(g.uint32(16),g.int32(d.priority)),d.cancel!=null&&d.cancel!==!1&&(g.uint32(24),g.bool(d.cancel)),d.wantType!=null&&l[d.wantType]!==0&&(g.uint32(32),r.Wantlist.WantType.codec().encode(d.wantType,g)),d.sendDontHave!=null&&d.sendDontHave!==!1&&(g.uint32(40),g.bool(d.sendDontHave)),p.lengthDelimited!==!1&&g.ldelim()},(d,g)=>{let p={block:new Uint8Array(0),priority:0,cancel:!1,wantType:c.Block,sendDontHave:!1},w=g==null?d.len:d.pos+g;for(;d.pos<w;){let x=d.uint32();switch(x>>>3){case 1:p.block=d.bytes();break;case 2:p.priority=d.int32();break;case 3:p.cancel=d.bool();break;case 4:p.wantType=r.Wantlist.WantType.codec().decode(d);break;case 5:p.sendDontHave=d.bool();break;default:d.skipType(x&7);break}}return p})),m),f.encode=d=>it(d,f.codec()),f.decode=d=>nt(d,f.codec())})(u=a.Entry||(a.Entry={}));let h;a.codec=()=>(h==null&&(h=ot((f,m,d={})=>{if(d.lengthDelimited!==!1&&m.fork(),f.entries!=null)for(let g of f.entries)m.uint32(10),r.Wantlist.Entry.codec().encode(g,m);f.full!=null&&f.full!==!1&&(m.uint32(16),m.bool(f.full)),d.lengthDelimited!==!1&&m.ldelim()},(f,m)=>{let d={entries:[],full:!1},g=m==null?f.len:f.pos+m;for(;f.pos<g;){let p=f.uint32();switch(p>>>3){case 1:d.entries.push(r.Wantlist.Entry.codec().decode(f,f.uint32()));break;case 2:d.full=f.bool();break;default:f.skipType(p&7);break}}return d})),h),a.encode=f=>it(f,a.codec()),a.decode=f=>nt(f,a.codec())})(t=r.Wantlist||(r.Wantlist={}));let e;(function(a){let c;a.codec=()=>(c==null&&(c=ot((l,u,h={})=>{h.lengthDelimited!==!1&&u.fork(),l.prefix!=null&&l.prefix.byteLength>0&&(u.uint32(10),u.bytes(l.prefix)),l.data!=null&&l.data.byteLength>0&&(u.uint32(18),u.bytes(l.data)),h.lengthDelimited!==!1&&u.ldelim()},(l,u)=>{let h={prefix:new Uint8Array(0),data:new Uint8Array(0)},f=u==null?l.len:l.pos+u;for(;l.pos<f;){let m=l.uint32();switch(m>>>3){case 1:h.prefix=l.bytes();break;case 2:h.data=l.bytes();break;default:l.skipType(m&7);break}}return h})),c),a.encode=l=>it(l,a.codec()),a.decode=l=>nt(l,a.codec())})(e=r.Block||(r.Block={}));let n;(function(a){a.Have="Have",a.DontHave="DontHave"})(n=r.BlockPresenceType||(r.BlockPresenceType={}));let s;(function(a){a[a.Have=0]="Have",a[a.DontHave=1]="DontHave"})(s||(s={})),function(a){a.codec=()=>$t(s)}(n=r.BlockPresenceType||(r.BlockPresenceType={}));let i;(function(a){let c;a.codec=()=>(c==null&&(c=ot((l,u,h={})=>{h.lengthDelimited!==!1&&u.fork(),l.cid!=null&&l.cid.byteLength>0&&(u.uint32(10),u.bytes(l.cid)),l.type!=null&&s[l.type]!==0&&(u.uint32(16),r.BlockPresenceType.codec().encode(l.type,u)),h.lengthDelimited!==!1&&u.ldelim()},(l,u)=>{let h={cid:new Uint8Array(0),type:n.Have},f=u==null?l.len:l.pos+u;for(;l.pos<f;){let m=l.uint32();switch(m>>>3){case 1:h.cid=l.bytes();break;case 2:h.type=r.BlockPresenceType.codec().decode(l);break;default:l.skipType(m&7);break}}return h})),c),a.encode=l=>it(l,a.codec()),a.decode=l=>nt(l,a.codec())})(i=r.BlockPresence||(r.BlockPresence={}));let o;r.codec=()=>(o==null&&(o=ot((a,c,l={})=>{if(l.lengthDelimited!==!1&&c.fork(),a.wantlist!=null&&(c.uint32(10),r.Wantlist.codec().encode(a.wantlist,c)),a.blocks!=null)for(let u of a.blocks)c.uint32(18),c.bytes(u);if(a.payload!=null)for(let u of a.payload)c.uint32(26),r.Block.codec().encode(u,c);if(a.blockPresences!=null)for(let u of a.blockPresences)c.uint32(34),r.BlockPresence.codec().encode(u,c);a.pendingBytes!=null&&a.pendingBytes!==0&&(c.uint32(40),c.int32(a.pendingBytes)),l.lengthDelimited!==!1&&c.ldelim()},(a,c)=>{let l={blocks:[],payload:[],blockPresences:[],pendingBytes:0},u=c==null?a.len:a.pos+c;for(;a.pos<u;){let h=a.uint32();switch(h>>>3){case 1:l.wantlist=r.Wantlist.codec().decode(a,a.uint32());break;case 2:l.blocks.push(a.bytes());break;case 3:l.payload.push(r.Block.codec().decode(a,a.uint32()));break;case 4:l.blockPresences.push(r.BlockPresence.codec().decode(a,a.uint32()));break;case 5:l.pendingBytes=a.int32();break;default:a.skipType(h&7);break}}return l})),o),r.encode=a=>it(a,r.codec()),r.decode=a=>nt(a,r.codec())})(D||(D={}));var L=class r{static Entry=j;static WantType={Block:D.Wantlist.WantType.Block,Have:D.Wantlist.WantType.Have};static BlockPresenceType={Have:D.BlockPresenceType.Have,DontHave:D.BlockPresenceType.DontHave};static deserialize=async(t,e)=>{let n=D.decode(t),s=n.wantlist?.full===!0,i=new r(s);return n.wantlist?.entries.forEach(o=>{if(o.block==null)return;let a=T.decode(o.block);i.addEntry(a,o.priority??0,o.wantType,!!o.cancel,!!o.sendDontHave)}),n.blockPresences.forEach(o=>{if(o.cid==null)return;let a=T.decode(o.cid);o.type===r.BlockPresenceType.Have?i.addHave(a):i.addDontHave(a)}),n.blocks.length>0?(await Promise.all(n.blocks.map(async o=>{let a=await Ct.digest(o),c=T.createV0(a);i.addBlock(c,o)})),i):(n.payload.length>0&&(await Promise.all(n.payload.map(async o=>{if(o.prefix==null||o.data==null)return;let a=(0,Bn.default)(o.prefix),c=a[0],l=a[1],u=a[2],h=u===Ct.code?Ct:await e?.getHasher(u);if(h==null)throw new pt("Unknown hash algorithm","ERR_UNKNOWN_HASH_ALG");let f=await h.digest(o.data),m=T.create(c,l,f);i.addBlock(m,o.data)})),i.setPendingBytes(n.pendingBytes)),i)};static blockPresenceSize=t=>t.bytes.length+1;full;wantlist;blocks;blockPresences;pendingBytes;constructor(t){this.full=t,this.wantlist=new Map,this.blocks=new Map,this.blockPresences=new Map,this.pendingBytes=0}get empty(){return this.blocks.size===0&&this.wantlist.size===0&&this.blockPresences.size===0}addEntry(t,e,n,s,i){n==null&&(n=r.WantType.Block);let o=t.toString(b),a=this.wantlist.get(o);a!=null?(a.wantType===n&&(a.priority=e),s===!0&&(a.cancel=!!s),i===!0&&(a.sendDontHave=!!i),n===r.WantType.Block&&a.wantType===r.WantType.Have&&(a.wantType=n)):this.wantlist.set(o,new j(t,e,n,s,i))}addBlock(t,e){let n=t.toString(b);this.blocks.set(n,e)}addHave(t){let e=t.toString(b);this.blockPresences.has(e)||this.blockPresences.set(e,r.BlockPresenceType.Have)}addDontHave(t){let e=t.toString(b);this.blockPresences.has(e)||this.blockPresences.set(e,r.BlockPresenceType.DontHave)}cancel(t){let e=t.toString(b);this.wantlist.delete(e),this.addEntry(t,0,r.WantType.Block,!0,!1)}setPendingBytes(t){this.pendingBytes=t}serializeToBitswap100(){return D.encode({wantlist:{entries:Array.from(this.wantlist.values()).map(t=>({block:t.cid.bytes,priority:Number(t.priority),cancel:!!t.cancel,wantType:D.Wantlist.WantType.Block,sendDontHave:!1})),full:!!this.full},blocks:Array.from(this.blocks.values())})}serializeToBitswap110(){let t={wantlist:{entries:Array.from(this.wantlist.values()).map(e=>({block:e.cid.bytes,priority:Number(e.priority),wantType:e.wantType,cancel:!!e.cancel,sendDontHave:!!e.sendDontHave})),full:!!this.full},blockPresences:[],payload:[],pendingBytes:this.pendingBytes,blocks:[]};for(let[e,n]of this.blocks.entries()){let s=T.parse(e),i=s.version,o=s.code,a=s.multihash.code,c=s.multihash.digest.length,l=gn([i,o,a,c]);t.payload.push({prefix:l,data:n})}for(let[e,n]of this.blockPresences)t.blockPresences.push({cid:T.parse(e).bytes,type:n});return this.pendingBytes>0&&(t.pendingBytes=this.pendingBytes),D.encode(t)}equals(t){return!(this.full!==t.full||this.pendingBytes!==t.pendingBytes||!Ht(this.wantlist,t.wantlist)||!Ht(this.blocks,t.blocks)||!Ht(this.blockPresences,t.blockPresences))}get[Symbol.toStringTag](){let t=Array.from(this.wantlist.keys()),e=Array.from(this.blocks.keys());return`BitswapMessage <full: ${this.full}, list: ${t}, blocks: ${e}>`}};var Fn={Block:D.Wantlist.WantType.Block,Have:D.Wantlist.WantType.Have},zo=(r,t)=>Array.prototype.slice.call(t,0).sort((e,n)=>{let s=r(e),i=r(n);return s<i?-1:s>i?1:0}),Z=class{static Entry=et;set;_stats;constructor(t,e){this.set=e!=null?Q({name:"ipfs_bitswap_wantlist",metrics:e.metrics}):new Map,this._stats=t}get length(){return this.set.size}add(t,e,n){let s=t.toString(b),i=this.set.get(s);i!=null?(i.inc(),i.priority=e,i.wantType===Fn.Have&&n===Fn.Block&&(i.wantType=n)):(this.set.set(s,new et(t,e,n)),this._stats!=null&&this._stats.push(void 0,"wantListSize",1))}remove(t){let e=t.toString(b),n=this.set.get(e);n!=null&&(n.dec(),!n.hasRefs()&&(this.set.delete(e),this._stats!=null&&this._stats.push(void 0,"wantListSize",-1)))}removeForce(t){this.set.has(t)&&this.set.delete(t)}forEach(t){this.set.forEach(t)}entries(){return this.set.entries()}sortedEntries(){return new Map(zo(t=>t[1].key,Array.from(this.set.entries())))}contains(t){let e=t.toString(b);return this.set.has(e)}get(t){let e=t.toString(b);return this.set.get(e)}};var Gt=class{partner;wantlist;exchangeCount;accounting;lastExchange;constructor(t){this.partner=t,this.wantlist=new Z,this.exchangeCount=0,this.accounting={bytesSent:0,bytesRecv:0}}sentBytes(t){this.exchangeCount++,this.lastExchange=new Date().getTime(),this.accounting.bytesSent+=t}receivedBytes(t){this.exchangeCount++,this.lastExchange=new Date().getTime(),this.accounting.bytesRecv+=t}wants(t,e,n){this.wantlist.add(t,e,n)}cancelWant(t){this.wantlist.remove(t)}wantlistContains(t){return this.wantlist.get(t)}debtRatio(){return this.accounting.bytesSent/(this.accounting.bytesRecv+1)}};var Dt=class extends Map{_cmp;_keys;constructor(t,e){super(),this._cmp=e??this._defaultSort,this._keys=[];for(let[n,s]of t??[])this.set(n,s)}update(t){if(t<0||t>=this._keys.length)return;let e=this._keys[t];this._keys.splice(t,1);let n=this._find(e);this._keys.splice(n,0,e)}set(t,e){if(this.has(t)){let s=this.indexOf(t);this._keys.splice(s,1)}super.set(t,e);let n=this._find(t);return this._keys.splice(n,0,t),this}clear(){super.clear(),this._keys=[]}delete(t){if(!this.has(t))return!1;let e=this.indexOf(t);return this._keys.splice(e,1),super.delete(t)}indexOf(t){if(!this.has(t))return-1;let e=this._find(t);if(this._keys[e]===t)return e;for(let n=1;n<this._keys.length;n++){if(this._keys[e+n]===t)return e+n;if(this._keys[e-n]===t)return e-n}return-1}_find(t){let e=0,n=this._keys.length;for(;e<n;){let s=e+n>>>1,i=this._kCmp(this._keys[s],t);if(i<0)e=s+1;else if(i>0)n=s;else return s}return e}*keys(){for(let t of this._keys)yield t}*values(){for(let t of this._keys)yield this.get(t)}*entries(){for(let t of this._keys)yield[t,this.get(t)]}*[Symbol.iterator](){yield*this.entries()}forEach(t,e=this){if(t!=null)for(let n of this._keys){let s=this.get(n);if(s==null)throw new Error("Value cannot be undefined");t.apply(e,[[n,s]])}}_defaultSort(t,e){return t[0]<e[0]?-1:e[0]<t[0]?1:0}_kCmp(t,e){return this._cmp([t,this.get(t)],[e,this.get(e)])}};var Ho={hasNewInfo(){return!1},merge(){}},Xt=class{_taskMerger;_byPeer;constructor(t=Ho){this._taskMerger=t,this._byPeer=new Dt([],Qt.compare)}pushTasks(t,e){let n=this._byPeer.get(t.toString());n==null&&(n=new Qt(t,this._taskMerger)),n.pushTasks(e),this._byPeer.set(t.toString(),n)}popTasks(t){let e=this._head();if(e===void 0)return{tasks:[],pendingSize:0};let{tasks:n,pendingSize:s}=e.popTasks(t);if(n.length===0)return{tasks:n,pendingSize:s};let i=e.peerId;return e.isIdle()?this._byPeer.delete(i.toString()):this._byPeer.update(0),{peerId:i,tasks:n,pendingSize:s}}_head(){if(this._byPeer.size!==0)for(let[,t]of this._byPeer)return t}remove(t,e){this._byPeer.get(e.toString())?.remove(t)}tasksDone(t,e){let n=this._byPeer.get(t.toString());if(n==null)return;let s=this._byPeer.indexOf(t.toString());for(let i of e)n.taskDone(i);this._byPeer.update(s)}},Qt=class{peerId;_taskMerger;_activeTotalSize;_pending;_active;constructor(t,e){this.peerId=t,this._taskMerger=e,this._activeTotalSize=0,this._pending=new Ye,this._active=new Set}pushTasks(t){for(let e of t)this._pushTask(e)}_pushTask(t){if(!this._taskHasMoreInfoThanActiveTasks(t))return;let e=this._pending.get(t.topic);if(e!=null){t.priority>e.priority&&this._pending.updatePriority(t.topic,t.priority),this._taskMerger.merge(t,e);return}this._pending.add(t)}_taskHasMoreInfoThanActiveTasks(t){let e=[];for(let n of this._active)n.topic===t.topic&&e.push(n);return e.length===0?!0:this._taskMerger.hasNewInfo(t,e)}popTasks(t){let e=0,n=[],s=this._pending.tasks();for(let i=0;i<s.length&&e<t;i++){let o=s[i];n.push(o),e+=o.size,this._pending.delete(o.topic),this._activeTotalSize+=o.size,this._active.add(o)}return{tasks:n,pendingSize:this._pending.totalSize}}taskDone(t){this._active.has(t)&&(this._activeTotalSize-=t.size,this._active.delete(t))}remove(t){this._pending.delete(t)}isIdle(){return this._pending.length===0&&this._active.size===0}static compare(t,e){return t[1]._pending.length===0?1:e[1]._pending.length===0?-1:t[1]._activeTotalSize===e[1]._activeTotalSize?e[1]._pending.length-t[1]._pending.length:t[1]._activeTotalSize-e[1]._activeTotalSize}},Ye=class{_tasks;constructor(){this._tasks=new Dt([],this._compare)}get length(){return this._tasks.size}get totalSize(){return[...this._tasks.values()].reduce((t,e)=>t+e.task.size,0)}get(t){return this._tasks?.get(t)?.task}add(t){this._tasks.set(t.topic,{created:Date.now(),task:t})}delete(t){this._tasks.delete(t)}tasks(){return[...this._tasks.values()].map(t=>t.task)}updatePriority(t,e){let n=this._tasks.get(t);if(n==null)return;let s=this._tasks.indexOf(t);n.task.priority=e,this._tasks.update(s)}_compare(t,e){return t[1].task.priority===e[1].task.priority?t[1].created-e[1].created:e[1].task.priority-t[1].task.priority}};var Dn={hasNewInfo(r,t){let e=!1,n=!1;for(let s of t)s.data.haveBlock&&(e=!0),s.data.isWantBlock&&(n=!0);return!!(!n&&r.data.isWantBlock||!e&&r.data.haveBlock)},merge(r,t){let e=r.data,n=t.data;!n.haveBlock&&e.haveBlock&&(n.haveBlock=e.haveBlock,n.blockSize=e.blockSize),!n.isWantBlock&&e.isWantBlock&&(n.isWantBlock=!0,(!n.haveBlock||e.haveBlock)&&(n.haveBlock=e.haveBlock,t.size=r.size)),n.isWantBlock&&n.haveBlock&&(t.size=n.blockSize)}};var In=L.WantType,Wo=16*1024,qo=1024,jt=class{_log;blockstore;network;_stats;_opts;ledgerMap;_running;_requestQueue;constructor(t,e,n,s,i,o={}){this._log=z(t,"engine"),this.blockstore=e,this.network=n,this._stats=s,this._opts=this._processOpts(o),this.ledgerMap=Q({name:"ipfs_bitswap_ledger_map",metrics:i.metrics}),this._running=!1,this._requestQueue=new Xt(Dn)}_processOpts(t){return{maxSizeReplaceHasWithBlock:qo,targetMessageSize:Wo,...t}}_scheduleProcessTasks(){setTimeout(()=>{this._processTasks().catch(t=>{this._log.error("error processing stats",t)})})}async _processTasks(){if(!this._running)return;let{peerId:t,tasks:e,pendingSize:n}=this._requestQueue.popTasks(this._opts.targetMessageSize);if(e.length===0)return;let s=new L(!1);s.setPendingBytes(n);let i=[],o=new Map;for(let c of e){let l=T.parse(c.topic);c.data.haveBlock?c.data.isWantBlock?(i.push(l),o.set(c.topic,c.data)):s.addHave(l):s.addDontHave(l)}let a=await this._getBlocks(i);for(let[c,l]of o){let u=T.parse(c),h=a.get(c);h!=null?s.addBlock(u,h):l.sendDontHave&&s.addDontHave(u)}if(s.empty){t!=null&&this._requestQueue.tasksDone(t,e),this._scheduleProcessTasks();return}try{t!=null&&await this.network.sendMessage(t,s);for(let[c,l]of a.entries())t!=null&&this.messageSent(t,T.parse(c),l)}catch(c){this._log.error(c)}t!=null&&this._requestQueue.tasksDone(t,e),this._scheduleProcessTasks()}wantlistForPeer(t){let e=t.toString(),n=this.ledgerMap.get(e);return n!=null?n.wantlist.sortedEntries():new Map}ledgerForPeer(t){let e=t.toString(),n=this.ledgerMap.get(e);if(n!=null)return{peer:n.partner,value:n.debtRatio(),sent:n.accounting.bytesSent,recv:n.accounting.bytesRecv,exchanged:n.exchangeCount}}peers(){return Array.from(this.ledgerMap.values()).map(t=>t.partner)}receivedBlocks(t){if(t.length!==0){for(let e of this.ledgerMap.values())for(let{cid:n,block:s}of t){let i=e.wantlistContains(n);if(i==null)continue;let o=s.length,a=this._sendAsBlock(i.wantType,o),c=o;a||(c=L.blockPresenceSize(i.cid)),this._requestQueue.pushTasks(e.partner,[{topic:i.cid.toString(b),priority:i.priority,size:c,data:{blockSize:o,isWantBlock:a,haveBlock:!0,sendDontHave:!1}}])}this._scheduleProcessTasks()}}async messageReceived(t,e){let n=this._findOrCreate(t);if(e.empty)return;if(e.full&&(n.wantlist=new Z),this._updateBlockAccounting(e.blocks,n),e.wantlist.size===0){this._scheduleProcessTasks();return}let s=[],i=[];e.wantlist.forEach(o=>{o.cancel?(n.cancelWant(o.cid),s.push(o.cid)):(n.wants(o.cid,o.priority,o.wantType),i.push(o))}),this._cancelWants(t,s),await this._addWants(t,i),this._scheduleProcessTasks()}_cancelWants(t,e){for(let n of e)this._requestQueue.remove(n.toString(b),t)}async _addWants(t,e){let n=await this._getBlockSizes(e.map(i=>i.cid)),s=[];for(let i of e){let o=i.cid.toString(b),a=n.get(o);if(a==null)i.sendDontHave&&s.push({topic:o,priority:i.priority,size:L.blockPresenceSize(i.cid),data:{isWantBlock:i.wantType===In.Block,blockSize:0,haveBlock:!1,sendDontHave:i.sendDontHave}});else{let c=this._sendAsBlock(i.wantType,a),l=a;c||(l=L.blockPresenceSize(i.cid)),s.push({topic:o,priority:i.priority,size:l,data:{isWantBlock:c,blockSize:a,haveBlock:!0,sendDontHave:i.sendDontHave}})}this._requestQueue.pushTasks(t,s)}}_sendAsBlock(t,e){return t===In.Block||e<=this._opts.maxSizeReplaceHasWithBlock}async _getBlockSizes(t){let e=await this._getBlocks(t);return new Map([...e].map(([n,s])=>[n,s.length]))}async _getBlocks(t){let e=new Map;return await Promise.all(t.map(async n=>{try{let s=await this.blockstore.get(n);e.set(n.toString(b),s)}catch(s){s.code!=="ERR_NOT_FOUND"&&this._log.error("failed to query blockstore for %s: %s",n,s)}})),e}_updateBlockAccounting(t,e){for(let n of t.values())this._log("got block (%s bytes)",n.length),e.receivedBytes(n.length)}messageSent(t,e,n){let s=this._findOrCreate(t);s.sentBytes(n.length),s.wantlist.remove(e)}numBytesSentTo(t){return this._findOrCreate(t).accounting.bytesSent}numBytesReceivedFrom(t){return this._findOrCreate(t).accounting.bytesRecv}peerDisconnected(t){this.ledgerMap.delete(t.toString())}_findOrCreate(t){let e=t.toString(),n=this.ledgerMap.get(e);if(n!=null)return n;let s=new Gt(t);return this.ledgerMap.set(e,s),this._stats!=null&&this._stats.push(e,"peerCount",1),s}start(){this._running=!0}stop(){this._running=!1}};function Vo(r){return r[Symbol.asyncIterator]!=null}function $o(r){if(Vo(r))return(async()=>{for await(let t of r);})();for(let t of r);}var Nn=$o;var Go=Math.pow(2,7),Xo=Math.pow(2,14),Qo=Math.pow(2,21),tr=Math.pow(2,28),er=Math.pow(2,35),rr=Math.pow(2,42),nr=Math.pow(2,49),y=128,B=127;function at(r){if(r<Go)return 1;if(r<Xo)return 2;if(r<Qo)return 3;if(r<tr)return 4;if(r<er)return 5;if(r<rr)return 6;if(r<nr)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function jo(r,t,e=0){switch(at(r)){case 8:t[e++]=r&255|y,r/=128;case 7:t[e++]=r&255|y,r/=128;case 6:t[e++]=r&255|y,r/=128;case 5:t[e++]=r&255|y,r/=128;case 4:t[e++]=r&255|y,r>>>=7;case 3:t[e++]=r&255|y,r>>>=7;case 2:t[e++]=r&255|y,r>>>=7;case 1:{t[e++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return t}function Jo(r,t,e=0){switch(at(r)){case 8:t.set(e++,r&255|y),r/=128;case 7:t.set(e++,r&255|y),r/=128;case 6:t.set(e++,r&255|y),r/=128;case 5:t.set(e++,r&255|y),r/=128;case 4:t.set(e++,r&255|y),r>>>=7;case 3:t.set(e++,r&255|y),r>>>=7;case 2:t.set(e++,r&255|y),r>>>=7;case 1:{t.set(e++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return t}function Ko(r,t){let e=r[t],n=0;if(n+=e&B,e<y||(e=r[t+1],n+=(e&B)<<7,e<y)||(e=r[t+2],n+=(e&B)<<14,e<y)||(e=r[t+3],n+=(e&B)<<21,e<y)||(e=r[t+4],n+=(e&B)*tr,e<y)||(e=r[t+5],n+=(e&B)*er,e<y)||(e=r[t+6],n+=(e&B)*rr,e<y)||(e=r[t+7],n+=(e&B)*nr,e<y))return n;throw new RangeError("Could not decode varint")}function Zo(r,t){let e=r.get(t),n=0;if(n+=e&B,e<y||(e=r.get(t+1),n+=(e&B)<<7,e<y)||(e=r.get(t+2),n+=(e&B)<<14,e<y)||(e=r.get(t+3),n+=(e&B)<<21,e<y)||(e=r.get(t+4),n+=(e&B)*tr,e<y)||(e=r.get(t+5),n+=(e&B)*er,e<y)||(e=r.get(t+6),n+=(e&B)*rr,e<y)||(e=r.get(t+7),n+=(e&B)*nr,e<y))return n;throw new RangeError("Could not decode varint")}function Mn(r,t,e=0){return t==null&&(t=A(at(r))),t instanceof Uint8Array?jo(r,t,e):Jo(r,t,e)}function Rn(r,t=0){return r instanceof Uint8Array?Ko(r,t):Zo(r,t)}function sr(r,t){if(globalThis.Buffer!=null)return K(globalThis.Buffer.concat(r,t));t==null&&(t=r.reduce((s,i)=>s+i.length,0));let e=A(t),n=0;for(let s of r)e.set(s,n),n+=s.length;return K(e)}var On=Symbol.for("@achingbrain/uint8arraylist");function Un(r,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let e=0;for(let n of r){let s=e+n.byteLength;if(t<s)return{buf:n,index:t-e};e=s}throw new RangeError("index is out of bounds")}function Jt(r){return!!r?.[On]}var wt=class r{bufs;length;[On]=!0;constructor(...t){this.bufs=[],this.length=0,t.length>0&&this.appendAll(t)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...t){this.appendAll(t)}appendAll(t){let e=0;for(let n of t)if(n instanceof Uint8Array)e+=n.byteLength,this.bufs.push(n);else if(Jt(n))e+=n.byteLength,this.bufs.push(...n.bufs);else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}prepend(...t){this.prependAll(t)}prependAll(t){let e=0;for(let n of t.reverse())if(n instanceof Uint8Array)e+=n.byteLength,this.bufs.unshift(n);else if(Jt(n))e+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}get(t){let e=Un(this.bufs,t);return e.buf[e.index]}set(t,e){let n=Un(this.bufs,t);n.buf[n.index]=e}write(t,e=0){if(t instanceof Uint8Array)for(let n=0;n<t.length;n++)this.set(e+n,t[n]);else if(Jt(t))for(let n=0;n<t.length;n++)this.set(e+n,t.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(t){if(t=Math.trunc(t),!(Number.isNaN(t)||t<=0)){if(t===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(t>=this.bufs[0].byteLength)t-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(t),this.length-=t;break}}}slice(t,e){let{bufs:n,length:s}=this._subList(t,e);return sr(n,s)}subarray(t,e){let{bufs:n,length:s}=this._subList(t,e);return n.length===1?n[0]:sr(n,s)}sublist(t,e){let{bufs:n,length:s}=this._subList(t,e),i=new r;return i.length=s,i.bufs=[...n],i}_subList(t,e){if(t=t??0,e=e??this.length,t<0&&(t=this.length+t),e<0&&(e=this.length+e),t<0||e>this.length)throw new RangeError("index is out of bounds");if(t===e)return{bufs:[],length:0};if(t===0&&e===this.length)return{bufs:this.bufs,length:this.length};let n=[],s=0;for(let i=0;i<this.bufs.length;i++){let o=this.bufs[i],a=s,c=a+o.byteLength;if(s=c,t>=c)continue;let l=t>=a&&t<c,u=e>a&&e<=c;if(l&&u){if(t===a&&e===c){n.push(o);break}let h=t-a;n.push(o.subarray(h,h+(e-t)));break}if(l){if(t===0){n.push(o);continue}n.push(o.subarray(t-a));continue}if(u){if(e===c){n.push(o);break}n.push(o.subarray(0,e-a));break}n.push(o)}return{bufs:n,length:e-t}}indexOf(t,e=0){if(!Jt(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(e=Number(e??0),isNaN(e)&&(e=0),e<0&&(e=this.length+e),e<0&&(e=0),t.length===0)return e>this.length?this.length:e;let s=n.byteLength;if(s===0)throw new TypeError("search must be at least 1 byte long");let i=256,o=new Int32Array(i);for(let h=0;h<i;h++)o[h]=-1;for(let h=0;h<s;h++)o[n[h]]=h;let a=o,c=this.byteLength-n.byteLength,l=n.byteLength-1,u;for(let h=e;h<=c;h+=u){u=0;for(let f=l;f>=0;f--){let m=this.get(h+f);if(n[f]!==m){u=Math.max(1,f-a[m]);break}}if(u===0)return h}return-1}getInt8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getInt8(0)}setInt8(t,e){let n=A(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,e),this.write(n,t)}getInt16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,e)}setInt16(t,e,n){let s=$(2);new DataView(s.buffer,s.byteOffset,s.byteLength).setInt16(0,e,n),this.write(s,t)}getInt32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,e)}setInt32(t,e,n){let s=$(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setInt32(0,e,n),this.write(s,t)}getBigInt64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,e)}setBigInt64(t,e,n){let s=$(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setBigInt64(0,e,n),this.write(s,t)}getUint8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getUint8(0)}setUint8(t,e){let n=A(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,e),this.write(n,t)}getUint16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,e)}setUint16(t,e,n){let s=$(2);new DataView(s.buffer,s.byteOffset,s.byteLength).setUint16(0,e,n),this.write(s,t)}getUint32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,e)}setUint32(t,e,n){let s=$(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setUint32(0,e,n),this.write(s,t)}getBigUint64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,e)}setBigUint64(t,e,n){let s=$(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setBigUint64(0,e,n),this.write(s,t)}getFloat32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,e)}setFloat32(t,e,n){let s=$(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setFloat32(0,e,n),this.write(s,t)}getFloat64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,e)}setFloat64(t,e,n){let s=$(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setFloat64(0,e,n),this.write(s,t)}equals(t){if(t==null||!(t instanceof r)||t.bufs.length!==this.bufs.length)return!1;for(let e=0;e<this.bufs.length;e++)if(!zt(this.bufs[e],t.bufs[e]))return!1;return!0}static fromUint8Arrays(t,e){let n=new r;return n.bufs=t,e==null&&(e=t.reduce((s,i)=>s+i.byteLength,0)),n.length=e,n}};function Kt(r){return r[Symbol.asyncIterator]!=null}var Zt=r=>{let t=at(r),e=A(t);return Mn(r,e),Zt.bytes=t,e};Zt.bytes=0;function Yt(r,t){t=t??{};let e=t.lengthEncoder??Zt;function*n(s){let i=e(s.byteLength);i instanceof Uint8Array?yield i:yield*i,s instanceof Uint8Array?yield s:yield*s}return Kt(r)?async function*(){for await(let s of r)yield*n(s)}():function*(){for(let s of r)yield*n(s)}()}Yt.single=(r,t)=>{t=t??{};let e=t.lengthEncoder??Zt;return new wt(e(r.byteLength),r)};var _t=q(Wn(),1);var ta=8,ea=1024*1024*4,ct;(function(r){r[r.LENGTH=0]="LENGTH",r[r.DATA=1]="DATA"})(ct||(ct={}));var ir=r=>{let t=Rn(r);return ir.bytes=at(t),t};ir.bytes=0;function It(r,t){let e=new wt,n=ct.LENGTH,s=-1,i=t?.lengthDecoder??ir,o=t?.maxLengthLength??ta,a=t?.maxDataLength??ea;function*c(){for(;e.byteLength>0;){if(n===ct.LENGTH)try{if(s=i(e),s<0)throw(0,_t.default)(new Error("invalid message length"),"ERR_INVALID_MSG_LENGTH");if(s>a)throw(0,_t.default)(new Error("message length too long"),"ERR_MSG_DATA_TOO_LONG");let l=i.bytes;e.consume(l),t?.onLength!=null&&t.onLength(s),n=ct.DATA}catch(l){if(l instanceof RangeError){if(e.byteLength>o)throw(0,_t.default)(new Error("message length length too long"),"ERR_MSG_LENGTH_TOO_LONG");break}throw l}if(n===ct.DATA){if(e.byteLength<s)break;let l=e.sublist(0,s);e.consume(s),t?.onData!=null&&t.onData(l),yield l,n=ct.LENGTH}}}return Kt(r)?async function*(){for await(let l of r)e.append(l),yield*c();if(e.byteLength>0)throw(0,_t.default)(new Error("unexpected end of input"),"ERR_UNEXPECTED_EOF")}():function*(){for(let l of r)e.append(l),yield*c();if(e.byteLength>0)throw(0,_t.default)(new Error("unexpected end of input"),"ERR_UNEXPECTED_EOF")}()}It.fromReader=(r,t)=>{let e=1,n=async function*(){for(;;)try{let{done:i,value:o}=await r.next(e);if(i===!0)return;o!=null&&(yield o)}catch(i){if(i.code==="ERR_UNDER_READ")return{done:!0,value:null};throw i}finally{e=1}}();return It(n,{...t??{},onLength:i=>{e=i}})};function na(r){return r[Symbol.asyncIterator]!=null}function sa(r,t){if(na(r))return async function*(){for await(let a of r)yield t(a)}();let e=Rt(r),{value:n,done:s}=e.next();if(s===!0)return function*(){}();let i=t(n);if(typeof i.then=="function")return async function*(){yield await i;for await(let a of e)yield t(a)}();let o=t;return function*(){yield i;for(let a of e)yield o(a)}()}var qn=sa;function te(){let r={};return r.promise=new Promise((t,e)=>{r.resolve=t,r.reject=e}),r}var ee=class{buffer;mask;top;btm;next;constructor(t){if(!(t>0)||t-1&t)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(t),this.mask=t-1,this.top=0,this.btm=0,this.next=null}push(t){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=t,this.top=this.top+1&this.mask,!0)}shift(){let t=this.buffer[this.btm];if(t!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,t}isEmpty(){return this.buffer[this.btm]===void 0}},xt=class{size;hwm;head;tail;constructor(t={}){this.hwm=t.splitLimit??16,this.head=new ee(this.hwm),this.tail=this.head,this.size=0}calculateSize(t){return t?.byteLength!=null?t.byteLength:1}push(t){if(t?.value!=null&&(this.size+=this.calculateSize(t.value)),!this.head.push(t)){let e=this.head;this.head=e.next=new ee(2*this.head.buffer.length),this.head.push(t)}}shift(){let t=this.tail.shift();if(t===void 0&&this.tail.next!=null){let e=this.tail.next;this.tail.next=null,this.tail=e,t=this.tail.shift()}return t?.value!=null&&(this.size-=this.calculateSize(t.value)),t}isEmpty(){return this.head.isEmpty()}};var or=class extends Error{type;code;constructor(t,e){super(t??"The operation was aborted"),this.type="aborted",this.code=e??"ABORT_ERR"}};function re(r={}){return ia(e=>{let n=e.shift();if(n==null)return{done:!0};if(n.error!=null)throw n.error;return{done:n.done===!0,value:n.value}},r)}function ia(r,t){t=t??{};let e=t.onEnd,n=new xt,s,i,o,a=te(),c=async()=>{try{return n.isEmpty()?o?{done:!0}:await new Promise((p,w)=>{i=x=>{i=null,n.push(x);try{p(r(n))}catch(k){w(k)}return s}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=te()})}},l=p=>i!=null?i(p):(n.push(p),s),u=p=>(n=new xt,i!=null?i({error:p}):(n.push({error:p}),s)),h=p=>{if(o)return s;if(t?.objectMode!==!0&&p?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return l({done:!1,value:p})},f=p=>o?s:(o=!0,p!=null?u(p):l({done:!0})),m=()=>(n=new xt,f(),{done:!0}),d=p=>(f(p),{done:!0});if(s={[Symbol.asyncIterator](){return this},next:c,return:m,throw:d,push:h,end:f,get readableLength(){return n.size},onEmpty:async p=>{let w=p?.signal;if(w?.throwIfAborted(),n.isEmpty())return;let x,k;w!=null&&(x=new Promise((E,I)=>{k=()=>{I(new or)},w.addEventListener("abort",k)}));try{await Promise.race([a.promise,x])}finally{k!=null&&w!=null&&w?.removeEventListener("abort",k)}}},e==null)return s;let g=s;return s={[Symbol.asyncIterator](){return this},next(){return g.next()},throw(p){return g.throw(p),e!=null&&(e(p),e=void 0),{done:!0}},return(){return g.return(),e!=null&&(e(),e=void 0),{done:!0}},push:h,end(p){return g.end(p),e!=null&&(e(p),e=void 0),s},get readableLength(){return g.readableLength},onEmpty:p=>g.onEmpty(p)},s}function oa(r){return r[Symbol.asyncIterator]!=null}function aa(...r){let t=[];for(let e of r)oa(e)||t.push(e);return t.length===r.length?function*(){for(let e of t)yield*e}():async function*(){let e=re({objectMode:!0});Promise.resolve().then(async()=>{try{await Promise.all(r.map(async n=>{for await(let s of n)e.push(s)})),e.end()}catch(n){e.end(n)}}),yield*e}()}var Vn=aa;function cr(r,...t){if(r==null)throw new Error("Empty pipeline");if(ar(r)){let n=r;r=()=>n.source}else if(Gn(r)||$n(r)){let n=r;r=()=>n}let e=[r,...t];if(e.length>1&&ar(e[e.length-1])&&(e[e.length-1]=e[e.length-1].sink),e.length>2)for(let n=1;n<e.length-1;n++)ar(e[n])&&(e[n]=la(e[n]));return ca(...e)}var ca=(...r)=>{let t;for(;r.length>0;)t=r.shift()(t);return t},$n=r=>r?.[Symbol.asyncIterator]!=null,Gn=r=>r?.[Symbol.iterator]!=null,ar=r=>r==null?!1:r.sink!=null&&r.source!=null,la=r=>t=>{let e=r.sink(t);if(e?.then!=null){let n=re({objectMode:!0});e.then(()=>{n.end()},o=>{n.end(o)});let s,i=r.source;if($n(i))s=async function*(){yield*i,n.end()};else if(Gn(i))s=function*(){yield*i,n.end()};else throw new Error("Unknown duplex source type - must be Iterable or AsyncIterable");return Vn(n,s())}return r.source};function ua(r){return r[Symbol.asyncIterator]!=null}function ha(r,t){return ua(r)?async function*(){let e=0;if(!(t<1)){for await(let n of r)if(yield n,e++,e===t)return}}():function*(){let e=0;if(!(t<1)){for(let n of r)if(yield n,e++,e===t)return}}()}var Xn=ha;var W=class extends Event{constructor(t,e){super(t),this.detail=e}};var is=q(ts(),1);var es=Math.pow(2,31)-1,rs=1e3,ns=1;var hr="/ipfs/bitswap/1.0.0",fr="/ipfs/bitswap/1.1.0",dr="/ipfs/bitswap/1.2.0",pa=1024,ga=1024,ma=3e4,se=class{_log;_libp2p;_bitswap;_protocols;_stats;_running;_hashLoader;_maxInboundStreams;_maxOutboundStreams;_incomingStreamTimeout;_registrarIds;constructor(t,e,n,s={}){this._log=z(t.peerId,"network"),this._libp2p=t,this._bitswap=e,this._protocols=[hr],s.b100Only!==!0&&(this._protocols.unshift(fr),this._protocols.unshift(dr)),this._stats=n,this._running=!1,this._onPeerConnect=this._onPeerConnect.bind(this),this._onPeerDisconnect=this._onPeerDisconnect.bind(this),this._onConnection=this._onConnection.bind(this),this._hashLoader=s.hashLoader??{async getHasher(){throw new Error("Not implemented")}},this._maxInboundStreams=s.maxInboundStreams??pa,this._maxOutboundStreams=s.maxOutboundStreams??ga,this._incomingStreamTimeout=s.incomingStreamTimeout??ma}async start(){this._running=!0,await this._libp2p.handle(this._protocols,this._onConnection,{maxInboundStreams:this._maxInboundStreams,maxOutboundStreams:this._maxOutboundStreams});let t={onConnect:this._onPeerConnect,onDisconnect:this._onPeerDisconnect};this._registrarIds=[];for(let e of this._protocols)this._registrarIds.push(await this._libp2p.register(e,t));this._libp2p.getConnections().forEach(e=>{this._onPeerConnect(e.remotePeer)})}async stop(){if(this._running=!1,await this._libp2p.unhandle(this._protocols),this._registrarIds!=null){for(let t of this._registrarIds)this._libp2p.unregister(t);this._registrarIds=[]}}_onConnection(t){if(!this._running)return;let{stream:e,connection:n}=t,s=new is.TimeoutController(this._incomingStreamTimeout);Promise.resolve().then(async()=>{this._log("incoming new bitswap %s connection from %p",e.protocol,n.remotePeer);let i=()=>{e.abort(new pt("Incoming Bitswap stream timed out","ERR_TIMEOUT"))},o=AbortSignal.timeout(this._incomingStreamTimeout);o.addEventListener("abort",i),await cr(e,a=>It(a),async a=>{for await(let c of a){try{let l=await L.deserialize(c.subarray(),this._hashLoader);await this._bitswap._receiveMessage(n.remotePeer,l)}catch(l){this._bitswap._receiveError(l);break}o.removeEventListener("abort",i),o=AbortSignal.timeout(this._incomingStreamTimeout),o.addEventListener("abort",i)}}),await e.close({signal:o})}).catch(i=>{this._log(i),e.abort(i)}).finally(()=>{s.clear()})}_onPeerConnect(t){this._bitswap._onPeerConnected(t)}_onPeerDisconnect(t){this._bitswap._onPeerDisconnected(t)}findProviders(t,e={}){return e.onProgress?.(new W("bitswap:network:find-providers",t)),this._libp2p.contentRouting.findProviders(t,e)}async findAndConnect(t,e){await Nn(Xn(qn(this.findProviders(t,e),async n=>this.connectTo(n.id,e).catch(s=>{this._log.error(s)})),3)).catch(n=>{this._log.error(n)})}async provide(t,e={}){e.onProgress?.(new W("bitswap:network:provide",t)),await this._libp2p.contentRouting.provide(t,e)}async sendMessage(t,e,n={}){if(!this._running)throw new Error("network isn't running");let s=t.toString();this._log("sendMessage to %s",s,e),n.onProgress?.(new W("bitswap:network:send-wantlist",t)),await this._writeMessage(t,e,n),this._updateSentStats(t,e.blocks)}async connectTo(t,e={}){if(!this._running)throw new Error("network isn't running");return e.onProgress?.(new W("bitswap:network:dial",t)),this._libp2p.dial(t,e)}_updateSentStats(t,e){let n=t.toString();if(this._stats!=null){for(let s of e.values())this._stats.push(n,"dataSent",s.length);this._stats.push(n,"blocksSent",e.size)}}async _writeMessage(t,e,n={}){let s=await this._libp2p.dialProtocol(t,[dr,fr,hr]);try{let i;switch(s.protocol){case hr:i=e.serializeToBitswap100();break;case fr:case dr:i=e.serializeToBitswap110();break;default:throw new Error(`Unknown protocol: ${s.protocol}`)}await cr([i],o=>Yt(o),s),await s.close()}catch(i){n.onProgress?.(new W("bitswap:network:send-wantlist:error",{peer:t,error:i})),this._log(i),s.abort(i)}}};var ys=q(ae(),1);function gr(r,t="utf8"){let e=qt[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return(t==="utf8"||t==="utf-8")&&globalThis.Buffer!=null&&globalThis.Buffer.from!=null?globalThis.Buffer.from(r.buffer,r.byteOffset,r.byteLength).toString("utf8"):e.encoder.encode(r).substring(1)}var ms=r=>`unwant:${gr(r.multihash.bytes,"base64")}`,bs=r=>`block:${gr(r.multihash.bytes,"base64")}`,ce=class extends ys.EventEmitter{_log;constructor(t){super(),this.setMaxListeners(rs),this._log=z(t,"notif")}hasBlock(t,e){let n=bs(t);this._log(n),this.emit(n,e)}async wantBlock(t,e={}){if(t==null)throw new Error("Not a valid cid");let n=bs(t),s=ms(t);return this._log(`wantBlock:${t}`),new Promise((i,o)=>{let a=()=>{this.removeListener(n,c),e.onProgress?.(new W("bitswap:want-block:unwant",t)),o(new Error(`Block for ${t} unwanted`))},c=l=>{this.removeListener(s,a),e.onProgress?.(new W("bitswap:want-block:block",t)),i(l)};this.once(s,a),this.once(n,c),e.signal?.addEventListener("abort",()=>{this.removeListener(n,c),this.removeListener(s,a),o(new Error(`Want for ${t} aborted`))})})}unwantBlock(t){let e=ms(t);this._log(e),this.emit(e)}};var Es=q(ae(),1);var vs=q(ae(),1),mr=q(xs(),1),Nt=class extends vs.EventEmitter{_options;_queue;_stats;_frequencyLastTime;_frequencyAccumulators;_movingAverages;_enabled;_timeout;constructor(t,e){super(),this._options=e,this._queue=[],this._stats={},this._frequencyLastTime=Date.now(),this._frequencyAccumulators={},this._movingAverages={},this._update=this._update.bind(this),t.forEach(n=>{this._stats[n]=BigInt(0),this._movingAverages[n]={},this._options.movingAverageIntervals.forEach(s=>{(this._movingAverages[n][s]=(0,mr.default)(s)).push(this._frequencyLastTime,0)})}),this._enabled=this._options.enabled}enable(){this._enabled=!0}disable(){this._enabled=!1}stop(){this._timeout!=null&&clearTimeout(this._timeout)}get snapshot(){return Object.assign({},this._stats)}get movingAverages(){return Object.assign({},this._movingAverages)}push(t,e){this._enabled&&(this._queue.push([t,e,Date.now()]),this._resetComputeTimeout())}_resetComputeTimeout(){this._timeout!=null&&clearTimeout(this._timeout),this._timeout=setTimeout(this._update,this._nextTimeout())}_nextTimeout(){let t=this._queue.length/this._options.computeThrottleMaxQueueSize;return Math.max(this._options.computeThrottleTimeout*(1-t),0)}_update(){if(this._timeout=void 0,this._queue.length>0){let t;for(;this._queue.length>0;){let e=t=this._queue.shift();e!=null&&this._applyOp(e)}t!=null&&this._updateFrequency(t[2]),this.emit("update",this._stats)}}_updateFrequency(t){let e=t-this._frequencyLastTime;e>0&&Object.keys(this._stats).forEach(n=>{this._updateFrequencyFor(n,e,t)}),this._frequencyLastTime=t}_updateFrequencyFor(t,e,n){let s=this._frequencyAccumulators[t]??0;this._frequencyAccumulators[t]=0;let i=s/e*1e3,o=this._movingAverages[t];o==null&&(o=this._movingAverages[t]={}),this._options.movingAverageIntervals.forEach(a=>{let c=o[a];c==null&&(c=o[a]=(0,mr.default)(a)),c.push(n,i)})}_applyOp(t){let e=t[0],n=t[1];if(typeof n!="number")throw new Error(`invalid increment number: ${n}`);Object.prototype.hasOwnProperty.call(this._stats,e)||(this._stats[e]=BigInt(0)),this._stats[e]=BigInt(this._stats[e])+BigInt(n),this._frequencyAccumulators[e]==null&&(this._frequencyAccumulators[e]=0),this._frequencyAccumulators[e]+=n}};var ks={enabled:!1,computeThrottleTimeout:1e3,computeThrottleMaxQueueSize:1e3,movingAverageIntervals:[60*1e3,5*60*1e3,15*60*1e3]},le=class extends Es.EventEmitter{_initialCounters;_options;_enabled;_global;_peers;constructor(t,e=[],n=ks){super();let s=Object.assign({},ks,n);if(typeof s.computeThrottleTimeout!="number")throw new Error("need computeThrottleTimeout");if(typeof s.computeThrottleMaxQueueSize!="number")throw new Error("need computeThrottleMaxQueueSize");this._initialCounters=e,this._options=s,this._enabled=this._options.enabled,this._global=new Nt(e,s),this._global.on("update",i=>this.emit("update",i)),this._peers=Q({name:"ipfs_bitswap_stats_peers",metrics:t.metrics})}enable(){this._enabled=!0,this._options.enabled=!0,this._global.enable()}disable(){this._enabled=!1,this._options.enabled=!1,this._global.disable()}stop(){this._enabled=!1,this._global.stop();for(let t of this._peers)t[1].stop()}get snapshot(){return this._global.snapshot}get movingAverages(){return this._global.movingAverages}forPeer(t){let e=t.toString();return this._peers.get(e)}push(t,e,n){if(this._enabled&&(this._global.push(e,n),t!=null)){let s=this._peers.get(t);s==null&&(s=new Nt(this._initialCounters,this._options),this._peers.set(t,s)),s.push(e,n)}}disconnected(t){let e=t.toString(),n=this._peers.get(e);n!=null&&(n.stop(),this._peers.delete(e))}};var Ss=Ea;function Ea(r,t,e){var n=null,s=null,i=function(){n&&(clearTimeout(n),s=null,n=null)},o=function(){var c=s;i(),c&&c()},a=function(){if(!t)return r.apply(this,arguments);var c=this,l=arguments,u=e&&!n;if(i(),s=function(){r.apply(c,l)},n=setTimeout(function(){if(n=null,!u){var h=s;return s=null,h()}},t),u)return s()};return a.cancel=i,a.flush=o,a}var ue=class{peerId;refcnt;network;_entries;_log;constructor(t,e,n){this.peerId=e,this.network=n,this.refcnt=1,this._entries=[],this._log=z(t,"msgqueue"),this.sendEntries=Ss(this.sendEntries.bind(this),ns)}addMessage(t,e={}){t.empty||this.send(t,e)}addEntries(t,e={}){this._entries=this._entries.concat(t),this.sendEntries(e)}sendEntries(t={}){if(this._entries.length===0)return;let e=new L(!1);this._entries.forEach(n=>{n.cancel===!0?e.cancel(n.cid):e.addEntry(n.cid,n.priority)}),this._entries=[],this.addMessage(e,t)}async send(t,e={}){try{await this.network.connectTo(this.peerId,e)}catch(n){this._log.error("cant connect to peer %p: %s",this.peerId,n.message);return}this._log("sending message to peer %p",this.peerId),this.network.sendMessage(this.peerId,t,e).catch(n=>{this._log.error("send error",n)})}};var he=class{peers;wantlist;network;_peerId;_log;constructor(t,e,n,s){this.peers=Q({name:"ipfs_bitswap_want_manager_peers",metrics:s.metrics}),this.wantlist=new Z(n,s),this.network=e,this._peerId=t,this._log=z(t,"want")}_addEntries(t,e,n,s={}){let i=t.map((o,a)=>new L.Entry(o,es-a,L.WantType.Block,e));i.forEach(o=>{o.cancel?n===!0?this.wantlist.removeForce(o.cid.toString(b)):this.wantlist.remove(o.cid):(this._log("adding to wantlist"),this.wantlist.add(o.cid,o.priority))});for(let o of this.peers.values())o.addEntries(i,s)}_startPeerHandler(t){let e=this.peers.get(t.toString());if(e!=null){e.refcnt++;return}e=new ue(this._peerId,t,this.network);let n=new L(!0);for(let s of this.wantlist.entries())n.addEntry(s[1].cid,s[1].priority);return e.addMessage(n),this.peers.set(t.toString(),e),e}_stopPeerHandler(t){let e=this.peers.get(t.toString());e!=null&&(e.refcnt--,!(e.refcnt>0)&&this.peers.delete(t.toString()))}wantBlocks(t,e={}){this._addEntries(t,!1,!1,e),e.signal?.addEventListener("abort",()=>{this.cancelWants(t)})}unwantBlocks(t){this._log("unwant blocks: %s",t.length),this._addEntries(t,!0,!0)}cancelWants(t){this._log("cancel wants: %s",t.length),this._addEntries(t,!0)}connectedPeers(){return Array.from(this.peers.keys())}connected(t){this._startPeerHandler(t)}disconnected(t){this._stopPeerHandler(t)}start(){}stop(){this.peers.forEach(t=>{this.disconnected(t.peerId)})}};var Sa={async getHasher(){throw new Error("Not implemented")}},Ta={maxInboundStreams:1024,maxOutboundStreams:1024,incomingStreamTimeout:3e4,hashLoader:Sa,statsEnabled:!1,statsComputeThrottleTimeout:1e3,statsComputeThrottleMaxQueueSize:1e3},Ca=["blocksReceived","dataReceived","dupBlksReceived","dupDataReceived","blocksSent","dataSent","providesBufferLength","wantListLength","peerCount"],fe=class{_libp2p;_log;stats;network;blockstore;engine;wm;notifications;started;constructor(t,e,n={}){this._libp2p=t,this._log=z(this.peerId),n=Object.assign({},Ta,n),this.stats=new le(t,Ca,{enabled:n.statsEnabled,computeThrottleTimeout:n.statsComputeThrottleTimeout,computeThrottleMaxQueueSize:n.statsComputeThrottleMaxQueueSize}),this.network=new se(t,this,this.stats,{hashLoader:n.hashLoader,maxInboundStreams:n.maxInboundStreams,maxOutboundStreams:n.maxOutboundStreams,incomingStreamTimeout:n.incomingStreamTimeout}),this.blockstore=e,this.engine=new jt(this.peerId,e,this.network,this.stats,t),this.wm=new he(this.peerId,this.network,this.stats,t),this.notifications=new ce(this.peerId),this.started=!1}isStarted(){return this.started}get peerId(){return this._libp2p.peerId}async _receiveMessage(t,e){try{await this.engine.messageReceived(t,e)}catch{this._log("failed to receive message",e)}if(e.blocks.size===0)return;let n=[];for(let[s,i]of e.blocks.entries()){let o=T.parse(s);n.push({wasWanted:this.wm.wantlist.contains(o),cid:o,data:i})}this.wm.cancelWants(n.filter(({wasWanted:s})=>s).map(({cid:s})=>s)),await Promise.all(n.map(async({cid:s,wasWanted:i,data:o})=>{await this._handleReceivedBlock(t,s,o,i)}))}async _handleReceivedBlock(t,e,n,s){this._log("received block");let i=await this.blockstore.has(e);this._updateReceiveCounters(t.toString(),e,n,i),s&&await this.put(e,n)}_updateReceiveCounters(t,e,n,s){this.stats.push(t,"blocksReceived",1),this.stats.push(t,"dataReceived",n.length),s&&(this.stats.push(t,"dupBlksReceived",1),this.stats.push(t,"dupDataReceived",n.length))}_receiveError(t){this._log.error("ReceiveError",t)}_onPeerConnected(t){this.wm.connected(t)}_onPeerDisconnected(t){this.wm.disconnected(t),this.engine.peerDisconnected(t),this.stats.disconnected(t)}enableStats(){this.stats.enable()}disableStats(){this.stats.disable()}wantlistForPeer(t,e){return this.engine.wantlistForPeer(t)}ledgerForPeer(t){return this.engine.ledgerForPeer(t)}async want(t,e={}){let n=async(c,l)=>(this.wm.wantBlocks([c],l),this.notifications.wantBlock(c,l)),s=!1,i=async(c,l)=>{try{return await this.blockstore.get(c,l)}catch(u){if(u.code!=="ERR_NOT_FOUND")throw u;return s||(s=!0,this.network.findAndConnect(c,l).catch(h=>{this._log.error(h)})),await n(c,l)}},o=new AbortController,a=wr([o.signal,e.signal]);try{return await Promise.race([this.notifications.wantBlock(t,{...e,signal:a}),i(t,{...e,signal:a})])}finally{o.abort(),a.clear()}}unwant(t){let e=Array.isArray(t)?t:[t];this.wm.unwantBlocks(e),e.forEach(n=>{this.notifications.unwantBlock(n)})}cancelWants(t){this.wm.cancelWants(Array.isArray(t)?t:[t])}async put(t,e,n){await this.blockstore.put(t,e),this.notify(t,e)}async*putMany(t,e){yield*this.blockstore.putMany(xr(t,({cid:n,block:s})=>{this.notify(n,s)}),e)}notify(t,e,n={}){this.notifications.hasBlock(t,e),this.engine.receivedBlocks([{cid:t,block:e}]),this.network.provide(t,n).catch(s=>{this._log.error("Failed to provide: %s",s.message)})}getWantlist(){return this.wm.wantlist.entries()}get peers(){return this.engine.peers()}async start(){this.wm.start(),await this.network.start(),this.engine.start(),this.started=!0}async stop(){this.stats.stop(),this.wm.stop(),await this.network.stop(),this.engine.stop(),this.started=!1}};var Ts=(r,t,e={})=>new fe(r,t,e);var br=class{bitswap;started;constructor(t,e={}){let{libp2p:n,blockstore:s,hashers:i}=t;this.bitswap=Ts(n,s,{hashLoader:{getHasher:async o=>{let a;if(typeof o=="string"?a=Object.values(i).find(c=>c.name===o):a=i[o],a!=null)return a;throw new Error(`Could not load hasher for code/name "${o}"`)}},...e}),this.started=!1}isStarted(){return this.started}async start(){await this.bitswap.start(),this.started=!0}async stop(){await this.bitswap.stop(),this.started=!1}announce(t,e,n){this.bitswap.notify(t,e,n)}async retrieve(t,{validateFn:e,...n}={}){return this.bitswap.want(t,n)}};function Cs(r={}){return t=>new br(t,r)}var de=class{url;#t=0;#e=0;#r=0;#n=0;constructor(t){this.url=t instanceof URL?t:new URL(t)}async getRawBlock(t,e){let n=this.url;if(n.pathname=`/ipfs/${t.toString()}`,n.search="?format=raw",e?.aborted===!0)throw new Error(`Signal to fetch raw block for CID ${t} from gateway ${this.url} was aborted prior to fetch`);try{this.#t++;let s=await fetch(n.toString(),{signal:e,headers:{Accept:"application/vnd.ipld.raw"},cache:"force-cache"});if(!s.ok)throw this.#e++,new Error(`unable to fetch raw block for CID ${t} from gateway ${this.url}`);return this.#n++,new Uint8Array(await s.arrayBuffer())}catch{throw e?.aborted===!0?new Error(`fetching raw block for CID ${t} from gateway ${this.url} was aborted`):(this.#e++,new Error(`unable to fetch raw block for CID ${t}`))}}reliability(){return this.#t===0?1:this.#r>0?-1/0:this.#n/(this.#t+this.#e*3)}incrementInvalidBlocks(){this.#r++}};var pe=class{gateways;log;constructor(t,e={}){this.log=t.logger.forComponent("helia:trustless-gateway-block-broker"),this.gateways=(e.gateways??As).map(n=>new de(n))}async retrieve(t,e={}){let n=this.gateways.sort((i,o)=>o.reliability()-i.reliability()),s=[];for(let i of n){this.log("getting block for %c from %s",t,i.url);try{let o=await i.getRawBlock(t,e.signal);this.log.trace("got block for %c from %s",t,i.url);try{await e.validateFn?.(o)}catch(a){throw this.log.error("failed to validate block for %c from %s",t,i.url,a),i.incrementInvalidBlocks(),new Error(`unable to validate block for CID ${t} from gateway ${i.url}`)}return o}catch(o){if(this.log.error("failed to get block for %c from %s",t,i.url,o),o instanceof Error?s.push(o):s.push(new Error(`unable to fetch raw block for CID ${t} from gateway ${i.url}`)),e.signal?.aborted===!0){this.log.trace("request aborted while fetching raw block for CID %c from gateway %s",t,i.url);break}}}throw new AggregateError(s,`unable to fetch raw block for CID ${t} from any gateway`)}};var As=["https://dweb.link","https://cf-ipfs.com","https://4everland.io"];function Ls(r={}){return t=>new pe(t,r)}return Ms(Aa);})();
|
|
2
|
+
"use strict";var HeliaBlockBrokers=(()=>{var Ds=Object.create;var Nt=Object.defineProperty;var Is=Object.getOwnPropertyDescriptor;var Ns=Object.getOwnPropertyNames;var Ms=Object.getPrototypeOf,Rs=Object.prototype.hasOwnProperty;var S=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports),N=(r,t)=>{for(var e in t)Nt(r,e,{get:t[e],enumerable:!0})},_r=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of Ns(t))!Rs.call(r,s)&&s!==e&&Nt(r,s,{get:()=>t[s],enumerable:!(n=Is(t,s))||n.enumerable});return r};var $=(r,t,e)=>(e=r!=null?Ds(Ms(r)):{},_r(t||!r||!r.__esModule?Nt(e,"default",{value:r,enumerable:!0}):e,r)),Ps=r=>_r(Nt({},"__esModule",{value:!0}),r);var qr=S((Za,Wr)=>{Wr.exports=Hr;var zr=128,Si=127,Ti=~Si,Ci=Math.pow(2,31);function Hr(r,t,e){t=t||[],e=e||0;for(var n=e;r>=Ci;)t[e++]=r&255|zr,r/=128;for(;r&Ti;)t[e++]=r&255|zr,r>>>=7;return t[e]=r|0,Hr.bytes=e-n+1,t}});var Gr=S((Ya,Vr)=>{Vr.exports=Ce;var Ai=128,$r=127;function Ce(r,n){var e=0,n=n||0,s=0,i=n,o,a=r.length;do{if(i>=a)throw Ce.bytes=0,new RangeError("Could not decode varint");o=r[i++],e+=s<28?(o&$r)<<s:(o&$r)*Math.pow(2,s),s+=7}while(o>=Ai);return Ce.bytes=i-n,e}});var Qr=S((tc,Xr)=>{var Li=Math.pow(2,7),Bi=Math.pow(2,14),Fi=Math.pow(2,21),Di=Math.pow(2,28),Ii=Math.pow(2,35),Ni=Math.pow(2,42),Mi=Math.pow(2,49),Ri=Math.pow(2,56),Pi=Math.pow(2,63);Xr.exports=function(r){return r<Li?1:r<Bi?2:r<Fi?3:r<Di?4:r<Ii?5:r<Ni?6:r<Mi?7:r<Ri?8:r<Pi?9:10}});var Jr=S((ec,jr)=>{jr.exports={encode:qr(),decode:Gr(),encodingLength:Qr()}});var Yr=S((rc,Zr)=>{"use strict";var Kr=Jr();Zr.exports=r=>{if(!(r instanceof Uint8Array))throw new Error("arg needs to be a Uint8Array");let t=[];for(;r.length>0;){let e=Kr.decode(r);t.push(e),r=r.slice(Kr.decode.bytes)}return t}});var en=S((nc,tn)=>{var gt=1e3,mt=gt*60,bt=mt*60,et=bt*24,Ui=et*7,Oi=et*365.25;tn.exports=function(r,t){t=t||{};var e=typeof r;if(e==="string"&&r.length>0)return zi(r);if(e==="number"&&isFinite(r))return t.long?Wi(r):Hi(r);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(r))};function zi(r){if(r=String(r),!(r.length>100)){var t=/^(-?(?:\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(t){var e=parseFloat(t[1]),n=(t[2]||"ms").toLowerCase();switch(n){case"years":case"year":case"yrs":case"yr":case"y":return e*Oi;case"weeks":case"week":case"w":return e*Ui;case"days":case"day":case"d":return e*et;case"hours":case"hour":case"hrs":case"hr":case"h":return e*bt;case"minutes":case"minute":case"mins":case"min":case"m":return e*mt;case"seconds":case"second":case"secs":case"sec":case"s":return e*gt;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return e;default:return}}}}function Hi(r){var t=Math.abs(r);return t>=et?Math.round(r/et)+"d":t>=bt?Math.round(r/bt)+"h":t>=mt?Math.round(r/mt)+"m":t>=gt?Math.round(r/gt)+"s":r+"ms"}function Wi(r){var t=Math.abs(r);return t>=et?Pt(r,t,et,"day"):t>=bt?Pt(r,t,bt,"hour"):t>=mt?Pt(r,t,mt,"minute"):t>=gt?Pt(r,t,gt,"second"):r+" ms"}function Pt(r,t,e,n){var s=t>=e*1.5;return Math.round(r/e)+" "+n+(s?"s":"")}});var nn=S((sc,rn)=>{function qi(r){e.debug=e,e.default=e,e.coerce=c,e.disable=i,e.enable=s,e.enabled=o,e.humanize=en(),e.destroy=l,Object.keys(r).forEach(u=>{e[u]=r[u]}),e.names=[],e.skips=[],e.formatters={};function t(u){let h=0;for(let f=0;f<u.length;f++)h=(h<<5)-h+u.charCodeAt(f),h|=0;return e.colors[Math.abs(h)%e.colors.length]}e.selectColor=t;function e(u){let h,f=null,m,d;function g(...p){if(!g.enabled)return;let w=g,x=Number(new Date),k=x-(h||x);w.diff=k,w.prev=h,w.curr=x,h=x,p[0]=e.coerce(p[0]),typeof p[0]!="string"&&p.unshift("%O");let E=0;p[0]=p[0].replace(/%([a-zA-Z%])/g,(U,I)=>{if(U==="%%")return"%";E++;let O=e.formatters[I];if(typeof O=="function"){let lt=p[E];U=O.call(w,lt),p.splice(E,1),E--}return U}),e.formatArgs.call(w,p),(w.log||e.log).apply(w,p)}return g.namespace=u,g.useColors=e.useColors(),g.color=e.selectColor(u),g.extend=n,g.destroy=e.destroy,Object.defineProperty(g,"enabled",{enumerable:!0,configurable:!1,get:()=>f!==null?f:(m!==e.namespaces&&(m=e.namespaces,d=e.enabled(u)),d),set:p=>{f=p}}),typeof e.init=="function"&&e.init(g),g}function n(u,h){let f=e(this.namespace+(typeof h>"u"?":":h)+u);return f.log=this.log,f}function s(u){e.save(u),e.namespaces=u,e.names=[],e.skips=[];let h,f=(typeof u=="string"?u:"").split(/[\s,]+/),m=f.length;for(h=0;h<m;h++)f[h]&&(u=f[h].replace(/\*/g,".*?"),u[0]==="-"?e.skips.push(new RegExp("^"+u.slice(1)+"$")):e.names.push(new RegExp("^"+u+"$")))}function i(){let u=[...e.names.map(a),...e.skips.map(a).map(h=>"-"+h)].join(",");return e.enable(""),u}function o(u){if(u[u.length-1]==="*")return!0;let h,f;for(h=0,f=e.skips.length;h<f;h++)if(e.skips[h].test(u))return!1;for(h=0,f=e.names.length;h<f;h++)if(e.names[h].test(u))return!0;return!1}function a(u){return u.toString().substring(2,u.toString().length-2).replace(/\.\*\?$/,"*")}function c(u){return u instanceof Error?u.stack||u.message:u}function l(){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 e.enable(e.load()),e}rn.exports=qi});var sn=S((M,Ut)=>{M.formatArgs=Vi;M.save=Gi;M.load=Xi;M.useColors=$i;M.storage=Qi();M.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`."))}})();M.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 $i(){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 Vi(r){if(r[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+r[0]+(this.useColors?"%c ":" ")+"+"+Ut.exports.humanize(this.diff),!this.useColors)return;let t="color: "+this.color;r.splice(1,0,t,"color: inherit");let e=0,n=0;r[0].replace(/%[a-zA-Z%]/g,s=>{s!=="%%"&&(e++,s==="%c"&&(n=e))}),r.splice(n,0,t)}M.log=console.debug||console.log||(()=>{});function Gi(r){try{r?M.storage.setItem("debug",r):M.storage.removeItem("debug")}catch{}}function Xi(){let r;try{r=M.storage.getItem("debug")}catch{}return!r&&typeof process<"u"&&"env"in process&&(r=process.env.DEBUG),r}function Qi(){try{return localStorage}catch{}}Ut.exports=nn()(M);var{formatters:ji}=Ut.exports;ji.j=function(r){try{return JSON.stringify(r)}catch(t){return"[UnexpectedJSONParseError]: "+t.message}}});var ln=S((_c,cn)=>{cn.exports=Be;var an=128,to=127,eo=~to,ro=Math.pow(2,31);function Be(r,t,e){if(Number.MAX_SAFE_INTEGER&&r>Number.MAX_SAFE_INTEGER)throw Be.bytes=0,new RangeError("Could not encode varint");t=t||[],e=e||0;for(var n=e;r>=ro;)t[e++]=r&255|an,r/=128;for(;r&eo;)t[e++]=r&255|an,r>>>=7;return t[e]=r|0,Be.bytes=e-n+1,t}});var fn=S((xc,hn)=>{hn.exports=Fe;var no=128,un=127;function Fe(r,n){var e=0,n=n||0,s=0,i=n,o,a=r.length;do{if(i>=a||s>49)throw Fe.bytes=0,new RangeError("Could not decode varint");o=r[i++],e+=s<28?(o&un)<<s:(o&un)*Math.pow(2,s),s+=7}while(o>=no);return Fe.bytes=i-n,e}});var pn=S((vc,dn)=>{var so=Math.pow(2,7),io=Math.pow(2,14),oo=Math.pow(2,21),ao=Math.pow(2,28),co=Math.pow(2,35),lo=Math.pow(2,42),uo=Math.pow(2,49),ho=Math.pow(2,56),fo=Math.pow(2,63);dn.exports=function(r){return r<so?1:r<io?2:r<oo?3:r<ao?4:r<co?5:r<lo?6:r<uo?7:r<ho?8:r<fo?9:10}});var mn=S((kc,gn)=>{gn.exports={encode:ln(),decode:fn(),encodingLength:pn()}});var $n=S((Tu,qn)=>{"use strict";function Wn(r,t){for(let e in t)Object.defineProperty(r,e,{value:t[e],enumerable:!0,configurable:!0});return r}function Yo(r,t,e){if(!r||typeof r=="string")throw new TypeError("Please pass an Error to err-code");e||(e={}),typeof t=="object"&&(e=t,t=""),t&&(e.code=t);try{return Wn(r,e)}catch{e.message=r.message,e.stack=r.stack;let s=function(){};return s.prototype=Object.create(Object.getPrototypeOf(r)),Wn(new s,e)}}qn.exports=Yo});var Kn=S((Gu,Jn)=>{"use strict";Jn.exports=function(){return Date.now()}});var Yn=S((Xu,Zn)=>{"use strict";var ne=Kn(),hr=class{constructor(t,e,n){let s=this;this._started=ne(),this._rescheduled=0,this._scheduled=e,this._args=n,this._triggered=!1,this._timerWrapper=()=>{s._rescheduled>0?(s._scheduled=s._rescheduled-(ne()-s._started),s._schedule(s._scheduled)):(s._triggered=!0,t.apply(null,s._args))},this._timer=setTimeout(this._timerWrapper,e)}reschedule(t){t||(t=this._scheduled);let e=ne();e+t-(this._started+this._scheduled)<0?(clearTimeout(this._timer),this._schedule(t)):this._triggered?this._schedule(t):(this._started=e,this._rescheduled=t)}_schedule(t){this._triggered=!1,this._started=ne(),this._rescheduled=0,this._scheduled=t,this._timer=setTimeout(this._timerWrapper,t)}clear(){clearTimeout(this._timer)}};function fa(){if(typeof arguments[0]!="function")throw new Error("callback needed");if(typeof arguments[1]!="number")throw new Error("timeout needed");let r;if(arguments.length>0){r=new Array(arguments.length-2);for(var t=0;t<r.length;t++)r[t]=arguments[t+2]}return new hr(arguments[0],arguments[1],r)}Zn.exports=fa});var rs=S((Qu,es)=>{"use strict";var{AbortController:da}=globalThis,ts=Yn(),fr=class r extends da{constructor(t){super(),this._ms=t,this._timer=ts(()=>this.abort(),t),Object.setPrototypeOf(this,r.prototype)}abort(){return this._timer.clear(),super.abort()}clear(){this._timer.clear()}reset(){this._timer.clear(),this._timer=ts(()=>this.abort(),this._ms)}};es.exports={TimeoutController:fr}});var ae=S((ih,mr)=>{"use strict";var vt=typeof Reflect=="object"?Reflect:null,cs=vt&&typeof vt.apply=="function"?vt.apply:function(t,e,n){return Function.prototype.apply.call(t,e,n)},ie;vt&&typeof vt.ownKeys=="function"?ie=vt.ownKeys:Object.getOwnPropertySymbols?ie=function(t){return Object.getOwnPropertyNames(t).concat(Object.getOwnPropertySymbols(t))}:ie=function(t){return Object.getOwnPropertyNames(t)};function ba(r){console&&console.warn&&console.warn(r)}var us=Number.isNaN||function(t){return t!==t};function _(){_.init.call(this)}mr.exports=_;mr.exports.once=xa;_.EventEmitter=_;_.prototype._events=void 0;_.prototype._eventsCount=0;_.prototype._maxListeners=void 0;var ls=10;function oe(r){if(typeof r!="function")throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof r)}Object.defineProperty(_,"defaultMaxListeners",{enumerable:!0,get:function(){return ls},set:function(r){if(typeof r!="number"||r<0||us(r))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+r+".");ls=r}});_.init=function(){(this._events===void 0||this._events===Object.getPrototypeOf(this)._events)&&(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0};_.prototype.setMaxListeners=function(t){if(typeof t!="number"||t<0||us(t))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+t+".");return this._maxListeners=t,this};function hs(r){return r._maxListeners===void 0?_.defaultMaxListeners:r._maxListeners}_.prototype.getMaxListeners=function(){return hs(this)};_.prototype.emit=function(t){for(var e=[],n=1;n<arguments.length;n++)e.push(arguments[n]);var s=t==="error",i=this._events;if(i!==void 0)s=s&&i.error===void 0;else if(!s)return!1;if(s){var o;if(e.length>0&&(o=e[0]),o instanceof Error)throw o;var a=new Error("Unhandled error."+(o?" ("+o.message+")":""));throw a.context=o,a}var c=i[t];if(c===void 0)return!1;if(typeof c=="function")cs(c,this,e);else for(var l=c.length,u=ms(c,l),n=0;n<l;++n)cs(u[n],this,e);return!0};function fs(r,t,e,n){var s,i,o;if(oe(e),i=r._events,i===void 0?(i=r._events=Object.create(null),r._eventsCount=0):(i.newListener!==void 0&&(r.emit("newListener",t,e.listener?e.listener:e),i=r._events),o=i[t]),o===void 0)o=i[t]=e,++r._eventsCount;else if(typeof o=="function"?o=i[t]=n?[e,o]:[o,e]:n?o.unshift(e):o.push(e),s=hs(r),s>0&&o.length>s&&!o.warned){o.warned=!0;var a=new Error("Possible EventEmitter memory leak detected. "+o.length+" "+String(t)+" listeners added. Use emitter.setMaxListeners() to increase limit");a.name="MaxListenersExceededWarning",a.emitter=r,a.type=t,a.count=o.length,ba(a)}return r}_.prototype.addListener=function(t,e){return fs(this,t,e,!1)};_.prototype.on=_.prototype.addListener;_.prototype.prependListener=function(t,e){return fs(this,t,e,!0)};function ya(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,arguments.length===0?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function ds(r,t,e){var n={fired:!1,wrapFn:void 0,target:r,type:t,listener:e},s=ya.bind(n);return s.listener=e,n.wrapFn=s,s}_.prototype.once=function(t,e){return oe(e),this.on(t,ds(this,t,e)),this};_.prototype.prependOnceListener=function(t,e){return oe(e),this.prependListener(t,ds(this,t,e)),this};_.prototype.removeListener=function(t,e){var n,s,i,o,a;if(oe(e),s=this._events,s===void 0)return this;if(n=s[t],n===void 0)return this;if(n===e||n.listener===e)--this._eventsCount===0?this._events=Object.create(null):(delete s[t],s.removeListener&&this.emit("removeListener",t,n.listener||e));else if(typeof n!="function"){for(i=-1,o=n.length-1;o>=0;o--)if(n[o]===e||n[o].listener===e){a=n[o].listener,i=o;break}if(i<0)return this;i===0?n.shift():wa(n,i),n.length===1&&(s[t]=n[0]),s.removeListener!==void 0&&this.emit("removeListener",t,a||e)}return this};_.prototype.off=_.prototype.removeListener;_.prototype.removeAllListeners=function(t){var e,n,s;if(n=this._events,n===void 0)return this;if(n.removeListener===void 0)return arguments.length===0?(this._events=Object.create(null),this._eventsCount=0):n[t]!==void 0&&(--this._eventsCount===0?this._events=Object.create(null):delete n[t]),this;if(arguments.length===0){var i=Object.keys(n),o;for(s=0;s<i.length;++s)o=i[s],o!=="removeListener"&&this.removeAllListeners(o);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if(e=n[t],typeof e=="function")this.removeListener(t,e);else if(e!==void 0)for(s=e.length-1;s>=0;s--)this.removeListener(t,e[s]);return this};function ps(r,t,e){var n=r._events;if(n===void 0)return[];var s=n[t];return s===void 0?[]:typeof s=="function"?e?[s.listener||s]:[s]:e?_a(s):ms(s,s.length)}_.prototype.listeners=function(t){return ps(this,t,!0)};_.prototype.rawListeners=function(t){return ps(this,t,!1)};_.listenerCount=function(r,t){return typeof r.listenerCount=="function"?r.listenerCount(t):gs.call(r,t)};_.prototype.listenerCount=gs;function gs(r){var t=this._events;if(t!==void 0){var e=t[r];if(typeof e=="function")return 1;if(e!==void 0)return e.length}return 0}_.prototype.eventNames=function(){return this._eventsCount>0?ie(this._events):[]};function ms(r,t){for(var e=new Array(t),n=0;n<t;++n)e[n]=r[n];return e}function wa(r,t){for(;t+1<r.length;t++)r[t]=r[t+1];r.pop()}function _a(r){for(var t=new Array(r.length),e=0;e<t.length;++e)t[e]=r[e].listener||r[e];return t}function xa(r,t){return new Promise(function(e,n){function s(o){r.removeListener(t,i),n(o)}function i(){typeof r.removeListener=="function"&&r.removeListener("error",s),e([].slice.call(arguments))}bs(r,t,i,{once:!0}),t!=="error"&&va(r,s,{once:!0})})}function va(r,t,e){typeof r.on=="function"&&bs(r,"error",t,e)}function bs(r,t,e,n){if(typeof r.on=="function")n.once?r.once(t,e):r.on(t,e);else if(typeof r.addEventListener=="function")r.addEventListener(t,function s(i){n.once&&r.removeEventListener(t,s),e(i)});else throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type '+typeof r)}});var ks=S((xs,vs)=>{"use strict";var ka=Math.exp;xs=vs.exports=function(t){if(typeof t!="number")throw new Error("must provide a timespan to the moving average constructor");if(t<=0)throw new Error("must provide a timespan > 0 to the moving average constructor");let e,n=0,s=0,i=0,o,a={};function c(l,u){return 1-ka(-(l-u)/t)}return a.push=function(u,h){if(o){let f=c(u,o),m=h-e,d=f*m;e=f*h+(1-f)*e,n=(1-f)*(n+m*d),s=Math.sqrt(n),i=e+f*m}else e=h;o=u},a.movingAverage=function(){return e},a.variance=function(){return n},a.deviation=function(){return s},a.forecast=function(){return i},a}});var Aa={};N(Aa,{bitswap:()=>Ls,trustlessGateway:()=>Fs});function xr(r){let t=new globalThis.AbortController;function e(){t.abort();for(let i of r)i?.removeEventListener!=null&&i.removeEventListener("abort",e)}for(let i of r){if(i?.aborted===!0){e();break}i?.addEventListener!=null&&i.addEventListener("abort",e)}function n(){for(let i of r)i?.removeEventListener!=null&&i.removeEventListener("abort",e)}let s=t.signal;return s.clear=n,s}function Us(r){let[t,e]=r[Symbol.asyncIterator]!=null?[r[Symbol.asyncIterator](),Symbol.asyncIterator]:[r[Symbol.iterator](),Symbol.iterator],n=[];return{peek:()=>t.next(),push:s=>{n.push(s)},next:()=>n.length>0?{done:!1,value:n.shift()}:t.next(),[e](){return this}}}var Mt=Us;function Os(r){return r[Symbol.asyncIterator]!=null}function vr(r){return r?.then!=null}function zs(r,t){if(Os(r))return async function*(){for await(let a of r){let c=t(a);vr(c)&&await c,yield a}}();let e=Mt(r),{value:n,done:s}=e.next();if(s===!0)return function*(){}();if(typeof t(n)?.then=="function")return async function*(){yield n;for await(let a of e){let c=t(a);vr(c)&&await c,yield a}}();let o=t;return function*(){yield n;for(let a of e)o(a),yield a}()}var kr=zs;var we={};N(we,{base32:()=>Q,base32hex:()=>js,base32hexpad:()=>Ks,base32hexpadupper:()=>Zs,base32hexupper:()=>Js,base32pad:()=>Xs,base32padupper:()=>Qs,base32upper:()=>Gs,base32z:()=>Ys});var Na=new Uint8Array(0);function Er(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}function V(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 Sr(r){return new TextEncoder().encode(r)}function Tr(r){return new TextDecoder().decode(r)}function Hs(r,t){if(r.length>=255)throw new TypeError("Alphabet too long");for(var e=new Uint8Array(256),n=0;n<e.length;n++)e[n]=255;for(var s=0;s<r.length;s++){var i=r.charAt(s),o=i.charCodeAt(0);if(e[o]!==255)throw new TypeError(i+" is ambiguous");e[o]=s}var a=r.length,c=r.charAt(0),l=Math.log(a)/Math.log(256),u=Math.log(256)/Math.log(a);function h(d){if(d instanceof Uint8Array||(ArrayBuffer.isView(d)?d=new Uint8Array(d.buffer,d.byteOffset,d.byteLength):Array.isArray(d)&&(d=Uint8Array.from(d))),!(d instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(d.length===0)return"";for(var g=0,p=0,w=0,x=d.length;w!==x&&d[w]===0;)w++,g++;for(var k=(x-w)*u+1>>>0,E=new Uint8Array(k);w!==x;){for(var D=d[w],U=0,I=k-1;(D!==0||U<p)&&I!==-1;I--,U++)D+=256*E[I]>>>0,E[I]=D%a>>>0,D=D/a>>>0;if(D!==0)throw new Error("Non-zero carry");p=U,w++}for(var O=k-p;O!==k&&E[O]===0;)O++;for(var lt=c.repeat(g);O<k;++O)lt+=r.charAt(E[O]);return lt}function f(d){if(typeof d!="string")throw new TypeError("Expected String");if(d.length===0)return new Uint8Array;var g=0;if(d[g]!==" "){for(var p=0,w=0;d[g]===c;)p++,g++;for(var x=(d.length-g)*l+1>>>0,k=new Uint8Array(x);d[g];){var E=e[d.charCodeAt(g)];if(E===255)return;for(var D=0,U=x-1;(E!==0||D<w)&&U!==-1;U--,D++)E+=a*k[U]>>>0,k[U]=E%256>>>0,E=E/256>>>0;if(E!==0)throw new Error("Non-zero carry");w=D,g++}if(d[g]!==" "){for(var I=x-w;I!==x&&k[I]===0;)I++;for(var O=new Uint8Array(p+(x-I)),lt=p;I!==x;)O[lt++]=k[I++];return O}}}function m(d){var g=f(d);if(g)return g;throw new Error(`Non-${t} character`)}return{encode:h,decodeUnsafe:f,decode:m}}var Ws=Hs,qs=Ws,Ar=qs;var ge=class{name;prefix;baseEncode;constructor(t,e,n){this.name=t,this.prefix=e,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},me=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,e,n){if(this.name=t,this.prefix=e,e.codePointAt(0)===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=e.codePointAt(0),this.baseDecode=n}decode(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return Lr(this,t)}},be=class{decoders;constructor(t){this.decoders=t}or(t){return Lr(this,t)}decode(t){let e=t[0],n=this.decoders[e];if(n!=null)return n.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function Lr(r,t){return new be({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var ye=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,e,n,s){this.name=t,this.prefix=e,this.baseEncode=n,this.baseDecode=s,this.encoder=new ge(t,e,n),this.decoder=new me(t,e,s)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function ut({name:r,prefix:t,encode:e,decode:n}){return new ye(r,t,e,n)}function X({name:r,prefix:t,alphabet:e}){let{encode:n,decode:s}=Ar(e,r);return ut({prefix:t,name:r,encode:n,decode:i=>V(s(i))})}function $s(r,t,e,n){let s={};for(let u=0;u<t.length;++u)s[t[u]]=u;let i=r.length;for(;r[i-1]==="=";)--i;let o=new Uint8Array(i*e/8|0),a=0,c=0,l=0;for(let u=0;u<i;++u){let h=s[r[u]];if(h===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<e|h,a+=e,a>=8&&(a-=8,o[l++]=255&c>>a)}if(a>=e||255&c<<8-a)throw new SyntaxError("Unexpected end of data");return o}function Vs(r,t,e){let n=t[t.length-1]==="=",s=(1<<e)-1,i="",o=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],o+=8;o>e;)o-=e,i+=t[s&a>>o];if(o!==0&&(i+=t[s&a<<e-o]),n)for(;i.length*e&7;)i+="=";return i}function v({name:r,prefix:t,bitsPerChar:e,alphabet:n}){return ut({prefix:t,name:r,encode(s){return Vs(s,n,e)},decode(s){return $s(s,n,e,r)}})}var Q=v({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Gs=v({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Xs=v({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Qs=v({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),js=v({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Js=v({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Ks=v({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Zs=v({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Ys=v({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var _e={};N(_e,{base58btc:()=>b,base58flickr:()=>ti});var b=X({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),ti=X({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var ei=Dr,Br=128,ri=127,ni=~ri,si=Math.pow(2,31);function Dr(r,t,e){t=t||[],e=e||0;for(var n=e;r>=si;)t[e++]=r&255|Br,r/=128;for(;r∋)t[e++]=r&255|Br,r>>>=7;return t[e]=r|0,Dr.bytes=e-n+1,t}var ii=xe,oi=128,Fr=127;function xe(r,n){var e=0,n=n||0,s=0,i=n,o,a=r.length;do{if(i>=a)throw xe.bytes=0,new RangeError("Could not decode varint");o=r[i++],e+=s<28?(o&Fr)<<s:(o&Fr)*Math.pow(2,s),s+=7}while(o>=oi);return xe.bytes=i-n,e}var ai=Math.pow(2,7),ci=Math.pow(2,14),li=Math.pow(2,21),ui=Math.pow(2,28),hi=Math.pow(2,35),fi=Math.pow(2,42),di=Math.pow(2,49),pi=Math.pow(2,56),gi=Math.pow(2,63),mi=function(r){return r<ai?1:r<ci?2:r<li?3:r<ui?4:r<hi?5:r<fi?6:r<di?7:r<pi?8:r<gi?9:10},bi={encode:ei,decode:ii,encodingLength:mi},yi=bi,kt=yi;function Et(r,t=0){return[kt.decode(r,t),kt.decode.bytes]}function ht(r,t,e=0){return kt.encode(r,t,e),t}function ft(r){return kt.encodingLength(r)}function tt(r,t){let e=t.byteLength,n=ft(r),s=n+ft(e),i=new Uint8Array(s+e);return ht(r,i,0),ht(e,i,n),i.set(t,s),new dt(r,e,t,i)}function Ir(r){let t=V(r),[e,n]=Et(t),[s,i]=Et(t.subarray(n)),o=t.subarray(n+i);if(o.byteLength!==s)throw new Error("Incorrect length");return new dt(e,s,o,t)}function Nr(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&Er(r.bytes,e.bytes)}}var dt=class{code;size;digest;bytes;constructor(t,e,n,s){this.code=t,this.size=e,this.digest=n,this.bytes=s}};function Mr(r,t){let{bytes:e,version:n}=r;switch(n){case 0:return _i(e,ve(r),t??b.encoder);default:return xi(e,ve(r),t??Q.encoder)}}var Rr=new WeakMap;function ve(r){let t=Rr.get(r);if(t==null){let e=new Map;return Rr.set(r,e),e}return t}var T=class r{code;version;multihash;bytes;"/";constructor(t,e,n,s){this.code=e,this.version=t,this.multihash=n,this.bytes=s,this["/"]=s}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:t,multihash:e}=this;if(t!==Tt)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==vi)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(e)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:t,digest:e}=this.multihash,n=tt(t,e);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(t){return r.equals(this,t)}static equals(t,e){let n=e;return n!=null&&t.code===n.code&&t.version===n.version&&Nr(t.multihash,n.multihash)}toString(t){return Mr(this,t)}toJSON(){return{"/":Mr(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(t){if(t==null)return null;let e=t;if(e instanceof r)return e;if(e["/"]!=null&&e["/"]===e.bytes||e.asCID===e){let{version:n,code:s,multihash:i,bytes:o}=e;return new r(n,s,i,o??Pr(n,s,i.bytes))}else if(e[ki]===!0){let{version:n,multihash:s,code:i}=e,o=Ir(s);return r.create(n,i,o)}else return null}static create(t,e,n){if(typeof e!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(t){case 0:{if(e!==Tt)throw new Error(`Version 0 CID must use dag-pb (code: ${Tt}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let s=Pr(t,e,n.bytes);return new r(t,e,n,s)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,Tt,t)}static createV1(t,e){return r.create(1,t,e)}static decode(t){let[e,n]=r.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return e}static decodeFirst(t){let e=r.inspectBytes(t),n=e.size-e.multihashSize,s=V(t.subarray(n,n+e.multihashSize));if(s.byteLength!==e.multihashSize)throw new Error("Incorrect length");let i=s.subarray(e.multihashSize-e.digestSize),o=new dt(e.multihashCode,e.digestSize,i,s);return[e.version===0?r.createV0(o):r.createV1(e.codec,o),t.subarray(e.size)]}static inspectBytes(t){let e=0,n=()=>{let[h,f]=Et(t.subarray(e));return e+=f,h},s=n(),i=Tt;if(s===18?(s=0,e=0):i=n(),s!==0&&s!==1)throw new RangeError(`Invalid CID version ${s}`);let o=e,a=n(),c=n(),l=e+c,u=l-o;return{version:s,codec:i,multihashCode:a,digestSize:c,multihashSize:u,size:l}}static parse(t,e){let[n,s]=wi(t,e),i=r.decode(s);if(i.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return ve(i).set(n,t),i}};function wi(r,t){switch(r[0]){case"Q":{let e=t??b;return[b.prefix,e.decode(`${b.prefix}${r}`)]}case b.prefix:{let e=t??b;return[b.prefix,e.decode(r)]}case Q.prefix:{let e=t??Q;return[Q.prefix,e.decode(r)]}default:{if(t==null)throw Error("To parse non base32 or base58btc encoded CID multibase decoder must be provided");return[r[0],t.decode(r)]}}}function _i(r,t,e){let{prefix:n}=e;if(n!==b.prefix)throw Error(`Cannot string encode V0 in ${e.name} encoding`);let s=t.get(n);if(s==null){let i=e.encode(r).slice(1);return t.set(n,i),i}else return s}function xi(r,t,e){let{prefix:n}=e,s=t.get(n);if(s==null){let i=e.encode(r);return t.set(n,i),i}else return s}var Tt=112,vi=18;function Pr(r,t,e){let n=ft(r),s=n+ft(t),i=new Uint8Array(s+e.byteLength);return ht(r,i,0),ht(t,i,n),i.set(e,s),i}var ki=Symbol.for("@ipld/js-cid/CID");var ke=class extends Map{metric;constructor(t){super();let{name:e,metrics:n}=t;this.metric=n.registerMetric(e),this.updateComponentMetric()}set(t,e){return super.set(t,e),this.updateComponentMetric(),this}delete(t){let e=super.delete(t);return this.updateComponentMetric(),e}clear(){super.clear(),this.updateComponentMetric()}updateComponentMetric(){this.metric.update(this.size)}};function j(r){let{name:t,metrics:e}=r,n;return e!=null?n=new ke({name:t,metrics:e}):n=new Map,n}var pt=class extends Error{code;props;constructor(t,e,n){super(t),this.code=e,this.name=n?.name??"CodeError",this.props=n??{}}};var Te={};N(Te,{sha256:()=>Ct,sha512:()=>Ei});function Se({name:r,code:t,encode:e}){return new Ee(r,t,e)}var Ee=class{name;code;encode;constructor(t,e,n){this.name=t,this.code=e,this.encode=n}digest(t){if(t instanceof Uint8Array){let e=this.encode(t);return e instanceof Uint8Array?tt(this.code,e):e.then(n=>tt(this.code,n))}else throw Error("Unknown type, must be binary type")}};function Or(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var Ct=Se({name:"sha2-256",code:18,encode:Or("SHA-256")}),Ei=Se({name:"sha2-512",code:19,encode:Or("SHA-512")});var Mn=$(Yr(),1);var R=$(sn(),1);var Le={};N(Le,{base64:()=>Ae,base64pad:()=>Ji,base64url:()=>Ki,base64urlpad:()=>Zi});var Ae=v({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Ji=v({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Ki=v({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Zi=v({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});R.default.formatters.b=r=>r==null?"undefined":b.baseEncode(r);R.default.formatters.t=r=>r==null?"undefined":Q.baseEncode(r);R.default.formatters.m=r=>r==null?"undefined":Ae.baseEncode(r);R.default.formatters.p=r=>r==null?"undefined":r.toString();R.default.formatters.c=r=>r==null?"undefined":r.toString();R.default.formatters.k=r=>r==null?"undefined":r.toString();R.default.formatters.a=r=>r==null?"undefined":r.toString();function Yi(r){let t=()=>{};return t.enabled=!1,t.color="",t.diff=0,t.log=()=>{},t.namespace=r,t.destroy=()=>!0,t.extend=()=>t,t}function on(r){let t=Yi(`${r}:trace`);return R.default.enabled(`${r}:trace`)&&R.default.names.map(e=>e.toString()).find(e=>e.includes(":trace"))!=null&&(t=(0,R.default)(`${r}:trace`)),Object.assign((0,R.default)(r),{error:(0,R.default)(`${r}:error`),trace:t})}function Ot(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}var rt=class{_refCounter;cid;priority;wantType;constructor(t,e,n){this._refCounter=1,this.cid=t,this.priority=e??1,this.wantType=n}inc(){this._refCounter+=1}dec(){this._refCounter=Math.max(0,this._refCounter-1)}hasRefs(){return this._refCounter>0}get[Symbol.toStringTag](){return`WantlistEntry <key: ${this.cid.toString(b)}, priority: ${this.priority}, refs: ${this._refCounter}>`}equals(t){return this._refCounter===t._refCounter&&this.cid.equals(t.cid)&&this.priority===t.priority&&this.wantType===t.wantType}};var J=class{entry;cancel;sendDontHave;constructor(t,e,n,s,i){this.entry=new rt(t,e,n),this.cancel=!!s,this.sendDontHave=!!i}get cid(){return this.entry.cid}set cid(t){this.entry.cid=t}get priority(){return this.entry.priority}set priority(t){this.entry.priority=t}get wantType(){return this.entry.wantType}set wantType(t){this.entry.wantType=t}get[Symbol.toStringTag](){return`BitswapMessageEntry ${this.cid.toString(b)} <cancel: ${this.cancel}, priority: ${this.priority}>`}equals(t){return this.cancel===t.cancel&&this.sendDontHave===t.sendDontHave&&this.wantType===t.wantType&&this.entry.equals(t.entry)}};var z=(r,t)=>{let e=["bitswap"];return t!=null&&e.push(t),r!=null&&e.push(`${r.toString().slice(0,8)}`),on(e.join(":"))};var zt=(r,t)=>{if(r.size!==t.size)return!1;for(let[e,n]of r){let s=t.get(e);if(s===void 0||n instanceof Uint8Array&&s instanceof Uint8Array&&!Ot(n,s)||n instanceof J&&s instanceof J&&!n.equals(s))return!1}return!0};var At=$(mn(),1);function po(r){let t=new Uint8Array(r.reduce((n,s)=>n+At.default.encodingLength(s),0)),e=0;for(let n of r)t=At.encode(n,t,e),e+=At.default.encodingLength(n);return t}var bn=po;function K(r){return globalThis.Buffer!=null?new Uint8Array(r.buffer,r.byteOffset,r.byteLength):r}function G(r=0){return globalThis.Buffer?.alloc!=null?K(globalThis.Buffer.alloc(r)):new Uint8Array(r)}function C(r=0){return globalThis.Buffer?.allocUnsafe!=null?K(globalThis.Buffer.allocUnsafe(r)):new Uint8Array(r)}var go=Math.pow(2,7),mo=Math.pow(2,14),bo=Math.pow(2,21),De=Math.pow(2,28),Ie=Math.pow(2,35),Ne=Math.pow(2,42),Me=Math.pow(2,49),y=128,A=127;function H(r){if(r<go)return 1;if(r<mo)return 2;if(r<bo)return 3;if(r<De)return 4;if(r<Ie)return 5;if(r<Ne)return 6;if(r<Me)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Re(r,t,e=0){switch(H(r)){case 8:t[e++]=r&255|y,r/=128;case 7:t[e++]=r&255|y,r/=128;case 6:t[e++]=r&255|y,r/=128;case 5:t[e++]=r&255|y,r/=128;case 4:t[e++]=r&255|y,r>>>=7;case 3:t[e++]=r&255|y,r>>>=7;case 2:t[e++]=r&255|y,r>>>=7;case 1:{t[e++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return t}function yo(r,t,e=0){switch(H(r)){case 8:t.set(e++,r&255|y),r/=128;case 7:t.set(e++,r&255|y),r/=128;case 6:t.set(e++,r&255|y),r/=128;case 5:t.set(e++,r&255|y),r/=128;case 4:t.set(e++,r&255|y),r>>>=7;case 3:t.set(e++,r&255|y),r>>>=7;case 2:t.set(e++,r&255|y),r>>>=7;case 1:{t.set(e++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return t}function Pe(r,t){let e=r[t],n=0;if(n+=e&A,e<y||(e=r[t+1],n+=(e&A)<<7,e<y)||(e=r[t+2],n+=(e&A)<<14,e<y)||(e=r[t+3],n+=(e&A)<<21,e<y)||(e=r[t+4],n+=(e&A)*De,e<y)||(e=r[t+5],n+=(e&A)*Ie,e<y)||(e=r[t+6],n+=(e&A)*Ne,e<y)||(e=r[t+7],n+=(e&A)*Me,e<y))return n;throw new RangeError("Could not decode varint")}function wo(r,t){let e=r.get(t),n=0;if(n+=e&A,e<y||(e=r.get(t+1),n+=(e&A)<<7,e<y)||(e=r.get(t+2),n+=(e&A)<<14,e<y)||(e=r.get(t+3),n+=(e&A)<<21,e<y)||(e=r.get(t+4),n+=(e&A)*De,e<y)||(e=r.get(t+5),n+=(e&A)*Ie,e<y)||(e=r.get(t+6),n+=(e&A)*Ne,e<y)||(e=r.get(t+7),n+=(e&A)*Me,e<y))return n;throw new RangeError("Could not decode varint")}function yn(r,t,e=0){return t==null&&(t=C(H(r))),t instanceof Uint8Array?Re(r,t,e):yo(r,t,e)}function wn(r,t=0){return r instanceof Uint8Array?Pe(r,t):wo(r,t)}var Ue=new Float32Array([-0]),Z=new Uint8Array(Ue.buffer);function xn(r,t,e){Ue[0]=r,t[e]=Z[0],t[e+1]=Z[1],t[e+2]=Z[2],t[e+3]=Z[3]}function vn(r,t){return Z[0]=r[t],Z[1]=r[t+1],Z[2]=r[t+2],Z[3]=r[t+3],Ue[0]}var Oe=new Float64Array([-0]),L=new Uint8Array(Oe.buffer);function kn(r,t,e){Oe[0]=r,t[e]=L[0],t[e+1]=L[1],t[e+2]=L[2],t[e+3]=L[3],t[e+4]=L[4],t[e+5]=L[5],t[e+6]=L[6],t[e+7]=L[7]}function En(r,t){return L[0]=r[t],L[1]=r[t+1],L[2]=r[t+2],L[3]=r[t+3],L[4]=r[t+4],L[5]=r[t+5],L[6]=r[t+6],L[7]=r[t+7],Oe[0]}var _o=BigInt(Number.MAX_SAFE_INTEGER),xo=BigInt(Number.MIN_SAFE_INTEGER),P=class r{lo;hi;constructor(t,e){this.lo=t|0,this.hi=e|0}toNumber(t=!1){if(!t&&this.hi>>>31>0){let e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(e+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(t=!1){if(t)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(BigInt(e)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(t=!1){return this.toBigInt(t).toString()}zzEncode(){let t=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^t)>>>0,this.lo=(this.lo<<1^t)>>>0,this}zzDecode(){let t=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^t)>>>0,this.hi=(this.hi>>>1^t)>>>0,this}length(){let t=this.lo,e=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?e===0?t<16384?t<128?1:2:t<2097152?3:4:e<16384?e<128?5:6:e<2097152?7:8:n<128?9:10}static fromBigInt(t){if(t===0n)return nt;if(t<_o&&t>xo)return this.fromNumber(Number(t));let e=t<0n;e&&(t=-t);let n=t>>32n,s=t-(n<<32n);return e&&(n=~n|0n,s=~s|0n,++s>Sn&&(s=0n,++n>Sn&&(n=0n))),new r(Number(s),Number(n))}static fromNumber(t){if(t===0)return nt;let e=t<0;e&&(t=-t);let n=t>>>0,s=(t-n)/4294967296>>>0;return e&&(s=~s>>>0,n=~n>>>0,++n>4294967295&&(n=0,++s>4294967295&&(s=0))),new r(n,s)}static from(t){return typeof t=="number"?r.fromNumber(t):typeof t=="bigint"?r.fromBigInt(t):typeof t=="string"?r.fromBigInt(BigInt(t)):t.low!=null||t.high!=null?new r(t.low>>>0,t.high>>>0):nt}},nt=new P(0,0);nt.toBigInt=function(){return 0n};nt.zzEncode=nt.zzDecode=function(){return this};nt.length=function(){return 1};var Sn=4294967296n;function Tn(r){let t=0,e=0;for(let n=0;n<r.length;++n)e=r.charCodeAt(n),e<128?t+=1:e<2048?t+=2:(e&64512)===55296&&(r.charCodeAt(n+1)&64512)===56320?(++n,t+=4):t+=3;return t}function Cn(r,t,e){if(e-t<1)return"";let s,i=[],o=0,a;for(;t<e;)a=r[t++],a<128?i[o++]=a:a>191&&a<224?i[o++]=(a&31)<<6|r[t++]&63:a>239&&a<365?(a=((a&7)<<18|(r[t++]&63)<<12|(r[t++]&63)<<6|r[t++]&63)-65536,i[o++]=55296+(a>>10),i[o++]=56320+(a&1023)):i[o++]=(a&15)<<12|(r[t++]&63)<<6|r[t++]&63,o>8191&&((s??(s=[])).push(String.fromCharCode.apply(String,i)),o=0);return s!=null?(o>0&&s.push(String.fromCharCode.apply(String,i.slice(0,o))),s.join("")):String.fromCharCode.apply(String,i.slice(0,o))}function ze(r,t,e){let n=e,s,i;for(let o=0;o<r.length;++o)s=r.charCodeAt(o),s<128?t[e++]=s:s<2048?(t[e++]=s>>6|192,t[e++]=s&63|128):(s&64512)===55296&&((i=r.charCodeAt(o+1))&64512)===56320?(s=65536+((s&1023)<<10)+(i&1023),++o,t[e++]=s>>18|240,t[e++]=s>>12&63|128,t[e++]=s>>6&63|128,t[e++]=s&63|128):(t[e++]=s>>12|224,t[e++]=s>>6&63|128,t[e++]=s&63|128);return e-n}function W(r,t){return RangeError(`index out of range: ${r.pos} + ${t??1} > ${r.len}`)}function Ht(r,t){return(r[t-4]|r[t-3]<<8|r[t-2]<<16|r[t-1]<<24)>>>0}var He=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(t){this.buf=t,this.pos=0,this.len=t.length}uint32(){let t=4294967295;if(t=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(t=(t|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return t;if((this.pos+=5)>this.len)throw this.pos=this.len,W(this,10);return t}int32(){return this.uint32()|0}sint32(){let t=this.uint32();return t>>>1^-(t&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw W(this,4);return Ht(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw W(this,4);return Ht(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw W(this,4);let t=vn(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw W(this,4);let t=En(this.buf,this.pos);return this.pos+=8,t}bytes(){let t=this.uint32(),e=this.pos,n=this.pos+t;if(n>this.len)throw W(this,t);return this.pos+=t,e===n?new Uint8Array(0):this.buf.subarray(e,n)}string(){let t=this.bytes();return Cn(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw W(this,t);this.pos+=t}else do if(this.pos>=this.len)throw W(this);while(this.buf[this.pos++]&128);return this}skipType(t){switch(t){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(t=this.uint32()&7)!==4;)this.skipType(t);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${t} at offset ${this.pos}`)}return this}readLongVarint(){let t=new P(0,0),e=0;if(this.len-this.pos>4){for(;e<4;++e)if(t.lo=(t.lo|(this.buf[this.pos]&127)<<e*7)>>>0,this.buf[this.pos++]<128)return t;if(t.lo=(t.lo|(this.buf[this.pos]&127)<<28)>>>0,t.hi=(t.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return t;e=0}else{for(;e<3;++e){if(this.pos>=this.len)throw W(this);if(t.lo=(t.lo|(this.buf[this.pos]&127)<<e*7)>>>0,this.buf[this.pos++]<128)return t}return t.lo=(t.lo|(this.buf[this.pos++]&127)<<e*7)>>>0,t}if(this.len-this.pos>4){for(;e<5;++e)if(t.hi=(t.hi|(this.buf[this.pos]&127)<<e*7+3)>>>0,this.buf[this.pos++]<128)return t}else for(;e<5;++e){if(this.pos>=this.len)throw W(this);if(t.hi=(t.hi|(this.buf[this.pos]&127)<<e*7+3)>>>0,this.buf[this.pos++]<128)return t}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw W(this,8);let t=Ht(this.buf,this.pos+=4),e=Ht(this.buf,this.pos+=4);return new P(t,e)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let t=Pe(this.buf,this.pos);return this.pos+=H(t),t}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function We(r){return new He(r instanceof Uint8Array?r:r.subarray())}function st(r,t,e){let n=We(r);return t.decode(n,void 0,e)}var qe={};N(qe,{base10:()=>vo});var vo=X({prefix:"9",name:"base10",alphabet:"0123456789"});var $e={};N($e,{base16:()=>ko,base16upper:()=>Eo});var ko=v({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Eo=v({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Ve={};N(Ve,{base2:()=>So});var So=v({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Ge={};N(Ge,{base256emoji:()=>Bo});var Ln=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}"),To=Ln.reduce((r,t,e)=>(r[e]=t,r),[]),Co=Ln.reduce((r,t,e)=>(r[t.codePointAt(0)]=e,r),[]);function Ao(r){return r.reduce((t,e)=>(t+=To[e],t),"")}function Lo(r){let t=[];for(let e of r){let n=Co[e.codePointAt(0)];if(n===void 0)throw new Error(`Non-base256emoji character: ${e}`);t.push(n)}return new Uint8Array(t)}var Bo=ut({prefix:"\u{1F680}",name:"base256emoji",encode:Ao,decode:Lo});var Xe={};N(Xe,{base36:()=>Fo,base36upper:()=>Do});var Fo=X({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Do=X({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Qe={};N(Qe,{base8:()=>Io});var Io=v({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var je={};N(je,{identity:()=>No});var No=ut({prefix:"\0",name:"identity",encode:r=>Tr(r),decode:r=>Sr(r)});var Vc=new TextEncoder,Gc=new TextDecoder;var Je={};N(Je,{identity:()=>Oo});var Bn=0,Po="identity",Fn=V;function Uo(r){return tt(Bn,Fn(r))}var Oo={code:Bn,name:Po,encode:Fn,digest:Uo};var Ke={...je,...Ve,...Qe,...qe,...$e,...we,...Xe,..._e,...Le,...Ge},sl={...Te,...Je};function In(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var Dn=In("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Ze=In("ascii","a",r=>{let t="a";for(let e=0;e<r.length;e++)t+=String.fromCharCode(r[e]);return t},r=>{r=r.substring(1);let t=C(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),zo={utf8:Dn,"utf-8":Dn,hex:Ke.base16,latin1:Ze,ascii:Ze,binary:Ze,...Ke},Wt=zo;function Nn(r,t="utf8"){let e=Wt[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return(t==="utf8"||t==="utf-8")&&globalThis.Buffer!=null&&globalThis.Buffer.from!=null?K(globalThis.Buffer.from(r,"utf-8")):e.decoder.decode(`${e.prefix}${r}`)}function Ye(r){let t=r??8192,e=t>>>1,n,s=t;return function(o){if(o<1||o>e)return C(o);s+o>t&&(n=C(t),s=0);let a=n.subarray(s,s+=o);return s&7&&(s=(s|7)+1),a}}var it=class{fn;len;next;val;constructor(t,e,n){this.fn=t,this.len=e,this.next=void 0,this.val=n}};function tr(){}var rr=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},Ho=Ye();function Wo(r){return globalThis.Buffer!=null?C(r):Ho(r)}var Bt=class{len;head;tail;states;constructor(){this.len=0,this.head=new it(tr,0,0),this.tail=this.head,this.states=null}_push(t,e,n){return this.tail=this.tail.next=new it(t,e,n),this.len+=e,this}uint32(t){return this.len+=(this.tail=this.tail.next=new nr((t=t>>>0)<128?1:t<16384?2:t<2097152?3:t<268435456?4:5,t)).len,this}int32(t){return t<0?this._push(qt,10,P.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let e=P.fromBigInt(t);return this._push(qt,e.length(),e)}uint64Number(t){return this._push(Re,H(t),t)}uint64String(t){return this.uint64(BigInt(t))}int64(t){return this.uint64(t)}int64Number(t){return this.uint64Number(t)}int64String(t){return this.uint64String(t)}sint64(t){let e=P.fromBigInt(t).zzEncode();return this._push(qt,e.length(),e)}sint64Number(t){let e=P.fromNumber(t).zzEncode();return this._push(qt,e.length(),e)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(er,1,t?1:0)}fixed32(t){return this._push(Lt,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=P.fromBigInt(t);return this._push(Lt,4,e.lo)._push(Lt,4,e.hi)}fixed64Number(t){let e=P.fromNumber(t);return this._push(Lt,4,e.lo)._push(Lt,4,e.hi)}fixed64String(t){return this.fixed64(BigInt(t))}sfixed64(t){return this.fixed64(t)}sfixed64Number(t){return this.fixed64Number(t)}sfixed64String(t){return this.fixed64String(t)}float(t){return this._push(xn,4,t)}double(t){return this._push(kn,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(er,1,0):this.uint32(e)._push($o,e,t)}string(t){let e=Tn(t);return e!==0?this.uint32(e)._push(ze,e,t):this._push(er,1,0)}fork(){return this.states=new rr(this),this.head=this.tail=new it(tr,0,0),this.len=0,this}reset(){return this.states!=null?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new it(tr,0,0),this.len=0),this}ldelim(){let t=this.head,e=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=t.next,this.tail=e,this.len+=n),this}finish(){let t=this.head.next,e=Wo(this.len),n=0;for(;t!=null;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e}};function er(r,t,e){t[e]=r&255}function qo(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var nr=class extends it{next;constructor(t,e){super(qo,t,e),this.next=void 0}};function qt(r,t,e){for(;r.hi!==0;)t[e++]=r.lo&127|128,r.lo=(r.lo>>>7|r.hi<<25)>>>0,r.hi>>>=7;for(;r.lo>127;)t[e++]=r.lo&127|128,r.lo=r.lo>>>7;t[e++]=r.lo}function Lt(r,t,e){t[e]=r&255,t[e+1]=r>>>8&255,t[e+2]=r>>>16&255,t[e+3]=r>>>24}function $o(r,t,e){t.set(r,e)}globalThis.Buffer!=null&&(Bt.prototype.bytes=function(r){let t=r.length>>>0;return this.uint32(t),t>0&&this._push(Vo,t,r),this},Bt.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(Go,t,r),this});function Vo(r,t,e){t.set(r,e)}function Go(r,t,e){r.length<40?ze(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set(Nn(r),e)}function sr(){return new Bt}function ot(r,t){let e=sr();return t.encode(r,e,{lengthDelimited:!1}),e.finish()}var yt;(function(r){r[r.VARINT=0]="VARINT",r[r.BIT64=1]="BIT64",r[r.LENGTH_DELIMITED=2]="LENGTH_DELIMITED",r[r.START_GROUP=3]="START_GROUP",r[r.END_GROUP=4]="END_GROUP",r[r.BIT32=5]="BIT32"})(yt||(yt={}));function $t(r,t,e,n){return{name:r,type:t,encode:e,decode:n}}function Vt(r){function t(s){if(r[s.toString()]==null)throw new Error("Invalid enum value");return r[s]}let e=function(i,o){let a=t(i);o.int32(a)},n=function(i){let o=i.int32();return t(o)};return $t("enum",yt.VARINT,e,n)}function at(r,t){return $t("message",yt.LENGTH_DELIMITED,r,t)}var F;(function(r){let t;(function(a){let c;(function(f){f.Block="Block",f.Have="Have"})(c=a.WantType||(a.WantType={}));let l;(function(f){f[f.Block=0]="Block",f[f.Have=1]="Have"})(l||(l={})),function(f){f.codec=()=>Vt(l)}(c=a.WantType||(a.WantType={}));let u;(function(f){let m;f.codec=()=>(m==null&&(m=at((d,g,p={})=>{p.lengthDelimited!==!1&&g.fork(),d.block!=null&&d.block.byteLength>0&&(g.uint32(10),g.bytes(d.block)),d.priority!=null&&d.priority!==0&&(g.uint32(16),g.int32(d.priority)),d.cancel!=null&&d.cancel!==!1&&(g.uint32(24),g.bool(d.cancel)),d.wantType!=null&&l[d.wantType]!==0&&(g.uint32(32),r.Wantlist.WantType.codec().encode(d.wantType,g)),d.sendDontHave!=null&&d.sendDontHave!==!1&&(g.uint32(40),g.bool(d.sendDontHave)),p.lengthDelimited!==!1&&g.ldelim()},(d,g)=>{let p={block:new Uint8Array(0),priority:0,cancel:!1,wantType:c.Block,sendDontHave:!1},w=g==null?d.len:d.pos+g;for(;d.pos<w;){let x=d.uint32();switch(x>>>3){case 1:p.block=d.bytes();break;case 2:p.priority=d.int32();break;case 3:p.cancel=d.bool();break;case 4:p.wantType=r.Wantlist.WantType.codec().decode(d);break;case 5:p.sendDontHave=d.bool();break;default:d.skipType(x&7);break}}return p})),m),f.encode=d=>ot(d,f.codec()),f.decode=d=>st(d,f.codec())})(u=a.Entry||(a.Entry={}));let h;a.codec=()=>(h==null&&(h=at((f,m,d={})=>{if(d.lengthDelimited!==!1&&m.fork(),f.entries!=null)for(let g of f.entries)m.uint32(10),r.Wantlist.Entry.codec().encode(g,m);f.full!=null&&f.full!==!1&&(m.uint32(16),m.bool(f.full)),d.lengthDelimited!==!1&&m.ldelim()},(f,m)=>{let d={entries:[],full:!1},g=m==null?f.len:f.pos+m;for(;f.pos<g;){let p=f.uint32();switch(p>>>3){case 1:d.entries.push(r.Wantlist.Entry.codec().decode(f,f.uint32()));break;case 2:d.full=f.bool();break;default:f.skipType(p&7);break}}return d})),h),a.encode=f=>ot(f,a.codec()),a.decode=f=>st(f,a.codec())})(t=r.Wantlist||(r.Wantlist={}));let e;(function(a){let c;a.codec=()=>(c==null&&(c=at((l,u,h={})=>{h.lengthDelimited!==!1&&u.fork(),l.prefix!=null&&l.prefix.byteLength>0&&(u.uint32(10),u.bytes(l.prefix)),l.data!=null&&l.data.byteLength>0&&(u.uint32(18),u.bytes(l.data)),h.lengthDelimited!==!1&&u.ldelim()},(l,u)=>{let h={prefix:new Uint8Array(0),data:new Uint8Array(0)},f=u==null?l.len:l.pos+u;for(;l.pos<f;){let m=l.uint32();switch(m>>>3){case 1:h.prefix=l.bytes();break;case 2:h.data=l.bytes();break;default:l.skipType(m&7);break}}return h})),c),a.encode=l=>ot(l,a.codec()),a.decode=l=>st(l,a.codec())})(e=r.Block||(r.Block={}));let n;(function(a){a.Have="Have",a.DontHave="DontHave"})(n=r.BlockPresenceType||(r.BlockPresenceType={}));let s;(function(a){a[a.Have=0]="Have",a[a.DontHave=1]="DontHave"})(s||(s={})),function(a){a.codec=()=>Vt(s)}(n=r.BlockPresenceType||(r.BlockPresenceType={}));let i;(function(a){let c;a.codec=()=>(c==null&&(c=at((l,u,h={})=>{h.lengthDelimited!==!1&&u.fork(),l.cid!=null&&l.cid.byteLength>0&&(u.uint32(10),u.bytes(l.cid)),l.type!=null&&s[l.type]!==0&&(u.uint32(16),r.BlockPresenceType.codec().encode(l.type,u)),h.lengthDelimited!==!1&&u.ldelim()},(l,u)=>{let h={cid:new Uint8Array(0),type:n.Have},f=u==null?l.len:l.pos+u;for(;l.pos<f;){let m=l.uint32();switch(m>>>3){case 1:h.cid=l.bytes();break;case 2:h.type=r.BlockPresenceType.codec().decode(l);break;default:l.skipType(m&7);break}}return h})),c),a.encode=l=>ot(l,a.codec()),a.decode=l=>st(l,a.codec())})(i=r.BlockPresence||(r.BlockPresence={}));let o;r.codec=()=>(o==null&&(o=at((a,c,l={})=>{if(l.lengthDelimited!==!1&&c.fork(),a.wantlist!=null&&(c.uint32(10),r.Wantlist.codec().encode(a.wantlist,c)),a.blocks!=null)for(let u of a.blocks)c.uint32(18),c.bytes(u);if(a.payload!=null)for(let u of a.payload)c.uint32(26),r.Block.codec().encode(u,c);if(a.blockPresences!=null)for(let u of a.blockPresences)c.uint32(34),r.BlockPresence.codec().encode(u,c);a.pendingBytes!=null&&a.pendingBytes!==0&&(c.uint32(40),c.int32(a.pendingBytes)),l.lengthDelimited!==!1&&c.ldelim()},(a,c)=>{let l={blocks:[],payload:[],blockPresences:[],pendingBytes:0},u=c==null?a.len:a.pos+c;for(;a.pos<u;){let h=a.uint32();switch(h>>>3){case 1:l.wantlist=r.Wantlist.codec().decode(a,a.uint32());break;case 2:l.blocks.push(a.bytes());break;case 3:l.payload.push(r.Block.codec().decode(a,a.uint32()));break;case 4:l.blockPresences.push(r.BlockPresence.codec().decode(a,a.uint32()));break;case 5:l.pendingBytes=a.int32();break;default:a.skipType(h&7);break}}return l})),o),r.encode=a=>ot(a,r.codec()),r.decode=a=>st(a,r.codec())})(F||(F={}));var B=class r{static Entry=J;static WantType={Block:F.Wantlist.WantType.Block,Have:F.Wantlist.WantType.Have};static BlockPresenceType={Have:F.BlockPresenceType.Have,DontHave:F.BlockPresenceType.DontHave};static deserialize=async(t,e)=>{let n=F.decode(t),s=n.wantlist?.full===!0,i=new r(s);return n.wantlist?.entries.forEach(o=>{if(o.block==null)return;let a=T.decode(o.block);i.addEntry(a,o.priority??0,o.wantType,!!o.cancel,!!o.sendDontHave)}),n.blockPresences.forEach(o=>{if(o.cid==null)return;let a=T.decode(o.cid);o.type===r.BlockPresenceType.Have?i.addHave(a):i.addDontHave(a)}),n.blocks.length>0?(await Promise.all(n.blocks.map(async o=>{let a=await Ct.digest(o),c=T.createV0(a);i.addBlock(c,o)})),i):(n.payload.length>0&&(await Promise.all(n.payload.map(async o=>{if(o.prefix==null||o.data==null)return;let a=(0,Mn.default)(o.prefix),c=a[0],l=a[1],u=a[2],h=u===Ct.code?Ct:await e?.getHasher(u);if(h==null)throw new pt("Unknown hash algorithm","ERR_UNKNOWN_HASH_ALG");let f=await h.digest(o.data),m=T.create(c,l,f);i.addBlock(m,o.data)})),i.setPendingBytes(n.pendingBytes)),i)};static blockPresenceSize=t=>t.bytes.length+1;full;wantlist;blocks;blockPresences;pendingBytes;constructor(t){this.full=t,this.wantlist=new Map,this.blocks=new Map,this.blockPresences=new Map,this.pendingBytes=0}get empty(){return this.blocks.size===0&&this.wantlist.size===0&&this.blockPresences.size===0}addEntry(t,e,n,s,i){n==null&&(n=r.WantType.Block);let o=t.toString(b),a=this.wantlist.get(o);a!=null?(a.wantType===n&&(a.priority=e),s===!0&&(a.cancel=!!s),i===!0&&(a.sendDontHave=!!i),n===r.WantType.Block&&a.wantType===r.WantType.Have&&(a.wantType=n)):this.wantlist.set(o,new J(t,e,n,s,i))}addBlock(t,e){let n=t.toString(b);this.blocks.set(n,e)}addHave(t){let e=t.toString(b);this.blockPresences.has(e)||this.blockPresences.set(e,r.BlockPresenceType.Have)}addDontHave(t){let e=t.toString(b);this.blockPresences.has(e)||this.blockPresences.set(e,r.BlockPresenceType.DontHave)}cancel(t){let e=t.toString(b);this.wantlist.delete(e),this.addEntry(t,0,r.WantType.Block,!0,!1)}setPendingBytes(t){this.pendingBytes=t}serializeToBitswap100(){return F.encode({wantlist:{entries:Array.from(this.wantlist.values()).map(t=>({block:t.cid.bytes,priority:Number(t.priority),cancel:!!t.cancel,wantType:F.Wantlist.WantType.Block,sendDontHave:!1})),full:!!this.full},blocks:Array.from(this.blocks.values())})}serializeToBitswap110(){let t={wantlist:{entries:Array.from(this.wantlist.values()).map(e=>({block:e.cid.bytes,priority:Number(e.priority),wantType:e.wantType,cancel:!!e.cancel,sendDontHave:!!e.sendDontHave})),full:!!this.full},blockPresences:[],payload:[],pendingBytes:this.pendingBytes,blocks:[]};for(let[e,n]of this.blocks.entries()){let s=T.parse(e),i=s.version,o=s.code,a=s.multihash.code,c=s.multihash.digest.length,l=bn([i,o,a,c]);t.payload.push({prefix:l,data:n})}for(let[e,n]of this.blockPresences)t.blockPresences.push({cid:T.parse(e).bytes,type:n});return this.pendingBytes>0&&(t.pendingBytes=this.pendingBytes),F.encode(t)}equals(t){return!(this.full!==t.full||this.pendingBytes!==t.pendingBytes||!zt(this.wantlist,t.wantlist)||!zt(this.blocks,t.blocks)||!zt(this.blockPresences,t.blockPresences))}get[Symbol.toStringTag](){let t=Array.from(this.wantlist.keys()),e=Array.from(this.blocks.keys());return`BitswapMessage <full: ${this.full}, list: ${t}, blocks: ${e}>`}};var Rn={Block:F.Wantlist.WantType.Block,Have:F.Wantlist.WantType.Have},Xo=(r,t)=>Array.prototype.slice.call(t,0).sort((e,n)=>{let s=r(e),i=r(n);return s<i?-1:s>i?1:0}),Y=class{static Entry=rt;set;_stats;constructor(t,e){this.set=e!=null?j({name:"ipfs_bitswap_wantlist",metrics:e.metrics}):new Map,this._stats=t}get length(){return this.set.size}add(t,e,n){let s=t.toString(b),i=this.set.get(s);i!=null?(i.inc(),i.priority=e,i.wantType===Rn.Have&&n===Rn.Block&&(i.wantType=n)):(this.set.set(s,new rt(t,e,n)),this._stats!=null&&this._stats.push(void 0,"wantListSize",1))}remove(t){let e=t.toString(b),n=this.set.get(e);n!=null&&(n.dec(),!n.hasRefs()&&(this.set.delete(e),this._stats!=null&&this._stats.push(void 0,"wantListSize",-1)))}removeForce(t){this.set.has(t)&&this.set.delete(t)}forEach(t){this.set.forEach(t)}entries(){return this.set.entries()}sortedEntries(){return new Map(Xo(t=>t[1].key,Array.from(this.set.entries())))}contains(t){let e=t.toString(b);return this.set.has(e)}get(t){let e=t.toString(b);return this.set.get(e)}};var Gt=class{partner;wantlist;exchangeCount;accounting;lastExchange;constructor(t){this.partner=t,this.wantlist=new Y,this.exchangeCount=0,this.accounting={bytesSent:0,bytesRecv:0}}sentBytes(t){this.exchangeCount++,this.lastExchange=new Date().getTime(),this.accounting.bytesSent+=t}receivedBytes(t){this.exchangeCount++,this.lastExchange=new Date().getTime(),this.accounting.bytesRecv+=t}wants(t,e,n){this.wantlist.add(t,e,n)}cancelWant(t){this.wantlist.remove(t)}wantlistContains(t){return this.wantlist.get(t)}debtRatio(){return this.accounting.bytesSent/(this.accounting.bytesRecv+1)}};var Ft=class extends Map{_cmp;_keys;constructor(t,e){super(),this._cmp=e??this._defaultSort,this._keys=[];for(let[n,s]of t??[])this.set(n,s)}update(t){if(t<0||t>=this._keys.length)return;let e=this._keys[t];this._keys.splice(t,1);let n=this._find(e);this._keys.splice(n,0,e)}set(t,e){if(this.has(t)){let s=this.indexOf(t);this._keys.splice(s,1)}super.set(t,e);let n=this._find(t);return this._keys.splice(n,0,t),this}clear(){super.clear(),this._keys=[]}delete(t){if(!this.has(t))return!1;let e=this.indexOf(t);return this._keys.splice(e,1),super.delete(t)}indexOf(t){if(!this.has(t))return-1;let e=this._find(t);if(this._keys[e]===t)return e;for(let n=1;n<this._keys.length;n++){if(this._keys[e+n]===t)return e+n;if(this._keys[e-n]===t)return e-n}return-1}_find(t){let e=0,n=this._keys.length;for(;e<n;){let s=e+n>>>1,i=this._kCmp(this._keys[s],t);if(i<0)e=s+1;else if(i>0)n=s;else return s}return e}*keys(){for(let t of this._keys)yield t}*values(){for(let t of this._keys)yield this.get(t)}*entries(){for(let t of this._keys)yield[t,this.get(t)]}*[Symbol.iterator](){yield*this.entries()}forEach(t,e=this){if(t!=null)for(let n of this._keys){let s=this.get(n);if(s==null)throw new Error("Value cannot be undefined");t.apply(e,[[n,s]])}}_defaultSort(t,e){return t[0]<e[0]?-1:e[0]<t[0]?1:0}_kCmp(t,e){return this._cmp([t,this.get(t)],[e,this.get(e)])}};var Qo={hasNewInfo(){return!1},merge(){}},Xt=class{_taskMerger;_byPeer;constructor(t=Qo){this._taskMerger=t,this._byPeer=new Ft([],Qt.compare)}pushTasks(t,e){let n=this._byPeer.get(t.toString());n==null&&(n=new Qt(t,this._taskMerger)),n.pushTasks(e),this._byPeer.set(t.toString(),n)}popTasks(t){let e=this._head();if(e===void 0)return{tasks:[],pendingSize:0};let{tasks:n,pendingSize:s}=e.popTasks(t);if(n.length===0)return{tasks:n,pendingSize:s};let i=e.peerId;return e.isIdle()?this._byPeer.delete(i.toString()):this._byPeer.update(0),{peerId:i,tasks:n,pendingSize:s}}_head(){if(this._byPeer.size!==0)for(let[,t]of this._byPeer)return t}remove(t,e){this._byPeer.get(e.toString())?.remove(t)}tasksDone(t,e){let n=this._byPeer.get(t.toString());if(n==null)return;let s=this._byPeer.indexOf(t.toString());for(let i of e)n.taskDone(i);this._byPeer.update(s)}},Qt=class{peerId;_taskMerger;_activeTotalSize;_pending;_active;constructor(t,e){this.peerId=t,this._taskMerger=e,this._activeTotalSize=0,this._pending=new ir,this._active=new Set}pushTasks(t){for(let e of t)this._pushTask(e)}_pushTask(t){if(!this._taskHasMoreInfoThanActiveTasks(t))return;let e=this._pending.get(t.topic);if(e!=null){t.priority>e.priority&&this._pending.updatePriority(t.topic,t.priority),this._taskMerger.merge(t,e);return}this._pending.add(t)}_taskHasMoreInfoThanActiveTasks(t){let e=[];for(let n of this._active)n.topic===t.topic&&e.push(n);return e.length===0?!0:this._taskMerger.hasNewInfo(t,e)}popTasks(t){let e=0,n=[],s=this._pending.tasks();for(let i=0;i<s.length&&e<t;i++){let o=s[i];n.push(o),e+=o.size,this._pending.delete(o.topic),this._activeTotalSize+=o.size,this._active.add(o)}return{tasks:n,pendingSize:this._pending.totalSize}}taskDone(t){this._active.has(t)&&(this._activeTotalSize-=t.size,this._active.delete(t))}remove(t){this._pending.delete(t)}isIdle(){return this._pending.length===0&&this._active.size===0}static compare(t,e){return t[1]._pending.length===0?1:e[1]._pending.length===0?-1:t[1]._activeTotalSize===e[1]._activeTotalSize?e[1]._pending.length-t[1]._pending.length:t[1]._activeTotalSize-e[1]._activeTotalSize}},ir=class{_tasks;constructor(){this._tasks=new Ft([],this._compare)}get length(){return this._tasks.size}get totalSize(){return[...this._tasks.values()].reduce((t,e)=>t+e.task.size,0)}get(t){return this._tasks?.get(t)?.task}add(t){this._tasks.set(t.topic,{created:Date.now(),task:t})}delete(t){this._tasks.delete(t)}tasks(){return[...this._tasks.values()].map(t=>t.task)}updatePriority(t,e){let n=this._tasks.get(t);if(n==null)return;let s=this._tasks.indexOf(t);n.task.priority=e,this._tasks.update(s)}_compare(t,e){return t[1].task.priority===e[1].task.priority?t[1].created-e[1].created:e[1].task.priority-t[1].task.priority}};var Pn={hasNewInfo(r,t){let e=!1,n=!1;for(let s of t)s.data.haveBlock&&(e=!0),s.data.isWantBlock&&(n=!0);return!!(!n&&r.data.isWantBlock||!e&&r.data.haveBlock)},merge(r,t){let e=r.data,n=t.data;!n.haveBlock&&e.haveBlock&&(n.haveBlock=e.haveBlock,n.blockSize=e.blockSize),!n.isWantBlock&&e.isWantBlock&&(n.isWantBlock=!0,(!n.haveBlock||e.haveBlock)&&(n.haveBlock=e.haveBlock,t.size=r.size)),n.isWantBlock&&n.haveBlock&&(t.size=n.blockSize)}};var Un=B.WantType,jo=16*1024,Jo=1024,jt=class{_log;blockstore;network;_stats;_opts;ledgerMap;_running;_requestQueue;constructor(t,e,n,s,i,o={}){this._log=z(t,"engine"),this.blockstore=e,this.network=n,this._stats=s,this._opts=this._processOpts(o),this.ledgerMap=j({name:"ipfs_bitswap_ledger_map",metrics:i.metrics}),this._running=!1,this._requestQueue=new Xt(Pn)}_processOpts(t){return{maxSizeReplaceHasWithBlock:Jo,targetMessageSize:jo,...t}}_scheduleProcessTasks(){setTimeout(()=>{this._processTasks().catch(t=>{this._log.error("error processing stats",t)})})}async _processTasks(){if(!this._running)return;let{peerId:t,tasks:e,pendingSize:n}=this._requestQueue.popTasks(this._opts.targetMessageSize);if(e.length===0)return;let s=new B(!1);s.setPendingBytes(n);let i=[],o=new Map;for(let c of e){let l=T.parse(c.topic);c.data.haveBlock?c.data.isWantBlock?(i.push(l),o.set(c.topic,c.data)):s.addHave(l):s.addDontHave(l)}let a=await this._getBlocks(i);for(let[c,l]of o){let u=T.parse(c),h=a.get(c);h!=null?s.addBlock(u,h):l.sendDontHave&&s.addDontHave(u)}if(s.empty){t!=null&&this._requestQueue.tasksDone(t,e),this._scheduleProcessTasks();return}try{t!=null&&await this.network.sendMessage(t,s);for(let[c,l]of a.entries())t!=null&&this.messageSent(t,T.parse(c),l)}catch(c){this._log.error(c)}t!=null&&this._requestQueue.tasksDone(t,e),this._scheduleProcessTasks()}wantlistForPeer(t){let e=t.toString(),n=this.ledgerMap.get(e);return n!=null?n.wantlist.sortedEntries():new Map}ledgerForPeer(t){let e=t.toString(),n=this.ledgerMap.get(e);if(n!=null)return{peer:n.partner,value:n.debtRatio(),sent:n.accounting.bytesSent,recv:n.accounting.bytesRecv,exchanged:n.exchangeCount}}peers(){return Array.from(this.ledgerMap.values()).map(t=>t.partner)}receivedBlocks(t){if(t.length!==0){for(let e of this.ledgerMap.values())for(let{cid:n,block:s}of t){let i=e.wantlistContains(n);if(i==null)continue;let o=s.length,a=this._sendAsBlock(i.wantType,o),c=o;a||(c=B.blockPresenceSize(i.cid)),this._requestQueue.pushTasks(e.partner,[{topic:i.cid.toString(b),priority:i.priority,size:c,data:{blockSize:o,isWantBlock:a,haveBlock:!0,sendDontHave:!1}}])}this._scheduleProcessTasks()}}async messageReceived(t,e){let n=this._findOrCreate(t);if(e.empty)return;if(e.full&&(n.wantlist=new Y),this._updateBlockAccounting(e.blocks,n),e.wantlist.size===0){this._scheduleProcessTasks();return}let s=[],i=[];e.wantlist.forEach(o=>{o.cancel?(n.cancelWant(o.cid),s.push(o.cid)):(n.wants(o.cid,o.priority,o.wantType),i.push(o))}),this._cancelWants(t,s),await this._addWants(t,i),this._scheduleProcessTasks()}_cancelWants(t,e){for(let n of e)this._requestQueue.remove(n.toString(b),t)}async _addWants(t,e){let n=await this._getBlockSizes(e.map(i=>i.cid)),s=[];for(let i of e){let o=i.cid.toString(b),a=n.get(o);if(a==null)i.sendDontHave&&s.push({topic:o,priority:i.priority,size:B.blockPresenceSize(i.cid),data:{isWantBlock:i.wantType===Un.Block,blockSize:0,haveBlock:!1,sendDontHave:i.sendDontHave}});else{let c=this._sendAsBlock(i.wantType,a),l=a;c||(l=B.blockPresenceSize(i.cid)),s.push({topic:o,priority:i.priority,size:l,data:{isWantBlock:c,blockSize:a,haveBlock:!0,sendDontHave:i.sendDontHave}})}this._requestQueue.pushTasks(t,s)}}_sendAsBlock(t,e){return t===Un.Block||e<=this._opts.maxSizeReplaceHasWithBlock}async _getBlockSizes(t){let e=await this._getBlocks(t);return new Map([...e].map(([n,s])=>[n,s.length]))}async _getBlocks(t){let e=new Map;return await Promise.all(t.map(async n=>{try{let s=await this.blockstore.get(n);e.set(n.toString(b),s)}catch(s){s.code!=="ERR_NOT_FOUND"&&this._log.error("failed to query blockstore for %s: %s",n,s)}})),e}_updateBlockAccounting(t,e){for(let n of t.values())this._log("got block (%s bytes)",n.length),e.receivedBytes(n.length)}messageSent(t,e,n){let s=this._findOrCreate(t);s.sentBytes(n.length),s.wantlist.remove(e)}numBytesSentTo(t){return this._findOrCreate(t).accounting.bytesSent}numBytesReceivedFrom(t){return this._findOrCreate(t).accounting.bytesRecv}peerDisconnected(t){this.ledgerMap.delete(t.toString())}_findOrCreate(t){let e=t.toString(),n=this.ledgerMap.get(e);if(n!=null)return n;let s=new Gt(t);return this.ledgerMap.set(e,s),this._stats!=null&&this._stats.push(e,"peerCount",1),s}start(){this._running=!0}stop(){this._running=!1}};function Ko(r){return r[Symbol.asyncIterator]!=null}function Zo(r){if(Ko(r))return(async()=>{for await(let t of r);})();for(let t of r);}var On=Zo;function or(r,t){if(globalThis.Buffer!=null)return K(globalThis.Buffer.concat(r,t));t==null&&(t=r.reduce((s,i)=>s+i.length,0));let e=C(t),n=0;for(let s of r)e.set(s,n),n+=s.length;return K(e)}var Hn=Symbol.for("@achingbrain/uint8arraylist");function zn(r,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let e=0;for(let n of r){let s=e+n.byteLength;if(t<s)return{buf:n,index:t-e};e=s}throw new RangeError("index is out of bounds")}function Jt(r){return!!r?.[Hn]}var wt=class r{bufs;length;[Hn]=!0;constructor(...t){this.bufs=[],this.length=0,t.length>0&&this.appendAll(t)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...t){this.appendAll(t)}appendAll(t){let e=0;for(let n of t)if(n instanceof Uint8Array)e+=n.byteLength,this.bufs.push(n);else if(Jt(n))e+=n.byteLength,this.bufs.push(...n.bufs);else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}prepend(...t){this.prependAll(t)}prependAll(t){let e=0;for(let n of t.reverse())if(n instanceof Uint8Array)e+=n.byteLength,this.bufs.unshift(n);else if(Jt(n))e+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}get(t){let e=zn(this.bufs,t);return e.buf[e.index]}set(t,e){let n=zn(this.bufs,t);n.buf[n.index]=e}write(t,e=0){if(t instanceof Uint8Array)for(let n=0;n<t.length;n++)this.set(e+n,t[n]);else if(Jt(t))for(let n=0;n<t.length;n++)this.set(e+n,t.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(t){if(t=Math.trunc(t),!(Number.isNaN(t)||t<=0)){if(t===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(t>=this.bufs[0].byteLength)t-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(t),this.length-=t;break}}}slice(t,e){let{bufs:n,length:s}=this._subList(t,e);return or(n,s)}subarray(t,e){let{bufs:n,length:s}=this._subList(t,e);return n.length===1?n[0]:or(n,s)}sublist(t,e){let{bufs:n,length:s}=this._subList(t,e),i=new r;return i.length=s,i.bufs=[...n],i}_subList(t,e){if(t=t??0,e=e??this.length,t<0&&(t=this.length+t),e<0&&(e=this.length+e),t<0||e>this.length)throw new RangeError("index is out of bounds");if(t===e)return{bufs:[],length:0};if(t===0&&e===this.length)return{bufs:this.bufs,length:this.length};let n=[],s=0;for(let i=0;i<this.bufs.length;i++){let o=this.bufs[i],a=s,c=a+o.byteLength;if(s=c,t>=c)continue;let l=t>=a&&t<c,u=e>a&&e<=c;if(l&&u){if(t===a&&e===c){n.push(o);break}let h=t-a;n.push(o.subarray(h,h+(e-t)));break}if(l){if(t===0){n.push(o);continue}n.push(o.subarray(t-a));continue}if(u){if(e===c){n.push(o);break}n.push(o.subarray(0,e-a));break}n.push(o)}return{bufs:n,length:e-t}}indexOf(t,e=0){if(!Jt(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(e=Number(e??0),isNaN(e)&&(e=0),e<0&&(e=this.length+e),e<0&&(e=0),t.length===0)return e>this.length?this.length:e;let s=n.byteLength;if(s===0)throw new TypeError("search must be at least 1 byte long");let i=256,o=new Int32Array(i);for(let h=0;h<i;h++)o[h]=-1;for(let h=0;h<s;h++)o[n[h]]=h;let a=o,c=this.byteLength-n.byteLength,l=n.byteLength-1,u;for(let h=e;h<=c;h+=u){u=0;for(let f=l;f>=0;f--){let m=this.get(h+f);if(n[f]!==m){u=Math.max(1,f-a[m]);break}}if(u===0)return h}return-1}getInt8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getInt8(0)}setInt8(t,e){let n=C(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,e),this.write(n,t)}getInt16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,e)}setInt16(t,e,n){let s=G(2);new DataView(s.buffer,s.byteOffset,s.byteLength).setInt16(0,e,n),this.write(s,t)}getInt32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,e)}setInt32(t,e,n){let s=G(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setInt32(0,e,n),this.write(s,t)}getBigInt64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,e)}setBigInt64(t,e,n){let s=G(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setBigInt64(0,e,n),this.write(s,t)}getUint8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getUint8(0)}setUint8(t,e){let n=C(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,e),this.write(n,t)}getUint16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,e)}setUint16(t,e,n){let s=G(2);new DataView(s.buffer,s.byteOffset,s.byteLength).setUint16(0,e,n),this.write(s,t)}getUint32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,e)}setUint32(t,e,n){let s=G(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setUint32(0,e,n),this.write(s,t)}getBigUint64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,e)}setBigUint64(t,e,n){let s=G(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setBigUint64(0,e,n),this.write(s,t)}getFloat32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,e)}setFloat32(t,e,n){let s=G(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setFloat32(0,e,n),this.write(s,t)}getFloat64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,e)}setFloat64(t,e,n){let s=G(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setFloat64(0,e,n),this.write(s,t)}equals(t){if(t==null||!(t instanceof r)||t.bufs.length!==this.bufs.length)return!1;for(let e=0;e<this.bufs.length;e++)if(!Ot(this.bufs[e],t.bufs[e]))return!1;return!0}static fromUint8Arrays(t,e){let n=new r;return n.bufs=t,e==null&&(e=t.reduce((s,i)=>s+i.byteLength,0)),n.length=e,n}};function Kt(r){return r[Symbol.asyncIterator]!=null}var Zt=r=>{let t=H(r),e=C(t);return yn(r,e),Zt.bytes=t,e};Zt.bytes=0;function Yt(r,t){t=t??{};let e=t.lengthEncoder??Zt;function*n(s){let i=e(s.byteLength);i instanceof Uint8Array?yield i:yield*i,s instanceof Uint8Array?yield s:yield*s}return Kt(r)?async function*(){for await(let s of r)yield*n(s)}():function*(){for(let s of r)yield*n(s)}()}Yt.single=(r,t)=>{t=t??{};let e=t.lengthEncoder??Zt;return new wt(e(r.byteLength),r)};var _t=$($n(),1);var ta=8,ea=1024*1024*4,ct;(function(r){r[r.LENGTH=0]="LENGTH",r[r.DATA=1]="DATA"})(ct||(ct={}));var ar=r=>{let t=wn(r);return ar.bytes=H(t),t};ar.bytes=0;function Dt(r,t){let e=new wt,n=ct.LENGTH,s=-1,i=t?.lengthDecoder??ar,o=t?.maxLengthLength??ta,a=t?.maxDataLength??ea;function*c(){for(;e.byteLength>0;){if(n===ct.LENGTH)try{if(s=i(e),s<0)throw(0,_t.default)(new Error("invalid message length"),"ERR_INVALID_MSG_LENGTH");if(s>a)throw(0,_t.default)(new Error("message length too long"),"ERR_MSG_DATA_TOO_LONG");let l=i.bytes;e.consume(l),t?.onLength!=null&&t.onLength(s),n=ct.DATA}catch(l){if(l instanceof RangeError){if(e.byteLength>o)throw(0,_t.default)(new Error("message length length too long"),"ERR_MSG_LENGTH_TOO_LONG");break}throw l}if(n===ct.DATA){if(e.byteLength<s)break;let l=e.sublist(0,s);e.consume(s),t?.onData!=null&&t.onData(l),yield l,n=ct.LENGTH}}}return Kt(r)?async function*(){for await(let l of r)e.append(l),yield*c();if(e.byteLength>0)throw(0,_t.default)(new Error("unexpected end of input"),"ERR_UNEXPECTED_EOF")}():function*(){for(let l of r)e.append(l),yield*c();if(e.byteLength>0)throw(0,_t.default)(new Error("unexpected end of input"),"ERR_UNEXPECTED_EOF")}()}Dt.fromReader=(r,t)=>{let e=1,n=async function*(){for(;;)try{let{done:i,value:o}=await r.next(e);if(i===!0)return;o!=null&&(yield o)}catch(i){if(i.code==="ERR_UNDER_READ")return{done:!0,value:null};throw i}finally{e=1}}();return Dt(n,{...t??{},onLength:i=>{e=i}})};function na(r){return r[Symbol.asyncIterator]!=null}function sa(r,t){if(na(r))return async function*(){for await(let a of r)yield t(a)}();let e=Mt(r),{value:n,done:s}=e.next();if(s===!0)return function*(){}();let i=t(n);if(typeof i.then=="function")return async function*(){yield await i;for await(let a of e)yield t(a)}();let o=t;return function*(){yield i;for(let a of e)yield o(a)}()}var Vn=sa;function te(){let r={};return r.promise=new Promise((t,e)=>{r.resolve=t,r.reject=e}),r}var ee=class{buffer;mask;top;btm;next;constructor(t){if(!(t>0)||t-1&t)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(t),this.mask=t-1,this.top=0,this.btm=0,this.next=null}push(t){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=t,this.top=this.top+1&this.mask,!0)}shift(){let t=this.buffer[this.btm];if(t!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,t}isEmpty(){return this.buffer[this.btm]===void 0}},xt=class{size;hwm;head;tail;constructor(t={}){this.hwm=t.splitLimit??16,this.head=new ee(this.hwm),this.tail=this.head,this.size=0}calculateSize(t){return t?.byteLength!=null?t.byteLength:1}push(t){if(t?.value!=null&&(this.size+=this.calculateSize(t.value)),!this.head.push(t)){let e=this.head;this.head=e.next=new ee(2*this.head.buffer.length),this.head.push(t)}}shift(){let t=this.tail.shift();if(t===void 0&&this.tail.next!=null){let e=this.tail.next;this.tail.next=null,this.tail=e,t=this.tail.shift()}return t?.value!=null&&(this.size-=this.calculateSize(t.value)),t}isEmpty(){return this.head.isEmpty()}};var cr=class extends Error{type;code;constructor(t,e){super(t??"The operation was aborted"),this.type="aborted",this.code=e??"ABORT_ERR"}};function re(r={}){return ia(e=>{let n=e.shift();if(n==null)return{done:!0};if(n.error!=null)throw n.error;return{done:n.done===!0,value:n.value}},r)}function ia(r,t){t=t??{};let e=t.onEnd,n=new xt,s,i,o,a=te(),c=async()=>{try{return n.isEmpty()?o?{done:!0}:await new Promise((p,w)=>{i=x=>{i=null,n.push(x);try{p(r(n))}catch(k){w(k)}return s}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=te()})}},l=p=>i!=null?i(p):(n.push(p),s),u=p=>(n=new xt,i!=null?i({error:p}):(n.push({error:p}),s)),h=p=>{if(o)return s;if(t?.objectMode!==!0&&p?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return l({done:!1,value:p})},f=p=>o?s:(o=!0,p!=null?u(p):l({done:!0})),m=()=>(n=new xt,f(),{done:!0}),d=p=>(f(p),{done:!0});if(s={[Symbol.asyncIterator](){return this},next:c,return:m,throw:d,push:h,end:f,get readableLength(){return n.size},onEmpty:async p=>{let w=p?.signal;if(w?.throwIfAborted(),n.isEmpty())return;let x,k;w!=null&&(x=new Promise((E,D)=>{k=()=>{D(new cr)},w.addEventListener("abort",k)}));try{await Promise.race([a.promise,x])}finally{k!=null&&w!=null&&w?.removeEventListener("abort",k)}}},e==null)return s;let g=s;return s={[Symbol.asyncIterator](){return this},next(){return g.next()},throw(p){return g.throw(p),e!=null&&(e(p),e=void 0),{done:!0}},return(){return g.return(),e!=null&&(e(),e=void 0),{done:!0}},push:h,end(p){return g.end(p),e!=null&&(e(p),e=void 0),s},get readableLength(){return g.readableLength},onEmpty:p=>g.onEmpty(p)},s}function oa(r){return r[Symbol.asyncIterator]!=null}function aa(...r){let t=[];for(let e of r)oa(e)||t.push(e);return t.length===r.length?function*(){for(let e of t)yield*e}():async function*(){let e=re({objectMode:!0});Promise.resolve().then(async()=>{try{await Promise.all(r.map(async n=>{for await(let s of n)e.push(s)})),e.end()}catch(n){e.end(n)}}),yield*e}()}var Gn=aa;function ur(r,...t){if(r==null)throw new Error("Empty pipeline");if(lr(r)){let n=r;r=()=>n.source}else if(Qn(r)||Xn(r)){let n=r;r=()=>n}let e=[r,...t];if(e.length>1&&lr(e[e.length-1])&&(e[e.length-1]=e[e.length-1].sink),e.length>2)for(let n=1;n<e.length-1;n++)lr(e[n])&&(e[n]=la(e[n]));return ca(...e)}var ca=(...r)=>{let t;for(;r.length>0;)t=r.shift()(t);return t},Xn=r=>r?.[Symbol.asyncIterator]!=null,Qn=r=>r?.[Symbol.iterator]!=null,lr=r=>r==null?!1:r.sink!=null&&r.source!=null,la=r=>t=>{let e=r.sink(t);if(e?.then!=null){let n=re({objectMode:!0});e.then(()=>{n.end()},o=>{n.end(o)});let s,i=r.source;if(Xn(i))s=async function*(){yield*i,n.end()};else if(Qn(i))s=function*(){yield*i,n.end()};else throw new Error("Unknown duplex source type - must be Iterable or AsyncIterable");return Gn(n,s())}return r.source};function ua(r){return r[Symbol.asyncIterator]!=null}function ha(r,t){return ua(r)?async function*(){let e=0;if(!(t<1)){for await(let n of r)if(yield n,e++,e===t)return}}():function*(){let e=0;if(!(t<1)){for(let n of r)if(yield n,e++,e===t)return}}()}var jn=ha;var q=class extends Event{constructor(t,e){super(t),this.detail=e}};var as=$(rs(),1);var ns=Math.pow(2,31)-1,ss=1e3,is=1;var dr="/ipfs/bitswap/1.0.0",pr="/ipfs/bitswap/1.1.0",gr="/ipfs/bitswap/1.2.0",pa=1024,ga=1024,ma=3e4,se=class{_log;_libp2p;_bitswap;_protocols;_stats;_running;_hashLoader;_maxInboundStreams;_maxOutboundStreams;_incomingStreamTimeout;_registrarIds;constructor(t,e,n,s={}){this._log=z(t.peerId,"network"),this._libp2p=t,this._bitswap=e,this._protocols=[dr],s.b100Only!==!0&&(this._protocols.unshift(pr),this._protocols.unshift(gr)),this._stats=n,this._running=!1,this._onPeerConnect=this._onPeerConnect.bind(this),this._onPeerDisconnect=this._onPeerDisconnect.bind(this),this._onConnection=this._onConnection.bind(this),this._hashLoader=s.hashLoader??{async getHasher(){throw new Error("Not implemented")}},this._maxInboundStreams=s.maxInboundStreams??pa,this._maxOutboundStreams=s.maxOutboundStreams??ga,this._incomingStreamTimeout=s.incomingStreamTimeout??ma}async start(){this._running=!0,await this._libp2p.handle(this._protocols,this._onConnection,{maxInboundStreams:this._maxInboundStreams,maxOutboundStreams:this._maxOutboundStreams});let t={onConnect:this._onPeerConnect,onDisconnect:this._onPeerDisconnect};this._registrarIds=[];for(let e of this._protocols)this._registrarIds.push(await this._libp2p.register(e,t));this._libp2p.getConnections().forEach(e=>{this._onPeerConnect(e.remotePeer)})}async stop(){if(this._running=!1,await this._libp2p.unhandle(this._protocols),this._registrarIds!=null){for(let t of this._registrarIds)this._libp2p.unregister(t);this._registrarIds=[]}}_onConnection(t){if(!this._running)return;let{stream:e,connection:n}=t,s=new as.TimeoutController(this._incomingStreamTimeout);Promise.resolve().then(async()=>{this._log("incoming new bitswap %s connection from %p",e.protocol,n.remotePeer);let i=()=>{e.abort(new pt("Incoming Bitswap stream timed out","ERR_TIMEOUT"))},o=AbortSignal.timeout(this._incomingStreamTimeout);o.addEventListener("abort",i),await ur(e,a=>Dt(a),async a=>{for await(let c of a){try{let l=await B.deserialize(c.subarray(),this._hashLoader);await this._bitswap._receiveMessage(n.remotePeer,l)}catch(l){this._bitswap._receiveError(l);break}o.removeEventListener("abort",i),o=AbortSignal.timeout(this._incomingStreamTimeout),o.addEventListener("abort",i)}}),await e.close({signal:o})}).catch(i=>{this._log(i),e.abort(i)}).finally(()=>{s.clear()})}_onPeerConnect(t){this._bitswap._onPeerConnected(t)}_onPeerDisconnect(t){this._bitswap._onPeerDisconnected(t)}findProviders(t,e={}){return e.onProgress?.(new q("bitswap:network:find-providers",t)),this._libp2p.contentRouting.findProviders(t,e)}async findAndConnect(t,e){await On(jn(Vn(this.findProviders(t,e),async n=>this.connectTo(n.id,e).catch(s=>{this._log.error(s)})),3)).catch(n=>{this._log.error(n)})}async provide(t,e={}){e.onProgress?.(new q("bitswap:network:provide",t)),await this._libp2p.contentRouting.provide(t,e)}async sendMessage(t,e,n={}){if(!this._running)throw new Error("network isn't running");let s=t.toString();this._log("sendMessage to %s",s,e),n.onProgress?.(new q("bitswap:network:send-wantlist",t)),await this._writeMessage(t,e,n),this._updateSentStats(t,e.blocks)}async connectTo(t,e={}){if(!this._running)throw new Error("network isn't running");return e.onProgress?.(new q("bitswap:network:dial",t)),this._libp2p.dial(t,e)}_updateSentStats(t,e){let n=t.toString();if(this._stats!=null){for(let s of e.values())this._stats.push(n,"dataSent",s.length);this._stats.push(n,"blocksSent",e.size)}}async _writeMessage(t,e,n={}){let s=await this._libp2p.dialProtocol(t,[gr,pr,dr]);try{let i;switch(s.protocol){case dr:i=e.serializeToBitswap100();break;case pr:case gr:i=e.serializeToBitswap110();break;default:throw new Error(`Unknown protocol: ${s.protocol}`)}await ur([i],o=>Yt(o),s),await s.close()}catch(i){n.onProgress?.(new q("bitswap:network:send-wantlist:error",{peer:t,error:i})),this._log(i),s.abort(i)}}};var _s=$(ae(),1);function br(r,t="utf8"){let e=Wt[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return(t==="utf8"||t==="utf-8")&&globalThis.Buffer!=null&&globalThis.Buffer.from!=null?globalThis.Buffer.from(r.buffer,r.byteOffset,r.byteLength).toString("utf8"):e.encoder.encode(r).substring(1)}var ys=r=>`unwant:${br(r.multihash.bytes,"base64")}`,ws=r=>`block:${br(r.multihash.bytes,"base64")}`,ce=class extends _s.EventEmitter{_log;constructor(t){super(),this.setMaxListeners(ss),this._log=z(t,"notif")}hasBlock(t,e){let n=ws(t);this._log(n),this.emit(n,e)}async wantBlock(t,e={}){if(t==null)throw new Error("Not a valid cid");let n=ws(t),s=ys(t);return this._log(`wantBlock:${t}`),new Promise((i,o)=>{let a=()=>{this.removeListener(n,c),e.onProgress?.(new q("bitswap:want-block:unwant",t)),o(new Error(`Block for ${t} unwanted`))},c=l=>{this.removeListener(s,a),e.onProgress?.(new q("bitswap:want-block:block",t)),i(l)};this.once(s,a),this.once(n,c),e.signal?.addEventListener("abort",()=>{this.removeListener(n,c),this.removeListener(s,a),o(new Error(`Want for ${t} aborted`))})})}unwantBlock(t){let e=ys(t);this._log(e),this.emit(e)}};var Ts=$(ae(),1);var Es=$(ae(),1),yr=$(ks(),1),It=class extends Es.EventEmitter{_options;_queue;_stats;_frequencyLastTime;_frequencyAccumulators;_movingAverages;_enabled;_timeout;constructor(t,e){super(),this._options=e,this._queue=[],this._stats={},this._frequencyLastTime=Date.now(),this._frequencyAccumulators={},this._movingAverages={},this._update=this._update.bind(this),t.forEach(n=>{this._stats[n]=BigInt(0),this._movingAverages[n]={},this._options.movingAverageIntervals.forEach(s=>{(this._movingAverages[n][s]=(0,yr.default)(s)).push(this._frequencyLastTime,0)})}),this._enabled=this._options.enabled}enable(){this._enabled=!0}disable(){this._enabled=!1}stop(){this._timeout!=null&&clearTimeout(this._timeout)}get snapshot(){return Object.assign({},this._stats)}get movingAverages(){return Object.assign({},this._movingAverages)}push(t,e){this._enabled&&(this._queue.push([t,e,Date.now()]),this._resetComputeTimeout())}_resetComputeTimeout(){this._timeout!=null&&clearTimeout(this._timeout),this._timeout=setTimeout(this._update,this._nextTimeout())}_nextTimeout(){let t=this._queue.length/this._options.computeThrottleMaxQueueSize;return Math.max(this._options.computeThrottleTimeout*(1-t),0)}_update(){if(this._timeout=void 0,this._queue.length>0){let t;for(;this._queue.length>0;){let e=t=this._queue.shift();e!=null&&this._applyOp(e)}t!=null&&this._updateFrequency(t[2]),this.emit("update",this._stats)}}_updateFrequency(t){let e=t-this._frequencyLastTime;e>0&&Object.keys(this._stats).forEach(n=>{this._updateFrequencyFor(n,e,t)}),this._frequencyLastTime=t}_updateFrequencyFor(t,e,n){let s=this._frequencyAccumulators[t]??0;this._frequencyAccumulators[t]=0;let i=s/e*1e3,o=this._movingAverages[t];o==null&&(o=this._movingAverages[t]={}),this._options.movingAverageIntervals.forEach(a=>{let c=o[a];c==null&&(c=o[a]=(0,yr.default)(a)),c.push(n,i)})}_applyOp(t){let e=t[0],n=t[1];if(typeof n!="number")throw new Error(`invalid increment number: ${n}`);Object.prototype.hasOwnProperty.call(this._stats,e)||(this._stats[e]=BigInt(0)),this._stats[e]=BigInt(this._stats[e])+BigInt(n),this._frequencyAccumulators[e]==null&&(this._frequencyAccumulators[e]=0),this._frequencyAccumulators[e]+=n}};var Ss={enabled:!1,computeThrottleTimeout:1e3,computeThrottleMaxQueueSize:1e3,movingAverageIntervals:[60*1e3,5*60*1e3,15*60*1e3]},le=class extends Ts.EventEmitter{_initialCounters;_options;_enabled;_global;_peers;constructor(t,e=[],n=Ss){super();let s=Object.assign({},Ss,n);if(typeof s.computeThrottleTimeout!="number")throw new Error("need computeThrottleTimeout");if(typeof s.computeThrottleMaxQueueSize!="number")throw new Error("need computeThrottleMaxQueueSize");this._initialCounters=e,this._options=s,this._enabled=this._options.enabled,this._global=new It(e,s),this._global.on("update",i=>this.emit("update",i)),this._peers=j({name:"ipfs_bitswap_stats_peers",metrics:t.metrics})}enable(){this._enabled=!0,this._options.enabled=!0,this._global.enable()}disable(){this._enabled=!1,this._options.enabled=!1,this._global.disable()}stop(){this._enabled=!1,this._global.stop();for(let t of this._peers)t[1].stop()}get snapshot(){return this._global.snapshot}get movingAverages(){return this._global.movingAverages}forPeer(t){let e=t.toString();return this._peers.get(e)}push(t,e,n){if(this._enabled&&(this._global.push(e,n),t!=null)){let s=this._peers.get(t);s==null&&(s=new It(this._initialCounters,this._options),this._peers.set(t,s)),s.push(e,n)}}disconnected(t){let e=t.toString(),n=this._peers.get(e);n!=null&&(n.stop(),this._peers.delete(e))}};var Cs=Ea;function Ea(r,t,e){var n=null,s=null,i=function(){n&&(clearTimeout(n),s=null,n=null)},o=function(){var c=s;i(),c&&c()},a=function(){if(!t)return r.apply(this,arguments);var c=this,l=arguments,u=e&&!n;if(i(),s=function(){r.apply(c,l)},n=setTimeout(function(){if(n=null,!u){var h=s;return s=null,h()}},t),u)return s()};return a.cancel=i,a.flush=o,a}var ue=class{peerId;refcnt;network;_entries;_log;constructor(t,e,n){this.peerId=e,this.network=n,this.refcnt=1,this._entries=[],this._log=z(t,"msgqueue"),this.sendEntries=Cs(this.sendEntries.bind(this),is)}addMessage(t,e={}){t.empty||this.send(t,e)}addEntries(t,e={}){this._entries=this._entries.concat(t),this.sendEntries(e)}sendEntries(t={}){if(this._entries.length===0)return;let e=new B(!1);this._entries.forEach(n=>{n.cancel===!0?e.cancel(n.cid):e.addEntry(n.cid,n.priority)}),this._entries=[],this.addMessage(e,t)}async send(t,e={}){try{await this.network.connectTo(this.peerId,e)}catch(n){this._log.error("cant connect to peer %p: %s",this.peerId,n.message);return}this._log("sending message to peer %p",this.peerId),this.network.sendMessage(this.peerId,t,e).catch(n=>{this._log.error("send error",n)})}};var he=class{peers;wantlist;network;_peerId;_log;constructor(t,e,n,s){this.peers=j({name:"ipfs_bitswap_want_manager_peers",metrics:s.metrics}),this.wantlist=new Y(n,s),this.network=e,this._peerId=t,this._log=z(t,"want")}_addEntries(t,e,n,s={}){let i=t.map((o,a)=>new B.Entry(o,ns-a,B.WantType.Block,e));i.forEach(o=>{o.cancel?n===!0?this.wantlist.removeForce(o.cid.toString(b)):this.wantlist.remove(o.cid):(this._log("adding to wantlist"),this.wantlist.add(o.cid,o.priority))});for(let o of this.peers.values())o.addEntries(i,s)}_startPeerHandler(t){let e=this.peers.get(t.toString());if(e!=null){e.refcnt++;return}e=new ue(this._peerId,t,this.network);let n=new B(!0);for(let s of this.wantlist.entries())n.addEntry(s[1].cid,s[1].priority);return e.addMessage(n),this.peers.set(t.toString(),e),e}_stopPeerHandler(t){let e=this.peers.get(t.toString());e!=null&&(e.refcnt--,!(e.refcnt>0)&&this.peers.delete(t.toString()))}wantBlocks(t,e={}){this._addEntries(t,!1,!1,e),e.signal?.addEventListener("abort",()=>{this.cancelWants(t)})}unwantBlocks(t){this._log("unwant blocks: %s",t.length),this._addEntries(t,!0,!0)}cancelWants(t){this._log("cancel wants: %s",t.length),this._addEntries(t,!0)}connectedPeers(){return Array.from(this.peers.keys())}connected(t){this._startPeerHandler(t)}disconnected(t){this._stopPeerHandler(t)}start(){}stop(){this.peers.forEach(t=>{this.disconnected(t.peerId)})}};var Sa={async getHasher(){throw new Error("Not implemented")}},Ta={maxInboundStreams:1024,maxOutboundStreams:1024,incomingStreamTimeout:3e4,hashLoader:Sa,statsEnabled:!1,statsComputeThrottleTimeout:1e3,statsComputeThrottleMaxQueueSize:1e3},Ca=["blocksReceived","dataReceived","dupBlksReceived","dupDataReceived","blocksSent","dataSent","providesBufferLength","wantListLength","peerCount"],fe=class{_libp2p;_log;stats;network;blockstore;engine;wm;notifications;started;constructor(t,e,n={}){this._libp2p=t,this._log=z(this.peerId),n=Object.assign({},Ta,n),this.stats=new le(t,Ca,{enabled:n.statsEnabled,computeThrottleTimeout:n.statsComputeThrottleTimeout,computeThrottleMaxQueueSize:n.statsComputeThrottleMaxQueueSize}),this.network=new se(t,this,this.stats,{hashLoader:n.hashLoader,maxInboundStreams:n.maxInboundStreams,maxOutboundStreams:n.maxOutboundStreams,incomingStreamTimeout:n.incomingStreamTimeout}),this.blockstore=e,this.engine=new jt(this.peerId,e,this.network,this.stats,t),this.wm=new he(this.peerId,this.network,this.stats,t),this.notifications=new ce(this.peerId),this.started=!1}isStarted(){return this.started}get peerId(){return this._libp2p.peerId}async _receiveMessage(t,e){try{await this.engine.messageReceived(t,e)}catch{this._log("failed to receive message",e)}if(e.blocks.size===0)return;let n=[];for(let[s,i]of e.blocks.entries()){let o=T.parse(s);n.push({wasWanted:this.wm.wantlist.contains(o),cid:o,data:i})}this.wm.cancelWants(n.filter(({wasWanted:s})=>s).map(({cid:s})=>s)),await Promise.all(n.map(async({cid:s,wasWanted:i,data:o})=>{await this._handleReceivedBlock(t,s,o,i)}))}async _handleReceivedBlock(t,e,n,s){this._log("received block");let i=await this.blockstore.has(e);this._updateReceiveCounters(t.toString(),e,n,i),s&&await this.put(e,n)}_updateReceiveCounters(t,e,n,s){this.stats.push(t,"blocksReceived",1),this.stats.push(t,"dataReceived",n.length),s&&(this.stats.push(t,"dupBlksReceived",1),this.stats.push(t,"dupDataReceived",n.length))}_receiveError(t){this._log.error("ReceiveError",t)}_onPeerConnected(t){this.wm.connected(t)}_onPeerDisconnected(t){this.wm.disconnected(t),this.engine.peerDisconnected(t),this.stats.disconnected(t)}enableStats(){this.stats.enable()}disableStats(){this.stats.disable()}wantlistForPeer(t,e){return this.engine.wantlistForPeer(t)}ledgerForPeer(t){return this.engine.ledgerForPeer(t)}async want(t,e={}){let n=async(c,l)=>(this.wm.wantBlocks([c],l),this.notifications.wantBlock(c,l)),s=!1,i=async(c,l)=>{try{return await this.blockstore.get(c,l)}catch(u){if(u.code!=="ERR_NOT_FOUND")throw u;return s||(s=!0,this.network.findAndConnect(c,l).catch(h=>{this._log.error(h)})),await n(c,l)}},o=new AbortController,a=xr([o.signal,e.signal]);try{return await Promise.race([this.notifications.wantBlock(t,{...e,signal:a}),i(t,{...e,signal:a})])}finally{o.abort(),a.clear()}}unwant(t){let e=Array.isArray(t)?t:[t];this.wm.unwantBlocks(e),e.forEach(n=>{this.notifications.unwantBlock(n)})}cancelWants(t){this.wm.cancelWants(Array.isArray(t)?t:[t])}async put(t,e,n){await this.blockstore.put(t,e),this.notify(t,e)}async*putMany(t,e){yield*this.blockstore.putMany(kr(t,({cid:n,block:s})=>{this.notify(n,s)}),e)}notify(t,e,n={}){this.notifications.hasBlock(t,e),this.engine.receivedBlocks([{cid:t,block:e}]),this.network.provide(t,n).catch(s=>{this._log.error("Failed to provide: %s",s.message)})}getWantlist(){return this.wm.wantlist.entries()}get peers(){return this.engine.peers()}async start(){this.wm.start(),await this.network.start(),this.engine.start(),this.started=!0}async stop(){this.stats.stop(),this.wm.stop(),await this.network.stop(),this.engine.stop(),this.started=!1}};var As=(r,t,e={})=>new fe(r,t,e);var wr=class{bitswap;started;constructor(t,e={}){let{libp2p:n,blockstore:s,hashers:i}=t;this.bitswap=As(n,s,{hashLoader:{getHasher:async o=>{let a;if(typeof o=="string"?a=Object.values(i).find(c=>c.name===o):a=i[o],a!=null)return a;throw new Error(`Could not load hasher for code/name "${o}"`)}},...e}),this.started=!1}isStarted(){return this.started}async start(){await this.bitswap.start(),this.started=!0}async stop(){await this.bitswap.stop(),this.started=!1}announce(t,e,n){this.bitswap.notify(t,e,n)}async retrieve(t,{validateFn:e,...n}={}){return this.bitswap.want(t,n)}};function Ls(r={}){return t=>new wr(t,r)}var de=class{url;#t=0;#e=0;#r=0;#n=0;constructor(t){this.url=t instanceof URL?t:new URL(t)}async getRawBlock(t,e){let n=this.url;if(n.pathname=`/ipfs/${t.toString()}`,n.search="?format=raw",e?.aborted===!0)throw new Error(`Signal to fetch raw block for CID ${t} from gateway ${this.url} was aborted prior to fetch`);try{this.#t++;let s=await fetch(n.toString(),{signal:e,headers:{Accept:"application/vnd.ipld.raw"},cache:"force-cache"});if(!s.ok)throw this.#e++,new Error(`unable to fetch raw block for CID ${t} from gateway ${this.url}`);return this.#n++,new Uint8Array(await s.arrayBuffer())}catch{throw e?.aborted===!0?new Error(`fetching raw block for CID ${t} from gateway ${this.url} was aborted`):(this.#e++,new Error(`unable to fetch raw block for CID ${t}`))}}reliability(){return this.#t===0?1:this.#r>0?-1/0:this.#n/(this.#t+this.#e*3)}incrementInvalidBlocks(){this.#r++}};var pe=class{gateways;log;constructor(t,e={}){this.log=t.logger.forComponent("helia:trustless-gateway-block-broker"),this.gateways=(e.gateways??Bs).map(n=>new de(n))}async retrieve(t,e={}){let n=this.gateways.sort((i,o)=>o.reliability()-i.reliability()),s=[];for(let i of n){this.log("getting block for %c from %s",t,i.url);try{let o=await i.getRawBlock(t,e.signal);this.log.trace("got block for %c from %s",t,i.url);try{await e.validateFn?.(o)}catch(a){throw this.log.error("failed to validate block for %c from %s",t,i.url,a),i.incrementInvalidBlocks(),new Error(`unable to validate block for CID ${t} from gateway ${i.url}`)}return o}catch(o){if(this.log.error("failed to get block for %c from %s",t,i.url,o),o instanceof Error?s.push(o):s.push(new Error(`unable to fetch raw block for CID ${t} from gateway ${i.url}`)),e.signal?.aborted===!0){this.log.trace("request aborted while fetching raw block for CID %c from gateway %s",t,i.url);break}}}throw new AggregateError(s,`unable to fetch raw block for CID ${t} from any gateway`)}};var Bs=["https://trustless-gateway.link","https://cloudflare-ipfs.com","https://4everland.io"];function Fs(r={}){return t=>new pe(t,r)}return Ps(Aa);})();
|
|
3
3
|
return HeliaBlockBrokers}));
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { TrustlessGatewayBlockBroker } from './broker.js';
|
|
2
2
|
export const DEFAULT_TRUSTLESS_GATEWAYS = [
|
|
3
3
|
// 2023-10-03: IPNS, Origin, and Block/CAR support from https://ipfs-public-gateway-checker.on.fleek.co/
|
|
4
|
-
'https://
|
|
4
|
+
'https://trustless-gateway.link',
|
|
5
5
|
// 2023-10-03: IPNS, Origin, and Block/CAR support from https://ipfs-public-gateway-checker.on.fleek.co/
|
|
6
|
-
'https://
|
|
6
|
+
'https://cloudflare-ipfs.com',
|
|
7
7
|
// 2023-10-03: IPNS, Origin, and Block/CAR support from https://ipfs-public-gateway-checker.on.fleek.co/
|
|
8
8
|
'https://4everland.io'
|
|
9
9
|
];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/trustless-gateway/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,2BAA2B,EAAE,MAAM,aAAa,CAAA;AAKzD,MAAM,CAAC,MAAM,0BAA0B,GAAG;IACxC,wGAAwG;IACxG,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/trustless-gateway/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,2BAA2B,EAAE,MAAM,aAAa,CAAA;AAKzD,MAAM,CAAC,MAAM,0BAA0B,GAAG;IACxC,wGAAwG;IACxG,gCAAgC;IAEhC,wGAAwG;IACxG,6BAA6B;IAE7B,wGAAwG;IACxG,sBAAsB;CACvB,CAAA;AAaD,MAAM,UAAU,gBAAgB,CAAE,OAAwC,EAAE;IAC1E,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,IAAI,2BAA2B,CAAC,UAAU,EAAE,IAAI,CAAC,CAAA;AAC1E,CAAC"}
|
package/package.json
CHANGED
|
@@ -5,10 +5,10 @@ import type { ProgressEvent } from 'progress-events'
|
|
|
5
5
|
|
|
6
6
|
export const DEFAULT_TRUSTLESS_GATEWAYS = [
|
|
7
7
|
// 2023-10-03: IPNS, Origin, and Block/CAR support from https://ipfs-public-gateway-checker.on.fleek.co/
|
|
8
|
-
'https://
|
|
8
|
+
'https://trustless-gateway.link',
|
|
9
9
|
|
|
10
10
|
// 2023-10-03: IPNS, Origin, and Block/CAR support from https://ipfs-public-gateway-checker.on.fleek.co/
|
|
11
|
-
'https://
|
|
11
|
+
'https://cloudflare-ipfs.com',
|
|
12
12
|
|
|
13
13
|
// 2023-10-03: IPNS, Origin, and Block/CAR support from https://ipfs-public-gateway-checker.on.fleek.co/
|
|
14
14
|
'https://4everland.io'
|