@helia/trustless-gateway-client 1.0.0 → 1.0.1-688bd9de
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 +11 -11
- package/dist/index.min.js.map +3 -3
- package/package.json +3 -3
- package/dist/typedoc-urls.json +0 -18
package/dist/index.min.js
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
(function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.HeliaTrustlessGatewayClient = factory()}(typeof self !== 'undefined' ? self : this, function () {
|
|
2
|
-
"use strict";var HeliaTrustlessGatewayClient=(()=>{var No=Object.create;var et=Object.defineProperty;var Uo=Object.getOwnPropertyDescriptor;var $o=Object.getOwnPropertyNames;var Ro=Object.getPrototypeOf,zo=Object.prototype.hasOwnProperty;var Bt=(r,e)=>()=>{try{return e||r((e={exports:{}}).exports,e),e.exports}catch(t){throw e=0,t}},F=(r,e)=>{for(var t in e)et(r,t,{get:e[t],enumerable:!0})},hn=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of $o(e))!zo.call(r,o)&&o!==t&&et(r,o,{get:()=>e[o],enumerable:!(n=Uo(e,o))||n.enumerable});return r};var Bo=(r,e,t)=>(t=r!=null?No(Ro(r)):{},hn(e||!r||!r.__esModule?et(t,"default",{value:r,enumerable:!0}):t,r)),Mo=r=>hn(et({},"__esModule",{value:!0}),r);var vr=Bt(Pe=>{"use strict";Object.defineProperty(Pe,"__esModule",{value:!0});Pe.Netmask4Impl=void 0;Pe.ip2long=Ce;Pe.long2ip=J;function J(r){let e=(r&-16777216)>>>24,t=(r&255<<16)>>>16,n=(r&65280)>>>8,o=r&255;return[e,t,n,o].join(".")}var pi=48,mi=97,gi=65;function bi(r){let e=0,t=10,n="9",o=0;r.length>1&&r[o]==="0"&&(r[o+1]==="x"||r[o+1]==="X"?(o+=2,t=16):"0"<=r[o+1]&&r[o+1]<="9"&&(o++,t=8,n="7"));let s=o;for(;o<r.length;){if("0"<=r[o]&&r[o]<=n)e=e*t+(r.charCodeAt(o)-pi)>>>0;else if(t===16)if("a"<=r[o]&&r[o]<="f")e=e*t+(10+r.charCodeAt(o)-mi)>>>0;else if("A"<=r[o]&&r[o]<="F")e=e*t+(10+r.charCodeAt(o)-gi)>>>0;else break;else break;if(e>4294967295)throw new Error("too large");o++}if(o===s)throw new Error("empty octet");return[e,o]}function Ce(r){let e=[];for(let t=0;t<=3&&r.length!==0;t++){if(t>0){if(r[0]!==".")throw new Error("Invalid IP");r=r.substring(1)}let[n,o]=bi(r);r=r.substring(o),e.push(n)}if(r.length!==0)throw new Error("Invalid IP");switch(e.length){case 1:if(e[0]>4294967295)throw new Error("Invalid IP");return e[0]>>>0;case 2:if(e[0]>255||e[1]>16777215)throw new Error("Invalid IP");return(e[0]<<24|e[1])>>>0;case 3:if(e[0]>255||e[1]>255||e[2]>65535)throw new Error("Invalid IP");return(e[0]<<24|e[1]<<16|e[2])>>>0;case 4:if(e[0]>255||e[1]>255||e[2]>255||e[3]>255)throw new Error("Invalid IP");return(e[0]<<24|e[1]<<16|e[2]<<8|e[3])>>>0;default:throw new Error("Invalid IP")}}var Er=class r{constructor(e,t){if(typeof e!="string")throw new Error("Missing `net' parameter");let n=t;if(!n){let o=e.split("/",2);e=o[0],n=o[1]}if(n||(n=32),typeof n=="string"&&n.indexOf(".")>-1){try{this.maskLong=Ce(n)}catch{throw new Error("Invalid mask: "+n)}this.bitmask=NaN;for(let o=32;o>=0;o--)if(this.maskLong===4294967295<<32-o>>>0){this.bitmask=o;break}}else if(n||n===0)this.bitmask=parseInt(n,10),this.maskLong=0,this.bitmask>0&&(this.maskLong=4294967295<<32-this.bitmask>>>0);else throw new Error("Invalid mask: empty");try{this.netLong=(Ce(e)&this.maskLong)>>>0}catch{throw new Error("Invalid net address: "+e)}if(!(this.bitmask<=32))throw new Error("Invalid mask for ip4: "+n);this.size=Math.pow(2,32-this.bitmask),this.base=J(this.netLong),this.mask=J(this.maskLong),this.hostmask=J(~this.maskLong),this.first=this.bitmask<=30?J(this.netLong+1):this.base,this.last=this.bitmask<=30?J(this.netLong+this.size-2):J(this.netLong+this.size-1),this.broadcast=this.bitmask<=30?J(this.netLong+this.size-1):void 0}contains(e){return typeof e=="string"&&(e.indexOf("/")>0||e.split(".").length!==4)&&(e=new r(e)),e instanceof r?this.contains(e.base)&&this.contains(e.broadcast||e.last):(Ce(e)&this.maskLong)>>>0===(this.netLong&this.maskLong)>>>0}next(e=1){return new r(J(this.netLong+this.size*e),this.mask)}forEach(e){let t=Ce(this.first),n=Ce(this.last),o=0;for(;t<=n;)e(J(t),t,o),o++,t++}toString(){return this.base+"/"+this.bitmask}};Pe.Netmask4Impl=Er});var qn=Bt(Ae=>{"use strict";Object.defineProperty(Ae,"__esModule",{value:!0});Ae.Netmask6Impl=void 0;Ae.ip6bigint=Ir;Ae.bigint2ip6=me;var wi=vr(),_r=(1n<<128n)-1n;function Ir(r){let e=r.indexOf("%");e!==-1&&(r=r.substring(0,e));let t=r.lastIndexOf(":");if(t!==-1&&r.indexOf(".",t)!==-1){let n=r.substring(t+1),o=(0,wi.ip2long)(n),s=r.substring(0,t+1)+"0:0";return Vn(s)&~0xffffffffn|BigInt(o)}return Vn(r)}function Vn(r){let e=r.indexOf("::"),t;if(e!==-1){let o=r.substring(0,e),s=r.substring(e+2),i=o===""?[]:o.split(":"),a=s===""?[]:s.split(":"),c=8-i.length-a.length;if(c<0)throw new Error("Invalid IPv6: too many groups");t=[...i,...Array(c).fill("0"),...a]}else t=r.split(":");if(t.length!==8)throw new Error("Invalid IPv6: expected 8 groups, got "+t.length);let n=0n;for(let o=0;o<8;o++){let s=t[o];if(s.length===0||s.length>4)throw new Error('Invalid IPv6: bad group "'+s+'"');let i=parseInt(s,16);if(isNaN(i)||i<0||i>65535)throw new Error('Invalid IPv6: bad group "'+s+'"');n=n<<16n|BigInt(i)}return n}function me(r){if(r<0n||r>_r)throw new Error("Invalid IPv6 address value");let e=[];for(let i=0;i<8;i++)e.unshift(Number(r&0xffffn)),r>>=16n;let t=-1,n=0,o=-1,s=0;for(let i=0;i<8;i++)e[i]===0?o===-1?(o=i,s=1):s++:(s>n&&s>=2&&(t=o,n=s),o=-1,s=0);if(s>n&&s>=2&&(t=o,n=s),t!==-1&&t+n===8&&t>0)return e.slice(0,t).map(a=>a.toString(16)).join(":")+"::";if(t===0)return"::"+e.slice(n).map(a=>a.toString(16)).join(":");if(t>0){let i=e.slice(0,t).map(c=>c.toString(16)),a=e.slice(t+n).map(c=>c.toString(16));return i.join(":")+"::"+a.join(":")}else return e.map(i=>i.toString(16)).join(":")}var Sr=class r{constructor(e,t){if(typeof e!="string")throw new Error("Missing `net' parameter");let n=t;if(n==null){let o=e.indexOf("/");o!==-1?(n=parseInt(e.substring(o+1),10),e=e.substring(0,o)):n=128}if(isNaN(n)||n<0||n>128)throw new Error("Invalid mask for IPv6: "+n);this.bitmask=n,this.bitmask===0?this.maskBigint=0n:this.maskBigint=_r>>BigInt(128-this.bitmask)<<BigInt(128-this.bitmask);try{this.netBigint=Ir(e)&this.maskBigint}catch{throw new Error("Invalid IPv6 net address: "+e)}this.size=Number(1n<<BigInt(128-this.bitmask)),this.base=me(this.netBigint),this.mask=me(this.maskBigint),this.hostmask=me(~this.maskBigint&_r),this.first=this.base,this.last=me(this.netBigint+(1n<<BigInt(128-this.bitmask))-1n),this.broadcast=void 0}contains(e){return typeof e=="string"&&e.indexOf("/")>0&&(e=new r(e)),e instanceof r?this.contains(e.base)&&this.contains(e.last):(Ir(e)&this.maskBigint)===this.netBigint}next(e=1){let t=1n<<BigInt(128-this.bitmask);return new r(me(this.netBigint+t*BigInt(e)),this.bitmask)}forEach(e){let t=this.netBigint,n=1n<<BigInt(128-this.bitmask),o=this.netBigint+n-1n,s=0;for(;t<=o;)e(me(t),Number(t),s),s++,t++}toString(){return this.base+"/"+this.bitmask}};Ae.Netmask6Impl=Sr});var jn=Bt(ae=>{"use strict";Object.defineProperty(ae,"__esModule",{value:!0});ae.long2ip=ae.ip2long=ae.Netmask=void 0;var dt=vr();Object.defineProperty(ae,"ip2long",{enumerable:!0,get:function(){return dt.ip2long}});Object.defineProperty(ae,"long2ip",{enumerable:!0,get:function(){return dt.long2ip}});var xi=qn(),Cr=class r{constructor(e,t){if(typeof e!="string")throw new Error("Missing `net' parameter");(e.indexOf("/")!==-1?e.substring(0,e.indexOf("/")):e).indexOf(":")!==-1?this._impl=new xi.Netmask6Impl(e,t):this._impl=new dt.Netmask4Impl(e,t),this.base=this._impl.base,this.mask=this._impl.mask,this.hostmask=this._impl.hostmask,this.bitmask=this._impl.bitmask,this.size=this._impl.size,this.first=this._impl.first,this.last=this._impl.last,this.broadcast=this._impl.broadcast,this._impl instanceof dt.Netmask4Impl?(this.maskLong=this._impl.maskLong,this.netLong=this._impl.netLong):(this.maskLong=0,this.netLong=0)}contains(e){return typeof e=="string"&&(e.indexOf("/")>0?e=new r(e):e.indexOf(":")===-1&&e.split(".").length!==4&&(e=new r(e))),e instanceof r?this.contains(e.base)&&this.contains(e.broadcast||e.last):this._impl.contains(e)}next(e=1){let t=this._impl.next(e);return new r(t.base,t.bitmask)}forEach(e){this._impl.forEach(e)}toString(){return this._impl.toString()}};ae.Netmask=Cr});var Aa={};F(Aa,{DEFAULT_ALLOW_INSECURE:()=>Je,DEFAULT_ALLOW_LOCAL:()=>Ye,DEFAULT_MAX_SIZE:()=>ln,trustlessGatewayBlockBroker:()=>Pa});var Ta=new Uint8Array(0);function dn(r,e){if(r===e)return!0;if(r.byteLength!==e.byteLength)return!1;for(let t=0;t<r.byteLength;t++)if(r[t]!==e[t])return!1;return!0}function Z(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return fe(r);if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return fe(new Uint8Array(r.buffer,r.byteOffset,r.byteLength));throw new Error("Unknown type, must be binary type")}function pn(r){return new TextEncoder().encode(r)}function mn(r){return new TextDecoder().decode(r)}function Vo(r){return r?.buffer instanceof ArrayBuffer}function fe(r){return Vo(r)?r:r.slice()}var Wt={};F(Wt,{base32:()=>ie,base32hex:()=>Yo,base32hexpad:()=>es,base32hexpadupper:()=>ts,base32hexupper:()=>Zo,base32pad:()=>Ko,base32padupper:()=>Jo,base32upper:()=>Xo,base32z:()=>rs});function qo(r,e,t){if(r.length>=255)throw new TypeError("Alphabet too long");for(var n=new Uint8Array(256),o=0;o<n.length;o++)n[o]=255;for(var s=0;s<r.length;s++){var i=r.charAt(s),a=i.charCodeAt(0);if(n[a]!==255)throw new TypeError(i+" is ambiguous");if(n[a]=s,t){var c=i.toLowerCase().charCodeAt(0),l=i.toUpperCase().charCodeAt(0);c!==a&&(n[c]=s),l!==a&&(n[l]=s)}}var h=r.length,d=r.charAt(0),u=Math.log(h)/Math.log(256),p=Math.log(256)/Math.log(h);function L(g){if(g instanceof Uint8Array||(ArrayBuffer.isView(g)?g=new Uint8Array(g.buffer,g.byteOffset,g.byteLength):Array.isArray(g)&&(g=Uint8Array.from(g))),!(g instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(g.length===0)return"";for(var S=0,k=0,N=0,U=g.length;N!==U&&g[N]===0;)N++,S++;for(var H=(U-N)*p+1>>>0,$=new Uint8Array(H);N!==U;){for(var G=g[N],oe=0,z=H-1;(G!==0||oe<k)&&z!==-1;z--,oe++)G+=256*$[z]>>>0,$[z]=G%h>>>0,G=G/h>>>0;if(G!==0)throw new Error("Non-zero carry");k=oe,N++}for(var Y=H-k;Y!==H&&$[Y]===0;)Y++;for(var Ze=d.repeat(S);Y<H;++Y)Ze+=r.charAt($[Y]);return Ze}function O(g){if(typeof g!="string")throw new TypeError("Expected String");if(g.length===0)return new Uint8Array;var S=0;if(g[S]!==" "){for(var k=0,N=0;g[S]===d;)k++,S++;for(var U=(g.length-S)*u+1>>>0,H=new Uint8Array(U);g[S];){var $=n[g.charCodeAt(S)];if($===255)return;for(var G=0,oe=U-1;($!==0||G<N)&&oe!==-1;oe--,G++)$+=h*H[oe]>>>0,H[oe]=$%256>>>0,$=$/256>>>0;if($!==0)throw new Error("Non-zero carry");N=G,S++}if(g[S]!==" "){for(var z=U-N;z!==U&&H[z]===0;)z++;for(var Y=new Uint8Array(k+(U-z)),Ze=k;z!==U;)Y[Ze++]=H[z++];return Y}}}function x(g){var S=O(g);if(S)return S;throw new Error(`Non-${e} character`)}return{encode:L,decodeUnsafe:O,decode:x}}var jo=qo,Wo=jo,bn=Wo;var Mt=class{name;prefix;baseEncode;constructor(e,t,n){this.name=e,this.prefix=t,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},Vt=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,t,n){this.name=e,this.prefix=t;let o=t.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(e){if(typeof e=="string"){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(e){return wn(this,e)}},qt=class{decoders;constructor(e){this.decoders=e}or(e){return wn(this,e)}decode(e){let t=e[0],n=this.decoders[t];if(n!=null)return n.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function wn(r,e){return new qt({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}var jt=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,t,n,o){this.name=e,this.prefix=t,this.baseEncode=n,this.baseDecode=o,this.encoder=new Mt(e,t,n),this.decoder=new Vt(e,t,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function we({name:r,prefix:e,encode:t,decode:n}){return new jt(r,e,t,n)}function se({name:r,prefix:e,alphabet:t,caseInsensitive:n=!1}){let{encode:o,decode:s}=bn(t,r,n);return we({prefix:e,name:r,encode:o,decode:i=>Z(s(i))})}function Ho(r,e,t,n){let o=r.length;for(;r[o-1]==="=";)--o;let s=new Uint8Array(o*t/8|0),i=0,a=0,c=0;for(let l=0;l<o;++l){let h=e[r[l]];if(h===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<t|h,i+=t,i>=8&&(i-=8,s[c++]=255&a>>i)}if(i>=t||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function Go(r,e,t){let n=e[e.length-1]==="=",o=(1<<t)-1,s="",i=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],i+=8;i>t;)i-=t,s+=e[o&a>>i];if(i!==0&&(s+=e[o&a<<t-i]),n)for(;(s.length*t&7)!==0;)s+="=";return s}function Qo(r,e){let t={};for(let n=0;n<r.length;++n)if(t[r[n]]=n,e){let o=r[n].toLowerCase(),s=r[n].toUpperCase();o!==r[n]&&(t[o]=n),s!==r[n]&&(t[s]=n)}return t}function _({name:r,prefix:e,bitsPerChar:t,alphabet:n,caseInsensitive:o=!1}){let s=Qo(n,o);return we({prefix:e,name:r,encode(i){return Go(i,n,t)},decode(i){return Ho(i,s,t,r)}})}var ie=_({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5,caseInsensitive:!0}),Xo=_({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5,caseInsensitive:!0}),Ko=_({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5,caseInsensitive:!0}),Jo=_({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5,caseInsensitive:!0}),Yo=_({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5,caseInsensitive:!0}),Zo=_({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5,caseInsensitive:!0}),es=_({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5,caseInsensitive:!0}),ts=_({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5,caseInsensitive:!0}),rs=_({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Ht={};F(Ht,{base36:()=>Ne,base36upper:()=>ns});var Ne=se({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz",caseInsensitive:!0}),ns=se({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",caseInsensitive:!0});var Gt={};F(Gt,{base58btc:()=>Q,base58flickr:()=>os});var Q=se({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),os=se({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var ss=En,xn=128,is=127,as=~is,cs=Math.pow(2,31);function En(r,e,t){e=e||[],t=t||0;for(var n=t;r>=cs;)e[t++]=r&255|xn,r/=128;for(;r&as;)e[t++]=r&255|xn,r>>>=7;return e[t]=r|0,En.bytes=t-n+1,e}var us=Qt,ls=128,yn=127;function Qt(r,n){var t=0,n=n||0,o=0,s=n,i,a=r.length;do{if(s>=a)throw Qt.bytes=0,new RangeError("Could not decode varint");i=r[s++],t+=o<28?(i&yn)<<o:(i&yn)*Math.pow(2,o),o+=7}while(i>=ls);return Qt.bytes=s-n,t}var fs=Math.pow(2,7),hs=Math.pow(2,14),ds=Math.pow(2,21),ps=Math.pow(2,28),ms=Math.pow(2,35),gs=Math.pow(2,42),bs=Math.pow(2,49),ws=Math.pow(2,56),xs=Math.pow(2,63),ys=function(r){return r<fs?1:r<hs?2:r<ds?3:r<ps?4:r<ms?5:r<gs?6:r<bs?7:r<ws?8:r<xs?9:10},Es={encode:ss,decode:us,encodingLength:ys},vs=Es,Ue=vs;function $e(r,e=0){return[Ue.decode(r,e),Ue.decode.bytes]}function xe(r,e,t=0){return Ue.encode(r,e,t),e}function ye(r){return Ue.encodingLength(r)}function ve(r,e){let t=e.byteLength,n=ye(r),o=n+ye(t),s=new Uint8Array(o+t);return xe(r,s,0),xe(t,s,n),s.set(e,o),new Ee(r,t,e,s)}function vn(r){let e=Z(r),[t,n]=$e(e),[o,s]=$e(e.subarray(n)),i=e.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new Ee(t,o,i,e)}function _n(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&dn(r.bytes,t.bytes)}}var Ee=class{code;size;digest;bytes;constructor(e,t,n,o){this.code=e,this.size=t,this.digest=fe(n),this.bytes=fe(o)}};function In(r,e){let{bytes:t,version:n}=r;return n===0?Is(t,Xt(r),e??Q.encoder):Ss(t,Xt(r),e??ie.encoder)}var Sn=new WeakMap;function Xt(r){let e=Sn.get(r);if(e==null){let t=new Map;return Sn.set(r,t),t}return e}var X=class r{code;version;multihash;bytes;"/";constructor(e,t,n,o){this.code=t,this.version=e,this.multihash=n,this.bytes=fe(o),this["/"]=this.bytes}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:e,multihash:t}=this;if(e!==ze)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==Cs)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(t)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:e,digest:t}=this.multihash,n=ve(e,t);return r.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(e){return r.equals(this,e)}static equals(e,t){let n=t;return n!=null&&e.code===n.code&&e.version===n.version&&_n(e.multihash,n.multihash)}toString(e){return In(this,e)}toJSON(){return{"/":In(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(e){if(e==null)return null;let t=e;if(t instanceof r)return t;if(t["/"]!=null&&t["/"]===t.bytes||t.asCID===t){let{version:n,code:o,multihash:s,bytes:i}=t;return new r(n,o,s,i??Cn(n,o,s.bytes))}else if(t[Ps]===!0){let{version:n,multihash:o,code:s}=t,i=vn(o);return r.create(n,s,i)}else return null}static create(e,t,n){if(typeof t!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(e){case 0:{if(t!==ze)throw new Error(`Version 0 CID must use dag-pb (code: ${ze}) block encoding`);return new r(e,t,n,n.bytes)}case 1:{let o=Cn(e,t,n.bytes);return new r(e,t,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return r.create(0,ze,e)}static createV1(e,t){return r.create(1,e,t)}static decode(e){let[t,n]=r.decodeFirst(e);if(n.length!==0)throw new Error("Incorrect length");return t}static decodeFirst(e){let t=r.inspectBytes(e),n=t.size-t.multihashSize,o=Z(e.subarray(n,n+t.multihashSize));if(o.byteLength!==t.multihashSize)throw new Error("Incorrect length");let s=o.subarray(t.multihashSize-t.digestSize),i=new Ee(t.multihashCode,t.digestSize,s,o);return[t.version===0?r.createV0(i):r.createV1(t.codec,i),e.subarray(t.size)]}static inspectBytes(e){let t=0,n=()=>{let[d,u]=$e(e.subarray(t));return t+=u,d},o=n(),s=ze;if(o===18?(o=0,t=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=t,a=n(),c=n(),l=t+c,h=l-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:h,size:l}}static parse(e,t){let[n,o]=_s(e,t),s=r.decode(o);if(s.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Xt(s).set(n,e),s}};function _s(r,e){switch(r[0]){case"Q":{let t=e??Q;return[Q.prefix,t.decode(`${Q.prefix}${r}`)]}case Q.prefix:{let t=e??Q;return[Q.prefix,t.decode(r)]}case ie.prefix:{let t=e??ie;return[ie.prefix,t.decode(r)]}case Ne.prefix:{let t=e??Ne;return[Ne.prefix,t.decode(r)]}default:{if(e==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[r[0],e.decode(r)]}}}function Is(r,e,t){let{prefix:n}=t;if(n!==Q.prefix)throw Error(`Cannot string encode V0 in ${t.name} encoding`);let o=e.get(n);if(o==null){let s=t.encode(r).slice(1);return e.set(n,s),s}else return o}function Ss(r,e,t){let{prefix:n}=t,o=e.get(n);if(o==null){let s=t.encode(r);return e.set(n,s),s}else return o}var ze=112,Cs=18;function Cn(r,e,t){let n=ye(r),o=n+ye(e),s=new Uint8Array(o+t.byteLength);return xe(r,s,0),xe(e,s,n),s.set(t,o),s}var Ps=Symbol.for("@ipld/js-cid/CID");var As=20;function Jt({name:r,code:e,encode:t,minDigestLength:n,maxDigestLength:o}){return new Kt(r,e,t,n,o)}var Kt=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,t,n,o,s){this.name=e,this.code=t,this.encode=n,this.minDigestLength=o??As,this.maxDigestLength=s}digest(e,t){if(t?.truncate!=null){if(t.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&t.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(e instanceof Uint8Array){let n=this.encode(e);return n instanceof Uint8Array?Pn(n,this.code,t?.truncate):n.then(o=>Pn(o,this.code,t?.truncate))}else throw Error("Unknown type, must be binary type")}};function Pn(r,e,t){if(t!=null&&t!==r.byteLength){if(t>r.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${r.byteLength}`);r=r.subarray(0,t)}return ve(e,r)}var Zt={};F(Zt,{base64:()=>Be,base64pad:()=>Ds,base64url:()=>Yt,base64urlpad:()=>Ts});var Be=_({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Ds=_({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Yt=_({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Ts=_({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var tr={};F(tr,{identity:()=>er});var Dn=0,Ls="identity",Tn=Z;function ks(r,e){if(e?.truncate!=null&&e.truncate!==r.byteLength){if(e.truncate<0||e.truncate>r.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${r.byteLength}`);r=r.subarray(0,e.truncate)}return ve(Dn,Tn(r))}var er={code:Dn,name:Ls,encode:Tn,digest:ks};function R(r=0){return new Uint8Array(r)}function K(r=0){return new Uint8Array(r)}function Os(r){return r?.buffer instanceof ArrayBuffer}function rr(r){if(Os(r))return r;let e=r.slice();return new Uint8Array(e.buffer,0,e.byteLength)}function ee(r,e){e==null&&(e=r.reduce((o,s)=>o+s.length,0));let t=K(e),n=0;for(let o of r)t.set(o,n),n+=o.length;return rr(t)}function he(r,e){if(r===e)return!0;if(r.byteLength!==e.byteLength)return!1;for(let t=0;t<r.byteLength;t++)if(r[t]!==e[t])return!1;return!0}var kn=Symbol.for("@achingbrain/uint8arraylist");function Ln(r,e){if(e==null||e<0)throw new RangeError("index is out of bounds");let t=0;for(let n of r){let o=t+n.byteLength;if(e<o)return{buf:n,index:e-t};t=o}throw new RangeError("index is out of bounds")}function rt(r){return!!r?.[kn]}var nt=class r{bufs;length;[kn]=!0;constructor(...e){this.bufs=[],this.length=0,e.length>0&&this.appendAll(e)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...e){this.appendAll(e)}appendAll(e){let t=0;for(let n of e)if(n instanceof Uint8Array)t+=n.byteLength,this.bufs.push(n);else if(rt(n)){t+=n.byteLength;for(let o of n.bufs)this.bufs.push(o)}else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=t}prepend(...e){this.prependAll(e)}prependAll(e){let t=0;for(let n of e.reverse())if(n instanceof Uint8Array)t+=n.byteLength,this.bufs.unshift(n);else if(rt(n))t+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=t}get(e){let t=Ln(this.bufs,e);return t.buf[t.index]}set(e,t){let n=Ln(this.bufs,e);n.buf[n.index]=t}write(e,t=0){if(e instanceof Uint8Array)for(let n=0;n<e.length;n++)this.set(t+n,e[n]);else if(rt(e))for(let n=0;n<e.length;n++)this.set(t+n,e.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(e){if(e=Math.trunc(e),!(Number.isNaN(e)||e<=0)){if(e===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(e>=this.bufs[0].byteLength)e-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(e),this.length-=e;break}}}slice(e,t){let{bufs:n,length:o}=this._subList(e,t);return ee(n,o)}subarray(e,t){let{bufs:n,length:o}=this._subList(e,t);return n.length===1?n[0]:ee(n,o)}sublist(e,t){let{bufs:n,length:o}=this._subList(e,t),s=new r;return s.length=o,s.bufs=n,s}_subList(e,t){if(e=e??0,t=t??this.length,e<0&&(e=this.length+e),t<0&&(t=this.length+t),e<0||t>this.length)throw new RangeError("index is out of bounds");if(e===t)return{bufs:[],length:0};if(e===0&&t===this.length)return{bufs:[...this.bufs],length:this.length};let n=[],o=0;for(let s=0;s<this.bufs.length;s++){let i=this.bufs[s],a=o,c=a+i.byteLength;if(o=c,e>=c)continue;let l=e>=a&&e<c,h=t>a&&t<=c;if(l&&h){if(e===a&&t===c){n.push(i);break}let d=e-a;n.push(i.subarray(d,d+(t-e)));break}if(l){if(e===0){n.push(i);continue}n.push(i.subarray(e-a));continue}if(h){if(t===c){n.push(i);break}n.push(i.subarray(0,t-a));break}n.push(i)}return{bufs:n,length:t-e}}indexOf(e,t=0){if(!rt(e)&&!(e instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=e instanceof Uint8Array?e:e.subarray();if(t=Number(t??0),isNaN(t)&&(t=0),t<0&&(t=this.length+t),t<0&&(t=0),e.length===0)return t>this.length?this.length:t;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let s=256,i=new Int32Array(s);for(let d=0;d<s;d++)i[d]=-1;for(let d=0;d<o;d++)i[n[d]]=d;let a=i,c=this.byteLength-n.byteLength,l=n.byteLength-1,h;for(let d=t;d<=c;d+=h){h=0;for(let u=l;u>=0;u--){let p=this.get(d+u);if(n[u]!==p){h=Math.max(1,u-a[p]);break}}if(h===0)return d}return-1}getInt8(e){let t=this.subarray(e,e+1);return new DataView(t.buffer,t.byteOffset,t.byteLength).getInt8(0)}setInt8(e,t){let n=K(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,t),this.write(n,e)}getInt16(e,t){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,t)}setInt16(e,t,n){let o=R(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,t,n),this.write(o,e)}getInt32(e,t){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,t)}setInt32(e,t,n){let o=R(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,t,n),this.write(o,e)}getBigInt64(e,t){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,t)}setBigInt64(e,t,n){let o=R(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,t,n),this.write(o,e)}getUint8(e){let t=this.subarray(e,e+1);return new DataView(t.buffer,t.byteOffset,t.byteLength).getUint8(0)}setUint8(e,t){let n=K(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,t),this.write(n,e)}getUint16(e,t){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,t)}setUint16(e,t,n){let o=R(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,t,n),this.write(o,e)}getUint32(e,t){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,t)}setUint32(e,t,n){let o=R(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,t,n),this.write(o,e)}getBigUint64(e,t){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,t)}setBigUint64(e,t,n){let o=R(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,t,n),this.write(o,e)}getFloat32(e,t){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,t)}setFloat32(e,t,n){let o=R(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,t,n),this.write(o,e)}getFloat64(e,t){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,t)}setFloat64(e,t,n){let o=R(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,t,n),this.write(o,e)}equals(e){if(e==null||!(e instanceof r)||e.bufs.length!==this.bufs.length)return!1;for(let t=0;t<this.bufs.length;t++)if(!he(this.bufs[t],e.bufs[t]))return!1;return!0}static fromUint8Arrays(e,t){let n=new r;return n.bufs=e,t==null&&(t=e.reduce((o,s)=>o+s.byteLength,0)),n.length=t,n}};function Fs(r){return r.buffer instanceof ArrayBuffer}function nr(r){return Fs(r)?r:r.slice()}var Ns=Math.pow(2,7),Us=Math.pow(2,14),$s=Math.pow(2,21),or=Math.pow(2,28),sr=Math.pow(2,35),ir=Math.pow(2,42),ar=Math.pow(2,49),v=128,D=127;function _e(r){if(r<Ns)return 1;if(r<Us)return 2;if(r<$s)return 3;if(r<or)return 4;if(r<sr)return 5;if(r<ir)return 6;if(r<ar)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function cr(r,e,t=0){switch(_e(r)){case 8:e[t++]=r&255|v,r/=128;case 7:e[t++]=r&255|v,r/=128;case 6:e[t++]=r&255|v,r/=128;case 5:e[t++]=r&255|v,r/=128;case 4:e[t++]=r&255|v,r>>>=7;case 3:e[t++]=r&255|v,r>>>=7;case 2:e[t++]=r&255|v,r>>>=7;case 1:{e[t++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return e}function Rs(r,e){let t=r[e],n=0;if(n+=t&D,t<v||(t=r[e+1],n+=(t&D)<<7,t<v)||(t=r[e+2],n+=(t&D)<<14,t<v)||(t=r[e+3],n+=(t&D)<<21,t<v)||(t=r[e+4],n+=(t&D)*or,t<v)||(t=r[e+5],n+=(t&D)*sr,t<v)||(t=r[e+6],n+=(t&D)*ir,t<v)||(t=r[e+7],n+=(t&D)*ar,t<v))return n;throw new RangeError("Could not decode varint")}function zs(r,e){let t=r.get(e),n=0;if(n+=t&D,t<v||(t=r.get(e+1),n+=(t&D)<<7,t<v)||(t=r.get(e+2),n+=(t&D)<<14,t<v)||(t=r.get(e+3),n+=(t&D)<<21,t<v)||(t=r.get(e+4),n+=(t&D)*or,t<v)||(t=r.get(e+5),n+=(t&D)*sr,t<v)||(t=r.get(e+6),n+=(t&D)*ir,t<v)||(t=r.get(e+7),n+=(t&D)*ar,t<v))return n;throw new RangeError("Could not decode varint")}function ur(r,e=0){return r instanceof Uint8Array?Rs(r,e):zs(r,e)}var lr={};F(lr,{base10:()=>Ms});var Ms=se({prefix:"9",name:"base10",alphabet:"0123456789"});var fr={};F(fr,{base16:()=>Vs,base16upper:()=>qs});var Vs=_({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4,caseInsensitive:!0}),qs=_({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4,caseInsensitive:!0});var hr={};F(hr,{base2:()=>js});var js=_({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var dr={};F(dr,{base256emoji:()=>Xs});var On=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}"),Ws=On.reduce((r,e,t)=>(r[t]=e,r),[]),Hs=On.reduce((r,e,t)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return r[n]=t,r},[]);function Gs(r){return r.reduce((e,t)=>(e+=Ws[t],e),"")}function Qs(r){let e=[];for(let t of r){let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);let o=Hs[n];if(o==null)throw new Error(`Non-base256emoji character: ${t}`);e.push(o)}return new Uint8Array(e)}var Xs=we({prefix:"\u{1F680}",name:"base256emoji",encode:Gs,decode:Qs});var pr={};F(pr,{base8:()=>Ks});var Ks=_({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var mr={};F(mr,{identity:()=>Js});var Js=we({prefix:"\0",name:"identity",encode:r=>mn(r),decode:r=>pn(r)});var vc=new TextEncoder,_c=new TextDecoder;var gr={};F(gr,{sha256:()=>ei,sha512:()=>ti});function Fn(r){return async e=>new Uint8Array(await crypto.subtle.digest(r,e))}var ei=Jt({name:"sha2-256",code:18,encode:Fn("SHA-256")}),ti=Jt({name:"sha2-512",code:19,encode:Fn("SHA-512")});var Me={...mr,...hr,...pr,...lr,...fr,...Wt,...Ht,...Gt,...Zt,...dr},Pc={...gr,...tr};function Un(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}var Nn=Un("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),br=Un("ascii","a",r=>{let e="a";for(let t=0;t<r.length;t++)e+=String.fromCharCode(r[t]);return e},r=>{r=r.substring(1);let e=K(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),ri={utf8:Nn,"utf-8":Nn,hex:Me.base16,latin1:br,ascii:br,binary:br,...Me},ot=ri;function C(r,e="utf8"){let t=ot[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.decoder.decode(`${t.prefix}${r}`)}var st=class extends Error{static name="InsufficientProvidersError";constructor(e="Insufficient providers found"){super(e),this.name="InsufficientProvidersError"}};var B=class extends Error{static name="AbortError";constructor(e="The operation was aborted"){super(e),this.name="AbortError"}};var it=class extends Error{static name="InvalidParametersError";constructor(e="Invalid parameters"){super(e),this.name="InvalidParametersError"}};function ni(r){return typeof r?.handleEvent=="function"}function oi(r){return(r!==!0&&r!==!1&&r?.once)??!1}var Ie=class extends EventTarget{#e=new Map;constructor(){super()}listenerCount(e){let t=this.#e.get(e);return t==null?0:t.length}addEventListener(e,t,n){let o=oi(n);super.addEventListener(e,i=>{if(o){let a=this.#e.get(i.type);a!=null&&(a=a.filter(({callback:c})=>c!==t),this.#e.set(i.type,a))}ni(t)?t.handleEvent(i):t(i)},n);let s=this.#e.get(e);s==null&&(s=[],this.#e.set(e,s)),s.push({callback:t,once:o})}removeEventListener(e,t,n){super.removeEventListener(e.toString(),t??null,n);let o=this.#e.get(e);o!=null&&(o=o.filter(({callback:s})=>s!==t),this.#e.set(e,o))}safeDispatchEvent(e,t={}){return this.dispatchEvent(new CustomEvent(e,t))}};var wr={32:16777619n,64:1099511628211n,128:309485009821345068724781371n,256:374144419156711147060143317175368453031918731002211n,512:35835915874844867368919076489095108449946327955754392558399825615420669938882575126094039892345713852759n,1024:5016456510113118655434598811035278955030765345404790744303017523831112055108147451509157692220295382716162651878526895249385292291816524375083746691371804094271873160484737966720260389217684476157468082573n},$n={32:2166136261n,64:14695981039346656037n,128:144066263297769815596495629667062367629n,256:100029257958052580907070968620625704837092796014241193945225284501741471925557n,512:9659303129496669498009435400716310466090418745672637896108374329434462657994582932197716438449813051892206539805784495328239340083876191928701583869517785n,1024:14197795064947621068722070641403218320880622795441933960878474914617582723252296732303717722150864096521202355549365628174669108571814760471015076148029755969804077320157692458563003215304957150157403644460363550505412711285966361610267868082893823963790439336411086884584107735010676915n},Rn=new globalThis.TextEncoder;function si(r,e){let t=wr[e],n=$n[e];for(let o=0;o<r.length;o++)n^=BigInt(r[o]),n=BigInt.asUintN(e,n*t);return n}function ii(r,e,t){if(t.length===0)throw new Error("The `utf8Buffer` option must have a length greater than zero");let n=wr[e],o=$n[e],s=r;for(;s.length>0;){let i=Rn.encodeInto(s,t);s=s.slice(i.read);for(let a=0;a<i.written;a++)o^=BigInt(t[a]),o=BigInt.asUintN(e,o*n)}return o}function xr(r,{size:e=32,utf8Buffer:t}={}){if(!wr[e])throw new Error("The `size` option must be one of 32, 64, 128, 256, 512, or 1024");if(typeof r=="string"){if(t)return ii(r,e,t);r=Rn.encode(r)}return si(r,e)}var Ve={hash:r=>Number(xr(r,{size:32})),hashV:(r,e)=>ai(Ve.hash(r,e))};function ai(r){let e=r.toString(16);return e.length%2===1&&(e=`0${e}`),C(e,"base16")}var yr=64,M=class{fp;h;seed;constructor(e,t,n,o=2){if(o>yr)throw new TypeError("Invalid Fingerprint Size");let s=t.hashV(e,n),i=R(o);for(let a=0;a<i.length;a++)i[a]=s[a];i.length===0&&(i[0]=7),this.fp=i,this.h=t,this.seed=n}hash(){return this.h.hash(this.fp,this.seed)}equals(e){return e?.fp instanceof Uint8Array?he(this.fp,e.fp):!1}};function de(r,e){return Math.floor(Math.random()*(e-r))+r}var pe=class{contents;constructor(e){this.contents=new Array(e).fill(null)}has(e){if(!(e instanceof M))throw new TypeError("Invalid Fingerprint");return this.contents.some(t=>e.equals(t))}add(e){if(!(e instanceof M))throw new TypeError("Invalid Fingerprint");for(let t=0;t<this.contents.length;t++)if(this.contents[t]==null)return this.contents[t]=e,!0;return!0}swap(e){if(!(e instanceof M))throw new TypeError("Invalid Fingerprint");let t=de(0,this.contents.length-1),n=this.contents[t];return this.contents[t]=e,n}remove(e){if(!(e instanceof M))throw new TypeError("Invalid Fingerprint");let t=this.contents.findIndex(n=>e.equals(n));return t>-1?(this.contents[t]=null,!0):!1}};var ci=500,qe=class{bucketSize;filterSize;fingerprintSize;buckets;count;hash;seed;constructor(e){this.filterSize=e.filterSize,this.bucketSize=e.bucketSize??4,this.fingerprintSize=e.fingerprintSize??2,this.count=0,this.buckets=[],this.hash=e.hash??Ve,this.seed=e.seed??de(0,Math.pow(2,10))}add(e){typeof e=="string"&&(e=C(e));let t=new M(e,this.hash,this.seed,this.fingerprintSize),n=this.hash.hash(e,this.seed)%this.filterSize,o=(n^t.hash())%this.filterSize;if(this.buckets[n]==null&&(this.buckets[n]=new pe(this.bucketSize)),this.buckets[o]==null&&(this.buckets[o]=new pe(this.bucketSize)),this.buckets[n].add(t)||this.buckets[o].add(t))return this.count++,!0;let s=[n,o],i=s[de(0,s.length-1)];this.buckets[i]==null&&(this.buckets[i]=new pe(this.bucketSize));for(let a=0;a<ci;a++){let c=this.buckets[i].swap(t);if(c!=null&&(i=(i^c.hash())%this.filterSize,this.buckets[i]==null&&(this.buckets[i]=new pe(this.bucketSize)),this.buckets[i].add(c)))return this.count++,!0}return!1}has(e){typeof e=="string"&&(e=C(e));let t=new M(e,this.hash,this.seed,this.fingerprintSize),n=this.hash.hash(e,this.seed)%this.filterSize,o=this.buckets[n]?.has(t)??!1;if(o)return o;let s=(n^t.hash())%this.filterSize;return this.buckets[s]?.has(t)??!1}remove(e){typeof e=="string"&&(e=C(e));let t=new M(e,this.hash,this.seed,this.fingerprintSize),n=this.hash.hash(e,this.seed)%this.filterSize,o=this.buckets[n]?.remove(t)??!1;if(o)return this.count--,o;let s=(n^t.hash())%this.filterSize,i=this.buckets[s]?.remove(t)??!1;return i&&this.count--,i}get reliable(){return Math.floor(100*(this.count/this.filterSize))<=90}},ui={1:.5,2:.84,4:.95,8:.98};function li(r=.001){return r>.002?2:r>1e-5?4:8}function zn(r,e=.001){let t=li(e),n=ui[t],o=Math.round(r/n),s=Math.min(Math.ceil(Math.log2(1/e)+Math.log2(2*t)),yr);return{filterSize:o,bucketSize:t,fingerprintSize:s}}var at=class{filterSize;bucketSize;fingerprintSize;scale;filterSeries;hash;seed;constructor(e){this.bucketSize=e.bucketSize??4,this.filterSize=e.filterSize??(1<<18)/this.bucketSize,this.fingerprintSize=e.fingerprintSize??2,this.scale=e.scale??2,this.hash=e.hash??Ve,this.seed=e.seed??de(0,Math.pow(2,10)),this.filterSeries=[new qe({filterSize:this.filterSize,bucketSize:this.bucketSize,fingerprintSize:this.fingerprintSize,hash:this.hash,seed:this.seed})]}add(e){if(typeof e=="string"&&(e=C(e)),this.has(e))return!0;let t=this.filterSeries.find(n=>n.reliable);if(t==null){let n=this.filterSize*Math.pow(this.scale,this.filterSeries.length);t=new qe({filterSize:n,bucketSize:this.bucketSize,fingerprintSize:this.fingerprintSize,hash:this.hash,seed:this.seed}),this.filterSeries.push(t)}return t.add(e)}has(e){typeof e=="string"&&(e=C(e));for(let t=0;t<this.filterSeries.length;t++)if(this.filterSeries[t].has(e))return!0;return!1}remove(e){typeof e=="string"&&(e=C(e));for(let t=0;t<this.filterSeries.length;t++)if(this.filterSeries[t].remove(e))return!0;return!1}get count(){return this.filterSeries.reduce((e,t)=>e+t.count,0)}};function ct(r,e=.001,t){return new at({...zn(r,e),...t??{}})}function fi(r){let e=r.getComponents(),t={},n=0;return e[n]?.name==="ip6zone"&&(t.zone=`${e[n].value}`,n++),e[n]?.name==="ip4"||e[n]?.name==="ip6"||e[n]?.name==="dns"||e[n]?.name==="dns4"||e[n]?.name==="dns6"?(t.type=e[n].name,t.host=e[n].value,n++):e[n]?.name==="dnsaddr"&&(t.type=e[n].name,t.host=`_dnsaddr.${e[n].value}`,n++),(e[n]?.name==="tcp"||e[n]?.name==="udp")&&(t.protocol=e[n].name==="tcp"?"tcp":"udp",t.port=parseInt(`${e[n].value}`),n++),e[n]?.name==="ipcidr"&&(t.type==="ip4"?t.cidr=parseInt(`${e[n].value}`):t.type==="ip6"&&(t.cidr=`${e[n].value}`),n++),t.type==null||t.host==null?null:(e[n]?.name==="tls"&&e[n+1]?.name==="sni"&&(t.sni=e[n+1].value,n+=2),t)}function ut(r){let e=fi(r);if(e==null)throw new it(`Multiaddr ${r} was not an IPv4, IPv6, DNS, DNS4, DNS6 or DNSADDR address`);return e}var lt=class{index=0;input="";new(e){return this.index=0,this.input=e,this}readAtomically(e){let t=this.index,n=e();return n===void 0&&(this.index=t),n}parseWith(e){let t=e();if(this.index===this.input.length)return t}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(e){return this.readAtomically(()=>{let t=this.readChar();if(t===e)return t})}readSeparator(e,t,n){return this.readAtomically(()=>{if(!(t>0&&this.readGivenChar(e)===void 0))return n()})}readNumber(e,t,n,o){return this.readAtomically(()=>{let s=0,i=0,a=this.peekChar();if(a===void 0)return;let c=a==="0",l=2**(8*o)-1;for(;;){let h=this.readAtomically(()=>{let d=this.readChar();if(d===void 0)return;let u=Number.parseInt(d,e);if(!Number.isNaN(u))return u});if(h===void 0)break;if(s*=e,s+=h,s>l||(i+=1,t!==void 0&&i>t))return}if(i!==0)return!n&&c&&i>1?void 0:s})}readIPv4Addr(){return this.readAtomically(()=>{let e=new Uint8Array(4);for(let t=0;t<e.length;t++){let n=this.readSeparator(".",t,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;e[t]=n}return e})}readIPv6Addr(){let e=t=>{for(let n=0;n<t.length/2;n++){let o=n*2;if(n<t.length-3){let i=this.readSeparator(":",n,()=>this.readIPv4Addr());if(i!==void 0)return t[o]=i[0],t[o+1]=i[1],t[o+2]=i[2],t[o+3]=i[3],[o+4,!0]}let s=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(s===void 0)return[o,!1];t[o]=s>>8,t[o+1]=s&255}return[t.length,!1]};return this.readAtomically(()=>{let t=new Uint8Array(16),[n,o]=e(t);if(n===16)return t;if(o||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let s=new Uint8Array(14),i=16-(n+2),[a]=e(s.subarray(0,i));return t.set(s.subarray(0,a),16-a),t})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var hi=45,di=15,ft=new lt;function Bn(r){if(!(r.length>di))return ft.new(r).parseWith(()=>ft.readIPv4Addr())}function Mn(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>hi))return ft.new(r).parseWith(()=>ft.readIPv6Addr())}function Se(r){return!!Bn(r)}function ht(r){return!!Mn(r)}var Wn=Bo(jn(),1),yi=["0.0.0.0/8","10.0.0.0/8","100.64.0.0/10","127.0.0.0/8","169.254.0.0/16","172.16.0.0/12","192.0.0.0/24","192.0.0.0/29","192.0.0.8/32","192.0.0.9/32","192.0.0.10/32","192.0.0.170/32","192.0.0.171/32","192.0.2.0/24","192.31.196.0/24","192.52.193.0/24","192.88.99.0/24","192.168.0.0/16","192.175.48.0/24","198.18.0.0/15","198.51.100.0/24","203.0.113.0/24","240.0.0.0/4","255.255.255.255/32"],Ei=yi.map(r=>new Wn.Netmask(r));function Pr(r){for(let e of Ei)if(e.contains(r))return!0;return!1}function vi(r){return/^::ffff:([0-9a-fA-F]{1,4}):([0-9a-fA-F]{1,4})$/.test(r)}function _i(r){let e=r.split(":");if(e.length<2)return!1;let t=e[e.length-1].padStart(4,"0"),n=e[e.length-2].padStart(4,"0"),o=`${parseInt(n.substring(0,2),16)}.${parseInt(n.substring(2),16)}.${parseInt(t.substring(0,2),16)}.${parseInt(t.substring(2),16)}`;return Pr(o)}function Ii(r){return/^::ffff:([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(r)}function Si(r){let e=r.split(":"),t=e[e.length-1];return Pr(t)}function Ci(r){return/^::$/.test(r)||/^::1$/.test(r)||/^64:ff9b::([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(r)||/^100::([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^2001::([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^2001:2[0-9a-fA-F]:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^2001:db8:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^2002:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^f[c-d]([0-9a-fA-F]{2,2}):/i.test(r)||/^fe[8-9a-bA-B][0-9a-fA-F]:/i.test(r)||/^ff([0-9a-fA-F]{2,2}):/i.test(r)}function Hn(r){if(Se(r))return Pr(r);if(vi(r))return _i(r);if(Ii(r))return Si(r);if(ht(r))return Ci(r)}function Gn(r){try{let e=ut(r);switch(e.type){case"ip4":case"ip6":return Hn(e.host)??!1;default:return e.host==="localhost"}}catch{return!1}}function ce(r,e="utf8"){let t=ot[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.encoder.encode(r).substring(1)}var A=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},te=class extends Error{static name="ValidationError";name="ValidationError"},pt=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},mt=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};function Dr(r){return e=>ce(e,r)}function Tr(r){return e=>C(e,r)}function De(r){return new DataView(r.buffer).getUint16(r.byteOffset).toString()}function ge(r){let e=new ArrayBuffer(2);return new DataView(e).setUint16(0,typeof r=="string"?parseInt(r):r),new Uint8Array(e)}function Qn(r){let e=r.split(":");if(e.length!==2)throw new Error(`failed to parse onion addr: ["'${e.join('", "')}'"]' does not contain a port number`);if(e[0].length!==16)throw new Error(`failed to parse onion addr: ${e[0]} not a Tor onion address.`);let t=C(e[0],"base32"),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=ge(n);return ee([t,o],t.length+o.length)}function Xn(r){let e=r.split(":");if(e.length!==2)throw new Error(`failed to parse onion addr: ["'${e.join('", "')}'"]' does not contain a port number`);if(e[0].length!==56)throw new Error(`failed to parse onion addr: ${e[0]} not a Tor onion3 address.`);let t=ie.decode(`b${e[0]}`),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=ge(n);return ee([t,o],t.length+o.length)}function Lr(r){let e=r.subarray(0,r.length-2),t=r.subarray(r.length-2),n=ce(e,"base32"),o=De(t);return`${n}:${o}`}var kr=function(r){r=r.toString().trim();let e=new Uint8Array(4);return r.split(/\./g).forEach((t,n)=>{let o=parseInt(t,10);if(isNaN(o)||o<0||o>255)throw new A("Invalid byte value in IP address");e[n]=o}),e},Kn=function(r){let e=0;r=r.toString().trim();let t=r.split(":",8),n;for(n=0;n<t.length;n++){let s=Se(t[n]),i;s&&(i=kr(t[n]),t[n]=ce(i.subarray(0,2),"base16")),i!=null&&++n<8&&t.splice(n,0,ce(i.subarray(2,4),"base16"))}if(t[0]==="")for(;t.length<8;)t.unshift("0");else if(t[t.length-1]==="")for(;t.length<8;)t.push("0");else if(t.length<8){for(n=0;n<t.length&&t[n]!=="";n++);let s=[n,1];for(n=9-t.length;n>0;n--)s.push("0");t.splice.apply(t,s)}let o=new Uint8Array(e+16);for(n=0;n<t.length;n++){t[n]===""&&(t[n]="0");let s=parseInt(t[n],16);if(isNaN(s)||s<0||s>65535)throw new A("Invalid byte value in IP address");o[e++]=s>>8&255,o[e++]=s&255}return o},Jn=function(r){if(r.byteLength!==4)throw new A("IPv4 address was incorrect length");let e=[];for(let t=0;t<r.byteLength;t++)e.push(r[t]);return e.join(".")},Yn=function(r){if(r.byteLength!==16)throw new A("IPv6 address was incorrect length");let e=[];for(let n=0;n<r.byteLength;n+=2){let o=r[n],s=r[n+1],i=`${o.toString(16).padStart(2,"0")}${s.toString(16).padStart(2,"0")}`;e.push(i)}let t=e.join(":");try{let n=new URL(`http://[${t}]`);return n.hostname.substring(1,n.hostname.length-1)}catch{throw new A(`Invalid IPv6 address "${t}"`)}};function Zn(r){try{let e=new URL(`http://[${r}]`);return e.hostname.substring(1,e.hostname.length-1)}catch{throw new A(`Invalid IPv6 address "${r}"`)}}var Ar=Object.values(Me).map(r=>r.decoder),Pi=(function(){let r=Ar[0].or(Ar[1]);return Ar.slice(2).forEach(e=>r=r.or(e)),r})();function eo(r){return Pi.decode(r)}function to(r){return e=>r.encoder.encode(e)}function Ai(r){if(parseInt(r).toString()!==r)throw new te("Value must be an integer")}function Di(r){if(r<0)throw new te("Value must be a positive integer, or zero")}function Ti(r){return e=>{if(e>r)throw new te(`Value must be smaller than or equal to ${r}`)}}function Li(...r){return e=>{for(let t of r)t(e)}}var je=Li(Ai,Di,Ti(65535));var P=-1,Or=class{protocolsByCode=new Map;protocolsByName=new Map;getProtocol(e){let t;if(typeof e=="string"?t=this.protocolsByName.get(e):t=this.protocolsByCode.get(e),t==null)throw new mt(`Protocol ${e} was unknown`);return t}addProtocol(e){this.protocolsByCode.set(e.code,e),this.protocolsByName.set(e.name,e),e.aliases?.forEach(t=>{this.protocolsByName.set(t,e)})}removeProtocol(e){let t=this.protocolsByCode.get(e);t!=null&&(this.protocolsByCode.delete(t.code),this.protocolsByName.delete(t.name),t.aliases?.forEach(n=>{this.protocolsByName.delete(n)}))}},re=new Or,Wi=[{code:4,name:"ip4",size:32,valueToBytes:kr,bytesToValue:Jn,validate:r=>{if(!Se(r))throw new te(`Invalid IPv4 address "${r}"`)}},{code:6,name:"tcp",size:16,valueToBytes:ge,bytesToValue:De,validate:je},{code:273,name:"udp",size:16,valueToBytes:ge,bytesToValue:De,validate:je},{code:33,name:"dccp",size:16,valueToBytes:ge,bytesToValue:De,validate:je},{code:41,name:"ip6",size:128,valueToBytes:Kn,bytesToValue:Yn,stringToValue:Zn,validate:r=>{if(!ht(r))throw new te(`Invalid IPv6 address "${r}"`)}},{code:42,name:"ip6zone",size:P},{code:43,name:"ipcidr",size:8,bytesToValue:Dr("base10"),valueToBytes:Tr("base10")},{code:53,name:"dns",size:P},{code:54,name:"dns4",size:P},{code:55,name:"dns6",size:P},{code:56,name:"dnsaddr",size:P},{code:132,name:"sctp",size:16,valueToBytes:ge,bytesToValue:De,validate:je},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:P,stringToValue:r=>decodeURIComponent(r),valueToString:r=>encodeURIComponent(r)},{code:421,name:"p2p",aliases:["ipfs"],size:P,bytesToValue:Dr("base58btc"),valueToBytes:r=>r.startsWith("Q")||r.startsWith("1")?Tr("base58btc")(r):X.parse(r).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:Lr,valueToBytes:Qn},{code:445,name:"onion3",size:296,bytesToValue:Lr,valueToBytes:Xn},{code:446,name:"garlic64",size:P},{code:447,name:"garlic32",size:P},{code:448,name:"tls"},{code:449,name:"sni",size:P},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:P,bytesToValue:to(Yt),valueToBytes:eo},{code:480,name:"http"},{code:481,name:"http-path",size:P,stringToValue:r=>`/${decodeURIComponent(r)}`,valueToString:r=>encodeURIComponent(r.substring(1))},{code:443,name:"https"},{code:477,name:"ws"},{code:478,name:"wss"},{code:479,name:"p2p-websocket-star"},{code:277,name:"p2p-stardust"},{code:275,name:"p2p-webrtc-star"},{code:276,name:"p2p-webrtc-direct"},{code:280,name:"webrtc-direct"},{code:281,name:"webrtc"},{code:290,name:"p2p-circuit"},{code:777,name:"memory",size:P}];Wi.forEach(r=>{re.addProtocol(r)});function ro(r){let e=[],t=0;for(;t<r.length;){let n=ur(r,t),o=re.getProtocol(n),s=_e(n),i=Hi(o,r,t+s),a=0;i>0&&o.size===P&&(a=_e(i));let c=s+a+i,l={code:n,name:o.name,bytes:nr(r.subarray(t,t+c))};if(i>0){let h=t+s+a,d=r.subarray(h,h+i);l.value=o.bytesToValue?.(d)??ce(d)}e.push(l),t+=c}return e}function no(r){let e=0,t=[];for(let n of r){if(n.bytes==null){let o=re.getProtocol(n.code),s=_e(n.code),i,a=0,c=0;n.value!=null&&(i=o.valueToBytes?.(n.value)??C(n.value),a=i.byteLength,o.size===P&&(c=_e(a)));let l=new Uint8Array(s+c+a),h=0;cr(n.code,l,h),h+=s,i!=null&&(o.size===P&&(cr(a,l,h),h+=c),l.set(i,h)),n.bytes=l}t.push(n.bytes),e+=n.bytes.byteLength}return ee(t,e)}function oo(r){if(r.charAt(0)!=="/")throw new A('String multiaddr must start with "/"');let e=[],t="protocol",n="",o="";for(let s=1;s<r.length;s++){let i=r.charAt(s);i!=="/"&&(t==="protocol"?o+=r.charAt(s):n+=r.charAt(s));let a=s===r.length-1;if(i==="/"||a){let c=re.getProtocol(o);if(t==="protocol"){if(c.size==null||c.size===0){e.push({code:c.code,name:c.name}),n="",o="",t="protocol";continue}else if(a)throw new A(`Component ${o} was missing value`);t="value"}else if(t==="value"){let l={code:c.code,name:c.name};if(c.size!=null&&c.size!==0){if(n==="")throw new A(`Component ${o} was missing value`);l.value=c.stringToValue?.(n)??n}e.push(l),n="",o="",t="protocol"}}}if(o!==""&&n!=="")throw new A("Incomplete multiaddr");return e}function so(r){return`/${r.flatMap(e=>{if(e.value==null)return e.name;let t=re.getProtocol(e.code);if(t==null)throw new A(`Unknown protocol code ${e.code}`);return[e.name,t.valueToString?.(e.value)??e.value]}).join("/")}`}function Hi(r,e,t){return r.size==null||r.size===0?0:r.size>0?r.size/8:ur(e,t)}var Gi=Symbol.for("nodejs.util.inspect.custom"),Wr=Symbol.for("@multiformats/multiaddr");function Qi(r){if(r==null&&(r="/"),io(r))return r.getComponents();if(r instanceof Uint8Array)return ro(r);if(typeof r=="string")return r=r.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),r===""&&(r="/"),oo(r);if(Array.isArray(r))return r;throw new A("Must be a string, Uint8Array, Component[], or another Multiaddr")}var Et=class r{[Wr]=!0;#e;#t;#r;constructor(e="/",t={}){this.#e=Qi(e),t.validate!==!1&&Xi(this)}get bytes(){return this.#r==null&&(this.#r=no(this.#e)),this.#r}toString(){return this.#t==null&&(this.#t=so(this.#e)),this.#t}toJSON(){return this.toString()}getComponents(){return[...this.#e.map(e=>({...e}))]}encapsulate(e){let t=new r(e);return new r([...this.#e,...t.getComponents()],{validate:!1})}decapsulate(e){let t=e.toString(),n=this.toString(),o=n.lastIndexOf(t);if(o<0)throw new pt(`Address ${this.toString()} does not contain subaddress: ${t}`);return new r(n.slice(0,o),{validate:!1})}decapsulateCode(e){let t;for(let n=this.#e.length-1;n>-1;n--)if(this.#e[n].code===e){t=n;break}return new r(this.#e.slice(0,t),{validate:!1})}equals(e){return he(this.bytes,e.bytes)}[Gi](){return`Multiaddr(${this.toString()})`}};function Xi(r){r.getComponents().forEach(e=>{let t=re.getProtocol(e.code);e.value!=null&&t.validate?.(e.value)})}function io(r){return!!r?.[Wr]}function vt(r){return new Et(r)}var y=r=>({match:e=>{let t=e[0];return t==null||t.code!==r||t.value!=null?!1:e.slice(1)}}),f=(r,e)=>({match:t=>{let n=t[0];return n?.code!==r||n.value==null||e!=null&&n.value!==e?!1:t.slice(1)}}),ao=r=>({match:e=>r.match(e)===!1?e:!1}),m=r=>({match:e=>{let t=r.match(e);return t===!1?e:t}}),T=(...r)=>({match:e=>{let t;for(let n of r){let o=n.match(e);o!==!1&&(t==null||o.length<t.length)&&(t=o)}return t??!1}}),b=(...r)=>({match:e=>{for(let t of r){let n=t.match(e);if(n===!1)return!1;e=n}return e}});function E(...r){function e(o){if(o==null)return!1;let s=o.getComponents();for(let i of r){let a=i.match(s);if(a===!1)return!1;s=a}return s}function t(o){return e(o)!==!1}function n(o){let s=e(o);return s===!1?!1:s.length===0}return{matchers:r,matches:t,exactMatch:n}}var Ki=f(421),Dl=E(Ki),It=f(54),St=f(55),Ct=f(56),Gr=f(53),Tl=E(It,m(f(421))),Ll=E(St,m(f(421))),kl=E(Ct,m(f(421))),co=E(T(Gr,Ct,It,St),m(f(421))),uo=b(f(4),m(f(43))),lo=b(m(f(42)),f(41),m(f(43))),Qr=T(uo,lo),ke=T(Qr,Gr,It,St,Ct),Ol=E(T(Qr,b(T(Gr,Ct,It,St),m(f(421))))),Fl=E(uo),Nl=E(lo),Ul=E(Qr),Xr=b(ke,f(6)),Ke=b(ke,f(273)),$l=E(b(Xr,m(f(421)))),Rl=E(Ke),Kr=b(Ke,y(460),m(f(421))),Pt=b(Ke,y(461),m(f(421))),Ji=T(Kr,Pt),zl=E(Kr),Bl=E(Pt),Hr=T(ke,Xr,Ke,Kr,Pt),fo=T(b(Hr,y(477),m(f(421)))),Ml=E(fo),ho=T(b(Hr,y(478),m(f(421))),b(Hr,y(448),m(f(449)),y(477),m(f(421)))),Vl=E(ho),po=b(Ke,y(280),m(f(466)),m(f(466)),m(f(421))),ql=E(po),mo=b(Pt,y(465),m(f(466)),m(f(466)),m(f(421))),jl=E(mo),_t=T(fo,ho,b(Xr,m(f(421))),b(Ji,m(f(421))),b(ke,m(f(421))),po,mo,f(421)),Wl=E(_t),Yi=b(m(_t),y(290),ao(y(281)),m(f(421))),Hl=E(Yi),Zi=T(b(_t,y(290),y(281),m(f(421))),b(_t,y(281),m(f(421))),b(y(281),m(f(421)))),Gl=E(Zi),ea=b(ke,T(b(f(6,"80")),b(f(6),y(480)),y(480)),m(f(481)),m(f(421))),go=E(ea),ta=b(ke,T(b(f(6,"443")),b(f(6,"443"),y(480)),b(f(6),y(443)),b(f(6),y(448),y(480)),b(y(448),y(480)),y(448),y(443)),m(f(481)),m(f(421))),bo=E(ta),ra=T(b(f(777),m(f(421)))),Ql=E(ra),na=T(b(f(400),m(f(421)))),Xl=E(na);function ne(){let r={};return r.promise=new Promise((e,t)=>{r.resolve=e,r.reject=t}),r}var At=class{buffer;mask;top;btm;next;constructor(e){if(!(e>0)||(e-1&e)!==0)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(e),this.mask=e-1,this.top=0,this.btm=0,this.next=null}push(e){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=e,this.top=this.top+1&this.mask,!0)}shift(){let e=this.buffer[this.btm];if(e!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,e}isEmpty(){return this.buffer[this.btm]===void 0}},Oe=class{size;hwm;head;tail;constructor(e={}){this.hwm=e.splitLimit??16,this.head=new At(this.hwm),this.tail=this.head,this.size=0}calculateSize(e){return e?.byteLength!=null?e.byteLength:1}push(e){if(e?.value!=null&&(this.size+=this.calculateSize(e.value)),!this.head.push(e)){let t=this.head;this.head=t.next=new At(2*this.head.buffer.length),this.head.push(e)}}shift(){let e=this.tail.shift();if(e===void 0&&this.tail.next!=null){let t=this.tail.next;this.tail.next=null,this.tail=t,e=this.tail.shift()}return e?.value!=null&&(this.size-=this.calculateSize(e.value)),e}isEmpty(){return this.head.isEmpty()}};var Jr=class extends Error{type;code;constructor(e,t){super(e??"The operation was aborted"),this.type="aborted",this.code=t??"ABORT_ERR"}};function wo(r={}){return oa(t=>{let n=t.shift();if(n==null)return{done:!0};if(n.error!=null)throw n.error;return{done:n.done===!0,value:n.value}},r)}function oa(r,e){e=e??{};let t=e.onEnd,n=new Oe,o,s,i,a=ne(),c=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((x,g)=>{s=S=>{s=null,n.push(S);try{x(r(n))}catch(k){g(k)}return o}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=ne()})}},l=x=>s!=null?s(x):(n.push(x),o),h=x=>(n=new Oe,s!=null?s({error:x}):(n.push({error:x}),o)),d=x=>{if(i)return o;if(e?.objectMode!==!0&&x?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return l({done:!1,value:x})},u=x=>i?o:(i=!0,x!=null?h(x):l({done:!0})),p=()=>(n=new Oe,u(),{done:!0}),L=x=>(u(x),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:c,return:p,throw:L,push:d,end:u,get readableLength(){return n.size},onEmpty:async x=>{let g=x?.signal;if(g?.throwIfAborted(),n.isEmpty())return;let S,k;g!=null&&(S=new Promise((N,U)=>{k=()=>{U(new Jr)},g.addEventListener("abort",k)}));try{await Promise.race([a.promise,S])}finally{k!=null&&g!=null&&g?.removeEventListener("abort",k)}}},t==null)return o;let O=o;return o={[Symbol.asyncIterator](){return this},next(){return O.next()},throw(x){return O.throw(x),t!=null&&(t(x),t=void 0),{done:!0}},return(){return O.return(),t!=null&&(t(),t=void 0),{done:!0}},push:d,end(x){return O.end(x),t!=null&&(t(x),t=void 0),o},get readableLength(){return O.readableLength},onEmpty:x=>O.onEmpty(x)},o}var Yr=class r extends Error{name="TimeoutError";constructor(e,t){super(e,t),Error.captureStackTrace?.(this,r)}},xo=r=>r.reason??new DOMException("This operation was aborted.","AbortError");function Zr(r,e){let{milliseconds:t,fallback:n,message:o,customTimers:s={setTimeout,clearTimeout},signal:i}=e,a,c,h=new Promise((d,u)=>{if(typeof t!="number"||Math.sign(t)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${t}\``);if(i?.aborted){u(xo(i));return}if(i&&(c=()=>{u(xo(i))},i.addEventListener("abort",c,{once:!0})),r.then(d,u),t===Number.POSITIVE_INFINITY)return;let p=new Yr;a=s.setTimeout.call(void 0,()=>{if(n){try{d(n())}catch(L){u(L)}return}typeof r.cancel=="function"&&r.cancel(),o===!1?d():o instanceof Error?u(o):(p.message=o??`Promise timed out after ${t} milliseconds`,u(p))},t)}).finally(()=>{h.clear(),c&&i&&i.removeEventListener("abort",c)});return h.clear=()=>{s.clearTimeout.call(void 0,a),a=void 0},h}var sa=r=>{let e=r.addEventListener||r.on||r.addListener,t=r.removeEventListener||r.off||r.removeListener;if(!e||!t)throw new TypeError("Emitter is not compatible");return{addListener:e.bind(r),removeListener:t.bind(r)}};function ia(r,e,t){let n,o=new Promise((s,i)=>{if(t={rejectionEvents:["error"],multiArgs:!1,rejectionMultiArgs:!1,resolveImmediately:!1,...t},!(t.count>=0&&(t.count===Number.POSITIVE_INFINITY||Number.isInteger(t.count))))throw new TypeError("The `count` option should be at least 0 or more");t.signal?.throwIfAborted();let a=[e].flat(),c=[],{addListener:l,removeListener:h}=sa(r),d=async(...p)=>{let L=t.multiArgs?p:p[0];if(t.filter)try{if(!await t.filter(L))return}catch(O){n(),i(O);return}c.push(L),t.count===c.length&&(n(),s(c))},u=(...p)=>{n(),i(t.rejectionMultiArgs?p:p[0])};n=()=>{for(let p of a)h(p,d);for(let p of t.rejectionEvents)a.includes(p)||h(p,u)};for(let p of a)l(p,d);for(let p of t.rejectionEvents)a.includes(p)||l(p,u);t.signal&&t.signal.addEventListener("abort",()=>{u(t.signal.reason)},{once:!0}),t.resolveImmediately&&s(c)});if(o.cancel=n,typeof t.timeout=="number"){let s=Zr(o,{milliseconds:t.timeout});return s.cancel=()=>{n(),s.clear()},s}return o}function Dt(r,e,t){typeof t=="function"&&(t={filter:t}),t={...t,count:1,resolveImmediately:!1};let n=ia(r,e,t),o=n.then(s=>s[0]);return o.cancel=n.cancel,o}function en(r,e){let t,n=function(){let o=function(){t=void 0,r()};clearTimeout(t),t=setTimeout(o,e)};return n.start=()=>{},n.stop=()=>{clearTimeout(t)},n}var Tt=class extends Error{static name="QueueFullError";constructor(e="The queue was full"){super(e),this.name="QueueFullError"}};function aa(r){return r.reason}async function Lt(r,e,t){if(e==null)return r;let n=t?.translateError??aa;if(e.aborted)return r.catch(()=>{}),Promise.reject(n(e));let o;try{return await Promise.race([r,new Promise((s,i)=>{o=()=>{i(n(e))},e.addEventListener("abort",o)})])}finally{o!=null&&e.removeEventListener("abort",o)}}var kt=class{deferred;signal;onProgress;constructor(e){this.signal=e?.signal,this.onProgress=e?.onProgress,this.deferred=ne(),this.onAbort=this.onAbort.bind(this),this.signal?.addEventListener("abort",this.onAbort)}onAbort(){this.deferred.reject(this.signal?.reason??new B)}cleanup(){this.signal?.removeEventListener("abort",this.onAbort)}};function ca(){return`${parseInt(String(Math.random()*1e9),10).toString()}${Date.now()}`}var Ot=class{id;fn;options;recipients;status;timeline;controller;dispatchingProgress;constructor(e,t){this.id=ca(),this.status="queued",this.fn=e,this.options=t,this.recipients=[],this.timeline={created:Date.now()},this.controller=new AbortController,this.controller.signal,this.dispatchingProgress=!1,this.onAbort=this.onAbort.bind(this)}abort(e){this.controller.abort(e)}onAbort(){this.recipients.reduce((t,n)=>t&&n.signal?.aborted===!0,!0)&&(this.controller.abort(new B),this.cleanup())}async join(e){let t=new kt(e);return this.recipients.push(t),e?.signal?.addEventListener("abort",this.onAbort),t.deferred.promise}async run(){this.status="running",this.timeline.started=Date.now();try{this.controller.signal.throwIfAborted();let e=await Lt(this.fn({...this.options??{},signal:this.controller.signal,onProgress:t=>{if(!this.dispatchingProgress){this.dispatchingProgress=!0;try{this.recipients.forEach(n=>{n.onProgress?.(t)})}finally{this.dispatchingProgress=!1}}}}),this.controller.signal);this.recipients.forEach(t=>{t.deferred.resolve(e)}),this.status="complete"}catch(e){this.recipients.forEach(t=>{t.deferred.reject(e)}),this.status="errored"}finally{this.timeline.finished=Date.now(),this.cleanup()}}cleanup(){this.recipients.forEach(e=>{e.cleanup(),e.signal?.removeEventListener("abort",this.onAbort)})}};var Ft=class extends Ie{concurrency;maxSize;queue;pending;sort;paused;constructor(e={}){super(),this.concurrency=e.concurrency??Number.POSITIVE_INFINITY,this.maxSize=e.maxSize??Number.POSITIVE_INFINITY,this.pending=0,this.paused=!1,e.metricName!=null&&e.metrics?.registerMetricGroup(e.metricName,{calculate:()=>({size:this.queue.length,running:this.pending,queued:this.queue.length-this.pending})}),this.sort=e.sort,this.queue=[],this.emitEmpty=en(this.emitEmpty.bind(this),1),this.emitIdle=en(this.emitIdle.bind(this),1)}emitEmpty(){this.size===0&&this.safeDispatchEvent("empty")}emitIdle(){this.running===0&&this.safeDispatchEvent("idle")}pause(){this.paused=!0}resume(){this.paused&&(this.paused=!1,this.tryToStartAnother())}tryToStartAnother(){if(this.paused)return!1;if(this.size===0)return this.emitEmpty(),this.running===0&&this.emitIdle(),!1;if(this.pending<this.concurrency){let e;for(let t of this.queue)if(t.status==="queued"){e=t;break}return e==null?!1:(this.safeDispatchEvent("active"),this.pending++,e.run().finally(()=>{for(let t=0;t<this.queue.length;t++)if(this.queue[t]===e){this.queue.splice(t,1);break}this.pending--,this.tryToStartAnother(),this.safeDispatchEvent("next")}),!0)}return!1}enqueue(e){this.queue.push(e),this.sort!=null&&this.queue.sort(this.sort)}async add(e,t){if(t?.signal?.throwIfAborted(),this.size===this.maxSize)throw new Tt;let n=new Ot(e,t);this.enqueue(n),this.safeDispatchEvent("add");let o=n.join(t).then(s=>(this.safeDispatchEvent("completed",{detail:s}),this.safeDispatchEvent("success",{detail:{job:n,result:s}}),s)).catch(s=>{if(n.status==="queued"){for(let i=0;i<this.queue.length;i++)if(this.queue[i]===n){this.queue.splice(i,1);break}}throw this.safeDispatchEvent("failure",{detail:{job:n,error:s}}),s});return this.tryToStartAnother(),o}clear(){this.queue.splice(0,this.queue.length)}abort(){this.queue.forEach(e=>{e.abort(new B)}),this.clear()}async onEmpty(e){this.size!==0&&await Dt(this,"empty",e)}async onSizeLessThan(e,t){this.size<e||await Dt(this,"next",{...t,filter:()=>this.size<e})}async onIdle(e){this.pending===0&&this.size===0||await Dt(this,"idle",e)}get size(){return this.queue.length}get queued(){return this.queue.length-this.pending}get running(){return this.pending}async*toGenerator(e){e?.signal?.throwIfAborted();let t=wo({objectMode:!0}),n=c=>{c!=null?this.abort():this.clear(),t.end(c)},o=c=>{c.detail!=null&&t.push(c.detail)},s=c=>{n(c.detail.error)},i=()=>{n()},a=()=>{n(new B("Queue aborted"))};this.addEventListener("completed",o),this.addEventListener("failure",s),this.addEventListener("idle",i),e?.signal?.addEventListener("abort",a);try{yield*t}finally{this.removeEventListener("completed",o),this.removeEventListener("failure",s),this.removeEventListener("idle",i),e?.signal?.removeEventListener("abort",a),n()}}};var Nt=class extends Ie{initialPeerSearchComplete;requests;logName;log;logger;minProviders;maxProviders;providers;evictionFilter;initialProviders;cidPeerFilterSize;constructor(e,t){super(),this.logName=t.name,this.logger=e.logger,this.log=e.logger.forComponent(this.logName),this.requests=new Map,this.minProviders=t.minProviders??1,this.maxProviders=t.maxProviders??5,this.cidPeerFilterSize=t.cidPeerFilterSize??100,this.providers=[],this.evictionFilter=ct(this.maxProviders),this.initialProviders=[...t.providers??[]]}async retrieve(e,t={}){let n=Be.encode(e.multihash.bytes),o=this.requests.get(n);if(o!=null)return this.log("join existing request for %c",e),o.observers++,o.promise;let s=ne(),i={promise:s.promise,observers:1,queryFilter:ct(this.cidPeerFilterSize)};this.requests.set(n,i);let a=!1;this.initialPeerSearchComplete==null&&(a=!0,this.log=this.logger.forComponent(`${this.logName}:${e}`),this.initialPeerSearchComplete=this.findProviders(e,this.minProviders,t));let c=!1,l=new Ft({concurrency:this.maxProviders});l.addEventListener("failure",u=>{this.log.error("error querying provider %s, evicting from session - %e",u.detail.job.options.provider,u.detail.error),this.evict(u.detail.job.options.provider)}),l.addEventListener("success",u=>{c=!0,s.resolve(u.detail.result)}),l.addEventListener("idle",()=>{if(c){this.log.trace("session idle, found block");return}if(t.signal?.aborted===!0){this.log.trace("session idle, signal aborted");return}Promise.resolve().then(async()=>{this.log("no session peers had block for for %c, finding new providers",e);for(let u=0;u<this.minProviders&&this.providers.length!==0;u++){let p=this.providers[Math.floor(Math.random()*this.providers.length)];this.evict(p)}await this.findProviders(e,this.minProviders,t),this.log("found new providers re-retrieving %c",e),this.requests.delete(n),s.resolve(await this.retrieve(e,t))}).catch(u=>{this.log.error("could not find new providers for %c - %e",e,u),s.reject(u)})});let h=u=>{let p=this.toFilterKey(u.detail);i.queryFilter.has(p)||(i.queryFilter.add(p),this.emitFoundProviderProgressEvent(e,u.detail,t),l.add(async()=>this.queryProvider(e,u.detail,t),{provider:u.detail}).catch(L=>{t.signal?.aborted!==!0&&this.log.error("error retrieving session block for %c - %e",e,L)}))};if(this.addEventListener("provider",h),a)try{await Lt(this.initialPeerSearchComplete,t.signal),a&&this.log("found initial session peers for %c",e)}catch(u){throw a&&this.log("failed to find initial session peers for %c - %e",e,u),this.requests.delete(n),i.observers>1&&s.reject(u),u}Promise.all([...this.providers].filter(u=>{let p=this.toFilterKey(u),L=i.queryFilter.has(p);return L||i.queryFilter.add(this.toFilterKey(u)),!L}).map(async u=>l.add(async()=>this.queryProvider(e,u,t),{provider:u}))).catch(u=>{t.signal?.aborted!==!0&&this.log.error("error retrieving session block for %c - %e",e,u)});let d=()=>{s.reject(new B(t.signal?.reason??"Session aborted")),l.abort()};t.signal?.addEventListener("abort",d);try{return await s.promise}finally{this.removeEventListener("provider",h),t.signal?.removeEventListener("abort",d),l.clear(),this.requests.delete(n)}}evict(e){this.evictionFilter.add(this.toFilterKey(e));let t=this.providers.findIndex(n=>this.equals(n,e));t!==-1&&this.providers.splice(t,1)}isEvicted(e){return this.evictionFilter.has(this.toFilterKey(e))}hasProvider(e){return!!(this.providers.find(t=>this.equals(t,e))!=null||this.isEvicted(e))}async addPeer(e,t){let n=await this.convertToProvider(e,"manually-added",t);n==null||this.hasProvider(n)||(this.providers.push(n),this.safeDispatchEvent("provider",{detail:n}))}async findProviders(e,t,n){let o=ne(),s=0;return Promise.resolve().then(async()=>{this.log("finding %d-%d new provider(s) for %c - %d initial providers",t,this.maxProviders,e,this.initialProviders.length);let i=this,a=async function*(){for(;i.initialProviders.length>0;){let l=i.initialProviders.pop();if(l==null)continue;let h=await i.convertToProvider(l,"manual",n);h!=null&&(yield h)}},c=async function*(){yield*a(),yield*i.findNewProviders(e,n)};for await(let l of c()){if(this.providers.length===this.maxProviders||n.signal?.aborted===!0)break;if(!this.hasProvider(l)&&(this.log("found %d providers, %d in session",s,this.providers.length),this.providers.push(l),this.safeDispatchEvent("provider",{detail:l}),s++,this.providers.length===t&&(this.log("session is ready with %d peer(s), new peers present",this.providers.length),o.resolve()),this.providers.length===this.maxProviders)){this.log("found max session peers %d",this.providers.length);break}}if(this.log("found %d new session peers while trying to find %d, %d in session",s,t,this.providers.length),this.providers.length<t)throw new st(`Found ${s} of ${t} ${this.name} providers for ${e}, ${this.providers.length} in session after evictions`)}).catch(i=>{this.log.error("error searching routing for potential session peers for %c - %e",e,i),o.reject(i)}),o.promise}};function yo(r){return r==null?!1:X.asCID(r)!=null}var ha=[6,53,56,54,55];function Eo(r){return Io("sni",r)?.value}function vo(r){let e=Io("tcp",r)?.value;return e==null?"":`:${e}`}function Io(r,e){return e.find(t=>t.name===r)}function _o(r){return r.some(({code:e})=>e===448)}function q(r,e){let t=So[r.name];if(t==null)throw new Error(`Can't interpret protocol ${r.name}`);let n=t(r,e);return r.code===41?`[${n}]`:n}var So={ip4:(r,e)=>r.value,ip6:(r,e)=>e.length===0?r.value:`[${r.value}]`,tcp:(r,e)=>{let t=e.pop();if(t==null)throw new Error("Unexpected end of multiaddr");return`tcp://${q(t,e)}:${r.value}`},udp:(r,e)=>{let t=e.pop();if(t==null)throw new Error("Unexpected end of multiaddr");return`udp://${q(t,e)}:${r.value}`},dnsaddr:(r,e)=>r.value,dns4:(r,e)=>r.value,dns6:(r,e)=>r.value,dns:(r,e)=>r.value,ipfs:(r,e)=>{let t=e.pop();if(t==null)throw new Error("Unexpected end of multiaddr");return`${q(t,e)}`},p2p:(r,e)=>{let t=e.pop();if(t==null)throw new Error("Unexpected end of multiaddr");return`${q(t,e)}`},http:(r,e)=>{let t=_o(e),n=Eo(e),o=vo(e);if(t&&n!=null)return`https://${n}${o}`;let s=t?"https://":"http://",i=e.pop();if(i==null)throw new Error("Unexpected end of multiaddr");let a=q(i,e);return a=a?.replace("tcp://",""),`${s}${a}`},"http-path":(r,e)=>{let t=e.pop();if(t==null)throw new Error("Unexpected end of multiaddr");let n=q(t,e),o=decodeURIComponent(r.value??"");return`${n}${o}`},tls:(r,e)=>{let t=e.pop();if(t==null)throw new Error("Unexpected end of multiaddr");return q(t,e)},sni:(r,e)=>{let t=e.pop();if(t==null)throw new Error("Unexpected end of multiaddr");return q(t,e)},https:(r,e)=>{let t=e.pop();if(t==null)throw new Error("Unexpected end of multiaddr");let n=q(t,e);return n=n?.replace("tcp://",""),`https://${n}`},ws:(r,e)=>{let t=_o(e),n=Eo(e),o=vo(e);if(t&&n!=null)return`wss://${n}${o}`;let s=t?"wss://":"ws://",i=e.pop();if(i==null)throw new Error("Unexpected end of multiaddr");let a=q(i,e);return a=a?.replace("tcp://",""),`${s}${a}`},wss:(r,e)=>{let t=e.pop();if(t==null)throw new Error("Unexpected end of multiaddr");let n=q(t,e);return n=n?.replace("tcp://",""),`wss://${n}`}};function Ut(r,e){let n=vt(r).getComponents(),o=n.pop();if(o==null)throw new Error("Unexpected end of multiaddr");let s=So[o.name];if(s==null)throw new Error(`No interpreter found for ${o.name}`);let i=s(o,n)??"";return e?.assumeHttp!==!1&&ha.includes(o.code)&&(i=i.replace(/^.*:\/\//,""),o.value==="443"?i=`https://${i}`:i=`http://${i}`),(i.startsWith("http://")||i.startsWith("https://")||i.startsWith("ws://")||i.startsWith("wss://"))&&(i=new URL(i).toString(),i.endsWith("/")&&(i=i.substring(0,i.length-1))),i}var j=class extends Event{type;detail;constructor(e,t){super(e),this.type=e,this.detail=t}};var Co="[a-fA-F\\d:]",le=r=>r&&r.includeBoundaries?`(?:(?<=\\s|^)(?=${Co})|(?<=${Co})(?=\\s|$))`:"",W="(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)){3}",I="[a-fA-F\\d]{1,4}",$t=`
|
|
2
|
+
"use strict";var HeliaTrustlessGatewayClient=(()=>{var Uo=Object.create;var et=Object.defineProperty;var $o=Object.getOwnPropertyDescriptor;var Ro=Object.getOwnPropertyNames;var zo=Object.getPrototypeOf,Bo=Object.prototype.hasOwnProperty;var Bt=(r,e)=>()=>{try{return e||r((e={exports:{}}).exports,e),e.exports}catch(t){throw e=0,t}},F=(r,e)=>{for(var t in e)et(r,t,{get:e[t],enumerable:!0})},hn=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Ro(e))!Bo.call(r,o)&&o!==t&&et(r,o,{get:()=>e[o],enumerable:!(n=$o(e,o))||n.enumerable});return r};var Mo=(r,e,t)=>(t=r!=null?Uo(zo(r)):{},hn(e||!r||!r.__esModule?et(t,"default",{value:r,enumerable:!0}):t,r)),Vo=r=>hn(et({},"__esModule",{value:!0}),r);var vr=Bt(Pe=>{"use strict";Object.defineProperty(Pe,"__esModule",{value:!0});Pe.Netmask4Impl=void 0;Pe.ip2long=Ce;Pe.long2ip=Y;function Y(r){let e=(r&-16777216)>>>24,t=(r&255<<16)>>>16,n=(r&65280)>>>8,o=r&255;return[e,t,n,o].join(".")}var mi=48,gi=97,bi=65;function wi(r){let e=0,t=10,n="9",o=0;r.length>1&&r[o]==="0"&&(r[o+1]==="x"||r[o+1]==="X"?(o+=2,t=16):"0"<=r[o+1]&&r[o+1]<="9"&&(o++,t=8,n="7"));let s=o;for(;o<r.length;){if("0"<=r[o]&&r[o]<=n)e=e*t+(r.charCodeAt(o)-mi)>>>0;else if(t===16)if("a"<=r[o]&&r[o]<="f")e=e*t+(10+r.charCodeAt(o)-gi)>>>0;else if("A"<=r[o]&&r[o]<="F")e=e*t+(10+r.charCodeAt(o)-bi)>>>0;else break;else break;if(e>4294967295)throw new Error("too large");o++}if(o===s)throw new Error("empty octet");return[e,o]}function Ce(r){let e=[];for(let t=0;t<=3&&r.length!==0;t++){if(t>0){if(r[0]!==".")throw new Error("Invalid IP");r=r.substring(1)}let[n,o]=wi(r);r=r.substring(o),e.push(n)}if(r.length!==0)throw new Error("Invalid IP");switch(e.length){case 1:if(e[0]>4294967295)throw new Error("Invalid IP");return e[0]>>>0;case 2:if(e[0]>255||e[1]>16777215)throw new Error("Invalid IP");return(e[0]<<24|e[1])>>>0;case 3:if(e[0]>255||e[1]>255||e[2]>65535)throw new Error("Invalid IP");return(e[0]<<24|e[1]<<16|e[2])>>>0;case 4:if(e[0]>255||e[1]>255||e[2]>255||e[3]>255)throw new Error("Invalid IP");return(e[0]<<24|e[1]<<16|e[2]<<8|e[3])>>>0;default:throw new Error("Invalid IP")}}var Er=class r{constructor(e,t){if(typeof e!="string")throw new Error("Missing `net' parameter");let n=t;if(!n){let o=e.split("/",2);e=o[0],n=o[1]}if(n||(n=32),typeof n=="string"&&n.indexOf(".")>-1){try{this.maskLong=Ce(n)}catch{throw new Error("Invalid mask: "+n)}this.bitmask=NaN;for(let o=32;o>=0;o--)if(this.maskLong===4294967295<<32-o>>>0){this.bitmask=o;break}}else if(n||n===0)this.bitmask=parseInt(n,10),this.maskLong=0,this.bitmask>0&&(this.maskLong=4294967295<<32-this.bitmask>>>0);else throw new Error("Invalid mask: empty");try{this.netLong=(Ce(e)&this.maskLong)>>>0}catch{throw new Error("Invalid net address: "+e)}if(!(this.bitmask<=32))throw new Error("Invalid mask for ip4: "+n);this.size=Math.pow(2,32-this.bitmask),this.base=Y(this.netLong),this.mask=Y(this.maskLong),this.hostmask=Y(~this.maskLong),this.first=this.bitmask<=30?Y(this.netLong+1):this.base,this.last=this.bitmask<=30?Y(this.netLong+this.size-2):Y(this.netLong+this.size-1),this.broadcast=this.bitmask<=30?Y(this.netLong+this.size-1):void 0}contains(e){return typeof e=="string"&&(e.indexOf("/")>0||e.split(".").length!==4)&&(e=new r(e)),e instanceof r?this.contains(e.base)&&this.contains(e.broadcast||e.last):(Ce(e)&this.maskLong)>>>0===(this.netLong&this.maskLong)>>>0}next(e=1){return new r(Y(this.netLong+this.size*e),this.mask)}forEach(e){let t=Ce(this.first),n=Ce(this.last),o=0;for(;t<=n;)e(Y(t),t,o),o++,t++}toString(){return this.base+"/"+this.bitmask}};Pe.Netmask4Impl=Er});var jn=Bt(Ae=>{"use strict";Object.defineProperty(Ae,"__esModule",{value:!0});Ae.Netmask6Impl=void 0;Ae.ip6bigint=Ir;Ae.bigint2ip6=me;var xi=vr(),_r=(1n<<128n)-1n;function Ir(r){let e=r.indexOf("%");e!==-1&&(r=r.substring(0,e));let t=r.lastIndexOf(":");if(t!==-1&&r.indexOf(".",t)!==-1){let n=r.substring(t+1),o=(0,xi.ip2long)(n),s=r.substring(0,t+1)+"0:0";return qn(s)&~0xffffffffn|BigInt(o)}return qn(r)}function qn(r){let e=r.indexOf("::"),t;if(e!==-1){let o=r.substring(0,e),s=r.substring(e+2),i=o===""?[]:o.split(":"),a=s===""?[]:s.split(":"),c=8-i.length-a.length;if(c<0)throw new Error("Invalid IPv6: too many groups");t=[...i,...Array(c).fill("0"),...a]}else t=r.split(":");if(t.length!==8)throw new Error("Invalid IPv6: expected 8 groups, got "+t.length);let n=0n;for(let o=0;o<8;o++){let s=t[o];if(s.length===0||s.length>4)throw new Error('Invalid IPv6: bad group "'+s+'"');let i=parseInt(s,16);if(isNaN(i)||i<0||i>65535)throw new Error('Invalid IPv6: bad group "'+s+'"');n=n<<16n|BigInt(i)}return n}function me(r){if(r<0n||r>_r)throw new Error("Invalid IPv6 address value");let e=[];for(let i=0;i<8;i++)e.unshift(Number(r&0xffffn)),r>>=16n;let t=-1,n=0,o=-1,s=0;for(let i=0;i<8;i++)e[i]===0?o===-1?(o=i,s=1):s++:(s>n&&s>=2&&(t=o,n=s),o=-1,s=0);if(s>n&&s>=2&&(t=o,n=s),t!==-1&&t+n===8&&t>0)return e.slice(0,t).map(a=>a.toString(16)).join(":")+"::";if(t===0)return"::"+e.slice(n).map(a=>a.toString(16)).join(":");if(t>0){let i=e.slice(0,t).map(c=>c.toString(16)),a=e.slice(t+n).map(c=>c.toString(16));return i.join(":")+"::"+a.join(":")}else return e.map(i=>i.toString(16)).join(":")}var Sr=class r{constructor(e,t){if(typeof e!="string")throw new Error("Missing `net' parameter");let n=t;if(n==null){let o=e.indexOf("/");o!==-1?(n=parseInt(e.substring(o+1),10),e=e.substring(0,o)):n=128}if(isNaN(n)||n<0||n>128)throw new Error("Invalid mask for IPv6: "+n);this.bitmask=n,this.bitmask===0?this.maskBigint=0n:this.maskBigint=_r>>BigInt(128-this.bitmask)<<BigInt(128-this.bitmask);try{this.netBigint=Ir(e)&this.maskBigint}catch{throw new Error("Invalid IPv6 net address: "+e)}this.size=Number(1n<<BigInt(128-this.bitmask)),this.base=me(this.netBigint),this.mask=me(this.maskBigint),this.hostmask=me(~this.maskBigint&_r),this.first=this.base,this.last=me(this.netBigint+(1n<<BigInt(128-this.bitmask))-1n),this.broadcast=void 0}contains(e){return typeof e=="string"&&e.indexOf("/")>0&&(e=new r(e)),e instanceof r?this.contains(e.base)&&this.contains(e.last):(Ir(e)&this.maskBigint)===this.netBigint}next(e=1){let t=1n<<BigInt(128-this.bitmask);return new r(me(this.netBigint+t*BigInt(e)),this.bitmask)}forEach(e){let t=this.netBigint,n=1n<<BigInt(128-this.bitmask),o=this.netBigint+n-1n,s=0;for(;t<=o;)e(me(t),Number(t),s),s++,t++}toString(){return this.base+"/"+this.bitmask}};Ae.Netmask6Impl=Sr});var Wn=Bt(ae=>{"use strict";Object.defineProperty(ae,"__esModule",{value:!0});ae.long2ip=ae.ip2long=ae.Netmask=void 0;var dt=vr();Object.defineProperty(ae,"ip2long",{enumerable:!0,get:function(){return dt.ip2long}});Object.defineProperty(ae,"long2ip",{enumerable:!0,get:function(){return dt.long2ip}});var yi=jn(),Cr=class r{constructor(e,t){if(typeof e!="string")throw new Error("Missing `net' parameter");(e.indexOf("/")!==-1?e.substring(0,e.indexOf("/")):e).indexOf(":")!==-1?this._impl=new yi.Netmask6Impl(e,t):this._impl=new dt.Netmask4Impl(e,t),this.base=this._impl.base,this.mask=this._impl.mask,this.hostmask=this._impl.hostmask,this.bitmask=this._impl.bitmask,this.size=this._impl.size,this.first=this._impl.first,this.last=this._impl.last,this.broadcast=this._impl.broadcast,this._impl instanceof dt.Netmask4Impl?(this.maskLong=this._impl.maskLong,this.netLong=this._impl.netLong):(this.maskLong=0,this.netLong=0)}contains(e){return typeof e=="string"&&(e.indexOf("/")>0?e=new r(e):e.indexOf(":")===-1&&e.split(".").length!==4&&(e=new r(e))),e instanceof r?this.contains(e.base)&&this.contains(e.broadcast||e.last):this._impl.contains(e)}next(e=1){let t=this._impl.next(e);return new r(t.base,t.bitmask)}forEach(e){this._impl.forEach(e)}toString(){return this._impl.toString()}};ae.Netmask=Cr});var Ta={};F(Ta,{DEFAULT_ALLOW_INSECURE:()=>Je,DEFAULT_ALLOW_LOCAL:()=>Ye,DEFAULT_MAX_SIZE:()=>ln,trustlessGatewayBlockBroker:()=>Aa});var La=new Uint8Array(0);function pn(r,e){if(r===e)return!0;if(r.byteLength!==e.byteLength)return!1;for(let t=0;t<r.byteLength;t++)if(r[t]!==e[t])return!1;return!0}function R(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return fe(r);if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return fe(new Uint8Array(r.buffer,r.byteOffset,r.byteLength));throw new Error("Unknown type, must be binary type")}function mn(r){let e=new Uint8Array(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}var dn=4096;function gn(r){let e=r.length;if(e<=dn)return String.fromCharCode.apply(String,r);let t="",n=0;for(;n<e;)t+=String.fromCharCode.apply(String,r.subarray(n,n+=dn));return t}function qo(r){return r?.buffer instanceof ArrayBuffer}function fe(r){return qo(r)?r:r.slice()}var Wt={};F(Wt,{base32:()=>ie,base32hex:()=>Zo,base32hexpad:()=>ts,base32hexpadupper:()=>rs,base32hexupper:()=>es,base32pad:()=>Jo,base32padupper:()=>Yo,base32upper:()=>Ko,base32z:()=>ns});function jo(r,e,t){if(r.length>=255)throw new TypeError("Alphabet too long");for(var n=new Uint8Array(256),o=0;o<n.length;o++)n[o]=255;for(var s=0;s<r.length;s++){var i=r.charAt(s),a=i.charCodeAt(0);if(n[a]!==255)throw new TypeError(i+" is ambiguous");if(n[a]=s,t){var c=i.toLowerCase().charCodeAt(0),l=i.toUpperCase().charCodeAt(0);c!==a&&(n[c]=s),l!==a&&(n[l]=s)}}var h=r.length,d=r.charAt(0),u=Math.log(h)/Math.log(256),p=Math.log(256)/Math.log(h);function L(g){if(g instanceof Uint8Array||(ArrayBuffer.isView(g)?g=new Uint8Array(g.buffer,g.byteOffset,g.byteLength):Array.isArray(g)&&(g=Uint8Array.from(g))),!(g instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(g.length===0)return"";for(var S=0,k=0,N=0,U=g.length;N!==U&&g[N]===0;)N++,S++;for(var G=(U-N)*p+1>>>0,$=new Uint8Array(G);N!==U;){for(var Q=g[N],oe=0,B=G-1;(Q!==0||oe<k)&&B!==-1;B--,oe++)Q+=256*$[B]>>>0,$[B]=Q%h>>>0,Q=Q/h>>>0;if(Q!==0)throw new Error("Non-zero carry");k=oe,N++}for(var Z=G-k;Z!==G&&$[Z]===0;)Z++;for(var Ze=d.repeat(S);Z<G;++Z)Ze+=r.charAt($[Z]);return Ze}function O(g){if(typeof g!="string")throw new TypeError("Expected String");if(g.length===0)return new Uint8Array;var S=0;if(g[S]!==" "){for(var k=0,N=0;g[S]===d;)k++,S++;for(var U=(g.length-S)*u+1>>>0,G=new Uint8Array(U);g[S];){var $=n[g.charCodeAt(S)];if($===255)return;for(var Q=0,oe=U-1;($!==0||Q<N)&&oe!==-1;oe--,Q++)$+=h*G[oe]>>>0,G[oe]=$%256>>>0,$=$/256>>>0;if($!==0)throw new Error("Non-zero carry");N=Q,S++}if(g[S]!==" "){for(var B=U-N;B!==U&&G[B]===0;)B++;for(var Z=new Uint8Array(k+(U-B)),Ze=k;B!==U;)Z[Ze++]=G[B++];return Z}}}function x(g){var S=O(g);if(S)return S;throw new Error(`Non-${e} character`)}return{encode:L,decodeUnsafe:O,decode:x}}var Wo=jo,Ho=Wo,wn=Ho;var Mt=class{name;prefix;baseEncode;constructor(e,t,n){this.name=e,this.prefix=t,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},Vt=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,t,n){this.name=e,this.prefix=t;let o=t.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(e){if(typeof e=="string"){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(e){return xn(this,e)}},qt=class{decoders;constructor(e){this.decoders=e}or(e){return xn(this,e)}decode(e){let t=e[0],n=this.decoders[t];if(n!=null)return n.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function xn(r,e){return new qt({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}var jt=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,t,n,o){this.name=e,this.prefix=t,this.baseEncode=n,this.baseDecode=o,this.encoder=new Mt(e,t,n),this.decoder=new Vt(e,t,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function we({name:r,prefix:e,encode:t,decode:n}){return new jt(r,e,t,n)}function se({name:r,prefix:e,alphabet:t,caseInsensitive:n=!1}){let{encode:o,decode:s}=wn(t,r,n);return we({prefix:e,name:r,encode:o,decode:i=>R(s(i))})}function Go(r,e,t,n){let o=r.length;for(;r[o-1]==="=";)--o;let s=new Uint8Array(o*t/8|0),i=0,a=0,c=0;for(let l=0;l<o;++l){let h=e[r[l]];if(h===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<t|h,i+=t,i>=8&&(i-=8,s[c++]=255&a>>i)}if(i>=t||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function Qo(r,e,t){let n=e[e.length-1]==="=",o=(1<<t)-1,s="",i=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],i+=8;i>t;)i-=t,s+=e[o&a>>i];if(i!==0&&(s+=e[o&a<<t-i]),n)for(;(s.length*t&7)!==0;)s+="=";return s}function Xo(r,e){let t={};for(let n=0;n<r.length;++n)if(t[r[n]]=n,e){let o=r[n].toLowerCase(),s=r[n].toUpperCase();o!==r[n]&&(t[o]=n),s!==r[n]&&(t[s]=n)}return t}function _({name:r,prefix:e,bitsPerChar:t,alphabet:n,caseInsensitive:o=!1}){let s=Xo(n,o);return we({prefix:e,name:r,encode(i){return Qo(i,n,t)},decode(i){return Go(i,s,t,r)}})}var ie=_({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5,caseInsensitive:!0}),Ko=_({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5,caseInsensitive:!0}),Jo=_({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5,caseInsensitive:!0}),Yo=_({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5,caseInsensitive:!0}),Zo=_({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5,caseInsensitive:!0}),es=_({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5,caseInsensitive:!0}),ts=_({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5,caseInsensitive:!0}),rs=_({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5,caseInsensitive:!0}),ns=_({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Ht={};F(Ht,{base36:()=>Ne,base36upper:()=>os});var Ne=se({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz",caseInsensitive:!0}),os=se({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",caseInsensitive:!0});var Gt={};F(Gt,{base58btc:()=>X,base58flickr:()=>ss});var X=se({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),ss=se({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var is=vn,yn=128,as=127,cs=~as,us=Math.pow(2,31);function vn(r,e,t){e=e||[],t=t||0;for(var n=t;r>=us;)e[t++]=r&255|yn,r/=128;for(;r&cs;)e[t++]=r&255|yn,r>>>=7;return e[t]=r|0,vn.bytes=t-n+1,e}var ls=Qt,fs=128,En=127;function Qt(r,n){var t=0,n=n||0,o=0,s=n,i,a=r.length;do{if(s>=a)throw Qt.bytes=0,new RangeError("Could not decode varint");i=r[s++],t+=o<28?(i&En)<<o:(i&En)*Math.pow(2,o),o+=7}while(i>=fs);return Qt.bytes=s-n,t}var hs=Math.pow(2,7),ds=Math.pow(2,14),ps=Math.pow(2,21),ms=Math.pow(2,28),gs=Math.pow(2,35),bs=Math.pow(2,42),ws=Math.pow(2,49),xs=Math.pow(2,56),ys=Math.pow(2,63),Es=function(r){return r<hs?1:r<ds?2:r<ps?3:r<ms?4:r<gs?5:r<bs?6:r<ws?7:r<xs?8:r<ys?9:10},vs={encode:is,decode:ls,encodingLength:Es},_s=vs,Ue=_s;function $e(r,e=0){return[Ue.decode(r,e),Ue.decode.bytes]}function xe(r,e,t=0){return Ue.encode(r,e,t),e}function ye(r){return Ue.encodingLength(r)}function ve(r,e){let t=e.byteLength,n=ye(r),o=n+ye(t),s=new Uint8Array(o+t);return xe(r,s,0),xe(t,s,n),s.set(e,o),new Ee(r,t,e,s)}function _n(r){let e=R(r),[t,n]=$e(e),[o,s]=$e(e.subarray(n)),i=e.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new Ee(t,o,i,e)}function In(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&pn(r.bytes,t.bytes)}}var Ee=class{code;size;digest;bytes;constructor(e,t,n,o){this.code=e,this.size=t,this.digest=fe(n),this.bytes=fe(o)}};function Sn(r,e){let{bytes:t,version:n}=r;return n===0?Ss(t,Xt(r),e??X.encoder):Cs(t,Xt(r),e??ie.encoder)}var Cn=new WeakMap;function Xt(r){let e=Cn.get(r);if(e==null){let t=new Map;return Cn.set(r,t),t}return e}var K=class r{code;version;multihash;bytes;"/";constructor(e,t,n,o){this.code=t,this.version=e,this.multihash=n,this.bytes=fe(o),this["/"]=this.bytes}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:e,multihash:t}=this;if(e!==ze)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==Ps)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(t)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:e,digest:t}=this.multihash,n=ve(e,t);return r.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(e){return r.equals(this,e)}static equals(e,t){let n=t;return n!=null&&e.code===n.code&&e.version===n.version&&In(e.multihash,n.multihash)}toString(e){return Sn(this,e)}toJSON(){return{"/":Sn(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(e){if(e==null)return null;let t=e;if(t instanceof r)return t;if(t["/"]!=null&&t["/"]===t.bytes||t.asCID===t){let{version:n,code:o,multihash:s,bytes:i}=t;return new r(n,o,s,i??Pn(n,o,s.bytes))}else if(t[As]===!0){let{version:n,multihash:o,code:s}=t,i=_n(o);return r.create(n,s,i)}else return null}static create(e,t,n){if(typeof t!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(e){case 0:{if(t!==ze)throw new Error(`Version 0 CID must use dag-pb (code: ${ze}) block encoding`);return new r(e,t,n,n.bytes)}case 1:{let o=Pn(e,t,n.bytes);return new r(e,t,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return r.create(0,ze,e)}static createV1(e,t){return r.create(1,e,t)}static decode(e){let[t,n]=r.decodeFirst(e);if(n.length!==0)throw new Error("Incorrect length");return t}static decodeFirst(e){let t=r.inspectBytes(e),n=t.size-t.multihashSize,o=R(e.subarray(n,n+t.multihashSize));if(o.byteLength!==t.multihashSize)throw new Error("Incorrect length");let s=o.subarray(t.multihashSize-t.digestSize),i=new Ee(t.multihashCode,t.digestSize,s,o);return[t.version===0?r.createV0(i):r.createV1(t.codec,i),e.subarray(t.size)]}static inspectBytes(e){let t=0,n=()=>{let[d,u]=$e(e.subarray(t));return t+=u,d},o=n(),s=ze;if(o===18?(o=0,t=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=t,a=n(),c=n(),l=t+c,h=l-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:h,size:l}}static parse(e,t){let[n,o]=Is(e,t),s=r.decode(o);if(s.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Xt(s).set(n,e),s}};function Is(r,e){switch(r[0]){case"Q":{let t=e??X;return[X.prefix,t.decode(`${X.prefix}${r}`)]}case X.prefix:{let t=e??X;return[X.prefix,t.decode(r)]}case ie.prefix:{let t=e??ie;return[ie.prefix,t.decode(r)]}case Ne.prefix:{let t=e??Ne;return[Ne.prefix,t.decode(r)]}default:{if(e==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[r[0],e.decode(r)]}}}function Ss(r,e,t){let{prefix:n}=t;if(n!==X.prefix)throw Error(`Cannot string encode V0 in ${t.name} encoding`);let o=e.get(n);if(o==null){let s=t.encode(r).slice(1);return e.set(n,s),s}else return o}function Cs(r,e,t){let{prefix:n}=t,o=e.get(n);if(o==null){let s=t.encode(r);return e.set(n,s),s}else return o}var ze=112,Ps=18;function Pn(r,e,t){let n=ye(r),o=n+ye(e),s=new Uint8Array(o+t.byteLength);return xe(r,s,0),xe(e,s,n),s.set(t,o),s}var As=Symbol.for("@ipld/js-cid/CID");var Ts=20;function Jt({name:r,code:e,encode:t,minDigestLength:n,maxDigestLength:o}){return new Kt(r,e,t,n,o)}var Kt=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,t,n,o,s){this.name=e,this.code=t,this.encode=n,this.minDigestLength=o??Ts,this.maxDigestLength=s}digest(e,t){if(t?.truncate!=null){if(t.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&t.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(e instanceof Uint8Array){let n=this.encode(e);return n instanceof Uint8Array?An(n,this.code,t?.truncate):n.then(o=>An(o,this.code,t?.truncate))}else throw Error("Unknown type, must be binary type")}};function An(r,e,t){if(t!=null&&t!==r.byteLength){if(t>r.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${r.byteLength}`);r=r.subarray(0,t)}return ve(e,r)}var Zt={};F(Zt,{base64:()=>Be,base64pad:()=>Ds,base64url:()=>Yt,base64urlpad:()=>Ls});var Be=_({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Ds=_({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Yt=_({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Ls=_({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var tr={};F(tr,{identity:()=>er});var Dn=0,ks="identity",Ln=R;function Os(r,e){if(e?.truncate!=null&&e.truncate!==r.byteLength){if(e.truncate<0||e.truncate>r.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${r.byteLength}`);r=r.subarray(0,e.truncate)}return ve(Dn,Ln(r))}var er={code:Dn,name:ks,encode:Ln,digest:Os};function z(r=0){return new Uint8Array(r)}function J(r=0){return new Uint8Array(r)}function Fs(r){return r?.buffer instanceof ArrayBuffer}function rr(r){if(Fs(r))return r;let e=r.slice();return new Uint8Array(e.buffer,0,e.byteLength)}function ee(r,e){e==null&&(e=r.reduce((o,s)=>o+s.length,0));let t=J(e),n=0;for(let o of r)t.set(o,n),n+=o.length;return rr(t)}function he(r,e){if(r===e)return!0;if(r.byteLength!==e.byteLength)return!1;for(let t=0;t<r.byteLength;t++)if(r[t]!==e[t])return!1;return!0}var On=Symbol.for("@achingbrain/uint8arraylist");function kn(r,e){if(e==null||e<0)throw new RangeError("index is out of bounds");let t=0;for(let n of r){let o=t+n.byteLength;if(e<o)return{buf:n,index:e-t};t=o}throw new RangeError("index is out of bounds")}function rt(r){return!!r?.[On]}var nt=class r{bufs;length;[On]=!0;constructor(...e){this.bufs=[],this.length=0,e.length>0&&this.appendAll(e)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...e){this.appendAll(e)}appendAll(e){let t=0;for(let n of e)if(n instanceof Uint8Array)t+=n.byteLength,this.bufs.push(n);else if(rt(n)){t+=n.byteLength;for(let o of n.bufs)this.bufs.push(o)}else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=t}prepend(...e){this.prependAll(e)}prependAll(e){let t=0;for(let n of e.reverse())if(n instanceof Uint8Array)t+=n.byteLength,this.bufs.unshift(n);else if(rt(n))t+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=t}get(e){let t=kn(this.bufs,e);return t.buf[t.index]}set(e,t){let n=kn(this.bufs,e);n.buf[n.index]=t}write(e,t=0){if(e instanceof Uint8Array)for(let n=0;n<e.length;n++)this.set(t+n,e[n]);else if(rt(e))for(let n=0;n<e.length;n++)this.set(t+n,e.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(e){if(e=Math.trunc(e),!(Number.isNaN(e)||e<=0)){if(e===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(e>=this.bufs[0].byteLength)e-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(e),this.length-=e;break}}}slice(e,t){let{bufs:n,length:o}=this._subList(e,t);return ee(n,o)}subarray(e,t){let{bufs:n,length:o}=this._subList(e,t);return n.length===1?n[0]:ee(n,o)}sublist(e,t){let{bufs:n,length:o}=this._subList(e,t),s=new r;return s.length=o,s.bufs=n,s}_subList(e,t){if(e=e??0,t=t??this.length,e<0&&(e=this.length+e),t<0&&(t=this.length+t),e<0||t>this.length)throw new RangeError("index is out of bounds");if(e===t)return{bufs:[],length:0};if(e===0&&t===this.length)return{bufs:[...this.bufs],length:this.length};let n=[],o=0;for(let s=0;s<this.bufs.length;s++){let i=this.bufs[s],a=o,c=a+i.byteLength;if(o=c,e>=c)continue;let l=e>=a&&e<c,h=t>a&&t<=c;if(l&&h){if(e===a&&t===c){n.push(i);break}let d=e-a;n.push(i.subarray(d,d+(t-e)));break}if(l){if(e===0){n.push(i);continue}n.push(i.subarray(e-a));continue}if(h){if(t===c){n.push(i);break}n.push(i.subarray(0,t-a));break}n.push(i)}return{bufs:n,length:t-e}}indexOf(e,t=0){if(!rt(e)&&!(e instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=e instanceof Uint8Array?e:e.subarray();if(t=Number(t??0),isNaN(t)&&(t=0),t<0&&(t=this.length+t),t<0&&(t=0),e.length===0)return t>this.length?this.length:t;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let s=256,i=new Int32Array(s);for(let d=0;d<s;d++)i[d]=-1;for(let d=0;d<o;d++)i[n[d]]=d;let a=i,c=this.byteLength-n.byteLength,l=n.byteLength-1,h;for(let d=t;d<=c;d+=h){h=0;for(let u=l;u>=0;u--){let p=this.get(d+u);if(n[u]!==p){h=Math.max(1,u-a[p]);break}}if(h===0)return d}return-1}getInt8(e){let t=this.subarray(e,e+1);return new DataView(t.buffer,t.byteOffset,t.byteLength).getInt8(0)}setInt8(e,t){let n=J(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,t),this.write(n,e)}getInt16(e,t){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,t)}setInt16(e,t,n){let o=z(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,t,n),this.write(o,e)}getInt32(e,t){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,t)}setInt32(e,t,n){let o=z(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,t,n),this.write(o,e)}getBigInt64(e,t){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,t)}setBigInt64(e,t,n){let o=z(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,t,n),this.write(o,e)}getUint8(e){let t=this.subarray(e,e+1);return new DataView(t.buffer,t.byteOffset,t.byteLength).getUint8(0)}setUint8(e,t){let n=J(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,t),this.write(n,e)}getUint16(e,t){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,t)}setUint16(e,t,n){let o=z(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,t,n),this.write(o,e)}getUint32(e,t){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,t)}setUint32(e,t,n){let o=z(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,t,n),this.write(o,e)}getBigUint64(e,t){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,t)}setBigUint64(e,t,n){let o=z(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,t,n),this.write(o,e)}getFloat32(e,t){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,t)}setFloat32(e,t,n){let o=z(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,t,n),this.write(o,e)}getFloat64(e,t){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,t)}setFloat64(e,t,n){let o=z(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,t,n),this.write(o,e)}equals(e){if(e==null||!(e instanceof r)||e.bufs.length!==this.bufs.length)return!1;for(let t=0;t<this.bufs.length;t++)if(!he(this.bufs[t],e.bufs[t]))return!1;return!0}static fromUint8Arrays(e,t){let n=new r;return n.bufs=e,t==null&&(t=e.reduce((o,s)=>o+s.byteLength,0)),n.length=t,n}};function Ns(r){return r.buffer instanceof ArrayBuffer}function nr(r){return Ns(r)?r:r.slice()}var Us=Math.pow(2,7),$s=Math.pow(2,14),Rs=Math.pow(2,21),or=Math.pow(2,28),sr=Math.pow(2,35),ir=Math.pow(2,42),ar=Math.pow(2,49),v=128,T=127;function _e(r){if(r<Us)return 1;if(r<$s)return 2;if(r<Rs)return 3;if(r<or)return 4;if(r<sr)return 5;if(r<ir)return 6;if(r<ar)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function cr(r,e,t=0){switch(_e(r)){case 8:e[t++]=r&255|v,r/=128;case 7:e[t++]=r&255|v,r/=128;case 6:e[t++]=r&255|v,r/=128;case 5:e[t++]=r&255|v,r/=128;case 4:e[t++]=r&255|v,r>>>=7;case 3:e[t++]=r&255|v,r>>>=7;case 2:e[t++]=r&255|v,r>>>=7;case 1:{e[t++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return e}function zs(r,e){let t=r[e],n=0;if(n+=t&T,t<v||(t=r[e+1],n+=(t&T)<<7,t<v)||(t=r[e+2],n+=(t&T)<<14,t<v)||(t=r[e+3],n+=(t&T)<<21,t<v)||(t=r[e+4],n+=(t&T)*or,t<v)||(t=r[e+5],n+=(t&T)*sr,t<v)||(t=r[e+6],n+=(t&T)*ir,t<v)||(t=r[e+7],n+=(t&T)*ar,t<v))return n;throw new RangeError("Could not decode varint")}function Bs(r,e){let t=r.get(e),n=0;if(n+=t&T,t<v||(t=r.get(e+1),n+=(t&T)<<7,t<v)||(t=r.get(e+2),n+=(t&T)<<14,t<v)||(t=r.get(e+3),n+=(t&T)<<21,t<v)||(t=r.get(e+4),n+=(t&T)*or,t<v)||(t=r.get(e+5),n+=(t&T)*sr,t<v)||(t=r.get(e+6),n+=(t&T)*ir,t<v)||(t=r.get(e+7),n+=(t&T)*ar,t<v))return n;throw new RangeError("Could not decode varint")}function ur(r,e=0){return r instanceof Uint8Array?zs(r,e):Bs(r,e)}var lr={};F(lr,{base10:()=>Vs});var Vs=se({prefix:"9",name:"base10",alphabet:"0123456789"});var fr={};F(fr,{base16:()=>qs,base16upper:()=>js});var qs=_({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4,caseInsensitive:!0}),js=_({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4,caseInsensitive:!0});var hr={};F(hr,{base2:()=>Ws});var Ws=_({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var dr={};F(dr,{base256emoji:()=>Ks});var Fn=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}"),Hs=Fn.reduce((r,e,t)=>(r[t]=e,r),[]),Gs=Fn.reduce((r,e,t)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return r[n]=t,r},[]);function Qs(r){return r.reduce((e,t)=>(e+=Hs[t],e),"")}function Xs(r){let e=[];for(let t of r){let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);let o=Gs[n];if(o==null)throw new Error(`Non-base256emoji character: ${t}`);e.push(o)}return new Uint8Array(e)}var Ks=we({prefix:"\u{1F680}",name:"base256emoji",encode:Qs,decode:Xs});var pr={};F(pr,{base8:()=>Js});var Js=_({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var mr={};F(mr,{identity:()=>Ys});var Ys=we({prefix:"\0",name:"identity",encode:r=>gn(R(r)),decode:r=>R(mn(r))});var _c=new TextEncoder,Ic=new TextDecoder;var gr={};F(gr,{sha256:()=>ti,sha512:()=>ri});function Nn(r){return async e=>new Uint8Array(await crypto.subtle.digest(r,e))}var ti=Jt({name:"sha2-256",code:18,encode:Nn("SHA-256")}),ri=Jt({name:"sha2-512",code:19,encode:Nn("SHA-512")});var Me={...mr,...hr,...pr,...lr,...fr,...Wt,...Ht,...Gt,...Zt,...dr},Ac={...gr,...tr};function $n(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}var Un=$n("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),br=$n("ascii","a",r=>{let e="a";for(let t=0;t<r.length;t++)e+=String.fromCharCode(r[t]);return e},r=>{r=r.substring(1);let e=J(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),ni={utf8:Un,"utf-8":Un,hex:Me.base16,latin1:br,ascii:br,binary:br,...Me},ot=ni;function C(r,e="utf8"){let t=ot[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.decoder.decode(`${t.prefix}${r}`)}var st=class extends Error{static name="InsufficientProvidersError";constructor(e="Insufficient providers found"){super(e),this.name="InsufficientProvidersError"}};var M=class extends Error{static name="AbortError";constructor(e="The operation was aborted"){super(e),this.name="AbortError"}};var it=class extends Error{static name="InvalidParametersError";constructor(e="Invalid parameters"){super(e),this.name="InvalidParametersError"}};function oi(r){return typeof r?.handleEvent=="function"}function si(r){return(r!==!0&&r!==!1&&r?.once)??!1}var Ie=class extends EventTarget{#e=new Map;constructor(){super()}listenerCount(e){let t=this.#e.get(e);return t==null?0:t.length}addEventListener(e,t,n){let o=si(n);super.addEventListener(e,i=>{if(o){let a=this.#e.get(i.type);a!=null&&(a=a.filter(({callback:c})=>c!==t),this.#e.set(i.type,a))}oi(t)?t.handleEvent(i):t(i)},n);let s=this.#e.get(e);s==null&&(s=[],this.#e.set(e,s)),s.push({callback:t,once:o})}removeEventListener(e,t,n){super.removeEventListener(e.toString(),t??null,n);let o=this.#e.get(e);o!=null&&(o=o.filter(({callback:s})=>s!==t),this.#e.set(e,o))}safeDispatchEvent(e,t={}){return this.dispatchEvent(new CustomEvent(e,t))}};var wr={32:16777619n,64:1099511628211n,128:309485009821345068724781371n,256:374144419156711147060143317175368453031918731002211n,512:35835915874844867368919076489095108449946327955754392558399825615420669938882575126094039892345713852759n,1024:5016456510113118655434598811035278955030765345404790744303017523831112055108147451509157692220295382716162651878526895249385292291816524375083746691371804094271873160484737966720260389217684476157468082573n},Rn={32:2166136261n,64:14695981039346656037n,128:144066263297769815596495629667062367629n,256:100029257958052580907070968620625704837092796014241193945225284501741471925557n,512:9659303129496669498009435400716310466090418745672637896108374329434462657994582932197716438449813051892206539805784495328239340083876191928701583869517785n,1024:14197795064947621068722070641403218320880622795441933960878474914617582723252296732303717722150864096521202355549365628174669108571814760471015076148029755969804077320157692458563003215304957150157403644460363550505412711285966361610267868082893823963790439336411086884584107735010676915n},zn=new globalThis.TextEncoder;function ii(r,e){let t=wr[e],n=Rn[e];for(let o=0;o<r.length;o++)n^=BigInt(r[o]),n=BigInt.asUintN(e,n*t);return n}function ai(r,e,t){if(t.length===0)throw new Error("The `utf8Buffer` option must have a length greater than zero");let n=wr[e],o=Rn[e],s=r;for(;s.length>0;){let i=zn.encodeInto(s,t);s=s.slice(i.read);for(let a=0;a<i.written;a++)o^=BigInt(t[a]),o=BigInt.asUintN(e,o*n)}return o}function xr(r,{size:e=32,utf8Buffer:t}={}){if(!wr[e])throw new Error("The `size` option must be one of 32, 64, 128, 256, 512, or 1024");if(typeof r=="string"){if(t)return ai(r,e,t);r=zn.encode(r)}return ii(r,e)}var Ve={hash:r=>Number(xr(r,{size:32})),hashV:(r,e)=>ci(Ve.hash(r,e))};function ci(r){let e=r.toString(16);return e.length%2===1&&(e=`0${e}`),C(e,"base16")}var yr=64,V=class{fp;h;seed;constructor(e,t,n,o=2){if(o>yr)throw new TypeError("Invalid Fingerprint Size");let s=t.hashV(e,n),i=z(o);for(let a=0;a<i.length;a++)i[a]=s[a];i.length===0&&(i[0]=7),this.fp=i,this.h=t,this.seed=n}hash(){return this.h.hash(this.fp,this.seed)}equals(e){return e?.fp instanceof Uint8Array?he(this.fp,e.fp):!1}};function de(r,e){return Math.floor(Math.random()*(e-r))+r}var pe=class{contents;constructor(e){this.contents=new Array(e).fill(null)}has(e){if(!(e instanceof V))throw new TypeError("Invalid Fingerprint");return this.contents.some(t=>e.equals(t))}add(e){if(!(e instanceof V))throw new TypeError("Invalid Fingerprint");for(let t=0;t<this.contents.length;t++)if(this.contents[t]==null)return this.contents[t]=e,!0;return!0}swap(e){if(!(e instanceof V))throw new TypeError("Invalid Fingerprint");let t=de(0,this.contents.length-1),n=this.contents[t];return this.contents[t]=e,n}remove(e){if(!(e instanceof V))throw new TypeError("Invalid Fingerprint");let t=this.contents.findIndex(n=>e.equals(n));return t>-1?(this.contents[t]=null,!0):!1}};var ui=500,qe=class{bucketSize;filterSize;fingerprintSize;buckets;count;hash;seed;constructor(e){this.filterSize=e.filterSize,this.bucketSize=e.bucketSize??4,this.fingerprintSize=e.fingerprintSize??2,this.count=0,this.buckets=[],this.hash=e.hash??Ve,this.seed=e.seed??de(0,Math.pow(2,10))}add(e){typeof e=="string"&&(e=C(e));let t=new V(e,this.hash,this.seed,this.fingerprintSize),n=this.hash.hash(e,this.seed)%this.filterSize,o=(n^t.hash())%this.filterSize;if(this.buckets[n]==null&&(this.buckets[n]=new pe(this.bucketSize)),this.buckets[o]==null&&(this.buckets[o]=new pe(this.bucketSize)),this.buckets[n].add(t)||this.buckets[o].add(t))return this.count++,!0;let s=[n,o],i=s[de(0,s.length-1)];this.buckets[i]==null&&(this.buckets[i]=new pe(this.bucketSize));for(let a=0;a<ui;a++){let c=this.buckets[i].swap(t);if(c!=null&&(i=(i^c.hash())%this.filterSize,this.buckets[i]==null&&(this.buckets[i]=new pe(this.bucketSize)),this.buckets[i].add(c)))return this.count++,!0}return!1}has(e){typeof e=="string"&&(e=C(e));let t=new V(e,this.hash,this.seed,this.fingerprintSize),n=this.hash.hash(e,this.seed)%this.filterSize,o=this.buckets[n]?.has(t)??!1;if(o)return o;let s=(n^t.hash())%this.filterSize;return this.buckets[s]?.has(t)??!1}remove(e){typeof e=="string"&&(e=C(e));let t=new V(e,this.hash,this.seed,this.fingerprintSize),n=this.hash.hash(e,this.seed)%this.filterSize,o=this.buckets[n]?.remove(t)??!1;if(o)return this.count--,o;let s=(n^t.hash())%this.filterSize,i=this.buckets[s]?.remove(t)??!1;return i&&this.count--,i}get reliable(){return Math.floor(100*(this.count/this.filterSize))<=90}},li={1:.5,2:.84,4:.95,8:.98};function fi(r=.001){return r>.002?2:r>1e-5?4:8}function Bn(r,e=.001){let t=fi(e),n=li[t],o=Math.round(r/n),s=Math.min(Math.ceil(Math.log2(1/e)+Math.log2(2*t)),yr);return{filterSize:o,bucketSize:t,fingerprintSize:s}}var at=class{filterSize;bucketSize;fingerprintSize;scale;filterSeries;hash;seed;constructor(e){this.bucketSize=e.bucketSize??4,this.filterSize=e.filterSize??(1<<18)/this.bucketSize,this.fingerprintSize=e.fingerprintSize??2,this.scale=e.scale??2,this.hash=e.hash??Ve,this.seed=e.seed??de(0,Math.pow(2,10)),this.filterSeries=[new qe({filterSize:this.filterSize,bucketSize:this.bucketSize,fingerprintSize:this.fingerprintSize,hash:this.hash,seed:this.seed})]}add(e){if(typeof e=="string"&&(e=C(e)),this.has(e))return!0;let t=this.filterSeries.find(n=>n.reliable);if(t==null){let n=this.filterSize*Math.pow(this.scale,this.filterSeries.length);t=new qe({filterSize:n,bucketSize:this.bucketSize,fingerprintSize:this.fingerprintSize,hash:this.hash,seed:this.seed}),this.filterSeries.push(t)}return t.add(e)}has(e){typeof e=="string"&&(e=C(e));for(let t=0;t<this.filterSeries.length;t++)if(this.filterSeries[t].has(e))return!0;return!1}remove(e){typeof e=="string"&&(e=C(e));for(let t=0;t<this.filterSeries.length;t++)if(this.filterSeries[t].remove(e))return!0;return!1}get count(){return this.filterSeries.reduce((e,t)=>e+t.count,0)}};function ct(r,e=.001,t){return new at({...Bn(r,e),...t??{}})}function hi(r){let e=r.getComponents(),t={},n=0;return e[n]?.name==="ip6zone"&&(t.zone=`${e[n].value}`,n++),e[n]?.name==="ip4"||e[n]?.name==="ip6"||e[n]?.name==="dns"||e[n]?.name==="dns4"||e[n]?.name==="dns6"?(t.type=e[n].name,t.host=e[n].value,n++):e[n]?.name==="dnsaddr"&&(t.type=e[n].name,t.host=`_dnsaddr.${e[n].value}`,n++),(e[n]?.name==="tcp"||e[n]?.name==="udp")&&(t.protocol=e[n].name==="tcp"?"tcp":"udp",t.port=parseInt(`${e[n].value}`),n++),e[n]?.name==="ipcidr"&&(t.type==="ip4"?t.cidr=parseInt(`${e[n].value}`):t.type==="ip6"&&(t.cidr=`${e[n].value}`),n++),t.type==null||t.host==null?null:(e[n]?.name==="tls"&&e[n+1]?.name==="sni"&&(t.sni=e[n+1].value,n+=2),t)}function ut(r){let e=hi(r);if(e==null)throw new it(`Multiaddr ${r} was not an IPv4, IPv6, DNS, DNS4, DNS6 or DNSADDR address`);return e}var lt=class{index=0;input="";new(e){return this.index=0,this.input=e,this}readAtomically(e){let t=this.index,n=e();return n===void 0&&(this.index=t),n}parseWith(e){let t=e();if(this.index===this.input.length)return t}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(e){return this.readAtomically(()=>{let t=this.readChar();if(t===e)return t})}readSeparator(e,t,n){return this.readAtomically(()=>{if(!(t>0&&this.readGivenChar(e)===void 0))return n()})}readNumber(e,t,n,o){return this.readAtomically(()=>{let s=0,i=0,a=this.peekChar();if(a===void 0)return;let c=a==="0",l=2**(8*o)-1;for(;;){let h=this.readAtomically(()=>{let d=this.readChar();if(d===void 0)return;let u=Number.parseInt(d,e);if(!Number.isNaN(u))return u});if(h===void 0)break;if(s*=e,s+=h,s>l||(i+=1,t!==void 0&&i>t))return}if(i!==0)return!n&&c&&i>1?void 0:s})}readIPv4Addr(){return this.readAtomically(()=>{let e=new Uint8Array(4);for(let t=0;t<e.length;t++){let n=this.readSeparator(".",t,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;e[t]=n}return e})}readIPv6Addr(){let e=t=>{for(let n=0;n<t.length/2;n++){let o=n*2;if(n<t.length-3){let i=this.readSeparator(":",n,()=>this.readIPv4Addr());if(i!==void 0)return t[o]=i[0],t[o+1]=i[1],t[o+2]=i[2],t[o+3]=i[3],[o+4,!0]}let s=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(s===void 0)return[o,!1];t[o]=s>>8,t[o+1]=s&255}return[t.length,!1]};return this.readAtomically(()=>{let t=new Uint8Array(16),[n,o]=e(t);if(n===16)return t;if(o||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let s=new Uint8Array(14),i=16-(n+2),[a]=e(s.subarray(0,i));return t.set(s.subarray(0,a),16-a),t})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var di=45,pi=15,ft=new lt;function Mn(r){if(!(r.length>pi))return ft.new(r).parseWith(()=>ft.readIPv4Addr())}function Vn(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>di))return ft.new(r).parseWith(()=>ft.readIPv6Addr())}function Se(r){return!!Mn(r)}function ht(r){return!!Vn(r)}var Hn=Mo(Wn(),1),Ei=["0.0.0.0/8","10.0.0.0/8","100.64.0.0/10","127.0.0.0/8","169.254.0.0/16","172.16.0.0/12","192.0.0.0/24","192.0.0.0/29","192.0.0.8/32","192.0.0.9/32","192.0.0.10/32","192.0.0.170/32","192.0.0.171/32","192.0.2.0/24","192.31.196.0/24","192.52.193.0/24","192.88.99.0/24","192.168.0.0/16","192.175.48.0/24","198.18.0.0/15","198.51.100.0/24","203.0.113.0/24","240.0.0.0/4","255.255.255.255/32"],vi=Ei.map(r=>new Hn.Netmask(r));function Pr(r){for(let e of vi)if(e.contains(r))return!0;return!1}function _i(r){return/^::ffff:([0-9a-fA-F]{1,4}):([0-9a-fA-F]{1,4})$/.test(r)}function Ii(r){let e=r.split(":");if(e.length<2)return!1;let t=e[e.length-1].padStart(4,"0"),n=e[e.length-2].padStart(4,"0"),o=`${parseInt(n.substring(0,2),16)}.${parseInt(n.substring(2),16)}.${parseInt(t.substring(0,2),16)}.${parseInt(t.substring(2),16)}`;return Pr(o)}function Si(r){return/^::ffff:([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(r)}function Ci(r){let e=r.split(":"),t=e[e.length-1];return Pr(t)}function Pi(r){return/^::$/.test(r)||/^::1$/.test(r)||/^64:ff9b::([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(r)||/^100::([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^2001::([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^2001:2[0-9a-fA-F]:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^2001:db8:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^2002:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^f[c-d]([0-9a-fA-F]{2,2}):/i.test(r)||/^fe[8-9a-bA-B][0-9a-fA-F]:/i.test(r)||/^ff([0-9a-fA-F]{2,2}):/i.test(r)}function Gn(r){if(Se(r))return Pr(r);if(_i(r))return Ii(r);if(Si(r))return Ci(r);if(ht(r))return Pi(r)}function Qn(r){try{let e=ut(r);switch(e.type){case"ip4":case"ip6":return Gn(e.host)??!1;default:return e.host==="localhost"}}catch{return!1}}function ce(r,e="utf8"){let t=ot[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.encoder.encode(r).substring(1)}var A=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},te=class extends Error{static name="ValidationError";name="ValidationError"},pt=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},mt=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};function Tr(r){return e=>ce(e,r)}function Dr(r){return e=>C(e,r)}function Te(r){return new DataView(r.buffer).getUint16(r.byteOffset).toString()}function ge(r){let e=new ArrayBuffer(2);return new DataView(e).setUint16(0,typeof r=="string"?parseInt(r):r),new Uint8Array(e)}function Xn(r){let e=r.split(":");if(e.length!==2)throw new Error(`failed to parse onion addr: ["'${e.join('", "')}'"]' does not contain a port number`);if(e[0].length!==16)throw new Error(`failed to parse onion addr: ${e[0]} not a Tor onion address.`);let t=C(e[0],"base32"),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=ge(n);return ee([t,o],t.length+o.length)}function Kn(r){let e=r.split(":");if(e.length!==2)throw new Error(`failed to parse onion addr: ["'${e.join('", "')}'"]' does not contain a port number`);if(e[0].length!==56)throw new Error(`failed to parse onion addr: ${e[0]} not a Tor onion3 address.`);let t=ie.decode(`b${e[0]}`),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=ge(n);return ee([t,o],t.length+o.length)}function Lr(r){let e=r.subarray(0,r.length-2),t=r.subarray(r.length-2),n=ce(e,"base32"),o=Te(t);return`${n}:${o}`}var kr=function(r){r=r.toString().trim();let e=new Uint8Array(4);return r.split(/\./g).forEach((t,n)=>{let o=parseInt(t,10);if(isNaN(o)||o<0||o>255)throw new A("Invalid byte value in IP address");e[n]=o}),e},Jn=function(r){let e=0;r=r.toString().trim();let t=r.split(":",8),n;for(n=0;n<t.length;n++){let s=Se(t[n]),i;s&&(i=kr(t[n]),t[n]=ce(i.subarray(0,2),"base16")),i!=null&&++n<8&&t.splice(n,0,ce(i.subarray(2,4),"base16"))}if(t[0]==="")for(;t.length<8;)t.unshift("0");else if(t[t.length-1]==="")for(;t.length<8;)t.push("0");else if(t.length<8){for(n=0;n<t.length&&t[n]!=="";n++);let s=[n,1];for(n=9-t.length;n>0;n--)s.push("0");t.splice.apply(t,s)}let o=new Uint8Array(e+16);for(n=0;n<t.length;n++){t[n]===""&&(t[n]="0");let s=parseInt(t[n],16);if(isNaN(s)||s<0||s>65535)throw new A("Invalid byte value in IP address");o[e++]=s>>8&255,o[e++]=s&255}return o},Yn=function(r){if(r.byteLength!==4)throw new A("IPv4 address was incorrect length");let e=[];for(let t=0;t<r.byteLength;t++)e.push(r[t]);return e.join(".")},Zn=function(r){if(r.byteLength!==16)throw new A("IPv6 address was incorrect length");let e=[];for(let n=0;n<r.byteLength;n+=2){let o=r[n],s=r[n+1],i=`${o.toString(16).padStart(2,"0")}${s.toString(16).padStart(2,"0")}`;e.push(i)}let t=e.join(":");try{let n=new URL(`http://[${t}]`);return n.hostname.substring(1,n.hostname.length-1)}catch{throw new A(`Invalid IPv6 address "${t}"`)}};function eo(r){try{let e=new URL(`http://[${r}]`);return e.hostname.substring(1,e.hostname.length-1)}catch{throw new A(`Invalid IPv6 address "${r}"`)}}var Ar=Object.values(Me).map(r=>r.decoder),Ai=(function(){let r=Ar[0].or(Ar[1]);return Ar.slice(2).forEach(e=>r=r.or(e)),r})();function to(r){return Ai.decode(r)}function ro(r){return e=>r.encoder.encode(e)}function Ti(r){if(parseInt(r).toString()!==r)throw new te("Value must be an integer")}function Di(r){if(r<0)throw new te("Value must be a positive integer, or zero")}function Li(r){return e=>{if(e>r)throw new te(`Value must be smaller than or equal to ${r}`)}}function ki(...r){return e=>{for(let t of r)t(e)}}var je=ki(Ti,Di,Li(65535));var P=-1,Or=class{protocolsByCode=new Map;protocolsByName=new Map;getProtocol(e){let t;if(typeof e=="string"?t=this.protocolsByName.get(e):t=this.protocolsByCode.get(e),t==null)throw new mt(`Protocol ${e} was unknown`);return t}addProtocol(e){this.protocolsByCode.set(e.code,e),this.protocolsByName.set(e.name,e),e.aliases?.forEach(t=>{this.protocolsByName.set(t,e)})}removeProtocol(e){let t=this.protocolsByCode.get(e);t!=null&&(this.protocolsByCode.delete(t.code),this.protocolsByName.delete(t.name),t.aliases?.forEach(n=>{this.protocolsByName.delete(n)}))}},re=new Or,Hi=[{code:4,name:"ip4",size:32,valueToBytes:kr,bytesToValue:Yn,validate:r=>{if(!Se(r))throw new te(`Invalid IPv4 address "${r}"`)}},{code:6,name:"tcp",size:16,valueToBytes:ge,bytesToValue:Te,validate:je},{code:273,name:"udp",size:16,valueToBytes:ge,bytesToValue:Te,validate:je},{code:33,name:"dccp",size:16,valueToBytes:ge,bytesToValue:Te,validate:je},{code:41,name:"ip6",size:128,valueToBytes:Jn,bytesToValue:Zn,stringToValue:eo,validate:r=>{if(!ht(r))throw new te(`Invalid IPv6 address "${r}"`)}},{code:42,name:"ip6zone",size:P},{code:43,name:"ipcidr",size:8,bytesToValue:Tr("base10"),valueToBytes:Dr("base10")},{code:53,name:"dns",size:P},{code:54,name:"dns4",size:P},{code:55,name:"dns6",size:P},{code:56,name:"dnsaddr",size:P},{code:132,name:"sctp",size:16,valueToBytes:ge,bytesToValue:Te,validate:je},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:P,stringToValue:r=>decodeURIComponent(r),valueToString:r=>encodeURIComponent(r)},{code:421,name:"p2p",aliases:["ipfs"],size:P,bytesToValue:Tr("base58btc"),valueToBytes:r=>r.startsWith("Q")||r.startsWith("1")?Dr("base58btc")(r):K.parse(r).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:Lr,valueToBytes:Xn},{code:445,name:"onion3",size:296,bytesToValue:Lr,valueToBytes:Kn},{code:446,name:"garlic64",size:P},{code:447,name:"garlic32",size:P},{code:448,name:"tls"},{code:449,name:"sni",size:P},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:P,bytesToValue:ro(Yt),valueToBytes:to},{code:480,name:"http"},{code:481,name:"http-path",size:P,stringToValue:r=>`/${decodeURIComponent(r)}`,valueToString:r=>encodeURIComponent(r.substring(1))},{code:443,name:"https"},{code:477,name:"ws"},{code:478,name:"wss"},{code:479,name:"p2p-websocket-star"},{code:277,name:"p2p-stardust"},{code:275,name:"p2p-webrtc-star"},{code:276,name:"p2p-webrtc-direct"},{code:280,name:"webrtc-direct"},{code:281,name:"webrtc"},{code:290,name:"p2p-circuit"},{code:777,name:"memory",size:P}];Hi.forEach(r=>{re.addProtocol(r)});function no(r){let e=[],t=0;for(;t<r.length;){let n=ur(r,t),o=re.getProtocol(n),s=_e(n),i=Gi(o,r,t+s),a=0;i>0&&o.size===P&&(a=_e(i));let c=s+a+i,l={code:n,name:o.name,bytes:nr(r.subarray(t,t+c))};if(i>0){let h=t+s+a,d=r.subarray(h,h+i);l.value=o.bytesToValue?.(d)??ce(d)}e.push(l),t+=c}return e}function oo(r){let e=0,t=[];for(let n of r){if(n.bytes==null){let o=re.getProtocol(n.code),s=_e(n.code),i,a=0,c=0;n.value!=null&&(i=o.valueToBytes?.(n.value)??C(n.value),a=i.byteLength,o.size===P&&(c=_e(a)));let l=new Uint8Array(s+c+a),h=0;cr(n.code,l,h),h+=s,i!=null&&(o.size===P&&(cr(a,l,h),h+=c),l.set(i,h)),n.bytes=l}t.push(n.bytes),e+=n.bytes.byteLength}return ee(t,e)}function so(r){if(r.charAt(0)!=="/")throw new A('String multiaddr must start with "/"');let e=[],t="protocol",n="",o="";for(let s=1;s<r.length;s++){let i=r.charAt(s);i!=="/"&&(t==="protocol"?o+=r.charAt(s):n+=r.charAt(s));let a=s===r.length-1;if(i==="/"||a){let c=re.getProtocol(o);if(t==="protocol"){if(c.size==null||c.size===0){e.push({code:c.code,name:c.name}),n="",o="",t="protocol";continue}else if(a)throw new A(`Component ${o} was missing value`);t="value"}else if(t==="value"){let l={code:c.code,name:c.name};if(c.size!=null&&c.size!==0){if(n==="")throw new A(`Component ${o} was missing value`);l.value=c.stringToValue?.(n)??n}e.push(l),n="",o="",t="protocol"}}}if(o!==""&&n!=="")throw new A("Incomplete multiaddr");return e}function io(r){return`/${r.flatMap(e=>{if(e.value==null)return e.name;let t=re.getProtocol(e.code);if(t==null)throw new A(`Unknown protocol code ${e.code}`);return[e.name,t.valueToString?.(e.value)??e.value]}).join("/")}`}function Gi(r,e,t){return r.size==null||r.size===0?0:r.size>0?r.size/8:ur(e,t)}var Qi=Symbol.for("nodejs.util.inspect.custom"),Wr=Symbol.for("@multiformats/multiaddr");function Xi(r){if(r==null&&(r="/"),ao(r))return r.getComponents();if(r instanceof Uint8Array)return no(r);if(typeof r=="string")return r=r.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),r===""&&(r="/"),so(r);if(Array.isArray(r))return r;throw new A("Must be a string, Uint8Array, Component[], or another Multiaddr")}var Et=class r{[Wr]=!0;#e;#t;#r;constructor(e="/",t={}){this.#e=Xi(e),t.validate!==!1&&Ki(this)}get bytes(){return this.#r==null&&(this.#r=oo(this.#e)),this.#r}toString(){return this.#t==null&&(this.#t=io(this.#e)),this.#t}toJSON(){return this.toString()}getComponents(){return[...this.#e.map(e=>({...e}))]}encapsulate(e){let t=new r(e);return new r([...this.#e,...t.getComponents()],{validate:!1})}decapsulate(e){let t=e.toString(),n=this.toString(),o=n.lastIndexOf(t);if(o<0)throw new pt(`Address ${this.toString()} does not contain subaddress: ${t}`);return new r(n.slice(0,o),{validate:!1})}decapsulateCode(e){let t;for(let n=this.#e.length-1;n>-1;n--)if(this.#e[n].code===e){t=n;break}return new r(this.#e.slice(0,t),{validate:!1})}equals(e){return he(this.bytes,e.bytes)}[Qi](){return`Multiaddr(${this.toString()})`}};function Ki(r){r.getComponents().forEach(e=>{let t=re.getProtocol(e.code);e.value!=null&&t.validate?.(e.value)})}function ao(r){return!!r?.[Wr]}function vt(r){return new Et(r)}var y=r=>({match:e=>{let t=e[0];return t==null||t.code!==r||t.value!=null?!1:e.slice(1)}}),f=(r,e)=>({match:t=>{let n=t[0];return n?.code!==r||n.value==null||e!=null&&n.value!==e?!1:t.slice(1)}}),co=r=>({match:e=>r.match(e)===!1?e:!1}),m=r=>({match:e=>{let t=r.match(e);return t===!1?e:t}}),D=(...r)=>({match:e=>{let t;for(let n of r){let o=n.match(e);o!==!1&&(t==null||o.length<t.length)&&(t=o)}return t??!1}}),b=(...r)=>({match:e=>{for(let t of r){let n=t.match(e);if(n===!1)return!1;e=n}return e}});function E(...r){function e(o){if(o==null)return!1;let s=o.getComponents();for(let i of r){let a=i.match(s);if(a===!1)return!1;s=a}return s}function t(o){return e(o)!==!1}function n(o){let s=e(o);return s===!1?!1:s.length===0}return{matchers:r,matches:t,exactMatch:n}}var Ji=f(421),Dl=E(Ji),It=f(54),St=f(55),Ct=f(56),Gr=f(53),Ll=E(It,m(f(421))),kl=E(St,m(f(421))),Ol=E(Ct,m(f(421))),uo=E(D(Gr,Ct,It,St),m(f(421))),lo=b(f(4),m(f(43))),fo=b(m(f(42)),f(41),m(f(43))),Qr=D(lo,fo),ke=D(Qr,Gr,It,St,Ct),Fl=E(D(Qr,b(D(Gr,Ct,It,St),m(f(421))))),Nl=E(lo),Ul=E(fo),$l=E(Qr),Xr=b(ke,f(6)),Ke=b(ke,f(273)),Rl=E(b(Xr,m(f(421)))),zl=E(Ke),Kr=b(Ke,y(460),m(f(421))),Pt=b(Ke,y(461),m(f(421))),Yi=D(Kr,Pt),Bl=E(Kr),Ml=E(Pt),Hr=D(ke,Xr,Ke,Kr,Pt),ho=D(b(Hr,y(477),m(f(421)))),Vl=E(ho),po=D(b(Hr,y(478),m(f(421))),b(Hr,y(448),m(f(449)),y(477),m(f(421)))),ql=E(po),mo=b(Ke,y(280),m(f(466)),m(f(466)),m(f(421))),jl=E(mo),go=b(Pt,y(465),m(f(466)),m(f(466)),m(f(421))),Wl=E(go),_t=D(ho,po,b(Xr,m(f(421))),b(Yi,m(f(421))),b(ke,m(f(421))),mo,go,f(421)),Hl=E(_t),Zi=b(m(_t),y(290),co(y(281)),m(f(421))),Gl=E(Zi),ea=D(b(_t,y(290),y(281),m(f(421))),b(_t,y(281),m(f(421))),b(y(281),m(f(421)))),Ql=E(ea),ta=b(ke,D(b(f(6,"80")),b(f(6),y(480)),y(480)),m(f(481)),m(f(421))),bo=E(ta),ra=b(ke,D(b(f(6,"443")),b(f(6,"443"),y(480)),b(f(6),y(443)),b(f(6),y(448),y(480)),b(y(448),y(480)),y(448),y(443)),m(f(481)),m(f(421))),wo=E(ra),na=D(b(f(777),m(f(421)))),Xl=E(na),oa=D(b(f(400),m(f(421)))),Kl=E(oa);function ne(){let r={};return r.promise=new Promise((e,t)=>{r.resolve=e,r.reject=t}),r}var At=class{buffer;mask;top;btm;next;constructor(e){if(!(e>0)||(e-1&e)!==0)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(e),this.mask=e-1,this.top=0,this.btm=0,this.next=null}push(e){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=e,this.top=this.top+1&this.mask,!0)}shift(){let e=this.buffer[this.btm];if(e!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,e}isEmpty(){return this.buffer[this.btm]===void 0}},Oe=class{size;hwm;head;tail;constructor(e={}){this.hwm=e.splitLimit??16,this.head=new At(this.hwm),this.tail=this.head,this.size=0}calculateSize(e){return e?.byteLength!=null?e.byteLength:1}push(e){if(e?.value!=null&&(this.size+=this.calculateSize(e.value)),!this.head.push(e)){let t=this.head;this.head=t.next=new At(2*this.head.buffer.length),this.head.push(e)}}shift(){let e=this.tail.shift();if(e===void 0&&this.tail.next!=null){let t=this.tail.next;this.tail.next=null,this.tail=t,e=this.tail.shift()}return e?.value!=null&&(this.size-=this.calculateSize(e.value)),e}isEmpty(){return this.head.isEmpty()}};var Jr=class extends Error{type;code;constructor(e,t){super(e??"The operation was aborted"),this.type="aborted",this.code=t??"ABORT_ERR"}};function xo(r={}){return sa(t=>{let n=t.shift();if(n==null)return{done:!0};if(n.error!=null)throw n.error;return{done:n.done===!0,value:n.value}},r)}function sa(r,e){e=e??{};let t=e.onEnd,n=new Oe,o,s,i,a=ne(),c=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((x,g)=>{s=S=>{s=null,n.push(S);try{x(r(n))}catch(k){g(k)}return o}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=ne()})}},l=x=>s!=null?s(x):(n.push(x),o),h=x=>(n=new Oe,s!=null?s({error:x}):(n.push({error:x}),o)),d=x=>{if(i)return o;if(e?.objectMode!==!0&&x?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return l({done:!1,value:x})},u=x=>i?o:(i=!0,x!=null?h(x):l({done:!0})),p=()=>(n=new Oe,u(),{done:!0}),L=x=>(u(x),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:c,return:p,throw:L,push:d,end:u,get readableLength(){return n.size},onEmpty:async x=>{let g=x?.signal;if(g?.throwIfAborted(),n.isEmpty())return;let S,k;g!=null&&(S=new Promise((N,U)=>{k=()=>{U(new Jr)},g.addEventListener("abort",k)}));try{await Promise.race([a.promise,S])}finally{k!=null&&g!=null&&g?.removeEventListener("abort",k)}}},t==null)return o;let O=o;return o={[Symbol.asyncIterator](){return this},next(){return O.next()},throw(x){return O.throw(x),t!=null&&(t(x),t=void 0),{done:!0}},return(){return O.return(),t!=null&&(t(),t=void 0),{done:!0}},push:d,end(x){return O.end(x),t!=null&&(t(x),t=void 0),o},get readableLength(){return O.readableLength},onEmpty:x=>O.onEmpty(x)},o}var Yr=class r extends Error{name="TimeoutError";constructor(e,t){super(e,t),Error.captureStackTrace?.(this,r)}},yo=r=>r.reason??new DOMException("This operation was aborted.","AbortError");function Zr(r,e){let{milliseconds:t,fallback:n,message:o,customTimers:s={setTimeout,clearTimeout},signal:i}=e,a,c,h=new Promise((d,u)=>{if(typeof t!="number"||Math.sign(t)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${t}\``);if(i?.aborted){u(yo(i));return}if(i&&(c=()=>{u(yo(i))},i.addEventListener("abort",c,{once:!0})),r.then(d,u),t===Number.POSITIVE_INFINITY)return;let p=new Yr;a=s.setTimeout.call(void 0,()=>{if(n){try{d(n())}catch(L){u(L)}return}typeof r.cancel=="function"&&r.cancel(),o===!1?d():o instanceof Error?u(o):(p.message=o??`Promise timed out after ${t} milliseconds`,u(p))},t)}).finally(()=>{h.clear(),c&&i&&i.removeEventListener("abort",c)});return h.clear=()=>{s.clearTimeout.call(void 0,a),a=void 0},h}var ia=r=>{let e=r.addEventListener||r.on||r.addListener,t=r.removeEventListener||r.off||r.removeListener;if(!e||!t)throw new TypeError("Emitter is not compatible");return{addListener:e.bind(r),removeListener:t.bind(r)}};function aa(r,e,t){let n,o=new Promise((s,i)=>{if(t={rejectionEvents:["error"],multiArgs:!1,rejectionMultiArgs:!1,resolveImmediately:!1,...t},!(t.count>=0&&(t.count===Number.POSITIVE_INFINITY||Number.isInteger(t.count))))throw new TypeError("The `count` option should be at least 0 or more");t.signal?.throwIfAborted();let a=[e].flat(),c=[],{addListener:l,removeListener:h}=ia(r),d=async(...p)=>{let L=t.multiArgs?p:p[0];if(t.filter)try{if(!await t.filter(L))return}catch(O){n(),i(O);return}c.push(L),t.count===c.length&&(n(),s(c))},u=(...p)=>{n(),i(t.rejectionMultiArgs?p:p[0])};n=()=>{for(let p of a)h(p,d);for(let p of t.rejectionEvents)a.includes(p)||h(p,u)};for(let p of a)l(p,d);for(let p of t.rejectionEvents)a.includes(p)||l(p,u);t.signal&&t.signal.addEventListener("abort",()=>{u(t.signal.reason)},{once:!0}),t.resolveImmediately&&s(c)});if(o.cancel=n,typeof t.timeout=="number"){let s=Zr(o,{milliseconds:t.timeout});return s.cancel=()=>{n(),s.clear()},s}return o}function Tt(r,e,t){typeof t=="function"&&(t={filter:t}),t={...t,count:1,resolveImmediately:!1};let n=aa(r,e,t),o=n.then(s=>s[0]);return o.cancel=n.cancel,o}function en(r,e){let t,n=function(){let o=function(){t=void 0,r()};clearTimeout(t),t=setTimeout(o,e)};return n.start=()=>{},n.stop=()=>{clearTimeout(t)},n}var Dt=class extends Error{static name="QueueFullError";constructor(e="The queue was full"){super(e),this.name="QueueFullError"}};function ca(r){return r.reason}async function Lt(r,e,t){if(e==null)return r;let n=t?.translateError??ca;if(e.aborted)return r.catch(()=>{}),Promise.reject(n(e));let o;try{return await Promise.race([r,new Promise((s,i)=>{o=()=>{i(n(e))},e.addEventListener("abort",o)})])}finally{o!=null&&e.removeEventListener("abort",o)}}var kt=class{deferred;signal;onProgress;constructor(e){this.signal=e?.signal,this.onProgress=e?.onProgress,this.deferred=ne(),this.onAbort=this.onAbort.bind(this),this.signal?.addEventListener("abort",this.onAbort)}onAbort(){this.deferred.reject(this.signal?.reason??new M)}cleanup(){this.signal?.removeEventListener("abort",this.onAbort)}};function ua(){return`${parseInt(String(Math.random()*1e9),10).toString()}${Date.now()}`}var Ot=class{id;fn;options;recipients;status;timeline;controller;dispatchingProgress;constructor(e,t){this.id=ua(),this.status="queued",this.fn=e,this.options=t,this.recipients=[],this.timeline={created:Date.now()},this.controller=new AbortController,this.controller.signal,this.dispatchingProgress=!1,this.onAbort=this.onAbort.bind(this)}abort(e){this.controller.abort(e)}onAbort(){this.recipients.reduce((t,n)=>t&&n.signal?.aborted===!0,!0)&&(this.controller.abort(new M),this.cleanup())}async join(e){let t=new kt(e);return this.recipients.push(t),e?.signal?.addEventListener("abort",this.onAbort),t.deferred.promise}async run(){this.status="running",this.timeline.started=Date.now();try{this.controller.signal.throwIfAborted();let e=await Lt(this.fn({...this.options??{},signal:this.controller.signal,onProgress:t=>{if(!this.dispatchingProgress){this.dispatchingProgress=!0;try{this.recipients.forEach(n=>{n.onProgress?.(t)})}finally{this.dispatchingProgress=!1}}}}),this.controller.signal);this.recipients.forEach(t=>{t.deferred.resolve(e)}),this.status="complete"}catch(e){this.recipients.forEach(t=>{t.deferred.reject(e)}),this.status="errored"}finally{this.timeline.finished=Date.now(),this.cleanup()}}cleanup(){this.recipients.forEach(e=>{e.cleanup(),e.signal?.removeEventListener("abort",this.onAbort)})}};var Ft=class extends Ie{concurrency;maxSize;queue;pending;sort;paused;constructor(e={}){super(),this.concurrency=e.concurrency??Number.POSITIVE_INFINITY,this.maxSize=e.maxSize??Number.POSITIVE_INFINITY,this.pending=0,this.paused=!1,e.metricName!=null&&e.metrics?.registerMetricGroup(e.metricName,{calculate:()=>({size:this.queue.length,running:this.pending,queued:this.queue.length-this.pending})}),this.sort=e.sort,this.queue=[],this.emitEmpty=en(this.emitEmpty.bind(this),1),this.emitIdle=en(this.emitIdle.bind(this),1)}emitEmpty(){this.size===0&&this.safeDispatchEvent("empty")}emitIdle(){this.running===0&&this.safeDispatchEvent("idle")}pause(){this.paused=!0}resume(){this.paused&&(this.paused=!1,this.tryToStartAnother())}tryToStartAnother(){if(this.paused)return!1;if(this.size===0)return this.emitEmpty(),this.running===0&&this.emitIdle(),!1;if(this.pending<this.concurrency){let e;for(let t of this.queue)if(t.status==="queued"){e=t;break}return e==null?!1:(this.safeDispatchEvent("active"),this.pending++,e.run().finally(()=>{for(let t=0;t<this.queue.length;t++)if(this.queue[t]===e){this.queue.splice(t,1);break}this.pending--,this.tryToStartAnother(),this.safeDispatchEvent("next")}),!0)}return!1}enqueue(e){this.queue.push(e),this.sort!=null&&this.queue.sort(this.sort)}async add(e,t){if(t?.signal?.throwIfAborted(),this.size===this.maxSize)throw new Dt;let n=new Ot(e,t);this.enqueue(n),this.safeDispatchEvent("add");let o=n.join(t).then(s=>(this.safeDispatchEvent("completed",{detail:s}),this.safeDispatchEvent("success",{detail:{job:n,result:s}}),s)).catch(s=>{if(n.status==="queued"){for(let i=0;i<this.queue.length;i++)if(this.queue[i]===n){this.queue.splice(i,1);break}}throw this.safeDispatchEvent("failure",{detail:{job:n,error:s}}),s});return this.tryToStartAnother(),o}clear(){this.queue.splice(0,this.queue.length)}abort(){this.queue.forEach(e=>{e.abort(new M)}),this.clear()}async onEmpty(e){this.size!==0&&await Tt(this,"empty",e)}async onSizeLessThan(e,t){this.size<e||await Tt(this,"next",{...t,filter:()=>this.size<e})}async onIdle(e){this.pending===0&&this.size===0||await Tt(this,"idle",e)}get size(){return this.queue.length}get queued(){return this.queue.length-this.pending}get running(){return this.pending}async*toGenerator(e){e?.signal?.throwIfAborted();let t=xo({objectMode:!0}),n=c=>{c!=null?this.abort():this.clear(),t.end(c)},o=c=>{c.detail!=null&&t.push(c.detail)},s=c=>{n(c.detail.error)},i=()=>{n()},a=()=>{n(new M("Queue aborted"))};this.addEventListener("completed",o),this.addEventListener("failure",s),this.addEventListener("idle",i),e?.signal?.addEventListener("abort",a);try{yield*t}finally{this.removeEventListener("completed",o),this.removeEventListener("failure",s),this.removeEventListener("idle",i),e?.signal?.removeEventListener("abort",a),n()}}};var Nt=class extends Ie{initialPeerSearchComplete;requests;logName;log;logger;minProviders;maxProviders;providers;evictionFilter;initialProviders;cidPeerFilterSize;constructor(e,t){super(),this.logName=t.name,this.logger=e.logger,this.log=e.logger.forComponent(this.logName),this.requests=new Map,this.minProviders=t.minProviders??1,this.maxProviders=t.maxProviders??5,this.cidPeerFilterSize=t.cidPeerFilterSize??100,this.providers=[],this.evictionFilter=ct(this.maxProviders),this.initialProviders=[...t.providers??[]]}async retrieve(e,t={}){let n=Be.encode(e.multihash.bytes),o=this.requests.get(n);if(o!=null)return this.log("join existing request for %c",e),o.observers++,o.promise;let s=ne(),i={promise:s.promise,observers:1,queryFilter:ct(this.cidPeerFilterSize)};this.requests.set(n,i);let a=!1;this.initialPeerSearchComplete==null&&(a=!0,this.log=this.logger.forComponent(`${this.logName}:${e}`),this.initialPeerSearchComplete=this.findProviders(e,this.minProviders,t));let c=!1,l=new Ft({concurrency:this.maxProviders});l.addEventListener("failure",u=>{this.log.error("error querying provider %s, evicting from session - %e",u.detail.job.options.provider,u.detail.error),this.evict(u.detail.job.options.provider)}),l.addEventListener("success",u=>{c=!0,s.resolve(u.detail.result)}),l.addEventListener("idle",()=>{if(c){this.log.trace("session idle, found block");return}if(t.signal?.aborted===!0){this.log.trace("session idle, signal aborted");return}Promise.resolve().then(async()=>{this.log("no session peers had block for for %c, finding new providers",e);for(let u=0;u<this.minProviders&&this.providers.length!==0;u++){let p=this.providers[Math.floor(Math.random()*this.providers.length)];this.evict(p)}await this.findProviders(e,this.minProviders,t),this.log("found new providers re-retrieving %c",e),this.requests.delete(n),s.resolve(await this.retrieve(e,t))}).catch(u=>{this.log.error("could not find new providers for %c - %e",e,u),s.reject(u)})});let h=u=>{let p=this.toFilterKey(u.detail);i.queryFilter.has(p)||(i.queryFilter.add(p),this.emitFoundProviderProgressEvent(e,u.detail,t),l.add(async()=>this.queryProvider(e,u.detail,t),{provider:u.detail}).catch(L=>{t.signal?.aborted!==!0&&this.log.error("error retrieving session block for %c - %e",e,L)}))};if(this.addEventListener("provider",h),a)try{await Lt(this.initialPeerSearchComplete,t.signal),a&&this.log("found initial session peers for %c",e)}catch(u){throw a&&this.log("failed to find initial session peers for %c - %e",e,u),this.requests.delete(n),i.observers>1&&s.reject(u),u}Promise.all([...this.providers].filter(u=>{let p=this.toFilterKey(u),L=i.queryFilter.has(p);return L||i.queryFilter.add(this.toFilterKey(u)),!L}).map(async u=>l.add(async()=>this.queryProvider(e,u,t),{provider:u}))).catch(u=>{t.signal?.aborted!==!0&&this.log.error("error retrieving session block for %c - %e",e,u)});let d=()=>{s.reject(new M(t.signal?.reason??"Session aborted")),l.abort()};t.signal?.addEventListener("abort",d);try{return await s.promise}finally{this.removeEventListener("provider",h),t.signal?.removeEventListener("abort",d),l.clear(),this.requests.delete(n)}}evict(e){this.evictionFilter.add(this.toFilterKey(e));let t=this.providers.findIndex(n=>this.equals(n,e));t!==-1&&this.providers.splice(t,1)}isEvicted(e){return this.evictionFilter.has(this.toFilterKey(e))}hasProvider(e){return!!(this.providers.find(t=>this.equals(t,e))!=null||this.isEvicted(e))}async addPeer(e,t){let n=await this.convertToProvider(e,"manually-added",t);n==null||this.hasProvider(n)||(this.providers.push(n),this.safeDispatchEvent("provider",{detail:n}))}async findProviders(e,t,n){let o=ne(),s=0;return Promise.resolve().then(async()=>{this.log("finding %d-%d new provider(s) for %c - %d initial providers",t,this.maxProviders,e,this.initialProviders.length);let i=this,a=async function*(){for(;i.initialProviders.length>0;){let l=i.initialProviders.pop();if(l==null)continue;let h=await i.convertToProvider(l,"manual",n);h!=null&&(yield h)}},c=async function*(){yield*a(),yield*i.findNewProviders(e,n)};for await(let l of c()){if(this.providers.length===this.maxProviders||n.signal?.aborted===!0)break;if(!this.hasProvider(l)&&(this.log("found %d providers, %d in session",s,this.providers.length),this.providers.push(l),this.safeDispatchEvent("provider",{detail:l}),s++,this.providers.length===t&&(this.log("session is ready with %d peer(s), new peers present",this.providers.length),o.resolve()),this.providers.length===this.maxProviders)){this.log("found max session peers %d",this.providers.length);break}}if(this.log("found %d new session peers while trying to find %d, %d in session",s,t,this.providers.length),this.providers.length<t)throw new st(`Found ${s} of ${t} ${this.name} providers for ${e}, ${this.providers.length} in session after evictions`)}).catch(i=>{this.log.error("error searching routing for potential session peers for %c - %e",e,i),o.reject(i)}),o.promise}};function Eo(r){return r==null?!1:K.asCID(r)!=null}var da=[6,53,56,54,55];function vo(r){return So("sni",r)?.value}function _o(r){let e=So("tcp",r)?.value;return e==null?"":`:${e}`}function So(r,e){return e.find(t=>t.name===r)}function Io(r){return r.some(({code:e})=>e===448)}function j(r,e){let t=Co[r.name];if(t==null)throw new Error(`Can't interpret protocol ${r.name}`);let n=t(r,e);return r.code===41?`[${n}]`:n}var Co={ip4:(r,e)=>r.value,ip6:(r,e)=>e.length===0?r.value:`[${r.value}]`,tcp:(r,e)=>{let t=e.pop();if(t==null)throw new Error("Unexpected end of multiaddr");return`tcp://${j(t,e)}:${r.value}`},udp:(r,e)=>{let t=e.pop();if(t==null)throw new Error("Unexpected end of multiaddr");return`udp://${j(t,e)}:${r.value}`},dnsaddr:(r,e)=>r.value,dns4:(r,e)=>r.value,dns6:(r,e)=>r.value,dns:(r,e)=>r.value,ipfs:(r,e)=>{let t=e.pop();if(t==null)throw new Error("Unexpected end of multiaddr");return`${j(t,e)}`},p2p:(r,e)=>{let t=e.pop();if(t==null)throw new Error("Unexpected end of multiaddr");return`${j(t,e)}`},http:(r,e)=>{let t=Io(e),n=vo(e),o=_o(e);if(t&&n!=null)return`https://${n}${o}`;let s=t?"https://":"http://",i=e.pop();if(i==null)throw new Error("Unexpected end of multiaddr");let a=j(i,e);return a=a?.replace("tcp://",""),`${s}${a}`},"http-path":(r,e)=>{let t=e.pop();if(t==null)throw new Error("Unexpected end of multiaddr");let n=j(t,e),o=decodeURIComponent(r.value??"");return`${n}${o}`},tls:(r,e)=>{let t=e.pop();if(t==null)throw new Error("Unexpected end of multiaddr");return j(t,e)},sni:(r,e)=>{let t=e.pop();if(t==null)throw new Error("Unexpected end of multiaddr");return j(t,e)},https:(r,e)=>{let t=e.pop();if(t==null)throw new Error("Unexpected end of multiaddr");let n=j(t,e);return n=n?.replace("tcp://",""),`https://${n}`},ws:(r,e)=>{let t=Io(e),n=vo(e),o=_o(e);if(t&&n!=null)return`wss://${n}${o}`;let s=t?"wss://":"ws://",i=e.pop();if(i==null)throw new Error("Unexpected end of multiaddr");let a=j(i,e);return a=a?.replace("tcp://",""),`${s}${a}`},wss:(r,e)=>{let t=e.pop();if(t==null)throw new Error("Unexpected end of multiaddr");let n=j(t,e);return n=n?.replace("tcp://",""),`wss://${n}`}};function Ut(r,e){let n=vt(r).getComponents(),o=n.pop();if(o==null)throw new Error("Unexpected end of multiaddr");let s=Co[o.name];if(s==null)throw new Error(`No interpreter found for ${o.name}`);let i=s(o,n)??"";return e?.assumeHttp!==!1&&da.includes(o.code)&&(i=i.replace(/^.*:\/\//,""),o.value==="443"?i=`https://${i}`:i=`http://${i}`),(i.startsWith("http://")||i.startsWith("https://")||i.startsWith("ws://")||i.startsWith("wss://"))&&(i=new URL(i).toString(),i.endsWith("/")&&(i=i.substring(0,i.length-1))),i}var W=class extends Event{type;detail;constructor(e,t){super(e),this.type=e,this.detail=t}};var Po="[a-fA-F\\d:]",le=r=>r&&r.includeBoundaries?`(?:(?<=\\s|^)(?=${Po})|(?<=${Po})(?=\\s|$))`:"",H="(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)){3}",I="[a-fA-F\\d]{1,4}",$t=`
|
|
3
3
|
(?:
|
|
4
4
|
(?:${I}:){7}(?:${I}|:)| // 1:2:3:4:5:6:7:: 1:2:3:4:5:6:7:8
|
|
5
|
-
(?:${I}:){6}(?:${
|
|
6
|
-
(?:${I}:){5}(?::${
|
|
7
|
-
(?:${I}:){4}(?:(?::${I}){0,1}:${
|
|
8
|
-
(?:${I}:){3}(?:(?::${I}){0,2}:${
|
|
9
|
-
(?:${I}:){2}(?:(?::${I}){0,3}:${
|
|
10
|
-
(?:${I}:){1}(?:(?::${I}){0,4}:${
|
|
11
|
-
(?::(?:(?::${I}){0,5}:${
|
|
5
|
+
(?:${I}:){6}(?:${H}|:${I}|:)| // 1:2:3:4:5:6:: 1:2:3:4:5:6::8 1:2:3:4:5:6::8 1:2:3:4:5:6::1.2.3.4
|
|
6
|
+
(?:${I}:){5}(?::${H}|(?::${I}){1,2}|:)| // 1:2:3:4:5:: 1:2:3:4:5::7:8 1:2:3:4:5::8 1:2:3:4:5::7:1.2.3.4
|
|
7
|
+
(?:${I}:){4}(?:(?::${I}){0,1}:${H}|(?::${I}){1,3}|:)| // 1:2:3:4:: 1:2:3:4::6:7:8 1:2:3:4::8 1:2:3:4::6:7:1.2.3.4
|
|
8
|
+
(?:${I}:){3}(?:(?::${I}){0,2}:${H}|(?::${I}){1,4}|:)| // 1:2:3:: 1:2:3::5:6:7:8 1:2:3::8 1:2:3::5:6:7:1.2.3.4
|
|
9
|
+
(?:${I}:){2}(?:(?::${I}){0,3}:${H}|(?::${I}){1,5}|:)| // 1:2:: 1:2::4:5:6:7:8 1:2::8 1:2::4:5:6:7:1.2.3.4
|
|
10
|
+
(?:${I}:){1}(?:(?::${I}){0,4}:${H}|(?::${I}){1,6}|:)| // 1:: 1::3:4:5:6:7:8 1::8 1::3:4:5:6:7:1.2.3.4
|
|
11
|
+
(?::(?:(?::${I}){0,5}:${H}|(?::${I}){1,7}|:)) // ::2:3:4:5:6:7:8 ::2:3:4:5:6:7:8 ::8 ::1.2.3.4
|
|
12
12
|
)(?:%[0-9a-zA-Z]{1,})? // %eth0 %1
|
|
13
|
-
`.replace(/\s*\/\/.*$/gm,"").replace(/\n/g,"").trim(),
|
|
13
|
+
`.replace(/\s*\/\/.*$/gm,"").replace(/\n/g,"").trim(),pa=new RegExp(`(?:^${H}$)|(?:^${$t}$)`),ma=new RegExp(`^${H}$`),ga=new RegExp(`^${$t}$`),tn=r=>r&&r.exact?pa:new RegExp(`(?:${le(r)}${H}${le(r)})|(?:${le(r)}${$t}${le(r)})`,"g");tn.v4=r=>r&&r.exact?ma:new RegExp(`${le(r)}${H}${le(r)}`,"g");tn.v6=r=>r&&r.exact?ga:new RegExp(`${le(r)}${$t}${le(r)}`,"g");var rn=tn;function nn(r){let e=(...t)=>r(...t);return Object.defineProperty(e,"name",{value:`functionTimeout(${r.name||"<anonymous>"})`,configurable:!0}),e}function Ao(){return!1}var{toString:ba}=Object.prototype;function on(r){return ba.call(r)==="[object RegExp]"}var To={global:"g",ignoreCase:"i",multiline:"m",dotAll:"s",sticky:"y",unicode:"u"};function sn(r,e={}){if(!on(r))throw new TypeError("Expected a RegExp instance");let t=Object.keys(To).map(o=>(typeof e[o]=="boolean"?e[o]:r[o])?To[o]:"").join(""),n=new RegExp(e.source||r.source,t);return n.lastIndex=typeof e.lastIndex=="number"?e.lastIndex:r.lastIndex,n}function an(r,e,{timeout:t}={}){try{return nn(()=>sn(r).test(e),{timeout:t})()}catch(n){if(Ao(n))return!1;throw n}}var wa=15,xa=45,Do={timeout:400};function cn(r){return r.length>xa?!1:an(rn.v6({exact:!0}),r,Do)}function Lo(r){return r.length>wa?!1:an(rn.v4({exact:!0}),r,Do)}var ko={http:"80",https:"443",ws:"80",wss:"443"},ya=["http","https","ws","wss"];function Oo(r,e){e=e??{};let t=e.defaultDnsType??"dns",{scheme:n,hostname:o,port:s,path:i}=Ea(r),a=[va(o,t),_a(s,n),Ia(n)];i!=null&&a.push(Sa(i));let c="/"+a.filter(l=>!!l).reduce((l,h)=>l.concat(h),[]).join("/");return vt(c)}function Ea(r){let[e]=r.split(":");ya.includes(e)||(r="http"+r.substring(e.length));let{protocol:t,hostname:n,port:o,pathname:s,search:i}=new URL(r);if(o==null||o===""){let c=Ca(e);c!=null&&(o=c),c==null&&t==="http:"&&(o="80")}let a;return s!=null&&s!==""&&s!=="/"&&(s.startsWith("/")&&(s=s.substring(1)),a=s),i!=null&&i!==""&&(a=a??"",a+=i),{scheme:e,hostname:n,port:o,path:a}}function va(r,e){if(!(r==null||r==="")){if(Lo(r))return["ip4",r];if(cn(r))return["ip6",r];if(r[0]==="["){let t=r.substring(1,r.length-1);if(cn(t))return["ip6",t]}return[e,r]}}function _a(r,e){if(!(r==null||r===""))return e==="udp"?["udp",r]:["tcp",r]}function Ia(r){if(r.match(/^tcp$|^udp$/)==null)return r==="https"?["/tls/http"]:r==="wss"?["/tls/ws"]:[r]}function Sa(r){if(!(r==null||r===""))return["http-path",encodeURIComponent(r)]}function Ca(r){if(!(r==null||r===""||ko[r]==null))return ko[r]}function un(r,e,t){return r.filter(n=>{let o=wo.exactMatch(n),s=bo.exactMatch(n);if(!o&&!s)return!1;if(o||e&&s)return t||uo.matches(n)?!0:Qn(n)===!1;if(!e&&t){let{host:i}=ut(n);if(i==="127.0.0.1"||i==="localhost"||i.endsWith(".localhost"))return!0}return!1})}async function*Rt(r,e,t,n,o,s={}){for await(let i of e.findProviders(r,s)){let a=un(i.multiaddrs,n,o);if(a.length===0)continue;let c=new URL(Ut(a[0]));yield new Fe(c,{logger:t,transformRequestInit:s.transformRequestInit,routing:i.routing})}}async function Fo(r,e,t){let{signal:n,log:o}=t??{},s=r.headers.get("content-length");if(s!=null){let c=parseInt(s,10);if(c>e)throw o?.error("content-length header (%d) is greater than the limit (%d)",c,e),r.body!=null&&await r.body.cancel().catch(l=>{o?.error("error cancelling response body after content-length check - %e",l)}),new Error(`Content-Length header (${c}) is greater than the limit (${e}).`)}let i=r.body?.getReader();if(i==null)throw new Error("Response body is not readable");let a=new nt;try{for(;;){if(n?.aborted===!0)throw new Error("Response body read was aborted.");let{done:c,value:l}=await i.read();if(c)break;if(a.append(l),a.byteLength>e)throw new Error(`Response body is greater than the limit (${e}), received ${a.byteLength} bytes.`)}}finally{i.cancel().catch(c=>{o?.error("error cancelling reader - %e",c)}).finally(()=>{i.releaseLock()})}return a.subarray()}var Pa=2336,Fe=class{url;peer;#e=0;#t=0;#r=0;#o=0;#n=new Map;log;transformRequestInit;routing;constructor(e,{logger:t,transformRequestInit:n,routing:o}){this.url=e instanceof URL?e:new URL(e),this.transformRequestInit=n,this.log=t.forComponent(`helia:trustless-gateway-block-broker:${this.url.host}`),this.routing=o,this.peer=K.createV1(Pa,er.digest(C(this.url.toString())))}#s(e){let t=e.multihash.bytes;return Be.encode(t)}async getRawBlock(e,t={}){let n=new URL(this.url.toString());n.pathname=`/ipfs/${e.toString()}`;let o=t.maxSize??ln;if(n.search="?format=raw",t.signal?.aborted===!0)throw new Error(`Signal to fetch raw block for CID ${e} from gateway ${this.url} was aborted prior to fetch`);let s=this.#s(e),i=new AbortController,a=()=>{i.abort()};t.signal?.addEventListener("abort",a);try{let c=this.#n.get(s);if(c==null){this.#e++;let l={signal:i.signal,headers:{Accept:"application/vnd.ipld.raw"},cache:"force-cache"},h=this.transformRequestInit!=null?await this.transformRequestInit(l):l,d=new Headers(h.headers);this.log(`sending request
|
|
14
14
|
%s %s HTTP/1.1
|
|
15
15
|
%s
|
|
16
16
|
`,h.method??"GET",n,[...d.entries()].map(([u,p])=>`${u}: ${p}`).join(`
|
|
17
|
-
`)),t.onProgress?.(new
|
|
17
|
+
`)),t.onProgress?.(new W("helia:block-broker:connect",{broker:"trustless-gateway",type:"connect",provider:this.peer,cid:e})),c=fetch(n.toString(),h).then(async u=>{if(this.log(`received response
|
|
18
18
|
HTTP/1.1 %d %s
|
|
19
19
|
%s
|
|
20
20
|
`,u.status,u.statusText,[...u.headers.entries()].map(([L,O])=>`${L}: ${O}`).join(`
|
|
21
|
-
`)),!u.ok)throw this.#t++,new Error(`Unable to fetch raw block for CID ${e} from gateway ${this.url}, received ${u.status} ${u.statusText}`);t.onProgress?.(new
|
|
21
|
+
`)),!u.ok)throw this.#t++,new Error(`Unable to fetch raw block for CID ${e} from gateway ${this.url}, received ${u.status} ${u.statusText}`);t.onProgress?.(new W("helia:block-broker:connected",{broker:"trustless-gateway",type:"connected",provider:this.peer,address:Oo(n.toString()),cid:e})),t.onProgress?.(new W("helia:block-broker:request-block",{broker:"trustless-gateway",type:"request-block",provider:this.peer,cid:e}));let p=await Fo(u,o,{signal:i.signal,log:this.log});return t.onProgress?.(new W("helia:block-broker:receive-block",{broker:"trustless-gateway",type:"receive-block",provider:this.peer,cid:e})),this.#o++,p}),this.#n.set(s,c)}return await c}catch(c){throw t.signal?.aborted===!0?new Error(`Fetching raw block for CID ${e} from gateway ${this.url} was aborted`):(this.#t++,new Error(`Unable to fetch raw block for CID ${e} - ${c.message}`))}finally{t.signal?.removeEventListener("abort",a),this.#n.delete(s)}}reliability(){return this.#e===0?1:this.#r>0?-1/0:this.#o/(this.#e+this.#t*3)}incrementInvalidBlocks(){this.#r++}getStats(){return{attempts:this.#e,errors:this.#t,invalidBlocks:this.#r,successes:this.#o,pendingResponses:this.#n.size}}toString(){return`TrustlessGateway(${this.url})`}};var fn=class extends Nt{name="trustless-gateway-session";routing;allowInsecure;allowLocal;transformRequestInit;constructor(e,t){super(e,{...t,name:"helia:trustless-gateway:session"}),this.routing=e.routing,this.allowInsecure=t.allowInsecure??Je,this.allowLocal=t.allowLocal??Ye,this.transformRequestInit=t.transformRequestInit}async queryProvider(e,t,n){this.log("fetching BLOCK for %c from %s",e,t.url),n?.onProgress?.(new W("helia:block-brokers:query-provider:start",{blockBroker:"trustless-gateway",provider:t.url,transport:"http",cid:e}));let o;try{o=await t.getRawBlock(e,n),this.log.trace("got block for %c from %s",e,t.url)}finally{n?.onProgress?.(new W("helia:block-brokers:query-provider:end",{blockBroker:"trustless-gateway",provider:t.url,transport:"http",cid:e}))}return await n.validateFn?.(o),o}async*findNewProviders(e,t={}){yield*Rt(e,this.routing,this.logger,this.allowInsecure,this.allowLocal,{...t,transformRequestInit:this.transformRequestInit})}toFilterKey(e){return e.url.toString()}equals(e,t){return e.url.toString()===t.url.toString()}async convertToProvider(e,t,n){if(n?.signal?.throwIfAborted(),Eo(e))return;let o=un(Array.isArray(e)?e:[e],this.allowInsecure,this.allowLocal);if(o.length===0)return;let s=Ut(o[0]);return new Fe(s,{logger:this.logger,transformRequestInit:this.transformRequestInit,routing:t})}emitFoundProviderProgressEvent(e,t,n){n?.onProgress?.(new W("trustless-gateway:found-provider",{type:"trustless-gateway",cid:e,url:t.url.toJSON(),routing:t.routing}))}};function No(r,e){return new fn(r,e)}var zt=class{name="trustless-gateway";allowInsecure;allowLocal;transformRequestInit;routing;log;logger;constructor(e,t={}){this.log=e.logger.forComponent("helia:trustless-gateway-block-broker"),this.logger=e.logger,this.routing=e.routing,this.allowInsecure=t.allowInsecure??Je,this.allowLocal=t.allowLocal??Ye,this.transformRequestInit=t.transformRequestInit}async retrieve(e,t={}){let n=[];for await(let o of Rt(e,this.routing,this.logger,this.allowInsecure,this.allowLocal,{...t,transformRequestInit:this.transformRequestInit})){this.log("getting block for %c from %s",e,o.url);try{let s=await o.getRawBlock(e,t);this.log.trace("got block for %c from %s",e,o.url);try{await t.validateFn?.(s)}catch(i){this.log.error("failed to validate block for %c from %s - %e",e,o.url,i);continue}return s}catch(s){if(this.log.error("failed to get block for %c from %s - %e",e,o.url,s),s instanceof Error?n.push(s):n.push(new Error(`Unable to fetch raw block for CID ${e} from gateway ${o.url}`)),t.signal?.aborted===!0){this.log.trace("request aborted while fetching raw block for CID %c from gateway %s",e,o.url);break}}}throw n.length>0?new AggregateError(n,`Unable to fetch raw block for CID ${e} from any gateway`):new Error(`Unable to fetch raw block for CID ${e} from any gateway`)}createSession(e={}){return No({logger:this.logger,routing:this.routing},{...e,allowLocal:this.allowLocal,allowInsecure:this.allowInsecure,transformRequestInit:this.transformRequestInit})}};var Je=!1,Ye=!1,ln=2097152;function Aa(r={}){return e=>new zt(e,r)}return Vo(Ta);})();
|
|
22
22
|
return HeliaTrustlessGatewayClient}));
|
|
23
23
|
//# sourceMappingURL=index.min.js.map
|