@libp2p/daemon-server 7.0.6 → 8.0.0

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,7 +1,30 @@
1
1
  (function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.Libp2PDaemonServer = factory()}(typeof self !== 'undefined' ? self : this, function () {
2
- "use strict";var Libp2PDaemonServer=(()=>{var wi=Object.create;var ye=Object.defineProperty;var Ei=Object.getOwnPropertyDescriptor;var xi=Object.getOwnPropertyNames;var Ii=Object.getPrototypeOf,Ai=Object.prototype.hasOwnProperty;var H=(r=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(r,{get:(t,e)=>(typeof require<"u"?require:t)[e]}):r)(function(r){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+r+'" is not supported')});var bt=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports),J=(r,t)=>{for(var e in t)ye(r,e,{get:t[e],enumerable:!0})},Pn=(r,t,e,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of xi(t))!Ai.call(r,n)&&n!==e&&ye(r,n,{get:()=>t[n],enumerable:!(o=Ei(t,n))||o.enumerable});return r};var St=(r,t,e)=>(e=r!=null?wi(Ii(r)):{},Pn(t||!r||!r.__esModule?ye(e,"default",{value:r,enumerable:!0}):e,r)),Ci=r=>Pn(ye({},"__esModule",{value:!0}),r);var ao=bt((zu,co)=>{var Yt=1e3,Qt=Yt*60,Jt=Qt*60,kt=Jt*24,zs=kt*7,Hs=kt*365.25;co.exports=function(r,t){t=t||{};var e=typeof r;if(e==="string"&&r.length>0)return Ws(r);if(e==="number"&&isFinite(r))return t.long?Xs(r):Ks(r);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(r))};function Ws(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]),o=(t[2]||"ms").toLowerCase();switch(o){case"years":case"year":case"yrs":case"yr":case"y":return e*Hs;case"weeks":case"week":case"w":return e*zs;case"days":case"day":case"d":return e*kt;case"hours":case"hour":case"hrs":case"hr":case"h":return e*Jt;case"minutes":case"minute":case"mins":case"min":case"m":return e*Qt;case"seconds":case"second":case"secs":case"sec":case"s":return e*Yt;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return e;default:return}}}}function Ks(r){var t=Math.abs(r);return t>=kt?Math.round(r/kt)+"d":t>=Jt?Math.round(r/Jt)+"h":t>=Qt?Math.round(r/Qt)+"m":t>=Yt?Math.round(r/Yt)+"s":r+"ms"}function Xs(r){var t=Math.abs(r);return t>=kt?ke(r,t,kt,"day"):t>=Jt?ke(r,t,Jt,"hour"):t>=Qt?ke(r,t,Qt,"minute"):t>=Yt?ke(r,t,Yt,"second"):r+" ms"}function ke(r,t,e,o){var n=t>=e*1.5;return Math.round(r/e)+" "+o+(n?"s":"")}});var Qr=bt((Hu,uo)=>{function Ys(r){e.debug=e,e.default=e,e.coerce=a,e.disable=i,e.enable=n,e.enabled=s,e.humanize=ao(),e.destroy=f,Object.keys(r).forEach(u=>{e[u]=r[u]}),e.names=[],e.skips=[],e.formatters={};function t(u){let l=0;for(let g=0;g<u.length;g++)l=(l<<5)-l+u.charCodeAt(g),l|=0;return e.colors[Math.abs(l)%e.colors.length]}e.selectColor=t;function e(u){let l,g=null,b,p;function y(...h){if(!y.enabled)return;let w=y,E=Number(new Date),R=E-(l||E);w.diff=R,w.prev=l,w.curr=E,l=E,h[0]=e.coerce(h[0]),typeof h[0]!="string"&&h.unshift("%O");let k=0;h[0]=h[0].replace(/%([a-zA-Z%])/g,(et,Q)=>{if(et==="%%")return"%";k++;let rt=e.formatters[Q];if(typeof rt=="function"){let Vt=h[k];et=rt.call(w,Vt),h.splice(k,1),k--}return et}),e.formatArgs.call(w,h),(w.log||e.log).apply(w,h)}return y.namespace=u,y.useColors=e.useColors(),y.color=e.selectColor(u),y.extend=o,y.destroy=e.destroy,Object.defineProperty(y,"enabled",{enumerable:!0,configurable:!1,get:()=>g!==null?g:(b!==e.namespaces&&(b=e.namespaces,p=e.enabled(u)),p),set:h=>{g=h}}),typeof e.init=="function"&&e.init(y),y}function o(u,l){let g=e(this.namespace+(typeof l>"u"?":":l)+u);return g.log=this.log,g}function n(u){e.save(u),e.namespaces=u,e.names=[],e.skips=[];let l,g=(typeof u=="string"?u:"").split(/[\s,]+/),b=g.length;for(l=0;l<b;l++)g[l]&&(u=g[l].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(c),...e.skips.map(c).map(l=>"-"+l)].join(",");return e.enable(""),u}function s(u){if(u[u.length-1]==="*")return!0;let l,g;for(l=0,g=e.skips.length;l<g;l++)if(e.skips[l].test(u))return!1;for(l=0,g=e.names.length;l<g;l++)if(e.names[l].test(u))return!0;return!1}function c(u){return u.toString().substring(2,u.toString().length-2).replace(/\.\*\?$/,"*")}function a(u){return u instanceof Error?u.stack||u.message:u}function f(){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}uo.exports=Ys});var lo=bt((q,Oe)=>{q.formatArgs=Js;q.save=Zs;q.load=qs;q.useColors=Qs;q.storage=js();q.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`."))}})();q.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 Qs(){if(typeof window<"u"&&window.process&&(window.process.type==="renderer"||window.process.__nwjs))return!0;if(typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/))return!1;let r;return 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&&(r=navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/))&&parseInt(r[1],10)>=31||typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)}function Js(r){if(r[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+r[0]+(this.useColors?"%c ":" ")+"+"+Oe.exports.humanize(this.diff),!this.useColors)return;let t="color: "+this.color;r.splice(1,0,t,"color: inherit");let e=0,o=0;r[0].replace(/%[a-zA-Z%]/g,n=>{n!=="%%"&&(e++,n==="%c"&&(o=e))}),r.splice(o,0,t)}q.log=console.debug||console.log||(()=>{});function Zs(r){try{r?q.storage.setItem("debug",r):q.storage.removeItem("debug")}catch{}}function qs(){let r;try{r=q.storage.getItem("debug")}catch{}return!r&&typeof process<"u"&&"env"in process&&(r=process.env.DEBUG),r}function js(){try{return localStorage}catch{}}Oe.exports=Qr()(q);var{formatters:tc}=Oe.exports;tc.j=function(r){try{return JSON.stringify(r)}catch(t){return"[UnexpectedJSONParseError]: "+t.message}}});var ho=bt((Wu,fo)=>{"use strict";fo.exports=(r,t)=>{t=t||process.argv;let e=r.startsWith("-")?"":r.length===1?"-":"--",o=t.indexOf(e+r),n=t.indexOf("--");return o!==-1&&(n===-1?!0:o<n)}});var mo=bt((Ku,po)=>{"use strict";var ec=H("os"),dt=ho(),G=process.env,Zt;dt("no-color")||dt("no-colors")||dt("color=false")?Zt=!1:(dt("color")||dt("colors")||dt("color=true")||dt("color=always"))&&(Zt=!0);"FORCE_COLOR"in G&&(Zt=G.FORCE_COLOR.length===0||parseInt(G.FORCE_COLOR,10)!==0);function rc(r){return r===0?!1:{level:r,hasBasic:!0,has256:r>=2,has16m:r>=3}}function nc(r){if(Zt===!1)return 0;if(dt("color=16m")||dt("color=full")||dt("color=truecolor"))return 3;if(dt("color=256"))return 2;if(r&&!r.isTTY&&Zt!==!0)return 0;let t=Zt?1:0;if(process.platform==="win32"){let e=ec.release().split(".");return Number(process.versions.node.split(".")[0])>=8&&Number(e[0])>=10&&Number(e[2])>=10586?Number(e[2])>=14931?3:2:1}if("CI"in G)return["TRAVIS","CIRCLECI","APPVEYOR","GITLAB_CI"].some(e=>e in G)||G.CI_NAME==="codeship"?1:t;if("TEAMCITY_VERSION"in G)return/^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(G.TEAMCITY_VERSION)?1:0;if(G.COLORTERM==="truecolor")return 3;if("TERM_PROGRAM"in G){let e=parseInt((G.TERM_PROGRAM_VERSION||"").split(".")[0],10);switch(G.TERM_PROGRAM){case"iTerm.app":return e>=3?3:2;case"Apple_Terminal":return 2}}return/-256(color)?$/i.test(G.TERM)?2:/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(G.TERM)||"COLORTERM"in G?1:(G.TERM==="dumb",t)}function Jr(r){let t=nc(r);return rc(t)}po.exports={supportsColor:Jr,stdout:Jr(process.stdout),stderr:Jr(process.stderr)}});var yo=bt((O,Ue)=>{var oc=H("tty"),_e=H("util");O.init=dc;O.log=ac;O.formatArgs=sc;O.save=uc;O.load=lc;O.useColors=ic;O.destroy=_e.deprecate(()=>{},"Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.");O.colors=[6,2,3,4,5,1];try{let r=mo();r&&(r.stderr||r).level>=2&&(O.colors=[20,21,26,27,32,33,38,39,40,41,42,43,44,45,56,57,62,63,68,69,74,75,76,77,78,79,80,81,92,93,98,99,112,113,128,129,134,135,148,149,160,161,162,163,164,165,166,167,168,169,170,171,172,173,178,179,184,185,196,197,198,199,200,201,202,203,204,205,206,207,208,209,214,215,220,221])}catch{}O.inspectOpts=Object.keys(process.env).filter(r=>/^debug_/i.test(r)).reduce((r,t)=>{let e=t.substring(6).toLowerCase().replace(/_([a-z])/g,(n,i)=>i.toUpperCase()),o=process.env[t];return/^(yes|on|true|enabled)$/i.test(o)?o=!0:/^(no|off|false|disabled)$/i.test(o)?o=!1:o==="null"?o=null:o=Number(o),r[e]=o,r},{});function ic(){return"colors"in O.inspectOpts?!!O.inspectOpts.colors:oc.isatty(process.stderr.fd)}function sc(r){let{namespace:t,useColors:e}=this;if(e){let o=this.color,n="\x1B[3"+(o<8?o:"8;5;"+o),i=` ${n};1m${t} \x1B[0m`;r[0]=i+r[0].split(`
2
+ "use strict";var Libp2PDaemonServer=(()=>{var Oc=Object.create;var pr=Object.defineProperty;var Dc=Object.getOwnPropertyDescriptor;var Uc=Object.getOwnPropertyNames;var Rc=Object.getPrototypeOf,_c=Object.prototype.hasOwnProperty;var Y=(r=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(r,{get:(t,e)=>(typeof require<"u"?require:t)[e]}):r)(function(r){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+r+'" is not supported')});var at=(r,t)=>{for(var e in t)pr(r,e,{get:t[e],enumerable:!0})},Ti=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Uc(t))!_c.call(r,o)&&o!==e&&pr(r,o,{get:()=>t[o],enumerable:!(n=Dc(t,o))||n.enumerable});return r};var ht=(r,t,e)=>(e=r!=null?Oc(Rc(r)):{},Ti(t||!r||!r.__esModule?pr(e,"default",{value:r,enumerable:!0}):e,r)),Mc=r=>Ti(pr({},"__esModule",{value:!0}),r);var jl={};at(jl,{Server:()=>Cn,createServer:()=>Jl});var Dn=Y("node:buffer");function fe(r){return new Uint8Array(r.buffer,r.byteOffset,r.byteLength)}function Kt(r=0){return fe(Dn.Buffer.alloc(r))}function ut(r=0){return fe(Dn.Buffer.allocUnsafe(r))}var Kc=Math.pow(2,7),$c=Math.pow(2,14),Vc=Math.pow(2,21),Un=Math.pow(2,28),Rn=Math.pow(2,35),_n=Math.pow(2,42),Mn=Math.pow(2,49),C=128,et=127;function H(r){if(r<Kc)return 1;if(r<$c)return 2;if(r<Vc)return 3;if(r<Un)return 4;if(r<Rn)return 5;if(r<_n)return 6;if(r<Mn)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Kn(r,t,e=0){switch(H(r)){case 8:t[e++]=r&255|C,r/=128;case 7:t[e++]=r&255|C,r/=128;case 6:t[e++]=r&255|C,r/=128;case 5:t[e++]=r&255|C,r/=128;case 4:t[e++]=r&255|C,r>>>=7;case 3:t[e++]=r&255|C,r>>>=7;case 2:t[e++]=r&255|C,r>>>=7;case 1:{t[e++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return t}function Gc(r,t,e=0){switch(H(r)){case 8:t.set(e++,r&255|C),r/=128;case 7:t.set(e++,r&255|C),r/=128;case 6:t.set(e++,r&255|C),r/=128;case 5:t.set(e++,r&255|C),r/=128;case 4:t.set(e++,r&255|C),r>>>=7;case 3:t.set(e++,r&255|C),r>>>=7;case 2:t.set(e++,r&255|C),r>>>=7;case 1:{t.set(e++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return t}function $n(r,t){let e=r[t],n=0;if(n+=e&et,e<C||(e=r[t+1],n+=(e&et)<<7,e<C)||(e=r[t+2],n+=(e&et)<<14,e<C)||(e=r[t+3],n+=(e&et)<<21,e<C)||(e=r[t+4],n+=(e&et)*Un,e<C)||(e=r[t+5],n+=(e&et)*Rn,e<C)||(e=r[t+6],n+=(e&et)*_n,e<C)||(e=r[t+7],n+=(e&et)*Mn,e<C))return n;throw new RangeError("Could not decode varint")}function Fc(r,t){let e=r.get(t),n=0;if(n+=e&et,e<C||(e=r.get(t+1),n+=(e&et)<<7,e<C)||(e=r.get(t+2),n+=(e&et)<<14,e<C)||(e=r.get(t+3),n+=(e&et)<<21,e<C)||(e=r.get(t+4),n+=(e&et)*Un,e<C)||(e=r.get(t+5),n+=(e&et)*Rn,e<C)||(e=r.get(t+6),n+=(e&et)*_n,e<C)||(e=r.get(t+7),n+=(e&et)*Mn,e<C))return n;throw new RangeError("Could not decode varint")}function _t(r,t,e=0){return t==null&&(t=ut(H(r))),t instanceof Uint8Array?Kn(r,t,e):Gc(r,t,e)}function kt(r,t=0){return r instanceof Uint8Array?$n(r,t):Fc(r,t)}var Vn=new Float32Array([-0]),Jt=new Uint8Array(Vn.buffer);function Li(r,t,e){Vn[0]=r,t[e]=Jt[0],t[e+1]=Jt[1],t[e+2]=Jt[2],t[e+3]=Jt[3]}function Bi(r,t){return Jt[0]=r[t],Jt[1]=r[t+1],Jt[2]=r[t+2],Jt[3]=r[t+3],Vn[0]}var Gn=new Float64Array([-0]),rt=new Uint8Array(Gn.buffer);function ki(r,t,e){Gn[0]=r,t[e]=rt[0],t[e+1]=rt[1],t[e+2]=rt[2],t[e+3]=rt[3],t[e+4]=rt[4],t[e+5]=rt[5],t[e+6]=rt[6],t[e+7]=rt[7]}function Ni(r,t){return rt[0]=r[t],rt[1]=r[t+1],rt[2]=r[t+2],rt[3]=r[t+3],rt[4]=r[t+4],rt[5]=r[t+5],rt[6]=r[t+6],rt[7]=r[t+7],Gn[0]}var zc=BigInt(Number.MAX_SAFE_INTEGER),Hc=BigInt(Number.MIN_SAFE_INTEGER),pt=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 de;if(t<zc&&t>Hc)return this.fromNumber(Number(t));let e=t<0n;e&&(t=-t);let n=t>>32n,o=t-(n<<32n);return e&&(n=~n|0n,o=~o|0n,++o>Pi&&(o=0n,++n>Pi&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(t){if(t===0)return de;let e=t<0;e&&(t=-t);let n=t>>>0,o=(t-n)/4294967296>>>0;return e&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new r(n,o)}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):de}},de=new pt(0,0);de.toBigInt=function(){return 0n};de.zzEncode=de.zzDecode=function(){return this};de.length=function(){return 1};var Pi=4294967296n;function Ci(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 Oi(r,t,e){if(e-t<1)return"";let o,i=[],s=0,c;for(;t<e;)c=r[t++],c<128?i[s++]=c:c>191&&c<224?i[s++]=(c&31)<<6|r[t++]&63:c>239&&c<365?(c=((c&7)<<18|(r[t++]&63)<<12|(r[t++]&63)<<6|r[t++]&63)-65536,i[s++]=55296+(c>>10),i[s++]=56320+(c&1023)):i[s++]=(c&15)<<12|(r[t++]&63)<<6|r[t++]&63,s>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,i)),s=0);return o!=null?(s>0&&o.push(String.fromCharCode.apply(String,i.slice(0,s))),o.join("")):String.fromCharCode.apply(String,i.slice(0,s))}function Fn(r,t,e){let n=e,o,i;for(let s=0;s<r.length;++s)o=r.charCodeAt(s),o<128?t[e++]=o:o<2048?(t[e++]=o>>6|192,t[e++]=o&63|128):(o&64512)===55296&&((i=r.charCodeAt(s+1))&64512)===56320?(o=65536+((o&1023)<<10)+(i&1023),++s,t[e++]=o>>18|240,t[e++]=o>>12&63|128,t[e++]=o>>6&63|128,t[e++]=o&63|128):(t[e++]=o>>12|224,t[e++]=o>>6&63|128,t[e++]=o&63|128);return e-n}function Nt(r,t){return RangeError(`index out of range: ${r.pos} + ${t??1} > ${r.len}`)}function mr(r,t){return(r[t-4]|r[t-3]<<8|r[t-2]<<16|r[t-1]<<24)>>>0}var zn=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,Nt(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 Nt(this,4);return mr(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Nt(this,4);return mr(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Nt(this,4);let t=Bi(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Nt(this,4);let t=Ni(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 Nt(this,t);return this.pos+=t,e===n?new Uint8Array(0):this.buf.subarray(e,n)}string(){let t=this.bytes();return Oi(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw Nt(this,t);this.pos+=t}else do if(this.pos>=this.len)throw Nt(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 pt(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 Nt(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 Nt(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 Nt(this,8);let t=mr(this.buf,this.pos+=4),e=mr(this.buf,this.pos+=4);return new pt(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=$n(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 Hn(r){return new zn(r instanceof Uint8Array?r:r.subarray())}function _(r,t,e){let n=Hn(r);return t.decode(n,void 0,e)}var ts=Y("node:buffer");var Xn={};at(Xn,{base10:()=>Qc});var pf=new Uint8Array(0);function Ui(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 vt(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 Ri(r){return new TextEncoder().encode(r)}function _i(r){return new TextDecoder().decode(r)}function qc(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 o=0;o<r.length;o++){var i=r.charAt(o),s=i.charCodeAt(0);if(e[s]!==255)throw new TypeError(i+" is ambiguous");e[s]=o}var c=r.length,a=r.charAt(0),l=Math.log(c)/Math.log(256),f=Math.log(256)/Math.log(c);function d(b){if(b instanceof Uint8Array||(ArrayBuffer.isView(b)?b=new Uint8Array(b.buffer,b.byteOffset,b.byteLength):Array.isArray(b)&&(b=Uint8Array.from(b))),!(b instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(b.length===0)return"";for(var m=0,u=0,p=0,y=b.length;p!==y&&b[p]===0;)p++,m++;for(var E=(y-p)*f+1>>>0,S=new Uint8Array(E);p!==y;){for(var k=b[p],B=0,v=E-1;(k!==0||B<u)&&v!==-1;v--,B++)k+=256*S[v]>>>0,S[v]=k%c>>>0,k=k/c>>>0;if(k!==0)throw new Error("Non-zero carry");u=B,p++}for(var T=E-u;T!==E&&S[T]===0;)T++;for(var N=a.repeat(m);T<E;++T)N+=r.charAt(S[T]);return N}function h(b){if(typeof b!="string")throw new TypeError("Expected String");if(b.length===0)return new Uint8Array;var m=0;if(b[m]!==" "){for(var u=0,p=0;b[m]===a;)u++,m++;for(var y=(b.length-m)*l+1>>>0,E=new Uint8Array(y);b[m];){var S=e[b.charCodeAt(m)];if(S===255)return;for(var k=0,B=y-1;(S!==0||k<p)&&B!==-1;B--,k++)S+=c*E[B]>>>0,E[B]=S%256>>>0,S=S/256>>>0;if(S!==0)throw new Error("Non-zero carry");p=k,m++}if(b[m]!==" "){for(var v=y-p;v!==y&&E[v]===0;)v++;for(var T=new Uint8Array(u+(y-v)),N=u;v!==y;)T[N++]=E[v++];return T}}}function g(b){var m=h(b);if(m)return m;throw new Error(`Non-${t} character`)}return{encode:d,decodeUnsafe:h,decode:g}}var Wc=qc,Yc=Wc,Ki=Yc;var qn=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")}},Wn=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 $i(this,t)}},Yn=class{decoders;constructor(t){this.decoders=t}or(t){return $i(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 $i(r,t){return new Yn({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var Zn=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,e,n,o){this.name=t,this.prefix=e,this.baseEncode=n,this.baseDecode=o,this.encoder=new qn(t,e,n),this.decoder=new Wn(t,e,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function ke({name:r,prefix:t,encode:e,decode:n}){return new Zn(r,t,e,n)}function jt({name:r,prefix:t,alphabet:e}){let{encode:n,decode:o}=Ki(e,r);return ke({prefix:t,name:r,encode:n,decode:i=>vt(o(i))})}function Zc(r,t,e,n){let o={};for(let f=0;f<t.length;++f)o[t[f]]=f;let i=r.length;for(;r[i-1]==="=";)--i;let s=new Uint8Array(i*e/8|0),c=0,a=0,l=0;for(let f=0;f<i;++f){let d=o[r[f]];if(d===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<e|d,c+=e,c>=8&&(c-=8,s[l++]=255&a>>c)}if(c>=e||255&a<<8-c)throw new SyntaxError("Unexpected end of data");return s}function Xc(r,t,e){let n=t[t.length-1]==="=",o=(1<<e)-1,i="",s=0,c=0;for(let a=0;a<r.length;++a)for(c=c<<8|r[a],s+=8;s>e;)s-=e,i+=t[o&c>>s];if(s!==0&&(i+=t[o&c<<e-s]),n)for(;i.length*e&7;)i+="=";return i}function G({name:r,prefix:t,bitsPerChar:e,alphabet:n}){return ke({prefix:t,name:r,encode(o){return Xc(o,n,e)},decode(o){return Zc(o,n,e,r)}})}var Qc=jt({prefix:"9",name:"base10",alphabet:"0123456789"});var Qn={};at(Qn,{base16:()=>Jc,base16upper:()=>jc});var Jc=G({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),jc=G({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Jn={};at(Jn,{base2:()=>ta});var ta=G({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var jn={};at(jn,{base256emoji:()=>ia});var Vi=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}"),ea=Vi.reduce((r,t,e)=>(r[e]=t,r),[]),ra=Vi.reduce((r,t,e)=>(r[t.codePointAt(0)]=e,r),[]);function na(r){return r.reduce((t,e)=>(t+=ea[e],t),"")}function oa(r){let t=[];for(let e of r){let n=ra[e.codePointAt(0)];if(n===void 0)throw new Error(`Non-base256emoji character: ${e}`);t.push(n)}return new Uint8Array(t)}var ia=ke({prefix:"\u{1F680}",name:"base256emoji",encode:na,decode:oa});var to={};at(to,{base32:()=>Pt,base32hex:()=>ua,base32hexpad:()=>fa,base32hexpadupper:()=>da,base32hexupper:()=>la,base32pad:()=>ca,base32padupper:()=>aa,base32upper:()=>sa,base32z:()=>ha});var Pt=G({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),sa=G({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),ca=G({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),aa=G({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),ua=G({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),la=G({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),fa=G({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),da=G({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),ha=G({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var eo={};at(eo,{base36:()=>pa,base36upper:()=>ma});var pa=jt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),ma=jt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var ro={};at(ro,{base58btc:()=>M,base58flickr:()=>ga});var M=jt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),ga=jt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var oo={};at(oo,{base64:()=>no,base64pad:()=>ya,base64url:()=>ba,base64urlpad:()=>wa});var no=G({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),ya=G({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),ba=G({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),wa=G({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var io={};at(io,{base8:()=>xa});var xa=G({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var so={};at(so,{identity:()=>Ea});var Ea=ke({prefix:"\0",name:"identity",encode:r=>_i(r),decode:r=>Ri(r)});var Nf=new TextEncoder,Pf=new TextDecoder;var ao={};at(ao,{identity:()=>$t});var Ia=zi,Gi=128,Aa=127,Ta=~Aa,La=Math.pow(2,31);function zi(r,t,e){t=t||[],e=e||0;for(var n=e;r>=La;)t[e++]=r&255|Gi,r/=128;for(;r&Ta;)t[e++]=r&255|Gi,r>>>=7;return t[e]=r|0,zi.bytes=e-n+1,t}var Ba=co,ka=128,Fi=127;function co(r,n){var e=0,n=n||0,o=0,i=n,s,c=r.length;do{if(i>=c)throw co.bytes=0,new RangeError("Could not decode varint");s=r[i++],e+=o<28?(s&Fi)<<o:(s&Fi)*Math.pow(2,o),o+=7}while(s>=ka);return co.bytes=i-n,e}var Na=Math.pow(2,7),Pa=Math.pow(2,14),Ca=Math.pow(2,21),Oa=Math.pow(2,28),Da=Math.pow(2,35),Ua=Math.pow(2,42),Ra=Math.pow(2,49),_a=Math.pow(2,56),Ma=Math.pow(2,63),Ka=function(r){return r<Na?1:r<Pa?2:r<Ca?3:r<Oa?4:r<Da?5:r<Ua?6:r<Ra?7:r<_a?8:r<Ma?9:10},$a={encode:Ia,decode:Ba,encodingLength:Ka},Va=$a,Je=Va;function je(r,t=0){return[Je.decode(r,t),Je.decode.bytes]}function Ne(r,t,e=0){return Je.encode(r,t,e),t}function Pe(r){return Je.encodingLength(r)}function he(r,t){let e=t.byteLength,n=Pe(r),o=n+Pe(e),i=new Uint8Array(o+e);return Ne(r,i,0),Ne(e,i,n),i.set(t,o),new Ce(r,e,t,i)}function Ct(r){let t=vt(r),[e,n]=je(t),[o,i]=je(t.subarray(n)),s=t.subarray(n+i);if(s.byteLength!==o)throw new Error("Incorrect length");return new Ce(e,o,s,t)}function Hi(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&Ui(r.bytes,e.bytes)}}var Ce=class{code;size;digest;bytes;constructor(t,e,n,o){this.code=t,this.size=e,this.digest=n,this.bytes=o}};var qi=0,Ga="identity",Wi=vt;function Fa(r){return he(qi,Wi(r))}var $t={code:qi,name:Ga,encode:Wi,digest:Fa};var po={};at(po,{sha256:()=>ho,sha512:()=>za});var fo=ht(Y("crypto"),1);function lo({name:r,code:t,encode:e}){return new uo(r,t,e)}var uo=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?he(this.code,e):e.then(n=>he(this.code,n))}else throw Error("Unknown type, must be binary type")}};var ho=lo({name:"sha2-256",code:18,encode:r=>vt(fo.default.createHash("sha256").update(r).digest())}),za=lo({name:"sha2-512",code:19,encode:r=>vt(fo.default.createHash("sha512").update(r).digest())});function Zi(r,t){let{bytes:e,version:n}=r;switch(n){case 0:return qa(e,mo(r),t??M.encoder);default:return Wa(e,mo(r),t??Pt.encoder)}}var Xi=new WeakMap;function mo(r){let t=Xi.get(r);if(t==null){let e=new Map;return Xi.set(r,e),e}return t}var Q=class r{code;version;multihash;bytes;"/";constructor(t,e,n,o){this.code=e,this.version=t,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:t,multihash:e}=this;if(t!==tr)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==Ya)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=he(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&&Hi(t.multihash,n.multihash)}toString(t){return Zi(this,t)}toJSON(){return{"/":Zi(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:o,multihash:i,bytes:s}=e;return new r(n,o,i,s??Qi(n,o,i.bytes))}else if(e[Za]===!0){let{version:n,multihash:o,code:i}=e,s=Ct(o);return r.create(n,i,s)}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!==tr)throw new Error(`Version 0 CID must use dag-pb (code: ${tr}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let o=Qi(t,e,n.bytes);return new r(t,e,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,tr,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,o=vt(t.subarray(n,n+e.multihashSize));if(o.byteLength!==e.multihashSize)throw new Error("Incorrect length");let i=o.subarray(e.multihashSize-e.digestSize),s=new Ce(e.multihashCode,e.digestSize,i,o);return[e.version===0?r.createV0(s):r.createV1(e.codec,s),t.subarray(e.size)]}static inspectBytes(t){let e=0,n=()=>{let[d,h]=je(t.subarray(e));return e+=h,d},o=n(),i=tr;if(o===18?(o=0,e=0):i=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let s=e,c=n(),a=n(),l=e+a,f=l-s;return{version:o,codec:i,multihashCode:c,digestSize:a,multihashSize:f,size:l}}static parse(t,e){let[n,o]=Ha(t,e),i=r.decode(o);if(i.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return mo(i).set(n,t),i}};function Ha(r,t){switch(r[0]){case"Q":{let e=t??M;return[M.prefix,e.decode(`${M.prefix}${r}`)]}case M.prefix:{let e=t??M;return[M.prefix,e.decode(r)]}case Pt.prefix:{let e=t??Pt;return[Pt.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 qa(r,t,e){let{prefix:n}=e;if(n!==M.prefix)throw Error(`Cannot string encode V0 in ${e.name} encoding`);let o=t.get(n);if(o==null){let i=e.encode(r).slice(1);return t.set(n,i),i}else return o}function Wa(r,t,e){let{prefix:n}=e,o=t.get(n);if(o==null){let i=e.encode(r);return t.set(n,i),i}else return o}var tr=112,Ya=18;function Qi(r,t,e){let n=Pe(r),o=n+Pe(t),i=new Uint8Array(o+e.byteLength);return Ne(r,i,0),Ne(t,i,n),i.set(e,o),i}var Za=Symbol.for("@ipld/js-cid/CID");var er={...so,...Jn,...io,...Xn,...Qn,...to,...eo,...ro,...oo,...jn},jf={...po,...ao};function ji(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var Ji=ji("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),go=ji("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=ut(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),Xa={utf8:Ji,"utf-8":Ji,hex:er.base16,latin1:go,ascii:go,binary:go,...er},yr=Xa;function Mt(r,t="utf8"){let e=yr[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return t==="utf8"||t==="utf-8"?fe(ts.Buffer.from(r,"utf-8")):e.decoder.decode(`${e.prefix}${r}`)}function yo(r){let t=r??8192,e=t>>>1,n,o=t;return function(s){if(s<1||s>e)return ut(s);o+s>t&&(n=ut(t),o=0);let c=n.subarray(o,o+=s);return o&7&&(o=(o|7)+1),c}}var pe=class{fn;len;next;val;constructor(t,e,n){this.fn=t,this.len=e,this.next=void 0,this.val=n}};function bo(){}var xo=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},Qa=yo();function Ja(r){return globalThis.Buffer!=null?ut(r):Qa(r)}var nr=class{len;head;tail;states;constructor(){this.len=0,this.head=new pe(bo,0,0),this.tail=this.head,this.states=null}_push(t,e,n){return this.tail=this.tail.next=new pe(t,e,n),this.len+=e,this}uint32(t){return this.len+=(this.tail=this.tail.next=new Eo((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(br,10,pt.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let e=pt.fromBigInt(t);return this._push(br,e.length(),e)}uint64Number(t){return this._push(Kn,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=pt.fromBigInt(t).zzEncode();return this._push(br,e.length(),e)}sint64Number(t){let e=pt.fromNumber(t).zzEncode();return this._push(br,e.length(),e)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(wo,1,t?1:0)}fixed32(t){return this._push(rr,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=pt.fromBigInt(t);return this._push(rr,4,e.lo)._push(rr,4,e.hi)}fixed64Number(t){let e=pt.fromNumber(t);return this._push(rr,4,e.lo)._push(rr,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(Li,4,t)}double(t){return this._push(ki,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(wo,1,0):this.uint32(e)._push(tu,e,t)}string(t){let e=Ci(t);return e!==0?this.uint32(e)._push(Fn,e,t):this._push(wo,1,0)}fork(){return this.states=new xo(this),this.head=this.tail=new pe(bo,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 pe(bo,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=Ja(this.len),n=0;for(;t!=null;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e}};function wo(r,t,e){t[e]=r&255}function ja(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var Eo=class extends pe{next;constructor(t,e){super(ja,t,e),this.next=void 0}};function br(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 rr(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 tu(r,t,e){t.set(r,e)}globalThis.Buffer!=null&&(nr.prototype.bytes=function(r){let t=r.length>>>0;return this.uint32(t),t>0&&this._push(eu,t,r),this},nr.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(ru,t,r),this});function eu(r,t,e){t.set(r,e)}function ru(r,t,e){r.length<40?Fn(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set(Mt(r),e)}function vo(){return new nr}function K(r,t){let e=vo();return t.encode(r,e,{lengthDelimited:!1}),e.finish()}var Oe;(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"})(Oe||(Oe={}));function wr(r,t,e,n){return{name:r,type:t,encode:e,decode:n}}function Ot(r){function t(o){if(r[o.toString()]==null)throw new Error("Invalid enum value");return r[o]}let e=function(i,s){let c=t(i);s.int32(c)},n=function(i){let s=i.int32();return t(s)};return wr("enum",Oe.VARINT,e,n)}function $(r,t){return wr("message",Oe.LENGTH_DELIMITED,r,t)}var St;(function(r){let t;(function(o){o.IDENTIFY="IDENTIFY",o.CONNECT="CONNECT",o.STREAM_OPEN="STREAM_OPEN",o.STREAM_HANDLER="STREAM_HANDLER",o.DHT="DHT",o.LIST_PEERS="LIST_PEERS",o.CONNMANAGER="CONNMANAGER",o.DISCONNECT="DISCONNECT",o.PUBSUB="PUBSUB",o.PEERSTORE="PEERSTORE"})(t=r.Type||(r.Type={}));let e;(function(o){o[o.IDENTIFY=0]="IDENTIFY",o[o.CONNECT=1]="CONNECT",o[o.STREAM_OPEN=2]="STREAM_OPEN",o[o.STREAM_HANDLER=3]="STREAM_HANDLER",o[o.DHT=4]="DHT",o[o.LIST_PEERS=5]="LIST_PEERS",o[o.CONNMANAGER=6]="CONNMANAGER",o[o.DISCONNECT=7]="DISCONNECT",o[o.PUBSUB=8]="PUBSUB",o[o.PEERSTORE=9]="PEERSTORE"})(e||(e={})),function(o){o.codec=()=>Ot(e)}(t=r.Type||(r.Type={}));let n;r.codec=()=>(n==null&&(n=$((o,i,s={})=>{s.lengthDelimited!==!1&&i.fork(),o.type!=null&&(i.uint32(8),r.Type.codec().encode(o.type,i)),o.connect!=null&&(i.uint32(18),Er.codec().encode(o.connect,i)),o.streamOpen!=null&&(i.uint32(26),vr.codec().encode(o.streamOpen,i)),o.streamHandler!=null&&(i.uint32(34),Sr.codec().encode(o.streamHandler,i)),o.dht!=null&&(i.uint32(42),It.codec().encode(o.dht,i)),o.connManager!=null&&(i.uint32(50),Ar.codec().encode(o.connManager,i)),o.disconnect!=null&&(i.uint32(58),Tr.codec().encode(o.disconnect,i)),o.pubsub!=null&&(i.uint32(66),Vt.codec().encode(o.pubsub,i)),o.peerStore!=null&&(i.uint32(74),me.codec().encode(o.peerStore,i)),s.lengthDelimited!==!1&&i.ldelim()},(o,i)=>{let s={},c=i==null?o.len:o.pos+i;for(;o.pos<c;){let a=o.uint32();switch(a>>>3){case 1:s.type=r.Type.codec().decode(o);break;case 2:s.connect=Er.codec().decode(o,o.uint32());break;case 3:s.streamOpen=vr.codec().decode(o,o.uint32());break;case 4:s.streamHandler=Sr.codec().decode(o,o.uint32());break;case 5:s.dht=It.codec().decode(o,o.uint32());break;case 6:s.connManager=Ar.codec().decode(o,o.uint32());break;case 7:s.disconnect=Tr.codec().decode(o,o.uint32());break;case 8:s.pubsub=Vt.codec().decode(o,o.uint32());break;case 9:s.peerStore=me.codec().decode(o,o.uint32());break;default:o.skipType(a&7);break}}return s})),n),r.encode=o=>K(o,r.codec()),r.decode=o=>_(o,r.codec())})(St||(St={}));var q;(function(r){let t;(function(o){o.OK="OK",o.ERROR="ERROR"})(t=r.Type||(r.Type={}));let e;(function(o){o[o.OK=0]="OK",o[o.ERROR=1]="ERROR"})(e||(e={})),function(o){o.codec=()=>Ot(e)}(t=r.Type||(r.Type={}));let n;r.codec=()=>(n==null&&(n=$((o,i,s={})=>{if(s.lengthDelimited!==!1&&i.fork(),o.type!=null&&(i.uint32(8),r.Type.codec().encode(o.type,i)),o.error!=null&&(i.uint32(18),Ir.codec().encode(o.error,i)),o.streamInfo!=null&&(i.uint32(26),De.codec().encode(o.streamInfo,i)),o.identify!=null&&(i.uint32(34),xr.codec().encode(o.identify,i)),o.dht!=null&&(i.uint32(42),tt.codec().encode(o.dht,i)),o.peers!=null)for(let c of o.peers)i.uint32(50),ee.codec().encode(c,i);o.pubsub!=null&&(i.uint32(58),Lr.codec().encode(o.pubsub,i)),o.peerStore!=null&&(i.uint32(66),Br.codec().encode(o.peerStore,i)),s.lengthDelimited!==!1&&i.ldelim()},(o,i)=>{let s={peers:[]},c=i==null?o.len:o.pos+i;for(;o.pos<c;){let a=o.uint32();switch(a>>>3){case 1:s.type=r.Type.codec().decode(o);break;case 2:s.error=Ir.codec().decode(o,o.uint32());break;case 3:s.streamInfo=De.codec().decode(o,o.uint32());break;case 4:s.identify=xr.codec().decode(o,o.uint32());break;case 5:s.dht=tt.codec().decode(o,o.uint32());break;case 6:s.peers.push(ee.codec().decode(o,o.uint32()));break;case 7:s.pubsub=Lr.codec().decode(o,o.uint32());break;case 8:s.peerStore=Br.codec().decode(o,o.uint32());break;default:o.skipType(a&7);break}}return s})),n),r.encode=o=>K(o,r.codec()),r.decode=o=>_(o,r.codec())})(q||(q={}));var xr;(function(r){let t;r.codec=()=>(t==null&&(t=$((e,n,o={})=>{if(o.lengthDelimited!==!1&&n.fork(),e.id!=null&&e.id.byteLength>0&&(n.uint32(10),n.bytes(e.id)),e.addrs!=null)for(let i of e.addrs)n.uint32(18),n.bytes(i);o.lengthDelimited!==!1&&n.ldelim()},(e,n)=>{let o={id:new Uint8Array(0),addrs:[]},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let s=e.uint32();switch(s>>>3){case 1:o.id=e.bytes();break;case 2:o.addrs.push(e.bytes());break;default:e.skipType(s&7);break}}return o})),t),r.encode=e=>K(e,r.codec()),r.decode=e=>_(e,r.codec())})(xr||(xr={}));var Er;(function(r){let t;r.codec=()=>(t==null&&(t=$((e,n,o={})=>{if(o.lengthDelimited!==!1&&n.fork(),e.peer!=null&&e.peer.byteLength>0&&(n.uint32(10),n.bytes(e.peer)),e.addrs!=null)for(let i of e.addrs)n.uint32(18),n.bytes(i);e.timeout!=null&&(n.uint32(24),n.int64(e.timeout)),o.lengthDelimited!==!1&&n.ldelim()},(e,n)=>{let o={peer:new Uint8Array(0),addrs:[]},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let s=e.uint32();switch(s>>>3){case 1:o.peer=e.bytes();break;case 2:o.addrs.push(e.bytes());break;case 3:o.timeout=e.int64();break;default:e.skipType(s&7);break}}return o})),t),r.encode=e=>K(e,r.codec()),r.decode=e=>_(e,r.codec())})(Er||(Er={}));var vr;(function(r){let t;r.codec=()=>(t==null&&(t=$((e,n,o={})=>{if(o.lengthDelimited!==!1&&n.fork(),e.peer!=null&&e.peer.byteLength>0&&(n.uint32(10),n.bytes(e.peer)),e.proto!=null)for(let i of e.proto)n.uint32(18),n.string(i);e.timeout!=null&&(n.uint32(24),n.int64(e.timeout)),o.lengthDelimited!==!1&&n.ldelim()},(e,n)=>{let o={peer:new Uint8Array(0),proto:[]},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let s=e.uint32();switch(s>>>3){case 1:o.peer=e.bytes();break;case 2:o.proto.push(e.string());break;case 3:o.timeout=e.int64();break;default:e.skipType(s&7);break}}return o})),t),r.encode=e=>K(e,r.codec()),r.decode=e=>_(e,r.codec())})(vr||(vr={}));var Sr;(function(r){let t;r.codec=()=>(t==null&&(t=$((e,n,o={})=>{if(o.lengthDelimited!==!1&&n.fork(),e.addr!=null&&e.addr.byteLength>0&&(n.uint32(10),n.bytes(e.addr)),e.proto!=null)for(let i of e.proto)n.uint32(18),n.string(i);o.lengthDelimited!==!1&&n.ldelim()},(e,n)=>{let o={addr:new Uint8Array(0),proto:[]},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let s=e.uint32();switch(s>>>3){case 1:o.addr=e.bytes();break;case 2:o.proto.push(e.string());break;default:e.skipType(s&7);break}}return o})),t),r.encode=e=>K(e,r.codec()),r.decode=e=>_(e,r.codec())})(Sr||(Sr={}));var Ir;(function(r){let t;r.codec=()=>(t==null&&(t=$((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.msg!=null&&e.msg!==""&&(n.uint32(10),n.string(e.msg)),o.lengthDelimited!==!1&&n.ldelim()},(e,n)=>{let o={msg:""},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let s=e.uint32();switch(s>>>3){case 1:o.msg=e.string();break;default:e.skipType(s&7);break}}return o})),t),r.encode=e=>K(e,r.codec()),r.decode=e=>_(e,r.codec())})(Ir||(Ir={}));var De;(function(r){let t;r.codec=()=>(t==null&&(t=$((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.peer!=null&&e.peer.byteLength>0&&(n.uint32(10),n.bytes(e.peer)),e.addr!=null&&e.addr.byteLength>0&&(n.uint32(18),n.bytes(e.addr)),e.proto!=null&&e.proto!==""&&(n.uint32(26),n.string(e.proto)),o.lengthDelimited!==!1&&n.ldelim()},(e,n)=>{let o={peer:new Uint8Array(0),addr:new Uint8Array(0),proto:""},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let s=e.uint32();switch(s>>>3){case 1:o.peer=e.bytes();break;case 2:o.addr=e.bytes();break;case 3:o.proto=e.string();break;default:e.skipType(s&7);break}}return o})),t),r.encode=e=>K(e,r.codec()),r.decode=e=>_(e,r.codec())})(De||(De={}));var It;(function(r){let t;(function(o){o.FIND_PEER="FIND_PEER",o.FIND_PEERS_CONNECTED_TO_PEER="FIND_PEERS_CONNECTED_TO_PEER",o.FIND_PROVIDERS="FIND_PROVIDERS",o.GET_CLOSEST_PEERS="GET_CLOSEST_PEERS",o.GET_PUBLIC_KEY="GET_PUBLIC_KEY",o.GET_VALUE="GET_VALUE",o.SEARCH_VALUE="SEARCH_VALUE",o.PUT_VALUE="PUT_VALUE",o.PROVIDE="PROVIDE"})(t=r.Type||(r.Type={}));let e;(function(o){o[o.FIND_PEER=0]="FIND_PEER",o[o.FIND_PEERS_CONNECTED_TO_PEER=1]="FIND_PEERS_CONNECTED_TO_PEER",o[o.FIND_PROVIDERS=2]="FIND_PROVIDERS",o[o.GET_CLOSEST_PEERS=3]="GET_CLOSEST_PEERS",o[o.GET_PUBLIC_KEY=4]="GET_PUBLIC_KEY",o[o.GET_VALUE=5]="GET_VALUE",o[o.SEARCH_VALUE=6]="SEARCH_VALUE",o[o.PUT_VALUE=7]="PUT_VALUE",o[o.PROVIDE=8]="PROVIDE"})(e||(e={})),function(o){o.codec=()=>Ot(e)}(t=r.Type||(r.Type={}));let n;r.codec=()=>(n==null&&(n=$((o,i,s={})=>{s.lengthDelimited!==!1&&i.fork(),o.type!=null&&(i.uint32(8),r.Type.codec().encode(o.type,i)),o.peer!=null&&(i.uint32(18),i.bytes(o.peer)),o.cid!=null&&(i.uint32(26),i.bytes(o.cid)),o.key!=null&&(i.uint32(34),i.bytes(o.key)),o.value!=null&&(i.uint32(42),i.bytes(o.value)),o.count!=null&&(i.uint32(48),i.int32(o.count)),o.timeout!=null&&(i.uint32(56),i.int64(o.timeout)),s.lengthDelimited!==!1&&i.ldelim()},(o,i)=>{let s={},c=i==null?o.len:o.pos+i;for(;o.pos<c;){let a=o.uint32();switch(a>>>3){case 1:s.type=r.Type.codec().decode(o);break;case 2:s.peer=o.bytes();break;case 3:s.cid=o.bytes();break;case 4:s.key=o.bytes();break;case 5:s.value=o.bytes();break;case 6:s.count=o.int32();break;case 7:s.timeout=o.int64();break;default:o.skipType(a&7);break}}return s})),n),r.encode=o=>K(o,r.codec()),r.decode=o=>_(o,r.codec())})(It||(It={}));var tt;(function(r){let t;(function(o){o.BEGIN="BEGIN",o.VALUE="VALUE",o.END="END"})(t=r.Type||(r.Type={}));let e;(function(o){o[o.BEGIN=0]="BEGIN",o[o.VALUE=1]="VALUE",o[o.END=2]="END"})(e||(e={})),function(o){o.codec=()=>Ot(e)}(t=r.Type||(r.Type={}));let n;r.codec=()=>(n==null&&(n=$((o,i,s={})=>{s.lengthDelimited!==!1&&i.fork(),o.type!=null&&(i.uint32(8),r.Type.codec().encode(o.type,i)),o.peer!=null&&(i.uint32(18),ee.codec().encode(o.peer,i)),o.value!=null&&(i.uint32(26),i.bytes(o.value)),s.lengthDelimited!==!1&&i.ldelim()},(o,i)=>{let s={},c=i==null?o.len:o.pos+i;for(;o.pos<c;){let a=o.uint32();switch(a>>>3){case 1:s.type=r.Type.codec().decode(o);break;case 2:s.peer=ee.codec().decode(o,o.uint32());break;case 3:s.value=o.bytes();break;default:o.skipType(a&7);break}}return s})),n),r.encode=o=>K(o,r.codec()),r.decode=o=>_(o,r.codec())})(tt||(tt={}));var ee;(function(r){let t;r.codec=()=>(t==null&&(t=$((e,n,o={})=>{if(o.lengthDelimited!==!1&&n.fork(),e.id!=null&&e.id.byteLength>0&&(n.uint32(10),n.bytes(e.id)),e.addrs!=null)for(let i of e.addrs)n.uint32(18),n.bytes(i);o.lengthDelimited!==!1&&n.ldelim()},(e,n)=>{let o={id:new Uint8Array(0),addrs:[]},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let s=e.uint32();switch(s>>>3){case 1:o.id=e.bytes();break;case 2:o.addrs.push(e.bytes());break;default:e.skipType(s&7);break}}return o})),t),r.encode=e=>K(e,r.codec()),r.decode=e=>_(e,r.codec())})(ee||(ee={}));var Ar;(function(r){let t;(function(o){o.TAG_PEER="TAG_PEER",o.UNTAG_PEER="UNTAG_PEER",o.TRIM="TRIM"})(t=r.Type||(r.Type={}));let e;(function(o){o[o.TAG_PEER=0]="TAG_PEER",o[o.UNTAG_PEER=1]="UNTAG_PEER",o[o.TRIM=2]="TRIM"})(e||(e={})),function(o){o.codec=()=>Ot(e)}(t=r.Type||(r.Type={}));let n;r.codec=()=>(n==null&&(n=$((o,i,s={})=>{s.lengthDelimited!==!1&&i.fork(),o.type!=null&&(i.uint32(8),r.Type.codec().encode(o.type,i)),o.peer!=null&&(i.uint32(18),i.bytes(o.peer)),o.tag!=null&&(i.uint32(26),i.string(o.tag)),o.weight!=null&&(i.uint32(32),i.int64(o.weight)),s.lengthDelimited!==!1&&i.ldelim()},(o,i)=>{let s={},c=i==null?o.len:o.pos+i;for(;o.pos<c;){let a=o.uint32();switch(a>>>3){case 1:s.type=r.Type.codec().decode(o);break;case 2:s.peer=o.bytes();break;case 3:s.tag=o.string();break;case 4:s.weight=o.int64();break;default:o.skipType(a&7);break}}return s})),n),r.encode=o=>K(o,r.codec()),r.decode=o=>_(o,r.codec())})(Ar||(Ar={}));var Tr;(function(r){let t;r.codec=()=>(t==null&&(t=$((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.peer!=null&&e.peer.byteLength>0&&(n.uint32(10),n.bytes(e.peer)),o.lengthDelimited!==!1&&n.ldelim()},(e,n)=>{let o={peer:new Uint8Array(0)},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let s=e.uint32();switch(s>>>3){case 1:o.peer=e.bytes();break;default:e.skipType(s&7);break}}return o})),t),r.encode=e=>K(e,r.codec()),r.decode=e=>_(e,r.codec())})(Tr||(Tr={}));var Vt;(function(r){let t;(function(o){o.GET_TOPICS="GET_TOPICS",o.LIST_PEERS="LIST_PEERS",o.PUBLISH="PUBLISH",o.SUBSCRIBE="SUBSCRIBE"})(t=r.Type||(r.Type={}));let e;(function(o){o[o.GET_TOPICS=0]="GET_TOPICS",o[o.LIST_PEERS=1]="LIST_PEERS",o[o.PUBLISH=2]="PUBLISH",o[o.SUBSCRIBE=3]="SUBSCRIBE"})(e||(e={})),function(o){o.codec=()=>Ot(e)}(t=r.Type||(r.Type={}));let n;r.codec=()=>(n==null&&(n=$((o,i,s={})=>{s.lengthDelimited!==!1&&i.fork(),o.type!=null&&(i.uint32(8),r.Type.codec().encode(o.type,i)),o.topic!=null&&(i.uint32(18),i.string(o.topic)),o.data!=null&&(i.uint32(26),i.bytes(o.data)),s.lengthDelimited!==!1&&i.ldelim()},(o,i)=>{let s={},c=i==null?o.len:o.pos+i;for(;o.pos<c;){let a=o.uint32();switch(a>>>3){case 1:s.type=r.Type.codec().decode(o);break;case 2:s.topic=o.string();break;case 3:s.data=o.bytes();break;default:o.skipType(a&7);break}}return s})),n),r.encode=o=>K(o,r.codec()),r.decode=o=>_(o,r.codec())})(Vt||(Vt={}));var or;(function(r){let t;r.codec=()=>(t==null&&(t=$((e,n,o={})=>{if(o.lengthDelimited!==!1&&n.fork(),e.from!=null&&(n.uint32(10),n.bytes(e.from)),e.data!=null&&(n.uint32(18),n.bytes(e.data)),e.seqno!=null&&(n.uint32(26),n.bytes(e.seqno)),e.topicIDs!=null)for(let i of e.topicIDs)n.uint32(34),n.string(i);e.signature!=null&&(n.uint32(42),n.bytes(e.signature)),e.key!=null&&(n.uint32(50),n.bytes(e.key)),o.lengthDelimited!==!1&&n.ldelim()},(e,n)=>{let o={topicIDs:[]},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let s=e.uint32();switch(s>>>3){case 1:o.from=e.bytes();break;case 2:o.data=e.bytes();break;case 3:o.seqno=e.bytes();break;case 4:o.topicIDs.push(e.string());break;case 5:o.signature=e.bytes();break;case 6:o.key=e.bytes();break;default:e.skipType(s&7);break}}return o})),t),r.encode=e=>K(e,r.codec()),r.decode=e=>_(e,r.codec())})(or||(or={}));var Lr;(function(r){let t;r.codec=()=>(t==null&&(t=$((e,n,o={})=>{if(o.lengthDelimited!==!1&&n.fork(),e.topics!=null)for(let i of e.topics)n.uint32(10),n.string(i);if(e.peerIDs!=null)for(let i of e.peerIDs)n.uint32(18),n.bytes(i);o.lengthDelimited!==!1&&n.ldelim()},(e,n)=>{let o={topics:[],peerIDs:[]},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let s=e.uint32();switch(s>>>3){case 1:o.topics.push(e.string());break;case 2:o.peerIDs.push(e.bytes());break;default:e.skipType(s&7);break}}return o})),t),r.encode=e=>K(e,r.codec()),r.decode=e=>_(e,r.codec())})(Lr||(Lr={}));var me;(function(r){let t;(function(o){o.UNSPECIFIED="UNSPECIFIED",o.GET_PROTOCOLS="GET_PROTOCOLS",o.GET_PEER_INFO="GET_PEER_INFO"})(t=r.Type||(r.Type={}));let e;(function(o){o[o.UNSPECIFIED=0]="UNSPECIFIED",o[o.GET_PROTOCOLS=1]="GET_PROTOCOLS",o[o.GET_PEER_INFO=2]="GET_PEER_INFO"})(e||(e={})),function(o){o.codec=()=>Ot(e)}(t=r.Type||(r.Type={}));let n;r.codec=()=>(n==null&&(n=$((o,i,s={})=>{if(s.lengthDelimited!==!1&&i.fork(),o.type!=null&&(i.uint32(8),r.Type.codec().encode(o.type,i)),o.id!=null&&(i.uint32(18),i.bytes(o.id)),o.protos!=null)for(let c of o.protos)i.uint32(26),i.string(c);s.lengthDelimited!==!1&&i.ldelim()},(o,i)=>{let s={protos:[]},c=i==null?o.len:o.pos+i;for(;o.pos<c;){let a=o.uint32();switch(a>>>3){case 1:s.type=r.Type.codec().decode(o);break;case 2:s.id=o.bytes();break;case 3:s.protos.push(o.string());break;default:o.skipType(a&7);break}}return s})),n),r.encode=o=>K(o,r.codec()),r.decode=o=>_(o,r.codec())})(me||(me={}));var Br;(function(r){let t;r.codec=()=>(t==null&&(t=$((e,n,o={})=>{if(o.lengthDelimited!==!1&&n.fork(),e.peer!=null&&(n.uint32(10),ee.codec().encode(e.peer,n)),e.protos!=null)for(let i of e.protos)n.uint32(18),n.string(i);o.lengthDelimited!==!1&&n.ldelim()},(e,n)=>{let o={protos:[]},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let s=e.uint32();switch(s>>>3){case 1:o.peer=ee.codec().decode(e,e.uint32());break;case 2:o.protos.push(e.string());break;default:e.skipType(s&7);break}}return o})),t),r.encode=e=>K(e,r.codec()),r.decode=e=>_(e,r.codec())})(Br||(Br={}));var So={upgradeInbound:async r=>r,upgradeOutbound:async r=>r};var ns=ht(Y("node:tty"),1),Dr=ht(Y("node:util"),1);function nu(r,t){try{if(typeof r=="string"&&r.length>0)return ou(r);if(typeof r=="number"&&isFinite(r))return t?.long?su(r):iu(r);throw new Error("Value is not a string or number.")}catch(e){let n=cu(e)?`${e.message}. value=${JSON.stringify(r)}`:"An unknown error has occured.";throw new Error(n)}}function ou(r){if(r=String(r),r.length>100)throw new Error("Value exceeds the maximum length of 100 characters.");let 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)return NaN;let e=parseFloat(t[1]),n=(t[2]||"ms").toLowerCase();switch(n){case"years":case"year":case"yrs":case"yr":case"y":return e*315576e5;case"weeks":case"week":case"w":return e*6048e5;case"days":case"day":case"d":return e*864e5;case"hours":case"hour":case"hrs":case"hr":case"h":return e*36e5;case"minutes":case"minute":case"mins":case"min":case"m":return e*6e4;case"seconds":case"second":case"secs":case"sec":case"s":return e*1e3;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return e;default:throw new Error(`The unit ${n} was matched, but no matching case exists.`)}}var Nr=nu;function iu(r){let t=Math.abs(r);return t>=864e5?`${Math.round(r/864e5)}d`:t>=36e5?`${Math.round(r/36e5)}h`:t>=6e4?`${Math.round(r/6e4)}m`:t>=1e3?`${Math.round(r/1e3)}s`:`${r}ms`}function su(r){let t=Math.abs(r);return t>=864e5?kr(r,t,864e5,"day"):t>=36e5?kr(r,t,36e5,"hour"):t>=6e4?kr(r,t,6e4,"minute"):t>=1e3?kr(r,t,1e3,"second"):`${r} ms`}function kr(r,t,e,n){let o=t>=e*1.5;return`${Math.round(r/e)} ${n}${o?"s":""}`}function cu(r){return typeof r=="object"&&r!==null&&"message"in r}var Cr=ht(Y("node:process"),1),rs=ht(Y("node:os"),1),Io=ht(Y("node:tty"),1);function At(r,t=globalThis.Deno?globalThis.Deno.args:Cr.default.argv){let e=r.startsWith("-")?"":r.length===1?"-":"--",n=t.indexOf(e+r),o=t.indexOf("--");return n!==-1&&(o===-1||n<o)}var{env:V}=Cr.default,Pr;At("no-color")||At("no-colors")||At("color=false")||At("color=never")?Pr=0:(At("color")||At("colors")||At("color=true")||At("color=always"))&&(Pr=1);function au(){if("FORCE_COLOR"in V)return V.FORCE_COLOR==="true"?1:V.FORCE_COLOR==="false"?0:V.FORCE_COLOR.length===0?1:Math.min(Number.parseInt(V.FORCE_COLOR,10),3)}function uu(r){return r===0?!1:{level:r,hasBasic:!0,has256:r>=2,has16m:r>=3}}function lu(r,{streamIsTTY:t,sniffFlags:e=!0}={}){let n=au();n!==void 0&&(Pr=n);let o=e?Pr:n;if(o===0)return 0;if(e){if(At("color=16m")||At("color=full")||At("color=truecolor"))return 3;if(At("color=256"))return 2}if("TF_BUILD"in V&&"AGENT_NAME"in V)return 1;if(r&&!t&&o===void 0)return 0;let i=o||0;if(V.TERM==="dumb")return i;if(Cr.default.platform==="win32"){let s=rs.default.release().split(".");return Number(s[0])>=10&&Number(s[2])>=10586?Number(s[2])>=14931?3:2:1}if("CI"in V)return"GITHUB_ACTIONS"in V||"GITEA_ACTIONS"in V?3:["TRAVIS","CIRCLECI","APPVEYOR","GITLAB_CI","BUILDKITE","DRONE"].some(s=>s in V)||V.CI_NAME==="codeship"?1:i;if("TEAMCITY_VERSION"in V)return/^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(V.TEAMCITY_VERSION)?1:0;if(V.COLORTERM==="truecolor"||V.TERM==="xterm-kitty")return 3;if("TERM_PROGRAM"in V){let s=Number.parseInt((V.TERM_PROGRAM_VERSION||"").split(".")[0],10);switch(V.TERM_PROGRAM){case"iTerm.app":return s>=3?3:2;case"Apple_Terminal":return 2}}return/-256(color)?$/i.test(V.TERM)?2:/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(V.TERM)||"COLORTERM"in V?1:i}function es(r,t={}){let e=lu(r,{streamIsTTY:r&&r.isTTY,...t});return uu(e)}var fu={stdout:es({isTTY:Io.default.isatty(1)}),stderr:es({isTTY:Io.default.isatty(2)})},Or=fu;function Ao(r){e.debug=e,e.default=e,e.coerce=a,e.disable=i,e.enable=o,e.enabled=s,e.humanize=Nr,e.destroy=l,Object.keys(r).forEach(f=>{e[f]=r[f]}),e.names=[],e.skips=[],e.formatters={};function t(f){let d=0;for(let h=0;h<f.length;h++)d=(d<<5)-d+f.charCodeAt(h),d|=0;return e.colors[Math.abs(d)%e.colors.length]}e.selectColor=t;function e(f){let d,h=null,g,b;function m(...u){if(!m.enabled)return;let p=m,y=Number(new Date),E=y-(d||y);p.diff=E,p.prev=d,p.curr=y,d=y,u[0]=e.coerce(u[0]),typeof u[0]!="string"&&u.unshift("%O");let S=0;u[0]=u[0].replace(/%([a-zA-Z%])/g,(B,v)=>{if(B==="%%")return"%";S++;let T=e.formatters[v];if(typeof T=="function"){let N=u[S];B=T.call(p,N),u.splice(S,1),S--}return B}),e.formatArgs.call(p,u),(p.log||e.log).apply(p,u)}return m.namespace=f,m.useColors=e.useColors(),m.color=e.selectColor(f),m.extend=n,m.destroy=e.destroy,Object.defineProperty(m,"enabled",{enumerable:!0,configurable:!1,get:()=>h!==null?h:(g!==e.namespaces&&(g=e.namespaces,b=e.enabled(f)),b),set:u=>{h=u}}),typeof e.init=="function"&&e.init(m),m}function n(f,d){let h=e(this.namespace+(typeof d>"u"?":":d)+f);return h.log=this.log,h}function o(f){e.save(f),e.namespaces=f,e.names=[],e.skips=[];let d,h=(typeof f=="string"?f:"").split(/[\s,]+/),g=h.length;for(d=0;d<g;d++)h[d]&&(f=h[d].replace(/\*/g,".*?"),f[0]==="-"?e.skips.push(new RegExp("^"+f.substr(1)+"$")):e.names.push(new RegExp("^"+f+"$")))}function i(){let f=[...e.names.map(c),...e.skips.map(c).map(d=>"-"+d)].join(",");return e.enable(""),f}function s(f){if(f[f.length-1]==="*")return!0;let d,h;for(d=0,h=e.skips.length;d<h;d++)if(e.skips[d].test(f))return!1;for(d=0,h=e.names.length;d<h;d++)if(e.names[d].test(f))return!0;return!1}function c(f){return f.toString().substring(2,f.toString().length-2).replace(/\.\*\?$/,"*")}function a(f){return f instanceof Error?f.stack??f.message:f}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.setupFormatters(e.formatters),e.enable(e.load()),e}var os=[6,2,3,4,5,1];Or.stderr!==!1&&(Or.stderr??Or).level>=2&&(os=[20,21,26,27,32,33,38,39,40,41,42,43,44,45,56,57,62,63,68,69,74,75,76,77,78,79,80,81,92,93,98,99,112,113,128,129,134,135,148,149,160,161,162,163,164,165,166,167,168,169,170,171,172,173,178,179,184,185,196,197,198,199,200,201,202,203,204,205,206,207,208,209,214,215,220,221]);var Ue=Object.keys(process.env).filter(r=>/^debug_/i.test(r)).reduce((r,t)=>{let e=t.substring(6).toLowerCase().replace(/_([a-z])/g,(o,i)=>i.toUpperCase()),n=process.env[t];return/^(yes|on|true|enabled)$/i.test(n)?n=!0:/^(no|off|false|disabled)$/i.test(n)?n=!1:n==="null"?n=null:n=Number(n),r[e]=n,r},{});function du(){return"colors"in Ue?!!Ue.colors:ns.default.isatty(process.stderr.fd)}function hu(r){let{namespace:t,useColors:e}=this;if(e!=null){let n=this.color,o="\x1B[3"+(n<8?n:"8;5;"+n),i=` ${o};1m${t} \x1B[0m`;r[0]=i+r[0].split(`
3
3
  `).join(`
4
- `+i),r.push(n+"m+"+Ue.exports.humanize(this.diff)+"\x1B[0m")}else r[0]=cc()+t+" "+r[0]}function cc(){return O.inspectOpts.hideDate?"":new Date().toISOString()+" "}function ac(...r){return process.stderr.write(_e.formatWithOptions(O.inspectOpts,...r)+`
5
- `)}function uc(r){r?process.env.DEBUG=r:delete process.env.DEBUG}function lc(){return process.env.DEBUG}function dc(r){r.inspectOpts={};let t=Object.keys(O.inspectOpts);for(let e=0;e<t.length;e++)r.inspectOpts[t[e]]=O.inspectOpts[t[e]]}Ue.exports=Qr()(O);var{formatters:go}=Ue.exports;go.o=function(r){return this.inspectOpts.colors=this.useColors,_e.inspect(r,this.inspectOpts).split(`
6
- `).map(t=>t.trim()).join(" ")};go.O=function(r){return this.inspectOpts.colors=this.useColors,_e.inspect(r,this.inspectOpts)}});var bo=bt((Xu,Zr)=>{typeof process>"u"||process.type==="renderer"||process.browser===!0||process.__nwjs?Zr.exports=lo():Zr.exports=yo()});var di=bt((ih,li)=>{"use strict";function ui(r,t){for(let e in t)Object.defineProperty(r,e,{value:t[e],enumerable:!0,configurable:!0});return r}function Zc(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 ui(r,e)}catch{e.message=r.message,e.stack=r.stack;let n=function(){};return n.prototype=Object.create(Object.getPrototypeOf(r)),ui(new n,e)}}li.exports=Zc});var la={};J(la,{Server:()=>sr,createServer:()=>ua});var cr=H("node:buffer");function Tt(r){return new Uint8Array(r.buffer,r.byteOffset,r.byteLength)}function ht(r=0){return Tt(cr.Buffer.alloc(r))}function W(r=0){return Tt(cr.Buffer.allocUnsafe(r))}var vi=Math.pow(2,7),Si=Math.pow(2,14),Ti=Math.pow(2,21),ar=Math.pow(2,28),ur=Math.pow(2,35),lr=Math.pow(2,42),dr=Math.pow(2,49),x=128,M=127;function v(r){if(r<vi)return 1;if(r<Si)return 2;if(r<Ti)return 3;if(r<ar)return 4;if(r<ur)return 5;if(r<lr)return 6;if(r<dr)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function fr(r,t,e=0){switch(v(r)){case 8:t[e++]=r&255|x,r/=128;case 7:t[e++]=r&255|x,r/=128;case 6:t[e++]=r&255|x,r/=128;case 5:t[e++]=r&255|x,r/=128;case 4:t[e++]=r&255|x,r>>>=7;case 3:t[e++]=r&255|x,r>>>=7;case 2:t[e++]=r&255|x,r>>>=7;case 1:{t[e++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return t}function Li(r,t,e=0){switch(v(r)){case 8:t.set(e++,r&255|x),r/=128;case 7:t.set(e++,r&255|x),r/=128;case 6:t.set(e++,r&255|x),r/=128;case 5:t.set(e++,r&255|x),r/=128;case 4:t.set(e++,r&255|x),r>>>=7;case 3:t.set(e++,r&255|x),r>>>=7;case 2:t.set(e++,r&255|x),r>>>=7;case 1:{t.set(e++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return t}function hr(r,t){let e=r[t],o=0;if(o+=e&M,e<x||(e=r[t+1],o+=(e&M)<<7,e<x)||(e=r[t+2],o+=(e&M)<<14,e<x)||(e=r[t+3],o+=(e&M)<<21,e<x)||(e=r[t+4],o+=(e&M)*ar,e<x)||(e=r[t+5],o+=(e&M)*ur,e<x)||(e=r[t+6],o+=(e&M)*lr,e<x)||(e=r[t+7],o+=(e&M)*dr,e<x))return o;throw new RangeError("Could not decode varint")}function Ni(r,t){let e=r.get(t),o=0;if(o+=e&M,e<x||(e=r.get(t+1),o+=(e&M)<<7,e<x)||(e=r.get(t+2),o+=(e&M)<<14,e<x)||(e=r.get(t+3),o+=(e&M)<<21,e<x)||(e=r.get(t+4),o+=(e&M)*ar,e<x)||(e=r.get(t+5),o+=(e&M)*ur,e<x)||(e=r.get(t+6),o+=(e&M)*lr,e<x)||(e=r.get(t+7),o+=(e&M)*dr,e<x))return o;throw new RangeError("Could not decode varint")}function ft(r,t,e=0){return t==null&&(t=W(v(r))),t instanceof Uint8Array?fr(r,t,e):Li(r,t,e)}function at(r,t=0){return r instanceof Uint8Array?hr(r,t):Ni(r,t)}var pr=new Float32Array([-0]),wt=new Uint8Array(pr.buffer);function kn(r,t,e){pr[0]=r,t[e]=wt[0],t[e+1]=wt[1],t[e+2]=wt[2],t[e+3]=wt[3]}function On(r,t){return wt[0]=r[t],wt[1]=r[t+1],wt[2]=r[t+2],wt[3]=r[t+3],pr[0]}var mr=new Float64Array([-0]),B=new Uint8Array(mr.buffer);function _n(r,t,e){mr[0]=r,t[e]=B[0],t[e+1]=B[1],t[e+2]=B[2],t[e+3]=B[3],t[e+4]=B[4],t[e+5]=B[5],t[e+6]=B[6],t[e+7]=B[7]}function Un(r,t){return B[0]=r[t],B[1]=r[t+1],B[2]=r[t+2],B[3]=r[t+3],B[4]=r[t+4],B[5]=r[t+5],B[6]=r[t+6],B[7]=r[t+7],mr[0]}var Ri=BigInt(Number.MAX_SAFE_INTEGER),Di=BigInt(Number.MIN_SAFE_INTEGER),Z=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,o=~this.hi>>>0;return e===0&&(o=o+1>>>0),-(e+o*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,o=~this.hi>>>0;return e===0&&(o=o+1>>>0),-(BigInt(e)+(BigInt(o)<<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,o=this.hi>>>24;return o===0?e===0?t<16384?t<128?1:2:t<2097152?3:4:e<16384?e<128?5:6:e<2097152?7:8:o<128?9:10}static fromBigInt(t){if(t===0n)return Lt;if(t<Ri&&t>Di)return this.fromNumber(Number(t));let e=t<0n;e&&(t=-t);let o=t>>32n,n=t-(o<<32n);return e&&(o=~o|0n,n=~n|0n,++n>Fn&&(n=0n,++o>Fn&&(o=0n))),new r(Number(n),Number(o))}static fromNumber(t){if(t===0)return Lt;let e=t<0;e&&(t=-t);let o=t>>>0,n=(t-o)/4294967296>>>0;return e&&(n=~n>>>0,o=~o>>>0,++o>4294967295&&(o=0,++n>4294967295&&(n=0))),new r(o,n)}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):Lt}},Lt=new Z(0,0);Lt.toBigInt=function(){return 0n};Lt.zzEncode=Lt.zzDecode=function(){return this};Lt.length=function(){return 1};var Fn=4294967296n;function Mn(r){let t=0,e=0;for(let o=0;o<r.length;++o)e=r.charCodeAt(o),e<128?t+=1:e<2048?t+=2:(e&64512)===55296&&(r.charCodeAt(o+1)&64512)===56320?(++o,t+=4):t+=3;return t}function Bn(r,t,e){if(e-t<1)return"";let n,i=[],s=0,c;for(;t<e;)c=r[t++],c<128?i[s++]=c:c>191&&c<224?i[s++]=(c&31)<<6|r[t++]&63:c>239&&c<365?(c=((c&7)<<18|(r[t++]&63)<<12|(r[t++]&63)<<6|r[t++]&63)-65536,i[s++]=55296+(c>>10),i[s++]=56320+(c&1023)):i[s++]=(c&15)<<12|(r[t++]&63)<<6|r[t++]&63,s>8191&&((n??(n=[])).push(String.fromCharCode.apply(String,i)),s=0);return n!=null?(s>0&&n.push(String.fromCharCode.apply(String,i.slice(0,s))),n.join("")):String.fromCharCode.apply(String,i.slice(0,s))}function gr(r,t,e){let o=e,n,i;for(let s=0;s<r.length;++s)n=r.charCodeAt(s),n<128?t[e++]=n:n<2048?(t[e++]=n>>6|192,t[e++]=n&63|128):(n&64512)===55296&&((i=r.charCodeAt(s+1))&64512)===56320?(n=65536+((n&1023)<<10)+(i&1023),++s,t[e++]=n>>18|240,t[e++]=n>>12&63|128,t[e++]=n>>6&63|128,t[e++]=n&63|128):(t[e++]=n>>12|224,t[e++]=n>>6&63|128,t[e++]=n&63|128);return e-o}function ut(r,t){return RangeError(`index out of range: ${r.pos} + ${t??1} > ${r.len}`)}function be(r,t){return(r[t-4]|r[t-3]<<8|r[t-2]<<16|r[t-1]<<24)>>>0}var yr=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,ut(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 ut(this,4);return be(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw ut(this,4);return be(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw ut(this,4);let t=On(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw ut(this,4);let t=Un(this.buf,this.pos);return this.pos+=8,t}bytes(){let t=this.uint32(),e=this.pos,o=this.pos+t;if(o>this.len)throw ut(this,t);return this.pos+=t,e===o?new Uint8Array(0):this.buf.subarray(e,o)}string(){let t=this.bytes();return Bn(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw ut(this,t);this.pos+=t}else do if(this.pos>=this.len)throw ut(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 Z(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 ut(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 ut(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 ut(this,8);let t=be(this.buf,this.pos+=4),e=be(this.buf,this.pos+=4);return new Z(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=hr(this.buf,this.pos);return this.pos+=v(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 br(r){return new yr(r instanceof Uint8Array?r:r.subarray())}function S(r,t,e){let o=br(r);return t.decode(o,void 0,e)}var so=H("node:buffer");var Ar={};J(Ar,{base10:()=>Fi});var Ca=new Uint8Array(0);function Vn(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 nt(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 $n(r){return new TextEncoder().encode(r)}function zn(r){return new TextDecoder().decode(r)}function Pi(r,t){if(r.length>=255)throw new TypeError("Alphabet too long");for(var e=new Uint8Array(256),o=0;o<e.length;o++)e[o]=255;for(var n=0;n<r.length;n++){var i=r.charAt(n),s=i.charCodeAt(0);if(e[s]!==255)throw new TypeError(i+" is ambiguous");e[s]=n}var c=r.length,a=r.charAt(0),f=Math.log(c)/Math.log(256),u=Math.log(256)/Math.log(c);function l(p){if(p instanceof Uint8Array||(ArrayBuffer.isView(p)?p=new Uint8Array(p.buffer,p.byteOffset,p.byteLength):Array.isArray(p)&&(p=Uint8Array.from(p))),!(p instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(p.length===0)return"";for(var y=0,h=0,w=0,E=p.length;w!==E&&p[w]===0;)w++,y++;for(var R=(E-w)*u+1>>>0,k=new Uint8Array(R);w!==E;){for(var Y=p[w],et=0,Q=R-1;(Y!==0||et<h)&&Q!==-1;Q--,et++)Y+=256*k[Q]>>>0,k[Q]=Y%c>>>0,Y=Y/c>>>0;if(Y!==0)throw new Error("Non-zero carry");h=et,w++}for(var rt=R-h;rt!==R&&k[rt]===0;)rt++;for(var Vt=a.repeat(y);rt<R;++rt)Vt+=r.charAt(k[rt]);return Vt}function g(p){if(typeof p!="string")throw new TypeError("Expected String");if(p.length===0)return new Uint8Array;var y=0;if(p[y]!==" "){for(var h=0,w=0;p[y]===a;)h++,y++;for(var E=(p.length-y)*f+1>>>0,R=new Uint8Array(E);p[y];){var k=e[p.charCodeAt(y)];if(k===255)return;for(var Y=0,et=E-1;(k!==0||Y<w)&&et!==-1;et--,Y++)k+=c*R[et]>>>0,R[et]=k%256>>>0,k=k/256>>>0;if(k!==0)throw new Error("Non-zero carry");w=Y,y++}if(p[y]!==" "){for(var Q=E-w;Q!==E&&R[Q]===0;)Q++;for(var rt=new Uint8Array(h+(E-Q)),Vt=h;Q!==E;)rt[Vt++]=R[Q++];return rt}}}function b(p){var y=g(p);if(y)return y;throw new Error(`Non-${t} character`)}return{encode:l,decodeUnsafe:g,decode:b}}var ki=Pi,Oi=ki,Wn=Oi;var wr=class{name;prefix;baseEncode;constructor(t,e,o){this.name=t,this.prefix=e,this.baseEncode=o}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},Er=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,e,o){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=o}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 Kn(this,t)}},xr=class{decoders;constructor(t){this.decoders=t}or(t){return Kn(this,t)}decode(t){let e=t[0],o=this.decoders[e];if(o!=null)return o.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function Kn(r,t){return new xr({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var Ir=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,e,o,n){this.name=t,this.prefix=e,this.baseEncode=o,this.baseDecode=n,this.encoder=new wr(t,e,o),this.decoder=new Er(t,e,n)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function $t({name:r,prefix:t,encode:e,decode:o}){return new Ir(r,t,e,o)}function Et({name:r,prefix:t,alphabet:e}){let{encode:o,decode:n}=Wn(e,r);return $t({prefix:t,name:r,encode:o,decode:i=>nt(n(i))})}function _i(r,t,e,o){let n={};for(let u=0;u<t.length;++u)n[t[u]]=u;let i=r.length;for(;r[i-1]==="=";)--i;let s=new Uint8Array(i*e/8|0),c=0,a=0,f=0;for(let u=0;u<i;++u){let l=n[r[u]];if(l===void 0)throw new SyntaxError(`Non-${o} character`);a=a<<e|l,c+=e,c>=8&&(c-=8,s[f++]=255&a>>c)}if(c>=e||255&a<<8-c)throw new SyntaxError("Unexpected end of data");return s}function Ui(r,t,e){let o=t[t.length-1]==="=",n=(1<<e)-1,i="",s=0,c=0;for(let a=0;a<r.length;++a)for(c=c<<8|r[a],s+=8;s>e;)s-=e,i+=t[n&c>>s];if(s!==0&&(i+=t[n&c<<e-s]),o)for(;i.length*e&7;)i+="=";return i}function A({name:r,prefix:t,bitsPerChar:e,alphabet:o}){return $t({prefix:t,name:r,encode(n){return Ui(n,o,e)},decode(n){return _i(n,o,e,r)}})}var Fi=Et({prefix:"9",name:"base10",alphabet:"0123456789"});var Cr={};J(Cr,{base16:()=>Mi,base16upper:()=>Bi});var Mi=A({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Bi=A({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var vr={};J(vr,{base2:()=>Gi});var Gi=A({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Sr={};J(Sr,{base256emoji:()=>Wi});var Xn=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}"),Vi=Xn.reduce((r,t,e)=>(r[e]=t,r),[]),$i=Xn.reduce((r,t,e)=>(r[t.codePointAt(0)]=e,r),[]);function zi(r){return r.reduce((t,e)=>(t+=Vi[e],t),"")}function Hi(r){let t=[];for(let e of r){let o=$i[e.codePointAt(0)];if(o===void 0)throw new Error(`Non-base256emoji character: ${e}`);t.push(o)}return new Uint8Array(t)}var Wi=$t({prefix:"\u{1F680}",name:"base256emoji",encode:zi,decode:Hi});var Tr={};J(Tr,{base32:()=>lt,base32hex:()=>Qi,base32hexpad:()=>Zi,base32hexpadupper:()=>qi,base32hexupper:()=>Ji,base32pad:()=>Xi,base32padupper:()=>Yi,base32upper:()=>Ki,base32z:()=>ji});var lt=A({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Ki=A({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Xi=A({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Yi=A({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Qi=A({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Ji=A({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Zi=A({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),qi=A({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),ji=A({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Lr={};J(Lr,{base36:()=>ts,base36upper:()=>es});var ts=Et({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),es=Et({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Nr={};J(Nr,{base58btc:()=>D,base58flickr:()=>rs});var D=Et({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),rs=Et({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Dr={};J(Dr,{base64:()=>Rr,base64pad:()=>ns,base64url:()=>os,base64urlpad:()=>is});var Rr=A({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),ns=A({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),os=A({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),is=A({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Pr={};J(Pr,{base8:()=>ss});var ss=A({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var kr={};J(kr,{identity:()=>cs});var cs=$t({prefix:"\0",name:"identity",encode:r=>zn(r),decode:r=>$n(r)});var Ga=new TextEncoder,Va=new TextDecoder;var _r={};J(_r,{identity:()=>ce});var ls=Jn,Yn=128,ds=127,fs=~ds,hs=Math.pow(2,31);function Jn(r,t,e){t=t||[],e=e||0;for(var o=e;r>=hs;)t[e++]=r&255|Yn,r/=128;for(;r&fs;)t[e++]=r&255|Yn,r>>>=7;return t[e]=r|0,Jn.bytes=e-o+1,t}var ps=Or,ms=128,Qn=127;function Or(r,o){var e=0,o=o||0,n=0,i=o,s,c=r.length;do{if(i>=c)throw Or.bytes=0,new RangeError("Could not decode varint");s=r[i++],e+=n<28?(s&Qn)<<n:(s&Qn)*Math.pow(2,n),n+=7}while(s>=ms);return Or.bytes=i-o,e}var gs=Math.pow(2,7),ys=Math.pow(2,14),bs=Math.pow(2,21),ws=Math.pow(2,28),Es=Math.pow(2,35),xs=Math.pow(2,42),Is=Math.pow(2,49),As=Math.pow(2,56),Cs=Math.pow(2,63),vs=function(r){return r<gs?1:r<ys?2:r<bs?3:r<ws?4:r<Es?5:r<xs?6:r<Is?7:r<As?8:r<Cs?9:10},Ss={encode:ls,decode:ps,encodingLength:vs},Ts=Ss,ie=Ts;function se(r,t=0){return[ie.decode(r,t),ie.decode.bytes]}function zt(r,t,e=0){return ie.encode(r,t,e),t}function Ht(r){return ie.encodingLength(r)}function xt(r,t){let e=t.byteLength,o=Ht(r),n=o+Ht(e),i=new Uint8Array(n+e);return zt(r,i,0),zt(e,i,o),i.set(t,n),new Wt(r,e,t,i)}function Nt(r){let t=nt(r),[e,o]=se(t),[n,i]=se(t.subarray(o)),s=t.subarray(o+i);if(s.byteLength!==n)throw new Error("Incorrect length");return new Wt(e,n,s,t)}function Zn(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&Vn(r.bytes,e.bytes)}}var Wt=class{code;size;digest;bytes;constructor(t,e,o,n){this.code=t,this.size=e,this.digest=o,this.bytes=n}};var qn=0,Ls="identity",jn=nt;function Ns(r){return xt(qn,jn(r))}var ce={code:qn,name:Ls,encode:jn,digest:Ns};var Br={};J(Br,{sha256:()=>Ee,sha512:()=>Rs});var Mr=St(H("crypto"),1);function Fr({name:r,code:t,encode:e}){return new Ur(r,t,e)}var Ur=class{name;code;encode;constructor(t,e,o){this.name=t,this.code=e,this.encode=o}digest(t){if(t instanceof Uint8Array){let e=this.encode(t);return e instanceof Uint8Array?xt(this.code,e):e.then(o=>xt(this.code,o))}else throw Error("Unknown type, must be binary type")}};var Ee=Fr({name:"sha2-256",code:18,encode:r=>nt(Mr.default.createHash("sha256").update(r).digest())}),Rs=Fr({name:"sha2-512",code:19,encode:r=>nt(Mr.default.createHash("sha512").update(r).digest())});function eo(r,t){let{bytes:e,version:o}=r;switch(o){case 0:return Ps(e,Gr(r),t??D.encoder);default:return ks(e,Gr(r),t??lt.encoder)}}var ro=new WeakMap;function Gr(r){let t=ro.get(r);if(t==null){let e=new Map;return ro.set(r,e),e}return t}var $=class r{code;version;multihash;bytes;"/";constructor(t,e,o,n){this.code=e,this.version=t,this.multihash=o,this.bytes=n,this["/"]=n}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!==ae)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==Os)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,o=xt(t,e);return r.createV1(this.code,o)}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 o=e;return o!=null&&t.code===o.code&&t.version===o.version&&Zn(t.multihash,o.multihash)}toString(t){return eo(this,t)}toJSON(){return{"/":eo(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:o,code:n,multihash:i,bytes:s}=e;return new r(o,n,i,s??no(o,n,i.bytes))}else if(e[_s]===!0){let{version:o,multihash:n,code:i}=e,s=Nt(n);return r.create(o,i,s)}else return null}static create(t,e,o){if(typeof e!="number")throw new Error("String codecs are no longer supported");if(!(o.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(t){case 0:{if(e!==ae)throw new Error(`Version 0 CID must use dag-pb (code: ${ae}) block encoding`);return new r(t,e,o,o.bytes)}case 1:{let n=no(t,e,o.bytes);return new r(t,e,o,n)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,ae,t)}static createV1(t,e){return r.create(1,t,e)}static decode(t){let[e,o]=r.decodeFirst(t);if(o.length!==0)throw new Error("Incorrect length");return e}static decodeFirst(t){let e=r.inspectBytes(t),o=e.size-e.multihashSize,n=nt(t.subarray(o,o+e.multihashSize));if(n.byteLength!==e.multihashSize)throw new Error("Incorrect length");let i=n.subarray(e.multihashSize-e.digestSize),s=new Wt(e.multihashCode,e.digestSize,i,n);return[e.version===0?r.createV0(s):r.createV1(e.codec,s),t.subarray(e.size)]}static inspectBytes(t){let e=0,o=()=>{let[l,g]=se(t.subarray(e));return e+=g,l},n=o(),i=ae;if(n===18?(n=0,e=0):i=o(),n!==0&&n!==1)throw new RangeError(`Invalid CID version ${n}`);let s=e,c=o(),a=o(),f=e+a,u=f-s;return{version:n,codec:i,multihashCode:c,digestSize:a,multihashSize:u,size:f}}static parse(t,e){let[o,n]=Ds(t,e),i=r.decode(n);if(i.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Gr(i).set(o,t),i}};function Ds(r,t){switch(r[0]){case"Q":{let e=t??D;return[D.prefix,e.decode(`${D.prefix}${r}`)]}case D.prefix:{let e=t??D;return[D.prefix,e.decode(r)]}case lt.prefix:{let e=t??lt;return[lt.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 Ps(r,t,e){let{prefix:o}=e;if(o!==D.prefix)throw Error(`Cannot string encode V0 in ${e.name} encoding`);let n=t.get(o);if(n==null){let i=e.encode(r).slice(1);return t.set(o,i),i}else return n}function ks(r,t,e){let{prefix:o}=e,n=t.get(o);if(n==null){let i=e.encode(r);return t.set(o,i),i}else return n}var ae=112,Os=18;function no(r,t,e){let o=Ht(r),n=o+Ht(t),i=new Uint8Array(n+e.byteLength);return zt(r,i,0),zt(t,i,o),i.set(e,n),i}var _s=Symbol.for("@ipld/js-cid/CID");var It={...kr,...vr,...Pr,...Ar,...Cr,...Tr,...Lr,...Nr,...Dr,...Sr},uu={...Br,..._r};function io(r,t,e,o){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:o}}}var oo=io("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Vr=io("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=W(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),Us={utf8:oo,"utf-8":oo,hex:It.base16,latin1:Vr,ascii:Vr,binary:Vr,...It},xe=Us;function pt(r,t="utf8"){let e=xe[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return t==="utf8"||t==="utf-8"?Tt(so.Buffer.from(r,"utf-8")):e.decoder.decode(`${e.prefix}${r}`)}function $r(r){let t=r??8192,e=t>>>1,o,n=t;return function(s){if(s<1||s>e)return W(s);n+s>t&&(o=W(t),n=0);let c=o.subarray(n,n+=s);return n&7&&(n=(n|7)+1),c}}var Dt=class{fn;len;next;val;constructor(t,e,o){this.fn=t,this.len=e,this.next=void 0,this.val=o}};function zr(){}var Wr=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},Fs=$r();function Ms(r){return globalThis.Buffer!=null?W(r):Fs(r)}var le=class{len;head;tail;states;constructor(){this.len=0,this.head=new Dt(zr,0,0),this.tail=this.head,this.states=null}_push(t,e,o){return this.tail=this.tail.next=new Dt(t,e,o),this.len+=e,this}uint32(t){return this.len+=(this.tail=this.tail.next=new Kr((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(Ie,10,Z.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let e=Z.fromBigInt(t);return this._push(Ie,e.length(),e)}uint64Number(t){return this._push(fr,v(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=Z.fromBigInt(t).zzEncode();return this._push(Ie,e.length(),e)}sint64Number(t){let e=Z.fromNumber(t).zzEncode();return this._push(Ie,e.length(),e)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(Hr,1,t?1:0)}fixed32(t){return this._push(ue,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=Z.fromBigInt(t);return this._push(ue,4,e.lo)._push(ue,4,e.hi)}fixed64Number(t){let e=Z.fromNumber(t);return this._push(ue,4,e.lo)._push(ue,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(kn,4,t)}double(t){return this._push(_n,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(Hr,1,0):this.uint32(e)._push(Gs,e,t)}string(t){let e=Mn(t);return e!==0?this.uint32(e)._push(gr,e,t):this._push(Hr,1,0)}fork(){return this.states=new Wr(this),this.head=this.tail=new Dt(zr,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 Dt(zr,0,0),this.len=0),this}ldelim(){let t=this.head,e=this.tail,o=this.len;return this.reset().uint32(o),o!==0&&(this.tail.next=t.next,this.tail=e,this.len+=o),this}finish(){let t=this.head.next,e=Ms(this.len),o=0;for(;t!=null;)t.fn(t.val,e,o),o+=t.len,t=t.next;return e}};function Hr(r,t,e){t[e]=r&255}function Bs(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var Kr=class extends Dt{next;constructor(t,e){super(Bs,t,e),this.next=void 0}};function Ie(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 ue(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 Gs(r,t,e){t.set(r,e)}globalThis.Buffer!=null&&(le.prototype.bytes=function(r){let t=r.length>>>0;return this.uint32(t),t>0&&this._push(Vs,t,r),this},le.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push($s,t,r),this});function Vs(r,t,e){t.set(r,e)}function $s(r,t,e){r.length<40?gr(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set(pt(r),e)}function Xr(){return new le}function T(r,t){let e=Xr();return t.encode(r,e,{lengthDelimited:!1}),e.finish()}var Kt;(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"})(Kt||(Kt={}));function Ae(r,t,e,o){return{name:r,type:t,encode:e,decode:o}}function mt(r){function t(n){if(r[n.toString()]==null)throw new Error("Invalid enum value");return r[n]}let e=function(i,s){let c=t(i);s.int32(c)},o=function(i){let s=i.int32();return t(s)};return Ae("enum",Kt.VARINT,e,o)}function L(r,t){return Ae("message",Kt.LENGTH_DELIMITED,r,t)}var ot;(function(r){let t;(function(n){n.IDENTIFY="IDENTIFY",n.CONNECT="CONNECT",n.STREAM_OPEN="STREAM_OPEN",n.STREAM_HANDLER="STREAM_HANDLER",n.DHT="DHT",n.LIST_PEERS="LIST_PEERS",n.CONNMANAGER="CONNMANAGER",n.DISCONNECT="DISCONNECT",n.PUBSUB="PUBSUB",n.PEERSTORE="PEERSTORE"})(t=r.Type||(r.Type={}));let e;(function(n){n[n.IDENTIFY=0]="IDENTIFY",n[n.CONNECT=1]="CONNECT",n[n.STREAM_OPEN=2]="STREAM_OPEN",n[n.STREAM_HANDLER=3]="STREAM_HANDLER",n[n.DHT=4]="DHT",n[n.LIST_PEERS=5]="LIST_PEERS",n[n.CONNMANAGER=6]="CONNMANAGER",n[n.DISCONNECT=7]="DISCONNECT",n[n.PUBSUB=8]="PUBSUB",n[n.PEERSTORE=9]="PEERSTORE"})(e||(e={})),function(n){n.codec=()=>mt(e)}(t=r.Type||(r.Type={}));let o;r.codec=()=>(o==null&&(o=L((n,i,s={})=>{s.lengthDelimited!==!1&&i.fork(),n.type!=null&&(i.uint32(8),r.Type.codec().encode(n.type,i)),n.connect!=null&&(i.uint32(18),ve.codec().encode(n.connect,i)),n.streamOpen!=null&&(i.uint32(26),Se.codec().encode(n.streamOpen,i)),n.streamHandler!=null&&(i.uint32(34),Te.codec().encode(n.streamHandler,i)),n.dht!=null&&(i.uint32(42),it.codec().encode(n.dht,i)),n.connManager!=null&&(i.uint32(50),Ne.codec().encode(n.connManager,i)),n.disconnect!=null&&(i.uint32(58),Re.codec().encode(n.disconnect,i)),n.pubsub!=null&&(i.uint32(66),gt.codec().encode(n.pubsub,i)),n.peerStore!=null&&(i.uint32(74),Pt.codec().encode(n.peerStore,i)),s.lengthDelimited!==!1&&i.ldelim()},(n,i)=>{let s={},c=i==null?n.len:n.pos+i;for(;n.pos<c;){let a=n.uint32();switch(a>>>3){case 1:s.type=r.Type.codec().decode(n);break;case 2:s.connect=ve.codec().decode(n,n.uint32());break;case 3:s.streamOpen=Se.codec().decode(n,n.uint32());break;case 4:s.streamHandler=Te.codec().decode(n,n.uint32());break;case 5:s.dht=it.codec().decode(n,n.uint32());break;case 6:s.connManager=Ne.codec().decode(n,n.uint32());break;case 7:s.disconnect=Re.codec().decode(n,n.uint32());break;case 8:s.pubsub=gt.codec().decode(n,n.uint32());break;case 9:s.peerStore=Pt.codec().decode(n,n.uint32());break;default:n.skipType(a&7);break}}return s})),o),r.encode=n=>T(n,r.codec()),r.decode=n=>S(n,r.codec())})(ot||(ot={}));var N;(function(r){let t;(function(n){n.OK="OK",n.ERROR="ERROR"})(t=r.Type||(r.Type={}));let e;(function(n){n[n.OK=0]="OK",n[n.ERROR=1]="ERROR"})(e||(e={})),function(n){n.codec=()=>mt(e)}(t=r.Type||(r.Type={}));let o;r.codec=()=>(o==null&&(o=L((n,i,s={})=>{if(s.lengthDelimited!==!1&&i.fork(),n.type!=null&&(i.uint32(8),r.Type.codec().encode(n.type,i)),n.error!=null&&(i.uint32(18),Le.codec().encode(n.error,i)),n.streamInfo!=null&&(i.uint32(26),Xt.codec().encode(n.streamInfo,i)),n.identify!=null&&(i.uint32(34),Ce.codec().encode(n.identify,i)),n.dht!=null&&(i.uint32(42),U.codec().encode(n.dht,i)),n.peers!=null)for(let c of n.peers)i.uint32(50),At.codec().encode(c,i);n.pubsub!=null&&(i.uint32(58),De.codec().encode(n.pubsub,i)),n.peerStore!=null&&(i.uint32(66),Pe.codec().encode(n.peerStore,i)),s.lengthDelimited!==!1&&i.ldelim()},(n,i)=>{let s={peers:[]},c=i==null?n.len:n.pos+i;for(;n.pos<c;){let a=n.uint32();switch(a>>>3){case 1:s.type=r.Type.codec().decode(n);break;case 2:s.error=Le.codec().decode(n,n.uint32());break;case 3:s.streamInfo=Xt.codec().decode(n,n.uint32());break;case 4:s.identify=Ce.codec().decode(n,n.uint32());break;case 5:s.dht=U.codec().decode(n,n.uint32());break;case 6:s.peers.push(At.codec().decode(n,n.uint32()));break;case 7:s.pubsub=De.codec().decode(n,n.uint32());break;case 8:s.peerStore=Pe.codec().decode(n,n.uint32());break;default:n.skipType(a&7);break}}return s})),o),r.encode=n=>T(n,r.codec()),r.decode=n=>S(n,r.codec())})(N||(N={}));var Ce;(function(r){let t;r.codec=()=>(t==null&&(t=L((e,o,n={})=>{if(n.lengthDelimited!==!1&&o.fork(),e.id!=null&&e.id.byteLength>0&&(o.uint32(10),o.bytes(e.id)),e.addrs!=null)for(let i of e.addrs)o.uint32(18),o.bytes(i);n.lengthDelimited!==!1&&o.ldelim()},(e,o)=>{let n={id:new Uint8Array(0),addrs:[]},i=o==null?e.len:e.pos+o;for(;e.pos<i;){let s=e.uint32();switch(s>>>3){case 1:n.id=e.bytes();break;case 2:n.addrs.push(e.bytes());break;default:e.skipType(s&7);break}}return n})),t),r.encode=e=>T(e,r.codec()),r.decode=e=>S(e,r.codec())})(Ce||(Ce={}));var ve;(function(r){let t;r.codec=()=>(t==null&&(t=L((e,o,n={})=>{if(n.lengthDelimited!==!1&&o.fork(),e.peer!=null&&e.peer.byteLength>0&&(o.uint32(10),o.bytes(e.peer)),e.addrs!=null)for(let i of e.addrs)o.uint32(18),o.bytes(i);e.timeout!=null&&(o.uint32(24),o.int64(e.timeout)),n.lengthDelimited!==!1&&o.ldelim()},(e,o)=>{let n={peer:new Uint8Array(0),addrs:[]},i=o==null?e.len:e.pos+o;for(;e.pos<i;){let s=e.uint32();switch(s>>>3){case 1:n.peer=e.bytes();break;case 2:n.addrs.push(e.bytes());break;case 3:n.timeout=e.int64();break;default:e.skipType(s&7);break}}return n})),t),r.encode=e=>T(e,r.codec()),r.decode=e=>S(e,r.codec())})(ve||(ve={}));var Se;(function(r){let t;r.codec=()=>(t==null&&(t=L((e,o,n={})=>{if(n.lengthDelimited!==!1&&o.fork(),e.peer!=null&&e.peer.byteLength>0&&(o.uint32(10),o.bytes(e.peer)),e.proto!=null)for(let i of e.proto)o.uint32(18),o.string(i);e.timeout!=null&&(o.uint32(24),o.int64(e.timeout)),n.lengthDelimited!==!1&&o.ldelim()},(e,o)=>{let n={peer:new Uint8Array(0),proto:[]},i=o==null?e.len:e.pos+o;for(;e.pos<i;){let s=e.uint32();switch(s>>>3){case 1:n.peer=e.bytes();break;case 2:n.proto.push(e.string());break;case 3:n.timeout=e.int64();break;default:e.skipType(s&7);break}}return n})),t),r.encode=e=>T(e,r.codec()),r.decode=e=>S(e,r.codec())})(Se||(Se={}));var Te;(function(r){let t;r.codec=()=>(t==null&&(t=L((e,o,n={})=>{if(n.lengthDelimited!==!1&&o.fork(),e.addr!=null&&e.addr.byteLength>0&&(o.uint32(10),o.bytes(e.addr)),e.proto!=null)for(let i of e.proto)o.uint32(18),o.string(i);n.lengthDelimited!==!1&&o.ldelim()},(e,o)=>{let n={addr:new Uint8Array(0),proto:[]},i=o==null?e.len:e.pos+o;for(;e.pos<i;){let s=e.uint32();switch(s>>>3){case 1:n.addr=e.bytes();break;case 2:n.proto.push(e.string());break;default:e.skipType(s&7);break}}return n})),t),r.encode=e=>T(e,r.codec()),r.decode=e=>S(e,r.codec())})(Te||(Te={}));var Le;(function(r){let t;r.codec=()=>(t==null&&(t=L((e,o,n={})=>{n.lengthDelimited!==!1&&o.fork(),e.msg!=null&&e.msg!==""&&(o.uint32(10),o.string(e.msg)),n.lengthDelimited!==!1&&o.ldelim()},(e,o)=>{let n={msg:""},i=o==null?e.len:e.pos+o;for(;e.pos<i;){let s=e.uint32();switch(s>>>3){case 1:n.msg=e.string();break;default:e.skipType(s&7);break}}return n})),t),r.encode=e=>T(e,r.codec()),r.decode=e=>S(e,r.codec())})(Le||(Le={}));var Xt;(function(r){let t;r.codec=()=>(t==null&&(t=L((e,o,n={})=>{n.lengthDelimited!==!1&&o.fork(),e.peer!=null&&e.peer.byteLength>0&&(o.uint32(10),o.bytes(e.peer)),e.addr!=null&&e.addr.byteLength>0&&(o.uint32(18),o.bytes(e.addr)),e.proto!=null&&e.proto!==""&&(o.uint32(26),o.string(e.proto)),n.lengthDelimited!==!1&&o.ldelim()},(e,o)=>{let n={peer:new Uint8Array(0),addr:new Uint8Array(0),proto:""},i=o==null?e.len:e.pos+o;for(;e.pos<i;){let s=e.uint32();switch(s>>>3){case 1:n.peer=e.bytes();break;case 2:n.addr=e.bytes();break;case 3:n.proto=e.string();break;default:e.skipType(s&7);break}}return n})),t),r.encode=e=>T(e,r.codec()),r.decode=e=>S(e,r.codec())})(Xt||(Xt={}));var it;(function(r){let t;(function(n){n.FIND_PEER="FIND_PEER",n.FIND_PEERS_CONNECTED_TO_PEER="FIND_PEERS_CONNECTED_TO_PEER",n.FIND_PROVIDERS="FIND_PROVIDERS",n.GET_CLOSEST_PEERS="GET_CLOSEST_PEERS",n.GET_PUBLIC_KEY="GET_PUBLIC_KEY",n.GET_VALUE="GET_VALUE",n.SEARCH_VALUE="SEARCH_VALUE",n.PUT_VALUE="PUT_VALUE",n.PROVIDE="PROVIDE"})(t=r.Type||(r.Type={}));let e;(function(n){n[n.FIND_PEER=0]="FIND_PEER",n[n.FIND_PEERS_CONNECTED_TO_PEER=1]="FIND_PEERS_CONNECTED_TO_PEER",n[n.FIND_PROVIDERS=2]="FIND_PROVIDERS",n[n.GET_CLOSEST_PEERS=3]="GET_CLOSEST_PEERS",n[n.GET_PUBLIC_KEY=4]="GET_PUBLIC_KEY",n[n.GET_VALUE=5]="GET_VALUE",n[n.SEARCH_VALUE=6]="SEARCH_VALUE",n[n.PUT_VALUE=7]="PUT_VALUE",n[n.PROVIDE=8]="PROVIDE"})(e||(e={})),function(n){n.codec=()=>mt(e)}(t=r.Type||(r.Type={}));let o;r.codec=()=>(o==null&&(o=L((n,i,s={})=>{s.lengthDelimited!==!1&&i.fork(),n.type!=null&&(i.uint32(8),r.Type.codec().encode(n.type,i)),n.peer!=null&&(i.uint32(18),i.bytes(n.peer)),n.cid!=null&&(i.uint32(26),i.bytes(n.cid)),n.key!=null&&(i.uint32(34),i.bytes(n.key)),n.value!=null&&(i.uint32(42),i.bytes(n.value)),n.count!=null&&(i.uint32(48),i.int32(n.count)),n.timeout!=null&&(i.uint32(56),i.int64(n.timeout)),s.lengthDelimited!==!1&&i.ldelim()},(n,i)=>{let s={},c=i==null?n.len:n.pos+i;for(;n.pos<c;){let a=n.uint32();switch(a>>>3){case 1:s.type=r.Type.codec().decode(n);break;case 2:s.peer=n.bytes();break;case 3:s.cid=n.bytes();break;case 4:s.key=n.bytes();break;case 5:s.value=n.bytes();break;case 6:s.count=n.int32();break;case 7:s.timeout=n.int64();break;default:n.skipType(a&7);break}}return s})),o),r.encode=n=>T(n,r.codec()),r.decode=n=>S(n,r.codec())})(it||(it={}));var U;(function(r){let t;(function(n){n.BEGIN="BEGIN",n.VALUE="VALUE",n.END="END"})(t=r.Type||(r.Type={}));let e;(function(n){n[n.BEGIN=0]="BEGIN",n[n.VALUE=1]="VALUE",n[n.END=2]="END"})(e||(e={})),function(n){n.codec=()=>mt(e)}(t=r.Type||(r.Type={}));let o;r.codec=()=>(o==null&&(o=L((n,i,s={})=>{s.lengthDelimited!==!1&&i.fork(),n.type!=null&&(i.uint32(8),r.Type.codec().encode(n.type,i)),n.peer!=null&&(i.uint32(18),At.codec().encode(n.peer,i)),n.value!=null&&(i.uint32(26),i.bytes(n.value)),s.lengthDelimited!==!1&&i.ldelim()},(n,i)=>{let s={},c=i==null?n.len:n.pos+i;for(;n.pos<c;){let a=n.uint32();switch(a>>>3){case 1:s.type=r.Type.codec().decode(n);break;case 2:s.peer=At.codec().decode(n,n.uint32());break;case 3:s.value=n.bytes();break;default:n.skipType(a&7);break}}return s})),o),r.encode=n=>T(n,r.codec()),r.decode=n=>S(n,r.codec())})(U||(U={}));var At;(function(r){let t;r.codec=()=>(t==null&&(t=L((e,o,n={})=>{if(n.lengthDelimited!==!1&&o.fork(),e.id!=null&&e.id.byteLength>0&&(o.uint32(10),o.bytes(e.id)),e.addrs!=null)for(let i of e.addrs)o.uint32(18),o.bytes(i);n.lengthDelimited!==!1&&o.ldelim()},(e,o)=>{let n={id:new Uint8Array(0),addrs:[]},i=o==null?e.len:e.pos+o;for(;e.pos<i;){let s=e.uint32();switch(s>>>3){case 1:n.id=e.bytes();break;case 2:n.addrs.push(e.bytes());break;default:e.skipType(s&7);break}}return n})),t),r.encode=e=>T(e,r.codec()),r.decode=e=>S(e,r.codec())})(At||(At={}));var Ne;(function(r){let t;(function(n){n.TAG_PEER="TAG_PEER",n.UNTAG_PEER="UNTAG_PEER",n.TRIM="TRIM"})(t=r.Type||(r.Type={}));let e;(function(n){n[n.TAG_PEER=0]="TAG_PEER",n[n.UNTAG_PEER=1]="UNTAG_PEER",n[n.TRIM=2]="TRIM"})(e||(e={})),function(n){n.codec=()=>mt(e)}(t=r.Type||(r.Type={}));let o;r.codec=()=>(o==null&&(o=L((n,i,s={})=>{s.lengthDelimited!==!1&&i.fork(),n.type!=null&&(i.uint32(8),r.Type.codec().encode(n.type,i)),n.peer!=null&&(i.uint32(18),i.bytes(n.peer)),n.tag!=null&&(i.uint32(26),i.string(n.tag)),n.weight!=null&&(i.uint32(32),i.int64(n.weight)),s.lengthDelimited!==!1&&i.ldelim()},(n,i)=>{let s={},c=i==null?n.len:n.pos+i;for(;n.pos<c;){let a=n.uint32();switch(a>>>3){case 1:s.type=r.Type.codec().decode(n);break;case 2:s.peer=n.bytes();break;case 3:s.tag=n.string();break;case 4:s.weight=n.int64();break;default:n.skipType(a&7);break}}return s})),o),r.encode=n=>T(n,r.codec()),r.decode=n=>S(n,r.codec())})(Ne||(Ne={}));var Re;(function(r){let t;r.codec=()=>(t==null&&(t=L((e,o,n={})=>{n.lengthDelimited!==!1&&o.fork(),e.peer!=null&&e.peer.byteLength>0&&(o.uint32(10),o.bytes(e.peer)),n.lengthDelimited!==!1&&o.ldelim()},(e,o)=>{let n={peer:new Uint8Array(0)},i=o==null?e.len:e.pos+o;for(;e.pos<i;){let s=e.uint32();switch(s>>>3){case 1:n.peer=e.bytes();break;default:e.skipType(s&7);break}}return n})),t),r.encode=e=>T(e,r.codec()),r.decode=e=>S(e,r.codec())})(Re||(Re={}));var gt;(function(r){let t;(function(n){n.GET_TOPICS="GET_TOPICS",n.LIST_PEERS="LIST_PEERS",n.PUBLISH="PUBLISH",n.SUBSCRIBE="SUBSCRIBE"})(t=r.Type||(r.Type={}));let e;(function(n){n[n.GET_TOPICS=0]="GET_TOPICS",n[n.LIST_PEERS=1]="LIST_PEERS",n[n.PUBLISH=2]="PUBLISH",n[n.SUBSCRIBE=3]="SUBSCRIBE"})(e||(e={})),function(n){n.codec=()=>mt(e)}(t=r.Type||(r.Type={}));let o;r.codec=()=>(o==null&&(o=L((n,i,s={})=>{s.lengthDelimited!==!1&&i.fork(),n.type!=null&&(i.uint32(8),r.Type.codec().encode(n.type,i)),n.topic!=null&&(i.uint32(18),i.string(n.topic)),n.data!=null&&(i.uint32(26),i.bytes(n.data)),s.lengthDelimited!==!1&&i.ldelim()},(n,i)=>{let s={},c=i==null?n.len:n.pos+i;for(;n.pos<c;){let a=n.uint32();switch(a>>>3){case 1:s.type=r.Type.codec().decode(n);break;case 2:s.topic=n.string();break;case 3:s.data=n.bytes();break;default:n.skipType(a&7);break}}return s})),o),r.encode=n=>T(n,r.codec()),r.decode=n=>S(n,r.codec())})(gt||(gt={}));var de;(function(r){let t;r.codec=()=>(t==null&&(t=L((e,o,n={})=>{if(n.lengthDelimited!==!1&&o.fork(),e.from!=null&&(o.uint32(10),o.bytes(e.from)),e.data!=null&&(o.uint32(18),o.bytes(e.data)),e.seqno!=null&&(o.uint32(26),o.bytes(e.seqno)),e.topicIDs!=null)for(let i of e.topicIDs)o.uint32(34),o.string(i);e.signature!=null&&(o.uint32(42),o.bytes(e.signature)),e.key!=null&&(o.uint32(50),o.bytes(e.key)),n.lengthDelimited!==!1&&o.ldelim()},(e,o)=>{let n={topicIDs:[]},i=o==null?e.len:e.pos+o;for(;e.pos<i;){let s=e.uint32();switch(s>>>3){case 1:n.from=e.bytes();break;case 2:n.data=e.bytes();break;case 3:n.seqno=e.bytes();break;case 4:n.topicIDs.push(e.string());break;case 5:n.signature=e.bytes();break;case 6:n.key=e.bytes();break;default:e.skipType(s&7);break}}return n})),t),r.encode=e=>T(e,r.codec()),r.decode=e=>S(e,r.codec())})(de||(de={}));var De;(function(r){let t;r.codec=()=>(t==null&&(t=L((e,o,n={})=>{if(n.lengthDelimited!==!1&&o.fork(),e.topics!=null)for(let i of e.topics)o.uint32(10),o.string(i);if(e.peerIDs!=null)for(let i of e.peerIDs)o.uint32(18),o.bytes(i);n.lengthDelimited!==!1&&o.ldelim()},(e,o)=>{let n={topics:[],peerIDs:[]},i=o==null?e.len:e.pos+o;for(;e.pos<i;){let s=e.uint32();switch(s>>>3){case 1:n.topics.push(e.string());break;case 2:n.peerIDs.push(e.bytes());break;default:e.skipType(s&7);break}}return n})),t),r.encode=e=>T(e,r.codec()),r.decode=e=>S(e,r.codec())})(De||(De={}));var Pt;(function(r){let t;(function(n){n.UNSPECIFIED="UNSPECIFIED",n.GET_PROTOCOLS="GET_PROTOCOLS",n.GET_PEER_INFO="GET_PEER_INFO"})(t=r.Type||(r.Type={}));let e;(function(n){n[n.UNSPECIFIED=0]="UNSPECIFIED",n[n.GET_PROTOCOLS=1]="GET_PROTOCOLS",n[n.GET_PEER_INFO=2]="GET_PEER_INFO"})(e||(e={})),function(n){n.codec=()=>mt(e)}(t=r.Type||(r.Type={}));let o;r.codec=()=>(o==null&&(o=L((n,i,s={})=>{if(s.lengthDelimited!==!1&&i.fork(),n.type!=null&&(i.uint32(8),r.Type.codec().encode(n.type,i)),n.id!=null&&(i.uint32(18),i.bytes(n.id)),n.protos!=null)for(let c of n.protos)i.uint32(26),i.string(c);s.lengthDelimited!==!1&&i.ldelim()},(n,i)=>{let s={protos:[]},c=i==null?n.len:n.pos+i;for(;n.pos<c;){let a=n.uint32();switch(a>>>3){case 1:s.type=r.Type.codec().decode(n);break;case 2:s.id=n.bytes();break;case 3:s.protos.push(n.string());break;default:n.skipType(a&7);break}}return s})),o),r.encode=n=>T(n,r.codec()),r.decode=n=>S(n,r.codec())})(Pt||(Pt={}));var Pe;(function(r){let t;r.codec=()=>(t==null&&(t=L((e,o,n={})=>{if(n.lengthDelimited!==!1&&o.fork(),e.peer!=null&&(o.uint32(10),At.codec().encode(e.peer,o)),e.protos!=null)for(let i of e.protos)o.uint32(18),o.string(i);n.lengthDelimited!==!1&&o.ldelim()},(e,o)=>{let n={protos:[]},i=o==null?e.len:e.pos+o;for(;e.pos<i;){let s=e.uint32();switch(s>>>3){case 1:n.peer=At.codec().decode(e,e.uint32());break;case 2:n.protos.push(e.string());break;default:e.skipType(s&7);break}}return n})),t),r.encode=e=>T(e,r.codec()),r.decode=e=>S(e,r.codec())})(Pe||(Pe={}));var Yr={upgradeInbound:async r=>r,upgradeOutbound:async r=>r};var j=St(bo(),1);j.default.formatters.b=r=>r==null?"undefined":D.baseEncode(r);j.default.formatters.t=r=>r==null?"undefined":lt.baseEncode(r);j.default.formatters.m=r=>r==null?"undefined":Rr.baseEncode(r);j.default.formatters.p=r=>r==null?"undefined":r.toString();j.default.formatters.c=r=>r==null?"undefined":r.toString();j.default.formatters.k=r=>r==null?"undefined":r.toString();j.default.formatters.a=r=>r==null?"undefined":r.toString();function fc(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 wo(){return{forComponent(r){return Ot(r)}}}function Ot(r){let t=fc(`${r}:trace`);return j.default.enabled(`${r}:trace`)&&j.default.names.map(e=>e.toString()).find(e=>e.includes(":trace"))!=null&&(t=(0,j.default)(`${r}:trace`)),Object.assign((0,j.default)(r),{error:(0,j.default)(`${r}:error`),trace:t})}var qr=Symbol.for("@libp2p/peer-id");var xo=Symbol.for("@libp2p/transport");var Eo;(function(r){r[r.FATAL_ALL=0]="FATAL_ALL",r[r.NO_FATAL=1]="NO_FATAL"})(Eo||(Eo={}));var fe=class r extends Error{code;type;constructor(t="The operation was aborted"){super(t),this.name="AbortError",this.code=r.code,this.type=r.type}static code="ABORT_ERR";static type="aborted"},P=class extends Error{code;props;constructor(t,e,o){super(t),this.code=e,this.name=o?.name??"CodeError",this.props=o??{}}};var Io=H("events"),Ao=(r,...t)=>{try{(0,Io.setMaxListeners)(r,...t)}catch{}};var Fe=class extends EventTarget{#t=new Map;constructor(){super(),Ao(1/0,this)}listenerCount(t){let e=this.#t.get(t);return e==null?0:e.length}addEventListener(t,e,o){super.addEventListener(t,e,o);let n=this.#t.get(t);n==null&&(n=[],this.#t.set(t,n)),n.push({callback:e,once:(o!==!0&&o!==!1&&o?.once)??!1})}removeEventListener(t,e,o){super.removeEventListener(t.toString(),e??null,o);let n=this.#t.get(t);n!=null&&(n=n.filter(({callback:i})=>i!==e),this.#t.set(t,n))}dispatchEvent(t){let e=super.dispatchEvent(t),o=this.#t.get(t.type);return o==null||(o=o.filter(({once:n})=>!n),this.#t.set(t.type,o)),e}safeDispatchEvent(t,e={}){return this.dispatchEvent(new hc(t,e))}},jr=class extends Event{detail;constructor(t,e){super(t,e),this.detail=e?.detail}},hc=globalThis.CustomEvent??jr;var Co=Symbol.for("@libp2p/service-capabilities"),ol=Symbol.for("@libp2p/service-dependencies");function _t(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 vo=H("node:buffer");function F(r,t="utf8"){let e=xe[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return t==="utf8"||t==="utf-8"?vo.Buffer.from(r.buffer,r.byteOffset,r.byteLength).toString("utf8"):e.encoder.encode(r).substring(1)}var To=Symbol.for("nodejs.util.inspect.custom"),So=Object.values(It).map(r=>r.decoder).reduce((r,t)=>r.or(t),It.identity.decoder),Lo=114,No=36,Ro=37,he=class{type;multihash;privateKey;publicKey;string;constructor(t){this.type=t.type,this.multihash=t.multihash,this.privateKey=t.privateKey,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[qr]=!0;toString(){return this.string==null&&(this.string=D.encode(this.multihash.bytes).slice(1)),this.string}toCID(){return $.createV1(Lo,this.multihash)}toBytes(){return this.multihash.bytes}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return _t(this.multihash.bytes,t);if(typeof t=="string")return pc(t).equals(this);if(t?.multihash?.bytes!=null)return _t(this.multihash.bytes,t.multihash.bytes);throw new Error("not valid Id")}[To](){return`PeerId(${this.toString()})`}},pe=class extends he{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},me=class extends he{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.multihash.digest}},ge=class extends he{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.multihash.digest}},tn=2336,en=class{type="url";multihash;privateKey;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=ce.digest(pt(this.url))}[To](){return`PeerId(${this.url})`}[qr]=!0;toString(){return this.toCID().toString()}toCID(){return $.createV1(tn,this.multihash)}toBytes(){return this.toCID().bytes}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=F(t)),t.toString()===this.toString())}};function pc(r,t){if(t=t??So,r.charAt(0)==="1"||r.charAt(0)==="Q"){let e=Nt(D.decode(`z${r}`));return r.startsWith("12D")?new me({multihash:e}):r.startsWith("16U")?new ge({multihash:e}):new pe({multihash:e})}return Ut(So.decode(r))}function Ut(r){try{let t=Nt(r);if(t.code===ce.code){if(t.digest.length===No)return new me({multihash:t});if(t.digest.length===Ro)return new ge({multihash:t})}if(t.code===Ee.code)return new pe({multihash:t})}catch{return mc($.decode(r))}throw new Error("Supplied PeerID CID is invalid")}function mc(r){if(r==null||r.multihash==null||r.version==null||r.version===1&&r.code!==Lo&&r.code!==tn)throw new Error("Supplied PeerID CID is invalid");if(r.code===tn){let e=F(r.multihash.digest);return new en(new URL(e))}let t=r.multihash;if(t.code===Ee.code)return new pe({multihash:r.multihash});if(t.code===ce.code){if(t.digest.length===No)return new me({multihash:r.multihash});if(t.digest.length===Ro)return new ge({multihash:r.multihash})}throw new Error("Supplied PeerID CID is invalid")}var ii=St(H("net"),1);var Do=H("node:buffer");function st(r,t){return Tt(Do.Buffer.concat(r,t))}var Me=class{index=0;input="";new(t){return this.index=0,this.input=t,this}readAtomically(t){let e=this.index,o=t();return o===void 0&&(this.index=e),o}parseWith(t){let e=t();if(this.index===this.input.length)return e}peekChar(){if(!(this.index>=this.input.length))return this.input[this.index]}readChar(){if(!(this.index>=this.input.length))return this.input[this.index++]}readGivenChar(t){return this.readAtomically(()=>{let e=this.readChar();if(e===t)return e})}readSeparator(t,e,o){return this.readAtomically(()=>{if(!(e>0&&this.readGivenChar(t)===void 0))return o()})}readNumber(t,e,o,n){return this.readAtomically(()=>{let i=0,s=0,c=this.peekChar();if(c===void 0)return;let a=c==="0",f=2**(8*n)-1;for(;;){let u=this.readAtomically(()=>{let l=this.readChar();if(l===void 0)return;let g=Number.parseInt(l,t);if(!Number.isNaN(g))return g});if(u===void 0)break;if(i*=t,i+=u,i>f||(s+=1,e!==void 0&&s>e))return}if(s!==0)return!o&&a&&s>1?void 0:i})}readIPv4Addr(){return this.readAtomically(()=>{let t=new Uint8Array(4);for(let e=0;e<t.length;e++){let o=this.readSeparator(".",e,()=>this.readNumber(10,3,!1,1));if(o===void 0)return;t[e]=o}return t})}readIPv6Addr(){let t=e=>{for(let o=0;o<e.length/2;o++){let n=o*2;if(o<e.length-3){let s=this.readSeparator(":",o,()=>this.readIPv4Addr());if(s!==void 0)return e[n]=s[0],e[n+1]=s[1],e[n+2]=s[2],e[n+3]=s[3],[n+4,!0]}let i=this.readSeparator(":",o,()=>this.readNumber(16,4,!0,2));if(i===void 0)return[n,!1];e[n]=i>>8,e[n+1]=i&255}return[e.length,!1]};return this.readAtomically(()=>{let e=new Uint8Array(16),[o,n]=t(e);if(o===16)return e;if(n||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let i=new Uint8Array(14),s=16-(o+2),[c]=t(i.subarray(0,s));return e.set(i.subarray(0,c),16-c),e})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var Wl=new Me;var jl=parseInt("0xFFFF",16),td=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);var ct=H("node:net");function Be(r){return!!(0,ct.isIP)(r)}var Oo=ct.isIPv4,xc=ct.isIPv6,rn=function(r){let t=0;if(r=r.toString().trim(),Oo(r)){let e=new Uint8Array(t+4);return r.split(/\./g).forEach(o=>{e[t++]=parseInt(o,10)&255}),e}if(xc(r)){let e=r.split(":",8),o;for(o=0;o<e.length;o++){let i=Oo(e[o]),s;i&&(s=rn(e[o]),e[o]=F(s.slice(0,2),"base16")),s!=null&&++o<8&&e.splice(o,0,F(s.slice(2,4),"base16"))}if(e[0]==="")for(;e.length<8;)e.unshift("0");else if(e[e.length-1]==="")for(;e.length<8;)e.push("0");else if(e.length<8){for(o=0;o<e.length&&e[o]!=="";o++);let i=[o,1];for(o=9-e.length;o>0;o--)i.push("0");e.splice.apply(e,i)}let n=new Uint8Array(t+16);for(o=0;o<e.length;o++){let i=parseInt(e[o],16);n[t++]=i>>8&255,n[t++]=i&255}return n}throw new Error("invalid ip address")},_o=function(r,t=0,e){t=~~t,e=e??r.length-t;let o=new DataView(r.buffer);if(e===4){let n=[];for(let i=0;i<e;i++)n.push(r[t+i]);return n.join(".")}if(e===16){let n=[];for(let i=0;i<e;i+=2)n.push(o.getUint16(t+i).toString(16));return n.join(":").replace(/(^|:)0(:0)*:0(:|$)/,"$1::$3").replace(/:{3,4}/,"::")}return""};var qt={},nn={},Ac=[[4,32,"ip4"],[6,16,"tcp"],[33,16,"dccp"],[41,128,"ip6"],[42,-1,"ip6zone"],[43,8,"ipcidr"],[53,-1,"dns",!0],[54,-1,"dns4",!0],[55,-1,"dns6",!0],[56,-1,"dnsaddr",!0],[132,16,"sctp"],[273,16,"udp"],[275,0,"p2p-webrtc-star"],[276,0,"p2p-webrtc-direct"],[277,0,"p2p-stardust"],[280,0,"webrtc-direct"],[281,0,"webrtc"],[290,0,"p2p-circuit"],[301,0,"udt"],[302,0,"utp"],[400,-1,"unix",!1,!0],[421,-1,"ipfs"],[421,-1,"p2p"],[443,0,"https"],[444,96,"onion"],[445,296,"onion3"],[446,-1,"garlic64"],[448,0,"tls"],[449,-1,"sni"],[460,0,"quic"],[461,0,"quic-v1"],[465,0,"webtransport"],[466,-1,"certhash"],[477,0,"ws"],[478,0,"wss"],[479,0,"p2p-websocket-star"],[480,0,"http"],[481,-1,"http-path"],[777,-1,"memory"]];Ac.forEach(r=>{let t=Cc(...r);nn[t.code]=t,qt[t.name]=t});function Cc(r,t,e,o,n){return{code:r,size:t,name:e,resolvable:!!o,path:!!n}}function I(r){if(typeof r=="number"){if(nn[r]!=null)return nn[r];throw new Error(`no protocol with code: ${r}`)}else if(typeof r=="string"){if(qt[r]!=null)return qt[r];throw new Error(`no protocol with name: ${r}`)}throw new Error(`invalid protocol id type: ${typeof r}`)}var Md=I("ip4"),Bd=I("ip6"),Gd=I("ipcidr");function an(r,t){switch(I(r).code){case 4:case 41:return Sc(t);case 42:return cn(t);case 6:case 273:case 33:case 132:return Mo(t).toString();case 53:case 54:case 55:case 56:case 400:case 449:case 777:return cn(t);case 421:return Rc(t);case 444:return Fo(t);case 445:return Fo(t);case 466:return Nc(t);case 481:return globalThis.encodeURIComponent(cn(t));default:return F(t,"base16")}}function un(r,t){switch(I(r).code){case 4:return Uo(t);case 41:return Uo(t);case 42:return sn(t);case 6:case 273:case 33:case 132:return ln(parseInt(t,10));case 53:case 54:case 55:case 56:case 400:case 449:case 777:return sn(t);case 421:return Tc(t);case 444:return Dc(t);case 445:return Pc(t);case 466:return Lc(t);case 481:return sn(globalThis.decodeURIComponent(t));default:return pt(t,"base16")}}var on=Object.values(It).map(r=>r.decoder),vc=function(){let r=on[0].or(on[1]);return on.slice(2).forEach(t=>r=r.or(t)),r}();function Uo(r){if(!Be(r))throw new Error("invalid ip address");return rn(r)}function Sc(r){let t=_o(r,0,r.length);if(t==null)throw new Error("ipBuff is required");if(!Be(t))throw new Error("invalid ip address");return t}function ln(r){let t=new ArrayBuffer(2);return new DataView(t).setUint16(0,r),new Uint8Array(t)}function Mo(r){return new DataView(r.buffer).getUint16(r.byteOffset)}function sn(r){let t=pt(r),e=Uint8Array.from(ft(t.length));return st([e,t],e.length+t.length)}function cn(r){let t=at(r);if(r=r.slice(v(t)),r.length!==t)throw new Error("inconsistent lengths");return F(r)}function Tc(r){let t;r[0]==="Q"||r[0]==="1"?t=Nt(D.decode(`z${r}`)).bytes:t=$.parse(r).multihash.bytes;let e=Uint8Array.from(ft(t.length));return st([e,t],e.length+t.length)}function Lc(r){let t=vc.decode(r),e=Uint8Array.from(ft(t.length));return st([e,t],e.length+t.length)}function Nc(r){let t=at(r),e=r.slice(v(t));if(e.length!==t)throw new Error("inconsistent lengths");return"u"+F(e,"base64url")}function Rc(r){let t=at(r),e=r.slice(v(t));if(e.length!==t)throw new Error("inconsistent lengths");return F(e,"base58btc")}function Dc(r){let t=r.split(":");if(t.length!==2)throw new Error(`failed to parse onion addr: ["'${t.join('", "')}'"]' does not contain a port number`);if(t[0].length!==16)throw new Error(`failed to parse onion addr: ${t[0]} not a Tor onion address.`);let e=lt.decode("b"+t[0]),o=parseInt(t[1],10);if(o<1||o>65536)throw new Error("Port number is not in range(1, 65536)");let n=ln(o);return st([e,n],e.length+n.length)}function Pc(r){let t=r.split(":");if(t.length!==2)throw new Error(`failed to parse onion addr: ["'${t.join('", "')}'"]' does not contain a port number`);if(t[0].length!==56)throw new Error(`failed to parse onion addr: ${t[0]} not a Tor onion3 address.`);let e=lt.decode(`b${t[0]}`),o=parseInt(t[1],10);if(o<1||o>65536)throw new Error("Port number is not in range(1, 65536)");let n=ln(o);return st([e,n],e.length+n.length)}function Fo(r){let t=r.slice(0,r.length-2),e=r.slice(r.length-2),o=F(t,"base32"),n=Mo(e);return`${o}:${n}`}function Bo(r){r=dn(r);let t=[],e=[],o=null,n=r.split("/").slice(1);if(n.length===1&&n[0]==="")return{bytes:new Uint8Array,string:"/",tuples:[],stringTuples:[],path:null};for(let i=0;i<n.length;i++){let s=n[i],c=I(s);if(c.size===0){t.push([c.code]),e.push([c.code]);continue}if(i++,i>=n.length)throw Vo("invalid address: "+r);if(c.path===!0){o=dn(n.slice(i).join("/")),t.push([c.code,un(c.code,o)]),e.push([c.code,o]);break}let a=un(c.code,n[i]);t.push([c.code,a]),e.push([c.code,an(c.code,a)])}return{string:Go(e),bytes:hn(t),tuples:t,stringTuples:e,path:o}}function fn(r){let t=[],e=[],o=null,n=0;for(;n<r.length;){let i=at(r,n),s=v(i),c=I(i),a=kc(c,r.slice(n+s));if(a===0){t.push([i]),e.push([i]),n+=s;continue}let f=r.slice(n+s,n+s+a);if(n+=a+s,n>r.length)throw Vo("Invalid address Uint8Array: "+F(r,"base16"));t.push([i,f]);let u=an(i,f);if(e.push([i,u]),c.path===!0){o=u;break}}return{bytes:Uint8Array.from(r),string:Go(e),tuples:t,stringTuples:e,path:o}}function Go(r){let t=[];return r.map(e=>{let o=I(e[0]);return t.push(o.name),e.length>1&&e[1]!=null&&t.push(e[1]),null}),dn(t.join("/"))}function hn(r){return st(r.map(t=>{let e=I(t[0]),o=Uint8Array.from(ft(e.code));return t.length>1&&t[1]!=null&&(o=st([o,t[1]])),o}))}function kc(r,t){if(r.size>0)return r.size/8;if(r.size===0)return 0;{let e=at(t instanceof Uint8Array?t:Uint8Array.from(t));return e+v(e)}}function dn(r){return"/"+r.trim().split("/").filter(t=>t).join("/")}function Vo(r){return new Error("Error parsing address: "+r)}var Oc=Symbol.for("nodejs.util.inspect.custom"),pn=Symbol.for("@multiformats/js-multiaddr/multiaddr"),_c=[I("dns").code,I("dns4").code,I("dns6").code,I("dnsaddr").code],Ge=class r{bytes;#t;#e;#r;#n;[pn]=!0;constructor(t){t==null&&(t="");let e;if(t instanceof Uint8Array)e=fn(t);else if(typeof t=="string"){if(t.length>0&&t.charAt(0)!=="/")throw new Error(`multiaddr "${t}" must start with a "/"`);e=Bo(t)}else if(zo(t))e=fn(t.bytes);else throw new Error("addr must be a string, Buffer, or another Multiaddr");this.bytes=e.bytes,this.#t=e.string,this.#e=e.tuples,this.#r=e.stringTuples,this.#n=e.path}toString(){return this.#t}toJSON(){return this.toString()}toOptions(){let t,e,o,n,i="",s=I("tcp"),c=I("udp"),a=I("ip4"),f=I("ip6"),u=I("dns6"),l=I("ip6zone");for(let[b,p]of this.stringTuples())b===l.code&&(i=`%${p??""}`),_c.includes(b)&&(e=s.name,n=443,o=`${p??""}${i}`,t=b===u.code?6:4),(b===s.code||b===c.code)&&(e=I(b).name,n=parseInt(p??"")),(b===a.code||b===f.code)&&(e=I(b).name,o=`${p??""}${i}`,t=b===f.code?6:4);if(t==null||e==null||o==null||n==null)throw new Error('multiaddr must have a valid format: "/{ip4, ip6, dns4, dns6, dnsaddr}/{address}/{tcp, udp}/{port}".');return{family:t,host:o,transport:e,port:n}}protos(){return this.#e.map(([t])=>Object.assign({},I(t)))}protoCodes(){return this.#e.map(([t])=>t)}protoNames(){return this.#e.map(([t])=>I(t).name)}tuples(){return this.#e}stringTuples(){return this.#r}encapsulate(t){return t=new r(t),new r(this.toString()+t.toString())}decapsulate(t){let e=t.toString(),o=this.toString(),n=o.lastIndexOf(e);if(n<0)throw new Error(`Address ${this.toString()} does not contain subaddress: ${t.toString()}`);return new r(o.slice(0,n))}decapsulateCode(t){let e=this.tuples();for(let o=e.length-1;o>=0;o--)if(e[o][0]===t)return new r(hn(e.slice(0,o)));return this}getPeerId(){try{let t=[];this.stringTuples().forEach(([o,n])=>{o===qt.p2p.code&&t.push([o,n]),o===qt["p2p-circuit"].code&&(t=[])});let e=t.pop();if(e?.[1]!=null){let o=e[1];return o[0]==="Q"||o[0]==="1"?F(D.decode(`z${o}`),"base58btc"):F($.parse(o).multihash.bytes,"base58btc")}return null}catch{return null}}getPath(){return this.#n}equals(t){return _t(this.bytes,t.bytes)}async resolve(t){let e=this.protos().find(i=>i.resolvable);if(e==null)return[this];let o=$o.get(e.name);if(o==null)throw new P(`no available resolver for ${e.name}`,"ERR_NO_AVAILABLE_RESOLVER");return(await o(this,t)).map(i=>K(i))}nodeAddress(){let t=this.toOptions();if(t.transport!=="tcp"&&t.transport!=="udp")throw new Error(`multiaddr must have a valid format - no protocol with name: "${t.transport}". Must have a valid transport protocol: "{tcp, udp}"`);return{family:t.family,address:t.host,port:t.port}}isThinWaistAddress(t){let e=(t??this).protos();return!(e.length!==2||e[0].code!==4&&e[0].code!==41||e[1].code!==6&&e[1].code!==273)}[Oc](){return`Multiaddr(${this.#t})`}};var $o=new Map;function zo(r){return!!r?.[pn]}function K(r){return new Ge(r)}var Uc=d("dns4"),Fc=d("dns6"),Mc=d("dnsaddr"),Mt=C(d("dns"),Mc,Uc,Fc),ze=C(d("ip4"),d("ip6")),vt=C(m(ze,d("tcp")),m(Mt,d("tcp"))),He=m(ze,d("udp")),Bc=m(He,d("utp")),Gc=m(He,d("quic")),Vc=m(He,d("quic-v1")),mn=C(m(vt,d("ws")),m(Mt,d("ws"))),Ve=C(m(mn,d("p2p")),mn),gn=C(m(vt,d("wss")),m(Mt,d("wss")),m(vt,d("tls"),d("ws")),m(Mt,d("tls"),d("ws"))),$e=C(m(gn,d("p2p")),gn),yn=C(m(vt,d("http")),m(ze,d("http")),m(Mt,d("http"))),bn=C(m(vt,d("https")),m(ze,d("https")),m(Mt,d("https"))),Ho=m(He,d("webrtc-direct"),d("certhash")),Xo=C(m(Ho,d("p2p")),Ho),Wo=m(Vc,d("webtransport"),d("certhash"),d("certhash")),Yo=C(m(Wo,d("p2p")),Wo),Qo=C(m(Ve,d("p2p-webrtc-star"),d("p2p")),m($e,d("p2p-webrtc-star"),d("p2p")),m(Ve,d("p2p-webrtc-star")),m($e,d("p2p-webrtc-star"))),hf=C(m(Ve,d("p2p-websocket-star"),d("p2p")),m($e,d("p2p-websocket-star"),d("p2p")),m(Ve,d("p2p-websocket-star")),m($e,d("p2p-websocket-star"))),Jo=C(m(yn,d("p2p-webrtc-direct"),d("p2p")),m(bn,d("p2p-webrtc-direct"),d("p2p")),m(yn,d("p2p-webrtc-direct")),m(bn,d("p2p-webrtc-direct"))),Bt=C(mn,gn,yn,bn,Qo,Jo,vt,Bc,Gc,Mt,Xo,Yo),pf=C(m(Bt,d("p2p-stardust"),d("p2p")),m(Bt,d("p2p-stardust"))),Ct=C(m(Bt,d("p2p")),Qo,Jo,Xo,Yo,d("p2p")),Ko=C(m(Ct,d("p2p-circuit"),Ct),m(Ct,d("p2p-circuit")),m(d("p2p-circuit"),Ct),m(Bt,d("p2p-circuit")),m(d("p2p-circuit"),Bt),d("p2p-circuit")),Zo=()=>C(m(Ko,Zo),Ko),Ft=Zo(),mf=C(m(Ft,Ct,Ft),m(Ct,Ft),m(Ft,Ct),Ft,Ct);var gf=C(m(Ft,d("webrtc"),d("p2p")),m(Ft,d("webrtc")),m(Bt,d("webrtc"),d("p2p")),m(Bt,d("webrtc")),d("webrtc"));function qo(r){function t(e){let o;try{o=K(e)}catch{return!1}let n=r(o.protoNames());return n===null?!1:n===!0||n===!1?n:n.length===0}return t}function m(...r){function t(e){if(e.length<r.length)return null;let o=e;return r.some(n=>(o=typeof n=="function"?n().partialMatch(e):n.partialMatch(e),Array.isArray(o)&&(e=o),o===null)),o}return{toString:function(){return"{ "+r.join(" ")+" }"},input:r,matches:qo(t),partialMatch:t}}function C(...r){function t(o){let n=null;return r.some(i=>{let s=typeof i=="function"?i().partialMatch(o):i.partialMatch(o);return s!=null?(n=s,!0):!1}),n}return{toString:function(){return"{ "+r.join(" ")+" }"},input:r,matches:qo(t),partialMatch:t}}function d(r){let t=r;function e(n){let i;try{i=K(n)}catch{return!1}let s=i.protoNames();return s.length===1&&s[0]===t}function o(n){return n.length===0?null:n[0]===t?n.slice(1):null}return{toString:function(){return t},matches:e,partialMatch:o}}var We=class extends Event{type;detail;constructor(t,e){super(t),this.type=t,this.detail=e}};var oi=St(H("net"),1);var wn={ERR_INVALID_IP_PARAMETER:"ERR_INVALID_IP_PARAMETER",ERR_INVALID_PORT_PARAMETER:"ERR_INVALID_PORT_PARAMETER",ERR_INVALID_IP:"ERR_INVALID_IP"};function jo(r,t){if(typeof r!="string")throw new P(`invalid ip provided: ${r}`,wn.ERR_INVALID_IP_PARAMETER);if(typeof t=="string"&&(t=parseInt(t)),isNaN(t))throw new P(`invalid port provided: ${t}`,wn.ERR_INVALID_PORT_PARAMETER);if((0,ct.isIPv4)(r))return K(`/ip4/${r}/tcp/${t}`);if((0,ct.isIPv6)(r))return K(`/ip6/${r}/tcp/${t}`);throw new P(`invalid ip:port for creating a multiaddr: ${r}:${t}`,wn.ERR_INVALID_IP)}function ti(r){if(Hc(r))return async function*(){let t=r.getReader();try{for(;;){let{done:e,value:o}=await t.read();if(e)return;yield o}}finally{t.releaseLock()}}();if(zc(r))return r;throw new Error("unknown stream")}function zc(r){return r[Symbol.asyncIterator]!=null}function Hc(r){return typeof r?.getReader=="function"}function ei(r){return async t=>{let e=async()=>{Wc(t)&&await t.return(void 0)},o,n,i=w=>{o=w,e().catch(E=>{E=new AggregateError([o,E],"The Writable emitted an error, additionally an error occurred while ending the Source")}).finally(()=>{n?.(w)})},s,c=!1,a=()=>{c=!0,s?.()},f,u=!1,l=()=>{u=!0,f?.()},g,b=()=>{g?.()},p=async()=>new Promise((w,E)=>{s=g=w,n=E,r.once("drain",b)}),y=async()=>(await e(),new Promise((w,E)=>{if(c||u||o!=null){w();return}f=s=w,n=E})),h=()=>{r.removeListener("error",i),r.removeListener("close",a),r.removeListener("finish",l),r.removeListener("drain",b)};r.once("error",i),r.once("close",a),r.once("finish",l);try{for await(let w of t){if(!r.writable||r.destroyed||o!=null)break;r.write(w)||await p()}}catch(w){o==null&&r.destroy(w),o=w}try{if(r.writable&&r.end(),await y(),o!=null)throw o}finally{h()}}}function Wc(r){return r.return!=null}function En(r){return{sink:ei(r),source:ti(r)}}var xn=St(H("os"),1),ri=St(H("path"),1);var Kc={ip4:"IPv4",ip6:"IPv6"};function jt(r,t={}){let e=r.getPath();return e!=null?xn.default.platform()==="win32"?{path:ri.default.join("\\\\.\\pipe\\",e)}:{path:e}:{...t,...r.toOptions()}}function In(r,t,e){let o=n=>K(`/${r}/${n}/tcp/${e}`);return(Xc(t)?Qc(Kc[r]):[t]).map(o)}function Xc(r){return["0.0.0.0","::"].includes(r)}var Yc=xn.default.networkInterfaces();function Qc(r){let t=[];for(let[,e]of Object.entries(Yc))if(e!=null)for(let o of e)o.family===r&&t.push(o.address);return t}var Ke=(r,t)=>{let e=null,o=t.logger.forComponent("libp2p:tcp:socket"),n=t.metrics,i=t.metricPrefix??"",s=t.socketInactivityTimeout??3e5,c=t.socketCloseTimeout??500;t.listeningAddr?.getPath()!=null&&(t.remoteAddr=t.listeningAddr),t.remoteAddr?.getPath()!=null&&(t.localAddr=t.remoteAddr);let a;if(t.remoteAddr!=null)a=t.remoteAddr;else{if(r.remoteAddress==null||r.remotePort==null)throw new P("Could not determine remote address or port","ERR_NO_REMOTE_ADDRESS");a=jo(r.remoteAddress,r.remotePort)}let f=jt(a),u=f.path??`${f.host??""}:${f.port??""}`,{sink:l,source:g}=En(r);r.setTimeout(s,()=>{o("%s socket read timeout",u),n?.increment({[`${i}timeout`]:!0});let p;r.readable&&(p=new P("Socket read timeout","ERR_SOCKET_READ_TIMEOUT")),r.destroy(p)}),r.once("close",()=>{o("%s socket close",u),n?.increment({[`${i}close`]:!0}),b.timeline.close==null&&(b.timeline.close=Date.now())}),r.once("end",()=>{o("%s socket end",u),n?.increment({[`${i}end`]:!0})});let b={async sink(p){try{await l(async function*(){for await(let y of p)y instanceof Uint8Array?yield y:yield y.subarray()}())}catch(y){y.type!=="aborted"&&o.error("%s error in sink",u,y)}r.end()},source:g,remoteAddr:a,timeline:{open:Date.now()},async close(p={}){if(r.destroyed){o("The %s socket is destroyed",u);return}if(e!=null)return o("The %s socket is closed or closing",u),e;if(p.signal==null){let h=AbortSignal.timeout(c);p={...p,signal:h}}let y=()=>{r.destroy(new P("Destroying socket after timeout","ERR_CLOSE_TIMEOUT"))};p.signal?.addEventListener("abort",y);try{o("%s closing socket",u),e=new Promise((h,w)=>{r.once("close",()=>{o("%s socket closed",u),h()}),r.once("error",E=>{o("%s socket error",u,E),b.timeline.close==null&&(b.timeline.close=Date.now()),r.destroyed||w(E)}),r.setTimeout(c),r.end(),r.writableLength>0?r.once("drain",()=>{o("%s socket drained",u),r.destroy()}):r.destroy()}),await e}catch(h){this.abort(h)}finally{p.signal?.removeEventListener("abort",y)}},abort:p=>{o("%s socket abort due to error",u,p),r.destroyed||r.destroy(p),b.timeline.close==null&&(b.timeline.close=Date.now())},log:o};return b};async function ni(r,t){try{await r.close()}catch(e){t.log.error("an error occurred closing the connection",e),r.abort(e)}}var _;(function(r){r[r.INACTIVE=0]="INACTIVE",r[r.ACTIVE=1]="ACTIVE",r[r.PAUSED=2]="PAUSED"})(_||(_={}));var Xe=class extends Fe{context;server;connections=new Set;status={code:_.INACTIVE};metrics;addr;log;constructor(t){if(super(),this.context=t,t.keepAlive=t.keepAlive??!0,t.noDelay=t.noDelay??!0,this.log=t.logger.forComponent("libp2p:tcp:listener"),this.addr="unknown",this.server=oi.default.createServer(t,this.onSocket.bind(this)),t.maxConnections!==void 0&&(this.server.maxConnections=t.maxConnections),t.closeServerOnMaxConnections!=null&&t.closeServerOnMaxConnections.closeAbove<t.closeServerOnMaxConnections.listenBelow)throw new P("closeAbove must be >= listenBelow","ERR_CONNECTION_LIMITS");this.server.on("listening",()=>{if(t.metrics!=null){let e=this.server.address();e==null?this.addr="unknown":typeof e=="string"?this.addr=e:this.addr=`${e.address}:${e.port}`,t.metrics?.registerMetricGroup("libp2p_tcp_inbound_connections_total",{label:"address",help:"Current active connections in TCP listener",calculate:()=>({[this.addr]:this.connections.size})}),this.metrics={status:t.metrics.registerMetricGroup("libp2p_tcp_listener_status_info",{label:"address",help:"Current status of the TCP listener socket"}),errors:t.metrics.registerMetricGroup("libp2p_tcp_listener_errors_total",{label:"address",help:"Total count of TCP listener errors by type"}),events:t.metrics.registerMetricGroup("libp2p_tcp_listener_events_total",{label:"address",help:"Total count of TCP listener events by type"})},this.metrics?.status.update({[this.addr]:_.ACTIVE})}this.safeDispatchEvent("listening")}).on("error",e=>{this.metrics?.errors.increment({[`${this.addr} listen_error`]:!0}),this.safeDispatchEvent("error",{detail:e})}).on("close",()=>{this.metrics?.status.update({[this.addr]:this.status.code}),this.status.code!==_.PAUSED&&this.safeDispatchEvent("close")})}onSocket(t){if(this.status.code!==_.ACTIVE)throw new P("Server is not listening yet","ERR_SERVER_NOT_RUNNING");t.on("error",o=>{this.log("socket error",o),this.metrics?.events.increment({[`${this.addr} error`]:!0})});let e;try{e=Ke(t,{listeningAddr:this.status.listeningAddr,socketInactivityTimeout:this.context.socketInactivityTimeout,socketCloseTimeout:this.context.socketCloseTimeout,metrics:this.metrics?.events,metricPrefix:`${this.addr} `,logger:this.context.logger})}catch(o){this.log.error("inbound connection failed",o),this.metrics?.errors.increment({[`${this.addr} inbound_to_connection`]:!0});return}this.log("new inbound connection %s",e.remoteAddr);try{this.context.upgrader.upgradeInbound(e).then(o=>{this.log("inbound connection upgraded %s",e.remoteAddr),this.connections.add(e),t.once("close",()=>{this.connections.delete(e),this.context.closeServerOnMaxConnections!=null&&this.connections.size<this.context.closeServerOnMaxConnections.listenBelow&&this.resume().catch(n=>{this.log.error("error attempting to listen server once connection count under limit",n),this.context.closeServerOnMaxConnections?.onListenError?.(n)})}),this.context.handler!=null&&this.context.handler(o),this.context.closeServerOnMaxConnections!=null&&this.connections.size>=this.context.closeServerOnMaxConnections.closeAbove&&this.pause(!1).catch(n=>{this.log.error("error attempting to close server once connection count over limit",n)}),this.safeDispatchEvent("connection",{detail:o})}).catch(async o=>{this.log.error("inbound connection failed",o),this.metrics?.errors.increment({[`${this.addr} inbound_upgrade`]:!0}),await ni(e,{log:this.log})}).catch(o=>{this.log.error("closing inbound connection failed",o)})}catch(o){this.log.error("inbound connection failed",o),ni(e,{log:this.log}).catch(n=>{this.log.error("closing inbound connection failed",n),this.metrics?.errors.increment({[`${this.addr} inbound_closing_failed`]:!0})})}}getAddrs(){if(this.status.code===_.INACTIVE)return[];let t=[],e=this.server.address(),{listeningAddr:o,peerId:n}=this.status;if(e==null)return[];if(typeof e=="string")t=[o];else try{o.toString().startsWith("/ip4")?t=t.concat(In("ip4",e.address,e.port)):e.family==="IPv6"&&(t=t.concat(In("ip6",e.address,e.port)))}catch(i){this.log.error("could not turn %s:%s into multiaddr",e.address,e.port,i)}return t.map(i=>n!=null?i.encapsulate(`/p2p/${n}`):i)}async listen(t){if(this.status.code===_.ACTIVE||this.status.code===_.PAUSED)throw new P("server is already listening","ERR_SERVER_ALREADY_LISTENING");let e=t.getPeerId(),o=e==null?t.decapsulateCode(421):t,{backlog:n}=this.context;try{this.status={code:_.ACTIVE,listeningAddr:o,peerId:e,netConfig:jt(o,{backlog:n})},await this.resume()}catch(i){throw this.status={code:_.INACTIVE},i}}async close(){let t=new P("Listener is closing","ERR_LISTENER_CLOSING");this.connections.forEach(e=>{e.abort(t)}),await this.pause(!0)}async resume(){if(this.server.listening||this.status.code===_.INACTIVE)return;let t=this.status.netConfig;await new Promise((e,o)=>{this.server.once("error",o),this.server.listen(t,e)}),this.status={...this.status,code:_.ACTIVE},this.log("listening on %s",this.server.address())}async pause(t){if(!this.server.listening&&this.status.code===_.PAUSED&&t){this.status={code:_.INACTIVE};return}!this.server.listening||this.status.code!==_.ACTIVE||(this.log("closing server on %s",this.server.address()),this.status=t?{code:_.INACTIVE}:{...this.status,code:_.PAUSED},await new Promise((e,o)=>{this.server.close(n=>{if(n!=null){o(n);return}e()})}))}};var An=class{opts;metrics;components;log;constructor(t,e={}){this.log=t.logger.forComponent("libp2p:tcp"),this.opts=e,this.components=t,t.metrics!=null&&(this.metrics={dialerEvents:t.metrics.registerCounterGroup("libp2p_tcp_dialer_events_total",{label:"event",help:"Total count of TCP dialer events by type"})})}[xo]=!0;[Symbol.toStringTag]="@libp2p/tcp";[Co]=["@libp2p/transport"];async dial(t,e){e.keepAlive=e.keepAlive??!0,e.noDelay=e.noDelay??!0;let o=await this._connect(t,e);o.on("error",c=>{this.log("socket error",c)});let n=Ke(o,{remoteAddr:t,socketInactivityTimeout:this.opts.outboundSocketInactivityTimeout,socketCloseTimeout:this.opts.socketCloseTimeout,metrics:this.metrics?.dialerEvents,logger:this.components.logger}),i=()=>{n.close().catch(c=>{this.log.error("Error closing maConn after abort",c)})};e.signal?.addEventListener("abort",i,{once:!0}),this.log("new outbound connection %s",n.remoteAddr);let s=await e.upgrader.upgradeOutbound(n);if(this.log("outbound connection %s upgraded",n.remoteAddr),e.signal?.removeEventListener("abort",i),e.signal?.aborted===!0)throw s.close().catch(c=>{this.log.error("Error closing conn after abort",c)}),new fe;return s}async _connect(t,e){return e.signal?.throwIfAborted(),e.onProgress?.(new We("tcp:open-connection")),new Promise((o,n)=>{let i=Date.now(),s=jt(t,{...this.opts.dialOpts??{},...e});this.log("dialing %a",t);let c=ii.default.connect(s),a=b=>{let p=s.path??`${s.host??""}:${s.port}`;b.message=`connection error ${p}: ${b.message}`,this.metrics?.dialerEvents.increment({error:!0}),g(b)},f=()=>{this.log("connection timeout %a",t),this.metrics?.dialerEvents.increment({timeout:!0});let b=new P(`connection timeout after ${Date.now()-i}ms`,"ERR_CONNECT_TIMEOUT");c.emit("error",b)},u=()=>{this.log("connection opened %a",t),this.metrics?.dialerEvents.increment({connect:!0}),g()},l=()=>{this.log("connection aborted %a",t),this.metrics?.dialerEvents.increment({abort:!0}),c.destroy(),g(new fe)},g=b=>{if(c.removeListener("error",a),c.removeListener("timeout",f),c.removeListener("connect",u),e.signal!=null&&e.signal.removeEventListener("abort",l),b!=null){n(b);return}o(c)};c.on("error",a),c.on("timeout",f),c.on("connect",u),e.signal!=null&&e.signal.addEventListener("abort",l)})}createListener(t){return new Xe({...this.opts.listenOpts??{},...t,maxConnections:this.opts.maxConnections,backlog:this.opts.backlog,closeServerOnMaxConnections:this.opts.closeServerOnMaxConnections,socketInactivityTimeout:this.opts.inboundSocketInactivityTimeout,socketCloseTimeout:this.opts.socketCloseTimeout,metrics:this.components.metrics,logger:this.components.logger})}listenFilter(t){return t=Array.isArray(t)?t:[t],t.filter(e=>e.protoCodes().includes(290)?!1:e.protoCodes().includes(400)?!0:vt.matches(e.decapsulateCode(421)))}dialFilter(t){return this.listenFilter(t)}};function si(r={}){return t=>new An(t,r)}var ai=Symbol.for("@achingbrain/uint8arraylist");function ci(r,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let e=0;for(let o of r){let n=e+o.byteLength;if(t<n)return{buf:o,index:t-e};e=n}throw new RangeError("index is out of bounds")}function Ye(r){return!!r?.[ai]}var tt=class r{bufs;length;[ai]=!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 o of t)if(o instanceof Uint8Array)e+=o.byteLength,this.bufs.push(o);else if(Ye(o))e+=o.byteLength,this.bufs.push(...o.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 o of t.reverse())if(o instanceof Uint8Array)e+=o.byteLength,this.bufs.unshift(o);else if(Ye(o))e+=o.byteLength,this.bufs.unshift(...o.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}get(t){let e=ci(this.bufs,t);return e.buf[e.index]}set(t,e){let o=ci(this.bufs,t);o.buf[o.index]=e}write(t,e=0){if(t instanceof Uint8Array)for(let o=0;o<t.length;o++)this.set(e+o,t[o]);else if(Ye(t))for(let o=0;o<t.length;o++)this.set(e+o,t.get(o));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:o,length:n}=this._subList(t,e);return st(o,n)}subarray(t,e){let{bufs:o,length:n}=this._subList(t,e);return o.length===1?o[0]:st(o,n)}sublist(t,e){let{bufs:o,length:n}=this._subList(t,e),i=new r;return i.length=n,i.bufs=[...o],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 o=[],n=0;for(let i=0;i<this.bufs.length;i++){let s=this.bufs[i],c=n,a=c+s.byteLength;if(n=a,t>=a)continue;let f=t>=c&&t<a,u=e>c&&e<=a;if(f&&u){if(t===c&&e===a){o.push(s);break}let l=t-c;o.push(s.subarray(l,l+(e-t)));break}if(f){if(t===0){o.push(s);continue}o.push(s.subarray(t-c));continue}if(u){if(e===a){o.push(s);break}o.push(s.subarray(0,e-c));break}o.push(s)}return{bufs:o,length:e-t}}indexOf(t,e=0){if(!Ye(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let o=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 n=o.byteLength;if(n===0)throw new TypeError("search must be at least 1 byte long");let i=256,s=new Int32Array(i);for(let l=0;l<i;l++)s[l]=-1;for(let l=0;l<n;l++)s[o[l]]=l;let c=s,a=this.byteLength-o.byteLength,f=o.byteLength-1,u;for(let l=e;l<=a;l+=u){u=0;for(let g=f;g>=0;g--){let b=this.get(l+g);if(o[g]!==b){u=Math.max(1,g-c[b]);break}}if(u===0)return l}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 o=W(1);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt8(0,e),this.write(o,t)}getInt16(t,e){let o=this.subarray(t,t+2);return new DataView(o.buffer,o.byteOffset,o.byteLength).getInt16(0,e)}setInt16(t,e,o){let n=ht(2);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt16(0,e,o),this.write(n,t)}getInt32(t,e){let o=this.subarray(t,t+4);return new DataView(o.buffer,o.byteOffset,o.byteLength).getInt32(0,e)}setInt32(t,e,o){let n=ht(4);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt32(0,e,o),this.write(n,t)}getBigInt64(t,e){let o=this.subarray(t,t+8);return new DataView(o.buffer,o.byteOffset,o.byteLength).getBigInt64(0,e)}setBigInt64(t,e,o){let n=ht(8);new DataView(n.buffer,n.byteOffset,n.byteLength).setBigInt64(0,e,o),this.write(n,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 o=W(1);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint8(0,e),this.write(o,t)}getUint16(t,e){let o=this.subarray(t,t+2);return new DataView(o.buffer,o.byteOffset,o.byteLength).getUint16(0,e)}setUint16(t,e,o){let n=ht(2);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint16(0,e,o),this.write(n,t)}getUint32(t,e){let o=this.subarray(t,t+4);return new DataView(o.buffer,o.byteOffset,o.byteLength).getUint32(0,e)}setUint32(t,e,o){let n=ht(4);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint32(0,e,o),this.write(n,t)}getBigUint64(t,e){let o=this.subarray(t,t+8);return new DataView(o.buffer,o.byteOffset,o.byteLength).getBigUint64(0,e)}setBigUint64(t,e,o){let n=ht(8);new DataView(n.buffer,n.byteOffset,n.byteLength).setBigUint64(0,e,o),this.write(n,t)}getFloat32(t,e){let o=this.subarray(t,t+4);return new DataView(o.buffer,o.byteOffset,o.byteLength).getFloat32(0,e)}setFloat32(t,e,o){let n=ht(4);new DataView(n.buffer,n.byteOffset,n.byteLength).setFloat32(0,e,o),this.write(n,t)}getFloat64(t,e){let o=this.subarray(t,t+8);return new DataView(o.buffer,o.byteOffset,o.byteLength).getFloat64(0,e)}setFloat64(t,e,o){let n=ht(8);new DataView(n.buffer,n.byteOffset,n.byteLength).setFloat64(0,e,o),this.write(n,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(!_t(this.bufs[e],t.bufs[e]))return!1;return!0}static fromUint8Arrays(t,e){let o=new r;return o.bufs=t,e==null&&(e=t.reduce((n,i)=>n+i.byteLength,0)),o.length=e,o}};function Qe(r){return r[Symbol.asyncIterator]!=null}var Je=r=>{let t=v(r),e=W(t);return ft(r,e),Je.bytes=t,e};Je.bytes=0;function Ze(r,t){t=t??{};let e=t.lengthEncoder??Je;function*o(n){let i=e(n.byteLength);i instanceof Uint8Array?yield i:yield*i,n instanceof Uint8Array?yield n:yield*n}return Qe(r)?async function*(){for await(let n of r)yield*o(n)}():function*(){for(let n of r)yield*o(n)}()}Ze.single=(r,t)=>{t=t??{};let e=t.lengthEncoder??Je;return new tt(e(r.byteLength),r)};var te=St(di(),1);var qc=8,jc=1024*1024*4,Gt;(function(r){r[r.LENGTH=0]="LENGTH",r[r.DATA=1]="DATA"})(Gt||(Gt={}));var vn=r=>{let t=at(r);return vn.bytes=v(t),t};vn.bytes=0;function Cn(r,t){let e=new tt,o=Gt.LENGTH,n=-1,i=t?.lengthDecoder??vn,s=t?.maxLengthLength??qc,c=t?.maxDataLength??jc;function*a(){for(;e.byteLength>0;){if(o===Gt.LENGTH)try{if(n=i(e),n<0)throw(0,te.default)(new Error("invalid message length"),"ERR_INVALID_MSG_LENGTH");if(n>c)throw(0,te.default)(new Error("message length too long"),"ERR_MSG_DATA_TOO_LONG");let f=i.bytes;e.consume(f),t?.onLength!=null&&t.onLength(n),o=Gt.DATA}catch(f){if(f instanceof RangeError){if(e.byteLength>s)throw(0,te.default)(new Error("message length length too long"),"ERR_MSG_LENGTH_TOO_LONG");break}throw f}if(o===Gt.DATA){if(e.byteLength<n)break;let f=e.sublist(0,n);e.consume(n),t?.onData!=null&&t.onData(f),yield f,o=Gt.LENGTH}}}return Qe(r)?async function*(){for await(let f of r)e.append(f),yield*a();if(e.byteLength>0)throw(0,te.default)(new Error("unexpected end of input"),"ERR_UNEXPECTED_EOF")}():function*(){for(let f of r)e.append(f),yield*a();if(e.byteLength>0)throw(0,te.default)(new Error("unexpected end of input"),"ERR_UNEXPECTED_EOF")}()}Cn.fromReader=(r,t)=>{let e=1,o=async function*(){for(;;)try{let{done:i,value:s}=await r.next(e);if(i===!0)return;s!=null&&(yield s)}catch(i){if(i.code==="ERR_UNDER_READ")return{done:!0,value:null};throw i}finally{e=1}}();return Cn(o,{...t??{},onLength:i=>{e=i}})};function yt(){let r={};return r.promise=new Promise((t,e)=>{r.resolve=t,r.reject=e}),r}var qe=class extends Error{type;code;constructor(t,e){super(t??"The operation was aborted"),this.type="aborted",this.name="AbortError",this.code=e??"ABORT_ERR"}};async function fi(r,t,e){if(t==null)return r;if(t.aborted)return Promise.reject(new qe(e?.errorMessage,e?.errorCode));let o,n=new qe(e?.errorMessage,e?.errorCode);try{return await Promise.race([r,new Promise((i,s)=>{o=()=>{s(n)},t.addEventListener("abort",o)})])}finally{o!=null&&t.removeEventListener("abort",o)}}var Sn=class{readNext;haveNext;ended;nextResult;constructor(){this.ended=!1,this.readNext=yt(),this.haveNext=yt()}[Symbol.asyncIterator](){return this}async next(){if(this.nextResult==null&&await this.haveNext.promise,this.nextResult==null)throw new Error("HaveNext promise resolved but nextResult was undefined");let t=this.nextResult;return this.nextResult=void 0,this.readNext.resolve(),this.readNext=yt(),t}async throw(t){return this.ended=!0,t!=null&&(this.haveNext.promise.catch(()=>{}),this.haveNext.reject(t)),{done:!0,value:void 0}}async return(){let t={done:!0,value:void 0};return await this._push(void 0),t}async push(t,e){await this._push(t,e)}async end(t,e){t!=null?await this.throw(t):await this._push(void 0,e)}async _push(t,e){if(t!=null&&this.ended)throw new Error("Cannot push value onto an ended pushable");for(;this.nextResult!=null;)await this.readNext.promise;t!=null?this.nextResult={done:!1,value:t}:(this.ended=!0,this.nextResult={done:!0,value:void 0}),this.haveNext.resolve(),this.haveNext=yt(),await fi(this.readNext.promise,e?.signal,e)}};function hi(){return new Sn}var je=class extends Error{code;constructor(t,e){super(t),this.code=e}},Tn=class extends je{type;constructor(t){super(t,"ABORT_ERR"),this.type="aborted"}};function pi(r,t){let e=hi();r.sink(e).catch(async s=>{await e.end(s)}),r.sink=async s=>{for await(let c of s)await e.push(c);await e.end()};let o=r.source;r.source[Symbol.iterator]!=null?o=r.source[Symbol.iterator]():r.source[Symbol.asyncIterator]!=null&&(o=r.source[Symbol.asyncIterator]());let n=new tt;return{read:async(s,c)=>{c?.signal?.throwIfAborted();let a,f=new Promise((u,l)=>{a=()=>{l(new Tn("Read aborted"))},c?.signal?.addEventListener("abort",a)});try{if(s==null){let{done:l,value:g}=await Promise.race([o.next(),f]);return l===!0?new tt:g}for(;n.byteLength<s;){let{value:l,done:g}=await Promise.race([o.next(),f]);if(g===!0)throw new je("unexpected end of input","ERR_UNEXPECTED_EOF");n.append(l)}let u=n.sublist(0,s);return n.consume(s),u}finally{a!=null&&c?.signal?.removeEventListener("abort",a)}},write:async(s,c)=>{c?.signal?.throwIfAborted(),s instanceof Uint8Array?await e.push(s,c):await e.push(s.subarray(),c)},unwrap:()=>{if(n.byteLength>0){let s=r.source;r.source=async function*(){t?.yieldBytes===!1?yield n:yield*n,yield*s}()}return r}}}var tr=class extends Error{code;constructor(t,e){super(t),this.code=e}};function ee(r,t={}){let e=pi(r,t);t.maxDataLength!=null&&t.maxLengthLength==null&&(t.maxLengthLength=v(t.maxDataLength));let o=t?.lengthDecoder??at,n=t?.lengthEncoder??ft;return{read:async s=>{let c=-1,a=new tt;for(;;){a.append(await e.read(1,s));try{c=o(a)}catch(f){if(f instanceof RangeError)continue;throw f}if(t?.maxLengthLength!=null&&a.byteLength>t.maxLengthLength)throw new tr("message length length too long","ERR_MSG_LENGTH_TOO_LONG");if(c>-1)break}if(t?.maxDataLength!=null&&c>t.maxDataLength)throw new tr("message length too long","ERR_MSG_DATA_TOO_LONG");return e.read(c,s)},write:async(s,c)=>{await e.write(new tt(n(s.byteLength),s),c)},writeV:async(s,c)=>{let a=new tt(...s.flatMap(f=>[n(f.byteLength),f]));await e.write(a,c)},unwrap:()=>e.unwrap()}}var er=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}},re=class{size;hwm;head;tail;constructor(t={}){this.hwm=t.splitLimit??16,this.head=new er(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 er(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 Ln=class extends Error{type;code;constructor(t,e){super(t??"The operation was aborted"),this.type="aborted",this.code=e??"ABORT_ERR"}};function ne(r={}){return ea(e=>{let o=e.shift();if(o==null)return{done:!0};if(o.error!=null)throw o.error;return{done:o.done===!0,value:o.value}},r)}function ea(r,t){t=t??{};let e=t.onEnd,o=new re,n,i,s,c=yt(),a=async()=>{try{return o.isEmpty()?s?{done:!0}:await new Promise((h,w)=>{i=E=>{i=null,o.push(E);try{h(r(o))}catch(R){w(R)}return n}}):r(o)}finally{o.isEmpty()&&queueMicrotask(()=>{c.resolve(),c=yt()})}},f=h=>i!=null?i(h):(o.push(h),n),u=h=>(o=new re,i!=null?i({error:h}):(o.push({error:h}),n)),l=h=>{if(s)return n;if(t?.objectMode!==!0&&h?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return f({done:!1,value:h})},g=h=>s?n:(s=!0,h!=null?u(h):f({done:!0})),b=()=>(o=new re,g(),{done:!0}),p=h=>(g(h),{done:!0});if(n={[Symbol.asyncIterator](){return this},next:a,return:b,throw:p,push:l,end:g,get readableLength(){return o.size},onEmpty:async h=>{let w=h?.signal;if(w?.throwIfAborted(),o.isEmpty())return;let E,R;w!=null&&(E=new Promise((k,Y)=>{R=()=>{Y(new Ln)},w.addEventListener("abort",R)}));try{await Promise.race([c.promise,E])}finally{R!=null&&w!=null&&w?.removeEventListener("abort",R)}}},e==null)return n;let y=n;return n={[Symbol.asyncIterator](){return this},next(){return y.next()},throw(h){return y.throw(h),e!=null&&(e(h),e=void 0),{done:!0}},return(){return y.return(),e!=null&&(e(),e=void 0),{done:!0}},push:l,end(h){return y.end(h),e!=null&&(e(h),e=void 0),n},get readableLength(){return y.readableLength},onEmpty:h=>y.onEmpty(h)},n}function ra(r){return r[Symbol.asyncIterator]!=null}function na(...r){let t=[];for(let e of r)ra(e)||t.push(e);return t.length===r.length?function*(){for(let e of t)yield*e}():async function*(){let e=ne({objectMode:!0});Promise.resolve().then(async()=>{try{await Promise.all(r.map(async o=>{for await(let n of o)e.push(n)})),e.end()}catch(o){e.end(o)}}),yield*e}()}var mi=na;function Rn(r,...t){if(r==null)throw new Error("Empty pipeline");if(Nn(r)){let o=r;r=()=>o.source}else if(yi(r)||gi(r)){let o=r;r=()=>o}let e=[r,...t];if(e.length>1&&Nn(e[e.length-1])&&(e[e.length-1]=e[e.length-1].sink),e.length>2)for(let o=1;o<e.length-1;o++)Nn(e[o])&&(e[o]=ia(e[o]));return oa(...e)}var oa=(...r)=>{let t;for(;r.length>0;)t=r.shift()(t);return t},gi=r=>r?.[Symbol.asyncIterator]!=null,yi=r=>r?.[Symbol.iterator]!=null,Nn=r=>r==null?!1:r.sink!=null&&r.source!=null,ia=r=>t=>{let e=r.sink(t);if(e?.then!=null){let o=ne({objectMode:!0});e.then(()=>{o.end()},s=>{o.end(s)});let n,i=r.source;if(gi(i))n=async function*(){yield*i,o.end()};else if(yi(i))n=function*(){yield*i,o.end()};else throw new Error("Unknown duplex source type - must be Iterable or AsyncIterable");return mi(o,n())}return r.source};function bi(r,t){let e=ee(r,t),o={read:async(n,i)=>{let s=await e.read(i);return n.decode(s)},write:async(n,i,s)=>{await e.write(i.encode(n),s)},writeV:async(n,i,s)=>{await e.writeV(n.map(c=>i.encode(c)),s)},pb:n=>({read:async i=>o.read(n,i),write:async(i,s)=>o.write(i,n,s),writeV:async(i,s)=>o.writeV(i,n,s),unwrap:()=>o}),unwrap:()=>e.unwrap()};return o}function sa(r){return r[Symbol.asyncIterator]!=null}function ca(r){if(sa(r))return(async()=>{for await(let t of r);})();for(let t of r);}var Dn=ca;function X(r){return N.encode({type:N.Type.OK,peers:[],...r}).subarray()}function V(r){return N.encode({type:N.Type.ERROR,error:{msg:r.message},peers:[]}).subarray()}var rr=Ot("libp2p:daemon-server:dht"),nr=class{dht;constructor(t){let{dht:e}=t;this.dht=e}async*provide(t){try{await Dn(this.dht.provide(t)),yield X()}catch(e){rr.error(e),yield V(e)}}async*getClosestPeers(t){yield X({dht:{type:U.Type.BEGIN}});for await(let e of this.dht.getClosestPeers(t))e.name==="PEER_RESPONSE"&&(yield*e.closer.map(o=>U.encode({type:U.Type.VALUE,value:o.id.toBytes()})));yield U.encode({type:U.Type.END})}async*getPublicKey(t){yield V(new Error("FIX ME: not implemented"))}async*getValue(t){try{for await(let e of this.dht.get(t))e.name==="VALUE"&&(yield X({dht:{type:U.Type.VALUE,value:e.value}}))}catch(e){rr.error(e),yield V(e)}}async*putValue(t,e){try{await Dn(this.dht.put(t,e)),yield X()}catch(o){rr.error(o),yield V(o)}}async*findPeer(t){try{for await(let e of this.dht.findPeer(t))e.name==="FINAL_PEER"&&(yield X({dht:{type:U.Type.VALUE,peer:{id:e.peer.id.toBytes(),addrs:e.peer.multiaddrs.map(o=>o.bytes)}}}));throw new Error("Peer not found")}catch(e){rr.error(e),yield V(e)}}async*findProviders(t,e){yield X({dht:{type:U.Type.BEGIN}});try{let o=e,n=0;for await(let i of this.dht.findProviders(t))if(i.name==="PEER_RESPONSE"){for(let s of i.providers)n++,yield U.encode({type:U.Type.VALUE,peer:{id:s.id.toBytes(),addrs:(s.multiaddrs??[]).map(c=>c.bytes)}});if(o===n)break}}catch(o){yield V(o)}yield U.encode({type:U.Type.END})}};var or=Ot("libp2p:daemon-server:pubsub"),ir=class{pubsub;constructor(t){let{pubsub:e}=t;this.pubsub=e}async*getTopics(){try{yield X({pubsub:{topics:this.pubsub.getTopics(),peerIDs:[]}})}catch(t){or.error(t),yield V(t)}}async*subscribe(t){try{let e=ne();this.pubsub.subscribe(t),this.pubsub.addEventListener("message",o=>{let n=o.detail;n.topic===t&&(n.type==="signed"?e.push(de.encode({from:n.from.toBytes(),data:n.data,seqno:n.sequenceNumber==null?void 0:pt(n.sequenceNumber.toString(16).padStart(16,"0"),"base16"),topicIDs:[n.topic],signature:n.signature,key:n.key}).subarray()):e.push(de.encode({data:n.data,topicIDs:[n.topic]}).subarray()))}),yield X(),yield*e}catch(e){or.error(e),yield V(e)}}async*publish(t,e){try{await this.pubsub.publish(t,e),yield X()}catch(o){or.error(o),yield V(o)}}async*listPeers(t){try{yield X({pubsub:{topics:[t],peerIDs:this.pubsub.getSubscribers(t).map(e=>e.toBytes())}})}catch(e){or.error(e),yield V(e)}}};var aa=1<<22,z=Ot("libp2p:daemon-server"),sr=class{multiaddr;libp2p;tcp;listener;dhtOperations;pubsubOperations;constructor(t){let{multiaddr:e,libp2pNode:o}=t;this.multiaddr=e,this.libp2p=o,this.tcp=si()({logger:wo()}),this.listener=this.tcp.createListener({handler:this.handleConnection.bind(this),upgrader:Yr}),this._onExit=this._onExit.bind(this),o.services.dht!=null&&(this.dhtOperations=new nr({dht:o.services.dht})),o.services.pubsub!=null&&(this.pubsubOperations=new ir({pubsub:o.services.pubsub}))}async connect(t){if(t.connect==null||t.connect.addrs==null)throw new Error("Invalid request");let e=t.connect.peer,o=t.connect.addrs.map(i=>K(i)),n=Ut(e);return z("connect - adding multiaddrs %a to peer %p",o,n),await this.libp2p.peerStore.merge(n,{multiaddrs:o}),z("connect - dial %p",n),this.libp2p.dial(n)}async openStream(t){if(t.streamOpen==null||t.streamOpen.proto==null)throw new Error("Invalid request");let{peer:e,proto:o}=t.streamOpen,n=Ut(e);z("openStream - dial %p",n);let i=await this.libp2p.dial(n);z("openStream - open stream for protocol %s",o);let s=await i.newStream(o,{runOnTransientConnection:!0,runOnLimitedConnection:!0});return{streamInfo:{peer:n.toBytes(),addr:i.remoteAddr.bytes,proto:s.protocol??""},connection:s}}async registerStreamHandler(t){if(t.streamHandler==null||t.streamHandler.proto==null)throw new Error("Invalid request");let e=t.streamHandler.proto,o=K(t.streamHandler.addr),n;z("registerStreamHandler - handle %s",e),await this.libp2p.handle(e,({connection:i,stream:s})=>{Promise.resolve().then(async()=>{n=await this.tcp.dial(o,{upgrader:Yr});let c=Xt.encode({peer:i.remotePeer.toBytes(),addr:i.remoteAddr.bytes,proto:s.protocol??""}),a=Ze.single(c);await Rn(async function*(){yield a,yield*s.source}(),async function*(f){for await(let u of f)yield*u},n,s.sink)}).catch(async c=>{z.error(c),n!=null&&await n.close(c)}).finally(()=>{n?.close().catch(c=>{z.error(c)})})},{runOnTransientConnection:!0,runOnLimitedConnection:!0})}_listen(){process.on("SIGTERM",this._onExit),process.on("SIGINT",this._onExit),process.on("SIGHUP",this._onExit)}_onExit(){this.stop({exit:!0}).catch(t=>{z.error(t)})}async start(){this._listen(),await this.libp2p.start(),await this.listener.listen(this.multiaddr)}getMultiaddr(){let t=this.listener.getAddrs();if(t.length>0)return t[0];throw new Error("Not started")}async stop(t={exit:!1}){await this.libp2p.stop(),await this.listener.close(),t.exit&&z("server closed, exiting"),process.removeListener("SIGTERM",this._onExit),process.removeListener("SIGINT",this._onExit),process.removeListener("SIGHUP",this._onExit)}async*handlePeerStoreRequest(t){try{switch(t.type){case Pt.Type.GET_PROTOCOLS:if(t.id==null)throw new Error("Invalid request");let e=Ut(t.id),n=(await this.libp2p.peerStore.get(e)).protocols;yield X({peerStore:{protos:n}});return;case Pt.Type.GET_PEER_INFO:throw new Error("ERR_NOT_IMPLEMENTED");default:throw new Error("ERR_INVALID_REQUEST_TYPE")}}catch(e){z.error(e),yield V(e)}}async*handlePubsubRequest(t){try{if(this.libp2p.services.pubsub==null||this.pubsubOperations==null)throw new Error("PubSub not configured");switch(t.type){case gt.Type.GET_TOPICS:yield*this.pubsubOperations.getTopics();return;case gt.Type.SUBSCRIBE:if(t.topic==null)throw new Error("Invalid request");yield*this.pubsubOperations.subscribe(t.topic);return;case gt.Type.PUBLISH:if(t.topic==null||t.data==null)throw new Error("Invalid request");yield*this.pubsubOperations.publish(t.topic,t.data);return;case gt.Type.LIST_PEERS:if(t.topic==null)throw new Error("Invalid request");yield*this.pubsubOperations.listPeers(t.topic);return;default:throw new Error("ERR_INVALID_REQUEST_TYPE")}}catch(e){z.error(e),yield V(e)}}async*handleDHTRequest(t){try{if(this.libp2p.services.dht==null||this.dhtOperations==null)throw new Error("DHT not configured");switch(t.type){case it.Type.FIND_PEER:if(t.peer==null)throw new Error("Invalid request");yield*this.dhtOperations.findPeer(Ut(t.peer));return;case it.Type.FIND_PROVIDERS:if(t.cid==null)throw new Error("Invalid request");yield*this.dhtOperations.findProviders($.decode(t.cid),t.count??20);return;case it.Type.PROVIDE:if(t.cid==null)throw new Error("Invalid request");yield*this.dhtOperations.provide($.decode(t.cid));return;case it.Type.GET_CLOSEST_PEERS:if(t.key==null)throw new Error("Invalid request");yield*this.dhtOperations.getClosestPeers(t.key);return;case it.Type.GET_PUBLIC_KEY:if(t.peer==null)throw new Error("Invalid request");yield*this.dhtOperations.getPublicKey(Ut(t.peer));return;case it.Type.GET_VALUE:if(t.key==null)throw new Error("Invalid request");yield*this.dhtOperations.getValue(t.key);return;case it.Type.PUT_VALUE:if(t.key==null||t.value==null)throw new Error("Invalid request");yield*this.dhtOperations.putValue(t.key,t.value);return;default:throw new Error("ERR_INVALID_REQUEST_TYPE")}}catch(e){z.error(e),yield V(e)}}handleConnection(t){Promise.resolve().then(async()=>{let e=this,o=bi(t,{maxDataLength:aa}),n=await o.read(ot);z("read",n);try{switch(n.type){case ot.Type.CONNECT:{await e.connect(n),await o.write({type:N.Type.OK},N);break}case ot.Type.IDENTIFY:{await o.write({type:N.Type.OK,identify:{id:e.libp2p.peerId.toBytes(),addrs:e.libp2p.getMultiaddrs().map(i=>i.decapsulateCode(I("p2p").code)).map(i=>i.bytes)}},N);break}case ot.Type.LIST_PEERS:{let i=[],s=new Set;for(let c of e.libp2p.getConnections()){let a=c.remotePeer.toString();s.has(a)||(s.add(a),i.push({id:c.remotePeer.toBytes(),addrs:[c.remoteAddr.bytes]}))}await o.write({type:N.Type.OK,peers:i},N);break}case ot.Type.STREAM_OPEN:{let i=await e.openStream(n);await o.write({type:N.Type.OK,streamInfo:i.streamInfo},N);let s=o.unwrap();await Rn(s,i.connection,s);break}case ot.Type.STREAM_HANDLER:{await e.registerStreamHandler(n),await o.write({type:N.Type.OK},N);break}case ot.Type.PEERSTORE:{if(n.peerStore==null)throw new Error("ERR_INVALID_REQUEST");let i=o.unwrap(),s=ee(i);for await(let c of e.handlePeerStoreRequest(n.peerStore))await s.write(c);break}case ot.Type.PUBSUB:{if(n.pubsub==null)throw new Error("ERR_INVALID_REQUEST");let i=o.unwrap(),s=ee(i);for await(let c of e.handlePubsubRequest(n.pubsub))await s.write(c);break}case ot.Type.DHT:{if(n.dht==null)throw new Error("ERR_INVALID_REQUEST");let i=o.unwrap(),s=ee(i);for await(let c of e.handleDHTRequest(n.dht))await s.write(c);break}default:throw new Error("ERR_INVALID_REQUEST_TYPE")}}catch(i){z.error(i),await o.write({type:N.Type.ERROR,error:{msg:i.message},peers:[]},N)}finally{await o.unwrap().close()}}).catch(e=>{z.error("error handling incoming connection",e)})}},ua=(r,t)=>new sr({multiaddr:r,libp2pNode:t});return Ci(la);})();
4
+ `+i),r.push(o+"m+"+Nr(this.diff)+"\x1B[0m")}else r[0]=pu()+t+" "+r[0]}function pu(){return Ue.hideDate!=null?"":new Date().toISOString()+" "}function mu(...r){return process.stderr.write(Dr.default.format(...r)+`
5
+ `)}function gu(r){r!=null?process.env.DEBUG=r:delete process.env.DEBUG}function yu(){return process.env.DEBUG}function bu(r){r.inspectOpts={};let t=Object.keys(Ue);for(let e=0;e<t.length;e++)r.inspectOpts[t[e]]=Ue[t[e]]}function wu(r){r.o=function(t){return this.inspectOpts.colors=this.useColors,Dr.default.inspect(t,this.inspectOpts).split(`
6
+ `).map(e=>e.trim()).join(" ")},r.O=function(t){return this.inspectOpts.colors=this.useColors,Dr.default.inspect(t,this.inspectOpts)}}var is=Ao({init:bu,log:mu,formatArgs:hu,save:gu,load:yu,useColors:du,setupFormatters:wu,colors:os,inspectOpts:Ue});var mt=is;mt.formatters.b=r=>r==null?"undefined":M.baseEncode(r);mt.formatters.t=r=>r==null?"undefined":Pt.baseEncode(r);mt.formatters.m=r=>r==null?"undefined":no.baseEncode(r);mt.formatters.p=r=>r==null?"undefined":r.toString();mt.formatters.c=r=>r==null?"undefined":r.toString();mt.formatters.k=r=>r==null?"undefined":r.toString();mt.formatters.a=r=>r==null?"undefined":r.toString();function xu(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 ss(){return{forComponent(r){return ge(r)}}}function ge(r){let t=xu(`${r}:trace`);return mt.enabled(`${r}:trace`)&&mt.names.map(e=>e.toString()).find(e=>e.includes(":trace"))!=null&&(t=mt(`${r}:trace`)),Object.assign(mt(r),{error:mt(`${r}:error`),trace:t})}var To=Symbol.for("@libp2p/peer-id");var as=Symbol.for("@libp2p/transport");var cs;(function(r){r[r.FATAL_ALL=0]="FATAL_ALL",r[r.NO_FATAL=1]="NO_FATAL"})(cs||(cs={}));var Gt=class extends Error{static name="AbortError";constructor(t="The operation was aborted"){super(t),this.name="AbortError"}};var gt=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},Ur=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var Rr=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}};var Re=class extends Error{static name="TimeoutError";constructor(t="Timed out"){super(t),this.name="TimeoutError"}},_r=class extends Error{static name="NotStartedError";constructor(t="Not started"){super(t),this.name="NotStartedError"}},Mr=class extends Error{static name="AlreadyStartedError";constructor(t="Already started"){super(t),this.name="AlreadyStartedError"}};var ir=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var us=Y("events"),ls=(r,...t)=>{try{(0,us.setMaxListeners)(r,...t)}catch{}};var Kr=class extends EventTarget{#t=new Map;constructor(){super(),ls(1/0,this)}listenerCount(t){let e=this.#t.get(t);return e==null?0:e.length}addEventListener(t,e,n){super.addEventListener(t,e,n);let o=this.#t.get(t);o==null&&(o=[],this.#t.set(t,o)),o.push({callback:e,once:(n!==!0&&n!==!1&&n?.once)??!1})}removeEventListener(t,e,n){super.removeEventListener(t.toString(),e??null,n);let o=this.#t.get(t);o!=null&&(o=o.filter(({callback:i})=>i!==e),this.#t.set(t,o))}dispatchEvent(t){let e=super.dispatchEvent(t),n=this.#t.get(t.type);return n==null||(n=n.filter(({once:o})=>!o),this.#t.set(t.type,n)),e}safeDispatchEvent(t,e={}){return this.dispatchEvent(new CustomEvent(t,e))}};var fs=Symbol.for("@libp2p/service-capabilities"),th=Symbol.for("@libp2p/service-dependencies");function Dt(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 $r=ht(Y("crypto"),1);var ds=Y("node:buffer");function yt(r,t){return fe(ds.Buffer.concat(r,t))}var hs=Y("node:buffer");function W(r,t="utf8"){let e=yr[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return t==="utf8"||t==="utf-8"?hs.Buffer.from(r.buffer,r.byteOffset,r.byteLength).toString("utf8"):e.encoder.encode(r).substring(1)}var Ch=$r.default.generateKeyPairSync,sr=32;var Eu=64;function ps(r,t,e){if(r.byteLength!==sr)throw new TypeError('"key" must be 32 bytes in length.');if(!(r instanceof Uint8Array))throw new TypeError('"key" must be a node.js Buffer, or Uint8Array.');if(t.byteLength!==Eu)throw new TypeError('"sig" must be 64 bytes in length.');if(!(t instanceof Uint8Array))throw new TypeError('"sig" must be a node.js Buffer, or Uint8Array.');let n=$r.default.createPublicKey({format:"jwk",key:{crv:"Ed25519",x:W(r,"base64url"),kty:"OKP"}});return $r.default.verify(null,e instanceof Uint8Array?e:e.subarray(),n,t)}var Vr=class{type="Ed25519";raw;constructor(t){this.raw=Lo(t,sr)}toMultihash(){return $t.digest(_e(this))}toCID(){return Q.createV1(114,this.toMultihash())}toString(){return M.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:Dt(this.raw,t.raw)}verify(t,e){return ps(this.raw,e,t)}};function gs(r){return r=Lo(r,sr),new Vr(r)}function Lo(r,t){if(r=Uint8Array.from(r??[]),r.length!==t)throw new gt(`Key must be a Uint8Array of length ${t}, got ${r.length}`);return r}var Tt;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.secp256k1="secp256k1"})(Tt||(Tt={}));var Bo;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.secp256k1=2]="secp256k1"})(Bo||(Bo={}));(function(r){r.codec=()=>Ot(Bo)})(Tt||(Tt={}));var cr;(function(r){let t;r.codec=()=>(t==null&&(t=$((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),Tt.codec().encode(e.Type,n)),e.Data!=null&&(n.uint32(18),n.bytes(e.Data)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let i={},s=n==null?e.len:e.pos+n;for(;e.pos<s;){let c=e.uint32();switch(c>>>3){case 1:{i.Type=Tt.codec().decode(e);break}case 2:{i.Data=e.bytes();break}default:{e.skipType(c&7);break}}}return i})),t),r.encode=e=>K(e,r.codec()),r.decode=(e,n)=>_(e,r.codec(),n)})(cr||(cr={}));var ko;(function(r){let t;r.codec=()=>(t==null&&(t=$((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),Tt.codec().encode(e.Type,n)),e.Data!=null&&(n.uint32(18),n.bytes(e.Data)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let i={},s=n==null?e.len:e.pos+n;for(;e.pos<s;){let c=e.uint32();switch(c>>>3){case 1:{i.Type=Tt.codec().decode(e);break}case 2:{i.Data=e.bytes();break}default:{e.skipType(c&7);break}}}return i})),t),r.encode=e=>K(e,r.codec()),r.decode=(e,n)=>_(e,r.codec(),n)})(ko||(ko={}));function ys(r){if(!Number.isSafeInteger(r)||r<0)throw new Error(`positive integer expected, not ${r}`)}function Iu(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}function Me(r,...t){if(!Iu(r))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(r.length))throw new Error(`Uint8Array expected of length ${t}, not of length=${r.length}`)}function bs(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");ys(r.outputLen),ys(r.blockLen)}function Ke(r,t=!0){if(r.destroyed)throw new Error("Hash instance has been destroyed");if(t&&r.finished)throw new Error("Hash#digest() has already been called")}function ws(r,t){Me(r);let e=t.outputLen;if(r.length<e)throw new Error(`digestInto() expects output buffer of length at least ${e}`)}var Ft=ht(Y("node:crypto"),1),ye=Ft&&typeof Ft=="object"&&"webcrypto"in Ft?Ft.webcrypto:Ft&&typeof Ft=="object"&&"randomBytes"in Ft?Ft:void 0;var Gr=r=>new DataView(r.buffer,r.byteOffset,r.byteLength),Ut=(r,t)=>r<<32-t|r>>>t;var jh=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function Au(r){if(typeof r!="string")throw new Error(`utf8ToBytes expected string, got ${typeof r}`);return new Uint8Array(new TextEncoder().encode(r))}function ar(r){return typeof r=="string"&&(r=Au(r)),Me(r),r}function xs(...r){let t=0;for(let n=0;n<r.length;n++){let o=r[n];Me(o),t+=o.length}let e=new Uint8Array(t);for(let n=0,o=0;n<r.length;n++){let i=r[n];e.set(i,o),o+=i.length}return e}var $e=class{clone(){return this._cloneInto()}},tp={}.toString;function Es(r){let t=n=>r().update(ar(n)).digest(),e=r();return t.outputLen=e.outputLen,t.blockLen=e.blockLen,t.create=()=>r(),t}function vs(r=32){if(ye&&typeof ye.getRandomValues=="function")return ye.getRandomValues(new Uint8Array(r));if(ye&&typeof ye.randomBytes=="function")return ye.randomBytes(r);throw new Error("crypto.getRandomValues must be defined")}function Tu(r,t,e,n){if(typeof r.setBigUint64=="function")return r.setBigUint64(t,e,n);let o=BigInt(32),i=BigInt(4294967295),s=Number(e>>o&i),c=Number(e&i),a=n?4:0,l=n?0:4;r.setUint32(t+a,s,n),r.setUint32(t+l,c,n)}var Ss=(r,t,e)=>r&t^~r&e,Is=(r,t,e)=>r&t^r&e^t&e,Fr=class extends $e{constructor(t,e,n,o){super(),this.blockLen=t,this.outputLen=e,this.padOffset=n,this.isLE=o,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(t),this.view=Gr(this.buffer)}update(t){Ke(this);let{view:e,buffer:n,blockLen:o}=this;t=ar(t);let i=t.length;for(let s=0;s<i;){let c=Math.min(o-this.pos,i-s);if(c===o){let a=Gr(t);for(;o<=i-s;s+=o)this.process(a,s);continue}n.set(t.subarray(s,s+c),this.pos),this.pos+=c,s+=c,this.pos===o&&(this.process(e,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){Ke(this),ws(t,this),this.finished=!0;let{buffer:e,view:n,blockLen:o,isLE:i}=this,{pos:s}=this;e[s++]=128,this.buffer.subarray(s).fill(0),this.padOffset>o-s&&(this.process(n,0),s=0);for(let d=s;d<o;d++)e[d]=0;Tu(n,o-8,BigInt(this.length*8),i),this.process(n,0);let c=Gr(t),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let l=a/4,f=this.get();if(l>f.length)throw new Error("_sha2: outputLen bigger than state");for(let d=0;d<l;d++)c.setUint32(4*d,f[d],i)}digest(){let{buffer:t,outputLen:e}=this;this.digestInto(t);let n=t.slice(0,e);return this.destroy(),n}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());let{blockLen:e,buffer:n,length:o,finished:i,destroyed:s,pos:c}=this;return t.length=o,t.pos=c,t.finished=i,t.destroyed=s,o%e&&t.buffer.set(n),t}};var Lu=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),re=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),ne=new Uint32Array(64),No=class extends Fr{constructor(){super(64,32,8,!1),this.A=re[0]|0,this.B=re[1]|0,this.C=re[2]|0,this.D=re[3]|0,this.E=re[4]|0,this.F=re[5]|0,this.G=re[6]|0,this.H=re[7]|0}get(){let{A:t,B:e,C:n,D:o,E:i,F:s,G:c,H:a}=this;return[t,e,n,o,i,s,c,a]}set(t,e,n,o,i,s,c,a){this.A=t|0,this.B=e|0,this.C=n|0,this.D=o|0,this.E=i|0,this.F=s|0,this.G=c|0,this.H=a|0}process(t,e){for(let d=0;d<16;d++,e+=4)ne[d]=t.getUint32(e,!1);for(let d=16;d<64;d++){let h=ne[d-15],g=ne[d-2],b=Ut(h,7)^Ut(h,18)^h>>>3,m=Ut(g,17)^Ut(g,19)^g>>>10;ne[d]=m+ne[d-7]+b+ne[d-16]|0}let{A:n,B:o,C:i,D:s,E:c,F:a,G:l,H:f}=this;for(let d=0;d<64;d++){let h=Ut(c,6)^Ut(c,11)^Ut(c,25),g=f+h+Ss(c,a,l)+Lu[d]+ne[d]|0,m=(Ut(n,2)^Ut(n,13)^Ut(n,22))+Is(n,o,i)|0;f=l,l=a,a=c,c=s+g|0,s=i,i=o,o=n,n=g+m|0}n=n+this.A|0,o=o+this.B|0,i=i+this.C|0,s=s+this.D|0,c=c+this.E|0,a=a+this.F|0,l=l+this.G|0,f=f+this.H|0,this.set(n,o,i,s,c,a,l,f)}roundClean(){ne.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};var As=Es(()=>new No);var zr=class extends $e{constructor(t,e){super(),this.finished=!1,this.destroyed=!1,bs(t);let n=ar(e);if(this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let o=this.blockLen,i=new Uint8Array(o);i.set(n.length>o?t.create().update(n).digest():n);for(let s=0;s<i.length;s++)i[s]^=54;this.iHash.update(i),this.oHash=t.create();for(let s=0;s<i.length;s++)i[s]^=106;this.oHash.update(i),i.fill(0)}update(t){return Ke(this),this.iHash.update(t),this}digestInto(t){Ke(this),Me(t,this.outputLen),this.finished=!0,this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){let t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||(t=Object.create(Object.getPrototypeOf(this),{}));let{oHash:e,iHash:n,finished:o,destroyed:i,blockLen:s,outputLen:c}=this;return t=t,t.finished=o,t.destroyed=i,t.blockLen=s,t.outputLen=c,t.oHash=e._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},Po=(r,t,e)=>new zr(r,t).update(e).digest();Po.create=(r,t)=>new zr(r,t);var Mo={};at(Mo,{aInRange:()=>se,abool:()=>be,abytes:()=>Ve,bitGet:()=>Ou,bitLen:()=>Ro,bitMask:()=>lr,bitSet:()=>Du,bytesToHex:()=>we,bytesToNumberBE:()=>Ht,bytesToNumberLE:()=>qr,concatBytes:()=>Ge,createHmacDrbg:()=>_o,ensureBytes:()=>bt,equalBytes:()=>Pu,hexToBytes:()=>Ee,hexToNumber:()=>Uo,inRange:()=>ur,isBytes:()=>oe,memoized:()=>Yr,notImplemented:()=>Ru,numberToBytesBE:()=>ie,numberToBytesLE:()=>Wr,numberToHexUnpadded:()=>xe,numberToVarBytesBE:()=>Nu,utf8ToBytes:()=>Cu,validateObject:()=>ce});var Do=BigInt(0),Hr=BigInt(1),Bu=BigInt(2);function oe(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}function Ve(r){if(!oe(r))throw new Error("Uint8Array expected")}function be(r,t){if(typeof t!="boolean")throw new Error(`${r} must be valid boolean, got "${t}".`)}var ku=Array.from({length:256},(r,t)=>t.toString(16).padStart(2,"0"));function we(r){Ve(r);let t="";for(let e=0;e<r.length;e++)t+=ku[r[e]];return t}function xe(r){let t=r.toString(16);return t.length&1?`0${t}`:t}function Uo(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return BigInt(r===""?"0":`0x${r}`)}var zt={_0:48,_9:57,_A:65,_F:70,_a:97,_f:102};function Ts(r){if(r>=zt._0&&r<=zt._9)return r-zt._0;if(r>=zt._A&&r<=zt._F)return r-(zt._A-10);if(r>=zt._a&&r<=zt._f)return r-(zt._a-10)}function Ee(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);let t=r.length,e=t/2;if(t%2)throw new Error("padded hex string expected, got unpadded hex of length "+t);let n=new Uint8Array(e);for(let o=0,i=0;o<e;o++,i+=2){let s=Ts(r.charCodeAt(i)),c=Ts(r.charCodeAt(i+1));if(s===void 0||c===void 0){let a=r[i]+r[i+1];throw new Error('hex string expected, got non-hex character "'+a+'" at index '+i)}n[o]=s*16+c}return n}function Ht(r){return Uo(we(r))}function qr(r){return Ve(r),Uo(we(Uint8Array.from(r).reverse()))}function ie(r,t){return Ee(r.toString(16).padStart(t*2,"0"))}function Wr(r,t){return ie(r,t).reverse()}function Nu(r){return Ee(xe(r))}function bt(r,t,e){let n;if(typeof t=="string")try{n=Ee(t)}catch(i){throw new Error(`${r} must be valid hex string, got "${t}". Cause: ${i}`)}else if(oe(t))n=Uint8Array.from(t);else throw new Error(`${r} must be hex string or Uint8Array`);let o=n.length;if(typeof e=="number"&&o!==e)throw new Error(`${r} expected ${e} bytes, got ${o}`);return n}function Ge(...r){let t=0;for(let n=0;n<r.length;n++){let o=r[n];Ve(o),t+=o.length}let e=new Uint8Array(t);for(let n=0,o=0;n<r.length;n++){let i=r[n];e.set(i,o),o+=i.length}return e}function Pu(r,t){if(r.length!==t.length)return!1;let e=0;for(let n=0;n<r.length;n++)e|=r[n]^t[n];return e===0}function Cu(r){if(typeof r!="string")throw new Error(`utf8ToBytes expected string, got ${typeof r}`);return new Uint8Array(new TextEncoder().encode(r))}var Co=r=>typeof r=="bigint"&&Do<=r;function ur(r,t,e){return Co(r)&&Co(t)&&Co(e)&&t<=r&&r<e}function se(r,t,e,n){if(!ur(t,e,n))throw new Error(`expected valid ${r}: ${e} <= n < ${n}, got ${typeof t} ${t}`)}function Ro(r){let t;for(t=0;r>Do;r>>=Hr,t+=1);return t}function Ou(r,t){return r>>BigInt(t)&Hr}function Du(r,t,e){return r|(e?Hr:Do)<<BigInt(t)}var lr=r=>(Bu<<BigInt(r-1))-Hr,Oo=r=>new Uint8Array(r),Ls=r=>Uint8Array.from(r);function _o(r,t,e){if(typeof r!="number"||r<2)throw new Error("hashLen must be a number");if(typeof t!="number"||t<2)throw new Error("qByteLen must be a number");if(typeof e!="function")throw new Error("hmacFn must be a function");let n=Oo(r),o=Oo(r),i=0,s=()=>{n.fill(1),o.fill(0),i=0},c=(...d)=>e(o,n,...d),a=(d=Oo())=>{o=c(Ls([0]),d),n=c(),d.length!==0&&(o=c(Ls([1]),d),n=c())},l=()=>{if(i++>=1e3)throw new Error("drbg: tried 1000 values");let d=0,h=[];for(;d<t;){n=c();let g=n.slice();h.push(g),d+=n.length}return Ge(...h)};return(d,h)=>{s(),a(d);let g;for(;!(g=h(l()));)a();return s(),g}}var Uu={bigint:r=>typeof r=="bigint",function:r=>typeof r=="function",boolean:r=>typeof r=="boolean",string:r=>typeof r=="string",stringOrUint8Array:r=>typeof r=="string"||oe(r),isSafeInteger:r=>Number.isSafeInteger(r),array:r=>Array.isArray(r),field:(r,t)=>t.Fp.isValid(r),hash:r=>typeof r=="function"&&Number.isSafeInteger(r.outputLen)};function ce(r,t,e={}){let n=(o,i,s)=>{let c=Uu[i];if(typeof c!="function")throw new Error(`Invalid validator "${i}", expected function`);let a=r[o];if(!(s&&a===void 0)&&!c(a,r))throw new Error(`Invalid param ${String(o)}=${a} (${typeof a}), expected ${i}`)};for(let[o,i]of Object.entries(t))n(o,i,!1);for(let[o,i]of Object.entries(e))n(o,i,!0);return r}var Ru=()=>{throw new Error("not implemented")};function Yr(r){let t=new WeakMap;return(e,...n)=>{let o=t.get(e);if(o!==void 0)return o;let i=r(e,...n);return t.set(e,i),i}}var Z=BigInt(0),F=BigInt(1),ve=BigInt(2),_u=BigInt(3),Ko=BigInt(4),Bs=BigInt(5),ks=BigInt(8),Mu=BigInt(9),Ku=BigInt(16);function nt(r,t){let e=r%t;return e>=Z?e:t+e}function $u(r,t,e){if(e<=Z||t<Z)throw new Error("Expected power/modulo > 0");if(e===F)return Z;let n=F;for(;t>Z;)t&F&&(n=n*r%e),r=r*r%e,t>>=F;return n}function wt(r,t,e){let n=r;for(;t-- >Z;)n*=n,n%=e;return n}function Zr(r,t){if(r===Z||t<=Z)throw new Error(`invert: expected positive integers, got n=${r} mod=${t}`);let e=nt(r,t),n=t,o=Z,i=F,s=F,c=Z;for(;e!==Z;){let l=n/e,f=n%e,d=o-s*l,h=i-c*l;n=e,e=f,o=s,i=c,s=d,c=h}if(n!==F)throw new Error("invert: does not exist");return nt(o,t)}function Vu(r){let t=(r-F)/ve,e,n,o;for(e=r-F,n=0;e%ve===Z;e/=ve,n++);for(o=ve;o<r&&$u(o,t,r)!==r-F;o++);if(n===1){let s=(r+F)/Ko;return function(a,l){let f=a.pow(l,s);if(!a.eql(a.sqr(f),l))throw new Error("Cannot find square root");return f}}let i=(e+F)/ve;return function(c,a){if(c.pow(a,t)===c.neg(c.ONE))throw new Error("Cannot find square root");let l=n,f=c.pow(c.mul(c.ONE,o),e),d=c.pow(a,i),h=c.pow(a,e);for(;!c.eql(h,c.ONE);){if(c.eql(h,c.ZERO))return c.ZERO;let g=1;for(let m=c.sqr(h);g<l&&!c.eql(m,c.ONE);g++)m=c.sqr(m);let b=c.pow(f,F<<BigInt(l-g-1));f=c.sqr(b),d=c.mul(d,b),h=c.mul(h,f),l=g}return d}}function Gu(r){if(r%Ko===_u){let t=(r+F)/Ko;return function(n,o){let i=n.pow(o,t);if(!n.eql(n.sqr(i),o))throw new Error("Cannot find square root");return i}}if(r%ks===Bs){let t=(r-Bs)/ks;return function(n,o){let i=n.mul(o,ve),s=n.pow(i,t),c=n.mul(o,s),a=n.mul(n.mul(c,ve),s),l=n.mul(c,n.sub(a,n.ONE));if(!n.eql(n.sqr(l),o))throw new Error("Cannot find square root");return l}}return r%Ku,Vu(r)}var Fu=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function $o(r){let t={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},e=Fu.reduce((n,o)=>(n[o]="function",n),t);return ce(r,e)}function zu(r,t,e){if(e<Z)throw new Error("Expected power > 0");if(e===Z)return r.ONE;if(e===F)return t;let n=r.ONE,o=t;for(;e>Z;)e&F&&(n=r.mul(n,o)),o=r.sqr(o),e>>=F;return n}function Hu(r,t){let e=new Array(t.length),n=t.reduce((i,s,c)=>r.is0(s)?i:(e[c]=i,r.mul(i,s)),r.ONE),o=r.inv(n);return t.reduceRight((i,s,c)=>r.is0(s)?i:(e[c]=r.mul(i,e[c]),r.mul(i,s)),o),e}function Vo(r,t){let e=t!==void 0?t:r.toString(2).length,n=Math.ceil(e/8);return{nBitLength:e,nByteLength:n}}function Xr(r,t,e=!1,n={}){if(r<=Z)throw new Error(`Expected Field ORDER > 0, got ${r}`);let{nBitLength:o,nByteLength:i}=Vo(r,t);if(i>2048)throw new Error("Field lengths over 2048 bytes are not supported");let s=Gu(r),c=Object.freeze({ORDER:r,BITS:o,BYTES:i,MASK:lr(o),ZERO:Z,ONE:F,create:a=>nt(a,r),isValid:a=>{if(typeof a!="bigint")throw new Error(`Invalid field element: expected bigint, got ${typeof a}`);return Z<=a&&a<r},is0:a=>a===Z,isOdd:a=>(a&F)===F,neg:a=>nt(-a,r),eql:(a,l)=>a===l,sqr:a=>nt(a*a,r),add:(a,l)=>nt(a+l,r),sub:(a,l)=>nt(a-l,r),mul:(a,l)=>nt(a*l,r),pow:(a,l)=>zu(c,a,l),div:(a,l)=>nt(a*Zr(l,r),r),sqrN:a=>a*a,addN:(a,l)=>a+l,subN:(a,l)=>a-l,mulN:(a,l)=>a*l,inv:a=>Zr(a,r),sqrt:n.sqrt||(a=>s(c,a)),invertBatch:a=>Hu(c,a),cmov:(a,l,f)=>f?l:a,toBytes:a=>e?Wr(a,i):ie(a,i),fromBytes:a=>{if(a.length!==i)throw new Error(`Fp.fromBytes: expected ${i}, got ${a.length}`);return e?qr(a):Ht(a)}});return Object.freeze(c)}function Ns(r){if(typeof r!="bigint")throw new Error("field order must be bigint");let t=r.toString(2).length;return Math.ceil(t/8)}function Go(r){let t=Ns(r);return t+Math.ceil(t/2)}function Ps(r,t,e=!1){let n=r.length,o=Ns(t),i=Go(t);if(n<16||n<i||n>1024)throw new Error(`expected ${i}-1024 bytes of input, got ${n}`);let s=e?Ht(r):qr(r),c=nt(s,t-F)+F;return e?Wr(c,o):ie(c,o)}var Wu=BigInt(0),Fo=BigInt(1),zo=new WeakMap,Cs=new WeakMap;function Os(r,t){let e=(i,s)=>{let c=s.negate();return i?c:s},n=i=>{if(!Number.isSafeInteger(i)||i<=0||i>t)throw new Error(`Wrong window size=${i}, should be [1..${t}]`)},o=i=>{n(i);let s=Math.ceil(t/i)+1,c=2**(i-1);return{windows:s,windowSize:c}};return{constTimeNegate:e,unsafeLadder(i,s){let c=r.ZERO,a=i;for(;s>Wu;)s&Fo&&(c=c.add(a)),a=a.double(),s>>=Fo;return c},precomputeWindow(i,s){let{windows:c,windowSize:a}=o(s),l=[],f=i,d=f;for(let h=0;h<c;h++){d=f,l.push(d);for(let g=1;g<a;g++)d=d.add(f),l.push(d);f=d.double()}return l},wNAF(i,s,c){let{windows:a,windowSize:l}=o(i),f=r.ZERO,d=r.BASE,h=BigInt(2**i-1),g=2**i,b=BigInt(i);for(let m=0;m<a;m++){let u=m*l,p=Number(c&h);c>>=b,p>l&&(p-=g,c+=Fo);let y=u,E=u+Math.abs(p)-1,S=m%2!==0,k=p<0;p===0?d=d.add(e(S,s[y])):f=f.add(e(k,s[E]))}return{p:f,f:d}},wNAFCached(i,s,c){let a=Cs.get(i)||1,l=zo.get(i);return l||(l=this.precomputeWindow(i,a),a!==1&&zo.set(i,c(l))),this.wNAF(a,l,s)},setWindowSize(i,s){n(s),Cs.set(i,s),zo.delete(i)}}}function Ds(r,t,e,n){if(!Array.isArray(e)||!Array.isArray(n)||n.length!==e.length)throw new Error("arrays of points and scalars must have equal length");n.forEach((f,d)=>{if(!t.isValid(f))throw new Error(`wrong scalar at index ${d}`)}),e.forEach((f,d)=>{if(!(f instanceof r))throw new Error(`wrong point at index ${d}`)});let o=Ro(BigInt(e.length)),i=o>12?o-3:o>4?o-2:o?2:1,s=(1<<i)-1,c=new Array(s+1).fill(r.ZERO),a=Math.floor((t.BITS-1)/i)*i,l=r.ZERO;for(let f=a;f>=0;f-=i){c.fill(r.ZERO);for(let h=0;h<n.length;h++){let g=n[h],b=Number(g>>BigInt(f)&BigInt(s));c[b]=c[b].add(e[h])}let d=r.ZERO;for(let h=c.length-1,g=r.ZERO;h>0;h--)g=g.add(c[h]),d=d.add(g);if(l=l.add(d),f!==0)for(let h=0;h<i;h++)l=l.double()}return l}function Ho(r){return $o(r.Fp),ce(r,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...Vo(r.n,r.nBitLength),...r,p:r.Fp.ORDER})}function Us(r){r.lowS!==void 0&&be("lowS",r.lowS),r.prehash!==void 0&&be("prehash",r.prehash)}function Yu(r){let t=Ho(r);ce(t,{a:"field",b:"field"},{allowedPrivateKeyLengths:"array",wrapPrivateKey:"boolean",isTorsionFree:"function",clearCofactor:"function",allowInfinityPoint:"boolean",fromBytes:"function",toBytes:"function"});let{endo:e,Fp:n,a:o}=t;if(e){if(!n.eql(o,n.ZERO))throw new Error("Endomorphism can only be defined for Koblitz curves that have a=0");if(typeof e!="object"||typeof e.beta!="bigint"||typeof e.splitScalar!="function")throw new Error("Expected endomorphism with beta: bigint and splitScalar: function")}return Object.freeze({...t})}var{bytesToNumberBE:Zu,hexToBytes:Xu}=Mo,qt={Err:class extends Error{constructor(t=""){super(t)}},_tlv:{encode:(r,t)=>{let{Err:e}=qt;if(r<0||r>256)throw new e("tlv.encode: wrong tag");if(t.length&1)throw new e("tlv.encode: unpadded data");let n=t.length/2,o=xe(n);if(o.length/2&128)throw new e("tlv.encode: long form length too big");let i=n>127?xe(o.length/2|128):"";return`${xe(r)}${i}${o}${t}`},decode(r,t){let{Err:e}=qt,n=0;if(r<0||r>256)throw new e("tlv.encode: wrong tag");if(t.length<2||t[n++]!==r)throw new e("tlv.decode: wrong tlv");let o=t[n++],i=!!(o&128),s=0;if(!i)s=o;else{let a=o&127;if(!a)throw new e("tlv.decode(long): indefinite length not supported");if(a>4)throw new e("tlv.decode(long): byte length is too big");let l=t.subarray(n,n+a);if(l.length!==a)throw new e("tlv.decode: length bytes not complete");if(l[0]===0)throw new e("tlv.decode(long): zero leftmost byte");for(let f of l)s=s<<8|f;if(n+=a,s<128)throw new e("tlv.decode(long): not minimal encoding")}let c=t.subarray(n,n+s);if(c.length!==s)throw new e("tlv.decode: wrong value length");return{v:c,l:t.subarray(n+s)}}},_int:{encode(r){let{Err:t}=qt;if(r<Wt)throw new t("integer: negative integers are not allowed");let e=xe(r);if(Number.parseInt(e[0],16)&8&&(e="00"+e),e.length&1)throw new t("unexpected assertion");return e},decode(r){let{Err:t}=qt;if(r[0]&128)throw new t("Invalid signature integer: negative");if(r[0]===0&&!(r[1]&128))throw new t("Invalid signature integer: unnecessary leading zero");return Zu(r)}},toSig(r){let{Err:t,_int:e,_tlv:n}=qt,o=typeof r=="string"?Xu(r):r;Ve(o);let{v:i,l:s}=n.decode(48,o);if(s.length)throw new t("Invalid signature: left bytes after parsing");let{v:c,l:a}=n.decode(2,i),{v:l,l:f}=n.decode(2,a);if(f.length)throw new t("Invalid signature: left bytes after parsing");return{r:e.decode(c),s:e.decode(l)}},hexFromSig(r){let{_tlv:t,_int:e}=qt,n=`${t.encode(2,e.encode(r.r))}${t.encode(2,e.encode(r.s))}`;return t.encode(48,n)}},Wt=BigInt(0),J=BigInt(1),bp=BigInt(2),Rs=BigInt(3),wp=BigInt(4);function Qu(r){let t=Yu(r),{Fp:e}=t,n=Xr(t.n,t.nBitLength),o=t.toBytes||((m,u,p)=>{let y=u.toAffine();return Ge(Uint8Array.from([4]),e.toBytes(y.x),e.toBytes(y.y))}),i=t.fromBytes||(m=>{let u=m.subarray(1),p=e.fromBytes(u.subarray(0,e.BYTES)),y=e.fromBytes(u.subarray(e.BYTES,2*e.BYTES));return{x:p,y}});function s(m){let{a:u,b:p}=t,y=e.sqr(m),E=e.mul(y,m);return e.add(e.add(E,e.mul(m,u)),p)}if(!e.eql(e.sqr(t.Gy),s(t.Gx)))throw new Error("bad generator point: equation left != right");function c(m){return ur(m,J,t.n)}function a(m){let{allowedPrivateKeyLengths:u,nByteLength:p,wrapPrivateKey:y,n:E}=t;if(u&&typeof m!="bigint"){if(oe(m)&&(m=we(m)),typeof m!="string"||!u.includes(m.length))throw new Error("Invalid key");m=m.padStart(p*2,"0")}let S;try{S=typeof m=="bigint"?m:Ht(bt("private key",m,p))}catch{throw new Error(`private key must be ${p} bytes, hex or bigint, not ${typeof m}`)}return y&&(S=nt(S,E)),se("private key",S,J,E),S}function l(m){if(!(m instanceof h))throw new Error("ProjectivePoint expected")}let f=Yr((m,u)=>{let{px:p,py:y,pz:E}=m;if(e.eql(E,e.ONE))return{x:p,y};let S=m.is0();u==null&&(u=S?e.ONE:e.inv(E));let k=e.mul(p,u),B=e.mul(y,u),v=e.mul(E,u);if(S)return{x:e.ZERO,y:e.ZERO};if(!e.eql(v,e.ONE))throw new Error("invZ was invalid");return{x:k,y:B}}),d=Yr(m=>{if(m.is0()){if(t.allowInfinityPoint&&!e.is0(m.py))return;throw new Error("bad point: ZERO")}let{x:u,y:p}=m.toAffine();if(!e.isValid(u)||!e.isValid(p))throw new Error("bad point: x or y not FE");let y=e.sqr(p),E=s(u);if(!e.eql(y,E))throw new Error("bad point: equation left != right");if(!m.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});class h{constructor(u,p,y){if(this.px=u,this.py=p,this.pz=y,u==null||!e.isValid(u))throw new Error("x required");if(p==null||!e.isValid(p))throw new Error("y required");if(y==null||!e.isValid(y))throw new Error("z required");Object.freeze(this)}static fromAffine(u){let{x:p,y}=u||{};if(!u||!e.isValid(p)||!e.isValid(y))throw new Error("invalid affine point");if(u instanceof h)throw new Error("projective point not allowed");let E=S=>e.eql(S,e.ZERO);return E(p)&&E(y)?h.ZERO:new h(p,y,e.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(u){let p=e.invertBatch(u.map(y=>y.pz));return u.map((y,E)=>y.toAffine(p[E])).map(h.fromAffine)}static fromHex(u){let p=h.fromAffine(i(bt("pointHex",u)));return p.assertValidity(),p}static fromPrivateKey(u){return h.BASE.multiply(a(u))}static msm(u,p){return Ds(h,n,u,p)}_setWindowSize(u){b.setWindowSize(this,u)}assertValidity(){d(this)}hasEvenY(){let{y:u}=this.toAffine();if(e.isOdd)return!e.isOdd(u);throw new Error("Field doesn't support isOdd")}equals(u){l(u);let{px:p,py:y,pz:E}=this,{px:S,py:k,pz:B}=u,v=e.eql(e.mul(p,B),e.mul(S,E)),T=e.eql(e.mul(y,B),e.mul(k,E));return v&&T}negate(){return new h(this.px,e.neg(this.py),this.pz)}double(){let{a:u,b:p}=t,y=e.mul(p,Rs),{px:E,py:S,pz:k}=this,B=e.ZERO,v=e.ZERO,T=e.ZERO,N=e.mul(E,E),Et=e.mul(S,S),R=e.mul(k,k),D=e.mul(E,S);return D=e.add(D,D),T=e.mul(E,k),T=e.add(T,T),B=e.mul(u,T),v=e.mul(y,R),v=e.add(B,v),B=e.sub(Et,v),v=e.add(Et,v),v=e.mul(B,v),B=e.mul(D,B),T=e.mul(y,T),R=e.mul(u,R),D=e.sub(N,R),D=e.mul(u,D),D=e.add(D,T),T=e.add(N,N),N=e.add(T,N),N=e.add(N,R),N=e.mul(N,D),v=e.add(v,N),R=e.mul(S,k),R=e.add(R,R),N=e.mul(R,D),B=e.sub(B,N),T=e.mul(R,Et),T=e.add(T,T),T=e.add(T,T),new h(B,v,T)}add(u){l(u);let{px:p,py:y,pz:E}=this,{px:S,py:k,pz:B}=u,v=e.ZERO,T=e.ZERO,N=e.ZERO,Et=t.a,R=e.mul(t.b,Rs),D=e.mul(p,S),dt=e.mul(y,k),x=e.mul(E,B),I=e.add(p,y),A=e.add(S,k);I=e.mul(I,A),A=e.add(D,dt),I=e.sub(I,A),A=e.add(p,E);let P=e.add(S,B);return A=e.mul(A,P),P=e.add(D,x),A=e.sub(A,P),P=e.add(y,E),v=e.add(k,B),P=e.mul(P,v),v=e.add(dt,x),P=e.sub(P,v),N=e.mul(Et,A),v=e.mul(R,x),N=e.add(v,N),v=e.sub(dt,N),N=e.add(dt,N),T=e.mul(v,N),dt=e.add(D,D),dt=e.add(dt,D),x=e.mul(Et,x),A=e.mul(R,A),dt=e.add(dt,x),x=e.sub(D,x),x=e.mul(Et,x),A=e.add(A,x),D=e.mul(dt,A),T=e.add(T,D),D=e.mul(P,A),v=e.mul(I,v),v=e.sub(v,D),D=e.mul(I,dt),N=e.mul(P,N),N=e.add(N,D),new h(v,T,N)}subtract(u){return this.add(u.negate())}is0(){return this.equals(h.ZERO)}wNAF(u){return b.wNAFCached(this,u,h.normalizeZ)}multiplyUnsafe(u){se("scalar",u,Wt,t.n);let p=h.ZERO;if(u===Wt)return p;if(u===J)return this;let{endo:y}=t;if(!y)return b.unsafeLadder(this,u);let{k1neg:E,k1:S,k2neg:k,k2:B}=y.splitScalar(u),v=p,T=p,N=this;for(;S>Wt||B>Wt;)S&J&&(v=v.add(N)),B&J&&(T=T.add(N)),N=N.double(),S>>=J,B>>=J;return E&&(v=v.negate()),k&&(T=T.negate()),T=new h(e.mul(T.px,y.beta),T.py,T.pz),v.add(T)}multiply(u){let{endo:p,n:y}=t;se("scalar",u,J,y);let E,S;if(p){let{k1neg:k,k1:B,k2neg:v,k2:T}=p.splitScalar(u),{p:N,f:Et}=this.wNAF(B),{p:R,f:D}=this.wNAF(T);N=b.constTimeNegate(k,N),R=b.constTimeNegate(v,R),R=new h(e.mul(R.px,p.beta),R.py,R.pz),E=N.add(R),S=Et.add(D)}else{let{p:k,f:B}=this.wNAF(u);E=k,S=B}return h.normalizeZ([E,S])[0]}multiplyAndAddUnsafe(u,p,y){let E=h.BASE,S=(B,v)=>v===Wt||v===J||!B.equals(E)?B.multiplyUnsafe(v):B.multiply(v),k=S(this,p).add(S(u,y));return k.is0()?void 0:k}toAffine(u){return f(this,u)}isTorsionFree(){let{h:u,isTorsionFree:p}=t;if(u===J)return!0;if(p)return p(h,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){let{h:u,clearCofactor:p}=t;return u===J?this:p?p(h,this):this.multiplyUnsafe(t.h)}toRawBytes(u=!0){return be("isCompressed",u),this.assertValidity(),o(h,this,u)}toHex(u=!0){return be("isCompressed",u),we(this.toRawBytes(u))}}h.BASE=new h(t.Gx,t.Gy,e.ONE),h.ZERO=new h(e.ZERO,e.ONE,e.ZERO);let g=t.nBitLength,b=Os(h,t.endo?Math.ceil(g/2):g);return{CURVE:t,ProjectivePoint:h,normPrivateKeyToScalar:a,weierstrassEquation:s,isWithinCurveOrder:c}}function Ju(r){let t=Ho(r);return ce(t,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...t})}function _s(r){let t=Ju(r),{Fp:e,n}=t,o=e.BYTES+1,i=2*e.BYTES+1;function s(x){return nt(x,n)}function c(x){return Zr(x,n)}let{ProjectivePoint:a,normPrivateKeyToScalar:l,weierstrassEquation:f,isWithinCurveOrder:d}=Qu({...t,toBytes(x,I,A){let P=I.toAffine(),U=e.toBytes(P.x),X=Ge;return be("isCompressed",A),A?X(Uint8Array.from([I.hasEvenY()?2:3]),U):X(Uint8Array.from([4]),U,e.toBytes(P.y))},fromBytes(x){let I=x.length,A=x[0],P=x.subarray(1);if(I===o&&(A===2||A===3)){let U=Ht(P);if(!ur(U,J,e.ORDER))throw new Error("Point is not on curve");let X=f(U),st;try{st=e.sqrt(X)}catch(Bt){let Xt=Bt instanceof Error?": "+Bt.message:"";throw new Error("Point is not on curve"+Xt)}let ct=(st&J)===J;return(A&1)===1!==ct&&(st=e.neg(st)),{x:U,y:st}}else if(I===i&&A===4){let U=e.fromBytes(P.subarray(0,e.BYTES)),X=e.fromBytes(P.subarray(e.BYTES,2*e.BYTES));return{x:U,y:X}}else throw new Error(`Point of length ${I} was invalid. Expected ${o} compressed bytes or ${i} uncompressed bytes`)}}),h=x=>we(ie(x,t.nByteLength));function g(x){let I=n>>J;return x>I}function b(x){return g(x)?s(-x):x}let m=(x,I,A)=>Ht(x.slice(I,A));class u{constructor(I,A,P){this.r=I,this.s=A,this.recovery=P,this.assertValidity()}static fromCompact(I){let A=t.nByteLength;return I=bt("compactSignature",I,A*2),new u(m(I,0,A),m(I,A,2*A))}static fromDER(I){let{r:A,s:P}=qt.toSig(bt("DER",I));return new u(A,P)}assertValidity(){se("r",this.r,J,n),se("s",this.s,J,n)}addRecoveryBit(I){return new u(this.r,this.s,I)}recoverPublicKey(I){let{r:A,s:P,recovery:U}=this,X=B(bt("msgHash",I));if(U==null||![0,1,2,3].includes(U))throw new Error("recovery id invalid");let st=U===2||U===3?A+t.n:A;if(st>=e.ORDER)throw new Error("recovery id 2 or 3 invalid");let ct=U&1?"03":"02",Zt=a.fromHex(ct+h(st)),Bt=c(st),Xt=s(-X*Bt),Xe=s(P*Bt),Qt=a.BASE.multiplyAndAddUnsafe(Zt,Xt,Xe);if(!Qt)throw new Error("point at infinify");return Qt.assertValidity(),Qt}hasHighS(){return g(this.s)}normalizeS(){return this.hasHighS()?new u(this.r,s(-this.s),this.recovery):this}toDERRawBytes(){return Ee(this.toDERHex())}toDERHex(){return qt.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return Ee(this.toCompactHex())}toCompactHex(){return h(this.r)+h(this.s)}}let p={isValidPrivateKey(x){try{return l(x),!0}catch{return!1}},normPrivateKeyToScalar:l,randomPrivateKey:()=>{let x=Go(t.n);return Ps(t.randomBytes(x),t.n)},precompute(x=8,I=a.BASE){return I._setWindowSize(x),I.multiply(BigInt(3)),I}};function y(x,I=!0){return a.fromPrivateKey(x).toRawBytes(I)}function E(x){let I=oe(x),A=typeof x=="string",P=(I||A)&&x.length;return I?P===o||P===i:A?P===2*o||P===2*i:x instanceof a}function S(x,I,A=!0){if(E(x))throw new Error("first arg must be private key");if(!E(I))throw new Error("second arg must be public key");return a.fromHex(I).multiply(l(x)).toRawBytes(A)}let k=t.bits2int||function(x){let I=Ht(x),A=x.length*8-t.nBitLength;return A>0?I>>BigInt(A):I},B=t.bits2int_modN||function(x){return s(k(x))},v=lr(t.nBitLength);function T(x){return se(`num < 2^${t.nBitLength}`,x,Wt,v),ie(x,t.nByteLength)}function N(x,I,A=Et){if(["recovered","canonical"].some(le=>le in A))throw new Error("sign() legacy options not supported");let{hash:P,randomBytes:U}=t,{lowS:X,prehash:st,extraEntropy:ct}=A;X==null&&(X=!0),x=bt("msgHash",x),Us(A),st&&(x=bt("prehashed msgHash",P(x)));let Zt=B(x),Bt=l(I),Xt=[T(Bt),T(Zt)];if(ct!=null&&ct!==!1){let le=ct===!0?U(e.BYTES):ct;Xt.push(bt("extraEntropy",le))}let Xe=Ge(...Xt),Qt=Zt;function On(le){let Le=k(le);if(!d(Le))return;let Si=c(Le),Rt=a.BASE.multiply(Le).toAffine(),Be=s(Rt.x);if(Be===Wt)return;let hr=s(Si*s(Qt+Be*Bt));if(hr===Wt)return;let Ii=(Rt.x===Be?0:2)|Number(Rt.y&J),Ai=hr;return X&&g(hr)&&(Ai=b(hr),Ii^=1),new u(Be,Ai,Ii)}return{seed:Xe,k2sig:On}}let Et={lowS:t.lowS,prehash:!1},R={lowS:t.lowS,prehash:!1};function D(x,I,A=Et){let{seed:P,k2sig:U}=N(x,I,A),X=t;return _o(X.hash.outputLen,X.nByteLength,X.hmac)(P,U)}a.BASE._setWindowSize(8);function dt(x,I,A,P=R){let U=x;if(I=bt("msgHash",I),A=bt("publicKey",A),"strict"in P)throw new Error("options.strict was renamed to lowS");Us(P);let{lowS:X,prehash:st}=P,ct,Zt;try{if(typeof U=="string"||oe(U))try{ct=u.fromDER(U)}catch(Rt){if(!(Rt instanceof qt.Err))throw Rt;ct=u.fromCompact(U)}else if(typeof U=="object"&&typeof U.r=="bigint"&&typeof U.s=="bigint"){let{r:Rt,s:Be}=U;ct=new u(Rt,Be)}else throw new Error("PARSE");Zt=a.fromHex(A)}catch(Rt){if(Rt.message==="PARSE")throw new Error("signature must be Signature instance, Uint8Array or hex string");return!1}if(X&&ct.hasHighS())return!1;st&&(I=t.hash(I));let{r:Bt,s:Xt}=ct,Xe=B(I),Qt=c(Xt),On=s(Xe*Qt),le=s(Bt*Qt),Le=a.BASE.multiplyAndAddUnsafe(Zt,On,le)?.toAffine();return Le?s(Le.x)===Bt:!1}return{CURVE:t,getPublicKey:y,getSharedSecret:S,sign:D,verify:dt,ProjectivePoint:a,Signature:u,utils:p}}function ju(r){return{hash:r,hmac:(t,...e)=>Po(r,t,xs(...e)),randomBytes:vs}}function Ms(r,t){let e=n=>_s({...r,...ju(n)});return Object.freeze({...e(t),create:e})}var Vs=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),Ks=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),tl=BigInt(1),qo=BigInt(2),$s=(r,t)=>(r+t/qo)/t;function el(r){let t=Vs,e=BigInt(3),n=BigInt(6),o=BigInt(11),i=BigInt(22),s=BigInt(23),c=BigInt(44),a=BigInt(88),l=r*r*r%t,f=l*l*r%t,d=wt(f,e,t)*f%t,h=wt(d,e,t)*f%t,g=wt(h,qo,t)*l%t,b=wt(g,o,t)*g%t,m=wt(b,i,t)*b%t,u=wt(m,c,t)*m%t,p=wt(u,a,t)*u%t,y=wt(p,c,t)*m%t,E=wt(y,e,t)*f%t,S=wt(E,s,t)*b%t,k=wt(S,n,t)*l%t,B=wt(k,qo,t);if(!Wo.eql(Wo.sqr(B),r))throw new Error("Cannot find square root");return B}var Wo=Xr(Vs,void 0,void 0,{sqrt:el}),Fe=Ms({a:BigInt(0),b:BigInt(7),Fp:Wo,n:Ks,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:r=>{let t=Ks,e=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-tl*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),o=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),i=e,s=BigInt("0x100000000000000000000000000000000"),c=$s(i*r,t),a=$s(-n*r,t),l=nt(r-c*e-a*o,t),f=nt(-c*n-a*i,t),d=l>s,h=f>s;if(d&&(l=t-l),h&&(f=t-f),l>s||f>s)throw new Error("splitScalar: Endomorphism failed, k="+r);return{k1neg:d,k1:l,k2neg:h,k2:f}}}},As),Bp=BigInt(0);var kp=Fe.ProjectivePoint;var Gs=ht(Y("node:crypto"),1);var Qr=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}};function Fs(r,t,e){let n=Gs.default.createHash("sha256");if(e instanceof Uint8Array)n.update(e);else for(let i of e)n.update(i);let o=n.digest();try{return Fe.verify(t,o,r)}catch(i){throw new Qr(String(i))}}var Jr=class{type="secp256k1";raw;_key;constructor(t){this._key=Hs(t),this.raw=zs(this._key)}toMultihash(){return $t.digest(_e(this))}toCID(){return Q.createV1(114,this.toMultihash())}toString(){return M.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:Dt(this.raw,t.raw)}verify(t,e){return Fs(this._key,e,t)}};function qs(r){return new Jr(r)}function zs(r){return Fe.ProjectivePoint.fromHex(r).toRawBytes(!0)}function Hs(r){try{return Fe.ProjectivePoint.fromHex(r),r}catch(t){throw new Ur(String(t))}}function Ws(r){let{Type:t,Data:e}=cr.decode(r.digest),n=e??new Uint8Array;switch(t){case Tt.Ed25519:return gs(n);case Tt.secp256k1:return qs(n);default:throw new ir}}function _e(r){return cr.encode({Type:Tt[r.type],Data:r.raw})}var Ys=Symbol.for("nodejs.util.inspect.custom"),rl=114,fr=class{type;multihash;publicKey;string;constructor(t){this.type=t.type,this.multihash=t.multihash,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[To]=!0;toString(){return this.string==null&&(this.string=M.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return Q.createV1(rl,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return Dt(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return Dt(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[Ys](){return`PeerId(${this.toString()})`}},jr=class extends fr{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},tn=class extends fr{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},en=class extends fr{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},nl=2336,rn=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=$t.digest(Mt(this.url))}[Ys](){return`PeerId(${this.url})`}[To]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return Q.createV1(nl,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=W(t)),t.toString()===this.toString())}};function ze(r){if(il(r))return new jr({multihash:r});if(ol(r))try{let t=Ws(r);if(t.type==="Ed25519")return new tn({multihash:r,publicKey:t});if(t.type==="secp256k1")return new en({multihash:r,publicKey:t})}catch{let e=W(r.digest);return new rn(new URL(e))}throw new Rr("Supplied PeerID Multihash is invalid")}function ol(r){return r.code===$t.code}function il(r){return r.code===ho.code}var vc=ht(Y("net"),1);var nn=class{index=0;input="";new(t){return this.index=0,this.input=t,this}readAtomically(t){let e=this.index,n=t();return n===void 0&&(this.index=e),n}parseWith(t){let e=t();if(this.index===this.input.length)return e}peekChar(){if(!(this.index>=this.input.length))return this.input[this.index]}readChar(){if(!(this.index>=this.input.length))return this.input[this.index++]}readGivenChar(t){return this.readAtomically(()=>{let e=this.readChar();if(e===t)return e})}readSeparator(t,e,n){return this.readAtomically(()=>{if(!(e>0&&this.readGivenChar(t)===void 0))return n()})}readNumber(t,e,n,o){return this.readAtomically(()=>{let i=0,s=0,c=this.peekChar();if(c===void 0)return;let a=c==="0",l=2**(8*o)-1;for(;;){let f=this.readAtomically(()=>{let d=this.readChar();if(d===void 0)return;let h=Number.parseInt(d,t);if(!Number.isNaN(h))return h});if(f===void 0)break;if(i*=t,i+=f,i>l||(s+=1,e!==void 0&&s>e))return}if(s!==0)return!n&&a&&s>1?void 0:i})}readIPv4Addr(){return this.readAtomically(()=>{let t=new Uint8Array(4);for(let e=0;e<t.length;e++){let n=this.readSeparator(".",e,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;t[e]=n}return t})}readIPv6Addr(){let t=e=>{for(let n=0;n<e.length/2;n++){let o=n*2;if(n<e.length-3){let s=this.readSeparator(":",n,()=>this.readIPv4Addr());if(s!==void 0)return e[o]=s[0],e[o+1]=s[1],e[o+2]=s[2],e[o+3]=s[3],[o+4,!0]}let i=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(i===void 0)return[o,!1];e[o]=i>>8,e[o+1]=i&255}return[e.length,!1]};return this.readAtomically(()=>{let e=new Uint8Array(16),[n,o]=t(e);if(n===16)return e;if(o||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let i=new Uint8Array(14),s=16-(n+2),[c]=t(i.subarray(0,s));return e.set(i.subarray(0,c),16-c),e})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var Bm=new nn;var Rm=parseInt("0xFFFF",16),_m=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);var Lt=Y("node:net");function on(r){return!!(0,Lt.isIP)(r)}var Qs=Lt.isIPv4,fl=Lt.isIPv6,Yo=function(r){let t=0;if(r=r.toString().trim(),Qs(r)){let e=new Uint8Array(t+4);return r.split(/\./g).forEach(n=>{e[t++]=parseInt(n,10)&255}),e}if(fl(r)){let e=r.split(":",8),n;for(n=0;n<e.length;n++){let i=Qs(e[n]),s;i&&(s=Yo(e[n]),e[n]=W(s.slice(0,2),"base16")),s!=null&&++n<8&&e.splice(n,0,W(s.slice(2,4),"base16"))}if(e[0]==="")for(;e.length<8;)e.unshift("0");else if(e[e.length-1]==="")for(;e.length<8;)e.push("0");else if(e.length<8){for(n=0;n<e.length&&e[n]!=="";n++);let i=[n,1];for(n=9-e.length;n>0;n--)i.push("0");e.splice.apply(e,i)}let o=new Uint8Array(t+16);for(n=0;n<e.length;n++){let i=parseInt(e[n],16);o[t++]=i>>8&255,o[t++]=i&255}return o}throw new Error("invalid ip address")},Js=function(r,t=0,e){t=~~t,e=e??r.length-t;let n=new DataView(r.buffer);if(e===4){let o=[];for(let i=0;i<e;i++)o.push(r[t+i]);return o.join(".")}if(e===16){let o=[];for(let i=0;i<e;i+=2)o.push(n.getUint16(t+i).toString(16));return o.join(":").replace(/(^|:)0(:0)*:0(:|$)/,"$1::$3").replace(/:{3,4}/,"::")}return""};var He={},Zo={},hl=[[4,32,"ip4"],[6,16,"tcp"],[33,16,"dccp"],[41,128,"ip6"],[42,-1,"ip6zone"],[43,8,"ipcidr"],[53,-1,"dns",!0],[54,-1,"dns4",!0],[55,-1,"dns6",!0],[56,-1,"dnsaddr",!0],[132,16,"sctp"],[273,16,"udp"],[275,0,"p2p-webrtc-star"],[276,0,"p2p-webrtc-direct"],[277,0,"p2p-stardust"],[280,0,"webrtc-direct"],[281,0,"webrtc"],[290,0,"p2p-circuit"],[301,0,"udt"],[302,0,"utp"],[400,-1,"unix",!1,!0],[421,-1,"ipfs"],[421,-1,"p2p"],[443,0,"https"],[444,96,"onion"],[445,296,"onion3"],[446,-1,"garlic64"],[448,0,"tls"],[449,-1,"sni"],[460,0,"quic"],[461,0,"quic-v1"],[465,0,"webtransport"],[466,-1,"certhash"],[477,0,"ws"],[478,0,"wss"],[479,0,"p2p-websocket-star"],[480,0,"http"],[481,-1,"http-path"],[777,-1,"memory"]];hl.forEach(r=>{let t=pl(...r);Zo[t.code]=t,He[t.name]=t});function pl(r,t,e,n,o){return{code:r,size:t,name:e,resolvable:!!n,path:!!o}}function O(r){if(typeof r=="number"){if(Zo[r]!=null)return Zo[r];throw new Error(`no protocol with code: ${r}`)}else if(typeof r=="string"){if(He[r]!=null)return He[r];throw new Error(`no protocol with name: ${r}`)}throw new Error(`invalid protocol id type: ${typeof r}`)}var Eg=O("ip4"),vg=O("ip6"),Sg=O("ipcidr");function jo(r,t){switch(O(r).code){case 4:case 41:return gl(t);case 42:return Jo(t);case 6:case 273:case 33:case 132:return ec(t).toString();case 53:case 54:case 55:case 56:case 400:case 449:case 777:return Jo(t);case 421:return xl(t);case 444:return tc(t);case 445:return tc(t);case 466:return wl(t);case 481:return globalThis.encodeURIComponent(Jo(t));default:return W(t,"base16")}}function ti(r,t){switch(O(r).code){case 4:return js(t);case 41:return js(t);case 42:return Qo(t);case 6:case 273:case 33:case 132:return ei(parseInt(t,10));case 53:case 54:case 55:case 56:case 400:case 449:case 777:return Qo(t);case 421:return yl(t);case 444:return El(t);case 445:return vl(t);case 466:return bl(t);case 481:return Qo(globalThis.decodeURIComponent(t));default:return Mt(t,"base16")}}var Xo=Object.values(er).map(r=>r.decoder),ml=function(){let r=Xo[0].or(Xo[1]);return Xo.slice(2).forEach(t=>r=r.or(t)),r}();function js(r){if(!on(r))throw new Error("invalid ip address");return Yo(r)}function gl(r){let t=Js(r,0,r.length);if(t==null)throw new Error("ipBuff is required");if(!on(t))throw new Error("invalid ip address");return t}function ei(r){let t=new ArrayBuffer(2);return new DataView(t).setUint16(0,r),new Uint8Array(t)}function ec(r){return new DataView(r.buffer).getUint16(r.byteOffset)}function Qo(r){let t=Mt(r),e=Uint8Array.from(_t(t.length));return yt([e,t],e.length+t.length)}function Jo(r){let t=kt(r);if(r=r.slice(H(t)),r.length!==t)throw new Error("inconsistent lengths");return W(r)}function yl(r){let t;r[0]==="Q"||r[0]==="1"?t=Ct(M.decode(`z${r}`)).bytes:t=Q.parse(r).multihash.bytes;let e=Uint8Array.from(_t(t.length));return yt([e,t],e.length+t.length)}function bl(r){let t=ml.decode(r),e=Uint8Array.from(_t(t.length));return yt([e,t],e.length+t.length)}function wl(r){let t=kt(r),e=r.slice(H(t));if(e.length!==t)throw new Error("inconsistent lengths");return"u"+W(e,"base64url")}function xl(r){let t=kt(r),e=r.slice(H(t));if(e.length!==t)throw new Error("inconsistent lengths");return W(e,"base58btc")}function El(r){let t=r.split(":");if(t.length!==2)throw new Error(`failed to parse onion addr: ["'${t.join('", "')}'"]' does not contain a port number`);if(t[0].length!==16)throw new Error(`failed to parse onion addr: ${t[0]} not a Tor onion address.`);let e=Pt.decode("b"+t[0]),n=parseInt(t[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=ei(n);return yt([e,o],e.length+o.length)}function vl(r){let t=r.split(":");if(t.length!==2)throw new Error(`failed to parse onion addr: ["'${t.join('", "')}'"]' does not contain a port number`);if(t[0].length!==56)throw new Error(`failed to parse onion addr: ${t[0]} not a Tor onion3 address.`);let e=Pt.decode(`b${t[0]}`),n=parseInt(t[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=ei(n);return yt([e,o],e.length+o.length)}function tc(r){let t=r.slice(0,r.length-2),e=r.slice(r.length-2),n=W(t,"base32"),o=ec(e);return`${n}:${o}`}function rc(r){r=ri(r);let t=[],e=[],n=null,o=r.split("/").slice(1);if(o.length===1&&o[0]==="")return{bytes:new Uint8Array,string:"/",tuples:[],stringTuples:[],path:null};for(let i=0;i<o.length;i++){let s=o[i],c=O(s);if(c.size===0){t.push([c.code]),e.push([c.code]);continue}if(i++,i>=o.length)throw oc("invalid address: "+r);if(c.path===!0){n=ri(o.slice(i).join("/")),t.push([c.code,ti(c.code,n)]),e.push([c.code,n]);break}let a=ti(c.code,o[i]);t.push([c.code,a]),e.push([c.code,jo(c.code,a)])}return{string:nc(e),bytes:oi(t),tuples:t,stringTuples:e,path:n}}function ni(r){let t=[],e=[],n=null,o=0;for(;o<r.length;){let i=kt(r,o),s=H(i),c=O(i),a=Sl(c,r.slice(o+s));if(a===0){t.push([i]),e.push([i]),o+=s;continue}let l=r.slice(o+s,o+s+a);if(o+=a+s,o>r.length)throw oc("Invalid address Uint8Array: "+W(r,"base16"));t.push([i,l]);let f=jo(i,l);if(e.push([i,f]),c.path===!0){n=f;break}}return{bytes:Uint8Array.from(r),string:nc(e),tuples:t,stringTuples:e,path:n}}function nc(r){let t=[];return r.map(e=>{let n=O(e[0]);return t.push(n.name),e.length>1&&e[1]!=null&&t.push(e[1]),null}),ri(t.join("/"))}function oi(r){return yt(r.map(t=>{let e=O(t[0]),n=Uint8Array.from(_t(e.code));return t.length>1&&t[1]!=null&&(n=yt([n,t[1]])),n}))}function Sl(r,t){if(r.size>0)return r.size/8;if(r.size===0)return 0;{let e=kt(t instanceof Uint8Array?t:Uint8Array.from(t));return e+H(e)}}function ri(r){return"/"+r.trim().split("/").filter(t=>t).join("/")}function oc(r){return new Error("Error parsing address: "+r)}var Il=Symbol.for("nodejs.util.inspect.custom"),si=Symbol.for("@multiformats/js-multiaddr/multiaddr"),Al=[O("dns").code,O("dns4").code,O("dns6").code,O("dnsaddr").code],ii=class extends Error{constructor(t="No available resolver"){super(t),this.name="NoAvailableResolverError"}},sn=class r{bytes;#t;#e;#r;#n;[si]=!0;constructor(t){t==null&&(t="");let e;if(t instanceof Uint8Array)e=ni(t);else if(typeof t=="string"){if(t.length>0&&t.charAt(0)!=="/")throw new Error(`multiaddr "${t}" must start with a "/"`);e=rc(t)}else if(sc(t))e=ni(t.bytes);else throw new Error("addr must be a string, Buffer, or another Multiaddr");this.bytes=e.bytes,this.#t=e.string,this.#e=e.tuples,this.#r=e.stringTuples,this.#n=e.path}toString(){return this.#t}toJSON(){return this.toString()}toOptions(){let t,e,n,o,i="",s=O("tcp"),c=O("udp"),a=O("ip4"),l=O("ip6"),f=O("dns6"),d=O("ip6zone");for(let[g,b]of this.stringTuples())g===d.code&&(i=`%${b??""}`),Al.includes(g)&&(e=s.name,o=443,n=`${b??""}${i}`,t=g===f.code?6:4),(g===s.code||g===c.code)&&(e=O(g).name,o=parseInt(b??"")),(g===a.code||g===l.code)&&(e=O(g).name,n=`${b??""}${i}`,t=g===l.code?6:4);if(t==null||e==null||n==null||o==null)throw new Error('multiaddr must have a valid format: "/{ip4, ip6, dns4, dns6, dnsaddr}/{address}/{tcp, udp}/{port}".');return{family:t,host:n,transport:e,port:o}}protos(){return this.#e.map(([t])=>Object.assign({},O(t)))}protoCodes(){return this.#e.map(([t])=>t)}protoNames(){return this.#e.map(([t])=>O(t).name)}tuples(){return this.#e}stringTuples(){return this.#r}encapsulate(t){return t=new r(t),new r(this.toString()+t.toString())}decapsulate(t){let e=t.toString(),n=this.toString(),o=n.lastIndexOf(e);if(o<0)throw new Error(`Address ${this.toString()} does not contain subaddress: ${t.toString()}`);return new r(n.slice(0,o))}decapsulateCode(t){let e=this.tuples();for(let n=e.length-1;n>=0;n--)if(e[n][0]===t)return new r(oi(e.slice(0,n)));return this}getPeerId(){try{let t=[];this.stringTuples().forEach(([n,o])=>{n===He.p2p.code&&t.push([n,o]),n===He["p2p-circuit"].code&&(t=[])});let e=t.pop();if(e?.[1]!=null){let n=e[1];return n[0]==="Q"||n[0]==="1"?W(M.decode(`z${n}`),"base58btc"):W(Q.parse(n).multihash.bytes,"base58btc")}return null}catch{return null}}getPath(){return this.#n}equals(t){return Dt(this.bytes,t.bytes)}async resolve(t){let e=this.protos().find(i=>i.resolvable);if(e==null)return[this];let n=ic.get(e.name);if(n==null)throw new ii(`no available resolver for ${e.name}`);return(await n(this,t)).map(i=>lt(i))}nodeAddress(){let t=this.toOptions();if(t.transport!=="tcp"&&t.transport!=="udp")throw new Error(`multiaddr must have a valid format - no protocol with name: "${t.transport}". Must have a valid transport protocol: "{tcp, udp}"`);return{family:t.family,address:t.host,port:t.port}}isThinWaistAddress(t){let e=(t??this).protos();return!(e.length!==2||e[0].code!==4&&e[0].code!==41||e[1].code!==6&&e[1].code!==273)}[Il](){return`Multiaddr(${this.#t})`}};var ic=new Map;function sc(r){return!!r?.[si]}function lt(r){return new sn(r)}var Tl=w("dns4"),Ll=w("dns6"),Bl=w("dnsaddr"),Ie=z(w("dns"),Bl,Tl,Ll),un=z(w("ip4"),w("ip6")),ue=z(L(un,w("tcp")),L(Ie,w("tcp"))),ln=L(un,w("udp")),kl=L(ln,w("utp")),Nl=L(ln,w("quic")),Pl=L(ln,w("quic-v1")),ci=z(L(ue,w("ws")),L(Ie,w("ws"))),cn=z(L(ci,w("p2p")),ci),ai=z(L(ue,w("wss")),L(Ie,w("wss")),L(ue,w("tls"),w("ws")),L(Ie,w("tls"),w("ws"))),an=z(L(ai,w("p2p")),ai),ui=z(L(ue,w("http")),L(un,w("http")),L(Ie,w("http"))),li=z(L(ue,w("https")),L(un,w("https")),L(Ie,w("https"))),cc=L(ln,w("webrtc-direct"),w("certhash")),lc=z(L(cc,w("p2p")),cc),ac=L(Pl,w("webtransport"),w("certhash"),w("certhash")),fc=z(L(ac,w("p2p")),ac),dc=z(L(cn,w("p2p-webrtc-star"),w("p2p")),L(an,w("p2p-webrtc-star"),w("p2p")),L(cn,w("p2p-webrtc-star")),L(an,w("p2p-webrtc-star"))),Yg=z(L(cn,w("p2p-websocket-star"),w("p2p")),L(an,w("p2p-websocket-star"),w("p2p")),L(cn,w("p2p-websocket-star")),L(an,w("p2p-websocket-star"))),hc=z(L(ui,w("p2p-webrtc-direct"),w("p2p")),L(li,w("p2p-webrtc-direct"),w("p2p")),L(ui,w("p2p-webrtc-direct")),L(li,w("p2p-webrtc-direct"))),Ae=z(ci,ai,ui,li,dc,hc,ue,kl,Nl,Ie,lc,fc),Zg=z(L(Ae,w("p2p-stardust"),w("p2p")),L(Ae,w("p2p-stardust"))),ae=z(L(Ae,w("p2p")),dc,hc,lc,fc,w("p2p")),uc=z(L(ae,w("p2p-circuit"),ae),L(ae,w("p2p-circuit")),L(w("p2p-circuit"),ae),L(Ae,w("p2p-circuit")),L(w("p2p-circuit"),Ae),w("p2p-circuit")),pc=()=>z(L(uc,pc),uc),Se=pc(),Xg=z(L(Se,ae,Se),L(ae,Se),L(Se,ae),Se,ae);var Qg=z(L(Se,w("webrtc"),w("p2p")),L(Se,w("webrtc")),L(Ae,w("webrtc"),w("p2p")),L(Ae,w("webrtc")),w("webrtc"));function mc(r){function t(e){let n;try{n=lt(e)}catch{return!1}let o=r(n.protoNames());return o===null?!1:o===!0||o===!1?o:o.length===0}return t}function L(...r){function t(e){if(e.length<r.length)return null;let n=e;return r.some(o=>(n=typeof o=="function"?o().partialMatch(e):o.partialMatch(e),Array.isArray(n)&&(e=n),n===null)),n}return{toString:function(){return"{ "+r.join(" ")+" }"},input:r,matches:mc(t),partialMatch:t}}function z(...r){function t(n){let o=null;return r.some(i=>{let s=typeof i=="function"?i().partialMatch(n):i.partialMatch(n);return s!=null?(o=s,!0):!1}),o}return{toString:function(){return"{ "+r.join(" ")+" }"},input:r,matches:mc(t),partialMatch:t}}function w(r){let t=r;function e(o){let i;try{i=lt(o)}catch{return!1}let s=i.protoNames();return s.length===1&&s[0]===t}function n(o){return o.length===0?null:o[0]===t?o.slice(1):null}return{toString:function(){return t},matches:e,partialMatch:n}}var fn=class extends Event{type;detail;constructor(t,e){super(t),this.type=t,this.detail=e}};var Ec=ht(Y("net"),1);function gc(r,t){if(typeof r!="string")throw new gt(`invalid ip provided: ${r}`);if(typeof t=="string"&&(t=parseInt(t)),isNaN(t))throw new gt(`invalid port provided: ${t}`);if((0,Lt.isIPv4)(r))return lt(`/ip4/${r}/tcp/${t}`);if((0,Lt.isIPv6)(r))return lt(`/ip6/${r}/tcp/${t}`);throw new gt(`invalid ip:port for creating a multiaddr: ${r}:${t}`)}function yc(r){if(Dl(r))return async function*(){let t=r.getReader();try{for(;;){let{done:e,value:n}=await t.read();if(e)return;yield n}}finally{t.releaseLock()}}();if(Ol(r))return r;throw new Error("unknown stream")}function Ol(r){return r[Symbol.asyncIterator]!=null}function Dl(r){return typeof r?.getReader=="function"}function bc(r){return async t=>{let e=async()=>{Ul(t)&&await t.return(void 0)},n,o,i=p=>{n=p,e().catch(y=>{y=new AggregateError([n,y],"The Writable emitted an error, additionally an error occurred while ending the Source")}).finally(()=>{o?.(p)})},s,c=!1,a=()=>{c=!0,s?.()},l,f=!1,d=()=>{f=!0,l?.()},h,g=()=>{h?.()},b=async()=>new Promise((p,y)=>{s=h=p,o=y,r.once("drain",g)}),m=async()=>(await e(),new Promise((p,y)=>{if(c||f||n!=null){p();return}l=s=p,o=y})),u=()=>{r.removeListener("error",i),r.removeListener("close",a),r.removeListener("finish",d),r.removeListener("drain",g)};r.once("error",i),r.once("close",a),r.once("finish",d);try{for await(let p of t){if(!r.writable||r.destroyed||n!=null)break;r.write(p)||await b()}}catch(p){n==null&&r.destroy(p),n=p}try{if(r.writable&&r.end(),await m(),n!=null)throw n}finally{u()}}}function Ul(r){return r.return!=null}function fi(r){return{sink:bc(r),source:yc(r)}}var di=ht(Y("os"),1),wc=ht(Y("path"),1);var Rl={ip4:"IPv4",ip6:"IPv6"};function qe(r,t={}){let e=r.getPath();return e!=null?di.default.platform()==="win32"?{path:wc.default.join("\\\\.\\pipe\\",e)}:{path:e}:{...t,...r.toOptions()}}function hi(r,t,e){let n=o=>lt(`/${r}/${o}/tcp/${e}`);return(_l(t)?Kl(Rl[r]):[t]).map(n)}function _l(r){return["0.0.0.0","::"].includes(r)}var Ml=di.default.networkInterfaces();function Kl(r){let t=[];for(let[,e]of Object.entries(Ml))if(e!=null)for(let n of e)n.family===r&&t.push(n.address);return t}var dn=(r,t)=>{let e=null,n=t.logger.forComponent("libp2p:tcp:socket"),o=t.metrics,i=t.metricPrefix??"",s=t.socketInactivityTimeout??3e5,c=t.socketCloseTimeout??500;t.listeningAddr?.getPath()!=null&&(t.remoteAddr=t.listeningAddr),t.remoteAddr?.getPath()!=null&&(t.localAddr=t.remoteAddr);let a;if(t.remoteAddr!=null)a=t.remoteAddr;else{if(r.remoteAddress==null||r.remotePort==null)throw new gt("Could not determine remote address or port");a=gc(r.remoteAddress,r.remotePort)}let l=qe(a),f=l.path??`${l.host??""}:${l.port??""}`,{sink:d,source:h}=fi(r);r.setTimeout(s,()=>{n("%s socket read timeout",f),o?.increment({[`${i}timeout`]:!0});let b;r.readable&&(b=new Re("Socket read timeout")),r.destroy(b)}),r.once("close",()=>{n("%s socket close",f),o?.increment({[`${i}close`]:!0}),g.timeline.close==null&&(g.timeline.close=Date.now())}),r.once("end",()=>{n("%s socket end",f),o?.increment({[`${i}end`]:!0})});let g={async sink(b){try{await d(async function*(){for await(let m of b)m instanceof Uint8Array?yield m:yield m.subarray()}())}catch(m){m.type!=="aborted"&&n.error("%s error in sink",f,m)}r.end()},source:h,remoteAddr:a,timeline:{open:Date.now()},async close(b={}){if(r.destroyed){n("The %s socket is destroyed",f);return}if(e!=null)return n("The %s socket is closed or closing",f),e;if(b.signal==null){let u=AbortSignal.timeout(c);b={...b,signal:u}}let m=()=>{r.destroy(new Gt("Destroying socket after timeout"))};b.signal?.addEventListener("abort",m);try{n("%s closing socket",f),e=new Promise((u,p)=>{r.once("close",()=>{n("%s socket closed",f),u()}),r.once("error",y=>{n("%s socket error",f,y),g.timeline.close==null&&(g.timeline.close=Date.now()),r.destroyed||p(y)}),r.setTimeout(c),r.end(),r.writableLength>0?r.once("drain",()=>{n("%s socket drained",f),r.destroy()}):r.destroy()}),await e}catch(u){this.abort(u)}finally{b.signal?.removeEventListener("abort",m)}},abort:b=>{n("%s socket abort due to error",f,b),r.destroyed||r.destroy(b),g.timeline.close==null&&(g.timeline.close=Date.now())},log:n};return g};async function xc(r,t){try{await r.close()}catch(e){t.log.error("an error occurred closing the connection",e),r.abort(e)}}var j;(function(r){r[r.INACTIVE=0]="INACTIVE",r[r.ACTIVE=1]="ACTIVE",r[r.PAUSED=2]="PAUSED"})(j||(j={}));var hn=class extends Kr{context;server;connections=new Set;status={code:j.INACTIVE};metrics;addr;log;constructor(t){if(super(),this.context=t,t.keepAlive=t.keepAlive??!0,t.noDelay=t.noDelay??!0,this.log=t.logger.forComponent("libp2p:tcp:listener"),this.addr="unknown",this.server=Ec.default.createServer(t,this.onSocket.bind(this)),t.maxConnections!==void 0&&(this.server.maxConnections=t.maxConnections),t.closeServerOnMaxConnections!=null&&t.closeServerOnMaxConnections.closeAbove<t.closeServerOnMaxConnections.listenBelow)throw new gt("closeAbove must be >= listenBelow");this.server.on("listening",()=>{if(t.metrics!=null){let e=this.server.address();e==null?this.addr="unknown":typeof e=="string"?this.addr=e:this.addr=`${e.address}:${e.port}`,t.metrics?.registerMetricGroup("libp2p_tcp_inbound_connections_total",{label:"address",help:"Current active connections in TCP listener",calculate:()=>({[this.addr]:this.connections.size})}),this.metrics={status:t.metrics.registerMetricGroup("libp2p_tcp_listener_status_info",{label:"address",help:"Current status of the TCP listener socket"}),errors:t.metrics.registerMetricGroup("libp2p_tcp_listener_errors_total",{label:"address",help:"Total count of TCP listener errors by type"}),events:t.metrics.registerMetricGroup("libp2p_tcp_listener_events_total",{label:"address",help:"Total count of TCP listener events by type"})},this.metrics?.status.update({[this.addr]:j.ACTIVE})}this.safeDispatchEvent("listening")}).on("error",e=>{this.metrics?.errors.increment({[`${this.addr} listen_error`]:!0}),this.safeDispatchEvent("error",{detail:e})}).on("close",()=>{this.metrics?.status.update({[this.addr]:this.status.code}),this.status.code!==j.PAUSED&&this.safeDispatchEvent("close")})}onSocket(t){if(this.status.code!==j.ACTIVE)throw new _r("Server is not listening yet");t.on("error",n=>{this.log("socket error",n),this.metrics?.events.increment({[`${this.addr} error`]:!0})});let e;try{e=dn(t,{listeningAddr:this.status.listeningAddr,socketInactivityTimeout:this.context.socketInactivityTimeout,socketCloseTimeout:this.context.socketCloseTimeout,metrics:this.metrics?.events,metricPrefix:`${this.addr} `,logger:this.context.logger})}catch(n){this.log.error("inbound connection failed",n),this.metrics?.errors.increment({[`${this.addr} inbound_to_connection`]:!0});return}this.log("new inbound connection %s",e.remoteAddr);try{this.context.upgrader.upgradeInbound(e).then(n=>{this.log("inbound connection upgraded %s",e.remoteAddr),this.connections.add(e),t.once("close",()=>{this.connections.delete(e),this.context.closeServerOnMaxConnections!=null&&this.connections.size<this.context.closeServerOnMaxConnections.listenBelow&&this.resume().catch(o=>{this.log.error("error attempting to listen server once connection count under limit",o),this.context.closeServerOnMaxConnections?.onListenError?.(o)})}),this.context.handler!=null&&this.context.handler(n),this.context.closeServerOnMaxConnections!=null&&this.connections.size>=this.context.closeServerOnMaxConnections.closeAbove&&this.pause(!1).catch(o=>{this.log.error("error attempting to close server once connection count over limit",o)}),this.safeDispatchEvent("connection",{detail:n})}).catch(async n=>{this.log.error("inbound connection failed",n),this.metrics?.errors.increment({[`${this.addr} inbound_upgrade`]:!0}),await xc(e,{log:this.log})}).catch(n=>{this.log.error("closing inbound connection failed",n)})}catch(n){this.log.error("inbound connection failed",n),xc(e,{log:this.log}).catch(o=>{this.log.error("closing inbound connection failed",o),this.metrics?.errors.increment({[`${this.addr} inbound_closing_failed`]:!0})})}}getAddrs(){if(this.status.code===j.INACTIVE)return[];let t=[],e=this.server.address(),{listeningAddr:n,peerId:o}=this.status;if(e==null)return[];if(typeof e=="string")t=[n];else try{n.toString().startsWith("/ip4")?t=t.concat(hi("ip4",e.address,e.port)):e.family==="IPv6"&&(t=t.concat(hi("ip6",e.address,e.port)))}catch(i){this.log.error("could not turn %s:%s into multiaddr",e.address,e.port,i)}return t.map(i=>o!=null?i.encapsulate(`/p2p/${o}`):i)}async listen(t){if(this.status.code===j.ACTIVE||this.status.code===j.PAUSED)throw new Mr("server is already listening");let e=t.getPeerId(),n=e==null?t.decapsulateCode(421):t,{backlog:o}=this.context;try{this.status={code:j.ACTIVE,listeningAddr:n,peerId:e,netConfig:qe(n,{backlog:o})},await this.resume()}catch(i){throw this.status={code:j.INACTIVE},i}}async close(){let t=new Gt("Listener is closing");this.connections.forEach(e=>{e.abort(t)}),await this.pause(!0)}async resume(){if(this.server.listening||this.status.code===j.INACTIVE)return;let t=this.status.netConfig;await new Promise((e,n)=>{this.server.once("error",n),this.server.listen(t,e)}),this.status={...this.status,code:j.ACTIVE},this.log("listening on %s",this.server.address())}async pause(t){if(!this.server.listening&&this.status.code===j.PAUSED&&t){this.status={code:j.INACTIVE};return}!this.server.listening||this.status.code!==j.ACTIVE||(this.log("closing server on %s",this.server.address()),this.status=t?{code:j.INACTIVE}:{...this.status,code:j.PAUSED},await new Promise((e,n)=>{this.server.close(o=>{if(o!=null){n(o);return}e()})}))}};var pn=class{opts;metrics;components;log;constructor(t,e={}){this.log=t.logger.forComponent("libp2p:tcp"),this.opts=e,this.components=t,t.metrics!=null&&(this.metrics={dialerEvents:t.metrics.registerCounterGroup("libp2p_tcp_dialer_events_total",{label:"event",help:"Total count of TCP dialer events by type"})})}[as]=!0;[Symbol.toStringTag]="@libp2p/tcp";[fs]=["@libp2p/transport"];async dial(t,e){e.keepAlive=e.keepAlive??!0,e.noDelay=e.noDelay??!0;let n=await this._connect(t,e);n.on("error",c=>{this.log("socket error",c)});let o=dn(n,{remoteAddr:t,socketInactivityTimeout:this.opts.outboundSocketInactivityTimeout,socketCloseTimeout:this.opts.socketCloseTimeout,metrics:this.metrics?.dialerEvents,logger:this.components.logger}),i=()=>{o.close().catch(c=>{this.log.error("Error closing maConn after abort",c)})};e.signal?.addEventListener("abort",i,{once:!0}),this.log("new outbound connection %s",o.remoteAddr);let s=await e.upgrader.upgradeOutbound(o);if(this.log("outbound connection %s upgraded",o.remoteAddr),e.signal?.removeEventListener("abort",i),e.signal?.aborted===!0)throw s.close().catch(c=>{this.log.error("Error closing conn after abort",c)}),new Gt;return s}async _connect(t,e){return e.signal?.throwIfAborted(),e.onProgress?.(new fn("tcp:open-connection")),new Promise((n,o)=>{let i=Date.now(),s=qe(t,{...this.opts.dialOpts??{},...e});this.log("dialing %a",t);let c=vc.default.connect(s),a=g=>{let b=s.path??`${s.host??""}:${s.port}`;g.message=`connection error ${b}: ${g.message}`,this.metrics?.dialerEvents.increment({error:!0}),h(g)},l=()=>{this.log("connection timeout %a",t),this.metrics?.dialerEvents.increment({timeout:!0});let g=new Re(`connection timeout after ${Date.now()-i}ms`);c.emit("error",g)},f=()=>{this.log("connection opened %a",t),this.metrics?.dialerEvents.increment({connect:!0}),h()},d=()=>{this.log("connection aborted %a",t),this.metrics?.dialerEvents.increment({abort:!0}),c.destroy(),h(new Gt)},h=g=>{if(c.removeListener("error",a),c.removeListener("timeout",l),c.removeListener("connect",f),e.signal!=null&&e.signal.removeEventListener("abort",d),g!=null){o(g);return}n(c)};c.on("error",a),c.on("timeout",l),c.on("connect",f),e.signal!=null&&e.signal.addEventListener("abort",d)})}createListener(t){return new hn({...this.opts.listenOpts??{},...t,maxConnections:this.opts.maxConnections,backlog:this.opts.backlog,closeServerOnMaxConnections:this.opts.closeServerOnMaxConnections,socketInactivityTimeout:this.opts.inboundSocketInactivityTimeout,socketCloseTimeout:this.opts.socketCloseTimeout,metrics:this.components.metrics,logger:this.components.logger})}listenFilter(t){return t=Array.isArray(t)?t:[t],t.filter(e=>e.protoCodes().includes(290)?!1:e.protoCodes().includes(400)?!0:ue.matches(e.decapsulateCode(421)))}dialFilter(t){return this.listenFilter(t)}};function Sc(r={}){return t=>new pn(t,r)}var Ac=Symbol.for("@achingbrain/uint8arraylist");function Ic(r,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let e=0;for(let n of r){let o=e+n.byteLength;if(t<o)return{buf:n,index:t-e};e=o}throw new RangeError("index is out of bounds")}function mn(r){return!!r?.[Ac]}var xt=class r{bufs;length;[Ac]=!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(mn(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(mn(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=Ic(this.bufs,t);return e.buf[e.index]}set(t,e){let n=Ic(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(mn(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:o}=this._subList(t,e);return yt(n,o)}subarray(t,e){let{bufs:n,length:o}=this._subList(t,e);return n.length===1?n[0]:yt(n,o)}sublist(t,e){let{bufs:n,length:o}=this._subList(t,e),i=new r;return i.length=o,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=[],o=0;for(let i=0;i<this.bufs.length;i++){let s=this.bufs[i],c=o,a=c+s.byteLength;if(o=a,t>=a)continue;let l=t>=c&&t<a,f=e>c&&e<=a;if(l&&f){if(t===c&&e===a){n.push(s);break}let d=t-c;n.push(s.subarray(d,d+(e-t)));break}if(l){if(t===0){n.push(s);continue}n.push(s.subarray(t-c));continue}if(f){if(e===a){n.push(s);break}n.push(s.subarray(0,e-c));break}n.push(s)}return{bufs:n,length:e-t}}indexOf(t,e=0){if(!mn(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 o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let i=256,s=new Int32Array(i);for(let d=0;d<i;d++)s[d]=-1;for(let d=0;d<o;d++)s[n[d]]=d;let c=s,a=this.byteLength-n.byteLength,l=n.byteLength-1,f;for(let d=e;d<=a;d+=f){f=0;for(let h=l;h>=0;h--){let g=this.get(d+h);if(n[h]!==g){f=Math.max(1,h-c[g]);break}}if(f===0)return d}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=ut(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 o=Kt(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,e,n),this.write(o,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 o=Kt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,e,n),this.write(o,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 o=Kt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,e,n),this.write(o,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=ut(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 o=Kt(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,e,n),this.write(o,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 o=Kt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,e,n),this.write(o,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 o=Kt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,e,n),this.write(o,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 o=Kt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,e,n),this.write(o,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 o=Kt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,e,n),this.write(o,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(!Dt(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((o,i)=>o+i.byteLength,0)),n.length=e,n}};function gn(r){return r[Symbol.asyncIterator]!=null}var yn=r=>{let t=H(r),e=ut(t);return _t(r,e),yn.bytes=t,e};yn.bytes=0;function bn(r,t){t=t??{};let e=t.lengthEncoder??yn;function*n(o){let i=e(o.byteLength);i instanceof Uint8Array?yield i:yield*i,o instanceof Uint8Array?yield o:yield*o}return gn(r)?async function*(){for await(let o of r)yield*n(o)}():function*(){for(let o of r)yield*n(o)}()}bn.single=(r,t)=>{t=t??{};let e=t.lengthEncoder??yn;return new xt(e(r.byteLength),r)};var wn=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},xn=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},En=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"},dr=class extends Error{name="UnexpectedEOFError";code="ERR_UNEXPECTED_EOF"};var Vl=8,Gl=1024*1024*4,Te;(function(r){r[r.LENGTH=0]="LENGTH",r[r.DATA=1]="DATA"})(Te||(Te={}));var mi=r=>{let t=kt(r);return mi.bytes=H(t),t};mi.bytes=0;function pi(r,t){let e=new xt,n=Te.LENGTH,o=-1,i=t?.lengthDecoder??mi,s=t?.maxLengthLength??Vl,c=t?.maxDataLength??Gl;function*a(){for(;e.byteLength>0;){if(n===Te.LENGTH)try{if(o=i(e),o<0)throw new wn("Invalid message length");if(o>c)throw new xn("Message length too long");let l=i.bytes;e.consume(l),t?.onLength!=null&&t.onLength(o),n=Te.DATA}catch(l){if(l instanceof RangeError){if(e.byteLength>s)throw new En("Message length length too long");break}throw l}if(n===Te.DATA){if(e.byteLength<o)break;let l=e.sublist(0,o);e.consume(o),t?.onData!=null&&t.onData(l),yield l,n=Te.LENGTH}}}return gn(r)?async function*(){for await(let l of r)e.append(l),yield*a();if(e.byteLength>0)throw new dr("Unexpected end of input")}():function*(){for(let l of r)e.append(l),yield*a();if(e.byteLength>0)throw new dr("Unexpected end of input")}()}pi.fromReader=(r,t)=>{let e=1,n=async function*(){for(;;)try{let{done:i,value:s}=await r.next(e);if(i===!0)return;s!=null&&(yield s)}catch(i){if(i.code==="ERR_UNDER_READ")return{done:!0,value:null};throw i}finally{e=1}}();return pi(n,{...t??{},onLength:i=>{e=i}})};function Yt(){let r={};return r.promise=new Promise((t,e)=>{r.resolve=t,r.reject=e}),r}var vn=class extends Error{type;code;constructor(t,e,n){super(t??"The operation was aborted"),this.type="aborted",this.name=n??"AbortError",this.code=e??"ABORT_ERR"}};async function Tc(r,t,e){if(t==null)return r;if(t.aborted)return Promise.reject(new vn(e?.errorMessage,e?.errorCode,e?.errorName));let n,o=new vn(e?.errorMessage,e?.errorCode,e?.errorName);try{return await Promise.race([r,new Promise((i,s)=>{n=()=>{s(o)},t.addEventListener("abort",n)})])}finally{n!=null&&t.removeEventListener("abort",n)}}var gi=class{readNext;haveNext;ended;nextResult;constructor(){this.ended=!1,this.readNext=Yt(),this.haveNext=Yt()}[Symbol.asyncIterator](){return this}async next(){if(this.nextResult==null&&await this.haveNext.promise,this.nextResult==null)throw new Error("HaveNext promise resolved but nextResult was undefined");let t=this.nextResult;return this.nextResult=void 0,this.readNext.resolve(),this.readNext=Yt(),t}async throw(t){return this.ended=!0,t!=null&&(this.haveNext.promise.catch(()=>{}),this.haveNext.reject(t)),{done:!0,value:void 0}}async return(){let t={done:!0,value:void 0};return await this._push(void 0),t}async push(t,e){await this._push(t,e)}async end(t,e){t!=null?await this.throw(t):await this._push(void 0,e)}async _push(t,e){if(t!=null&&this.ended)throw new Error("Cannot push value onto an ended pushable");for(;this.nextResult!=null;)await this.readNext.promise;t!=null?this.nextResult={done:!1,value:t}:(this.ended=!0,this.nextResult={done:!0,value:void 0}),this.haveNext.resolve(),this.haveNext=Yt(),await Tc(this.readNext.promise,e?.signal,e)}};function Lc(){return new gi}var Sn=class extends Error{name="UnexpectedEOFError";code="ERR_UNEXPECTED_EOF"};var yi=class extends Error{code;constructor(t,e){super(t),this.code=e}},bi=class extends yi{type;constructor(t){super(t,"ABORT_ERR"),this.type="aborted",this.name="AbortError"}};function Bc(r,t){let e=Lc();r.sink(e).catch(async s=>{await e.end(s)}),r.sink=async s=>{for await(let c of s)await e.push(c);await e.end()};let n=r.source;r.source[Symbol.iterator]!=null?n=r.source[Symbol.iterator]():r.source[Symbol.asyncIterator]!=null&&(n=r.source[Symbol.asyncIterator]());let o=new xt;return{read:async(s,c)=>{c?.signal?.throwIfAborted();let a,l=new Promise((f,d)=>{a=()=>{d(new bi("Read aborted"))},c?.signal?.addEventListener("abort",a)});try{if(s==null){let{done:d,value:h}=await Promise.race([n.next(),l]);return d===!0?new xt:h}for(;o.byteLength<s;){let{value:d,done:h}=await Promise.race([n.next(),l]);if(h===!0)throw new Sn("unexpected end of input");o.append(d)}let f=o.sublist(0,s);return o.consume(s),f}finally{a!=null&&c?.signal?.removeEventListener("abort",a)}},write:async(s,c)=>{c?.signal?.throwIfAborted(),s instanceof Uint8Array?await e.push(s,c):await e.push(s.subarray(),c)},unwrap:()=>{if(o.byteLength>0){let s=r.source;r.source=async function*(){t?.yieldBytes===!1?yield o:yield*o,yield*s}()}return r}}}var In=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},An=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},Tn=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function We(r,t={}){let e=Bc(r,t);t.maxDataLength!=null&&t.maxLengthLength==null&&(t.maxLengthLength=H(t.maxDataLength));let n=t?.lengthDecoder??kt,o=t?.lengthEncoder??_t;return{read:async s=>{let c=-1,a=new xt;for(;;){a.append(await e.read(1,s));try{c=n(a)}catch(l){if(l instanceof RangeError)continue;throw l}if(c<0)throw new In("Invalid message length");if(t?.maxLengthLength!=null&&a.byteLength>t.maxLengthLength)throw new Tn("message length length too long");if(c>-1)break}if(t?.maxDataLength!=null&&c>t.maxDataLength)throw new An("message length too long");return e.read(c,s)},write:async(s,c)=>{await e.write(new xt(o(s.byteLength),s),c)},writeV:async(s,c)=>{let a=new xt(...s.flatMap(l=>[o(l.byteLength),l]));await e.write(a,c)},unwrap:()=>e.unwrap()}}var Ln=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}},Ye=class{size;hwm;head;tail;constructor(t={}){this.hwm=t.splitLimit??16,this.head=new Ln(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 Ln(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 wi=class extends Error{type;code;constructor(t,e){super(t??"The operation was aborted"),this.type="aborted",this.code=e??"ABORT_ERR"}};function Ze(r={}){return zl(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 zl(r,t){t=t??{};let e=t.onEnd,n=new Ye,o,i,s,c=Yt(),a=async()=>{try{return n.isEmpty()?s?{done:!0}:await new Promise((u,p)=>{i=y=>{i=null,n.push(y);try{u(r(n))}catch(E){p(E)}return o}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{c.resolve(),c=Yt()})}},l=u=>i!=null?i(u):(n.push(u),o),f=u=>(n=new Ye,i!=null?i({error:u}):(n.push({error:u}),o)),d=u=>{if(s)return o;if(t?.objectMode!==!0&&u?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return l({done:!1,value:u})},h=u=>s?o:(s=!0,u!=null?f(u):l({done:!0})),g=()=>(n=new Ye,h(),{done:!0}),b=u=>(h(u),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:a,return:g,throw:b,push:d,end:h,get readableLength(){return n.size},onEmpty:async u=>{let p=u?.signal;if(p?.throwIfAborted(),n.isEmpty())return;let y,E;p!=null&&(y=new Promise((S,k)=>{E=()=>{k(new wi)},p.addEventListener("abort",E)}));try{await Promise.race([c.promise,y])}finally{E!=null&&p!=null&&p?.removeEventListener("abort",E)}}},e==null)return o;let m=o;return o={[Symbol.asyncIterator](){return this},next(){return m.next()},throw(u){return m.throw(u),e!=null&&(e(u),e=void 0),{done:!0}},return(){return m.return(),e!=null&&(e(),e=void 0),{done:!0}},push:d,end(u){return m.end(u),e!=null&&(e(u),e=void 0),o},get readableLength(){return m.readableLength},onEmpty:u=>m.onEmpty(u)},o}function Hl(r){return r[Symbol.asyncIterator]!=null}function ql(...r){let t=[];for(let e of r)Hl(e)||t.push(e);return t.length===r.length?function*(){for(let e of t)yield*e}():async function*(){let e=Ze({objectMode:!0});Promise.resolve().then(async()=>{try{await Promise.all(r.map(async n=>{for await(let o of n)e.push(o)})),e.end()}catch(n){e.end(n)}}),yield*e}()}var kc=ql;function Ei(r,...t){if(r==null)throw new Error("Empty pipeline");if(xi(r)){let n=r;r=()=>n.source}else if(Pc(r)||Nc(r)){let n=r;r=()=>n}let e=[r,...t];if(e.length>1&&xi(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++)xi(e[n])&&(e[n]=Yl(e[n]));return Wl(...e)}var Wl=(...r)=>{let t;for(;r.length>0;)t=r.shift()(t);return t},Nc=r=>r?.[Symbol.asyncIterator]!=null,Pc=r=>r?.[Symbol.iterator]!=null,xi=r=>r==null?!1:r.sink!=null&&r.source!=null,Yl=r=>t=>{let e=r.sink(t);if(e?.then!=null){let n=Ze({objectMode:!0});e.then(()=>{n.end()},s=>{n.end(s)});let o,i=r.source;if(Nc(i))o=async function*(){yield*i,n.end()};else if(Pc(i))o=function*(){yield*i,n.end()};else throw new Error("Unknown duplex source type - must be Iterable or AsyncIterable");return kc(n,o())}return r.source};function Cc(r,t){let e=We(r,t),n={read:async(o,i)=>{let s=await e.read(i);return o.decode(s)},write:async(o,i,s)=>{await e.write(i.encode(o),s)},writeV:async(o,i,s)=>{await e.writeV(o.map(c=>i.encode(c)),s)},pb:o=>({read:async i=>n.read(o,i),write:async(i,s)=>n.write(i,o,s),writeV:async(i,s)=>n.writeV(i,o,s),unwrap:()=>n}),unwrap:()=>e.unwrap()};return n}function Zl(r){return r[Symbol.asyncIterator]!=null}function Xl(r){if(Zl(r))return(async()=>{for await(let t of r);})();for(let t of r);}var vi=Xl;function ft(r){return q.encode({type:q.Type.OK,peers:[],...r}).subarray()}function ot(r){return q.encode({type:q.Type.ERROR,error:{msg:r.message},peers:[]}).subarray()}var Bn=ge("libp2p:daemon-server:dht"),kn=class{dht;constructor(t){let{dht:e}=t;this.dht=e}async*provide(t){try{await vi(this.dht.provide(t)),yield ft()}catch(e){Bn.error(e),yield ot(e)}}async*getClosestPeers(t){yield ft({dht:{type:tt.Type.BEGIN}});for await(let e of this.dht.getClosestPeers(t))e.name==="PEER_RESPONSE"&&(yield*e.closer.map(n=>tt.encode({type:tt.Type.VALUE,value:n.id.toMultihash().bytes})));yield tt.encode({type:tt.Type.END})}async*getPublicKey(t){yield ot(new Error("FIX ME: not implemented"))}async*getValue(t){try{for await(let e of this.dht.get(t))e.name==="VALUE"&&(yield ft({dht:{type:tt.Type.VALUE,value:e.value}}))}catch(e){Bn.error(e),yield ot(e)}}async*putValue(t,e){try{await vi(this.dht.put(t,e)),yield ft()}catch(n){Bn.error(n),yield ot(n)}}async*findPeer(t){try{for await(let e of this.dht.findPeer(t))e.name==="FINAL_PEER"&&(yield ft({dht:{type:tt.Type.VALUE,peer:{id:e.peer.id.toMultihash().bytes,addrs:e.peer.multiaddrs.map(n=>n.bytes)}}}));throw new Error("Peer not found")}catch(e){Bn.error(e),yield ot(e)}}async*findProviders(t,e){yield ft({dht:{type:tt.Type.BEGIN}});try{let n=e,o=0;for await(let i of this.dht.findProviders(t))if(i.name==="PEER_RESPONSE"){for(let s of i.providers)o++,yield tt.encode({type:tt.Type.VALUE,peer:{id:s.id.toMultihash().bytes,addrs:(s.multiaddrs??[]).map(c=>c.bytes)}});if(n===o)break}}catch(n){yield ot(n)}yield tt.encode({type:tt.Type.END})}};var Nn=ge("libp2p:daemon-server:pubsub"),Pn=class{pubsub;constructor(t){let{pubsub:e}=t;this.pubsub=e}async*getTopics(){try{yield ft({pubsub:{topics:this.pubsub.getTopics(),peerIDs:[]}})}catch(t){Nn.error(t),yield ot(t)}}async*subscribe(t){try{let e=Ze();this.pubsub.subscribe(t),this.pubsub.addEventListener("message",n=>{let o=n.detail;o.topic===t&&(o.type==="signed"?e.push(or.encode({from:o.from.toMultihash().bytes,data:o.data,seqno:o.sequenceNumber==null?void 0:Mt(o.sequenceNumber.toString(16).padStart(16,"0"),"base16"),topicIDs:[o.topic],signature:o.signature,key:_e(o.key)}).subarray()):e.push(or.encode({data:o.data,topicIDs:[o.topic]}).subarray()))}),yield ft(),yield*e}catch(e){Nn.error(e),yield ot(e)}}async*publish(t,e){try{await this.pubsub.publish(t,e),yield ft()}catch(n){Nn.error(n),yield ot(n)}}async*listPeers(t){try{yield ft({pubsub:{topics:[t],peerIDs:this.pubsub.getSubscribers(t).map(e=>e.toMultihash().bytes)}})}catch(e){Nn.error(e),yield ot(e)}}};var Ql=1<<22,it=ge("libp2p:daemon-server"),Cn=class{multiaddr;libp2p;tcp;listener;dhtOperations;pubsubOperations;constructor(t){let{multiaddr:e,libp2pNode:n}=t;this.multiaddr=e,this.libp2p=n,this.tcp=Sc()({logger:ss()}),this.listener=this.tcp.createListener({handler:this.handleConnection.bind(this),upgrader:So}),this._onExit=this._onExit.bind(this),n.services.dht!=null&&(this.dhtOperations=new kn({dht:n.services.dht})),n.services.pubsub!=null&&(this.pubsubOperations=new Pn({pubsub:n.services.pubsub}))}async connect(t){if(t.connect?.addrs==null)throw new Error("Invalid request");let e=t.connect.peer,n=t.connect.addrs.map(i=>lt(i)),o=ze(Ct(e));return it("connect - adding multiaddrs %a to peer %p",n,o),await this.libp2p.peerStore.merge(o,{multiaddrs:n}),it("connect - dial %p",o),this.libp2p.dial(o)}async openStream(t){if(t.streamOpen?.proto==null)throw new Error("Invalid request");let{peer:e,proto:n}=t.streamOpen,o=ze(Ct(e));it("openStream - dial %p",o);let i=await this.libp2p.dial(o);it("openStream - open stream for protocol %s",n);let s=await i.newStream(n,{runOnLimitedConnection:!0});return{streamInfo:{peer:o.toMultihash().bytes,addr:i.remoteAddr.bytes,proto:s.protocol??""},connection:s}}async registerStreamHandler(t){if(t.streamHandler?.proto==null)throw new Error("Invalid request");let e=t.streamHandler.proto,n=lt(t.streamHandler.addr),o;it("registerStreamHandler - handle %s",e),await this.libp2p.handle(e,({connection:i,stream:s})=>{Promise.resolve().then(async()=>{o=await this.tcp.dial(n,{upgrader:So});let c=De.encode({peer:i.remotePeer.toMultihash().bytes,addr:i.remoteAddr.bytes,proto:s.protocol??""}),a=bn.single(c);await Ei(async function*(){yield a,yield*s.source}(),async function*(l){for await(let f of l)yield*f},o,s.sink)}).catch(async c=>{it.error(c),o!=null&&await o.close(c)}).finally(()=>{o?.close().catch(c=>{it.error(c)})})},{runOnLimitedConnection:!0})}_listen(){process.on("SIGTERM",this._onExit),process.on("SIGINT",this._onExit),process.on("SIGHUP",this._onExit)}_onExit(){this.stop({exit:!0}).catch(t=>{it.error(t)})}async start(){this._listen(),await this.libp2p.start(),await this.listener.listen(this.multiaddr)}getMultiaddr(){let t=this.listener.getAddrs();if(t.length>0)return t[0];throw new Error("Not started")}async stop(t={exit:!1}){await this.libp2p.stop(),await this.listener.close(),t.exit&&it("server closed, exiting"),process.removeListener("SIGTERM",this._onExit),process.removeListener("SIGINT",this._onExit),process.removeListener("SIGHUP",this._onExit)}async*handlePeerStoreRequest(t){try{switch(t.type){case me.Type.GET_PROTOCOLS:if(t.id==null)throw new Error("Invalid request");let e=ze(Ct(t.id)),o=(await this.libp2p.peerStore.get(e)).protocols;yield ft({peerStore:{protos:o}});return;case me.Type.GET_PEER_INFO:throw new Error("ERR_NOT_IMPLEMENTED");default:throw new Error("ERR_INVALID_REQUEST_TYPE")}}catch(e){it.error(e),yield ot(e)}}async*handlePubsubRequest(t){try{if(this.libp2p.services.pubsub==null||this.pubsubOperations==null)throw new Error("PubSub not configured");switch(t.type){case Vt.Type.GET_TOPICS:yield*this.pubsubOperations.getTopics();return;case Vt.Type.SUBSCRIBE:if(t.topic==null)throw new Error("Invalid request");yield*this.pubsubOperations.subscribe(t.topic);return;case Vt.Type.PUBLISH:if(t.topic==null||t.data==null)throw new Error("Invalid request");yield*this.pubsubOperations.publish(t.topic,t.data);return;case Vt.Type.LIST_PEERS:if(t.topic==null)throw new Error("Invalid request");yield*this.pubsubOperations.listPeers(t.topic);return;default:throw new Error("ERR_INVALID_REQUEST_TYPE")}}catch(e){it.error(e),yield ot(e)}}async*handleDHTRequest(t){try{if(this.libp2p.services.dht==null||this.dhtOperations==null)throw new Error("DHT not configured");switch(t.type){case It.Type.FIND_PEER:if(t.peer==null)throw new Error("Invalid request");yield*this.dhtOperations.findPeer(ze(Ct(t.peer)));return;case It.Type.FIND_PROVIDERS:if(t.cid==null)throw new Error("Invalid request");yield*this.dhtOperations.findProviders(Q.decode(t.cid),t.count??20);return;case It.Type.PROVIDE:if(t.cid==null)throw new Error("Invalid request");yield*this.dhtOperations.provide(Q.decode(t.cid));return;case It.Type.GET_CLOSEST_PEERS:if(t.key==null)throw new Error("Invalid request");yield*this.dhtOperations.getClosestPeers(t.key);return;case It.Type.GET_PUBLIC_KEY:if(t.peer==null)throw new Error("Invalid request");yield*this.dhtOperations.getPublicKey(ze(Ct(t.peer)));return;case It.Type.GET_VALUE:if(t.key==null)throw new Error("Invalid request");yield*this.dhtOperations.getValue(t.key);return;case It.Type.PUT_VALUE:if(t.key==null||t.value==null)throw new Error("Invalid request");yield*this.dhtOperations.putValue(t.key,t.value);return;default:throw new Error("ERR_INVALID_REQUEST_TYPE")}}catch(e){it.error(e),yield ot(e)}}handleConnection(t){Promise.resolve().then(async()=>{let e=this,n=Cc(t,{maxDataLength:Ql}),o=await n.read(St);it("read",o);try{switch(o.type){case St.Type.CONNECT:{await e.connect(o),await n.write({type:q.Type.OK},q);break}case St.Type.IDENTIFY:{await n.write({type:q.Type.OK,identify:{id:e.libp2p.peerId.toMultihash().bytes,addrs:e.libp2p.getMultiaddrs().map(i=>i.decapsulateCode(O("p2p").code)).map(i=>i.bytes)}},q);break}case St.Type.LIST_PEERS:{let i=[],s=new Set;for(let c of e.libp2p.getConnections()){let a=c.remotePeer.toString();s.has(a)||(s.add(a),i.push({id:c.remotePeer.toMultihash().bytes,addrs:[c.remoteAddr.bytes]}))}await n.write({type:q.Type.OK,peers:i},q);break}case St.Type.STREAM_OPEN:{let i=await e.openStream(o);await n.write({type:q.Type.OK,streamInfo:i.streamInfo},q);let s=n.unwrap();await Ei(s,i.connection,s);break}case St.Type.STREAM_HANDLER:{await e.registerStreamHandler(o),await n.write({type:q.Type.OK},q);break}case St.Type.PEERSTORE:{if(o.peerStore==null)throw new Error("ERR_INVALID_REQUEST");let i=n.unwrap(),s=We(i);for await(let c of e.handlePeerStoreRequest(o.peerStore))await s.write(c);break}case St.Type.PUBSUB:{if(o.pubsub==null)throw new Error("ERR_INVALID_REQUEST");let i=n.unwrap(),s=We(i);for await(let c of e.handlePubsubRequest(o.pubsub))await s.write(c);break}case St.Type.DHT:{if(o.dht==null)throw new Error("ERR_INVALID_REQUEST");let i=n.unwrap(),s=We(i);for await(let c of e.handleDHTRequest(o.dht))await s.write(c);break}default:throw new Error("ERR_INVALID_REQUEST_TYPE")}}catch(i){it.error(i),await n.write({type:q.Type.ERROR,error:{msg:i.message},peers:[]},q)}finally{await n.unwrap().close()}}).catch(e=>{it.error("error handling incoming connection",e)})}},Jl=(r,t)=>new Cn({multiaddr:r,libp2pNode:t});return Mc(jl);})();
7
+ /*! Bundled license information:
8
+
9
+ @noble/hashes/esm/utils.js:
10
+ (*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
11
+
12
+ @noble/curves/esm/abstract/utils.js:
13
+ (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
14
+
15
+ @noble/curves/esm/abstract/modular.js:
16
+ (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
17
+
18
+ @noble/curves/esm/abstract/curve.js:
19
+ (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
20
+
21
+ @noble/curves/esm/abstract/weierstrass.js:
22
+ (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
23
+
24
+ @noble/curves/esm/_shortw_utils.js:
25
+ (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
26
+
27
+ @noble/curves/esm/secp256k1.js:
28
+ (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
29
+ */
7
30
  return Libp2PDaemonServer}));