@libp2p/autonat-v2 2.0.9 → 2.0.10
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 +1 -1
- package/dist/index.min.js.map +3 -3
- package/package.json +4 -4
package/dist/index.min.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
(function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.Libp2PAutonatV2 = factory()}(typeof self !== 'undefined' ? self : this, function () {
|
|
2
|
-
"use strict";var Libp2PAutonatV2=(()=>{var xc=Object.create;var Ar=Object.defineProperty;var wc=Object.getOwnPropertyDescriptor;var Ec=Object.getOwnPropertyNames;var Sc=Object.getPrototypeOf,vc=Object.prototype.hasOwnProperty;var _c=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports),gt=(r,t)=>{for(var e in t)Ar(r,e,{get:t[e],enumerable:!0})},ks=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Ec(t))!vc.call(r,o)&&o!==e&&Ar(r,o,{get:()=>t[o],enumerable:!(n=wc(t,o))||n.enumerable});return r};var Ac=(r,t,e)=>(e=r!=null?xc(Sc(r)):{},ks(t||!r||!r.__esModule?Ar(e,"default",{value:r,enumerable:!0}):e,r)),Ic=r=>ks(Ar({},"__esModule",{value:!0}),r);var za=_c(wr=>{(function(){var r,t,e,n,o,s,i,a;a=function(c){var u,l,f,d;return u=(c&255<<24)>>>24,l=(c&255<<16)>>>16,f=(c&65280)>>>8,d=c&255,[u,l,f,d].join(".")},i=function(c){var u,l,f,d,p,h;for(u=[],f=d=0;d<=3&&c.length!==0;f=++d){if(f>0){if(c[0]!==".")throw new Error("Invalid IP");c=c.substring(1)}h=t(c),p=h[0],l=h[1],c=c.substring(l),u.push(p)}if(c.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(c){return c.charCodeAt(0)},n=e("0"),s=e("a"),o=e("A"),t=function(c){var u,l,f,d,p;for(d=0,u=10,l="9",f=0,c.length>1&&c[f]==="0"&&(c[f+1]==="x"||c[f+1]==="X"?(f+=2,u=16):"0"<=c[f+1]&&c[f+1]<="9"&&(f++,u=8,l="7")),p=f;f<c.length;){if("0"<=c[f]&&c[f]<=l)d=d*u+(e(c[f])-n)>>>0;else if(u===16)if("a"<=c[f]&&c[f]<="f")d=d*u+(10+e(c[f])-s)>>>0;else if("A"<=c[f]&&c[f]<="F")d=d*u+(10+e(c[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 c(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=a(this.netLong),this.mask=a(this.maskLong),this.hostmask=a(~this.maskLong),this.first=this.bitmask<=30?a(this.netLong+1):this.base,this.last=this.bitmask<=30?a(this.netLong+this.size-2):a(this.netLong+this.size-1),this.broadcast=this.bitmask<=30?a(this.netLong+this.size-1):void 0}return c.prototype.contains=function(u){return typeof u=="string"&&(u.indexOf("/")>0||u.split(".").length!==4)&&(u=new c(u)),u instanceof c?this.contains(u.base)&&this.contains(u.broadcast||u.last):(i(u)&this.maskLong)>>>0===(this.netLong&this.maskLong)>>>0},c.prototype.next=function(u){return u==null&&(u=1),new c(a(this.netLong+this.size*u),this.mask)},c.prototype.forEach=function(u){var l,f,d;for(d=i(this.first),f=i(this.last),l=0;d<=f;)u(a(d),d,l),l++,d++},c.prototype.toString=function(){return this.base+"/"+this.bitmask},c})(),wr.ip2long=i,wr.long2ip=a,wr.Netmask=r}).call(wr)});var xd={};gt(xd,{autoNATv2:()=>yd});var Tt=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"}},Ir=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var Br=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}};var wt=class extends Error{static name="ProtocolError";constructor(t="Protocol error"){super(t),this.name="ProtocolError"}};var Ge=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var On=Symbol.for("@libp2p/peer-id");function Us(r){return r!=null&&typeof r.start=="function"&&typeof r.stop=="function"}async function Ms(...r){let t=[];for(let e of r)Us(e)&&t.push(e);await Promise.all(t.map(async e=>{e.beforeStart!=null&&await e.beforeStart()})),await Promise.all(t.map(async e=>{await e.start()})),await Promise.all(t.map(async e=>{e.afterStart!=null&&await e.afterStart()}))}async function Ks(...r){let t=[];for(let e of r)Us(e)&&t.push(e);await Promise.all(t.map(async e=>{e.beforeStop!=null&&await e.beforeStop()})),await Promise.all(t.map(async e=>{await e.stop()})),await Promise.all(t.map(async e=>{e.afterStop!=null&&await e.afterStop()}))}var Dr=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 Lr=Symbol.for("@libp2p/service-capabilities"),Rr=Symbol.for("@libp2p/service-dependencies");var Kn={};gt(Kn,{base58btc:()=>Y,base58flickr:()=>Pc});var jd=new Uint8Array(0);function qs(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 Ct(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 Fs(r){return new TextEncoder().encode(r)}function zs(r){return new TextDecoder().decode(r)}function Bc(r,t){if(r.length>=255)throw new TypeError("Alphabet too long");for(var e=new Uint8Array(256),n=0;n<e.length;n++)e[n]=255;for(var o=0;o<r.length;o++){var s=r.charAt(o),i=s.charCodeAt(0);if(e[i]!==255)throw new TypeError(s+" is ambiguous");e[i]=o}var a=r.length,c=r.charAt(0),u=Math.log(a)/Math.log(256),l=Math.log(256)/Math.log(a);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,x=0,y=0,A=h.length;y!==A&&h[y]===0;)y++,v++;for(var w=(A-y)*l+1>>>0,I=new Uint8Array(w);y!==A;){for(var P=h[y],U=0,M=w-1;(P!==0||U<x)&&M!==-1;M--,U++)P+=256*I[M]>>>0,I[M]=P%a>>>0,P=P/a>>>0;if(P!==0)throw new Error("Non-zero carry");x=U,y++}for(var S=w-x;S!==w&&I[S]===0;)S++;for(var E=c.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 x=0,y=0;h[v]===c;)x++,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<y)&&U!==-1;U--,P++)I+=a*w[U]>>>0,w[U]=I%256>>>0,I=I/256>>>0;if(I!==0)throw new Error("Non-zero carry");y=P,v++}if(h[v]!==" "){for(var M=A-y;M!==A&&w[M]===0;)M++;for(var S=new Uint8Array(x+(A-M)),E=x;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 Dc=Bc,Lc=Dc,Hs=Lc;var Nn=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")}},kn=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 $s(this,t)}},Un=class{decoders;constructor(t){this.decoders=t}or(t){return $s(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 $s(r,t){return new Un({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var Mn=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 Nn(t,e,n),this.decoder=new kn(t,e,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function ye({name:r,prefix:t,encode:e,decode:n}){return new Mn(r,t,e,n)}function Ht({name:r,prefix:t,alphabet:e}){let{encode:n,decode:o}=Hs(e,r);return ye({prefix:t,name:r,encode:n,decode:s=>Ct(o(s))})}function Rc(r,t,e,n){let o=r.length;for(;r[o-1]==="=";)--o;let s=new Uint8Array(o*e/8|0),i=0,a=0,c=0;for(let u=0;u<o;++u){let l=t[r[u]];if(l===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<e|l,i+=e,i>=8&&(i-=8,s[c++]=255&a>>i)}if(i>=e||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function Tc(r,t,e){let n=t[t.length-1]==="=",o=(1<<e)-1,s="",i=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],i+=8;i>e;)i-=e,s+=t[o&a>>i];if(i!==0&&(s+=t[o&a<<e-i]),n)for(;(s.length*e&7)!==0;)s+="=";return s}function Cc(r){let t={};for(let e=0;e<r.length;++e)t[r[e]]=e;return t}function X({name:r,prefix:t,bitsPerChar:e,alphabet:n}){let o=Cc(n);return ye({prefix:t,name:r,encode(s){return Tc(s,n,e)},decode(s){return Rc(s,o,e,r)}})}var Y=Ht({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Pc=Ht({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var qn={};gt(qn,{base32:()=>$t,base32hex:()=>Uc,base32hexpad:()=>Kc,base32hexpadupper:()=>qc,base32hexupper:()=>Mc,base32pad:()=>Nc,base32padupper:()=>kc,base32upper:()=>Oc,base32z:()=>Fc});var $t=X({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Oc=X({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Nc=X({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),kc=X({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Uc=X({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Mc=X({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Kc=X({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),qc=X({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Fc=X({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Fn={};gt(Fn,{base36:()=>Ze,base36upper:()=>zc});var Ze=Ht({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),zc=Ht({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Vc=Xs,Gs=128,Hc=127,$c=~Hc,Gc=Math.pow(2,31);function Xs(r,t,e){t=t||[],e=e||0;for(var n=e;r>=Gc;)t[e++]=r&255|Gs,r/=128;for(;r&$c;)t[e++]=r&255|Gs,r>>>=7;return t[e]=r|0,Xs.bytes=e-n+1,t}var Zc=zn,Xc=128,Zs=127;function zn(r,n){var e=0,n=n||0,o=0,s=n,i,a=r.length;do{if(s>=a)throw zn.bytes=0,new RangeError("Could not decode varint");i=r[s++],e+=o<28?(i&Zs)<<o:(i&Zs)*Math.pow(2,o),o+=7}while(i>=Xc);return zn.bytes=s-n,e}var Yc=Math.pow(2,7),jc=Math.pow(2,14),Wc=Math.pow(2,21),Qc=Math.pow(2,28),Jc=Math.pow(2,35),tu=Math.pow(2,42),eu=Math.pow(2,49),ru=Math.pow(2,56),nu=Math.pow(2,63),ou=function(r){return r<Yc?1:r<jc?2:r<Wc?3:r<Qc?4:r<Jc?5:r<tu?6:r<eu?7:r<ru?8:r<nu?9:10},su={encode:Vc,decode:Zc,encodingLength:ou},iu=su,Xe=iu;function Ye(r,t=0){return[Xe.decode(r,t),Xe.decode.bytes]}function xe(r,t,e=0){return Xe.encode(r,t,e),t}function we(r){return Xe.encodingLength(r)}function Se(r,t){let e=t.byteLength,n=we(r),o=n+we(e),s=new Uint8Array(o+e);return xe(r,s,0),xe(e,s,n),s.set(t,o),new Ee(r,e,t,s)}function je(r){let t=Ct(r),[e,n]=Ye(t),[o,s]=Ye(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new Ee(e,o,i,t)}function Ys(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&qs(r.bytes,e.bytes)}}var Ee=class{code;size;digest;bytes;constructor(t,e,n,o){this.code=t,this.size=e,this.digest=n,this.bytes=o}};function js(r,t){let{bytes:e,version:n}=r;switch(n){case 0:return cu(e,Vn(r),t??Y.encoder);default:return uu(e,Vn(r),t??$t.encoder)}}var Ws=new WeakMap;function Vn(r){let t=Ws.get(r);if(t==null){let e=new Map;return Ws.set(r,e),e}return t}var it=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!==We)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==fu)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=Se(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&&Ys(t.multihash,n.multihash)}toString(t){return js(this,t)}toJSON(){return{"/":js(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??Qs(n,o,s.bytes))}else if(e[lu]===!0){let{version:n,multihash:o,code:s}=e,i=je(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!==We)throw new Error(`Version 0 CID must use dag-pb (code: ${We}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let o=Qs(t,e,n.bytes);return new r(t,e,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,We,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=Ct(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 Ee(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]=Ye(t.subarray(e));return e+=d,f},o=n(),s=We;if(o===18?(o=0,e=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=e,a=n(),c=n(),u=e+c,l=u-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:l,size:u}}static parse(t,e){let[n,o]=au(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 Vn(s).set(n,t),s}};function au(r,t){switch(r[0]){case"Q":{let e=t??Y;return[Y.prefix,e.decode(`${Y.prefix}${r}`)]}case Y.prefix:{let e=t??Y;return[Y.prefix,e.decode(r)]}case $t.prefix:{let e=t??$t;return[$t.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 cu(r,t,e){let{prefix:n}=e;if(n!==Y.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 uu(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 We=112,fu=18;function Qs(r,t,e){let n=we(r),o=n+we(t),s=new Uint8Array(o+e.byteLength);return xe(r,s,0),xe(t,s,n),s.set(e,o),s}var lu=Symbol.for("@ipld/js-cid/CID");var Hn={};gt(Hn,{identity:()=>_t});var Js=0,du="identity",ti=Ct;function hu(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 Se(Js,ti(r))}var _t={code:Js,name:du,encode:ti,digest:hu};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 bt(r=0){return new Uint8Array(r)}function ht(r=0){return new Uint8Array(r)}function Pt(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 ri=Symbol.for("@achingbrain/uint8arraylist");function ei(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 Cr(r){return!!r?.[ri]}var Q=class r{bufs;length;[ri]=!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(Cr(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(Cr(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=ei(this.bufs,t);return e.buf[e.index]}set(t,e){let n=ei(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(Cr(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 Pt(n,o)}subarray(t,e){let{bufs:n,length:o}=this._subList(t,e);return n.length===1?n[0]:Pt(n,o)}sublist(t,e){let{bufs:n,length:o}=this._subList(t,e),s=new r;return s.length=o,s.bufs=[...n],s}_subList(t,e){if(t=t??0,e=e??this.length,t<0&&(t=this.length+t),e<0&&(e=this.length+e),t<0||e>this.length)throw new RangeError("index is out of bounds");if(t===e)return{bufs:[],length:0};if(t===0&&e===this.length)return{bufs:this.bufs,length:this.length};let n=[],o=0;for(let s=0;s<this.bufs.length;s++){let i=this.bufs[s],a=o,c=a+i.byteLength;if(o=c,t>=c)continue;let u=t>=a&&t<c,l=e>a&&e<=c;if(u&&l){if(t===a&&e===c){n.push(i);break}let f=t-a;n.push(i.subarray(f,f+(e-t)));break}if(u){if(t===0){n.push(i);continue}n.push(i.subarray(t-a));continue}if(l){if(e===c){n.push(i);break}n.push(i.subarray(0,e-a));break}n.push(i)}return{bufs:n,length:e-t}}indexOf(t,e=0){if(!Cr(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 a=i,c=this.byteLength-n.byteLength,u=n.byteLength-1,l;for(let f=e;f<=c;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-a[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=bt(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=bt(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=bt(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=bt(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=bt(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=bt(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=bt(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=bt(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 $n={};gt($n,{base10:()=>pu});var pu=Ht({prefix:"9",name:"base10",alphabet:"0123456789"});var Gn={};gt(Gn,{base16:()=>mu,base16upper:()=>gu});var mu=X({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),gu=X({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Zn={};gt(Zn,{base2:()=>bu});var bu=X({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Xn={};gt(Xn,{base256emoji:()=>Su});var ni=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}"),yu=ni.reduce((r,t,e)=>(r[e]=t,r),[]),xu=ni.reduce((r,t,e)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return r[n]=e,r},[]);function wu(r){return r.reduce((t,e)=>(t+=yu[e],t),"")}function Eu(r){let t=[];for(let e of r){let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);let o=xu[n];if(o==null)throw new Error(`Non-base256emoji character: ${e}`);t.push(o)}return new Uint8Array(t)}var Su=ye({prefix:"\u{1F680}",name:"base256emoji",encode:wu,decode:Eu});var jn={};gt(jn,{base64:()=>vu,base64pad:()=>_u,base64url:()=>Yn,base64urlpad:()=>Au});var vu=X({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),_u=X({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Yn=X({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Au=X({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Wn={};gt(Wn,{base8:()=>Iu});var Iu=X({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Qn={};gt(Qn,{identity:()=>Bu});var Bu=ye({prefix:"\0",name:"identity",encode:r=>zs(r),decode:r=>Fs(r)});var Ph=new TextEncoder,Oh=new TextDecoder;var eo={};gt(eo,{sha256:()=>Qe,sha512:()=>Tu});var Ru=20;function to({name:r,code:t,encode:e,minDigestLength:n,maxDigestLength:o}){return new Jn(r,t,e,n,o)}var Jn=class{name;code;encode;minDigestLength;maxDigestLength;constructor(t,e,n,o,s){this.name=t,this.code=e,this.encode=n,this.minDigestLength=o??Ru,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?oi(n,this.code,e?.truncate):n.then(o=>oi(o,this.code,e?.truncate))}else throw Error("Unknown type, must be binary type")}};function oi(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 Se(t,r)}function ii(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var Qe=to({name:"sha2-256",code:18,encode:ii("SHA-256")}),Tu=to({name:"sha2-512",code:19,encode:ii("SHA-512")});var Je={...Qn,...Zn,...Wn,...$n,...Gn,...qn,...Fn,...Kn,...jn,...Xn},Gh={...eo,...Hn};function ci(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var ai=ci("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),ro=ci("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}),Cu={utf8:ai,"utf-8":ai,hex:Je.base16,latin1:ro,ascii:ro,binary:ro,...Je},Pr=Cu;function H(r,t="utf8"){let e=Pr[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.decoder.decode(`${e.prefix}${r}`)}function W(r,t="utf8"){let e=Pr[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.encoder.encode(r).substring(1)}var Pu=parseInt("11111",2),no=parseInt("10000000",2),Ou=parseInt("01111111",2),ui={0:tr,1:tr,2:Nu,3:Mu,4:Ku,5:Uu,6:ku,16:tr,22:tr,48:tr};function oo(r,t={offset:0}){let e=r[t.offset]&Pu;if(t.offset++,ui[e]!=null)return ui[e](r,t);throw new Error("No decoder for tag "+e)}function er(r,t){let e=0;if((r[t.offset]&no)===no){let n=r[t.offset]&Ou,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 tr(r,t){er(r,t);let e=[];for(;!(t.offset>=r.byteLength);){let n=oo(r,t);if(n===null)break;e.push(n)}return e}function Nu(r,t){let e=er(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 ku(r,t){let e=er(r,t),n=t.offset+e,o=r[t.offset];t.offset++;let s=0,i=0;o<40?(s=0,i=o):o<80?(s=1,i=o-40):(s=2,i=o-80);let a=`${s}.${i}`,c=[];for(;t.offset<n;){let u=r[t.offset];if(t.offset++,c.push(u&127),u<128){c.reverse();let l=0;for(let f=0;f<c.length;f++)l+=c[f]<<f*7;a+=`.${l}`,c=[]}}return a}function Uu(r,t){return t.offset++,null}function Mu(r,t){let e=er(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 Ku(r,t){let e=er(r,t),n=r.subarray(t.offset,t.offset+e);return t.offset+=e,n}function qu(r){let t=r.toString(16);t.length%2===1&&(t="0"+t);let e=new Q;for(let n=0;n<t.length;n+=2)e.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return e}function so(r){if(r.byteLength<128)return Uint8Array.from([r.byteLength]);let t=qu(r.byteLength);return new Q(Uint8Array.from([t.byteLength|no]),t)}function fi(r){let t=new Q,e=128;return(r.subarray()[0]&e)===e&&t.append(Uint8Array.from([0])),t.append(r),new Q(Uint8Array.from([2]),so(t),t)}function li(r){let t=Uint8Array.from([0]),e=new Q(t,r);return new Q(Uint8Array.from([3]),so(e),e)}function Or(r,t=48){let e=new Q;for(let n of r)e.append(n);return new Q(Uint8Array.from([t]),so(e),e)}async function di(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 Fu=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),zu=Uint8Array.from([6,5,43,129,4,0,34]),Vu=Uint8Array.from([6,5,43,129,4,0,35]),Hu={ext:!0,kty:"EC",crv:"P-256"},$u={ext:!0,kty:"EC",crv:"P-384"},Gu={ext:!0,kty:"EC",crv:"P-521"},io=32,ao=48,co=66;function hi(r){let t=oo(r);return pi(t)}function pi(r){let t=r[1][1][0],e=1,n,o;if(t.byteLength===io*2+1)return n=W(t.subarray(e,e+io),"base64url"),o=W(t.subarray(e+io),"base64url"),new ve({...Hu,key_ops:["verify"],x:n,y:o});if(t.byteLength===ao*2+1)return n=W(t.subarray(e,e+ao),"base64url"),o=W(t.subarray(e+ao),"base64url"),new ve({...$u,key_ops:["verify"],x:n,y:o});if(t.byteLength===co*2+1)return n=W(t.subarray(e,e+co),"base64url"),o=W(t.subarray(e+co),"base64url"),new ve({...Gu,key_ops:["verify"],x:n,y:o});throw new ft(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function mi(r){return Or([fi(Uint8Array.from([1])),Or([Zu(r.crv)],160),Or([li(new Q(Uint8Array.from([4]),H(r.x??"","base64url"),H(r.y??"","base64url")))],161)]).subarray()}function Zu(r){if(r==="P-256")return Fu;if(r==="P-384")return zu;if(r==="P-521")return Vu;throw new ft(`Invalid curve ${r}`)}var ve=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=mi(this.jwk)),this._raw}toMultihash(){return _t.digest(_e(this))}toCID(){return it.createV1(114,this.toMultihash())}toString(){return Y.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 di(this.jwk,e,t,n)}};function re(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function Lt(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=re(r),o=r?.length,s=t!==void 0;if(!n||s&&o!==t){let i=e&&`"${e}" `,a=s?` of length ${t}`:"",c=n?`length=${o}`:`type=${typeof r}`;throw new Error(i+"expected Uint8Array"+a+", got "+c)}return r}function Nr(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash must wrapped by utils.createHasher");Lt(r.outputLen),Lt(r.blockLen)}function Ae(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 bi(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 Nt(...r){for(let t=0;t<r.length;t++)r[t].fill(0)}function kr(r){return new DataView(r.buffer,r.byteOffset,r.byteLength)}function At(r,t){return r<<32-t|r>>>t}var yi=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Xu=Array.from({length:256},(r,t)=>t.toString(16).padStart(2,"0"));function kt(r){if(k(r),yi)return r.toHex();let t="";for(let e=0;e<r.length;e++)t+=Xu[r[e]];return t}var Ot={_0:48,_9:57,A:65,F:70,a:97,f:102};function gi(r){if(r>=Ot._0&&r<=Ot._9)return r-Ot._0;if(r>=Ot.A&&r<=Ot.F)return r-(Ot.A-10);if(r>=Ot.a&&r<=Ot.f)return r-(Ot.a-10)}function Ut(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);if(yi)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=gi(r.charCodeAt(s)),a=gi(r.charCodeAt(s+1));if(i===void 0||a===void 0){let c=r[s]+r[s+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+s)}n[o]=i*16+a}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 uo(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 Ie(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 fo=r=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,r])});function xi(r,t,e){return r&t^~r&e}function wi(r,t,e){return r&t^r&e^t&e}var rr=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=kr(this.buffer)}update(t){Ae(this),k(t);let{view:e,buffer:n,blockLen:o}=this,s=t.length;for(let i=0;i<s;){let a=Math.min(o-this.pos,s-i);if(a===o){let c=kr(t);for(;o<=s-i;i+=o)this.process(c,i);continue}n.set(t.subarray(i,i+a),this.pos),this.pos+=a,i+=a,this.pos===o&&(this.process(e,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){Ae(this),bi(t,this),this.finished=!0;let{buffer:e,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;e[i++]=128,Nt(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 a=kr(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen must be aligned to 32bit");let u=c/4,l=this.get();if(u>l.length)throw new Error("_sha2: outputLen bigger than state");for(let f=0;f<u;f++)a.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:a}=this;return t.destroyed=i,t.finished=s,t.length=o,t.pos=a,o%e&&t.buffer.set(n),t}clone(){return this._cloneInto()}},Mt=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var nt=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var Ur=BigInt(4294967295),Ei=BigInt(32);function Yu(r,t=!1){return t?{h:Number(r&Ur),l:Number(r>>Ei&Ur)}:{h:Number(r>>Ei&Ur)|0,l:Number(r&Ur)|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:a}=Yu(r[s],t);[n[s],o[s]]=[i,a]}return[n,o]}var lo=(r,t,e)=>r>>>e,ho=(r,t,e)=>r<<32-e|t>>>e,ne=(r,t,e)=>r>>>e|t<<32-e,oe=(r,t,e)=>r<<32-e|t>>>e,nr=(r,t,e)=>r<<64-e|t>>>e-32,or=(r,t,e)=>r>>>e-32|t<<64-e;function Rt(r,t,e,n){let o=(t>>>0)+(n>>>0);return{h:r+e+(o/2**32|0)|0,l:o|0}}var vi=(r,t,e)=>(r>>>0)+(t>>>0)+(e>>>0),_i=(r,t,e,n)=>t+e+n+(r/2**32|0)|0,Ai=(r,t,e,n)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0),Ii=(r,t,e,n,o)=>t+e+n+o+(r/2**32|0)|0,Bi=(r,t,e,n,o)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0)+(o>>>0),Di=(r,t,e,n,o,s)=>t+e+n+o+s+(r/2**32|0)|0;var Wu=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]),Gt=new Uint32Array(64),po=class extends rr{constructor(t){super(64,t,8,!1)}get(){let{A:t,B:e,C:n,D:o,E:s,F:i,G:a,H:c}=this;return[t,e,n,o,s,i,a,c]}set(t,e,n,o,s,i,a,c){this.A=t|0,this.B=e|0,this.C=n|0,this.D=o|0,this.E=s|0,this.F=i|0,this.G=a|0,this.H=c|0}process(t,e){for(let f=0;f<16;f++,e+=4)Gt[f]=t.getUint32(e,!1);for(let f=16;f<64;f++){let d=Gt[f-15],p=Gt[f-2],h=At(d,7)^At(d,18)^d>>>3,v=At(p,17)^At(p,19)^p>>>10;Gt[f]=v+Gt[f-7]+h+Gt[f-16]|0}let{A:n,B:o,C:s,D:i,E:a,F:c,G:u,H:l}=this;for(let f=0;f<64;f++){let d=At(a,6)^At(a,11)^At(a,25),p=l+d+xi(a,c,u)+Wu[f]+Gt[f]|0,v=(At(n,2)^At(n,13)^At(n,22))+wi(n,o,s)|0;l=u,u=c,c=a,a=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,a=a+this.E|0,c=c+this.F|0,u=u+this.G|0,l=l+this.H|0,this.set(n,o,s,i,a,c,u,l)}roundClean(){Nt(Gt)}destroy(){this.set(0,0,0,0,0,0,0,0),Nt(this.buffer)}},mo=class extends po{A=Mt[0]|0;B=Mt[1]|0;C=Mt[2]|0;D=Mt[3]|0;E=Mt[4]|0;F=Mt[5]|0;G=Mt[6]|0;H=Mt[7]|0;constructor(){super(32)}};var Li=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))),Qu=Li[0],Ju=Li[1],Zt=new Uint32Array(80),Xt=new Uint32Array(80),go=class extends rr{constructor(t){super(128,t,16,!1)}get(){let{Ah:t,Al:e,Bh:n,Bl:o,Ch:s,Cl:i,Dh:a,Dl:c,Eh:u,El:l,Fh:f,Fl:d,Gh:p,Gl:h,Hh:v,Hl:x}=this;return[t,e,n,o,s,i,a,c,u,l,f,d,p,h,v,x]}set(t,e,n,o,s,i,a,c,u,l,f,d,p,h,v,x){this.Ah=t|0,this.Al=e|0,this.Bh=n|0,this.Bl=o|0,this.Ch=s|0,this.Cl=i|0,this.Dh=a|0,this.Dl=c|0,this.Eh=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=x|0}process(t,e){for(let w=0;w<16;w++,e+=4)Zt[w]=t.getUint32(e),Xt[w]=t.getUint32(e+=4);for(let w=16;w<80;w++){let I=Zt[w-15]|0,P=Xt[w-15]|0,U=ne(I,P,1)^ne(I,P,8)^lo(I,P,7),M=oe(I,P,1)^oe(I,P,8)^ho(I,P,7),S=Zt[w-2]|0,E=Xt[w-2]|0,O=ne(S,E,19)^nr(S,E,61)^lo(S,E,6),K=oe(S,E,19)^or(S,E,61)^ho(S,E,6),R=Ai(M,K,Xt[w-7],Xt[w-16]),g=Ii(R,U,O,Zt[w-7],Zt[w-16]);Zt[w]=g|0,Xt[w]=R|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:a,Cl:c,Dh:u,Dl:l,Eh:f,El:d,Fh:p,Fl:h,Gh:v,Gl:x,Hh:y,Hl:A}=this;for(let w=0;w<80;w++){let I=ne(f,d,14)^ne(f,d,18)^nr(f,d,41),P=oe(f,d,14)^oe(f,d,18)^or(f,d,41),U=f&p^~f&v,M=d&h^~d&x,S=Bi(A,P,M,Ju[w],Xt[w]),E=Di(S,y,I,U,Qu[w],Zt[w]),O=S|0,K=ne(n,o,28)^nr(n,o,34)^nr(n,o,39),R=oe(n,o,28)^or(n,o,34)^or(n,o,39),g=n&s^n&a^s&a,b=o&i^o&c^i&c;y=v|0,A=x|0,v=p|0,x=h|0,p=f|0,h=d|0,{h:f,l:d}=Rt(u|0,l|0,E|0,O|0),u=a|0,l=c|0,a=s|0,c=i|0,s=n|0,i=o|0;let m=vi(O,R,b);n=_i(m,E,K,g),o=m|0}({h:n,l:o}=Rt(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=Rt(this.Bh|0,this.Bl|0,s|0,i|0),{h:a,l:c}=Rt(this.Ch|0,this.Cl|0,a|0,c|0),{h:u,l}=Rt(this.Dh|0,this.Dl|0,u|0,l|0),{h:f,l:d}=Rt(this.Eh|0,this.El|0,f|0,d|0),{h:p,l:h}=Rt(this.Fh|0,this.Fl|0,p|0,h|0),{h:v,l:x}=Rt(this.Gh|0,this.Gl|0,v|0,x|0),{h:y,l:A}=Rt(this.Hh|0,this.Hl|0,y|0,A|0),this.set(n,o,s,i,a,c,u,l,f,d,p,h,v,x,y,A)}roundClean(){Nt(Zt,Xt)}destroy(){Nt(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},bo=class extends go{Ah=nt[0]|0;Al=nt[1]|0;Bh=nt[2]|0;Bl=nt[3]|0;Ch=nt[4]|0;Cl=nt[5]|0;Dh=nt[6]|0;Dl=nt[7]|0;Eh=nt[8]|0;El=nt[9]|0;Fh=nt[10]|0;Fl=nt[11]|0;Gh=nt[12]|0;Gl=nt[13]|0;Hh=nt[14]|0;Hl=nt[15]|0;constructor(){super(64)}};var Ri=uo(()=>new mo,fo(1));var Ti=uo(()=>new bo,fo(3));var xo=BigInt(0),yo=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 Ci(r){if(typeof r=="bigint"){if(!Mr(r))throw new Error("positive bigint expected, got "+r)}else Lt(r);return r}function sr(r){let t=Ci(r).toString(16);return t.length&1?"0"+t:t}function Pi(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return r===""?xo:BigInt("0x"+r)}function Be(r){return Pi(kt(r))}function se(r){return Pi(kt(qr(k(r)).reverse()))}function Kr(r,t){Lt(t),r=Ci(r);let e=Ut(r.toString(16).padStart(t*2,"0"));if(e.length!==t)throw new Error("number too large");return e}function wo(r,t){return Kr(r,t).reverse()}function qr(r){return Uint8Array.from(r)}var Mr=r=>typeof r=="bigint"&&xo<=r;function tf(r,t,e){return Mr(r)&&Mr(t)&&Mr(e)&&t<=r&&r<e}function ir(r,t,e,n){if(!tf(t,e,n))throw new Error("expected valid "+r+": "+e+" <= n < "+n+", got "+t)}function Eo(r){let t;for(t=0;r>xo;r>>=yo,t+=1);return t}var ar=r=>(yo<<BigInt(r))-yo;function Oi(r,t,e){if(Lt(r,"hashLen"),Lt(t,"qByteLen"),typeof e!="function")throw new Error("hmacFn must be a function");let n=x=>new Uint8Array(x),o=Uint8Array.of(),s=Uint8Array.of(0),i=Uint8Array.of(1),a=1e3,c=n(r),u=n(r),l=0,f=()=>{c.fill(1),u.fill(0),l=0},d=(...x)=>e(u,pt(c,...x)),p=(x=o)=>{u=d(s,x),c=d(),x.length!==0&&(u=d(i,x),c=d())},h=()=>{if(l++>=a)throw new Error("drbg: tried max amount of iterations");let x=0,y=[];for(;x<t;){c=d();let A=c.slice();y.push(A),x+=c.length}return pt(...y)};return(x,y)=>{f(),p(x);let A;for(;!(A=y(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,a){let c=r[s];if(a&&c===void 0)return;let u=typeof c;if(u!==i||c===null)throw new Error(`param "${s}" is invalid: expected ${i}, got ${u}`)}let o=(s,i)=>Object.entries(s).forEach(([a,c])=>n(a,c,i));o(t,!1),o(e,!0)}function De(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),J=BigInt(1),ie=BigInt(2),Ui=BigInt(3),Mi=BigInt(4),Ki=BigInt(5),ef=BigInt(7),qi=BigInt(8),rf=BigInt(9),Fi=BigInt(16);function j(r,t){let e=r%t;return e>=dt?e:t+e}function V(r,t,e){let n=r;for(;t-- >dt;)n*=n,n%=e;return n}function Ni(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=j(r,t),n=t,o=dt,s=J,i=J,a=dt;for(;e!==dt;){let u=n/e,l=n%e,f=o-i*u,d=s-a*u;n=e,e=l,o=i,s=a,i=f,a=d}if(n!==J)throw new Error("invert: does not exist");return j(o,t)}function vo(r,t,e){if(!r.eql(r.sqr(t),e))throw new Error("Cannot find square root")}function zi(r,t){let e=(r.ORDER+J)/Mi,n=r.pow(t,e);return vo(r,n,t),n}function nf(r,t){let e=(r.ORDER-Ki)/qi,n=r.mul(t,ie),o=r.pow(n,e),s=r.mul(t,o),i=r.mul(r.mul(s,ie),o),a=r.mul(s,r.sub(i,r.ONE));return vo(r,a,t),a}function of(r){let t=Le(r),e=Vi(r),n=e(t,t.neg(t.ONE)),o=e(t,n),s=e(t,t.neg(n)),i=(r+ef)/Fi;return(a,c)=>{let u=a.pow(c,i),l=a.mul(u,n),f=a.mul(u,o),d=a.mul(u,s),p=a.eql(a.sqr(l),c),h=a.eql(a.sqr(f),c);u=a.cmov(u,l,p),l=a.cmov(d,f,h);let v=a.eql(a.sqr(l),c),x=a.cmov(u,l,v);return vo(a,x,c),x}}function Vi(r){if(r<Ui)throw new Error("sqrt is not defined for small field");let t=r-J,e=0;for(;t%ie===dt;)t/=ie,e++;let n=ie,o=Le(r);for(;ki(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(e===1)return zi;let s=o.pow(n,t),i=(t+J)/ie;return function(c,u){if(c.is0(u))return u;if(ki(c,u)!==1)throw new Error("Cannot find square root");let l=e,f=c.mul(c.ONE,s),d=c.pow(u,t),p=c.pow(u,i);for(;!c.eql(d,c.ONE);){if(c.is0(d))return c.ZERO;let h=1,v=c.sqr(d);for(;!c.eql(v,c.ONE);)if(h++,v=c.sqr(v),h===l)throw new Error("Cannot find square root");let x=J<<BigInt(l-h-1),y=c.pow(f,x);l=h,f=c.sqr(y),d=c.mul(d,f),p=c.mul(p,y)}return p}}function sf(r){return r%Mi===Ui?zi:r%qi===Ki?nf:r%Fi===rf?of(r):Vi(r)}var Hi=(r,t)=>(j(r,t)&J)===J,af=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function _o(r){let t={ORDER:"bigint",BYTES:"number",BITS:"number"},e=af.reduce((n,o)=>(n[o]="function",n),t);return Yt(r,e),r}function cf(r,t,e){if(e<dt)throw new Error("invalid exponent, negatives unsupported");if(e===dt)return r.ONE;if(e===J)return t;let n=r.ONE,o=t;for(;e>dt;)e&J&&(n=r.mul(n,o)),o=r.sqr(o),e>>=J;return n}function cr(r,t,e=!1){let n=new Array(t.length).fill(e?r.ZERO:void 0),o=t.reduce((i,a,c)=>r.is0(a)?i:(n[c]=i,r.mul(i,a)),r.ONE),s=r.inv(o);return t.reduceRight((i,a,c)=>r.is0(a)?i:(n[c]=r.mul(i,n[c]),r.mul(i,a)),s),n}function ki(r,t){let e=(r.ORDER-J)/ie,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 uf(r,t){t!==void 0&&Lt(t);let e=t!==void 0?t:r.toString(2).length,n=Math.ceil(e/8);return{nBitLength:e,nByteLength:n}}var So=class{ORDER;BITS;BYTES;isLE;ZERO=dt;ONE=J;_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}=uf(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 j(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&J)===J}neg(t){return j(-t,this.ORDER)}eql(t,e){return t===e}sqr(t){return j(t*t,this.ORDER)}add(t,e){return j(t+e,this.ORDER)}sub(t,e){return j(t-e,this.ORDER)}mul(t,e){return j(t*e,this.ORDER)}pow(t,e){return cf(this,t,e)}div(t,e){return j(t*Ni(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 Ni(t,this.ORDER)}sqrt(t){return this._sqrt||(this._sqrt=sf(this.ORDER)),this._sqrt(this,t)}toBytes(t){return this.isLE?wo(t,this.BYTES):Kr(t,this.BYTES)}fromBytes(t,e=!1){k(t);let{_lengths:n,BYTES:o,isLE:s,ORDER:i,_mod:a}=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 c=s?se(t):Be(t);if(a&&(c=j(c,i)),!e&&!this.isValid(c))throw new Error("invalid field element: outside of range 0..ORDER");return c}invertBatch(t){return cr(this,t)}cmov(t,e,n){return n?e:t}};function Le(r,t={}){return new So(r,t)}function $i(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 Ao(r){let t=$i(r);return t+Math.ceil(t/2)}function Io(r,t,e=!1){k(r);let n=r.length,o=$i(t),s=Ao(t);if(n<16||n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=e?se(r):Be(r),a=j(i,t-J)+J;return e?wo(a,o):Kr(a,o)}var Re=BigInt(0),ae=BigInt(1);function ur(r,t){let e=t.negate();return r?e:t}function ce(r,t){let e=cr(r.Fp,t.map(n=>n.Z));return t.map((n,o)=>r.fromAffine(n.toAffine(e[o])))}function Yi(r,t){if(!Number.isSafeInteger(r)||r<=0||r>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+r)}function Bo(r,t){Yi(r,t);let e=Math.ceil(t/r)+1,n=2**(r-1),o=2**r,s=ar(r),i=BigInt(r);return{windows:e,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function Gi(r,t,e){let{windowSize:n,mask:o,maxNumber:s,shiftBy:i}=e,a=Number(r&o),c=r>>i;a>n&&(a-=s,c+=ae);let u=t*n,l=u+Math.abs(a)-1,f=a===0,d=a<0,p=t%2!==0;return{nextN:c,offset:l,isZero:f,isNeg:d,isNegF:p,offsetF:u}}var Do=new WeakMap,ji=new WeakMap;function Lo(r){return ji.get(r)||1}function Zi(r){if(r!==Re)throw new Error("invalid wNAF")}var Te=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>Re;)e&ae&&(n=n.add(o)),o=o.double(),e>>=ae;return n}precomputeWindow(t,e){let{windows:n,windowSize:o}=Bo(e,this.bits),s=[],i=t,a=i;for(let c=0;c<n;c++){a=i,s.push(a);for(let u=1;u<o;u++)a=a.add(i),s.push(a);i=a.double()}return s}wNAF(t,e,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let o=this.ZERO,s=this.BASE,i=Bo(t,this.bits);for(let a=0;a<i.windows;a++){let{nextN:c,offset:u,isZero:l,isNeg:f,isNegF:d,offsetF:p}=Gi(n,a,i);n=c,l?s=s.add(ur(d,e[p])):o=o.add(ur(f,e[u]))}return Zi(n),{p:o,f:s}}wNAFUnsafe(t,e,n,o=this.ZERO){let s=Bo(t,this.bits);for(let i=0;i<s.windows&&n!==Re;i++){let{nextN:a,offset:c,isZero:u,isNeg:l}=Gi(n,i,s);if(n=a,!u){let f=e[c];o=o.add(l?f.negate():f)}}return Zi(n),o}getPrecomputes(t,e,n){let o=Do.get(e);return o||(o=this.precomputeWindow(e,t),t!==1&&(typeof n=="function"&&(o=n(o)),Do.set(e,o))),o}cached(t,e,n){let o=Lo(t);return this.wNAF(o,this.getPrecomputes(o,t,n),e)}unsafe(t,e,n,o){let s=Lo(t);return s===1?this._unsafeLadder(t,e,o):this.wNAFUnsafe(s,this.getPrecomputes(s,t,n),e,o)}createCache(t,e){Yi(e,this.bits),ji.set(t,e),Do.delete(t)}hasCache(t){return Lo(t)!==1}};function Wi(r,t,e,n){let o=t,s=r.ZERO,i=r.ZERO;for(;e>Re||n>Re;)e&ae&&(s=s.add(o)),n&ae&&(i=i.add(o)),o=o.double(),e>>=ae,n>>=ae;return{p1:s,p2:i}}function Xi(r,t,e){if(t){if(t.ORDER!==r)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return _o(t),t}else return Le(r,{isLE:e})}function Fr(r,t,e={},n){if(n===void 0&&(n=r==="edwards"),!t||typeof t!="object")throw new Error(`expected valid ${r} CURVE object`);for(let c of["p","n","h"]){let u=t[c];if(!(typeof u=="bigint"&&u>Re))throw new Error(`CURVE.${c} must be positive bigint`)}let o=Xi(t.p,e.Fp,n),s=Xi(t.n,e.Fn,n),a=["Gx","Gy","a",r==="weierstrass"?"b":"d"];for(let c of a)if(!o.isValid(t[c]))throw new Error(`CURVE.${c} must be valid field element of CURVE.Fp`);return t=Object.freeze(Object.assign({},t)),{CURVE:t,Fp:o,Fn:s}}function zr(r,t){return function(n){let o=r(n);return{secretKey:o,publicKey:t(o)}}}var jt=BigInt(0),tt=BigInt(1),Ro=BigInt(2),ff=BigInt(8);function lf(r,t,e,n){let o=r.sqr(e),s=r.sqr(n),i=r.add(r.mul(t.a,o),s),a=r.add(r.ONE,r.mul(t.d,r.mul(o,s)));return r.eql(i,a)}function Qi(r,t={}){let e=Fr("edwards",r,t,t.FpFnLE),{Fp:n,Fn:o}=e,s=e.CURVE,{h:i}=s;Yt(t,{},{uvRatio:"function"});let a=Ro<<BigInt(o.BYTES*8)-tt,c=x=>n.create(x),u=t.uvRatio||((x,y)=>{try{return{isValid:!0,value:n.sqrt(n.div(x,y))}}catch{return{isValid:!1,value:jt}}});if(!lf(n,s,s.Gx,s.Gy))throw new Error("bad curve params: generator point");function l(x,y,A=!1){let w=A?tt:jt;return ir("coordinate "+x,y,w,a),y}function f(x){if(!(x instanceof h))throw new Error("EdwardsPoint expected")}let d=De((x,y)=>{let{X:A,Y:w,Z:I}=x,P=x.is0();y==null&&(y=P?ff:n.inv(I));let U=c(A*y),M=c(w*y),S=n.mul(I,y);if(P)return{x:jt,y:tt};if(S!==tt)throw new Error("invZ was invalid");return{x:U,y:M}}),p=De(x=>{let{a:y,d:A}=s;if(x.is0())throw new Error("bad point: ZERO");let{X:w,Y:I,Z:P,T:U}=x,M=c(w*w),S=c(I*I),E=c(P*P),O=c(E*E),K=c(M*y),R=c(E*c(K+S)),g=c(O+c(A*c(M*S)));if(R!==g)throw new Error("bad point: equation left != right (1)");let b=c(w*I),m=c(P*U);if(b!==m)throw new Error("bad point: equation left != right (2)");return!0});class h{static BASE=new h(s.Gx,s.Gy,tt,c(s.Gx*s.Gy));static ZERO=new h(jt,tt,tt,jt);static Fp=n;static Fn=o;X;Y;Z;T;constructor(y,A,w,I){this.X=l("x",y),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(y){if(y instanceof h)throw new Error("extended point not allowed");let{x:A,y:w}=y||{};return l("x",A),l("y",w),new h(A,w,tt,c(A*w))}static fromBytes(y,A=!1){let w=n.BYTES,{a:I,d:P}=s;y=qr(k(y,w,"point")),Kt(A,"zip215");let U=qr(y),M=y[w-1];U[w-1]=M&-129;let S=se(U),E=A?a:n.ORDER;ir("point.y",S,jt,E);let O=c(S*S),K=c(O-tt),R=c(P*O-I),{isValid:g,value:b}=u(K,R);if(!g)throw new Error("bad point: invalid y coordinate");let m=(b&tt)===tt,_=(M&128)!==0;if(!A&&b===jt&&_)throw new Error("bad point: x=0 and x_0=1");return _!==m&&(b=c(-b)),h.fromAffine({x:b,y:S})}static fromHex(y,A=!1){return h.fromBytes(Ut(y),A)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(y=8,A=!0){return v.createCache(this,y),A||this.multiply(Ro),this}assertValidity(){p(this)}equals(y){f(y);let{X:A,Y:w,Z:I}=this,{X:P,Y:U,Z:M}=y,S=c(A*M),E=c(P*I),O=c(w*M),K=c(U*I);return S===E&&O===K}is0(){return this.equals(h.ZERO)}negate(){return new h(c(-this.X),this.Y,this.Z,c(-this.T))}double(){let{a:y}=s,{X:A,Y:w,Z:I}=this,P=c(A*A),U=c(w*w),M=c(Ro*c(I*I)),S=c(y*P),E=A+w,O=c(c(E*E)-P-U),K=S+U,R=K-M,g=S-U,b=c(O*R),m=c(K*g),_=c(O*g),B=c(R*K);return new h(b,m,B,_)}add(y){f(y);let{a:A,d:w}=s,{X:I,Y:P,Z:U,T:M}=this,{X:S,Y:E,Z:O,T:K}=y,R=c(I*S),g=c(P*E),b=c(M*w*K),m=c(U*O),_=c((I+P)*(S+E)-R-g),B=m-b,L=m+b,T=c(g-A*R),D=c(_*B),C=c(L*T),N=c(_*T),$=c(B*L);return new h(D,C,$,N)}subtract(y){return this.add(y.negate())}multiply(y){if(!o.isValidNot0(y))throw new Error("invalid scalar: expected 1 <= sc < curve.n");let{p:A,f:w}=v.cached(this,y,I=>ce(h,I));return ce(h,[A,w])[0]}multiplyUnsafe(y,A=h.ZERO){if(!o.isValid(y))throw new Error("invalid scalar: expected 0 <= sc < curve.n");return y===jt?h.ZERO:this.is0()||y===tt?this:v.unsafe(this,y,w=>ce(h,w),A)}isSmallOrder(){return this.multiplyUnsafe(i).is0()}isTorsionFree(){return v.unsafe(this,s.n).is0()}toAffine(y){return d(this,y)}clearCofactor(){return i===tt?this:this.multiplyUnsafe(i)}toBytes(){let{x:y,y:A}=this.toAffine(),w=n.toBytes(A);return w[w.length-1]|=y&tt?128:0,w}toHex(){return kt(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let v=new Te(h,o.BITS);return h.BASE.precompute(8),h}function Ji(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,a=e.randomBytes||Ie,c=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(se(S))}function f(S){let E=w.secretKey;k(S,w.secretKey,"secretKey");let O=k(t(S),2*E,"hashedSecretKey"),K=c(O.slice(0,E)),R=O.slice(E,2*E),g=l(K);return{head:K,prefix:R,scalar:g}}function d(S){let{head:E,prefix:O,scalar:K}=f(S),R=o.multiply(K),g=R.toBytes();return{head:E,prefix:O,scalar:K,point:R,pointBytes:g}}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:R,pointBytes:g}=d(E),b=h(O.context,K,S),m=o.multiply(b).toBytes(),_=h(O.context,m,g,S),B=i.create(b+_*R);if(!i.isValid(B))throw new Error("sign failed: invalid s");let L=pt(m,i.toBytes(B));return k(L,w.signature,"result")}let x={zip215:!0};function y(S,E,O,K=x){let{context:R,zip215:g}=K,b=w.signature;S=k(S,b,"signature"),E=k(E,void 0,"message"),O=k(O,w.publicKey,"publicKey"),g!==void 0&&Kt(g,"zip215"),n&&(E=n(E));let m=b/2,_=S.subarray(0,m),B=se(S.subarray(m,b)),L,T,D;try{L=r.fromBytes(O,g),T=r.fromBytes(_,g),D=o.multiplyUnsafe(B)}catch{return!1}if(!g&&L.isSmallOrder())return!1;let C=h(R,T.toBytes(),L.toBytes(),E);return T.add(L.multiplyUnsafe(C)).subtract(D).clearCofactor().is0()}let A=s.BYTES,w={secretKey:A,publicKey:A,signature:2*A,seed:A};function I(S=a(w.seed)){return k(S,w.seed,"seed")}function P(S){return re(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 R=K?s.div(tt+E,tt-E):s.div(E-tt,E+tt);return s.toBytes(R)},toMontgomerySecret(S){let E=w.secretKey;k(S,E);let O=t(S.subarray(0,E));return c(O).subarray(0,E)}};return Object.freeze({keygen:zr(I,p),getPublicKey:p,sign:v,verify:y,utils:M,Point:r,lengths:w})}var df=BigInt(1),ta=BigInt(2);var hf=BigInt(5),pf=BigInt(8),To=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),mf={p:To,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:pf,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function gf(r){let t=BigInt(10),e=BigInt(20),n=BigInt(40),o=BigInt(80),s=To,a=r*r%s*r%s,c=V(a,ta,s)*a%s,u=V(c,df,s)*r%s,l=V(u,hf,s)*u%s,f=V(l,t,s)*l%s,d=V(f,e,s)*f%s,p=V(d,n,s)*d%s,h=V(p,o,s)*p%s,v=V(h,o,s)*p%s,x=V(v,t,s)*l%s;return{pow_p_5_8:V(x,ta,s)*r%s,b2:a}}function bf(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}var ea=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function yf(r,t){let e=To,n=j(t*t*t,e),o=j(n*n*t,e),s=gf(r*o).pow_p_5_8,i=j(r*n*s,e),a=j(t*i*i,e),c=i,u=j(i*ea,e),l=a===r,f=a===j(-r,e),d=a===j(-r*ea,e);return l&&(i=c),(f||d)&&(i=u),Hi(i,e)&&(i=j(-i,e)),{isValid:l||f,value:i}}var xf=Qi(mf,{uvRatio:yf});function wf(r){return Ji(xf,Ti,Object.assign({adjustScalarBytes:bf},r))}var ra=wf({});var fr=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},Vr=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var na={get(r=globalThis){let t=r.crypto;if(t?.subtle==null)throw new Vr("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 Hr=na;var $r=32;var Co,Ef=(async()=>{try{return await Hr.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function Sf(r,t,e){if(r.buffer instanceof ArrayBuffer){let n=await Hr.get().subtle.importKey("raw",r.buffer,{name:"Ed25519"},!1,["verify"]);return await Hr.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 vf(r,t,e){return ra.verify(t,e instanceof Uint8Array?e:e.subarray(),r)}async function oa(r,t,e){return Co==null&&(Co=await Ef),Co?Sf(r,t,e):vf(r,t,e)}function Gr(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}var Zr=class{type="Ed25519";raw;constructor(t){this.raw=Po(t,$r)}toMultihash(){return _t.digest(_e(this))}toCID(){return it.createV1(114,this.toMultihash())}toString(){return Y.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=oa(this.raw,e,t);return Gr(o)?o.then(s=>(n?.signal?.throwIfAborted(),s)):o}};function ia(r){return r=Po(r,$r),new Zr(r)}function Po(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 Af=Math.pow(2,7),If=Math.pow(2,14),Bf=Math.pow(2,21),Oo=Math.pow(2,28),No=Math.pow(2,35),ko=Math.pow(2,42),Uo=Math.pow(2,49),F=128,at=127;function mt(r){if(r<Af)return 1;if(r<If)return 2;if(r<Bf)return 3;if(r<Oo)return 4;if(r<No)return 5;if(r<ko)return 6;if(r<Uo)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Ce(r,t,e=0){switch(mt(r)){case 8:t[e++]=r&255|F,r/=128;case 7:t[e++]=r&255|F,r/=128;case 6:t[e++]=r&255|F,r/=128;case 5:t[e++]=r&255|F,r/=128;case 4:t[e++]=r&255|F,r>>>=7;case 3:t[e++]=r&255|F,r>>>=7;case 2:t[e++]=r&255|F,r>>>=7;case 1:{t[e++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return t}function Df(r,t,e=0){switch(mt(r)){case 8:t.set(e++,r&255|F),r/=128;case 7:t.set(e++,r&255|F),r/=128;case 6:t.set(e++,r&255|F),r/=128;case 5:t.set(e++,r&255|F),r/=128;case 4:t.set(e++,r&255|F),r>>>=7;case 3:t.set(e++,r&255|F),r>>>=7;case 2:t.set(e++,r&255|F),r>>>=7;case 1:{t.set(e++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return t}function Mo(r,t){let e=r[t],n=0;if(n+=e&at,e<F||(e=r[t+1],n+=(e&at)<<7,e<F)||(e=r[t+2],n+=(e&at)<<14,e<F)||(e=r[t+3],n+=(e&at)<<21,e<F)||(e=r[t+4],n+=(e&at)*Oo,e<F)||(e=r[t+5],n+=(e&at)*No,e<F)||(e=r[t+6],n+=(e&at)*ko,e<F)||(e=r[t+7],n+=(e&at)*Uo,e<F))return n;throw new RangeError("Could not decode varint")}function Lf(r,t){let e=r.get(t),n=0;if(n+=e&at,e<F||(e=r.get(t+1),n+=(e&at)<<7,e<F)||(e=r.get(t+2),n+=(e&at)<<14,e<F)||(e=r.get(t+3),n+=(e&at)<<21,e<F)||(e=r.get(t+4),n+=(e&at)*Oo,e<F)||(e=r.get(t+5),n+=(e&at)*No,e<F)||(e=r.get(t+6),n+=(e&at)*ko,e<F)||(e=r.get(t+7),n+=(e&at)*Uo,e<F))return n;throw new RangeError("Could not decode varint")}function aa(r,t,e=0){return t==null&&(t=ht(mt(r))),t instanceof Uint8Array?Ce(r,t,e):Df(r,t,e)}function lr(r,t=0){return r instanceof Uint8Array?Mo(r,t):Lf(r,t)}var Ko=new Float32Array([-0]),Wt=new Uint8Array(Ko.buffer);function ua(r,t,e){Ko[0]=r,t[e]=Wt[0],t[e+1]=Wt[1],t[e+2]=Wt[2],t[e+3]=Wt[3]}function fa(r,t){return Wt[0]=r[t],Wt[1]=r[t+1],Wt[2]=r[t+2],Wt[3]=r[t+3],Ko[0]}var qo=new Float64Array([-0]),ct=new Uint8Array(qo.buffer);function la(r,t,e){qo[0]=r,t[e]=ct[0],t[e+1]=ct[1],t[e+2]=ct[2],t[e+3]=ct[3],t[e+4]=ct[4],t[e+5]=ct[5],t[e+6]=ct[6],t[e+7]=ct[7]}function da(r,t){return ct[0]=r[t],ct[1]=r[t+1],ct[2]=r[t+2],ct[3]=r[t+3],ct[4]=r[t+4],ct[5]=r[t+5],ct[6]=r[t+6],ct[7]=r[t+7],qo[0]}var Rf=BigInt(Number.MAX_SAFE_INTEGER),Tf=BigInt(Number.MIN_SAFE_INTEGER),yt=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 ue;if(t<Rf&&t>Tf)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>ha&&(o=0n,++n>ha&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(t){if(t===0)return ue;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):ue}},ue=new yt(0,0);ue.toBigInt=function(){return 0n};ue.zzEncode=ue.zzDecode=function(){return this};ue.length=function(){return 1};var ha=4294967296n;function pa(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 ma(r,t,e){if(e-t<1)return"";let o,s=[],i=0,a;for(;t<e;)a=r[t++],a<128?s[i++]=a:a>191&&a<224?s[i++]=(a&31)<<6|r[t++]&63:a>239&&a<365?(a=((a&7)<<18|(r[t++]&63)<<12|(r[t++]&63)<<6|r[t++]&63)-65536,s[i++]=55296+(a>>10),s[i++]=56320+(a&1023)):s[i++]=(a&15)<<12|(r[t++]&63)<<6|r[t++]&63,i>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,s)),i=0);return o!=null?(i>0&&o.push(String.fromCharCode.apply(String,s.slice(0,i))),o.join("")):String.fromCharCode.apply(String,s.slice(0,i))}function Fo(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 It(r,t){return RangeError(`index out of range: ${r.pos} + ${t??1} > ${r.len}`)}function Xr(r,t){return(r[t-4]|r[t-3]<<8|r[t-2]<<16|r[t-1]<<24)>>>0}var zo=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,It(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 It(this,4);return Xr(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw It(this,4);return Xr(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw It(this,4);let t=fa(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw It(this,4);let t=da(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 It(this,t);return this.pos+=t,e===n?new Uint8Array(0):this.buf.subarray(e,n)}string(){let t=this.bytes();return ma(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw It(this,t);this.pos+=t}else do if(this.pos>=this.len)throw It(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 yt(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 It(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 It(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 It(this,8);let t=Xr(this.buf,this.pos+=4),e=Xr(this.buf,this.pos+=4);return new yt(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=Mo(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 Vo(r){return new zo(r instanceof Uint8Array?r:r.subarray())}function Et(r,t,e){let n=Vo(r);return t.decode(n,void 0,e)}function Ho(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 a=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),a}}var fe=class{fn;len;next;val;constructor(t,e,n){this.fn=t,this.len=e,this.next=void 0,this.val=n}};function $o(){}var Zo=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},Cf=Ho();function Pf(r){return globalThis.Buffer!=null?ht(r):Cf(r)}var hr=class{len;head;tail;states;constructor(){this.len=0,this.head=new fe($o,0,0),this.tail=this.head,this.states=null}_push(t,e,n){return this.tail=this.tail.next=new fe(t,e,n),this.len+=e,this}uint32(t){return this.len+=(this.tail=this.tail.next=new Xo((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(Yr,10,yt.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let e=yt.fromBigInt(t);return this._push(Yr,e.length(),e)}uint64Number(t){return this._push(Ce,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=yt.fromBigInt(t).zzEncode();return this._push(Yr,e.length(),e)}sint64Number(t){let e=yt.fromNumber(t).zzEncode();return this._push(Yr,e.length(),e)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(Go,1,t?1:0)}fixed32(t){return this._push(dr,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=yt.fromBigInt(t);return this._push(dr,4,e.lo)._push(dr,4,e.hi)}fixed64Number(t){let e=yt.fromNumber(t);return this._push(dr,4,e.lo)._push(dr,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(ua,4,t)}double(t){return this._push(la,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(Go,1,0):this.uint32(e)._push(Nf,e,t)}string(t){let e=pa(t);return e!==0?this.uint32(e)._push(Fo,e,t):this._push(Go,1,0)}fork(){return this.states=new Zo(this),this.head=this.tail=new fe($o,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 fe($o,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=Pf(this.len),n=0;for(;t!=null;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e}};function Go(r,t,e){t[e]=r&255}function Of(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var Xo=class extends fe{next;constructor(t,e){super(Of,t,e),this.next=void 0}};function Yr(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 dr(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 Nf(r,t,e){t.set(r,e)}globalThis.Buffer!=null&&(hr.prototype.bytes=function(r){let t=r.length>>>0;return this.uint32(t),t>0&&this._push(kf,t,r),this},hr.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(Uf,t,r),this});function kf(r,t,e){t.set(r,e)}function Uf(r,t,e){r.length<40?Fo(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set(H(r),e)}function Yo(){return new hr}function St(r,t){let e=Yo();return t.encode(r,e,{lengthDelimited:!1}),e.finish()}var Pe;(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"})(Pe||(Pe={}));function jr(r,t,e,n){return{name:r,type:t,encode:e,decode:n}}function le(r){function t(o){if(r[o.toString()]==null)throw new Error("Invalid enum value");return r[o]}let e=function(s,i){let a=t(s);i.int32(a)},n=function(s){let i=s.int32();return t(i)};return jr("enum",Pe.VARINT,e,n)}function vt(r,t){return jr("message",Pe.LENGTH_DELIMITED,r,t)}var Wr=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var xt;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.secp256k1="secp256k1",r.ECDSA="ECDSA"})(xt||(xt={}));var jo;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.secp256k1=2]="secp256k1",r[r.ECDSA=3]="ECDSA"})(jo||(jo={}));(function(r){r.codec=()=>le(jo)})(xt||(xt={}));var pr;(function(r){let t;r.codec=()=>(t==null&&(t=vt((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),xt.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 a=e.uint32();switch(a>>>3){case 1:{s.Type=xt.codec().decode(e);break}case 2:{s.Data=e.bytes();break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>St(e,r.codec()),r.decode=(e,n)=>Et(e,r.codec(),n)})(pr||(pr={}));var Wo;(function(r){let t;r.codec=()=>(t==null&&(t=vt((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),xt.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 a=e.uint32();switch(a>>>3){case 1:{s.Type=xt.codec().decode(e);break}case 2:{s.Data=e.bytes();break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>St(e,r.codec()),r.decode=(e,n)=>Et(e,r.codec(),n)})(Wo||(Wo={}));var Qr=class{oHash;iHash;blockLen;outputLen;finished=!1;destroyed=!1;constructor(t,e){if(Nr(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),Nt(o)}update(t){return Ae(this),this.iHash.update(t),this}digestInto(t){Ae(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:a}=this;return t=t,t.finished=o,t.destroyed=s,t.blockLen=i,t.outputLen=a,t.oHash=e._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},Qo=(r,t,e)=>new Qr(r,t).update(e).digest();Qo.create=(r,t)=>new Qr(r,t);var ba=(r,t)=>(r+(r>=0?t:-t)/ya)/t;function Kf(r,t,e){let[[n,o],[s,i]]=t,a=ba(i*r,e),c=ba(-o*r,e),u=r-a*n-c*s,l=-a*o-c*i,f=u<qt,d=l<qt;f&&(u=-u),d&&(l=-l);let p=ar(Math.ceil(Eo(e)/2))+Oe;if(u<qt||u>=p||l<qt||l>=p)throw new Error("splitScalar (endomorphism): failed, k="+r);return{k1neg:f,k1:u,k2neg:d,k2:l}}function ts(r){if(!["compact","recovered","der"].includes(r))throw new Error('Signature format must be "compact", "recovered", or "der"');return r}function Jo(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&&ts(e.format),e}var es=class extends Error{constructor(t=""){super(t)}},Qt={Err:es,_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=sr(n);if(o.length/2&128)throw new e("tlv.encode: long form length too big");let s=n>127?sr(o.length/2|128):"";return sr(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 c=o&127;if(!c)throw new e("tlv.decode(long): indefinite length not supported");if(c>4)throw new e("tlv.decode(long): byte length is too big");let u=t.subarray(n,n+c);if(u.length!==c)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+=c,i<128)throw new e("tlv.decode(long): not minimal encoding")}let a=t.subarray(n,n+i);if(a.length!==i)throw new e("tlv.decode: wrong value length");return{v:a,l:t.subarray(n+i)}}},_int:{encode(r){let{Err:t}=Qt;if(r<qt)throw new t("integer: negative integers are not allowed");let e=sr(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 Be(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:a,l:c}=n.decode(2,s),{v:u,l}=n.decode(2,c);if(l.length)throw new t("invalid signature: left bytes after parsing");return{r:e.decode(a),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)}},qt=BigInt(0),Oe=BigInt(1),ya=BigInt(2),Jr=BigInt(3),qf=BigInt(4);function xa(r,t={}){let e=Fr("weierstrass",r,t),{Fp:n,Fn:o}=e,s=e.CURVE,{h:i,n:a}=s;Yt(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object"});let{endo:c}=t;if(c&&(!n.is0(s.a)||typeof c.beta!="bigint"||!Array.isArray(c.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let u=Ea(n,o);function l(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function f(R,g,b){let{x:m,y:_}=g.toAffine(),B=n.toBytes(m);if(Kt(b,"isCompressed"),b){l();let L=!n.isOdd(_);return pt(wa(L),B)}else return pt(Uint8Array.of(4),B,n.toBytes(_))}function d(R){k(R,void 0,"Point");let{publicKey:g,publicKeyUncompressed:b}=u,m=R.length,_=R[0],B=R.subarray(1);if(m===g&&(_===2||_===3)){let L=n.fromBytes(B);if(!n.isValid(L))throw new Error("bad point: is not on curve, wrong x");let T=v(L),D;try{D=n.sqrt(T)}catch($){let z=$ instanceof Error?": "+$.message:"";throw new Error("bad point: is not on curve, sqrt error"+z)}l();let C=n.isOdd(D);return(_&1)===1!==C&&(D=n.neg(D)),{x:L,y:D}}else if(m===b&&_===4){let L=n.BYTES,T=n.fromBytes(B.subarray(0,L)),D=n.fromBytes(B.subarray(L,L*2));if(!x(T,D))throw new Error("bad point: is not on curve");return{x:T,y:D}}else throw new Error(`bad point: got length ${m}, expected compressed=${g} or uncompressed=${b}`)}let p=t.toBytes||f,h=t.fromBytes||d;function v(R){let g=n.sqr(R),b=n.mul(g,R);return n.add(n.add(b,n.mul(R,s.a)),s.b)}function x(R,g){let b=n.sqr(g),m=v(R);return n.eql(b,m)}if(!x(s.Gx,s.Gy))throw new Error("bad curve params: generator point");let y=n.mul(n.pow(s.a,Jr),qf),A=n.mul(n.sqr(s.b),BigInt(27));if(n.is0(n.add(y,A)))throw new Error("bad curve params: a or b");function w(R,g,b=!1){if(!n.isValid(g)||b&&n.is0(g))throw new Error(`bad point coordinate ${R}`);return g}function I(R){if(!(R instanceof E))throw new Error("Weierstrass Point expected")}function P(R){if(!c||!c.basises)throw new Error("no endo");return Kf(R,c.basises,o.ORDER)}let U=De((R,g)=>{let{X:b,Y:m,Z:_}=R;if(n.eql(_,n.ONE))return{x:b,y:m};let B=R.is0();g==null&&(g=B?n.ONE:n.inv(_));let L=n.mul(b,g),T=n.mul(m,g),D=n.mul(_,g);if(B)return{x:n.ZERO,y:n.ZERO};if(!n.eql(D,n.ONE))throw new Error("invZ was invalid");return{x:L,y:T}}),M=De(R=>{if(R.is0()){if(t.allowInfinityPoint&&!n.is0(R.Y))return;throw new Error("bad point: ZERO")}let{x:g,y:b}=R.toAffine();if(!n.isValid(g)||!n.isValid(b))throw new Error("bad point: x or y not field elements");if(!x(g,b))throw new Error("bad point: equation left != right");if(!R.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function S(R,g,b,m,_){return b=new E(n.mul(b.X,R),b.Y,b.Z),g=ur(m,g),b=ur(_,b),g.add(b)}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(g,b,m){this.X=w("x",g),this.Y=w("y",b,!0),this.Z=w("z",m),Object.freeze(this)}static CURVE(){return s}static fromAffine(g){let{x:b,y:m}=g||{};if(!g||!n.isValid(b)||!n.isValid(m))throw new Error("invalid affine point");if(g instanceof E)throw new Error("projective point not allowed");return n.is0(b)&&n.is0(m)?E.ZERO:new E(b,m,n.ONE)}static fromBytes(g){let b=E.fromAffine(h(k(g,void 0,"point")));return b.assertValidity(),b}static fromHex(g){return E.fromBytes(Ut(g))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(g=8,b=!0){return K.createCache(this,g),b||this.multiply(Jr),this}assertValidity(){M(this)}hasEvenY(){let{y:g}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(g)}equals(g){I(g);let{X:b,Y:m,Z:_}=this,{X:B,Y:L,Z:T}=g,D=n.eql(n.mul(b,T),n.mul(B,_)),C=n.eql(n.mul(m,T),n.mul(L,_));return D&&C}negate(){return new E(this.X,n.neg(this.Y),this.Z)}double(){let{a:g,b}=s,m=n.mul(b,Jr),{X:_,Y:B,Z:L}=this,T=n.ZERO,D=n.ZERO,C=n.ZERO,N=n.mul(_,_),$=n.mul(B,B),z=n.mul(L,L),q=n.mul(_,B);return q=n.add(q,q),C=n.mul(_,L),C=n.add(C,C),T=n.mul(g,C),D=n.mul(m,z),D=n.add(T,D),T=n.sub($,D),D=n.add($,D),D=n.mul(T,D),T=n.mul(q,T),C=n.mul(m,C),z=n.mul(g,z),q=n.sub(N,z),q=n.mul(g,q),q=n.add(q,C),C=n.add(N,N),N=n.add(C,N),N=n.add(N,z),N=n.mul(N,q),D=n.add(D,N),z=n.mul(B,L),z=n.add(z,z),N=n.mul(z,q),T=n.sub(T,N),C=n.mul(z,$),C=n.add(C,C),C=n.add(C,C),new E(T,D,C)}add(g){I(g);let{X:b,Y:m,Z:_}=this,{X:B,Y:L,Z:T}=g,D=n.ZERO,C=n.ZERO,N=n.ZERO,$=s.a,z=n.mul(s.b,Jr),q=n.mul(b,B),G=n.mul(m,L),rt=n.mul(_,T),Dt=n.add(b,m),Z=n.add(B,L);Dt=n.mul(Dt,Z),Z=n.add(q,G),Dt=n.sub(Dt,Z),Z=n.add(b,_);let st=n.add(B,T);return Z=n.mul(Z,st),st=n.add(q,rt),Z=n.sub(Z,st),st=n.add(m,_),D=n.add(L,T),st=n.mul(st,D),D=n.add(G,rt),st=n.sub(st,D),N=n.mul($,Z),D=n.mul(z,rt),N=n.add(D,N),D=n.sub(G,N),N=n.add(G,N),C=n.mul(D,N),G=n.add(q,q),G=n.add(G,q),rt=n.mul($,rt),Z=n.mul(z,Z),G=n.add(G,rt),rt=n.sub(q,rt),rt=n.mul($,rt),Z=n.add(Z,rt),q=n.mul(G,Z),C=n.add(C,q),q=n.mul(st,Z),D=n.mul(Dt,D),D=n.sub(D,q),q=n.mul(Dt,G),N=n.mul(st,N),N=n.add(N,q),new E(D,C,N)}subtract(g){return this.add(g.negate())}is0(){return this.equals(E.ZERO)}multiply(g){let{endo:b}=t;if(!o.isValidNot0(g))throw new Error("invalid scalar: out of range");let m,_,B=L=>K.cached(this,L,T=>ce(E,T));if(b){let{k1neg:L,k1:T,k2neg:D,k2:C}=P(g),{p:N,f:$}=B(T),{p:z,f:q}=B(C);_=$.add(q),m=S(b.beta,N,z,L,D)}else{let{p:L,f:T}=B(g);m=L,_=T}return ce(E,[m,_])[0]}multiplyUnsafe(g){let{endo:b}=t,m=this;if(!o.isValid(g))throw new Error("invalid scalar: out of range");if(g===qt||m.is0())return E.ZERO;if(g===Oe)return m;if(K.hasCache(this))return this.multiply(g);if(b){let{k1neg:_,k1:B,k2neg:L,k2:T}=P(g),{p1:D,p2:C}=Wi(E,m,B,T);return S(b.beta,D,C,_,L)}else return K.unsafe(m,g)}toAffine(g){return U(this,g)}isTorsionFree(){let{isTorsionFree:g}=t;return i===Oe?!0:g?g(E,this):K.unsafe(this,a).is0()}clearCofactor(){let{clearCofactor:g}=t;return i===Oe?this:g?g(E,this):this.multiplyUnsafe(i)}isSmallOrder(){return this.multiplyUnsafe(i).is0()}toBytes(g=!0){return Kt(g,"isCompressed"),this.assertValidity(),p(E,this,g)}toHex(g=!0){return kt(this.toBytes(g))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let O=o.BITS,K=new Te(E,t.endo?Math.ceil(O/2):O);return E.BASE.precompute(8),E}function wa(r){return Uint8Array.of(r?2:3)}function Ea(r,t){return{secretKey:t.BYTES,publicKey:1+r.BYTES,publicKeyUncompressed:1+2*r.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function Ff(r,t={}){let{Fn:e}=r,n=t.randomBytes||Ie,o=Object.assign(Ea(r.Fp,e),{seed:Ao(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:x}=o;try{let y=p.length;return h===!0&&y!==v||h===!1&&y!==x?!1:!!r.fromBytes(p)}catch{return!1}}function a(p=n(o.seed)){return Io(k(p,o.seed,"seed"),e.ORDER)}function c(p,h=!0){return r.BASE.multiply(e.fromBytes(p)).toBytes(h)}function u(p){let{secretKey:h,publicKey:v,publicKeyUncompressed:x}=o;if(!re(p)||"_lengths"in e&&e._lengths||h===v)return;let y=k(p,void 0,"key").length;return y===v||y===x}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 x=e.fromBytes(p);return r.fromBytes(h).multiply(x).toBytes(v)}let f={isValidSecretKey:s,isValidPublicKey:i,randomSecretKey:a},d=zr(a,c);return Object.freeze({getPublicKey:c,getSharedSecret:l,keygen:d,Point:r,utils:f,lengths:o})}function Sa(r,t,e={}){Nr(t),Yt(e,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"}),e=Object.assign({},e);let n=e.randomBytes||Ie,o=e.hmac||((b,m)=>Qo(t,b,m)),{Fp:s,Fn:i}=r,{ORDER:a,BITS:c}=i,{keygen:u,getPublicKey:l,getSharedSecret:f,utils:d,lengths:p}=Ff(r,e),h={prehash:!0,lowS:typeof e.lowS=="boolean"?e.lowS:!0,format:"compact",extraEntropy:!1},v=a*ya<s.ORDER;function x(b){let m=a>>Oe;return b>m}function y(b,m){if(!i.isValidNot0(m))throw new Error(`invalid signature ${b}: 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(b,m){ts(m);let _=p.signature,B=m==="compact"?_:m==="recovered"?_+1:void 0;return k(b,B)}class I{r;s;recovery;constructor(m,_,B){if(this.r=y("r",m),this.s=y("s",_),B!=null){if(A(),![0,1,2,3].includes(B))throw new Error("invalid recovery id");this.recovery=B}Object.freeze(this)}static fromBytes(m,_=h.format){w(m,_);let B;if(_==="der"){let{r:C,s:N}=Qt.toSig(k(m));return new I(C,N)}_==="recovered"&&(B=m[0],_="compact",m=m.subarray(1));let L=p.signature/2,T=m.subarray(0,L),D=m.subarray(L,L*2);return new I(i.fromBytes(T),i.fromBytes(D),B)}static fromHex(m,_){return this.fromBytes(Ut(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:B}=this,L=this.assertRecovery(),T=L===2||L===3?_+a:_;if(!s.isValid(T))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let D=s.toBytes(T),C=r.fromBytes(pt(wa((L&1)===0),D)),N=i.inv(T),$=U(k(m,void 0,"msgHash")),z=i.create(-$*N),q=i.create(B*N),G=r.BASE.multiplyUnsafe(z).add(C.multiplyUnsafe(q));if(G.is0())throw new Error("invalid recovery: point at infinify");return G.assertValidity(),G}hasHighS(){return x(this.s)}toBytes(m=h.format){if(ts(m),m==="der")return Ut(Qt.hexFromSig(this));let{r:_,s:B}=this,L=i.toBytes(_),T=i.toBytes(B);return m==="recovered"?(A(),pt(Uint8Array.of(this.assertRecovery()),L,T)):pt(L,T)}toHex(m){return kt(this.toBytes(m))}}let P=e.bits2int||function(m){if(m.length>8192)throw new Error("input is too large");let _=Be(m),B=m.length*8-c;return B>0?_>>BigInt(B):_},U=e.bits2int_modN||function(m){return i.create(P(m))},M=ar(c);function S(b){return ir("num < 2^"+c,b,qt,M),i.toBytes(b)}function E(b,m){return k(b,void 0,"message"),m?k(t(b),void 0,"prehashed message"):b}function O(b,m,_){let{lowS:B,prehash:L,extraEntropy:T}=Jo(_,h);b=E(b,L);let D=U(b),C=i.fromBytes(m);if(!i.isValidNot0(C))throw new Error("invalid private key");let N=[S(C),S(D)];if(T!=null&&T!==!1){let G=T===!0?n(p.secretKey):T;N.push(k(G,void 0,"extraEntropy"))}let $=pt(...N),z=D;function q(G){let rt=P(G);if(!i.isValidNot0(rt))return;let Dt=i.inv(rt),Z=r.BASE.multiply(rt).toAffine(),st=i.create(Z.x);if(st===qt)return;let _r=i.create(Dt*i.create(z+st*C));if(_r===qt)return;let Os=(Z.x===st?0:2)|Number(Z.y&Oe),Ns=_r;return B&&x(_r)&&(Ns=i.neg(_r),Os^=1),new I(st,Ns,v?void 0:Os)}return{seed:$,k2sig:q}}function K(b,m,_={}){let{seed:B,k2sig:L}=O(b,m,_);return Oi(t.outputLen,i.BYTES,o)(B,L).toBytes(_.format)}function R(b,m,_,B={}){let{lowS:L,prehash:T,format:D}=Jo(B,h);if(_=k(_,void 0,"publicKey"),m=E(m,T),!re(b)){let C=b instanceof I?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+C)}w(b,D);try{let C=I.fromBytes(b,D),N=r.fromBytes(_);if(L&&C.hasHighS())return!1;let{r:$,s:z}=C,q=U(m),G=i.inv(z),rt=i.create(q*G),Dt=i.create($*G),Z=r.BASE.multiplyUnsafe(rt).add(N.multiplyUnsafe(Dt));return Z.is0()?!1:i.create(Z.x)===$}catch{return!1}}function g(b,m,_={}){let{prehash:B}=Jo(_,h);return m=E(m,B),I.fromBytes(b,"recovered").recoverPublicKey(m).toBytes()}return Object.freeze({keygen:u,getPublicKey:l,getSharedSecret:f,utils:d,lengths:p,Point:r,sign:K,verify:R,recoverPublicKey:g,Signature:I,hash:t})}var ns={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},zf={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var va=BigInt(2);function Vf(r){let t=ns.p,e=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),a=BigInt(44),c=BigInt(88),u=r*r*r%t,l=u*u*r%t,f=V(l,e,t)*l%t,d=V(f,e,t)*l%t,p=V(d,va,t)*u%t,h=V(p,o,t)*p%t,v=V(h,s,t)*h%t,x=V(v,a,t)*v%t,y=V(x,c,t)*x%t,A=V(y,a,t)*v%t,w=V(A,e,t)*l%t,I=V(w,i,t)*h%t,P=V(I,n,t)*u%t,U=V(P,va,t);if(!rs.eql(rs.sqr(U),r))throw new Error("Cannot find square root");return U}var rs=Le(ns.p,{sqrt:Vf}),Hf=xa(ns,{Fp:rs,endo:zf}),Ne=Sa(Hf,Ri);function _a(r,t,e,n){let o=Qe.digest(e instanceof Uint8Array?e:e.subarray());if(Gr(o))return o.then(({digest:s})=>(n?.signal?.throwIfAborted(),Ne.verify(t,s,r,{prehash:!1,format:"der"}))).catch(s=>{throw s.name==="AbortError"?s:new fr(String(s))});try{return n?.signal?.throwIfAborted(),Ne.verify(t,o.digest,r,{prehash:!1,format:"der"})}catch(s){throw new fr(String(s))}}var tn=class{type="secp256k1";raw;_key;constructor(t){this._key=Ia(t),this.raw=Aa(this._key)}toMultihash(){return _t.digest(_e(this))}toCID(){return it.createV1(114,this.toMultihash())}toString(){return Y.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 _a(this._key,e,t,n)}};function Ba(r){return new tn(r)}function Aa(r){return Ne.Point.fromBytes(r).toBytes()}function Ia(r){try{return Ne.Point.fromBytes(r),r}catch(t){throw new Ir(String(t))}}function Da(r){let{Type:t,Data:e}=pr.decode(r.digest),n=e??new Uint8Array;switch(t){case xt.Ed25519:return ia(n);case xt.secp256k1:return Ba(n);case xt.ECDSA:return hi(n);default:throw new Ge}}function _e(r){return pr.encode({Type:xt[r.type],Data:r.raw})}var La=Symbol.for("nodejs.util.inspect.custom"),$f=114,mr=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()})`}[On]=!0;toString(){return this.string==null&&(this.string=Y.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return it.createV1($f,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")}[La](){return`PeerId(${this.toString()})`}},en=class extends mr{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},rn=class extends mr{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},nn=class extends mr{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},Gf=2336,on=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=_t.digest(H(this.url))}[La](){return`PeerId(${this.url})`}[On]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return it.createV1(Gf,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=W(t)),t.toString()===this.toString())}};function Ra(r){if(Xf(r))return new en({multihash:r});if(Zf(r))try{let t=Da(r);if(t.type==="Ed25519")return new rn({multihash:r,publicKey:t});if(t.type==="secp256k1")return new nn({multihash:r,publicKey:t})}catch{let e=W(r.digest);return new on(new URL(e))}throw new Br("Supplied PeerID Multihash is invalid")}function Zf(r){return r.code===_t.code}function Xf(r){return r.code===Qe.code}function os(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 sn(r){let t=je(Y.decode(`z${r}`));return Ra(t)}var an=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 os(this.set.entries(),t=>{let e=sn(t[0]);return[e,e]})}forEach(t){this.set.forEach(e=>{let n=sn(e);t(n,n,this)})}has(t){return this.set.has(t.toString())}values(){return os(this.set.values(),t=>sn(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 ss(){return new an}var is={32:16777619n,64:1099511628211n,128:309485009821345068724781371n,256:374144419156711147060143317175368453031918731002211n,512:35835915874844867368919076489095108449946327955754392558399825615420669938882575126094039892345713852759n,1024:5016456510113118655434598811035278955030765345404790744303017523831112055108147451509157692220295382716162651878526895249385292291816524375083746691371804094271873160484737966720260389217684476157468082573n},Ta={32:2166136261n,64:14695981039346656037n,128:144066263297769815596495629667062367629n,256:100029257958052580907070968620625704837092796014241193945225284501741471925557n,512:9659303129496669498009435400716310466090418745672637896108374329434462657994582932197716438449813051892206539805784495328239340083876191928701583869517785n,1024:14197795064947621068722070641403218320880622795441933960878474914617582723252296732303717722150864096521202355549365628174669108571814760471015076148029755969804077320157692458563003215304957150157403644460363550505412711285966361610267868082893823963790439336411086884584107735010676915n},Ca=new globalThis.TextEncoder;function Yf(r,t){let e=is[t],n=Ta[t];for(let o=0;o<r.length;o++)n^=BigInt(r[o]),n=BigInt.asUintN(t,n*e);return n}function jf(r,t,e){if(e.length===0)throw new Error("The `utf8Buffer` option must have a length greater than zero");let n=is[t],o=Ta[t],s=r;for(;s.length>0;){let i=Ca.encodeInto(s,e);s=s.slice(i.read);for(let a=0;a<i.written;a++)o^=BigInt(e[a]),o=BigInt.asUintN(t,o*n)}return o}function as(r,{size:t=32,utf8Buffer:e}={}){if(!is[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 jf(r,t,e);r=Ca.encode(r)}return Yf(r,t)}var gr={hash:r=>Number(as(r,{size:32})),hashV:(r,t)=>Wf(gr.hash(r,t))};function Wf(r){let t=r.toString(16);return t.length%2===1&&(t=`0${t}`),H(t,"base16")}var cs=64,Bt=class{fp;h;seed;constructor(t,e,n,o=2){if(o>cs)throw new TypeError("Invalid Fingerprint Size");let s=e.hashV(t,n),i=bt(o);for(let a=0;a<i.length;a++)i[a]=s[a];i.length===0&&(i[0]=7),this.fp=i,this.h=e,this.seed=n}hash(){return this.h.hash(this.fp,this.seed)}equals(t){return t?.fp instanceof Uint8Array?lt(this.fp,t.fp):!1}};function de(r,t){return Math.floor(Math.random()*(t-r))+r}var he=class{contents;constructor(t){this.contents=new Array(t).fill(null)}has(t){if(!(t instanceof Bt))throw new TypeError("Invalid Fingerprint");return this.contents.some(e=>t.equals(e))}add(t){if(!(t instanceof Bt))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 Bt))throw new TypeError("Invalid Fingerprint");let e=de(0,this.contents.length-1),n=this.contents[e];return this.contents[e]=t,n}remove(t){if(!(t instanceof Bt))throw new TypeError("Invalid Fingerprint");let e=this.contents.findIndex(n=>t.equals(n));return e>-1?(this.contents[e]=null,!0):!1}};var Qf=500,br=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??gr,this.seed=t.seed??de(0,Math.pow(2,10))}add(t){typeof t=="string"&&(t=H(t));let e=new Bt(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 he(this.bucketSize)),this.buckets[o]==null&&(this.buckets[o]=new he(this.bucketSize)),this.buckets[n].add(e)||this.buckets[o].add(e))return this.count++,!0;let s=[n,o],i=s[de(0,s.length-1)];this.buckets[i]==null&&(this.buckets[i]=new he(this.bucketSize));for(let a=0;a<Qf;a++){let c=this.buckets[i].swap(e);if(c!=null&&(i=(i^c.hash())%this.filterSize,this.buckets[i]==null&&(this.buckets[i]=new he(this.bucketSize)),this.buckets[i].add(c)))return this.count++,!0}return!1}has(t){typeof t=="string"&&(t=H(t));let e=new Bt(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=H(t));let e=new Bt(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}},Jf={1:.5,2:.84,4:.95,8:.98};function tl(r=.001){return r>.002?2:r>1e-5?4:8}function Pa(r,t=.001){let e=tl(t),n=Jf[e],o=Math.round(r/n),s=Math.min(Math.ceil(Math.log2(1/t)+Math.log2(2*e)),cs);return{filterSize:o,bucketSize:e,fingerprintSize:s}}var cn=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??gr,this.seed=t.seed??de(0,Math.pow(2,10)),this.filterSeries=[new br({filterSize:this.filterSize,bucketSize:this.bucketSize,fingerprintSize:this.fingerprintSize,hash:this.hash,seed:this.seed})]}add(t){if(typeof t=="string"&&(t=H(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 br({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=H(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=H(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 us(r,t=.001,e){return new cn({...Pa(r,t),...e??{}})}function Jt(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 un=class{index=0;input="";new(t){return this.index=0,this.input=t,this}readAtomically(t){let e=this.index,n=t();return n===void 0&&(this.index=e),n}parseWith(t){let e=t();if(this.index===this.input.length)return e}peekChar(){if(!(this.index>=this.input.length))return this.input[this.index]}readChar(){if(!(this.index>=this.input.length))return this.input[this.index++]}readGivenChar(t){return this.readAtomically(()=>{let e=this.readChar();if(e===t)return e})}readSeparator(t,e,n){return this.readAtomically(()=>{if(!(e>0&&this.readGivenChar(t)===void 0))return n()})}readNumber(t,e,n,o){return this.readAtomically(()=>{let s=0,i=0,a=this.peekChar();if(a===void 0)return;let c=a==="0",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&&c&&i>1?void 0:s})}readIPv4Addr(){return this.readAtomically(()=>{let t=new Uint8Array(4);for(let e=0;e<t.length;e++){let n=this.readSeparator(".",e,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;t[e]=n}return t})}readIPv6Addr(){let t=e=>{for(let n=0;n<e.length/2;n++){let o=n*2;if(n<e.length-3){let i=this.readSeparator(":",n,()=>this.readIPv4Addr());if(i!==void 0)return e[o]=i[0],e[o+1]=i[1],e[o+2]=i[2],e[o+3]=i[3],[o+4,!0]}let s=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(s===void 0)return[o,!1];e[o]=s>>8,e[o+1]=s&255}return[e.length,!1]};return this.readAtomically(()=>{let e=new Uint8Array(16),[n,o]=t(e);if(n===16)return e;if(o||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let s=new Uint8Array(14),i=16-(n+2),[a]=t(s.subarray(0,i));return e.set(s.subarray(0,a),16-a),e})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var Oa=45,el=15,ke=new un;function fn(r){if(!(r.length>el))return ke.new(r).parseWith(()=>ke.readIPv4Addr())}function ln(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>Oa))return ke.new(r).parseWith(()=>ke.readIPv6Addr())}function Ue(r,t=!1){if(r.includes("%")&&(r=r.split("%")[0]),r.length>Oa)return;let e=ke.new(r).parseWith(()=>ke.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 Na(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 ka(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 fs(r){switch(r.length){case pe:return r.join(".");case me:{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 Ua(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 Ma(r){let t="0x";for(let e of r)t+=(e>>4).toString(16)+(e&15).toString(16);return t}var pe=4,me=16,Wg=parseInt("0xFFFF",16),rl=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function yr(r,t){t.length===me&&r.length===pe&&Na(t,0,11)&&(t=t.slice(12)),t.length===pe&&r.length===me&&ka(r,rl,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 Ka(r,t){if(typeof t=="string"&&(t=Ue(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 ls(r){let[t,e]=r.split("/");if(!t||!e)throw new Error("Failed to parse given CIDR: "+r);let n=pe,o=fn(t);if(o==null&&(n=me,o=ln(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=ds(s,8*n);return{network:yr(o,i),mask:i}}function ds(r,t){if(t!==8*pe&&t!==8*me)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 xr=class{constructor(t,e){if(e==null)({network:this.network,mask:this.mask}=ls(t));else{let n=Ue(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=Ue(e);if(s==null)throw new Error("Failed to parse mask");this.mask=s}else this.mask=ds(o,8*n.length);this.network=yr(n,this.mask)}}contains(t){return Ka({network:this.network,mask:this.mask},t)}toString(){let t=Ua(this.mask),e=t!==-1?String(t):Ma(this.mask);return fs(this.network)+"/"+e}};function qa(r,t){return new xr(r).contains(t)}function Fa(r){try{let t=Jt(r);switch(t.type){case"ip6":return qa("2000::/3",t.host);default:return!1}}catch{return!1}}function Me(r){return!!fn(r)}function dn(r){return!!ln(r)}var Va=Ac(za(),1),nl=["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"],ol=nl.map(r=>new Va.Netmask(r));function hs(r){for(let t of ol)if(t.contains(r))return!0;return!1}function sl(r){return/^::ffff:([0-9a-fA-F]{1,4}):([0-9a-fA-F]{1,4})$/.test(r)}function il(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 hs(o)}function al(r){return/^::ffff:([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(r)}function cl(r){let t=r.split(":"),e=t[t.length-1];return hs(e)}function ul(r){return/^::$/.test(r)||/^::1$/.test(r)||/^64:ff9b::([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(r)||/^100::([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^2001::([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^2001:2[0-9a-fA-F]:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^2001:db8:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^2002:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^f[c-d]([0-9a-fA-F]{2,2}):/i.test(r)||/^fe[8-9a-bA-B][0-9a-fA-F]:/i.test(r)||/^ff([0-9a-fA-F]{2,2}):/i.test(r)}function hn(r){if(Me(r))return hs(r);if(sl(r))return il(r);if(al(r))return cl(r);if(dn(r))return ul(r)}function Ha(r){try{let t=Jt(r);switch(t.type){case"ip4":case"ip6":return hn(t.host)??!1;default:return t.host==="localhost"}}catch{return!1}}function Ke(){let r={};return r.promise=new Promise((t,e)=>{r.resolve=t,r.reject=e}),r}var pn=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}},qe=class{size;hwm;head;tail;constructor(t={}){this.hwm=t.splitLimit??16,this.head=new pn(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 pn(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 ps=class extends Error{type;code;constructor(t,e){super(t??"The operation was aborted"),this.type="aborted",this.code=e??"ABORT_ERR"}};function mn(r={}){return fl(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 fl(r,t){t=t??{};let e=t.onEnd,n=new qe,o,s,i,a=Ke(),c=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((x,y)=>{s=A=>{s=null,n.push(A);try{x(r(n))}catch(w){y(w)}return o}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=Ke()})}},u=x=>s!=null?s(x):(n.push(x),o),l=x=>(n=new qe,s!=null?s({error:x}):(n.push({error:x}),o)),f=x=>{if(i)return o;if(t?.objectMode!==!0&&x?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return u({done:!1,value:x})},d=x=>i?o:(i=!0,x!=null?l(x):u({done:!0})),p=()=>(n=new qe,d(),{done:!0}),h=x=>(d(x),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:c,return:p,throw:h,push:f,end:d,get readableLength(){return n.size},onEmpty:async x=>{let y=x?.signal;if(y?.throwIfAborted(),n.isEmpty())return;let A,w;y!=null&&(A=new Promise((I,P)=>{w=()=>{P(new ps)},y.addEventListener("abort",w)}));try{await Promise.race([a.promise,A])}finally{w!=null&&y!=null&&y?.removeEventListener("abort",w)}}},e==null)return o;let v=o;return o={[Symbol.asyncIterator](){return this},next(){return v.next()},throw(x){return v.throw(x),e!=null&&(e(x),e=void 0),{done:!0}},return(){return v.return(),e!=null&&(e(),e=void 0),{done:!0}},push:f,end(x){return v.end(x),e!=null&&(e(x),e=void 0),o},get readableLength(){return v.readableLength},onEmpty:x=>v.onEmpty(x)},o}var ms=class extends Error{constructor(t){super(t),this.name="TimeoutError"}},gs=class extends Error{constructor(t){super(),this.name="AbortError",this.message=t}},$a=r=>globalThis.DOMException===void 0?new gs(r):new DOMException(r),Ga=r=>{let t=r.reason===void 0?$a("This operation was aborted."):r.reason;return t instanceof Error?t:$a(t)};function bs(r,t){let{milliseconds:e,fallback:n,message:o,customTimers:s={setTimeout,clearTimeout}}=t,i,a,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(Ga(p)),a=()=>{f(Ga(p))},p.addEventListener("abort",a,{once:!0})}if(e===Number.POSITIVE_INFINITY){r.then(l,f);return}let d=new ms;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(),a&&t.signal&&t.signal.removeEventListener("abort",a)});return u.clear=()=>{s.clearTimeout.call(void 0,i),i=void 0},u}var ll=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 dl(r,t,e){let n,o=new Promise((s,i)=>{if(e={rejectionEvents:["error"],multiArgs:!1,rejectionMultiArgs:!1,resolveImmediately:!1,...e},!(e.count>=0&&(e.count===Number.POSITIVE_INFINITY||Number.isInteger(e.count))))throw new TypeError("The `count` option should be at least 0 or more");e.signal?.throwIfAborted();let a=[t].flat(),c=[],{addListener:u,removeListener:l}=ll(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}c.push(h),e.count===c.length&&(n(),s(c))},d=(...p)=>{n(),i(e.rejectionMultiArgs?p:p[0])};n=()=>{for(let p of a)l(p,f);for(let p of e.rejectionEvents)a.includes(p)||l(p,d)};for(let p of a)u(p,f);for(let p of e.rejectionEvents)a.includes(p)||u(p,d);e.signal&&e.signal.addEventListener("abort",()=>{d(e.signal.reason)},{once:!0}),e.resolveImmediately&&s(c)});if(o.cancel=n,typeof e.timeout=="number"){let s=bs(o,{milliseconds:e.timeout});return s.cancel=()=>{n(),s.clear()},s}return o}function Fe(r,t,e){typeof e=="function"&&(e={filter:e}),e={...e,count:1,resolveImmediately:!1};let n=dl(r,t,e),o=n.then(s=>s[0]);return o.cancel=n.cancel,o}function Er(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 gn=class extends Error{static name="QueueFullError";constructor(t="The queue was full"){super(t),this.name="QueueFullError"}},ge=class extends Error{static name="UnexpectedEOFError";name="UnexpectedEOFError"};function hl(r){return r.reason}async function bn(r,t,e){if(t==null)return r;let n=e?.translateError??hl;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 yn=class{deferred;signal;constructor(t){this.signal=t,this.deferred=Ke(),this.onAbort=this.onAbort.bind(this),this.signal?.addEventListener("abort",this.onAbort)}onAbort(){this.deferred.reject(this.signal?.reason??new Tt)}cleanup(){this.signal?.removeEventListener("abort",this.onAbort)}};function pl(){return`${parseInt(String(Math.random()*1e9),10).toString()}${Date.now()}`}var xn=class{id;fn;options;recipients;status;timeline;controller;constructor(t,e){this.id=pl(),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 Tt),this.cleanup())}async join(t={}){let e=new yn(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 bn(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 wn=class extends Dr{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=Er(this.emitEmpty.bind(this),1),this.emitIdle=Er(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 gn;let n=new xn(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 Tt)}),this.clear()}async onEmpty(t){this.size!==0&&await Fe(this,"empty",t)}async onSizeLessThan(t,e){this.size<t||await Fe(this,"next",{...e,filter:()=>this.size<t})}async onIdle(t){this.pending===0&&this.size===0||await Fe(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=mn({objectMode:!0}),n=c=>{c!=null?this.abort():this.clear(),e.end(c)},o=c=>{c.detail!=null&&e.push(c.detail)},s=c=>{n(c.detail.error)},i=()=>{n()},a=()=>{n(new Tt("Queue aborted"))};this.addEventListener("completed",o),this.addEventListener("failure",s),this.addEventListener("idle",i),t?.signal?.addEventListener("abort",a);try{yield*e}finally{this.removeEventListener("completed",o),this.removeEventListener("failure",s),this.removeEventListener("idle",i),t?.signal?.removeEventListener("abort",a),n()}}};function Sr(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 ot=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},Ft=class extends Error{static name="ValidationError";name="ValidationError"},En=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},Sn=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};function xs(r){return t=>W(t,r)}function ws(r){return t=>H(t,r)}function ze(r){return new DataView(r.buffer).getUint16(r.byteOffset).toString()}function be(r){let t=new ArrayBuffer(2);return new DataView(t).setUint16(0,typeof r=="string"?parseInt(r):r),new Uint8Array(t)}function Za(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=H(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=be(n);return Pt([e,o],e.length+o.length)}function Xa(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=$t.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=be(n);return Pt([e,o],e.length+o.length)}function Es(r){let t=r.subarray(0,r.length-2),e=r.subarray(r.length-2),n=W(t,"base32"),o=ze(e);return`${n}:${o}`}var Ss=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 ot("Invalid byte value in IP address");t[n]=o}),t},Ya=function(r){let t=0;r=r.toString().trim();let e=r.split(":",8),n;for(n=0;n<e.length;n++){let s=Me(e[n]),i;s&&(i=Ss(e[n]),e[n]=W(i.subarray(0,2),"base16")),i!=null&&++n<8&&e.splice(n,0,W(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 ot("Invalid byte value in IP address");o[t++]=s>>8&255,o[t++]=s&255}return o},ja=function(r){if(r.byteLength!==4)throw new ot("IPv4 address was incorrect length");let t=[];for(let e=0;e<r.byteLength;e++)t.push(r[e]);return t.join(".")},Wa=function(r){if(r.byteLength!==16)throw new ot("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 ot(`Invalid IPv6 address "${e}"`)}};function Qa(r){try{let t=new URL(`http://[${r}]`);return t.hostname.substring(1,t.hostname.length-1)}catch{throw new ot(`Invalid IPv6 address "${r}"`)}}var ys=Object.values(Je).map(r=>r.decoder),ml=(function(){let r=ys[0].or(ys[1]);return ys.slice(2).forEach(t=>r=r.or(t)),r})();function Ja(r){return ml.decode(r)}function tc(r){return t=>r.encoder.encode(t)}function gl(r){if(parseInt(r).toString()!==r)throw new Ft("Value must be an integer")}function bl(r){if(r<0)throw new Ft("Value must be a positive integer, or zero")}function yl(r){return t=>{if(t>r)throw new Ft(`Value must be smaller than or equal to ${r}`)}}function xl(...r){return t=>{for(let e of r)e(t)}}var vr=xl(gl,bl,yl(65535));var et=-1,vs=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 Sn(`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 vs,od=[{code:4,name:"ip4",size:32,valueToBytes:Ss,bytesToValue:ja,validate:r=>{if(!Me(r))throw new Ft(`Invalid IPv4 address "${r}"`)}},{code:6,name:"tcp",size:16,valueToBytes:be,bytesToValue:ze,validate:vr},{code:273,name:"udp",size:16,valueToBytes:be,bytesToValue:ze,validate:vr},{code:33,name:"dccp",size:16,valueToBytes:be,bytesToValue:ze,validate:vr},{code:41,name:"ip6",size:128,valueToBytes:Ya,bytesToValue:Wa,stringToValue:Qa,validate:r=>{if(!dn(r))throw new Ft(`Invalid IPv6 address "${r}"`)}},{code:42,name:"ip6zone",size:et},{code:43,name:"ipcidr",size:8,bytesToValue:xs("base10"),valueToBytes:ws("base10")},{code:53,name:"dns",size:et},{code:54,name:"dns4",size:et},{code:55,name:"dns6",size:et},{code:56,name:"dnsaddr",size:et},{code:132,name:"sctp",size:16,valueToBytes:be,bytesToValue:ze,validate:vr},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:et,stringToValue:r=>decodeURIComponent(r),valueToString:r=>encodeURIComponent(r)},{code:421,name:"p2p",aliases:["ipfs"],size:et,bytesToValue:xs("base58btc"),valueToBytes:r=>r.startsWith("Q")||r.startsWith("1")?ws("base58btc")(r):it.parse(r).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:Es,valueToBytes:Za},{code:445,name:"onion3",size:296,bytesToValue:Es,valueToBytes:Xa},{code:446,name:"garlic64",size:et},{code:447,name:"garlic32",size:et},{code:448,name:"tls"},{code:449,name:"sni",size:et},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:et,bytesToValue:tc(Yn),valueToBytes:Ja},{code:480,name:"http"},{code:481,name:"http-path",size:et,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:et}];od.forEach(r=>{zt.addProtocol(r)});function ec(r){let t=[],e=0;for(;e<r.length;){let n=lr(r,e),o=zt.getProtocol(n),s=mt(n),i=sd(o,r,e+s),a=0;i>0&&o.size===et&&(a=mt(i));let c=s+a+i,u={code:n,name:o.name,bytes:r.subarray(e,e+c)};if(i>0){let l=e+s+a,f=r.subarray(l,l+i);u.value=o.bytesToValue?.(f)??W(f)}t.push(u),e+=c}return t}function rc(r){let t=0,e=[];for(let n of r){if(n.bytes==null){let o=zt.getProtocol(n.code),s=mt(n.code),i,a=0,c=0;n.value!=null&&(i=o.valueToBytes?.(n.value)??H(n.value),a=i.byteLength,o.size===et&&(c=mt(a)));let u=new Uint8Array(s+c+a),l=0;Ce(n.code,u,l),l+=s,i!=null&&(o.size===et&&(Ce(a,u,l),l+=c),u.set(i,l)),n.bytes=u}e.push(n.bytes),t+=n.bytes.byteLength}return Pt(e,t)}function nc(r){if(r.charAt(0)!=="/")throw new ot('String multiaddr must start with "/"');let t=[],e="protocol",n="",o="";for(let s=1;s<r.length;s++){let i=r.charAt(s);i!=="/"&&(e==="protocol"?o+=r.charAt(s):n+=r.charAt(s));let a=s===r.length-1;if(i==="/"||a){let c=zt.getProtocol(o);if(e==="protocol"){if(c.size==null||c.size===0){t.push({code:c.code,name:c.name}),n="",o="",e="protocol";continue}else if(a)throw new ot(`Component ${o} was missing value`);e="value"}else if(e==="value"){let u={code:c.code,name:c.name};if(c.size!=null&&c.size!==0){if(n==="")throw new ot(`Component ${o} was missing value`);u.value=c.stringToValue?.(n)??n}t.push(u),n="",o="",e="protocol"}}}if(o!==""&&n!=="")throw new ot("Incomplete multiaddr");return t}function oc(r){return`/${r.flatMap(t=>{if(t.value==null)return t.name;let e=zt.getProtocol(t.code);if(e==null)throw new ot(`Unknown protocol code ${t.code}`);return[t.name,e.valueToString?.(t.value)??t.value]}).join("/")}`}function sd(r,t,e){return r.size==null||r.size===0?0:r.size>0?r.size/8:lr(t,e)}var id=Symbol.for("nodejs.util.inspect.custom"),Is=Symbol.for("@multiformats/multiaddr");function ad(r){if(r==null&&(r="/"),sc(r))return r.getComponents();if(r instanceof Uint8Array)return ec(r);if(typeof r=="string")return r=r.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),r===""&&(r="/"),nc(r);if(Array.isArray(r))return r;throw new ot("Must be a string, Uint8Array, Component[], or another Multiaddr")}var vn=class r{[Is]=!0;#t;#e;#r;constructor(t="/",e={}){this.#t=ad(t),e.validate!==!1&&cd(this)}get bytes(){return this.#r==null&&(this.#r=rc(this.#t)),this.#r}toString(){return this.#e==null&&(this.#e=oc(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 En(`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)}[id](){return`Multiaddr(${this.toString()})`}};function cd(r){r.getComponents().forEach(t=>{let e=zt.getProtocol(t.code);t.value!=null&&e.validate?.(t.value)})}function sc(r){return!!r?.[Is]}function ic(r){return new vn(r)}var ud=4194304,_n=class extends Error{static name="UnwrappedError";name="UnwrappedError"},Ds=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},Ls=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},Rs=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function fd(r){return typeof r?.closeRead=="function"}function ld(r){return typeof r?.close=="function"}function Bs(r){return fd(r)?r.remoteWriteStatus!=="writable"&&r.readBufferLength===0:ld(r)?r.status!=="open":!1}function dd(r){return r?.addEventListener!=null&&r?.removeEventListener!=null&&r?.send!=null&&r?.push!=null&&r?.log!=null}function hd(r,t){let e=t?.maxBufferSize??ud,n=new Q,o,s=!1;if(!dd(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 a=l=>{l.error!=null?o?.reject(l.error):o?.resolve()};r.addEventListener("close",a);let c=()=>{o?.resolve()};r.addEventListener("remoteCloseWrite",c);let u={readBuffer:n,async read(l){if(s===!0)throw new _n("Stream was unwrapped");if(Bs(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 ge(`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 bn(o.promise,l?.signal),Bs(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(Bs(r))throw r.log.error("closed while reading %d/%d bytes",n.byteLength,d),new ge(`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 _n("Stream was unwrapped");r.send(l)||await Fe(r,"drain",{signal:f?.signal,rejectionEvents:["close"]})},unwrap(){return s||(s=!0,r.removeEventListener("message",i),r.removeEventListener("close",a),r.removeEventListener("remoteCloseWrite",c),n.byteLength>0&&(r.log("stream unwrapped with %d unread bytes",n.byteLength),r.push(n))),r}};return u}function pd(r,t={}){let e=hd(r,t);t.maxDataLength!=null&&t.maxLengthLength==null&&(t.maxLengthLength=mt(t.maxDataLength));let n=t?.lengthDecoder??lr,o=t?.lengthEncoder??aa;return{async read(i){let a=-1,c=new Q;for(;;){let l=await e.read({...i,bytes:1});if(l==null)break;c.append(l);try{a=n(c)}catch(f){if(f instanceof RangeError)continue;throw f}if(a<0)throw new Ds("Invalid message length");if(t?.maxLengthLength!=null&&c.byteLength>t.maxLengthLength)throw new Rs(`Message length length too long - ${c.byteLength} > ${t.maxLengthLength}`);if(a>-1)break}if(t?.maxDataLength!=null&&a>t.maxDataLength)throw new Ls(`Message length too long - ${a} > ${t.maxDataLength}`);let u=await e.read({...i,bytes:a});if(u==null)throw r.log.error("tried to read %d bytes but the stream closed",a),new ge(`Unexpected EOF - tried to read ${a} bytes but the stream closed`);if(u.byteLength!==a)throw r.log.error("read %d/%d bytes before the stream closed",u.byteLength,a),new ge(`Unexpected EOF - read ${u.byteLength}/${a} bytes before the stream closed`);return u},async write(i,a){await e.write(new Q(o(i.byteLength),i),a)},async writeV(i,a){let c=new Q(...i.flatMap(u=>[o(u.byteLength),u]));await e.write(c,a)},unwrap(){return e.unwrap()}}}function Ve(r,t){let e=pd(r,t),n={read:async(o,s)=>{let i=await e.read(s);return o.decode(i)},write:async(o,s,i)=>{await e.write(s.encode(o),i)},writeV:async(o,s,i)=>{await e.writeV(o.map(a=>s.encode(a)),i)},pb:o=>({read:async s=>n.read(o,s),write:async(s,i)=>n.write(s,o,i),writeV:async(s,i)=>n.writeV(s,o,i),unwrap:()=>n}),unwrap:()=>e.unwrap()};return n}var An=class extends wn{has(t){return this.find(t)!=null}find(t){return this.queue.find(e=>t.equals(e.options.peerId))}};function ac(r,t,e){let n,o,s=!1;function i(){let u={signal:o.signal};if(e?.timeout!=null){let l=Sr([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 a=Er(i,e?.debounce??100),c=!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),a())},start:()=>{c||(c=!0,o=new AbortController,o.signal,e?.runImmediately===!0?queueMicrotask(()=>{i()}):n=setTimeout(i,t))},stop:()=>{clearTimeout(n),o?.abort(),c=!1}}}var Ts=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 cc(r){let{name:t,metrics:e}=r,n;return e!=null?n=new Ts({name:t,metrics:e}):n=new Map,n}var Cs="libp2p",Ps="autonat";var uc="dial-request",fc="dial-back",lc=200n*1024n,dc=4096;var He;(function(r){let t;r.codec=()=>(t==null&&(t=vt((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e={...e},e.dialDataResponse!=null&&(e.dialDataRequest=void 0,e.dialResponse=void 0,e.dialRequest=void 0),e.dialDataRequest!=null&&(e.dialDataResponse=void 0,e.dialResponse=void 0,e.dialRequest=void 0),e.dialResponse!=null&&(e.dialDataResponse=void 0,e.dialDataRequest=void 0,e.dialRequest=void 0),e.dialRequest!=null&&(e.dialDataResponse=void 0,e.dialDataRequest=void 0,e.dialResponse=void 0),e.dialRequest!=null&&(n.uint32(10),In.codec().encode(e.dialRequest,n)),e.dialResponse!=null&&(n.uint32(18),Vt.codec().encode(e.dialResponse,n)),e.dialDataRequest!=null&&(n.uint32(26),Bn.codec().encode(e.dialDataRequest,n)),e.dialDataResponse!=null&&(n.uint32(34),Ln.codec().encode(e.dialDataResponse,n)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let a=e.uint32();switch(a>>>3){case 1:{s.dialRequest=In.codec().decode(e,e.uint32(),{limits:o.limits?.dialRequest});break}case 2:{s.dialResponse=Vt.codec().decode(e,e.uint32(),{limits:o.limits?.dialResponse});break}case 3:{s.dialDataRequest=Bn.codec().decode(e,e.uint32(),{limits:o.limits?.dialDataRequest});break}case 4:{s.dialDataResponse=Ln.codec().decode(e,e.uint32(),{limits:o.limits?.dialDataResponse});break}default:{e.skipType(a&7);break}}}return s.dialDataResponse!=null&&(delete s.dialDataRequest,delete s.dialResponse,delete s.dialRequest),s.dialDataRequest!=null&&(delete s.dialDataResponse,delete s.dialResponse,delete s.dialRequest),s.dialResponse!=null&&(delete s.dialDataResponse,delete s.dialDataRequest,delete s.dialRequest),s.dialRequest!=null&&(delete s.dialDataResponse,delete s.dialDataRequest,delete s.dialResponse),s})),t),r.encode=e=>St(e,r.codec()),r.decode=(e,n)=>Et(e,r.codec(),n)})(He||(He={}));var In;(function(r){let t;r.codec=()=>(t==null&&(t=vt((e,n,o={})=>{if(o.lengthDelimited!==!1&&n.fork(),e.addrs!=null)for(let s of e.addrs)n.uint32(10),n.bytes(s);e.nonce!=null&&e.nonce!==0n&&(n.uint32(17),n.fixed64(e.nonce)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={addrs:[],nonce:0n},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let a=e.uint32();switch(a>>>3){case 1:{if(o.limits?.addrs!=null&&s.addrs.length===o.limits.addrs)throw new Wr('Decode error - map field "addrs" had too many elements');s.addrs.push(e.bytes());break}case 2:{s.nonce=e.fixed64();break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>St(e,r.codec()),r.decode=(e,n)=>Et(e,r.codec(),n)})(In||(In={}));var Bn;(function(r){let t;r.codec=()=>(t==null&&(t=vt((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.addrIdx!=null&&e.addrIdx!==0&&(n.uint32(8),n.uint32(e.addrIdx)),e.numBytes!=null&&e.numBytes!==0n&&(n.uint32(16),n.uint64(e.numBytes)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={addrIdx:0,numBytes:0n},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let a=e.uint32();switch(a>>>3){case 1:{s.addrIdx=e.uint32();break}case 2:{s.numBytes=e.uint64();break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>St(e,r.codec()),r.decode=(e,n)=>Et(e,r.codec(),n)})(Bn||(Bn={}));var ut;(function(r){r.UNUSED="UNUSED",r.E_DIAL_ERROR="E_DIAL_ERROR",r.E_DIAL_BACK_ERROR="E_DIAL_BACK_ERROR",r.OK="OK"})(ut||(ut={}));var Dn;(function(r){r[r.UNUSED=0]="UNUSED",r[r.E_DIAL_ERROR=100]="E_DIAL_ERROR",r[r.E_DIAL_BACK_ERROR=101]="E_DIAL_BACK_ERROR",r[r.OK=200]="OK"})(Dn||(Dn={}));(function(r){r.codec=()=>le(Dn)})(ut||(ut={}));var Vt;(function(r){let t;(function(o){o.E_INTERNAL_ERROR="E_INTERNAL_ERROR",o.E_REQUEST_REJECTED="E_REQUEST_REJECTED",o.E_DIAL_REFUSED="E_DIAL_REFUSED",o.OK="OK"})(t=r.ResponseStatus||(r.ResponseStatus={}));let e;(function(o){o[o.E_INTERNAL_ERROR=0]="E_INTERNAL_ERROR",o[o.E_REQUEST_REJECTED=100]="E_REQUEST_REJECTED",o[o.E_DIAL_REFUSED=101]="E_DIAL_REFUSED",o[o.OK=200]="OK"})(e||(e={})),(function(o){o.codec=()=>le(e)})(t=r.ResponseStatus||(r.ResponseStatus={}));let n;r.codec=()=>(n==null&&(n=vt((o,s,i={})=>{i.lengthDelimited!==!1&&s.fork(),o.status!=null&&e[o.status]!==0&&(s.uint32(8),r.ResponseStatus.codec().encode(o.status,s)),o.addrIdx!=null&&o.addrIdx!==0&&(s.uint32(16),s.uint32(o.addrIdx)),o.dialStatus!=null&&Dn[o.dialStatus]!==0&&(s.uint32(24),ut.codec().encode(o.dialStatus,s)),i.lengthDelimited!==!1&&s.ldelim()},(o,s,i={})=>{let a={status:t.E_INTERNAL_ERROR,addrIdx:0,dialStatus:ut.UNUSED},c=s==null?o.len:o.pos+s;for(;o.pos<c;){let u=o.uint32();switch(u>>>3){case 1:{a.status=r.ResponseStatus.codec().decode(o);break}case 2:{a.addrIdx=o.uint32();break}case 3:{a.dialStatus=ut.codec().decode(o);break}default:{o.skipType(u&7);break}}}return a})),n),r.encode=o=>St(o,r.codec()),r.decode=(o,s)=>Et(o,r.codec(),s)})(Vt||(Vt={}));var Ln;(function(r){let t;r.codec=()=>(t==null&&(t=vt((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.data!=null&&e.data.byteLength>0&&(n.uint32(10),n.bytes(e.data)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={data:bt(0)},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let a=e.uint32();switch(a>>>3){case 1:{s.data=e.bytes();break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>St(e,r.codec()),r.decode=(e,n)=>Et(e,r.codec(),n)})(Ln||(Ln={}));var $e;(function(r){let t;r.codec=()=>(t==null&&(t=vt((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.nonce!=null&&e.nonce!==0n&&(n.uint32(9),n.fixed64(e.nonce)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={nonce:0n},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let a=e.uint32();switch(a>>>3){case 1:{s.nonce=e.fixed64();break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>St(e,r.codec()),r.decode=(e,n)=>Et(e,r.codec(),n)})($e||($e={}));var te;(function(r){let t;(function(o){o.OK="OK"})(t=r.DialBackStatus||(r.DialBackStatus={}));let e;(function(o){o[o.OK=0]="OK"})(e||(e={})),(function(o){o.codec=()=>le(e)})(t=r.DialBackStatus||(r.DialBackStatus={}));let n;r.codec=()=>(n==null&&(n=vt((o,s,i={})=>{i.lengthDelimited!==!1&&s.fork(),o.status!=null&&e[o.status]!==0&&(s.uint32(8),r.DialBackStatus.codec().encode(o.status,s)),i.lengthDelimited!==!1&&s.ldelim()},(o,s,i={})=>{let a={status:t.OK},c=s==null?o.len:o.pos+s;for(;o.pos<c;){let u=o.uint32();switch(u>>>3){case 1:{a.status=r.DialBackStatus.codec().decode(o);break}default:{o.skipType(u&7);break}}}return a})),n),r.encode=o=>St(o,r.codec()),r.decode=(o,s)=>Et(o,r.codec(),s)})(te||(te={}));function Rn(r,t){return Math.round(Math.random()*(t-r)+r)}var gd=4,bd=8,Tn=class{components;dialRequestProtocol;dialBackProtocol;timeout;maxInboundStreams;maxOutboundStreams;maxMessageSize;maxDialDataBytes;dialDataChunkSize;started;log;topologyId;dialResults;findPeers;addressFilter;connectionThreshold;queue;nonces;constructor(t,e){this.components=t,this.log=t.logger.forComponent("libp2p:auto-nat-v2:client"),this.started=!1,this.dialRequestProtocol=e.dialRequestProtocol,this.dialBackProtocol=e.dialBackProtocol,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=cc({name:"libp2p_autonat_v2_dial_results",metrics:t.metrics}),this.findPeers=ac(this.findRandomPeers.bind(this),6e4),this.addressFilter=us(1024),this.queue=new An({concurrency:3,maxSize:50}),this.maxDialDataBytes=e.maxDialDataBytes??lc,this.dialDataChunkSize=e.dialDataChunkSize??dc,this.nonces=new Set}[Symbol.toStringTag]="@libp2p/autonat-v2";[Lr]=["@libp2p/autonat"];get[Rr](){return["@libp2p/identify"]}isStarted(){return this.started}async start(){this.started||(this.topologyId=await this.components.registrar.register(this.dialRequestProtocol,{onConnect:(t,e)=>{this.verifyExternalAddresses(e).catch(n=>{this.log.error("could not verify addresses - %e",n)})}}),await this.components.registrar.handle(this.dialBackProtocol,(t,e)=>{this.handleDialBackStream(t,e).catch(n=>{this.log.error("error handling incoming autonat stream - %e",n)})},{maxInboundStreams:this.maxInboundStreams,maxOutboundStreams:this.maxOutboundStreams}),this.findPeers.start(),this.started=!0)}async stop(){await this.components.registrar.unhandle(this.dialRequestProtocol),await this.components.registrar.unhandle(this.dialBackProtocol),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=Sr([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 handleDialBackStream(t,e){let n=AbortSignal.timeout(this.timeout);let o=Ve(t,{maxDataLength:this.maxMessageSize});try{let s=await o.read($e,{signal:n});if(!this.nonces.has(s.nonce))throw new wt("No matching dial found for nonce value");this.nonces.delete(s.nonce),await o.write({status:te.DialBackStatus.OK},te),await t.close({signal:n})}catch(s){this.log.error("error handling incoming dial back stream - %e",s),t.abort(s)}}getUnverifiedMultiaddrs(t,e){let n=this.components.addressManager.getAddressesWithMetadata().sort((s,i)=>s.type==="observed"&&i.type!=="observed"?1:i.type==="observed"&&s.type!=="observed"?-1:0).filter(s=>!(!(s.expires<Date.now())||Jt(s.multiaddr).type==="ip6"&&(!e||!Fa(s.multiaddr))||Ha(s.multiaddr))),o=[];for(let s of n){let i=s.multiaddr.toString(),a=this.dialResults.get(i);if(a!=null&&a.networkSegments.includes(t)){this.log.trace("%a already has a network segment result from %s",a.multiaddr,t);continue}if(a==null){let c=s.expires<Date.now();if(c&&this.addressFilter.remove?.(i),this.addressFilter.has(i))continue;this.addressFilter.add(i),this.log.trace("creating dial result %s %s",c?"to revalidate":"for",i),a={multiaddr:s.multiaddr,success:0,failure:0,networkSegments:[],verifyingPeers:ss(),type:s.type,lastVerified:s.lastVerified},this.dialResults.set(i,a)}o.push(a)}return o}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})=>Jt(i).type==="ip6"),o=this.getNetworkSegment(t.remoteAddr),s=this.getUnverifiedMultiaddrs(o,n);if(s.length!==0){if(!this.hasConnectionCapacity()){s[0]?.lastVerified!=null?(this.log("automatically re-verifying %a because we are too close to the connection limit",s[0].multiaddr),this.confirmAddress(s[0])):this.log("skipping verifying %a because we are too close to the connection limit",s[0]?.multiaddr);return}this.queue.add(async i=>{let a=Sr([i.signal,AbortSignal.timeout(this.timeout)]),c=BigInt(Rn(0,Number.MAX_SAFE_INTEGER));this.nonces.add(c);try{await this.askPeerToVerify(t,o,c,i)}finally{a.clear(),this.nonces.delete(c)}},{peerId:t.remotePeer}).catch(i=>{this.log.error("error from %p verifying addresses - %e",t.remotePeer,i)})}}async askPeerToVerify(t,e,n,o){let s=[...this.dialResults.values()].filter(a=>a.result==null).map(a=>a.multiaddr);if(s.length===0){this.queue.clear();return}this.log.trace("asking %a to verify multiaddrs %s",t.remoteAddr,s);let i=await t.newStream(this.dialRequestProtocol,o);try{let a=Ve(i).pb(He);await a.write({dialRequest:{addrs:s.map(c=>c.bytes),nonce:n}},o);for(let c=0;c<s.length;c++){let u=await a.read(o);if(u.dialDataRequest!=null){if(u.dialDataRequest.numBytes>this.maxDialDataBytes){this.log("too many dial data byte requested by %p - %s/%s",t.remotePeer,u.dialDataRequest.numBytes,this.maxDialDataBytes);continue}this.log("sending %d bytes to %p as anti-amplification attack protection",u.dialDataRequest.numBytes,t.remotePeer);let p=new Uint8Array(this.dialDataChunkSize),h=BigInt(this.dialDataChunkSize);for(let v=0n;v<u.dialDataRequest.numBytes;v+=h)await a.write({dialDataResponse:{data:p}},o);u=await a.read(o)}if(u.dialResponse==null){this.log("invalid autonat response from %p - %j",t.remotePeer,u);return}if(u.dialResponse.status!==Vt.ResponseStatus.OK)return;let f=s[u.dialResponse.addrIdx];if(f==null){this.log.trace("peer dialed unknown address");continue}let d=this.dialResults.get(f.toString());if(d==null){this.log.trace("peer reported %a as %s but there is no result object",f,u.dialResponse.status);continue}if(d.networkSegments.includes(e)){this.log.trace("%a results already included network segment %s",f,e);continue}if(d.result!=null){this.log.trace("already resolved result for %a, ignoring response from",f,t.remotePeer);continue}if(d.verifyingPeers.has(t.remotePeer)){this.log.trace("peer %p has already verified %a, ignoring response",t.remotePeer,f);continue}if(d.verifyingPeers.add(t.remotePeer),d.networkSegments.push(e),u.dialResponse.dialStatus===ut.OK){if(this.log.trace("%p dialed %a successfully",t.remotePeer,d.multiaddr),d.success++,d.type!=="observed"){this.confirmAddress(d);continue}}else if(u.dialResponse.dialStatus===ut.E_DIAL_ERROR)this.log.trace("%p could not dial %a",t.remotePeer,d.multiaddr),d.failure++;else if(u.dialResponse.dialStatus===ut.E_DIAL_BACK_ERROR){this.log.trace("%p saw error while dialing %a",t.remotePeer,d.multiaddr);continue}this.log("%a success %d failure %d",d.multiaddr,d.success,d.failure),d.success===gd&&this.confirmAddress(d),d.failure===bd&&this.unconfirmAddress(d)}}finally{try{await i.close(o)}catch(a){i.abort(a)}}}hasConnectionCapacity(){let e=this.components.connectionManager.getConnections().length,n=this.components.connectionManager.getMaxConnections();return e/n*100<this.connectionThreshold}confirmAddress(t){this.log("%s address %a is externally dialable",t.type,t.multiaddr),this.components.addressManager.confirmObservedAddr(t.multiaddr),this.dialResults.delete(t.multiaddr.toString()),t.result=!0}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}getNetworkSegment(t){let e=Jt(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`)}}};var Cn=class{components;dialRequestProtocol;dialBackProtocol;timeout;maxInboundStreams;maxOutboundStreams;maxMessageSize;started;log;constructor(t,e){this.components=t,this.log=t.logger.forComponent("libp2p:auto-nat-v2:server"),this.started=!1,this.dialRequestProtocol=e.dialRequestProtocol,this.dialBackProtocol=e.dialBackProtocol,this.timeout=e.timeout??3e4,this.maxInboundStreams=e.maxInboundStreams??2,this.maxOutboundStreams=e.maxOutboundStreams??20,this.maxMessageSize=e.maxMessageSize??8192,this.handleDialRequestStream=this.handleDialRequestStream.bind(this)}async start(){this.started||(await this.components.registrar.handle(this.dialRequestProtocol,this.handleDialRequestStream,{maxInboundStreams:this.maxInboundStreams,maxOutboundStreams:this.maxOutboundStreams}),this.started=!0)}async stop(){await this.components.registrar.unhandle(this.dialRequestProtocol),this.started=!1}async handleDialRequestStream(t,e){let n=AbortSignal.timeout(this.timeout);let o=Ve(t,{maxDataLength:this.maxMessageSize}).pb(He),s=bc(e.remoteAddr);if(s==null)throw new wt(`Could not find IP address in connection address "${e.remoteAddr}"`);let{dialRequest:i}=await o.read({signal:n});if(i==null)throw new wt("Did not receive DialRequest message on incoming dial request stream");if(i.addrs.length===0)throw new wt("Did not receive any addresses to dial");for(let a=0;a<i.addrs.length;a++)try{let c=ic(i.addrs[a]);if(!await this.components.connectionManager.isDialable(c,{signal:n})){await o.write({dialResponse:{addrIdx:a,status:Vt.ResponseStatus.E_DIAL_REFUSED,dialStatus:ut.UNUSED}},{signal:n});continue}let l=bc(c);if(l==null)throw new wt(`Could not find IP address in requested address "${c}"`);if(hn(l))throw new wt(`Requested address had private IP "${c}"`);l!==s&&await this.preventAmplificationAttack(o,a,{signal:n});let f=await this.dialClientBack(c,i.nonce,{signal:n});await o.write({dialResponse:{addrIdx:a,status:Vt.ResponseStatus.OK,dialStatus:f}},{signal:n})}catch(c){this.log.error("error handling incoming dialback request - %e",c)}await t.close({signal:n})}async preventAmplificationAttack(t,e,n){let o=Rn(3e4,1e5);await t.write({dialDataRequest:{addrIdx:e,numBytes:BigInt(o)}},n);let s=0;for(;s<o;){let{dialDataResponse:i}=await t.read(n);if(i==null)throw new wt("Did not receive DialDataResponse message on incoming dial request stream");s+=i.data.byteLength}}async dialClientBack(t,e,n){let o;try{o=await this.components.connectionManager.openConnection(t,{force:!0,...n})}catch(s){return this.log.error("failed to open connection to %a - %e",t,s),ut.E_DIAL_ERROR}try{let s=await o.newStream(this.dialBackProtocol,n),i=Ve(s,{maxDataLength:this.maxMessageSize});if(await i.write({nonce:e},$e,n),(await i.read(te,n)).status!==te.DialBackStatus.OK)throw new wt("DialBackResponse status was not OK");await o.close(n)}catch(s){return this.log.error("could not perform dial back - %e",s),o.abort(s),ut.E_DIAL_BACK_ERROR}return ut.OK}};function bc(r){return r.getComponents().filter(t=>t.code===4||t.code===41).map(t=>t.value).pop()}var Pn=class{client;server;constructor(t,e){let n=`/${e.protocolPrefix??Cs}/${Ps}/${"2"}/${uc}`,o=`/${e.protocolPrefix??Cs}/${Ps}/${"2"}/${fc}`;this.client=new Tn(t,{...e,dialRequestProtocol:n,dialBackProtocol:o}),this.server=new Cn(t,{...e,dialRequestProtocol:n,dialBackProtocol:o})}[Symbol.toStringTag]="@libp2p/autonat-v2";[Lr]=["@libp2p/autonat"];get[Rr](){return["@libp2p/identify"]}async start(){await Ms(this.client,this.server)}async stop(){await Ks(this.client,this.server)}};function yd(r={}){return t=>new Pn(t,r)}return Ic(xd);})();
|
|
2
|
+
"use strict";var Libp2PAutonatV2=(()=>{var xc=Object.create;var Ir=Object.defineProperty;var wc=Object.getOwnPropertyDescriptor;var Ec=Object.getOwnPropertyNames;var Sc=Object.getPrototypeOf,vc=Object.prototype.hasOwnProperty;var _c=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports),gt=(r,t)=>{for(var e in t)Ir(r,e,{get:t[e],enumerable:!0})},Ns=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Ec(t))!vc.call(r,o)&&o!==e&&Ir(r,o,{get:()=>t[o],enumerable:!(n=wc(t,o))||n.enumerable});return r};var Ac=(r,t,e)=>(e=r!=null?xc(Sc(r)):{},Ns(t||!r||!r.__esModule?Ir(e,"default",{value:r,enumerable:!0}):e,r)),Ic=r=>Ns(Ir({},"__esModule",{value:!0}),r);var za=_c(wr=>{(function(){var r,t,e,n,o,s,i,a;a=function(c){var u,l,f,d;return u=(c&255<<24)>>>24,l=(c&255<<16)>>>16,f=(c&65280)>>>8,d=c&255,[u,l,f,d].join(".")},i=function(c){var u,l,f,d,p,h;for(u=[],f=d=0;d<=3&&c.length!==0;f=++d){if(f>0){if(c[0]!==".")throw new Error("Invalid IP");c=c.substring(1)}h=t(c),p=h[0],l=h[1],c=c.substring(l),u.push(p)}if(c.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(c){return c.charCodeAt(0)},n=e("0"),s=e("a"),o=e("A"),t=function(c){var u,l,f,d,p;for(d=0,u=10,l="9",f=0,c.length>1&&c[f]==="0"&&(c[f+1]==="x"||c[f+1]==="X"?(f+=2,u=16):"0"<=c[f+1]&&c[f+1]<="9"&&(f++,u=8,l="7")),p=f;f<c.length;){if("0"<=c[f]&&c[f]<=l)d=d*u+(e(c[f])-n)>>>0;else if(u===16)if("a"<=c[f]&&c[f]<="f")d=d*u+(10+e(c[f])-s)>>>0;else if("A"<=c[f]&&c[f]<="F")d=d*u+(10+e(c[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 c(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=a(this.netLong),this.mask=a(this.maskLong),this.hostmask=a(~this.maskLong),this.first=this.bitmask<=30?a(this.netLong+1):this.base,this.last=this.bitmask<=30?a(this.netLong+this.size-2):a(this.netLong+this.size-1),this.broadcast=this.bitmask<=30?a(this.netLong+this.size-1):void 0}return c.prototype.contains=function(u){return typeof u=="string"&&(u.indexOf("/")>0||u.split(".").length!==4)&&(u=new c(u)),u instanceof c?this.contains(u.base)&&this.contains(u.broadcast||u.last):(i(u)&this.maskLong)>>>0===(this.netLong&this.maskLong)>>>0},c.prototype.next=function(u){return u==null&&(u=1),new c(a(this.netLong+this.size*u),this.mask)},c.prototype.forEach=function(u){var l,f,d;for(d=i(this.first),f=i(this.last),l=0;d<=f;)u(a(d),d,l),l++,d++},c.prototype.toString=function(){return this.base+"/"+this.bitmask},c})(),wr.ip2long=i,wr.long2ip=a,wr.Netmask=r}).call(wr)});var xd={};gt(xd,{autoNATv2:()=>yd});var Tt=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"}},Br=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var Dr=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}};var wt=class extends Error{static name="ProtocolError";constructor(t="Protocol error"){super(t),this.name="ProtocolError"}};var Ge=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var On=Symbol.for("@libp2p/peer-id");function Us(r){return r!=null&&typeof r.start=="function"&&typeof r.stop=="function"}async function Ms(...r){let t=[];for(let e of r)Us(e)&&t.push(e);await Promise.all(t.map(async e=>{e.beforeStart!=null&&await e.beforeStart()})),await Promise.all(t.map(async e=>{await e.start()})),await Promise.all(t.map(async e=>{e.afterStart!=null&&await e.afterStart()}))}async function Ks(...r){let t=[];for(let e of r)Us(e)&&t.push(e);await Promise.all(t.map(async e=>{e.beforeStop!=null&&await e.beforeStop()})),await Promise.all(t.map(async e=>{await e.stop()})),await Promise.all(t.map(async e=>{e.afterStop!=null&&await e.afterStop()}))}var Lr=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 Rr=Symbol.for("@libp2p/service-capabilities"),Tr=Symbol.for("@libp2p/service-dependencies");var Kn={};gt(Kn,{base58btc:()=>Y,base58flickr:()=>Pc});var jd=new Uint8Array(0);function qs(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 Ct(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 Fs(r){return new TextEncoder().encode(r)}function zs(r){return new TextDecoder().decode(r)}function Bc(r,t){if(r.length>=255)throw new TypeError("Alphabet too long");for(var e=new Uint8Array(256),n=0;n<e.length;n++)e[n]=255;for(var o=0;o<r.length;o++){var s=r.charAt(o),i=s.charCodeAt(0);if(e[i]!==255)throw new TypeError(s+" is ambiguous");e[i]=o}var a=r.length,c=r.charAt(0),u=Math.log(a)/Math.log(256),l=Math.log(256)/Math.log(a);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,x=0,y=0,A=h.length;y!==A&&h[y]===0;)y++,v++;for(var w=(A-y)*l+1>>>0,I=new Uint8Array(w);y!==A;){for(var P=h[y],U=0,M=w-1;(P!==0||U<x)&&M!==-1;M--,U++)P+=256*I[M]>>>0,I[M]=P%a>>>0,P=P/a>>>0;if(P!==0)throw new Error("Non-zero carry");x=U,y++}for(var S=w-x;S!==w&&I[S]===0;)S++;for(var E=c.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 x=0,y=0;h[v]===c;)x++,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<y)&&U!==-1;U--,P++)I+=a*w[U]>>>0,w[U]=I%256>>>0,I=I/256>>>0;if(I!==0)throw new Error("Non-zero carry");y=P,v++}if(h[v]!==" "){for(var M=A-y;M!==A&&w[M]===0;)M++;for(var S=new Uint8Array(x+(A-M)),E=x;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 Dc=Bc,Lc=Dc,Hs=Lc;var kn=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")}},Nn=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 $s(this,t)}},Un=class{decoders;constructor(t){this.decoders=t}or(t){return $s(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 $s(r,t){return new Un({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var Mn=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 kn(t,e,n),this.decoder=new Nn(t,e,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function ye({name:r,prefix:t,encode:e,decode:n}){return new Mn(r,t,e,n)}function Ht({name:r,prefix:t,alphabet:e}){let{encode:n,decode:o}=Hs(e,r);return ye({prefix:t,name:r,encode:n,decode:s=>Ct(o(s))})}function Rc(r,t,e,n){let o=r.length;for(;r[o-1]==="=";)--o;let s=new Uint8Array(o*e/8|0),i=0,a=0,c=0;for(let u=0;u<o;++u){let l=t[r[u]];if(l===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<e|l,i+=e,i>=8&&(i-=8,s[c++]=255&a>>i)}if(i>=e||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function Tc(r,t,e){let n=t[t.length-1]==="=",o=(1<<e)-1,s="",i=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],i+=8;i>e;)i-=e,s+=t[o&a>>i];if(i!==0&&(s+=t[o&a<<e-i]),n)for(;(s.length*e&7)!==0;)s+="=";return s}function Cc(r){let t={};for(let e=0;e<r.length;++e)t[r[e]]=e;return t}function X({name:r,prefix:t,bitsPerChar:e,alphabet:n}){let o=Cc(n);return ye({prefix:t,name:r,encode(s){return Tc(s,n,e)},decode(s){return Rc(s,o,e,r)}})}var Y=Ht({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Pc=Ht({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var qn={};gt(qn,{base32:()=>$t,base32hex:()=>Uc,base32hexpad:()=>Kc,base32hexpadupper:()=>qc,base32hexupper:()=>Mc,base32pad:()=>kc,base32padupper:()=>Nc,base32upper:()=>Oc,base32z:()=>Fc});var $t=X({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Oc=X({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),kc=X({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Nc=X({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Uc=X({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Mc=X({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Kc=X({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),qc=X({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Fc=X({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Fn={};gt(Fn,{base36:()=>Ze,base36upper:()=>zc});var Ze=Ht({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),zc=Ht({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Vc=Xs,Gs=128,Hc=127,$c=~Hc,Gc=Math.pow(2,31);function Xs(r,t,e){t=t||[],e=e||0;for(var n=e;r>=Gc;)t[e++]=r&255|Gs,r/=128;for(;r&$c;)t[e++]=r&255|Gs,r>>>=7;return t[e]=r|0,Xs.bytes=e-n+1,t}var Zc=zn,Xc=128,Zs=127;function zn(r,n){var e=0,n=n||0,o=0,s=n,i,a=r.length;do{if(s>=a)throw zn.bytes=0,new RangeError("Could not decode varint");i=r[s++],e+=o<28?(i&Zs)<<o:(i&Zs)*Math.pow(2,o),o+=7}while(i>=Xc);return zn.bytes=s-n,e}var Yc=Math.pow(2,7),jc=Math.pow(2,14),Wc=Math.pow(2,21),Qc=Math.pow(2,28),Jc=Math.pow(2,35),tu=Math.pow(2,42),eu=Math.pow(2,49),ru=Math.pow(2,56),nu=Math.pow(2,63),ou=function(r){return r<Yc?1:r<jc?2:r<Wc?3:r<Qc?4:r<Jc?5:r<tu?6:r<eu?7:r<ru?8:r<nu?9:10},su={encode:Vc,decode:Zc,encodingLength:ou},iu=su,Xe=iu;function Ye(r,t=0){return[Xe.decode(r,t),Xe.decode.bytes]}function xe(r,t,e=0){return Xe.encode(r,t,e),t}function we(r){return Xe.encodingLength(r)}function Se(r,t){let e=t.byteLength,n=we(r),o=n+we(e),s=new Uint8Array(o+e);return xe(r,s,0),xe(e,s,n),s.set(t,o),new Ee(r,e,t,s)}function je(r){let t=Ct(r),[e,n]=Ye(t),[o,s]=Ye(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new Ee(e,o,i,t)}function Ys(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&qs(r.bytes,e.bytes)}}var Ee=class{code;size;digest;bytes;constructor(t,e,n,o){this.code=t,this.size=e,this.digest=n,this.bytes=o}};function js(r,t){let{bytes:e,version:n}=r;switch(n){case 0:return cu(e,Vn(r),t??Y.encoder);default:return uu(e,Vn(r),t??$t.encoder)}}var Ws=new WeakMap;function Vn(r){let t=Ws.get(r);if(t==null){let e=new Map;return Ws.set(r,e),e}return t}var it=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!==We)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==fu)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=Se(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&&Ys(t.multihash,n.multihash)}toString(t){return js(this,t)}toJSON(){return{"/":js(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??Qs(n,o,s.bytes))}else if(e[lu]===!0){let{version:n,multihash:o,code:s}=e,i=je(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!==We)throw new Error(`Version 0 CID must use dag-pb (code: ${We}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let o=Qs(t,e,n.bytes);return new r(t,e,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,We,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=Ct(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 Ee(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]=Ye(t.subarray(e));return e+=d,f},o=n(),s=We;if(o===18?(o=0,e=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=e,a=n(),c=n(),u=e+c,l=u-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:l,size:u}}static parse(t,e){let[n,o]=au(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 Vn(s).set(n,t),s}};function au(r,t){switch(r[0]){case"Q":{let e=t??Y;return[Y.prefix,e.decode(`${Y.prefix}${r}`)]}case Y.prefix:{let e=t??Y;return[Y.prefix,e.decode(r)]}case $t.prefix:{let e=t??$t;return[$t.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 cu(r,t,e){let{prefix:n}=e;if(n!==Y.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 uu(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 We=112,fu=18;function Qs(r,t,e){let n=we(r),o=n+we(t),s=new Uint8Array(o+e.byteLength);return xe(r,s,0),xe(t,s,n),s.set(e,o),s}var lu=Symbol.for("@ipld/js-cid/CID");var Hn={};gt(Hn,{identity:()=>_t});var Js=0,du="identity",ti=Ct;function hu(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 Se(Js,ti(r))}var _t={code:Js,name:du,encode:ti,digest:hu};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 bt(r=0){return new Uint8Array(r)}function ht(r=0){return new Uint8Array(r)}function Pt(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 ri=Symbol.for("@achingbrain/uint8arraylist");function ei(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 Pr(r){return!!r?.[ri]}var Q=class r{bufs;length;[ri]=!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(Pr(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(Pr(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=ei(this.bufs,t);return e.buf[e.index]}set(t,e){let n=ei(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(Pr(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 Pt(n,o)}subarray(t,e){let{bufs:n,length:o}=this._subList(t,e);return n.length===1?n[0]:Pt(n,o)}sublist(t,e){let{bufs:n,length:o}=this._subList(t,e),s=new r;return s.length=o,s.bufs=[...n],s}_subList(t,e){if(t=t??0,e=e??this.length,t<0&&(t=this.length+t),e<0&&(e=this.length+e),t<0||e>this.length)throw new RangeError("index is out of bounds");if(t===e)return{bufs:[],length:0};if(t===0&&e===this.length)return{bufs:this.bufs,length:this.length};let n=[],o=0;for(let s=0;s<this.bufs.length;s++){let i=this.bufs[s],a=o,c=a+i.byteLength;if(o=c,t>=c)continue;let u=t>=a&&t<c,l=e>a&&e<=c;if(u&&l){if(t===a&&e===c){n.push(i);break}let f=t-a;n.push(i.subarray(f,f+(e-t)));break}if(u){if(t===0){n.push(i);continue}n.push(i.subarray(t-a));continue}if(l){if(e===c){n.push(i);break}n.push(i.subarray(0,e-a));break}n.push(i)}return{bufs:n,length:e-t}}indexOf(t,e=0){if(!Pr(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 a=i,c=this.byteLength-n.byteLength,u=n.byteLength-1,l;for(let f=e;f<=c;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-a[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=bt(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=bt(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=bt(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=bt(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=bt(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=bt(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=bt(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=bt(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 $n={};gt($n,{base10:()=>pu});var pu=Ht({prefix:"9",name:"base10",alphabet:"0123456789"});var Gn={};gt(Gn,{base16:()=>mu,base16upper:()=>gu});var mu=X({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),gu=X({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Zn={};gt(Zn,{base2:()=>bu});var bu=X({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Xn={};gt(Xn,{base256emoji:()=>Su});var ni=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}"),yu=ni.reduce((r,t,e)=>(r[e]=t,r),[]),xu=ni.reduce((r,t,e)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return r[n]=e,r},[]);function wu(r){return r.reduce((t,e)=>(t+=yu[e],t),"")}function Eu(r){let t=[];for(let e of r){let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);let o=xu[n];if(o==null)throw new Error(`Non-base256emoji character: ${e}`);t.push(o)}return new Uint8Array(t)}var Su=ye({prefix:"\u{1F680}",name:"base256emoji",encode:wu,decode:Eu});var jn={};gt(jn,{base64:()=>vu,base64pad:()=>_u,base64url:()=>Yn,base64urlpad:()=>Au});var vu=X({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),_u=X({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Yn=X({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Au=X({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Wn={};gt(Wn,{base8:()=>Iu});var Iu=X({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Qn={};gt(Qn,{identity:()=>Bu});var Bu=ye({prefix:"\0",name:"identity",encode:r=>zs(r),decode:r=>Fs(r)});var Ph=new TextEncoder,Oh=new TextDecoder;var eo={};gt(eo,{sha256:()=>Qe,sha512:()=>Tu});var Ru=20;function to({name:r,code:t,encode:e,minDigestLength:n,maxDigestLength:o}){return new Jn(r,t,e,n,o)}var Jn=class{name;code;encode;minDigestLength;maxDigestLength;constructor(t,e,n,o,s){this.name=t,this.code=e,this.encode=n,this.minDigestLength=o??Ru,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?oi(n,this.code,e?.truncate):n.then(o=>oi(o,this.code,e?.truncate))}else throw Error("Unknown type, must be binary type")}};function oi(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 Se(t,r)}function ii(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var Qe=to({name:"sha2-256",code:18,encode:ii("SHA-256")}),Tu=to({name:"sha2-512",code:19,encode:ii("SHA-512")});var Je={...Qn,...Zn,...Wn,...$n,...Gn,...qn,...Fn,...Kn,...jn,...Xn},Gh={...eo,...Hn};function ci(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var ai=ci("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),ro=ci("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}),Cu={utf8:ai,"utf-8":ai,hex:Je.base16,latin1:ro,ascii:ro,binary:ro,...Je},Or=Cu;function H(r,t="utf8"){let e=Or[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.decoder.decode(`${e.prefix}${r}`)}function W(r,t="utf8"){let e=Or[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.encoder.encode(r).substring(1)}var Pu=parseInt("11111",2),no=parseInt("10000000",2),Ou=parseInt("01111111",2),ui={0:tr,1:tr,2:ku,3:Mu,4:Ku,5:Uu,6:Nu,16:tr,22:tr,48:tr};function oo(r,t={offset:0}){let e=r[t.offset]&Pu;if(t.offset++,ui[e]!=null)return ui[e](r,t);throw new Error("No decoder for tag "+e)}function er(r,t){let e=0;if((r[t.offset]&no)===no){let n=r[t.offset]&Ou,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 tr(r,t){er(r,t);let e=[];for(;!(t.offset>=r.byteLength);){let n=oo(r,t);if(n===null)break;e.push(n)}return e}function ku(r,t){let e=er(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 Nu(r,t){let e=er(r,t),n=t.offset+e,o=r[t.offset];t.offset++;let s=0,i=0;o<40?(s=0,i=o):o<80?(s=1,i=o-40):(s=2,i=o-80);let a=`${s}.${i}`,c=[];for(;t.offset<n;){let u=r[t.offset];if(t.offset++,c.push(u&127),u<128){c.reverse();let l=0;for(let f=0;f<c.length;f++)l+=c[f]<<f*7;a+=`.${l}`,c=[]}}return a}function Uu(r,t){return t.offset++,null}function Mu(r,t){let e=er(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 Ku(r,t){let e=er(r,t),n=r.subarray(t.offset,t.offset+e);return t.offset+=e,n}function qu(r){let t=r.toString(16);t.length%2===1&&(t="0"+t);let e=new Q;for(let n=0;n<t.length;n+=2)e.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return e}function so(r){if(r.byteLength<128)return Uint8Array.from([r.byteLength]);let t=qu(r.byteLength);return new Q(Uint8Array.from([t.byteLength|no]),t)}function fi(r){let t=new Q,e=128;return(r.subarray()[0]&e)===e&&t.append(Uint8Array.from([0])),t.append(r),new Q(Uint8Array.from([2]),so(t),t)}function li(r){let t=Uint8Array.from([0]),e=new Q(t,r);return new Q(Uint8Array.from([3]),so(e),e)}function kr(r,t=48){let e=new Q;for(let n of r)e.append(n);return new Q(Uint8Array.from([t]),so(e),e)}async function di(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 Fu=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),zu=Uint8Array.from([6,5,43,129,4,0,34]),Vu=Uint8Array.from([6,5,43,129,4,0,35]),Hu={ext:!0,kty:"EC",crv:"P-256"},$u={ext:!0,kty:"EC",crv:"P-384"},Gu={ext:!0,kty:"EC",crv:"P-521"},io=32,ao=48,co=66;function hi(r){let t=oo(r);return pi(t)}function pi(r){let t=r[1][1][0],e=1,n,o;if(t.byteLength===io*2+1)return n=W(t.subarray(e,e+io),"base64url"),o=W(t.subarray(e+io),"base64url"),new ve({...Hu,key_ops:["verify"],x:n,y:o});if(t.byteLength===ao*2+1)return n=W(t.subarray(e,e+ao),"base64url"),o=W(t.subarray(e+ao),"base64url"),new ve({...$u,key_ops:["verify"],x:n,y:o});if(t.byteLength===co*2+1)return n=W(t.subarray(e,e+co),"base64url"),o=W(t.subarray(e+co),"base64url"),new ve({...Gu,key_ops:["verify"],x:n,y:o});throw new ft(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function mi(r){return kr([fi(Uint8Array.from([1])),kr([Zu(r.crv)],160),kr([li(new Q(Uint8Array.from([4]),H(r.x??"","base64url"),H(r.y??"","base64url")))],161)]).subarray()}function Zu(r){if(r==="P-256")return Fu;if(r==="P-384")return zu;if(r==="P-521")return Vu;throw new ft(`Invalid curve ${r}`)}var ve=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=mi(this.jwk)),this._raw}toMultihash(){return _t.digest(_e(this))}toCID(){return it.createV1(114,this.toMultihash())}toString(){return Y.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 di(this.jwk,e,t,n)}};function re(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function Lt(r,t=""){if(!Number.isSafeInteger(r)||r<0){let e=t&&`"${t}" `;throw new Error(`${e}expected integer >= 0, got ${r}`)}}function N(r,t,e=""){let n=re(r),o=r?.length,s=t!==void 0;if(!n||s&&o!==t){let i=e&&`"${e}" `,a=s?` of length ${t}`:"",c=n?`length=${o}`:`type=${typeof r}`;throw new Error(i+"expected Uint8Array"+a+", got "+c)}return r}function Nr(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash must wrapped by utils.createHasher");Lt(r.outputLen),Lt(r.blockLen)}function Ae(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 bi(r,t){N(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 kt(...r){for(let t=0;t<r.length;t++)r[t].fill(0)}function Ur(r){return new DataView(r.buffer,r.byteOffset,r.byteLength)}function At(r,t){return r<<32-t|r>>>t}var yi=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Xu=Array.from({length:256},(r,t)=>t.toString(16).padStart(2,"0"));function Nt(r){if(N(r),yi)return r.toHex();let t="";for(let e=0;e<r.length;e++)t+=Xu[r[e]];return t}var Ot={_0:48,_9:57,A:65,F:70,a:97,f:102};function gi(r){if(r>=Ot._0&&r<=Ot._9)return r-Ot._0;if(r>=Ot.A&&r<=Ot.F)return r-(Ot.A-10);if(r>=Ot.a&&r<=Ot.f)return r-(Ot.a-10)}function Ut(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);if(yi)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=gi(r.charCodeAt(s)),a=gi(r.charCodeAt(s+1));if(i===void 0||a===void 0){let c=r[s]+r[s+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+s)}n[o]=i*16+a}return n}function pt(...r){let t=0;for(let n=0;n<r.length;n++){let o=r[n];N(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 uo(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 Ie(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 fo=r=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,r])});function xi(r,t,e){return r&t^~r&e}function wi(r,t,e){return r&t^r&e^t&e}var rr=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=Ur(this.buffer)}update(t){Ae(this),N(t);let{view:e,buffer:n,blockLen:o}=this,s=t.length;for(let i=0;i<s;){let a=Math.min(o-this.pos,s-i);if(a===o){let c=Ur(t);for(;o<=s-i;i+=o)this.process(c,i);continue}n.set(t.subarray(i,i+a),this.pos),this.pos+=a,i+=a,this.pos===o&&(this.process(e,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){Ae(this),bi(t,this),this.finished=!0;let{buffer:e,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;e[i++]=128,kt(this.buffer.subarray(i)),this.padOffset>o-i&&(this.process(n,0),i=0);for(let f=i;f<o;f++)e[f]=0;n.setBigUint64(o-8,BigInt(this.length*8),s),this.process(n,0);let a=Ur(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen must be aligned to 32bit");let u=c/4,l=this.get();if(u>l.length)throw new Error("_sha2: outputLen bigger than state");for(let f=0;f<u;f++)a.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:a}=this;return t.destroyed=i,t.finished=s,t.length=o,t.pos=a,o%e&&t.buffer.set(n),t}clone(){return this._cloneInto()}},Mt=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var nt=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var Mr=BigInt(4294967295),Ei=BigInt(32);function Yu(r,t=!1){return t?{h:Number(r&Mr),l:Number(r>>Ei&Mr)}:{h:Number(r>>Ei&Mr)|0,l:Number(r&Mr)|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:a}=Yu(r[s],t);[n[s],o[s]]=[i,a]}return[n,o]}var lo=(r,t,e)=>r>>>e,ho=(r,t,e)=>r<<32-e|t>>>e,ne=(r,t,e)=>r>>>e|t<<32-e,oe=(r,t,e)=>r<<32-e|t>>>e,nr=(r,t,e)=>r<<64-e|t>>>e-32,or=(r,t,e)=>r>>>e-32|t<<64-e;function Rt(r,t,e,n){let o=(t>>>0)+(n>>>0);return{h:r+e+(o/2**32|0)|0,l:o|0}}var vi=(r,t,e)=>(r>>>0)+(t>>>0)+(e>>>0),_i=(r,t,e,n)=>t+e+n+(r/2**32|0)|0,Ai=(r,t,e,n)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0),Ii=(r,t,e,n,o)=>t+e+n+o+(r/2**32|0)|0,Bi=(r,t,e,n,o)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0)+(o>>>0),Di=(r,t,e,n,o,s)=>t+e+n+o+s+(r/2**32|0)|0;var Wu=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]),Gt=new Uint32Array(64),po=class extends rr{constructor(t){super(64,t,8,!1)}get(){let{A:t,B:e,C:n,D:o,E:s,F:i,G:a,H:c}=this;return[t,e,n,o,s,i,a,c]}set(t,e,n,o,s,i,a,c){this.A=t|0,this.B=e|0,this.C=n|0,this.D=o|0,this.E=s|0,this.F=i|0,this.G=a|0,this.H=c|0}process(t,e){for(let f=0;f<16;f++,e+=4)Gt[f]=t.getUint32(e,!1);for(let f=16;f<64;f++){let d=Gt[f-15],p=Gt[f-2],h=At(d,7)^At(d,18)^d>>>3,v=At(p,17)^At(p,19)^p>>>10;Gt[f]=v+Gt[f-7]+h+Gt[f-16]|0}let{A:n,B:o,C:s,D:i,E:a,F:c,G:u,H:l}=this;for(let f=0;f<64;f++){let d=At(a,6)^At(a,11)^At(a,25),p=l+d+xi(a,c,u)+Wu[f]+Gt[f]|0,v=(At(n,2)^At(n,13)^At(n,22))+wi(n,o,s)|0;l=u,u=c,c=a,a=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,a=a+this.E|0,c=c+this.F|0,u=u+this.G|0,l=l+this.H|0,this.set(n,o,s,i,a,c,u,l)}roundClean(){kt(Gt)}destroy(){this.set(0,0,0,0,0,0,0,0),kt(this.buffer)}},mo=class extends po{A=Mt[0]|0;B=Mt[1]|0;C=Mt[2]|0;D=Mt[3]|0;E=Mt[4]|0;F=Mt[5]|0;G=Mt[6]|0;H=Mt[7]|0;constructor(){super(32)}};var Li=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))),Qu=Li[0],Ju=Li[1],Zt=new Uint32Array(80),Xt=new Uint32Array(80),go=class extends rr{constructor(t){super(128,t,16,!1)}get(){let{Ah:t,Al:e,Bh:n,Bl:o,Ch:s,Cl:i,Dh:a,Dl:c,Eh:u,El:l,Fh:f,Fl:d,Gh:p,Gl:h,Hh:v,Hl:x}=this;return[t,e,n,o,s,i,a,c,u,l,f,d,p,h,v,x]}set(t,e,n,o,s,i,a,c,u,l,f,d,p,h,v,x){this.Ah=t|0,this.Al=e|0,this.Bh=n|0,this.Bl=o|0,this.Ch=s|0,this.Cl=i|0,this.Dh=a|0,this.Dl=c|0,this.Eh=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=x|0}process(t,e){for(let w=0;w<16;w++,e+=4)Zt[w]=t.getUint32(e),Xt[w]=t.getUint32(e+=4);for(let w=16;w<80;w++){let I=Zt[w-15]|0,P=Xt[w-15]|0,U=ne(I,P,1)^ne(I,P,8)^lo(I,P,7),M=oe(I,P,1)^oe(I,P,8)^ho(I,P,7),S=Zt[w-2]|0,E=Xt[w-2]|0,O=ne(S,E,19)^nr(S,E,61)^lo(S,E,6),K=oe(S,E,19)^or(S,E,61)^ho(S,E,6),R=Ai(M,K,Xt[w-7],Xt[w-16]),g=Ii(R,U,O,Zt[w-7],Zt[w-16]);Zt[w]=g|0,Xt[w]=R|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:a,Cl:c,Dh:u,Dl:l,Eh:f,El:d,Fh:p,Fl:h,Gh:v,Gl:x,Hh:y,Hl:A}=this;for(let w=0;w<80;w++){let I=ne(f,d,14)^ne(f,d,18)^nr(f,d,41),P=oe(f,d,14)^oe(f,d,18)^or(f,d,41),U=f&p^~f&v,M=d&h^~d&x,S=Bi(A,P,M,Ju[w],Xt[w]),E=Di(S,y,I,U,Qu[w],Zt[w]),O=S|0,K=ne(n,o,28)^nr(n,o,34)^nr(n,o,39),R=oe(n,o,28)^or(n,o,34)^or(n,o,39),g=n&s^n&a^s&a,b=o&i^o&c^i&c;y=v|0,A=x|0,v=p|0,x=h|0,p=f|0,h=d|0,{h:f,l:d}=Rt(u|0,l|0,E|0,O|0),u=a|0,l=c|0,a=s|0,c=i|0,s=n|0,i=o|0;let m=vi(O,R,b);n=_i(m,E,K,g),o=m|0}({h:n,l:o}=Rt(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=Rt(this.Bh|0,this.Bl|0,s|0,i|0),{h:a,l:c}=Rt(this.Ch|0,this.Cl|0,a|0,c|0),{h:u,l}=Rt(this.Dh|0,this.Dl|0,u|0,l|0),{h:f,l:d}=Rt(this.Eh|0,this.El|0,f|0,d|0),{h:p,l:h}=Rt(this.Fh|0,this.Fl|0,p|0,h|0),{h:v,l:x}=Rt(this.Gh|0,this.Gl|0,v|0,x|0),{h:y,l:A}=Rt(this.Hh|0,this.Hl|0,y|0,A|0),this.set(n,o,s,i,a,c,u,l,f,d,p,h,v,x,y,A)}roundClean(){kt(Zt,Xt)}destroy(){kt(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},bo=class extends go{Ah=nt[0]|0;Al=nt[1]|0;Bh=nt[2]|0;Bl=nt[3]|0;Ch=nt[4]|0;Cl=nt[5]|0;Dh=nt[6]|0;Dl=nt[7]|0;Eh=nt[8]|0;El=nt[9]|0;Fh=nt[10]|0;Fl=nt[11]|0;Gh=nt[12]|0;Gl=nt[13]|0;Hh=nt[14]|0;Hl=nt[15]|0;constructor(){super(64)}};var Ri=uo(()=>new mo,fo(1));var Ti=uo(()=>new bo,fo(3));var xo=BigInt(0),yo=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 Ci(r){if(typeof r=="bigint"){if(!Kr(r))throw new Error("positive bigint expected, got "+r)}else Lt(r);return r}function sr(r){let t=Ci(r).toString(16);return t.length&1?"0"+t:t}function Pi(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return r===""?xo:BigInt("0x"+r)}function Be(r){return Pi(Nt(r))}function se(r){return Pi(Nt(Fr(N(r)).reverse()))}function qr(r,t){Lt(t),r=Ci(r);let e=Ut(r.toString(16).padStart(t*2,"0"));if(e.length!==t)throw new Error("number too large");return e}function wo(r,t){return qr(r,t).reverse()}function Fr(r){return Uint8Array.from(r)}var Kr=r=>typeof r=="bigint"&&xo<=r;function tf(r,t,e){return Kr(r)&&Kr(t)&&Kr(e)&&t<=r&&r<e}function ir(r,t,e,n){if(!tf(t,e,n))throw new Error("expected valid "+r+": "+e+" <= n < "+n+", got "+t)}function Eo(r){let t;for(t=0;r>xo;r>>=yo,t+=1);return t}var ar=r=>(yo<<BigInt(r))-yo;function Oi(r,t,e){if(Lt(r,"hashLen"),Lt(t,"qByteLen"),typeof e!="function")throw new Error("hmacFn must be a function");let n=x=>new Uint8Array(x),o=Uint8Array.of(),s=Uint8Array.of(0),i=Uint8Array.of(1),a=1e3,c=n(r),u=n(r),l=0,f=()=>{c.fill(1),u.fill(0),l=0},d=(...x)=>e(u,pt(c,...x)),p=(x=o)=>{u=d(s,x),c=d(),x.length!==0&&(u=d(i,x),c=d())},h=()=>{if(l++>=a)throw new Error("drbg: tried max amount of iterations");let x=0,y=[];for(;x<t;){c=d();let A=c.slice();y.push(A),x+=c.length}return pt(...y)};return(x,y)=>{f(),p(x);let A;for(;!(A=y(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,a){let c=r[s];if(a&&c===void 0)return;let u=typeof c;if(u!==i||c===null)throw new Error(`param "${s}" is invalid: expected ${i}, got ${u}`)}let o=(s,i)=>Object.entries(s).forEach(([a,c])=>n(a,c,i));o(t,!1),o(e,!0)}function De(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),J=BigInt(1),ie=BigInt(2),Ui=BigInt(3),Mi=BigInt(4),Ki=BigInt(5),ef=BigInt(7),qi=BigInt(8),rf=BigInt(9),Fi=BigInt(16);function j(r,t){let e=r%t;return e>=dt?e:t+e}function V(r,t,e){let n=r;for(;t-- >dt;)n*=n,n%=e;return n}function ki(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=j(r,t),n=t,o=dt,s=J,i=J,a=dt;for(;e!==dt;){let u=n/e,l=n%e,f=o-i*u,d=s-a*u;n=e,e=l,o=i,s=a,i=f,a=d}if(n!==J)throw new Error("invert: does not exist");return j(o,t)}function vo(r,t,e){if(!r.eql(r.sqr(t),e))throw new Error("Cannot find square root")}function zi(r,t){let e=(r.ORDER+J)/Mi,n=r.pow(t,e);return vo(r,n,t),n}function nf(r,t){let e=(r.ORDER-Ki)/qi,n=r.mul(t,ie),o=r.pow(n,e),s=r.mul(t,o),i=r.mul(r.mul(s,ie),o),a=r.mul(s,r.sub(i,r.ONE));return vo(r,a,t),a}function of(r){let t=Le(r),e=Vi(r),n=e(t,t.neg(t.ONE)),o=e(t,n),s=e(t,t.neg(n)),i=(r+ef)/Fi;return(a,c)=>{let u=a.pow(c,i),l=a.mul(u,n),f=a.mul(u,o),d=a.mul(u,s),p=a.eql(a.sqr(l),c),h=a.eql(a.sqr(f),c);u=a.cmov(u,l,p),l=a.cmov(d,f,h);let v=a.eql(a.sqr(l),c),x=a.cmov(u,l,v);return vo(a,x,c),x}}function Vi(r){if(r<Ui)throw new Error("sqrt is not defined for small field");let t=r-J,e=0;for(;t%ie===dt;)t/=ie,e++;let n=ie,o=Le(r);for(;Ni(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(e===1)return zi;let s=o.pow(n,t),i=(t+J)/ie;return function(c,u){if(c.is0(u))return u;if(Ni(c,u)!==1)throw new Error("Cannot find square root");let l=e,f=c.mul(c.ONE,s),d=c.pow(u,t),p=c.pow(u,i);for(;!c.eql(d,c.ONE);){if(c.is0(d))return c.ZERO;let h=1,v=c.sqr(d);for(;!c.eql(v,c.ONE);)if(h++,v=c.sqr(v),h===l)throw new Error("Cannot find square root");let x=J<<BigInt(l-h-1),y=c.pow(f,x);l=h,f=c.sqr(y),d=c.mul(d,f),p=c.mul(p,y)}return p}}function sf(r){return r%Mi===Ui?zi:r%qi===Ki?nf:r%Fi===rf?of(r):Vi(r)}var Hi=(r,t)=>(j(r,t)&J)===J,af=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function _o(r){let t={ORDER:"bigint",BYTES:"number",BITS:"number"},e=af.reduce((n,o)=>(n[o]="function",n),t);return Yt(r,e),r}function cf(r,t,e){if(e<dt)throw new Error("invalid exponent, negatives unsupported");if(e===dt)return r.ONE;if(e===J)return t;let n=r.ONE,o=t;for(;e>dt;)e&J&&(n=r.mul(n,o)),o=r.sqr(o),e>>=J;return n}function cr(r,t,e=!1){let n=new Array(t.length).fill(e?r.ZERO:void 0),o=t.reduce((i,a,c)=>r.is0(a)?i:(n[c]=i,r.mul(i,a)),r.ONE),s=r.inv(o);return t.reduceRight((i,a,c)=>r.is0(a)?i:(n[c]=r.mul(i,n[c]),r.mul(i,a)),s),n}function Ni(r,t){let e=(r.ORDER-J)/ie,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 uf(r,t){t!==void 0&&Lt(t);let e=t!==void 0?t:r.toString(2).length,n=Math.ceil(e/8);return{nBitLength:e,nByteLength:n}}var So=class{ORDER;BITS;BYTES;isLE;ZERO=dt;ONE=J;_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}=uf(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 j(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&J)===J}neg(t){return j(-t,this.ORDER)}eql(t,e){return t===e}sqr(t){return j(t*t,this.ORDER)}add(t,e){return j(t+e,this.ORDER)}sub(t,e){return j(t-e,this.ORDER)}mul(t,e){return j(t*e,this.ORDER)}pow(t,e){return cf(this,t,e)}div(t,e){return j(t*ki(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 ki(t,this.ORDER)}sqrt(t){return this._sqrt||(this._sqrt=sf(this.ORDER)),this._sqrt(this,t)}toBytes(t){return this.isLE?wo(t,this.BYTES):qr(t,this.BYTES)}fromBytes(t,e=!1){N(t);let{_lengths:n,BYTES:o,isLE:s,ORDER:i,_mod:a}=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 c=s?se(t):Be(t);if(a&&(c=j(c,i)),!e&&!this.isValid(c))throw new Error("invalid field element: outside of range 0..ORDER");return c}invertBatch(t){return cr(this,t)}cmov(t,e,n){return n?e:t}};function Le(r,t={}){return new So(r,t)}function $i(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 Ao(r){let t=$i(r);return t+Math.ceil(t/2)}function Io(r,t,e=!1){N(r);let n=r.length,o=$i(t),s=Ao(t);if(n<16||n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=e?se(r):Be(r),a=j(i,t-J)+J;return e?wo(a,o):qr(a,o)}var Re=BigInt(0),ae=BigInt(1);function ur(r,t){let e=t.negate();return r?e:t}function ce(r,t){let e=cr(r.Fp,t.map(n=>n.Z));return t.map((n,o)=>r.fromAffine(n.toAffine(e[o])))}function Yi(r,t){if(!Number.isSafeInteger(r)||r<=0||r>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+r)}function Bo(r,t){Yi(r,t);let e=Math.ceil(t/r)+1,n=2**(r-1),o=2**r,s=ar(r),i=BigInt(r);return{windows:e,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function Gi(r,t,e){let{windowSize:n,mask:o,maxNumber:s,shiftBy:i}=e,a=Number(r&o),c=r>>i;a>n&&(a-=s,c+=ae);let u=t*n,l=u+Math.abs(a)-1,f=a===0,d=a<0,p=t%2!==0;return{nextN:c,offset:l,isZero:f,isNeg:d,isNegF:p,offsetF:u}}var Do=new WeakMap,ji=new WeakMap;function Lo(r){return ji.get(r)||1}function Zi(r){if(r!==Re)throw new Error("invalid wNAF")}var Te=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>Re;)e&ae&&(n=n.add(o)),o=o.double(),e>>=ae;return n}precomputeWindow(t,e){let{windows:n,windowSize:o}=Bo(e,this.bits),s=[],i=t,a=i;for(let c=0;c<n;c++){a=i,s.push(a);for(let u=1;u<o;u++)a=a.add(i),s.push(a);i=a.double()}return s}wNAF(t,e,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let o=this.ZERO,s=this.BASE,i=Bo(t,this.bits);for(let a=0;a<i.windows;a++){let{nextN:c,offset:u,isZero:l,isNeg:f,isNegF:d,offsetF:p}=Gi(n,a,i);n=c,l?s=s.add(ur(d,e[p])):o=o.add(ur(f,e[u]))}return Zi(n),{p:o,f:s}}wNAFUnsafe(t,e,n,o=this.ZERO){let s=Bo(t,this.bits);for(let i=0;i<s.windows&&n!==Re;i++){let{nextN:a,offset:c,isZero:u,isNeg:l}=Gi(n,i,s);if(n=a,!u){let f=e[c];o=o.add(l?f.negate():f)}}return Zi(n),o}getPrecomputes(t,e,n){let o=Do.get(e);return o||(o=this.precomputeWindow(e,t),t!==1&&(typeof n=="function"&&(o=n(o)),Do.set(e,o))),o}cached(t,e,n){let o=Lo(t);return this.wNAF(o,this.getPrecomputes(o,t,n),e)}unsafe(t,e,n,o){let s=Lo(t);return s===1?this._unsafeLadder(t,e,o):this.wNAFUnsafe(s,this.getPrecomputes(s,t,n),e,o)}createCache(t,e){Yi(e,this.bits),ji.set(t,e),Do.delete(t)}hasCache(t){return Lo(t)!==1}};function Wi(r,t,e,n){let o=t,s=r.ZERO,i=r.ZERO;for(;e>Re||n>Re;)e&ae&&(s=s.add(o)),n&ae&&(i=i.add(o)),o=o.double(),e>>=ae,n>>=ae;return{p1:s,p2:i}}function Xi(r,t,e){if(t){if(t.ORDER!==r)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return _o(t),t}else return Le(r,{isLE:e})}function zr(r,t,e={},n){if(n===void 0&&(n=r==="edwards"),!t||typeof t!="object")throw new Error(`expected valid ${r} CURVE object`);for(let c of["p","n","h"]){let u=t[c];if(!(typeof u=="bigint"&&u>Re))throw new Error(`CURVE.${c} must be positive bigint`)}let o=Xi(t.p,e.Fp,n),s=Xi(t.n,e.Fn,n),a=["Gx","Gy","a",r==="weierstrass"?"b":"d"];for(let c of a)if(!o.isValid(t[c]))throw new Error(`CURVE.${c} must be valid field element of CURVE.Fp`);return t=Object.freeze(Object.assign({},t)),{CURVE:t,Fp:o,Fn:s}}function Vr(r,t){return function(n){let o=r(n);return{secretKey:o,publicKey:t(o)}}}var jt=BigInt(0),tt=BigInt(1),Ro=BigInt(2),ff=BigInt(8);function lf(r,t,e,n){let o=r.sqr(e),s=r.sqr(n),i=r.add(r.mul(t.a,o),s),a=r.add(r.ONE,r.mul(t.d,r.mul(o,s)));return r.eql(i,a)}function Qi(r,t={}){let e=zr("edwards",r,t,t.FpFnLE),{Fp:n,Fn:o}=e,s=e.CURVE,{h:i}=s;Yt(t,{},{uvRatio:"function"});let a=Ro<<BigInt(o.BYTES*8)-tt,c=x=>n.create(x),u=t.uvRatio||((x,y)=>{try{return{isValid:!0,value:n.sqrt(n.div(x,y))}}catch{return{isValid:!1,value:jt}}});if(!lf(n,s,s.Gx,s.Gy))throw new Error("bad curve params: generator point");function l(x,y,A=!1){let w=A?tt:jt;return ir("coordinate "+x,y,w,a),y}function f(x){if(!(x instanceof h))throw new Error("EdwardsPoint expected")}let d=De((x,y)=>{let{X:A,Y:w,Z:I}=x,P=x.is0();y==null&&(y=P?ff:n.inv(I));let U=c(A*y),M=c(w*y),S=n.mul(I,y);if(P)return{x:jt,y:tt};if(S!==tt)throw new Error("invZ was invalid");return{x:U,y:M}}),p=De(x=>{let{a:y,d:A}=s;if(x.is0())throw new Error("bad point: ZERO");let{X:w,Y:I,Z:P,T:U}=x,M=c(w*w),S=c(I*I),E=c(P*P),O=c(E*E),K=c(M*y),R=c(E*c(K+S)),g=c(O+c(A*c(M*S)));if(R!==g)throw new Error("bad point: equation left != right (1)");let b=c(w*I),m=c(P*U);if(b!==m)throw new Error("bad point: equation left != right (2)");return!0});class h{static BASE=new h(s.Gx,s.Gy,tt,c(s.Gx*s.Gy));static ZERO=new h(jt,tt,tt,jt);static Fp=n;static Fn=o;X;Y;Z;T;constructor(y,A,w,I){this.X=l("x",y),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(y){if(y instanceof h)throw new Error("extended point not allowed");let{x:A,y:w}=y||{};return l("x",A),l("y",w),new h(A,w,tt,c(A*w))}static fromBytes(y,A=!1){let w=n.BYTES,{a:I,d:P}=s;y=Fr(N(y,w,"point")),Kt(A,"zip215");let U=Fr(y),M=y[w-1];U[w-1]=M&-129;let S=se(U),E=A?a:n.ORDER;ir("point.y",S,jt,E);let O=c(S*S),K=c(O-tt),R=c(P*O-I),{isValid:g,value:b}=u(K,R);if(!g)throw new Error("bad point: invalid y coordinate");let m=(b&tt)===tt,_=(M&128)!==0;if(!A&&b===jt&&_)throw new Error("bad point: x=0 and x_0=1");return _!==m&&(b=c(-b)),h.fromAffine({x:b,y:S})}static fromHex(y,A=!1){return h.fromBytes(Ut(y),A)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(y=8,A=!0){return v.createCache(this,y),A||this.multiply(Ro),this}assertValidity(){p(this)}equals(y){f(y);let{X:A,Y:w,Z:I}=this,{X:P,Y:U,Z:M}=y,S=c(A*M),E=c(P*I),O=c(w*M),K=c(U*I);return S===E&&O===K}is0(){return this.equals(h.ZERO)}negate(){return new h(c(-this.X),this.Y,this.Z,c(-this.T))}double(){let{a:y}=s,{X:A,Y:w,Z:I}=this,P=c(A*A),U=c(w*w),M=c(Ro*c(I*I)),S=c(y*P),E=A+w,O=c(c(E*E)-P-U),K=S+U,R=K-M,g=S-U,b=c(O*R),m=c(K*g),_=c(O*g),B=c(R*K);return new h(b,m,B,_)}add(y){f(y);let{a:A,d:w}=s,{X:I,Y:P,Z:U,T:M}=this,{X:S,Y:E,Z:O,T:K}=y,R=c(I*S),g=c(P*E),b=c(M*w*K),m=c(U*O),_=c((I+P)*(S+E)-R-g),B=m-b,L=m+b,T=c(g-A*R),D=c(_*B),C=c(L*T),k=c(_*T),$=c(B*L);return new h(D,C,$,k)}subtract(y){return this.add(y.negate())}multiply(y){if(!o.isValidNot0(y))throw new Error("invalid scalar: expected 1 <= sc < curve.n");let{p:A,f:w}=v.cached(this,y,I=>ce(h,I));return ce(h,[A,w])[0]}multiplyUnsafe(y,A=h.ZERO){if(!o.isValid(y))throw new Error("invalid scalar: expected 0 <= sc < curve.n");return y===jt?h.ZERO:this.is0()||y===tt?this:v.unsafe(this,y,w=>ce(h,w),A)}isSmallOrder(){return this.multiplyUnsafe(i).is0()}isTorsionFree(){return v.unsafe(this,s.n).is0()}toAffine(y){return d(this,y)}clearCofactor(){return i===tt?this:this.multiplyUnsafe(i)}toBytes(){let{x:y,y:A}=this.toAffine(),w=n.toBytes(A);return w[w.length-1]|=y&tt?128:0,w}toHex(){return Nt(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let v=new Te(h,o.BITS);return h.BASE.precompute(8),h}function Ji(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,a=e.randomBytes||Ie,c=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(se(S))}function f(S){let E=w.secretKey;N(S,w.secretKey,"secretKey");let O=N(t(S),2*E,"hashedSecretKey"),K=c(O.slice(0,E)),R=O.slice(E,2*E),g=l(K);return{head:K,prefix:R,scalar:g}}function d(S){let{head:E,prefix:O,scalar:K}=f(S),R=o.multiply(K),g=R.toBytes();return{head:E,prefix:O,scalar:K,point:R,pointBytes:g}}function p(S){return d(S).pointBytes}function h(S=Uint8Array.of(),...E){let O=pt(...E);return l(t(u(O,N(S,void 0,"context"),!!n)))}function v(S,E,O={}){S=N(S,void 0,"message"),n&&(S=n(S));let{prefix:K,scalar:R,pointBytes:g}=d(E),b=h(O.context,K,S),m=o.multiply(b).toBytes(),_=h(O.context,m,g,S),B=i.create(b+_*R);if(!i.isValid(B))throw new Error("sign failed: invalid s");let L=pt(m,i.toBytes(B));return N(L,w.signature,"result")}let x={zip215:!0};function y(S,E,O,K=x){let{context:R,zip215:g}=K,b=w.signature;S=N(S,b,"signature"),E=N(E,void 0,"message"),O=N(O,w.publicKey,"publicKey"),g!==void 0&&Kt(g,"zip215"),n&&(E=n(E));let m=b/2,_=S.subarray(0,m),B=se(S.subarray(m,b)),L,T,D;try{L=r.fromBytes(O,g),T=r.fromBytes(_,g),D=o.multiplyUnsafe(B)}catch{return!1}if(!g&&L.isSmallOrder())return!1;let C=h(R,T.toBytes(),L.toBytes(),E);return T.add(L.multiplyUnsafe(C)).subtract(D).clearCofactor().is0()}let A=s.BYTES,w={secretKey:A,publicKey:A,signature:2*A,seed:A};function I(S=a(w.seed)){return N(S,w.seed,"seed")}function P(S){return re(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 R=K?s.div(tt+E,tt-E):s.div(E-tt,E+tt);return s.toBytes(R)},toMontgomerySecret(S){let E=w.secretKey;N(S,E);let O=t(S.subarray(0,E));return c(O).subarray(0,E)}};return Object.freeze({keygen:Vr(I,p),getPublicKey:p,sign:v,verify:y,utils:M,Point:r,lengths:w})}var df=BigInt(1),ta=BigInt(2);var hf=BigInt(5),pf=BigInt(8),To=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),mf={p:To,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:pf,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function gf(r){let t=BigInt(10),e=BigInt(20),n=BigInt(40),o=BigInt(80),s=To,a=r*r%s*r%s,c=V(a,ta,s)*a%s,u=V(c,df,s)*r%s,l=V(u,hf,s)*u%s,f=V(l,t,s)*l%s,d=V(f,e,s)*f%s,p=V(d,n,s)*d%s,h=V(p,o,s)*p%s,v=V(h,o,s)*p%s,x=V(v,t,s)*l%s;return{pow_p_5_8:V(x,ta,s)*r%s,b2:a}}function bf(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}var ea=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function yf(r,t){let e=To,n=j(t*t*t,e),o=j(n*n*t,e),s=gf(r*o).pow_p_5_8,i=j(r*n*s,e),a=j(t*i*i,e),c=i,u=j(i*ea,e),l=a===r,f=a===j(-r,e),d=a===j(-r*ea,e);return l&&(i=c),(f||d)&&(i=u),Hi(i,e)&&(i=j(-i,e)),{isValid:l||f,value:i}}var xf=Qi(mf,{uvRatio:yf});function wf(r){return Ji(xf,Ti,Object.assign({adjustScalarBytes:bf},r))}var ra=wf({});var fr=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},Hr=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var na={get(r=globalThis){let t=r.crypto;if(t?.subtle==null)throw new Hr("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 $r=na;var Gr=32;var Co,Ef=(async()=>{try{return await $r.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function Sf(r,t,e){if(r.buffer instanceof ArrayBuffer){let n=await $r.get().subtle.importKey("raw",r.buffer,{name:"Ed25519"},!1,["verify"]);return await $r.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 vf(r,t,e){return ra.verify(t,e instanceof Uint8Array?e:e.subarray(),r)}async function oa(r,t,e){return Co==null&&(Co=await Ef),Co?Sf(r,t,e):vf(r,t,e)}function Zr(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}var Xr=class{type="Ed25519";raw;constructor(t){this.raw=Po(t,Gr)}toMultihash(){return _t.digest(_e(this))}toCID(){return it.createV1(114,this.toMultihash())}toString(){return Y.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=oa(this.raw,e,t);return Zr(o)?o.then(s=>(n?.signal?.throwIfAborted(),s)):o}};function ia(r){return r=Po(r,Gr),new Xr(r)}function Po(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 Af=Math.pow(2,7),If=Math.pow(2,14),Bf=Math.pow(2,21),Oo=Math.pow(2,28),ko=Math.pow(2,35),No=Math.pow(2,42),Uo=Math.pow(2,49),F=128,at=127;function mt(r){if(r<Af)return 1;if(r<If)return 2;if(r<Bf)return 3;if(r<Oo)return 4;if(r<ko)return 5;if(r<No)return 6;if(r<Uo)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Ce(r,t,e=0){switch(mt(r)){case 8:t[e++]=r&255|F,r/=128;case 7:t[e++]=r&255|F,r/=128;case 6:t[e++]=r&255|F,r/=128;case 5:t[e++]=r&255|F,r/=128;case 4:t[e++]=r&255|F,r>>>=7;case 3:t[e++]=r&255|F,r>>>=7;case 2:t[e++]=r&255|F,r>>>=7;case 1:{t[e++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return t}function Df(r,t,e=0){switch(mt(r)){case 8:t.set(e++,r&255|F),r/=128;case 7:t.set(e++,r&255|F),r/=128;case 6:t.set(e++,r&255|F),r/=128;case 5:t.set(e++,r&255|F),r/=128;case 4:t.set(e++,r&255|F),r>>>=7;case 3:t.set(e++,r&255|F),r>>>=7;case 2:t.set(e++,r&255|F),r>>>=7;case 1:{t.set(e++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return t}function Mo(r,t){let e=r[t],n=0;if(n+=e&at,e<F||(e=r[t+1],n+=(e&at)<<7,e<F)||(e=r[t+2],n+=(e&at)<<14,e<F)||(e=r[t+3],n+=(e&at)<<21,e<F)||(e=r[t+4],n+=(e&at)*Oo,e<F)||(e=r[t+5],n+=(e&at)*ko,e<F)||(e=r[t+6],n+=(e&at)*No,e<F)||(e=r[t+7],n+=(e&at)*Uo,e<F))return n;throw new RangeError("Could not decode varint")}function Lf(r,t){let e=r.get(t),n=0;if(n+=e&at,e<F||(e=r.get(t+1),n+=(e&at)<<7,e<F)||(e=r.get(t+2),n+=(e&at)<<14,e<F)||(e=r.get(t+3),n+=(e&at)<<21,e<F)||(e=r.get(t+4),n+=(e&at)*Oo,e<F)||(e=r.get(t+5),n+=(e&at)*ko,e<F)||(e=r.get(t+6),n+=(e&at)*No,e<F)||(e=r.get(t+7),n+=(e&at)*Uo,e<F))return n;throw new RangeError("Could not decode varint")}function aa(r,t,e=0){return t==null&&(t=ht(mt(r))),t instanceof Uint8Array?Ce(r,t,e):Df(r,t,e)}function lr(r,t=0){return r instanceof Uint8Array?Mo(r,t):Lf(r,t)}var Ko=new Float32Array([-0]),Wt=new Uint8Array(Ko.buffer);function ua(r,t,e){Ko[0]=r,t[e]=Wt[0],t[e+1]=Wt[1],t[e+2]=Wt[2],t[e+3]=Wt[3]}function fa(r,t){return Wt[0]=r[t],Wt[1]=r[t+1],Wt[2]=r[t+2],Wt[3]=r[t+3],Ko[0]}var qo=new Float64Array([-0]),ct=new Uint8Array(qo.buffer);function la(r,t,e){qo[0]=r,t[e]=ct[0],t[e+1]=ct[1],t[e+2]=ct[2],t[e+3]=ct[3],t[e+4]=ct[4],t[e+5]=ct[5],t[e+6]=ct[6],t[e+7]=ct[7]}function da(r,t){return ct[0]=r[t],ct[1]=r[t+1],ct[2]=r[t+2],ct[3]=r[t+3],ct[4]=r[t+4],ct[5]=r[t+5],ct[6]=r[t+6],ct[7]=r[t+7],qo[0]}var Rf=BigInt(Number.MAX_SAFE_INTEGER),Tf=BigInt(Number.MIN_SAFE_INTEGER),yt=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 ue;if(t<Rf&&t>Tf)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>ha&&(o=0n,++n>ha&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(t){if(t===0)return ue;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):ue}},ue=new yt(0,0);ue.toBigInt=function(){return 0n};ue.zzEncode=ue.zzDecode=function(){return this};ue.length=function(){return 1};var ha=4294967296n;function pa(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 ma(r,t,e){if(e-t<1)return"";let o,s=[],i=0,a;for(;t<e;)a=r[t++],a<128?s[i++]=a:a>191&&a<224?s[i++]=(a&31)<<6|r[t++]&63:a>239&&a<365?(a=((a&7)<<18|(r[t++]&63)<<12|(r[t++]&63)<<6|r[t++]&63)-65536,s[i++]=55296+(a>>10),s[i++]=56320+(a&1023)):s[i++]=(a&15)<<12|(r[t++]&63)<<6|r[t++]&63,i>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,s)),i=0);return o!=null?(i>0&&o.push(String.fromCharCode.apply(String,s.slice(0,i))),o.join("")):String.fromCharCode.apply(String,s.slice(0,i))}function Fo(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 It(r,t){return RangeError(`index out of range: ${r.pos} + ${t??1} > ${r.len}`)}function Yr(r,t){return(r[t-4]|r[t-3]<<8|r[t-2]<<16|r[t-1]<<24)>>>0}var zo=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,It(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 It(this,4);return Yr(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw It(this,4);return Yr(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw It(this,4);let t=fa(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw It(this,4);let t=da(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 It(this,t);return this.pos+=t,e===n?new Uint8Array(0):this.buf.subarray(e,n)}string(){let t=this.bytes();return ma(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw It(this,t);this.pos+=t}else do if(this.pos>=this.len)throw It(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 yt(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 It(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 It(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 It(this,8);let t=Yr(this.buf,this.pos+=4),e=Yr(this.buf,this.pos+=4);return new yt(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=Mo(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 Vo(r){return new zo(r instanceof Uint8Array?r:r.subarray())}function Et(r,t,e){let n=Vo(r);return t.decode(n,void 0,e)}function Ho(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 a=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),a}}var fe=class{fn;len;next;val;constructor(t,e,n){this.fn=t,this.len=e,this.next=void 0,this.val=n}};function $o(){}var Zo=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},Cf=Ho();function Pf(r){return globalThis.Buffer!=null?ht(r):Cf(r)}var hr=class{len;head;tail;states;constructor(){this.len=0,this.head=new fe($o,0,0),this.tail=this.head,this.states=null}_push(t,e,n){return this.tail=this.tail.next=new fe(t,e,n),this.len+=e,this}uint32(t){return this.len+=(this.tail=this.tail.next=new Xo((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(jr,10,yt.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let e=yt.fromBigInt(t);return this._push(jr,e.length(),e)}uint64Number(t){return this._push(Ce,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=yt.fromBigInt(t).zzEncode();return this._push(jr,e.length(),e)}sint64Number(t){let e=yt.fromNumber(t).zzEncode();return this._push(jr,e.length(),e)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(Go,1,t?1:0)}fixed32(t){return this._push(dr,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=yt.fromBigInt(t);return this._push(dr,4,e.lo)._push(dr,4,e.hi)}fixed64Number(t){let e=yt.fromNumber(t);return this._push(dr,4,e.lo)._push(dr,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(ua,4,t)}double(t){return this._push(la,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(Go,1,0):this.uint32(e)._push(kf,e,t)}string(t){let e=pa(t);return e!==0?this.uint32(e)._push(Fo,e,t):this._push(Go,1,0)}fork(){return this.states=new Zo(this),this.head=this.tail=new fe($o,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 fe($o,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=Pf(this.len),n=0;for(;t!=null;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e}};function Go(r,t,e){t[e]=r&255}function Of(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var Xo=class extends fe{next;constructor(t,e){super(Of,t,e),this.next=void 0}};function jr(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 dr(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 kf(r,t,e){t.set(r,e)}globalThis.Buffer!=null&&(hr.prototype.bytes=function(r){let t=r.length>>>0;return this.uint32(t),t>0&&this._push(Nf,t,r),this},hr.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(Uf,t,r),this});function Nf(r,t,e){t.set(r,e)}function Uf(r,t,e){r.length<40?Fo(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set(H(r),e)}function Yo(){return new hr}function St(r,t){let e=Yo();return t.encode(r,e,{lengthDelimited:!1}),e.finish()}var Pe;(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"})(Pe||(Pe={}));function Wr(r,t,e,n){return{name:r,type:t,encode:e,decode:n}}function le(r){function t(o){if(r[o.toString()]==null)throw new Error("Invalid enum value");return r[o]}let e=function(s,i){let a=t(s);i.int32(a)},n=function(s){let i=s.int32();return t(i)};return Wr("enum",Pe.VARINT,e,n)}function vt(r,t){return Wr("message",Pe.LENGTH_DELIMITED,r,t)}var Qr=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var xt;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.secp256k1="secp256k1",r.ECDSA="ECDSA"})(xt||(xt={}));var jo;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.secp256k1=2]="secp256k1",r[r.ECDSA=3]="ECDSA"})(jo||(jo={}));(function(r){r.codec=()=>le(jo)})(xt||(xt={}));var pr;(function(r){let t;r.codec=()=>(t==null&&(t=vt((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),xt.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 a=e.uint32();switch(a>>>3){case 1:{s.Type=xt.codec().decode(e);break}case 2:{s.Data=e.bytes();break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>St(e,r.codec()),r.decode=(e,n)=>Et(e,r.codec(),n)})(pr||(pr={}));var Wo;(function(r){let t;r.codec=()=>(t==null&&(t=vt((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),xt.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 a=e.uint32();switch(a>>>3){case 1:{s.Type=xt.codec().decode(e);break}case 2:{s.Data=e.bytes();break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>St(e,r.codec()),r.decode=(e,n)=>Et(e,r.codec(),n)})(Wo||(Wo={}));var Jr=class{oHash;iHash;blockLen;outputLen;finished=!1;destroyed=!1;constructor(t,e){if(Nr(t),N(e,void 0,"key"),this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let n=this.blockLen,o=new Uint8Array(n);o.set(e.length>n?t.create().update(e).digest():e);for(let s=0;s<o.length;s++)o[s]^=54;this.iHash.update(o),this.oHash=t.create();for(let s=0;s<o.length;s++)o[s]^=106;this.oHash.update(o),kt(o)}update(t){return Ae(this),this.iHash.update(t),this}digestInto(t){Ae(this),N(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:a}=this;return t=t,t.finished=o,t.destroyed=s,t.blockLen=i,t.outputLen=a,t.oHash=e._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},Qo=(r,t,e)=>new Jr(r,t).update(e).digest();Qo.create=(r,t)=>new Jr(r,t);var ba=(r,t)=>(r+(r>=0?t:-t)/ya)/t;function Kf(r,t,e){let[[n,o],[s,i]]=t,a=ba(i*r,e),c=ba(-o*r,e),u=r-a*n-c*s,l=-a*o-c*i,f=u<qt,d=l<qt;f&&(u=-u),d&&(l=-l);let p=ar(Math.ceil(Eo(e)/2))+Oe;if(u<qt||u>=p||l<qt||l>=p)throw new Error("splitScalar (endomorphism): failed, k="+r);return{k1neg:f,k1:u,k2neg:d,k2:l}}function ts(r){if(!["compact","recovered","der"].includes(r))throw new Error('Signature format must be "compact", "recovered", or "der"');return r}function Jo(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&&ts(e.format),e}var es=class extends Error{constructor(t=""){super(t)}},Qt={Err:es,_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=sr(n);if(o.length/2&128)throw new e("tlv.encode: long form length too big");let s=n>127?sr(o.length/2|128):"";return sr(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 c=o&127;if(!c)throw new e("tlv.decode(long): indefinite length not supported");if(c>4)throw new e("tlv.decode(long): byte length is too big");let u=t.subarray(n,n+c);if(u.length!==c)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+=c,i<128)throw new e("tlv.decode(long): not minimal encoding")}let a=t.subarray(n,n+i);if(a.length!==i)throw new e("tlv.decode: wrong value length");return{v:a,l:t.subarray(n+i)}}},_int:{encode(r){let{Err:t}=Qt;if(r<qt)throw new t("integer: negative integers are not allowed");let e=sr(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 Be(r)}},toSig(r){let{Err:t,_int:e,_tlv:n}=Qt,o=N(r,void 0,"signature"),{v:s,l:i}=n.decode(48,o);if(i.length)throw new t("invalid signature: left bytes after parsing");let{v:a,l:c}=n.decode(2,s),{v:u,l}=n.decode(2,c);if(l.length)throw new t("invalid signature: left bytes after parsing");return{r:e.decode(a),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)}},qt=BigInt(0),Oe=BigInt(1),ya=BigInt(2),tn=BigInt(3),qf=BigInt(4);function xa(r,t={}){let e=zr("weierstrass",r,t),{Fp:n,Fn:o}=e,s=e.CURVE,{h:i,n:a}=s;Yt(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object"});let{endo:c}=t;if(c&&(!n.is0(s.a)||typeof c.beta!="bigint"||!Array.isArray(c.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let u=Ea(n,o);function l(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function f(R,g,b){let{x:m,y:_}=g.toAffine(),B=n.toBytes(m);if(Kt(b,"isCompressed"),b){l();let L=!n.isOdd(_);return pt(wa(L),B)}else return pt(Uint8Array.of(4),B,n.toBytes(_))}function d(R){N(R,void 0,"Point");let{publicKey:g,publicKeyUncompressed:b}=u,m=R.length,_=R[0],B=R.subarray(1);if(m===g&&(_===2||_===3)){let L=n.fromBytes(B);if(!n.isValid(L))throw new Error("bad point: is not on curve, wrong x");let T=v(L),D;try{D=n.sqrt(T)}catch($){let z=$ instanceof Error?": "+$.message:"";throw new Error("bad point: is not on curve, sqrt error"+z)}l();let C=n.isOdd(D);return(_&1)===1!==C&&(D=n.neg(D)),{x:L,y:D}}else if(m===b&&_===4){let L=n.BYTES,T=n.fromBytes(B.subarray(0,L)),D=n.fromBytes(B.subarray(L,L*2));if(!x(T,D))throw new Error("bad point: is not on curve");return{x:T,y:D}}else throw new Error(`bad point: got length ${m}, expected compressed=${g} or uncompressed=${b}`)}let p=t.toBytes||f,h=t.fromBytes||d;function v(R){let g=n.sqr(R),b=n.mul(g,R);return n.add(n.add(b,n.mul(R,s.a)),s.b)}function x(R,g){let b=n.sqr(g),m=v(R);return n.eql(b,m)}if(!x(s.Gx,s.Gy))throw new Error("bad curve params: generator point");let y=n.mul(n.pow(s.a,tn),qf),A=n.mul(n.sqr(s.b),BigInt(27));if(n.is0(n.add(y,A)))throw new Error("bad curve params: a or b");function w(R,g,b=!1){if(!n.isValid(g)||b&&n.is0(g))throw new Error(`bad point coordinate ${R}`);return g}function I(R){if(!(R instanceof E))throw new Error("Weierstrass Point expected")}function P(R){if(!c||!c.basises)throw new Error("no endo");return Kf(R,c.basises,o.ORDER)}let U=De((R,g)=>{let{X:b,Y:m,Z:_}=R;if(n.eql(_,n.ONE))return{x:b,y:m};let B=R.is0();g==null&&(g=B?n.ONE:n.inv(_));let L=n.mul(b,g),T=n.mul(m,g),D=n.mul(_,g);if(B)return{x:n.ZERO,y:n.ZERO};if(!n.eql(D,n.ONE))throw new Error("invZ was invalid");return{x:L,y:T}}),M=De(R=>{if(R.is0()){if(t.allowInfinityPoint&&!n.is0(R.Y))return;throw new Error("bad point: ZERO")}let{x:g,y:b}=R.toAffine();if(!n.isValid(g)||!n.isValid(b))throw new Error("bad point: x or y not field elements");if(!x(g,b))throw new Error("bad point: equation left != right");if(!R.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function S(R,g,b,m,_){return b=new E(n.mul(b.X,R),b.Y,b.Z),g=ur(m,g),b=ur(_,b),g.add(b)}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(g,b,m){this.X=w("x",g),this.Y=w("y",b,!0),this.Z=w("z",m),Object.freeze(this)}static CURVE(){return s}static fromAffine(g){let{x:b,y:m}=g||{};if(!g||!n.isValid(b)||!n.isValid(m))throw new Error("invalid affine point");if(g instanceof E)throw new Error("projective point not allowed");return n.is0(b)&&n.is0(m)?E.ZERO:new E(b,m,n.ONE)}static fromBytes(g){let b=E.fromAffine(h(N(g,void 0,"point")));return b.assertValidity(),b}static fromHex(g){return E.fromBytes(Ut(g))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(g=8,b=!0){return K.createCache(this,g),b||this.multiply(tn),this}assertValidity(){M(this)}hasEvenY(){let{y:g}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(g)}equals(g){I(g);let{X:b,Y:m,Z:_}=this,{X:B,Y:L,Z:T}=g,D=n.eql(n.mul(b,T),n.mul(B,_)),C=n.eql(n.mul(m,T),n.mul(L,_));return D&&C}negate(){return new E(this.X,n.neg(this.Y),this.Z)}double(){let{a:g,b}=s,m=n.mul(b,tn),{X:_,Y:B,Z:L}=this,T=n.ZERO,D=n.ZERO,C=n.ZERO,k=n.mul(_,_),$=n.mul(B,B),z=n.mul(L,L),q=n.mul(_,B);return q=n.add(q,q),C=n.mul(_,L),C=n.add(C,C),T=n.mul(g,C),D=n.mul(m,z),D=n.add(T,D),T=n.sub($,D),D=n.add($,D),D=n.mul(T,D),T=n.mul(q,T),C=n.mul(m,C),z=n.mul(g,z),q=n.sub(k,z),q=n.mul(g,q),q=n.add(q,C),C=n.add(k,k),k=n.add(C,k),k=n.add(k,z),k=n.mul(k,q),D=n.add(D,k),z=n.mul(B,L),z=n.add(z,z),k=n.mul(z,q),T=n.sub(T,k),C=n.mul(z,$),C=n.add(C,C),C=n.add(C,C),new E(T,D,C)}add(g){I(g);let{X:b,Y:m,Z:_}=this,{X:B,Y:L,Z:T}=g,D=n.ZERO,C=n.ZERO,k=n.ZERO,$=s.a,z=n.mul(s.b,tn),q=n.mul(b,B),G=n.mul(m,L),rt=n.mul(_,T),Dt=n.add(b,m),Z=n.add(B,L);Dt=n.mul(Dt,Z),Z=n.add(q,G),Dt=n.sub(Dt,Z),Z=n.add(b,_);let st=n.add(B,T);return Z=n.mul(Z,st),st=n.add(q,rt),Z=n.sub(Z,st),st=n.add(m,_),D=n.add(L,T),st=n.mul(st,D),D=n.add(G,rt),st=n.sub(st,D),k=n.mul($,Z),D=n.mul(z,rt),k=n.add(D,k),D=n.sub(G,k),k=n.add(G,k),C=n.mul(D,k),G=n.add(q,q),G=n.add(G,q),rt=n.mul($,rt),Z=n.mul(z,Z),G=n.add(G,rt),rt=n.sub(q,rt),rt=n.mul($,rt),Z=n.add(Z,rt),q=n.mul(G,Z),C=n.add(C,q),q=n.mul(st,Z),D=n.mul(Dt,D),D=n.sub(D,q),q=n.mul(Dt,G),k=n.mul(st,k),k=n.add(k,q),new E(D,C,k)}subtract(g){return this.add(g.negate())}is0(){return this.equals(E.ZERO)}multiply(g){let{endo:b}=t;if(!o.isValidNot0(g))throw new Error("invalid scalar: out of range");let m,_,B=L=>K.cached(this,L,T=>ce(E,T));if(b){let{k1neg:L,k1:T,k2neg:D,k2:C}=P(g),{p:k,f:$}=B(T),{p:z,f:q}=B(C);_=$.add(q),m=S(b.beta,k,z,L,D)}else{let{p:L,f:T}=B(g);m=L,_=T}return ce(E,[m,_])[0]}multiplyUnsafe(g){let{endo:b}=t,m=this;if(!o.isValid(g))throw new Error("invalid scalar: out of range");if(g===qt||m.is0())return E.ZERO;if(g===Oe)return m;if(K.hasCache(this))return this.multiply(g);if(b){let{k1neg:_,k1:B,k2neg:L,k2:T}=P(g),{p1:D,p2:C}=Wi(E,m,B,T);return S(b.beta,D,C,_,L)}else return K.unsafe(m,g)}toAffine(g){return U(this,g)}isTorsionFree(){let{isTorsionFree:g}=t;return i===Oe?!0:g?g(E,this):K.unsafe(this,a).is0()}clearCofactor(){let{clearCofactor:g}=t;return i===Oe?this:g?g(E,this):this.multiplyUnsafe(i)}isSmallOrder(){return this.multiplyUnsafe(i).is0()}toBytes(g=!0){return Kt(g,"isCompressed"),this.assertValidity(),p(E,this,g)}toHex(g=!0){return Nt(this.toBytes(g))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let O=o.BITS,K=new Te(E,t.endo?Math.ceil(O/2):O);return E.BASE.precompute(8),E}function wa(r){return Uint8Array.of(r?2:3)}function Ea(r,t){return{secretKey:t.BYTES,publicKey:1+r.BYTES,publicKeyUncompressed:1+2*r.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function Ff(r,t={}){let{Fn:e}=r,n=t.randomBytes||Ie,o=Object.assign(Ea(r.Fp,e),{seed:Ao(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:x}=o;try{let y=p.length;return h===!0&&y!==v||h===!1&&y!==x?!1:!!r.fromBytes(p)}catch{return!1}}function a(p=n(o.seed)){return Io(N(p,o.seed,"seed"),e.ORDER)}function c(p,h=!0){return r.BASE.multiply(e.fromBytes(p)).toBytes(h)}function u(p){let{secretKey:h,publicKey:v,publicKeyUncompressed:x}=o;if(!re(p)||"_lengths"in e&&e._lengths||h===v)return;let y=N(p,void 0,"key").length;return y===v||y===x}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 x=e.fromBytes(p);return r.fromBytes(h).multiply(x).toBytes(v)}let f={isValidSecretKey:s,isValidPublicKey:i,randomSecretKey:a},d=Vr(a,c);return Object.freeze({getPublicKey:c,getSharedSecret:l,keygen:d,Point:r,utils:f,lengths:o})}function Sa(r,t,e={}){Nr(t),Yt(e,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"}),e=Object.assign({},e);let n=e.randomBytes||Ie,o=e.hmac||((b,m)=>Qo(t,b,m)),{Fp:s,Fn:i}=r,{ORDER:a,BITS:c}=i,{keygen:u,getPublicKey:l,getSharedSecret:f,utils:d,lengths:p}=Ff(r,e),h={prehash:!0,lowS:typeof e.lowS=="boolean"?e.lowS:!0,format:"compact",extraEntropy:!1},v=a*ya<s.ORDER;function x(b){let m=a>>Oe;return b>m}function y(b,m){if(!i.isValidNot0(m))throw new Error(`invalid signature ${b}: 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(b,m){ts(m);let _=p.signature,B=m==="compact"?_:m==="recovered"?_+1:void 0;return N(b,B)}class I{r;s;recovery;constructor(m,_,B){if(this.r=y("r",m),this.s=y("s",_),B!=null){if(A(),![0,1,2,3].includes(B))throw new Error("invalid recovery id");this.recovery=B}Object.freeze(this)}static fromBytes(m,_=h.format){w(m,_);let B;if(_==="der"){let{r:C,s:k}=Qt.toSig(N(m));return new I(C,k)}_==="recovered"&&(B=m[0],_="compact",m=m.subarray(1));let L=p.signature/2,T=m.subarray(0,L),D=m.subarray(L,L*2);return new I(i.fromBytes(T),i.fromBytes(D),B)}static fromHex(m,_){return this.fromBytes(Ut(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:B}=this,L=this.assertRecovery(),T=L===2||L===3?_+a:_;if(!s.isValid(T))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let D=s.toBytes(T),C=r.fromBytes(pt(wa((L&1)===0),D)),k=i.inv(T),$=U(N(m,void 0,"msgHash")),z=i.create(-$*k),q=i.create(B*k),G=r.BASE.multiplyUnsafe(z).add(C.multiplyUnsafe(q));if(G.is0())throw new Error("invalid recovery: point at infinify");return G.assertValidity(),G}hasHighS(){return x(this.s)}toBytes(m=h.format){if(ts(m),m==="der")return Ut(Qt.hexFromSig(this));let{r:_,s:B}=this,L=i.toBytes(_),T=i.toBytes(B);return m==="recovered"?(A(),pt(Uint8Array.of(this.assertRecovery()),L,T)):pt(L,T)}toHex(m){return Nt(this.toBytes(m))}}let P=e.bits2int||function(m){if(m.length>8192)throw new Error("input is too large");let _=Be(m),B=m.length*8-c;return B>0?_>>BigInt(B):_},U=e.bits2int_modN||function(m){return i.create(P(m))},M=ar(c);function S(b){return ir("num < 2^"+c,b,qt,M),i.toBytes(b)}function E(b,m){return N(b,void 0,"message"),m?N(t(b),void 0,"prehashed message"):b}function O(b,m,_){let{lowS:B,prehash:L,extraEntropy:T}=Jo(_,h);b=E(b,L);let D=U(b),C=i.fromBytes(m);if(!i.isValidNot0(C))throw new Error("invalid private key");let k=[S(C),S(D)];if(T!=null&&T!==!1){let G=T===!0?n(p.secretKey):T;k.push(N(G,void 0,"extraEntropy"))}let $=pt(...k),z=D;function q(G){let rt=P(G);if(!i.isValidNot0(rt))return;let Dt=i.inv(rt),Z=r.BASE.multiply(rt).toAffine(),st=i.create(Z.x);if(st===qt)return;let Ar=i.create(Dt*i.create(z+st*C));if(Ar===qt)return;let Os=(Z.x===st?0:2)|Number(Z.y&Oe),ks=Ar;return B&&x(Ar)&&(ks=i.neg(Ar),Os^=1),new I(st,ks,v?void 0:Os)}return{seed:$,k2sig:q}}function K(b,m,_={}){let{seed:B,k2sig:L}=O(b,m,_);return Oi(t.outputLen,i.BYTES,o)(B,L).toBytes(_.format)}function R(b,m,_,B={}){let{lowS:L,prehash:T,format:D}=Jo(B,h);if(_=N(_,void 0,"publicKey"),m=E(m,T),!re(b)){let C=b instanceof I?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+C)}w(b,D);try{let C=I.fromBytes(b,D),k=r.fromBytes(_);if(L&&C.hasHighS())return!1;let{r:$,s:z}=C,q=U(m),G=i.inv(z),rt=i.create(q*G),Dt=i.create($*G),Z=r.BASE.multiplyUnsafe(rt).add(k.multiplyUnsafe(Dt));return Z.is0()?!1:i.create(Z.x)===$}catch{return!1}}function g(b,m,_={}){let{prehash:B}=Jo(_,h);return m=E(m,B),I.fromBytes(b,"recovered").recoverPublicKey(m).toBytes()}return Object.freeze({keygen:u,getPublicKey:l,getSharedSecret:f,utils:d,lengths:p,Point:r,sign:K,verify:R,recoverPublicKey:g,Signature:I,hash:t})}var ns={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},zf={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var va=BigInt(2);function Vf(r){let t=ns.p,e=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),a=BigInt(44),c=BigInt(88),u=r*r*r%t,l=u*u*r%t,f=V(l,e,t)*l%t,d=V(f,e,t)*l%t,p=V(d,va,t)*u%t,h=V(p,o,t)*p%t,v=V(h,s,t)*h%t,x=V(v,a,t)*v%t,y=V(x,c,t)*x%t,A=V(y,a,t)*v%t,w=V(A,e,t)*l%t,I=V(w,i,t)*h%t,P=V(I,n,t)*u%t,U=V(P,va,t);if(!rs.eql(rs.sqr(U),r))throw new Error("Cannot find square root");return U}var rs=Le(ns.p,{sqrt:Vf}),Hf=xa(ns,{Fp:rs,endo:zf}),ke=Sa(Hf,Ri);function _a(r,t,e,n){let o=Qe.digest(e instanceof Uint8Array?e:e.subarray());if(Zr(o))return o.then(({digest:s})=>(n?.signal?.throwIfAborted(),ke.verify(t,s,r,{prehash:!1,format:"der"}))).catch(s=>{throw s.name==="AbortError"?s:new fr(String(s))});try{return n?.signal?.throwIfAborted(),ke.verify(t,o.digest,r,{prehash:!1,format:"der"})}catch(s){throw new fr(String(s))}}var en=class{type="secp256k1";raw;_key;constructor(t){this._key=Ia(t),this.raw=Aa(this._key)}toMultihash(){return _t.digest(_e(this))}toCID(){return it.createV1(114,this.toMultihash())}toString(){return Y.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 _a(this._key,e,t,n)}};function Ba(r){return new en(r)}function Aa(r){return ke.Point.fromBytes(r).toBytes()}function Ia(r){try{return ke.Point.fromBytes(r),r}catch(t){throw new Br(String(t))}}function Da(r){let{Type:t,Data:e}=pr.decode(r.digest),n=e??new Uint8Array;switch(t){case xt.Ed25519:return ia(n);case xt.secp256k1:return Ba(n);case xt.ECDSA:return hi(n);default:throw new Ge}}function _e(r){return pr.encode({Type:xt[r.type],Data:r.raw})}var La=Symbol.for("nodejs.util.inspect.custom"),$f=114,mr=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()})`}[On]=!0;toString(){return this.string==null&&(this.string=Y.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return it.createV1($f,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")}[La](){return`PeerId(${this.toString()})`}},rn=class extends mr{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},nn=class extends mr{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},on=class extends mr{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},Gf=2336,sn=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=_t.digest(H(this.url))}[La](){return`PeerId(${this.url})`}[On]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return it.createV1(Gf,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=W(t)),t.toString()===this.toString())}};function Ra(r){if(Xf(r))return new rn({multihash:r});if(Zf(r))try{let t=Da(r);if(t.type==="Ed25519")return new nn({multihash:r,publicKey:t});if(t.type==="secp256k1")return new on({multihash:r,publicKey:t})}catch{let e=W(r.digest);return new sn(new URL(e))}throw new Dr("Supplied PeerID Multihash is invalid")}function Zf(r){return r.code===_t.code}function Xf(r){return r.code===Qe.code}function os(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 an(r){let t=je(Y.decode(`z${r}`));return Ra(t)}var cn=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 os(this.set.entries(),t=>{let e=an(t[0]);return[e,e]})}forEach(t){this.set.forEach(e=>{let n=an(e);t(n,n,this)})}has(t){return this.set.has(t.toString())}values(){return os(this.set.values(),t=>an(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 ss(){return new cn}var is={32:16777619n,64:1099511628211n,128:309485009821345068724781371n,256:374144419156711147060143317175368453031918731002211n,512:35835915874844867368919076489095108449946327955754392558399825615420669938882575126094039892345713852759n,1024:5016456510113118655434598811035278955030765345404790744303017523831112055108147451509157692220295382716162651878526895249385292291816524375083746691371804094271873160484737966720260389217684476157468082573n},Ta={32:2166136261n,64:14695981039346656037n,128:144066263297769815596495629667062367629n,256:100029257958052580907070968620625704837092796014241193945225284501741471925557n,512:9659303129496669498009435400716310466090418745672637896108374329434462657994582932197716438449813051892206539805784495328239340083876191928701583869517785n,1024:14197795064947621068722070641403218320880622795441933960878474914617582723252296732303717722150864096521202355549365628174669108571814760471015076148029755969804077320157692458563003215304957150157403644460363550505412711285966361610267868082893823963790439336411086884584107735010676915n},Ca=new globalThis.TextEncoder;function Yf(r,t){let e=is[t],n=Ta[t];for(let o=0;o<r.length;o++)n^=BigInt(r[o]),n=BigInt.asUintN(t,n*e);return n}function jf(r,t,e){if(e.length===0)throw new Error("The `utf8Buffer` option must have a length greater than zero");let n=is[t],o=Ta[t],s=r;for(;s.length>0;){let i=Ca.encodeInto(s,e);s=s.slice(i.read);for(let a=0;a<i.written;a++)o^=BigInt(e[a]),o=BigInt.asUintN(t,o*n)}return o}function as(r,{size:t=32,utf8Buffer:e}={}){if(!is[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 jf(r,t,e);r=Ca.encode(r)}return Yf(r,t)}var gr={hash:r=>Number(as(r,{size:32})),hashV:(r,t)=>Wf(gr.hash(r,t))};function Wf(r){let t=r.toString(16);return t.length%2===1&&(t=`0${t}`),H(t,"base16")}var cs=64,Bt=class{fp;h;seed;constructor(t,e,n,o=2){if(o>cs)throw new TypeError("Invalid Fingerprint Size");let s=e.hashV(t,n),i=bt(o);for(let a=0;a<i.length;a++)i[a]=s[a];i.length===0&&(i[0]=7),this.fp=i,this.h=e,this.seed=n}hash(){return this.h.hash(this.fp,this.seed)}equals(t){return t?.fp instanceof Uint8Array?lt(this.fp,t.fp):!1}};function de(r,t){return Math.floor(Math.random()*(t-r))+r}var he=class{contents;constructor(t){this.contents=new Array(t).fill(null)}has(t){if(!(t instanceof Bt))throw new TypeError("Invalid Fingerprint");return this.contents.some(e=>t.equals(e))}add(t){if(!(t instanceof Bt))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 Bt))throw new TypeError("Invalid Fingerprint");let e=de(0,this.contents.length-1),n=this.contents[e];return this.contents[e]=t,n}remove(t){if(!(t instanceof Bt))throw new TypeError("Invalid Fingerprint");let e=this.contents.findIndex(n=>t.equals(n));return e>-1?(this.contents[e]=null,!0):!1}};var Qf=500,br=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??gr,this.seed=t.seed??de(0,Math.pow(2,10))}add(t){typeof t=="string"&&(t=H(t));let e=new Bt(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 he(this.bucketSize)),this.buckets[o]==null&&(this.buckets[o]=new he(this.bucketSize)),this.buckets[n].add(e)||this.buckets[o].add(e))return this.count++,!0;let s=[n,o],i=s[de(0,s.length-1)];this.buckets[i]==null&&(this.buckets[i]=new he(this.bucketSize));for(let a=0;a<Qf;a++){let c=this.buckets[i].swap(e);if(c!=null&&(i=(i^c.hash())%this.filterSize,this.buckets[i]==null&&(this.buckets[i]=new he(this.bucketSize)),this.buckets[i].add(c)))return this.count++,!0}return!1}has(t){typeof t=="string"&&(t=H(t));let e=new Bt(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=H(t));let e=new Bt(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}},Jf={1:.5,2:.84,4:.95,8:.98};function tl(r=.001){return r>.002?2:r>1e-5?4:8}function Pa(r,t=.001){let e=tl(t),n=Jf[e],o=Math.round(r/n),s=Math.min(Math.ceil(Math.log2(1/t)+Math.log2(2*e)),cs);return{filterSize:o,bucketSize:e,fingerprintSize:s}}var un=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??gr,this.seed=t.seed??de(0,Math.pow(2,10)),this.filterSeries=[new br({filterSize:this.filterSize,bucketSize:this.bucketSize,fingerprintSize:this.fingerprintSize,hash:this.hash,seed:this.seed})]}add(t){if(typeof t=="string"&&(t=H(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 br({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=H(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=H(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 us(r,t=.001,e){return new un({...Pa(r,t),...e??{}})}function Jt(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 fn=class{index=0;input="";new(t){return this.index=0,this.input=t,this}readAtomically(t){let e=this.index,n=t();return n===void 0&&(this.index=e),n}parseWith(t){let e=t();if(this.index===this.input.length)return e}peekChar(){if(!(this.index>=this.input.length))return this.input[this.index]}readChar(){if(!(this.index>=this.input.length))return this.input[this.index++]}readGivenChar(t){return this.readAtomically(()=>{let e=this.readChar();if(e===t)return e})}readSeparator(t,e,n){return this.readAtomically(()=>{if(!(e>0&&this.readGivenChar(t)===void 0))return n()})}readNumber(t,e,n,o){return this.readAtomically(()=>{let s=0,i=0,a=this.peekChar();if(a===void 0)return;let c=a==="0",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&&c&&i>1?void 0:s})}readIPv4Addr(){return this.readAtomically(()=>{let t=new Uint8Array(4);for(let e=0;e<t.length;e++){let n=this.readSeparator(".",e,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;t[e]=n}return t})}readIPv6Addr(){let t=e=>{for(let n=0;n<e.length/2;n++){let o=n*2;if(n<e.length-3){let i=this.readSeparator(":",n,()=>this.readIPv4Addr());if(i!==void 0)return e[o]=i[0],e[o+1]=i[1],e[o+2]=i[2],e[o+3]=i[3],[o+4,!0]}let s=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(s===void 0)return[o,!1];e[o]=s>>8,e[o+1]=s&255}return[e.length,!1]};return this.readAtomically(()=>{let e=new Uint8Array(16),[n,o]=t(e);if(n===16)return e;if(o||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let s=new Uint8Array(14),i=16-(n+2),[a]=t(s.subarray(0,i));return e.set(s.subarray(0,a),16-a),e})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var Oa=45,el=15,Ne=new fn;function ln(r){if(!(r.length>el))return Ne.new(r).parseWith(()=>Ne.readIPv4Addr())}function dn(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>Oa))return Ne.new(r).parseWith(()=>Ne.readIPv6Addr())}function Ue(r,t=!1){if(r.includes("%")&&(r=r.split("%")[0]),r.length>Oa)return;let e=Ne.new(r).parseWith(()=>Ne.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 ka(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 Na(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 fs(r){switch(r.length){case pe:return r.join(".");case me:{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 Ua(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 Ma(r){let t="0x";for(let e of r)t+=(e>>4).toString(16)+(e&15).toString(16);return t}var pe=4,me=16,Wg=parseInt("0xFFFF",16),rl=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function yr(r,t){t.length===me&&r.length===pe&&ka(t,0,11)&&(t=t.slice(12)),t.length===pe&&r.length===me&&Na(r,rl,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 Ka(r,t){if(typeof t=="string"&&(t=Ue(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 ls(r){let[t,e]=r.split("/");if(!t||!e)throw new Error("Failed to parse given CIDR: "+r);let n=pe,o=ln(t);if(o==null&&(n=me,o=dn(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=ds(s,8*n);return{network:yr(o,i),mask:i}}function ds(r,t){if(t!==8*pe&&t!==8*me)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 xr=class{constructor(t,e){if(e==null)({network:this.network,mask:this.mask}=ls(t));else{let n=Ue(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=Ue(e);if(s==null)throw new Error("Failed to parse mask");this.mask=s}else this.mask=ds(o,8*n.length);this.network=yr(n,this.mask)}}contains(t){return Ka({network:this.network,mask:this.mask},t)}toString(){let t=Ua(this.mask),e=t!==-1?String(t):Ma(this.mask);return fs(this.network)+"/"+e}};function qa(r,t){return new xr(r).contains(t)}function Fa(r){try{let t=Jt(r);switch(t.type){case"ip6":return qa("2000::/3",t.host);default:return!1}}catch{return!1}}function Me(r){return!!ln(r)}function hn(r){return!!dn(r)}var Va=Ac(za(),1),nl=["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"],ol=nl.map(r=>new Va.Netmask(r));function hs(r){for(let t of ol)if(t.contains(r))return!0;return!1}function sl(r){return/^::ffff:([0-9a-fA-F]{1,4}):([0-9a-fA-F]{1,4})$/.test(r)}function il(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 hs(o)}function al(r){return/^::ffff:([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(r)}function cl(r){let t=r.split(":"),e=t[t.length-1];return hs(e)}function ul(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 pn(r){if(Me(r))return hs(r);if(sl(r))return il(r);if(al(r))return cl(r);if(hn(r))return ul(r)}function Ha(r){try{let t=Jt(r);switch(t.type){case"ip4":case"ip6":return pn(t.host)??!1;default:return t.host==="localhost"}}catch{return!1}}function Ke(){let r={};return r.promise=new Promise((t,e)=>{r.resolve=t,r.reject=e}),r}var mn=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}},qe=class{size;hwm;head;tail;constructor(t={}){this.hwm=t.splitLimit??16,this.head=new mn(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 mn(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 ps=class extends Error{type;code;constructor(t,e){super(t??"The operation was aborted"),this.type="aborted",this.code=e??"ABORT_ERR"}};function gn(r={}){return fl(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 fl(r,t){t=t??{};let e=t.onEnd,n=new qe,o,s,i,a=Ke(),c=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((x,y)=>{s=A=>{s=null,n.push(A);try{x(r(n))}catch(w){y(w)}return o}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=Ke()})}},u=x=>s!=null?s(x):(n.push(x),o),l=x=>(n=new qe,s!=null?s({error:x}):(n.push({error:x}),o)),f=x=>{if(i)return o;if(t?.objectMode!==!0&&x?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return u({done:!1,value:x})},d=x=>i?o:(i=!0,x!=null?l(x):u({done:!0})),p=()=>(n=new qe,d(),{done:!0}),h=x=>(d(x),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:c,return:p,throw:h,push:f,end:d,get readableLength(){return n.size},onEmpty:async x=>{let y=x?.signal;if(y?.throwIfAborted(),n.isEmpty())return;let A,w;y!=null&&(A=new Promise((I,P)=>{w=()=>{P(new ps)},y.addEventListener("abort",w)}));try{await Promise.race([a.promise,A])}finally{w!=null&&y!=null&&y?.removeEventListener("abort",w)}}},e==null)return o;let v=o;return o={[Symbol.asyncIterator](){return this},next(){return v.next()},throw(x){return v.throw(x),e!=null&&(e(x),e=void 0),{done:!0}},return(){return v.return(),e!=null&&(e(),e=void 0),{done:!0}},push:f,end(x){return v.end(x),e!=null&&(e(x),e=void 0),o},get readableLength(){return v.readableLength},onEmpty:x=>v.onEmpty(x)},o}var ms=class extends Error{constructor(t){super(t),this.name="TimeoutError"}},gs=class extends Error{constructor(t){super(),this.name="AbortError",this.message=t}},$a=r=>globalThis.DOMException===void 0?new gs(r):new DOMException(r),Ga=r=>{let t=r.reason===void 0?$a("This operation was aborted."):r.reason;return t instanceof Error?t:$a(t)};function bs(r,t){let{milliseconds:e,fallback:n,message:o,customTimers:s={setTimeout,clearTimeout}}=t,i,a,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(Ga(p)),a=()=>{f(Ga(p))},p.addEventListener("abort",a,{once:!0})}if(e===Number.POSITIVE_INFINITY){r.then(l,f);return}let d=new ms;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(),a&&t.signal&&t.signal.removeEventListener("abort",a)});return u.clear=()=>{s.clearTimeout.call(void 0,i),i=void 0},u}var ll=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 dl(r,t,e){let n,o=new Promise((s,i)=>{if(e={rejectionEvents:["error"],multiArgs:!1,rejectionMultiArgs:!1,resolveImmediately:!1,...e},!(e.count>=0&&(e.count===Number.POSITIVE_INFINITY||Number.isInteger(e.count))))throw new TypeError("The `count` option should be at least 0 or more");e.signal?.throwIfAborted();let a=[t].flat(),c=[],{addListener:u,removeListener:l}=ll(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}c.push(h),e.count===c.length&&(n(),s(c))},d=(...p)=>{n(),i(e.rejectionMultiArgs?p:p[0])};n=()=>{for(let p of a)l(p,f);for(let p of e.rejectionEvents)a.includes(p)||l(p,d)};for(let p of a)u(p,f);for(let p of e.rejectionEvents)a.includes(p)||u(p,d);e.signal&&e.signal.addEventListener("abort",()=>{d(e.signal.reason)},{once:!0}),e.resolveImmediately&&s(c)});if(o.cancel=n,typeof e.timeout=="number"){let s=bs(o,{milliseconds:e.timeout});return s.cancel=()=>{n(),s.clear()},s}return o}function Fe(r,t,e){typeof e=="function"&&(e={filter:e}),e={...e,count:1,resolveImmediately:!1};let n=dl(r,t,e),o=n.then(s=>s[0]);return o.cancel=n.cancel,o}function Er(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 bn=class extends Error{static name="QueueFullError";constructor(t="The queue was full"){super(t),this.name="QueueFullError"}},ge=class extends Error{static name="UnexpectedEOFError";name="UnexpectedEOFError"};function hl(r){return r.reason}async function Sr(r,t,e){if(t==null)return r;let n=e?.translateError??hl;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 yn=class{deferred;signal;constructor(t){this.signal=t,this.deferred=Ke(),this.onAbort=this.onAbort.bind(this),this.signal?.addEventListener("abort",this.onAbort)}onAbort(){this.deferred.reject(this.signal?.reason??new Tt)}cleanup(){this.signal?.removeEventListener("abort",this.onAbort)}};function pl(){return`${parseInt(String(Math.random()*1e9),10).toString()}${Date.now()}`}var xn=class{id;fn;options;recipients;status;timeline;controller;constructor(t,e){this.id=pl(),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 Tt),this.cleanup())}async join(t={}){let e=new yn(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 Sr(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 wn=class extends Lr{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=Er(this.emitEmpty.bind(this),1),this.emitIdle=Er(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 bn;let n=new xn(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 Tt)}),this.clear()}async onEmpty(t){this.size!==0&&await Fe(this,"empty",t)}async onSizeLessThan(t,e){this.size<t||await Fe(this,"next",{...e,filter:()=>this.size<t})}async onIdle(t){this.pending===0&&this.size===0||await Fe(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=gn({objectMode:!0}),n=c=>{c!=null?this.abort():this.clear(),e.end(c)},o=c=>{c.detail!=null&&e.push(c.detail)},s=c=>{n(c.detail.error)},i=()=>{n()},a=()=>{n(new Tt("Queue aborted"))};this.addEventListener("completed",o),this.addEventListener("failure",s),this.addEventListener("idle",i),t?.signal?.addEventListener("abort",a);try{yield*e}finally{this.removeEventListener("completed",o),this.removeEventListener("failure",s),this.removeEventListener("idle",i),t?.signal?.removeEventListener("abort",a),n()}}};function vr(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 ot=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},Ft=class extends Error{static name="ValidationError";name="ValidationError"},En=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},Sn=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};function xs(r){return t=>W(t,r)}function ws(r){return t=>H(t,r)}function ze(r){return new DataView(r.buffer).getUint16(r.byteOffset).toString()}function be(r){let t=new ArrayBuffer(2);return new DataView(t).setUint16(0,typeof r=="string"?parseInt(r):r),new Uint8Array(t)}function Za(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=H(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=be(n);return Pt([e,o],e.length+o.length)}function Xa(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=$t.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=be(n);return Pt([e,o],e.length+o.length)}function Es(r){let t=r.subarray(0,r.length-2),e=r.subarray(r.length-2),n=W(t,"base32"),o=ze(e);return`${n}:${o}`}var Ss=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 ot("Invalid byte value in IP address");t[n]=o}),t},Ya=function(r){let t=0;r=r.toString().trim();let e=r.split(":",8),n;for(n=0;n<e.length;n++){let s=Me(e[n]),i;s&&(i=Ss(e[n]),e[n]=W(i.subarray(0,2),"base16")),i!=null&&++n<8&&e.splice(n,0,W(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 ot("Invalid byte value in IP address");o[t++]=s>>8&255,o[t++]=s&255}return o},ja=function(r){if(r.byteLength!==4)throw new ot("IPv4 address was incorrect length");let t=[];for(let e=0;e<r.byteLength;e++)t.push(r[e]);return t.join(".")},Wa=function(r){if(r.byteLength!==16)throw new ot("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 ot(`Invalid IPv6 address "${e}"`)}};function Qa(r){try{let t=new URL(`http://[${r}]`);return t.hostname.substring(1,t.hostname.length-1)}catch{throw new ot(`Invalid IPv6 address "${r}"`)}}var ys=Object.values(Je).map(r=>r.decoder),ml=(function(){let r=ys[0].or(ys[1]);return ys.slice(2).forEach(t=>r=r.or(t)),r})();function Ja(r){return ml.decode(r)}function tc(r){return t=>r.encoder.encode(t)}function gl(r){if(parseInt(r).toString()!==r)throw new Ft("Value must be an integer")}function bl(r){if(r<0)throw new Ft("Value must be a positive integer, or zero")}function yl(r){return t=>{if(t>r)throw new Ft(`Value must be smaller than or equal to ${r}`)}}function xl(...r){return t=>{for(let e of r)e(t)}}var _r=xl(gl,bl,yl(65535));var et=-1,vs=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 Sn(`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 vs,od=[{code:4,name:"ip4",size:32,valueToBytes:Ss,bytesToValue:ja,validate:r=>{if(!Me(r))throw new Ft(`Invalid IPv4 address "${r}"`)}},{code:6,name:"tcp",size:16,valueToBytes:be,bytesToValue:ze,validate:_r},{code:273,name:"udp",size:16,valueToBytes:be,bytesToValue:ze,validate:_r},{code:33,name:"dccp",size:16,valueToBytes:be,bytesToValue:ze,validate:_r},{code:41,name:"ip6",size:128,valueToBytes:Ya,bytesToValue:Wa,stringToValue:Qa,validate:r=>{if(!hn(r))throw new Ft(`Invalid IPv6 address "${r}"`)}},{code:42,name:"ip6zone",size:et},{code:43,name:"ipcidr",size:8,bytesToValue:xs("base10"),valueToBytes:ws("base10")},{code:53,name:"dns",size:et},{code:54,name:"dns4",size:et},{code:55,name:"dns6",size:et},{code:56,name:"dnsaddr",size:et},{code:132,name:"sctp",size:16,valueToBytes:be,bytesToValue:ze,validate:_r},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:et,stringToValue:r=>decodeURIComponent(r),valueToString:r=>encodeURIComponent(r)},{code:421,name:"p2p",aliases:["ipfs"],size:et,bytesToValue:xs("base58btc"),valueToBytes:r=>r.startsWith("Q")||r.startsWith("1")?ws("base58btc")(r):it.parse(r).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:Es,valueToBytes:Za},{code:445,name:"onion3",size:296,bytesToValue:Es,valueToBytes:Xa},{code:446,name:"garlic64",size:et},{code:447,name:"garlic32",size:et},{code:448,name:"tls"},{code:449,name:"sni",size:et},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:et,bytesToValue:tc(Yn),valueToBytes:Ja},{code:480,name:"http"},{code:481,name:"http-path",size:et,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:et}];od.forEach(r=>{zt.addProtocol(r)});function ec(r){let t=[],e=0;for(;e<r.length;){let n=lr(r,e),o=zt.getProtocol(n),s=mt(n),i=sd(o,r,e+s),a=0;i>0&&o.size===et&&(a=mt(i));let c=s+a+i,u={code:n,name:o.name,bytes:r.subarray(e,e+c)};if(i>0){let l=e+s+a,f=r.subarray(l,l+i);u.value=o.bytesToValue?.(f)??W(f)}t.push(u),e+=c}return t}function rc(r){let t=0,e=[];for(let n of r){if(n.bytes==null){let o=zt.getProtocol(n.code),s=mt(n.code),i,a=0,c=0;n.value!=null&&(i=o.valueToBytes?.(n.value)??H(n.value),a=i.byteLength,o.size===et&&(c=mt(a)));let u=new Uint8Array(s+c+a),l=0;Ce(n.code,u,l),l+=s,i!=null&&(o.size===et&&(Ce(a,u,l),l+=c),u.set(i,l)),n.bytes=u}e.push(n.bytes),t+=n.bytes.byteLength}return Pt(e,t)}function nc(r){if(r.charAt(0)!=="/")throw new ot('String multiaddr must start with "/"');let t=[],e="protocol",n="",o="";for(let s=1;s<r.length;s++){let i=r.charAt(s);i!=="/"&&(e==="protocol"?o+=r.charAt(s):n+=r.charAt(s));let a=s===r.length-1;if(i==="/"||a){let c=zt.getProtocol(o);if(e==="protocol"){if(c.size==null||c.size===0){t.push({code:c.code,name:c.name}),n="",o="",e="protocol";continue}else if(a)throw new ot(`Component ${o} was missing value`);e="value"}else if(e==="value"){let u={code:c.code,name:c.name};if(c.size!=null&&c.size!==0){if(n==="")throw new ot(`Component ${o} was missing value`);u.value=c.stringToValue?.(n)??n}t.push(u),n="",o="",e="protocol"}}}if(o!==""&&n!=="")throw new ot("Incomplete multiaddr");return t}function oc(r){return`/${r.flatMap(t=>{if(t.value==null)return t.name;let e=zt.getProtocol(t.code);if(e==null)throw new ot(`Unknown protocol code ${t.code}`);return[t.name,e.valueToString?.(t.value)??t.value]}).join("/")}`}function sd(r,t,e){return r.size==null||r.size===0?0:r.size>0?r.size/8:lr(t,e)}var id=Symbol.for("nodejs.util.inspect.custom"),Is=Symbol.for("@multiformats/multiaddr");function ad(r){if(r==null&&(r="/"),sc(r))return r.getComponents();if(r instanceof Uint8Array)return ec(r);if(typeof r=="string")return r=r.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),r===""&&(r="/"),nc(r);if(Array.isArray(r))return r;throw new ot("Must be a string, Uint8Array, Component[], or another Multiaddr")}var vn=class r{[Is]=!0;#t;#e;#r;constructor(t="/",e={}){this.#t=ad(t),e.validate!==!1&&cd(this)}get bytes(){return this.#r==null&&(this.#r=rc(this.#t)),this.#r}toString(){return this.#e==null&&(this.#e=oc(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 En(`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)}[id](){return`Multiaddr(${this.toString()})`}};function cd(r){r.getComponents().forEach(t=>{let e=zt.getProtocol(t.code);t.value!=null&&e.validate?.(t.value)})}function sc(r){return!!r?.[Is]}function ic(r){return new vn(r)}var ud=4194304,_n=class extends Error{static name="UnwrappedError";name="UnwrappedError"},Ds=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},Ls=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},Rs=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function fd(r){return typeof r?.closeRead=="function"}function ld(r){return typeof r?.close=="function"}function Bs(r){return fd(r)?r.remoteWriteStatus!=="writable"&&r.readBufferLength===0:ld(r)?r.status!=="open":!1}function dd(r){return r?.addEventListener!=null&&r?.removeEventListener!=null&&r?.send!=null&&r?.push!=null&&r?.log!=null}function hd(r,t){let e=t?.maxBufferSize??ud,n=new Q,o,s=!1;if(!dd(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 a=l=>{l.error!=null?o?.reject(l.error):o?.resolve()};r.addEventListener("close",a);let c=()=>{o?.resolve()};r.addEventListener("remoteCloseWrite",c);let u={readBuffer:n,async read(l){if(s===!0)throw new _n("Stream was unwrapped");if(Bs(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 ge(`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 Sr(o.promise,l?.signal),Bs(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(Bs(r))throw r.log.error("closed while reading %d/%d bytes",n.byteLength,d),new ge(`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 _n("Stream was unwrapped");r.send(l)||await Fe(r,"drain",{signal:f?.signal,rejectionEvents:["close"]})},unwrap(){return s||(s=!0,r.removeEventListener("message",i),r.removeEventListener("close",a),r.removeEventListener("remoteCloseWrite",c),n.byteLength>0&&(r.log("stream unwrapped with %d unread bytes",n.byteLength),r.push(n))),r}};return u}function pd(r,t={}){let e=hd(r,t);t.maxDataLength!=null&&t.maxLengthLength==null&&(t.maxLengthLength=mt(t.maxDataLength));let n=t?.lengthDecoder??lr,o=t?.lengthEncoder??aa;return{async read(i){let a=-1,c=new Q;for(;;){let l=await e.read({...i,bytes:1});if(l==null)break;c.append(l);try{a=n(c)}catch(f){if(f instanceof RangeError)continue;throw f}if(a<0)throw new Ds("Invalid message length");if(t?.maxLengthLength!=null&&c.byteLength>t.maxLengthLength)throw new Rs(`Message length length too long - ${c.byteLength} > ${t.maxLengthLength}`);if(a>-1)break}if(t?.maxDataLength!=null&&a>t.maxDataLength)throw new Ls(`Message length too long - ${a} > ${t.maxDataLength}`);let u=await e.read({...i,bytes:a});if(u==null)throw r.log.error("tried to read %d bytes but the stream closed",a),new ge(`Unexpected EOF - tried to read ${a} bytes but the stream closed`);if(u.byteLength!==a)throw r.log.error("read %d/%d bytes before the stream closed",u.byteLength,a),new ge(`Unexpected EOF - read ${u.byteLength}/${a} bytes before the stream closed`);return u},async write(i,a){await e.write(new Q(o(i.byteLength),i),a)},async writeV(i,a){let c=new Q(...i.flatMap(u=>[o(u.byteLength),u]));await e.write(c,a)},unwrap(){return e.unwrap()}}}function Ve(r,t){let e=pd(r,t),n={read:async(o,s)=>{let i=await e.read(s);return o.decode(i)},write:async(o,s,i)=>{await e.write(s.encode(o),i)},writeV:async(o,s,i)=>{await e.writeV(o.map(a=>s.encode(a)),i)},pb:o=>({read:async s=>n.read(o,s),write:async(s,i)=>n.write(s,o,i),writeV:async(s,i)=>n.writeV(s,o,i),unwrap:()=>n}),unwrap:()=>e.unwrap()};return n}var An=class extends wn{has(t){return this.find(t)!=null}find(t){return this.queue.find(e=>t.equals(e.options.peerId))}};function ac(r,t,e){let n,o,s=!1;function i(){let u={signal:o.signal};if(e?.timeout!=null){let l=vr([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 a=Er(i,e?.debounce??100),c=!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),a())},start:()=>{c||(c=!0,o=new AbortController,o.signal,e?.runImmediately===!0?queueMicrotask(()=>{i()}):n=setTimeout(i,t))},stop:()=>{clearTimeout(n),o?.abort(),c=!1}}}var Ts=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 cc(r){let{name:t,metrics:e}=r,n;return e!=null?n=new Ts({name:t,metrics:e}):n=new Map,n}var Cs="libp2p",Ps="autonat";var uc="dial-request",fc="dial-back",lc=200n*1024n,dc=4096;var He;(function(r){let t;r.codec=()=>(t==null&&(t=vt((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e={...e},e.dialDataResponse!=null&&(e.dialDataRequest=void 0,e.dialResponse=void 0,e.dialRequest=void 0),e.dialDataRequest!=null&&(e.dialDataResponse=void 0,e.dialResponse=void 0,e.dialRequest=void 0),e.dialResponse!=null&&(e.dialDataResponse=void 0,e.dialDataRequest=void 0,e.dialRequest=void 0),e.dialRequest!=null&&(e.dialDataResponse=void 0,e.dialDataRequest=void 0,e.dialResponse=void 0),e.dialRequest!=null&&(n.uint32(10),In.codec().encode(e.dialRequest,n)),e.dialResponse!=null&&(n.uint32(18),Vt.codec().encode(e.dialResponse,n)),e.dialDataRequest!=null&&(n.uint32(26),Bn.codec().encode(e.dialDataRequest,n)),e.dialDataResponse!=null&&(n.uint32(34),Ln.codec().encode(e.dialDataResponse,n)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let a=e.uint32();switch(a>>>3){case 1:{s.dialRequest=In.codec().decode(e,e.uint32(),{limits:o.limits?.dialRequest});break}case 2:{s.dialResponse=Vt.codec().decode(e,e.uint32(),{limits:o.limits?.dialResponse});break}case 3:{s.dialDataRequest=Bn.codec().decode(e,e.uint32(),{limits:o.limits?.dialDataRequest});break}case 4:{s.dialDataResponse=Ln.codec().decode(e,e.uint32(),{limits:o.limits?.dialDataResponse});break}default:{e.skipType(a&7);break}}}return s.dialDataResponse!=null&&(delete s.dialDataRequest,delete s.dialResponse,delete s.dialRequest),s.dialDataRequest!=null&&(delete s.dialDataResponse,delete s.dialResponse,delete s.dialRequest),s.dialResponse!=null&&(delete s.dialDataResponse,delete s.dialDataRequest,delete s.dialRequest),s.dialRequest!=null&&(delete s.dialDataResponse,delete s.dialDataRequest,delete s.dialResponse),s})),t),r.encode=e=>St(e,r.codec()),r.decode=(e,n)=>Et(e,r.codec(),n)})(He||(He={}));var In;(function(r){let t;r.codec=()=>(t==null&&(t=vt((e,n,o={})=>{if(o.lengthDelimited!==!1&&n.fork(),e.addrs!=null)for(let s of e.addrs)n.uint32(10),n.bytes(s);e.nonce!=null&&e.nonce!==0n&&(n.uint32(17),n.fixed64(e.nonce)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={addrs:[],nonce:0n},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let a=e.uint32();switch(a>>>3){case 1:{if(o.limits?.addrs!=null&&s.addrs.length===o.limits.addrs)throw new Qr('Decode error - map field "addrs" had too many elements');s.addrs.push(e.bytes());break}case 2:{s.nonce=e.fixed64();break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>St(e,r.codec()),r.decode=(e,n)=>Et(e,r.codec(),n)})(In||(In={}));var Bn;(function(r){let t;r.codec=()=>(t==null&&(t=vt((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.addrIdx!=null&&e.addrIdx!==0&&(n.uint32(8),n.uint32(e.addrIdx)),e.numBytes!=null&&e.numBytes!==0n&&(n.uint32(16),n.uint64(e.numBytes)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={addrIdx:0,numBytes:0n},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let a=e.uint32();switch(a>>>3){case 1:{s.addrIdx=e.uint32();break}case 2:{s.numBytes=e.uint64();break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>St(e,r.codec()),r.decode=(e,n)=>Et(e,r.codec(),n)})(Bn||(Bn={}));var ut;(function(r){r.UNUSED="UNUSED",r.E_DIAL_ERROR="E_DIAL_ERROR",r.E_DIAL_BACK_ERROR="E_DIAL_BACK_ERROR",r.OK="OK"})(ut||(ut={}));var Dn;(function(r){r[r.UNUSED=0]="UNUSED",r[r.E_DIAL_ERROR=100]="E_DIAL_ERROR",r[r.E_DIAL_BACK_ERROR=101]="E_DIAL_BACK_ERROR",r[r.OK=200]="OK"})(Dn||(Dn={}));(function(r){r.codec=()=>le(Dn)})(ut||(ut={}));var Vt;(function(r){let t;(function(o){o.E_INTERNAL_ERROR="E_INTERNAL_ERROR",o.E_REQUEST_REJECTED="E_REQUEST_REJECTED",o.E_DIAL_REFUSED="E_DIAL_REFUSED",o.OK="OK"})(t=r.ResponseStatus||(r.ResponseStatus={}));let e;(function(o){o[o.E_INTERNAL_ERROR=0]="E_INTERNAL_ERROR",o[o.E_REQUEST_REJECTED=100]="E_REQUEST_REJECTED",o[o.E_DIAL_REFUSED=101]="E_DIAL_REFUSED",o[o.OK=200]="OK"})(e||(e={})),(function(o){o.codec=()=>le(e)})(t=r.ResponseStatus||(r.ResponseStatus={}));let n;r.codec=()=>(n==null&&(n=vt((o,s,i={})=>{i.lengthDelimited!==!1&&s.fork(),o.status!=null&&e[o.status]!==0&&(s.uint32(8),r.ResponseStatus.codec().encode(o.status,s)),o.addrIdx!=null&&o.addrIdx!==0&&(s.uint32(16),s.uint32(o.addrIdx)),o.dialStatus!=null&&Dn[o.dialStatus]!==0&&(s.uint32(24),ut.codec().encode(o.dialStatus,s)),i.lengthDelimited!==!1&&s.ldelim()},(o,s,i={})=>{let a={status:t.E_INTERNAL_ERROR,addrIdx:0,dialStatus:ut.UNUSED},c=s==null?o.len:o.pos+s;for(;o.pos<c;){let u=o.uint32();switch(u>>>3){case 1:{a.status=r.ResponseStatus.codec().decode(o);break}case 2:{a.addrIdx=o.uint32();break}case 3:{a.dialStatus=ut.codec().decode(o);break}default:{o.skipType(u&7);break}}}return a})),n),r.encode=o=>St(o,r.codec()),r.decode=(o,s)=>Et(o,r.codec(),s)})(Vt||(Vt={}));var Ln;(function(r){let t;r.codec=()=>(t==null&&(t=vt((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.data!=null&&e.data.byteLength>0&&(n.uint32(10),n.bytes(e.data)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={data:bt(0)},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let a=e.uint32();switch(a>>>3){case 1:{s.data=e.bytes();break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>St(e,r.codec()),r.decode=(e,n)=>Et(e,r.codec(),n)})(Ln||(Ln={}));var $e;(function(r){let t;r.codec=()=>(t==null&&(t=vt((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.nonce!=null&&e.nonce!==0n&&(n.uint32(9),n.fixed64(e.nonce)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={nonce:0n},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let a=e.uint32();switch(a>>>3){case 1:{s.nonce=e.fixed64();break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>St(e,r.codec()),r.decode=(e,n)=>Et(e,r.codec(),n)})($e||($e={}));var te;(function(r){let t;(function(o){o.OK="OK"})(t=r.DialBackStatus||(r.DialBackStatus={}));let e;(function(o){o[o.OK=0]="OK"})(e||(e={})),(function(o){o.codec=()=>le(e)})(t=r.DialBackStatus||(r.DialBackStatus={}));let n;r.codec=()=>(n==null&&(n=vt((o,s,i={})=>{i.lengthDelimited!==!1&&s.fork(),o.status!=null&&e[o.status]!==0&&(s.uint32(8),r.DialBackStatus.codec().encode(o.status,s)),i.lengthDelimited!==!1&&s.ldelim()},(o,s,i={})=>{let a={status:t.OK},c=s==null?o.len:o.pos+s;for(;o.pos<c;){let u=o.uint32();switch(u>>>3){case 1:{a.status=r.DialBackStatus.codec().decode(o);break}default:{o.skipType(u&7);break}}}return a})),n),r.encode=o=>St(o,r.codec()),r.decode=(o,s)=>Et(o,r.codec(),s)})(te||(te={}));function Rn(r,t){return Math.round(Math.random()*(t-r)+r)}var gd=4,bd=8,Tn=class{components;dialRequestProtocol;dialBackProtocol;timeout;maxInboundStreams;maxOutboundStreams;maxMessageSize;maxDialDataBytes;dialDataChunkSize;started;log;topologyId;dialResults;findPeers;addressFilter;connectionThreshold;queue;nonces;constructor(t,e){this.components=t,this.log=t.logger.forComponent("libp2p:auto-nat-v2:client"),this.started=!1,this.dialRequestProtocol=e.dialRequestProtocol,this.dialBackProtocol=e.dialBackProtocol,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=cc({name:"libp2p_autonat_v2_dial_results",metrics:t.metrics}),this.findPeers=ac(this.findRandomPeers.bind(this),6e4),this.addressFilter=us(1024),this.queue=new An({concurrency:3,maxSize:50}),this.maxDialDataBytes=e.maxDialDataBytes??lc,this.dialDataChunkSize=e.dialDataChunkSize??dc,this.nonces=new Set}[Symbol.toStringTag]="@libp2p/autonat-v2";[Rr]=["@libp2p/autonat"];get[Tr](){return["@libp2p/identify"]}isStarted(){return this.started}async start(){this.started||(this.topologyId=await this.components.registrar.register(this.dialRequestProtocol,{onConnect:(t,e)=>{this.verifyExternalAddresses(e).catch(n=>{this.log.error("could not verify addresses - %e",n)})}}),await this.components.registrar.handle(this.dialBackProtocol,(t,e)=>{this.handleDialBackStream(t,e).catch(n=>{this.log.error("error handling incoming autonat stream - %e",n)})},{maxInboundStreams:this.maxInboundStreams,maxOutboundStreams:this.maxOutboundStreams}),this.findPeers.start(),this.started=!0)}async stop(){await this.components.registrar.unhandle(this.dialRequestProtocol),await this.components.registrar.unhandle(this.dialBackProtocol),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=vr([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 handleDialBackStream(t,e){let n=AbortSignal.timeout(this.timeout);let o=Ve(t,{maxDataLength:this.maxMessageSize});try{let s=await o.read($e,{signal:n});if(!this.nonces.has(s.nonce))throw new wt("No matching dial found for nonce value");this.nonces.delete(s.nonce),await o.write({status:te.DialBackStatus.OK},te),await t.close({signal:n})}catch(s){this.log.error("error handling incoming dial back stream - %e",s),t.abort(s)}}getUnverifiedMultiaddrs(t,e){let n=this.components.addressManager.getAddressesWithMetadata().sort((s,i)=>s.type==="observed"&&i.type!=="observed"?1:i.type==="observed"&&s.type!=="observed"?-1:0).filter(s=>!(!(s.expires<Date.now())||Jt(s.multiaddr).type==="ip6"&&(!e||!Fa(s.multiaddr))||Ha(s.multiaddr))),o=[];for(let s of n){let i=s.multiaddr.toString(),a=this.dialResults.get(i);if(a!=null&&a.networkSegments.includes(t)){this.log.trace("%a already has a network segment result from %s",a.multiaddr,t);continue}if(a==null){let c=s.expires<Date.now();if(c&&this.addressFilter.remove?.(i),this.addressFilter.has(i))continue;this.addressFilter.add(i),this.log.trace("creating dial result %s %s",c?"to revalidate":"for",i),a={multiaddr:s.multiaddr,success:0,failure:0,networkSegments:[],verifyingPeers:ss(),type:s.type,lastVerified:s.lastVerified},this.dialResults.set(i,a)}o.push(a)}return o}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})=>Jt(i).type==="ip6"),o=this.getNetworkSegment(t.remoteAddr),s=this.getUnverifiedMultiaddrs(o,n);if(s.length!==0){if(!this.hasConnectionCapacity()){s[0]?.lastVerified!=null?(this.log("automatically re-verifying %a because we are too close to the connection limit",s[0].multiaddr),this.confirmAddress(s[0])):this.log("skipping verifying %a because we are too close to the connection limit",s[0]?.multiaddr);return}this.queue.add(async i=>{let a=vr([i.signal,AbortSignal.timeout(this.timeout)]),c=BigInt(Rn(0,Number.MAX_SAFE_INTEGER));this.nonces.add(c);try{await this.askPeerToVerify(t,o,c,i)}finally{a.clear(),this.nonces.delete(c)}},{peerId:t.remotePeer}).catch(i=>{this.log.error("error from %p verifying addresses - %e",t.remotePeer,i)})}}async askPeerToVerify(t,e,n,o){let s=[...this.dialResults.values()].filter(a=>a.result==null).map(a=>a.multiaddr);if(s.length===0){this.queue.clear();return}this.log.trace("asking %a to verify multiaddrs %s",t.remoteAddr,s);let i=await t.newStream(this.dialRequestProtocol,o);try{let a=Ve(i).pb(He);await a.write({dialRequest:{addrs:s.map(c=>c.bytes),nonce:n}},o);for(let c=0;c<s.length;c++){let u=await a.read(o);if(u.dialDataRequest!=null){if(u.dialDataRequest.numBytes>this.maxDialDataBytes){this.log("too many dial data byte requested by %p - %s/%s",t.remotePeer,u.dialDataRequest.numBytes,this.maxDialDataBytes);continue}this.log("sending %d bytes to %p as anti-amplification attack protection",u.dialDataRequest.numBytes,t.remotePeer);let p=new Uint8Array(this.dialDataChunkSize),h=BigInt(this.dialDataChunkSize);for(let v=0n;v<u.dialDataRequest.numBytes;v+=h)await a.write({dialDataResponse:{data:p}},o);u=await a.read(o)}if(u.dialResponse==null){this.log("invalid autonat response from %p - %j",t.remotePeer,u);return}if(u.dialResponse.status!==Vt.ResponseStatus.OK)return;let f=s[u.dialResponse.addrIdx];if(f==null){this.log.trace("peer dialed unknown address");continue}let d=this.dialResults.get(f.toString());if(d==null){this.log.trace("peer reported %a as %s but there is no result object",f,u.dialResponse.status);continue}if(d.networkSegments.includes(e)){this.log.trace("%a results already included network segment %s",f,e);continue}if(d.result!=null){this.log.trace("already resolved result for %a, ignoring response from",f,t.remotePeer);continue}if(d.verifyingPeers.has(t.remotePeer)){this.log.trace("peer %p has already verified %a, ignoring response",t.remotePeer,f);continue}if(d.verifyingPeers.add(t.remotePeer),d.networkSegments.push(e),u.dialResponse.dialStatus===ut.OK){if(this.log.trace("%p dialed %a successfully",t.remotePeer,d.multiaddr),d.success++,d.type!=="observed"){this.confirmAddress(d);continue}}else if(u.dialResponse.dialStatus===ut.E_DIAL_ERROR)this.log.trace("%p could not dial %a",t.remotePeer,d.multiaddr),d.failure++;else if(u.dialResponse.dialStatus===ut.E_DIAL_BACK_ERROR){this.log.trace("%p saw error while dialing %a",t.remotePeer,d.multiaddr);continue}this.log("%a success %d failure %d",d.multiaddr,d.success,d.failure),d.success===gd&&this.confirmAddress(d),d.failure===bd&&this.unconfirmAddress(d)}}finally{try{await i.close(o)}catch(a){i.abort(a)}}}hasConnectionCapacity(){let e=this.components.connectionManager.getConnections().length,n=this.components.connectionManager.getMaxConnections();return e/n*100<this.connectionThreshold}confirmAddress(t){this.log("%s address %a is externally dialable",t.type,t.multiaddr),this.components.addressManager.confirmObservedAddr(t.multiaddr),this.dialResults.delete(t.multiaddr.toString()),t.result=!0}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}getNetworkSegment(t){let e=Jt(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`)}}};var Cn=class{components;dialRequestProtocol;dialBackProtocol;timeout;maxInboundStreams;maxOutboundStreams;maxMessageSize;started;log;constructor(t,e){this.components=t,this.log=t.logger.forComponent("libp2p:auto-nat-v2:server"),this.started=!1,this.dialRequestProtocol=e.dialRequestProtocol,this.dialBackProtocol=e.dialBackProtocol,this.timeout=e.timeout??3e4,this.maxInboundStreams=e.maxInboundStreams??2,this.maxOutboundStreams=e.maxOutboundStreams??20,this.maxMessageSize=e.maxMessageSize??8192,this.handleDialRequestStream=this.handleDialRequestStream.bind(this)}async start(){this.started||(await this.components.registrar.handle(this.dialRequestProtocol,this.handleDialRequestStream,{maxInboundStreams:this.maxInboundStreams,maxOutboundStreams:this.maxOutboundStreams}),this.started=!0)}async stop(){await this.components.registrar.unhandle(this.dialRequestProtocol),this.started=!1}async handleDialRequestStream(t,e){let n=AbortSignal.timeout(this.timeout);let o=Ve(t,{maxDataLength:this.maxMessageSize}).pb(He),s=bc(e.remoteAddr);if(s==null)throw new wt(`Could not find IP address in connection address "${e.remoteAddr}"`);let{dialRequest:i}=await o.read({signal:n});if(i==null)throw new wt("Did not receive DialRequest message on incoming dial request stream");if(i.addrs.length===0)throw new wt("Did not receive any addresses to dial");for(let a=0;a<i.addrs.length;a++)try{let c=ic(i.addrs[a]);if(!await this.components.connectionManager.isDialable(c,{signal:n})){await o.write({dialResponse:{addrIdx:a,status:Vt.ResponseStatus.E_DIAL_REFUSED,dialStatus:ut.UNUSED}},{signal:n});continue}let l=bc(c);if(l==null)throw new wt(`Could not find IP address in requested address "${c}"`);if(pn(l))throw new wt(`Requested address had private IP "${c}"`);l!==s&&await this.preventAmplificationAttack(o,a,{signal:n});let f=await this.dialClientBack(c,i.nonce,{signal:n});await o.write({dialResponse:{addrIdx:a,status:Vt.ResponseStatus.OK,dialStatus:f}},{signal:n})}catch(c){this.log.error("error handling incoming dialback request - %e",c)}await t.close({signal:n})}async preventAmplificationAttack(t,e,n){let o=Rn(3e4,1e5);await t.write({dialDataRequest:{addrIdx:e,numBytes:BigInt(o)}},n);let s=0;for(;s<o;){let{dialDataResponse:i}=await t.read(n);if(i==null)throw new wt("Did not receive DialDataResponse message on incoming dial request stream");s+=i.data.byteLength}}async dialClientBack(t,e,n){let o;try{o=await this.components.connectionManager.openConnection(t,{force:!0,...n})}catch(s){return this.log.error("failed to open connection to %a - %e",t,s),ut.E_DIAL_ERROR}try{let s=await o.newStream(this.dialBackProtocol,n),i=Ve(s,{maxDataLength:this.maxMessageSize});if(await i.write({nonce:e},$e,n),(await i.read(te,n)).status!==te.DialBackStatus.OK)throw new wt("DialBackResponse status was not OK");await o.close(n)}catch(s){return this.log.error("could not perform dial back - %e",s),o.abort(s),ut.E_DIAL_BACK_ERROR}return ut.OK}};function bc(r){return r.getComponents().filter(t=>t.code===4||t.code===41).map(t=>t.value).pop()}var Pn=class{client;server;constructor(t,e){let n=`/${e.protocolPrefix??Cs}/${Ps}/${"2"}/${uc}`,o=`/${e.protocolPrefix??Cs}/${Ps}/${"2"}/${fc}`;this.client=new Tn(t,{...e,dialRequestProtocol:n,dialBackProtocol:o}),this.server=new Cn(t,{...e,dialRequestProtocol:n,dialBackProtocol:o})}[Symbol.toStringTag]="@libp2p/autonat-v2";[Rr]=["@libp2p/autonat"];get[Tr](){return["@libp2p/identify"]}async start(){await Ms(this.client,this.server)}async stop(){await Ks(this.client,this.server)}};function yd(r={}){return t=>new Pn(t,r)}return Ic(xd);})();
|
|
3
3
|
/*! Bundled license information:
|
|
4
4
|
|
|
5
5
|
@noble/hashes/utils.js:
|