@libp2p/autonat 3.0.8 → 3.0.9-7fff925bf

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 Za=Object.create;var yr=Object.defineProperty;var Ya=Object.getOwnPropertyDescriptor;var Xa=Object.getOwnPropertyNames;var Wa=Object.getPrototypeOf,Qa=Object.prototype.hasOwnProperty;var Ja=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports),gt=(r,t)=>{for(var e in t)yr(r,e,{get:t[e],enumerable:!0})},ws=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Xa(t))!Qa.call(r,o)&&o!==e&&yr(r,o,{get:()=>t[o],enumerable:!(n=Ya(t,o))||n.enumerable});return r};var tc=(r,t,e)=>(e=r!=null?Za(Wa(r)):{},ws(t||!r||!r.__esModule?yr(e,"default",{value:r,enumerable:!0}):e,r)),ec=r=>ws(yr({},"__esModule",{value:!0}),r);var _a=Ja(pr=>{(function(){var r,t,e,n,o,s,i,c;c=function(a){var u,l,f,d;return u=(a&255<<24)>>>24,l=(a&255<<16)>>>16,f=(a&65280)>>>8,d=a&255,[u,l,f,d].join(".")},i=function(a){var u,l,f,d,p,h;for(u=[],f=d=0;d<=3&&a.length!==0;f=++d){if(f>0){if(a[0]!==".")throw new Error("Invalid IP");a=a.substring(1)}h=t(a),p=h[0],l=h[1],a=a.substring(l),u.push(p)}if(a.length!==0)throw new Error("Invalid IP");switch(u.length){case 1:if(u[0]>4294967295)throw new Error("Invalid IP");return u[0]>>>0;case 2:if(u[0]>255||u[1]>16777215)throw new Error("Invalid IP");return(u[0]<<24|u[1])>>>0;case 3:if(u[0]>255||u[1]>255||u[2]>65535)throw new Error("Invalid IP");return(u[0]<<24|u[1]<<16|u[2])>>>0;case 4:if(u[0]>255||u[1]>255||u[2]>255||u[3]>255)throw new Error("Invalid IP");return(u[0]<<24|u[1]<<16|u[2]<<8|u[3])>>>0;default:throw new Error("Invalid IP")}},e=function(a){return a.charCodeAt(0)},n=e("0"),s=e("a"),o=e("A"),t=function(a){var u,l,f,d,p;for(d=0,u=10,l="9",f=0,a.length>1&&a[f]==="0"&&(a[f+1]==="x"||a[f+1]==="X"?(f+=2,u=16):"0"<=a[f+1]&&a[f+1]<="9"&&(f++,u=8,l="7")),p=f;f<a.length;){if("0"<=a[f]&&a[f]<=l)d=d*u+(e(a[f])-n)>>>0;else if(u===16)if("a"<=a[f]&&a[f]<="f")d=d*u+(10+e(a[f])-s)>>>0;else if("A"<=a[f]&&a[f]<="F")d=d*u+(10+e(a[f])-o)>>>0;else break;else break;if(d>4294967295)throw new Error("too large");f++}if(f===p)throw new Error("empty octet");return[d,f]},r=(function(){function a(u,l){var f,d,p,h;if(typeof u!="string")throw new Error("Missing `net' parameter");if(l||(h=u.split("/",2),u=h[0],l=h[1]),l||(l=32),typeof l=="string"&&l.indexOf(".")>-1){try{this.maskLong=i(l)}catch(v){throw f=v,new Error("Invalid mask: "+l)}for(d=p=32;p>=0;d=--p)if(this.maskLong===4294967295<<32-d>>>0){this.bitmask=d;break}}else if(l||l===0)this.bitmask=parseInt(l,10),this.maskLong=0,this.bitmask>0&&(this.maskLong=4294967295<<32-this.bitmask>>>0);else throw new Error("Invalid mask: empty");try{this.netLong=(i(u)&this.maskLong)>>>0}catch(v){throw f=v,new Error("Invalid net address: "+u)}if(!(this.bitmask<=32))throw new Error("Invalid mask for ip4: "+l);this.size=Math.pow(2,32-this.bitmask),this.base=c(this.netLong),this.mask=c(this.maskLong),this.hostmask=c(~this.maskLong),this.first=this.bitmask<=30?c(this.netLong+1):this.base,this.last=this.bitmask<=30?c(this.netLong+this.size-2):c(this.netLong+this.size-1),this.broadcast=this.bitmask<=30?c(this.netLong+this.size-1):void 0}return a.prototype.contains=function(u){return typeof u=="string"&&(u.indexOf("/")>0||u.split(".").length!==4)&&(u=new a(u)),u instanceof a?this.contains(u.base)&&this.contains(u.broadcast||u.last):(i(u)&this.maskLong)>>>0===(this.netLong&this.maskLong)>>>0},a.prototype.next=function(u){return u==null&&(u=1),new a(c(this.netLong+this.size*u),this.mask)},a.prototype.forEach=function(u){var l,f,d;for(d=i(this.first),f=i(this.last),l=0;d<=f;)u(c(d),d,l),l++,d++},a.prototype.toString=function(){return this.base+"/"+this.bitmask},a})(),pr.ip2long=i,pr.long2ip=c,pr.Netmask=r}).call(pr)});var Jl={};gt(Jl,{autoNAT:()=>Ql});var Bt=class extends Error{static name="AbortError";constructor(t="The operation was aborted"){super(t),this.name="AbortError"}};var ft=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},xr=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var wr=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}};var qe=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var wn=Symbol.for("@libp2p/peer-id");var Er=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){super.addEventListener(t,e,n);let o=this.#t.get(t);o==null&&(o=[],this.#t.set(t,o)),o.push({callback:e,once:(n!==!0&&n!==!1&&n?.once)??!1})}removeEventListener(t,e,n){super.removeEventListener(t.toString(),e??null,n);let o=this.#t.get(t);o!=null&&(o=o.filter(({callback:s})=>s!==e),this.#t.set(t,o))}dispatchEvent(t){let e=super.dispatchEvent(t),n=this.#t.get(t.type);return n==null||(n=n.filter(({once:o})=>!o),this.#t.set(t.type,n)),e}safeDispatchEvent(t,e={}){return this.dispatchEvent(new CustomEvent(t,e))}};var Es=Symbol.for("@libp2p/service-capabilities"),Ss=Symbol.for("@libp2p/service-dependencies");var An={};gt(An,{base58btc:()=>X,base58flickr:()=>cc});var Td=new Uint8Array(0);function vs(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 Tt(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 _s(r){return new TextEncoder().encode(r)}function As(r){return new TextDecoder().decode(r)}function rc(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 c=r.length,a=r.charAt(0),u=Math.log(c)/Math.log(256),l=Math.log(256)/Math.log(c);function f(h){if(h instanceof Uint8Array||(ArrayBuffer.isView(h)?h=new Uint8Array(h.buffer,h.byteOffset,h.byteLength):Array.isArray(h)&&(h=Uint8Array.from(h))),!(h instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(h.length===0)return"";for(var v=0,g=0,x=0,A=h.length;x!==A&&h[x]===0;)x++,v++;for(var w=(A-x)*l+1>>>0,I=new Uint8Array(w);x!==A;){for(var P=h[x],U=0,M=w-1;(P!==0||U<g)&&M!==-1;M--,U++)P+=256*I[M]>>>0,I[M]=P%c>>>0,P=P/c>>>0;if(P!==0)throw new Error("Non-zero carry");g=U,x++}for(var S=w-g;S!==w&&I[S]===0;)S++;for(var E=a.repeat(v);S<w;++S)E+=r.charAt(I[S]);return E}function d(h){if(typeof h!="string")throw new TypeError("Expected String");if(h.length===0)return new Uint8Array;var v=0;if(h[v]!==" "){for(var g=0,x=0;h[v]===a;)g++,v++;for(var A=(h.length-v)*u+1>>>0,w=new Uint8Array(A);h[v];){var I=e[h.charCodeAt(v)];if(I===255)return;for(var P=0,U=A-1;(I!==0||P<x)&&U!==-1;U--,P++)I+=c*w[U]>>>0,w[U]=I%256>>>0,I=I/256>>>0;if(I!==0)throw new Error("Non-zero carry");x=P,v++}if(h[v]!==" "){for(var M=A-x;M!==A&&w[M]===0;)M++;for(var S=new Uint8Array(g+(A-M)),E=g;M!==A;)S[E++]=w[M++];return S}}}function p(h){var v=d(h);if(v)return v;throw new Error(`Non-${t} character`)}return{encode:f,decodeUnsafe:d,decode:p}}var nc=rc,oc=nc,Ls=oc;var En=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")}},Sn=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 Bs(this,t)}},vn=class{decoders;constructor(t){this.decoders=t}or(t){return Bs(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 Bs(r,t){return new vn({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var _n=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 En(t,e,n),this.decoder=new Sn(t,e,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function me({name:r,prefix:t,encode:e,decode:n}){return new _n(r,t,e,n)}function Vt({name:r,prefix:t,alphabet:e}){let{encode:n,decode:o}=Ls(e,r);return me({prefix:t,name:r,encode:n,decode:s=>Tt(o(s))})}function sc(r,t,e,n){let o=r.length;for(;r[o-1]==="=";)--o;let s=new Uint8Array(o*e/8|0),i=0,c=0,a=0;for(let u=0;u<o;++u){let l=t[r[u]];if(l===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<e|l,i+=e,i>=8&&(i-=8,s[a++]=255&c>>i)}if(i>=e||(255&c<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function ic(r,t,e){let n=t[t.length-1]==="=",o=(1<<e)-1,s="",i=0,c=0;for(let a=0;a<r.length;++a)for(c=c<<8|r[a],i+=8;i>e;)i-=e,s+=t[o&c>>i];if(i!==0&&(s+=t[o&c<<e-i]),n)for(;(s.length*e&7)!==0;)s+="=";return s}function ac(r){let t={};for(let e=0;e<r.length;++e)t[r[e]]=e;return t}function Y({name:r,prefix:t,bitsPerChar:e,alphabet:n}){let o=ac(n);return me({prefix:t,name:r,encode(s){return ic(s,n,e)},decode(s){return sc(s,o,e,r)}})}var X=Vt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),cc=Vt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var In={};gt(In,{base32:()=>Ht,base32hex:()=>dc,base32hexpad:()=>pc,base32hexpadupper:()=>mc,base32hexupper:()=>hc,base32pad:()=>fc,base32padupper:()=>lc,base32upper:()=>uc,base32z:()=>gc});var Ht=Y({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),uc=Y({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),fc=Y({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),lc=Y({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),dc=Y({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),hc=Y({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),pc=Y({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),mc=Y({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),gc=Y({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Ln={};gt(Ln,{base36:()=>ze,base36upper:()=>bc});var ze=Vt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),bc=Vt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var yc=Cs,Ts=128,xc=127,wc=~xc,Ec=Math.pow(2,31);function Cs(r,t,e){t=t||[],e=e||0;for(var n=e;r>=Ec;)t[e++]=r&255|Ts,r/=128;for(;r&wc;)t[e++]=r&255|Ts,r>>>=7;return t[e]=r|0,Cs.bytes=e-n+1,t}var Sc=Bn,vc=128,Ds=127;function Bn(r,n){var e=0,n=n||0,o=0,s=n,i,c=r.length;do{if(s>=c)throw Bn.bytes=0,new RangeError("Could not decode varint");i=r[s++],e+=o<28?(i&Ds)<<o:(i&Ds)*Math.pow(2,o),o+=7}while(i>=vc);return Bn.bytes=s-n,e}var _c=Math.pow(2,7),Ac=Math.pow(2,14),Ic=Math.pow(2,21),Lc=Math.pow(2,28),Bc=Math.pow(2,35),Tc=Math.pow(2,42),Dc=Math.pow(2,49),Cc=Math.pow(2,56),Rc=Math.pow(2,63),Pc=function(r){return r<_c?1:r<Ac?2:r<Ic?3:r<Lc?4:r<Bc?5:r<Tc?6:r<Dc?7:r<Cc?8:r<Rc?9:10},Oc={encode:yc,decode:Sc,encodingLength:Pc},Nc=Oc,Ve=Nc;function He(r,t=0){return[Ve.decode(r,t),Ve.decode.bytes]}function ge(r,t,e=0){return Ve.encode(r,t,e),t}function be(r){return Ve.encodingLength(r)}function xe(r,t){let e=t.byteLength,n=be(r),o=n+be(e),s=new Uint8Array(o+e);return ge(r,s,0),ge(e,s,n),s.set(t,o),new ye(r,e,t,s)}function Jt(r){let t=Tt(r),[e,n]=He(t),[o,s]=He(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new ye(e,o,i,t)}function Rs(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&vs(r.bytes,e.bytes)}}var ye=class{code;size;digest;bytes;constructor(t,e,n,o){this.code=t,this.size=e,this.digest=n,this.bytes=o}};function Ps(r,t){let{bytes:e,version:n}=r;switch(n){case 0:return Uc(e,Tn(r),t??X.encoder);default:return Mc(e,Tn(r),t??Ht.encoder)}}var Os=new WeakMap;function Tn(r){let t=Os.get(r);if(t==null){let e=new Map;return Os.set(r,e),e}return t}var at=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!==$e)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==Kc)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=xe(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&&Rs(t.multihash,n.multihash)}toString(t){return Ps(this,t)}toJSON(){return{"/":Ps(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??Ns(n,o,s.bytes))}else if(e[Fc]===!0){let{version:n,multihash:o,code:s}=e,i=Jt(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!==$e)throw new Error(`Version 0 CID must use dag-pb (code: ${$e}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let o=Ns(t,e,n.bytes);return new r(t,e,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,$e,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=Tt(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 ye(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[f,d]=He(t.subarray(e));return e+=d,f},o=n(),s=$e;if(o===18?(o=0,e=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=e,c=n(),a=n(),u=e+a,l=u-i;return{version:o,codec:s,multihashCode:c,digestSize:a,multihashSize:l,size:u}}static parse(t,e){let[n,o]=kc(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 Tn(s).set(n,t),s}};function kc(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 Ht.prefix:{let e=t??Ht;return[Ht.prefix,e.decode(r)]}case ze.prefix:{let e=t??ze;return[ze.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 Uc(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 Mc(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 $e=112,Kc=18;function Ns(r,t,e){let n=be(r),o=n+be(t),s=new Uint8Array(o+e.byteLength);return ge(r,s,0),ge(t,s,n),s.set(e,o),s}var Fc=Symbol.for("@ipld/js-cid/CID");var Dn={};gt(Dn,{identity:()=>xt});var ks=0,qc="identity",Us=Tt;function zc(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 xe(ks,Us(r))}var xt={code:ks,name:qc,encode:Us,digest:zc};function lt(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 wt(r=0){return new Uint8Array(r)}function ht(r=0){return new Uint8Array(r)}function Dt(r,t){t==null&&(t=r.reduce((o,s)=>o+s.length,0));let e=ht(t),n=0;for(let o of r)e.set(o,n),n+=o.length;return e}var Ks=Symbol.for("@achingbrain/uint8arraylist");function Ms(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 vr(r){return!!r?.[Ks]}var J=class r{bufs;length;[Ks]=!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(vr(n))e+=n.byteLength,this.bufs.push(...n.bufs);else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}prepend(...t){this.prependAll(t)}prependAll(t){let e=0;for(let n of t.reverse())if(n instanceof Uint8Array)e+=n.byteLength,this.bufs.unshift(n);else if(vr(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=Ms(this.bufs,t);return e.buf[e.index]}set(t,e){let n=Ms(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(vr(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 Dt(n,o)}subarray(t,e){let{bufs:n,length:o}=this._subList(t,e);return n.length===1?n[0]:Dt(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],c=o,a=c+i.byteLength;if(o=a,t>=a)continue;let u=t>=c&&t<a,l=e>c&&e<=a;if(u&&l){if(t===c&&e===a){n.push(i);break}let f=t-c;n.push(i.subarray(f,f+(e-t)));break}if(u){if(t===0){n.push(i);continue}n.push(i.subarray(t-c));continue}if(l){if(e===a){n.push(i);break}n.push(i.subarray(0,e-c));break}n.push(i)}return{bufs:n,length:e-t}}indexOf(t,e=0){if(!vr(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 f=0;f<s;f++)i[f]=-1;for(let f=0;f<o;f++)i[n[f]]=f;let c=i,a=this.byteLength-n.byteLength,u=n.byteLength-1,l;for(let f=e;f<=a;f+=l){l=0;for(let d=u;d>=0;d--){let p=this.get(f+d);if(n[d]!==p){l=Math.max(1,d-c[p]);break}}if(l===0)return f}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=ht(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=wt(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=wt(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=wt(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=ht(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=wt(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=wt(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=wt(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=wt(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=wt(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(!lt(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 Cn={};gt(Cn,{base10:()=>Vc});var Vc=Vt({prefix:"9",name:"base10",alphabet:"0123456789"});var Rn={};gt(Rn,{base16:()=>Hc,base16upper:()=>$c});var Hc=Y({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),$c=Y({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Pn={};gt(Pn,{base2:()=>jc});var jc=Y({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var On={};gt(On,{base256emoji:()=>Wc});var Fs=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}"),Gc=Fs.reduce((r,t,e)=>(r[e]=t,r),[]),Zc=Fs.reduce((r,t,e)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return r[n]=e,r},[]);function Yc(r){return r.reduce((t,e)=>(t+=Gc[e],t),"")}function Xc(r){let t=[];for(let e of r){let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);let o=Zc[n];if(o==null)throw new Error(`Non-base256emoji character: ${e}`);t.push(o)}return new Uint8Array(t)}var Wc=me({prefix:"\u{1F680}",name:"base256emoji",encode:Yc,decode:Xc});var kn={};gt(kn,{base64:()=>Qc,base64pad:()=>Jc,base64url:()=>Nn,base64urlpad:()=>tu});var Qc=Y({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Jc=Y({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Nn=Y({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),tu=Y({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Un={};gt(Un,{base8:()=>eu});var eu=Y({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Mn={};gt(Mn,{identity:()=>ru});var ru=me({prefix:"\0",name:"identity",encode:r=>As(r),decode:r=>_s(r)});var dh=new TextEncoder,hh=new TextDecoder;var qn={};gt(qn,{sha256:()=>je,sha512:()=>iu});var su=20;function Fn({name:r,code:t,encode:e,minDigestLength:n,maxDigestLength:o}){return new Kn(r,t,e,n,o)}var Kn=class{name;code;encode;minDigestLength;maxDigestLength;constructor(t,e,n,o,s){this.name=t,this.code=e,this.encode=n,this.minDigestLength=o??su,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?qs(n,this.code,e?.truncate):n.then(o=>qs(o,this.code,e?.truncate))}else throw Error("Unknown type, must be binary type")}};function qs(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 xe(t,r)}function Vs(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var je=Fn({name:"sha2-256",code:18,encode:Vs("SHA-256")}),iu=Fn({name:"sha2-512",code:19,encode:Vs("SHA-512")});var Ge={...Mn,...Pn,...Un,...Cn,...Rn,...In,...Ln,...An,...kn,...On},Ah={...qn,...Dn};function $s(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var Hs=$s("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),zn=$s("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=ht(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),au={utf8:Hs,"utf-8":Hs,hex:Ge.base16,latin1:zn,ascii:zn,binary:zn,...Ge},_r=au;function $(r,t="utf8"){let e=_r[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.decoder.decode(`${e.prefix}${r}`)}function Q(r,t="utf8"){let e=_r[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.encoder.encode(r).substring(1)}var cu=parseInt("11111",2),Vn=parseInt("10000000",2),uu=parseInt("01111111",2),js={0:Ze,1:Ze,2:fu,3:hu,4:pu,5:du,6:lu,16:Ze,22:Ze,48:Ze};function Hn(r,t={offset:0}){let e=r[t.offset]&cu;if(t.offset++,js[e]!=null)return js[e](r,t);throw new Error("No decoder for tag "+e)}function Ye(r,t){let e=0;if((r[t.offset]&Vn)===Vn){let n=r[t.offset]&uu,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 Ze(r,t){Ye(r,t);let e=[];for(;!(t.offset>=r.byteLength);){let n=Hn(r,t);if(n===null)break;e.push(n)}return e}function fu(r,t){let e=Ye(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 lu(r,t){let e=Ye(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 c=`${s}.${i}`,a=[];for(;t.offset<n;){let u=r[t.offset];if(t.offset++,a.push(u&127),u<128){a.reverse();let l=0;for(let f=0;f<a.length;f++)l+=a[f]<<f*7;c+=`.${l}`,a=[]}}return c}function du(r,t){return t.offset++,null}function hu(r,t){let e=Ye(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 pu(r,t){let e=Ye(r,t),n=r.subarray(t.offset,t.offset+e);return t.offset+=e,n}function mu(r){let t=r.toString(16);t.length%2===1&&(t="0"+t);let e=new J;for(let n=0;n<t.length;n+=2)e.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return e}function $n(r){if(r.byteLength<128)return Uint8Array.from([r.byteLength]);let t=mu(r.byteLength);return new J(Uint8Array.from([t.byteLength|Vn]),t)}function Gs(r){let t=new J,e=128;return(r.subarray()[0]&e)===e&&t.append(Uint8Array.from([0])),t.append(r),new J(Uint8Array.from([2]),$n(t),t)}function Zs(r){let t=Uint8Array.from([0]),e=new J(t,r);return new J(Uint8Array.from([3]),$n(e),e)}function Ar(r,t=48){let e=new J;for(let n of r)e.append(n);return new J(Uint8Array.from([t]),$n(e),e)}async function Ys(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,t,e.subarray());return n?.signal?.throwIfAborted(),s}var gu=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),bu=Uint8Array.from([6,5,43,129,4,0,34]),yu=Uint8Array.from([6,5,43,129,4,0,35]),xu={ext:!0,kty:"EC",crv:"P-256"},wu={ext:!0,kty:"EC",crv:"P-384"},Eu={ext:!0,kty:"EC",crv:"P-521"},jn=32,Gn=48,Zn=66;function Xs(r){let t=Hn(r);return Ws(t)}function Ws(r){let t=r[1][1][0],e=1,n,o;if(t.byteLength===jn*2+1)return n=Q(t.subarray(e,e+jn),"base64url"),o=Q(t.subarray(e+jn),"base64url"),new we({...xu,key_ops:["verify"],x:n,y:o});if(t.byteLength===Gn*2+1)return n=Q(t.subarray(e,e+Gn),"base64url"),o=Q(t.subarray(e+Gn),"base64url"),new we({...wu,key_ops:["verify"],x:n,y:o});if(t.byteLength===Zn*2+1)return n=Q(t.subarray(e,e+Zn),"base64url"),o=Q(t.subarray(e+Zn),"base64url"),new we({...Eu,key_ops:["verify"],x:n,y:o});throw new ft(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function Qs(r){return Ar([Gs(Uint8Array.from([1])),Ar([Su(r.crv)],160),Ar([Zs(new J(Uint8Array.from([4]),$(r.x??"","base64url"),$(r.y??"","base64url")))],161)]).subarray()}function Su(r){if(r==="P-256")return gu;if(r==="P-384")return bu;if(r==="P-521")return yu;throw new ft(`Invalid curve ${r}`)}var we=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=Qs(this.jwk)),this._raw}toMultihash(){return xt.digest(Ee(this))}toCID(){return at.createV1(114,this.toMultihash())}toString(){return X.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:lt(this.raw,t.raw)}async verify(t,e,n){return Ys(this.jwk,e,t,n)}};function te(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function It(r,t=""){if(!Number.isSafeInteger(r)||r<0){let e=t&&`"${t}" `;throw new Error(`${e}expected integer >= 0, got ${r}`)}}function k(r,t,e=""){let n=te(r),o=r?.length,s=t!==void 0;if(!n||s&&o!==t){let i=e&&`"${e}" `,c=s?` of length ${t}`:"",a=n?`length=${o}`:`type=${typeof r}`;throw new Error(i+"expected Uint8Array"+c+", got "+a)}return r}function Ir(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash must wrapped by utils.createHasher");It(r.outputLen),It(r.blockLen)}function Se(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 ti(r,t){k(r,void 0,"digestInto() output");let e=t.outputLen;if(r.length<e)throw new Error('"digestInto() output" expected to be of length >='+e)}function Rt(...r){for(let t=0;t<r.length;t++)r[t].fill(0)}function Lr(r){return new DataView(r.buffer,r.byteOffset,r.byteLength)}function Et(r,t){return r<<32-t|r>>>t}var ei=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",vu=Array.from({length:256},(r,t)=>t.toString(16).padStart(2,"0"));function Pt(r){if(k(r),ei)return r.toHex();let t="";for(let e=0;e<r.length;e++)t+=vu[r[e]];return t}var Ct={_0:48,_9:57,A:65,F:70,a:97,f:102};function Js(r){if(r>=Ct._0&&r<=Ct._9)return r-Ct._0;if(r>=Ct.A&&r<=Ct.F)return r-(Ct.A-10);if(r>=Ct.a&&r<=Ct.f)return r-(Ct.a-10)}function Ot(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);if(ei)return Uint8Array.fromHex(r);let t=r.length,e=t/2;if(t%2)throw new Error("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=Js(r.charCodeAt(s)),c=Js(r.charCodeAt(s+1));if(i===void 0||c===void 0){let a=r[s]+r[s+1];throw new Error('hex string expected, got non-hex character "'+a+'" at index '+s)}n[o]=i*16+c}return n}function pt(...r){let t=0;for(let n=0;n<r.length;n++){let o=r[n];k(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 Yn(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.create=o=>r(o),Object.assign(e,t),Object.freeze(e)}function ve(r=32){let t=typeof globalThis=="object"?globalThis.crypto:null;if(typeof t?.getRandomValues!="function")throw new Error("crypto.getRandomValues must be defined");return t.getRandomValues(new Uint8Array(r))}var Xn=r=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,r])});function ri(r,t,e){return r&t^~r&e}function ni(r,t,e){return r&t^r&e^t&e}var Xe=class{blockLen;outputLen;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=Lr(this.buffer)}update(t){Se(this),k(t);let{view:e,buffer:n,blockLen:o}=this,s=t.length;for(let i=0;i<s;){let c=Math.min(o-this.pos,s-i);if(c===o){let a=Lr(t);for(;o<=s-i;i+=o)this.process(a,i);continue}n.set(t.subarray(i,i+c),this.pos),this.pos+=c,i+=c,this.pos===o&&(this.process(e,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){Se(this),ti(t,this),this.finished=!0;let{buffer:e,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;e[i++]=128,Rt(this.buffer.subarray(i)),this.padOffset>o-i&&(this.process(n,0),i=0);for(let f=i;f<o;f++)e[f]=0;n.setBigUint64(o-8,BigInt(this.length*8),s),this.process(n,0);let c=Lr(t),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen must be aligned to 32bit");let u=a/4,l=this.get();if(u>l.length)throw new Error("_sha2: outputLen bigger than state");for(let f=0;f<u;f++)c.setUint32(4*f,l[f],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:c}=this;return t.destroyed=i,t.finished=s,t.length=o,t.pos=c,o%e&&t.buffer.set(n),t}clone(){return this._cloneInto()}},Nt=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var ot=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var Br=BigInt(4294967295),oi=BigInt(32);function _u(r,t=!1){return t?{h:Number(r&Br),l:Number(r>>oi&Br)}:{h:Number(r>>oi&Br)|0,l:Number(r&Br)|0}}function si(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:c}=_u(r[s],t);[n[s],o[s]]=[i,c]}return[n,o]}var Wn=(r,t,e)=>r>>>e,Qn=(r,t,e)=>r<<32-e|t>>>e,ee=(r,t,e)=>r>>>e|t<<32-e,re=(r,t,e)=>r<<32-e|t>>>e,We=(r,t,e)=>r<<64-e|t>>>e-32,Qe=(r,t,e)=>r>>>e-32|t<<64-e;function Lt(r,t,e,n){let o=(t>>>0)+(n>>>0);return{h:r+e+(o/2**32|0)|0,l:o|0}}var ii=(r,t,e)=>(r>>>0)+(t>>>0)+(e>>>0),ai=(r,t,e,n)=>t+e+n+(r/2**32|0)|0,ci=(r,t,e,n)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0),ui=(r,t,e,n,o)=>t+e+n+o+(r/2**32|0)|0,fi=(r,t,e,n,o)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0)+(o>>>0),li=(r,t,e,n,o,s)=>t+e+n+o+s+(r/2**32|0)|0;var Iu=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]),jt=new Uint32Array(64),Jn=class extends Xe{constructor(t){super(64,t,8,!1)}get(){let{A:t,B:e,C:n,D:o,E:s,F:i,G:c,H:a}=this;return[t,e,n,o,s,i,c,a]}set(t,e,n,o,s,i,c,a){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=c|0,this.H=a|0}process(t,e){for(let f=0;f<16;f++,e+=4)jt[f]=t.getUint32(e,!1);for(let f=16;f<64;f++){let d=jt[f-15],p=jt[f-2],h=Et(d,7)^Et(d,18)^d>>>3,v=Et(p,17)^Et(p,19)^p>>>10;jt[f]=v+jt[f-7]+h+jt[f-16]|0}let{A:n,B:o,C:s,D:i,E:c,F:a,G:u,H:l}=this;for(let f=0;f<64;f++){let d=Et(c,6)^Et(c,11)^Et(c,25),p=l+d+ri(c,a,u)+Iu[f]+jt[f]|0,v=(Et(n,2)^Et(n,13)^Et(n,22))+ni(n,o,s)|0;l=u,u=a,a=c,c=i+p|0,i=s,s=o,o=n,n=p+v|0}n=n+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,c=c+this.E|0,a=a+this.F|0,u=u+this.G|0,l=l+this.H|0,this.set(n,o,s,i,c,a,u,l)}roundClean(){Rt(jt)}destroy(){this.set(0,0,0,0,0,0,0,0),Rt(this.buffer)}},to=class extends Jn{A=Nt[0]|0;B=Nt[1]|0;C=Nt[2]|0;D=Nt[3]|0;E=Nt[4]|0;F=Nt[5]|0;G=Nt[6]|0;H=Nt[7]|0;constructor(){super(32)}};var di=si(["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))),Lu=di[0],Bu=di[1],Gt=new Uint32Array(80),Zt=new Uint32Array(80),eo=class extends Xe{constructor(t){super(128,t,16,!1)}get(){let{Ah:t,Al:e,Bh:n,Bl:o,Ch:s,Cl:i,Dh:c,Dl:a,Eh:u,El:l,Fh:f,Fl:d,Gh:p,Gl:h,Hh:v,Hl:g}=this;return[t,e,n,o,s,i,c,a,u,l,f,d,p,h,v,g]}set(t,e,n,o,s,i,c,a,u,l,f,d,p,h,v,g){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=c|0,this.Dl=a|0,this.Eh=u|0,this.El=l|0,this.Fh=f|0,this.Fl=d|0,this.Gh=p|0,this.Gl=h|0,this.Hh=v|0,this.Hl=g|0}process(t,e){for(let w=0;w<16;w++,e+=4)Gt[w]=t.getUint32(e),Zt[w]=t.getUint32(e+=4);for(let w=16;w<80;w++){let I=Gt[w-15]|0,P=Zt[w-15]|0,U=ee(I,P,1)^ee(I,P,8)^Wn(I,P,7),M=re(I,P,1)^re(I,P,8)^Qn(I,P,7),S=Gt[w-2]|0,E=Zt[w-2]|0,O=ee(S,E,19)^We(S,E,61)^Wn(S,E,6),K=re(S,E,19)^Qe(S,E,61)^Qn(S,E,6),D=ci(M,K,Zt[w-7],Zt[w-16]),b=ui(D,U,O,Gt[w-7],Gt[w-16]);Gt[w]=b|0,Zt[w]=D|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:c,Cl:a,Dh:u,Dl:l,Eh:f,El:d,Fh:p,Fl:h,Gh:v,Gl:g,Hh:x,Hl:A}=this;for(let w=0;w<80;w++){let I=ee(f,d,14)^ee(f,d,18)^We(f,d,41),P=re(f,d,14)^re(f,d,18)^Qe(f,d,41),U=f&p^~f&v,M=d&h^~d&g,S=fi(A,P,M,Bu[w],Zt[w]),E=li(S,x,I,U,Lu[w],Gt[w]),O=S|0,K=ee(n,o,28)^We(n,o,34)^We(n,o,39),D=re(n,o,28)^Qe(n,o,34)^Qe(n,o,39),b=n&s^n&c^s&c,y=o&i^o&a^i&a;x=v|0,A=g|0,v=p|0,g=h|0,p=f|0,h=d|0,{h:f,l:d}=Lt(u|0,l|0,E|0,O|0),u=c|0,l=a|0,c=s|0,a=i|0,s=n|0,i=o|0;let m=ii(O,D,y);n=ai(m,E,K,b),o=m|0}({h:n,l:o}=Lt(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=Lt(this.Bh|0,this.Bl|0,s|0,i|0),{h:c,l:a}=Lt(this.Ch|0,this.Cl|0,c|0,a|0),{h:u,l}=Lt(this.Dh|0,this.Dl|0,u|0,l|0),{h:f,l:d}=Lt(this.Eh|0,this.El|0,f|0,d|0),{h:p,l:h}=Lt(this.Fh|0,this.Fl|0,p|0,h|0),{h:v,l:g}=Lt(this.Gh|0,this.Gl|0,v|0,g|0),{h:x,l:A}=Lt(this.Hh|0,this.Hl|0,x|0,A|0),this.set(n,o,s,i,c,a,u,l,f,d,p,h,v,g,x,A)}roundClean(){Rt(Gt,Zt)}destroy(){Rt(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},ro=class extends eo{Ah=ot[0]|0;Al=ot[1]|0;Bh=ot[2]|0;Bl=ot[3]|0;Ch=ot[4]|0;Cl=ot[5]|0;Dh=ot[6]|0;Dl=ot[7]|0;Eh=ot[8]|0;El=ot[9]|0;Fh=ot[10]|0;Fl=ot[11]|0;Gh=ot[12]|0;Gl=ot[13]|0;Hh=ot[14]|0;Hl=ot[15]|0;constructor(){super(64)}};var hi=Yn(()=>new to,Xn(1));var pi=Yn(()=>new ro,Xn(3));var oo=BigInt(0),no=BigInt(1);function kt(r,t=""){if(typeof r!="boolean"){let e=t&&`"${t}" `;throw new Error(e+"expected boolean, got type="+typeof r)}return r}function mi(r){if(typeof r=="bigint"){if(!Tr(r))throw new Error("positive bigint expected, got "+r)}else It(r);return r}function Je(r){let t=mi(r).toString(16);return t.length&1?"0"+t:t}function gi(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return r===""?oo:BigInt("0x"+r)}function _e(r){return gi(Pt(r))}function ne(r){return gi(Pt(Cr(k(r)).reverse()))}function Dr(r,t){It(t),r=mi(r);let e=Ot(r.toString(16).padStart(t*2,"0"));if(e.length!==t)throw new Error("number too large");return e}function so(r,t){return Dr(r,t).reverse()}function Cr(r){return Uint8Array.from(r)}var Tr=r=>typeof r=="bigint"&&oo<=r;function Tu(r,t,e){return Tr(r)&&Tr(t)&&Tr(e)&&t<=r&&r<e}function tr(r,t,e,n){if(!Tu(t,e,n))throw new Error("expected valid "+r+": "+e+" <= n < "+n+", got "+t)}function io(r){let t;for(t=0;r>oo;r>>=no,t+=1);return t}var er=r=>(no<<BigInt(r))-no;function bi(r,t,e){if(It(r,"hashLen"),It(t,"qByteLen"),typeof e!="function")throw new Error("hmacFn must be a function");let n=g=>new Uint8Array(g),o=Uint8Array.of(),s=Uint8Array.of(0),i=Uint8Array.of(1),c=1e3,a=n(r),u=n(r),l=0,f=()=>{a.fill(1),u.fill(0),l=0},d=(...g)=>e(u,pt(a,...g)),p=(g=o)=>{u=d(s,g),a=d(),g.length!==0&&(u=d(i,g),a=d())},h=()=>{if(l++>=c)throw new Error("drbg: tried max amount of iterations");let g=0,x=[];for(;g<t;){a=d();let A=a.slice();x.push(A),g+=a.length}return pt(...x)};return(g,x)=>{f(),p(g);let A;for(;!(A=x(h()));)p();return f(),A}}function Yt(r,t={},e={}){if(!r||typeof r!="object")throw new Error("expected valid options object");function n(s,i,c){let a=r[s];if(c&&a===void 0)return;let u=typeof a;if(u!==i||a===null)throw new Error(`param "${s}" is invalid: expected ${i}, got ${u}`)}let o=(s,i)=>Object.entries(s).forEach(([c,a])=>n(c,a,i));o(t,!1),o(e,!0)}function Ae(r){let t=new WeakMap;return(e,...n)=>{let o=t.get(e);if(o!==void 0)return o;let s=r(e,...n);return t.set(e,s),s}}var dt=BigInt(0),tt=BigInt(1),oe=BigInt(2),wi=BigInt(3),Ei=BigInt(4),Si=BigInt(5),Du=BigInt(7),vi=BigInt(8),Cu=BigInt(9),_i=BigInt(16);function W(r,t){let e=r%t;return e>=dt?e:t+e}function H(r,t,e){let n=r;for(;t-- >dt;)n*=n,n%=e;return n}function yi(r,t){if(r===dt)throw new Error("invert: expected non-zero number");if(t<=dt)throw new Error("invert: expected positive modulus, got "+t);let e=W(r,t),n=t,o=dt,s=tt,i=tt,c=dt;for(;e!==dt;){let u=n/e,l=n%e,f=o-i*u,d=s-c*u;n=e,e=l,o=i,s=c,i=f,c=d}if(n!==tt)throw new Error("invert: does not exist");return W(o,t)}function co(r,t,e){if(!r.eql(r.sqr(t),e))throw new Error("Cannot find square root")}function Ai(r,t){let e=(r.ORDER+tt)/Ei,n=r.pow(t,e);return co(r,n,t),n}function Ru(r,t){let e=(r.ORDER-Si)/vi,n=r.mul(t,oe),o=r.pow(n,e),s=r.mul(t,o),i=r.mul(r.mul(s,oe),o),c=r.mul(s,r.sub(i,r.ONE));return co(r,c,t),c}function Pu(r){let t=Ie(r),e=Ii(r),n=e(t,t.neg(t.ONE)),o=e(t,n),s=e(t,t.neg(n)),i=(r+Du)/_i;return(c,a)=>{let u=c.pow(a,i),l=c.mul(u,n),f=c.mul(u,o),d=c.mul(u,s),p=c.eql(c.sqr(l),a),h=c.eql(c.sqr(f),a);u=c.cmov(u,l,p),l=c.cmov(d,f,h);let v=c.eql(c.sqr(l),a),g=c.cmov(u,l,v);return co(c,g,a),g}}function Ii(r){if(r<wi)throw new Error("sqrt is not defined for small field");let t=r-tt,e=0;for(;t%oe===dt;)t/=oe,e++;let n=oe,o=Ie(r);for(;xi(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(e===1)return Ai;let s=o.pow(n,t),i=(t+tt)/oe;return function(a,u){if(a.is0(u))return u;if(xi(a,u)!==1)throw new Error("Cannot find square root");let l=e,f=a.mul(a.ONE,s),d=a.pow(u,t),p=a.pow(u,i);for(;!a.eql(d,a.ONE);){if(a.is0(d))return a.ZERO;let h=1,v=a.sqr(d);for(;!a.eql(v,a.ONE);)if(h++,v=a.sqr(v),h===l)throw new Error("Cannot find square root");let g=tt<<BigInt(l-h-1),x=a.pow(f,g);l=h,f=a.sqr(x),d=a.mul(d,f),p=a.mul(p,x)}return p}}function Ou(r){return r%Ei===wi?Ai:r%vi===Si?Ru:r%_i===Cu?Pu(r):Ii(r)}var Li=(r,t)=>(W(r,t)&tt)===tt,Nu=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function uo(r){let t={ORDER:"bigint",BYTES:"number",BITS:"number"},e=Nu.reduce((n,o)=>(n[o]="function",n),t);return Yt(r,e),r}function ku(r,t,e){if(e<dt)throw new Error("invalid exponent, negatives unsupported");if(e===dt)return r.ONE;if(e===tt)return t;let n=r.ONE,o=t;for(;e>dt;)e&tt&&(n=r.mul(n,o)),o=r.sqr(o),e>>=tt;return n}function rr(r,t,e=!1){let n=new Array(t.length).fill(e?r.ZERO:void 0),o=t.reduce((i,c,a)=>r.is0(c)?i:(n[a]=i,r.mul(i,c)),r.ONE),s=r.inv(o);return t.reduceRight((i,c,a)=>r.is0(c)?i:(n[a]=r.mul(i,n[a]),r.mul(i,c)),s),n}function xi(r,t){let e=(r.ORDER-tt)/oe,n=r.pow(t,e),o=r.eql(n,r.ONE),s=r.eql(n,r.ZERO),i=r.eql(n,r.neg(r.ONE));if(!o&&!s&&!i)throw new Error("invalid Legendre symbol result");return o?1:s?0:-1}function Uu(r,t){t!==void 0&&It(t);let e=t!==void 0?t:r.toString(2).length,n=Math.ceil(e/8);return{nBitLength:e,nByteLength:n}}var ao=class{ORDER;BITS;BYTES;isLE;ZERO=dt;ONE=tt;_lengths;_sqrt;_mod;constructor(t,e={}){if(t<=dt)throw new Error("invalid field: expected ORDER > 0, got "+t);let n;this.isLE=!1,e!=null&&typeof e=="object"&&(typeof e.BITS=="number"&&(n=e.BITS),typeof e.sqrt=="function"&&(this.sqrt=e.sqrt),typeof e.isLE=="boolean"&&(this.isLE=e.isLE),e.allowedLengths&&(this._lengths=e.allowedLengths?.slice()),typeof e.modFromBytes=="boolean"&&(this._mod=e.modFromBytes));let{nBitLength:o,nByteLength:s}=Uu(t,n);if(s>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");this.ORDER=t,this.BITS=o,this.BYTES=s,this._sqrt=void 0,Object.preventExtensions(this)}create(t){return W(t,this.ORDER)}isValid(t){if(typeof t!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof t);return dt<=t&&t<this.ORDER}is0(t){return t===dt}isValidNot0(t){return!this.is0(t)&&this.isValid(t)}isOdd(t){return(t&tt)===tt}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 ku(this,t,e)}div(t,e){return W(t*yi(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 yi(t,this.ORDER)}sqrt(t){return this._sqrt||(this._sqrt=Ou(this.ORDER)),this._sqrt(this,t)}toBytes(t){return this.isLE?so(t,this.BYTES):Dr(t,this.BYTES)}fromBytes(t,e=!1){k(t);let{_lengths:n,BYTES:o,isLE:s,ORDER:i,_mod:c}=this;if(n){if(!n.includes(t.length)||t.length>o)throw new Error("Field.fromBytes: expected "+n+" bytes, got "+t.length);let u=new Uint8Array(o);u.set(t,s?0:u.length-t.length),t=u}if(t.length!==o)throw new Error("Field.fromBytes: expected "+o+" bytes, got "+t.length);let a=s?ne(t):_e(t);if(c&&(a=W(a,i)),!e&&!this.isValid(a))throw new Error("invalid field element: outside of range 0..ORDER");return a}invertBatch(t){return rr(this,t)}cmov(t,e,n){return n?e:t}};function Ie(r,t={}){return new ao(r,t)}function Bi(r){if(typeof r!="bigint")throw new Error("field order must be bigint");let t=r.toString(2).length;return Math.ceil(t/8)}function fo(r){let t=Bi(r);return t+Math.ceil(t/2)}function lo(r,t,e=!1){k(r);let n=r.length,o=Bi(t),s=fo(t);if(n<16||n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=e?ne(r):_e(r),c=W(i,t-tt)+tt;return e?so(c,o):Dr(c,o)}var Le=BigInt(0),se=BigInt(1);function nr(r,t){let e=t.negate();return r?e:t}function ie(r,t){let e=rr(r.Fp,t.map(n=>n.Z));return t.map((n,o)=>r.fromAffine(n.toAffine(e[o])))}function Ri(r,t){if(!Number.isSafeInteger(r)||r<=0||r>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+r)}function ho(r,t){Ri(r,t);let e=Math.ceil(t/r)+1,n=2**(r-1),o=2**r,s=er(r),i=BigInt(r);return{windows:e,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function Ti(r,t,e){let{windowSize:n,mask:o,maxNumber:s,shiftBy:i}=e,c=Number(r&o),a=r>>i;c>n&&(c-=s,a+=se);let u=t*n,l=u+Math.abs(c)-1,f=c===0,d=c<0,p=t%2!==0;return{nextN:a,offset:l,isZero:f,isNeg:d,isNegF:p,offsetF:u}}var po=new WeakMap,Pi=new WeakMap;function mo(r){return Pi.get(r)||1}function Di(r){if(r!==Le)throw new Error("invalid wNAF")}var Be=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>Le;)e&se&&(n=n.add(o)),o=o.double(),e>>=se;return n}precomputeWindow(t,e){let{windows:n,windowSize:o}=ho(e,this.bits),s=[],i=t,c=i;for(let a=0;a<n;a++){c=i,s.push(c);for(let u=1;u<o;u++)c=c.add(i),s.push(c);i=c.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=ho(t,this.bits);for(let c=0;c<i.windows;c++){let{nextN:a,offset:u,isZero:l,isNeg:f,isNegF:d,offsetF:p}=Ti(n,c,i);n=a,l?s=s.add(nr(d,e[p])):o=o.add(nr(f,e[u]))}return Di(n),{p:o,f:s}}wNAFUnsafe(t,e,n,o=this.ZERO){let s=ho(t,this.bits);for(let i=0;i<s.windows&&n!==Le;i++){let{nextN:c,offset:a,isZero:u,isNeg:l}=Ti(n,i,s);if(n=c,!u){let f=e[a];o=o.add(l?f.negate():f)}}return Di(n),o}getPrecomputes(t,e,n){let o=po.get(e);return o||(o=this.precomputeWindow(e,t),t!==1&&(typeof n=="function"&&(o=n(o)),po.set(e,o))),o}cached(t,e,n){let o=mo(t);return this.wNAF(o,this.getPrecomputes(o,t,n),e)}unsafe(t,e,n,o){let s=mo(t);return s===1?this._unsafeLadder(t,e,o):this.wNAFUnsafe(s,this.getPrecomputes(s,t,n),e,o)}createCache(t,e){Ri(e,this.bits),Pi.set(t,e),po.delete(t)}hasCache(t){return mo(t)!==1}};function Oi(r,t,e,n){let o=t,s=r.ZERO,i=r.ZERO;for(;e>Le||n>Le;)e&se&&(s=s.add(o)),n&se&&(i=i.add(o)),o=o.double(),e>>=se,n>>=se;return{p1:s,p2:i}}function Ci(r,t,e){if(t){if(t.ORDER!==r)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return uo(t),t}else return Ie(r,{isLE:e})}function Rr(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 a of["p","n","h"]){let u=t[a];if(!(typeof u=="bigint"&&u>Le))throw new Error(`CURVE.${a} must be positive bigint`)}let o=Ci(t.p,e.Fp,n),s=Ci(t.n,e.Fn,n),c=["Gx","Gy","a",r==="weierstrass"?"b":"d"];for(let a of c)if(!o.isValid(t[a]))throw new Error(`CURVE.${a} must be valid field element of CURVE.Fp`);return t=Object.freeze(Object.assign({},t)),{CURVE:t,Fp:o,Fn:s}}function Pr(r,t){return function(n){let o=r(n);return{secretKey:o,publicKey:t(o)}}}var Xt=BigInt(0),et=BigInt(1),go=BigInt(2),Mu=BigInt(8);function Ku(r,t,e,n){let o=r.sqr(e),s=r.sqr(n),i=r.add(r.mul(t.a,o),s),c=r.add(r.ONE,r.mul(t.d,r.mul(o,s)));return r.eql(i,c)}function Ni(r,t={}){let e=Rr("edwards",r,t,t.FpFnLE),{Fp:n,Fn:o}=e,s=e.CURVE,{h:i}=s;Yt(t,{},{uvRatio:"function"});let c=go<<BigInt(o.BYTES*8)-et,a=g=>n.create(g),u=t.uvRatio||((g,x)=>{try{return{isValid:!0,value:n.sqrt(n.div(g,x))}}catch{return{isValid:!1,value:Xt}}});if(!Ku(n,s,s.Gx,s.Gy))throw new Error("bad curve params: generator point");function l(g,x,A=!1){let w=A?et:Xt;return tr("coordinate "+g,x,w,c),x}function f(g){if(!(g instanceof h))throw new Error("EdwardsPoint expected")}let d=Ae((g,x)=>{let{X:A,Y:w,Z:I}=g,P=g.is0();x==null&&(x=P?Mu:n.inv(I));let U=a(A*x),M=a(w*x),S=n.mul(I,x);if(P)return{x:Xt,y:et};if(S!==et)throw new Error("invZ was invalid");return{x:U,y:M}}),p=Ae(g=>{let{a:x,d:A}=s;if(g.is0())throw new Error("bad point: ZERO");let{X:w,Y:I,Z:P,T:U}=g,M=a(w*w),S=a(I*I),E=a(P*P),O=a(E*E),K=a(M*x),D=a(E*a(K+S)),b=a(O+a(A*a(M*S)));if(D!==b)throw new Error("bad point: equation left != right (1)");let y=a(w*I),m=a(P*U);if(y!==m)throw new Error("bad point: equation left != right (2)");return!0});class h{static BASE=new h(s.Gx,s.Gy,et,a(s.Gx*s.Gy));static ZERO=new h(Xt,et,et,Xt);static Fp=n;static Fn=o;X;Y;Z;T;constructor(x,A,w,I){this.X=l("x",x),this.Y=l("y",A),this.Z=l("z",w,!0),this.T=l("t",I),Object.freeze(this)}static CURVE(){return s}static fromAffine(x){if(x instanceof h)throw new Error("extended point not allowed");let{x:A,y:w}=x||{};return l("x",A),l("y",w),new h(A,w,et,a(A*w))}static fromBytes(x,A=!1){let w=n.BYTES,{a:I,d:P}=s;x=Cr(k(x,w,"point")),kt(A,"zip215");let U=Cr(x),M=x[w-1];U[w-1]=M&-129;let S=ne(U),E=A?c:n.ORDER;tr("point.y",S,Xt,E);let O=a(S*S),K=a(O-et),D=a(P*O-I),{isValid:b,value:y}=u(K,D);if(!b)throw new Error("bad point: invalid y coordinate");let m=(y&et)===et,_=(M&128)!==0;if(!A&&y===Xt&&_)throw new Error("bad point: x=0 and x_0=1");return _!==m&&(y=a(-y)),h.fromAffine({x:y,y:S})}static fromHex(x,A=!1){return h.fromBytes(Ot(x),A)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(x=8,A=!0){return v.createCache(this,x),A||this.multiply(go),this}assertValidity(){p(this)}equals(x){f(x);let{X:A,Y:w,Z:I}=this,{X:P,Y:U,Z:M}=x,S=a(A*M),E=a(P*I),O=a(w*M),K=a(U*I);return S===E&&O===K}is0(){return this.equals(h.ZERO)}negate(){return new h(a(-this.X),this.Y,this.Z,a(-this.T))}double(){let{a:x}=s,{X:A,Y:w,Z:I}=this,P=a(A*A),U=a(w*w),M=a(go*a(I*I)),S=a(x*P),E=A+w,O=a(a(E*E)-P-U),K=S+U,D=K-M,b=S-U,y=a(O*D),m=a(K*b),_=a(O*b),L=a(D*K);return new h(y,m,L,_)}add(x){f(x);let{a:A,d:w}=s,{X:I,Y:P,Z:U,T:M}=this,{X:S,Y:E,Z:O,T:K}=x,D=a(I*S),b=a(P*E),y=a(M*w*K),m=a(U*O),_=a((I+P)*(S+E)-D-b),L=m-y,T=m+y,C=a(b-A*D),B=a(_*L),R=a(T*C),N=a(_*C),j=a(L*T);return new h(B,R,j,N)}subtract(x){return this.add(x.negate())}multiply(x){if(!o.isValidNot0(x))throw new Error("invalid scalar: expected 1 <= sc < curve.n");let{p:A,f:w}=v.cached(this,x,I=>ie(h,I));return ie(h,[A,w])[0]}multiplyUnsafe(x,A=h.ZERO){if(!o.isValid(x))throw new Error("invalid scalar: expected 0 <= sc < curve.n");return x===Xt?h.ZERO:this.is0()||x===et?this:v.unsafe(this,x,w=>ie(h,w),A)}isSmallOrder(){return this.multiplyUnsafe(i).is0()}isTorsionFree(){return v.unsafe(this,s.n).is0()}toAffine(x){return d(this,x)}clearCofactor(){return i===et?this:this.multiplyUnsafe(i)}toBytes(){let{x,y:A}=this.toAffine(),w=n.toBytes(A);return w[w.length-1]|=x&et?128:0,w}toHex(){return Pt(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let v=new Be(h,o.BITS);return h.BASE.precompute(8),h}function ki(r,t,e={}){if(typeof t!="function")throw new Error('"hash" function param is required');Yt(e,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",mapToCurve:"function"});let{prehash:n}=e,{BASE:o,Fp:s,Fn:i}=r,c=e.randomBytes||ve,a=e.adjustScalarBytes||(S=>S),u=e.domain||((S,E,O)=>{if(kt(O,"phflag"),E.length||O)throw new Error("Contexts/pre-hash are not supported");return S});function l(S){return i.create(ne(S))}function f(S){let E=w.secretKey;k(S,w.secretKey,"secretKey");let O=k(t(S),2*E,"hashedSecretKey"),K=a(O.slice(0,E)),D=O.slice(E,2*E),b=l(K);return{head:K,prefix:D,scalar:b}}function d(S){let{head:E,prefix:O,scalar:K}=f(S),D=o.multiply(K),b=D.toBytes();return{head:E,prefix:O,scalar:K,point:D,pointBytes:b}}function p(S){return d(S).pointBytes}function h(S=Uint8Array.of(),...E){let O=pt(...E);return l(t(u(O,k(S,void 0,"context"),!!n)))}function v(S,E,O={}){S=k(S,void 0,"message"),n&&(S=n(S));let{prefix:K,scalar:D,pointBytes:b}=d(E),y=h(O.context,K,S),m=o.multiply(y).toBytes(),_=h(O.context,m,b,S),L=i.create(y+_*D);if(!i.isValid(L))throw new Error("sign failed: invalid s");let T=pt(m,i.toBytes(L));return k(T,w.signature,"result")}let g={zip215:!0};function x(S,E,O,K=g){let{context:D,zip215:b}=K,y=w.signature;S=k(S,y,"signature"),E=k(E,void 0,"message"),O=k(O,w.publicKey,"publicKey"),b!==void 0&&kt(b,"zip215"),n&&(E=n(E));let m=y/2,_=S.subarray(0,m),L=ne(S.subarray(m,y)),T,C,B;try{T=r.fromBytes(O,b),C=r.fromBytes(_,b),B=o.multiplyUnsafe(L)}catch{return!1}if(!b&&T.isSmallOrder())return!1;let R=h(D,C.toBytes(),T.toBytes(),E);return C.add(T.multiplyUnsafe(R)).subtract(B).clearCofactor().is0()}let A=s.BYTES,w={secretKey:A,publicKey:A,signature:2*A,seed:A};function I(S=c(w.seed)){return k(S,w.seed,"seed")}function P(S){return te(S)&&S.length===i.BYTES}function U(S,E){try{return!!r.fromBytes(S,E)}catch{return!1}}let M={getExtendedPublicKey:d,randomSecretKey:I,isValidSecretKey:P,isValidPublicKey:U,toMontgomery(S){let{y:E}=r.fromBytes(S),O=w.publicKey,K=O===32;if(!K&&O!==57)throw new Error("only defined for 25519 and 448");let D=K?s.div(et+E,et-E):s.div(E-et,E+et);return s.toBytes(D)},toMontgomerySecret(S){let E=w.secretKey;k(S,E);let O=t(S.subarray(0,E));return a(O).subarray(0,E)}};return Object.freeze({keygen:Pr(I,p),getPublicKey:p,sign:v,verify:x,utils:M,Point:r,lengths:w})}var Fu=BigInt(1),Ui=BigInt(2);var qu=BigInt(5),zu=BigInt(8),bo=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),Vu={p:bo,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:zu,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function Hu(r){let t=BigInt(10),e=BigInt(20),n=BigInt(40),o=BigInt(80),s=bo,c=r*r%s*r%s,a=H(c,Ui,s)*c%s,u=H(a,Fu,s)*r%s,l=H(u,qu,s)*u%s,f=H(l,t,s)*l%s,d=H(f,e,s)*f%s,p=H(d,n,s)*d%s,h=H(p,o,s)*p%s,v=H(h,o,s)*p%s,g=H(v,t,s)*l%s;return{pow_p_5_8:H(g,Ui,s)*r%s,b2:c}}function $u(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}var Mi=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function ju(r,t){let e=bo,n=W(t*t*t,e),o=W(n*n*t,e),s=Hu(r*o).pow_p_5_8,i=W(r*n*s,e),c=W(t*i*i,e),a=i,u=W(i*Mi,e),l=c===r,f=c===W(-r,e),d=c===W(-r*Mi,e);return l&&(i=a),(f||d)&&(i=u),Li(i,e)&&(i=W(-i,e)),{isValid:l||f,value:i}}var Gu=Ni(Vu,{uvRatio:ju});function Zu(r){return ki(Gu,pi,Object.assign({adjustScalarBytes:$u},r))}var Ki=Zu({});var or=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},Or=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var Fi={get(r=globalThis){let t=r.crypto;if(t?.subtle==null)throw new Or("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 Nr=Fi;var kr=32;var yo,Yu=(async()=>{try{return await Nr.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function Xu(r,t,e){if(r.buffer instanceof ArrayBuffer){let n=await Nr.get().subtle.importKey("raw",r.buffer,{name:"Ed25519"},!1,["verify"]);return await Nr.get().subtle.verify({name:"Ed25519"},n,t,e instanceof Uint8Array?e:e.subarray())}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function Wu(r,t,e){return Ki.verify(t,e instanceof Uint8Array?e:e.subarray(),r)}async function qi(r,t,e){return yo==null&&(yo=await Yu),yo?Xu(r,t,e):Wu(r,t,e)}function Ur(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}var Mr=class{type="Ed25519";raw;constructor(t){this.raw=xo(t,kr)}toMultihash(){return xt.digest(Ee(this))}toCID(){return at.createV1(114,this.toMultihash())}toString(){return X.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:lt(this.raw,t.raw)}verify(t,e,n){n?.signal?.throwIfAborted();let o=qi(this.raw,e,t);return Ur(o)?o.then(s=>(n?.signal?.throwIfAborted(),s)):o}};function Vi(r){return r=xo(r,kr),new Mr(r)}function xo(r,t){if(r=Uint8Array.from(r??[]),r.length!==t)throw new ft(`Key must be a Uint8Array of length ${t}, got ${r.length}`);return r}var Ju=Math.pow(2,7),tf=Math.pow(2,14),ef=Math.pow(2,21),wo=Math.pow(2,28),Eo=Math.pow(2,35),So=Math.pow(2,42),vo=Math.pow(2,49),q=128,ct=127;function mt(r){if(r<Ju)return 1;if(r<tf)return 2;if(r<ef)return 3;if(r<wo)return 4;if(r<Eo)return 5;if(r<So)return 6;if(r<vo)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Te(r,t,e=0){switch(mt(r)){case 8:t[e++]=r&255|q,r/=128;case 7:t[e++]=r&255|q,r/=128;case 6:t[e++]=r&255|q,r/=128;case 5:t[e++]=r&255|q,r/=128;case 4:t[e++]=r&255|q,r>>>=7;case 3:t[e++]=r&255|q,r>>>=7;case 2:t[e++]=r&255|q,r>>>=7;case 1:{t[e++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return t}function rf(r,t,e=0){switch(mt(r)){case 8:t.set(e++,r&255|q),r/=128;case 7:t.set(e++,r&255|q),r/=128;case 6:t.set(e++,r&255|q),r/=128;case 5:t.set(e++,r&255|q),r/=128;case 4:t.set(e++,r&255|q),r>>>=7;case 3:t.set(e++,r&255|q),r>>>=7;case 2:t.set(e++,r&255|q),r>>>=7;case 1:{t.set(e++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return t}function _o(r,t){let e=r[t],n=0;if(n+=e&ct,e<q||(e=r[t+1],n+=(e&ct)<<7,e<q)||(e=r[t+2],n+=(e&ct)<<14,e<q)||(e=r[t+3],n+=(e&ct)<<21,e<q)||(e=r[t+4],n+=(e&ct)*wo,e<q)||(e=r[t+5],n+=(e&ct)*Eo,e<q)||(e=r[t+6],n+=(e&ct)*So,e<q)||(e=r[t+7],n+=(e&ct)*vo,e<q))return n;throw new RangeError("Could not decode varint")}function nf(r,t){let e=r.get(t),n=0;if(n+=e&ct,e<q||(e=r.get(t+1),n+=(e&ct)<<7,e<q)||(e=r.get(t+2),n+=(e&ct)<<14,e<q)||(e=r.get(t+3),n+=(e&ct)<<21,e<q)||(e=r.get(t+4),n+=(e&ct)*wo,e<q)||(e=r.get(t+5),n+=(e&ct)*Eo,e<q)||(e=r.get(t+6),n+=(e&ct)*So,e<q)||(e=r.get(t+7),n+=(e&ct)*vo,e<q))return n;throw new RangeError("Could not decode varint")}function Hi(r,t,e=0){return t==null&&(t=ht(mt(r))),t instanceof Uint8Array?Te(r,t,e):rf(r,t,e)}function sr(r,t=0){return r instanceof Uint8Array?_o(r,t):nf(r,t)}var Ao=new Float32Array([-0]),Wt=new Uint8Array(Ao.buffer);function ji(r,t,e){Ao[0]=r,t[e]=Wt[0],t[e+1]=Wt[1],t[e+2]=Wt[2],t[e+3]=Wt[3]}function Gi(r,t){return Wt[0]=r[t],Wt[1]=r[t+1],Wt[2]=r[t+2],Wt[3]=r[t+3],Ao[0]}var Io=new Float64Array([-0]),ut=new Uint8Array(Io.buffer);function Zi(r,t,e){Io[0]=r,t[e]=ut[0],t[e+1]=ut[1],t[e+2]=ut[2],t[e+3]=ut[3],t[e+4]=ut[4],t[e+5]=ut[5],t[e+6]=ut[6],t[e+7]=ut[7]}function Yi(r,t){return ut[0]=r[t],ut[1]=r[t+1],ut[2]=r[t+2],ut[3]=r[t+3],ut[4]=r[t+4],ut[5]=r[t+5],ut[6]=r[t+6],ut[7]=r[t+7],Io[0]}var of=BigInt(Number.MAX_SAFE_INTEGER),sf=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 ae;if(t<of&&t>sf)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>Xi&&(o=0n,++n>Xi&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(t){if(t===0)return ae;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):ae}},ae=new bt(0,0);ae.toBigInt=function(){return 0n};ae.zzEncode=ae.zzDecode=function(){return this};ae.length=function(){return 1};var Xi=4294967296n;function Wi(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 Qi(r,t,e){if(e-t<1)return"";let o,s=[],i=0,c;for(;t<e;)c=r[t++],c<128?s[i++]=c:c>191&&c<224?s[i++]=(c&31)<<6|r[t++]&63:c>239&&c<365?(c=((c&7)<<18|(r[t++]&63)<<12|(r[t++]&63)<<6|r[t++]&63)-65536,s[i++]=55296+(c>>10),s[i++]=56320+(c&1023)):s[i++]=(c&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 Lo(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 St(r,t){return RangeError(`index out of range: ${r.pos} + ${t??1} > ${r.len}`)}function Kr(r,t){return(r[t-4]|r[t-3]<<8|r[t-2]<<16|r[t-1]<<24)>>>0}var Bo=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,St(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 St(this,4);return Kr(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw St(this,4);return Kr(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw St(this,4);let t=Gi(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw St(this,4);let t=Yi(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 St(this,t);return this.pos+=t,e===n?new Uint8Array(0):this.buf.subarray(e,n)}string(){let t=this.bytes();return Qi(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw St(this,t);this.pos+=t}else do if(this.pos>=this.len)throw St(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 St(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 St(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 St(this,8);let t=Kr(this.buf,this.pos+=4),e=Kr(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=_o(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 To(r){return new Bo(r instanceof Uint8Array?r:r.subarray())}function Ut(r,t,e){let n=To(r);return t.decode(n,void 0,e)}function Do(r){let t=r??8192,e=t>>>1,n,o=t;return function(i){if(i<1||i>e)return ht(i);o+i>t&&(n=ht(t),o=0);let c=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),c}}var ce=class{fn;len;next;val;constructor(t,e,n){this.fn=t,this.len=e,this.next=void 0,this.val=n}};function Co(){}var Po=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},af=Do();function cf(r){return globalThis.Buffer!=null?ht(r):af(r)}var ar=class{len;head;tail;states;constructor(){this.len=0,this.head=new ce(Co,0,0),this.tail=this.head,this.states=null}_push(t,e,n){return this.tail=this.tail.next=new ce(t,e,n),this.len+=e,this}uint32(t){return this.len+=(this.tail=this.tail.next=new Oo((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(Fr,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(Fr,e.length(),e)}uint64Number(t){return this._push(Te,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(Fr,e.length(),e)}sint64Number(t){let e=bt.fromNumber(t).zzEncode();return this._push(Fr,e.length(),e)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(Ro,1,t?1:0)}fixed32(t){return this._push(ir,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=bt.fromBigInt(t);return this._push(ir,4,e.lo)._push(ir,4,e.hi)}fixed64Number(t){let e=bt.fromNumber(t);return this._push(ir,4,e.lo)._push(ir,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(ji,4,t)}double(t){return this._push(Zi,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(Ro,1,0):this.uint32(e)._push(ff,e,t)}string(t){let e=Wi(t);return e!==0?this.uint32(e)._push(Lo,e,t):this._push(Ro,1,0)}fork(){return this.states=new Po(this),this.head=this.tail=new ce(Co,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 ce(Co,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=cf(this.len),n=0;for(;t!=null;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e}};function Ro(r,t,e){t[e]=r&255}function uf(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var Oo=class extends ce{next;constructor(t,e){super(uf,t,e),this.next=void 0}};function Fr(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 ir(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 ff(r,t,e){t.set(r,e)}globalThis.Buffer!=null&&(ar.prototype.bytes=function(r){let t=r.length>>>0;return this.uint32(t),t>0&&this._push(lf,t,r),this},ar.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(df,t,r),this});function lf(r,t,e){t.set(r,e)}function df(r,t,e){r.length<40?Lo(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set($(r),e)}function No(){return new ar}function Mt(r,t){let e=No();return t.encode(r,e,{lengthDelimited:!1}),e.finish()}var De;(function(r){r[r.VARINT=0]="VARINT",r[r.BIT64=1]="BIT64",r[r.LENGTH_DELIMITED=2]="LENGTH_DELIMITED",r[r.START_GROUP=3]="START_GROUP",r[r.END_GROUP=4]="END_GROUP",r[r.BIT32=5]="BIT32"})(De||(De={}));function qr(r,t,e,n){return{name:r,type:t,encode:e,decode:n}}function Ce(r){function t(o){if(r[o.toString()]==null)throw new Error("Invalid enum value");return r[o]}let e=function(s,i){let c=t(s);i.int32(c)},n=function(s){let i=s.int32();return t(i)};return qr("enum",De.VARINT,e,n)}function Kt(r,t){return qr("message",De.LENGTH_DELIMITED,r,t)}var zr=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var yt;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.secp256k1="secp256k1",r.ECDSA="ECDSA"})(yt||(yt={}));var ko;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.secp256k1=2]="secp256k1",r[r.ECDSA=3]="ECDSA"})(ko||(ko={}));(function(r){r.codec=()=>Ce(ko)})(yt||(yt={}));var cr;(function(r){let t;r.codec=()=>(t==null&&(t=Kt((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),yt.codec().encode(e.Type,n)),e.Data!=null&&(n.uint32(18),n.bytes(e.Data)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let c=e.uint32();switch(c>>>3){case 1:{s.Type=yt.codec().decode(e);break}case 2:{s.Data=e.bytes();break}default:{e.skipType(c&7);break}}}return s})),t),r.encode=e=>Mt(e,r.codec()),r.decode=(e,n)=>Ut(e,r.codec(),n)})(cr||(cr={}));var Uo;(function(r){let t;r.codec=()=>(t==null&&(t=Kt((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),yt.codec().encode(e.Type,n)),e.Data!=null&&(n.uint32(18),n.bytes(e.Data)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let c=e.uint32();switch(c>>>3){case 1:{s.Type=yt.codec().decode(e);break}case 2:{s.Data=e.bytes();break}default:{e.skipType(c&7);break}}}return s})),t),r.encode=e=>Mt(e,r.codec()),r.decode=(e,n)=>Ut(e,r.codec(),n)})(Uo||(Uo={}));var Vr=class{oHash;iHash;blockLen;outputLen;finished=!1;destroyed=!1;constructor(t,e){if(Ir(t),k(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),Rt(o)}update(t){return Se(this),this.iHash.update(t),this}digestInto(t){Se(this),k(t,this.outputLen,"output"),this.finished=!0,this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){let t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||=Object.create(Object.getPrototypeOf(this),{});let{oHash:e,iHash:n,finished:o,destroyed:s,blockLen:i,outputLen:c}=this;return t=t,t.finished=o,t.destroyed=s,t.blockLen=i,t.outputLen=c,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()}},Mo=(r,t,e)=>new Vr(r,t).update(e).digest();Mo.create=(r,t)=>new Vr(r,t);var ta=(r,t)=>(r+(r>=0?t:-t)/ea)/t;function pf(r,t,e){let[[n,o],[s,i]]=t,c=ta(i*r,e),a=ta(-o*r,e),u=r-c*n-a*s,l=-c*o-a*i,f=u<Ft,d=l<Ft;f&&(u=-u),d&&(l=-l);let p=er(Math.ceil(io(e)/2))+Re;if(u<Ft||u>=p||l<Ft||l>=p)throw new Error("splitScalar (endomorphism): failed, k="+r);return{k1neg:f,k1:u,k2neg:d,k2:l}}function Fo(r){if(!["compact","recovered","der"].includes(r))throw new Error('Signature format must be "compact", "recovered", or "der"');return r}function Ko(r,t){let e={};for(let n of Object.keys(t))e[n]=r[n]===void 0?t[n]:r[n];return kt(e.lowS,"lowS"),kt(e.prehash,"prehash"),e.format!==void 0&&Fo(e.format),e}var qo=class extends Error{constructor(t=""){super(t)}},Qt={Err:qo,_tlv:{encode:(r,t)=>{let{Err:e}=Qt;if(r<0||r>256)throw new e("tlv.encode: wrong tag");if(t.length&1)throw new e("tlv.encode: unpadded data");let n=t.length/2,o=Je(n);if(o.length/2&128)throw new e("tlv.encode: long form length too big");let s=n>127?Je(o.length/2|128):"";return Je(r)+s+o+t},decode(r,t){let{Err:e}=Qt,n=0;if(r<0||r>256)throw new e("tlv.encode: wrong tag");if(t.length<2||t[n++]!==r)throw new e("tlv.decode: wrong tlv");let o=t[n++],s=!!(o&128),i=0;if(!s)i=o;else{let a=o&127;if(!a)throw new e("tlv.decode(long): indefinite length not supported");if(a>4)throw new e("tlv.decode(long): byte length is too big");let u=t.subarray(n,n+a);if(u.length!==a)throw new e("tlv.decode: length bytes not complete");if(u[0]===0)throw new e("tlv.decode(long): zero leftmost byte");for(let l of u)i=i<<8|l;if(n+=a,i<128)throw new e("tlv.decode(long): not minimal encoding")}let c=t.subarray(n,n+i);if(c.length!==i)throw new e("tlv.decode: wrong value length");return{v:c,l:t.subarray(n+i)}}},_int:{encode(r){let{Err:t}=Qt;if(r<Ft)throw new t("integer: negative integers are not allowed");let e=Je(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}=Qt;if(r[0]&128)throw new t("invalid signature integer: negative");if(r[0]===0&&!(r[1]&128))throw new t("invalid signature integer: unnecessary leading zero");return _e(r)}},toSig(r){let{Err:t,_int:e,_tlv:n}=Qt,o=k(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:c,l:a}=n.decode(2,s),{v:u,l}=n.decode(2,a);if(l.length)throw new t("invalid signature: left bytes after parsing");return{r:e.decode(c),s:e.decode(u)}},hexFromSig(r){let{_tlv:t,_int:e}=Qt,n=t.encode(2,e.encode(r.r)),o=t.encode(2,e.encode(r.s)),s=n+o;return t.encode(48,s)}},Ft=BigInt(0),Re=BigInt(1),ea=BigInt(2),Hr=BigInt(3),mf=BigInt(4);function ra(r,t={}){let e=Rr("weierstrass",r,t),{Fp:n,Fn:o}=e,s=e.CURVE,{h:i,n:c}=s;Yt(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object"});let{endo:a}=t;if(a&&(!n.is0(s.a)||typeof a.beta!="bigint"||!Array.isArray(a.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let u=oa(n,o);function l(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function f(D,b,y){let{x:m,y:_}=b.toAffine(),L=n.toBytes(m);if(kt(y,"isCompressed"),y){l();let T=!n.isOdd(_);return pt(na(T),L)}else return pt(Uint8Array.of(4),L,n.toBytes(_))}function d(D){k(D,void 0,"Point");let{publicKey:b,publicKeyUncompressed:y}=u,m=D.length,_=D[0],L=D.subarray(1);if(m===b&&(_===2||_===3)){let T=n.fromBytes(L);if(!n.isValid(T))throw new Error("bad point: is not on curve, wrong x");let C=v(T),B;try{B=n.sqrt(C)}catch(j){let V=j instanceof Error?": "+j.message:"";throw new Error("bad point: is not on curve, sqrt error"+V)}l();let R=n.isOdd(B);return(_&1)===1!==R&&(B=n.neg(B)),{x:T,y:B}}else if(m===y&&_===4){let T=n.BYTES,C=n.fromBytes(L.subarray(0,T)),B=n.fromBytes(L.subarray(T,T*2));if(!g(C,B))throw new Error("bad point: is not on curve");return{x:C,y:B}}else throw new Error(`bad point: got length ${m}, expected compressed=${b} or uncompressed=${y}`)}let p=t.toBytes||f,h=t.fromBytes||d;function v(D){let b=n.sqr(D),y=n.mul(b,D);return n.add(n.add(y,n.mul(D,s.a)),s.b)}function g(D,b){let y=n.sqr(b),m=v(D);return n.eql(y,m)}if(!g(s.Gx,s.Gy))throw new Error("bad curve params: generator point");let x=n.mul(n.pow(s.a,Hr),mf),A=n.mul(n.sqr(s.b),BigInt(27));if(n.is0(n.add(x,A)))throw new Error("bad curve params: a or b");function w(D,b,y=!1){if(!n.isValid(b)||y&&n.is0(b))throw new Error(`bad point coordinate ${D}`);return b}function I(D){if(!(D instanceof E))throw new Error("Weierstrass Point expected")}function P(D){if(!a||!a.basises)throw new Error("no endo");return pf(D,a.basises,o.ORDER)}let U=Ae((D,b)=>{let{X:y,Y:m,Z:_}=D;if(n.eql(_,n.ONE))return{x:y,y:m};let L=D.is0();b==null&&(b=L?n.ONE:n.inv(_));let T=n.mul(y,b),C=n.mul(m,b),B=n.mul(_,b);if(L)return{x:n.ZERO,y:n.ZERO};if(!n.eql(B,n.ONE))throw new Error("invZ was invalid");return{x:T,y:C}}),M=Ae(D=>{if(D.is0()){if(t.allowInfinityPoint&&!n.is0(D.Y))return;throw new Error("bad point: ZERO")}let{x:b,y}=D.toAffine();if(!n.isValid(b)||!n.isValid(y))throw new Error("bad point: x or y not field elements");if(!g(b,y))throw new Error("bad point: equation left != right");if(!D.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function S(D,b,y,m,_){return y=new E(n.mul(y.X,D),y.Y,y.Z),b=nr(m,b),y=nr(_,y),b.add(y)}class E{static BASE=new E(s.Gx,s.Gy,n.ONE);static ZERO=new E(n.ZERO,n.ONE,n.ZERO);static Fp=n;static Fn=o;X;Y;Z;constructor(b,y,m){this.X=w("x",b),this.Y=w("y",y,!0),this.Z=w("z",m),Object.freeze(this)}static CURVE(){return s}static fromAffine(b){let{x:y,y:m}=b||{};if(!b||!n.isValid(y)||!n.isValid(m))throw new Error("invalid affine point");if(b instanceof E)throw new Error("projective point not allowed");return n.is0(y)&&n.is0(m)?E.ZERO:new E(y,m,n.ONE)}static fromBytes(b){let y=E.fromAffine(h(k(b,void 0,"point")));return y.assertValidity(),y}static fromHex(b){return E.fromBytes(Ot(b))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(b=8,y=!0){return K.createCache(this,b),y||this.multiply(Hr),this}assertValidity(){M(this)}hasEvenY(){let{y:b}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(b)}equals(b){I(b);let{X:y,Y:m,Z:_}=this,{X:L,Y:T,Z:C}=b,B=n.eql(n.mul(y,C),n.mul(L,_)),R=n.eql(n.mul(m,C),n.mul(T,_));return B&&R}negate(){return new E(this.X,n.neg(this.Y),this.Z)}double(){let{a:b,b:y}=s,m=n.mul(y,Hr),{X:_,Y:L,Z:T}=this,C=n.ZERO,B=n.ZERO,R=n.ZERO,N=n.mul(_,_),j=n.mul(L,L),V=n.mul(T,T),F=n.mul(_,L);return F=n.add(F,F),R=n.mul(_,T),R=n.add(R,R),C=n.mul(b,R),B=n.mul(m,V),B=n.add(C,B),C=n.sub(j,B),B=n.add(j,B),B=n.mul(C,B),C=n.mul(F,C),R=n.mul(m,R),V=n.mul(b,V),F=n.sub(N,V),F=n.mul(b,F),F=n.add(F,R),R=n.add(N,N),N=n.add(R,N),N=n.add(N,V),N=n.mul(N,F),B=n.add(B,N),V=n.mul(L,T),V=n.add(V,V),N=n.mul(V,F),C=n.sub(C,N),R=n.mul(V,j),R=n.add(R,R),R=n.add(R,R),new E(C,B,R)}add(b){I(b);let{X:y,Y:m,Z:_}=this,{X:L,Y:T,Z:C}=b,B=n.ZERO,R=n.ZERO,N=n.ZERO,j=s.a,V=n.mul(s.b,Hr),F=n.mul(y,L),G=n.mul(m,T),nt=n.mul(_,C),At=n.add(y,m),Z=n.add(L,T);At=n.mul(At,Z),Z=n.add(F,G),At=n.sub(At,Z),Z=n.add(y,_);let it=n.add(L,C);return Z=n.mul(Z,it),it=n.add(F,nt),Z=n.sub(Z,it),it=n.add(m,_),B=n.add(T,C),it=n.mul(it,B),B=n.add(G,nt),it=n.sub(it,B),N=n.mul(j,Z),B=n.mul(V,nt),N=n.add(B,N),B=n.sub(G,N),N=n.add(G,N),R=n.mul(B,N),G=n.add(F,F),G=n.add(G,F),nt=n.mul(j,nt),Z=n.mul(V,Z),G=n.add(G,nt),nt=n.sub(F,nt),nt=n.mul(j,nt),Z=n.add(Z,nt),F=n.mul(G,Z),R=n.add(R,F),F=n.mul(it,Z),B=n.mul(At,B),B=n.sub(B,F),F=n.mul(At,G),N=n.mul(it,N),N=n.add(N,F),new E(B,R,N)}subtract(b){return this.add(b.negate())}is0(){return this.equals(E.ZERO)}multiply(b){let{endo:y}=t;if(!o.isValidNot0(b))throw new Error("invalid scalar: out of range");let m,_,L=T=>K.cached(this,T,C=>ie(E,C));if(y){let{k1neg:T,k1:C,k2neg:B,k2:R}=P(b),{p:N,f:j}=L(C),{p:V,f:F}=L(R);_=j.add(F),m=S(y.beta,N,V,T,B)}else{let{p:T,f:C}=L(b);m=T,_=C}return ie(E,[m,_])[0]}multiplyUnsafe(b){let{endo:y}=t,m=this;if(!o.isValid(b))throw new Error("invalid scalar: out of range");if(b===Ft||m.is0())return E.ZERO;if(b===Re)return m;if(K.hasCache(this))return this.multiply(b);if(y){let{k1neg:_,k1:L,k2neg:T,k2:C}=P(b),{p1:B,p2:R}=Oi(E,m,L,C);return S(y.beta,B,R,_,T)}else return K.unsafe(m,b)}toAffine(b){return U(this,b)}isTorsionFree(){let{isTorsionFree:b}=t;return i===Re?!0:b?b(E,this):K.unsafe(this,c).is0()}clearCofactor(){let{clearCofactor:b}=t;return i===Re?this:b?b(E,this):this.multiplyUnsafe(i)}isSmallOrder(){return this.multiplyUnsafe(i).is0()}toBytes(b=!0){return kt(b,"isCompressed"),this.assertValidity(),p(E,this,b)}toHex(b=!0){return Pt(this.toBytes(b))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let O=o.BITS,K=new Be(E,t.endo?Math.ceil(O/2):O);return E.BASE.precompute(8),E}function na(r){return Uint8Array.of(r?2:3)}function oa(r,t){return{secretKey:t.BYTES,publicKey:1+r.BYTES,publicKeyUncompressed:1+2*r.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function gf(r,t={}){let{Fn:e}=r,n=t.randomBytes||ve,o=Object.assign(oa(r.Fp,e),{seed:fo(e.ORDER)});function s(p){try{let h=e.fromBytes(p);return e.isValidNot0(h)}catch{return!1}}function i(p,h){let{publicKey:v,publicKeyUncompressed:g}=o;try{let x=p.length;return h===!0&&x!==v||h===!1&&x!==g?!1:!!r.fromBytes(p)}catch{return!1}}function c(p=n(o.seed)){return lo(k(p,o.seed,"seed"),e.ORDER)}function a(p,h=!0){return r.BASE.multiply(e.fromBytes(p)).toBytes(h)}function u(p){let{secretKey:h,publicKey:v,publicKeyUncompressed:g}=o;if(!te(p)||"_lengths"in e&&e._lengths||h===v)return;let x=k(p,void 0,"key").length;return x===v||x===g}function l(p,h,v=!0){if(u(p)===!0)throw new Error("first arg must be private key");if(u(h)===!1)throw new Error("second arg must be public key");let g=e.fromBytes(p);return r.fromBytes(h).multiply(g).toBytes(v)}let f={isValidSecretKey:s,isValidPublicKey:i,randomSecretKey:c},d=Pr(c,a);return Object.freeze({getPublicKey:a,getSharedSecret:l,keygen:d,Point:r,utils:f,lengths:o})}function sa(r,t,e={}){Ir(t),Yt(e,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"}),e=Object.assign({},e);let n=e.randomBytes||ve,o=e.hmac||((y,m)=>Mo(t,y,m)),{Fp:s,Fn:i}=r,{ORDER:c,BITS:a}=i,{keygen:u,getPublicKey:l,getSharedSecret:f,utils:d,lengths:p}=gf(r,e),h={prehash:!0,lowS:typeof e.lowS=="boolean"?e.lowS:!0,format:"compact",extraEntropy:!1},v=c*ea<s.ORDER;function g(y){let m=c>>Re;return y>m}function x(y,m){if(!i.isValidNot0(m))throw new Error(`invalid signature ${y}: out of range 1..Point.Fn.ORDER`);return m}function A(){if(v)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function w(y,m){Fo(m);let _=p.signature,L=m==="compact"?_:m==="recovered"?_+1:void 0;return k(y,L)}class I{r;s;recovery;constructor(m,_,L){if(this.r=x("r",m),this.s=x("s",_),L!=null){if(A(),![0,1,2,3].includes(L))throw new Error("invalid recovery id");this.recovery=L}Object.freeze(this)}static fromBytes(m,_=h.format){w(m,_);let L;if(_==="der"){let{r:R,s:N}=Qt.toSig(k(m));return new I(R,N)}_==="recovered"&&(L=m[0],_="compact",m=m.subarray(1));let T=p.signature/2,C=m.subarray(0,T),B=m.subarray(T,T*2);return new I(i.fromBytes(C),i.fromBytes(B),L)}static fromHex(m,_){return this.fromBytes(Ot(m),_)}assertRecovery(){let{recovery:m}=this;if(m==null)throw new Error("invalid recovery id: must be present");return m}addRecoveryBit(m){return new I(this.r,this.s,m)}recoverPublicKey(m){let{r:_,s:L}=this,T=this.assertRecovery(),C=T===2||T===3?_+c:_;if(!s.isValid(C))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let B=s.toBytes(C),R=r.fromBytes(pt(na((T&1)===0),B)),N=i.inv(C),j=U(k(m,void 0,"msgHash")),V=i.create(-j*N),F=i.create(L*N),G=r.BASE.multiplyUnsafe(V).add(R.multiplyUnsafe(F));if(G.is0())throw new Error("invalid recovery: point at infinify");return G.assertValidity(),G}hasHighS(){return g(this.s)}toBytes(m=h.format){if(Fo(m),m==="der")return Ot(Qt.hexFromSig(this));let{r:_,s:L}=this,T=i.toBytes(_),C=i.toBytes(L);return m==="recovered"?(A(),pt(Uint8Array.of(this.assertRecovery()),T,C)):pt(T,C)}toHex(m){return Pt(this.toBytes(m))}}let P=e.bits2int||function(m){if(m.length>8192)throw new Error("input is too large");let _=_e(m),L=m.length*8-a;return L>0?_>>BigInt(L):_},U=e.bits2int_modN||function(m){return i.create(P(m))},M=er(a);function S(y){return tr("num < 2^"+a,y,Ft,M),i.toBytes(y)}function E(y,m){return k(y,void 0,"message"),m?k(t(y),void 0,"prehashed message"):y}function O(y,m,_){let{lowS:L,prehash:T,extraEntropy:C}=Ko(_,h);y=E(y,T);let B=U(y),R=i.fromBytes(m);if(!i.isValidNot0(R))throw new Error("invalid private key");let N=[S(R),S(B)];if(C!=null&&C!==!1){let G=C===!0?n(p.secretKey):C;N.push(k(G,void 0,"extraEntropy"))}let j=pt(...N),V=B;function F(G){let nt=P(G);if(!i.isValidNot0(nt))return;let At=i.inv(nt),Z=r.BASE.multiply(nt).toAffine(),it=i.create(Z.x);if(it===Ft)return;let br=i.create(At*i.create(V+it*R));if(br===Ft)return;let ys=(Z.x===it?0:2)|Number(Z.y&Re),xs=br;return L&&g(br)&&(xs=i.neg(br),ys^=1),new I(it,xs,v?void 0:ys)}return{seed:j,k2sig:F}}function K(y,m,_={}){let{seed:L,k2sig:T}=O(y,m,_);return bi(t.outputLen,i.BYTES,o)(L,T).toBytes(_.format)}function D(y,m,_,L={}){let{lowS:T,prehash:C,format:B}=Ko(L,h);if(_=k(_,void 0,"publicKey"),m=E(m,C),!te(y)){let R=y instanceof I?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+R)}w(y,B);try{let R=I.fromBytes(y,B),N=r.fromBytes(_);if(T&&R.hasHighS())return!1;let{r:j,s:V}=R,F=U(m),G=i.inv(V),nt=i.create(F*G),At=i.create(j*G),Z=r.BASE.multiplyUnsafe(nt).add(N.multiplyUnsafe(At));return Z.is0()?!1:i.create(Z.x)===j}catch{return!1}}function b(y,m,_={}){let{prehash:L}=Ko(_,h);return m=E(m,L),I.fromBytes(y,"recovered").recoverPublicKey(m).toBytes()}return Object.freeze({keygen:u,getPublicKey:l,getSharedSecret:f,utils:d,lengths:p,Point:r,sign:K,verify:D,recoverPublicKey:b,Signature:I,hash:t})}var Vo={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},bf={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var ia=BigInt(2);function yf(r){let t=Vo.p,e=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),c=BigInt(44),a=BigInt(88),u=r*r*r%t,l=u*u*r%t,f=H(l,e,t)*l%t,d=H(f,e,t)*l%t,p=H(d,ia,t)*u%t,h=H(p,o,t)*p%t,v=H(h,s,t)*h%t,g=H(v,c,t)*v%t,x=H(g,a,t)*g%t,A=H(x,c,t)*v%t,w=H(A,e,t)*l%t,I=H(w,i,t)*h%t,P=H(I,n,t)*u%t,U=H(P,ia,t);if(!zo.eql(zo.sqr(U),r))throw new Error("Cannot find square root");return U}var zo=Ie(Vo.p,{sqrt:yf}),xf=ra(Vo,{Fp:zo,endo:bf}),Pe=sa(xf,hi);function aa(r,t,e,n){let o=je.digest(e instanceof Uint8Array?e:e.subarray());if(Ur(o))return o.then(({digest:s})=>(n?.signal?.throwIfAborted(),Pe.verify(t,s,r,{prehash:!1,format:"der"}))).catch(s=>{throw s.name==="AbortError"?s:new or(String(s))});try{return n?.signal?.throwIfAborted(),Pe.verify(t,o.digest,r,{prehash:!1,format:"der"})}catch(s){throw new or(String(s))}}var $r=class{type="secp256k1";raw;_key;constructor(t){this._key=ua(t),this.raw=ca(this._key)}toMultihash(){return xt.digest(Ee(this))}toCID(){return at.createV1(114,this.toMultihash())}toString(){return X.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:lt(this.raw,t.raw)}verify(t,e,n){return aa(this._key,e,t,n)}};function fa(r){return new $r(r)}function ca(r){return Pe.Point.fromBytes(r).toBytes()}function ua(r){try{return Pe.Point.fromBytes(r),r}catch(t){throw new xr(String(t))}}function la(r){let{Type:t,Data:e}=cr.decode(r.digest),n=e??new Uint8Array;switch(t){case yt.Ed25519:return Vi(n);case yt.secp256k1:return fa(n);case yt.ECDSA:return Xs(n);default:throw new qe}}function Ee(r){return cr.encode({Type:yt[r.type],Data:r.raw})}var da=Symbol.for("nodejs.util.inspect.custom"),wf=114,ur=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()})`}[wn]=!0;toString(){return this.string==null&&(this.string=X.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return at.createV1(wf,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return lt(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return lt(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[da](){return`PeerId(${this.toString()})`}},jr=class extends ur{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},Gr=class extends ur{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},Zr=class extends ur{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},Ef=2336,Yr=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=xt.digest($(this.url))}[da](){return`PeerId(${this.url})`}[wn]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return at.createV1(Ef,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=Q(t)),t.toString()===this.toString())}};function Xr(r){if(vf(r))return new jr({multihash:r});if(Sf(r))try{let t=la(r);if(t.type==="Ed25519")return new Gr({multihash:r,publicKey:t});if(t.type==="secp256k1")return new Zr({multihash:r,publicKey:t})}catch{let e=Q(r.digest);return new Yr(new URL(e))}throw new wr("Supplied PeerID Multihash is invalid")}function Sf(r){return r.code===xt.code}function vf(r){return r.code===je.code}function Ho(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 Wr(r){let t=Jt(X.decode(`z${r}`));return Xr(t)}var Qr=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 Ho(this.set.entries(),t=>{let e=Wr(t[0]);return[e,e]})}forEach(t){this.set.forEach(e=>{let n=Wr(e);t(n,n,this)})}has(t){return this.set.has(t.toString())}values(){return Ho(this.set.values(),t=>Wr(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 $o(){return new Qr}var jo={32:16777619n,64:1099511628211n,128:309485009821345068724781371n,256:374144419156711147060143317175368453031918731002211n,512:35835915874844867368919076489095108449946327955754392558399825615420669938882575126094039892345713852759n,1024:5016456510113118655434598811035278955030765345404790744303017523831112055108147451509157692220295382716162651878526895249385292291816524375083746691371804094271873160484737966720260389217684476157468082573n},ha={32:2166136261n,64:14695981039346656037n,128:144066263297769815596495629667062367629n,256:100029257958052580907070968620625704837092796014241193945225284501741471925557n,512:9659303129496669498009435400716310466090418745672637896108374329434462657994582932197716438449813051892206539805784495328239340083876191928701583869517785n,1024:14197795064947621068722070641403218320880622795441933960878474914617582723252296732303717722150864096521202355549365628174669108571814760471015076148029755969804077320157692458563003215304957150157403644460363550505412711285966361610267868082893823963790439336411086884584107735010676915n},pa=new globalThis.TextEncoder;function _f(r,t){let e=jo[t],n=ha[t];for(let o=0;o<r.length;o++)n^=BigInt(r[o]),n=BigInt.asUintN(t,n*e);return n}function Af(r,t,e){if(e.length===0)throw new Error("The `utf8Buffer` option must have a length greater than zero");let n=jo[t],o=ha[t],s=r;for(;s.length>0;){let i=pa.encodeInto(s,e);s=s.slice(i.read);for(let c=0;c<i.written;c++)o^=BigInt(e[c]),o=BigInt.asUintN(t,o*n)}return o}function Go(r,{size:t=32,utf8Buffer:e}={}){if(!jo[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 Af(r,t,e);r=pa.encode(r)}return _f(r,t)}var fr={hash:r=>Number(Go(r,{size:32})),hashV:(r,t)=>If(fr.hash(r,t))};function If(r){let t=r.toString(16);return t.length%2===1&&(t=`0${t}`),$(t,"base16")}var Zo=64,vt=class{fp;h;seed;constructor(t,e,n,o=2){if(o>Zo)throw new TypeError("Invalid Fingerprint Size");let s=e.hashV(t,n),i=wt(o);for(let c=0;c<i.length;c++)i[c]=s[c];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?lt(this.fp,t.fp):!1}};function ue(r,t){return Math.floor(Math.random()*(t-r))+r}var fe=class{contents;constructor(t){this.contents=new Array(t).fill(null)}has(t){if(!(t instanceof vt))throw new TypeError("Invalid Fingerprint");return this.contents.some(e=>t.equals(e))}add(t){if(!(t instanceof vt))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 vt))throw new TypeError("Invalid Fingerprint");let e=ue(0,this.contents.length-1),n=this.contents[e];return this.contents[e]=t,n}remove(t){if(!(t instanceof vt))throw new TypeError("Invalid Fingerprint");let e=this.contents.findIndex(n=>t.equals(n));return e>-1?(this.contents[e]=null,!0):!1}};var Lf=500,lr=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??fr,this.seed=t.seed??ue(0,Math.pow(2,10))}add(t){typeof t=="string"&&(t=$(t));let e=new vt(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 fe(this.bucketSize)),this.buckets[o]==null&&(this.buckets[o]=new fe(this.bucketSize)),this.buckets[n].add(e)||this.buckets[o].add(e))return this.count++,!0;let s=[n,o],i=s[ue(0,s.length-1)];this.buckets[i]==null&&(this.buckets[i]=new fe(this.bucketSize));for(let c=0;c<Lf;c++){let a=this.buckets[i].swap(e);if(a!=null&&(i=(i^a.hash())%this.filterSize,this.buckets[i]==null&&(this.buckets[i]=new fe(this.bucketSize)),this.buckets[i].add(a)))return this.count++,!0}return!1}has(t){typeof t=="string"&&(t=$(t));let e=new vt(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=$(t));let e=new vt(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}},Bf={1:.5,2:.84,4:.95,8:.98};function Tf(r=.001){return r>.002?2:r>1e-5?4:8}function ma(r,t=.001){let e=Tf(t),n=Bf[e],o=Math.round(r/n),s=Math.min(Math.ceil(Math.log2(1/t)+Math.log2(2*e)),Zo);return{filterSize:o,bucketSize:e,fingerprintSize:s}}var Jr=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??fr,this.seed=t.seed??ue(0,Math.pow(2,10)),this.filterSeries=[new lr({filterSize:this.filterSize,bucketSize:this.bucketSize,fingerprintSize:this.fingerprintSize,hash:this.hash,seed:this.seed})]}add(t){if(typeof t=="string"&&(t=$(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 lr({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=$(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=$(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 Yo(r,t=.001,e){return new Jr({...ma(r,t),...e??{}})}function _t(r){let t=r.getComponents(),e={},n=0;if(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)throw new ft(`Multiaddr ${r} was not an IPv4, IPv6, DNS, DNS4, DNS6 or DNSADDR address`);return t[n]?.name==="tls"&&t[n+1]?.name==="sni"&&(e.sni=t[n+1].value,n+=2),e}var tn=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,c=this.peekChar();if(c===void 0)return;let a=c==="0",u=2**(8*o)-1;for(;;){let l=this.readAtomically(()=>{let f=this.readChar();if(f===void 0)return;let d=Number.parseInt(f,t);if(!Number.isNaN(d))return d});if(l===void 0)break;if(s*=t,s+=l,s>u||(i+=1,e!==void 0&&i>e))return}if(i!==0)return!n&&a&&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),[c]=t(s.subarray(0,i));return e.set(s.subarray(0,c),16-c),e})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var ga=45,Df=15,Oe=new tn;function en(r){if(!(r.length>Df))return Oe.new(r).parseWith(()=>Oe.readIPv4Addr())}function rn(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>ga))return Oe.new(r).parseWith(()=>Oe.readIPv6Addr())}function Ne(r,t=!1){if(r.includes("%")&&(r=r.split("%")[0]),r.length>ga)return;let e=Oe.new(r).parseWith(()=>Oe.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 ba(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 ya(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 Xo(r){switch(r.length){case le: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 xa(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 wa(r){let t="0x";for(let e of r)t+=(e>>4).toString(16)+(e&15).toString(16);return t}var le=4,de=16,Dg=parseInt("0xFFFF",16),Cf=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function dr(r,t){t.length===de&&r.length===le&&ba(t,0,11)&&(t=t.slice(12)),t.length===le&&r.length===de&&ya(r,Cf,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 Ea(r,t){if(typeof t=="string"&&(t=Ne(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 Wo(r){let[t,e]=r.split("/");if(!t||!e)throw new Error("Failed to parse given CIDR: "+r);let n=le,o=en(t);if(o==null&&(n=de,o=rn(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=Qo(s,8*n);return{network:dr(o,i),mask:i}}function Qo(r,t){if(t!==8*le&&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 hr=class{constructor(t,e){if(e==null)({network:this.network,mask:this.mask}=Wo(t));else{let n=Ne(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=Ne(e);if(s==null)throw new Error("Failed to parse mask");this.mask=s}else this.mask=Qo(o,8*n.length);this.network=dr(n,this.mask)}}contains(t){return Ea({network:this.network,mask:this.mask},t)}toString(){let t=xa(this.mask),e=t!==-1?String(t):wa(this.mask);return Xo(this.network)+"/"+e}};function Sa(r,t){return new hr(r).contains(t)}function va(r){try{let t=_t(r);switch(t.type){case"ip6":return Sa("2000::/3",t.host);default:return!1}}catch{return!1}}function ke(r){return!!en(r)}function nn(r){return!!rn(r)}var Aa=tc(_a(),1),Rf=["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"],Pf=Rf.map(r=>new Aa.Netmask(r));function Jo(r){for(let t of Pf)if(t.contains(r))return!0;return!1}function Of(r){return/^::ffff:([0-9a-fA-F]{1,4}):([0-9a-fA-F]{1,4})$/.test(r)}function Nf(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 Jo(o)}function kf(r){return/^::ffff:([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(r)}function Uf(r){let t=r.split(":"),e=t[t.length-1];return Jo(e)}function Mf(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 Ia(r){if(ke(r))return Jo(r);if(Of(r))return Nf(r);if(kf(r))return Uf(r);if(nn(r))return Mf(r)}function ts(r){try{let t=_t(r);switch(t.type){case"ip4":case"ip6":return Ia(t.host)??!1;default:return t.host==="localhost"}}catch{return!1}}function Ue(){let r={};return r.promise=new Promise((t,e)=>{r.resolve=t,r.reject=e}),r}var on=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}},Me=class{size;hwm;head;tail;constructor(t={}){this.hwm=t.splitLimit??16,this.head=new on(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 on(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 es=class extends Error{type;code;constructor(t,e){super(t??"The operation was aborted"),this.type="aborted",this.code=e??"ABORT_ERR"}};function sn(r={}){return Kf(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 Kf(r,t){t=t??{};let e=t.onEnd,n=new Me,o,s,i,c=Ue(),a=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((g,x)=>{s=A=>{s=null,n.push(A);try{g(r(n))}catch(w){x(w)}return o}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{c.resolve(),c=Ue()})}},u=g=>s!=null?s(g):(n.push(g),o),l=g=>(n=new Me,s!=null?s({error:g}):(n.push({error:g}),o)),f=g=>{if(i)return o;if(t?.objectMode!==!0&&g?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return u({done:!1,value:g})},d=g=>i?o:(i=!0,g!=null?l(g):u({done:!0})),p=()=>(n=new Me,d(),{done:!0}),h=g=>(d(g),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:a,return:p,throw:h,push:f,end:d,get readableLength(){return n.size},onEmpty:async g=>{let x=g?.signal;if(x?.throwIfAborted(),n.isEmpty())return;let A,w;x!=null&&(A=new Promise((I,P)=>{w=()=>{P(new es)},x.addEventListener("abort",w)}));try{await Promise.race([c.promise,A])}finally{w!=null&&x!=null&&x?.removeEventListener("abort",w)}}},e==null)return o;let v=o;return o={[Symbol.asyncIterator](){return this},next(){return v.next()},throw(g){return v.throw(g),e!=null&&(e(g),e=void 0),{done:!0}},return(){return v.return(),e!=null&&(e(),e=void 0),{done:!0}},push:f,end(g){return v.end(g),e!=null&&(e(g),e=void 0),o},get readableLength(){return v.readableLength},onEmpty:g=>v.onEmpty(g)},o}var rs=class extends Error{constructor(t){super(t),this.name="TimeoutError"}},ns=class extends Error{constructor(t){super(),this.name="AbortError",this.message=t}},La=r=>globalThis.DOMException===void 0?new ns(r):new DOMException(r),Ba=r=>{let t=r.reason===void 0?La("This operation was aborted."):r.reason;return t instanceof Error?t:La(t)};function os(r,t){let{milliseconds:e,fallback:n,message:o,customTimers:s={setTimeout,clearTimeout}}=t,i,c,u=new Promise((l,f)=>{if(typeof e!="number"||Math.sign(e)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${e}\``);if(t.signal){let{signal:p}=t;p.aborted&&f(Ba(p)),c=()=>{f(Ba(p))},p.addEventListener("abort",c,{once:!0})}if(e===Number.POSITIVE_INFINITY){r.then(l,f);return}let d=new rs;i=s.setTimeout.call(void 0,()=>{if(n){try{l(n())}catch(p){f(p)}return}typeof r.cancel=="function"&&r.cancel(),o===!1?l():o instanceof Error?f(o):(d.message=o??`Promise timed out after ${e} milliseconds`,f(d))},e),(async()=>{try{l(await r)}catch(p){f(p)}})()}).finally(()=>{u.clear(),c&&t.signal&&t.signal.removeEventListener("abort",c)});return u.clear=()=>{s.clearTimeout.call(void 0,i),i=void 0},u}var Ff=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 qf(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 c=[t].flat(),a=[],{addListener:u,removeListener:l}=Ff(r),f=async(...p)=>{let h=e.multiArgs?p:p[0];if(e.filter)try{if(!await e.filter(h))return}catch(v){n(),i(v);return}a.push(h),e.count===a.length&&(n(),s(a))},d=(...p)=>{n(),i(e.rejectionMultiArgs?p:p[0])};n=()=>{for(let p of c)l(p,f);for(let p of e.rejectionEvents)c.includes(p)||l(p,d)};for(let p of c)u(p,f);for(let p of e.rejectionEvents)c.includes(p)||u(p,d);e.signal&&e.signal.addEventListener("abort",()=>{d(e.signal.reason)},{once:!0}),e.resolveImmediately&&s(a)});if(o.cancel=n,typeof e.timeout=="number"){let s=os(o,{milliseconds:e.timeout});return s.cancel=()=>{n(),s.clear()},s}return o}function Ke(r,t,e){typeof e=="function"&&(e={filter:e}),e={...e,count:1,resolveImmediately:!1};let n=qf(r,t,e),o=n.then(s=>s[0]);return o.cancel=n.cancel,o}function mr(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 an=class extends Error{static name="QueueFullError";constructor(t="The queue was full"){super(t),this.name="QueueFullError"}},he=class extends Error{static name="UnexpectedEOFError";name="UnexpectedEOFError"};function zf(r){return r.reason}async function cn(r,t,e){if(t==null)return r;let n=e?.translateError??zf;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 un=class{deferred;signal;constructor(t){this.signal=t,this.deferred=Ue(),this.onAbort=this.onAbort.bind(this),this.signal?.addEventListener("abort",this.onAbort)}onAbort(){this.deferred.reject(this.signal?.reason??new Bt)}cleanup(){this.signal?.removeEventListener("abort",this.onAbort)}};function Vf(){return`${parseInt(String(Math.random()*1e9),10).toString()}${Date.now()}`}var fn=class{id;fn;options;recipients;status;timeline;controller;constructor(t,e){this.id=Vf(),this.status="queued",this.fn=t,this.options=e,this.recipients=[],this.timeline={created:Date.now()},this.controller=new AbortController,this.controller.signal,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 Bt),this.cleanup())}async join(t={}){let e=new un(t.signal);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 cn(this.fn({...this.options??{},signal:this.controller.signal}),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 ln=class extends Er{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=mr(this.emitEmpty.bind(this),1),this.emitIdle=mr(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 an;let n=new fn(t,e);return this.enqueue(n),this.safeDispatchEvent("add"),this.tryToStartAnother(),n.join(e).then(o=>(this.safeDispatchEvent("completed",{detail:o}),this.safeDispatchEvent("success",{detail:{job:n,result:o}}),o)).catch(o=>{if(n.status==="queued"){for(let s=0;s<this.queue.length;s++)if(this.queue[s]===n){this.queue.splice(s,1);break}}throw this.safeDispatchEvent("failure",{detail:{job:n,error:o}}),o})}clear(){this.queue.splice(0,this.queue.length)}abort(){this.queue.forEach(t=>{t.abort(new Bt)}),this.clear()}async onEmpty(t){this.size!==0&&await Ke(this,"empty",t)}async onSizeLessThan(t,e){this.size<t||await Ke(this,"next",{...e,filter:()=>this.size<t})}async onIdle(t){this.pending===0&&this.size===0||await Ke(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=sn({objectMode:!0}),n=a=>{a!=null?this.abort():this.clear(),e.end(a)},o=a=>{a.detail!=null&&e.push(a.detail)},s=a=>{n(a.detail.error)},i=()=>{n()},c=()=>{n(new Bt("Queue aborted"))};this.addEventListener("completed",o),this.addEventListener("failure",s),this.addEventListener("idle",i),t?.signal?.addEventListener("abort",c);try{yield*e}finally{this.removeEventListener("completed",o),this.removeEventListener("failure",s),this.removeEventListener("idle",i),t?.signal?.removeEventListener("abort",c),n()}}};function dn(r){let t=new globalThis.AbortController;function e(){t.abort();for(let s of r)s?.removeEventListener!=null&&s.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 st=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},qt=class extends Error{static name="ValidationError";name="ValidationError"},hn=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},pn=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};function is(r){return t=>Q(t,r)}function as(r){return t=>$(t,r)}function Fe(r){return new DataView(r.buffer).getUint16(r.byteOffset).toString()}function pe(r){let t=new ArrayBuffer(2);return new DataView(t).setUint16(0,typeof r=="string"?parseInt(r):r),new Uint8Array(t)}function Ta(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=$(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=pe(n);return Dt([e,o],e.length+o.length)}function Da(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=Ht.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=pe(n);return Dt([e,o],e.length+o.length)}function cs(r){let t=r.subarray(0,r.length-2),e=r.subarray(r.length-2),n=Q(t,"base32"),o=Fe(e);return`${n}:${o}`}var us=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 st("Invalid byte value in IP address");t[n]=o}),t},Ca=function(r){let t=0;r=r.toString().trim();let e=r.split(":",8),n;for(n=0;n<e.length;n++){let s=ke(e[n]),i;s&&(i=us(e[n]),e[n]=Q(i.subarray(0,2),"base16")),i!=null&&++n<8&&e.splice(n,0,Q(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 st("Invalid byte value in IP address");o[t++]=s>>8&255,o[t++]=s&255}return o},Ra=function(r){if(r.byteLength!==4)throw new st("IPv4 address was incorrect length");let t=[];for(let e=0;e<r.byteLength;e++)t.push(r[e]);return t.join(".")},Pa=function(r){if(r.byteLength!==16)throw new st("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 st(`Invalid IPv6 address "${e}"`)}};function Oa(r){try{let t=new URL(`http://[${r}]`);return t.hostname.substring(1,t.hostname.length-1)}catch{throw new st(`Invalid IPv6 address "${r}"`)}}var ss=Object.values(Ge).map(r=>r.decoder),Hf=(function(){let r=ss[0].or(ss[1]);return ss.slice(2).forEach(t=>r=r.or(t)),r})();function Na(r){return Hf.decode(r)}function ka(r){return t=>r.encoder.encode(t)}function $f(r){if(parseInt(r).toString()!==r)throw new qt("Value must be an integer")}function jf(r){if(r<0)throw new qt("Value must be a positive integer, or zero")}function Gf(r){return t=>{if(t>r)throw new qt(`Value must be smaller than or equal to ${r}`)}}function Zf(...r){return t=>{for(let e of r)e(t)}}var gr=Zf($f,jf,Gf(65535));var rt=-1,fs=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 pn(`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 fs,Ol=[{code:4,name:"ip4",size:32,valueToBytes:us,bytesToValue:Ra,validate:r=>{if(!ke(r))throw new qt(`Invalid IPv4 address "${r}"`)}},{code:6,name:"tcp",size:16,valueToBytes:pe,bytesToValue:Fe,validate:gr},{code:273,name:"udp",size:16,valueToBytes:pe,bytesToValue:Fe,validate:gr},{code:33,name:"dccp",size:16,valueToBytes:pe,bytesToValue:Fe,validate:gr},{code:41,name:"ip6",size:128,valueToBytes:Ca,bytesToValue:Pa,stringToValue:Oa,validate:r=>{if(!nn(r))throw new qt(`Invalid IPv6 address "${r}"`)}},{code:42,name:"ip6zone",size:rt},{code:43,name:"ipcidr",size:8,bytesToValue:is("base10"),valueToBytes:as("base10")},{code:53,name:"dns",size:rt},{code:54,name:"dns4",size:rt},{code:55,name:"dns6",size:rt},{code:56,name:"dnsaddr",size:rt},{code:132,name:"sctp",size:16,valueToBytes:pe,bytesToValue:Fe,validate:gr},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:rt,stringToValue:r=>decodeURIComponent(r),valueToString:r=>encodeURIComponent(r)},{code:421,name:"p2p",aliases:["ipfs"],size:rt,bytesToValue:is("base58btc"),valueToBytes:r=>r.startsWith("Q")||r.startsWith("1")?as("base58btc")(r):at.parse(r).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:cs,valueToBytes:Ta},{code:445,name:"onion3",size:296,bytesToValue:cs,valueToBytes:Da},{code:446,name:"garlic64",size:rt},{code:447,name:"garlic32",size:rt},{code:448,name:"tls"},{code:449,name:"sni",size:rt},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:rt,bytesToValue:ka(Nn),valueToBytes:Na},{code:480,name:"http"},{code:481,name:"http-path",size:rt,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:rt}];Ol.forEach(r=>{zt.addProtocol(r)});function Ua(r){let t=[],e=0;for(;e<r.length;){let n=sr(r,e),o=zt.getProtocol(n),s=mt(n),i=Nl(o,r,e+s),c=0;i>0&&o.size===rt&&(c=mt(i));let a=s+c+i,u={code:n,name:o.name,bytes:r.subarray(e,e+a)};if(i>0){let l=e+s+c,f=r.subarray(l,l+i);u.value=o.bytesToValue?.(f)??Q(f)}t.push(u),e+=a}return t}function Ma(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,c=0,a=0;n.value!=null&&(i=o.valueToBytes?.(n.value)??$(n.value),c=i.byteLength,o.size===rt&&(a=mt(c)));let u=new Uint8Array(s+a+c),l=0;Te(n.code,u,l),l+=s,i!=null&&(o.size===rt&&(Te(c,u,l),l+=a),u.set(i,l)),n.bytes=u}e.push(n.bytes),t+=n.bytes.byteLength}return Dt(e,t)}function Ka(r){if(r.charAt(0)!=="/")throw new st('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 c=s===r.length-1;if(i==="/"||c){let a=zt.getProtocol(o);if(e==="protocol"){if(a.size==null||a.size===0){t.push({code:a.code,name:a.name}),n="",o="",e="protocol";continue}else if(c)throw new st(`Component ${o} was missing value`);e="value"}else if(e==="value"){let u={code:a.code,name:a.name};if(a.size!=null&&a.size!==0){if(n==="")throw new st(`Component ${o} was missing value`);u.value=a.stringToValue?.(n)??n}t.push(u),n="",o="",e="protocol"}}}if(o!==""&&n!=="")throw new st("Incomplete multiaddr");return t}function Fa(r){return`/${r.flatMap(t=>{if(t.value==null)return t.name;let e=zt.getProtocol(t.code);if(e==null)throw new st(`Unknown protocol code ${t.code}`);return[t.name,e.valueToString?.(t.value)??t.value]}).join("/")}`}function Nl(r,t,e){return r.size==null||r.size===0?0:r.size>0?r.size/8:sr(t,e)}var kl=Symbol.for("nodejs.util.inspect.custom"),ls=Symbol.for("@multiformats/multiaddr");function Ul(r){if(r==null&&(r="/"),qa(r))return r.getComponents();if(r instanceof Uint8Array)return Ua(r);if(typeof r=="string")return r=r.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),r===""&&(r="/"),Ka(r);if(Array.isArray(r))return r;throw new st("Must be a string, Uint8Array, Component[], or another Multiaddr")}var gn=class r{[ls]=!0;#t;#e;#r;constructor(t="/",e={}){this.#t=Ul(t),e.validate!==!1&&Ml(this)}get bytes(){return this.#r==null&&(this.#r=Ma(this.#t)),this.#r}toString(){return this.#e==null&&(this.#e=Fa(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 hn(`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 lt(this.bytes,t.bytes)}[kl](){return`Multiaddr(${this.toString()})`}};function Ml(r){r.getComponents().forEach(t=>{let e=zt.getProtocol(t.code);t.value!=null&&e.validate?.(t.value)})}function qa(r){return!!r?.[ls]}function za(r){return new gn(r)}var Kl=4194304,bn=class extends Error{static name="UnwrappedError";name="UnwrappedError"},hs=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},ps=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},ms=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function Fl(r){return typeof r?.closeRead=="function"}function ql(r){return typeof r?.close=="function"}function ds(r){return Fl(r)?r.remoteWriteStatus!=="writable"&&r.readBufferLength===0:ql(r)?r.status!=="open":!1}function zl(r){return r?.addEventListener!=null&&r?.removeEventListener!=null&&r?.send!=null&&r?.push!=null&&r?.log!=null}function Vl(r,t){let e=t?.maxBufferSize??Kl,n=new J,o,s=!1;if(!zl(r))throw new ft("Argument should be a Stream or a Multiaddr");let i=l=>{if(n.append(l.data),n.byteLength>e){let f=n.byteLength;n.consume(n.byteLength),o?.reject(new Error(`Read buffer overflow - ${f} > ${e}`))}o?.resolve()};r.addEventListener("message",i);let c=l=>{l.error!=null?o?.reject(l.error):o?.resolve()};r.addEventListener("close",c);let a=()=>{o?.resolve()};r.addEventListener("remoteCloseWrite",a);let u={readBuffer:n,async read(l){if(s===!0)throw new bn("Stream was unwrapped");if(ds(r)){if(l?.bytes==null)return null;if(n.byteLength<l.bytes)throw r.log.error("closed after reading %d/%d bytes",n.byteLength,l.bytes),new he(`Unexpected EOF - stream closed after reading ${n.byteLength}/${l.bytes} bytes`)}let f=l?.bytes??1;for(o=Promise.withResolvers();;){if(n.byteLength>=f){o.resolve();break}if(await cn(o.promise,l?.signal),ds(r)){if(n.byteLength===0&&l?.bytes==null)return null;break}o=Promise.withResolvers()}let d=l?.bytes??n.byteLength;if(n.byteLength<d){if(ds(r))throw r.log.error("closed while reading %d/%d bytes",n.byteLength,d),new he(`Unexpected EOF - stream closed while reading ${n.byteLength}/${d} bytes`);return u.read(l)}let p=n.sublist(0,d);return n.consume(d),p},async write(l,f){if(s===!0)throw new bn("Stream was unwrapped");r.send(l)||await Ke(r,"drain",{signal:f?.signal,rejectionEvents:["close"]})},unwrap(){return s||(s=!0,r.removeEventListener("message",i),r.removeEventListener("close",c),r.removeEventListener("remoteCloseWrite",a),n.byteLength>0&&(r.log("stream unwrapped with %d unread bytes",n.byteLength),r.push(n))),r}};return u}function Hl(r,t={}){let e=Vl(r,t);t.maxDataLength!=null&&t.maxLengthLength==null&&(t.maxLengthLength=mt(t.maxDataLength));let n=t?.lengthDecoder??sr,o=t?.lengthEncoder??Hi;return{async read(i){let c=-1,a=new J;for(;;){let l=await e.read({...i,bytes:1});if(l==null)break;a.append(l);try{c=n(a)}catch(f){if(f instanceof RangeError)continue;throw f}if(c<0)throw new hs("Invalid message length");if(t?.maxLengthLength!=null&&a.byteLength>t.maxLengthLength)throw new ms(`Message length length too long - ${a.byteLength} > ${t.maxLengthLength}`);if(c>-1)break}if(t?.maxDataLength!=null&&c>t.maxDataLength)throw new ps(`Message length too long - ${c} > ${t.maxDataLength}`);let u=await e.read({...i,bytes:c});if(u==null)throw r.log.error("tried to read %d bytes but the stream closed",c),new he(`Unexpected EOF - tried to read ${c} bytes but the stream closed`);if(u.byteLength!==c)throw r.log.error("read %d/%d bytes before the stream closed",u.byteLength,c),new he(`Unexpected EOF - read ${u.byteLength}/${c} bytes before the stream closed`);return u},async write(i,c){await e.write(new J(o(i.byteLength),i),c)},async writeV(i,c){let a=new J(...i.flatMap(u=>[o(u.byteLength),u]));await e.write(a,c)},unwrap(){return e.unwrap()}}}function gs(r,t){let e=Hl(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(c=>s.encode(c)),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 yn=class extends ln{has(t){return this.find(t)!=null}find(t){return this.queue.find(e=>t.equals(e.options.peerId))}};function Va(r,t,e){let n,o,s=!1;function i(){let u={signal:o.signal};if(e?.timeout!=null){let l=dn([o.signal,AbortSignal.timeout(e.timeout)]);u.signal=l}s=!0,Promise.resolve().then(async()=>{await r(u)}).catch(()=>{}).finally(()=>{s=!1,!o.signal.aborted&&(n=setTimeout(i,t))})}let c=mr(i,e?.debounce??100),a=!1;return{setInterval:u=>{t!==u&&(t=u,n!=null&&(clearTimeout(n),n=setTimeout(i,t)))},setTimeout:u=>{e??={},e.timeout=u},run:()=>{s||(clearTimeout(n),c())},start:()=>{a||(a=!0,o=new AbortController,o.signal,e?.runImmediately===!0?queueMicrotask(()=>{i()}):n=setTimeout(i,t))},stop:()=>{clearTimeout(n),o?.abort(),a=!1}}}var bs=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 Ha(r){let{name:t,metrics:e}=r,n;return e!=null?n=new bs({name:t,metrics:e}):n=new Map,n}var $a="libp2p",ja="autonat",Ga="1.0.0";var z;(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=()=>Ce(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=()=>Ce(o)})(n=r.ResponseStatus||(r.ResponseStatus={}));let s;(function(u){let l;u.codec=()=>(l==null&&(l=Kt((f,d,p={})=>{if(p.lengthDelimited!==!1&&d.fork(),f.id!=null&&(d.uint32(10),d.bytes(f.id)),f.addrs!=null)for(let h of f.addrs)d.uint32(18),d.bytes(h);p.lengthDelimited!==!1&&d.ldelim()},(f,d,p={})=>{let h={addrs:[]},v=d==null?f.len:f.pos+d;for(;f.pos<v;){let g=f.uint32();switch(g>>>3){case 1:{h.id=f.bytes();break}case 2:{if(p.limits?.addrs!=null&&h.addrs.length===p.limits.addrs)throw new zr('Decode error - map field "addrs" had too many elements');h.addrs.push(f.bytes());break}default:{f.skipType(g&7);break}}}return h})),l),u.encode=f=>Mt(f,u.codec()),u.decode=(f,d)=>Ut(f,u.codec(),d)})(s=r.PeerInfo||(r.PeerInfo={}));let i;(function(u){let l;u.codec=()=>(l==null&&(l=Kt((f,d,p={})=>{p.lengthDelimited!==!1&&d.fork(),f.peer!=null&&(d.uint32(10),r.PeerInfo.codec().encode(f.peer,d)),p.lengthDelimited!==!1&&d.ldelim()},(f,d,p={})=>{let h={},v=d==null?f.len:f.pos+d;for(;f.pos<v;){let g=f.uint32();switch(g>>>3){case 1:{h.peer=r.PeerInfo.codec().decode(f,f.uint32(),{limits:p.limits?.peer});break}default:{f.skipType(g&7);break}}}return h})),l),u.encode=f=>Mt(f,u.codec()),u.decode=(f,d)=>Ut(f,u.codec(),d)})(i=r.Dial||(r.Dial={}));let c;(function(u){let l;u.codec=()=>(l==null&&(l=Kt((f,d,p={})=>{p.lengthDelimited!==!1&&d.fork(),f.status!=null&&(d.uint32(8),r.ResponseStatus.codec().encode(f.status,d)),f.statusText!=null&&(d.uint32(18),d.string(f.statusText)),f.addr!=null&&(d.uint32(26),d.bytes(f.addr)),p.lengthDelimited!==!1&&d.ldelim()},(f,d,p={})=>{let h={},v=d==null?f.len:f.pos+d;for(;f.pos<v;){let g=f.uint32();switch(g>>>3){case 1:{h.status=r.ResponseStatus.codec().decode(f);break}case 2:{h.statusText=f.string();break}case 3:{h.addr=f.bytes();break}default:{f.skipType(g&7);break}}}return h})),l),u.encode=f=>Mt(f,u.codec()),u.decode=(f,d)=>Ut(f,u.codec(),d)})(c=r.DialResponse||(r.DialResponse={}));let a;r.codec=()=>(a==null&&(a=Kt((u,l,f={})=>{f.lengthDelimited!==!1&&l.fork(),u.type!=null&&(l.uint32(8),r.MessageType.codec().encode(u.type,l)),u.dial!=null&&(l.uint32(18),r.Dial.codec().encode(u.dial,l)),u.dialResponse!=null&&(l.uint32(26),r.DialResponse.codec().encode(u.dialResponse,l)),f.lengthDelimited!==!1&&l.ldelim()},(u,l,f={})=>{let d={},p=l==null?u.len:u.pos+l;for(;u.pos<p;){let h=u.uint32();switch(h>>>3){case 1:{d.type=r.MessageType.codec().decode(u);break}case 2:{d.dial=r.Dial.codec().decode(u,u.uint32(),{limits:f.limits?.dial});break}case 3:{d.dialResponse=r.DialResponse.codec().decode(u,u.uint32(),{limits:f.limits?.dialResponse});break}default:{u.skipType(h&7);break}}}return d})),a),r.encode=u=>Mt(u,r.codec()),r.decode=(u,l)=>Ut(u,r.codec(),l)})(z||(z={}));var Xl=4,Wl=8,xn=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??$a}/${ja}/${Ga}`,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=Ha({name:"libp2p_autonat_dial_results",metrics:t.metrics}),this.findPeers=Va(this.findRandomPeers.bind(this),6e4),this.addressFilter=Yo(1024)}[Symbol.toStringTag]="@libp2p/autonat";[Es]=["@libp2p/autonat"];get[Ss](){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=dn([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=gs(t,{maxDataLength:this.maxMessageSize}).pb(z),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(f=>_t(f).host),s=t.dial;if(s==null)return this.log.error("dial was missing from message"),{type:z.MessageType.DIAL_RESPONSE,dialResponse:{status:z.ResponseStatus.E_BAD_REQUEST,statusText:"No Dial message found in message"}};let i,c=s.peer;if(c?.id==null)return this.log.error("peerId missing from message"),{type:z.MessageType.DIAL_RESPONSE,dialResponse:{status:z.ResponseStatus.E_BAD_REQUEST,statusText:"missing peer info"}};try{let f=Jt(c.id);i=Xr(f)}catch(f){return this.log.error("invalid PeerId - %e",f),{type:z.MessageType.DIAL_RESPONSE,dialResponse:{status:z.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:z.MessageType.DIAL_RESPONSE,dialResponse:{status:z.ResponseStatus.E_BAD_REQUEST,statusText:"peer id mismatch"}};let a=c.addrs.map(f=>za(f)).filter(f=>{try{let d=_t(f);return ts(f)?!1:d.host!==_t(e.remoteAddr).host?(this.log.trace("not dialing %a - target host did not match remote host %a",f,e.remoteAddr),!1):o.includes(d.host)?!1:this.components.transportManager.dialTransportForMultiaddr(f)==null?(this.log.trace("not dialing %a - transport unsupported",f),!1):!0}catch{return!1}}).map(f=>(f.getComponents().find(d=>d.code===421)?.value==null&&(f=f.encapsulate(`/p2p/${i.toString()}`)),f));if(a.length===0)return this.log("refused to dial all multiaddrs for %p from message",i),{type:z.MessageType.DIAL_RESPONSE,dialResponse:{status:z.ResponseStatus.E_DIAL_REFUSED,statusText:"no dialable addresses"}};this.log("dial multiaddrs %s for peer %p",a.map(f=>f.toString()).join(", "),i);let u="",l=a[0];for(let f of a){let d;l=f;try{if(d=await this.components.connectionManager.openConnection(f,n),!d.remoteAddr.equals(f))throw this.log.error("tried to dial %a but dialed %a",f,d.remoteAddr),new Error("Unexpected remote address");return this.log("successfully dialed %p via %a",i,f),{type:z.MessageType.DIAL_RESPONSE,dialResponse:{status:z.ResponseStatus.OK,addr:d.remoteAddr.decapsulateCode(421).bytes}}}catch(p){this.log.error("could not dial %p - %e",i,p),u=p.message}finally{d!=null&&await d.close()}}return{type:z.MessageType.DIAL_RESPONSE,dialResponse:{status:z.ResponseStatus.E_DIAL_ERROR,statusText:u,addr:l.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())||_t(o.multiaddr).type==="ip6"&&(!e||!va(o.multiaddr))||ts(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 c=o.expires<Date.now();if(c&&this.addressFilter.remove?.(s),this.addressFilter.has(s))continue;this.addressFilter.add(s),this.log.trace("creating dial result %s %s",c?"to revalidate":"for",s),i={multiaddr:o.multiaddr,success:0,failure:0,networkSegments:[],verifyingPeers:$o(),queue:new yn({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})=>_t(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 c=gs(i).pb(z),[,a]=await Promise.all([c.write({type:z.MessageType.DIAL,dial:{peer:{id:this.components.peerId.toMultihash().bytes,addrs:[n.multiaddr.bytes]}}},{signal:s}),c.read({signal:s})]);if(a.type!==z.MessageType.DIAL_RESPONSE||a.dialResponse==null){this.log("invalid autonat response from %p - %j",t.remotePeer,a);return}let u=a.dialResponse.status;if(this.log.trace("autonat response from %p for %a is %s",t.remotePeer,n.multiaddr,u),u!==z.ResponseStatus.OK&&u!==z.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,a.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),u===z.ResponseStatus.OK){if(o.success++,o.type!=="observed"){this.confirmAddress(o);return}}else u===z.ResponseStatus.E_DIAL_ERROR&&o.failure++;this.log("%a success %d failure %d",o.multiaddr,o.success,o.failure),o.success===Xl&&this.confirmAddress(o),o.failure===Wl&&this.unconfirmAddress(o)}finally{try{await i.close({signal:s})}catch(c){i.abort(c)}}}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=_t(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 ft(`Remote address ${t} was not an IPv4 or Ipv6 address`)}}};function Ql(r={}){return t=>new xn(t,r)}return ec(Jl);})();
2
+ "use strict";var Libp2PAutonat=(()=>{var Za=Object.create;var xr=Object.defineProperty;var Ya=Object.getOwnPropertyDescriptor;var Xa=Object.getOwnPropertyNames;var Wa=Object.getPrototypeOf,Qa=Object.prototype.hasOwnProperty;var Ja=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports),gt=(r,t)=>{for(var e in t)xr(r,e,{get:t[e],enumerable:!0})},ws=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Xa(t))!Qa.call(r,o)&&o!==e&&xr(r,o,{get:()=>t[o],enumerable:!(n=Ya(t,o))||n.enumerable});return r};var tc=(r,t,e)=>(e=r!=null?Za(Wa(r)):{},ws(t||!r||!r.__esModule?xr(e,"default",{value:r,enumerable:!0}):e,r)),ec=r=>ws(xr({},"__esModule",{value:!0}),r);var _a=Ja(pr=>{(function(){var r,t,e,n,o,s,i,c;c=function(a){var u,l,f,d;return u=(a&255<<24)>>>24,l=(a&255<<16)>>>16,f=(a&65280)>>>8,d=a&255,[u,l,f,d].join(".")},i=function(a){var u,l,f,d,p,h;for(u=[],f=d=0;d<=3&&a.length!==0;f=++d){if(f>0){if(a[0]!==".")throw new Error("Invalid IP");a=a.substring(1)}h=t(a),p=h[0],l=h[1],a=a.substring(l),u.push(p)}if(a.length!==0)throw new Error("Invalid IP");switch(u.length){case 1:if(u[0]>4294967295)throw new Error("Invalid IP");return u[0]>>>0;case 2:if(u[0]>255||u[1]>16777215)throw new Error("Invalid IP");return(u[0]<<24|u[1])>>>0;case 3:if(u[0]>255||u[1]>255||u[2]>65535)throw new Error("Invalid IP");return(u[0]<<24|u[1]<<16|u[2])>>>0;case 4:if(u[0]>255||u[1]>255||u[2]>255||u[3]>255)throw new Error("Invalid IP");return(u[0]<<24|u[1]<<16|u[2]<<8|u[3])>>>0;default:throw new Error("Invalid IP")}},e=function(a){return a.charCodeAt(0)},n=e("0"),s=e("a"),o=e("A"),t=function(a){var u,l,f,d,p;for(d=0,u=10,l="9",f=0,a.length>1&&a[f]==="0"&&(a[f+1]==="x"||a[f+1]==="X"?(f+=2,u=16):"0"<=a[f+1]&&a[f+1]<="9"&&(f++,u=8,l="7")),p=f;f<a.length;){if("0"<=a[f]&&a[f]<=l)d=d*u+(e(a[f])-n)>>>0;else if(u===16)if("a"<=a[f]&&a[f]<="f")d=d*u+(10+e(a[f])-s)>>>0;else if("A"<=a[f]&&a[f]<="F")d=d*u+(10+e(a[f])-o)>>>0;else break;else break;if(d>4294967295)throw new Error("too large");f++}if(f===p)throw new Error("empty octet");return[d,f]},r=(function(){function a(u,l){var f,d,p,h;if(typeof u!="string")throw new Error("Missing `net' parameter");if(l||(h=u.split("/",2),u=h[0],l=h[1]),l||(l=32),typeof l=="string"&&l.indexOf(".")>-1){try{this.maskLong=i(l)}catch(v){throw f=v,new Error("Invalid mask: "+l)}for(d=p=32;p>=0;d=--p)if(this.maskLong===4294967295<<32-d>>>0){this.bitmask=d;break}}else if(l||l===0)this.bitmask=parseInt(l,10),this.maskLong=0,this.bitmask>0&&(this.maskLong=4294967295<<32-this.bitmask>>>0);else throw new Error("Invalid mask: empty");try{this.netLong=(i(u)&this.maskLong)>>>0}catch(v){throw f=v,new Error("Invalid net address: "+u)}if(!(this.bitmask<=32))throw new Error("Invalid mask for ip4: "+l);this.size=Math.pow(2,32-this.bitmask),this.base=c(this.netLong),this.mask=c(this.maskLong),this.hostmask=c(~this.maskLong),this.first=this.bitmask<=30?c(this.netLong+1):this.base,this.last=this.bitmask<=30?c(this.netLong+this.size-2):c(this.netLong+this.size-1),this.broadcast=this.bitmask<=30?c(this.netLong+this.size-1):void 0}return a.prototype.contains=function(u){return typeof u=="string"&&(u.indexOf("/")>0||u.split(".").length!==4)&&(u=new a(u)),u instanceof a?this.contains(u.base)&&this.contains(u.broadcast||u.last):(i(u)&this.maskLong)>>>0===(this.netLong&this.maskLong)>>>0},a.prototype.next=function(u){return u==null&&(u=1),new a(c(this.netLong+this.size*u),this.mask)},a.prototype.forEach=function(u){var l,f,d;for(d=i(this.first),f=i(this.last),l=0;d<=f;)u(c(d),d,l),l++,d++},a.prototype.toString=function(){return this.base+"/"+this.bitmask},a})(),pr.ip2long=i,pr.long2ip=c,pr.Netmask=r}).call(pr)});var Jl={};gt(Jl,{autoNAT:()=>Ql});var Bt=class extends Error{static name="AbortError";constructor(t="The operation was aborted"){super(t),this.name="AbortError"}};var ft=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},wr=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var Er=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}};var qe=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var wn=Symbol.for("@libp2p/peer-id");var Sr=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){super.addEventListener(t,e,n);let o=this.#t.get(t);o==null&&(o=[],this.#t.set(t,o)),o.push({callback:e,once:(n!==!0&&n!==!1&&n?.once)??!1})}removeEventListener(t,e,n){super.removeEventListener(t.toString(),e??null,n);let o=this.#t.get(t);o!=null&&(o=o.filter(({callback:s})=>s!==e),this.#t.set(t,o))}dispatchEvent(t){let e=super.dispatchEvent(t),n=this.#t.get(t.type);return n==null||(n=n.filter(({once:o})=>!o),this.#t.set(t.type,n)),e}safeDispatchEvent(t,e={}){return this.dispatchEvent(new CustomEvent(t,e))}};var Es=Symbol.for("@libp2p/service-capabilities"),Ss=Symbol.for("@libp2p/service-dependencies");var An={};gt(An,{base58btc:()=>X,base58flickr:()=>cc});var Td=new Uint8Array(0);function vs(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 Tt(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 _s(r){return new TextEncoder().encode(r)}function As(r){return new TextDecoder().decode(r)}function rc(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 c=r.length,a=r.charAt(0),u=Math.log(c)/Math.log(256),l=Math.log(256)/Math.log(c);function f(h){if(h instanceof Uint8Array||(ArrayBuffer.isView(h)?h=new Uint8Array(h.buffer,h.byteOffset,h.byteLength):Array.isArray(h)&&(h=Uint8Array.from(h))),!(h instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(h.length===0)return"";for(var v=0,g=0,x=0,A=h.length;x!==A&&h[x]===0;)x++,v++;for(var w=(A-x)*l+1>>>0,I=new Uint8Array(w);x!==A;){for(var P=h[x],U=0,M=w-1;(P!==0||U<g)&&M!==-1;M--,U++)P+=256*I[M]>>>0,I[M]=P%c>>>0,P=P/c>>>0;if(P!==0)throw new Error("Non-zero carry");g=U,x++}for(var S=w-g;S!==w&&I[S]===0;)S++;for(var E=a.repeat(v);S<w;++S)E+=r.charAt(I[S]);return E}function d(h){if(typeof h!="string")throw new TypeError("Expected String");if(h.length===0)return new Uint8Array;var v=0;if(h[v]!==" "){for(var g=0,x=0;h[v]===a;)g++,v++;for(var A=(h.length-v)*u+1>>>0,w=new Uint8Array(A);h[v];){var I=e[h.charCodeAt(v)];if(I===255)return;for(var P=0,U=A-1;(I!==0||P<x)&&U!==-1;U--,P++)I+=c*w[U]>>>0,w[U]=I%256>>>0,I=I/256>>>0;if(I!==0)throw new Error("Non-zero carry");x=P,v++}if(h[v]!==" "){for(var M=A-x;M!==A&&w[M]===0;)M++;for(var S=new Uint8Array(g+(A-M)),E=g;M!==A;)S[E++]=w[M++];return S}}}function p(h){var v=d(h);if(v)return v;throw new Error(`Non-${t} character`)}return{encode:f,decodeUnsafe:d,decode:p}}var nc=rc,oc=nc,Ls=oc;var En=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")}},Sn=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 Bs(this,t)}},vn=class{decoders;constructor(t){this.decoders=t}or(t){return Bs(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 Bs(r,t){return new vn({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var _n=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 En(t,e,n),this.decoder=new Sn(t,e,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function me({name:r,prefix:t,encode:e,decode:n}){return new _n(r,t,e,n)}function Vt({name:r,prefix:t,alphabet:e}){let{encode:n,decode:o}=Ls(e,r);return me({prefix:t,name:r,encode:n,decode:s=>Tt(o(s))})}function sc(r,t,e,n){let o=r.length;for(;r[o-1]==="=";)--o;let s=new Uint8Array(o*e/8|0),i=0,c=0,a=0;for(let u=0;u<o;++u){let l=t[r[u]];if(l===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<e|l,i+=e,i>=8&&(i-=8,s[a++]=255&c>>i)}if(i>=e||(255&c<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function ic(r,t,e){let n=t[t.length-1]==="=",o=(1<<e)-1,s="",i=0,c=0;for(let a=0;a<r.length;++a)for(c=c<<8|r[a],i+=8;i>e;)i-=e,s+=t[o&c>>i];if(i!==0&&(s+=t[o&c<<e-i]),n)for(;(s.length*e&7)!==0;)s+="=";return s}function ac(r){let t={};for(let e=0;e<r.length;++e)t[r[e]]=e;return t}function Y({name:r,prefix:t,bitsPerChar:e,alphabet:n}){let o=ac(n);return me({prefix:t,name:r,encode(s){return ic(s,n,e)},decode(s){return sc(s,o,e,r)}})}var X=Vt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),cc=Vt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var In={};gt(In,{base32:()=>Ht,base32hex:()=>dc,base32hexpad:()=>pc,base32hexpadupper:()=>mc,base32hexupper:()=>hc,base32pad:()=>fc,base32padupper:()=>lc,base32upper:()=>uc,base32z:()=>gc});var Ht=Y({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),uc=Y({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),fc=Y({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),lc=Y({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),dc=Y({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),hc=Y({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),pc=Y({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),mc=Y({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),gc=Y({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Ln={};gt(Ln,{base36:()=>ze,base36upper:()=>bc});var ze=Vt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),bc=Vt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var yc=Cs,Ts=128,xc=127,wc=~xc,Ec=Math.pow(2,31);function Cs(r,t,e){t=t||[],e=e||0;for(var n=e;r>=Ec;)t[e++]=r&255|Ts,r/=128;for(;r&wc;)t[e++]=r&255|Ts,r>>>=7;return t[e]=r|0,Cs.bytes=e-n+1,t}var Sc=Bn,vc=128,Ds=127;function Bn(r,n){var e=0,n=n||0,o=0,s=n,i,c=r.length;do{if(s>=c)throw Bn.bytes=0,new RangeError("Could not decode varint");i=r[s++],e+=o<28?(i&Ds)<<o:(i&Ds)*Math.pow(2,o),o+=7}while(i>=vc);return Bn.bytes=s-n,e}var _c=Math.pow(2,7),Ac=Math.pow(2,14),Ic=Math.pow(2,21),Lc=Math.pow(2,28),Bc=Math.pow(2,35),Tc=Math.pow(2,42),Dc=Math.pow(2,49),Cc=Math.pow(2,56),Rc=Math.pow(2,63),Pc=function(r){return r<_c?1:r<Ac?2:r<Ic?3:r<Lc?4:r<Bc?5:r<Tc?6:r<Dc?7:r<Cc?8:r<Rc?9:10},Oc={encode:yc,decode:Sc,encodingLength:Pc},Nc=Oc,Ve=Nc;function He(r,t=0){return[Ve.decode(r,t),Ve.decode.bytes]}function ge(r,t,e=0){return Ve.encode(r,t,e),t}function be(r){return Ve.encodingLength(r)}function xe(r,t){let e=t.byteLength,n=be(r),o=n+be(e),s=new Uint8Array(o+e);return ge(r,s,0),ge(e,s,n),s.set(t,o),new ye(r,e,t,s)}function Jt(r){let t=Tt(r),[e,n]=He(t),[o,s]=He(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new ye(e,o,i,t)}function Rs(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&vs(r.bytes,e.bytes)}}var ye=class{code;size;digest;bytes;constructor(t,e,n,o){this.code=t,this.size=e,this.digest=n,this.bytes=o}};function Ps(r,t){let{bytes:e,version:n}=r;switch(n){case 0:return Uc(e,Tn(r),t??X.encoder);default:return Mc(e,Tn(r),t??Ht.encoder)}}var Os=new WeakMap;function Tn(r){let t=Os.get(r);if(t==null){let e=new Map;return Os.set(r,e),e}return t}var at=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!==$e)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==Kc)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=xe(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&&Rs(t.multihash,n.multihash)}toString(t){return Ps(this,t)}toJSON(){return{"/":Ps(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??Ns(n,o,s.bytes))}else if(e[Fc]===!0){let{version:n,multihash:o,code:s}=e,i=Jt(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!==$e)throw new Error(`Version 0 CID must use dag-pb (code: ${$e}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let o=Ns(t,e,n.bytes);return new r(t,e,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,$e,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=Tt(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 ye(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[f,d]=He(t.subarray(e));return e+=d,f},o=n(),s=$e;if(o===18?(o=0,e=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=e,c=n(),a=n(),u=e+a,l=u-i;return{version:o,codec:s,multihashCode:c,digestSize:a,multihashSize:l,size:u}}static parse(t,e){let[n,o]=kc(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 Tn(s).set(n,t),s}};function kc(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 Ht.prefix:{let e=t??Ht;return[Ht.prefix,e.decode(r)]}case ze.prefix:{let e=t??ze;return[ze.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 Uc(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 Mc(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 $e=112,Kc=18;function Ns(r,t,e){let n=be(r),o=n+be(t),s=new Uint8Array(o+e.byteLength);return ge(r,s,0),ge(t,s,n),s.set(e,o),s}var Fc=Symbol.for("@ipld/js-cid/CID");var Dn={};gt(Dn,{identity:()=>xt});var ks=0,qc="identity",Us=Tt;function zc(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 xe(ks,Us(r))}var xt={code:ks,name:qc,encode:Us,digest:zc};function lt(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 wt(r=0){return new Uint8Array(r)}function ht(r=0){return new Uint8Array(r)}function Dt(r,t){t==null&&(t=r.reduce((o,s)=>o+s.length,0));let e=ht(t),n=0;for(let o of r)e.set(o,n),n+=o.length;return e}var Ks=Symbol.for("@achingbrain/uint8arraylist");function Ms(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 _r(r){return!!r?.[Ks]}var J=class r{bufs;length;[Ks]=!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(_r(n))e+=n.byteLength,this.bufs.push(...n.bufs);else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}prepend(...t){this.prependAll(t)}prependAll(t){let e=0;for(let n of t.reverse())if(n instanceof Uint8Array)e+=n.byteLength,this.bufs.unshift(n);else if(_r(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=Ms(this.bufs,t);return e.buf[e.index]}set(t,e){let n=Ms(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(_r(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 Dt(n,o)}subarray(t,e){let{bufs:n,length:o}=this._subList(t,e);return n.length===1?n[0]:Dt(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],c=o,a=c+i.byteLength;if(o=a,t>=a)continue;let u=t>=c&&t<a,l=e>c&&e<=a;if(u&&l){if(t===c&&e===a){n.push(i);break}let f=t-c;n.push(i.subarray(f,f+(e-t)));break}if(u){if(t===0){n.push(i);continue}n.push(i.subarray(t-c));continue}if(l){if(e===a){n.push(i);break}n.push(i.subarray(0,e-c));break}n.push(i)}return{bufs:n,length:e-t}}indexOf(t,e=0){if(!_r(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 f=0;f<s;f++)i[f]=-1;for(let f=0;f<o;f++)i[n[f]]=f;let c=i,a=this.byteLength-n.byteLength,u=n.byteLength-1,l;for(let f=e;f<=a;f+=l){l=0;for(let d=u;d>=0;d--){let p=this.get(f+d);if(n[d]!==p){l=Math.max(1,d-c[p]);break}}if(l===0)return f}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=ht(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=wt(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=wt(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=wt(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=ht(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=wt(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=wt(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=wt(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=wt(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=wt(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(!lt(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 Cn={};gt(Cn,{base10:()=>Vc});var Vc=Vt({prefix:"9",name:"base10",alphabet:"0123456789"});var Rn={};gt(Rn,{base16:()=>Hc,base16upper:()=>$c});var Hc=Y({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),$c=Y({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Pn={};gt(Pn,{base2:()=>jc});var jc=Y({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var On={};gt(On,{base256emoji:()=>Wc});var Fs=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}"),Gc=Fs.reduce((r,t,e)=>(r[e]=t,r),[]),Zc=Fs.reduce((r,t,e)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return r[n]=e,r},[]);function Yc(r){return r.reduce((t,e)=>(t+=Gc[e],t),"")}function Xc(r){let t=[];for(let e of r){let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);let o=Zc[n];if(o==null)throw new Error(`Non-base256emoji character: ${e}`);t.push(o)}return new Uint8Array(t)}var Wc=me({prefix:"\u{1F680}",name:"base256emoji",encode:Yc,decode:Xc});var kn={};gt(kn,{base64:()=>Qc,base64pad:()=>Jc,base64url:()=>Nn,base64urlpad:()=>tu});var Qc=Y({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Jc=Y({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Nn=Y({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),tu=Y({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Un={};gt(Un,{base8:()=>eu});var eu=Y({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Mn={};gt(Mn,{identity:()=>ru});var ru=me({prefix:"\0",name:"identity",encode:r=>As(r),decode:r=>_s(r)});var dh=new TextEncoder,hh=new TextDecoder;var qn={};gt(qn,{sha256:()=>je,sha512:()=>iu});var su=20;function Fn({name:r,code:t,encode:e,minDigestLength:n,maxDigestLength:o}){return new Kn(r,t,e,n,o)}var Kn=class{name;code;encode;minDigestLength;maxDigestLength;constructor(t,e,n,o,s){this.name=t,this.code=e,this.encode=n,this.minDigestLength=o??su,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?qs(n,this.code,e?.truncate):n.then(o=>qs(o,this.code,e?.truncate))}else throw Error("Unknown type, must be binary type")}};function qs(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 xe(t,r)}function Vs(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var je=Fn({name:"sha2-256",code:18,encode:Vs("SHA-256")}),iu=Fn({name:"sha2-512",code:19,encode:Vs("SHA-512")});var Ge={...Mn,...Pn,...Un,...Cn,...Rn,...In,...Ln,...An,...kn,...On},Ah={...qn,...Dn};function $s(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var Hs=$s("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),zn=$s("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=ht(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),au={utf8:Hs,"utf-8":Hs,hex:Ge.base16,latin1:zn,ascii:zn,binary:zn,...Ge},Ar=au;function $(r,t="utf8"){let e=Ar[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.decoder.decode(`${e.prefix}${r}`)}function Q(r,t="utf8"){let e=Ar[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.encoder.encode(r).substring(1)}var cu=parseInt("11111",2),Vn=parseInt("10000000",2),uu=parseInt("01111111",2),js={0:Ze,1:Ze,2:fu,3:hu,4:pu,5:du,6:lu,16:Ze,22:Ze,48:Ze};function Hn(r,t={offset:0}){let e=r[t.offset]&cu;if(t.offset++,js[e]!=null)return js[e](r,t);throw new Error("No decoder for tag "+e)}function Ye(r,t){let e=0;if((r[t.offset]&Vn)===Vn){let n=r[t.offset]&uu,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 Ze(r,t){Ye(r,t);let e=[];for(;!(t.offset>=r.byteLength);){let n=Hn(r,t);if(n===null)break;e.push(n)}return e}function fu(r,t){let e=Ye(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 lu(r,t){let e=Ye(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 c=`${s}.${i}`,a=[];for(;t.offset<n;){let u=r[t.offset];if(t.offset++,a.push(u&127),u<128){a.reverse();let l=0;for(let f=0;f<a.length;f++)l+=a[f]<<f*7;c+=`.${l}`,a=[]}}return c}function du(r,t){return t.offset++,null}function hu(r,t){let e=Ye(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 pu(r,t){let e=Ye(r,t),n=r.subarray(t.offset,t.offset+e);return t.offset+=e,n}function mu(r){let t=r.toString(16);t.length%2===1&&(t="0"+t);let e=new J;for(let n=0;n<t.length;n+=2)e.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return e}function $n(r){if(r.byteLength<128)return Uint8Array.from([r.byteLength]);let t=mu(r.byteLength);return new J(Uint8Array.from([t.byteLength|Vn]),t)}function Gs(r){let t=new J,e=128;return(r.subarray()[0]&e)===e&&t.append(Uint8Array.from([0])),t.append(r),new J(Uint8Array.from([2]),$n(t),t)}function Zs(r){let t=Uint8Array.from([0]),e=new J(t,r);return new J(Uint8Array.from([3]),$n(e),e)}function Ir(r,t=48){let e=new J;for(let n of r)e.append(n);return new J(Uint8Array.from([t]),$n(e),e)}async function Ys(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,t,e.subarray());return n?.signal?.throwIfAborted(),s}var gu=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),bu=Uint8Array.from([6,5,43,129,4,0,34]),yu=Uint8Array.from([6,5,43,129,4,0,35]),xu={ext:!0,kty:"EC",crv:"P-256"},wu={ext:!0,kty:"EC",crv:"P-384"},Eu={ext:!0,kty:"EC",crv:"P-521"},jn=32,Gn=48,Zn=66;function Xs(r){let t=Hn(r);return Ws(t)}function Ws(r){let t=r[1][1][0],e=1,n,o;if(t.byteLength===jn*2+1)return n=Q(t.subarray(e,e+jn),"base64url"),o=Q(t.subarray(e+jn),"base64url"),new we({...xu,key_ops:["verify"],x:n,y:o});if(t.byteLength===Gn*2+1)return n=Q(t.subarray(e,e+Gn),"base64url"),o=Q(t.subarray(e+Gn),"base64url"),new we({...wu,key_ops:["verify"],x:n,y:o});if(t.byteLength===Zn*2+1)return n=Q(t.subarray(e,e+Zn),"base64url"),o=Q(t.subarray(e+Zn),"base64url"),new we({...Eu,key_ops:["verify"],x:n,y:o});throw new ft(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function Qs(r){return Ir([Gs(Uint8Array.from([1])),Ir([Su(r.crv)],160),Ir([Zs(new J(Uint8Array.from([4]),$(r.x??"","base64url"),$(r.y??"","base64url")))],161)]).subarray()}function Su(r){if(r==="P-256")return gu;if(r==="P-384")return bu;if(r==="P-521")return yu;throw new ft(`Invalid curve ${r}`)}var we=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=Qs(this.jwk)),this._raw}toMultihash(){return xt.digest(Ee(this))}toCID(){return at.createV1(114,this.toMultihash())}toString(){return X.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:lt(this.raw,t.raw)}async verify(t,e,n){return Ys(this.jwk,e,t,n)}};function te(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function It(r,t=""){if(!Number.isSafeInteger(r)||r<0){let e=t&&`"${t}" `;throw new Error(`${e}expected integer >= 0, got ${r}`)}}function k(r,t,e=""){let n=te(r),o=r?.length,s=t!==void 0;if(!n||s&&o!==t){let i=e&&`"${e}" `,c=s?` of length ${t}`:"",a=n?`length=${o}`:`type=${typeof r}`;throw new Error(i+"expected Uint8Array"+c+", got "+a)}return r}function Lr(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash must wrapped by utils.createHasher");It(r.outputLen),It(r.blockLen)}function Se(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 ti(r,t){k(r,void 0,"digestInto() output");let e=t.outputLen;if(r.length<e)throw new Error('"digestInto() output" expected to be of length >='+e)}function Rt(...r){for(let t=0;t<r.length;t++)r[t].fill(0)}function Br(r){return new DataView(r.buffer,r.byteOffset,r.byteLength)}function Et(r,t){return r<<32-t|r>>>t}var ei=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",vu=Array.from({length:256},(r,t)=>t.toString(16).padStart(2,"0"));function Pt(r){if(k(r),ei)return r.toHex();let t="";for(let e=0;e<r.length;e++)t+=vu[r[e]];return t}var Ct={_0:48,_9:57,A:65,F:70,a:97,f:102};function Js(r){if(r>=Ct._0&&r<=Ct._9)return r-Ct._0;if(r>=Ct.A&&r<=Ct.F)return r-(Ct.A-10);if(r>=Ct.a&&r<=Ct.f)return r-(Ct.a-10)}function Ot(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);if(ei)return Uint8Array.fromHex(r);let t=r.length,e=t/2;if(t%2)throw new Error("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=Js(r.charCodeAt(s)),c=Js(r.charCodeAt(s+1));if(i===void 0||c===void 0){let a=r[s]+r[s+1];throw new Error('hex string expected, got non-hex character "'+a+'" at index '+s)}n[o]=i*16+c}return n}function pt(...r){let t=0;for(let n=0;n<r.length;n++){let o=r[n];k(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 Yn(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.create=o=>r(o),Object.assign(e,t),Object.freeze(e)}function ve(r=32){let t=typeof globalThis=="object"?globalThis.crypto:null;if(typeof t?.getRandomValues!="function")throw new Error("crypto.getRandomValues must be defined");return t.getRandomValues(new Uint8Array(r))}var Xn=r=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,r])});function ri(r,t,e){return r&t^~r&e}function ni(r,t,e){return r&t^r&e^t&e}var Xe=class{blockLen;outputLen;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=Br(this.buffer)}update(t){Se(this),k(t);let{view:e,buffer:n,blockLen:o}=this,s=t.length;for(let i=0;i<s;){let c=Math.min(o-this.pos,s-i);if(c===o){let a=Br(t);for(;o<=s-i;i+=o)this.process(a,i);continue}n.set(t.subarray(i,i+c),this.pos),this.pos+=c,i+=c,this.pos===o&&(this.process(e,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){Se(this),ti(t,this),this.finished=!0;let{buffer:e,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;e[i++]=128,Rt(this.buffer.subarray(i)),this.padOffset>o-i&&(this.process(n,0),i=0);for(let f=i;f<o;f++)e[f]=0;n.setBigUint64(o-8,BigInt(this.length*8),s),this.process(n,0);let c=Br(t),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen must be aligned to 32bit");let u=a/4,l=this.get();if(u>l.length)throw new Error("_sha2: outputLen bigger than state");for(let f=0;f<u;f++)c.setUint32(4*f,l[f],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:c}=this;return t.destroyed=i,t.finished=s,t.length=o,t.pos=c,o%e&&t.buffer.set(n),t}clone(){return this._cloneInto()}},Nt=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var ot=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var Tr=BigInt(4294967295),oi=BigInt(32);function _u(r,t=!1){return t?{h:Number(r&Tr),l:Number(r>>oi&Tr)}:{h:Number(r>>oi&Tr)|0,l:Number(r&Tr)|0}}function si(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:c}=_u(r[s],t);[n[s],o[s]]=[i,c]}return[n,o]}var Wn=(r,t,e)=>r>>>e,Qn=(r,t,e)=>r<<32-e|t>>>e,ee=(r,t,e)=>r>>>e|t<<32-e,re=(r,t,e)=>r<<32-e|t>>>e,We=(r,t,e)=>r<<64-e|t>>>e-32,Qe=(r,t,e)=>r>>>e-32|t<<64-e;function Lt(r,t,e,n){let o=(t>>>0)+(n>>>0);return{h:r+e+(o/2**32|0)|0,l:o|0}}var ii=(r,t,e)=>(r>>>0)+(t>>>0)+(e>>>0),ai=(r,t,e,n)=>t+e+n+(r/2**32|0)|0,ci=(r,t,e,n)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0),ui=(r,t,e,n,o)=>t+e+n+o+(r/2**32|0)|0,fi=(r,t,e,n,o)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0)+(o>>>0),li=(r,t,e,n,o,s)=>t+e+n+o+s+(r/2**32|0)|0;var Iu=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]),jt=new Uint32Array(64),Jn=class extends Xe{constructor(t){super(64,t,8,!1)}get(){let{A:t,B:e,C:n,D:o,E:s,F:i,G:c,H:a}=this;return[t,e,n,o,s,i,c,a]}set(t,e,n,o,s,i,c,a){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=c|0,this.H=a|0}process(t,e){for(let f=0;f<16;f++,e+=4)jt[f]=t.getUint32(e,!1);for(let f=16;f<64;f++){let d=jt[f-15],p=jt[f-2],h=Et(d,7)^Et(d,18)^d>>>3,v=Et(p,17)^Et(p,19)^p>>>10;jt[f]=v+jt[f-7]+h+jt[f-16]|0}let{A:n,B:o,C:s,D:i,E:c,F:a,G:u,H:l}=this;for(let f=0;f<64;f++){let d=Et(c,6)^Et(c,11)^Et(c,25),p=l+d+ri(c,a,u)+Iu[f]+jt[f]|0,v=(Et(n,2)^Et(n,13)^Et(n,22))+ni(n,o,s)|0;l=u,u=a,a=c,c=i+p|0,i=s,s=o,o=n,n=p+v|0}n=n+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,c=c+this.E|0,a=a+this.F|0,u=u+this.G|0,l=l+this.H|0,this.set(n,o,s,i,c,a,u,l)}roundClean(){Rt(jt)}destroy(){this.set(0,0,0,0,0,0,0,0),Rt(this.buffer)}},to=class extends Jn{A=Nt[0]|0;B=Nt[1]|0;C=Nt[2]|0;D=Nt[3]|0;E=Nt[4]|0;F=Nt[5]|0;G=Nt[6]|0;H=Nt[7]|0;constructor(){super(32)}};var di=si(["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))),Lu=di[0],Bu=di[1],Gt=new Uint32Array(80),Zt=new Uint32Array(80),eo=class extends Xe{constructor(t){super(128,t,16,!1)}get(){let{Ah:t,Al:e,Bh:n,Bl:o,Ch:s,Cl:i,Dh:c,Dl:a,Eh:u,El:l,Fh:f,Fl:d,Gh:p,Gl:h,Hh:v,Hl:g}=this;return[t,e,n,o,s,i,c,a,u,l,f,d,p,h,v,g]}set(t,e,n,o,s,i,c,a,u,l,f,d,p,h,v,g){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=c|0,this.Dl=a|0,this.Eh=u|0,this.El=l|0,this.Fh=f|0,this.Fl=d|0,this.Gh=p|0,this.Gl=h|0,this.Hh=v|0,this.Hl=g|0}process(t,e){for(let w=0;w<16;w++,e+=4)Gt[w]=t.getUint32(e),Zt[w]=t.getUint32(e+=4);for(let w=16;w<80;w++){let I=Gt[w-15]|0,P=Zt[w-15]|0,U=ee(I,P,1)^ee(I,P,8)^Wn(I,P,7),M=re(I,P,1)^re(I,P,8)^Qn(I,P,7),S=Gt[w-2]|0,E=Zt[w-2]|0,O=ee(S,E,19)^We(S,E,61)^Wn(S,E,6),K=re(S,E,19)^Qe(S,E,61)^Qn(S,E,6),D=ci(M,K,Zt[w-7],Zt[w-16]),b=ui(D,U,O,Gt[w-7],Gt[w-16]);Gt[w]=b|0,Zt[w]=D|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:c,Cl:a,Dh:u,Dl:l,Eh:f,El:d,Fh:p,Fl:h,Gh:v,Gl:g,Hh:x,Hl:A}=this;for(let w=0;w<80;w++){let I=ee(f,d,14)^ee(f,d,18)^We(f,d,41),P=re(f,d,14)^re(f,d,18)^Qe(f,d,41),U=f&p^~f&v,M=d&h^~d&g,S=fi(A,P,M,Bu[w],Zt[w]),E=li(S,x,I,U,Lu[w],Gt[w]),O=S|0,K=ee(n,o,28)^We(n,o,34)^We(n,o,39),D=re(n,o,28)^Qe(n,o,34)^Qe(n,o,39),b=n&s^n&c^s&c,y=o&i^o&a^i&a;x=v|0,A=g|0,v=p|0,g=h|0,p=f|0,h=d|0,{h:f,l:d}=Lt(u|0,l|0,E|0,O|0),u=c|0,l=a|0,c=s|0,a=i|0,s=n|0,i=o|0;let m=ii(O,D,y);n=ai(m,E,K,b),o=m|0}({h:n,l:o}=Lt(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=Lt(this.Bh|0,this.Bl|0,s|0,i|0),{h:c,l:a}=Lt(this.Ch|0,this.Cl|0,c|0,a|0),{h:u,l}=Lt(this.Dh|0,this.Dl|0,u|0,l|0),{h:f,l:d}=Lt(this.Eh|0,this.El|0,f|0,d|0),{h:p,l:h}=Lt(this.Fh|0,this.Fl|0,p|0,h|0),{h:v,l:g}=Lt(this.Gh|0,this.Gl|0,v|0,g|0),{h:x,l:A}=Lt(this.Hh|0,this.Hl|0,x|0,A|0),this.set(n,o,s,i,c,a,u,l,f,d,p,h,v,g,x,A)}roundClean(){Rt(Gt,Zt)}destroy(){Rt(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},ro=class extends eo{Ah=ot[0]|0;Al=ot[1]|0;Bh=ot[2]|0;Bl=ot[3]|0;Ch=ot[4]|0;Cl=ot[5]|0;Dh=ot[6]|0;Dl=ot[7]|0;Eh=ot[8]|0;El=ot[9]|0;Fh=ot[10]|0;Fl=ot[11]|0;Gh=ot[12]|0;Gl=ot[13]|0;Hh=ot[14]|0;Hl=ot[15]|0;constructor(){super(64)}};var hi=Yn(()=>new to,Xn(1));var pi=Yn(()=>new ro,Xn(3));var oo=BigInt(0),no=BigInt(1);function kt(r,t=""){if(typeof r!="boolean"){let e=t&&`"${t}" `;throw new Error(e+"expected boolean, got type="+typeof r)}return r}function mi(r){if(typeof r=="bigint"){if(!Dr(r))throw new Error("positive bigint expected, got "+r)}else It(r);return r}function Je(r){let t=mi(r).toString(16);return t.length&1?"0"+t:t}function gi(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return r===""?oo:BigInt("0x"+r)}function _e(r){return gi(Pt(r))}function ne(r){return gi(Pt(Rr(k(r)).reverse()))}function Cr(r,t){It(t),r=mi(r);let e=Ot(r.toString(16).padStart(t*2,"0"));if(e.length!==t)throw new Error("number too large");return e}function so(r,t){return Cr(r,t).reverse()}function Rr(r){return Uint8Array.from(r)}var Dr=r=>typeof r=="bigint"&&oo<=r;function Tu(r,t,e){return Dr(r)&&Dr(t)&&Dr(e)&&t<=r&&r<e}function tr(r,t,e,n){if(!Tu(t,e,n))throw new Error("expected valid "+r+": "+e+" <= n < "+n+", got "+t)}function io(r){let t;for(t=0;r>oo;r>>=no,t+=1);return t}var er=r=>(no<<BigInt(r))-no;function bi(r,t,e){if(It(r,"hashLen"),It(t,"qByteLen"),typeof e!="function")throw new Error("hmacFn must be a function");let n=g=>new Uint8Array(g),o=Uint8Array.of(),s=Uint8Array.of(0),i=Uint8Array.of(1),c=1e3,a=n(r),u=n(r),l=0,f=()=>{a.fill(1),u.fill(0),l=0},d=(...g)=>e(u,pt(a,...g)),p=(g=o)=>{u=d(s,g),a=d(),g.length!==0&&(u=d(i,g),a=d())},h=()=>{if(l++>=c)throw new Error("drbg: tried max amount of iterations");let g=0,x=[];for(;g<t;){a=d();let A=a.slice();x.push(A),g+=a.length}return pt(...x)};return(g,x)=>{f(),p(g);let A;for(;!(A=x(h()));)p();return f(),A}}function Yt(r,t={},e={}){if(!r||typeof r!="object")throw new Error("expected valid options object");function n(s,i,c){let a=r[s];if(c&&a===void 0)return;let u=typeof a;if(u!==i||a===null)throw new Error(`param "${s}" is invalid: expected ${i}, got ${u}`)}let o=(s,i)=>Object.entries(s).forEach(([c,a])=>n(c,a,i));o(t,!1),o(e,!0)}function Ae(r){let t=new WeakMap;return(e,...n)=>{let o=t.get(e);if(o!==void 0)return o;let s=r(e,...n);return t.set(e,s),s}}var dt=BigInt(0),tt=BigInt(1),oe=BigInt(2),wi=BigInt(3),Ei=BigInt(4),Si=BigInt(5),Du=BigInt(7),vi=BigInt(8),Cu=BigInt(9),_i=BigInt(16);function W(r,t){let e=r%t;return e>=dt?e:t+e}function H(r,t,e){let n=r;for(;t-- >dt;)n*=n,n%=e;return n}function yi(r,t){if(r===dt)throw new Error("invert: expected non-zero number");if(t<=dt)throw new Error("invert: expected positive modulus, got "+t);let e=W(r,t),n=t,o=dt,s=tt,i=tt,c=dt;for(;e!==dt;){let u=n/e,l=n%e,f=o-i*u,d=s-c*u;n=e,e=l,o=i,s=c,i=f,c=d}if(n!==tt)throw new Error("invert: does not exist");return W(o,t)}function co(r,t,e){if(!r.eql(r.sqr(t),e))throw new Error("Cannot find square root")}function Ai(r,t){let e=(r.ORDER+tt)/Ei,n=r.pow(t,e);return co(r,n,t),n}function Ru(r,t){let e=(r.ORDER-Si)/vi,n=r.mul(t,oe),o=r.pow(n,e),s=r.mul(t,o),i=r.mul(r.mul(s,oe),o),c=r.mul(s,r.sub(i,r.ONE));return co(r,c,t),c}function Pu(r){let t=Ie(r),e=Ii(r),n=e(t,t.neg(t.ONE)),o=e(t,n),s=e(t,t.neg(n)),i=(r+Du)/_i;return(c,a)=>{let u=c.pow(a,i),l=c.mul(u,n),f=c.mul(u,o),d=c.mul(u,s),p=c.eql(c.sqr(l),a),h=c.eql(c.sqr(f),a);u=c.cmov(u,l,p),l=c.cmov(d,f,h);let v=c.eql(c.sqr(l),a),g=c.cmov(u,l,v);return co(c,g,a),g}}function Ii(r){if(r<wi)throw new Error("sqrt is not defined for small field");let t=r-tt,e=0;for(;t%oe===dt;)t/=oe,e++;let n=oe,o=Ie(r);for(;xi(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(e===1)return Ai;let s=o.pow(n,t),i=(t+tt)/oe;return function(a,u){if(a.is0(u))return u;if(xi(a,u)!==1)throw new Error("Cannot find square root");let l=e,f=a.mul(a.ONE,s),d=a.pow(u,t),p=a.pow(u,i);for(;!a.eql(d,a.ONE);){if(a.is0(d))return a.ZERO;let h=1,v=a.sqr(d);for(;!a.eql(v,a.ONE);)if(h++,v=a.sqr(v),h===l)throw new Error("Cannot find square root");let g=tt<<BigInt(l-h-1),x=a.pow(f,g);l=h,f=a.sqr(x),d=a.mul(d,f),p=a.mul(p,x)}return p}}function Ou(r){return r%Ei===wi?Ai:r%vi===Si?Ru:r%_i===Cu?Pu(r):Ii(r)}var Li=(r,t)=>(W(r,t)&tt)===tt,Nu=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function uo(r){let t={ORDER:"bigint",BYTES:"number",BITS:"number"},e=Nu.reduce((n,o)=>(n[o]="function",n),t);return Yt(r,e),r}function ku(r,t,e){if(e<dt)throw new Error("invalid exponent, negatives unsupported");if(e===dt)return r.ONE;if(e===tt)return t;let n=r.ONE,o=t;for(;e>dt;)e&tt&&(n=r.mul(n,o)),o=r.sqr(o),e>>=tt;return n}function rr(r,t,e=!1){let n=new Array(t.length).fill(e?r.ZERO:void 0),o=t.reduce((i,c,a)=>r.is0(c)?i:(n[a]=i,r.mul(i,c)),r.ONE),s=r.inv(o);return t.reduceRight((i,c,a)=>r.is0(c)?i:(n[a]=r.mul(i,n[a]),r.mul(i,c)),s),n}function xi(r,t){let e=(r.ORDER-tt)/oe,n=r.pow(t,e),o=r.eql(n,r.ONE),s=r.eql(n,r.ZERO),i=r.eql(n,r.neg(r.ONE));if(!o&&!s&&!i)throw new Error("invalid Legendre symbol result");return o?1:s?0:-1}function Uu(r,t){t!==void 0&&It(t);let e=t!==void 0?t:r.toString(2).length,n=Math.ceil(e/8);return{nBitLength:e,nByteLength:n}}var ao=class{ORDER;BITS;BYTES;isLE;ZERO=dt;ONE=tt;_lengths;_sqrt;_mod;constructor(t,e={}){if(t<=dt)throw new Error("invalid field: expected ORDER > 0, got "+t);let n;this.isLE=!1,e!=null&&typeof e=="object"&&(typeof e.BITS=="number"&&(n=e.BITS),typeof e.sqrt=="function"&&(this.sqrt=e.sqrt),typeof e.isLE=="boolean"&&(this.isLE=e.isLE),e.allowedLengths&&(this._lengths=e.allowedLengths?.slice()),typeof e.modFromBytes=="boolean"&&(this._mod=e.modFromBytes));let{nBitLength:o,nByteLength:s}=Uu(t,n);if(s>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");this.ORDER=t,this.BITS=o,this.BYTES=s,this._sqrt=void 0,Object.preventExtensions(this)}create(t){return W(t,this.ORDER)}isValid(t){if(typeof t!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof t);return dt<=t&&t<this.ORDER}is0(t){return t===dt}isValidNot0(t){return!this.is0(t)&&this.isValid(t)}isOdd(t){return(t&tt)===tt}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 ku(this,t,e)}div(t,e){return W(t*yi(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 yi(t,this.ORDER)}sqrt(t){return this._sqrt||(this._sqrt=Ou(this.ORDER)),this._sqrt(this,t)}toBytes(t){return this.isLE?so(t,this.BYTES):Cr(t,this.BYTES)}fromBytes(t,e=!1){k(t);let{_lengths:n,BYTES:o,isLE:s,ORDER:i,_mod:c}=this;if(n){if(!n.includes(t.length)||t.length>o)throw new Error("Field.fromBytes: expected "+n+" bytes, got "+t.length);let u=new Uint8Array(o);u.set(t,s?0:u.length-t.length),t=u}if(t.length!==o)throw new Error("Field.fromBytes: expected "+o+" bytes, got "+t.length);let a=s?ne(t):_e(t);if(c&&(a=W(a,i)),!e&&!this.isValid(a))throw new Error("invalid field element: outside of range 0..ORDER");return a}invertBatch(t){return rr(this,t)}cmov(t,e,n){return n?e:t}};function Ie(r,t={}){return new ao(r,t)}function Bi(r){if(typeof r!="bigint")throw new Error("field order must be bigint");let t=r.toString(2).length;return Math.ceil(t/8)}function fo(r){let t=Bi(r);return t+Math.ceil(t/2)}function lo(r,t,e=!1){k(r);let n=r.length,o=Bi(t),s=fo(t);if(n<16||n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=e?ne(r):_e(r),c=W(i,t-tt)+tt;return e?so(c,o):Cr(c,o)}var Le=BigInt(0),se=BigInt(1);function nr(r,t){let e=t.negate();return r?e:t}function ie(r,t){let e=rr(r.Fp,t.map(n=>n.Z));return t.map((n,o)=>r.fromAffine(n.toAffine(e[o])))}function Ri(r,t){if(!Number.isSafeInteger(r)||r<=0||r>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+r)}function ho(r,t){Ri(r,t);let e=Math.ceil(t/r)+1,n=2**(r-1),o=2**r,s=er(r),i=BigInt(r);return{windows:e,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function Ti(r,t,e){let{windowSize:n,mask:o,maxNumber:s,shiftBy:i}=e,c=Number(r&o),a=r>>i;c>n&&(c-=s,a+=se);let u=t*n,l=u+Math.abs(c)-1,f=c===0,d=c<0,p=t%2!==0;return{nextN:a,offset:l,isZero:f,isNeg:d,isNegF:p,offsetF:u}}var po=new WeakMap,Pi=new WeakMap;function mo(r){return Pi.get(r)||1}function Di(r){if(r!==Le)throw new Error("invalid wNAF")}var Be=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>Le;)e&se&&(n=n.add(o)),o=o.double(),e>>=se;return n}precomputeWindow(t,e){let{windows:n,windowSize:o}=ho(e,this.bits),s=[],i=t,c=i;for(let a=0;a<n;a++){c=i,s.push(c);for(let u=1;u<o;u++)c=c.add(i),s.push(c);i=c.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=ho(t,this.bits);for(let c=0;c<i.windows;c++){let{nextN:a,offset:u,isZero:l,isNeg:f,isNegF:d,offsetF:p}=Ti(n,c,i);n=a,l?s=s.add(nr(d,e[p])):o=o.add(nr(f,e[u]))}return Di(n),{p:o,f:s}}wNAFUnsafe(t,e,n,o=this.ZERO){let s=ho(t,this.bits);for(let i=0;i<s.windows&&n!==Le;i++){let{nextN:c,offset:a,isZero:u,isNeg:l}=Ti(n,i,s);if(n=c,!u){let f=e[a];o=o.add(l?f.negate():f)}}return Di(n),o}getPrecomputes(t,e,n){let o=po.get(e);return o||(o=this.precomputeWindow(e,t),t!==1&&(typeof n=="function"&&(o=n(o)),po.set(e,o))),o}cached(t,e,n){let o=mo(t);return this.wNAF(o,this.getPrecomputes(o,t,n),e)}unsafe(t,e,n,o){let s=mo(t);return s===1?this._unsafeLadder(t,e,o):this.wNAFUnsafe(s,this.getPrecomputes(s,t,n),e,o)}createCache(t,e){Ri(e,this.bits),Pi.set(t,e),po.delete(t)}hasCache(t){return mo(t)!==1}};function Oi(r,t,e,n){let o=t,s=r.ZERO,i=r.ZERO;for(;e>Le||n>Le;)e&se&&(s=s.add(o)),n&se&&(i=i.add(o)),o=o.double(),e>>=se,n>>=se;return{p1:s,p2:i}}function Ci(r,t,e){if(t){if(t.ORDER!==r)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return uo(t),t}else return Ie(r,{isLE:e})}function Pr(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 a of["p","n","h"]){let u=t[a];if(!(typeof u=="bigint"&&u>Le))throw new Error(`CURVE.${a} must be positive bigint`)}let o=Ci(t.p,e.Fp,n),s=Ci(t.n,e.Fn,n),c=["Gx","Gy","a",r==="weierstrass"?"b":"d"];for(let a of c)if(!o.isValid(t[a]))throw new Error(`CURVE.${a} must be valid field element of CURVE.Fp`);return t=Object.freeze(Object.assign({},t)),{CURVE:t,Fp:o,Fn:s}}function Or(r,t){return function(n){let o=r(n);return{secretKey:o,publicKey:t(o)}}}var Xt=BigInt(0),et=BigInt(1),go=BigInt(2),Mu=BigInt(8);function Ku(r,t,e,n){let o=r.sqr(e),s=r.sqr(n),i=r.add(r.mul(t.a,o),s),c=r.add(r.ONE,r.mul(t.d,r.mul(o,s)));return r.eql(i,c)}function Ni(r,t={}){let e=Pr("edwards",r,t,t.FpFnLE),{Fp:n,Fn:o}=e,s=e.CURVE,{h:i}=s;Yt(t,{},{uvRatio:"function"});let c=go<<BigInt(o.BYTES*8)-et,a=g=>n.create(g),u=t.uvRatio||((g,x)=>{try{return{isValid:!0,value:n.sqrt(n.div(g,x))}}catch{return{isValid:!1,value:Xt}}});if(!Ku(n,s,s.Gx,s.Gy))throw new Error("bad curve params: generator point");function l(g,x,A=!1){let w=A?et:Xt;return tr("coordinate "+g,x,w,c),x}function f(g){if(!(g instanceof h))throw new Error("EdwardsPoint expected")}let d=Ae((g,x)=>{let{X:A,Y:w,Z:I}=g,P=g.is0();x==null&&(x=P?Mu:n.inv(I));let U=a(A*x),M=a(w*x),S=n.mul(I,x);if(P)return{x:Xt,y:et};if(S!==et)throw new Error("invZ was invalid");return{x:U,y:M}}),p=Ae(g=>{let{a:x,d:A}=s;if(g.is0())throw new Error("bad point: ZERO");let{X:w,Y:I,Z:P,T:U}=g,M=a(w*w),S=a(I*I),E=a(P*P),O=a(E*E),K=a(M*x),D=a(E*a(K+S)),b=a(O+a(A*a(M*S)));if(D!==b)throw new Error("bad point: equation left != right (1)");let y=a(w*I),m=a(P*U);if(y!==m)throw new Error("bad point: equation left != right (2)");return!0});class h{static BASE=new h(s.Gx,s.Gy,et,a(s.Gx*s.Gy));static ZERO=new h(Xt,et,et,Xt);static Fp=n;static Fn=o;X;Y;Z;T;constructor(x,A,w,I){this.X=l("x",x),this.Y=l("y",A),this.Z=l("z",w,!0),this.T=l("t",I),Object.freeze(this)}static CURVE(){return s}static fromAffine(x){if(x instanceof h)throw new Error("extended point not allowed");let{x:A,y:w}=x||{};return l("x",A),l("y",w),new h(A,w,et,a(A*w))}static fromBytes(x,A=!1){let w=n.BYTES,{a:I,d:P}=s;x=Rr(k(x,w,"point")),kt(A,"zip215");let U=Rr(x),M=x[w-1];U[w-1]=M&-129;let S=ne(U),E=A?c:n.ORDER;tr("point.y",S,Xt,E);let O=a(S*S),K=a(O-et),D=a(P*O-I),{isValid:b,value:y}=u(K,D);if(!b)throw new Error("bad point: invalid y coordinate");let m=(y&et)===et,_=(M&128)!==0;if(!A&&y===Xt&&_)throw new Error("bad point: x=0 and x_0=1");return _!==m&&(y=a(-y)),h.fromAffine({x:y,y:S})}static fromHex(x,A=!1){return h.fromBytes(Ot(x),A)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(x=8,A=!0){return v.createCache(this,x),A||this.multiply(go),this}assertValidity(){p(this)}equals(x){f(x);let{X:A,Y:w,Z:I}=this,{X:P,Y:U,Z:M}=x,S=a(A*M),E=a(P*I),O=a(w*M),K=a(U*I);return S===E&&O===K}is0(){return this.equals(h.ZERO)}negate(){return new h(a(-this.X),this.Y,this.Z,a(-this.T))}double(){let{a:x}=s,{X:A,Y:w,Z:I}=this,P=a(A*A),U=a(w*w),M=a(go*a(I*I)),S=a(x*P),E=A+w,O=a(a(E*E)-P-U),K=S+U,D=K-M,b=S-U,y=a(O*D),m=a(K*b),_=a(O*b),L=a(D*K);return new h(y,m,L,_)}add(x){f(x);let{a:A,d:w}=s,{X:I,Y:P,Z:U,T:M}=this,{X:S,Y:E,Z:O,T:K}=x,D=a(I*S),b=a(P*E),y=a(M*w*K),m=a(U*O),_=a((I+P)*(S+E)-D-b),L=m-y,T=m+y,C=a(b-A*D),B=a(_*L),R=a(T*C),N=a(_*C),j=a(L*T);return new h(B,R,j,N)}subtract(x){return this.add(x.negate())}multiply(x){if(!o.isValidNot0(x))throw new Error("invalid scalar: expected 1 <= sc < curve.n");let{p:A,f:w}=v.cached(this,x,I=>ie(h,I));return ie(h,[A,w])[0]}multiplyUnsafe(x,A=h.ZERO){if(!o.isValid(x))throw new Error("invalid scalar: expected 0 <= sc < curve.n");return x===Xt?h.ZERO:this.is0()||x===et?this:v.unsafe(this,x,w=>ie(h,w),A)}isSmallOrder(){return this.multiplyUnsafe(i).is0()}isTorsionFree(){return v.unsafe(this,s.n).is0()}toAffine(x){return d(this,x)}clearCofactor(){return i===et?this:this.multiplyUnsafe(i)}toBytes(){let{x,y:A}=this.toAffine(),w=n.toBytes(A);return w[w.length-1]|=x&et?128:0,w}toHex(){return Pt(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let v=new Be(h,o.BITS);return h.BASE.precompute(8),h}function ki(r,t,e={}){if(typeof t!="function")throw new Error('"hash" function param is required');Yt(e,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",mapToCurve:"function"});let{prehash:n}=e,{BASE:o,Fp:s,Fn:i}=r,c=e.randomBytes||ve,a=e.adjustScalarBytes||(S=>S),u=e.domain||((S,E,O)=>{if(kt(O,"phflag"),E.length||O)throw new Error("Contexts/pre-hash are not supported");return S});function l(S){return i.create(ne(S))}function f(S){let E=w.secretKey;k(S,w.secretKey,"secretKey");let O=k(t(S),2*E,"hashedSecretKey"),K=a(O.slice(0,E)),D=O.slice(E,2*E),b=l(K);return{head:K,prefix:D,scalar:b}}function d(S){let{head:E,prefix:O,scalar:K}=f(S),D=o.multiply(K),b=D.toBytes();return{head:E,prefix:O,scalar:K,point:D,pointBytes:b}}function p(S){return d(S).pointBytes}function h(S=Uint8Array.of(),...E){let O=pt(...E);return l(t(u(O,k(S,void 0,"context"),!!n)))}function v(S,E,O={}){S=k(S,void 0,"message"),n&&(S=n(S));let{prefix:K,scalar:D,pointBytes:b}=d(E),y=h(O.context,K,S),m=o.multiply(y).toBytes(),_=h(O.context,m,b,S),L=i.create(y+_*D);if(!i.isValid(L))throw new Error("sign failed: invalid s");let T=pt(m,i.toBytes(L));return k(T,w.signature,"result")}let g={zip215:!0};function x(S,E,O,K=g){let{context:D,zip215:b}=K,y=w.signature;S=k(S,y,"signature"),E=k(E,void 0,"message"),O=k(O,w.publicKey,"publicKey"),b!==void 0&&kt(b,"zip215"),n&&(E=n(E));let m=y/2,_=S.subarray(0,m),L=ne(S.subarray(m,y)),T,C,B;try{T=r.fromBytes(O,b),C=r.fromBytes(_,b),B=o.multiplyUnsafe(L)}catch{return!1}if(!b&&T.isSmallOrder())return!1;let R=h(D,C.toBytes(),T.toBytes(),E);return C.add(T.multiplyUnsafe(R)).subtract(B).clearCofactor().is0()}let A=s.BYTES,w={secretKey:A,publicKey:A,signature:2*A,seed:A};function I(S=c(w.seed)){return k(S,w.seed,"seed")}function P(S){return te(S)&&S.length===i.BYTES}function U(S,E){try{return!!r.fromBytes(S,E)}catch{return!1}}let M={getExtendedPublicKey:d,randomSecretKey:I,isValidSecretKey:P,isValidPublicKey:U,toMontgomery(S){let{y:E}=r.fromBytes(S),O=w.publicKey,K=O===32;if(!K&&O!==57)throw new Error("only defined for 25519 and 448");let D=K?s.div(et+E,et-E):s.div(E-et,E+et);return s.toBytes(D)},toMontgomerySecret(S){let E=w.secretKey;k(S,E);let O=t(S.subarray(0,E));return a(O).subarray(0,E)}};return Object.freeze({keygen:Or(I,p),getPublicKey:p,sign:v,verify:x,utils:M,Point:r,lengths:w})}var Fu=BigInt(1),Ui=BigInt(2);var qu=BigInt(5),zu=BigInt(8),bo=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),Vu={p:bo,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:zu,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function Hu(r){let t=BigInt(10),e=BigInt(20),n=BigInt(40),o=BigInt(80),s=bo,c=r*r%s*r%s,a=H(c,Ui,s)*c%s,u=H(a,Fu,s)*r%s,l=H(u,qu,s)*u%s,f=H(l,t,s)*l%s,d=H(f,e,s)*f%s,p=H(d,n,s)*d%s,h=H(p,o,s)*p%s,v=H(h,o,s)*p%s,g=H(v,t,s)*l%s;return{pow_p_5_8:H(g,Ui,s)*r%s,b2:c}}function $u(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}var Mi=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function ju(r,t){let e=bo,n=W(t*t*t,e),o=W(n*n*t,e),s=Hu(r*o).pow_p_5_8,i=W(r*n*s,e),c=W(t*i*i,e),a=i,u=W(i*Mi,e),l=c===r,f=c===W(-r,e),d=c===W(-r*Mi,e);return l&&(i=a),(f||d)&&(i=u),Li(i,e)&&(i=W(-i,e)),{isValid:l||f,value:i}}var Gu=Ni(Vu,{uvRatio:ju});function Zu(r){return ki(Gu,pi,Object.assign({adjustScalarBytes:$u},r))}var Ki=Zu({});var or=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},Nr=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var Fi={get(r=globalThis){let t=r.crypto;if(t?.subtle==null)throw new Nr("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 kr=Fi;var Ur=32;var yo,Yu=(async()=>{try{return await kr.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function Xu(r,t,e){if(r.buffer instanceof ArrayBuffer){let n=await kr.get().subtle.importKey("raw",r.buffer,{name:"Ed25519"},!1,["verify"]);return await kr.get().subtle.verify({name:"Ed25519"},n,t,e instanceof Uint8Array?e:e.subarray())}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function Wu(r,t,e){return Ki.verify(t,e instanceof Uint8Array?e:e.subarray(),r)}async function qi(r,t,e){return yo==null&&(yo=await Yu),yo?Xu(r,t,e):Wu(r,t,e)}function Mr(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}var Kr=class{type="Ed25519";raw;constructor(t){this.raw=xo(t,Ur)}toMultihash(){return xt.digest(Ee(this))}toCID(){return at.createV1(114,this.toMultihash())}toString(){return X.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:lt(this.raw,t.raw)}verify(t,e,n){n?.signal?.throwIfAborted();let o=qi(this.raw,e,t);return Mr(o)?o.then(s=>(n?.signal?.throwIfAborted(),s)):o}};function Vi(r){return r=xo(r,Ur),new Kr(r)}function xo(r,t){if(r=Uint8Array.from(r??[]),r.length!==t)throw new ft(`Key must be a Uint8Array of length ${t}, got ${r.length}`);return r}var Ju=Math.pow(2,7),tf=Math.pow(2,14),ef=Math.pow(2,21),wo=Math.pow(2,28),Eo=Math.pow(2,35),So=Math.pow(2,42),vo=Math.pow(2,49),q=128,ct=127;function mt(r){if(r<Ju)return 1;if(r<tf)return 2;if(r<ef)return 3;if(r<wo)return 4;if(r<Eo)return 5;if(r<So)return 6;if(r<vo)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Te(r,t,e=0){switch(mt(r)){case 8:t[e++]=r&255|q,r/=128;case 7:t[e++]=r&255|q,r/=128;case 6:t[e++]=r&255|q,r/=128;case 5:t[e++]=r&255|q,r/=128;case 4:t[e++]=r&255|q,r>>>=7;case 3:t[e++]=r&255|q,r>>>=7;case 2:t[e++]=r&255|q,r>>>=7;case 1:{t[e++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return t}function rf(r,t,e=0){switch(mt(r)){case 8:t.set(e++,r&255|q),r/=128;case 7:t.set(e++,r&255|q),r/=128;case 6:t.set(e++,r&255|q),r/=128;case 5:t.set(e++,r&255|q),r/=128;case 4:t.set(e++,r&255|q),r>>>=7;case 3:t.set(e++,r&255|q),r>>>=7;case 2:t.set(e++,r&255|q),r>>>=7;case 1:{t.set(e++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return t}function _o(r,t){let e=r[t],n=0;if(n+=e&ct,e<q||(e=r[t+1],n+=(e&ct)<<7,e<q)||(e=r[t+2],n+=(e&ct)<<14,e<q)||(e=r[t+3],n+=(e&ct)<<21,e<q)||(e=r[t+4],n+=(e&ct)*wo,e<q)||(e=r[t+5],n+=(e&ct)*Eo,e<q)||(e=r[t+6],n+=(e&ct)*So,e<q)||(e=r[t+7],n+=(e&ct)*vo,e<q))return n;throw new RangeError("Could not decode varint")}function nf(r,t){let e=r.get(t),n=0;if(n+=e&ct,e<q||(e=r.get(t+1),n+=(e&ct)<<7,e<q)||(e=r.get(t+2),n+=(e&ct)<<14,e<q)||(e=r.get(t+3),n+=(e&ct)<<21,e<q)||(e=r.get(t+4),n+=(e&ct)*wo,e<q)||(e=r.get(t+5),n+=(e&ct)*Eo,e<q)||(e=r.get(t+6),n+=(e&ct)*So,e<q)||(e=r.get(t+7),n+=(e&ct)*vo,e<q))return n;throw new RangeError("Could not decode varint")}function Hi(r,t,e=0){return t==null&&(t=ht(mt(r))),t instanceof Uint8Array?Te(r,t,e):rf(r,t,e)}function sr(r,t=0){return r instanceof Uint8Array?_o(r,t):nf(r,t)}var Ao=new Float32Array([-0]),Wt=new Uint8Array(Ao.buffer);function ji(r,t,e){Ao[0]=r,t[e]=Wt[0],t[e+1]=Wt[1],t[e+2]=Wt[2],t[e+3]=Wt[3]}function Gi(r,t){return Wt[0]=r[t],Wt[1]=r[t+1],Wt[2]=r[t+2],Wt[3]=r[t+3],Ao[0]}var Io=new Float64Array([-0]),ut=new Uint8Array(Io.buffer);function Zi(r,t,e){Io[0]=r,t[e]=ut[0],t[e+1]=ut[1],t[e+2]=ut[2],t[e+3]=ut[3],t[e+4]=ut[4],t[e+5]=ut[5],t[e+6]=ut[6],t[e+7]=ut[7]}function Yi(r,t){return ut[0]=r[t],ut[1]=r[t+1],ut[2]=r[t+2],ut[3]=r[t+3],ut[4]=r[t+4],ut[5]=r[t+5],ut[6]=r[t+6],ut[7]=r[t+7],Io[0]}var of=BigInt(Number.MAX_SAFE_INTEGER),sf=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 ae;if(t<of&&t>sf)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>Xi&&(o=0n,++n>Xi&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(t){if(t===0)return ae;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):ae}},ae=new bt(0,0);ae.toBigInt=function(){return 0n};ae.zzEncode=ae.zzDecode=function(){return this};ae.length=function(){return 1};var Xi=4294967296n;function Wi(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 Qi(r,t,e){if(e-t<1)return"";let o,s=[],i=0,c;for(;t<e;)c=r[t++],c<128?s[i++]=c:c>191&&c<224?s[i++]=(c&31)<<6|r[t++]&63:c>239&&c<365?(c=((c&7)<<18|(r[t++]&63)<<12|(r[t++]&63)<<6|r[t++]&63)-65536,s[i++]=55296+(c>>10),s[i++]=56320+(c&1023)):s[i++]=(c&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 Lo(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 St(r,t){return RangeError(`index out of range: ${r.pos} + ${t??1} > ${r.len}`)}function Fr(r,t){return(r[t-4]|r[t-3]<<8|r[t-2]<<16|r[t-1]<<24)>>>0}var Bo=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,St(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 St(this,4);return Fr(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw St(this,4);return Fr(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw St(this,4);let t=Gi(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw St(this,4);let t=Yi(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 St(this,t);return this.pos+=t,e===n?new Uint8Array(0):this.buf.subarray(e,n)}string(){let t=this.bytes();return Qi(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw St(this,t);this.pos+=t}else do if(this.pos>=this.len)throw St(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 St(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 St(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 St(this,8);let t=Fr(this.buf,this.pos+=4),e=Fr(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=_o(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 To(r){return new Bo(r instanceof Uint8Array?r:r.subarray())}function Ut(r,t,e){let n=To(r);return t.decode(n,void 0,e)}function Do(r){let t=r??8192,e=t>>>1,n,o=t;return function(i){if(i<1||i>e)return ht(i);o+i>t&&(n=ht(t),o=0);let c=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),c}}var ce=class{fn;len;next;val;constructor(t,e,n){this.fn=t,this.len=e,this.next=void 0,this.val=n}};function Co(){}var Po=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},af=Do();function cf(r){return globalThis.Buffer!=null?ht(r):af(r)}var ar=class{len;head;tail;states;constructor(){this.len=0,this.head=new ce(Co,0,0),this.tail=this.head,this.states=null}_push(t,e,n){return this.tail=this.tail.next=new ce(t,e,n),this.len+=e,this}uint32(t){return this.len+=(this.tail=this.tail.next=new Oo((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(qr,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(qr,e.length(),e)}uint64Number(t){return this._push(Te,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(qr,e.length(),e)}sint64Number(t){let e=bt.fromNumber(t).zzEncode();return this._push(qr,e.length(),e)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(Ro,1,t?1:0)}fixed32(t){return this._push(ir,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=bt.fromBigInt(t);return this._push(ir,4,e.lo)._push(ir,4,e.hi)}fixed64Number(t){let e=bt.fromNumber(t);return this._push(ir,4,e.lo)._push(ir,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(ji,4,t)}double(t){return this._push(Zi,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(Ro,1,0):this.uint32(e)._push(ff,e,t)}string(t){let e=Wi(t);return e!==0?this.uint32(e)._push(Lo,e,t):this._push(Ro,1,0)}fork(){return this.states=new Po(this),this.head=this.tail=new ce(Co,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 ce(Co,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=cf(this.len),n=0;for(;t!=null;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e}};function Ro(r,t,e){t[e]=r&255}function uf(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var Oo=class extends ce{next;constructor(t,e){super(uf,t,e),this.next=void 0}};function qr(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 ir(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 ff(r,t,e){t.set(r,e)}globalThis.Buffer!=null&&(ar.prototype.bytes=function(r){let t=r.length>>>0;return this.uint32(t),t>0&&this._push(lf,t,r),this},ar.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(df,t,r),this});function lf(r,t,e){t.set(r,e)}function df(r,t,e){r.length<40?Lo(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set($(r),e)}function No(){return new ar}function Mt(r,t){let e=No();return t.encode(r,e,{lengthDelimited:!1}),e.finish()}var De;(function(r){r[r.VARINT=0]="VARINT",r[r.BIT64=1]="BIT64",r[r.LENGTH_DELIMITED=2]="LENGTH_DELIMITED",r[r.START_GROUP=3]="START_GROUP",r[r.END_GROUP=4]="END_GROUP",r[r.BIT32=5]="BIT32"})(De||(De={}));function zr(r,t,e,n){return{name:r,type:t,encode:e,decode:n}}function Ce(r){function t(o){if(r[o.toString()]==null)throw new Error("Invalid enum value");return r[o]}let e=function(s,i){let c=t(s);i.int32(c)},n=function(s){let i=s.int32();return t(i)};return zr("enum",De.VARINT,e,n)}function Kt(r,t){return zr("message",De.LENGTH_DELIMITED,r,t)}var Vr=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var yt;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.secp256k1="secp256k1",r.ECDSA="ECDSA"})(yt||(yt={}));var ko;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.secp256k1=2]="secp256k1",r[r.ECDSA=3]="ECDSA"})(ko||(ko={}));(function(r){r.codec=()=>Ce(ko)})(yt||(yt={}));var cr;(function(r){let t;r.codec=()=>(t==null&&(t=Kt((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),yt.codec().encode(e.Type,n)),e.Data!=null&&(n.uint32(18),n.bytes(e.Data)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let c=e.uint32();switch(c>>>3){case 1:{s.Type=yt.codec().decode(e);break}case 2:{s.Data=e.bytes();break}default:{e.skipType(c&7);break}}}return s})),t),r.encode=e=>Mt(e,r.codec()),r.decode=(e,n)=>Ut(e,r.codec(),n)})(cr||(cr={}));var Uo;(function(r){let t;r.codec=()=>(t==null&&(t=Kt((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),yt.codec().encode(e.Type,n)),e.Data!=null&&(n.uint32(18),n.bytes(e.Data)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let c=e.uint32();switch(c>>>3){case 1:{s.Type=yt.codec().decode(e);break}case 2:{s.Data=e.bytes();break}default:{e.skipType(c&7);break}}}return s})),t),r.encode=e=>Mt(e,r.codec()),r.decode=(e,n)=>Ut(e,r.codec(),n)})(Uo||(Uo={}));var Hr=class{oHash;iHash;blockLen;outputLen;finished=!1;destroyed=!1;constructor(t,e){if(Lr(t),k(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),Rt(o)}update(t){return Se(this),this.iHash.update(t),this}digestInto(t){Se(this),k(t,this.outputLen,"output"),this.finished=!0,this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){let t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||=Object.create(Object.getPrototypeOf(this),{});let{oHash:e,iHash:n,finished:o,destroyed:s,blockLen:i,outputLen:c}=this;return t=t,t.finished=o,t.destroyed=s,t.blockLen=i,t.outputLen=c,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()}},Mo=(r,t,e)=>new Hr(r,t).update(e).digest();Mo.create=(r,t)=>new Hr(r,t);var ta=(r,t)=>(r+(r>=0?t:-t)/ea)/t;function pf(r,t,e){let[[n,o],[s,i]]=t,c=ta(i*r,e),a=ta(-o*r,e),u=r-c*n-a*s,l=-c*o-a*i,f=u<Ft,d=l<Ft;f&&(u=-u),d&&(l=-l);let p=er(Math.ceil(io(e)/2))+Re;if(u<Ft||u>=p||l<Ft||l>=p)throw new Error("splitScalar (endomorphism): failed, k="+r);return{k1neg:f,k1:u,k2neg:d,k2:l}}function Fo(r){if(!["compact","recovered","der"].includes(r))throw new Error('Signature format must be "compact", "recovered", or "der"');return r}function Ko(r,t){let e={};for(let n of Object.keys(t))e[n]=r[n]===void 0?t[n]:r[n];return kt(e.lowS,"lowS"),kt(e.prehash,"prehash"),e.format!==void 0&&Fo(e.format),e}var qo=class extends Error{constructor(t=""){super(t)}},Qt={Err:qo,_tlv:{encode:(r,t)=>{let{Err:e}=Qt;if(r<0||r>256)throw new e("tlv.encode: wrong tag");if(t.length&1)throw new e("tlv.encode: unpadded data");let n=t.length/2,o=Je(n);if(o.length/2&128)throw new e("tlv.encode: long form length too big");let s=n>127?Je(o.length/2|128):"";return Je(r)+s+o+t},decode(r,t){let{Err:e}=Qt,n=0;if(r<0||r>256)throw new e("tlv.encode: wrong tag");if(t.length<2||t[n++]!==r)throw new e("tlv.decode: wrong tlv");let o=t[n++],s=!!(o&128),i=0;if(!s)i=o;else{let a=o&127;if(!a)throw new e("tlv.decode(long): indefinite length not supported");if(a>4)throw new e("tlv.decode(long): byte length is too big");let u=t.subarray(n,n+a);if(u.length!==a)throw new e("tlv.decode: length bytes not complete");if(u[0]===0)throw new e("tlv.decode(long): zero leftmost byte");for(let l of u)i=i<<8|l;if(n+=a,i<128)throw new e("tlv.decode(long): not minimal encoding")}let c=t.subarray(n,n+i);if(c.length!==i)throw new e("tlv.decode: wrong value length");return{v:c,l:t.subarray(n+i)}}},_int:{encode(r){let{Err:t}=Qt;if(r<Ft)throw new t("integer: negative integers are not allowed");let e=Je(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}=Qt;if(r[0]&128)throw new t("invalid signature integer: negative");if(r[0]===0&&!(r[1]&128))throw new t("invalid signature integer: unnecessary leading zero");return _e(r)}},toSig(r){let{Err:t,_int:e,_tlv:n}=Qt,o=k(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:c,l:a}=n.decode(2,s),{v:u,l}=n.decode(2,a);if(l.length)throw new t("invalid signature: left bytes after parsing");return{r:e.decode(c),s:e.decode(u)}},hexFromSig(r){let{_tlv:t,_int:e}=Qt,n=t.encode(2,e.encode(r.r)),o=t.encode(2,e.encode(r.s)),s=n+o;return t.encode(48,s)}},Ft=BigInt(0),Re=BigInt(1),ea=BigInt(2),$r=BigInt(3),mf=BigInt(4);function ra(r,t={}){let e=Pr("weierstrass",r,t),{Fp:n,Fn:o}=e,s=e.CURVE,{h:i,n:c}=s;Yt(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object"});let{endo:a}=t;if(a&&(!n.is0(s.a)||typeof a.beta!="bigint"||!Array.isArray(a.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let u=oa(n,o);function l(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function f(D,b,y){let{x:m,y:_}=b.toAffine(),L=n.toBytes(m);if(kt(y,"isCompressed"),y){l();let T=!n.isOdd(_);return pt(na(T),L)}else return pt(Uint8Array.of(4),L,n.toBytes(_))}function d(D){k(D,void 0,"Point");let{publicKey:b,publicKeyUncompressed:y}=u,m=D.length,_=D[0],L=D.subarray(1);if(m===b&&(_===2||_===3)){let T=n.fromBytes(L);if(!n.isValid(T))throw new Error("bad point: is not on curve, wrong x");let C=v(T),B;try{B=n.sqrt(C)}catch(j){let V=j instanceof Error?": "+j.message:"";throw new Error("bad point: is not on curve, sqrt error"+V)}l();let R=n.isOdd(B);return(_&1)===1!==R&&(B=n.neg(B)),{x:T,y:B}}else if(m===y&&_===4){let T=n.BYTES,C=n.fromBytes(L.subarray(0,T)),B=n.fromBytes(L.subarray(T,T*2));if(!g(C,B))throw new Error("bad point: is not on curve");return{x:C,y:B}}else throw new Error(`bad point: got length ${m}, expected compressed=${b} or uncompressed=${y}`)}let p=t.toBytes||f,h=t.fromBytes||d;function v(D){let b=n.sqr(D),y=n.mul(b,D);return n.add(n.add(y,n.mul(D,s.a)),s.b)}function g(D,b){let y=n.sqr(b),m=v(D);return n.eql(y,m)}if(!g(s.Gx,s.Gy))throw new Error("bad curve params: generator point");let x=n.mul(n.pow(s.a,$r),mf),A=n.mul(n.sqr(s.b),BigInt(27));if(n.is0(n.add(x,A)))throw new Error("bad curve params: a or b");function w(D,b,y=!1){if(!n.isValid(b)||y&&n.is0(b))throw new Error(`bad point coordinate ${D}`);return b}function I(D){if(!(D instanceof E))throw new Error("Weierstrass Point expected")}function P(D){if(!a||!a.basises)throw new Error("no endo");return pf(D,a.basises,o.ORDER)}let U=Ae((D,b)=>{let{X:y,Y:m,Z:_}=D;if(n.eql(_,n.ONE))return{x:y,y:m};let L=D.is0();b==null&&(b=L?n.ONE:n.inv(_));let T=n.mul(y,b),C=n.mul(m,b),B=n.mul(_,b);if(L)return{x:n.ZERO,y:n.ZERO};if(!n.eql(B,n.ONE))throw new Error("invZ was invalid");return{x:T,y:C}}),M=Ae(D=>{if(D.is0()){if(t.allowInfinityPoint&&!n.is0(D.Y))return;throw new Error("bad point: ZERO")}let{x:b,y}=D.toAffine();if(!n.isValid(b)||!n.isValid(y))throw new Error("bad point: x or y not field elements");if(!g(b,y))throw new Error("bad point: equation left != right");if(!D.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function S(D,b,y,m,_){return y=new E(n.mul(y.X,D),y.Y,y.Z),b=nr(m,b),y=nr(_,y),b.add(y)}class E{static BASE=new E(s.Gx,s.Gy,n.ONE);static ZERO=new E(n.ZERO,n.ONE,n.ZERO);static Fp=n;static Fn=o;X;Y;Z;constructor(b,y,m){this.X=w("x",b),this.Y=w("y",y,!0),this.Z=w("z",m),Object.freeze(this)}static CURVE(){return s}static fromAffine(b){let{x:y,y:m}=b||{};if(!b||!n.isValid(y)||!n.isValid(m))throw new Error("invalid affine point");if(b instanceof E)throw new Error("projective point not allowed");return n.is0(y)&&n.is0(m)?E.ZERO:new E(y,m,n.ONE)}static fromBytes(b){let y=E.fromAffine(h(k(b,void 0,"point")));return y.assertValidity(),y}static fromHex(b){return E.fromBytes(Ot(b))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(b=8,y=!0){return K.createCache(this,b),y||this.multiply($r),this}assertValidity(){M(this)}hasEvenY(){let{y:b}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(b)}equals(b){I(b);let{X:y,Y:m,Z:_}=this,{X:L,Y:T,Z:C}=b,B=n.eql(n.mul(y,C),n.mul(L,_)),R=n.eql(n.mul(m,C),n.mul(T,_));return B&&R}negate(){return new E(this.X,n.neg(this.Y),this.Z)}double(){let{a:b,b:y}=s,m=n.mul(y,$r),{X:_,Y:L,Z:T}=this,C=n.ZERO,B=n.ZERO,R=n.ZERO,N=n.mul(_,_),j=n.mul(L,L),V=n.mul(T,T),F=n.mul(_,L);return F=n.add(F,F),R=n.mul(_,T),R=n.add(R,R),C=n.mul(b,R),B=n.mul(m,V),B=n.add(C,B),C=n.sub(j,B),B=n.add(j,B),B=n.mul(C,B),C=n.mul(F,C),R=n.mul(m,R),V=n.mul(b,V),F=n.sub(N,V),F=n.mul(b,F),F=n.add(F,R),R=n.add(N,N),N=n.add(R,N),N=n.add(N,V),N=n.mul(N,F),B=n.add(B,N),V=n.mul(L,T),V=n.add(V,V),N=n.mul(V,F),C=n.sub(C,N),R=n.mul(V,j),R=n.add(R,R),R=n.add(R,R),new E(C,B,R)}add(b){I(b);let{X:y,Y:m,Z:_}=this,{X:L,Y:T,Z:C}=b,B=n.ZERO,R=n.ZERO,N=n.ZERO,j=s.a,V=n.mul(s.b,$r),F=n.mul(y,L),G=n.mul(m,T),nt=n.mul(_,C),At=n.add(y,m),Z=n.add(L,T);At=n.mul(At,Z),Z=n.add(F,G),At=n.sub(At,Z),Z=n.add(y,_);let it=n.add(L,C);return Z=n.mul(Z,it),it=n.add(F,nt),Z=n.sub(Z,it),it=n.add(m,_),B=n.add(T,C),it=n.mul(it,B),B=n.add(G,nt),it=n.sub(it,B),N=n.mul(j,Z),B=n.mul(V,nt),N=n.add(B,N),B=n.sub(G,N),N=n.add(G,N),R=n.mul(B,N),G=n.add(F,F),G=n.add(G,F),nt=n.mul(j,nt),Z=n.mul(V,Z),G=n.add(G,nt),nt=n.sub(F,nt),nt=n.mul(j,nt),Z=n.add(Z,nt),F=n.mul(G,Z),R=n.add(R,F),F=n.mul(it,Z),B=n.mul(At,B),B=n.sub(B,F),F=n.mul(At,G),N=n.mul(it,N),N=n.add(N,F),new E(B,R,N)}subtract(b){return this.add(b.negate())}is0(){return this.equals(E.ZERO)}multiply(b){let{endo:y}=t;if(!o.isValidNot0(b))throw new Error("invalid scalar: out of range");let m,_,L=T=>K.cached(this,T,C=>ie(E,C));if(y){let{k1neg:T,k1:C,k2neg:B,k2:R}=P(b),{p:N,f:j}=L(C),{p:V,f:F}=L(R);_=j.add(F),m=S(y.beta,N,V,T,B)}else{let{p:T,f:C}=L(b);m=T,_=C}return ie(E,[m,_])[0]}multiplyUnsafe(b){let{endo:y}=t,m=this;if(!o.isValid(b))throw new Error("invalid scalar: out of range");if(b===Ft||m.is0())return E.ZERO;if(b===Re)return m;if(K.hasCache(this))return this.multiply(b);if(y){let{k1neg:_,k1:L,k2neg:T,k2:C}=P(b),{p1:B,p2:R}=Oi(E,m,L,C);return S(y.beta,B,R,_,T)}else return K.unsafe(m,b)}toAffine(b){return U(this,b)}isTorsionFree(){let{isTorsionFree:b}=t;return i===Re?!0:b?b(E,this):K.unsafe(this,c).is0()}clearCofactor(){let{clearCofactor:b}=t;return i===Re?this:b?b(E,this):this.multiplyUnsafe(i)}isSmallOrder(){return this.multiplyUnsafe(i).is0()}toBytes(b=!0){return kt(b,"isCompressed"),this.assertValidity(),p(E,this,b)}toHex(b=!0){return Pt(this.toBytes(b))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let O=o.BITS,K=new Be(E,t.endo?Math.ceil(O/2):O);return E.BASE.precompute(8),E}function na(r){return Uint8Array.of(r?2:3)}function oa(r,t){return{secretKey:t.BYTES,publicKey:1+r.BYTES,publicKeyUncompressed:1+2*r.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function gf(r,t={}){let{Fn:e}=r,n=t.randomBytes||ve,o=Object.assign(oa(r.Fp,e),{seed:fo(e.ORDER)});function s(p){try{let h=e.fromBytes(p);return e.isValidNot0(h)}catch{return!1}}function i(p,h){let{publicKey:v,publicKeyUncompressed:g}=o;try{let x=p.length;return h===!0&&x!==v||h===!1&&x!==g?!1:!!r.fromBytes(p)}catch{return!1}}function c(p=n(o.seed)){return lo(k(p,o.seed,"seed"),e.ORDER)}function a(p,h=!0){return r.BASE.multiply(e.fromBytes(p)).toBytes(h)}function u(p){let{secretKey:h,publicKey:v,publicKeyUncompressed:g}=o;if(!te(p)||"_lengths"in e&&e._lengths||h===v)return;let x=k(p,void 0,"key").length;return x===v||x===g}function l(p,h,v=!0){if(u(p)===!0)throw new Error("first arg must be private key");if(u(h)===!1)throw new Error("second arg must be public key");let g=e.fromBytes(p);return r.fromBytes(h).multiply(g).toBytes(v)}let f={isValidSecretKey:s,isValidPublicKey:i,randomSecretKey:c},d=Or(c,a);return Object.freeze({getPublicKey:a,getSharedSecret:l,keygen:d,Point:r,utils:f,lengths:o})}function sa(r,t,e={}){Lr(t),Yt(e,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"}),e=Object.assign({},e);let n=e.randomBytes||ve,o=e.hmac||((y,m)=>Mo(t,y,m)),{Fp:s,Fn:i}=r,{ORDER:c,BITS:a}=i,{keygen:u,getPublicKey:l,getSharedSecret:f,utils:d,lengths:p}=gf(r,e),h={prehash:!0,lowS:typeof e.lowS=="boolean"?e.lowS:!0,format:"compact",extraEntropy:!1},v=c*ea<s.ORDER;function g(y){let m=c>>Re;return y>m}function x(y,m){if(!i.isValidNot0(m))throw new Error(`invalid signature ${y}: out of range 1..Point.Fn.ORDER`);return m}function A(){if(v)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function w(y,m){Fo(m);let _=p.signature,L=m==="compact"?_:m==="recovered"?_+1:void 0;return k(y,L)}class I{r;s;recovery;constructor(m,_,L){if(this.r=x("r",m),this.s=x("s",_),L!=null){if(A(),![0,1,2,3].includes(L))throw new Error("invalid recovery id");this.recovery=L}Object.freeze(this)}static fromBytes(m,_=h.format){w(m,_);let L;if(_==="der"){let{r:R,s:N}=Qt.toSig(k(m));return new I(R,N)}_==="recovered"&&(L=m[0],_="compact",m=m.subarray(1));let T=p.signature/2,C=m.subarray(0,T),B=m.subarray(T,T*2);return new I(i.fromBytes(C),i.fromBytes(B),L)}static fromHex(m,_){return this.fromBytes(Ot(m),_)}assertRecovery(){let{recovery:m}=this;if(m==null)throw new Error("invalid recovery id: must be present");return m}addRecoveryBit(m){return new I(this.r,this.s,m)}recoverPublicKey(m){let{r:_,s:L}=this,T=this.assertRecovery(),C=T===2||T===3?_+c:_;if(!s.isValid(C))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let B=s.toBytes(C),R=r.fromBytes(pt(na((T&1)===0),B)),N=i.inv(C),j=U(k(m,void 0,"msgHash")),V=i.create(-j*N),F=i.create(L*N),G=r.BASE.multiplyUnsafe(V).add(R.multiplyUnsafe(F));if(G.is0())throw new Error("invalid recovery: point at infinify");return G.assertValidity(),G}hasHighS(){return g(this.s)}toBytes(m=h.format){if(Fo(m),m==="der")return Ot(Qt.hexFromSig(this));let{r:_,s:L}=this,T=i.toBytes(_),C=i.toBytes(L);return m==="recovered"?(A(),pt(Uint8Array.of(this.assertRecovery()),T,C)):pt(T,C)}toHex(m){return Pt(this.toBytes(m))}}let P=e.bits2int||function(m){if(m.length>8192)throw new Error("input is too large");let _=_e(m),L=m.length*8-a;return L>0?_>>BigInt(L):_},U=e.bits2int_modN||function(m){return i.create(P(m))},M=er(a);function S(y){return tr("num < 2^"+a,y,Ft,M),i.toBytes(y)}function E(y,m){return k(y,void 0,"message"),m?k(t(y),void 0,"prehashed message"):y}function O(y,m,_){let{lowS:L,prehash:T,extraEntropy:C}=Ko(_,h);y=E(y,T);let B=U(y),R=i.fromBytes(m);if(!i.isValidNot0(R))throw new Error("invalid private key");let N=[S(R),S(B)];if(C!=null&&C!==!1){let G=C===!0?n(p.secretKey):C;N.push(k(G,void 0,"extraEntropy"))}let j=pt(...N),V=B;function F(G){let nt=P(G);if(!i.isValidNot0(nt))return;let At=i.inv(nt),Z=r.BASE.multiply(nt).toAffine(),it=i.create(Z.x);if(it===Ft)return;let yr=i.create(At*i.create(V+it*R));if(yr===Ft)return;let ys=(Z.x===it?0:2)|Number(Z.y&Re),xs=yr;return L&&g(yr)&&(xs=i.neg(yr),ys^=1),new I(it,xs,v?void 0:ys)}return{seed:j,k2sig:F}}function K(y,m,_={}){let{seed:L,k2sig:T}=O(y,m,_);return bi(t.outputLen,i.BYTES,o)(L,T).toBytes(_.format)}function D(y,m,_,L={}){let{lowS:T,prehash:C,format:B}=Ko(L,h);if(_=k(_,void 0,"publicKey"),m=E(m,C),!te(y)){let R=y instanceof I?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+R)}w(y,B);try{let R=I.fromBytes(y,B),N=r.fromBytes(_);if(T&&R.hasHighS())return!1;let{r:j,s:V}=R,F=U(m),G=i.inv(V),nt=i.create(F*G),At=i.create(j*G),Z=r.BASE.multiplyUnsafe(nt).add(N.multiplyUnsafe(At));return Z.is0()?!1:i.create(Z.x)===j}catch{return!1}}function b(y,m,_={}){let{prehash:L}=Ko(_,h);return m=E(m,L),I.fromBytes(y,"recovered").recoverPublicKey(m).toBytes()}return Object.freeze({keygen:u,getPublicKey:l,getSharedSecret:f,utils:d,lengths:p,Point:r,sign:K,verify:D,recoverPublicKey:b,Signature:I,hash:t})}var Vo={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},bf={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var ia=BigInt(2);function yf(r){let t=Vo.p,e=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),c=BigInt(44),a=BigInt(88),u=r*r*r%t,l=u*u*r%t,f=H(l,e,t)*l%t,d=H(f,e,t)*l%t,p=H(d,ia,t)*u%t,h=H(p,o,t)*p%t,v=H(h,s,t)*h%t,g=H(v,c,t)*v%t,x=H(g,a,t)*g%t,A=H(x,c,t)*v%t,w=H(A,e,t)*l%t,I=H(w,i,t)*h%t,P=H(I,n,t)*u%t,U=H(P,ia,t);if(!zo.eql(zo.sqr(U),r))throw new Error("Cannot find square root");return U}var zo=Ie(Vo.p,{sqrt:yf}),xf=ra(Vo,{Fp:zo,endo:bf}),Pe=sa(xf,hi);function aa(r,t,e,n){let o=je.digest(e instanceof Uint8Array?e:e.subarray());if(Mr(o))return o.then(({digest:s})=>(n?.signal?.throwIfAborted(),Pe.verify(t,s,r,{prehash:!1,format:"der"}))).catch(s=>{throw s.name==="AbortError"?s:new or(String(s))});try{return n?.signal?.throwIfAborted(),Pe.verify(t,o.digest,r,{prehash:!1,format:"der"})}catch(s){throw new or(String(s))}}var jr=class{type="secp256k1";raw;_key;constructor(t){this._key=ua(t),this.raw=ca(this._key)}toMultihash(){return xt.digest(Ee(this))}toCID(){return at.createV1(114,this.toMultihash())}toString(){return X.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:lt(this.raw,t.raw)}verify(t,e,n){return aa(this._key,e,t,n)}};function fa(r){return new jr(r)}function ca(r){return Pe.Point.fromBytes(r).toBytes()}function ua(r){try{return Pe.Point.fromBytes(r),r}catch(t){throw new wr(String(t))}}function la(r){let{Type:t,Data:e}=cr.decode(r.digest),n=e??new Uint8Array;switch(t){case yt.Ed25519:return Vi(n);case yt.secp256k1:return fa(n);case yt.ECDSA:return Xs(n);default:throw new qe}}function Ee(r){return cr.encode({Type:yt[r.type],Data:r.raw})}var da=Symbol.for("nodejs.util.inspect.custom"),wf=114,ur=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()})`}[wn]=!0;toString(){return this.string==null&&(this.string=X.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return at.createV1(wf,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return lt(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return lt(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[da](){return`PeerId(${this.toString()})`}},Gr=class extends ur{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},Zr=class extends ur{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},Yr=class extends ur{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},Ef=2336,Xr=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=xt.digest($(this.url))}[da](){return`PeerId(${this.url})`}[wn]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return at.createV1(Ef,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=Q(t)),t.toString()===this.toString())}};function Wr(r){if(vf(r))return new Gr({multihash:r});if(Sf(r))try{let t=la(r);if(t.type==="Ed25519")return new Zr({multihash:r,publicKey:t});if(t.type==="secp256k1")return new Yr({multihash:r,publicKey:t})}catch{let e=Q(r.digest);return new Xr(new URL(e))}throw new Er("Supplied PeerID Multihash is invalid")}function Sf(r){return r.code===xt.code}function vf(r){return r.code===je.code}function Ho(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 Qr(r){let t=Jt(X.decode(`z${r}`));return Wr(t)}var Jr=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 Ho(this.set.entries(),t=>{let e=Qr(t[0]);return[e,e]})}forEach(t){this.set.forEach(e=>{let n=Qr(e);t(n,n,this)})}has(t){return this.set.has(t.toString())}values(){return Ho(this.set.values(),t=>Qr(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 $o(){return new Jr}var jo={32:16777619n,64:1099511628211n,128:309485009821345068724781371n,256:374144419156711147060143317175368453031918731002211n,512:35835915874844867368919076489095108449946327955754392558399825615420669938882575126094039892345713852759n,1024:5016456510113118655434598811035278955030765345404790744303017523831112055108147451509157692220295382716162651878526895249385292291816524375083746691371804094271873160484737966720260389217684476157468082573n},ha={32:2166136261n,64:14695981039346656037n,128:144066263297769815596495629667062367629n,256:100029257958052580907070968620625704837092796014241193945225284501741471925557n,512:9659303129496669498009435400716310466090418745672637896108374329434462657994582932197716438449813051892206539805784495328239340083876191928701583869517785n,1024:14197795064947621068722070641403218320880622795441933960878474914617582723252296732303717722150864096521202355549365628174669108571814760471015076148029755969804077320157692458563003215304957150157403644460363550505412711285966361610267868082893823963790439336411086884584107735010676915n},pa=new globalThis.TextEncoder;function _f(r,t){let e=jo[t],n=ha[t];for(let o=0;o<r.length;o++)n^=BigInt(r[o]),n=BigInt.asUintN(t,n*e);return n}function Af(r,t,e){if(e.length===0)throw new Error("The `utf8Buffer` option must have a length greater than zero");let n=jo[t],o=ha[t],s=r;for(;s.length>0;){let i=pa.encodeInto(s,e);s=s.slice(i.read);for(let c=0;c<i.written;c++)o^=BigInt(e[c]),o=BigInt.asUintN(t,o*n)}return o}function Go(r,{size:t=32,utf8Buffer:e}={}){if(!jo[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 Af(r,t,e);r=pa.encode(r)}return _f(r,t)}var fr={hash:r=>Number(Go(r,{size:32})),hashV:(r,t)=>If(fr.hash(r,t))};function If(r){let t=r.toString(16);return t.length%2===1&&(t=`0${t}`),$(t,"base16")}var Zo=64,vt=class{fp;h;seed;constructor(t,e,n,o=2){if(o>Zo)throw new TypeError("Invalid Fingerprint Size");let s=e.hashV(t,n),i=wt(o);for(let c=0;c<i.length;c++)i[c]=s[c];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?lt(this.fp,t.fp):!1}};function ue(r,t){return Math.floor(Math.random()*(t-r))+r}var fe=class{contents;constructor(t){this.contents=new Array(t).fill(null)}has(t){if(!(t instanceof vt))throw new TypeError("Invalid Fingerprint");return this.contents.some(e=>t.equals(e))}add(t){if(!(t instanceof vt))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 vt))throw new TypeError("Invalid Fingerprint");let e=ue(0,this.contents.length-1),n=this.contents[e];return this.contents[e]=t,n}remove(t){if(!(t instanceof vt))throw new TypeError("Invalid Fingerprint");let e=this.contents.findIndex(n=>t.equals(n));return e>-1?(this.contents[e]=null,!0):!1}};var Lf=500,lr=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??fr,this.seed=t.seed??ue(0,Math.pow(2,10))}add(t){typeof t=="string"&&(t=$(t));let e=new vt(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 fe(this.bucketSize)),this.buckets[o]==null&&(this.buckets[o]=new fe(this.bucketSize)),this.buckets[n].add(e)||this.buckets[o].add(e))return this.count++,!0;let s=[n,o],i=s[ue(0,s.length-1)];this.buckets[i]==null&&(this.buckets[i]=new fe(this.bucketSize));for(let c=0;c<Lf;c++){let a=this.buckets[i].swap(e);if(a!=null&&(i=(i^a.hash())%this.filterSize,this.buckets[i]==null&&(this.buckets[i]=new fe(this.bucketSize)),this.buckets[i].add(a)))return this.count++,!0}return!1}has(t){typeof t=="string"&&(t=$(t));let e=new vt(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=$(t));let e=new vt(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}},Bf={1:.5,2:.84,4:.95,8:.98};function Tf(r=.001){return r>.002?2:r>1e-5?4:8}function ma(r,t=.001){let e=Tf(t),n=Bf[e],o=Math.round(r/n),s=Math.min(Math.ceil(Math.log2(1/t)+Math.log2(2*e)),Zo);return{filterSize:o,bucketSize:e,fingerprintSize:s}}var tn=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??fr,this.seed=t.seed??ue(0,Math.pow(2,10)),this.filterSeries=[new lr({filterSize:this.filterSize,bucketSize:this.bucketSize,fingerprintSize:this.fingerprintSize,hash:this.hash,seed:this.seed})]}add(t){if(typeof t=="string"&&(t=$(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 lr({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=$(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=$(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 Yo(r,t=.001,e){return new tn({...ma(r,t),...e??{}})}function _t(r){let t=r.getComponents(),e={},n=0;if(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)throw new ft(`Multiaddr ${r} was not an IPv4, IPv6, DNS, DNS4, DNS6 or DNSADDR address`);return t[n]?.name==="tls"&&t[n+1]?.name==="sni"&&(e.sni=t[n+1].value,n+=2),e}var en=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,c=this.peekChar();if(c===void 0)return;let a=c==="0",u=2**(8*o)-1;for(;;){let l=this.readAtomically(()=>{let f=this.readChar();if(f===void 0)return;let d=Number.parseInt(f,t);if(!Number.isNaN(d))return d});if(l===void 0)break;if(s*=t,s+=l,s>u||(i+=1,e!==void 0&&i>e))return}if(i!==0)return!n&&a&&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),[c]=t(s.subarray(0,i));return e.set(s.subarray(0,c),16-c),e})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var ga=45,Df=15,Oe=new en;function rn(r){if(!(r.length>Df))return Oe.new(r).parseWith(()=>Oe.readIPv4Addr())}function nn(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>ga))return Oe.new(r).parseWith(()=>Oe.readIPv6Addr())}function Ne(r,t=!1){if(r.includes("%")&&(r=r.split("%")[0]),r.length>ga)return;let e=Oe.new(r).parseWith(()=>Oe.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 ba(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 ya(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 Xo(r){switch(r.length){case le: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 xa(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 wa(r){let t="0x";for(let e of r)t+=(e>>4).toString(16)+(e&15).toString(16);return t}var le=4,de=16,Dg=parseInt("0xFFFF",16),Cf=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function dr(r,t){t.length===de&&r.length===le&&ba(t,0,11)&&(t=t.slice(12)),t.length===le&&r.length===de&&ya(r,Cf,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 Ea(r,t){if(typeof t=="string"&&(t=Ne(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 Wo(r){let[t,e]=r.split("/");if(!t||!e)throw new Error("Failed to parse given CIDR: "+r);let n=le,o=rn(t);if(o==null&&(n=de,o=nn(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=Qo(s,8*n);return{network:dr(o,i),mask:i}}function Qo(r,t){if(t!==8*le&&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 hr=class{constructor(t,e){if(e==null)({network:this.network,mask:this.mask}=Wo(t));else{let n=Ne(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=Ne(e);if(s==null)throw new Error("Failed to parse mask");this.mask=s}else this.mask=Qo(o,8*n.length);this.network=dr(n,this.mask)}}contains(t){return Ea({network:this.network,mask:this.mask},t)}toString(){let t=xa(this.mask),e=t!==-1?String(t):wa(this.mask);return Xo(this.network)+"/"+e}};function Sa(r,t){return new hr(r).contains(t)}function va(r){try{let t=_t(r);switch(t.type){case"ip6":return Sa("2000::/3",t.host);default:return!1}}catch{return!1}}function ke(r){return!!rn(r)}function on(r){return!!nn(r)}var Aa=tc(_a(),1),Rf=["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"],Pf=Rf.map(r=>new Aa.Netmask(r));function Jo(r){for(let t of Pf)if(t.contains(r))return!0;return!1}function Of(r){return/^::ffff:([0-9a-fA-F]{1,4}):([0-9a-fA-F]{1,4})$/.test(r)}function Nf(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 Jo(o)}function kf(r){return/^::ffff:([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(r)}function Uf(r){let t=r.split(":"),e=t[t.length-1];return Jo(e)}function Mf(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 Ia(r){if(ke(r))return Jo(r);if(Of(r))return Nf(r);if(kf(r))return Uf(r);if(on(r))return Mf(r)}function ts(r){try{let t=_t(r);switch(t.type){case"ip4":case"ip6":return Ia(t.host)??!1;default:return t.host==="localhost"}}catch{return!1}}function Ue(){let r={};return r.promise=new Promise((t,e)=>{r.resolve=t,r.reject=e}),r}var sn=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}},Me=class{size;hwm;head;tail;constructor(t={}){this.hwm=t.splitLimit??16,this.head=new sn(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 sn(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 es=class extends Error{type;code;constructor(t,e){super(t??"The operation was aborted"),this.type="aborted",this.code=e??"ABORT_ERR"}};function an(r={}){return Kf(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 Kf(r,t){t=t??{};let e=t.onEnd,n=new Me,o,s,i,c=Ue(),a=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((g,x)=>{s=A=>{s=null,n.push(A);try{g(r(n))}catch(w){x(w)}return o}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{c.resolve(),c=Ue()})}},u=g=>s!=null?s(g):(n.push(g),o),l=g=>(n=new Me,s!=null?s({error:g}):(n.push({error:g}),o)),f=g=>{if(i)return o;if(t?.objectMode!==!0&&g?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return u({done:!1,value:g})},d=g=>i?o:(i=!0,g!=null?l(g):u({done:!0})),p=()=>(n=new Me,d(),{done:!0}),h=g=>(d(g),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:a,return:p,throw:h,push:f,end:d,get readableLength(){return n.size},onEmpty:async g=>{let x=g?.signal;if(x?.throwIfAborted(),n.isEmpty())return;let A,w;x!=null&&(A=new Promise((I,P)=>{w=()=>{P(new es)},x.addEventListener("abort",w)}));try{await Promise.race([c.promise,A])}finally{w!=null&&x!=null&&x?.removeEventListener("abort",w)}}},e==null)return o;let v=o;return o={[Symbol.asyncIterator](){return this},next(){return v.next()},throw(g){return v.throw(g),e!=null&&(e(g),e=void 0),{done:!0}},return(){return v.return(),e!=null&&(e(),e=void 0),{done:!0}},push:f,end(g){return v.end(g),e!=null&&(e(g),e=void 0),o},get readableLength(){return v.readableLength},onEmpty:g=>v.onEmpty(g)},o}var rs=class extends Error{constructor(t){super(t),this.name="TimeoutError"}},ns=class extends Error{constructor(t){super(),this.name="AbortError",this.message=t}},La=r=>globalThis.DOMException===void 0?new ns(r):new DOMException(r),Ba=r=>{let t=r.reason===void 0?La("This operation was aborted."):r.reason;return t instanceof Error?t:La(t)};function os(r,t){let{milliseconds:e,fallback:n,message:o,customTimers:s={setTimeout,clearTimeout}}=t,i,c,u=new Promise((l,f)=>{if(typeof e!="number"||Math.sign(e)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${e}\``);if(t.signal){let{signal:p}=t;p.aborted&&f(Ba(p)),c=()=>{f(Ba(p))},p.addEventListener("abort",c,{once:!0})}if(e===Number.POSITIVE_INFINITY){r.then(l,f);return}let d=new rs;i=s.setTimeout.call(void 0,()=>{if(n){try{l(n())}catch(p){f(p)}return}typeof r.cancel=="function"&&r.cancel(),o===!1?l():o instanceof Error?f(o):(d.message=o??`Promise timed out after ${e} milliseconds`,f(d))},e),(async()=>{try{l(await r)}catch(p){f(p)}})()}).finally(()=>{u.clear(),c&&t.signal&&t.signal.removeEventListener("abort",c)});return u.clear=()=>{s.clearTimeout.call(void 0,i),i=void 0},u}var Ff=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 qf(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 c=[t].flat(),a=[],{addListener:u,removeListener:l}=Ff(r),f=async(...p)=>{let h=e.multiArgs?p:p[0];if(e.filter)try{if(!await e.filter(h))return}catch(v){n(),i(v);return}a.push(h),e.count===a.length&&(n(),s(a))},d=(...p)=>{n(),i(e.rejectionMultiArgs?p:p[0])};n=()=>{for(let p of c)l(p,f);for(let p of e.rejectionEvents)c.includes(p)||l(p,d)};for(let p of c)u(p,f);for(let p of e.rejectionEvents)c.includes(p)||u(p,d);e.signal&&e.signal.addEventListener("abort",()=>{d(e.signal.reason)},{once:!0}),e.resolveImmediately&&s(a)});if(o.cancel=n,typeof e.timeout=="number"){let s=os(o,{milliseconds:e.timeout});return s.cancel=()=>{n(),s.clear()},s}return o}function Ke(r,t,e){typeof e=="function"&&(e={filter:e}),e={...e,count:1,resolveImmediately:!1};let n=qf(r,t,e),o=n.then(s=>s[0]);return o.cancel=n.cancel,o}function mr(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 cn=class extends Error{static name="QueueFullError";constructor(t="The queue was full"){super(t),this.name="QueueFullError"}},he=class extends Error{static name="UnexpectedEOFError";name="UnexpectedEOFError"};function zf(r){return r.reason}async function gr(r,t,e){if(t==null)return r;let n=e?.translateError??zf;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 un=class{deferred;signal;constructor(t){this.signal=t,this.deferred=Ue(),this.onAbort=this.onAbort.bind(this),this.signal?.addEventListener("abort",this.onAbort)}onAbort(){this.deferred.reject(this.signal?.reason??new Bt)}cleanup(){this.signal?.removeEventListener("abort",this.onAbort)}};function Vf(){return`${parseInt(String(Math.random()*1e9),10).toString()}${Date.now()}`}var fn=class{id;fn;options;recipients;status;timeline;controller;constructor(t,e){this.id=Vf(),this.status="queued",this.fn=t,this.options=e,this.recipients=[],this.timeline={created:Date.now()},this.controller=new AbortController,this.controller.signal,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 Bt),this.cleanup())}async join(t={}){let e=new un(t.signal);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 gr(this.fn({...this.options??{},signal:this.controller.signal}),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 ln=class extends Sr{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=mr(this.emitEmpty.bind(this),1),this.emitIdle=mr(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 cn;let n=new fn(t,e);return this.enqueue(n),this.safeDispatchEvent("add"),this.tryToStartAnother(),n.join(e).then(o=>(this.safeDispatchEvent("completed",{detail:o}),this.safeDispatchEvent("success",{detail:{job:n,result:o}}),o)).catch(o=>{if(n.status==="queued"){for(let s=0;s<this.queue.length;s++)if(this.queue[s]===n){this.queue.splice(s,1);break}}throw this.safeDispatchEvent("failure",{detail:{job:n,error:o}}),o})}clear(){this.queue.splice(0,this.queue.length)}abort(){this.queue.forEach(t=>{t.abort(new Bt)}),this.clear()}async onEmpty(t){this.size!==0&&await Ke(this,"empty",t)}async onSizeLessThan(t,e){this.size<t||await Ke(this,"next",{...e,filter:()=>this.size<t})}async onIdle(t){this.pending===0&&this.size===0||await Ke(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=an({objectMode:!0}),n=a=>{a!=null?this.abort():this.clear(),e.end(a)},o=a=>{a.detail!=null&&e.push(a.detail)},s=a=>{n(a.detail.error)},i=()=>{n()},c=()=>{n(new Bt("Queue aborted"))};this.addEventListener("completed",o),this.addEventListener("failure",s),this.addEventListener("idle",i),t?.signal?.addEventListener("abort",c);try{yield*e}finally{this.removeEventListener("completed",o),this.removeEventListener("failure",s),this.removeEventListener("idle",i),t?.signal?.removeEventListener("abort",c),n()}}};function dn(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 st=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},qt=class extends Error{static name="ValidationError";name="ValidationError"},hn=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},pn=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};function is(r){return t=>Q(t,r)}function as(r){return t=>$(t,r)}function Fe(r){return new DataView(r.buffer).getUint16(r.byteOffset).toString()}function pe(r){let t=new ArrayBuffer(2);return new DataView(t).setUint16(0,typeof r=="string"?parseInt(r):r),new Uint8Array(t)}function Ta(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=$(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=pe(n);return Dt([e,o],e.length+o.length)}function Da(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=Ht.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=pe(n);return Dt([e,o],e.length+o.length)}function cs(r){let t=r.subarray(0,r.length-2),e=r.subarray(r.length-2),n=Q(t,"base32"),o=Fe(e);return`${n}:${o}`}var us=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 st("Invalid byte value in IP address");t[n]=o}),t},Ca=function(r){let t=0;r=r.toString().trim();let e=r.split(":",8),n;for(n=0;n<e.length;n++){let s=ke(e[n]),i;s&&(i=us(e[n]),e[n]=Q(i.subarray(0,2),"base16")),i!=null&&++n<8&&e.splice(n,0,Q(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 st("Invalid byte value in IP address");o[t++]=s>>8&255,o[t++]=s&255}return o},Ra=function(r){if(r.byteLength!==4)throw new st("IPv4 address was incorrect length");let t=[];for(let e=0;e<r.byteLength;e++)t.push(r[e]);return t.join(".")},Pa=function(r){if(r.byteLength!==16)throw new st("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 st(`Invalid IPv6 address "${e}"`)}};function Oa(r){try{let t=new URL(`http://[${r}]`);return t.hostname.substring(1,t.hostname.length-1)}catch{throw new st(`Invalid IPv6 address "${r}"`)}}var ss=Object.values(Ge).map(r=>r.decoder),Hf=(function(){let r=ss[0].or(ss[1]);return ss.slice(2).forEach(t=>r=r.or(t)),r})();function Na(r){return Hf.decode(r)}function ka(r){return t=>r.encoder.encode(t)}function $f(r){if(parseInt(r).toString()!==r)throw new qt("Value must be an integer")}function jf(r){if(r<0)throw new qt("Value must be a positive integer, or zero")}function Gf(r){return t=>{if(t>r)throw new qt(`Value must be smaller than or equal to ${r}`)}}function Zf(...r){return t=>{for(let e of r)e(t)}}var br=Zf($f,jf,Gf(65535));var rt=-1,fs=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 pn(`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 fs,Ol=[{code:4,name:"ip4",size:32,valueToBytes:us,bytesToValue:Ra,validate:r=>{if(!ke(r))throw new qt(`Invalid IPv4 address "${r}"`)}},{code:6,name:"tcp",size:16,valueToBytes:pe,bytesToValue:Fe,validate:br},{code:273,name:"udp",size:16,valueToBytes:pe,bytesToValue:Fe,validate:br},{code:33,name:"dccp",size:16,valueToBytes:pe,bytesToValue:Fe,validate:br},{code:41,name:"ip6",size:128,valueToBytes:Ca,bytesToValue:Pa,stringToValue:Oa,validate:r=>{if(!on(r))throw new qt(`Invalid IPv6 address "${r}"`)}},{code:42,name:"ip6zone",size:rt},{code:43,name:"ipcidr",size:8,bytesToValue:is("base10"),valueToBytes:as("base10")},{code:53,name:"dns",size:rt},{code:54,name:"dns4",size:rt},{code:55,name:"dns6",size:rt},{code:56,name:"dnsaddr",size:rt},{code:132,name:"sctp",size:16,valueToBytes:pe,bytesToValue:Fe,validate:br},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:rt,stringToValue:r=>decodeURIComponent(r),valueToString:r=>encodeURIComponent(r)},{code:421,name:"p2p",aliases:["ipfs"],size:rt,bytesToValue:is("base58btc"),valueToBytes:r=>r.startsWith("Q")||r.startsWith("1")?as("base58btc")(r):at.parse(r).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:cs,valueToBytes:Ta},{code:445,name:"onion3",size:296,bytesToValue:cs,valueToBytes:Da},{code:446,name:"garlic64",size:rt},{code:447,name:"garlic32",size:rt},{code:448,name:"tls"},{code:449,name:"sni",size:rt},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:rt,bytesToValue:ka(Nn),valueToBytes:Na},{code:480,name:"http"},{code:481,name:"http-path",size:rt,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:rt}];Ol.forEach(r=>{zt.addProtocol(r)});function Ua(r){let t=[],e=0;for(;e<r.length;){let n=sr(r,e),o=zt.getProtocol(n),s=mt(n),i=Nl(o,r,e+s),c=0;i>0&&o.size===rt&&(c=mt(i));let a=s+c+i,u={code:n,name:o.name,bytes:r.subarray(e,e+a)};if(i>0){let l=e+s+c,f=r.subarray(l,l+i);u.value=o.bytesToValue?.(f)??Q(f)}t.push(u),e+=a}return t}function Ma(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,c=0,a=0;n.value!=null&&(i=o.valueToBytes?.(n.value)??$(n.value),c=i.byteLength,o.size===rt&&(a=mt(c)));let u=new Uint8Array(s+a+c),l=0;Te(n.code,u,l),l+=s,i!=null&&(o.size===rt&&(Te(c,u,l),l+=a),u.set(i,l)),n.bytes=u}e.push(n.bytes),t+=n.bytes.byteLength}return Dt(e,t)}function Ka(r){if(r.charAt(0)!=="/")throw new st('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 c=s===r.length-1;if(i==="/"||c){let a=zt.getProtocol(o);if(e==="protocol"){if(a.size==null||a.size===0){t.push({code:a.code,name:a.name}),n="",o="",e="protocol";continue}else if(c)throw new st(`Component ${o} was missing value`);e="value"}else if(e==="value"){let u={code:a.code,name:a.name};if(a.size!=null&&a.size!==0){if(n==="")throw new st(`Component ${o} was missing value`);u.value=a.stringToValue?.(n)??n}t.push(u),n="",o="",e="protocol"}}}if(o!==""&&n!=="")throw new st("Incomplete multiaddr");return t}function Fa(r){return`/${r.flatMap(t=>{if(t.value==null)return t.name;let e=zt.getProtocol(t.code);if(e==null)throw new st(`Unknown protocol code ${t.code}`);return[t.name,e.valueToString?.(t.value)??t.value]}).join("/")}`}function Nl(r,t,e){return r.size==null||r.size===0?0:r.size>0?r.size/8:sr(t,e)}var kl=Symbol.for("nodejs.util.inspect.custom"),ls=Symbol.for("@multiformats/multiaddr");function Ul(r){if(r==null&&(r="/"),qa(r))return r.getComponents();if(r instanceof Uint8Array)return Ua(r);if(typeof r=="string")return r=r.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),r===""&&(r="/"),Ka(r);if(Array.isArray(r))return r;throw new st("Must be a string, Uint8Array, Component[], or another Multiaddr")}var gn=class r{[ls]=!0;#t;#e;#r;constructor(t="/",e={}){this.#t=Ul(t),e.validate!==!1&&Ml(this)}get bytes(){return this.#r==null&&(this.#r=Ma(this.#t)),this.#r}toString(){return this.#e==null&&(this.#e=Fa(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 hn(`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 lt(this.bytes,t.bytes)}[kl](){return`Multiaddr(${this.toString()})`}};function Ml(r){r.getComponents().forEach(t=>{let e=zt.getProtocol(t.code);t.value!=null&&e.validate?.(t.value)})}function qa(r){return!!r?.[ls]}function za(r){return new gn(r)}var Kl=4194304,bn=class extends Error{static name="UnwrappedError";name="UnwrappedError"},hs=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},ps=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},ms=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function Fl(r){return typeof r?.closeRead=="function"}function ql(r){return typeof r?.close=="function"}function ds(r){return Fl(r)?r.remoteWriteStatus!=="writable"&&r.readBufferLength===0:ql(r)?r.status!=="open":!1}function zl(r){return r?.addEventListener!=null&&r?.removeEventListener!=null&&r?.send!=null&&r?.push!=null&&r?.log!=null}function Vl(r,t){let e=t?.maxBufferSize??Kl,n=new J,o,s=!1;if(!zl(r))throw new ft("Argument should be a Stream or a Multiaddr");let i=l=>{if(n.append(l.data),n.byteLength>e){let f=n.byteLength;n.consume(n.byteLength),o?.reject(new Error(`Read buffer overflow - ${f} > ${e}`))}o?.resolve()};r.addEventListener("message",i);let c=l=>{l.error!=null?o?.reject(l.error):o?.resolve()};r.addEventListener("close",c);let a=()=>{o?.resolve()};r.addEventListener("remoteCloseWrite",a);let u={readBuffer:n,async read(l){if(s===!0)throw new bn("Stream was unwrapped");if(ds(r)){if(l?.bytes==null)return null;if(n.byteLength<l.bytes)throw r.log.error("closed after reading %d/%d bytes",n.byteLength,l.bytes),new he(`Unexpected EOF - stream closed after reading ${n.byteLength}/${l.bytes} bytes`)}let f=l?.bytes??1;for(o=Promise.withResolvers();;){if(n.byteLength>=f){o.resolve();break}if(await gr(o.promise,l?.signal),ds(r)){if(n.byteLength===0&&l?.bytes==null)return null;break}o=Promise.withResolvers()}let d=l?.bytes??n.byteLength;if(n.byteLength<d){if(ds(r))throw r.log.error("closed while reading %d/%d bytes",n.byteLength,d),new he(`Unexpected EOF - stream closed while reading ${n.byteLength}/${d} bytes`);return u.read(l)}let p=n.sublist(0,d);return n.consume(d),p},async write(l,f){if(s===!0)throw new bn("Stream was unwrapped");r.send(l)||await Ke(r,"drain",{signal:f?.signal,rejectionEvents:["close"]})},unwrap(){return s||(s=!0,r.removeEventListener("message",i),r.removeEventListener("close",c),r.removeEventListener("remoteCloseWrite",a),n.byteLength>0&&(r.log("stream unwrapped with %d unread bytes",n.byteLength),r.push(n))),r}};return u}function Hl(r,t={}){let e=Vl(r,t);t.maxDataLength!=null&&t.maxLengthLength==null&&(t.maxLengthLength=mt(t.maxDataLength));let n=t?.lengthDecoder??sr,o=t?.lengthEncoder??Hi;return{async read(i){let c=-1,a=new J;for(;;){let l=await e.read({...i,bytes:1});if(l==null)break;a.append(l);try{c=n(a)}catch(f){if(f instanceof RangeError)continue;throw f}if(c<0)throw new hs("Invalid message length");if(t?.maxLengthLength!=null&&a.byteLength>t.maxLengthLength)throw new ms(`Message length length too long - ${a.byteLength} > ${t.maxLengthLength}`);if(c>-1)break}if(t?.maxDataLength!=null&&c>t.maxDataLength)throw new ps(`Message length too long - ${c} > ${t.maxDataLength}`);let u=await e.read({...i,bytes:c});if(u==null)throw r.log.error("tried to read %d bytes but the stream closed",c),new he(`Unexpected EOF - tried to read ${c} bytes but the stream closed`);if(u.byteLength!==c)throw r.log.error("read %d/%d bytes before the stream closed",u.byteLength,c),new he(`Unexpected EOF - read ${u.byteLength}/${c} bytes before the stream closed`);return u},async write(i,c){await e.write(new J(o(i.byteLength),i),c)},async writeV(i,c){let a=new J(...i.flatMap(u=>[o(u.byteLength),u]));await e.write(a,c)},unwrap(){return e.unwrap()}}}function gs(r,t){let e=Hl(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(c=>s.encode(c)),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 yn=class extends ln{has(t){return this.find(t)!=null}find(t){return this.queue.find(e=>t.equals(e.options.peerId))}};function Va(r,t,e){let n,o,s=!1;function i(){let u={signal:o.signal};if(e?.timeout!=null){let l=dn([o.signal,AbortSignal.timeout(e.timeout)]);u.signal=l}s=!0,Promise.resolve().then(async()=>{await r(u)}).catch(()=>{}).finally(()=>{s=!1,!o.signal.aborted&&(n=setTimeout(i,t))})}let c=mr(i,e?.debounce??100),a=!1;return{setInterval:u=>{t!==u&&(t=u,n!=null&&(clearTimeout(n),n=setTimeout(i,t)))},setTimeout:u=>{e??={},e.timeout=u},run:()=>{s||(clearTimeout(n),c())},start:()=>{a||(a=!0,o=new AbortController,o.signal,e?.runImmediately===!0?queueMicrotask(()=>{i()}):n=setTimeout(i,t))},stop:()=>{clearTimeout(n),o?.abort(),a=!1}}}var bs=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 Ha(r){let{name:t,metrics:e}=r,n;return e!=null?n=new bs({name:t,metrics:e}):n=new Map,n}var $a="libp2p",ja="autonat",Ga="1.0.0";var z;(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=()=>Ce(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=()=>Ce(o)})(n=r.ResponseStatus||(r.ResponseStatus={}));let s;(function(u){let l;u.codec=()=>(l==null&&(l=Kt((f,d,p={})=>{if(p.lengthDelimited!==!1&&d.fork(),f.id!=null&&(d.uint32(10),d.bytes(f.id)),f.addrs!=null)for(let h of f.addrs)d.uint32(18),d.bytes(h);p.lengthDelimited!==!1&&d.ldelim()},(f,d,p={})=>{let h={addrs:[]},v=d==null?f.len:f.pos+d;for(;f.pos<v;){let g=f.uint32();switch(g>>>3){case 1:{h.id=f.bytes();break}case 2:{if(p.limits?.addrs!=null&&h.addrs.length===p.limits.addrs)throw new Vr('Decode error - map field "addrs" had too many elements');h.addrs.push(f.bytes());break}default:{f.skipType(g&7);break}}}return h})),l),u.encode=f=>Mt(f,u.codec()),u.decode=(f,d)=>Ut(f,u.codec(),d)})(s=r.PeerInfo||(r.PeerInfo={}));let i;(function(u){let l;u.codec=()=>(l==null&&(l=Kt((f,d,p={})=>{p.lengthDelimited!==!1&&d.fork(),f.peer!=null&&(d.uint32(10),r.PeerInfo.codec().encode(f.peer,d)),p.lengthDelimited!==!1&&d.ldelim()},(f,d,p={})=>{let h={},v=d==null?f.len:f.pos+d;for(;f.pos<v;){let g=f.uint32();switch(g>>>3){case 1:{h.peer=r.PeerInfo.codec().decode(f,f.uint32(),{limits:p.limits?.peer});break}default:{f.skipType(g&7);break}}}return h})),l),u.encode=f=>Mt(f,u.codec()),u.decode=(f,d)=>Ut(f,u.codec(),d)})(i=r.Dial||(r.Dial={}));let c;(function(u){let l;u.codec=()=>(l==null&&(l=Kt((f,d,p={})=>{p.lengthDelimited!==!1&&d.fork(),f.status!=null&&(d.uint32(8),r.ResponseStatus.codec().encode(f.status,d)),f.statusText!=null&&(d.uint32(18),d.string(f.statusText)),f.addr!=null&&(d.uint32(26),d.bytes(f.addr)),p.lengthDelimited!==!1&&d.ldelim()},(f,d,p={})=>{let h={},v=d==null?f.len:f.pos+d;for(;f.pos<v;){let g=f.uint32();switch(g>>>3){case 1:{h.status=r.ResponseStatus.codec().decode(f);break}case 2:{h.statusText=f.string();break}case 3:{h.addr=f.bytes();break}default:{f.skipType(g&7);break}}}return h})),l),u.encode=f=>Mt(f,u.codec()),u.decode=(f,d)=>Ut(f,u.codec(),d)})(c=r.DialResponse||(r.DialResponse={}));let a;r.codec=()=>(a==null&&(a=Kt((u,l,f={})=>{f.lengthDelimited!==!1&&l.fork(),u.type!=null&&(l.uint32(8),r.MessageType.codec().encode(u.type,l)),u.dial!=null&&(l.uint32(18),r.Dial.codec().encode(u.dial,l)),u.dialResponse!=null&&(l.uint32(26),r.DialResponse.codec().encode(u.dialResponse,l)),f.lengthDelimited!==!1&&l.ldelim()},(u,l,f={})=>{let d={},p=l==null?u.len:u.pos+l;for(;u.pos<p;){let h=u.uint32();switch(h>>>3){case 1:{d.type=r.MessageType.codec().decode(u);break}case 2:{d.dial=r.Dial.codec().decode(u,u.uint32(),{limits:f.limits?.dial});break}case 3:{d.dialResponse=r.DialResponse.codec().decode(u,u.uint32(),{limits:f.limits?.dialResponse});break}default:{u.skipType(h&7);break}}}return d})),a),r.encode=u=>Mt(u,r.codec()),r.decode=(u,l)=>Ut(u,r.codec(),l)})(z||(z={}));var Xl=4,Wl=8,xn=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??$a}/${ja}/${Ga}`,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=Ha({name:"libp2p_autonat_dial_results",metrics:t.metrics}),this.findPeers=Va(this.findRandomPeers.bind(this),6e4),this.addressFilter=Yo(1024)}[Symbol.toStringTag]="@libp2p/autonat";[Es]=["@libp2p/autonat"];get[Ss](){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=dn([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=gs(t,{maxDataLength:this.maxMessageSize}).pb(z),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(f=>_t(f).host),s=t.dial;if(s==null)return this.log.error("dial was missing from message"),{type:z.MessageType.DIAL_RESPONSE,dialResponse:{status:z.ResponseStatus.E_BAD_REQUEST,statusText:"No Dial message found in message"}};let i,c=s.peer;if(c?.id==null)return this.log.error("peerId missing from message"),{type:z.MessageType.DIAL_RESPONSE,dialResponse:{status:z.ResponseStatus.E_BAD_REQUEST,statusText:"missing peer info"}};try{let f=Jt(c.id);i=Wr(f)}catch(f){return this.log.error("invalid PeerId - %e",f),{type:z.MessageType.DIAL_RESPONSE,dialResponse:{status:z.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:z.MessageType.DIAL_RESPONSE,dialResponse:{status:z.ResponseStatus.E_BAD_REQUEST,statusText:"peer id mismatch"}};let a=c.addrs.map(f=>za(f)).filter(f=>{try{let d=_t(f);return ts(f)?!1:d.host!==_t(e.remoteAddr).host?(this.log.trace("not dialing %a - target host did not match remote host %a",f,e.remoteAddr),!1):o.includes(d.host)?!1:this.components.transportManager.dialTransportForMultiaddr(f)==null?(this.log.trace("not dialing %a - transport unsupported",f),!1):!0}catch{return!1}}).map(f=>(f.getComponents().find(d=>d.code===421)?.value==null&&(f=f.encapsulate(`/p2p/${i.toString()}`)),f));if(a.length===0)return this.log("refused to dial all multiaddrs for %p from message",i),{type:z.MessageType.DIAL_RESPONSE,dialResponse:{status:z.ResponseStatus.E_DIAL_REFUSED,statusText:"no dialable addresses"}};this.log("dial multiaddrs %s for peer %p",a.map(f=>f.toString()).join(", "),i);let u="",l=a[0];for(let f of a){let d;l=f;try{if(d=await this.components.connectionManager.openConnection(f,n),!d.remoteAddr.equals(f))throw this.log.error("tried to dial %a but dialed %a",f,d.remoteAddr),new Error("Unexpected remote address");return this.log("successfully dialed %p via %a",i,f),{type:z.MessageType.DIAL_RESPONSE,dialResponse:{status:z.ResponseStatus.OK,addr:d.remoteAddr.decapsulateCode(421).bytes}}}catch(p){this.log.error("could not dial %p - %e",i,p),u=p.message}finally{d!=null&&await d.close()}}return{type:z.MessageType.DIAL_RESPONSE,dialResponse:{status:z.ResponseStatus.E_DIAL_ERROR,statusText:u,addr:l.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())||_t(o.multiaddr).type==="ip6"&&(!e||!va(o.multiaddr))||ts(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 c=o.expires<Date.now();if(c&&this.addressFilter.remove?.(s),this.addressFilter.has(s))continue;this.addressFilter.add(s),this.log.trace("creating dial result %s %s",c?"to revalidate":"for",s),i={multiaddr:o.multiaddr,success:0,failure:0,networkSegments:[],verifyingPeers:$o(),queue:new yn({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})=>_t(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 c=gs(i).pb(z),[,a]=await Promise.all([c.write({type:z.MessageType.DIAL,dial:{peer:{id:this.components.peerId.toMultihash().bytes,addrs:[n.multiaddr.bytes]}}},{signal:s}),c.read({signal:s})]);if(a.type!==z.MessageType.DIAL_RESPONSE||a.dialResponse==null){this.log("invalid autonat response from %p - %j",t.remotePeer,a);return}let u=a.dialResponse.status;if(this.log.trace("autonat response from %p for %a is %s",t.remotePeer,n.multiaddr,u),u!==z.ResponseStatus.OK&&u!==z.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,a.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),u===z.ResponseStatus.OK){if(o.success++,o.type!=="observed"){this.confirmAddress(o);return}}else u===z.ResponseStatus.E_DIAL_ERROR&&o.failure++;this.log("%a success %d failure %d",o.multiaddr,o.success,o.failure),o.success===Xl&&this.confirmAddress(o),o.failure===Wl&&this.unconfirmAddress(o)}finally{try{await i.close({signal:s})}catch(c){i.abort(c)}}}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=_t(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 ft(`Remote address ${t} was not an IPv4 or Ipv6 address`)}}};function Ql(r={}){return t=>new xn(t,r)}return ec(Jl);})();
3
3
  /*! Bundled license information:
4
4
 
5
5
  @noble/hashes/utils.js: