@libp2p/autonat 3.0.20-29797a5bb → 3.0.20-5b8813abc

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.min.js CHANGED
@@ -1,5 +1,5 @@
1
1
  (function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.Libp2PAutonat = factory()}(typeof self !== 'undefined' ? self : this, function () {
2
- "use strict";var Libp2PAutonat=(()=>{var iu=Object.create;var on=Object.defineProperty;var au=Object.getOwnPropertyDescriptor;var cu=Object.getOwnPropertyNames;var fu=Object.getPrototypeOf,uu=Object.prototype.hasOwnProperty;var yo=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports),V=(r,t)=>{for(var e in t)on(r,e,{get:t[e],enumerable:!0})},Qi=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of cu(t))!uu.call(r,o)&&o!==e&&on(r,o,{get:()=>t[o],enumerable:!(n=au(t,o))||n.enumerable});return r};var lu=(r,t,e)=>(e=r!=null?iu(fu(r)):{},Qi(t||!r||!r.__esModule?on(e,"default",{value:r,enumerable:!0}):e,r)),du=r=>Qi(on({},"__esModule",{value:!0}),r);var Ii=yo(cr=>{"use strict";Object.defineProperty(cr,"__esModule",{value:!0});cr.Netmask4Impl=void 0;cr.ip2long=ar;cr.long2ip=Rt;function Rt(r){let t=(r&-16777216)>>>24,e=(r&255<<16)>>>16,n=(r&65280)>>>8,o=r&255;return[t,e,n,o].join(".")}var ap=48,cp=97,fp=65;function up(r){let t=0,e=10,n="9",o=0;r.length>1&&r[o]==="0"&&(r[o+1]==="x"||r[o+1]==="X"?(o+=2,e=16):"0"<=r[o+1]&&r[o+1]<="9"&&(o++,e=8,n="7"));let s=o;for(;o<r.length;){if("0"<=r[o]&&r[o]<=n)t=t*e+(r.charCodeAt(o)-ap)>>>0;else if(e===16)if("a"<=r[o]&&r[o]<="f")t=t*e+(10+r.charCodeAt(o)-cp)>>>0;else if("A"<=r[o]&&r[o]<="F")t=t*e+(10+r.charCodeAt(o)-fp)>>>0;else break;else break;if(t>4294967295)throw new Error("too large");o++}if(o===s)throw new Error("empty octet");return[t,o]}function ar(r){let t=[];for(let e=0;e<=3&&r.length!==0;e++){if(e>0){if(r[0]!==".")throw new Error("Invalid IP");r=r.substring(1)}let[n,o]=up(r);r=r.substring(o),t.push(n)}if(r.length!==0)throw new Error("Invalid IP");switch(t.length){case 1:if(t[0]>4294967295)throw new Error("Invalid IP");return t[0]>>>0;case 2:if(t[0]>255||t[1]>16777215)throw new Error("Invalid IP");return(t[0]<<24|t[1])>>>0;case 3:if(t[0]>255||t[1]>255||t[2]>65535)throw new Error("Invalid IP");return(t[0]<<24|t[1]<<16|t[2])>>>0;case 4:if(t[0]>255||t[1]>255||t[2]>255||t[3]>255)throw new Error("Invalid IP");return(t[0]<<24|t[1]<<16|t[2]<<8|t[3])>>>0;default:throw new Error("Invalid IP")}}var Ai=class r{constructor(t,e){if(typeof t!="string")throw new Error("Missing `net' parameter");let n=e;if(!n){let o=t.split("/",2);t=o[0],n=o[1]}if(n||(n=32),typeof n=="string"&&n.indexOf(".")>-1){try{this.maskLong=ar(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=(ar(t)&this.maskLong)>>>0}catch{throw new Error("Invalid net address: "+t)}if(!(this.bitmask<=32))throw new Error("Invalid mask for ip4: "+n);this.size=Math.pow(2,32-this.bitmask),this.base=Rt(this.netLong),this.mask=Rt(this.maskLong),this.hostmask=Rt(~this.maskLong),this.first=this.bitmask<=30?Rt(this.netLong+1):this.base,this.last=this.bitmask<=30?Rt(this.netLong+this.size-2):Rt(this.netLong+this.size-1),this.broadcast=this.bitmask<=30?Rt(this.netLong+this.size-1):void 0}contains(t){return typeof t=="string"&&(t.indexOf("/")>0||t.split(".").length!==4)&&(t=new r(t)),t instanceof r?this.contains(t.base)&&this.contains(t.broadcast||t.last):(ar(t)&this.maskLong)>>>0===(this.netLong&this.maskLong)>>>0}next(t=1){return new r(Rt(this.netLong+this.size*t),this.mask)}forEach(t){let e=ar(this.first),n=ar(this.last),o=0;for(;e<=n;)t(Rt(e),e,o),o++,e++}toString(){return this.base+"/"+this.bitmask}};cr.Netmask4Impl=Ai});var Rf=yo(fr=>{"use strict";Object.defineProperty(fr,"__esModule",{value:!0});fr.Netmask6Impl=void 0;fr.ip6bigint=Bi;fr.bigint2ip6=Te;var lp=Ii(),Ti=(1n<<128n)-1n;function Bi(r){let t=r.indexOf("%");t!==-1&&(r=r.substring(0,t));let e=r.lastIndexOf(":");if(e!==-1&&r.indexOf(".",e)!==-1){let n=r.substring(e+1),o=(0,lp.ip2long)(n),s=r.substring(0,e+1)+"0:0";return Of(s)&~0xffffffffn|BigInt(o)}return Of(r)}function Of(r){let t=r.indexOf("::"),e;if(t!==-1){let o=r.substring(0,t),s=r.substring(t+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");e=[...i,...Array(c).fill("0"),...a]}else e=r.split(":");if(e.length!==8)throw new Error("Invalid IPv6: expected 8 groups, got "+e.length);let n=0n;for(let o=0;o<8;o++){let s=e[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 Te(r){if(r<0n||r>Ti)throw new Error("Invalid IPv6 address value");let t=[];for(let i=0;i<8;i++)t.unshift(Number(r&0xffffn)),r>>=16n;let e=-1,n=0,o=-1,s=0;for(let i=0;i<8;i++)t[i]===0?o===-1?(o=i,s=1):s++:(s>n&&s>=2&&(e=o,n=s),o=-1,s=0);if(s>n&&s>=2&&(e=o,n=s),e!==-1&&e+n===8&&e>0)return t.slice(0,e).map(a=>a.toString(16)).join(":")+"::";if(e===0)return"::"+t.slice(n).map(a=>a.toString(16)).join(":");if(e>0){let i=t.slice(0,e).map(c=>c.toString(16)),a=t.slice(e+n).map(c=>c.toString(16));return i.join(":")+"::"+a.join(":")}else return t.map(i=>i.toString(16)).join(":")}var Li=class r{constructor(t,e){if(typeof t!="string")throw new Error("Missing `net' parameter");let n=e;if(n==null){let o=t.indexOf("/");o!==-1?(n=parseInt(t.substring(o+1),10),t=t.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=Ti>>BigInt(128-this.bitmask)<<BigInt(128-this.bitmask);try{this.netBigint=Bi(t)&this.maskBigint}catch{throw new Error("Invalid IPv6 net address: "+t)}this.size=Number(1n<<BigInt(128-this.bitmask)),this.base=Te(this.netBigint),this.mask=Te(this.maskBigint),this.hostmask=Te(~this.maskBigint&Ti),this.first=this.base,this.last=Te(this.netBigint+(1n<<BigInt(128-this.bitmask))-1n),this.broadcast=void 0}contains(t){return typeof t=="string"&&t.indexOf("/")>0&&(t=new r(t)),t instanceof r?this.contains(t.base)&&this.contains(t.last):(Bi(t)&this.maskBigint)===this.netBigint}next(t=1){let e=1n<<BigInt(128-this.bitmask);return new r(Te(this.netBigint+e*BigInt(t)),this.bitmask)}forEach(t){let e=this.netBigint,n=1n<<BigInt(128-this.bitmask),o=this.netBigint+n-1n,s=0;for(;e<=o;)t(Te(e),Number(e),s),s++,e++}toString(){return this.base+"/"+this.bitmask}};fr.Netmask6Impl=Li});var Pf=yo(ue=>{"use strict";Object.defineProperty(ue,"__esModule",{value:!0});ue.long2ip=ue.ip2long=ue.Netmask=void 0;var to=Ii();Object.defineProperty(ue,"ip2long",{enumerable:!0,get:function(){return to.ip2long}});Object.defineProperty(ue,"long2ip",{enumerable:!0,get:function(){return to.long2ip}});var dp=Rf(),Di=class r{constructor(t,e){if(typeof t!="string")throw new Error("Missing `net' parameter");(t.indexOf("/")!==-1?t.substring(0,t.indexOf("/")):t).indexOf(":")!==-1?this._impl=new dp.Netmask6Impl(t,e):this._impl=new to.Netmask4Impl(t,e),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 to.Netmask4Impl?(this.maskLong=this._impl.maskLong,this.netLong=this._impl.netLong):(this.maskLong=0,this.netLong=0)}contains(t){return typeof t=="string"&&(t.indexOf("/")>0?t=new r(t):t.indexOf(":")===-1&&t.split(".").length!==4&&(t=new r(t))),t instanceof r?this.contains(t.base)&&this.contains(t.broadcast||t.last):this._impl.contains(t)}next(t=1){let e=this._impl.next(t);return new r(e.base,e.bitmask)}forEach(t){this._impl.forEach(t)}toString(){return this._impl.toString()}};ue.Netmask=Di});var k0={};V(k0,{autoNAT:()=>P0});var Pt=class extends Error{static name="AbortError";constructor(t="The operation was aborted"){super(t),this.name="AbortError"}};var dt=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},sn=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var an=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}};var mr=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var xo=Symbol.for("@libp2p/peer-id");function hu(r){return typeof r?.handleEvent=="function"}function pu(r){return(r!==!0&&r!==!1&&r?.once)??!1}var cn=class extends EventTarget{#t=new Map;constructor(){super()}listenerCount(t){let e=this.#t.get(t);return e==null?0:e.length}addEventListener(t,e,n){let o=pu(n);super.addEventListener(t,i=>{if(o){let a=this.#t.get(i.type);a!=null&&(a=a.filter(({callback:c})=>c!==e),this.#t.set(i.type,a))}hu(e)?e.handleEvent(i):e(i)},n);let s=this.#t.get(t);s==null&&(s=[],this.#t.set(t,s)),s.push({callback:e,once:o})}removeEventListener(t,e,n){super.removeEventListener(t.toString(),e??null,n);let o=this.#t.get(t);o!=null&&(o=o.filter(({callback:s})=>s!==e),this.#t.set(t,o))}safeDispatchEvent(t,e={}){return this.dispatchEvent(new CustomEvent(t,e))}};var Ji=Symbol.for("@libp2p/service-capabilities"),ta=Symbol.for("@libp2p/service-dependencies");var _o={};V(_o,{base58btc:()=>X,base58flickr:()=>Eu});var lm=new Uint8Array(0);function ea(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}function kt(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return r;if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return new Uint8Array(r.buffer,r.byteOffset,r.byteLength);throw new Error("Unknown type, must be binary type")}function ra(r){return new TextEncoder().encode(r)}function na(r){return new TextDecoder().decode(r)}function mu(r,t){if(r.length>=255)throw new TypeError("Alphabet too long");for(var e=new Uint8Array(256),n=0;n<e.length;n++)e[n]=255;for(var o=0;o<r.length;o++){var s=r.charAt(o),i=s.charCodeAt(0);if(e[i]!==255)throw new TypeError(s+" is ambiguous");e[i]=o}var a=r.length,c=r.charAt(0),f=Math.log(a)/Math.log(256),d=Math.log(256)/Math.log(a);function h(b){if(b instanceof Uint8Array||(ArrayBuffer.isView(b)?b=new Uint8Array(b.buffer,b.byteOffset,b.byteLength):Array.isArray(b)&&(b=Uint8Array.from(b))),!(b instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(b.length===0)return"";for(var x=0,m=0,l=0,g=b.length;l!==g&&b[l]===0;)l++,x++;for(var w=(g-l)*d+1>>>0,_=new Uint8Array(w);l!==g;){for(var A=b[l],D=0,L=w-1;(A!==0||D<m)&&L!==-1;L--,D++)A+=256*_[L]>>>0,_[L]=A%a>>>0,A=A/a>>>0;if(A!==0)throw new Error("Non-zero carry");m=D,l++}for(var B=w-m;B!==w&&_[B]===0;)B++;for(var k=c.repeat(x);B<w;++B)k+=r.charAt(_[B]);return k}function u(b){if(typeof b!="string")throw new TypeError("Expected String");if(b.length===0)return new Uint8Array;var x=0;if(b[x]!==" "){for(var m=0,l=0;b[x]===c;)m++,x++;for(var g=(b.length-x)*f+1>>>0,w=new Uint8Array(g);b[x];){var _=e[b.charCodeAt(x)];if(_===255)return;for(var A=0,D=g-1;(_!==0||A<l)&&D!==-1;D--,A++)_+=a*w[D]>>>0,w[D]=_%256>>>0,_=_/256>>>0;if(_!==0)throw new Error("Non-zero carry");l=A,x++}if(b[x]!==" "){for(var L=g-l;L!==g&&w[L]===0;)L++;for(var B=new Uint8Array(m+(g-L)),k=m;L!==g;)B[k++]=w[L++];return B}}}function p(b){var x=u(b);if(x)return x;throw new Error(`Non-${t} character`)}return{encode:h,decodeUnsafe:u,decode:p}}var gu=mu,bu=gu,sa=bu;var wo=class{name;prefix;baseEncode;constructor(t,e,n){this.name=t,this.prefix=e,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},Eo=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,e,n){this.name=t,this.prefix=e;let o=e.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return ia(this,t)}},vo=class{decoders;constructor(t){this.decoders=t}or(t){return ia(this,t)}decode(t){let e=t[0],n=this.decoders[e];if(n!=null)return n.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function ia(r,t){return new vo({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var So=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,e,n,o){this.name=t,this.prefix=e,this.baseEncode=n,this.baseDecode=o,this.encoder=new wo(t,e,n),this.decoder=new Eo(t,e,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function Oe({name:r,prefix:t,encode:e,decode:n}){return new So(r,t,e,n)}function Yt({name:r,prefix:t,alphabet:e}){let{encode:n,decode:o}=sa(e,r);return Oe({prefix:t,name:r,encode:n,decode:s=>kt(o(s))})}function yu(r,t,e,n){let o=r.length;for(;r[o-1]==="=";)--o;let s=new Uint8Array(o*e/8|0),i=0,a=0,c=0;for(let f=0;f<o;++f){let d=t[r[f]];if(d===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<e|d,i+=e,i>=8&&(i-=8,s[c++]=255&a>>i)}if(i>=e||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function xu(r,t,e){let n=t[t.length-1]==="=",o=(1<<e)-1,s="",i=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],i+=8;i>e;)i-=e,s+=t[o&a>>i];if(i!==0&&(s+=t[o&a<<e-i]),n)for(;(s.length*e&7)!==0;)s+="=";return s}function wu(r){let t={};for(let e=0;e<r.length;++e)t[r[e]]=e;return t}function $({name:r,prefix:t,bitsPerChar:e,alphabet:n}){let o=wu(n);return Oe({prefix:t,name:r,encode(s){return xu(s,n,e)},decode(s){return yu(s,o,e,r)}})}var X=Yt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Eu=Yt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Ao={};V(Ao,{base32:()=>Xt,base32hex:()=>Au,base32hexpad:()=>Tu,base32hexpadupper:()=>Bu,base32hexupper:()=>Iu,base32pad:()=>Su,base32padupper:()=>_u,base32upper:()=>vu,base32z:()=>Lu});var Xt=$({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),vu=$({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Su=$({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),_u=$({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Au=$({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Iu=$({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Tu=$({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Bu=$({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Lu=$({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Io={};V(Io,{base36:()=>gr,base36upper:()=>Du});var gr=Yt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Du=Yt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Cu=fa,aa=128,Ou=127,Ru=~Ou,Pu=Math.pow(2,31);function fa(r,t,e){t=t||[],e=e||0;for(var n=e;r>=Pu;)t[e++]=r&255|aa,r/=128;for(;r&Ru;)t[e++]=r&255|aa,r>>>=7;return t[e]=r|0,fa.bytes=e-n+1,t}var ku=To,Fu=128,ca=127;function To(r,n){var e=0,n=n||0,o=0,s=n,i,a=r.length;do{if(s>=a)throw To.bytes=0,new RangeError("Could not decode varint");i=r[s++],e+=o<28?(i&ca)<<o:(i&ca)*Math.pow(2,o),o+=7}while(i>=Fu);return To.bytes=s-n,e}var Nu=Math.pow(2,7),Uu=Math.pow(2,14),Mu=Math.pow(2,21),zu=Math.pow(2,28),Ku=Math.pow(2,35),qu=Math.pow(2,42),Vu=Math.pow(2,49),Hu=Math.pow(2,56),ju=Math.pow(2,63),$u=function(r){return r<Nu?1:r<Uu?2:r<Mu?3:r<zu?4:r<Ku?5:r<qu?6:r<Vu?7:r<Hu?8:r<ju?9:10},Gu={encode:Cu,decode:ku,encodingLength:$u},Zu=Gu,br=Zu;function yr(r,t=0){return[br.decode(r,t),br.decode.bytes]}function Re(r,t,e=0){return br.encode(r,t,e),t}function Pe(r){return br.encodingLength(r)}function Fe(r,t){let e=t.byteLength,n=Pe(r),o=n+Pe(e),s=new Uint8Array(o+e);return Re(r,s,0),Re(e,s,n),s.set(t,o),new ke(r,e,t,s)}function le(r){let t=kt(r),[e,n]=yr(t),[o,s]=yr(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new ke(e,o,i,t)}function ua(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&ea(r.bytes,e.bytes)}}var ke=class{code;size;digest;bytes;constructor(t,e,n,o){this.code=t,this.size=e,this.digest=n,this.bytes=o}};function la(r,t){let{bytes:e,version:n}=r;return n===0?Xu(e,Bo(r),t??X.encoder):Wu(e,Bo(r),t??Xt.encoder)}var da=new WeakMap;function Bo(r){let t=da.get(r);if(t==null){let e=new Map;return da.set(r,e),e}return t}var ct=class r{code;version;multihash;bytes;"/";constructor(t,e,n,o){this.code=e,this.version=t,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:t,multihash:e}=this;if(t!==xr)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==Qu)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(e)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:t,digest:e}=this.multihash,n=Fe(t,e);return r.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(t){return r.equals(this,t)}static equals(t,e){let n=e;return n!=null&&t.code===n.code&&t.version===n.version&&ua(t.multihash,n.multihash)}toString(t){return la(this,t)}toJSON(){return{"/":la(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(t){if(t==null)return null;let e=t;if(e instanceof r)return e;if(e["/"]!=null&&e["/"]===e.bytes||e.asCID===e){let{version:n,code:o,multihash:s,bytes:i}=e;return new r(n,o,s,i??ha(n,o,s.bytes))}else if(e[Ju]===!0){let{version:n,multihash:o,code:s}=e,i=le(o);return r.create(n,s,i)}else return null}static create(t,e,n){if(typeof e!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(t){case 0:{if(e!==xr)throw new Error(`Version 0 CID must use dag-pb (code: ${xr}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let o=ha(t,e,n.bytes);return new r(t,e,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,xr,t)}static createV1(t,e){return r.create(1,t,e)}static decode(t){let[e,n]=r.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return e}static decodeFirst(t){let e=r.inspectBytes(t),n=e.size-e.multihashSize,o=kt(t.subarray(n,n+e.multihashSize));if(o.byteLength!==e.multihashSize)throw new Error("Incorrect length");let s=o.subarray(e.multihashSize-e.digestSize),i=new ke(e.multihashCode,e.digestSize,s,o);return[e.version===0?r.createV0(i):r.createV1(e.codec,i),t.subarray(e.size)]}static inspectBytes(t){let e=0,n=()=>{let[h,u]=yr(t.subarray(e));return e+=u,h},o=n(),s=xr;if(o===18?(o=0,e=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=e,a=n(),c=n(),f=e+c,d=f-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:d,size:f}}static parse(t,e){let[n,o]=Yu(t,e),s=r.decode(o);if(s.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Bo(s).set(n,t),s}};function Yu(r,t){switch(r[0]){case"Q":{let e=t??X;return[X.prefix,e.decode(`${X.prefix}${r}`)]}case X.prefix:{let e=t??X;return[X.prefix,e.decode(r)]}case Xt.prefix:{let e=t??Xt;return[Xt.prefix,e.decode(r)]}case gr.prefix:{let e=t??gr;return[gr.prefix,e.decode(r)]}default:{if(t==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[r[0],t.decode(r)]}}}function Xu(r,t,e){let{prefix:n}=e;if(n!==X.prefix)throw Error(`Cannot string encode V0 in ${e.name} encoding`);let o=t.get(n);if(o==null){let s=e.encode(r).slice(1);return t.set(n,s),s}else return o}function Wu(r,t,e){let{prefix:n}=e,o=t.get(n);if(o==null){let s=e.encode(r);return t.set(n,s),s}else return o}var xr=112,Qu=18;function ha(r,t,e){let n=Pe(r),o=n+Pe(t),s=new Uint8Array(o+e.byteLength);return Re(r,s,0),Re(t,s,n),s.set(e,o),s}var Ju=Symbol.for("@ipld/js-cid/CID");var Lo={};V(Lo,{identity:()=>xt});var pa=0,tl="identity",ma=kt;function el(r,t){if(t?.truncate!=null&&t.truncate!==r.byteLength){if(t.truncate<0||t.truncate>r.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${r.byteLength}`);r=r.subarray(0,t.truncate)}return Fe(pa,ma(r))}var xt={code:pa,name:tl,encode:ma,digest:el};function wt(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}function rl(r){return r.buffer instanceof ArrayBuffer}function Ne(r){return rl(r)?r:r.slice()}async function ga(r,t,e,n){let o=await crypto.subtle.importKey("jwk",r,{name:"ECDSA",namedCurve:r.crv??"P-256"},!1,["verify"]);n?.signal?.throwIfAborted();let s=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},o,Ne(t),Ne(e.subarray()));return n?.signal?.throwIfAborted(),s}function Ft(r=0){return new Uint8Array(r)}function wr(r=0){return new Uint8Array(r)}function Do(r,t){t==null&&(t=r.reduce((o,s)=>o+s.length,0));let e=wr(t),n=0;for(let o of r)e.set(o,n),n+=o.length;return e}function ba(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}var xa=Symbol.for("@achingbrain/uint8arraylist");function ya(r,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let e=0;for(let n of r){let o=e+n.byteLength;if(t<o)return{buf:n,index:t-e};e=o}throw new RangeError("index is out of bounds")}function un(r){return!!r?.[xa]}var rt=class r{bufs;length;[xa]=!0;constructor(...t){this.bufs=[],this.length=0,t.length>0&&this.appendAll(t)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...t){this.appendAll(t)}appendAll(t){let e=0;for(let n of t)if(n instanceof Uint8Array)e+=n.byteLength,this.bufs.push(n);else if(un(n)){e+=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+=e}prepend(...t){this.prependAll(t)}prependAll(t){let e=0;for(let n of t.reverse())if(n instanceof Uint8Array)e+=n.byteLength,this.bufs.unshift(n);else if(un(n))e+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}get(t){let e=ya(this.bufs,t);return e.buf[e.index]}set(t,e){let n=ya(this.bufs,t);n.buf[n.index]=e}write(t,e=0){if(t instanceof Uint8Array)for(let n=0;n<t.length;n++)this.set(e+n,t[n]);else if(un(t))for(let n=0;n<t.length;n++)this.set(e+n,t.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(t){if(t=Math.trunc(t),!(Number.isNaN(t)||t<=0)){if(t===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(t>=this.bufs[0].byteLength)t-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(t),this.length-=t;break}}}slice(t,e){let{bufs:n,length:o}=this._subList(t,e);return Do(n,o)}subarray(t,e){let{bufs:n,length:o}=this._subList(t,e);return n.length===1?n[0]:Do(n,o)}sublist(t,e){let{bufs:n,length:o}=this._subList(t,e),s=new r;return s.length=o,s.bufs=n,s}_subList(t,e){if(t=t??0,e=e??this.length,t<0&&(t=this.length+t),e<0&&(e=this.length+e),t<0||e>this.length)throw new RangeError("index is out of bounds");if(t===e)return{bufs:[],length:0};if(t===0&&e===this.length)return{bufs:[...this.bufs],length:this.length};let n=[],o=0;for(let s=0;s<this.bufs.length;s++){let i=this.bufs[s],a=o,c=a+i.byteLength;if(o=c,t>=c)continue;let f=t>=a&&t<c,d=e>a&&e<=c;if(f&&d){if(t===a&&e===c){n.push(i);break}let h=t-a;n.push(i.subarray(h,h+(e-t)));break}if(f){if(t===0){n.push(i);continue}n.push(i.subarray(t-a));continue}if(d){if(e===c){n.push(i);break}n.push(i.subarray(0,e-a));break}n.push(i)}return{bufs:n,length:e-t}}indexOf(t,e=0){if(!un(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(e=Number(e??0),isNaN(e)&&(e=0),e<0&&(e=this.length+e),e<0&&(e=0),t.length===0)return e>this.length?this.length:e;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let s=256,i=new Int32Array(s);for(let h=0;h<s;h++)i[h]=-1;for(let h=0;h<o;h++)i[n[h]]=h;let a=i,c=this.byteLength-n.byteLength,f=n.byteLength-1,d;for(let h=e;h<=c;h+=d){d=0;for(let u=f;u>=0;u--){let p=this.get(h+u);if(n[u]!==p){d=Math.max(1,u-a[p]);break}}if(d===0)return h}return-1}getInt8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getInt8(0)}setInt8(t,e){let n=wr(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,e),this.write(n,t)}getInt16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,e)}setInt16(t,e,n){let o=Ft(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,e,n),this.write(o,t)}getInt32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,e)}setInt32(t,e,n){let o=Ft(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,e,n),this.write(o,t)}getBigInt64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,e)}setBigInt64(t,e,n){let o=Ft(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,e,n),this.write(o,t)}getUint8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getUint8(0)}setUint8(t,e){let n=wr(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,e),this.write(n,t)}getUint16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,e)}setUint16(t,e,n){let o=Ft(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,e,n),this.write(o,t)}getUint32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,e)}setUint32(t,e,n){let o=Ft(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,e,n),this.write(o,t)}getBigUint64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,e)}setBigUint64(t,e,n){let o=Ft(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,e,n),this.write(o,t)}getFloat32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,e)}setFloat32(t,e,n){let o=Ft(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,e,n),this.write(o,t)}getFloat64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,e)}setFloat64(t,e,n){let o=Ft(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,e,n),this.write(o,t)}equals(t){if(t==null||!(t instanceof r)||t.bufs.length!==this.bufs.length)return!1;for(let e=0;e<this.bufs.length;e++)if(!ba(this.bufs[e],t.bufs[e]))return!1;return!0}static fromUint8Arrays(t,e){let n=new r;return n.bufs=t,e==null&&(e=t.reduce((o,s)=>o+s.byteLength,0)),n.length=e,n}};var ko={};V(ko,{base10:()=>ul});var Hm=new Uint8Array(0);function wa(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}function Nt(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return de(r);if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return de(new Uint8Array(r.buffer,r.byteOffset,r.byteLength));throw new Error("Unknown type, must be binary type")}function Ea(r){return new TextEncoder().encode(r)}function va(r){return new TextDecoder().decode(r)}function nl(r){return r?.buffer instanceof ArrayBuffer}function de(r){return nl(r)?r:r.slice()}function ol(r,t){if(r.length>=255)throw new TypeError("Alphabet too long");for(var e=new Uint8Array(256),n=0;n<e.length;n++)e[n]=255;for(var o=0;o<r.length;o++){var s=r.charAt(o),i=s.charCodeAt(0);if(e[i]!==255)throw new TypeError(s+" is ambiguous");e[i]=o}var a=r.length,c=r.charAt(0),f=Math.log(a)/Math.log(256),d=Math.log(256)/Math.log(a);function h(b){if(b instanceof Uint8Array||(ArrayBuffer.isView(b)?b=new Uint8Array(b.buffer,b.byteOffset,b.byteLength):Array.isArray(b)&&(b=Uint8Array.from(b))),!(b instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(b.length===0)return"";for(var x=0,m=0,l=0,g=b.length;l!==g&&b[l]===0;)l++,x++;for(var w=(g-l)*d+1>>>0,_=new Uint8Array(w);l!==g;){for(var A=b[l],D=0,L=w-1;(A!==0||D<m)&&L!==-1;L--,D++)A+=256*_[L]>>>0,_[L]=A%a>>>0,A=A/a>>>0;if(A!==0)throw new Error("Non-zero carry");m=D,l++}for(var B=w-m;B!==w&&_[B]===0;)B++;for(var k=c.repeat(x);B<w;++B)k+=r.charAt(_[B]);return k}function u(b){if(typeof b!="string")throw new TypeError("Expected String");if(b.length===0)return new Uint8Array;var x=0;if(b[x]!==" "){for(var m=0,l=0;b[x]===c;)m++,x++;for(var g=(b.length-x)*f+1>>>0,w=new Uint8Array(g);b[x];){var _=e[b.charCodeAt(x)];if(_===255)return;for(var A=0,D=g-1;(_!==0||A<l)&&D!==-1;D--,A++)_+=a*w[D]>>>0,w[D]=_%256>>>0,_=_/256>>>0;if(_!==0)throw new Error("Non-zero carry");l=A,x++}if(b[x]!==" "){for(var L=g-l;L!==g&&w[L]===0;)L++;for(var B=new Uint8Array(m+(g-L)),k=m;L!==g;)B[k++]=w[L++];return B}}}function p(b){var x=u(b);if(x)return x;throw new Error(`Non-${t} character`)}return{encode:h,decodeUnsafe:u,decode:p}}var sl=ol,il=sl,_a=il;var Co=class{name;prefix;baseEncode;constructor(t,e,n){this.name=t,this.prefix=e,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},Oo=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,e,n){this.name=t,this.prefix=e;let o=e.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return Aa(this,t)}},Ro=class{decoders;constructor(t){this.decoders=t}or(t){return Aa(this,t)}decode(t){let e=t[0],n=this.decoders[e];if(n!=null)return n.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function Aa(r,t){return new Ro({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var Po=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,e,n,o){this.name=t,this.prefix=e,this.baseEncode=n,this.baseDecode=o,this.encoder=new Co(t,e,n),this.decoder=new Oo(t,e,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function Ue({name:r,prefix:t,encode:e,decode:n}){return new Po(r,t,e,n)}function Qt({name:r,prefix:t,alphabet:e}){let{encode:n,decode:o}=_a(e,r);return Ue({prefix:t,name:r,encode:n,decode:s=>Nt(o(s))})}function al(r,t,e,n){let o=r.length;for(;r[o-1]==="=";)--o;let s=new Uint8Array(o*e/8|0),i=0,a=0,c=0;for(let f=0;f<o;++f){let d=t[r[f]];if(d===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<e|d,i+=e,i>=8&&(i-=8,s[c++]=255&a>>i)}if(i>=e||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function cl(r,t,e){let n=t[t.length-1]==="=",o=(1<<e)-1,s="",i=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],i+=8;i>e;)i-=e,s+=t[o&a>>i];if(i!==0&&(s+=t[o&a<<e-i]),n)for(;(s.length*e&7)!==0;)s+="=";return s}function fl(r){let t={};for(let e=0;e<r.length;++e)t[r[e]]=e;return t}function G({name:r,prefix:t,bitsPerChar:e,alphabet:n}){let o=fl(n);return Ue({prefix:t,name:r,encode(s){return cl(s,n,e)},decode(s){return al(s,o,e,r)}})}var ul=Qt({prefix:"9",name:"base10",alphabet:"0123456789"});var Fo={};V(Fo,{base16:()=>ll,base16upper:()=>dl});var ll=G({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),dl=G({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var No={};V(No,{base2:()=>hl});var hl=G({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Uo={};V(Uo,{base256emoji:()=>yl});var Ia=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}"),pl=Ia.reduce((r,t,e)=>(r[e]=t,r),[]),ml=Ia.reduce((r,t,e)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return r[n]=e,r},[]);function gl(r){return r.reduce((t,e)=>(t+=pl[e],t),"")}function bl(r){let t=[];for(let e of r){let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);let o=ml[n];if(o==null)throw new Error(`Non-base256emoji character: ${e}`);t.push(o)}return new Uint8Array(t)}var yl=Ue({prefix:"\u{1F680}",name:"base256emoji",encode:gl,decode:bl});var Mo={};V(Mo,{base32:()=>Me,base32hex:()=>vl,base32hexpad:()=>_l,base32hexpadupper:()=>Al,base32hexupper:()=>Sl,base32pad:()=>wl,base32padupper:()=>El,base32upper:()=>xl,base32z:()=>Il});var Me=G({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),xl=G({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),wl=G({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),El=G({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),vl=G({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Sl=G({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),_l=G({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Al=G({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Il=G({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var zo={};V(zo,{base36:()=>Er,base36upper:()=>Tl});var Er=Qt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Tl=Qt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Ko={};V(Ko,{base58btc:()=>Lt,base58flickr:()=>Bl});var Lt=Qt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Bl=Qt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var qo={};V(qo,{base64:()=>Ll,base64pad:()=>Dl,base64url:()=>Cl,base64urlpad:()=>Ol});var Ll=G({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Dl=G({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Cl=G({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Ol=G({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Vo={};V(Vo,{base8:()=>Rl});var Rl=G({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Ho={};V(Ho,{identity:()=>Pl});var Pl=Ue({prefix:"\0",name:"identity",encode:r=>va(r),decode:r=>Ea(r)});var ig=new TextEncoder,ag=new TextDecoder;var $o={};V($o,{identity:()=>nd});var Nl=La,Ta=128,Ul=127,Ml=~Ul,zl=Math.pow(2,31);function La(r,t,e){t=t||[],e=e||0;for(var n=e;r>=zl;)t[e++]=r&255|Ta,r/=128;for(;r&Ml;)t[e++]=r&255|Ta,r>>>=7;return t[e]=r|0,La.bytes=e-n+1,t}var Kl=jo,ql=128,Ba=127;function jo(r,n){var e=0,n=n||0,o=0,s=n,i,a=r.length;do{if(s>=a)throw jo.bytes=0,new RangeError("Could not decode varint");i=r[s++],e+=o<28?(i&Ba)<<o:(i&Ba)*Math.pow(2,o),o+=7}while(i>=ql);return jo.bytes=s-n,e}var Vl=Math.pow(2,7),Hl=Math.pow(2,14),jl=Math.pow(2,21),$l=Math.pow(2,28),Gl=Math.pow(2,35),Zl=Math.pow(2,42),Yl=Math.pow(2,49),Xl=Math.pow(2,56),Wl=Math.pow(2,63),Ql=function(r){return r<Vl?1:r<Hl?2:r<jl?3:r<$l?4:r<Gl?5:r<Zl?6:r<Yl?7:r<Xl?8:r<Wl?9:10},Jl={encode:Nl,decode:Kl,encodingLength:Ql},td=Jl,vr=td;function Sr(r,t=0){return[vr.decode(r,t),vr.decode.bytes]}function ze(r,t,e=0){return vr.encode(r,t,e),t}function Ke(r){return vr.encodingLength(r)}function Ve(r,t){let e=t.byteLength,n=Ke(r),o=n+Ke(e),s=new Uint8Array(o+e);return ze(r,s,0),ze(e,s,n),s.set(t,o),new qe(r,e,t,s)}function Da(r){let t=Nt(r),[e,n]=Sr(t),[o,s]=Sr(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new qe(e,o,i,t)}function Ca(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&wa(r.bytes,e.bytes)}}var qe=class{code;size;digest;bytes;constructor(t,e,n,o){this.code=t,this.size=e,this.digest=de(n),this.bytes=de(o)}};var Oa=0,ed="identity",Ra=Nt;function rd(r,t){if(t?.truncate!=null&&t.truncate!==r.byteLength){if(t.truncate<0||t.truncate>r.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${r.byteLength}`);r=r.subarray(0,t.truncate)}return Ve(Oa,Ra(r))}var nd={code:Oa,name:ed,encode:Ra,digest:rd};var Yo={};V(Yo,{sha256:()=>sd,sha512:()=>id});var od=20;function Zo({name:r,code:t,encode:e,minDigestLength:n,maxDigestLength:o}){return new Go(r,t,e,n,o)}var Go=class{name;code;encode;minDigestLength;maxDigestLength;constructor(t,e,n,o,s){this.name=t,this.code=e,this.encode=n,this.minDigestLength=o??od,this.maxDigestLength=s}digest(t,e){if(e?.truncate!=null){if(e.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&e.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(t instanceof Uint8Array){let n=this.encode(t);return n instanceof Uint8Array?Pa(n,this.code,e?.truncate):n.then(o=>Pa(o,this.code,e?.truncate))}else throw Error("Unknown type, must be binary type")}};function Pa(r,t,e){if(e!=null&&e!==r.byteLength){if(e>r.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${r.byteLength}`);r=r.subarray(0,e)}return Ve(t,r)}function Fa(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var sd=Zo({name:"sha2-256",code:18,encode:Fa("SHA-256")}),id=Zo({name:"sha2-512",code:19,encode:Fa("SHA-512")});function Na(r,t){let{bytes:e,version:n}=r;return n===0?cd(e,Xo(r),t??Lt.encoder):fd(e,Xo(r),t??Me.encoder)}var Ua=new WeakMap;function Xo(r){let t=Ua.get(r);if(t==null){let e=new Map;return Ua.set(r,e),e}return t}var dn=class r{code;version;multihash;bytes;"/";constructor(t,e,n,o){this.code=e,this.version=t,this.multihash=n,this.bytes=de(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:t,multihash:e}=this;if(t!==Ar)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==ud)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(e)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:t,digest:e}=this.multihash,n=Ve(t,e);return r.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(t){return r.equals(this,t)}static equals(t,e){let n=e;return n!=null&&t.code===n.code&&t.version===n.version&&Ca(t.multihash,n.multihash)}toString(t){return Na(this,t)}toJSON(){return{"/":Na(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(t){if(t==null)return null;let e=t;if(e instanceof r)return e;if(e["/"]!=null&&e["/"]===e.bytes||e.asCID===e){let{version:n,code:o,multihash:s,bytes:i}=e;return new r(n,o,s,i??Ma(n,o,s.bytes))}else if(e[ld]===!0){let{version:n,multihash:o,code:s}=e,i=Da(o);return r.create(n,s,i)}else return null}static create(t,e,n){if(typeof e!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(t){case 0:{if(e!==Ar)throw new Error(`Version 0 CID must use dag-pb (code: ${Ar}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let o=Ma(t,e,n.bytes);return new r(t,e,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,Ar,t)}static createV1(t,e){return r.create(1,t,e)}static decode(t){let[e,n]=r.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return e}static decodeFirst(t){let e=r.inspectBytes(t),n=e.size-e.multihashSize,o=Nt(t.subarray(n,n+e.multihashSize));if(o.byteLength!==e.multihashSize)throw new Error("Incorrect length");let s=o.subarray(e.multihashSize-e.digestSize),i=new qe(e.multihashCode,e.digestSize,s,o);return[e.version===0?r.createV0(i):r.createV1(e.codec,i),t.subarray(e.size)]}static inspectBytes(t){let e=0,n=()=>{let[h,u]=Sr(t.subarray(e));return e+=u,h},o=n(),s=Ar;if(o===18?(o=0,e=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=e,a=n(),c=n(),f=e+c,d=f-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:d,size:f}}static parse(t,e){let[n,o]=ad(t,e),s=r.decode(o);if(s.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Xo(s).set(n,t),s}};function ad(r,t){switch(r[0]){case"Q":{let e=t??Lt;return[Lt.prefix,e.decode(`${Lt.prefix}${r}`)]}case Lt.prefix:{let e=t??Lt;return[Lt.prefix,e.decode(r)]}case Me.prefix:{let e=t??Me;return[Me.prefix,e.decode(r)]}case Er.prefix:{let e=t??Er;return[Er.prefix,e.decode(r)]}default:{if(t==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[r[0],t.decode(r)]}}}function cd(r,t,e){let{prefix:n}=e;if(n!==Lt.prefix)throw Error(`Cannot string encode V0 in ${e.name} encoding`);let o=t.get(n);if(o==null){let s=e.encode(r).slice(1);return t.set(n,s),s}else return o}function fd(r,t,e){let{prefix:n}=e,o=t.get(n);if(o==null){let s=e.encode(r);return t.set(n,s),s}else return o}var Ar=112,ud=18;function Ma(r,t,e){let n=Ke(r),o=n+Ke(t),s=new Uint8Array(o+e.byteLength);return ze(r,s,0),ze(t,s,n),s.set(e,o),s}var ld=Symbol.for("@ipld/js-cid/CID");var Wo={...Ho,...No,...Vo,...ko,...Fo,...Mo,...zo,...Ko,...qo,...Uo},Lg={...Yo,...$o};function za(r=0){return new Uint8Array(r)}function Qo(r=0){return new Uint8Array(r)}function qa(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var Ka=qa("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Jo=qa("ascii","a",r=>{let t="a";for(let e=0;e<r.length;e++)t+=String.fromCharCode(r[e]);return t},r=>{r=r.substring(1);let t=Qo(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),dd={utf8:Ka,"utf-8":Ka,hex:Wo.base16,latin1:Jo,ascii:Jo,binary:Jo,...Wo},hn=dd;function ft(r,t="utf8"){let e=hn[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.decoder.decode(`${e.prefix}${r}`)}function yt(r,t="utf8"){let e=hn[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.encoder.encode(r).substring(1)}var hd=parseInt("11111",2),ts=parseInt("10000000",2),pd=parseInt("01111111",2),Va={0:Ir,1:Ir,2:md,3:yd,4:xd,5:bd,6:gd,16:Ir,22:Ir,48:Ir};function es(r,t={offset:0}){let e=r[t.offset]&hd;if(t.offset++,Va[e]!=null)return Va[e](r,t);throw new Error("No decoder for tag "+e)}function Tr(r,t){let e=0;if((r[t.offset]&ts)===ts){let n=r[t.offset]&pd,o="0x";t.offset++;for(let s=0;s<n;s++,t.offset++)o+=r[t.offset].toString(16).padStart(2,"0");e=parseInt(o,16)}else e=r[t.offset],t.offset++;return e}function Ir(r,t){Tr(r,t);let e=[];for(;!(t.offset>=r.byteLength);){let n=es(r,t);if(n===null)break;e.push(n)}return e}function md(r,t){let e=Tr(r,t),n=t.offset,o=t.offset+e,s=[];for(let i=n;i<o;i++)i===n&&r[i]===0||s.push(r[i]);return t.offset+=e,Uint8Array.from(s)}function gd(r,t){let e=Tr(r,t),n=t.offset+e,o=r[t.offset];t.offset++;let s=0,i=0;o<40?(s=0,i=o):o<80?(s=1,i=o-40):(s=2,i=o-80);let a=`${s}.${i}`,c=[];for(;t.offset<n;){let f=r[t.offset];if(t.offset++,c.push(f&127),f<128){c.reverse();let d=0;for(let h=0;h<c.length;h++)d+=c[h]<<h*7;a+=`.${d}`,c=[]}}return a}function bd(r,t){return t.offset++,null}function yd(r,t){let e=Tr(r,t),n=r[t.offset];t.offset++;let o=r.subarray(t.offset,t.offset+e-1);if(t.offset+=e,n!==0)throw new Error("Unused bits in bit string is unimplemented");return o}function xd(r,t){let e=Tr(r,t),n=r.subarray(t.offset,t.offset+e);return t.offset+=e,n}function wd(r){let t=r.toString(16);t.length%2===1&&(t="0"+t);let e=new rt;for(let n=0;n<t.length;n+=2)e.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return e}function rs(r){if(r.byteLength<128)return Uint8Array.from([r.byteLength]);let t=wd(r.byteLength);return new rt(Uint8Array.from([t.byteLength|ts]),t)}function Ha(r){let t=new rt,e=128;return(r.subarray()[0]&e)===e&&t.append(Uint8Array.from([0])),t.append(r),new rt(Uint8Array.from([2]),rs(t),t)}function ja(r){let t=Uint8Array.from([0]),e=new rt(t,r);return new rt(Uint8Array.from([3]),rs(e),e)}function pn(r,t=48){let e=new rt;for(let n of r)e.append(n);return new rt(Uint8Array.from([t]),rs(e),e)}var Ed=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),vd=Uint8Array.from([6,5,43,129,4,0,34]),Sd=Uint8Array.from([6,5,43,129,4,0,35]),_d={ext:!0,kty:"EC",crv:"P-256"},Ad={ext:!0,kty:"EC",crv:"P-384"},Id={ext:!0,kty:"EC",crv:"P-521"},ns=32,os=48,ss=66;function $a(r){let t=es(r);return Ga(t)}function Ga(r){let t=r[1][1][0],e=1,n,o;if(t.byteLength===ns*2+1)return n=yt(t.subarray(e,e+ns),"base64url"),o=yt(t.subarray(e+ns),"base64url"),new He({..._d,key_ops:["verify"],x:n,y:o});if(t.byteLength===os*2+1)return n=yt(t.subarray(e,e+os),"base64url"),o=yt(t.subarray(e+os),"base64url"),new He({...Ad,key_ops:["verify"],x:n,y:o});if(t.byteLength===ss*2+1)return n=yt(t.subarray(e,e+ss),"base64url"),o=yt(t.subarray(e+ss),"base64url"),new He({...Id,key_ops:["verify"],x:n,y:o});throw new dt(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function Za(r){return pn([Ha(Uint8Array.from([1])),pn([Td(r.crv)],160),pn([ja(new rt(Uint8Array.from([4]),ft(r.x??"","base64url"),ft(r.y??"","base64url")))],161)]).subarray()}function Td(r){if(r==="P-256")return Ed;if(r==="P-384")return vd;if(r==="P-521")return Sd;throw new dt(`Invalid curve ${r}`)}var He=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=Za(this.jwk)),this._raw}toMultihash(){return xt.digest(je(this))}toCID(){return ct.createV1(114,this.toMultihash())}toString(){return X.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:wt(this.raw,t.raw)}async verify(t,e,n){return ga(this.jwk,e,t,n)}};function is(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in r&&r.BYTES_PER_ELEMENT===1}function Jt(r,t=""){if(typeof r!="number"){let e=t&&`"${t}" `;throw new TypeError(`${e}expected number, got ${typeof r}`)}if(!Number.isSafeInteger(r)||r<0){let e=t&&`"${t}" `;throw new RangeError(`${e}expected integer >= 0, got ${r}`)}}function gt(r,t,e=""){let n=is(r),o=r?.length,s=t!==void 0;if(!n||s&&o!==t){let i=e&&`"${e}" `,a=s?` of length ${t}`:"",c=n?`length=${o}`:`type=${typeof r}`,f=i+"expected Uint8Array"+a+", got "+c;throw n?new RangeError(f):new TypeError(f)}return r}function mn(r){if(typeof r!="function"||typeof r.create!="function")throw new TypeError("Hash must wrapped by utils.createHasher");if(Jt(r.outputLen),Jt(r.blockLen),r.outputLen<1)throw new Error('"outputLen" must be >= 1');if(r.blockLen<1)throw new Error('"blockLen" must be >= 1')}function $e(r,t=!0){if(r.destroyed)throw new Error("Hash instance has been destroyed");if(t&&r.finished)throw new Error("Hash#digest() has already been called")}function gn(r,t){gt(r,void 0,"digestInto() output");let e=t.outputLen;if(r.length<e)throw new RangeError('"digestInto() output" expected to be of length >='+e)}function Mt(...r){for(let t=0;t<r.length;t++)r[t].fill(0)}function bn(r){return new DataView(r.buffer,r.byteOffset,r.byteLength)}function Et(r,t){return r<<32-t|r>>>t}var Xa=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Bd=Array.from({length:256},(r,t)=>t.toString(16).padStart(2,"0"));function yn(r){if(gt(r),Xa)return r.toHex();let t="";for(let e=0;e<r.length;e++)t+=Bd[r[e]];return t}var Ut={_0:48,_9:57,A:65,F:70,a:97,f:102};function Ya(r){if(r>=Ut._0&&r<=Ut._9)return r-Ut._0;if(r>=Ut.A&&r<=Ut.F)return r-(Ut.A-10);if(r>=Ut.a&&r<=Ut.f)return r-(Ut.a-10)}function Br(r){if(typeof r!="string")throw new TypeError("hex string expected, got "+typeof r);if(Xa)try{return Uint8Array.fromHex(r)}catch(o){throw o instanceof SyntaxError?new RangeError(o.message):o}let t=r.length,e=t/2;if(t%2)throw new RangeError("hex string expected, got unpadded hex of length "+t);let n=new Uint8Array(e);for(let o=0,s=0;o<e;o++,s+=2){let i=Ya(r.charCodeAt(s)),a=Ya(r.charCodeAt(s+1));if(i===void 0||a===void 0){let c=r[s]+r[s+1];throw new RangeError('hex string expected, got non-hex character "'+c+'" at index '+s)}n[o]=i*16+a}return n}function as(...r){let t=0;for(let n=0;n<r.length;n++){let o=r[n];gt(o),t+=o.length}let e=new Uint8Array(t);for(let n=0,o=0;n<r.length;n++){let s=r[n];e.set(s,o),o+=s.length}return e}function cs(r,t={}){let e=(o,s)=>r(s).update(o).digest(),n=r(void 0);return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.canXOF=n.canXOF,e.create=o=>r(o),Object.assign(e,t),Object.freeze(e)}function Wa(r=32){Jt(r,"bytesLength");let t=typeof globalThis=="object"?globalThis.crypto:null;if(typeof t?.getRandomValues!="function")throw new Error("crypto.getRandomValues must be defined");if(r>65536)throw new RangeError(`"bytesLength" expected <= 65536, got ${r}`);return t.getRandomValues(new Uint8Array(r))}var fs=r=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,r])});function Qa(r,t,e){return r&t^~r&e}function Ja(r,t,e){return r&t^r&e^t&e}var Lr=class{blockLen;outputLen;canXOF=!1;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(t,e,n,o){this.blockLen=t,this.outputLen=e,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(t),this.view=bn(this.buffer)}update(t){$e(this),gt(t);let{view:e,buffer:n,blockLen:o}=this,s=t.length;for(let i=0;i<s;){let a=Math.min(o-this.pos,s-i);if(a===o){let c=bn(t);for(;o<=s-i;i+=o)this.process(c,i);continue}n.set(t.subarray(i,i+a),this.pos),this.pos+=a,i+=a,this.pos===o&&(this.process(e,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){$e(this),gn(t,this),this.finished=!0;let{buffer:e,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;e[i++]=128,Mt(this.buffer.subarray(i)),this.padOffset>o-i&&(this.process(n,0),i=0);for(let h=i;h<o;h++)e[h]=0;n.setBigUint64(o-8,BigInt(this.length*8),s),this.process(n,0);let a=bn(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen must be aligned to 32bit");let f=c/4,d=this.get();if(f>d.length)throw new Error("_sha2: outputLen bigger than state");for(let h=0;h<f;h++)a.setUint32(4*h,d[h],s)}digest(){let{buffer:t,outputLen:e}=this;this.digestInto(t);let n=t.slice(0,e);return this.destroy(),n}_cloneInto(t){t||=new this.constructor,t.set(...this.get());let{blockLen:e,buffer:n,length:o,finished:s,destroyed:i,pos:a}=this;return t.destroyed=i,t.finished=s,t.length=o,t.pos=a,o%e&&t.buffer.set(n),t}clone(){return this._cloneInto()}},zt=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var st=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var xn=BigInt(4294967295),tc=BigInt(32);function Ld(r,t=!1){return t?{h:Number(r&xn),l:Number(r>>tc&xn)}:{h:Number(r>>tc&xn)|0,l:Number(r&xn)|0}}function ec(r,t=!1){let e=r.length,n=new Uint32Array(e),o=new Uint32Array(e);for(let s=0;s<e;s++){let{h:i,l:a}=Ld(r[s],t);[n[s],o[s]]=[i,a]}return[n,o]}var us=(r,t,e)=>r>>>e,ls=(r,t,e)=>r<<32-e|t>>>e,he=(r,t,e)=>r>>>e|t<<32-e,pe=(r,t,e)=>r<<32-e|t>>>e,Dr=(r,t,e)=>r<<64-e|t>>>e-32,Cr=(r,t,e)=>r>>>e-32|t<<64-e;function Dt(r,t,e,n){let o=(t>>>0)+(n>>>0);return{h:r+e+(o/2**32|0)|0,l:o|0}}var rc=(r,t,e)=>(r>>>0)+(t>>>0)+(e>>>0),nc=(r,t,e,n)=>t+e+n+(r/2**32|0)|0,oc=(r,t,e,n)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0),sc=(r,t,e,n,o)=>t+e+n+o+(r/2**32|0)|0,ic=(r,t,e,n,o)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0)+(o>>>0),ac=(r,t,e,n,o,s)=>t+e+n+o+s+(r/2**32|0)|0;var Cd=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),te=new Uint32Array(64),ds=class extends Lr{constructor(t){super(64,t,8,!1)}get(){let{A:t,B:e,C:n,D:o,E:s,F:i,G:a,H:c}=this;return[t,e,n,o,s,i,a,c]}set(t,e,n,o,s,i,a,c){this.A=t|0,this.B=e|0,this.C=n|0,this.D=o|0,this.E=s|0,this.F=i|0,this.G=a|0,this.H=c|0}process(t,e){for(let h=0;h<16;h++,e+=4)te[h]=t.getUint32(e,!1);for(let h=16;h<64;h++){let u=te[h-15],p=te[h-2],b=Et(u,7)^Et(u,18)^u>>>3,x=Et(p,17)^Et(p,19)^p>>>10;te[h]=x+te[h-7]+b+te[h-16]|0}let{A:n,B:o,C:s,D:i,E:a,F:c,G:f,H:d}=this;for(let h=0;h<64;h++){let u=Et(a,6)^Et(a,11)^Et(a,25),p=d+u+Qa(a,c,f)+Cd[h]+te[h]|0,x=(Et(n,2)^Et(n,13)^Et(n,22))+Ja(n,o,s)|0;d=f,f=c,c=a,a=i+p|0,i=s,s=o,o=n,n=p+x|0}n=n+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,a=a+this.E|0,c=c+this.F|0,f=f+this.G|0,d=d+this.H|0,this.set(n,o,s,i,a,c,f,d)}roundClean(){Mt(te)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),Mt(this.buffer)}},hs=class extends ds{A=zt[0]|0;B=zt[1]|0;C=zt[2]|0;D=zt[3]|0;E=zt[4]|0;F=zt[5]|0;G=zt[6]|0;H=zt[7]|0;constructor(){super(32)}};var cc=ec(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(r=>BigInt(r))),Od=cc[0],Rd=cc[1],ee=new Uint32Array(80),re=new Uint32Array(80),ps=class extends Lr{constructor(t){super(128,t,16,!1)}get(){let{Ah:t,Al:e,Bh:n,Bl:o,Ch:s,Cl:i,Dh:a,Dl:c,Eh:f,El:d,Fh:h,Fl:u,Gh:p,Gl:b,Hh:x,Hl:m}=this;return[t,e,n,o,s,i,a,c,f,d,h,u,p,b,x,m]}set(t,e,n,o,s,i,a,c,f,d,h,u,p,b,x,m){this.Ah=t|0,this.Al=e|0,this.Bh=n|0,this.Bl=o|0,this.Ch=s|0,this.Cl=i|0,this.Dh=a|0,this.Dl=c|0,this.Eh=f|0,this.El=d|0,this.Fh=h|0,this.Fl=u|0,this.Gh=p|0,this.Gl=b|0,this.Hh=x|0,this.Hl=m|0}process(t,e){for(let w=0;w<16;w++,e+=4)ee[w]=t.getUint32(e),re[w]=t.getUint32(e+=4);for(let w=16;w<80;w++){let _=ee[w-15]|0,A=re[w-15]|0,D=he(_,A,1)^he(_,A,8)^us(_,A,7),L=pe(_,A,1)^pe(_,A,8)^ls(_,A,7),B=ee[w-2]|0,k=re[w-2]|0,q=he(B,k,19)^Dr(B,k,61)^us(B,k,6),F=pe(B,k,19)^Cr(B,k,61)^ls(B,k,6),y=oc(L,F,re[w-7],re[w-16]),E=sc(y,D,q,ee[w-7],ee[w-16]);ee[w]=E|0,re[w]=y|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:a,Cl:c,Dh:f,Dl:d,Eh:h,El:u,Fh:p,Fl:b,Gh:x,Gl:m,Hh:l,Hl:g}=this;for(let w=0;w<80;w++){let _=he(h,u,14)^he(h,u,18)^Dr(h,u,41),A=pe(h,u,14)^pe(h,u,18)^Cr(h,u,41),D=h&p^~h&x,L=u&b^~u&m,B=ic(g,A,L,Rd[w],re[w]),k=ac(B,l,_,D,Od[w],ee[w]),q=B|0,F=he(n,o,28)^Dr(n,o,34)^Dr(n,o,39),y=pe(n,o,28)^Cr(n,o,34)^Cr(n,o,39),E=n&s^n&a^s&a,I=o&i^o&c^i&c;l=x|0,g=m|0,x=p|0,m=b|0,p=h|0,b=u|0,{h,l:u}=Dt(f|0,d|0,k|0,q|0),f=a|0,d=c|0,a=s|0,c=i|0,s=n|0,i=o|0;let S=rc(q,y,I);n=nc(S,k,F,E),o=S|0}({h:n,l:o}=Dt(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=Dt(this.Bh|0,this.Bl|0,s|0,i|0),{h:a,l:c}=Dt(this.Ch|0,this.Cl|0,a|0,c|0),{h:f,l:d}=Dt(this.Dh|0,this.Dl|0,f|0,d|0),{h,l:u}=Dt(this.Eh|0,this.El|0,h|0,u|0),{h:p,l:b}=Dt(this.Fh|0,this.Fl|0,p|0,b|0),{h:x,l:m}=Dt(this.Gh|0,this.Gl|0,x|0,m|0),{h:l,l:g}=Dt(this.Hh|0,this.Hl|0,l|0,g|0),this.set(n,o,s,i,a,c,f,d,h,u,p,b,x,m,l,g)}roundClean(){Mt(ee,re)}destroy(){this.destroyed=!0,Mt(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},ms=class extends ps{Ah=st[0]|0;Al=st[1]|0;Bh=st[2]|0;Bl=st[3]|0;Ch=st[4]|0;Cl=st[5]|0;Dh=st[6]|0;Dl=st[7]|0;Eh=st[8]|0;El=st[9]|0;Fh=st[10]|0;Fl=st[11]|0;Gh=st[12]|0;Gl=st[13]|0;Hh=st[14]|0;Hl=st[15]|0;constructor(){super(64)}};var fc=cs(()=>new hs,fs(1));var wn=cs(()=>new ms,fs(3));var M=(r,t,e)=>gt(r,t,e),bs=Jt,Ge=yn,J=(...r)=>as(...r),Ze=r=>Br(r),me=is,Or=r=>Wa(r),vn=BigInt(0),gs=BigInt(1);function vt(r,t=""){if(typeof r!="boolean"){let e=t&&`"${t}" `;throw new TypeError(e+"expected boolean, got type="+typeof r)}return r}function Sn(r){if(typeof r=="bigint"){if(!En(r))throw new RangeError("positive bigint expected, got "+r)}else bs(r);return r}function St(r,t=""){if(typeof r!="number"){let e=t&&`"${t}" `;throw new TypeError(e+"expected number, got type="+typeof r)}if(!Number.isSafeInteger(r)){let e=t&&`"${t}" `;throw new RangeError(e+"expected safe integer, got "+r)}}function Rr(r){let t=Sn(r).toString(16);return t.length&1?"0"+t:t}function uc(r){if(typeof r!="string")throw new TypeError("hex string expected, got "+typeof r);return r===""?vn:BigInt("0x"+r)}function ge(r){return uc(yn(r))}function Ct(r){return uc(yn(Pr(gt(r)).reverse()))}function _n(r,t){if(Jt(t),t===0)throw new RangeError("zero length");r=Sn(r);let e=r.toString(16);if(e.length>t*2)throw new RangeError("number too large");return Br(e.padStart(t*2,"0"))}function ys(r,t){return _n(r,t).reverse()}function lc(r,t){if(r=M(r),t=M(t),r.length!==t.length)return!1;let e=0;for(let n=0;n<r.length;n++)e|=r[n]^t[n];return e===0}function Pr(r){return Uint8Array.from(M(r))}function An(r){if(typeof r!="string")throw new TypeError("ascii string expected, got "+typeof r);return Uint8Array.from(r,(t,e)=>{let n=t.charCodeAt(0);if(t.length!==1||n>127)throw new RangeError(`string contains non-ASCII character "${r[e]}" with code ${n} at position ${e}`);return n})}var En=r=>typeof r=="bigint"&&vn<=r;function Pd(r,t,e){return En(r)&&En(t)&&En(e)&&t<=r&&r<e}function Ye(r,t,e,n){if(!Pd(t,e,n))throw new RangeError("expected valid "+r+": "+e+" <= n < "+n+", got "+t)}function Xe(r){if(r<vn)throw new Error("expected non-negative bigint, got "+r);let t;for(t=0;r>vn;r>>=gs,t+=1);return t}var kr=r=>(gs<<BigInt(r))-gs;function dc(r,t,e){if(Jt(r,"hashLen"),Jt(t,"qByteLen"),typeof e!="function")throw new TypeError("hmacFn must be a function");let n=m=>new Uint8Array(m),o=Uint8Array.of(),s=Uint8Array.of(0),i=Uint8Array.of(1),a=1e3,c=n(r),f=n(r),d=0,h=()=>{c.fill(1),f.fill(0),d=0},u=(...m)=>e(f,J(c,...m)),p=(m=o)=>{f=u(s,m),c=u(),m.length!==0&&(f=u(i,m),c=u())},b=()=>{if(d++>=a)throw new Error("drbg: tried max amount of iterations");let m=0,l=[];for(;m<t;){c=u();let g=c.slice();l.push(g),m+=c.length}return J(...l)};return(m,l)=>{h(),p(m);let g;for(;(g=l(b()))===void 0;)p();return h(),g}}function _t(r,t={},e={}){if(Object.prototype.toString.call(r)!=="[object Object]")throw new TypeError("expected valid options object");function n(s,i,a){if(!a&&i!=="function"&&!Object.hasOwn(r,s))throw new TypeError(`param "${s}" is invalid: expected own property`);let c=r[s];if(a&&c===void 0)return;let f=typeof c;if(f!==i||c===null)throw new TypeError(`param "${s}" is invalid: expected ${i}, got ${f}`)}let o=(s,i)=>Object.entries(s).forEach(([a,c])=>n(a,c,i));o(t,!1),o(e,!0)}var xs=()=>{throw new Error("not implemented")};var it=BigInt(0),Z=BigInt(1),be=BigInt(2),gc=BigInt(3),bc=BigInt(4),yc=BigInt(5),kd=BigInt(7),xc=BigInt(8),Fd=BigInt(9),wc=BigInt(16);function W(r,t){if(t<=it)throw new Error("mod: expected positive modulus, got "+t);let e=r%t;return e>=it?e:t+e}function j(r,t,e){if(t<it)throw new Error("pow2: expected non-negative exponent, got "+t);let n=r;for(;t-- >it;)n*=n,n%=e;return n}function hc(r,t){if(r===it)throw new Error("invert: expected non-zero number");if(t<=it)throw new Error("invert: expected positive modulus, got "+t);let e=W(r,t),n=t,o=it,s=Z,i=Z,a=it;for(;e!==it;){let f=n/e,d=n-e*f,h=o-i*f,u=s-a*f;n=e,e=d,o=i,s=a,i=h,a=u}if(n!==Z)throw new Error("invert: does not exist");return W(o,t)}function ws(r,t,e){let n=r;if(!n.eql(n.sqr(t),e))throw new Error("Cannot find square root")}function Ec(r,t){let e=r,n=(e.ORDER+Z)/bc,o=e.pow(t,n);return ws(e,o,t),o}function Nd(r,t){let e=r,n=(e.ORDER-yc)/xc,o=e.mul(t,be),s=e.pow(o,n),i=e.mul(t,s),a=e.mul(e.mul(i,be),s),c=e.mul(i,e.sub(a,e.ONE));return ws(e,c,t),c}function Ud(r){let t=We(r),e=vc(r),n=e(t,t.neg(t.ONE)),o=e(t,n),s=e(t,t.neg(n)),i=(r+kd)/wc;return((a,c)=>{let f=a,d=f.pow(c,i),h=f.mul(d,n),u=f.mul(d,o),p=f.mul(d,s),b=f.eql(f.sqr(h),c),x=f.eql(f.sqr(u),c);d=f.cmov(d,h,b),h=f.cmov(p,u,x);let m=f.eql(f.sqr(h),c),l=f.cmov(d,h,m);return ws(f,l,c),l})}function vc(r){if(r<gc)throw new Error("sqrt is not defined for small field");let t=r-Z,e=0;for(;t%be===it;)t/=be,e++;let n=be,o=We(r);for(;pc(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(e===1)return Ec;let s=o.pow(n,t),i=(t+Z)/be;return function(c,f){let d=c;if(d.is0(f))return f;if(pc(d,f)!==1)throw new Error("Cannot find square root");let h=e,u=d.mul(d.ONE,s),p=d.pow(f,t),b=d.pow(f,i);for(;!d.eql(p,d.ONE);){if(d.is0(p))return d.ZERO;let x=1,m=d.sqr(p);for(;!d.eql(m,d.ONE);)if(x++,m=d.sqr(m),x===h)throw new Error("Cannot find square root");let l=Z<<BigInt(h-x-1),g=d.pow(u,l);h=x,u=d.sqr(g),p=d.mul(p,u),b=d.mul(b,g)}return b}}function Md(r){return r%bc===gc?Ec:r%xc===yc?Nd:r%wc===Fd?Ud(r):vc(r)}var Kt=(r,t)=>(W(r,t)&Z)===Z,zd=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Es(r){let t={ORDER:"bigint",BYTES:"number",BITS:"number"},e=zd.reduce((n,o)=>(n[o]="function",n),t);if(_t(r,e),St(r.BYTES,"BYTES"),St(r.BITS,"BITS"),r.BYTES<1||r.BITS<1)throw new Error("invalid field: expected BYTES/BITS > 0");if(r.ORDER<=Z)throw new Error("invalid field: expected ORDER > 1, got "+r.ORDER);return r}function Kd(r,t,e){let n=r;if(e<it)throw new Error("invalid exponent, negatives unsupported");if(e===it)return n.ONE;if(e===Z)return t;let o=n.ONE,s=t;for(;e>it;)e&Z&&(o=n.mul(o,s)),s=n.sqr(s),e>>=Z;return o}function Fr(r,t,e=!1){let n=r,o=new Array(t.length).fill(e?n.ZERO:void 0),s=t.reduce((a,c,f)=>n.is0(c)?a:(o[f]=a,n.mul(a,c)),n.ONE),i=n.inv(s);return t.reduceRight((a,c,f)=>n.is0(c)?a:(o[f]=n.mul(a,o[f]),n.mul(a,c)),i),o}function pc(r,t){let e=r,n=(e.ORDER-Z)/be,o=e.pow(t,n),s=e.eql(o,e.ONE),i=e.eql(o,e.ZERO),a=e.eql(o,e.neg(e.ONE));if(!s&&!i&&!a)throw new Error("invalid Legendre symbol result");return s?1:i?0:-1}function qd(r,t){if(t!==void 0&&bs(t),r<=it)throw new Error("invalid n length: expected positive n, got "+r);if(t!==void 0&&t<1)throw new Error("invalid n length: expected positive bit length, got "+t);let e=Xe(r);if(t!==void 0&&t<e)throw new Error(`invalid n length: expected bit length (${e}) >= n.length (${t})`);let n=t!==void 0?t:e,o=Math.ceil(n/8);return{nBitLength:n,nByteLength:o}}var mc=new WeakMap,In=class{ORDER;BITS;BYTES;isLE;ZERO=it;ONE=Z;_lengths;_mod;constructor(t,e={}){if(t<=Z)throw new Error("invalid field: expected ORDER > 1, got "+t);let n;this.isLE=!1,e!=null&&typeof e=="object"&&(typeof e.BITS=="number"&&(n=e.BITS),typeof e.sqrt=="function"&&Object.defineProperty(this,"sqrt",{value:e.sqrt,enumerable:!0}),typeof e.isLE=="boolean"&&(this.isLE=e.isLE),e.allowedLengths&&(this._lengths=Object.freeze(e.allowedLengths.slice())),typeof e.modFromBytes=="boolean"&&(this._mod=e.modFromBytes));let{nBitLength:o,nByteLength:s}=qd(t,n);if(s>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");this.ORDER=t,this.BITS=o,this.BYTES=s,Object.freeze(this)}create(t){return W(t,this.ORDER)}isValid(t){if(typeof t!="bigint")throw new TypeError("invalid field element: expected bigint, got "+typeof t);return it<=t&&t<this.ORDER}is0(t){return t===it}isValidNot0(t){return!this.is0(t)&&this.isValid(t)}isOdd(t){return(t&Z)===Z}neg(t){return W(-t,this.ORDER)}eql(t,e){return t===e}sqr(t){return W(t*t,this.ORDER)}add(t,e){return W(t+e,this.ORDER)}sub(t,e){return W(t-e,this.ORDER)}mul(t,e){return W(t*e,this.ORDER)}pow(t,e){return Kd(this,t,e)}div(t,e){return W(t*hc(e,this.ORDER),this.ORDER)}sqrN(t){return t*t}addN(t,e){return t+e}subN(t,e){return t-e}mulN(t,e){return t*e}inv(t){return hc(t,this.ORDER)}sqrt(t){let e=mc.get(this);return e||mc.set(this,e=Md(this.ORDER)),e(this,t)}toBytes(t){return this.isLE?ys(t,this.BYTES):_n(t,this.BYTES)}fromBytes(t,e=!1){M(t);let{_lengths:n,BYTES:o,isLE:s,ORDER:i,_mod:a}=this;if(n){if(t.length<1||!n.includes(t.length)||t.length>o)throw new Error("Field.fromBytes: expected "+n+" bytes, got "+t.length);let f=new Uint8Array(o);f.set(t,s?0:f.length-t.length),t=f}if(t.length!==o)throw new Error("Field.fromBytes: expected "+o+" bytes, got "+t.length);let c=s?Ct(t):ge(t);if(a&&(c=W(c,i)),!e&&!this.isValid(c))throw new Error("invalid field element: outside of range 0..ORDER");return c}invertBatch(t){return Fr(this,t)}cmov(t,e,n){return vt(n,"condition"),n?e:t}};Object.freeze(In.prototype);function We(r,t={}){return new In(r,t)}function Sc(r){if(typeof r!="bigint")throw new Error("field order must be bigint");if(r<=Z)throw new Error("field order must be greater than 1");let t=Xe(r-Z);return Math.ceil(t/8)}function vs(r){let t=Sc(r);return t+Math.ceil(t/2)}function Ss(r,t,e=!1){M(r);let n=r.length,o=Sc(t),s=Math.max(vs(t),16);if(n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=e?Ct(r):ge(r),a=W(i,t-Z)+Z;return e?ys(a,o):_n(a,o)}var Qe=BigInt(0),ye=BigInt(1);function Nr(r,t){let e=t.negate();return r?e:t}function xe(r,t){let e=Fr(r.Fp,t.map(n=>n.Z));return t.map((n,o)=>r.fromAffine(n.toAffine(e[o])))}function Tc(r,t){if(!Number.isSafeInteger(r)||r<=0||r>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+r)}function _s(r,t){Tc(r,t);let e=Math.ceil(t/r)+1,n=2**(r-1),o=2**r,s=kr(r),i=BigInt(r);return{windows:e,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function _c(r,t,e){let{windowSize:n,mask:o,maxNumber:s,shiftBy:i}=e,a=Number(r&o),c=r>>i;a>n&&(a-=s,c+=ye);let f=t*n,d=f+Math.abs(a)-1,h=a===0,u=a<0,p=t%2!==0;return{nextN:c,offset:d,isZero:h,isNeg:u,isNegF:p,offsetF:f}}var As=new WeakMap,Bc=new WeakMap;function Is(r){return Bc.get(r)||1}function Ac(r){if(r!==Qe)throw new Error("invalid wNAF")}var Je=class{BASE;ZERO;Fn;bits;constructor(t,e){this.BASE=t.BASE,this.ZERO=t.ZERO,this.Fn=t.Fn,this.bits=e}_unsafeLadder(t,e,n=this.ZERO){let o=t;for(;e>Qe;)e&ye&&(n=n.add(o)),o=o.double(),e>>=ye;return n}precomputeWindow(t,e){let{windows:n,windowSize:o}=_s(e,this.bits),s=[],i=t,a=i;for(let c=0;c<n;c++){a=i,s.push(a);for(let f=1;f<o;f++)a=a.add(i),s.push(a);i=a.double()}return s}wNAF(t,e,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let o=this.ZERO,s=this.BASE,i=_s(t,this.bits);for(let a=0;a<i.windows;a++){let{nextN:c,offset:f,isZero:d,isNeg:h,isNegF:u,offsetF:p}=_c(n,a,i);n=c,d?s=s.add(Nr(u,e[p])):o=o.add(Nr(h,e[f]))}return Ac(n),{p:o,f:s}}wNAFUnsafe(t,e,n,o=this.ZERO){let s=_s(t,this.bits);for(let i=0;i<s.windows&&n!==Qe;i++){let{nextN:a,offset:c,isZero:f,isNeg:d}=_c(n,i,s);if(n=a,!f){let h=e[c];o=o.add(d?h.negate():h)}}return Ac(n),o}getPrecomputes(t,e,n){let o=As.get(e);return o||(o=this.precomputeWindow(e,t),t!==1&&(typeof n=="function"&&(o=n(o)),As.set(e,o))),o}cached(t,e,n){let o=Is(t);return this.wNAF(o,this.getPrecomputes(o,t,n),e)}unsafe(t,e,n,o){let s=Is(t);return s===1?this._unsafeLadder(t,e,o):this.wNAFUnsafe(s,this.getPrecomputes(s,t,n),e,o)}createCache(t,e){Tc(e,this.bits),Bc.set(t,e),As.delete(t)}hasCache(t){return Is(t)!==1}};function Lc(r,t,e,n){let o=t,s=r.ZERO,i=r.ZERO;for(;e>Qe||n>Qe;)e&ye&&(s=s.add(o)),n&ye&&(i=i.add(o)),o=o.double(),e>>=ye,n>>=ye;return{p1:s,p2:i}}function Ic(r,t,e){if(t){if(t.ORDER!==r)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return Es(t),t}else return We(r,{isLE:e})}function Tn(r,t,e={},n){if(n===void 0&&(n=r==="edwards"),!t||typeof t!="object")throw new Error(`expected valid ${r} CURVE object`);for(let c of["p","n","h"]){let f=t[c];if(!(typeof f=="bigint"&&f>Qe))throw new Error(`CURVE.${c} must be positive bigint`)}let o=Ic(t.p,e.Fp,n),s=Ic(t.n,e.Fn,n),a=["Gx","Gy","a",r==="weierstrass"?"b":"d"];for(let c of a)if(!o.isValid(t[c]))throw new Error(`CURVE.${c} must be valid field element of CURVE.Fp`);return t=Object.freeze(Object.assign({},t)),{CURVE:t,Fp:o,Fn:s}}function Bn(r,t){return function(n){let o=r(n);return{secretKey:o,publicKey:t(o)}}}var ne=BigInt(0),nt=BigInt(1),Ts=BigInt(2),Vd=BigInt(8);function Hd(r,t,e,n){let o=r.sqr(e),s=r.sqr(n),i=r.add(r.mul(t.a,o),s),a=r.add(r.ONE,r.mul(t.d,r.mul(o,s)));return r.eql(i,a)}function Dc(r,t={}){let e=t,n=Tn("edwards",r,e,e.FpFnLE),{Fp:o,Fn:s}=n,i=n.CURVE,{h:a}=i;_t(e,{},{uvRatio:"function"});let c=Ts<<BigInt(s.BYTES*8)-nt,f=x=>o.create(x),d=e.uvRatio===void 0?(x,m)=>{try{return{isValid:!0,value:o.sqrt(o.div(x,m))}}catch{return{isValid:!1,value:ne}}}:e.uvRatio;if(!Hd(o,i,i.Gx,i.Gy))throw new Error("bad curve params: generator point");function h(x,m,l=!1){let g=l?nt:ne;return Ye("coordinate "+x,m,g,c),m}function u(x){if(!(x instanceof p))throw new Error("EdwardsPoint expected")}class p{static BASE=new p(i.Gx,i.Gy,nt,f(i.Gx*i.Gy));static ZERO=new p(ne,nt,nt,ne);static Fp=o;static Fn=s;X;Y;Z;T;constructor(m,l,g,w){this.X=h("x",m),this.Y=h("y",l),this.Z=h("z",g,!0),this.T=h("t",w),Object.freeze(this)}static CURVE(){return i}static fromAffine(m){if(m instanceof p)throw new Error("extended point not allowed");let{x:l,y:g}=m||{};return h("x",l),h("y",g),new p(l,g,nt,f(l*g))}static fromBytes(m,l=!1){let g=o.BYTES,{a:w,d:_}=i;m=Pr(M(m,g,"point")),vt(l,"zip215");let A=Pr(m),D=m[g-1];A[g-1]=D&-129;let L=Ct(A),B=l?c:o.ORDER;Ye("point.y",L,ne,B);let k=f(L*L),q=f(k-nt),F=f(_*k-w),{isValid:y,value:E}=d(q,F);if(!y)throw new Error("bad point: invalid y coordinate");let I=(E&nt)===nt,S=(D&128)!==0;if(!l&&E===ne&&S)throw new Error("bad point: x=0 and x_0=1");return S!==I&&(E=f(-E)),p.fromAffine({x:E,y:L})}static fromHex(m,l=!1){return p.fromBytes(Ze(m),l)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(m=8,l=!0){return b.createCache(this,m),l||this.multiply(Ts),this}assertValidity(){let m=this,{a:l,d:g}=i;if(m.is0())throw new Error("bad point: ZERO");let{X:w,Y:_,Z:A,T:D}=m,L=f(w*w),B=f(_*_),k=f(A*A),q=f(k*k),F=f(L*l),y=f(k*f(F+B)),E=f(q+f(g*f(L*B)));if(y!==E)throw new Error("bad point: equation left != right (1)");let I=f(w*_),S=f(A*D);if(I!==S)throw new Error("bad point: equation left != right (2)")}equals(m){u(m);let{X:l,Y:g,Z:w}=this,{X:_,Y:A,Z:D}=m,L=f(l*D),B=f(_*w),k=f(g*D),q=f(A*w);return L===B&&k===q}is0(){return this.equals(p.ZERO)}negate(){return new p(f(-this.X),this.Y,this.Z,f(-this.T))}double(){let{a:m}=i,{X:l,Y:g,Z:w}=this,_=f(l*l),A=f(g*g),D=f(Ts*f(w*w)),L=f(m*_),B=l+g,k=f(f(B*B)-_-A),q=L+A,F=q-D,y=L-A,E=f(k*F),I=f(q*y),S=f(k*y),v=f(F*q);return new p(E,I,v,S)}add(m){u(m);let{a:l,d:g}=i,{X:w,Y:_,Z:A,T:D}=this,{X:L,Y:B,Z:k,T:q}=m,F=f(w*L),y=f(_*B),E=f(D*g*q),I=f(A*k),S=f((w+_)*(L+B)-F-y),v=I-E,T=I+E,O=f(y-l*F),C=f(S*v),R=f(T*O),P=f(S*O),U=f(v*T);return new p(C,R,U,P)}subtract(m){return u(m),this.add(m.negate())}multiply(m){if(!s.isValidNot0(m))throw new RangeError("invalid scalar: expected 1 <= sc < curve.n");let{p:l,f:g}=b.cached(this,m,w=>xe(p,w));return xe(p,[l,g])[0]}multiplyUnsafe(m){if(!s.isValid(m))throw new RangeError("invalid scalar: expected 0 <= sc < curve.n");return m===ne?p.ZERO:this.is0()||m===nt?this:b.unsafe(this,m,l=>xe(p,l))}isSmallOrder(){return this.clearCofactor().is0()}isTorsionFree(){return b.unsafe(this,i.n).is0()}toAffine(m){let l=this,g=m,{X:w,Y:_,Z:A}=l,D=l.is0();g==null&&(g=D?Vd:o.inv(A));let L=f(w*g),B=f(_*g),k=o.mul(A,g);if(D)return{x:ne,y:nt};if(k!==nt)throw new Error("invZ was invalid");return{x:L,y:B}}clearCofactor(){return a===nt?this:this.multiplyUnsafe(a)}toBytes(){let{x:m,y:l}=this.toAffine(),g=o.toBytes(l);return g[g.length-1]|=m&nt?128:0,g}toHex(){return Ge(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let b=new Je(p,s.BITS);return s.BITS>=8&&p.BASE.precompute(8),Object.freeze(p.prototype),Object.freeze(p),p}var Ln=class{static BASE;static ZERO;static Fp;static Fn;ep;constructor(t){this.ep=t}static fromBytes(t){xs()}static fromHex(t){xs()}get x(){return this.toAffine().x}get y(){return this.toAffine().y}clearCofactor(){return this}assertValidity(){this.ep.assertValidity()}toAffine(t){return this.ep.toAffine(t)}toHex(){return Ge(this.toBytes())}toString(){return this.toHex()}isTorsionFree(){return!0}isSmallOrder(){return!1}add(t){return this.assertSame(t),this.init(this.ep.add(t.ep))}subtract(t){return this.assertSame(t),this.init(this.ep.subtract(t.ep))}multiply(t){return this.init(this.ep.multiply(t))}multiplyUnsafe(t){return this.init(this.ep.multiplyUnsafe(t))}double(){return this.init(this.ep.double())}negate(){return this.init(this.ep.negate())}precompute(t,e){return this.ep.precompute(t,e),this}};function Cc(r,t,e={}){if(typeof t!="function")throw new Error('"hash" function param is required');let n=t,o=e;_t(o,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",zip215:"boolean",mapToCurve:"function"});let{prehash:s}=o,{BASE:i,Fp:a,Fn:c}=r,f=n.outputLen,d=2*a.BYTES;if(f!==void 0&&(St(f,"hash.outputLen"),f!==d))throw new Error(`hash.outputLen must be ${d}, got ${f}`);let h=o.randomBytes===void 0?Or:o.randomBytes,u=o.adjustScalarBytes===void 0?y=>y:o.adjustScalarBytes,p=o.domain===void 0?(y,E,I)=>{if(vt(I,"phflag"),E.length||I)throw new Error("Contexts/pre-hash are not supported");return y}:o.domain;function b(y){return c.create(Ct(y))}function x(y){let E=L.secretKey;M(y,L.secretKey,"secretKey");let I=M(n(y),2*E,"hashedSecretKey"),S=u(I.slice(0,E)),v=I.slice(E,2*E),T=b(S);return{head:S,prefix:v,scalar:T}}function m(y){let{head:E,prefix:I,scalar:S}=x(y),v=i.multiply(S),T=v.toBytes();return{head:E,prefix:I,scalar:S,point:v,pointBytes:T}}function l(y){return m(y).pointBytes}function g(y=Uint8Array.of(),...E){let I=J(...E);return b(n(p(I,M(y,void 0,"context"),!!s)))}function w(y,E,I={}){y=M(y,void 0,"message"),s&&(y=s(y));let{prefix:S,scalar:v,pointBytes:T}=m(E),O=g(I.context,S,y),C=i.multiply(O).toBytes(),R=g(I.context,C,T,y),P=c.create(O+R*v);if(!c.isValid(P))throw new Error("sign failed: invalid s");let U=J(C,c.toBytes(P));return M(U,L.signature,"result")}let _={zip215:o.zip215};function A(y,E,I,S=_){let{context:v}=S,T=S.zip215===void 0?!!_.zip215:S.zip215,O=L.signature;y=M(y,O,"signature"),E=M(E,void 0,"message"),I=M(I,L.publicKey,"publicKey"),T!==void 0&&vt(T,"zip215"),s&&(E=s(E));let C=O/2,R=y.subarray(0,C),P=Ct(y.subarray(C,O)),U,z,N;try{U=r.fromBytes(I,T),z=r.fromBytes(R,T),N=i.multiplyUnsafe(P)}catch{return!1}if(!T&&U.isSmallOrder())return!1;let Q=g(v,R,I,E);return z.add(U.multiplyUnsafe(Q)).subtract(N).clearCofactor().is0()}let D=a.BYTES,L={secretKey:D,publicKey:D,signature:2*D,seed:D};function B(y){return y=y===void 0?h(L.seed):y,M(y,L.seed,"seed")}function k(y){return me(y)&&y.length===L.secretKey}function q(y,E){try{return!!r.fromBytes(y,E===void 0?_.zip215:E)}catch{return!1}}let F={getExtendedPublicKey:m,randomSecretKey:B,isValidSecretKey:k,isValidPublicKey:q,toMontgomery(y){let{y:E}=r.fromBytes(y),I=L.publicKey,S=I===32;if(!S&&I!==57)throw new Error("only defined for 25519 and 448");let v=S?a.div(nt+E,nt-E):a.div(E-nt,E+nt);return a.toBytes(v)},toMontgomerySecret(y){let E=L.secretKey;M(y,E);let I=n(y.subarray(0,E));return u(I).subarray(0,E)}};return Object.freeze(L),Object.freeze(F),Object.freeze({keygen:Bn(B,l),getPublicKey:l,sign:w,verify:A,utils:F,Point:r,lengths:L})}function Ur(r,t){if(St(r),St(t),t<0||t>4)throw new Error("invalid I2OSP length: "+t);if(r<0||r>2**(8*t)-1)throw new Error("invalid I2OSP input: "+r);let e=Array.from({length:t}).fill(0);for(let n=t-1;n>=0;n--)e[n]=r&255,r>>>=8;return new Uint8Array(e)}function jd(r,t){let e=new Uint8Array(r.length);for(let n=0;n<r.length;n++)e[n]=r[n]^t[n];return e}function $d(r){if(!me(r)&&typeof r!="string")throw new Error("DST must be Uint8Array or ascii string");let t=typeof r=="string"?An(r):r;if(t.length===0)throw new Error("DST must be non-empty");return t}function Bs(r,t,e,n){M(r),St(e),t=$d(t),t.length>255&&(t=n(J(An("H2C-OVERSIZE-DST-"),t)));let{outputLen:o,blockLen:s}=n,i=Math.ceil(e/o);if(e>65535||i>255)throw new Error("expand_message_xmd: invalid lenInBytes");let a=J(t,Ur(t.length,1)),c=new Uint8Array(s),f=Ur(e,2),d=new Array(i),h=n(J(c,r,f,Ur(0,1),a));d[0]=n(J(h,Ur(1,1),a));for(let p=1;p<i;p++){let b=[jd(h,d[p-1]),Ur(p+1,1),a];d[p]=n(J(...b))}return J(...d).slice(0,e)}var Oc="HashToScalar-";var Gd=BigInt(0),qt=BigInt(1),Rc=BigInt(2);var Zd=BigInt(5),Yd=BigInt(8),tr=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),Os={p:tr,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:Yd,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function Xd(r){let t=BigInt(10),e=BigInt(20),n=BigInt(40),o=BigInt(80),s=tr,a=r*r%s*r%s,c=j(a,Rc,s)*a%s,f=j(c,qt,s)*r%s,d=j(f,Zd,s)*f%s,h=j(d,t,s)*d%s,u=j(h,e,s)*h%s,p=j(u,n,s)*u%s,b=j(p,o,s)*p%s,x=j(b,o,s)*p%s,m=j(x,t,s)*d%s;return{pow_p_5_8:j(m,Rc,s)*r%s,b2:a}}function Wd(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}var Ls=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function Rs(r,t){let e=tr,n=W(t*t*t,e),o=W(n*n*t,e),s=Xd(r*o).pow_p_5_8,i=W(r*n*s,e),a=W(t*i*i,e),c=i,f=W(i*Ls,e),d=a===r,h=a===W(-r,e),u=a===W(-r*Ls,e);return d&&(i=c),(h||u)&&(i=f),Kt(i,e)&&(i=W(-i,e)),{isValid:d||h,value:i}}var se=Dc(Os,{uvRatio:Rs}),oe=se.Fp,Fc=se.Fn;function Qd(r){return Cc(se,wn,Object.assign({adjustScalarBytes:Wd,zip215:!0},r))}var Nc=Qd({});var Ds=Ls,Jd=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),th=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),eh=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),rh=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952"),Pc=r=>Rs(qt,r),nh=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),Cs=r=>oe.create(Ct(r)&nh);function kc(r){let{d:t}=Os,e=tr,n=l=>oe.create(l),o=n(Ds*r*r),s=n((o+qt)*eh),i=BigInt(-1),a=n((i-t*o)*n(o+t)),{isValid:c,value:f}=Rs(s,a),d=n(f*r);Kt(d,e)||(d=n(-d)),c||(f=d),c||(i=o);let h=n(i*(o-qt)*rh-a),u=f*f,p=n((f+f)*a),b=n(h*Jd),x=n(qt-u),m=n(qt+u);return new se(n(p*m),n(x*b),n(b*m),n(p*x))}var ie=class r extends Ln{static BASE=new r(se.BASE);static ZERO=new r(se.ZERO);static Fp=oe;static Fn=Fc;constructor(t){super(t)}static fromAffine(t){return new r(se.fromAffine(t))}assertSame(t){if(!(t instanceof r))throw new Error("RistrettoPoint expected")}init(t){return new r(t)}static fromBytes(t){gt(t,32);let{a:e,d:n}=Os,o=tr,s=_=>oe.create(_),i=Cs(t);if(!lc(oe.toBytes(i),t)||Kt(i,o))throw new Error("invalid ristretto255 encoding 1");let a=s(i*i),c=s(qt+e*a),f=s(qt-e*a),d=s(c*c),h=s(f*f),u=s(e*n*d-h),{isValid:p,value:b}=Pc(s(u*h)),x=s(b*f),m=s(b*x*u),l=s((i+i)*x);Kt(l,o)&&(l=s(-l));let g=s(c*m),w=s(l*g);if(!p||Kt(w,o)||g===Gd)throw new Error("invalid ristretto255 encoding 2");return new r(new se(l,g,qt,w))}static fromHex(t){return r.fromBytes(Br(t))}toBytes(){let{X:t,Y:e,Z:n,T:o}=this.ep,s=tr,i=m=>oe.create(m),a=i(i(n+e)*i(n-e)),c=i(t*e),f=i(c*c),{value:d}=Pc(i(a*f)),h=i(d*a),u=i(d*c),p=i(h*u*o),b;if(Kt(o*p,s)){let m=i(e*Ds),l=i(t*Ds);t=m,e=l,b=i(h*th)}else b=u;Kt(t*p,s)&&(e=i(-e));let x=i((n-e)*b);return Kt(x,s)&&(x=i(-x)),oe.toBytes(x)}equals(t){this.assertSame(t);let{X:e,Y:n}=this.ep,{X:o,Y:s}=t.ep,i=f=>oe.create(f),a=i(e*s)===i(n*o),c=i(n*s)===i(e*o);return a||c}is0(){return this.equals(r.ZERO)}};Object.freeze(ie.BASE);Object.freeze(ie.ZERO);Object.freeze(ie.prototype);Object.freeze(ie);var oh=Object.freeze({Point:ie,hashToCurve(r,t){let e=t?.DST===void 0?"ristretto255_XMD:SHA-512_R255MAP_RO_":t.DST,n=Bs(r,e,64,wn);return oh.deriveToCurve(n)},hashToScalar(r,t={DST:Oc}){let e=Bs(r,t.DST,64,wn);return Fc.create(Ct(e))},deriveToCurve(r){gt(r,64);let t=Cs(r.subarray(0,32)),e=kc(t),n=Cs(r.subarray(32,64)),o=kc(n);return new ie(e.add(o))}});var Mr=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},Dn=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var Cn={get(r=globalThis){let t=r.crypto;if(t?.subtle==null)throw new Dn("Missing Web Crypto API. The most likely cause of this error is that this page is being accessed from an insecure context (i.e. not HTTPS). For more information and possible resolutions see https://github.com/libp2p/js-libp2p/blob/main/packages/crypto/README.md#web-crypto-api");return t}};var On=32;var Ps,sh=(async()=>{try{return await Cn.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function ih(r,t,e){if(r.buffer instanceof ArrayBuffer){let n=await Cn.get().subtle.importKey("raw",r.buffer,{name:"Ed25519"},!1,["verify"]);return await Cn.get().subtle.verify({name:"Ed25519"},n,Ne(t),Ne(e instanceof Uint8Array?e:e.subarray()))}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function ah(r,t,e){return Nc.verify(t,e instanceof Uint8Array?e:e.subarray(),r)}async function Uc(r,t,e){return Ps==null&&(Ps=await sh),Ps?ih(r,t,e):ah(r,t,e)}function Rn(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}var Pn=class{type="Ed25519";raw;constructor(t){this.raw=ks(t,On)}toMultihash(){return xt.digest(je(this))}toCID(){return ct.createV1(114,this.toMultihash())}toString(){return X.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:wt(this.raw,t.raw)}verify(t,e,n){n?.signal?.throwIfAborted();let o=Uc(this.raw,e,t);return Rn(o)?o.then(s=>(n?.signal?.throwIfAborted(),s)):o}};function zc(r){return r=ks(r,On),new Pn(r)}function ks(r,t){if(r=Uint8Array.from(r??[]),r.length!==t)throw new dt(`Key must be a Uint8Array of length ${t}, got ${r.length}`);return r}function Kc(r=0){return new Uint8Array(r)}var fh=Math.pow(2,7),uh=Math.pow(2,14),lh=Math.pow(2,21),Fs=Math.pow(2,28),Ns=Math.pow(2,35),Us=Math.pow(2,42),Ms=Math.pow(2,49),K=128,ut=127;function mt(r){if(r<fh)return 1;if(r<uh)return 2;if(r<lh)return 3;if(r<Fs)return 4;if(r<Ns)return 5;if(r<Us)return 6;if(r<Ms)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function er(r,t,e=0){switch(mt(r)){case 8:t[e++]=r&255|K,r/=128;case 7:t[e++]=r&255|K,r/=128;case 6:t[e++]=r&255|K,r/=128;case 5:t[e++]=r&255|K,r/=128;case 4:t[e++]=r&255|K,r>>>=7;case 3:t[e++]=r&255|K,r>>>=7;case 2:t[e++]=r&255|K,r>>>=7;case 1:{t[e++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return t}function dh(r,t,e=0){switch(mt(r)){case 8:t.set(e++,r&255|K),r/=128;case 7:t.set(e++,r&255|K),r/=128;case 6:t.set(e++,r&255|K),r/=128;case 5:t.set(e++,r&255|K),r/=128;case 4:t.set(e++,r&255|K),r>>>=7;case 3:t.set(e++,r&255|K),r>>>=7;case 2:t.set(e++,r&255|K),r>>>=7;case 1:{t.set(e++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return t}function zs(r,t){let e=r[t],n=0;if(n+=e&ut,e<K||(e=r[t+1],n+=(e&ut)<<7,e<K)||(e=r[t+2],n+=(e&ut)<<14,e<K)||(e=r[t+3],n+=(e&ut)<<21,e<K)||(e=r[t+4],n+=(e&ut)*Fs,e<K)||(e=r[t+5],n+=(e&ut)*Ns,e<K)||(e=r[t+6],n+=(e&ut)*Us,e<K)||(e=r[t+7],n+=(e&ut)*Ms,e<K))return n;throw new RangeError("Could not decode varint")}function hh(r,t){let e=r.get(t),n=0;if(n+=e&ut,e<K||(e=r.get(t+1),n+=(e&ut)<<7,e<K)||(e=r.get(t+2),n+=(e&ut)<<14,e<K)||(e=r.get(t+3),n+=(e&ut)<<21,e<K)||(e=r.get(t+4),n+=(e&ut)*Fs,e<K)||(e=r.get(t+5),n+=(e&ut)*Ns,e<K)||(e=r.get(t+6),n+=(e&ut)*Us,e<K)||(e=r.get(t+7),n+=(e&ut)*Ms,e<K))return n;throw new RangeError("Could not decode varint")}function qc(r,t,e=0){return t==null&&(t=Kc(mt(r))),t instanceof Uint8Array?er(r,t,e):dh(r,t,e)}function zr(r,t=0){return r instanceof Uint8Array?zs(r,t):hh(r,t)}var Ks=new Float32Array([-0]),ae=new Uint8Array(Ks.buffer);function Hc(r,t,e){Ks[0]=r,t[e]=ae[0],t[e+1]=ae[1],t[e+2]=ae[2],t[e+3]=ae[3]}function jc(r,t){return ae[0]=r[t],ae[1]=r[t+1],ae[2]=r[t+2],ae[3]=r[t+3],Ks[0]}var qs=new Float64Array([-0]),lt=new Uint8Array(qs.buffer);function $c(r,t,e){qs[0]=r,t[e]=lt[0],t[e+1]=lt[1],t[e+2]=lt[2],t[e+3]=lt[3],t[e+4]=lt[4],t[e+5]=lt[5],t[e+6]=lt[6],t[e+7]=lt[7]}function Gc(r,t){return lt[0]=r[t],lt[1]=r[t+1],lt[2]=r[t+2],lt[3]=r[t+3],lt[4]=r[t+4],lt[5]=r[t+5],lt[6]=r[t+6],lt[7]=r[t+7],qs[0]}var ph=BigInt(Number.MAX_SAFE_INTEGER),mh=BigInt(Number.MIN_SAFE_INTEGER),bt=class r{lo;hi;constructor(t,e){this.lo=t|0,this.hi=e|0}toNumber(t=!1){if(!t&&this.hi>>>31>0){let e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(e+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(t=!1){if(t)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(BigInt(e)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(t=!1){return this.toBigInt(t).toString()}zzEncode(){let t=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^t)>>>0,this.lo=(this.lo<<1^t)>>>0,this}zzDecode(){let t=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^t)>>>0,this.hi=(this.hi>>>1^t)>>>0,this}length(){let t=this.lo,e=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?e===0?t<16384?t<128?1:2:t<2097152?3:4:e<16384?e<128?5:6:e<2097152?7:8:n<128?9:10}static fromBigInt(t){if(t===0n)return we;if(t<ph&&t>mh)return this.fromNumber(Number(t));let e=t<0n;e&&(t=-t);let n=t>>32n,o=t-(n<<32n);return e&&(n=~n|0n,o=~o|0n,++o>Zc&&(o=0n,++n>Zc&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(t){if(t===0)return we;let e=t<0;e&&(t=-t);let n=t>>>0,o=(t-n)/4294967296>>>0;return e&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new r(n,o)}static from(t){return typeof t=="number"?r.fromNumber(t):typeof t=="bigint"?r.fromBigInt(t):typeof t=="string"?r.fromBigInt(BigInt(t)):t.low!=null||t.high!=null?new r(t.low>>>0,t.high>>>0):we}},we=new bt(0,0);we.toBigInt=function(){return 0n};we.zzEncode=we.zzDecode=function(){return this};we.length=function(){return 1};var Zc=4294967296n;function Yc(r){let t=0,e=0;for(let n=0;n<r.length;++n)e=r.charCodeAt(n),e<128?t+=1:e<2048?t+=2:(e&64512)===55296&&(r.charCodeAt(n+1)&64512)===56320?(++n,t+=4):t+=3;return t}function Xc(r,t,e){if(e-t<1)return"";let o,s=[],i=0,a;for(;t<e;)a=r[t++],a<128?s[i++]=a:a>191&&a<224?s[i++]=(a&31)<<6|r[t++]&63:a>239&&a<365?(a=((a&7)<<18|(r[t++]&63)<<12|(r[t++]&63)<<6|r[t++]&63)-65536,s[i++]=55296+(a>>10),s[i++]=56320+(a&1023)):s[i++]=(a&15)<<12|(r[t++]&63)<<6|r[t++]&63,i>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,s)),i=0);return o!=null?(i>0&&o.push(String.fromCharCode.apply(String,s.slice(0,i))),o.join("")):String.fromCharCode.apply(String,s.slice(0,i))}function Vs(r,t,e){let n=e,o,s;for(let i=0;i<r.length;++i)o=r.charCodeAt(i),o<128?t[e++]=o:o<2048?(t[e++]=o>>6|192,t[e++]=o&63|128):(o&64512)===55296&&((s=r.charCodeAt(i+1))&64512)===56320?(o=65536+((o&1023)<<10)+(s&1023),++i,t[e++]=o>>18|240,t[e++]=o>>12&63|128,t[e++]=o>>6&63|128,t[e++]=o&63|128):(t[e++]=o>>12|224,t[e++]=o>>6&63|128,t[e++]=o&63|128);return e-n}function At(r,t){return RangeError(`index out of range: ${r.pos} + ${t??1} > ${r.len}`)}function kn(r,t){return(r[t-4]|r[t-3]<<8|r[t-2]<<16|r[t-1]<<24)>>>0}var Hs=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(t){this.buf=t,this.pos=0,this.len=t.length}uint32(){let t=4294967295;if(t=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(t=(t|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return t;if((this.pos+=5)>this.len)throw this.pos=this.len,At(this,10);return t}int32(){return this.uint32()|0}sint32(){let t=this.uint32();return t>>>1^-(t&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw At(this,4);return kn(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw At(this,4);return kn(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw At(this,4);let t=jc(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw At(this,4);let t=Gc(this.buf,this.pos);return this.pos+=8,t}bytes(){let t=this.uint32(),e=this.pos,n=this.pos+t;if(n>this.len)throw At(this,t);return this.pos+=t,e===n?new Uint8Array(0):this.buf.subarray(e,n)}string(){let t=this.bytes();return Xc(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw At(this,t);this.pos+=t}else do if(this.pos>=this.len)throw At(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(t){switch(t){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(t=this.uint32()&7)!==4;)this.skipType(t);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${t} at offset ${this.pos}`)}return this}readLongVarint(){let t=new bt(0,0),e=0;if(this.len-this.pos>4){for(;e<4;++e)if(t.lo=(t.lo|(this.buf[this.pos]&127)<<e*7)>>>0,this.buf[this.pos++]<128)return t;if(t.lo=(t.lo|(this.buf[this.pos]&127)<<28)>>>0,t.hi=(t.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return t;e=0}else{for(;e<3;++e){if(this.pos>=this.len)throw At(this);if(t.lo=(t.lo|(this.buf[this.pos]&127)<<e*7)>>>0,this.buf[this.pos++]<128)return t}return t.lo=(t.lo|(this.buf[this.pos++]&127)<<e*7)>>>0,t}if(this.len-this.pos>4){for(;e<5;++e)if(t.hi=(t.hi|(this.buf[this.pos]&127)<<e*7+3)>>>0,this.buf[this.pos++]<128)return t}else for(;e<5;++e){if(this.pos>=this.len)throw At(this);if(t.hi=(t.hi|(this.buf[this.pos]&127)<<e*7+3)>>>0,this.buf[this.pos++]<128)return t}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw At(this,8);let t=kn(this.buf,this.pos+=4),e=kn(this.buf,this.pos+=4);return new bt(t,e)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let t=zs(this.buf,this.pos);return this.pos+=mt(t),t}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function Kr(r){return new Hs(r instanceof Uint8Array?r:r.subarray())}function Vt(r,t,e){let n=Kr(r);return t.decode(n,void 0,e)}function Ee(r=0){return new Uint8Array(r)}var js={};V(js,{base10:()=>gh});var gh=Yt({prefix:"9",name:"base10",alphabet:"0123456789"});var $s={};V($s,{base16:()=>bh,base16upper:()=>yh});var bh=$({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),yh=$({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Gs={};V(Gs,{base2:()=>xh});var xh=$({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Zs={};V(Zs,{base256emoji:()=>_h});var Qc=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}"),wh=Qc.reduce((r,t,e)=>(r[e]=t,r),[]),Eh=Qc.reduce((r,t,e)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return r[n]=e,r},[]);function vh(r){return r.reduce((t,e)=>(t+=wh[e],t),"")}function Sh(r){let t=[];for(let e of r){let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);let o=Eh[n];if(o==null)throw new Error(`Non-base256emoji character: ${e}`);t.push(o)}return new Uint8Array(t)}var _h=Oe({prefix:"\u{1F680}",name:"base256emoji",encode:vh,decode:Sh});var Xs={};V(Xs,{base64:()=>Ah,base64pad:()=>Ih,base64url:()=>Ys,base64urlpad:()=>Th});var Ah=$({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Ih=$({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Ys=$({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Th=$({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Ws={};V(Ws,{base8:()=>Bh});var Bh=$({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Qs={};V(Qs,{identity:()=>Lh});var Lh=Oe({prefix:"\0",name:"identity",encode:r=>na(r),decode:r=>ra(r)});var Cy=new TextEncoder,Oy=new TextDecoder;var ei={};V(ei,{sha256:()=>qr,sha512:()=>Rh});var Oh=20;function ti({name:r,code:t,encode:e,minDigestLength:n,maxDigestLength:o}){return new Js(r,t,e,n,o)}var Js=class{name;code;encode;minDigestLength;maxDigestLength;constructor(t,e,n,o,s){this.name=t,this.code=e,this.encode=n,this.minDigestLength=o??Oh,this.maxDigestLength=s}digest(t,e){if(e?.truncate!=null){if(e.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&e.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(t instanceof Uint8Array){let n=this.encode(t);return n instanceof Uint8Array?Jc(n,this.code,e?.truncate):n.then(o=>Jc(o,this.code,e?.truncate))}else throw Error("Unknown type, must be binary type")}};function Jc(r,t,e){if(e!=null&&e!==r.byteLength){if(e>r.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${r.byteLength}`);r=r.subarray(0,e)}return Fe(t,r)}function ef(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var qr=ti({name:"sha2-256",code:18,encode:ef("SHA-256")}),Rh=ti({name:"sha2-512",code:19,encode:ef("SHA-512")});var ce={...Qs,...Gs,...Ws,...js,...$s,...Ao,...Io,..._o,...Xs,...Zs},Hy={...ei,...Lo};function nf(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var rf=nf("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),ri=nf("ascii","a",r=>{let t="a";for(let e=0;e<r.length;e++)t+=String.fromCharCode(r[e]);return t},r=>{r=r.substring(1);let t=Ee(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),Ph={utf8:rf,"utf-8":rf,hex:ce.base16,latin1:ri,ascii:ri,binary:ri,...ce},of=Ph;function sf(r,t="utf8"){let e=of[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.decoder.decode(`${e.prefix}${r}`)}function ni(r){let t=r??8192,e=t>>>1,n,o=t;return function(i){if(i<1||i>e)return Ee(i);o+i>t&&(n=Ee(t),o=0);let a=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),a}}var ve=class{fn;len;next;val;constructor(t,e,n){this.fn=t,this.len=e,this.next=void 0,this.val=n}};function oi(){}var ii=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},kh=ni();function Fh(r){return globalThis.Buffer!=null?Ee(r):kh(r)}var Hr=class{len;head;tail;states;constructor(){this.len=0,this.head=new ve(oi,0,0),this.tail=this.head,this.states=null}_push(t,e,n){return this.tail=this.tail.next=new ve(t,e,n),this.len+=e,this}uint32(t){return this.len+=(this.tail=this.tail.next=new ai((t=t>>>0)<128?1:t<16384?2:t<2097152?3:t<268435456?4:5,t)).len,this}int32(t){return t<0?this._push(Fn,10,bt.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let e=bt.fromBigInt(t);return this._push(Fn,e.length(),e)}uint64Number(t){return this._push(er,mt(t),t)}uint64String(t){return this.uint64(BigInt(t))}int64(t){return this.uint64(t)}int64Number(t){return this.uint64Number(t)}int64String(t){return this.uint64String(t)}sint64(t){let e=bt.fromBigInt(t).zzEncode();return this._push(Fn,e.length(),e)}sint64Number(t){let e=bt.fromNumber(t).zzEncode();return this._push(Fn,e.length(),e)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(si,1,t?1:0)}fixed32(t){return this._push(Vr,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=bt.fromBigInt(t);return this._push(Vr,4,e.lo)._push(Vr,4,e.hi)}fixed64Number(t){let e=bt.fromNumber(t);return this._push(Vr,4,e.lo)._push(Vr,4,e.hi)}fixed64String(t){return this.fixed64(BigInt(t))}sfixed64(t){return this.fixed64(t)}sfixed64Number(t){return this.fixed64Number(t)}sfixed64String(t){return this.fixed64String(t)}float(t){return this._push(Hc,4,t)}double(t){return this._push($c,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(si,1,0):this.uint32(e)._push(Uh,e,t)}string(t){let e=Yc(t);return e!==0?this.uint32(e)._push(Vs,e,t):this._push(si,1,0)}fork(){return this.states=new ii(this),this.head=this.tail=new ve(oi,0,0),this.len=0,this}reset(){return this.states!=null?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new ve(oi,0,0),this.len=0),this}ldelim(){let t=this.head,e=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=t.next,this.tail=e,this.len+=n),this}finish(){let t=this.head.next,e=Fh(this.len),n=0;for(;t!=null;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e}};function si(r,t,e){t[e]=r&255}function Nh(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var ai=class extends ve{next;constructor(t,e){super(Nh,t,e),this.next=void 0}};function Fn(r,t,e){for(;r.hi!==0;)t[e++]=r.lo&127|128,r.lo=(r.lo>>>7|r.hi<<25)>>>0,r.hi>>>=7;for(;r.lo>127;)t[e++]=r.lo&127|128,r.lo=r.lo>>>7;t[e++]=r.lo}function Vr(r,t,e){t[e]=r&255,t[e+1]=r>>>8&255,t[e+2]=r>>>16&255,t[e+3]=r>>>24}function Uh(r,t,e){t.set(r,e)}globalThis.Buffer!=null&&(Hr.prototype.bytes=function(r){let t=r.length>>>0;return this.uint32(t),t>0&&this._push(Mh,t,r),this},Hr.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(zh,t,r),this});function Mh(r,t,e){t.set(r,e)}function zh(r,t,e){r.length<40?Vs(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set(sf(r),e)}function ci(){return new Hr}function Ht(r,t){let e=ci();return t.encode(r,e,{lengthDelimited:!1}),e.finish()}function*jt(r,t,e){let n=Kr(r);yield*t.stream(n,void 0,"$",e)}var Nn={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function Un(r,t,e,n,o){return{name:r,type:t,encode:e,decode:n,stream:o}}function rr(r){function t(s){if(r[s.toString()]==null)throw new Error("Invalid enum value");return r[s]}let e=function(i,a){let c=t(i);a.int32(c)},n=function(i){let a=i.int32();return t(a)},o=function*(i){let a=i.int32();yield t(a)};return Un("enum",Nn.VARINT,e,n,o)}function $t(r,t,e){return Un("message",Nn.LENGTH_DELIMITED,r,t,e)}var jr=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var ht;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.secp256k1="secp256k1",r.ECDSA="ECDSA"})(ht||(ht={}));var fi;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.secp256k1=2]="secp256k1",r[r.ECDSA=3]="ECDSA"})(fi||(fi={}));(function(r){r.codec=()=>rr(fi)})(ht||(ht={}));var $r;(function(r){let t;r.codec=()=>(t==null&&(t=$t((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.Type!=null&&(i.uint32(8),ht.codec().encode(s.Type,i)),s.Data!=null&&(i.uint32(18),i.bytes(s.Data)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={},f=i==null?s.len:s.pos+i;for(;s.pos<f;){let d=s.uint32();switch(d>>>3){case 1:{c.Type=ht.codec().decode(s);break}case 2:{c.Data=s.bytes();break}default:{s.skipType(d&7);break}}}return c},function*(s,i,a,c={}){let f=i==null?s.len:s.pos+i;for(;s.pos<f;){let d=s.uint32();switch(d>>>3){case 1:{yield{field:`${a}.Type`,value:ht.codec().decode(s)};break}case 2:{yield{field:`${a}.Data`,value:s.bytes()};break}default:{s.skipType(d&7);break}}}})),t);function e(s){return Ht(s,r.codec())}r.encode=e;function n(s,i){return Vt(s,r.codec(),i)}r.decode=n;function o(s,i){return jt(s,r.codec(),i)}r.stream=o})($r||($r={}));var ui;(function(r){let t;r.codec=()=>(t==null&&(t=$t((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.Type!=null&&(i.uint32(8),ht.codec().encode(s.Type,i)),s.Data!=null&&(i.uint32(18),i.bytes(s.Data)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={},f=i==null?s.len:s.pos+i;for(;s.pos<f;){let d=s.uint32();switch(d>>>3){case 1:{c.Type=ht.codec().decode(s);break}case 2:{c.Data=s.bytes();break}default:{s.skipType(d&7);break}}}return c},function*(s,i,a,c={}){let f=i==null?s.len:s.pos+i;for(;s.pos<f;){let d=s.uint32();switch(d>>>3){case 1:{yield{field:`${a}.Type`,value:ht.codec().decode(s)};break}case 2:{yield{field:`${a}.Data`,value:s.bytes()};break}default:{s.skipType(d&7);break}}}})),t);function e(s){return Ht(s,r.codec())}r.encode=e;function n(s,i){return Vt(s,r.codec(),i)}r.decode=n;function o(s,i){return jt(s,r.codec(),i)}r.stream=o})(ui||(ui={}));var Mn=class{oHash;iHash;blockLen;outputLen;canXOF=!1;finished=!1;destroyed=!1;constructor(t,e){if(mn(t),gt(e,void 0,"key"),this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let n=this.blockLen,o=new Uint8Array(n);o.set(e.length>n?t.create().update(e).digest():e);for(let s=0;s<o.length;s++)o[s]^=54;this.iHash.update(o),this.oHash=t.create();for(let s=0;s<o.length;s++)o[s]^=106;this.oHash.update(o),Mt(o)}update(t){return $e(this),this.iHash.update(t),this}digestInto(t){$e(this),gn(t,this),this.finished=!0;let e=t.subarray(0,this.outputLen);this.iHash.digestInto(e),this.oHash.update(e),this.oHash.digestInto(e),this.destroy()}digest(){let t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||=Object.create(Object.getPrototypeOf(this),{});let{oHash:e,iHash:n,finished:o,destroyed:s,blockLen:i,outputLen:a}=this;return t=t,t.finished=o,t.destroyed=s,t.blockLen=i,t.outputLen=a,t.oHash=e._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},af=(()=>{let r=((t,e,n)=>new Mn(t,e).update(n).digest());return r.create=(t,e)=>new Mn(t,e),r})();var cf=(r,t)=>(r+(r>=0?t:-t)/ff)/t;function qh(r,t,e){Ye("scalar",r,Ot,e);let[[n,o],[s,i]]=t,a=cf(i*r,e),c=cf(-o*r,e),f=r-a*n-c*s,d=-a*o-c*i,h=f<Ot,u=d<Ot;h&&(f=-f),u&&(d=-d);let p=kr(Math.ceil(Xe(e)/2))+fe;if(f<Ot||f>=p||d<Ot||d>=p)throw new Error("splitScalar (endomorphism): failed for k");return{k1neg:h,k1:f,k2neg:u,k2:d}}function di(r){if(!["compact","recovered","der"].includes(r))throw new Error('Signature format must be "compact", "recovered", or "der"');return r}function li(r,t){_t(r);let e={};for(let n of Object.keys(t))e[n]=r[n]===void 0?t[n]:r[n];return vt(e.lowS,"lowS"),vt(e.prehash,"prehash"),e.format!==void 0&&di(e.format),e}var hi=class extends Error{constructor(t=""){super(t)}},It={Err:hi,_tlv:{encode:(r,t)=>{let{Err:e}=It;if(St(r,"tag"),r<0||r>255)throw new e("tlv.encode: wrong tag");if(typeof t!="string")throw new TypeError('"data" expected string, got type='+typeof t);if(t.length&1)throw new e("tlv.encode: unpadded data");let n=t.length/2,o=Rr(n);if(o.length/2&128)throw new e("tlv.encode: long form length too big");let s=n>127?Rr(o.length/2|128):"";return Rr(r)+s+o+t},decode(r,t){let{Err:e}=It;t=M(t,void 0,"DER data");let n=0;if(r<0||r>255)throw new e("tlv.encode: wrong tag");if(t.length<2||t[n++]!==r)throw new e("tlv.decode: wrong tlv");let o=t[n++],s=!!(o&128),i=0;if(!s)i=o;else{let c=o&127;if(!c)throw new e("tlv.decode(long): indefinite length not supported");if(c>4)throw new e("tlv.decode(long): byte length is too big");let f=t.subarray(n,n+c);if(f.length!==c)throw new e("tlv.decode: length bytes not complete");if(f[0]===0)throw new e("tlv.decode(long): zero leftmost byte");for(let d of f)i=i<<8|d;if(n+=c,i<128)throw new e("tlv.decode(long): not minimal encoding")}let a=t.subarray(n,n+i);if(a.length!==i)throw new e("tlv.decode: wrong value length");return{v:a,l:t.subarray(n+i)}}},_int:{encode(r){let{Err:t}=It;if(Sn(r),r<Ot)throw new t("integer: negative integers are not allowed");let e=Rr(r);if(Number.parseInt(e[0],16)&8&&(e="00"+e),e.length&1)throw new t("unexpected DER parsing assertion: unpadded hex");return e},decode(r){let{Err:t}=It;if(r.length<1)throw new t("invalid signature integer: empty");if(r[0]&128)throw new t("invalid signature integer: negative");if(r.length>1&&r[0]===0&&!(r[1]&128))throw new t("invalid signature integer: unnecessary leading zero");return ge(r)}},toSig(r){let{Err:t,_int:e,_tlv:n}=It,o=M(r,void 0,"signature"),{v:s,l:i}=n.decode(48,o);if(i.length)throw new t("invalid signature: left bytes after parsing");let{v:a,l:c}=n.decode(2,s),{v:f,l:d}=n.decode(2,c);if(d.length)throw new t("invalid signature: left bytes after parsing");return{r:e.decode(a),s:e.decode(f)}},hexFromSig(r){let{_tlv:t,_int:e}=It,n=t.encode(2,e.encode(r.r)),o=t.encode(2,e.encode(r.s)),s=n+o;return t.encode(48,s)}};Object.freeze(It._tlv);Object.freeze(It._int);Object.freeze(It);var Ot=BigInt(0),fe=BigInt(1),ff=BigInt(2),zn=BigInt(3),Vh=BigInt(4);function uf(r,t={}){let e=Tn("weierstrass",r,t),n=e.Fp,o=e.Fn,s=e.CURVE,{h:i,n:a}=s;_t(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object"});let{endo:c,allowInfinityPoint:f}=t;if(c&&(!n.is0(s.a)||typeof c.beta!="bigint"||!Array.isArray(c.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let d=df(n,o);function h(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function u(F,y,E){if(f&&y.is0())return Uint8Array.of(0);let{x:I,y:S}=y.toAffine(),v=n.toBytes(I);if(vt(E,"isCompressed"),E){h();let T=!n.isOdd(S);return J(lf(T),v)}else return J(Uint8Array.of(4),v,n.toBytes(S))}function p(F){M(F,void 0,"Point");let{publicKey:y,publicKeyUncompressed:E}=d,I=F.length,S=F[0],v=F.subarray(1);if(f&&I===1&&S===0)return{x:n.ZERO,y:n.ZERO};if(I===y&&(S===2||S===3)){let T=n.fromBytes(v);if(!n.isValid(T))throw new Error("bad point: is not on curve, wrong x");let O=m(T),C;try{C=n.sqrt(O)}catch(U){let z=U instanceof Error?": "+U.message:"";throw new Error("bad point: is not on curve, sqrt error"+z)}h();let R=n.isOdd(C);return(S&1)===1!==R&&(C=n.neg(C)),{x:T,y:C}}else if(I===E&&S===4){let T=n.BYTES,O=n.fromBytes(v.subarray(0,T)),C=n.fromBytes(v.subarray(T,T*2));if(!l(O,C))throw new Error("bad point: is not on curve");return{x:O,y:C}}else throw new Error(`bad point: got length ${I}, expected compressed=${y} or uncompressed=${E}`)}let b=t.toBytes===void 0?u:t.toBytes,x=t.fromBytes===void 0?p:t.fromBytes;function m(F){let y=n.sqr(F),E=n.mul(y,F);return n.add(n.add(E,n.mul(F,s.a)),s.b)}function l(F,y){let E=n.sqr(y),I=m(F);return n.eql(E,I)}if(!l(s.Gx,s.Gy))throw new Error("bad curve params: generator point");let g=n.mul(n.pow(s.a,zn),Vh),w=n.mul(n.sqr(s.b),BigInt(27));if(n.is0(n.add(g,w)))throw new Error("bad curve params: a or b");function _(F,y,E=!1){if(!n.isValid(y)||E&&n.is0(y))throw new Error(`bad point coordinate ${F}`);return y}function A(F){if(!(F instanceof B))throw new Error("Weierstrass Point expected")}function D(F){if(!c||!c.basises)throw new Error("no endo");return qh(F,c.basises,o.ORDER)}function L(F,y,E,I,S){return E=new B(n.mul(E.X,F),E.Y,E.Z),y=Nr(I,y),E=Nr(S,E),y.add(E)}class B{static BASE=new B(s.Gx,s.Gy,n.ONE);static ZERO=new B(n.ZERO,n.ONE,n.ZERO);static Fp=n;static Fn=o;X;Y;Z;constructor(y,E,I){this.X=_("x",y),this.Y=_("y",E,!0),this.Z=_("z",I),Object.freeze(this)}static CURVE(){return s}static fromAffine(y){let{x:E,y:I}=y||{};if(!y||!n.isValid(E)||!n.isValid(I))throw new Error("invalid affine point");if(y instanceof B)throw new Error("projective point not allowed");return n.is0(E)&&n.is0(I)?B.ZERO:new B(E,I,n.ONE)}static fromBytes(y){let E=B.fromAffine(x(M(y,void 0,"point")));return E.assertValidity(),E}static fromHex(y){return B.fromBytes(Ze(y))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(y=8,E=!0){return q.createCache(this,y),E||this.multiply(zn),this}assertValidity(){let y=this;if(y.is0()){if(t.allowInfinityPoint&&n.is0(y.X)&&n.eql(y.Y,n.ONE)&&n.is0(y.Z))return;throw new Error("bad point: ZERO")}let{x:E,y:I}=y.toAffine();if(!n.isValid(E)||!n.isValid(I))throw new Error("bad point: x or y not field elements");if(!l(E,I))throw new Error("bad point: equation left != right");if(!y.isTorsionFree())throw new Error("bad point: not in prime-order subgroup")}hasEvenY(){let{y}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(y)}equals(y){A(y);let{X:E,Y:I,Z:S}=this,{X:v,Y:T,Z:O}=y,C=n.eql(n.mul(E,O),n.mul(v,S)),R=n.eql(n.mul(I,O),n.mul(T,S));return C&&R}negate(){return new B(this.X,n.neg(this.Y),this.Z)}double(){let{a:y,b:E}=s,I=n.mul(E,zn),{X:S,Y:v,Z:T}=this,O=n.ZERO,C=n.ZERO,R=n.ZERO,P=n.mul(S,S),U=n.mul(v,v),z=n.mul(T,T),N=n.mul(S,v);return N=n.add(N,N),R=n.mul(S,T),R=n.add(R,R),O=n.mul(y,R),C=n.mul(I,z),C=n.add(O,C),O=n.sub(U,C),C=n.add(U,C),C=n.mul(O,C),O=n.mul(N,O),R=n.mul(I,R),z=n.mul(y,z),N=n.sub(P,z),N=n.mul(y,N),N=n.add(N,R),R=n.add(P,P),P=n.add(R,P),P=n.add(P,z),P=n.mul(P,N),C=n.add(C,P),z=n.mul(v,T),z=n.add(z,z),P=n.mul(z,N),O=n.sub(O,P),R=n.mul(z,U),R=n.add(R,R),R=n.add(R,R),new B(O,C,R)}add(y){A(y);let{X:E,Y:I,Z:S}=this,{X:v,Y:T,Z:O}=y,C=n.ZERO,R=n.ZERO,P=n.ZERO,U=s.a,z=n.mul(s.b,zn),N=n.mul(E,v),Q=n.mul(I,T),tt=n.mul(S,O),et=n.add(E,I),Y=n.add(v,T);et=n.mul(et,Y),Y=n.add(N,Q),et=n.sub(et,Y),Y=n.add(E,S);let pt=n.add(v,O);return Y=n.mul(Y,pt),pt=n.add(N,tt),Y=n.sub(Y,pt),pt=n.add(I,S),C=n.add(T,O),pt=n.mul(pt,C),C=n.add(Q,tt),pt=n.sub(pt,C),P=n.mul(U,Y),C=n.mul(z,tt),P=n.add(C,P),C=n.sub(Q,P),P=n.add(Q,P),R=n.mul(C,P),Q=n.add(N,N),Q=n.add(Q,N),tt=n.mul(U,tt),Y=n.mul(z,Y),Q=n.add(Q,tt),tt=n.sub(N,tt),tt=n.mul(U,tt),Y=n.add(Y,tt),N=n.mul(Q,Y),R=n.add(R,N),N=n.mul(pt,Y),C=n.mul(et,C),C=n.sub(C,N),N=n.mul(et,Q),P=n.mul(pt,P),P=n.add(P,N),new B(C,R,P)}subtract(y){return A(y),this.add(y.negate())}is0(){return this.equals(B.ZERO)}multiply(y){let{endo:E}=t;if(!o.isValidNot0(y))throw new RangeError("invalid scalar: out of range");let I,S,v=T=>q.cached(this,T,O=>xe(B,O));if(E){let{k1neg:T,k1:O,k2neg:C,k2:R}=D(y),{p:P,f:U}=v(O),{p:z,f:N}=v(R);S=U.add(N),I=L(E.beta,P,z,T,C)}else{let{p:T,f:O}=v(y);I=T,S=O}return xe(B,[I,S])[0]}multiplyUnsafe(y){let{endo:E}=t,I=this,S=y;if(!o.isValid(S))throw new RangeError("invalid scalar: out of range");if(S===Ot||I.is0())return B.ZERO;if(S===fe)return I;if(q.hasCache(this))return this.multiply(S);if(E){let{k1neg:v,k1:T,k2neg:O,k2:C}=D(S),{p1:R,p2:P}=Lc(B,I,T,C);return L(E.beta,R,P,v,O)}else return q.unsafe(I,S)}toAffine(y){let E=this,I=y,{X:S,Y:v,Z:T}=E;if(n.eql(T,n.ONE))return{x:S,y:v};let O=E.is0();I==null&&(I=O?n.ONE:n.inv(T));let C=n.mul(S,I),R=n.mul(v,I),P=n.mul(T,I);if(O)return{x:n.ZERO,y:n.ZERO};if(!n.eql(P,n.ONE))throw new Error("invZ was invalid");return{x:C,y:R}}isTorsionFree(){let{isTorsionFree:y}=t;return i===fe?!0:y?y(B,this):q.unsafe(this,a).is0()}clearCofactor(){let{clearCofactor:y}=t;return i===fe?this:y?y(B,this):this.multiplyUnsafe(i)}isSmallOrder(){return i===fe?this.is0():this.clearCofactor().is0()}toBytes(y=!0){return vt(y,"isCompressed"),this.assertValidity(),b(B,this,y)}toHex(y=!0){return Ge(this.toBytes(y))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let k=o.BITS,q=new Je(B,t.endo?Math.ceil(k/2):k);return k>=8&&B.BASE.precompute(8),Object.freeze(B.prototype),Object.freeze(B),B}function lf(r){return Uint8Array.of(r?2:3)}function df(r,t){return{secretKey:t.BYTES,publicKey:1+r.BYTES,publicKeyUncompressed:1+2*r.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function Hh(r,t={}){let{Fn:e}=r,n=t.randomBytes===void 0?Or:t.randomBytes,o=Object.assign(df(r.Fp,e),{seed:Math.max(vs(e.ORDER),16)});function s(p){try{let b=e.fromBytes(p);return e.isValidNot0(b)}catch{return!1}}function i(p,b){let{publicKey:x,publicKeyUncompressed:m}=o;try{let l=p.length;return b===!0&&l!==x||b===!1&&l!==m?!1:!!r.fromBytes(p)}catch{return!1}}function a(p){return p=p===void 0?n(o.seed):p,Ss(M(p,o.seed,"seed"),e.ORDER)}function c(p,b=!0){return r.BASE.multiply(e.fromBytes(p)).toBytes(b)}function f(p){let{secretKey:b,publicKey:x,publicKeyUncompressed:m}=o,l=e._lengths;if(!me(p))return;let g=M(p,void 0,"key").length,w=g===x||g===m,_=g===b||!!l?.includes(g);if(!(w&&_))return w}function d(p,b,x=!0){if(f(p)===!0)throw new Error("first arg must be private key");if(f(b)===!1)throw new Error("second arg must be public key");let m=e.fromBytes(p);return r.fromBytes(b).multiply(m).toBytes(x)}let h={isValidSecretKey:s,isValidPublicKey:i,randomSecretKey:a},u=Bn(a,c);return Object.freeze(h),Object.freeze(o),Object.freeze({getPublicKey:c,getSharedSecret:d,keygen:u,Point:r,utils:h,lengths:o})}function hf(r,t,e={}){let n=t;mn(n),_t(e,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"}),e=Object.assign({},e);let o=e.randomBytes===void 0?Or:e.randomBytes,s=e.hmac===void 0?(S,v)=>af(n,S,v):e.hmac,{Fp:i,Fn:a}=r,{ORDER:c,BITS:f}=a,{keygen:d,getPublicKey:h,getSharedSecret:u,utils:p,lengths:b}=Hh(r,e),x={prehash:!0,lowS:typeof e.lowS=="boolean"?e.lowS:!0,format:"compact",extraEntropy:!1},m=c*ff+fe<i.ORDER;function l(S){let v=c>>fe;return S>v}function g(S,v){if(!a.isValidNot0(v))throw new Error(`invalid signature ${S}: out of range 1..Point.Fn.ORDER`);return v}function w(){if(m)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function _(S,v){di(v);let T=b.signature,O=v==="compact"?T:v==="recovered"?T+1:void 0;return M(S,O)}class A{r;s;recovery;constructor(v,T,O){if(this.r=g("r",v),this.s=g("s",T),O!=null){if(w(),![0,1,2,3].includes(O))throw new Error("invalid recovery id");this.recovery=O}Object.freeze(this)}static fromBytes(v,T=x.format){_(v,T);let O;if(T==="der"){let{r:U,s:z}=It.toSig(M(v));return new A(U,z)}T==="recovered"&&(O=v[0],T="compact",v=v.subarray(1));let C=b.signature/2,R=v.subarray(0,C),P=v.subarray(C,C*2);return new A(a.fromBytes(R),a.fromBytes(P),O)}static fromHex(v,T){return this.fromBytes(Ze(v),T)}assertRecovery(){let{recovery:v}=this;if(v==null)throw new Error("invalid recovery id: must be present");return v}addRecoveryBit(v){return new A(this.r,this.s,v)}recoverPublicKey(v){let{r:T,s:O}=this,C=this.assertRecovery(),R=C===2||C===3?T+c:T;if(!i.isValid(R))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let P=i.toBytes(R),U=r.fromBytes(J(lf((C&1)===0),P)),z=a.inv(R),N=L(M(v,void 0,"msgHash")),Q=a.create(-N*z),tt=a.create(O*z),et=r.BASE.multiplyUnsafe(Q).add(U.multiplyUnsafe(tt));if(et.is0())throw new Error("invalid recovery: point at infinify");return et.assertValidity(),et}hasHighS(){return l(this.s)}toBytes(v=x.format){if(di(v),v==="der")return Ze(It.hexFromSig(this));let{r:T,s:O}=this,C=a.toBytes(T),R=a.toBytes(O);return v==="recovered"?(w(),J(Uint8Array.of(this.assertRecovery()),C,R)):J(C,R)}toHex(v){return Ge(this.toBytes(v))}}Object.freeze(A.prototype),Object.freeze(A);let D=e.bits2int===void 0?function(v){if(v.length>8192)throw new Error("input is too large");let T=ge(v),O=v.length*8-f;return O>0?T>>BigInt(O):T}:e.bits2int,L=e.bits2int_modN===void 0?function(v){return a.create(D(v))}:e.bits2int_modN,B=kr(f);function k(S){return Ye("num < 2^"+f,S,Ot,B),a.toBytes(S)}function q(S,v){return M(S,void 0,"message"),v?M(n(S),void 0,"prehashed message"):S}function F(S,v,T){let{lowS:O,prehash:C,extraEntropy:R}=li(T,x);S=q(S,C);let P=L(S),U=a.fromBytes(v);if(!a.isValidNot0(U))throw new Error("invalid private key");let z=[k(U),k(P)];if(R!=null&&R!==!1){let et=R===!0?o(b.secretKey):R;z.push(M(et,void 0,"extraEntropy"))}let N=J(...z),Q=P;function tt(et){let Y=D(et);if(!a.isValidNot0(Y))return;let pt=a.inv(Y),Ce=r.BASE.multiply(Y).toAffine(),pr=a.create(Ce.x);if(pr===Ot)return;let nn=a.create(pt*a.create(Q+pr*U));if(nn===Ot)return;let Xi=(Ce.x===pr?0:2)|Number(Ce.y&fe),Wi=nn;return O&&l(nn)&&(Wi=a.neg(nn),Xi^=1),new A(pr,Wi,m?void 0:Xi)}return{seed:N,k2sig:tt}}function y(S,v,T={}){let{seed:O,k2sig:C}=F(S,v,T);return dc(n.outputLen,a.BYTES,s)(O,C).toBytes(T.format)}function E(S,v,T,O={}){let{lowS:C,prehash:R,format:P}=li(O,x);if(T=M(T,void 0,"publicKey"),v=q(v,R),!me(S)){let U=S instanceof A?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+U)}_(S,P);try{let U=A.fromBytes(S,P),z=r.fromBytes(T);if(C&&U.hasHighS())return!1;let{r:N,s:Q}=U,tt=L(v),et=a.inv(Q),Y=a.create(tt*et),pt=a.create(N*et),Ce=r.BASE.multiplyUnsafe(Y).add(z.multiplyUnsafe(pt));return Ce.is0()?!1:a.create(Ce.x)===N}catch{return!1}}function I(S,v,T={}){let{prehash:O}=li(T,x);return v=q(v,O),A.fromBytes(S,"recovered").recoverPublicKey(v).toBytes()}return Object.freeze({keygen:d,getPublicKey:h,getSharedSecret:u,utils:p,lengths:b,Point:r,sign:y,verify:E,recoverPublicKey:I,Signature:A,hash:n})}var mi={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},jh={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var pf=BigInt(2);function $h(r){let t=mi.p,e=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),a=BigInt(44),c=BigInt(88),f=r*r*r%t,d=f*f*r%t,h=j(d,e,t)*d%t,u=j(h,e,t)*d%t,p=j(u,pf,t)*f%t,b=j(p,o,t)*p%t,x=j(b,s,t)*b%t,m=j(x,a,t)*x%t,l=j(m,c,t)*m%t,g=j(l,a,t)*x%t,w=j(g,e,t)*d%t,_=j(w,i,t)*b%t,A=j(_,n,t)*f%t,D=j(A,pf,t);if(!pi.eql(pi.sqr(D),r))throw new Error("Cannot find square root");return D}var pi=We(mi.p,{sqrt:$h}),Gh=uf(mi,{Fp:pi,endo:jh}),nr=hf(Gh,fc);function mf(r,t,e,n){let o=qr.digest(e instanceof Uint8Array?e:e.subarray());if(Rn(o))return o.then(({digest:s})=>(n?.signal?.throwIfAborted(),nr.verify(t,s,r,{prehash:!1,format:"der"}))).catch(s=>{throw s.name==="AbortError"?s:new Mr(String(s))});try{return n?.signal?.throwIfAborted(),nr.verify(t,o.digest,r,{prehash:!1,format:"der"})}catch(s){throw new Mr(String(s))}}var Kn=class{type="secp256k1";raw;_key;constructor(t){this._key=bf(t),this.raw=gf(this._key)}toMultihash(){return xt.digest(je(this))}toCID(){return ct.createV1(114,this.toMultihash())}toString(){return X.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:wt(this.raw,t.raw)}verify(t,e,n){return mf(this._key,e,t,n)}};function yf(r){return new Kn(r)}function gf(r){return nr.Point.fromBytes(r).toBytes()}function bf(r){try{return nr.Point.fromBytes(r),r}catch(t){throw new sn(String(t))}}function xf(r){let{Type:t,Data:e}=$r.decode(r.digest),n=e??new Uint8Array;switch(t){case ht.Ed25519:return zc(n);case ht.secp256k1:return yf(n);case ht.ECDSA:return $a(n);default:throw new mr}}function je(r){return $r.encode({Type:ht[r.type],Data:r.raw})}var wf=Symbol.for("nodejs.util.inspect.custom"),Zh=114,Gr=class{type;multihash;publicKey;string;constructor(t){this.type=t.type,this.multihash=t.multihash,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[xo]=!0;toString(){return this.string==null&&(this.string=X.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return ct.createV1(Zh,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return wt(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return wt(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[wf](){return`PeerId(${this.toString()})`}},qn=class extends Gr{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},Vn=class extends Gr{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},Hn=class extends Gr{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},Yh=2336,jn=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=xt.digest(ft(this.url))}[wf](){return`PeerId(${this.url})`}[xo]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return ct.createV1(Yh,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=yt(t)),t.toString()===this.toString())}};function $n(r){if(Wh(r))return new qn({multihash:r});if(Xh(r))try{let t=xf(r);if(t.type==="Ed25519")return new Vn({multihash:r,publicKey:t});if(t.type==="secp256k1")return new Hn({multihash:r,publicKey:t})}catch{let e=yt(r.digest);return new jn(new URL(e))}throw new an("Supplied PeerID Multihash is invalid")}function Xh(r){return r.code===xt.code}function Wh(r){return r.code===qr.code}function gi(r,t){let e={[Symbol.iterator]:()=>e,next:()=>{let n=r.next(),o=n.value;return n.done===!0||o==null?{done:!0,value:void 0}:{done:!1,value:t(o)}}};return e}function Gn(r){let t=le(X.decode(`z${r}`));return $n(t)}var Zn=class r{set;constructor(t){if(this.set=new Set,t!=null)for(let e of t)this.set.add(e.toString())}get size(){return this.set.size}[Symbol.iterator](){return this.values()}add(t){this.set.add(t.toString())}clear(){this.set.clear()}delete(t){this.set.delete(t.toString())}entries(){return gi(this.set.entries(),t=>{let e=Gn(t[0]);return[e,e]})}forEach(t){this.set.forEach(e=>{let n=Gn(e);t(n,n,this)})}has(t){return this.set.has(t.toString())}values(){return gi(this.set.values(),t=>Gn(t))}intersection(t){let e=new r;for(let n of t)this.has(n)&&e.add(n);return e}difference(t){let e=new r;for(let n of this)t.has(n)||e.add(n);return e}union(t){let e=new r;for(let n of t)e.add(n);for(let n of this)e.add(n);return e}};function bi(){return new Zn}var yi={32:16777619n,64:1099511628211n,128:309485009821345068724781371n,256:374144419156711147060143317175368453031918731002211n,512:35835915874844867368919076489095108449946327955754392558399825615420669938882575126094039892345713852759n,1024:5016456510113118655434598811035278955030765345404790744303017523831112055108147451509157692220295382716162651878526895249385292291816524375083746691371804094271873160484737966720260389217684476157468082573n},Ef={32:2166136261n,64:14695981039346656037n,128:144066263297769815596495629667062367629n,256:100029257958052580907070968620625704837092796014241193945225284501741471925557n,512:9659303129496669498009435400716310466090418745672637896108374329434462657994582932197716438449813051892206539805784495328239340083876191928701583869517785n,1024:14197795064947621068722070641403218320880622795441933960878474914617582723252296732303717722150864096521202355549365628174669108571814760471015076148029755969804077320157692458563003215304957150157403644460363550505412711285966361610267868082893823963790439336411086884584107735010676915n},vf=new globalThis.TextEncoder;function Qh(r,t){let e=yi[t],n=Ef[t];for(let o=0;o<r.length;o++)n^=BigInt(r[o]),n=BigInt.asUintN(t,n*e);return n}function Jh(r,t,e){if(e.length===0)throw new Error("The `utf8Buffer` option must have a length greater than zero");let n=yi[t],o=Ef[t],s=r;for(;s.length>0;){let i=vf.encodeInto(s,e);s=s.slice(i.read);for(let a=0;a<i.written;a++)o^=BigInt(e[a]),o=BigInt.asUintN(t,o*n)}return o}function xi(r,{size:t=32,utf8Buffer:e}={}){if(!yi[t])throw new Error("The `size` option must be one of 32, 64, 128, 256, 512, or 1024");if(typeof r=="string"){if(e)return Jh(r,t,e);r=vf.encode(r)}return Qh(r,t)}var Zr={hash:r=>Number(xi(r,{size:32})),hashV:(r,t)=>tp(Zr.hash(r,t))};function tp(r){let t=r.toString(16);return t.length%2===1&&(t=`0${t}`),ft(t,"base16")}var wi=64,Tt=class{fp;h;seed;constructor(t,e,n,o=2){if(o>wi)throw new TypeError("Invalid Fingerprint Size");let s=e.hashV(t,n),i=za(o);for(let a=0;a<i.length;a++)i[a]=s[a];i.length===0&&(i[0]=7),this.fp=i,this.h=e,this.seed=n}hash(){return this.h.hash(this.fp,this.seed)}equals(t){return t?.fp instanceof Uint8Array?wt(this.fp,t.fp):!1}};function Se(r,t){return Math.floor(Math.random()*(t-r))+r}var _e=class{contents;constructor(t){this.contents=new Array(t).fill(null)}has(t){if(!(t instanceof Tt))throw new TypeError("Invalid Fingerprint");return this.contents.some(e=>t.equals(e))}add(t){if(!(t instanceof Tt))throw new TypeError("Invalid Fingerprint");for(let e=0;e<this.contents.length;e++)if(this.contents[e]==null)return this.contents[e]=t,!0;return!0}swap(t){if(!(t instanceof Tt))throw new TypeError("Invalid Fingerprint");let e=Se(0,this.contents.length-1),n=this.contents[e];return this.contents[e]=t,n}remove(t){if(!(t instanceof Tt))throw new TypeError("Invalid Fingerprint");let e=this.contents.findIndex(n=>t.equals(n));return e>-1?(this.contents[e]=null,!0):!1}};var ep=500,Yr=class{bucketSize;filterSize;fingerprintSize;buckets;count;hash;seed;constructor(t){this.filterSize=t.filterSize,this.bucketSize=t.bucketSize??4,this.fingerprintSize=t.fingerprintSize??2,this.count=0,this.buckets=[],this.hash=t.hash??Zr,this.seed=t.seed??Se(0,Math.pow(2,10))}add(t){typeof t=="string"&&(t=ft(t));let e=new Tt(t,this.hash,this.seed,this.fingerprintSize),n=this.hash.hash(t,this.seed)%this.filterSize,o=(n^e.hash())%this.filterSize;if(this.buckets[n]==null&&(this.buckets[n]=new _e(this.bucketSize)),this.buckets[o]==null&&(this.buckets[o]=new _e(this.bucketSize)),this.buckets[n].add(e)||this.buckets[o].add(e))return this.count++,!0;let s=[n,o],i=s[Se(0,s.length-1)];this.buckets[i]==null&&(this.buckets[i]=new _e(this.bucketSize));for(let a=0;a<ep;a++){let c=this.buckets[i].swap(e);if(c!=null&&(i=(i^c.hash())%this.filterSize,this.buckets[i]==null&&(this.buckets[i]=new _e(this.bucketSize)),this.buckets[i].add(c)))return this.count++,!0}return!1}has(t){typeof t=="string"&&(t=ft(t));let e=new Tt(t,this.hash,this.seed,this.fingerprintSize),n=this.hash.hash(t,this.seed)%this.filterSize,o=this.buckets[n]?.has(e)??!1;if(o)return o;let s=(n^e.hash())%this.filterSize;return this.buckets[s]?.has(e)??!1}remove(t){typeof t=="string"&&(t=ft(t));let e=new Tt(t,this.hash,this.seed,this.fingerprintSize),n=this.hash.hash(t,this.seed)%this.filterSize,o=this.buckets[n]?.remove(e)??!1;if(o)return this.count--,o;let s=(n^e.hash())%this.filterSize,i=this.buckets[s]?.remove(e)??!1;return i&&this.count--,i}get reliable(){return Math.floor(100*(this.count/this.filterSize))<=90}},rp={1:.5,2:.84,4:.95,8:.98};function np(r=.001){return r>.002?2:r>1e-5?4:8}function Sf(r,t=.001){let e=np(t),n=rp[e],o=Math.round(r/n),s=Math.min(Math.ceil(Math.log2(1/t)+Math.log2(2*e)),wi);return{filterSize:o,bucketSize:e,fingerprintSize:s}}var Yn=class{filterSize;bucketSize;fingerprintSize;scale;filterSeries;hash;seed;constructor(t){this.bucketSize=t.bucketSize??4,this.filterSize=t.filterSize??(1<<18)/this.bucketSize,this.fingerprintSize=t.fingerprintSize??2,this.scale=t.scale??2,this.hash=t.hash??Zr,this.seed=t.seed??Se(0,Math.pow(2,10)),this.filterSeries=[new Yr({filterSize:this.filterSize,bucketSize:this.bucketSize,fingerprintSize:this.fingerprintSize,hash:this.hash,seed:this.seed})]}add(t){if(typeof t=="string"&&(t=ft(t)),this.has(t))return!0;let e=this.filterSeries.find(n=>n.reliable);if(e==null){let n=this.filterSize*Math.pow(this.scale,this.filterSeries.length);e=new Yr({filterSize:n,bucketSize:this.bucketSize,fingerprintSize:this.fingerprintSize,hash:this.hash,seed:this.seed}),this.filterSeries.push(e)}return e.add(t)}has(t){typeof t=="string"&&(t=ft(t));for(let e=0;e<this.filterSeries.length;e++)if(this.filterSeries[e].has(t))return!0;return!1}remove(t){typeof t=="string"&&(t=ft(t));for(let e=0;e<this.filterSeries.length;e++)if(this.filterSeries[e].remove(t))return!0;return!1}get count(){return this.filterSeries.reduce((t,e)=>t+e.count,0)}};function Ei(r,t=.001,e){return new Yn({...Sf(r,t),...e??{}})}function op(r){let t=r.getComponents(),e={},n=0;return t[n]?.name==="ip6zone"&&(e.zone=`${t[n].value}`,n++),t[n]?.name==="ip4"||t[n]?.name==="ip6"||t[n]?.name==="dns"||t[n]?.name==="dns4"||t[n]?.name==="dns6"?(e.type=t[n].name,e.host=t[n].value,n++):t[n]?.name==="dnsaddr"&&(e.type=t[n].name,e.host=`_dnsaddr.${t[n].value}`,n++),(t[n]?.name==="tcp"||t[n]?.name==="udp")&&(e.protocol=t[n].name==="tcp"?"tcp":"udp",e.port=parseInt(`${t[n].value}`),n++),t[n]?.name==="ipcidr"&&(e.type==="ip4"?e.cidr=parseInt(`${t[n].value}`):e.type==="ip6"&&(e.cidr=`${t[n].value}`),n++),e.type==null||e.host==null?null:(t[n]?.name==="tls"&&t[n+1]?.name==="sni"&&(e.sni=t[n+1].value,n+=2),e)}function Bt(r){let t=op(r);if(t==null)throw new dt(`Multiaddr ${r} was not an IPv4, IPv6, DNS, DNS4, DNS6 or DNSADDR address`);return t}var Xn=class{index=0;input="";new(t){return this.index=0,this.input=t,this}readAtomically(t){let e=this.index,n=t();return n===void 0&&(this.index=e),n}parseWith(t){let e=t();if(this.index===this.input.length)return e}peekChar(){if(!(this.index>=this.input.length))return this.input[this.index]}readChar(){if(!(this.index>=this.input.length))return this.input[this.index++]}readGivenChar(t){return this.readAtomically(()=>{let e=this.readChar();if(e===t)return e})}readSeparator(t,e,n){return this.readAtomically(()=>{if(!(e>0&&this.readGivenChar(t)===void 0))return n()})}readNumber(t,e,n,o){return this.readAtomically(()=>{let s=0,i=0,a=this.peekChar();if(a===void 0)return;let c=a==="0",f=2**(8*o)-1;for(;;){let d=this.readAtomically(()=>{let h=this.readChar();if(h===void 0)return;let u=Number.parseInt(h,t);if(!Number.isNaN(u))return u});if(d===void 0)break;if(s*=t,s+=d,s>f||(i+=1,e!==void 0&&i>e))return}if(i!==0)return!n&&c&&i>1?void 0:s})}readIPv4Addr(){return this.readAtomically(()=>{let t=new Uint8Array(4);for(let e=0;e<t.length;e++){let n=this.readSeparator(".",e,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;t[e]=n}return t})}readIPv6Addr(){let t=e=>{for(let n=0;n<e.length/2;n++){let o=n*2;if(n<e.length-3){let i=this.readSeparator(":",n,()=>this.readIPv4Addr());if(i!==void 0)return e[o]=i[0],e[o+1]=i[1],e[o+2]=i[2],e[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];e[o]=s>>8,e[o+1]=s&255}return[e.length,!1]};return this.readAtomically(()=>{let e=new Uint8Array(16),[n,o]=t(e);if(n===16)return e;if(o||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let s=new Uint8Array(14),i=16-(n+2),[a]=t(s.subarray(0,i));return e.set(s.subarray(0,a),16-a),e})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var _f=45,sp=15,or=new Xn;function Wn(r){if(!(r.length>sp))return or.new(r).parseWith(()=>or.readIPv4Addr())}function Qn(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>_f))return or.new(r).parseWith(()=>or.readIPv6Addr())}function sr(r,t=!1){if(r.includes("%")&&(r=r.split("%")[0]),r.length>_f)return;let e=or.new(r).parseWith(()=>or.readIPAddr());if(e)return t&&e.length===4?Uint8Array.from([0,0,0,0,0,0,0,0,0,0,255,255,e[0],e[1],e[2],e[3]]):e}function Af(r,t,e){let n=0;for(let o of r)if(!(n<t)){if(n>e)break;if(o!==255)return!1;n++}return!0}function If(r,t,e,n){let o=0;for(let s of r)if(!(o<e)){if(o>n)break;if(s!==t[o])return!1;o++}return!0}function vi(r){switch(r.length){case Ae:return r.join(".");case Ie:{let t=[];for(let e=0;e<r.length;e++)e%2===0&&t.push(r[e].toString(16).padStart(2,"0")+r[e+1].toString(16).padStart(2,"0"));return t.join(":")}default:throw new Error("Invalid ip length")}}function Tf(r){let t=0;for(let[e,n]of r.entries()){if(n===255){t+=8;continue}for(;(n&128)!=0;)t++,n=n<<1;if((n&128)!=0)return-1;for(let o=e+1;o<r.length;o++)if(r[o]!=0)return-1;break}return t}function Bf(r){let t="0x";for(let e of r)t+=(e>>4).toString(16)+(e&15).toString(16);return t}var Ae=4,Ie=16,v1=parseInt("0xFFFF",16),ip=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function Xr(r,t){t.length===Ie&&r.length===Ae&&Af(t,0,11)&&(t=t.slice(12)),t.length===Ae&&r.length===Ie&&If(r,ip,0,11)&&(r=r.slice(12));let e=r.length;if(e!=t.length)throw new Error("Failed to mask ip");let n=new Uint8Array(e);for(let o=0;o<e;o++)n[o]=r[o]&t[o];return n}function Lf(r,t){if(typeof t=="string"&&(t=sr(t)),t==null)throw new Error("Invalid ip");if(t.length!==r.network.length)return!1;for(let e=0;e<t.length;e++)if((r.network[e]&r.mask[e])!==(t[e]&r.mask[e]))return!1;return!0}function Si(r){let[t,e]=r.split("/");if(!t||!e)throw new Error("Failed to parse given CIDR: "+r);let n=Ae,o=Wn(t);if(o==null&&(n=Ie,o=Qn(t),o==null))throw new Error("Failed to parse given CIDR: "+r);let s=parseInt(e,10);if(Number.isNaN(s)||String(s).length!==e.length||s<0||s>n*8)throw new Error("Failed to parse given CIDR: "+r);let i=_i(s,8*n);return{network:Xr(o,i),mask:i}}function _i(r,t){if(t!==8*Ae&&t!==8*Ie)throw new Error("Invalid CIDR mask");if(r<0||r>t)throw new Error("Invalid CIDR mask");let e=t/8,n=new Uint8Array(e);for(let o=0;o<e;o++){if(r>=8){n[o]=255,r-=8;continue}n[o]=255-(255>>r),r=0}return n}var Wr=class{constructor(t,e){if(e==null)({network:this.network,mask:this.mask}=Si(t));else{let n=sr(t);if(n==null)throw new Error("Failed to parse network");e=String(e);let o=parseInt(e,10);if(Number.isNaN(o)||String(o).length!==e.length||o<0||o>n.length*8){let s=sr(e);if(s==null)throw new Error("Failed to parse mask");this.mask=s}else this.mask=_i(o,8*n.length);this.network=Xr(n,this.mask)}}contains(t){return Lf({network:this.network,mask:this.mask},t)}toString(){let t=Tf(this.mask),e=t!==-1?String(t):Bf(this.mask);return vi(this.network)+"/"+e}};function Df(r,t){return new Wr(r).contains(t)}function Cf(r){try{let t=Bt(r);return t.type==="ip6"?Df("2000::/3",t.host):!1}catch{return!1}}function ir(r){return!!Wn(r)}function Jn(r){return!!Qn(r)}var kf=lu(Pf(),1),hp=["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"],pp=hp.map(r=>new kf.Netmask(r));function Ci(r){for(let t of pp)if(t.contains(r))return!0;return!1}function mp(r){return/^::ffff:([0-9a-fA-F]{1,4}):([0-9a-fA-F]{1,4})$/.test(r)}function gp(r){let t=r.split(":");if(t.length<2)return!1;let e=t[t.length-1].padStart(4,"0"),n=t[t.length-2].padStart(4,"0"),o=`${parseInt(n.substring(0,2),16)}.${parseInt(n.substring(2),16)}.${parseInt(e.substring(0,2),16)}.${parseInt(e.substring(2),16)}`;return Ci(o)}function bp(r){return/^::ffff:([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(r)}function yp(r){let t=r.split(":"),e=t[t.length-1];return Ci(e)}function xp(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 Ff(r){if(ir(r))return Ci(r);if(mp(r))return gp(r);if(bp(r))return yp(r);if(Jn(r))return xp(r)}function Oi(r){try{let t=Bt(r);switch(t.type){case"ip4":case"ip6":return Ff(t.host)??!1;default:return t.host==="localhost"}}catch{return!1}}function Nf(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}function eo(r=0){return new Uint8Array(r)}function Qr(r,t){t==null&&(t=r.reduce((o,s)=>o+s.length,0));let e=eo(t),n=0;for(let o of r)e.set(o,n),n+=o.length;return e}function Mf(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var Uf=Mf("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Ri=Mf("ascii","a",r=>{let t="a";for(let e=0;e<r.length;e++)t+=String.fromCharCode(r[e]);return t},r=>{r=r.substring(1);let t=eo(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),wp={utf8:Uf,"utf-8":Uf,hex:ce.base16,latin1:Ri,ascii:Ri,binary:Ri,...ce},ro=wp;function Jr(r,t="utf8"){let e=ro[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.decoder.decode(`${e.prefix}${r}`)}function Be(r,t="utf8"){let e=ro[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.encoder.encode(r).substring(1)}var at=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},Gt=class extends Error{static name="ValidationError";name="ValidationError"},no=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},oo=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};function ki(r){return t=>Be(t,r)}function Fi(r){return t=>Jr(t,r)}function ur(r){return new DataView(r.buffer).getUint16(r.byteOffset).toString()}function Le(r){let t=new ArrayBuffer(2);return new DataView(t).setUint16(0,typeof r=="string"?parseInt(r):r),new Uint8Array(t)}function zf(r){let t=r.split(":");if(t.length!==2)throw new Error(`failed to parse onion addr: ["'${t.join('", "')}'"]' does not contain a port number`);if(t[0].length!==16)throw new Error(`failed to parse onion addr: ${t[0]} not a Tor onion address.`);let e=Jr(t[0],"base32"),n=parseInt(t[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=Le(n);return Qr([e,o],e.length+o.length)}function Kf(r){let t=r.split(":");if(t.length!==2)throw new Error(`failed to parse onion addr: ["'${t.join('", "')}'"]' does not contain a port number`);if(t[0].length!==56)throw new Error(`failed to parse onion addr: ${t[0]} not a Tor onion3 address.`);let e=Xt.decode(`b${t[0]}`),n=parseInt(t[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=Le(n);return Qr([e,o],e.length+o.length)}function Ni(r){let t=r.subarray(0,r.length-2),e=r.subarray(r.length-2),n=Be(t,"base32"),o=ur(e);return`${n}:${o}`}var Ui=function(r){r=r.toString().trim();let t=new Uint8Array(4);return r.split(/\./g).forEach((e,n)=>{let o=parseInt(e,10);if(isNaN(o)||o<0||o>255)throw new at("Invalid byte value in IP address");t[n]=o}),t},qf=function(r){let t=0;r=r.toString().trim();let e=r.split(":",8),n;for(n=0;n<e.length;n++){let s=ir(e[n]),i;s&&(i=Ui(e[n]),e[n]=Be(i.subarray(0,2),"base16")),i!=null&&++n<8&&e.splice(n,0,Be(i.subarray(2,4),"base16"))}if(e[0]==="")for(;e.length<8;)e.unshift("0");else if(e[e.length-1]==="")for(;e.length<8;)e.push("0");else if(e.length<8){for(n=0;n<e.length&&e[n]!=="";n++);let s=[n,1];for(n=9-e.length;n>0;n--)s.push("0");e.splice.apply(e,s)}let o=new Uint8Array(t+16);for(n=0;n<e.length;n++){e[n]===""&&(e[n]="0");let s=parseInt(e[n],16);if(isNaN(s)||s<0||s>65535)throw new at("Invalid byte value in IP address");o[t++]=s>>8&255,o[t++]=s&255}return o},Vf=function(r){if(r.byteLength!==4)throw new at("IPv4 address was incorrect length");let t=[];for(let e=0;e<r.byteLength;e++)t.push(r[e]);return t.join(".")},Hf=function(r){if(r.byteLength!==16)throw new at("IPv6 address was incorrect length");let t=[];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")}`;t.push(i)}let e=t.join(":");try{let n=new URL(`http://[${e}]`);return n.hostname.substring(1,n.hostname.length-1)}catch{throw new at(`Invalid IPv6 address "${e}"`)}};function jf(r){try{let t=new URL(`http://[${r}]`);return t.hostname.substring(1,t.hostname.length-1)}catch{throw new at(`Invalid IPv6 address "${r}"`)}}var Pi=Object.values(ce).map(r=>r.decoder),Ep=(function(){let r=Pi[0].or(Pi[1]);return Pi.slice(2).forEach(t=>r=r.or(t)),r})();function $f(r){return Ep.decode(r)}function Gf(r){return t=>r.encoder.encode(t)}function vp(r){if(parseInt(r).toString()!==r)throw new Gt("Value must be an integer")}function Sp(r){if(r<0)throw new Gt("Value must be a positive integer, or zero")}function _p(r){return t=>{if(t>r)throw new Gt(`Value must be smaller than or equal to ${r}`)}}function Ap(...r){return t=>{for(let e of r)e(t)}}var tn=Ap(vp,Sp,_p(65535));var ot=-1,Mi=class{protocolsByCode=new Map;protocolsByName=new Map;getProtocol(t){let e;if(typeof t=="string"?e=this.protocolsByName.get(t):e=this.protocolsByCode.get(t),e==null)throw new oo(`Protocol ${t} was unknown`);return e}addProtocol(t){this.protocolsByCode.set(t.code,t),this.protocolsByName.set(t.name,t),t.aliases?.forEach(e=>{this.protocolsByName.set(e,t)})}removeProtocol(t){let e=this.protocolsByCode.get(t);e!=null&&(this.protocolsByCode.delete(e.code),this.protocolsByName.delete(e.name),e.aliases?.forEach(n=>{this.protocolsByName.delete(n)}))}},Zt=new Mi,l0=[{code:4,name:"ip4",size:32,valueToBytes:Ui,bytesToValue:Vf,validate:r=>{if(!ir(r))throw new Gt(`Invalid IPv4 address "${r}"`)}},{code:6,name:"tcp",size:16,valueToBytes:Le,bytesToValue:ur,validate:tn},{code:273,name:"udp",size:16,valueToBytes:Le,bytesToValue:ur,validate:tn},{code:33,name:"dccp",size:16,valueToBytes:Le,bytesToValue:ur,validate:tn},{code:41,name:"ip6",size:128,valueToBytes:qf,bytesToValue:Hf,stringToValue:jf,validate:r=>{if(!Jn(r))throw new Gt(`Invalid IPv6 address "${r}"`)}},{code:42,name:"ip6zone",size:ot},{code:43,name:"ipcidr",size:8,bytesToValue:ki("base10"),valueToBytes:Fi("base10")},{code:53,name:"dns",size:ot},{code:54,name:"dns4",size:ot},{code:55,name:"dns6",size:ot},{code:56,name:"dnsaddr",size:ot},{code:132,name:"sctp",size:16,valueToBytes:Le,bytesToValue:ur,validate:tn},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:ot,stringToValue:r=>decodeURIComponent(r),valueToString:r=>encodeURIComponent(r)},{code:421,name:"p2p",aliases:["ipfs"],size:ot,bytesToValue:ki("base58btc"),valueToBytes:r=>r.startsWith("Q")||r.startsWith("1")?Fi("base58btc")(r):ct.parse(r).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:Ni,valueToBytes:zf},{code:445,name:"onion3",size:296,bytesToValue:Ni,valueToBytes:Kf},{code:446,name:"garlic64",size:ot},{code:447,name:"garlic32",size:ot},{code:448,name:"tls"},{code:449,name:"sni",size:ot},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:ot,bytesToValue:Gf(Ys),valueToBytes:$f},{code:480,name:"http"},{code:481,name:"http-path",size:ot,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:ot}];l0.forEach(r=>{Zt.addProtocol(r)});function Zf(r){let t=[],e=0;for(;e<r.length;){let n=zr(r,e),o=Zt.getProtocol(n),s=mt(n),i=d0(o,r,e+s),a=0;i>0&&o.size===ot&&(a=mt(i));let c=s+a+i,f={code:n,name:o.name,bytes:r.subarray(e,e+c)};if(i>0){let d=e+s+a,h=r.subarray(d,d+i);f.value=o.bytesToValue?.(h)??Be(h)}t.push(f),e+=c}return t}function Yf(r){let t=0,e=[];for(let n of r){if(n.bytes==null){let o=Zt.getProtocol(n.code),s=mt(n.code),i,a=0,c=0;n.value!=null&&(i=o.valueToBytes?.(n.value)??Jr(n.value),a=i.byteLength,o.size===ot&&(c=mt(a)));let f=new Uint8Array(s+c+a),d=0;er(n.code,f,d),d+=s,i!=null&&(o.size===ot&&(er(a,f,d),d+=c),f.set(i,d)),n.bytes=f}e.push(n.bytes),t+=n.bytes.byteLength}return Qr(e,t)}function Xf(r){if(r.charAt(0)!=="/")throw new at('String multiaddr must start with "/"');let t=[],e="protocol",n="",o="";for(let s=1;s<r.length;s++){let i=r.charAt(s);i!=="/"&&(e==="protocol"?o+=r.charAt(s):n+=r.charAt(s));let a=s===r.length-1;if(i==="/"||a){let c=Zt.getProtocol(o);if(e==="protocol"){if(c.size==null||c.size===0){t.push({code:c.code,name:c.name}),n="",o="",e="protocol";continue}else if(a)throw new at(`Component ${o} was missing value`);e="value"}else if(e==="value"){let f={code:c.code,name:c.name};if(c.size!=null&&c.size!==0){if(n==="")throw new at(`Component ${o} was missing value`);f.value=c.stringToValue?.(n)??n}t.push(f),n="",o="",e="protocol"}}}if(o!==""&&n!=="")throw new at("Incomplete multiaddr");return t}function Wf(r){return`/${r.flatMap(t=>{if(t.value==null)return t.name;let e=Zt.getProtocol(t.code);if(e==null)throw new at(`Unknown protocol code ${t.code}`);return[t.name,e.valueToString?.(t.value)??t.value]}).join("/")}`}function d0(r,t,e){return r.size==null||r.size===0?0:r.size>0?r.size/8:zr(t,e)}var h0=Symbol.for("nodejs.util.inspect.custom"),zi=Symbol.for("@multiformats/multiaddr");function p0(r){if(r==null&&(r="/"),Qf(r))return r.getComponents();if(r instanceof Uint8Array)return Zf(r);if(typeof r=="string")return r=r.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),r===""&&(r="/"),Xf(r);if(Array.isArray(r))return r;throw new at("Must be a string, Uint8Array, Component[], or another Multiaddr")}var io=class r{[zi]=!0;#t;#e;#r;constructor(t="/",e={}){this.#t=p0(t),e.validate!==!1&&m0(this)}get bytes(){return this.#r==null&&(this.#r=Yf(this.#t)),this.#r}toString(){return this.#e==null&&(this.#e=Wf(this.#t)),this.#e}toJSON(){return this.toString()}getComponents(){return[...this.#t.map(t=>({...t}))]}encapsulate(t){let e=new r(t);return new r([...this.#t,...e.getComponents()],{validate:!1})}decapsulate(t){let e=t.toString(),n=this.toString(),o=n.lastIndexOf(e);if(o<0)throw new no(`Address ${this.toString()} does not contain subaddress: ${e}`);return new r(n.slice(0,o),{validate:!1})}decapsulateCode(t){let e;for(let n=this.#t.length-1;n>-1;n--)if(this.#t[n].code===t){e=n;break}return new r(this.#t.slice(0,e),{validate:!1})}equals(t){return Nf(this.bytes,t.bytes)}[h0](){return`Multiaddr(${this.toString()})`}};function m0(r){r.getComponents().forEach(t=>{let e=Zt.getProtocol(t.code);t.value!=null&&e.validate?.(t.value)})}function Qf(r){return!!r?.[zi]}function Jf(r){return new io(r)}function lr(){let r={};return r.promise=new Promise((t,e)=>{r.resolve=t,r.reject=e}),r}var ao=class{buffer;mask;top;btm;next;constructor(t){if(!(t>0)||(t-1&t)!==0)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(t),this.mask=t-1,this.top=0,this.btm=0,this.next=null}push(t){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=t,this.top=this.top+1&this.mask,!0)}shift(){let t=this.buffer[this.btm];if(t!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,t}isEmpty(){return this.buffer[this.btm]===void 0}},dr=class{size;hwm;head;tail;constructor(t={}){this.hwm=t.splitLimit??16,this.head=new ao(this.hwm),this.tail=this.head,this.size=0}calculateSize(t){return t?.byteLength!=null?t.byteLength:1}push(t){if(t?.value!=null&&(this.size+=this.calculateSize(t.value)),!this.head.push(t)){let e=this.head;this.head=e.next=new ao(2*this.head.buffer.length),this.head.push(t)}}shift(){let t=this.tail.shift();if(t===void 0&&this.tail.next!=null){let e=this.tail.next;this.tail.next=null,this.tail=e,t=this.tail.shift()}return t?.value!=null&&(this.size-=this.calculateSize(t.value)),t}isEmpty(){return this.head.isEmpty()}};var Ki=class extends Error{type;code;constructor(t,e){super(t??"The operation was aborted"),this.type="aborted",this.code=e??"ABORT_ERR"}};function co(r={}){return g0(e=>{let n=e.shift();if(n==null)return{done:!0};if(n.error!=null)throw n.error;return{done:n.done===!0,value:n.value}},r)}function g0(r,t){t=t??{};let e=t.onEnd,n=new dr,o,s,i,a=lr(),c=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((m,l)=>{s=g=>{s=null,n.push(g);try{m(r(n))}catch(w){l(w)}return o}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=lr()})}},f=m=>s!=null?s(m):(n.push(m),o),d=m=>(n=new dr,s!=null?s({error:m}):(n.push({error:m}),o)),h=m=>{if(i)return o;if(t?.objectMode!==!0&&m?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return f({done:!1,value:m})},u=m=>i?o:(i=!0,m!=null?d(m):f({done:!0})),p=()=>(n=new dr,u(),{done:!0}),b=m=>(u(m),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:c,return:p,throw:b,push:h,end:u,get readableLength(){return n.size},onEmpty:async m=>{let l=m?.signal;if(l?.throwIfAborted(),n.isEmpty())return;let g,w;l!=null&&(g=new Promise((_,A)=>{w=()=>{A(new Ki)},l.addEventListener("abort",w)}));try{await Promise.race([a.promise,g])}finally{w!=null&&l!=null&&l?.removeEventListener("abort",w)}}},e==null)return o;let x=o;return o={[Symbol.asyncIterator](){return this},next(){return x.next()},throw(m){return x.throw(m),e!=null&&(e(m),e=void 0),{done:!0}},return(){return x.return(),e!=null&&(e(),e=void 0),{done:!0}},push:h,end(m){return x.end(m),e!=null&&(e(m),e=void 0),o},get readableLength(){return x.readableLength},onEmpty:m=>x.onEmpty(m)},o}var qi=class r extends Error{name="TimeoutError";constructor(t,e){super(t,e),Error.captureStackTrace?.(this,r)}},tu=r=>r.reason??new DOMException("This operation was aborted.","AbortError");function Vi(r,t){let{milliseconds:e,fallback:n,message:o,customTimers:s={setTimeout,clearTimeout},signal:i}=t,a,c,d=new Promise((h,u)=>{if(typeof e!="number"||Math.sign(e)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${e}\``);if(i?.aborted){u(tu(i));return}if(i&&(c=()=>{u(tu(i))},i.addEventListener("abort",c,{once:!0})),r.then(h,u),e===Number.POSITIVE_INFINITY)return;let p=new qi;a=s.setTimeout.call(void 0,()=>{if(n){try{h(n())}catch(b){u(b)}return}typeof r.cancel=="function"&&r.cancel(),o===!1?h():o instanceof Error?u(o):(p.message=o??`Promise timed out after ${e} milliseconds`,u(p))},e)}).finally(()=>{d.clear(),c&&i&&i.removeEventListener("abort",c)});return d.clear=()=>{s.clearTimeout.call(void 0,a),a=void 0},d}var b0=r=>{let t=r.addEventListener||r.on||r.addListener,e=r.removeEventListener||r.off||r.removeListener;if(!t||!e)throw new TypeError("Emitter is not compatible");return{addListener:t.bind(r),removeListener:e.bind(r)}};function y0(r,t,e){let n,o=new Promise((s,i)=>{if(e={rejectionEvents:["error"],multiArgs:!1,rejectionMultiArgs:!1,resolveImmediately:!1,...e},!(e.count>=0&&(e.count===Number.POSITIVE_INFINITY||Number.isInteger(e.count))))throw new TypeError("The `count` option should be at least 0 or more");e.signal?.throwIfAborted();let a=[t].flat(),c=[],{addListener:f,removeListener:d}=b0(r),h=async(...p)=>{let b=e.multiArgs?p:p[0];if(e.filter)try{if(!await e.filter(b))return}catch(x){n(),i(x);return}c.push(b),e.count===c.length&&(n(),s(c))},u=(...p)=>{n(),i(e.rejectionMultiArgs?p:p[0])};n=()=>{for(let p of a)d(p,h);for(let p of e.rejectionEvents)a.includes(p)||d(p,u)};for(let p of a)f(p,h);for(let p of e.rejectionEvents)a.includes(p)||f(p,u);e.signal&&e.signal.addEventListener("abort",()=>{u(e.signal.reason)},{once:!0}),e.resolveImmediately&&s(c)});if(o.cancel=n,typeof e.timeout=="number"){let s=Vi(o,{milliseconds:e.timeout});return s.cancel=()=>{n(),s.clear()},s}return o}function hr(r,t,e){typeof e=="function"&&(e={filter:e}),e={...e,count:1,resolveImmediately:!1};let n=y0(r,t,e),o=n.then(s=>s[0]);return o.cancel=n.cancel,o}function en(r,t){let e,n=function(){let o=function(){e=void 0,r()};clearTimeout(e),e=setTimeout(o,t)};return n.start=()=>{},n.stop=()=>{clearTimeout(e)},n}var fo=class extends Error{static name="QueueFullError";constructor(t="The queue was full"){super(t),this.name="QueueFullError"}},De=class extends Error{static name="UnexpectedEOFError";name="UnexpectedEOFError"};function x0(r){return r.reason}async function rn(r,t,e){if(t==null)return r;let n=e?.translateError??x0;if(t.aborted)return r.catch(()=>{}),Promise.reject(n(t));let o;try{return await Promise.race([r,new Promise((s,i)=>{o=()=>{i(n(t))},t.addEventListener("abort",o)})])}finally{o!=null&&t.removeEventListener("abort",o)}}var uo=class{deferred;signal;onProgress;constructor(t){this.signal=t?.signal,this.onProgress=t?.onProgress,this.deferred=lr(),this.onAbort=this.onAbort.bind(this),this.signal?.addEventListener("abort",this.onAbort)}onAbort(){this.deferred.reject(this.signal?.reason??new Pt)}cleanup(){this.signal?.removeEventListener("abort",this.onAbort)}};function w0(){return`${parseInt(String(Math.random()*1e9),10).toString()}${Date.now()}`}var lo=class{id;fn;options;recipients;status;timeline;controller;dispatchingProgress;constructor(t,e){this.id=w0(),this.status="queued",this.fn=t,this.options=e,this.recipients=[],this.timeline={created:Date.now()},this.controller=new AbortController,this.controller.signal,this.dispatchingProgress=!1,this.onAbort=this.onAbort.bind(this)}abort(t){this.controller.abort(t)}onAbort(){this.recipients.reduce((e,n)=>e&&n.signal?.aborted===!0,!0)&&(this.controller.abort(new Pt),this.cleanup())}async join(t){let e=new uo(t);return this.recipients.push(e),t?.signal?.addEventListener("abort",this.onAbort),e.deferred.promise}async run(){this.status="running",this.timeline.started=Date.now();try{this.controller.signal.throwIfAborted();let t=await rn(this.fn({...this.options??{},signal:this.controller.signal,onProgress:e=>{if(!this.dispatchingProgress){this.dispatchingProgress=!0;try{this.recipients.forEach(n=>{n.onProgress?.(e)})}finally{this.dispatchingProgress=!1}}}}),this.controller.signal);this.recipients.forEach(e=>{e.deferred.resolve(t)}),this.status="complete"}catch(t){this.recipients.forEach(e=>{e.deferred.reject(t)}),this.status="errored"}finally{this.timeline.finished=Date.now(),this.cleanup()}}cleanup(){this.recipients.forEach(t=>{t.cleanup(),t.signal?.removeEventListener("abort",this.onAbort)})}};var ho=class extends cn{concurrency;maxSize;queue;pending;sort;paused;constructor(t={}){super(),this.concurrency=t.concurrency??Number.POSITIVE_INFINITY,this.maxSize=t.maxSize??Number.POSITIVE_INFINITY,this.pending=0,this.paused=!1,t.metricName!=null&&t.metrics?.registerMetricGroup(t.metricName,{calculate:()=>({size:this.queue.length,running:this.pending,queued:this.queue.length-this.pending})}),this.sort=t.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 t;for(let e of this.queue)if(e.status==="queued"){t=e;break}return t==null?!1:(this.safeDispatchEvent("active"),this.pending++,t.run().finally(()=>{for(let e=0;e<this.queue.length;e++)if(this.queue[e]===t){this.queue.splice(e,1);break}this.pending--,this.tryToStartAnother(),this.safeDispatchEvent("next")}),!0)}return!1}enqueue(t){this.queue.push(t),this.sort!=null&&this.queue.sort(this.sort)}async add(t,e){if(e?.signal?.throwIfAborted(),this.size===this.maxSize)throw new fo;let n=new lo(t,e);this.enqueue(n),this.safeDispatchEvent("add");let o=n.join(e).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(t=>{t.abort(new Pt)}),this.clear()}async onEmpty(t){this.size!==0&&await hr(this,"empty",t)}async onSizeLessThan(t,e){this.size<t||await hr(this,"next",{...e,filter:()=>this.size<t})}async onIdle(t){this.pending===0&&this.size===0||await hr(this,"idle",t)}get size(){return this.queue.length}get queued(){return this.queue.length-this.pending}get running(){return this.pending}async*toGenerator(t){t?.signal?.throwIfAborted();let e=co({objectMode:!0}),n=c=>{c!=null?this.abort():this.clear(),e.end(c)},o=c=>{c.detail!=null&&e.push(c.detail)},s=c=>{n(c.detail.error)},i=()=>{n()},a=()=>{n(new Pt("Queue aborted"))};this.addEventListener("completed",o),this.addEventListener("failure",s),this.addEventListener("idle",i),t?.signal?.addEventListener("abort",a);try{yield*e}finally{this.removeEventListener("completed",o),this.removeEventListener("failure",s),this.removeEventListener("idle",i),t?.signal?.removeEventListener("abort",a),n()}}};function po(r){let t=new globalThis.AbortController;function e(){let s=r.filter(i=>i?.aborted===!0).map(i=>i?.reason).pop();t.abort(s);for(let i of r)i?.removeEventListener!=null&&i.removeEventListener("abort",e)}for(let s of r){if(s?.aborted===!0){e();break}s?.addEventListener!=null&&s.addEventListener("abort",e)}function n(){for(let s of r)s?.removeEventListener!=null&&s.removeEventListener("abort",e)}let o=t.signal;return o.clear=n,o}var E0=4194304,mo=class extends Error{static name="UnwrappedError";name="UnwrappedError"},ji=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},$i=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},Gi=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function v0(r){return typeof r?.closeRead=="function"}function S0(r){return typeof r?.close=="function"}function Hi(r){return v0(r)?r.remoteWriteStatus!=="writable"&&r.readBufferLength===0:S0(r)?r.status!=="open":!1}function _0(r){return r?.addEventListener!=null&&r?.removeEventListener!=null&&r?.send!=null&&r?.push!=null&&r?.log!=null}function A0(r,t){let e=t?.maxBufferSize??E0,n=new rt,o,s=!1;if(!_0(r))throw new dt("Argument should be a Stream or a Multiaddr");let i=d=>{if(n.append(d.data),n.byteLength>e){let h=n.byteLength;n.consume(n.byteLength),o?.reject(new Error(`Read buffer overflow - ${h} > ${e}`))}o?.resolve()};r.addEventListener("message",i);let a=d=>{d.error!=null?o?.reject(d.error):o?.resolve()};r.addEventListener("close",a);let c=()=>{o?.resolve()};r.addEventListener("remoteCloseWrite",c);let f={readBuffer:n,async read(d){if(s===!0)throw new mo("Stream was unwrapped");if(Hi(r)){if(n.byteLength===0&&d?.bytes==null)return null;if(d?.bytes!=null&&n.byteLength<d.bytes)throw r.log.error("closed after reading %d/%d bytes",n.byteLength,d.bytes),new De(`Unexpected EOF - stream closed after reading ${n.byteLength}/${d.bytes} bytes`)}let h=d?.bytes??1;for(o=Promise.withResolvers();;){if(n.byteLength>=h){o.resolve();break}if(await rn(o.promise,d?.signal),Hi(r)){if(n.byteLength===0&&d?.bytes==null)return null;break}o=Promise.withResolvers()}let u=d?.bytes??n.byteLength;if(n.byteLength<u){if(Hi(r))throw r.log.error("closed while reading %d/%d bytes",n.byteLength,u),new De(`Unexpected EOF - stream closed while reading ${n.byteLength}/${u} bytes`);return f.read(d)}let p=n.sublist(0,u);return n.consume(u),p},async write(d,h){if(s===!0)throw new mo("Stream was unwrapped");r.send(d)||await hr(r,"drain",{signal:h?.signal,rejectionEvents:["close"]})},unwrap(){return s||(s=!0,r.removeEventListener("message",i),r.removeEventListener("close",a),r.removeEventListener("remoteCloseWrite",c),n.byteLength>0&&(r.log("stream unwrapped with %d unread bytes",n.byteLength),r.unshift(n))),r}};return f}function I0(r,t={}){let e=A0(r,t);t.maxDataLength!=null&&t.maxLengthLength==null&&(t.maxLengthLength=mt(t.maxDataLength));let n=t?.lengthDecoder??zr,o=t?.lengthEncoder??qc;return{async read(i){let a=-1,c=new rt;for(;;){let d=await e.read({...i,bytes:1});if(d==null)break;c.append(d);try{a=n(c)}catch(h){if(h instanceof RangeError)continue;throw h}if(a<0)throw new ji("Invalid message length");if(t?.maxLengthLength!=null&&c.byteLength>t.maxLengthLength)throw new Gi(`Message length length too long - ${c.byteLength} > ${t.maxLengthLength}`);if(a>-1)break}if(t?.maxDataLength!=null&&a>t.maxDataLength)throw new $i(`Message length too long - ${a} > ${t.maxDataLength}`);let f=await e.read({...i,bytes:a});if(f==null)throw r.log.error("tried to read %d bytes but the stream closed",a),new De(`Unexpected EOF - tried to read ${a} bytes but the stream closed`);if(f.byteLength!==a)throw r.log.error("read %d/%d bytes before the stream closed",f.byteLength,a),new De(`Unexpected EOF - read ${f.byteLength}/${a} bytes before the stream closed`);return f},async write(i,a){await e.write(new rt(o(i.byteLength),i),a)},async writeV(i,a){let c=new rt(...i.flatMap(f=>[o(f.byteLength),f]));await e.write(c,a)},unwrap(){return e.unwrap()}}}function Zi(r,t){let e=I0(r,t),n={read:async(o,s)=>{let i=await e.read(s);return o.decode(i)},write:async(o,s,i)=>{await e.write(s.encode(o),i)},writeV:async(o,s,i)=>{await e.writeV(o.map(a=>s.encode(a)),i)},pb:o=>({read:async s=>n.read(o,s),write:async(s,i)=>n.write(s,o,i),writeV:async(s,i)=>n.writeV(s,o,i),unwrap:()=>n}),unwrap:()=>e.unwrap()};return n}var go=class extends ho{has(t){return this.find(t)!=null}find(t){return this.queue.find(e=>t.equals(e.options.peerId))}};function eu(r,t,e){let n,o,s=!1;function i(){let f={signal:o.signal},d;e?.timeout!=null&&(d=po([o.signal,AbortSignal.timeout(e.timeout)]),f.signal=d),s=!0,Promise.resolve().then(async()=>{await r(f)}).catch(()=>{}).finally(()=>{d!=null&&(d.aborted?d.clear():d.addEventListener("abort",()=>{d.clear()},{once:!0})),s=!1,!o.signal.aborted&&(n=setTimeout(i,t))})}let a=en(i,e?.debounce??100),c=!1;return{setInterval:f=>{t!==f&&(t=f,n!=null&&(clearTimeout(n),n=setTimeout(i,t)))},setTimeout:f=>{e??={},e.timeout=f},run:()=>{s||(clearTimeout(n),a())},start:()=>{c||(c=!0,o=new AbortController,o.signal,e?.runImmediately===!0?queueMicrotask(()=>{i()}):n=setTimeout(i,t))},stop:()=>{clearTimeout(n),o?.abort(),c=!1}}}var Yi=class extends Map{metric;constructor(t){super();let{name:e,metrics:n}=t;this.metric=n.registerMetric(e),this.updateComponentMetric()}set(t,e){return super.set(t,e),this.updateComponentMetric(),this}delete(t){let e=super.delete(t);return this.updateComponentMetric(),e}clear(){super.clear(),this.updateComponentMetric()}updateComponentMetric(){this.metric.update(this.size)}};function ru(r){let{name:t,metrics:e}=r,n;return e!=null?n=new Yi({name:t,metrics:e}):n=new Map,n}var nu="libp2p",ou="autonat",su="1.0.0";var H;(function(r){let t;(function(u){u.DIAL="DIAL",u.DIAL_RESPONSE="DIAL_RESPONSE"})(t=r.MessageType||(r.MessageType={}));let e;(function(u){u[u.DIAL=0]="DIAL",u[u.DIAL_RESPONSE=1]="DIAL_RESPONSE"})(e||(e={})),(function(u){u.codec=()=>rr(e)})(t=r.MessageType||(r.MessageType={}));let n;(function(u){u.OK="OK",u.E_DIAL_ERROR="E_DIAL_ERROR",u.E_DIAL_REFUSED="E_DIAL_REFUSED",u.E_BAD_REQUEST="E_BAD_REQUEST",u.E_INTERNAL_ERROR="E_INTERNAL_ERROR"})(n=r.ResponseStatus||(r.ResponseStatus={}));let o;(function(u){u[u.OK=0]="OK",u[u.E_DIAL_ERROR=100]="E_DIAL_ERROR",u[u.E_DIAL_REFUSED=101]="E_DIAL_REFUSED",u[u.E_BAD_REQUEST=200]="E_BAD_REQUEST",u[u.E_INTERNAL_ERROR=300]="E_INTERNAL_ERROR"})(o||(o={})),(function(u){u.codec=()=>rr(o)})(n=r.ResponseStatus||(r.ResponseStatus={}));let s;(function(u){let p;u.codec=()=>(p==null&&(p=$t((l,g,w={})=>{if(w.lengthDelimited!==!1&&g.fork(),l.id!=null&&(g.uint32(10),g.bytes(l.id)),l.addrs!=null&&l.addrs.length>0)for(let _ of l.addrs)g.uint32(18),g.bytes(_);w.lengthDelimited!==!1&&g.ldelim()},(l,g,w={})=>{let _={addrs:[]},A=g==null?l.len:l.pos+g;for(;l.pos<A;){let D=l.uint32();switch(D>>>3){case 1:{_.id=l.bytes();break}case 2:{if(w.limits?.addrs!=null&&_.addrs.length===w.limits.addrs)throw new jr('Decode error - repeated field "addrs" had too many elements');_.addrs.push(l.bytes());break}default:{l.skipType(D&7);break}}}return _},function*(l,g,w,_={}){let A={addrs:0},D=g==null?l.len:l.pos+g;for(;l.pos<D;){let L=l.uint32();switch(L>>>3){case 1:{yield{field:`${w}.id`,value:l.bytes()};break}case 2:{if(_.limits?.addrs!=null&&A.addrs===_.limits.addrs)throw new jr('Streaming decode error - repeated field "addrs" had too many elements');yield{field:`${w}.addrs[]`,index:A.addrs,value:l.bytes()},A.addrs++;break}default:{l.skipType(L&7);break}}}})),p);function b(l){return Ht(l,u.codec())}u.encode=b;function x(l,g){return Vt(l,u.codec(),g)}u.decode=x;function m(l,g){return jt(l,u.codec(),g)}u.stream=m})(s=r.PeerInfo||(r.PeerInfo={}));let i;(function(u){let p;u.codec=()=>(p==null&&(p=$t((l,g,w={})=>{w.lengthDelimited!==!1&&g.fork(),l.peer!=null&&(g.uint32(10),r.PeerInfo.codec().encode(l.peer,g)),w.lengthDelimited!==!1&&g.ldelim()},(l,g,w={})=>{let _={},A=g==null?l.len:l.pos+g;for(;l.pos<A;){let D=l.uint32();D>>>3===1?_.peer=r.PeerInfo.codec().decode(l,l.uint32(),{limits:w.limits?.peer}):l.skipType(D&7)}return _},function*(l,g,w,_={}){let A=g==null?l.len:l.pos+g;for(;l.pos<A;){let D=l.uint32();D>>>3===1?yield*r.PeerInfo.codec().stream(l,l.uint32(),`${w}.peer`,{limits:_.limits?.peer}):l.skipType(D&7)}})),p);function b(l){return Ht(l,u.codec())}u.encode=b;function x(l,g){return Vt(l,u.codec(),g)}u.decode=x;function m(l,g){return jt(l,u.codec(),g)}u.stream=m})(i=r.Dial||(r.Dial={}));let a;(function(u){let p;u.codec=()=>(p==null&&(p=$t((l,g,w={})=>{w.lengthDelimited!==!1&&g.fork(),l.status!=null&&(g.uint32(8),r.ResponseStatus.codec().encode(l.status,g)),l.statusText!=null&&(g.uint32(18),g.string(l.statusText)),l.addr!=null&&(g.uint32(26),g.bytes(l.addr)),w.lengthDelimited!==!1&&g.ldelim()},(l,g,w={})=>{let _={},A=g==null?l.len:l.pos+g;for(;l.pos<A;){let D=l.uint32();switch(D>>>3){case 1:{_.status=r.ResponseStatus.codec().decode(l);break}case 2:{_.statusText=l.string();break}case 3:{_.addr=l.bytes();break}default:{l.skipType(D&7);break}}}return _},function*(l,g,w,_={}){let A=g==null?l.len:l.pos+g;for(;l.pos<A;){let D=l.uint32();switch(D>>>3){case 1:{yield{field:`${w}.status`,value:r.ResponseStatus.codec().decode(l)};break}case 2:{yield{field:`${w}.statusText`,value:l.string()};break}case 3:{yield{field:`${w}.addr`,value:l.bytes()};break}default:{l.skipType(D&7);break}}}})),p);function b(l){return Ht(l,u.codec())}u.encode=b;function x(l,g){return Vt(l,u.codec(),g)}u.decode=x;function m(l,g){return jt(l,u.codec(),g)}u.stream=m})(a=r.DialResponse||(r.DialResponse={}));let c;r.codec=()=>(c==null&&(c=$t((u,p,b={})=>{b.lengthDelimited!==!1&&p.fork(),u.type!=null&&(p.uint32(8),r.MessageType.codec().encode(u.type,p)),u.dial!=null&&(p.uint32(18),r.Dial.codec().encode(u.dial,p)),u.dialResponse!=null&&(p.uint32(26),r.DialResponse.codec().encode(u.dialResponse,p)),b.lengthDelimited!==!1&&p.ldelim()},(u,p,b={})=>{let x={},m=p==null?u.len:u.pos+p;for(;u.pos<m;){let l=u.uint32();switch(l>>>3){case 1:{x.type=r.MessageType.codec().decode(u);break}case 2:{x.dial=r.Dial.codec().decode(u,u.uint32(),{limits:b.limits?.dial});break}case 3:{x.dialResponse=r.DialResponse.codec().decode(u,u.uint32(),{limits:b.limits?.dialResponse});break}default:{u.skipType(l&7);break}}}return x},function*(u,p,b,x={}){let m=p==null?u.len:u.pos+p;for(;u.pos<m;){let l=u.uint32();switch(l>>>3){case 1:{yield{field:`${b}.type`,value:r.MessageType.codec().decode(u)};break}case 2:{yield*r.Dial.codec().stream(u,u.uint32(),`${b}.dial`,{limits:x.limits?.dial});break}case 3:{yield*r.DialResponse.codec().stream(u,u.uint32(),`${b}.dialResponse`,{limits:x.limits?.dialResponse});break}default:{u.skipType(l&7);break}}}})),c);function f(u){return Ht(u,r.codec())}r.encode=f;function d(u,p){return Vt(u,r.codec(),p)}r.decode=d;function h(u,p){return jt(u,r.codec(),p)}r.stream=h})(H||(H={}));var O0=4,R0=8,bo=class{components;protocol;timeout;maxInboundStreams;maxOutboundStreams;maxMessageSize;started;log;topologyId;dialResults;findPeers;addressFilter;connectionThreshold;constructor(t,e){this.components=t,this.log=t.logger.forComponent("libp2p:auto-nat"),this.started=!1,this.protocol=`/${e.protocolPrefix??nu}/${ou}/${su}`,this.timeout=e.timeout??3e4,this.maxInboundStreams=e.maxInboundStreams??2,this.maxOutboundStreams=e.maxOutboundStreams??20,this.connectionThreshold=e.connectionThreshold??80,this.maxMessageSize=e.maxMessageSize??8192,this.dialResults=ru({name:"libp2p_autonat_dial_results",metrics:t.metrics}),this.findPeers=eu(this.findRandomPeers.bind(this),6e4),this.addressFilter=Ei(1024)}[Symbol.toStringTag]="@libp2p/autonat";[Ji]=["@libp2p/autonat"];get[ta](){return["@libp2p/identify"]}isStarted(){return this.started}async start(){this.started||(await this.components.registrar.handle(this.protocol,(t,e)=>{this.handleIncomingAutonatStream(t,e).catch(n=>{this.log.error("error handling incoming autonat stream - %e",n)})},{maxInboundStreams:this.maxInboundStreams,maxOutboundStreams:this.maxOutboundStreams}),this.topologyId=await this.components.registrar.register(this.protocol,{onConnect:(t,e)=>{this.verifyExternalAddresses(e).catch(n=>{this.log.error("could not verify addresses - %e",n)})}}),this.findPeers.start(),this.started=!0)}async stop(){await this.components.registrar.unhandle(this.protocol),this.topologyId!=null&&await this.components.registrar.unhandle(this.topologyId),this.dialResults.clear(),this.findPeers.stop(),this.started=!1}allAddressesAreVerified(){return this.components.addressManager.getAddressesWithMetadata().every(t=>t.expires>Date.now()?!0:t.verified)}async findRandomPeers(t){if(this.allAddressesAreVerified())return;let e=po([AbortSignal.timeout(1e4),t?.signal]);try{this.log("starting random walk to find peers to run AutoNAT");for await(let n of this.components.randomWalk.walk({signal:e})){if(!await this.components.connectionManager.isDialable(n.multiaddrs)){this.log.trace("random peer %p was not dialable %s",n.id,n.multiaddrs.map(o=>o.toString()).join(", "));continue}try{this.log.trace("dial random peer %p",n.id),await this.components.connectionManager.openConnection(n.multiaddrs,{signal:e})}catch{}if(this.allAddressesAreVerified()){this.log("stopping random walk, all addresses are verified");return}if(!this.hasConnectionCapacity()){this.log("stopping random walk, too close to max connections");return}}}catch{}}async handleIncomingAutonatStream(t,e){let n=AbortSignal.timeout(this.timeout);try{let o=Zi(t,{maxDataLength:this.maxMessageSize}).pb(H),s=await o.read({signal:n}),i=await this.handleAutonatMessage(s,e,{signal:n});await o.write(i,{signal:n}),await t.close({signal:n})}catch(o){this.log.error("error handling incoming autonat stream - %e",o),t.abort(o)}}async handleAutonatMessage(t,e,n){let o=this.components.addressManager.getAddresses().map(h=>Bt(h).host),s=t.dial;if(s==null)return this.log.error("dial was missing from message"),{type:H.MessageType.DIAL_RESPONSE,dialResponse:{status:H.ResponseStatus.E_BAD_REQUEST,statusText:"No Dial message found in message"}};let i,a=s.peer;if(a?.id==null)return this.log.error("peerId missing from message"),{type:H.MessageType.DIAL_RESPONSE,dialResponse:{status:H.ResponseStatus.E_BAD_REQUEST,statusText:"missing peer info"}};try{let h=le(a.id);i=$n(h)}catch(h){return this.log.error("invalid PeerId - %e",h),{type:H.MessageType.DIAL_RESPONSE,dialResponse:{status:H.ResponseStatus.E_BAD_REQUEST,statusText:"bad peer id"}}}if(this.log("incoming request from %p",i),!e.remotePeer.equals(i))return this.log("target peer %p did not equal sending peer %p",i,e.remotePeer),{type:H.MessageType.DIAL_RESPONSE,dialResponse:{status:H.ResponseStatus.E_BAD_REQUEST,statusText:"peer id mismatch"}};let c=a.addrs.map(h=>Jf(h)).filter(h=>{try{let u=Bt(h);return Oi(h)?!1:u.host!==Bt(e.remoteAddr).host?(this.log.trace("not dialing %a - target host did not match remote host %a",h,e.remoteAddr),!1):o.includes(u.host)?!1:this.components.transportManager.dialTransportForMultiaddr(h)==null?(this.log.trace("not dialing %a - transport unsupported",h),!1):!0}catch{return!1}}).map(h=>(h.getComponents().find(u=>u.code===421)?.value==null&&(h=h.encapsulate(`/p2p/${i.toString()}`)),h));if(c.length===0)return this.log("refused to dial all multiaddrs for %p from message",i),{type:H.MessageType.DIAL_RESPONSE,dialResponse:{status:H.ResponseStatus.E_DIAL_REFUSED,statusText:"no dialable addresses"}};this.log("dial multiaddrs %s for peer %p",c.map(h=>h.toString()).join(", "),i);let f="",d=c[0];for(let h of c){let u;d=h;try{if(u=await this.components.connectionManager.openConnection(h,n),!u.remoteAddr.equals(h))throw this.log.error("tried to dial %a but dialed %a",h,u.remoteAddr),new Error("Unexpected remote address");return this.log("successfully dialed %p via %a",i,h),{type:H.MessageType.DIAL_RESPONSE,dialResponse:{status:H.ResponseStatus.OK,addr:u.remoteAddr.decapsulateCode(421).bytes}}}catch(p){this.log.error("could not dial %p - %e",i,p),f=p.message}finally{u!=null&&await u.close()}}return{type:H.MessageType.DIAL_RESPONSE,dialResponse:{status:H.ResponseStatus.E_DIAL_ERROR,statusText:f,addr:d.bytes}}}getFirstUnverifiedMultiaddr(t,e){let n=this.components.addressManager.getAddressesWithMetadata().sort((o,s)=>o.type==="observed"&&s.type!=="observed"?1:s.type==="observed"&&o.type!=="observed"?-1:0).filter(o=>!(!(o.expires<Date.now())||Bt(o.multiaddr).type==="ip6"&&(!e||!Cf(o.multiaddr))||Oi(o.multiaddr)));for(let o of n){let s=o.multiaddr.toString(),i=this.dialResults.get(s);if(i!=null){if(i.networkSegments.includes(t)){this.log.trace("%a already has a network segment result from %s",i.multiaddr,t);continue}if(i.queue.size>10){this.log.trace("%a already has enough peers queued",i.multiaddr);continue}}if(i==null){let a=o.expires<Date.now();if(a&&this.addressFilter.remove?.(s),this.addressFilter.has(s))continue;this.addressFilter.add(s),this.log.trace("creating dial result %s %s",a?"to revalidate":"for",s),i={multiaddr:o.multiaddr,success:0,failure:0,networkSegments:[],verifyingPeers:bi(),queue:new go({concurrency:3,maxSize:50}),type:o.type,lastVerified:o.lastVerified},this.dialResults.set(s,i)}return i}}removeOutdatedMultiaddrResults(){let t=new Set(this.components.addressManager.getAddressesWithMetadata().filter(({expires:e})=>e<Date.now()).map(({multiaddr:e})=>e.toString()));for(let e of this.dialResults.keys())t.has(e)||(this.log.trace("remove results for %a",e),this.dialResults.delete(e))}async verifyExternalAddresses(t){if(!this.isStarted())return;this.removeOutdatedMultiaddrResults();let n=(await this.components.peerStore.get(t.remotePeer)).addresses.some(({multiaddr:i})=>Bt(i).type==="ip6"),o=this.getNetworkSegment(t.remoteAddr),s=this.getFirstUnverifiedMultiaddr(o,n);if(s==null){this.log.trace("no unverified public addresses found for peer %p to verify, not requesting verification",t.remotePeer);return}if(!this.hasConnectionCapacity()){s.lastVerified!=null?(this.log("automatically re-verifying %a because we are too close to the connection limit",s.multiaddr),this.confirmAddress(s)):this.log("skipping verifying %a because we are too close to the connection limit",s.multiaddr);return}s.queue.add(async i=>{await this.askPeerToVerify(t,o,i)},{peerId:t.remotePeer,multiaddr:s.multiaddr}).catch(i=>{s?.result==null&&this.log.error("error from %p verifying address %a - %e",t.remotePeer,s?.multiaddr,i)})}async askPeerToVerify(t,e,n){let o=this.dialResults.get(n.multiaddr.toString());if(o==null){this.log("%a was verified while %p was queued",n.multiaddr,t.remotePeer);return}let s=AbortSignal.timeout(this.timeout);this.log.trace("asking %a to verify multiaddr %s",t.remoteAddr,n.multiaddr);let i=await t.newStream(this.protocol,{signal:s});try{let a=Zi(i).pb(H),[,c]=await Promise.all([a.write({type:H.MessageType.DIAL,dial:{peer:{id:this.components.peerId.toMultihash().bytes,addrs:[n.multiaddr.bytes]}}},{signal:s}),a.read({signal:s})]);if(c.type!==H.MessageType.DIAL_RESPONSE||c.dialResponse==null){this.log("invalid autonat response from %p - %j",t.remotePeer,c);return}let f=c.dialResponse.status;if(this.log.trace("autonat response from %p for %a is %s",t.remotePeer,n.multiaddr,f),f!==H.ResponseStatus.OK&&f!==H.ResponseStatus.E_DIAL_ERROR)return;if(o=this.dialResults.get(n.multiaddr.toString()),o==null){this.log.trace("peer reported %a as %s but there is no result object",n.multiaddr,c.dialResponse.status);return}if(o.networkSegments.includes(e)){this.log.trace("%a results included network segment %s",n.multiaddr,e);return}if(o.result!=null){this.log.trace("already resolved result for %a, ignoring response from",n.multiaddr,t.remotePeer);return}if(o.verifyingPeers.has(t.remotePeer)){this.log.trace("peer %p has already verified %a, ignoring response",t.remotePeer,n.multiaddr);return}if(o.verifyingPeers.add(t.remotePeer),o.networkSegments.push(e),f===H.ResponseStatus.OK){if(o.success++,o.type!=="observed"){this.confirmAddress(o);return}}else f===H.ResponseStatus.E_DIAL_ERROR&&o.failure++;this.log("%a success %d failure %d",o.multiaddr,o.success,o.failure),o.success===O0&&this.confirmAddress(o),o.failure===R0&&this.unconfirmAddress(o)}finally{try{await i.close({signal:s})}catch(a){i.abort(a)}}}hasConnectionCapacity(){let e=this.components.connectionManager.getConnections().length,n=this.components.connectionManager.getMaxConnections();return e/n*100<this.connectionThreshold}confirmAddress(t){this.log("%s address %a is externally dialable",t.type,t.multiaddr),this.components.addressManager.confirmObservedAddr(t.multiaddr),this.dialResults.delete(t.multiaddr.toString()),t.result=!0,t.queue.abort()}unconfirmAddress(t){this.log("%s address %a is not externally dialable",t.type,t.multiaddr),this.components.addressManager.removeObservedAddr(t.multiaddr),this.dialResults.delete(t.multiaddr.toString()),t.result=!1,t.queue.abort()}getNetworkSegment(t){let e=Bt(t);switch(e.type){case"ip4":return e.host.split(".")[0].padStart(3,"0");case"ip6":return e.host.split(":")[0].padStart(4,"0");default:throw new dt(`Remote address ${t} was not an IPv4 or Ipv6 address`)}}};function P0(r={}){return t=>new bo(t,r)}return du(k0);})();
2
+ "use strict";var Libp2PAutonat=(()=>{var pu=Object.create;var cn=Object.defineProperty;var mu=Object.getOwnPropertyDescriptor;var gu=Object.getOwnPropertyNames;var bu=Object.getPrototypeOf,yu=Object.prototype.hasOwnProperty;var xo=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports),V=(r,t)=>{for(var e in t)cn(r,e,{get:t[e],enumerable:!0})},oa=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of gu(t))!yu.call(r,o)&&o!==e&&cn(r,o,{get:()=>t[o],enumerable:!(n=mu(t,o))||n.enumerable});return r};var xu=(r,t,e)=>(e=r!=null?pu(bu(r)):{},oa(t||!r||!r.__esModule?cn(e,"default",{value:r,enumerable:!0}):e,r)),wu=r=>oa(cn({},"__esModule",{value:!0}),r);var vi=xo(ur=>{"use strict";Object.defineProperty(ur,"__esModule",{value:!0});ur.Netmask4Impl=void 0;ur.ip2long=fr;ur.long2ip=Pt;function Pt(r){let t=(r&-16777216)>>>24,e=(r&255<<16)>>>16,n=(r&65280)>>>8,o=r&255;return[t,e,n,o].join(".")}var pp=48,mp=97,gp=65;function bp(r){let t=0,e=10,n="9",o=0;r.length>1&&r[o]==="0"&&(r[o+1]==="x"||r[o+1]==="X"?(o+=2,e=16):"0"<=r[o+1]&&r[o+1]<="9"&&(o++,e=8,n="7"));let s=o;for(;o<r.length;){if("0"<=r[o]&&r[o]<=n)t=t*e+(r.charCodeAt(o)-pp)>>>0;else if(e===16)if("a"<=r[o]&&r[o]<="f")t=t*e+(10+r.charCodeAt(o)-mp)>>>0;else if("A"<=r[o]&&r[o]<="F")t=t*e+(10+r.charCodeAt(o)-gp)>>>0;else break;else break;if(t>4294967295)throw new Error("too large");o++}if(o===s)throw new Error("empty octet");return[t,o]}function fr(r){let t=[];for(let e=0;e<=3&&r.length!==0;e++){if(e>0){if(r[0]!==".")throw new Error("Invalid IP");r=r.substring(1)}let[n,o]=bp(r);r=r.substring(o),t.push(n)}if(r.length!==0)throw new Error("Invalid IP");switch(t.length){case 1:if(t[0]>4294967295)throw new Error("Invalid IP");return t[0]>>>0;case 2:if(t[0]>255||t[1]>16777215)throw new Error("Invalid IP");return(t[0]<<24|t[1])>>>0;case 3:if(t[0]>255||t[1]>255||t[2]>65535)throw new Error("Invalid IP");return(t[0]<<24|t[1]<<16|t[2])>>>0;case 4:if(t[0]>255||t[1]>255||t[2]>255||t[3]>255)throw new Error("Invalid IP");return(t[0]<<24|t[1]<<16|t[2]<<8|t[3])>>>0;default:throw new Error("Invalid IP")}}var Si=class r{constructor(t,e){if(typeof t!="string")throw new Error("Missing `net' parameter");let n=e;if(!n){let o=t.split("/",2);t=o[0],n=o[1]}if(n||(n=32),typeof n=="string"&&n.indexOf(".")>-1){try{this.maskLong=fr(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=(fr(t)&this.maskLong)>>>0}catch{throw new Error("Invalid net address: "+t)}if(!(this.bitmask<=32))throw new Error("Invalid mask for ip4: "+n);this.size=Math.pow(2,32-this.bitmask),this.base=Pt(this.netLong),this.mask=Pt(this.maskLong),this.hostmask=Pt(~this.maskLong),this.first=this.bitmask<=30?Pt(this.netLong+1):this.base,this.last=this.bitmask<=30?Pt(this.netLong+this.size-2):Pt(this.netLong+this.size-1),this.broadcast=this.bitmask<=30?Pt(this.netLong+this.size-1):void 0}contains(t){return typeof t=="string"&&(t.indexOf("/")>0||t.split(".").length!==4)&&(t=new r(t)),t instanceof r?this.contains(t.base)&&this.contains(t.broadcast||t.last):(fr(t)&this.maskLong)>>>0===(this.netLong&this.maskLong)>>>0}next(t=1){return new r(Pt(this.netLong+this.size*t),this.mask)}forEach(t){let e=fr(this.first),n=fr(this.last),o=0;for(;e<=n;)t(Pt(e),e,o),o++,e++}toString(){return this.base+"/"+this.bitmask}};ur.Netmask4Impl=Si});var Kf=xo(lr=>{"use strict";Object.defineProperty(lr,"__esModule",{value:!0});lr.Netmask6Impl=void 0;lr.ip6bigint=Ai;lr.bigint2ip6=Re;var yp=vi(),_i=(1n<<128n)-1n;function Ai(r){let t=r.indexOf("%");t!==-1&&(r=r.substring(0,t));let e=r.lastIndexOf(":");if(e!==-1&&r.indexOf(".",e)!==-1){let n=r.substring(e+1),o=(0,yp.ip2long)(n),s=r.substring(0,e+1)+"0:0";return zf(s)&~0xffffffffn|BigInt(o)}return zf(r)}function zf(r){let t=r.indexOf("::"),e;if(t!==-1){let o=r.substring(0,t),s=r.substring(t+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");e=[...i,...Array(c).fill("0"),...a]}else e=r.split(":");if(e.length!==8)throw new Error("Invalid IPv6: expected 8 groups, got "+e.length);let n=0n;for(let o=0;o<8;o++){let s=e[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 Re(r){if(r<0n||r>_i)throw new Error("Invalid IPv6 address value");let t=[];for(let i=0;i<8;i++)t.unshift(Number(r&0xffffn)),r>>=16n;let e=-1,n=0,o=-1,s=0;for(let i=0;i<8;i++)t[i]===0?o===-1?(o=i,s=1):s++:(s>n&&s>=2&&(e=o,n=s),o=-1,s=0);if(s>n&&s>=2&&(e=o,n=s),e!==-1&&e+n===8&&e>0)return t.slice(0,e).map(a=>a.toString(16)).join(":")+"::";if(e===0)return"::"+t.slice(n).map(a=>a.toString(16)).join(":");if(e>0){let i=t.slice(0,e).map(c=>c.toString(16)),a=t.slice(e+n).map(c=>c.toString(16));return i.join(":")+"::"+a.join(":")}else return t.map(i=>i.toString(16)).join(":")}var Ii=class r{constructor(t,e){if(typeof t!="string")throw new Error("Missing `net' parameter");let n=e;if(n==null){let o=t.indexOf("/");o!==-1?(n=parseInt(t.substring(o+1),10),t=t.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=_i>>BigInt(128-this.bitmask)<<BigInt(128-this.bitmask);try{this.netBigint=Ai(t)&this.maskBigint}catch{throw new Error("Invalid IPv6 net address: "+t)}this.size=Number(1n<<BigInt(128-this.bitmask)),this.base=Re(this.netBigint),this.mask=Re(this.maskBigint),this.hostmask=Re(~this.maskBigint&_i),this.first=this.base,this.last=Re(this.netBigint+(1n<<BigInt(128-this.bitmask))-1n),this.broadcast=void 0}contains(t){return typeof t=="string"&&t.indexOf("/")>0&&(t=new r(t)),t instanceof r?this.contains(t.base)&&this.contains(t.last):(Ai(t)&this.maskBigint)===this.netBigint}next(t=1){let e=1n<<BigInt(128-this.bitmask);return new r(Re(this.netBigint+e*BigInt(t)),this.bitmask)}forEach(t){let e=this.netBigint,n=1n<<BigInt(128-this.bitmask),o=this.netBigint+n-1n,s=0;for(;e<=o;)t(Re(e),Number(e),s),s++,e++}toString(){return this.base+"/"+this.bitmask}};lr.Netmask6Impl=Ii});var qf=xo(pe=>{"use strict";Object.defineProperty(pe,"__esModule",{value:!0});pe.long2ip=pe.ip2long=pe.Netmask=void 0;var no=vi();Object.defineProperty(pe,"ip2long",{enumerable:!0,get:function(){return no.ip2long}});Object.defineProperty(pe,"long2ip",{enumerable:!0,get:function(){return no.long2ip}});var xp=Kf(),Ti=class r{constructor(t,e){if(typeof t!="string")throw new Error("Missing `net' parameter");(t.indexOf("/")!==-1?t.substring(0,t.indexOf("/")):t).indexOf(":")!==-1?this._impl=new xp.Netmask6Impl(t,e):this._impl=new no.Netmask4Impl(t,e),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 no.Netmask4Impl?(this.maskLong=this._impl.maskLong,this.netLong=this._impl.netLong):(this.maskLong=0,this.netLong=0)}contains(t){return typeof t=="string"&&(t.indexOf("/")>0?t=new r(t):t.indexOf(":")===-1&&t.split(".").length!==4&&(t=new r(t))),t instanceof r?this.contains(t.base)&&this.contains(t.broadcast||t.last):this._impl.contains(t)}next(t=1){let e=this._impl.next(t);return new r(e.base,e.bitmask)}forEach(t){this._impl.forEach(t)}toString(){return this._impl.toString()}};pe.Netmask=Ti});var em={};V(em,{autoNAT:()=>tm});var kt=class extends Error{static name="AbortError";constructor(t="The operation was aborted"){super(t),this.name="AbortError"}};var mt=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},fn=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var un=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}};var yr=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var wo=Symbol.for("@libp2p/peer-id");function Eu(r){return typeof r?.handleEvent=="function"}function Su(r){return(r!==!0&&r!==!1&&r?.once)??!1}var ln=class extends EventTarget{#t=new Map;constructor(){super()}listenerCount(t){let e=this.#t.get(t);return e==null?0:e.length}addEventListener(t,e,n){let o=Su(n);super.addEventListener(t,i=>{if(o){let a=this.#t.get(i.type);a!=null&&(a=a.filter(({callback:c})=>c!==e),this.#t.set(i.type,a))}Eu(e)?e.handleEvent(i):e(i)},n);let s=this.#t.get(t);s==null&&(s=[],this.#t.set(t,s)),s.push({callback:e,once:o})}removeEventListener(t,e,n){super.removeEventListener(t.toString(),e??null,n);let o=this.#t.get(t);o!=null&&(o=o.filter(({callback:s})=>s!==e),this.#t.set(t,o))}safeDispatchEvent(t,e={}){return this.dispatchEvent(new CustomEvent(t,e))}};var sa=Symbol.for("@libp2p/service-capabilities"),ia=Symbol.for("@libp2p/service-dependencies");var Ao={};V(Ao,{base58btc:()=>Q,base58flickr:()=>Cu});var Dm=new Uint8Array(0);function aa(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}function Nt(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return me(r);if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return me(new Uint8Array(r.buffer,r.byteOffset,r.byteLength));throw new Error("Unknown type, must be binary type")}function ca(r){return new TextEncoder().encode(r)}function fa(r){return new TextDecoder().decode(r)}function vu(r){return r?.buffer instanceof ArrayBuffer}function me(r){return vu(r)?r:r.slice()}function _u(r,t){if(r.length>=255)throw new TypeError("Alphabet too long");for(var e=new Uint8Array(256),n=0;n<e.length;n++)e[n]=255;for(var o=0;o<r.length;o++){var s=r.charAt(o),i=s.charCodeAt(0);if(e[i]!==255)throw new TypeError(s+" is ambiguous");e[i]=o}var a=r.length,c=r.charAt(0),f=Math.log(a)/Math.log(256),d=Math.log(256)/Math.log(a);function h(b){if(b instanceof Uint8Array||(ArrayBuffer.isView(b)?b=new Uint8Array(b.buffer,b.byteOffset,b.byteLength):Array.isArray(b)&&(b=Uint8Array.from(b))),!(b instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(b.length===0)return"";for(var x=0,m=0,l=0,g=b.length;l!==g&&b[l]===0;)l++,x++;for(var w=(g-l)*d+1>>>0,_=new Uint8Array(w);l!==g;){for(var A=b[l],C=0,L=w-1;(A!==0||C<m)&&L!==-1;L--,C++)A+=256*_[L]>>>0,_[L]=A%a>>>0,A=A/a>>>0;if(A!==0)throw new Error("Non-zero carry");m=C,l++}for(var B=w-m;B!==w&&_[B]===0;)B++;for(var P=c.repeat(x);B<w;++B)P+=r.charAt(_[B]);return P}function u(b){if(typeof b!="string")throw new TypeError("Expected String");if(b.length===0)return new Uint8Array;var x=0;if(b[x]!==" "){for(var m=0,l=0;b[x]===c;)m++,x++;for(var g=(b.length-x)*f+1>>>0,w=new Uint8Array(g);b[x];){var _=e[b.charCodeAt(x)];if(_===255)return;for(var A=0,C=g-1;(_!==0||A<l)&&C!==-1;C--,A++)_+=a*w[C]>>>0,w[C]=_%256>>>0,_=_/256>>>0;if(_!==0)throw new Error("Non-zero carry");l=A,x++}if(b[x]!==" "){for(var L=g-l;L!==g&&w[L]===0;)L++;for(var B=new Uint8Array(m+(g-L)),P=m;L!==g;)B[P++]=w[L++];return B}}}function p(b){var x=u(b);if(x)return x;throw new Error(`Non-${t} character`)}return{encode:h,decodeUnsafe:u,decode:p}}var Au=_u,Iu=Au,la=Iu;var Eo=class{name;prefix;baseEncode;constructor(t,e,n){this.name=t,this.prefix=e,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},So=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,e,n){this.name=t,this.prefix=e;let o=e.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return da(this,t)}},vo=class{decoders;constructor(t){this.decoders=t}or(t){return da(this,t)}decode(t){let e=t[0],n=this.decoders[e];if(n!=null)return n.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function da(r,t){return new vo({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var _o=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,e,n,o){this.name=t,this.prefix=e,this.baseEncode=n,this.baseDecode=o,this.encoder=new Eo(t,e,n),this.decoder=new So(t,e,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function ke({name:r,prefix:t,encode:e,decode:n}){return new _o(r,t,e,n)}function Qt({name:r,prefix:t,alphabet:e}){let{encode:n,decode:o}=la(e,r);return ke({prefix:t,name:r,encode:n,decode:s=>Nt(o(s))})}function Tu(r,t,e,n){let o=r.length;for(;r[o-1]==="=";)--o;let s=new Uint8Array(o*e/8|0),i=0,a=0,c=0;for(let f=0;f<o;++f){let d=t[r[f]];if(d===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<e|d,i+=e,i>=8&&(i-=8,s[c++]=255&a>>i)}if(i>=e||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function Bu(r,t,e){let n=t[t.length-1]==="=",o=(1<<e)-1,s="",i=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],i+=8;i>e;)i-=e,s+=t[o&a>>i];if(i!==0&&(s+=t[o&a<<e-i]),n)for(;(s.length*e&7)!==0;)s+="=";return s}function Lu(r){let t={};for(let e=0;e<r.length;++e)t[r[e]]=e;return t}function G({name:r,prefix:t,bitsPerChar:e,alphabet:n}){let o=Lu(n);return ke({prefix:t,name:r,encode(s){return Bu(s,n,e)},decode(s){return Tu(s,o,e,r)}})}var Q=Qt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Cu=Qt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Io={};V(Io,{base32:()=>Jt,base32hex:()=>Fu,base32hexpad:()=>ku,base32hexpadupper:()=>Nu,base32hexupper:()=>Pu,base32pad:()=>Ru,base32padupper:()=>Ou,base32upper:()=>Du,base32z:()=>Uu});var Jt=G({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Du=G({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Ru=G({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Ou=G({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Fu=G({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Pu=G({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),ku=G({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Nu=G({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Uu=G({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var To={};V(To,{base36:()=>xr,base36upper:()=>Mu});var xr=Qt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Mu=Qt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var zu=ma,ha=128,Ku=127,qu=~Ku,Vu=Math.pow(2,31);function ma(r,t,e){t=t||[],e=e||0;for(var n=e;r>=Vu;)t[e++]=r&255|ha,r/=128;for(;r&qu;)t[e++]=r&255|ha,r>>>=7;return t[e]=r|0,ma.bytes=e-n+1,t}var Hu=Bo,ju=128,pa=127;function Bo(r,n){var e=0,n=n||0,o=0,s=n,i,a=r.length;do{if(s>=a)throw Bo.bytes=0,new RangeError("Could not decode varint");i=r[s++],e+=o<28?(i&pa)<<o:(i&pa)*Math.pow(2,o),o+=7}while(i>=ju);return Bo.bytes=s-n,e}var $u=Math.pow(2,7),Gu=Math.pow(2,14),Zu=Math.pow(2,21),Yu=Math.pow(2,28),Xu=Math.pow(2,35),Wu=Math.pow(2,42),Qu=Math.pow(2,49),Ju=Math.pow(2,56),tl=Math.pow(2,63),el=function(r){return r<$u?1:r<Gu?2:r<Zu?3:r<Yu?4:r<Xu?5:r<Wu?6:r<Qu?7:r<Ju?8:r<tl?9:10},rl={encode:zu,decode:Hu,encodingLength:el},nl=rl,wr=nl;function Er(r,t=0){return[wr.decode(r,t),wr.decode.bytes]}function Ne(r,t,e=0){return wr.encode(r,t,e),t}function Ue(r){return wr.encodingLength(r)}function ze(r,t){let e=t.byteLength,n=Ue(r),o=n+Ue(e),s=new Uint8Array(o+e);return Ne(r,s,0),Ne(e,s,n),s.set(t,o),new Me(r,e,t,s)}function ge(r){let t=Nt(r),[e,n]=Er(t),[o,s]=Er(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new Me(e,o,i,t)}function ga(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&aa(r.bytes,e.bytes)}}var Me=class{code;size;digest;bytes;constructor(t,e,n,o){this.code=t,this.size=e,this.digest=me(n),this.bytes=me(o)}};function ba(r,t){let{bytes:e,version:n}=r;return n===0?sl(e,Lo(r),t??Q.encoder):il(e,Lo(r),t??Jt.encoder)}var ya=new WeakMap;function Lo(r){let t=ya.get(r);if(t==null){let e=new Map;return ya.set(r,e),e}return t}var lt=class r{code;version;multihash;bytes;"/";constructor(t,e,n,o){this.code=e,this.version=t,this.multihash=n,this.bytes=me(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:t,multihash:e}=this;if(t!==Sr)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==al)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(e)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:t,digest:e}=this.multihash,n=ze(t,e);return r.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(t){return r.equals(this,t)}static equals(t,e){let n=e;return n!=null&&t.code===n.code&&t.version===n.version&&ga(t.multihash,n.multihash)}toString(t){return ba(this,t)}toJSON(){return{"/":ba(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(t){if(t==null)return null;let e=t;if(e instanceof r)return e;if(e["/"]!=null&&e["/"]===e.bytes||e.asCID===e){let{version:n,code:o,multihash:s,bytes:i}=e;return new r(n,o,s,i??xa(n,o,s.bytes))}else if(e[cl]===!0){let{version:n,multihash:o,code:s}=e,i=ge(o);return r.create(n,s,i)}else return null}static create(t,e,n){if(typeof e!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(t){case 0:{if(e!==Sr)throw new Error(`Version 0 CID must use dag-pb (code: ${Sr}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let o=xa(t,e,n.bytes);return new r(t,e,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,Sr,t)}static createV1(t,e){return r.create(1,t,e)}static decode(t){let[e,n]=r.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return e}static decodeFirst(t){let e=r.inspectBytes(t),n=e.size-e.multihashSize,o=Nt(t.subarray(n,n+e.multihashSize));if(o.byteLength!==e.multihashSize)throw new Error("Incorrect length");let s=o.subarray(e.multihashSize-e.digestSize),i=new Me(e.multihashCode,e.digestSize,s,o);return[e.version===0?r.createV0(i):r.createV1(e.codec,i),t.subarray(e.size)]}static inspectBytes(t){let e=0,n=()=>{let[h,u]=Er(t.subarray(e));return e+=u,h},o=n(),s=Sr;if(o===18?(o=0,e=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=e,a=n(),c=n(),f=e+c,d=f-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:d,size:f}}static parse(t,e){let[n,o]=ol(t,e),s=r.decode(o);if(s.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Lo(s).set(n,t),s}};function ol(r,t){switch(r[0]){case"Q":{let e=t??Q;return[Q.prefix,e.decode(`${Q.prefix}${r}`)]}case Q.prefix:{let e=t??Q;return[Q.prefix,e.decode(r)]}case Jt.prefix:{let e=t??Jt;return[Jt.prefix,e.decode(r)]}case xr.prefix:{let e=t??xr;return[xr.prefix,e.decode(r)]}default:{if(t==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[r[0],t.decode(r)]}}}function sl(r,t,e){let{prefix:n}=e;if(n!==Q.prefix)throw Error(`Cannot string encode V0 in ${e.name} encoding`);let o=t.get(n);if(o==null){let s=e.encode(r).slice(1);return t.set(n,s),s}else return o}function il(r,t,e){let{prefix:n}=e,o=t.get(n);if(o==null){let s=e.encode(r);return t.set(n,s),s}else return o}var Sr=112,al=18;function xa(r,t,e){let n=Ue(r),o=n+Ue(t),s=new Uint8Array(o+e.byteLength);return Ne(r,s,0),Ne(t,s,n),s.set(e,o),s}var cl=Symbol.for("@ipld/js-cid/CID");var Co={};V(Co,{identity:()=>St});var wa=0,fl="identity",Ea=Nt;function ul(r,t){if(t?.truncate!=null&&t.truncate!==r.byteLength){if(t.truncate<0||t.truncate>r.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${r.byteLength}`);r=r.subarray(0,t.truncate)}return ze(wa,Ea(r))}var St={code:wa,name:fl,encode:Ea,digest:ul};function xt(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}function ll(r){return r.buffer instanceof ArrayBuffer}function Ut(r){return ll(r)?r:r.slice()}async function Sa(r,t,e,n){let o=await crypto.subtle.importKey("jwk",r,{name:"ECDSA",namedCurve:r.crv??"P-256"},!1,["verify"]);n?.signal?.throwIfAborted();let s=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},o,Ut(t),Ut(e.subarray()));return n?.signal?.throwIfAborted(),s}function Mt(r=0){return new Uint8Array(r)}function vr(r=0){return new Uint8Array(r)}function Do(r,t){t==null&&(t=r.reduce((o,s)=>o+s.length,0));let e=vr(t),n=0;for(let o of r)e.set(o,n),n+=o.length;return e}function va(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}var Aa=Symbol.for("@achingbrain/uint8arraylist");function _a(r,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let e=0;for(let n of r){let o=e+n.byteLength;if(t<o)return{buf:n,index:t-e};e=o}throw new RangeError("index is out of bounds")}function hn(r){return!!r?.[Aa]}var st=class r{bufs;length;[Aa]=!0;constructor(...t){this.bufs=[],this.length=0,t.length>0&&this.appendAll(t)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...t){this.appendAll(t)}appendAll(t){let e=0;for(let n of t)if(n instanceof Uint8Array)e+=n.byteLength,this.bufs.push(n);else if(hn(n)){e+=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+=e}prepend(...t){this.prependAll(t)}prependAll(t){let e=0;for(let n of t.reverse())if(n instanceof Uint8Array)e+=n.byteLength,this.bufs.unshift(n);else if(hn(n))e+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}get(t){let e=_a(this.bufs,t);return e.buf[e.index]}set(t,e){let n=_a(this.bufs,t);n.buf[n.index]=e}write(t,e=0){if(t instanceof Uint8Array)for(let n=0;n<t.length;n++)this.set(e+n,t[n]);else if(hn(t))for(let n=0;n<t.length;n++)this.set(e+n,t.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(t){if(t=Math.trunc(t),!(Number.isNaN(t)||t<=0)){if(t===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(t>=this.bufs[0].byteLength)t-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(t),this.length-=t;break}}}slice(t,e){let{bufs:n,length:o}=this._subList(t,e);return Do(n,o)}subarray(t,e){let{bufs:n,length:o}=this._subList(t,e);return n.length===1?n[0]:Do(n,o)}sublist(t,e){let{bufs:n,length:o}=this._subList(t,e),s=new r;return s.length=o,s.bufs=n,s}_subList(t,e){if(t=t??0,e=e??this.length,t<0&&(t=this.length+t),e<0&&(e=this.length+e),t<0||e>this.length)throw new RangeError("index is out of bounds");if(t===e)return{bufs:[],length:0};if(t===0&&e===this.length)return{bufs:[...this.bufs],length:this.length};let n=[],o=0;for(let s=0;s<this.bufs.length;s++){let i=this.bufs[s],a=o,c=a+i.byteLength;if(o=c,t>=c)continue;let f=t>=a&&t<c,d=e>a&&e<=c;if(f&&d){if(t===a&&e===c){n.push(i);break}let h=t-a;n.push(i.subarray(h,h+(e-t)));break}if(f){if(t===0){n.push(i);continue}n.push(i.subarray(t-a));continue}if(d){if(e===c){n.push(i);break}n.push(i.subarray(0,e-a));break}n.push(i)}return{bufs:n,length:e-t}}indexOf(t,e=0){if(!hn(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(e=Number(e??0),isNaN(e)&&(e=0),e<0&&(e=this.length+e),e<0&&(e=0),t.length===0)return e>this.length?this.length:e;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let s=256,i=new Int32Array(s);for(let h=0;h<s;h++)i[h]=-1;for(let h=0;h<o;h++)i[n[h]]=h;let a=i,c=this.byteLength-n.byteLength,f=n.byteLength-1,d;for(let h=e;h<=c;h+=d){d=0;for(let u=f;u>=0;u--){let p=this.get(h+u);if(n[u]!==p){d=Math.max(1,u-a[p]);break}}if(d===0)return h}return-1}getInt8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getInt8(0)}setInt8(t,e){let n=vr(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,e),this.write(n,t)}getInt16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,e)}setInt16(t,e,n){let o=Mt(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,e,n),this.write(o,t)}getInt32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,e)}setInt32(t,e,n){let o=Mt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,e,n),this.write(o,t)}getBigInt64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,e)}setBigInt64(t,e,n){let o=Mt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,e,n),this.write(o,t)}getUint8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getUint8(0)}setUint8(t,e){let n=vr(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,e),this.write(n,t)}getUint16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,e)}setUint16(t,e,n){let o=Mt(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,e,n),this.write(o,t)}getUint32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,e)}setUint32(t,e,n){let o=Mt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,e,n),this.write(o,t)}getBigUint64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,e)}setBigUint64(t,e,n){let o=Mt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,e,n),this.write(o,t)}getFloat32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,e)}setFloat32(t,e,n){let o=Mt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,e,n),this.write(o,t)}getFloat64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,e)}setFloat64(t,e,n){let o=Mt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,e,n),this.write(o,t)}equals(t){if(t==null||!(t instanceof r)||t.bufs.length!==this.bufs.length)return!1;for(let e=0;e<this.bufs.length;e++)if(!va(this.bufs[e],t.bufs[e]))return!1;return!0}static fromUint8Arrays(t,e){let n=new r;return n.bufs=t,e==null&&(e=t.reduce((o,s)=>o+s.byteLength,0)),n.length=e,n}};var Ro={};V(Ro,{base10:()=>dl});var dl=Qt({prefix:"9",name:"base10",alphabet:"0123456789"});var Oo={};V(Oo,{base16:()=>hl,base16upper:()=>pl});var hl=G({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),pl=G({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Fo={};V(Fo,{base2:()=>ml});var ml=G({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Po={};V(Po,{base256emoji:()=>wl});var Ia=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}"),gl=Ia.reduce((r,t,e)=>(r[e]=t,r),[]),bl=Ia.reduce((r,t,e)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return r[n]=e,r},[]);function yl(r){return r.reduce((t,e)=>(t+=gl[e],t),"")}function xl(r){let t=[];for(let e of r){let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);let o=bl[n];if(o==null)throw new Error(`Non-base256emoji character: ${e}`);t.push(o)}return new Uint8Array(t)}var wl=ke({prefix:"\u{1F680}",name:"base256emoji",encode:yl,decode:xl});var No={};V(No,{base64:()=>El,base64pad:()=>Sl,base64url:()=>ko,base64urlpad:()=>vl});var El=G({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Sl=G({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),ko=G({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),vl=G({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Uo={};V(Uo,{base8:()=>_l});var _l=G({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Mo={};V(Mo,{identity:()=>Al});var Al=ke({prefix:"\0",name:"identity",encode:r=>fa(r),decode:r=>ca(r)});var yg=new TextEncoder,xg=new TextDecoder;var qo={};V(qo,{sha256:()=>_r,sha512:()=>Ll});var Bl=20;function Ko({name:r,code:t,encode:e,minDigestLength:n,maxDigestLength:o}){return new zo(r,t,e,n,o)}var zo=class{name;code;encode;minDigestLength;maxDigestLength;constructor(t,e,n,o,s){this.name=t,this.code=e,this.encode=n,this.minDigestLength=o??Bl,this.maxDigestLength=s}digest(t,e){if(e?.truncate!=null){if(e.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&e.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(t instanceof Uint8Array){let n=this.encode(t);return n instanceof Uint8Array?Ta(n,this.code,e?.truncate):n.then(o=>Ta(o,this.code,e?.truncate))}else throw Error("Unknown type, must be binary type")}};function Ta(r,t,e){if(e!=null&&e!==r.byteLength){if(e>r.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${r.byteLength}`);r=r.subarray(0,e)}return ze(t,r)}function La(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var _r=Ko({name:"sha2-256",code:18,encode:La("SHA-256")}),Ll=Ko({name:"sha2-512",code:19,encode:La("SHA-512")});var Ar={...Mo,...Fo,...Uo,...Ro,...Oo,...Io,...To,...Ao,...No,...Po},Dg={...qo,...Co};function Vo(r=0){return new Uint8Array(r)}function be(r=0){return new Uint8Array(r)}function Da(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var Ca=Da("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Ho=Da("ascii","a",r=>{let t="a";for(let e=0;e<r.length;e++)t+=String.fromCharCode(r[e]);return t},r=>{r=r.substring(1);let t=be(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),Cl={utf8:Ca,"utf-8":Ca,hex:Ar.base16,latin1:Ho,ascii:Ho,binary:Ho,...Ar},pn=Cl;function Z(r,t="utf8"){let e=pn[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.decoder.decode(`${e.prefix}${r}`)}function tt(r,t="utf8"){let e=pn[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.encoder.encode(r).substring(1)}var Dl=parseInt("11111",2),jo=parseInt("10000000",2),Rl=parseInt("01111111",2),Ra={0:Ir,1:Ir,2:Ol,3:kl,4:Nl,5:Pl,6:Fl,16:Ir,22:Ir,48:Ir};function $o(r,t={offset:0}){let e=r[t.offset]&Dl;if(t.offset++,Ra[e]!=null)return Ra[e](r,t);throw new Error("No decoder for tag "+e)}function Tr(r,t){let e=0;if((r[t.offset]&jo)===jo){let n=r[t.offset]&Rl,o="0x";t.offset++;for(let s=0;s<n;s++,t.offset++)o+=r[t.offset].toString(16).padStart(2,"0");e=parseInt(o,16)}else e=r[t.offset],t.offset++;return e}function Ir(r,t){Tr(r,t);let e=[];for(;!(t.offset>=r.byteLength);){let n=$o(r,t);if(n===null)break;e.push(n)}return e}function Ol(r,t){let e=Tr(r,t),n=t.offset,o=t.offset+e,s=[];for(let i=n;i<o;i++)i===n&&r[i]===0||s.push(r[i]);return t.offset+=e,Uint8Array.from(s)}function Fl(r,t){let e=Tr(r,t),n=t.offset+e,o=r[t.offset];t.offset++;let s=0,i=0;o<40?(s=0,i=o):o<80?(s=1,i=o-40):(s=2,i=o-80);let a=`${s}.${i}`,c=[];for(;t.offset<n;){let f=r[t.offset];if(t.offset++,c.push(f&127),f<128){c.reverse();let d=0;for(let h=0;h<c.length;h++)d+=c[h]<<h*7;a+=`.${d}`,c=[]}}return a}function Pl(r,t){return t.offset++,null}function kl(r,t){let e=Tr(r,t),n=r[t.offset];t.offset++;let o=r.subarray(t.offset,t.offset+e-1);if(t.offset+=e,n!==0)throw new Error("Unused bits in bit string is unimplemented");return o}function Nl(r,t){let e=Tr(r,t),n=r.subarray(t.offset,t.offset+e);return t.offset+=e,n}function Ul(r){let t=r.toString(16);t.length%2===1&&(t="0"+t);let e=new st;for(let n=0;n<t.length;n+=2)e.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return e}function Go(r){if(r.byteLength<128)return Uint8Array.from([r.byteLength]);let t=Ul(r.byteLength);return new st(Uint8Array.from([t.byteLength|jo]),t)}function Oa(r){let t=new st,e=128;return(r.subarray()[0]&e)===e&&t.append(Uint8Array.from([0])),t.append(r),new st(Uint8Array.from([2]),Go(t),t)}function Fa(r){let t=Uint8Array.from([0]),e=new st(t,r);return new st(Uint8Array.from([3]),Go(e),e)}function mn(r,t=48){let e=new st;for(let n of r)e.append(n);return new st(Uint8Array.from([t]),Go(e),e)}var Ml=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),zl=Uint8Array.from([6,5,43,129,4,0,34]),Kl=Uint8Array.from([6,5,43,129,4,0,35]),ql={ext:!0,kty:"EC",crv:"P-256"},Vl={ext:!0,kty:"EC",crv:"P-384"},Hl={ext:!0,kty:"EC",crv:"P-521"},Zo=32,Yo=48,Xo=66;function Pa(r){let t=$o(r);return ka(t)}function ka(r){let t=r[1][1][0],e=1,n,o;if(t.byteLength===Zo*2+1)return n=tt(t.subarray(e,e+Zo),"base64url"),o=tt(t.subarray(e+Zo),"base64url"),new Ke({...ql,key_ops:["verify"],x:n,y:o});if(t.byteLength===Yo*2+1)return n=tt(t.subarray(e,e+Yo),"base64url"),o=tt(t.subarray(e+Yo),"base64url"),new Ke({...Vl,key_ops:["verify"],x:n,y:o});if(t.byteLength===Xo*2+1)return n=tt(t.subarray(e,e+Xo),"base64url"),o=tt(t.subarray(e+Xo),"base64url"),new Ke({...Hl,key_ops:["verify"],x:n,y:o});throw new mt(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function Na(r){return mn([Oa(Uint8Array.from([1])),mn([jl(r.crv)],160),mn([Fa(new st(Uint8Array.from([4]),Z(r.x??"","base64url"),Z(r.y??"","base64url")))],161)]).subarray()}function jl(r){if(r==="P-256")return Ml;if(r==="P-384")return zl;if(r==="P-521")return Kl;throw new mt(`Invalid curve ${r}`)}var Ke=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=Na(this.jwk)),this._raw}toMultihash(){return St.digest(qe(this))}toCID(){return lt.createV1(114,this.toMultihash())}toString(){return Q.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:xt(this.raw,t.raw)}async verify(t,e,n){return Sa(this.jwk,e,t,n)}};function Wo(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in r&&r.BYTES_PER_ELEMENT===1}function ee(r,t=""){if(typeof r!="number"){let e=t&&`"${t}" `;throw new TypeError(`${e}expected number, got ${typeof r}`)}if(!Number.isSafeInteger(r)||r<0){let e=t&&`"${t}" `;throw new RangeError(`${e}expected integer >= 0, got ${r}`)}}function wt(r,t,e=""){let n=Wo(r),o=r?.length,s=t!==void 0;if(!n||s&&o!==t){let i=e&&`"${e}" `,a=s?` of length ${t}`:"",c=n?`length=${o}`:`type=${typeof r}`,f=i+"expected Uint8Array"+a+", got "+c;throw n?new RangeError(f):new TypeError(f)}return r}function gn(r){if(typeof r!="function"||typeof r.create!="function")throw new TypeError("Hash must wrapped by utils.createHasher");if(ee(r.outputLen),ee(r.blockLen),r.outputLen<1)throw new Error('"outputLen" must be >= 1');if(r.blockLen<1)throw new Error('"blockLen" must be >= 1')}function Ve(r,t=!0){if(r.destroyed)throw new Error("Hash instance has been destroyed");if(t&&r.finished)throw new Error("Hash#digest() has already been called")}function bn(r,t){wt(r,void 0,"digestInto() output");let e=t.outputLen;if(r.length<e)throw new RangeError('"digestInto() output" expected to be of length >='+e)}function Kt(...r){for(let t=0;t<r.length;t++)r[t].fill(0)}function yn(r){return new DataView(r.buffer,r.byteOffset,r.byteLength)}function vt(r,t){return r<<32-t|r>>>t}var Ma=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",$l=Array.from({length:256},(r,t)=>t.toString(16).padStart(2,"0"));function xn(r){if(wt(r),Ma)return r.toHex();let t="";for(let e=0;e<r.length;e++)t+=$l[r[e]];return t}var zt={_0:48,_9:57,A:65,F:70,a:97,f:102};function Ua(r){if(r>=zt._0&&r<=zt._9)return r-zt._0;if(r>=zt.A&&r<=zt.F)return r-(zt.A-10);if(r>=zt.a&&r<=zt.f)return r-(zt.a-10)}function Br(r){if(typeof r!="string")throw new TypeError("hex string expected, got "+typeof r);if(Ma)try{return Uint8Array.fromHex(r)}catch(o){throw o instanceof SyntaxError?new RangeError(o.message):o}let t=r.length,e=t/2;if(t%2)throw new RangeError("hex string expected, got unpadded hex of length "+t);let n=new Uint8Array(e);for(let o=0,s=0;o<e;o++,s+=2){let i=Ua(r.charCodeAt(s)),a=Ua(r.charCodeAt(s+1));if(i===void 0||a===void 0){let c=r[s]+r[s+1];throw new RangeError('hex string expected, got non-hex character "'+c+'" at index '+s)}n[o]=i*16+a}return n}function Qo(...r){let t=0;for(let n=0;n<r.length;n++){let o=r[n];wt(o),t+=o.length}let e=new Uint8Array(t);for(let n=0,o=0;n<r.length;n++){let s=r[n];e.set(s,o),o+=s.length}return e}function Jo(r,t={}){let e=(o,s)=>r(s).update(o).digest(),n=r(void 0);return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.canXOF=n.canXOF,e.create=o=>r(o),Object.assign(e,t),Object.freeze(e)}function za(r=32){ee(r,"bytesLength");let t=typeof globalThis=="object"?globalThis.crypto:null;if(typeof t?.getRandomValues!="function")throw new Error("crypto.getRandomValues must be defined");if(r>65536)throw new RangeError(`"bytesLength" expected <= 65536, got ${r}`);return t.getRandomValues(new Uint8Array(r))}var ts=r=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,r])});function Ka(r,t,e){return r&t^~r&e}function qa(r,t,e){return r&t^r&e^t&e}var Lr=class{blockLen;outputLen;canXOF=!1;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(t,e,n,o){this.blockLen=t,this.outputLen=e,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(t),this.view=yn(this.buffer)}update(t){Ve(this),wt(t);let{view:e,buffer:n,blockLen:o}=this,s=t.length;for(let i=0;i<s;){let a=Math.min(o-this.pos,s-i);if(a===o){let c=yn(t);for(;o<=s-i;i+=o)this.process(c,i);continue}n.set(t.subarray(i,i+a),this.pos),this.pos+=a,i+=a,this.pos===o&&(this.process(e,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){Ve(this),bn(t,this),this.finished=!0;let{buffer:e,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;e[i++]=128,Kt(this.buffer.subarray(i)),this.padOffset>o-i&&(this.process(n,0),i=0);for(let h=i;h<o;h++)e[h]=0;n.setBigUint64(o-8,BigInt(this.length*8),s),this.process(n,0);let a=yn(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen must be aligned to 32bit");let f=c/4,d=this.get();if(f>d.length)throw new Error("_sha2: outputLen bigger than state");for(let h=0;h<f;h++)a.setUint32(4*h,d[h],s)}digest(){let{buffer:t,outputLen:e}=this;this.digestInto(t);let n=t.slice(0,e);return this.destroy(),n}_cloneInto(t){t||=new this.constructor,t.set(...this.get());let{blockLen:e,buffer:n,length:o,finished:s,destroyed:i,pos:a}=this;return t.destroyed=i,t.finished=s,t.length=o,t.pos=a,o%e&&t.buffer.set(n),t}clone(){return this._cloneInto()}},qt=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var ct=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var wn=BigInt(4294967295),Va=BigInt(32);function Gl(r,t=!1){return t?{h:Number(r&wn),l:Number(r>>Va&wn)}:{h:Number(r>>Va&wn)|0,l:Number(r&wn)|0}}function Ha(r,t=!1){let e=r.length,n=new Uint32Array(e),o=new Uint32Array(e);for(let s=0;s<e;s++){let{h:i,l:a}=Gl(r[s],t);[n[s],o[s]]=[i,a]}return[n,o]}var es=(r,t,e)=>r>>>e,rs=(r,t,e)=>r<<32-e|t>>>e,ye=(r,t,e)=>r>>>e|t<<32-e,xe=(r,t,e)=>r<<32-e|t>>>e,Cr=(r,t,e)=>r<<64-e|t>>>e-32,Dr=(r,t,e)=>r>>>e-32|t<<64-e;function Dt(r,t,e,n){let o=(t>>>0)+(n>>>0);return{h:r+e+(o/2**32|0)|0,l:o|0}}var ja=(r,t,e)=>(r>>>0)+(t>>>0)+(e>>>0),$a=(r,t,e,n)=>t+e+n+(r/2**32|0)|0,Ga=(r,t,e,n)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0),Za=(r,t,e,n,o)=>t+e+n+o+(r/2**32|0)|0,Ya=(r,t,e,n,o)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0)+(o>>>0),Xa=(r,t,e,n,o,s)=>t+e+n+o+s+(r/2**32|0)|0;var Yl=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),re=new Uint32Array(64),ns=class extends Lr{constructor(t){super(64,t,8,!1)}get(){let{A:t,B:e,C:n,D:o,E:s,F:i,G:a,H:c}=this;return[t,e,n,o,s,i,a,c]}set(t,e,n,o,s,i,a,c){this.A=t|0,this.B=e|0,this.C=n|0,this.D=o|0,this.E=s|0,this.F=i|0,this.G=a|0,this.H=c|0}process(t,e){for(let h=0;h<16;h++,e+=4)re[h]=t.getUint32(e,!1);for(let h=16;h<64;h++){let u=re[h-15],p=re[h-2],b=vt(u,7)^vt(u,18)^u>>>3,x=vt(p,17)^vt(p,19)^p>>>10;re[h]=x+re[h-7]+b+re[h-16]|0}let{A:n,B:o,C:s,D:i,E:a,F:c,G:f,H:d}=this;for(let h=0;h<64;h++){let u=vt(a,6)^vt(a,11)^vt(a,25),p=d+u+Ka(a,c,f)+Yl[h]+re[h]|0,x=(vt(n,2)^vt(n,13)^vt(n,22))+qa(n,o,s)|0;d=f,f=c,c=a,a=i+p|0,i=s,s=o,o=n,n=p+x|0}n=n+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,a=a+this.E|0,c=c+this.F|0,f=f+this.G|0,d=d+this.H|0,this.set(n,o,s,i,a,c,f,d)}roundClean(){Kt(re)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),Kt(this.buffer)}},os=class extends ns{A=qt[0]|0;B=qt[1]|0;C=qt[2]|0;D=qt[3]|0;E=qt[4]|0;F=qt[5]|0;G=qt[6]|0;H=qt[7]|0;constructor(){super(32)}};var Wa=Ha(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(r=>BigInt(r))),Xl=Wa[0],Wl=Wa[1],ne=new Uint32Array(80),oe=new Uint32Array(80),ss=class extends Lr{constructor(t){super(128,t,16,!1)}get(){let{Ah:t,Al:e,Bh:n,Bl:o,Ch:s,Cl:i,Dh:a,Dl:c,Eh:f,El:d,Fh:h,Fl:u,Gh:p,Gl:b,Hh:x,Hl:m}=this;return[t,e,n,o,s,i,a,c,f,d,h,u,p,b,x,m]}set(t,e,n,o,s,i,a,c,f,d,h,u,p,b,x,m){this.Ah=t|0,this.Al=e|0,this.Bh=n|0,this.Bl=o|0,this.Ch=s|0,this.Cl=i|0,this.Dh=a|0,this.Dl=c|0,this.Eh=f|0,this.El=d|0,this.Fh=h|0,this.Fl=u|0,this.Gh=p|0,this.Gl=b|0,this.Hh=x|0,this.Hl=m|0}process(t,e){for(let w=0;w<16;w++,e+=4)ne[w]=t.getUint32(e),oe[w]=t.getUint32(e+=4);for(let w=16;w<80;w++){let _=ne[w-15]|0,A=oe[w-15]|0,C=ye(_,A,1)^ye(_,A,8)^es(_,A,7),L=xe(_,A,1)^xe(_,A,8)^rs(_,A,7),B=ne[w-2]|0,P=oe[w-2]|0,q=ye(B,P,19)^Cr(B,P,61)^es(B,P,6),k=xe(B,P,19)^Dr(B,P,61)^rs(B,P,6),y=Ga(L,k,oe[w-7],oe[w-16]),E=Za(y,C,q,ne[w-7],ne[w-16]);ne[w]=E|0,oe[w]=y|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:a,Cl:c,Dh:f,Dl:d,Eh:h,El:u,Fh:p,Fl:b,Gh:x,Gl:m,Hh:l,Hl:g}=this;for(let w=0;w<80;w++){let _=ye(h,u,14)^ye(h,u,18)^Cr(h,u,41),A=xe(h,u,14)^xe(h,u,18)^Dr(h,u,41),C=h&p^~h&x,L=u&b^~u&m,B=Ya(g,A,L,Wl[w],oe[w]),P=Xa(B,l,_,C,Xl[w],ne[w]),q=B|0,k=ye(n,o,28)^Cr(n,o,34)^Cr(n,o,39),y=xe(n,o,28)^Dr(n,o,34)^Dr(n,o,39),E=n&s^n&a^s&a,I=o&i^o&c^i&c;l=x|0,g=m|0,x=p|0,m=b|0,p=h|0,b=u|0,{h,l:u}=Dt(f|0,d|0,P|0,q|0),f=a|0,d=c|0,a=s|0,c=i|0,s=n|0,i=o|0;let v=ja(q,y,I);n=$a(v,P,k,E),o=v|0}({h:n,l:o}=Dt(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=Dt(this.Bh|0,this.Bl|0,s|0,i|0),{h:a,l:c}=Dt(this.Ch|0,this.Cl|0,a|0,c|0),{h:f,l:d}=Dt(this.Dh|0,this.Dl|0,f|0,d|0),{h,l:u}=Dt(this.Eh|0,this.El|0,h|0,u|0),{h:p,l:b}=Dt(this.Fh|0,this.Fl|0,p|0,b|0),{h:x,l:m}=Dt(this.Gh|0,this.Gl|0,x|0,m|0),{h:l,l:g}=Dt(this.Hh|0,this.Hl|0,l|0,g|0),this.set(n,o,s,i,a,c,f,d,h,u,p,b,x,m,l,g)}roundClean(){Kt(ne,oe)}destroy(){this.destroyed=!0,Kt(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},is=class extends ss{Ah=ct[0]|0;Al=ct[1]|0;Bh=ct[2]|0;Bl=ct[3]|0;Ch=ct[4]|0;Cl=ct[5]|0;Dh=ct[6]|0;Dl=ct[7]|0;Eh=ct[8]|0;El=ct[9]|0;Fh=ct[10]|0;Fl=ct[11]|0;Gh=ct[12]|0;Gl=ct[13]|0;Hh=ct[14]|0;Hl=ct[15]|0;constructor(){super(64)}};var Qa=Jo(()=>new os,ts(1));var En=Jo(()=>new is,ts(3));var M=(r,t,e)=>wt(r,t,e),cs=ee,He=xn,rt=(...r)=>Qo(...r),je=r=>Br(r),we=Wo,Rr=r=>za(r),vn=BigInt(0),as=BigInt(1);function _t(r,t=""){if(typeof r!="boolean"){let e=t&&`"${t}" `;throw new TypeError(e+"expected boolean, got type="+typeof r)}return r}function _n(r){if(typeof r=="bigint"){if(!Sn(r))throw new RangeError("positive bigint expected, got "+r)}else cs(r);return r}function At(r,t=""){if(typeof r!="number"){let e=t&&`"${t}" `;throw new TypeError(e+"expected number, got type="+typeof r)}if(!Number.isSafeInteger(r)){let e=t&&`"${t}" `;throw new RangeError(e+"expected safe integer, got "+r)}}function Or(r){let t=_n(r).toString(16);return t.length&1?"0"+t:t}function Ja(r){if(typeof r!="string")throw new TypeError("hex string expected, got "+typeof r);return r===""?vn:BigInt("0x"+r)}function Ee(r){return Ja(xn(r))}function Rt(r){return Ja(xn(Fr(wt(r)).reverse()))}function An(r,t){if(ee(t),t===0)throw new RangeError("zero length");r=_n(r);let e=r.toString(16);if(e.length>t*2)throw new RangeError("number too large");return Br(e.padStart(t*2,"0"))}function fs(r,t){return An(r,t).reverse()}function tc(r,t){if(r=M(r),t=M(t),r.length!==t.length)return!1;let e=0;for(let n=0;n<r.length;n++)e|=r[n]^t[n];return e===0}function Fr(r){return Uint8Array.from(M(r))}function In(r){if(typeof r!="string")throw new TypeError("ascii string expected, got "+typeof r);return Uint8Array.from(r,(t,e)=>{let n=t.charCodeAt(0);if(t.length!==1||n>127)throw new RangeError(`string contains non-ASCII character "${r[e]}" with code ${n} at position ${e}`);return n})}var Sn=r=>typeof r=="bigint"&&vn<=r;function Ql(r,t,e){return Sn(r)&&Sn(t)&&Sn(e)&&t<=r&&r<e}function $e(r,t,e,n){if(!Ql(t,e,n))throw new RangeError("expected valid "+r+": "+e+" <= n < "+n+", got "+t)}function Ge(r){if(r<vn)throw new Error("expected non-negative bigint, got "+r);let t;for(t=0;r>vn;r>>=as,t+=1);return t}var Pr=r=>(as<<BigInt(r))-as;function ec(r,t,e){if(ee(r,"hashLen"),ee(t,"qByteLen"),typeof e!="function")throw new TypeError("hmacFn must be a function");let n=m=>new Uint8Array(m),o=Uint8Array.of(),s=Uint8Array.of(0),i=Uint8Array.of(1),a=1e3,c=n(r),f=n(r),d=0,h=()=>{c.fill(1),f.fill(0),d=0},u=(...m)=>e(f,rt(c,...m)),p=(m=o)=>{f=u(s,m),c=u(),m.length!==0&&(f=u(i,m),c=u())},b=()=>{if(d++>=a)throw new Error("drbg: tried max amount of iterations");let m=0,l=[];for(;m<t;){c=u();let g=c.slice();l.push(g),m+=c.length}return rt(...l)};return(m,l)=>{h(),p(m);let g;for(;(g=l(b()))===void 0;)p();return h(),g}}function It(r,t={},e={}){if(Object.prototype.toString.call(r)!=="[object Object]")throw new TypeError("expected valid options object");function n(s,i,a){if(!a&&i!=="function"&&!Object.hasOwn(r,s))throw new TypeError(`param "${s}" is invalid: expected own property`);let c=r[s];if(a&&c===void 0)return;let f=typeof c;if(f!==i||c===null)throw new TypeError(`param "${s}" is invalid: expected ${i}, got ${f}`)}let o=(s,i)=>Object.entries(s).forEach(([a,c])=>n(a,c,i));o(t,!1),o(e,!0)}var us=()=>{throw new Error("not implemented")};var ft=BigInt(0),Y=BigInt(1),Se=BigInt(2),sc=BigInt(3),ic=BigInt(4),ac=BigInt(5),Jl=BigInt(7),cc=BigInt(8),td=BigInt(9),fc=BigInt(16);function J(r,t){if(t<=ft)throw new Error("mod: expected positive modulus, got "+t);let e=r%t;return e>=ft?e:t+e}function j(r,t,e){if(t<ft)throw new Error("pow2: expected non-negative exponent, got "+t);let n=r;for(;t-- >ft;)n*=n,n%=e;return n}function rc(r,t){if(r===ft)throw new Error("invert: expected non-zero number");if(t<=ft)throw new Error("invert: expected positive modulus, got "+t);let e=J(r,t),n=t,o=ft,s=Y,i=Y,a=ft;for(;e!==ft;){let f=n/e,d=n-e*f,h=o-i*f,u=s-a*f;n=e,e=d,o=i,s=a,i=h,a=u}if(n!==Y)throw new Error("invert: does not exist");return J(o,t)}function ls(r,t,e){let n=r;if(!n.eql(n.sqr(t),e))throw new Error("Cannot find square root")}function uc(r,t){let e=r,n=(e.ORDER+Y)/ic,o=e.pow(t,n);return ls(e,o,t),o}function ed(r,t){let e=r,n=(e.ORDER-ac)/cc,o=e.mul(t,Se),s=e.pow(o,n),i=e.mul(t,s),a=e.mul(e.mul(i,Se),s),c=e.mul(i,e.sub(a,e.ONE));return ls(e,c,t),c}function rd(r){let t=Ze(r),e=lc(r),n=e(t,t.neg(t.ONE)),o=e(t,n),s=e(t,t.neg(n)),i=(r+Jl)/fc;return((a,c)=>{let f=a,d=f.pow(c,i),h=f.mul(d,n),u=f.mul(d,o),p=f.mul(d,s),b=f.eql(f.sqr(h),c),x=f.eql(f.sqr(u),c);d=f.cmov(d,h,b),h=f.cmov(p,u,x);let m=f.eql(f.sqr(h),c),l=f.cmov(d,h,m);return ls(f,l,c),l})}function lc(r){if(r<sc)throw new Error("sqrt is not defined for small field");let t=r-Y,e=0;for(;t%Se===ft;)t/=Se,e++;let n=Se,o=Ze(r);for(;nc(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(e===1)return uc;let s=o.pow(n,t),i=(t+Y)/Se;return function(c,f){let d=c;if(d.is0(f))return f;if(nc(d,f)!==1)throw new Error("Cannot find square root");let h=e,u=d.mul(d.ONE,s),p=d.pow(f,t),b=d.pow(f,i);for(;!d.eql(p,d.ONE);){if(d.is0(p))return d.ZERO;let x=1,m=d.sqr(p);for(;!d.eql(m,d.ONE);)if(x++,m=d.sqr(m),x===h)throw new Error("Cannot find square root");let l=Y<<BigInt(h-x-1),g=d.pow(u,l);h=x,u=d.sqr(g),p=d.mul(p,u),b=d.mul(b,g)}return b}}function nd(r){return r%ic===sc?uc:r%cc===ac?ed:r%fc===td?rd(r):lc(r)}var Vt=(r,t)=>(J(r,t)&Y)===Y,od=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function ds(r){let t={ORDER:"bigint",BYTES:"number",BITS:"number"},e=od.reduce((n,o)=>(n[o]="function",n),t);if(It(r,e),At(r.BYTES,"BYTES"),At(r.BITS,"BITS"),r.BYTES<1||r.BITS<1)throw new Error("invalid field: expected BYTES/BITS > 0");if(r.ORDER<=Y)throw new Error("invalid field: expected ORDER > 1, got "+r.ORDER);return r}function sd(r,t,e){let n=r;if(e<ft)throw new Error("invalid exponent, negatives unsupported");if(e===ft)return n.ONE;if(e===Y)return t;let o=n.ONE,s=t;for(;e>ft;)e&Y&&(o=n.mul(o,s)),s=n.sqr(s),e>>=Y;return o}function kr(r,t,e=!1){let n=r,o=new Array(t.length).fill(e?n.ZERO:void 0),s=t.reduce((a,c,f)=>n.is0(c)?a:(o[f]=a,n.mul(a,c)),n.ONE),i=n.inv(s);return t.reduceRight((a,c,f)=>n.is0(c)?a:(o[f]=n.mul(a,o[f]),n.mul(a,c)),i),o}function nc(r,t){let e=r,n=(e.ORDER-Y)/Se,o=e.pow(t,n),s=e.eql(o,e.ONE),i=e.eql(o,e.ZERO),a=e.eql(o,e.neg(e.ONE));if(!s&&!i&&!a)throw new Error("invalid Legendre symbol result");return s?1:i?0:-1}function id(r,t){if(t!==void 0&&cs(t),r<=ft)throw new Error("invalid n length: expected positive n, got "+r);if(t!==void 0&&t<1)throw new Error("invalid n length: expected positive bit length, got "+t);let e=Ge(r);if(t!==void 0&&t<e)throw new Error(`invalid n length: expected bit length (${e}) >= n.length (${t})`);let n=t!==void 0?t:e,o=Math.ceil(n/8);return{nBitLength:n,nByteLength:o}}var oc=new WeakMap,Tn=class{ORDER;BITS;BYTES;isLE;ZERO=ft;ONE=Y;_lengths;_mod;constructor(t,e={}){if(t<=Y)throw new Error("invalid field: expected ORDER > 1, got "+t);let n;this.isLE=!1,e!=null&&typeof e=="object"&&(typeof e.BITS=="number"&&(n=e.BITS),typeof e.sqrt=="function"&&Object.defineProperty(this,"sqrt",{value:e.sqrt,enumerable:!0}),typeof e.isLE=="boolean"&&(this.isLE=e.isLE),e.allowedLengths&&(this._lengths=Object.freeze(e.allowedLengths.slice())),typeof e.modFromBytes=="boolean"&&(this._mod=e.modFromBytes));let{nBitLength:o,nByteLength:s}=id(t,n);if(s>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");this.ORDER=t,this.BITS=o,this.BYTES=s,Object.freeze(this)}create(t){return J(t,this.ORDER)}isValid(t){if(typeof t!="bigint")throw new TypeError("invalid field element: expected bigint, got "+typeof t);return ft<=t&&t<this.ORDER}is0(t){return t===ft}isValidNot0(t){return!this.is0(t)&&this.isValid(t)}isOdd(t){return(t&Y)===Y}neg(t){return J(-t,this.ORDER)}eql(t,e){return t===e}sqr(t){return J(t*t,this.ORDER)}add(t,e){return J(t+e,this.ORDER)}sub(t,e){return J(t-e,this.ORDER)}mul(t,e){return J(t*e,this.ORDER)}pow(t,e){return sd(this,t,e)}div(t,e){return J(t*rc(e,this.ORDER),this.ORDER)}sqrN(t){return t*t}addN(t,e){return t+e}subN(t,e){return t-e}mulN(t,e){return t*e}inv(t){return rc(t,this.ORDER)}sqrt(t){let e=oc.get(this);return e||oc.set(this,e=nd(this.ORDER)),e(this,t)}toBytes(t){return this.isLE?fs(t,this.BYTES):An(t,this.BYTES)}fromBytes(t,e=!1){M(t);let{_lengths:n,BYTES:o,isLE:s,ORDER:i,_mod:a}=this;if(n){if(t.length<1||!n.includes(t.length)||t.length>o)throw new Error("Field.fromBytes: expected "+n+" bytes, got "+t.length);let f=new Uint8Array(o);f.set(t,s?0:f.length-t.length),t=f}if(t.length!==o)throw new Error("Field.fromBytes: expected "+o+" bytes, got "+t.length);let c=s?Rt(t):Ee(t);if(a&&(c=J(c,i)),!e&&!this.isValid(c))throw new Error("invalid field element: outside of range 0..ORDER");return c}invertBatch(t){return kr(this,t)}cmov(t,e,n){return _t(n,"condition"),n?e:t}};Object.freeze(Tn.prototype);function Ze(r,t={}){return new Tn(r,t)}function dc(r){if(typeof r!="bigint")throw new Error("field order must be bigint");if(r<=Y)throw new Error("field order must be greater than 1");let t=Ge(r-Y);return Math.ceil(t/8)}function hs(r){let t=dc(r);return t+Math.ceil(t/2)}function ps(r,t,e=!1){M(r);let n=r.length,o=dc(t),s=Math.max(hs(t),16);if(n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=e?Rt(r):Ee(r),a=J(i,t-Y)+Y;return e?fs(a,o):An(a,o)}var Ye=BigInt(0),ve=BigInt(1);function Nr(r,t){let e=t.negate();return r?e:t}function _e(r,t){let e=kr(r.Fp,t.map(n=>n.Z));return t.map((n,o)=>r.fromAffine(n.toAffine(e[o])))}function gc(r,t){if(!Number.isSafeInteger(r)||r<=0||r>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+r)}function ms(r,t){gc(r,t);let e=Math.ceil(t/r)+1,n=2**(r-1),o=2**r,s=Pr(r),i=BigInt(r);return{windows:e,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function hc(r,t,e){let{windowSize:n,mask:o,maxNumber:s,shiftBy:i}=e,a=Number(r&o),c=r>>i;a>n&&(a-=s,c+=ve);let f=t*n,d=f+Math.abs(a)-1,h=a===0,u=a<0,p=t%2!==0;return{nextN:c,offset:d,isZero:h,isNeg:u,isNegF:p,offsetF:f}}var gs=new WeakMap,bc=new WeakMap;function bs(r){return bc.get(r)||1}function pc(r){if(r!==Ye)throw new Error("invalid wNAF")}var Xe=class{BASE;ZERO;Fn;bits;constructor(t,e){this.BASE=t.BASE,this.ZERO=t.ZERO,this.Fn=t.Fn,this.bits=e}_unsafeLadder(t,e,n=this.ZERO){let o=t;for(;e>Ye;)e&ve&&(n=n.add(o)),o=o.double(),e>>=ve;return n}precomputeWindow(t,e){let{windows:n,windowSize:o}=ms(e,this.bits),s=[],i=t,a=i;for(let c=0;c<n;c++){a=i,s.push(a);for(let f=1;f<o;f++)a=a.add(i),s.push(a);i=a.double()}return s}wNAF(t,e,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let o=this.ZERO,s=this.BASE,i=ms(t,this.bits);for(let a=0;a<i.windows;a++){let{nextN:c,offset:f,isZero:d,isNeg:h,isNegF:u,offsetF:p}=hc(n,a,i);n=c,d?s=s.add(Nr(u,e[p])):o=o.add(Nr(h,e[f]))}return pc(n),{p:o,f:s}}wNAFUnsafe(t,e,n,o=this.ZERO){let s=ms(t,this.bits);for(let i=0;i<s.windows&&n!==Ye;i++){let{nextN:a,offset:c,isZero:f,isNeg:d}=hc(n,i,s);if(n=a,!f){let h=e[c];o=o.add(d?h.negate():h)}}return pc(n),o}getPrecomputes(t,e,n){let o=gs.get(e);return o||(o=this.precomputeWindow(e,t),t!==1&&(typeof n=="function"&&(o=n(o)),gs.set(e,o))),o}cached(t,e,n){let o=bs(t);return this.wNAF(o,this.getPrecomputes(o,t,n),e)}unsafe(t,e,n,o){let s=bs(t);return s===1?this._unsafeLadder(t,e,o):this.wNAFUnsafe(s,this.getPrecomputes(s,t,n),e,o)}createCache(t,e){gc(e,this.bits),bc.set(t,e),gs.delete(t)}hasCache(t){return bs(t)!==1}};function yc(r,t,e,n){let o=t,s=r.ZERO,i=r.ZERO;for(;e>Ye||n>Ye;)e&ve&&(s=s.add(o)),n&ve&&(i=i.add(o)),o=o.double(),e>>=ve,n>>=ve;return{p1:s,p2:i}}function mc(r,t,e){if(t){if(t.ORDER!==r)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return ds(t),t}else return Ze(r,{isLE:e})}function Bn(r,t,e={},n){if(n===void 0&&(n=r==="edwards"),!t||typeof t!="object")throw new Error(`expected valid ${r} CURVE object`);for(let c of["p","n","h"]){let f=t[c];if(!(typeof f=="bigint"&&f>Ye))throw new Error(`CURVE.${c} must be positive bigint`)}let o=mc(t.p,e.Fp,n),s=mc(t.n,e.Fn,n),a=["Gx","Gy","a",r==="weierstrass"?"b":"d"];for(let c of a)if(!o.isValid(t[c]))throw new Error(`CURVE.${c} must be valid field element of CURVE.Fp`);return t=Object.freeze(Object.assign({},t)),{CURVE:t,Fp:o,Fn:s}}function Ln(r,t){return function(n){let o=r(n);return{secretKey:o,publicKey:t(o)}}}var se=BigInt(0),it=BigInt(1),ys=BigInt(2),ad=BigInt(8);function cd(r,t,e,n){let o=r.sqr(e),s=r.sqr(n),i=r.add(r.mul(t.a,o),s),a=r.add(r.ONE,r.mul(t.d,r.mul(o,s)));return r.eql(i,a)}function xc(r,t={}){let e=t,n=Bn("edwards",r,e,e.FpFnLE),{Fp:o,Fn:s}=n,i=n.CURVE,{h:a}=i;It(e,{},{uvRatio:"function"});let c=ys<<BigInt(s.BYTES*8)-it,f=x=>o.create(x),d=e.uvRatio===void 0?(x,m)=>{try{return{isValid:!0,value:o.sqrt(o.div(x,m))}}catch{return{isValid:!1,value:se}}}:e.uvRatio;if(!cd(o,i,i.Gx,i.Gy))throw new Error("bad curve params: generator point");function h(x,m,l=!1){let g=l?it:se;return $e("coordinate "+x,m,g,c),m}function u(x){if(!(x instanceof p))throw new Error("EdwardsPoint expected")}class p{static BASE=new p(i.Gx,i.Gy,it,f(i.Gx*i.Gy));static ZERO=new p(se,it,it,se);static Fp=o;static Fn=s;X;Y;Z;T;constructor(m,l,g,w){this.X=h("x",m),this.Y=h("y",l),this.Z=h("z",g,!0),this.T=h("t",w),Object.freeze(this)}static CURVE(){return i}static fromAffine(m){if(m instanceof p)throw new Error("extended point not allowed");let{x:l,y:g}=m||{};return h("x",l),h("y",g),new p(l,g,it,f(l*g))}static fromBytes(m,l=!1){let g=o.BYTES,{a:w,d:_}=i;m=Fr(M(m,g,"point")),_t(l,"zip215");let A=Fr(m),C=m[g-1];A[g-1]=C&-129;let L=Rt(A),B=l?c:o.ORDER;$e("point.y",L,se,B);let P=f(L*L),q=f(P-it),k=f(_*P-w),{isValid:y,value:E}=d(q,k);if(!y)throw new Error("bad point: invalid y coordinate");let I=(E&it)===it,v=(C&128)!==0;if(!l&&E===se&&v)throw new Error("bad point: x=0 and x_0=1");return v!==I&&(E=f(-E)),p.fromAffine({x:E,y:L})}static fromHex(m,l=!1){return p.fromBytes(je(m),l)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(m=8,l=!0){return b.createCache(this,m),l||this.multiply(ys),this}assertValidity(){let m=this,{a:l,d:g}=i;if(m.is0())throw new Error("bad point: ZERO");let{X:w,Y:_,Z:A,T:C}=m,L=f(w*w),B=f(_*_),P=f(A*A),q=f(P*P),k=f(L*l),y=f(P*f(k+B)),E=f(q+f(g*f(L*B)));if(y!==E)throw new Error("bad point: equation left != right (1)");let I=f(w*_),v=f(A*C);if(I!==v)throw new Error("bad point: equation left != right (2)")}equals(m){u(m);let{X:l,Y:g,Z:w}=this,{X:_,Y:A,Z:C}=m,L=f(l*C),B=f(_*w),P=f(g*C),q=f(A*w);return L===B&&P===q}is0(){return this.equals(p.ZERO)}negate(){return new p(f(-this.X),this.Y,this.Z,f(-this.T))}double(){let{a:m}=i,{X:l,Y:g,Z:w}=this,_=f(l*l),A=f(g*g),C=f(ys*f(w*w)),L=f(m*_),B=l+g,P=f(f(B*B)-_-A),q=L+A,k=q-C,y=L-A,E=f(P*k),I=f(q*y),v=f(P*y),S=f(k*q);return new p(E,I,S,v)}add(m){u(m);let{a:l,d:g}=i,{X:w,Y:_,Z:A,T:C}=this,{X:L,Y:B,Z:P,T:q}=m,k=f(w*L),y=f(_*B),E=f(C*g*q),I=f(A*P),v=f((w+_)*(L+B)-k-y),S=I-E,T=I+E,R=f(y-l*k),D=f(v*S),O=f(T*R),F=f(v*R),U=f(S*T);return new p(D,O,U,F)}subtract(m){return u(m),this.add(m.negate())}multiply(m){if(!s.isValidNot0(m))throw new RangeError("invalid scalar: expected 1 <= sc < curve.n");let{p:l,f:g}=b.cached(this,m,w=>_e(p,w));return _e(p,[l,g])[0]}multiplyUnsafe(m){if(!s.isValid(m))throw new RangeError("invalid scalar: expected 0 <= sc < curve.n");return m===se?p.ZERO:this.is0()||m===it?this:b.unsafe(this,m,l=>_e(p,l))}isSmallOrder(){return this.clearCofactor().is0()}isTorsionFree(){return b.unsafe(this,i.n).is0()}toAffine(m){let l=this,g=m,{X:w,Y:_,Z:A}=l,C=l.is0();g==null&&(g=C?ad:o.inv(A));let L=f(w*g),B=f(_*g),P=o.mul(A,g);if(C)return{x:se,y:it};if(P!==it)throw new Error("invZ was invalid");return{x:L,y:B}}clearCofactor(){return a===it?this:this.multiplyUnsafe(a)}toBytes(){let{x:m,y:l}=this.toAffine(),g=o.toBytes(l);return g[g.length-1]|=m&it?128:0,g}toHex(){return He(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let b=new Xe(p,s.BITS);return s.BITS>=8&&p.BASE.precompute(8),Object.freeze(p.prototype),Object.freeze(p),p}var Cn=class{static BASE;static ZERO;static Fp;static Fn;ep;constructor(t){this.ep=t}static fromBytes(t){us()}static fromHex(t){us()}get x(){return this.toAffine().x}get y(){return this.toAffine().y}clearCofactor(){return this}assertValidity(){this.ep.assertValidity()}toAffine(t){return this.ep.toAffine(t)}toHex(){return He(this.toBytes())}toString(){return this.toHex()}isTorsionFree(){return!0}isSmallOrder(){return!1}add(t){return this.assertSame(t),this.init(this.ep.add(t.ep))}subtract(t){return this.assertSame(t),this.init(this.ep.subtract(t.ep))}multiply(t){return this.init(this.ep.multiply(t))}multiplyUnsafe(t){return this.init(this.ep.multiplyUnsafe(t))}double(){return this.init(this.ep.double())}negate(){return this.init(this.ep.negate())}precompute(t,e){return this.ep.precompute(t,e),this}};function wc(r,t,e={}){if(typeof t!="function")throw new Error('"hash" function param is required');let n=t,o=e;It(o,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",zip215:"boolean",mapToCurve:"function"});let{prehash:s}=o,{BASE:i,Fp:a,Fn:c}=r,f=n.outputLen,d=2*a.BYTES;if(f!==void 0&&(At(f,"hash.outputLen"),f!==d))throw new Error(`hash.outputLen must be ${d}, got ${f}`);let h=o.randomBytes===void 0?Rr:o.randomBytes,u=o.adjustScalarBytes===void 0?y=>y:o.adjustScalarBytes,p=o.domain===void 0?(y,E,I)=>{if(_t(I,"phflag"),E.length||I)throw new Error("Contexts/pre-hash are not supported");return y}:o.domain;function b(y){return c.create(Rt(y))}function x(y){let E=L.secretKey;M(y,L.secretKey,"secretKey");let I=M(n(y),2*E,"hashedSecretKey"),v=u(I.slice(0,E)),S=I.slice(E,2*E),T=b(v);return{head:v,prefix:S,scalar:T}}function m(y){let{head:E,prefix:I,scalar:v}=x(y),S=i.multiply(v),T=S.toBytes();return{head:E,prefix:I,scalar:v,point:S,pointBytes:T}}function l(y){return m(y).pointBytes}function g(y=Uint8Array.of(),...E){let I=rt(...E);return b(n(p(I,M(y,void 0,"context"),!!s)))}function w(y,E,I={}){y=M(y,void 0,"message"),s&&(y=s(y));let{prefix:v,scalar:S,pointBytes:T}=m(E),R=g(I.context,v,y),D=i.multiply(R).toBytes(),O=g(I.context,D,T,y),F=c.create(R+O*S);if(!c.isValid(F))throw new Error("sign failed: invalid s");let U=rt(D,c.toBytes(F));return M(U,L.signature,"result")}let _={zip215:o.zip215};function A(y,E,I,v=_){let{context:S}=v,T=v.zip215===void 0?!!_.zip215:v.zip215,R=L.signature;y=M(y,R,"signature"),E=M(E,void 0,"message"),I=M(I,L.publicKey,"publicKey"),T!==void 0&&_t(T,"zip215"),s&&(E=s(E));let D=R/2,O=y.subarray(0,D),F=Rt(y.subarray(D,R)),U,z,N;try{U=r.fromBytes(I,T),z=r.fromBytes(O,T),N=i.multiplyUnsafe(F)}catch{return!1}if(!T&&U.isSmallOrder())return!1;let et=g(S,O,I,E);return z.add(U.multiplyUnsafe(et)).subtract(N).clearCofactor().is0()}let C=a.BYTES,L={secretKey:C,publicKey:C,signature:2*C,seed:C};function B(y){return y=y===void 0?h(L.seed):y,M(y,L.seed,"seed")}function P(y){return we(y)&&y.length===L.secretKey}function q(y,E){try{return!!r.fromBytes(y,E===void 0?_.zip215:E)}catch{return!1}}let k={getExtendedPublicKey:m,randomSecretKey:B,isValidSecretKey:P,isValidPublicKey:q,toMontgomery(y){let{y:E}=r.fromBytes(y),I=L.publicKey,v=I===32;if(!v&&I!==57)throw new Error("only defined for 25519 and 448");let S=v?a.div(it+E,it-E):a.div(E-it,E+it);return a.toBytes(S)},toMontgomerySecret(y){let E=L.secretKey;M(y,E);let I=n(y.subarray(0,E));return u(I).subarray(0,E)}};return Object.freeze(L),Object.freeze(k),Object.freeze({keygen:Ln(B,l),getPublicKey:l,sign:w,verify:A,utils:k,Point:r,lengths:L})}function Ur(r,t){if(At(r),At(t),t<0||t>4)throw new Error("invalid I2OSP length: "+t);if(r<0||r>2**(8*t)-1)throw new Error("invalid I2OSP input: "+r);let e=Array.from({length:t}).fill(0);for(let n=t-1;n>=0;n--)e[n]=r&255,r>>>=8;return new Uint8Array(e)}function fd(r,t){let e=new Uint8Array(r.length);for(let n=0;n<r.length;n++)e[n]=r[n]^t[n];return e}function ud(r){if(!we(r)&&typeof r!="string")throw new Error("DST must be Uint8Array or ascii string");let t=typeof r=="string"?In(r):r;if(t.length===0)throw new Error("DST must be non-empty");return t}function xs(r,t,e,n){M(r),At(e),t=ud(t),t.length>255&&(t=n(rt(In("H2C-OVERSIZE-DST-"),t)));let{outputLen:o,blockLen:s}=n,i=Math.ceil(e/o);if(e>65535||i>255)throw new Error("expand_message_xmd: invalid lenInBytes");let a=rt(t,Ur(t.length,1)),c=new Uint8Array(s),f=Ur(e,2),d=new Array(i),h=n(rt(c,r,f,Ur(0,1),a));d[0]=n(rt(h,Ur(1,1),a));for(let p=1;p<i;p++){let b=[fd(h,d[p-1]),Ur(p+1,1),a];d[p]=n(rt(...b))}return rt(...d).slice(0,e)}var Ec="HashToScalar-";var ld=BigInt(0),Ht=BigInt(1),Sc=BigInt(2);var dd=BigInt(5),hd=BigInt(8),We=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),vs={p:We,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:hd,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function pd(r){let t=BigInt(10),e=BigInt(20),n=BigInt(40),o=BigInt(80),s=We,a=r*r%s*r%s,c=j(a,Sc,s)*a%s,f=j(c,Ht,s)*r%s,d=j(f,dd,s)*f%s,h=j(d,t,s)*d%s,u=j(h,e,s)*h%s,p=j(u,n,s)*u%s,b=j(p,o,s)*p%s,x=j(b,o,s)*p%s,m=j(x,t,s)*d%s;return{pow_p_5_8:j(m,Sc,s)*r%s,b2:a}}function md(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}var ws=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function _s(r,t){let e=We,n=J(t*t*t,e),o=J(n*n*t,e),s=pd(r*o).pow_p_5_8,i=J(r*n*s,e),a=J(t*i*i,e),c=i,f=J(i*ws,e),d=a===r,h=a===J(-r,e),u=a===J(-r*ws,e);return d&&(i=c),(h||u)&&(i=f),Vt(i,e)&&(i=J(-i,e)),{isValid:d||h,value:i}}var ae=xc(vs,{uvRatio:_s}),ie=ae.Fp,Ac=ae.Fn;function gd(r){return wc(ae,En,Object.assign({adjustScalarBytes:md,zip215:!0},r))}var Ic=gd({});var Es=ws,bd=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),yd=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),xd=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),wd=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952"),vc=r=>_s(Ht,r),Ed=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),Ss=r=>ie.create(Rt(r)&Ed);function _c(r){let{d:t}=vs,e=We,n=l=>ie.create(l),o=n(Es*r*r),s=n((o+Ht)*xd),i=BigInt(-1),a=n((i-t*o)*n(o+t)),{isValid:c,value:f}=_s(s,a),d=n(f*r);Vt(d,e)||(d=n(-d)),c||(f=d),c||(i=o);let h=n(i*(o-Ht)*wd-a),u=f*f,p=n((f+f)*a),b=n(h*bd),x=n(Ht-u),m=n(Ht+u);return new ae(n(p*m),n(x*b),n(b*m),n(p*x))}var ce=class r extends Cn{static BASE=new r(ae.BASE);static ZERO=new r(ae.ZERO);static Fp=ie;static Fn=Ac;constructor(t){super(t)}static fromAffine(t){return new r(ae.fromAffine(t))}assertSame(t){if(!(t instanceof r))throw new Error("RistrettoPoint expected")}init(t){return new r(t)}static fromBytes(t){wt(t,32);let{a:e,d:n}=vs,o=We,s=_=>ie.create(_),i=Ss(t);if(!tc(ie.toBytes(i),t)||Vt(i,o))throw new Error("invalid ristretto255 encoding 1");let a=s(i*i),c=s(Ht+e*a),f=s(Ht-e*a),d=s(c*c),h=s(f*f),u=s(e*n*d-h),{isValid:p,value:b}=vc(s(u*h)),x=s(b*f),m=s(b*x*u),l=s((i+i)*x);Vt(l,o)&&(l=s(-l));let g=s(c*m),w=s(l*g);if(!p||Vt(w,o)||g===ld)throw new Error("invalid ristretto255 encoding 2");return new r(new ae(l,g,Ht,w))}static fromHex(t){return r.fromBytes(Br(t))}toBytes(){let{X:t,Y:e,Z:n,T:o}=this.ep,s=We,i=m=>ie.create(m),a=i(i(n+e)*i(n-e)),c=i(t*e),f=i(c*c),{value:d}=vc(i(a*f)),h=i(d*a),u=i(d*c),p=i(h*u*o),b;if(Vt(o*p,s)){let m=i(e*Es),l=i(t*Es);t=m,e=l,b=i(h*yd)}else b=u;Vt(t*p,s)&&(e=i(-e));let x=i((n-e)*b);return Vt(x,s)&&(x=i(-x)),ie.toBytes(x)}equals(t){this.assertSame(t);let{X:e,Y:n}=this.ep,{X:o,Y:s}=t.ep,i=f=>ie.create(f),a=i(e*s)===i(n*o),c=i(n*s)===i(e*o);return a||c}is0(){return this.equals(r.ZERO)}};Object.freeze(ce.BASE);Object.freeze(ce.ZERO);Object.freeze(ce.prototype);Object.freeze(ce);var Sd=Object.freeze({Point:ce,hashToCurve(r,t){let e=t?.DST===void 0?"ristretto255_XMD:SHA-512_R255MAP_RO_":t.DST,n=xs(r,e,64,En);return Sd.deriveToCurve(n)},hashToScalar(r,t={DST:Ec}){let e=xs(r,t.DST,64,En);return Ac.create(Rt(e))},deriveToCurve(r){wt(r,64);let t=Ss(r.subarray(0,32)),e=_c(t),n=Ss(r.subarray(32,64)),o=_c(n);return new ce(e.add(o))}});var Mr=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},Dn=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var Rn={get(r=globalThis){let t=r.crypto;if(t?.subtle==null)throw new Dn("Missing Web Crypto API. The most likely cause of this error is that this page is being accessed from an insecure context (i.e. not HTTPS). For more information and possible resolutions see https://github.com/libp2p/js-libp2p/blob/main/packages/crypto/README.md#web-crypto-api");return t}};var On=32;var As,vd=(async()=>{try{return await Rn.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function _d(r,t,e){if(r.buffer instanceof ArrayBuffer){let n=await Rn.get().subtle.importKey("raw",r.buffer,{name:"Ed25519"},!1,["verify"]);return await Rn.get().subtle.verify({name:"Ed25519"},n,Ut(t),Ut(e instanceof Uint8Array?e:e.subarray()))}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function Ad(r,t,e){return Ic.verify(t,e instanceof Uint8Array?e:e.subarray(),r)}async function Tc(r,t,e){return As==null&&(As=await vd),As?_d(r,t,e):Ad(r,t,e)}function Id(r){return r?.buffer instanceof ArrayBuffer}function Is(r){if(Id(r))return r;let t=r.slice();return new Uint8Array(t.buffer,0,t.byteLength)}function Ae(r,t){t==null&&(t=r.reduce((o,s)=>o+s.length,0));let e=be(t),n=0;for(let o of r)e.set(o,n),n+=o.length;return Is(e)}function Fn(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}var Pn=class{type="Ed25519";raw;constructor(t){this.raw=Ts(t,On)}toMultihash(){return St.digest(qe(this))}toCID(){return lt.createV1(114,this.toMultihash())}toString(){return Q.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:xt(this.raw,t.raw)}verify(t,e,n){n?.signal?.throwIfAborted();let o=Tc(this.raw,e,t);return Fn(o)?o.then(s=>(n?.signal?.throwIfAborted(),s)):o}};function Lc(r){return r=Ts(r,On),new Pn(r)}function Ts(r,t){if(r=Uint8Array.from(r??[]),r.length!==t)throw new mt(`Key must be a Uint8Array of length ${t}, got ${r.length}`);return r}function fe(r=0){return new Uint8Array(r)}var Bd=Math.pow(2,7),Ld=Math.pow(2,14),Cd=Math.pow(2,21),Cc=Math.pow(2,28),Dc=Math.pow(2,35),Rc=Math.pow(2,42),Oc=Math.pow(2,49),gt=128,ue=127;function zr(r){if(r<Bd)return 1;if(r<Ld)return 2;if(r<Cd)return 3;if(r<Cc)return 4;if(r<Dc)return 5;if(r<Rc)return 6;if(r<Oc)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Fc(r,t,e=0){switch(zr(r)){case 8:t[e++]=r&255|gt,r/=128;case 7:t[e++]=r&255|gt,r/=128;case 6:t[e++]=r&255|gt,r/=128;case 5:t[e++]=r&255|gt,r/=128;case 4:t[e++]=r&255|gt,r>>>=7;case 3:t[e++]=r&255|gt,r>>>=7;case 2:t[e++]=r&255|gt,r>>>=7;case 1:{t[e++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return t}function Pc(r,t){let e=r[t],n=0;if(n+=e&ue,e<gt||(e=r[t+1],n+=(e&ue)<<7,e<gt)||(e=r[t+2],n+=(e&ue)<<14,e<gt)||(e=r[t+3],n+=(e&ue)<<21,e<gt)||(e=r[t+4],n+=(e&ue)*Cc,e<gt)||(e=r[t+5],n+=(e&ue)*Dc,e<gt)||(e=r[t+6],n+=(e&ue)*Rc,e<gt)||(e=r[t+7],n+=(e&ue)*Oc,e<gt))return n;throw new RangeError("Could not decode varint")}var Bs=new Float32Array([-0]),le=new Uint8Array(Bs.buffer);function kc(r,t,e){Bs[0]=r,t[e]=le[0],t[e+1]=le[1],t[e+2]=le[2],t[e+3]=le[3]}function Nc(r,t){return le[0]=r[t],le[1]=r[t+1],le[2]=r[t+2],le[3]=r[t+3],Bs[0]}var Ls=new Float64Array([-0]),dt=new Uint8Array(Ls.buffer);function Uc(r,t,e){Ls[0]=r,t[e]=dt[0],t[e+1]=dt[1],t[e+2]=dt[2],t[e+3]=dt[3],t[e+4]=dt[4],t[e+5]=dt[5],t[e+6]=dt[6],t[e+7]=dt[7]}function Mc(r,t){return dt[0]=r[t],dt[1]=r[t+1],dt[2]=r[t+2],dt[3]=r[t+3],dt[4]=r[t+4],dt[5]=r[t+5],dt[6]=r[t+6],dt[7]=r[t+7],Ls[0]}var Dd=BigInt(Number.MAX_SAFE_INTEGER),Rd=BigInt(Number.MIN_SAFE_INTEGER),Et=class r{lo;hi;constructor(t,e){this.lo=t|0,this.hi=e|0}toNumber(t=!1){if(!t&&this.hi>>>31>0){let e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(e+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(t=!1){if(t)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(BigInt(e)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(t=!1){return this.toBigInt(t).toString()}zzEncode(){let t=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^t)>>>0,this.lo=(this.lo<<1^t)>>>0,this}zzDecode(){let t=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^t)>>>0,this.hi=(this.hi>>>1^t)>>>0,this}length(){let t=this.lo,e=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?e===0?t<16384?t<128?1:2:t<2097152?3:4:e<16384?e<128?5:6:e<2097152?7:8:n<128?9:10}static fromBigInt(t){if(t===0n)return Ie;if(t<Dd&&t>Rd)return this.fromNumber(Number(t));let e=t<0n;e&&(t=-t);let n=t>>32n,o=t-(n<<32n);return e&&(n=~n|0n,o=~o|0n,++o>zc&&(o=0n,++n>zc&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(t){if(t===0)return Ie;let e=t<0;e&&(t=-t);let n=t>>>0,o=(t-n)/4294967296>>>0;return e&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new r(n,o)}static from(t){return typeof t=="number"?r.fromNumber(t):typeof t=="bigint"?r.fromBigInt(t):typeof t=="string"?r.fromBigInt(BigInt(t)):t.low!=null||t.high!=null?new r(t.low>>>0,t.high>>>0):Ie}},Ie=new Et(0,0);Ie.toBigInt=function(){return 0n};Ie.zzEncode=Ie.zzDecode=function(){return this};Ie.length=function(){return 1};var zc=4294967296n;function Kc(r){let t=0,e=0;for(let n=0;n<r.length;++n)e=r.charCodeAt(n),e<128?t+=1:e<2048?t+=2:(e&64512)===55296&&(r.charCodeAt(n+1)&64512)===56320?(++n,t+=4):t+=3;return t}function qc(r,t,e){if(e-t<1)return"";let o,s=[],i=0,a;for(;t<e;)a=r[t++],a<128?s[i++]=a:a>191&&a<224?s[i++]=(a&31)<<6|r[t++]&63:a>239&&a<365?(a=((a&7)<<18|(r[t++]&63)<<12|(r[t++]&63)<<6|r[t++]&63)-65536,s[i++]=55296+(a>>10),s[i++]=56320+(a&1023)):s[i++]=(a&15)<<12|(r[t++]&63)<<6|r[t++]&63,i>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,s)),i=0);return o!=null?(i>0&&o.push(String.fromCharCode.apply(String,s.slice(0,i))),o.join("")):String.fromCharCode.apply(String,s.slice(0,i))}function Cs(r,t,e){let n=e,o,s;for(let i=0;i<r.length;++i)o=r.charCodeAt(i),o<128?t[e++]=o:o<2048?(t[e++]=o>>6|192,t[e++]=o&63|128):(o&64512)===55296&&((s=r.charCodeAt(i+1))&64512)===56320?(o=65536+((o&1023)<<10)+(s&1023),++i,t[e++]=o>>18|240,t[e++]=o>>12&63|128,t[e++]=o>>6&63|128,t[e++]=o&63|128):(t[e++]=o>>12|224,t[e++]=o>>6&63|128,t[e++]=o&63|128);return e-n}function Tt(r,t){return RangeError(`index out of range: ${r.pos} + ${t??1} > ${r.len}`)}function kn(r,t){return(r[t-4]|r[t-3]<<8|r[t-2]<<16|r[t-1]<<24)>>>0}var Ds=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(t){this.buf=t,this.pos=0,this.len=t.length}uint32(){let t=4294967295;if(t=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(t=(t|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return t;if((this.pos+=5)>this.len)throw this.pos=this.len,Tt(this,10);return t}int32(){return this.uint32()|0}sint32(){let t=this.uint32();return t>>>1^-(t&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw Tt(this,4);return kn(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Tt(this,4);return kn(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Tt(this,4);let t=Nc(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Tt(this,4);let t=Mc(this.buf,this.pos);return this.pos+=8,t}bytes(){let t=this.uint32(),e=this.pos,n=this.pos+t;if(n>this.len)throw Tt(this,t);return this.pos+=t,e===n?new Uint8Array(0):this.buf.subarray(e,n)}string(){let t=this.bytes();return qc(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw Tt(this,t);this.pos+=t}else do if(this.pos>=this.len)throw Tt(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(t){switch(t){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(t=this.uint32()&7)!==4;)this.skipType(t);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${t} at offset ${this.pos}`)}return this}readLongVarint(){let t=new Et(0,0),e=0;if(this.len-this.pos>4){for(;e<4;++e)if(t.lo=(t.lo|(this.buf[this.pos]&127)<<e*7)>>>0,this.buf[this.pos++]<128)return t;if(t.lo=(t.lo|(this.buf[this.pos]&127)<<28)>>>0,t.hi=(t.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return t;e=0}else{for(;e<3;++e){if(this.pos>=this.len)throw Tt(this);if(t.lo=(t.lo|(this.buf[this.pos]&127)<<e*7)>>>0,this.buf[this.pos++]<128)return t}return t.lo=(t.lo|(this.buf[this.pos++]&127)<<e*7)>>>0,t}if(this.len-this.pos>4){for(;e<5;++e)if(t.hi=(t.hi|(this.buf[this.pos]&127)<<e*7+3)>>>0,this.buf[this.pos++]<128)return t}else for(;e<5;++e){if(this.pos>=this.len)throw Tt(this);if(t.hi=(t.hi|(this.buf[this.pos]&127)<<e*7+3)>>>0,this.buf[this.pos++]<128)return t}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw Tt(this,8);let t=kn(this.buf,this.pos+=4),e=kn(this.buf,this.pos+=4);return new Et(t,e)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let t=Pc(this.buf,this.pos);return this.pos+=zr(t),t}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function Kr(r){return new Ds(r instanceof Uint8Array?r:r.subarray())}function jt(r,t,e){let n=Kr(r);return t.decode(n,void 0,e)}var ks={};V(ks,{base10:()=>Md});var vy=new Uint8Array(0);function Hc(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}function $t(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return r;if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return new Uint8Array(r.buffer,r.byteOffset,r.byteLength);throw new Error("Unknown type, must be binary type")}function jc(r){return new TextEncoder().encode(r)}function $c(r){return new TextDecoder().decode(r)}function Od(r,t){if(r.length>=255)throw new TypeError("Alphabet too long");for(var e=new Uint8Array(256),n=0;n<e.length;n++)e[n]=255;for(var o=0;o<r.length;o++){var s=r.charAt(o),i=s.charCodeAt(0);if(e[i]!==255)throw new TypeError(s+" is ambiguous");e[i]=o}var a=r.length,c=r.charAt(0),f=Math.log(a)/Math.log(256),d=Math.log(256)/Math.log(a);function h(b){if(b instanceof Uint8Array||(ArrayBuffer.isView(b)?b=new Uint8Array(b.buffer,b.byteOffset,b.byteLength):Array.isArray(b)&&(b=Uint8Array.from(b))),!(b instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(b.length===0)return"";for(var x=0,m=0,l=0,g=b.length;l!==g&&b[l]===0;)l++,x++;for(var w=(g-l)*d+1>>>0,_=new Uint8Array(w);l!==g;){for(var A=b[l],C=0,L=w-1;(A!==0||C<m)&&L!==-1;L--,C++)A+=256*_[L]>>>0,_[L]=A%a>>>0,A=A/a>>>0;if(A!==0)throw new Error("Non-zero carry");m=C,l++}for(var B=w-m;B!==w&&_[B]===0;)B++;for(var P=c.repeat(x);B<w;++B)P+=r.charAt(_[B]);return P}function u(b){if(typeof b!="string")throw new TypeError("Expected String");if(b.length===0)return new Uint8Array;var x=0;if(b[x]!==" "){for(var m=0,l=0;b[x]===c;)m++,x++;for(var g=(b.length-x)*f+1>>>0,w=new Uint8Array(g);b[x];){var _=e[b.charCodeAt(x)];if(_===255)return;for(var A=0,C=g-1;(_!==0||A<l)&&C!==-1;C--,A++)_+=a*w[C]>>>0,w[C]=_%256>>>0,_=_/256>>>0;if(_!==0)throw new Error("Non-zero carry");l=A,x++}if(b[x]!==" "){for(var L=g-l;L!==g&&w[L]===0;)L++;for(var B=new Uint8Array(m+(g-L)),P=m;L!==g;)B[P++]=w[L++];return B}}}function p(b){var x=u(b);if(x)return x;throw new Error(`Non-${t} character`)}return{encode:h,decodeUnsafe:u,decode:p}}var Fd=Od,Pd=Fd,Zc=Pd;var Rs=class{name;prefix;baseEncode;constructor(t,e,n){this.name=t,this.prefix=e,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},Os=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,e,n){this.name=t,this.prefix=e;let o=e.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return Yc(this,t)}},Fs=class{decoders;constructor(t){this.decoders=t}or(t){return Yc(this,t)}decode(t){let e=t[0],n=this.decoders[e];if(n!=null)return n.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function Yc(r,t){return new Fs({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var Ps=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,e,n,o){this.name=t,this.prefix=e,this.baseEncode=n,this.baseDecode=o,this.encoder=new Rs(t,e,n),this.decoder=new Os(t,e,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function Qe({name:r,prefix:t,encode:e,decode:n}){return new Ps(r,t,e,n)}function de({name:r,prefix:t,alphabet:e}){let{encode:n,decode:o}=Zc(e,r);return Qe({prefix:t,name:r,encode:n,decode:s=>$t(o(s))})}function kd(r,t,e,n){let o=r.length;for(;r[o-1]==="=";)--o;let s=new Uint8Array(o*e/8|0),i=0,a=0,c=0;for(let f=0;f<o;++f){let d=t[r[f]];if(d===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<e|d,i+=e,i>=8&&(i-=8,s[c++]=255&a>>i)}if(i>=e||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function Nd(r,t,e){let n=t[t.length-1]==="=",o=(1<<e)-1,s="",i=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],i+=8;i>e;)i-=e,s+=t[o&a>>i];if(i!==0&&(s+=t[o&a<<e-i]),n)for(;(s.length*e&7)!==0;)s+="=";return s}function Ud(r){let t={};for(let e=0;e<r.length;++e)t[r[e]]=e;return t}function X({name:r,prefix:t,bitsPerChar:e,alphabet:n}){let o=Ud(n);return Qe({prefix:t,name:r,encode(s){return Nd(s,n,e)},decode(s){return kd(s,o,e,r)}})}var Md=de({prefix:"9",name:"base10",alphabet:"0123456789"});var Ns={};V(Ns,{base16:()=>zd,base16upper:()=>Kd});var zd=X({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Kd=X({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Us={};V(Us,{base2:()=>qd});var qd=X({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Ms={};V(Ms,{base256emoji:()=>Gd});var Xc=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}"),Vd=Xc.reduce((r,t,e)=>(r[e]=t,r),[]),Hd=Xc.reduce((r,t,e)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return r[n]=e,r},[]);function jd(r){return r.reduce((t,e)=>(t+=Vd[e],t),"")}function $d(r){let t=[];for(let e of r){let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);let o=Hd[n];if(o==null)throw new Error(`Non-base256emoji character: ${e}`);t.push(o)}return new Uint8Array(t)}var Gd=Qe({prefix:"\u{1F680}",name:"base256emoji",encode:jd,decode:$d});var zs={};V(zs,{base32:()=>Je,base32hex:()=>Wd,base32hexpad:()=>Jd,base32hexpadupper:()=>th,base32hexupper:()=>Qd,base32pad:()=>Yd,base32padupper:()=>Xd,base32upper:()=>Zd,base32z:()=>eh});var Je=X({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Zd=X({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Yd=X({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Xd=X({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Wd=X({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Qd=X({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Jd=X({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),th=X({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),eh=X({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Ks={};V(Ks,{base36:()=>qr,base36upper:()=>rh});var qr=de({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),rh=de({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var qs={};V(qs,{base58btc:()=>Ot,base58flickr:()=>nh});var Ot=de({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),nh=de({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Vs={};V(Vs,{base64:()=>oh,base64pad:()=>sh,base64url:()=>ih,base64urlpad:()=>ah});var oh=X({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),sh=X({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),ih=X({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),ah=X({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Hs={};V(Hs,{base8:()=>ch});var ch=X({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var js={};V(js,{identity:()=>fh});var fh=Qe({prefix:"\0",name:"identity",encode:r=>$c(r),decode:r=>jc(r)});var My=new TextEncoder,zy=new TextDecoder;var Gs={};V(Gs,{identity:()=>Rh});var dh=Jc,Wc=128,hh=127,ph=~hh,mh=Math.pow(2,31);function Jc(r,t,e){t=t||[],e=e||0;for(var n=e;r>=mh;)t[e++]=r&255|Wc,r/=128;for(;r&ph;)t[e++]=r&255|Wc,r>>>=7;return t[e]=r|0,Jc.bytes=e-n+1,t}var gh=$s,bh=128,Qc=127;function $s(r,n){var e=0,n=n||0,o=0,s=n,i,a=r.length;do{if(s>=a)throw $s.bytes=0,new RangeError("Could not decode varint");i=r[s++],e+=o<28?(i&Qc)<<o:(i&Qc)*Math.pow(2,o),o+=7}while(i>=bh);return $s.bytes=s-n,e}var yh=Math.pow(2,7),xh=Math.pow(2,14),wh=Math.pow(2,21),Eh=Math.pow(2,28),Sh=Math.pow(2,35),vh=Math.pow(2,42),_h=Math.pow(2,49),Ah=Math.pow(2,56),Ih=Math.pow(2,63),Th=function(r){return r<yh?1:r<xh?2:r<wh?3:r<Eh?4:r<Sh?5:r<vh?6:r<_h?7:r<Ah?8:r<Ih?9:10},Bh={encode:dh,decode:gh,encodingLength:Th},Lh=Bh,Vr=Lh;function Hr(r,t=0){return[Vr.decode(r,t),Vr.decode.bytes]}function tr(r,t,e=0){return Vr.encode(r,t,e),t}function er(r){return Vr.encodingLength(r)}function nr(r,t){let e=t.byteLength,n=er(r),o=n+er(e),s=new Uint8Array(o+e);return tr(r,s,0),tr(e,s,n),s.set(t,o),new rr(r,e,t,s)}function tf(r){let t=$t(r),[e,n]=Hr(t),[o,s]=Hr(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new rr(e,o,i,t)}function ef(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&Hc(r.bytes,e.bytes)}}var rr=class{code;size;digest;bytes;constructor(t,e,n,o){this.code=t,this.size=e,this.digest=n,this.bytes=o}};var rf=0,Ch="identity",nf=$t;function Dh(r,t){if(t?.truncate!=null&&t.truncate!==r.byteLength){if(t.truncate<0||t.truncate>r.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${r.byteLength}`);r=r.subarray(0,t.truncate)}return nr(rf,nf(r))}var Rh={code:rf,name:Ch,encode:nf,digest:Dh};var Xs={};V(Xs,{sha256:()=>Fh,sha512:()=>Ph});var Oh=20;function Ys({name:r,code:t,encode:e,minDigestLength:n,maxDigestLength:o}){return new Zs(r,t,e,n,o)}var Zs=class{name;code;encode;minDigestLength;maxDigestLength;constructor(t,e,n,o,s){this.name=t,this.code=e,this.encode=n,this.minDigestLength=o??Oh,this.maxDigestLength=s}digest(t,e){if(e?.truncate!=null){if(e.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&e.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(t instanceof Uint8Array){let n=this.encode(t);return n instanceof Uint8Array?of(n,this.code,e?.truncate):n.then(o=>of(o,this.code,e?.truncate))}else throw Error("Unknown type, must be binary type")}};function of(r,t,e){if(e!=null&&e!==r.byteLength){if(e>r.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${r.byteLength}`);r=r.subarray(0,e)}return nr(t,r)}function af(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var Fh=Ys({name:"sha2-256",code:18,encode:af("SHA-256")}),Ph=Ys({name:"sha2-512",code:19,encode:af("SHA-512")});function cf(r,t){let{bytes:e,version:n}=r;return n===0?Nh(e,Ws(r),t??Ot.encoder):Uh(e,Ws(r),t??Je.encoder)}var ff=new WeakMap;function Ws(r){let t=ff.get(r);if(t==null){let e=new Map;return ff.set(r,e),e}return t}var Un=class r{code;version;multihash;bytes;"/";constructor(t,e,n,o){this.code=e,this.version=t,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:t,multihash:e}=this;if(t!==$r)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==Mh)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(e)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:t,digest:e}=this.multihash,n=nr(t,e);return r.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(t){return r.equals(this,t)}static equals(t,e){let n=e;return n!=null&&t.code===n.code&&t.version===n.version&&ef(t.multihash,n.multihash)}toString(t){return cf(this,t)}toJSON(){return{"/":cf(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(t){if(t==null)return null;let e=t;if(e instanceof r)return e;if(e["/"]!=null&&e["/"]===e.bytes||e.asCID===e){let{version:n,code:o,multihash:s,bytes:i}=e;return new r(n,o,s,i??uf(n,o,s.bytes))}else if(e[zh]===!0){let{version:n,multihash:o,code:s}=e,i=tf(o);return r.create(n,s,i)}else return null}static create(t,e,n){if(typeof e!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(t){case 0:{if(e!==$r)throw new Error(`Version 0 CID must use dag-pb (code: ${$r}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let o=uf(t,e,n.bytes);return new r(t,e,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,$r,t)}static createV1(t,e){return r.create(1,t,e)}static decode(t){let[e,n]=r.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return e}static decodeFirst(t){let e=r.inspectBytes(t),n=e.size-e.multihashSize,o=$t(t.subarray(n,n+e.multihashSize));if(o.byteLength!==e.multihashSize)throw new Error("Incorrect length");let s=o.subarray(e.multihashSize-e.digestSize),i=new rr(e.multihashCode,e.digestSize,s,o);return[e.version===0?r.createV0(i):r.createV1(e.codec,i),t.subarray(e.size)]}static inspectBytes(t){let e=0,n=()=>{let[h,u]=Hr(t.subarray(e));return e+=u,h},o=n(),s=$r;if(o===18?(o=0,e=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=e,a=n(),c=n(),f=e+c,d=f-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:d,size:f}}static parse(t,e){let[n,o]=kh(t,e),s=r.decode(o);if(s.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Ws(s).set(n,t),s}};function kh(r,t){switch(r[0]){case"Q":{let e=t??Ot;return[Ot.prefix,e.decode(`${Ot.prefix}${r}`)]}case Ot.prefix:{let e=t??Ot;return[Ot.prefix,e.decode(r)]}case Je.prefix:{let e=t??Je;return[Je.prefix,e.decode(r)]}case qr.prefix:{let e=t??qr;return[qr.prefix,e.decode(r)]}default:{if(t==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[r[0],t.decode(r)]}}}function Nh(r,t,e){let{prefix:n}=e;if(n!==Ot.prefix)throw Error(`Cannot string encode V0 in ${e.name} encoding`);let o=t.get(n);if(o==null){let s=e.encode(r).slice(1);return t.set(n,s),s}else return o}function Uh(r,t,e){let{prefix:n}=e,o=t.get(n);if(o==null){let s=e.encode(r);return t.set(n,s),s}else return o}var $r=112,Mh=18;function uf(r,t,e){let n=er(r),o=n+er(t),s=new Uint8Array(o+e.byteLength);return tr(r,s,0),tr(t,s,n),s.set(e,o),s}var zh=Symbol.for("@ipld/js-cid/CID");var Qs={...js,...Us,...Hs,...ks,...Ns,...zs,...Ks,...qs,...Vs,...Ms},cx={...Xs,...Gs};function df(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var lf=df("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Js=df("ascii","a",r=>{let t="a";for(let e=0;e<r.length;e++)t+=String.fromCharCode(r[e]);return t},r=>{r=r.substring(1);let t=fe(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),Kh={utf8:lf,"utf-8":lf,hex:Qs.base16,latin1:Js,ascii:Js,binary:Js,...Qs},hf=Kh;function pf(r,t="utf8"){let e=hf[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.decoder.decode(`${e.prefix}${r}`)}function ti(r){let t=r??8192,e=t>>>1,n,o=t;return function(i){if(i<1||i>e)return fe(i);o+i>t&&(n=fe(t),o=0);let a=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),a}}var Te=class{fn;len;next;val;constructor(t,e,n){this.fn=t,this.len=e,this.next=void 0,this.val=n}};function ei(){}var ni=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},qh=ti();function Vh(r){return globalThis.Buffer!=null?fe(r):qh(r)}var Zr=class{len;head;tail;states;constructor(){this.len=0,this.head=new Te(ei,0,0),this.tail=this.head,this.states=null}_push(t,e,n){return this.tail=this.tail.next=new Te(t,e,n),this.len+=e,this}uint32(t){return this.len+=(this.tail=this.tail.next=new oi((t=t>>>0)<128?1:t<16384?2:t<2097152?3:t<268435456?4:5,t)).len,this}int32(t){return t<0?this._push(Mn,10,Et.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let e=Et.fromBigInt(t);return this._push(Mn,e.length(),e)}uint64Number(t){return this._push(Fc,zr(t),t)}uint64String(t){return this.uint64(BigInt(t))}int64(t){return this.uint64(t)}int64Number(t){return this.uint64Number(t)}int64String(t){return this.uint64String(t)}sint64(t){let e=Et.fromBigInt(t).zzEncode();return this._push(Mn,e.length(),e)}sint64Number(t){let e=Et.fromNumber(t).zzEncode();return this._push(Mn,e.length(),e)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(ri,1,t?1:0)}fixed32(t){return this._push(Gr,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=Et.fromBigInt(t);return this._push(Gr,4,e.lo)._push(Gr,4,e.hi)}fixed64Number(t){let e=Et.fromNumber(t);return this._push(Gr,4,e.lo)._push(Gr,4,e.hi)}fixed64String(t){return this.fixed64(BigInt(t))}sfixed64(t){return this.fixed64(t)}sfixed64Number(t){return this.fixed64Number(t)}sfixed64String(t){return this.fixed64String(t)}float(t){return this._push(kc,4,t)}double(t){return this._push(Uc,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(ri,1,0):this.uint32(e)._push(jh,e,t)}string(t){let e=Kc(t);return e!==0?this.uint32(e)._push(Cs,e,t):this._push(ri,1,0)}fork(){return this.states=new ni(this),this.head=this.tail=new Te(ei,0,0),this.len=0,this}reset(){return this.states!=null?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new Te(ei,0,0),this.len=0),this}ldelim(){let t=this.head,e=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=t.next,this.tail=e,this.len+=n),this}finish(){let t=this.head.next,e=Vh(this.len),n=0;for(;t!=null;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e}};function ri(r,t,e){t[e]=r&255}function Hh(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var oi=class extends Te{next;constructor(t,e){super(Hh,t,e),this.next=void 0}};function Mn(r,t,e){for(;r.hi!==0;)t[e++]=r.lo&127|128,r.lo=(r.lo>>>7|r.hi<<25)>>>0,r.hi>>>=7;for(;r.lo>127;)t[e++]=r.lo&127|128,r.lo=r.lo>>>7;t[e++]=r.lo}function Gr(r,t,e){t[e]=r&255,t[e+1]=r>>>8&255,t[e+2]=r>>>16&255,t[e+3]=r>>>24}function jh(r,t,e){t.set(r,e)}globalThis.Buffer!=null&&(Zr.prototype.bytes=function(r){let t=r.length>>>0;return this.uint32(t),t>0&&this._push($h,t,r),this},Zr.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(Gh,t,r),this});function $h(r,t,e){t.set(r,e)}function Gh(r,t,e){r.length<40?Cs(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set(pf(r),e)}function si(){return new Zr}function Gt(r,t){let e=si();return t.encode(r,e,{lengthDelimited:!1}),e.finish()}function*Zt(r,t,e){let n=Kr(r);yield*t.stream(n,void 0,"$",e)}var zn={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function Kn(r,t,e,n,o){return{name:r,type:t,encode:e,decode:n,stream:o}}function or(r){function t(s){if(r[s.toString()]==null)throw new Error("Invalid enum value");return r[s]}let e=function(i,a){let c=t(i);a.int32(c)},n=function(i){let a=i.int32();return t(a)},o=function*(i){let a=i.int32();yield t(a)};return Kn("enum",zn.VARINT,e,n,o)}function Yt(r,t,e){return Kn("message",zn.LENGTH_DELIMITED,r,t,e)}var Yr=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var bt;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.secp256k1="secp256k1",r.ECDSA="ECDSA"})(bt||(bt={}));var ii;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.secp256k1=2]="secp256k1",r[r.ECDSA=3]="ECDSA"})(ii||(ii={}));(function(r){r.codec=()=>or(ii)})(bt||(bt={}));var Xr;(function(r){let t;r.codec=()=>(t==null&&(t=Yt((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.Type!=null&&(i.uint32(8),bt.codec().encode(s.Type,i)),s.Data!=null&&(i.uint32(18),i.bytes(s.Data)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={},f=i==null?s.len:s.pos+i;for(;s.pos<f;){let d=s.uint32();switch(d>>>3){case 1:{c.Type=bt.codec().decode(s);break}case 2:{c.Data=s.bytes();break}default:{s.skipType(d&7);break}}}return c},function*(s,i,a,c={}){let f=i==null?s.len:s.pos+i;for(;s.pos<f;){let d=s.uint32();switch(d>>>3){case 1:{yield{field:`${a}.Type`,value:bt.codec().decode(s)};break}case 2:{yield{field:`${a}.Data`,value:s.bytes()};break}default:{s.skipType(d&7);break}}}})),t);function e(s){return Gt(s,r.codec())}r.encode=e;function n(s,i){return jt(s,r.codec(),i)}r.decode=n;function o(s,i){return Zt(s,r.codec(),i)}r.stream=o})(Xr||(Xr={}));var ai;(function(r){let t;r.codec=()=>(t==null&&(t=Yt((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.Type!=null&&(i.uint32(8),bt.codec().encode(s.Type,i)),s.Data!=null&&(i.uint32(18),i.bytes(s.Data)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={},f=i==null?s.len:s.pos+i;for(;s.pos<f;){let d=s.uint32();switch(d>>>3){case 1:{c.Type=bt.codec().decode(s);break}case 2:{c.Data=s.bytes();break}default:{s.skipType(d&7);break}}}return c},function*(s,i,a,c={}){let f=i==null?s.len:s.pos+i;for(;s.pos<f;){let d=s.uint32();switch(d>>>3){case 1:{yield{field:`${a}.Type`,value:bt.codec().decode(s)};break}case 2:{yield{field:`${a}.Data`,value:s.bytes()};break}default:{s.skipType(d&7);break}}}})),t);function e(s){return Gt(s,r.codec())}r.encode=e;function n(s,i){return jt(s,r.codec(),i)}r.decode=n;function o(s,i){return Zt(s,r.codec(),i)}r.stream=o})(ai||(ai={}));var qn=class{oHash;iHash;blockLen;outputLen;canXOF=!1;finished=!1;destroyed=!1;constructor(t,e){if(gn(t),wt(e,void 0,"key"),this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let n=this.blockLen,o=new Uint8Array(n);o.set(e.length>n?t.create().update(e).digest():e);for(let s=0;s<o.length;s++)o[s]^=54;this.iHash.update(o),this.oHash=t.create();for(let s=0;s<o.length;s++)o[s]^=106;this.oHash.update(o),Kt(o)}update(t){return Ve(this),this.iHash.update(t),this}digestInto(t){Ve(this),bn(t,this),this.finished=!0;let e=t.subarray(0,this.outputLen);this.iHash.digestInto(e),this.oHash.update(e),this.oHash.digestInto(e),this.destroy()}digest(){let t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||=Object.create(Object.getPrototypeOf(this),{});let{oHash:e,iHash:n,finished:o,destroyed:s,blockLen:i,outputLen:a}=this;return t=t,t.finished=o,t.destroyed=s,t.blockLen=i,t.outputLen=a,t.oHash=e._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},mf=(()=>{let r=((t,e,n)=>new qn(t,e).update(n).digest());return r.create=(t,e)=>new qn(t,e),r})();var gf=(r,t)=>(r+(r>=0?t:-t)/bf)/t;function Yh(r,t,e){$e("scalar",r,Ft,e);let[[n,o],[s,i]]=t,a=gf(i*r,e),c=gf(-o*r,e),f=r-a*n-c*s,d=-a*o-c*i,h=f<Ft,u=d<Ft;h&&(f=-f),u&&(d=-d);let p=Pr(Math.ceil(Ge(e)/2))+he;if(f<Ft||f>=p||d<Ft||d>=p)throw new Error("splitScalar (endomorphism): failed for k");return{k1neg:h,k1:f,k2neg:u,k2:d}}function fi(r){if(!["compact","recovered","der"].includes(r))throw new Error('Signature format must be "compact", "recovered", or "der"');return r}function ci(r,t){It(r);let e={};for(let n of Object.keys(t))e[n]=r[n]===void 0?t[n]:r[n];return _t(e.lowS,"lowS"),_t(e.prehash,"prehash"),e.format!==void 0&&fi(e.format),e}var ui=class extends Error{constructor(t=""){super(t)}},Bt={Err:ui,_tlv:{encode:(r,t)=>{let{Err:e}=Bt;if(At(r,"tag"),r<0||r>255)throw new e("tlv.encode: wrong tag");if(typeof t!="string")throw new TypeError('"data" expected string, got type='+typeof t);if(t.length&1)throw new e("tlv.encode: unpadded data");let n=t.length/2,o=Or(n);if(o.length/2&128)throw new e("tlv.encode: long form length too big");let s=n>127?Or(o.length/2|128):"";return Or(r)+s+o+t},decode(r,t){let{Err:e}=Bt;t=M(t,void 0,"DER data");let n=0;if(r<0||r>255)throw new e("tlv.encode: wrong tag");if(t.length<2||t[n++]!==r)throw new e("tlv.decode: wrong tlv");let o=t[n++],s=!!(o&128),i=0;if(!s)i=o;else{let c=o&127;if(!c)throw new e("tlv.decode(long): indefinite length not supported");if(c>4)throw new e("tlv.decode(long): byte length is too big");let f=t.subarray(n,n+c);if(f.length!==c)throw new e("tlv.decode: length bytes not complete");if(f[0]===0)throw new e("tlv.decode(long): zero leftmost byte");for(let d of f)i=i<<8|d;if(n+=c,i<128)throw new e("tlv.decode(long): not minimal encoding")}let a=t.subarray(n,n+i);if(a.length!==i)throw new e("tlv.decode: wrong value length");return{v:a,l:t.subarray(n+i)}}},_int:{encode(r){let{Err:t}=Bt;if(_n(r),r<Ft)throw new t("integer: negative integers are not allowed");let e=Or(r);if(Number.parseInt(e[0],16)&8&&(e="00"+e),e.length&1)throw new t("unexpected DER parsing assertion: unpadded hex");return e},decode(r){let{Err:t}=Bt;if(r.length<1)throw new t("invalid signature integer: empty");if(r[0]&128)throw new t("invalid signature integer: negative");if(r.length>1&&r[0]===0&&!(r[1]&128))throw new t("invalid signature integer: unnecessary leading zero");return Ee(r)}},toSig(r){let{Err:t,_int:e,_tlv:n}=Bt,o=M(r,void 0,"signature"),{v:s,l:i}=n.decode(48,o);if(i.length)throw new t("invalid signature: left bytes after parsing");let{v:a,l:c}=n.decode(2,s),{v:f,l:d}=n.decode(2,c);if(d.length)throw new t("invalid signature: left bytes after parsing");return{r:e.decode(a),s:e.decode(f)}},hexFromSig(r){let{_tlv:t,_int:e}=Bt,n=t.encode(2,e.encode(r.r)),o=t.encode(2,e.encode(r.s)),s=n+o;return t.encode(48,s)}};Object.freeze(Bt._tlv);Object.freeze(Bt._int);Object.freeze(Bt);var Ft=BigInt(0),he=BigInt(1),bf=BigInt(2),Vn=BigInt(3),Xh=BigInt(4);function yf(r,t={}){let e=Bn("weierstrass",r,t),n=e.Fp,o=e.Fn,s=e.CURVE,{h:i,n:a}=s;It(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object"});let{endo:c,allowInfinityPoint:f}=t;if(c&&(!n.is0(s.a)||typeof c.beta!="bigint"||!Array.isArray(c.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let d=wf(n,o);function h(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function u(k,y,E){if(f&&y.is0())return Uint8Array.of(0);let{x:I,y:v}=y.toAffine(),S=n.toBytes(I);if(_t(E,"isCompressed"),E){h();let T=!n.isOdd(v);return rt(xf(T),S)}else return rt(Uint8Array.of(4),S,n.toBytes(v))}function p(k){M(k,void 0,"Point");let{publicKey:y,publicKeyUncompressed:E}=d,I=k.length,v=k[0],S=k.subarray(1);if(f&&I===1&&v===0)return{x:n.ZERO,y:n.ZERO};if(I===y&&(v===2||v===3)){let T=n.fromBytes(S);if(!n.isValid(T))throw new Error("bad point: is not on curve, wrong x");let R=m(T),D;try{D=n.sqrt(R)}catch(U){let z=U instanceof Error?": "+U.message:"";throw new Error("bad point: is not on curve, sqrt error"+z)}h();let O=n.isOdd(D);return(v&1)===1!==O&&(D=n.neg(D)),{x:T,y:D}}else if(I===E&&v===4){let T=n.BYTES,R=n.fromBytes(S.subarray(0,T)),D=n.fromBytes(S.subarray(T,T*2));if(!l(R,D))throw new Error("bad point: is not on curve");return{x:R,y:D}}else throw new Error(`bad point: got length ${I}, expected compressed=${y} or uncompressed=${E}`)}let b=t.toBytes===void 0?u:t.toBytes,x=t.fromBytes===void 0?p:t.fromBytes;function m(k){let y=n.sqr(k),E=n.mul(y,k);return n.add(n.add(E,n.mul(k,s.a)),s.b)}function l(k,y){let E=n.sqr(y),I=m(k);return n.eql(E,I)}if(!l(s.Gx,s.Gy))throw new Error("bad curve params: generator point");let g=n.mul(n.pow(s.a,Vn),Xh),w=n.mul(n.sqr(s.b),BigInt(27));if(n.is0(n.add(g,w)))throw new Error("bad curve params: a or b");function _(k,y,E=!1){if(!n.isValid(y)||E&&n.is0(y))throw new Error(`bad point coordinate ${k}`);return y}function A(k){if(!(k instanceof B))throw new Error("Weierstrass Point expected")}function C(k){if(!c||!c.basises)throw new Error("no endo");return Yh(k,c.basises,o.ORDER)}function L(k,y,E,I,v){return E=new B(n.mul(E.X,k),E.Y,E.Z),y=Nr(I,y),E=Nr(v,E),y.add(E)}class B{static BASE=new B(s.Gx,s.Gy,n.ONE);static ZERO=new B(n.ZERO,n.ONE,n.ZERO);static Fp=n;static Fn=o;X;Y;Z;constructor(y,E,I){this.X=_("x",y),this.Y=_("y",E,!0),this.Z=_("z",I),Object.freeze(this)}static CURVE(){return s}static fromAffine(y){let{x:E,y:I}=y||{};if(!y||!n.isValid(E)||!n.isValid(I))throw new Error("invalid affine point");if(y instanceof B)throw new Error("projective point not allowed");return n.is0(E)&&n.is0(I)?B.ZERO:new B(E,I,n.ONE)}static fromBytes(y){let E=B.fromAffine(x(M(y,void 0,"point")));return E.assertValidity(),E}static fromHex(y){return B.fromBytes(je(y))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(y=8,E=!0){return q.createCache(this,y),E||this.multiply(Vn),this}assertValidity(){let y=this;if(y.is0()){if(t.allowInfinityPoint&&n.is0(y.X)&&n.eql(y.Y,n.ONE)&&n.is0(y.Z))return;throw new Error("bad point: ZERO")}let{x:E,y:I}=y.toAffine();if(!n.isValid(E)||!n.isValid(I))throw new Error("bad point: x or y not field elements");if(!l(E,I))throw new Error("bad point: equation left != right");if(!y.isTorsionFree())throw new Error("bad point: not in prime-order subgroup")}hasEvenY(){let{y}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(y)}equals(y){A(y);let{X:E,Y:I,Z:v}=this,{X:S,Y:T,Z:R}=y,D=n.eql(n.mul(E,R),n.mul(S,v)),O=n.eql(n.mul(I,R),n.mul(T,v));return D&&O}negate(){return new B(this.X,n.neg(this.Y),this.Z)}double(){let{a:y,b:E}=s,I=n.mul(E,Vn),{X:v,Y:S,Z:T}=this,R=n.ZERO,D=n.ZERO,O=n.ZERO,F=n.mul(v,v),U=n.mul(S,S),z=n.mul(T,T),N=n.mul(v,S);return N=n.add(N,N),O=n.mul(v,T),O=n.add(O,O),R=n.mul(y,O),D=n.mul(I,z),D=n.add(R,D),R=n.sub(U,D),D=n.add(U,D),D=n.mul(R,D),R=n.mul(N,R),O=n.mul(I,O),z=n.mul(y,z),N=n.sub(F,z),N=n.mul(y,N),N=n.add(N,O),O=n.add(F,F),F=n.add(O,F),F=n.add(F,z),F=n.mul(F,N),D=n.add(D,F),z=n.mul(S,T),z=n.add(z,z),F=n.mul(z,N),R=n.sub(R,F),O=n.mul(z,U),O=n.add(O,O),O=n.add(O,O),new B(R,D,O)}add(y){A(y);let{X:E,Y:I,Z:v}=this,{X:S,Y:T,Z:R}=y,D=n.ZERO,O=n.ZERO,F=n.ZERO,U=s.a,z=n.mul(s.b,Vn),N=n.mul(E,S),et=n.mul(I,T),nt=n.mul(v,R),ot=n.add(E,I),W=n.add(S,T);ot=n.mul(ot,W),W=n.add(N,et),ot=n.sub(ot,W),W=n.add(E,v);let yt=n.add(S,R);return W=n.mul(W,yt),yt=n.add(N,nt),W=n.sub(W,yt),yt=n.add(I,v),D=n.add(T,R),yt=n.mul(yt,D),D=n.add(et,nt),yt=n.sub(yt,D),F=n.mul(U,W),D=n.mul(z,nt),F=n.add(D,F),D=n.sub(et,F),F=n.add(et,F),O=n.mul(D,F),et=n.add(N,N),et=n.add(et,N),nt=n.mul(U,nt),W=n.mul(z,W),et=n.add(et,nt),nt=n.sub(N,nt),nt=n.mul(U,nt),W=n.add(W,nt),N=n.mul(et,W),O=n.add(O,N),N=n.mul(yt,W),D=n.mul(ot,D),D=n.sub(D,N),N=n.mul(ot,et),F=n.mul(yt,F),F=n.add(F,N),new B(D,O,F)}subtract(y){return A(y),this.add(y.negate())}is0(){return this.equals(B.ZERO)}multiply(y){let{endo:E}=t;if(!o.isValidNot0(y))throw new RangeError("invalid scalar: out of range");let I,v,S=T=>q.cached(this,T,R=>_e(B,R));if(E){let{k1neg:T,k1:R,k2neg:D,k2:O}=C(y),{p:F,f:U}=S(R),{p:z,f:N}=S(O);v=U.add(N),I=L(E.beta,F,z,T,D)}else{let{p:T,f:R}=S(y);I=T,v=R}return _e(B,[I,v])[0]}multiplyUnsafe(y){let{endo:E}=t,I=this,v=y;if(!o.isValid(v))throw new RangeError("invalid scalar: out of range");if(v===Ft||I.is0())return B.ZERO;if(v===he)return I;if(q.hasCache(this))return this.multiply(v);if(E){let{k1neg:S,k1:T,k2neg:R,k2:D}=C(v),{p1:O,p2:F}=yc(B,I,T,D);return L(E.beta,O,F,S,R)}else return q.unsafe(I,v)}toAffine(y){let E=this,I=y,{X:v,Y:S,Z:T}=E;if(n.eql(T,n.ONE))return{x:v,y:S};let R=E.is0();I==null&&(I=R?n.ONE:n.inv(T));let D=n.mul(v,I),O=n.mul(S,I),F=n.mul(T,I);if(R)return{x:n.ZERO,y:n.ZERO};if(!n.eql(F,n.ONE))throw new Error("invZ was invalid");return{x:D,y:O}}isTorsionFree(){let{isTorsionFree:y}=t;return i===he?!0:y?y(B,this):q.unsafe(this,a).is0()}clearCofactor(){let{clearCofactor:y}=t;return i===he?this:y?y(B,this):this.multiplyUnsafe(i)}isSmallOrder(){return i===he?this.is0():this.clearCofactor().is0()}toBytes(y=!0){return _t(y,"isCompressed"),this.assertValidity(),b(B,this,y)}toHex(y=!0){return He(this.toBytes(y))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let P=o.BITS,q=new Xe(B,t.endo?Math.ceil(P/2):P);return P>=8&&B.BASE.precompute(8),Object.freeze(B.prototype),Object.freeze(B),B}function xf(r){return Uint8Array.of(r?2:3)}function wf(r,t){return{secretKey:t.BYTES,publicKey:1+r.BYTES,publicKeyUncompressed:1+2*r.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function Wh(r,t={}){let{Fn:e}=r,n=t.randomBytes===void 0?Rr:t.randomBytes,o=Object.assign(wf(r.Fp,e),{seed:Math.max(hs(e.ORDER),16)});function s(p){try{let b=e.fromBytes(p);return e.isValidNot0(b)}catch{return!1}}function i(p,b){let{publicKey:x,publicKeyUncompressed:m}=o;try{let l=p.length;return b===!0&&l!==x||b===!1&&l!==m?!1:!!r.fromBytes(p)}catch{return!1}}function a(p){return p=p===void 0?n(o.seed):p,ps(M(p,o.seed,"seed"),e.ORDER)}function c(p,b=!0){return r.BASE.multiply(e.fromBytes(p)).toBytes(b)}function f(p){let{secretKey:b,publicKey:x,publicKeyUncompressed:m}=o,l=e._lengths;if(!we(p))return;let g=M(p,void 0,"key").length,w=g===x||g===m,_=g===b||!!l?.includes(g);if(!(w&&_))return w}function d(p,b,x=!0){if(f(p)===!0)throw new Error("first arg must be private key");if(f(b)===!1)throw new Error("second arg must be public key");let m=e.fromBytes(p);return r.fromBytes(b).multiply(m).toBytes(x)}let h={isValidSecretKey:s,isValidPublicKey:i,randomSecretKey:a},u=Ln(a,c);return Object.freeze(h),Object.freeze(o),Object.freeze({getPublicKey:c,getSharedSecret:d,keygen:u,Point:r,utils:h,lengths:o})}function Ef(r,t,e={}){let n=t;gn(n),It(e,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"}),e=Object.assign({},e);let o=e.randomBytes===void 0?Rr:e.randomBytes,s=e.hmac===void 0?(v,S)=>mf(n,v,S):e.hmac,{Fp:i,Fn:a}=r,{ORDER:c,BITS:f}=a,{keygen:d,getPublicKey:h,getSharedSecret:u,utils:p,lengths:b}=Wh(r,e),x={prehash:!0,lowS:typeof e.lowS=="boolean"?e.lowS:!0,format:"compact",extraEntropy:!1},m=c*bf+he<i.ORDER;function l(v){let S=c>>he;return v>S}function g(v,S){if(!a.isValidNot0(S))throw new Error(`invalid signature ${v}: out of range 1..Point.Fn.ORDER`);return S}function w(){if(m)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function _(v,S){fi(S);let T=b.signature,R=S==="compact"?T:S==="recovered"?T+1:void 0;return M(v,R)}class A{r;s;recovery;constructor(S,T,R){if(this.r=g("r",S),this.s=g("s",T),R!=null){if(w(),![0,1,2,3].includes(R))throw new Error("invalid recovery id");this.recovery=R}Object.freeze(this)}static fromBytes(S,T=x.format){_(S,T);let R;if(T==="der"){let{r:U,s:z}=Bt.toSig(M(S));return new A(U,z)}T==="recovered"&&(R=S[0],T="compact",S=S.subarray(1));let D=b.signature/2,O=S.subarray(0,D),F=S.subarray(D,D*2);return new A(a.fromBytes(O),a.fromBytes(F),R)}static fromHex(S,T){return this.fromBytes(je(S),T)}assertRecovery(){let{recovery:S}=this;if(S==null)throw new Error("invalid recovery id: must be present");return S}addRecoveryBit(S){return new A(this.r,this.s,S)}recoverPublicKey(S){let{r:T,s:R}=this,D=this.assertRecovery(),O=D===2||D===3?T+c:T;if(!i.isValid(O))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let F=i.toBytes(O),U=r.fromBytes(rt(xf((D&1)===0),F)),z=a.inv(O),N=L(M(S,void 0,"msgHash")),et=a.create(-N*z),nt=a.create(R*z),ot=r.BASE.multiplyUnsafe(et).add(U.multiplyUnsafe(nt));if(ot.is0())throw new Error("invalid recovery: point at infinify");return ot.assertValidity(),ot}hasHighS(){return l(this.s)}toBytes(S=x.format){if(fi(S),S==="der")return je(Bt.hexFromSig(this));let{r:T,s:R}=this,D=a.toBytes(T),O=a.toBytes(R);return S==="recovered"?(w(),rt(Uint8Array.of(this.assertRecovery()),D,O)):rt(D,O)}toHex(S){return He(this.toBytes(S))}}Object.freeze(A.prototype),Object.freeze(A);let C=e.bits2int===void 0?function(S){if(S.length>8192)throw new Error("input is too large");let T=Ee(S),R=S.length*8-f;return R>0?T>>BigInt(R):T}:e.bits2int,L=e.bits2int_modN===void 0?function(S){return a.create(C(S))}:e.bits2int_modN,B=Pr(f);function P(v){return $e("num < 2^"+f,v,Ft,B),a.toBytes(v)}function q(v,S){return M(v,void 0,"message"),S?M(n(v),void 0,"prehashed message"):v}function k(v,S,T){let{lowS:R,prehash:D,extraEntropy:O}=ci(T,x);v=q(v,D);let F=L(v),U=a.fromBytes(S);if(!a.isValidNot0(U))throw new Error("invalid private key");let z=[P(U),P(F)];if(O!=null&&O!==!1){let ot=O===!0?o(b.secretKey):O;z.push(M(ot,void 0,"extraEntropy"))}let N=rt(...z),et=F;function nt(ot){let W=C(ot);if(!a.isValidNot0(W))return;let yt=a.inv(W),Pe=r.BASE.multiply(W).toAffine(),br=a.create(Pe.x);if(br===Ft)return;let an=a.create(yt*a.create(et+br*U));if(an===Ft)return;let ra=(Pe.x===br?0:2)|Number(Pe.y&he),na=an;return R&&l(an)&&(na=a.neg(an),ra^=1),new A(br,na,m?void 0:ra)}return{seed:N,k2sig:nt}}function y(v,S,T={}){let{seed:R,k2sig:D}=k(v,S,T);return ec(n.outputLen,a.BYTES,s)(R,D).toBytes(T.format)}function E(v,S,T,R={}){let{lowS:D,prehash:O,format:F}=ci(R,x);if(T=M(T,void 0,"publicKey"),S=q(S,O),!we(v)){let U=v instanceof A?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+U)}_(v,F);try{let U=A.fromBytes(v,F),z=r.fromBytes(T);if(D&&U.hasHighS())return!1;let{r:N,s:et}=U,nt=L(S),ot=a.inv(et),W=a.create(nt*ot),yt=a.create(N*ot),Pe=r.BASE.multiplyUnsafe(W).add(z.multiplyUnsafe(yt));return Pe.is0()?!1:a.create(Pe.x)===N}catch{return!1}}function I(v,S,T={}){let{prehash:R}=ci(T,x);return S=q(S,R),A.fromBytes(v,"recovered").recoverPublicKey(S).toBytes()}return Object.freeze({keygen:d,getPublicKey:h,getSharedSecret:u,utils:p,lengths:b,Point:r,sign:y,verify:E,recoverPublicKey:I,Signature:A,hash:n})}var di={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},Qh={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var Sf=BigInt(2);function Jh(r){let t=di.p,e=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),a=BigInt(44),c=BigInt(88),f=r*r*r%t,d=f*f*r%t,h=j(d,e,t)*d%t,u=j(h,e,t)*d%t,p=j(u,Sf,t)*f%t,b=j(p,o,t)*p%t,x=j(b,s,t)*b%t,m=j(x,a,t)*x%t,l=j(m,c,t)*m%t,g=j(l,a,t)*x%t,w=j(g,e,t)*d%t,_=j(w,i,t)*b%t,A=j(_,n,t)*f%t,C=j(A,Sf,t);if(!li.eql(li.sqr(C),r))throw new Error("Cannot find square root");return C}var li=Ze(di.p,{sqrt:Jh}),tp=yf(di,{Fp:li,endo:Qh}),sr=Ef(tp,Qa);function vf(r,t,e,n){let o=_r.digest(e instanceof Uint8Array?e:e.subarray());if(Fn(o))return o.then(({digest:s})=>(n?.signal?.throwIfAborted(),sr.verify(t,s,r,{prehash:!1,format:"der"}))).catch(s=>{throw s.name==="AbortError"?s:new Mr(String(s))});try{return n?.signal?.throwIfAborted(),sr.verify(t,o.digest,r,{prehash:!1,format:"der"})}catch(s){throw new Mr(String(s))}}var Hn=class{type="secp256k1";raw;_key;constructor(t){this._key=Af(t),this.raw=_f(this._key)}toMultihash(){return St.digest(qe(this))}toCID(){return lt.createV1(114,this.toMultihash())}toString(){return Q.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:xt(this.raw,t.raw)}verify(t,e,n){return vf(this._key,e,t,n)}};function If(r){return new Hn(r)}function _f(r){return sr.Point.fromBytes(r).toBytes()}function Af(r){try{return sr.Point.fromBytes(r),r}catch(t){throw new fn(String(t))}}function Tf(r){let{Type:t,Data:e}=Xr.decode(r.digest),n=e??new Uint8Array;switch(t){case bt.Ed25519:return Lc(n);case bt.secp256k1:return If(n);case bt.ECDSA:return Pa(n);default:throw new yr}}function qe(r){return Xr.encode({Type:bt[r.type],Data:r.raw})}var Bf=Symbol.for("nodejs.util.inspect.custom"),ep=114,Wr=class{type;multihash;publicKey;string;constructor(t){this.type=t.type,this.multihash=t.multihash,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[wo]=!0;toString(){return this.string==null&&(this.string=Q.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return lt.createV1(ep,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return xt(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return xt(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[Bf](){return`PeerId(${this.toString()})`}},jn=class extends Wr{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},$n=class extends Wr{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},Gn=class extends Wr{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},rp=2336,Zn=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=St.digest(Z(this.url))}[Bf](){return`PeerId(${this.url})`}[wo]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return lt.createV1(rp,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=tt(t)),t.toString()===this.toString())}};function Yn(r){if(op(r))return new jn({multihash:r});if(np(r))try{let t=Tf(r);if(t.type==="Ed25519")return new $n({multihash:r,publicKey:t});if(t.type==="secp256k1")return new Gn({multihash:r,publicKey:t})}catch{let e=tt(r.digest);return new Zn(new URL(e))}throw new un("Supplied PeerID Multihash is invalid")}function np(r){return r.code===St.code}function op(r){return r.code===_r.code}function hi(r,t){let e={[Symbol.iterator]:()=>e,next:()=>{let n=r.next(),o=n.value;return n.done===!0||o==null?{done:!0,value:void 0}:{done:!1,value:t(o)}}};return e}function Xn(r){let t=ge(Q.decode(`z${r}`));return Yn(t)}var Wn=class r{set;constructor(t){if(this.set=new Set,t!=null)for(let e of t)this.set.add(e.toString())}get size(){return this.set.size}[Symbol.iterator](){return this.values()}add(t){this.set.add(t.toString())}clear(){this.set.clear()}delete(t){this.set.delete(t.toString())}entries(){return hi(this.set.entries(),t=>{let e=Xn(t[0]);return[e,e]})}forEach(t){this.set.forEach(e=>{let n=Xn(e);t(n,n,this)})}has(t){return this.set.has(t.toString())}values(){return hi(this.set.values(),t=>Xn(t))}intersection(t){let e=new r;for(let n of t)this.has(n)&&e.add(n);return e}difference(t){let e=new r;for(let n of this)t.has(n)||e.add(n);return e}union(t){let e=new r;for(let n of t)e.add(n);for(let n of this)e.add(n);return e}};function pi(){return new Wn}var mi={32:16777619n,64:1099511628211n,128:309485009821345068724781371n,256:374144419156711147060143317175368453031918731002211n,512:35835915874844867368919076489095108449946327955754392558399825615420669938882575126094039892345713852759n,1024:5016456510113118655434598811035278955030765345404790744303017523831112055108147451509157692220295382716162651878526895249385292291816524375083746691371804094271873160484737966720260389217684476157468082573n},Lf={32:2166136261n,64:14695981039346656037n,128:144066263297769815596495629667062367629n,256:100029257958052580907070968620625704837092796014241193945225284501741471925557n,512:9659303129496669498009435400716310466090418745672637896108374329434462657994582932197716438449813051892206539805784495328239340083876191928701583869517785n,1024:14197795064947621068722070641403218320880622795441933960878474914617582723252296732303717722150864096521202355549365628174669108571814760471015076148029755969804077320157692458563003215304957150157403644460363550505412711285966361610267868082893823963790439336411086884584107735010676915n},Cf=new globalThis.TextEncoder;function sp(r,t){let e=mi[t],n=Lf[t];for(let o=0;o<r.length;o++)n^=BigInt(r[o]),n=BigInt.asUintN(t,n*e);return n}function ip(r,t,e){if(e.length===0)throw new Error("The `utf8Buffer` option must have a length greater than zero");let n=mi[t],o=Lf[t],s=r;for(;s.length>0;){let i=Cf.encodeInto(s,e);s=s.slice(i.read);for(let a=0;a<i.written;a++)o^=BigInt(e[a]),o=BigInt.asUintN(t,o*n)}return o}function gi(r,{size:t=32,utf8Buffer:e}={}){if(!mi[t])throw new Error("The `size` option must be one of 32, 64, 128, 256, 512, or 1024");if(typeof r=="string"){if(e)return ip(r,t,e);r=Cf.encode(r)}return sp(r,t)}var Qr={hash:r=>Number(gi(r,{size:32})),hashV:(r,t)=>ap(Qr.hash(r,t))};function ap(r){let t=r.toString(16);return t.length%2===1&&(t=`0${t}`),Z(t,"base16")}var bi=64,Lt=class{fp;h;seed;constructor(t,e,n,o=2){if(o>bi)throw new TypeError("Invalid Fingerprint Size");let s=e.hashV(t,n),i=Vo(o);for(let a=0;a<i.length;a++)i[a]=s[a];i.length===0&&(i[0]=7),this.fp=i,this.h=e,this.seed=n}hash(){return this.h.hash(this.fp,this.seed)}equals(t){return t?.fp instanceof Uint8Array?xt(this.fp,t.fp):!1}};function Be(r,t){return Math.floor(Math.random()*(t-r))+r}var Le=class{contents;constructor(t){this.contents=new Array(t).fill(null)}has(t){if(!(t instanceof Lt))throw new TypeError("Invalid Fingerprint");return this.contents.some(e=>t.equals(e))}add(t){if(!(t instanceof Lt))throw new TypeError("Invalid Fingerprint");for(let e=0;e<this.contents.length;e++)if(this.contents[e]==null)return this.contents[e]=t,!0;return!0}swap(t){if(!(t instanceof Lt))throw new TypeError("Invalid Fingerprint");let e=Be(0,this.contents.length-1),n=this.contents[e];return this.contents[e]=t,n}remove(t){if(!(t instanceof Lt))throw new TypeError("Invalid Fingerprint");let e=this.contents.findIndex(n=>t.equals(n));return e>-1?(this.contents[e]=null,!0):!1}};var cp=500,Jr=class{bucketSize;filterSize;fingerprintSize;buckets;count;hash;seed;constructor(t){this.filterSize=t.filterSize,this.bucketSize=t.bucketSize??4,this.fingerprintSize=t.fingerprintSize??2,this.count=0,this.buckets=[],this.hash=t.hash??Qr,this.seed=t.seed??Be(0,Math.pow(2,10))}add(t){typeof t=="string"&&(t=Z(t));let e=new Lt(t,this.hash,this.seed,this.fingerprintSize),n=this.hash.hash(t,this.seed)%this.filterSize,o=(n^e.hash())%this.filterSize;if(this.buckets[n]==null&&(this.buckets[n]=new Le(this.bucketSize)),this.buckets[o]==null&&(this.buckets[o]=new Le(this.bucketSize)),this.buckets[n].add(e)||this.buckets[o].add(e))return this.count++,!0;let s=[n,o],i=s[Be(0,s.length-1)];this.buckets[i]==null&&(this.buckets[i]=new Le(this.bucketSize));for(let a=0;a<cp;a++){let c=this.buckets[i].swap(e);if(c!=null&&(i=(i^c.hash())%this.filterSize,this.buckets[i]==null&&(this.buckets[i]=new Le(this.bucketSize)),this.buckets[i].add(c)))return this.count++,!0}return!1}has(t){typeof t=="string"&&(t=Z(t));let e=new Lt(t,this.hash,this.seed,this.fingerprintSize),n=this.hash.hash(t,this.seed)%this.filterSize,o=this.buckets[n]?.has(e)??!1;if(o)return o;let s=(n^e.hash())%this.filterSize;return this.buckets[s]?.has(e)??!1}remove(t){typeof t=="string"&&(t=Z(t));let e=new Lt(t,this.hash,this.seed,this.fingerprintSize),n=this.hash.hash(t,this.seed)%this.filterSize,o=this.buckets[n]?.remove(e)??!1;if(o)return this.count--,o;let s=(n^e.hash())%this.filterSize,i=this.buckets[s]?.remove(e)??!1;return i&&this.count--,i}get reliable(){return Math.floor(100*(this.count/this.filterSize))<=90}},fp={1:.5,2:.84,4:.95,8:.98};function up(r=.001){return r>.002?2:r>1e-5?4:8}function Df(r,t=.001){let e=up(t),n=fp[e],o=Math.round(r/n),s=Math.min(Math.ceil(Math.log2(1/t)+Math.log2(2*e)),bi);return{filterSize:o,bucketSize:e,fingerprintSize:s}}var Qn=class{filterSize;bucketSize;fingerprintSize;scale;filterSeries;hash;seed;constructor(t){this.bucketSize=t.bucketSize??4,this.filterSize=t.filterSize??(1<<18)/this.bucketSize,this.fingerprintSize=t.fingerprintSize??2,this.scale=t.scale??2,this.hash=t.hash??Qr,this.seed=t.seed??Be(0,Math.pow(2,10)),this.filterSeries=[new Jr({filterSize:this.filterSize,bucketSize:this.bucketSize,fingerprintSize:this.fingerprintSize,hash:this.hash,seed:this.seed})]}add(t){if(typeof t=="string"&&(t=Z(t)),this.has(t))return!0;let e=this.filterSeries.find(n=>n.reliable);if(e==null){let n=this.filterSize*Math.pow(this.scale,this.filterSeries.length);e=new Jr({filterSize:n,bucketSize:this.bucketSize,fingerprintSize:this.fingerprintSize,hash:this.hash,seed:this.seed}),this.filterSeries.push(e)}return e.add(t)}has(t){typeof t=="string"&&(t=Z(t));for(let e=0;e<this.filterSeries.length;e++)if(this.filterSeries[e].has(t))return!0;return!1}remove(t){typeof t=="string"&&(t=Z(t));for(let e=0;e<this.filterSeries.length;e++)if(this.filterSeries[e].remove(t))return!0;return!1}get count(){return this.filterSeries.reduce((t,e)=>t+e.count,0)}};function yi(r,t=.001,e){return new Qn({...Df(r,t),...e??{}})}function lp(r){let t=r.getComponents(),e={},n=0;return t[n]?.name==="ip6zone"&&(e.zone=`${t[n].value}`,n++),t[n]?.name==="ip4"||t[n]?.name==="ip6"||t[n]?.name==="dns"||t[n]?.name==="dns4"||t[n]?.name==="dns6"?(e.type=t[n].name,e.host=t[n].value,n++):t[n]?.name==="dnsaddr"&&(e.type=t[n].name,e.host=`_dnsaddr.${t[n].value}`,n++),(t[n]?.name==="tcp"||t[n]?.name==="udp")&&(e.protocol=t[n].name==="tcp"?"tcp":"udp",e.port=parseInt(`${t[n].value}`),n++),t[n]?.name==="ipcidr"&&(e.type==="ip4"?e.cidr=parseInt(`${t[n].value}`):e.type==="ip6"&&(e.cidr=`${t[n].value}`),n++),e.type==null||e.host==null?null:(t[n]?.name==="tls"&&t[n+1]?.name==="sni"&&(e.sni=t[n+1].value,n+=2),e)}function Ct(r){let t=lp(r);if(t==null)throw new mt(`Multiaddr ${r} was not an IPv4, IPv6, DNS, DNS4, DNS6 or DNSADDR address`);return t}var Jn=class{index=0;input="";new(t){return this.index=0,this.input=t,this}readAtomically(t){let e=this.index,n=t();return n===void 0&&(this.index=e),n}parseWith(t){let e=t();if(this.index===this.input.length)return e}peekChar(){if(!(this.index>=this.input.length))return this.input[this.index]}readChar(){if(!(this.index>=this.input.length))return this.input[this.index++]}readGivenChar(t){return this.readAtomically(()=>{let e=this.readChar();if(e===t)return e})}readSeparator(t,e,n){return this.readAtomically(()=>{if(!(e>0&&this.readGivenChar(t)===void 0))return n()})}readNumber(t,e,n,o){return this.readAtomically(()=>{let s=0,i=0,a=this.peekChar();if(a===void 0)return;let c=a==="0",f=2**(8*o)-1;for(;;){let d=this.readAtomically(()=>{let h=this.readChar();if(h===void 0)return;let u=Number.parseInt(h,t);if(!Number.isNaN(u))return u});if(d===void 0)break;if(s*=t,s+=d,s>f||(i+=1,e!==void 0&&i>e))return}if(i!==0)return!n&&c&&i>1?void 0:s})}readIPv4Addr(){return this.readAtomically(()=>{let t=new Uint8Array(4);for(let e=0;e<t.length;e++){let n=this.readSeparator(".",e,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;t[e]=n}return t})}readIPv6Addr(){let t=e=>{for(let n=0;n<e.length/2;n++){let o=n*2;if(n<e.length-3){let i=this.readSeparator(":",n,()=>this.readIPv4Addr());if(i!==void 0)return e[o]=i[0],e[o+1]=i[1],e[o+2]=i[2],e[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];e[o]=s>>8,e[o+1]=s&255}return[e.length,!1]};return this.readAtomically(()=>{let e=new Uint8Array(16),[n,o]=t(e);if(n===16)return e;if(o||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let s=new Uint8Array(14),i=16-(n+2),[a]=t(s.subarray(0,i));return e.set(s.subarray(0,a),16-a),e})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var Rf=45,dp=15,ir=new Jn;function to(r){if(!(r.length>dp))return ir.new(r).parseWith(()=>ir.readIPv4Addr())}function eo(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>Rf))return ir.new(r).parseWith(()=>ir.readIPv6Addr())}function ar(r,t=!1){if(r.includes("%")&&(r=r.split("%")[0]),r.length>Rf)return;let e=ir.new(r).parseWith(()=>ir.readIPAddr());if(e)return t&&e.length===4?Uint8Array.from([0,0,0,0,0,0,0,0,0,0,255,255,e[0],e[1],e[2],e[3]]):e}function Of(r,t,e){let n=0;for(let o of r)if(!(n<t)){if(n>e)break;if(o!==255)return!1;n++}return!0}function Ff(r,t,e,n){let o=0;for(let s of r)if(!(o<e)){if(o>n)break;if(s!==t[o])return!1;o++}return!0}function xi(r){switch(r.length){case Ce:return r.join(".");case De:{let t=[];for(let e=0;e<r.length;e++)e%2===0&&t.push(r[e].toString(16).padStart(2,"0")+r[e+1].toString(16).padStart(2,"0"));return t.join(":")}default:throw new Error("Invalid ip length")}}function Pf(r){let t=0;for(let[e,n]of r.entries()){if(n===255){t+=8;continue}for(;(n&128)!=0;)t++,n=n<<1;if((n&128)!=0)return-1;for(let o=e+1;o<r.length;o++)if(r[o]!=0)return-1;break}return t}function kf(r){let t="0x";for(let e of r)t+=(e>>4).toString(16)+(e&15).toString(16);return t}var Ce=4,De=16,z1=parseInt("0xFFFF",16),hp=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function tn(r,t){t.length===De&&r.length===Ce&&Of(t,0,11)&&(t=t.slice(12)),t.length===Ce&&r.length===De&&Ff(r,hp,0,11)&&(r=r.slice(12));let e=r.length;if(e!=t.length)throw new Error("Failed to mask ip");let n=new Uint8Array(e);for(let o=0;o<e;o++)n[o]=r[o]&t[o];return n}function Nf(r,t){if(typeof t=="string"&&(t=ar(t)),t==null)throw new Error("Invalid ip");if(t.length!==r.network.length)return!1;for(let e=0;e<t.length;e++)if((r.network[e]&r.mask[e])!==(t[e]&r.mask[e]))return!1;return!0}function wi(r){let[t,e]=r.split("/");if(!t||!e)throw new Error("Failed to parse given CIDR: "+r);let n=Ce,o=to(t);if(o==null&&(n=De,o=eo(t),o==null))throw new Error("Failed to parse given CIDR: "+r);let s=parseInt(e,10);if(Number.isNaN(s)||String(s).length!==e.length||s<0||s>n*8)throw new Error("Failed to parse given CIDR: "+r);let i=Ei(s,8*n);return{network:tn(o,i),mask:i}}function Ei(r,t){if(t!==8*Ce&&t!==8*De)throw new Error("Invalid CIDR mask");if(r<0||r>t)throw new Error("Invalid CIDR mask");let e=t/8,n=new Uint8Array(e);for(let o=0;o<e;o++){if(r>=8){n[o]=255,r-=8;continue}n[o]=255-(255>>r),r=0}return n}var en=class{constructor(t,e){if(e==null)({network:this.network,mask:this.mask}=wi(t));else{let n=ar(t);if(n==null)throw new Error("Failed to parse network");e=String(e);let o=parseInt(e,10);if(Number.isNaN(o)||String(o).length!==e.length||o<0||o>n.length*8){let s=ar(e);if(s==null)throw new Error("Failed to parse mask");this.mask=s}else this.mask=Ei(o,8*n.length);this.network=tn(n,this.mask)}}contains(t){return Nf({network:this.network,mask:this.mask},t)}toString(){let t=Pf(this.mask),e=t!==-1?String(t):kf(this.mask);return xi(this.network)+"/"+e}};function Uf(r,t){return new en(r).contains(t)}function Mf(r){try{let t=Ct(r);return t.type==="ip6"?Uf("2000::/3",t.host):!1}catch{return!1}}function cr(r){return!!to(r)}function ro(r){return!!eo(r)}var Vf=xu(qf(),1),wp=["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"],Ep=wp.map(r=>new Vf.Netmask(r));function Bi(r){for(let t of Ep)if(t.contains(r))return!0;return!1}function Sp(r){return/^::ffff:([0-9a-fA-F]{1,4}):([0-9a-fA-F]{1,4})$/.test(r)}function vp(r){let t=r.split(":");if(t.length<2)return!1;let e=t[t.length-1].padStart(4,"0"),n=t[t.length-2].padStart(4,"0"),o=`${parseInt(n.substring(0,2),16)}.${parseInt(n.substring(2),16)}.${parseInt(e.substring(0,2),16)}.${parseInt(e.substring(2),16)}`;return Bi(o)}function _p(r){return/^::ffff:([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(r)}function Ap(r){let t=r.split(":"),e=t[t.length-1];return Bi(e)}function Ip(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 Hf(r){if(cr(r))return Bi(r);if(Sp(r))return vp(r);if(_p(r))return Ap(r);if(ro(r))return Ip(r)}function Li(r){try{let t=Ct(r);switch(t.type){case"ip4":case"ip6":return Hf(t.host)??!1;default:return t.host==="localhost"}}catch{return!1}}var Tp=Math.pow(2,7),Bp=Math.pow(2,14),Lp=Math.pow(2,21),Ci=Math.pow(2,28),Di=Math.pow(2,35),Ri=Math.pow(2,42),Oi=Math.pow(2,49),$=128,ht=127;function dr(r){if(r<Tp)return 1;if(r<Bp)return 2;if(r<Lp)return 3;if(r<Ci)return 4;if(r<Di)return 5;if(r<Ri)return 6;if(r<Oi)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Fi(r,t,e=0){switch(dr(r)){case 8:t[e++]=r&255|$,r/=128;case 7:t[e++]=r&255|$,r/=128;case 6:t[e++]=r&255|$,r/=128;case 5:t[e++]=r&255|$,r/=128;case 4:t[e++]=r&255|$,r>>>=7;case 3:t[e++]=r&255|$,r>>>=7;case 2:t[e++]=r&255|$,r>>>=7;case 1:{t[e++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return t}function Cp(r,t){let e=r[t],n=0;if(n+=e&ht,e<$||(e=r[t+1],n+=(e&ht)<<7,e<$)||(e=r[t+2],n+=(e&ht)<<14,e<$)||(e=r[t+3],n+=(e&ht)<<21,e<$)||(e=r[t+4],n+=(e&ht)*Ci,e<$)||(e=r[t+5],n+=(e&ht)*Di,e<$)||(e=r[t+6],n+=(e&ht)*Ri,e<$)||(e=r[t+7],n+=(e&ht)*Oi,e<$))return n;throw new RangeError("Could not decode varint")}function Dp(r,t){let e=r.get(t),n=0;if(n+=e&ht,e<$||(e=r.get(t+1),n+=(e&ht)<<7,e<$)||(e=r.get(t+2),n+=(e&ht)<<14,e<$)||(e=r.get(t+3),n+=(e&ht)<<21,e<$)||(e=r.get(t+4),n+=(e&ht)*Ci,e<$)||(e=r.get(t+5),n+=(e&ht)*Di,e<$)||(e=r.get(t+6),n+=(e&ht)*Ri,e<$)||(e=r.get(t+7),n+=(e&ht)*Oi,e<$))return n;throw new RangeError("Could not decode varint")}function Pi(r,t=0){return r instanceof Uint8Array?Cp(r,t):Dp(r,t)}var ut=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},Xt=class extends Error{static name="ValidationError";name="ValidationError"},oo=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},so=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};function Ni(r){return t=>tt(t,r)}function Ui(r){return t=>Z(t,r)}function hr(r){return new DataView(r.buffer).getUint16(r.byteOffset).toString()}function Oe(r){let t=new ArrayBuffer(2);return new DataView(t).setUint16(0,typeof r=="string"?parseInt(r):r),new Uint8Array(t)}function jf(r){let t=r.split(":");if(t.length!==2)throw new Error(`failed to parse onion addr: ["'${t.join('", "')}'"]' does not contain a port number`);if(t[0].length!==16)throw new Error(`failed to parse onion addr: ${t[0]} not a Tor onion address.`);let e=Z(t[0],"base32"),n=parseInt(t[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=Oe(n);return Ae([e,o],e.length+o.length)}function $f(r){let t=r.split(":");if(t.length!==2)throw new Error(`failed to parse onion addr: ["'${t.join('", "')}'"]' does not contain a port number`);if(t[0].length!==56)throw new Error(`failed to parse onion addr: ${t[0]} not a Tor onion3 address.`);let e=Jt.decode(`b${t[0]}`),n=parseInt(t[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=Oe(n);return Ae([e,o],e.length+o.length)}function Mi(r){let t=r.subarray(0,r.length-2),e=r.subarray(r.length-2),n=tt(t,"base32"),o=hr(e);return`${n}:${o}`}var zi=function(r){r=r.toString().trim();let t=new Uint8Array(4);return r.split(/\./g).forEach((e,n)=>{let o=parseInt(e,10);if(isNaN(o)||o<0||o>255)throw new ut("Invalid byte value in IP address");t[n]=o}),t},Gf=function(r){let t=0;r=r.toString().trim();let e=r.split(":",8),n;for(n=0;n<e.length;n++){let s=cr(e[n]),i;s&&(i=zi(e[n]),e[n]=tt(i.subarray(0,2),"base16")),i!=null&&++n<8&&e.splice(n,0,tt(i.subarray(2,4),"base16"))}if(e[0]==="")for(;e.length<8;)e.unshift("0");else if(e[e.length-1]==="")for(;e.length<8;)e.push("0");else if(e.length<8){for(n=0;n<e.length&&e[n]!=="";n++);let s=[n,1];for(n=9-e.length;n>0;n--)s.push("0");e.splice.apply(e,s)}let o=new Uint8Array(t+16);for(n=0;n<e.length;n++){e[n]===""&&(e[n]="0");let s=parseInt(e[n],16);if(isNaN(s)||s<0||s>65535)throw new ut("Invalid byte value in IP address");o[t++]=s>>8&255,o[t++]=s&255}return o},Zf=function(r){if(r.byteLength!==4)throw new ut("IPv4 address was incorrect length");let t=[];for(let e=0;e<r.byteLength;e++)t.push(r[e]);return t.join(".")},Yf=function(r){if(r.byteLength!==16)throw new ut("IPv6 address was incorrect length");let t=[];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")}`;t.push(i)}let e=t.join(":");try{let n=new URL(`http://[${e}]`);return n.hostname.substring(1,n.hostname.length-1)}catch{throw new ut(`Invalid IPv6 address "${e}"`)}};function Xf(r){try{let t=new URL(`http://[${r}]`);return t.hostname.substring(1,t.hostname.length-1)}catch{throw new ut(`Invalid IPv6 address "${r}"`)}}var ki=Object.values(Ar).map(r=>r.decoder),Op=(function(){let r=ki[0].or(ki[1]);return ki.slice(2).forEach(t=>r=r.or(t)),r})();function Wf(r){return Op.decode(r)}function Qf(r){return t=>r.encoder.encode(t)}function Fp(r){if(parseInt(r).toString()!==r)throw new Xt("Value must be an integer")}function Pp(r){if(r<0)throw new Xt("Value must be a positive integer, or zero")}function kp(r){return t=>{if(t>r)throw new Xt(`Value must be smaller than or equal to ${r}`)}}function Np(...r){return t=>{for(let e of r)e(t)}}var rn=Np(Fp,Pp,kp(65535));var at=-1,Ki=class{protocolsByCode=new Map;protocolsByName=new Map;getProtocol(t){let e;if(typeof t=="string"?e=this.protocolsByName.get(t):e=this.protocolsByCode.get(t),e==null)throw new so(`Protocol ${t} was unknown`);return e}addProtocol(t){this.protocolsByCode.set(t.code,t),this.protocolsByName.set(t.name,t),t.aliases?.forEach(e=>{this.protocolsByName.set(e,t)})}removeProtocol(t){let e=this.protocolsByCode.get(t);e!=null&&(this.protocolsByCode.delete(e.code),this.protocolsByName.delete(e.name),e.aliases?.forEach(n=>{this.protocolsByName.delete(n)}))}},Wt=new Ki,v0=[{code:4,name:"ip4",size:32,valueToBytes:zi,bytesToValue:Zf,validate:r=>{if(!cr(r))throw new Xt(`Invalid IPv4 address "${r}"`)}},{code:6,name:"tcp",size:16,valueToBytes:Oe,bytesToValue:hr,validate:rn},{code:273,name:"udp",size:16,valueToBytes:Oe,bytesToValue:hr,validate:rn},{code:33,name:"dccp",size:16,valueToBytes:Oe,bytesToValue:hr,validate:rn},{code:41,name:"ip6",size:128,valueToBytes:Gf,bytesToValue:Yf,stringToValue:Xf,validate:r=>{if(!ro(r))throw new Xt(`Invalid IPv6 address "${r}"`)}},{code:42,name:"ip6zone",size:at},{code:43,name:"ipcidr",size:8,bytesToValue:Ni("base10"),valueToBytes:Ui("base10")},{code:53,name:"dns",size:at},{code:54,name:"dns4",size:at},{code:55,name:"dns6",size:at},{code:56,name:"dnsaddr",size:at},{code:132,name:"sctp",size:16,valueToBytes:Oe,bytesToValue:hr,validate:rn},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:at,stringToValue:r=>decodeURIComponent(r),valueToString:r=>encodeURIComponent(r)},{code:421,name:"p2p",aliases:["ipfs"],size:at,bytesToValue:Ni("base58btc"),valueToBytes:r=>r.startsWith("Q")||r.startsWith("1")?Ui("base58btc")(r):lt.parse(r).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:Mi,valueToBytes:jf},{code:445,name:"onion3",size:296,bytesToValue:Mi,valueToBytes:$f},{code:446,name:"garlic64",size:at},{code:447,name:"garlic32",size:at},{code:448,name:"tls"},{code:449,name:"sni",size:at},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:at,bytesToValue:Qf(ko),valueToBytes:Wf},{code:480,name:"http"},{code:481,name:"http-path",size:at,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:at}];v0.forEach(r=>{Wt.addProtocol(r)});function Jf(r){let t=[],e=0;for(;e<r.length;){let n=Pi(r,e),o=Wt.getProtocol(n),s=dr(n),i=_0(o,r,e+s),a=0;i>0&&o.size===at&&(a=dr(i));let c=s+a+i,f={code:n,name:o.name,bytes:Ut(r.subarray(e,e+c))};if(i>0){let d=e+s+a,h=r.subarray(d,d+i);f.value=o.bytesToValue?.(h)??tt(h)}t.push(f),e+=c}return t}function tu(r){let t=0,e=[];for(let n of r){if(n.bytes==null){let o=Wt.getProtocol(n.code),s=dr(n.code),i,a=0,c=0;n.value!=null&&(i=o.valueToBytes?.(n.value)??Z(n.value),a=i.byteLength,o.size===at&&(c=dr(a)));let f=new Uint8Array(s+c+a),d=0;Fi(n.code,f,d),d+=s,i!=null&&(o.size===at&&(Fi(a,f,d),d+=c),f.set(i,d)),n.bytes=f}e.push(n.bytes),t+=n.bytes.byteLength}return Ae(e,t)}function eu(r){if(r.charAt(0)!=="/")throw new ut('String multiaddr must start with "/"');let t=[],e="protocol",n="",o="";for(let s=1;s<r.length;s++){let i=r.charAt(s);i!=="/"&&(e==="protocol"?o+=r.charAt(s):n+=r.charAt(s));let a=s===r.length-1;if(i==="/"||a){let c=Wt.getProtocol(o);if(e==="protocol"){if(c.size==null||c.size===0){t.push({code:c.code,name:c.name}),n="",o="",e="protocol";continue}else if(a)throw new ut(`Component ${o} was missing value`);e="value"}else if(e==="value"){let f={code:c.code,name:c.name};if(c.size!=null&&c.size!==0){if(n==="")throw new ut(`Component ${o} was missing value`);f.value=c.stringToValue?.(n)??n}t.push(f),n="",o="",e="protocol"}}}if(o!==""&&n!=="")throw new ut("Incomplete multiaddr");return t}function ru(r){return`/${r.flatMap(t=>{if(t.value==null)return t.name;let e=Wt.getProtocol(t.code);if(e==null)throw new ut(`Unknown protocol code ${t.code}`);return[t.name,e.valueToString?.(t.value)??t.value]}).join("/")}`}function _0(r,t,e){return r.size==null||r.size===0?0:r.size>0?r.size/8:Pi(t,e)}var A0=Symbol.for("nodejs.util.inspect.custom"),qi=Symbol.for("@multiformats/multiaddr");function I0(r){if(r==null&&(r="/"),nu(r))return r.getComponents();if(r instanceof Uint8Array)return Jf(r);if(typeof r=="string")return r=r.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),r===""&&(r="/"),eu(r);if(Array.isArray(r))return r;throw new ut("Must be a string, Uint8Array, Component[], or another Multiaddr")}var ao=class r{[qi]=!0;#t;#e;#r;constructor(t="/",e={}){this.#t=I0(t),e.validate!==!1&&T0(this)}get bytes(){return this.#r==null&&(this.#r=tu(this.#t)),this.#r}toString(){return this.#e==null&&(this.#e=ru(this.#t)),this.#e}toJSON(){return this.toString()}getComponents(){return[...this.#t.map(t=>({...t}))]}encapsulate(t){let e=new r(t);return new r([...this.#t,...e.getComponents()],{validate:!1})}decapsulate(t){let e=t.toString(),n=this.toString(),o=n.lastIndexOf(e);if(o<0)throw new oo(`Address ${this.toString()} does not contain subaddress: ${e}`);return new r(n.slice(0,o),{validate:!1})}decapsulateCode(t){let e;for(let n=this.#t.length-1;n>-1;n--)if(this.#t[n].code===t){e=n;break}return new r(this.#t.slice(0,e),{validate:!1})}equals(t){return xt(this.bytes,t.bytes)}[A0](){return`Multiaddr(${this.toString()})`}};function T0(r){r.getComponents().forEach(t=>{let e=Wt.getProtocol(t.code);t.value!=null&&e.validate?.(t.value)})}function nu(r){return!!r?.[qi]}function ou(r){return new ao(r)}function pr(){let r={};return r.promise=new Promise((t,e)=>{r.resolve=t,r.reject=e}),r}var co=class{buffer;mask;top;btm;next;constructor(t){if(!(t>0)||(t-1&t)!==0)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(t),this.mask=t-1,this.top=0,this.btm=0,this.next=null}push(t){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=t,this.top=this.top+1&this.mask,!0)}shift(){let t=this.buffer[this.btm];if(t!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,t}isEmpty(){return this.buffer[this.btm]===void 0}},mr=class{size;hwm;head;tail;constructor(t={}){this.hwm=t.splitLimit??16,this.head=new co(this.hwm),this.tail=this.head,this.size=0}calculateSize(t){return t?.byteLength!=null?t.byteLength:1}push(t){if(t?.value!=null&&(this.size+=this.calculateSize(t.value)),!this.head.push(t)){let e=this.head;this.head=e.next=new co(2*this.head.buffer.length),this.head.push(t)}}shift(){let t=this.tail.shift();if(t===void 0&&this.tail.next!=null){let e=this.tail.next;this.tail.next=null,this.tail=e,t=this.tail.shift()}return t?.value!=null&&(this.size-=this.calculateSize(t.value)),t}isEmpty(){return this.head.isEmpty()}};var Vi=class extends Error{type;code;constructor(t,e){super(t??"The operation was aborted"),this.type="aborted",this.code=e??"ABORT_ERR"}};function fo(r={}){return B0(e=>{let n=e.shift();if(n==null)return{done:!0};if(n.error!=null)throw n.error;return{done:n.done===!0,value:n.value}},r)}function B0(r,t){t=t??{};let e=t.onEnd,n=new mr,o,s,i,a=pr(),c=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((m,l)=>{s=g=>{s=null,n.push(g);try{m(r(n))}catch(w){l(w)}return o}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=pr()})}},f=m=>s!=null?s(m):(n.push(m),o),d=m=>(n=new mr,s!=null?s({error:m}):(n.push({error:m}),o)),h=m=>{if(i)return o;if(t?.objectMode!==!0&&m?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return f({done:!1,value:m})},u=m=>i?o:(i=!0,m!=null?d(m):f({done:!0})),p=()=>(n=new mr,u(),{done:!0}),b=m=>(u(m),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:c,return:p,throw:b,push:h,end:u,get readableLength(){return n.size},onEmpty:async m=>{let l=m?.signal;if(l?.throwIfAborted(),n.isEmpty())return;let g,w;l!=null&&(g=new Promise((_,A)=>{w=()=>{A(new Vi)},l.addEventListener("abort",w)}));try{await Promise.race([a.promise,g])}finally{w!=null&&l!=null&&l?.removeEventListener("abort",w)}}},e==null)return o;let x=o;return o={[Symbol.asyncIterator](){return this},next(){return x.next()},throw(m){return x.throw(m),e!=null&&(e(m),e=void 0),{done:!0}},return(){return x.return(),e!=null&&(e(),e=void 0),{done:!0}},push:h,end(m){return x.end(m),e!=null&&(e(m),e=void 0),o},get readableLength(){return x.readableLength},onEmpty:m=>x.onEmpty(m)},o}var Hi=class r extends Error{name="TimeoutError";constructor(t,e){super(t,e),Error.captureStackTrace?.(this,r)}},su=r=>r.reason??new DOMException("This operation was aborted.","AbortError");function ji(r,t){let{milliseconds:e,fallback:n,message:o,customTimers:s={setTimeout,clearTimeout},signal:i}=t,a,c,d=new Promise((h,u)=>{if(typeof e!="number"||Math.sign(e)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${e}\``);if(i?.aborted){u(su(i));return}if(i&&(c=()=>{u(su(i))},i.addEventListener("abort",c,{once:!0})),r.then(h,u),e===Number.POSITIVE_INFINITY)return;let p=new Hi;a=s.setTimeout.call(void 0,()=>{if(n){try{h(n())}catch(b){u(b)}return}typeof r.cancel=="function"&&r.cancel(),o===!1?h():o instanceof Error?u(o):(p.message=o??`Promise timed out after ${e} milliseconds`,u(p))},e)}).finally(()=>{d.clear(),c&&i&&i.removeEventListener("abort",c)});return d.clear=()=>{s.clearTimeout.call(void 0,a),a=void 0},d}var L0=r=>{let t=r.addEventListener||r.on||r.addListener,e=r.removeEventListener||r.off||r.removeListener;if(!t||!e)throw new TypeError("Emitter is not compatible");return{addListener:t.bind(r),removeListener:e.bind(r)}};function C0(r,t,e){let n,o=new Promise((s,i)=>{if(e={rejectionEvents:["error"],multiArgs:!1,rejectionMultiArgs:!1,resolveImmediately:!1,...e},!(e.count>=0&&(e.count===Number.POSITIVE_INFINITY||Number.isInteger(e.count))))throw new TypeError("The `count` option should be at least 0 or more");e.signal?.throwIfAborted();let a=[t].flat(),c=[],{addListener:f,removeListener:d}=L0(r),h=async(...p)=>{let b=e.multiArgs?p:p[0];if(e.filter)try{if(!await e.filter(b))return}catch(x){n(),i(x);return}c.push(b),e.count===c.length&&(n(),s(c))},u=(...p)=>{n(),i(e.rejectionMultiArgs?p:p[0])};n=()=>{for(let p of a)d(p,h);for(let p of e.rejectionEvents)a.includes(p)||d(p,u)};for(let p of a)f(p,h);for(let p of e.rejectionEvents)a.includes(p)||f(p,u);e.signal&&e.signal.addEventListener("abort",()=>{u(e.signal.reason)},{once:!0}),e.resolveImmediately&&s(c)});if(o.cancel=n,typeof e.timeout=="number"){let s=ji(o,{milliseconds:e.timeout});return s.cancel=()=>{n(),s.clear()},s}return o}function gr(r,t,e){typeof e=="function"&&(e={filter:e}),e={...e,count:1,resolveImmediately:!1};let n=C0(r,t,e),o=n.then(s=>s[0]);return o.cancel=n.cancel,o}function nn(r,t){let e,n=function(){let o=function(){e=void 0,r()};clearTimeout(e),e=setTimeout(o,t)};return n.start=()=>{},n.stop=()=>{clearTimeout(e)},n}var uo=class extends Error{static name="QueueFullError";constructor(t="The queue was full"){super(t),this.name="QueueFullError"}},Fe=class extends Error{static name="UnexpectedEOFError";name="UnexpectedEOFError"};function D0(r){return r.reason}async function on(r,t,e){if(t==null)return r;let n=e?.translateError??D0;if(t.aborted)return r.catch(()=>{}),Promise.reject(n(t));let o;try{return await Promise.race([r,new Promise((s,i)=>{o=()=>{i(n(t))},t.addEventListener("abort",o)})])}finally{o!=null&&t.removeEventListener("abort",o)}}var lo=class{deferred;signal;onProgress;constructor(t){this.signal=t?.signal,this.onProgress=t?.onProgress,this.deferred=pr(),this.onAbort=this.onAbort.bind(this),this.signal?.addEventListener("abort",this.onAbort)}onAbort(){this.deferred.reject(this.signal?.reason??new kt)}cleanup(){this.signal?.removeEventListener("abort",this.onAbort)}};function R0(){return`${parseInt(String(Math.random()*1e9),10).toString()}${Date.now()}`}var ho=class{id;fn;options;recipients;status;timeline;controller;dispatchingProgress;constructor(t,e){this.id=R0(),this.status="queued",this.fn=t,this.options=e,this.recipients=[],this.timeline={created:Date.now()},this.controller=new AbortController,this.controller.signal,this.dispatchingProgress=!1,this.onAbort=this.onAbort.bind(this)}abort(t){this.controller.abort(t)}onAbort(){this.recipients.reduce((e,n)=>e&&n.signal?.aborted===!0,!0)&&(this.controller.abort(new kt),this.cleanup())}async join(t){let e=new lo(t);return this.recipients.push(e),t?.signal?.addEventListener("abort",this.onAbort),e.deferred.promise}async run(){this.status="running",this.timeline.started=Date.now();try{this.controller.signal.throwIfAborted();let t=await on(this.fn({...this.options??{},signal:this.controller.signal,onProgress:e=>{if(!this.dispatchingProgress){this.dispatchingProgress=!0;try{this.recipients.forEach(n=>{n.onProgress?.(e)})}finally{this.dispatchingProgress=!1}}}}),this.controller.signal);this.recipients.forEach(e=>{e.deferred.resolve(t)}),this.status="complete"}catch(t){this.recipients.forEach(e=>{e.deferred.reject(t)}),this.status="errored"}finally{this.timeline.finished=Date.now(),this.cleanup()}}cleanup(){this.recipients.forEach(t=>{t.cleanup(),t.signal?.removeEventListener("abort",this.onAbort)})}};var po=class extends ln{concurrency;maxSize;queue;pending;sort;paused;constructor(t={}){super(),this.concurrency=t.concurrency??Number.POSITIVE_INFINITY,this.maxSize=t.maxSize??Number.POSITIVE_INFINITY,this.pending=0,this.paused=!1,t.metricName!=null&&t.metrics?.registerMetricGroup(t.metricName,{calculate:()=>({size:this.queue.length,running:this.pending,queued:this.queue.length-this.pending})}),this.sort=t.sort,this.queue=[],this.emitEmpty=nn(this.emitEmpty.bind(this),1),this.emitIdle=nn(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 t;for(let e of this.queue)if(e.status==="queued"){t=e;break}return t==null?!1:(this.safeDispatchEvent("active"),this.pending++,t.run().finally(()=>{for(let e=0;e<this.queue.length;e++)if(this.queue[e]===t){this.queue.splice(e,1);break}this.pending--,this.tryToStartAnother(),this.safeDispatchEvent("next")}),!0)}return!1}enqueue(t){this.queue.push(t),this.sort!=null&&this.queue.sort(this.sort)}async add(t,e){if(e?.signal?.throwIfAborted(),this.size===this.maxSize)throw new uo;let n=new ho(t,e);this.enqueue(n),this.safeDispatchEvent("add");let o=n.join(e).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(t=>{t.abort(new kt)}),this.clear()}async onEmpty(t){this.size!==0&&await gr(this,"empty",t)}async onSizeLessThan(t,e){this.size<t||await gr(this,"next",{...e,filter:()=>this.size<t})}async onIdle(t){this.pending===0&&this.size===0||await gr(this,"idle",t)}get size(){return this.queue.length}get queued(){return this.queue.length-this.pending}get running(){return this.pending}async*toGenerator(t){t?.signal?.throwIfAborted();let e=fo({objectMode:!0}),n=c=>{c!=null?this.abort():this.clear(),e.end(c)},o=c=>{c.detail!=null&&e.push(c.detail)},s=c=>{n(c.detail.error)},i=()=>{n()},a=()=>{n(new kt("Queue aborted"))};this.addEventListener("completed",o),this.addEventListener("failure",s),this.addEventListener("idle",i),t?.signal?.addEventListener("abort",a);try{yield*e}finally{this.removeEventListener("completed",o),this.removeEventListener("failure",s),this.removeEventListener("idle",i),t?.signal?.removeEventListener("abort",a),n()}}};function mo(r){let t=new globalThis.AbortController;function e(){let s=r.filter(i=>i?.aborted===!0).map(i=>i?.reason).pop();t.abort(s);for(let i of r)i?.removeEventListener!=null&&i.removeEventListener("abort",e)}for(let s of r){if(s?.aborted===!0){e();break}s?.addEventListener!=null&&s.addEventListener("abort",e)}function n(){for(let s of r)s?.removeEventListener!=null&&s.removeEventListener("abort",e)}let o=t.signal;return o.clear=n,o}function iu(r=0){return new Uint8Array(r)}var O0=Math.pow(2,7),F0=Math.pow(2,14),P0=Math.pow(2,21),$i=Math.pow(2,28),Gi=Math.pow(2,35),Zi=Math.pow(2,42),Yi=Math.pow(2,49),K=128,pt=127;function sn(r){if(r<O0)return 1;if(r<F0)return 2;if(r<P0)return 3;if(r<$i)return 4;if(r<Gi)return 5;if(r<Zi)return 6;if(r<Yi)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function k0(r,t,e=0){switch(sn(r)){case 8:t[e++]=r&255|K,r/=128;case 7:t[e++]=r&255|K,r/=128;case 6:t[e++]=r&255|K,r/=128;case 5:t[e++]=r&255|K,r/=128;case 4:t[e++]=r&255|K,r>>>=7;case 3:t[e++]=r&255|K,r>>>=7;case 2:t[e++]=r&255|K,r>>>=7;case 1:{t[e++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return t}function N0(r,t,e=0){switch(sn(r)){case 8:t.set(e++,r&255|K),r/=128;case 7:t.set(e++,r&255|K),r/=128;case 6:t.set(e++,r&255|K),r/=128;case 5:t.set(e++,r&255|K),r/=128;case 4:t.set(e++,r&255|K),r>>>=7;case 3:t.set(e++,r&255|K),r>>>=7;case 2:t.set(e++,r&255|K),r>>>=7;case 1:{t.set(e++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return t}function U0(r,t){let e=r[t],n=0;if(n+=e&pt,e<K||(e=r[t+1],n+=(e&pt)<<7,e<K)||(e=r[t+2],n+=(e&pt)<<14,e<K)||(e=r[t+3],n+=(e&pt)<<21,e<K)||(e=r[t+4],n+=(e&pt)*$i,e<K)||(e=r[t+5],n+=(e&pt)*Gi,e<K)||(e=r[t+6],n+=(e&pt)*Zi,e<K)||(e=r[t+7],n+=(e&pt)*Yi,e<K))return n;throw new RangeError("Could not decode varint")}function M0(r,t){let e=r.get(t),n=0;if(n+=e&pt,e<K||(e=r.get(t+1),n+=(e&pt)<<7,e<K)||(e=r.get(t+2),n+=(e&pt)<<14,e<K)||(e=r.get(t+3),n+=(e&pt)<<21,e<K)||(e=r.get(t+4),n+=(e&pt)*$i,e<K)||(e=r.get(t+5),n+=(e&pt)*Gi,e<K)||(e=r.get(t+6),n+=(e&pt)*Zi,e<K)||(e=r.get(t+7),n+=(e&pt)*Yi,e<K))return n;throw new RangeError("Could not decode varint")}function au(r,t,e=0){return t==null&&(t=iu(sn(r))),t instanceof Uint8Array?k0(r,t,e):N0(r,t,e)}function cu(r,t=0){return r instanceof Uint8Array?U0(r,t):M0(r,t)}var K0=4194304,go=class extends Error{static name="UnwrappedError";name="UnwrappedError"},Wi=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},Qi=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},Ji=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function q0(r){return typeof r?.closeRead=="function"}function V0(r){return typeof r?.close=="function"}function Xi(r){return q0(r)?r.remoteWriteStatus!=="writable"&&r.readBufferLength===0:V0(r)?r.status!=="open":!1}function H0(r){return r?.addEventListener!=null&&r?.removeEventListener!=null&&r?.send!=null&&r?.push!=null&&r?.log!=null}function j0(r,t){let e=t?.maxBufferSize??K0,n=new st,o,s=!1;if(!H0(r))throw new mt("Argument should be a Stream or a Multiaddr");let i=d=>{if(n.append(d.data),n.byteLength>e){let h=n.byteLength;n.consume(n.byteLength),o?.reject(new Error(`Read buffer overflow - ${h} > ${e}`))}o?.resolve()};r.addEventListener("message",i);let a=d=>{d.error!=null?o?.reject(d.error):o?.resolve()};r.addEventListener("close",a);let c=()=>{o?.resolve()};r.addEventListener("remoteCloseWrite",c);let f={readBuffer:n,async read(d){if(s===!0)throw new go("Stream was unwrapped");if(Xi(r)){if(n.byteLength===0&&d?.bytes==null)return null;if(d?.bytes!=null&&n.byteLength<d.bytes)throw r.log.error("closed after reading %d/%d bytes",n.byteLength,d.bytes),new Fe(`Unexpected EOF - stream closed after reading ${n.byteLength}/${d.bytes} bytes`)}let h=d?.bytes??1;for(o=Promise.withResolvers();;){if(n.byteLength>=h){o.resolve();break}if(await on(o.promise,d?.signal),Xi(r)){if(n.byteLength===0&&d?.bytes==null)return null;break}o=Promise.withResolvers()}let u=d?.bytes??n.byteLength;if(n.byteLength<u){if(Xi(r))throw r.log.error("closed while reading %d/%d bytes",n.byteLength,u),new Fe(`Unexpected EOF - stream closed while reading ${n.byteLength}/${u} bytes`);return f.read(d)}let p=n.sublist(0,u);return n.consume(u),p},async write(d,h){if(s===!0)throw new go("Stream was unwrapped");r.send(d)||await gr(r,"drain",{signal:h?.signal,rejectionEvents:["close"]})},unwrap(){return s||(s=!0,r.removeEventListener("message",i),r.removeEventListener("close",a),r.removeEventListener("remoteCloseWrite",c),n.byteLength>0&&(r.log("stream unwrapped with %d unread bytes",n.byteLength),r.unshift(n))),r}};return f}function $0(r,t={}){let e=j0(r,t);t.maxDataLength!=null&&t.maxLengthLength==null&&(t.maxLengthLength=sn(t.maxDataLength));let n=t?.lengthDecoder??cu,o=t?.lengthEncoder??au;return{async read(i){let a=-1,c=new st;for(;;){let d=await e.read({...i,bytes:1});if(d==null)break;c.append(d);try{a=n(c)}catch(h){if(h instanceof RangeError)continue;throw h}if(a<0)throw new Wi("Invalid message length");if(t?.maxLengthLength!=null&&c.byteLength>t.maxLengthLength)throw new Ji(`Message length length too long - ${c.byteLength} > ${t.maxLengthLength}`);if(a>-1)break}if(t?.maxDataLength!=null&&a>t.maxDataLength)throw new Qi(`Message length too long - ${a} > ${t.maxDataLength}`);let f=await e.read({...i,bytes:a});if(f==null)throw r.log.error("tried to read %d bytes but the stream closed",a),new Fe(`Unexpected EOF - tried to read ${a} bytes but the stream closed`);if(f.byteLength!==a)throw r.log.error("read %d/%d bytes before the stream closed",f.byteLength,a),new Fe(`Unexpected EOF - read ${f.byteLength}/${a} bytes before the stream closed`);return f},async write(i,a){await e.write(new st(o(i.byteLength),i),a)},async writeV(i,a){let c=new st(...i.flatMap(f=>[o(f.byteLength),f]));await e.write(c,a)},unwrap(){return e.unwrap()}}}function ta(r,t){let e=$0(r,t),n={read:async(o,s)=>{let i=await e.read(s);return o.decode(i)},write:async(o,s,i)=>{await e.write(s.encode(o),i)},writeV:async(o,s,i)=>{await e.writeV(o.map(a=>s.encode(a)),i)},pb:o=>({read:async s=>n.read(o,s),write:async(s,i)=>n.write(s,o,i),writeV:async(s,i)=>n.writeV(s,o,i),unwrap:()=>n}),unwrap:()=>e.unwrap()};return n}var bo=class extends po{has(t){return this.find(t)!=null}find(t){return this.queue.find(e=>t.equals(e.options.peerId))}};function fu(r,t,e){let n,o,s=!1;function i(){let f={signal:o.signal},d;e?.timeout!=null&&(d=mo([o.signal,AbortSignal.timeout(e.timeout)]),f.signal=d),s=!0,Promise.resolve().then(async()=>{await r(f)}).catch(()=>{}).finally(()=>{d!=null&&(d.aborted?d.clear():d.addEventListener("abort",()=>{d.clear()},{once:!0})),s=!1,!o.signal.aborted&&(n=setTimeout(i,t))})}let a=nn(i,e?.debounce??100),c=!1;return{setInterval:f=>{t!==f&&(t=f,n!=null&&(clearTimeout(n),n=setTimeout(i,t)))},setTimeout:f=>{e??={},e.timeout=f},run:()=>{s||(clearTimeout(n),a())},start:()=>{c||(c=!0,o=new AbortController,o.signal,e?.runImmediately===!0?queueMicrotask(()=>{i()}):n=setTimeout(i,t))},stop:()=>{clearTimeout(n),o?.abort(),c=!1}}}var ea=class extends Map{metric;constructor(t){super();let{name:e,metrics:n}=t;this.metric=n.registerMetric(e),this.updateComponentMetric()}set(t,e){return super.set(t,e),this.updateComponentMetric(),this}delete(t){let e=super.delete(t);return this.updateComponentMetric(),e}clear(){super.clear(),this.updateComponentMetric()}updateComponentMetric(){this.metric.update(this.size)}};function uu(r){let{name:t,metrics:e}=r,n;return e!=null?n=new ea({name:t,metrics:e}):n=new Map,n}var lu="libp2p",du="autonat",hu="1.0.0";var H;(function(r){let t;(function(u){u.DIAL="DIAL",u.DIAL_RESPONSE="DIAL_RESPONSE"})(t=r.MessageType||(r.MessageType={}));let e;(function(u){u[u.DIAL=0]="DIAL",u[u.DIAL_RESPONSE=1]="DIAL_RESPONSE"})(e||(e={})),(function(u){u.codec=()=>or(e)})(t=r.MessageType||(r.MessageType={}));let n;(function(u){u.OK="OK",u.E_DIAL_ERROR="E_DIAL_ERROR",u.E_DIAL_REFUSED="E_DIAL_REFUSED",u.E_BAD_REQUEST="E_BAD_REQUEST",u.E_INTERNAL_ERROR="E_INTERNAL_ERROR"})(n=r.ResponseStatus||(r.ResponseStatus={}));let o;(function(u){u[u.OK=0]="OK",u[u.E_DIAL_ERROR=100]="E_DIAL_ERROR",u[u.E_DIAL_REFUSED=101]="E_DIAL_REFUSED",u[u.E_BAD_REQUEST=200]="E_BAD_REQUEST",u[u.E_INTERNAL_ERROR=300]="E_INTERNAL_ERROR"})(o||(o={})),(function(u){u.codec=()=>or(o)})(n=r.ResponseStatus||(r.ResponseStatus={}));let s;(function(u){let p;u.codec=()=>(p==null&&(p=Yt((l,g,w={})=>{if(w.lengthDelimited!==!1&&g.fork(),l.id!=null&&(g.uint32(10),g.bytes(l.id)),l.addrs!=null&&l.addrs.length>0)for(let _ of l.addrs)g.uint32(18),g.bytes(_);w.lengthDelimited!==!1&&g.ldelim()},(l,g,w={})=>{let _={addrs:[]},A=g==null?l.len:l.pos+g;for(;l.pos<A;){let C=l.uint32();switch(C>>>3){case 1:{_.id=l.bytes();break}case 2:{if(w.limits?.addrs!=null&&_.addrs.length===w.limits.addrs)throw new Yr('Decode error - repeated field "addrs" had too many elements');_.addrs.push(l.bytes());break}default:{l.skipType(C&7);break}}}return _},function*(l,g,w,_={}){let A={addrs:0},C=g==null?l.len:l.pos+g;for(;l.pos<C;){let L=l.uint32();switch(L>>>3){case 1:{yield{field:`${w}.id`,value:l.bytes()};break}case 2:{if(_.limits?.addrs!=null&&A.addrs===_.limits.addrs)throw new Yr('Streaming decode error - repeated field "addrs" had too many elements');yield{field:`${w}.addrs[]`,index:A.addrs,value:l.bytes()},A.addrs++;break}default:{l.skipType(L&7);break}}}})),p);function b(l){return Gt(l,u.codec())}u.encode=b;function x(l,g){return jt(l,u.codec(),g)}u.decode=x;function m(l,g){return Zt(l,u.codec(),g)}u.stream=m})(s=r.PeerInfo||(r.PeerInfo={}));let i;(function(u){let p;u.codec=()=>(p==null&&(p=Yt((l,g,w={})=>{w.lengthDelimited!==!1&&g.fork(),l.peer!=null&&(g.uint32(10),r.PeerInfo.codec().encode(l.peer,g)),w.lengthDelimited!==!1&&g.ldelim()},(l,g,w={})=>{let _={},A=g==null?l.len:l.pos+g;for(;l.pos<A;){let C=l.uint32();C>>>3===1?_.peer=r.PeerInfo.codec().decode(l,l.uint32(),{limits:w.limits?.peer}):l.skipType(C&7)}return _},function*(l,g,w,_={}){let A=g==null?l.len:l.pos+g;for(;l.pos<A;){let C=l.uint32();C>>>3===1?yield*r.PeerInfo.codec().stream(l,l.uint32(),`${w}.peer`,{limits:_.limits?.peer}):l.skipType(C&7)}})),p);function b(l){return Gt(l,u.codec())}u.encode=b;function x(l,g){return jt(l,u.codec(),g)}u.decode=x;function m(l,g){return Zt(l,u.codec(),g)}u.stream=m})(i=r.Dial||(r.Dial={}));let a;(function(u){let p;u.codec=()=>(p==null&&(p=Yt((l,g,w={})=>{w.lengthDelimited!==!1&&g.fork(),l.status!=null&&(g.uint32(8),r.ResponseStatus.codec().encode(l.status,g)),l.statusText!=null&&(g.uint32(18),g.string(l.statusText)),l.addr!=null&&(g.uint32(26),g.bytes(l.addr)),w.lengthDelimited!==!1&&g.ldelim()},(l,g,w={})=>{let _={},A=g==null?l.len:l.pos+g;for(;l.pos<A;){let C=l.uint32();switch(C>>>3){case 1:{_.status=r.ResponseStatus.codec().decode(l);break}case 2:{_.statusText=l.string();break}case 3:{_.addr=l.bytes();break}default:{l.skipType(C&7);break}}}return _},function*(l,g,w,_={}){let A=g==null?l.len:l.pos+g;for(;l.pos<A;){let C=l.uint32();switch(C>>>3){case 1:{yield{field:`${w}.status`,value:r.ResponseStatus.codec().decode(l)};break}case 2:{yield{field:`${w}.statusText`,value:l.string()};break}case 3:{yield{field:`${w}.addr`,value:l.bytes()};break}default:{l.skipType(C&7);break}}}})),p);function b(l){return Gt(l,u.codec())}u.encode=b;function x(l,g){return jt(l,u.codec(),g)}u.decode=x;function m(l,g){return Zt(l,u.codec(),g)}u.stream=m})(a=r.DialResponse||(r.DialResponse={}));let c;r.codec=()=>(c==null&&(c=Yt((u,p,b={})=>{b.lengthDelimited!==!1&&p.fork(),u.type!=null&&(p.uint32(8),r.MessageType.codec().encode(u.type,p)),u.dial!=null&&(p.uint32(18),r.Dial.codec().encode(u.dial,p)),u.dialResponse!=null&&(p.uint32(26),r.DialResponse.codec().encode(u.dialResponse,p)),b.lengthDelimited!==!1&&p.ldelim()},(u,p,b={})=>{let x={},m=p==null?u.len:u.pos+p;for(;u.pos<m;){let l=u.uint32();switch(l>>>3){case 1:{x.type=r.MessageType.codec().decode(u);break}case 2:{x.dial=r.Dial.codec().decode(u,u.uint32(),{limits:b.limits?.dial});break}case 3:{x.dialResponse=r.DialResponse.codec().decode(u,u.uint32(),{limits:b.limits?.dialResponse});break}default:{u.skipType(l&7);break}}}return x},function*(u,p,b,x={}){let m=p==null?u.len:u.pos+p;for(;u.pos<m;){let l=u.uint32();switch(l>>>3){case 1:{yield{field:`${b}.type`,value:r.MessageType.codec().decode(u)};break}case 2:{yield*r.Dial.codec().stream(u,u.uint32(),`${b}.dial`,{limits:x.limits?.dial});break}case 3:{yield*r.DialResponse.codec().stream(u,u.uint32(),`${b}.dialResponse`,{limits:x.limits?.dialResponse});break}default:{u.skipType(l&7);break}}}})),c);function f(u){return Gt(u,r.codec())}r.encode=f;function d(u,p){return jt(u,r.codec(),p)}r.decode=d;function h(u,p){return Zt(u,r.codec(),p)}r.stream=h})(H||(H={}));var Q0=4,J0=8,yo=class{components;protocol;timeout;maxInboundStreams;maxOutboundStreams;maxMessageSize;started;log;topologyId;dialResults;findPeers;addressFilter;connectionThreshold;constructor(t,e){this.components=t,this.log=t.logger.forComponent("libp2p:auto-nat"),this.started=!1,this.protocol=`/${e.protocolPrefix??lu}/${du}/${hu}`,this.timeout=e.timeout??3e4,this.maxInboundStreams=e.maxInboundStreams??2,this.maxOutboundStreams=e.maxOutboundStreams??20,this.connectionThreshold=e.connectionThreshold??80,this.maxMessageSize=e.maxMessageSize??8192,this.dialResults=uu({name:"libp2p_autonat_dial_results",metrics:t.metrics}),this.findPeers=fu(this.findRandomPeers.bind(this),6e4),this.addressFilter=yi(1024)}[Symbol.toStringTag]="@libp2p/autonat";[sa]=["@libp2p/autonat"];get[ia](){return["@libp2p/identify"]}isStarted(){return this.started}async start(){this.started||(await this.components.registrar.handle(this.protocol,(t,e)=>{this.handleIncomingAutonatStream(t,e).catch(n=>{this.log.error("error handling incoming autonat stream - %e",n)})},{maxInboundStreams:this.maxInboundStreams,maxOutboundStreams:this.maxOutboundStreams}),this.topologyId=await this.components.registrar.register(this.protocol,{onConnect:(t,e)=>{this.verifyExternalAddresses(e).catch(n=>{this.log.error("could not verify addresses - %e",n)})}}),this.findPeers.start(),this.started=!0)}async stop(){await this.components.registrar.unhandle(this.protocol),this.topologyId!=null&&await this.components.registrar.unhandle(this.topologyId),this.dialResults.clear(),this.findPeers.stop(),this.started=!1}allAddressesAreVerified(){return this.components.addressManager.getAddressesWithMetadata().every(t=>t.expires>Date.now()?!0:t.verified)}async findRandomPeers(t){if(this.allAddressesAreVerified())return;let e=mo([AbortSignal.timeout(1e4),t?.signal]);try{this.log("starting random walk to find peers to run AutoNAT");for await(let n of this.components.randomWalk.walk({signal:e})){if(!await this.components.connectionManager.isDialable(n.multiaddrs)){this.log.trace("random peer %p was not dialable %s",n.id,n.multiaddrs.map(o=>o.toString()).join(", "));continue}try{this.log.trace("dial random peer %p",n.id),await this.components.connectionManager.openConnection(n.multiaddrs,{signal:e})}catch{}if(this.allAddressesAreVerified()){this.log("stopping random walk, all addresses are verified");return}if(!this.hasConnectionCapacity()){this.log("stopping random walk, too close to max connections");return}}}catch{}}async handleIncomingAutonatStream(t,e){let n=AbortSignal.timeout(this.timeout);try{let o=ta(t,{maxDataLength:this.maxMessageSize}).pb(H),s=await o.read({signal:n}),i=await this.handleAutonatMessage(s,e,{signal:n});await o.write(i,{signal:n}),await t.close({signal:n})}catch(o){this.log.error("error handling incoming autonat stream - %e",o),t.abort(o)}}async handleAutonatMessage(t,e,n){let o=this.components.addressManager.getAddresses().map(h=>Ct(h).host),s=t.dial;if(s==null)return this.log.error("dial was missing from message"),{type:H.MessageType.DIAL_RESPONSE,dialResponse:{status:H.ResponseStatus.E_BAD_REQUEST,statusText:"No Dial message found in message"}};let i,a=s.peer;if(a?.id==null)return this.log.error("peerId missing from message"),{type:H.MessageType.DIAL_RESPONSE,dialResponse:{status:H.ResponseStatus.E_BAD_REQUEST,statusText:"missing peer info"}};try{let h=ge(a.id);i=Yn(h)}catch(h){return this.log.error("invalid PeerId - %e",h),{type:H.MessageType.DIAL_RESPONSE,dialResponse:{status:H.ResponseStatus.E_BAD_REQUEST,statusText:"bad peer id"}}}if(this.log("incoming request from %p",i),!e.remotePeer.equals(i))return this.log("target peer %p did not equal sending peer %p",i,e.remotePeer),{type:H.MessageType.DIAL_RESPONSE,dialResponse:{status:H.ResponseStatus.E_BAD_REQUEST,statusText:"peer id mismatch"}};let c=a.addrs.map(h=>ou(h)).filter(h=>{try{let u=Ct(h);return Li(h)?!1:u.host!==Ct(e.remoteAddr).host?(this.log.trace("not dialing %a - target host did not match remote host %a",h,e.remoteAddr),!1):o.includes(u.host)?!1:this.components.transportManager.dialTransportForMultiaddr(h)==null?(this.log.trace("not dialing %a - transport unsupported",h),!1):!0}catch{return!1}}).map(h=>(h.getComponents().find(u=>u.code===421)?.value==null&&(h=h.encapsulate(`/p2p/${i.toString()}`)),h));if(c.length===0)return this.log("refused to dial all multiaddrs for %p from message",i),{type:H.MessageType.DIAL_RESPONSE,dialResponse:{status:H.ResponseStatus.E_DIAL_REFUSED,statusText:"no dialable addresses"}};this.log("dial multiaddrs %s for peer %p",c.map(h=>h.toString()).join(", "),i);let f="",d=c[0];for(let h of c){let u;d=h;try{if(u=await this.components.connectionManager.openConnection(h,n),!u.remoteAddr.equals(h))throw this.log.error("tried to dial %a but dialed %a",h,u.remoteAddr),new Error("Unexpected remote address");return this.log("successfully dialed %p via %a",i,h),{type:H.MessageType.DIAL_RESPONSE,dialResponse:{status:H.ResponseStatus.OK,addr:u.remoteAddr.decapsulateCode(421).bytes}}}catch(p){this.log.error("could not dial %p - %e",i,p),f=p.message}finally{u!=null&&await u.close()}}return{type:H.MessageType.DIAL_RESPONSE,dialResponse:{status:H.ResponseStatus.E_DIAL_ERROR,statusText:f,addr:d.bytes}}}getFirstUnverifiedMultiaddr(t,e){let n=this.components.addressManager.getAddressesWithMetadata().sort((o,s)=>o.type==="observed"&&s.type!=="observed"?1:s.type==="observed"&&o.type!=="observed"?-1:0).filter(o=>!(!(o.expires<Date.now())||Ct(o.multiaddr).type==="ip6"&&(!e||!Mf(o.multiaddr))||Li(o.multiaddr)));for(let o of n){let s=o.multiaddr.toString(),i=this.dialResults.get(s);if(i!=null){if(i.networkSegments.includes(t)){this.log.trace("%a already has a network segment result from %s",i.multiaddr,t);continue}if(i.queue.size>10){this.log.trace("%a already has enough peers queued",i.multiaddr);continue}}if(i==null){let a=o.expires<Date.now();if(a&&this.addressFilter.remove?.(s),this.addressFilter.has(s))continue;this.addressFilter.add(s),this.log.trace("creating dial result %s %s",a?"to revalidate":"for",s),i={multiaddr:o.multiaddr,success:0,failure:0,networkSegments:[],verifyingPeers:pi(),queue:new bo({concurrency:3,maxSize:50}),type:o.type,lastVerified:o.lastVerified},this.dialResults.set(s,i)}return i}}removeOutdatedMultiaddrResults(){let t=new Set(this.components.addressManager.getAddressesWithMetadata().filter(({expires:e})=>e<Date.now()).map(({multiaddr:e})=>e.toString()));for(let e of this.dialResults.keys())t.has(e)||(this.log.trace("remove results for %a",e),this.dialResults.delete(e))}async verifyExternalAddresses(t){if(!this.isStarted())return;this.removeOutdatedMultiaddrResults();let n=(await this.components.peerStore.get(t.remotePeer)).addresses.some(({multiaddr:i})=>Ct(i).type==="ip6"),o=this.getNetworkSegment(t.remoteAddr),s=this.getFirstUnverifiedMultiaddr(o,n);if(s==null){this.log.trace("no unverified public addresses found for peer %p to verify, not requesting verification",t.remotePeer);return}if(!this.hasConnectionCapacity()){s.lastVerified!=null?(this.log("automatically re-verifying %a because we are too close to the connection limit",s.multiaddr),this.confirmAddress(s)):this.log("skipping verifying %a because we are too close to the connection limit",s.multiaddr);return}s.queue.add(async i=>{await this.askPeerToVerify(t,o,i)},{peerId:t.remotePeer,multiaddr:s.multiaddr}).catch(i=>{s?.result==null&&this.log.error("error from %p verifying address %a - %e",t.remotePeer,s?.multiaddr,i)})}async askPeerToVerify(t,e,n){let o=this.dialResults.get(n.multiaddr.toString());if(o==null){this.log("%a was verified while %p was queued",n.multiaddr,t.remotePeer);return}let s=AbortSignal.timeout(this.timeout);this.log.trace("asking %a to verify multiaddr %s",t.remoteAddr,n.multiaddr);let i=await t.newStream(this.protocol,{signal:s});try{let a=ta(i).pb(H),[,c]=await Promise.all([a.write({type:H.MessageType.DIAL,dial:{peer:{id:this.components.peerId.toMultihash().bytes,addrs:[n.multiaddr.bytes]}}},{signal:s}),a.read({signal:s})]);if(c.type!==H.MessageType.DIAL_RESPONSE||c.dialResponse==null){this.log("invalid autonat response from %p - %j",t.remotePeer,c);return}let f=c.dialResponse.status;if(this.log.trace("autonat response from %p for %a is %s",t.remotePeer,n.multiaddr,f),f!==H.ResponseStatus.OK&&f!==H.ResponseStatus.E_DIAL_ERROR)return;if(o=this.dialResults.get(n.multiaddr.toString()),o==null){this.log.trace("peer reported %a as %s but there is no result object",n.multiaddr,c.dialResponse.status);return}if(o.networkSegments.includes(e)){this.log.trace("%a results included network segment %s",n.multiaddr,e);return}if(o.result!=null){this.log.trace("already resolved result for %a, ignoring response from",n.multiaddr,t.remotePeer);return}if(o.verifyingPeers.has(t.remotePeer)){this.log.trace("peer %p has already verified %a, ignoring response",t.remotePeer,n.multiaddr);return}if(o.verifyingPeers.add(t.remotePeer),o.networkSegments.push(e),f===H.ResponseStatus.OK){if(o.success++,o.type!=="observed"){this.confirmAddress(o);return}}else f===H.ResponseStatus.E_DIAL_ERROR&&o.failure++;this.log("%a success %d failure %d",o.multiaddr,o.success,o.failure),o.success===Q0&&this.confirmAddress(o),o.failure===J0&&this.unconfirmAddress(o)}finally{try{await i.close({signal:s})}catch(a){i.abort(a)}}}hasConnectionCapacity(){let e=this.components.connectionManager.getConnections().length,n=this.components.connectionManager.getMaxConnections();return e/n*100<this.connectionThreshold}confirmAddress(t){this.log("%s address %a is externally dialable",t.type,t.multiaddr),this.components.addressManager.confirmObservedAddr(t.multiaddr),this.dialResults.delete(t.multiaddr.toString()),t.result=!0,t.queue.abort()}unconfirmAddress(t){this.log("%s address %a is not externally dialable",t.type,t.multiaddr),this.components.addressManager.removeObservedAddr(t.multiaddr),this.dialResults.delete(t.multiaddr.toString()),t.result=!1,t.queue.abort()}getNetworkSegment(t){let e=Ct(t);switch(e.type){case"ip4":return e.host.split(".")[0].padStart(3,"0");case"ip6":return e.host.split(":")[0].padStart(4,"0");default:throw new mt(`Remote address ${t} was not an IPv4 or Ipv6 address`)}}};function tm(r={}){return t=>new yo(t,r)}return wu(em);})();
3
3
  /*! Bundled license information:
4
4
 
5
5
  @noble/curves/utils.js: